scsi.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. =====================
  2. SCSI Interfaces Guide
  3. =====================
  4. :Author: James Bottomley
  5. :Author: Rob Landley
  6. Introduction
  7. ============
  8. Protocol vs bus
  9. ---------------
  10. Once upon a time, the Small Computer Systems Interface defined both a
  11. parallel I/O bus and a data protocol to connect a wide variety of
  12. peripherals (disk drives, tape drives, modems, printers, scanners,
  13. optical drives, test equipment, and medical devices) to a host computer.
  14. Although the old parallel (fast/wide/ultra) SCSI bus has largely fallen
  15. out of use, the SCSI command set is more widely used than ever to
  16. communicate with devices over a number of different busses.
  17. The `SCSI protocol <http://www.t10.org/scsi-3.htm>`__ is a big-endian
  18. peer-to-peer packet based protocol. SCSI commands are 6, 10, 12, or 16
  19. bytes long, often followed by an associated data payload.
  20. SCSI commands can be transported over just about any kind of bus, and
  21. are the default protocol for storage devices attached to USB, SATA, SAS,
  22. Fibre Channel, FireWire, and ATAPI devices. SCSI packets are also
  23. commonly exchanged over Infiniband,
  24. `I2O <http://i2o.shadowconnect.com/faq.php>`__, TCP/IP
  25. (`iSCSI <https://en.wikipedia.org/wiki/ISCSI>`__), even `Parallel
  26. ports <http://cyberelk.net/tim/parport/parscsi.html>`__.
  27. Design of the Linux SCSI subsystem
  28. ----------------------------------
  29. The SCSI subsystem uses a three layer design, with upper, mid, and low
  30. layers. Every operation involving the SCSI subsystem (such as reading a
  31. sector from a disk) uses one driver at each of the 3 levels: one upper
  32. layer driver, one lower layer driver, and the SCSI midlayer.
  33. The SCSI upper layer provides the interface between userspace and the
  34. kernel, in the form of block and char device nodes for I/O and ioctl().
  35. The SCSI lower layer contains drivers for specific hardware devices.
  36. In between is the SCSI mid-layer, analogous to a network routing layer
  37. such as the IPv4 stack. The SCSI mid-layer routes a packet based data
  38. protocol between the upper layer's /dev nodes and the corresponding
  39. devices in the lower layer. It manages command queues, provides error
  40. handling and power management functions, and responds to ioctl()
  41. requests.
  42. SCSI upper layer
  43. ================
  44. The upper layer supports the user-kernel interface by providing device
  45. nodes.
  46. sd (SCSI Disk)
  47. --------------
  48. sd (sd_mod.o)
  49. sr (SCSI CD-ROM)
  50. ----------------
  51. sr (sr_mod.o)
  52. st (SCSI Tape)
  53. --------------
  54. st (st.o)
  55. sg (SCSI Generic)
  56. -----------------
  57. sg (sg.o)
  58. ch (SCSI Media Changer)
  59. -----------------------
  60. ch (ch.c)
  61. SCSI mid layer
  62. ==============
  63. SCSI midlayer implementation
  64. ----------------------------
  65. include/scsi/scsi_device.h
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. .. kernel-doc:: include/scsi/scsi_device.h
  68. :internal:
  69. drivers/scsi/scsi.c
  70. ~~~~~~~~~~~~~~~~~~~
  71. Main file for the SCSI midlayer.
  72. .. kernel-doc:: drivers/scsi/scsi.c
  73. :export:
  74. drivers/scsi/scsicam.c
  75. ~~~~~~~~~~~~~~~~~~~~~~
  76. `SCSI Common Access
  77. Method <http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf>`__ support
  78. functions, for use with HDIO_GETGEO, etc.
  79. .. kernel-doc:: drivers/scsi/scsicam.c
  80. :export:
  81. drivers/scsi/scsi_error.c
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. Common SCSI error/timeout handling routines.
  84. .. kernel-doc:: drivers/scsi/scsi_error.c
  85. :export:
  86. drivers/scsi/scsi_devinfo.c
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. Manage scsi_dev_info_list, which tracks blacklisted and whitelisted
  89. devices.
  90. .. kernel-doc:: drivers/scsi/scsi_devinfo.c
  91. :internal:
  92. drivers/scsi/scsi_ioctl.c
  93. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. Handle ioctl() calls for SCSI devices.
  95. .. kernel-doc:: drivers/scsi/scsi_ioctl.c
  96. :export:
  97. drivers/scsi/scsi_lib.c
  98. ~~~~~~~~~~~~~~~~~~~~~~~~
  99. SCSI queuing library.
  100. .. kernel-doc:: drivers/scsi/scsi_lib.c
  101. :export:
  102. drivers/scsi/scsi_lib_dma.c
  103. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. SCSI library functions depending on DMA (map and unmap scatter-gather
  105. lists).
  106. .. kernel-doc:: drivers/scsi/scsi_lib_dma.c
  107. :export:
  108. drivers/scsi/scsi_proc.c
  109. ~~~~~~~~~~~~~~~~~~~~~~~~~
  110. The functions in this file provide an interface between the PROC file
  111. system and the SCSI device drivers It is mainly used for debugging,
  112. statistics and to pass information directly to the lowlevel driver. I.E.
  113. plumbing to manage /proc/scsi/\*
  114. .. kernel-doc:: drivers/scsi/scsi_proc.c
  115. :internal:
  116. drivers/scsi/scsi_netlink.c
  117. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118. Infrastructure to provide async events from transports to userspace via
  119. netlink, using a single NETLINK_SCSITRANSPORT protocol for all
  120. transports. See `the original patch
  121. submission <http://marc.info/?l=linux-scsi&m=115507374832500&w=2>`__ for
  122. more details.
  123. .. kernel-doc:: drivers/scsi/scsi_netlink.c
  124. :internal:
  125. drivers/scsi/scsi_scan.c
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~
  127. Scan a host to determine which (if any) devices are attached. The
  128. general scanning/probing algorithm is as follows, exceptions are made to
  129. it depending on device specific flags, compilation options, and global
  130. variable (boot or module load time) settings. A specific LUN is scanned
  131. via an INQUIRY command; if the LUN has a device attached, a scsi_device
  132. is allocated and setup for it. For every id of every channel on the
  133. given host, start by scanning LUN 0. Skip hosts that don't respond at
  134. all to a scan of LUN 0. Otherwise, if LUN 0 has a device attached,
  135. allocate and setup a scsi_device for it. If target is SCSI-3 or up,
  136. issue a REPORT LUN, and scan all of the LUNs returned by the REPORT LUN;
  137. else, sequentially scan LUNs up until some maximum is reached, or a LUN
  138. is seen that cannot have a device attached to it.
  139. .. kernel-doc:: drivers/scsi/scsi_scan.c
  140. :internal:
  141. drivers/scsi/scsi_sysctl.c
  142. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. Set up the sysctl entry: "/dev/scsi/logging_level"
  144. (DEV_SCSI_LOGGING_LEVEL) which sets/returns scsi_logging_level.
  145. drivers/scsi/scsi_sysfs.c
  146. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. SCSI sysfs interface routines.
  148. .. kernel-doc:: drivers/scsi/scsi_sysfs.c
  149. :export:
  150. drivers/scsi/hosts.c
  151. ~~~~~~~~~~~~~~~~~~~~
  152. mid to lowlevel SCSI driver interface
  153. .. kernel-doc:: drivers/scsi/hosts.c
  154. :export:
  155. drivers/scsi/scsi_common.c
  156. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  157. general support functions
  158. .. kernel-doc:: drivers/scsi/scsi_common.c
  159. :export:
  160. Transport classes
  161. -----------------
  162. Transport classes are service libraries for drivers in the SCSI lower
  163. layer, which expose transport attributes in sysfs.
  164. Fibre Channel transport
  165. ~~~~~~~~~~~~~~~~~~~~~~~
  166. The file drivers/scsi/scsi_transport_fc.c defines transport attributes
  167. for Fibre Channel.
  168. .. kernel-doc:: drivers/scsi/scsi_transport_fc.c
  169. :export:
  170. iSCSI transport class
  171. ~~~~~~~~~~~~~~~~~~~~~
  172. The file drivers/scsi/scsi_transport_iscsi.c defines transport
  173. attributes for the iSCSI class, which sends SCSI packets over TCP/IP
  174. connections.
  175. .. kernel-doc:: drivers/scsi/scsi_transport_iscsi.c
  176. :export:
  177. Serial Attached SCSI (SAS) transport class
  178. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  179. The file drivers/scsi/scsi_transport_sas.c defines transport
  180. attributes for Serial Attached SCSI, a variant of SATA aimed at large
  181. high-end systems.
  182. The SAS transport class contains common code to deal with SAS HBAs, an
  183. aproximated representation of SAS topologies in the driver model, and
  184. various sysfs attributes to expose these topologies and management
  185. interfaces to userspace.
  186. In addition to the basic SCSI core objects this transport class
  187. introduces two additional intermediate objects: The SAS PHY as
  188. represented by struct sas_phy defines an "outgoing" PHY on a SAS HBA or
  189. Expander, and the SAS remote PHY represented by struct sas_rphy defines
  190. an "incoming" PHY on a SAS Expander or end device. Note that this is
  191. purely a software concept, the underlying hardware for a PHY and a
  192. remote PHY is the exactly the same.
  193. There is no concept of a SAS port in this code, users can see what PHYs
  194. form a wide port based on the port_identifier attribute, which is the
  195. same for all PHYs in a port.
  196. .. kernel-doc:: drivers/scsi/scsi_transport_sas.c
  197. :export:
  198. SATA transport class
  199. ~~~~~~~~~~~~~~~~~~~~
  200. The SATA transport is handled by libata, which has its own book of
  201. documentation in this directory.
  202. Parallel SCSI (SPI) transport class
  203. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204. The file drivers/scsi/scsi_transport_spi.c defines transport
  205. attributes for traditional (fast/wide/ultra) SCSI busses.
  206. .. kernel-doc:: drivers/scsi/scsi_transport_spi.c
  207. :export:
  208. SCSI RDMA (SRP) transport class
  209. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210. The file drivers/scsi/scsi_transport_srp.c defines transport
  211. attributes for SCSI over Remote Direct Memory Access.
  212. .. kernel-doc:: drivers/scsi/scsi_transport_srp.c
  213. :export:
  214. SCSI lower layer
  215. ================
  216. Host Bus Adapter transport types
  217. --------------------------------
  218. Many modern device controllers use the SCSI command set as a protocol to
  219. communicate with their devices through many different types of physical
  220. connections.
  221. In SCSI language a bus capable of carrying SCSI commands is called a
  222. "transport", and a controller connecting to such a bus is called a "host
  223. bus adapter" (HBA).
  224. Debug transport
  225. ~~~~~~~~~~~~~~~
  226. The file drivers/scsi/scsi_debug.c simulates a host adapter with a
  227. variable number of disks (or disk like devices) attached, sharing a
  228. common amount of RAM. Does a lot of checking to make sure that we are
  229. not getting blocks mixed up, and panics the kernel if anything out of
  230. the ordinary is seen.
  231. To be more realistic, the simulated devices have the transport
  232. attributes of SAS disks.
  233. For documentation see http://sg.danny.cz/sg/sdebug26.html
  234. todo
  235. ~~~~
  236. Parallel (fast/wide/ultra) SCSI, USB, SATA, SAS, Fibre Channel,
  237. FireWire, ATAPI devices, Infiniband, I2O, Parallel ports,
  238. netlink...