scsi.rst 9.4 KB

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