scsi.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * scsi.c Copyright (C) 1992 Drew Eckhardt
  3. * Copyright (C) 1993, 1994, 1995, 1999 Eric Youngdale
  4. * Copyright (C) 2002, 2003 Christoph Hellwig
  5. *
  6. * generic mid-level SCSI driver
  7. * Initial versions: Drew Eckhardt
  8. * Subsequent revisions: Eric Youngdale
  9. *
  10. * <drew@colorado.edu>
  11. *
  12. * Bug correction thanks go to :
  13. * Rik Faith <faith@cs.unc.edu>
  14. * Tommy Thorn <tthorn>
  15. * Thomas Wuensche <tw@fgb1.fgb.mw.tu-muenchen.de>
  16. *
  17. * Modified by Eric Youngdale eric@andante.org or ericy@gnu.ai.mit.edu to
  18. * add scatter-gather, multiple outstanding request, and other
  19. * enhancements.
  20. *
  21. * Native multichannel, wide scsi, /proc/scsi and hot plugging
  22. * support added by Michael Neuffer <mike@i-connect.net>
  23. *
  24. * Added request_module("scsi_hostadapter") for kerneld:
  25. * (Put an "alias scsi_hostadapter your_hostadapter" in /etc/modprobe.conf)
  26. * Bjorn Ekwall <bj0rn@blox.se>
  27. * (changed to kmod)
  28. *
  29. * Major improvements to the timeout, abort, and reset processing,
  30. * as well as performance modifications for large queue depths by
  31. * Leonard N. Zubkoff <lnz@dandelion.com>
  32. *
  33. * Converted cli() code to spinlocks, Ingo Molnar
  34. *
  35. * Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
  36. *
  37. * out_of_space hacks, D. Gilbert (dpg) 990608
  38. */
  39. #include <linux/module.h>
  40. #include <linux/moduleparam.h>
  41. #include <linux/kernel.h>
  42. #include <linux/sched.h>
  43. #include <linux/timer.h>
  44. #include <linux/string.h>
  45. #include <linux/slab.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/delay.h>
  48. #include <linux/init.h>
  49. #include <linux/completion.h>
  50. #include <linux/unistd.h>
  51. #include <linux/spinlock.h>
  52. #include <linux/kmod.h>
  53. #include <linux/interrupt.h>
  54. #include <linux/notifier.h>
  55. #include <linux/cpu.h>
  56. #include <linux/mutex.h>
  57. #include <scsi/scsi.h>
  58. #include <scsi/scsi_cmnd.h>
  59. #include <scsi/scsi_dbg.h>
  60. #include <scsi/scsi_device.h>
  61. #include <scsi/scsi_eh.h>
  62. #include <scsi/scsi_host.h>
  63. #include <scsi/scsi_tcq.h>
  64. #include <scsi/scsi_request.h>
  65. #include "scsi_priv.h"
  66. #include "scsi_logging.h"
  67. static void scsi_done(struct scsi_cmnd *cmd);
  68. /*
  69. * Definitions and constants.
  70. */
  71. #define MIN_RESET_DELAY (2*HZ)
  72. /* Do not call reset on error if we just did a reset within 15 sec. */
  73. #define MIN_RESET_PERIOD (15*HZ)
  74. /*
  75. * Macro to determine the size of SCSI command. This macro takes vendor
  76. * unique commands into account. SCSI commands in groups 6 and 7 are
  77. * vendor unique and we will depend upon the command length being
  78. * supplied correctly in cmd_len.
  79. */
  80. #define CDB_SIZE(cmd) (((((cmd)->cmnd[0] >> 5) & 7) < 6) ? \
  81. COMMAND_SIZE((cmd)->cmnd[0]) : (cmd)->cmd_len)
  82. /*
  83. * Note - the initial logging level can be set here to log events at boot time.
  84. * After the system is up, you may enable logging via the /proc interface.
  85. */
  86. unsigned int scsi_logging_level;
  87. #if defined(CONFIG_SCSI_LOGGING)
  88. EXPORT_SYMBOL(scsi_logging_level);
  89. #endif
  90. const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE] = {
  91. "Direct-Access ",
  92. "Sequential-Access",
  93. "Printer ",
  94. "Processor ",
  95. "WORM ",
  96. "CD-ROM ",
  97. "Scanner ",
  98. "Optical Device ",
  99. "Medium Changer ",
  100. "Communications ",
  101. "Unknown ",
  102. "Unknown ",
  103. "RAID ",
  104. "Enclosure ",
  105. "Direct-Access-RBC",
  106. };
  107. EXPORT_SYMBOL(scsi_device_types);
  108. /*
  109. * Function: scsi_allocate_request
  110. *
  111. * Purpose: Allocate a request descriptor.
  112. *
  113. * Arguments: device - device for which we want a request
  114. * gfp_mask - allocation flags passed to kmalloc
  115. *
  116. * Lock status: No locks assumed to be held. This function is SMP-safe.
  117. *
  118. * Returns: Pointer to request block.
  119. */
  120. struct scsi_request *scsi_allocate_request(struct scsi_device *sdev,
  121. gfp_t gfp_mask)
  122. {
  123. const int offset = ALIGN(sizeof(struct scsi_request), 4);
  124. const int size = offset + sizeof(struct request);
  125. struct scsi_request *sreq;
  126. sreq = kzalloc(size, gfp_mask);
  127. if (likely(sreq != NULL)) {
  128. sreq->sr_request = (struct request *)(((char *)sreq) + offset);
  129. sreq->sr_device = sdev;
  130. sreq->sr_host = sdev->host;
  131. sreq->sr_magic = SCSI_REQ_MAGIC;
  132. sreq->sr_data_direction = DMA_BIDIRECTIONAL;
  133. }
  134. return sreq;
  135. }
  136. EXPORT_SYMBOL(scsi_allocate_request);
  137. void __scsi_release_request(struct scsi_request *sreq)
  138. {
  139. struct request *req = sreq->sr_request;
  140. /* unlikely because the tag was usually ended earlier by the
  141. * mid-layer. However, for layering reasons ULD's don't end
  142. * the tag of commands they generate. */
  143. if (unlikely(blk_rq_tagged(req))) {
  144. unsigned long flags;
  145. struct request_queue *q = req->q;
  146. spin_lock_irqsave(q->queue_lock, flags);
  147. blk_queue_end_tag(q, req);
  148. spin_unlock_irqrestore(q->queue_lock, flags);
  149. }
  150. if (likely(sreq->sr_command != NULL)) {
  151. struct scsi_cmnd *cmd = sreq->sr_command;
  152. sreq->sr_command = NULL;
  153. scsi_next_command(cmd);
  154. }
  155. }
  156. /*
  157. * Function: scsi_release_request
  158. *
  159. * Purpose: Release a request descriptor.
  160. *
  161. * Arguments: sreq - request to release
  162. *
  163. * Lock status: No locks assumed to be held. This function is SMP-safe.
  164. */
  165. void scsi_release_request(struct scsi_request *sreq)
  166. {
  167. __scsi_release_request(sreq);
  168. kfree(sreq);
  169. }
  170. EXPORT_SYMBOL(scsi_release_request);
  171. struct scsi_host_cmd_pool {
  172. kmem_cache_t *slab;
  173. unsigned int users;
  174. char *name;
  175. unsigned int slab_flags;
  176. gfp_t gfp_mask;
  177. };
  178. static struct scsi_host_cmd_pool scsi_cmd_pool = {
  179. .name = "scsi_cmd_cache",
  180. .slab_flags = SLAB_HWCACHE_ALIGN,
  181. };
  182. static struct scsi_host_cmd_pool scsi_cmd_dma_pool = {
  183. .name = "scsi_cmd_cache(DMA)",
  184. .slab_flags = SLAB_HWCACHE_ALIGN|SLAB_CACHE_DMA,
  185. .gfp_mask = __GFP_DMA,
  186. };
  187. static DEFINE_MUTEX(host_cmd_pool_mutex);
  188. static struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *shost,
  189. gfp_t gfp_mask)
  190. {
  191. struct scsi_cmnd *cmd;
  192. cmd = kmem_cache_alloc(shost->cmd_pool->slab,
  193. gfp_mask | shost->cmd_pool->gfp_mask);
  194. if (unlikely(!cmd)) {
  195. unsigned long flags;
  196. spin_lock_irqsave(&shost->free_list_lock, flags);
  197. if (likely(!list_empty(&shost->free_list))) {
  198. cmd = list_entry(shost->free_list.next,
  199. struct scsi_cmnd, list);
  200. list_del_init(&cmd->list);
  201. }
  202. spin_unlock_irqrestore(&shost->free_list_lock, flags);
  203. }
  204. return cmd;
  205. }
  206. /*
  207. * Function: scsi_get_command()
  208. *
  209. * Purpose: Allocate and setup a scsi command block
  210. *
  211. * Arguments: dev - parent scsi device
  212. * gfp_mask- allocator flags
  213. *
  214. * Returns: The allocated scsi command structure.
  215. */
  216. struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask)
  217. {
  218. struct scsi_cmnd *cmd;
  219. /* Bail if we can't get a reference to the device */
  220. if (!get_device(&dev->sdev_gendev))
  221. return NULL;
  222. cmd = __scsi_get_command(dev->host, gfp_mask);
  223. if (likely(cmd != NULL)) {
  224. unsigned long flags;
  225. memset(cmd, 0, sizeof(*cmd));
  226. cmd->device = dev;
  227. init_timer(&cmd->eh_timeout);
  228. INIT_LIST_HEAD(&cmd->list);
  229. spin_lock_irqsave(&dev->list_lock, flags);
  230. list_add_tail(&cmd->list, &dev->cmd_list);
  231. spin_unlock_irqrestore(&dev->list_lock, flags);
  232. cmd->jiffies_at_alloc = jiffies;
  233. } else
  234. put_device(&dev->sdev_gendev);
  235. return cmd;
  236. }
  237. EXPORT_SYMBOL(scsi_get_command);
  238. /*
  239. * Function: scsi_put_command()
  240. *
  241. * Purpose: Free a scsi command block
  242. *
  243. * Arguments: cmd - command block to free
  244. *
  245. * Returns: Nothing.
  246. *
  247. * Notes: The command must not belong to any lists.
  248. */
  249. void scsi_put_command(struct scsi_cmnd *cmd)
  250. {
  251. struct scsi_device *sdev = cmd->device;
  252. struct Scsi_Host *shost = sdev->host;
  253. unsigned long flags;
  254. /* serious error if the command hasn't come from a device list */
  255. spin_lock_irqsave(&cmd->device->list_lock, flags);
  256. BUG_ON(list_empty(&cmd->list));
  257. list_del_init(&cmd->list);
  258. spin_unlock(&cmd->device->list_lock);
  259. /* changing locks here, don't need to restore the irq state */
  260. spin_lock(&shost->free_list_lock);
  261. if (unlikely(list_empty(&shost->free_list))) {
  262. list_add(&cmd->list, &shost->free_list);
  263. cmd = NULL;
  264. }
  265. spin_unlock_irqrestore(&shost->free_list_lock, flags);
  266. if (likely(cmd != NULL))
  267. kmem_cache_free(shost->cmd_pool->slab, cmd);
  268. put_device(&sdev->sdev_gendev);
  269. }
  270. EXPORT_SYMBOL(scsi_put_command);
  271. /*
  272. * Function: scsi_setup_command_freelist()
  273. *
  274. * Purpose: Setup the command freelist for a scsi host.
  275. *
  276. * Arguments: shost - host to allocate the freelist for.
  277. *
  278. * Returns: Nothing.
  279. */
  280. int scsi_setup_command_freelist(struct Scsi_Host *shost)
  281. {
  282. struct scsi_host_cmd_pool *pool;
  283. struct scsi_cmnd *cmd;
  284. spin_lock_init(&shost->free_list_lock);
  285. INIT_LIST_HEAD(&shost->free_list);
  286. /*
  287. * Select a command slab for this host and create it if not
  288. * yet existant.
  289. */
  290. mutex_lock(&host_cmd_pool_mutex);
  291. pool = (shost->unchecked_isa_dma ? &scsi_cmd_dma_pool : &scsi_cmd_pool);
  292. if (!pool->users) {
  293. pool->slab = kmem_cache_create(pool->name,
  294. sizeof(struct scsi_cmnd), 0,
  295. pool->slab_flags, NULL, NULL);
  296. if (!pool->slab)
  297. goto fail;
  298. }
  299. pool->users++;
  300. shost->cmd_pool = pool;
  301. mutex_unlock(&host_cmd_pool_mutex);
  302. /*
  303. * Get one backup command for this host.
  304. */
  305. cmd = kmem_cache_alloc(shost->cmd_pool->slab,
  306. GFP_KERNEL | shost->cmd_pool->gfp_mask);
  307. if (!cmd)
  308. goto fail2;
  309. list_add(&cmd->list, &shost->free_list);
  310. return 0;
  311. fail2:
  312. if (!--pool->users)
  313. kmem_cache_destroy(pool->slab);
  314. return -ENOMEM;
  315. fail:
  316. mutex_unlock(&host_cmd_pool_mutex);
  317. return -ENOMEM;
  318. }
  319. /*
  320. * Function: scsi_destroy_command_freelist()
  321. *
  322. * Purpose: Release the command freelist for a scsi host.
  323. *
  324. * Arguments: shost - host that's freelist is going to be destroyed
  325. */
  326. void scsi_destroy_command_freelist(struct Scsi_Host *shost)
  327. {
  328. while (!list_empty(&shost->free_list)) {
  329. struct scsi_cmnd *cmd;
  330. cmd = list_entry(shost->free_list.next, struct scsi_cmnd, list);
  331. list_del_init(&cmd->list);
  332. kmem_cache_free(shost->cmd_pool->slab, cmd);
  333. }
  334. mutex_lock(&host_cmd_pool_mutex);
  335. if (!--shost->cmd_pool->users)
  336. kmem_cache_destroy(shost->cmd_pool->slab);
  337. mutex_unlock(&host_cmd_pool_mutex);
  338. }
  339. #ifdef CONFIG_SCSI_LOGGING
  340. void scsi_log_send(struct scsi_cmnd *cmd)
  341. {
  342. unsigned int level;
  343. struct scsi_device *sdev;
  344. /*
  345. * If ML QUEUE log level is greater than or equal to:
  346. *
  347. * 1: nothing (match completion)
  348. *
  349. * 2: log opcode + command of all commands
  350. *
  351. * 3: same as 2 plus dump cmd address
  352. *
  353. * 4: same as 3 plus dump extra junk
  354. */
  355. if (unlikely(scsi_logging_level)) {
  356. level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
  357. SCSI_LOG_MLQUEUE_BITS);
  358. if (level > 1) {
  359. sdev = cmd->device;
  360. sdev_printk(KERN_INFO, sdev, "send ");
  361. if (level > 2)
  362. printk("0x%p ", cmd);
  363. /*
  364. * spaces to match disposition and cmd->result
  365. * output in scsi_log_completion.
  366. */
  367. printk(" ");
  368. scsi_print_command(cmd);
  369. if (level > 3) {
  370. printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
  371. " done = 0x%p, queuecommand 0x%p\n",
  372. cmd->buffer, cmd->bufflen,
  373. cmd->done,
  374. sdev->host->hostt->queuecommand);
  375. }
  376. }
  377. }
  378. }
  379. void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
  380. {
  381. unsigned int level;
  382. struct scsi_device *sdev;
  383. /*
  384. * If ML COMPLETE log level is greater than or equal to:
  385. *
  386. * 1: log disposition, result, opcode + command, and conditionally
  387. * sense data for failures or non SUCCESS dispositions.
  388. *
  389. * 2: same as 1 but for all command completions.
  390. *
  391. * 3: same as 2 plus dump cmd address
  392. *
  393. * 4: same as 3 plus dump extra junk
  394. */
  395. if (unlikely(scsi_logging_level)) {
  396. level = SCSI_LOG_LEVEL(SCSI_LOG_MLCOMPLETE_SHIFT,
  397. SCSI_LOG_MLCOMPLETE_BITS);
  398. if (((level > 0) && (cmd->result || disposition != SUCCESS)) ||
  399. (level > 1)) {
  400. sdev = cmd->device;
  401. sdev_printk(KERN_INFO, sdev, "done ");
  402. if (level > 2)
  403. printk("0x%p ", cmd);
  404. /*
  405. * Dump truncated values, so we usually fit within
  406. * 80 chars.
  407. */
  408. switch (disposition) {
  409. case SUCCESS:
  410. printk("SUCCESS");
  411. break;
  412. case NEEDS_RETRY:
  413. printk("RETRY ");
  414. break;
  415. case ADD_TO_MLQUEUE:
  416. printk("MLQUEUE");
  417. break;
  418. case FAILED:
  419. printk("FAILED ");
  420. break;
  421. case TIMEOUT_ERROR:
  422. /*
  423. * If called via scsi_times_out.
  424. */
  425. printk("TIMEOUT");
  426. break;
  427. default:
  428. printk("UNKNOWN");
  429. }
  430. printk(" %8x ", cmd->result);
  431. scsi_print_command(cmd);
  432. if (status_byte(cmd->result) & CHECK_CONDITION) {
  433. /*
  434. * XXX The scsi_print_sense formatting/prefix
  435. * doesn't match this function.
  436. */
  437. scsi_print_sense("", cmd);
  438. }
  439. if (level > 3) {
  440. printk(KERN_INFO "scsi host busy %d failed %d\n",
  441. sdev->host->host_busy,
  442. sdev->host->host_failed);
  443. }
  444. }
  445. }
  446. }
  447. #endif
  448. /*
  449. * Assign a serial number and pid to the request for error recovery
  450. * and debugging purposes. Protected by the Host_Lock of host.
  451. */
  452. static inline void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  453. {
  454. cmd->serial_number = host->cmd_serial_number++;
  455. if (cmd->serial_number == 0)
  456. cmd->serial_number = host->cmd_serial_number++;
  457. cmd->pid = host->cmd_pid++;
  458. if (cmd->pid == 0)
  459. cmd->pid = host->cmd_pid++;
  460. }
  461. /*
  462. * Function: scsi_dispatch_command
  463. *
  464. * Purpose: Dispatch a command to the low-level driver.
  465. *
  466. * Arguments: cmd - command block we are dispatching.
  467. *
  468. * Notes:
  469. */
  470. int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
  471. {
  472. struct Scsi_Host *host = cmd->device->host;
  473. unsigned long flags = 0;
  474. unsigned long timeout;
  475. int rtn = 0;
  476. /* check if the device is still usable */
  477. if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
  478. /* in SDEV_DEL we error all commands. DID_NO_CONNECT
  479. * returns an immediate error upwards, and signals
  480. * that the device is no longer present */
  481. cmd->result = DID_NO_CONNECT << 16;
  482. atomic_inc(&cmd->device->iorequest_cnt);
  483. __scsi_done(cmd);
  484. /* return 0 (because the command has been processed) */
  485. goto out;
  486. }
  487. /* Check to see if the scsi lld put this device into state SDEV_BLOCK. */
  488. if (unlikely(cmd->device->sdev_state == SDEV_BLOCK)) {
  489. /*
  490. * in SDEV_BLOCK, the command is just put back on the device
  491. * queue. The suspend state has already blocked the queue so
  492. * future requests should not occur until the device
  493. * transitions out of the suspend state.
  494. */
  495. scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
  496. SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n"));
  497. /*
  498. * NOTE: rtn is still zero here because we don't need the
  499. * queue to be plugged on return (it's already stopped)
  500. */
  501. goto out;
  502. }
  503. /*
  504. * If SCSI-2 or lower, store the LUN value in cmnd.
  505. */
  506. if (cmd->device->scsi_level <= SCSI_2) {
  507. cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
  508. (cmd->device->lun << 5 & 0xe0);
  509. }
  510. /*
  511. * We will wait MIN_RESET_DELAY clock ticks after the last reset so
  512. * we can avoid the drive not being ready.
  513. */
  514. timeout = host->last_reset + MIN_RESET_DELAY;
  515. if (host->resetting && time_before(jiffies, timeout)) {
  516. int ticks_remaining = timeout - jiffies;
  517. /*
  518. * NOTE: This may be executed from within an interrupt
  519. * handler! This is bad, but for now, it'll do. The irq
  520. * level of the interrupt handler has been masked out by the
  521. * platform dependent interrupt handling code already, so the
  522. * sti() here will not cause another call to the SCSI host's
  523. * interrupt handler (assuming there is one irq-level per
  524. * host).
  525. */
  526. while (--ticks_remaining >= 0)
  527. mdelay(1 + 999 / HZ);
  528. host->resetting = 0;
  529. }
  530. /*
  531. * AK: unlikely race here: for some reason the timer could
  532. * expire before the serial number is set up below.
  533. */
  534. scsi_add_timer(cmd, cmd->timeout_per_command, scsi_times_out);
  535. scsi_log_send(cmd);
  536. /*
  537. * We will use a queued command if possible, otherwise we will
  538. * emulate the queuing and calling of completion function ourselves.
  539. */
  540. atomic_inc(&cmd->device->iorequest_cnt);
  541. /*
  542. * Before we queue this command, check if the command
  543. * length exceeds what the host adapter can handle.
  544. */
  545. if (CDB_SIZE(cmd) > cmd->device->host->max_cmd_len) {
  546. SCSI_LOG_MLQUEUE(3,
  547. printk("queuecommand : command too long.\n"));
  548. cmd->result = (DID_ABORT << 16);
  549. scsi_done(cmd);
  550. goto out;
  551. }
  552. spin_lock_irqsave(host->host_lock, flags);
  553. scsi_cmd_get_serial(host, cmd);
  554. if (unlikely(host->shost_state == SHOST_DEL)) {
  555. cmd->result = (DID_NO_CONNECT << 16);
  556. scsi_done(cmd);
  557. } else {
  558. rtn = host->hostt->queuecommand(cmd, scsi_done);
  559. }
  560. spin_unlock_irqrestore(host->host_lock, flags);
  561. if (rtn) {
  562. if (scsi_delete_timer(cmd)) {
  563. atomic_inc(&cmd->device->iodone_cnt);
  564. scsi_queue_insert(cmd,
  565. (rtn == SCSI_MLQUEUE_DEVICE_BUSY) ?
  566. rtn : SCSI_MLQUEUE_HOST_BUSY);
  567. }
  568. SCSI_LOG_MLQUEUE(3,
  569. printk("queuecommand : request rejected\n"));
  570. }
  571. out:
  572. SCSI_LOG_MLQUEUE(3, printk("leaving scsi_dispatch_cmnd()\n"));
  573. return rtn;
  574. }
  575. /*
  576. * Function: scsi_init_cmd_from_req
  577. *
  578. * Purpose: Queue a SCSI command
  579. * Purpose: Initialize a struct scsi_cmnd from a struct scsi_request
  580. *
  581. * Arguments: cmd - command descriptor.
  582. * sreq - Request from the queue.
  583. *
  584. * Lock status: None needed.
  585. *
  586. * Returns: Nothing.
  587. *
  588. * Notes: Mainly transfer data from the request structure to the
  589. * command structure. The request structure is allocated
  590. * using the normal memory allocator, and requests can pile
  591. * up to more or less any depth. The command structure represents
  592. * a consumable resource, as these are allocated into a pool
  593. * when the SCSI subsystem initializes. The preallocation is
  594. * required so that in low-memory situations a disk I/O request
  595. * won't cause the memory manager to try and write out a page.
  596. * The request structure is generally used by ioctls and character
  597. * devices.
  598. */
  599. void scsi_init_cmd_from_req(struct scsi_cmnd *cmd, struct scsi_request *sreq)
  600. {
  601. sreq->sr_command = cmd;
  602. cmd->cmd_len = sreq->sr_cmd_len;
  603. cmd->use_sg = sreq->sr_use_sg;
  604. cmd->request = sreq->sr_request;
  605. memcpy(cmd->data_cmnd, sreq->sr_cmnd, sizeof(cmd->data_cmnd));
  606. cmd->serial_number = 0;
  607. cmd->bufflen = sreq->sr_bufflen;
  608. cmd->buffer = sreq->sr_buffer;
  609. cmd->retries = 0;
  610. cmd->allowed = sreq->sr_allowed;
  611. cmd->done = sreq->sr_done;
  612. cmd->timeout_per_command = sreq->sr_timeout_per_command;
  613. cmd->sc_data_direction = sreq->sr_data_direction;
  614. cmd->sglist_len = sreq->sr_sglist_len;
  615. cmd->underflow = sreq->sr_underflow;
  616. cmd->sc_request = sreq;
  617. memcpy(cmd->cmnd, sreq->sr_cmnd, sizeof(sreq->sr_cmnd));
  618. /*
  619. * Zero the sense buffer. Some host adapters automatically request
  620. * sense on error. 0 is not a valid sense code.
  621. */
  622. memset(cmd->sense_buffer, 0, sizeof(sreq->sr_sense_buffer));
  623. cmd->request_buffer = sreq->sr_buffer;
  624. cmd->request_bufflen = sreq->sr_bufflen;
  625. cmd->old_use_sg = cmd->use_sg;
  626. if (cmd->cmd_len == 0)
  627. cmd->cmd_len = COMMAND_SIZE(cmd->cmnd[0]);
  628. cmd->old_cmd_len = cmd->cmd_len;
  629. cmd->sc_old_data_direction = cmd->sc_data_direction;
  630. cmd->old_underflow = cmd->underflow;
  631. /*
  632. * Start the timer ticking.
  633. */
  634. cmd->result = 0;
  635. SCSI_LOG_MLQUEUE(3, printk("Leaving scsi_init_cmd_from_req()\n"));
  636. }
  637. /*
  638. * Per-CPU I/O completion queue.
  639. */
  640. static DEFINE_PER_CPU(struct list_head, scsi_done_q);
  641. /**
  642. * scsi_done - Enqueue the finished SCSI command into the done queue.
  643. * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
  644. * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
  645. *
  646. * This function is the mid-level's (SCSI Core) interrupt routine, which
  647. * regains ownership of the SCSI command (de facto) from a LLDD, and enqueues
  648. * the command to the done queue for further processing.
  649. *
  650. * This is the producer of the done queue who enqueues at the tail.
  651. *
  652. * This function is interrupt context safe.
  653. */
  654. static void scsi_done(struct scsi_cmnd *cmd)
  655. {
  656. /*
  657. * We don't have to worry about this one timing out any more.
  658. * If we are unable to remove the timer, then the command
  659. * has already timed out. In which case, we have no choice but to
  660. * let the timeout function run, as we have no idea where in fact
  661. * that function could really be. It might be on another processor,
  662. * etc, etc.
  663. */
  664. if (!scsi_delete_timer(cmd))
  665. return;
  666. __scsi_done(cmd);
  667. }
  668. /* Private entry to scsi_done() to complete a command when the timer
  669. * isn't running --- used by scsi_times_out */
  670. void __scsi_done(struct scsi_cmnd *cmd)
  671. {
  672. struct request *rq = cmd->request;
  673. /*
  674. * Set the serial numbers back to zero
  675. */
  676. cmd->serial_number = 0;
  677. atomic_inc(&cmd->device->iodone_cnt);
  678. if (cmd->result)
  679. atomic_inc(&cmd->device->ioerr_cnt);
  680. BUG_ON(!rq);
  681. /*
  682. * The uptodate/nbytes values don't matter, as we allow partial
  683. * completes and thus will check this in the softirq callback
  684. */
  685. rq->completion_data = cmd;
  686. blk_complete_request(rq);
  687. }
  688. /*
  689. * Function: scsi_retry_command
  690. *
  691. * Purpose: Send a command back to the low level to be retried.
  692. *
  693. * Notes: This command is always executed in the context of the
  694. * bottom half handler, or the error handler thread. Low
  695. * level drivers should not become re-entrant as a result of
  696. * this.
  697. */
  698. int scsi_retry_command(struct scsi_cmnd *cmd)
  699. {
  700. /*
  701. * Restore the SCSI command state.
  702. */
  703. scsi_setup_cmd_retry(cmd);
  704. /*
  705. * Zero the sense information from the last time we tried
  706. * this command.
  707. */
  708. memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
  709. return scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY);
  710. }
  711. /*
  712. * Function: scsi_finish_command
  713. *
  714. * Purpose: Pass command off to upper layer for finishing of I/O
  715. * request, waking processes that are waiting on results,
  716. * etc.
  717. */
  718. void scsi_finish_command(struct scsi_cmnd *cmd)
  719. {
  720. struct scsi_device *sdev = cmd->device;
  721. struct Scsi_Host *shost = sdev->host;
  722. struct scsi_request *sreq;
  723. scsi_device_unbusy(sdev);
  724. /*
  725. * Clear the flags which say that the device/host is no longer
  726. * capable of accepting new commands. These are set in scsi_queue.c
  727. * for both the queue full condition on a device, and for a
  728. * host full condition on the host.
  729. *
  730. * XXX(hch): What about locking?
  731. */
  732. shost->host_blocked = 0;
  733. sdev->device_blocked = 0;
  734. /*
  735. * If we have valid sense information, then some kind of recovery
  736. * must have taken place. Make a note of this.
  737. */
  738. if (SCSI_SENSE_VALID(cmd))
  739. cmd->result |= (DRIVER_SENSE << 24);
  740. SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev,
  741. "Notifying upper driver of completion "
  742. "(result %x)\n", cmd->result));
  743. /*
  744. * We can get here with use_sg=0, causing a panic in the upper level
  745. */
  746. cmd->use_sg = cmd->old_use_sg;
  747. /*
  748. * If there is an associated request structure, copy the data over
  749. * before we call the completion function.
  750. */
  751. sreq = cmd->sc_request;
  752. if (sreq) {
  753. sreq->sr_result = sreq->sr_command->result;
  754. if (sreq->sr_result) {
  755. memcpy(sreq->sr_sense_buffer,
  756. sreq->sr_command->sense_buffer,
  757. sizeof(sreq->sr_sense_buffer));
  758. }
  759. }
  760. cmd->done(cmd);
  761. }
  762. EXPORT_SYMBOL(scsi_finish_command);
  763. /*
  764. * Function: scsi_adjust_queue_depth()
  765. *
  766. * Purpose: Allow low level drivers to tell us to change the queue depth
  767. * on a specific SCSI device
  768. *
  769. * Arguments: sdev - SCSI Device in question
  770. * tagged - Do we use tagged queueing (non-0) or do we treat
  771. * this device as an untagged device (0)
  772. * tags - Number of tags allowed if tagged queueing enabled,
  773. * or number of commands the low level driver can
  774. * queue up in non-tagged mode (as per cmd_per_lun).
  775. *
  776. * Returns: Nothing
  777. *
  778. * Lock Status: None held on entry
  779. *
  780. * Notes: Low level drivers may call this at any time and we will do
  781. * the right thing depending on whether or not the device is
  782. * currently active and whether or not it even has the
  783. * command blocks built yet.
  784. */
  785. void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
  786. {
  787. unsigned long flags;
  788. /*
  789. * refuse to set tagged depth to an unworkable size
  790. */
  791. if (tags <= 0)
  792. return;
  793. spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
  794. /* Check to see if the queue is managed by the block layer
  795. * if it is, and we fail to adjust the depth, exit */
  796. if (blk_queue_tagged(sdev->request_queue) &&
  797. blk_queue_resize_tags(sdev->request_queue, tags) != 0)
  798. goto out;
  799. sdev->queue_depth = tags;
  800. switch (tagged) {
  801. case MSG_ORDERED_TAG:
  802. sdev->ordered_tags = 1;
  803. sdev->simple_tags = 1;
  804. break;
  805. case MSG_SIMPLE_TAG:
  806. sdev->ordered_tags = 0;
  807. sdev->simple_tags = 1;
  808. break;
  809. default:
  810. sdev_printk(KERN_WARNING, sdev,
  811. "scsi_adjust_queue_depth, bad queue type, "
  812. "disabled\n");
  813. case 0:
  814. sdev->ordered_tags = sdev->simple_tags = 0;
  815. sdev->queue_depth = tags;
  816. break;
  817. }
  818. out:
  819. spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
  820. }
  821. EXPORT_SYMBOL(scsi_adjust_queue_depth);
  822. /*
  823. * Function: scsi_track_queue_full()
  824. *
  825. * Purpose: This function will track successive QUEUE_FULL events on a
  826. * specific SCSI device to determine if and when there is a
  827. * need to adjust the queue depth on the device.
  828. *
  829. * Arguments: sdev - SCSI Device in question
  830. * depth - Current number of outstanding SCSI commands on
  831. * this device, not counting the one returned as
  832. * QUEUE_FULL.
  833. *
  834. * Returns: 0 - No change needed
  835. * >0 - Adjust queue depth to this new depth
  836. * -1 - Drop back to untagged operation using host->cmd_per_lun
  837. * as the untagged command depth
  838. *
  839. * Lock Status: None held on entry
  840. *
  841. * Notes: Low level drivers may call this at any time and we will do
  842. * "The Right Thing." We are interrupt context safe.
  843. */
  844. int scsi_track_queue_full(struct scsi_device *sdev, int depth)
  845. {
  846. if ((jiffies >> 4) == sdev->last_queue_full_time)
  847. return 0;
  848. sdev->last_queue_full_time = (jiffies >> 4);
  849. if (sdev->last_queue_full_depth != depth) {
  850. sdev->last_queue_full_count = 1;
  851. sdev->last_queue_full_depth = depth;
  852. } else {
  853. sdev->last_queue_full_count++;
  854. }
  855. if (sdev->last_queue_full_count <= 10)
  856. return 0;
  857. if (sdev->last_queue_full_depth < 8) {
  858. /* Drop back to untagged */
  859. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  860. return -1;
  861. }
  862. if (sdev->ordered_tags)
  863. scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
  864. else
  865. scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
  866. return depth;
  867. }
  868. EXPORT_SYMBOL(scsi_track_queue_full);
  869. /**
  870. * scsi_device_get - get an addition reference to a scsi_device
  871. * @sdev: device to get a reference to
  872. *
  873. * Gets a reference to the scsi_device and increments the use count
  874. * of the underlying LLDD module. You must hold host_lock of the
  875. * parent Scsi_Host or already have a reference when calling this.
  876. */
  877. int scsi_device_get(struct scsi_device *sdev)
  878. {
  879. if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL)
  880. return -ENXIO;
  881. if (!get_device(&sdev->sdev_gendev))
  882. return -ENXIO;
  883. if (!try_module_get(sdev->host->hostt->module)) {
  884. put_device(&sdev->sdev_gendev);
  885. return -ENXIO;
  886. }
  887. return 0;
  888. }
  889. EXPORT_SYMBOL(scsi_device_get);
  890. /**
  891. * scsi_device_put - release a reference to a scsi_device
  892. * @sdev: device to release a reference on.
  893. *
  894. * Release a reference to the scsi_device and decrements the use count
  895. * of the underlying LLDD module. The device is freed once the last
  896. * user vanishes.
  897. */
  898. void scsi_device_put(struct scsi_device *sdev)
  899. {
  900. module_put(sdev->host->hostt->module);
  901. put_device(&sdev->sdev_gendev);
  902. }
  903. EXPORT_SYMBOL(scsi_device_put);
  904. /* helper for shost_for_each_device, thus not documented */
  905. struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,
  906. struct scsi_device *prev)
  907. {
  908. struct list_head *list = (prev ? &prev->siblings : &shost->__devices);
  909. struct scsi_device *next = NULL;
  910. unsigned long flags;
  911. spin_lock_irqsave(shost->host_lock, flags);
  912. while (list->next != &shost->__devices) {
  913. next = list_entry(list->next, struct scsi_device, siblings);
  914. /* skip devices that we can't get a reference to */
  915. if (!scsi_device_get(next))
  916. break;
  917. next = NULL;
  918. list = list->next;
  919. }
  920. spin_unlock_irqrestore(shost->host_lock, flags);
  921. if (prev)
  922. scsi_device_put(prev);
  923. return next;
  924. }
  925. EXPORT_SYMBOL(__scsi_iterate_devices);
  926. /**
  927. * starget_for_each_device - helper to walk all devices of a target
  928. * @starget: target whose devices we want to iterate over.
  929. *
  930. * This traverses over each devices of @shost. The devices have
  931. * a reference that must be released by scsi_host_put when breaking
  932. * out of the loop.
  933. */
  934. void starget_for_each_device(struct scsi_target *starget, void * data,
  935. void (*fn)(struct scsi_device *, void *))
  936. {
  937. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  938. struct scsi_device *sdev;
  939. shost_for_each_device(sdev, shost) {
  940. if ((sdev->channel == starget->channel) &&
  941. (sdev->id == starget->id))
  942. fn(sdev, data);
  943. }
  944. }
  945. EXPORT_SYMBOL(starget_for_each_device);
  946. /**
  947. * __scsi_device_lookup_by_target - find a device given the target (UNLOCKED)
  948. * @starget: SCSI target pointer
  949. * @lun: SCSI Logical Unit Number
  950. *
  951. * Looks up the scsi_device with the specified @lun for a give
  952. * @starget. The returned scsi_device does not have an additional
  953. * reference. You must hold the host's host_lock over this call and
  954. * any access to the returned scsi_device.
  955. *
  956. * Note: The only reason why drivers would want to use this is because
  957. * they're need to access the device list in irq context. Otherwise you
  958. * really want to use scsi_device_lookup_by_target instead.
  959. **/
  960. struct scsi_device *__scsi_device_lookup_by_target(struct scsi_target *starget,
  961. uint lun)
  962. {
  963. struct scsi_device *sdev;
  964. list_for_each_entry(sdev, &starget->devices, same_target_siblings) {
  965. if (sdev->lun ==lun)
  966. return sdev;
  967. }
  968. return NULL;
  969. }
  970. EXPORT_SYMBOL(__scsi_device_lookup_by_target);
  971. /**
  972. * scsi_device_lookup_by_target - find a device given the target
  973. * @starget: SCSI target pointer
  974. * @lun: SCSI Logical Unit Number
  975. *
  976. * Looks up the scsi_device with the specified @channel, @id, @lun for a
  977. * give host. The returned scsi_device has an additional reference that
  978. * needs to be release with scsi_host_put once you're done with it.
  979. **/
  980. struct scsi_device *scsi_device_lookup_by_target(struct scsi_target *starget,
  981. uint lun)
  982. {
  983. struct scsi_device *sdev;
  984. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  985. unsigned long flags;
  986. spin_lock_irqsave(shost->host_lock, flags);
  987. sdev = __scsi_device_lookup_by_target(starget, lun);
  988. if (sdev && scsi_device_get(sdev))
  989. sdev = NULL;
  990. spin_unlock_irqrestore(shost->host_lock, flags);
  991. return sdev;
  992. }
  993. EXPORT_SYMBOL(scsi_device_lookup_by_target);
  994. /**
  995. * scsi_device_lookup - find a device given the host (UNLOCKED)
  996. * @shost: SCSI host pointer
  997. * @channel: SCSI channel (zero if only one channel)
  998. * @pun: SCSI target number (physical unit number)
  999. * @lun: SCSI Logical Unit Number
  1000. *
  1001. * Looks up the scsi_device with the specified @channel, @id, @lun for a
  1002. * give host. The returned scsi_device does not have an additional reference.
  1003. * You must hold the host's host_lock over this call and any access to the
  1004. * returned scsi_device.
  1005. *
  1006. * Note: The only reason why drivers would want to use this is because
  1007. * they're need to access the device list in irq context. Otherwise you
  1008. * really want to use scsi_device_lookup instead.
  1009. **/
  1010. struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
  1011. uint channel, uint id, uint lun)
  1012. {
  1013. struct scsi_device *sdev;
  1014. list_for_each_entry(sdev, &shost->__devices, siblings) {
  1015. if (sdev->channel == channel && sdev->id == id &&
  1016. sdev->lun ==lun)
  1017. return sdev;
  1018. }
  1019. return NULL;
  1020. }
  1021. EXPORT_SYMBOL(__scsi_device_lookup);
  1022. /**
  1023. * scsi_device_lookup - find a device given the host
  1024. * @shost: SCSI host pointer
  1025. * @channel: SCSI channel (zero if only one channel)
  1026. * @id: SCSI target number (physical unit number)
  1027. * @lun: SCSI Logical Unit Number
  1028. *
  1029. * Looks up the scsi_device with the specified @channel, @id, @lun for a
  1030. * give host. The returned scsi_device has an additional reference that
  1031. * needs to be release with scsi_host_put once you're done with it.
  1032. **/
  1033. struct scsi_device *scsi_device_lookup(struct Scsi_Host *shost,
  1034. uint channel, uint id, uint lun)
  1035. {
  1036. struct scsi_device *sdev;
  1037. unsigned long flags;
  1038. spin_lock_irqsave(shost->host_lock, flags);
  1039. sdev = __scsi_device_lookup(shost, channel, id, lun);
  1040. if (sdev && scsi_device_get(sdev))
  1041. sdev = NULL;
  1042. spin_unlock_irqrestore(shost->host_lock, flags);
  1043. return sdev;
  1044. }
  1045. EXPORT_SYMBOL(scsi_device_lookup);
  1046. /**
  1047. * scsi_device_cancel - cancel outstanding IO to this device
  1048. * @sdev: Pointer to struct scsi_device
  1049. * @recovery: Boolean instructing function to recover device or not.
  1050. *
  1051. **/
  1052. int scsi_device_cancel(struct scsi_device *sdev, int recovery)
  1053. {
  1054. struct scsi_cmnd *scmd;
  1055. LIST_HEAD(active_list);
  1056. struct list_head *lh, *lh_sf;
  1057. unsigned long flags;
  1058. scsi_device_set_state(sdev, SDEV_CANCEL);
  1059. spin_lock_irqsave(&sdev->list_lock, flags);
  1060. list_for_each_entry(scmd, &sdev->cmd_list, list) {
  1061. if (scmd->request && scmd->request->rq_status != RQ_INACTIVE) {
  1062. /*
  1063. * If we are unable to remove the timer, it means
  1064. * that the command has already timed out or
  1065. * finished.
  1066. */
  1067. if (!scsi_delete_timer(scmd))
  1068. continue;
  1069. list_add_tail(&scmd->eh_entry, &active_list);
  1070. }
  1071. }
  1072. spin_unlock_irqrestore(&sdev->list_lock, flags);
  1073. if (!list_empty(&active_list)) {
  1074. list_for_each_safe(lh, lh_sf, &active_list) {
  1075. scmd = list_entry(lh, struct scsi_cmnd, eh_entry);
  1076. list_del_init(lh);
  1077. if (recovery &&
  1078. !scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD)) {
  1079. scmd->result = (DID_ABORT << 16);
  1080. scsi_finish_command(scmd);
  1081. }
  1082. }
  1083. }
  1084. return 0;
  1085. }
  1086. EXPORT_SYMBOL(scsi_device_cancel);
  1087. MODULE_DESCRIPTION("SCSI core");
  1088. MODULE_LICENSE("GPL");
  1089. module_param(scsi_logging_level, int, S_IRUGO|S_IWUSR);
  1090. MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels");
  1091. static int __init init_scsi(void)
  1092. {
  1093. int error, i;
  1094. error = scsi_init_queue();
  1095. if (error)
  1096. return error;
  1097. error = scsi_init_procfs();
  1098. if (error)
  1099. goto cleanup_queue;
  1100. error = scsi_init_devinfo();
  1101. if (error)
  1102. goto cleanup_procfs;
  1103. error = scsi_init_hosts();
  1104. if (error)
  1105. goto cleanup_devlist;
  1106. error = scsi_init_sysctl();
  1107. if (error)
  1108. goto cleanup_hosts;
  1109. error = scsi_sysfs_register();
  1110. if (error)
  1111. goto cleanup_sysctl;
  1112. for_each_cpu(i)
  1113. INIT_LIST_HEAD(&per_cpu(scsi_done_q, i));
  1114. printk(KERN_NOTICE "SCSI subsystem initialized\n");
  1115. return 0;
  1116. cleanup_sysctl:
  1117. scsi_exit_sysctl();
  1118. cleanup_hosts:
  1119. scsi_exit_hosts();
  1120. cleanup_devlist:
  1121. scsi_exit_devinfo();
  1122. cleanup_procfs:
  1123. scsi_exit_procfs();
  1124. cleanup_queue:
  1125. scsi_exit_queue();
  1126. printk(KERN_ERR "SCSI subsystem failed to initialize, error = %d\n",
  1127. -error);
  1128. return error;
  1129. }
  1130. static void __exit exit_scsi(void)
  1131. {
  1132. scsi_sysfs_unregister();
  1133. scsi_exit_sysctl();
  1134. scsi_exit_hosts();
  1135. scsi_exit_devinfo();
  1136. scsi_exit_procfs();
  1137. scsi_exit_queue();
  1138. }
  1139. subsys_initcall(init_scsi);
  1140. module_exit(exit_scsi);