From de753e5e8678d9674de0a3bda9ead9e770fdbf53 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 12 Nov 2007 17:56:24 +0900 Subject: ata_piix: add SATELLITE U205 to broken suspend list Satellite U205 has alternate product name where the satellite part is all capatalized. Add it to the blacklist. This is reported by Ross Patterson in kernel bugzilla bug #7780. Signed-off-by: Tejun Heo Cc: Ross Patterson --- drivers/ata/ata_piix.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 328ce8a0842..80b735b7097 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -973,6 +973,13 @@ static int piix_broken_suspend(void) DMI_MATCH(DMI_PRODUCT_NAME, "Satellite U205"), }, }, + { + .ident = "SATELLITE U205", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"), + DMI_MATCH(DMI_PRODUCT_NAME, "SATELLITE U205"), + }, + }, { .ident = "Portege M500", .matches = { -- cgit v1.2.3 From 21bef6dd2b419f28c8096a8e30ad86dcbff44c02 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Thu, 15 Nov 2007 10:35:45 +0900 Subject: libata: remove unused functions This patch removes the following obsolete functions: - libata-core.c: __sata_phy_reset() - libata-core.c: sata_phy_reset() - libata-eh.c: ata_qc_timeout() - libata-eh.c: ata_eng_timeout() Signed-off-by: Adrian Bunk Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 78 -------------------------------------- drivers/ata/libata-eh.c | 95 ----------------------------------------------- include/linux/libata.h | 4 -- 3 files changed, 177 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 81898036dbc..1584164e770 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2580,81 +2580,6 @@ void sata_print_link_status(struct ata_link *link) } } -/** - * __sata_phy_reset - Wake/reset a low-level SATA PHY - * @ap: SATA port associated with target SATA PHY. - * - * This function issues commands to standard SATA Sxxx - * PHY registers, to wake up the phy (and device), and - * clear any reset condition. - * - * LOCKING: - * PCI/etc. bus probe sem. - * - */ -void __sata_phy_reset(struct ata_port *ap) -{ - struct ata_link *link = &ap->link; - unsigned long timeout = jiffies + (HZ * 5); - u32 sstatus; - - if (ap->flags & ATA_FLAG_SATA_RESET) { - /* issue phy wake/reset */ - sata_scr_write_flush(link, SCR_CONTROL, 0x301); - /* Couldn't find anything in SATA I/II specs, but - * AHCI-1.1 10.4.2 says at least 1 ms. */ - mdelay(1); - } - /* phy wake/clear reset */ - sata_scr_write_flush(link, SCR_CONTROL, 0x300); - - /* wait for phy to become ready, if necessary */ - do { - msleep(200); - sata_scr_read(link, SCR_STATUS, &sstatus); - if ((sstatus & 0xf) != 1) - break; - } while (time_before(jiffies, timeout)); - - /* print link status */ - sata_print_link_status(link); - - /* TODO: phy layer with polling, timeouts, etc. */ - if (!ata_link_offline(link)) - ata_port_probe(ap); - else - ata_port_disable(ap); - - if (ap->flags & ATA_FLAG_DISABLED) - return; - - if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { - ata_port_disable(ap); - return; - } - - ap->cbl = ATA_CBL_SATA; -} - -/** - * sata_phy_reset - Reset SATA bus. - * @ap: SATA port associated with target SATA PHY. - * - * This function resets the SATA bus, and then probes - * the bus for devices. - * - * LOCKING: - * PCI/etc. bus probe sem. - * - */ -void sata_phy_reset(struct ata_port *ap) -{ - __sata_phy_reset(ap); - if (ap->flags & ATA_FLAG_DISABLED) - return; - ata_bus_reset(ap); -} - /** * ata_dev_pair - return other device on cable * @adev: device @@ -7653,8 +7578,6 @@ EXPORT_SYMBOL_GPL(ata_dev_disable); EXPORT_SYMBOL_GPL(sata_set_spd); EXPORT_SYMBOL_GPL(sata_link_debounce); EXPORT_SYMBOL_GPL(sata_link_resume); -EXPORT_SYMBOL_GPL(sata_phy_reset); -EXPORT_SYMBOL_GPL(__sata_phy_reset); EXPORT_SYMBOL_GPL(ata_bus_reset); EXPORT_SYMBOL_GPL(ata_std_prereset); EXPORT_SYMBOL_GPL(ata_std_softreset); @@ -7725,7 +7648,6 @@ EXPORT_SYMBOL_GPL(ata_port_desc); #ifdef CONFIG_PCI EXPORT_SYMBOL_GPL(ata_port_pbar_desc); #endif /* CONFIG_PCI */ -EXPORT_SYMBOL_GPL(ata_eng_timeout); EXPORT_SYMBOL_GPL(ata_port_schedule_eh); EXPORT_SYMBOL_GPL(ata_link_abort); EXPORT_SYMBOL_GPL(ata_port_abort); diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c index ed8813b222a..0dac69db1fd 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) } } -/** - * ata_qc_timeout - Handle timeout of queued command - * @qc: Command that timed out - * - * Some part of the kernel (currently, only the SCSI layer) - * has noticed that the active command on port @ap has not - * completed after a specified length of time. Handle this - * condition by disabling DMA (if necessary) and completing - * transactions, with error if necessary. - * - * This also handles the case of the "lost interrupt", where - * for some reason (possibly hardware bug, possibly driver bug) - * an interrupt was not delivered to the driver, even though the - * transaction completed successfully. - * - * TODO: kill this function once old EH is gone. - * - * LOCKING: - * Inherited from SCSI layer (none, can sleep) - */ -static void ata_qc_timeout(struct ata_queued_cmd *qc) -{ - struct ata_port *ap = qc->ap; - u8 host_stat = 0, drv_stat; - unsigned long flags; - - DPRINTK("ENTER\n"); - - ap->hsm_task_state = HSM_ST_IDLE; - - spin_lock_irqsave(ap->lock, flags); - - switch (qc->tf.protocol) { - - case ATA_PROT_DMA: - case ATA_PROT_ATAPI_DMA: - host_stat = ap->ops->bmdma_status(ap); - - /* before we do anything else, clear DMA-Start bit */ - ap->ops->bmdma_stop(qc); - - /* fall through */ - - default: - ata_altstatus(ap); - drv_stat = ata_chk_status(ap); - - /* ack bmdma irq events */ - ap->ops->irq_clear(ap); - - ata_dev_printk(qc->dev, KERN_ERR, "command 0x%x timeout, " - "stat 0x%x host_stat 0x%x\n", - qc->tf.command, drv_stat, host_stat); - - /* complete taskfile transaction */ - qc->err_mask |= AC_ERR_TIMEOUT; - break; - } - - spin_unlock_irqrestore(ap->lock, flags); - - ata_eh_qc_complete(qc); - - DPRINTK("EXIT\n"); -} - -/** - * ata_eng_timeout - Handle timeout of queued command - * @ap: Port on which timed-out command is active - * - * Some part of the kernel (currently, only the SCSI layer) - * has noticed that the active command on port @ap has not - * completed after a specified length of time. Handle this - * condition by disabling DMA (if necessary) and completing - * transactions, with error if necessary. - * - * This also handles the case of the "lost interrupt", where - * for some reason (possibly hardware bug, possibly driver bug) - * an interrupt was not delivered to the driver, even though the - * transaction completed successfully. - * - * TODO: kill this function once old EH is gone. - * - * LOCKING: - * Inherited from SCSI layer (none, can sleep) - */ -void ata_eng_timeout(struct ata_port *ap) -{ - DPRINTK("ENTER\n"); - - ata_qc_timeout(ata_qc_from_tag(ap, ap->link.active_tag)); - - DPRINTK("EXIT\n"); -} - static int ata_eh_nr_in_flight(struct ata_port *ap) { unsigned int tag; diff --git a/include/linux/libata.h b/include/linux/libata.h index 56a5673aeba..3f9a6a140a9 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -771,8 +771,6 @@ static inline int ata_port_is_dummy(struct ata_port *ap) extern void sata_print_link_status(struct ata_link *link); extern void ata_port_probe(struct ata_port *); -extern void __sata_phy_reset(struct ata_port *ap); -extern void sata_phy_reset(struct ata_port *ap); extern void ata_bus_reset(struct ata_port *ap); extern int sata_set_spd(struct ata_link *link); extern int sata_link_debounce(struct ata_link *link, @@ -994,8 +992,6 @@ extern void sata_pmp_do_eh(struct ata_port *ap, /* * EH */ -extern void ata_eng_timeout(struct ata_port *ap); - extern void ata_port_schedule_eh(struct ata_port *ap); extern int ata_link_abort(struct ata_link *link); extern int ata_port_abort(struct ata_port *ap); -- cgit v1.2.3 From 2d3b8eea7f2fbafd5d779cc92f7aedbd1ef575e9 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Thu, 15 Nov 2007 10:35:46 +0900 Subject: libata: workaround DRQ=1 ERR=1 for ATAPI tape drives After an error condition, some ATAPI tape drives set DRQ=1 together with ERR=1 when asking the host to transfer the CDB of the next packet command (i.e. request sense). This patch, a revised version of Alan/Mark's previous patch, adds ATA_HORKAGE_STUCK_ERR to workaround the problem by ignoring the ERR bit and proceed sending the CDB. Signed-off-by: Albert Lee Cc: Alan Cox Cc: Mark Lord Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 18 +++++++++++++----- include/linux/libata.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 1584164e770..5478b4c6c6e 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5415,11 +5415,19 @@ fsm_start: * let the EH abort the command or reset the device. */ if (unlikely(status & (ATA_ERR | ATA_DF))) { - ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device " - "error, dev_stat 0x%X\n", status); - qc->err_mask |= AC_ERR_HSM; - ap->hsm_task_state = HSM_ST_ERR; - goto fsm_start; + /* Some ATAPI tape drives forget to clear the ERR bit + * when doing the next command (mostly request sense). + * We ignore ERR here to workaround and proceed sending + * the CDB. + */ + if (!(qc->dev->horkage & ATA_HORKAGE_STUCK_ERR)) { + ata_port_printk(ap, KERN_WARNING, + "DRQ=1 with device error, " + "dev_stat 0x%X\n", status); + qc->err_mask |= AC_ERR_HSM; + ap->hsm_task_state = HSM_ST_ERR; + goto fsm_start; + } } /* Send the CDB (atapi) or the first data block (ata pio out). diff --git a/include/linux/libata.h b/include/linux/libata.h index 3f9a6a140a9..ef52a07c43d 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h @@ -340,6 +340,7 @@ enum { ATA_HORKAGE_HPA_SIZE = (1 << 6), /* native size off by one */ ATA_HORKAGE_IPM = (1 << 7), /* Link PM problems */ ATA_HORKAGE_IVB = (1 << 8), /* cbl det validity bit bugs */ + ATA_HORKAGE_STUCK_ERR = (1 << 9), /* stuck ERR on next PACKET */ /* DMA mask for user DMA control: User visible values; DO NOT renumber */ -- cgit v1.2.3 From f442cd86c1c86c5f44bc2cf23f89536f7e4cfe59 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Thu, 15 Nov 2007 10:35:47 +0900 Subject: libata: use ATA_HORKAGE_STUCK_ERR for ATAPI tape drives Per Mark's comments, maybe all ATAPI tape drives need ATA_HORKAGE_STUCK_ERR. This patch applys ATA_HORKAGE_STUCK_ERR for all ATAPI tape drives. Signed-off-by: Albert Lee Cc: Mark Lord Signed-off-by: Tejun Heo --- drivers/ata/libata-core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 5478b4c6c6e..f7f6ca991e3 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2307,8 +2307,10 @@ int ata_dev_configure(struct ata_device *dev) } if ((dev->class == ATA_DEV_ATAPI) && - (atapi_command_packet_set(id) == TYPE_TAPE)) + (atapi_command_packet_set(id) == TYPE_TAPE)) { dev->max_sectors = ATA_MAX_SECTORS_TAPE; + dev->horkage |= ATA_HORKAGE_STUCK_ERR; + } if (dev->horkage & ATA_HORKAGE_MAX_SEC_128) dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128, -- cgit v1.2.3 From 607126c2a21cd6e9bb807fdd415c1a992f7b9009 Mon Sep 17 00:00:00 2001 From: Mark Lord Date: Thu, 15 Nov 2007 13:13:59 +0900 Subject: libata-scsi: be tolerant of 12-byte ATAPI commands in 16-byte CDBs Sebastian Kemper reported that issuing CD/DVD commands under libata is not fully compatible with ide-scsi. In particular, the GPCMD_SET_STREAMING was being rejected at the host level in some instances. The reason is that libata-scsi insists upon the cmd_len field exactly matching the SCSI opcode being issued, whereas ide-scsi tolerates 12-byte commands contained within a 16-byte (cmd_len) CDB. There doesn't seem to be a good reason for us to not be compatible there, so here is a patch to fix libata-scsi to permit SCSI opcodes so long as they fit within whatever size CDB is provided. Signed-off-by: Mark Lord Signed-off-by: Tejun Heo --- drivers/ata/libata-scsi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 94144ed50a6..a45f6ac3b24 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -2869,7 +2869,8 @@ static inline int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, xlat_func = NULL; if (likely((scsi_op != ATA_16) || !atapi_passthru16)) { /* relay SCSI command to ATAPI device */ - if (unlikely(scmd->cmd_len > dev->cdb_len)) + int len = COMMAND_SIZE(scsi_op); + if (unlikely(len > scmd->cmd_len || len > dev->cdb_len)) goto bad_cdb_len; xlat_func = atapi_xlat; -- cgit v1.2.3 From 1f71d0672ac88e79f444d77102e05292dbc66d0d Mon Sep 17 00:00:00 2001 From: Gabriel C Date: Thu, 15 Nov 2007 13:14:00 +0900 Subject: pata_sis.c: Add Packard Bell EasyNote K5305 to laptops With newer kernels HDD in my old laptop is limited to UDMA 33. With this patch I get UDMA 100 again. Signed-off-by: Gabriel Craciunescu Signed-off-by: Tejun Heo --- drivers/ata/pata_sis.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c index 3b5be77e861..87546d9f1ca 100644 --- a/drivers/ata/pata_sis.c +++ b/drivers/ata/pata_sis.c @@ -55,6 +55,7 @@ static const struct sis_laptop sis_laptop[] = { /* devid, subvendor, subdev */ { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */ { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */ + { 0x5513, 0x1071, 0x8640 }, /* EasyNote K5305 */ /* end marker */ { 0, } }; -- cgit v1.2.3 From 00242ec87608d7a0ed989e54333f3fc8f3d665b0 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 19 Nov 2007 11:24:25 +0900 Subject: ata_piix: reorganize controller IDs Move piix_pata_mwdma to top, rename ich9_2port_sata to ich8_2port_sata for consistency and use automatically incremented values instead of assigning fixed values to ease adding new controller IDs. Signed-off-by: Tejun Heo --- drivers/ata/ata_piix.c | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 80b735b7097..77fea05990d 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -119,18 +119,18 @@ enum { PIIX_80C_SEC = (1 << 7) | (1 << 6), /* controller IDs */ - piix_pata_33 = 0, /* PIIX4 at 33Mhz */ - ich_pata_33 = 1, /* ICH up to UDMA 33 only */ - ich_pata_66 = 2, /* ICH up to 66 Mhz */ - ich_pata_100 = 3, /* ICH up to UDMA 100 */ - ich5_sata = 5, - ich6_sata = 6, - ich6_sata_ahci = 7, - ich6m_sata_ahci = 8, - ich8_sata_ahci = 9, - piix_pata_mwdma = 10, /* PIIX3 MWDMA only */ - tolapai_sata_ahci = 11, - ich9_2port_sata = 12, + piix_pata_mwdma = 0, /* PIIX3 MWDMA only */ + piix_pata_33, /* PIIX4 at 33Mhz */ + ich_pata_33, /* ICH up to UDMA 33 only */ + ich_pata_66, /* ICH up to 66 Mhz */ + ich_pata_100, /* ICH up to UDMA 100 */ + ich5_sata, + ich6_sata, + ich6_sata_ahci, + ich6m_sata_ahci, + ich8_sata_ahci, + ich8_2port_sata, + tolapai_sata_ahci, /* constants for mapping table */ P0 = 0, /* port 0 */ @@ -239,19 +239,19 @@ static const struct pci_device_id piix_pci_tbl[] = { /* SATA Controller 1 IDE (ICH8) */ { 0x8086, 0x2820, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, /* SATA Controller 2 IDE (ICH8) */ - { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, + { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* Mobile SATA Controller IDE (ICH8M) */ { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, /* SATA Controller IDE (ICH9) */ { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, /* SATA Controller IDE (ICH9) */ - { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, + { 0x8086, 0x2921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* SATA Controller IDE (ICH9) */ - { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, + { 0x8086, 0x2926, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* SATA Controller IDE (ICH9M) */ - { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, + { 0x8086, 0x2928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* SATA Controller IDE (ICH9M) */ - { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich9_2port_sata }, + { 0x8086, 0x292d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* SATA Controller IDE (ICH9M) */ { 0x8086, 0x292e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, /* SATA Controller IDE (Tolapai) */ @@ -437,7 +437,7 @@ static const struct piix_map_db ich8_map_db = { }, }; -static const struct piix_map_db tolapai_map_db = { +static const struct piix_map_db ich8_2port_map_db = { .mask = 0x3, .port_enable = 0x3, .map = { @@ -449,7 +449,7 @@ static const struct piix_map_db tolapai_map_db = { }, }; -static const struct piix_map_db ich9_2port_map_db = { +static const struct piix_map_db tolapai_map_db = { .mask = 0x3, .port_enable = 0x3, .map = { @@ -467,11 +467,20 @@ static const struct piix_map_db *piix_map_db_table[] = { [ich6_sata_ahci] = &ich6_map_db, [ich6m_sata_ahci] = &ich6m_map_db, [ich8_sata_ahci] = &ich8_map_db, + [ich8_2port_sata] = &ich8_2port_map_db, [tolapai_sata_ahci] = &tolapai_map_db, - [ich9_2port_sata] = &ich9_2port_map_db, }; static struct ata_port_info piix_port_info[] = { + [piix_pata_mwdma] = /* PIIX3 MWDMA only */ + { + .sht = &piix_sht, + .flags = PIIX_PATA_FLAGS, + .pio_mask = 0x1f, /* pio0-4 */ + .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ + .port_ops = &piix_pata_ops, + }, + [piix_pata_33] = /* PIIX4 at 33MHz */ { .sht = &piix_sht, @@ -565,16 +574,7 @@ static struct ata_port_info piix_port_info[] = { .port_ops = &piix_sata_ops, }, - [piix_pata_mwdma] = /* PIIX3 MWDMA only */ - { - .sht = &piix_sht, - .flags = PIIX_PATA_FLAGS, - .pio_mask = 0x1f, /* pio0-4 */ - .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ - .port_ops = &piix_pata_ops, - }, - - [tolapai_sata_ahci] = + [ich8_2port_sata] = { .sht = &piix_sht, .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR | @@ -585,7 +585,7 @@ static struct ata_port_info piix_port_info[] = { .port_ops = &piix_sata_ops, }, - [ich9_2port_sata] = + [tolapai_sata_ahci] = { .sht = &piix_sht, .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR | -- cgit v1.2.3 From 8d8ef2fb931d1035e1f02095086cfd3f78eafe3f Mon Sep 17 00:00:00 2001 From: Thomas Rohwer Date: Mon, 19 Nov 2007 11:54:24 +0900 Subject: ata_piix: only enable the first port on apple macbook pro ICH8M on apple macbook pro occasionally locks up completely during PCS initialization if ports other than the first one are enabled. Add a separate controller ID and only enable the first port. tj: commit description added and patch updated to fit with the previous controller ID update. Signed-off-by: Thomas Rohwer Signed-off-by: Tejun Heo --- drivers/ata/ata_piix.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 77fea05990d..d5ff1d89bea 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -130,6 +130,7 @@ enum { ich6m_sata_ahci, ich8_sata_ahci, ich8_2port_sata, + ich8m_apple_sata_ahci, /* locks up on second port enable */ tolapai_sata_ahci, /* constants for mapping table */ @@ -242,6 +243,8 @@ static const struct pci_device_id piix_pci_tbl[] = { { 0x8086, 0x2825, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata }, /* Mobile SATA Controller IDE (ICH8M) */ { 0x8086, 0x2828, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, + /* Mobile SATA Controller IDE (ICH8M), Apple */ + { 0x8086, 0x2828, 0x106b, 0x00a0, 0, 0, ich8m_apple_sata_ahci }, /* SATA Controller IDE (ICH9) */ { 0x8086, 0x2920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata_ahci }, /* SATA Controller IDE (ICH9) */ @@ -449,6 +452,18 @@ static const struct piix_map_db ich8_2port_map_db = { }, }; +static const struct piix_map_db ich8m_apple_map_db = { + .mask = 0x3, + .port_enable = 0x1, + .map = { + /* PM PS SM SS MAP */ + { P0, NA, NA, NA }, /* 00b */ + { RV, RV, RV, RV }, + { P0, P2, IDE, IDE }, /* 10b */ + { RV, RV, RV, RV }, + }, +}; + static const struct piix_map_db tolapai_map_db = { .mask = 0x3, .port_enable = 0x3, @@ -468,6 +483,7 @@ static const struct piix_map_db *piix_map_db_table[] = { [ich6m_sata_ahci] = &ich6m_map_db, [ich8_sata_ahci] = &ich8_map_db, [ich8_2port_sata] = &ich8_2port_map_db, + [ich8m_apple_sata_ahci] = &ich8m_apple_map_db, [tolapai_sata_ahci] = &tolapai_map_db, }; @@ -595,6 +611,18 @@ static struct ata_port_info piix_port_info[] = { .udma_mask = ATA_UDMA6, .port_ops = &piix_sata_ops, }, + + [ich8m_apple_sata_ahci] = + { + .sht = &piix_sht, + .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SCR | + PIIX_FLAG_AHCI, + .pio_mask = 0x1f, /* pio0-4 */ + .mwdma_mask = 0x07, /* mwdma0-2 */ + .udma_mask = ATA_UDMA6, + .port_ops = &piix_sata_ops, + }, + }; static struct pci_bits piix_enable_bits[] = { -- cgit v1.2.3 From a0ce9aca97ccf71dc969b44a4c9b3c36da0be362 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 19 Nov 2007 12:06:37 +0900 Subject: ata_piix: port enable for the first SATA controller of ICH8 is 0xf not 0x3 ICH8 and 9 use two SFF controllers to show 6 SATA ports. The first controllre hosts the first 4 ports while the second one hosts the last 2. The PCS register of the first controller encompasses the first four ports or all six ports depending on configuration while PCS of the second controller controls the last two ports. Using 0xf for the first controller and 0x3 for the second controller always result in the correct configuration. Signed-off-by: Tejun Heo --- drivers/ata/ata_piix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index d5ff1d89bea..671e7966500 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -430,7 +430,7 @@ static const struct piix_map_db ich6m_map_db = { static const struct piix_map_db ich8_map_db = { .mask = 0x3, - .port_enable = 0x3, + .port_enable = 0xf, .map = { /* PM PS SM SS MAP */ { P0, P2, P1, P3 }, /* 00b (hardwired when in AHCI) */ -- cgit v1.2.3 From dd05c199cd02ffd2ac49eb29677f1468910996a8 Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Fri, 16 Nov 2007 19:50:04 +0300 Subject: pata_sil680: kill bogus reset code (take 2) Since writing to two reserved bits ain't much of a housekeeping, I think it's time we get rid of the custom error handler in this driver. ;-) Signed-off-by: Sergei Shtylyov Signed-off-by: Jeff Garzik --- drivers/ata/pata_sil680.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c index 5c1e9cb59ec..503245a1eaf 100644 --- a/drivers/ata/pata_sil680.c +++ b/drivers/ata/pata_sil680.c @@ -33,7 +33,7 @@ #include #define DRV_NAME "pata_sil680" -#define DRV_VERSION "0.4.7" +#define DRV_VERSION "0.4.8" #define SIL680_MMIO_BAR 5 @@ -93,34 +93,6 @@ static int sil680_cable_detect(struct ata_port *ap) { return ATA_CBL_PATA40; } -/** - * sil680_bus_reset - reset the SIL680 bus - * @link: ATA link to reset - * @deadline: deadline jiffies for the operation - * - * Perform the SIL680 housekeeping when doing an ATA bus reset - */ - -static int sil680_bus_reset(struct ata_link *link, unsigned int *classes, - unsigned long deadline) -{ - struct ata_port *ap = link->ap; - struct pci_dev *pdev = to_pci_dev(ap->host->dev); - unsigned long addr = sil680_selreg(ap, 0); - u8 reset; - - pci_read_config_byte(pdev, addr, &reset); - pci_write_config_byte(pdev, addr, reset | 0x03); - udelay(25); - pci_write_config_byte(pdev, addr, reset); - return ata_std_softreset(link, classes, deadline); -} - -static void sil680_error_handler(struct ata_port *ap) -{ - ata_bmdma_drive_eh(ap, ata_std_prereset, sil680_bus_reset, NULL, ata_std_postreset); -} - /** * sil680_set_piomode - set initial PIO mode data * @ap: ATA interface @@ -249,7 +221,7 @@ static struct ata_port_operations sil680_port_ops = { .freeze = ata_bmdma_freeze, .thaw = ata_bmdma_thaw, - .error_handler = sil680_error_handler, + .error_handler = ata_bmdma_error_handler, .post_internal_cmd = ata_bmdma_post_internal_cmd, .cable_detect = sil680_cable_detect, -- cgit v1.2.3 From 0706efd61edfcf958c2c19669aa65c2180ec3ba0 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 19 Nov 2007 18:06:11 +0900 Subject: pata_jmicron: fix disabled port handling in jmicron_pre_reset() There are two bugs in disabled port handling. * test in PORT_PATA0 is reversed * ->prereset should return -ENOENT for disabled ports not 0 The first bug makes the PATA channel considered disabled but the second bug saves the day by returning 0. The net result is that cable is always left at ATA_CBL_UNKNOWN. This results in false 80c configuration and thus transfer errors. This patch fixes both bugs. Signed-off-by: Tejun Heo Signed-off-by: Jeff Garzik --- drivers/ata/pata_jmicron.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c index 225a7223a72..5b8174d9406 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) * actually do our cable checking etc. Thankfully we don't need * to do the plumbing for other cases. */ - switch (port_map[port]) - { + switch (port_map[port]) { case PORT_PATA0: - if (control & (1 << 5)) - return 0; + if ((control & (1 << 5)) == 0) + return -ENOENT; if (control & (1 << 3)) /* 40/80 pin primary */ ap->cbl = ATA_CBL_PATA40; else @@ -93,7 +92,7 @@ static int jmicron_pre_reset(struct ata_link *link, unsigned long deadline) case PORT_PATA1: /* Bit 21 is set if the port is enabled */ if ((control5 & (1 << 21)) == 0) - return 0; + return -ENOENT; if (control5 & (1 << 19)) /* 40/80 pin secondary */ ap->cbl = ATA_CBL_PATA40; else -- cgit v1.2.3 From 93e2618e0cee1f5b5a4cfc1b7521939318dbf5bb Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Thu, 22 Nov 2007 18:46:57 +0900 Subject: sata_sil24: fix sg table sizing sil24 unnecessarily used LIBATA_MAX_PRD and ATAPI sg table was short by one entry which might cause very obscure problems. This patch updates sg table sizing such that * One full page is used for PRB + sg table. On 4k page, this results in 253 sg's. * Make ATAPI sg block properly sized. * Make build fail if command block size doesn't equal PAGE_SIZE. Signed-off-by: Tejun Heo Signed-off-by: Jeff Garzik --- drivers/ata/sata_sil24.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c index 187dcb02c68..96fd5260446 100644 --- a/drivers/ata/sata_sil24.c +++ b/drivers/ata/sata_sil24.c @@ -63,6 +63,21 @@ enum { SIL24_HOST_BAR = 0, SIL24_PORT_BAR = 2, + /* sil24 fetches in chunks of 64bytes. The first block + * contains the PRB and two SGEs. From the second block, it's + * consisted of four SGEs and called SGT. Calculate the + * number of SGTs that fit into one page. + */ + SIL24_PRB_SZ = sizeof(struct sil24_prb) + + 2 * sizeof(struct sil24_sge), + SIL24_MAX_SGT = (PAGE_SIZE - SIL24_PRB_SZ) + / (4 * sizeof(struct sil24_sge)), + + /* This will give us one unused SGEs for ATA. This extra SGE + * will be used to store CDB for ATAPI devices. + */ + SIL24_MAX_SGE = 4 * SIL24_MAX_SGT + 1, + /* * Global controller registers (128 bytes @ BAR0) */ @@ -247,13 +262,13 @@ enum { struct sil24_ata_block { struct sil24_prb prb; - struct sil24_sge sge[LIBATA_MAX_PRD]; + struct sil24_sge sge[SIL24_MAX_SGE]; }; struct sil24_atapi_block { struct sil24_prb prb; u8 cdb[16]; - struct sil24_sge sge[LIBATA_MAX_PRD - 1]; + struct sil24_sge sge[SIL24_MAX_SGE]; }; union sil24_cmd_block { @@ -378,7 +393,7 @@ static struct scsi_host_template sil24_sht = { .change_queue_depth = ata_scsi_change_queue_depth, .can_queue = SIL24_MAX_CMDS, .this_id = ATA_SHT_THIS_ID, - .sg_tablesize = LIBATA_MAX_PRD, + .sg_tablesize = SIL24_MAX_SGE, .cmd_per_lun = ATA_SHT_CMD_PER_LUN, .emulated = ATA_SHT_EMULATED, .use_clustering = ATA_SHT_USE_CLUSTERING, @@ -1284,6 +1299,7 @@ static void sil24_init_controller(struct ata_host *host) static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) { + extern int __MARKER__sil24_cmd_block_is_sized_wrongly; static int printed_version; struct ata_port_info pi = sil24_port_info[ent->driver_data]; 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) int i, rc; u32 tmp; + /* cause link error if sil24_cmd_block is sized wrongly */ + if (sizeof(union sil24_cmd_block) != PAGE_SIZE) + __MARKER__sil24_cmd_block_is_sized_wrongly = 1; + if (!printed_version++) dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); -- cgit v1.2.3 From c47a631f8bfad08a6001f8dd479004caa5059a75 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:28:28 +0000 Subject: ata_piix: Invalid use of writel/readl with iomap Should use ioread* as discussed previously Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/ata_piix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c index 671e7966500..483269db2c7 100644 --- a/drivers/ata/ata_piix.c +++ b/drivers/ata/ata_piix.c @@ -1121,12 +1121,12 @@ static int piix_disable_ahci(struct pci_dev *pdev) if (!mmio) return -ENOMEM; - tmp = readl(mmio + AHCI_GLOBAL_CTL); + tmp = ioread32(mmio + AHCI_GLOBAL_CTL); if (tmp & AHCI_ENABLE) { tmp &= ~AHCI_ENABLE; - writel(tmp, mmio + AHCI_GLOBAL_CTL); + iowrite32(tmp, mmio + AHCI_GLOBAL_CTL); - tmp = readl(mmio + AHCI_GLOBAL_CTL); + tmp = ioread32(mmio + AHCI_GLOBAL_CTL); if (tmp & AHCI_ENABLE) rc = -EIO; } -- cgit v1.2.3 From 92c52c52e123e6fabb85392b16bcdbdb64cfdc1c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:30:16 +0000 Subject: libata-core: List more documentation sources for reference And next time I'll be able to find the ata tape spec easily... Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/libata-core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index f7f6ca991e3..33f06277b3b 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -30,6 +30,14 @@ * Hardware documentation available from http://www.t13.org/ and * http://www.sata-io.org/ * + * Standards documents from: + * http://www.t13.org (ATA standards, PCI DMA IDE spec) + * http://www.t10.org (SCSI MMC - for ATAPI MMC) + * http://www.sata-io.org (SATA) + * http://www.compactflash.org (CF) + * http://www.qic.org (QIC157 - Tape and DSC) + * http://www.ce-ata.org (CE-ATA: not supported) + * */ #include -- cgit v1.2.3 From 8f59a13accd78e9759548b40aa2a053938a01ec7 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:36:28 +0000 Subject: pata_ali: Add Mitac 8317 and derivatives Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/pata_ali.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index 364534e7aff..d12f386c150 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) /* Fujitsu P2000 */ if (pdev->subsystem_vendor == 0x10CF && pdev->subsystem_device == 0x10AF) return 1; + /* Mitac 8317 (Winbook-A) and relatives */ + if (pdev->subsystem_vendor == 0x1071 && pdev->subsystem_device == 0x8317) + return 1; /* Systems by DMI */ if (dmi_check_system(cable_dmi_table)) return 1; -- cgit v1.2.3 From 498222f323ab11331dc5cfedb97752477f0fe42a Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:37:58 +0000 Subject: pata_ali: Lots of problems still showing up with small ATAPI DMA Hopefully there is a better long term solution but for now lets favour reliability. Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/pata_ali.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index d12f386c150..62aa2f90329 100644 --- a/drivers/ata/pata_ali.c +++ b/drivers/ata/pata_ali.c @@ -285,6 +285,21 @@ static void ali_lock_sectors(struct ata_device *adev) adev->max_sectors = 255; } +/** + * ali_check_atapi_dma - DMA check for most ALi controllers + * @adev: Device + * + * Called to decide whether commands should be sent by DMA or PIO + */ + +static int ali_check_atapi_dma(struct ata_queued_cmd *qc) +{ + /* If its not a media command, its not worth it */ + if (qc->nbytes < 2048) + return -EOPNOTSUPP; + return 0; +} + static struct scsi_host_template ali_sht = { .module = THIS_MODULE, .name = DRV_NAME, @@ -381,6 +396,7 @@ static struct ata_port_operations ali_c2_port_ops = { .mode_filter = ata_pci_default_filter, .tf_load = ata_tf_load, .tf_read = ata_tf_read, + .check_atapi_dma = ali_check_atapi_dma, .check_status = ata_check_status, .exec_command = ata_exec_command, .dev_select = ata_std_dev_select, @@ -418,6 +434,7 @@ static struct ata_port_operations ali_c5_port_ops = { .mode_filter = ata_pci_default_filter, .tf_load = ata_tf_load, .tf_read = ata_tf_read, + .check_atapi_dma = ali_check_atapi_dma, .check_status = ata_check_status, .exec_command = ata_exec_command, .dev_select = ata_std_dev_select, -- cgit v1.2.3 From 22d5c760c8bc2f146d5c31f69de7f52efd118992 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:39:13 +0000 Subject: pata_hpt37x: Fix cable detect bug spotted by Sergei Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/pata_hpt37x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c index 3816b8605e0..46dc70e0dee 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) /* Restore state */ pci_write_config_byte(pdev, 0x5B, scr2); - if (ata66 & (1 << ap->port_no)) + if (ata66 & (2 >> ap->port_no)) ap->cbl = ATA_CBL_PATA40; else ap->cbl = ATA_CBL_PATA80; -- cgit v1.2.3 From 91e33d31096a2b518ae5744c345af15c1ff06fd5 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Mon, 19 Nov 2007 14:41:05 +0000 Subject: pata_isapnp: Polled devices If a card has no IRQ then pass no interrupt handler but allow polled usage. Signed-off-by: Alan Cox Signed-off-by: Jeff Garzik --- drivers/ata/pata_isapnp.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c index 88ab0e1d353..4320e798632 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 struct ata_host *host; struct ata_port *ap; void __iomem *cmd_addr, *ctl_addr; + int irq = 0; + irq_handler_t handler = NULL; if (pnp_port_valid(idev, 0) == 0) return -ENODEV; - /* FIXME: Should selected polled PIO here not fail */ - if (pnp_irq_valid(idev, 0) == 0) - return -ENODEV; + if (pnp_irq_valid(idev, 0)) { + irq = pnp_irq(idev, 0); + handler = ata_interrupt; + } /* allocate host */ 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 (unsigned long long)pnp_port_start(idev, 1)); /* activate */ - return ata_host_activate(host, pnp_irq(idev, 0), ata_interrupt, 0, + return ata_host_activate(host, irq, handler, 0, &isapnp_sht); } -- cgit v1.2.3 From 2541d0ca7e4645d7e2d295eb241c318a7f875f3a Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Fri, 23 Nov 2007 21:08:42 -0500 Subject: pata_ali: trim trailing whitespace (fix checkpatch complaints) Signed-off-by: Jeff Garzik --- drivers/ata/pata_ali.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c index 62aa2f90329..8caf9afc8b9 100644 --- a/drivers/ata/pata_ali.c +++ b/drivers/ata/pata_ali.c @@ -291,7 +291,7 @@ static void ali_lock_sectors(struct ata_device *adev) * * Called to decide whether commands should be sent by DMA or PIO */ - + static int ali_check_atapi_dma(struct ata_queued_cmd *qc) { /* If its not a media command, its not worth it */ -- cgit v1.2.3 From dc86f6d4183c79a08fa01c08dd2191895c0c7eb0 Mon Sep 17 00:00:00 2001 From: sonic zhang Date: Mon, 26 Nov 2007 17:50:56 +0800 Subject: libata: Return proper ATA INT status in pata_bf54x driver INT status can be OR. Signed-off-by: Sonic Zhang Signed-off-by: Jeff Garzik --- drivers/ata/pata_bf54x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c index b5e38426b81..81db405a544 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) unsigned short int_status = ATAPI_GET_INT_STATUS(base); if (ATAPI_GET_STATUS(base) & (MULTI_XFER_ON|ULTRA_XFER_ON)) { - host_stat = ATA_DMA_ACTIVE; + host_stat |= ATA_DMA_ACTIVE; } if (int_status & (MULTI_DONE_INT|UDMAIN_DONE_INT|UDMAOUT_DONE_INT)) { - host_stat = ATA_DMA_INTR; + host_stat |= ATA_DMA_INTR; } if (int_status & (MULTI_TERM_INT|UDMAIN_TERM_INT|UDMAOUT_TERM_INT)) { - host_stat = ATA_DMA_ERR; + host_stat |= ATA_DMA_ERR; } return host_stat; -- cgit v1.2.3 From e190222d04cb1119c62876ac87cf9b9403ba3bd5 Mon Sep 17 00:00:00 2001 From: Tejun Heo Date: Mon, 26 Nov 2007 20:58:02 +0900 Subject: libata: bump transfer chunk size if it's odd None of the drives I have follows what the standard says about transfer chunk size. Of the four SATA and six PATA ATAPI devices tested, four ignore transfer chunk size completely and the ones which honor it don't behave according to the spec when it's odd. According to the spec, transfer chunk size can be odd if the amount of data to transfer equals or is smaller than the chunk size and the device can indicate the same odd number and transfer the whole thing at one go with a pad byte appended. However, in reality, none of the drives I have does that. They all indicate and transfer even number of bytes one byte shorter than the chunk size first; then indicate and transfer two bytes, which is clearly out of spec. In addition to unnecessary second PIO data phase, this also creates a weird problem when combined with SATA controllers which perform PIO via DMA. Some of these controllers use actualy number of bytes received to update DMA pointer so chunks which are sized 4n + 2 makes DMA pointer off by two bytes. This causes data corruption and buffer overruns. This patch rounds nbytes up to the nearest even number such that ATAPI devices don't split data transfer for the last odd byte. This shouldn't confuse controllers which depend on transfer chunk size as devices will report the rounded-up number, actually transfer that much and padding buffer is there to receive them. Signed-off-by: Tejun Heo Signed-off-by: Jeff Garzik --- drivers/ata/libata-scsi.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index a45f6ac3b24..a883bb03d4c 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) if (!using_pio && ata_check_atapi_dma(qc)) using_pio = 1; - /* Some controller variants snoop this value for Packet transfers - to do state machine and FIFO management. Thus we want to set it - properly, and for DMA where it is effectively meaningless */ + /* Some controller variants snoop this value for Packet + * transfers to do state machine and FIFO management. Thus we + * want to set it properly, and for DMA where it is + * effectively meaningless. + */ nbytes = min(qc->nbytes, (unsigned int)63 * 1024); + /* Most ATAPI devices which honor transfer chunk size don't + * behave according to the spec when odd chunk size which + * matches the transfer length is specified. If the number of + * bytes to transfer is 2n+1. According to the spec, what + * should happen is to indicate that 2n+1 is going to be + * transferred and transfer 2n+2 bytes where the last byte is + * padding. + * + * In practice, this doesn't happen. ATAPI devices first + * indicate and transfer 2n bytes and then indicate and + * transfer 2 bytes where the last byte is padding. + * + * This inconsistency confuses several controllers which + * perform PIO using DMA such as Intel AHCIs and sil3124/32. + * These controllers use actual number of transferred bytes to + * update DMA poitner and transfer of 4n+2 bytes make those + * controller push DMA pointer by 4n+4 bytes because SATA data + * FISes are aligned to 4 bytes. This causes data corruption + * and buffer overrun. + * + * Always setting nbytes to even number solves this problem + * because then ATAPI devices don't have to split data at 2n + * boundaries. + */ + if (nbytes & 0x1) + nbytes++; + qc->tf.lbam = (nbytes & 0xFF); qc->tf.lbah = (nbytes >> 8); -- cgit v1.2.3