iscsi_iser.c 19 KB

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