scsi.tmpl 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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="scsimid">
  5. <bookinfo>
  6. <title>SCSI Interfaces Guide</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>James</firstname>
  10. <surname>Bottomley</surname>
  11. <affiliation>
  12. <address>
  13. <email>James.Bottomley@hansenpartnership.com</email>
  14. </address>
  15. </affiliation>
  16. </author>
  17. <author>
  18. <firstname>Rob</firstname>
  19. <surname>Landley</surname>
  20. <affiliation>
  21. <address>
  22. <email>rob@landley.net</email>
  23. </address>
  24. </affiliation>
  25. </author>
  26. </authorgroup>
  27. <copyright>
  28. <year>2007</year>
  29. <holder>Linux Foundation</holder>
  30. </copyright>
  31. <legalnotice>
  32. <para>
  33. This documentation is free software; you can redistribute
  34. it and/or modify it under the terms of the GNU General Public
  35. License version 2.
  36. </para>
  37. <para>
  38. This program is distributed in the hope that it will be
  39. useful, but WITHOUT ANY WARRANTY; without even the implied
  40. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  41. For more details see the file COPYING in the source
  42. distribution of Linux.
  43. </para>
  44. </legalnotice>
  45. </bookinfo>
  46. <toc></toc>
  47. <chapter id="intro">
  48. <title>Introduction</title>
  49. <sect1 id="protocol_vs_bus">
  50. <title>Protocol vs bus</title>
  51. <para>
  52. Once upon a time, the Small Computer Systems Interface defined both
  53. a parallel I/O bus and a data protocol to connect a wide variety of
  54. peripherals (disk drives, tape drives, modems, printers, scanners,
  55. optical drives, test equipment, and medical devices) to a host
  56. computer.
  57. </para>
  58. <para>
  59. Although the old parallel (fast/wide/ultra) SCSI bus has largely
  60. fallen out of use, the SCSI command set is more widely used than ever
  61. to communicate with devices over a number of different busses.
  62. </para>
  63. <para>
  64. The <ulink url='http://www.t10.org/scsi-3.htm'>SCSI protocol</ulink>
  65. is a big-endian peer-to-peer packet based protocol. SCSI commands
  66. are 6, 10, 12, or 16 bytes long, often followed by an associated data
  67. payload.
  68. </para>
  69. <para>
  70. SCSI commands can be transported over just about any kind of bus, and
  71. are the default protocol for storage devices attached to USB, SATA,
  72. SAS, Fibre Channel, FireWire, and ATAPI devices. SCSI packets are
  73. also commonly exchanged over Infiniband,
  74. <ulink url='http://i2o.shadowconnect.com/faq.php'>I20</ulink>, TCP/IP
  75. (<ulink url='https://en.wikipedia.org/wiki/ISCSI'>iSCSI</ulink>), even
  76. <ulink url='http://cyberelk.net/tim/parport/parscsi.html'>Parallel
  77. ports</ulink>.
  78. </para>
  79. </sect1>
  80. <sect1 id="subsystem_design">
  81. <title>Design of the Linux SCSI subsystem</title>
  82. <para>
  83. The SCSI subsystem uses a three layer design, with upper, mid, and low
  84. layers. Every operation involving the SCSI subsystem (such as reading
  85. a sector from a disk) uses one driver at each of the 3 levels: one
  86. upper layer driver, one lower layer driver, and the SCSI midlayer.
  87. </para>
  88. <para>
  89. The SCSI upper layer provides the interface between userspace and the
  90. kernel, in the form of block and char device nodes for I/O and
  91. ioctl(). The SCSI lower layer contains drivers for specific hardware
  92. devices.
  93. </para>
  94. <para>
  95. In between is the SCSI mid-layer, analogous to a network routing
  96. layer such as the IPv4 stack. The SCSI mid-layer routes a packet
  97. based data protocol between the upper layer's /dev nodes and the
  98. corresponding devices in the lower layer. It manages command queues,
  99. provides error handling and power management functions, and responds
  100. to ioctl() requests.
  101. </para>
  102. </sect1>
  103. </chapter>
  104. <chapter id="upper_layer">
  105. <title>SCSI upper layer</title>
  106. <para>
  107. The upper layer supports the user-kernel interface by providing
  108. device nodes.
  109. </para>
  110. <sect1 id="sd">
  111. <title>sd (SCSI Disk)</title>
  112. <para>sd (sd_mod.o)</para>
  113. <!-- !Idrivers/scsi/sd.c -->
  114. </sect1>
  115. <sect1 id="sr">
  116. <title>sr (SCSI CD-ROM)</title>
  117. <para>sr (sr_mod.o)</para>
  118. </sect1>
  119. <sect1 id="st">
  120. <title>st (SCSI Tape)</title>
  121. <para>st (st.o)</para>
  122. </sect1>
  123. <sect1 id="sg">
  124. <title>sg (SCSI Generic)</title>
  125. <para>sg (sg.o)</para>
  126. </sect1>
  127. <sect1 id="ch">
  128. <title>ch (SCSI Media Changer)</title>
  129. <para>ch (ch.c)</para>
  130. </sect1>
  131. </chapter>
  132. <chapter id="mid_layer">
  133. <title>SCSI mid layer</title>
  134. <sect1 id="midlayer_implementation">
  135. <title>SCSI midlayer implementation</title>
  136. <sect2 id="scsi_device.h">
  137. <title>include/scsi/scsi_device.h</title>
  138. <para>
  139. </para>
  140. !Iinclude/scsi/scsi_device.h
  141. </sect2>
  142. <sect2 id="scsi.c">
  143. <title>drivers/scsi/scsi.c</title>
  144. <para>Main file for the SCSI midlayer.</para>
  145. !Edrivers/scsi/scsi.c
  146. </sect2>
  147. <sect2 id="scsicam.c">
  148. <title>drivers/scsi/scsicam.c</title>
  149. <para>
  150. <ulink url='http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf'>SCSI
  151. Common Access Method</ulink> support functions, for use with
  152. HDIO_GETGEO, etc.
  153. </para>
  154. !Edrivers/scsi/scsicam.c
  155. </sect2>
  156. <sect2 id="scsi_error.c">
  157. <title>drivers/scsi/scsi_error.c</title>
  158. <para>Common SCSI error/timeout handling routines.</para>
  159. !Edrivers/scsi/scsi_error.c
  160. </sect2>
  161. <sect2 id="scsi_devinfo.c">
  162. <title>drivers/scsi/scsi_devinfo.c</title>
  163. <para>
  164. Manage scsi_dev_info_list, which tracks blacklisted and whitelisted
  165. devices.
  166. </para>
  167. !Idrivers/scsi/scsi_devinfo.c
  168. </sect2>
  169. <sect2 id="scsi_ioctl.c">
  170. <title>drivers/scsi/scsi_ioctl.c</title>
  171. <para>
  172. Handle ioctl() calls for SCSI devices.
  173. </para>
  174. !Edrivers/scsi/scsi_ioctl.c
  175. </sect2>
  176. <sect2 id="scsi_lib.c">
  177. <title>drivers/scsi/scsi_lib.c</title>
  178. <para>
  179. SCSI queuing library.
  180. </para>
  181. !Edrivers/scsi/scsi_lib.c
  182. </sect2>
  183. <sect2 id="scsi_lib_dma.c">
  184. <title>drivers/scsi/scsi_lib_dma.c</title>
  185. <para>
  186. SCSI library functions depending on DMA
  187. (map and unmap scatter-gather lists).
  188. </para>
  189. !Edrivers/scsi/scsi_lib_dma.c
  190. </sect2>
  191. <sect2 id="scsi_module.c">
  192. <title>drivers/scsi/scsi_module.c</title>
  193. <para>
  194. The file drivers/scsi/scsi_module.c contains legacy support for
  195. old-style host templates. It should never be used by any new driver.
  196. </para>
  197. </sect2>
  198. <sect2 id="scsi_proc.c">
  199. <title>drivers/scsi/scsi_proc.c</title>
  200. <para>
  201. The functions in this file provide an interface between
  202. the PROC file system and the SCSI device drivers
  203. It is mainly used for debugging, statistics and to pass
  204. information directly to the lowlevel driver.
  205. I.E. plumbing to manage /proc/scsi/*
  206. </para>
  207. !Idrivers/scsi/scsi_proc.c
  208. </sect2>
  209. <sect2 id="scsi_netlink.c">
  210. <title>drivers/scsi/scsi_netlink.c</title>
  211. <para>
  212. Infrastructure to provide async events from transports to userspace
  213. via netlink, using a single NETLINK_SCSITRANSPORT protocol for all
  214. transports.
  215. See <ulink url='http://marc.info/?l=linux-scsi&amp;m=115507374832500&amp;w=2'>the
  216. original patch submission</ulink> for more details.
  217. </para>
  218. !Idrivers/scsi/scsi_netlink.c
  219. </sect2>
  220. <sect2 id="scsi_scan.c">
  221. <title>drivers/scsi/scsi_scan.c</title>
  222. <para>
  223. Scan a host to determine which (if any) devices are attached.
  224. The general scanning/probing algorithm is as follows, exceptions are
  225. made to it depending on device specific flags, compilation options,
  226. and global variable (boot or module load time) settings.
  227. A specific LUN is scanned via an INQUIRY command; if the LUN has a
  228. device attached, a scsi_device is allocated and setup for it.
  229. For every id of every channel on the given host, start by scanning
  230. LUN 0. Skip hosts that don't respond at all to a scan of LUN 0.
  231. Otherwise, if LUN 0 has a device attached, allocate and setup a
  232. scsi_device for it. If target is SCSI-3 or up, issue a REPORT LUN,
  233. and scan all of the LUNs returned by the REPORT LUN; else,
  234. sequentially scan LUNs up until some maximum is reached, or a LUN is
  235. seen that cannot have a device attached to it.
  236. </para>
  237. !Idrivers/scsi/scsi_scan.c
  238. </sect2>
  239. <sect2 id="scsi_sysctl.c">
  240. <title>drivers/scsi/scsi_sysctl.c</title>
  241. <para>
  242. Set up the sysctl entry: "/dev/scsi/logging_level"
  243. (DEV_SCSI_LOGGING_LEVEL) which sets/returns scsi_logging_level.
  244. </para>
  245. </sect2>
  246. <sect2 id="scsi_sysfs.c">
  247. <title>drivers/scsi/scsi_sysfs.c</title>
  248. <para>
  249. SCSI sysfs interface routines.
  250. </para>
  251. !Edrivers/scsi/scsi_sysfs.c
  252. </sect2>
  253. <sect2 id="hosts.c">
  254. <title>drivers/scsi/hosts.c</title>
  255. <para>
  256. mid to lowlevel SCSI driver interface
  257. </para>
  258. !Edrivers/scsi/hosts.c
  259. </sect2>
  260. <sect2 id="constants.c">
  261. <title>drivers/scsi/constants.c</title>
  262. <para>
  263. mid to lowlevel SCSI driver interface
  264. </para>
  265. !Edrivers/scsi/constants.c
  266. </sect2>
  267. </sect1>
  268. <sect1 id="Transport_classes">
  269. <title>Transport classes</title>
  270. <para>
  271. Transport classes are service libraries for drivers in the SCSI
  272. lower layer, which expose transport attributes in sysfs.
  273. </para>
  274. <sect2 id="Fibre_Channel_transport">
  275. <title>Fibre Channel transport</title>
  276. <para>
  277. The file drivers/scsi/scsi_transport_fc.c defines transport attributes
  278. for Fibre Channel.
  279. </para>
  280. !Edrivers/scsi/scsi_transport_fc.c
  281. </sect2>
  282. <sect2 id="iSCSI_transport">
  283. <title>iSCSI transport class</title>
  284. <para>
  285. The file drivers/scsi/scsi_transport_iscsi.c defines transport
  286. attributes for the iSCSI class, which sends SCSI packets over TCP/IP
  287. connections.
  288. </para>
  289. !Edrivers/scsi/scsi_transport_iscsi.c
  290. </sect2>
  291. <sect2 id="SAS_transport">
  292. <title>Serial Attached SCSI (SAS) transport class</title>
  293. <para>
  294. The file drivers/scsi/scsi_transport_sas.c defines transport
  295. attributes for Serial Attached SCSI, a variant of SATA aimed at
  296. large high-end systems.
  297. </para>
  298. <para>
  299. The SAS transport class contains common code to deal with SAS HBAs,
  300. an aproximated representation of SAS topologies in the driver model,
  301. and various sysfs attributes to expose these topologies and management
  302. interfaces to userspace.
  303. </para>
  304. <para>
  305. In addition to the basic SCSI core objects this transport class
  306. introduces two additional intermediate objects: The SAS PHY
  307. as represented by struct sas_phy defines an "outgoing" PHY on
  308. a SAS HBA or Expander, and the SAS remote PHY represented by
  309. struct sas_rphy defines an "incoming" PHY on a SAS Expander or
  310. end device. Note that this is purely a software concept, the
  311. underlying hardware for a PHY and a remote PHY is the exactly
  312. the same.
  313. </para>
  314. <para>
  315. There is no concept of a SAS port in this code, users can see
  316. what PHYs form a wide port based on the port_identifier attribute,
  317. which is the same for all PHYs in a port.
  318. </para>
  319. !Edrivers/scsi/scsi_transport_sas.c
  320. </sect2>
  321. <sect2 id="SATA_transport">
  322. <title>SATA transport class</title>
  323. <para>
  324. The SATA transport is handled by libata, which has its own book of
  325. documentation in this directory.
  326. </para>
  327. </sect2>
  328. <sect2 id="SPI_transport">
  329. <title>Parallel SCSI (SPI) transport class</title>
  330. <para>
  331. The file drivers/scsi/scsi_transport_spi.c defines transport
  332. attributes for traditional (fast/wide/ultra) SCSI busses.
  333. </para>
  334. !Edrivers/scsi/scsi_transport_spi.c
  335. </sect2>
  336. <sect2 id="SRP_transport">
  337. <title>SCSI RDMA (SRP) transport class</title>
  338. <para>
  339. The file drivers/scsi/scsi_transport_srp.c defines transport
  340. attributes for SCSI over Remote Direct Memory Access.
  341. </para>
  342. !Edrivers/scsi/scsi_transport_srp.c
  343. </sect2>
  344. </sect1>
  345. </chapter>
  346. <chapter id="lower_layer">
  347. <title>SCSI lower layer</title>
  348. <sect1 id="hba_drivers">
  349. <title>Host Bus Adapter transport types</title>
  350. <para>
  351. Many modern device controllers use the SCSI command set as a protocol to
  352. communicate with their devices through many different types of physical
  353. connections.
  354. </para>
  355. <para>
  356. In SCSI language a bus capable of carrying SCSI commands is
  357. called a "transport", and a controller connecting to such a bus is
  358. called a "host bus adapter" (HBA).
  359. </para>
  360. <sect2 id="scsi_debug.c">
  361. <title>Debug transport</title>
  362. <para>
  363. The file drivers/scsi/scsi_debug.c simulates a host adapter with a
  364. variable number of disks (or disk like devices) attached, sharing a
  365. common amount of RAM. Does a lot of checking to make sure that we are
  366. not getting blocks mixed up, and panics the kernel if anything out of
  367. the ordinary is seen.
  368. </para>
  369. <para>
  370. To be more realistic, the simulated devices have the transport
  371. attributes of SAS disks.
  372. </para>
  373. <para>
  374. For documentation see
  375. <ulink url='http://sg.danny.cz/sg/sdebug26.html'>http://sg.danny.cz/sg/sdebug26.html</ulink>
  376. </para>
  377. <!-- !Edrivers/scsi/scsi_debug.c -->
  378. </sect2>
  379. <sect2 id="todo">
  380. <title>todo</title>
  381. <para>Parallel (fast/wide/ultra) SCSI, USB, SATA,
  382. SAS, Fibre Channel, FireWire, ATAPI devices, Infiniband,
  383. I20, iSCSI, Parallel ports, netlink...
  384. </para>
  385. </sect2>
  386. </sect1>
  387. </chapter>
  388. </book>