iscsi_iser.c 18 KB

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