aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/ahci.c108
-rw-r--r--drivers/scsi/ata_piix.c54
-rw-r--r--drivers/scsi/libata-core.c625
-rw-r--r--drivers/scsi/libata-scsi.c140
-rw-r--r--drivers/scsi/libata.h2
-rw-r--r--drivers/scsi/pdc_adma.c4
-rw-r--r--drivers/scsi/sata_mv.c18
-rw-r--r--drivers/scsi/sata_promise.c120
-rw-r--r--drivers/scsi/sata_qstor.c4
-rw-r--r--drivers/scsi/sata_sil24.c16
-rw-r--r--drivers/scsi/sata_sx4.c16
-rw-r--r--drivers/scsi/scsi_error.c7
12 files changed, 777 insertions, 337 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 2fffc7bf5d96..f65a00fe81d9 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 {
184static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 188static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg);
185static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 189static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
186static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 190static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
187static int ahci_qc_issue(struct ata_queued_cmd *qc); 191static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
188static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); 192static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
189static void ahci_phy_reset(struct ata_port *ap); 193static void ahci_phy_reset(struct ata_port *ap);
190static void ahci_irq_clear(struct ata_port *ap); 194static void ahci_irq_clear(struct ata_port *ap);
@@ -448,25 +452,72 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
448 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 452 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
449} 453}
450 454
451static void ahci_phy_reset(struct ata_port *ap) 455static int ahci_stop_engine(struct ata_port *ap)
456{
457 void __iomem *mmio = ap->host_set->mmio_base;
458 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
459 int work;
460 u32 tmp;
461
462 tmp = readl(port_mmio + PORT_CMD);
463 tmp &= ~PORT_CMD_START;
464 writel(tmp, port_mmio + PORT_CMD);
465
466 /* wait for engine to stop. TODO: this could be
467 * as long as 500 msec
468 */
469 work = 1000;
470 while (work-- > 0) {
471 tmp = readl(port_mmio + PORT_CMD);
472 if ((tmp & PORT_CMD_LIST_ON) == 0)
473 return 0;
474 udelay(10);
475 }
476
477 return -EIO;
478}
479
480static void ahci_start_engine(struct ata_port *ap)
481{
482 void __iomem *mmio = ap->host_set->mmio_base;
483 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
484 u32 tmp;
485
486 tmp = readl(port_mmio + PORT_CMD);
487 tmp |= PORT_CMD_START;
488 writel(tmp, port_mmio + PORT_CMD);
489 readl(port_mmio + PORT_CMD); /* flush */
490}
491
492static unsigned int ahci_dev_classify(struct ata_port *ap)
452{ 493{
453 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 494 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
454 struct ata_taskfile tf; 495 struct ata_taskfile tf;
496 u32 tmp;
497
498 tmp = readl(port_mmio + PORT_SIG);
499 tf.lbah = (tmp >> 24) & 0xff;
500 tf.lbam = (tmp >> 16) & 0xff;
501 tf.lbal = (tmp >> 8) & 0xff;
502 tf.nsect = (tmp) & 0xff;
503
504 return ata_dev_classify(&tf);
505}
506
507static void ahci_phy_reset(struct ata_port *ap)
508{
509 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
455 struct ata_device *dev = &ap->device[0]; 510 struct ata_device *dev = &ap->device[0];
456 u32 new_tmp, tmp; 511 u32 new_tmp, tmp;
457 512
513 ahci_stop_engine(ap);
458 __sata_phy_reset(ap); 514 __sata_phy_reset(ap);
515 ahci_start_engine(ap);
459 516
460 if (ap->flags & ATA_FLAG_PORT_DISABLED) 517 if (ap->flags & ATA_FLAG_PORT_DISABLED)
461 return; 518 return;
462 519
463 tmp = readl(port_mmio + PORT_SIG); 520 dev->class = ahci_dev_classify(ap);
464 tf.lbah = (tmp >> 24) & 0xff;
465 tf.lbam = (tmp >> 16) & 0xff;
466 tf.lbal = (tmp >> 8) & 0xff;
467 tf.nsect = (tmp) & 0xff;
468
469 dev->class = ata_dev_classify(&tf);
470 if (!ata_dev_present(dev)) { 521 if (!ata_dev_present(dev)) {
471 ata_port_disable(ap); 522 ata_port_disable(ap);
472 return; 523 return;
@@ -574,7 +625,6 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
574 void __iomem *mmio = ap->host_set->mmio_base; 625 void __iomem *mmio = ap->host_set->mmio_base;
575 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 626 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
576 u32 tmp; 627 u32 tmp;
577 int work;
578 628
579 if ((ap->device[0].class != ATA_DEV_ATAPI) || 629 if ((ap->device[0].class != ATA_DEV_ATAPI) ||
580 ((irq_stat & PORT_IRQ_TF_ERR) == 0)) 630 ((irq_stat & PORT_IRQ_TF_ERR) == 0))
@@ -590,20 +640,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
590 readl(port_mmio + PORT_SCR_ERR)); 640 readl(port_mmio + PORT_SCR_ERR));
591 641
592 /* stop DMA */ 642 /* stop DMA */
593 tmp = readl(port_mmio + PORT_CMD); 643 ahci_stop_engine(ap);
594 tmp &= ~PORT_CMD_START;
595 writel(tmp, port_mmio + PORT_CMD);
596
597 /* wait for engine to stop. TODO: this could be
598 * as long as 500 msec
599 */
600 work = 1000;
601 while (work-- > 0) {
602 tmp = readl(port_mmio + PORT_CMD);
603 if ((tmp & PORT_CMD_LIST_ON) == 0)
604 break;
605 udelay(10);
606 }
607 644
608 /* clear SATA phy error, if any */ 645 /* clear SATA phy error, if any */
609 tmp = readl(port_mmio + PORT_SCR_ERR); 646 tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -622,10 +659,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
622 } 659 }
623 660
624 /* re-start DMA */ 661 /* re-start DMA */
625 tmp = readl(port_mmio + PORT_CMD); 662 ahci_start_engine(ap);
626 tmp |= PORT_CMD_START;
627 writel(tmp, port_mmio + PORT_CMD);
628 readl(port_mmio + PORT_CMD); /* flush */
629} 663}
630 664
631static void ahci_eng_timeout(struct ata_port *ap) 665static void ahci_eng_timeout(struct ata_port *ap)
@@ -646,19 +680,13 @@ static void ahci_eng_timeout(struct ata_port *ap)
646 ap->id); 680 ap->id);
647 } else { 681 } else {
648 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT)); 682 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
649 683 qc->err_mask |= AC_ERR_TIMEOUT;
650 /* hack alert! We cannot use the supplied completion
651 * function from inside the ->eh_strategy_handler() thread.
652 * libata is the only user of ->eh_strategy_handler() in
653 * any kernel, so the default scsi_done() assumes it is
654 * not being called from the SCSI EH.
655 */
656 qc->scsidone = scsi_finish_command;
657 qc->err_mask |= AC_ERR_OTHER;
658 ata_qc_complete(qc);
659 } 684 }
660 685
661 spin_unlock_irqrestore(&host_set->lock, flags); 686 spin_unlock_irqrestore(&host_set->lock, flags);
687
688 if (qc)
689 ata_eh_qc_complete(qc);
662} 690}
663 691
664static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 692static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
@@ -695,7 +723,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
695 ahci_restart_port(ap, status); 723 ahci_restart_port(ap, status);
696 724
697 if (qc) { 725 if (qc) {
698 qc->err_mask |= AC_ERR_OTHER; 726 qc->err_mask |= err_mask;
699 ata_qc_complete(qc); 727 ata_qc_complete(qc);
700 } 728 }
701 } 729 }
@@ -774,7 +802,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
774 return IRQ_RETVAL(handled); 802 return IRQ_RETVAL(handled);
775} 803}
776 804
777static int ahci_qc_issue(struct ata_queued_cmd *qc) 805static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
778{ 806{
779 struct ata_port *ap = qc->ap; 807 struct ata_port *ap = qc->ap;
780 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 808 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
64static unsigned int ata_busy_sleep (struct ata_port *ap,
65 unsigned long tmout_pat,
66 unsigned long tmout);
67static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev); 64static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev);
68static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev); 65static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev);
69static void ata_set_mode(struct ata_port *ap); 66static void ata_set_mode(struct ata_port *ap);
@@ -73,7 +70,6 @@ static int fgb(u32 bitmap);
73static int ata_choose_xfer_mode(const struct ata_port *ap, 70static 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);
76static void __ata_qc_complete(struct ata_queued_cmd *qc);
77 73
78static unsigned int ata_unique_id = 1; 74static unsigned int ata_unique_id = 1;
79static struct workqueue_struct *ata_wq; 75static 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
851static u8 ata_dev_try_classify(struct ata_port *ap, unsigned int device) 851static unsigned int
852ata_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
1076struct ata_exec_internal_arg { 1074static inline void
1077 unsigned int err_mask; 1075ata_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
1082int ata_qc_complete_internal(struct ata_queued_cmd *qc) 1080static inline void
1081ata_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)) 1086static inline void
1088 qc->ap->ops->tf_read(qc->ap, arg->tf); 1087ata_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; 1092void 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
1450void ata_dev_config(struct ata_port *ap, unsigned int i) 1452void 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 */
1556static 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 */
1887static void ata_set_mode(struct ata_port *ap) 1927static 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
1937static unsigned int ata_busy_sleep (struct ata_port *ap, 1976unsigned 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 */
2248int 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 */
2311int 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 */
2379void 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 */
2423int 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
2435static 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 */
2498int 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
2195static void ata_pr_blacklisted(const struct ata_port *ap, 2523static 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)
3286err_out: 3614err_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
3574static 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 */
3599void ata_qc_free(struct ata_queued_cmd *qc) 3905void 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
3618void ata_qc_complete(struct ata_queued_cmd *qc) 3934void 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
3648static inline int ata_should_dma_map(struct ata_queued_cmd *qc) 3952static 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
3688int ata_qc_issue(struct ata_queued_cmd *qc) 3992unsigned 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
3711err_out: 4015sg_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
3734int ata_qc_issue_prot(struct ata_queued_cmd *qc) 4039unsigned 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 */
4306int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) 4601int 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
4318int ata_port_start (struct ata_port *ap) 4626int 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);
5161EXPORT_SYMBOL_GPL(sata_phy_reset); 5470EXPORT_SYMBOL_GPL(sata_phy_reset);
5162EXPORT_SYMBOL_GPL(__sata_phy_reset); 5471EXPORT_SYMBOL_GPL(__sata_phy_reset);
5163EXPORT_SYMBOL_GPL(ata_bus_reset); 5472EXPORT_SYMBOL_GPL(ata_bus_reset);
5473EXPORT_SYMBOL_GPL(ata_std_softreset);
5474EXPORT_SYMBOL_GPL(sata_std_hardreset);
5475EXPORT_SYMBOL_GPL(ata_std_postreset);
5476EXPORT_SYMBOL_GPL(ata_std_probe_reset);
5477EXPORT_SYMBOL_GPL(ata_drive_probe_reset);
5164EXPORT_SYMBOL_GPL(ata_port_disable); 5478EXPORT_SYMBOL_GPL(ata_port_disable);
5165EXPORT_SYMBOL_GPL(ata_ratelimit); 5479EXPORT_SYMBOL_GPL(ata_ratelimit);
5480EXPORT_SYMBOL_GPL(ata_busy_sleep);
5166EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 5481EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
5167EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 5482EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
5168EXPORT_SYMBOL_GPL(ata_scsi_error); 5483EXPORT_SYMBOL_GPL(ata_scsi_error);
@@ -5173,6 +5488,8 @@ EXPORT_SYMBOL_GPL(ata_dev_classify);
5173EXPORT_SYMBOL_GPL(ata_dev_id_string); 5488EXPORT_SYMBOL_GPL(ata_dev_id_string);
5174EXPORT_SYMBOL_GPL(ata_dev_config); 5489EXPORT_SYMBOL_GPL(ata_dev_config);
5175EXPORT_SYMBOL_GPL(ata_scsi_simulate); 5490EXPORT_SYMBOL_GPL(ata_scsi_simulate);
5491EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
5492EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
5176 5493
5177EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 5494EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
5178EXPORT_SYMBOL_GPL(ata_timing_compute); 5495EXPORT_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;
206error: 206error:
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
749static void ata_eh_scsidone(struct scsi_cmnd *scmd)
750{
751 /* nada */
752}
753
754static 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 */
776void 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 */
794void 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
1228static int ata_scsi_qc_complete(struct ata_queued_cmd *qc) 1269static 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
1991static int atapi_sense_complete(struct ata_queued_cmd *qc) 2033static 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
2059static int atapi_qc_complete(struct ata_queued_cmd *qc) 2100static 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);
46extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc); 46extern int ata_rwcmd_protocol(struct ata_queued_cmd *qc);
47extern void ata_qc_free(struct ata_queued_cmd *qc); 47extern void ata_qc_free(struct ata_queued_cmd *qc);
48extern int ata_qc_issue(struct ata_queued_cmd *qc); 48extern unsigned int ata_qc_issue(struct ata_queued_cmd *qc);
49extern int ata_check_atapi_dma(struct ata_queued_cmd *qc); 49extern int ata_check_atapi_dma(struct ata_queued_cmd *qc);
50extern void ata_dev_select(struct ata_port *ap, unsigned int device, 50extern 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);
131static void adma_port_stop(struct ata_port *ap); 131static void adma_port_stop(struct ata_port *ap);
132static void adma_phy_reset(struct ata_port *ap); 132static void adma_phy_reset(struct ata_port *ap);
133static void adma_qc_prep(struct ata_queued_cmd *qc); 133static void adma_qc_prep(struct ata_queued_cmd *qc);
134static int adma_qc_issue(struct ata_queued_cmd *qc); 134static unsigned int adma_qc_issue(struct ata_queued_cmd *qc);
135static int adma_check_atapi_dma(struct ata_queued_cmd *qc); 135static int adma_check_atapi_dma(struct ata_queued_cmd *qc);
136static void adma_bmdma_stop(struct ata_queued_cmd *qc); 136static void adma_bmdma_stop(struct ata_queued_cmd *qc);
137static u8 adma_bmdma_status(struct ata_port *ap); 137static 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
422static int adma_qc_issue(struct ata_queued_cmd *qc) 422static 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);
328static int mv_port_start(struct ata_port *ap); 328static int mv_port_start(struct ata_port *ap);
329static void mv_port_stop(struct ata_port *ap); 329static void mv_port_stop(struct ata_port *ap);
330static void mv_qc_prep(struct ata_queued_cmd *qc); 330static void mv_qc_prep(struct ata_queued_cmd *qc);
331static int mv_qc_issue(struct ata_queued_cmd *qc); 331static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
332static irqreturn_t mv_interrupt(int irq, void *dev_instance, 332static irqreturn_t mv_interrupt(int irq, void *dev_instance,
333 struct pt_regs *regs); 333 struct pt_regs *regs);
334static void mv_eng_timeout(struct ata_port *ap); 334static 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 */
1043static int mv_qc_issue(struct ata_queued_cmd *qc) 1043static 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)
1839static void mv_eng_timeout(struct ata_port *ap) 1839static 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
52enum { 52enum {
@@ -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
88struct pdc_host_priv {
89 int hotplug_offset;
90};
91
85static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 92static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
86static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 93static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
87static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 94static 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);
95static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 102static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
96static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 103static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
97static void pdc_irq_clear(struct ata_port *ap); 104static void pdc_irq_clear(struct ata_port *ap);
98static int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 105static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
106static void pdc_host_stop(struct ata_host_set *host_set);
99 107
100 108
101static struct scsi_host_template pdc_ata_sht = { 109static 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
143static const struct ata_port_operations pdc_pata_ops = { 151static 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
164static const struct ata_port_info pdc_port_info[] = { 172static 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
206static const struct pci_device_id pdc_ata_pci_tbl[] = { 234static 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
328static 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
301static void pdc_reset_port(struct ata_port *ap) 338static 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
431out: 458out:
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
554done_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
547static int pdc_qc_issue_prot(struct ata_queued_cmd *qc) 577static 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)
600static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 630static 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);
120static void qs_port_stop(struct ata_port *ap); 120static void qs_port_stop(struct ata_port *ap);
121static void qs_phy_reset(struct ata_port *ap); 121static void qs_phy_reset(struct ata_port *ap);
122static void qs_qc_prep(struct ata_queued_cmd *qc); 122static void qs_qc_prep(struct ata_queued_cmd *qc);
123static int qs_qc_issue(struct ata_queued_cmd *qc); 123static unsigned int qs_qc_issue(struct ata_queued_cmd *qc);
124static int qs_check_atapi_dma(struct ata_queued_cmd *qc); 124static int qs_check_atapi_dma(struct ata_queued_cmd *qc);
125static void qs_bmdma_stop(struct ata_queued_cmd *qc); 125static void qs_bmdma_stop(struct ata_queued_cmd *qc);
126static u8 qs_bmdma_status(struct ata_port *ap); 126static 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
355static int qs_qc_issue(struct ata_queued_cmd *qc) 355static 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);
251static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 251static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
252static void sil24_phy_reset(struct ata_port *ap); 252static void sil24_phy_reset(struct ata_port *ap);
253static void sil24_qc_prep(struct ata_queued_cmd *qc); 253static void sil24_qc_prep(struct ata_queued_cmd *qc);
254static int sil24_qc_issue(struct ata_queued_cmd *qc); 254static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
255static void sil24_irq_clear(struct ata_port *ap); 255static void sil24_irq_clear(struct ata_port *ap);
256static void sil24_eng_timeout(struct ata_port *ap); 256static void sil24_eng_timeout(struct ata_port *ap);
257static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *regs); 257static 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
560static int sil24_qc_issue(struct ata_queued_cmd *qc) 560static 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,
174static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, 174static void pdc20621_put_to_dimm(struct ata_probe_ent *pe,
175 void *psource, u32 offset, u32 size); 175 void *psource, u32 offset, u32 size);
176static void pdc20621_irq_clear(struct ata_port *ap); 176static void pdc20621_irq_clear(struct ata_port *ap);
177static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc); 177static unsigned int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc);
178 178
179 179
180static struct scsi_host_template pdc_sata_sht = { 180static 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
681static int pdc20621_qc_issue_prot(struct ata_queued_cmd *qc) 681static 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
902out: 892out:
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 **/
587static void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, 587void 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}
599EXPORT_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 **/
1428static void scsi_eh_flush_done_q(struct list_head *done_q) 1428void 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}
1457EXPORT_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.