Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / Documentation / scsi / scsi_mid_low_api.txt
index 463dfc7..75a535a 100644 (file)
@@ -8,11 +8,11 @@ This document outlines the interface between the Linux SCSI mid level and
 SCSI lower level drivers. Lower level drivers (LLDs) are variously called 
 host bus adapter (HBA) drivers and host drivers (HD). A "host" in this
 context is a bridge between a computer IO bus (e.g. PCI or ISA) and a
-single SCSI initiator device on a SCSI transport. An "initiator" device
-(SCSI terminology) sends SCSI commands to "target" SCSI devices (e.g.
-disks). There can be many LLDs in a running system, but only one per
-hardware type. Most LLDs can control one or more SCSI HBAs. Some HBAs 
-contain multiple hosts.
+single SCSI initiator port on a SCSI transport. An "initiator" port
+(SCSI terminology, see SAM-3 at http://www.t10.org) sends SCSI commands
+to "target" SCSI ports (e.g. disks). There can be many LLDs in a running
+system, but only one per hardware type. Most LLDs can control one or more
+SCSI HBAs. Some HBAs contain multiple hosts.
 
 In some cases the SCSI transport is an external bus that already has
 its own subsystem in Linux (e.g. USB and ieee1394). In such cases the
@@ -35,7 +35,7 @@ ISA or MCA adapters).]
 The SCSI mid level isolates an 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.6.0-test4.
+This version of the document roughly matches linux kernel version 2.6..
 
 Documentation
 =============
@@ -150,7 +150,8 @@ scsi devices of which only the first 2 respond:
 LLD                   mid level                    LLD
 ===-------------------=========--------------------===------
 scsi_host_alloc()  -->
-scsi_add_host()  --------+
+scsi_add_host()  ---->
+scsi_scan_host()  -------+
                          |
                     slave_alloc()
                     slave_configure() -->  scsi_adjust_queue_depth()
@@ -196,7 +197,7 @@ of the issues involved. See the section on reference counting below.
 
 
 The hotplug concept may be extended to SCSI devices. Currently, when an
-HBA is added, the scsi_add_host() function causes a scan for SCSI devices
+HBA is added, the scsi_scan_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.
 An LLD can use this sequence to make the mid level aware of a SCSI device:
@@ -323,6 +324,16 @@ struct Scsi_Host:
         instance. If the reference count reaches 0 then the given instance
         is freed
 
+The Scsi_device structure has had reference counting infrastructure added.
+This effectively spreads the ownership of struct Scsi_device instances
+across the various SCSI layers which use them. Previously such instances
+were exclusively owned by the mid level. See the access functions declared
+towards the end of include/scsi/scsi_device.h . If an LLD wants to keep
+a copy of a pointer to a Scsi_device instance it should use scsi_device_get()
+to bump its reference count. When it is finished with the pointer it can
+use scsi_device_put() to decrement its reference count (and potentially
+delete it).
+
 ^^ struct Scsi_Host actually has 2 reference counts which are manipulated
 in parallel by these functions.
 
@@ -336,7 +347,7 @@ Next, there is a movement to "outlaw" typedefs introducing synonyms for
 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;"
+"typedef struct scsi_cmnd Scsi_Cmnd;"
 
 Also, most C99 enhancements are encouraged to the extent they are supported
 by the relevant gcc compilers. So C99 style structure and array
@@ -353,21 +364,21 @@ and Adaptec have their own coding conventions.
 Mid level supplied functions
 ============================
 These functions are supplied by the SCSI mid level for use by LLDs.
-The names (i.e. entry points) of these functions are exported (mainly in 
-scsi_syms.c) so an LLD that is a module can access them. The kernel will
+The names (i.e. entry points) of these functions are exported 
+so an LLD that is a module can access them. The kernel will
 arrange for the SCSI mid level to be loaded and initialized before any LLD
 is initialized. The functions below are listed alphabetically and their
 names all start with "scsi_".
 
 Summary:
+   scsi_activate_tcq - turn on tag command queueing
    scsi_add_device - creates new scsi device (lu) instance
-   scsi_add_host - perform sysfs registration and SCSI bus scan.
-   scsi_add_timer - (re-)start timer on a SCSI command.
+   scsi_add_host - perform sysfs registration and set up transport class
    scsi_adjust_queue_depth - change the queue depth on a SCSI device
    scsi_assign_lock - replace default host_lock with given lock
    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_deactivate_tcq - turn off tag command queueing
    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)
@@ -376,9 +387,7 @@ Summary:
    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
-   scsi_set_device - place device reference in host structure
-   scsi_to_pci_dma_dir - convert SCSI subsystem direction flag to PCI
-   scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS
+   scsi_scan_host - scan SCSI bus
    scsi_track_queue_full - track successive QUEUE_FULL events 
    scsi_unblock_requests - allow further commands to be queued to given host
    scsi_unregister - [calls scsi_host_put()]
@@ -386,6 +395,24 @@ Summary:
 
 Details:
 
+/**
+ * scsi_activate_tcq - turn on tag command queueing ("ordered" task attribute)
+ * @sdev:       device to turn on TCQ for
+ * @depth:      queue depth
+ *
+ *      Returns nothing
+ *
+ *      Might block: no
+ *
+ *      Notes: Eventually, it is hoped depth would be the maximum depth
+ *      the device could cope with and the real queue depth
+ *      would be adjustable from 0 to depth.
+ *
+ *      Defined (inline) in: include/scsi/scsi_tcq.h
+ **/
+void scsi_activate_tcq(struct scsi_device *sdev, int depth)
+
+
 /**
  * scsi_add_device - creates new scsi device (lu) instance
  * @shost:   pointer to scsi host instance
@@ -400,10 +427,10 @@ Details:
  *      Might block: yes
  *
  *      Notes: This call is usually performed internally during a scsi
- *      bus scan when an HBA is added (i.e. scsi_add_host()). So it
+ *      bus scan when an HBA is added (i.e. scsi_scan_host()). So it
  *      should only be called if the HBA becomes aware of a new scsi
- *      device (lu) after scsi_add_host() has completed. If successful
- *      this call we lead to slave_alloc() and slave_configure() callbacks
+ *      device (lu) after scsi_scan_host() has completed. If successful
+ *      this call can lead to slave_alloc() and slave_configure() callbacks
  *      into the LLD.
  *
  *      Defined in: drivers/scsi/scsi_scan.c
@@ -414,16 +441,20 @@ struct scsi_device * scsi_add_device(struct Scsi_Host *shost,
 
 
 /**
- * scsi_add_host - perform sysfs registration and SCSI bus scan.
+ * scsi_add_host - perform sysfs registration and set up transport class
  * @shost:   pointer to scsi host instance
- * @dev:     pointer to struct device host instance
+ * @dev:     pointer to struct device of type scsi class
  *
  *      Returns 0 on success, negative errno of failure (e.g. -ENOMEM)
  *
  *      Might block: no
  *
  *      Notes: Only required in "hotplug initialization model" after a
- *      successful call to scsi_host_alloc().
+ *      successful call to scsi_host_alloc().  This function does not
+ *     scan the bus; this can be done by calling scsi_scan_host() or
+ *     in some other transport-specific way.  The LLD must set up
+ *     the transport template before calling this function and may only
+ *     access the transport class data after this function has been called.
  *
  *      Defined in: drivers/scsi/hosts.c
  **/
@@ -431,31 +462,10 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
 
 
 /**
- * scsi_add_timer - (re-)start timer on a SCSI command.
- * @scmd:    pointer to scsi command instance
- * @timeout: duration of timeout in "jiffies"
- * @complete: pointer to function to call if timeout expires
- *
- *      Returns nothing
- *
- *      Might block: no
- *
- *      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, 
- *      we cancel the timer. An LLD can use this function to change
- *      the existing timeout value.
- *
- *      Defined in: drivers/scsi/scsi_error.c
- **/
-void scsi_add_timer(struct scsi_cmnd *scmd, int timeout, 
-                    void (*complete)(struct scsi_cmnd *))
-
-
-/**
- * scsi_adjust_queue_depth - change the queue depth on a SCSI device
- * @SDpnt:      pointer to SCSI device to change queue depth on
+ * scsi_adjust_queue_depth - allow LLD to change queue depth on a SCSI device
+ * @sdev:       pointer to SCSI device to change queue depth on
  * @tagged:     0 - no tagged queuing
- *              MSG_SIMPLE_TAG - simple (unordered) tagged queuing
+ *              MSG_SIMPLE_TAG - simple tagged queuing
  *              MSG_ORDERED_TAG - ordered tagged queuing
  * @tags        Number of tags allowed if tagged queuing enabled,
  *              or number of commands the LLD can queue up
@@ -469,13 +479,13 @@ void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
  *      LLD. [Specifically during and after slave_configure() and prior to
  *      slave_destroy().] Can safely be invoked from interrupt code. Actual
  *      queue depth change may be delayed until the next command is being
- *      processed.
+ *      processed. See also scsi_activate_tcq() and scsi_deactivate_tcq().
  *
  *      Defined in: drivers/scsi/scsi.c [see source code for more notes]
  *
  **/
-void scsi_adjust_queue_depth(struct scsi_device * SDpnt, int tagged, 
-                             int num_tags)
+void scsi_adjust_queue_depth(struct scsi_device * sdev, int tagged, 
+                             int tags)
 
 
 /**
@@ -510,7 +520,7 @@ unsigned char *scsi_bios_ptable(struct block_device *dev)
 /**
  * scsi_block_requests - prevent further commands being queued to given host
  *
- * @SHpnt: pointer to host to block commands on
+ * @shost: pointer to host to block commands on
  *
  *      Returns nothing
  *
@@ -521,31 +531,28 @@ unsigned char *scsi_bios_ptable(struct block_device *dev)
  *
  *      Defined in: drivers/scsi/scsi_lib.c
 **/
-void scsi_block_requests(struct Scsi_Host * SHpnt)
+void scsi_block_requests(struct Scsi_Host * shost)
 
 
 /**
- * scsi_delete_timer - cancel timer on a SCSI command.
- * @scmd:    pointer to scsi command instance
- *
- *      Returns 1 if able to cancel timer else 0 (i.e. too late or already
- *      cancelled).
+ * scsi_deactivate_tcq - turn off tag command queueing
+ * @sdev:       device to turn off TCQ for
+ * @depth:      queue depth (stored in sdev)
  *
- *      Might block: no [may in the future if it invokes del_timer_sync()]
+ *      Returns nothing
  *
- *      Notes: All commands issued by upper levels already have a timeout
- *      associated with them. An LLD can use this function to cancel the
- *      timer.
+ *      Might block: no
  *
- *      Defined in: drivers/scsi/scsi_error.c
+ *      Defined (inline) in: include/scsi/scsi_tcq.h
  **/
-int scsi_delete_timer(struct scsi_cmnd *scmd)
+void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
 
 
 /**
- * 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
+ * scsi_host_alloc - create a scsi host adapter instance and perform basic
+ *                   initialization.
+ * @sht:        pointer to scsi host template
+ * @privsize:   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
@@ -555,12 +562,15 @@ int scsi_delete_timer(struct scsi_cmnd *scmd)
  *      Notes: When this call returns to the LLD, 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.
+ *      area for the LLD's exclusive use.
  *      Both associated refcounting objects have their refcount set to 1.
+ *      Full registration (in sysfs) and a bus scan are performed later when
+ *      scsi_add_host() and scsi_scan_host() are called.
  *
  *      Defined in: drivers/scsi/hosts.c .
  **/
-struct Scsi_Host * scsi_host_alloc(struct scsi_host_template *, int xtr_bytes)
+struct Scsi_Host * scsi_host_alloc(struct scsi_host_template * sht,
+                                   int privsize)
 
 
 /**
@@ -619,8 +629,8 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
 
 /**
  * scsi_register - create and register a scsi host adapter instance.
- * @shost_tp:   pointer to scsi host template
- * @xtr_bytes:  extra bytes to allocate in hostdata array (which is the
+ * @sht:        pointer to scsi host template
+ * @privsize:   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
@@ -634,7 +644,8 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
  *
  *      Defined in: drivers/scsi/hosts.c .
  **/
-struct Scsi_Host * scsi_register(struct scsi_host_template *, int xtr_bytes)
+struct Scsi_Host * scsi_register(struct scsi_host_template * sht,
+                                 int privsize)
 
 
 /**
@@ -694,62 +705,23 @@ void scsi_report_bus_reset(struct Scsi_Host * shost, int channel)
 
 
 /**
- * scsi_set_device - place device reference in host structure
+ * scsi_scan_host - scan SCSI bus
  * @shost: a pointer to a scsi host instance
- * @pdev: pointer to device instance to assign
- *
- *      Returns nothing
- *
- *      Might block: no
- *
- *      Defined in: include/scsi/scsi_host.h .
- **/
-void scsi_set_device(struct Scsi_Host * shost, struct device * dev)
-
-
-/**
- * scsi_to_pci_dma_dir - convert SCSI subsystem direction flag to PCI
- * @scsi_data_direction: SCSI subsystem direction flag
  *
- *      Returns PCI_DMA_TODEVICE given SCSI_DATA_WRITE,
- *              PCI_DMA_FROMDEVICE given SCSI_DATA_READ
- *              PCI_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN
- *              else returns PCI_DMA_NONE
- *
- *      Might block: no
+ *     Might block: yes
  *
- *      Notes: The SCSI subsystem now uses the same values for these
- *      constants as the PCI subsystem so this function is a nop.
+ *     Notes: Should be called after scsi_add_host()
  *
- *      Defined in: drivers/scsi/scsi.h .
+ *     Defined in: drivers/scsi/scsi_scan.c
  **/
-int scsi_to_pci_dma_dir(unsigned char scsi_data_direction)
-
-
-/**
- * scsi_to_sbus_dma_dir - convert SCSI subsystem direction flag to SBUS
- * @scsi_data_direction: SCSI subsystem direction flag
- *
- *      Returns SBUS_DMA_TODEVICE given SCSI_DATA_WRITE,
- *              SBUS_DMA_FROMDEVICE given SCSI_DATA_READ
- *              SBUS_DMA_BIDIRECTIONAL given SCSI_DATA_UNKNOWN
- *              else returns SBUS_DMA_NONE
- *
- *      Notes: The SCSI subsystem now uses the same values for these
- *      constants as the SBUS subsystem so this function is a nop.
- *
- *      Might block: no
- *
- *      Defined in: drivers/scsi/scsi.h .
- **/
-int scsi_to_sbus_dma_dir(unsigned char scsi_data_direction)
+void scsi_scan_host(struct Scsi_Host *shost)
 
 
 /**
  * scsi_track_queue_full - track successive QUEUE_FULL events on given
  *                      device to determine if and when there is a need
  *                      to adjust the queue depth on the device.
- * @SDptr: pointer to SCSI device instance
+ * @sdev:  pointer to SCSI device instance
  * @depth: Current number of outstanding SCSI commands on this device,
  *         not counting the one returned as QUEUE_FULL.
  *
@@ -765,13 +737,13 @@ int scsi_to_sbus_dma_dir(unsigned char scsi_data_direction)
  *
  *      Defined in: drivers/scsi/scsi.c .
  **/
-int scsi_track_queue_full(Scsi_Device *SDptr, int depth)
+int scsi_track_queue_full(struct scsi_device *sdev, int depth)
 
 
 /**
  * scsi_unblock_requests - allow further commands to be queued to given host
  *
- * @SHpnt: pointer to host to unblock commands on
+ * @shost: pointer to host to unblock commands on
  *
  *      Returns nothing
  *
@@ -779,7 +751,7 @@ int scsi_track_queue_full(Scsi_Device *SDptr, int depth)
  *
  *      Defined in: drivers/scsi/scsi_lib.c .
 **/
-void scsi_unblock_requests(struct Scsi_Host * SHpnt)
+void scsi_unblock_requests(struct Scsi_Host * shost)
 
 
 /**
@@ -832,7 +804,6 @@ Summary:
    eh_bus_reset_handler - issue SCSI bus reset
    eh_device_reset_handler - issue SCSI device reset
    eh_host_reset_handler - reset host (host bus adapter)
-   eh_strategy_handler - driver supplied alternate to scsi_unjam_host()
    info - supply information about given host
    ioctl - driver can respond to ioctls
    proc_info - supports /proc/scsi/{driver_name}/{host_no}
@@ -901,20 +872,20 @@ Details:
  *
  *      Returns:
  *
- *     EH_HANDLED:             I fixed the error, please complete the command
- *     EH_RESET_TIMER:         I need more time, reset the timer and
- *                             begin counting again
- *     EH_NOT_HANDLED          Begin normal error recovery
-
+ *      EH_HANDLED:             I fixed the error, please complete the command
+ *      EH_RESET_TIMER:         I need more time, reset the timer and
+ *                              begin counting again
+ *      EH_NOT_HANDLED          Begin normal error recovery
+ *
  *
  *      Locks: None held
  *
  *      Calling context: interrupt
  *
- *     Notes: This is to give the LLD an opportunity to do local recovery.
- *     This recovery is limited to determining if the outstanding command
- *     will ever complete.  You may not abort and restart the command from
- *     this callback.
+ *      Notes: This is to give the LLD an opportunity to do local recovery.
+ *      This recovery is limited to determining if the outstanding command
+ *      will ever complete.  You may not abort and restart the command from
+ *      this callback.
  *
  *      Optionally defined in: LLD
  **/
@@ -927,8 +898,7 @@ Details:
  *
  *      Returns SUCCESS if command aborted else FAILED
  *
- *      Locks: struct Scsi_Host::host_lock held (with irqsave) on entry 
- *      and assumed to be held on return.
+ *      Locks: None held
  *
  *      Calling context: kernel thread
  *
@@ -946,8 +916,7 @@ Details:
  *
  *      Returns SUCCESS if command aborted else FAILED
  *
- *      Locks: struct Scsi_Host::host_lock held (with irqsave) on entry 
- *      and assumed to be held on return.
+ *      Locks: None held
  *
  *      Calling context: kernel thread
  *
@@ -965,8 +934,7 @@ Details:
  *
  *      Returns SUCCESS if command aborted else FAILED
  *
- *      Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
- *      and assumed to be held on return.
+ *      Locks: None held
  *
  *      Calling context: kernel thread
  *
@@ -984,8 +952,7 @@ Details:
  *
  *      Returns SUCCESS if command aborted else FAILED
  *
- *      Locks: struct Scsi_Host::host_lock held (with irqsave) on entry
- *      and assumed to be held on return.
+ *      Locks: None held
  *
  *      Calling context: kernel thread
  *
@@ -1001,24 +968,6 @@ Details:
      int eh_host_reset_handler(struct scsi_cmnd * scp)
 
 
-/**
- *      eh_strategy_handler - driver supplied alternate to scsi_unjam_host()
- *      @shp: host on which error has occurred
- *
- *      Returns TRUE if host unjammed, else FALSE.
- *
- *      Locks: none
- *
- *      Calling context: kernel thread
- *
- *      Notes: Invoked from scsi_eh thread. LLD supplied alternate to 
- *      scsi_unjam_host() found in scsi_error.c
- *
- *      Optionally defined in: LLD
- **/
-     int eh_strategy_handler(struct Scsi_Host * shp)
-
-
 /**
  *      info - supply information about given host: driver name plus data
  *             to distinguish given host
@@ -1072,10 +1021,6 @@ Details:
  *      mid level does not recognize it, then the LLD that controls
  *      the device receives the ioctl. According to recent Unix standards
  *      unsupported ioctl() 'cmd' numbers should return -ENOTTY.
- *      However the mid level returns -EINVAL for unrecognized 'cmd'
- *      numbers when this function is not supplied by the driver.
- *      Unfortunately some applications expect -EINVAL and react badly
- *      when -ENOTTY is returned; stick with -EINVAL.
  *
  *      Optionally defined in: LLD
  **/
@@ -1110,7 +1055,7 @@ Details:
  *      Optionally defined in: LLD
  **/
     int proc_info(char * buffer, char ** start, off_t offset, 
-                  int length, int hostno, int writeto1_read0)
+                  int length, int host_no, int writeto1_read0)
 
 
 /**
@@ -1120,42 +1065,42 @@ Details:
  *
  *      Returns 0 on success.
  *
- *     If there's a failure, return either:
+ *      If there's a failure, return either:
  *
- *     SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
- *     SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
+ *      SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
+ *      SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  *
- *     On both of these returns, the mid-layer will requeue the I/O
+ *      On both of these returns, the mid-layer will requeue the I/O
  *
- *     - if the return is SCSI_MLQUEUE_DEVICE_BUSY, only that particular
- *     device will be paused, and it will be unpaused when a command to
- *     the device returns (or after a brief delay if there are no more
- *     outstanding commands to it).  Commands to other devices continue
- *     to be processed normally.
+ *      - if the return is SCSI_MLQUEUE_DEVICE_BUSY, only that particular
+ *      device will be paused, and it will be unpaused when a command to
+ *      the device returns (or after a brief delay if there are no more
+ *      outstanding commands to it).  Commands to other devices continue
+ *      to be processed normally.
  *
- *     - if the return is SCSI_MLQUEUE_HOST_BUSY, all I/O to the host
- *     is paused and will be unpaused when any command returns from
- *     the host (or after a brief delay if there are no outstanding
- *     commands to the host).
+ *      - if the return is SCSI_MLQUEUE_HOST_BUSY, all I/O to the host
+ *      is paused and will be unpaused when any command returns from
+ *      the host (or after a brief delay if there are no outstanding
+ *      commands to the host).
  *
- *     For compatibility with earlier versions of queuecommand, any
- *     other return value is treated the same as
- *     SCSI_MLQUEUE_HOST_BUSY.
+ *      For compatibility with earlier versions of queuecommand, any
+ *      other return value is treated the same as
+ *      SCSI_MLQUEUE_HOST_BUSY.
  *
- *     Other types of errors that are detected immediately may be
- *     flagged by setting scp->result to an appropriate value,
- *     invoking the 'done' callback, and then returning 0 from this
- *     function. If the command is not performed immediately (and the
- *     LLD is starting (or will start) the given command) then this
- *     function should place 0 in scp->result and return 0.
+ *      Other types of errors that are detected immediately may be
+ *      flagged by setting scp->result to an appropriate value,
+ *      invoking the 'done' callback, and then returning 0 from this
+ *      function. If the command is not performed immediately (and the
+ *      LLD is starting (or will start) the given command) then this
+ *      function should place 0 in scp->result and return 0.
  *
- *     Command ownership.  If the driver returns zero, it owns the
- *     command and must take responsibility for ensuring the 'done'
- *     callback is executed.  Note: the driver may call done before
- *     returning zero, but after it has called done, it may not
- *     return any value other than zero.  If the driver makes a
- *     non-zero return, it must not execute the command's done
- *     callback at any time.
+ *      Command ownership.  If the driver returns zero, it owns the
+ *      command and must take responsibility for ensuring the 'done'
+ *      callback is executed.  Note: the driver may call done before
+ *      returning zero, but after it has called done, it may not
+ *      return any value other than zero.  If the driver makes a
+ *      non-zero return, it must not execute the command's done
+ *      callback at any time.
  *
  *      Locks: struct Scsi_Host::host_lock held on entry (with "irqsave")
  *             and is expected to be held on return.
@@ -1308,16 +1253,19 @@ 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
-                   kernel boot (or module) parameter)
+                   this host. Issued in ascending order from 0.
     can_queue    - must be greater than 0; do not send more than can_queue
                    commands to the adapter.
     this_id      - scsi id of host (scsi initiator) or -1 if not known
     sg_tablesize - maximum scatter gather elements allowed by host.
                    0 implies scatter gather not supported by host
     max_sectors  - maximum number of sectors (usually 512 bytes) allowed
-                   in a single SCSI command. 0 implies no maximum.
+                   in a single SCSI command. The default value of 0 leads
+                   to a setting of SCSI_DEFAULT_MAX_SECTORS (defined in
+                   scsi_host.h) which is currently set to 1024. So for a
+                   disk the maximum transfer size is 512 KB when max_sectors
+                   is not defined. Note that this size may not be sufficient
+                   for disk firmware uploads.
     cmd_per_lun  - maximum number of commands that can be queued on devices
                    controlled by the host. Overridden by LLD calls to
                    scsi_adjust_queue_depth().
@@ -1328,6 +1276,9 @@ of interest:
                      0=>disallow SCSI command merging
     hostt        - pointer to driver's struct scsi_host_template from which
                    this struct Scsi_Host instance was spawned
+    hostt->proc_name  - name of LLD. This is the driver name that sysfs uses
+    transportt   - pointer to driver's struct scsi_transport_template instance
+                   (if any). FC and SPI transports currently supported.
     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 
@@ -1335,7 +1286,8 @@ of interest:
     hostdata[0]  - area reserved for LLD at end of struct Scsi_Host. Size
                    is set by the second argument (named 'xtr_bytes') to
                    scsi_host_alloc() or scsi_register().
-The structure is defined in include/scsi/scsi_host.h
+
+The scsi_host structure is defined in include/scsi/scsi_host.h
 
 struct scsi_device
 ------------------
@@ -1347,11 +1299,66 @@ The structure is defined in include/scsi/scsi_device.h
 struct scsi_cmnd
 ----------------
 Instances of this structure convey SCSI commands to the LLD and responses
-back to the mid level. The SCSI mid level will ensure that no more SCSI 
-commands become queued against the LLD than are indicated by 
-scsi_adjust_queue_depth() (or struct Scsi_Host::cmd_per_lun). There will 
-be at least one instance of struct scsi_cmnd available for each SCSI device. 
-The structure is defined in include/scsi/scsi_cmnd.h
+back to the mid level. The SCSI mid level will ensure that no more SCSI
+commands become queued against the LLD than are indicated by
+scsi_adjust_queue_depth() (or struct Scsi_Host::cmd_per_lun). There will
+be at least one instance of struct scsi_cmnd available for each SCSI device.
+Members of interest:
+    cmnd         - array containing SCSI command
+    cmnd_len     - length (in bytes) of SCSI command
+    sc_data_direction - direction of data transfer in data phase. See
+                "enum dma_data_direction" in include/linux/dma-mapping.h
+    request_bufflen - number of data bytes to transfer (0 if no data phase)
+    use_sg       - ==0 -> no scatter gather list, hence transfer data
+                          to/from request_buffer
+                 - >0 ->  scatter gather list (actually an array) in
+                          request_buffer with use_sg elements
+    request_buffer - either contains data buffer or scatter gather list
+                     depending on the setting of use_sg. Scatter gather
+                     elements are defined by 'struct scatterlist' found
+                     in include/asm/scatterlist.h .
+    done         - function pointer that should be invoked by LLD when the
+                   SCSI command is completed (successfully or otherwise).
+                   Should only be called by an LLD if the LLD has accepted
+                   the command (i.e. queuecommand() returned or will return
+                   0). The LLD may invoke 'done'  prior to queuecommand()
+                   finishing.
+    result       - should be set by LLD prior to calling 'done'. A value
+                   of 0 implies a successfully completed command (and all
+                   data (if any) has been transferred to or from the SCSI
+                   target device). 'result' is a 32 bit unsigned integer that
+                   can be viewed as 4 related bytes. The SCSI status value is
+                   in the LSB. See include/scsi/scsi.h status_byte(),
+                   msg_byte(), host_byte() and driver_byte() macros and
+                   related constants.
+    sense_buffer - an array (maximum size: SCSI_SENSE_BUFFERSIZE bytes) that
+                   should be written when the SCSI status (LSB of 'result')
+                   is set to CHECK_CONDITION (2). When CHECK_CONDITION is
+                   set, if the top nibble of sense_buffer[0] has the value 7
+                   then the mid level will assume the sense_buffer array
+                   contains a valid SCSI sense buffer; otherwise the mid
+                   level will issue a REQUEST_SENSE SCSI command to
+                   retrieve the sense buffer. The latter strategy is error
+                   prone in the presence of command queuing so the LLD should
+                   always "auto-sense".
+    device       - pointer to scsi_device object that this command is
+                   associated with.
+    resid        - an LLD should set this signed integer to the requested
+                   transfer length (i.e. 'request_bufflen') less the number
+                   of bytes that are actually transferred. 'resid' is
+                   preset to 0 so an LLD can ignore it if it cannot detect
+                   underruns (overruns should be rare). If possible an LLD
+                   should set 'resid' prior to invoking 'done'. The most
+                   interesting case is data transfers from a SCSI target
+                   device device (i.e. READs) that underrun. 
+    underflow    - LLD should place (DID_ERROR << 16) in 'result' if
+                   actual number of bytes transferred is less than this
+                   figure. Not many LLDs implement this check and some that
+                   do just output an error message to the log rather than
+                   report a DID_ERROR. Better for an LLD to implement
+                   'resid'.
+
+The scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h
 
 
 Locks
@@ -1420,15 +1427,16 @@ to support it.
 Credits
 =======
 The following people have contributed to this document:
-        Mike Anderson <andmike@us.ibm.com>
-        James Bottomley <James.Bottomley@steeleye.com> 
-        Patrick Mansfield <patmans@us.ibm.com> 
-        Christoph Hellwig <hch@infradead.org>
-        Doug Ledford <dledford@redhat.com>
-        Andries Brouwer <Andries.Brouwer@cwi.nl>
-        Randy Dunlap <rddunlap@osdl.org>
+        Mike Anderson <andmike at us dot ibm dot com>
+        James Bottomley <James dot Bottomley at steeleye dot com> 
+        Patrick Mansfield <patmans at us dot ibm dot com> 
+        Christoph Hellwig <hch at infradead dot org>
+        Doug Ledford <dledford at redhat dot com>
+        Andries Brouwer <Andries dot Brouwer at cwi dot nl>
+        Randy Dunlap <rdunlap at xenotime dot net>
+        Alan Stern <stern at rowland dot harvard dot edu>
 
 
 Douglas Gilbert
-dgilbert@interlog.com
-29th August 2003
+dgilbert at interlog dot com
+21st September 2004