iscsi_iser.c 19 KB

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