iscsi_iser.c 19 KB

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