iscsi_iser.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * iSCSI Initiator over iSER Data-Path
  3. *
  4. * Copyright (C) 2004 Dmitry Yusupov
  5. * Copyright (C) 2004 Alex Aizman
  6. * Copyright (C) 2005 Mike Christie
  7. * Copyright (c) 2005, 2006 Voltaire, Inc. All rights reserved.
  8. * maintained by openib-general@openib.org
  9. *
  10. * This software is available to you under a choice of one of two
  11. * licenses. You may choose to be licensed under the terms of the GNU
  12. * General Public License (GPL) Version 2, available from the file
  13. * COPYING in the main directory of this source tree, or the
  14. * OpenIB.org BSD license below:
  15. *
  16. * Redistribution and use in source and binary forms, with or
  17. * without modification, are permitted provided that the following
  18. * conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials
  27. * provided with the distribution.
  28. *
  29. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  33. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  34. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  35. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  36. * SOFTWARE.
  37. *
  38. * Credits:
  39. * Christoph Hellwig
  40. * FUJITA Tomonori
  41. * Arne Redlich
  42. * Zhenyu Wang
  43. * Modified by:
  44. * Erez Zilber
  45. *
  46. *
  47. * $Id: iscsi_iser.c 6965 2006-05-07 11:36:20Z ogerlitz $
  48. */
  49. #include <linux/types.h>
  50. #include <linux/list.h>
  51. #include <linux/hardirq.h>
  52. #include <linux/kfifo.h>
  53. #include <linux/blkdev.h>
  54. #include <linux/init.h>
  55. #include <linux/ioctl.h>
  56. #include <linux/cdev.h>
  57. #include <linux/in.h>
  58. #include <linux/net.h>
  59. #include <linux/scatterlist.h>
  60. #include <linux/delay.h>
  61. #include <net/sock.h>
  62. #include <asm/uaccess.h>
  63. #include <scsi/scsi_cmnd.h>
  64. #include <scsi/scsi_device.h>
  65. #include <scsi/scsi_eh.h>
  66. #include <scsi/scsi_tcq.h>
  67. #include <scsi/scsi_host.h>
  68. #include <scsi/scsi.h>
  69. #include <scsi/scsi_transport_iscsi.h>
  70. #include "iscsi_iser.h"
  71. static unsigned int iscsi_max_lun = 512;
  72. module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
  73. int iser_debug_level = 0;
  74. MODULE_DESCRIPTION("iSER (iSCSI Extensions for RDMA) Datamover "
  75. "v" DRV_VER " (" DRV_DATE ")");
  76. MODULE_LICENSE("Dual BSD/GPL");
  77. MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
  78. module_param_named(debug_level, iser_debug_level, int, 0644);
  79. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:disabled)");
  80. struct iser_global ig;
  81. void
  82. iscsi_iser_recv(struct iscsi_conn *conn,
  83. struct iscsi_hdr *hdr, char *rx_data, int rx_data_len)
  84. {
  85. int rc = 0;
  86. uint32_t ret_itt;
  87. int datalen;
  88. int ahslen;
  89. /* verify PDU length */
  90. datalen = ntoh24(hdr->dlength);
  91. if (datalen != rx_data_len) {
  92. printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
  93. datalen, rx_data_len);
  94. rc = ISCSI_ERR_DATALEN;
  95. goto error;
  96. }
  97. /* read AHS */
  98. ahslen = hdr->hlength * 4;
  99. /* verify itt (itt encoding: age+cid+itt) */
  100. rc = iscsi_verify_itt(conn, hdr, &ret_itt);
  101. if (!rc)
  102. rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
  103. if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
  104. goto error;
  105. return;
  106. error:
  107. iscsi_conn_failure(conn, rc);
  108. }
  109. /**
  110. * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
  111. *
  112. **/
  113. static void
  114. iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
  115. {
  116. struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data;
  117. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  118. struct scsi_cmnd *sc = ctask->sc;
  119. iser_ctask->command_sent = 0;
  120. iser_ctask->iser_conn = iser_conn;
  121. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  122. BUG_ON(ctask->total_length == 0);
  123. debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
  124. ctask->itt, ctask->total_length, ctask->imm_count,
  125. ctask->unsol_count);
  126. }
  127. iser_ctask_rdma_init(iser_ctask);
  128. }
  129. /**
  130. * iscsi_mtask_xmit - xmit management(immediate) task
  131. * @conn: iscsi connection
  132. * @mtask: task management task
  133. *
  134. * Notes:
  135. * The function can return -EAGAIN in which case caller must
  136. * call it again later, or recover. '0' return code means successful
  137. * xmit.
  138. *
  139. **/
  140. static int
  141. iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
  142. struct iscsi_mgmt_task *mtask)
  143. {
  144. int error = 0;
  145. debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
  146. error = iser_send_control(conn, mtask);
  147. /* since iser xmits control with zero copy, mtasks can not be recycled
  148. * right after sending them.
  149. * The recycling scheme is based on whether a response is expected
  150. * - if yes, the mtask is recycled at iscsi_complete_pdu
  151. * - if no, the mtask is recycled at iser_snd_completion
  152. */
  153. if (error && error != -EAGAIN)
  154. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  155. return error;
  156. }
  157. static int
  158. iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
  159. struct iscsi_cmd_task *ctask)
  160. {
  161. struct iscsi_data hdr;
  162. int error = 0;
  163. /* Send data-out PDUs while there's still unsolicited data to send */
  164. while (ctask->unsol_count > 0) {
  165. iscsi_prep_unsolicit_data_pdu(ctask, &hdr);
  166. debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
  167. hdr.itt, ctask->data_count);
  168. /* the buffer description has been passed with the command */
  169. /* Send the command */
  170. error = iser_send_data_out(conn, ctask, &hdr);
  171. if (error) {
  172. ctask->unsol_datasn--;
  173. goto iscsi_iser_ctask_xmit_unsol_data_exit;
  174. }
  175. ctask->unsol_count -= ctask->data_count;
  176. debug_scsi("Need to send %d more as data-out PDUs\n",
  177. ctask->unsol_count);
  178. }
  179. iscsi_iser_ctask_xmit_unsol_data_exit:
  180. return error;
  181. }
  182. static int
  183. iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
  184. struct iscsi_cmd_task *ctask)
  185. {
  186. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  187. int error = 0;
  188. debug_scsi("ctask deq [cid %d itt 0x%x]\n",
  189. conn->id, ctask->itt);
  190. /*
  191. * serialize with TMF AbortTask
  192. */
  193. if (ctask->mtask)
  194. return error;
  195. /* Send the cmd PDU */
  196. if (!iser_ctask->command_sent) {
  197. error = iser_send_command(conn, ctask);
  198. if (error)
  199. goto iscsi_iser_ctask_xmit_exit;
  200. iser_ctask->command_sent = 1;
  201. }
  202. /* Send unsolicited data-out PDU(s) if necessary */
  203. if (ctask->unsol_count)
  204. error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
  205. iscsi_iser_ctask_xmit_exit:
  206. if (error && error != -EAGAIN)
  207. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  208. return error;
  209. }
  210. static void
  211. iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
  212. {
  213. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  214. if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
  215. iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
  216. iser_ctask_rdma_finalize(iser_ctask);
  217. }
  218. }
  219. static struct iser_conn *
  220. iscsi_iser_ib_conn_lookup(__u64 ep_handle)
  221. {
  222. struct iser_conn *ib_conn;
  223. struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
  224. mutex_lock(&ig.connlist_mutex);
  225. list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
  226. if (ib_conn == uib_conn) {
  227. mutex_unlock(&ig.connlist_mutex);
  228. return ib_conn;
  229. }
  230. }
  231. mutex_unlock(&ig.connlist_mutex);
  232. iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
  233. return NULL;
  234. }
  235. static struct iscsi_cls_conn *
  236. iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  237. {
  238. struct iscsi_conn *conn;
  239. struct iscsi_cls_conn *cls_conn;
  240. struct iscsi_iser_conn *iser_conn;
  241. cls_conn = iscsi_conn_setup(cls_session, conn_idx);
  242. if (!cls_conn)
  243. return NULL;
  244. conn = cls_conn->dd_data;
  245. /*
  246. * due to issues with the login code re iser sematics
  247. * this not set in iscsi_conn_setup - FIXME
  248. */
  249. conn->max_recv_dlength = 128;
  250. iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL);
  251. if (!iser_conn)
  252. goto conn_alloc_fail;
  253. /* currently this is the only field which need to be initiated */
  254. rwlock_init(&iser_conn->lock);
  255. conn->dd_data = iser_conn;
  256. iser_conn->iscsi_conn = conn;
  257. return cls_conn;
  258. conn_alloc_fail:
  259. iscsi_conn_teardown(cls_conn);
  260. return NULL;
  261. }
  262. static void
  263. iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
  264. {
  265. struct iscsi_conn *conn = cls_conn->dd_data;
  266. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  267. iscsi_conn_teardown(cls_conn);
  268. kfree(iser_conn);
  269. }
  270. static int
  271. iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
  272. struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
  273. int is_leading)
  274. {
  275. struct iscsi_conn *conn = cls_conn->dd_data;
  276. struct iscsi_iser_conn *iser_conn;
  277. struct iser_conn *ib_conn;
  278. int error;
  279. error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
  280. if (error)
  281. return error;
  282. /* the transport ep handle comes from user space so it must be
  283. * verified against the global ib connections list */
  284. ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
  285. if (!ib_conn) {
  286. iser_err("can't bind eph %llx\n",
  287. (unsigned long long)transport_eph);
  288. return -EINVAL;
  289. }
  290. /* binds the iSER connection retrieved from the previously
  291. * connected ep_handle to the iSCSI layer connection. exchanges
  292. * connection pointers */
  293. iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
  294. iser_conn = conn->dd_data;
  295. ib_conn->iser_conn = iser_conn;
  296. iser_conn->ib_conn = ib_conn;
  297. conn->recv_lock = &iser_conn->lock;
  298. return 0;
  299. }
  300. static int
  301. iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
  302. {
  303. struct iscsi_conn *conn = cls_conn->dd_data;
  304. int err;
  305. err = iscsi_conn_start(cls_conn);
  306. if (err)
  307. return err;
  308. return iser_conn_set_full_featured_mode(conn);
  309. }
  310. static struct iscsi_transport iscsi_iser_transport;
  311. static struct iscsi_cls_session *
  312. iscsi_iser_session_create(struct iscsi_transport *iscsit,
  313. struct scsi_transport_template *scsit,
  314. uint32_t initial_cmdsn, uint32_t *hostno)
  315. {
  316. struct iscsi_cls_session *cls_session;
  317. struct iscsi_session *session;
  318. int i;
  319. uint32_t hn;
  320. struct iscsi_cmd_task *ctask;
  321. struct iscsi_mgmt_task *mtask;
  322. struct iscsi_iser_cmd_task *iser_ctask;
  323. struct iser_desc *desc;
  324. cls_session = iscsi_session_setup(iscsit, scsit,
  325. sizeof(struct iscsi_iser_cmd_task),
  326. sizeof(struct iser_desc),
  327. initial_cmdsn, &hn);
  328. if (!cls_session)
  329. return NULL;
  330. *hostno = hn;
  331. session = class_to_transport_session(cls_session);
  332. /* libiscsi setup itts, data and pool so just set desc fields */
  333. for (i = 0; i < session->cmds_max; i++) {
  334. ctask = session->cmds[i];
  335. iser_ctask = ctask->dd_data;
  336. ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
  337. }
  338. for (i = 0; i < session->mgmtpool_max; i++) {
  339. mtask = session->mgmt_cmds[i];
  340. desc = mtask->dd_data;
  341. mtask->hdr = &desc->iscsi_header;
  342. desc->data = mtask->data;
  343. }
  344. return cls_session;
  345. }
  346. static int
  347. iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
  348. enum iscsi_param param, char *buf, int buflen)
  349. {
  350. int value;
  351. switch (param) {
  352. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  353. /* TBD */
  354. break;
  355. case ISCSI_PARAM_HDRDGST_EN:
  356. sscanf(buf, "%d", &value);
  357. if (value) {
  358. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  359. return -EPROTO;
  360. }
  361. break;
  362. case ISCSI_PARAM_DATADGST_EN:
  363. sscanf(buf, "%d", &value);
  364. if (value) {
  365. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  366. return -EPROTO;
  367. }
  368. break;
  369. case ISCSI_PARAM_IFMARKER_EN:
  370. sscanf(buf, "%d", &value);
  371. if (value) {
  372. printk(KERN_ERR "IFMarker wasn't negotiated to No");
  373. return -EPROTO;
  374. }
  375. break;
  376. case ISCSI_PARAM_OFMARKER_EN:
  377. sscanf(buf, "%d", &value);
  378. if (value) {
  379. printk(KERN_ERR "OFMarker wasn't negotiated to No");
  380. return -EPROTO;
  381. }
  382. break;
  383. default:
  384. return iscsi_set_param(cls_conn, param, buf, buflen);
  385. }
  386. return 0;
  387. }
  388. static void
  389. iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
  390. {
  391. struct iscsi_conn *conn = cls_conn->dd_data;
  392. stats->txdata_octets = conn->txdata_octets;
  393. stats->rxdata_octets = conn->rxdata_octets;
  394. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  395. stats->dataout_pdus = conn->dataout_pdus_cnt;
  396. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  397. stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
  398. stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
  399. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  400. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  401. stats->custom_length = 3;
  402. strcpy(stats->custom[0].desc, "qp_tx_queue_full");
  403. stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
  404. strcpy(stats->custom[1].desc, "fmr_map_not_avail");
  405. stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
  406. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  407. stats->custom[2].value = conn->eh_abort_cnt;
  408. }
  409. static int
  410. iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
  411. __u64 *ep_handle)
  412. {
  413. int err;
  414. struct iser_conn *ib_conn;
  415. err = iser_conn_init(&ib_conn);
  416. if (err)
  417. goto out;
  418. err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
  419. if (!err)
  420. *ep_handle = (__u64)(unsigned long)ib_conn;
  421. out:
  422. return err;
  423. }
  424. static int
  425. iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
  426. {
  427. struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
  428. int rc;
  429. if (!ib_conn)
  430. return -EINVAL;
  431. rc = wait_event_interruptible_timeout(ib_conn->wait,
  432. ib_conn->state == ISER_CONN_UP,
  433. msecs_to_jiffies(timeout_ms));
  434. /* if conn establishment failed, return error code to iscsi */
  435. if (!rc &&
  436. (ib_conn->state == ISER_CONN_TERMINATING ||
  437. ib_conn->state == ISER_CONN_DOWN))
  438. rc = -1;
  439. iser_err("ib conn %p rc = %d\n", ib_conn, rc);
  440. if (rc > 0)
  441. return 1; /* success, this is the equivalent of POLLOUT */
  442. else if (!rc)
  443. return 0; /* timeout */
  444. else
  445. return rc; /* signal */
  446. }
  447. static void
  448. iscsi_iser_ep_disconnect(__u64 ep_handle)
  449. {
  450. struct iser_conn *ib_conn;
  451. ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
  452. if (!ib_conn)
  453. return;
  454. iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
  455. iser_conn_terminate(ib_conn);
  456. }
  457. static struct scsi_host_template iscsi_iser_sht = {
  458. .name = "iSCSI Initiator over iSER, v." DRV_VER,
  459. .queuecommand = iscsi_queuecommand,
  460. .can_queue = ISCSI_XMIT_CMDS_MAX - 1,
  461. .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
  462. .max_sectors = 1024,
  463. .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
  464. .eh_abort_handler = iscsi_eh_abort,
  465. .eh_host_reset_handler = iscsi_eh_host_reset,
  466. .use_clustering = DISABLE_CLUSTERING,
  467. .proc_name = "iscsi_iser",
  468. .this_id = -1,
  469. };
  470. static struct iscsi_transport iscsi_iser_transport = {
  471. .owner = THIS_MODULE,
  472. .name = "iser",
  473. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
  474. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  475. ISCSI_MAX_XMIT_DLENGTH |
  476. ISCSI_HDRDGST_EN |
  477. ISCSI_DATADGST_EN |
  478. ISCSI_INITIAL_R2T_EN |
  479. ISCSI_MAX_R2T |
  480. ISCSI_IMM_DATA_EN |
  481. ISCSI_FIRST_BURST |
  482. ISCSI_MAX_BURST |
  483. ISCSI_PDU_INORDER_EN |
  484. ISCSI_DATASEQ_INORDER_EN |
  485. ISCSI_EXP_STATSN |
  486. ISCSI_PERSISTENT_PORT |
  487. ISCSI_PERSISTENT_ADDRESS |
  488. ISCSI_TARGET_NAME |
  489. ISCSI_TPGT,
  490. .host_template = &iscsi_iser_sht,
  491. .conndata_size = sizeof(struct iscsi_conn),
  492. .max_lun = ISCSI_ISER_MAX_LUN,
  493. .max_cmd_len = ISCSI_ISER_MAX_CMD_LEN,
  494. /* session management */
  495. .create_session = iscsi_iser_session_create,
  496. .destroy_session = iscsi_session_teardown,
  497. /* connection management */
  498. .create_conn = iscsi_iser_conn_create,
  499. .bind_conn = iscsi_iser_conn_bind,
  500. .destroy_conn = iscsi_iser_conn_destroy,
  501. .set_param = iscsi_iser_set_param,
  502. .get_conn_param = iscsi_conn_get_param,
  503. .get_session_param = iscsi_session_get_param,
  504. .start_conn = iscsi_iser_conn_start,
  505. .stop_conn = iscsi_conn_stop,
  506. /* IO */
  507. .send_pdu = iscsi_conn_send_pdu,
  508. .get_stats = iscsi_iser_conn_get_stats,
  509. .init_cmd_task = iscsi_iser_cmd_init,
  510. .xmit_cmd_task = iscsi_iser_ctask_xmit,
  511. .xmit_mgmt_task = iscsi_iser_mtask_xmit,
  512. .cleanup_cmd_task = iscsi_iser_cleanup_ctask,
  513. /* recovery */
  514. .session_recovery_timedout = iscsi_session_recovery_timedout,
  515. .ep_connect = iscsi_iser_ep_connect,
  516. .ep_poll = iscsi_iser_ep_poll,
  517. .ep_disconnect = iscsi_iser_ep_disconnect
  518. };
  519. static int __init iser_init(void)
  520. {
  521. int err;
  522. iser_dbg("Starting iSER datamover...\n");
  523. if (iscsi_max_lun < 1) {
  524. printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
  525. return -EINVAL;
  526. }
  527. iscsi_iser_transport.max_lun = iscsi_max_lun;
  528. memset(&ig, 0, sizeof(struct iser_global));
  529. ig.desc_cache = kmem_cache_create("iser_descriptors",
  530. sizeof (struct iser_desc),
  531. 0, SLAB_HWCACHE_ALIGN,
  532. NULL, NULL);
  533. if (ig.desc_cache == NULL)
  534. return -ENOMEM;
  535. /* device init is called only after the first addr resolution */
  536. mutex_init(&ig.device_list_mutex);
  537. INIT_LIST_HEAD(&ig.device_list);
  538. mutex_init(&ig.connlist_mutex);
  539. INIT_LIST_HEAD(&ig.connlist);
  540. if (!iscsi_register_transport(&iscsi_iser_transport)) {
  541. iser_err("iscsi_register_transport failed\n");
  542. err = -EINVAL;
  543. goto register_transport_failure;
  544. }
  545. return 0;
  546. register_transport_failure:
  547. kmem_cache_destroy(ig.desc_cache);
  548. return err;
  549. }
  550. static void __exit iser_exit(void)
  551. {
  552. iser_dbg("Removing iSER datamover...\n");
  553. iscsi_unregister_transport(&iscsi_iser_transport);
  554. kmem_cache_destroy(ig.desc_cache);
  555. }
  556. module_init(iser_init);
  557. module_exit(iser_exit);