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