aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r--drivers/scsi/libata-core.c469
1 files changed, 162 insertions, 307 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c
index 0314abd97f2d..d279666dcb38 100644
--- a/drivers/scsi/libata-core.c
+++ b/drivers/scsi/libata-core.c
@@ -64,9 +64,9 @@
64static unsigned int ata_dev_init_params(struct ata_port *ap, 64static unsigned int ata_dev_init_params(struct ata_port *ap,
65 struct ata_device *dev); 65 struct ata_device *dev);
66static void ata_set_mode(struct ata_port *ap); 66static void ata_set_mode(struct ata_port *ap);
67static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev); 67static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
68static unsigned int ata_dev_xfermask(struct ata_port *ap, 68 struct ata_device *dev);
69 struct ata_device *dev); 69static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev);
70 70
71static unsigned int ata_unique_id = 1; 71static unsigned int ata_unique_id = 1;
72static struct workqueue_struct *ata_wq; 72static struct workqueue_struct *ata_wq;
@@ -190,7 +190,7 @@ static const u8 ata_rw_cmds[] = {
190 * ata_rwcmd_protocol - set taskfile r/w commands and protocol 190 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
191 * @qc: command to examine and configure 191 * @qc: command to examine and configure
192 * 192 *
193 * Examine the device configuration and tf->flags to calculate 193 * Examine the device configuration and tf->flags to calculate
194 * the proper read/write commands and protocol to use. 194 * the proper read/write commands and protocol to use.
195 * 195 *
196 * LOCKING: 196 * LOCKING:
@@ -203,7 +203,7 @@ int ata_rwcmd_protocol(struct ata_queued_cmd *qc)
203 u8 cmd; 203 u8 cmd;
204 204
205 int index, fua, lba48, write; 205 int index, fua, lba48, write;
206 206
207 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0; 207 fua = (tf->flags & ATA_TFLAG_FUA) ? 4 : 0;
208 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0; 208 lba48 = (tf->flags & ATA_TFLAG_LBA48) ? 2 : 0;
209 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0; 209 write = (tf->flags & ATA_TFLAG_WRITE) ? 1 : 0;
@@ -252,6 +252,29 @@ static unsigned int ata_pack_xfermask(unsigned int pio_mask,
252 ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA); 252 ((udma_mask << ATA_SHIFT_UDMA) & ATA_MASK_UDMA);
253} 253}
254 254
255/**
256 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
257 * @xfer_mask: xfer_mask to unpack
258 * @pio_mask: resulting pio_mask
259 * @mwdma_mask: resulting mwdma_mask
260 * @udma_mask: resulting udma_mask
261 *
262 * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask.
263 * Any NULL distination masks will be ignored.
264 */
265static void ata_unpack_xfermask(unsigned int xfer_mask,
266 unsigned int *pio_mask,
267 unsigned int *mwdma_mask,
268 unsigned int *udma_mask)
269{
270 if (pio_mask)
271 *pio_mask = (xfer_mask & ATA_MASK_PIO) >> ATA_SHIFT_PIO;
272 if (mwdma_mask)
273 *mwdma_mask = (xfer_mask & ATA_MASK_MWDMA) >> ATA_SHIFT_MWDMA;
274 if (udma_mask)
275 *udma_mask = (xfer_mask & ATA_MASK_UDMA) >> ATA_SHIFT_UDMA;
276}
277
255static const struct ata_xfer_ent { 278static const struct ata_xfer_ent {
256 unsigned int shift, bits; 279 unsigned int shift, bits;
257 u8 base; 280 u8 base;
@@ -372,6 +395,15 @@ static const char *ata_mode_string(unsigned int xfer_mask)
372 return "<n/a>"; 395 return "<n/a>";
373} 396}
374 397
398static void ata_dev_disable(struct ata_port *ap, struct ata_device *dev)
399{
400 if (ata_dev_present(dev)) {
401 printk(KERN_WARNING "ata%u: dev %u disabled\n",
402 ap->id, dev->devno);
403 dev->class++;
404 }
405}
406
375/** 407/**
376 * ata_pio_devchk - PATA device presence detection 408 * ata_pio_devchk - PATA device presence detection
377 * @ap: ATA channel to examine 409 * @ap: ATA channel to examine
@@ -987,6 +1019,22 @@ ata_exec_internal(struct ata_port *ap, struct ata_device *dev,
987 1019
988 ata_qc_free(qc); 1020 ata_qc_free(qc);
989 1021
1022 /* XXX - Some LLDDs (sata_mv) disable port on command failure.
1023 * Until those drivers are fixed, we detect the condition
1024 * here, fail the command with AC_ERR_SYSTEM and reenable the
1025 * port.
1026 *
1027 * Note that this doesn't change any behavior as internal
1028 * command failure results in disabling the device in the
1029 * higher layer for LLDDs without new reset/EH callbacks.
1030 *
1031 * Kill the following code as soon as those drivers are fixed.
1032 */
1033 if (ap->flags & ATA_FLAG_PORT_DISABLED) {
1034 err_mask |= AC_ERR_SYSTEM;
1035 ata_port_probe(ap);
1036 }
1037
990 return err_mask; 1038 return err_mask;
991} 1039}
992 1040
@@ -1007,7 +1055,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1007 return 0; 1055 return 0;
1008 if (speed > 2) 1056 if (speed > 2)
1009 return 1; 1057 return 1;
1010 1058
1011 /* If we have no drive specific rule, then PIO 2 is non IORDY */ 1059 /* If we have no drive specific rule, then PIO 2 is non IORDY */
1012 1060
1013 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */ 1061 if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
@@ -1305,7 +1353,7 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1305 if (print_info) 1353 if (print_info)
1306 printk(KERN_INFO "ata%u(%u): applying bridge limits\n", 1354 printk(KERN_INFO "ata%u(%u): applying bridge limits\n",
1307 ap->id, dev->devno); 1355 ap->id, dev->devno);
1308 ap->udma_mask &= ATA_UDMA5; 1356 dev->udma_mask &= ATA_UDMA5;
1309 dev->max_sectors = ATA_MAX_SECTORS; 1357 dev->max_sectors = ATA_MAX_SECTORS;
1310 } 1358 }
1311 1359
@@ -1316,8 +1364,6 @@ static int ata_dev_configure(struct ata_port *ap, struct ata_device *dev,
1316 return 0; 1364 return 0;
1317 1365
1318err_out_nosup: 1366err_out_nosup:
1319 printk(KERN_WARNING "ata%u: dev %u not supported, ignoring\n",
1320 ap->id, dev->devno);
1321 DPRINTK("EXIT, err\n"); 1367 DPRINTK("EXIT, err\n");
1322 return rc; 1368 return rc;
1323} 1369}
@@ -1384,7 +1430,7 @@ static int ata_bus_probe(struct ata_port *ap)
1384 } 1430 }
1385 1431
1386 if (ata_dev_configure(ap, dev, 1)) { 1432 if (ata_dev_configure(ap, dev, 1)) {
1387 dev->class++; /* disable device */ 1433 ata_dev_disable(ap, dev);
1388 continue; 1434 continue;
1389 } 1435 }
1390 1436
@@ -1530,6 +1576,23 @@ void sata_phy_reset(struct ata_port *ap)
1530} 1576}
1531 1577
1532/** 1578/**
1579 * ata_dev_pair - return other device on cable
1580 * @ap: port
1581 * @adev: device
1582 *
1583 * Obtain the other device on the same cable, or if none is
1584 * present NULL is returned
1585 */
1586
1587struct ata_device *ata_dev_pair(struct ata_port *ap, struct ata_device *adev)
1588{
1589 struct ata_device *pair = &ap->device[1 - adev->devno];
1590 if (!ata_dev_present(pair))
1591 return NULL;
1592 return pair;
1593}
1594
1595/**
1533 * ata_port_disable - Disable port. 1596 * ata_port_disable - Disable port.
1534 * @ap: Port to be disabled. 1597 * @ap: Port to be disabled.
1535 * 1598 *
@@ -1557,7 +1620,7 @@ void ata_port_disable(struct ata_port *ap)
1557 * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds). 1620 * PIO 0-5, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
1558 * These were taken from ATA/ATAPI-6 standard, rev 0a, except 1621 * These were taken from ATA/ATAPI-6 standard, rev 0a, except
1559 * for PIO 5, which is a nonstandard extension and UDMA6, which 1622 * for PIO 5, which is a nonstandard extension and UDMA6, which
1560 * is currently supported only by Maxtor drives. 1623 * is currently supported only by Maxtor drives.
1561 */ 1624 */
1562 1625
1563static const struct ata_timing ata_timing[] = { 1626static const struct ata_timing ata_timing[] = {
@@ -1572,11 +1635,11 @@ static const struct ata_timing ata_timing[] = {
1572 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 }, 1635 { XFER_UDMA_0, 0, 0, 0, 0, 0, 0, 0, 120 },
1573 1636
1574/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */ 1637/* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
1575 1638
1576 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 }, 1639 { XFER_MW_DMA_2, 25, 0, 0, 0, 70, 25, 120, 0 },
1577 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 }, 1640 { XFER_MW_DMA_1, 45, 0, 0, 0, 80, 50, 150, 0 },
1578 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 }, 1641 { XFER_MW_DMA_0, 60, 0, 0, 0, 215, 215, 480, 0 },
1579 1642
1580 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 }, 1643 { XFER_SW_DMA_2, 60, 0, 0, 0, 120, 120, 240, 0 },
1581 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 }, 1644 { XFER_SW_DMA_1, 90, 0, 0, 0, 240, 240, 480, 0 },
1582 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 }, 1645 { XFER_SW_DMA_0, 120, 0, 0, 0, 480, 480, 960, 0 },
@@ -1629,7 +1692,7 @@ static const struct ata_timing* ata_timing_find_mode(unsigned short speed)
1629 for (t = ata_timing; t->mode != speed; t++) 1692 for (t = ata_timing; t->mode != speed; t++)
1630 if (t->mode == 0xFF) 1693 if (t->mode == 0xFF)
1631 return NULL; 1694 return NULL;
1632 return t; 1695 return t;
1633} 1696}
1634 1697
1635int ata_timing_compute(struct ata_device *adev, unsigned short speed, 1698int ata_timing_compute(struct ata_device *adev, unsigned short speed,
@@ -1639,7 +1702,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1639 struct ata_timing p; 1702 struct ata_timing p;
1640 1703
1641 /* 1704 /*
1642 * Find the mode. 1705 * Find the mode.
1643 */ 1706 */
1644 1707
1645 if (!(s = ata_timing_find_mode(speed))) 1708 if (!(s = ata_timing_find_mode(speed)))
@@ -1697,20 +1760,28 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
1697 return 0; 1760 return 0;
1698} 1761}
1699 1762
1700static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev) 1763static int ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1701{ 1764{
1702 if (!ata_dev_present(dev) || (ap->flags & ATA_FLAG_PORT_DISABLED)) 1765 unsigned int err_mask;
1703 return; 1766 int rc;
1704 1767
1705 if (dev->xfer_shift == ATA_SHIFT_PIO) 1768 if (dev->xfer_shift == ATA_SHIFT_PIO)
1706 dev->flags |= ATA_DFLAG_PIO; 1769 dev->flags |= ATA_DFLAG_PIO;
1707 1770
1708 ata_dev_set_xfermode(ap, dev); 1771 err_mask = ata_dev_set_xfermode(ap, dev);
1772 if (err_mask) {
1773 printk(KERN_ERR
1774 "ata%u: failed to set xfermode (err_mask=0x%x)\n",
1775 ap->id, err_mask);
1776 return -EIO;
1777 }
1709 1778
1710 if (ata_dev_revalidate(ap, dev, 0)) { 1779 rc = ata_dev_revalidate(ap, dev, 0);
1711 printk(KERN_ERR "ata%u: failed to revalidate after set " 1780 if (rc) {
1712 "xfermode, disabled\n", ap->id); 1781 printk(KERN_ERR
1713 ata_port_disable(ap); 1782 "ata%u: failed to revalidate after set xfermode\n",
1783 ap->id);
1784 return rc;
1714 } 1785 }
1715 1786
1716 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n", 1787 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
@@ -1719,6 +1790,7 @@ static void ata_dev_set_mode(struct ata_port *ap, struct ata_device *dev)
1719 printk(KERN_INFO "ata%u: dev %u configured for %s\n", 1790 printk(KERN_INFO "ata%u: dev %u configured for %s\n",
1720 ap->id, dev->devno, 1791 ap->id, dev->devno,
1721 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode))); 1792 ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)));
1793 return 0;
1722} 1794}
1723 1795
1724static int ata_host_set_pio(struct ata_port *ap) 1796static int ata_host_set_pio(struct ata_port *ap)
@@ -1778,16 +1850,19 @@ static void ata_set_mode(struct ata_port *ap)
1778 /* step 1: calculate xfer_mask */ 1850 /* step 1: calculate xfer_mask */
1779 for (i = 0; i < ATA_MAX_DEVICES; i++) { 1851 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1780 struct ata_device *dev = &ap->device[i]; 1852 struct ata_device *dev = &ap->device[i];
1781 unsigned int xfer_mask; 1853 unsigned int pio_mask, dma_mask;
1782 1854
1783 if (!ata_dev_present(dev)) 1855 if (!ata_dev_present(dev))
1784 continue; 1856 continue;
1785 1857
1786 xfer_mask = ata_dev_xfermask(ap, dev); 1858 ata_dev_xfermask(ap, dev);
1859
1860 /* TODO: let LLDD filter dev->*_mask here */
1787 1861
1788 dev->pio_mode = ata_xfer_mask2mode(xfer_mask & ATA_MASK_PIO); 1862 pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
1789 dev->dma_mode = ata_xfer_mask2mode(xfer_mask & (ATA_MASK_MWDMA | 1863 dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
1790 ATA_MASK_UDMA)); 1864 dev->pio_mode = ata_xfer_mask2mode(pio_mask);
1865 dev->dma_mode = ata_xfer_mask2mode(dma_mask);
1791 } 1866 }
1792 1867
1793 /* step 2: always set host PIO timings */ 1868 /* step 2: always set host PIO timings */
@@ -1799,11 +1874,15 @@ static void ata_set_mode(struct ata_port *ap)
1799 ata_host_set_dma(ap); 1874 ata_host_set_dma(ap);
1800 1875
1801 /* step 4: update devices' xfer mode */ 1876 /* step 4: update devices' xfer mode */
1802 for (i = 0; i < ATA_MAX_DEVICES; i++) 1877 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1803 ata_dev_set_mode(ap, &ap->device[i]); 1878 struct ata_device *dev = &ap->device[i];
1804 1879
1805 if (ap->flags & ATA_FLAG_PORT_DISABLED) 1880 if (!ata_dev_present(dev))
1806 return; 1881 continue;
1882
1883 if (ata_dev_set_mode(ap, dev))
1884 goto err_out;
1885 }
1807 1886
1808 if (ap->ops->post_set_mode) 1887 if (ap->ops->post_set_mode)
1809 ap->ops->post_set_mode(ap); 1888 ap->ops->post_set_mode(ap);
@@ -1999,11 +2078,11 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
1999 */ 2078 */
2000 msleep(150); 2079 msleep(150);
2001 2080
2002 2081
2003 /* Before we perform post reset processing we want to see if 2082 /* Before we perform post reset processing we want to see if
2004 the bus shows 0xFF because the odd clown forgets the D7 pulldown 2083 the bus shows 0xFF because the odd clown forgets the D7 pulldown
2005 resistor */ 2084 resistor */
2006 2085
2007 if (ata_check_status(ap) == 0xFF) 2086 if (ata_check_status(ap) == 0xFF)
2008 return 1; /* Positive is failure for some reason */ 2087 return 1; /* Positive is failure for some reason */
2009 2088
@@ -2572,22 +2651,22 @@ static const char * const ata_dma_blacklist [] = {
2572 "SanDisk SDP3B-64", NULL, 2651 "SanDisk SDP3B-64", NULL,
2573 "SANYO CD-ROM CRD", NULL, 2652 "SANYO CD-ROM CRD", NULL,
2574 "HITACHI CDR-8", NULL, 2653 "HITACHI CDR-8", NULL,
2575 "HITACHI CDR-8335", NULL, 2654 "HITACHI CDR-8335", NULL,
2576 "HITACHI CDR-8435", NULL, 2655 "HITACHI CDR-8435", NULL,
2577 "Toshiba CD-ROM XM-6202B", NULL, 2656 "Toshiba CD-ROM XM-6202B", NULL,
2578 "TOSHIBA CD-ROM XM-1702BC", NULL, 2657 "TOSHIBA CD-ROM XM-1702BC", NULL,
2579 "CD-532E-A", NULL, 2658 "CD-532E-A", NULL,
2580 "E-IDE CD-ROM CR-840", NULL, 2659 "E-IDE CD-ROM CR-840", NULL,
2581 "CD-ROM Drive/F5A", NULL, 2660 "CD-ROM Drive/F5A", NULL,
2582 "WPI CDD-820", NULL, 2661 "WPI CDD-820", NULL,
2583 "SAMSUNG CD-ROM SC-148C", NULL, 2662 "SAMSUNG CD-ROM SC-148C", NULL,
2584 "SAMSUNG CD-ROM SC", NULL, 2663 "SAMSUNG CD-ROM SC", NULL,
2585 "SanDisk SDP3B-64", NULL, 2664 "SanDisk SDP3B-64", NULL,
2586 "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL, 2665 "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,
2587 "_NEC DV5800A", NULL, 2666 "_NEC DV5800A", NULL,
2588 "SAMSUNG CD-ROM SN-124", "N001" 2667 "SAMSUNG CD-ROM SN-124", "N001"
2589}; 2668};
2590 2669
2591static int ata_strim(char *s, size_t len) 2670static int ata_strim(char *s, size_t len)
2592{ 2671{
2593 len = strnlen(s, len); 2672 len = strnlen(s, len);
@@ -2630,18 +2709,15 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
2630 * @ap: Port on which the device to compute xfermask for resides 2709 * @ap: Port on which the device to compute xfermask for resides
2631 * @dev: Device to compute xfermask for 2710 * @dev: Device to compute xfermask for
2632 * 2711 *
2633 * Compute supported xfermask of @dev. This function is 2712 * Compute supported xfermask of @dev and store it in
2634 * responsible for applying all known limits including host 2713 * dev->*_mask. This function is responsible for applying all
2635 * controller limits, device blacklist, etc... 2714 * known limits including host controller limits, device
2715 * blacklist, etc...
2636 * 2716 *
2637 * LOCKING: 2717 * LOCKING:
2638 * None. 2718 * None.
2639 *
2640 * RETURNS:
2641 * Computed xfermask.
2642 */ 2719 */
2643static unsigned int ata_dev_xfermask(struct ata_port *ap, 2720static void ata_dev_xfermask(struct ata_port *ap, struct ata_device *dev)
2644 struct ata_device *dev)
2645{ 2721{
2646 unsigned long xfer_mask; 2722 unsigned long xfer_mask;
2647 int i; 2723 int i;
@@ -2654,6 +2730,8 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2654 struct ata_device *d = &ap->device[i]; 2730 struct ata_device *d = &ap->device[i];
2655 if (!ata_dev_present(d)) 2731 if (!ata_dev_present(d))
2656 continue; 2732 continue;
2733 xfer_mask &= ata_pack_xfermask(d->pio_mask, d->mwdma_mask,
2734 d->udma_mask);
2657 xfer_mask &= ata_id_xfermask(d->id); 2735 xfer_mask &= ata_id_xfermask(d->id);
2658 if (ata_dma_blacklisted(d)) 2736 if (ata_dma_blacklisted(d))
2659 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 2737 xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
@@ -2663,7 +2741,8 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2663 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, " 2741 printk(KERN_WARNING "ata%u: dev %u is on DMA blacklist, "
2664 "disabling DMA\n", ap->id, dev->devno); 2742 "disabling DMA\n", ap->id, dev->devno);
2665 2743
2666 return xfer_mask; 2744 ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
2745 &dev->udma_mask);
2667} 2746}
2668 2747
2669/** 2748/**
@@ -2676,11 +2755,16 @@ static unsigned int ata_dev_xfermask(struct ata_port *ap,
2676 * 2755 *
2677 * LOCKING: 2756 * LOCKING:
2678 * PCI/etc. bus probe sem. 2757 * PCI/etc. bus probe sem.
2758 *
2759 * RETURNS:
2760 * 0 on success, AC_ERR_* mask otherwise.
2679 */ 2761 */
2680 2762
2681static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) 2763static unsigned int ata_dev_set_xfermode(struct ata_port *ap,
2764 struct ata_device *dev)
2682{ 2765{
2683 struct ata_taskfile tf; 2766 struct ata_taskfile tf;
2767 unsigned int err_mask;
2684 2768
2685 /* set up set-features taskfile */ 2769 /* set up set-features taskfile */
2686 DPRINTK("set features - xfer mode\n"); 2770 DPRINTK("set features - xfer mode\n");
@@ -2692,13 +2776,10 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)
2692 tf.protocol = ATA_PROT_NODATA; 2776 tf.protocol = ATA_PROT_NODATA;
2693 tf.nsect = dev->xfer_mode; 2777 tf.nsect = dev->xfer_mode;
2694 2778
2695 if (ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0)) { 2779 err_mask = ata_exec_internal(ap, dev, &tf, DMA_NONE, NULL, 0);
2696 printk(KERN_ERR "ata%u: failed to set xfermode, disabled\n",
2697 ap->id);
2698 ata_port_disable(ap);
2699 }
2700 2780
2701 DPRINTK("EXIT\n"); 2781 DPRINTK("EXIT, err_mask=%x\n", err_mask);
2782 return err_mask;
2702} 2783}
2703 2784
2704/** 2785/**
@@ -2775,7 +2856,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2775 2856
2776 if (qc->flags & ATA_QCFLAG_SG) { 2857 if (qc->flags & ATA_QCFLAG_SG) {
2777 if (qc->n_elem) 2858 if (qc->n_elem)
2778 dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir); 2859 dma_unmap_sg(ap->dev, sg, qc->n_elem, dir);
2779 /* restore last sg */ 2860 /* restore last sg */
2780 sg[qc->orig_n_elem - 1].length += qc->pad_len; 2861 sg[qc->orig_n_elem - 1].length += qc->pad_len;
2781 if (pad_buf) { 2862 if (pad_buf) {
@@ -2786,7 +2867,7 @@ static void ata_sg_clean(struct ata_queued_cmd *qc)
2786 } 2867 }
2787 } else { 2868 } else {
2788 if (qc->n_elem) 2869 if (qc->n_elem)
2789 dma_unmap_single(ap->host_set->dev, 2870 dma_unmap_single(ap->dev,
2790 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]), 2871 sg_dma_address(&sg[0]), sg_dma_len(&sg[0]),
2791 dir); 2872 dir);
2792 /* restore sg */ 2873 /* restore sg */
@@ -2997,7 +3078,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
2997 goto skip_map; 3078 goto skip_map;
2998 } 3079 }
2999 3080
3000 dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, 3081 dma_address = dma_map_single(ap->dev, qc->buf_virt,
3001 sg->length, dir); 3082 sg->length, dir);
3002 if (dma_mapping_error(dma_address)) { 3083 if (dma_mapping_error(dma_address)) {
3003 /* restore sg */ 3084 /* restore sg */
@@ -3085,7 +3166,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
3085 } 3166 }
3086 3167
3087 dir = qc->dma_dir; 3168 dir = qc->dma_dir;
3088 n_elem = dma_map_sg(ap->host_set->dev, sg, pre_n_elem, dir); 3169 n_elem = dma_map_sg(ap->dev, sg, pre_n_elem, dir);
3089 if (n_elem < 1) { 3170 if (n_elem < 1) {
3090 /* restore last sg */ 3171 /* restore last sg */
3091 lsg->length += qc->pad_len; 3172 lsg->length += qc->pad_len;
@@ -3616,7 +3697,7 @@ static void ata_pio_error(struct ata_port *ap)
3616 if (qc->tf.command != ATA_CMD_PACKET) 3697 if (qc->tf.command != ATA_CMD_PACKET)
3617 printk(KERN_WARNING "ata%u: PIO error\n", ap->id); 3698 printk(KERN_WARNING "ata%u: PIO error\n", ap->id);
3618 3699
3619 /* make sure qc->err_mask is available to 3700 /* make sure qc->err_mask is available to
3620 * know what's wrong and recover 3701 * know what's wrong and recover
3621 */ 3702 */
3622 WARN_ON(qc->err_mask == 0); 3703 WARN_ON(qc->err_mask == 0);
@@ -4065,240 +4146,6 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
4065} 4146}
4066 4147
4067/** 4148/**
4068 * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction
4069 * @qc: Info associated with this ATA transaction.
4070 *
4071 * LOCKING:
4072 * spin_lock_irqsave(host_set lock)
4073 */
4074
4075static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc)
4076{
4077 struct ata_port *ap = qc->ap;
4078 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
4079 u8 dmactl;
4080 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
4081
4082 /* load PRD table addr. */
4083 mb(); /* make sure PRD table writes are visible to controller */
4084 writel(ap->prd_dma, mmio + ATA_DMA_TABLE_OFS);
4085
4086 /* specify data direction, triple-check start bit is clear */
4087 dmactl = readb(mmio + ATA_DMA_CMD);
4088 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
4089 if (!rw)
4090 dmactl |= ATA_DMA_WR;
4091 writeb(dmactl, mmio + ATA_DMA_CMD);
4092
4093 /* issue r/w command */
4094 ap->ops->exec_command(ap, &qc->tf);
4095}
4096
4097/**
4098 * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction
4099 * @qc: Info associated with this ATA transaction.
4100 *
4101 * LOCKING:
4102 * spin_lock_irqsave(host_set lock)
4103 */
4104
4105static void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
4106{
4107 struct ata_port *ap = qc->ap;
4108 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
4109 u8 dmactl;
4110
4111 /* start host DMA transaction */
4112 dmactl = readb(mmio + ATA_DMA_CMD);
4113 writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD);
4114
4115 /* Strictly, one may wish to issue a readb() here, to
4116 * flush the mmio write. However, control also passes
4117 * to the hardware at this point, and it will interrupt
4118 * us when we are to resume control. So, in effect,
4119 * we don't care when the mmio write flushes.
4120 * Further, a read of the DMA status register _immediately_
4121 * following the write may not be what certain flaky hardware
4122 * is expected, so I think it is best to not add a readb()
4123 * without first all the MMIO ATA cards/mobos.
4124 * Or maybe I'm just being paranoid.
4125 */
4126}
4127
4128/**
4129 * ata_bmdma_setup_pio - Set up PCI IDE BMDMA transaction (PIO)
4130 * @qc: Info associated with this ATA transaction.
4131 *
4132 * LOCKING:
4133 * spin_lock_irqsave(host_set lock)
4134 */
4135
4136static void ata_bmdma_setup_pio (struct ata_queued_cmd *qc)
4137{
4138 struct ata_port *ap = qc->ap;
4139 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
4140 u8 dmactl;
4141
4142 /* load PRD table addr. */
4143 outl(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
4144
4145 /* specify data direction, triple-check start bit is clear */
4146 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
4147 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
4148 if (!rw)
4149 dmactl |= ATA_DMA_WR;
4150 outb(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
4151
4152 /* issue r/w command */
4153 ap->ops->exec_command(ap, &qc->tf);
4154}
4155
4156/**
4157 * ata_bmdma_start_pio - Start a PCI IDE BMDMA transaction (PIO)
4158 * @qc: Info associated with this ATA transaction.
4159 *
4160 * LOCKING:
4161 * spin_lock_irqsave(host_set lock)
4162 */
4163
4164static void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
4165{
4166 struct ata_port *ap = qc->ap;
4167 u8 dmactl;
4168
4169 /* start host DMA transaction */
4170 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
4171 outb(dmactl | ATA_DMA_START,
4172 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
4173}
4174
4175
4176/**
4177 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
4178 * @qc: Info associated with this ATA transaction.
4179 *
4180 * Writes the ATA_DMA_START flag to the DMA command register.
4181 *
4182 * May be used as the bmdma_start() entry in ata_port_operations.
4183 *
4184 * LOCKING:
4185 * spin_lock_irqsave(host_set lock)
4186 */
4187void ata_bmdma_start(struct ata_queued_cmd *qc)
4188{
4189 if (qc->ap->flags & ATA_FLAG_MMIO)
4190 ata_bmdma_start_mmio(qc);
4191 else
4192 ata_bmdma_start_pio(qc);
4193}
4194
4195
4196/**
4197 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
4198 * @qc: Info associated with this ATA transaction.
4199 *
4200 * Writes address of PRD table to device's PRD Table Address
4201 * register, sets the DMA control register, and calls
4202 * ops->exec_command() to start the transfer.
4203 *
4204 * May be used as the bmdma_setup() entry in ata_port_operations.
4205 *
4206 * LOCKING:
4207 * spin_lock_irqsave(host_set lock)
4208 */
4209void ata_bmdma_setup(struct ata_queued_cmd *qc)
4210{
4211 if (qc->ap->flags & ATA_FLAG_MMIO)
4212 ata_bmdma_setup_mmio(qc);
4213 else
4214 ata_bmdma_setup_pio(qc);
4215}
4216
4217
4218/**
4219 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
4220 * @ap: Port associated with this ATA transaction.
4221 *
4222 * Clear interrupt and error flags in DMA status register.
4223 *
4224 * May be used as the irq_clear() entry in ata_port_operations.
4225 *
4226 * LOCKING:
4227 * spin_lock_irqsave(host_set lock)
4228 */
4229
4230void ata_bmdma_irq_clear(struct ata_port *ap)
4231{
4232 if (!ap->ioaddr.bmdma_addr)
4233 return;
4234
4235 if (ap->flags & ATA_FLAG_MMIO) {
4236 void __iomem *mmio =
4237 ((void __iomem *) ap->ioaddr.bmdma_addr) + ATA_DMA_STATUS;
4238 writeb(readb(mmio), mmio);
4239 } else {
4240 unsigned long addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS;
4241 outb(inb(addr), addr);
4242 }
4243}
4244
4245
4246/**
4247 * ata_bmdma_status - Read PCI IDE BMDMA status
4248 * @ap: Port associated with this ATA transaction.
4249 *
4250 * Read and return BMDMA status register.
4251 *
4252 * May be used as the bmdma_status() entry in ata_port_operations.
4253 *
4254 * LOCKING:
4255 * spin_lock_irqsave(host_set lock)
4256 */
4257
4258u8 ata_bmdma_status(struct ata_port *ap)
4259{
4260 u8 host_stat;
4261 if (ap->flags & ATA_FLAG_MMIO) {
4262 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
4263 host_stat = readb(mmio + ATA_DMA_STATUS);
4264 } else
4265 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
4266 return host_stat;
4267}
4268
4269
4270/**
4271 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
4272 * @qc: Command we are ending DMA for
4273 *
4274 * Clears the ATA_DMA_START flag in the dma control register
4275 *
4276 * May be used as the bmdma_stop() entry in ata_port_operations.
4277 *
4278 * LOCKING:
4279 * spin_lock_irqsave(host_set lock)
4280 */
4281
4282void ata_bmdma_stop(struct ata_queued_cmd *qc)
4283{
4284 struct ata_port *ap = qc->ap;
4285 if (ap->flags & ATA_FLAG_MMIO) {
4286 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
4287
4288 /* clear start/stop bit */
4289 writeb(readb(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
4290 mmio + ATA_DMA_CMD);
4291 } else {
4292 /* clear start/stop bit */
4293 outb(inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START,
4294 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
4295 }
4296
4297 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
4298 ata_altstatus(ap); /* dummy read */
4299}
4300
4301/**
4302 * ata_host_intr - Handle host interrupt for given (port, task) 4149 * ata_host_intr - Handle host interrupt for given (port, task)
4303 * @ap: Port on which interrupt arrived (possibly...) 4150 * @ap: Port on which interrupt arrived (possibly...)
4304 * @qc: Taskfile currently active in engine 4151 * @qc: Taskfile currently active in engine
@@ -4506,14 +4353,15 @@ int ata_device_resume(struct ata_port *ap, struct ata_device *dev)
4506 * Flush the cache on the drive, if appropriate, then issue a 4353 * Flush the cache on the drive, if appropriate, then issue a
4507 * standbynow command. 4354 * standbynow command.
4508 */ 4355 */
4509int ata_device_suspend(struct ata_port *ap, struct ata_device *dev) 4356int ata_device_suspend(struct ata_port *ap, struct ata_device *dev, pm_message_t state)
4510{ 4357{
4511 if (!ata_dev_present(dev)) 4358 if (!ata_dev_present(dev))
4512 return 0; 4359 return 0;
4513 if (dev->class == ATA_DEV_ATA) 4360 if (dev->class == ATA_DEV_ATA)
4514 ata_flush_cache(ap, dev); 4361 ata_flush_cache(ap, dev);
4515 4362
4516 ata_standby_drive(ap, dev); 4363 if (state.event != PM_EVENT_FREEZE)
4364 ata_standby_drive(ap, dev);
4517 ap->flags |= ATA_FLAG_SUSPENDED; 4365 ap->flags |= ATA_FLAG_SUSPENDED;
4518 return 0; 4366 return 0;
4519} 4367}
@@ -4533,7 +4381,7 @@ int ata_device_suspend(struct ata_port *ap, struct ata_device *dev)
4533 4381
4534int ata_port_start (struct ata_port *ap) 4382int ata_port_start (struct ata_port *ap)
4535{ 4383{
4536 struct device *dev = ap->host_set->dev; 4384 struct device *dev = ap->dev;
4537 int rc; 4385 int rc;
4538 4386
4539 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL); 4387 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL);
@@ -4566,7 +4414,7 @@ int ata_port_start (struct ata_port *ap)
4566 4414
4567void ata_port_stop (struct ata_port *ap) 4415void ata_port_stop (struct ata_port *ap)
4568{ 4416{
4569 struct device *dev = ap->host_set->dev; 4417 struct device *dev = ap->dev;
4570 4418
4571 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); 4419 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
4572 ata_pad_free(ap, dev); 4420 ata_pad_free(ap, dev);
@@ -4632,6 +4480,7 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4632 ap->host = host; 4480 ap->host = host;
4633 ap->ctl = ATA_DEVCTL_OBS; 4481 ap->ctl = ATA_DEVCTL_OBS;
4634 ap->host_set = host_set; 4482 ap->host_set = host_set;
4483 ap->dev = ent->dev;
4635 ap->port_no = port_no; 4484 ap->port_no = port_no;
4636 ap->hard_port_no = 4485 ap->hard_port_no =
4637 ent->legacy_mode ? ent->hard_port_no : port_no; 4486 ent->legacy_mode ? ent->hard_port_no : port_no;
@@ -4647,8 +4496,13 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host,
4647 INIT_WORK(&ap->port_task, NULL, NULL); 4496 INIT_WORK(&ap->port_task, NULL, NULL);
4648 INIT_LIST_HEAD(&ap->eh_done_q); 4497 INIT_LIST_HEAD(&ap->eh_done_q);
4649 4498
4650 for (i = 0; i < ATA_MAX_DEVICES; i++) 4499 for (i = 0; i < ATA_MAX_DEVICES; i++) {
4651 ap->device[i].devno = i; 4500 struct ata_device *dev = &ap->device[i];
4501 dev->devno = i;
4502 dev->pio_mask = UINT_MAX;
4503 dev->mwdma_mask = UINT_MAX;
4504 dev->udma_mask = UINT_MAX;
4505 }
4652 4506
4653#ifdef ATA_IRQ_TRAP 4507#ifdef ATA_IRQ_TRAP
4654 ap->stats.unhandled_irq = 1; 4508 ap->stats.unhandled_irq = 1;
@@ -4842,7 +4696,7 @@ err_free_ret:
4842 * ata_host_set_remove - PCI layer callback for device removal 4696 * ata_host_set_remove - PCI layer callback for device removal
4843 * @host_set: ATA host set that was removed 4697 * @host_set: ATA host set that was removed
4844 * 4698 *
4845 * Unregister all objects associated with this host set. Free those 4699 * Unregister all objects associated with this host set. Free those
4846 * objects. 4700 * objects.
4847 * 4701 *
4848 * LOCKING: 4702 * LOCKING:
@@ -5114,6 +4968,8 @@ EXPORT_SYMBOL_GPL(ata_std_postreset);
5114EXPORT_SYMBOL_GPL(ata_std_probe_reset); 4968EXPORT_SYMBOL_GPL(ata_std_probe_reset);
5115EXPORT_SYMBOL_GPL(ata_drive_probe_reset); 4969EXPORT_SYMBOL_GPL(ata_drive_probe_reset);
5116EXPORT_SYMBOL_GPL(ata_dev_revalidate); 4970EXPORT_SYMBOL_GPL(ata_dev_revalidate);
4971EXPORT_SYMBOL_GPL(ata_dev_classify);
4972EXPORT_SYMBOL_GPL(ata_dev_pair);
5117EXPORT_SYMBOL_GPL(ata_port_disable); 4973EXPORT_SYMBOL_GPL(ata_port_disable);
5118EXPORT_SYMBOL_GPL(ata_ratelimit); 4974EXPORT_SYMBOL_GPL(ata_ratelimit);
5119EXPORT_SYMBOL_GPL(ata_busy_sleep); 4975EXPORT_SYMBOL_GPL(ata_busy_sleep);
@@ -5124,7 +4980,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_error);
5124EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 4980EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
5125EXPORT_SYMBOL_GPL(ata_scsi_release); 4981EXPORT_SYMBOL_GPL(ata_scsi_release);
5126EXPORT_SYMBOL_GPL(ata_host_intr); 4982EXPORT_SYMBOL_GPL(ata_host_intr);
5127EXPORT_SYMBOL_GPL(ata_dev_classify);
5128EXPORT_SYMBOL_GPL(ata_id_string); 4983EXPORT_SYMBOL_GPL(ata_id_string);
5129EXPORT_SYMBOL_GPL(ata_id_c_string); 4984EXPORT_SYMBOL_GPL(ata_id_c_string);
5130EXPORT_SYMBOL_GPL(ata_scsi_simulate); 4985EXPORT_SYMBOL_GPL(ata_scsi_simulate);