Commit 54e3e213 authored by Douglas Gilbert's avatar Douglas Gilbert Committed by James Bottomley

[update] scsi_mid_low_api.txt

Here is another version of the scsi_mid_low_api.txt
document. It adds descriptions of functions supplied
by the mid level for a LLD (lower level driver) to call.
It is also tries to describe the two, alternate
registration scenarios. How do the terms:
"hotplug initialization model" and "passive
initialization model" sound?
parent 6617da58
Linux Kernel 2.5 series Linux Kernel 2.5 series
SCSI mid_level - lower_level interface SCSI mid_level - lower_level driver interface
====================================== =============================================
Introduction Introduction
============ ============
This document outlines the interface between the Linux scsi mid level This document outlines the interface between the Linux SCSI mid level and
and lower level drivers. Lower level drivers are variously called HBA SCSI lower level drivers. Lower level drivers (LLDs) are variously called
(host bus adapter) drivers, host drivers (HD) or pseudo adapter drivers. host bus adapter (HBA) drivers, host drivers (HD) or pseudo adapter drivers.
The latter alludes to the fact that a lower level driver may be a The latter alludes to the fact that a LLD may be a bridge to another IO
bridge to another IO subsystem (and the "ide-scsi" driver is an example subsystem (e.g. the "usb-storage" driver). There can be many LLDs in a
of this). There can be many lower level drivers active in a running running system, but only one per hardware type. Most LLDs can control one
system, but only one per hardware type. For example, the aic7xxx driver or more SCSI hosts.
controls adaptec controllers based on the 7xxx chip series. Most lower
level drivers can control one or more scsi hosts (a.k.a. scsi initiators). For example, the aic7xxx LLD controls Adaptec SCSI parallel interface
(SPI) controllers based on that company's 7xxx chip series. The aic7xxx
LLD can be built into the kernel or loaded as a module. There can only be
one aic7xxx LLD running in a Linux system but it may be controlling many
HBAs. These HBAs might be either on PCI daughterboards or built into
the motherboard (or both). Like most modern HBAs, each aic7xxx host
has its own PCI device address. [The one-to-one correspondance between
a SCSI host and a PCI device is common but not required (e.g. with
ISA or MCA adapters).]
The Linux kernel source Documentation/DocBook/scsidrivers.tmpl file The Linux kernel source Documentation/DocBook/scsidrivers.tmpl file
refers to this file. With the appropriate DocBook toolset, this permits refers to this file. With the appropriate DocBook toolset, this permits
users to generate html, ps and pdf renderings of information within this users to generate html, ps and pdf renderings of information within this
file (e.g. the interface functions). file (e.g. the interface functions).
This version of the document was written in the period when lk 2.5.47
was current.
Driver structure Driver structure
================ ================
Traditionally a lower level driver for the scsi subsystem has been Traditionally a LLD for the SCSI subsystem has been at least two files in
at least two files in the drivers/scsi directory. For example, a the drivers/scsi directory. For example, a driver called "xyz" has a header
driver called "xyz" has a header file "xyz.h" and a source file file "xyz.h" and a source file "xyz.c". [Actually there is no good reason
"xyz.c". [Actually there is no good reason why this couldn't all why this couldn't all be in one file.] Some drivers that have been ported
be in one file.] Some drivers that have been ported to several operating to several operating systems have more than two files. For example the
systems (e.g. aic7xxx which has separate files for generic and aic7xxx driver has separate files for generic and OS-specific code
OS-specific code) have more than two files. Such drivers tend to have (e.g. FreeBSD and Linux). Such drivers tend to have their own directory
their own directory under the drivers/scsi directory. under the drivers/scsi directory.
scsi_module.c is normally included at the end of a lower When a new LLD is being added to Linux, the following files (found in the
level driver. For it to work a declaration like this is needed before drivers/scsi directory) will need some attention: Makefile, Config.help and
Config.in . SCSI documentation is in the process of being moved to the
Documentation/scsi directory in the kernel source tree. It is probably best
to study how existing LLDs are organized.
As the 2.5 series development kernels evolve, changes are being
introduced into this interface. An example of this is driver
initialization code where there are now 2 models available. The older
one, similar to what was found in the lk 2.4 series, is based on hosts
that are detected at HBA driver load time. This will be referred to
the "passive" initialization model. The newer model allows HBAs to be
hotplugged (and unplugged) while the driver is loaded and will be
referred to as the "hotplug" initialization model. The newer model is
preferred as it can handle both traditional SCSI equipment that is
permanently connected as well as modern "SCSI" usb-storage devices
(e.g. digital cameras) that are hotplugged. Both initialization models
are discussed in the following sections.
A LLD interfaces to the SCSI subsystem several ways:
a) directly invoking functions supplied by the mid level
b) passing a set of function pointers to a registration function
supplied by the mid level. The mid level will then invoke these
functions at some point in the future
c) direct access to instances of well known data structures maintained
by the mid level
Those functions in group a) are listed in a section entitled "Mid level
supplied functions" below.
Those functions in group b) are listed in a section entitled "Interface
functions" below. The function pointers are placed in the members of
"struct SHT", an instance of which is passed to scsi_register() [or
scsi_register_host() in the passive initialization model]. Those interface
functions that are not mandatory and that the LLD does
not wish to supply should have NULL placed in the corresponding member
of struct SHT. [Defining an instance of struct SHT at file scope will
cause NULL to be placed in function pointer members not explicitly
initialized.]
Those instances in group c) are slowly being removed as they tend to be
"racy" especially in a hotplug environment.
Hotplug initialization model
============================
In this model a LLD controls when SCSI hosts are introduced
and removed from the SCSI subsystem. Hosts can be introduced as early as
driver initialization and removed as late as driver shutdown. Typically
a driver will respond to a sysfs probe() callback that indicates a
HBA is present (e.g. a PCI device). After confirming it is a device that
it wants to control, it will initialize the HBA and then register a new
host with the SCSI mid level.
Hot unplugging a HBA that controls a disk which is processing SCSI
commands on a mounted file system is an ugly situation. Issues with
this scenario are still being worked through. The primary concern in
the stability of the kernel (specifically the block and SCSI subsystems)
since the effected disk can be "cleaned up" the next time it is seen.
During LLD initialization the driver should register
itself with the appropriate IO bus that it expects to find HBA(s)
(e.g. the PCI bus). This can probably be done via sysfs (formerly known
as driverfs). Any driver parameters (especially those that are writeable
after the driver is loaded) could also be registered with sysfs at
this point. At the end of driver initialization the SCSI mid level is
typically not aware of its presence.
At some later time, the LLD becomes aware of a HBA and what follows
is a typical sequence of calls (for 3 discovered SCSI devices)
between the LLD and the mid level.
LLD mid level LLD
--- --------- ---
scsi_register() -->
scsi_add_host() --------+
|
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
The invocation of scsi_adjust_queue_depth() by the LLD is optional.
Here is the corresponding sequence when a host (HBA) is being
removed:
LLD mid level
--- ---------
scsi_remove_host() -----+
|
slave_detach()
slave_detach()
slave_detach()
scsi_unregister() -->
It is practical for a LLD to keep track of struct Scsi_Host instances
(a pointer is returned by scsi_register() ) and struct scsi_device
instances (a pointer is passed as the parameter to slave_attach() ).
Both classes of instances are "owned" by the mid-level. struct scsi_devices
instances are freed after slave_detach(). struct Scsi_Host instances
are freed after scsi_unregister().
Passive initialization model
============================
LLD initialization (both built-in and module) and shutdown and "wired
up" by passing function pointers to the module_init() and module_exit()
macros respectively. In this model the function identified by "module_init"
must call scsi_register_host() and the function identified by "module_exit"
must call scsi_unregister_host().
Most LLDs inherited from the lk 2.4 series include a file called
"scsi_module.c" [yes the ".c" is a little surprising] in their
source code. For it to work a declaration like this is needed before
it is included: it is included:
static struct SHT driver_template = DRIVER_TEMPLATE; static struct SHT driver_template = DRIVER_TEMPLATE;
#include "scsi_module.c" #include "scsi_module.c"
...@@ -39,19 +161,57 @@ it is included: ...@@ -39,19 +161,57 @@ it is included:
In this case "DRIVER_TEMPLATE" is defined to be a structure initializer In this case "DRIVER_TEMPLATE" is defined to be a structure initializer
that is placed in the driver header file by convention. It contains that is placed in the driver header file by convention. It contains
pointers to supported interface functions and other values. pointers to supported interface functions and other values.
struct SHT is defined in hosts.h .
The scsi_module.c assumes the name "driver_template" is appropriately Here is an example of an initialization sequence when two hosts are
defined. scsi_module.c contains 2 functions: detected (so detect() returns 2) and the SCSI bus scan on each host
1) init_this_scsi_driver() called during builtin and module driver finds 3 SCSI devices.
initialization: invokes mid level's scsi_register_host()
2) exit_this_scsi_driver() called during closedown: invokes LLD mid level LLD
mid level's scsi_unregister_host() --- --------- ---
scsi_register_host() -------+
|
detect() -----------------+
| |
| scsi_register()
| scsi_register()
|
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
|
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
slave_attach() --> scsi_adjust_queue_depth()
If the LLD does not supply a slave_attach() then the mid level invokes
scsi_adjust_queue_depth() itself with tagged queuing off and "cmd_per_lun"
for that host as the third parameter.
Here is a LLD shutdown sequence:
LLD mid level LLD
--- --------- ---
scsi_unregister_host() -----+
|
slave_detach()
slave_detach()
slave_detach()
release() --> scsi_unregister()
|
slave_detach()
slave_detach()
slave_detach()
release() --> scsi_unregister()
Both slave_detach() and release() are optional. If they are not supplied
the mid level supplies default actions.
The shortcoming of the "passive initialization model" is that host
registration and de-registration are (typically) tied to LLD initialization
and shutdown. Once the LLD is initialized then a new host that appears
(e.g. via hotplugging) cannot easily be added without a redundant
driver shutdown and re-initialization.
When a new, lower level driver is being added to Linux, the following
files (all found in the drivers/scsi directory) will need some attention:
Makefile, Config.help and Config.in . It is probably best to look at what
an existing lower level driver does in this regard.
Conventions Conventions
=========== ===========
...@@ -59,7 +219,7 @@ First there is Linus's thoughts on C coding found in file ...@@ -59,7 +219,7 @@ First there is Linus's thoughts on C coding found in file
Documentation/CodingStyle . Documentation/CodingStyle .
Next there is a movement to "outlaw" typedefs introducing synonyms for Next there is a movement to "outlaw" typedefs introducing synonyms for
struct tags. Both can be still found in the scsi subsystem, for example: struct tags. Both can be still found in the SCSI subsystem, for example:
"typedef struct SHT { ...} Scsi_Host_Template;" in hosts.h . In this "typedef struct SHT { ...} Scsi_Host_Template;" in hosts.h . In this
case "struct SHT" is preferred to "Scsi_Host_Template". case "struct SHT" is preferred to "Scsi_Host_Template".
...@@ -68,26 +228,265 @@ by the relevant gcc compilers. So "//" style comments are encouraged ...@@ -68,26 +228,265 @@ by the relevant gcc compilers. So "//" style comments are encouraged
were appropriate as are C99 style structure and array initializers. were appropriate as are C99 style structure and array initializers.
Mid level supplied functions
============================
These functions are supplied by the SCSI mid level for use by LLDs.
The names (i.e. entry points) of these functions are exported
so a LLD that is a module can access them when the SCSI
mid level is built into the kernel. The kernel will arrange for the
SCSI mid level to be loaded and initialized before any LLD
is initialized. The functions below are listed alphabetically and their
names all start with "scsi_".
/**
* scsi_add_host - perform sysfs registration and SCSI bus scan.
* @shost: pointer to scsi host instance
*
* Returns 0 on success, negative errno of failure (e.g. -ENOMEM)
*
* Notes: Only required in "hotplug initialization model" after a
* successful call to scsi_register().
* Defined in drivers/scsi/hosts.c
**/
int scsi_add_host(struct Scsi_Host *shost)
/**
* scsi_adjust_queue_depth - change the queue depth on a SCSI device
* @SDpnt: pointer to SCSI device to change queue depth on
* @tagged: 0 - no tagged queueing
* MSG_SIMPLE_TAG - simple (unordered) tagged queueing
* MSG_ORDERED_TAG - ordered tagged queueing
* @tags Number of tags allowed if tagged queueing enabled,
* or number of commands the LLD can queue up
* in non-tagged mode (as per cmd_per_lun).
*
* Returns nothing
*
* Notes: Can be invoked any time on a SCSI device controlled by this
* LLD. [Specifically after slave_attach() and prior to slave_detach().]
* Can safely be invoked from interrupt code. Actual queue depth change
* may be delayed until the next command is being processed.
* Defined in drivers/scsi/scsi.c [see source code for more notes]
*
**/
void scsi_adjust_queue_depth(struct scsi_device * SDpnt, int tagged,
int num_tags)
/**
* scsi_assign_lock - replace default host_lock with given lock
* @shost: a pointer to a scsi host instance
* @lock: pointer to lock to replace host_lock for this host
*
* Returns nothing
*
* Notes: Defined in drivers/scsi/hosts.h .
**/
void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
/**
* scsi_bios_ptable - return copy of block device's partition table
* @dev: pointer to block device
*
* Returns pointer to partition table, or NULL or failure
*
* Notes: Caller owns memory returned (free with kfree() )
* Defined in drivers/scsi/scsicam.c
**/
unsigned char *scsi_bios_ptable(struct block_device *dev)
/**
* scsi_block_requests - prevent further commands being queued to given host
*
* @SHpnt: pointer to host to block commands on
*
* Returns nothing
*
* Notes: There is no timer nor any other means by which the requests
* get unblocked other than the LLD calling scsi_unblock_requests().
* Defined in drivers/scsi/scsi_lib.c
**/
void scsi_block_requests(struct Scsi_Host * SHpnt)
/**
* scsi_partsize - parse partition table into cylinders, heads + sectors
* @buf: pointer to partition table
* @capacity: size of (total) disk in 512 byte sectors
* @cyls: outputs number of cylinders calculated via this pointer
* @hds: outputs number of heads calculated via this pointer
* @secs: outputs number of sectors calculated via this pointer
*
* Returns 0 on success, -1 on failure
*
* Notes: Caller owns memory returned (free with kfree() )
* Defined in drivers/scsi/scsicam.c
**/
int scsi_partsize(unsigned char *buf, unsigned long capacity,
unsigned int *cyls, unsigned int *hds, unsigned int *secs)
/**
* scsi_register - create and register a scsi host adapter instance.
* @shost_tp: pointer to scsi host template
* @xtr_bytes: extra bytes to allocate in hostdata array (which is the
* last member of the returned Scsi_Host instance)
*
* Returns pointer to new Scsi_Host instance or NULL on failure
*
* Notes: When this call returns to the LLDD, the SCSI bus scan on
* this host has _not_ yet been done.
* The hostdata array (by default zero length) is a per host scratch
* area for the LLD.
* Defined in drivers/scsi/hosts.c .
**/
struct Scsi_Host * scsi_register(struct SHT *, int xtr_bytes)
/**
* scsi_register_host - register a low level host driver
* @shost_tp: pointer to a scsi host driver template
*
* Returns 0 on Success, 1 on failure
*
* Notes: Should only be invoked if the "passive initialization
* model" is being used. Notice this is a _driver_ rather than
* HBA registration function. Most older drivers call this
* function by including the scsi_module.c file.
* This function is deprecated, use the "hotplug initialization
* model" instead.
* Defined in drivers/scsi/hosts.c .
**/
int scsi_register_host(Scsi_Host_Template *shost_tp)
/**
* scsi_remove_host - detach and remove all SCSI devices owned by host
* @shost: a pointer to a scsi host instance
*
* Returns value: 0 on success, 1 on failure (e.g. LLD busy ??)
*
* Notes: Should only be invoked if the "hotplug initialization
* model" is being used. It should be called _prior_ to
* scsi_unregister().
* Defined in drivers/scsi/hosts.c .
**/
int scsi_remove_host(struct Scsi_Host *shost)
/**
* scsi_report_bus_reset - report scsi _bus_ reset observed
* @shost: a pointer to a scsi host involved
* @channel: channel (within) host on which scsi bus reset occurred
*
* Returns nothing
*
* Notes: This only needs to be called if the reset is one which
* originates from an unknown location. Resets originated by the
* mid level itself don't need to call this, but there should be
* no harm. The main purpose of this is to make sure that a
* CHECK_CONDITION is properly treated.
* Defined in drivers/scsi/scsi_lib.c .
**/
void scsi_report_bus_reset(struct Scsi_Host * shost, int channel)
/**
* scsi_set_pci_device - place PCI device reference in host structure
* @shost: a pointer to a scsi host instance
* @pdev: pointer to PCI device instance to assign
*
* Returns nothing
*
* Notes: Defined in drivers/scsi/hosts.h .
**/
void scsi_set_pci_device(struct Scsi_Host * shost, struct pci_dev * pdev)
/**
* scsi_to_pci_dma_dir - convert SCSI subsystem direction flag to PCI
* @scsi_data_direction: SCSI subsystem direction flag
*
* Returns PCI_DMA_TODEVICE given SCSI_DATA_WRITE,
* PCI_DMA_FROMDEVICE given SCSI_DATA_READ
* PCI_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN
* else returns PCI_DMA_NONE
*
* Notes: Defined in drivers/scsi/scsi.h .
**/
int scsi_to_pci_dma_dir(unsigned char scsi_data_direction)
/**
* scsi_unblock_requests - allow further commands to be queued to given host
*
* @SHpnt: pointer to host to unblock commands on
*
* Returns nothing
*
* Notes: Defined in drivers/scsi/scsi_lib.c .
**/
void scsi_unblock_requests(struct Scsi_Host * SHpnt)
/**
* scsi_unregister - unregister and free host
* @shp: pointer to scsi host instance to unregister.
* N.B. shp points to freed memory on return
*
* Returns nothing
*
* Notes: Should only be invoked if the "hotplug initialization
* model" is being used. It should be called _after_
* scsi_remove_host().
* Defined in drivers/scsi/hosts.c .
**/
void scsi_unregister(struct Scsi_Host * shp)
/**
* scsi_unregister_host - unregister a low level host adapter driver
* @shost_tp: scsi host template to unregister.
*
* Returns 0 on Success, 1 on Failure
*
* Notes: Should only be invoked if the "passive initialization
* model" is being used. Notice this is a _driver_ rather than
* HBA deregistration function. Most older drivers call this
* function by including the scsi_module.c file.
* This function is deprecated, use the "hotplug initialization
* model" instead.
* Defined in drivers/scsi/hosts.c .
**/
int scsi_unregister_host(Scsi_Host_Template *shost_tp)
Interface Functions Interface Functions
=================== ===================
Interface functions should be declared static. The accepted convention Interface functions are supplied (defined) by LLDs and
is that driver "xyz" will declare its detect() function as: their function pointers are placed in an instance of struct SHT which
static int xyz_detect(struct SHT * shtp); is passed to scsi_register() [or scsi_register_host()]. Some
are mandatory. Interface functions should be declared static. The
A pointer to this function should be placed in the 'detect' member of accepted convention is that driver "xyz" will declare its slave_attach()
a "struct SHT" instance. A pointer to such an instance should function as:
passed to the mid level's scsi_register_host(). static int xyz_slave_attach(struct scsi_device * sdev);
A pointer to this function should be placed in the 'slave_attach' member
of a "struct SHT" instance. A pointer to such an instance should
passed to the mid level's scsi_register() [or scsi_register_host()].
The interface functions are also described in the hosts.h file immediately The interface functions are also described in the hosts.h file immediately
above their definition point in "struct SHT". In some cases more detail above their definition point in "struct SHT". In some cases more detail
is given in hosts.h than below. is given in hosts.h than below.
Those interface functions marked "Required: yes" must be implemented Those interface functions marked "Required: yes" must be implemented
by the lower level driver and a pointer to that function must be by the LLD and a pointer to that function must be placed in the driver's
placed in the driver's "struct SHT" instance. Interface functions marked "struct SHT" instance. Interface functions marked "Required: no" need not
"Required: no" need not be implemented and if they are a pointer to be implemented.
that function should be placed in the driver's "struct SHT" instance.
The interface functions are listed below in alphabetical order. The interface functions are listed below in alphabetical order.
...@@ -96,11 +495,11 @@ The interface functions are listed below in alphabetical order. ...@@ -96,11 +495,11 @@ The interface functions are listed below in alphabetical order.
* bios_param - fetch head, sector, cylinder info for a disk * bios_param - fetch head, sector, cylinder info for a disk
* @sdev: pointer to scsi device context (defined in scsi.h) * @sdev: pointer to scsi device context (defined in scsi.h)
* @bdev: pointer to block device context (defined in fs.h) * @bdev: pointer to block device context (defined in fs.h)
* @capacity: device size (in sectors) * @capacity: device size (in 512 byte sectors)
* @params: three element array to place output: * @params: three element array to place output:
* params[0] number of heads * params[0] number of heads (max 255)
* params[1] number of sectors * params[1] number of sectors (max 63)
* params[2] number of cylinders * params[2] number of cylinders
* *
* Return value is ignored * Return value is ignored
* *
...@@ -132,7 +531,7 @@ The interface functions are listed below in alphabetical order. ...@@ -132,7 +531,7 @@ The interface functions are listed below in alphabetical order.
* and is expected to be held on return. * and is expected to be held on return.
* *
* Notes: Drivers tend to be dropping support for this function and * Notes: Drivers tend to be dropping support for this function and
* rather supporting queuecommand(). * supporting queuecommand() instead.
**/ **/
int command(struct scsi_cmnd * scp); int command(struct scsi_cmnd * scp);
...@@ -144,11 +543,12 @@ The interface functions are listed below in alphabetical order. ...@@ -144,11 +543,12 @@ The interface functions are listed below in alphabetical order.
* Returns number of hosts this driver wants to control. 0 means no * Returns number of hosts this driver wants to control. 0 means no
* suitable hosts found. * suitable hosts found.
* *
* Required: yes * Required: yes, if "passive initialization mode" is used
* [in "hotplug initialization mode" it is not invoked]
* *
* Locks: none held * Locks: none held
* *
* Notes: First function called from the scsi mid level on this * Notes: First function called from the SCSI mid level on this
* driver. Upper level drivers (e.g. sd) may not (yet) be present. * driver. Upper level drivers (e.g. sd) may not (yet) be present.
* For each host found, this method should call scsi_register() * For each host found, this method should call scsi_register()
* [see hosts.c]. * [see hosts.c].
...@@ -174,8 +574,8 @@ The interface functions are listed below in alphabetical order. ...@@ -174,8 +574,8 @@ The interface functions are listed below in alphabetical order.
/** /**
* eh_device_reset_handler - issue scsi device reset * eh_device_reset_handler - issue SCSI device reset
* @scp: identifies scsi device to be reset * @scp: identifies SCSI device to be reset
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
...@@ -191,8 +591,8 @@ The interface functions are listed below in alphabetical order. ...@@ -191,8 +591,8 @@ The interface functions are listed below in alphabetical order.
/** /**
* eh_bus_reset_handler - issue scsi bus reset * eh_bus_reset_handler - issue SCSI bus reset
* @scp: scsi bus that contains this device should be reset * @scp: SCSI bus that contains this device should be reset
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
...@@ -209,7 +609,7 @@ The interface functions are listed below in alphabetical order. ...@@ -209,7 +609,7 @@ The interface functions are listed below in alphabetical order.
/** /**
* eh_host_reset_handler - reset host (host bus adapter) * eh_host_reset_handler - reset host (host bus adapter)
* @scp: scsi host that contains this device should be reset * @scp: SCSI host that contains this device should be reset
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
...@@ -288,11 +688,11 @@ The interface functions are listed below in alphabetical order. ...@@ -288,11 +688,11 @@ The interface functions are listed below in alphabetical order.
* *
* Locks: none * Locks: none
* *
* Notes: The scsi subsystem uses a "trickle down" ioctl model. * Notes: The SCSI subsystem uses a "trickle down" ioctl model.
* The user issues an ioctl() against an upper level driver * The user issues an ioctl() against an upper level driver
* (e.g. /dev/sdc) and if the upper level driver doesn't recognize * (e.g. /dev/sdc) and if the upper level driver doesn't recognize
* the 'cmd' then it is passed to the scsi mid level. If the scsi * the 'cmd' then it is passed to the SCSI mid level. If the SCSI
* mid level does not recognize it, then the lower driver that controls * mid level does not recognize it, then the LLD that controls
* the device receives the ioctl. According to recent Unix standards * the device receives the ioctl. According to recent Unix standards
* unsupported ioctl() 'cmd' numbers should return -ENOTTY. * unsupported ioctl() 'cmd' numbers should return -ENOTTY.
* However the mid level returns -EINVAL for unrecognized 'cmd' * However the mid level returns -EINVAL for unrecognized 'cmd'
...@@ -351,16 +751,16 @@ int proc_info(char * buffer, char ** start, off_t offset, ...@@ -351,16 +751,16 @@ int proc_info(char * buffer, char ** start, off_t offset,
* not wait for IO to complete. Hence the 'done' callback is invoked * not wait for IO to complete. Hence the 'done' callback is invoked
* (often directly from an interrupt service routine) sometime after * (often directly from an interrupt service routine) sometime after
* this command has returned. In some cases (e.g. pseudo adapter * this command has returned. In some cases (e.g. pseudo adapter
* drivers that manufacture the response to a scsi INQUIRY) * drivers that manufacture the response to a SCSI INQUIRY)
* the 'done' callback may be invoked before this function returns. * the 'done' callback may be invoked before this function returns.
* If the 'done' callback is not invoked within a certain period * If the 'done' callback is not invoked within a certain period
* the scsi mid level will commence error processing. * the SCSI mid level will commence error processing.
* The integer with 4 component bytes that command() uses as its * The integer with 4 component bytes that command() uses as its
* return value should be generated by this function. However, in * return value should be generated by this function. However, in
* this case, it should be placed in scp->result before this function * this case, it should be placed in scp->result before this function
* returns. * returns.
* If a status of CHECK CONDITION is placed in "result" when the * If a status of CHECK CONDITION is placed in "result" when the
* 'done' callback is invoked, then the lower level driver should * 'done' callback is invoked, then the LLD driver should
* perform autosense and fill in the struct scsi_cmnd::sense_buffer * perform autosense and fill in the struct scsi_cmnd::sense_buffer
* array. * array.
**/ **/
...@@ -386,26 +786,6 @@ int proc_info(char * buffer, char ** start, off_t offset, ...@@ -386,26 +786,6 @@ int proc_info(char * buffer, char ** start, off_t offset,
int release(struct Scsi_Host * shp); int release(struct Scsi_Host * shp);
/**
* select_queue_depths - calculate allowable number of scsi commands
* that can be queued on each device (disk)
* on the given host
* @shp: host containing device
* @sdp: first device to examine [start of list]
*
* Returns nothing
*
* Required: no
*
* Locks: none
*
* Notes: This function should examine all devices on the given host.
* The next device can be fetched with sdp->next (NULL when finished).
* Queue depths should be placed in struct scsi_device::queue_depth .
**/
void select_queue_depths(struct Scsi_Host * shp, struct scsi_device * sdp);
/** /**
* slave_attach - driver fine tuning for give device just after it * slave_attach - driver fine tuning for give device just after it
* has been first scan (i.e. it responded to an * has been first scan (i.e. it responded to an
...@@ -458,7 +838,7 @@ Data Structures ...@@ -458,7 +838,7 @@ Data Structures
=============== ===============
struct SHT struct SHT
---------- ----------
There is one "struct SHT" instance per lower level driver ***. It is There is one "struct SHT" instance per LLD ***. It is
typically initialized as a file scope static in a driver's header file. That typically initialized as a file scope static in a driver's header file. That
way members that are not explicitly initialized will be set to 0 or NULL. way members that are not explicitly initialized will be set to 0 or NULL.
Member of interest: Member of interest:
...@@ -473,8 +853,8 @@ The structure is defined and commented in hosts.h ...@@ -473,8 +853,8 @@ The structure is defined and commented in hosts.h
struct Scsi_Host struct Scsi_Host
---------------- ----------------
There is one struct Scsi_Host instance per host (HBA) that a lower level There is one struct Scsi_Host instance per host (HBA) that a LLD
driver controls. The struct Scsi_Host structure has many members in common controls. The struct Scsi_Host structure has many members in common
with "struct SHT". When a new struct Scsi_Host instance is created (in with "struct SHT". When a new struct Scsi_Host instance is created (in
scsi_register() in hosts.c) those common members are initialized from scsi_register() in hosts.c) those common members are initialized from
the driver's struct SHT instance. Members of interest: the driver's struct SHT instance. Members of interest:
...@@ -488,15 +868,15 @@ the driver's struct SHT instance. Members of interest: ...@@ -488,15 +868,15 @@ the driver's struct SHT instance. Members of interest:
sg_tablesize - maximum scatter gather elements allowed by host. sg_tablesize - maximum scatter gather elements allowed by host.
0 implies scatter gather not supported by host 0 implies scatter gather not supported by host
max_sectors - maximum number of sectors (usually 512 bytes) allowed max_sectors - maximum number of sectors (usually 512 bytes) allowed
in a single scsi command. 0 implies no maximum. in a single SCSI command. 0 implies no maximum.
cmd_per_lun - maximum number of command that can be queued on devices cmd_per_lun - maximum number of command that can be queued on devices
controlled by the host. Used if select_queue_depths() controlled by the host. Overridden by LLD calls to
not defined or yields 0. scsi_adjust_queue_depth().
unchecked_isa_dma - 1->only use bottom 16 MB of ram (ISA DMA addressing unchecked_isa_dma - 1->only use bottom 16 MB of ram (ISA DMA addressing
restriction), 0->can use full 32 bit (or better) DMA restriction), 0->can use full 32 bit (or better) DMA
address space address space
use_clustering - 1->scsi commands in mid level's queue can be merged, use_clustering - 1->SCSI commands in mid level's queue can be merged,
0->disallow scsi command merging 0->disallow SCSI command merging
highmem_io - 1->can DMA in to or out of high memory, highmem_io - 1->can DMA in to or out of high memory,
0->use bounce buffers if data is in high memory 0->use bounce buffers if data is in high memory
hostt - pointer to driver's struct SHT from which this hostt - pointer to driver's struct SHT from which this
...@@ -508,51 +888,20 @@ The structure is defined in hosts.h ...@@ -508,51 +888,20 @@ The structure is defined in hosts.h
struct scsi_device struct scsi_device
------------------ ------------------
Generally, there is one instance of this structure for each scsi logical unit Generally, there is one instance of this structure for each SCSI logical unit
on a host. Scsi devices are uniquely identified within a host by bus number, on a host. Scsi devices are uniquely identified within a host by bus number,
target id and logical unit number (lun). target id and logical unit number (lun).
The structure is defined in scsi.h The structure is defined in scsi.h
struct scsi_cmnd struct scsi_cmnd
---------------- ----------------
Instances of this structure convey scsi commands to the lower level Instances of this structure convey SCSI commands to the LLD.
driver. Each scsi device has a pool of struct scsi_cmnd instances whose size Each SCSI device has a pool of struct scsi_cmnd instances whose size
is determined by select_queue_depths (or struct Scsi_Host::cmd_per_lun). is determined by scsi_adjust_queue_depth() (or struct Scsi_Host::cmd_per_lun).
There will be at least one instance of struct scsi_cmnd for each scsi device. There will be at least one instance of struct scsi_cmnd for each SCSI device.
The structure is defined in scsi.h The structure is defined in scsi.h
Flow of control during initialization
=====================================
Lower level driver mid level
------------------ ---------
init_this_scsi_driver() [1] -----+
<scsi_modules.c> |
v
scsi_register_host()
|
detect() [2] <--+
|
queuecommand()** [3] <--+
|
select_queue_depths()* <--+
Notes
-----
[1] invoked during kernel initialization when built in or during module
initialization. The scsi mid level will already be initialized.
[2] detect() calls scsi_register() for each HBA it wants to control
(if not, scsi_register_host() will do it instead)
[3] called as part of scsi bus scan during discovery of devices. This scan
will be done for each host. Scsi commands such as INQUIRY, MODE SENSE
and REPORT LUNS will be sent during device discovery
* invoked for each host controlled by the lower level driver
** invoked for each device of each host controlled by the driver
Locks Locks
===== =====
Each struct Scsi_Host instance has a spin_lock called struct Each struct Scsi_Host instance has a spin_lock called struct
...@@ -562,12 +911,12 @@ is initialized to point at default_lock with the scsi_assign_lock() function. ...@@ -562,12 +911,12 @@ is initialized to point at default_lock with the scsi_assign_lock() function.
Thereafter lock and unlock operations performed by the mid level use the Thereafter lock and unlock operations performed by the mid level use the
struct Scsi_Host::host_lock pointer. struct Scsi_Host::host_lock pointer.
Lower level drivers can override the use of struct Scsi_Host::default_lock by LLDs can override the use of struct Scsi_Host::default_lock by
using scsi_assign_lock(). The earliest opportunity to do this would using scsi_assign_lock(). The earliest opportunity to do this would
be in the detect() function after it has invoked scsi_register(). It be in the detect() function after it has invoked scsi_register(). It
could be replaced by a coarser grain lock (e.g. per driver) or a could be replaced by a coarser grain lock (e.g. per driver) or a
lock of equal granularity (i.e. per host). Using finer grain locks lock of equal granularity (i.e. per host). Using finer grain locks
(e.g. per scsi device) may be possible by juggling locks in (e.g. per SCSI device) may be possible by juggling locks in
queuecommand(). queuecommand().
Autosense Autosense
...@@ -575,13 +924,13 @@ Autosense ...@@ -575,13 +924,13 @@ Autosense
Autosense (or auto-sense) is defined in the SAM-2 document as "the Autosense (or auto-sense) is defined in the SAM-2 document as "the
automatic return of sense data to the application client coincident automatic return of sense data to the application client coincident
with the completion of a SCSI command" when a status of CHECK CONDITION with the completion of a SCSI command" when a status of CHECK CONDITION
occurs. Lower level drivers should perform autosense. This should be occurs. LLDs should perform autosense. This should be done when the LLD
done when the lower level driver detects a CHECK CONDITION status by either: detects a CHECK CONDITION status by either:
a) instructing the SCSI protocol (e.g. SCSI Parallel Interface (SPI)) a) instructing the SCSI protocol (e.g. SCSI Parallel Interface (SPI))
to perform an extra data in phase on such responses to perform an extra data in phase on such responses
b) or, the lower level driver issuing a REQUEST SENSE command itself b) or, the LLD issuing a REQUEST SENSE command itself
Either way, the mid level decides whether the lower level driver has Either way, the mid level decides whether the LLD has
performed autosense by checking struct scsi_cmnd::sense_buffer[0] . If this performed autosense by checking struct scsi_cmnd::sense_buffer[0] . If this
byte has an upper nibble of 7 then autosense is assumed to have taken byte has an upper nibble of 7 then autosense is assumed to have taken
place. If it has another value (and this byte is initialized to 0 before place. If it has another value (and this byte is initialized to 0 before
...@@ -589,28 +938,30 @@ each command) then the mid level will issue a REQUEST SENSE command. ...@@ -589,28 +938,30 @@ each command) then the mid level will issue a REQUEST SENSE command.
In the presence of queued commands the "nexus" that maintains sense In the presence of queued commands the "nexus" that maintains sense
buffer data from the command that failed until a following REQUEST SENSE buffer data from the command that failed until a following REQUEST SENSE
may get out of synchronization. This is why it is best for the lower may get out of synchronization. This is why it is best for the LLD
level driver to perform autosense. to perform autosense.
Changes since lk 2.4 series Changes since lk 2.4 series
=========================== ===========================
io_request_lock has been replaced by several finer grained locks. The lock io_request_lock has been replaced by several finer grained locks. The lock
relevant to lower level drivers is struct Scsi_Host::host_lock and there is relevant to LLDs is struct Scsi_Host::host_lock and there is
one per scsi host. one per SCSI host.
The older error handling mechanism has been removed. This means the The older error handling mechanism has been removed. This means the
lower level interface functions abort() and reset() have been removed. LLD interface functions abort() and reset() have been removed.
The struct SHT::use_new_eh_code flag has been removed. The struct SHT::use_new_eh_code flag has been removed.
In the 2.4 series the scsi subsystem configuration descriptions were In the 2.4 series the SCSI subsystem configuration descriptions were
aggregated with the configuration descriptions from all other Linux aggregated with the configuration descriptions from all other Linux
subsystems in the Documentation/Configure.help file. In the 2.5 series, subsystems in the Documentation/Configure.help file. In the 2.5 series,
the scsi subsystem now has its own (much smaller) drivers/scsi/Config.help the SCSI subsystem now has its own (much smaller) drivers/scsi/Config.help
file. file.
Addition of slave_attach() and slave_detach(). Addition of slave_attach() and slave_detach().
Addition of the "hotplug initialization model".
Credits Credits
======= =======
...@@ -618,8 +969,9 @@ The following people have contributed to this document: ...@@ -618,8 +969,9 @@ The following people have contributed to this document:
Mike Anderson <andmike@us.ibm.com> Mike Anderson <andmike@us.ibm.com>
James Bottomley <James.Bottomley@steeleye.com> James Bottomley <James.Bottomley@steeleye.com>
Patrick Mansfield <patmans@us.ibm.com> Patrick Mansfield <patmans@us.ibm.com>
Christoph Hellwig <hch@infradead.org>
Douglas Gilbert Douglas Gilbert
dgilbert@interlog.com dgilbert@interlog.com
8th November 2002 17th November 2002
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment