The Linux SG driver is a high level SCSI subsystem device driver that is
used to handle devices _not_ covered by the other high level drivers: sd
(disks), st (tapes) and sr (CDROMs). The sg driver is used by scanners, cd
writers and applications that read cd audio digitally. It is also a character
device which gives it some advantages over the other 3 block devices in some
contexts.
The original driver was written by Lawrence Foard and in recent years has seldom been changed. In August 1998 Heiko Eissfeldt and Joerg Schilling (author of cdrecord) started working on enhancements to this driver. Soon after the author became involved and these efforts culminated in a new sg driver being placed in Linux kernel 2.2.6 which was released by Linus Torvalds on 16th April 1999. It contains the first major upgrade to the SCSI generic packet device driver ("sg") since 1992. This new driver has a super-set of the original interface and the semantics of the implementation are very similar. Hence it offers a high degree of backward compatibility with the original driver.
The major reason for introducing a new sg driver into the 2.2 series of kernels was the problem that the original device driver was having finding memory. This driver improves the situation by using scatter gather, memory above the 16 Mbytes level and memory from the scsi dma pool as appropriate. Other drivers were effected by these memory problems (especially those associated with ISA hardware). In kernel 2.2.10 H.J. Lu introduced a new kernel memory allocator that alleviated many of these memory problems.
The following enhancements have been added: scatter gather, command queuing, per file descriptor sequencing (was per device) and asynchronous notification. Scatter gather allows large buffers (previously limited to 128 KB on i386) to be used. Scatter gather is also a lot more "kernel friendly". The original driver used a single large buffer which made it impossible to run 2 or more sg-based applications at the same time. With the new driver a buffer is reserved for each file descriptor.
A "version 3" sg driver is now available. It adds a new interface that allows more control over SCSI commands and returns more information about their performance. This driver is targeted at the 2.3 series of development kernels hopefully to be present when 2.4 is released. A separate version with reduced capabilities is available for the 2.2 series kernels. Features include: larger sense buffer, residual DMA count, direct IO support, command duration timing and "proc_fs" interface.
The following table summarizes the different versions of the sg device driver
that are available. If you wish to use one of these tarballs then untar it in
/usr/src/linux (or wherever the top of your kernel tree is). As a precaution you
may wish to copy the files include/scsi/sg.h and drivers/scsi/sg.c to other
names. This will facilitate reversing the patch if required. For information
about the differences between versions see the history section at the top of the
include/scsi/sg.h file.
Linux version | Sg driver version+tarball |
Patch | Notes |
<= 2.2.6 | sg22orig.tgz | found in RH6.0, original documentation | |
2.2.6 + 2.2.7 | sg2131.tgz | pat_sg2134_225.gz | |
2.2.8 + 2.2.9 | sg2132.tgz | ||
2.2.10 -> 2.2.13 | sg2134.tgz | patch | |
2.2.14 (current) | sg2136.tgz | patch on sg version 2.1.34 | for documentation + utilities see bullet list |
2.3.39 + 2.3.40 | sg2335in2339.tgz | roughly equivalent to sg version 2.1.34 | |
optional 2.2 series | sg version 3.0.10 | sg version 3 extras in cell below | |
candidate 2.3 series | sg version 3.1.10 | patch on lk 2.3.40 | utilities, documentation and notes |
The current production version of the sg driver (2.1.36) cures some SMP problems that people have had and at least one oops. This version is applicable to the 2.2 series of kernels (but not the 2.3 series).
Older versions can be obtained from this directory. A sub directory called "original" contains the original driver (i.e. prior to linux kernel 2.2.6) and its HOWTO document. Following are some links to related pages on this site:
Douglas Gilbert can be emailed
at this address.
Last updated: 27th January 2000,
20:00