iscsi_iser.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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. * Copyright (c) 2013 Mellanox Technologies. All rights reserved.
  9. * maintained by openib-general@openib.org
  10. *
  11. * This software is available to you under a choice of one of two
  12. * licenses. You may choose to be licensed under the terms of the GNU
  13. * General Public License (GPL) Version 2, available from the file
  14. * COPYING in the main directory of this source tree, or the
  15. * OpenIB.org BSD license below:
  16. *
  17. * Redistribution and use in source and binary forms, with or
  18. * without modification, are permitted provided that the following
  19. * conditions are met:
  20. *
  21. * - Redistributions of source code must retain the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer.
  24. *
  25. * - Redistributions in binary form must reproduce the above
  26. * copyright notice, this list of conditions and the following
  27. * disclaimer in the documentation and/or other materials
  28. * provided with the distribution.
  29. *
  30. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  31. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  32. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  33. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  34. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  35. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  36. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  37. * SOFTWARE.
  38. *
  39. * Credits:
  40. * Christoph Hellwig
  41. * FUJITA Tomonori
  42. * Arne Redlich
  43. * Zhenyu Wang
  44. * Modified by:
  45. * Erez Zilber
  46. */
  47. #include <linux/types.h>
  48. #include <linux/list.h>
  49. #include <linux/hardirq.h>
  50. #include <linux/kfifo.h>
  51. #include <linux/blkdev.h>
  52. #include <linux/init.h>
  53. #include <linux/ioctl.h>
  54. #include <linux/cdev.h>
  55. #include <linux/in.h>
  56. #include <linux/net.h>
  57. #include <linux/scatterlist.h>
  58. #include <linux/delay.h>
  59. #include <linux/slab.h>
  60. #include <linux/module.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. MODULE_LICENSE("Dual BSD/GPL");
  79. MODULE_AUTHOR("Alex Nezhinsky, Dan Bar Dov, Or Gerlitz");
  80. MODULE_VERSION(DRV_VER);
  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 || (datalen + 4) < rx_data_len) {
  94. iser_err("wrong datalen %d (hdr), %d (IB)\n",
  95. datalen, rx_data_len);
  96. rc = ISCSI_ERR_DATALEN;
  97. goto error;
  98. }
  99. if (datalen != rx_data_len)
  100. iser_dbg("aligned datalen (%d) hdr, %d (IB)\n",
  101. datalen, rx_data_len);
  102. /* read AHS */
  103. ahslen = hdr->hlength * 4;
  104. rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
  105. if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
  106. goto error;
  107. return;
  108. error:
  109. iscsi_conn_failure(conn, rc);
  110. }
  111. static int iscsi_iser_pdu_alloc(struct iscsi_task *task, uint8_t opcode)
  112. {
  113. struct iscsi_iser_task *iser_task = task->dd_data;
  114. task->hdr = (struct iscsi_hdr *)&iser_task->desc.iscsi_header;
  115. task->hdr_max = sizeof(iser_task->desc.iscsi_header);
  116. return 0;
  117. }
  118. int iser_initialize_task_headers(struct iscsi_task *task,
  119. struct iser_tx_desc *tx_desc)
  120. {
  121. struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
  122. struct iser_device *device = iser_conn->ib_conn->device;
  123. struct iscsi_iser_task *iser_task = task->dd_data;
  124. u64 dma_addr;
  125. dma_addr = ib_dma_map_single(device->ib_device, (void *)tx_desc,
  126. ISER_HEADERS_LEN, DMA_TO_DEVICE);
  127. if (ib_dma_mapping_error(device->ib_device, dma_addr))
  128. return -ENOMEM;
  129. tx_desc->dma_addr = dma_addr;
  130. tx_desc->tx_sg[0].addr = tx_desc->dma_addr;
  131. tx_desc->tx_sg[0].length = ISER_HEADERS_LEN;
  132. tx_desc->tx_sg[0].lkey = device->mr->lkey;
  133. iser_task->iser_conn = iser_conn;
  134. return 0;
  135. }
  136. /**
  137. * iscsi_iser_task_init - Initialize task
  138. * @task: iscsi task
  139. *
  140. * Initialize the task for the scsi command or mgmt command.
  141. */
  142. static int
  143. iscsi_iser_task_init(struct iscsi_task *task)
  144. {
  145. struct iscsi_iser_task *iser_task = task->dd_data;
  146. if (iser_initialize_task_headers(task, &iser_task->desc))
  147. return -ENOMEM;
  148. /* mgmt task */
  149. if (!task->sc)
  150. return 0;
  151. iser_task->command_sent = 0;
  152. iser_task_rdma_init(iser_task);
  153. return 0;
  154. }
  155. /**
  156. * iscsi_iser_mtask_xmit - xmit management(immediate) task
  157. * @conn: iscsi connection
  158. * @task: task management task
  159. *
  160. * Notes:
  161. * The function can return -EAGAIN in which case caller must
  162. * call it again later, or recover. '0' return code means successful
  163. * xmit.
  164. *
  165. **/
  166. static int
  167. iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct iscsi_task *task)
  168. {
  169. int error = 0;
  170. iser_dbg("mtask xmit [cid %d itt 0x%x]\n", conn->id, task->itt);
  171. error = iser_send_control(conn, task);
  172. /* since iser xmits control with zero copy, tasks can not be recycled
  173. * right after sending them.
  174. * The recycling scheme is based on whether a response is expected
  175. * - if yes, the task is recycled at iscsi_complete_pdu
  176. * - if no, the task is recycled at iser_snd_completion
  177. */
  178. return error;
  179. }
  180. static int
  181. iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
  182. struct iscsi_task *task)
  183. {
  184. struct iscsi_r2t_info *r2t = &task->unsol_r2t;
  185. struct iscsi_data hdr;
  186. int error = 0;
  187. /* Send data-out PDUs while there's still unsolicited data to send */
  188. while (iscsi_task_has_unsol_data(task)) {
  189. iscsi_prep_data_out_pdu(task, r2t, &hdr);
  190. iser_dbg("Sending data-out: itt 0x%x, data count %d\n",
  191. hdr.itt, r2t->data_count);
  192. /* the buffer description has been passed with the command */
  193. /* Send the command */
  194. error = iser_send_data_out(conn, task, &hdr);
  195. if (error) {
  196. r2t->datasn--;
  197. goto iscsi_iser_task_xmit_unsol_data_exit;
  198. }
  199. r2t->sent += r2t->data_count;
  200. iser_dbg("Need to send %d more as data-out PDUs\n",
  201. r2t->data_length - r2t->sent);
  202. }
  203. iscsi_iser_task_xmit_unsol_data_exit:
  204. return error;
  205. }
  206. static int
  207. iscsi_iser_task_xmit(struct iscsi_task *task)
  208. {
  209. struct iscsi_conn *conn = task->conn;
  210. struct iscsi_iser_task *iser_task = task->dd_data;
  211. int error = 0;
  212. if (!task->sc)
  213. return iscsi_iser_mtask_xmit(conn, task);
  214. if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
  215. BUG_ON(scsi_bufflen(task->sc) == 0);
  216. iser_dbg("cmd [itt %x total %d imm %d unsol_data %d\n",
  217. task->itt, scsi_bufflen(task->sc),
  218. task->imm_count, task->unsol_r2t.data_length);
  219. }
  220. iser_dbg("ctask xmit [cid %d itt 0x%x]\n",
  221. conn->id, task->itt);
  222. /* Send the cmd PDU */
  223. if (!iser_task->command_sent) {
  224. error = iser_send_command(conn, task);
  225. if (error)
  226. goto iscsi_iser_task_xmit_exit;
  227. iser_task->command_sent = 1;
  228. }
  229. /* Send unsolicited data-out PDU(s) if necessary */
  230. if (iscsi_task_has_unsol_data(task))
  231. error = iscsi_iser_task_xmit_unsol_data(conn, task);
  232. iscsi_iser_task_xmit_exit:
  233. return error;
  234. }
  235. static void iscsi_iser_cleanup_task(struct iscsi_task *task)
  236. {
  237. struct iscsi_iser_task *iser_task = task->dd_data;
  238. struct iser_tx_desc *tx_desc = &iser_task->desc;
  239. struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
  240. struct iser_device *device = iser_conn->ib_conn->device;
  241. ib_dma_unmap_single(device->ib_device,
  242. tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
  243. /* mgmt tasks do not need special cleanup */
  244. if (!task->sc)
  245. return;
  246. if (iser_task->status == ISER_TASK_STATUS_STARTED) {
  247. iser_task->status = ISER_TASK_STATUS_COMPLETED;
  248. iser_task_rdma_finalize(iser_task);
  249. }
  250. }
  251. static struct iscsi_cls_conn *
  252. iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  253. {
  254. struct iscsi_conn *conn;
  255. struct iscsi_cls_conn *cls_conn;
  256. struct iscsi_iser_conn *iser_conn;
  257. cls_conn = iscsi_conn_setup(cls_session, sizeof(*iser_conn), conn_idx);
  258. if (!cls_conn)
  259. return NULL;
  260. conn = cls_conn->dd_data;
  261. /*
  262. * due to issues with the login code re iser sematics
  263. * this not set in iscsi_conn_setup - FIXME
  264. */
  265. conn->max_recv_dlength = ISER_RECV_DATA_SEG_LEN;
  266. iser_conn = conn->dd_data;
  267. conn->dd_data = iser_conn;
  268. iser_conn->iscsi_conn = conn;
  269. return cls_conn;
  270. }
  271. static void
  272. iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
  273. {
  274. struct iscsi_conn *conn = cls_conn->dd_data;
  275. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  276. struct iser_conn *ib_conn = iser_conn->ib_conn;
  277. iscsi_conn_teardown(cls_conn);
  278. /*
  279. * Userspace will normally call the stop callback and
  280. * already have freed the ib_conn, but if it goofed up then
  281. * we free it here.
  282. */
  283. if (ib_conn) {
  284. ib_conn->iser_conn = NULL;
  285. iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
  286. }
  287. }
  288. static int
  289. iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
  290. struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
  291. int is_leading)
  292. {
  293. struct iscsi_conn *conn = cls_conn->dd_data;
  294. struct iscsi_iser_conn *iser_conn;
  295. struct iscsi_session *session;
  296. struct iser_conn *ib_conn;
  297. struct iscsi_endpoint *ep;
  298. int error;
  299. error = iscsi_conn_bind(cls_session, cls_conn, is_leading);
  300. if (error)
  301. return error;
  302. /* the transport ep handle comes from user space so it must be
  303. * verified against the global ib connections list */
  304. ep = iscsi_lookup_endpoint(transport_eph);
  305. if (!ep) {
  306. iser_err("can't bind eph %llx\n",
  307. (unsigned long long)transport_eph);
  308. return -EINVAL;
  309. }
  310. ib_conn = ep->dd_data;
  311. session = conn->session;
  312. if (iser_alloc_rx_descriptors(ib_conn, session))
  313. return -ENOMEM;
  314. /* binds the iSER connection retrieved from the previously
  315. * connected ep_handle to the iSCSI layer connection. exchanges
  316. * connection pointers */
  317. iser_info("binding iscsi/iser conn %p %p to ib_conn %p\n",
  318. conn, conn->dd_data, ib_conn);
  319. iser_conn = conn->dd_data;
  320. ib_conn->iser_conn = iser_conn;
  321. iser_conn->ib_conn = ib_conn;
  322. iser_conn_get(ib_conn); /* ref iscsi/ib conn binding */
  323. return 0;
  324. }
  325. static void
  326. iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
  327. {
  328. struct iscsi_conn *conn = cls_conn->dd_data;
  329. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  330. struct iser_conn *ib_conn = iser_conn->ib_conn;
  331. /*
  332. * Userspace may have goofed up and not bound the connection or
  333. * might have only partially setup the connection.
  334. */
  335. if (ib_conn) {
  336. iscsi_conn_stop(cls_conn, flag);
  337. /*
  338. * There is no unbind event so the stop callback
  339. * must release the ref from the bind.
  340. */
  341. iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
  342. }
  343. iser_conn->ib_conn = NULL;
  344. }
  345. static void iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
  346. {
  347. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  348. iscsi_session_teardown(cls_session);
  349. iscsi_host_remove(shost);
  350. iscsi_host_free(shost);
  351. }
  352. static struct iscsi_cls_session *
  353. iscsi_iser_session_create(struct iscsi_endpoint *ep,
  354. uint16_t cmds_max, uint16_t qdepth,
  355. uint32_t initial_cmdsn)
  356. {
  357. struct iscsi_cls_session *cls_session;
  358. struct iscsi_session *session;
  359. struct Scsi_Host *shost;
  360. struct iser_conn *ib_conn = NULL;
  361. shost = iscsi_host_alloc(&iscsi_iser_sht, 0, 0);
  362. if (!shost)
  363. return NULL;
  364. shost->transportt = iscsi_iser_scsi_transport;
  365. shost->cmd_per_lun = qdepth;
  366. shost->max_lun = iscsi_max_lun;
  367. shost->max_id = 0;
  368. shost->max_channel = 0;
  369. shost->max_cmd_len = 16;
  370. /*
  371. * older userspace tools (before 2.0-870) did not pass us
  372. * the leading conn's ep so this will be NULL;
  373. */
  374. if (ep)
  375. ib_conn = ep->dd_data;
  376. if (iscsi_host_add(shost,
  377. ep ? ib_conn->device->ib_device->dma_device : NULL))
  378. goto free_host;
  379. if (cmds_max > ISER_DEF_XMIT_CMDS_MAX) {
  380. iser_info("cmds_max changed from %u to %u\n",
  381. cmds_max, ISER_DEF_XMIT_CMDS_MAX);
  382. cmds_max = ISER_DEF_XMIT_CMDS_MAX;
  383. }
  384. cls_session = iscsi_session_setup(&iscsi_iser_transport, shost,
  385. cmds_max, 0,
  386. sizeof(struct iscsi_iser_task),
  387. initial_cmdsn, 0);
  388. if (!cls_session)
  389. goto remove_host;
  390. session = cls_session->dd_data;
  391. shost->can_queue = session->scsi_cmds_max;
  392. return cls_session;
  393. remove_host:
  394. iscsi_host_remove(shost);
  395. free_host:
  396. iscsi_host_free(shost);
  397. return NULL;
  398. }
  399. static int
  400. iscsi_iser_set_param(struct iscsi_cls_conn *cls_conn,
  401. enum iscsi_param param, char *buf, int buflen)
  402. {
  403. int value;
  404. switch (param) {
  405. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  406. /* TBD */
  407. break;
  408. case ISCSI_PARAM_HDRDGST_EN:
  409. sscanf(buf, "%d", &value);
  410. if (value) {
  411. iser_err("DataDigest wasn't negotiated to None");
  412. return -EPROTO;
  413. }
  414. break;
  415. case ISCSI_PARAM_DATADGST_EN:
  416. sscanf(buf, "%d", &value);
  417. if (value) {
  418. iser_err("DataDigest wasn't negotiated to None");
  419. return -EPROTO;
  420. }
  421. break;
  422. case ISCSI_PARAM_IFMARKER_EN:
  423. sscanf(buf, "%d", &value);
  424. if (value) {
  425. iser_err("IFMarker wasn't negotiated to No");
  426. return -EPROTO;
  427. }
  428. break;
  429. case ISCSI_PARAM_OFMARKER_EN:
  430. sscanf(buf, "%d", &value);
  431. if (value) {
  432. iser_err("OFMarker wasn't negotiated to No");
  433. return -EPROTO;
  434. }
  435. break;
  436. default:
  437. return iscsi_set_param(cls_conn, param, buf, buflen);
  438. }
  439. return 0;
  440. }
  441. static void
  442. iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
  443. {
  444. struct iscsi_conn *conn = cls_conn->dd_data;
  445. stats->txdata_octets = conn->txdata_octets;
  446. stats->rxdata_octets = conn->rxdata_octets;
  447. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  448. stats->dataout_pdus = conn->dataout_pdus_cnt;
  449. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  450. stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
  451. stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
  452. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  453. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  454. stats->custom_length = 4;
  455. strcpy(stats->custom[0].desc, "qp_tx_queue_full");
  456. stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
  457. strcpy(stats->custom[1].desc, "fmr_map_not_avail");
  458. stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
  459. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  460. stats->custom[2].value = conn->eh_abort_cnt;
  461. strcpy(stats->custom[3].desc, "fmr_unalign_cnt");
  462. stats->custom[3].value = conn->fmr_unalign_cnt;
  463. }
  464. static int iscsi_iser_get_ep_param(struct iscsi_endpoint *ep,
  465. enum iscsi_param param, char *buf)
  466. {
  467. struct iser_conn *ib_conn = ep->dd_data;
  468. int len;
  469. switch (param) {
  470. case ISCSI_PARAM_CONN_PORT:
  471. case ISCSI_PARAM_CONN_ADDRESS:
  472. if (!ib_conn || !ib_conn->cma_id)
  473. return -ENOTCONN;
  474. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  475. &ib_conn->cma_id->route.addr.dst_addr,
  476. param, buf);
  477. break;
  478. default:
  479. return -ENOSYS;
  480. }
  481. return len;
  482. }
  483. static struct iscsi_endpoint *
  484. iscsi_iser_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  485. int non_blocking)
  486. {
  487. int err;
  488. struct iser_conn *ib_conn;
  489. struct iscsi_endpoint *ep;
  490. ep = iscsi_create_endpoint(sizeof(*ib_conn));
  491. if (!ep)
  492. return ERR_PTR(-ENOMEM);
  493. ib_conn = ep->dd_data;
  494. ib_conn->ep = ep;
  495. iser_conn_init(ib_conn);
  496. err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr,
  497. non_blocking);
  498. if (err)
  499. return ERR_PTR(err);
  500. return ep;
  501. }
  502. static int
  503. iscsi_iser_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  504. {
  505. struct iser_conn *ib_conn;
  506. int rc;
  507. ib_conn = ep->dd_data;
  508. rc = wait_event_interruptible_timeout(ib_conn->wait,
  509. ib_conn->state == ISER_CONN_UP,
  510. msecs_to_jiffies(timeout_ms));
  511. /* if conn establishment failed, return error code to iscsi */
  512. if (!rc &&
  513. (ib_conn->state == ISER_CONN_TERMINATING ||
  514. ib_conn->state == ISER_CONN_DOWN))
  515. rc = -1;
  516. iser_info("ib conn %p rc = %d\n", ib_conn, rc);
  517. if (rc > 0)
  518. return 1; /* success, this is the equivalent of POLLOUT */
  519. else if (!rc)
  520. return 0; /* timeout */
  521. else
  522. return rc; /* signal */
  523. }
  524. static void
  525. iscsi_iser_ep_disconnect(struct iscsi_endpoint *ep)
  526. {
  527. struct iser_conn *ib_conn;
  528. ib_conn = ep->dd_data;
  529. if (ib_conn->iser_conn)
  530. /*
  531. * Must suspend xmit path if the ep is bound to the
  532. * iscsi_conn, so we know we are not accessing the ib_conn
  533. * when we free it.
  534. *
  535. * This may not be bound if the ep poll failed.
  536. */
  537. iscsi_suspend_tx(ib_conn->iser_conn->iscsi_conn);
  538. iser_info("ib conn %p state %d\n", ib_conn, ib_conn->state);
  539. iser_conn_terminate(ib_conn);
  540. }
  541. static umode_t iser_attr_is_visible(int param_type, int param)
  542. {
  543. switch (param_type) {
  544. case ISCSI_HOST_PARAM:
  545. switch (param) {
  546. case ISCSI_HOST_PARAM_NETDEV_NAME:
  547. case ISCSI_HOST_PARAM_HWADDRESS:
  548. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  549. return S_IRUGO;
  550. default:
  551. return 0;
  552. }
  553. case ISCSI_PARAM:
  554. switch (param) {
  555. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  556. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  557. case ISCSI_PARAM_HDRDGST_EN:
  558. case ISCSI_PARAM_DATADGST_EN:
  559. case ISCSI_PARAM_CONN_ADDRESS:
  560. case ISCSI_PARAM_CONN_PORT:
  561. case ISCSI_PARAM_EXP_STATSN:
  562. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  563. case ISCSI_PARAM_PERSISTENT_PORT:
  564. case ISCSI_PARAM_PING_TMO:
  565. case ISCSI_PARAM_RECV_TMO:
  566. case ISCSI_PARAM_INITIAL_R2T_EN:
  567. case ISCSI_PARAM_MAX_R2T:
  568. case ISCSI_PARAM_IMM_DATA_EN:
  569. case ISCSI_PARAM_FIRST_BURST:
  570. case ISCSI_PARAM_MAX_BURST:
  571. case ISCSI_PARAM_PDU_INORDER_EN:
  572. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  573. case ISCSI_PARAM_TARGET_NAME:
  574. case ISCSI_PARAM_TPGT:
  575. case ISCSI_PARAM_USERNAME:
  576. case ISCSI_PARAM_PASSWORD:
  577. case ISCSI_PARAM_USERNAME_IN:
  578. case ISCSI_PARAM_PASSWORD_IN:
  579. case ISCSI_PARAM_FAST_ABORT:
  580. case ISCSI_PARAM_ABORT_TMO:
  581. case ISCSI_PARAM_LU_RESET_TMO:
  582. case ISCSI_PARAM_TGT_RESET_TMO:
  583. case ISCSI_PARAM_IFACE_NAME:
  584. case ISCSI_PARAM_INITIATOR_NAME:
  585. case ISCSI_PARAM_DISCOVERY_SESS:
  586. return S_IRUGO;
  587. default:
  588. return 0;
  589. }
  590. }
  591. return 0;
  592. }
  593. static struct scsi_host_template iscsi_iser_sht = {
  594. .module = THIS_MODULE,
  595. .name = "iSCSI Initiator over iSER",
  596. .queuecommand = iscsi_queuecommand,
  597. .change_queue_depth = iscsi_change_queue_depth,
  598. .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
  599. .max_sectors = 1024,
  600. .cmd_per_lun = ISER_DEF_CMD_PER_LUN,
  601. .eh_abort_handler = iscsi_eh_abort,
  602. .eh_device_reset_handler= iscsi_eh_device_reset,
  603. .eh_target_reset_handler = iscsi_eh_recover_target,
  604. .target_alloc = iscsi_target_alloc,
  605. .use_clustering = DISABLE_CLUSTERING,
  606. .proc_name = "iscsi_iser",
  607. .this_id = -1,
  608. };
  609. static struct iscsi_transport iscsi_iser_transport = {
  610. .owner = THIS_MODULE,
  611. .name = "iser",
  612. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_TEXT_NEGO,
  613. /* session management */
  614. .create_session = iscsi_iser_session_create,
  615. .destroy_session = iscsi_iser_session_destroy,
  616. /* connection management */
  617. .create_conn = iscsi_iser_conn_create,
  618. .bind_conn = iscsi_iser_conn_bind,
  619. .destroy_conn = iscsi_iser_conn_destroy,
  620. .attr_is_visible = iser_attr_is_visible,
  621. .set_param = iscsi_iser_set_param,
  622. .get_conn_param = iscsi_conn_get_param,
  623. .get_ep_param = iscsi_iser_get_ep_param,
  624. .get_session_param = iscsi_session_get_param,
  625. .start_conn = iscsi_conn_start,
  626. .stop_conn = iscsi_iser_conn_stop,
  627. /* iscsi host params */
  628. .get_host_param = iscsi_host_get_param,
  629. .set_host_param = iscsi_host_set_param,
  630. /* IO */
  631. .send_pdu = iscsi_conn_send_pdu,
  632. .get_stats = iscsi_iser_conn_get_stats,
  633. .init_task = iscsi_iser_task_init,
  634. .xmit_task = iscsi_iser_task_xmit,
  635. .cleanup_task = iscsi_iser_cleanup_task,
  636. .alloc_pdu = iscsi_iser_pdu_alloc,
  637. /* recovery */
  638. .session_recovery_timedout = iscsi_session_recovery_timedout,
  639. .ep_connect = iscsi_iser_ep_connect,
  640. .ep_poll = iscsi_iser_ep_poll,
  641. .ep_disconnect = iscsi_iser_ep_disconnect
  642. };
  643. static int __init iser_init(void)
  644. {
  645. int err;
  646. iser_dbg("Starting iSER datamover...\n");
  647. if (iscsi_max_lun < 1) {
  648. iser_err("Invalid max_lun value of %u\n", iscsi_max_lun);
  649. return -EINVAL;
  650. }
  651. memset(&ig, 0, sizeof(struct iser_global));
  652. ig.desc_cache = kmem_cache_create("iser_descriptors",
  653. sizeof(struct iser_tx_desc),
  654. 0, SLAB_HWCACHE_ALIGN,
  655. NULL);
  656. if (ig.desc_cache == NULL)
  657. return -ENOMEM;
  658. /* device init is called only after the first addr resolution */
  659. mutex_init(&ig.device_list_mutex);
  660. INIT_LIST_HEAD(&ig.device_list);
  661. mutex_init(&ig.connlist_mutex);
  662. INIT_LIST_HEAD(&ig.connlist);
  663. iscsi_iser_scsi_transport = iscsi_register_transport(
  664. &iscsi_iser_transport);
  665. if (!iscsi_iser_scsi_transport) {
  666. iser_err("iscsi_register_transport failed\n");
  667. err = -EINVAL;
  668. goto register_transport_failure;
  669. }
  670. return 0;
  671. register_transport_failure:
  672. kmem_cache_destroy(ig.desc_cache);
  673. return err;
  674. }
  675. static void __exit iser_exit(void)
  676. {
  677. iser_dbg("Removing iSER datamover...\n");
  678. iscsi_unregister_transport(&iscsi_iser_transport);
  679. kmem_cache_destroy(ig.desc_cache);
  680. }
  681. module_init(iser_init);
  682. module_exit(iser_exit);