scsidrivers.tmpl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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="scsidrivers">
  5. <bookinfo>
  6. <title>SCSI Subsystem Interfaces</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Douglas</firstname>
  10. <surname>Gilbert</surname>
  11. <affiliation>
  12. <address>
  13. <email>dgilbert@interlog.com</email>
  14. </address>
  15. </affiliation>
  16. </author>
  17. </authorgroup>
  18. <pubdate>2003-08-11</pubdate>
  19. <copyright>
  20. <year>2002</year>
  21. <year>2003</year>
  22. <holder>Douglas Gilbert</holder>
  23. </copyright>
  24. <legalnotice>
  25. <para>
  26. This documentation is free software; you can redistribute
  27. it and/or modify it under the terms of the GNU General Public
  28. License as published by the Free Software Foundation; either
  29. version 2 of the License, or (at your option) any later
  30. version.
  31. </para>
  32. <para>
  33. This program is distributed in the hope that it will be
  34. useful, but WITHOUT ANY WARRANTY; without even the implied
  35. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  36. See the GNU General Public License for more details.
  37. </para>
  38. <para>
  39. You should have received a copy of the GNU General Public
  40. License along with this program; if not, write to the Free
  41. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  42. MA 02111-1307 USA
  43. </para>
  44. <para>
  45. For more details see the file COPYING in the source
  46. distribution of Linux.
  47. </para>
  48. </legalnotice>
  49. </bookinfo>
  50. <toc></toc>
  51. <chapter id="intro">
  52. <title>Introduction</title>
  53. <para>
  54. This document outlines the interface between the Linux scsi mid level
  55. and lower level drivers. Lower level drivers are variously called HBA
  56. (host bus adapter) drivers, host drivers (HD) or pseudo adapter drivers.
  57. The latter alludes to the fact that a lower level driver may be a
  58. bridge to another IO subsystem (and the "ide-scsi" driver is an example
  59. of this). There can be many lower level drivers active in a running
  60. system, but only one per hardware type. For example, the aic7xxx driver
  61. controls adaptec controllers based on the 7xxx chip series. Most lower
  62. level drivers can control one or more scsi hosts (a.k.a. scsi initiators).
  63. </para>
  64. <para>
  65. This document can been found in an ASCII text file in the linux kernel
  66. source: <filename>Documentation/scsi/scsi_mid_low_api.txt</filename> .
  67. It currently hold a little more information than this document. The
  68. <filename>drivers/scsi/hosts.h</filename> and <filename>
  69. drivers/scsi/scsi.h</filename> headers contain descriptions of members
  70. of important structures for the scsi subsystem.
  71. </para>
  72. </chapter>
  73. <chapter id="driver-struct">
  74. <title>Driver structure</title>
  75. <para>
  76. Traditionally a lower level driver for the scsi subsystem has been
  77. at least two files in the drivers/scsi directory. For example, a
  78. driver called "xyz" has a header file "xyz.h" and a source file
  79. "xyz.c". [Actually there is no good reason why this couldn't all
  80. be in one file.] Some drivers that have been ported to several operating
  81. systems (e.g. aic7xxx which has separate files for generic and
  82. OS-specific code) have more than two files. Such drivers tend to have
  83. their own directory under the drivers/scsi directory.
  84. </para>
  85. <para>
  86. scsi_module.c is normally included at the end of a lower
  87. level driver. For it to work a declaration like this is needed before
  88. it is included:
  89. <programlisting>
  90. static Scsi_Host_Template driver_template = DRIVER_TEMPLATE;
  91. /* DRIVER_TEMPLATE should contain pointers to supported interface
  92. functions. Scsi_Host_Template is defined hosts.h */
  93. #include "scsi_module.c"
  94. </programlisting>
  95. </para>
  96. <para>
  97. The scsi_module.c assumes the name "driver_template" is appropriately
  98. defined. It contains 2 functions:
  99. <orderedlist>
  100. <listitem><para>
  101. init_this_scsi_driver() called during builtin and module driver
  102. initialization: invokes mid level's scsi_register_host()
  103. </para></listitem>
  104. <listitem><para>
  105. exit_this_scsi_driver() called during closedown: invokes
  106. mid level's scsi_unregister_host()
  107. </para></listitem>
  108. </orderedlist>
  109. </para>
  110. <para>
  111. When a new, lower level driver is being added to Linux, the following
  112. files (all found in the drivers/scsi directory) will need some attention:
  113. Makefile, Config.help and Config.in . It is probably best to look at what
  114. an existing lower level driver does in this regard.
  115. </para>
  116. </chapter>
  117. <chapter id="intfunctions">
  118. <title>Interface Functions</title>
  119. !EDocumentation/scsi/scsi_mid_low_api.txt
  120. </chapter>
  121. <chapter id="locks">
  122. <title>Locks</title>
  123. <para>
  124. Each Scsi_Host instance has a spin_lock called Scsi_Host::default_lock
  125. which is initialized in scsi_register() [found in hosts.c]. Within the
  126. same function the Scsi_Host::host_lock pointer is initialized to point
  127. at default_lock with the scsi_assign_lock() function. Thereafter
  128. lock and unlock operations performed by the mid level use the
  129. Scsi_Host::host_lock pointer.
  130. </para>
  131. <para>
  132. Lower level drivers can override the use of Scsi_Host::default_lock by
  133. using scsi_assign_lock(). The earliest opportunity to do this would
  134. be in the detect() function after it has invoked scsi_register(). It
  135. could be replaced by a coarser grain lock (e.g. per driver) or a
  136. lock of equal granularity (i.e. per host). Using finer grain locks
  137. (e.g. per scsi device) may be possible by juggling locks in
  138. queuecommand().
  139. </para>
  140. </chapter>
  141. <chapter id="changes">
  142. <title>Changes since lk 2.4 series</title>
  143. <para>
  144. io_request_lock has been replaced by several finer grained locks. The lock
  145. relevant to lower level drivers is Scsi_Host::host_lock and there is one
  146. per scsi host.
  147. </para>
  148. <para>
  149. The older error handling mechanism has been removed. This means the
  150. lower level interface functions abort() and reset() have been removed.
  151. </para>
  152. <para>
  153. In the 2.4 series the scsi subsystem configuration descriptions were
  154. aggregated with the configuration descriptions from all other Linux
  155. subsystems in the Documentation/Configure.help file. In the 2.5 series,
  156. the scsi subsystem now has its own (much smaller) drivers/scsi/Config.help
  157. file.
  158. </para>
  159. </chapter>
  160. <chapter id="credits">
  161. <title>Credits</title>
  162. <para>
  163. The following people have contributed to this document:
  164. <orderedlist>
  165. <listitem><para>
  166. Mike Anderson <email>andmike@us.ibm.com</email>
  167. </para></listitem>
  168. <listitem><para>
  169. James Bottomley <email>James.Bottomley@steeleye.com</email>
  170. </para></listitem>
  171. <listitem><para>
  172. Patrick Mansfield <email>patmans@us.ibm.com</email>
  173. </para></listitem>
  174. </orderedlist>
  175. </para>
  176. </chapter>
  177. </book>