iscsi_iser.c 20 KB

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