Loading Documentation/scsi/index.rst +1 −0 Original line number Diff line number Diff line Loading @@ -35,5 +35,6 @@ Linux SCSI Subsystem scsi_eh scsi_fc_transport scsi-generic scsi_mid_low_api scsi_transport_srp/figures Documentation/scsi/scsi_eh.rst +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ SCSI EH ======= This document describes SCSI midlayer error handling infrastructure. Please refer to Documentation/scsi/scsi_mid_low_api.txt for more Please refer to Documentation/scsi/scsi_mid_low_api.rst for more information regarding SCSI midlayer. .. TABLE OF CONTENTS Loading Documentation/scsi/scsi_mid_low_api.txt→Documentation/scsi/scsi_mid_low_api.rst +1334 −0 Original line number Diff line number Diff line Linux Kernel 2.6 series .. SPDX-License-Identifier: GPL-2.0 ============================================= SCSI mid_level - lower_level driver interface ============================================= Loading Loading @@ -84,6 +86,7 @@ IEEE 1394 connected digital cameras) that are hotplugged. Both initialization models are discussed in the following sections. An LLD interfaces to the SCSI subsystem several ways: a) directly invoking functions supplied by the mid level b) passing a set of function pointers to a registration function supplied by the mid level. The mid level will then invoke these Loading @@ -98,7 +101,7 @@ supplied functions" below. Those functions in group b) are listed in a section entitled "Interface functions" below. Their function pointers are placed in the members of "struct scsi_host_template", an instance of which is passed to scsi_host_alloc() ** . Those interface functions that the LLD does not scsi_host_alloc() [#]_. Those interface functions that the LLD does not wish to supply should have NULL placed in the corresponding member of struct scsi_host_template. Defining an instance of struct scsi_host_template at file scope will cause NULL to be placed in function Loading @@ -111,9 +114,9 @@ that are shared with the mid level and other layers. All functions defined within an LLD and all data defined at file scope should be static. For example the slave_alloc() function in an LLD 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 .. [#] the scsi_host_alloc() function is a replacement for the rather vaguely named scsi_register() function in most situations. Loading @@ -137,7 +140,7 @@ aware of an LLD when that LLD registers its first HBA. At some later time, the LLD becomes aware of an HBA and what follows is a typical sequence of calls between the LLD and the mid level. This example shows the mid level scanning the newly introduced HBA for 3 scsi devices of which only the first 2 respond: scsi devices of which only the first 2 respond:: HBA PROBE: assume 2 SCSI devices found in scan LLD mid level LLD Loading @@ -154,19 +157,19 @@ scsi_scan_host() -------+ | slave_alloc() *** slave_destroy() *** ------------------------------------------------------------ If the LLD wants to adjust the default queue settings, it can invoke scsi_change_queue_depth() in its slave_configure() routine. *** For scsi devices that the mid level tries to scan but do not respond, a slave_alloc(), slave_destroy() pair is called. If the LLD wants to adjust the default queue settings, it can invoke scsi_change_queue_depth() in its slave_configure() routine. When an HBA is being removed it could be as part of an orderly shutdown associated with the LLD module being unloaded (e.g. with the "rmmod" command) or in response to a "hot unplug" indicated by sysfs()'s remove() callback being invoked. In either case, the sequence is the same: same:: HBA REMOVE: assume 2 SCSI devices attached LLD mid level LLD Loading @@ -176,7 +179,6 @@ scsi_remove_host() ---------+ slave_destroy() slave_destroy() scsi_host_put() ------------------------------------------------------------ It may be useful for a LLD to keep track of struct Scsi_Host instances (a pointer is returned by scsi_host_alloc()). Such instances are "owned" Loading @@ -193,7 +195,7 @@ The hotplug concept may be extended to SCSI devices. Currently, when an 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: An LLD can use this sequence to make the mid level aware of a SCSI device:: SCSI DEVICE hotplug LLD mid level LLD Loading @@ -202,7 +204,6 @@ scsi_add_device() ------+ | slave_alloc() slave_configure() [--> scsi_change_queue_depth()] ------------------------------------------------------------ In a similar fashion, an LLD may become aware that a SCSI device has been removed (unplugged) or the connection to it has been interrupted. Some Loading @@ -210,7 +211,7 @@ 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. An LLD that detects the removal of a SCSI device can instigate its removal from upper layers with this sequence: upper layers with this sequence:: SCSI DEVICE hot unplug LLD mid level LLD Loading @@ -218,7 +219,6 @@ LLD mid level LLD scsi_remove_device() -------+ | slave_destroy() ------------------------------------------------------------ It may be useful for an LLD to keep track of struct scsi_device instances (a pointer is passed as the parameter to slave_alloc() and Loading @@ -237,10 +237,16 @@ 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_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 - 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 Loading @@ -254,7 +260,9 @@ 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 .. Note:: struct Scsi_Host actually has 2 reference counts which are manipulated in parallel by these functions. Loading @@ -273,7 +281,7 @@ Also, most C99 enhancements are encouraged to the extent they are supported by the relevant gcc compilers. So C99 style structure and array initializers are encouraged where appropriate. Don't go too far, VLAs are not properly supported yet. An exception to this is the use of "//" style comments; /*...*/ comments are still preferred in Linux. ``//`` style comments; ``/*...*/`` comments are still preferred in Linux. Well written, tested and documented code, need not be re-formatted to comply with the above conventions. For example, the aic7xxx driver Loading @@ -288,29 +296,30 @@ 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_". names all start with ``scsi_``. Summary: scsi_add_device - creates new scsi device (lu) instance scsi_add_host - perform sysfs registration and set up transport class scsi_change_queue_depth - change the queue depth on a SCSI device scsi_bios_ptable - return copy of block device's partition table scsi_block_requests - prevent further commands being queued to given host scsi_host_alloc - return a new scsi_host instance whose refcount==1 scsi_host_get - increments Scsi_Host instance's refcount scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) scsi_partsize - parse partition table into cylinders, heads + sectors scsi_register - create and register a scsi host adapter instance. scsi_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_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()] Details: - scsi_add_device - creates new scsi device (lu) instance - scsi_add_host - perform sysfs registration and set up transport class - scsi_change_queue_depth - change the queue depth on a SCSI device - scsi_bios_ptable - return copy of block device's partition table - scsi_block_requests - prevent further commands being queued to given host - scsi_host_alloc - return a new scsi_host instance whose refcount==1 - scsi_host_get - increments Scsi_Host instance's refcount - scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) - scsi_partsize - parse partition table into cylinders, heads + sectors - scsi_register - create and register a scsi host adapter instance. - scsi_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_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()] Details:: /** * scsi_add_device - creates new scsi device (lu) instance Loading Loading @@ -646,8 +655,10 @@ pointers are placed in an instance of struct scsi_host_template which is passed to scsi_host_alloc() [or scsi_register() / init_this_scsi_driver()]. Some are mandatory. Interface functions should be declared static. The accepted convention is that driver "xyz" will declare its slave_configure() function as: function as:: static int xyz_slave_configure(struct scsi_device * sdev); and so forth for all interface functions listed below. A pointer to this function should be placed in the 'slave_configure' member Loading @@ -662,22 +673,23 @@ In some cases more detail is given in scsi_host.h than below. The interface functions are listed below in alphabetical order. Summary: bios_param - fetch head, sector, cylinder info for a disk eh_timed_out - notify the host that a command timer expired eh_abort_handler - abort given command 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) info - supply information about given host ioctl - driver can respond to ioctls proc_info - supports /proc/scsi/{driver_name}/{host_no} queuecommand - queue scsi command, invoke 'done' on completion slave_alloc - prior to any commands being sent to a new device slave_configure - driver fine tuning for given device after attach slave_destroy - given device is about to be shut down Details: - bios_param - fetch head, sector, cylinder info for a disk - eh_timed_out - notify the host that a command timer expired - eh_abort_handler - abort given command - 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) - info - supply information about given host - ioctl - driver can respond to ioctls - proc_info - supports /proc/scsi/{driver_name}/{host_no} - queuecommand - queue scsi command, invoke 'done' on completion - slave_alloc - prior to any commands being sent to a new device - slave_configure - driver fine tuning for given device after attach - slave_destroy - given device is about to be shut down Details:: /** * bios_param - fetch head, sector, cylinder info for a disk Loading Loading @@ -1051,21 +1063,28 @@ Data Structures =============== struct scsi_host_template ------------------------- There is one "struct scsi_host_template" 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 way members that are not explicitly initialized will be set to 0 or NULL. Member of interest: name - name of driver (may contain spaces, please limit to name - name of driver (may contain spaces, please limit to less than 80 characters) proc_name - name used in "/proc/scsi/<proc_name>/<host_no>" and proc_name - name used in "/proc/scsi/<proc_name>/<host_no>" and by sysfs in one of its "drivers" directories. Hence "proc_name" should only contain characters acceptable to a Unix file name. (*queuecommand)() - primary callback that the mid level uses to inject ``(*queuecommand)()`` - primary callback that the mid level uses to inject SCSI commands into an LLD. The structure is defined and commented in include/scsi/scsi_host.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. an LLD that handles both ISA and PCI cards and has a separate instance of struct scsi_host_template for each class). Loading @@ -1078,42 +1097,58 @@ with "struct scsi_host_template". When a new struct Scsi_Host instance is created (in scsi_host_alloc() in hosts.c) those common members are initialized from the driver's struct scsi_host_template instance. Members of interest: host_no - system wide unique number that is used for identifying host_no - system wide unique number that is used for identifying this host. Issued in ascending order from 0. can_queue - must be greater than 0; do not send more than can_queue 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. this_id - scsi id of host (scsi initiator) or -1 if not known sg_tablesize - maximum scatter gather elements allowed by host. Set this to SG_ALL or less to avoid chained SG lists. Must be at least 1. max_sectors - maximum number of sectors (usually 512 bytes) allowed max_sectors - maximum number of sectors (usually 512 bytes) allowed in a single SCSI command. 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 cmd_per_lun - maximum number of commands that can be queued on devices controlled by the host. Overridden by LLD calls to scsi_change_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 address space no_async_abort - 1=>Asynchronous aborts are not supported 0=>Timed-out commands will be aborted asynchronously hostt - pointer to driver's struct scsi_host_template from which no_async_abort - 1=>Asynchronous aborts are not supported - 0=>Timed-out commands will be aborted asynchronously 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 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 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 my_devices - a double linked list of pointers to struct scsi_device instances that belong to this host. hostdata[0] - area reserved for LLD at end of struct Scsi_Host. Size 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(). vendor_id - a unique value that identifies the vendor supplying vendor_id - a unique value that identifies the vendor supplying the LLD for the Scsi_Host. Used most often in validating vendor-specific message requests. Value consists of an identifier type and a vendor-specific value. Loading @@ -1136,26 +1171,35 @@ commands become queued against the LLD than are indicated by scsi_change_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 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 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 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/linux/scatterlist.h . done - function pointer that should be invoked by LLD when the 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 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 Loading @@ -1163,7 +1207,8 @@ Members of interest: 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 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 Loading @@ -1173,9 +1218,11 @@ Members of interest: 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 device - pointer to scsi_device object that this command is associated with. resid - an LLD should set this signed integer to the requested 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 Loading @@ -1183,7 +1230,8 @@ Members of interest: should set 'resid' prior to invoking 'done'. The most interesting case is data transfers from a SCSI target device (e.g. READs) that underrun. underflow - LLD should place (DID_ERROR << 16) in 'result' if 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 Loading @@ -1196,10 +1244,13 @@ when such data transfers have sense keys of MEDIUM ERROR and HARDWARE ERROR (and possibly RECOVERED ERROR). In these cases if a LLD is in doubt how much data has been received then the safest approach is to indicate no bytes have been received. For example: to indicate that no valid data has been received a LLD might use these helpers: a LLD might use these helpers:: scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); where 'SCpnt' is a pointer to a scsi_cmnd object. To indicate only three 512 bytes blocks has been received 'resid' could be set like this: bytes blocks has been received 'resid' could be set like this:: scsi_set_resid(SCpnt, scsi_bufflen(SCpnt) - (3 * 512)); The scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h Loading @@ -1223,6 +1274,7 @@ automatic return of sense data to the application client coincident with the completion of a SCSI command" when a status of CHECK CONDITION occurs. LLDs should perform autosense. This should be done when the LLD detects a CHECK CONDITION status by either: a) instructing the SCSI protocol (e.g. SCSI Parallel Interface (SPI)) to perform an extra data in phase on such responses b) or, the LLD issuing a REQUEST SENSE command itself Loading Loading @@ -1265,16 +1317,18 @@ to support it. Credits ======= The following people have contributed to this document: Mike Anderson <andmike at us dot ibm dot com> James Bottomley <James dot Bottomley at hansenpartnership 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> - Mike Anderson <andmike at us dot ibm dot com> - James Bottomley <James dot Bottomley at hansenpartnership 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 at interlog dot com 21st September 2004 scripts/documentation-file-ref-check +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ use Getopt::Long qw(:config no_auto_abbrev); # to mention a past documentation file, for example, to give credits for # the original work. my %false_positives = ( "Documentation/scsi/scsi_mid_low_api.txt" => "Documentation/Configure.help", "Documentation/scsi/scsi_mid_low_api.rst" => "Documentation/Configure.help", "drivers/vhost/vhost.c" => "Documentation/virtual/lguest/lguest.c", ); Loading Loading
Documentation/scsi/index.rst +1 −0 Original line number Diff line number Diff line Loading @@ -35,5 +35,6 @@ Linux SCSI Subsystem scsi_eh scsi_fc_transport scsi-generic scsi_mid_low_api scsi_transport_srp/figures
Documentation/scsi/scsi_eh.rst +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ SCSI EH ======= This document describes SCSI midlayer error handling infrastructure. Please refer to Documentation/scsi/scsi_mid_low_api.txt for more Please refer to Documentation/scsi/scsi_mid_low_api.rst for more information regarding SCSI midlayer. .. TABLE OF CONTENTS Loading
Documentation/scsi/scsi_mid_low_api.txt→Documentation/scsi/scsi_mid_low_api.rst +1334 −0 Original line number Diff line number Diff line Linux Kernel 2.6 series .. SPDX-License-Identifier: GPL-2.0 ============================================= SCSI mid_level - lower_level driver interface ============================================= Loading Loading @@ -84,6 +86,7 @@ IEEE 1394 connected digital cameras) that are hotplugged. Both initialization models are discussed in the following sections. An LLD interfaces to the SCSI subsystem several ways: a) directly invoking functions supplied by the mid level b) passing a set of function pointers to a registration function supplied by the mid level. The mid level will then invoke these Loading @@ -98,7 +101,7 @@ supplied functions" below. Those functions in group b) are listed in a section entitled "Interface functions" below. Their function pointers are placed in the members of "struct scsi_host_template", an instance of which is passed to scsi_host_alloc() ** . Those interface functions that the LLD does not scsi_host_alloc() [#]_. Those interface functions that the LLD does not wish to supply should have NULL placed in the corresponding member of struct scsi_host_template. Defining an instance of struct scsi_host_template at file scope will cause NULL to be placed in function Loading @@ -111,9 +114,9 @@ that are shared with the mid level and other layers. All functions defined within an LLD and all data defined at file scope should be static. For example the slave_alloc() function in an LLD 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 .. [#] the scsi_host_alloc() function is a replacement for the rather vaguely named scsi_register() function in most situations. Loading @@ -137,7 +140,7 @@ aware of an LLD when that LLD registers its first HBA. At some later time, the LLD becomes aware of an HBA and what follows is a typical sequence of calls between the LLD and the mid level. This example shows the mid level scanning the newly introduced HBA for 3 scsi devices of which only the first 2 respond: scsi devices of which only the first 2 respond:: HBA PROBE: assume 2 SCSI devices found in scan LLD mid level LLD Loading @@ -154,19 +157,19 @@ scsi_scan_host() -------+ | slave_alloc() *** slave_destroy() *** ------------------------------------------------------------ If the LLD wants to adjust the default queue settings, it can invoke scsi_change_queue_depth() in its slave_configure() routine. *** For scsi devices that the mid level tries to scan but do not respond, a slave_alloc(), slave_destroy() pair is called. If the LLD wants to adjust the default queue settings, it can invoke scsi_change_queue_depth() in its slave_configure() routine. When an HBA is being removed it could be as part of an orderly shutdown associated with the LLD module being unloaded (e.g. with the "rmmod" command) or in response to a "hot unplug" indicated by sysfs()'s remove() callback being invoked. In either case, the sequence is the same: same:: HBA REMOVE: assume 2 SCSI devices attached LLD mid level LLD Loading @@ -176,7 +179,6 @@ scsi_remove_host() ---------+ slave_destroy() slave_destroy() scsi_host_put() ------------------------------------------------------------ It may be useful for a LLD to keep track of struct Scsi_Host instances (a pointer is returned by scsi_host_alloc()). Such instances are "owned" Loading @@ -193,7 +195,7 @@ The hotplug concept may be extended to SCSI devices. Currently, when an 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: An LLD can use this sequence to make the mid level aware of a SCSI device:: SCSI DEVICE hotplug LLD mid level LLD Loading @@ -202,7 +204,6 @@ scsi_add_device() ------+ | slave_alloc() slave_configure() [--> scsi_change_queue_depth()] ------------------------------------------------------------ In a similar fashion, an LLD may become aware that a SCSI device has been removed (unplugged) or the connection to it has been interrupted. Some Loading @@ -210,7 +211,7 @@ 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. An LLD that detects the removal of a SCSI device can instigate its removal from upper layers with this sequence: upper layers with this sequence:: SCSI DEVICE hot unplug LLD mid level LLD Loading @@ -218,7 +219,6 @@ LLD mid level LLD scsi_remove_device() -------+ | slave_destroy() ------------------------------------------------------------ It may be useful for an LLD to keep track of struct scsi_device instances (a pointer is passed as the parameter to slave_alloc() and Loading @@ -237,10 +237,16 @@ 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_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 - 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 Loading @@ -254,7 +260,9 @@ 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 .. Note:: struct Scsi_Host actually has 2 reference counts which are manipulated in parallel by these functions. Loading @@ -273,7 +281,7 @@ Also, most C99 enhancements are encouraged to the extent they are supported by the relevant gcc compilers. So C99 style structure and array initializers are encouraged where appropriate. Don't go too far, VLAs are not properly supported yet. An exception to this is the use of "//" style comments; /*...*/ comments are still preferred in Linux. ``//`` style comments; ``/*...*/`` comments are still preferred in Linux. Well written, tested and documented code, need not be re-formatted to comply with the above conventions. For example, the aic7xxx driver Loading @@ -288,29 +296,30 @@ 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_". names all start with ``scsi_``. Summary: scsi_add_device - creates new scsi device (lu) instance scsi_add_host - perform sysfs registration and set up transport class scsi_change_queue_depth - change the queue depth on a SCSI device scsi_bios_ptable - return copy of block device's partition table scsi_block_requests - prevent further commands being queued to given host scsi_host_alloc - return a new scsi_host instance whose refcount==1 scsi_host_get - increments Scsi_Host instance's refcount scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) scsi_partsize - parse partition table into cylinders, heads + sectors scsi_register - create and register a scsi host adapter instance. scsi_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_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()] Details: - scsi_add_device - creates new scsi device (lu) instance - scsi_add_host - perform sysfs registration and set up transport class - scsi_change_queue_depth - change the queue depth on a SCSI device - scsi_bios_ptable - return copy of block device's partition table - scsi_block_requests - prevent further commands being queued to given host - scsi_host_alloc - return a new scsi_host instance whose refcount==1 - scsi_host_get - increments Scsi_Host instance's refcount - scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) - scsi_partsize - parse partition table into cylinders, heads + sectors - scsi_register - create and register a scsi host adapter instance. - scsi_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_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()] Details:: /** * scsi_add_device - creates new scsi device (lu) instance Loading Loading @@ -646,8 +655,10 @@ pointers are placed in an instance of struct scsi_host_template which is passed to scsi_host_alloc() [or scsi_register() / init_this_scsi_driver()]. Some are mandatory. Interface functions should be declared static. The accepted convention is that driver "xyz" will declare its slave_configure() function as: function as:: static int xyz_slave_configure(struct scsi_device * sdev); and so forth for all interface functions listed below. A pointer to this function should be placed in the 'slave_configure' member Loading @@ -662,22 +673,23 @@ In some cases more detail is given in scsi_host.h than below. The interface functions are listed below in alphabetical order. Summary: bios_param - fetch head, sector, cylinder info for a disk eh_timed_out - notify the host that a command timer expired eh_abort_handler - abort given command 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) info - supply information about given host ioctl - driver can respond to ioctls proc_info - supports /proc/scsi/{driver_name}/{host_no} queuecommand - queue scsi command, invoke 'done' on completion slave_alloc - prior to any commands being sent to a new device slave_configure - driver fine tuning for given device after attach slave_destroy - given device is about to be shut down Details: - bios_param - fetch head, sector, cylinder info for a disk - eh_timed_out - notify the host that a command timer expired - eh_abort_handler - abort given command - 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) - info - supply information about given host - ioctl - driver can respond to ioctls - proc_info - supports /proc/scsi/{driver_name}/{host_no} - queuecommand - queue scsi command, invoke 'done' on completion - slave_alloc - prior to any commands being sent to a new device - slave_configure - driver fine tuning for given device after attach - slave_destroy - given device is about to be shut down Details:: /** * bios_param - fetch head, sector, cylinder info for a disk Loading Loading @@ -1051,21 +1063,28 @@ Data Structures =============== struct scsi_host_template ------------------------- There is one "struct scsi_host_template" 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 way members that are not explicitly initialized will be set to 0 or NULL. Member of interest: name - name of driver (may contain spaces, please limit to name - name of driver (may contain spaces, please limit to less than 80 characters) proc_name - name used in "/proc/scsi/<proc_name>/<host_no>" and proc_name - name used in "/proc/scsi/<proc_name>/<host_no>" and by sysfs in one of its "drivers" directories. Hence "proc_name" should only contain characters acceptable to a Unix file name. (*queuecommand)() - primary callback that the mid level uses to inject ``(*queuecommand)()`` - primary callback that the mid level uses to inject SCSI commands into an LLD. The structure is defined and commented in include/scsi/scsi_host.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. an LLD that handles both ISA and PCI cards and has a separate instance of struct scsi_host_template for each class). Loading @@ -1078,42 +1097,58 @@ with "struct scsi_host_template". When a new struct Scsi_Host instance is created (in scsi_host_alloc() in hosts.c) those common members are initialized from the driver's struct scsi_host_template instance. Members of interest: host_no - system wide unique number that is used for identifying host_no - system wide unique number that is used for identifying this host. Issued in ascending order from 0. can_queue - must be greater than 0; do not send more than can_queue 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. this_id - scsi id of host (scsi initiator) or -1 if not known sg_tablesize - maximum scatter gather elements allowed by host. Set this to SG_ALL or less to avoid chained SG lists. Must be at least 1. max_sectors - maximum number of sectors (usually 512 bytes) allowed max_sectors - maximum number of sectors (usually 512 bytes) allowed in a single SCSI command. 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 cmd_per_lun - maximum number of commands that can be queued on devices controlled by the host. Overridden by LLD calls to scsi_change_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 address space no_async_abort - 1=>Asynchronous aborts are not supported 0=>Timed-out commands will be aborted asynchronously hostt - pointer to driver's struct scsi_host_template from which no_async_abort - 1=>Asynchronous aborts are not supported - 0=>Timed-out commands will be aborted asynchronously 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 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 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 my_devices - a double linked list of pointers to struct scsi_device instances that belong to this host. hostdata[0] - area reserved for LLD at end of struct Scsi_Host. Size 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(). vendor_id - a unique value that identifies the vendor supplying vendor_id - a unique value that identifies the vendor supplying the LLD for the Scsi_Host. Used most often in validating vendor-specific message requests. Value consists of an identifier type and a vendor-specific value. Loading @@ -1136,26 +1171,35 @@ commands become queued against the LLD than are indicated by scsi_change_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 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 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 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/linux/scatterlist.h . done - function pointer that should be invoked by LLD when the 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 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 Loading @@ -1163,7 +1207,8 @@ Members of interest: 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 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 Loading @@ -1173,9 +1218,11 @@ Members of interest: 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 device - pointer to scsi_device object that this command is associated with. resid - an LLD should set this signed integer to the requested 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 Loading @@ -1183,7 +1230,8 @@ Members of interest: should set 'resid' prior to invoking 'done'. The most interesting case is data transfers from a SCSI target device (e.g. READs) that underrun. underflow - LLD should place (DID_ERROR << 16) in 'result' if 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 Loading @@ -1196,10 +1244,13 @@ when such data transfers have sense keys of MEDIUM ERROR and HARDWARE ERROR (and possibly RECOVERED ERROR). In these cases if a LLD is in doubt how much data has been received then the safest approach is to indicate no bytes have been received. For example: to indicate that no valid data has been received a LLD might use these helpers: a LLD might use these helpers:: scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); where 'SCpnt' is a pointer to a scsi_cmnd object. To indicate only three 512 bytes blocks has been received 'resid' could be set like this: bytes blocks has been received 'resid' could be set like this:: scsi_set_resid(SCpnt, scsi_bufflen(SCpnt) - (3 * 512)); The scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h Loading @@ -1223,6 +1274,7 @@ automatic return of sense data to the application client coincident with the completion of a SCSI command" when a status of CHECK CONDITION occurs. LLDs should perform autosense. This should be done when the LLD detects a CHECK CONDITION status by either: a) instructing the SCSI protocol (e.g. SCSI Parallel Interface (SPI)) to perform an extra data in phase on such responses b) or, the LLD issuing a REQUEST SENSE command itself Loading Loading @@ -1265,16 +1317,18 @@ to support it. Credits ======= The following people have contributed to this document: Mike Anderson <andmike at us dot ibm dot com> James Bottomley <James dot Bottomley at hansenpartnership 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> - Mike Anderson <andmike at us dot ibm dot com> - James Bottomley <James dot Bottomley at hansenpartnership 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 at interlog dot com 21st September 2004
scripts/documentation-file-ref-check +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ use Getopt::Long qw(:config no_auto_abbrev); # to mention a past documentation file, for example, to give credits for # the original work. my %false_positives = ( "Documentation/scsi/scsi_mid_low_api.txt" => "Documentation/Configure.help", "Documentation/scsi/scsi_mid_low_api.rst" => "Documentation/Configure.help", "drivers/vhost/vhost.c" => "Documentation/virtual/lguest/lguest.c", ); Loading