1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun============================================= 4*4882a593SmuzhiyunSCSI mid_level - lower_level driver interface 5*4882a593Smuzhiyun============================================= 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunIntroduction 8*4882a593Smuzhiyun============ 9*4882a593SmuzhiyunThis document outlines the interface between the Linux SCSI mid level and 10*4882a593SmuzhiyunSCSI lower level drivers. Lower level drivers (LLDs) are variously called 11*4882a593Smuzhiyunhost bus adapter (HBA) drivers and host drivers (HD). A "host" in this 12*4882a593Smuzhiyuncontext is a bridge between a computer IO bus (e.g. PCI or ISA) and a 13*4882a593Smuzhiyunsingle SCSI initiator port on a SCSI transport. An "initiator" port 14*4882a593Smuzhiyun(SCSI terminology, see SAM-3 at http://www.t10.org) sends SCSI commands 15*4882a593Smuzhiyunto "target" SCSI ports (e.g. disks). There can be many LLDs in a running 16*4882a593Smuzhiyunsystem, but only one per hardware type. Most LLDs can control one or more 17*4882a593SmuzhiyunSCSI HBAs. Some HBAs contain multiple hosts. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunIn some cases the SCSI transport is an external bus that already has 20*4882a593Smuzhiyunits own subsystem in Linux (e.g. USB and ieee1394). In such cases the 21*4882a593SmuzhiyunSCSI subsystem LLD is a software bridge to the other driver subsystem. 22*4882a593SmuzhiyunExamples are the usb-storage driver (found in the drivers/usb/storage 23*4882a593Smuzhiyundirectory) and the ieee1394/sbp2 driver (found in the drivers/ieee1394 24*4882a593Smuzhiyundirectory). 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunFor example, the aic7xxx LLD controls Adaptec SCSI parallel interface 27*4882a593Smuzhiyun(SPI) controllers based on that company's 7xxx chip series. The aic7xxx 28*4882a593SmuzhiyunLLD can be built into the kernel or loaded as a module. There can only be 29*4882a593Smuzhiyunone aic7xxx LLD running in a Linux system but it may be controlling many 30*4882a593SmuzhiyunHBAs. These HBAs might be either on PCI daughter-boards or built into 31*4882a593Smuzhiyunthe motherboard (or both). Some aic7xxx based HBAs are dual controllers 32*4882a593Smuzhiyunand thus represent two hosts. Like most modern HBAs, each aic7xxx host 33*4882a593Smuzhiyunhas its own PCI device address. [The one-to-one correspondence between 34*4882a593Smuzhiyuna SCSI host and a PCI device is common but not required (e.g. with 35*4882a593SmuzhiyunISA adapters).] 36*4882a593Smuzhiyun 37*4882a593SmuzhiyunThe SCSI mid level isolates an LLD from other layers such as the SCSI 38*4882a593Smuzhiyunupper layer drivers and the block layer. 39*4882a593Smuzhiyun 40*4882a593SmuzhiyunThis version of the document roughly matches linux kernel version 2.6.8 . 41*4882a593Smuzhiyun 42*4882a593SmuzhiyunDocumentation 43*4882a593Smuzhiyun============= 44*4882a593SmuzhiyunThere is a SCSI documentation directory within the kernel source tree, 45*4882a593Smuzhiyuntypically Documentation/scsi . Most documents are in plain 46*4882a593Smuzhiyun(i.e. ASCII) text. This file is named scsi_mid_low_api.txt and can be 47*4882a593Smuzhiyunfound in that directory. A more recent copy of this document may be found 48*4882a593Smuzhiyunat http://web.archive.org/web/20070107183357rn_1/sg.torque.net/scsi/. 49*4882a593SmuzhiyunMany LLDs are documented there (e.g. aic7xxx.txt). The SCSI mid-level is 50*4882a593Smuzhiyunbriefly described in scsi.txt which contains a url to a document 51*4882a593Smuzhiyundescribing the SCSI subsystem in the lk 2.4 series. Two upper level 52*4882a593Smuzhiyundrivers have documents in that directory: st.txt (SCSI tape driver) and 53*4882a593Smuzhiyunscsi-generic.txt (for the sg driver). 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunSome documentation (or urls) for LLDs may be found in the C source code 56*4882a593Smuzhiyunor in the same directory as the C source code. For example to find a url 57*4882a593Smuzhiyunabout the USB mass storage driver see the 58*4882a593Smuzhiyun/usr/src/linux/drivers/usb/storage directory. 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunDriver structure 61*4882a593Smuzhiyun================ 62*4882a593SmuzhiyunTraditionally an LLD for the SCSI subsystem has been at least two files in 63*4882a593Smuzhiyunthe drivers/scsi directory. For example, a driver called "xyz" has a header 64*4882a593Smuzhiyunfile "xyz.h" and a source file "xyz.c". [Actually there is no good reason 65*4882a593Smuzhiyunwhy this couldn't all be in one file; the header file is superfluous.] Some 66*4882a593Smuzhiyundrivers that have been ported to several operating systems have more than 67*4882a593Smuzhiyuntwo files. For example the aic7xxx driver has separate files for generic 68*4882a593Smuzhiyunand OS-specific code (e.g. FreeBSD and Linux). Such drivers tend to have 69*4882a593Smuzhiyuntheir own directory under the drivers/scsi directory. 70*4882a593Smuzhiyun 71*4882a593SmuzhiyunWhen a new LLD is being added to Linux, the following files (found in the 72*4882a593Smuzhiyundrivers/scsi directory) will need some attention: Makefile and Kconfig . 73*4882a593SmuzhiyunIt is probably best to study how existing LLDs are organized. 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunAs the 2.5 series development kernels evolve into the 2.6 series 76*4882a593Smuzhiyunproduction series, changes are being introduced into this interface. An 77*4882a593Smuzhiyunexample of this is driver initialization code where there are now 2 models 78*4882a593Smuzhiyunavailable. The older one, similar to what was found in the lk 2.4 series, 79*4882a593Smuzhiyunis based on hosts that are detected at HBA driver load time. This will be 80*4882a593Smuzhiyunreferred to the "passive" initialization model. The newer model allows HBAs 81*4882a593Smuzhiyunto be hot plugged (and unplugged) during the lifetime of the LLD and will 82*4882a593Smuzhiyunbe referred to as the "hotplug" initialization model. The newer model is 83*4882a593Smuzhiyunpreferred as it can handle both traditional SCSI equipment that is 84*4882a593Smuzhiyunpermanently connected as well as modern "SCSI" devices (e.g. USB or 85*4882a593SmuzhiyunIEEE 1394 connected digital cameras) that are hotplugged. Both 86*4882a593Smuzhiyuninitialization models are discussed in the following sections. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunAn LLD interfaces to the SCSI subsystem several ways: 89*4882a593Smuzhiyun 90*4882a593Smuzhiyun a) directly invoking functions supplied by the mid level 91*4882a593Smuzhiyun b) passing a set of function pointers to a registration function 92*4882a593Smuzhiyun supplied by the mid level. The mid level will then invoke these 93*4882a593Smuzhiyun functions at some point in the future. The LLD will supply 94*4882a593Smuzhiyun implementations of these functions. 95*4882a593Smuzhiyun c) direct access to instances of well known data structures maintained 96*4882a593Smuzhiyun by the mid level 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunThose functions in group a) are listed in a section entitled "Mid level 99*4882a593Smuzhiyunsupplied functions" below. 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunThose functions in group b) are listed in a section entitled "Interface 102*4882a593Smuzhiyunfunctions" below. Their function pointers are placed in the members of 103*4882a593Smuzhiyun"struct scsi_host_template", an instance of which is passed to 104*4882a593Smuzhiyunscsi_host_alloc() [#]_. Those interface functions that the LLD does not 105*4882a593Smuzhiyunwish to supply should have NULL placed in the corresponding member of 106*4882a593Smuzhiyunstruct scsi_host_template. Defining an instance of struct 107*4882a593Smuzhiyunscsi_host_template at file scope will cause NULL to be placed in function 108*4882a593Smuzhiyunpointer members not explicitly initialized. 109*4882a593Smuzhiyun 110*4882a593SmuzhiyunThose usages in group c) should be handled with care, especially in a 111*4882a593Smuzhiyun"hotplug" environment. LLDs should be aware of the lifetime of instances 112*4882a593Smuzhiyunthat are shared with the mid level and other layers. 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunAll functions defined within an LLD and all data defined at file scope 115*4882a593Smuzhiyunshould be static. For example the slave_alloc() function in an LLD 116*4882a593Smuzhiyuncalled "xxx" could be defined as 117*4882a593Smuzhiyun``static int xxx_slave_alloc(struct scsi_device * sdev) { /* code */ }`` 118*4882a593Smuzhiyun 119*4882a593Smuzhiyun.. [#] the scsi_host_alloc() function is a replacement for the rather vaguely 120*4882a593Smuzhiyun named scsi_register() function in most situations. 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunHotplug initialization model 124*4882a593Smuzhiyun============================ 125*4882a593SmuzhiyunIn this model an LLD controls when SCSI hosts are introduced and removed 126*4882a593Smuzhiyunfrom the SCSI subsystem. Hosts can be introduced as early as driver 127*4882a593Smuzhiyuninitialization and removed as late as driver shutdown. Typically a driver 128*4882a593Smuzhiyunwill respond to a sysfs probe() callback that indicates an HBA has been 129*4882a593Smuzhiyundetected. After confirming that the new device is one that the LLD wants 130*4882a593Smuzhiyunto control, the LLD will initialize the HBA and then register a new host 131*4882a593Smuzhiyunwith the SCSI mid level. 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunDuring LLD initialization the driver should register itself with the 134*4882a593Smuzhiyunappropriate IO bus on which it expects to find HBA(s) (e.g. the PCI bus). 135*4882a593SmuzhiyunThis can probably be done via sysfs. Any driver parameters (especially 136*4882a593Smuzhiyunthose that are writable after the driver is loaded) could also be 137*4882a593Smuzhiyunregistered with sysfs at this point. The SCSI mid level first becomes 138*4882a593Smuzhiyunaware of an LLD when that LLD registers its first HBA. 139*4882a593Smuzhiyun 140*4882a593SmuzhiyunAt some later time, the LLD becomes aware of an HBA and what follows 141*4882a593Smuzhiyunis a typical sequence of calls between the LLD and the mid level. 142*4882a593SmuzhiyunThis example shows the mid level scanning the newly introduced HBA for 3 143*4882a593Smuzhiyunscsi devices of which only the first 2 respond:: 144*4882a593Smuzhiyun 145*4882a593Smuzhiyun HBA PROBE: assume 2 SCSI devices found in scan 146*4882a593Smuzhiyun LLD mid level LLD 147*4882a593Smuzhiyun ===-------------------=========--------------------===------ 148*4882a593Smuzhiyun scsi_host_alloc() --> 149*4882a593Smuzhiyun scsi_add_host() ----> 150*4882a593Smuzhiyun scsi_scan_host() -------+ 151*4882a593Smuzhiyun | 152*4882a593Smuzhiyun slave_alloc() 153*4882a593Smuzhiyun slave_configure() --> scsi_change_queue_depth() 154*4882a593Smuzhiyun | 155*4882a593Smuzhiyun slave_alloc() 156*4882a593Smuzhiyun slave_configure() 157*4882a593Smuzhiyun | 158*4882a593Smuzhiyun slave_alloc() *** 159*4882a593Smuzhiyun slave_destroy() *** 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun 162*4882a593Smuzhiyun *** For scsi devices that the mid level tries to scan but do not 163*4882a593Smuzhiyun respond, a slave_alloc(), slave_destroy() pair is called. 164*4882a593Smuzhiyun 165*4882a593SmuzhiyunIf the LLD wants to adjust the default queue settings, it can invoke 166*4882a593Smuzhiyunscsi_change_queue_depth() in its slave_configure() routine. 167*4882a593Smuzhiyun 168*4882a593SmuzhiyunWhen an HBA is being removed it could be as part of an orderly shutdown 169*4882a593Smuzhiyunassociated with the LLD module being unloaded (e.g. with the "rmmod" 170*4882a593Smuzhiyuncommand) or in response to a "hot unplug" indicated by sysfs()'s 171*4882a593Smuzhiyunremove() callback being invoked. In either case, the sequence is the 172*4882a593Smuzhiyunsame:: 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun HBA REMOVE: assume 2 SCSI devices attached 175*4882a593Smuzhiyun LLD mid level LLD 176*4882a593Smuzhiyun ===----------------------=========-----------------===------ 177*4882a593Smuzhiyun scsi_remove_host() ---------+ 178*4882a593Smuzhiyun | 179*4882a593Smuzhiyun slave_destroy() 180*4882a593Smuzhiyun slave_destroy() 181*4882a593Smuzhiyun scsi_host_put() 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunIt may be useful for a LLD to keep track of struct Scsi_Host instances 184*4882a593Smuzhiyun(a pointer is returned by scsi_host_alloc()). Such instances are "owned" 185*4882a593Smuzhiyunby the mid-level. struct Scsi_Host instances are freed from 186*4882a593Smuzhiyunscsi_host_put() when the reference count hits zero. 187*4882a593Smuzhiyun 188*4882a593SmuzhiyunHot unplugging an HBA that controls a disk which is processing SCSI 189*4882a593Smuzhiyuncommands on a mounted file system is an interesting situation. Reference 190*4882a593Smuzhiyuncounting logic is being introduced into the mid level to cope with many 191*4882a593Smuzhiyunof the issues involved. See the section on reference counting below. 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunThe hotplug concept may be extended to SCSI devices. Currently, when an 195*4882a593SmuzhiyunHBA is added, the scsi_scan_host() function causes a scan for SCSI devices 196*4882a593Smuzhiyunattached to the HBA's SCSI transport. On newer SCSI transports the HBA 197*4882a593Smuzhiyunmay become aware of a new SCSI device _after_ the scan has completed. 198*4882a593SmuzhiyunAn LLD can use this sequence to make the mid level aware of a SCSI device:: 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun SCSI DEVICE hotplug 201*4882a593Smuzhiyun LLD mid level LLD 202*4882a593Smuzhiyun ===-------------------=========--------------------===------ 203*4882a593Smuzhiyun scsi_add_device() ------+ 204*4882a593Smuzhiyun | 205*4882a593Smuzhiyun slave_alloc() 206*4882a593Smuzhiyun slave_configure() [--> scsi_change_queue_depth()] 207*4882a593Smuzhiyun 208*4882a593SmuzhiyunIn a similar fashion, an LLD may become aware that a SCSI device has been 209*4882a593Smuzhiyunremoved (unplugged) or the connection to it has been interrupted. Some 210*4882a593Smuzhiyunexisting SCSI transports (e.g. SPI) may not become aware that a SCSI 211*4882a593Smuzhiyundevice has been removed until a subsequent SCSI command fails which will 212*4882a593Smuzhiyunprobably cause that device to be set offline by the mid level. An LLD that 213*4882a593Smuzhiyundetects the removal of a SCSI device can instigate its removal from 214*4882a593Smuzhiyunupper layers with this sequence:: 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun SCSI DEVICE hot unplug 217*4882a593Smuzhiyun LLD mid level LLD 218*4882a593Smuzhiyun ===----------------------=========-----------------===------ 219*4882a593Smuzhiyun scsi_remove_device() -------+ 220*4882a593Smuzhiyun | 221*4882a593Smuzhiyun slave_destroy() 222*4882a593Smuzhiyun 223*4882a593SmuzhiyunIt may be useful for an LLD to keep track of struct scsi_device instances 224*4882a593Smuzhiyun(a pointer is passed as the parameter to slave_alloc() and 225*4882a593Smuzhiyunslave_configure() callbacks). Such instances are "owned" by the mid-level. 226*4882a593Smuzhiyunstruct scsi_device instances are freed after slave_destroy(). 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun 229*4882a593SmuzhiyunReference Counting 230*4882a593Smuzhiyun================== 231*4882a593SmuzhiyunThe Scsi_Host structure has had reference counting infrastructure added. 232*4882a593SmuzhiyunThis effectively spreads the ownership of struct Scsi_Host instances 233*4882a593Smuzhiyunacross the various SCSI layers which use them. Previously such instances 234*4882a593Smuzhiyunwere exclusively owned by the mid level. LLDs would not usually need to 235*4882a593Smuzhiyundirectly manipulate these reference counts but there may be some cases 236*4882a593Smuzhiyunwhere they do. 237*4882a593Smuzhiyun 238*4882a593SmuzhiyunThere are 3 reference counting functions of interest associated with 239*4882a593Smuzhiyunstruct Scsi_Host: 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun - scsi_host_alloc(): 242*4882a593Smuzhiyun returns a pointer to new instance of struct 243*4882a593Smuzhiyun Scsi_Host which has its reference count ^^ set to 1 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun - scsi_host_get(): 246*4882a593Smuzhiyun adds 1 to the reference count of the given instance 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun - scsi_host_put(): 249*4882a593Smuzhiyun decrements 1 from the reference count of the given 250*4882a593Smuzhiyun instance. If the reference count reaches 0 then the given instance 251*4882a593Smuzhiyun is freed 252*4882a593Smuzhiyun 253*4882a593SmuzhiyunThe scsi_device structure has had reference counting infrastructure added. 254*4882a593SmuzhiyunThis effectively spreads the ownership of struct scsi_device instances 255*4882a593Smuzhiyunacross the various SCSI layers which use them. Previously such instances 256*4882a593Smuzhiyunwere exclusively owned by the mid level. See the access functions declared 257*4882a593Smuzhiyuntowards the end of include/scsi/scsi_device.h . If an LLD wants to keep 258*4882a593Smuzhiyuna copy of a pointer to a scsi_device instance it should use scsi_device_get() 259*4882a593Smuzhiyunto bump its reference count. When it is finished with the pointer it can 260*4882a593Smuzhiyunuse scsi_device_put() to decrement its reference count (and potentially 261*4882a593Smuzhiyundelete it). 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun.. Note:: 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun struct Scsi_Host actually has 2 reference counts which are manipulated 266*4882a593Smuzhiyun in parallel by these functions. 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun 269*4882a593SmuzhiyunConventions 270*4882a593Smuzhiyun=========== 271*4882a593SmuzhiyunFirst, Linus Torvalds's thoughts on C coding style can be found in the 272*4882a593SmuzhiyunDocumentation/process/coding-style.rst file. 273*4882a593Smuzhiyun 274*4882a593SmuzhiyunAlso, most C99 enhancements are encouraged to the extent they are supported 275*4882a593Smuzhiyunby the relevant gcc compilers. So C99 style structure and array 276*4882a593Smuzhiyuninitializers are encouraged where appropriate. Don't go too far, 277*4882a593SmuzhiyunVLAs are not properly supported yet. An exception to this is the use of 278*4882a593Smuzhiyun``//`` style comments; ``/*...*/`` comments are still preferred in Linux. 279*4882a593Smuzhiyun 280*4882a593SmuzhiyunWell written, tested and documented code, need not be re-formatted to 281*4882a593Smuzhiyuncomply with the above conventions. For example, the aic7xxx driver 282*4882a593Smuzhiyuncomes to Linux from FreeBSD and Adaptec's own labs. No doubt FreeBSD 283*4882a593Smuzhiyunand Adaptec have their own coding conventions. 284*4882a593Smuzhiyun 285*4882a593Smuzhiyun 286*4882a593SmuzhiyunMid level supplied functions 287*4882a593Smuzhiyun============================ 288*4882a593SmuzhiyunThese functions are supplied by the SCSI mid level for use by LLDs. 289*4882a593SmuzhiyunThe names (i.e. entry points) of these functions are exported 290*4882a593Smuzhiyunso an LLD that is a module can access them. The kernel will 291*4882a593Smuzhiyunarrange for the SCSI mid level to be loaded and initialized before any LLD 292*4882a593Smuzhiyunis initialized. The functions below are listed alphabetically and their 293*4882a593Smuzhiyunnames all start with ``scsi_``. 294*4882a593Smuzhiyun 295*4882a593SmuzhiyunSummary: 296*4882a593Smuzhiyun 297*4882a593Smuzhiyun - scsi_add_device - creates new scsi device (lu) instance 298*4882a593Smuzhiyun - scsi_add_host - perform sysfs registration and set up transport class 299*4882a593Smuzhiyun - scsi_change_queue_depth - change the queue depth on a SCSI device 300*4882a593Smuzhiyun - scsi_bios_ptable - return copy of block device's partition table 301*4882a593Smuzhiyun - scsi_block_requests - prevent further commands being queued to given host 302*4882a593Smuzhiyun - scsi_host_alloc - return a new scsi_host instance whose refcount==1 303*4882a593Smuzhiyun - scsi_host_get - increments Scsi_Host instance's refcount 304*4882a593Smuzhiyun - scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) 305*4882a593Smuzhiyun - scsi_register - create and register a scsi host adapter instance. 306*4882a593Smuzhiyun - scsi_remove_device - detach and remove a SCSI device 307*4882a593Smuzhiyun - scsi_remove_host - detach and remove all SCSI devices owned by host 308*4882a593Smuzhiyun - scsi_report_bus_reset - report scsi _bus_ reset observed 309*4882a593Smuzhiyun - scsi_scan_host - scan SCSI bus 310*4882a593Smuzhiyun - scsi_track_queue_full - track successive QUEUE_FULL events 311*4882a593Smuzhiyun - scsi_unblock_requests - allow further commands to be queued to given host 312*4882a593Smuzhiyun - scsi_unregister - [calls scsi_host_put()] 313*4882a593Smuzhiyun 314*4882a593Smuzhiyun 315*4882a593SmuzhiyunDetails:: 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun /** 318*4882a593Smuzhiyun * scsi_add_device - creates new scsi device (lu) instance 319*4882a593Smuzhiyun * @shost: pointer to scsi host instance 320*4882a593Smuzhiyun * @channel: channel number (rarely other than 0) 321*4882a593Smuzhiyun * @id: target id number 322*4882a593Smuzhiyun * @lun: logical unit number 323*4882a593Smuzhiyun * 324*4882a593Smuzhiyun * Returns pointer to new struct scsi_device instance or 325*4882a593Smuzhiyun * ERR_PTR(-ENODEV) (or some other bent pointer) if something is 326*4882a593Smuzhiyun * wrong (e.g. no lu responds at given address) 327*4882a593Smuzhiyun * 328*4882a593Smuzhiyun * Might block: yes 329*4882a593Smuzhiyun * 330*4882a593Smuzhiyun * Notes: This call is usually performed internally during a scsi 331*4882a593Smuzhiyun * bus scan when an HBA is added (i.e. scsi_scan_host()). So it 332*4882a593Smuzhiyun * should only be called if the HBA becomes aware of a new scsi 333*4882a593Smuzhiyun * device (lu) after scsi_scan_host() has completed. If successful 334*4882a593Smuzhiyun * this call can lead to slave_alloc() and slave_configure() callbacks 335*4882a593Smuzhiyun * into the LLD. 336*4882a593Smuzhiyun * 337*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_scan.c 338*4882a593Smuzhiyun **/ 339*4882a593Smuzhiyun struct scsi_device * scsi_add_device(struct Scsi_Host *shost, 340*4882a593Smuzhiyun unsigned int channel, 341*4882a593Smuzhiyun unsigned int id, unsigned int lun) 342*4882a593Smuzhiyun 343*4882a593Smuzhiyun 344*4882a593Smuzhiyun /** 345*4882a593Smuzhiyun * scsi_add_host - perform sysfs registration and set up transport class 346*4882a593Smuzhiyun * @shost: pointer to scsi host instance 347*4882a593Smuzhiyun * @dev: pointer to struct device of type scsi class 348*4882a593Smuzhiyun * 349*4882a593Smuzhiyun * Returns 0 on success, negative errno of failure (e.g. -ENOMEM) 350*4882a593Smuzhiyun * 351*4882a593Smuzhiyun * Might block: no 352*4882a593Smuzhiyun * 353*4882a593Smuzhiyun * Notes: Only required in "hotplug initialization model" after a 354*4882a593Smuzhiyun * successful call to scsi_host_alloc(). This function does not 355*4882a593Smuzhiyun * scan the bus; this can be done by calling scsi_scan_host() or 356*4882a593Smuzhiyun * in some other transport-specific way. The LLD must set up 357*4882a593Smuzhiyun * the transport template before calling this function and may only 358*4882a593Smuzhiyun * access the transport class data after this function has been called. 359*4882a593Smuzhiyun * 360*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c 361*4882a593Smuzhiyun **/ 362*4882a593Smuzhiyun int scsi_add_host(struct Scsi_Host *shost, struct device * dev) 363*4882a593Smuzhiyun 364*4882a593Smuzhiyun 365*4882a593Smuzhiyun /** 366*4882a593Smuzhiyun * scsi_change_queue_depth - allow LLD to change queue depth on a SCSI device 367*4882a593Smuzhiyun * @sdev: pointer to SCSI device to change queue depth on 368*4882a593Smuzhiyun * @tags Number of tags allowed if tagged queuing enabled, 369*4882a593Smuzhiyun * or number of commands the LLD can queue up 370*4882a593Smuzhiyun * in non-tagged mode (as per cmd_per_lun). 371*4882a593Smuzhiyun * 372*4882a593Smuzhiyun * Returns nothing 373*4882a593Smuzhiyun * 374*4882a593Smuzhiyun * Might block: no 375*4882a593Smuzhiyun * 376*4882a593Smuzhiyun * Notes: Can be invoked any time on a SCSI device controlled by this 377*4882a593Smuzhiyun * LLD. [Specifically during and after slave_configure() and prior to 378*4882a593Smuzhiyun * slave_destroy().] Can safely be invoked from interrupt code. 379*4882a593Smuzhiyun * 380*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi.c [see source code for more notes] 381*4882a593Smuzhiyun * 382*4882a593Smuzhiyun **/ 383*4882a593Smuzhiyun int scsi_change_queue_depth(struct scsi_device *sdev, int tags) 384*4882a593Smuzhiyun 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun /** 387*4882a593Smuzhiyun * scsi_bios_ptable - return copy of block device's partition table 388*4882a593Smuzhiyun * @dev: pointer to block device 389*4882a593Smuzhiyun * 390*4882a593Smuzhiyun * Returns pointer to partition table, or NULL for failure 391*4882a593Smuzhiyun * 392*4882a593Smuzhiyun * Might block: yes 393*4882a593Smuzhiyun * 394*4882a593Smuzhiyun * Notes: Caller owns memory returned (free with kfree() ) 395*4882a593Smuzhiyun * 396*4882a593Smuzhiyun * Defined in: drivers/scsi/scsicam.c 397*4882a593Smuzhiyun **/ 398*4882a593Smuzhiyun unsigned char *scsi_bios_ptable(struct block_device *dev) 399*4882a593Smuzhiyun 400*4882a593Smuzhiyun 401*4882a593Smuzhiyun /** 402*4882a593Smuzhiyun * scsi_block_requests - prevent further commands being queued to given host 403*4882a593Smuzhiyun * 404*4882a593Smuzhiyun * @shost: pointer to host to block commands on 405*4882a593Smuzhiyun * 406*4882a593Smuzhiyun * Returns nothing 407*4882a593Smuzhiyun * 408*4882a593Smuzhiyun * Might block: no 409*4882a593Smuzhiyun * 410*4882a593Smuzhiyun * Notes: There is no timer nor any other means by which the requests 411*4882a593Smuzhiyun * get unblocked other than the LLD calling scsi_unblock_requests(). 412*4882a593Smuzhiyun * 413*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_lib.c 414*4882a593Smuzhiyun **/ 415*4882a593Smuzhiyun void scsi_block_requests(struct Scsi_Host * shost) 416*4882a593Smuzhiyun 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun /** 419*4882a593Smuzhiyun * scsi_host_alloc - create a scsi host adapter instance and perform basic 420*4882a593Smuzhiyun * initialization. 421*4882a593Smuzhiyun * @sht: pointer to scsi host template 422*4882a593Smuzhiyun * @privsize: extra bytes to allocate in hostdata array (which is the 423*4882a593Smuzhiyun * last member of the returned Scsi_Host instance) 424*4882a593Smuzhiyun * 425*4882a593Smuzhiyun * Returns pointer to new Scsi_Host instance or NULL on failure 426*4882a593Smuzhiyun * 427*4882a593Smuzhiyun * Might block: yes 428*4882a593Smuzhiyun * 429*4882a593Smuzhiyun * Notes: When this call returns to the LLD, the SCSI bus scan on 430*4882a593Smuzhiyun * this host has _not_ yet been done. 431*4882a593Smuzhiyun * The hostdata array (by default zero length) is a per host scratch 432*4882a593Smuzhiyun * area for the LLD's exclusive use. 433*4882a593Smuzhiyun * Both associated refcounting objects have their refcount set to 1. 434*4882a593Smuzhiyun * Full registration (in sysfs) and a bus scan are performed later when 435*4882a593Smuzhiyun * scsi_add_host() and scsi_scan_host() are called. 436*4882a593Smuzhiyun * 437*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c . 438*4882a593Smuzhiyun **/ 439*4882a593Smuzhiyun struct Scsi_Host * scsi_host_alloc(struct scsi_host_template * sht, 440*4882a593Smuzhiyun int privsize) 441*4882a593Smuzhiyun 442*4882a593Smuzhiyun 443*4882a593Smuzhiyun /** 444*4882a593Smuzhiyun * scsi_host_get - increment Scsi_Host instance refcount 445*4882a593Smuzhiyun * @shost: pointer to struct Scsi_Host instance 446*4882a593Smuzhiyun * 447*4882a593Smuzhiyun * Returns nothing 448*4882a593Smuzhiyun * 449*4882a593Smuzhiyun * Might block: currently may block but may be changed to not block 450*4882a593Smuzhiyun * 451*4882a593Smuzhiyun * Notes: Actually increments the counts in two sub-objects 452*4882a593Smuzhiyun * 453*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c 454*4882a593Smuzhiyun **/ 455*4882a593Smuzhiyun void scsi_host_get(struct Scsi_Host *shost) 456*4882a593Smuzhiyun 457*4882a593Smuzhiyun 458*4882a593Smuzhiyun /** 459*4882a593Smuzhiyun * scsi_host_put - decrement Scsi_Host instance refcount, free if 0 460*4882a593Smuzhiyun * @shost: pointer to struct Scsi_Host instance 461*4882a593Smuzhiyun * 462*4882a593Smuzhiyun * Returns nothing 463*4882a593Smuzhiyun * 464*4882a593Smuzhiyun * Might block: currently may block but may be changed to not block 465*4882a593Smuzhiyun * 466*4882a593Smuzhiyun * Notes: Actually decrements the counts in two sub-objects. If the 467*4882a593Smuzhiyun * latter refcount reaches 0, the Scsi_Host instance is freed. 468*4882a593Smuzhiyun * The LLD need not worry exactly when the Scsi_Host instance is 469*4882a593Smuzhiyun * freed, it just shouldn't access the instance after it has balanced 470*4882a593Smuzhiyun * out its refcount usage. 471*4882a593Smuzhiyun * 472*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c 473*4882a593Smuzhiyun **/ 474*4882a593Smuzhiyun void scsi_host_put(struct Scsi_Host *shost) 475*4882a593Smuzhiyun 476*4882a593Smuzhiyun 477*4882a593Smuzhiyun /** 478*4882a593Smuzhiyun * scsi_register - create and register a scsi host adapter instance. 479*4882a593Smuzhiyun * @sht: pointer to scsi host template 480*4882a593Smuzhiyun * @privsize: extra bytes to allocate in hostdata array (which is the 481*4882a593Smuzhiyun * last member of the returned Scsi_Host instance) 482*4882a593Smuzhiyun * 483*4882a593Smuzhiyun * Returns pointer to new Scsi_Host instance or NULL on failure 484*4882a593Smuzhiyun * 485*4882a593Smuzhiyun * Might block: yes 486*4882a593Smuzhiyun * 487*4882a593Smuzhiyun * Notes: When this call returns to the LLD, the SCSI bus scan on 488*4882a593Smuzhiyun * this host has _not_ yet been done. 489*4882a593Smuzhiyun * The hostdata array (by default zero length) is a per host scratch 490*4882a593Smuzhiyun * area for the LLD. 491*4882a593Smuzhiyun * 492*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c . 493*4882a593Smuzhiyun **/ 494*4882a593Smuzhiyun struct Scsi_Host * scsi_register(struct scsi_host_template * sht, 495*4882a593Smuzhiyun int privsize) 496*4882a593Smuzhiyun 497*4882a593Smuzhiyun 498*4882a593Smuzhiyun /** 499*4882a593Smuzhiyun * scsi_remove_device - detach and remove a SCSI device 500*4882a593Smuzhiyun * @sdev: a pointer to a scsi device instance 501*4882a593Smuzhiyun * 502*4882a593Smuzhiyun * Returns value: 0 on success, -EINVAL if device not attached 503*4882a593Smuzhiyun * 504*4882a593Smuzhiyun * Might block: yes 505*4882a593Smuzhiyun * 506*4882a593Smuzhiyun * Notes: If an LLD becomes aware that a scsi device (lu) has 507*4882a593Smuzhiyun * been removed but its host is still present then it can request 508*4882a593Smuzhiyun * the removal of that scsi device. If successful this call will 509*4882a593Smuzhiyun * lead to the slave_destroy() callback being invoked. sdev is an 510*4882a593Smuzhiyun * invalid pointer after this call. 511*4882a593Smuzhiyun * 512*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_sysfs.c . 513*4882a593Smuzhiyun **/ 514*4882a593Smuzhiyun int scsi_remove_device(struct scsi_device *sdev) 515*4882a593Smuzhiyun 516*4882a593Smuzhiyun 517*4882a593Smuzhiyun /** 518*4882a593Smuzhiyun * scsi_remove_host - detach and remove all SCSI devices owned by host 519*4882a593Smuzhiyun * @shost: a pointer to a scsi host instance 520*4882a593Smuzhiyun * 521*4882a593Smuzhiyun * Returns value: 0 on success, 1 on failure (e.g. LLD busy ??) 522*4882a593Smuzhiyun * 523*4882a593Smuzhiyun * Might block: yes 524*4882a593Smuzhiyun * 525*4882a593Smuzhiyun * Notes: Should only be invoked if the "hotplug initialization 526*4882a593Smuzhiyun * model" is being used. It should be called _prior_ to 527*4882a593Smuzhiyun * scsi_unregister(). 528*4882a593Smuzhiyun * 529*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c . 530*4882a593Smuzhiyun **/ 531*4882a593Smuzhiyun int scsi_remove_host(struct Scsi_Host *shost) 532*4882a593Smuzhiyun 533*4882a593Smuzhiyun 534*4882a593Smuzhiyun /** 535*4882a593Smuzhiyun * scsi_report_bus_reset - report scsi _bus_ reset observed 536*4882a593Smuzhiyun * @shost: a pointer to a scsi host involved 537*4882a593Smuzhiyun * @channel: channel (within) host on which scsi bus reset occurred 538*4882a593Smuzhiyun * 539*4882a593Smuzhiyun * Returns nothing 540*4882a593Smuzhiyun * 541*4882a593Smuzhiyun * Might block: no 542*4882a593Smuzhiyun * 543*4882a593Smuzhiyun * Notes: This only needs to be called if the reset is one which 544*4882a593Smuzhiyun * originates from an unknown location. Resets originated by the 545*4882a593Smuzhiyun * mid level itself don't need to call this, but there should be 546*4882a593Smuzhiyun * no harm. The main purpose of this is to make sure that a 547*4882a593Smuzhiyun * CHECK_CONDITION is properly treated. 548*4882a593Smuzhiyun * 549*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_error.c . 550*4882a593Smuzhiyun **/ 551*4882a593Smuzhiyun void scsi_report_bus_reset(struct Scsi_Host * shost, int channel) 552*4882a593Smuzhiyun 553*4882a593Smuzhiyun 554*4882a593Smuzhiyun /** 555*4882a593Smuzhiyun * scsi_scan_host - scan SCSI bus 556*4882a593Smuzhiyun * @shost: a pointer to a scsi host instance 557*4882a593Smuzhiyun * 558*4882a593Smuzhiyun * Might block: yes 559*4882a593Smuzhiyun * 560*4882a593Smuzhiyun * Notes: Should be called after scsi_add_host() 561*4882a593Smuzhiyun * 562*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_scan.c 563*4882a593Smuzhiyun **/ 564*4882a593Smuzhiyun void scsi_scan_host(struct Scsi_Host *shost) 565*4882a593Smuzhiyun 566*4882a593Smuzhiyun 567*4882a593Smuzhiyun /** 568*4882a593Smuzhiyun * scsi_track_queue_full - track successive QUEUE_FULL events on given 569*4882a593Smuzhiyun * device to determine if and when there is a need 570*4882a593Smuzhiyun * to adjust the queue depth on the device. 571*4882a593Smuzhiyun * @sdev: pointer to SCSI device instance 572*4882a593Smuzhiyun * @depth: Current number of outstanding SCSI commands on this device, 573*4882a593Smuzhiyun * not counting the one returned as QUEUE_FULL. 574*4882a593Smuzhiyun * 575*4882a593Smuzhiyun * Returns 0 - no change needed 576*4882a593Smuzhiyun * >0 - adjust queue depth to this new depth 577*4882a593Smuzhiyun * -1 - drop back to untagged operation using host->cmd_per_lun 578*4882a593Smuzhiyun * as the untagged command depth 579*4882a593Smuzhiyun * 580*4882a593Smuzhiyun * Might block: no 581*4882a593Smuzhiyun * 582*4882a593Smuzhiyun * Notes: LLDs may call this at any time and we will do "The Right 583*4882a593Smuzhiyun * Thing"; interrupt context safe. 584*4882a593Smuzhiyun * 585*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi.c . 586*4882a593Smuzhiyun **/ 587*4882a593Smuzhiyun int scsi_track_queue_full(struct scsi_device *sdev, int depth) 588*4882a593Smuzhiyun 589*4882a593Smuzhiyun 590*4882a593Smuzhiyun /** 591*4882a593Smuzhiyun * scsi_unblock_requests - allow further commands to be queued to given host 592*4882a593Smuzhiyun * 593*4882a593Smuzhiyun * @shost: pointer to host to unblock commands on 594*4882a593Smuzhiyun * 595*4882a593Smuzhiyun * Returns nothing 596*4882a593Smuzhiyun * 597*4882a593Smuzhiyun * Might block: no 598*4882a593Smuzhiyun * 599*4882a593Smuzhiyun * Defined in: drivers/scsi/scsi_lib.c . 600*4882a593Smuzhiyun **/ 601*4882a593Smuzhiyun void scsi_unblock_requests(struct Scsi_Host * shost) 602*4882a593Smuzhiyun 603*4882a593Smuzhiyun 604*4882a593Smuzhiyun /** 605*4882a593Smuzhiyun * scsi_unregister - unregister and free memory used by host instance 606*4882a593Smuzhiyun * @shp: pointer to scsi host instance to unregister. 607*4882a593Smuzhiyun * 608*4882a593Smuzhiyun * Returns nothing 609*4882a593Smuzhiyun * 610*4882a593Smuzhiyun * Might block: no 611*4882a593Smuzhiyun * 612*4882a593Smuzhiyun * Notes: Should not be invoked if the "hotplug initialization 613*4882a593Smuzhiyun * model" is being used. Called internally by exit_this_scsi_driver() 614*4882a593Smuzhiyun * in the "passive initialization model". Hence a LLD has no need to 615*4882a593Smuzhiyun * call this function directly. 616*4882a593Smuzhiyun * 617*4882a593Smuzhiyun * Defined in: drivers/scsi/hosts.c . 618*4882a593Smuzhiyun **/ 619*4882a593Smuzhiyun void scsi_unregister(struct Scsi_Host * shp) 620*4882a593Smuzhiyun 621*4882a593Smuzhiyun 622*4882a593Smuzhiyun 623*4882a593Smuzhiyun 624*4882a593SmuzhiyunInterface Functions 625*4882a593Smuzhiyun=================== 626*4882a593SmuzhiyunInterface functions are supplied (defined) by LLDs and their function 627*4882a593Smuzhiyunpointers are placed in an instance of struct scsi_host_template which 628*4882a593Smuzhiyunis passed to scsi_host_alloc() [or scsi_register() / init_this_scsi_driver()]. 629*4882a593SmuzhiyunSome are mandatory. Interface functions should be declared static. The 630*4882a593Smuzhiyunaccepted convention is that driver "xyz" will declare its slave_configure() 631*4882a593Smuzhiyunfunction as:: 632*4882a593Smuzhiyun 633*4882a593Smuzhiyun static int xyz_slave_configure(struct scsi_device * sdev); 634*4882a593Smuzhiyun 635*4882a593Smuzhiyunand so forth for all interface functions listed below. 636*4882a593Smuzhiyun 637*4882a593SmuzhiyunA pointer to this function should be placed in the 'slave_configure' member 638*4882a593Smuzhiyunof a "struct scsi_host_template" instance. A pointer to such an instance 639*4882a593Smuzhiyunshould be passed to the mid level's scsi_host_alloc() [or scsi_register() / 640*4882a593Smuzhiyuninit_this_scsi_driver()]. 641*4882a593Smuzhiyun 642*4882a593SmuzhiyunThe interface functions are also described in the include/scsi/scsi_host.h 643*4882a593Smuzhiyunfile immediately above their definition point in "struct scsi_host_template". 644*4882a593SmuzhiyunIn some cases more detail is given in scsi_host.h than below. 645*4882a593Smuzhiyun 646*4882a593SmuzhiyunThe interface functions are listed below in alphabetical order. 647*4882a593Smuzhiyun 648*4882a593SmuzhiyunSummary: 649*4882a593Smuzhiyun 650*4882a593Smuzhiyun - bios_param - fetch head, sector, cylinder info for a disk 651*4882a593Smuzhiyun - eh_timed_out - notify the host that a command timer expired 652*4882a593Smuzhiyun - eh_abort_handler - abort given command 653*4882a593Smuzhiyun - eh_bus_reset_handler - issue SCSI bus reset 654*4882a593Smuzhiyun - eh_device_reset_handler - issue SCSI device reset 655*4882a593Smuzhiyun - eh_host_reset_handler - reset host (host bus adapter) 656*4882a593Smuzhiyun - info - supply information about given host 657*4882a593Smuzhiyun - ioctl - driver can respond to ioctls 658*4882a593Smuzhiyun - proc_info - supports /proc/scsi/{driver_name}/{host_no} 659*4882a593Smuzhiyun - queuecommand - queue scsi command, invoke 'done' on completion 660*4882a593Smuzhiyun - slave_alloc - prior to any commands being sent to a new device 661*4882a593Smuzhiyun - slave_configure - driver fine tuning for given device after attach 662*4882a593Smuzhiyun - slave_destroy - given device is about to be shut down 663*4882a593Smuzhiyun 664*4882a593Smuzhiyun 665*4882a593SmuzhiyunDetails:: 666*4882a593Smuzhiyun 667*4882a593Smuzhiyun /** 668*4882a593Smuzhiyun * bios_param - fetch head, sector, cylinder info for a disk 669*4882a593Smuzhiyun * @sdev: pointer to scsi device context (defined in 670*4882a593Smuzhiyun * include/scsi/scsi_device.h) 671*4882a593Smuzhiyun * @bdev: pointer to block device context (defined in fs.h) 672*4882a593Smuzhiyun * @capacity: device size (in 512 byte sectors) 673*4882a593Smuzhiyun * @params: three element array to place output: 674*4882a593Smuzhiyun * params[0] number of heads (max 255) 675*4882a593Smuzhiyun * params[1] number of sectors (max 63) 676*4882a593Smuzhiyun * params[2] number of cylinders 677*4882a593Smuzhiyun * 678*4882a593Smuzhiyun * Return value is ignored 679*4882a593Smuzhiyun * 680*4882a593Smuzhiyun * Locks: none 681*4882a593Smuzhiyun * 682*4882a593Smuzhiyun * Calling context: process (sd) 683*4882a593Smuzhiyun * 684*4882a593Smuzhiyun * Notes: an arbitrary geometry (based on READ CAPACITY) is used 685*4882a593Smuzhiyun * if this function is not provided. The params array is 686*4882a593Smuzhiyun * pre-initialized with made up values just in case this function 687*4882a593Smuzhiyun * doesn't output anything. 688*4882a593Smuzhiyun * 689*4882a593Smuzhiyun * Optionally defined in: LLD 690*4882a593Smuzhiyun **/ 691*4882a593Smuzhiyun int bios_param(struct scsi_device * sdev, struct block_device *bdev, 692*4882a593Smuzhiyun sector_t capacity, int params[3]) 693*4882a593Smuzhiyun 694*4882a593Smuzhiyun 695*4882a593Smuzhiyun /** 696*4882a593Smuzhiyun * eh_timed_out - The timer for the command has just fired 697*4882a593Smuzhiyun * @scp: identifies command timing out 698*4882a593Smuzhiyun * 699*4882a593Smuzhiyun * Returns: 700*4882a593Smuzhiyun * 701*4882a593Smuzhiyun * EH_HANDLED: I fixed the error, please complete the command 702*4882a593Smuzhiyun * EH_RESET_TIMER: I need more time, reset the timer and 703*4882a593Smuzhiyun * begin counting again 704*4882a593Smuzhiyun * EH_NOT_HANDLED Begin normal error recovery 705*4882a593Smuzhiyun * 706*4882a593Smuzhiyun * 707*4882a593Smuzhiyun * Locks: None held 708*4882a593Smuzhiyun * 709*4882a593Smuzhiyun * Calling context: interrupt 710*4882a593Smuzhiyun * 711*4882a593Smuzhiyun * Notes: This is to give the LLD an opportunity to do local recovery. 712*4882a593Smuzhiyun * This recovery is limited to determining if the outstanding command 713*4882a593Smuzhiyun * will ever complete. You may not abort and restart the command from 714*4882a593Smuzhiyun * this callback. 715*4882a593Smuzhiyun * 716*4882a593Smuzhiyun * Optionally defined in: LLD 717*4882a593Smuzhiyun **/ 718*4882a593Smuzhiyun int eh_timed_out(struct scsi_cmnd * scp) 719*4882a593Smuzhiyun 720*4882a593Smuzhiyun 721*4882a593Smuzhiyun /** 722*4882a593Smuzhiyun * eh_abort_handler - abort command associated with scp 723*4882a593Smuzhiyun * @scp: identifies command to be aborted 724*4882a593Smuzhiyun * 725*4882a593Smuzhiyun * Returns SUCCESS if command aborted else FAILED 726*4882a593Smuzhiyun * 727*4882a593Smuzhiyun * Locks: None held 728*4882a593Smuzhiyun * 729*4882a593Smuzhiyun * Calling context: kernel thread 730*4882a593Smuzhiyun * 731*4882a593Smuzhiyun * Notes: If 'no_async_abort' is defined this callback 732*4882a593Smuzhiyun * will be invoked from scsi_eh thread. No other commands 733*4882a593Smuzhiyun * will then be queued on current host during eh. 734*4882a593Smuzhiyun * Otherwise it will be called whenever scsi_times_out() 735*4882a593Smuzhiyun * is called due to a command timeout. 736*4882a593Smuzhiyun * 737*4882a593Smuzhiyun * Optionally defined in: LLD 738*4882a593Smuzhiyun **/ 739*4882a593Smuzhiyun int eh_abort_handler(struct scsi_cmnd * scp) 740*4882a593Smuzhiyun 741*4882a593Smuzhiyun 742*4882a593Smuzhiyun /** 743*4882a593Smuzhiyun * eh_bus_reset_handler - issue SCSI bus reset 744*4882a593Smuzhiyun * @scp: SCSI bus that contains this device should be reset 745*4882a593Smuzhiyun * 746*4882a593Smuzhiyun * Returns SUCCESS if command aborted else FAILED 747*4882a593Smuzhiyun * 748*4882a593Smuzhiyun * Locks: None held 749*4882a593Smuzhiyun * 750*4882a593Smuzhiyun * Calling context: kernel thread 751*4882a593Smuzhiyun * 752*4882a593Smuzhiyun * Notes: Invoked from scsi_eh thread. No other commands will be 753*4882a593Smuzhiyun * queued on current host during eh. 754*4882a593Smuzhiyun * 755*4882a593Smuzhiyun * Optionally defined in: LLD 756*4882a593Smuzhiyun **/ 757*4882a593Smuzhiyun int eh_bus_reset_handler(struct scsi_cmnd * scp) 758*4882a593Smuzhiyun 759*4882a593Smuzhiyun 760*4882a593Smuzhiyun /** 761*4882a593Smuzhiyun * eh_device_reset_handler - issue SCSI device reset 762*4882a593Smuzhiyun * @scp: identifies SCSI device to be reset 763*4882a593Smuzhiyun * 764*4882a593Smuzhiyun * Returns SUCCESS if command aborted else FAILED 765*4882a593Smuzhiyun * 766*4882a593Smuzhiyun * Locks: None held 767*4882a593Smuzhiyun * 768*4882a593Smuzhiyun * Calling context: kernel thread 769*4882a593Smuzhiyun * 770*4882a593Smuzhiyun * Notes: Invoked from scsi_eh thread. No other commands will be 771*4882a593Smuzhiyun * queued on current host during eh. 772*4882a593Smuzhiyun * 773*4882a593Smuzhiyun * Optionally defined in: LLD 774*4882a593Smuzhiyun **/ 775*4882a593Smuzhiyun int eh_device_reset_handler(struct scsi_cmnd * scp) 776*4882a593Smuzhiyun 777*4882a593Smuzhiyun 778*4882a593Smuzhiyun /** 779*4882a593Smuzhiyun * eh_host_reset_handler - reset host (host bus adapter) 780*4882a593Smuzhiyun * @scp: SCSI host that contains this device should be reset 781*4882a593Smuzhiyun * 782*4882a593Smuzhiyun * Returns SUCCESS if command aborted else FAILED 783*4882a593Smuzhiyun * 784*4882a593Smuzhiyun * Locks: None held 785*4882a593Smuzhiyun * 786*4882a593Smuzhiyun * Calling context: kernel thread 787*4882a593Smuzhiyun * 788*4882a593Smuzhiyun * Notes: Invoked from scsi_eh thread. No other commands will be 789*4882a593Smuzhiyun * queued on current host during eh. 790*4882a593Smuzhiyun * With the default eh_strategy in place, if none of the _abort_, 791*4882a593Smuzhiyun * _device_reset_, _bus_reset_ or this eh handler function are 792*4882a593Smuzhiyun * defined (or they all return FAILED) then the device in question 793*4882a593Smuzhiyun * will be set offline whenever eh is invoked. 794*4882a593Smuzhiyun * 795*4882a593Smuzhiyun * Optionally defined in: LLD 796*4882a593Smuzhiyun **/ 797*4882a593Smuzhiyun int eh_host_reset_handler(struct scsi_cmnd * scp) 798*4882a593Smuzhiyun 799*4882a593Smuzhiyun 800*4882a593Smuzhiyun /** 801*4882a593Smuzhiyun * info - supply information about given host: driver name plus data 802*4882a593Smuzhiyun * to distinguish given host 803*4882a593Smuzhiyun * @shp: host to supply information about 804*4882a593Smuzhiyun * 805*4882a593Smuzhiyun * Return ASCII null terminated string. [This driver is assumed to 806*4882a593Smuzhiyun * manage the memory pointed to and maintain it, typically for the 807*4882a593Smuzhiyun * lifetime of this host.] 808*4882a593Smuzhiyun * 809*4882a593Smuzhiyun * Locks: none 810*4882a593Smuzhiyun * 811*4882a593Smuzhiyun * Calling context: process 812*4882a593Smuzhiyun * 813*4882a593Smuzhiyun * Notes: Often supplies PCI or ISA information such as IO addresses 814*4882a593Smuzhiyun * and interrupt numbers. If not supplied struct Scsi_Host::name used 815*4882a593Smuzhiyun * instead. It is assumed the returned information fits on one line 816*4882a593Smuzhiyun * (i.e. does not included embedded newlines). 817*4882a593Smuzhiyun * The SCSI_IOCTL_PROBE_HOST ioctl yields the string returned by this 818*4882a593Smuzhiyun * function (or struct Scsi_Host::name if this function is not 819*4882a593Smuzhiyun * available). 820*4882a593Smuzhiyun * In a similar manner, init_this_scsi_driver() outputs to the console 821*4882a593Smuzhiyun * each host's "info" (or name) for the driver it is registering. 822*4882a593Smuzhiyun * Also if proc_info() is not supplied, the output of this function 823*4882a593Smuzhiyun * is used instead. 824*4882a593Smuzhiyun * 825*4882a593Smuzhiyun * Optionally defined in: LLD 826*4882a593Smuzhiyun **/ 827*4882a593Smuzhiyun const char * info(struct Scsi_Host * shp) 828*4882a593Smuzhiyun 829*4882a593Smuzhiyun 830*4882a593Smuzhiyun /** 831*4882a593Smuzhiyun * ioctl - driver can respond to ioctls 832*4882a593Smuzhiyun * @sdp: device that ioctl was issued for 833*4882a593Smuzhiyun * @cmd: ioctl number 834*4882a593Smuzhiyun * @arg: pointer to read or write data from. Since it points to 835*4882a593Smuzhiyun * user space, should use appropriate kernel functions 836*4882a593Smuzhiyun * (e.g. copy_from_user() ). In the Unix style this argument 837*4882a593Smuzhiyun * can also be viewed as an unsigned long. 838*4882a593Smuzhiyun * 839*4882a593Smuzhiyun * Returns negative "errno" value when there is a problem. 0 or a 840*4882a593Smuzhiyun * positive value indicates success and is returned to the user space. 841*4882a593Smuzhiyun * 842*4882a593Smuzhiyun * Locks: none 843*4882a593Smuzhiyun * 844*4882a593Smuzhiyun * Calling context: process 845*4882a593Smuzhiyun * 846*4882a593Smuzhiyun * Notes: The SCSI subsystem uses a "trickle down" ioctl model. 847*4882a593Smuzhiyun * The user issues an ioctl() against an upper level driver 848*4882a593Smuzhiyun * (e.g. /dev/sdc) and if the upper level driver doesn't recognize 849*4882a593Smuzhiyun * the 'cmd' then it is passed to the SCSI mid level. If the SCSI 850*4882a593Smuzhiyun * mid level does not recognize it, then the LLD that controls 851*4882a593Smuzhiyun * the device receives the ioctl. According to recent Unix standards 852*4882a593Smuzhiyun * unsupported ioctl() 'cmd' numbers should return -ENOTTY. 853*4882a593Smuzhiyun * 854*4882a593Smuzhiyun * Optionally defined in: LLD 855*4882a593Smuzhiyun **/ 856*4882a593Smuzhiyun int ioctl(struct scsi_device *sdp, int cmd, void *arg) 857*4882a593Smuzhiyun 858*4882a593Smuzhiyun 859*4882a593Smuzhiyun /** 860*4882a593Smuzhiyun * proc_info - supports /proc/scsi/{driver_name}/{host_no} 861*4882a593Smuzhiyun * @buffer: anchor point to output to (0==writeto1_read0) or fetch from 862*4882a593Smuzhiyun * (1==writeto1_read0). 863*4882a593Smuzhiyun * @start: where "interesting" data is written to. Ignored when 864*4882a593Smuzhiyun * 1==writeto1_read0. 865*4882a593Smuzhiyun * @offset: offset within buffer 0==writeto1_read0 is actually 866*4882a593Smuzhiyun * interested in. Ignored when 1==writeto1_read0 . 867*4882a593Smuzhiyun * @length: maximum (or actual) extent of buffer 868*4882a593Smuzhiyun * @host_no: host number of interest (struct Scsi_Host::host_no) 869*4882a593Smuzhiyun * @writeto1_read0: 1 -> data coming from user space towards driver 870*4882a593Smuzhiyun * (e.g. "echo some_string > /proc/scsi/xyz/2") 871*4882a593Smuzhiyun * 0 -> user what data from this driver 872*4882a593Smuzhiyun * (e.g. "cat /proc/scsi/xyz/2") 873*4882a593Smuzhiyun * 874*4882a593Smuzhiyun * Returns length when 1==writeto1_read0. Otherwise number of chars 875*4882a593Smuzhiyun * output to buffer past offset. 876*4882a593Smuzhiyun * 877*4882a593Smuzhiyun * Locks: none held 878*4882a593Smuzhiyun * 879*4882a593Smuzhiyun * Calling context: process 880*4882a593Smuzhiyun * 881*4882a593Smuzhiyun * Notes: Driven from scsi_proc.c which interfaces to proc_fs. proc_fs 882*4882a593Smuzhiyun * support can now be configured out of the scsi subsystem. 883*4882a593Smuzhiyun * 884*4882a593Smuzhiyun * Optionally defined in: LLD 885*4882a593Smuzhiyun **/ 886*4882a593Smuzhiyun int proc_info(char * buffer, char ** start, off_t offset, 887*4882a593Smuzhiyun int length, int host_no, int writeto1_read0) 888*4882a593Smuzhiyun 889*4882a593Smuzhiyun 890*4882a593Smuzhiyun /** 891*4882a593Smuzhiyun * queuecommand - queue scsi command, invoke scp->scsi_done on completion 892*4882a593Smuzhiyun * @shost: pointer to the scsi host object 893*4882a593Smuzhiyun * @scp: pointer to scsi command object 894*4882a593Smuzhiyun * 895*4882a593Smuzhiyun * Returns 0 on success. 896*4882a593Smuzhiyun * 897*4882a593Smuzhiyun * If there's a failure, return either: 898*4882a593Smuzhiyun * 899*4882a593Smuzhiyun * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or 900*4882a593Smuzhiyun * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full 901*4882a593Smuzhiyun * 902*4882a593Smuzhiyun * On both of these returns, the mid-layer will requeue the I/O 903*4882a593Smuzhiyun * 904*4882a593Smuzhiyun * - if the return is SCSI_MLQUEUE_DEVICE_BUSY, only that particular 905*4882a593Smuzhiyun * device will be paused, and it will be unpaused when a command to 906*4882a593Smuzhiyun * the device returns (or after a brief delay if there are no more 907*4882a593Smuzhiyun * outstanding commands to it). Commands to other devices continue 908*4882a593Smuzhiyun * to be processed normally. 909*4882a593Smuzhiyun * 910*4882a593Smuzhiyun * - if the return is SCSI_MLQUEUE_HOST_BUSY, all I/O to the host 911*4882a593Smuzhiyun * is paused and will be unpaused when any command returns from 912*4882a593Smuzhiyun * the host (or after a brief delay if there are no outstanding 913*4882a593Smuzhiyun * commands to the host). 914*4882a593Smuzhiyun * 915*4882a593Smuzhiyun * For compatibility with earlier versions of queuecommand, any 916*4882a593Smuzhiyun * other return value is treated the same as 917*4882a593Smuzhiyun * SCSI_MLQUEUE_HOST_BUSY. 918*4882a593Smuzhiyun * 919*4882a593Smuzhiyun * Other types of errors that are detected immediately may be 920*4882a593Smuzhiyun * flagged by setting scp->result to an appropriate value, 921*4882a593Smuzhiyun * invoking the scp->scsi_done callback, and then returning 0 922*4882a593Smuzhiyun * from this function. If the command is not performed 923*4882a593Smuzhiyun * immediately (and the LLD is starting (or will start) the given 924*4882a593Smuzhiyun * command) then this function should place 0 in scp->result and 925*4882a593Smuzhiyun * return 0. 926*4882a593Smuzhiyun * 927*4882a593Smuzhiyun * Command ownership. If the driver returns zero, it owns the 928*4882a593Smuzhiyun * command and must take responsibility for ensuring the 929*4882a593Smuzhiyun * scp->scsi_done callback is executed. Note: the driver may 930*4882a593Smuzhiyun * call scp->scsi_done before returning zero, but after it has 931*4882a593Smuzhiyun * called scp->scsi_done, it may not return any value other than 932*4882a593Smuzhiyun * zero. If the driver makes a non-zero return, it must not 933*4882a593Smuzhiyun * execute the command's scsi_done callback at any time. 934*4882a593Smuzhiyun * 935*4882a593Smuzhiyun * Locks: up to and including 2.6.36, struct Scsi_Host::host_lock 936*4882a593Smuzhiyun * held on entry (with "irqsave") and is expected to be 937*4882a593Smuzhiyun * held on return. From 2.6.37 onwards, queuecommand is 938*4882a593Smuzhiyun * called without any locks held. 939*4882a593Smuzhiyun * 940*4882a593Smuzhiyun * Calling context: in interrupt (soft irq) or process context 941*4882a593Smuzhiyun * 942*4882a593Smuzhiyun * Notes: This function should be relatively fast. Normally it 943*4882a593Smuzhiyun * will not wait for IO to complete. Hence the scp->scsi_done 944*4882a593Smuzhiyun * callback is invoked (often directly from an interrupt service 945*4882a593Smuzhiyun * routine) some time after this function has returned. In some 946*4882a593Smuzhiyun * cases (e.g. pseudo adapter drivers that manufacture the 947*4882a593Smuzhiyun * response to a SCSI INQUIRY) the scp->scsi_done callback may be 948*4882a593Smuzhiyun * invoked before this function returns. If the scp->scsi_done 949*4882a593Smuzhiyun * callback is not invoked within a certain period the SCSI mid 950*4882a593Smuzhiyun * level will commence error processing. If a status of CHECK 951*4882a593Smuzhiyun * CONDITION is placed in "result" when the scp->scsi_done 952*4882a593Smuzhiyun * callback is invoked, then the LLD driver should perform 953*4882a593Smuzhiyun * autosense and fill in the struct scsi_cmnd::sense_buffer 954*4882a593Smuzhiyun * array. The scsi_cmnd::sense_buffer array is zeroed prior to 955*4882a593Smuzhiyun * the mid level queuing a command to an LLD. 956*4882a593Smuzhiyun * 957*4882a593Smuzhiyun * Defined in: LLD 958*4882a593Smuzhiyun **/ 959*4882a593Smuzhiyun int queuecommand(struct Scsi_Host *shost, struct scsi_cmnd * scp) 960*4882a593Smuzhiyun 961*4882a593Smuzhiyun 962*4882a593Smuzhiyun /** 963*4882a593Smuzhiyun * slave_alloc - prior to any commands being sent to a new device 964*4882a593Smuzhiyun * (i.e. just prior to scan) this call is made 965*4882a593Smuzhiyun * @sdp: pointer to new device (about to be scanned) 966*4882a593Smuzhiyun * 967*4882a593Smuzhiyun * Returns 0 if ok. Any other return is assumed to be an error and 968*4882a593Smuzhiyun * the device is ignored. 969*4882a593Smuzhiyun * 970*4882a593Smuzhiyun * Locks: none 971*4882a593Smuzhiyun * 972*4882a593Smuzhiyun * Calling context: process 973*4882a593Smuzhiyun * 974*4882a593Smuzhiyun * Notes: Allows the driver to allocate any resources for a device 975*4882a593Smuzhiyun * prior to its initial scan. The corresponding scsi device may not 976*4882a593Smuzhiyun * exist but the mid level is just about to scan for it (i.e. send 977*4882a593Smuzhiyun * and INQUIRY command plus ...). If a device is found then 978*4882a593Smuzhiyun * slave_configure() will be called while if a device is not found 979*4882a593Smuzhiyun * slave_destroy() is called. 980*4882a593Smuzhiyun * For more details see the include/scsi/scsi_host.h file. 981*4882a593Smuzhiyun * 982*4882a593Smuzhiyun * Optionally defined in: LLD 983*4882a593Smuzhiyun **/ 984*4882a593Smuzhiyun int slave_alloc(struct scsi_device *sdp) 985*4882a593Smuzhiyun 986*4882a593Smuzhiyun 987*4882a593Smuzhiyun /** 988*4882a593Smuzhiyun * slave_configure - driver fine tuning for given device just after it 989*4882a593Smuzhiyun * has been first scanned (i.e. it responded to an 990*4882a593Smuzhiyun * INQUIRY) 991*4882a593Smuzhiyun * @sdp: device that has just been attached 992*4882a593Smuzhiyun * 993*4882a593Smuzhiyun * Returns 0 if ok. Any other return is assumed to be an error and 994*4882a593Smuzhiyun * the device is taken offline. [offline devices will _not_ have 995*4882a593Smuzhiyun * slave_destroy() called on them so clean up resources.] 996*4882a593Smuzhiyun * 997*4882a593Smuzhiyun * Locks: none 998*4882a593Smuzhiyun * 999*4882a593Smuzhiyun * Calling context: process 1000*4882a593Smuzhiyun * 1001*4882a593Smuzhiyun * Notes: Allows the driver to inspect the response to the initial 1002*4882a593Smuzhiyun * INQUIRY done by the scanning code and take appropriate action. 1003*4882a593Smuzhiyun * For more details see the include/scsi/scsi_host.h file. 1004*4882a593Smuzhiyun * 1005*4882a593Smuzhiyun * Optionally defined in: LLD 1006*4882a593Smuzhiyun **/ 1007*4882a593Smuzhiyun int slave_configure(struct scsi_device *sdp) 1008*4882a593Smuzhiyun 1009*4882a593Smuzhiyun 1010*4882a593Smuzhiyun /** 1011*4882a593Smuzhiyun * slave_destroy - given device is about to be shut down. All 1012*4882a593Smuzhiyun * activity has ceased on this device. 1013*4882a593Smuzhiyun * @sdp: device that is about to be shut down 1014*4882a593Smuzhiyun * 1015*4882a593Smuzhiyun * Returns nothing 1016*4882a593Smuzhiyun * 1017*4882a593Smuzhiyun * Locks: none 1018*4882a593Smuzhiyun * 1019*4882a593Smuzhiyun * Calling context: process 1020*4882a593Smuzhiyun * 1021*4882a593Smuzhiyun * Notes: Mid level structures for given device are still in place 1022*4882a593Smuzhiyun * but are about to be torn down. Any per device resources allocated 1023*4882a593Smuzhiyun * by this driver for given device should be freed now. No further 1024*4882a593Smuzhiyun * commands will be sent for this sdp instance. [However the device 1025*4882a593Smuzhiyun * could be re-attached in the future in which case a new instance 1026*4882a593Smuzhiyun * of struct scsi_device would be supplied by future slave_alloc() 1027*4882a593Smuzhiyun * and slave_configure() calls.] 1028*4882a593Smuzhiyun * 1029*4882a593Smuzhiyun * Optionally defined in: LLD 1030*4882a593Smuzhiyun **/ 1031*4882a593Smuzhiyun void slave_destroy(struct scsi_device *sdp) 1032*4882a593Smuzhiyun 1033*4882a593Smuzhiyun 1034*4882a593Smuzhiyun 1035*4882a593SmuzhiyunData Structures 1036*4882a593Smuzhiyun=============== 1037*4882a593Smuzhiyunstruct scsi_host_template 1038*4882a593Smuzhiyun------------------------- 1039*4882a593SmuzhiyunThere is one "struct scsi_host_template" instance per LLD [#]_. It is 1040*4882a593Smuzhiyuntypically initialized as a file scope static in a driver's header file. That 1041*4882a593Smuzhiyunway members that are not explicitly initialized will be set to 0 or NULL. 1042*4882a593SmuzhiyunMember of interest: 1043*4882a593Smuzhiyun 1044*4882a593Smuzhiyun name 1045*4882a593Smuzhiyun - name of driver (may contain spaces, please limit to 1046*4882a593Smuzhiyun less than 80 characters) 1047*4882a593Smuzhiyun 1048*4882a593Smuzhiyun proc_name 1049*4882a593Smuzhiyun - name used in "/proc/scsi/<proc_name>/<host_no>" and 1050*4882a593Smuzhiyun by sysfs in one of its "drivers" directories. Hence 1051*4882a593Smuzhiyun "proc_name" should only contain characters acceptable 1052*4882a593Smuzhiyun to a Unix file name. 1053*4882a593Smuzhiyun 1054*4882a593Smuzhiyun ``(*queuecommand)()`` 1055*4882a593Smuzhiyun - primary callback that the mid level uses to inject 1056*4882a593Smuzhiyun SCSI commands into an LLD. 1057*4882a593Smuzhiyun 1058*4882a593SmuzhiyunThe structure is defined and commented in include/scsi/scsi_host.h 1059*4882a593Smuzhiyun 1060*4882a593Smuzhiyun.. [#] In extreme situations a single driver may have several instances 1061*4882a593Smuzhiyun if it controls several different classes of hardware (e.g. an LLD 1062*4882a593Smuzhiyun that handles both ISA and PCI cards and has a separate instance of 1063*4882a593Smuzhiyun struct scsi_host_template for each class). 1064*4882a593Smuzhiyun 1065*4882a593Smuzhiyunstruct Scsi_Host 1066*4882a593Smuzhiyun---------------- 1067*4882a593SmuzhiyunThere is one struct Scsi_Host instance per host (HBA) that an LLD 1068*4882a593Smuzhiyuncontrols. The struct Scsi_Host structure has many members in common 1069*4882a593Smuzhiyunwith "struct scsi_host_template". When a new struct Scsi_Host instance 1070*4882a593Smuzhiyunis created (in scsi_host_alloc() in hosts.c) those common members are 1071*4882a593Smuzhiyuninitialized from the driver's struct scsi_host_template instance. Members 1072*4882a593Smuzhiyunof interest: 1073*4882a593Smuzhiyun 1074*4882a593Smuzhiyun host_no 1075*4882a593Smuzhiyun - system wide unique number that is used for identifying 1076*4882a593Smuzhiyun this host. Issued in ascending order from 0. 1077*4882a593Smuzhiyun can_queue 1078*4882a593Smuzhiyun - must be greater than 0; do not send more than can_queue 1079*4882a593Smuzhiyun commands to the adapter. 1080*4882a593Smuzhiyun this_id 1081*4882a593Smuzhiyun - scsi id of host (scsi initiator) or -1 if not known 1082*4882a593Smuzhiyun sg_tablesize 1083*4882a593Smuzhiyun - maximum scatter gather elements allowed by host. 1084*4882a593Smuzhiyun Set this to SG_ALL or less to avoid chained SG lists. 1085*4882a593Smuzhiyun Must be at least 1. 1086*4882a593Smuzhiyun max_sectors 1087*4882a593Smuzhiyun - maximum number of sectors (usually 512 bytes) allowed 1088*4882a593Smuzhiyun in a single SCSI command. The default value of 0 leads 1089*4882a593Smuzhiyun to a setting of SCSI_DEFAULT_MAX_SECTORS (defined in 1090*4882a593Smuzhiyun scsi_host.h) which is currently set to 1024. So for a 1091*4882a593Smuzhiyun disk the maximum transfer size is 512 KB when max_sectors 1092*4882a593Smuzhiyun is not defined. Note that this size may not be sufficient 1093*4882a593Smuzhiyun for disk firmware uploads. 1094*4882a593Smuzhiyun cmd_per_lun 1095*4882a593Smuzhiyun - maximum number of commands that can be queued on devices 1096*4882a593Smuzhiyun controlled by the host. Overridden by LLD calls to 1097*4882a593Smuzhiyun scsi_change_queue_depth(). 1098*4882a593Smuzhiyun unchecked_isa_dma 1099*4882a593Smuzhiyun - 1=>only use bottom 16 MB of ram (ISA DMA addressing 1100*4882a593Smuzhiyun restriction), 0=>can use full 32 bit (or better) DMA 1101*4882a593Smuzhiyun address space 1102*4882a593Smuzhiyun no_async_abort 1103*4882a593Smuzhiyun - 1=>Asynchronous aborts are not supported 1104*4882a593Smuzhiyun - 0=>Timed-out commands will be aborted asynchronously 1105*4882a593Smuzhiyun hostt 1106*4882a593Smuzhiyun - pointer to driver's struct scsi_host_template from which 1107*4882a593Smuzhiyun this struct Scsi_Host instance was spawned 1108*4882a593Smuzhiyun hostt->proc_name 1109*4882a593Smuzhiyun - name of LLD. This is the driver name that sysfs uses 1110*4882a593Smuzhiyun transportt 1111*4882a593Smuzhiyun - pointer to driver's struct scsi_transport_template instance 1112*4882a593Smuzhiyun (if any). FC and SPI transports currently supported. 1113*4882a593Smuzhiyun sh_list 1114*4882a593Smuzhiyun - a double linked list of pointers to all struct Scsi_Host 1115*4882a593Smuzhiyun instances (currently ordered by ascending host_no) 1116*4882a593Smuzhiyun my_devices 1117*4882a593Smuzhiyun - a double linked list of pointers to struct scsi_device 1118*4882a593Smuzhiyun instances that belong to this host. 1119*4882a593Smuzhiyun hostdata[0] 1120*4882a593Smuzhiyun - area reserved for LLD at end of struct Scsi_Host. Size 1121*4882a593Smuzhiyun is set by the second argument (named 'xtr_bytes') to 1122*4882a593Smuzhiyun scsi_host_alloc() or scsi_register(). 1123*4882a593Smuzhiyun vendor_id 1124*4882a593Smuzhiyun - a unique value that identifies the vendor supplying 1125*4882a593Smuzhiyun the LLD for the Scsi_Host. Used most often in validating 1126*4882a593Smuzhiyun vendor-specific message requests. Value consists of an 1127*4882a593Smuzhiyun identifier type and a vendor-specific value. 1128*4882a593Smuzhiyun See scsi_netlink.h for a description of valid formats. 1129*4882a593Smuzhiyun 1130*4882a593SmuzhiyunThe scsi_host structure is defined in include/scsi/scsi_host.h 1131*4882a593Smuzhiyun 1132*4882a593Smuzhiyunstruct scsi_device 1133*4882a593Smuzhiyun------------------ 1134*4882a593SmuzhiyunGenerally, there is one instance of this structure for each SCSI logical unit 1135*4882a593Smuzhiyunon a host. Scsi devices connected to a host are uniquely identified by a 1136*4882a593Smuzhiyunchannel number, target id and logical unit number (lun). 1137*4882a593SmuzhiyunThe structure is defined in include/scsi/scsi_device.h 1138*4882a593Smuzhiyun 1139*4882a593Smuzhiyunstruct scsi_cmnd 1140*4882a593Smuzhiyun---------------- 1141*4882a593SmuzhiyunInstances of this structure convey SCSI commands to the LLD and responses 1142*4882a593Smuzhiyunback to the mid level. The SCSI mid level will ensure that no more SCSI 1143*4882a593Smuzhiyuncommands become queued against the LLD than are indicated by 1144*4882a593Smuzhiyunscsi_change_queue_depth() (or struct Scsi_Host::cmd_per_lun). There will 1145*4882a593Smuzhiyunbe at least one instance of struct scsi_cmnd available for each SCSI device. 1146*4882a593SmuzhiyunMembers of interest: 1147*4882a593Smuzhiyun 1148*4882a593Smuzhiyun cmnd 1149*4882a593Smuzhiyun - array containing SCSI command 1150*4882a593Smuzhiyun cmnd_len 1151*4882a593Smuzhiyun - length (in bytes) of SCSI command 1152*4882a593Smuzhiyun sc_data_direction 1153*4882a593Smuzhiyun - direction of data transfer in data phase. See 1154*4882a593Smuzhiyun "enum dma_data_direction" in include/linux/dma-mapping.h 1155*4882a593Smuzhiyun request_bufflen 1156*4882a593Smuzhiyun - number of data bytes to transfer (0 if no data phase) 1157*4882a593Smuzhiyun use_sg 1158*4882a593Smuzhiyun - ==0 -> no scatter gather list, hence transfer data 1159*4882a593Smuzhiyun to/from request_buffer 1160*4882a593Smuzhiyun - >0 -> scatter gather list (actually an array) in 1161*4882a593Smuzhiyun request_buffer with use_sg elements 1162*4882a593Smuzhiyun request_buffer 1163*4882a593Smuzhiyun - either contains data buffer or scatter gather list 1164*4882a593Smuzhiyun depending on the setting of use_sg. Scatter gather 1165*4882a593Smuzhiyun elements are defined by 'struct scatterlist' found 1166*4882a593Smuzhiyun in include/linux/scatterlist.h . 1167*4882a593Smuzhiyun done 1168*4882a593Smuzhiyun - function pointer that should be invoked by LLD when the 1169*4882a593Smuzhiyun SCSI command is completed (successfully or otherwise). 1170*4882a593Smuzhiyun Should only be called by an LLD if the LLD has accepted 1171*4882a593Smuzhiyun the command (i.e. queuecommand() returned or will return 1172*4882a593Smuzhiyun 0). The LLD may invoke 'done' prior to queuecommand() 1173*4882a593Smuzhiyun finishing. 1174*4882a593Smuzhiyun result 1175*4882a593Smuzhiyun - should be set by LLD prior to calling 'done'. A value 1176*4882a593Smuzhiyun of 0 implies a successfully completed command (and all 1177*4882a593Smuzhiyun data (if any) has been transferred to or from the SCSI 1178*4882a593Smuzhiyun target device). 'result' is a 32 bit unsigned integer that 1179*4882a593Smuzhiyun can be viewed as 4 related bytes. The SCSI status value is 1180*4882a593Smuzhiyun in the LSB. See include/scsi/scsi.h status_byte(), 1181*4882a593Smuzhiyun msg_byte(), host_byte() and driver_byte() macros and 1182*4882a593Smuzhiyun related constants. 1183*4882a593Smuzhiyun sense_buffer 1184*4882a593Smuzhiyun - an array (maximum size: SCSI_SENSE_BUFFERSIZE bytes) that 1185*4882a593Smuzhiyun should be written when the SCSI status (LSB of 'result') 1186*4882a593Smuzhiyun is set to CHECK_CONDITION (2). When CHECK_CONDITION is 1187*4882a593Smuzhiyun set, if the top nibble of sense_buffer[0] has the value 7 1188*4882a593Smuzhiyun then the mid level will assume the sense_buffer array 1189*4882a593Smuzhiyun contains a valid SCSI sense buffer; otherwise the mid 1190*4882a593Smuzhiyun level will issue a REQUEST_SENSE SCSI command to 1191*4882a593Smuzhiyun retrieve the sense buffer. The latter strategy is error 1192*4882a593Smuzhiyun prone in the presence of command queuing so the LLD should 1193*4882a593Smuzhiyun always "auto-sense". 1194*4882a593Smuzhiyun device 1195*4882a593Smuzhiyun - pointer to scsi_device object that this command is 1196*4882a593Smuzhiyun associated with. 1197*4882a593Smuzhiyun resid 1198*4882a593Smuzhiyun - an LLD should set this signed integer to the requested 1199*4882a593Smuzhiyun transfer length (i.e. 'request_bufflen') less the number 1200*4882a593Smuzhiyun of bytes that are actually transferred. 'resid' is 1201*4882a593Smuzhiyun preset to 0 so an LLD can ignore it if it cannot detect 1202*4882a593Smuzhiyun underruns (overruns should be rare). If possible an LLD 1203*4882a593Smuzhiyun should set 'resid' prior to invoking 'done'. The most 1204*4882a593Smuzhiyun interesting case is data transfers from a SCSI target 1205*4882a593Smuzhiyun device (e.g. READs) that underrun. 1206*4882a593Smuzhiyun underflow 1207*4882a593Smuzhiyun - LLD should place (DID_ERROR << 16) in 'result' if 1208*4882a593Smuzhiyun actual number of bytes transferred is less than this 1209*4882a593Smuzhiyun figure. Not many LLDs implement this check and some that 1210*4882a593Smuzhiyun do just output an error message to the log rather than 1211*4882a593Smuzhiyun report a DID_ERROR. Better for an LLD to implement 1212*4882a593Smuzhiyun 'resid'. 1213*4882a593Smuzhiyun 1214*4882a593SmuzhiyunIt is recommended that a LLD set 'resid' on data transfers from a SCSI 1215*4882a593Smuzhiyuntarget device (e.g. READs). It is especially important that 'resid' is set 1216*4882a593Smuzhiyunwhen such data transfers have sense keys of MEDIUM ERROR and HARDWARE ERROR 1217*4882a593Smuzhiyun(and possibly RECOVERED ERROR). In these cases if a LLD is in doubt how much 1218*4882a593Smuzhiyundata has been received then the safest approach is to indicate no bytes have 1219*4882a593Smuzhiyunbeen received. For example: to indicate that no valid data has been received 1220*4882a593Smuzhiyuna LLD might use these helpers:: 1221*4882a593Smuzhiyun 1222*4882a593Smuzhiyun scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); 1223*4882a593Smuzhiyun 1224*4882a593Smuzhiyunwhere 'SCpnt' is a pointer to a scsi_cmnd object. To indicate only three 512 1225*4882a593Smuzhiyunbytes blocks has been received 'resid' could be set like this:: 1226*4882a593Smuzhiyun 1227*4882a593Smuzhiyun scsi_set_resid(SCpnt, scsi_bufflen(SCpnt) - (3 * 512)); 1228*4882a593Smuzhiyun 1229*4882a593SmuzhiyunThe scsi_cmnd structure is defined in include/scsi/scsi_cmnd.h 1230*4882a593Smuzhiyun 1231*4882a593Smuzhiyun 1232*4882a593SmuzhiyunLocks 1233*4882a593Smuzhiyun===== 1234*4882a593SmuzhiyunEach struct Scsi_Host instance has a spin_lock called struct 1235*4882a593SmuzhiyunScsi_Host::default_lock which is initialized in scsi_host_alloc() [found in 1236*4882a593Smuzhiyunhosts.c]. Within the same function the struct Scsi_Host::host_lock pointer 1237*4882a593Smuzhiyunis initialized to point at default_lock. Thereafter lock and unlock 1238*4882a593Smuzhiyunoperations performed by the mid level use the struct Scsi_Host::host_lock 1239*4882a593Smuzhiyunpointer. Previously drivers could override the host_lock pointer but 1240*4882a593Smuzhiyunthis is not allowed anymore. 1241*4882a593Smuzhiyun 1242*4882a593Smuzhiyun 1243*4882a593SmuzhiyunAutosense 1244*4882a593Smuzhiyun========= 1245*4882a593SmuzhiyunAutosense (or auto-sense) is defined in the SAM-2 document as "the 1246*4882a593Smuzhiyunautomatic return of sense data to the application client coincident 1247*4882a593Smuzhiyunwith the completion of a SCSI command" when a status of CHECK CONDITION 1248*4882a593Smuzhiyunoccurs. LLDs should perform autosense. This should be done when the LLD 1249*4882a593Smuzhiyundetects a CHECK CONDITION status by either: 1250*4882a593Smuzhiyun 1251*4882a593Smuzhiyun a) instructing the SCSI protocol (e.g. SCSI Parallel Interface (SPI)) 1252*4882a593Smuzhiyun to perform an extra data in phase on such responses 1253*4882a593Smuzhiyun b) or, the LLD issuing a REQUEST SENSE command itself 1254*4882a593Smuzhiyun 1255*4882a593SmuzhiyunEither way, when a status of CHECK CONDITION is detected, the mid level 1256*4882a593Smuzhiyundecides whether the LLD has performed autosense by checking struct 1257*4882a593Smuzhiyunscsi_cmnd::sense_buffer[0] . If this byte has an upper nibble of 7 (or 0xf) 1258*4882a593Smuzhiyunthen autosense is assumed to have taken place. If it has another value (and 1259*4882a593Smuzhiyunthis byte is initialized to 0 before each command) then the mid level will 1260*4882a593Smuzhiyunissue a REQUEST SENSE command. 1261*4882a593Smuzhiyun 1262*4882a593SmuzhiyunIn the presence of queued commands the "nexus" that maintains sense 1263*4882a593Smuzhiyunbuffer data from the command that failed until a following REQUEST SENSE 1264*4882a593Smuzhiyunmay get out of synchronization. This is why it is best for the LLD 1265*4882a593Smuzhiyunto perform autosense. 1266*4882a593Smuzhiyun 1267*4882a593Smuzhiyun 1268*4882a593SmuzhiyunChanges since lk 2.4 series 1269*4882a593Smuzhiyun=========================== 1270*4882a593Smuzhiyunio_request_lock has been replaced by several finer grained locks. The lock 1271*4882a593Smuzhiyunrelevant to LLDs is struct Scsi_Host::host_lock and there is 1272*4882a593Smuzhiyunone per SCSI host. 1273*4882a593Smuzhiyun 1274*4882a593SmuzhiyunThe older error handling mechanism has been removed. This means the 1275*4882a593SmuzhiyunLLD interface functions abort() and reset() have been removed. 1276*4882a593SmuzhiyunThe struct scsi_host_template::use_new_eh_code flag has been removed. 1277*4882a593Smuzhiyun 1278*4882a593SmuzhiyunIn the 2.4 series the SCSI subsystem configuration descriptions were 1279*4882a593Smuzhiyunaggregated with the configuration descriptions from all other Linux 1280*4882a593Smuzhiyunsubsystems in the Documentation/Configure.help file. In the 2.6 series, 1281*4882a593Smuzhiyunthe SCSI subsystem now has its own (much smaller) drivers/scsi/Kconfig 1282*4882a593Smuzhiyunfile that contains both configuration and help information. 1283*4882a593Smuzhiyun 1284*4882a593Smuzhiyunstruct SHT has been renamed to struct scsi_host_template. 1285*4882a593Smuzhiyun 1286*4882a593SmuzhiyunAddition of the "hotplug initialization model" and many extra functions 1287*4882a593Smuzhiyunto support it. 1288*4882a593Smuzhiyun 1289*4882a593Smuzhiyun 1290*4882a593SmuzhiyunCredits 1291*4882a593Smuzhiyun======= 1292*4882a593SmuzhiyunThe following people have contributed to this document: 1293*4882a593Smuzhiyun 1294*4882a593Smuzhiyun - Mike Anderson <andmike at us dot ibm dot com> 1295*4882a593Smuzhiyun - James Bottomley <James dot Bottomley at hansenpartnership dot com> 1296*4882a593Smuzhiyun - Patrick Mansfield <patmans at us dot ibm dot com> 1297*4882a593Smuzhiyun - Christoph Hellwig <hch at infradead dot org> 1298*4882a593Smuzhiyun - Doug Ledford <dledford at redhat dot com> 1299*4882a593Smuzhiyun - Andries Brouwer <Andries dot Brouwer at cwi dot nl> 1300*4882a593Smuzhiyun - Randy Dunlap <rdunlap at xenotime dot net> 1301*4882a593Smuzhiyun - Alan Stern <stern at rowland dot harvard dot edu> 1302*4882a593Smuzhiyun 1303*4882a593Smuzhiyun 1304*4882a593SmuzhiyunDouglas Gilbert 1305*4882a593Smuzhiyundgilbert at interlog dot com 1306*4882a593Smuzhiyun 1307*4882a593Smuzhiyun21st September 2004 1308