aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ahci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/ahci.c')
-rw-r--r--drivers/scsi/ahci.c197
1 files changed, 117 insertions, 80 deletions
diff --git a/drivers/scsi/ahci.c b/drivers/scsi/ahci.c
index 559ff7aae3f1..e97ab3e6de4d 100644
--- a/drivers/scsi/ahci.c
+++ b/drivers/scsi/ahci.c
@@ -66,6 +66,9 @@ 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_PREFETCH = (1 << 7),
70 AHCI_CMD_RESET = (1 << 8),
71 AHCI_CMD_CLR_BUSY = (1 << 10),
69 72
70 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */ 73 RX_FIS_D2H_REG = 0x40, /* offset of D2H Register FIS data */
71 74
@@ -85,6 +88,7 @@ enum {
85 88
86 /* HOST_CAP bits */ 89 /* HOST_CAP bits */
87 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */ 90 HOST_CAP_64 = (1 << 31), /* PCI DAC (64-bit DMA) support */
91 HOST_CAP_CLO = (1 << 24), /* Command List Override support */
88 92
89 /* registers for each SATA port */ 93 /* registers for each SATA port */
90 PORT_LST_ADDR = 0x00, /* command list DMA addr */ 94 PORT_LST_ADDR = 0x00, /* command list DMA addr */
@@ -138,6 +142,7 @@ enum {
138 PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */ 142 PORT_CMD_LIST_ON = (1 << 15), /* cmd list DMA engine running */
139 PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */ 143 PORT_CMD_FIS_ON = (1 << 14), /* FIS DMA engine running */
140 PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */ 144 PORT_CMD_FIS_RX = (1 << 4), /* Enable FIS receive DMA engine */
145 PORT_CMD_CLO = (1 << 3), /* Command list override */
141 PORT_CMD_POWER_ON = (1 << 2), /* Power up device */ 146 PORT_CMD_POWER_ON = (1 << 2), /* Power up device */
142 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */ 147 PORT_CMD_SPIN_UP = (1 << 1), /* Spin up device */
143 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */ 148 PORT_CMD_START = (1 << 0), /* Enable port DMA engine */
@@ -184,9 +189,9 @@ struct ahci_port_priv {
184static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg); 189static 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); 190static 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); 191static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
187static int ahci_qc_issue(struct ata_queued_cmd *qc); 192static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
188static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs); 193static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
189static void ahci_phy_reset(struct ata_port *ap); 194static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes);
190static void ahci_irq_clear(struct ata_port *ap); 195static void ahci_irq_clear(struct ata_port *ap);
191static void ahci_eng_timeout(struct ata_port *ap); 196static void ahci_eng_timeout(struct ata_port *ap);
192static int ahci_port_start(struct ata_port *ap); 197static int ahci_port_start(struct ata_port *ap);
@@ -202,11 +207,11 @@ static struct scsi_host_template ahci_sht = {
202 .name = DRV_NAME, 207 .name = DRV_NAME,
203 .ioctl = ata_scsi_ioctl, 208 .ioctl = ata_scsi_ioctl,
204 .queuecommand = ata_scsi_queuecmd, 209 .queuecommand = ata_scsi_queuecmd,
210 .eh_timed_out = ata_scsi_timed_out,
205 .eh_strategy_handler = ata_scsi_error, 211 .eh_strategy_handler = ata_scsi_error,
206 .can_queue = ATA_DEF_QUEUE, 212 .can_queue = ATA_DEF_QUEUE,
207 .this_id = ATA_SHT_THIS_ID, 213 .this_id = ATA_SHT_THIS_ID,
208 .sg_tablesize = AHCI_MAX_SG, 214 .sg_tablesize = AHCI_MAX_SG,
209 .max_sectors = ATA_MAX_SECTORS,
210 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 215 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
211 .emulated = ATA_SHT_EMULATED, 216 .emulated = ATA_SHT_EMULATED,
212 .use_clustering = AHCI_USE_CLUSTERING, 217 .use_clustering = AHCI_USE_CLUSTERING,
@@ -225,7 +230,7 @@ static const struct ata_port_operations ahci_ops = {
225 230
226 .tf_read = ahci_tf_read, 231 .tf_read = ahci_tf_read,
227 232
228 .phy_reset = ahci_phy_reset, 233 .probe_reset = ahci_probe_reset,
229 234
230 .qc_prep = ahci_qc_prep, 235 .qc_prep = ahci_qc_prep,
231 .qc_issue = ahci_qc_issue, 236 .qc_issue = ahci_qc_issue,
@@ -247,8 +252,7 @@ static const struct ata_port_info ahci_port_info[] = {
247 { 252 {
248 .sht = &ahci_sht, 253 .sht = &ahci_sht,
249 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 254 .host_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
250 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 255 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
251 ATA_FLAG_PIO_DMA,
252 .pio_mask = 0x1f, /* pio0-4 */ 256 .pio_mask = 0x1f, /* pio0-4 */
253 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 257 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
254 .port_ops = &ahci_ops, 258 .port_ops = &ahci_ops,
@@ -450,17 +454,48 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
450 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 454 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
451} 455}
452 456
453static void ahci_phy_reset(struct ata_port *ap) 457static int ahci_stop_engine(struct ata_port *ap)
454{ 458{
455 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 459 void __iomem *mmio = ap->host_set->mmio_base;
456 struct ata_taskfile tf; 460 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
457 struct ata_device *dev = &ap->device[0]; 461 int work;
458 u32 new_tmp, tmp; 462 u32 tmp;
459 463
460 __sata_phy_reset(ap); 464 tmp = readl(port_mmio + PORT_CMD);
465 tmp &= ~PORT_CMD_START;
466 writel(tmp, port_mmio + PORT_CMD);
461 467
462 if (ap->flags & ATA_FLAG_PORT_DISABLED) 468 /* wait for engine to stop. TODO: this could be
463 return; 469 * as long as 500 msec
470 */
471 work = 1000;
472 while (work-- > 0) {
473 tmp = readl(port_mmio + PORT_CMD);
474 if ((tmp & PORT_CMD_LIST_ON) == 0)
475 return 0;
476 udelay(10);
477 }
478
479 return -EIO;
480}
481
482static void ahci_start_engine(struct ata_port *ap)
483{
484 void __iomem *mmio = ap->host_set->mmio_base;
485 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
486 u32 tmp;
487
488 tmp = readl(port_mmio + PORT_CMD);
489 tmp |= PORT_CMD_START;
490 writel(tmp, port_mmio + PORT_CMD);
491 readl(port_mmio + PORT_CMD); /* flush */
492}
493
494static unsigned int ahci_dev_classify(struct ata_port *ap)
495{
496 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
497 struct ata_taskfile tf;
498 u32 tmp;
464 499
465 tmp = readl(port_mmio + PORT_SIG); 500 tmp = readl(port_mmio + PORT_SIG);
466 tf.lbah = (tmp >> 24) & 0xff; 501 tf.lbah = (tmp >> 24) & 0xff;
@@ -468,15 +503,46 @@ static void ahci_phy_reset(struct ata_port *ap)
468 tf.lbal = (tmp >> 8) & 0xff; 503 tf.lbal = (tmp >> 8) & 0xff;
469 tf.nsect = (tmp) & 0xff; 504 tf.nsect = (tmp) & 0xff;
470 505
471 dev->class = ata_dev_classify(&tf); 506 return ata_dev_classify(&tf);
472 if (!ata_dev_present(dev)) { 507}
473 ata_port_disable(ap); 508
474 return; 509static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, u32 opts)
475 } 510{
511 pp->cmd_slot[0].opts = cpu_to_le32(opts);
512 pp->cmd_slot[0].status = 0;
513 pp->cmd_slot[0].tbl_addr = cpu_to_le32(pp->cmd_tbl_dma & 0xffffffff);
514 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
515}
516
517static int ahci_hardreset(struct ata_port *ap, int verbose, unsigned int *class)
518{
519 int rc;
520
521 DPRINTK("ENTER\n");
522
523 ahci_stop_engine(ap);
524 rc = sata_std_hardreset(ap, verbose, class);
525 ahci_start_engine(ap);
526
527 if (rc == 0)
528 *class = ahci_dev_classify(ap);
529 if (*class == ATA_DEV_UNKNOWN)
530 *class = ATA_DEV_NONE;
531
532 DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
533 return rc;
534}
535
536static void ahci_postreset(struct ata_port *ap, unsigned int *class)
537{
538 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;
539 u32 new_tmp, tmp;
540
541 ata_std_postreset(ap, class);
476 542
477 /* Make sure port's ATAPI bit is set appropriately */ 543 /* Make sure port's ATAPI bit is set appropriately */
478 new_tmp = tmp = readl(port_mmio + PORT_CMD); 544 new_tmp = tmp = readl(port_mmio + PORT_CMD);
479 if (dev->class == ATA_DEV_ATAPI) 545 if (*class == ATA_DEV_ATAPI)
480 new_tmp |= PORT_CMD_ATAPI; 546 new_tmp |= PORT_CMD_ATAPI;
481 else 547 else
482 new_tmp &= ~PORT_CMD_ATAPI; 548 new_tmp &= ~PORT_CMD_ATAPI;
@@ -486,6 +552,12 @@ static void ahci_phy_reset(struct ata_port *ap)
486 } 552 }
487} 553}
488 554
555static int ahci_probe_reset(struct ata_port *ap, unsigned int *classes)
556{
557 return ata_drive_probe_reset(ap, NULL, NULL, ahci_hardreset,
558 ahci_postreset, classes);
559}
560
489static u8 ahci_check_status(struct ata_port *ap) 561static u8 ahci_check_status(struct ata_port *ap)
490{ 562{
491 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr; 563 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr;
@@ -533,42 +605,36 @@ static void ahci_qc_prep(struct ata_queued_cmd *qc)
533{ 605{
534 struct ata_port *ap = qc->ap; 606 struct ata_port *ap = qc->ap;
535 struct ahci_port_priv *pp = ap->private_data; 607 struct ahci_port_priv *pp = ap->private_data;
608 int is_atapi = is_atapi_taskfile(&qc->tf);
536 u32 opts; 609 u32 opts;
537 const u32 cmd_fis_len = 5; /* five dwords */ 610 const u32 cmd_fis_len = 5; /* five dwords */
538 unsigned int n_elem; 611 unsigned int n_elem;
539 612
540 /* 613 /*
541 * Fill in command slot information (currently only one slot,
542 * slot 0, is currently since we don't do queueing)
543 */
544
545 opts = cmd_fis_len;
546 if (qc->tf.flags & ATA_TFLAG_WRITE)
547 opts |= AHCI_CMD_WRITE;
548 if (is_atapi_taskfile(&qc->tf))
549 opts |= AHCI_CMD_ATAPI;
550
551 pp->cmd_slot[0].opts = cpu_to_le32(opts);
552 pp->cmd_slot[0].status = 0;
553 pp->cmd_slot[0].tbl_addr = cpu_to_le32(pp->cmd_tbl_dma & 0xffffffff);
554 pp->cmd_slot[0].tbl_addr_hi = cpu_to_le32((pp->cmd_tbl_dma >> 16) >> 16);
555
556 /*
557 * Fill in command table information. First, the header, 614 * Fill in command table information. First, the header,
558 * a SATA Register - Host to Device command FIS. 615 * a SATA Register - Host to Device command FIS.
559 */ 616 */
560 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0); 617 ata_tf_to_fis(&qc->tf, pp->cmd_tbl, 0);
561 if (opts & AHCI_CMD_ATAPI) { 618 if (is_atapi) {
562 memset(pp->cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32); 619 memset(pp->cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
563 memcpy(pp->cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, ap->cdb_len); 620 memcpy(pp->cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb,
621 qc->dev->cdb_len);
564 } 622 }
565 623
566 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 624 n_elem = 0;
567 return; 625 if (qc->flags & ATA_QCFLAG_DMAMAP)
626 n_elem = ahci_fill_sg(qc);
568 627
569 n_elem = ahci_fill_sg(qc); 628 /*
629 * Fill in command slot information.
630 */
631 opts = cmd_fis_len | n_elem << 16;
632 if (qc->tf.flags & ATA_TFLAG_WRITE)
633 opts |= AHCI_CMD_WRITE;
634 if (is_atapi)
635 opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
570 636
571 pp->cmd_slot[0].opts |= cpu_to_le32(n_elem << 16); 637 ahci_fill_cmd_slot(pp, opts);
572} 638}
573 639
574static void ahci_restart_port(struct ata_port *ap, u32 irq_stat) 640static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
@@ -576,7 +642,6 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
576 void __iomem *mmio = ap->host_set->mmio_base; 642 void __iomem *mmio = ap->host_set->mmio_base;
577 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 643 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
578 u32 tmp; 644 u32 tmp;
579 int work;
580 645
581 if ((ap->device[0].class != ATA_DEV_ATAPI) || 646 if ((ap->device[0].class != ATA_DEV_ATAPI) ||
582 ((irq_stat & PORT_IRQ_TF_ERR) == 0)) 647 ((irq_stat & PORT_IRQ_TF_ERR) == 0))
@@ -592,20 +657,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
592 readl(port_mmio + PORT_SCR_ERR)); 657 readl(port_mmio + PORT_SCR_ERR));
593 658
594 /* stop DMA */ 659 /* stop DMA */
595 tmp = readl(port_mmio + PORT_CMD); 660 ahci_stop_engine(ap);
596 tmp &= ~PORT_CMD_START;
597 writel(tmp, port_mmio + PORT_CMD);
598
599 /* wait for engine to stop. TODO: this could be
600 * as long as 500 msec
601 */
602 work = 1000;
603 while (work-- > 0) {
604 tmp = readl(port_mmio + PORT_CMD);
605 if ((tmp & PORT_CMD_LIST_ON) == 0)
606 break;
607 udelay(10);
608 }
609 661
610 /* clear SATA phy error, if any */ 662 /* clear SATA phy error, if any */
611 tmp = readl(port_mmio + PORT_SCR_ERR); 663 tmp = readl(port_mmio + PORT_SCR_ERR);
@@ -624,10 +676,7 @@ static void ahci_restart_port(struct ata_port *ap, u32 irq_stat)
624 } 676 }
625 677
626 /* re-start DMA */ 678 /* re-start DMA */
627 tmp = readl(port_mmio + PORT_CMD); 679 ahci_start_engine(ap);
628 tmp |= PORT_CMD_START;
629 writel(tmp, port_mmio + PORT_CMD);
630 readl(port_mmio + PORT_CMD); /* flush */
631} 680}
632 681
633static void ahci_eng_timeout(struct ata_port *ap) 682static void ahci_eng_timeout(struct ata_port *ap)
@@ -642,25 +691,13 @@ static void ahci_eng_timeout(struct ata_port *ap)
642 691
643 spin_lock_irqsave(&host_set->lock, flags); 692 spin_lock_irqsave(&host_set->lock, flags);
644 693
694 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
645 qc = ata_qc_from_tag(ap, ap->active_tag); 695 qc = ata_qc_from_tag(ap, ap->active_tag);
646 if (!qc) { 696 qc->err_mask |= AC_ERR_TIMEOUT;
647 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
648 ap->id);
649 } else {
650 ahci_restart_port(ap, readl(port_mmio + PORT_IRQ_STAT));
651
652 /* hack alert! We cannot use the supplied completion
653 * function from inside the ->eh_strategy_handler() thread.
654 * libata is the only user of ->eh_strategy_handler() in
655 * any kernel, so the default scsi_done() assumes it is
656 * not being called from the SCSI EH.
657 */
658 qc->scsidone = scsi_finish_command;
659 qc->err_mask |= AC_ERR_OTHER;
660 ata_qc_complete(qc);
661 }
662 697
663 spin_unlock_irqrestore(&host_set->lock, flags); 698 spin_unlock_irqrestore(&host_set->lock, flags);
699
700 ata_eh_qc_complete(qc);
664} 701}
665 702
666static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 703static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
@@ -678,7 +715,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
678 ci = readl(port_mmio + PORT_CMD_ISSUE); 715 ci = readl(port_mmio + PORT_CMD_ISSUE);
679 if (likely((ci & 0x1) == 0)) { 716 if (likely((ci & 0x1) == 0)) {
680 if (qc) { 717 if (qc) {
681 assert(qc->err_mask == 0); 718 WARN_ON(qc->err_mask);
682 ata_qc_complete(qc); 719 ata_qc_complete(qc);
683 qc = NULL; 720 qc = NULL;
684 } 721 }
@@ -697,7 +734,7 @@ static inline int ahci_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
697 ahci_restart_port(ap, status); 734 ahci_restart_port(ap, status);
698 735
699 if (qc) { 736 if (qc) {
700 qc->err_mask |= AC_ERR_OTHER; 737 qc->err_mask |= err_mask;
701 ata_qc_complete(qc); 738 ata_qc_complete(qc);
702 } 739 }
703 } 740 }
@@ -770,7 +807,7 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
770 return IRQ_RETVAL(handled); 807 return IRQ_RETVAL(handled);
771} 808}
772 809
773static int ahci_qc_issue(struct ata_queued_cmd *qc) 810static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
774{ 811{
775 struct ata_port *ap = qc->ap; 812 struct ata_port *ap = qc->ap;
776 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 813 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr;