aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2009-01-09 03:39:43 -0500
committerLen Brown <len.brown@intel.com>2009-01-09 03:39:43 -0500
commitb2576e1d4408e134e2188c967b1f28af39cd79d4 (patch)
tree004f3c82faab760f304ce031d6d2f572e7746a50 /drivers/ata
parent3cc8a5f4ba91f67bbdb81a43a99281a26aab8d77 (diff)
parent2150edc6c5cf00f7adb54538b9ea2a3e9cedca3f (diff)
Merge branch 'linus' into release
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/Kconfig3
-rw-r--r--drivers/ata/ahci.c18
-rw-r--r--drivers/ata/ata_generic.c5
-rw-r--r--drivers/ata/ata_piix.c72
-rw-r--r--drivers/ata/libata-acpi.c19
-rw-r--r--drivers/ata/libata-core.c305
-rw-r--r--drivers/ata/libata-eh.c116
-rw-r--r--drivers/ata/libata-pmp.c22
-rw-r--r--drivers/ata/libata-scsi.c28
-rw-r--r--drivers/ata/libata-sff.c185
-rw-r--r--drivers/ata/pata_ali.c107
-rw-r--r--drivers/ata/pata_amd.c4
-rw-r--r--drivers/ata/pata_bf54x.c1
-rw-r--r--drivers/ata/pata_hpt366.c109
-rw-r--r--drivers/ata/pata_hpt3x3.c49
-rw-r--r--drivers/ata/pata_it821x.c34
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c14
-rw-r--r--drivers/ata/pata_legacy.c18
-rw-r--r--drivers/ata/pata_mpc52xx.c546
-rw-r--r--drivers/ata/pata_mpiix.c3
-rw-r--r--drivers/ata/pata_oldpiix.c1
-rw-r--r--drivers/ata/pata_pdc2027x.c29
-rw-r--r--drivers/ata/pata_platform.c16
-rw-r--r--drivers/ata/pata_radisys.c1
-rw-r--r--drivers/ata/pata_rz1000.c16
-rw-r--r--drivers/ata/pata_scc.c1
-rw-r--r--drivers/ata/pata_serverworks.c1
-rw-r--r--drivers/ata/pata_sil680.c4
-rw-r--r--drivers/ata/pata_sis.c1
-rw-r--r--drivers/ata/sata_mv.c1
-rw-r--r--drivers/ata/sata_sil.c98
-rw-r--r--drivers/ata/sata_sil24.c7
32 files changed, 1254 insertions, 580 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 421b7c71e72d..1a7be96d627b 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -456,7 +456,8 @@ config PATA_MARVELL
456 456
457config PATA_MPC52xx 457config PATA_MPC52xx
458 tristate "Freescale MPC52xx SoC internal IDE" 458 tristate "Freescale MPC52xx SoC internal IDE"
459 depends on PPC_MPC52xx 459 depends on PPC_MPC52xx && PPC_BESTCOMM
460 select PPC_BESTCOMM_ATA
460 help 461 help
461 This option enables support for integrated IDE controller 462 This option enables support for integrated IDE controller
462 of the Freescale MPC52xx SoC. 463 of the Freescale MPC52xx SoC.
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index a67b8e7c712d..7f701cbe14ab 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -105,7 +105,7 @@ enum {
105 board_ahci_ign_iferr = 2, 105 board_ahci_ign_iferr = 2,
106 board_ahci_sb600 = 3, 106 board_ahci_sb600 = 3,
107 board_ahci_mv = 4, 107 board_ahci_mv = 4,
108 board_ahci_sb700 = 5, 108 board_ahci_sb700 = 5, /* for SB700 and SB800 */
109 board_ahci_mcp65 = 6, 109 board_ahci_mcp65 = 6,
110 board_ahci_nopmp = 7, 110 board_ahci_nopmp = 7,
111 111
@@ -439,7 +439,7 @@ static const struct ata_port_info ahci_port_info[] = {
439 .udma_mask = ATA_UDMA6, 439 .udma_mask = ATA_UDMA6,
440 .port_ops = &ahci_ops, 440 .port_ops = &ahci_ops,
441 }, 441 },
442 /* board_ahci_sb700 */ 442 /* board_ahci_sb700, for SB700 and SB800 */
443 { 443 {
444 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL), 444 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
445 .flags = AHCI_FLAG_COMMON, 445 .flags = AHCI_FLAG_COMMON,
@@ -1119,14 +1119,14 @@ static void ahci_start_port(struct ata_port *ap)
1119 1119
1120 /* turn on LEDs */ 1120 /* turn on LEDs */
1121 if (ap->flags & ATA_FLAG_EM) { 1121 if (ap->flags & ATA_FLAG_EM) {
1122 ata_port_for_each_link(link, ap) { 1122 ata_for_each_link(link, ap, EDGE) {
1123 emp = &pp->em_priv[link->pmp]; 1123 emp = &pp->em_priv[link->pmp];
1124 ahci_transmit_led_message(ap, emp->led_state, 4); 1124 ahci_transmit_led_message(ap, emp->led_state, 4);
1125 } 1125 }
1126 } 1126 }
1127 1127
1128 if (ap->flags & ATA_FLAG_SW_ACTIVITY) 1128 if (ap->flags & ATA_FLAG_SW_ACTIVITY)
1129 ata_port_for_each_link(link, ap) 1129 ata_for_each_link(link, ap, EDGE)
1130 ahci_init_sw_activity(link); 1130 ahci_init_sw_activity(link);
1131 1131
1132} 1132}
@@ -1361,7 +1361,7 @@ static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
1361 struct ahci_em_priv *emp; 1361 struct ahci_em_priv *emp;
1362 int rc = 0; 1362 int rc = 0;
1363 1363
1364 ata_port_for_each_link(link, ap) { 1364 ata_for_each_link(link, ap, EDGE) {
1365 emp = &pp->em_priv[link->pmp]; 1365 emp = &pp->em_priv[link->pmp];
1366 rc += sprintf(buf, "%lx\n", emp->led_state); 1366 rc += sprintf(buf, "%lx\n", emp->led_state);
1367 } 1367 }
@@ -1941,7 +1941,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1941 u32 serror; 1941 u32 serror;
1942 1942
1943 /* determine active link */ 1943 /* determine active link */
1944 ata_port_for_each_link(link, ap) 1944 ata_for_each_link(link, ap, EDGE)
1945 if (ata_link_active(link)) 1945 if (ata_link_active(link))
1946 break; 1946 break;
1947 if (!link) 1947 if (!link)
@@ -2446,6 +2446,8 @@ static void ahci_print_info(struct ata_host *host)
2446 speed_s = "1.5"; 2446 speed_s = "1.5";
2447 else if (speed == 2) 2447 else if (speed == 2)
2448 speed_s = "3"; 2448 speed_s = "3";
2449 else if (speed == 3)
2450 speed_s = "6";
2449 else 2451 else
2450 speed_s = "?"; 2452 speed_s = "?";
2451 2453
@@ -2610,6 +2612,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2610 (pdev->revision == 0xa1 || pdev->revision == 0xa2)) 2612 (pdev->revision == 0xa1 || pdev->revision == 0xa2))
2611 hpriv->flags |= AHCI_HFLAG_NO_MSI; 2613 hpriv->flags |= AHCI_HFLAG_NO_MSI;
2612 2614
2615 /* SB800 does NOT need the workaround to ignore SERR_INTERNAL */
2616 if (board_id == board_ahci_sb700 && pdev->revision >= 0x40)
2617 hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL;
2618
2613 if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev)) 2619 if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
2614 pci_intx(pdev, 1); 2620 pci_intx(pdev, 1);
2615 2621
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 5c33767e66de..dc48a6398abe 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -57,10 +57,7 @@ static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
57 if (pdev->vendor == PCI_VENDOR_ID_CENATEK) 57 if (pdev->vendor == PCI_VENDOR_ID_CENATEK)
58 dma_enabled = 0xFF; 58 dma_enabled = 0xFF;
59 59
60 ata_link_for_each_dev(dev, link) { 60 ata_for_each_dev(dev, link, ENABLED) {
61 if (!ata_dev_enabled(dev))
62 continue;
63
64 /* We don't really care */ 61 /* We don't really care */
65 dev->pio_mode = XFER_PIO_0; 62 dev->pio_mode = XFER_PIO_0;
66 dev->dma_mode = XFER_MW_DMA_0; 63 dev->dma_mode = XFER_MW_DMA_0;
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index c11936e13dd3..887d8f46a287 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -154,11 +154,13 @@ struct piix_map_db {
154 154
155struct piix_host_priv { 155struct piix_host_priv {
156 const int *map; 156 const int *map;
157 u32 saved_iocfg;
157 void __iomem *sidpr; 158 void __iomem *sidpr;
158}; 159};
159 160
160static int piix_init_one(struct pci_dev *pdev, 161static int piix_init_one(struct pci_dev *pdev,
161 const struct pci_device_id *ent); 162 const struct pci_device_id *ent);
163static void piix_remove_one(struct pci_dev *pdev);
162static int piix_pata_prereset(struct ata_link *link, unsigned long deadline); 164static int piix_pata_prereset(struct ata_link *link, unsigned long deadline);
163static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev); 165static void piix_set_piomode(struct ata_port *ap, struct ata_device *adev);
164static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev); 166static void piix_set_dmamode(struct ata_port *ap, struct ata_device *adev);
@@ -296,7 +298,7 @@ static struct pci_driver piix_pci_driver = {
296 .name = DRV_NAME, 298 .name = DRV_NAME,
297 .id_table = piix_pci_tbl, 299 .id_table = piix_pci_tbl,
298 .probe = piix_init_one, 300 .probe = piix_init_one,
299 .remove = ata_pci_remove_one, 301 .remove = piix_remove_one,
300#ifdef CONFIG_PM 302#ifdef CONFIG_PM
301 .suspend = piix_pci_device_suspend, 303 .suspend = piix_pci_device_suspend,
302 .resume = piix_pci_device_resume, 304 .resume = piix_pci_device_resume,
@@ -308,7 +310,7 @@ static struct scsi_host_template piix_sht = {
308}; 310};
309 311
310static struct ata_port_operations piix_pata_ops = { 312static struct ata_port_operations piix_pata_ops = {
311 .inherits = &ata_bmdma_port_ops, 313 .inherits = &ata_bmdma32_port_ops,
312 .cable_detect = ata_cable_40wire, 314 .cable_detect = ata_cable_40wire,
313 .set_piomode = piix_set_piomode, 315 .set_piomode = piix_set_piomode,
314 .set_dmamode = piix_set_dmamode, 316 .set_dmamode = piix_set_dmamode,
@@ -610,8 +612,9 @@ static const struct ich_laptop ich_laptop[] = {
610static int ich_pata_cable_detect(struct ata_port *ap) 612static int ich_pata_cable_detect(struct ata_port *ap)
611{ 613{
612 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 614 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
615 struct piix_host_priv *hpriv = ap->host->private_data;
613 const struct ich_laptop *lap = &ich_laptop[0]; 616 const struct ich_laptop *lap = &ich_laptop[0];
614 u8 tmp, mask; 617 u8 mask;
615 618
616 /* Check for specials - Acer Aspire 5602WLMi */ 619 /* Check for specials - Acer Aspire 5602WLMi */
617 while (lap->device) { 620 while (lap->device) {
@@ -625,8 +628,7 @@ static int ich_pata_cable_detect(struct ata_port *ap)
625 628
626 /* check BIOS cable detect results */ 629 /* check BIOS cable detect results */
627 mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC; 630 mask = ap->port_no == 0 ? PIIX_80C_PRI : PIIX_80C_SEC;
628 pci_read_config_byte(pdev, PIIX_IOCFG, &tmp); 631 if ((hpriv->saved_iocfg & mask) == 0)
629 if ((tmp & mask) == 0)
630 return ATA_CBL_PATA40; 632 return ATA_CBL_PATA40;
631 return ATA_CBL_PATA80; 633 return ATA_CBL_PATA80;
632} 634}
@@ -1072,20 +1074,13 @@ static int piix_broken_suspend(void)
1072 * matching is necessary because dmi_system_id.matches is 1074 * matching is necessary because dmi_system_id.matches is
1073 * limited to four entries. 1075 * limited to four entries.
1074 */ 1076 */
1075 if (dmi_get_system_info(DMI_SYS_VENDOR) && 1077 if (dmi_match(DMI_SYS_VENDOR, "TOSHIBA") &&
1076 dmi_get_system_info(DMI_PRODUCT_NAME) && 1078 dmi_match(DMI_PRODUCT_NAME, "000000") &&
1077 dmi_get_system_info(DMI_PRODUCT_VERSION) && 1079 dmi_match(DMI_PRODUCT_VERSION, "000000") &&
1078 dmi_get_system_info(DMI_PRODUCT_SERIAL) && 1080 dmi_match(DMI_PRODUCT_SERIAL, "000000") &&
1079 dmi_get_system_info(DMI_BOARD_VENDOR) && 1081 dmi_match(DMI_BOARD_VENDOR, "TOSHIBA") &&
1080 dmi_get_system_info(DMI_BOARD_NAME) && 1082 dmi_match(DMI_BOARD_NAME, "Portable PC") &&
1081 dmi_get_system_info(DMI_BOARD_VERSION) && 1083 dmi_match(DMI_BOARD_VERSION, "Version A0"))
1082 !strcmp(dmi_get_system_info(DMI_SYS_VENDOR), "TOSHIBA") &&
1083 !strcmp(dmi_get_system_info(DMI_PRODUCT_NAME), "000000") &&
1084 !strcmp(dmi_get_system_info(DMI_PRODUCT_VERSION), "000000") &&
1085 !strcmp(dmi_get_system_info(DMI_PRODUCT_SERIAL), "000000") &&
1086 !strcmp(dmi_get_system_info(DMI_BOARD_VENDOR), "TOSHIBA") &&
1087 !strcmp(dmi_get_system_info(DMI_BOARD_NAME), "Portable PC") &&
1088 !strcmp(dmi_get_system_info(DMI_BOARD_VERSION), "Version A0"))
1089 return 1; 1084 return 1;
1090 1085
1091 return 0; 1086 return 0;
@@ -1357,7 +1352,7 @@ static int __devinit piix_init_sidpr(struct ata_host *host)
1357 return 0; 1352 return 0;
1358} 1353}
1359 1354
1360static void piix_iocfg_bit18_quirk(struct pci_dev *pdev) 1355static void piix_iocfg_bit18_quirk(struct ata_host *host)
1361{ 1356{
1362 static const struct dmi_system_id sysids[] = { 1357 static const struct dmi_system_id sysids[] = {
1363 { 1358 {
@@ -1374,7 +1369,8 @@ static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
1374 1369
1375 { } /* terminate list */ 1370 { } /* terminate list */
1376 }; 1371 };
1377 u32 iocfg; 1372 struct pci_dev *pdev = to_pci_dev(host->dev);
1373 struct piix_host_priv *hpriv = host->private_data;
1378 1374
1379 if (!dmi_check_system(sysids)) 1375 if (!dmi_check_system(sysids))
1380 return; 1376 return;
@@ -1383,12 +1379,11 @@ static void piix_iocfg_bit18_quirk(struct pci_dev *pdev)
1383 * seem to use it to disable a channel. Clear the bit on the 1379 * seem to use it to disable a channel. Clear the bit on the
1384 * affected systems. 1380 * affected systems.
1385 */ 1381 */
1386 pci_read_config_dword(pdev, PIIX_IOCFG, &iocfg); 1382 if (hpriv->saved_iocfg & (1 << 18)) {
1387 if (iocfg & (1 << 18)) {
1388 dev_printk(KERN_INFO, &pdev->dev, 1383 dev_printk(KERN_INFO, &pdev->dev,
1389 "applying IOCFG bit18 quirk\n"); 1384 "applying IOCFG bit18 quirk\n");
1390 iocfg &= ~(1 << 18); 1385 pci_write_config_dword(pdev, PIIX_IOCFG,
1391 pci_write_config_dword(pdev, PIIX_IOCFG, iocfg); 1386 hpriv->saved_iocfg & ~(1 << 18));
1392 } 1387 }
1393} 1388}
1394 1389
@@ -1437,6 +1432,17 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1437 if (rc) 1432 if (rc)
1438 return rc; 1433 return rc;
1439 1434
1435 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1436 if (!hpriv)
1437 return -ENOMEM;
1438
1439 /* Save IOCFG, this will be used for cable detection, quirk
1440 * detection and restoration on detach. This is necessary
1441 * because some ACPI implementations mess up cable related
1442 * bits on _STM. Reported on kernel bz#11879.
1443 */
1444 pci_read_config_dword(pdev, PIIX_IOCFG, &hpriv->saved_iocfg);
1445
1440 /* ICH6R may be driven by either ata_piix or ahci driver 1446 /* ICH6R may be driven by either ata_piix or ahci driver
1441 * regardless of BIOS configuration. Make sure AHCI mode is 1447 * regardless of BIOS configuration. Make sure AHCI mode is
1442 * off. 1448 * off.
@@ -1448,10 +1454,6 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1448 } 1454 }
1449 1455
1450 /* SATA map init can change port_info, do it before prepping host */ 1456 /* SATA map init can change port_info, do it before prepping host */
1451 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1452 if (!hpriv)
1453 return -ENOMEM;
1454
1455 if (port_flags & ATA_FLAG_SATA) 1457 if (port_flags & ATA_FLAG_SATA)
1456 hpriv->map = piix_init_sata_map(pdev, port_info, 1458 hpriv->map = piix_init_sata_map(pdev, port_info,
1457 piix_map_db_table[ent->driver_data]); 1459 piix_map_db_table[ent->driver_data]);
@@ -1470,7 +1472,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1470 } 1472 }
1471 1473
1472 /* apply IOCFG bit18 quirk */ 1474 /* apply IOCFG bit18 quirk */
1473 piix_iocfg_bit18_quirk(pdev); 1475 piix_iocfg_bit18_quirk(host);
1474 1476
1475 /* On ICH5, some BIOSen disable the interrupt using the 1477 /* On ICH5, some BIOSen disable the interrupt using the
1476 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3. 1478 * PCI_COMMAND_INTX_DISABLE bit added in PCI 2.3.
@@ -1495,6 +1497,16 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1495 return ata_pci_sff_activate_host(host, ata_sff_interrupt, &piix_sht); 1497 return ata_pci_sff_activate_host(host, ata_sff_interrupt, &piix_sht);
1496} 1498}
1497 1499
1500static void piix_remove_one(struct pci_dev *pdev)
1501{
1502 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1503 struct piix_host_priv *hpriv = host->private_data;
1504
1505 pci_write_config_dword(pdev, PIIX_IOCFG, hpriv->saved_iocfg);
1506
1507 ata_pci_remove_one(pdev);
1508}
1509
1498static int __init piix_init(void) 1510static int __init piix_init(void)
1499{ 1511{
1500 int rc; 1512 int rc;
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 246987f0b88c..6273d98d00eb 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -83,7 +83,7 @@ void ata_acpi_associate_sata_port(struct ata_port *ap)
83 83
84 ap->link.device->acpi_handle = NULL; 84 ap->link.device->acpi_handle = NULL;
85 85
86 ata_port_for_each_link(link, ap) { 86 ata_for_each_link(link, ap, EDGE) {
87 acpi_integer adr = SATA_ADR(ap->port_no, link->pmp); 87 acpi_integer adr = SATA_ADR(ap->port_no, link->pmp);
88 88
89 link->device->acpi_handle = 89 link->device->acpi_handle =
@@ -123,8 +123,8 @@ static void ata_acpi_detach_device(struct ata_port *ap, struct ata_device *dev)
123 struct ata_link *tlink; 123 struct ata_link *tlink;
124 struct ata_device *tdev; 124 struct ata_device *tdev;
125 125
126 ata_port_for_each_link(tlink, ap) 126 ata_for_each_link(tlink, ap, EDGE)
127 ata_link_for_each_dev(tdev, tlink) 127 ata_for_each_dev(tdev, tlink, ALL)
128 tdev->flags |= ATA_DFLAG_DETACH; 128 tdev->flags |= ATA_DFLAG_DETACH;
129 } 129 }
130 130
@@ -582,12 +582,9 @@ int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm)
582{ 582{
583 struct ata_device *dev; 583 struct ata_device *dev;
584 584
585 ata_link_for_each_dev(dev, &ap->link) { 585 ata_for_each_dev(dev, &ap->link, ENABLED) {
586 unsigned long xfer_mask, udma_mask; 586 unsigned long xfer_mask, udma_mask;
587 587
588 if (!ata_dev_enabled(dev))
589 continue;
590
591 xfer_mask = ata_acpi_gtm_xfermask(dev, gtm); 588 xfer_mask = ata_acpi_gtm_xfermask(dev, gtm);
592 ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask); 589 ata_unpack_xfermask(xfer_mask, NULL, NULL, &udma_mask);
593 590
@@ -887,7 +884,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
887 * use values set by _STM. Cache _GTF result and 884 * use values set by _STM. Cache _GTF result and
888 * schedule _GTF. 885 * schedule _GTF.
889 */ 886 */
890 ata_link_for_each_dev(dev, &ap->link) { 887 ata_for_each_dev(dev, &ap->link, ALL) {
891 ata_acpi_clear_gtf(dev); 888 ata_acpi_clear_gtf(dev);
892 if (ata_dev_enabled(dev) && 889 if (ata_dev_enabled(dev) &&
893 ata_dev_get_GTF(dev, NULL) >= 0) 890 ata_dev_get_GTF(dev, NULL) >= 0)
@@ -898,7 +895,7 @@ void ata_acpi_on_resume(struct ata_port *ap)
898 * there's no reason to evaluate IDE _GTF early 895 * there's no reason to evaluate IDE _GTF early
899 * without _STM. Clear cache and schedule _GTF. 896 * without _STM. Clear cache and schedule _GTF.
900 */ 897 */
901 ata_link_for_each_dev(dev, &ap->link) { 898 ata_for_each_dev(dev, &ap->link, ALL) {
902 ata_acpi_clear_gtf(dev); 899 ata_acpi_clear_gtf(dev);
903 if (ata_dev_enabled(dev)) 900 if (ata_dev_enabled(dev))
904 dev->flags |= ATA_DFLAG_ACPI_PENDING; 901 dev->flags |= ATA_DFLAG_ACPI_PENDING;
@@ -926,8 +923,8 @@ void ata_acpi_set_state(struct ata_port *ap, pm_message_t state)
926 if (state.event == PM_EVENT_ON) 923 if (state.event == PM_EVENT_ON)
927 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0); 924 acpi_bus_set_power(ap->acpi_handle, ACPI_STATE_D0);
928 925
929 ata_link_for_each_dev(dev, &ap->link) { 926 ata_for_each_dev(dev, &ap->link, ENABLED) {
930 if (dev->acpi_handle && ata_dev_enabled(dev)) 927 if (dev->acpi_handle)
931 acpi_bus_set_power(dev->acpi_handle, 928 acpi_bus_set_power(dev->acpi_handle,
932 state.event == PM_EVENT_ON ? 929 state.event == PM_EVENT_ON ?
933 ACPI_STATE_D0 : ACPI_STATE_D3); 930 ACPI_STATE_D0 : ACPI_STATE_D3);
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index bc6695e3c848..175df54eb664 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -56,6 +56,7 @@
56#include <linux/workqueue.h> 56#include <linux/workqueue.h>
57#include <linux/scatterlist.h> 57#include <linux/scatterlist.h>
58#include <linux/io.h> 58#include <linux/io.h>
59#include <linux/async.h>
59#include <scsi/scsi.h> 60#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h> 61#include <scsi/scsi_cmnd.h>
61#include <scsi/scsi_host.h> 62#include <scsi/scsi_host.h>
@@ -163,43 +164,119 @@ MODULE_LICENSE("GPL");
163MODULE_VERSION(DRV_VERSION); 164MODULE_VERSION(DRV_VERSION);
164 165
165 166
166/* 167/**
167 * Iterator helpers. Don't use directly. 168 * ata_link_next - link iteration helper
169 * @link: the previous link, NULL to start
170 * @ap: ATA port containing links to iterate
171 * @mode: iteration mode, one of ATA_LITER_*
172 *
173 * LOCKING:
174 * Host lock or EH context.
168 * 175 *
169 * LOCKING: 176 * RETURNS:
170 * Host lock or EH context. 177 * Pointer to the next link.
171 */ 178 */
172struct ata_link *__ata_port_next_link(struct ata_port *ap, 179struct ata_link *ata_link_next(struct ata_link *link, struct ata_port *ap,
173 struct ata_link *link, bool dev_only) 180 enum ata_link_iter_mode mode)
174{ 181{
182 BUG_ON(mode != ATA_LITER_EDGE &&
183 mode != ATA_LITER_PMP_FIRST && mode != ATA_LITER_HOST_FIRST);
184
175 /* NULL link indicates start of iteration */ 185 /* NULL link indicates start of iteration */
176 if (!link) { 186 if (!link)
177 if (dev_only && sata_pmp_attached(ap)) 187 switch (mode) {
178 return ap->pmp_link; 188 case ATA_LITER_EDGE:
179 return &ap->link; 189 case ATA_LITER_PMP_FIRST:
180 } 190 if (sata_pmp_attached(ap))
191 return ap->pmp_link;
192 /* fall through */
193 case ATA_LITER_HOST_FIRST:
194 return &ap->link;
195 }
181 196
182 /* we just iterated over the host master link, what's next? */ 197 /* we just iterated over the host link, what's next? */
183 if (link == &ap->link) { 198 if (link == &ap->link)
184 if (!sata_pmp_attached(ap)) { 199 switch (mode) {
185 if (unlikely(ap->slave_link) && !dev_only) 200 case ATA_LITER_HOST_FIRST:
201 if (sata_pmp_attached(ap))
202 return ap->pmp_link;
203 /* fall through */
204 case ATA_LITER_PMP_FIRST:
205 if (unlikely(ap->slave_link))
186 return ap->slave_link; 206 return ap->slave_link;
207 /* fall through */
208 case ATA_LITER_EDGE:
187 return NULL; 209 return NULL;
188 } 210 }
189 return ap->pmp_link;
190 }
191 211
192 /* slave_link excludes PMP */ 212 /* slave_link excludes PMP */
193 if (unlikely(link == ap->slave_link)) 213 if (unlikely(link == ap->slave_link))
194 return NULL; 214 return NULL;
195 215
196 /* iterate to the next PMP link */ 216 /* we were over a PMP link */
197 if (++link < ap->pmp_link + ap->nr_pmp_links) 217 if (++link < ap->pmp_link + ap->nr_pmp_links)
198 return link; 218 return link;
219
220 if (mode == ATA_LITER_PMP_FIRST)
221 return &ap->link;
222
199 return NULL; 223 return NULL;
200} 224}
201 225
202/** 226/**
227 * ata_dev_next - device iteration helper
228 * @dev: the previous device, NULL to start
229 * @link: ATA link containing devices to iterate
230 * @mode: iteration mode, one of ATA_DITER_*
231 *
232 * LOCKING:
233 * Host lock or EH context.
234 *
235 * RETURNS:
236 * Pointer to the next device.
237 */
238struct ata_device *ata_dev_next(struct ata_device *dev, struct ata_link *link,
239 enum ata_dev_iter_mode mode)
240{
241 BUG_ON(mode != ATA_DITER_ENABLED && mode != ATA_DITER_ENABLED_REVERSE &&
242 mode != ATA_DITER_ALL && mode != ATA_DITER_ALL_REVERSE);
243
244 /* NULL dev indicates start of iteration */
245 if (!dev)
246 switch (mode) {
247 case ATA_DITER_ENABLED:
248 case ATA_DITER_ALL:
249 dev = link->device;
250 goto check;
251 case ATA_DITER_ENABLED_REVERSE:
252 case ATA_DITER_ALL_REVERSE:
253 dev = link->device + ata_link_max_devices(link) - 1;
254 goto check;
255 }
256
257 next:
258 /* move to the next one */
259 switch (mode) {
260 case ATA_DITER_ENABLED:
261 case ATA_DITER_ALL:
262 if (++dev < link->device + ata_link_max_devices(link))
263 goto check;
264 return NULL;
265 case ATA_DITER_ENABLED_REVERSE:
266 case ATA_DITER_ALL_REVERSE:
267 if (--dev >= link->device)
268 goto check;
269 return NULL;
270 }
271
272 check:
273 if ((mode == ATA_DITER_ENABLED || mode == ATA_DITER_ENABLED_REVERSE) &&
274 !ata_dev_enabled(dev))
275 goto next;
276 return dev;
277}
278
279/**
203 * ata_dev_phys_link - find physical link for a device 280 * ata_dev_phys_link - find physical link for a device
204 * @dev: ATA device to look up physical link for 281 * @dev: ATA device to look up physical link for
205 * 282 *
@@ -930,6 +1007,7 @@ static const char *sata_spd_string(unsigned int spd)
930 static const char * const spd_str[] = { 1007 static const char * const spd_str[] = {
931 "1.5 Gbps", 1008 "1.5 Gbps",
932 "3.0 Gbps", 1009 "3.0 Gbps",
1010 "6.0 Gbps",
933 }; 1011 };
934 1012
935 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str)) 1013 if (spd == 0 || (spd - 1) >= ARRAY_SIZE(spd_str))
@@ -1107,8 +1185,8 @@ static void ata_lpm_enable(struct ata_host *host)
1107 1185
1108 for (i = 0; i < host->n_ports; i++) { 1186 for (i = 0; i < host->n_ports; i++) {
1109 ap = host->ports[i]; 1187 ap = host->ports[i];
1110 ata_port_for_each_link(link, ap) { 1188 ata_for_each_link(link, ap, EDGE) {
1111 ata_link_for_each_dev(dev, link) 1189 ata_for_each_dev(dev, link, ALL)
1112 ata_dev_disable_pm(dev); 1190 ata_dev_disable_pm(dev);
1113 } 1191 }
1114 } 1192 }
@@ -1923,6 +2001,10 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1923 as the caller should know this */ 2001 as the caller should know this */
1924 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY) 2002 if (adev->link->ap->flags & ATA_FLAG_NO_IORDY)
1925 return 0; 2003 return 0;
2004 /* CF spec. r4.1 Table 22 says no iordy on PIO5 and PIO6. */
2005 if (ata_id_is_cfa(adev->id)
2006 && (adev->pio_mode == XFER_PIO_5 || adev->pio_mode == XFER_PIO_6))
2007 return 0;
1926 /* PIO3 and higher it is mandatory */ 2008 /* PIO3 and higher it is mandatory */
1927 if (adev->pio_mode > XFER_PIO_2) 2009 if (adev->pio_mode > XFER_PIO_2)
1928 return 1; 2010 return 1;
@@ -2594,11 +2676,11 @@ int ata_bus_probe(struct ata_port *ap)
2594 2676
2595 ata_port_probe(ap); 2677 ata_port_probe(ap);
2596 2678
2597 ata_link_for_each_dev(dev, &ap->link) 2679 ata_for_each_dev(dev, &ap->link, ALL)
2598 tries[dev->devno] = ATA_PROBE_MAX_TRIES; 2680 tries[dev->devno] = ATA_PROBE_MAX_TRIES;
2599 2681
2600 retry: 2682 retry:
2601 ata_link_for_each_dev(dev, &ap->link) { 2683 ata_for_each_dev(dev, &ap->link, ALL) {
2602 /* If we issue an SRST then an ATA drive (not ATAPI) 2684 /* If we issue an SRST then an ATA drive (not ATAPI)
2603 * may change configuration and be in PIO0 timing. If 2685 * may change configuration and be in PIO0 timing. If
2604 * we do a hard reset (or are coming from power on) 2686 * we do a hard reset (or are coming from power on)
@@ -2620,7 +2702,7 @@ int ata_bus_probe(struct ata_port *ap)
2620 /* reset and determine device classes */ 2702 /* reset and determine device classes */
2621 ap->ops->phy_reset(ap); 2703 ap->ops->phy_reset(ap);
2622 2704
2623 ata_link_for_each_dev(dev, &ap->link) { 2705 ata_for_each_dev(dev, &ap->link, ALL) {
2624 if (!(ap->flags & ATA_FLAG_DISABLED) && 2706 if (!(ap->flags & ATA_FLAG_DISABLED) &&
2625 dev->class != ATA_DEV_UNKNOWN) 2707 dev->class != ATA_DEV_UNKNOWN)
2626 classes[dev->devno] = dev->class; 2708 classes[dev->devno] = dev->class;
@@ -2636,7 +2718,7 @@ int ata_bus_probe(struct ata_port *ap)
2636 specific sequence bass-ackwards so that PDIAG- is released by 2718 specific sequence bass-ackwards so that PDIAG- is released by
2637 the slave device */ 2719 the slave device */
2638 2720
2639 ata_link_for_each_dev_reverse(dev, &ap->link) { 2721 ata_for_each_dev(dev, &ap->link, ALL_REVERSE) {
2640 if (tries[dev->devno]) 2722 if (tries[dev->devno])
2641 dev->class = classes[dev->devno]; 2723 dev->class = classes[dev->devno];
2642 2724
@@ -2653,24 +2735,19 @@ int ata_bus_probe(struct ata_port *ap)
2653 if (ap->ops->cable_detect) 2735 if (ap->ops->cable_detect)
2654 ap->cbl = ap->ops->cable_detect(ap); 2736 ap->cbl = ap->ops->cable_detect(ap);
2655 2737
2656 /* We may have SATA bridge glue hiding here irrespective of the 2738 /* We may have SATA bridge glue hiding here irrespective of
2657 reported cable types and sensed types */ 2739 * the reported cable types and sensed types. When SATA
2658 ata_link_for_each_dev(dev, &ap->link) { 2740 * drives indicate we have a bridge, we don't know which end
2659 if (!ata_dev_enabled(dev)) 2741 * of the link the bridge is which is a problem.
2660 continue; 2742 */
2661 /* SATA drives indicate we have a bridge. We don't know which 2743 ata_for_each_dev(dev, &ap->link, ENABLED)
2662 end of the link the bridge is which is a problem */
2663 if (ata_id_is_sata(dev->id)) 2744 if (ata_id_is_sata(dev->id))
2664 ap->cbl = ATA_CBL_SATA; 2745 ap->cbl = ATA_CBL_SATA;
2665 }
2666 2746
2667 /* After the identify sequence we can now set up the devices. We do 2747 /* After the identify sequence we can now set up the devices. We do
2668 this in the normal order so that the user doesn't get confused */ 2748 this in the normal order so that the user doesn't get confused */
2669 2749
2670 ata_link_for_each_dev(dev, &ap->link) { 2750 ata_for_each_dev(dev, &ap->link, ENABLED) {
2671 if (!ata_dev_enabled(dev))
2672 continue;
2673
2674 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO; 2751 ap->link.eh_context.i.flags |= ATA_EHI_PRINTINFO;
2675 rc = ata_dev_configure(dev); 2752 rc = ata_dev_configure(dev);
2676 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO; 2753 ap->link.eh_context.i.flags &= ~ATA_EHI_PRINTINFO;
@@ -2683,9 +2760,8 @@ int ata_bus_probe(struct ata_port *ap)
2683 if (rc) 2760 if (rc)
2684 goto fail; 2761 goto fail;
2685 2762
2686 ata_link_for_each_dev(dev, &ap->link) 2763 ata_for_each_dev(dev, &ap->link, ENABLED)
2687 if (ata_dev_enabled(dev)) 2764 return 0;
2688 return 0;
2689 2765
2690 /* no device present, disable port */ 2766 /* no device present, disable port */
2691 ata_port_disable(ap); 2767 ata_port_disable(ap);
@@ -3331,13 +3407,10 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3331 int rc = 0, used_dma = 0, found = 0; 3407 int rc = 0, used_dma = 0, found = 0;
3332 3408
3333 /* step 1: calculate xfer_mask */ 3409 /* step 1: calculate xfer_mask */
3334 ata_link_for_each_dev(dev, link) { 3410 ata_for_each_dev(dev, link, ENABLED) {
3335 unsigned long pio_mask, dma_mask; 3411 unsigned long pio_mask, dma_mask;
3336 unsigned int mode_mask; 3412 unsigned int mode_mask;
3337 3413
3338 if (!ata_dev_enabled(dev))
3339 continue;
3340
3341 mode_mask = ATA_DMA_MASK_ATA; 3414 mode_mask = ATA_DMA_MASK_ATA;
3342 if (dev->class == ATA_DEV_ATAPI) 3415 if (dev->class == ATA_DEV_ATAPI)
3343 mode_mask = ATA_DMA_MASK_ATAPI; 3416 mode_mask = ATA_DMA_MASK_ATAPI;
@@ -3366,10 +3439,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3366 goto out; 3439 goto out;
3367 3440
3368 /* step 2: always set host PIO timings */ 3441 /* step 2: always set host PIO timings */
3369 ata_link_for_each_dev(dev, link) { 3442 ata_for_each_dev(dev, link, ENABLED) {
3370 if (!ata_dev_enabled(dev))
3371 continue;
3372
3373 if (dev->pio_mode == 0xff) { 3443 if (dev->pio_mode == 0xff) {
3374 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n"); 3444 ata_dev_printk(dev, KERN_WARNING, "no PIO support\n");
3375 rc = -EINVAL; 3445 rc = -EINVAL;
@@ -3383,8 +3453,8 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3383 } 3453 }
3384 3454
3385 /* step 3: set host DMA timings */ 3455 /* step 3: set host DMA timings */
3386 ata_link_for_each_dev(dev, link) { 3456 ata_for_each_dev(dev, link, ENABLED) {
3387 if (!ata_dev_enabled(dev) || !ata_dma_enabled(dev)) 3457 if (!ata_dma_enabled(dev))
3388 continue; 3458 continue;
3389 3459
3390 dev->xfer_mode = dev->dma_mode; 3460 dev->xfer_mode = dev->dma_mode;
@@ -3394,11 +3464,7 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
3394 } 3464 }
3395 3465
3396 /* step 4: update devices' xfer mode */ 3466 /* step 4: update devices' xfer mode */
3397 ata_link_for_each_dev(dev, link) { 3467 ata_for_each_dev(dev, link, ENABLED) {
3398 /* don't update suspended devices' xfer mode */
3399 if (!ata_dev_enabled(dev))
3400 continue;
3401
3402 rc = ata_dev_set_mode(dev); 3468 rc = ata_dev_set_mode(dev);
3403 if (rc) 3469 if (rc)
3404 goto out; 3470 goto out;
@@ -4048,6 +4114,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
4048 { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ }, 4114 { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ },
4049 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ }, 4115 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ },
4050 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ }, 4116 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ },
4117 { "OCZ CORE_SSD", "02.10104", ATA_HORKAGE_NONCQ },
4051 4118
4052 /* Seagate NCQ + FLUSH CACHE firmware bug */ 4119 /* Seagate NCQ + FLUSH CACHE firmware bug */
4053 { "ST31500341AS", "SD15", ATA_HORKAGE_NONCQ | 4120 { "ST31500341AS", "SD15", ATA_HORKAGE_NONCQ |
@@ -4263,9 +4330,9 @@ static int cable_is_40wire(struct ata_port *ap)
4263 * - if you have a non detect capable drive you don't want it 4330 * - if you have a non detect capable drive you don't want it
4264 * to colour the choice 4331 * to colour the choice
4265 */ 4332 */
4266 ata_port_for_each_link(link, ap) { 4333 ata_for_each_link(link, ap, EDGE) {
4267 ata_link_for_each_dev(dev, link) { 4334 ata_for_each_dev(dev, link, ENABLED) {
4268 if (ata_dev_enabled(dev) && !ata_is_40wire(dev)) 4335 if (!ata_is_40wire(dev))
4269 return 0; 4336 return 0;
4270 } 4337 }
4271 } 4338 }
@@ -4672,7 +4739,6 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)
4672/** 4739/**
4673 * ata_qc_new_init - Request an available ATA command, and initialize it 4740 * ata_qc_new_init - Request an available ATA command, and initialize it
4674 * @dev: Device from whom we request an available command structure 4741 * @dev: Device from whom we request an available command structure
4675 * @tag: command tag
4676 * 4742 *
4677 * LOCKING: 4743 * LOCKING:
4678 * None. 4744 * None.
@@ -5218,7 +5284,7 @@ static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
5218 } 5284 }
5219 5285
5220 ap->pflags |= ATA_PFLAG_PM_PENDING; 5286 ap->pflags |= ATA_PFLAG_PM_PENDING;
5221 __ata_port_for_each_link(link, ap) { 5287 ata_for_each_link(link, ap, HOST_FIRST) {
5222 link->eh_info.action |= action; 5288 link->eh_info.action |= action;
5223 link->eh_info.flags |= ehi_flags; 5289 link->eh_info.flags |= ehi_flags;
5224 } 5290 }
@@ -5849,6 +5915,54 @@ void ata_host_init(struct ata_host *host, struct device *dev,
5849 host->ops = ops; 5915 host->ops = ops;
5850} 5916}
5851 5917
5918
5919static void async_port_probe(void *data, async_cookie_t cookie)
5920{
5921 int rc;
5922 struct ata_port *ap = data;
5923 /* probe */
5924 if (ap->ops->error_handler) {
5925 struct ata_eh_info *ehi = &ap->link.eh_info;
5926 unsigned long flags;
5927
5928 ata_port_probe(ap);
5929
5930 /* kick EH for boot probing */
5931 spin_lock_irqsave(ap->lock, flags);
5932
5933 ehi->probe_mask |= ATA_ALL_DEVICES;
5934 ehi->action |= ATA_EH_RESET | ATA_EH_LPM;
5935 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
5936
5937 ap->pflags &= ~ATA_PFLAG_INITIALIZING;
5938 ap->pflags |= ATA_PFLAG_LOADING;
5939 ata_port_schedule_eh(ap);
5940
5941 spin_unlock_irqrestore(ap->lock, flags);
5942
5943 /* wait for EH to finish */
5944 ata_port_wait_eh(ap);
5945 } else {
5946 DPRINTK("ata%u: bus probe begin\n", ap->print_id);
5947 rc = ata_bus_probe(ap);
5948 DPRINTK("ata%u: bus probe end\n", ap->print_id);
5949
5950 if (rc) {
5951 /* FIXME: do something useful here?
5952 * Current libata behavior will
5953 * tear down everything when
5954 * the module is removed
5955 * or the h/w is unplugged.
5956 */
5957 }
5958 }
5959
5960 /* in order to keep device order, we need to synchronize at this point */
5961 async_synchronize_cookie(cookie);
5962
5963 ata_scsi_scan_host(ap, 1);
5964
5965}
5852/** 5966/**
5853 * ata_host_register - register initialized ATA host 5967 * ata_host_register - register initialized ATA host
5854 * @host: ATA host to register 5968 * @host: ATA host to register
@@ -5928,52 +6042,9 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
5928 DPRINTK("probe begin\n"); 6042 DPRINTK("probe begin\n");
5929 for (i = 0; i < host->n_ports; i++) { 6043 for (i = 0; i < host->n_ports; i++) {
5930 struct ata_port *ap = host->ports[i]; 6044 struct ata_port *ap = host->ports[i];
5931 6045 async_schedule(async_port_probe, ap);
5932 /* probe */
5933 if (ap->ops->error_handler) {
5934 struct ata_eh_info *ehi = &ap->link.eh_info;
5935 unsigned long flags;
5936
5937 ata_port_probe(ap);
5938
5939 /* kick EH for boot probing */
5940 spin_lock_irqsave(ap->lock, flags);
5941
5942 ehi->probe_mask |= ATA_ALL_DEVICES;
5943 ehi->action |= ATA_EH_RESET | ATA_EH_LPM;
5944 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
5945
5946 ap->pflags &= ~ATA_PFLAG_INITIALIZING;
5947 ap->pflags |= ATA_PFLAG_LOADING;
5948 ata_port_schedule_eh(ap);
5949
5950 spin_unlock_irqrestore(ap->lock, flags);
5951
5952 /* wait for EH to finish */
5953 ata_port_wait_eh(ap);
5954 } else {
5955 DPRINTK("ata%u: bus probe begin\n", ap->print_id);
5956 rc = ata_bus_probe(ap);
5957 DPRINTK("ata%u: bus probe end\n", ap->print_id);
5958
5959 if (rc) {
5960 /* FIXME: do something useful here?
5961 * Current libata behavior will
5962 * tear down everything when
5963 * the module is removed
5964 * or the h/w is unplugged.
5965 */
5966 }
5967 }
5968 }
5969
5970 /* probes are done, now scan each port's disk(s) */
5971 DPRINTK("host probe begin\n");
5972 for (i = 0; i < host->n_ports; i++) {
5973 struct ata_port *ap = host->ports[i];
5974
5975 ata_scsi_scan_host(ap, 1);
5976 } 6046 }
6047 DPRINTK("probe end\n");
5977 6048
5978 return 0; 6049 return 0;
5979} 6050}
@@ -6047,8 +6118,6 @@ int ata_host_activate(struct ata_host *host, int irq,
6047static void ata_port_detach(struct ata_port *ap) 6118static void ata_port_detach(struct ata_port *ap)
6048{ 6119{
6049 unsigned long flags; 6120 unsigned long flags;
6050 struct ata_link *link;
6051 struct ata_device *dev;
6052 6121
6053 if (!ap->ops->error_handler) 6122 if (!ap->ops->error_handler)
6054 goto skip_eh; 6123 goto skip_eh;
@@ -6056,28 +6125,15 @@ static void ata_port_detach(struct ata_port *ap)
6056 /* tell EH we're leaving & flush EH */ 6125 /* tell EH we're leaving & flush EH */
6057 spin_lock_irqsave(ap->lock, flags); 6126 spin_lock_irqsave(ap->lock, flags);
6058 ap->pflags |= ATA_PFLAG_UNLOADING; 6127 ap->pflags |= ATA_PFLAG_UNLOADING;
6128 ata_port_schedule_eh(ap);
6059 spin_unlock_irqrestore(ap->lock, flags); 6129 spin_unlock_irqrestore(ap->lock, flags);
6060 6130
6131 /* wait till EH commits suicide */
6061 ata_port_wait_eh(ap); 6132 ata_port_wait_eh(ap);
6062 6133
6063 /* EH is now guaranteed to see UNLOADING - EH context belongs 6134 /* it better be dead now */
6064 * to us. Restore SControl and disable all existing devices. 6135 WARN_ON(!(ap->pflags & ATA_PFLAG_UNLOADED));
6065 */
6066 __ata_port_for_each_link(link, ap) {
6067 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
6068 ata_link_for_each_dev(dev, link)
6069 ata_dev_disable(dev);
6070 }
6071
6072 /* Final freeze & EH. All in-flight commands are aborted. EH
6073 * will be skipped and retrials will be terminated with bad
6074 * target.
6075 */
6076 spin_lock_irqsave(ap->lock, flags);
6077 ata_port_freeze(ap); /* won't be thawed */
6078 spin_unlock_irqrestore(ap->lock, flags);
6079 6136
6080 ata_port_wait_eh(ap);
6081 cancel_rearming_delayed_work(&ap->hotplug_task); 6137 cancel_rearming_delayed_work(&ap->hotplug_task);
6082 6138
6083 skip_eh: 6139 skip_eh:
@@ -6528,7 +6584,8 @@ EXPORT_SYMBOL_GPL(ata_base_port_ops);
6528EXPORT_SYMBOL_GPL(sata_port_ops); 6584EXPORT_SYMBOL_GPL(sata_port_ops);
6529EXPORT_SYMBOL_GPL(ata_dummy_port_ops); 6585EXPORT_SYMBOL_GPL(ata_dummy_port_ops);
6530EXPORT_SYMBOL_GPL(ata_dummy_port_info); 6586EXPORT_SYMBOL_GPL(ata_dummy_port_info);
6531EXPORT_SYMBOL_GPL(__ata_port_next_link); 6587EXPORT_SYMBOL_GPL(ata_link_next);
6588EXPORT_SYMBOL_GPL(ata_dev_next);
6532EXPORT_SYMBOL_GPL(ata_std_bios_param); 6589EXPORT_SYMBOL_GPL(ata_std_bios_param);
6533EXPORT_SYMBOL_GPL(ata_host_init); 6590EXPORT_SYMBOL_GPL(ata_host_init);
6534EXPORT_SYMBOL_GPL(ata_host_alloc); 6591EXPORT_SYMBOL_GPL(ata_host_alloc);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 32da9a93ce44..8147a8386370 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -422,7 +422,7 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
422 422
423 if (!dev) { 423 if (!dev) {
424 ehi->action &= ~action; 424 ehi->action &= ~action;
425 ata_link_for_each_dev(tdev, link) 425 ata_for_each_dev(tdev, link, ALL)
426 ehi->dev_action[tdev->devno] &= ~action; 426 ehi->dev_action[tdev->devno] &= ~action;
427 } else { 427 } else {
428 /* doesn't make sense for port-wide EH actions */ 428 /* doesn't make sense for port-wide EH actions */
@@ -430,7 +430,7 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
430 430
431 /* break ehi->action into ehi->dev_action */ 431 /* break ehi->action into ehi->dev_action */
432 if (ehi->action & action) { 432 if (ehi->action & action) {
433 ata_link_for_each_dev(tdev, link) 433 ata_for_each_dev(tdev, link, ALL)
434 ehi->dev_action[tdev->devno] |= 434 ehi->dev_action[tdev->devno] |=
435 ehi->action & action; 435 ehi->action & action;
436 ehi->action &= ~action; 436 ehi->action &= ~action;
@@ -491,6 +491,31 @@ enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
491 return ret; 491 return ret;
492} 492}
493 493
494static void ata_eh_unload(struct ata_port *ap)
495{
496 struct ata_link *link;
497 struct ata_device *dev;
498 unsigned long flags;
499
500 /* Restore SControl IPM and SPD for the next driver and
501 * disable attached devices.
502 */
503 ata_for_each_link(link, ap, PMP_FIRST) {
504 sata_scr_write(link, SCR_CONTROL, link->saved_scontrol & 0xff0);
505 ata_for_each_dev(dev, link, ALL)
506 ata_dev_disable(dev);
507 }
508
509 /* freeze and set UNLOADED */
510 spin_lock_irqsave(ap->lock, flags);
511
512 ata_port_freeze(ap); /* won't be thawed */
513 ap->pflags &= ~ATA_PFLAG_EH_PENDING; /* clear pending from freeze */
514 ap->pflags |= ATA_PFLAG_UNLOADED;
515
516 spin_unlock_irqrestore(ap->lock, flags);
517}
518
494/** 519/**
495 * ata_scsi_error - SCSI layer error handler callback 520 * ata_scsi_error - SCSI layer error handler callback
496 * @host: SCSI host on which error occurred 521 * @host: SCSI host on which error occurred
@@ -592,7 +617,7 @@ void ata_scsi_error(struct Scsi_Host *host)
592 /* fetch & clear EH info */ 617 /* fetch & clear EH info */
593 spin_lock_irqsave(ap->lock, flags); 618 spin_lock_irqsave(ap->lock, flags);
594 619
595 __ata_port_for_each_link(link, ap) { 620 ata_for_each_link(link, ap, HOST_FIRST) {
596 struct ata_eh_context *ehc = &link->eh_context; 621 struct ata_eh_context *ehc = &link->eh_context;
597 struct ata_device *dev; 622 struct ata_device *dev;
598 623
@@ -600,12 +625,9 @@ void ata_scsi_error(struct Scsi_Host *host)
600 link->eh_context.i = link->eh_info; 625 link->eh_context.i = link->eh_info;
601 memset(&link->eh_info, 0, sizeof(link->eh_info)); 626 memset(&link->eh_info, 0, sizeof(link->eh_info));
602 627
603 ata_link_for_each_dev(dev, link) { 628 ata_for_each_dev(dev, link, ENABLED) {
604 int devno = dev->devno; 629 int devno = dev->devno;
605 630
606 if (!ata_dev_enabled(dev))
607 continue;
608
609 ehc->saved_xfer_mode[devno] = dev->xfer_mode; 631 ehc->saved_xfer_mode[devno] = dev->xfer_mode;
610 if (ata_ncq_enabled(dev)) 632 if (ata_ncq_enabled(dev))
611 ehc->saved_ncq_enabled |= 1 << devno; 633 ehc->saved_ncq_enabled |= 1 << devno;
@@ -621,8 +643,13 @@ void ata_scsi_error(struct Scsi_Host *host)
621 /* invoke EH, skip if unloading or suspended */ 643 /* invoke EH, skip if unloading or suspended */
622 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED))) 644 if (!(ap->pflags & (ATA_PFLAG_UNLOADING | ATA_PFLAG_SUSPENDED)))
623 ap->ops->error_handler(ap); 645 ap->ops->error_handler(ap);
624 else 646 else {
647 /* if unloading, commence suicide */
648 if ((ap->pflags & ATA_PFLAG_UNLOADING) &&
649 !(ap->pflags & ATA_PFLAG_UNLOADED))
650 ata_eh_unload(ap);
625 ata_eh_finish(ap); 651 ata_eh_finish(ap);
652 }
626 653
627 /* process port suspend request */ 654 /* process port suspend request */
628 ata_eh_handle_port_suspend(ap); 655 ata_eh_handle_port_suspend(ap);
@@ -644,7 +671,7 @@ void ata_scsi_error(struct Scsi_Host *host)
644 } 671 }
645 672
646 /* this run is complete, make sure EH info is clear */ 673 /* this run is complete, make sure EH info is clear */
647 __ata_port_for_each_link(link, ap) 674 ata_for_each_link(link, ap, HOST_FIRST)
648 memset(&link->eh_info, 0, sizeof(link->eh_info)); 675 memset(&link->eh_info, 0, sizeof(link->eh_info));
649 676
650 /* Clear host_eh_scheduled while holding ap->lock such 677 /* Clear host_eh_scheduled while holding ap->lock such
@@ -1025,7 +1052,7 @@ int sata_async_notification(struct ata_port *ap)
1025 struct ata_link *link; 1052 struct ata_link *link;
1026 1053
1027 /* check and notify ATAPI AN */ 1054 /* check and notify ATAPI AN */
1028 ata_port_for_each_link(link, ap) { 1055 ata_for_each_link(link, ap, EDGE) {
1029 if (!(sntf & (1 << link->pmp))) 1056 if (!(sntf & (1 << link->pmp)))
1030 continue; 1057 continue;
1031 1058
@@ -2005,7 +2032,7 @@ void ata_eh_autopsy(struct ata_port *ap)
2005{ 2032{
2006 struct ata_link *link; 2033 struct ata_link *link;
2007 2034
2008 ata_port_for_each_link(link, ap) 2035 ata_for_each_link(link, ap, EDGE)
2009 ata_eh_link_autopsy(link); 2036 ata_eh_link_autopsy(link);
2010 2037
2011 /* Handle the frigging slave link. Autopsy is done similarly 2038 /* Handle the frigging slave link. Autopsy is done similarly
@@ -2219,7 +2246,7 @@ void ata_eh_report(struct ata_port *ap)
2219{ 2246{
2220 struct ata_link *link; 2247 struct ata_link *link;
2221 2248
2222 __ata_port_for_each_link(link, ap) 2249 ata_for_each_link(link, ap, HOST_FIRST)
2223 ata_eh_link_report(link); 2250 ata_eh_link_report(link);
2224} 2251}
2225 2252
@@ -2230,7 +2257,7 @@ static int ata_do_reset(struct ata_link *link, ata_reset_fn_t reset,
2230 struct ata_device *dev; 2257 struct ata_device *dev;
2231 2258
2232 if (clear_classes) 2259 if (clear_classes)
2233 ata_link_for_each_dev(dev, link) 2260 ata_for_each_dev(dev, link, ALL)
2234 classes[dev->devno] = ATA_DEV_UNKNOWN; 2261 classes[dev->devno] = ATA_DEV_UNKNOWN;
2235 2262
2236 return reset(link, classes, deadline); 2263 return reset(link, classes, deadline);
@@ -2294,7 +2321,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2294 2321
2295 ata_eh_about_to_do(link, NULL, ATA_EH_RESET); 2322 ata_eh_about_to_do(link, NULL, ATA_EH_RESET);
2296 2323
2297 ata_link_for_each_dev(dev, link) { 2324 ata_for_each_dev(dev, link, ALL) {
2298 /* If we issue an SRST then an ATA drive (not ATAPI) 2325 /* If we issue an SRST then an ATA drive (not ATAPI)
2299 * may change configuration and be in PIO0 timing. If 2326 * may change configuration and be in PIO0 timing. If
2300 * we do a hard reset (or are coming from power on) 2327 * we do a hard reset (or are coming from power on)
@@ -2355,7 +2382,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2355 "port disabled. ignoring.\n"); 2382 "port disabled. ignoring.\n");
2356 ehc->i.action &= ~ATA_EH_RESET; 2383 ehc->i.action &= ~ATA_EH_RESET;
2357 2384
2358 ata_link_for_each_dev(dev, link) 2385 ata_for_each_dev(dev, link, ALL)
2359 classes[dev->devno] = ATA_DEV_NONE; 2386 classes[dev->devno] = ATA_DEV_NONE;
2360 2387
2361 rc = 0; 2388 rc = 0;
@@ -2369,7 +2396,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2369 * bang classes and return. 2396 * bang classes and return.
2370 */ 2397 */
2371 if (reset && !(ehc->i.action & ATA_EH_RESET)) { 2398 if (reset && !(ehc->i.action & ATA_EH_RESET)) {
2372 ata_link_for_each_dev(dev, link) 2399 ata_for_each_dev(dev, link, ALL)
2373 classes[dev->devno] = ATA_DEV_NONE; 2400 classes[dev->devno] = ATA_DEV_NONE;
2374 rc = 0; 2401 rc = 0;
2375 goto out; 2402 goto out;
@@ -2454,7 +2481,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2454 /* 2481 /*
2455 * Post-reset processing 2482 * Post-reset processing
2456 */ 2483 */
2457 ata_link_for_each_dev(dev, link) { 2484 ata_for_each_dev(dev, link, ALL) {
2458 /* After the reset, the device state is PIO 0 and the 2485 /* After the reset, the device state is PIO 0 and the
2459 * controller state is undefined. Reset also wakes up 2486 * controller state is undefined. Reset also wakes up
2460 * drives from sleeping mode. 2487 * drives from sleeping mode.
@@ -2510,7 +2537,7 @@ int ata_eh_reset(struct ata_link *link, int classify,
2510 * can be reliably detected and retried. 2537 * can be reliably detected and retried.
2511 */ 2538 */
2512 nr_unknown = 0; 2539 nr_unknown = 0;
2513 ata_link_for_each_dev(dev, link) { 2540 ata_for_each_dev(dev, link, ALL) {
2514 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */ 2541 /* convert all ATA_DEV_UNKNOWN to ATA_DEV_NONE */
2515 if (classes[dev->devno] == ATA_DEV_UNKNOWN) { 2542 if (classes[dev->devno] == ATA_DEV_UNKNOWN) {
2516 classes[dev->devno] = ATA_DEV_NONE; 2543 classes[dev->devno] = ATA_DEV_NONE;
@@ -2619,8 +2646,8 @@ static inline void ata_eh_pull_park_action(struct ata_port *ap)
2619 2646
2620 spin_lock_irqsave(ap->lock, flags); 2647 spin_lock_irqsave(ap->lock, flags);
2621 INIT_COMPLETION(ap->park_req_pending); 2648 INIT_COMPLETION(ap->park_req_pending);
2622 ata_port_for_each_link(link, ap) { 2649 ata_for_each_link(link, ap, EDGE) {
2623 ata_link_for_each_dev(dev, link) { 2650 ata_for_each_dev(dev, link, ALL) {
2624 struct ata_eh_info *ehi = &link->eh_info; 2651 struct ata_eh_info *ehi = &link->eh_info;
2625 2652
2626 link->eh_context.i.dev_action[dev->devno] |= 2653 link->eh_context.i.dev_action[dev->devno] |=
@@ -2675,7 +2702,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2675 * be done backwards such that PDIAG- is released by the slave 2702 * be done backwards such that PDIAG- is released by the slave
2676 * device before the master device is identified. 2703 * device before the master device is identified.
2677 */ 2704 */
2678 ata_link_for_each_dev_reverse(dev, link) { 2705 ata_for_each_dev(dev, link, ALL_REVERSE) {
2679 unsigned int action = ata_eh_dev_action(dev); 2706 unsigned int action = ata_eh_dev_action(dev);
2680 unsigned int readid_flags = 0; 2707 unsigned int readid_flags = 0;
2681 2708
@@ -2744,7 +2771,7 @@ static int ata_eh_revalidate_and_attach(struct ata_link *link,
2744 /* Configure new devices forward such that user doesn't see 2771 /* Configure new devices forward such that user doesn't see
2745 * device detection messages backwards. 2772 * device detection messages backwards.
2746 */ 2773 */
2747 ata_link_for_each_dev(dev, link) { 2774 ata_for_each_dev(dev, link, ALL) {
2748 if (!(new_mask & (1 << dev->devno)) || 2775 if (!(new_mask & (1 << dev->devno)) ||
2749 dev->class == ATA_DEV_PMP) 2776 dev->class == ATA_DEV_PMP)
2750 continue; 2777 continue;
@@ -2793,10 +2820,7 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2793 int rc; 2820 int rc;
2794 2821
2795 /* if data transfer is verified, clear DUBIOUS_XFER on ering top */ 2822 /* if data transfer is verified, clear DUBIOUS_XFER on ering top */
2796 ata_link_for_each_dev(dev, link) { 2823 ata_for_each_dev(dev, link, ENABLED) {
2797 if (!ata_dev_enabled(dev))
2798 continue;
2799
2800 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) { 2824 if (!(dev->flags & ATA_DFLAG_DUBIOUS_XFER)) {
2801 struct ata_ering_entry *ent; 2825 struct ata_ering_entry *ent;
2802 2826
@@ -2813,14 +2837,11 @@ int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
2813 rc = ata_do_set_mode(link, r_failed_dev); 2837 rc = ata_do_set_mode(link, r_failed_dev);
2814 2838
2815 /* if transfer mode has changed, set DUBIOUS_XFER on device */ 2839 /* if transfer mode has changed, set DUBIOUS_XFER on device */
2816 ata_link_for_each_dev(dev, link) { 2840 ata_for_each_dev(dev, link, ENABLED) {
2817 struct ata_eh_context *ehc = &link->eh_context; 2841 struct ata_eh_context *ehc = &link->eh_context;
2818 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno]; 2842 u8 saved_xfer_mode = ehc->saved_xfer_mode[dev->devno];
2819 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno)); 2843 u8 saved_ncq = !!(ehc->saved_ncq_enabled & (1 << dev->devno));
2820 2844
2821 if (!ata_dev_enabled(dev))
2822 continue;
2823
2824 if (dev->xfer_mode != saved_xfer_mode || 2845 if (dev->xfer_mode != saved_xfer_mode ||
2825 ata_ncq_enabled(dev) != saved_ncq) 2846 ata_ncq_enabled(dev) != saved_ncq)
2826 dev->flags |= ATA_DFLAG_DUBIOUS_XFER; 2847 dev->flags |= ATA_DFLAG_DUBIOUS_XFER;
@@ -2881,9 +2902,8 @@ static int ata_link_nr_enabled(struct ata_link *link)
2881 struct ata_device *dev; 2902 struct ata_device *dev;
2882 int cnt = 0; 2903 int cnt = 0;
2883 2904
2884 ata_link_for_each_dev(dev, link) 2905 ata_for_each_dev(dev, link, ENABLED)
2885 if (ata_dev_enabled(dev)) 2906 cnt++;
2886 cnt++;
2887 return cnt; 2907 return cnt;
2888} 2908}
2889 2909
@@ -2892,7 +2912,7 @@ static int ata_link_nr_vacant(struct ata_link *link)
2892 struct ata_device *dev; 2912 struct ata_device *dev;
2893 int cnt = 0; 2913 int cnt = 0;
2894 2914
2895 ata_link_for_each_dev(dev, link) 2915 ata_for_each_dev(dev, link, ALL)
2896 if (dev->class == ATA_DEV_UNKNOWN) 2916 if (dev->class == ATA_DEV_UNKNOWN)
2897 cnt++; 2917 cnt++;
2898 return cnt; 2918 return cnt;
@@ -2918,7 +2938,7 @@ static int ata_eh_skip_recovery(struct ata_link *link)
2918 return 0; 2938 return 0;
2919 2939
2920 /* skip if class codes for all vacant slots are ATA_DEV_NONE */ 2940 /* skip if class codes for all vacant slots are ATA_DEV_NONE */
2921 ata_link_for_each_dev(dev, link) { 2941 ata_for_each_dev(dev, link, ALL) {
2922 if (dev->class == ATA_DEV_UNKNOWN && 2942 if (dev->class == ATA_DEV_UNKNOWN &&
2923 ehc->classes[dev->devno] != ATA_DEV_NONE) 2943 ehc->classes[dev->devno] != ATA_DEV_NONE)
2924 return 0; 2944 return 0;
@@ -3026,7 +3046,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3026 DPRINTK("ENTER\n"); 3046 DPRINTK("ENTER\n");
3027 3047
3028 /* prep for recovery */ 3048 /* prep for recovery */
3029 ata_port_for_each_link(link, ap) { 3049 ata_for_each_link(link, ap, EDGE) {
3030 struct ata_eh_context *ehc = &link->eh_context; 3050 struct ata_eh_context *ehc = &link->eh_context;
3031 3051
3032 /* re-enable link? */ 3052 /* re-enable link? */
@@ -3038,7 +3058,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3038 ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK); 3058 ata_eh_done(link, NULL, ATA_EH_ENABLE_LINK);
3039 } 3059 }
3040 3060
3041 ata_link_for_each_dev(dev, link) { 3061 ata_for_each_dev(dev, link, ALL) {
3042 if (link->flags & ATA_LFLAG_NO_RETRY) 3062 if (link->flags & ATA_LFLAG_NO_RETRY)
3043 ehc->tries[dev->devno] = 1; 3063 ehc->tries[dev->devno] = 1;
3044 else 3064 else
@@ -3068,19 +3088,19 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3068 goto out; 3088 goto out;
3069 3089
3070 /* prep for EH */ 3090 /* prep for EH */
3071 ata_port_for_each_link(link, ap) { 3091 ata_for_each_link(link, ap, EDGE) {
3072 struct ata_eh_context *ehc = &link->eh_context; 3092 struct ata_eh_context *ehc = &link->eh_context;
3073 3093
3074 /* skip EH if possible. */ 3094 /* skip EH if possible. */
3075 if (ata_eh_skip_recovery(link)) 3095 if (ata_eh_skip_recovery(link))
3076 ehc->i.action = 0; 3096 ehc->i.action = 0;
3077 3097
3078 ata_link_for_each_dev(dev, link) 3098 ata_for_each_dev(dev, link, ALL)
3079 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN; 3099 ehc->classes[dev->devno] = ATA_DEV_UNKNOWN;
3080 } 3100 }
3081 3101
3082 /* reset */ 3102 /* reset */
3083 ata_port_for_each_link(link, ap) { 3103 ata_for_each_link(link, ap, EDGE) {
3084 struct ata_eh_context *ehc = &link->eh_context; 3104 struct ata_eh_context *ehc = &link->eh_context;
3085 3105
3086 if (!(ehc->i.action & ATA_EH_RESET)) 3106 if (!(ehc->i.action & ATA_EH_RESET))
@@ -3105,8 +3125,8 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3105 ata_eh_pull_park_action(ap); 3125 ata_eh_pull_park_action(ap);
3106 3126
3107 deadline = jiffies; 3127 deadline = jiffies;
3108 ata_port_for_each_link(link, ap) { 3128 ata_for_each_link(link, ap, EDGE) {
3109 ata_link_for_each_dev(dev, link) { 3129 ata_for_each_dev(dev, link, ALL) {
3110 struct ata_eh_context *ehc = &link->eh_context; 3130 struct ata_eh_context *ehc = &link->eh_context;
3111 unsigned long tmp; 3131 unsigned long tmp;
3112 3132
@@ -3134,8 +3154,8 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3134 deadline = wait_for_completion_timeout(&ap->park_req_pending, 3154 deadline = wait_for_completion_timeout(&ap->park_req_pending,
3135 deadline - now); 3155 deadline - now);
3136 } while (deadline); 3156 } while (deadline);
3137 ata_port_for_each_link(link, ap) { 3157 ata_for_each_link(link, ap, EDGE) {
3138 ata_link_for_each_dev(dev, link) { 3158 ata_for_each_dev(dev, link, ALL) {
3139 if (!(link->eh_context.unloaded_mask & 3159 if (!(link->eh_context.unloaded_mask &
3140 (1 << dev->devno))) 3160 (1 << dev->devno)))
3141 continue; 3161 continue;
@@ -3146,7 +3166,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3146 } 3166 }
3147 3167
3148 /* the rest */ 3168 /* the rest */
3149 ata_port_for_each_link(link, ap) { 3169 ata_for_each_link(link, ap, EDGE) {
3150 struct ata_eh_context *ehc = &link->eh_context; 3170 struct ata_eh_context *ehc = &link->eh_context;
3151 3171
3152 /* revalidate existing devices and attach new ones */ 3172 /* revalidate existing devices and attach new ones */
@@ -3172,7 +3192,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3172 * disrupting the current users of the device. 3192 * disrupting the current users of the device.
3173 */ 3193 */
3174 if (ehc->i.flags & ATA_EHI_DID_RESET) { 3194 if (ehc->i.flags & ATA_EHI_DID_RESET) {
3175 ata_link_for_each_dev(dev, link) { 3195 ata_for_each_dev(dev, link, ALL) {
3176 if (dev->class != ATA_DEV_ATAPI) 3196 if (dev->class != ATA_DEV_ATAPI)
3177 continue; 3197 continue;
3178 rc = atapi_eh_clear_ua(dev); 3198 rc = atapi_eh_clear_ua(dev);
@@ -3183,7 +3203,7 @@ int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
3183 3203
3184 /* configure link power saving */ 3204 /* configure link power saving */
3185 if (ehc->i.action & ATA_EH_LPM) 3205 if (ehc->i.action & ATA_EH_LPM)
3186 ata_link_for_each_dev(dev, link) 3206 ata_for_each_dev(dev, link, ALL)
3187 ata_dev_enable_pm(dev, ap->pm_policy); 3207 ata_dev_enable_pm(dev, ap->pm_policy);
3188 3208
3189 /* this link is okay now */ 3209 /* this link is okay now */
@@ -3288,7 +3308,7 @@ void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
3288 rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset, 3308 rc = ata_eh_recover(ap, prereset, softreset, hardreset, postreset,
3289 NULL); 3309 NULL);
3290 if (rc) { 3310 if (rc) {
3291 ata_link_for_each_dev(dev, &ap->link) 3311 ata_for_each_dev(dev, &ap->link, ALL)
3292 ata_dev_disable(dev); 3312 ata_dev_disable(dev);
3293 } 3313 }
3294 3314
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index b65db309c181..98ca07a2db87 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -321,7 +321,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
321 321
322 if (vendor == 0x1095 && devid == 0x3726) { 322 if (vendor == 0x1095 && devid == 0x3726) {
323 /* sil3726 quirks */ 323 /* sil3726 quirks */
324 ata_port_for_each_link(link, ap) { 324 ata_for_each_link(link, ap, EDGE) {
325 /* Class code report is unreliable and SRST 325 /* Class code report is unreliable and SRST
326 * times out under certain configurations. 326 * times out under certain configurations.
327 */ 327 */
@@ -336,7 +336,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
336 } 336 }
337 } else if (vendor == 0x1095 && devid == 0x4723) { 337 } else if (vendor == 0x1095 && devid == 0x4723) {
338 /* sil4723 quirks */ 338 /* sil4723 quirks */
339 ata_port_for_each_link(link, ap) { 339 ata_for_each_link(link, ap, EDGE) {
340 /* class code report is unreliable */ 340 /* class code report is unreliable */
341 if (link->pmp < 2) 341 if (link->pmp < 2)
342 link->flags |= ATA_LFLAG_ASSUME_ATA; 342 link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -348,7 +348,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
348 } 348 }
349 } else if (vendor == 0x1095 && devid == 0x4726) { 349 } else if (vendor == 0x1095 && devid == 0x4726) {
350 /* sil4726 quirks */ 350 /* sil4726 quirks */
351 ata_port_for_each_link(link, ap) { 351 ata_for_each_link(link, ap, EDGE) {
352 /* Class code report is unreliable and SRST 352 /* Class code report is unreliable and SRST
353 * times out under certain configurations. 353 * times out under certain configurations.
354 * Config device can be at port 0 or 5 and 354 * Config device can be at port 0 or 5 and
@@ -450,7 +450,7 @@ int sata_pmp_attach(struct ata_device *dev)
450 if (ap->ops->pmp_attach) 450 if (ap->ops->pmp_attach)
451 ap->ops->pmp_attach(ap); 451 ap->ops->pmp_attach(ap);
452 452
453 ata_port_for_each_link(tlink, ap) 453 ata_for_each_link(tlink, ap, EDGE)
454 sata_link_init_spd(tlink); 454 sata_link_init_spd(tlink);
455 455
456 ata_acpi_associate_sata_port(ap); 456 ata_acpi_associate_sata_port(ap);
@@ -487,7 +487,7 @@ static void sata_pmp_detach(struct ata_device *dev)
487 if (ap->ops->pmp_detach) 487 if (ap->ops->pmp_detach)
488 ap->ops->pmp_detach(ap); 488 ap->ops->pmp_detach(ap);
489 489
490 ata_port_for_each_link(tlink, ap) 490 ata_for_each_link(tlink, ap, EDGE)
491 ata_eh_detach_dev(tlink->device); 491 ata_eh_detach_dev(tlink->device);
492 492
493 spin_lock_irqsave(ap->lock, flags); 493 spin_lock_irqsave(ap->lock, flags);
@@ -700,7 +700,7 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
700 } 700 }
701 701
702 /* PMP is reset, SErrors cannot be trusted, scan all */ 702 /* PMP is reset, SErrors cannot be trusted, scan all */
703 ata_port_for_each_link(tlink, ap) { 703 ata_for_each_link(tlink, ap, EDGE) {
704 struct ata_eh_context *ehc = &tlink->eh_context; 704 struct ata_eh_context *ehc = &tlink->eh_context;
705 705
706 ehc->i.probe_mask |= ATA_ALL_DEVICES; 706 ehc->i.probe_mask |= ATA_ALL_DEVICES;
@@ -768,7 +768,7 @@ static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
768 768
769 spin_lock_irqsave(ap->lock, flags); 769 spin_lock_irqsave(ap->lock, flags);
770 770
771 ata_port_for_each_link(link, ap) { 771 ata_for_each_link(link, ap, EDGE) {
772 if (!(link->flags & ATA_LFLAG_DISABLED)) 772 if (!(link->flags & ATA_LFLAG_DISABLED))
773 continue; 773 continue;
774 774
@@ -852,7 +852,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
852 int cnt, rc; 852 int cnt, rc;
853 853
854 pmp_tries = ATA_EH_PMP_TRIES; 854 pmp_tries = ATA_EH_PMP_TRIES;
855 ata_port_for_each_link(link, ap) 855 ata_for_each_link(link, ap, EDGE)
856 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES; 856 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
857 857
858 retry: 858 retry:
@@ -861,7 +861,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
861 rc = ata_eh_recover(ap, ops->prereset, ops->softreset, 861 rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
862 ops->hardreset, ops->postreset, NULL); 862 ops->hardreset, ops->postreset, NULL);
863 if (rc) { 863 if (rc) {
864 ata_link_for_each_dev(dev, &ap->link) 864 ata_for_each_dev(dev, &ap->link, ALL)
865 ata_dev_disable(dev); 865 ata_dev_disable(dev);
866 return rc; 866 return rc;
867 } 867 }
@@ -870,7 +870,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
870 return 0; 870 return 0;
871 871
872 /* new PMP online */ 872 /* new PMP online */
873 ata_port_for_each_link(link, ap) 873 ata_for_each_link(link, ap, EDGE)
874 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES; 874 link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
875 875
876 /* fall through */ 876 /* fall through */
@@ -942,7 +942,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
942 } 942 }
943 943
944 cnt = 0; 944 cnt = 0;
945 ata_port_for_each_link(link, ap) { 945 ata_for_each_link(link, ap, EDGE) {
946 if (!(gscr_error & (1 << link->pmp))) 946 if (!(gscr_error & (1 << link->pmp)))
947 continue; 947 continue;
948 948
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 47c7afcb36f2..9e92107691f2 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -517,7 +517,7 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
517 /* Good values for timeout and retries? Values below 517 /* Good values for timeout and retries? Values below
518 from scsi_ioctl_send_command() for default case... */ 518 from scsi_ioctl_send_command() for default case... */
519 cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, 519 cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize,
520 sensebuf, (10*HZ), 5, 0); 520 sensebuf, (10*HZ), 5, 0, NULL);
521 521
522 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ 522 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
523 u8 *desc = sensebuf + 8; 523 u8 *desc = sensebuf + 8;
@@ -603,7 +603,7 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
603 /* Good values for timeout and retries? Values below 603 /* Good values for timeout and retries? Values below
604 from scsi_ioctl_send_command() for default case... */ 604 from scsi_ioctl_send_command() for default case... */
605 cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, 605 cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
606 sensebuf, (10*HZ), 5, 0); 606 sensebuf, (10*HZ), 5, 0, NULL);
607 607
608 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ 608 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
609 u8 *desc = sensebuf + 8; 609 u8 *desc = sensebuf + 8;
@@ -3229,12 +3229,12 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3229 return; 3229 return;
3230 3230
3231 repeat: 3231 repeat:
3232 ata_port_for_each_link(link, ap) { 3232 ata_for_each_link(link, ap, EDGE) {
3233 ata_link_for_each_dev(dev, link) { 3233 ata_for_each_dev(dev, link, ENABLED) {
3234 struct scsi_device *sdev; 3234 struct scsi_device *sdev;
3235 int channel = 0, id = 0; 3235 int channel = 0, id = 0;
3236 3236
3237 if (!ata_dev_enabled(dev) || dev->sdev) 3237 if (dev->sdev)
3238 continue; 3238 continue;
3239 3239
3240 if (ata_is_host_link(link)) 3240 if (ata_is_host_link(link))
@@ -3255,9 +3255,9 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
3255 * failure occurred, scan would have failed silently. Check 3255 * failure occurred, scan would have failed silently. Check
3256 * whether all devices are attached. 3256 * whether all devices are attached.
3257 */ 3257 */
3258 ata_port_for_each_link(link, ap) { 3258 ata_for_each_link(link, ap, EDGE) {
3259 ata_link_for_each_dev(dev, link) { 3259 ata_for_each_dev(dev, link, ENABLED) {
3260 if (ata_dev_enabled(dev) && !dev->sdev) 3260 if (!dev->sdev)
3261 goto exit_loop; 3261 goto exit_loop;
3262 } 3262 }
3263 } 3263 }
@@ -3369,7 +3369,7 @@ static void ata_scsi_remove_dev(struct ata_device *dev)
3369 3369
3370 if (sdev) { 3370 if (sdev) {
3371 ata_dev_printk(dev, KERN_INFO, "detaching (SCSI %s)\n", 3371 ata_dev_printk(dev, KERN_INFO, "detaching (SCSI %s)\n",
3372 sdev->sdev_gendev.bus_id); 3372 dev_name(&sdev->sdev_gendev));
3373 3373
3374 scsi_remove_device(sdev); 3374 scsi_remove_device(sdev);
3375 scsi_device_put(sdev); 3375 scsi_device_put(sdev);
@@ -3381,7 +3381,7 @@ static void ata_scsi_handle_link_detach(struct ata_link *link)
3381 struct ata_port *ap = link->ap; 3381 struct ata_port *ap = link->ap;
3382 struct ata_device *dev; 3382 struct ata_device *dev;
3383 3383
3384 ata_link_for_each_dev(dev, link) { 3384 ata_for_each_dev(dev, link, ALL) {
3385 unsigned long flags; 3385 unsigned long flags;
3386 3386
3387 if (!(dev->flags & ATA_DFLAG_DETACHED)) 3387 if (!(dev->flags & ATA_DFLAG_DETACHED))
@@ -3496,7 +3496,7 @@ static int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
3496 if (devno == SCAN_WILD_CARD) { 3496 if (devno == SCAN_WILD_CARD) {
3497 struct ata_link *link; 3497 struct ata_link *link;
3498 3498
3499 ata_port_for_each_link(link, ap) { 3499 ata_for_each_link(link, ap, EDGE) {
3500 struct ata_eh_info *ehi = &link->eh_info; 3500 struct ata_eh_info *ehi = &link->eh_info;
3501 ehi->probe_mask |= ATA_ALL_DEVICES; 3501 ehi->probe_mask |= ATA_ALL_DEVICES;
3502 ehi->action |= ATA_EH_RESET; 3502 ehi->action |= ATA_EH_RESET;
@@ -3544,11 +3544,11 @@ void ata_scsi_dev_rescan(struct work_struct *work)
3544 3544
3545 spin_lock_irqsave(ap->lock, flags); 3545 spin_lock_irqsave(ap->lock, flags);
3546 3546
3547 ata_port_for_each_link(link, ap) { 3547 ata_for_each_link(link, ap, EDGE) {
3548 ata_link_for_each_dev(dev, link) { 3548 ata_for_each_dev(dev, link, ENABLED) {
3549 struct scsi_device *sdev = dev->sdev; 3549 struct scsi_device *sdev = dev->sdev;
3550 3550
3551 if (!ata_dev_enabled(dev) || !sdev) 3551 if (!sdev)
3552 continue; 3552 continue;
3553 if (scsi_device_get(sdev)) 3553 if (scsi_device_get(sdev))
3554 continue; 3554 continue;
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 9033d164c4ec..c59ad76c84b1 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -66,6 +66,7 @@ const struct ata_port_operations ata_sff_port_ops = {
66 66
67 .port_start = ata_sff_port_start, 67 .port_start = ata_sff_port_start,
68}; 68};
69EXPORT_SYMBOL_GPL(ata_sff_port_ops);
69 70
70const struct ata_port_operations ata_bmdma_port_ops = { 71const struct ata_port_operations ata_bmdma_port_ops = {
71 .inherits = &ata_sff_port_ops, 72 .inherits = &ata_sff_port_ops,
@@ -77,6 +78,14 @@ const struct ata_port_operations ata_bmdma_port_ops = {
77 .bmdma_stop = ata_bmdma_stop, 78 .bmdma_stop = ata_bmdma_stop,
78 .bmdma_status = ata_bmdma_status, 79 .bmdma_status = ata_bmdma_status,
79}; 80};
81EXPORT_SYMBOL_GPL(ata_bmdma_port_ops);
82
83const struct ata_port_operations ata_bmdma32_port_ops = {
84 .inherits = &ata_bmdma_port_ops,
85
86 .sff_data_xfer = ata_sff_data_xfer32,
87};
88EXPORT_SYMBOL_GPL(ata_bmdma32_port_ops);
80 89
81/** 90/**
82 * ata_fill_sg - Fill PCI IDE PRD table 91 * ata_fill_sg - Fill PCI IDE PRD table
@@ -166,8 +175,9 @@ static void ata_fill_sg_dumb(struct ata_queued_cmd *qc)
166 blen = len & 0xffff; 175 blen = len & 0xffff;
167 ap->prd[pi].addr = cpu_to_le32(addr); 176 ap->prd[pi].addr = cpu_to_le32(addr);
168 if (blen == 0) { 177 if (blen == 0) {
169 /* Some PATA chipsets like the CS5530 can't 178 /* Some PATA chipsets like the CS5530 can't
170 cope with 0x0000 meaning 64K as the spec says */ 179 cope with 0x0000 meaning 64K as the spec
180 says */
171 ap->prd[pi].flags_len = cpu_to_le32(0x8000); 181 ap->prd[pi].flags_len = cpu_to_le32(0x8000);
172 blen = 0x8000; 182 blen = 0x8000;
173 ap->prd[++pi].addr = cpu_to_le32(addr + 0x8000); 183 ap->prd[++pi].addr = cpu_to_le32(addr + 0x8000);
@@ -200,6 +210,7 @@ void ata_sff_qc_prep(struct ata_queued_cmd *qc)
200 210
201 ata_fill_sg(qc); 211 ata_fill_sg(qc);
202} 212}
213EXPORT_SYMBOL_GPL(ata_sff_qc_prep);
203 214
204/** 215/**
205 * ata_sff_dumb_qc_prep - Prepare taskfile for submission 216 * ata_sff_dumb_qc_prep - Prepare taskfile for submission
@@ -217,6 +228,7 @@ void ata_sff_dumb_qc_prep(struct ata_queued_cmd *qc)
217 228
218 ata_fill_sg_dumb(qc); 229 ata_fill_sg_dumb(qc);
219} 230}
231EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep);
220 232
221/** 233/**
222 * ata_sff_check_status - Read device status reg & clear interrupt 234 * ata_sff_check_status - Read device status reg & clear interrupt
@@ -233,6 +245,7 @@ u8 ata_sff_check_status(struct ata_port *ap)
233{ 245{
234 return ioread8(ap->ioaddr.status_addr); 246 return ioread8(ap->ioaddr.status_addr);
235} 247}
248EXPORT_SYMBOL_GPL(ata_sff_check_status);
236 249
237/** 250/**
238 * ata_sff_altstatus - Read device alternate status reg 251 * ata_sff_altstatus - Read device alternate status reg
@@ -275,7 +288,7 @@ static u8 ata_sff_irq_status(struct ata_port *ap)
275 status = ata_sff_altstatus(ap); 288 status = ata_sff_altstatus(ap);
276 /* Not us: We are busy */ 289 /* Not us: We are busy */
277 if (status & ATA_BUSY) 290 if (status & ATA_BUSY)
278 return status; 291 return status;
279 } 292 }
280 /* Clear INTRQ latch */ 293 /* Clear INTRQ latch */
281 status = ap->ops->sff_check_status(ap); 294 status = ap->ops->sff_check_status(ap);
@@ -319,6 +332,7 @@ void ata_sff_pause(struct ata_port *ap)
319 ata_sff_sync(ap); 332 ata_sff_sync(ap);
320 ndelay(400); 333 ndelay(400);
321} 334}
335EXPORT_SYMBOL_GPL(ata_sff_pause);
322 336
323/** 337/**
324 * ata_sff_dma_pause - Pause before commencing DMA 338 * ata_sff_dma_pause - Pause before commencing DMA
@@ -327,7 +341,7 @@ void ata_sff_pause(struct ata_port *ap)
327 * Perform I/O fencing and ensure sufficient cycle delays occur 341 * Perform I/O fencing and ensure sufficient cycle delays occur
328 * for the HDMA1:0 transition 342 * for the HDMA1:0 transition
329 */ 343 */
330 344
331void ata_sff_dma_pause(struct ata_port *ap) 345void ata_sff_dma_pause(struct ata_port *ap)
332{ 346{
333 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) { 347 if (ap->ops->sff_check_altstatus || ap->ioaddr.altstatus_addr) {
@@ -341,6 +355,7 @@ void ata_sff_dma_pause(struct ata_port *ap)
341 corruption. */ 355 corruption. */
342 BUG(); 356 BUG();
343} 357}
358EXPORT_SYMBOL_GPL(ata_sff_dma_pause);
344 359
345/** 360/**
346 * ata_sff_busy_sleep - sleep until BSY clears, or timeout 361 * ata_sff_busy_sleep - sleep until BSY clears, or timeout
@@ -396,6 +411,7 @@ int ata_sff_busy_sleep(struct ata_port *ap,
396 411
397 return 0; 412 return 0;
398} 413}
414EXPORT_SYMBOL_GPL(ata_sff_busy_sleep);
399 415
400static int ata_sff_check_ready(struct ata_link *link) 416static int ata_sff_check_ready(struct ata_link *link)
401{ 417{
@@ -422,6 +438,7 @@ int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline)
422{ 438{
423 return ata_wait_ready(link, deadline, ata_sff_check_ready); 439 return ata_wait_ready(link, deadline, ata_sff_check_ready);
424} 440}
441EXPORT_SYMBOL_GPL(ata_sff_wait_ready);
425 442
426/** 443/**
427 * ata_sff_dev_select - Select device 0/1 on ATA bus 444 * ata_sff_dev_select - Select device 0/1 on ATA bus
@@ -449,6 +466,7 @@ void ata_sff_dev_select(struct ata_port *ap, unsigned int device)
449 iowrite8(tmp, ap->ioaddr.device_addr); 466 iowrite8(tmp, ap->ioaddr.device_addr);
450 ata_sff_pause(ap); /* needed; also flushes, for mmio */ 467 ata_sff_pause(ap); /* needed; also flushes, for mmio */
451} 468}
469EXPORT_SYMBOL_GPL(ata_sff_dev_select);
452 470
453/** 471/**
454 * ata_dev_select - Select device 0/1 on ATA bus 472 * ata_dev_select - Select device 0/1 on ATA bus
@@ -513,6 +531,7 @@ u8 ata_sff_irq_on(struct ata_port *ap)
513 531
514 return tmp; 532 return tmp;
515} 533}
534EXPORT_SYMBOL_GPL(ata_sff_irq_on);
516 535
517/** 536/**
518 * ata_sff_irq_clear - Clear PCI IDE BMDMA interrupt. 537 * ata_sff_irq_clear - Clear PCI IDE BMDMA interrupt.
@@ -534,6 +553,7 @@ void ata_sff_irq_clear(struct ata_port *ap)
534 553
535 iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS); 554 iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS);
536} 555}
556EXPORT_SYMBOL_GPL(ata_sff_irq_clear);
537 557
538/** 558/**
539 * ata_sff_tf_load - send taskfile registers to host controller 559 * ata_sff_tf_load - send taskfile registers to host controller
@@ -593,6 +613,7 @@ void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
593 613
594 ata_wait_idle(ap); 614 ata_wait_idle(ap);
595} 615}
616EXPORT_SYMBOL_GPL(ata_sff_tf_load);
596 617
597/** 618/**
598 * ata_sff_tf_read - input device's ATA taskfile shadow registers 619 * ata_sff_tf_read - input device's ATA taskfile shadow registers
@@ -633,6 +654,7 @@ void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
633 WARN_ON(1); 654 WARN_ON(1);
634 } 655 }
635} 656}
657EXPORT_SYMBOL_GPL(ata_sff_tf_read);
636 658
637/** 659/**
638 * ata_sff_exec_command - issue ATA command to host controller 660 * ata_sff_exec_command - issue ATA command to host controller
@@ -652,6 +674,7 @@ void ata_sff_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
652 iowrite8(tf->command, ap->ioaddr.command_addr); 674 iowrite8(tf->command, ap->ioaddr.command_addr);
653 ata_sff_pause(ap); 675 ata_sff_pause(ap);
654} 676}
677EXPORT_SYMBOL_GPL(ata_sff_exec_command);
655 678
656/** 679/**
657 * ata_tf_to_host - issue ATA taskfile to host controller 680 * ata_tf_to_host - issue ATA taskfile to host controller
@@ -717,6 +740,53 @@ unsigned int ata_sff_data_xfer(struct ata_device *dev, unsigned char *buf,
717 740
718 return words << 1; 741 return words << 1;
719} 742}
743EXPORT_SYMBOL_GPL(ata_sff_data_xfer);
744
745/**
746 * ata_sff_data_xfer32 - Transfer data by PIO
747 * @dev: device to target
748 * @buf: data buffer
749 * @buflen: buffer length
750 * @rw: read/write
751 *
752 * Transfer data from/to the device data register by PIO using 32bit
753 * I/O operations.
754 *
755 * LOCKING:
756 * Inherited from caller.
757 *
758 * RETURNS:
759 * Bytes consumed.
760 */
761
762unsigned int ata_sff_data_xfer32(struct ata_device *dev, unsigned char *buf,
763 unsigned int buflen, int rw)
764{
765 struct ata_port *ap = dev->link->ap;
766 void __iomem *data_addr = ap->ioaddr.data_addr;
767 unsigned int words = buflen >> 2;
768 int slop = buflen & 3;
769
770 /* Transfer multiple of 4 bytes */
771 if (rw == READ)
772 ioread32_rep(data_addr, buf, words);
773 else
774 iowrite32_rep(data_addr, buf, words);
775
776 if (unlikely(slop)) {
777 __le32 pad;
778 if (rw == READ) {
779 pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
780 memcpy(buf + buflen - slop, &pad, slop);
781 } else {
782 memcpy(&pad, buf + buflen - slop, slop);
783 iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
784 }
785 words++;
786 }
787 return words << 2;
788}
789EXPORT_SYMBOL_GPL(ata_sff_data_xfer32);
720 790
721/** 791/**
722 * ata_sff_data_xfer_noirq - Transfer data by PIO 792 * ata_sff_data_xfer_noirq - Transfer data by PIO
@@ -746,6 +816,7 @@ unsigned int ata_sff_data_xfer_noirq(struct ata_device *dev, unsigned char *buf,
746 816
747 return consumed; 817 return consumed;
748} 818}
819EXPORT_SYMBOL_GPL(ata_sff_data_xfer_noirq);
749 820
750/** 821/**
751 * ata_pio_sector - Transfer a sector of data. 822 * ata_pio_sector - Transfer a sector of data.
@@ -922,13 +993,15 @@ next_sg:
922 buf = kmap_atomic(page, KM_IRQ0); 993 buf = kmap_atomic(page, KM_IRQ0);
923 994
924 /* do the actual data transfer */ 995 /* do the actual data transfer */
925 consumed = ap->ops->sff_data_xfer(dev, buf + offset, count, rw); 996 consumed = ap->ops->sff_data_xfer(dev, buf + offset,
997 count, rw);
926 998
927 kunmap_atomic(buf, KM_IRQ0); 999 kunmap_atomic(buf, KM_IRQ0);
928 local_irq_restore(flags); 1000 local_irq_restore(flags);
929 } else { 1001 } else {
930 buf = page_address(page); 1002 buf = page_address(page);
931 consumed = ap->ops->sff_data_xfer(dev, buf + offset, count, rw); 1003 consumed = ap->ops->sff_data_xfer(dev, buf + offset,
1004 count, rw);
932 } 1005 }
933 1006
934 bytes -= min(bytes, consumed); 1007 bytes -= min(bytes, consumed);
@@ -1013,18 +1086,19 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
1013 * RETURNS: 1086 * RETURNS:
1014 * 1 if ok in workqueue, 0 otherwise. 1087 * 1 if ok in workqueue, 0 otherwise.
1015 */ 1088 */
1016static inline int ata_hsm_ok_in_wq(struct ata_port *ap, struct ata_queued_cmd *qc) 1089static inline int ata_hsm_ok_in_wq(struct ata_port *ap,
1090 struct ata_queued_cmd *qc)
1017{ 1091{
1018 if (qc->tf.flags & ATA_TFLAG_POLLING) 1092 if (qc->tf.flags & ATA_TFLAG_POLLING)
1019 return 1; 1093 return 1;
1020 1094
1021 if (ap->hsm_task_state == HSM_ST_FIRST) { 1095 if (ap->hsm_task_state == HSM_ST_FIRST) {
1022 if (qc->tf.protocol == ATA_PROT_PIO && 1096 if (qc->tf.protocol == ATA_PROT_PIO &&
1023 (qc->tf.flags & ATA_TFLAG_WRITE)) 1097 (qc->tf.flags & ATA_TFLAG_WRITE))
1024 return 1; 1098 return 1;
1025 1099
1026 if (ata_is_atapi(qc->tf.protocol) && 1100 if (ata_is_atapi(qc->tf.protocol) &&
1027 !(qc->dev->flags & ATA_DFLAG_CDB_INTR)) 1101 !(qc->dev->flags & ATA_DFLAG_CDB_INTR))
1028 return 1; 1102 return 1;
1029 } 1103 }
1030 1104
@@ -1338,6 +1412,7 @@ fsm_start:
1338 1412
1339 return poll_next; 1413 return poll_next;
1340} 1414}
1415EXPORT_SYMBOL_GPL(ata_sff_hsm_move);
1341 1416
1342void ata_pio_task(struct work_struct *work) 1417void ata_pio_task(struct work_struct *work)
1343{ 1418{
@@ -1507,6 +1582,7 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
1507 1582
1508 return 0; 1583 return 0;
1509} 1584}
1585EXPORT_SYMBOL_GPL(ata_sff_qc_issue);
1510 1586
1511/** 1587/**
1512 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read 1588 * ata_sff_qc_fill_rtf - fill result TF using ->sff_tf_read
@@ -1526,6 +1602,7 @@ bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc)
1526 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf); 1602 qc->ap->ops->sff_tf_read(qc->ap, &qc->result_tf);
1527 return true; 1603 return true;
1528} 1604}
1605EXPORT_SYMBOL_GPL(ata_sff_qc_fill_rtf);
1529 1606
1530/** 1607/**
1531 * ata_sff_host_intr - Handle host interrupt for given (port, task) 1608 * ata_sff_host_intr - Handle host interrupt for given (port, task)
@@ -1623,6 +1700,7 @@ idle_irq:
1623#endif 1700#endif
1624 return 0; /* irq not handled */ 1701 return 0; /* irq not handled */
1625} 1702}
1703EXPORT_SYMBOL_GPL(ata_sff_host_intr);
1626 1704
1627/** 1705/**
1628 * ata_sff_interrupt - Default ATA host interrupt handler 1706 * ata_sff_interrupt - Default ATA host interrupt handler
@@ -1667,6 +1745,7 @@ irqreturn_t ata_sff_interrupt(int irq, void *dev_instance)
1667 1745
1668 return IRQ_RETVAL(handled); 1746 return IRQ_RETVAL(handled);
1669} 1747}
1748EXPORT_SYMBOL_GPL(ata_sff_interrupt);
1670 1749
1671/** 1750/**
1672 * ata_sff_freeze - Freeze SFF controller port 1751 * ata_sff_freeze - Freeze SFF controller port
@@ -1695,6 +1774,7 @@ void ata_sff_freeze(struct ata_port *ap)
1695 1774
1696 ap->ops->sff_irq_clear(ap); 1775 ap->ops->sff_irq_clear(ap);
1697} 1776}
1777EXPORT_SYMBOL_GPL(ata_sff_freeze);
1698 1778
1699/** 1779/**
1700 * ata_sff_thaw - Thaw SFF controller port 1780 * ata_sff_thaw - Thaw SFF controller port
@@ -1712,6 +1792,7 @@ void ata_sff_thaw(struct ata_port *ap)
1712 ap->ops->sff_irq_clear(ap); 1792 ap->ops->sff_irq_clear(ap);
1713 ap->ops->sff_irq_on(ap); 1793 ap->ops->sff_irq_on(ap);
1714} 1794}
1795EXPORT_SYMBOL_GPL(ata_sff_thaw);
1715 1796
1716/** 1797/**
1717 * ata_sff_prereset - prepare SFF link for reset 1798 * ata_sff_prereset - prepare SFF link for reset
@@ -1753,6 +1834,7 @@ int ata_sff_prereset(struct ata_link *link, unsigned long deadline)
1753 1834
1754 return 0; 1835 return 0;
1755} 1836}
1837EXPORT_SYMBOL_GPL(ata_sff_prereset);
1756 1838
1757/** 1839/**
1758 * ata_devchk - PATA device presence detection 1840 * ata_devchk - PATA device presence detection
@@ -1865,6 +1947,7 @@ unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
1865 1947
1866 return class; 1948 return class;
1867} 1949}
1950EXPORT_SYMBOL_GPL(ata_sff_dev_classify);
1868 1951
1869/** 1952/**
1870 * ata_sff_wait_after_reset - wait for devices to become ready after reset 1953 * ata_sff_wait_after_reset - wait for devices to become ready after reset
@@ -1941,6 +2024,7 @@ int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
1941 2024
1942 return ret; 2025 return ret;
1943} 2026}
2027EXPORT_SYMBOL_GPL(ata_sff_wait_after_reset);
1944 2028
1945static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask, 2029static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
1946 unsigned long deadline) 2030 unsigned long deadline)
@@ -2013,6 +2097,7 @@ int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
2013 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]); 2097 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes[0], classes[1]);
2014 return 0; 2098 return 0;
2015} 2099}
2100EXPORT_SYMBOL_GPL(ata_sff_softreset);
2016 2101
2017/** 2102/**
2018 * sata_sff_hardreset - reset host port via SATA phy reset 2103 * sata_sff_hardreset - reset host port via SATA phy reset
@@ -2045,6 +2130,7 @@ int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
2045 DPRINTK("EXIT, class=%u\n", *class); 2130 DPRINTK("EXIT, class=%u\n", *class);
2046 return rc; 2131 return rc;
2047} 2132}
2133EXPORT_SYMBOL_GPL(sata_sff_hardreset);
2048 2134
2049/** 2135/**
2050 * ata_sff_postreset - SFF postreset callback 2136 * ata_sff_postreset - SFF postreset callback
@@ -2080,6 +2166,7 @@ void ata_sff_postreset(struct ata_link *link, unsigned int *classes)
2080 if (ap->ioaddr.ctl_addr) 2166 if (ap->ioaddr.ctl_addr)
2081 iowrite8(ap->ctl, ap->ioaddr.ctl_addr); 2167 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
2082} 2168}
2169EXPORT_SYMBOL_GPL(ata_sff_postreset);
2083 2170
2084/** 2171/**
2085 * ata_sff_error_handler - Stock error handler for BMDMA controller 2172 * ata_sff_error_handler - Stock error handler for BMDMA controller
@@ -2152,6 +2239,7 @@ void ata_sff_error_handler(struct ata_port *ap)
2152 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset, 2239 ata_do_eh(ap, ap->ops->prereset, softreset, hardreset,
2153 ap->ops->postreset); 2240 ap->ops->postreset);
2154} 2241}
2242EXPORT_SYMBOL_GPL(ata_sff_error_handler);
2155 2243
2156/** 2244/**
2157 * ata_sff_post_internal_cmd - Stock post_internal_cmd for SFF controller 2245 * ata_sff_post_internal_cmd - Stock post_internal_cmd for SFF controller
@@ -2174,6 +2262,7 @@ void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc)
2174 2262
2175 spin_unlock_irqrestore(ap->lock, flags); 2263 spin_unlock_irqrestore(ap->lock, flags);
2176} 2264}
2265EXPORT_SYMBOL_GPL(ata_sff_post_internal_cmd);
2177 2266
2178/** 2267/**
2179 * ata_sff_port_start - Set port up for dma. 2268 * ata_sff_port_start - Set port up for dma.
@@ -2194,6 +2283,7 @@ int ata_sff_port_start(struct ata_port *ap)
2194 return ata_port_start(ap); 2283 return ata_port_start(ap);
2195 return 0; 2284 return 0;
2196} 2285}
2286EXPORT_SYMBOL_GPL(ata_sff_port_start);
2197 2287
2198/** 2288/**
2199 * ata_sff_std_ports - initialize ioaddr with standard port offsets. 2289 * ata_sff_std_ports - initialize ioaddr with standard port offsets.
@@ -2219,6 +2309,7 @@ void ata_sff_std_ports(struct ata_ioports *ioaddr)
2219 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS; 2309 ioaddr->status_addr = ioaddr->cmd_addr + ATA_REG_STATUS;
2220 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD; 2310 ioaddr->command_addr = ioaddr->cmd_addr + ATA_REG_CMD;
2221} 2311}
2312EXPORT_SYMBOL_GPL(ata_sff_std_ports);
2222 2313
2223unsigned long ata_bmdma_mode_filter(struct ata_device *adev, 2314unsigned long ata_bmdma_mode_filter(struct ata_device *adev,
2224 unsigned long xfer_mask) 2315 unsigned long xfer_mask)
@@ -2230,6 +2321,7 @@ unsigned long ata_bmdma_mode_filter(struct ata_device *adev,
2230 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2321 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
2231 return xfer_mask; 2322 return xfer_mask;
2232} 2323}
2324EXPORT_SYMBOL_GPL(ata_bmdma_mode_filter);
2233 2325
2234/** 2326/**
2235 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction 2327 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
@@ -2258,6 +2350,7 @@ void ata_bmdma_setup(struct ata_queued_cmd *qc)
2258 /* issue r/w command */ 2350 /* issue r/w command */
2259 ap->ops->sff_exec_command(ap, &qc->tf); 2351 ap->ops->sff_exec_command(ap, &qc->tf);
2260} 2352}
2353EXPORT_SYMBOL_GPL(ata_bmdma_setup);
2261 2354
2262/** 2355/**
2263 * ata_bmdma_start - Start a PCI IDE BMDMA transaction 2356 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
@@ -2290,6 +2383,7 @@ void ata_bmdma_start(struct ata_queued_cmd *qc)
2290 * unneccessarily delayed for MMIO 2383 * unneccessarily delayed for MMIO
2291 */ 2384 */
2292} 2385}
2386EXPORT_SYMBOL_GPL(ata_bmdma_start);
2293 2387
2294/** 2388/**
2295 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer 2389 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
@@ -2314,6 +2408,7 @@ void ata_bmdma_stop(struct ata_queued_cmd *qc)
2314 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 2408 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
2315 ata_sff_dma_pause(ap); 2409 ata_sff_dma_pause(ap);
2316} 2410}
2411EXPORT_SYMBOL_GPL(ata_bmdma_stop);
2317 2412
2318/** 2413/**
2319 * ata_bmdma_status - Read PCI IDE BMDMA status 2414 * ata_bmdma_status - Read PCI IDE BMDMA status
@@ -2330,6 +2425,7 @@ u8 ata_bmdma_status(struct ata_port *ap)
2330{ 2425{
2331 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 2426 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
2332} 2427}
2428EXPORT_SYMBOL_GPL(ata_bmdma_status);
2333 2429
2334/** 2430/**
2335 * ata_bus_reset - reset host port and associated ATA channel 2431 * ata_bus_reset - reset host port and associated ATA channel
@@ -2422,6 +2518,7 @@ err_out:
2422 2518
2423 DPRINTK("EXIT\n"); 2519 DPRINTK("EXIT\n");
2424} 2520}
2521EXPORT_SYMBOL_GPL(ata_bus_reset);
2425 2522
2426#ifdef CONFIG_PCI 2523#ifdef CONFIG_PCI
2427 2524
@@ -2449,6 +2546,7 @@ int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev)
2449 return -EOPNOTSUPP; 2546 return -EOPNOTSUPP;
2450 return 0; 2547 return 0;
2451} 2548}
2549EXPORT_SYMBOL_GPL(ata_pci_bmdma_clear_simplex);
2452 2550
2453/** 2551/**
2454 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host 2552 * ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
@@ -2501,11 +2599,12 @@ int ata_pci_bmdma_init(struct ata_host *host)
2501 host->flags |= ATA_HOST_SIMPLEX; 2599 host->flags |= ATA_HOST_SIMPLEX;
2502 2600
2503 ata_port_desc(ap, "bmdma 0x%llx", 2601 ata_port_desc(ap, "bmdma 0x%llx",
2504 (unsigned long long)pci_resource_start(pdev, 4) + 8 * i); 2602 (unsigned long long)pci_resource_start(pdev, 4) + 8 * i);
2505 } 2603 }
2506 2604
2507 return 0; 2605 return 0;
2508} 2606}
2607EXPORT_SYMBOL_GPL(ata_pci_bmdma_init);
2509 2608
2510static int ata_resources_present(struct pci_dev *pdev, int port) 2609static int ata_resources_present(struct pci_dev *pdev, int port)
2511{ 2610{
@@ -2513,7 +2612,7 @@ static int ata_resources_present(struct pci_dev *pdev, int port)
2513 2612
2514 /* Check the PCI resources for this channel are enabled */ 2613 /* Check the PCI resources for this channel are enabled */
2515 port = port * 2; 2614 port = port * 2;
2516 for (i = 0; i < 2; i ++) { 2615 for (i = 0; i < 2; i++) {
2517 if (pci_resource_start(pdev, port + i) == 0 || 2616 if (pci_resource_start(pdev, port + i) == 0 ||
2518 pci_resource_len(pdev, port + i) == 0) 2617 pci_resource_len(pdev, port + i) == 0)
2519 return 0; 2618 return 0;
@@ -2598,6 +2697,7 @@ int ata_pci_sff_init_host(struct ata_host *host)
2598 2697
2599 return 0; 2698 return 0;
2600} 2699}
2700EXPORT_SYMBOL_GPL(ata_pci_sff_init_host);
2601 2701
2602/** 2702/**
2603 * ata_pci_sff_prepare_host - helper to prepare native PCI ATA host 2703 * ata_pci_sff_prepare_host - helper to prepare native PCI ATA host
@@ -2615,7 +2715,7 @@ int ata_pci_sff_init_host(struct ata_host *host)
2615 * 0 on success, -errno otherwise. 2715 * 0 on success, -errno otherwise.
2616 */ 2716 */
2617int ata_pci_sff_prepare_host(struct pci_dev *pdev, 2717int ata_pci_sff_prepare_host(struct pci_dev *pdev,
2618 const struct ata_port_info * const * ppi, 2718 const struct ata_port_info * const *ppi,
2619 struct ata_host **r_host) 2719 struct ata_host **r_host)
2620{ 2720{
2621 struct ata_host *host; 2721 struct ata_host *host;
@@ -2645,17 +2745,18 @@ int ata_pci_sff_prepare_host(struct pci_dev *pdev,
2645 *r_host = host; 2745 *r_host = host;
2646 return 0; 2746 return 0;
2647 2747
2648 err_bmdma: 2748err_bmdma:
2649 /* This is necessary because PCI and iomap resources are 2749 /* This is necessary because PCI and iomap resources are
2650 * merged and releasing the top group won't release the 2750 * merged and releasing the top group won't release the
2651 * acquired resources if some of those have been acquired 2751 * acquired resources if some of those have been acquired
2652 * before entering this function. 2752 * before entering this function.
2653 */ 2753 */
2654 pcim_iounmap_regions(pdev, 0xf); 2754 pcim_iounmap_regions(pdev, 0xf);
2655 err_out: 2755err_out:
2656 devres_release_group(&pdev->dev, NULL); 2756 devres_release_group(&pdev->dev, NULL);
2657 return rc; 2757 return rc;
2658} 2758}
2759EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host);
2659 2760
2660/** 2761/**
2661 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it 2762 * ata_pci_sff_activate_host - start SFF host, request IRQ and register it
@@ -2741,7 +2842,7 @@ int ata_pci_sff_activate_host(struct ata_host *host,
2741 } 2842 }
2742 2843
2743 rc = ata_host_register(host, sht); 2844 rc = ata_host_register(host, sht);
2744 out: 2845out:
2745 if (rc == 0) 2846 if (rc == 0)
2746 devres_remove_group(dev, NULL); 2847 devres_remove_group(dev, NULL);
2747 else 2848 else
@@ -2749,6 +2850,7 @@ int ata_pci_sff_activate_host(struct ata_host *host,
2749 2850
2750 return rc; 2851 return rc;
2751} 2852}
2853EXPORT_SYMBOL_GPL(ata_pci_sff_activate_host);
2752 2854
2753/** 2855/**
2754 * ata_pci_sff_init_one - Initialize/register PCI IDE host controller 2856 * ata_pci_sff_init_one - Initialize/register PCI IDE host controller
@@ -2776,7 +2878,7 @@ int ata_pci_sff_activate_host(struct ata_host *host,
2776 * Zero on success, negative on errno-based value on error. 2878 * Zero on success, negative on errno-based value on error.
2777 */ 2879 */
2778int ata_pci_sff_init_one(struct pci_dev *pdev, 2880int ata_pci_sff_init_one(struct pci_dev *pdev,
2779 const struct ata_port_info * const * ppi, 2881 const struct ata_port_info * const *ppi,
2780 struct scsi_host_template *sht, void *host_priv) 2882 struct scsi_host_template *sht, void *host_priv)
2781{ 2883{
2782 struct device *dev = &pdev->dev; 2884 struct device *dev = &pdev->dev;
@@ -2815,7 +2917,7 @@ int ata_pci_sff_init_one(struct pci_dev *pdev,
2815 2917
2816 pci_set_master(pdev); 2918 pci_set_master(pdev);
2817 rc = ata_pci_sff_activate_host(host, ata_sff_interrupt, sht); 2919 rc = ata_pci_sff_activate_host(host, ata_sff_interrupt, sht);
2818 out: 2920out:
2819 if (rc == 0) 2921 if (rc == 0)
2820 devres_remove_group(&pdev->dev, NULL); 2922 devres_remove_group(&pdev->dev, NULL);
2821 else 2923 else
@@ -2823,54 +2925,7 @@ int ata_pci_sff_init_one(struct pci_dev *pdev,
2823 2925
2824 return rc; 2926 return rc;
2825} 2927}
2928EXPORT_SYMBOL_GPL(ata_pci_sff_init_one);
2826 2929
2827#endif /* CONFIG_PCI */ 2930#endif /* CONFIG_PCI */
2828 2931
2829EXPORT_SYMBOL_GPL(ata_sff_port_ops);
2830EXPORT_SYMBOL_GPL(ata_bmdma_port_ops);
2831EXPORT_SYMBOL_GPL(ata_sff_qc_prep);
2832EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep);
2833EXPORT_SYMBOL_GPL(ata_sff_dev_select);
2834EXPORT_SYMBOL_GPL(ata_sff_check_status);
2835EXPORT_SYMBOL_GPL(ata_sff_dma_pause);
2836EXPORT_SYMBOL_GPL(ata_sff_pause);
2837EXPORT_SYMBOL_GPL(ata_sff_busy_sleep);
2838EXPORT_SYMBOL_GPL(ata_sff_wait_ready);
2839EXPORT_SYMBOL_GPL(ata_sff_tf_load);
2840EXPORT_SYMBOL_GPL(ata_sff_tf_read);
2841EXPORT_SYMBOL_GPL(ata_sff_exec_command);
2842EXPORT_SYMBOL_GPL(ata_sff_data_xfer);
2843EXPORT_SYMBOL_GPL(ata_sff_data_xfer_noirq);
2844EXPORT_SYMBOL_GPL(ata_sff_irq_on);
2845EXPORT_SYMBOL_GPL(ata_sff_irq_clear);
2846EXPORT_SYMBOL_GPL(ata_sff_hsm_move);
2847EXPORT_SYMBOL_GPL(ata_sff_qc_issue);
2848EXPORT_SYMBOL_GPL(ata_sff_qc_fill_rtf);
2849EXPORT_SYMBOL_GPL(ata_sff_host_intr);
2850EXPORT_SYMBOL_GPL(ata_sff_interrupt);
2851EXPORT_SYMBOL_GPL(ata_sff_freeze);
2852EXPORT_SYMBOL_GPL(ata_sff_thaw);
2853EXPORT_SYMBOL_GPL(ata_sff_prereset);
2854EXPORT_SYMBOL_GPL(ata_sff_dev_classify);
2855EXPORT_SYMBOL_GPL(ata_sff_wait_after_reset);
2856EXPORT_SYMBOL_GPL(ata_sff_softreset);
2857EXPORT_SYMBOL_GPL(sata_sff_hardreset);
2858EXPORT_SYMBOL_GPL(ata_sff_postreset);
2859EXPORT_SYMBOL_GPL(ata_sff_error_handler);
2860EXPORT_SYMBOL_GPL(ata_sff_post_internal_cmd);
2861EXPORT_SYMBOL_GPL(ata_sff_port_start);
2862EXPORT_SYMBOL_GPL(ata_sff_std_ports);
2863EXPORT_SYMBOL_GPL(ata_bmdma_mode_filter);
2864EXPORT_SYMBOL_GPL(ata_bmdma_setup);
2865EXPORT_SYMBOL_GPL(ata_bmdma_start);
2866EXPORT_SYMBOL_GPL(ata_bmdma_stop);
2867EXPORT_SYMBOL_GPL(ata_bmdma_status);
2868EXPORT_SYMBOL_GPL(ata_bus_reset);
2869#ifdef CONFIG_PCI
2870EXPORT_SYMBOL_GPL(ata_pci_bmdma_clear_simplex);
2871EXPORT_SYMBOL_GPL(ata_pci_bmdma_init);
2872EXPORT_SYMBOL_GPL(ata_pci_sff_init_host);
2873EXPORT_SYMBOL_GPL(ata_pci_sff_prepare_host);
2874EXPORT_SYMBOL_GPL(ata_pci_sff_activate_host);
2875EXPORT_SYMBOL_GPL(ata_pci_sff_init_one);
2876#endif /* CONFIG_PCI */
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 73c466e452ca..a7999c19f0c9 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -19,7 +19,9 @@
19 * 19 *
20 * TODO/CHECK 20 * TODO/CHECK
21 * Cannot have ATAPI on both master & slave for rev < c2 (???) but 21 * Cannot have ATAPI on both master & slave for rev < c2 (???) but
22 * otherwise should do atapi DMA. 22 * otherwise should do atapi DMA (For now for old we do PIO only for
23 * ATAPI)
24 * Review Sunblade workaround.
23 */ 25 */
24 26
25#include <linux/kernel.h> 27#include <linux/kernel.h>
@@ -33,12 +35,14 @@
33#include <linux/dmi.h> 35#include <linux/dmi.h>
34 36
35#define DRV_NAME "pata_ali" 37#define DRV_NAME "pata_ali"
36#define DRV_VERSION "0.7.5" 38#define DRV_VERSION "0.7.8"
37 39
38static int ali_atapi_dma = 0; 40static int ali_atapi_dma = 0;
39module_param_named(atapi_dma, ali_atapi_dma, int, 0644); 41module_param_named(atapi_dma, ali_atapi_dma, int, 0644);
40MODULE_PARM_DESC(atapi_dma, "Enable ATAPI DMA (0=disable, 1=enable)"); 42MODULE_PARM_DESC(atapi_dma, "Enable ATAPI DMA (0=disable, 1=enable)");
41 43
44static struct pci_dev *isa_bridge;
45
42/* 46/*
43 * Cable special cases 47 * Cable special cases
44 */ 48 */
@@ -147,8 +151,7 @@ static void ali_fifo_control(struct ata_port *ap, struct ata_device *adev, int o
147 151
148 pci_read_config_byte(pdev, pio_fifo, &fifo); 152 pci_read_config_byte(pdev, pio_fifo, &fifo);
149 fifo &= ~(0x0F << shift); 153 fifo &= ~(0x0F << shift);
150 if (on) 154 fifo |= (on << shift);
151 fifo |= (on << shift);
152 pci_write_config_byte(pdev, pio_fifo, fifo); 155 pci_write_config_byte(pdev, pio_fifo, fifo);
153} 156}
154 157
@@ -337,6 +340,23 @@ static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
337 return 0; 340 return 0;
338} 341}
339 342
343static void ali_c2_c3_postreset(struct ata_link *link, unsigned int *classes)
344{
345 u8 r;
346 int port_bit = 4 << link->ap->port_no;
347
348 /* If our bridge is an ALI 1533 then do the extra work */
349 if (isa_bridge) {
350 /* Tristate and re-enable the bus signals */
351 pci_read_config_byte(isa_bridge, 0x58, &r);
352 r &= ~port_bit;
353 pci_write_config_byte(isa_bridge, 0x58, r);
354 r |= port_bit;
355 pci_write_config_byte(isa_bridge, 0x58, r);
356 }
357 ata_sff_postreset(link, classes);
358}
359
340static struct scsi_host_template ali_sht = { 360static struct scsi_host_template ali_sht = {
341 ATA_BMDMA_SHT(DRV_NAME), 361 ATA_BMDMA_SHT(DRV_NAME),
342}; 362};
@@ -349,10 +369,11 @@ static struct ata_port_operations ali_early_port_ops = {
349 .inherits = &ata_sff_port_ops, 369 .inherits = &ata_sff_port_ops,
350 .cable_detect = ata_cable_40wire, 370 .cable_detect = ata_cable_40wire,
351 .set_piomode = ali_set_piomode, 371 .set_piomode = ali_set_piomode,
372 .sff_data_xfer = ata_sff_data_xfer32,
352}; 373};
353 374
354static const struct ata_port_operations ali_dma_base_ops = { 375static const struct ata_port_operations ali_dma_base_ops = {
355 .inherits = &ata_bmdma_port_ops, 376 .inherits = &ata_bmdma32_port_ops,
356 .set_piomode = ali_set_piomode, 377 .set_piomode = ali_set_piomode,
357 .set_dmamode = ali_set_dmamode, 378 .set_dmamode = ali_set_dmamode,
358}; 379};
@@ -377,6 +398,17 @@ static struct ata_port_operations ali_c2_port_ops = {
377 .check_atapi_dma = ali_check_atapi_dma, 398 .check_atapi_dma = ali_check_atapi_dma,
378 .cable_detect = ali_c2_cable_detect, 399 .cable_detect = ali_c2_cable_detect,
379 .dev_config = ali_lock_sectors, 400 .dev_config = ali_lock_sectors,
401 .postreset = ali_c2_c3_postreset,
402};
403
404/*
405 * Port operations for DMA capable ALi with cable detect
406 */
407static struct ata_port_operations ali_c4_port_ops = {
408 .inherits = &ali_dma_base_ops,
409 .check_atapi_dma = ali_check_atapi_dma,
410 .cable_detect = ali_c2_cable_detect,
411 .dev_config = ali_lock_sectors,
380}; 412};
381 413
382/* 414/*
@@ -401,52 +433,49 @@ static struct ata_port_operations ali_c5_port_ops = {
401static void ali_init_chipset(struct pci_dev *pdev) 433static void ali_init_chipset(struct pci_dev *pdev)
402{ 434{
403 u8 tmp; 435 u8 tmp;
404 struct pci_dev *north, *isa_bridge; 436 struct pci_dev *north;
405 437
406 /* 438 /*
407 * The chipset revision selects the driver operations and 439 * The chipset revision selects the driver operations and
408 * mode data. 440 * mode data.
409 */ 441 */
410 442
411 if (pdev->revision >= 0x20 && pdev->revision < 0xC2) { 443 if (pdev->revision <= 0x20) {
412 /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */ 444 pci_read_config_byte(pdev, 0x53, &tmp);
413 pci_read_config_byte(pdev, 0x4B, &tmp); 445 tmp |= 0x03;
414 /* Clear CD-ROM DMA write bit */ 446 pci_write_config_byte(pdev, 0x53, tmp);
415 tmp &= 0x7F; 447 } else {
416 pci_write_config_byte(pdev, 0x4B, tmp); 448 pci_read_config_byte(pdev, 0x4a, &tmp);
417 } else if (pdev->revision >= 0xC2) { 449 pci_write_config_byte(pdev, 0x4a, tmp | 0x20);
418 /* Enable cable detection logic */
419 pci_read_config_byte(pdev, 0x4B, &tmp); 450 pci_read_config_byte(pdev, 0x4B, &tmp);
420 pci_write_config_byte(pdev, 0x4B, tmp | 0x08); 451 if (pdev->revision < 0xC2)
421 } 452 /* 1543-E/F, 1543C-C, 1543C-D, 1543C-E */
422 north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0)); 453 /* Clear CD-ROM DMA write bit */
423 isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 454 tmp &= 0x7F;
424 455 /* Cable and UDMA */
425 if (north && north->vendor == PCI_VENDOR_ID_AL && isa_bridge) { 456 pci_write_config_byte(pdev, 0x4B, tmp | 0x09);
426 /* Configure the ALi bridge logic. For non ALi rely on BIOS.
427 Set the south bridge enable bit */
428 pci_read_config_byte(isa_bridge, 0x79, &tmp);
429 if (pdev->revision == 0xC2)
430 pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
431 else if (pdev->revision > 0xC2 && pdev->revision < 0xC5)
432 pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
433 }
434 if (pdev->revision >= 0x20) {
435 /* 457 /*
436 * CD_ROM DMA on (0x53 bit 0). Enable this even if we want 458 * CD_ROM DMA on (0x53 bit 0). Enable this even if we want
437 * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control 459 * to use PIO. 0x53 bit 1 (rev 20 only) - enable FIFO control
438 * via 0x54/55. 460 * via 0x54/55.
439 */ 461 */
440 pci_read_config_byte(pdev, 0x53, &tmp); 462 pci_read_config_byte(pdev, 0x53, &tmp);
441 if (pdev->revision <= 0x20)
442 tmp &= ~0x02;
443 if (pdev->revision >= 0xc7) 463 if (pdev->revision >= 0xc7)
444 tmp |= 0x03; 464 tmp |= 0x03;
445 else 465 else
446 tmp |= 0x01; /* CD_ROM enable for DMA */ 466 tmp |= 0x01; /* CD_ROM enable for DMA */
447 pci_write_config_byte(pdev, 0x53, tmp); 467 pci_write_config_byte(pdev, 0x53, tmp);
448 } 468 }
449 pci_dev_put(isa_bridge); 469 north = pci_get_bus_and_slot(0, PCI_DEVFN(0,0));
470 if (north && north->vendor == PCI_VENDOR_ID_AL && isa_bridge) {
471 /* Configure the ALi bridge logic. For non ALi rely on BIOS.
472 Set the south bridge enable bit */
473 pci_read_config_byte(isa_bridge, 0x79, &tmp);
474 if (pdev->revision == 0xC2)
475 pci_write_config_byte(isa_bridge, 0x79, tmp | 0x04);
476 else if (pdev->revision > 0xC2 && pdev->revision < 0xC5)
477 pci_write_config_byte(isa_bridge, 0x79, tmp | 0x02);
478 }
450 pci_dev_put(north); 479 pci_dev_put(north);
451 ata_pci_bmdma_clear_simplex(pdev); 480 ata_pci_bmdma_clear_simplex(pdev);
452} 481}
@@ -503,7 +532,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
503 .pio_mask = 0x1f, 532 .pio_mask = 0x1f,
504 .mwdma_mask = 0x07, 533 .mwdma_mask = 0x07,
505 .udma_mask = ATA_UDMA5, 534 .udma_mask = ATA_UDMA5,
506 .port_ops = &ali_c2_port_ops 535 .port_ops = &ali_c4_port_ops
507 }; 536 };
508 /* Revision 0xC5 is UDMA133 with LBA48 DMA */ 537 /* Revision 0xC5 is UDMA133 with LBA48 DMA */
509 static const struct ata_port_info info_c5 = { 538 static const struct ata_port_info info_c5 = {
@@ -516,7 +545,6 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
516 545
517 const struct ata_port_info *ppi[] = { NULL, NULL }; 546 const struct ata_port_info *ppi[] = { NULL, NULL };
518 u8 tmp; 547 u8 tmp;
519 struct pci_dev *isa_bridge;
520 int rc; 548 int rc;
521 549
522 rc = pcim_enable_device(pdev); 550 rc = pcim_enable_device(pdev);
@@ -543,14 +571,12 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
543 571
544 ali_init_chipset(pdev); 572 ali_init_chipset(pdev);
545 573
546 isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
547 if (isa_bridge && pdev->revision >= 0x20 && pdev->revision < 0xC2) { 574 if (isa_bridge && pdev->revision >= 0x20 && pdev->revision < 0xC2) {
548 /* Are we paired with a UDMA capable chip */ 575 /* Are we paired with a UDMA capable chip */
549 pci_read_config_byte(isa_bridge, 0x5E, &tmp); 576 pci_read_config_byte(isa_bridge, 0x5E, &tmp);
550 if ((tmp & 0x1E) == 0x12) 577 if ((tmp & 0x1E) == 0x12)
551 ppi[0] = &info_20_udma; 578 ppi[0] = &info_20_udma;
552 } 579 }
553 pci_dev_put(isa_bridge);
554 580
555 return ata_pci_sff_init_one(pdev, ppi, &ali_sht, NULL); 581 return ata_pci_sff_init_one(pdev, ppi, &ali_sht, NULL);
556} 582}
@@ -590,13 +616,20 @@ static struct pci_driver ali_pci_driver = {
590 616
591static int __init ali_init(void) 617static int __init ali_init(void)
592{ 618{
593 return pci_register_driver(&ali_pci_driver); 619 int ret;
620 isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
621
622 ret = pci_register_driver(&ali_pci_driver);
623 if (ret < 0)
624 pci_dev_put(isa_bridge);
625 return ret;
594} 626}
595 627
596 628
597static void __exit ali_exit(void) 629static void __exit ali_exit(void)
598{ 630{
599 pci_unregister_driver(&ali_pci_driver); 631 pci_unregister_driver(&ali_pci_driver);
632 pci_dev_put(isa_bridge);
600} 633}
601 634
602 635
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 0ec9c7d9fe9d..63719ab9ea44 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -24,7 +24,7 @@
24#include <linux/libata.h> 24#include <linux/libata.h>
25 25
26#define DRV_NAME "pata_amd" 26#define DRV_NAME "pata_amd"
27#define DRV_VERSION "0.3.10" 27#define DRV_VERSION "0.3.11"
28 28
29/** 29/**
30 * timing_setup - shared timing computation and load 30 * timing_setup - shared timing computation and load
@@ -345,7 +345,7 @@ static struct scsi_host_template amd_sht = {
345}; 345};
346 346
347static const struct ata_port_operations amd_base_port_ops = { 347static const struct ata_port_operations amd_base_port_ops = {
348 .inherits = &ata_bmdma_port_ops, 348 .inherits = &ata_bmdma32_port_ops,
349 .prereset = amd_pre_reset, 349 .prereset = amd_pre_reset,
350}; 350};
351 351
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index 1266924c11f9..1050fed96b2b 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -356,7 +356,6 @@ static void bfin_set_piomode(struct ata_port *ap, struct ata_device *adev)
356 * bfin_set_dmamode - Initialize host controller PATA DMA timings 356 * bfin_set_dmamode - Initialize host controller PATA DMA timings
357 * @ap: Port whose timings we are configuring 357 * @ap: Port whose timings we are configuring
358 * @adev: um 358 * @adev: um
359 * @udma: udma mode, 0 - 6
360 * 359 *
361 * Set UDMA mode for device. 360 * Set UDMA mode for device.
362 * 361 *
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index e0c4f05d7d57..65c28e5a6cd7 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -30,7 +30,7 @@
30#define DRV_VERSION "0.6.2" 30#define DRV_VERSION "0.6.2"
31 31
32struct hpt_clock { 32struct hpt_clock {
33 u8 xfer_speed; 33 u8 xfer_mode;
34 u32 timing; 34 u32 timing;
35}; 35};
36 36
@@ -189,28 +189,6 @@ static unsigned long hpt366_filter(struct ata_device *adev, unsigned long mask)
189 return ata_bmdma_mode_filter(adev, mask); 189 return ata_bmdma_mode_filter(adev, mask);
190} 190}
191 191
192/**
193 * hpt36x_find_mode - reset the hpt36x bus
194 * @ap: ATA port
195 * @speed: transfer mode
196 *
197 * Return the 32bit register programming information for this channel
198 * that matches the speed provided.
199 */
200
201static u32 hpt36x_find_mode(struct ata_port *ap, int speed)
202{
203 struct hpt_clock *clocks = ap->host->private_data;
204
205 while(clocks->xfer_speed) {
206 if (clocks->xfer_speed == speed)
207 return clocks->timing;
208 clocks++;
209 }
210 BUG();
211 return 0xffffffffU; /* silence compiler warning */
212}
213
214static int hpt36x_cable_detect(struct ata_port *ap) 192static int hpt36x_cable_detect(struct ata_port *ap)
215{ 193{
216 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 194 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -226,25 +204,16 @@ static int hpt36x_cable_detect(struct ata_port *ap)
226 return ATA_CBL_PATA80; 204 return ATA_CBL_PATA80;
227} 205}
228 206
229/** 207static void hpt366_set_mode(struct ata_port *ap, struct ata_device *adev,
230 * hpt366_set_piomode - PIO setup 208 u8 mode)
231 * @ap: ATA interface
232 * @adev: device on the interface
233 *
234 * Perform PIO mode setup.
235 */
236
237static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
238{ 209{
210 struct hpt_clock *clocks = ap->host->private_data;
239 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 211 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
240 u32 addr1, addr2; 212 u32 addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
241 u32 reg; 213 u32 addr2 = 0x51 + 4 * ap->port_no;
242 u32 mode; 214 u32 mask, reg;
243 u8 fast; 215 u8 fast;
244 216
245 addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
246 addr2 = 0x51 + 4 * ap->port_no;
247
248 /* Fast interrupt prediction disable, hold off interrupt disable */ 217 /* Fast interrupt prediction disable, hold off interrupt disable */
249 pci_read_config_byte(pdev, addr2, &fast); 218 pci_read_config_byte(pdev, addr2, &fast);
250 if (fast & 0x80) { 219 if (fast & 0x80) {
@@ -252,12 +221,43 @@ static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
252 pci_write_config_byte(pdev, addr2, fast); 221 pci_write_config_byte(pdev, addr2, fast);
253 } 222 }
254 223
224 /* determine timing mask and find matching clock entry */
225 if (mode < XFER_MW_DMA_0)
226 mask = 0xc1f8ffff;
227 else if (mode < XFER_UDMA_0)
228 mask = 0x303800ff;
229 else
230 mask = 0x30070000;
231
232 while (clocks->xfer_mode) {
233 if (clocks->xfer_mode == mode)
234 break;
235 clocks++;
236 }
237 if (!clocks->xfer_mode)
238 BUG();
239
240 /*
241 * Combine new mode bits with old config bits and disable
242 * on-chip PIO FIFO/buffer (and PIO MST mode as well) to avoid
243 * problems handling I/O errors later.
244 */
255 pci_read_config_dword(pdev, addr1, &reg); 245 pci_read_config_dword(pdev, addr1, &reg);
256 mode = hpt36x_find_mode(ap, adev->pio_mode); 246 reg = ((reg & ~mask) | (clocks->timing & mask)) & ~0xc0000000;
257 mode &= ~0x8000000; /* No FIFO in PIO */ 247 pci_write_config_dword(pdev, addr1, reg);
258 mode &= ~0x30070000; /* Leave config bits alone */ 248}
259 reg &= 0x30070000; /* Strip timing bits */ 249
260 pci_write_config_dword(pdev, addr1, reg | mode); 250/**
251 * hpt366_set_piomode - PIO setup
252 * @ap: ATA interface
253 * @adev: device on the interface
254 *
255 * Perform PIO mode setup.
256 */
257
258static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
259{
260 hpt366_set_mode(ap, adev, adev->pio_mode);
261} 261}
262 262
263/** 263/**
@@ -271,28 +271,7 @@ static void hpt366_set_piomode(struct ata_port *ap, struct ata_device *adev)
271 271
272static void hpt366_set_dmamode(struct ata_port *ap, struct ata_device *adev) 272static void hpt366_set_dmamode(struct ata_port *ap, struct ata_device *adev)
273{ 273{
274 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 274 hpt366_set_mode(ap, adev, adev->dma_mode);
275 u32 addr1, addr2;
276 u32 reg;
277 u32 mode;
278 u8 fast;
279
280 addr1 = 0x40 + 4 * (adev->devno + 2 * ap->port_no);
281 addr2 = 0x51 + 4 * ap->port_no;
282
283 /* Fast interrupt prediction disable, hold off interrupt disable */
284 pci_read_config_byte(pdev, addr2, &fast);
285 if (fast & 0x80) {
286 fast &= ~0x80;
287 pci_write_config_byte(pdev, addr2, fast);
288 }
289
290 pci_read_config_dword(pdev, addr1, &reg);
291 mode = hpt36x_find_mode(ap, adev->dma_mode);
292 mode |= 0x8000000; /* FIFO in MWDMA or UDMA */
293 mode &= ~0xC0000000; /* Leave config bits alone */
294 reg &= 0xC0000000; /* Strip timing bits */
295 pci_write_config_dword(pdev, addr1, reg | mode);
296} 275}
297 276
298static struct scsi_host_template hpt36x_sht = { 277static struct scsi_host_template hpt36x_sht = {
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index f11a320337c0..f19cc645881a 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -23,7 +23,7 @@
23#include <linux/libata.h> 23#include <linux/libata.h>
24 24
25#define DRV_NAME "pata_hpt3x3" 25#define DRV_NAME "pata_hpt3x3"
26#define DRV_VERSION "0.5.3" 26#define DRV_VERSION "0.6.1"
27 27
28/** 28/**
29 * hpt3x3_set_piomode - PIO setup 29 * hpt3x3_set_piomode - PIO setup
@@ -80,14 +80,48 @@ static void hpt3x3_set_dmamode(struct ata_port *ap, struct ata_device *adev)
80 r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */ 80 r2 &= ~(0x11 << dn); /* Clear MWDMA and UDMA bits */
81 81
82 if (adev->dma_mode >= XFER_UDMA_0) 82 if (adev->dma_mode >= XFER_UDMA_0)
83 r2 |= (0x10 << dn); /* Ultra mode */ 83 r2 |= (0x01 << dn); /* Ultra mode */
84 else 84 else
85 r2 |= (0x01 << dn); /* MWDMA */ 85 r2 |= (0x10 << dn); /* MWDMA */
86 86
87 pci_write_config_dword(pdev, 0x44, r1); 87 pci_write_config_dword(pdev, 0x44, r1);
88 pci_write_config_dword(pdev, 0x48, r2); 88 pci_write_config_dword(pdev, 0x48, r2);
89} 89}
90#endif /* CONFIG_PATA_HPT3X3_DMA */ 90
91/**
92 * hpt3x3_freeze - DMA workaround
93 * @ap: port to freeze
94 *
95 * When freezing an HPT3x3 we must stop any pending DMA before
96 * writing to the control register or the chip will hang
97 */
98
99static void hpt3x3_freeze(struct ata_port *ap)
100{
101 void __iomem *mmio = ap->ioaddr.bmdma_addr;
102
103 iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ ATA_DMA_START,
104 mmio + ATA_DMA_CMD);
105 ata_sff_dma_pause(ap);
106 ata_sff_freeze(ap);
107}
108
109/**
110 * hpt3x3_bmdma_setup - DMA workaround
111 * @qc: Queued command
112 *
113 * When issuing BMDMA we must clean up the error/active bits in
114 * software on this device
115 */
116
117static void hpt3x3_bmdma_setup(struct ata_queued_cmd *qc)
118{
119 struct ata_port *ap = qc->ap;
120 u8 r = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
121 r |= ATA_DMA_INTR | ATA_DMA_ERR;
122 iowrite8(r, ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
123 return ata_bmdma_setup(qc);
124}
91 125
92/** 126/**
93 * hpt3x3_atapi_dma - ATAPI DMA check 127 * hpt3x3_atapi_dma - ATAPI DMA check
@@ -101,18 +135,23 @@ static int hpt3x3_atapi_dma(struct ata_queued_cmd *qc)
101 return 1; 135 return 1;
102} 136}
103 137
138#endif /* CONFIG_PATA_HPT3X3_DMA */
139
104static struct scsi_host_template hpt3x3_sht = { 140static struct scsi_host_template hpt3x3_sht = {
105 ATA_BMDMA_SHT(DRV_NAME), 141 ATA_BMDMA_SHT(DRV_NAME),
106}; 142};
107 143
108static struct ata_port_operations hpt3x3_port_ops = { 144static struct ata_port_operations hpt3x3_port_ops = {
109 .inherits = &ata_bmdma_port_ops, 145 .inherits = &ata_bmdma_port_ops,
110 .check_atapi_dma= hpt3x3_atapi_dma,
111 .cable_detect = ata_cable_40wire, 146 .cable_detect = ata_cable_40wire,
112 .set_piomode = hpt3x3_set_piomode, 147 .set_piomode = hpt3x3_set_piomode,
113#if defined(CONFIG_PATA_HPT3X3_DMA) 148#if defined(CONFIG_PATA_HPT3X3_DMA)
114 .set_dmamode = hpt3x3_set_dmamode, 149 .set_dmamode = hpt3x3_set_dmamode,
150 .bmdma_setup = hpt3x3_bmdma_setup,
151 .check_atapi_dma= hpt3x3_atapi_dma,
152 .freeze = hpt3x3_freeze,
115#endif 153#endif
154
116}; 155};
117 156
118/** 157/**
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index 860ede526282..f828a29d7756 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -465,24 +465,22 @@ static int it821x_smart_set_mode(struct ata_link *link, struct ata_device **unus
465{ 465{
466 struct ata_device *dev; 466 struct ata_device *dev;
467 467
468 ata_link_for_each_dev(dev, link) { 468 ata_for_each_dev(dev, link, ENABLED) {
469 if (ata_dev_enabled(dev)) { 469 /* We don't really care */
470 /* We don't really care */ 470 dev->pio_mode = XFER_PIO_0;
471 dev->pio_mode = XFER_PIO_0; 471 dev->dma_mode = XFER_MW_DMA_0;
472 dev->dma_mode = XFER_MW_DMA_0; 472 /* We do need the right mode information for DMA or PIO
473 /* We do need the right mode information for DMA or PIO 473 and this comes from the current configuration flags */
474 and this comes from the current configuration flags */ 474 if (ata_id_has_dma(dev->id)) {
475 if (ata_id_has_dma(dev->id)) { 475 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
476 ata_dev_printk(dev, KERN_INFO, "configured for DMA\n"); 476 dev->xfer_mode = XFER_MW_DMA_0;
477 dev->xfer_mode = XFER_MW_DMA_0; 477 dev->xfer_shift = ATA_SHIFT_MWDMA;
478 dev->xfer_shift = ATA_SHIFT_MWDMA; 478 dev->flags &= ~ATA_DFLAG_PIO;
479 dev->flags &= ~ATA_DFLAG_PIO; 479 } else {
480 } else { 480 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
481 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n"); 481 dev->xfer_mode = XFER_PIO_0;
482 dev->xfer_mode = XFER_PIO_0; 482 dev->xfer_shift = ATA_SHIFT_PIO;
483 dev->xfer_shift = ATA_SHIFT_PIO; 483 dev->flags |= ATA_DFLAG_PIO;
484 dev->flags |= ATA_DFLAG_PIO;
485 }
486 } 484 }
487 } 485 }
488 return 0; 486 return 0;
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 2014253f6c88..b173c157ab00 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -30,14 +30,12 @@ static int ixp4xx_set_mode(struct ata_link *link, struct ata_device **error)
30{ 30{
31 struct ata_device *dev; 31 struct ata_device *dev;
32 32
33 ata_link_for_each_dev(dev, link) { 33 ata_for_each_dev(dev, link, ENABLED) {
34 if (ata_dev_enabled(dev)) { 34 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
35 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n"); 35 dev->pio_mode = XFER_PIO_0;
36 dev->pio_mode = XFER_PIO_0; 36 dev->xfer_mode = XFER_PIO_0;
37 dev->xfer_mode = XFER_PIO_0; 37 dev->xfer_shift = ATA_SHIFT_PIO;
38 dev->xfer_shift = ATA_SHIFT_PIO; 38 dev->flags |= ATA_DFLAG_PIO;
39 dev->flags |= ATA_DFLAG_PIO;
40 }
41 } 39 }
42 return 0; 40 return 0;
43} 41}
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 930c2208640b..6c1d778b63a9 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -194,15 +194,12 @@ static int legacy_set_mode(struct ata_link *link, struct ata_device **unused)
194{ 194{
195 struct ata_device *dev; 195 struct ata_device *dev;
196 196
197 ata_link_for_each_dev(dev, link) { 197 ata_for_each_dev(dev, link, ENABLED) {
198 if (ata_dev_enabled(dev)) { 198 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
199 ata_dev_printk(dev, KERN_INFO, 199 dev->pio_mode = XFER_PIO_0;
200 "configured for PIO\n"); 200 dev->xfer_mode = XFER_PIO_0;
201 dev->pio_mode = XFER_PIO_0; 201 dev->xfer_shift = ATA_SHIFT_PIO;
202 dev->xfer_mode = XFER_PIO_0; 202 dev->flags |= ATA_DFLAG_PIO;
203 dev->xfer_shift = ATA_SHIFT_PIO;
204 dev->flags |= ATA_DFLAG_PIO;
205 }
206 } 203 }
207 return 0; 204 return 0;
208} 205}
@@ -641,7 +638,6 @@ static void qdi6500_set_piomode(struct ata_port *ap, struct ata_device *adev)
641 * qdi6580dp_set_piomode - PIO setup for dual channel 638 * qdi6580dp_set_piomode - PIO setup for dual channel
642 * @ap: Port 639 * @ap: Port
643 * @adev: Device 640 * @adev: Device
644 * @irq: interrupt line
645 * 641 *
646 * In dual channel mode the 6580 has one clock per channel and we have 642 * In dual channel mode the 6580 has one clock per channel and we have
647 * to software clockswitch in qc_issue. 643 * to software clockswitch in qc_issue.
@@ -1028,7 +1024,7 @@ static __init int legacy_init_one(struct legacy_probe *probe)
1028 /* Nothing found means we drop the port as its probably not there */ 1024 /* Nothing found means we drop the port as its probably not there */
1029 1025
1030 ret = -ENODEV; 1026 ret = -ENODEV;
1031 ata_link_for_each_dev(dev, &ap->link) { 1027 ata_for_each_dev(dev, &ap->link, ALL) {
1032 if (!ata_dev_absent(dev)) { 1028 if (!ata_dev_absent(dev)) {
1033 legacy_host[probe->slot] = host; 1029 legacy_host[probe->slot] = host;
1034 ld->platform_dev = pdev; 1030 ld->platform_dev = pdev;
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index a9e827356d06..50ae6d13078a 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -6,6 +6,9 @@
6 * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com> 6 * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
7 * Copyright (C) 2003 Mipsys - Benjamin Herrenschmidt 7 * Copyright (C) 2003 Mipsys - Benjamin Herrenschmidt
8 * 8 *
9 * UDMA support based on patches by Freescale (Bernard Kuhn, John Rigby),
10 * Domen Puncer and Tim Yamin.
11 *
9 * This file is licensed under the terms of the GNU General Public License 12 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any 13 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied. 14 * kind, whether express or implied.
@@ -17,28 +20,46 @@
17#include <linux/delay.h> 20#include <linux/delay.h>
18#include <linux/libata.h> 21#include <linux/libata.h>
19#include <linux/of_platform.h> 22#include <linux/of_platform.h>
23#include <linux/types.h>
20 24
21#include <asm/types.h> 25#include <asm/cacheflush.h>
22#include <asm/prom.h> 26#include <asm/prom.h>
23#include <asm/mpc52xx.h> 27#include <asm/mpc52xx.h>
24 28
29#include <sysdev/bestcomm/bestcomm.h>
30#include <sysdev/bestcomm/bestcomm_priv.h>
31#include <sysdev/bestcomm/ata.h>
25 32
26#define DRV_NAME "mpc52xx_ata" 33#define DRV_NAME "mpc52xx_ata"
27#define DRV_VERSION "0.1.2"
28
29 34
30/* Private structures used by the driver */ 35/* Private structures used by the driver */
31struct mpc52xx_ata_timings { 36struct mpc52xx_ata_timings {
32 u32 pio1; 37 u32 pio1;
33 u32 pio2; 38 u32 pio2;
39 u32 mdma1;
40 u32 mdma2;
41 u32 udma1;
42 u32 udma2;
43 u32 udma3;
44 u32 udma4;
45 u32 udma5;
46 int using_udma;
34}; 47};
35 48
36struct mpc52xx_ata_priv { 49struct mpc52xx_ata_priv {
37 unsigned int ipb_period; 50 unsigned int ipb_period;
38 struct mpc52xx_ata __iomem * ata_regs; 51 struct mpc52xx_ata __iomem *ata_regs;
52 phys_addr_t ata_regs_pa;
39 int ata_irq; 53 int ata_irq;
40 struct mpc52xx_ata_timings timings[2]; 54 struct mpc52xx_ata_timings timings[2];
41 int csel; 55 int csel;
56
57 /* DMA */
58 struct bcom_task *dmatsk;
59 const struct udmaspec *udmaspec;
60 const struct mdmaspec *mdmaspec;
61 int mpc52xx_ata_dma_last_write;
62 int waiting_for_dma;
42}; 63};
43 64
44 65
@@ -53,6 +74,107 @@ static const int ataspec_ta[5] = { 35, 35, 35, 35, 35};
53 74
54#define CALC_CLKCYC(c,v) ((((v)+(c)-1)/(c))) 75#define CALC_CLKCYC(c,v) ((((v)+(c)-1)/(c)))
55 76
77/* ======================================================================== */
78
79/* ATAPI-4 MDMA specs (in clocks) */
80struct mdmaspec {
81 u32 t0M;
82 u32 td;
83 u32 th;
84 u32 tj;
85 u32 tkw;
86 u32 tm;
87 u32 tn;
88};
89
90static const struct mdmaspec mdmaspec66[3] = {
91 { .t0M = 32, .td = 15, .th = 2, .tj = 2, .tkw = 15, .tm = 4, .tn = 1 },
92 { .t0M = 10, .td = 6, .th = 1, .tj = 1, .tkw = 4, .tm = 2, .tn = 1 },
93 { .t0M = 8, .td = 5, .th = 1, .tj = 1, .tkw = 2, .tm = 2, .tn = 1 },
94};
95
96static const struct mdmaspec mdmaspec132[3] = {
97 { .t0M = 64, .td = 29, .th = 3, .tj = 3, .tkw = 29, .tm = 7, .tn = 2 },
98 { .t0M = 20, .td = 11, .th = 2, .tj = 1, .tkw = 7, .tm = 4, .tn = 1 },
99 { .t0M = 16, .td = 10, .th = 2, .tj = 1, .tkw = 4, .tm = 4, .tn = 1 },
100};
101
102/* ATAPI-4 UDMA specs (in clocks) */
103struct udmaspec {
104 u32 tcyc;
105 u32 t2cyc;
106 u32 tds;
107 u32 tdh;
108 u32 tdvs;
109 u32 tdvh;
110 u32 tfs;
111 u32 tli;
112 u32 tmli;
113 u32 taz;
114 u32 tzah;
115 u32 tenv;
116 u32 tsr;
117 u32 trfs;
118 u32 trp;
119 u32 tack;
120 u32 tss;
121};
122
123static const struct udmaspec udmaspec66[6] = {
124 { .tcyc = 8, .t2cyc = 16, .tds = 1, .tdh = 1, .tdvs = 5, .tdvh = 1,
125 .tfs = 16, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
126 .tsr = 3, .trfs = 5, .trp = 11, .tack = 2, .tss = 4,
127 },
128 { .tcyc = 5, .t2cyc = 11, .tds = 1, .tdh = 1, .tdvs = 4, .tdvh = 1,
129 .tfs = 14, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
130 .tsr = 2, .trfs = 5, .trp = 9, .tack = 2, .tss = 4,
131 },
132 { .tcyc = 4, .t2cyc = 8, .tds = 1, .tdh = 1, .tdvs = 3, .tdvh = 1,
133 .tfs = 12, .tli = 10, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
134 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
135 },
136 { .tcyc = 3, .t2cyc = 6, .tds = 1, .tdh = 1, .tdvs = 2, .tdvh = 1,
137 .tfs = 9, .tli = 7, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
138 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
139 },
140 { .tcyc = 2, .t2cyc = 4, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
141 .tfs = 8, .tli = 8, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
142 .tsr = 2, .trfs = 4, .trp = 7, .tack = 2, .tss = 4,
143 },
144 { .tcyc = 2, .t2cyc = 2, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
145 .tfs = 6, .tli = 5, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
146 .tsr = 2, .trfs = 4, .trp = 6, .tack = 2, .tss = 4,
147 },
148};
149
150static const struct udmaspec udmaspec132[6] = {
151 { .tcyc = 15, .t2cyc = 31, .tds = 2, .tdh = 1, .tdvs = 10, .tdvh = 1,
152 .tfs = 30, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
153 .tsr = 7, .trfs = 10, .trp = 22, .tack = 3, .tss = 7,
154 },
155 { .tcyc = 10, .t2cyc = 21, .tds = 2, .tdh = 1, .tdvs = 7, .tdvh = 1,
156 .tfs = 27, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
157 .tsr = 4, .trfs = 10, .trp = 17, .tack = 3, .tss = 7,
158 },
159 { .tcyc = 6, .t2cyc = 12, .tds = 1, .tdh = 1, .tdvs = 5, .tdvh = 1,
160 .tfs = 23, .tli = 20, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
161 .tsr = 3, .trfs = 8, .trp = 14, .tack = 3, .tss = 7,
162 },
163 { .tcyc = 7, .t2cyc = 12, .tds = 1, .tdh = 1, .tdvs = 3, .tdvh = 1,
164 .tfs = 15, .tli = 13, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
165 .tsr = 3, .trfs = 8, .trp = 14, .tack = 3, .tss = 7,
166 },
167 { .tcyc = 2, .t2cyc = 5, .tds = 0, .tdh = 0, .tdvs = 1, .tdvh = 1,
168 .tfs = 16, .tli = 14, .tmli = 2, .taz = 1, .tzah = 2, .tenv = 2,
169 .tsr = 2, .trfs = 7, .trp = 13, .tack = 2, .tss = 6,
170 },
171 { .tcyc = 3, .t2cyc = 6, .tds = 1, .tdh = 1, .tdvs = 1, .tdvh = 1,
172 .tfs = 12, .tli = 10, .tmli = 3, .taz = 2, .tzah = 3, .tenv = 3,
173 .tsr = 3, .trfs = 7, .trp = 12, .tack = 3, .tss = 7,
174 },
175};
176
177/* ======================================================================== */
56 178
57/* Bit definitions inside the registers */ 179/* Bit definitions inside the registers */
58#define MPC52xx_ATA_HOSTCONF_SMR 0x80000000UL /* State machine reset */ 180#define MPC52xx_ATA_HOSTCONF_SMR 0x80000000UL /* State machine reset */
@@ -66,6 +188,7 @@ static const int ataspec_ta[5] = { 35, 35, 35, 35, 35};
66#define MPC52xx_ATA_HOSTSTAT_WERR 0x01000000UL /* Write Error */ 188#define MPC52xx_ATA_HOSTSTAT_WERR 0x01000000UL /* Write Error */
67 189
68#define MPC52xx_ATA_FIFOSTAT_EMPTY 0x01 /* FIFO Empty */ 190#define MPC52xx_ATA_FIFOSTAT_EMPTY 0x01 /* FIFO Empty */
191#define MPC52xx_ATA_FIFOSTAT_ERROR 0x40 /* FIFO Error */
69 192
70#define MPC52xx_ATA_DMAMODE_WRITE 0x01 /* Write DMA */ 193#define MPC52xx_ATA_DMAMODE_WRITE 0x01 /* Write DMA */
71#define MPC52xx_ATA_DMAMODE_READ 0x02 /* Read DMA */ 194#define MPC52xx_ATA_DMAMODE_READ 0x02 /* Read DMA */
@@ -75,6 +198,8 @@ static const int ataspec_ta[5] = { 35, 35, 35, 35, 35};
75#define MPC52xx_ATA_DMAMODE_FR 0x20 /* FIFO Reset */ 198#define MPC52xx_ATA_DMAMODE_FR 0x20 /* FIFO Reset */
76#define MPC52xx_ATA_DMAMODE_HUT 0x40 /* Host UDMA burst terminate */ 199#define MPC52xx_ATA_DMAMODE_HUT 0x40 /* Host UDMA burst terminate */
77 200
201#define MAX_DMA_BUFFERS 128
202#define MAX_DMA_BUFFER_SIZE 0x20000u
78 203
79/* Structure of the hardware registers */ 204/* Structure of the hardware registers */
80struct mpc52xx_ata { 205struct mpc52xx_ata {
@@ -140,7 +265,6 @@ struct mpc52xx_ata {
140 265
141 266
142/* MPC52xx low level hw control */ 267/* MPC52xx low level hw control */
143
144static int 268static int
145mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio) 269mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio)
146{ 270{
@@ -148,7 +272,7 @@ mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio)
148 unsigned int ipb_period = priv->ipb_period; 272 unsigned int ipb_period = priv->ipb_period;
149 unsigned int t0, t1, t2_8, t2_16, t2i, t4, ta; 273 unsigned int t0, t1, t2_8, t2_16, t2i, t4, ta;
150 274
151 if ((pio<0) || (pio>4)) 275 if ((pio < 0) || (pio > 4))
152 return -EINVAL; 276 return -EINVAL;
153 277
154 t0 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t0[pio]); 278 t0 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t0[pio]);
@@ -165,6 +289,43 @@ mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio)
165 return 0; 289 return 0;
166} 290}
167 291
292static int
293mpc52xx_ata_compute_mdma_timings(struct mpc52xx_ata_priv *priv, int dev,
294 int speed)
295{
296 struct mpc52xx_ata_timings *t = &priv->timings[dev];
297 const struct mdmaspec *s = &priv->mdmaspec[speed];
298
299 if (speed < 0 || speed > 2)
300 return -EINVAL;
301
302 t->mdma1 = (s->t0M << 24) | (s->td << 16) | (s->tkw << 8) | (s->tm);
303 t->mdma2 = (s->th << 24) | (s->tj << 16) | (s->tn << 8);
304 t->using_udma = 0;
305
306 return 0;
307}
308
309static int
310mpc52xx_ata_compute_udma_timings(struct mpc52xx_ata_priv *priv, int dev,
311 int speed)
312{
313 struct mpc52xx_ata_timings *t = &priv->timings[dev];
314 const struct udmaspec *s = &priv->udmaspec[speed];
315
316 if (speed < 0 || speed > 2)
317 return -EINVAL;
318
319 t->udma1 = (s->t2cyc << 24) | (s->tcyc << 16) | (s->tds << 8) | s->tdh;
320 t->udma2 = (s->tdvs << 24) | (s->tdvh << 16) | (s->tfs << 8) | s->tli;
321 t->udma3 = (s->tmli << 24) | (s->taz << 16) | (s->tenv << 8) | s->tsr;
322 t->udma4 = (s->tss << 24) | (s->trfs << 16) | (s->trp << 8) | s->tack;
323 t->udma5 = (s->tzah << 24);
324 t->using_udma = 1;
325
326 return 0;
327}
328
168static void 329static void
169mpc52xx_ata_apply_timings(struct mpc52xx_ata_priv *priv, int device) 330mpc52xx_ata_apply_timings(struct mpc52xx_ata_priv *priv, int device)
170{ 331{
@@ -173,14 +334,13 @@ mpc52xx_ata_apply_timings(struct mpc52xx_ata_priv *priv, int device)
173 334
174 out_be32(&regs->pio1, timing->pio1); 335 out_be32(&regs->pio1, timing->pio1);
175 out_be32(&regs->pio2, timing->pio2); 336 out_be32(&regs->pio2, timing->pio2);
176 out_be32(&regs->mdma1, 0); 337 out_be32(&regs->mdma1, timing->mdma1);
177 out_be32(&regs->mdma2, 0); 338 out_be32(&regs->mdma2, timing->mdma2);
178 out_be32(&regs->udma1, 0); 339 out_be32(&regs->udma1, timing->udma1);
179 out_be32(&regs->udma2, 0); 340 out_be32(&regs->udma2, timing->udma2);
180 out_be32(&regs->udma3, 0); 341 out_be32(&regs->udma3, timing->udma3);
181 out_be32(&regs->udma4, 0); 342 out_be32(&regs->udma4, timing->udma4);
182 out_be32(&regs->udma5, 0); 343 out_be32(&regs->udma5, timing->udma5);
183
184 priv->csel = device; 344 priv->csel = device;
185} 345}
186 346
@@ -208,7 +368,7 @@ mpc52xx_ata_hw_init(struct mpc52xx_ata_priv *priv)
208 368
209 /* Set the time slot to 1us */ 369 /* Set the time slot to 1us */
210 tslot = CALC_CLKCYC(priv->ipb_period, 1000000); 370 tslot = CALC_CLKCYC(priv->ipb_period, 1000000);
211 out_be32(&regs->share_cnt, tslot << 16 ); 371 out_be32(&regs->share_cnt, tslot << 16);
212 372
213 /* Init timings to PIO0 */ 373 /* Init timings to PIO0 */
214 memset(priv->timings, 0x00, 2*sizeof(struct mpc52xx_ata_timings)); 374 memset(priv->timings, 0x00, 2*sizeof(struct mpc52xx_ata_timings));
@@ -237,13 +397,37 @@ mpc52xx_ata_set_piomode(struct ata_port *ap, struct ata_device *adev)
237 rv = mpc52xx_ata_compute_pio_timings(priv, adev->devno, pio); 397 rv = mpc52xx_ata_compute_pio_timings(priv, adev->devno, pio);
238 398
239 if (rv) { 399 if (rv) {
240 printk(KERN_ERR DRV_NAME 400 dev_err(ap->dev, "error: invalid PIO mode: %d\n", pio);
241 ": Trying to select invalid PIO mode %d\n", pio); 401 return;
402 }
403
404 mpc52xx_ata_apply_timings(priv, adev->devno);
405}
406
407static void
408mpc52xx_ata_set_dmamode(struct ata_port *ap, struct ata_device *adev)
409{
410 struct mpc52xx_ata_priv *priv = ap->host->private_data;
411 int rv;
412
413 if (adev->dma_mode >= XFER_UDMA_0) {
414 int dma = adev->dma_mode - XFER_UDMA_0;
415 rv = mpc52xx_ata_compute_udma_timings(priv, adev->devno, dma);
416 } else {
417 int dma = adev->dma_mode - XFER_MW_DMA_0;
418 rv = mpc52xx_ata_compute_mdma_timings(priv, adev->devno, dma);
419 }
420
421 if (rv) {
422 dev_alert(ap->dev,
423 "Trying to select invalid DMA mode %d\n",
424 adev->dma_mode);
242 return; 425 return;
243 } 426 }
244 427
245 mpc52xx_ata_apply_timings(priv, adev->devno); 428 mpc52xx_ata_apply_timings(priv, adev->devno);
246} 429}
430
247static void 431static void
248mpc52xx_ata_dev_select(struct ata_port *ap, unsigned int device) 432mpc52xx_ata_dev_select(struct ata_port *ap, unsigned int device)
249{ 433{
@@ -252,7 +436,173 @@ mpc52xx_ata_dev_select(struct ata_port *ap, unsigned int device)
252 if (device != priv->csel) 436 if (device != priv->csel)
253 mpc52xx_ata_apply_timings(priv, device); 437 mpc52xx_ata_apply_timings(priv, device);
254 438
255 ata_sff_dev_select(ap,device); 439 ata_sff_dev_select(ap, device);
440}
441
442static int
443mpc52xx_ata_build_dmatable(struct ata_queued_cmd *qc)
444{
445 struct ata_port *ap = qc->ap;
446 struct mpc52xx_ata_priv *priv = ap->host->private_data;
447 struct bcom_ata_bd *bd;
448 unsigned int read = !(qc->tf.flags & ATA_TFLAG_WRITE), si;
449 struct scatterlist *sg;
450 int count = 0;
451
452 if (read)
453 bcom_ata_rx_prepare(priv->dmatsk);
454 else
455 bcom_ata_tx_prepare(priv->dmatsk);
456
457 for_each_sg(qc->sg, sg, qc->n_elem, si) {
458 dma_addr_t cur_addr = sg_dma_address(sg);
459 u32 cur_len = sg_dma_len(sg);
460
461 while (cur_len) {
462 unsigned int tc = min(cur_len, MAX_DMA_BUFFER_SIZE);
463 bd = (struct bcom_ata_bd *)
464 bcom_prepare_next_buffer(priv->dmatsk);
465
466 if (read) {
467 bd->status = tc;
468 bd->src_pa = (__force u32) priv->ata_regs_pa +
469 offsetof(struct mpc52xx_ata, fifo_data);
470 bd->dst_pa = (__force u32) cur_addr;
471 } else {
472 bd->status = tc;
473 bd->src_pa = (__force u32) cur_addr;
474 bd->dst_pa = (__force u32) priv->ata_regs_pa +
475 offsetof(struct mpc52xx_ata, fifo_data);
476 }
477
478 bcom_submit_next_buffer(priv->dmatsk, NULL);
479
480 cur_addr += tc;
481 cur_len -= tc;
482 count++;
483
484 if (count > MAX_DMA_BUFFERS) {
485 dev_alert(ap->dev, "dma table"
486 "too small\n");
487 goto use_pio_instead;
488 }
489 }
490 }
491 return 1;
492
493 use_pio_instead:
494 bcom_ata_reset_bd(priv->dmatsk);
495 return 0;
496}
497
498static void
499mpc52xx_bmdma_setup(struct ata_queued_cmd *qc)
500{
501 struct ata_port *ap = qc->ap;
502 struct mpc52xx_ata_priv *priv = ap->host->private_data;
503 struct mpc52xx_ata __iomem *regs = priv->ata_regs;
504
505 unsigned int read = !(qc->tf.flags & ATA_TFLAG_WRITE);
506 u8 dma_mode;
507
508 if (!mpc52xx_ata_build_dmatable(qc))
509 dev_alert(ap->dev, "%s: %i, return 1?\n",
510 __func__, __LINE__);
511
512 /* Check FIFO is OK... */
513 if (in_8(&priv->ata_regs->fifo_status) & MPC52xx_ATA_FIFOSTAT_ERROR)
514 dev_alert(ap->dev, "%s: FIFO error detected: 0x%02x!\n",
515 __func__, in_8(&priv->ata_regs->fifo_status));
516
517 if (read) {
518 dma_mode = MPC52xx_ATA_DMAMODE_IE | MPC52xx_ATA_DMAMODE_READ |
519 MPC52xx_ATA_DMAMODE_FE;
520
521 /* Setup FIFO if direction changed */
522 if (priv->mpc52xx_ata_dma_last_write != 0) {
523 priv->mpc52xx_ata_dma_last_write = 0;
524
525 /* Configure FIFO with granularity to 7 */
526 out_8(&regs->fifo_control, 7);
527 out_be16(&regs->fifo_alarm, 128);
528
529 /* Set FIFO Reset bit (FR) */
530 out_8(&regs->dma_mode, MPC52xx_ATA_DMAMODE_FR);
531 }
532 } else {
533 dma_mode = MPC52xx_ATA_DMAMODE_IE | MPC52xx_ATA_DMAMODE_WRITE;
534
535 /* Setup FIFO if direction changed */
536 if (priv->mpc52xx_ata_dma_last_write != 1) {
537 priv->mpc52xx_ata_dma_last_write = 1;
538
539 /* Configure FIFO with granularity to 4 */
540 out_8(&regs->fifo_control, 4);
541 out_be16(&regs->fifo_alarm, 128);
542 }
543 }
544
545 if (priv->timings[qc->dev->devno].using_udma)
546 dma_mode |= MPC52xx_ATA_DMAMODE_UDMA;
547
548 out_8(&regs->dma_mode, dma_mode);
549 priv->waiting_for_dma = ATA_DMA_ACTIVE;
550
551 ata_wait_idle(ap);
552 ap->ops->sff_exec_command(ap, &qc->tf);
553}
554
555static void
556mpc52xx_bmdma_start(struct ata_queued_cmd *qc)
557{
558 struct ata_port *ap = qc->ap;
559 struct mpc52xx_ata_priv *priv = ap->host->private_data;
560
561 bcom_set_task_auto_start(priv->dmatsk->tasknum, priv->dmatsk->tasknum);
562 bcom_enable(priv->dmatsk);
563}
564
565static void
566mpc52xx_bmdma_stop(struct ata_queued_cmd *qc)
567{
568 struct ata_port *ap = qc->ap;
569 struct mpc52xx_ata_priv *priv = ap->host->private_data;
570
571 bcom_disable(priv->dmatsk);
572 bcom_ata_reset_bd(priv->dmatsk);
573 priv->waiting_for_dma = 0;
574
575 /* Check FIFO is OK... */
576 if (in_8(&priv->ata_regs->fifo_status) & MPC52xx_ATA_FIFOSTAT_ERROR)
577 dev_alert(ap->dev, "%s: FIFO error detected: 0x%02x!\n",
578 __func__, in_8(&priv->ata_regs->fifo_status));
579}
580
581static u8
582mpc52xx_bmdma_status(struct ata_port *ap)
583{
584 struct mpc52xx_ata_priv *priv = ap->host->private_data;
585
586 /* Check FIFO is OK... */
587 if (in_8(&priv->ata_regs->fifo_status) & MPC52xx_ATA_FIFOSTAT_ERROR) {
588 dev_alert(ap->dev, "%s: FIFO error detected: 0x%02x!\n",
589 __func__, in_8(&priv->ata_regs->fifo_status));
590 return priv->waiting_for_dma | ATA_DMA_ERR;
591 }
592
593 return priv->waiting_for_dma;
594}
595
596static irqreturn_t
597mpc52xx_ata_task_irq(int irq, void *vpriv)
598{
599 struct mpc52xx_ata_priv *priv = vpriv;
600 while (bcom_buffer_done(priv->dmatsk))
601 bcom_retrieve_buffer(priv->dmatsk, NULL, NULL);
602
603 priv->waiting_for_dma |= ATA_DMA_INTR;
604
605 return IRQ_HANDLED;
256} 606}
257 607
258static struct scsi_host_template mpc52xx_ata_sht = { 608static struct scsi_host_template mpc52xx_ata_sht = {
@@ -262,14 +612,18 @@ static struct scsi_host_template mpc52xx_ata_sht = {
262static struct ata_port_operations mpc52xx_ata_port_ops = { 612static struct ata_port_operations mpc52xx_ata_port_ops = {
263 .inherits = &ata_sff_port_ops, 613 .inherits = &ata_sff_port_ops,
264 .sff_dev_select = mpc52xx_ata_dev_select, 614 .sff_dev_select = mpc52xx_ata_dev_select,
265 .cable_detect = ata_cable_40wire,
266 .set_piomode = mpc52xx_ata_set_piomode, 615 .set_piomode = mpc52xx_ata_set_piomode,
267 .post_internal_cmd = ATA_OP_NULL, 616 .set_dmamode = mpc52xx_ata_set_dmamode,
617 .bmdma_setup = mpc52xx_bmdma_setup,
618 .bmdma_start = mpc52xx_bmdma_start,
619 .bmdma_stop = mpc52xx_bmdma_stop,
620 .bmdma_status = mpc52xx_bmdma_status,
621 .qc_prep = ata_noop_qc_prep,
268}; 622};
269 623
270static int __devinit 624static int __devinit
271mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv, 625mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv,
272 unsigned long raw_ata_regs) 626 unsigned long raw_ata_regs, int mwdma_mask, int udma_mask)
273{ 627{
274 struct ata_host *host; 628 struct ata_host *host;
275 struct ata_port *ap; 629 struct ata_port *ap;
@@ -281,9 +635,9 @@ mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv,
281 635
282 ap = host->ports[0]; 636 ap = host->ports[0];
283 ap->flags |= ATA_FLAG_SLAVE_POSS; 637 ap->flags |= ATA_FLAG_SLAVE_POSS;
284 ap->pio_mask = 0x1f; /* Up to PIO4 */ 638 ap->pio_mask = ATA_PIO4;
285 ap->mwdma_mask = 0x00; /* No MWDMA */ 639 ap->mwdma_mask = mwdma_mask;
286 ap->udma_mask = 0x00; /* No UDMA */ 640 ap->udma_mask = udma_mask;
287 ap->ops = &mpc52xx_ata_port_ops; 641 ap->ops = &mpc52xx_ata_port_ops;
288 host->private_data = priv; 642 host->private_data = priv;
289 643
@@ -330,89 +684,139 @@ mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match)
330{ 684{
331 unsigned int ipb_freq; 685 unsigned int ipb_freq;
332 struct resource res_mem; 686 struct resource res_mem;
333 int ata_irq; 687 int ata_irq = 0;
334 struct mpc52xx_ata __iomem *ata_regs; 688 struct mpc52xx_ata __iomem *ata_regs;
335 struct mpc52xx_ata_priv *priv; 689 struct mpc52xx_ata_priv *priv = NULL;
336 int rv; 690 int rv, ret, task_irq = 0;
691 int mwdma_mask = 0, udma_mask = 0;
692 const __be32 *prop;
693 int proplen;
694 struct bcom_task *dmatsk = NULL;
337 695
338 /* Get ipb frequency */ 696 /* Get ipb frequency */
339 ipb_freq = mpc52xx_find_ipb_freq(op->node); 697 ipb_freq = mpc52xx_find_ipb_freq(op->node);
340 if (!ipb_freq) { 698 if (!ipb_freq) {
341 printk(KERN_ERR DRV_NAME ": " 699 dev_err(&op->dev, "could not determine IPB bus frequency\n");
342 "Unable to find IPB Bus frequency\n" );
343 return -ENODEV; 700 return -ENODEV;
344 } 701 }
345 702
346 /* Get IRQ and register */ 703 /* Get device base address from device tree, request the region
704 * and ioremap it. */
347 rv = of_address_to_resource(op->node, 0, &res_mem); 705 rv = of_address_to_resource(op->node, 0, &res_mem);
348 if (rv) { 706 if (rv) {
349 printk(KERN_ERR DRV_NAME ": " 707 dev_err(&op->dev, "could not determine device base address\n");
350 "Error while parsing device node resource\n" );
351 return rv; 708 return rv;
352 } 709 }
353 710
354 ata_irq = irq_of_parse_and_map(op->node, 0);
355 if (ata_irq == NO_IRQ) {
356 printk(KERN_ERR DRV_NAME ": "
357 "Error while mapping the irq\n");
358 return -EINVAL;
359 }
360
361 /* Request mem region */
362 if (!devm_request_mem_region(&op->dev, res_mem.start, 711 if (!devm_request_mem_region(&op->dev, res_mem.start,
363 sizeof(struct mpc52xx_ata), DRV_NAME)) { 712 sizeof(*ata_regs), DRV_NAME)) {
364 printk(KERN_ERR DRV_NAME ": " 713 dev_err(&op->dev, "error requesting register region\n");
365 "Error while requesting mem region\n"); 714 return -EBUSY;
366 rv = -EBUSY;
367 goto err;
368 } 715 }
369 716
370 /* Remap registers */ 717 ata_regs = devm_ioremap(&op->dev, res_mem.start, sizeof(*ata_regs));
371 ata_regs = devm_ioremap(&op->dev, res_mem.start,
372 sizeof(struct mpc52xx_ata));
373 if (!ata_regs) { 718 if (!ata_regs) {
374 printk(KERN_ERR DRV_NAME ": " 719 dev_err(&op->dev, "error mapping device registers\n");
375 "Error while mapping register set\n");
376 rv = -ENOMEM; 720 rv = -ENOMEM;
377 goto err; 721 goto err;
378 } 722 }
379 723
724 /*
725 * By default, all DMA modes are disabled for the MPC5200. Some
726 * boards don't have the required signals routed to make DMA work.
727 * Also, the MPC5200B has a silicon bug that causes data corruption
728 * with UDMA if it is used at the same time as the LocalPlus bus.
729 *
730 * Instead of trying to guess what modes are usable, check the
731 * ATA device tree node to find out what DMA modes work on the board.
732 * UDMA/MWDMA modes can also be forced by adding "libata.force=<mode>"
733 * to the kernel boot parameters.
734 *
735 * The MPC5200 ATA controller supports MWDMA modes 0, 1 and 2 and
736 * UDMA modes 0, 1 and 2.
737 */
738 prop = of_get_property(op->node, "mwdma-mode", &proplen);
739 if ((prop) && (proplen >= 4))
740 mwdma_mask = 0x7 & ((1 << (*prop + 1)) - 1);
741 prop = of_get_property(op->node, "udma-mode", &proplen);
742 if ((prop) && (proplen >= 4))
743 udma_mask = 0x7 & ((1 << (*prop + 1)) - 1);
744
745 ata_irq = irq_of_parse_and_map(op->node, 0);
746 if (ata_irq == NO_IRQ) {
747 dev_err(&op->dev, "error mapping irq\n");
748 return -EINVAL;
749 }
750
380 /* Prepare our private structure */ 751 /* Prepare our private structure */
381 priv = devm_kzalloc(&op->dev, sizeof(struct mpc52xx_ata_priv), 752 priv = devm_kzalloc(&op->dev, sizeof(*priv), GFP_ATOMIC);
382 GFP_ATOMIC);
383 if (!priv) { 753 if (!priv) {
384 printk(KERN_ERR DRV_NAME ": " 754 dev_err(&op->dev, "error allocating private structure\n");
385 "Error while allocating private structure\n");
386 rv = -ENOMEM; 755 rv = -ENOMEM;
387 goto err; 756 goto err;
388 } 757 }
389 758
390 priv->ipb_period = 1000000000 / (ipb_freq / 1000); 759 priv->ipb_period = 1000000000 / (ipb_freq / 1000);
391 priv->ata_regs = ata_regs; 760 priv->ata_regs = ata_regs;
761 priv->ata_regs_pa = res_mem.start;
392 priv->ata_irq = ata_irq; 762 priv->ata_irq = ata_irq;
393 priv->csel = -1; 763 priv->csel = -1;
764 priv->mpc52xx_ata_dma_last_write = -1;
765
766 if (ipb_freq/1000000 == 66) {
767 priv->mdmaspec = mdmaspec66;
768 priv->udmaspec = udmaspec66;
769 } else {
770 priv->mdmaspec = mdmaspec132;
771 priv->udmaspec = udmaspec132;
772 }
773
774 /* Allocate a BestComm task for DMA */
775 dmatsk = bcom_ata_init(MAX_DMA_BUFFERS, MAX_DMA_BUFFER_SIZE);
776 if (!dmatsk) {
777 dev_err(&op->dev, "bestcomm initialization failed\n");
778 rv = -ENOMEM;
779 goto err;
780 }
781
782 task_irq = bcom_get_task_irq(dmatsk);
783 ret = request_irq(task_irq, &mpc52xx_ata_task_irq, IRQF_DISABLED,
784 "ATA task", priv);
785 if (ret) {
786 dev_err(&op->dev, "error requesting DMA IRQ\n");
787 goto err;
788 }
789 priv->dmatsk = dmatsk;
394 790
395 /* Init the hw */ 791 /* Init the hw */
396 rv = mpc52xx_ata_hw_init(priv); 792 rv = mpc52xx_ata_hw_init(priv);
397 if (rv) { 793 if (rv) {
398 printk(KERN_ERR DRV_NAME ": Error during HW init\n"); 794 dev_err(&op->dev, "error initializing hardware\n");
399 goto err; 795 goto err;
400 } 796 }
401 797
402 /* Register ourselves to libata */ 798 /* Register ourselves to libata */
403 rv = mpc52xx_ata_init_one(&op->dev, priv, res_mem.start); 799 rv = mpc52xx_ata_init_one(&op->dev, priv, res_mem.start,
800 mwdma_mask, udma_mask);
404 if (rv) { 801 if (rv) {
405 printk(KERN_ERR DRV_NAME ": " 802 dev_err(&op->dev, "error registering with ATA layer\n");
406 "Error while registering to ATA layer\n"); 803 goto err;
407 return rv;
408 } 804 }
409 805
410 /* Done */
411 return 0; 806 return 0;
412 807
413 /* Error path */ 808 err:
414err: 809 devm_release_mem_region(&op->dev, res_mem.start, sizeof(*ata_regs));
415 irq_dispose_mapping(ata_irq); 810 if (ata_irq)
811 irq_dispose_mapping(ata_irq);
812 if (task_irq)
813 irq_dispose_mapping(task_irq);
814 if (dmatsk)
815 bcom_ata_release(dmatsk);
816 if (ata_regs)
817 devm_iounmap(&op->dev, ata_regs);
818 if (priv)
819 devm_kfree(&op->dev, priv);
416 return rv; 820 return rv;
417} 821}
418 822
@@ -420,10 +824,23 @@ static int
420mpc52xx_ata_remove(struct of_device *op) 824mpc52xx_ata_remove(struct of_device *op)
421{ 825{
422 struct mpc52xx_ata_priv *priv; 826 struct mpc52xx_ata_priv *priv;
827 int task_irq;
423 828
829 /* Deregister the ATA interface */
424 priv = mpc52xx_ata_remove_one(&op->dev); 830 priv = mpc52xx_ata_remove_one(&op->dev);
831
832 /* Clean up DMA */
833 task_irq = bcom_get_task_irq(priv->dmatsk);
834 irq_dispose_mapping(task_irq);
835 bcom_ata_release(priv->dmatsk);
425 irq_dispose_mapping(priv->ata_irq); 836 irq_dispose_mapping(priv->ata_irq);
426 837
838 /* Clear up IO allocations */
839 devm_iounmap(&op->dev, priv->ata_regs);
840 devm_release_mem_region(&op->dev, priv->ata_regs_pa,
841 sizeof(*priv->ata_regs));
842 devm_kfree(&op->dev, priv);
843
427 return 0; 844 return 0;
428} 845}
429 846
@@ -447,7 +864,7 @@ mpc52xx_ata_resume(struct of_device *op)
447 864
448 rv = mpc52xx_ata_hw_init(priv); 865 rv = mpc52xx_ata_hw_init(priv);
449 if (rv) { 866 if (rv) {
450 printk(KERN_ERR DRV_NAME ": Error during HW init\n"); 867 dev_err(host->dev, "error initializing hardware\n");
451 return rv; 868 return rv;
452 } 869 }
453 870
@@ -507,5 +924,4 @@ MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>");
507MODULE_DESCRIPTION("Freescale MPC52xx IDE/ATA libata driver"); 924MODULE_DESCRIPTION("Freescale MPC52xx IDE/ATA libata driver");
508MODULE_LICENSE("GPL"); 925MODULE_LICENSE("GPL");
509MODULE_DEVICE_TABLE(of, mpc52xx_ata_of_match); 926MODULE_DEVICE_TABLE(of, mpc52xx_ata_of_match);
510MODULE_VERSION(DRV_VERSION);
511 927
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 7c8faa48b5f3..aa576cac4d17 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_mpiix" 37#define DRV_NAME "pata_mpiix"
38#define DRV_VERSION "0.7.6" 38#define DRV_VERSION "0.7.7"
39 39
40enum { 40enum {
41 IDETIM = 0x6C, /* IDE control register */ 41 IDETIM = 0x6C, /* IDE control register */
@@ -146,6 +146,7 @@ static struct ata_port_operations mpiix_port_ops = {
146 .cable_detect = ata_cable_40wire, 146 .cable_detect = ata_cable_40wire,
147 .set_piomode = mpiix_set_piomode, 147 .set_piomode = mpiix_set_piomode,
148 .prereset = mpiix_pre_reset, 148 .prereset = mpiix_pre_reset,
149 .sff_data_xfer = ata_sff_data_xfer32,
149}; 150};
150 151
151static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id) 152static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index c0dbc46a348e..2c1a91c40c1a 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -116,7 +116,6 @@ static void oldpiix_set_piomode (struct ata_port *ap, struct ata_device *adev)
116 * oldpiix_set_dmamode - Initialize host controller PATA DMA timings 116 * oldpiix_set_dmamode - Initialize host controller PATA DMA timings
117 * @ap: Port whose timings we are configuring 117 * @ap: Port whose timings we are configuring
118 * @adev: Device to program 118 * @adev: Device to program
119 * @isich: True if the device is an ICH and has IOCFG registers
120 * 119 *
121 * Set MWDMA mode for device, in host controller PCI config space. 120 * Set MWDMA mode for device, in host controller PCI config space.
122 * 121 *
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 0e1c2c1134d3..e94efccaa482 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -281,7 +281,6 @@ static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long
281 * pdc2027x_set_piomode - Initialize host controller PATA PIO timings 281 * pdc2027x_set_piomode - Initialize host controller PATA PIO timings
282 * @ap: Port to configure 282 * @ap: Port to configure
283 * @adev: um 283 * @adev: um
284 * @pio: PIO mode, 0 - 4
285 * 284 *
286 * Set PIO mode for device. 285 * Set PIO mode for device.
287 * 286 *
@@ -326,7 +325,6 @@ static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev)
326 * pdc2027x_set_dmamode - Initialize host controller PATA UDMA timings 325 * pdc2027x_set_dmamode - Initialize host controller PATA UDMA timings
327 * @ap: Port to configure 326 * @ap: Port to configure
328 * @adev: um 327 * @adev: um
329 * @udma: udma mode, XFER_UDMA_0 to XFER_UDMA_6
330 * 328 *
331 * Set UDMA mode for device. 329 * Set UDMA mode for device.
332 * 330 *
@@ -406,23 +404,20 @@ static int pdc2027x_set_mode(struct ata_link *link, struct ata_device **r_failed
406 if (rc < 0) 404 if (rc < 0)
407 return rc; 405 return rc;
408 406
409 ata_link_for_each_dev(dev, link) { 407 ata_for_each_dev(dev, link, ENABLED) {
410 if (ata_dev_enabled(dev)) { 408 pdc2027x_set_piomode(ap, dev);
411 409
412 pdc2027x_set_piomode(ap, dev); 410 /*
411 * Enable prefetch if the device support PIO only.
412 */
413 if (dev->xfer_shift == ATA_SHIFT_PIO) {
414 u32 ctcr1 = ioread32(dev_mmio(ap, dev, PDC_CTCR1));
415 ctcr1 |= (1 << 25);
416 iowrite32(ctcr1, dev_mmio(ap, dev, PDC_CTCR1));
413 417
414 /* 418 PDPRINTK("Turn on prefetch\n");
415 * Enable prefetch if the device support PIO only. 419 } else {
416 */ 420 pdc2027x_set_dmamode(ap, dev);
417 if (dev->xfer_shift == ATA_SHIFT_PIO) {
418 u32 ctcr1 = ioread32(dev_mmio(ap, dev, PDC_CTCR1));
419 ctcr1 |= (1 << 25);
420 iowrite32(ctcr1, dev_mmio(ap, dev, PDC_CTCR1));
421
422 PDPRINTK("Turn on prefetch\n");
423 } else {
424 pdc2027x_set_dmamode(ap, dev);
425 }
426 } 421 }
427 } 422 }
428 return 0; 423 return 0;
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 77e4e3b17f54..d8d743af3225 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -34,14 +34,12 @@ static int pata_platform_set_mode(struct ata_link *link, struct ata_device **unu
34{ 34{
35 struct ata_device *dev; 35 struct ata_device *dev;
36 36
37 ata_link_for_each_dev(dev, link) { 37 ata_for_each_dev(dev, link, ENABLED) {
38 if (ata_dev_enabled(dev)) { 38 /* We don't really care */
39 /* We don't really care */ 39 dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
40 dev->pio_mode = dev->xfer_mode = XFER_PIO_0; 40 dev->xfer_shift = ATA_SHIFT_PIO;
41 dev->xfer_shift = ATA_SHIFT_PIO; 41 dev->flags |= ATA_DFLAG_PIO;
42 dev->flags |= ATA_DFLAG_PIO; 42 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
43 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
44 }
45 } 43 }
46 return 0; 44 return 0;
47} 45}
@@ -188,7 +186,7 @@ EXPORT_SYMBOL_GPL(__pata_platform_probe);
188 * A platform bus ATA device has been unplugged. Perform the needed 186 * A platform bus ATA device has been unplugged. Perform the needed
189 * cleanup. Also called on module unload for any active devices. 187 * cleanup. Also called on module unload for any active devices.
190 */ 188 */
191int __devexit __pata_platform_remove(struct device *dev) 189int __pata_platform_remove(struct device *dev)
192{ 190{
193 struct ata_host *host = dev_get_drvdata(dev); 191 struct ata_host *host = dev_get_drvdata(dev);
194 192
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 0b0aa452de14..695d44ae52c6 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -81,7 +81,6 @@ static void radisys_set_piomode (struct ata_port *ap, struct ata_device *adev)
81 * radisys_set_dmamode - Initialize host controller PATA DMA timings 81 * radisys_set_dmamode - Initialize host controller PATA DMA timings
82 * @ap: Port whose timings we are configuring 82 * @ap: Port whose timings we are configuring
83 * @adev: Device to program 83 * @adev: Device to program
84 * @isich: True if the device is an ICH and has IOCFG registers
85 * 84 *
86 * Set MWDMA mode for device, in host controller PCI config space. 85 * Set MWDMA mode for device, in host controller PCI config space.
87 * 86 *
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 7dfd1f3f6f3a..46d6bc1bf1e9 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -38,15 +38,13 @@ static int rz1000_set_mode(struct ata_link *link, struct ata_device **unused)
38{ 38{
39 struct ata_device *dev; 39 struct ata_device *dev;
40 40
41 ata_link_for_each_dev(dev, link) { 41 ata_for_each_dev(dev, link, ENABLED) {
42 if (ata_dev_enabled(dev)) { 42 /* We don't really care */
43 /* We don't really care */ 43 dev->pio_mode = XFER_PIO_0;
44 dev->pio_mode = XFER_PIO_0; 44 dev->xfer_mode = XFER_PIO_0;
45 dev->xfer_mode = XFER_PIO_0; 45 dev->xfer_shift = ATA_SHIFT_PIO;
46 dev->xfer_shift = ATA_SHIFT_PIO; 46 dev->flags |= ATA_DFLAG_PIO;
47 dev->flags |= ATA_DFLAG_PIO; 47 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
48 ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
49 }
50 } 48 }
51 return 0; 49 return 0;
52} 50}
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index cf3707e516a2..d447f1cb46ec 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -210,7 +210,6 @@ static void scc_set_piomode (struct ata_port *ap, struct ata_device *adev)
210 * scc_set_dmamode - Initialize host controller PATA DMA timings 210 * scc_set_dmamode - Initialize host controller PATA DMA timings
211 * @ap: Port whose timings we are configuring 211 * @ap: Port whose timings we are configuring
212 * @adev: um 212 * @adev: um
213 * @udma: udma mode, 0 - 6
214 * 213 *
215 * Set UDMA mode for device. 214 * Set UDMA mode for device.
216 * 215 *
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 72e41c9f969b..8d2fd9dd40c7 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -138,7 +138,6 @@ static struct sv_cable_table cable_detect[] = {
138/** 138/**
139 * serverworks_cable_detect - cable detection 139 * serverworks_cable_detect - cable detection
140 * @ap: ATA port 140 * @ap: ATA port
141 * @deadline: deadline jiffies for the operation
142 * 141 *
143 * Perform cable detection according to the device and subvendor 142 * Perform cable detection according to the device and subvendor
144 * identifications 143 * identifications
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 83580a59db58..9e764e5747e6 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -32,7 +32,7 @@
32#include <linux/libata.h> 32#include <linux/libata.h>
33 33
34#define DRV_NAME "pata_sil680" 34#define DRV_NAME "pata_sil680"
35#define DRV_VERSION "0.4.8" 35#define DRV_VERSION "0.4.9"
36 36
37#define SIL680_MMIO_BAR 5 37#define SIL680_MMIO_BAR 5
38 38
@@ -195,7 +195,7 @@ static struct scsi_host_template sil680_sht = {
195}; 195};
196 196
197static struct ata_port_operations sil680_port_ops = { 197static struct ata_port_operations sil680_port_ops = {
198 .inherits = &ata_bmdma_port_ops, 198 .inherits = &ata_bmdma32_port_ops,
199 .cable_detect = sil680_cable_detect, 199 .cable_detect = sil680_cable_detect,
200 .set_piomode = sil680_set_piomode, 200 .set_piomode = sil680_set_piomode,
201 .set_dmamode = sil680_set_dmamode, 201 .set_dmamode = sil680_set_dmamode,
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index e4be55e047f6..27ceb42a774b 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -112,7 +112,6 @@ static int sis_133_cable_detect(struct ata_port *ap)
112/** 112/**
113 * sis_66_cable_detect - check for 40/80 pin 113 * sis_66_cable_detect - check for 40/80 pin
114 * @ap: Port 114 * @ap: Port
115 * @deadline: deadline jiffies for the operation
116 * 115 *
117 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133 116 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
118 * SiS IDE controllers. 117 * SiS IDE controllers.
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 2b24ae58b52e..86918634a4c5 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1836,7 +1836,6 @@ static void mv_unexpected_intr(struct ata_port *ap, int edma_was_enabled)
1836/** 1836/**
1837 * mv_err_intr - Handle error interrupts on the port 1837 * mv_err_intr - Handle error interrupts on the port
1838 * @ap: ATA channel to manipulate 1838 * @ap: ATA channel to manipulate
1839 * @qc: affected command (non-NCQ), or NULL
1840 * 1839 *
1841 * Most cases require a full reset of the chip's state machine, 1840 * Most cases require a full reset of the chip's state machine,
1842 * which also performs a COMRESET. 1841 * which also performs a COMRESET.
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 031d7b7dee34..564c142b03b0 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -46,7 +46,9 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_sil" 48#define DRV_NAME "sata_sil"
49#define DRV_VERSION "2.3" 49#define DRV_VERSION "2.4"
50
51#define SIL_DMA_BOUNDARY 0x7fffffffUL
50 52
51enum { 53enum {
52 SIL_MMIO_BAR = 5, 54 SIL_MMIO_BAR = 5,
@@ -118,6 +120,10 @@ static void sil_dev_config(struct ata_device *dev);
118static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val); 120static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
119static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val); 121static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
120static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed); 122static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed);
123static void sil_qc_prep(struct ata_queued_cmd *qc);
124static void sil_bmdma_setup(struct ata_queued_cmd *qc);
125static void sil_bmdma_start(struct ata_queued_cmd *qc);
126static void sil_bmdma_stop(struct ata_queued_cmd *qc);
121static void sil_freeze(struct ata_port *ap); 127static void sil_freeze(struct ata_port *ap);
122static void sil_thaw(struct ata_port *ap); 128static void sil_thaw(struct ata_port *ap);
123 129
@@ -167,13 +173,22 @@ static struct pci_driver sil_pci_driver = {
167}; 173};
168 174
169static struct scsi_host_template sil_sht = { 175static struct scsi_host_template sil_sht = {
170 ATA_BMDMA_SHT(DRV_NAME), 176 ATA_BASE_SHT(DRV_NAME),
177 /** These controllers support Large Block Transfer which allows
178 transfer chunks up to 2GB and which cross 64KB boundaries,
179 therefore the DMA limits are more relaxed than standard ATA SFF. */
180 .dma_boundary = SIL_DMA_BOUNDARY,
181 .sg_tablesize = ATA_MAX_PRD
171}; 182};
172 183
173static struct ata_port_operations sil_ops = { 184static struct ata_port_operations sil_ops = {
174 .inherits = &ata_bmdma_port_ops, 185 .inherits = &ata_bmdma_port_ops,
175 .dev_config = sil_dev_config, 186 .dev_config = sil_dev_config,
176 .set_mode = sil_set_mode, 187 .set_mode = sil_set_mode,
188 .bmdma_setup = sil_bmdma_setup,
189 .bmdma_start = sil_bmdma_start,
190 .bmdma_stop = sil_bmdma_stop,
191 .qc_prep = sil_qc_prep,
177 .freeze = sil_freeze, 192 .freeze = sil_freeze,
178 .thaw = sil_thaw, 193 .thaw = sil_thaw,
179 .scr_read = sil_scr_read, 194 .scr_read = sil_scr_read,
@@ -249,6 +264,83 @@ module_param(slow_down, int, 0444);
249MODULE_PARM_DESC(slow_down, "Sledgehammer used to work around random problems, by limiting commands to 15 sectors (0=off, 1=on)"); 264MODULE_PARM_DESC(slow_down, "Sledgehammer used to work around random problems, by limiting commands to 15 sectors (0=off, 1=on)");
250 265
251 266
267static void sil_bmdma_stop(struct ata_queued_cmd *qc)
268{
269 struct ata_port *ap = qc->ap;
270 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
271 void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2;
272
273 /* clear start/stop bit - can safely always write 0 */
274 iowrite8(0, bmdma2);
275
276 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
277 ata_sff_dma_pause(ap);
278}
279
280static void sil_bmdma_setup(struct ata_queued_cmd *qc)
281{
282 struct ata_port *ap = qc->ap;
283 void __iomem *bmdma = ap->ioaddr.bmdma_addr;
284
285 /* load PRD table addr. */
286 iowrite32(ap->prd_dma, bmdma + ATA_DMA_TABLE_OFS);
287
288 /* issue r/w command */
289 ap->ops->sff_exec_command(ap, &qc->tf);
290}
291
292static void sil_bmdma_start(struct ata_queued_cmd *qc)
293{
294 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
295 struct ata_port *ap = qc->ap;
296 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
297 void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2;
298 u8 dmactl = ATA_DMA_START;
299
300 /* set transfer direction, start host DMA transaction
301 Note: For Large Block Transfer to work, the DMA must be started
302 using the bmdma2 register. */
303 if (!rw)
304 dmactl |= ATA_DMA_WR;
305 iowrite8(dmactl, bmdma2);
306}
307
308/* The way God intended PCI IDE scatter/gather lists to look and behave... */
309static void sil_fill_sg(struct ata_queued_cmd *qc)
310{
311 struct scatterlist *sg;
312 struct ata_port *ap = qc->ap;
313 struct ata_prd *prd, *last_prd = NULL;
314 unsigned int si;
315
316 prd = &ap->prd[0];
317 for_each_sg(qc->sg, sg, qc->n_elem, si) {
318 /* Note h/w doesn't support 64-bit, so we unconditionally
319 * truncate dma_addr_t to u32.
320 */
321 u32 addr = (u32) sg_dma_address(sg);
322 u32 sg_len = sg_dma_len(sg);
323
324 prd->addr = cpu_to_le32(addr);
325 prd->flags_len = cpu_to_le32(sg_len);
326 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, sg_len);
327
328 last_prd = prd;
329 prd++;
330 }
331
332 if (likely(last_prd))
333 last_prd->flags_len |= cpu_to_le32(ATA_PRD_EOT);
334}
335
336static void sil_qc_prep(struct ata_queued_cmd *qc)
337{
338 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
339 return;
340
341 sil_fill_sg(qc);
342}
343
252static unsigned char sil_get_device_cache_line(struct pci_dev *pdev) 344static unsigned char sil_get_device_cache_line(struct pci_dev *pdev)
253{ 345{
254 u8 cache_line = 0; 346 u8 cache_line = 0;
@@ -278,7 +370,7 @@ static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed)
278 if (rc) 370 if (rc)
279 return rc; 371 return rc;
280 372
281 ata_link_for_each_dev(dev, link) { 373 ata_for_each_dev(dev, link, ALL) {
282 if (!ata_dev_enabled(dev)) 374 if (!ata_dev_enabled(dev))
283 dev_mode[dev->devno] = 0; /* PIO0/1/2 */ 375 dev_mode[dev->devno] = 0; /* PIO0/1/2 */
284 else if (dev->flags & ATA_DFLAG_PIO) 376 else if (dev->flags & ATA_DFLAG_PIO)
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index ccee930f1e12..2590c2279fa7 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -51,13 +51,6 @@ struct sil24_sge {
51 __le32 flags; 51 __le32 flags;
52}; 52};
53 53
54/*
55 * Port multiplier
56 */
57struct sil24_port_multiplier {
58 __le32 diag;
59 __le32 sactive;
60};
61 54
62enum { 55enum {
63 SIL24_HOST_BAR = 0, 56 SIL24_HOST_BAR = 0,