aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-12-01 16:18:56 -0500
committerJeff Garzik <jeff@garzik.org>2007-12-01 16:18:56 -0500
commitc99da91e7a12724127475a85cc7a38214b3504e2 (patch)
treede0eb3fe32ce58804457963fd133a53bb8fba5b8 /drivers/ata
parenta31e23e15cbb9734c5883a4a7f58d8712d303e0b (diff)
parent92d499d991ec4f5cbd00d6f33967eab9d3ee8d6c (diff)
Merge branch 'master' into upstream-fixes
Diffstat (limited to 'drivers/ata')
-rw-r--r--drivers/ata/ata_piix.c93
-rw-r--r--drivers/ata/libata-core.c108
-rw-r--r--drivers/ata/libata-eh.c95
-rw-r--r--drivers/ata/libata-scsi.c38
-rw-r--r--drivers/ata/pata_ali.c20
-rw-r--r--drivers/ata/pata_bf54x.c6
-rw-r--r--drivers/ata/pata_hpt37x.c2
-rw-r--r--drivers/ata/pata_isapnp.c11
-rw-r--r--drivers/ata/pata_jmicron.c9
-rw-r--r--drivers/ata/pata_sil680.c32
-rw-r--r--drivers/ata/pata_sis.c1
-rw-r--r--drivers/ata/sata_sil24.c26
12 files changed, 183 insertions, 258 deletions
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 328ce8a08426..483269db2c7d 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -119,18 +119,19 @@ enum {
119 PIIX_80C_SEC = (1 << 7) | (1 << 6), 119 PIIX_80C_SEC = (1 << 7) | (1 << 6),
120 120
121 /* controller IDs */ 121 /* controller IDs */
122 piix_pata_33 = 0, /* PIIX4 at 33Mhz */ 122 piix_pata_mwdma = 0, /* PIIX3 MWDMA only */
123 ich_pata_33 = 1, /* ICH up to UDMA 33 only */ 123 piix_pata_33, /* PIIX4 at 33Mhz */
124 ich_pata_66 = 2, /* ICH up to 66 Mhz */ 124 ich_pata_33, /* ICH up to UDMA 33 only */
125 ich_pata_100 = 3, /* ICH up to UDMA 100 */ 125 ich_pata_66, /* ICH up to 66 Mhz */
126 ich5_sata = 5, 126 ich_pata_100, /* ICH up to UDMA 100 */
127 ich6_sata = 6, 127 ich5_sata,
128 ich6_sata_ahci = 7, 128 ich6_sata,
129 ich6m_sata_ahci = 8, 129 ich6_sata_ahci,
130 ich8_sata_ahci = 9, 130 ich6m_sata_ahci,
131 piix_pata_mwdma = 10, /* PIIX3 MWDMA only */ 131 ich8_sata_ahci,
132 tolapai_sata_ahci = 11, 132 ich8_2port_sata,
133 ich9_2port_sata = 12, 133 ich8m_apple_sata_ahci, /* locks up on second port enable */
134 tolapai_sata_ahci,
134 135
135 /* constants for mapping table */ 136 /* constants for mapping table */
136 P0 = 0, /* port 0 */ 137 P0 = 0, /* port 0 */
@@ -239,19 +240,21 @@ static const struct pci_device_id piix_pci_tbl[] = {
239 /* SATA Controller 1 IDE (ICH8) */ 240 /* SATA Controller 1 IDE (ICH8) */
240 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 241 { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
241 /* SATA Controller 2 IDE (ICH8) */ 242 /* SATA Controller 2 IDE (ICH8) */
242 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 243 { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
243 /* Mobile SATA Controller IDE (ICH8M) */ 244 /* Mobile SATA Controller IDE (ICH8M) */
244 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 245 { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
246 /* Mobile SATA Controller IDE (ICH8M), Apple */
247 { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata_ahci },
245 /* SATA Controller IDE (ICH9) */ 248 /* SATA Controller IDE (ICH9) */
246 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 249 { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
247 /* SATA Controller IDE (ICH9) */ 250 /* SATA Controller IDE (ICH9) */
248 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 251 { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
249 /* SATA Controller IDE (ICH9) */ 252 /* SATA Controller IDE (ICH9) */
250 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 253 { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
251 /* SATA Controller IDE (ICH9M) */ 254 /* SATA Controller IDE (ICH9M) */
252 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 255 { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
253 /* SATA Controller IDE (ICH9M) */ 256 /* SATA Controller IDE (ICH9M) */
254 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, 257 { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
255 /* SATA Controller IDE (ICH9M) */ 258 /* SATA Controller IDE (ICH9M) */
256 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, 259 { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci },
257 /* SATA Controller IDE (Tolapai) */ 260 /* SATA Controller IDE (Tolapai) */
@@ -427,7 +430,7 @@ static const struct piix_map_db ich6m_map_db = {
427 430
428static const struct piix_map_db ich8_map_db = { 431static const struct piix_map_db ich8_map_db = {
429 .mask = 0x3, 432 .mask = 0x3,
430 .port_enable = 0x3, 433 .port_enable = 0xf,
431 .map = { 434 .map = {
432 /* PM PS SM SS MAP */ 435 /* PM PS SM SS MAP */
433 { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */ 436 { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */
@@ -437,7 +440,7 @@ static const struct piix_map_db ich8_map_db = {
437 }, 440 },
438}; 441};
439 442
440static const struct piix_map_db tolapai_map_db = { 443static const struct piix_map_db ich8_2port_map_db = {
441 .mask = 0x3, 444 .mask = 0x3,
442 .port_enable = 0x3, 445 .port_enable = 0x3,
443 .map = { 446 .map = {
@@ -449,7 +452,19 @@ static const struct piix_map_db tolapai_map_db = {
449 }, 452 },
450}; 453};
451 454
452static const struct piix_map_db ich9_2port_map_db = { 455static const struct piix_map_db ich8m_apple_map_db = {
456 .mask = 0x3,
457 .port_enable = 0x1,
458 .map = {
459 /* PM PS SM SS MAP */
460 { P0, NA, NA, NA }, /* 00b */
461 { RV, RV, RV, RV },
462 { P0, P2, IDE, IDE }, /* 10b */
463 { RV, RV, RV, RV },
464 },
465};
466
467static const struct piix_map_db tolapai_map_db = {
453 .mask = 0x3, 468 .mask = 0x3,
454 .port_enable = 0x3, 469 .port_enable = 0x3,
455 .map = { 470 .map = {
@@ -467,11 +482,21 @@ static const struct piix_map_db *piix_map_db_table[] = {
467 [ich6_sata_ahci] = &ich6_map_db, 482 [ich6_sata_ahci] = &ich6_map_db,
468 [ich6m_sata_ahci] = &ich6m_map_db, 483 [ich6m_sata_ahci] = &ich6m_map_db,
469 [ich8_sata_ahci] = &ich8_map_db, 484 [ich8_sata_ahci] = &ich8_map_db,
485 [ich8_2port_sata] = &ich8_2port_map_db,
486 [ich8m_apple_sata_ahci] = &ich8m_apple_map_db,
470 [tolapai_sata_ahci] = &tolapai_map_db, 487 [tolapai_sata_ahci] = &tolapai_map_db,
471 [ich9_2port_sata] = &ich9_2port_map_db,
472}; 488};
473 489
474static struct ata_port_info piix_port_info[] = { 490static struct ata_port_info piix_port_info[] = {
491 [piix_pata_mwdma] = /* PIIX3 MWDMA only */
492 {
493 .sht = &piix_sht,
494 .flags = PIIX_PATA_FLAGS,
495 .pio_mask = 0x1f, /* pio0-4 */
496 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
497 .port_ops = &piix_pata_ops,
498 },
499
475 [piix_pata_33] = /* PIIX4 at 33MHz */ 500 [piix_pata_33] = /* PIIX4 at 33MHz */
476 { 501 {
477 .sht = &piix_sht, 502 .sht = &piix_sht,
@@ -565,13 +590,15 @@ static struct ata_port_info piix_port_info[] = {
565 .port_ops = &piix_sata_ops, 590 .port_ops = &piix_sata_ops,
566 }, 591 },
567 592
568 [piix_pata_mwdma] = /* PIIX3 MWDMA only */ 593 [ich8_2port_sata] =
569 { 594 {
570 .sht = &piix_sht, 595 .sht = &piix_sht,
571 .flags = PIIX_PATA_FLAGS, 596 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR |
597 PIIX_FLAG_AHCI,
572 .pio_mask = 0x1f, /* pio0-4 */ 598 .pio_mask = 0x1f, /* pio0-4 */
573 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ 599 .mwdma_mask = 0x07, /* mwdma0-2 */
574 .port_ops = &piix_pata_ops, 600 .udma_mask = ATA_UDMA6,
601 .port_ops = &piix_sata_ops,
575 }, 602 },
576 603
577 [tolapai_sata_ahci] = 604 [tolapai_sata_ahci] =
@@ -585,7 +612,7 @@ static struct ata_port_info piix_port_info[] = {
585 .port_ops = &piix_sata_ops, 612 .port_ops = &piix_sata_ops,
586 }, 613 },
587 614
588 [ich9_2port_sata] = 615 [ich8m_apple_sata_ahci] =
589 { 616 {
590 .sht = &piix_sht, 617 .sht = &piix_sht,
591 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR | 618 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR |
@@ -595,6 +622,7 @@ static struct ata_port_info piix_port_info[] = {
595 .udma_mask = ATA_UDMA6, 622 .udma_mask = ATA_UDMA6,
596 .port_ops = &piix_sata_ops, 623 .port_ops = &piix_sata_ops,
597 }, 624 },
625
598}; 626};
599 627
600static struct pci_bits piix_enable_bits[] = { 628static struct pci_bits piix_enable_bits[] = {
@@ -974,6 +1002,13 @@ static int piix_broken_suspend(void)
974 }, 1002 },
975 }, 1003 },
976 { 1004 {
1005 .ident = "SATELLITE U205",
1006 .matches = {
1007 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
1008 DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"),
1009 },
1010 },
1011 {
977 .ident = "Portege M500", 1012 .ident = "Portege M500",
978 .matches = { 1013 .matches = {
979 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), 1014 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
@@ -1086,12 +1121,12 @@ static int piix_disable_ahci(struct pci_dev *pdev)
1086 if (!mmio) 1121 if (!mmio)
1087 return -ENOMEM; 1122 return -ENOMEM;
1088 1123
1089 tmp = readl(mmio + AHCI_GLOBAL_CTL); 1124 tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
1090 if (tmp & AHCI_ENABLE) { 1125 if (tmp & AHCI_ENABLE) {
1091 tmp &= ~AHCI_ENABLE; 1126 tmp &= ~AHCI_ENABLE;
1092 writel(tmp, mmio + AHCI_GLOBAL_CTL); 1127 iowrite32(tmp, mmio + AHCI_GLOBAL_CTL);
1093 1128
1094 tmp = readl(mmio + AHCI_GLOBAL_CTL); 1129 tmp = ioread32(mmio + AHCI_GLOBAL_CTL);
1095 if (tmp & AHCI_ENABLE) 1130 if (tmp & AHCI_ENABLE)
1096 rc = -EIO; 1131 rc = -EIO;
1097 } 1132 }
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 81898036dbca..33f06277b3be 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -30,6 +30,14 @@
30 * Hardware documentation available from http://www.t13.org/ and 30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/ 31 * http://www.sata-io.org/
32 * 32 *
33 * Standards documents from:
34 * http://www.t13.org (ATA standards, PCI DMA IDE spec)
35 * http://www.t10.org (SCSI MMC - for ATAPI MMC)
36 * http://www.sata-io.org (SATA)
37 * http://www.compactflash.org (CF)
38 * http://www.qic.org (QIC157 - Tape and DSC)
39 * http://www.ce-ata.org (CE-ATA: not supported)
40 *
33 */ 41 */
34 42
35#include <linux/kernel.h> 43#include <linux/kernel.h>
@@ -2307,8 +2315,10 @@ int ata_dev_configure(struct ata_device *dev)
2307 } 2315 }
2308 2316
2309 if ((dev->class == ATA_DEV_ATAPI) && 2317 if ((dev->class == ATA_DEV_ATAPI) &&
2310 (atapi_command_packet_set(id) == TYPE_TAPE)) 2318 (atapi_command_packet_set(id) == TYPE_TAPE)) {
2311 dev->max_sectors = ATA_MAX_SECTORS_TAPE; 2319 dev->max_sectors = ATA_MAX_SECTORS_TAPE;
2320 dev->horkage |= ATA_HORKAGE_STUCK_ERR;
2321 }
2312 2322
2313 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) 2323 if (dev->horkage & ATA_HORKAGE_MAX_SEC_128)
2314 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, 2324 dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
@@ -2581,81 +2591,6 @@ void sata_print_link_status(struct ata_link *link)
2581} 2591}
2582 2592
2583/** 2593/**
2584 * __sata_phy_reset - Wake/reset a low-level SATA PHY
2585 * @ap: SATA port associated with target SATA PHY.
2586 *
2587 * This function issues commands to standard SATA Sxxx
2588 * PHY registers, to wake up the phy (and device), and
2589 * clear any reset condition.
2590 *
2591 * LOCKING:
2592 * PCI/etc. bus probe sem.
2593 *
2594 */
2595void __sata_phy_reset(struct ata_port *ap)
2596{
2597 struct ata_link *link = &ap->link;
2598 unsigned long timeout = jiffies + (HZ * 5);
2599 u32 sstatus;
2600
2601 if (ap->flags & ATA_FLAG_SATA_RESET) {
2602 /* issue phy wake/reset */
2603 sata_scr_write_flush(link, SCR_CONTROL, 0x301);
2604 /* Couldn't find anything in SATA I/II specs, but
2605 * AHCI-1.1 10.4.2 says at least 1 ms. */
2606 mdelay(1);
2607 }
2608 /* phy wake/clear reset */
2609 sata_scr_write_flush(link, SCR_CONTROL, 0x300);
2610
2611 /* wait for phy to become ready, if necessary */
2612 do {
2613 msleep(200);
2614 sata_scr_read(link, SCR_STATUS, &sstatus);
2615 if ((sstatus & 0xf) != 1)
2616 break;
2617 } while (time_before(jiffies, timeout));
2618
2619 /* print link status */
2620 sata_print_link_status(link);
2621
2622 /* TODO: phy layer with polling, timeouts, etc. */
2623 if (!ata_link_offline(link))
2624 ata_port_probe(ap);
2625 else
2626 ata_port_disable(ap);
2627
2628 if (ap->flags & ATA_FLAG_DISABLED)
2629 return;
2630
2631 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
2632 ata_port_disable(ap);
2633 return;
2634 }
2635
2636 ap->cbl = ATA_CBL_SATA;
2637}
2638
2639/**
2640 * sata_phy_reset - Reset SATA bus.
2641 * @ap: SATA port associated with target SATA PHY.
2642 *
2643 * This function resets the SATA bus, and then probes
2644 * the bus for devices.
2645 *
2646 * LOCKING:
2647 * PCI/etc. bus probe sem.
2648 *
2649 */
2650void sata_phy_reset(struct ata_port *ap)
2651{
2652 __sata_phy_reset(ap);
2653 if (ap->flags & ATA_FLAG_DISABLED)
2654 return;
2655 ata_bus_reset(ap);
2656}
2657
2658/**
2659 * ata_dev_pair - return other device on cable 2594 * ata_dev_pair - return other device on cable
2660 * @adev: device 2595 * @adev: device
2661 * 2596 *
@@ -5490,11 +5425,19 @@ fsm_start:
5490 * let the EH abort the command or reset the device. 5425 * let the EH abort the command or reset the device.
5491 */ 5426 */
5492 if (unlikely(status & (ATA_ERR | ATA_DF))) { 5427 if (unlikely(status & (ATA_ERR | ATA_DF))) {
5493 ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device " 5428 /* Some ATAPI tape drives forget to clear the ERR bit
5494 "error, dev_stat 0x%X\n", status); 5429 * when doing the next command (mostly request sense).
5495 qc->err_mask |= AC_ERR_HSM; 5430 * We ignore ERR here to workaround and proceed sending
5496 ap->hsm_task_state = HSM_ST_ERR; 5431 * the CDB.
5497 goto fsm_start; 5432 */
5433 if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) {
5434 ata_port_printk(ap, KERN_WARNING,
5435 "DRQ=1 with device error, "
5436 "dev_stat 0x%X\n", status);
5437 qc->err_mask |= AC_ERR_HSM;
5438 ap->hsm_task_state = HSM_ST_ERR;
5439 goto fsm_start;
5440 }
5498 } 5441 }
5499 5442
5500 /* Send the CDB (atapi) or the first data block (ata pio out). 5443 /* Send the CDB (atapi) or the first data block (ata pio out).
@@ -7653,8 +7596,6 @@ EXPORT_SYMBOL_GPL(ata_dev_disable);
7653EXPORT_SYMBOL_GPL(sata_set_spd); 7596EXPORT_SYMBOL_GPL(sata_set_spd);
7654EXPORT_SYMBOL_GPL(sata_link_debounce); 7597EXPORT_SYMBOL_GPL(sata_link_debounce);
7655EXPORT_SYMBOL_GPL(sata_link_resume); 7598EXPORT_SYMBOL_GPL(sata_link_resume);
7656EXPORT_SYMBOL_GPL(sata_phy_reset);
7657EXPORT_SYMBOL_GPL(__sata_phy_reset);
7658EXPORT_SYMBOL_GPL(ata_bus_reset); 7599EXPORT_SYMBOL_GPL(ata_bus_reset);
7659EXPORT_SYMBOL_GPL(ata_std_prereset); 7600EXPORT_SYMBOL_GPL(ata_std_prereset);
7660EXPORT_SYMBOL_GPL(ata_std_softreset); 7601EXPORT_SYMBOL_GPL(ata_std_softreset);
@@ -7725,7 +7666,6 @@ EXPORT_SYMBOL_GPL(ata_port_desc);
7725#ifdef CONFIG_PCI 7666#ifdef CONFIG_PCI
7726EXPORT_SYMBOL_GPL(ata_port_pbar_desc); 7667EXPORT_SYMBOL_GPL(ata_port_pbar_desc);
7727#endif /* CONFIG_PCI */ 7668#endif /* CONFIG_PCI */
7728EXPORT_SYMBOL_GPL(ata_eng_timeout);
7729EXPORT_SYMBOL_GPL(ata_port_schedule_eh); 7669EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
7730EXPORT_SYMBOL_GPL(ata_link_abort); 7670EXPORT_SYMBOL_GPL(ata_link_abort);
7731EXPORT_SYMBOL_GPL(ata_port_abort); 7671EXPORT_SYMBOL_GPL(ata_port_abort);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index ed8813b222a0..0dac69db1fdf 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -559,101 +559,6 @@ void ata_port_wait_eh(struct ata_port *ap)
559 } 559 }
560} 560}
561 561
562/**
563 * ata_qc_timeout - Handle timeout of queued command
564 * @qc: Command that timed out
565 *
566 * Some part of the kernel (currently, only the SCSI layer)
567 * has noticed that the active command on port @ap has not
568 * completed after a specified length of time. Handle this
569 * condition by disabling DMA (if necessary) and completing
570 * transactions, with error if necessary.
571 *
572 * This also handles the case of the "lost interrupt", where
573 * for some reason (possibly hardware bug, possibly driver bug)
574 * an interrupt was not delivered to the driver, even though the
575 * transaction completed successfully.
576 *
577 * TODO: kill this function once old EH is gone.
578 *
579 * LOCKING:
580 * Inherited from SCSI layer (none, can sleep)
581 */
582static void ata_qc_timeout(struct ata_queued_cmd *qc)
583{
584 struct ata_port *ap = qc->ap;
585 u8 host_stat = 0, drv_stat;
586 unsigned long flags;
587
588 DPRINTK("ENTER\n");
589
590 ap->hsm_task_state = HSM_ST_IDLE;
591
592 spin_lock_irqsave(ap->lock, flags);
593
594 switch (qc->tf.protocol) {
595
596 case ATA_PROT_DMA:
597 case ATA_PROT_ATAPI_DMA:
598 host_stat = ap->ops->bmdma_status(ap);
599
600 /* before we do anything else, clear DMA-Start bit */
601 ap->ops->bmdma_stop(qc);
602
603 /* fall through */
604
605 default:
606 ata_altstatus(ap);
607 drv_stat = ata_chk_status(ap);
608
609 /* ack bmdma irq events */
610 ap->ops->irq_clear(ap);
611
612 ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, "
613 "stat 0x%x host_stat 0x%x\n",
614 qc->tf.command, drv_stat, host_stat);
615
616 /* complete taskfile transaction */
617 qc->err_mask |= AC_ERR_TIMEOUT;
618 break;
619 }
620
621 spin_unlock_irqrestore(ap->lock, flags);
622
623 ata_eh_qc_complete(qc);
624
625 DPRINTK("EXIT\n");
626}
627
628/**
629 * ata_eng_timeout - Handle timeout of queued command
630 * @ap: Port on which timed-out command is active
631 *
632 * Some part of the kernel (currently, only the SCSI layer)
633 * has noticed that the active command on port @ap has not
634 * completed after a specified length of time. Handle this
635 * condition by disabling DMA (if necessary) and completing
636 * transactions, with error if necessary.
637 *
638 * This also handles the case of the "lost interrupt", where
639 * for some reason (possibly hardware bug, possibly driver bug)
640 * an interrupt was not delivered to the driver, even though the
641 * transaction completed successfully.
642 *
643 * TODO: kill this function once old EH is gone.
644 *
645 * LOCKING:
646 * Inherited from SCSI layer (none, can sleep)
647 */
648void ata_eng_timeout(struct ata_port *ap)
649{
650 DPRINTK("ENTER\n");
651
652 ata_qc_timeout(ata_qc_from_tag(ap, ap->link.active_tag));
653
654 DPRINTK("EXIT\n");
655}
656
657static int ata_eh_nr_in_flight(struct ata_port *ap) 562static int ata_eh_nr_in_flight(struct ata_port *ap)
658{ 563{
659 unsigned int tag; 564 unsigned int tag;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 94144ed50a6b..a883bb03d4c7 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2485,11 +2485,40 @@ static unsigned int atapi_xlat(struct ata_queued_cmd *qc)
2485 if (!using_pio && ata_check_atapi_dma(qc)) 2485 if (!using_pio && ata_check_atapi_dma(qc))
2486 using_pio = 1; 2486 using_pio = 1;
2487 2487
2488 /* Some controller variants snoop this value for Packet transfers 2488 /* Some controller variants snoop this value for Packet
2489 to do state machine and FIFO management. Thus we want to set it 2489 * transfers to do state machine and FIFO management. Thus we
2490 properly, and for DMA where it is effectively meaningless */ 2490 * want to set it properly, and for DMA where it is
2491 * effectively meaningless.
2492 */
2491 nbytes = min(qc->nbytes, (unsigned int)63 * 1024); 2493 nbytes = min(qc->nbytes, (unsigned int)63 * 1024);
2492 2494
2495 /* Most ATAPI devices which honor transfer chunk size don't
2496 * behave according to the spec when odd chunk size which
2497 * matches the transfer length is specified. If the number of
2498 * bytes to transfer is 2n+1. According to the spec, what
2499 * should happen is to indicate that 2n+1 is going to be
2500 * transferred and transfer 2n+2 bytes where the last byte is
2501 * padding.
2502 *
2503 * In practice, this doesn't happen. ATAPI devices first
2504 * indicate and transfer 2n bytes and then indicate and
2505 * transfer 2 bytes where the last byte is padding.
2506 *
2507 * This inconsistency confuses several controllers which
2508 * perform PIO using DMA such as Intel AHCIs and sil3124/32.
2509 * These controllers use actual number of transferred bytes to
2510 * update DMA poitner and transfer of 4n+2 bytes make those
2511 * controller push DMA pointer by 4n+4 bytes because SATA data
2512 * FISes are aligned to 4 bytes. This causes data corruption
2513 * and buffer overrun.
2514 *
2515 * Always setting nbytes to even number solves this problem
2516 * because then ATAPI devices don't have to split data at 2n
2517 * boundaries.
2518 */
2519 if (nbytes & 0x1)
2520 nbytes++;
2521
2493 qc->tf.lbam = (nbytes & 0xFF); 2522 qc->tf.lbam = (nbytes & 0xFF);
2494 qc->tf.lbah = (nbytes >> 8); 2523 qc->tf.lbah = (nbytes >> 8);
2495 2524
@@ -2869,7 +2898,8 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd,
2869 xlat_func = NULL; 2898 xlat_func = NULL;
2870 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { 2899 if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
2871 /* relay SCSI command to ATAPI device */ 2900 /* relay SCSI command to ATAPI device */
2872 if (unlikely(scmd->cmd_len > dev->cdb_len)) 2901 int len = COMMAND_SIZE(scsi_op);
2902 if (unlikely(len > scmd->cmd_len || len > dev->cdb_len))
2873 goto bad_cdb_len; 2903 goto bad_cdb_len;
2874 2904
2875 xlat_func = atapi_xlat; 2905 xlat_func = atapi_xlat;
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 364534e7aff4..8caf9afc8b90 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -63,6 +63,9 @@ static int ali_cable_override(struct pci_dev *pdev)
63 /* Fujitsu P2000 */ 63 /* Fujitsu P2000 */
64 if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF) 64 if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF)
65 return 1; 65 return 1;
66 /* Mitac 8317 (Winbook-A) and relatives */
67 if (pdev->subsystem_vendor == 0x1071 && pdev->subsystem_device == 0x8317)
68 return 1;
66 /* Systems by DMI */ 69 /* Systems by DMI */
67 if (dmi_check_system(cable_dmi_table)) 70 if (dmi_check_system(cable_dmi_table))
68 return 1; 71 return 1;
@@ -282,6 +285,21 @@ static void ali_lock_sectors(struct ata_device *adev)
282 adev->max_sectors = 255; 285 adev->max_sectors = 255;
283} 286}
284 287
288/**
289 * ali_check_atapi_dma - DMA check for most ALi controllers
290 * @adev: Device
291 *
292 * Called to decide whether commands should be sent by DMA or PIO
293 */
294
295static int ali_check_atapi_dma(struct ata_queued_cmd *qc)
296{
297 /* If its not a media command, its not worth it */
298 if (qc->nbytes < 2048)
299 return -EOPNOTSUPP;
300 return 0;
301}
302
285static struct scsi_host_template ali_sht = { 303static struct scsi_host_template ali_sht = {
286 .module = THIS_MODULE, 304 .module = THIS_MODULE,
287 .name = DRV_NAME, 305 .name = DRV_NAME,
@@ -378,6 +396,7 @@ static struct ata_port_operations ali_c2_port_ops = {
378 .mode_filter = ata_pci_default_filter, 396 .mode_filter = ata_pci_default_filter,
379 .tf_load = ata_tf_load, 397 .tf_load = ata_tf_load,
380 .tf_read = ata_tf_read, 398 .tf_read = ata_tf_read,
399 .check_atapi_dma = ali_check_atapi_dma,
381 .check_status = ata_check_status, 400 .check_status = ata_check_status,
382 .exec_command = ata_exec_command, 401 .exec_command = ata_exec_command,
383 .dev_select = ata_std_dev_select, 402 .dev_select = ata_std_dev_select,
@@ -415,6 +434,7 @@ static struct ata_port_operations ali_c5_port_ops = {
415 .mode_filter = ata_pci_default_filter, 434 .mode_filter = ata_pci_default_filter,
416 .tf_load = ata_tf_load, 435 .tf_load = ata_tf_load,
417 .tf_read = ata_tf_read, 436 .tf_read = ata_tf_read,
437 .check_atapi_dma = ali_check_atapi_dma,
418 .check_status = ata_check_status, 438 .check_status = ata_check_status,
419 .exec_command = ata_exec_command, 439 .exec_command = ata_exec_command,
420 .dev_select = ata_std_dev_select, 440 .dev_select = ata_std_dev_select,
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index b5e38426b815..81db405a5445 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -1145,13 +1145,13 @@ static unsigned char bfin_bmdma_status(struct ata_port *ap)
1145 unsigned short int_status = ATAPI_GET_INT_STATUS(base); 1145 unsigned short int_status = ATAPI_GET_INT_STATUS(base);
1146 1146
1147 if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON|ULTRA_XFER_ON)) { 1147 if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON|ULTRA_XFER_ON)) {
1148 host_stat = ATA_DMA_ACTIVE; 1148 host_stat |= ATA_DMA_ACTIVE;
1149 } 1149 }
1150 if (int_status & (MULTI_DONE_INT|UDMAIN_DONE_INT|UDMAOUT_DONE_INT)) { 1150 if (int_status & (MULTI_DONE_INT|UDMAIN_DONE_INT|UDMAOUT_DONE_INT)) {
1151 host_stat = ATA_DMA_INTR; 1151 host_stat |= ATA_DMA_INTR;
1152 } 1152 }
1153 if (int_status & (MULTI_TERM_INT|UDMAIN_TERM_INT|UDMAOUT_TERM_INT)) { 1153 if (int_status & (MULTI_TERM_INT|UDMAIN_TERM_INT|UDMAOUT_TERM_INT)) {
1154 host_stat = ATA_DMA_ERR; 1154 host_stat |= ATA_DMA_ERR;
1155 } 1155 }
1156 1156
1157 return host_stat; 1157 return host_stat;
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 3816b8605e0d..46dc70e0dee7 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -329,7 +329,7 @@ static int hpt37x_pre_reset(struct ata_link *link, unsigned long deadline)
329 /* Restore state */ 329 /* Restore state */
330 pci_write_config_byte(pdev, 0x5B, scr2); 330 pci_write_config_byte(pdev, 0x5B, scr2);
331 331
332 if (ata66 & (1 << ap->port_no)) 332 if (ata66 & (2 >> ap->port_no))
333 ap->cbl = ATA_CBL_PATA40; 333 ap->cbl = ATA_CBL_PATA40;
334 else 334 else
335 ap->cbl = ATA_CBL_PATA80; 335 ap->cbl = ATA_CBL_PATA80;
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 88ab0e1d353f..4320e7986321 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -75,13 +75,16 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
75 struct ata_host *host; 75 struct ata_host *host;
76 struct ata_port *ap; 76 struct ata_port *ap;
77 void __iomem *cmd_addr, *ctl_addr; 77 void __iomem *cmd_addr, *ctl_addr;
78 int irq = 0;
79 irq_handler_t handler = NULL;
78 80
79 if (pnp_port_valid(idev, 0) == 0) 81 if (pnp_port_valid(idev, 0) == 0)
80 return -ENODEV; 82 return -ENODEV;
81 83
82 /* FIXME: Should selected polled PIO here not fail */ 84 if (pnp_irq_valid(idev, 0)) {
83 if (pnp_irq_valid(idev, 0) == 0) 85 irq = pnp_irq(idev, 0);
84 return -ENODEV; 86 handler = ata_interrupt;
87 }
85 88
86 /* allocate host */ 89 /* allocate host */
87 host = ata_host_alloc(&idev->dev, 1); 90 host = ata_host_alloc(&idev->dev, 1);
@@ -115,7 +118,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
115 (unsigned long long)pnp_port_start(idev, 1)); 118 (unsigned long long)pnp_port_start(idev, 1));
116 119
117 /* activate */ 120 /* activate */
118 return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0, 121 return ata_host_activate(host, irq, handler, 0,
119 &isapnp_sht); 122 &isapnp_sht);
120} 123}
121 124
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 225a7223a726..5b8174d94067 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -80,11 +80,10 @@ static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
80 * actually do our cable checking etc. Thankfully we don't need 80 * actually do our cable checking etc. Thankfully we don't need
81 * to do the plumbing for other cases. 81 * to do the plumbing for other cases.
82 */ 82 */
83 switch (port_map[port]) 83 switch (port_map[port]) {
84 {
85 case PORT_PATA0: 84 case PORT_PATA0:
86 if (control & (1 << 5)) 85 if ((control & (1 << 5)) == 0)
87 return 0; 86 return -ENOENT;
88 if (control & (1 << 3)) /* 40/80 pin primary */ 87 if (control & (1 << 3)) /* 40/80 pin primary */
89 ap->cbl = ATA_CBL_PATA40; 88 ap->cbl = ATA_CBL_PATA40;
90 else 89 else
@@ -93,7 +92,7 @@ static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline)
93 case PORT_PATA1: 92 case PORT_PATA1:
94 /* Bit 21 is set if the port is enabled */ 93 /* Bit 21 is set if the port is enabled */
95 if ((control5 & (1 << 21)) == 0) 94 if ((control5 & (1 << 21)) == 0)
96 return 0; 95 return -ENOENT;
97 if (control5 & (1 << 19)) /* 40/80 pin secondary */ 96 if (control5 & (1 << 19)) /* 40/80 pin secondary */
98 ap->cbl = ATA_CBL_PATA40; 97 ap->cbl = ATA_CBL_PATA40;
99 else 98 else
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 5c1e9cb59ecb..503245a1eafa 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -33,7 +33,7 @@
33#include <linux/libata.h> 33#include <linux/libata.h>
34 34
35#define DRV_NAME "pata_sil680" 35#define DRV_NAME "pata_sil680"
36#define DRV_VERSION "0.4.7" 36#define DRV_VERSION "0.4.8"
37 37
38#define SIL680_MMIO_BAR 5 38#define SIL680_MMIO_BAR 5
39 39
@@ -94,34 +94,6 @@ static int sil680_cable_detect(struct ata_port *ap) {
94} 94}
95 95
96/** 96/**
97 * sil680_bus_reset - reset the SIL680 bus
98 * @link: ATA link to reset
99 * @deadline: deadline jiffies for the operation
100 *
101 * Perform the SIL680 housekeeping when doing an ATA bus reset
102 */
103
104static int sil680_bus_reset(struct ata_link *link, unsigned int *classes,
105 unsigned long deadline)
106{
107 struct ata_port *ap = link->ap;
108 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
109 unsigned long addr = sil680_selreg(ap, 0);
110 u8 reset;
111
112 pci_read_config_byte(pdev, addr, &reset);
113 pci_write_config_byte(pdev, addr, reset | 0x03);
114 udelay(25);
115 pci_write_config_byte(pdev, addr, reset);
116 return ata_std_softreset(link, classes, deadline);
117}
118
119static void sil680_error_handler(struct ata_port *ap)
120{
121 ata_bmdma_drive_eh(ap, ata_std_prereset, sil680_bus_reset, NULL, ata_std_postreset);
122}
123
124/**
125 * sil680_set_piomode - set initial PIO mode data 97 * sil680_set_piomode - set initial PIO mode data
126 * @ap: ATA interface 98 * @ap: ATA interface
127 * @adev: ATA device 99 * @adev: ATA device
@@ -249,7 +221,7 @@ static struct ata_port_operations sil680_port_ops = {
249 221
250 .freeze = ata_bmdma_freeze, 222 .freeze = ata_bmdma_freeze,
251 .thaw = ata_bmdma_thaw, 223 .thaw = ata_bmdma_thaw,
252 .error_handler = sil680_error_handler, 224 .error_handler = ata_bmdma_error_handler,
253 .post_internal_cmd = ata_bmdma_post_internal_cmd, 225 .post_internal_cmd = ata_bmdma_post_internal_cmd,
254 .cable_detect = sil680_cable_detect, 226 .cable_detect = sil680_cable_detect,
255 227
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 3b5be77e861c..87546d9f1ca0 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -55,6 +55,7 @@ static const struct sis_laptop sis_laptop[] = {
55 /* devid, subvendor, subdev */ 55 /* devid, subvendor, subdev */
56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ 56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
57 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */ 57 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
58 { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */
58 /* end marker */ 59 /* end marker */
59 { 0, } 60 { 0, }
60}; 61};
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 187dcb02c681..96fd5260446d 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -63,6 +63,21 @@ enum {
63 SIL24_HOST_BAR = 0, 63 SIL24_HOST_BAR = 0,
64 SIL24_PORT_BAR = 2, 64 SIL24_PORT_BAR = 2,
65 65
66 /* sil24 fetches in chunks of 64bytes. The first block
67 * contains the PRB and two SGEs. From the second block, it's
68 * consisted of four SGEs and called SGT. Calculate the
69 * number of SGTs that fit into one page.
70 */
71 SIL24_PRB_SZ = sizeof(struct sil24_prb)
72 + 2 * sizeof(struct sil24_sge),
73 SIL24_MAX_SGT = (PAGE_SIZE - SIL24_PRB_SZ)
74 / (4 * sizeof(struct sil24_sge)),
75
76 /* This will give us one unused SGEs for ATA. This extra SGE
77 * will be used to store CDB for ATAPI devices.
78 */
79 SIL24_MAX_SGE = 4 * SIL24_MAX_SGT + 1,
80
66 /* 81 /*
67 * Global controller registers (128 bytes @ BAR0) 82 * Global controller registers (128 bytes @ BAR0)
68 */ 83 */
@@ -247,13 +262,13 @@ enum {
247 262
248struct sil24_ata_block { 263struct sil24_ata_block {
249 struct sil24_prb prb; 264 struct sil24_prb prb;
250 struct sil24_sge sge[LIBATA_MAX_PRD]; 265 struct sil24_sge sge[SIL24_MAX_SGE];
251}; 266};
252 267
253struct sil24_atapi_block { 268struct sil24_atapi_block {
254 struct sil24_prb prb; 269 struct sil24_prb prb;
255 u8 cdb[16]; 270 u8 cdb[16];
256 struct sil24_sge sge[LIBATA_MAX_PRD - 1]; 271 struct sil24_sge sge[SIL24_MAX_SGE];
257}; 272};
258 273
259union sil24_cmd_block { 274union sil24_cmd_block {
@@ -378,7 +393,7 @@ static struct scsi_host_template sil24_sht = {
378 .change_queue_depth = ata_scsi_change_queue_depth, 393 .change_queue_depth = ata_scsi_change_queue_depth,
379 .can_queue = SIL24_MAX_CMDS, 394 .can_queue = SIL24_MAX_CMDS,
380 .this_id = ATA_SHT_THIS_ID, 395 .this_id = ATA_SHT_THIS_ID,
381 .sg_tablesize = LIBATA_MAX_PRD, 396 .sg_tablesize = SIL24_MAX_SGE,
382 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 397 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
383 .emulated = ATA_SHT_EMULATED, 398 .emulated = ATA_SHT_EMULATED,
384 .use_clustering = ATA_SHT_USE_CLUSTERING, 399 .use_clustering = ATA_SHT_USE_CLUSTERING,
@@ -1284,6 +1299,7 @@ static void sil24_init_controller(struct ata_host *host)
1284 1299
1285static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1300static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1286{ 1301{
1302 extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
1287 static int printed_version; 1303 static int printed_version;
1288 struct ata_port_info pi = sil24_port_info[ent->driver_data]; 1304 struct ata_port_info pi = sil24_port_info[ent->driver_data];
1289 const struct ata_port_info *ppi[] = { &pi, NULL }; 1305 const struct ata_port_info *ppi[] = { &pi, NULL };
@@ -1292,6 +1308,10 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1292 int i, rc; 1308 int i, rc;
1293 u32 tmp; 1309 u32 tmp;
1294 1310
1311 /* cause link error if sil24_cmd_block is sized wrongly */
1312 if (sizeof(union sil24_cmd_block) != PAGE_SIZE)
1313 __MARKER__sil24_cmd_block_is_sized_wrongly = 1;
1314
1295 if (!printed_version++) 1315 if (!printed_version++)
1296 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1316 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1297 1317