Commit 9877980f authored by James Bottomley's avatar James Bottomley

scsi_mid_low_api.txt update

From Douglas Gilbert <dougg@torque.net>
parent 5c8dfe47
......@@ -22,24 +22,26 @@ has its own PCI device address. [The one-to-one correspondence between
a SCSI host and a PCI device is common but not required (e.g. with
ISA or MCA adapters).]
This version of the document roughly matches linux kernel version 2.5.68 .
This document can be found in the Linux kernel source Documentation/scsi
directory and is called scsi_mid_low_api.txt . A more recent copy may
be found at http://www.torque.net/scsi/scsi_mid_low_api.txt.gz .
The SCSI mid level isolates a LLD from other layers such as the SCSI
upper layer drivers and the block layer.
This version of the document roughly matches linux kernel version 2.5.73 .
Documentation
=============
There is a SCSI documentation directory within the kernel source tree.
That directory is typically /usr/src/linux/Documentation/scsi . Most
documents are in plain (i.e. ASCII) text. This file can be found in that
directory, named scsi_mid_low_api.txt . Many LLDs are documented there
(e.g. aic7xxx.txt). The SCSI mid-level is briefly described in scsi.txt
(with a url to a document describing the SCSI subsystem in the lk 2.4
series). Two upper level drivers have documents in that directory:
st.txt (SCSI tape driver) and scsi-generic.txt (for the sg driver).
Some documentation (or urls) for LLDs may be in the C source code or
in the same directory as the C source code. For example to find a url
There is a SCSI documentation directory within the kernel source tree,
typically /usr/src/linux/Documentation/scsi . Most documents are in plain
(i.e. ASCII) text. This file is named scsi_mid_low_api.txt and can be
found in that directory. A more recent copy of this document may be found
at http://www.torque.net/scsi/scsi_mid_low_api.txt.gz .
Many LLDs are documented there (e.g. aic7xxx.txt). The SCSI mid-level is
briefly described in scsi.txt which contains a url to a document
describing the SCSI subsystem in the lk 2.4 series. Two upper level
drivers have documents in that directory: st.txt (SCSI tape driver) and
scsi-generic.txt (for the sg driver).
Some documentation (or urls) for LLDs may be found in the C source code
or in the same directory as the C source code. For example to find a url
about the USB mass storage driver see the
/usr/src/linux/drivers/usb/storage directory.
......@@ -69,12 +71,12 @@ 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
hot plugged (and unplugged) during the lifetime of the LLD 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.
permanently connected as well as modern "SCSI" devices (e.g. USB or
IEEE 1394 connected 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
......@@ -90,21 +92,27 @@ supplied functions" below.
Those functions in group b) are listed in a section entitled "Interface
functions" below. Their 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.]
"struct scsi_host_template", an instance of which is passed to
scsi_host_alloc() ** . Those interface functions that the LLD does not
wish to supply should have NULL placed in the corresponding member of
struct scsi_host_template. Defining an instance of struct
scsi_host_template 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.
Those usages in group c) should be handled with care, especially in a
"hotplug" environment. LLDs should be aware of the lifetime of instances
that are shared with the mid level and other layers.
All functions defined within a LLD and all data defined at file scope
should be static. For example the slave_alloc() function in a LLD
called "xxx" could be defined as
"static int xxx_slave_alloc(struct scsi_device * sdev) { /* code */ }"
** the scsi_host_alloc() function is a replacement for the rather vaguely
named scsi_register() function in most situations. The scsi_register()
and scsi_unregister() functions remain to support legacy LLDs that use
the passive initialization model.
Hotplug initialization model
============================
......@@ -116,13 +124,6 @@ detected. After confirming that the new device is one that the LLD wants
to control, the LLD 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 is
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.
In the sysfs model, a remove() callback indicates a HBA has disappeared.
During LLD initialization the driver should register itself with the
appropriate IO bus on which it expects to find HBA(s) (e.g. the PCI bus).
This can probably be done via sysfs. Any driver parameters (especially
......@@ -135,10 +136,10 @@ is a typical sequence of calls between the LLD and the mid level.
This example shows the mid level scanning the newly introduced HBA for 3
scsi devices of which only the first 2 respond:
[HBA PROBE]
HBA PROBE: assume 2 SCSI devices found in scan
LLD mid level LLD
--- --------- ---
scsi_register() -->
===-------------------=========--------------------===------
scsi_host_alloc() -->
scsi_add_host() --------+
|
slave_alloc()
......@@ -147,79 +148,107 @@ scsi_add_host() --------+
slave_alloc()
slave_configure()
|
slave_alloc() **
slave_destroy() **
slave_alloc() ***
slave_destroy() ***
------------------------------------------------------------
If the LLD wants to adjust the default queue settings, it can invoke
scsi_adjust_queue_depth() in its slave_configure() routine.
** For scsi devices that the mid level tries to scan but do not
*** For scsi devices that the mid level tries to scan but do not
respond, a slave_alloc(), slave_destroy() pair is called.
Here is the corresponding sequence when a host (HBA) is being
removed:
When a HBA is being removed is could as part of an orderly shutdown
associated with the LLD module being unloaded (e.g. with the "rmmod"
command) or in response to a "hot unplug" indicated by sysfs()'s
remove() callback being invoked. In either case, the sequence is the
same:
[HBA REMOVE]
HBA REMOVE: assume 2 SCSI devices attached
LLD mid level LLD
--- --------- ---
===----------------------=========-----------------===------
scsi_remove_host() ---------+
|
slave_destroy()
slave_destroy()
release() --> scsi_unregister()
scsi_host_put()
------------------------------------------------------------
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_alloc() and
slave_configure() ). Both classes of instances are "owned" by the
mid-level. struct scsi_device instances are freed after slave_destroy().
struct Scsi_Host instances are freed within scsi_unregister().
It may be useful for a LLD to keep track of struct Scsi_Host instances
(a pointer is returned by scsi_host_alloc()). Such instances are "owned"
by the mid-level. struct Scsi_Host instances are freed from
scsi_host_put() when the reference count hits zero.
TODO:
Descriptions, are the following correct?
[DEVICE hotplug]
Hot unplugging a HBA that controls a disk which is processing SCSI
commands on a mounted file system is an interesting situation. Reference
counting logic is being introduced into the mid level to cope with many
of the issues involved. See the section on reference counting below.
The hotplug concept may be extended to SCSI devices. Currently, when a
HBA is added, the scsi_add_host() function causes a scan for SCSI devices
attached to the HBA's SCSI transport. On newer SCSI transports the HBA
may become aware of a new SCSI device _after_ the scan has completed.
A LLD can use this sequence to make the mid level aware of a SCSI device:
SCSI DEVICE hotplug
LLD mid level LLD
--- --------- ---
===-------------------=========--------------------===------
scsi_add_device() ------+
|
slave_alloc()
slave_configure() [--> scsi_adjust_queue_depth()]
------------------------------------------------------------
[DEVICE unplug]
In a similar fashion, a LLD may become aware that a SCSI device has been
removed (unplugged) or the connection to it has been interrupted. Some
existing SCSI transports (e.g. SPI) may not become aware that a SCSI
device has been removed until a subsequent SCSI command fails which will
probably cause that device to be set offline by the mid level. A LLD that
detects the removal of a SCSI device can instigate its removal from
upper layers with this sequence:
SCSI DEVICE hot unplug
LLD mid level LLD
--- --------- ---
===----------------------=========-----------------===------
scsi_set_device_offline()
scsi_remove_device() -------+
|
slave_destroy()
------------------------------------------------------------
It may be useful for a LLD to keep track of struct scsi_device instances
(a pointer is passed as the parameter to slave_alloc() and
slave_configure() callbacks). Such instances are "owned" by the mid-level.
struct scsi_device instances are freed after slave_destroy().
Passive initialization model
============================
LLD initialization (both built-in and module) and shutdown are "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 that file to work a declaration like this is needed before
it is included:
static struct SHT driver_template = DRIVER_TEMPLATE;
These older LLDs include a file called "scsi_module.c" [yes the ".c" is a
little surprising] in their source code. For that file to work an
instance of struct scsi_host_template with the name "driver_template"
needs to be defined. Here is a typical code sequence used in this model:
static struct scsi_host_template driver_template = {
...
};
#include "scsi_module.c"
In this case "DRIVER_TEMPLATE" is defined to be a structure initializer
that is placed in the driver header file by convention. It contains
pointers to supported interface functions and other values.
The scsi_module.c file contains two functions:
- init_this_scsi_driver() which is executed when the LLD is
initialized (i.e. boot time or module load time)
- exit_this_scsi_driver() which is executed when the LLD is shut
down (i.e. module unload time)
Note: since these functions are tagged with __init and __exit qualifiers
a LLD should not call them explicitly (since the kernel does that).
Here is an example of an initialization sequence when two hosts are
detected (so detect() returns 2) and the SCSI bus scan on each host
finds 1 SCSI device (and a second device does not respond).
LLD mid level LLD
--- --------- ---
scsi_register_host() -------+
===----------------------=========-----------------===------
init_this_scsi_driver() ----+
|
detect() -----------------+
| |
......@@ -228,52 +257,77 @@ scsi_register_host() -------+
|
slave_alloc()
slave_configure() --> scsi_adjust_queue_depth()
slave_alloc() **
slave_destroy() **
slave_alloc() ***
slave_destroy() ***
|
slave_alloc()
slave_configure()
slave_alloc() **
slave_destroy() **
slave_alloc() ***
slave_destroy() ***
------------------------------------------------------------
The mid level invokes scsi_adjust_queue_depth() with tagged queuing off and
"cmd_per_lun" for that host as the queue length. These settings can be
overridden by a slave_configure() supplied by the LLD.
** For scsi devices that the mid level tries to scan but do not
*** For scsi devices that the mid level tries to scan but do not
respond, a slave_alloc(), slave_destroy() pair is called.
Here is a LLD shutdown sequence:
LLD mid level LLD
--- --------- ---
scsi_unregister_host() -----+
===----------------------=========-----------------===------
exit_this_scsi_driver() ----+
|
slave_destroy()
release() --> scsi_unregister()
|
slave_destroy()
release() --> scsi_unregister()
------------------------------------------------------------
slave_destroy() is optional.
A LLD need not define slave_destroy() (i.e. it is optional).
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.
driver shutdown and re-initialization. It may be possible to write a LLD
that uses both initialization models.
Reference Counting
==================
The Scsi_Host structure has had reference counting infrastructure added.
This effectively spreads the ownership of struct Scsi_Host instances
across the various SCSI layers which use them. Previously such instances
were exclusively owned by the mid level. LLDs would not usually need to
directly manipulate these reference counts but there may be some cases
where they do.
There are 3 reference counting functions of interest associated with
struct Scsi_Host:
- scsi_host_alloc(): returns a pointer to new instance of struct
Scsi_Host which has its reference count ^^ set to 1
- scsi_host_get(): adds 1 to the reference count of the given instance
- scsi_host_put(): decrements 1 from the reference count of the given
instance. If the reference count reaches 0 then the given instance
is freed
^^ struct Scsi_Host actually has 2 reference counts which are manipulated
in parallel by these functions.
Conventions
===========
First, Linus's thoughts on C coding can be found in the file
Documentation/CodingStyle .
First, Linus Torvald's thoughts on C coding style can be found in the
Documentation/CodingStyle file.
Next, there is a movement to "outlaw" typedefs introducing synonyms for
struct tags. Both can be still found in the SCSI subsystem, for example:
"typedef struct SHT { ...} Scsi_Host_Template;" in hosts.h . In this
case "struct SHT" is preferred to "Scsi_Host_Template". [The poor naming
example was chosen with malevolent intent.]
struct tags. Both can be still found in the SCSI subsystem, but
the typedefs have been moved to a single file, scsi_typedefs.h to
make their future removal easier, for example:
"typedef struct scsi_host_template Scsi_Host_Template;"
Also, C99 enhancements are encouraged to the extent they are supported
by the relevant gcc compilers. So "//" style comments are encouraged
......@@ -304,9 +358,11 @@ Summary:
scsi_bios_ptable - return copy of block device's partition table
scsi_block_requests - prevent further commands being queued to given host
scsi_delete_timer - cancel timer on a SCSI command.
scsi_host_alloc - return a new scsi_host instance whose refcount==1
scsi_host_get - increments Scsi_Host instance's refcount
scsi_host_put - decrements Scsi_Host instance's refcount (free if 0)
scsi_partsize - parse partition table into cylinders, heads + sectors
scsi_register - create and register a scsi host adapter instance.
scsi_register_host - register a low level host driver
scsi_remove_device - detach and remove a SCSI device
scsi_remove_host - detach and remove all SCSI devices owned by host
scsi_report_bus_reset - report scsi _bus_ reset observed
......@@ -316,8 +372,8 @@ Summary:
scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS
scsi_track_queue_full - track successive QUEUE_FULL events
scsi_unblock_requests - allow further commands to be queued to given host
scsi_unregister - unregister and free memory used by host instance
scsi_unregister_host - unregister a low level host adapter driver
scsi_unregister - [calls scsi_host_put()]
Details:
......@@ -354,7 +410,7 @@ struct scsi_device * scsi_add_device(struct Scsi_Host *shost,
* 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().
* successful call to scsi_host_alloc().
*
* Defined in: drivers/scsi/hosts.c
**/
......@@ -376,8 +432,8 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
*
* Defined in: drivers/scsi/scsi_error.c
**/
void scsi_add_timer(Scsi_Cmnd *scmd, int timeout, void (*complete)
(Scsi_Cmnd *))
void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
void (*complete)(struct scsi_cmnd *))
/**
......@@ -458,7 +514,56 @@ void scsi_block_requests(struct Scsi_Host * SHpnt)
*
* Defined in: drivers/scsi/scsi_error.c
**/
int scsi_delete_timer(Scsi_Cmnd *scmd)
int scsi_delete_timer(struct scsi_cmnd *scmd)
/**
* scsi_host_alloc - 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.
* Both associated refcounting objects have there refcount set to 1.
*
* Defined in: drivers/scsi/hosts.c .
**/
struct Scsi_Host * scsi_host_alloc(struct scsi_host_template *, int xtr_bytes)
/**
* scsi_host_get - increment Scsi_Host instance refcount
* @shost: pointer to struct Scsi_Host instance
*
* Returns nothing
*
* Notes: Actually increments the counts in two sub-objects
*
* Defined in: drivers/scsi/hosts.c
**/
void scsi_host_get(struct Scsi_Host *shost)
/**
* scsi_host_put - decrement Scsi_Host instance refcount, free if 0
* @shost: pointer to struct Scsi_Host instance
*
* Returns nothing
*
* Notes: Actually decrements the counts in two sub-objects. If the
* latter refcount reaches 0, the Scsi_Host instance is freed.
* The LLD need not worry exactly when the Scsi_Host instance is
* freed, it just shouldn't access the instance after it has balanced
* out its refcount usage.
*
* Defined in: drivers/scsi/hosts.c
**/
void scsi_host_put(struct Scsi_Host *shost)
/**
......@@ -494,25 +599,7 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
*
* 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)
struct Scsi_Host * scsi_register(struct scsi_host_template *, int xtr_bytes)
/**
......@@ -668,48 +755,26 @@ void scsi_unblock_requests(struct Scsi_Host * SHpnt)
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. So if there are multiple HBAs
* associated with the given template, they are each removed. 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 are supplied (defined) by LLDs and
their function pointers are placed in an instance of struct SHT which
is passed to scsi_register() [or scsi_register_host()]. Some
are mandatory. Interface functions should be declared static. The
Interface functions are supplied (defined) by LLDs and their function
pointers are placed in an instance of struct scsi_host_template which
is passed to scsi_host_alloc() [or scsi_register() / init_this_scsi_driver()].
Some are mandatory. Interface functions should be declared static. The
accepted convention is that driver "xyz" will declare its slave_configure()
function as:
static int xyz_slave_configure(struct scsi_device * sdev);
A pointer to this function should be placed in the 'slave_configure' 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()].
of a "struct scsi_host_template" instance. A pointer to such an instance
should passed to the mid level's scsi_host_alloc() [or scsi_register() /
init_this_scsi_driver()].
The interface functions are also described in the hosts.h file immediately
above their definition point in "struct SHT". In some cases more detail
is given in hosts.h than below.
Those interface functions marked "Required: yes" must be implemented
by the LLD and a pointer to that function must be placed in the driver's
"struct SHT" instance. Interface functions marked "Required: no" need not
be implemented.
above their definition point in "struct scsi_host_template". In some cases
more detail is given in hosts.h than below.
The interface functions are listed below in alphabetical order.
......@@ -731,6 +796,7 @@ Summary:
slave_configure - driver fine tuning for given device after attach
slave_destroy - given device is about to be shut down
Details:
/**
......@@ -745,8 +811,6 @@ Details:
*
* Return value is ignored
*
* Required: no
*
* Locks: none
*
* Notes: an arbitrary geometry (based on READ CAPACITY) is used
......@@ -754,10 +818,10 @@ Details:
* pre-initialized with made up values just in case this function
* doesn't output anything.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int bios_param(struct scsi_device * sdev, struct block_device *bdev,
sector_t capacity, int params[3]);
sector_t capacity, int params[3])
/**
......@@ -768,18 +832,16 @@ Details:
* host_byte, driver_byte (status_byte is in the lsb). A value of
* 0 is an unqualified success.
*
* Required: if struct Scsi_Host::can_queue can ever by cleared (zero)
* then this function is required.
*
* Locks: struct Scsi_Host::host_lock held on entry (with "irqsave")
* and is expected to be held on return.
*
* Notes: Drivers tend to be dropping support for this function and
* supporting queuecommand() instead.
*
* Defined in: LLD
* Defined in: LLD (if struct Scsi_Host::can_queue can ever by cleared
* (zero) then this function is required)
**/
int command(struct scsi_cmnd * scp);
int command(struct scsi_cmnd * scp)
/**
......@@ -789,9 +851,6 @@ Details:
* Returns number of hosts this driver wants to control. 0 means no
* suitable hosts found.
*
* Required: yes, if "passive initialization mode" is used
* [in "hotplug initialization mode" it is not invoked]
*
* Locks: none held
*
* Notes: First function called from the SCSI mid level on this
......@@ -799,9 +858,10 @@ Details:
* For each host found, this method should call scsi_register()
* [see hosts.c].
*
* Defined in: LLD
* Defined in: LLD (required if "passive initialization mode" is used,
* not invoked in "hotplug initialization mode")
**/
int detect(struct SHT * shtp);
int detect(struct scsi_host_template * shtp)
/**
......@@ -810,17 +870,15 @@ Details:
*
* Returns SUCCESS if command aborted else FAILED
*
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return.
*
* Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int eh_abort_handler(struct scsi_cmnd * scp);
int eh_abort_handler(struct scsi_cmnd * scp)
/**
......@@ -829,17 +887,15 @@ Details:
*
* Returns SUCCESS if command aborted else FAILED
*
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return.
*
* Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int eh_bus_reset_handler(struct scsi_cmnd * scp);
int eh_bus_reset_handler(struct scsi_cmnd * scp)
/**
......@@ -848,17 +904,15 @@ Details:
*
* Returns SUCCESS if command aborted else FAILED
*
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return.
*
* Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int eh_device_reset_handler(struct scsi_cmnd * scp);
int eh_device_reset_handler(struct scsi_cmnd * scp)
/**
......@@ -867,8 +921,6 @@ Details:
*
* Returns SUCCESS if command aborted else FAILED
*
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return.
*
......@@ -879,9 +931,9 @@ Details:
* defined (or they all return FAILED) then the device in question
* will be set offline whenever eh is invoked.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int eh_host_reset_handler(struct scsi_cmnd * scp);
int eh_host_reset_handler(struct scsi_cmnd * scp)
/**
......@@ -890,16 +942,14 @@ Details:
*
* Returns TRUE if host unjammed, else FALSE.
*
* Required: no
*
* Locks: none
*
* Notes: Invoked from scsi_eh thread. Driver supplied alternate to
* Notes: Invoked from scsi_eh thread. LLD supplied alternate to
* scsi_unjam_host() found in scsi_error.c
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int eh_strategy_handler(struct Scsi_Host * shp);
int eh_strategy_handler(struct Scsi_Host * shp)
/**
......@@ -911,8 +961,6 @@ Details:
* manage the memory pointed to and maintain it, typically for the
* lifetime of this host.]
*
* Required: no
*
* Locks: none
*
* Notes: Often supplies PCI or ISA information such as IO addresses
......@@ -922,14 +970,14 @@ Details:
* The SCSI_IOCTL_PROBE_HOST ioctl yields the string returned by this
* function (or struct Scsi_Host::name if this function is not
* available).
* In a similar manner, scsi_register_host() outputs to the console
* In a similar manner, init_this_scsi_driver() outputs to the console
* each host's "info" (or name) for the driver it is registering.
* Also if proc_info() is not supplied, the output of this function
* is used instead.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
const char * info(struct Scsi_Host * shp);
const char * info(struct Scsi_Host * shp)
/**
......@@ -944,8 +992,6 @@ Details:
* Returns negative "errno" value when there is a problem. 0 or a
* positive value indicates success and is returned to the user space.
*
* Required: no
*
* Locks: none
*
* Notes: The SCSI subsystem uses a "trickle down" ioctl model.
......@@ -960,9 +1006,9 @@ Details:
* Unfortunately some applications expect -EINVAL and react badly
* when -ENOTTY is returned; stick with -EINVAL.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int ioctl(struct scsi_device *sdp, int cmd, void *arg);
int ioctl(struct scsi_device *sdp, int cmd, void *arg)
/**
......@@ -983,16 +1029,14 @@ Details:
* Returns length when 1==writeto1_read0. Otherwise number of chars
* output to buffer past offset.
*
* Required: no
*
* Locks: none held
*
* Notes: Driven from scsi_proc.c which interfaces to proc_fs
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int proc_info(char * buffer, char ** start, off_t offset,
int length, int hostno, int writeto1_read0);
int proc_info(char * buffer, char ** start, off_t offset,
int length, int hostno, int writeto1_read0)
/**
......@@ -1000,13 +1044,10 @@ int proc_info(char * buffer, char ** start, off_t offset,
* @scp: pointer to scsi command object
* @done: function pointer to be invoked on completion
*
* Returns 1 if the adapter (host) is busy, else returns 0. One
* reason for an adapter to be busy is that the number
* of outstanding queued commands is already equal to
* struct Scsi_Host::can_queue .
*
* Required: if struct Scsi_Host::can_queue is ever non-zero
* then this function is required.
* Returns 0 on success and 1 if the LLD or the HBA is busy (i.e. run
* out of resources to queue further commands). Other types of errors
* are flagged by setting struct scsi_cmnd:result to an appropriate
* value, invoking the 'done' callback, and then returning 0.
*
* Locks: struct Scsi_Host::host_lock held on entry (with "irqsave")
* and is expected to be held on return.
......@@ -1028,10 +1069,11 @@ int proc_info(char * buffer, char ** start, off_t offset,
* perform autosense and fill in the struct scsi_cmnd::sense_buffer
* array.
*
* Defined in: LLD
* Defined in: LLD (required if if struct Scsi_Host::can_queue is ever
* non-zero)
**/
int queuecommand(struct scsi_cmnd * scp,
void (*done)(struct scsi_cmnd *));
void (*done)(struct scsi_cmnd *))
/**
......@@ -1040,20 +1082,17 @@ int proc_info(char * buffer, char ** start, off_t offset,
*
* Return value ignored (could soon be a function returning void).
*
* Required: yes (see notes)
*
* Locks: none held
*
* Notes: Invoked from mid level's scsi_unregister_host().
* Notes: Invoked from scsi_module.c's exit_this_scsi_driver().
* LLD's implementation of this function should call
* scsi_unregister(shp) prior to returning.
* If not supplied mid-level [in hosts.c] supplies its own
* implementation (see scsi_host_legacy_release()) which is for old
* ISA adapters so it is best not to use it.
* Only needed for old-style host templates.
*
* Defined in: LLD
* Defined in: LLD (required in "passive initialization model",
* should not be defined in hotplug model)
**/
int release(struct Scsi_Host * shp);
int release(struct Scsi_Host * shp)
/**
......@@ -1064,8 +1103,6 @@ int proc_info(char * buffer, char ** start, off_t offset,
* Returns 0 if ok. Any other return is assumed to be an error and
* the device is ignored.
*
* Required: no
*
* Locks: none
*
* Notes: Allows the driver to allocate any resources for a device
......@@ -1076,9 +1113,9 @@ int proc_info(char * buffer, char ** start, off_t offset,
* slave_destroy() is called.
* For more details see the hosts.h file.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int slave_alloc(struct scsi_device *sdp);
int slave_alloc(struct scsi_device *sdp)
/**
......@@ -1091,17 +1128,15 @@ int proc_info(char * buffer, char ** start, off_t offset,
* the device is taken offline. [offline devices will _not_ have
* slave_destroy() called on them so clean up resources.]
*
* Required: no
*
* Locks: none
*
* Notes: Allows the driver to inspect the response to the initial
* INQUIRY done by the scanning code and take appropriate action.
* For more details see the hosts.h file.
*
* Defined in: LLD
* Optionally defined in: LLD
**/
int slave_configure(struct scsi_device *sdp);
int slave_configure(struct scsi_device *sdp)
/**
......@@ -1111,8 +1146,6 @@ int proc_info(char * buffer, char ** start, off_t offset,
*
* Returns nothing
*
* Required: no
*
* Locks: none
*
* Notes: Mid level structures for given device are still in place
......@@ -1123,17 +1156,17 @@ int proc_info(char * buffer, char ** start, off_t offset,
* of struct scsi_device would be supplied by future slave_alloc()
* and slave_configure() calls.]
*
* Defined in: LLD
* Optionally defined in: LLD
**/
void slave_destroy(struct scsi_device *sdp);
void slave_destroy(struct scsi_device *sdp)
Data Structures
===============
struct SHT
----------
There is one "struct SHT" instance per LLD ***. It is
struct scsi_host_template
-------------------------
There is one "struct scsi_host_template" instance per LLD ***. It is
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.
Member of interest:
......@@ -1143,22 +1176,23 @@ Member of interest:
by sysfs in one of its "drivers" directories. Hence
"proc_name" should only contain characters acceptable
to a Unix file name.
(*release)() - should be defined by all LLDs as the default (legacy)
implementation is only appropriate for ISA adapters).
(*queuecommand)() - primary callback that the mid level uses to inject
SCSI commands into a LLD.
The structure is defined and commented in hosts.h
*** In extreme situations a single driver may have several instances
if it controls several different classes of hardware (e.g. the
advansys driver handles both ISA and PCI cards and has a separate
instance of struct SHT for each).
if it controls several different classes of hardware (e.g. a LLD
that handles both ISA and PCI cards and has a separate instance of
struct scsi_host_template for each class).
struct Scsi_Host
----------------
There is one struct Scsi_Host instance per host (HBA) that a LLD
controls. The struct Scsi_Host structure has many members in common
with "struct SHT". When a new struct Scsi_Host instance is created (in
scsi_register() in hosts.c) those common members are initialized from
the driver's struct SHT instance. Members of interest:
with "struct scsi_host_template". When a new struct Scsi_Host instance
is created (in scsi_host_alloc() in hosts.c) those common members are
initialized from the driver's struct scsi_host_template instance. Members
of interest:
host_no - system wide unique number that is used for identifying
this host. Issued in ascending order from 0 (and the
positioning can be influenced by the scsihosts
......@@ -1180,22 +1214,22 @@ the driver's struct SHT instance. Members of interest:
0->disallow SCSI command merging
highmem_io - 1->can DMA in to or out of high memory,
0->use bounce buffers if data is in high memory
hostt - pointer to driver's struct SHT from which this
struct Scsi_Host instance was spawned
hostt - pointer to driver's struct scsi_host_template from which
this struct Scsi_Host instance was spawned
sh_list - a double linked list of pointers to all struct Scsi_Host
instances (currently ordered by ascending host_no)
my_devices - a double linked list of pointers to struct scsi_device
instances that belong to this host.
hostdata[0] - area reserved for LLD at end of struct Scsi_Host. Size
is set by the second argument (named 'xtr_bytes') to
scsi_register().
scsi_host_alloc() or scsi_register().
The structure is defined in hosts.h
struct scsi_device
------------------
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,
cahnnel number, target id and logical unit number (lun).
on a host. Scsi devices connected to a host are uniquely identified by a
channel number, target id and logical unit number (lun).
The structure is defined in scsi.h
struct scsi_cmnd
......@@ -1211,7 +1245,7 @@ The structure is defined in scsi.h
Locks
=====
Each struct Scsi_Host instance has a spin_lock called struct
Scsi_Host::default_lock which is initialized in scsi_register() [found in
Scsi_Host::default_lock which is initialized in scsi_host_alloc() [found in
hosts.c]. Within the same function the struct Scsi_Host::host_lock pointer
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
......@@ -1236,11 +1270,12 @@ detects a CHECK CONDITION status by either:
to perform an extra data in phase on such responses
b) or, the LLD issuing a REQUEST SENSE command itself
Either way, the mid level decides whether the LLD has
performed autosense by checking struct scsi_cmnd::sense_buffer[0] . If this
byte has an upper nibble of 7 (or 0xf) then autosense is assumed to have
taken place. If it has another value (and this byte is initialized to 0
before each command) then the mid level will issue a REQUEST SENSE command.
Either way, when a status of CHECK CONDITION is detected, the mid level
decides whether the LLD has performed autosense by checking struct
scsi_cmnd::sense_buffer[0] . If this byte has an upper nibble of 7 (or 0xf)
then autosense is assumed to have taken place. If it has another value (and
this byte is initialized to 0 before each command) then the mid level will
issue a REQUEST SENSE command.
In the presence of queued commands the "nexus" that maintains sense
buffer data from the command that failed until a following REQUEST SENSE
......@@ -1256,7 +1291,7 @@ one per SCSI host.
The older error handling mechanism has been removed. This means the
LLD interface functions abort() and reset() have been removed.
The struct SHT::use_new_eh_code flag has been removed.
The struct scsi_host_template::use_new_eh_code flag has been removed.
In the 2.4 series the SCSI subsystem configuration descriptions were
aggregated with the configuration descriptions from all other Linux
......@@ -1264,9 +1299,10 @@ 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
file.
Addition of slave_alloc(), slave_configure() and slave_destroy().
struct SHT has been renamed to struct scsi_host_template.
Addition of the "hotplug initialization model".
Addition of the "hotplug initialization model" and many extra functions
to support it.
Credits
......@@ -1282,4 +1318,4 @@ The following people have contributed to this document:
Douglas Gilbert
dgilbert@interlog.com
29th April 2003
18th June 2003
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