libata.tmpl 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
  4. <book id="libataDevGuide">
  5. <bookinfo>
  6. <title>libATA Developer's Guide</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Jeff</firstname>
  10. <surname>Garzik</surname>
  11. </author>
  12. </authorgroup>
  13. <copyright>
  14. <year>2003-2005</year>
  15. <holder>Jeff Garzik</holder>
  16. </copyright>
  17. <legalnotice>
  18. <para>
  19. The contents of this file are subject to the Open
  20. Software License version 1.1 that can be found at
  21. <ulink url="http://www.opensource.org/licenses/osl-1.1.txt">http://www.opensource.org/licenses/osl-1.1.txt</ulink> and is included herein
  22. by reference.
  23. </para>
  24. <para>
  25. Alternatively, the contents of this file may be used under the terms
  26. of the GNU General Public License version 2 (the "GPL") as distributed
  27. in the kernel source COPYING file, in which case the provisions of
  28. the GPL are applicable instead of the above. If you wish to allow
  29. the use of your version of this file only under the terms of the
  30. GPL and not to allow others to use your version of this file under
  31. the OSL, indicate your decision by deleting the provisions above and
  32. replace them with the notice and other provisions required by the GPL.
  33. If you do not delete the provisions above, a recipient may use your
  34. version of this file under either the OSL or the GPL.
  35. </para>
  36. </legalnotice>
  37. </bookinfo>
  38. <toc></toc>
  39. <chapter id="libataIntroduction">
  40. <title>Introduction</title>
  41. <para>
  42. libATA is a library used inside the Linux kernel to support ATA host
  43. controllers and devices. libATA provides an ATA driver API, class
  44. transports for ATA and ATAPI devices, and SCSI&lt;-&gt;ATA translation
  45. for ATA devices according to the T10 SAT specification.
  46. </para>
  47. <para>
  48. This Guide documents the libATA driver API, library functions, library
  49. internals, and a couple sample ATA low-level drivers.
  50. </para>
  51. </chapter>
  52. <chapter id="libataDriverApi">
  53. <title>libata Driver API</title>
  54. <sect1>
  55. <title>struct ata_port_operations</title>
  56. <programlisting>
  57. void (*port_disable) (struct ata_port *);
  58. </programlisting>
  59. <para>
  60. Called from ata_bus_probe() and ata_bus_reset() error paths,
  61. as well as when unregistering from the SCSI module (rmmod, hot
  62. unplug).
  63. </para>
  64. <programlisting>
  65. void (*dev_config) (struct ata_port *, struct ata_device *);
  66. </programlisting>
  67. <para>
  68. Called after IDENTIFY [PACKET] DEVICE is issued to each device
  69. found. Typically used to apply device-specific fixups prior to
  70. issue of SET FEATURES - XFER MODE, and prior to operation.
  71. </para>
  72. <programlisting>
  73. void (*set_piomode) (struct ata_port *, struct ata_device *);
  74. void (*set_dmamode) (struct ata_port *, struct ata_device *);
  75. void (*post_set_mode) (struct ata_port *ap);
  76. </programlisting>
  77. <para>
  78. Hooks called prior to the issue of SET FEATURES - XFER MODE
  79. command. dev->pio_mode is guaranteed to be valid when
  80. ->set_piomode() is called, and dev->dma_mode is guaranteed to be
  81. valid when ->set_dmamode() is called. ->post_set_mode() is
  82. called unconditionally, after the SET FEATURES - XFER MODE
  83. command completes successfully.
  84. </para>
  85. <para>
  86. ->set_piomode() is always called (if present), but
  87. ->set_dma_mode() is only called if DMA is possible.
  88. </para>
  89. <programlisting>
  90. void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf);
  91. void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
  92. </programlisting>
  93. <para>
  94. ->tf_load() is called to load the given taskfile into hardware
  95. registers / DMA buffers. ->tf_read() is called to read the
  96. hardware registers / DMA buffers, to obtain the current set of
  97. taskfile register values.
  98. </para>
  99. <programlisting>
  100. void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf);
  101. </programlisting>
  102. <para>
  103. causes an ATA command, previously loaded with
  104. ->tf_load(), to be initiated in hardware.
  105. </para>
  106. <programlisting>
  107. int (*check_atapi_dma) (struct ata_queued_cmd *qc);
  108. </programlisting>
  109. <para>
  110. Allow low-level driver to filter ATA PACKET commands, returning a status
  111. indicating whether or not it is OK to use DMA for the supplied PACKET
  112. command.
  113. </para>
  114. <programlisting>
  115. u8 (*check_status)(struct ata_port *ap);
  116. u8 (*check_altstatus)(struct ata_port *ap);
  117. u8 (*check_err)(struct ata_port *ap);
  118. </programlisting>
  119. <para>
  120. Reads the Status/AltStatus/Error ATA shadow register from
  121. hardware. On some hardware, reading the Status register has
  122. the side effect of clearing the interrupt condition.
  123. </para>
  124. <programlisting>
  125. void (*dev_select)(struct ata_port *ap, unsigned int device);
  126. </programlisting>
  127. <para>
  128. Issues the low-level hardware command(s) that causes one of N
  129. hardware devices to be considered 'selected' (active and
  130. available for use) on the ATA bus. This generally has no
  131. meaning on FIS-based devices.
  132. </para>
  133. <programlisting>
  134. void (*phy_reset) (struct ata_port *ap);
  135. </programlisting>
  136. <para>
  137. The very first step in the probe phase. Actions vary depending
  138. on the bus type, typically. After waking up the device and probing
  139. for device presence (PATA and SATA), typically a soft reset
  140. (SRST) will be performed. Drivers typically use the helper
  141. functions ata_bus_reset() or sata_phy_reset() for this hook.
  142. </para>
  143. <programlisting>
  144. void (*bmdma_setup) (struct ata_queued_cmd *qc);
  145. void (*bmdma_start) (struct ata_queued_cmd *qc);
  146. void (*bmdma_stop) (struct ata_port *ap);
  147. u8 (*bmdma_status) (struct ata_port *ap);
  148. </programlisting>
  149. <para>
  150. When setting up an IDE BMDMA transaction, these hooks arm
  151. (->bmdma_setup), fire (->bmdma_start), and halt (->bmdma_stop)
  152. the hardware's DMA engine. ->bmdma_status is used to read the standard
  153. PCI IDE DMA Status register.
  154. </para>
  155. <para>
  156. These hooks are typically either no-ops, or simply not implemented, in
  157. FIS-based drivers.
  158. </para>
  159. <programlisting>
  160. void (*qc_prep) (struct ata_queued_cmd *qc);
  161. int (*qc_issue) (struct ata_queued_cmd *qc);
  162. </programlisting>
  163. <para>
  164. Higher-level hooks, these two hooks can potentially supercede
  165. several of the above taskfile/DMA engine hooks. ->qc_prep is
  166. called after the buffers have been DMA-mapped, and is typically
  167. used to populate the hardware's DMA scatter-gather table.
  168. Most drivers use the standard ata_qc_prep() helper function, but
  169. more advanced drivers roll their own.
  170. </para>
  171. <para>
  172. ->qc_issue is used to make a command active, once the hardware
  173. and S/G tables have been prepared. IDE BMDMA drivers use the
  174. helper function ata_qc_issue_prot() for taskfile protocol-based
  175. dispatch. More advanced drivers implement their own ->qc_issue.
  176. </para>
  177. <programlisting>
  178. void (*eng_timeout) (struct ata_port *ap);
  179. </programlisting>
  180. <para>
  181. This is a high level error handling function, called from the
  182. error handling thread, when a command times out. Most newer
  183. hardware will implement its own error handling code here. IDE BMDMA
  184. drivers may use the helper function ata_eng_timeout().
  185. </para>
  186. <programlisting>
  187. irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
  188. void (*irq_clear) (struct ata_port *);
  189. </programlisting>
  190. <para>
  191. ->irq_handler is the interrupt handling routine registered with
  192. the system, by libata. ->irq_clear is called during probe just
  193. before the interrupt handler is registered, to be sure hardware
  194. is quiet.
  195. </para>
  196. <programlisting>
  197. u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg);
  198. void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
  199. u32 val);
  200. </programlisting>
  201. <para>
  202. Read and write standard SATA phy registers. Currently only used
  203. if ->phy_reset hook called the sata_phy_reset() helper function.
  204. </para>
  205. <programlisting>
  206. int (*port_start) (struct ata_port *ap);
  207. void (*port_stop) (struct ata_port *ap);
  208. void (*host_stop) (struct ata_host_set *host_set);
  209. </programlisting>
  210. <para>
  211. ->port_start() is called just after the data structures for each
  212. port are initialized. Typically this is used to alloc per-port
  213. DMA buffers / tables / rings, enable DMA engines, and similar
  214. tasks.
  215. </para>
  216. <para>
  217. ->port_stop() is called after ->host_stop(). It's sole function
  218. is to release DMA/memory resources, now that they are no longer
  219. actively being used.
  220. </para>
  221. <para>
  222. ->host_stop() is called after all ->port_stop() calls
  223. have completed. The hook must finalize hardware shutdown, release DMA
  224. and other resources, etc.
  225. </para>
  226. </sect1>
  227. </chapter>
  228. <chapter id="libataExt">
  229. <title>libata Library</title>
  230. !Edrivers/scsi/libata-core.c
  231. </chapter>
  232. <chapter id="libataInt">
  233. <title>libata Core Internals</title>
  234. !Idrivers/scsi/libata-core.c
  235. </chapter>
  236. <chapter id="libataScsiInt">
  237. <title>libata SCSI translation/emulation</title>
  238. !Edrivers/scsi/libata-scsi.c
  239. !Idrivers/scsi/libata-scsi.c
  240. </chapter>
  241. <chapter id="PiixInt">
  242. <title>ata_piix Internals</title>
  243. !Idrivers/scsi/ata_piix.c
  244. </chapter>
  245. <chapter id="SILInt">
  246. <title>sata_sil Internals</title>
  247. !Idrivers/scsi/sata_sil.c
  248. </chapter>
  249. <chapter id="libataThanks">
  250. <title>Thanks</title>
  251. <para>
  252. The bulk of the ATA knowledge comes thanks to long conversations with
  253. Andre Hedrick (www.linux-ide.org), and long hours pondering the ATA
  254. and SCSI specifications.
  255. </para>
  256. <para>
  257. Thanks to Alan Cox for pointing out similarities
  258. between SATA and SCSI, and in general for motivation to hack on
  259. libata.
  260. </para>
  261. <para>
  262. libata's device detection
  263. method, ata_pio_devchk, and in general all the early probing was
  264. based on extensive study of Hale Landis's probe/reset code in his
  265. ATADRVR driver (www.ata-atapi.com).
  266. </para>
  267. </chapter>
  268. </book>