See reference W4 for the SCSI Generic (sg) driver documentation (also found there is the sg_utils package). For SCSI standards see reference W1 and for a book on the subject of SCSI programming and pass through mechanisms see reference B3.
The sg driver in lk 2.4 is "version 3" which adds an additional interface structure and some new ioctl()s. The most interesting new ioctl() is SG_IO which sends a SCSI command and waits for its response. See the Linux Documentation Project site: www.linuxdoc.org/HOWTO/SCSI-Generic-HOWTO/ for a full description of the sg driver. A (possibly later) version of this document can be found at www.torque.net/sg/p/sg_v3_ho.html.
The abbreviation "sg" is used within the kernel to refer both to the SCSI generic driver and the scatter-gather capability offered by many modern IO devices (usually associated with DMA). The context usually makes it clear which one is being referred to. As an example, note the contorted sg ioctl() named SG_GET_SG_TABLESIZE where the second "SG" refers to scatter gather.
The public interface for sg is found in the file: /usr/src/linux/include/scsi/sg.h. Depending on the distribution this may or may not contain the same information as /usr/include/scsi/sg.h which is controlled by the GNU library maintainers. If these 2 files are not the same use the former header file. Those writing applications based on sg should see its documentation for more on this matter.
The sg driver registers all SCSI devices (with a current maximum of 256) as they are seen. Each newly registered SCSI device gets allocated the next available minor device number. At least initially this will be the same sequence that devices are displayed in mid level's cat /proc/scsi/scsi. The sg devices device mapping can been seen with cat /proc/scsi/sg/devices or cat /proc/scsi/sg/device_strs. Differences between cat /proc/scsi/scsi and sg orderings will appear when a low level driver is removed (e.g. rmmod aha1542) or when a device is removed with remove-single-device. The sg driver will leave remaining SCSI device mapping to minor device numbers unchanged. This potentially leaves a "hole" in the sg mapping. An example follows:
$ cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: IBM Model: DNES-309170W Rev: SA30 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi1 Channel: 00 Id: 02 Lun: 00 Vendor: PIONEER Model: DVD-ROM DVD-303 Rev: 1.10 Type: CD-ROM ANSI SCSI revision: 02 Host: scsi1 Channel: 00 Id: 06 Lun: 00 Vendor: YAMAHA Model: CRW4416S Rev: 1.0g Type: CD-ROM ANSI SCSI revision: 02 $ cat /proc/scsi/sg/device_strs IBM DNES-309170W SA30 PIONEER DVD-ROM DVD-303 1.10 YAMAHA CRW4416S 1.0g $ echo "scsi remove-single-device 1 0 2 0" > /proc/scsi/scsi $ cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: IBM Model: DNES-309170W Rev: SA30 Type: Direct-Access ANSI SCSI revision: 03 Host: scsi1 Channel: 00 Id: 06 Lun: 00 Vendor: YAMAHA Model: CRW4416S Rev: 1.0g Type: CD-ROM ANSI SCSI revision: 02 $ cat /proc/scsi/sg/device_strs IBM DNES-309170W SA30 <no active device> YAMAHA CRW4416S 1.0g |
The new sg_io_hdr interface includes a data transfer residual count field called "resid". Only some lower level adapters support this feature and those that don't always yield zero in this field. At the time of writing the advansys, aha152x and the sym53c8xx drivers support this feature.
The SG_DEF_RESERVED_SIZE define value can be overridden by this kernel boot option:
sg_def_reserved_size=<n> |
def_reserved_size=<n> |
/proc/scsi/sg/debug [internal state of sg driver] /proc/scsi/sg/def_reserved_size [like boot/module load parameter] /proc/scsi/sg/devices [table of numeric device data] /proc/scsi/sg/device_hdr [column headers for sg/devices] /proc/scsi/sg/device_strs [table of strings from INQUIRY] /proc/scsi/sg/hosts [table of numeric host data] /proc/scsi/sg/host_hdr [column headers for sg/hosts] /proc/scsi/sg/host_strs [table of string ids for hosts] /proc/scsi/sg/version [sg version number and date] |