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" []>
7
<title>SCSI Interfaces Guide</title>
11
<firstname>James</firstname>
12
<surname>Bottomley</surname>
15
<email>James.Bottomley@hansenpartnership.com</email>
21
<firstname>Rob</firstname>
22
<surname>Landley</surname>
25
<email>rob@landley.net</email>
34
<holder>Linux Foundation</holder>
39
This documentation is free software; you can redistribute
40
it and/or modify it under the terms of the GNU General Public
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.
57
<title>Introduction</title>
58
<sect1 id="protocol_vs_bus">
59
<title>Protocol vs bus</title>
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
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.
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
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
84
(<ulink url='http://en.wikipedia.org/wiki/ISCSI'>iSCSI</ulink>), even
85
<ulink url='http://cyberelk.net/tim/parport/parscsi.html'>Parallel
89
<sect1 id="subsystem_design">
90
<title>Design of the Linux SCSI subsystem</title>
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
95
upper layer driver, one lower layer driver, and the SCSI midlayer.
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
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
114
<chapter id="upper_layer">
115
<title>SCSI upper layer</title>
117
The upper layer supports the user-kernel interface by providing
121
<title>sd (SCSI Disk)</title>
122
<para>sd (sd_mod.o)</para>
123
<!-- !Idrivers/scsi/sd.c -->
126
<title>sr (SCSI CD-ROM)</title>
127
<para>sr (sr_mod.o)</para>
130
<title>st (SCSI Tape)</title>
131
<para>st (st.o)</para>
134
<title>sg (SCSI Generic)</title>
135
<para>sg (sg.o)</para>
138
<title>ch (SCSI Media Changer)</title>
139
<para>ch (ch.c)</para>
143
<chapter id="mid_layer">
144
<title>SCSI mid layer</title>
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>
152
!Iinclude/scsi/scsi_device.h
156
<title>drivers/scsi/scsi.c</title>
157
<para>Main file for the SCSI midlayer.</para>
158
!Edrivers/scsi/scsi.c
160
<sect2 id="scsicam.c">
161
<title>drivers/scsi/scsicam.c</title>
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
167
!Edrivers/scsi/scsicam.c
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
174
<sect2 id="scsi_devinfo.c">
175
<title>drivers/scsi/scsi_devinfo.c</title>
177
Manage scsi_dev_info_list, which tracks blacklisted and whitelisted
180
!Idrivers/scsi/scsi_devinfo.c
182
<sect2 id="scsi_ioctl.c">
183
<title>drivers/scsi/scsi_ioctl.c</title>
185
Handle ioctl() calls for SCSI devices.
187
!Edrivers/scsi/scsi_ioctl.c
189
<sect2 id="scsi_lib.c">
190
<title>drivers/scsi/scsi_lib.c</title>
192
SCSI queuing library.
194
!Edrivers/scsi/scsi_lib.c
196
<sect2 id="scsi_lib_dma.c">
197
<title>drivers/scsi/scsi_lib_dma.c</title>
199
SCSI library functions depending on DMA
200
(map and unmap scatter-gather lists).
202
!Edrivers/scsi/scsi_lib_dma.c
204
<sect2 id="scsi_module.c">
205
<title>drivers/scsi/scsi_module.c</title>
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.
211
<sect2 id="scsi_proc.c">
212
<title>drivers/scsi/scsi_proc.c</title>
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.
219
I.E. plumbing to manage /proc/scsi/*
221
!Idrivers/scsi/scsi_proc.c
223
<sect2 id="scsi_netlink.c">
224
<title>drivers/scsi/scsi_netlink.c</title>
226
Infrastructure to provide async events from transports to userspace
227
via netlink, using a single NETLINK_SCSITRANSPORT protocol for all
230
See <ulink url='http://marc.info/?l=linux-scsi&m=115507374832500&w=2'>the
231
original patch submission</ulink> for more details.
233
!Idrivers/scsi/scsi_netlink.c
235
<sect2 id="scsi_scan.c">
236
<title>drivers/scsi/scsi_scan.c</title>
238
Scan a host to determine which (if any) devices are attached.
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.
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.
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.
255
!Idrivers/scsi/scsi_scan.c
257
<sect2 id="scsi_sysctl.c">
258
<title>drivers/scsi/scsi_sysctl.c</title>
260
Set up the sysctl entry: "/dev/scsi/logging_level"
261
(DEV_SCSI_LOGGING_LEVEL) which sets/returns scsi_logging_level.
264
<sect2 id="scsi_sysfs.c">
265
<title>drivers/scsi/scsi_sysfs.c</title>
267
SCSI sysfs interface routines.
269
!Edrivers/scsi/scsi_sysfs.c
272
<title>drivers/scsi/hosts.c</title>
274
mid to lowlevel SCSI driver interface
276
!Edrivers/scsi/hosts.c
278
<sect2 id="constants.c">
279
<title>drivers/scsi/constants.c</title>
281
mid to lowlevel SCSI driver interface
283
!Edrivers/scsi/constants.c
287
<sect1 id="Transport_classes">
288
<title>Transport classes</title>
290
Transport classes are service libraries for drivers in the SCSI
291
lower layer, which expose transport attributes in sysfs.
293
<sect2 id="Fibre_Channel_transport">
294
<title>Fibre Channel transport</title>
296
The file drivers/scsi/scsi_transport_fc.c defines transport attributes
299
!Edrivers/scsi/scsi_transport_fc.c
301
<sect2 id="iSCSI_transport">
302
<title>iSCSI transport class</title>
304
The file drivers/scsi/scsi_transport_iscsi.c defines transport
305
attributes for the iSCSI class, which sends SCSI packets over TCP/IP
308
!Edrivers/scsi/scsi_transport_iscsi.c
310
<sect2 id="SAS_transport">
311
<title>Serial Attached SCSI (SAS) transport class</title>
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.
318
The SAS transport class contains common code to deal with SAS HBAs,
319
an aproximated representation of SAS topologies in the driver model,
320
and various sysfs attributes to expose these topologies and management
321
interfaces to userspace.
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
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.
338
!Edrivers/scsi/scsi_transport_sas.c
340
<sect2 id="SATA_transport">
341
<title>SATA transport class</title>
343
The SATA transport is handled by libata, which has its own book of
344
documentation in this directory.
347
<sect2 id="SPI_transport">
348
<title>Parallel SCSI (SPI) transport class</title>
350
The file drivers/scsi/scsi_transport_spi.c defines transport
351
attributes for traditional (fast/wide/ultra) SCSI busses.
353
!Edrivers/scsi/scsi_transport_spi.c
355
<sect2 id="SRP_transport">
356
<title>SCSI RDMA (SRP) transport class</title>
358
The file drivers/scsi/scsi_transport_srp.c defines transport
359
attributes for SCSI over Remote Direct Memory Access.
361
!Edrivers/scsi/scsi_transport_srp.c
367
<chapter id="lower_layer">
368
<title>SCSI lower layer</title>
369
<sect1 id="hba_drivers">
370
<title>Host Bus Adapter transport types</title>
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
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).
381
<sect2 id="scsi_debug.c">
382
<title>Debug transport</title>
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.
391
To be more realistic, the simulated devices have the transport
392
attributes of SAS disks.
395
For documentation see
396
<ulink url='http://sg.danny.cz/sg/sdebug26.html'>http://sg.danny.cz/sg/sdebug26.html</ulink>
398
<!-- !Edrivers/scsi/scsi_debug.c -->
402
<para>Parallel (fast/wide/ultra) SCSI, USB, SATA,
403
SAS, Fibre Channel, FireWire, ATAPI devices, Infiniband,
404
I20, iSCSI, Parallel ports, netlink...