iscsi_iser.c 20 KB

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