Merge branch 'for-4.5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata

Pull libata fixes from Tejun Heo:

- PORTS_IMPL workaround for very early ahci controllers is misbehaving
on new systems. Disabled on recent ahci versions.

- Old-style PIO state machine had a horrible locking problem. Don't
know how we've been getting away this far. Fixed.

- Other device specific updates.

* 'for-4.5-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/libata:
ahci: Intel DNV device IDs SATA
libata: fix sff host state machine locking while polling
libata-sff: use WARN instead of BUG on illegal host state machine state
libata: disable forced PORTS_IMPL for >= AHCI 1.3
libata: blacklist a Viking flash model for MWDMA corruption
drivers: ata: wake port before DMA stop for ALPM

+61 -25
+20
drivers/ata/ahci.c
··· 264 264 { PCI_VDEVICE(INTEL, 0x3b2b), board_ahci }, /* PCH RAID */ 265 265 { PCI_VDEVICE(INTEL, 0x3b2c), board_ahci }, /* PCH RAID */ 266 266 { PCI_VDEVICE(INTEL, 0x3b2f), board_ahci }, /* PCH AHCI */ 267 + { PCI_VDEVICE(INTEL, 0x19b0), board_ahci }, /* DNV AHCI */ 268 + { PCI_VDEVICE(INTEL, 0x19b1), board_ahci }, /* DNV AHCI */ 269 + { PCI_VDEVICE(INTEL, 0x19b2), board_ahci }, /* DNV AHCI */ 270 + { PCI_VDEVICE(INTEL, 0x19b3), board_ahci }, /* DNV AHCI */ 271 + { PCI_VDEVICE(INTEL, 0x19b4), board_ahci }, /* DNV AHCI */ 272 + { PCI_VDEVICE(INTEL, 0x19b5), board_ahci }, /* DNV AHCI */ 273 + { PCI_VDEVICE(INTEL, 0x19b6), board_ahci }, /* DNV AHCI */ 274 + { PCI_VDEVICE(INTEL, 0x19b7), board_ahci }, /* DNV AHCI */ 275 + { PCI_VDEVICE(INTEL, 0x19bE), board_ahci }, /* DNV AHCI */ 276 + { PCI_VDEVICE(INTEL, 0x19bF), board_ahci }, /* DNV AHCI */ 277 + { PCI_VDEVICE(INTEL, 0x19c0), board_ahci }, /* DNV AHCI */ 278 + { PCI_VDEVICE(INTEL, 0x19c1), board_ahci }, /* DNV AHCI */ 279 + { PCI_VDEVICE(INTEL, 0x19c2), board_ahci }, /* DNV AHCI */ 280 + { PCI_VDEVICE(INTEL, 0x19c3), board_ahci }, /* DNV AHCI */ 281 + { PCI_VDEVICE(INTEL, 0x19c4), board_ahci }, /* DNV AHCI */ 282 + { PCI_VDEVICE(INTEL, 0x19c5), board_ahci }, /* DNV AHCI */ 283 + { PCI_VDEVICE(INTEL, 0x19c6), board_ahci }, /* DNV AHCI */ 284 + { PCI_VDEVICE(INTEL, 0x19c7), board_ahci }, /* DNV AHCI */ 285 + { PCI_VDEVICE(INTEL, 0x19cE), board_ahci }, /* DNV AHCI */ 286 + { PCI_VDEVICE(INTEL, 0x19cF), board_ahci }, /* DNV AHCI */ 267 287 { PCI_VDEVICE(INTEL, 0x1c02), board_ahci }, /* CPT AHCI */ 268 288 { PCI_VDEVICE(INTEL, 0x1c03), board_ahci }, /* CPT AHCI */ 269 289 { PCI_VDEVICE(INTEL, 0x1c04), board_ahci }, /* CPT RAID */
+1
drivers/ata/ahci.h
··· 250 250 AHCI_HFLAG_MULTI_MSI = 0, 251 251 AHCI_HFLAG_MULTI_MSIX = 0, 252 252 #endif 253 + AHCI_HFLAG_WAKE_BEFORE_STOP = (1 << 22), /* wake before DMA stop */ 253 254 254 255 /* ap->flags bits */ 255 256
+1
drivers/ata/ahci_brcmstb.c
··· 317 317 if (IS_ERR(hpriv)) 318 318 return PTR_ERR(hpriv); 319 319 hpriv->plat_data = priv; 320 + hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP; 320 321 321 322 brcm_sata_alpm_init(hpriv); 322 323
+24 -3
drivers/ata/libahci.c
··· 496 496 } 497 497 } 498 498 499 - /* fabricate port_map from cap.nr_ports */ 500 - if (!port_map) { 499 + /* fabricate port_map from cap.nr_ports for < AHCI 1.3 */ 500 + if (!port_map && vers < 0x10300) { 501 501 port_map = (1 << ahci_nr_ports(cap)) - 1; 502 502 dev_warn(dev, "forcing PORTS_IMPL to 0x%x\n", port_map); 503 503 ··· 593 593 int ahci_stop_engine(struct ata_port *ap) 594 594 { 595 595 void __iomem *port_mmio = ahci_port_base(ap); 596 + struct ahci_host_priv *hpriv = ap->host->private_data; 596 597 u32 tmp; 598 + 599 + /* 600 + * On some controllers, stopping a port's DMA engine while the port 601 + * is in ALPM state (partial or slumber) results in failures on 602 + * subsequent DMA engine starts. For those controllers, put the 603 + * port back in active state before stopping its DMA engine. 604 + */ 605 + if ((hpriv->flags & AHCI_HFLAG_WAKE_BEFORE_STOP) && 606 + (ap->link.lpm_policy > ATA_LPM_MAX_POWER) && 607 + ahci_set_lpm(&ap->link, ATA_LPM_MAX_POWER, ATA_LPM_WAKE_ONLY)) { 608 + dev_err(ap->host->dev, "Failed to wake up port before engine stop\n"); 609 + return -EIO; 610 + } 597 611 598 612 tmp = readl(port_mmio + PORT_CMD); 599 613 ··· 703 689 void __iomem *port_mmio = ahci_port_base(ap); 704 690 705 691 if (policy != ATA_LPM_MAX_POWER) { 692 + /* wakeup flag only applies to the max power policy */ 693 + hints &= ~ATA_LPM_WAKE_ONLY; 694 + 706 695 /* 707 696 * Disable interrupts on Phy Ready. This keeps us from 708 697 * getting woken up due to spurious phy ready ··· 721 704 u32 cmd = readl(port_mmio + PORT_CMD); 722 705 723 706 if (policy == ATA_LPM_MAX_POWER || !(hints & ATA_LPM_HIPM)) { 724 - cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE); 707 + if (!(hints & ATA_LPM_WAKE_ONLY)) 708 + cmd &= ~(PORT_CMD_ASP | PORT_CMD_ALPE); 725 709 cmd |= PORT_CMD_ICC_ACTIVE; 726 710 727 711 writel(cmd, port_mmio + PORT_CMD); ··· 730 712 731 713 /* wait 10ms to be sure we've come out of LPM state */ 732 714 ata_msleep(ap, 10); 715 + 716 + if (hints & ATA_LPM_WAKE_ONLY) 717 + return 0; 733 718 } else { 734 719 cmd |= PORT_CMD_ALPE; 735 720 if (policy == ATA_LPM_MIN_POWER)
+1
drivers/ata/libata-core.c
··· 4125 4125 { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA }, 4126 4126 { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA }, 4127 4127 { " 2GB ATA Flash Disk", "ADMA428M", ATA_HORKAGE_NODMA }, 4128 + { "VRFDFC22048UCHC-TE*", NULL, ATA_HORKAGE_NODMA }, 4128 4129 /* Odd clown on sil3726/4726 PMPs */ 4129 4130 { "Config Disk", NULL, ATA_HORKAGE_DISABLE }, 4130 4131
+13 -22
drivers/ata/libata-sff.c
··· 997 997 static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq) 998 998 { 999 999 struct ata_port *ap = qc->ap; 1000 - unsigned long flags; 1001 1000 1002 1001 if (ap->ops->error_handler) { 1003 1002 if (in_wq) { 1004 - spin_lock_irqsave(ap->lock, flags); 1005 - 1006 1003 /* EH might have kicked in while host lock is 1007 1004 * released. 1008 1005 */ ··· 1011 1014 } else 1012 1015 ata_port_freeze(ap); 1013 1016 } 1014 - 1015 - spin_unlock_irqrestore(ap->lock, flags); 1016 1017 } else { 1017 1018 if (likely(!(qc->err_mask & AC_ERR_HSM))) 1018 1019 ata_qc_complete(qc); ··· 1019 1024 } 1020 1025 } else { 1021 1026 if (in_wq) { 1022 - spin_lock_irqsave(ap->lock, flags); 1023 1027 ata_sff_irq_on(ap); 1024 1028 ata_qc_complete(qc); 1025 - spin_unlock_irqrestore(ap->lock, flags); 1026 1029 } else 1027 1030 ata_qc_complete(qc); 1028 1031 } ··· 1041 1048 { 1042 1049 struct ata_link *link = qc->dev->link; 1043 1050 struct ata_eh_info *ehi = &link->eh_info; 1044 - unsigned long flags = 0; 1045 1051 int poll_next; 1052 + 1053 + lockdep_assert_held(ap->lock); 1046 1054 1047 1055 WARN_ON_ONCE((qc->flags & ATA_QCFLAG_ACTIVE) == 0); 1048 1056 ··· 1106 1112 } 1107 1113 } 1108 1114 1109 - /* Send the CDB (atapi) or the first data block (ata pio out). 1110 - * During the state transition, interrupt handler shouldn't 1111 - * be invoked before the data transfer is complete and 1112 - * hsm_task_state is changed. Hence, the following locking. 1113 - */ 1114 - if (in_wq) 1115 - spin_lock_irqsave(ap->lock, flags); 1116 - 1117 1115 if (qc->tf.protocol == ATA_PROT_PIO) { 1118 1116 /* PIO data out protocol. 1119 1117 * send first data block. ··· 1120 1134 } else 1121 1135 /* send CDB */ 1122 1136 atapi_send_cdb(ap, qc); 1123 - 1124 - if (in_wq) 1125 - spin_unlock_irqrestore(ap->lock, flags); 1126 1137 1127 1138 /* if polling, ata_sff_pio_task() handles the rest. 1128 1139 * otherwise, interrupt handler takes over from here. ··· 1279 1296 break; 1280 1297 default: 1281 1298 poll_next = 0; 1282 - BUG(); 1299 + WARN(true, "ata%d: SFF host state machine in invalid state %d", 1300 + ap->print_id, ap->hsm_task_state); 1283 1301 } 1284 1302 1285 1303 return poll_next; ··· 1345 1361 u8 status; 1346 1362 int poll_next; 1347 1363 1364 + spin_lock_irq(ap->lock); 1365 + 1348 1366 BUG_ON(ap->sff_pio_task_link == NULL); 1349 1367 /* qc can be NULL if timeout occurred */ 1350 1368 qc = ata_qc_from_tag(ap, link->active_tag); 1351 1369 if (!qc) { 1352 1370 ap->sff_pio_task_link = NULL; 1353 - return; 1371 + goto out_unlock; 1354 1372 } 1355 1373 1356 1374 fsm_start: ··· 1367 1381 */ 1368 1382 status = ata_sff_busy_wait(ap, ATA_BUSY, 5); 1369 1383 if (status & ATA_BUSY) { 1384 + spin_unlock_irq(ap->lock); 1370 1385 ata_msleep(ap, 2); 1386 + spin_lock_irq(ap->lock); 1387 + 1371 1388 status = ata_sff_busy_wait(ap, ATA_BUSY, 10); 1372 1389 if (status & ATA_BUSY) { 1373 1390 ata_sff_queue_pio_task(link, ATA_SHORT_PAUSE); 1374 - return; 1391 + goto out_unlock; 1375 1392 } 1376 1393 } 1377 1394 ··· 1391 1402 */ 1392 1403 if (poll_next) 1393 1404 goto fsm_start; 1405 + out_unlock: 1406 + spin_unlock_irq(ap->lock); 1394 1407 } 1395 1408 1396 1409 /**
+1
include/linux/libata.h
··· 526 526 enum ata_lpm_hints { 527 527 ATA_LPM_EMPTY = (1 << 0), /* port empty/probing */ 528 528 ATA_LPM_HIPM = (1 << 1), /* may use HIPM */ 529 + ATA_LPM_WAKE_ONLY = (1 << 2), /* only wake up link */ 529 530 }; 530 531 531 532 /* forward declarations */