18c2ecf20Sopenharmony_ci======================== 28c2ecf20Sopenharmony_cilibATA Developer's Guide 38c2ecf20Sopenharmony_ci======================== 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci:Author: Jeff Garzik 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciIntroduction 88c2ecf20Sopenharmony_ci============ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cilibATA is a library used inside the Linux kernel to support ATA host 118c2ecf20Sopenharmony_cicontrollers and devices. libATA provides an ATA driver API, class 128c2ecf20Sopenharmony_citransports for ATA and ATAPI devices, and SCSI<->ATA translation for ATA 138c2ecf20Sopenharmony_cidevices according to the T10 SAT specification. 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ciThis Guide documents the libATA driver API, library functions, library 168c2ecf20Sopenharmony_ciinternals, and a couple sample ATA low-level drivers. 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cilibata Driver API 198c2ecf20Sopenharmony_ci================= 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci:c:type:`struct ata_port_operations <ata_port_operations>` 228c2ecf20Sopenharmony_ciis defined for every low-level libata 238c2ecf20Sopenharmony_cihardware driver, and it controls how the low-level driver interfaces 248c2ecf20Sopenharmony_ciwith the ATA and SCSI layers. 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciFIS-based drivers will hook into the system with ``->qc_prep()`` and 278c2ecf20Sopenharmony_ci``->qc_issue()`` high-level hooks. Hardware which behaves in a manner 288c2ecf20Sopenharmony_cisimilar to PCI IDE hardware may utilize several generic helpers, 298c2ecf20Sopenharmony_cidefining at a bare minimum the bus I/O addresses of the ATA shadow 308c2ecf20Sopenharmony_ciregister blocks. 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci:c:type:`struct ata_port_operations <ata_port_operations>` 338c2ecf20Sopenharmony_ci---------------------------------------------------------- 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciDisable ATA port 368c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci:: 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci void (*port_disable) (struct ata_port *); 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciCalled from :c:func:`ata_bus_probe` error path, as well as when unregistering 448c2ecf20Sopenharmony_cifrom the SCSI module (rmmod, hot unplug). This function should do 458c2ecf20Sopenharmony_ciwhatever needs to be done to take the port out of use. In most cases, 468c2ecf20Sopenharmony_ci:c:func:`ata_port_disable` can be used as this hook. 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciCalled from :c:func:`ata_bus_probe` on a failed probe. Called from 498c2ecf20Sopenharmony_ci:c:func:`ata_scsi_release`. 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciPost-IDENTIFY device configuration 528c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci:: 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci void (*dev_config) (struct ata_port *, struct ata_device *); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciCalled after IDENTIFY [PACKET] DEVICE is issued to each device found. 608c2ecf20Sopenharmony_ciTypically used to apply device-specific fixups prior to issue of SET 618c2ecf20Sopenharmony_ciFEATURES - XFER MODE, and prior to operation. 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciThis entry may be specified as NULL in ata_port_operations. 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciSet PIO/DMA mode 668c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci:: 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci void (*set_piomode) (struct ata_port *, struct ata_device *); 718c2ecf20Sopenharmony_ci void (*set_dmamode) (struct ata_port *, struct ata_device *); 728c2ecf20Sopenharmony_ci void (*post_set_mode) (struct ata_port *); 738c2ecf20Sopenharmony_ci unsigned int (*mode_filter) (struct ata_port *, struct ata_device *, unsigned int); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ciHooks called prior to the issue of SET FEATURES - XFER MODE command. The 778c2ecf20Sopenharmony_cioptional ``->mode_filter()`` hook is called when libata has built a mask of 788c2ecf20Sopenharmony_cithe possible modes. This is passed to the ``->mode_filter()`` function 798c2ecf20Sopenharmony_ciwhich should return a mask of valid modes after filtering those 808c2ecf20Sopenharmony_ciunsuitable due to hardware limits. It is not valid to use this interface 818c2ecf20Sopenharmony_cito add modes. 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci``dev->pio_mode`` and ``dev->dma_mode`` are guaranteed to be valid when 848c2ecf20Sopenharmony_ci``->set_piomode()`` and when ``->set_dmamode()`` is called. The timings for 858c2ecf20Sopenharmony_ciany other drive sharing the cable will also be valid at this point. That 868c2ecf20Sopenharmony_ciis the library records the decisions for the modes of each drive on a 878c2ecf20Sopenharmony_cichannel before it attempts to set any of them. 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci``->post_set_mode()`` is called unconditionally, after the SET FEATURES - 908c2ecf20Sopenharmony_ciXFER MODE command completes successfully. 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci``->set_piomode()`` is always called (if present), but ``->set_dma_mode()`` 938c2ecf20Sopenharmony_ciis only called if DMA is possible. 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ciTaskfile read/write 968c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci:: 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci void (*sff_tf_load) (struct ata_port *ap, struct ata_taskfile *tf); 1018c2ecf20Sopenharmony_ci void (*sff_tf_read) (struct ata_port *ap, struct ata_taskfile *tf); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci``->tf_load()`` is called to load the given taskfile into hardware 1058c2ecf20Sopenharmony_ciregisters / DMA buffers. ``->tf_read()`` is called to read the hardware 1068c2ecf20Sopenharmony_ciregisters / DMA buffers, to obtain the current set of taskfile register 1078c2ecf20Sopenharmony_civalues. Most drivers for taskfile-based hardware (PIO or MMIO) use 1088c2ecf20Sopenharmony_ci:c:func:`ata_sff_tf_load` and :c:func:`ata_sff_tf_read` for these hooks. 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ciPIO data read/write 1118c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~ 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci:: 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci void (*sff_data_xfer) (struct ata_device *, unsigned char *, unsigned int, int); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ciAll bmdma-style drivers must implement this hook. This is the low-level 1198c2ecf20Sopenharmony_cioperation that actually copies the data bytes during a PIO data 1208c2ecf20Sopenharmony_citransfer. Typically the driver will choose one of 1218c2ecf20Sopenharmony_ci:c:func:`ata_sff_data_xfer`, or :c:func:`ata_sff_data_xfer32`. 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciATA command execute 1248c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~ 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci:: 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci void (*sff_exec_command)(struct ata_port *ap, struct ata_taskfile *tf); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cicauses an ATA command, previously loaded with ``->tf_load()``, to be 1328c2ecf20Sopenharmony_ciinitiated in hardware. Most drivers for taskfile-based hardware use 1338c2ecf20Sopenharmony_ci:c:func:`ata_sff_exec_command` for this hook. 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ciPer-cmd ATAPI DMA capabilities filter 1368c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci:: 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci int (*check_atapi_dma) (struct ata_queued_cmd *qc); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ciAllow low-level driver to filter ATA PACKET commands, returning a status 1448c2ecf20Sopenharmony_ciindicating whether or not it is OK to use DMA for the supplied PACKET 1458c2ecf20Sopenharmony_cicommand. 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ciThis hook may be specified as NULL, in which case libata will assume 1488c2ecf20Sopenharmony_cithat atapi dma can be supported. 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ciRead specific ATA shadow registers 1518c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci:: 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci u8 (*sff_check_status)(struct ata_port *ap); 1568c2ecf20Sopenharmony_ci u8 (*sff_check_altstatus)(struct ata_port *ap); 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciReads the Status/AltStatus ATA shadow register from hardware. On some 1608c2ecf20Sopenharmony_cihardware, reading the Status register has the side effect of clearing 1618c2ecf20Sopenharmony_cithe interrupt condition. Most drivers for taskfile-based hardware use 1628c2ecf20Sopenharmony_ci:c:func:`ata_sff_check_status` for this hook. 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ciWrite specific ATA shadow register 1658c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci:: 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci void (*sff_set_devctl)(struct ata_port *ap, u8 ctl); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ciWrite the device control ATA shadow register to the hardware. Most 1738c2ecf20Sopenharmony_cidrivers don't need to define this. 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ciSelect ATA device on bus 1768c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~ 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci:: 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci void (*sff_dev_select)(struct ata_port *ap, unsigned int device); 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ciIssues the low-level hardware command(s) that causes one of N hardware 1848c2ecf20Sopenharmony_cidevices to be considered 'selected' (active and available for use) on 1858c2ecf20Sopenharmony_cithe ATA bus. This generally has no meaning on FIS-based devices. 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ciMost drivers for taskfile-based hardware use :c:func:`ata_sff_dev_select` for 1888c2ecf20Sopenharmony_cithis hook. 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ciPrivate tuning method 1918c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci:: 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci void (*set_mode) (struct ata_port *ap); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ciBy default libata performs drive and controller tuning in accordance 1998c2ecf20Sopenharmony_ciwith the ATA timing rules and also applies blacklists and cable limits. 2008c2ecf20Sopenharmony_ciSome controllers need special handling and have custom tuning rules, 2018c2ecf20Sopenharmony_citypically raid controllers that use ATA commands but do not actually do 2028c2ecf20Sopenharmony_cidrive timing. 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci **Warning** 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci This hook should not be used to replace the standard controller 2078c2ecf20Sopenharmony_ci tuning logic when a controller has quirks. Replacing the default 2088c2ecf20Sopenharmony_ci tuning logic in that case would bypass handling for drive and bridge 2098c2ecf20Sopenharmony_ci quirks that may be important to data reliability. If a controller 2108c2ecf20Sopenharmony_ci needs to filter the mode selection it should use the mode_filter 2118c2ecf20Sopenharmony_ci hook instead. 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ciControl PCI IDE BMDMA engine 2148c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci:: 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci void (*bmdma_setup) (struct ata_queued_cmd *qc); 2198c2ecf20Sopenharmony_ci void (*bmdma_start) (struct ata_queued_cmd *qc); 2208c2ecf20Sopenharmony_ci void (*bmdma_stop) (struct ata_port *ap); 2218c2ecf20Sopenharmony_ci u8 (*bmdma_status) (struct ata_port *ap); 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ciWhen setting up an IDE BMDMA transaction, these hooks arm 2258c2ecf20Sopenharmony_ci(``->bmdma_setup``), fire (``->bmdma_start``), and halt (``->bmdma_stop``) the 2268c2ecf20Sopenharmony_cihardware's DMA engine. ``->bmdma_status`` is used to read the standard PCI 2278c2ecf20Sopenharmony_ciIDE DMA Status register. 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ciThese hooks are typically either no-ops, or simply not implemented, in 2308c2ecf20Sopenharmony_ciFIS-based drivers. 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ciMost legacy IDE drivers use :c:func:`ata_bmdma_setup` for the 2338c2ecf20Sopenharmony_ci:c:func:`bmdma_setup` hook. :c:func:`ata_bmdma_setup` will write the pointer 2348c2ecf20Sopenharmony_cito the PRD table to the IDE PRD Table Address register, enable DMA in the DMA 2358c2ecf20Sopenharmony_ciCommand register, and call :c:func:`exec_command` to begin the transfer. 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ciMost legacy IDE drivers use :c:func:`ata_bmdma_start` for the 2388c2ecf20Sopenharmony_ci:c:func:`bmdma_start` hook. :c:func:`ata_bmdma_start` will write the 2398c2ecf20Sopenharmony_ciATA_DMA_START flag to the DMA Command register. 2408c2ecf20Sopenharmony_ci 2418c2ecf20Sopenharmony_ciMany legacy IDE drivers use :c:func:`ata_bmdma_stop` for the 2428c2ecf20Sopenharmony_ci:c:func:`bmdma_stop` hook. :c:func:`ata_bmdma_stop` clears the ATA_DMA_START 2438c2ecf20Sopenharmony_ciflag in the DMA command register. 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ciMany legacy IDE drivers use :c:func:`ata_bmdma_status` as the 2468c2ecf20Sopenharmony_ci:c:func:`bmdma_status` hook. 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ciHigh-level taskfile hooks 2498c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~ 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci:: 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci enum ata_completion_errors (*qc_prep) (struct ata_queued_cmd *qc); 2548c2ecf20Sopenharmony_ci int (*qc_issue) (struct ata_queued_cmd *qc); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ciHigher-level hooks, these two hooks can potentially supersede several of 2588c2ecf20Sopenharmony_cithe above taskfile/DMA engine hooks. ``->qc_prep`` is called after the 2598c2ecf20Sopenharmony_cibuffers have been DMA-mapped, and is typically used to populate the 2608c2ecf20Sopenharmony_cihardware's DMA scatter-gather table. Some drivers use the standard 2618c2ecf20Sopenharmony_ci:c:func:`ata_bmdma_qc_prep` and :c:func:`ata_bmdma_dumb_qc_prep` helper 2628c2ecf20Sopenharmony_cifunctions, but more advanced drivers roll their own. 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci``->qc_issue`` is used to make a command active, once the hardware and S/G 2658c2ecf20Sopenharmony_citables have been prepared. IDE BMDMA drivers use the helper function 2668c2ecf20Sopenharmony_ci:c:func:`ata_sff_qc_issue` for taskfile protocol-based dispatch. More 2678c2ecf20Sopenharmony_ciadvanced drivers implement their own ``->qc_issue``. 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci:c:func:`ata_sff_qc_issue` calls ``->sff_tf_load()``, ``->bmdma_setup()``, and 2708c2ecf20Sopenharmony_ci``->bmdma_start()`` as necessary to initiate a transfer. 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ciException and probe handling (EH) 2738c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2748c2ecf20Sopenharmony_ci 2758c2ecf20Sopenharmony_ci:: 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci void (*eng_timeout) (struct ata_port *ap); 2788c2ecf20Sopenharmony_ci void (*phy_reset) (struct ata_port *ap); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ciDeprecated. Use ``->error_handler()`` instead. 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_ci:: 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci void (*freeze) (struct ata_port *ap); 2868c2ecf20Sopenharmony_ci void (*thaw) (struct ata_port *ap); 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci:c:func:`ata_port_freeze` is called when HSM violations or some other 2908c2ecf20Sopenharmony_cicondition disrupts normal operation of the port. A frozen port is not 2918c2ecf20Sopenharmony_ciallowed to perform any operation until the port is thawed, which usually 2928c2ecf20Sopenharmony_cifollows a successful reset. 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ciThe optional ``->freeze()`` callback can be used for freezing the port 2958c2ecf20Sopenharmony_cihardware-wise (e.g. mask interrupt and stop DMA engine). If a port 2968c2ecf20Sopenharmony_cicannot be frozen hardware-wise, the interrupt handler must ack and clear 2978c2ecf20Sopenharmony_ciinterrupts unconditionally while the port is frozen. 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ciThe optional ``->thaw()`` callback is called to perform the opposite of 3008c2ecf20Sopenharmony_ci``->freeze()``: prepare the port for normal operation once again. Unmask 3018c2ecf20Sopenharmony_ciinterrupts, start DMA engine, etc. 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci:: 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci void (*error_handler) (struct ata_port *ap); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ci``->error_handler()`` is a driver's hook into probe, hotplug, and recovery 3098c2ecf20Sopenharmony_ciand other exceptional conditions. The primary responsibility of an 3108c2ecf20Sopenharmony_ciimplementation is to call :c:func:`ata_do_eh` or :c:func:`ata_bmdma_drive_eh` 3118c2ecf20Sopenharmony_ciwith a set of EH hooks as arguments: 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci'prereset' hook (may be NULL) is called during an EH reset, before any 3148c2ecf20Sopenharmony_ciother actions are taken. 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci'postreset' hook (may be NULL) is called after the EH reset is 3178c2ecf20Sopenharmony_ciperformed. Based on existing conditions, severity of the problem, and 3188c2ecf20Sopenharmony_cihardware capabilities, 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ciEither 'softreset' (may be NULL) or 'hardreset' (may be NULL) will be 3218c2ecf20Sopenharmony_cicalled to perform the low-level EH reset. 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci:: 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci void (*post_internal_cmd) (struct ata_queued_cmd *qc); 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ciPerform any hardware-specific actions necessary to finish processing 3298c2ecf20Sopenharmony_ciafter executing a probe-time or EH-time command via 3308c2ecf20Sopenharmony_ci:c:func:`ata_exec_internal`. 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ciHardware interrupt handling 3338c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci:: 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci irqreturn_t (*irq_handler)(int, void *, struct pt_regs *); 3388c2ecf20Sopenharmony_ci void (*irq_clear) (struct ata_port *); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci``->irq_handler`` is the interrupt handling routine registered with the 3428c2ecf20Sopenharmony_cisystem, by libata. ``->irq_clear`` is called during probe just before the 3438c2ecf20Sopenharmony_ciinterrupt handler is registered, to be sure hardware is quiet. 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ciThe second argument, dev_instance, should be cast to a pointer to 3468c2ecf20Sopenharmony_ci:c:type:`struct ata_host_set <ata_host_set>`. 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ciMost legacy IDE drivers use :c:func:`ata_sff_interrupt` for the irq_handler 3498c2ecf20Sopenharmony_cihook, which scans all ports in the host_set, determines which queued 3508c2ecf20Sopenharmony_cicommand was active (if any), and calls ata_sff_host_intr(ap,qc). 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ciMost legacy IDE drivers use :c:func:`ata_sff_irq_clear` for the 3538c2ecf20Sopenharmony_ci:c:func:`irq_clear` hook, which simply clears the interrupt and error flags 3548c2ecf20Sopenharmony_ciin the DMA status register. 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ciSATA phy read/write 3578c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~ 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci:: 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci int (*scr_read) (struct ata_port *ap, unsigned int sc_reg, 3628c2ecf20Sopenharmony_ci u32 *val); 3638c2ecf20Sopenharmony_ci int (*scr_write) (struct ata_port *ap, unsigned int sc_reg, 3648c2ecf20Sopenharmony_ci u32 val); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ciRead and write standard SATA phy registers. Currently only used if 3688c2ecf20Sopenharmony_ci``->phy_reset`` hook called the :c:func:`sata_phy_reset` helper function. 3698c2ecf20Sopenharmony_cisc_reg is one of SCR_STATUS, SCR_CONTROL, SCR_ERROR, or SCR_ACTIVE. 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ciInit and shutdown 3728c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~ 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci:: 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci int (*port_start) (struct ata_port *ap); 3778c2ecf20Sopenharmony_ci void (*port_stop) (struct ata_port *ap); 3788c2ecf20Sopenharmony_ci void (*host_stop) (struct ata_host_set *host_set); 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci``->port_start()`` is called just after the data structures for each port 3828c2ecf20Sopenharmony_ciare initialized. Typically this is used to alloc per-port DMA buffers / 3838c2ecf20Sopenharmony_citables / rings, enable DMA engines, and similar tasks. Some drivers also 3848c2ecf20Sopenharmony_ciuse this entry point as a chance to allocate driver-private memory for 3858c2ecf20Sopenharmony_ci``ap->private_data``. 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ciMany drivers use :c:func:`ata_port_start` as this hook or call it from their 3888c2ecf20Sopenharmony_ciown :c:func:`port_start` hooks. :c:func:`ata_port_start` allocates space for 3898c2ecf20Sopenharmony_cia legacy IDE PRD table and returns. 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci``->port_stop()`` is called after ``->host_stop()``. Its sole function is to 3928c2ecf20Sopenharmony_cirelease DMA/memory resources, now that they are no longer actively being 3938c2ecf20Sopenharmony_ciused. Many drivers also free driver-private data from port at this time. 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci``->host_stop()`` is called after all ``->port_stop()`` calls have completed. 3968c2ecf20Sopenharmony_ciThe hook must finalize hardware shutdown, release DMA and other 3978c2ecf20Sopenharmony_ciresources, etc. This hook may be specified as NULL, in which case it is 3988c2ecf20Sopenharmony_cinot called. 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ciError handling 4018c2ecf20Sopenharmony_ci============== 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ciThis chapter describes how errors are handled under libata. Readers are 4048c2ecf20Sopenharmony_ciadvised to read SCSI EH (Documentation/scsi/scsi_eh.rst) and ATA 4058c2ecf20Sopenharmony_ciexceptions doc first. 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ciOrigins of commands 4088c2ecf20Sopenharmony_ci------------------- 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ciIn libata, a command is represented with 4118c2ecf20Sopenharmony_ci:c:type:`struct ata_queued_cmd <ata_queued_cmd>` or qc. 4128c2ecf20Sopenharmony_ciqc's are preallocated during port initialization and repetitively used 4138c2ecf20Sopenharmony_cifor command executions. Currently only one qc is allocated per port but 4148c2ecf20Sopenharmony_ciyet-to-be-merged NCQ branch allocates one for each tag and maps each qc 4158c2ecf20Sopenharmony_cito NCQ tag 1-to-1. 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cilibata commands can originate from two sources - libata itself and SCSI 4188c2ecf20Sopenharmony_cimidlayer. libata internal commands are used for initialization and error 4198c2ecf20Sopenharmony_cihandling. All normal blk requests and commands for SCSI emulation are 4208c2ecf20Sopenharmony_cipassed as SCSI commands through queuecommand callback of SCSI host 4218c2ecf20Sopenharmony_citemplate. 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ciHow commands are issued 4248c2ecf20Sopenharmony_ci----------------------- 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ciInternal commands 4278c2ecf20Sopenharmony_ci First, qc is allocated and initialized using :c:func:`ata_qc_new_init`. 4288c2ecf20Sopenharmony_ci Although :c:func:`ata_qc_new_init` doesn't implement any wait or retry 4298c2ecf20Sopenharmony_ci mechanism when qc is not available, internal commands are currently 4308c2ecf20Sopenharmony_ci issued only during initialization and error recovery, so no other 4318c2ecf20Sopenharmony_ci command is active and allocation is guaranteed to succeed. 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci Once allocated qc's taskfile is initialized for the command to be 4348c2ecf20Sopenharmony_ci executed. qc currently has two mechanisms to notify completion. One 4358c2ecf20Sopenharmony_ci is via ``qc->complete_fn()`` callback and the other is completion 4368c2ecf20Sopenharmony_ci ``qc->waiting``. ``qc->complete_fn()`` callback is the asynchronous path 4378c2ecf20Sopenharmony_ci used by normal SCSI translated commands and ``qc->waiting`` is the 4388c2ecf20Sopenharmony_ci synchronous (issuer sleeps in process context) path used by internal 4398c2ecf20Sopenharmony_ci commands. 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci Once initialization is complete, host_set lock is acquired and the 4428c2ecf20Sopenharmony_ci qc is issued. 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ciSCSI commands 4458c2ecf20Sopenharmony_ci All libata drivers use :c:func:`ata_scsi_queuecmd` as 4468c2ecf20Sopenharmony_ci ``hostt->queuecommand`` callback. scmds can either be simulated or 4478c2ecf20Sopenharmony_ci translated. No qc is involved in processing a simulated scmd. The 4488c2ecf20Sopenharmony_ci result is computed right away and the scmd is completed. 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci For a translated scmd, :c:func:`ata_qc_new_init` is invoked to allocate a 4518c2ecf20Sopenharmony_ci qc and the scmd is translated into the qc. SCSI midlayer's 4528c2ecf20Sopenharmony_ci completion notification function pointer is stored into 4538c2ecf20Sopenharmony_ci ``qc->scsidone``. 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci ``qc->complete_fn()`` callback is used for completion notification. ATA 4568c2ecf20Sopenharmony_ci commands use :c:func:`ata_scsi_qc_complete` while ATAPI commands use 4578c2ecf20Sopenharmony_ci :c:func:`atapi_qc_complete`. Both functions end up calling ``qc->scsidone`` 4588c2ecf20Sopenharmony_ci to notify upper layer when the qc is finished. After translation is 4598c2ecf20Sopenharmony_ci completed, the qc is issued with :c:func:`ata_qc_issue`. 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci Note that SCSI midlayer invokes hostt->queuecommand while holding 4628c2ecf20Sopenharmony_ci host_set lock, so all above occur while holding host_set lock. 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ciHow commands are processed 4658c2ecf20Sopenharmony_ci-------------------------- 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ciDepending on which protocol and which controller are used, commands are 4688c2ecf20Sopenharmony_ciprocessed differently. For the purpose of discussion, a controller which 4698c2ecf20Sopenharmony_ciuses taskfile interface and all standard callbacks is assumed. 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ciCurrently 6 ATA command protocols are used. They can be sorted into the 4728c2ecf20Sopenharmony_cifollowing four categories according to how they are processed. 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ciATA NO DATA or DMA 4758c2ecf20Sopenharmony_ci ATA_PROT_NODATA and ATA_PROT_DMA fall into this category. These 4768c2ecf20Sopenharmony_ci types of commands don't require any software intervention once 4778c2ecf20Sopenharmony_ci issued. Device will raise interrupt on completion. 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ciATA PIO 4808c2ecf20Sopenharmony_ci ATA_PROT_PIO is in this category. libata currently implements PIO 4818c2ecf20Sopenharmony_ci with polling. ATA_NIEN bit is set to turn off interrupt and 4828c2ecf20Sopenharmony_ci pio_task on ata_wq performs polling and IO. 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ciATAPI NODATA or DMA 4858c2ecf20Sopenharmony_ci ATA_PROT_ATAPI_NODATA and ATA_PROT_ATAPI_DMA are in this 4868c2ecf20Sopenharmony_ci category. packet_task is used to poll BSY bit after issuing PACKET 4878c2ecf20Sopenharmony_ci command. Once BSY is turned off by the device, packet_task 4888c2ecf20Sopenharmony_ci transfers CDB and hands off processing to interrupt handler. 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ciATAPI PIO 4918c2ecf20Sopenharmony_ci ATA_PROT_ATAPI is in this category. ATA_NIEN bit is set and, as 4928c2ecf20Sopenharmony_ci in ATAPI NODATA or DMA, packet_task submits cdb. However, after 4938c2ecf20Sopenharmony_ci submitting cdb, further processing (data transfer) is handed off to 4948c2ecf20Sopenharmony_ci pio_task. 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ciHow commands are completed 4978c2ecf20Sopenharmony_ci-------------------------- 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ciOnce issued, all qc's are either completed with :c:func:`ata_qc_complete` or 5008c2ecf20Sopenharmony_citime out. For commands which are handled by interrupts, 5018c2ecf20Sopenharmony_ci:c:func:`ata_host_intr` invokes :c:func:`ata_qc_complete`, and, for PIO tasks, 5028c2ecf20Sopenharmony_cipio_task invokes :c:func:`ata_qc_complete`. In error cases, packet_task may 5038c2ecf20Sopenharmony_cialso complete commands. 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci:c:func:`ata_qc_complete` does the following. 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci1. DMA memory is unmapped. 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci2. ATA_QCFLAG_ACTIVE is cleared from qc->flags. 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci3. :c:expr:`qc->complete_fn` callback is invoked. If the return value of the 5128c2ecf20Sopenharmony_ci callback is not zero. Completion is short circuited and 5138c2ecf20Sopenharmony_ci :c:func:`ata_qc_complete` returns. 5148c2ecf20Sopenharmony_ci 5158c2ecf20Sopenharmony_ci4. :c:func:`__ata_qc_complete` is called, which does 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci 1. ``qc->flags`` is cleared to zero. 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci 2. ``ap->active_tag`` and ``qc->tag`` are poisoned. 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ci 3. ``qc->waiting`` is cleared & completed (in that order). 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci 4. qc is deallocated by clearing appropriate bit in ``ap->qactive``. 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ciSo, it basically notifies upper layer and deallocates qc. One exception 5268c2ecf20Sopenharmony_ciis short-circuit path in #3 which is used by :c:func:`atapi_qc_complete`. 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ciFor all non-ATAPI commands, whether it fails or not, almost the same 5298c2ecf20Sopenharmony_cicode path is taken and very little error handling takes place. A qc is 5308c2ecf20Sopenharmony_cicompleted with success status if it succeeded, with failed status 5318c2ecf20Sopenharmony_ciotherwise. 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ciHowever, failed ATAPI commands require more handling as REQUEST SENSE is 5348c2ecf20Sopenharmony_cineeded to acquire sense data. If an ATAPI command fails, 5358c2ecf20Sopenharmony_ci:c:func:`ata_qc_complete` is invoked with error status, which in turn invokes 5368c2ecf20Sopenharmony_ci:c:func:`atapi_qc_complete` via ``qc->complete_fn()`` callback. 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ciThis makes :c:func:`atapi_qc_complete` set ``scmd->result`` to 5398c2ecf20Sopenharmony_ciSAM_STAT_CHECK_CONDITION, complete the scmd and return 1. As the 5408c2ecf20Sopenharmony_cisense data is empty but ``scmd->result`` is CHECK CONDITION, SCSI midlayer 5418c2ecf20Sopenharmony_ciwill invoke EH for the scmd, and returning 1 makes :c:func:`ata_qc_complete` 5428c2ecf20Sopenharmony_cito return without deallocating the qc. This leads us to 5438c2ecf20Sopenharmony_ci:c:func:`ata_scsi_error` with partially completed qc. 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci:c:func:`ata_scsi_error` 5468c2ecf20Sopenharmony_ci------------------------ 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci:c:func:`ata_scsi_error` is the current ``transportt->eh_strategy_handler()`` 5498c2ecf20Sopenharmony_cifor libata. As discussed above, this will be entered in two cases - 5508c2ecf20Sopenharmony_citimeout and ATAPI error completion. This function calls low level libata 5518c2ecf20Sopenharmony_cidriver's :c:func:`eng_timeout` callback, the standard callback for which is 5528c2ecf20Sopenharmony_ci:c:func:`ata_eng_timeout`. It checks if a qc is active and calls 5538c2ecf20Sopenharmony_ci:c:func:`ata_qc_timeout` on the qc if so. Actual error handling occurs in 5548c2ecf20Sopenharmony_ci:c:func:`ata_qc_timeout`. 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ciIf EH is invoked for timeout, :c:func:`ata_qc_timeout` stops BMDMA and 5578c2ecf20Sopenharmony_cicompletes the qc. Note that as we're currently in EH, we cannot call 5588c2ecf20Sopenharmony_ciscsi_done. As described in SCSI EH doc, a recovered scmd should be 5598c2ecf20Sopenharmony_cieither retried with :c:func:`scsi_queue_insert` or finished with 5608c2ecf20Sopenharmony_ci:c:func:`scsi_finish_command`. Here, we override ``qc->scsidone`` with 5618c2ecf20Sopenharmony_ci:c:func:`scsi_finish_command` and calls :c:func:`ata_qc_complete`. 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ciIf EH is invoked due to a failed ATAPI qc, the qc here is completed but 5648c2ecf20Sopenharmony_cinot deallocated. The purpose of this half-completion is to use the qc as 5658c2ecf20Sopenharmony_ciplace holder to make EH code reach this place. This is a bit hackish, 5668c2ecf20Sopenharmony_cibut it works. 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ciOnce control reaches here, the qc is deallocated by invoking 5698c2ecf20Sopenharmony_ci:c:func:`__ata_qc_complete` explicitly. Then, internal qc for REQUEST SENSE 5708c2ecf20Sopenharmony_ciis issued. Once sense data is acquired, scmd is finished by directly 5718c2ecf20Sopenharmony_ciinvoking :c:func:`scsi_finish_command` on the scmd. Note that as we already 5728c2ecf20Sopenharmony_cihave completed and deallocated the qc which was associated with the 5738c2ecf20Sopenharmony_ciscmd, we don't need to/cannot call :c:func:`ata_qc_complete` again. 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ciProblems with the current EH 5768c2ecf20Sopenharmony_ci---------------------------- 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci- Error representation is too crude. Currently any and all error 5798c2ecf20Sopenharmony_ci conditions are represented with ATA STATUS and ERROR registers. 5808c2ecf20Sopenharmony_ci Errors which aren't ATA device errors are treated as ATA device 5818c2ecf20Sopenharmony_ci errors by setting ATA_ERR bit. Better error descriptor which can 5828c2ecf20Sopenharmony_ci properly represent ATA and other errors/exceptions is needed. 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci- When handling timeouts, no action is taken to make device forget 5858c2ecf20Sopenharmony_ci about the timed out command and ready for new commands. 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci- EH handling via :c:func:`ata_scsi_error` is not properly protected from 5888c2ecf20Sopenharmony_ci usual command processing. On EH entrance, the device is not in 5898c2ecf20Sopenharmony_ci quiescent state. Timed out commands may succeed or fail any time. 5908c2ecf20Sopenharmony_ci pio_task and atapi_task may still be running. 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci- Too weak error recovery. Devices / controllers causing HSM mismatch 5938c2ecf20Sopenharmony_ci errors and other errors quite often require reset to return to known 5948c2ecf20Sopenharmony_ci state. Also, advanced error handling is necessary to support features 5958c2ecf20Sopenharmony_ci like NCQ and hotplug. 5968c2ecf20Sopenharmony_ci 5978c2ecf20Sopenharmony_ci- ATA errors are directly handled in the interrupt handler and PIO 5988c2ecf20Sopenharmony_ci errors in pio_task. This is problematic for advanced error handling 5998c2ecf20Sopenharmony_ci for the following reasons. 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci First, advanced error handling often requires context and internal qc 6028c2ecf20Sopenharmony_ci execution. 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci Second, even a simple failure (say, CRC error) needs information 6058c2ecf20Sopenharmony_ci gathering and could trigger complex error handling (say, resetting & 6068c2ecf20Sopenharmony_ci reconfiguring). Having multiple code paths to gather information, 6078c2ecf20Sopenharmony_ci enter EH and trigger actions makes life painful. 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_ci Third, scattered EH code makes implementing low level drivers 6108c2ecf20Sopenharmony_ci difficult. Low level drivers override libata callbacks. If EH is 6118c2ecf20Sopenharmony_ci scattered over several places, each affected callbacks should perform 6128c2ecf20Sopenharmony_ci its part of error handling. This can be error prone and painful. 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_cilibata Library 6158c2ecf20Sopenharmony_ci============== 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/libata-core.c 6188c2ecf20Sopenharmony_ci :export: 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_cilibata Core Internals 6218c2ecf20Sopenharmony_ci===================== 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/libata-core.c 6248c2ecf20Sopenharmony_ci :internal: 6258c2ecf20Sopenharmony_ci 6268c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/libata-eh.c 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_cilibata SCSI translation/emulation 6298c2ecf20Sopenharmony_ci================================= 6308c2ecf20Sopenharmony_ci 6318c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/libata-scsi.c 6328c2ecf20Sopenharmony_ci :export: 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/libata-scsi.c 6358c2ecf20Sopenharmony_ci :internal: 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ciATA errors and exceptions 6388c2ecf20Sopenharmony_ci========================= 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ciThis chapter tries to identify what error/exception conditions exist for 6418c2ecf20Sopenharmony_ciATA/ATAPI devices and describe how they should be handled in 6428c2ecf20Sopenharmony_ciimplementation-neutral way. 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ciThe term 'error' is used to describe conditions where either an explicit 6458c2ecf20Sopenharmony_cierror condition is reported from device or a command has timed out. 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ciThe term 'exception' is either used to describe exceptional conditions 6488c2ecf20Sopenharmony_ciwhich are not errors (say, power or hotplug events), or to describe both 6498c2ecf20Sopenharmony_cierrors and non-error exceptional conditions. Where explicit distinction 6508c2ecf20Sopenharmony_cibetween error and exception is necessary, the term 'non-error exception' 6518c2ecf20Sopenharmony_ciis used. 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ciException categories 6548c2ecf20Sopenharmony_ci-------------------- 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ciExceptions are described primarily with respect to legacy taskfile + bus 6578c2ecf20Sopenharmony_cimaster IDE interface. If a controller provides other better mechanism 6588c2ecf20Sopenharmony_cifor error reporting, mapping those into categories described below 6598c2ecf20Sopenharmony_cishouldn't be difficult. 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ciIn the following sections, two recovery actions - reset and 6628c2ecf20Sopenharmony_cireconfiguring transport - are mentioned. These are described further in 6638c2ecf20Sopenharmony_ci`EH recovery actions <#exrec>`__. 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ciHSM violation 6668c2ecf20Sopenharmony_ci~~~~~~~~~~~~~ 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ciThis error is indicated when STATUS value doesn't match HSM requirement 6698c2ecf20Sopenharmony_ciduring issuing or execution any ATA/ATAPI command. 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci- ATA_STATUS doesn't contain !BSY && DRDY && !DRQ while trying to 6728c2ecf20Sopenharmony_ci issue a command. 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci- !BSY && !DRQ during PIO data transfer. 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci- DRQ on command completion. 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci- !BSY && ERR after CDB transfer starts but before the last byte of CDB 6798c2ecf20Sopenharmony_ci is transferred. ATA/ATAPI standard states that "The device shall not 6808c2ecf20Sopenharmony_ci terminate the PACKET command with an error before the last byte of 6818c2ecf20Sopenharmony_ci the command packet has been written" in the error outputs description 6828c2ecf20Sopenharmony_ci of PACKET command and the state diagram doesn't include such 6838c2ecf20Sopenharmony_ci transitions. 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_ciIn these cases, HSM is violated and not much information regarding the 6868c2ecf20Sopenharmony_cierror can be acquired from STATUS or ERROR register. IOW, this error can 6878c2ecf20Sopenharmony_cibe anything - driver bug, faulty device, controller and/or cable. 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ciAs HSM is violated, reset is necessary to restore known state. 6908c2ecf20Sopenharmony_ciReconfiguring transport for lower speed might be helpful too as 6918c2ecf20Sopenharmony_citransmission errors sometimes cause this kind of errors. 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ciATA/ATAPI device error (non-NCQ / non-CHECK CONDITION) 6948c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ciThese are errors detected and reported by ATA/ATAPI devices indicating 6978c2ecf20Sopenharmony_cidevice problems. For this type of errors, STATUS and ERROR register 6988c2ecf20Sopenharmony_civalues are valid and describe error condition. Note that some of ATA bus 6998c2ecf20Sopenharmony_cierrors are detected by ATA/ATAPI devices and reported using the same 7008c2ecf20Sopenharmony_cimechanism as device errors. Those cases are described later in this 7018c2ecf20Sopenharmony_cisection. 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ciFor ATA commands, this type of errors are indicated by !BSY && ERR 7048c2ecf20Sopenharmony_ciduring command execution and on completion. 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ciFor ATAPI commands, 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci- !BSY && ERR && ABRT right after issuing PACKET indicates that PACKET 7098c2ecf20Sopenharmony_ci command is not supported and falls in this category. 7108c2ecf20Sopenharmony_ci 7118c2ecf20Sopenharmony_ci- !BSY && ERR(==CHK) && !ABRT after the last byte of CDB is transferred 7128c2ecf20Sopenharmony_ci indicates CHECK CONDITION and doesn't fall in this category. 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci- !BSY && ERR(==CHK) && ABRT after the last byte of CDB is transferred 7158c2ecf20Sopenharmony_ci \*probably\* indicates CHECK CONDITION and doesn't fall in this 7168c2ecf20Sopenharmony_ci category. 7178c2ecf20Sopenharmony_ci 7188c2ecf20Sopenharmony_ciOf errors detected as above, the following are not ATA/ATAPI device 7198c2ecf20Sopenharmony_cierrors but ATA bus errors and should be handled according to 7208c2ecf20Sopenharmony_ci`ATA bus error <#excatATAbusErr>`__. 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ciCRC error during data transfer 7238c2ecf20Sopenharmony_ci This is indicated by ICRC bit in the ERROR register and means that 7248c2ecf20Sopenharmony_ci corruption occurred during data transfer. Up to ATA/ATAPI-7, the 7258c2ecf20Sopenharmony_ci standard specifies that this bit is only applicable to UDMA 7268c2ecf20Sopenharmony_ci transfers but ATA/ATAPI-8 draft revision 1f says that the bit may be 7278c2ecf20Sopenharmony_ci applicable to multiword DMA and PIO. 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ciABRT error during data transfer or on completion 7308c2ecf20Sopenharmony_ci Up to ATA/ATAPI-7, the standard specifies that ABRT could be set on 7318c2ecf20Sopenharmony_ci ICRC errors and on cases where a device is not able to complete a 7328c2ecf20Sopenharmony_ci command. Combined with the fact that MWDMA and PIO transfer errors 7338c2ecf20Sopenharmony_ci aren't allowed to use ICRC bit up to ATA/ATAPI-7, it seems to imply 7348c2ecf20Sopenharmony_ci that ABRT bit alone could indicate transfer errors. 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci However, ATA/ATAPI-8 draft revision 1f removes the part that ICRC 7378c2ecf20Sopenharmony_ci errors can turn on ABRT. So, this is kind of gray area. Some 7388c2ecf20Sopenharmony_ci heuristics are needed here. 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ciATA/ATAPI device errors can be further categorized as follows. 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ciMedia errors 7438c2ecf20Sopenharmony_ci This is indicated by UNC bit in the ERROR register. ATA devices 7448c2ecf20Sopenharmony_ci reports UNC error only after certain number of retries cannot 7458c2ecf20Sopenharmony_ci recover the data, so there's nothing much else to do other than 7468c2ecf20Sopenharmony_ci notifying upper layer. 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci READ and WRITE commands report CHS or LBA of the first failed sector 7498c2ecf20Sopenharmony_ci but ATA/ATAPI standard specifies that the amount of transferred data 7508c2ecf20Sopenharmony_ci on error completion is indeterminate, so we cannot assume that 7518c2ecf20Sopenharmony_ci sectors preceding the failed sector have been transferred and thus 7528c2ecf20Sopenharmony_ci cannot complete those sectors successfully as SCSI does. 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ciMedia changed / media change requested error 7558c2ecf20Sopenharmony_ci <<TODO: fill here>> 7568c2ecf20Sopenharmony_ci 7578c2ecf20Sopenharmony_ciAddress error 7588c2ecf20Sopenharmony_ci This is indicated by IDNF bit in the ERROR register. Report to upper 7598c2ecf20Sopenharmony_ci layer. 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ciOther errors 7628c2ecf20Sopenharmony_ci This can be invalid command or parameter indicated by ABRT ERROR bit 7638c2ecf20Sopenharmony_ci or some other error condition. Note that ABRT bit can indicate a lot 7648c2ecf20Sopenharmony_ci of things including ICRC and Address errors. Heuristics needed. 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ciDepending on commands, not all STATUS/ERROR bits are applicable. These 7678c2ecf20Sopenharmony_cinon-applicable bits are marked with "na" in the output descriptions but 7688c2ecf20Sopenharmony_ciup to ATA/ATAPI-7 no definition of "na" can be found. However, 7698c2ecf20Sopenharmony_ciATA/ATAPI-8 draft revision 1f describes "N/A" as follows. 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci 3.2.3.3a N/A 7728c2ecf20Sopenharmony_ci A keyword the indicates a field has no defined value in this 7738c2ecf20Sopenharmony_ci standard and should not be checked by the host or device. N/A 7748c2ecf20Sopenharmony_ci fields should be cleared to zero. 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ciSo, it seems reasonable to assume that "na" bits are cleared to zero by 7778c2ecf20Sopenharmony_cidevices and thus need no explicit masking. 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ciATAPI device CHECK CONDITION 7808c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7818c2ecf20Sopenharmony_ci 7828c2ecf20Sopenharmony_ciATAPI device CHECK CONDITION error is indicated by set CHK bit (ERR bit) 7838c2ecf20Sopenharmony_ciin the STATUS register after the last byte of CDB is transferred for a 7848c2ecf20Sopenharmony_ciPACKET command. For this kind of errors, sense data should be acquired 7858c2ecf20Sopenharmony_cito gather information regarding the errors. REQUEST SENSE packet command 7868c2ecf20Sopenharmony_cishould be used to acquire sense data. 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ciOnce sense data is acquired, this type of errors can be handled 7898c2ecf20Sopenharmony_cisimilarly to other SCSI errors. Note that sense data may indicate ATA 7908c2ecf20Sopenharmony_cibus error (e.g. Sense Key 04h HARDWARE ERROR && ASC/ASCQ 47h/00h SCSI 7918c2ecf20Sopenharmony_ciPARITY ERROR). In such cases, the error should be considered as an ATA 7928c2ecf20Sopenharmony_cibus error and handled according to `ATA bus error <#excatATAbusErr>`__. 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ciATA device error (NCQ) 7958c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~ 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ciNCQ command error is indicated by cleared BSY and set ERR bit during NCQ 7988c2ecf20Sopenharmony_cicommand phase (one or more NCQ commands outstanding). Although STATUS 7998c2ecf20Sopenharmony_ciand ERROR registers will contain valid values describing the error, READ 8008c2ecf20Sopenharmony_ciLOG EXT is required to clear the error condition, determine which 8018c2ecf20Sopenharmony_cicommand has failed and acquire more information. 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ciREAD LOG EXT Log Page 10h reports which tag has failed and taskfile 8048c2ecf20Sopenharmony_ciregister values describing the error. With this information the failed 8058c2ecf20Sopenharmony_cicommand can be handled as a normal ATA command error as in 8068c2ecf20Sopenharmony_ci`ATA/ATAPI device error (non-NCQ / non-CHECK CONDITION) <#excatDevErr>`__ 8078c2ecf20Sopenharmony_ciand all other in-flight commands must be retried. Note that this retry 8088c2ecf20Sopenharmony_cishould not be counted - it's likely that commands retried this way would 8098c2ecf20Sopenharmony_cihave completed normally if it were not for the failed command. 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ciNote that ATA bus errors can be reported as ATA device NCQ errors. This 8128c2ecf20Sopenharmony_cishould be handled as described in `ATA bus error <#excatATAbusErr>`__. 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ciIf READ LOG EXT Log Page 10h fails or reports NQ, we're thoroughly 8158c2ecf20Sopenharmony_ciscrewed. This condition should be treated according to 8168c2ecf20Sopenharmony_ci`HSM violation <#excatHSMviolation>`__. 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ciATA bus error 8198c2ecf20Sopenharmony_ci~~~~~~~~~~~~~ 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ciATA bus error means that data corruption occurred during transmission 8228c2ecf20Sopenharmony_ciover ATA bus (SATA or PATA). This type of errors can be indicated by 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci- ICRC or ABRT error as described in 8258c2ecf20Sopenharmony_ci `ATA/ATAPI device error (non-NCQ / non-CHECK CONDITION) <#excatDevErr>`__. 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci- Controller-specific error completion with error information 8288c2ecf20Sopenharmony_ci indicating transmission error. 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci- On some controllers, command timeout. In this case, there may be a 8318c2ecf20Sopenharmony_ci mechanism to determine that the timeout is due to transmission error. 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci- Unknown/random errors, timeouts and all sorts of weirdities. 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ciAs described above, transmission errors can cause wide variety of 8368c2ecf20Sopenharmony_cisymptoms ranging from device ICRC error to random device lockup, and, 8378c2ecf20Sopenharmony_cifor many cases, there is no way to tell if an error condition is due to 8388c2ecf20Sopenharmony_citransmission error or not; therefore, it's necessary to employ some kind 8398c2ecf20Sopenharmony_ciof heuristic when dealing with errors and timeouts. For example, 8408c2ecf20Sopenharmony_ciencountering repetitive ABRT errors for known supported command is 8418c2ecf20Sopenharmony_cilikely to indicate ATA bus error. 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ciOnce it's determined that ATA bus errors have possibly occurred, 8448c2ecf20Sopenharmony_cilowering ATA bus transmission speed is one of actions which may 8458c2ecf20Sopenharmony_cialleviate the problem. See `Reconfigure transport <#exrecReconf>`__ for 8468c2ecf20Sopenharmony_cimore information. 8478c2ecf20Sopenharmony_ci 8488c2ecf20Sopenharmony_ciPCI bus error 8498c2ecf20Sopenharmony_ci~~~~~~~~~~~~~ 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ciData corruption or other failures during transmission over PCI (or other 8528c2ecf20Sopenharmony_cisystem bus). For standard BMDMA, this is indicated by Error bit in the 8538c2ecf20Sopenharmony_ciBMDMA Status register. This type of errors must be logged as it 8548c2ecf20Sopenharmony_ciindicates something is very wrong with the system. Resetting host 8558c2ecf20Sopenharmony_cicontroller is recommended. 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ciLate completion 8588c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~ 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ciThis occurs when timeout occurs and the timeout handler finds out that 8618c2ecf20Sopenharmony_cithe timed out command has completed successfully or with error. This is 8628c2ecf20Sopenharmony_ciusually caused by lost interrupts. This type of errors must be logged. 8638c2ecf20Sopenharmony_ciResetting host controller is recommended. 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ciUnknown error (timeout) 8668c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~ 8678c2ecf20Sopenharmony_ci 8688c2ecf20Sopenharmony_ciThis is when timeout occurs and the command is still processing or the 8698c2ecf20Sopenharmony_cihost and device are in unknown state. When this occurs, HSM could be in 8708c2ecf20Sopenharmony_ciany valid or invalid state. To bring the device to known state and make 8718c2ecf20Sopenharmony_ciit forget about the timed out command, resetting is necessary. The timed 8728c2ecf20Sopenharmony_ciout command may be retried. 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ciTimeouts can also be caused by transmission errors. Refer to 8758c2ecf20Sopenharmony_ci`ATA bus error <#excatATAbusErr>`__ for more details. 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ciHotplug and power management exceptions 8788c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8798c2ecf20Sopenharmony_ci 8808c2ecf20Sopenharmony_ci<<TODO: fill here>> 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ciEH recovery actions 8838c2ecf20Sopenharmony_ci------------------- 8848c2ecf20Sopenharmony_ci 8858c2ecf20Sopenharmony_ciThis section discusses several important recovery actions. 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ciClearing error condition 8888c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~~~~ 8898c2ecf20Sopenharmony_ci 8908c2ecf20Sopenharmony_ciMany controllers require its error registers to be cleared by error 8918c2ecf20Sopenharmony_cihandler. Different controllers may have different requirements. 8928c2ecf20Sopenharmony_ci 8938c2ecf20Sopenharmony_ciFor SATA, it's strongly recommended to clear at least SError register 8948c2ecf20Sopenharmony_ciduring error handling. 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ciReset 8978c2ecf20Sopenharmony_ci~~~~~ 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ciDuring EH, resetting is necessary in the following cases. 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci- HSM is in unknown or invalid state 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci- HBA is in unknown or invalid state 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci- EH needs to make HBA/device forget about in-flight commands 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci- HBA/device behaves weirdly 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ciResetting during EH might be a good idea regardless of error condition 9108c2ecf20Sopenharmony_cito improve EH robustness. Whether to reset both or either one of HBA and 9118c2ecf20Sopenharmony_cidevice depends on situation but the following scheme is recommended. 9128c2ecf20Sopenharmony_ci 9138c2ecf20Sopenharmony_ci- When it's known that HBA is in ready state but ATA/ATAPI device is in 9148c2ecf20Sopenharmony_ci unknown state, reset only device. 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci- If HBA is in unknown state, reset both HBA and device. 9178c2ecf20Sopenharmony_ci 9188c2ecf20Sopenharmony_ciHBA resetting is implementation specific. For a controller complying to 9198c2ecf20Sopenharmony_citaskfile/BMDMA PCI IDE, stopping active DMA transaction may be 9208c2ecf20Sopenharmony_cisufficient iff BMDMA state is the only HBA context. But even mostly 9218c2ecf20Sopenharmony_citaskfile/BMDMA PCI IDE complying controllers may have implementation 9228c2ecf20Sopenharmony_cispecific requirements and mechanism to reset themselves. This must be 9238c2ecf20Sopenharmony_ciaddressed by specific drivers. 9248c2ecf20Sopenharmony_ci 9258c2ecf20Sopenharmony_ciOTOH, ATA/ATAPI standard describes in detail ways to reset ATA/ATAPI 9268c2ecf20Sopenharmony_cidevices. 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ciPATA hardware reset 9298c2ecf20Sopenharmony_ci This is hardware initiated device reset signalled with asserted PATA 9308c2ecf20Sopenharmony_ci RESET- signal. There is no standard way to initiate hardware reset 9318c2ecf20Sopenharmony_ci from software although some hardware provides registers that allow 9328c2ecf20Sopenharmony_ci driver to directly tweak the RESET- signal. 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ciSoftware reset 9358c2ecf20Sopenharmony_ci This is achieved by turning CONTROL SRST bit on for at least 5us. 9368c2ecf20Sopenharmony_ci Both PATA and SATA support it but, in case of SATA, this may require 9378c2ecf20Sopenharmony_ci controller-specific support as the second Register FIS to clear SRST 9388c2ecf20Sopenharmony_ci should be transmitted while BSY bit is still set. Note that on PATA, 9398c2ecf20Sopenharmony_ci this resets both master and slave devices on a channel. 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ciEXECUTE DEVICE DIAGNOSTIC command 9428c2ecf20Sopenharmony_ci Although ATA/ATAPI standard doesn't describe exactly, EDD implies 9438c2ecf20Sopenharmony_ci some level of resetting, possibly similar level with software reset. 9448c2ecf20Sopenharmony_ci Host-side EDD protocol can be handled with normal command processing 9458c2ecf20Sopenharmony_ci and most SATA controllers should be able to handle EDD's just like 9468c2ecf20Sopenharmony_ci other commands. As in software reset, EDD affects both devices on a 9478c2ecf20Sopenharmony_ci PATA bus. 9488c2ecf20Sopenharmony_ci 9498c2ecf20Sopenharmony_ci Although EDD does reset devices, this doesn't suit error handling as 9508c2ecf20Sopenharmony_ci EDD cannot be issued while BSY is set and it's unclear how it will 9518c2ecf20Sopenharmony_ci act when device is in unknown/weird state. 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ciATAPI DEVICE RESET command 9548c2ecf20Sopenharmony_ci This is very similar to software reset except that reset can be 9558c2ecf20Sopenharmony_ci restricted to the selected device without affecting the other device 9568c2ecf20Sopenharmony_ci sharing the cable. 9578c2ecf20Sopenharmony_ci 9588c2ecf20Sopenharmony_ciSATA phy reset 9598c2ecf20Sopenharmony_ci This is the preferred way of resetting a SATA device. In effect, 9608c2ecf20Sopenharmony_ci it's identical to PATA hardware reset. Note that this can be done 9618c2ecf20Sopenharmony_ci with the standard SCR Control register. As such, it's usually easier 9628c2ecf20Sopenharmony_ci to implement than software reset. 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ciOne more thing to consider when resetting devices is that resetting 9658c2ecf20Sopenharmony_ciclears certain configuration parameters and they need to be set to their 9668c2ecf20Sopenharmony_ciprevious or newly adjusted values after reset. 9678c2ecf20Sopenharmony_ci 9688c2ecf20Sopenharmony_ciParameters affected are. 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci- CHS set up with INITIALIZE DEVICE PARAMETERS (seldom used) 9718c2ecf20Sopenharmony_ci 9728c2ecf20Sopenharmony_ci- Parameters set with SET FEATURES including transfer mode setting 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci- Block count set with SET MULTIPLE MODE 9758c2ecf20Sopenharmony_ci 9768c2ecf20Sopenharmony_ci- Other parameters (SET MAX, MEDIA LOCK...) 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ciATA/ATAPI standard specifies that some parameters must be maintained 9798c2ecf20Sopenharmony_ciacross hardware or software reset, but doesn't strictly specify all of 9808c2ecf20Sopenharmony_cithem. Always reconfiguring needed parameters after reset is required for 9818c2ecf20Sopenharmony_cirobustness. Note that this also applies when resuming from deep sleep 9828c2ecf20Sopenharmony_ci(power-off). 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ciAlso, ATA/ATAPI standard requires that IDENTIFY DEVICE / IDENTIFY PACKET 9858c2ecf20Sopenharmony_ciDEVICE is issued after any configuration parameter is updated or a 9868c2ecf20Sopenharmony_cihardware reset and the result used for further operation. OS driver is 9878c2ecf20Sopenharmony_cirequired to implement revalidation mechanism to support this. 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_ciReconfigure transport 9908c2ecf20Sopenharmony_ci~~~~~~~~~~~~~~~~~~~~~ 9918c2ecf20Sopenharmony_ci 9928c2ecf20Sopenharmony_ciFor both PATA and SATA, a lot of corners are cut for cheap connectors, 9938c2ecf20Sopenharmony_cicables or controllers and it's quite common to see high transmission 9948c2ecf20Sopenharmony_cierror rate. This can be mitigated by lowering transmission speed. 9958c2ecf20Sopenharmony_ci 9968c2ecf20Sopenharmony_ciThe following is a possible scheme Jeff Garzik suggested. 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci If more than $N (3?) transmission errors happen in 15 minutes, 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci - if SATA, decrease SATA PHY speed. if speed cannot be decreased, 10018c2ecf20Sopenharmony_ci 10028c2ecf20Sopenharmony_ci - decrease UDMA xfer speed. if at UDMA0, switch to PIO4, 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci - decrease PIO xfer speed. if at PIO3, complain, but continue 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ciata_piix Internals 10078c2ecf20Sopenharmony_ci=================== 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/ata_piix.c 10108c2ecf20Sopenharmony_ci :internal: 10118c2ecf20Sopenharmony_ci 10128c2ecf20Sopenharmony_cisata_sil Internals 10138c2ecf20Sopenharmony_ci=================== 10148c2ecf20Sopenharmony_ci 10158c2ecf20Sopenharmony_ci.. kernel-doc:: drivers/ata/sata_sil.c 10168c2ecf20Sopenharmony_ci :internal: 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_ciThanks 10198c2ecf20Sopenharmony_ci====== 10208c2ecf20Sopenharmony_ci 10218c2ecf20Sopenharmony_ciThe bulk of the ATA knowledge comes thanks to long conversations with 10228c2ecf20Sopenharmony_ciAndre Hedrick (www.linux-ide.org), and long hours pondering the ATA and 10238c2ecf20Sopenharmony_ciSCSI specifications. 10248c2ecf20Sopenharmony_ci 10258c2ecf20Sopenharmony_ciThanks to Alan Cox for pointing out similarities between SATA and SCSI, 10268c2ecf20Sopenharmony_ciand in general for motivation to hack on libata. 10278c2ecf20Sopenharmony_ci 10288c2ecf20Sopenharmony_cilibata's device detection method, ata_pio_devchk, and in general all 10298c2ecf20Sopenharmony_cithe early probing was based on extensive study of Hale Landis's 10308c2ecf20Sopenharmony_ciprobe/reset code in his ATADRVR driver (www.ata-atapi.com). 1031