scsi_error.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  1. /*
  2. * scsi_error.c Copyright (C) 1997 Eric Youngdale
  3. *
  4. * SCSI error/timeout handling
  5. * Initial versions: Eric Youngdale. Based upon conversations with
  6. * Leonard Zubkoff and David Miller at Linux Expo,
  7. * ideas originating from all over the place.
  8. *
  9. * Restructured scsi_unjam_host and associated functions.
  10. * September 04, 2002 Mike Anderson (andmike@us.ibm.com)
  11. *
  12. * Forward port of Russell King's (rmk@arm.linux.org.uk) changes and
  13. * minor cleanups.
  14. * September 30, 2002 Mike Anderson (andmike@us.ibm.com)
  15. */
  16. #include <linux/module.h>
  17. #include <linux/sched.h>
  18. #include <linux/timer.h>
  19. #include <linux/string.h>
  20. #include <linux/slab.h>
  21. #include <linux/kernel.h>
  22. #include <linux/kthread.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/blkdev.h>
  25. #include <linux/delay.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_dbg.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_eh.h>
  30. #include <scsi/scsi_transport.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_ioctl.h>
  33. #include <scsi/scsi_request.h>
  34. #include "scsi_priv.h"
  35. #include "scsi_logging.h"
  36. #define SENSE_TIMEOUT (10*HZ)
  37. #define START_UNIT_TIMEOUT (30*HZ)
  38. /*
  39. * These should *probably* be handled by the host itself.
  40. * Since it is allowed to sleep, it probably should.
  41. */
  42. #define BUS_RESET_SETTLE_TIME (10)
  43. #define HOST_RESET_SETTLE_TIME (10)
  44. /* called with shost->host_lock held */
  45. void scsi_eh_wakeup(struct Scsi_Host *shost)
  46. {
  47. if (shost->host_busy == shost->host_failed) {
  48. wake_up_process(shost->ehandler);
  49. SCSI_LOG_ERROR_RECOVERY(5,
  50. printk("Waking error handler thread\n"));
  51. }
  52. }
  53. /**
  54. * scsi_eh_scmd_add - add scsi cmd to error handling.
  55. * @scmd: scmd to run eh on.
  56. * @eh_flag: optional SCSI_EH flag.
  57. *
  58. * Return value:
  59. * 0 on failure.
  60. **/
  61. int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
  62. {
  63. struct Scsi_Host *shost = scmd->device->host;
  64. unsigned long flags;
  65. int ret = 0;
  66. if (!shost->ehandler)
  67. return 0;
  68. spin_lock_irqsave(shost->host_lock, flags);
  69. if (scsi_host_set_state(shost, SHOST_RECOVERY))
  70. if (scsi_host_set_state(shost, SHOST_CANCEL_RECOVERY))
  71. goto out_unlock;
  72. ret = 1;
  73. scmd->eh_eflags |= eh_flag;
  74. list_add_tail(&scmd->eh_entry, &shost->eh_cmd_q);
  75. shost->host_failed++;
  76. scsi_eh_wakeup(shost);
  77. out_unlock:
  78. spin_unlock_irqrestore(shost->host_lock, flags);
  79. return ret;
  80. }
  81. /**
  82. * scsi_add_timer - Start timeout timer for a single scsi command.
  83. * @scmd: scsi command that is about to start running.
  84. * @timeout: amount of time to allow this command to run.
  85. * @complete: timeout function to call if timer isn't canceled.
  86. *
  87. * Notes:
  88. * This should be turned into an inline function. Each scsi command
  89. * has its own timer, and as it is added to the queue, we set up the
  90. * timer. When the command completes, we cancel the timer.
  91. **/
  92. void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
  93. void (*complete)(struct scsi_cmnd *))
  94. {
  95. /*
  96. * If the clock was already running for this command, then
  97. * first delete the timer. The timer handling code gets rather
  98. * confused if we don't do this.
  99. */
  100. if (scmd->eh_timeout.function)
  101. del_timer(&scmd->eh_timeout);
  102. scmd->eh_timeout.data = (unsigned long)scmd;
  103. scmd->eh_timeout.expires = jiffies + timeout;
  104. scmd->eh_timeout.function = (void (*)(unsigned long)) complete;
  105. SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p, time:"
  106. " %d, (%p)\n", __FUNCTION__,
  107. scmd, timeout, complete));
  108. add_timer(&scmd->eh_timeout);
  109. }
  110. /**
  111. * scsi_delete_timer - Delete/cancel timer for a given function.
  112. * @scmd: Cmd that we are canceling timer for
  113. *
  114. * Notes:
  115. * This should be turned into an inline function.
  116. *
  117. * Return value:
  118. * 1 if we were able to detach the timer. 0 if we blew it, and the
  119. * timer function has already started to run.
  120. **/
  121. int scsi_delete_timer(struct scsi_cmnd *scmd)
  122. {
  123. int rtn;
  124. rtn = del_timer(&scmd->eh_timeout);
  125. SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p,"
  126. " rtn: %d\n", __FUNCTION__,
  127. scmd, rtn));
  128. scmd->eh_timeout.data = (unsigned long)NULL;
  129. scmd->eh_timeout.function = NULL;
  130. return rtn;
  131. }
  132. /**
  133. * scsi_times_out - Timeout function for normal scsi commands.
  134. * @scmd: Cmd that is timing out.
  135. *
  136. * Notes:
  137. * We do not need to lock this. There is the potential for a race
  138. * only in that the normal completion handling might run, but if the
  139. * normal completion function determines that the timer has already
  140. * fired, then it mustn't do anything.
  141. **/
  142. void scsi_times_out(struct scsi_cmnd *scmd)
  143. {
  144. scsi_log_completion(scmd, TIMEOUT_ERROR);
  145. if (scmd->device->host->transportt->eh_timed_out)
  146. switch (scmd->device->host->transportt->eh_timed_out(scmd)) {
  147. case EH_HANDLED:
  148. __scsi_done(scmd);
  149. return;
  150. case EH_RESET_TIMER:
  151. scsi_add_timer(scmd, scmd->timeout_per_command,
  152. scsi_times_out);
  153. return;
  154. case EH_NOT_HANDLED:
  155. break;
  156. }
  157. if (unlikely(!scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) {
  158. scmd->result |= DID_TIME_OUT << 16;
  159. __scsi_done(scmd);
  160. }
  161. }
  162. /**
  163. * scsi_block_when_processing_errors - Prevent cmds from being queued.
  164. * @sdev: Device on which we are performing recovery.
  165. *
  166. * Description:
  167. * We block until the host is out of error recovery, and then check to
  168. * see whether the host or the device is offline.
  169. *
  170. * Return value:
  171. * 0 when dev was taken offline by error recovery. 1 OK to proceed.
  172. **/
  173. int scsi_block_when_processing_errors(struct scsi_device *sdev)
  174. {
  175. int online;
  176. wait_event(sdev->host->host_wait, !scsi_host_in_recovery(sdev->host));
  177. online = scsi_device_online(sdev);
  178. SCSI_LOG_ERROR_RECOVERY(5, printk("%s: rtn: %d\n", __FUNCTION__,
  179. online));
  180. return online;
  181. }
  182. EXPORT_SYMBOL(scsi_block_when_processing_errors);
  183. #ifdef CONFIG_SCSI_LOGGING
  184. /**
  185. * scsi_eh_prt_fail_stats - Log info on failures.
  186. * @shost: scsi host being recovered.
  187. * @work_q: Queue of scsi cmds to process.
  188. **/
  189. static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
  190. struct list_head *work_q)
  191. {
  192. struct scsi_cmnd *scmd;
  193. struct scsi_device *sdev;
  194. int total_failures = 0;
  195. int cmd_failed = 0;
  196. int cmd_cancel = 0;
  197. int devices_failed = 0;
  198. shost_for_each_device(sdev, shost) {
  199. list_for_each_entry(scmd, work_q, eh_entry) {
  200. if (scmd->device == sdev) {
  201. ++total_failures;
  202. if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD)
  203. ++cmd_cancel;
  204. else
  205. ++cmd_failed;
  206. }
  207. }
  208. if (cmd_cancel || cmd_failed) {
  209. SCSI_LOG_ERROR_RECOVERY(3,
  210. sdev_printk(KERN_INFO, sdev,
  211. "%s: cmds failed: %d, cancel: %d\n",
  212. __FUNCTION__, cmd_failed,
  213. cmd_cancel));
  214. cmd_cancel = 0;
  215. cmd_failed = 0;
  216. ++devices_failed;
  217. }
  218. }
  219. SCSI_LOG_ERROR_RECOVERY(2, printk("Total of %d commands on %d"
  220. " devices require eh work\n",
  221. total_failures, devices_failed));
  222. }
  223. #endif
  224. /**
  225. * scsi_check_sense - Examine scsi cmd sense
  226. * @scmd: Cmd to have sense checked.
  227. *
  228. * Return value:
  229. * SUCCESS or FAILED or NEEDS_RETRY
  230. *
  231. * Notes:
  232. * When a deferred error is detected the current command has
  233. * not been executed and needs retrying.
  234. **/
  235. static int scsi_check_sense(struct scsi_cmnd *scmd)
  236. {
  237. struct scsi_sense_hdr sshdr;
  238. if (! scsi_command_normalize_sense(scmd, &sshdr))
  239. return FAILED; /* no valid sense data */
  240. if (scsi_sense_is_deferred(&sshdr))
  241. return NEEDS_RETRY;
  242. /*
  243. * Previous logic looked for FILEMARK, EOM or ILI which are
  244. * mainly associated with tapes and returned SUCCESS.
  245. */
  246. if (sshdr.response_code == 0x70) {
  247. /* fixed format */
  248. if (scmd->sense_buffer[2] & 0xe0)
  249. return SUCCESS;
  250. } else {
  251. /*
  252. * descriptor format: look for "stream commands sense data
  253. * descriptor" (see SSC-3). Assume single sense data
  254. * descriptor. Ignore ILI from SBC-2 READ LONG and WRITE LONG.
  255. */
  256. if ((sshdr.additional_length > 3) &&
  257. (scmd->sense_buffer[8] == 0x4) &&
  258. (scmd->sense_buffer[11] & 0xe0))
  259. return SUCCESS;
  260. }
  261. switch (sshdr.sense_key) {
  262. case NO_SENSE:
  263. return SUCCESS;
  264. case RECOVERED_ERROR:
  265. return /* soft_error */ SUCCESS;
  266. case ABORTED_COMMAND:
  267. return NEEDS_RETRY;
  268. case NOT_READY:
  269. case UNIT_ATTENTION:
  270. /*
  271. * if we are expecting a cc/ua because of a bus reset that we
  272. * performed, treat this just as a retry. otherwise this is
  273. * information that we should pass up to the upper-level driver
  274. * so that we can deal with it there.
  275. */
  276. if (scmd->device->expecting_cc_ua) {
  277. scmd->device->expecting_cc_ua = 0;
  278. return NEEDS_RETRY;
  279. }
  280. /*
  281. * if the device is in the process of becoming ready, we
  282. * should retry.
  283. */
  284. if ((sshdr.asc == 0x04) && (sshdr.ascq == 0x01))
  285. return NEEDS_RETRY;
  286. /*
  287. * if the device is not started, we need to wake
  288. * the error handler to start the motor
  289. */
  290. if (scmd->device->allow_restart &&
  291. (sshdr.asc == 0x04) && (sshdr.ascq == 0x02))
  292. return FAILED;
  293. return SUCCESS;
  294. /* these three are not supported */
  295. case COPY_ABORTED:
  296. case VOLUME_OVERFLOW:
  297. case MISCOMPARE:
  298. return SUCCESS;
  299. case MEDIUM_ERROR:
  300. return NEEDS_RETRY;
  301. case HARDWARE_ERROR:
  302. if (scmd->device->retry_hwerror)
  303. return NEEDS_RETRY;
  304. else
  305. return SUCCESS;
  306. case ILLEGAL_REQUEST:
  307. case BLANK_CHECK:
  308. case DATA_PROTECT:
  309. default:
  310. return SUCCESS;
  311. }
  312. }
  313. /**
  314. * scsi_eh_completed_normally - Disposition a eh cmd on return from LLD.
  315. * @scmd: SCSI cmd to examine.
  316. *
  317. * Notes:
  318. * This is *only* called when we are examining the status of commands
  319. * queued during error recovery. the main difference here is that we
  320. * don't allow for the possibility of retries here, and we are a lot
  321. * more restrictive about what we consider acceptable.
  322. **/
  323. static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
  324. {
  325. /*
  326. * first check the host byte, to see if there is anything in there
  327. * that would indicate what we need to do.
  328. */
  329. if (host_byte(scmd->result) == DID_RESET) {
  330. /*
  331. * rats. we are already in the error handler, so we now
  332. * get to try and figure out what to do next. if the sense
  333. * is valid, we have a pretty good idea of what to do.
  334. * if not, we mark it as FAILED.
  335. */
  336. return scsi_check_sense(scmd);
  337. }
  338. if (host_byte(scmd->result) != DID_OK)
  339. return FAILED;
  340. /*
  341. * next, check the message byte.
  342. */
  343. if (msg_byte(scmd->result) != COMMAND_COMPLETE)
  344. return FAILED;
  345. /*
  346. * now, check the status byte to see if this indicates
  347. * anything special.
  348. */
  349. switch (status_byte(scmd->result)) {
  350. case GOOD:
  351. case COMMAND_TERMINATED:
  352. return SUCCESS;
  353. case CHECK_CONDITION:
  354. return scsi_check_sense(scmd);
  355. case CONDITION_GOOD:
  356. case INTERMEDIATE_GOOD:
  357. case INTERMEDIATE_C_GOOD:
  358. /*
  359. * who knows? FIXME(eric)
  360. */
  361. return SUCCESS;
  362. case BUSY:
  363. case QUEUE_FULL:
  364. case RESERVATION_CONFLICT:
  365. default:
  366. return FAILED;
  367. }
  368. return FAILED;
  369. }
  370. /**
  371. * scsi_eh_done - Completion function for error handling.
  372. * @scmd: Cmd that is done.
  373. **/
  374. static void scsi_eh_done(struct scsi_cmnd *scmd)
  375. {
  376. struct completion *eh_action;
  377. SCSI_LOG_ERROR_RECOVERY(3,
  378. printk("%s scmd: %p result: %x\n",
  379. __FUNCTION__, scmd, scmd->result));
  380. eh_action = scmd->device->host->eh_action;
  381. if (eh_action)
  382. complete(eh_action);
  383. }
  384. /**
  385. * scsi_send_eh_cmnd - send a cmd to a device as part of error recovery.
  386. * @scmd: SCSI Cmd to send.
  387. * @timeout: Timeout for cmd.
  388. *
  389. * Return value:
  390. * SUCCESS or FAILED or NEEDS_RETRY
  391. **/
  392. static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, int timeout)
  393. {
  394. struct scsi_device *sdev = scmd->device;
  395. struct Scsi_Host *shost = sdev->host;
  396. DECLARE_COMPLETION(done);
  397. unsigned long timeleft;
  398. unsigned long flags;
  399. int rtn;
  400. if (sdev->scsi_level <= SCSI_2)
  401. scmd->cmnd[1] = (scmd->cmnd[1] & 0x1f) |
  402. (sdev->lun << 5 & 0xe0);
  403. shost->eh_action = &done;
  404. scmd->request->rq_status = RQ_SCSI_BUSY;
  405. spin_lock_irqsave(shost->host_lock, flags);
  406. scsi_log_send(scmd);
  407. shost->hostt->queuecommand(scmd, scsi_eh_done);
  408. spin_unlock_irqrestore(shost->host_lock, flags);
  409. timeleft = wait_for_completion_timeout(&done, timeout);
  410. scmd->request->rq_status = RQ_SCSI_DONE;
  411. shost->eh_action = NULL;
  412. scsi_log_completion(scmd, SUCCESS);
  413. SCSI_LOG_ERROR_RECOVERY(3,
  414. printk("%s: scmd: %p, timeleft: %ld\n",
  415. __FUNCTION__, scmd, timeleft));
  416. /*
  417. * If there is time left scsi_eh_done got called, and we will
  418. * examine the actual status codes to see whether the command
  419. * actually did complete normally, else tell the host to forget
  420. * about this command.
  421. */
  422. if (timeleft) {
  423. rtn = scsi_eh_completed_normally(scmd);
  424. SCSI_LOG_ERROR_RECOVERY(3,
  425. printk("%s: scsi_eh_completed_normally %x\n",
  426. __FUNCTION__, rtn));
  427. switch (rtn) {
  428. case SUCCESS:
  429. case NEEDS_RETRY:
  430. case FAILED:
  431. break;
  432. default:
  433. rtn = FAILED;
  434. break;
  435. }
  436. } else {
  437. /*
  438. * FIXME(eric) - we are not tracking whether we could
  439. * abort a timed out command or not. not sure how
  440. * we should treat them differently anyways.
  441. */
  442. if (shost->hostt->eh_abort_handler)
  443. shost->hostt->eh_abort_handler(scmd);
  444. rtn = FAILED;
  445. }
  446. return rtn;
  447. }
  448. /**
  449. * scsi_request_sense - Request sense data from a particular target.
  450. * @scmd: SCSI cmd for request sense.
  451. *
  452. * Notes:
  453. * Some hosts automatically obtain this information, others require
  454. * that we obtain it on our own. This function will *not* return until
  455. * the command either times out, or it completes.
  456. **/
  457. static int scsi_request_sense(struct scsi_cmnd *scmd)
  458. {
  459. static unsigned char generic_sense[6] =
  460. {REQUEST_SENSE, 0, 0, 0, 252, 0};
  461. unsigned char *scsi_result;
  462. int saved_result;
  463. int rtn;
  464. memcpy(scmd->cmnd, generic_sense, sizeof(generic_sense));
  465. scsi_result = kmalloc(252, GFP_ATOMIC | ((scmd->device->host->hostt->unchecked_isa_dma) ? __GFP_DMA : 0));
  466. if (unlikely(!scsi_result)) {
  467. printk(KERN_ERR "%s: cannot allocate scsi_result.\n",
  468. __FUNCTION__);
  469. return FAILED;
  470. }
  471. /*
  472. * zero the sense buffer. some host adapters automatically always
  473. * request sense, so it is not a good idea that
  474. * scmd->request_buffer and scmd->sense_buffer point to the same
  475. * address (db). 0 is not a valid sense code.
  476. */
  477. memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
  478. memset(scsi_result, 0, 252);
  479. saved_result = scmd->result;
  480. scmd->request_buffer = scsi_result;
  481. scmd->request_bufflen = 252;
  482. scmd->use_sg = 0;
  483. scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
  484. scmd->sc_data_direction = DMA_FROM_DEVICE;
  485. scmd->underflow = 0;
  486. rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
  487. /* last chance to have valid sense data */
  488. if(!SCSI_SENSE_VALID(scmd)) {
  489. memcpy(scmd->sense_buffer, scmd->request_buffer,
  490. sizeof(scmd->sense_buffer));
  491. }
  492. kfree(scsi_result);
  493. /*
  494. * when we eventually call scsi_finish, we really wish to complete
  495. * the original request, so let's restore the original data. (db)
  496. */
  497. scsi_setup_cmd_retry(scmd);
  498. scmd->result = saved_result;
  499. return rtn;
  500. }
  501. /**
  502. * scsi_eh_finish_cmd - Handle a cmd that eh is finished with.
  503. * @scmd: Original SCSI cmd that eh has finished.
  504. * @done_q: Queue for processed commands.
  505. *
  506. * Notes:
  507. * We don't want to use the normal command completion while we are are
  508. * still handling errors - it may cause other commands to be queued,
  509. * and that would disturb what we are doing. thus we really want to
  510. * keep a list of pending commands for final completion, and once we
  511. * are ready to leave error handling we handle completion for real.
  512. **/
  513. void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, struct list_head *done_q)
  514. {
  515. scmd->device->host->host_failed--;
  516. scmd->eh_eflags = 0;
  517. /*
  518. * set this back so that the upper level can correctly free up
  519. * things.
  520. */
  521. scsi_setup_cmd_retry(scmd);
  522. list_move_tail(&scmd->eh_entry, done_q);
  523. }
  524. EXPORT_SYMBOL(scsi_eh_finish_cmd);
  525. /**
  526. * scsi_eh_get_sense - Get device sense data.
  527. * @work_q: Queue of commands to process.
  528. * @done_q: Queue of proccessed commands..
  529. *
  530. * Description:
  531. * See if we need to request sense information. if so, then get it
  532. * now, so we have a better idea of what to do.
  533. *
  534. * Notes:
  535. * This has the unfortunate side effect that if a shost adapter does
  536. * not automatically request sense information, that we end up shutting
  537. * it down before we request it.
  538. *
  539. * All drivers should request sense information internally these days,
  540. * so for now all I have to say is tough noogies if you end up in here.
  541. *
  542. * XXX: Long term this code should go away, but that needs an audit of
  543. * all LLDDs first.
  544. **/
  545. static int scsi_eh_get_sense(struct list_head *work_q,
  546. struct list_head *done_q)
  547. {
  548. struct scsi_cmnd *scmd, *next;
  549. int rtn;
  550. list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
  551. if ((scmd->eh_eflags & SCSI_EH_CANCEL_CMD) ||
  552. SCSI_SENSE_VALID(scmd))
  553. continue;
  554. SCSI_LOG_ERROR_RECOVERY(2, scmd_printk(KERN_INFO, scmd,
  555. "%s: requesting sense\n",
  556. current->comm));
  557. rtn = scsi_request_sense(scmd);
  558. if (rtn != SUCCESS)
  559. continue;
  560. SCSI_LOG_ERROR_RECOVERY(3, printk("sense requested for %p"
  561. " result %x\n", scmd,
  562. scmd->result));
  563. SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense("bh", scmd));
  564. rtn = scsi_decide_disposition(scmd);
  565. /*
  566. * if the result was normal, then just pass it along to the
  567. * upper level.
  568. */
  569. if (rtn == SUCCESS)
  570. /* we don't want this command reissued, just
  571. * finished with the sense data, so set
  572. * retries to the max allowed to ensure it
  573. * won't get reissued */
  574. scmd->retries = scmd->allowed;
  575. else if (rtn != NEEDS_RETRY)
  576. continue;
  577. scsi_eh_finish_cmd(scmd, done_q);
  578. }
  579. return list_empty(work_q);
  580. }
  581. /**
  582. * scsi_try_to_abort_cmd - Ask host to abort a running command.
  583. * @scmd: SCSI cmd to abort from Lower Level.
  584. *
  585. * Notes:
  586. * This function will not return until the user's completion function
  587. * has been called. there is no timeout on this operation. if the
  588. * author of the low-level driver wishes this operation to be timed,
  589. * they can provide this facility themselves. helper functions in
  590. * scsi_error.c can be supplied to make this easier to do.
  591. **/
  592. static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
  593. {
  594. if (!scmd->device->host->hostt->eh_abort_handler)
  595. return FAILED;
  596. /*
  597. * scsi_done was called just after the command timed out and before
  598. * we had a chance to process it. (db)
  599. */
  600. if (scmd->serial_number == 0)
  601. return SUCCESS;
  602. return scmd->device->host->hostt->eh_abort_handler(scmd);
  603. }
  604. /**
  605. * scsi_eh_tur - Send TUR to device.
  606. * @scmd: Scsi cmd to send TUR
  607. *
  608. * Return value:
  609. * 0 - Device is ready. 1 - Device NOT ready.
  610. **/
  611. static int scsi_eh_tur(struct scsi_cmnd *scmd)
  612. {
  613. static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0};
  614. int retry_cnt = 1, rtn;
  615. int saved_result;
  616. retry_tur:
  617. memcpy(scmd->cmnd, tur_command, sizeof(tur_command));
  618. /*
  619. * zero the sense buffer. the scsi spec mandates that any
  620. * untransferred sense data should be interpreted as being zero.
  621. */
  622. memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
  623. saved_result = scmd->result;
  624. scmd->request_buffer = NULL;
  625. scmd->request_bufflen = 0;
  626. scmd->use_sg = 0;
  627. scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
  628. scmd->underflow = 0;
  629. scmd->sc_data_direction = DMA_NONE;
  630. rtn = scsi_send_eh_cmnd(scmd, SENSE_TIMEOUT);
  631. /*
  632. * when we eventually call scsi_finish, we really wish to complete
  633. * the original request, so let's restore the original data. (db)
  634. */
  635. scsi_setup_cmd_retry(scmd);
  636. scmd->result = saved_result;
  637. /*
  638. * hey, we are done. let's look to see what happened.
  639. */
  640. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
  641. __FUNCTION__, scmd, rtn));
  642. if (rtn == SUCCESS)
  643. return 0;
  644. else if (rtn == NEEDS_RETRY) {
  645. if (retry_cnt--)
  646. goto retry_tur;
  647. return 0;
  648. }
  649. return 1;
  650. }
  651. /**
  652. * scsi_eh_abort_cmds - abort canceled commands.
  653. * @shost: scsi host being recovered.
  654. * @eh_done_q: list_head for processed commands.
  655. *
  656. * Decription:
  657. * Try and see whether or not it makes sense to try and abort the
  658. * running command. this only works out to be the case if we have one
  659. * command that has timed out. if the command simply failed, it makes
  660. * no sense to try and abort the command, since as far as the shost
  661. * adapter is concerned, it isn't running.
  662. **/
  663. static int scsi_eh_abort_cmds(struct list_head *work_q,
  664. struct list_head *done_q)
  665. {
  666. struct scsi_cmnd *scmd, *next;
  667. int rtn;
  668. list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
  669. if (!(scmd->eh_eflags & SCSI_EH_CANCEL_CMD))
  670. continue;
  671. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting cmd:"
  672. "0x%p\n", current->comm,
  673. scmd));
  674. rtn = scsi_try_to_abort_cmd(scmd);
  675. if (rtn == SUCCESS) {
  676. scmd->eh_eflags &= ~SCSI_EH_CANCEL_CMD;
  677. if (!scsi_device_online(scmd->device) ||
  678. !scsi_eh_tur(scmd)) {
  679. scsi_eh_finish_cmd(scmd, done_q);
  680. }
  681. } else
  682. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: aborting"
  683. " cmd failed:"
  684. "0x%p\n",
  685. current->comm,
  686. scmd));
  687. }
  688. return list_empty(work_q);
  689. }
  690. /**
  691. * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
  692. * @scmd: SCSI cmd used to send BDR
  693. *
  694. * Notes:
  695. * There is no timeout for this operation. if this operation is
  696. * unreliable for a given host, then the host itself needs to put a
  697. * timer on it, and set the host back to a consistent state prior to
  698. * returning.
  699. **/
  700. static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
  701. {
  702. int rtn;
  703. if (!scmd->device->host->hostt->eh_device_reset_handler)
  704. return FAILED;
  705. rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
  706. if (rtn == SUCCESS) {
  707. scmd->device->was_reset = 1;
  708. scmd->device->expecting_cc_ua = 1;
  709. }
  710. return rtn;
  711. }
  712. /**
  713. * scsi_eh_try_stu - Send START_UNIT to device.
  714. * @scmd: Scsi cmd to send START_UNIT
  715. *
  716. * Return value:
  717. * 0 - Device is ready. 1 - Device NOT ready.
  718. **/
  719. static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
  720. {
  721. static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0};
  722. int rtn;
  723. int saved_result;
  724. if (!scmd->device->allow_restart)
  725. return 1;
  726. memcpy(scmd->cmnd, stu_command, sizeof(stu_command));
  727. /*
  728. * zero the sense buffer. the scsi spec mandates that any
  729. * untransferred sense data should be interpreted as being zero.
  730. */
  731. memset(scmd->sense_buffer, 0, sizeof(scmd->sense_buffer));
  732. saved_result = scmd->result;
  733. scmd->request_buffer = NULL;
  734. scmd->request_bufflen = 0;
  735. scmd->use_sg = 0;
  736. scmd->cmd_len = COMMAND_SIZE(scmd->cmnd[0]);
  737. scmd->underflow = 0;
  738. scmd->sc_data_direction = DMA_NONE;
  739. rtn = scsi_send_eh_cmnd(scmd, START_UNIT_TIMEOUT);
  740. /*
  741. * when we eventually call scsi_finish, we really wish to complete
  742. * the original request, so let's restore the original data. (db)
  743. */
  744. scsi_setup_cmd_retry(scmd);
  745. scmd->result = saved_result;
  746. /*
  747. * hey, we are done. let's look to see what happened.
  748. */
  749. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: scmd %p rtn %x\n",
  750. __FUNCTION__, scmd, rtn));
  751. if (rtn == SUCCESS)
  752. return 0;
  753. return 1;
  754. }
  755. /**
  756. * scsi_eh_stu - send START_UNIT if needed
  757. * @shost: scsi host being recovered.
  758. * @eh_done_q: list_head for processed commands.
  759. *
  760. * Notes:
  761. * If commands are failing due to not ready, initializing command required,
  762. * try revalidating the device, which will end up sending a start unit.
  763. **/
  764. static int scsi_eh_stu(struct Scsi_Host *shost,
  765. struct list_head *work_q,
  766. struct list_head *done_q)
  767. {
  768. struct scsi_cmnd *scmd, *stu_scmd, *next;
  769. struct scsi_device *sdev;
  770. shost_for_each_device(sdev, shost) {
  771. stu_scmd = NULL;
  772. list_for_each_entry(scmd, work_q, eh_entry)
  773. if (scmd->device == sdev && SCSI_SENSE_VALID(scmd) &&
  774. scsi_check_sense(scmd) == FAILED ) {
  775. stu_scmd = scmd;
  776. break;
  777. }
  778. if (!stu_scmd)
  779. continue;
  780. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending START_UNIT to sdev:"
  781. " 0x%p\n", current->comm, sdev));
  782. if (!scsi_eh_try_stu(stu_scmd)) {
  783. if (!scsi_device_online(sdev) ||
  784. !scsi_eh_tur(stu_scmd)) {
  785. list_for_each_entry_safe(scmd, next,
  786. work_q, eh_entry) {
  787. if (scmd->device == sdev)
  788. scsi_eh_finish_cmd(scmd, done_q);
  789. }
  790. }
  791. } else {
  792. SCSI_LOG_ERROR_RECOVERY(3,
  793. printk("%s: START_UNIT failed to sdev:"
  794. " 0x%p\n", current->comm, sdev));
  795. }
  796. }
  797. return list_empty(work_q);
  798. }
  799. /**
  800. * scsi_eh_bus_device_reset - send bdr if needed
  801. * @shost: scsi host being recovered.
  802. * @eh_done_q: list_head for processed commands.
  803. *
  804. * Notes:
  805. * Try a bus device reset. still, look to see whether we have multiple
  806. * devices that are jammed or not - if we have multiple devices, it
  807. * makes no sense to try bus_device_reset - we really would need to try
  808. * a bus_reset instead.
  809. **/
  810. static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
  811. struct list_head *work_q,
  812. struct list_head *done_q)
  813. {
  814. struct scsi_cmnd *scmd, *bdr_scmd, *next;
  815. struct scsi_device *sdev;
  816. int rtn;
  817. shost_for_each_device(sdev, shost) {
  818. bdr_scmd = NULL;
  819. list_for_each_entry(scmd, work_q, eh_entry)
  820. if (scmd->device == sdev) {
  821. bdr_scmd = scmd;
  822. break;
  823. }
  824. if (!bdr_scmd)
  825. continue;
  826. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BDR sdev:"
  827. " 0x%p\n", current->comm,
  828. sdev));
  829. rtn = scsi_try_bus_device_reset(bdr_scmd);
  830. if (rtn == SUCCESS) {
  831. if (!scsi_device_online(sdev) ||
  832. !scsi_eh_tur(bdr_scmd)) {
  833. list_for_each_entry_safe(scmd, next,
  834. work_q, eh_entry) {
  835. if (scmd->device == sdev)
  836. scsi_eh_finish_cmd(scmd,
  837. done_q);
  838. }
  839. }
  840. } else {
  841. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BDR"
  842. " failed sdev:"
  843. "0x%p\n",
  844. current->comm,
  845. sdev));
  846. }
  847. }
  848. return list_empty(work_q);
  849. }
  850. /**
  851. * scsi_try_bus_reset - ask host to perform a bus reset
  852. * @scmd: SCSI cmd to send bus reset.
  853. **/
  854. static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
  855. {
  856. unsigned long flags;
  857. int rtn;
  858. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
  859. __FUNCTION__));
  860. if (!scmd->device->host->hostt->eh_bus_reset_handler)
  861. return FAILED;
  862. rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
  863. if (rtn == SUCCESS) {
  864. if (!scmd->device->host->hostt->skip_settle_delay)
  865. ssleep(BUS_RESET_SETTLE_TIME);
  866. spin_lock_irqsave(scmd->device->host->host_lock, flags);
  867. scsi_report_bus_reset(scmd->device->host,
  868. scmd_channel(scmd));
  869. spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
  870. }
  871. return rtn;
  872. }
  873. /**
  874. * scsi_try_host_reset - ask host adapter to reset itself
  875. * @scmd: SCSI cmd to send hsot reset.
  876. **/
  877. static int scsi_try_host_reset(struct scsi_cmnd *scmd)
  878. {
  879. unsigned long flags;
  880. int rtn;
  881. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
  882. __FUNCTION__));
  883. if (!scmd->device->host->hostt->eh_host_reset_handler)
  884. return FAILED;
  885. rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
  886. if (rtn == SUCCESS) {
  887. if (!scmd->device->host->hostt->skip_settle_delay)
  888. ssleep(HOST_RESET_SETTLE_TIME);
  889. spin_lock_irqsave(scmd->device->host->host_lock, flags);
  890. scsi_report_bus_reset(scmd->device->host,
  891. scmd_channel(scmd));
  892. spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
  893. }
  894. return rtn;
  895. }
  896. /**
  897. * scsi_eh_bus_reset - send a bus reset
  898. * @shost: scsi host being recovered.
  899. * @eh_done_q: list_head for processed commands.
  900. **/
  901. static int scsi_eh_bus_reset(struct Scsi_Host *shost,
  902. struct list_head *work_q,
  903. struct list_head *done_q)
  904. {
  905. struct scsi_cmnd *scmd, *chan_scmd, *next;
  906. unsigned int channel;
  907. int rtn;
  908. /*
  909. * we really want to loop over the various channels, and do this on
  910. * a channel by channel basis. we should also check to see if any
  911. * of the failed commands are on soft_reset devices, and if so, skip
  912. * the reset.
  913. */
  914. for (channel = 0; channel <= shost->max_channel; channel++) {
  915. chan_scmd = NULL;
  916. list_for_each_entry(scmd, work_q, eh_entry) {
  917. if (channel == scmd_channel(scmd)) {
  918. chan_scmd = scmd;
  919. break;
  920. /*
  921. * FIXME add back in some support for
  922. * soft_reset devices.
  923. */
  924. }
  925. }
  926. if (!chan_scmd)
  927. continue;
  928. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending BRST chan:"
  929. " %d\n", current->comm,
  930. channel));
  931. rtn = scsi_try_bus_reset(chan_scmd);
  932. if (rtn == SUCCESS) {
  933. list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
  934. if (channel == scmd_channel(scmd))
  935. if (!scsi_device_online(scmd->device) ||
  936. !scsi_eh_tur(scmd))
  937. scsi_eh_finish_cmd(scmd,
  938. done_q);
  939. }
  940. } else {
  941. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: BRST"
  942. " failed chan: %d\n",
  943. current->comm,
  944. channel));
  945. }
  946. }
  947. return list_empty(work_q);
  948. }
  949. /**
  950. * scsi_eh_host_reset - send a host reset
  951. * @work_q: list_head for processed commands.
  952. * @done_q: list_head for processed commands.
  953. **/
  954. static int scsi_eh_host_reset(struct list_head *work_q,
  955. struct list_head *done_q)
  956. {
  957. struct scsi_cmnd *scmd, *next;
  958. int rtn;
  959. if (!list_empty(work_q)) {
  960. scmd = list_entry(work_q->next,
  961. struct scsi_cmnd, eh_entry);
  962. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Sending HRST\n"
  963. , current->comm));
  964. rtn = scsi_try_host_reset(scmd);
  965. if (rtn == SUCCESS) {
  966. list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
  967. if (!scsi_device_online(scmd->device) ||
  968. (!scsi_eh_try_stu(scmd) && !scsi_eh_tur(scmd)) ||
  969. !scsi_eh_tur(scmd))
  970. scsi_eh_finish_cmd(scmd, done_q);
  971. }
  972. } else {
  973. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: HRST"
  974. " failed\n",
  975. current->comm));
  976. }
  977. }
  978. return list_empty(work_q);
  979. }
  980. /**
  981. * scsi_eh_offline_sdevs - offline scsi devices that fail to recover
  982. * @work_q: list_head for processed commands.
  983. * @done_q: list_head for processed commands.
  984. *
  985. **/
  986. static void scsi_eh_offline_sdevs(struct list_head *work_q,
  987. struct list_head *done_q)
  988. {
  989. struct scsi_cmnd *scmd, *next;
  990. list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
  991. sdev_printk(KERN_INFO, scmd->device,
  992. "scsi: Device offlined - not"
  993. " ready after error recovery\n");
  994. scsi_device_set_state(scmd->device, SDEV_OFFLINE);
  995. if (scmd->eh_eflags & SCSI_EH_CANCEL_CMD) {
  996. /*
  997. * FIXME: Handle lost cmds.
  998. */
  999. }
  1000. scsi_eh_finish_cmd(scmd, done_q);
  1001. }
  1002. return;
  1003. }
  1004. /**
  1005. * scsi_decide_disposition - Disposition a cmd on return from LLD.
  1006. * @scmd: SCSI cmd to examine.
  1007. *
  1008. * Notes:
  1009. * This is *only* called when we are examining the status after sending
  1010. * out the actual data command. any commands that are queued for error
  1011. * recovery (e.g. test_unit_ready) do *not* come through here.
  1012. *
  1013. * When this routine returns failed, it means the error handler thread
  1014. * is woken. In cases where the error code indicates an error that
  1015. * doesn't require the error handler read (i.e. we don't need to
  1016. * abort/reset), this function should return SUCCESS.
  1017. **/
  1018. int scsi_decide_disposition(struct scsi_cmnd *scmd)
  1019. {
  1020. int rtn;
  1021. /*
  1022. * if the device is offline, then we clearly just pass the result back
  1023. * up to the top level.
  1024. */
  1025. if (!scsi_device_online(scmd->device)) {
  1026. SCSI_LOG_ERROR_RECOVERY(5, printk("%s: device offline - report"
  1027. " as SUCCESS\n",
  1028. __FUNCTION__));
  1029. return SUCCESS;
  1030. }
  1031. /*
  1032. * first check the host byte, to see if there is anything in there
  1033. * that would indicate what we need to do.
  1034. */
  1035. switch (host_byte(scmd->result)) {
  1036. case DID_PASSTHROUGH:
  1037. /*
  1038. * no matter what, pass this through to the upper layer.
  1039. * nuke this special code so that it looks like we are saying
  1040. * did_ok.
  1041. */
  1042. scmd->result &= 0xff00ffff;
  1043. return SUCCESS;
  1044. case DID_OK:
  1045. /*
  1046. * looks good. drop through, and check the next byte.
  1047. */
  1048. break;
  1049. case DID_NO_CONNECT:
  1050. case DID_BAD_TARGET:
  1051. case DID_ABORT:
  1052. /*
  1053. * note - this means that we just report the status back
  1054. * to the top level driver, not that we actually think
  1055. * that it indicates SUCCESS.
  1056. */
  1057. return SUCCESS;
  1058. /*
  1059. * when the low level driver returns did_soft_error,
  1060. * it is responsible for keeping an internal retry counter
  1061. * in order to avoid endless loops (db)
  1062. *
  1063. * actually this is a bug in this function here. we should
  1064. * be mindful of the maximum number of retries specified
  1065. * and not get stuck in a loop.
  1066. */
  1067. case DID_SOFT_ERROR:
  1068. goto maybe_retry;
  1069. case DID_IMM_RETRY:
  1070. return NEEDS_RETRY;
  1071. case DID_REQUEUE:
  1072. return ADD_TO_MLQUEUE;
  1073. case DID_ERROR:
  1074. if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
  1075. status_byte(scmd->result) == RESERVATION_CONFLICT)
  1076. /*
  1077. * execute reservation conflict processing code
  1078. * lower down
  1079. */
  1080. break;
  1081. /* fallthrough */
  1082. case DID_BUS_BUSY:
  1083. case DID_PARITY:
  1084. goto maybe_retry;
  1085. case DID_TIME_OUT:
  1086. /*
  1087. * when we scan the bus, we get timeout messages for
  1088. * these commands if there is no device available.
  1089. * other hosts report did_no_connect for the same thing.
  1090. */
  1091. if ((scmd->cmnd[0] == TEST_UNIT_READY ||
  1092. scmd->cmnd[0] == INQUIRY)) {
  1093. return SUCCESS;
  1094. } else {
  1095. return FAILED;
  1096. }
  1097. case DID_RESET:
  1098. return SUCCESS;
  1099. default:
  1100. return FAILED;
  1101. }
  1102. /*
  1103. * next, check the message byte.
  1104. */
  1105. if (msg_byte(scmd->result) != COMMAND_COMPLETE)
  1106. return FAILED;
  1107. /*
  1108. * check the status byte to see if this indicates anything special.
  1109. */
  1110. switch (status_byte(scmd->result)) {
  1111. case QUEUE_FULL:
  1112. /*
  1113. * the case of trying to send too many commands to a
  1114. * tagged queueing device.
  1115. */
  1116. case BUSY:
  1117. /*
  1118. * device can't talk to us at the moment. Should only
  1119. * occur (SAM-3) when the task queue is empty, so will cause
  1120. * the empty queue handling to trigger a stall in the
  1121. * device.
  1122. */
  1123. return ADD_TO_MLQUEUE;
  1124. case GOOD:
  1125. case COMMAND_TERMINATED:
  1126. case TASK_ABORTED:
  1127. return SUCCESS;
  1128. case CHECK_CONDITION:
  1129. rtn = scsi_check_sense(scmd);
  1130. if (rtn == NEEDS_RETRY)
  1131. goto maybe_retry;
  1132. /* if rtn == FAILED, we have no sense information;
  1133. * returning FAILED will wake the error handler thread
  1134. * to collect the sense and redo the decide
  1135. * disposition */
  1136. return rtn;
  1137. case CONDITION_GOOD:
  1138. case INTERMEDIATE_GOOD:
  1139. case INTERMEDIATE_C_GOOD:
  1140. case ACA_ACTIVE:
  1141. /*
  1142. * who knows? FIXME(eric)
  1143. */
  1144. return SUCCESS;
  1145. case RESERVATION_CONFLICT:
  1146. sdev_printk(KERN_INFO, scmd->device,
  1147. "reservation conflict\n");
  1148. return SUCCESS; /* causes immediate i/o error */
  1149. default:
  1150. return FAILED;
  1151. }
  1152. return FAILED;
  1153. maybe_retry:
  1154. /* we requeue for retry because the error was retryable, and
  1155. * the request was not marked fast fail. Note that above,
  1156. * even if the request is marked fast fail, we still requeue
  1157. * for queue congestion conditions (QUEUE_FULL or BUSY) */
  1158. if ((++scmd->retries) <= scmd->allowed
  1159. && !blk_noretry_request(scmd->request)) {
  1160. return NEEDS_RETRY;
  1161. } else {
  1162. /*
  1163. * no more retries - report this one back to upper level.
  1164. */
  1165. return SUCCESS;
  1166. }
  1167. }
  1168. /**
  1169. * scsi_eh_lock_door - Prevent medium removal for the specified device
  1170. * @sdev: SCSI device to prevent medium removal
  1171. *
  1172. * Locking:
  1173. * We must be called from process context; scsi_allocate_request()
  1174. * may sleep.
  1175. *
  1176. * Notes:
  1177. * We queue up an asynchronous "ALLOW MEDIUM REMOVAL" request on the
  1178. * head of the devices request queue, and continue.
  1179. *
  1180. * Bugs:
  1181. * scsi_allocate_request() may sleep waiting for existing requests to
  1182. * be processed. However, since we haven't kicked off any request
  1183. * processing for this host, this may deadlock.
  1184. *
  1185. * If scsi_allocate_request() fails for what ever reason, we
  1186. * completely forget to lock the door.
  1187. **/
  1188. static void scsi_eh_lock_door(struct scsi_device *sdev)
  1189. {
  1190. unsigned char cmnd[MAX_COMMAND_SIZE];
  1191. cmnd[0] = ALLOW_MEDIUM_REMOVAL;
  1192. cmnd[1] = 0;
  1193. cmnd[2] = 0;
  1194. cmnd[3] = 0;
  1195. cmnd[4] = SCSI_REMOVAL_PREVENT;
  1196. cmnd[5] = 0;
  1197. scsi_execute_async(sdev, cmnd, 6, DMA_NONE, NULL, 0, 0, 10 * HZ,
  1198. 5, NULL, NULL, GFP_KERNEL);
  1199. }
  1200. /**
  1201. * scsi_restart_operations - restart io operations to the specified host.
  1202. * @shost: Host we are restarting.
  1203. *
  1204. * Notes:
  1205. * When we entered the error handler, we blocked all further i/o to
  1206. * this device. we need to 'reverse' this process.
  1207. **/
  1208. static void scsi_restart_operations(struct Scsi_Host *shost)
  1209. {
  1210. struct scsi_device *sdev;
  1211. unsigned long flags;
  1212. /*
  1213. * If the door was locked, we need to insert a door lock request
  1214. * onto the head of the SCSI request queue for the device. There
  1215. * is no point trying to lock the door of an off-line device.
  1216. */
  1217. shost_for_each_device(sdev, shost) {
  1218. if (scsi_device_online(sdev) && sdev->locked)
  1219. scsi_eh_lock_door(sdev);
  1220. }
  1221. /*
  1222. * next free up anything directly waiting upon the host. this
  1223. * will be requests for character device operations, and also for
  1224. * ioctls to queued block devices.
  1225. */
  1226. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: waking up host to restart\n",
  1227. __FUNCTION__));
  1228. spin_lock_irqsave(shost->host_lock, flags);
  1229. if (scsi_host_set_state(shost, SHOST_RUNNING))
  1230. if (scsi_host_set_state(shost, SHOST_CANCEL))
  1231. BUG_ON(scsi_host_set_state(shost, SHOST_DEL));
  1232. spin_unlock_irqrestore(shost->host_lock, flags);
  1233. wake_up(&shost->host_wait);
  1234. /*
  1235. * finally we need to re-initiate requests that may be pending. we will
  1236. * have had everything blocked while error handling is taking place, and
  1237. * now that error recovery is done, we will need to ensure that these
  1238. * requests are started.
  1239. */
  1240. scsi_run_host_queues(shost);
  1241. }
  1242. /**
  1243. * scsi_eh_ready_devs - check device ready state and recover if not.
  1244. * @shost: host to be recovered.
  1245. * @eh_done_q: list_head for processed commands.
  1246. *
  1247. **/
  1248. static void scsi_eh_ready_devs(struct Scsi_Host *shost,
  1249. struct list_head *work_q,
  1250. struct list_head *done_q)
  1251. {
  1252. if (!scsi_eh_stu(shost, work_q, done_q))
  1253. if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
  1254. if (!scsi_eh_bus_reset(shost, work_q, done_q))
  1255. if (!scsi_eh_host_reset(work_q, done_q))
  1256. scsi_eh_offline_sdevs(work_q, done_q);
  1257. }
  1258. /**
  1259. * scsi_eh_flush_done_q - finish processed commands or retry them.
  1260. * @done_q: list_head of processed commands.
  1261. *
  1262. **/
  1263. void scsi_eh_flush_done_q(struct list_head *done_q)
  1264. {
  1265. struct scsi_cmnd *scmd, *next;
  1266. list_for_each_entry_safe(scmd, next, done_q, eh_entry) {
  1267. list_del_init(&scmd->eh_entry);
  1268. if (scsi_device_online(scmd->device) &&
  1269. !blk_noretry_request(scmd->request) &&
  1270. (++scmd->retries <= scmd->allowed)) {
  1271. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush"
  1272. " retry cmd: %p\n",
  1273. current->comm,
  1274. scmd));
  1275. scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
  1276. } else {
  1277. /*
  1278. * If just we got sense for the device (called
  1279. * scsi_eh_get_sense), scmd->result is already
  1280. * set, do not set DRIVER_TIMEOUT.
  1281. */
  1282. if (!scmd->result)
  1283. scmd->result |= (DRIVER_TIMEOUT << 24);
  1284. SCSI_LOG_ERROR_RECOVERY(3, printk("%s: flush finish"
  1285. " cmd: %p\n",
  1286. current->comm, scmd));
  1287. scsi_finish_command(scmd);
  1288. }
  1289. }
  1290. }
  1291. EXPORT_SYMBOL(scsi_eh_flush_done_q);
  1292. /**
  1293. * scsi_unjam_host - Attempt to fix a host which has a cmd that failed.
  1294. * @shost: Host to unjam.
  1295. *
  1296. * Notes:
  1297. * When we come in here, we *know* that all commands on the bus have
  1298. * either completed, failed or timed out. we also know that no further
  1299. * commands are being sent to the host, so things are relatively quiet
  1300. * and we have freedom to fiddle with things as we wish.
  1301. *
  1302. * This is only the *default* implementation. it is possible for
  1303. * individual drivers to supply their own version of this function, and
  1304. * if the maintainer wishes to do this, it is strongly suggested that
  1305. * this function be taken as a template and modified. this function
  1306. * was designed to correctly handle problems for about 95% of the
  1307. * different cases out there, and it should always provide at least a
  1308. * reasonable amount of error recovery.
  1309. *
  1310. * Any command marked 'failed' or 'timeout' must eventually have
  1311. * scsi_finish_cmd() called for it. we do all of the retry stuff
  1312. * here, so when we restart the host after we return it should have an
  1313. * empty queue.
  1314. **/
  1315. static void scsi_unjam_host(struct Scsi_Host *shost)
  1316. {
  1317. unsigned long flags;
  1318. LIST_HEAD(eh_work_q);
  1319. LIST_HEAD(eh_done_q);
  1320. spin_lock_irqsave(shost->host_lock, flags);
  1321. list_splice_init(&shost->eh_cmd_q, &eh_work_q);
  1322. spin_unlock_irqrestore(shost->host_lock, flags);
  1323. SCSI_LOG_ERROR_RECOVERY(1, scsi_eh_prt_fail_stats(shost, &eh_work_q));
  1324. if (!scsi_eh_get_sense(&eh_work_q, &eh_done_q))
  1325. if (!scsi_eh_abort_cmds(&eh_work_q, &eh_done_q))
  1326. scsi_eh_ready_devs(shost, &eh_work_q, &eh_done_q);
  1327. scsi_eh_flush_done_q(&eh_done_q);
  1328. }
  1329. /**
  1330. * scsi_error_handler - SCSI error handler thread
  1331. * @data: Host for which we are running.
  1332. *
  1333. * Notes:
  1334. * This is the main error handling loop. This is run as a kernel thread
  1335. * for every SCSI host and handles all error handling activity.
  1336. **/
  1337. int scsi_error_handler(void *data)
  1338. {
  1339. struct Scsi_Host *shost = data;
  1340. current->flags |= PF_NOFREEZE;
  1341. /*
  1342. * We use TASK_INTERRUPTIBLE so that the thread is not
  1343. * counted against the load average as a running process.
  1344. * We never actually get interrupted because kthread_run
  1345. * disables singal delivery for the created thread.
  1346. */
  1347. set_current_state(TASK_INTERRUPTIBLE);
  1348. while (!kthread_should_stop()) {
  1349. if (shost->host_failed == 0 ||
  1350. shost->host_failed != shost->host_busy) {
  1351. SCSI_LOG_ERROR_RECOVERY(1,
  1352. printk("Error handler scsi_eh_%d sleeping\n",
  1353. shost->host_no));
  1354. schedule();
  1355. set_current_state(TASK_INTERRUPTIBLE);
  1356. continue;
  1357. }
  1358. __set_current_state(TASK_RUNNING);
  1359. SCSI_LOG_ERROR_RECOVERY(1,
  1360. printk("Error handler scsi_eh_%d waking up\n",
  1361. shost->host_no));
  1362. /*
  1363. * We have a host that is failing for some reason. Figure out
  1364. * what we need to do to get it up and online again (if we can).
  1365. * If we fail, we end up taking the thing offline.
  1366. */
  1367. if (shost->transportt->eh_strategy_handler)
  1368. shost->transportt->eh_strategy_handler(shost);
  1369. else
  1370. scsi_unjam_host(shost);
  1371. /*
  1372. * Note - if the above fails completely, the action is to take
  1373. * individual devices offline and flush the queue of any
  1374. * outstanding requests that may have been pending. When we
  1375. * restart, we restart any I/O to any other devices on the bus
  1376. * which are still online.
  1377. */
  1378. scsi_restart_operations(shost);
  1379. set_current_state(TASK_INTERRUPTIBLE);
  1380. }
  1381. __set_current_state(TASK_RUNNING);
  1382. SCSI_LOG_ERROR_RECOVERY(1,
  1383. printk("Error handler scsi_eh_%d exiting\n", shost->host_no));
  1384. shost->ehandler = NULL;
  1385. return 0;
  1386. }
  1387. /*
  1388. * Function: scsi_report_bus_reset()
  1389. *
  1390. * Purpose: Utility function used by low-level drivers to report that
  1391. * they have observed a bus reset on the bus being handled.
  1392. *
  1393. * Arguments: shost - Host in question
  1394. * channel - channel on which reset was observed.
  1395. *
  1396. * Returns: Nothing
  1397. *
  1398. * Lock status: Host lock must be held.
  1399. *
  1400. * Notes: This only needs to be called if the reset is one which
  1401. * originates from an unknown location. Resets originated
  1402. * by the mid-level itself don't need to call this, but there
  1403. * should be no harm.
  1404. *
  1405. * The main purpose of this is to make sure that a CHECK_CONDITION
  1406. * is properly treated.
  1407. */
  1408. void scsi_report_bus_reset(struct Scsi_Host *shost, int channel)
  1409. {
  1410. struct scsi_device *sdev;
  1411. __shost_for_each_device(sdev, shost) {
  1412. if (channel == sdev_channel(sdev)) {
  1413. sdev->was_reset = 1;
  1414. sdev->expecting_cc_ua = 1;
  1415. }
  1416. }
  1417. }
  1418. EXPORT_SYMBOL(scsi_report_bus_reset);
  1419. /*
  1420. * Function: scsi_report_device_reset()
  1421. *
  1422. * Purpose: Utility function used by low-level drivers to report that
  1423. * they have observed a device reset on the device being handled.
  1424. *
  1425. * Arguments: shost - Host in question
  1426. * channel - channel on which reset was observed
  1427. * target - target on which reset was observed
  1428. *
  1429. * Returns: Nothing
  1430. *
  1431. * Lock status: Host lock must be held
  1432. *
  1433. * Notes: This only needs to be called if the reset is one which
  1434. * originates from an unknown location. Resets originated
  1435. * by the mid-level itself don't need to call this, but there
  1436. * should be no harm.
  1437. *
  1438. * The main purpose of this is to make sure that a CHECK_CONDITION
  1439. * is properly treated.
  1440. */
  1441. void scsi_report_device_reset(struct Scsi_Host *shost, int channel, int target)
  1442. {
  1443. struct scsi_device *sdev;
  1444. __shost_for_each_device(sdev, shost) {
  1445. if (channel == sdev_channel(sdev) &&
  1446. target == sdev_id(sdev)) {
  1447. sdev->was_reset = 1;
  1448. sdev->expecting_cc_ua = 1;
  1449. }
  1450. }
  1451. }
  1452. EXPORT_SYMBOL(scsi_report_device_reset);
  1453. static void
  1454. scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
  1455. {
  1456. }
  1457. /*
  1458. * Function: scsi_reset_provider
  1459. *
  1460. * Purpose: Send requested reset to a bus or device at any phase.
  1461. *
  1462. * Arguments: device - device to send reset to
  1463. * flag - reset type (see scsi.h)
  1464. *
  1465. * Returns: SUCCESS/FAILURE.
  1466. *
  1467. * Notes: This is used by the SCSI Generic driver to provide
  1468. * Bus/Device reset capability.
  1469. */
  1470. int
  1471. scsi_reset_provider(struct scsi_device *dev, int flag)
  1472. {
  1473. struct scsi_cmnd *scmd = scsi_get_command(dev, GFP_KERNEL);
  1474. struct request req;
  1475. int rtn;
  1476. scmd->request = &req;
  1477. memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
  1478. scmd->request->rq_status = RQ_SCSI_BUSY;
  1479. memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
  1480. scmd->scsi_done = scsi_reset_provider_done_command;
  1481. scmd->done = NULL;
  1482. scmd->buffer = NULL;
  1483. scmd->bufflen = 0;
  1484. scmd->request_buffer = NULL;
  1485. scmd->request_bufflen = 0;
  1486. scmd->cmd_len = 0;
  1487. scmd->sc_data_direction = DMA_BIDIRECTIONAL;
  1488. scmd->sc_request = NULL;
  1489. scmd->sc_magic = SCSI_CMND_MAGIC;
  1490. init_timer(&scmd->eh_timeout);
  1491. /*
  1492. * Sometimes the command can get back into the timer chain,
  1493. * so use the pid as an identifier.
  1494. */
  1495. scmd->pid = 0;
  1496. switch (flag) {
  1497. case SCSI_TRY_RESET_DEVICE:
  1498. rtn = scsi_try_bus_device_reset(scmd);
  1499. if (rtn == SUCCESS)
  1500. break;
  1501. /* FALLTHROUGH */
  1502. case SCSI_TRY_RESET_BUS:
  1503. rtn = scsi_try_bus_reset(scmd);
  1504. if (rtn == SUCCESS)
  1505. break;
  1506. /* FALLTHROUGH */
  1507. case SCSI_TRY_RESET_HOST:
  1508. rtn = scsi_try_host_reset(scmd);
  1509. break;
  1510. default:
  1511. rtn = FAILED;
  1512. }
  1513. scsi_next_command(scmd);
  1514. return rtn;
  1515. }
  1516. EXPORT_SYMBOL(scsi_reset_provider);
  1517. /**
  1518. * scsi_normalize_sense - normalize main elements from either fixed or
  1519. * descriptor sense data format into a common format.
  1520. *
  1521. * @sense_buffer: byte array containing sense data returned by device
  1522. * @sb_len: number of valid bytes in sense_buffer
  1523. * @sshdr: pointer to instance of structure that common
  1524. * elements are written to.
  1525. *
  1526. * Notes:
  1527. * The "main elements" from sense data are: response_code, sense_key,
  1528. * asc, ascq and additional_length (only for descriptor format).
  1529. *
  1530. * Typically this function can be called after a device has
  1531. * responded to a SCSI command with the CHECK_CONDITION status.
  1532. *
  1533. * Return value:
  1534. * 1 if valid sense data information found, else 0;
  1535. **/
  1536. int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
  1537. struct scsi_sense_hdr *sshdr)
  1538. {
  1539. if (!sense_buffer || !sb_len)
  1540. return 0;
  1541. memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
  1542. sshdr->response_code = (sense_buffer[0] & 0x7f);
  1543. if (!scsi_sense_valid(sshdr))
  1544. return 0;
  1545. if (sshdr->response_code >= 0x72) {
  1546. /*
  1547. * descriptor format
  1548. */
  1549. if (sb_len > 1)
  1550. sshdr->sense_key = (sense_buffer[1] & 0xf);
  1551. if (sb_len > 2)
  1552. sshdr->asc = sense_buffer[2];
  1553. if (sb_len > 3)
  1554. sshdr->ascq = sense_buffer[3];
  1555. if (sb_len > 7)
  1556. sshdr->additional_length = sense_buffer[7];
  1557. } else {
  1558. /*
  1559. * fixed format
  1560. */
  1561. if (sb_len > 2)
  1562. sshdr->sense_key = (sense_buffer[2] & 0xf);
  1563. if (sb_len > 7) {
  1564. sb_len = (sb_len < (sense_buffer[7] + 8)) ?
  1565. sb_len : (sense_buffer[7] + 8);
  1566. if (sb_len > 12)
  1567. sshdr->asc = sense_buffer[12];
  1568. if (sb_len > 13)
  1569. sshdr->ascq = sense_buffer[13];
  1570. }
  1571. }
  1572. return 1;
  1573. }
  1574. EXPORT_SYMBOL(scsi_normalize_sense);
  1575. int scsi_request_normalize_sense(struct scsi_request *sreq,
  1576. struct scsi_sense_hdr *sshdr)
  1577. {
  1578. return scsi_normalize_sense(sreq->sr_sense_buffer,
  1579. sizeof(sreq->sr_sense_buffer), sshdr);
  1580. }
  1581. EXPORT_SYMBOL(scsi_request_normalize_sense);
  1582. int scsi_command_normalize_sense(struct scsi_cmnd *cmd,
  1583. struct scsi_sense_hdr *sshdr)
  1584. {
  1585. return scsi_normalize_sense(cmd->sense_buffer,
  1586. sizeof(cmd->sense_buffer), sshdr);
  1587. }
  1588. EXPORT_SYMBOL(scsi_command_normalize_sense);
  1589. /**
  1590. * scsi_sense_desc_find - search for a given descriptor type in
  1591. * descriptor sense data format.
  1592. *
  1593. * @sense_buffer: byte array of descriptor format sense data
  1594. * @sb_len: number of valid bytes in sense_buffer
  1595. * @desc_type: value of descriptor type to find
  1596. * (e.g. 0 -> information)
  1597. *
  1598. * Notes:
  1599. * only valid when sense data is in descriptor format
  1600. *
  1601. * Return value:
  1602. * pointer to start of (first) descriptor if found else NULL
  1603. **/
  1604. const u8 * scsi_sense_desc_find(const u8 * sense_buffer, int sb_len,
  1605. int desc_type)
  1606. {
  1607. int add_sen_len, add_len, desc_len, k;
  1608. const u8 * descp;
  1609. if ((sb_len < 8) || (0 == (add_sen_len = sense_buffer[7])))
  1610. return NULL;
  1611. if ((sense_buffer[0] < 0x72) || (sense_buffer[0] > 0x73))
  1612. return NULL;
  1613. add_sen_len = (add_sen_len < (sb_len - 8)) ?
  1614. add_sen_len : (sb_len - 8);
  1615. descp = &sense_buffer[8];
  1616. for (desc_len = 0, k = 0; k < add_sen_len; k += desc_len) {
  1617. descp += desc_len;
  1618. add_len = (k < (add_sen_len - 1)) ? descp[1]: -1;
  1619. desc_len = add_len + 2;
  1620. if (descp[0] == desc_type)
  1621. return descp;
  1622. if (add_len < 0) // short descriptor ??
  1623. break;
  1624. }
  1625. return NULL;
  1626. }
  1627. EXPORT_SYMBOL(scsi_sense_desc_find);
  1628. /**
  1629. * scsi_get_sense_info_fld - attempts to get information field from
  1630. * sense data (either fixed or descriptor format)
  1631. *
  1632. * @sense_buffer: byte array of sense data
  1633. * @sb_len: number of valid bytes in sense_buffer
  1634. * @info_out: pointer to 64 integer where 8 or 4 byte information
  1635. * field will be placed if found.
  1636. *
  1637. * Return value:
  1638. * 1 if information field found, 0 if not found.
  1639. **/
  1640. int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len,
  1641. u64 * info_out)
  1642. {
  1643. int j;
  1644. const u8 * ucp;
  1645. u64 ull;
  1646. if (sb_len < 7)
  1647. return 0;
  1648. switch (sense_buffer[0] & 0x7f) {
  1649. case 0x70:
  1650. case 0x71:
  1651. if (sense_buffer[0] & 0x80) {
  1652. *info_out = (sense_buffer[3] << 24) +
  1653. (sense_buffer[4] << 16) +
  1654. (sense_buffer[5] << 8) + sense_buffer[6];
  1655. return 1;
  1656. } else
  1657. return 0;
  1658. case 0x72:
  1659. case 0x73:
  1660. ucp = scsi_sense_desc_find(sense_buffer, sb_len,
  1661. 0 /* info desc */);
  1662. if (ucp && (0xa == ucp[1])) {
  1663. ull = 0;
  1664. for (j = 0; j < 8; ++j) {
  1665. if (j > 0)
  1666. ull <<= 8;
  1667. ull |= ucp[4 + j];
  1668. }
  1669. *info_out = ull;
  1670. return 1;
  1671. } else
  1672. return 0;
  1673. default:
  1674. return 0;
  1675. }
  1676. }
  1677. EXPORT_SYMBOL(scsi_get_sense_info_fld);