diff options
-rw-r--r-- | drivers/scsi/ahci.c | 108 | ||||
-rw-r--r-- | drivers/scsi/ata_piix.c | 54 | ||||
-rw-r--r-- | drivers/scsi/libata-core.c | 625 | ||||
-rw-r--r-- | drivers/scsi/libata-scsi.c | 140 | ||||
-rw-r--r-- | drivers/scsi/libata.h | 2 | ||||
-rw-r--r-- | drivers/scsi/pdc_adma.c | 4 | ||||
-rw-r--r-- | drivers/scsi/sata_mv.c | 18 | ||||
-rw-r--r-- | drivers/scsi/sata_promise.c | 120 | ||||
-rw-r--r-- | drivers/scsi/sata_qstor.c | 4 | ||||
-rw-r--r-- | drivers/scsi/sata_sil24.c | 16 | ||||
-rw-r--r-- | drivers/scsi/sata_sx4.c | 16 | ||||
-rw-r--r-- | drivers/scsi/scsi_error.c | 7 | ||||
-rw-r--r-- | include/linux/ata.h | 12 | ||||
-rw-r--r-- | include/linux/libata.h | 98 | ||||
-rw-r--r-- | include/scsi/scsi_eh.h | 3 |
15 files changed, 872 insertions, 355 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c index a800fb51168b..c840d5ec12a7 100644 --- a/drivers/scsi/ahci.c +++ b/drivers/scsi/ahci.c | |||
@@ -66,6 +66,8 @@ enum { | |||
66 | AHCI_IRQ_ON_SG = (1 << 31), | 66 | AHCI_IRQ_ON_SG = (1 << 31), |
67 | AHCI_CMD_ATAPI = (1 << 5), | 67 | AHCI_CMD_ATAPI = (1 << 5), |
68 | AHCI_CMD_WRITE = (1 << 6), | 68 | AHCI_CMD_WRITE = (1 << 6), |
69 | AHCI_CMD_RESET = (1 << 8), | ||
70 | AHCI_CMD_CLR_BUSY = (1 << 10), | ||
69 | 71 | ||
70 | RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ | 72 | RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ |
71 | 73 | ||
@@ -85,6 +87,7 @@ enum { | |||
85 | 87 | ||
86 | /* HOST_CAP bits */ | 88 | /* HOST_CAP bits */ |
87 | HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ | 89 | HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ |
90 | HOST_CAP_CLO = (1 << 24), /* Command List Override support */ | ||
88 | 91 | ||
89 | /* registers for each SATA port */ | 92 | /* registers for each SATA port */ |
90 | PORT_LST_ADDR = 0x00, /* command list DMA addr */ | 93 | PORT_LST_ADDR = 0x00, /* command list DMA addr */ |
@@ -138,6 +141,7 @@ enum { | |||
138 | PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */ | 141 | PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */ |
139 | PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */ | 142 | PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */ |
140 | PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */ | 143 | PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */ |
144 | PORT_CMD_CLO = (1 << 3), /* Command list override */ | ||
141 | PORT_CMD_POWER_ON = (1 << 2), /* Power up device */ | 145 | PORT_CMD_POWER_ON = (1 << 2), /* Power up device */ |
142 | PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ | 146 | PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ |
143 | PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ | 147 | PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ |
@@ -184,7 +188,7 @@ struct ahci_port_priv { | |||
184 | static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); | 188 | static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); |
185 | static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 189 | static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
186 | static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 190 | static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
187 | static int ahci_qc_issue(struct ata_queued_cmd *qc); | 191 | static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc); |
188 | static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); | 192 | static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); |
189 | static void ahci_phy_reset(struct ata_port *ap); | 193 | static void ahci_phy_reset(struct ata_port *ap); |
190 | static void ahci_irq_clear(struct ata_port *ap); | 194 | static void ahci_irq_clear(struct ata_port *ap); |
@@ -450,25 +454,72 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in, | |||
450 | writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); | 454 | writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); |
451 | } | 455 | } |
452 | 456 | ||
453 | static void ahci_phy_reset(struct ata_port *ap) | 457 | static int ahci_stop_engine(struct ata_port *ap) |
458 | { | ||
459 | void __iomem *mmio = ap->host_set->mmio_base; | ||
460 | void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); | ||
461 | int work; | ||
462 | u32 tmp; | ||
463 | |||
464 | tmp = readl(port_mmio + PORT_CMD); | ||
465 | tmp &= ~PORT_CMD_START; | ||
466 | writel(tmp, port_mmio + PORT_CMD); | ||
467 | |||
468 | /* wait for engine to stop. TODO: this could be | ||
469 | * as long as 500 msec | ||
470 | */ | ||
471 | work = 1000; | ||
472 | while (work-- > 0) { | ||
473 | tmp = readl(port_mmio + PORT_CMD); | ||
474 | if ((tmp & PORT_CMD_LIST_ON) == 0) | ||
475 | return 0; | ||
476 | udelay(10); | ||
477 | } | ||
478 | |||
479 | return -EIO; | ||
480 | } | ||
481 | |||
482 | static void ahci_start_engine(struct ata_port *ap) | ||
483 | { | ||
484 | void __iomem *mmio = ap->host_set->mmio_base; | ||
485 | void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); | ||
486 | u32 tmp; | ||
487 | |||
488 | tmp = readl(port_mmio + PORT_CMD); | ||
489 | tmp |= PORT_CMD_START; | ||
490 | writel(tmp, port_mmio + PORT_CMD); | ||
491 | readl(port_mmio + PORT_CMD); /* flush */ | ||
492 | } | ||
493 | |||
494 | static unsigned int ahci_dev_classify(struct ata_port *ap) | ||
454 | { | 495 | { |
455 | void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; | 496 | void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; |
456 | struct ata_taskfile tf; | 497 | struct ata_taskfile tf; |
498 | u32 tmp; | ||
499 | |||
500 | tmp = readl(port_mmio + PORT_SIG); | ||
501 | tf.lbah = (tmp >> 24) & 0xff; | ||
502 | tf.lbam = (tmp >> 16) & 0xff; | ||
503 | tf.lbal = (tmp >> 8) & 0xff; | ||
504 | tf.nsect = (tmp) & 0xff; | ||
505 | |||
506 | return ata_dev_classify(&tf); | ||
507 | } | ||
508 | |||
509 | static void ahci_phy_reset(struct ata_port *ap) | ||
510 | { | ||
511 | void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; | ||
457 | struct ata_device *dev = &ap->device[0]; | 512 | struct ata_device *dev = &ap->device[0]; |
458 | u32 new_tmp, tmp; | 513 | u32 new_tmp, tmp; |
459 | 514 | ||
515 | ahci_stop_engine(ap); | ||
460 | __sata_phy_reset(ap); | 516 | __sata_phy_reset(ap); |
517 | ahci_start_engine(ap); | ||
461 | 518 | ||
462 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 519 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
463 | return; | 520 | return; |
464 | 521 | ||
465 | tmp = readl(port_mmio + PORT_SIG); | 522 | dev->class = ahci_dev_classify(ap); |
466 | tf.lbah = (tmp >> 24) & 0xff; | ||
467 | tf.lbam = (tmp >> 16) & 0xff; | ||
468 | tf.lbal = (tmp >> 8) & 0xff; | ||
469 | tf.nsect = (tmp) & 0xff; | ||
470 | |||
471 | dev->class = ata_dev_classify(&tf); | ||
472 | if (!ata_dev_present(dev)) { | 523 | if (!ata_dev_present(dev)) { |
473 | ata_port_disable(ap); | 524 | ata_port_disable(ap); |
474 | return; | 525 | return; |
@@ -576,7 +627,6 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat) | |||
576 | void __iomem *mmio = ap->host_set->mmio_base; | 627 | void __iomem *mmio = ap->host_set->mmio_base; |
577 | void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); | 628 | void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); |
578 | u32 tmp; | 629 | u32 tmp; |
579 | int work; | ||
580 | 630 | ||
581 | if ((ap->device[0].class != ATA_DEV_ATAPI) || | 631 | if ((ap->device[0].class != ATA_DEV_ATAPI) || |
582 | ((irq_stat & PORT_IRQ_TF_ERR) == 0)) | 632 | ((irq_stat & PORT_IRQ_TF_ERR) == 0)) |
@@ -592,20 +642,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat) | |||
592 | readl(port_mmio + PORT_SCR_ERR)); | 642 | readl(port_mmio + PORT_SCR_ERR)); |
593 | 643 | ||
594 | /* stop DMA */ | 644 | /* stop DMA */ |
595 | tmp = readl(port_mmio + PORT_CMD); | 645 | ahci_stop_engine(ap); |
596 | tmp &= ~PORT_CMD_START; | ||
597 | writel(tmp, port_mmio + PORT_CMD); | ||
598 | |||
599 | /* wait for engine to stop. TODO: this could be | ||
600 | * as long as 500 msec | ||
601 | */ | ||
602 | work = 1000; | ||
603 | while (work-- > 0) { | ||
604 | tmp = readl(port_mmio + PORT_CMD); | ||
605 | if ((tmp & PORT_CMD_LIST_ON) == 0) | ||
606 | break; | ||
607 | udelay(10); | ||
608 | } | ||
609 | 646 | ||
610 | /* clear SATA phy error, if any */ | 647 | /* clear SATA phy error, if any */ |
611 | tmp = readl(port_mmio + PORT_SCR_ERR); | 648 | tmp = readl(port_mmio + PORT_SCR_ERR); |
@@ -624,10 +661,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat) | |||
624 | } | 661 | } |
625 | 662 | ||
626 | /* re-start DMA */ | 663 | /* re-start DMA */ |
627 | tmp = readl(port_mmio + PORT_CMD); | 664 | ahci_start_engine(ap); |
628 | tmp |= PORT_CMD_START; | ||
629 | writel(tmp, port_mmio + PORT_CMD); | ||
630 | readl(port_mmio + PORT_CMD); /* flush */ | ||
631 | } | 665 | } |
632 | 666 | ||
633 | static void ahci_eng_timeout(struct ata_port *ap) | 667 | static void ahci_eng_timeout(struct ata_port *ap) |
@@ -648,19 +682,13 @@ static void ahci_eng_timeout(struct ata_port *ap) | |||
648 | ap->id); | 682 | ap->id); |
649 | } else { | 683 | } else { |
650 | ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT)); | 684 | ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT)); |
651 | 685 | qc->err_mask |= AC_ERR_TIMEOUT; | |
652 | /* hack alert! We cannot use the supplied completion | ||
653 | * function from inside the ->eh_strategy_handler() thread. | ||
654 | * libata is the only user of ->eh_strategy_handler() in | ||
655 | * any kernel, so the default scsi_done() assumes it is | ||
656 | * not being called from the SCSI EH. | ||
657 | */ | ||
658 | qc->scsidone = scsi_finish_command; | ||
659 | qc->err_mask |= AC_ERR_OTHER; | ||
660 | ata_qc_complete(qc); | ||
661 | } | 686 | } |
662 | 687 | ||
663 | spin_unlock_irqrestore(&host_set->lock, flags); | 688 | spin_unlock_irqrestore(&host_set->lock, flags); |
689 | |||
690 | if (qc) | ||
691 | ata_eh_qc_complete(qc); | ||
664 | } | 692 | } |
665 | 693 | ||
666 | static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) | 694 | static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) |
@@ -697,7 +725,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) | |||
697 | ahci_restart_port(ap, status); | 725 | ahci_restart_port(ap, status); |
698 | 726 | ||
699 | if (qc) { | 727 | if (qc) { |
700 | qc->err_mask |= AC_ERR_OTHER; | 728 | qc->err_mask |= err_mask; |
701 | ata_qc_complete(qc); | 729 | ata_qc_complete(qc); |
702 | } | 730 | } |
703 | } | 731 | } |
@@ -776,7 +804,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs * | |||
776 | return IRQ_RETVAL(handled); | 804 | return IRQ_RETVAL(handled); |
777 | } | 805 | } |
778 | 806 | ||
779 | static int ahci_qc_issue(struct ata_queued_cmd *qc) | 807 | static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc) |
780 | { | 808 | { |
781 | struct ata_port *ap = qc->ap; | 809 | struct ata_port *ap = qc->ap; |
782 | void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; | 810 | void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; |
diff --git a/drivers/scsi/ata_piix.c b/drivers/scsi/ata_piix.c index fc3ca051ceed..49cc4209fe16 100644 --- a/drivers/scsi/ata_piix.c +++ b/drivers/scsi/ata_piix.c | |||
@@ -101,9 +101,11 @@ enum { | |||
101 | ICH5_PCS = 0x92, /* port control and status */ | 101 | ICH5_PCS = 0x92, /* port control and status */ |
102 | PIIX_SCC = 0x0A, /* sub-class code register */ | 102 | PIIX_SCC = 0x0A, /* sub-class code register */ |
103 | 103 | ||
104 | PIIX_FLAG_AHCI = (1 << 28), /* AHCI possible */ | 104 | PIIX_FLAG_AHCI = (1 << 27), /* AHCI possible */ |
105 | PIIX_FLAG_CHECKINTR = (1 << 29), /* make sure PCI INTx enabled */ | 105 | PIIX_FLAG_CHECKINTR = (1 << 28), /* make sure PCI INTx enabled */ |
106 | PIIX_FLAG_COMBINED = (1 << 30), /* combined mode possible */ | 106 | PIIX_FLAG_COMBINED = (1 << 29), /* combined mode possible */ |
107 | /* ICH6/7 use different scheme for map value */ | ||
108 | PIIX_FLAG_COMBINED_ICH6 = PIIX_FLAG_COMBINED | (1 << 30), | ||
107 | 109 | ||
108 | /* combined mode. if set, PATA is channel 0. | 110 | /* combined mode. if set, PATA is channel 0. |
109 | * if clear, PATA is channel 1. | 111 | * if clear, PATA is channel 1. |
@@ -297,8 +299,8 @@ static struct ata_port_info piix_port_info[] = { | |||
297 | { | 299 | { |
298 | .sht = &piix_sht, | 300 | .sht = &piix_sht, |
299 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | | 301 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | |
300 | PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR | | 302 | PIIX_FLAG_COMBINED_ICH6 | |
301 | ATA_FLAG_SLAVE_POSS, | 303 | PIIX_FLAG_CHECKINTR | ATA_FLAG_SLAVE_POSS, |
302 | .pio_mask = 0x1f, /* pio0-4 */ | 304 | .pio_mask = 0x1f, /* pio0-4 */ |
303 | .mwdma_mask = 0x07, /* mwdma0-2 */ | 305 | .mwdma_mask = 0x07, /* mwdma0-2 */ |
304 | .udma_mask = 0x7f, /* udma0-6 */ | 306 | .udma_mask = 0x7f, /* udma0-6 */ |
@@ -309,8 +311,9 @@ static struct ata_port_info piix_port_info[] = { | |||
309 | { | 311 | { |
310 | .sht = &piix_sht, | 312 | .sht = &piix_sht, |
311 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | | 313 | .host_flags = ATA_FLAG_SATA | ATA_FLAG_SRST | |
312 | PIIX_FLAG_COMBINED | PIIX_FLAG_CHECKINTR | | 314 | PIIX_FLAG_COMBINED_ICH6 | |
313 | ATA_FLAG_SLAVE_POSS | PIIX_FLAG_AHCI, | 315 | PIIX_FLAG_CHECKINTR | ATA_FLAG_SLAVE_POSS | |
316 | PIIX_FLAG_AHCI, | ||
314 | .pio_mask = 0x1f, /* pio0-4 */ | 317 | .pio_mask = 0x1f, /* pio0-4 */ |
315 | .mwdma_mask = 0x07, /* mwdma0-2 */ | 318 | .mwdma_mask = 0x07, /* mwdma0-2 */ |
316 | .udma_mask = 0x7f, /* udma0-6 */ | 319 | .udma_mask = 0x7f, /* udma0-6 */ |
@@ -627,6 +630,7 @@ static int piix_disable_ahci(struct pci_dev *pdev) | |||
627 | 630 | ||
628 | /** | 631 | /** |
629 | * piix_check_450nx_errata - Check for problem 450NX setup | 632 | * piix_check_450nx_errata - Check for problem 450NX setup |
633 | * @ata_dev: the PCI device to check | ||
630 | * | 634 | * |
631 | * Check for the present of 450NX errata #19 and errata #25. If | 635 | * Check for the present of 450NX errata #19 and errata #25. If |
632 | * they are found return an error code so we can turn off DMA | 636 | * they are found return an error code so we can turn off DMA |
@@ -680,6 +684,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | |||
680 | struct ata_port_info *port_info[2]; | 684 | struct ata_port_info *port_info[2]; |
681 | unsigned int combined = 0; | 685 | unsigned int combined = 0; |
682 | unsigned int pata_chan = 0, sata_chan = 0; | 686 | unsigned int pata_chan = 0, sata_chan = 0; |
687 | unsigned long host_flags; | ||
683 | 688 | ||
684 | if (!printed_version++) | 689 | if (!printed_version++) |
685 | dev_printk(KERN_DEBUG, &pdev->dev, | 690 | dev_printk(KERN_DEBUG, &pdev->dev, |
@@ -692,7 +697,9 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | |||
692 | port_info[0] = &piix_port_info[ent->driver_data]; | 697 | port_info[0] = &piix_port_info[ent->driver_data]; |
693 | port_info[1] = &piix_port_info[ent->driver_data]; | 698 | port_info[1] = &piix_port_info[ent->driver_data]; |
694 | 699 | ||
695 | if (port_info[0]->host_flags & PIIX_FLAG_AHCI) { | 700 | host_flags = port_info[0]->host_flags; |
701 | |||
702 | if (host_flags & PIIX_FLAG_AHCI) { | ||
696 | u8 tmp; | 703 | u8 tmp; |
697 | pci_read_config_byte(pdev, PIIX_SCC, &tmp); | 704 | pci_read_config_byte(pdev, PIIX_SCC, &tmp); |
698 | if (tmp == PIIX_AHCI_DEVICE) { | 705 | if (tmp == PIIX_AHCI_DEVICE) { |
@@ -702,16 +709,35 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | |||
702 | } | 709 | } |
703 | } | 710 | } |
704 | 711 | ||
705 | if (port_info[0]->host_flags & PIIX_FLAG_COMBINED) { | 712 | if (host_flags & PIIX_FLAG_COMBINED) { |
706 | u8 tmp; | 713 | u8 tmp; |
707 | pci_read_config_byte(pdev, ICH5_PMR, &tmp); | 714 | pci_read_config_byte(pdev, ICH5_PMR, &tmp); |
708 | 715 | ||
709 | if (tmp & PIIX_COMB) { | 716 | if (host_flags & PIIX_FLAG_COMBINED_ICH6) { |
710 | combined = 1; | 717 | switch (tmp & 0x3) { |
711 | if (tmp & PIIX_COMB_PATA_P0) | 718 | case 0: |
719 | break; | ||
720 | case 1: | ||
721 | combined = 1; | ||
712 | sata_chan = 1; | 722 | sata_chan = 1; |
713 | else | 723 | break; |
724 | case 2: | ||
725 | combined = 1; | ||
714 | pata_chan = 1; | 726 | pata_chan = 1; |
727 | break; | ||
728 | case 3: | ||
729 | dev_printk(KERN_WARNING, &pdev->dev, | ||
730 | "invalid MAP value %u\n", tmp); | ||
731 | break; | ||
732 | } | ||
733 | } else { | ||
734 | if (tmp & PIIX_COMB) { | ||
735 | combined = 1; | ||
736 | if (tmp & PIIX_COMB_PATA_P0) | ||
737 | sata_chan = 1; | ||
738 | else | ||
739 | pata_chan = 1; | ||
740 | } | ||
715 | } | 741 | } |
716 | } | 742 | } |
717 | 743 | ||
@@ -721,7 +747,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) | |||
721 | * MSI is disabled (and it is disabled, as we don't use | 747 | * MSI is disabled (and it is disabled, as we don't use |
722 | * message-signalled interrupts currently). | 748 | * message-signalled interrupts currently). |
723 | */ | 749 | */ |
724 | if (port_info[0]->host_flags & PIIX_FLAG_CHECKINTR) | 750 | if (host_flags & PIIX_FLAG_CHECKINTR) |
725 | pci_intx(pdev, 1); | 751 | pci_intx(pdev, 1); |
726 | 752 | ||
727 | if (combined) { | 753 | if (combined) { |
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 46c4cdbaee86..249e67fab81f 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -61,9 +61,6 @@ | |||
61 | 61 | ||
62 | #include "libata.h" | 62 | #include "libata.h" |
63 | 63 | ||
64 | static unsigned int ata_busy_sleep (struct ata_port *ap, | ||
65 | unsigned long tmout_pat, | ||
66 | unsigned long tmout); | ||
67 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev); | 64 | static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev); |
68 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev); | 65 | static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev); |
69 | static void ata_set_mode(struct ata_port *ap); | 66 | static void ata_set_mode(struct ata_port *ap); |
@@ -73,7 +70,6 @@ static int fgb(u32 bitmap); | |||
73 | static int ata_choose_xfer_mode(const struct ata_port *ap, | 70 | static int ata_choose_xfer_mode(const struct ata_port *ap, |
74 | u8 *xfer_mode_out, | 71 | u8 *xfer_mode_out, |
75 | unsigned int *xfer_shift_out); | 72 | unsigned int *xfer_shift_out); |
76 | static void __ata_qc_complete(struct ata_queued_cmd *qc); | ||
77 | 73 | ||
78 | static unsigned int ata_unique_id = 1; | 74 | static unsigned int ata_unique_id = 1; |
79 | static struct workqueue_struct *ata_wq; | 75 | static struct workqueue_struct *ata_wq; |
@@ -834,6 +830,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf) | |||
834 | * ata_dev_try_classify - Parse returned ATA device signature | 830 | * ata_dev_try_classify - Parse returned ATA device signature |
835 | * @ap: ATA channel to examine | 831 | * @ap: ATA channel to examine |
836 | * @device: Device to examine (starting at zero) | 832 | * @device: Device to examine (starting at zero) |
833 | * @r_err: Value of error register on completion | ||
837 | * | 834 | * |
838 | * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, | 835 | * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs, |
839 | * an ATA/ATAPI-defined set of values is placed in the ATA | 836 | * an ATA/ATAPI-defined set of values is placed in the ATA |
@@ -846,11 +843,14 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf) | |||
846 | * | 843 | * |
847 | * LOCKING: | 844 | * LOCKING: |
848 | * caller. | 845 | * caller. |
846 | * | ||
847 | * RETURNS: | ||
848 | * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE. | ||
849 | */ | 849 | */ |
850 | 850 | ||
851 | static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) | 851 | static unsigned int |
852 | ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err) | ||
852 | { | 853 | { |
853 | struct ata_device *dev = &ap->device[device]; | ||
854 | struct ata_taskfile tf; | 854 | struct ata_taskfile tf; |
855 | unsigned int class; | 855 | unsigned int class; |
856 | u8 err; | 856 | u8 err; |
@@ -861,8 +861,8 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) | |||
861 | 861 | ||
862 | ap->ops->tf_read(ap, &tf); | 862 | ap->ops->tf_read(ap, &tf); |
863 | err = tf.feature; | 863 | err = tf.feature; |
864 | 864 | if (r_err) | |
865 | dev->class = ATA_DEV_NONE; | 865 | *r_err = err; |
866 | 866 | ||
867 | /* see if device passed diags */ | 867 | /* see if device passed diags */ |
868 | if (err == 1) | 868 | if (err == 1) |
@@ -870,18 +870,16 @@ static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) | |||
870 | else if ((device == 0) && (err == 0x81)) | 870 | else if ((device == 0) && (err == 0x81)) |
871 | /* do nothing */ ; | 871 | /* do nothing */ ; |
872 | else | 872 | else |
873 | return err; | 873 | return ATA_DEV_NONE; |
874 | 874 | ||
875 | /* determine if device if ATA or ATAPI */ | 875 | /* determine if device is ATA or ATAPI */ |
876 | class = ata_dev_classify(&tf); | 876 | class = ata_dev_classify(&tf); |
877 | |||
877 | if (class == ATA_DEV_UNKNOWN) | 878 | if (class == ATA_DEV_UNKNOWN) |
878 | return err; | 879 | return ATA_DEV_NONE; |
879 | if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0)) | 880 | if ((class == ATA_DEV_ATA) && (ata_chk_status(ap) == 0)) |
880 | return err; | 881 | return ATA_DEV_NONE; |
881 | 882 | return class; | |
882 | dev->class = class; | ||
883 | |||
884 | return err; | ||
885 | } | 883 | } |
886 | 884 | ||
887 | /** | 885 | /** |
@@ -1073,24 +1071,30 @@ static unsigned int ata_pio_modes(const struct ata_device *adev) | |||
1073 | timing API will get this right anyway */ | 1071 | timing API will get this right anyway */ |
1074 | } | 1072 | } |
1075 | 1073 | ||
1076 | struct ata_exec_internal_arg { | 1074 | static inline void |
1077 | unsigned int err_mask; | 1075 | ata_queue_packet_task(struct ata_port *ap) |
1078 | struct ata_taskfile *tf; | 1076 | { |
1079 | struct completion *waiting; | 1077 | queue_work(ata_wq, &ap->packet_task); |
1080 | }; | 1078 | } |
1081 | 1079 | ||
1082 | int ata_qc_complete_internal(struct ata_queued_cmd *qc) | 1080 | static inline void |
1081 | ata_queue_pio_task(struct ata_port *ap) | ||
1083 | { | 1082 | { |
1084 | struct ata_exec_internal_arg *arg = qc->private_data; | 1083 | queue_work(ata_wq, &ap->pio_task); |
1085 | struct completion *waiting = arg->waiting; | 1084 | } |
1086 | 1085 | ||
1087 | if (!(qc->err_mask & ~AC_ERR_DEV)) | 1086 | static inline void |
1088 | qc->ap->ops->tf_read(qc->ap, arg->tf); | 1087 | ata_queue_delayed_pio_task(struct ata_port *ap, unsigned long delay) |
1089 | arg->err_mask = qc->err_mask; | 1088 | { |
1090 | arg->waiting = NULL; | 1089 | queue_delayed_work(ata_wq, &ap->pio_task, delay); |
1091 | complete(waiting); | 1090 | } |
1092 | 1091 | ||
1093 | return 0; | 1092 | void ata_qc_complete_internal(struct ata_queued_cmd *qc) |
1093 | { | ||
1094 | struct completion *waiting = qc->private_data; | ||
1095 | |||
1096 | qc->ap->ops->tf_read(qc->ap, &qc->tf); | ||
1097 | complete(waiting); | ||
1094 | } | 1098 | } |
1095 | 1099 | ||
1096 | /** | 1100 | /** |
@@ -1121,7 +1125,7 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
1121 | struct ata_queued_cmd *qc; | 1125 | struct ata_queued_cmd *qc; |
1122 | DECLARE_COMPLETION(wait); | 1126 | DECLARE_COMPLETION(wait); |
1123 | unsigned long flags; | 1127 | unsigned long flags; |
1124 | struct ata_exec_internal_arg arg; | 1128 | unsigned int err_mask; |
1125 | 1129 | ||
1126 | spin_lock_irqsave(&ap->host_set->lock, flags); | 1130 | spin_lock_irqsave(&ap->host_set->lock, flags); |
1127 | 1131 | ||
@@ -1135,13 +1139,12 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
1135 | qc->nsect = buflen / ATA_SECT_SIZE; | 1139 | qc->nsect = buflen / ATA_SECT_SIZE; |
1136 | } | 1140 | } |
1137 | 1141 | ||
1138 | arg.waiting = &wait; | 1142 | qc->private_data = &wait; |
1139 | arg.tf = tf; | ||
1140 | qc->private_data = &arg; | ||
1141 | qc->complete_fn = ata_qc_complete_internal; | 1143 | qc->complete_fn = ata_qc_complete_internal; |
1142 | 1144 | ||
1143 | if (ata_qc_issue(qc)) | 1145 | qc->err_mask = ata_qc_issue(qc); |
1144 | goto issue_fail; | 1146 | if (qc->err_mask) |
1147 | ata_qc_complete(qc); | ||
1145 | 1148 | ||
1146 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | 1149 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
1147 | 1150 | ||
@@ -1154,8 +1157,8 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
1154 | * before the caller cleans up, it will result in a | 1157 | * before the caller cleans up, it will result in a |
1155 | * spurious interrupt. We can live with that. | 1158 | * spurious interrupt. We can live with that. |
1156 | */ | 1159 | */ |
1157 | if (arg.waiting) { | 1160 | if (qc->flags & ATA_QCFLAG_ACTIVE) { |
1158 | qc->err_mask = AC_ERR_OTHER; | 1161 | qc->err_mask = AC_ERR_TIMEOUT; |
1159 | ata_qc_complete(qc); | 1162 | ata_qc_complete(qc); |
1160 | printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n", | 1163 | printk(KERN_WARNING "ata%u: qc timeout (cmd 0x%x)\n", |
1161 | ap->id, command); | 1164 | ap->id, command); |
@@ -1164,12 +1167,12 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev, | |||
1164 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | 1167 | spin_unlock_irqrestore(&ap->host_set->lock, flags); |
1165 | } | 1168 | } |
1166 | 1169 | ||
1167 | return arg.err_mask; | 1170 | *tf = qc->tf; |
1171 | err_mask = qc->err_mask; | ||
1168 | 1172 | ||
1169 | issue_fail: | ||
1170 | ata_qc_free(qc); | 1173 | ata_qc_free(qc); |
1171 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | 1174 | |
1172 | return AC_ERR_OTHER; | 1175 | return err_mask; |
1173 | } | 1176 | } |
1174 | 1177 | ||
1175 | /** | 1178 | /** |
@@ -1439,12 +1442,11 @@ static inline u8 ata_dev_knobble(const struct ata_port *ap) | |||
1439 | } | 1442 | } |
1440 | 1443 | ||
1441 | /** | 1444 | /** |
1442 | * ata_dev_config - Run device specific handlers and check for | 1445 | * ata_dev_config - Run device specific handlers & check for SATA->PATA bridges |
1443 | * SATA->PATA bridges | 1446 | * @ap: Bus |
1444 | * @ap: Bus | 1447 | * @i: Device |
1445 | * @i: Device | ||
1446 | * | 1448 | * |
1447 | * LOCKING: | 1449 | * LOCKING: |
1448 | */ | 1450 | */ |
1449 | 1451 | ||
1450 | void ata_dev_config(struct ata_port *ap, unsigned int i) | 1452 | void ata_dev_config(struct ata_port *ap, unsigned int i) |
@@ -1482,7 +1484,24 @@ static int ata_bus_probe(struct ata_port *ap) | |||
1482 | { | 1484 | { |
1483 | unsigned int i, found = 0; | 1485 | unsigned int i, found = 0; |
1484 | 1486 | ||
1485 | ap->ops->phy_reset(ap); | 1487 | if (ap->ops->probe_reset) { |
1488 | unsigned int classes[ATA_MAX_DEVICES]; | ||
1489 | int rc; | ||
1490 | |||
1491 | ata_port_probe(ap); | ||
1492 | |||
1493 | rc = ap->ops->probe_reset(ap, classes); | ||
1494 | if (rc == 0) { | ||
1495 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
1496 | ap->device[i].class = classes[i]; | ||
1497 | } else { | ||
1498 | printk(KERN_ERR "ata%u: probe reset failed, " | ||
1499 | "disabling port\n", ap->id); | ||
1500 | ata_port_disable(ap); | ||
1501 | } | ||
1502 | } else | ||
1503 | ap->ops->phy_reset(ap); | ||
1504 | |||
1486 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 1505 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
1487 | goto err_out; | 1506 | goto err_out; |
1488 | 1507 | ||
@@ -1526,6 +1545,41 @@ void ata_port_probe(struct ata_port *ap) | |||
1526 | } | 1545 | } |
1527 | 1546 | ||
1528 | /** | 1547 | /** |
1548 | * sata_print_link_status - Print SATA link status | ||
1549 | * @ap: SATA port to printk link status about | ||
1550 | * | ||
1551 | * This function prints link speed and status of a SATA link. | ||
1552 | * | ||
1553 | * LOCKING: | ||
1554 | * None. | ||
1555 | */ | ||
1556 | static void sata_print_link_status(struct ata_port *ap) | ||
1557 | { | ||
1558 | u32 sstatus, tmp; | ||
1559 | const char *speed; | ||
1560 | |||
1561 | if (!ap->ops->scr_read) | ||
1562 | return; | ||
1563 | |||
1564 | sstatus = scr_read(ap, SCR_STATUS); | ||
1565 | |||
1566 | if (sata_dev_present(ap)) { | ||
1567 | tmp = (sstatus >> 4) & 0xf; | ||
1568 | if (tmp & (1 << 0)) | ||
1569 | speed = "1.5"; | ||
1570 | else if (tmp & (1 << 1)) | ||
1571 | speed = "3.0"; | ||
1572 | else | ||
1573 | speed = "<unknown>"; | ||
1574 | printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n", | ||
1575 | ap->id, speed, sstatus); | ||
1576 | } else { | ||
1577 | printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", | ||
1578 | ap->id, sstatus); | ||
1579 | } | ||
1580 | } | ||
1581 | |||
1582 | /** | ||
1529 | * __sata_phy_reset - Wake/reset a low-level SATA PHY | 1583 | * __sata_phy_reset - Wake/reset a low-level SATA PHY |
1530 | * @ap: SATA port associated with target SATA PHY. | 1584 | * @ap: SATA port associated with target SATA PHY. |
1531 | * | 1585 | * |
@@ -1559,27 +1613,14 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1559 | break; | 1613 | break; |
1560 | } while (time_before(jiffies, timeout)); | 1614 | } while (time_before(jiffies, timeout)); |
1561 | 1615 | ||
1562 | /* TODO: phy layer with polling, timeouts, etc. */ | 1616 | /* print link status */ |
1563 | sstatus = scr_read(ap, SCR_STATUS); | 1617 | sata_print_link_status(ap); |
1564 | if (sata_dev_present(ap)) { | ||
1565 | const char *speed; | ||
1566 | u32 tmp; | ||
1567 | 1618 | ||
1568 | tmp = (sstatus >> 4) & 0xf; | 1619 | /* TODO: phy layer with polling, timeouts, etc. */ |
1569 | if (tmp & (1 << 0)) | 1620 | if (sata_dev_present(ap)) |
1570 | speed = "1.5"; | ||
1571 | else if (tmp & (1 << 1)) | ||
1572 | speed = "3.0"; | ||
1573 | else | ||
1574 | speed = "<unknown>"; | ||
1575 | printk(KERN_INFO "ata%u: SATA link up %s Gbps (SStatus %X)\n", | ||
1576 | ap->id, speed, sstatus); | ||
1577 | ata_port_probe(ap); | 1621 | ata_port_probe(ap); |
1578 | } else { | 1622 | else |
1579 | printk(KERN_INFO "ata%u: SATA link down (SStatus %X)\n", | ||
1580 | ap->id, sstatus); | ||
1581 | ata_port_disable(ap); | 1623 | ata_port_disable(ap); |
1582 | } | ||
1583 | 1624 | ||
1584 | if (ap->flags & ATA_FLAG_PORT_DISABLED) | 1625 | if (ap->flags & ATA_FLAG_PORT_DISABLED) |
1585 | return; | 1626 | return; |
@@ -1752,9 +1793,9 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed, | |||
1752 | ata_timing_quantize(t, t, T, UT); | 1793 | ata_timing_quantize(t, t, T, UT); |
1753 | 1794 | ||
1754 | /* | 1795 | /* |
1755 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, S.M.A.R.T | 1796 | * Even in DMA/UDMA modes we still use PIO access for IDENTIFY, |
1756 | * and some other commands. We have to ensure that the DMA cycle timing is | 1797 | * S.M.A.R.T * and some other commands. We have to ensure that the |
1757 | * slower/equal than the fastest PIO timing. | 1798 | * DMA cycle timing is slower/equal than the fastest PIO timing. |
1758 | */ | 1799 | */ |
1759 | 1800 | ||
1760 | if (speed > XFER_PIO_4) { | 1801 | if (speed > XFER_PIO_4) { |
@@ -1763,7 +1804,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed, | |||
1763 | } | 1804 | } |
1764 | 1805 | ||
1765 | /* | 1806 | /* |
1766 | * Lenghten active & recovery time so that cycle time is correct. | 1807 | * Lengthen active & recovery time so that cycle time is correct. |
1767 | */ | 1808 | */ |
1768 | 1809 | ||
1769 | if (t->act8b + t->rec8b < t->cyc8b) { | 1810 | if (t->act8b + t->rec8b < t->cyc8b) { |
@@ -1882,7 +1923,6 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode, | |||
1882 | * | 1923 | * |
1883 | * LOCKING: | 1924 | * LOCKING: |
1884 | * PCI/etc. bus probe sem. | 1925 | * PCI/etc. bus probe sem. |
1885 | * | ||
1886 | */ | 1926 | */ |
1887 | static void ata_set_mode(struct ata_port *ap) | 1927 | static void ata_set_mode(struct ata_port *ap) |
1888 | { | 1928 | { |
@@ -1931,12 +1971,10 @@ err_out: | |||
1931 | * or a timeout occurs. | 1971 | * or a timeout occurs. |
1932 | * | 1972 | * |
1933 | * LOCKING: None. | 1973 | * LOCKING: None. |
1934 | * | ||
1935 | */ | 1974 | */ |
1936 | 1975 | ||
1937 | static unsigned int ata_busy_sleep (struct ata_port *ap, | 1976 | unsigned int ata_busy_sleep (struct ata_port *ap, |
1938 | unsigned long tmout_pat, | 1977 | unsigned long tmout_pat, unsigned long tmout) |
1939 | unsigned long tmout) | ||
1940 | { | 1978 | { |
1941 | unsigned long timer_start, timeout; | 1979 | unsigned long timer_start, timeout; |
1942 | u8 status; | 1980 | u8 status; |
@@ -2155,9 +2193,9 @@ void ata_bus_reset(struct ata_port *ap) | |||
2155 | /* | 2193 | /* |
2156 | * determine by signature whether we have ATA or ATAPI devices | 2194 | * determine by signature whether we have ATA or ATAPI devices |
2157 | */ | 2195 | */ |
2158 | err = ata_dev_try_classify(ap, 0); | 2196 | ap->device[0].class = ata_dev_try_classify(ap, 0, &err); |
2159 | if ((slave_possible) && (err != 0x81)) | 2197 | if ((slave_possible) && (err != 0x81)) |
2160 | ata_dev_try_classify(ap, 1); | 2198 | ap->device[1].class = ata_dev_try_classify(ap, 1, &err); |
2161 | 2199 | ||
2162 | /* re-enable interrupts */ | 2200 | /* re-enable interrupts */ |
2163 | if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ | 2201 | if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ |
@@ -2192,6 +2230,296 @@ err_out: | |||
2192 | DPRINTK("EXIT\n"); | 2230 | DPRINTK("EXIT\n"); |
2193 | } | 2231 | } |
2194 | 2232 | ||
2233 | /** | ||
2234 | * ata_std_softreset - reset host port via ATA SRST | ||
2235 | * @ap: port to reset | ||
2236 | * @verbose: fail verbosely | ||
2237 | * @classes: resulting classes of attached devices | ||
2238 | * | ||
2239 | * Reset host port using ATA SRST. This function is to be used | ||
2240 | * as standard callback for ata_drive_*_reset() functions. | ||
2241 | * | ||
2242 | * LOCKING: | ||
2243 | * Kernel thread context (may sleep) | ||
2244 | * | ||
2245 | * RETURNS: | ||
2246 | * 0 on success, -errno otherwise. | ||
2247 | */ | ||
2248 | int ata_std_softreset(struct ata_port *ap, int verbose, unsigned int *classes) | ||
2249 | { | ||
2250 | unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; | ||
2251 | unsigned int devmask = 0, err_mask; | ||
2252 | u8 err; | ||
2253 | |||
2254 | DPRINTK("ENTER\n"); | ||
2255 | |||
2256 | /* determine if device 0/1 are present */ | ||
2257 | if (ata_devchk(ap, 0)) | ||
2258 | devmask |= (1 << 0); | ||
2259 | if (slave_possible && ata_devchk(ap, 1)) | ||
2260 | devmask |= (1 << 1); | ||
2261 | |||
2262 | /* devchk reports device presence without actual device on | ||
2263 | * most SATA controllers. Check SStatus and turn devmask off | ||
2264 | * if link is offline. Note that we should continue resetting | ||
2265 | * even when it seems like there's no device. | ||
2266 | */ | ||
2267 | if (ap->ops->scr_read && !sata_dev_present(ap)) | ||
2268 | devmask = 0; | ||
2269 | |||
2270 | /* select device 0 again */ | ||
2271 | ap->ops->dev_select(ap, 0); | ||
2272 | |||
2273 | /* issue bus reset */ | ||
2274 | DPRINTK("about to softreset, devmask=%x\n", devmask); | ||
2275 | err_mask = ata_bus_softreset(ap, devmask); | ||
2276 | if (err_mask) { | ||
2277 | if (verbose) | ||
2278 | printk(KERN_ERR "ata%u: SRST failed (err_mask=0x%x)\n", | ||
2279 | ap->id, err_mask); | ||
2280 | else | ||
2281 | DPRINTK("EXIT, softreset failed (err_mask=0x%x)\n", | ||
2282 | err_mask); | ||
2283 | return -EIO; | ||
2284 | } | ||
2285 | |||
2286 | /* determine by signature whether we have ATA or ATAPI devices */ | ||
2287 | classes[0] = ata_dev_try_classify(ap, 0, &err); | ||
2288 | if (slave_possible && err != 0x81) | ||
2289 | classes[1] = ata_dev_try_classify(ap, 1, &err); | ||
2290 | |||
2291 | DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]); | ||
2292 | return 0; | ||
2293 | } | ||
2294 | |||
2295 | /** | ||
2296 | * sata_std_hardreset - reset host port via SATA phy reset | ||
2297 | * @ap: port to reset | ||
2298 | * @verbose: fail verbosely | ||
2299 | * @class: resulting class of attached device | ||
2300 | * | ||
2301 | * SATA phy-reset host port using DET bits of SControl register. | ||
2302 | * This function is to be used as standard callback for | ||
2303 | * ata_drive_*_reset(). | ||
2304 | * | ||
2305 | * LOCKING: | ||
2306 | * Kernel thread context (may sleep) | ||
2307 | * | ||
2308 | * RETURNS: | ||
2309 | * 0 on success, -errno otherwise. | ||
2310 | */ | ||
2311 | int sata_std_hardreset(struct ata_port *ap, int verbose, unsigned int *class) | ||
2312 | { | ||
2313 | u32 sstatus, serror; | ||
2314 | unsigned long timeout = jiffies + (HZ * 5); | ||
2315 | |||
2316 | DPRINTK("ENTER\n"); | ||
2317 | |||
2318 | /* Issue phy wake/reset */ | ||
2319 | scr_write_flush(ap, SCR_CONTROL, 0x301); | ||
2320 | |||
2321 | /* | ||
2322 | * Couldn't find anything in SATA I/II specs, but AHCI-1.1 | ||
2323 | * 10.4.2 says at least 1 ms. | ||
2324 | */ | ||
2325 | msleep(1); | ||
2326 | |||
2327 | scr_write_flush(ap, SCR_CONTROL, 0x300); | ||
2328 | |||
2329 | /* Wait for phy to become ready, if necessary. */ | ||
2330 | do { | ||
2331 | msleep(200); | ||
2332 | sstatus = scr_read(ap, SCR_STATUS); | ||
2333 | if ((sstatus & 0xf) != 1) | ||
2334 | break; | ||
2335 | } while (time_before(jiffies, timeout)); | ||
2336 | |||
2337 | /* Clear SError */ | ||
2338 | serror = scr_read(ap, SCR_ERROR); | ||
2339 | scr_write(ap, SCR_ERROR, serror); | ||
2340 | |||
2341 | /* TODO: phy layer with polling, timeouts, etc. */ | ||
2342 | if (!sata_dev_present(ap)) { | ||
2343 | *class = ATA_DEV_NONE; | ||
2344 | DPRINTK("EXIT, link offline\n"); | ||
2345 | return 0; | ||
2346 | } | ||
2347 | |||
2348 | if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { | ||
2349 | if (verbose) | ||
2350 | printk(KERN_ERR "ata%u: COMRESET failed " | ||
2351 | "(device not ready)\n", ap->id); | ||
2352 | else | ||
2353 | DPRINTK("EXIT, device not ready\n"); | ||
2354 | return -EIO; | ||
2355 | } | ||
2356 | |||
2357 | *class = ata_dev_try_classify(ap, 0, NULL); | ||
2358 | |||
2359 | DPRINTK("EXIT, class=%u\n", *class); | ||
2360 | return 0; | ||
2361 | } | ||
2362 | |||
2363 | /** | ||
2364 | * ata_std_postreset - standard postreset callback | ||
2365 | * @ap: the target ata_port | ||
2366 | * @classes: classes of attached devices | ||
2367 | * | ||
2368 | * This function is invoked after a successful reset. Note that | ||
2369 | * the device might have been reset more than once using | ||
2370 | * different reset methods before postreset is invoked. | ||
2371 | * postreset is also reponsible for setting cable type. | ||
2372 | * | ||
2373 | * This function is to be used as standard callback for | ||
2374 | * ata_drive_*_reset(). | ||
2375 | * | ||
2376 | * LOCKING: | ||
2377 | * Kernel thread context (may sleep) | ||
2378 | */ | ||
2379 | void ata_std_postreset(struct ata_port *ap, unsigned int *classes) | ||
2380 | { | ||
2381 | DPRINTK("ENTER\n"); | ||
2382 | |||
2383 | /* set cable type */ | ||
2384 | if (ap->cbl == ATA_CBL_NONE && ap->flags & ATA_FLAG_SATA) | ||
2385 | ap->cbl = ATA_CBL_SATA; | ||
2386 | |||
2387 | /* print link status */ | ||
2388 | if (ap->cbl == ATA_CBL_SATA) | ||
2389 | sata_print_link_status(ap); | ||
2390 | |||
2391 | /* bail out if no device is present */ | ||
2392 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { | ||
2393 | DPRINTK("EXIT, no device\n"); | ||
2394 | return; | ||
2395 | } | ||
2396 | |||
2397 | /* is double-select really necessary? */ | ||
2398 | if (classes[0] != ATA_DEV_NONE) | ||
2399 | ap->ops->dev_select(ap, 1); | ||
2400 | if (classes[1] != ATA_DEV_NONE) | ||
2401 | ap->ops->dev_select(ap, 0); | ||
2402 | |||
2403 | /* re-enable interrupts & set up device control */ | ||
2404 | if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ | ||
2405 | ata_irq_on(ap); | ||
2406 | |||
2407 | DPRINTK("EXIT\n"); | ||
2408 | } | ||
2409 | |||
2410 | /** | ||
2411 | * ata_std_probe_reset - standard probe reset method | ||
2412 | * @ap: prot to perform probe-reset | ||
2413 | * @classes: resulting classes of attached devices | ||
2414 | * | ||
2415 | * The stock off-the-shelf ->probe_reset method. | ||
2416 | * | ||
2417 | * LOCKING: | ||
2418 | * Kernel thread context (may sleep) | ||
2419 | * | ||
2420 | * RETURNS: | ||
2421 | * 0 on success, -errno otherwise. | ||
2422 | */ | ||
2423 | int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes) | ||
2424 | { | ||
2425 | ata_reset_fn_t hardreset; | ||
2426 | |||
2427 | hardreset = NULL; | ||
2428 | if (ap->cbl == ATA_CBL_SATA && ap->ops->scr_read) | ||
2429 | hardreset = sata_std_hardreset; | ||
2430 | |||
2431 | return ata_drive_probe_reset(ap, ata_std_softreset, hardreset, | ||
2432 | ata_std_postreset, classes); | ||
2433 | } | ||
2434 | |||
2435 | static int do_probe_reset(struct ata_port *ap, ata_reset_fn_t reset, | ||
2436 | ata_postreset_fn_t postreset, | ||
2437 | unsigned int *classes) | ||
2438 | { | ||
2439 | int i, rc; | ||
2440 | |||
2441 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
2442 | classes[i] = ATA_DEV_UNKNOWN; | ||
2443 | |||
2444 | rc = reset(ap, 0, classes); | ||
2445 | if (rc) | ||
2446 | return rc; | ||
2447 | |||
2448 | /* If any class isn't ATA_DEV_UNKNOWN, consider classification | ||
2449 | * is complete and convert all ATA_DEV_UNKNOWN to | ||
2450 | * ATA_DEV_NONE. | ||
2451 | */ | ||
2452 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
2453 | if (classes[i] != ATA_DEV_UNKNOWN) | ||
2454 | break; | ||
2455 | |||
2456 | if (i < ATA_MAX_DEVICES) | ||
2457 | for (i = 0; i < ATA_MAX_DEVICES; i++) | ||
2458 | if (classes[i] == ATA_DEV_UNKNOWN) | ||
2459 | classes[i] = ATA_DEV_NONE; | ||
2460 | |||
2461 | if (postreset) | ||
2462 | postreset(ap, classes); | ||
2463 | |||
2464 | return classes[0] != ATA_DEV_UNKNOWN ? 0 : -ENODEV; | ||
2465 | } | ||
2466 | |||
2467 | /** | ||
2468 | * ata_drive_probe_reset - Perform probe reset with given methods | ||
2469 | * @ap: port to reset | ||
2470 | * @softreset: softreset method (can be NULL) | ||
2471 | * @hardreset: hardreset method (can be NULL) | ||
2472 | * @postreset: postreset method (can be NULL) | ||
2473 | * @classes: resulting classes of attached devices | ||
2474 | * | ||
2475 | * Reset the specified port and classify attached devices using | ||
2476 | * given methods. This function prefers softreset but tries all | ||
2477 | * possible reset sequences to reset and classify devices. This | ||
2478 | * function is intended to be used for constructing ->probe_reset | ||
2479 | * callback by low level drivers. | ||
2480 | * | ||
2481 | * Reset methods should follow the following rules. | ||
2482 | * | ||
2483 | * - Return 0 on sucess, -errno on failure. | ||
2484 | * - If classification is supported, fill classes[] with | ||
2485 | * recognized class codes. | ||
2486 | * - If classification is not supported, leave classes[] alone. | ||
2487 | * - If verbose is non-zero, print error message on failure; | ||
2488 | * otherwise, shut up. | ||
2489 | * | ||
2490 | * LOCKING: | ||
2491 | * Kernel thread context (may sleep) | ||
2492 | * | ||
2493 | * RETURNS: | ||
2494 | * 0 on success, -EINVAL if no reset method is avaliable, -ENODEV | ||
2495 | * if classification fails, and any error code from reset | ||
2496 | * methods. | ||
2497 | */ | ||
2498 | int ata_drive_probe_reset(struct ata_port *ap, | ||
2499 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, | ||
2500 | ata_postreset_fn_t postreset, unsigned int *classes) | ||
2501 | { | ||
2502 | int rc = -EINVAL; | ||
2503 | |||
2504 | if (softreset) { | ||
2505 | rc = do_probe_reset(ap, softreset, postreset, classes); | ||
2506 | if (rc == 0) | ||
2507 | return 0; | ||
2508 | } | ||
2509 | |||
2510 | if (!hardreset) | ||
2511 | return rc; | ||
2512 | |||
2513 | rc = do_probe_reset(ap, hardreset, postreset, classes); | ||
2514 | if (rc == 0 || rc != -ENODEV) | ||
2515 | return rc; | ||
2516 | |||
2517 | if (softreset) | ||
2518 | rc = do_probe_reset(ap, softreset, postreset, classes); | ||
2519 | |||
2520 | return rc; | ||
2521 | } | ||
2522 | |||
2195 | static void ata_pr_blacklisted(const struct ata_port *ap, | 2523 | static void ata_pr_blacklisted(const struct ata_port *ap, |
2196 | const struct ata_device *dev) | 2524 | const struct ata_device *dev) |
2197 | { | 2525 | { |
@@ -2869,7 +3197,7 @@ void ata_poll_qc_complete(struct ata_queued_cmd *qc) | |||
2869 | } | 3197 | } |
2870 | 3198 | ||
2871 | /** | 3199 | /** |
2872 | * ata_pio_poll - | 3200 | * ata_pio_poll - poll using PIO, depending on current state |
2873 | * @ap: the target ata_port | 3201 | * @ap: the target ata_port |
2874 | * | 3202 | * |
2875 | * LOCKING: | 3203 | * LOCKING: |
@@ -2908,7 +3236,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
2908 | status = ata_chk_status(ap); | 3236 | status = ata_chk_status(ap); |
2909 | if (status & ATA_BUSY) { | 3237 | if (status & ATA_BUSY) { |
2910 | if (time_after(jiffies, ap->pio_task_timeout)) { | 3238 | if (time_after(jiffies, ap->pio_task_timeout)) { |
2911 | qc->err_mask |= AC_ERR_ATA_BUS; | 3239 | qc->err_mask |= AC_ERR_TIMEOUT; |
2912 | ap->hsm_task_state = HSM_ST_TMOUT; | 3240 | ap->hsm_task_state = HSM_ST_TMOUT; |
2913 | return 0; | 3241 | return 0; |
2914 | } | 3242 | } |
@@ -2976,7 +3304,7 @@ static int ata_pio_complete (struct ata_port *ap) | |||
2976 | 3304 | ||
2977 | 3305 | ||
2978 | /** | 3306 | /** |
2979 | * swap_buf_le16 - swap halves of 16-words in place | 3307 | * swap_buf_le16 - swap halves of 16-bit words in place |
2980 | * @buf: Buffer to swap | 3308 | * @buf: Buffer to swap |
2981 | * @buf_words: Number of 16-bit words in buffer. | 3309 | * @buf_words: Number of 16-bit words in buffer. |
2982 | * | 3310 | * |
@@ -3286,7 +3614,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc) | |||
3286 | err_out: | 3614 | err_out: |
3287 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", | 3615 | printk(KERN_INFO "ata%u: dev %u: ATAPI check failed\n", |
3288 | ap->id, dev->devno); | 3616 | ap->id, dev->devno); |
3289 | qc->err_mask |= AC_ERR_ATA_BUS; | 3617 | qc->err_mask |= AC_ERR_HSM; |
3290 | ap->hsm_task_state = HSM_ST_ERR; | 3618 | ap->hsm_task_state = HSM_ST_ERR; |
3291 | } | 3619 | } |
3292 | 3620 | ||
@@ -3344,7 +3672,7 @@ static void ata_pio_block(struct ata_port *ap) | |||
3344 | } else { | 3672 | } else { |
3345 | /* handle BSY=0, DRQ=0 as error */ | 3673 | /* handle BSY=0, DRQ=0 as error */ |
3346 | if ((status & ATA_DRQ) == 0) { | 3674 | if ((status & ATA_DRQ) == 0) { |
3347 | qc->err_mask |= AC_ERR_ATA_BUS; | 3675 | qc->err_mask |= AC_ERR_HSM; |
3348 | ap->hsm_task_state = HSM_ST_ERR; | 3676 | ap->hsm_task_state = HSM_ST_ERR; |
3349 | return; | 3677 | return; |
3350 | } | 3678 | } |
@@ -3406,7 +3734,7 @@ fsm_start: | |||
3406 | } | 3734 | } |
3407 | 3735 | ||
3408 | if (timeout) | 3736 | if (timeout) |
3409 | queue_delayed_work(ata_wq, &ap->pio_task, timeout); | 3737 | ata_queue_delayed_pio_task(ap, timeout); |
3410 | else if (!qc_completed) | 3738 | else if (!qc_completed) |
3411 | goto fsm_start; | 3739 | goto fsm_start; |
3412 | } | 3740 | } |
@@ -3441,14 +3769,6 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
3441 | 3769 | ||
3442 | spin_lock_irqsave(&host_set->lock, flags); | 3770 | spin_lock_irqsave(&host_set->lock, flags); |
3443 | 3771 | ||
3444 | /* hack alert! We cannot use the supplied completion | ||
3445 | * function from inside the ->eh_strategy_handler() thread. | ||
3446 | * libata is the only user of ->eh_strategy_handler() in | ||
3447 | * any kernel, so the default scsi_done() assumes it is | ||
3448 | * not being called from the SCSI EH. | ||
3449 | */ | ||
3450 | qc->scsidone = scsi_finish_command; | ||
3451 | |||
3452 | switch (qc->tf.protocol) { | 3772 | switch (qc->tf.protocol) { |
3453 | 3773 | ||
3454 | case ATA_PROT_DMA: | 3774 | case ATA_PROT_DMA: |
@@ -3472,12 +3792,13 @@ static void ata_qc_timeout(struct ata_queued_cmd *qc) | |||
3472 | 3792 | ||
3473 | /* complete taskfile transaction */ | 3793 | /* complete taskfile transaction */ |
3474 | qc->err_mask |= ac_err_mask(drv_stat); | 3794 | qc->err_mask |= ac_err_mask(drv_stat); |
3475 | ata_qc_complete(qc); | ||
3476 | break; | 3795 | break; |
3477 | } | 3796 | } |
3478 | 3797 | ||
3479 | spin_unlock_irqrestore(&host_set->lock, flags); | 3798 | spin_unlock_irqrestore(&host_set->lock, flags); |
3480 | 3799 | ||
3800 | ata_eh_qc_complete(qc); | ||
3801 | |||
3481 | DPRINTK("EXIT\n"); | 3802 | DPRINTK("EXIT\n"); |
3482 | } | 3803 | } |
3483 | 3804 | ||
@@ -3571,21 +3892,6 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | |||
3571 | return qc; | 3892 | return qc; |
3572 | } | 3893 | } |
3573 | 3894 | ||
3574 | static void __ata_qc_complete(struct ata_queued_cmd *qc) | ||
3575 | { | ||
3576 | struct ata_port *ap = qc->ap; | ||
3577 | unsigned int tag; | ||
3578 | |||
3579 | qc->flags = 0; | ||
3580 | tag = qc->tag; | ||
3581 | if (likely(ata_tag_valid(tag))) { | ||
3582 | if (tag == ap->active_tag) | ||
3583 | ap->active_tag = ATA_TAG_POISON; | ||
3584 | qc->tag = ATA_TAG_POISON; | ||
3585 | clear_bit(tag, &ap->qactive); | ||
3586 | } | ||
3587 | } | ||
3588 | |||
3589 | /** | 3895 | /** |
3590 | * ata_qc_free - free unused ata_queued_cmd | 3896 | * ata_qc_free - free unused ata_queued_cmd |
3591 | * @qc: Command to complete | 3897 | * @qc: Command to complete |
@@ -3598,9 +3904,19 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc) | |||
3598 | */ | 3904 | */ |
3599 | void ata_qc_free(struct ata_queued_cmd *qc) | 3905 | void ata_qc_free(struct ata_queued_cmd *qc) |
3600 | { | 3906 | { |
3907 | struct ata_port *ap = qc->ap; | ||
3908 | unsigned int tag; | ||
3909 | |||
3601 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ | 3910 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ |
3602 | 3911 | ||
3603 | __ata_qc_complete(qc); | 3912 | qc->flags = 0; |
3913 | tag = qc->tag; | ||
3914 | if (likely(ata_tag_valid(tag))) { | ||
3915 | if (tag == ap->active_tag) | ||
3916 | ap->active_tag = ATA_TAG_POISON; | ||
3917 | qc->tag = ATA_TAG_POISON; | ||
3918 | clear_bit(tag, &ap->qactive); | ||
3919 | } | ||
3604 | } | 3920 | } |
3605 | 3921 | ||
3606 | /** | 3922 | /** |
@@ -3617,8 +3933,6 @@ void ata_qc_free(struct ata_queued_cmd *qc) | |||
3617 | 3933 | ||
3618 | void ata_qc_complete(struct ata_queued_cmd *qc) | 3934 | void ata_qc_complete(struct ata_queued_cmd *qc) |
3619 | { | 3935 | { |
3620 | int rc; | ||
3621 | |||
3622 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ | 3936 | assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ |
3623 | assert(qc->flags & ATA_QCFLAG_ACTIVE); | 3937 | assert(qc->flags & ATA_QCFLAG_ACTIVE); |
3624 | 3938 | ||
@@ -3632,17 +3946,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc) | |||
3632 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | 3946 | qc->flags &= ~ATA_QCFLAG_ACTIVE; |
3633 | 3947 | ||
3634 | /* call completion callback */ | 3948 | /* call completion callback */ |
3635 | rc = qc->complete_fn(qc); | 3949 | qc->complete_fn(qc); |
3636 | |||
3637 | /* if callback indicates not to complete command (non-zero), | ||
3638 | * return immediately | ||
3639 | */ | ||
3640 | if (rc != 0) | ||
3641 | return; | ||
3642 | |||
3643 | __ata_qc_complete(qc); | ||
3644 | |||
3645 | VPRINTK("EXIT\n"); | ||
3646 | } | 3950 | } |
3647 | 3951 | ||
3648 | static inline int ata_should_dma_map(struct ata_queued_cmd *qc) | 3952 | static inline int ata_should_dma_map(struct ata_queued_cmd *qc) |
@@ -3682,20 +3986,20 @@ static inline int ata_should_dma_map(struct ata_queued_cmd *qc) | |||
3682 | * spin_lock_irqsave(host_set lock) | 3986 | * spin_lock_irqsave(host_set lock) |
3683 | * | 3987 | * |
3684 | * RETURNS: | 3988 | * RETURNS: |
3685 | * Zero on success, negative on error. | 3989 | * Zero on success, AC_ERR_* mask on failure |
3686 | */ | 3990 | */ |
3687 | 3991 | ||
3688 | int ata_qc_issue(struct ata_queued_cmd *qc) | 3992 | unsigned int ata_qc_issue(struct ata_queued_cmd *qc) |
3689 | { | 3993 | { |
3690 | struct ata_port *ap = qc->ap; | 3994 | struct ata_port *ap = qc->ap; |
3691 | 3995 | ||
3692 | if (ata_should_dma_map(qc)) { | 3996 | if (ata_should_dma_map(qc)) { |
3693 | if (qc->flags & ATA_QCFLAG_SG) { | 3997 | if (qc->flags & ATA_QCFLAG_SG) { |
3694 | if (ata_sg_setup(qc)) | 3998 | if (ata_sg_setup(qc)) |
3695 | goto err_out; | 3999 | goto sg_err; |
3696 | } else if (qc->flags & ATA_QCFLAG_SINGLE) { | 4000 | } else if (qc->flags & ATA_QCFLAG_SINGLE) { |
3697 | if (ata_sg_setup_one(qc)) | 4001 | if (ata_sg_setup_one(qc)) |
3698 | goto err_out; | 4002 | goto sg_err; |
3699 | } | 4003 | } |
3700 | } else { | 4004 | } else { |
3701 | qc->flags &= ~ATA_QCFLAG_DMAMAP; | 4005 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
@@ -3708,8 +4012,9 @@ int ata_qc_issue(struct ata_queued_cmd *qc) | |||
3708 | 4012 | ||
3709 | return ap->ops->qc_issue(qc); | 4013 | return ap->ops->qc_issue(qc); |
3710 | 4014 | ||
3711 | err_out: | 4015 | sg_err: |
3712 | return -1; | 4016 | qc->flags &= ~ATA_QCFLAG_DMAMAP; |
4017 | return AC_ERR_SYSTEM; | ||
3713 | } | 4018 | } |
3714 | 4019 | ||
3715 | 4020 | ||
@@ -3728,10 +4033,10 @@ err_out: | |||
3728 | * spin_lock_irqsave(host_set lock) | 4033 | * spin_lock_irqsave(host_set lock) |
3729 | * | 4034 | * |
3730 | * RETURNS: | 4035 | * RETURNS: |
3731 | * Zero on success, negative on error. | 4036 | * Zero on success, AC_ERR_* mask on failure |
3732 | */ | 4037 | */ |
3733 | 4038 | ||
3734 | int ata_qc_issue_prot(struct ata_queued_cmd *qc) | 4039 | unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc) |
3735 | { | 4040 | { |
3736 | struct ata_port *ap = qc->ap; | 4041 | struct ata_port *ap = qc->ap; |
3737 | 4042 | ||
@@ -3752,31 +4057,31 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
3752 | ata_qc_set_polling(qc); | 4057 | ata_qc_set_polling(qc); |
3753 | ata_tf_to_host(ap, &qc->tf); | 4058 | ata_tf_to_host(ap, &qc->tf); |
3754 | ap->hsm_task_state = HSM_ST; | 4059 | ap->hsm_task_state = HSM_ST; |
3755 | queue_work(ata_wq, &ap->pio_task); | 4060 | ata_queue_pio_task(ap); |
3756 | break; | 4061 | break; |
3757 | 4062 | ||
3758 | case ATA_PROT_ATAPI: | 4063 | case ATA_PROT_ATAPI: |
3759 | ata_qc_set_polling(qc); | 4064 | ata_qc_set_polling(qc); |
3760 | ata_tf_to_host(ap, &qc->tf); | 4065 | ata_tf_to_host(ap, &qc->tf); |
3761 | queue_work(ata_wq, &ap->packet_task); | 4066 | ata_queue_packet_task(ap); |
3762 | break; | 4067 | break; |
3763 | 4068 | ||
3764 | case ATA_PROT_ATAPI_NODATA: | 4069 | case ATA_PROT_ATAPI_NODATA: |
3765 | ap->flags |= ATA_FLAG_NOINTR; | 4070 | ap->flags |= ATA_FLAG_NOINTR; |
3766 | ata_tf_to_host(ap, &qc->tf); | 4071 | ata_tf_to_host(ap, &qc->tf); |
3767 | queue_work(ata_wq, &ap->packet_task); | 4072 | ata_queue_packet_task(ap); |
3768 | break; | 4073 | break; |
3769 | 4074 | ||
3770 | case ATA_PROT_ATAPI_DMA: | 4075 | case ATA_PROT_ATAPI_DMA: |
3771 | ap->flags |= ATA_FLAG_NOINTR; | 4076 | ap->flags |= ATA_FLAG_NOINTR; |
3772 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ | 4077 | ap->ops->tf_load(ap, &qc->tf); /* load tf registers */ |
3773 | ap->ops->bmdma_setup(qc); /* set up bmdma */ | 4078 | ap->ops->bmdma_setup(qc); /* set up bmdma */ |
3774 | queue_work(ata_wq, &ap->packet_task); | 4079 | ata_queue_packet_task(ap); |
3775 | break; | 4080 | break; |
3776 | 4081 | ||
3777 | default: | 4082 | default: |
3778 | WARN_ON(1); | 4083 | WARN_ON(1); |
3779 | return -1; | 4084 | return AC_ERR_SYSTEM; |
3780 | } | 4085 | } |
3781 | 4086 | ||
3782 | return 0; | 4087 | return 0; |
@@ -4166,14 +4471,14 @@ static void atapi_packet_task(void *_data) | |||
4166 | /* sleep-wait for BSY to clear */ | 4471 | /* sleep-wait for BSY to clear */ |
4167 | DPRINTK("busy wait\n"); | 4472 | DPRINTK("busy wait\n"); |
4168 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { | 4473 | if (ata_busy_sleep(ap, ATA_TMOUT_CDB_QUICK, ATA_TMOUT_CDB)) { |
4169 | qc->err_mask |= AC_ERR_ATA_BUS; | 4474 | qc->err_mask |= AC_ERR_TIMEOUT; |
4170 | goto err_out; | 4475 | goto err_out; |
4171 | } | 4476 | } |
4172 | 4477 | ||
4173 | /* make sure DRQ is set */ | 4478 | /* make sure DRQ is set */ |
4174 | status = ata_chk_status(ap); | 4479 | status = ata_chk_status(ap); |
4175 | if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) { | 4480 | if ((status & (ATA_BUSY | ATA_DRQ)) != ATA_DRQ) { |
4176 | qc->err_mask |= AC_ERR_ATA_BUS; | 4481 | qc->err_mask |= AC_ERR_HSM; |
4177 | goto err_out; | 4482 | goto err_out; |
4178 | } | 4483 | } |
4179 | 4484 | ||
@@ -4202,7 +4507,7 @@ static void atapi_packet_task(void *_data) | |||
4202 | 4507 | ||
4203 | /* PIO commands are handled by polling */ | 4508 | /* PIO commands are handled by polling */ |
4204 | ap->hsm_task_state = HSM_ST; | 4509 | ap->hsm_task_state = HSM_ST; |
4205 | queue_work(ata_wq, &ap->pio_task); | 4510 | ata_queue_pio_task(ap); |
4206 | } | 4511 | } |
4207 | 4512 | ||
4208 | return; | 4513 | return; |
@@ -4212,19 +4517,6 @@ err_out: | |||
4212 | } | 4517 | } |
4213 | 4518 | ||
4214 | 4519 | ||
4215 | /** | ||
4216 | * ata_port_start - Set port up for dma. | ||
4217 | * @ap: Port to initialize | ||
4218 | * | ||
4219 | * Called just after data structures for each port are | ||
4220 | * initialized. Allocates space for PRD table. | ||
4221 | * | ||
4222 | * May be used as the port_start() entry in ata_port_operations. | ||
4223 | * | ||
4224 | * LOCKING: | ||
4225 | * Inherited from caller. | ||
4226 | */ | ||
4227 | |||
4228 | /* | 4520 | /* |
4229 | * Execute a 'simple' command, that only consists of the opcode 'cmd' itself, | 4521 | * Execute a 'simple' command, that only consists of the opcode 'cmd' itself, |
4230 | * without filling any other registers | 4522 | * without filling any other registers |
@@ -4276,6 +4568,8 @@ static int ata_start_drive(struct ata_port *ap, struct ata_device *dev) | |||
4276 | 4568 | ||
4277 | /** | 4569 | /** |
4278 | * ata_device_resume - wakeup a previously suspended devices | 4570 | * ata_device_resume - wakeup a previously suspended devices |
4571 | * @ap: port the device is connected to | ||
4572 | * @dev: the device to resume | ||
4279 | * | 4573 | * |
4280 | * Kick the drive back into action, by sending it an idle immediate | 4574 | * Kick the drive back into action, by sending it an idle immediate |
4281 | * command and making sure its transfer mode matches between drive | 4575 | * command and making sure its transfer mode matches between drive |
@@ -4298,10 +4592,11 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev) | |||
4298 | 4592 | ||
4299 | /** | 4593 | /** |
4300 | * ata_device_suspend - prepare a device for suspend | 4594 | * ata_device_suspend - prepare a device for suspend |
4595 | * @ap: port the device is connected to | ||
4596 | * @dev: the device to suspend | ||
4301 | * | 4597 | * |
4302 | * Flush the cache on the drive, if appropriate, then issue a | 4598 | * Flush the cache on the drive, if appropriate, then issue a |
4303 | * standbynow command. | 4599 | * standbynow command. |
4304 | * | ||
4305 | */ | 4600 | */ |
4306 | int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) | 4601 | int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) |
4307 | { | 4602 | { |
@@ -4315,6 +4610,19 @@ int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) | |||
4315 | return 0; | 4610 | return 0; |
4316 | } | 4611 | } |
4317 | 4612 | ||
4613 | /** | ||
4614 | * ata_port_start - Set port up for dma. | ||
4615 | * @ap: Port to initialize | ||
4616 | * | ||
4617 | * Called just after data structures for each port are | ||
4618 | * initialized. Allocates space for PRD table. | ||
4619 | * | ||
4620 | * May be used as the port_start() entry in ata_port_operations. | ||
4621 | * | ||
4622 | * LOCKING: | ||
4623 | * Inherited from caller. | ||
4624 | */ | ||
4625 | |||
4318 | int ata_port_start (struct ata_port *ap) | 4626 | int ata_port_start (struct ata_port *ap) |
4319 | { | 4627 | { |
4320 | struct device *dev = ap->host_set->dev; | 4628 | struct device *dev = ap->host_set->dev; |
@@ -4430,6 +4738,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | |||
4430 | 4738 | ||
4431 | INIT_WORK(&ap->packet_task, atapi_packet_task, ap); | 4739 | INIT_WORK(&ap->packet_task, atapi_packet_task, ap); |
4432 | INIT_WORK(&ap->pio_task, ata_pio_task, ap); | 4740 | INIT_WORK(&ap->pio_task, ata_pio_task, ap); |
4741 | INIT_LIST_HEAD(&ap->eh_done_q); | ||
4433 | 4742 | ||
4434 | for (i = 0; i < ATA_MAX_DEVICES; i++) | 4743 | for (i = 0; i < ATA_MAX_DEVICES; i++) |
4435 | ap->device[i].devno = i; | 4744 | ap->device[i].devno = i; |
@@ -4571,9 +4880,9 @@ int ata_device_add(const struct ata_probe_ent *ent) | |||
4571 | 4880 | ||
4572 | ap = host_set->ports[i]; | 4881 | ap = host_set->ports[i]; |
4573 | 4882 | ||
4574 | DPRINTK("ata%u: probe begin\n", ap->id); | 4883 | DPRINTK("ata%u: bus probe begin\n", ap->id); |
4575 | rc = ata_bus_probe(ap); | 4884 | rc = ata_bus_probe(ap); |
4576 | DPRINTK("ata%u: probe end\n", ap->id); | 4885 | DPRINTK("ata%u: bus probe end\n", ap->id); |
4577 | 4886 | ||
4578 | if (rc) { | 4887 | if (rc) { |
4579 | /* FIXME: do something useful here? | 4888 | /* FIXME: do something useful here? |
@@ -4597,7 +4906,7 @@ int ata_device_add(const struct ata_probe_ent *ent) | |||
4597 | } | 4906 | } |
4598 | 4907 | ||
4599 | /* probes are done, now scan each port's disk(s) */ | 4908 | /* probes are done, now scan each port's disk(s) */ |
4600 | DPRINTK("probe begin\n"); | 4909 | DPRINTK("host probe begin\n"); |
4601 | for (i = 0; i < count; i++) { | 4910 | for (i = 0; i < count; i++) { |
4602 | struct ata_port *ap = host_set->ports[i]; | 4911 | struct ata_port *ap = host_set->ports[i]; |
4603 | 4912 | ||
@@ -5161,8 +5470,14 @@ EXPORT_SYMBOL_GPL(ata_port_probe); | |||
5161 | EXPORT_SYMBOL_GPL(sata_phy_reset); | 5470 | EXPORT_SYMBOL_GPL(sata_phy_reset); |
5162 | EXPORT_SYMBOL_GPL(__sata_phy_reset); | 5471 | EXPORT_SYMBOL_GPL(__sata_phy_reset); |
5163 | EXPORT_SYMBOL_GPL(ata_bus_reset); | 5472 | EXPORT_SYMBOL_GPL(ata_bus_reset); |
5473 | EXPORT_SYMBOL_GPL(ata_std_softreset); | ||
5474 | EXPORT_SYMBOL_GPL(sata_std_hardreset); | ||
5475 | EXPORT_SYMBOL_GPL(ata_std_postreset); | ||
5476 | EXPORT_SYMBOL_GPL(ata_std_probe_reset); | ||
5477 | EXPORT_SYMBOL_GPL(ata_drive_probe_reset); | ||
5164 | EXPORT_SYMBOL_GPL(ata_port_disable); | 5478 | EXPORT_SYMBOL_GPL(ata_port_disable); |
5165 | EXPORT_SYMBOL_GPL(ata_ratelimit); | 5479 | EXPORT_SYMBOL_GPL(ata_ratelimit); |
5480 | EXPORT_SYMBOL_GPL(ata_busy_sleep); | ||
5166 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); | 5481 | EXPORT_SYMBOL_GPL(ata_scsi_ioctl); |
5167 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); | 5482 | EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); |
5168 | EXPORT_SYMBOL_GPL(ata_scsi_error); | 5483 | EXPORT_SYMBOL_GPL(ata_scsi_error); |
@@ -5173,6 +5488,8 @@ EXPORT_SYMBOL_GPL(ata_dev_classify); | |||
5173 | EXPORT_SYMBOL_GPL(ata_dev_id_string); | 5488 | EXPORT_SYMBOL_GPL(ata_dev_id_string); |
5174 | EXPORT_SYMBOL_GPL(ata_dev_config); | 5489 | EXPORT_SYMBOL_GPL(ata_dev_config); |
5175 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); | 5490 | EXPORT_SYMBOL_GPL(ata_scsi_simulate); |
5491 | EXPORT_SYMBOL_GPL(ata_eh_qc_complete); | ||
5492 | EXPORT_SYMBOL_GPL(ata_eh_qc_retry); | ||
5176 | 5493 | ||
5177 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); | 5494 | EXPORT_SYMBOL_GPL(ata_pio_need_iordy); |
5178 | EXPORT_SYMBOL_GPL(ata_timing_compute); | 5495 | EXPORT_SYMBOL_GPL(ata_timing_compute); |
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c index cfbceb504718..6df82934d2d6 100644 --- a/drivers/scsi/libata-scsi.c +++ b/drivers/scsi/libata-scsi.c | |||
@@ -151,7 +151,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
151 | struct scsi_sense_hdr sshdr; | 151 | struct scsi_sense_hdr sshdr; |
152 | enum dma_data_direction data_dir; | 152 | enum dma_data_direction data_dir; |
153 | 153 | ||
154 | if (NULL == (void *)arg) | 154 | if (arg == NULL) |
155 | return -EINVAL; | 155 | return -EINVAL; |
156 | 156 | ||
157 | if (copy_from_user(args, arg, sizeof(args))) | 157 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -201,7 +201,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
201 | /* Need code to retrieve data from check condition? */ | 201 | /* Need code to retrieve data from check condition? */ |
202 | 202 | ||
203 | if ((argbuf) | 203 | if ((argbuf) |
204 | && copy_to_user((void *)(arg + sizeof(args)), argbuf, argsize)) | 204 | && copy_to_user(arg + sizeof(args), argbuf, argsize)) |
205 | rc = -EFAULT; | 205 | rc = -EFAULT; |
206 | error: | 206 | error: |
207 | if (argbuf) | 207 | if (argbuf) |
@@ -228,7 +228,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) | |||
228 | u8 args[7]; | 228 | u8 args[7]; |
229 | struct scsi_sense_hdr sshdr; | 229 | struct scsi_sense_hdr sshdr; |
230 | 230 | ||
231 | if (NULL == (void *)arg) | 231 | if (arg == NULL) |
232 | return -EINVAL; | 232 | return -EINVAL; |
233 | 233 | ||
234 | if (copy_from_user(args, arg, sizeof(args))) | 234 | if (copy_from_user(args, arg, sizeof(args))) |
@@ -738,17 +738,64 @@ int ata_scsi_error(struct Scsi_Host *host) | |||
738 | ap = (struct ata_port *) &host->hostdata[0]; | 738 | ap = (struct ata_port *) &host->hostdata[0]; |
739 | ap->ops->eng_timeout(ap); | 739 | ap->ops->eng_timeout(ap); |
740 | 740 | ||
741 | /* TODO: this is per-command; when queueing is supported | 741 | assert(host->host_failed == 0 && list_empty(&host->eh_cmd_q)); |
742 | * this code will either change or move to a more | 742 | |
743 | * appropriate place | 743 | scsi_eh_flush_done_q(&ap->eh_done_q); |
744 | */ | ||
745 | host->host_failed--; | ||
746 | INIT_LIST_HEAD(&host->eh_cmd_q); | ||
747 | 744 | ||
748 | DPRINTK("EXIT\n"); | 745 | DPRINTK("EXIT\n"); |
749 | return 0; | 746 | return 0; |
750 | } | 747 | } |
751 | 748 | ||
749 | static void ata_eh_scsidone(struct scsi_cmnd *scmd) | ||
750 | { | ||
751 | /* nada */ | ||
752 | } | ||
753 | |||
754 | static void __ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
755 | { | ||
756 | struct ata_port *ap = qc->ap; | ||
757 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
758 | unsigned long flags; | ||
759 | |||
760 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
761 | qc->scsidone = ata_eh_scsidone; | ||
762 | ata_qc_complete(qc); | ||
763 | assert(!ata_tag_valid(qc->tag)); | ||
764 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
765 | |||
766 | scsi_eh_finish_cmd(scmd, &ap->eh_done_q); | ||
767 | } | ||
768 | |||
769 | /** | ||
770 | * ata_eh_qc_complete - Complete an active ATA command from EH | ||
771 | * @qc: Command to complete | ||
772 | * | ||
773 | * Indicate to the mid and upper layers that an ATA command has | ||
774 | * completed. To be used from EH. | ||
775 | */ | ||
776 | void ata_eh_qc_complete(struct ata_queued_cmd *qc) | ||
777 | { | ||
778 | struct scsi_cmnd *scmd = qc->scsicmd; | ||
779 | scmd->retries = scmd->allowed; | ||
780 | __ata_eh_qc_complete(qc); | ||
781 | } | ||
782 | |||
783 | /** | ||
784 | * ata_eh_qc_retry - Tell midlayer to retry an ATA command after EH | ||
785 | * @qc: Command to retry | ||
786 | * | ||
787 | * Indicate to the mid and upper layers that an ATA command | ||
788 | * should be retried. To be used from EH. | ||
789 | * | ||
790 | * SCSI midlayer limits the number of retries to scmd->allowed. | ||
791 | * This function might need to adjust scmd->retries for commands | ||
792 | * which get retried due to unrelated NCQ failures. | ||
793 | */ | ||
794 | void ata_eh_qc_retry(struct ata_queued_cmd *qc) | ||
795 | { | ||
796 | __ata_eh_qc_complete(qc); | ||
797 | } | ||
798 | |||
752 | /** | 799 | /** |
753 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command | 800 | * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command |
754 | * @qc: Storage for translated ATA taskfile | 801 | * @qc: Storage for translated ATA taskfile |
@@ -985,9 +1032,13 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
985 | if (dev->flags & ATA_DFLAG_LBA) { | 1032 | if (dev->flags & ATA_DFLAG_LBA) { |
986 | tf->flags |= ATA_TFLAG_LBA; | 1033 | tf->flags |= ATA_TFLAG_LBA; |
987 | 1034 | ||
988 | if (dev->flags & ATA_DFLAG_LBA48) { | 1035 | if (lba_28_ok(block, n_block)) { |
989 | if (n_block > (64 * 1024)) | 1036 | /* use LBA28 */ |
990 | goto invalid_fld; | 1037 | tf->command = ATA_CMD_VERIFY; |
1038 | tf->device |= (block >> 24) & 0xf; | ||
1039 | } else if (lba_48_ok(block, n_block)) { | ||
1040 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1041 | goto out_of_range; | ||
991 | 1042 | ||
992 | /* use LBA48 */ | 1043 | /* use LBA48 */ |
993 | tf->flags |= ATA_TFLAG_LBA48; | 1044 | tf->flags |= ATA_TFLAG_LBA48; |
@@ -998,15 +1049,9 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
998 | tf->hob_lbah = (block >> 40) & 0xff; | 1049 | tf->hob_lbah = (block >> 40) & 0xff; |
999 | tf->hob_lbam = (block >> 32) & 0xff; | 1050 | tf->hob_lbam = (block >> 32) & 0xff; |
1000 | tf->hob_lbal = (block >> 24) & 0xff; | 1051 | tf->hob_lbal = (block >> 24) & 0xff; |
1001 | } else { | 1052 | } else |
1002 | if (n_block > 256) | 1053 | /* request too large even for LBA48 */ |
1003 | goto invalid_fld; | 1054 | goto out_of_range; |
1004 | |||
1005 | /* use LBA28 */ | ||
1006 | tf->command = ATA_CMD_VERIFY; | ||
1007 | |||
1008 | tf->device |= (block >> 24) & 0xf; | ||
1009 | } | ||
1010 | 1055 | ||
1011 | tf->nsect = n_block & 0xff; | 1056 | tf->nsect = n_block & 0xff; |
1012 | 1057 | ||
@@ -1019,8 +1064,8 @@ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc, const u8 *sc | |||
1019 | /* CHS */ | 1064 | /* CHS */ |
1020 | u32 sect, head, cyl, track; | 1065 | u32 sect, head, cyl, track; |
1021 | 1066 | ||
1022 | if (n_block > 256) | 1067 | if (!lba_28_ok(block, n_block)) |
1023 | goto invalid_fld; | 1068 | goto out_of_range; |
1024 | 1069 | ||
1025 | /* Convert LBA to CHS */ | 1070 | /* Convert LBA to CHS */ |
1026 | track = (u32)block / dev->sectors; | 1071 | track = (u32)block / dev->sectors; |
@@ -1139,9 +1184,11 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1139 | if (dev->flags & ATA_DFLAG_LBA) { | 1184 | if (dev->flags & ATA_DFLAG_LBA) { |
1140 | tf->flags |= ATA_TFLAG_LBA; | 1185 | tf->flags |= ATA_TFLAG_LBA; |
1141 | 1186 | ||
1142 | if (dev->flags & ATA_DFLAG_LBA48) { | 1187 | if (lba_28_ok(block, n_block)) { |
1143 | /* The request -may- be too large for LBA48. */ | 1188 | /* use LBA28 */ |
1144 | if ((block >> 48) || (n_block > 65536)) | 1189 | tf->device |= (block >> 24) & 0xf; |
1190 | } else if (lba_48_ok(block, n_block)) { | ||
1191 | if (!(dev->flags & ATA_DFLAG_LBA48)) | ||
1145 | goto out_of_range; | 1192 | goto out_of_range; |
1146 | 1193 | ||
1147 | /* use LBA48 */ | 1194 | /* use LBA48 */ |
@@ -1152,15 +1199,9 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1152 | tf->hob_lbah = (block >> 40) & 0xff; | 1199 | tf->hob_lbah = (block >> 40) & 0xff; |
1153 | tf->hob_lbam = (block >> 32) & 0xff; | 1200 | tf->hob_lbam = (block >> 32) & 0xff; |
1154 | tf->hob_lbal = (block >> 24) & 0xff; | 1201 | tf->hob_lbal = (block >> 24) & 0xff; |
1155 | } else { | 1202 | } else |
1156 | /* use LBA28 */ | 1203 | /* request too large even for LBA48 */ |
1157 | 1204 | goto out_of_range; | |
1158 | /* The request -may- be too large for LBA28. */ | ||
1159 | if ((block >> 28) || (n_block > 256)) | ||
1160 | goto out_of_range; | ||
1161 | |||
1162 | tf->device |= (block >> 24) & 0xf; | ||
1163 | } | ||
1164 | 1205 | ||
1165 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1206 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
1166 | goto invalid_fld; | 1207 | goto invalid_fld; |
@@ -1178,7 +1219,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc, const u8 *scsicm | |||
1178 | u32 sect, head, cyl, track; | 1219 | u32 sect, head, cyl, track; |
1179 | 1220 | ||
1180 | /* The request -may- be too large for CHS addressing. */ | 1221 | /* The request -may- be too large for CHS addressing. */ |
1181 | if ((block >> 28) || (n_block > 256)) | 1222 | if (!lba_28_ok(block, n_block)) |
1182 | goto out_of_range; | 1223 | goto out_of_range; |
1183 | 1224 | ||
1184 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) | 1225 | if (unlikely(ata_rwcmd_protocol(qc) < 0)) |
@@ -1225,7 +1266,7 @@ nothing_to_do: | |||
1225 | return 1; | 1266 | return 1; |
1226 | } | 1267 | } |
1227 | 1268 | ||
1228 | static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | 1269 | static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) |
1229 | { | 1270 | { |
1230 | struct scsi_cmnd *cmd = qc->scsicmd; | 1271 | struct scsi_cmnd *cmd = qc->scsicmd; |
1231 | u8 *cdb = cmd->cmnd; | 1272 | u8 *cdb = cmd->cmnd; |
@@ -1262,7 +1303,7 @@ static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) | |||
1262 | 1303 | ||
1263 | qc->scsidone(cmd); | 1304 | qc->scsidone(cmd); |
1264 | 1305 | ||
1265 | return 0; | 1306 | ata_qc_free(qc); |
1266 | } | 1307 | } |
1267 | 1308 | ||
1268 | /** | 1309 | /** |
@@ -1328,8 +1369,9 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, | |||
1328 | goto early_finish; | 1369 | goto early_finish; |
1329 | 1370 | ||
1330 | /* select device, send command to hardware */ | 1371 | /* select device, send command to hardware */ |
1331 | if (ata_qc_issue(qc)) | 1372 | qc->err_mask = ata_qc_issue(qc); |
1332 | goto err_did; | 1373 | if (qc->err_mask) |
1374 | ata_qc_complete(qc); | ||
1333 | 1375 | ||
1334 | VPRINTK("EXIT\n"); | 1376 | VPRINTK("EXIT\n"); |
1335 | return; | 1377 | return; |
@@ -1988,7 +2030,7 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8 | |||
1988 | done(cmd); | 2030 | done(cmd); |
1989 | } | 2031 | } |
1990 | 2032 | ||
1991 | static int atapi_sense_complete(struct ata_queued_cmd *qc) | 2033 | static void atapi_sense_complete(struct ata_queued_cmd *qc) |
1992 | { | 2034 | { |
1993 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) | 2035 | if (qc->err_mask && ((qc->err_mask & AC_ERR_DEV) == 0)) |
1994 | /* FIXME: not quite right; we don't want the | 2036 | /* FIXME: not quite right; we don't want the |
@@ -1999,7 +2041,7 @@ static int atapi_sense_complete(struct ata_queued_cmd *qc) | |||
1999 | ata_gen_ata_desc_sense(qc); | 2041 | ata_gen_ata_desc_sense(qc); |
2000 | 2042 | ||
2001 | qc->scsidone(qc->scsicmd); | 2043 | qc->scsidone(qc->scsicmd); |
2002 | return 0; | 2044 | ata_qc_free(qc); |
2003 | } | 2045 | } |
2004 | 2046 | ||
2005 | /* is it pointless to prefer PIO for "safety reasons"? */ | 2047 | /* is it pointless to prefer PIO for "safety reasons"? */ |
@@ -2048,15 +2090,14 @@ static void atapi_request_sense(struct ata_queued_cmd *qc) | |||
2048 | 2090 | ||
2049 | qc->complete_fn = atapi_sense_complete; | 2091 | qc->complete_fn = atapi_sense_complete; |
2050 | 2092 | ||
2051 | if (ata_qc_issue(qc)) { | 2093 | qc->err_mask = ata_qc_issue(qc); |
2052 | qc->err_mask |= AC_ERR_OTHER; | 2094 | if (qc->err_mask) |
2053 | ata_qc_complete(qc); | 2095 | ata_qc_complete(qc); |
2054 | } | ||
2055 | 2096 | ||
2056 | DPRINTK("EXIT\n"); | 2097 | DPRINTK("EXIT\n"); |
2057 | } | 2098 | } |
2058 | 2099 | ||
2059 | static int atapi_qc_complete(struct ata_queued_cmd *qc) | 2100 | static void atapi_qc_complete(struct ata_queued_cmd *qc) |
2060 | { | 2101 | { |
2061 | struct scsi_cmnd *cmd = qc->scsicmd; | 2102 | struct scsi_cmnd *cmd = qc->scsicmd; |
2062 | unsigned int err_mask = qc->err_mask; | 2103 | unsigned int err_mask = qc->err_mask; |
@@ -2066,7 +2107,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2066 | if (unlikely(err_mask & AC_ERR_DEV)) { | 2107 | if (unlikely(err_mask & AC_ERR_DEV)) { |
2067 | cmd->result = SAM_STAT_CHECK_CONDITION; | 2108 | cmd->result = SAM_STAT_CHECK_CONDITION; |
2068 | atapi_request_sense(qc); | 2109 | atapi_request_sense(qc); |
2069 | return 1; | 2110 | return; |
2070 | } | 2111 | } |
2071 | 2112 | ||
2072 | else if (unlikely(err_mask)) | 2113 | else if (unlikely(err_mask)) |
@@ -2106,7 +2147,7 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc) | |||
2106 | } | 2147 | } |
2107 | 2148 | ||
2108 | qc->scsidone(cmd); | 2149 | qc->scsidone(cmd); |
2109 | return 0; | 2150 | ata_qc_free(qc); |
2110 | } | 2151 | } |
2111 | /** | 2152 | /** |
2112 | * atapi_xlat - Initialize PACKET taskfile | 2153 | * atapi_xlat - Initialize PACKET taskfile |
@@ -2492,7 +2533,8 @@ out_unlock: | |||
2492 | 2533 | ||
2493 | /** | 2534 | /** |
2494 | * ata_scsi_simulate - simulate SCSI command on ATA device | 2535 | * ata_scsi_simulate - simulate SCSI command on ATA device |
2495 | * @id: current IDENTIFY data for target device. | 2536 | * @ap: port the device is connected to |
2537 | * @dev: the target device | ||
2496 | * @cmd: SCSI command being sent to device. | 2538 | * @cmd: SCSI command being sent to device. |
2497 | * @done: SCSI command completion function. | 2539 | * @done: SCSI command completion function. |
2498 | * | 2540 | * |
diff --git a/drivers/scsi/libata.h b/drivers/scsi/libata.h index e03ce48b7b4b..9d76923a2253 100644 --- a/drivers/scsi/libata.h +++ b/drivers/scsi/libata.h | |||
@@ -45,7 +45,7 @@ extern struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | |||
45 | struct ata_device *dev); | 45 | struct ata_device *dev); |
46 | extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); | 46 | extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); |
47 | extern void ata_qc_free(struct ata_queued_cmd *qc); | 47 | extern void ata_qc_free(struct ata_queued_cmd *qc); |
48 | extern int ata_qc_issue(struct ata_queued_cmd *qc); | 48 | extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc); |
49 | extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); | 49 | extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); |
50 | extern void ata_dev_select(struct ata_port *ap, unsigned int device, | 50 | extern void ata_dev_select(struct ata_port *ap, unsigned int device, |
51 | unsigned int wait, unsigned int can_sleep); | 51 | unsigned int wait, unsigned int can_sleep); |
diff --git a/drivers/scsi/pdc_adma.c b/drivers/scsi/pdc_adma.c index e8df0c9ec1e6..3a6bf58dc37b 100644 --- a/drivers/scsi/pdc_adma.c +++ b/drivers/scsi/pdc_adma.c | |||
@@ -131,7 +131,7 @@ static void adma_host_stop(struct ata_host_set *host_set); | |||
131 | static void adma_port_stop(struct ata_port *ap); | 131 | static void adma_port_stop(struct ata_port *ap); |
132 | static void adma_phy_reset(struct ata_port *ap); | 132 | static void adma_phy_reset(struct ata_port *ap); |
133 | static void adma_qc_prep(struct ata_queued_cmd *qc); | 133 | static void adma_qc_prep(struct ata_queued_cmd *qc); |
134 | static int adma_qc_issue(struct ata_queued_cmd *qc); | 134 | static unsigned int adma_qc_issue(struct ata_queued_cmd *qc); |
135 | static int adma_check_atapi_dma(struct ata_queued_cmd *qc); | 135 | static int adma_check_atapi_dma(struct ata_queued_cmd *qc); |
136 | static void adma_bmdma_stop(struct ata_queued_cmd *qc); | 136 | static void adma_bmdma_stop(struct ata_queued_cmd *qc); |
137 | static u8 adma_bmdma_status(struct ata_port *ap); | 137 | static u8 adma_bmdma_status(struct ata_port *ap); |
@@ -419,7 +419,7 @@ static inline void adma_packet_start(struct ata_queued_cmd *qc) | |||
419 | writew(aPIOMD4 | aGO, chan + ADMA_CONTROL); | 419 | writew(aPIOMD4 | aGO, chan + ADMA_CONTROL); |
420 | } | 420 | } |
421 | 421 | ||
422 | static int adma_qc_issue(struct ata_queued_cmd *qc) | 422 | static unsigned int adma_qc_issue(struct ata_queued_cmd *qc) |
423 | { | 423 | { |
424 | struct adma_port_priv *pp = qc->ap->private_data; | 424 | struct adma_port_priv *pp = qc->ap->private_data; |
425 | 425 | ||
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c index cd54244058b5..d9a554ca45c7 100644 --- a/drivers/scsi/sata_mv.c +++ b/drivers/scsi/sata_mv.c | |||
@@ -328,7 +328,7 @@ static void mv_host_stop(struct ata_host_set *host_set); | |||
328 | static int mv_port_start(struct ata_port *ap); | 328 | static int mv_port_start(struct ata_port *ap); |
329 | static void mv_port_stop(struct ata_port *ap); | 329 | static void mv_port_stop(struct ata_port *ap); |
330 | static void mv_qc_prep(struct ata_queued_cmd *qc); | 330 | static void mv_qc_prep(struct ata_queued_cmd *qc); |
331 | static int mv_qc_issue(struct ata_queued_cmd *qc); | 331 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); |
332 | static irqreturn_t mv_interrupt(int irq, void *dev_instance, | 332 | static irqreturn_t mv_interrupt(int irq, void *dev_instance, |
333 | struct pt_regs *regs); | 333 | struct pt_regs *regs); |
334 | static void mv_eng_timeout(struct ata_port *ap); | 334 | static void mv_eng_timeout(struct ata_port *ap); |
@@ -1040,7 +1040,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
1040 | * LOCKING: | 1040 | * LOCKING: |
1041 | * Inherited from caller. | 1041 | * Inherited from caller. |
1042 | */ | 1042 | */ |
1043 | static int mv_qc_issue(struct ata_queued_cmd *qc) | 1043 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) |
1044 | { | 1044 | { |
1045 | void __iomem *port_mmio = mv_ap_base(qc->ap); | 1045 | void __iomem *port_mmio = mv_ap_base(qc->ap); |
1046 | struct mv_port_priv *pp = qc->ap->private_data; | 1046 | struct mv_port_priv *pp = qc->ap->private_data; |
@@ -1839,7 +1839,6 @@ static void mv_phy_reset(struct ata_port *ap) | |||
1839 | static void mv_eng_timeout(struct ata_port *ap) | 1839 | static void mv_eng_timeout(struct ata_port *ap) |
1840 | { | 1840 | { |
1841 | struct ata_queued_cmd *qc; | 1841 | struct ata_queued_cmd *qc; |
1842 | unsigned long flags; | ||
1843 | 1842 | ||
1844 | printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id); | 1843 | printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id); |
1845 | DPRINTK("All regs @ start of eng_timeout\n"); | 1844 | DPRINTK("All regs @ start of eng_timeout\n"); |
@@ -1858,17 +1857,8 @@ static void mv_eng_timeout(struct ata_port *ap) | |||
1858 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", | 1857 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", |
1859 | ap->id); | 1858 | ap->id); |
1860 | } else { | 1859 | } else { |
1861 | /* hack alert! We cannot use the supplied completion | 1860 | qc->err_mask |= AC_ERR_TIMEOUT; |
1862 | * function from inside the ->eh_strategy_handler() thread. | 1861 | ata_eh_qc_complete(qc); |
1863 | * libata is the only user of ->eh_strategy_handler() in | ||
1864 | * any kernel, so the default scsi_done() assumes it is | ||
1865 | * not being called from the SCSI EH. | ||
1866 | */ | ||
1867 | spin_lock_irqsave(&ap->host_set->lock, flags); | ||
1868 | qc->scsidone = scsi_finish_command; | ||
1869 | qc->err_mask |= AC_ERR_OTHER; | ||
1870 | ata_qc_complete(qc); | ||
1871 | spin_unlock_irqrestore(&ap->host_set->lock, flags); | ||
1872 | } | 1862 | } |
1873 | } | 1863 | } |
1874 | 1864 | ||
diff --git a/drivers/scsi/sata_promise.c b/drivers/scsi/sata_promise.c index b0b0a69b3563..0950a8e45814 100644 --- a/drivers/scsi/sata_promise.c +++ b/drivers/scsi/sata_promise.c | |||
@@ -46,7 +46,7 @@ | |||
46 | #include "sata_promise.h" | 46 | #include "sata_promise.h" |
47 | 47 | ||
48 | #define DRV_NAME "sata_promise" | 48 | #define DRV_NAME "sata_promise" |
49 | #define DRV_VERSION "1.03" | 49 | #define DRV_VERSION "1.04" |
50 | 50 | ||
51 | 51 | ||
52 | enum { | 52 | enum { |
@@ -58,6 +58,7 @@ enum { | |||
58 | PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */ | 58 | PDC_GLOBAL_CTL = 0x48, /* Global control/status (per port) */ |
59 | PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */ | 59 | PDC_CTLSTAT = 0x60, /* IDE control and status (per port) */ |
60 | PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */ | 60 | PDC_SATA_PLUG_CSR = 0x6C, /* SATA Plug control/status reg */ |
61 | PDC2_SATA_PLUG_CSR = 0x60, /* SATAII Plug control/status reg */ | ||
61 | PDC_SLEW_CTL = 0x470, /* slew rate control reg */ | 62 | PDC_SLEW_CTL = 0x470, /* slew rate control reg */ |
62 | 63 | ||
63 | PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) | | 64 | PDC_ERR_MASK = (1<<19) | (1<<20) | (1<<21) | (1<<22) | |
@@ -67,8 +68,10 @@ enum { | |||
67 | board_20319 = 1, /* FastTrak S150 TX4 */ | 68 | board_20319 = 1, /* FastTrak S150 TX4 */ |
68 | board_20619 = 2, /* FastTrak TX4000 */ | 69 | board_20619 = 2, /* FastTrak TX4000 */ |
69 | board_20771 = 3, /* FastTrak TX2300 */ | 70 | board_20771 = 3, /* FastTrak TX2300 */ |
71 | board_2057x = 4, /* SATAII150 Tx2plus */ | ||
72 | board_40518 = 5, /* SATAII150 Tx4 */ | ||
70 | 73 | ||
71 | PDC_HAS_PATA = (1 << 1), /* PDC20375 has PATA */ | 74 | PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */ |
72 | 75 | ||
73 | PDC_RESET = (1 << 11), /* HDMA reset */ | 76 | PDC_RESET = (1 << 11), /* HDMA reset */ |
74 | 77 | ||
@@ -82,6 +85,10 @@ struct pdc_port_priv { | |||
82 | dma_addr_t pkt_dma; | 85 | dma_addr_t pkt_dma; |
83 | }; | 86 | }; |
84 | 87 | ||
88 | struct pdc_host_priv { | ||
89 | int hotplug_offset; | ||
90 | }; | ||
91 | |||
85 | static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); | 92 | static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); |
86 | static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); | 93 | static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); |
87 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); | 94 | static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); |
@@ -95,7 +102,8 @@ static void pdc_qc_prep(struct ata_queued_cmd *qc); | |||
95 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); | 102 | static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); |
96 | static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); | 103 | static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); |
97 | static void pdc_irq_clear(struct ata_port *ap); | 104 | static void pdc_irq_clear(struct ata_port *ap); |
98 | static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); | 105 | static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); |
106 | static void pdc_host_stop(struct ata_host_set *host_set); | ||
99 | 107 | ||
100 | 108 | ||
101 | static struct scsi_host_template pdc_ata_sht = { | 109 | static struct scsi_host_template pdc_ata_sht = { |
@@ -137,7 +145,7 @@ static const struct ata_port_operations pdc_sata_ops = { | |||
137 | .scr_write = pdc_sata_scr_write, | 145 | .scr_write = pdc_sata_scr_write, |
138 | .port_start = pdc_port_start, | 146 | .port_start = pdc_port_start, |
139 | .port_stop = pdc_port_stop, | 147 | .port_stop = pdc_port_stop, |
140 | .host_stop = ata_pci_host_stop, | 148 | .host_stop = pdc_host_stop, |
141 | }; | 149 | }; |
142 | 150 | ||
143 | static const struct ata_port_operations pdc_pata_ops = { | 151 | static const struct ata_port_operations pdc_pata_ops = { |
@@ -158,7 +166,7 @@ static const struct ata_port_operations pdc_pata_ops = { | |||
158 | 166 | ||
159 | .port_start = pdc_port_start, | 167 | .port_start = pdc_port_start, |
160 | .port_stop = pdc_port_stop, | 168 | .port_stop = pdc_port_stop, |
161 | .host_stop = ata_pci_host_stop, | 169 | .host_stop = pdc_host_stop, |
162 | }; | 170 | }; |
163 | 171 | ||
164 | static const struct ata_port_info pdc_port_info[] = { | 172 | static const struct ata_port_info pdc_port_info[] = { |
@@ -201,6 +209,26 @@ static const struct ata_port_info pdc_port_info[] = { | |||
201 | .udma_mask = 0x7f, /* udma0-6 ; FIXME */ | 209 | .udma_mask = 0x7f, /* udma0-6 ; FIXME */ |
202 | .port_ops = &pdc_sata_ops, | 210 | .port_ops = &pdc_sata_ops, |
203 | }, | 211 | }, |
212 | |||
213 | /* board_2057x */ | ||
214 | { | ||
215 | .sht = &pdc_ata_sht, | ||
216 | .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, | ||
217 | .pio_mask = 0x1f, /* pio0-4 */ | ||
218 | .mwdma_mask = 0x07, /* mwdma0-2 */ | ||
219 | .udma_mask = 0x7f, /* udma0-6 ; FIXME */ | ||
220 | .port_ops = &pdc_sata_ops, | ||
221 | }, | ||
222 | |||
223 | /* board_40518 */ | ||
224 | { | ||
225 | .sht = &pdc_ata_sht, | ||
226 | .host_flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, | ||
227 | .pio_mask = 0x1f, /* pio0-4 */ | ||
228 | .mwdma_mask = 0x07, /* mwdma0-2 */ | ||
229 | .udma_mask = 0x7f, /* udma0-6 ; FIXME */ | ||
230 | .port_ops = &pdc_sata_ops, | ||
231 | }, | ||
204 | }; | 232 | }; |
205 | 233 | ||
206 | static const struct pci_device_id pdc_ata_pci_tbl[] = { | 234 | static const struct pci_device_id pdc_ata_pci_tbl[] = { |
@@ -217,9 +245,9 @@ static const struct pci_device_id pdc_ata_pci_tbl[] = { | |||
217 | { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 245 | { PCI_VENDOR_ID_PROMISE, 0x3376, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
218 | board_2037x }, | 246 | board_2037x }, |
219 | { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 247 | { PCI_VENDOR_ID_PROMISE, 0x3574, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
220 | board_2037x }, | 248 | board_2057x }, |
221 | { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 249 | { PCI_VENDOR_ID_PROMISE, 0x3d75, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
222 | board_2037x }, | 250 | board_2057x }, |
223 | { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 251 | { PCI_VENDOR_ID_PROMISE, 0x3d73, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
224 | board_2037x }, | 252 | board_2037x }, |
225 | 253 | ||
@@ -232,7 +260,7 @@ static const struct pci_device_id pdc_ata_pci_tbl[] = { | |||
232 | { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 260 | { PCI_VENDOR_ID_PROMISE, 0x3d17, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
233 | board_20319 }, | 261 | board_20319 }, |
234 | { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 262 | { PCI_VENDOR_ID_PROMISE, 0x3d18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
235 | board_20319 }, | 263 | board_40518 }, |
236 | 264 | ||
237 | { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0, | 265 | { PCI_VENDOR_ID_PROMISE, 0x6629, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
238 | board_20619 }, | 266 | board_20619 }, |
@@ -261,12 +289,11 @@ static int pdc_port_start(struct ata_port *ap) | |||
261 | if (rc) | 289 | if (rc) |
262 | return rc; | 290 | return rc; |
263 | 291 | ||
264 | pp = kmalloc(sizeof(*pp), GFP_KERNEL); | 292 | pp = kzalloc(sizeof(*pp), GFP_KERNEL); |
265 | if (!pp) { | 293 | if (!pp) { |
266 | rc = -ENOMEM; | 294 | rc = -ENOMEM; |
267 | goto err_out; | 295 | goto err_out; |
268 | } | 296 | } |
269 | memset(pp, 0, sizeof(*pp)); | ||
270 | 297 | ||
271 | pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); | 298 | pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); |
272 | if (!pp->pkt) { | 299 | if (!pp->pkt) { |
@@ -298,6 +325,16 @@ static void pdc_port_stop(struct ata_port *ap) | |||
298 | } | 325 | } |
299 | 326 | ||
300 | 327 | ||
328 | static void pdc_host_stop(struct ata_host_set *host_set) | ||
329 | { | ||
330 | struct pdc_host_priv *hp = host_set->private_data; | ||
331 | |||
332 | ata_pci_host_stop(host_set); | ||
333 | |||
334 | kfree(hp); | ||
335 | } | ||
336 | |||
337 | |||
301 | static void pdc_reset_port(struct ata_port *ap) | 338 | static void pdc_reset_port(struct ata_port *ap) |
302 | { | 339 | { |
303 | void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; | 340 | void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; |
@@ -400,21 +437,12 @@ static void pdc_eng_timeout(struct ata_port *ap) | |||
400 | goto out; | 437 | goto out; |
401 | } | 438 | } |
402 | 439 | ||
403 | /* hack alert! We cannot use the supplied completion | ||
404 | * function from inside the ->eh_strategy_handler() thread. | ||
405 | * libata is the only user of ->eh_strategy_handler() in | ||
406 | * any kernel, so the default scsi_done() assumes it is | ||
407 | * not being called from the SCSI EH. | ||
408 | */ | ||
409 | qc->scsidone = scsi_finish_command; | ||
410 | |||
411 | switch (qc->tf.protocol) { | 440 | switch (qc->tf.protocol) { |
412 | case ATA_PROT_DMA: | 441 | case ATA_PROT_DMA: |
413 | case ATA_PROT_NODATA: | 442 | case ATA_PROT_NODATA: |
414 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); | 443 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); |
415 | drv_stat = ata_wait_idle(ap); | 444 | drv_stat = ata_wait_idle(ap); |
416 | qc->err_mask |= __ac_err_mask(drv_stat); | 445 | qc->err_mask |= __ac_err_mask(drv_stat); |
417 | ata_qc_complete(qc); | ||
418 | break; | 446 | break; |
419 | 447 | ||
420 | default: | 448 | default: |
@@ -424,12 +452,13 @@ static void pdc_eng_timeout(struct ata_port *ap) | |||
424 | ap->id, qc->tf.command, drv_stat); | 452 | ap->id, qc->tf.command, drv_stat); |
425 | 453 | ||
426 | qc->err_mask |= ac_err_mask(drv_stat); | 454 | qc->err_mask |= ac_err_mask(drv_stat); |
427 | ata_qc_complete(qc); | ||
428 | break; | 455 | break; |
429 | } | 456 | } |
430 | 457 | ||
431 | out: | 458 | out: |
432 | spin_unlock_irqrestore(&host_set->lock, flags); | 459 | spin_unlock_irqrestore(&host_set->lock, flags); |
460 | if (qc) | ||
461 | ata_eh_qc_complete(qc); | ||
433 | DPRINTK("EXIT\n"); | 462 | DPRINTK("EXIT\n"); |
434 | } | 463 | } |
435 | 464 | ||
@@ -495,14 +524,15 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r | |||
495 | VPRINTK("QUICK EXIT 2\n"); | 524 | VPRINTK("QUICK EXIT 2\n"); |
496 | return IRQ_NONE; | 525 | return IRQ_NONE; |
497 | } | 526 | } |
527 | |||
528 | spin_lock(&host_set->lock); | ||
529 | |||
498 | mask &= 0xffff; /* only 16 tags possible */ | 530 | mask &= 0xffff; /* only 16 tags possible */ |
499 | if (!mask) { | 531 | if (!mask) { |
500 | VPRINTK("QUICK EXIT 3\n"); | 532 | VPRINTK("QUICK EXIT 3\n"); |
501 | return IRQ_NONE; | 533 | goto done_irq; |
502 | } | 534 | } |
503 | 535 | ||
504 | spin_lock(&host_set->lock); | ||
505 | |||
506 | writel(mask, mmio_base + PDC_INT_SEQMASK); | 536 | writel(mask, mmio_base + PDC_INT_SEQMASK); |
507 | 537 | ||
508 | for (i = 0; i < host_set->n_ports; i++) { | 538 | for (i = 0; i < host_set->n_ports; i++) { |
@@ -519,10 +549,10 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance, struct pt_regs *r | |||
519 | } | 549 | } |
520 | } | 550 | } |
521 | 551 | ||
522 | spin_unlock(&host_set->lock); | ||
523 | |||
524 | VPRINTK("EXIT\n"); | 552 | VPRINTK("EXIT\n"); |
525 | 553 | ||
554 | done_irq: | ||
555 | spin_unlock(&host_set->lock); | ||
526 | return IRQ_RETVAL(handled); | 556 | return IRQ_RETVAL(handled); |
527 | } | 557 | } |
528 | 558 | ||
@@ -544,7 +574,7 @@ static inline void pdc_packet_start(struct ata_queued_cmd *qc) | |||
544 | readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ | 574 | readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ |
545 | } | 575 | } |
546 | 576 | ||
547 | static int pdc_qc_issue_prot(struct ata_queued_cmd *qc) | 577 | static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) |
548 | { | 578 | { |
549 | switch (qc->tf.protocol) { | 579 | switch (qc->tf.protocol) { |
550 | case ATA_PROT_DMA: | 580 | case ATA_PROT_DMA: |
@@ -600,6 +630,8 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base) | |||
600 | static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) | 630 | static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) |
601 | { | 631 | { |
602 | void __iomem *mmio = pe->mmio_base; | 632 | void __iomem *mmio = pe->mmio_base; |
633 | struct pdc_host_priv *hp = pe->private_data; | ||
634 | int hotplug_offset = hp->hotplug_offset; | ||
603 | u32 tmp; | 635 | u32 tmp; |
604 | 636 | ||
605 | /* | 637 | /* |
@@ -614,12 +646,12 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) | |||
614 | writel(tmp, mmio + PDC_FLASH_CTL); | 646 | writel(tmp, mmio + PDC_FLASH_CTL); |
615 | 647 | ||
616 | /* clear plug/unplug flags for all ports */ | 648 | /* clear plug/unplug flags for all ports */ |
617 | tmp = readl(mmio + PDC_SATA_PLUG_CSR); | 649 | tmp = readl(mmio + hotplug_offset); |
618 | writel(tmp | 0xff, mmio + PDC_SATA_PLUG_CSR); | 650 | writel(tmp | 0xff, mmio + hotplug_offset); |
619 | 651 | ||
620 | /* mask plug/unplug ints */ | 652 | /* mask plug/unplug ints */ |
621 | tmp = readl(mmio + PDC_SATA_PLUG_CSR); | 653 | tmp = readl(mmio + hotplug_offset); |
622 | writel(tmp | 0xff0000, mmio + PDC_SATA_PLUG_CSR); | 654 | writel(tmp | 0xff0000, mmio + hotplug_offset); |
623 | 655 | ||
624 | /* reduce TBG clock to 133 Mhz. */ | 656 | /* reduce TBG clock to 133 Mhz. */ |
625 | tmp = readl(mmio + PDC_TBG_MODE); | 657 | tmp = readl(mmio + PDC_TBG_MODE); |
@@ -641,6 +673,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
641 | { | 673 | { |
642 | static int printed_version; | 674 | static int printed_version; |
643 | struct ata_probe_ent *probe_ent = NULL; | 675 | struct ata_probe_ent *probe_ent = NULL; |
676 | struct pdc_host_priv *hp; | ||
644 | unsigned long base; | 677 | unsigned long base; |
645 | void __iomem *mmio_base; | 678 | void __iomem *mmio_base; |
646 | unsigned int board_idx = (unsigned int) ent->driver_data; | 679 | unsigned int board_idx = (unsigned int) ent->driver_data; |
@@ -671,13 +704,12 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
671 | if (rc) | 704 | if (rc) |
672 | goto err_out_regions; | 705 | goto err_out_regions; |
673 | 706 | ||
674 | probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); | 707 | probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); |
675 | if (probe_ent == NULL) { | 708 | if (probe_ent == NULL) { |
676 | rc = -ENOMEM; | 709 | rc = -ENOMEM; |
677 | goto err_out_regions; | 710 | goto err_out_regions; |
678 | } | 711 | } |
679 | 712 | ||
680 | memset(probe_ent, 0, sizeof(*probe_ent)); | ||
681 | probe_ent->dev = pci_dev_to_dev(pdev); | 713 | probe_ent->dev = pci_dev_to_dev(pdev); |
682 | INIT_LIST_HEAD(&probe_ent->node); | 714 | INIT_LIST_HEAD(&probe_ent->node); |
683 | 715 | ||
@@ -688,6 +720,16 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
688 | } | 720 | } |
689 | base = (unsigned long) mmio_base; | 721 | base = (unsigned long) mmio_base; |
690 | 722 | ||
723 | hp = kzalloc(sizeof(*hp), GFP_KERNEL); | ||
724 | if (hp == NULL) { | ||
725 | rc = -ENOMEM; | ||
726 | goto err_out_free_ent; | ||
727 | } | ||
728 | |||
729 | /* Set default hotplug offset */ | ||
730 | hp->hotplug_offset = PDC_SATA_PLUG_CSR; | ||
731 | probe_ent->private_data = hp; | ||
732 | |||
691 | probe_ent->sht = pdc_port_info[board_idx].sht; | 733 | probe_ent->sht = pdc_port_info[board_idx].sht; |
692 | probe_ent->host_flags = pdc_port_info[board_idx].host_flags; | 734 | probe_ent->host_flags = pdc_port_info[board_idx].host_flags; |
693 | probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask; | 735 | probe_ent->pio_mask = pdc_port_info[board_idx].pio_mask; |
@@ -707,6 +749,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
707 | 749 | ||
708 | /* notice 4-port boards */ | 750 | /* notice 4-port boards */ |
709 | switch (board_idx) { | 751 | switch (board_idx) { |
752 | case board_40518: | ||
753 | /* Override hotplug offset for SATAII150 */ | ||
754 | hp->hotplug_offset = PDC2_SATA_PLUG_CSR; | ||
755 | /* Fall through */ | ||
710 | case board_20319: | 756 | case board_20319: |
711 | probe_ent->n_ports = 4; | 757 | probe_ent->n_ports = 4; |
712 | 758 | ||
@@ -716,6 +762,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
716 | probe_ent->port[2].scr_addr = base + 0x600; | 762 | probe_ent->port[2].scr_addr = base + 0x600; |
717 | probe_ent->port[3].scr_addr = base + 0x700; | 763 | probe_ent->port[3].scr_addr = base + 0x700; |
718 | break; | 764 | break; |
765 | case board_2057x: | ||
766 | /* Override hotplug offset for SATAII150 */ | ||
767 | hp->hotplug_offset = PDC2_SATA_PLUG_CSR; | ||
768 | /* Fall through */ | ||
719 | case board_2037x: | 769 | case board_2037x: |
720 | probe_ent->n_ports = 2; | 770 | probe_ent->n_ports = 2; |
721 | break; | 771 | break; |
@@ -741,8 +791,10 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e | |||
741 | /* initialize adapter */ | 791 | /* initialize adapter */ |
742 | pdc_host_init(board_idx, probe_ent); | 792 | pdc_host_init(board_idx, probe_ent); |
743 | 793 | ||
744 | /* FIXME: check ata_device_add return value */ | 794 | /* FIXME: Need any other frees than hp? */ |
745 | ata_device_add(probe_ent); | 795 | if (!ata_device_add(probe_ent)) |
796 | kfree(hp); | ||
797 | |||
746 | kfree(probe_ent); | 798 | kfree(probe_ent); |
747 | 799 | ||
748 | return 0; | 800 | return 0; |
diff --git a/drivers/scsi/sata_qstor.c b/drivers/scsi/sata_qstor.c index de05e2883f9c..2afbeb77f6fe 100644 --- a/drivers/scsi/sata_qstor.c +++ b/drivers/scsi/sata_qstor.c | |||
@@ -120,7 +120,7 @@ static void qs_host_stop(struct ata_host_set *host_set); | |||
120 | static void qs_port_stop(struct ata_port *ap); | 120 | static void qs_port_stop(struct ata_port *ap); |
121 | static void qs_phy_reset(struct ata_port *ap); | 121 | static void qs_phy_reset(struct ata_port *ap); |
122 | static void qs_qc_prep(struct ata_queued_cmd *qc); | 122 | static void qs_qc_prep(struct ata_queued_cmd *qc); |
123 | static int qs_qc_issue(struct ata_queued_cmd *qc); | 123 | static unsigned int qs_qc_issue(struct ata_queued_cmd *qc); |
124 | static int qs_check_atapi_dma(struct ata_queued_cmd *qc); | 124 | static int qs_check_atapi_dma(struct ata_queued_cmd *qc); |
125 | static void qs_bmdma_stop(struct ata_queued_cmd *qc); | 125 | static void qs_bmdma_stop(struct ata_queued_cmd *qc); |
126 | static u8 qs_bmdma_status(struct ata_port *ap); | 126 | static u8 qs_bmdma_status(struct ata_port *ap); |
@@ -352,7 +352,7 @@ static inline void qs_packet_start(struct ata_queued_cmd *qc) | |||
352 | readl(chan + QS_CCT_CFF); /* flush */ | 352 | readl(chan + QS_CCT_CFF); /* flush */ |
353 | } | 353 | } |
354 | 354 | ||
355 | static int qs_qc_issue(struct ata_queued_cmd *qc) | 355 | static unsigned int qs_qc_issue(struct ata_queued_cmd *qc) |
356 | { | 356 | { |
357 | struct qs_port_priv *pp = qc->ap->private_data; | 357 | struct qs_port_priv *pp = qc->ap->private_data; |
358 | 358 | ||
diff --git a/drivers/scsi/sata_sil24.c b/drivers/scsi/sata_sil24.c index 923130185a9e..7222fc7ff3fc 100644 --- a/drivers/scsi/sata_sil24.c +++ b/drivers/scsi/sata_sil24.c | |||
@@ -251,7 +251,7 @@ static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val); | |||
251 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); | 251 | static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); |
252 | static void sil24_phy_reset(struct ata_port *ap); | 252 | static void sil24_phy_reset(struct ata_port *ap); |
253 | static void sil24_qc_prep(struct ata_queued_cmd *qc); | 253 | static void sil24_qc_prep(struct ata_queued_cmd *qc); |
254 | static int sil24_qc_issue(struct ata_queued_cmd *qc); | 254 | static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc); |
255 | static void sil24_irq_clear(struct ata_port *ap); | 255 | static void sil24_irq_clear(struct ata_port *ap); |
256 | static void sil24_eng_timeout(struct ata_port *ap); | 256 | static void sil24_eng_timeout(struct ata_port *ap); |
257 | static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs); | 257 | static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs); |
@@ -557,7 +557,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc) | |||
557 | sil24_fill_sg(qc, sge); | 557 | sil24_fill_sg(qc, sge); |
558 | } | 558 | } |
559 | 559 | ||
560 | static int sil24_qc_issue(struct ata_queued_cmd *qc) | 560 | static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc) |
561 | { | 561 | { |
562 | struct ata_port *ap = qc->ap; | 562 | struct ata_port *ap = qc->ap; |
563 | void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; | 563 | void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; |
@@ -644,17 +644,9 @@ static void sil24_eng_timeout(struct ata_port *ap) | |||
644 | return; | 644 | return; |
645 | } | 645 | } |
646 | 646 | ||
647 | /* | ||
648 | * hack alert! We cannot use the supplied completion | ||
649 | * function from inside the ->eh_strategy_handler() thread. | ||
650 | * libata is the only user of ->eh_strategy_handler() in | ||
651 | * any kernel, so the default scsi_done() assumes it is | ||
652 | * not being called from the SCSI EH. | ||
653 | */ | ||
654 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); | 647 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); |
655 | qc->scsidone = scsi_finish_command; | 648 | qc->err_mask |= AC_ERR_TIMEOUT; |
656 | qc->err_mask |= AC_ERR_OTHER; | 649 | ata_eh_qc_complete(qc); |
657 | ata_qc_complete(qc); | ||
658 | 650 | ||
659 | sil24_reset_controller(ap); | 651 | sil24_reset_controller(ap); |
660 | } | 652 | } |
diff --git a/drivers/scsi/sata_sx4.c b/drivers/scsi/sata_sx4.c index bc87c16c80d2..9f992fbcf2e7 100644 --- a/drivers/scsi/sata_sx4.c +++ b/drivers/scsi/sata_sx4.c | |||
@@ -174,7 +174,7 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, | |||
174 | static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, | 174 | static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, |
175 | void *psource, u32 offset, u32 size); | 175 | void *psource, u32 offset, u32 size); |
176 | static void pdc20621_irq_clear(struct ata_port *ap); | 176 | static void pdc20621_irq_clear(struct ata_port *ap); |
177 | static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc); | 177 | static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc); |
178 | 178 | ||
179 | 179 | ||
180 | static struct scsi_host_template pdc_sata_sht = { | 180 | static struct scsi_host_template pdc_sata_sht = { |
@@ -678,7 +678,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc) | |||
678 | } | 678 | } |
679 | } | 679 | } |
680 | 680 | ||
681 | static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc) | 681 | static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc) |
682 | { | 682 | { |
683 | switch (qc->tf.protocol) { | 683 | switch (qc->tf.protocol) { |
684 | case ATA_PROT_DMA: | 684 | case ATA_PROT_DMA: |
@@ -872,20 +872,11 @@ static void pdc_eng_timeout(struct ata_port *ap) | |||
872 | goto out; | 872 | goto out; |
873 | } | 873 | } |
874 | 874 | ||
875 | /* hack alert! We cannot use the supplied completion | ||
876 | * function from inside the ->eh_strategy_handler() thread. | ||
877 | * libata is the only user of ->eh_strategy_handler() in | ||
878 | * any kernel, so the default scsi_done() assumes it is | ||
879 | * not being called from the SCSI EH. | ||
880 | */ | ||
881 | qc->scsidone = scsi_finish_command; | ||
882 | |||
883 | switch (qc->tf.protocol) { | 875 | switch (qc->tf.protocol) { |
884 | case ATA_PROT_DMA: | 876 | case ATA_PROT_DMA: |
885 | case ATA_PROT_NODATA: | 877 | case ATA_PROT_NODATA: |
886 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); | 878 | printk(KERN_ERR "ata%u: command timeout\n", ap->id); |
887 | qc->err_mask |= __ac_err_mask(ata_wait_idle(ap)); | 879 | qc->err_mask |= __ac_err_mask(ata_wait_idle(ap)); |
888 | ata_qc_complete(qc); | ||
889 | break; | 880 | break; |
890 | 881 | ||
891 | default: | 882 | default: |
@@ -895,12 +886,13 @@ static void pdc_eng_timeout(struct ata_port *ap) | |||
895 | ap->id, qc->tf.command, drv_stat); | 886 | ap->id, qc->tf.command, drv_stat); |
896 | 887 | ||
897 | qc->err_mask |= ac_err_mask(drv_stat); | 888 | qc->err_mask |= ac_err_mask(drv_stat); |
898 | ata_qc_complete(qc); | ||
899 | break; | 889 | break; |
900 | } | 890 | } |
901 | 891 | ||
902 | out: | 892 | out: |
903 | spin_unlock_irqrestore(&host_set->lock, flags); | 893 | spin_unlock_irqrestore(&host_set->lock, flags); |
894 | if (qc) | ||
895 | ata_eh_qc_complete(qc); | ||
904 | DPRINTK("EXIT\n"); | 896 | DPRINTK("EXIT\n"); |
905 | } | 897 | } |
906 | 898 | ||
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index a2333d2c7af0..6bac3d2668fa 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c | |||
@@ -584,8 +584,7 @@ static int scsi_request_sense(struct scsi_cmnd *scmd) | |||
584 | * keep a list of pending commands for final completion, and once we | 584 | * keep a list of pending commands for final completion, and once we |
585 | * are ready to leave error handling we handle completion for real. | 585 | * are ready to leave error handling we handle completion for real. |
586 | **/ | 586 | **/ |
587 | static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, | 587 | void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q) |
588 | struct list_head *done_q) | ||
589 | { | 588 | { |
590 | scmd->device->host->host_failed--; | 589 | scmd->device->host->host_failed--; |
591 | scmd->eh_eflags = 0; | 590 | scmd->eh_eflags = 0; |
@@ -597,6 +596,7 @@ static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, | |||
597 | scsi_setup_cmd_retry(scmd); | 596 | scsi_setup_cmd_retry(scmd); |
598 | list_move_tail(&scmd->eh_entry, done_q); | 597 | list_move_tail(&scmd->eh_entry, done_q); |
599 | } | 598 | } |
599 | EXPORT_SYMBOL(scsi_eh_finish_cmd); | ||
600 | 600 | ||
601 | /** | 601 | /** |
602 | * scsi_eh_get_sense - Get device sense data. | 602 | * scsi_eh_get_sense - Get device sense data. |
@@ -1425,7 +1425,7 @@ static void scsi_eh_ready_devs(struct Scsi_Host *shost, | |||
1425 | * @done_q: list_head of processed commands. | 1425 | * @done_q: list_head of processed commands. |
1426 | * | 1426 | * |
1427 | **/ | 1427 | **/ |
1428 | static void scsi_eh_flush_done_q(struct list_head *done_q) | 1428 | void scsi_eh_flush_done_q(struct list_head *done_q) |
1429 | { | 1429 | { |
1430 | struct scsi_cmnd *scmd, *next; | 1430 | struct scsi_cmnd *scmd, *next; |
1431 | 1431 | ||
@@ -1454,6 +1454,7 @@ static void scsi_eh_flush_done_q(struct list_head *done_q) | |||
1454 | } | 1454 | } |
1455 | } | 1455 | } |
1456 | } | 1456 | } |
1457 | EXPORT_SYMBOL(scsi_eh_flush_done_q); | ||
1457 | 1458 | ||
1458 | /** | 1459 | /** |
1459 | * scsi_unjam_host - Attempt to fix a host which has a cmd that failed. | 1460 | * scsi_unjam_host - Attempt to fix a host which has a cmd that failed. |
diff --git a/include/linux/ata.h b/include/linux/ata.h index 94f77cce27fa..a8155ca4947f 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h | |||
@@ -302,4 +302,16 @@ static inline int ata_ok(u8 status) | |||
302 | == ATA_DRDY); | 302 | == ATA_DRDY); |
303 | } | 303 | } |
304 | 304 | ||
305 | static inline int lba_28_ok(u64 block, u32 n_block) | ||
306 | { | ||
307 | /* check the ending block number */ | ||
308 | return ((block + n_block - 1) < ((u64)1 << 28)) && (n_block <= 256); | ||
309 | } | ||
310 | |||
311 | static inline int lba_48_ok(u64 block, u32 n_block) | ||
312 | { | ||
313 | /* check the ending block number */ | ||
314 | return ((block + n_block - 1) < ((u64)1 << 48)) && (n_block <= 65536); | ||
315 | } | ||
316 | |||
305 | #endif /* __LINUX_ATA_H__ */ | 317 | #endif /* __LINUX_ATA_H__ */ |
diff --git a/include/linux/libata.h b/include/linux/libata.h index 9e5db2949c58..474cdfa35d1e 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h | |||
@@ -35,7 +35,8 @@ | |||
35 | #include <linux/workqueue.h> | 35 | #include <linux/workqueue.h> |
36 | 36 | ||
37 | /* | 37 | /* |
38 | * compile-time options | 38 | * compile-time options: to be removed as soon as all the drivers are |
39 | * converted to the new debugging mechanism | ||
39 | */ | 40 | */ |
40 | #undef ATA_DEBUG /* debugging output */ | 41 | #undef ATA_DEBUG /* debugging output */ |
41 | #undef ATA_VERBOSE_DEBUG /* yet more debugging output */ | 42 | #undef ATA_VERBOSE_DEBUG /* yet more debugging output */ |
@@ -71,6 +72,38 @@ | |||
71 | } | 72 | } |
72 | #endif | 73 | #endif |
73 | 74 | ||
75 | /* NEW: debug levels */ | ||
76 | #define HAVE_LIBATA_MSG 1 | ||
77 | |||
78 | enum { | ||
79 | ATA_MSG_DRV = 0x0001, | ||
80 | ATA_MSG_INFO = 0x0002, | ||
81 | ATA_MSG_PROBE = 0x0004, | ||
82 | ATA_MSG_WARN = 0x0008, | ||
83 | ATA_MSG_MALLOC = 0x0010, | ||
84 | ATA_MSG_CTL = 0x0020, | ||
85 | ATA_MSG_INTR = 0x0040, | ||
86 | ATA_MSG_ERR = 0x0080, | ||
87 | }; | ||
88 | |||
89 | #define ata_msg_drv(p) ((p)->msg_enable & ATA_MSG_DRV) | ||
90 | #define ata_msg_info(p) ((p)->msg_enable & ATA_MSG_INFO) | ||
91 | #define ata_msg_probe(p) ((p)->msg_enable & ATA_MSG_PROBE) | ||
92 | #define ata_msg_warn(p) ((p)->msg_enable & ATA_MSG_WARN) | ||
93 | #define ata_msg_malloc(p) ((p)->msg_enable & ATA_MSG_MALLOC) | ||
94 | #define ata_msg_ctl(p) ((p)->msg_enable & ATA_MSG_CTL) | ||
95 | #define ata_msg_intr(p) ((p)->msg_enable & ATA_MSG_INTR) | ||
96 | #define ata_msg_err(p) ((p)->msg_enable & ATA_MSG_ERR) | ||
97 | |||
98 | static inline u32 ata_msg_init(int dval, int default_msg_enable_bits) | ||
99 | { | ||
100 | if (dval < 0 || dval >= (sizeof(u32) * 8)) | ||
101 | return default_msg_enable_bits; /* should be 0x1 - only driver info msgs */ | ||
102 | if (!dval) | ||
103 | return 0; | ||
104 | return (1 << dval) - 1; | ||
105 | } | ||
106 | |||
74 | /* defines only for the constants which don't work well as enums */ | 107 | /* defines only for the constants which don't work well as enums */ |
75 | #define ATA_TAG_POISON 0xfafbfcfdU | 108 | #define ATA_TAG_POISON 0xfafbfcfdU |
76 | 109 | ||
@@ -115,9 +148,9 @@ enum { | |||
115 | ATA_FLAG_PORT_DISABLED = (1 << 2), /* port is disabled, ignore it */ | 148 | ATA_FLAG_PORT_DISABLED = (1 << 2), /* port is disabled, ignore it */ |
116 | ATA_FLAG_SATA = (1 << 3), | 149 | ATA_FLAG_SATA = (1 << 3), |
117 | ATA_FLAG_NO_LEGACY = (1 << 4), /* no legacy mode check */ | 150 | ATA_FLAG_NO_LEGACY = (1 << 4), /* no legacy mode check */ |
118 | ATA_FLAG_SRST = (1 << 5), /* use ATA SRST, not E.D.D. */ | 151 | ATA_FLAG_SRST = (1 << 5), /* (obsolete) use ATA SRST, not E.D.D. */ |
119 | ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ | 152 | ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ |
120 | ATA_FLAG_SATA_RESET = (1 << 7), /* use COMRESET */ | 153 | ATA_FLAG_SATA_RESET = (1 << 7), /* (obsolete) use COMRESET */ |
121 | ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ | 154 | ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ |
122 | ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once | 155 | ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once |
123 | * proper HSM is in place. */ | 156 | * proper HSM is in place. */ |
@@ -189,10 +222,15 @@ enum hsm_task_states { | |||
189 | }; | 222 | }; |
190 | 223 | ||
191 | enum ata_completion_errors { | 224 | enum ata_completion_errors { |
192 | AC_ERR_OTHER = (1 << 0), | 225 | AC_ERR_DEV = (1 << 0), /* device reported error */ |
193 | AC_ERR_DEV = (1 << 1), | 226 | AC_ERR_HSM = (1 << 1), /* host state machine violation */ |
194 | AC_ERR_ATA_BUS = (1 << 2), | 227 | AC_ERR_TIMEOUT = (1 << 2), /* timeout */ |
195 | AC_ERR_HOST_BUS = (1 << 3), | 228 | AC_ERR_MEDIA = (1 << 3), /* media error */ |
229 | AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */ | ||
230 | AC_ERR_HOST_BUS = (1 << 5), /* host bus error */ | ||
231 | AC_ERR_SYSTEM = (1 << 6), /* system error */ | ||
232 | AC_ERR_INVALID = (1 << 7), /* invalid argument */ | ||
233 | AC_ERR_OTHER = (1 << 8), /* unknown */ | ||
196 | }; | 234 | }; |
197 | 235 | ||
198 | /* forward declarations */ | 236 | /* forward declarations */ |
@@ -202,7 +240,9 @@ struct ata_port; | |||
202 | struct ata_queued_cmd; | 240 | struct ata_queued_cmd; |
203 | 241 | ||
204 | /* typedefs */ | 242 | /* typedefs */ |
205 | typedef int (*ata_qc_cb_t) (struct ata_queued_cmd *qc); | 243 | typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc); |
244 | typedef int (*ata_reset_fn_t)(struct ata_port *, int, unsigned int *); | ||
245 | typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *); | ||
206 | 246 | ||
207 | struct ata_ioports { | 247 | struct ata_ioports { |
208 | unsigned long cmd_addr; | 248 | unsigned long cmd_addr; |
@@ -359,6 +399,9 @@ struct ata_port { | |||
359 | unsigned int hsm_task_state; | 399 | unsigned int hsm_task_state; |
360 | unsigned long pio_task_timeout; | 400 | unsigned long pio_task_timeout; |
361 | 401 | ||
402 | u32 msg_enable; | ||
403 | struct list_head eh_done_q; | ||
404 | |||
362 | void *private_data; | 405 | void *private_data; |
363 | }; | 406 | }; |
364 | 407 | ||
@@ -378,7 +421,9 @@ struct ata_port_operations { | |||
378 | u8 (*check_altstatus)(struct ata_port *ap); | 421 | u8 (*check_altstatus)(struct ata_port *ap); |
379 | void (*dev_select)(struct ata_port *ap, unsigned int device); | 422 | void (*dev_select)(struct ata_port *ap, unsigned int device); |
380 | 423 | ||
381 | void (*phy_reset) (struct ata_port *ap); | 424 | void (*phy_reset) (struct ata_port *ap); /* obsolete */ |
425 | int (*probe_reset) (struct ata_port *ap, unsigned int *classes); | ||
426 | |||
382 | void (*post_set_mode) (struct ata_port *ap); | 427 | void (*post_set_mode) (struct ata_port *ap); |
383 | 428 | ||
384 | int (*check_atapi_dma) (struct ata_queued_cmd *qc); | 429 | int (*check_atapi_dma) (struct ata_queued_cmd *qc); |
@@ -387,7 +432,7 @@ struct ata_port_operations { | |||
387 | void (*bmdma_start) (struct ata_queued_cmd *qc); | 432 | void (*bmdma_start) (struct ata_queued_cmd *qc); |
388 | 433 | ||
389 | void (*qc_prep) (struct ata_queued_cmd *qc); | 434 | void (*qc_prep) (struct ata_queued_cmd *qc); |
390 | int (*qc_issue) (struct ata_queued_cmd *qc); | 435 | unsigned int (*qc_issue) (struct ata_queued_cmd *qc); |
391 | 436 | ||
392 | void (*eng_timeout) (struct ata_port *ap); | 437 | void (*eng_timeout) (struct ata_port *ap); |
393 | 438 | ||
@@ -435,6 +480,14 @@ extern void ata_port_probe(struct ata_port *); | |||
435 | extern void __sata_phy_reset(struct ata_port *ap); | 480 | extern void __sata_phy_reset(struct ata_port *ap); |
436 | extern void sata_phy_reset(struct ata_port *ap); | 481 | extern void sata_phy_reset(struct ata_port *ap); |
437 | extern void ata_bus_reset(struct ata_port *ap); | 482 | extern void ata_bus_reset(struct ata_port *ap); |
483 | extern int ata_drive_probe_reset(struct ata_port *ap, | ||
484 | ata_reset_fn_t softreset, ata_reset_fn_t hardreset, | ||
485 | ata_postreset_fn_t postreset, unsigned int *classes); | ||
486 | extern int ata_std_softreset(struct ata_port *ap, int verbose, | ||
487 | unsigned int *classes); | ||
488 | extern int sata_std_hardreset(struct ata_port *ap, int verbose, | ||
489 | unsigned int *class); | ||
490 | extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes); | ||
438 | extern void ata_port_disable(struct ata_port *); | 491 | extern void ata_port_disable(struct ata_port *); |
439 | extern void ata_std_ports(struct ata_ioports *ioaddr); | 492 | extern void ata_std_ports(struct ata_ioports *ioaddr); |
440 | #ifdef CONFIG_PCI | 493 | #ifdef CONFIG_PCI |
@@ -450,6 +503,8 @@ extern int ata_scsi_detect(struct scsi_host_template *sht); | |||
450 | extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); | 503 | extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); |
451 | extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); | 504 | extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); |
452 | extern int ata_scsi_error(struct Scsi_Host *host); | 505 | extern int ata_scsi_error(struct Scsi_Host *host); |
506 | extern void ata_eh_qc_complete(struct ata_queued_cmd *qc); | ||
507 | extern void ata_eh_qc_retry(struct ata_queued_cmd *qc); | ||
453 | extern int ata_scsi_release(struct Scsi_Host *host); | 508 | extern int ata_scsi_release(struct Scsi_Host *host); |
454 | extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); | 509 | extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); |
455 | extern int ata_scsi_device_resume(struct scsi_device *); | 510 | extern int ata_scsi_device_resume(struct scsi_device *); |
@@ -457,6 +512,9 @@ extern int ata_scsi_device_suspend(struct scsi_device *); | |||
457 | extern int ata_device_resume(struct ata_port *, struct ata_device *); | 512 | extern int ata_device_resume(struct ata_port *, struct ata_device *); |
458 | extern int ata_device_suspend(struct ata_port *, struct ata_device *); | 513 | extern int ata_device_suspend(struct ata_port *, struct ata_device *); |
459 | extern int ata_ratelimit(void); | 514 | extern int ata_ratelimit(void); |
515 | extern unsigned int ata_busy_sleep(struct ata_port *ap, | ||
516 | unsigned long timeout_pat, | ||
517 | unsigned long timeout); | ||
460 | 518 | ||
461 | /* | 519 | /* |
462 | * Default driver ops implementations | 520 | * Default driver ops implementations |
@@ -470,12 +528,13 @@ extern void ata_std_dev_select (struct ata_port *ap, unsigned int device); | |||
470 | extern u8 ata_check_status(struct ata_port *ap); | 528 | extern u8 ata_check_status(struct ata_port *ap); |
471 | extern u8 ata_altstatus(struct ata_port *ap); | 529 | extern u8 ata_altstatus(struct ata_port *ap); |
472 | extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf); | 530 | extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf); |
531 | extern int ata_std_probe_reset(struct ata_port *ap, unsigned int *classes); | ||
473 | extern int ata_port_start (struct ata_port *ap); | 532 | extern int ata_port_start (struct ata_port *ap); |
474 | extern void ata_port_stop (struct ata_port *ap); | 533 | extern void ata_port_stop (struct ata_port *ap); |
475 | extern void ata_host_stop (struct ata_host_set *host_set); | 534 | extern void ata_host_stop (struct ata_host_set *host_set); |
476 | extern irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs); | 535 | extern irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs); |
477 | extern void ata_qc_prep(struct ata_queued_cmd *qc); | 536 | extern void ata_qc_prep(struct ata_queued_cmd *qc); |
478 | extern int ata_qc_issue_prot(struct ata_queued_cmd *qc); | 537 | extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc); |
479 | extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, | 538 | extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, |
480 | unsigned int buflen); | 539 | unsigned int buflen); |
481 | extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | 540 | extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
@@ -645,9 +704,9 @@ static inline u8 ata_wait_idle(struct ata_port *ap) | |||
645 | 704 | ||
646 | if (status & (ATA_BUSY | ATA_DRQ)) { | 705 | if (status & (ATA_BUSY | ATA_DRQ)) { |
647 | unsigned long l = ap->ioaddr.status_addr; | 706 | unsigned long l = ap->ioaddr.status_addr; |
648 | printk(KERN_WARNING | 707 | if (ata_msg_warn(ap)) |
649 | "ATA: abnormal status 0x%X on port 0x%lX\n", | 708 | printk(KERN_WARNING "ATA: abnormal status 0x%X on port 0x%lX\n", |
650 | status, l); | 709 | status, l); |
651 | } | 710 | } |
652 | 711 | ||
653 | return status; | 712 | return status; |
@@ -739,7 +798,8 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq) | |||
739 | 798 | ||
740 | status = ata_busy_wait(ap, bits, 1000); | 799 | status = ata_busy_wait(ap, bits, 1000); |
741 | if (status & bits) | 800 | if (status & bits) |
742 | DPRINTK("abnormal status 0x%X\n", status); | 801 | if (ata_msg_err(ap)) |
802 | printk(KERN_ERR "abnormal status 0x%X\n", status); | ||
743 | 803 | ||
744 | /* get controller status; clear intr, err bits */ | 804 | /* get controller status; clear intr, err bits */ |
745 | if (ap->flags & ATA_FLAG_MMIO) { | 805 | if (ap->flags & ATA_FLAG_MMIO) { |
@@ -757,8 +817,10 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq) | |||
757 | post_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); | 817 | post_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); |
758 | } | 818 | } |
759 | 819 | ||
760 | VPRINTK("irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n", | 820 | if (ata_msg_intr(ap)) |
761 | host_stat, post_stat, status); | 821 | printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n", |
822 | __FUNCTION__, | ||
823 | host_stat, post_stat, status); | ||
762 | 824 | ||
763 | return status; | 825 | return status; |
764 | } | 826 | } |
@@ -795,7 +857,7 @@ static inline int ata_try_flush_cache(const struct ata_device *dev) | |||
795 | static inline unsigned int ac_err_mask(u8 status) | 857 | static inline unsigned int ac_err_mask(u8 status) |
796 | { | 858 | { |
797 | if (status & ATA_BUSY) | 859 | if (status & ATA_BUSY) |
798 | return AC_ERR_ATA_BUS; | 860 | return AC_ERR_HSM; |
799 | if (status & (ATA_ERR | ATA_DF)) | 861 | if (status & (ATA_ERR | ATA_DF)) |
800 | return AC_ERR_DEV; | 862 | return AC_ERR_DEV; |
801 | return 0; | 863 | return 0; |
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index fabd879c2f2e..d160880b2a87 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h | |||
@@ -35,6 +35,9 @@ static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr) | |||
35 | } | 35 | } |
36 | 36 | ||
37 | 37 | ||
38 | extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, | ||
39 | struct list_head *done_q); | ||
40 | extern void scsi_eh_flush_done_q(struct list_head *done_q); | ||
38 | extern void scsi_report_bus_reset(struct Scsi_Host *, int); | 41 | extern void scsi_report_bus_reset(struct Scsi_Host *, int); |
39 | extern void scsi_report_device_reset(struct Scsi_Host *, int, int); | 42 | extern void scsi_report_device_reset(struct Scsi_Host *, int, int); |
40 | extern int scsi_block_when_processing_errors(struct scsi_device *); | 43 | extern int scsi_block_when_processing_errors(struct scsi_device *); |