scsi_mid_low_api.rst 49 KB

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