ibmvscsi.c 50 KB

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