aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ahci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/ahci.c')
-rw-r--r--drivers/ata/ahci.c161
1 files changed, 112 insertions, 49 deletions
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 545f330e59a5..11e4eb9f304e 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "ahci" 48#define DRV_NAME "ahci"
49#define DRV_VERSION "2.2" 49#define DRV_VERSION "2.3"
50 50
51 51
52enum { 52enum {
@@ -54,7 +54,7 @@ enum {
54 AHCI_MAX_PORTS = 32, 54 AHCI_MAX_PORTS = 32,
55 AHCI_MAX_SG = 168, /* hardware max is 64K */ 55 AHCI_MAX_SG = 168, /* hardware max is 64K */
56 AHCI_DMA_BOUNDARY = 0xffffffff, 56 AHCI_DMA_BOUNDARY = 0xffffffff,
57 AHCI_USE_CLUSTERING = 0, 57 AHCI_USE_CLUSTERING = 1,
58 AHCI_MAX_CMDS = 32, 58 AHCI_MAX_CMDS = 32,
59 AHCI_CMD_SZ = 32, 59 AHCI_CMD_SZ = 32,
60 AHCI_CMD_SLOT_SZ = AHCI_MAX_CMDS * AHCI_CMD_SZ, 60 AHCI_CMD_SLOT_SZ = AHCI_MAX_CMDS * AHCI_CMD_SZ,
@@ -81,6 +81,7 @@ enum {
81 board_ahci_vt8251 = 2, 81 board_ahci_vt8251 = 2,
82 board_ahci_ign_iferr = 3, 82 board_ahci_ign_iferr = 3,
83 board_ahci_sb600 = 4, 83 board_ahci_sb600 = 4,
84 board_ahci_mv = 5,
84 85
85 /* global controller registers */ 86 /* global controller registers */
86 HOST_CAP = 0x00, /* host capabilities */ 87 HOST_CAP = 0x00, /* host capabilities */
@@ -171,6 +172,8 @@ enum {
171 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */ 172 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */
172 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */ 173 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */
173 AHCI_FLAG_32BIT_ONLY = (1 << 28), /* force 32bit */ 174 AHCI_FLAG_32BIT_ONLY = (1 << 28), /* force 32bit */
175 AHCI_FLAG_MV_PATA = (1 << 29), /* PATA port */
176 AHCI_FLAG_NO_MSI = (1 << 30), /* no PCI MSI */
174 177
175 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 178 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
176 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 179 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
@@ -228,9 +231,12 @@ static void ahci_thaw(struct ata_port *ap);
228static void ahci_error_handler(struct ata_port *ap); 231static void ahci_error_handler(struct ata_port *ap);
229static void ahci_vt8251_error_handler(struct ata_port *ap); 232static void ahci_vt8251_error_handler(struct ata_port *ap);
230static void ahci_post_internal_cmd(struct ata_queued_cmd *qc); 233static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
234static int ahci_port_resume(struct ata_port *ap);
235static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl);
236static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
237 u32 opts);
231#ifdef CONFIG_PM 238#ifdef CONFIG_PM
232static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg); 239static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
233static int ahci_port_resume(struct ata_port *ap);
234static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 240static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
235static int ahci_pci_device_resume(struct pci_dev *pdev); 241static int ahci_pci_device_resume(struct pci_dev *pdev);
236#endif 242#endif
@@ -327,14 +333,14 @@ static const struct ata_port_info ahci_port_info[] = {
327 { 333 {
328 .flags = AHCI_FLAG_COMMON, 334 .flags = AHCI_FLAG_COMMON,
329 .pio_mask = 0x1f, /* pio0-4 */ 335 .pio_mask = 0x1f, /* pio0-4 */
330 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 336 .udma_mask = ATA_UDMA6,
331 .port_ops = &ahci_ops, 337 .port_ops = &ahci_ops,
332 }, 338 },
333 /* board_ahci_pi */ 339 /* board_ahci_pi */
334 { 340 {
335 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_HONOR_PI, 341 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_HONOR_PI,
336 .pio_mask = 0x1f, /* pio0-4 */ 342 .pio_mask = 0x1f, /* pio0-4 */
337 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 343 .udma_mask = ATA_UDMA6,
338 .port_ops = &ahci_ops, 344 .port_ops = &ahci_ops,
339 }, 345 },
340 /* board_ahci_vt8251 */ 346 /* board_ahci_vt8251 */
@@ -342,14 +348,14 @@ static const struct ata_port_info ahci_port_info[] = {
342 .flags = AHCI_FLAG_COMMON | ATA_FLAG_HRST_TO_RESUME | 348 .flags = AHCI_FLAG_COMMON | ATA_FLAG_HRST_TO_RESUME |
343 AHCI_FLAG_NO_NCQ, 349 AHCI_FLAG_NO_NCQ,
344 .pio_mask = 0x1f, /* pio0-4 */ 350 .pio_mask = 0x1f, /* pio0-4 */
345 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 351 .udma_mask = ATA_UDMA6,
346 .port_ops = &ahci_vt8251_ops, 352 .port_ops = &ahci_vt8251_ops,
347 }, 353 },
348 /* board_ahci_ign_iferr */ 354 /* board_ahci_ign_iferr */
349 { 355 {
350 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_IGN_IRQ_IF_ERR, 356 .flags = AHCI_FLAG_COMMON | AHCI_FLAG_IGN_IRQ_IF_ERR,
351 .pio_mask = 0x1f, /* pio0-4 */ 357 .pio_mask = 0x1f, /* pio0-4 */
352 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 358 .udma_mask = ATA_UDMA6,
353 .port_ops = &ahci_ops, 359 .port_ops = &ahci_ops,
354 }, 360 },
355 /* board_ahci_sb600 */ 361 /* board_ahci_sb600 */
@@ -358,7 +364,19 @@ static const struct ata_port_info ahci_port_info[] = {
358 AHCI_FLAG_IGN_SERR_INTERNAL | 364 AHCI_FLAG_IGN_SERR_INTERNAL |
359 AHCI_FLAG_32BIT_ONLY, 365 AHCI_FLAG_32BIT_ONLY,
360 .pio_mask = 0x1f, /* pio0-4 */ 366 .pio_mask = 0x1f, /* pio0-4 */
361 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 367 .udma_mask = ATA_UDMA6,
368 .port_ops = &ahci_ops,
369 },
370 /* board_ahci_mv */
371 {
372 .sht = &ahci_sht,
373 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
374 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
375 ATA_FLAG_SKIP_D2H_BSY | AHCI_FLAG_HONOR_PI |
376 AHCI_FLAG_NO_NCQ | AHCI_FLAG_NO_MSI |
377 AHCI_FLAG_MV_PATA,
378 .pio_mask = 0x1f, /* pio0-4 */
379 .udma_mask = ATA_UDMA6,
362 .port_ops = &ahci_ops, 380 .port_ops = &ahci_ops,
363 }, 381 },
364}; 382};
@@ -456,6 +474,9 @@ static const struct pci_device_id ahci_pci_tbl[] = {
456 { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 966 */ 474 { PCI_VDEVICE(SI, 0x1185), board_ahci }, /* SiS 966 */
457 { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */ 475 { PCI_VDEVICE(SI, 0x0186), board_ahci }, /* SiS 968 */
458 476
477 /* Marvell */
478 { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv }, /* 6145 */
479
459 /* Generic, PCI class code for AHCI */ 480 /* Generic, PCI class code for AHCI */
460 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 481 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
461 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci }, 482 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
@@ -481,11 +502,17 @@ static inline int ahci_nr_ports(u32 cap)
481 return (cap & 0x1f) + 1; 502 return (cap & 0x1f) + 1;
482} 503}
483 504
484static inline void __iomem *ahci_port_base(struct ata_port *ap) 505static inline void __iomem *__ahci_port_base(struct ata_host *host,
506 unsigned int port_no)
485{ 507{
486 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR]; 508 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
509
510 return mmio + 0x100 + (port_no * 0x80);
511}
487 512
488 return mmio + 0x100 + (ap->port_no * 0x80); 513static inline void __iomem *ahci_port_base(struct ata_port *ap)
514{
515 return __ahci_port_base(ap->host, ap->port_no);
489} 516}
490 517
491/** 518/**
@@ -527,7 +554,7 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
527 554
528 /* fixup zero port_map */ 555 /* fixup zero port_map */
529 if (!port_map) { 556 if (!port_map) {
530 port_map = (1 << ahci_nr_ports(hpriv->cap)) - 1; 557 port_map = (1 << ahci_nr_ports(cap)) - 1;
531 dev_printk(KERN_WARNING, &pdev->dev, 558 dev_printk(KERN_WARNING, &pdev->dev,
532 "PORTS_IMPL is zero, forcing 0x%x\n", port_map); 559 "PORTS_IMPL is zero, forcing 0x%x\n", port_map);
533 560
@@ -535,6 +562,20 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
535 hpriv->saved_port_map = port_map; 562 hpriv->saved_port_map = port_map;
536 } 563 }
537 564
565 /*
566 * Temporary Marvell 6145 hack: PATA port presence
567 * is asserted through the standard AHCI port
568 * presence register, as bit 4 (counting from 0)
569 */
570 if (pi->flags & AHCI_FLAG_MV_PATA) {
571 dev_printk(KERN_ERR, &pdev->dev,
572 "MV_AHCI HACK: port_map %x -> %x\n",
573 hpriv->port_map,
574 hpriv->port_map & 0xf);
575
576 port_map &= 0xf;
577 }
578
538 /* cross check port_map and cap.n_ports */ 579 /* cross check port_map and cap.n_ports */
539 if (pi->flags & AHCI_FLAG_HONOR_PI) { 580 if (pi->flags & AHCI_FLAG_HONOR_PI) {
540 u32 tmp_port_map = port_map; 581 u32 tmp_port_map = port_map;
@@ -740,7 +781,7 @@ static void ahci_power_down(struct ata_port *ap)
740} 781}
741#endif 782#endif
742 783
743static void ahci_init_port(struct ata_port *ap) 784static void ahci_start_port(struct ata_port *ap)
744{ 785{
745 /* enable FIS reception */ 786 /* enable FIS reception */
746 ahci_start_fis_rx(ap); 787 ahci_start_fis_rx(ap);
@@ -814,39 +855,62 @@ static int ahci_reset_controller(struct ata_host *host)
814 return 0; 855 return 0;
815} 856}
816 857
858static void ahci_port_init(struct pci_dev *pdev, struct ata_port *ap,
859 int port_no, void __iomem *mmio,
860 void __iomem *port_mmio)
861{
862 const char *emsg = NULL;
863 int rc;
864 u32 tmp;
865
866 /* make sure port is not active */
867 rc = ahci_deinit_port(ap, &emsg);
868 if (rc)
869 dev_printk(KERN_WARNING, &pdev->dev,
870 "%s (%d)\n", emsg, rc);
871
872 /* clear SError */
873 tmp = readl(port_mmio + PORT_SCR_ERR);
874 VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
875 writel(tmp, port_mmio + PORT_SCR_ERR);
876
877 /* clear port IRQ */
878 tmp = readl(port_mmio + PORT_IRQ_STAT);
879 VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
880 if (tmp)
881 writel(tmp, port_mmio + PORT_IRQ_STAT);
882
883 writel(1 << port_no, mmio + HOST_IRQ_STAT);
884}
885
817static void ahci_init_controller(struct ata_host *host) 886static void ahci_init_controller(struct ata_host *host)
818{ 887{
819 struct pci_dev *pdev = to_pci_dev(host->dev); 888 struct pci_dev *pdev = to_pci_dev(host->dev);
820 void __iomem *mmio = host->iomap[AHCI_PCI_BAR]; 889 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
821 int i, rc; 890 int i;
891 void __iomem *port_mmio;
822 u32 tmp; 892 u32 tmp;
823 893
824 for (i = 0; i < host->n_ports; i++) { 894 if (host->ports[0]->flags & AHCI_FLAG_MV_PATA) {
825 struct ata_port *ap = host->ports[i]; 895 port_mmio = __ahci_port_base(host, 4);
826 void __iomem *port_mmio = ahci_port_base(ap);
827 const char *emsg = NULL;
828
829 if (ata_port_is_dummy(ap))
830 continue;
831
832 /* make sure port is not active */
833 rc = ahci_deinit_port(ap, &emsg);
834 if (rc)
835 dev_printk(KERN_WARNING, &pdev->dev,
836 "%s (%d)\n", emsg, rc);
837 896
838 /* clear SError */ 897 writel(0, port_mmio + PORT_IRQ_MASK);
839 tmp = readl(port_mmio + PORT_SCR_ERR);
840 VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
841 writel(tmp, port_mmio + PORT_SCR_ERR);
842 898
843 /* clear port IRQ */ 899 /* clear port IRQ */
844 tmp = readl(port_mmio + PORT_IRQ_STAT); 900 tmp = readl(port_mmio + PORT_IRQ_STAT);
845 VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp); 901 VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
846 if (tmp) 902 if (tmp)
847 writel(tmp, port_mmio + PORT_IRQ_STAT); 903 writel(tmp, port_mmio + PORT_IRQ_STAT);
904 }
848 905
849 writel(1 << i, mmio + HOST_IRQ_STAT); 906 for (i = 0; i < host->n_ports; i++) {
907 struct ata_port *ap = host->ports[i];
908
909 port_mmio = ahci_port_base(ap);
910 if (ata_port_is_dummy(ap))
911 continue;
912
913 ahci_port_init(pdev, ap, i, mmio, port_mmio);
850 } 914 }
851 915
852 tmp = readl(mmio + HOST_CTL); 916 tmp = readl(mmio + HOST_CTL);
@@ -1232,7 +1296,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1232 ata_port_abort(ap); 1296 ata_port_abort(ap);
1233} 1297}
1234 1298
1235static void ahci_host_intr(struct ata_port *ap) 1299static void ahci_port_intr(struct ata_port *ap)
1236{ 1300{
1237 void __iomem *port_mmio = ap->ioaddr.cmd_addr; 1301 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
1238 struct ata_eh_info *ehi = &ap->eh_info; 1302 struct ata_eh_info *ehi = &ap->eh_info;
@@ -1358,7 +1422,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
1358 1422
1359 ap = host->ports[i]; 1423 ap = host->ports[i];
1360 if (ap) { 1424 if (ap) {
1361 ahci_host_intr(ap); 1425 ahci_port_intr(ap);
1362 VPRINTK("port %u\n", i); 1426 VPRINTK("port %u\n", i);
1363 } else { 1427 } else {
1364 VPRINTK("port %u (no irq)\n", i); 1428 VPRINTK("port %u (no irq)\n", i);
@@ -1466,7 +1530,7 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1466 ahci_power_down(ap); 1530 ahci_power_down(ap);
1467 else { 1531 else {
1468 ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc); 1532 ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc);
1469 ahci_init_port(ap); 1533 ahci_start_port(ap);
1470 } 1534 }
1471 1535
1472 return rc; 1536 return rc;
@@ -1475,7 +1539,7 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1475static int ahci_port_resume(struct ata_port *ap) 1539static int ahci_port_resume(struct ata_port *ap)
1476{ 1540{
1477 ahci_power_up(ap); 1541 ahci_power_up(ap);
1478 ahci_init_port(ap); 1542 ahci_start_port(ap);
1479 1543
1480 return 0; 1544 return 0;
1481} 1545}
@@ -1573,13 +1637,8 @@ static int ahci_port_start(struct ata_port *ap)
1573 1637
1574 ap->private_data = pp; 1638 ap->private_data = pp;
1575 1639
1576 /* power up port */ 1640 /* engage engines, captain */
1577 ahci_power_up(ap); 1641 return ahci_port_resume(ap);
1578
1579 /* initialize port */
1580 ahci_init_port(ap);
1581
1582 return 0;
1583} 1642}
1584 1643
1585static void ahci_port_stop(struct ata_port *ap) 1644static void ahci_port_stop(struct ata_port *ap)
@@ -1724,7 +1783,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1724 if (rc) 1783 if (rc)
1725 return rc; 1784 return rc;
1726 1785
1727 if (pci_enable_msi(pdev)) 1786 if ((pi.flags & AHCI_FLAG_NO_MSI) || pci_enable_msi(pdev))
1728 pci_intx(pdev, 1); 1787 pci_intx(pdev, 1);
1729 1788
1730 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); 1789 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
@@ -1745,14 +1804,18 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1745 host->private_data = hpriv; 1804 host->private_data = hpriv;
1746 1805
1747 for (i = 0; i < host->n_ports; i++) { 1806 for (i = 0; i < host->n_ports; i++) {
1748 if (hpriv->port_map & (1 << i)) { 1807 struct ata_port *ap = host->ports[i];
1749 struct ata_port *ap = host->ports[i]; 1808 void __iomem *port_mmio = ahci_port_base(ap);
1750 void __iomem *port_mmio = ahci_port_base(ap);
1751 1809
1810 /* standard SATA port setup */
1811 if (hpriv->port_map & (1 << i)) {
1752 ap->ioaddr.cmd_addr = port_mmio; 1812 ap->ioaddr.cmd_addr = port_mmio;
1753 ap->ioaddr.scr_addr = port_mmio + PORT_SCR; 1813 ap->ioaddr.scr_addr = port_mmio + PORT_SCR;
1754 } else 1814 }
1755 host->ports[i]->ops = &ata_dummy_port_ops; 1815
1816 /* disabled/not-implemented port */
1817 else
1818 ap->ops = &ata_dummy_port_ops;
1756 } 1819 }
1757 1820
1758 /* initialize adapter */ 1821 /* initialize adapter */