ibmvscsi.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. /* ------------------------------------------------------------
  2. * ibmvscsi.c
  3. * (C) Copyright IBM Corporation 1994, 2004
  4. * Authors: Colin DeVilbiss (devilbis@us.ibm.com)
  5. * Santiago Leon (santil@us.ibm.com)
  6. * Dave Boutcher (sleddog@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. * USA
  22. *
  23. * ------------------------------------------------------------
  24. * Emulation of a SCSI host adapter for Virtual I/O devices
  25. *
  26. * This driver supports the SCSI adapter implemented by the IBM
  27. * Power5 firmware. That SCSI adapter is not a physical adapter,
  28. * but allows Linux SCSI peripheral drivers to directly
  29. * access devices in another logical partition on the physical system.
  30. *
  31. * The virtual adapter(s) are present in the open firmware device
  32. * tree just like real adapters.
  33. *
  34. * One of the capabilities provided on these systems is the ability
  35. * to DMA between partitions. The architecture states that for VSCSI,
  36. * the server side is allowed to DMA to and from the client. The client
  37. * is never trusted to DMA to or from the server directly.
  38. *
  39. * Messages are sent between partitions on a "Command/Response Queue"
  40. * (CRQ), which is just a buffer of 16 byte entries in the receiver's
  41. * Senders cannot access the buffer directly, but send messages by
  42. * making a hypervisor call and passing in the 16 bytes. The hypervisor
  43. * puts the message in the next 16 byte space in round-robbin fashion,
  44. * turns on the high order bit of the message (the valid bit), and
  45. * generates an interrupt to the receiver (if interrupts are turned on.)
  46. * The receiver just turns off the valid bit when they have copied out
  47. * the message.
  48. *
  49. * The VSCSI client builds a SCSI Remote Protocol (SRP) Information Unit
  50. * (IU) (as defined in the T10 standard available at www.t10.org), gets
  51. * a DMA address for the message, and sends it to the server as the
  52. * payload of a CRQ message. The server DMAs the SRP IU and processes it,
  53. * including doing any additional data transfers. When it is done, it
  54. * DMAs the SRP response back to the same address as the request came from,
  55. * and sends a CRQ message back to inform the client that the request has
  56. * completed.
  57. *
  58. * Note that some of the underlying infrastructure is different between
  59. * machines conforming to the "RS/6000 Platform Architecture" (RPA) and
  60. * the older iSeries hypervisor models. To support both, some low level
  61. * routines have been broken out into rpa_vscsi.c and iseries_vscsi.c.
  62. * The Makefile should pick one, not two, not zero, of these.
  63. *
  64. * TODO: This is currently pretty tied to the IBM i/pSeries hypervisor
  65. * interfaces. It would be really nice to abstract this above an RDMA
  66. * layer.
  67. */
  68. #include <linux/module.h>
  69. #include <linux/moduleparam.h>
  70. #include <linux/dma-mapping.h>
  71. #include <linux/delay.h>
  72. #include <asm/vio.h>
  73. #include <scsi/scsi.h>
  74. #include <scsi/scsi_cmnd.h>
  75. #include <scsi/scsi_host.h>
  76. #include <scsi/scsi_device.h>
  77. #include <scsi/scsi_transport_srp.h>
  78. #include "ibmvscsi.h"
  79. /* The values below are somewhat arbitrary default values, but
  80. * OS/400 will use 3 busses (disks, CDs, tapes, I think.)
  81. * Note that there are 3 bits of channel value, 6 bits of id, and
  82. * 5 bits of LUN.
  83. */
  84. static int max_id = 64;
  85. static int max_channel = 3;
  86. static int init_timeout = 5;
  87. static int max_requests = IBMVSCSI_MAX_REQUESTS_DEFAULT;
  88. static struct scsi_transport_template *ibmvscsi_transport_template;
  89. #define IBMVSCSI_VERSION "1.5.8"
  90. MODULE_DESCRIPTION("IBM Virtual SCSI");
  91. MODULE_AUTHOR("Dave Boutcher");
  92. MODULE_LICENSE("GPL");
  93. MODULE_VERSION(IBMVSCSI_VERSION);
  94. module_param_named(max_id, max_id, int, S_IRUGO | S_IWUSR);
  95. MODULE_PARM_DESC(max_id, "Largest ID value for each channel");
  96. module_param_named(max_channel, max_channel, int, S_IRUGO | S_IWUSR);
  97. MODULE_PARM_DESC(max_channel, "Largest channel value");
  98. module_param_named(init_timeout, init_timeout, int, S_IRUGO | S_IWUSR);
  99. MODULE_PARM_DESC(init_timeout, "Initialization timeout in seconds");
  100. module_param_named(max_requests, max_requests, int, S_IRUGO | S_IWUSR);
  101. MODULE_PARM_DESC(max_requests, "Maximum requests for this adapter");
  102. /* ------------------------------------------------------------
  103. * Routines for the event pool and event structs
  104. */
  105. /**
  106. * initialize_event_pool: - Allocates and initializes the event pool for a host
  107. * @pool: event_pool to be initialized
  108. * @size: Number of events in pool
  109. * @hostdata: ibmvscsi_host_data who owns the event pool
  110. *
  111. * Returns zero on success.
  112. */
  113. static int initialize_event_pool(struct event_pool *pool,
  114. int size, struct ibmvscsi_host_data *hostdata)
  115. {
  116. int i;
  117. pool->size = size;
  118. pool->next = 0;
  119. pool->events = kcalloc(pool->size, sizeof(*pool->events), GFP_KERNEL);
  120. if (!pool->events)
  121. return -ENOMEM;
  122. pool->iu_storage =
  123. dma_alloc_coherent(hostdata->dev,
  124. pool->size * sizeof(*pool->iu_storage),
  125. &pool->iu_token, 0);
  126. if (!pool->iu_storage) {
  127. kfree(pool->events);
  128. return -ENOMEM;
  129. }
  130. for (i = 0; i < pool->size; ++i) {
  131. struct srp_event_struct *evt = &pool->events[i];
  132. memset(&evt->crq, 0x00, sizeof(evt->crq));
  133. atomic_set(&evt->free, 1);
  134. evt->crq.valid = 0x80;
  135. evt->crq.IU_length = sizeof(*evt->xfer_iu);
  136. evt->crq.IU_data_ptr = pool->iu_token +
  137. sizeof(*evt->xfer_iu) * i;
  138. evt->xfer_iu = pool->iu_storage + i;
  139. evt->hostdata = hostdata;
  140. evt->ext_list = NULL;
  141. evt->ext_list_token = 0;
  142. }
  143. return 0;
  144. }
  145. /**
  146. * release_event_pool: - Frees memory of an event pool of a host
  147. * @pool: event_pool to be released
  148. * @hostdata: ibmvscsi_host_data who owns the even pool
  149. *
  150. * Returns zero on success.
  151. */
  152. static void release_event_pool(struct event_pool *pool,
  153. struct ibmvscsi_host_data *hostdata)
  154. {
  155. int i, in_use = 0;
  156. for (i = 0; i < pool->size; ++i) {
  157. if (atomic_read(&pool->events[i].free) != 1)
  158. ++in_use;
  159. if (pool->events[i].ext_list) {
  160. dma_free_coherent(hostdata->dev,
  161. SG_ALL * sizeof(struct srp_direct_buf),
  162. pool->events[i].ext_list,
  163. pool->events[i].ext_list_token);
  164. }
  165. }
  166. if (in_use)
  167. dev_warn(hostdata->dev, "releasing event pool with %d "
  168. "events still in use?\n", in_use);
  169. kfree(pool->events);
  170. dma_free_coherent(hostdata->dev,
  171. pool->size * sizeof(*pool->iu_storage),
  172. pool->iu_storage, pool->iu_token);
  173. }
  174. /**
  175. * valid_event_struct: - Determines if event is valid.
  176. * @pool: event_pool that contains the event
  177. * @evt: srp_event_struct to be checked for validity
  178. *
  179. * Returns zero if event is invalid, one otherwise.
  180. */
  181. static int valid_event_struct(struct event_pool *pool,
  182. struct srp_event_struct *evt)
  183. {
  184. int index = evt - pool->events;
  185. if (index < 0 || index >= pool->size) /* outside of bounds */
  186. return 0;
  187. if (evt != pool->events + index) /* unaligned */
  188. return 0;
  189. return 1;
  190. }
  191. /**
  192. * ibmvscsi_free-event_struct: - Changes status of event to "free"
  193. * @pool: event_pool that contains the event
  194. * @evt: srp_event_struct to be modified
  195. *
  196. */
  197. static void free_event_struct(struct event_pool *pool,
  198. struct srp_event_struct *evt)
  199. {
  200. if (!valid_event_struct(pool, evt)) {
  201. dev_err(evt->hostdata->dev, "Freeing invalid event_struct %p "
  202. "(not in pool %p)\n", evt, pool->events);
  203. return;
  204. }
  205. if (atomic_inc_return(&evt->free) != 1) {
  206. dev_err(evt->hostdata->dev, "Freeing event_struct %p "
  207. "which is not in use!\n", evt);
  208. return;
  209. }
  210. }
  211. /**
  212. * get_evt_struct: - Gets the next free event in pool
  213. * @pool: event_pool that contains the events to be searched
  214. *
  215. * Returns the next event in "free" state, and NULL if none are free.
  216. * Note that no synchronization is done here, we assume the host_lock
  217. * will syncrhonze things.
  218. */
  219. static struct srp_event_struct *get_event_struct(struct event_pool *pool)
  220. {
  221. int i;
  222. int poolsize = pool->size;
  223. int offset = pool->next;
  224. for (i = 0; i < poolsize; i++) {
  225. offset = (offset + 1) % poolsize;
  226. if (!atomic_dec_if_positive(&pool->events[offset].free)) {
  227. pool->next = offset;
  228. return &pool->events[offset];
  229. }
  230. }
  231. printk(KERN_ERR "ibmvscsi: found no event struct in pool!\n");
  232. return NULL;
  233. }
  234. /**
  235. * init_event_struct: Initialize fields in an event struct that are always
  236. * required.
  237. * @evt: The event
  238. * @done: Routine to call when the event is responded to
  239. * @format: SRP or MAD format
  240. * @timeout: timeout value set in the CRQ
  241. */
  242. static void init_event_struct(struct srp_event_struct *evt_struct,
  243. void (*done) (struct srp_event_struct *),
  244. u8 format,
  245. int timeout)
  246. {
  247. evt_struct->cmnd = NULL;
  248. evt_struct->cmnd_done = NULL;
  249. evt_struct->sync_srp = NULL;
  250. evt_struct->crq.format = format;
  251. evt_struct->crq.timeout = timeout;
  252. evt_struct->done = done;
  253. }
  254. /* ------------------------------------------------------------
  255. * Routines for receiving SCSI responses from the hosting partition
  256. */
  257. /**
  258. * set_srp_direction: Set the fields in the srp related to data
  259. * direction and number of buffers based on the direction in
  260. * the scsi_cmnd and the number of buffers
  261. */
  262. static void set_srp_direction(struct scsi_cmnd *cmd,
  263. struct srp_cmd *srp_cmd,
  264. int numbuf)
  265. {
  266. u8 fmt;
  267. if (numbuf == 0)
  268. return;
  269. if (numbuf == 1)
  270. fmt = SRP_DATA_DESC_DIRECT;
  271. else {
  272. fmt = SRP_DATA_DESC_INDIRECT;
  273. numbuf = min(numbuf, MAX_INDIRECT_BUFS);
  274. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  275. srp_cmd->data_out_desc_cnt = numbuf;
  276. else
  277. srp_cmd->data_in_desc_cnt = numbuf;
  278. }
  279. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  280. srp_cmd->buf_fmt = fmt << 4;
  281. else
  282. srp_cmd->buf_fmt = fmt;
  283. }
  284. static void unmap_sg_list(int num_entries,
  285. struct device *dev,
  286. struct srp_direct_buf *md)
  287. {
  288. int i;
  289. for (i = 0; i < num_entries; ++i)
  290. dma_unmap_single(dev, md[i].va, md[i].len, DMA_BIDIRECTIONAL);
  291. }
  292. /**
  293. * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format
  294. * @cmd: srp_cmd whose additional_data member will be unmapped
  295. * @dev: device for which the memory is mapped
  296. *
  297. */
  298. static void unmap_cmd_data(struct srp_cmd *cmd,
  299. struct srp_event_struct *evt_struct,
  300. struct device *dev)
  301. {
  302. u8 out_fmt, in_fmt;
  303. out_fmt = cmd->buf_fmt >> 4;
  304. in_fmt = cmd->buf_fmt & ((1U << 4) - 1);
  305. if (out_fmt == SRP_NO_DATA_DESC && in_fmt == SRP_NO_DATA_DESC)
  306. return;
  307. else if (out_fmt == SRP_DATA_DESC_DIRECT ||
  308. in_fmt == SRP_DATA_DESC_DIRECT) {
  309. struct srp_direct_buf *data =
  310. (struct srp_direct_buf *) cmd->add_data;
  311. dma_unmap_single(dev, data->va, data->len, DMA_BIDIRECTIONAL);
  312. } else {
  313. struct srp_indirect_buf *indirect =
  314. (struct srp_indirect_buf *) cmd->add_data;
  315. int num_mapped = indirect->table_desc.len /
  316. sizeof(struct srp_direct_buf);
  317. if (num_mapped <= MAX_INDIRECT_BUFS) {
  318. unmap_sg_list(num_mapped, dev, &indirect->desc_list[0]);
  319. return;
  320. }
  321. unmap_sg_list(num_mapped, dev, evt_struct->ext_list);
  322. }
  323. }
  324. static int map_sg_list(struct scsi_cmnd *cmd, int nseg,
  325. struct srp_direct_buf *md)
  326. {
  327. int i;
  328. struct scatterlist *sg;
  329. u64 total_length = 0;
  330. scsi_for_each_sg(cmd, sg, nseg, i) {
  331. struct srp_direct_buf *descr = md + i;
  332. descr->va = sg_dma_address(sg);
  333. descr->len = sg_dma_len(sg);
  334. descr->key = 0;
  335. total_length += sg_dma_len(sg);
  336. }
  337. return total_length;
  338. }
  339. /**
  340. * map_sg_data: - Maps dma for a scatterlist and initializes decriptor fields
  341. * @cmd: Scsi_Cmnd with the scatterlist
  342. * @srp_cmd: srp_cmd that contains the memory descriptor
  343. * @dev: device for which to map dma memory
  344. *
  345. * Called by map_data_for_srp_cmd() when building srp cmd from scsi cmd.
  346. * Returns 1 on success.
  347. */
  348. static int map_sg_data(struct scsi_cmnd *cmd,
  349. struct srp_event_struct *evt_struct,
  350. struct srp_cmd *srp_cmd, struct device *dev)
  351. {
  352. int sg_mapped;
  353. u64 total_length = 0;
  354. struct srp_direct_buf *data =
  355. (struct srp_direct_buf *) srp_cmd->add_data;
  356. struct srp_indirect_buf *indirect =
  357. (struct srp_indirect_buf *) data;
  358. sg_mapped = scsi_dma_map(cmd);
  359. if (!sg_mapped)
  360. return 1;
  361. else if (sg_mapped < 0)
  362. return 0;
  363. set_srp_direction(cmd, srp_cmd, sg_mapped);
  364. /* special case; we can use a single direct descriptor */
  365. if (sg_mapped == 1) {
  366. map_sg_list(cmd, sg_mapped, data);
  367. return 1;
  368. }
  369. indirect->table_desc.va = 0;
  370. indirect->table_desc.len = sg_mapped * sizeof(struct srp_direct_buf);
  371. indirect->table_desc.key = 0;
  372. if (sg_mapped <= MAX_INDIRECT_BUFS) {
  373. total_length = map_sg_list(cmd, sg_mapped,
  374. &indirect->desc_list[0]);
  375. indirect->len = total_length;
  376. return 1;
  377. }
  378. /* get indirect table */
  379. if (!evt_struct->ext_list) {
  380. evt_struct->ext_list = (struct srp_direct_buf *)
  381. dma_alloc_coherent(dev,
  382. SG_ALL * sizeof(struct srp_direct_buf),
  383. &evt_struct->ext_list_token, 0);
  384. if (!evt_struct->ext_list) {
  385. sdev_printk(KERN_ERR, cmd->device,
  386. "Can't allocate memory for indirect table\n");
  387. return 0;
  388. }
  389. }
  390. total_length = map_sg_list(cmd, sg_mapped, evt_struct->ext_list);
  391. indirect->len = total_length;
  392. indirect->table_desc.va = evt_struct->ext_list_token;
  393. indirect->table_desc.len = sg_mapped * sizeof(indirect->desc_list[0]);
  394. memcpy(indirect->desc_list, evt_struct->ext_list,
  395. MAX_INDIRECT_BUFS * sizeof(struct srp_direct_buf));
  396. return 1;
  397. }
  398. /**
  399. * map_data_for_srp_cmd: - Calls functions to map data for srp cmds
  400. * @cmd: struct scsi_cmnd with the memory to be mapped
  401. * @srp_cmd: srp_cmd that contains the memory descriptor
  402. * @dev: dma device for which to map dma memory
  403. *
  404. * Called by scsi_cmd_to_srp_cmd() when converting scsi cmds to srp cmds
  405. * Returns 1 on success.
  406. */
  407. static int map_data_for_srp_cmd(struct scsi_cmnd *cmd,
  408. struct srp_event_struct *evt_struct,
  409. struct srp_cmd *srp_cmd, struct device *dev)
  410. {
  411. switch (cmd->sc_data_direction) {
  412. case DMA_FROM_DEVICE:
  413. case DMA_TO_DEVICE:
  414. break;
  415. case DMA_NONE:
  416. return 1;
  417. case DMA_BIDIRECTIONAL:
  418. sdev_printk(KERN_ERR, cmd->device,
  419. "Can't map DMA_BIDIRECTIONAL to read/write\n");
  420. return 0;
  421. default:
  422. sdev_printk(KERN_ERR, cmd->device,
  423. "Unknown data direction 0x%02x; can't map!\n",
  424. cmd->sc_data_direction);
  425. return 0;
  426. }
  427. return map_sg_data(cmd, evt_struct, srp_cmd, dev);
  428. }
  429. /**
  430. * purge_requests: Our virtual adapter just shut down. purge any sent requests
  431. * @hostdata: the adapter
  432. */
  433. static void purge_requests(struct ibmvscsi_host_data *hostdata, int error_code)
  434. {
  435. struct srp_event_struct *tmp_evt, *pos;
  436. unsigned long flags;
  437. spin_lock_irqsave(hostdata->host->host_lock, flags);
  438. list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) {
  439. list_del(&tmp_evt->list);
  440. del_timer(&tmp_evt->timer);
  441. if (tmp_evt->cmnd) {
  442. tmp_evt->cmnd->result = (error_code << 16);
  443. unmap_cmd_data(&tmp_evt->iu.srp.cmd,
  444. tmp_evt,
  445. tmp_evt->hostdata->dev);
  446. if (tmp_evt->cmnd_done)
  447. tmp_evt->cmnd_done(tmp_evt->cmnd);
  448. } else if (tmp_evt->done)
  449. tmp_evt->done(tmp_evt);
  450. free_event_struct(&tmp_evt->hostdata->pool, tmp_evt);
  451. }
  452. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  453. }
  454. /**
  455. * ibmvscsi_reset_host - Reset the connection to the server
  456. * @hostdata: struct ibmvscsi_host_data to reset
  457. */
  458. static void ibmvscsi_reset_host(struct ibmvscsi_host_data *hostdata)
  459. {
  460. scsi_block_requests(hostdata->host);
  461. atomic_set(&hostdata->request_limit, 0);
  462. purge_requests(hostdata, DID_ERROR);
  463. if ((ibmvscsi_reset_crq_queue(&hostdata->queue, hostdata)) ||
  464. (ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0)) ||
  465. (vio_enable_interrupts(to_vio_dev(hostdata->dev)))) {
  466. atomic_set(&hostdata->request_limit, -1);
  467. dev_err(hostdata->dev, "error after reset\n");
  468. }
  469. scsi_unblock_requests(hostdata->host);
  470. }
  471. /**
  472. * ibmvscsi_timeout - Internal command timeout handler
  473. * @evt_struct: struct srp_event_struct that timed out
  474. *
  475. * Called when an internally generated command times out
  476. */
  477. static void ibmvscsi_timeout(struct srp_event_struct *evt_struct)
  478. {
  479. struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
  480. dev_err(hostdata->dev, "Command timed out (%x). Resetting connection\n",
  481. evt_struct->iu.srp.cmd.opcode);
  482. ibmvscsi_reset_host(hostdata);
  483. }
  484. /* ------------------------------------------------------------
  485. * Routines for sending and receiving SRPs
  486. */
  487. /**
  488. * ibmvscsi_send_srp_event: - Transforms event to u64 array and calls send_crq()
  489. * @evt_struct: evt_struct to be sent
  490. * @hostdata: ibmvscsi_host_data of host
  491. * @timeout: timeout in seconds - 0 means do not time command
  492. *
  493. * Returns the value returned from ibmvscsi_send_crq(). (Zero for success)
  494. * Note that this routine assumes that host_lock is held for synchronization
  495. */
  496. static int ibmvscsi_send_srp_event(struct srp_event_struct *evt_struct,
  497. struct ibmvscsi_host_data *hostdata,
  498. unsigned long timeout)
  499. {
  500. u64 *crq_as_u64 = (u64 *) &evt_struct->crq;
  501. int request_status;
  502. int rc;
  503. /* If we have exhausted our request limit, just fail this request,
  504. * unless it is for a reset or abort.
  505. * Note that there are rare cases involving driver generated requests
  506. * (such as task management requests) that the mid layer may think we
  507. * can handle more requests (can_queue) when we actually can't
  508. */
  509. if (evt_struct->crq.format == VIOSRP_SRP_FORMAT) {
  510. request_status =
  511. atomic_dec_if_positive(&hostdata->request_limit);
  512. /* If request limit was -1 when we started, it is now even
  513. * less than that
  514. */
  515. if (request_status < -1)
  516. goto send_error;
  517. /* Otherwise, we may have run out of requests. */
  518. /* Abort and reset calls should make it through.
  519. * Nothing except abort and reset should use the last two
  520. * slots unless we had two or less to begin with.
  521. */
  522. else if (request_status < 2 &&
  523. evt_struct->iu.srp.cmd.opcode != SRP_TSK_MGMT) {
  524. /* In the case that we have less than two requests
  525. * available, check the server limit as a combination
  526. * of the request limit and the number of requests
  527. * in-flight (the size of the send list). If the
  528. * server limit is greater than 2, return busy so
  529. * that the last two are reserved for reset and abort.
  530. */
  531. int server_limit = request_status;
  532. struct srp_event_struct *tmp_evt;
  533. list_for_each_entry(tmp_evt, &hostdata->sent, list) {
  534. server_limit++;
  535. }
  536. if (server_limit > 2)
  537. goto send_busy;
  538. }
  539. }
  540. /* Copy the IU into the transfer area */
  541. *evt_struct->xfer_iu = evt_struct->iu;
  542. evt_struct->xfer_iu->srp.rsp.tag = (u64)evt_struct;
  543. /* Add this to the sent list. We need to do this
  544. * before we actually send
  545. * in case it comes back REALLY fast
  546. */
  547. list_add_tail(&evt_struct->list, &hostdata->sent);
  548. init_timer(&evt_struct->timer);
  549. if (timeout) {
  550. evt_struct->timer.data = (unsigned long) evt_struct;
  551. evt_struct->timer.expires = jiffies + (timeout * HZ);
  552. evt_struct->timer.function = (void (*)(unsigned long))ibmvscsi_timeout;
  553. add_timer(&evt_struct->timer);
  554. }
  555. if ((rc =
  556. ibmvscsi_send_crq(hostdata, crq_as_u64[0], crq_as_u64[1])) != 0) {
  557. list_del(&evt_struct->list);
  558. del_timer(&evt_struct->timer);
  559. dev_err(hostdata->dev, "send error %d\n", rc);
  560. atomic_inc(&hostdata->request_limit);
  561. goto send_error;
  562. }
  563. return 0;
  564. send_busy:
  565. unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
  566. free_event_struct(&hostdata->pool, evt_struct);
  567. atomic_inc(&hostdata->request_limit);
  568. return SCSI_MLQUEUE_HOST_BUSY;
  569. send_error:
  570. unmap_cmd_data(&evt_struct->iu.srp.cmd, evt_struct, hostdata->dev);
  571. if (evt_struct->cmnd != NULL) {
  572. evt_struct->cmnd->result = DID_ERROR << 16;
  573. evt_struct->cmnd_done(evt_struct->cmnd);
  574. } else if (evt_struct->done)
  575. evt_struct->done(evt_struct);
  576. free_event_struct(&hostdata->pool, evt_struct);
  577. return 0;
  578. }
  579. /**
  580. * handle_cmd_rsp: - Handle responses from commands
  581. * @evt_struct: srp_event_struct to be handled
  582. *
  583. * Used as a callback by when sending scsi cmds.
  584. * Gets called by ibmvscsi_handle_crq()
  585. */
  586. static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
  587. {
  588. struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp;
  589. struct scsi_cmnd *cmnd = evt_struct->cmnd;
  590. if (unlikely(rsp->opcode != SRP_RSP)) {
  591. if (printk_ratelimit())
  592. dev_warn(evt_struct->hostdata->dev,
  593. "bad SRP RSP type %d\n", rsp->opcode);
  594. }
  595. if (cmnd) {
  596. cmnd->result = rsp->status;
  597. if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
  598. memcpy(cmnd->sense_buffer,
  599. rsp->data,
  600. rsp->sense_data_len);
  601. unmap_cmd_data(&evt_struct->iu.srp.cmd,
  602. evt_struct,
  603. evt_struct->hostdata->dev);
  604. if (rsp->flags & SRP_RSP_FLAG_DOOVER)
  605. scsi_set_resid(cmnd, rsp->data_out_res_cnt);
  606. else if (rsp->flags & SRP_RSP_FLAG_DIOVER)
  607. scsi_set_resid(cmnd, rsp->data_in_res_cnt);
  608. }
  609. if (evt_struct->cmnd_done)
  610. evt_struct->cmnd_done(cmnd);
  611. }
  612. /**
  613. * lun_from_dev: - Returns the lun of the scsi device
  614. * @dev: struct scsi_device
  615. *
  616. */
  617. static inline u16 lun_from_dev(struct scsi_device *dev)
  618. {
  619. return (0x2 << 14) | (dev->id << 8) | (dev->channel << 5) | dev->lun;
  620. }
  621. /**
  622. * ibmvscsi_queue: - The queuecommand function of the scsi template
  623. * @cmd: struct scsi_cmnd to be executed
  624. * @done: Callback function to be called when cmd is completed
  625. */
  626. static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
  627. void (*done) (struct scsi_cmnd *))
  628. {
  629. struct srp_cmd *srp_cmd;
  630. struct srp_event_struct *evt_struct;
  631. struct srp_indirect_buf *indirect;
  632. struct ibmvscsi_host_data *hostdata = shost_priv(cmnd->device->host);
  633. u16 lun = lun_from_dev(cmnd->device);
  634. u8 out_fmt, in_fmt;
  635. evt_struct = get_event_struct(&hostdata->pool);
  636. if (!evt_struct)
  637. return SCSI_MLQUEUE_HOST_BUSY;
  638. /* Set up the actual SRP IU */
  639. srp_cmd = &evt_struct->iu.srp.cmd;
  640. memset(srp_cmd, 0x00, SRP_MAX_IU_LEN);
  641. srp_cmd->opcode = SRP_CMD;
  642. memcpy(srp_cmd->cdb, cmnd->cmnd, sizeof(cmnd->cmnd));
  643. srp_cmd->lun = ((u64) lun) << 48;
  644. if (!map_data_for_srp_cmd(cmnd, evt_struct, srp_cmd, hostdata->dev)) {
  645. sdev_printk(KERN_ERR, cmnd->device, "couldn't convert cmd to srp_cmd\n");
  646. free_event_struct(&hostdata->pool, evt_struct);
  647. return SCSI_MLQUEUE_HOST_BUSY;
  648. }
  649. init_event_struct(evt_struct,
  650. handle_cmd_rsp,
  651. VIOSRP_SRP_FORMAT,
  652. cmnd->timeout_per_command/HZ);
  653. evt_struct->cmnd = cmnd;
  654. evt_struct->cmnd_done = done;
  655. /* Fix up dma address of the buffer itself */
  656. indirect = (struct srp_indirect_buf *) srp_cmd->add_data;
  657. out_fmt = srp_cmd->buf_fmt >> 4;
  658. in_fmt = srp_cmd->buf_fmt & ((1U << 4) - 1);
  659. if ((in_fmt == SRP_DATA_DESC_INDIRECT ||
  660. out_fmt == SRP_DATA_DESC_INDIRECT) &&
  661. indirect->table_desc.va == 0) {
  662. indirect->table_desc.va = evt_struct->crq.IU_data_ptr +
  663. offsetof(struct srp_cmd, add_data) +
  664. offsetof(struct srp_indirect_buf, desc_list);
  665. }
  666. return ibmvscsi_send_srp_event(evt_struct, hostdata, 0);
  667. }
  668. /* ------------------------------------------------------------
  669. * Routines for driver initialization
  670. */
  671. /**
  672. * adapter_info_rsp: - Handle response to MAD adapter info request
  673. * @evt_struct: srp_event_struct with the response
  674. *
  675. * Used as a "done" callback by when sending adapter_info. Gets called
  676. * by ibmvscsi_handle_crq()
  677. */
  678. static void adapter_info_rsp(struct srp_event_struct *evt_struct)
  679. {
  680. struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
  681. dma_unmap_single(hostdata->dev,
  682. evt_struct->iu.mad.adapter_info.buffer,
  683. evt_struct->iu.mad.adapter_info.common.length,
  684. DMA_BIDIRECTIONAL);
  685. if (evt_struct->xfer_iu->mad.adapter_info.common.status) {
  686. dev_err(hostdata->dev, "error %d getting adapter info\n",
  687. evt_struct->xfer_iu->mad.adapter_info.common.status);
  688. } else {
  689. dev_info(hostdata->dev, "host srp version: %s, "
  690. "host partition %s (%d), OS %d, max io %u\n",
  691. hostdata->madapter_info.srp_version,
  692. hostdata->madapter_info.partition_name,
  693. hostdata->madapter_info.partition_number,
  694. hostdata->madapter_info.os_type,
  695. hostdata->madapter_info.port_max_txu[0]);
  696. if (hostdata->madapter_info.port_max_txu[0])
  697. hostdata->host->max_sectors =
  698. hostdata->madapter_info.port_max_txu[0] >> 9;
  699. if (hostdata->madapter_info.os_type == 3 &&
  700. strcmp(hostdata->madapter_info.srp_version, "1.6a") <= 0) {
  701. dev_err(hostdata->dev, "host (Ver. %s) doesn't support large transfers\n",
  702. hostdata->madapter_info.srp_version);
  703. dev_err(hostdata->dev, "limiting scatterlists to %d\n",
  704. MAX_INDIRECT_BUFS);
  705. hostdata->host->sg_tablesize = MAX_INDIRECT_BUFS;
  706. }
  707. }
  708. }
  709. /**
  710. * send_mad_adapter_info: - Sends the mad adapter info request
  711. * and stores the result so it can be retrieved with
  712. * sysfs. We COULD consider causing a failure if the
  713. * returned SRP version doesn't match ours.
  714. * @hostdata: ibmvscsi_host_data of host
  715. *
  716. * Returns zero if successful.
  717. */
  718. static void send_mad_adapter_info(struct ibmvscsi_host_data *hostdata)
  719. {
  720. struct viosrp_adapter_info *req;
  721. struct srp_event_struct *evt_struct;
  722. unsigned long flags;
  723. dma_addr_t addr;
  724. evt_struct = get_event_struct(&hostdata->pool);
  725. if (!evt_struct) {
  726. dev_err(hostdata->dev,
  727. "couldn't allocate an event for ADAPTER_INFO_REQ!\n");
  728. return;
  729. }
  730. init_event_struct(evt_struct,
  731. adapter_info_rsp,
  732. VIOSRP_MAD_FORMAT,
  733. init_timeout);
  734. req = &evt_struct->iu.mad.adapter_info;
  735. memset(req, 0x00, sizeof(*req));
  736. req->common.type = VIOSRP_ADAPTER_INFO_TYPE;
  737. req->common.length = sizeof(hostdata->madapter_info);
  738. req->buffer = addr = dma_map_single(hostdata->dev,
  739. &hostdata->madapter_info,
  740. sizeof(hostdata->madapter_info),
  741. DMA_BIDIRECTIONAL);
  742. if (dma_mapping_error(req->buffer)) {
  743. dev_err(hostdata->dev, "Unable to map request_buffer for adapter_info!\n");
  744. free_event_struct(&hostdata->pool, evt_struct);
  745. return;
  746. }
  747. spin_lock_irqsave(hostdata->host->host_lock, flags);
  748. if (ibmvscsi_send_srp_event(evt_struct, hostdata, init_timeout * 2)) {
  749. dev_err(hostdata->dev, "couldn't send ADAPTER_INFO_REQ!\n");
  750. dma_unmap_single(hostdata->dev,
  751. addr,
  752. sizeof(hostdata->madapter_info),
  753. DMA_BIDIRECTIONAL);
  754. }
  755. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  756. };
  757. /**
  758. * login_rsp: - Handle response to SRP login request
  759. * @evt_struct: srp_event_struct with the response
  760. *
  761. * Used as a "done" callback by when sending srp_login. Gets called
  762. * by ibmvscsi_handle_crq()
  763. */
  764. static void login_rsp(struct srp_event_struct *evt_struct)
  765. {
  766. struct ibmvscsi_host_data *hostdata = evt_struct->hostdata;
  767. switch (evt_struct->xfer_iu->srp.login_rsp.opcode) {
  768. case SRP_LOGIN_RSP: /* it worked! */
  769. break;
  770. case SRP_LOGIN_REJ: /* refused! */
  771. dev_info(hostdata->dev, "SRP_LOGIN_REJ reason %u\n",
  772. evt_struct->xfer_iu->srp.login_rej.reason);
  773. /* Login failed. */
  774. atomic_set(&hostdata->request_limit, -1);
  775. return;
  776. default:
  777. dev_err(hostdata->dev, "Invalid login response typecode 0x%02x!\n",
  778. evt_struct->xfer_iu->srp.login_rsp.opcode);
  779. /* Login failed. */
  780. atomic_set(&hostdata->request_limit, -1);
  781. return;
  782. }
  783. dev_info(hostdata->dev, "SRP_LOGIN succeeded\n");
  784. if (evt_struct->xfer_iu->srp.login_rsp.req_lim_delta < 0)
  785. dev_err(hostdata->dev, "Invalid request_limit.\n");
  786. /* Now we know what the real request-limit is.
  787. * This value is set rather than added to request_limit because
  788. * request_limit could have been set to -1 by this client.
  789. */
  790. atomic_set(&hostdata->request_limit,
  791. evt_struct->xfer_iu->srp.login_rsp.req_lim_delta);
  792. /* If we had any pending I/Os, kick them */
  793. scsi_unblock_requests(hostdata->host);
  794. send_mad_adapter_info(hostdata);
  795. return;
  796. }
  797. /**
  798. * send_srp_login: - Sends the srp login
  799. * @hostdata: ibmvscsi_host_data of host
  800. *
  801. * Returns zero if successful.
  802. */
  803. static int send_srp_login(struct ibmvscsi_host_data *hostdata)
  804. {
  805. int rc;
  806. unsigned long flags;
  807. struct srp_login_req *login;
  808. struct srp_event_struct *evt_struct = get_event_struct(&hostdata->pool);
  809. if (!evt_struct) {
  810. dev_err(hostdata->dev, "couldn't allocate an event for login req!\n");
  811. return FAILED;
  812. }
  813. init_event_struct(evt_struct,
  814. login_rsp,
  815. VIOSRP_SRP_FORMAT,
  816. init_timeout);
  817. login = &evt_struct->iu.srp.login_req;
  818. memset(login, 0x00, sizeof(struct srp_login_req));
  819. login->opcode = SRP_LOGIN_REQ;
  820. login->req_it_iu_len = sizeof(union srp_iu);
  821. login->req_buf_fmt = SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT;
  822. spin_lock_irqsave(hostdata->host->host_lock, flags);
  823. /* Start out with a request limit of 1, since this is negotiated in
  824. * the login request we are just sending
  825. */
  826. atomic_set(&hostdata->request_limit, 1);
  827. rc = ibmvscsi_send_srp_event(evt_struct, hostdata, init_timeout * 2);
  828. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  829. dev_info(hostdata->dev, "sent SRP login\n");
  830. return rc;
  831. };
  832. /**
  833. * sync_completion: Signal that a synchronous command has completed
  834. * Note that after returning from this call, the evt_struct is freed.
  835. * the caller waiting on this completion shouldn't touch the evt_struct
  836. * again.
  837. */
  838. static void sync_completion(struct srp_event_struct *evt_struct)
  839. {
  840. /* copy the response back */
  841. if (evt_struct->sync_srp)
  842. *evt_struct->sync_srp = *evt_struct->xfer_iu;
  843. complete(&evt_struct->comp);
  844. }
  845. /**
  846. * ibmvscsi_abort: Abort a command...from scsi host template
  847. * send this over to the server and wait synchronously for the response
  848. */
  849. static int ibmvscsi_eh_abort_handler(struct scsi_cmnd *cmd)
  850. {
  851. struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
  852. struct srp_tsk_mgmt *tsk_mgmt;
  853. struct srp_event_struct *evt;
  854. struct srp_event_struct *tmp_evt, *found_evt;
  855. union viosrp_iu srp_rsp;
  856. int rsp_rc;
  857. unsigned long flags;
  858. u16 lun = lun_from_dev(cmd->device);
  859. /* First, find this command in our sent list so we can figure
  860. * out the correct tag
  861. */
  862. spin_lock_irqsave(hostdata->host->host_lock, flags);
  863. found_evt = NULL;
  864. list_for_each_entry(tmp_evt, &hostdata->sent, list) {
  865. if (tmp_evt->cmnd == cmd) {
  866. found_evt = tmp_evt;
  867. break;
  868. }
  869. }
  870. if (!found_evt) {
  871. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  872. return SUCCESS;
  873. }
  874. evt = get_event_struct(&hostdata->pool);
  875. if (evt == NULL) {
  876. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  877. sdev_printk(KERN_ERR, cmd->device, "failed to allocate abort event\n");
  878. return FAILED;
  879. }
  880. init_event_struct(evt,
  881. sync_completion,
  882. VIOSRP_SRP_FORMAT,
  883. init_timeout);
  884. tsk_mgmt = &evt->iu.srp.tsk_mgmt;
  885. /* Set up an abort SRP command */
  886. memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
  887. tsk_mgmt->opcode = SRP_TSK_MGMT;
  888. tsk_mgmt->lun = ((u64) lun) << 48;
  889. tsk_mgmt->tsk_mgmt_func = SRP_TSK_ABORT_TASK;
  890. tsk_mgmt->task_tag = (u64) found_evt;
  891. sdev_printk(KERN_INFO, cmd->device, "aborting command. lun 0x%lx, tag 0x%lx\n",
  892. tsk_mgmt->lun, tsk_mgmt->task_tag);
  893. evt->sync_srp = &srp_rsp;
  894. init_completion(&evt->comp);
  895. rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, init_timeout * 2);
  896. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  897. if (rsp_rc != 0) {
  898. sdev_printk(KERN_ERR, cmd->device,
  899. "failed to send abort() event. rc=%d\n", rsp_rc);
  900. return FAILED;
  901. }
  902. wait_for_completion(&evt->comp);
  903. /* make sure we got a good response */
  904. if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
  905. if (printk_ratelimit())
  906. sdev_printk(KERN_WARNING, cmd->device, "abort bad SRP RSP type %d\n",
  907. srp_rsp.srp.rsp.opcode);
  908. return FAILED;
  909. }
  910. if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
  911. rsp_rc = *((int *)srp_rsp.srp.rsp.data);
  912. else
  913. rsp_rc = srp_rsp.srp.rsp.status;
  914. if (rsp_rc) {
  915. if (printk_ratelimit())
  916. sdev_printk(KERN_WARNING, cmd->device,
  917. "abort code %d for task tag 0x%lx\n",
  918. rsp_rc, tsk_mgmt->task_tag);
  919. return FAILED;
  920. }
  921. /* Because we dropped the spinlock above, it's possible
  922. * The event is no longer in our list. Make sure it didn't
  923. * complete while we were aborting
  924. */
  925. spin_lock_irqsave(hostdata->host->host_lock, flags);
  926. found_evt = NULL;
  927. list_for_each_entry(tmp_evt, &hostdata->sent, list) {
  928. if (tmp_evt->cmnd == cmd) {
  929. found_evt = tmp_evt;
  930. break;
  931. }
  932. }
  933. if (found_evt == NULL) {
  934. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  935. sdev_printk(KERN_INFO, cmd->device, "aborted task tag 0x%lx completed\n",
  936. tsk_mgmt->task_tag);
  937. return SUCCESS;
  938. }
  939. sdev_printk(KERN_INFO, cmd->device, "successfully aborted task tag 0x%lx\n",
  940. tsk_mgmt->task_tag);
  941. cmd->result = (DID_ABORT << 16);
  942. list_del(&found_evt->list);
  943. unmap_cmd_data(&found_evt->iu.srp.cmd, found_evt,
  944. found_evt->hostdata->dev);
  945. free_event_struct(&found_evt->hostdata->pool, found_evt);
  946. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  947. atomic_inc(&hostdata->request_limit);
  948. return SUCCESS;
  949. }
  950. /**
  951. * ibmvscsi_eh_device_reset_handler: Reset a single LUN...from scsi host
  952. * template send this over to the server and wait synchronously for the
  953. * response
  954. */
  955. static int ibmvscsi_eh_device_reset_handler(struct scsi_cmnd *cmd)
  956. {
  957. struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
  958. struct srp_tsk_mgmt *tsk_mgmt;
  959. struct srp_event_struct *evt;
  960. struct srp_event_struct *tmp_evt, *pos;
  961. union viosrp_iu srp_rsp;
  962. int rsp_rc;
  963. unsigned long flags;
  964. u16 lun = lun_from_dev(cmd->device);
  965. spin_lock_irqsave(hostdata->host->host_lock, flags);
  966. evt = get_event_struct(&hostdata->pool);
  967. if (evt == NULL) {
  968. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  969. sdev_printk(KERN_ERR, cmd->device, "failed to allocate reset event\n");
  970. return FAILED;
  971. }
  972. init_event_struct(evt,
  973. sync_completion,
  974. VIOSRP_SRP_FORMAT,
  975. init_timeout);
  976. tsk_mgmt = &evt->iu.srp.tsk_mgmt;
  977. /* Set up a lun reset SRP command */
  978. memset(tsk_mgmt, 0x00, sizeof(*tsk_mgmt));
  979. tsk_mgmt->opcode = SRP_TSK_MGMT;
  980. tsk_mgmt->lun = ((u64) lun) << 48;
  981. tsk_mgmt->tsk_mgmt_func = SRP_TSK_LUN_RESET;
  982. sdev_printk(KERN_INFO, cmd->device, "resetting device. lun 0x%lx\n",
  983. tsk_mgmt->lun);
  984. evt->sync_srp = &srp_rsp;
  985. init_completion(&evt->comp);
  986. rsp_rc = ibmvscsi_send_srp_event(evt, hostdata, init_timeout * 2);
  987. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  988. if (rsp_rc != 0) {
  989. sdev_printk(KERN_ERR, cmd->device,
  990. "failed to send reset event. rc=%d\n", rsp_rc);
  991. return FAILED;
  992. }
  993. wait_for_completion(&evt->comp);
  994. /* make sure we got a good response */
  995. if (unlikely(srp_rsp.srp.rsp.opcode != SRP_RSP)) {
  996. if (printk_ratelimit())
  997. sdev_printk(KERN_WARNING, cmd->device, "reset bad SRP RSP type %d\n",
  998. srp_rsp.srp.rsp.opcode);
  999. return FAILED;
  1000. }
  1001. if (srp_rsp.srp.rsp.flags & SRP_RSP_FLAG_RSPVALID)
  1002. rsp_rc = *((int *)srp_rsp.srp.rsp.data);
  1003. else
  1004. rsp_rc = srp_rsp.srp.rsp.status;
  1005. if (rsp_rc) {
  1006. if (printk_ratelimit())
  1007. sdev_printk(KERN_WARNING, cmd->device,
  1008. "reset code %d for task tag 0x%lx\n",
  1009. rsp_rc, tsk_mgmt->task_tag);
  1010. return FAILED;
  1011. }
  1012. /* We need to find all commands for this LUN that have not yet been
  1013. * responded to, and fail them with DID_RESET
  1014. */
  1015. spin_lock_irqsave(hostdata->host->host_lock, flags);
  1016. list_for_each_entry_safe(tmp_evt, pos, &hostdata->sent, list) {
  1017. if ((tmp_evt->cmnd) && (tmp_evt->cmnd->device == cmd->device)) {
  1018. if (tmp_evt->cmnd)
  1019. tmp_evt->cmnd->result = (DID_RESET << 16);
  1020. list_del(&tmp_evt->list);
  1021. unmap_cmd_data(&tmp_evt->iu.srp.cmd, tmp_evt,
  1022. tmp_evt->hostdata->dev);
  1023. free_event_struct(&tmp_evt->hostdata->pool,
  1024. tmp_evt);
  1025. atomic_inc(&hostdata->request_limit);
  1026. if (tmp_evt->cmnd_done)
  1027. tmp_evt->cmnd_done(tmp_evt->cmnd);
  1028. else if (tmp_evt->done)
  1029. tmp_evt->done(tmp_evt);
  1030. }
  1031. }
  1032. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  1033. return SUCCESS;
  1034. }
  1035. /**
  1036. * ibmvscsi_eh_host_reset_handler - Reset the connection to the server
  1037. * @cmd: struct scsi_cmnd having problems
  1038. */
  1039. static int ibmvscsi_eh_host_reset_handler(struct scsi_cmnd *cmd)
  1040. {
  1041. unsigned long wait_switch = 0;
  1042. struct ibmvscsi_host_data *hostdata = shost_priv(cmd->device->host);
  1043. dev_err(hostdata->dev, "Resetting connection due to error recovery\n");
  1044. ibmvscsi_reset_host(hostdata);
  1045. for (wait_switch = jiffies + (init_timeout * HZ);
  1046. time_before(jiffies, wait_switch) &&
  1047. atomic_read(&hostdata->request_limit) < 2;) {
  1048. msleep(10);
  1049. }
  1050. if (atomic_read(&hostdata->request_limit) <= 0)
  1051. return FAILED;
  1052. return SUCCESS;
  1053. }
  1054. /**
  1055. * ibmvscsi_handle_crq: - Handles and frees received events in the CRQ
  1056. * @crq: Command/Response queue
  1057. * @hostdata: ibmvscsi_host_data of host
  1058. *
  1059. */
  1060. void ibmvscsi_handle_crq(struct viosrp_crq *crq,
  1061. struct ibmvscsi_host_data *hostdata)
  1062. {
  1063. long rc;
  1064. unsigned long flags;
  1065. struct srp_event_struct *evt_struct =
  1066. (struct srp_event_struct *)crq->IU_data_ptr;
  1067. switch (crq->valid) {
  1068. case 0xC0: /* initialization */
  1069. switch (crq->format) {
  1070. case 0x01: /* Initialization message */
  1071. dev_info(hostdata->dev, "partner initialized\n");
  1072. /* Send back a response */
  1073. if ((rc = ibmvscsi_send_crq(hostdata,
  1074. 0xC002000000000000LL, 0)) == 0) {
  1075. /* Now login */
  1076. send_srp_login(hostdata);
  1077. } else {
  1078. dev_err(hostdata->dev, "Unable to send init rsp. rc=%ld\n", rc);
  1079. }
  1080. break;
  1081. case 0x02: /* Initialization response */
  1082. dev_info(hostdata->dev, "partner initialization complete\n");
  1083. /* Now login */
  1084. send_srp_login(hostdata);
  1085. break;
  1086. default:
  1087. dev_err(hostdata->dev, "unknown crq message type: %d\n", crq->format);
  1088. }
  1089. return;
  1090. case 0xFF: /* Hypervisor telling us the connection is closed */
  1091. scsi_block_requests(hostdata->host);
  1092. atomic_set(&hostdata->request_limit, 0);
  1093. if (crq->format == 0x06) {
  1094. /* We need to re-setup the interpartition connection */
  1095. dev_info(hostdata->dev, "Re-enabling adapter!\n");
  1096. purge_requests(hostdata, DID_REQUEUE);
  1097. if ((ibmvscsi_reenable_crq_queue(&hostdata->queue,
  1098. hostdata)) ||
  1099. (ibmvscsi_send_crq(hostdata,
  1100. 0xC001000000000000LL, 0))) {
  1101. atomic_set(&hostdata->request_limit,
  1102. -1);
  1103. dev_err(hostdata->dev, "error after enable\n");
  1104. }
  1105. } else {
  1106. dev_err(hostdata->dev, "Virtual adapter failed rc %d!\n",
  1107. crq->format);
  1108. purge_requests(hostdata, DID_ERROR);
  1109. if ((ibmvscsi_reset_crq_queue(&hostdata->queue,
  1110. hostdata)) ||
  1111. (ibmvscsi_send_crq(hostdata,
  1112. 0xC001000000000000LL, 0))) {
  1113. atomic_set(&hostdata->request_limit,
  1114. -1);
  1115. dev_err(hostdata->dev, "error after reset\n");
  1116. }
  1117. }
  1118. scsi_unblock_requests(hostdata->host);
  1119. return;
  1120. case 0x80: /* real payload */
  1121. break;
  1122. default:
  1123. dev_err(hostdata->dev, "got an invalid message type 0x%02x\n",
  1124. crq->valid);
  1125. return;
  1126. }
  1127. /* The only kind of payload CRQs we should get are responses to
  1128. * things we send. Make sure this response is to something we
  1129. * actually sent
  1130. */
  1131. if (!valid_event_struct(&hostdata->pool, evt_struct)) {
  1132. dev_err(hostdata->dev, "returned correlation_token 0x%p is invalid!\n",
  1133. (void *)crq->IU_data_ptr);
  1134. return;
  1135. }
  1136. if (atomic_read(&evt_struct->free)) {
  1137. dev_err(hostdata->dev, "received duplicate correlation_token 0x%p!\n",
  1138. (void *)crq->IU_data_ptr);
  1139. return;
  1140. }
  1141. if (crq->format == VIOSRP_SRP_FORMAT)
  1142. atomic_add(evt_struct->xfer_iu->srp.rsp.req_lim_delta,
  1143. &hostdata->request_limit);
  1144. del_timer(&evt_struct->timer);
  1145. if (evt_struct->done)
  1146. evt_struct->done(evt_struct);
  1147. else
  1148. dev_err(hostdata->dev, "returned done() is NULL; not running it!\n");
  1149. /*
  1150. * Lock the host_lock before messing with these structures, since we
  1151. * are running in a task context
  1152. */
  1153. spin_lock_irqsave(evt_struct->hostdata->host->host_lock, flags);
  1154. list_del(&evt_struct->list);
  1155. free_event_struct(&evt_struct->hostdata->pool, evt_struct);
  1156. spin_unlock_irqrestore(evt_struct->hostdata->host->host_lock, flags);
  1157. }
  1158. /**
  1159. * ibmvscsi_get_host_config: Send the command to the server to get host
  1160. * configuration data. The data is opaque to us.
  1161. */
  1162. static int ibmvscsi_do_host_config(struct ibmvscsi_host_data *hostdata,
  1163. unsigned char *buffer, int length)
  1164. {
  1165. struct viosrp_host_config *host_config;
  1166. struct srp_event_struct *evt_struct;
  1167. unsigned long flags;
  1168. dma_addr_t addr;
  1169. int rc;
  1170. evt_struct = get_event_struct(&hostdata->pool);
  1171. if (!evt_struct) {
  1172. dev_err(hostdata->dev, "couldn't allocate event for HOST_CONFIG!\n");
  1173. return -1;
  1174. }
  1175. init_event_struct(evt_struct,
  1176. sync_completion,
  1177. VIOSRP_MAD_FORMAT,
  1178. init_timeout);
  1179. host_config = &evt_struct->iu.mad.host_config;
  1180. /* Set up a lun reset SRP command */
  1181. memset(host_config, 0x00, sizeof(*host_config));
  1182. host_config->common.type = VIOSRP_HOST_CONFIG_TYPE;
  1183. host_config->common.length = length;
  1184. host_config->buffer = addr = dma_map_single(hostdata->dev, buffer,
  1185. length,
  1186. DMA_BIDIRECTIONAL);
  1187. if (dma_mapping_error(host_config->buffer)) {
  1188. dev_err(hostdata->dev, "dma_mapping error getting host config\n");
  1189. free_event_struct(&hostdata->pool, evt_struct);
  1190. return -1;
  1191. }
  1192. init_completion(&evt_struct->comp);
  1193. spin_lock_irqsave(hostdata->host->host_lock, flags);
  1194. rc = ibmvscsi_send_srp_event(evt_struct, hostdata, init_timeout * 2);
  1195. spin_unlock_irqrestore(hostdata->host->host_lock, flags);
  1196. if (rc == 0)
  1197. wait_for_completion(&evt_struct->comp);
  1198. dma_unmap_single(hostdata->dev, addr, length, DMA_BIDIRECTIONAL);
  1199. return rc;
  1200. }
  1201. /**
  1202. * ibmvscsi_slave_configure: Set the "allow_restart" flag for each disk.
  1203. * @sdev: struct scsi_device device to configure
  1204. *
  1205. * Enable allow_restart for a device if it is a disk. Adjust the
  1206. * queue_depth here also as is required by the documentation for
  1207. * struct scsi_host_template.
  1208. */
  1209. static int ibmvscsi_slave_configure(struct scsi_device *sdev)
  1210. {
  1211. struct Scsi_Host *shost = sdev->host;
  1212. unsigned long lock_flags = 0;
  1213. spin_lock_irqsave(shost->host_lock, lock_flags);
  1214. if (sdev->type == TYPE_DISK)
  1215. sdev->allow_restart = 1;
  1216. scsi_adjust_queue_depth(sdev, 0, shost->cmd_per_lun);
  1217. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  1218. return 0;
  1219. }
  1220. /**
  1221. * ibmvscsi_change_queue_depth - Change the device's queue depth
  1222. * @sdev: scsi device struct
  1223. * @qdepth: depth to set
  1224. *
  1225. * Return value:
  1226. * actual depth set
  1227. **/
  1228. static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1229. {
  1230. if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN)
  1231. qdepth = IBMVSCSI_MAX_CMDS_PER_LUN;
  1232. scsi_adjust_queue_depth(sdev, 0, qdepth);
  1233. return sdev->queue_depth;
  1234. }
  1235. /* ------------------------------------------------------------
  1236. * sysfs attributes
  1237. */
  1238. static ssize_t show_host_srp_version(struct class_device *class_dev, char *buf)
  1239. {
  1240. struct Scsi_Host *shost = class_to_shost(class_dev);
  1241. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1242. int len;
  1243. len = snprintf(buf, PAGE_SIZE, "%s\n",
  1244. hostdata->madapter_info.srp_version);
  1245. return len;
  1246. }
  1247. static struct class_device_attribute ibmvscsi_host_srp_version = {
  1248. .attr = {
  1249. .name = "srp_version",
  1250. .mode = S_IRUGO,
  1251. },
  1252. .show = show_host_srp_version,
  1253. };
  1254. static ssize_t show_host_partition_name(struct class_device *class_dev,
  1255. char *buf)
  1256. {
  1257. struct Scsi_Host *shost = class_to_shost(class_dev);
  1258. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1259. int len;
  1260. len = snprintf(buf, PAGE_SIZE, "%s\n",
  1261. hostdata->madapter_info.partition_name);
  1262. return len;
  1263. }
  1264. static struct class_device_attribute ibmvscsi_host_partition_name = {
  1265. .attr = {
  1266. .name = "partition_name",
  1267. .mode = S_IRUGO,
  1268. },
  1269. .show = show_host_partition_name,
  1270. };
  1271. static ssize_t show_host_partition_number(struct class_device *class_dev,
  1272. char *buf)
  1273. {
  1274. struct Scsi_Host *shost = class_to_shost(class_dev);
  1275. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1276. int len;
  1277. len = snprintf(buf, PAGE_SIZE, "%d\n",
  1278. hostdata->madapter_info.partition_number);
  1279. return len;
  1280. }
  1281. static struct class_device_attribute ibmvscsi_host_partition_number = {
  1282. .attr = {
  1283. .name = "partition_number",
  1284. .mode = S_IRUGO,
  1285. },
  1286. .show = show_host_partition_number,
  1287. };
  1288. static ssize_t show_host_mad_version(struct class_device *class_dev, char *buf)
  1289. {
  1290. struct Scsi_Host *shost = class_to_shost(class_dev);
  1291. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1292. int len;
  1293. len = snprintf(buf, PAGE_SIZE, "%d\n",
  1294. hostdata->madapter_info.mad_version);
  1295. return len;
  1296. }
  1297. static struct class_device_attribute ibmvscsi_host_mad_version = {
  1298. .attr = {
  1299. .name = "mad_version",
  1300. .mode = S_IRUGO,
  1301. },
  1302. .show = show_host_mad_version,
  1303. };
  1304. static ssize_t show_host_os_type(struct class_device *class_dev, char *buf)
  1305. {
  1306. struct Scsi_Host *shost = class_to_shost(class_dev);
  1307. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1308. int len;
  1309. len = snprintf(buf, PAGE_SIZE, "%d\n", hostdata->madapter_info.os_type);
  1310. return len;
  1311. }
  1312. static struct class_device_attribute ibmvscsi_host_os_type = {
  1313. .attr = {
  1314. .name = "os_type",
  1315. .mode = S_IRUGO,
  1316. },
  1317. .show = show_host_os_type,
  1318. };
  1319. static ssize_t show_host_config(struct class_device *class_dev, char *buf)
  1320. {
  1321. struct Scsi_Host *shost = class_to_shost(class_dev);
  1322. struct ibmvscsi_host_data *hostdata = shost_priv(shost);
  1323. /* returns null-terminated host config data */
  1324. if (ibmvscsi_do_host_config(hostdata, buf, PAGE_SIZE) == 0)
  1325. return strlen(buf);
  1326. else
  1327. return 0;
  1328. }
  1329. static struct class_device_attribute ibmvscsi_host_config = {
  1330. .attr = {
  1331. .name = "config",
  1332. .mode = S_IRUGO,
  1333. },
  1334. .show = show_host_config,
  1335. };
  1336. static struct class_device_attribute *ibmvscsi_attrs[] = {
  1337. &ibmvscsi_host_srp_version,
  1338. &ibmvscsi_host_partition_name,
  1339. &ibmvscsi_host_partition_number,
  1340. &ibmvscsi_host_mad_version,
  1341. &ibmvscsi_host_os_type,
  1342. &ibmvscsi_host_config,
  1343. NULL
  1344. };
  1345. /* ------------------------------------------------------------
  1346. * SCSI driver registration
  1347. */
  1348. static struct scsi_host_template driver_template = {
  1349. .module = THIS_MODULE,
  1350. .name = "IBM POWER Virtual SCSI Adapter " IBMVSCSI_VERSION,
  1351. .proc_name = "ibmvscsi",
  1352. .queuecommand = ibmvscsi_queuecommand,
  1353. .eh_abort_handler = ibmvscsi_eh_abort_handler,
  1354. .eh_device_reset_handler = ibmvscsi_eh_device_reset_handler,
  1355. .eh_host_reset_handler = ibmvscsi_eh_host_reset_handler,
  1356. .slave_configure = ibmvscsi_slave_configure,
  1357. .change_queue_depth = ibmvscsi_change_queue_depth,
  1358. .cmd_per_lun = 16,
  1359. .can_queue = IBMVSCSI_MAX_REQUESTS_DEFAULT,
  1360. .this_id = -1,
  1361. .sg_tablesize = SG_ALL,
  1362. .use_clustering = ENABLE_CLUSTERING,
  1363. .shost_attrs = ibmvscsi_attrs,
  1364. };
  1365. /**
  1366. * Called by bus code for each adapter
  1367. */
  1368. static int ibmvscsi_probe(struct vio_dev *vdev, const struct vio_device_id *id)
  1369. {
  1370. struct ibmvscsi_host_data *hostdata;
  1371. struct Scsi_Host *host;
  1372. struct device *dev = &vdev->dev;
  1373. struct srp_rport_identifiers ids;
  1374. struct srp_rport *rport;
  1375. unsigned long wait_switch = 0;
  1376. int rc;
  1377. vdev->dev.driver_data = NULL;
  1378. driver_template.can_queue = max_requests;
  1379. host = scsi_host_alloc(&driver_template, sizeof(*hostdata));
  1380. if (!host) {
  1381. dev_err(&vdev->dev, "couldn't allocate host data\n");
  1382. goto scsi_host_alloc_failed;
  1383. }
  1384. host->transportt = ibmvscsi_transport_template;
  1385. hostdata = shost_priv(host);
  1386. memset(hostdata, 0x00, sizeof(*hostdata));
  1387. INIT_LIST_HEAD(&hostdata->sent);
  1388. hostdata->host = host;
  1389. hostdata->dev = dev;
  1390. atomic_set(&hostdata->request_limit, -1);
  1391. hostdata->host->max_sectors = 32 * 8; /* default max I/O 32 pages */
  1392. rc = ibmvscsi_init_crq_queue(&hostdata->queue, hostdata, max_requests);
  1393. if (rc != 0 && rc != H_RESOURCE) {
  1394. dev_err(&vdev->dev, "couldn't initialize crq. rc=%d\n", rc);
  1395. goto init_crq_failed;
  1396. }
  1397. if (initialize_event_pool(&hostdata->pool, max_requests, hostdata) != 0) {
  1398. dev_err(&vdev->dev, "couldn't initialize event pool\n");
  1399. goto init_pool_failed;
  1400. }
  1401. host->max_lun = 8;
  1402. host->max_id = max_id;
  1403. host->max_channel = max_channel;
  1404. if (scsi_add_host(hostdata->host, hostdata->dev))
  1405. goto add_host_failed;
  1406. /* we don't have a proper target_port_id so let's use the fake one */
  1407. memcpy(ids.port_id, hostdata->madapter_info.partition_name,
  1408. sizeof(ids.port_id));
  1409. ids.roles = SRP_RPORT_ROLE_TARGET;
  1410. rport = srp_rport_add(host, &ids);
  1411. if (IS_ERR(rport))
  1412. goto add_srp_port_failed;
  1413. /* Try to send an initialization message. Note that this is allowed
  1414. * to fail if the other end is not acive. In that case we don't
  1415. * want to scan
  1416. */
  1417. if (ibmvscsi_send_crq(hostdata, 0xC001000000000000LL, 0) == 0
  1418. || rc == H_RESOURCE) {
  1419. /*
  1420. * Wait around max init_timeout secs for the adapter to finish
  1421. * initializing. When we are done initializing, we will have a
  1422. * valid request_limit. We don't want Linux scanning before
  1423. * we are ready.
  1424. */
  1425. for (wait_switch = jiffies + (init_timeout * HZ);
  1426. time_before(jiffies, wait_switch) &&
  1427. atomic_read(&hostdata->request_limit) < 2;) {
  1428. msleep(10);
  1429. }
  1430. /* if we now have a valid request_limit, initiate a scan */
  1431. if (atomic_read(&hostdata->request_limit) > 0)
  1432. scsi_scan_host(host);
  1433. }
  1434. vdev->dev.driver_data = hostdata;
  1435. return 0;
  1436. add_srp_port_failed:
  1437. scsi_remove_host(hostdata->host);
  1438. add_host_failed:
  1439. release_event_pool(&hostdata->pool, hostdata);
  1440. init_pool_failed:
  1441. ibmvscsi_release_crq_queue(&hostdata->queue, hostdata, max_requests);
  1442. init_crq_failed:
  1443. scsi_host_put(host);
  1444. scsi_host_alloc_failed:
  1445. return -1;
  1446. }
  1447. static int ibmvscsi_remove(struct vio_dev *vdev)
  1448. {
  1449. struct ibmvscsi_host_data *hostdata = vdev->dev.driver_data;
  1450. release_event_pool(&hostdata->pool, hostdata);
  1451. ibmvscsi_release_crq_queue(&hostdata->queue, hostdata,
  1452. max_requests);
  1453. srp_remove_host(hostdata->host);
  1454. scsi_remove_host(hostdata->host);
  1455. scsi_host_put(hostdata->host);
  1456. return 0;
  1457. }
  1458. /**
  1459. * ibmvscsi_device_table: Used by vio.c to match devices in the device tree we
  1460. * support.
  1461. */
  1462. static struct vio_device_id ibmvscsi_device_table[] __devinitdata = {
  1463. {"vscsi", "IBM,v-scsi"},
  1464. { "", "" }
  1465. };
  1466. MODULE_DEVICE_TABLE(vio, ibmvscsi_device_table);
  1467. static struct vio_driver ibmvscsi_driver = {
  1468. .id_table = ibmvscsi_device_table,
  1469. .probe = ibmvscsi_probe,
  1470. .remove = ibmvscsi_remove,
  1471. .driver = {
  1472. .name = "ibmvscsi",
  1473. .owner = THIS_MODULE,
  1474. }
  1475. };
  1476. static struct srp_function_template ibmvscsi_transport_functions = {
  1477. };
  1478. int __init ibmvscsi_module_init(void)
  1479. {
  1480. int ret;
  1481. ibmvscsi_transport_template =
  1482. srp_attach_transport(&ibmvscsi_transport_functions);
  1483. if (!ibmvscsi_transport_template)
  1484. return -ENOMEM;
  1485. ret = vio_register_driver(&ibmvscsi_driver);
  1486. if (ret)
  1487. srp_release_transport(ibmvscsi_transport_template);
  1488. return ret;
  1489. }
  1490. void __exit ibmvscsi_module_exit(void)
  1491. {
  1492. vio_unregister_driver(&ibmvscsi_driver);
  1493. srp_release_transport(ibmvscsi_transport_template);
  1494. }
  1495. module_init(ibmvscsi_module_init);
  1496. module_exit(ibmvscsi_module_exit);