diff options
Diffstat (limited to 'drivers/scsi/libata-core.c')
-rw-r--r-- | drivers/scsi/libata-core.c | 510 |
1 files changed, 452 insertions, 58 deletions
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index 8b5a3f00083d..84c4770e5bb4 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -186,6 +186,28 @@ static void ata_tf_load_mmio(struct ata_port *ap, struct ata_taskfile *tf) | |||
186 | ata_wait_idle(ap); | 186 | ata_wait_idle(ap); |
187 | } | 187 | } |
188 | 188 | ||
189 | |||
190 | /** | ||
191 | * ata_tf_load - send taskfile registers to host controller | ||
192 | * @ap: Port to which output is sent | ||
193 | * @tf: ATA taskfile register set | ||
194 | * | ||
195 | * Outputs ATA taskfile to standard ATA host controller using MMIO | ||
196 | * or PIO as indicated by the ATA_FLAG_MMIO flag. | ||
197 | * Writes the control, feature, nsect, lbal, lbam, and lbah registers. | ||
198 | * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect, | ||
199 | * hob_lbal, hob_lbam, and hob_lbah. | ||
200 | * | ||
201 | * This function waits for idle (!BUSY and !DRQ) after writing | ||
202 | * registers. If the control register has a new value, this | ||
203 | * function also waits for idle after writing control and before | ||
204 | * writing the remaining registers. | ||
205 | * | ||
206 | * May be used as the tf_load() entry in ata_port_operations. | ||
207 | * | ||
208 | * LOCKING: | ||
209 | * Inherited from caller. | ||
210 | */ | ||
189 | void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) | 211 | void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) |
190 | { | 212 | { |
191 | if (ap->flags & ATA_FLAG_MMIO) | 213 | if (ap->flags & ATA_FLAG_MMIO) |
@@ -195,11 +217,11 @@ void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf) | |||
195 | } | 217 | } |
196 | 218 | ||
197 | /** | 219 | /** |
198 | * ata_exec_command - issue ATA command to host controller | 220 | * ata_exec_command_pio - issue ATA command to host controller |
199 | * @ap: port to which command is being issued | 221 | * @ap: port to which command is being issued |
200 | * @tf: ATA taskfile register set | 222 | * @tf: ATA taskfile register set |
201 | * | 223 | * |
202 | * Issues PIO/MMIO write to ATA command register, with proper | 224 | * Issues PIO write to ATA command register, with proper |
203 | * synchronization with interrupt handler / other threads. | 225 | * synchronization with interrupt handler / other threads. |
204 | * | 226 | * |
205 | * LOCKING: | 227 | * LOCKING: |
@@ -235,6 +257,18 @@ static void ata_exec_command_mmio(struct ata_port *ap, struct ata_taskfile *tf) | |||
235 | ata_pause(ap); | 257 | ata_pause(ap); |
236 | } | 258 | } |
237 | 259 | ||
260 | |||
261 | /** | ||
262 | * ata_exec_command - issue ATA command to host controller | ||
263 | * @ap: port to which command is being issued | ||
264 | * @tf: ATA taskfile register set | ||
265 | * | ||
266 | * Issues PIO/MMIO write to ATA command register, with proper | ||
267 | * synchronization with interrupt handler / other threads. | ||
268 | * | ||
269 | * LOCKING: | ||
270 | * spin_lock_irqsave(host_set lock) | ||
271 | */ | ||
238 | void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) | 272 | void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf) |
239 | { | 273 | { |
240 | if (ap->flags & ATA_FLAG_MMIO) | 274 | if (ap->flags & ATA_FLAG_MMIO) |
@@ -305,7 +339,7 @@ void ata_tf_to_host_nolock(struct ata_port *ap, struct ata_taskfile *tf) | |||
305 | } | 339 | } |
306 | 340 | ||
307 | /** | 341 | /** |
308 | * ata_tf_read - input device's ATA taskfile shadow registers | 342 | * ata_tf_read_pio - input device's ATA taskfile shadow registers |
309 | * @ap: Port from which input is read | 343 | * @ap: Port from which input is read |
310 | * @tf: ATA taskfile register set for storing input | 344 | * @tf: ATA taskfile register set for storing input |
311 | * | 345 | * |
@@ -368,6 +402,23 @@ static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf) | |||
368 | } | 402 | } |
369 | } | 403 | } |
370 | 404 | ||
405 | |||
406 | /** | ||
407 | * ata_tf_read - input device's ATA taskfile shadow registers | ||
408 | * @ap: Port from which input is read | ||
409 | * @tf: ATA taskfile register set for storing input | ||
410 | * | ||
411 | * Reads ATA taskfile registers for currently-selected device | ||
412 | * into @tf. | ||
413 | * | ||
414 | * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48 | ||
415 | * is set, also reads the hob registers. | ||
416 | * | ||
417 | * May be used as the tf_read() entry in ata_port_operations. | ||
418 | * | ||
419 | * LOCKING: | ||
420 | * Inherited from caller. | ||
421 | */ | ||
371 | void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) | 422 | void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) |
372 | { | 423 | { |
373 | if (ap->flags & ATA_FLAG_MMIO) | 424 | if (ap->flags & ATA_FLAG_MMIO) |
@@ -381,7 +432,7 @@ void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) | |||
381 | * @ap: port where the device is | 432 | * @ap: port where the device is |
382 | * | 433 | * |
383 | * Reads ATA taskfile status register for currently-selected device | 434 | * Reads ATA taskfile status register for currently-selected device |
384 | * and return it's value. This also clears pending interrupts | 435 | * and return its value. This also clears pending interrupts |
385 | * from this device | 436 | * from this device |
386 | * | 437 | * |
387 | * LOCKING: | 438 | * LOCKING: |
@@ -397,7 +448,7 @@ static u8 ata_check_status_pio(struct ata_port *ap) | |||
397 | * @ap: port where the device is | 448 | * @ap: port where the device is |
398 | * | 449 | * |
399 | * Reads ATA taskfile status register for currently-selected device | 450 | * Reads ATA taskfile status register for currently-selected device |
400 | * via MMIO and return it's value. This also clears pending interrupts | 451 | * via MMIO and return its value. This also clears pending interrupts |
401 | * from this device | 452 | * from this device |
402 | * | 453 | * |
403 | * LOCKING: | 454 | * LOCKING: |
@@ -408,6 +459,20 @@ static u8 ata_check_status_mmio(struct ata_port *ap) | |||
408 | return readb((void __iomem *) ap->ioaddr.status_addr); | 459 | return readb((void __iomem *) ap->ioaddr.status_addr); |
409 | } | 460 | } |
410 | 461 | ||
462 | |||
463 | /** | ||
464 | * ata_check_status - Read device status reg & clear interrupt | ||
465 | * @ap: port where the device is | ||
466 | * | ||
467 | * Reads ATA taskfile status register for currently-selected device | ||
468 | * and return its value. This also clears pending interrupts | ||
469 | * from this device | ||
470 | * | ||
471 | * May be used as the check_status() entry in ata_port_operations. | ||
472 | * | ||
473 | * LOCKING: | ||
474 | * Inherited from caller. | ||
475 | */ | ||
411 | u8 ata_check_status(struct ata_port *ap) | 476 | u8 ata_check_status(struct ata_port *ap) |
412 | { | 477 | { |
413 | if (ap->flags & ATA_FLAG_MMIO) | 478 | if (ap->flags & ATA_FLAG_MMIO) |
@@ -415,6 +480,20 @@ u8 ata_check_status(struct ata_port *ap) | |||
415 | return ata_check_status_pio(ap); | 480 | return ata_check_status_pio(ap); |
416 | } | 481 | } |
417 | 482 | ||
483 | |||
484 | /** | ||
485 | * ata_altstatus - Read device alternate status reg | ||
486 | * @ap: port where the device is | ||
487 | * | ||
488 | * Reads ATA taskfile alternate status register for | ||
489 | * currently-selected device and return its value. | ||
490 | * | ||
491 | * Note: may NOT be used as the check_altstatus() entry in | ||
492 | * ata_port_operations. | ||
493 | * | ||
494 | * LOCKING: | ||
495 | * Inherited from caller. | ||
496 | */ | ||
418 | u8 ata_altstatus(struct ata_port *ap) | 497 | u8 ata_altstatus(struct ata_port *ap) |
419 | { | 498 | { |
420 | if (ap->ops->check_altstatus) | 499 | if (ap->ops->check_altstatus) |
@@ -425,6 +504,20 @@ u8 ata_altstatus(struct ata_port *ap) | |||
425 | return inb(ap->ioaddr.altstatus_addr); | 504 | return inb(ap->ioaddr.altstatus_addr); |
426 | } | 505 | } |
427 | 506 | ||
507 | |||
508 | /** | ||
509 | * ata_chk_err - Read device error reg | ||
510 | * @ap: port where the device is | ||
511 | * | ||
512 | * Reads ATA taskfile error register for | ||
513 | * currently-selected device and return its value. | ||
514 | * | ||
515 | * Note: may NOT be used as the check_err() entry in | ||
516 | * ata_port_operations. | ||
517 | * | ||
518 | * LOCKING: | ||
519 | * Inherited from caller. | ||
520 | */ | ||
428 | u8 ata_chk_err(struct ata_port *ap) | 521 | u8 ata_chk_err(struct ata_port *ap) |
429 | { | 522 | { |
430 | if (ap->ops->check_err) | 523 | if (ap->ops->check_err) |
@@ -873,10 +966,24 @@ void ata_dev_id_string(u16 *id, unsigned char *s, | |||
873 | } | 966 | } |
874 | } | 967 | } |
875 | 968 | ||
969 | |||
970 | /** | ||
971 | * ata_noop_dev_select - Select device 0/1 on ATA bus | ||
972 | * @ap: ATA channel to manipulate | ||
973 | * @device: ATA device (numbered from zero) to select | ||
974 | * | ||
975 | * This function performs no actual function. | ||
976 | * | ||
977 | * May be used as the dev_select() entry in ata_port_operations. | ||
978 | * | ||
979 | * LOCKING: | ||
980 | * caller. | ||
981 | */ | ||
876 | void ata_noop_dev_select (struct ata_port *ap, unsigned int device) | 982 | void ata_noop_dev_select (struct ata_port *ap, unsigned int device) |
877 | { | 983 | { |
878 | } | 984 | } |
879 | 985 | ||
986 | |||
880 | /** | 987 | /** |
881 | * ata_std_dev_select - Select device 0/1 on ATA bus | 988 | * ata_std_dev_select - Select device 0/1 on ATA bus |
882 | * @ap: ATA channel to manipulate | 989 | * @ap: ATA channel to manipulate |
@@ -884,7 +991,9 @@ void ata_noop_dev_select (struct ata_port *ap, unsigned int device) | |||
884 | * | 991 | * |
885 | * Use the method defined in the ATA specification to | 992 | * Use the method defined in the ATA specification to |
886 | * make either device 0, or device 1, active on the | 993 | * make either device 0, or device 1, active on the |
887 | * ATA channel. | 994 | * ATA channel. Works with both PIO and MMIO. |
995 | * | ||
996 | * May be used as the dev_select() entry in ata_port_operations. | ||
888 | * | 997 | * |
889 | * LOCKING: | 998 | * LOCKING: |
890 | * caller. | 999 | * caller. |
@@ -1221,7 +1330,12 @@ void ata_dev_config(struct ata_port *ap, unsigned int i) | |||
1221 | * ata_bus_probe - Reset and probe ATA bus | 1330 | * ata_bus_probe - Reset and probe ATA bus |
1222 | * @ap: Bus to probe | 1331 | * @ap: Bus to probe |
1223 | * | 1332 | * |
1333 | * Master ATA bus probing function. Initiates a hardware-dependent | ||
1334 | * bus reset, then attempts to identify any devices found on | ||
1335 | * the bus. | ||
1336 | * | ||
1224 | * LOCKING: | 1337 | * LOCKING: |
1338 | * PCI/etc. bus probe sem. | ||
1225 | * | 1339 | * |
1226 | * RETURNS: | 1340 | * RETURNS: |
1227 | * Zero on success, non-zero on error. | 1341 | * Zero on success, non-zero on error. |
@@ -1259,10 +1373,14 @@ err_out: | |||
1259 | } | 1373 | } |
1260 | 1374 | ||
1261 | /** | 1375 | /** |
1262 | * ata_port_probe - | 1376 | * ata_port_probe - Mark port as enabled |
1263 | * @ap: | 1377 | * @ap: Port for which we indicate enablement |
1264 | * | 1378 | * |
1265 | * LOCKING: | 1379 | * Modify @ap data structure such that the system |
1380 | * thinks that the entire port is enabled. | ||
1381 | * | ||
1382 | * LOCKING: host_set lock, or some other form of | ||
1383 | * serialization. | ||
1266 | */ | 1384 | */ |
1267 | 1385 | ||
1268 | void ata_port_probe(struct ata_port *ap) | 1386 | void ata_port_probe(struct ata_port *ap) |
@@ -1271,10 +1389,15 @@ void ata_port_probe(struct ata_port *ap) | |||
1271 | } | 1389 | } |
1272 | 1390 | ||
1273 | /** | 1391 | /** |
1274 | * __sata_phy_reset - | 1392 | * __sata_phy_reset - Wake/reset a low-level SATA PHY |
1275 | * @ap: | 1393 | * @ap: SATA port associated with target SATA PHY. |
1394 | * | ||
1395 | * This function issues commands to standard SATA Sxxx | ||
1396 | * PHY registers, to wake up the phy (and device), and | ||
1397 | * clear any reset condition. | ||
1276 | * | 1398 | * |
1277 | * LOCKING: | 1399 | * LOCKING: |
1400 | * PCI/etc. bus probe sem. | ||
1278 | * | 1401 | * |
1279 | */ | 1402 | */ |
1280 | void __sata_phy_reset(struct ata_port *ap) | 1403 | void __sata_phy_reset(struct ata_port *ap) |
@@ -1283,11 +1406,11 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1283 | unsigned long timeout = jiffies + (HZ * 5); | 1406 | unsigned long timeout = jiffies + (HZ * 5); |
1284 | 1407 | ||
1285 | if (ap->flags & ATA_FLAG_SATA_RESET) { | 1408 | if (ap->flags & ATA_FLAG_SATA_RESET) { |
1286 | scr_write(ap, SCR_CONTROL, 0x301); /* issue phy wake/reset */ | 1409 | /* issue phy wake/reset */ |
1287 | scr_read(ap, SCR_STATUS); /* dummy read; flush */ | 1410 | scr_write_flush(ap, SCR_CONTROL, 0x301); |
1288 | udelay(400); /* FIXME: a guess */ | 1411 | udelay(400); /* FIXME: a guess */ |
1289 | } | 1412 | } |
1290 | scr_write(ap, SCR_CONTROL, 0x300); /* issue phy wake/clear reset */ | 1413 | scr_write_flush(ap, SCR_CONTROL, 0x300); /* phy wake/clear reset */ |
1291 | 1414 | ||
1292 | /* wait for phy to become ready, if necessary */ | 1415 | /* wait for phy to become ready, if necessary */ |
1293 | do { | 1416 | do { |
@@ -1319,10 +1442,14 @@ void __sata_phy_reset(struct ata_port *ap) | |||
1319 | } | 1442 | } |
1320 | 1443 | ||
1321 | /** | 1444 | /** |
1322 | * __sata_phy_reset - | 1445 | * sata_phy_reset - Reset SATA bus. |
1323 | * @ap: | 1446 | * @ap: SATA port associated with target SATA PHY. |
1447 | * | ||
1448 | * This function resets the SATA bus, and then probes | ||
1449 | * the bus for devices. | ||
1324 | * | 1450 | * |
1325 | * LOCKING: | 1451 | * LOCKING: |
1452 | * PCI/etc. bus probe sem. | ||
1326 | * | 1453 | * |
1327 | */ | 1454 | */ |
1328 | void sata_phy_reset(struct ata_port *ap) | 1455 | void sata_phy_reset(struct ata_port *ap) |
@@ -1334,10 +1461,16 @@ void sata_phy_reset(struct ata_port *ap) | |||
1334 | } | 1461 | } |
1335 | 1462 | ||
1336 | /** | 1463 | /** |
1337 | * ata_port_disable - | 1464 | * ata_port_disable - Disable port. |
1338 | * @ap: | 1465 | * @ap: Port to be disabled. |
1339 | * | 1466 | * |
1340 | * LOCKING: | 1467 | * Modify @ap data structure such that the system |
1468 | * thinks that the entire port is disabled, and should | ||
1469 | * never attempt to probe or communicate with devices | ||
1470 | * on this port. | ||
1471 | * | ||
1472 | * LOCKING: host_set lock, or some other form of | ||
1473 | * serialization. | ||
1341 | */ | 1474 | */ |
1342 | 1475 | ||
1343 | void ata_port_disable(struct ata_port *ap) | 1476 | void ata_port_disable(struct ata_port *ap) |
@@ -1446,7 +1579,10 @@ static void ata_host_set_dma(struct ata_port *ap, u8 xfer_mode, | |||
1446 | * ata_set_mode - Program timings and issue SET FEATURES - XFER | 1579 | * ata_set_mode - Program timings and issue SET FEATURES - XFER |
1447 | * @ap: port on which timings will be programmed | 1580 | * @ap: port on which timings will be programmed |
1448 | * | 1581 | * |
1582 | * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). | ||
1583 | * | ||
1449 | * LOCKING: | 1584 | * LOCKING: |
1585 | * PCI/etc. bus probe sem. | ||
1450 | * | 1586 | * |
1451 | */ | 1587 | */ |
1452 | static void ata_set_mode(struct ata_port *ap) | 1588 | static void ata_set_mode(struct ata_port *ap) |
@@ -1497,7 +1633,10 @@ err_out: | |||
1497 | * @tmout_pat: impatience timeout | 1633 | * @tmout_pat: impatience timeout |
1498 | * @tmout: overall timeout | 1634 | * @tmout: overall timeout |
1499 | * | 1635 | * |
1500 | * LOCKING: | 1636 | * Sleep until ATA Status register bit BSY clears, |
1637 | * or a timeout occurs. | ||
1638 | * | ||
1639 | * LOCKING: None. | ||
1501 | * | 1640 | * |
1502 | */ | 1641 | */ |
1503 | 1642 | ||
@@ -1583,10 +1722,14 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask) | |||
1583 | } | 1722 | } |
1584 | 1723 | ||
1585 | /** | 1724 | /** |
1586 | * ata_bus_edd - | 1725 | * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command. |
1587 | * @ap: | 1726 | * @ap: Port to reset and probe |
1727 | * | ||
1728 | * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and | ||
1729 | * probe the bus. Not often used these days. | ||
1588 | * | 1730 | * |
1589 | * LOCKING: | 1731 | * LOCKING: |
1732 | * PCI/etc. bus probe sem. | ||
1590 | * | 1733 | * |
1591 | */ | 1734 | */ |
1592 | 1735 | ||
@@ -1663,8 +1806,8 @@ static unsigned int ata_bus_softreset(struct ata_port *ap, | |||
1663 | * the device is ATA or ATAPI. | 1806 | * the device is ATA or ATAPI. |
1664 | * | 1807 | * |
1665 | * LOCKING: | 1808 | * LOCKING: |
1666 | * Inherited from caller. Some functions called by this function | 1809 | * PCI/etc. bus probe sem. |
1667 | * obtain the host_set lock. | 1810 | * Obtains host_set lock. |
1668 | * | 1811 | * |
1669 | * SIDE EFFECTS: | 1812 | * SIDE EFFECTS: |
1670 | * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. | 1813 | * Sets ATA_FLAG_PORT_DISABLED if bus reset fails. |
@@ -1906,7 +2049,11 @@ static int fgb(u32 bitmap) | |||
1906 | * @xfer_mode_out: (output) SET FEATURES - XFER MODE code | 2049 | * @xfer_mode_out: (output) SET FEATURES - XFER MODE code |
1907 | * @xfer_shift_out: (output) bit shift that selects this mode | 2050 | * @xfer_shift_out: (output) bit shift that selects this mode |
1908 | * | 2051 | * |
2052 | * Based on host and device capabilities, determine the | ||
2053 | * maximum transfer mode that is amenable to all. | ||
2054 | * | ||
1909 | * LOCKING: | 2055 | * LOCKING: |
2056 | * PCI/etc. bus probe sem. | ||
1910 | * | 2057 | * |
1911 | * RETURNS: | 2058 | * RETURNS: |
1912 | * Zero on success, negative on error. | 2059 | * Zero on success, negative on error. |
@@ -1939,7 +2086,11 @@ static int ata_choose_xfer_mode(struct ata_port *ap, | |||
1939 | * @ap: Port associated with device @dev | 2086 | * @ap: Port associated with device @dev |
1940 | * @dev: Device to which command will be sent | 2087 | * @dev: Device to which command will be sent |
1941 | * | 2088 | * |
2089 | * Issue SET FEATURES - XFER MODE command to device @dev | ||
2090 | * on port @ap. | ||
2091 | * | ||
1942 | * LOCKING: | 2092 | * LOCKING: |
2093 | * PCI/etc. bus probe sem. | ||
1943 | */ | 2094 | */ |
1944 | 2095 | ||
1945 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | 2096 | static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) |
@@ -1977,10 +2128,13 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | |||
1977 | } | 2128 | } |
1978 | 2129 | ||
1979 | /** | 2130 | /** |
1980 | * ata_sg_clean - | 2131 | * ata_sg_clean - Unmap DMA memory associated with command |
1981 | * @qc: | 2132 | * @qc: Command containing DMA memory to be released |
2133 | * | ||
2134 | * Unmap all mapped DMA memory associated with this command. | ||
1982 | * | 2135 | * |
1983 | * LOCKING: | 2136 | * LOCKING: |
2137 | * spin_lock_irqsave(host_set lock) | ||
1984 | */ | 2138 | */ |
1985 | 2139 | ||
1986 | static void ata_sg_clean(struct ata_queued_cmd *qc) | 2140 | static void ata_sg_clean(struct ata_queued_cmd *qc) |
@@ -2011,7 +2165,11 @@ static void ata_sg_clean(struct ata_queued_cmd *qc) | |||
2011 | * ata_fill_sg - Fill PCI IDE PRD table | 2165 | * ata_fill_sg - Fill PCI IDE PRD table |
2012 | * @qc: Metadata associated with taskfile to be transferred | 2166 | * @qc: Metadata associated with taskfile to be transferred |
2013 | * | 2167 | * |
2168 | * Fill PCI IDE PRD (scatter-gather) table with segments | ||
2169 | * associated with the current disk command. | ||
2170 | * | ||
2014 | * LOCKING: | 2171 | * LOCKING: |
2172 | * spin_lock_irqsave(host_set lock) | ||
2015 | * | 2173 | * |
2016 | */ | 2174 | */ |
2017 | static void ata_fill_sg(struct ata_queued_cmd *qc) | 2175 | static void ata_fill_sg(struct ata_queued_cmd *qc) |
@@ -2058,7 +2216,13 @@ static void ata_fill_sg(struct ata_queued_cmd *qc) | |||
2058 | * ata_check_atapi_dma - Check whether ATAPI DMA can be supported | 2216 | * ata_check_atapi_dma - Check whether ATAPI DMA can be supported |
2059 | * @qc: Metadata associated with taskfile to check | 2217 | * @qc: Metadata associated with taskfile to check |
2060 | * | 2218 | * |
2219 | * Allow low-level driver to filter ATA PACKET commands, returning | ||
2220 | * a status indicating whether or not it is OK to use DMA for the | ||
2221 | * supplied PACKET command. | ||
2222 | * | ||
2061 | * LOCKING: | 2223 | * LOCKING: |
2224 | * spin_lock_irqsave(host_set lock) | ||
2225 | * | ||
2062 | * RETURNS: 0 when ATAPI DMA can be used | 2226 | * RETURNS: 0 when ATAPI DMA can be used |
2063 | * nonzero otherwise | 2227 | * nonzero otherwise |
2064 | */ | 2228 | */ |
@@ -2076,6 +2240,8 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc) | |||
2076 | * ata_qc_prep - Prepare taskfile for submission | 2240 | * ata_qc_prep - Prepare taskfile for submission |
2077 | * @qc: Metadata associated with taskfile to be prepared | 2241 | * @qc: Metadata associated with taskfile to be prepared |
2078 | * | 2242 | * |
2243 | * Prepare ATA taskfile for submission. | ||
2244 | * | ||
2079 | * LOCKING: | 2245 | * LOCKING: |
2080 | * spin_lock_irqsave(host_set lock) | 2246 | * spin_lock_irqsave(host_set lock) |
2081 | */ | 2247 | */ |
@@ -2087,6 +2253,32 @@ void ata_qc_prep(struct ata_queued_cmd *qc) | |||
2087 | ata_fill_sg(qc); | 2253 | ata_fill_sg(qc); |
2088 | } | 2254 | } |
2089 | 2255 | ||
2256 | /** | ||
2257 | * ata_sg_init_one - Associate command with memory buffer | ||
2258 | * @qc: Command to be associated | ||
2259 | * @buf: Memory buffer | ||
2260 | * @buflen: Length of memory buffer, in bytes. | ||
2261 | * | ||
2262 | * Initialize the data-related elements of queued_cmd @qc | ||
2263 | * to point to a single memory buffer, @buf of byte length @buflen. | ||
2264 | * | ||
2265 | * LOCKING: | ||
2266 | * spin_lock_irqsave(host_set lock) | ||
2267 | */ | ||
2268 | |||
2269 | |||
2270 | |||
2271 | /** | ||
2272 | * ata_sg_init_one - Prepare a one-entry scatter-gather list. | ||
2273 | * @qc: Queued command | ||
2274 | * @buf: transfer buffer | ||
2275 | * @buflen: length of buf | ||
2276 | * | ||
2277 | * Builds a single-entry scatter-gather list to initiate a | ||
2278 | * transfer utilizing the specified buffer. | ||
2279 | * | ||
2280 | * LOCKING: | ||
2281 | */ | ||
2090 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) | 2282 | void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) |
2091 | { | 2283 | { |
2092 | struct scatterlist *sg; | 2284 | struct scatterlist *sg; |
@@ -2101,9 +2293,35 @@ void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) | |||
2101 | sg = qc->sg; | 2293 | sg = qc->sg; |
2102 | sg->page = virt_to_page(buf); | 2294 | sg->page = virt_to_page(buf); |
2103 | sg->offset = (unsigned long) buf & ~PAGE_MASK; | 2295 | sg->offset = (unsigned long) buf & ~PAGE_MASK; |
2104 | sg_dma_len(sg) = buflen; | 2296 | sg->length = buflen; |
2105 | } | 2297 | } |
2106 | 2298 | ||
2299 | /** | ||
2300 | * ata_sg_init - Associate command with scatter-gather table. | ||
2301 | * @qc: Command to be associated | ||
2302 | * @sg: Scatter-gather table. | ||
2303 | * @n_elem: Number of elements in s/g table. | ||
2304 | * | ||
2305 | * Initialize the data-related elements of queued_cmd @qc | ||
2306 | * to point to a scatter-gather table @sg, containing @n_elem | ||
2307 | * elements. | ||
2308 | * | ||
2309 | * LOCKING: | ||
2310 | * spin_lock_irqsave(host_set lock) | ||
2311 | */ | ||
2312 | |||
2313 | |||
2314 | /** | ||
2315 | * ata_sg_init - Assign a scatter gather list to a queued command | ||
2316 | * @qc: Queued command | ||
2317 | * @sg: Scatter-gather list | ||
2318 | * @n_elem: length of sg list | ||
2319 | * | ||
2320 | * Attaches a scatter-gather list to a queued command. | ||
2321 | * | ||
2322 | * LOCKING: | ||
2323 | */ | ||
2324 | |||
2107 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | 2325 | void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
2108 | unsigned int n_elem) | 2326 | unsigned int n_elem) |
2109 | { | 2327 | { |
@@ -2113,14 +2331,16 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | |||
2113 | } | 2331 | } |
2114 | 2332 | ||
2115 | /** | 2333 | /** |
2116 | * ata_sg_setup_one - | 2334 | * ata_sg_setup_one - DMA-map the memory buffer associated with a command. |
2117 | * @qc: | 2335 | * @qc: Command with memory buffer to be mapped. |
2336 | * | ||
2337 | * DMA-map the memory buffer associated with queued_cmd @qc. | ||
2118 | * | 2338 | * |
2119 | * LOCKING: | 2339 | * LOCKING: |
2120 | * spin_lock_irqsave(host_set lock) | 2340 | * spin_lock_irqsave(host_set lock) |
2121 | * | 2341 | * |
2122 | * RETURNS: | 2342 | * RETURNS: |
2123 | * | 2343 | * Zero on success, negative on error. |
2124 | */ | 2344 | */ |
2125 | 2345 | ||
2126 | static int ata_sg_setup_one(struct ata_queued_cmd *qc) | 2346 | static int ata_sg_setup_one(struct ata_queued_cmd *qc) |
@@ -2131,11 +2351,12 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) | |||
2131 | dma_addr_t dma_address; | 2351 | dma_addr_t dma_address; |
2132 | 2352 | ||
2133 | dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, | 2353 | dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt, |
2134 | sg_dma_len(sg), dir); | 2354 | sg->length, dir); |
2135 | if (dma_mapping_error(dma_address)) | 2355 | if (dma_mapping_error(dma_address)) |
2136 | return -1; | 2356 | return -1; |
2137 | 2357 | ||
2138 | sg_dma_address(sg) = dma_address; | 2358 | sg_dma_address(sg) = dma_address; |
2359 | sg_dma_len(sg) = sg->length; | ||
2139 | 2360 | ||
2140 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), | 2361 | DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg), |
2141 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); | 2362 | qc->tf.flags & ATA_TFLAG_WRITE ? "write" : "read"); |
@@ -2144,13 +2365,16 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) | |||
2144 | } | 2365 | } |
2145 | 2366 | ||
2146 | /** | 2367 | /** |
2147 | * ata_sg_setup - | 2368 | * ata_sg_setup - DMA-map the scatter-gather table associated with a command. |
2148 | * @qc: | 2369 | * @qc: Command with scatter-gather table to be mapped. |
2370 | * | ||
2371 | * DMA-map the scatter-gather table associated with queued_cmd @qc. | ||
2149 | * | 2372 | * |
2150 | * LOCKING: | 2373 | * LOCKING: |
2151 | * spin_lock_irqsave(host_set lock) | 2374 | * spin_lock_irqsave(host_set lock) |
2152 | * | 2375 | * |
2153 | * RETURNS: | 2376 | * RETURNS: |
2377 | * Zero on success, negative on error. | ||
2154 | * | 2378 | * |
2155 | */ | 2379 | */ |
2156 | 2380 | ||
@@ -2180,6 +2404,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) | |||
2180 | * @ap: | 2404 | * @ap: |
2181 | * | 2405 | * |
2182 | * LOCKING: | 2406 | * LOCKING: |
2407 | * None. (executing in kernel thread context) | ||
2183 | * | 2408 | * |
2184 | * RETURNS: | 2409 | * RETURNS: |
2185 | * | 2410 | * |
@@ -2227,6 +2452,7 @@ static unsigned long ata_pio_poll(struct ata_port *ap) | |||
2227 | * @ap: | 2452 | * @ap: |
2228 | * | 2453 | * |
2229 | * LOCKING: | 2454 | * LOCKING: |
2455 | * None. (executing in kernel thread context) | ||
2230 | */ | 2456 | */ |
2231 | 2457 | ||
2232 | static void ata_pio_complete (struct ata_port *ap) | 2458 | static void ata_pio_complete (struct ata_port *ap) |
@@ -2269,6 +2495,18 @@ static void ata_pio_complete (struct ata_port *ap) | |||
2269 | ata_qc_complete(qc, drv_stat); | 2495 | ata_qc_complete(qc, drv_stat); |
2270 | } | 2496 | } |
2271 | 2497 | ||
2498 | |||
2499 | /** | ||
2500 | * swap_buf_le16 - | ||
2501 | * @buf: Buffer to swap | ||
2502 | * @buf_words: Number of 16-bit words in buffer. | ||
2503 | * | ||
2504 | * Swap halves of 16-bit words if needed to convert from | ||
2505 | * little-endian byte order to native cpu byte order, or | ||
2506 | * vice-versa. | ||
2507 | * | ||
2508 | * LOCKING: | ||
2509 | */ | ||
2272 | void swap_buf_le16(u16 *buf, unsigned int buf_words) | 2510 | void swap_buf_le16(u16 *buf, unsigned int buf_words) |
2273 | { | 2511 | { |
2274 | #ifdef __BIG_ENDIAN | 2512 | #ifdef __BIG_ENDIAN |
@@ -2340,7 +2578,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
2340 | qc->cursect++; | 2578 | qc->cursect++; |
2341 | qc->cursg_ofs++; | 2579 | qc->cursg_ofs++; |
2342 | 2580 | ||
2343 | if ((qc->cursg_ofs * ATA_SECT_SIZE) == sg_dma_len(&sg[qc->cursg])) { | 2581 | if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) { |
2344 | qc->cursg++; | 2582 | qc->cursg++; |
2345 | qc->cursg_ofs = 0; | 2583 | qc->cursg_ofs = 0; |
2346 | } | 2584 | } |
@@ -2377,7 +2615,7 @@ next_page: | |||
2377 | page = nth_page(page, (offset >> PAGE_SHIFT)); | 2615 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
2378 | offset %= PAGE_SIZE; | 2616 | offset %= PAGE_SIZE; |
2379 | 2617 | ||
2380 | count = min(sg_dma_len(sg) - qc->cursg_ofs, bytes); | 2618 | count = min(sg->length - qc->cursg_ofs, bytes); |
2381 | 2619 | ||
2382 | /* don't cross page boundaries */ | 2620 | /* don't cross page boundaries */ |
2383 | count = min(count, (unsigned int)PAGE_SIZE - offset); | 2621 | count = min(count, (unsigned int)PAGE_SIZE - offset); |
@@ -2388,7 +2626,7 @@ next_page: | |||
2388 | qc->curbytes += count; | 2626 | qc->curbytes += count; |
2389 | qc->cursg_ofs += count; | 2627 | qc->cursg_ofs += count; |
2390 | 2628 | ||
2391 | if (qc->cursg_ofs == sg_dma_len(sg)) { | 2629 | if (qc->cursg_ofs == sg->length) { |
2392 | qc->cursg++; | 2630 | qc->cursg++; |
2393 | qc->cursg_ofs = 0; | 2631 | qc->cursg_ofs = 0; |
2394 | } | 2632 | } |
@@ -2401,7 +2639,7 @@ next_page: | |||
2401 | kunmap(page); | 2639 | kunmap(page); |
2402 | 2640 | ||
2403 | if (bytes) { | 2641 | if (bytes) { |
2404 | if (qc->cursg_ofs < sg_dma_len(sg)) | 2642 | if (qc->cursg_ofs < sg->length) |
2405 | goto next_page; | 2643 | goto next_page; |
2406 | goto next_sg; | 2644 | goto next_sg; |
2407 | } | 2645 | } |
@@ -2444,6 +2682,7 @@ err_out: | |||
2444 | * @ap: | 2682 | * @ap: |
2445 | * | 2683 | * |
2446 | * LOCKING: | 2684 | * LOCKING: |
2685 | * None. (executing in kernel thread context) | ||
2447 | */ | 2686 | */ |
2448 | 2687 | ||
2449 | static void ata_pio_block(struct ata_port *ap) | 2688 | static void ata_pio_block(struct ata_port *ap) |
@@ -2569,7 +2808,7 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | |||
2569 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); | 2808 | ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); |
2570 | qc->dma_dir = DMA_FROM_DEVICE; | 2809 | qc->dma_dir = DMA_FROM_DEVICE; |
2571 | 2810 | ||
2572 | memset(&qc->cdb, 0, sizeof(ap->cdb_len)); | 2811 | memset(&qc->cdb, 0, ap->cdb_len); |
2573 | qc->cdb[0] = REQUEST_SENSE; | 2812 | qc->cdb[0] = REQUEST_SENSE; |
2574 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; | 2813 | qc->cdb[4] = SCSI_SENSE_BUFFERSIZE; |
2575 | 2814 | ||
@@ -2612,6 +2851,7 @@ static void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, | |||
2612 | * transaction completed successfully. | 2851 | * transaction completed successfully. |
2613 | * | 2852 | * |
2614 | * LOCKING: | 2853 | * LOCKING: |
2854 | * Inherited from SCSI layer (none, can sleep) | ||
2615 | */ | 2855 | */ |
2616 | 2856 | ||
2617 | static void ata_qc_timeout(struct ata_queued_cmd *qc) | 2857 | static void ata_qc_timeout(struct ata_queued_cmd *qc) |
@@ -2721,6 +2961,7 @@ out: | |||
2721 | * @dev: Device from whom we request an available command structure | 2961 | * @dev: Device from whom we request an available command structure |
2722 | * | 2962 | * |
2723 | * LOCKING: | 2963 | * LOCKING: |
2964 | * None. | ||
2724 | */ | 2965 | */ |
2725 | 2966 | ||
2726 | static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) | 2967 | static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) |
@@ -2746,6 +2987,7 @@ static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap) | |||
2746 | * @dev: Device from whom we request an available command structure | 2987 | * @dev: Device from whom we request an available command structure |
2747 | * | 2988 | * |
2748 | * LOCKING: | 2989 | * LOCKING: |
2990 | * None. | ||
2749 | */ | 2991 | */ |
2750 | 2992 | ||
2751 | struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, | 2993 | struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap, |
@@ -2810,6 +3052,7 @@ static void __ata_qc_complete(struct ata_queued_cmd *qc) | |||
2810 | * in case something prevents using it. | 3052 | * in case something prevents using it. |
2811 | * | 3053 | * |
2812 | * LOCKING: | 3054 | * LOCKING: |
3055 | * spin_lock_irqsave(host_set lock) | ||
2813 | * | 3056 | * |
2814 | */ | 3057 | */ |
2815 | void ata_qc_free(struct ata_queued_cmd *qc) | 3058 | void ata_qc_free(struct ata_queued_cmd *qc) |
@@ -2823,9 +3066,13 @@ void ata_qc_free(struct ata_queued_cmd *qc) | |||
2823 | /** | 3066 | /** |
2824 | * ata_qc_complete - Complete an active ATA command | 3067 | * ata_qc_complete - Complete an active ATA command |
2825 | * @qc: Command to complete | 3068 | * @qc: Command to complete |
2826 | * @drv_stat: ATA status register contents | 3069 | * @drv_stat: ATA Status register contents |
3070 | * | ||
3071 | * Indicate to the mid and upper layers that an ATA | ||
3072 | * command has completed, with either an ok or not-ok status. | ||
2827 | * | 3073 | * |
2828 | * LOCKING: | 3074 | * LOCKING: |
3075 | * spin_lock_irqsave(host_set lock) | ||
2829 | * | 3076 | * |
2830 | */ | 3077 | */ |
2831 | 3078 | ||
@@ -2841,6 +3088,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) | |||
2841 | 3088 | ||
2842 | /* call completion callback */ | 3089 | /* call completion callback */ |
2843 | rc = qc->complete_fn(qc, drv_stat); | 3090 | rc = qc->complete_fn(qc, drv_stat); |
3091 | qc->flags &= ~ATA_QCFLAG_ACTIVE; | ||
2844 | 3092 | ||
2845 | /* if callback indicates not to complete command (non-zero), | 3093 | /* if callback indicates not to complete command (non-zero), |
2846 | * return immediately | 3094 | * return immediately |
@@ -2920,6 +3168,7 @@ err_out: | |||
2920 | return -1; | 3168 | return -1; |
2921 | } | 3169 | } |
2922 | 3170 | ||
3171 | |||
2923 | /** | 3172 | /** |
2924 | * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner | 3173 | * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner |
2925 | * @qc: command to issue to device | 3174 | * @qc: command to issue to device |
@@ -2929,6 +3178,8 @@ err_out: | |||
2929 | * classes called "protocols", and issuing each type of protocol | 3178 | * classes called "protocols", and issuing each type of protocol |
2930 | * is slightly different. | 3179 | * is slightly different. |
2931 | * | 3180 | * |
3181 | * May be used as the qc_issue() entry in ata_port_operations. | ||
3182 | * | ||
2932 | * LOCKING: | 3183 | * LOCKING: |
2933 | * spin_lock_irqsave(host_set lock) | 3184 | * spin_lock_irqsave(host_set lock) |
2934 | * | 3185 | * |
@@ -2986,7 +3237,7 @@ int ata_qc_issue_prot(struct ata_queued_cmd *qc) | |||
2986 | } | 3237 | } |
2987 | 3238 | ||
2988 | /** | 3239 | /** |
2989 | * ata_bmdma_setup - Set up PCI IDE BMDMA transaction | 3240 | * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction |
2990 | * @qc: Info associated with this ATA transaction. | 3241 | * @qc: Info associated with this ATA transaction. |
2991 | * | 3242 | * |
2992 | * LOCKING: | 3243 | * LOCKING: |
@@ -3093,6 +3344,18 @@ static void ata_bmdma_start_pio (struct ata_queued_cmd *qc) | |||
3093 | ap->ioaddr.bmdma_addr + ATA_DMA_CMD); | 3344 | ap->ioaddr.bmdma_addr + ATA_DMA_CMD); |
3094 | } | 3345 | } |
3095 | 3346 | ||
3347 | |||
3348 | /** | ||
3349 | * ata_bmdma_start - Start a PCI IDE BMDMA transaction | ||
3350 | * @qc: Info associated with this ATA transaction. | ||
3351 | * | ||
3352 | * Writes the ATA_DMA_START flag to the DMA command register. | ||
3353 | * | ||
3354 | * May be used as the bmdma_start() entry in ata_port_operations. | ||
3355 | * | ||
3356 | * LOCKING: | ||
3357 | * spin_lock_irqsave(host_set lock) | ||
3358 | */ | ||
3096 | void ata_bmdma_start(struct ata_queued_cmd *qc) | 3359 | void ata_bmdma_start(struct ata_queued_cmd *qc) |
3097 | { | 3360 | { |
3098 | if (qc->ap->flags & ATA_FLAG_MMIO) | 3361 | if (qc->ap->flags & ATA_FLAG_MMIO) |
@@ -3101,6 +3364,20 @@ void ata_bmdma_start(struct ata_queued_cmd *qc) | |||
3101 | ata_bmdma_start_pio(qc); | 3364 | ata_bmdma_start_pio(qc); |
3102 | } | 3365 | } |
3103 | 3366 | ||
3367 | |||
3368 | /** | ||
3369 | * ata_bmdma_setup - Set up PCI IDE BMDMA transaction | ||
3370 | * @qc: Info associated with this ATA transaction. | ||
3371 | * | ||
3372 | * Writes address of PRD table to device's PRD Table Address | ||
3373 | * register, sets the DMA control register, and calls | ||
3374 | * ops->exec_command() to start the transfer. | ||
3375 | * | ||
3376 | * May be used as the bmdma_setup() entry in ata_port_operations. | ||
3377 | * | ||
3378 | * LOCKING: | ||
3379 | * spin_lock_irqsave(host_set lock) | ||
3380 | */ | ||
3104 | void ata_bmdma_setup(struct ata_queued_cmd *qc) | 3381 | void ata_bmdma_setup(struct ata_queued_cmd *qc) |
3105 | { | 3382 | { |
3106 | if (qc->ap->flags & ATA_FLAG_MMIO) | 3383 | if (qc->ap->flags & ATA_FLAG_MMIO) |
@@ -3109,6 +3386,19 @@ void ata_bmdma_setup(struct ata_queued_cmd *qc) | |||
3109 | ata_bmdma_setup_pio(qc); | 3386 | ata_bmdma_setup_pio(qc); |
3110 | } | 3387 | } |
3111 | 3388 | ||
3389 | |||
3390 | /** | ||
3391 | * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt. | ||
3392 | * @ap: Port associated with this ATA transaction. | ||
3393 | * | ||
3394 | * Clear interrupt and error flags in DMA status register. | ||
3395 | * | ||
3396 | * May be used as the irq_clear() entry in ata_port_operations. | ||
3397 | * | ||
3398 | * LOCKING: | ||
3399 | * spin_lock_irqsave(host_set lock) | ||
3400 | */ | ||
3401 | |||
3112 | void ata_bmdma_irq_clear(struct ata_port *ap) | 3402 | void ata_bmdma_irq_clear(struct ata_port *ap) |
3113 | { | 3403 | { |
3114 | if (ap->flags & ATA_FLAG_MMIO) { | 3404 | if (ap->flags & ATA_FLAG_MMIO) { |
@@ -3121,6 +3411,19 @@ void ata_bmdma_irq_clear(struct ata_port *ap) | |||
3121 | 3411 | ||
3122 | } | 3412 | } |
3123 | 3413 | ||
3414 | |||
3415 | /** | ||
3416 | * ata_bmdma_status - Read PCI IDE BMDMA status | ||
3417 | * @ap: Port associated with this ATA transaction. | ||
3418 | * | ||
3419 | * Read and return BMDMA status register. | ||
3420 | * | ||
3421 | * May be used as the bmdma_status() entry in ata_port_operations. | ||
3422 | * | ||
3423 | * LOCKING: | ||
3424 | * spin_lock_irqsave(host_set lock) | ||
3425 | */ | ||
3426 | |||
3124 | u8 ata_bmdma_status(struct ata_port *ap) | 3427 | u8 ata_bmdma_status(struct ata_port *ap) |
3125 | { | 3428 | { |
3126 | u8 host_stat; | 3429 | u8 host_stat; |
@@ -3132,6 +3435,19 @@ u8 ata_bmdma_status(struct ata_port *ap) | |||
3132 | return host_stat; | 3435 | return host_stat; |
3133 | } | 3436 | } |
3134 | 3437 | ||
3438 | |||
3439 | /** | ||
3440 | * ata_bmdma_stop - Stop PCI IDE BMDMA transfer | ||
3441 | * @ap: Port associated with this ATA transaction. | ||
3442 | * | ||
3443 | * Clears the ATA_DMA_START flag in the dma control register | ||
3444 | * | ||
3445 | * May be used as the bmdma_stop() entry in ata_port_operations. | ||
3446 | * | ||
3447 | * LOCKING: | ||
3448 | * spin_lock_irqsave(host_set lock) | ||
3449 | */ | ||
3450 | |||
3135 | void ata_bmdma_stop(struct ata_port *ap) | 3451 | void ata_bmdma_stop(struct ata_port *ap) |
3136 | { | 3452 | { |
3137 | if (ap->flags & ATA_FLAG_MMIO) { | 3453 | if (ap->flags & ATA_FLAG_MMIO) { |
@@ -3231,13 +3547,18 @@ idle_irq: | |||
3231 | 3547 | ||
3232 | /** | 3548 | /** |
3233 | * ata_interrupt - Default ATA host interrupt handler | 3549 | * ata_interrupt - Default ATA host interrupt handler |
3234 | * @irq: irq line | 3550 | * @irq: irq line (unused) |
3235 | * @dev_instance: pointer to our host information structure | 3551 | * @dev_instance: pointer to our ata_host_set information structure |
3236 | * @regs: unused | 3552 | * @regs: unused |
3237 | * | 3553 | * |
3554 | * Default interrupt handler for PCI IDE devices. Calls | ||
3555 | * ata_host_intr() for each port that is not disabled. | ||
3556 | * | ||
3238 | * LOCKING: | 3557 | * LOCKING: |
3558 | * Obtains host_set lock during operation. | ||
3239 | * | 3559 | * |
3240 | * RETURNS: | 3560 | * RETURNS: |
3561 | * IRQ_NONE or IRQ_HANDLED. | ||
3241 | * | 3562 | * |
3242 | */ | 3563 | */ |
3243 | 3564 | ||
@@ -3259,7 +3580,8 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance, struct pt_regs *regs) | |||
3259 | struct ata_queued_cmd *qc; | 3580 | struct ata_queued_cmd *qc; |
3260 | 3581 | ||
3261 | qc = ata_qc_from_tag(ap, ap->active_tag); | 3582 | qc = ata_qc_from_tag(ap, ap->active_tag); |
3262 | if (qc && (!(qc->tf.ctl & ATA_NIEN))) | 3583 | if (qc && (!(qc->tf.ctl & ATA_NIEN)) && |
3584 | (qc->flags & ATA_QCFLAG_ACTIVE)) | ||
3263 | handled |= ata_host_intr(ap, qc); | 3585 | handled |= ata_host_intr(ap, qc); |
3264 | } | 3586 | } |
3265 | } | 3587 | } |
@@ -3329,6 +3651,19 @@ err_out: | |||
3329 | ata_qc_complete(qc, ATA_ERR); | 3651 | ata_qc_complete(qc, ATA_ERR); |
3330 | } | 3652 | } |
3331 | 3653 | ||
3654 | |||
3655 | /** | ||
3656 | * ata_port_start - Set port up for dma. | ||
3657 | * @ap: Port to initialize | ||
3658 | * | ||
3659 | * Called just after data structures for each port are | ||
3660 | * initialized. Allocates space for PRD table. | ||
3661 | * | ||
3662 | * May be used as the port_start() entry in ata_port_operations. | ||
3663 | * | ||
3664 | * LOCKING: | ||
3665 | */ | ||
3666 | |||
3332 | int ata_port_start (struct ata_port *ap) | 3667 | int ata_port_start (struct ata_port *ap) |
3333 | { | 3668 | { |
3334 | struct device *dev = ap->host_set->dev; | 3669 | struct device *dev = ap->host_set->dev; |
@@ -3342,6 +3677,18 @@ int ata_port_start (struct ata_port *ap) | |||
3342 | return 0; | 3677 | return 0; |
3343 | } | 3678 | } |
3344 | 3679 | ||
3680 | |||
3681 | /** | ||
3682 | * ata_port_stop - Undo ata_port_start() | ||
3683 | * @ap: Port to shut down | ||
3684 | * | ||
3685 | * Frees the PRD table. | ||
3686 | * | ||
3687 | * May be used as the port_stop() entry in ata_port_operations. | ||
3688 | * | ||
3689 | * LOCKING: | ||
3690 | */ | ||
3691 | |||
3345 | void ata_port_stop (struct ata_port *ap) | 3692 | void ata_port_stop (struct ata_port *ap) |
3346 | { | 3693 | { |
3347 | struct device *dev = ap->host_set->dev; | 3694 | struct device *dev = ap->host_set->dev; |
@@ -3349,6 +3696,13 @@ void ata_port_stop (struct ata_port *ap) | |||
3349 | dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); | 3696 | dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma); |
3350 | } | 3697 | } |
3351 | 3698 | ||
3699 | void ata_host_stop (struct ata_host_set *host_set) | ||
3700 | { | ||
3701 | if (host_set->mmio_base) | ||
3702 | iounmap(host_set->mmio_base); | ||
3703 | } | ||
3704 | |||
3705 | |||
3352 | /** | 3706 | /** |
3353 | * ata_host_remove - Unregister SCSI host structure with upper layers | 3707 | * ata_host_remove - Unregister SCSI host structure with upper layers |
3354 | * @ap: Port to unregister | 3708 | * @ap: Port to unregister |
@@ -3377,7 +3731,11 @@ static void ata_host_remove(struct ata_port *ap, unsigned int do_unregister) | |||
3377 | * @ent: Probe information provided by low-level driver | 3731 | * @ent: Probe information provided by low-level driver |
3378 | * @port_no: Port number associated with this ata_port | 3732 | * @port_no: Port number associated with this ata_port |
3379 | * | 3733 | * |
3734 | * Initialize a new ata_port structure, and its associated | ||
3735 | * scsi_host. | ||
3736 | * | ||
3380 | * LOCKING: | 3737 | * LOCKING: |
3738 | * Inherited from caller. | ||
3381 | * | 3739 | * |
3382 | */ | 3740 | */ |
3383 | 3741 | ||
@@ -3432,9 +3790,13 @@ static void ata_host_init(struct ata_port *ap, struct Scsi_Host *host, | |||
3432 | * @host_set: Collections of ports to which we add | 3790 | * @host_set: Collections of ports to which we add |
3433 | * @port_no: Port number associated with this host | 3791 | * @port_no: Port number associated with this host |
3434 | * | 3792 | * |
3793 | * Attach low-level ATA driver to system. | ||
3794 | * | ||
3435 | * LOCKING: | 3795 | * LOCKING: |
3796 | * PCI/etc. bus probe sem. | ||
3436 | * | 3797 | * |
3437 | * RETURNS: | 3798 | * RETURNS: |
3799 | * New ata_port on success, for NULL on error. | ||
3438 | * | 3800 | * |
3439 | */ | 3801 | */ |
3440 | 3802 | ||
@@ -3467,12 +3829,22 @@ err_out: | |||
3467 | } | 3829 | } |
3468 | 3830 | ||
3469 | /** | 3831 | /** |
3470 | * ata_device_add - | 3832 | * ata_device_add - Register hardware device with ATA and SCSI layers |
3471 | * @ent: | 3833 | * @ent: Probe information describing hardware device to be registered |
3834 | * | ||
3835 | * This function processes the information provided in the probe | ||
3836 | * information struct @ent, allocates the necessary ATA and SCSI | ||
3837 | * host information structures, initializes them, and registers | ||
3838 | * everything with requisite kernel subsystems. | ||
3839 | * | ||
3840 | * This function requests irqs, probes the ATA bus, and probes | ||
3841 | * the SCSI bus. | ||
3472 | * | 3842 | * |
3473 | * LOCKING: | 3843 | * LOCKING: |
3844 | * PCI/etc. bus probe sem. | ||
3474 | * | 3845 | * |
3475 | * RETURNS: | 3846 | * RETURNS: |
3847 | * Number of ports registered. Zero on error (no ports registered). | ||
3476 | * | 3848 | * |
3477 | */ | 3849 | */ |
3478 | 3850 | ||
@@ -3624,7 +3996,15 @@ int ata_scsi_release(struct Scsi_Host *host) | |||
3624 | /** | 3996 | /** |
3625 | * ata_std_ports - initialize ioaddr with standard port offsets. | 3997 | * ata_std_ports - initialize ioaddr with standard port offsets. |
3626 | * @ioaddr: IO address structure to be initialized | 3998 | * @ioaddr: IO address structure to be initialized |
3999 | * | ||
4000 | * Utility function which initializes data_addr, error_addr, | ||
4001 | * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr, | ||
4002 | * device_addr, status_addr, and command_addr to standard offsets | ||
4003 | * relative to cmd_addr. | ||
4004 | * | ||
4005 | * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr. | ||
3627 | */ | 4006 | */ |
4007 | |||
3628 | void ata_std_ports(struct ata_ioports *ioaddr) | 4008 | void ata_std_ports(struct ata_ioports *ioaddr) |
3629 | { | 4009 | { |
3630 | ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; | 4010 | ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA; |
@@ -3666,6 +4046,20 @@ ata_probe_ent_alloc(struct device *dev, struct ata_port_info *port) | |||
3666 | return probe_ent; | 4046 | return probe_ent; |
3667 | } | 4047 | } |
3668 | 4048 | ||
4049 | |||
4050 | |||
4051 | /** | ||
4052 | * ata_pci_init_native_mode - Initialize native-mode driver | ||
4053 | * @pdev: pci device to be initialized | ||
4054 | * @port: array[2] of pointers to port info structures. | ||
4055 | * | ||
4056 | * Utility function which allocates and initializes an | ||
4057 | * ata_probe_ent structure for a standard dual-port | ||
4058 | * PIO-based IDE controller. The returned ata_probe_ent | ||
4059 | * structure can be passed to ata_device_add(). The returned | ||
4060 | * ata_probe_ent structure should then be freed with kfree(). | ||
4061 | */ | ||
4062 | |||
3669 | #ifdef CONFIG_PCI | 4063 | #ifdef CONFIG_PCI |
3670 | struct ata_probe_ent * | 4064 | struct ata_probe_ent * |
3671 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) | 4065 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port) |
@@ -3747,10 +4141,19 @@ ata_pci_init_legacy_mode(struct pci_dev *pdev, struct ata_port_info **port, | |||
3747 | * @port_info: Information from low-level host driver | 4141 | * @port_info: Information from low-level host driver |
3748 | * @n_ports: Number of ports attached to host controller | 4142 | * @n_ports: Number of ports attached to host controller |
3749 | * | 4143 | * |
4144 | * This is a helper function which can be called from a driver's | ||
4145 | * xxx_init_one() probe function if the hardware uses traditional | ||
4146 | * IDE taskfile registers. | ||
4147 | * | ||
4148 | * This function calls pci_enable_device(), reserves its register | ||
4149 | * regions, sets the dma mask, enables bus master mode, and calls | ||
4150 | * ata_device_add() | ||
4151 | * | ||
3750 | * LOCKING: | 4152 | * LOCKING: |
3751 | * Inherited from PCI layer (may sleep). | 4153 | * Inherited from PCI layer (may sleep). |
3752 | * | 4154 | * |
3753 | * RETURNS: | 4155 | * RETURNS: |
4156 | * Zero on success, negative on errno-based value on error. | ||
3754 | * | 4157 | * |
3755 | */ | 4158 | */ |
3756 | 4159 | ||
@@ -3905,10 +4308,6 @@ void ata_pci_remove_one (struct pci_dev *pdev) | |||
3905 | } | 4308 | } |
3906 | 4309 | ||
3907 | free_irq(host_set->irq, host_set); | 4310 | free_irq(host_set->irq, host_set); |
3908 | if (host_set->ops->host_stop) | ||
3909 | host_set->ops->host_stop(host_set); | ||
3910 | if (host_set->mmio_base) | ||
3911 | iounmap(host_set->mmio_base); | ||
3912 | 4311 | ||
3913 | for (i = 0; i < host_set->n_ports; i++) { | 4312 | for (i = 0; i < host_set->n_ports; i++) { |
3914 | ap = host_set->ports[i]; | 4313 | ap = host_set->ports[i]; |
@@ -3927,6 +4326,9 @@ void ata_pci_remove_one (struct pci_dev *pdev) | |||
3927 | scsi_host_put(ap->host); | 4326 | scsi_host_put(ap->host); |
3928 | } | 4327 | } |
3929 | 4328 | ||
4329 | if (host_set->ops->host_stop) | ||
4330 | host_set->ops->host_stop(host_set); | ||
4331 | |||
3930 | kfree(host_set); | 4332 | kfree(host_set); |
3931 | 4333 | ||
3932 | pci_release_regions(pdev); | 4334 | pci_release_regions(pdev); |
@@ -3970,15 +4372,6 @@ int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits) | |||
3970 | #endif /* CONFIG_PCI */ | 4372 | #endif /* CONFIG_PCI */ |
3971 | 4373 | ||
3972 | 4374 | ||
3973 | /** | ||
3974 | * ata_init - | ||
3975 | * | ||
3976 | * LOCKING: | ||
3977 | * | ||
3978 | * RETURNS: | ||
3979 | * | ||
3980 | */ | ||
3981 | |||
3982 | static int __init ata_init(void) | 4375 | static int __init ata_init(void) |
3983 | { | 4376 | { |
3984 | ata_wq = create_workqueue("ata"); | 4377 | ata_wq = create_workqueue("ata"); |
@@ -4024,6 +4417,7 @@ EXPORT_SYMBOL_GPL(ata_chk_err); | |||
4024 | EXPORT_SYMBOL_GPL(ata_exec_command); | 4417 | EXPORT_SYMBOL_GPL(ata_exec_command); |
4025 | EXPORT_SYMBOL_GPL(ata_port_start); | 4418 | EXPORT_SYMBOL_GPL(ata_port_start); |
4026 | EXPORT_SYMBOL_GPL(ata_port_stop); | 4419 | EXPORT_SYMBOL_GPL(ata_port_stop); |
4420 | EXPORT_SYMBOL_GPL(ata_host_stop); | ||
4027 | EXPORT_SYMBOL_GPL(ata_interrupt); | 4421 | EXPORT_SYMBOL_GPL(ata_interrupt); |
4028 | EXPORT_SYMBOL_GPL(ata_qc_prep); | 4422 | EXPORT_SYMBOL_GPL(ata_qc_prep); |
4029 | EXPORT_SYMBOL_GPL(ata_bmdma_setup); | 4423 | EXPORT_SYMBOL_GPL(ata_bmdma_setup); |