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 ...@@ -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 a SCSI host and a PCI device is common but not required (e.g. with
ISA or MCA adapters).] ISA or MCA adapters).]
This version of the document roughly matches linux kernel version 2.5.68 . The SCSI mid level isolates a LLD from other layers such as the SCSI
This document can be found in the Linux kernel source Documentation/scsi upper layer drivers and the block layer.
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 . This version of the document roughly matches linux kernel version 2.5.73 .
Documentation Documentation
============= =============
There is a SCSI documentation directory within the kernel source tree. There is a SCSI documentation directory within the kernel source tree,
That directory is typically /usr/src/linux/Documentation/scsi . Most typically /usr/src/linux/Documentation/scsi . Most documents are in plain
documents are in plain (i.e. ASCII) text. This file can be found in that (i.e. ASCII) text. This file is named scsi_mid_low_api.txt and can be
directory, named scsi_mid_low_api.txt . Many LLDs are documented there found in that directory. A more recent copy of this document may be found
(e.g. aic7xxx.txt). The SCSI mid-level is briefly described in scsi.txt at http://www.torque.net/scsi/scsi_mid_low_api.txt.gz .
(with a url to a document describing the SCSI subsystem in the lk 2.4 Many LLDs are documented there (e.g. aic7xxx.txt). The SCSI mid-level is
series). Two upper level drivers have documents in that directory: briefly described in scsi.txt which contains a url to a document
st.txt (SCSI tape driver) and scsi-generic.txt (for the sg driver). 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
Some documentation (or urls) for LLDs may be in the C source code or scsi-generic.txt (for the sg driver).
in the same directory as the C source code. For example to find a url
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 about the USB mass storage driver see the
/usr/src/linux/drivers/usb/storage directory. /usr/src/linux/drivers/usb/storage directory.
...@@ -69,12 +71,12 @@ initialization code where there are now 2 models available. The older ...@@ -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 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 that are detected at HBA driver load time. This will be referred to
the "passive" initialization model. The newer model allows HBAs to be 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 referred to as the "hotplug" initialization model. The newer model is
preferred as it can handle both traditional SCSI equipment that is preferred as it can handle both traditional SCSI equipment that is
permanently connected as well as modern "SCSI" usb-storage devices permanently connected as well as modern "SCSI" devices (e.g. USB or
(e.g. digital cameras) that are hotplugged. Both initialization models IEEE 1394 connected digital cameras) that are hotplugged. Both
are discussed in the following sections. initialization models are discussed in the following sections.
A LLD interfaces to the SCSI subsystem several ways: A LLD interfaces to the SCSI subsystem several ways:
a) directly invoking functions supplied by the mid level a) directly invoking functions supplied by the mid level
...@@ -90,21 +92,27 @@ supplied functions" below. ...@@ -90,21 +92,27 @@ supplied functions" below.
Those functions in group b) are listed in a section entitled "Interface Those functions in group b) are listed in a section entitled "Interface
functions" below. Their function pointers are placed in the members of functions" below. Their function pointers are placed in the members of
"struct SHT", an instance of which is passed to scsi_register() [or "struct scsi_host_template", an instance of which is passed to
scsi_register_host() in the passive initialization model]. Those interface scsi_host_alloc() ** . Those interface functions that the LLD does not
functions that are not mandatory and that the LLD does not wish to supply wish to supply should have NULL placed in the corresponding member of
should have NULL placed in the corresponding member of struct SHT. struct scsi_host_template. Defining an instance of struct
[Defining an instance of struct SHT at file scope will cause NULL to be scsi_host_template at file scope will cause NULL to be placed in function
placed in function pointer members not explicitly initialized.] pointer members not explicitly initialized.
Those instances in group c) are slowly being removed as they tend to be Those usages in group c) should be handled with care, especially in a
"racy" especially in a hotplug environment. "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 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 should be static. For example the slave_alloc() function in a LLD
called "xxx" could be defined as called "xxx" could be defined as
"static int xxx_slave_alloc(struct scsi_device * sdev) { /* code */ }" "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 Hotplug initialization model
============================ ============================
...@@ -116,13 +124,6 @@ detected. After confirming that the new device is one that the LLD wants ...@@ -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 to control, the LLD will initialize the HBA and then register a new host
with the SCSI mid level. 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 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). 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 This can probably be done via sysfs. Any driver parameters (especially
...@@ -135,145 +136,198 @@ is a typical sequence of calls between the LLD and the mid level. ...@@ -135,145 +136,198 @@ 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 This example shows the mid level scanning the newly introduced HBA for 3
scsi devices of which only the first 2 respond: scsi devices of which only the first 2 respond:
[HBA PROBE] HBA PROBE: assume 2 SCSI devices found in scan
LLD mid level LLD LLD mid level LLD
--- --------- --- ===-------------------=========--------------------===------
scsi_register() --> scsi_host_alloc() -->
scsi_add_host() --------+ scsi_add_host() --------+
| |
slave_alloc() slave_alloc()
slave_configure() --> scsi_adjust_queue_depth() slave_configure() --> scsi_adjust_queue_depth()
| |
slave_alloc() slave_alloc()
slave_configure() slave_configure()
| |
slave_alloc() ** slave_alloc() ***
slave_destroy() ** slave_destroy() ***
------------------------------------------------------------
If the LLD wants to adjust the default queue settings, it can invoke If the LLD wants to adjust the default queue settings, it can invoke
scsi_adjust_queue_depth() in its slave_configure() routine. 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. respond, a slave_alloc(), slave_destroy() pair is called.
Here is the corresponding sequence when a host (HBA) is being When a HBA is being removed is could as part of an orderly shutdown
removed: 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 LLD mid level LLD
--- --------- --- ===----------------------=========-----------------===------
scsi_remove_host() ---------+ scsi_remove_host() ---------+
| |
slave_destroy() slave_destroy()
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 It may be useful for a LLD to keep track of struct Scsi_Host instances
instances (a pointer is passed as the parameter to slave_alloc() and (a pointer is returned by scsi_host_alloc()). Such instances are "owned"
slave_configure() ). Both classes of instances are "owned" by the by the mid-level. struct Scsi_Host instances are freed from
mid-level. struct scsi_device instances are freed after slave_destroy(). scsi_host_put() when the reference count hits zero.
struct Scsi_Host instances are freed within scsi_unregister().
Hot unplugging a HBA that controls a disk which is processing SCSI
TODO: commands on a mounted file system is an interesting situation. Reference
Descriptions, are the following correct? counting logic is being introduced into the mid level to cope with many
[DEVICE hotplug] 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 LLD mid level LLD
--- --------- --- ===-------------------=========--------------------===------
scsi_add_device() ------+ scsi_add_device() ------+
| |
slave_alloc() slave_alloc()
slave_configure() [--> scsi_adjust_queue_depth()] 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 LLD mid level LLD
--- --------- --- ===----------------------=========-----------------===------
scsi_set_device_offline() scsi_set_device_offline()
scsi_remove_device() -------+ scsi_remove_device() -------+
| |
slave_destroy() 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 Passive initialization model
============================ ============================
LLD initialization (both built-in and module) and shutdown are "wired These older LLDs include a file called "scsi_module.c" [yes the ".c" is a
up" by passing function pointers to the module_init() and module_exit() little surprising] in their source code. For that file to work an
macros respectively. In this model the function identified by "module_init" instance of struct scsi_host_template with the name "driver_template"
must call scsi_register_host() and the function identified by "module_exit" needs to be defined. Here is a typical code sequence used in this model:
must call scsi_unregister_host(). static struct scsi_host_template driver_template = {
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;
#include "scsi_module.c" #include "scsi_module.c"
In this case "DRIVER_TEMPLATE" is defined to be a structure initializer The scsi_module.c file contains two functions:
that is placed in the driver header file by convention. It contains - init_this_scsi_driver() which is executed when the LLD is
pointers to supported interface functions and other values. 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 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 detected (so detect() returns 2) and the SCSI bus scan on each host
finds 1 SCSI device (and a second device does not respond). finds 1 SCSI device (and a second device does not respond).
LLD mid level LLD LLD mid level LLD
--- --------- --- ===----------------------=========-----------------===------
scsi_register_host() -------+ init_this_scsi_driver() ----+
| |
detect() -----------------+ detect() -----------------+
| | | |
| scsi_register() | scsi_register()
| scsi_register() | scsi_register()
| |
slave_alloc() slave_alloc()
slave_configure() --> scsi_adjust_queue_depth() slave_configure() --> scsi_adjust_queue_depth()
slave_alloc() ** slave_alloc() ***
slave_destroy() ** slave_destroy() ***
| |
slave_alloc() slave_alloc()
slave_configure() slave_configure()
slave_alloc() ** slave_alloc() ***
slave_destroy() ** slave_destroy() ***
------------------------------------------------------------
The mid level invokes scsi_adjust_queue_depth() with tagged queuing off and 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 "cmd_per_lun" for that host as the queue length. These settings can be
overridden by a slave_configure() supplied by the LLD. 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. respond, a slave_alloc(), slave_destroy() pair is called.
Here is a LLD shutdown sequence: Here is a LLD shutdown sequence:
LLD mid level LLD LLD mid level LLD
--- --------- --- ===----------------------=========-----------------===------
scsi_unregister_host() -----+ exit_this_scsi_driver() ----+
| |
slave_destroy() slave_destroy()
release() --> scsi_unregister() release() --> scsi_unregister()
| |
slave_destroy() slave_destroy()
release() --> scsi_unregister() 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 The shortcoming of the "passive initialization model" is that host
registration and de-registration are (typically) tied to LLD initialization registration and de-registration are (typically) tied to LLD initialization
and shutdown. Once the LLD is initialized then a new host that appears and shutdown. Once the LLD is initialized then a new host that appears
(e.g. via hotplugging) cannot easily be added without a redundant (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 Conventions
=========== ===========
First, Linus's thoughts on C coding can be found in the file First, Linus Torvald's thoughts on C coding style can be found in the
Documentation/CodingStyle . Documentation/CodingStyle file.
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, but
"typedef struct SHT { ...} Scsi_Host_Template;" in hosts.h . In this the typedefs have been moved to a single file, scsi_typedefs.h to
case "struct SHT" is preferred to "Scsi_Host_Template". [The poor naming make their future removal easier, for example:
example was chosen with malevolent intent.] "typedef struct scsi_host_template Scsi_Host_Template;"
Also, C99 enhancements are encouraged to the extent they are supported Also, C99 enhancements are encouraged to the extent they are supported
by the relevant gcc compilers. So "//" style comments are encouraged by the relevant gcc compilers. So "//" style comments are encouraged
...@@ -304,9 +358,11 @@ Summary: ...@@ -304,9 +358,11 @@ Summary:
scsi_bios_ptable - return copy of block device's partition table scsi_bios_ptable - return copy of block device's partition table
scsi_block_requests - prevent further commands being queued to given host scsi_block_requests - prevent further commands being queued to given host
scsi_delete_timer - cancel timer on a SCSI command. 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_partsize - parse partition table into cylinders, heads + sectors
scsi_register - create and register a scsi host adapter instance. 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_device - detach and remove a SCSI device
scsi_remove_host - detach and remove all SCSI devices owned by host scsi_remove_host - detach and remove all SCSI devices owned by host
scsi_report_bus_reset - report scsi _bus_ reset observed scsi_report_bus_reset - report scsi _bus_ reset observed
...@@ -316,8 +372,8 @@ Summary: ...@@ -316,8 +372,8 @@ Summary:
scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS
scsi_track_queue_full - track successive QUEUE_FULL events scsi_track_queue_full - track successive QUEUE_FULL events
scsi_unblock_requests - allow further commands to be queued to given host scsi_unblock_requests - allow further commands to be queued to given host
scsi_unregister - unregister and free memory used by host instance scsi_unregister - [calls scsi_host_put()]
scsi_unregister_host - unregister a low level host adapter driver
Details: Details:
...@@ -329,17 +385,17 @@ Details: ...@@ -329,17 +385,17 @@ Details:
* @lun: logical unit number * @lun: logical unit number
* *
* Returns pointer to new struct scsi_device instance or * Returns pointer to new struct scsi_device instance or
* ERR_PTR(-ENODEV) (or some other bent pointer) if something is * ERR_PTR(-ENODEV) (or some other bent pointer) if something is
* wrong (e.g. no lu responds at given address) * wrong (e.g. no lu responds at given address)
* *
* Notes: This call is usually performed internally during a scsi * Notes: This call is usually performed internally during a scsi
* bus scan when a HBA is added (i.e. scsi_add_host()). So it * bus scan when a HBA is added (i.e. scsi_add_host()). So it
* should only be called if the HBA becomes aware of a new scsi * should only be called if the HBA becomes aware of a new scsi
* device (lu) after scsi_add_host() has completed. If successful * device (lu) after scsi_add_host() has completed. If successful
* this call we lead to slave_alloc() and slave_configure() callbacks * this call we lead to slave_alloc() and slave_configure() callbacks
* into the LLD. * into the LLD.
* *
* Defined in: drivers/scsi/scsi_scan.c * Defined in: drivers/scsi/scsi_scan.c
**/ **/
struct scsi_device * scsi_add_device(struct Scsi_Host *shost, struct scsi_device * scsi_add_device(struct Scsi_Host *shost,
unsigned int channel, unsigned int channel,
...@@ -353,10 +409,10 @@ struct scsi_device * scsi_add_device(struct Scsi_Host *shost, ...@@ -353,10 +409,10 @@ struct scsi_device * scsi_add_device(struct Scsi_Host *shost,
* *
* Returns 0 on success, negative errno of failure (e.g. -ENOMEM) * Returns 0 on success, negative errno of failure (e.g. -ENOMEM)
* *
* Notes: Only required in "hotplug initialization model" after a * 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 * Defined in: drivers/scsi/hosts.c
**/ **/
int scsi_add_host(struct Scsi_Host *shost, struct device * dev) int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
...@@ -369,40 +425,40 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev) ...@@ -369,40 +425,40 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
* *
* Returns nothing * Returns nothing
* *
* Notes: Each scsi command has its own timer, and as it is added * Notes: Each scsi command has its own timer, and as it is added
* to the queue, we set up the timer. When the command completes, * to the queue, we set up the timer. When the command completes,
* we cancel the timer. A LLD can use this function to change * we cancel the timer. A LLD can use this function to change
* the existing timeout value. * the existing timeout value.
* *
* Defined in: drivers/scsi/scsi_error.c * Defined in: drivers/scsi/scsi_error.c
**/ **/
void scsi_add_timer(Scsi_Cmnd *scmd, int timeout, void (*complete) void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
(Scsi_Cmnd *)) void (*complete)(struct scsi_cmnd *))
/** /**
* scsi_adjust_queue_depth - change the queue depth on a SCSI device * scsi_adjust_queue_depth - change the queue depth on a SCSI device
* @SDpnt: pointer to SCSI device to change queue depth on * @SDpnt: pointer to SCSI device to change queue depth on
* @tagged: 0 - no tagged queuing * @tagged: 0 - no tagged queuing
* MSG_SIMPLE_TAG - simple (unordered) tagged queuing * MSG_SIMPLE_TAG - simple (unordered) tagged queuing
* MSG_ORDERED_TAG - ordered tagged queuing * MSG_ORDERED_TAG - ordered tagged queuing
* @tags Number of tags allowed if tagged queuing enabled, * @tags Number of tags allowed if tagged queuing enabled,
* or number of commands the LLD can queue up * or number of commands the LLD can queue up
* in non-tagged mode (as per cmd_per_lun). * in non-tagged mode (as per cmd_per_lun).
* *
* Returns nothing * Returns nothing
* *
* Notes: Can be invoked any time on a SCSI device controlled by this * Notes: Can be invoked any time on a SCSI device controlled by this
* LLD. [Specifically during and after slave_configure() and prior to * LLD. [Specifically during and after slave_configure() and prior to
* slave_destroy().] Can safely be invoked from interrupt code. Actual * slave_destroy().] Can safely be invoked from interrupt code. Actual
* queue depth change may be delayed until the next command is being * queue depth change may be delayed until the next command is being
* processed. * processed.
* *
* Defined in: drivers/scsi/scsi.c [see source code for more notes] * Defined in: drivers/scsi/scsi.c [see source code for more notes]
* *
**/ **/
void scsi_adjust_queue_depth(struct scsi_device * SDpnt, int tagged, void scsi_adjust_queue_depth(struct scsi_device * SDpnt, int tagged,
int num_tags) int num_tags)
/** /**
...@@ -419,13 +475,13 @@ void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock) ...@@ -419,13 +475,13 @@ void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
/** /**
* scsi_bios_ptable - return copy of block device's partition table * scsi_bios_ptable - return copy of block device's partition table
* @dev: pointer to block device * @dev: pointer to block device
* *
* Returns pointer to partition table, or NULL for failure * Returns pointer to partition table, or NULL for failure
* *
* Notes: Caller owns memory returned (free with kfree() ) * Notes: Caller owns memory returned (free with kfree() )
* *
* Defined in: drivers/scsi/scsicam.c * Defined in: drivers/scsi/scsicam.c
**/ **/
unsigned char *scsi_bios_ptable(struct block_device *dev) unsigned char *scsi_bios_ptable(struct block_device *dev)
...@@ -435,12 +491,12 @@ unsigned char *scsi_bios_ptable(struct block_device *dev) ...@@ -435,12 +491,12 @@ unsigned char *scsi_bios_ptable(struct block_device *dev)
* *
* @SHpnt: pointer to host to block commands on * @SHpnt: pointer to host to block commands on
* *
* Returns nothing * Returns nothing
* *
* Notes: There is no timer nor any other means by which the requests * Notes: There is no timer nor any other means by which the requests
* get unblocked other than the LLD calling scsi_unblock_requests(). * get unblocked other than the LLD calling scsi_unblock_requests().
* *
* Defined in: drivers/scsi/scsi_lib.c * Defined in: drivers/scsi/scsi_lib.c
**/ **/
void scsi_block_requests(struct Scsi_Host * SHpnt) void scsi_block_requests(struct Scsi_Host * SHpnt)
...@@ -450,15 +506,64 @@ void scsi_block_requests(struct Scsi_Host * SHpnt) ...@@ -450,15 +506,64 @@ void scsi_block_requests(struct Scsi_Host * SHpnt)
* @scmd: pointer to scsi command instance * @scmd: pointer to scsi command instance
* *
* Returns 1 if able to cancel timer else 0 (i.e. too late or already * Returns 1 if able to cancel timer else 0 (i.e. too late or already
* cancelled). * cancelled).
*
* Notes: All commands issued by upper levels already have a timeout
* associated with them. A LLD can use this function to cancel the
* timer.
*
* Defined in: drivers/scsi/scsi_error.c
**/
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: All commands issued by upper levels already have a timeout * Notes: Actually decrements the counts in two sub-objects. If the
* associated with them. A LLD can use this function to cancel the * latter refcount reaches 0, the Scsi_Host instance is freed.
* timer. * 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/scsi_error.c * Defined in: drivers/scsi/hosts.c
**/ **/
int scsi_delete_timer(Scsi_Cmnd *scmd) void scsi_host_put(struct Scsi_Host *shost)
/** /**
...@@ -469,11 +574,11 @@ int scsi_delete_timer(Scsi_Cmnd *scmd) ...@@ -469,11 +574,11 @@ int scsi_delete_timer(Scsi_Cmnd *scmd)
* @hds: outputs number of heads calculated via this pointer * @hds: outputs number of heads calculated via this pointer
* @secs: outputs number of sectors calculated via this pointer * @secs: outputs number of sectors calculated via this pointer
* *
* Returns 0 on success, -1 on failure * Returns 0 on success, -1 on failure
* *
* Notes: Caller owns memory returned (free with kfree() ) * Notes: Caller owns memory returned (free with kfree() )
* *
* Defined in: drivers/scsi/scsicam.c * Defined in: drivers/scsi/scsicam.c
**/ **/
int scsi_partsize(unsigned char *buf, unsigned long capacity, int scsi_partsize(unsigned char *buf, unsigned long capacity,
unsigned int *cyls, unsigned int *hds, unsigned int *secs) unsigned int *cyls, unsigned int *hds, unsigned int *secs)
...@@ -483,51 +588,33 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity, ...@@ -483,51 +588,33 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
* scsi_register - create and register a scsi host adapter instance. * scsi_register - create and register a scsi host adapter instance.
* @shost_tp: pointer to scsi host template * @shost_tp: pointer to scsi host template
* @xtr_bytes: extra bytes to allocate in hostdata array (which is the * @xtr_bytes: extra bytes to allocate in hostdata array (which is the
* last member of the returned Scsi_Host instance) * last member of the returned Scsi_Host instance)
* *
* Returns pointer to new Scsi_Host instance or NULL on failure * Returns pointer to new Scsi_Host instance or NULL on failure
* *
* Notes: When this call returns to the LLDD, the SCSI bus scan on * Notes: When this call returns to the LLDD, the SCSI bus scan on
* this host has _not_ yet been done. * this host has _not_ yet been done.
* The hostdata array (by default zero length) is a per host scratch * The hostdata array (by default zero length) is a per host scratch
* area for the LLD. * 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 . * 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)
/** /**
* scsi_remove_device - detach and remove a SCSI device * scsi_remove_device - detach and remove a SCSI device
* @sdev: a pointer to a scsi device instance * @sdev: a pointer to a scsi device instance
* *
* Returns value: 0 on success, -EINVAL if device not attached * Returns value: 0 on success, -EINVAL if device not attached
* *
* Notes: If a LLD becomes aware that a scsi device (lu) has * Notes: If a LLD becomes aware that a scsi device (lu) has
* been removed but its host is still present then it can request * been removed but its host is still present then it can request
* the removal of that scsi device. If successful this call will * the removal of that scsi device. If successful this call will
* lead to the slave_destroy() callback being invoked. sdev is an * lead to the slave_destroy() callback being invoked. sdev is an
* invalid pointer after this call. * invalid pointer after this call.
* *
* Defined in: drivers/scsi/scsi_scan.c . * Defined in: drivers/scsi/scsi_scan.c .
**/ **/
int scsi_remove_device(struct scsi_device *sdev) int scsi_remove_device(struct scsi_device *sdev)
...@@ -536,13 +623,13 @@ int scsi_remove_device(struct scsi_device *sdev) ...@@ -536,13 +623,13 @@ int scsi_remove_device(struct scsi_device *sdev)
* scsi_remove_host - detach and remove all SCSI devices owned by host * scsi_remove_host - detach and remove all SCSI devices owned by host
* @shost: a pointer to a scsi host instance * @shost: a pointer to a scsi host instance
* *
* Returns value: 0 on success, 1 on failure (e.g. LLD busy ??) * Returns value: 0 on success, 1 on failure (e.g. LLD busy ??)
* *
* Notes: Should only be invoked if the "hotplug initialization * Notes: Should only be invoked if the "hotplug initialization
* model" is being used. It should be called _prior_ to * model" is being used. It should be called _prior_ to
* scsi_unregister(). * scsi_unregister().
* *
* Defined in: drivers/scsi/hosts.c . * Defined in: drivers/scsi/hosts.c .
**/ **/
int scsi_remove_host(struct Scsi_Host *shost) int scsi_remove_host(struct Scsi_Host *shost)
...@@ -552,15 +639,15 @@ int scsi_remove_host(struct Scsi_Host *shost) ...@@ -552,15 +639,15 @@ int scsi_remove_host(struct Scsi_Host *shost)
* @shost: a pointer to a scsi host involved * @shost: a pointer to a scsi host involved
* @channel: channel (within) host on which scsi bus reset occurred * @channel: channel (within) host on which scsi bus reset occurred
* *
* Returns nothing * Returns nothing
* *
* Notes: This only needs to be called if the reset is one which * Notes: This only needs to be called if the reset is one which
* originates from an unknown location. Resets originated by the * originates from an unknown location. Resets originated by the
* mid level itself don't need to call this, but there should be * 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 * no harm. The main purpose of this is to make sure that a
* CHECK_CONDITION is properly treated. * CHECK_CONDITION is properly treated.
* *
* Defined in: drivers/scsi/scsi_lib.c . * Defined in: drivers/scsi/scsi_lib.c .
**/ **/
void scsi_report_bus_reset(struct Scsi_Host * shost, int channel) void scsi_report_bus_reset(struct Scsi_Host * shost, int channel)
...@@ -570,7 +657,7 @@ void scsi_report_bus_reset(struct Scsi_Host * shost, int channel) ...@@ -570,7 +657,7 @@ void scsi_report_bus_reset(struct Scsi_Host * shost, int channel)
* @shost: a pointer to a scsi host instance * @shost: a pointer to a scsi host instance
* @pdev: pointer to device instance to assign * @pdev: pointer to device instance to assign
* *
* Returns nothing * Returns nothing
* *
* Defined in: drivers/scsi/hosts.h . * Defined in: drivers/scsi/hosts.h .
**/ **/
...@@ -581,13 +668,13 @@ void scsi_set_device(struct Scsi_Host * shost, struct device * dev) ...@@ -581,13 +668,13 @@ void scsi_set_device(struct Scsi_Host * shost, struct device * dev)
* scsi_set_device_offline - set device offline then flush its queue * scsi_set_device_offline - set device offline then flush its queue
* @sdev: a pointer to a scsi device instance to be set offline * @sdev: a pointer to a scsi device instance to be set offline
* *
* Returns nothing * Returns nothing
* *
* Notes: Commands that are currently active on the scsi device have * Notes: Commands that are currently active on the scsi device have
* their timers cancelled and are transferred to the host's * their timers cancelled and are transferred to the host's
* "eh" list for cancellation. * "eh" list for cancellation.
* Defined in: drivers/scsi/scsi.c . * Defined in: drivers/scsi/scsi.c .
**/ **/
void scsi_set_device_offline(struct scsi_device * sdev) void scsi_set_device_offline(struct scsi_device * sdev)
...@@ -596,10 +683,10 @@ void scsi_set_device_offline(struct scsi_device * sdev) ...@@ -596,10 +683,10 @@ void scsi_set_device_offline(struct scsi_device * sdev)
* scsi_to_pci_dma_dir - convert SCSI subsystem direction flag to PCI * scsi_to_pci_dma_dir - convert SCSI subsystem direction flag to PCI
* @scsi_data_direction: SCSI subsystem direction flag * @scsi_data_direction: SCSI subsystem direction flag
* *
* Returns PCI_DMA_TODEVICE given SCSI_DATA_WRITE, * Returns PCI_DMA_TODEVICE given SCSI_DATA_WRITE,
* PCI_DMA_FROMDEVICE given SCSI_DATA_READ * PCI_DMA_FROMDEVICE given SCSI_DATA_READ
* PCI_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN * PCI_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN
* else returns PCI_DMA_NONE * else returns PCI_DMA_NONE
* *
* Defined in: drivers/scsi/scsi.h . * Defined in: drivers/scsi/scsi.h .
**/ **/
...@@ -610,10 +697,10 @@ int scsi_to_pci_dma_dir(unsigned char scsi_data_direction) ...@@ -610,10 +697,10 @@ int scsi_to_pci_dma_dir(unsigned char scsi_data_direction)
* scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS * scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS
* @scsi_data_direction: SCSI subsystem direction flag * @scsi_data_direction: SCSI subsystem direction flag
* *
* Returns SBUS_DMA_TODEVICE given SCSI_DATA_WRITE, * Returns SBUS_DMA_TODEVICE given SCSI_DATA_WRITE,
* SBUS_DMA_FROMDEVICE given SCSI_DATA_READ * SBUS_DMA_FROMDEVICE given SCSI_DATA_READ
* SBUS_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN * SBUS_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN
* else returns SBUS_DMA_NONE * else returns SBUS_DMA_NONE
* *
* Defined in: drivers/scsi/scsi.h . * Defined in: drivers/scsi/scsi.h .
**/ **/
...@@ -622,21 +709,21 @@ int scsi_to_sbus_dma_dir(unsigned char scsi_data_direction) ...@@ -622,21 +709,21 @@ int scsi_to_sbus_dma_dir(unsigned char scsi_data_direction)
/** /**
* scsi_track_queue_full - track successive QUEUE_FULL events on given * scsi_track_queue_full - track successive QUEUE_FULL events on given
* device to determine if and when there is a need * device to determine if and when there is a need
* to adjust the queue depth on the device. * to adjust the queue depth on the device.
* @SDptr: pointer to SCSI device instance * @SDptr: pointer to SCSI device instance
* @depth: Current number of outstanding SCSI commands on this device, * @depth: Current number of outstanding SCSI commands on this device,
* not counting the one returned as QUEUE_FULL. * not counting the one returned as QUEUE_FULL.
* *
* Returns 0 - no change needed * Returns 0 - no change needed
* >0 - adjust queue depth to this new depth * >0 - adjust queue depth to this new depth
* -1 - drop back to untagged operation using host->cmd_per_lun * -1 - drop back to untagged operation using host->cmd_per_lun
* as the untagged command depth * as the untagged command depth
* *
* Notes: LLDs may call this at any time and we will do "The Right * Notes: LLDs may call this at any time and we will do "The Right
* Thing"; interrupt context safe. * Thing"; interrupt context safe.
* *
* Defined in: drivers/scsi/scsi.c . * Defined in: drivers/scsi/scsi.c .
**/ **/
int scsi_track_queue_full(Scsi_Device *SDptr, int depth) int scsi_track_queue_full(Scsi_Device *SDptr, int depth)
...@@ -646,70 +733,48 @@ int scsi_track_queue_full(Scsi_Device *SDptr, int depth) ...@@ -646,70 +733,48 @@ int scsi_track_queue_full(Scsi_Device *SDptr, int depth)
* *
* @SHpnt: pointer to host to unblock commands on * @SHpnt: pointer to host to unblock commands on
* *
* Returns nothing * Returns nothing
* *
* Defined in: drivers/scsi/scsi_lib.c . * Defined in: drivers/scsi/scsi_lib.c .
**/ **/
void scsi_unblock_requests(struct Scsi_Host * SHpnt) void scsi_unblock_requests(struct Scsi_Host * SHpnt)
/** /**
* scsi_unregister - unregister and free memory used by host instance * scsi_unregister - unregister and free memory used by host instance
* @shp: pointer to scsi host instance to unregister. * @shp: pointer to scsi host instance to unregister.
* *
* Returns nothing * Returns nothing
* *
* Notes: Should only be invoked if the "hotplug initialization * Notes: Should only be invoked if the "hotplug initialization
* model" is being used. It should be called _after_ * model" is being used. It should be called _after_
* scsi_remove_host(). The shp pointer is invalid after this call. * scsi_remove_host(). The shp pointer is invalid after this call.
* *
* Defined in: drivers/scsi/hosts.c . * Defined in: drivers/scsi/hosts.c .
**/ **/
void scsi_unregister(struct Scsi_Host * shp) 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
=================== ===================
Interface functions are supplied (defined) by LLDs and Interface functions are supplied (defined) by LLDs and their function
their function pointers are placed in an instance of struct SHT which pointers are placed in an instance of struct scsi_host_template which
is passed to scsi_register() [or scsi_register_host()]. Some is passed to scsi_host_alloc() [or scsi_register() / init_this_scsi_driver()].
are mandatory. Interface functions should be declared static. The Some are mandatory. Interface functions should be declared static. The
accepted convention is that driver "xyz" will declare its slave_configure() accepted convention is that driver "xyz" will declare its slave_configure()
function as: function as:
static int xyz_slave_configure(struct scsi_device * sdev); static int xyz_slave_configure(struct scsi_device * sdev);
A pointer to this function should be placed in the 'slave_configure' member 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 of a "struct scsi_host_template" instance. A pointer to such an instance
passed to the mid level's scsi_register() [or scsi_register_host()]. 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 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 scsi_host_template". In some cases
is given in hosts.h than below. 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.
The interface functions are listed below in alphabetical order. The interface functions are listed below in alphabetical order.
...@@ -731,13 +796,14 @@ Summary: ...@@ -731,13 +796,14 @@ Summary:
slave_configure - driver fine tuning for given device after attach slave_configure - driver fine tuning for given device after attach
slave_destroy - given device is about to be shut down slave_destroy - given device is about to be shut down
Details: Details:
/** /**
* 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 512 byte 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 (max 255) * params[0] number of heads (max 255)
* params[1] number of sectors (max 63) * params[1] number of sectors (max 63)
...@@ -745,8 +811,6 @@ Details: ...@@ -745,8 +811,6 @@ Details:
* *
* Return value is ignored * Return value is ignored
* *
* Required: no
*
* Locks: none * Locks: none
* *
* Notes: an arbitrary geometry (based on READ CAPACITY) is used * Notes: an arbitrary geometry (based on READ CAPACITY) is used
...@@ -754,10 +818,10 @@ Details: ...@@ -754,10 +818,10 @@ Details:
* pre-initialized with made up values just in case this function * pre-initialized with made up values just in case this function
* doesn't output anything. * doesn't output anything.
* *
* Defined in: LLD * Optionally defined in: LLD
**/ **/
int bios_param(struct scsi_device * sdev, struct block_device *bdev, 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: ...@@ -768,18 +832,16 @@ Details:
* host_byte, driver_byte (status_byte is in the lsb). A value of * host_byte, driver_byte (status_byte is in the lsb). A value of
* 0 is an unqualified success. * 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") * Locks: struct Scsi_Host::host_lock held on entry (with "irqsave")
* 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
* supporting queuecommand() instead. * 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: ...@@ -789,9 +851,6 @@ Details:
* 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, 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
...@@ -799,9 +858,10 @@ Details: ...@@ -799,9 +858,10 @@ Details:
* 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].
* *
* 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: ...@@ -810,17 +870,15 @@ Details:
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry * Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return. * and assumed to be held on return.
* *
* Notes: Invoked from scsi_eh thread. No other commands will be * Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh. * 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: ...@@ -829,17 +887,15 @@ Details:
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry * Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return. * and assumed to be held on return.
* *
* Notes: Invoked from scsi_eh thread. No other commands will be * Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh. * 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: ...@@ -848,17 +904,15 @@ Details:
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry * Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return. * and assumed to be held on return.
* *
* Notes: Invoked from scsi_eh thread. No other commands will be * Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh. * 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,10 +921,8 @@ Details: ...@@ -867,10 +921,8 @@ Details:
* *
* Returns SUCCESS if command aborted else FAILED * Returns SUCCESS if command aborted else FAILED
* *
* Required: no
*
* Locks: struct Scsi_Host::host_lock held (with irqsave) on entry * Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
* and assumed to be held on return. * and assumed to be held on return.
* *
* Notes: Invoked from scsi_eh thread. No other commands will be * Notes: Invoked from scsi_eh thread. No other commands will be
* queued on current host during eh. * queued on current host during eh.
...@@ -879,9 +931,9 @@ Details: ...@@ -879,9 +931,9 @@ Details:
* defined (or they all return FAILED) then the device in question * defined (or they all return FAILED) then the device in question
* will be set offline whenever eh is invoked. * 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: ...@@ -890,16 +942,14 @@ Details:
* *
* Returns TRUE if host unjammed, else FALSE. * Returns TRUE if host unjammed, else FALSE.
* *
* Required: no
*
* Locks: none * 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 * 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: ...@@ -911,8 +961,6 @@ Details:
* manage the memory pointed to and maintain it, typically for the * manage the memory pointed to and maintain it, typically for the
* lifetime of this host.] * lifetime of this host.]
* *
* Required: no
*
* Locks: none * Locks: none
* *
* Notes: Often supplies PCI or ISA information such as IO addresses * Notes: Often supplies PCI or ISA information such as IO addresses
...@@ -921,15 +969,15 @@ Details: ...@@ -921,15 +969,15 @@ Details:
* (i.e. does not included embedded newlines). * (i.e. does not included embedded newlines).
* The SCSI_IOCTL_PROBE_HOST ioctl yields the string returned by this * The SCSI_IOCTL_PROBE_HOST ioctl yields the string returned by this
* function (or struct Scsi_Host::name if this function is not * function (or struct Scsi_Host::name if this function is not
* available). * 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. * each host's "info" (or name) for the driver it is registering.
* Also if proc_info() is not supplied, the output of this function * Also if proc_info() is not supplied, the output of this function
* is used instead. * 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: ...@@ -944,8 +992,6 @@ Details:
* Returns negative "errno" value when there is a problem. 0 or a * Returns negative "errno" value when there is a problem. 0 or a
* positive value indicates success and is returned to the user space. * positive value indicates success and is returned to the user space.
* *
* Required: no
*
* Locks: none * Locks: none
* *
* Notes: The SCSI subsystem uses a "trickle down" ioctl model. * Notes: The SCSI subsystem uses a "trickle down" ioctl model.
...@@ -958,11 +1004,11 @@ Details: ...@@ -958,11 +1004,11 @@ Details:
* However the mid level returns -EINVAL for unrecognized 'cmd' * However the mid level returns -EINVAL for unrecognized 'cmd'
* numbers when this function is not supplied by the driver. * numbers when this function is not supplied by the driver.
* Unfortunately some applications expect -EINVAL and react badly * Unfortunately some applications expect -EINVAL and react badly
* when -ENOTTY is returned; stick with -EINVAL. * 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: ...@@ -983,16 +1029,14 @@ Details:
* Returns length when 1==writeto1_read0. Otherwise number of chars * Returns length when 1==writeto1_read0. Otherwise number of chars
* output to buffer past offset. * output to buffer past offset.
* *
* Required: no
*
* Locks: none held * Locks: none held
* *
* Notes: Driven from scsi_proc.c which interfaces to proc_fs * 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 proc_info(char * buffer, char ** start, off_t offset,
int length, int hostno, int writeto1_read0); int length, int hostno, int writeto1_read0)
/** /**
...@@ -1000,13 +1044,10 @@ int proc_info(char * buffer, char ** start, off_t offset, ...@@ -1000,13 +1044,10 @@ int proc_info(char * buffer, char ** start, off_t offset,
* @scp: pointer to scsi command object * @scp: pointer to scsi command object
* @done: function pointer to be invoked on completion * @done: function pointer to be invoked on completion
* *
* Returns 1 if the adapter (host) is busy, else returns 0. One * Returns 0 on success and 1 if the LLD or the HBA is busy (i.e. run
* reason for an adapter to be busy is that the number * out of resources to queue further commands). Other types of errors
* of outstanding queued commands is already equal to * are flagged by setting struct scsi_cmnd:result to an appropriate
* struct Scsi_Host::can_queue . * value, invoking the 'done' callback, and then returning 0.
*
* Required: if struct Scsi_Host::can_queue is ever non-zero
* then this function is required.
* *
* Locks: struct Scsi_Host::host_lock held on entry (with "irqsave") * Locks: struct Scsi_Host::host_lock held on entry (with "irqsave")
* and is expected to be held on return. * and is expected to be held on return.
...@@ -1024,14 +1065,15 @@ int proc_info(char * buffer, char ** start, off_t offset, ...@@ -1024,14 +1065,15 @@ int proc_info(char * buffer, char ** start, off_t offset,
* 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 LLD 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.
* *
* Defined in: LLD * Defined in: LLD (required if if struct Scsi_Host::can_queue is ever
* non-zero)
**/ **/
int queuecommand(struct scsi_cmnd * scp, int queuecommand(struct scsi_cmnd * scp,
void (*done)(struct scsi_cmnd *)); void (*done)(struct scsi_cmnd *))
/** /**
...@@ -1040,100 +1082,91 @@ int proc_info(char * buffer, char ** start, off_t offset, ...@@ -1040,100 +1082,91 @@ int proc_info(char * buffer, char ** start, off_t offset,
* *
* Return value ignored (could soon be a function returning void). * Return value ignored (could soon be a function returning void).
* *
* Required: yes (see notes)
*
* Locks: none held * 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 * LLD's implementation of this function should call
* scsi_unregister(shp) prior to returning. * scsi_unregister(shp) prior to returning.
* If not supplied mid-level [in hosts.c] supplies its own * Only needed for old-style host templates.
* implementation (see scsi_host_legacy_release()) which is for old
* ISA adapters so it is best not to use it.
* *
* 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)
/** /**
* slave_alloc - prior to any commands being sent to a new device * slave_alloc - prior to any commands being sent to a new device
* (i.e. just prior to scan) this call is made * (i.e. just prior to scan) this call is made
* @sdp: pointer to new device (about to be scanned) * @sdp: pointer to new device (about to be scanned)
* *
* Returns 0 if ok. Any other return is assumed to be an error and * Returns 0 if ok. Any other return is assumed to be an error and
* the device is ignored. * the device is ignored.
*
* Required: no
* *
* Locks: none * Locks: none
* *
* Notes: Allows the driver to allocate any resources for a device * Notes: Allows the driver to allocate any resources for a device
* prior to its initial scan. The corresponding scsi device may not * prior to its initial scan. The corresponding scsi device may not
* exist but the mid level is just about to scan for it (i.e. send * exist but the mid level is just about to scan for it (i.e. send
* and INQUIRY command plus ...). If a device is found then * and INQUIRY command plus ...). If a device is found then
* slave_configure() will be called while if a device is not found * slave_configure() will be called while if a device is not found
* slave_destroy() is called. * slave_destroy() is called.
* For more details see the hosts.h file. * 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)
/** /**
* slave_configure - driver fine tuning for given device just after it * slave_configure - driver fine tuning for given device just after it
* has been first scanned (i.e. it responded to an * has been first scanned (i.e. it responded to an
* INQUIRY) * INQUIRY)
* @sdp: device that has just been attached * @sdp: device that has just been attached
* *
* Returns 0 if ok. Any other return is assumed to be an error and * Returns 0 if ok. Any other return is assumed to be an error and
* the device is taken offline. [offline devices will _not_ have * the device is taken offline. [offline devices will _not_ have
* slave_destroy() called on them so clean up resources.] * slave_destroy() called on them so clean up resources.]
*
* Required: no
* *
* Locks: none * Locks: none
* *
* Notes: Allows the driver to inspect the response to the initial * Notes: Allows the driver to inspect the response to the initial
* INQUIRY done by the scanning code and take appropriate action. * INQUIRY done by the scanning code and take appropriate action.
* For more details see the hosts.h file. * 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)
/** /**
* slave_destroy - given device is about to be shut down. All * slave_destroy - given device is about to be shut down. All
* activity has ceased on this device. * activity has ceased on this device.
* @sdp: device that is about to be shut down * @sdp: device that is about to be shut down
* *
* Returns nothing * Returns nothing
* *
* Required: no
*
* Locks: none * Locks: none
* *
* Notes: Mid level structures for given device are still in place * Notes: Mid level structures for given device are still in place
* but are about to be torn down. Any per device resources allocated * but are about to be torn down. Any per device resources allocated
* by this driver for given device should be freed now. No further * by this driver for given device should be freed now. No further
* commands will be sent for this sdp instance. [However the device * commands will be sent for this sdp instance. [However the device
* could be re-attached in the future in which case a new instance * could be re-attached in the future in which case a new instance
* of struct scsi_device would be supplied by future slave_alloc() * of struct scsi_device would be supplied by future slave_alloc()
* and slave_configure() calls.] * 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 Data Structures
=============== ===============
struct SHT struct scsi_host_template
---------- -------------------------
There is one "struct SHT" instance per LLD ***. It is 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 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:
...@@ -1143,22 +1176,23 @@ Member of interest: ...@@ -1143,22 +1176,23 @@ Member of interest:
by sysfs in one of its "drivers" directories. Hence by sysfs in one of its "drivers" directories. Hence
"proc_name" should only contain characters acceptable "proc_name" should only contain characters acceptable
to a Unix file name. to a Unix file name.
(*release)() - should be defined by all LLDs as the default (legacy) (*queuecommand)() - primary callback that the mid level uses to inject
implementation is only appropriate for ISA adapters). SCSI commands into a LLD.
The structure is defined and commented in hosts.h The structure is defined and commented in hosts.h
*** In extreme situations a single driver may have several instances *** In extreme situations a single driver may have several instances
if it controls several different classes of hardware (e.g. the if it controls several different classes of hardware (e.g. a LLD
advansys driver handles both ISA and PCI cards and has a separate that handles both ISA and PCI cards and has a separate instance of
instance of struct SHT for each). struct scsi_host_template for each class).
struct Scsi_Host struct Scsi_Host
---------------- ----------------
There is one struct Scsi_Host instance per host (HBA) that a LLD There is one struct Scsi_Host instance per host (HBA) that a LLD
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 scsi_host_template". When a new struct Scsi_Host instance
scsi_register() in hosts.c) those common members are initialized from is created (in scsi_host_alloc() in hosts.c) those common members are
the driver's struct SHT instance. Members of interest: initialized from the driver's struct scsi_host_template instance. Members
of interest:
host_no - system wide unique number that is used for identifying host_no - system wide unique number that is used for identifying
this host. Issued in ascending order from 0 (and the this host. Issued in ascending order from 0 (and the
positioning can be influenced by the scsihosts positioning can be influenced by the scsihosts
...@@ -1172,7 +1206,7 @@ the driver's struct SHT instance. Members of interest: ...@@ -1172,7 +1206,7 @@ the driver's struct SHT instance. Members of interest:
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. Overridden by LLD calls to controlled by the host. Overridden by LLD calls to
scsi_adjust_queue_depth(). 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
...@@ -1180,22 +1214,22 @@ the driver's struct SHT instance. Members of interest: ...@@ -1180,22 +1214,22 @@ the driver's struct SHT instance. Members of interest:
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 scsi_host_template from which
struct Scsi_Host instance was spawned this struct Scsi_Host instance was spawned
sh_list - a double linked list of pointers to all struct Scsi_Host sh_list - a double linked list of pointers to all struct Scsi_Host
instances (currently ordered by ascending host_no) instances (currently ordered by ascending host_no)
my_devices - a double linked list of pointers to struct scsi_device my_devices - a double linked list of pointers to struct scsi_device
instances that belong to this host. instances that belong to this host.
hostdata[0] - area reserved for LLD at end of struct Scsi_Host. Size hostdata[0] - area reserved for LLD at end of struct Scsi_Host. Size
is set by the second argument (named 'xtr_bytes') to 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 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 connected to a host are uniquely identified by a
cahnnel number, target id and logical unit number (lun). channel number, 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
...@@ -1211,7 +1245,7 @@ The structure is defined in scsi.h ...@@ -1211,7 +1245,7 @@ The structure is defined in scsi.h
Locks Locks
===== =====
Each struct Scsi_Host instance has a spin_lock called struct 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 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. 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
...@@ -1236,11 +1270,12 @@ detects a CHECK CONDITION status by either: ...@@ -1236,11 +1270,12 @@ detects a CHECK CONDITION status by either:
to perform an extra data in phase on such responses to perform an extra data in phase on such responses
b) or, the LLD issuing a REQUEST SENSE command itself b) or, the LLD issuing a REQUEST SENSE command itself
Either way, the mid level decides whether the LLD has Either way, when a status of CHECK CONDITION is detected, the mid level
performed autosense by checking struct scsi_cmnd::sense_buffer[0] . If this decides whether the LLD has performed autosense by checking struct
byte has an upper nibble of 7 (or 0xf) then autosense is assumed to have scsi_cmnd::sense_buffer[0] . If this byte has an upper nibble of 7 (or 0xf)
taken place. If it has another value (and this byte is initialized to 0 then autosense is assumed to have taken place. If it has another value (and
before each command) then the mid level will issue a REQUEST SENSE command. 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 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
...@@ -1256,7 +1291,7 @@ one per SCSI host. ...@@ -1256,7 +1291,7 @@ 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
LLD 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 scsi_host_template::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
...@@ -1264,9 +1299,10 @@ subsystems in the Documentation/Configure.help file. In the 2.5 series, ...@@ -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 the SCSI subsystem now has its own (much smaller) drivers/scsi/Config.help
file. 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 Credits
...@@ -1275,11 +1311,11 @@ The following people have contributed to this document: ...@@ -1275,11 +1311,11 @@ 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> Christoph Hellwig <hch@infradead.org>
Doug Ledford <dledford@redhat.com> Doug Ledford <dledford@redhat.com>
Andries Brouwer <Andries.Brouwer@cwi.nl> Andries Brouwer <Andries.Brouwer@cwi.nl>
Douglas Gilbert Douglas Gilbert
dgilbert@interlog.com 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