scsi.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 buses.
  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. :export:
  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. drivers/scsi/scsi_netlink.c
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116. Infrastructure to provide async events from transports to userspace via
  117. netlink, using a single NETLINK_SCSITRANSPORT protocol for all
  118. transports. See `the original patch submission
  119. <https://lore.kernel.org/linux-scsi/1155070439.6275.5.camel@localhost.localdomain/>`__
  120. for more details.
  121. .. kernel-doc:: drivers/scsi/scsi_netlink.c
  122. :internal:
  123. drivers/scsi/scsi_scan.c
  124. ~~~~~~~~~~~~~~~~~~~~~~~~~
  125. Scan a host to determine which (if any) devices are attached. The
  126. general scanning/probing algorithm is as follows, exceptions are made to
  127. it depending on device specific flags, compilation options, and global
  128. variable (boot or module load time) settings. A specific LUN is scanned
  129. via an INQUIRY command; if the LUN has a device attached, a scsi_device
  130. is allocated and setup for it. For every id of every channel on the
  131. given host, start by scanning LUN 0. Skip hosts that don't respond at
  132. all to a scan of LUN 0. Otherwise, if LUN 0 has a device attached,
  133. allocate and setup a scsi_device for it. If target is SCSI-3 or up,
  134. issue a REPORT LUN, and scan all of the LUNs returned by the REPORT LUN;
  135. else, sequentially scan LUNs up until some maximum is reached, or a LUN
  136. is seen that cannot have a device attached to it.
  137. .. kernel-doc:: drivers/scsi/scsi_scan.c
  138. :export:
  139. drivers/scsi/scsi_sysctl.c
  140. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. Set up the sysctl entry: "/dev/scsi/logging_level"
  142. (DEV_SCSI_LOGGING_LEVEL) which sets/returns scsi_logging_level.
  143. drivers/scsi/scsi_sysfs.c
  144. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. SCSI sysfs interface routines.
  146. .. kernel-doc:: drivers/scsi/scsi_sysfs.c
  147. :export:
  148. drivers/scsi/hosts.c
  149. ~~~~~~~~~~~~~~~~~~~~
  150. mid to lowlevel SCSI driver interface
  151. .. kernel-doc:: drivers/scsi/hosts.c
  152. :export:
  153. drivers/scsi/scsi_common.c
  154. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. general support functions
  156. .. kernel-doc:: drivers/scsi/scsi_common.c
  157. :export:
  158. Transport classes
  159. -----------------
  160. Transport classes are service libraries for drivers in the SCSI lower
  161. layer, which expose transport attributes in sysfs.
  162. Fibre Channel transport
  163. ~~~~~~~~~~~~~~~~~~~~~~~
  164. The file drivers/scsi/scsi_transport_fc.c defines transport attributes
  165. for Fibre Channel.
  166. .. kernel-doc:: drivers/scsi/scsi_transport_fc.c
  167. :export:
  168. iSCSI transport class
  169. ~~~~~~~~~~~~~~~~~~~~~
  170. The file drivers/scsi/scsi_transport_iscsi.c defines transport
  171. attributes for the iSCSI class, which sends SCSI packets over TCP/IP
  172. connections.
  173. .. kernel-doc:: drivers/scsi/scsi_transport_iscsi.c
  174. :export:
  175. Serial Attached SCSI (SAS) transport class
  176. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177. The file drivers/scsi/scsi_transport_sas.c defines transport
  178. attributes for Serial Attached SCSI, a variant of SATA aimed at large
  179. high-end systems.
  180. The SAS transport class contains common code to deal with SAS HBAs, an
  181. approximated representation of SAS topologies in the driver model, and
  182. various sysfs attributes to expose these topologies and management
  183. interfaces to userspace.
  184. In addition to the basic SCSI core objects this transport class
  185. introduces two additional intermediate objects: The SAS PHY as
  186. represented by struct sas_phy defines an "outgoing" PHY on a SAS HBA or
  187. Expander, and the SAS remote PHY represented by struct sas_rphy defines
  188. an "incoming" PHY on a SAS Expander or end device. Note that this is
  189. purely a software concept, the underlying hardware for a PHY and a
  190. remote PHY is the exactly the same.
  191. There is no concept of a SAS port in this code, users can see what PHYs
  192. form a wide port based on the port_identifier attribute, which is the
  193. same for all PHYs in a port.
  194. .. kernel-doc:: drivers/scsi/scsi_transport_sas.c
  195. :export:
  196. SATA transport class
  197. ~~~~~~~~~~~~~~~~~~~~
  198. The SATA transport is handled by libata, which has its own book of
  199. documentation in this directory.
  200. Parallel SCSI (SPI) transport class
  201. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202. The file drivers/scsi/scsi_transport_spi.c defines transport
  203. attributes for traditional (fast/wide/ultra) SCSI buses.
  204. .. kernel-doc:: drivers/scsi/scsi_transport_spi.c
  205. :export:
  206. SCSI RDMA (SRP) transport class
  207. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  208. The file drivers/scsi/scsi_transport_srp.c defines transport
  209. attributes for SCSI over Remote Direct Memory Access.
  210. .. kernel-doc:: drivers/scsi/scsi_transport_srp.c
  211. :export:
  212. SCSI lower layer
  213. ================
  214. Host Bus Adapter transport types
  215. --------------------------------
  216. Many modern device controllers use the SCSI command set as a protocol to
  217. communicate with their devices through many different types of physical
  218. connections.
  219. In SCSI language a bus capable of carrying SCSI commands is called a
  220. "transport", and a controller connecting to such a bus is called a "host
  221. bus adapter" (HBA).
  222. Debug transport
  223. ~~~~~~~~~~~~~~~
  224. The file drivers/scsi/scsi_debug.c simulates a host adapter with a
  225. variable number of disks (or disk like devices) attached, sharing a
  226. common amount of RAM. Does a lot of checking to make sure that we are
  227. not getting blocks mixed up, and panics the kernel if anything out of
  228. the ordinary is seen.
  229. To be more realistic, the simulated devices have the transport
  230. attributes of SAS disks.
  231. For documentation see http://sg.danny.cz/sg/scsi_debug.html
  232. todo
  233. ~~~~
  234. Parallel (fast/wide/ultra) SCSI, USB, SATA, SAS, Fibre Channel,
  235. FireWire, ATAPI devices, Infiniband, Parallel ports,
  236. netlink...