libata.tmpl 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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</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="libataThanks">
  40. <title>Thanks</title>
  41. <para>
  42. The bulk of the ATA knowledge comes thanks to long conversations with
  43. Andre Hedrick (www.linux-ide.org).
  44. </para>
  45. <para>
  46. Thanks to Alan Cox for pointing out similarities
  47. between SATA and SCSI, and in general for motivation to hack on
  48. libata.
  49. </para>
  50. <para>
  51. libata's device detection
  52. method, ata_pio_devchk, and in general all the early probing was
  53. based on extensive study of Hale Landis's probe/reset code in his
  54. ATADRVR driver (www.ata-atapi.com).
  55. </para>
  56. </chapter>
  57. <chapter id="libataDriverApi">
  58. <title>libata Driver API</title>
  59. <sect1>
  60. <title>struct ata_port_operations</title>
  61. <programlisting>
  62. void (*port_disable) (struct ata_port *);
  63. </programlisting>
  64. <para>
  65. Called from ata_bus_probe() and ata_bus_reset() error paths,
  66. as well as when unregistering from the SCSI module (rmmod, hot
  67. unplug).
  68. </para>
  69. <programlisting>
  70. void (*dev_config) (struct ata_port *, struct ata_device *);
  71. </programlisting>
  72. <para>
  73. Called after IDENTIFY [PACKET] DEVICE is issued to each device
  74. found. Typically used to apply device-specific fixups prior to
  75. issue of SET FEATURES - XFER MODE, and prior to operation.
  76. </para>
  77. <programlisting>
  78. void (*set_piomode) (struct ata_port *, struct ata_device *);
  79. void (*set_dmamode) (struct ata_port *, struct ata_device *);
  80. void (*post_set_mode) (struct ata_port *ap);
  81. </programlisting>
  82. <para>
  83. Hooks called prior to the issue of SET FEATURES - XFER MODE
  84. command. dev->pio_mode is guaranteed to be valid when
  85. ->set_piomode() is called, and dev->dma_mode is guaranteed to be
  86. valid when ->set_dmamode() is called. ->post_set_mode() is
  87. called unconditionally, after the SET FEATURES - XFER MODE
  88. command completes successfully.
  89. </para>
  90. <para>
  91. ->set_piomode() is always called (if present), but
  92. ->set_dma_mode() is only called if DMA is possible.
  93. </para>
  94. <programlisting>
  95. void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf);
  96. void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
  97. </programlisting>
  98. <para>
  99. ->tf_load() is called to load the given taskfile into hardware
  100. registers / DMA buffers. ->tf_read() is called to read the
  101. hardware registers / DMA buffers, to obtain the current set of
  102. taskfile register values.
  103. </para>
  104. <programlisting>
  105. void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf);
  106. </programlisting>
  107. <para>
  108. causes an ATA command, previously loaded with
  109. ->tf_load(), to be initiated in hardware.
  110. </para>
  111. <programlisting>
  112. u8 (*check_status)(struct ata_port *ap);
  113. void (*dev_select)(struct ata_port *ap, unsigned int device);
  114. </programlisting>
  115. <para>
  116. Reads the Status ATA shadow register from hardware. On some
  117. hardware, this has the side effect of clearing the interrupt
  118. condition.
  119. </para>
  120. <programlisting>
  121. void (*dev_select)(struct ata_port *ap, unsigned int device);
  122. </programlisting>
  123. <para>
  124. Issues the low-level hardware command(s) that causes one of N
  125. hardware devices to be considered 'selected' (active and
  126. available for use) on the ATA bus.
  127. </para>
  128. <programlisting>
  129. void (*phy_reset) (struct ata_port *ap);
  130. </programlisting>
  131. <para>
  132. The very first step in the probe phase. Actions vary depending
  133. on the bus type, typically. After waking up the device and probing
  134. for device presence (PATA and SATA), typically a soft reset
  135. (SRST) will be performed. Drivers typically use the helper
  136. functions ata_bus_reset() or sata_phy_reset() for this hook.
  137. </para>
  138. <programlisting>
  139. void (*bmdma_setup) (struct ata_queued_cmd *qc);
  140. void (*bmdma_start) (struct ata_queued_cmd *qc);
  141. </programlisting>
  142. <para>
  143. When setting up an IDE BMDMA transaction, these hooks arm
  144. (->bmdma_setup) and fire (->bmdma_start) the hardware's DMA
  145. engine.
  146. </para>
  147. <programlisting>
  148. void (*qc_prep) (struct ata_queued_cmd *qc);
  149. int (*qc_issue) (struct ata_queued_cmd *qc);
  150. </programlisting>
  151. <para>
  152. Higher-level hooks, these two hooks can potentially supercede
  153. several of the above taskfile/DMA engine hooks. ->qc_prep is
  154. called after the buffers have been DMA-mapped, and is typically
  155. used to populate the hardware's DMA scatter-gather table.
  156. Most drivers use the standard ata_qc_prep() helper function, but
  157. more advanced drivers roll their own.
  158. </para>
  159. <para>
  160. ->qc_issue is used to make a command active, once the hardware
  161. and S/G tables have been prepared. IDE BMDMA drivers use the
  162. helper function ata_qc_issue_prot() for taskfile protocol-based
  163. dispatch. More advanced drivers roll their own ->qc_issue
  164. implementation, using this as the "issue new ATA command to
  165. hardware" hook.
  166. </para>
  167. <programlisting>
  168. void (*eng_timeout) (struct ata_port *ap);
  169. </programlisting>
  170. <para>
  171. This is a high level error handling function, called from the
  172. error handling thread, when a command times out.
  173. </para>
  174. <programlisting>
  175. irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
  176. void (*irq_clear) (struct ata_port *);
  177. </programlisting>
  178. <para>
  179. ->irq_handler is the interrupt handling routine registered with
  180. the system, by libata. ->irq_clear is called during probe just
  181. before the interrupt handler is registered, to be sure hardware
  182. is quiet.
  183. </para>
  184. <programlisting>
  185. u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg);
  186. void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
  187. u32 val);
  188. </programlisting>
  189. <para>
  190. Read and write standard SATA phy registers. Currently only used
  191. if ->phy_reset hook called the sata_phy_reset() helper function.
  192. </para>
  193. <programlisting>
  194. int (*port_start) (struct ata_port *ap);
  195. void (*port_stop) (struct ata_port *ap);
  196. void (*host_stop) (struct ata_host_set *host_set);
  197. </programlisting>
  198. <para>
  199. ->port_start() is called just after the data structures for each
  200. port are initialized. Typically this is used to alloc per-port
  201. DMA buffers / tables / rings, enable DMA engines, and similar
  202. tasks.
  203. </para>
  204. <para>
  205. ->host_stop() is called when the rmmod or hot unplug process
  206. begins. The hook must stop all hardware interrupts, DMA
  207. engines, etc.
  208. </para>
  209. <para>
  210. ->port_stop() is called after ->host_stop(). It's sole function
  211. is to release DMA/memory resources, now that they are no longer
  212. actively being used.
  213. </para>
  214. </sect1>
  215. </chapter>
  216. <chapter id="libataExt">
  217. <title>libata Library</title>
  218. !Edrivers/scsi/libata-core.c
  219. </chapter>
  220. <chapter id="libataInt">
  221. <title>libata Core Internals</title>
  222. !Idrivers/scsi/libata-core.c
  223. </chapter>
  224. <chapter id="libataScsiInt">
  225. <title>libata SCSI translation/emulation</title>
  226. !Edrivers/scsi/libata-scsi.c
  227. !Idrivers/scsi/libata-scsi.c
  228. </chapter>
  229. <chapter id="PiixInt">
  230. <title>ata_piix Internals</title>
  231. !Idrivers/scsi/ata_piix.c
  232. </chapter>
  233. <chapter id="SILInt">
  234. <title>sata_sil Internals</title>
  235. !Idrivers/scsi/sata_sil.c
  236. </chapter>
  237. </book>