scsi_error.c 49 KB

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