Documentation/driver-api/scsi.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

SCSI Interfaces Guide

Linux SCSI upper·mid·lower layer, host scan, queue·error·DMA와 FC·iSCSI·SAS·SPI·SRP transport class를 다루는 전문 번역입니다.

Source pathDocumentation/driver-api/scsi.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

scsi.rst:1-336

Linux SCSI subsystem은 userspace device class, command routing과 queue·error·scan을 맡는 mid-layer, hardware HBA를 다루는 lower layer로 구성됩니다. Mid-layer source별 역할과 FC·iSCSI·SAS·SPI·SRP transport attribute, SAS topology object, `scsi_debug` simulation까지 원문 순서대로 정리합니다.

문서 구성
원문 줄내용
1-52SCSI protocol과 3-layer subsystem 설계
53-83Upper-layer device class
84-226Mid-layer core, queue, DMA, scan과 system interface
227-302Transport class와 FC·iSCSI·SAS·SPI·SRP
303-336Lower-layer HBA, scsi_debug과 TODO

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

SCSI Interfaces Guide 문서 정보

1-7

이 문서는 Linux SCSI interface를 안내하며 저자는 James Bottomley와 Rob Landley입니다.

문서 식별 정보
항목
문서SCSI Interfaces Guide
저자James Bottomley, Rob Landley
범위Upper, mid, lower SCSI layer와 transport class

=====================
SCSI Interfaces Guide
=====================

:Author: James Bottomley
:Author: Rob Landley

SCSI protocol과 bus의 분리

8-33

Small Computer Systems Interface는 처음에 host computer와 disk, tape, modem, printer, scanner, optical drive, test equipment, medical device 등 다양한 peripheral을 연결하는 parallel I/O bus와 data protocol을 함께 정의했습니다.

기존 parallel fast/wide/ultra SCSI bus는 대부분 사용되지 않지만, SCSI command set은 여러 bus를 통해 device와 통신하는 protocol로 과거보다 더 널리 쓰입니다.

SCSI protocol은 big-endian peer-to-peer packet protocol입니다. Command 길이는 6, 10, 12 또는 16 byte이며 뒤에 관련 data payload가 이어지는 경우가 많습니다.

SCSI command는 거의 모든 종류의 bus로 운반할 수 있습니다. USB, SATA, SAS, Fibre Channel, FireWire, ATAPI storage device의 기본 protocol이며 Infiniband, TCP/IP의 iSCSI, 심지어 parallel port에서도 SCSI packet을 교환합니다.

SCSI protocol transport
구분
기존 물리 busParallel fast/wide/ultra SCSI
Storage interconnectUSB, SATA, SAS, Fibre Channel, FireWire, ATAPI
Network/RDMAiSCSI over TCP/IP, Infiniband
기타Parallel port

Command set은 특정 물리 bus와 분리되어 다양한 transport 위에서 동작합니다.

Introduction
============

Protocol vs bus
---------------

Once upon a time, the Small Computer Systems Interface defined both a
parallel I/O bus and a data protocol to connect a wide variety of
peripherals (disk drives, tape drives, modems, printers, scanners,
optical drives, test equipment, and medical devices) to a host computer.

Although the old parallel (fast/wide/ultra) SCSI bus has largely fallen
out of use, the SCSI command set is more widely used than ever to
communicate with devices over a number of different buses.

The `SCSI protocol <https://www.t10.org/scsi-3.htm>`__ is a big-endian
peer-to-peer packet based protocol. SCSI commands are 6, 10, 12, or 16
bytes long, often followed by an associated data payload.

SCSI commands can be transported over just about any kind of bus, and
are the default protocol for storage devices attached to USB, SATA, SAS,
Fibre Channel, FireWire, and ATAPI devices. SCSI packets are also
commonly exchanged over Infiniband,
TCP/IP (`iSCSI <https://en.wikipedia.org/wiki/ISCSI>`__), even `Parallel
ports <http://cyberelk.net/tim/parport/parscsi.html>`__.

Linux SCSI 3-layer 설계

34-52

SCSI subsystem은 upper, mid, low의 세 layer로 설계됩니다. Disk sector 읽기 같은 모든 operation은 upper-layer driver 하나, lower-layer driver 하나, SCSI mid-layer를 모두 사용합니다.

Upper layer는 I/O와 `ioctl()`을 위한 block·character device node 형태로 userspace와 kernel 사이 interface를 제공합니다. Lower layer에는 특정 hardware device용 driver가 있습니다.

사이의 SCSI mid-layer는 IPv4 stack 같은 network routing layer와 유사합니다. Upper layer의 `/dev` node와 lower-layer device 사이에서 packet protocol을 route하고 command queue, error handling, power management를 관리하며 `ioctl()` 요청에 응답합니다.

Linux SCSI 3-layer path
UserspaceUpper layer block / char nodeSCSI mid-layerLower-layer hardware driverSCSI device
SCSI mid-layerCommand queues / error handling / power management / ioctl

각 operation은 userspace device class, 공통 mid-layer, hardware-specific lower driver를 모두 통과합니다.

Design of the Linux SCSI subsystem
----------------------------------

The SCSI subsystem uses a three layer design, with upper, mid, and low
layers. Every operation involving the SCSI subsystem (such as reading a
sector from a disk) uses one driver at each of the 3 levels: one upper
layer driver, one lower layer driver, and the SCSI midlayer.

The SCSI upper layer provides the interface between userspace and the
kernel, in the form of block and char device nodes for I/O and ioctl().
The SCSI lower layer contains drivers for specific hardware devices.

In between is the SCSI mid-layer, analogous to a network routing layer
such as the IPv4 stack. The SCSI mid-layer routes a packet based data
protocol between the upper layer's /dev nodes and the corresponding
devices in the lower layer. It manages command queues, provides error
handling and power management functions, and responds to ioctl()
requests.

SCSI upper-layer device class

53-83

Upper layer는 device node를 제공해 user-kernel interface를 지원합니다.

주요 upper driver는 SCSI disk용 `sd`(`sd_mod.o`), CD-ROM용 `sr`(`sr_mod.o`), tape용 `st`(`st.o`), generic command용 `sg`(`sg.o`), media changer용 `ch`(`ch.c`)입니다.

SCSI upper driver
DriverDevice classModule/source
`sd`SCSI Disk`sd_mod.o`
`sr`SCSI CD-ROM`sr_mod.o`
`st`SCSI Tape`st.o`
`sg`SCSI Generic`sg.o`
`ch`SCSI Media Changer`ch.c`

SCSI upper layer
================

The upper layer supports the user-kernel interface by providing device
nodes.

sd (SCSI Disk)
--------------

sd (sd_mod.o)

sr (SCSI CD-ROM)
----------------

sr (sr_mod.o)

st (SCSI Tape)
--------------

st (st.o)

sg (SCSI Generic)
-----------------

sg (sg.o)

ch (SCSI Media Changer)
-----------------------

ch (ch.c)

Mid-layer core structure와 main file

84-103

SCSI mid-layer 구현의 device abstraction은 `include/scsi/scsi_device.h`에 있으며 kernel-doc은 internal declaration을 가져옵니다.

`drivers/scsi/scsi.c`는 SCSI mid-layer의 main file이며 exported function을 문서화합니다.

Mid-layer core source
Source path역할Kernel-doc
`include/scsi/scsi_device.h`SCSI device structure`:internal:`
`drivers/scsi/scsi.c`Mid-layer main file`:export:`

SCSI mid layer
==============

SCSI midlayer implementation
----------------------------

include/scsi/scsi_device.h
~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. kernel-doc:: include/scsi/scsi_device.h
   :internal:

drivers/scsi/scsi.c
~~~~~~~~~~~~~~~~~~~

Main file for the SCSI midlayer.

.. kernel-doc:: drivers/scsi/scsi.c
   :export:

CAM support와 error handling

104-121

`drivers/scsi/scsicam.c`는 `HDIO_GETGEO` 등에 사용하는 SCSI Common Access Method(CAM) support function을 제공하며 exported API를 문서화합니다.

`drivers/scsi/scsi_error.c`는 공통 SCSI error와 timeout handling routine을 제공하며 exported API를 문서화합니다.

CAM과 error source
Source path기능
`drivers/scsi/scsicam.c`CAM geometry support, `HDIO_GETGEO` 등
`drivers/scsi/scsi_error.c`공통 error·timeout 처리

drivers/scsi/scsicam.c
~~~~~~~~~~~~~~~~~~~~~~

`SCSI Common Access
Method <http://www.t10.org/ftp/t10/drafts/cam/cam-r12b.pdf>`__ support
functions, for use with HDIO_GETGEO, etc.

.. kernel-doc:: drivers/scsi/scsicam.c
   :export:

drivers/scsi/scsi_error.c
~~~~~~~~~~~~~~~~~~~~~~~~~~

Common SCSI error/timeout handling routines.

.. kernel-doc:: drivers/scsi/scsi_error.c
   :export:

Device info, ioctl과 queue library

122-145

`drivers/scsi/scsi_devinfo.c`는 blacklist와 whitelist device를 추적하는 `scsi_dev_info_list`를 관리합니다.

`drivers/scsi/scsi_ioctl.c`는 SCSI device의 `ioctl()` call을 처리하고, `drivers/scsi/scsi_lib.c`는 SCSI queuing library를 제공합니다. 세 file의 exported API를 kernel-doc으로 가져옵니다.

Mid-layer 관리 source
Source path역할
`drivers/scsi/scsi_devinfo.c`Blacklist·whitelist device tracking
`drivers/scsi/scsi_ioctl.c`SCSI device `ioctl()` 처리
`drivers/scsi/scsi_lib.c`Command queuing library

drivers/scsi/scsi_devinfo.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Manage scsi_dev_info_list, which tracks blacklisted and whitelisted
devices.

.. kernel-doc:: drivers/scsi/scsi_devinfo.c
   :export:

drivers/scsi/scsi_ioctl.c
~~~~~~~~~~~~~~~~~~~~~~~~~~

Handle ioctl() calls for SCSI devices.

.. kernel-doc:: drivers/scsi/scsi_ioctl.c
   :export:

drivers/scsi/scsi_lib.c
~~~~~~~~~~~~~~~~~~~~~~~~

SCSI queuing library.

.. kernel-doc:: drivers/scsi/scsi_lib.c
   :export:

DMA mapping과 /proc/scsi

146-165

`drivers/scsi/scsi_lib_dma.c`는 scatter-gather list의 map·unmap처럼 DMA에 의존하는 SCSI library function을 제공합니다.

`drivers/scsi/scsi_proc.c`의 function은 PROC filesystem과 SCSI device driver 사이 interface를 제공합니다. 주로 debugging, statistics, low-level driver에 직접 정보 전달을 위해 사용하며 `/proc/scsi/*`를 관리하는 plumbing입니다.

DMA와 proc interface
Source path역할Kernel-doc
`drivers/scsi/scsi_lib_dma.c`DMA scatter-gather map·unmap`:export:`
`drivers/scsi/scsi_proc.c``/proc/scsi/*` 관리File documentation


drivers/scsi/scsi_lib_dma.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SCSI library functions depending on DMA (map and unmap scatter-gather
lists).

.. kernel-doc:: drivers/scsi/scsi_lib_dma.c
   :export:

drivers/scsi/scsi_proc.c
~~~~~~~~~~~~~~~~~~~~~~~~~

The functions in this file provide an interface between the PROC file
system and the SCSI device drivers It is mainly used for debugging,
statistics and to pass information directly to the lowlevel driver. I.E.
plumbing to manage /proc/scsi/\*

.. kernel-doc:: drivers/scsi/scsi_proc.c

Host scan과 LUN 탐색

178-196

`drivers/scsi/scsi_scan.c`는 host에 연결된 device를 탐색합니다. 일반 algorithm은 device-specific flag, compile option, boot 또는 module load 시점의 global setting에 따라 예외가 생길 수 있습니다.

특정 LUN은 `INQUIRY` command로 scan하며 device가 있으면 `scsi_device`를 allocate하고 설정합니다. Host의 각 channel·ID에서 LUN 0부터 scan하고, LUN 0 scan에 전혀 응답하지 않는 host는 건너뜁니다.

LUN 0에 device가 있으면 `scsi_device`를 준비합니다. Target이 SCSI-3 이상이면 `REPORT LUN`을 발행해 반환된 모든 LUN을 scan합니다. 그보다 낮으면 maximum에 도달하거나 device를 붙일 수 없는 LUN이 나타날 때까지 LUN을 순차적으로 scan합니다.

SCSI host scan algorithm
Each channel and target IDINQUIRY LUN 0No responseSkip target
LUN 0 device foundAllocate `scsi_device`SCSI-3 or newer`REPORT LUN`Scan returned LUNs
LUN 0 device foundOlder targetSequential LUN scanMaximum or impossible LUN

LUN 0 응답과 target revision에 따라 REPORT LUN 또는 sequential scan 경로를 선택합니다.

drivers/scsi/scsi_scan.c
~~~~~~~~~~~~~~~~~~~~~~~~~

Scan a host to determine which (if any) devices are attached. The
general scanning/probing algorithm is as follows, exceptions are made to
it depending on device specific flags, compilation options, and global
variable (boot or module load time) settings. A specific LUN is scanned
via an INQUIRY command; if the LUN has a device attached, a scsi_device
is allocated and setup for it. For every id of every channel on the
given host, start by scanning LUN 0. Skip hosts that don't respond at
all to a scan of LUN 0. Otherwise, if LUN 0 has a device attached,
allocate and setup a scsi_device for it. If target is SCSI-3 or up,
issue a REPORT LUN, and scan all of the LUNs returned by the REPORT LUN;
else, sequentially scan LUNs up until some maximum is reached, or a LUN
is seen that cannot have a device attached to it.

.. kernel-doc:: drivers/scsi/scsi_scan.c
   :export:

Logging, sysfs와 host interface

197-226

`drivers/scsi/scsi_sysctl.c`는 `scsi_logging_level`을 설정하거나 반환하는 sysctl entry `/dev/scsi/logging_level`(`DEV_SCSI_LOGGING_LEVEL`)을 준비합니다.

`drivers/scsi/scsi_sysfs.c`는 SCSI sysfs interface routine을, `drivers/scsi/hosts.c`는 mid-layer와 low-level SCSI driver 사이 interface를, `drivers/scsi/scsi_common.c`는 일반 support function을 제공합니다.

Mid-layer system interface
Source path역할
`drivers/scsi/scsi_sysctl.c``scsi_logging_level` sysctl
`drivers/scsi/scsi_sysfs.c`SCSI sysfs interface
`drivers/scsi/hosts.c`Mid-to-low-level driver interface
`drivers/scsi/scsi_common.c`General support function

drivers/scsi/scsi_sysctl.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Set up the sysctl entry: "/dev/scsi/logging_level"
(DEV_SCSI_LOGGING_LEVEL) which sets/returns scsi_logging_level.

drivers/scsi/scsi_sysfs.c
~~~~~~~~~~~~~~~~~~~~~~~~~~

SCSI sysfs interface routines.

.. kernel-doc:: drivers/scsi/scsi_sysfs.c
   :export:

drivers/scsi/hosts.c
~~~~~~~~~~~~~~~~~~~~

mid to lowlevel SCSI driver interface

.. kernel-doc:: drivers/scsi/hosts.c
   :export:

drivers/scsi/scsi_common.c
~~~~~~~~~~~~~~~~~~~~~~~~~~

general support functions

.. kernel-doc:: drivers/scsi/scsi_common.c
   :export:

Transport class와 Fibre Channel

227-241

Transport class는 SCSI lower-layer driver를 위한 service library이며 transport attribute를 sysfs에 노출합니다.

`drivers/scsi/scsi_transport_fc.c`는 Fibre Channel transport attribute를 정의하고 exported API를 제공합니다.

SCSI transport class 역할
Lower-layer driverTransport service libraryTransport attributessysfsUserspace
Fibre Channel`scsi_transport_fc.c`

Transport-specific library가 lower driver의 topology와 attribute를 공통 sysfs model로 노출합니다.

Transport classes
-----------------

Transport classes are service libraries for drivers in the SCSI lower
layer, which expose transport attributes in sysfs.

Fibre Channel transport
~~~~~~~~~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_transport_fc.c defines transport attributes
for Fibre Channel.

.. kernel-doc:: drivers/scsi/scsi_transport_fc.c
   :export:

iSCSI transport class

242-251

`drivers/scsi/scsi_transport_iscsi.c`는 TCP/IP connection으로 SCSI packet을 보내는 iSCSI class의 transport attribute를 정의합니다.

iSCSI transport
항목내용
Source`drivers/scsi/scsi_transport_iscsi.c`
PayloadSCSI packet
ConnectionTCP/IP
Kernel-doc`:export:`

iSCSI transport class
~~~~~~~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_transport_iscsi.c defines transport
attributes for the iSCSI class, which sends SCSI packets over TCP/IP
connections.

.. kernel-doc:: drivers/scsi/scsi_transport_iscsi.c
   :export:

SAS transport topology model

252-278

`drivers/scsi/scsi_transport_sas.c`는 대형 high-end system을 대상으로 한 SATA variant인 Serial Attached SCSI의 transport attribute를 정의합니다.

SAS transport class는 SAS HBA를 다루는 공통 code, driver model 안의 근사 SAS topology 표현, topology와 management interface를 userspace에 노출하는 여러 sysfs attribute를 포함합니다.

기본 SCSI core object 외에 두 intermediate object를 추가합니다. `struct sas_phy`의 SAS PHY는 HBA 또는 expander의 outgoing PHY를, `struct sas_rphy`의 SAS remote PHY는 expander 또는 end device의 incoming PHY를 나타냅니다. 이는 순수 software concept이며 PHY와 remote PHY의 실제 hardware는 완전히 같습니다.

이 code에는 SAS port object 개념이 없습니다. 사용자는 같은 port의 모든 PHY가 공유하는 `port_identifier` attribute로 wide port를 구성하는 PHY를 알 수 있습니다.

SAS software topology
SAS HBA / Expander`struct sas_phy` outgoing PHYSAS link`struct sas_rphy` incoming PHYExpander / end device
PHYs with same `port_identifier`Wide port membership
Physical PHYSame hardware behind PHY and remote PHY

동일한 물리 PHY를 방향별 software object로 표현하고 port_identifier로 wide port membership을 노출합니다.

Serial Attached SCSI (SAS) transport class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_transport_sas.c defines transport
attributes for Serial Attached SCSI, a variant of SATA aimed at large
high-end systems.

The SAS transport class contains common code to deal with SAS HBAs, an
approximated representation of SAS topologies in the driver model, and
various sysfs attributes to expose these topologies and management
interfaces to userspace.

In addition to the basic SCSI core objects this transport class
introduces two additional intermediate objects: The SAS PHY as
represented by struct sas_phy defines an "outgoing" PHY on a SAS HBA or
Expander, and the SAS remote PHY represented by struct sas_rphy defines
an "incoming" PHY on a SAS Expander or end device. Note that this is
purely a software concept, the underlying hardware for a PHY and a
remote PHY is the exactly the same.

There is no concept of a SAS port in this code, users can see what PHYs
form a wide port based on the port_identifier attribute, which is the
same for all PHYs in a port.

.. kernel-doc:: drivers/scsi/scsi_transport_sas.c
   :export:

SATA와 Parallel SCSI transport

279-293

SATA transport는 libata가 처리하며 이 directory에 별도의 documentation book이 있습니다.

`drivers/scsi/scsi_transport_spi.c`는 전통적인 fast/wide/ultra SCSI bus의 Parallel SCSI(SPI) transport attribute를 정의하고 exported API를 제공합니다.

SATA와 SPI
Transport구현·문서
SATALibata와 별도 documentation
Parallel SCSI(SPI)`drivers/scsi/scsi_transport_spi.c`

SATA transport class
~~~~~~~~~~~~~~~~~~~~

The SATA transport is handled by libata, which has its own book of
documentation in this directory.

Parallel SCSI (SPI) transport class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_transport_spi.c defines transport
attributes for traditional (fast/wide/ultra) SCSI buses.

.. kernel-doc:: drivers/scsi/scsi_transport_spi.c
   :export:

SCSI RDMA transport

294-302

`drivers/scsi/scsi_transport_srp.c`는 Remote Direct Memory Access 위에서 SCSI를 운반하는 SCSI RDMA(SRP) transport attribute를 정의합니다.

SRP transport
항목내용
Source`drivers/scsi/scsi_transport_srp.c`
ProtocolSCSI RDMA Protocol
TransportRemote Direct Memory Access
Kernel-doc`:export:`

SCSI RDMA (SRP) transport class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_transport_srp.c defines transport
attributes for SCSI over Remote Direct Memory Access.

.. kernel-doc:: drivers/scsi/scsi_transport_srp.c
   :export:

SCSI lower layer와 HBA

303-316

많은 현대 device controller는 여러 종류의 물리 connection을 통해 device와 통신할 때 SCSI command set을 protocol로 사용합니다.

SCSI 용어에서 SCSI command를 운반할 수 있는 bus를 transport라 하고, 그런 bus에 연결되는 controller를 host bus adapter(HBA)라고 합니다.

Lower-layer transport 용어
SCSI lower-layer driverHost bus adapter (HBA)TransportPhysical connectionDevice

Hardware-specific HBA가 물리 connection을 통해 SCSI command transport에 연결됩니다.

SCSI lower layer
================

Host Bus Adapter transport types
--------------------------------

Many modern device controllers use the SCSI command set as a protocol to
communicate with their devices through many different types of physical
connections.

In SCSI language a bus capable of carrying SCSI commands is called a
"transport", and a controller connecting to such a bus is called a "host
bus adapter" (HBA).

scsi_debug simulated host

317-330

`drivers/scsi/scsi_debug.c`는 공통 RAM 영역을 공유하는 가변 개수의 disk 또는 disk-like device가 연결된 host adapter를 simulation합니다.

Block이 섞이지 않는지 광범위하게 검사하며 이상한 상태가 보이면 kernel panic을 발생시킵니다. 더 현실적인 simulation을 위해 device는 SAS disk transport attribute를 가집니다.

추가 문서는 `http://sg.danny.cz/sg/scsi_debug.html`을 참조합니다.

`scsi_debug` model
`scsi_debug` host adapterVariable simulated disksShared RAMBlock consistency checks
Unexpected conditionKernel panic
Simulated devicesSAS disk transport attributes

가상 HBA와 여러 disk가 공통 RAM을 사용하며 consistency check로 비정상 block mapping을 검출합니다.

Debug transport
~~~~~~~~~~~~~~~

The file drivers/scsi/scsi_debug.c simulates a host adapter with a
variable number of disks (or disk like devices) attached, sharing a
common amount of RAM. Does a lot of checking to make sure that we are
not getting blocks mixed up, and panics the kernel if anything out of
the ordinary is seen.

To be more realistic, the simulated devices have the transport
attributes of SAS disks.

For documentation see http://sg.danny.cz/sg/scsi_debug.html

문서화 TODO

331-336

추가 문서화가 필요한 항목으로 parallel fast/wide/ultra SCSI, USB, SATA, SAS, Fibre Channel, FireWire, ATAPI, Infiniband, parallel port와 netlink가 나열되어 있습니다.

TODO transport와 interface
분류대상
Storage busParallel SCSI, USB, SATA, SAS, Fibre Channel
기타 interconnectFireWire, ATAPI, Infiniband, Parallel port
MessagingNetlink

todo
~~~~

Parallel (fast/wide/ultra) SCSI, USB, SATA, SAS, Fibre Channel,
FireWire, ATAPI devices, Infiniband, Parallel ports,
netlink...