iscsi_iser.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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 struct scsi_host_template iscsi_iser_sht;
  69. static struct iscsi_transport iscsi_iser_transport;
  70. static struct scsi_transport_template *iscsi_iser_scsi_transport;
  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. int datalen;
  87. int ahslen;
  88. /* verify PDU length */
  89. datalen = ntoh24(hdr->dlength);
  90. if (datalen != rx_data_len) {
  91. printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
  92. datalen, rx_data_len);
  93. rc = ISCSI_ERR_DATALEN;
  94. goto error;
  95. }
  96. /* read AHS */
  97. ahslen = hdr->hlength * 4;
  98. rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
  99. if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
  100. goto error;
  101. return;
  102. error:
  103. iscsi_conn_failure(conn, rc);
  104. }
  105. /**
  106. * iscsi_iser_task_init - Initialize task
  107. * @task: iscsi task
  108. *
  109. * Initialize the task for the scsi command or mgmt command.
  110. */
  111. static int
  112. iscsi_iser_task_init(struct iscsi_task *task)
  113. {
  114. struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
  115. struct iscsi_iser_task *iser_task = task->dd_data;
  116. /* mgmt task */
  117. if (!task->sc) {
  118. iser_task->desc.data = task->data;
  119. return 0;
  120. }
  121. iser_task->command_sent = 0;
  122. iser_task->iser_conn = iser_conn;
  123. iser_task_rdma_init(iser_task);
  124. return 0;
  125. }
  126. /**
  127. * iscsi_iser_mtask_xmit - xmit management(immediate) task
  128. * @conn: iscsi connection
  129. * @task: task management task
  130. *
  131. * Notes:
  132. * The function can return -EAGAIN in which case caller must
  133. * call it again later, or recover. '0' return code means successful
  134. * xmit.
  135. *
  136. **/
  137. static int
  138. iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
  139. {
  140. int error = 0;
  141. debug_scsi("task deq [cid %d itt 0x%x]\n", conn->id, task->itt);
  142. error = iser_send_control(conn, task);
  143. /* since iser xmits control with zero copy, tasks can not be recycled
  144. * right after sending them.
  145. * The recycling scheme is based on whether a response is expected
  146. * - if yes, the task is recycled at iscsi_complete_pdu
  147. * - if no, the task is recycled at iser_snd_completion
  148. */
  149. if (error && error != -ENOBUFS)
  150. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  151. return error;
  152. }
  153. static int
  154. iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
  155. struct iscsi_task *task)
  156. {
  157. struct iscsi_data hdr;
  158. int error = 0;
  159. /* Send data-out PDUs while there's still unsolicited data to send */
  160. while (task->unsol_count > 0) {
  161. iscsi_prep_unsolicit_data_pdu(task, &hdr);
  162. debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
  163. hdr.itt, task->data_count);
  164. /* the buffer description has been passed with the command */
  165. /* Send the command */
  166. error = iser_send_data_out(conn, task, &hdr);
  167. if (error) {
  168. task->unsol_datasn--;
  169. goto iscsi_iser_task_xmit_unsol_data_exit;
  170. }
  171. task->unsol_count -= task->data_count;
  172. debug_scsi("Need to send %d more as data-out PDUs\n",
  173. task->unsol_count);
  174. }
  175. iscsi_iser_task_xmit_unsol_data_exit:
  176. return error;
  177. }
  178. static int
  179. iscsi_iser_task_xmit(struct iscsi_task *task)
  180. {
  181. struct iscsi_conn *conn = task->conn;
  182. struct iscsi_iser_task *iser_task = task->dd_data;
  183. int error = 0;
  184. if (!task->sc)
  185. return iscsi_iser_mtask_xmit(conn, task);
  186. if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
  187. BUG_ON(scsi_bufflen(task->sc) == 0);
  188. debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
  189. task->itt, scsi_bufflen(task->sc),
  190. task->imm_count, task->unsol_count);
  191. }
  192. debug_scsi("task deq [cid %d itt 0x%x]\n",
  193. conn->id, task->itt);
  194. /* Send the cmd PDU */
  195. if (!iser_task->command_sent) {
  196. error = iser_send_command(conn, task);
  197. if (error)
  198. goto iscsi_iser_task_xmit_exit;
  199. iser_task->command_sent = 1;
  200. }
  201. /* Send unsolicited data-out PDU(s) if necessary */
  202. if (task->unsol_count)
  203. error = iscsi_iser_task_xmit_unsol_data(conn, task);
  204. iscsi_iser_task_xmit_exit:
  205. if (error && error != -ENOBUFS)
  206. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  207. return error;
  208. }
  209. static void
  210. iscsi_iser_cleanup_task(struct iscsi_conn *conn, struct iscsi_task *task)
  211. {
  212. struct iscsi_iser_task *iser_task = task->dd_data;
  213. /* mgmt tasks do not need special cleanup */
  214. if (!task->sc)
  215. return;
  216. if (iser_task->status == ISER_TASK_STATUS_STARTED) {
  217. iser_task->status = ISER_TASK_STATUS_COMPLETED;
  218. iser_task_rdma_finalize(iser_task);
  219. }
  220. }
  221. static struct iscsi_cls_conn *
  222. iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  223. {
  224. struct iscsi_conn *conn;
  225. struct iscsi_cls_conn *cls_conn;
  226. struct iscsi_iser_conn *iser_conn;
  227. cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
  228. if (!cls_conn)
  229. return NULL;
  230. conn = cls_conn->dd_data;
  231. /*
  232. * due to issues with the login code re iser sematics
  233. * this not set in iscsi_conn_setup - FIXME
  234. */
  235. conn->max_recv_dlength = 128;
  236. iser_conn = conn->dd_data;
  237. conn->dd_data = iser_conn;
  238. iser_conn->iscsi_conn = conn;
  239. return cls_conn;
  240. }
  241. static void
  242. iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
  243. {
  244. struct iscsi_conn *conn = cls_conn->dd_data;
  245. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  246. struct iser_conn *ib_conn = iser_conn->ib_conn;
  247. iscsi_conn_teardown(cls_conn);
  248. /*
  249. * Userspace will normally call the stop callback and
  250. * already have freed the ib_conn, but if it goofed up then
  251. * we free it here.
  252. */
  253. if (ib_conn) {
  254. ib_conn->iser_conn = NULL;
  255. iser_conn_put(ib_conn);
  256. }
  257. }
  258. static int
  259. iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
  260. struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
  261. int is_leading)
  262. {
  263. struct iscsi_conn *conn = cls_conn->dd_data;
  264. struct iscsi_iser_conn *iser_conn;
  265. struct iser_conn *ib_conn;
  266. struct iscsi_endpoint *ep;
  267. int error;
  268. error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
  269. if (error)
  270. return error;
  271. /* the transport ep handle comes from user space so it must be
  272. * verified against the global ib connections list */
  273. ep = iscsi_lookup_endpoint(transport_eph);
  274. if (!ep) {
  275. iser_err("can't bind eph %llx\n",
  276. (unsigned long long)transport_eph);
  277. return -EINVAL;
  278. }
  279. ib_conn = ep->dd_data;
  280. /* binds the iSER connection retrieved from the previously
  281. * connected ep_handle to the iSCSI layer connection. exchanges
  282. * connection pointers */
  283. iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
  284. iser_conn = conn->dd_data;
  285. ib_conn->iser_conn = iser_conn;
  286. iser_conn->ib_conn = ib_conn;
  287. iser_conn_get(ib_conn);
  288. return 0;
  289. }
  290. static void
  291. iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
  292. {
  293. struct iscsi_conn *conn = cls_conn->dd_data;
  294. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  295. struct iser_conn *ib_conn = iser_conn->ib_conn;
  296. /*
  297. * Userspace may have goofed up and not bound the connection or
  298. * might have only partially setup the connection.
  299. */
  300. if (ib_conn) {
  301. iscsi_conn_stop(cls_conn, flag);
  302. /*
  303. * There is no unbind event so the stop callback
  304. * must release the ref from the bind.
  305. */
  306. iser_conn_put(ib_conn);
  307. }
  308. iser_conn->ib_conn = NULL;
  309. }
  310. static int
  311. iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
  312. {
  313. struct iscsi_conn *conn = cls_conn->dd_data;
  314. int err;
  315. err = iser_conn_set_full_featured_mode(conn);
  316. if (err)
  317. return err;
  318. return iscsi_conn_start(cls_conn);
  319. }
  320. static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
  321. {
  322. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  323. iscsi_host_remove(shost);
  324. iscsi_host_free(shost);
  325. }
  326. static struct iscsi_cls_session *
  327. iscsi_iser_session_create(struct iscsi_endpoint *ep,
  328. uint16_t cmds_max, uint16_t qdepth,
  329. uint32_t initial_cmdsn, uint32_t *hostno)
  330. {
  331. struct iscsi_cls_session *cls_session;
  332. struct iscsi_session *session;
  333. struct Scsi_Host *shost;
  334. int i;
  335. struct iscsi_task *task;
  336. struct iscsi_iser_task *iser_task;
  337. struct iser_conn *ib_conn;
  338. shost = iscsi_host_alloc(&iscsi_iser_sht, 0, ISCSI_MAX_CMD_PER_LUN);
  339. if (!shost)
  340. return NULL;
  341. shost->transportt = iscsi_iser_scsi_transport;
  342. shost->max_lun = iscsi_max_lun;
  343. shost->max_id = 0;
  344. shost->max_channel = 0;
  345. shost->max_cmd_len = 16;
  346. /*
  347. * older userspace tools (before 2.0-870) did not pass us
  348. * the leading conn's ep so this will be NULL;
  349. */
  350. if (ep)
  351. ib_conn = ep->dd_data;
  352. if (iscsi_host_add(shost,
  353. ep ? ib_conn->device->ib_device->dma_device : NULL))
  354. goto free_host;
  355. *hostno = shost->host_no;
  356. /*
  357. * we do not support setting can_queue cmd_per_lun from userspace yet
  358. * because we preallocate so many resources
  359. */
  360. cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
  361. ISCSI_DEF_XMIT_CMDS_MAX,
  362. sizeof(struct iscsi_iser_task),
  363. initial_cmdsn, 0);
  364. if (!cls_session)
  365. goto remove_host;
  366. session = cls_session->dd_data;
  367. shost->can_queue = session->scsi_cmds_max;
  368. /* libiscsi setup itts, data and pool so just set desc fields */
  369. for (i = 0; i < session->cmds_max; i++) {
  370. task = session->cmds[i];
  371. iser_task = task->dd_data;
  372. task->hdr = (struct iscsi_cmd *)&iser_task->desc.iscsi_header;
  373. task->hdr_max = sizeof(iser_task->desc.iscsi_header);
  374. }
  375. return cls_session;
  376. remove_host:
  377. iscsi_host_remove(shost);
  378. free_host:
  379. iscsi_host_free(shost);
  380. return NULL;
  381. }
  382. static int
  383. iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
  384. enum iscsi_param param, char *buf, int buflen)
  385. {
  386. int value;
  387. switch (param) {
  388. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  389. /* TBD */
  390. break;
  391. case ISCSI_PARAM_HDRDGST_EN:
  392. sscanf(buf, "%d", &value);
  393. if (value) {
  394. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  395. return -EPROTO;
  396. }
  397. break;
  398. case ISCSI_PARAM_DATADGST_EN:
  399. sscanf(buf, "%d", &value);
  400. if (value) {
  401. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  402. return -EPROTO;
  403. }
  404. break;
  405. case ISCSI_PARAM_IFMARKER_EN:
  406. sscanf(buf, "%d", &value);
  407. if (value) {
  408. printk(KERN_ERR "IFMarker wasn't negotiated to No");
  409. return -EPROTO;
  410. }
  411. break;
  412. case ISCSI_PARAM_OFMARKER_EN:
  413. sscanf(buf, "%d", &value);
  414. if (value) {
  415. printk(KERN_ERR "OFMarker wasn't negotiated to No");
  416. return -EPROTO;
  417. }
  418. break;
  419. default:
  420. return iscsi_set_param(cls_conn, param, buf, buflen);
  421. }
  422. return 0;
  423. }
  424. static void
  425. iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
  426. {
  427. struct iscsi_conn *conn = cls_conn->dd_data;
  428. stats->txdata_octets = conn->txdata_octets;
  429. stats->rxdata_octets = conn->rxdata_octets;
  430. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  431. stats->dataout_pdus = conn->dataout_pdus_cnt;
  432. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  433. stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
  434. stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
  435. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  436. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  437. stats->custom_length = 4;
  438. strcpy(stats->custom[0].desc, "qp_tx_queue_full");
  439. stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
  440. strcpy(stats->custom[1].desc, "fmr_map_not_avail");
  441. stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
  442. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  443. stats->custom[2].value = conn->eh_abort_cnt;
  444. strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
  445. stats->custom[3].value = conn->fmr_unalign_cnt;
  446. }
  447. static struct iscsi_endpoint *
  448. iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking)
  449. {
  450. int err;
  451. struct iser_conn *ib_conn;
  452. struct iscsi_endpoint *ep;
  453. ep = iscsi_create_endpoint(sizeof(*ib_conn));
  454. if (!ep)
  455. return ERR_PTR(-ENOMEM);
  456. ib_conn = ep->dd_data;
  457. ib_conn->ep = ep;
  458. iser_conn_init(ib_conn);
  459. err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr,
  460. non_blocking);
  461. if (err) {
  462. iscsi_destroy_endpoint(ep);
  463. return ERR_PTR(err);
  464. }
  465. return ep;
  466. }
  467. static int
  468. iscsi_iser_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  469. {
  470. struct iser_conn *ib_conn;
  471. int rc;
  472. ib_conn = ep->dd_data;
  473. rc = wait_event_interruptible_timeout(ib_conn->wait,
  474. ib_conn->state == ISER_CONN_UP,
  475. msecs_to_jiffies(timeout_ms));
  476. /* if conn establishment failed, return error code to iscsi */
  477. if (!rc &&
  478. (ib_conn->state == ISER_CONN_TERMINATING ||
  479. ib_conn->state == ISER_CONN_DOWN))
  480. rc = -1;
  481. iser_err("ib conn %p rc = %d\n", ib_conn, rc);
  482. if (rc > 0)
  483. return 1; /* success, this is the equivalent of POLLOUT */
  484. else if (!rc)
  485. return 0; /* timeout */
  486. else
  487. return rc; /* signal */
  488. }
  489. static void
  490. iscsi_iser_ep_disconnect(struct iscsi_endpoint *ep)
  491. {
  492. struct iser_conn *ib_conn;
  493. ib_conn = ep->dd_data;
  494. if (ib_conn->iser_conn)
  495. /*
  496. * Must suspend xmit path if the ep is bound to the
  497. * iscsi_conn, so we know we are not accessing the ib_conn
  498. * when we free it.
  499. *
  500. * This may not be bound if the ep poll failed.
  501. */
  502. iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
  503. iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
  504. iser_conn_terminate(ib_conn);
  505. }
  506. static struct scsi_host_template iscsi_iser_sht = {
  507. .module = THIS_MODULE,
  508. .name = "iSCSI Initiator over iSER, v." DRV_VER,
  509. .queuecommand = iscsi_queuecommand,
  510. .change_queue_depth = iscsi_change_queue_depth,
  511. .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
  512. .max_sectors = 1024,
  513. .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
  514. .eh_abort_handler = iscsi_eh_abort,
  515. .eh_device_reset_handler= iscsi_eh_device_reset,
  516. .eh_host_reset_handler = iscsi_eh_host_reset,
  517. .use_clustering = DISABLE_CLUSTERING,
  518. .proc_name = "iscsi_iser",
  519. .this_id = -1,
  520. };
  521. static struct iscsi_transport iscsi_iser_transport = {
  522. .owner = THIS_MODULE,
  523. .name = "iser",
  524. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
  525. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  526. ISCSI_MAX_XMIT_DLENGTH |
  527. ISCSI_HDRDGST_EN |
  528. ISCSI_DATADGST_EN |
  529. ISCSI_INITIAL_R2T_EN |
  530. ISCSI_MAX_R2T |
  531. ISCSI_IMM_DATA_EN |
  532. ISCSI_FIRST_BURST |
  533. ISCSI_MAX_BURST |
  534. ISCSI_PDU_INORDER_EN |
  535. ISCSI_DATASEQ_INORDER_EN |
  536. ISCSI_EXP_STATSN |
  537. ISCSI_PERSISTENT_PORT |
  538. ISCSI_PERSISTENT_ADDRESS |
  539. ISCSI_TARGET_NAME | ISCSI_TPGT |
  540. ISCSI_USERNAME | ISCSI_PASSWORD |
  541. ISCSI_USERNAME_IN | ISCSI_PASSWORD_IN |
  542. ISCSI_FAST_ABORT | ISCSI_ABORT_TMO |
  543. ISCSI_PING_TMO | ISCSI_RECV_TMO |
  544. ISCSI_IFACE_NAME | ISCSI_INITIATOR_NAME,
  545. .host_param_mask = ISCSI_HOST_HWADDRESS |
  546. ISCSI_HOST_NETDEV_NAME |
  547. ISCSI_HOST_INITIATOR_NAME,
  548. /* session management */
  549. .create_session = iscsi_iser_session_create,
  550. .destroy_session = iscsi_iser_session_destroy,
  551. /* connection management */
  552. .create_conn = iscsi_iser_conn_create,
  553. .bind_conn = iscsi_iser_conn_bind,
  554. .destroy_conn = iscsi_iser_conn_destroy,
  555. .set_param = iscsi_iser_set_param,
  556. .get_conn_param = iscsi_conn_get_param,
  557. .get_session_param = iscsi_session_get_param,
  558. .start_conn = iscsi_iser_conn_start,
  559. .stop_conn = iscsi_iser_conn_stop,
  560. /* iscsi host params */
  561. .get_host_param = iscsi_host_get_param,
  562. .set_host_param = iscsi_host_set_param,
  563. /* IO */
  564. .send_pdu = iscsi_conn_send_pdu,
  565. .get_stats = iscsi_iser_conn_get_stats,
  566. .init_task = iscsi_iser_task_init,
  567. .xmit_task = iscsi_iser_task_xmit,
  568. .cleanup_task = iscsi_iser_cleanup_task,
  569. /* recovery */
  570. .session_recovery_timedout = iscsi_session_recovery_timedout,
  571. .ep_connect = iscsi_iser_ep_connect,
  572. .ep_poll = iscsi_iser_ep_poll,
  573. .ep_disconnect = iscsi_iser_ep_disconnect
  574. };
  575. static int __init iser_init(void)
  576. {
  577. int err;
  578. iser_dbg("Starting iSER datamover...\n");
  579. if (iscsi_max_lun < 1) {
  580. printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
  581. return -EINVAL;
  582. }
  583. memset(&ig, 0, sizeof(struct iser_global));
  584. ig.desc_cache = kmem_cache_create("iser_descriptors",
  585. sizeof (struct iser_desc),
  586. 0, SLAB_HWCACHE_ALIGN,
  587. NULL);
  588. if (ig.desc_cache == NULL)
  589. return -ENOMEM;
  590. /* device init is called only after the first addr resolution */
  591. mutex_init(&ig.device_list_mutex);
  592. INIT_LIST_HEAD(&ig.device_list);
  593. mutex_init(&ig.connlist_mutex);
  594. INIT_LIST_HEAD(&ig.connlist);
  595. iscsi_iser_scsi_transport = iscsi_register_transport(
  596. &iscsi_iser_transport);
  597. if (!iscsi_iser_scsi_transport) {
  598. iser_err("iscsi_register_transport failed\n");
  599. err = -EINVAL;
  600. goto register_transport_failure;
  601. }
  602. return 0;
  603. register_transport_failure:
  604. kmem_cache_destroy(ig.desc_cache);
  605. return err;
  606. }
  607. static void __exit iser_exit(void)
  608. {
  609. iser_dbg("Removing iSER datamover...\n");
  610. iscsi_unregister_transport(&iscsi_iser_transport);
  611. kmem_cache_destroy(ig.desc_cache);
  612. }
  613. module_init(iser_init);
  614. module_exit(iser_exit);