iscsi_iser.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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/devfs_fs_kernel.h>
  57. #include <linux/cdev.h>
  58. #include <linux/in.h>
  59. #include <linux/net.h>
  60. #include <linux/scatterlist.h>
  61. #include <linux/delay.h>
  62. #include <net/sock.h>
  63. #include <asm/uaccess.h>
  64. #include <scsi/scsi_cmnd.h>
  65. #include <scsi/scsi_device.h>
  66. #include <scsi/scsi_eh.h>
  67. #include <scsi/scsi_tcq.h>
  68. #include <scsi/scsi_host.h>
  69. #include <scsi/scsi.h>
  70. #include <scsi/scsi_transport_iscsi.h>
  71. #include "iscsi_iser.h"
  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. uint32_t ret_itt;
  88. int datalen;
  89. int ahslen;
  90. /* verify PDU length */
  91. datalen = ntoh24(hdr->dlength);
  92. if (datalen != rx_data_len) {
  93. printk(KERN_ERR "iscsi_iser: datalen %d (hdr) != %d (IB) \n",
  94. datalen, rx_data_len);
  95. rc = ISCSI_ERR_DATALEN;
  96. goto error;
  97. }
  98. /* read AHS */
  99. ahslen = hdr->hlength * 4;
  100. /* verify itt (itt encoding: age+cid+itt) */
  101. rc = iscsi_verify_itt(conn, hdr, &ret_itt);
  102. if (!rc)
  103. rc = iscsi_complete_pdu(conn, hdr, rx_data, rx_data_len);
  104. if (rc && rc != ISCSI_ERR_NO_SCSI_CMD)
  105. goto error;
  106. return;
  107. error:
  108. iscsi_conn_failure(conn, rc);
  109. }
  110. /**
  111. * iscsi_iser_cmd_init - Initialize iSCSI SCSI_READ or SCSI_WRITE commands
  112. *
  113. **/
  114. static void
  115. iscsi_iser_cmd_init(struct iscsi_cmd_task *ctask)
  116. {
  117. struct iscsi_iser_conn *iser_conn = ctask->conn->dd_data;
  118. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  119. struct scsi_cmnd *sc = ctask->sc;
  120. iser_ctask->command_sent = 0;
  121. iser_ctask->iser_conn = iser_conn;
  122. if (sc->sc_data_direction == DMA_TO_DEVICE) {
  123. BUG_ON(ctask->total_length == 0);
  124. /* bytes to be sent via RDMA operations */
  125. iser_ctask->rdma_data_count = ctask->total_length -
  126. ctask->imm_count -
  127. ctask->unsol_count;
  128. debug_scsi("cmd [itt %x total %d imm %d unsol_data %d "
  129. "rdma_data %d]\n",
  130. ctask->itt, ctask->total_length, ctask->imm_count,
  131. ctask->unsol_count, iser_ctask->rdma_data_count);
  132. } else
  133. /* bytes to be sent via RDMA operations */
  134. iser_ctask->rdma_data_count = ctask->total_length;
  135. iser_ctask_rdma_init(iser_ctask);
  136. }
  137. /**
  138. * iscsi_mtask_xmit - xmit management(immediate) task
  139. * @conn: iscsi connection
  140. * @mtask: task management task
  141. *
  142. * Notes:
  143. * The function can return -EAGAIN in which case caller must
  144. * call it again later, or recover. '0' return code means successful
  145. * xmit.
  146. *
  147. **/
  148. static int
  149. iscsi_iser_mtask_xmit(struct iscsi_conn *conn,
  150. struct iscsi_mgmt_task *mtask)
  151. {
  152. int error = 0;
  153. debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id, mtask->itt);
  154. error = iser_send_control(conn, mtask);
  155. /* since iser xmits control with zero copy, mtasks can not be recycled
  156. * right after sending them.
  157. * The recycling scheme is based on whether a response is expected
  158. * - if yes, the mtask is recycled at iscsi_complete_pdu
  159. * - if no, the mtask is recycled at iser_snd_completion
  160. */
  161. if (error && error != -EAGAIN)
  162. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  163. return error;
  164. }
  165. static int
  166. iscsi_iser_ctask_xmit_unsol_data(struct iscsi_conn *conn,
  167. struct iscsi_cmd_task *ctask)
  168. {
  169. struct iscsi_data hdr;
  170. int error = 0;
  171. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  172. /* Send data-out PDUs while there's still unsolicited data to send */
  173. while (ctask->unsol_count > 0) {
  174. iscsi_prep_unsolicit_data_pdu(ctask, &hdr,
  175. iser_ctask->rdma_data_count);
  176. debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
  177. hdr.itt, ctask->data_count);
  178. /* the buffer description has been passed with the command */
  179. /* Send the command */
  180. error = iser_send_data_out(conn, ctask, &hdr);
  181. if (error) {
  182. ctask->unsol_datasn--;
  183. goto iscsi_iser_ctask_xmit_unsol_data_exit;
  184. }
  185. ctask->unsol_count -= ctask->data_count;
  186. debug_scsi("Need to send %d more as data-out PDUs\n",
  187. ctask->unsol_count);
  188. }
  189. iscsi_iser_ctask_xmit_unsol_data_exit:
  190. return error;
  191. }
  192. static int
  193. iscsi_iser_ctask_xmit(struct iscsi_conn *conn,
  194. struct iscsi_cmd_task *ctask)
  195. {
  196. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  197. int error = 0;
  198. debug_scsi("ctask deq [cid %d itt 0x%x]\n",
  199. conn->id, ctask->itt);
  200. /*
  201. * serialize with TMF AbortTask
  202. */
  203. if (ctask->mtask)
  204. return error;
  205. /* Send the cmd PDU */
  206. if (!iser_ctask->command_sent) {
  207. error = iser_send_command(conn, ctask);
  208. if (error)
  209. goto iscsi_iser_ctask_xmit_exit;
  210. iser_ctask->command_sent = 1;
  211. }
  212. /* Send unsolicited data-out PDU(s) if necessary */
  213. if (ctask->unsol_count)
  214. error = iscsi_iser_ctask_xmit_unsol_data(conn, ctask);
  215. iscsi_iser_ctask_xmit_exit:
  216. if (error && error != -EAGAIN)
  217. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  218. return error;
  219. }
  220. static void
  221. iscsi_iser_cleanup_ctask(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
  222. {
  223. struct iscsi_iser_cmd_task *iser_ctask = ctask->dd_data;
  224. if (iser_ctask->status == ISER_TASK_STATUS_STARTED) {
  225. iser_ctask->status = ISER_TASK_STATUS_COMPLETED;
  226. iser_ctask_rdma_finalize(iser_ctask);
  227. }
  228. }
  229. static struct iser_conn *
  230. iscsi_iser_ib_conn_lookup(__u64 ep_handle)
  231. {
  232. struct iser_conn *ib_conn;
  233. struct iser_conn *uib_conn = (struct iser_conn *)(unsigned long)ep_handle;
  234. mutex_lock(&ig.connlist_mutex);
  235. list_for_each_entry(ib_conn, &ig.connlist, conn_list) {
  236. if (ib_conn == uib_conn) {
  237. mutex_unlock(&ig.connlist_mutex);
  238. return ib_conn;
  239. }
  240. }
  241. mutex_unlock(&ig.connlist_mutex);
  242. iser_err("no conn exists for eph %llx\n",(unsigned long long)ep_handle);
  243. return NULL;
  244. }
  245. static struct iscsi_cls_conn *
  246. iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
  247. {
  248. struct iscsi_conn *conn;
  249. struct iscsi_cls_conn *cls_conn;
  250. struct iscsi_iser_conn *iser_conn;
  251. cls_conn = iscsi_conn_setup(cls_session, conn_idx);
  252. if (!cls_conn)
  253. return NULL;
  254. conn = cls_conn->dd_data;
  255. /*
  256. * due to issues with the login code re iser sematics
  257. * this not set in iscsi_conn_setup - FIXME
  258. */
  259. conn->max_recv_dlength = 128;
  260. iser_conn = kzalloc(sizeof(*iser_conn), GFP_KERNEL);
  261. if (!iser_conn)
  262. goto conn_alloc_fail;
  263. /* currently this is the only field which need to be initiated */
  264. rwlock_init(&iser_conn->lock);
  265. conn->dd_data = iser_conn;
  266. iser_conn->iscsi_conn = conn;
  267. return cls_conn;
  268. conn_alloc_fail:
  269. iscsi_conn_teardown(cls_conn);
  270. return NULL;
  271. }
  272. static void
  273. iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
  274. {
  275. struct iscsi_conn *conn = cls_conn->dd_data;
  276. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  277. iscsi_conn_teardown(cls_conn);
  278. kfree(iser_conn);
  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. 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. ib_conn = iscsi_iser_ib_conn_lookup(transport_eph);
  295. if (!ib_conn) {
  296. iser_err("can't bind eph %llx\n",
  297. (unsigned long long)transport_eph);
  298. return -EINVAL;
  299. }
  300. /* binds the iSER connection retrieved from the previously
  301. * connected ep_handle to the iSCSI layer connection. exchanges
  302. * connection pointers */
  303. iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
  304. iser_conn = conn->dd_data;
  305. ib_conn->iser_conn = iser_conn;
  306. iser_conn->ib_conn = ib_conn;
  307. conn->recv_lock = &iser_conn->lock;
  308. return 0;
  309. }
  310. static int
  311. iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
  312. {
  313. struct iscsi_conn *conn = cls_conn->dd_data;
  314. int err;
  315. err = iscsi_conn_start(cls_conn);
  316. if (err)
  317. return err;
  318. return iser_conn_set_full_featured_mode(conn);
  319. }
  320. static void
  321. iscsi_iser_conn_terminate(struct iscsi_conn *conn)
  322. {
  323. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  324. struct iser_conn *ib_conn = iser_conn->ib_conn;
  325. BUG_ON(!ib_conn);
  326. /* starts conn teardown process, waits until all previously *
  327. * posted buffers get flushed, deallocates all conn resources */
  328. iser_conn_terminate(ib_conn);
  329. iser_conn->ib_conn = NULL;
  330. conn->recv_lock = NULL;
  331. }
  332. static struct iscsi_transport iscsi_iser_transport;
  333. static struct iscsi_cls_session *
  334. iscsi_iser_session_create(struct iscsi_transport *iscsit,
  335. struct scsi_transport_template *scsit,
  336. uint32_t initial_cmdsn, uint32_t *hostno)
  337. {
  338. struct iscsi_cls_session *cls_session;
  339. struct iscsi_session *session;
  340. int i;
  341. uint32_t hn;
  342. struct iscsi_cmd_task *ctask;
  343. struct iscsi_mgmt_task *mtask;
  344. struct iscsi_iser_cmd_task *iser_ctask;
  345. struct iser_desc *desc;
  346. cls_session = iscsi_session_setup(iscsit, scsit,
  347. sizeof(struct iscsi_iser_cmd_task),
  348. sizeof(struct iser_desc),
  349. initial_cmdsn, &hn);
  350. if (!cls_session)
  351. return NULL;
  352. *hostno = hn;
  353. session = class_to_transport_session(cls_session);
  354. /* libiscsi setup itts, data and pool so just set desc fields */
  355. for (i = 0; i < session->cmds_max; i++) {
  356. ctask = session->cmds[i];
  357. iser_ctask = ctask->dd_data;
  358. ctask->hdr = (struct iscsi_cmd *)&iser_ctask->desc.iscsi_header;
  359. }
  360. for (i = 0; i < session->mgmtpool_max; i++) {
  361. mtask = session->mgmt_cmds[i];
  362. desc = mtask->dd_data;
  363. mtask->hdr = &desc->iscsi_header;
  364. desc->data = mtask->data;
  365. }
  366. return cls_session;
  367. }
  368. static int
  369. iscsi_iser_conn_set_param(struct iscsi_cls_conn *cls_conn,
  370. enum iscsi_param param, uint32_t value)
  371. {
  372. struct iscsi_conn *conn = cls_conn->dd_data;
  373. struct iscsi_session *session = conn->session;
  374. spin_lock_bh(&session->lock);
  375. if (conn->c_stage != ISCSI_CONN_INITIAL_STAGE &&
  376. conn->stop_stage != STOP_CONN_RECOVER) {
  377. printk(KERN_ERR "iscsi_iser: can not change parameter [%d]\n",
  378. param);
  379. spin_unlock_bh(&session->lock);
  380. return 0;
  381. }
  382. spin_unlock_bh(&session->lock);
  383. switch (param) {
  384. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  385. /* TBD */
  386. break;
  387. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  388. conn->max_xmit_dlength = value;
  389. break;
  390. case ISCSI_PARAM_HDRDGST_EN:
  391. if (value) {
  392. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  393. return -EPROTO;
  394. }
  395. break;
  396. case ISCSI_PARAM_DATADGST_EN:
  397. if (value) {
  398. printk(KERN_ERR "DataDigest wasn't negotiated to None");
  399. return -EPROTO;
  400. }
  401. break;
  402. case ISCSI_PARAM_INITIAL_R2T_EN:
  403. session->initial_r2t_en = value;
  404. break;
  405. case ISCSI_PARAM_IMM_DATA_EN:
  406. session->imm_data_en = value;
  407. break;
  408. case ISCSI_PARAM_FIRST_BURST:
  409. session->first_burst = value;
  410. break;
  411. case ISCSI_PARAM_MAX_BURST:
  412. session->max_burst = value;
  413. break;
  414. case ISCSI_PARAM_PDU_INORDER_EN:
  415. session->pdu_inorder_en = value;
  416. break;
  417. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  418. session->dataseq_inorder_en = value;
  419. break;
  420. case ISCSI_PARAM_ERL:
  421. session->erl = value;
  422. break;
  423. case ISCSI_PARAM_IFMARKER_EN:
  424. if (value) {
  425. printk(KERN_ERR "IFMarker wasn't negotiated to No");
  426. return -EPROTO;
  427. }
  428. break;
  429. case ISCSI_PARAM_OFMARKER_EN:
  430. if (value) {
  431. printk(KERN_ERR "OFMarker wasn't negotiated to No");
  432. return -EPROTO;
  433. }
  434. break;
  435. default:
  436. break;
  437. }
  438. return 0;
  439. }
  440. static int
  441. iscsi_iser_session_get_param(struct iscsi_cls_session *cls_session,
  442. enum iscsi_param param, uint32_t *value)
  443. {
  444. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  445. struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
  446. switch (param) {
  447. case ISCSI_PARAM_INITIAL_R2T_EN:
  448. *value = session->initial_r2t_en;
  449. break;
  450. case ISCSI_PARAM_MAX_R2T:
  451. *value = session->max_r2t;
  452. break;
  453. case ISCSI_PARAM_IMM_DATA_EN:
  454. *value = session->imm_data_en;
  455. break;
  456. case ISCSI_PARAM_FIRST_BURST:
  457. *value = session->first_burst;
  458. break;
  459. case ISCSI_PARAM_MAX_BURST:
  460. *value = session->max_burst;
  461. break;
  462. case ISCSI_PARAM_PDU_INORDER_EN:
  463. *value = session->pdu_inorder_en;
  464. break;
  465. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  466. *value = session->dataseq_inorder_en;
  467. break;
  468. case ISCSI_PARAM_ERL:
  469. *value = session->erl;
  470. break;
  471. case ISCSI_PARAM_IFMARKER_EN:
  472. *value = 0;
  473. break;
  474. case ISCSI_PARAM_OFMARKER_EN:
  475. *value = 0;
  476. break;
  477. default:
  478. return ISCSI_ERR_PARAM_NOT_FOUND;
  479. }
  480. return 0;
  481. }
  482. static int
  483. iscsi_iser_conn_get_param(struct iscsi_cls_conn *cls_conn,
  484. enum iscsi_param param, uint32_t *value)
  485. {
  486. struct iscsi_conn *conn = cls_conn->dd_data;
  487. switch(param) {
  488. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  489. *value = conn->max_recv_dlength;
  490. break;
  491. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  492. *value = conn->max_xmit_dlength;
  493. break;
  494. case ISCSI_PARAM_HDRDGST_EN:
  495. *value = 0;
  496. break;
  497. case ISCSI_PARAM_DATADGST_EN:
  498. *value = 0;
  499. break;
  500. /*case ISCSI_PARAM_TARGET_RECV_DLENGTH:
  501. *value = conn->target_recv_dlength;
  502. break;
  503. case ISCSI_PARAM_INITIATOR_RECV_DLENGTH:
  504. *value = conn->initiator_recv_dlength;
  505. break;*/
  506. default:
  507. return ISCSI_ERR_PARAM_NOT_FOUND;
  508. }
  509. return 0;
  510. }
  511. static void
  512. iscsi_iser_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
  513. {
  514. struct iscsi_conn *conn = cls_conn->dd_data;
  515. stats->txdata_octets = conn->txdata_octets;
  516. stats->rxdata_octets = conn->rxdata_octets;
  517. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  518. stats->dataout_pdus = conn->dataout_pdus_cnt;
  519. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  520. stats->datain_pdus = conn->datain_pdus_cnt; /* always 0 */
  521. stats->r2t_pdus = conn->r2t_pdus_cnt; /* always 0 */
  522. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  523. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  524. stats->custom_length = 3;
  525. strcpy(stats->custom[0].desc, "qp_tx_queue_full");
  526. stats->custom[0].value = 0; /* TB iser_conn->qp_tx_queue_full; */
  527. strcpy(stats->custom[1].desc, "fmr_map_not_avail");
  528. stats->custom[1].value = 0; /* TB iser_conn->fmr_map_not_avail */;
  529. strcpy(stats->custom[2].desc, "eh_abort_cnt");
  530. stats->custom[2].value = conn->eh_abort_cnt;
  531. }
  532. static int
  533. iscsi_iser_ep_connect(struct sockaddr *dst_addr, int non_blocking,
  534. __u64 *ep_handle)
  535. {
  536. int err;
  537. struct iser_conn *ib_conn;
  538. err = iser_conn_init(&ib_conn);
  539. if (err)
  540. goto out;
  541. err = iser_connect(ib_conn, NULL, (struct sockaddr_in *)dst_addr, non_blocking);
  542. if (!err)
  543. *ep_handle = (__u64)(unsigned long)ib_conn;
  544. out:
  545. return err;
  546. }
  547. static int
  548. iscsi_iser_ep_poll(__u64 ep_handle, int timeout_ms)
  549. {
  550. struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
  551. int rc;
  552. if (!ib_conn)
  553. return -EINVAL;
  554. rc = wait_event_interruptible_timeout(ib_conn->wait,
  555. ib_conn->state == ISER_CONN_UP,
  556. msecs_to_jiffies(timeout_ms));
  557. /* if conn establishment failed, return error code to iscsi */
  558. if (!rc &&
  559. (ib_conn->state == ISER_CONN_TERMINATING ||
  560. ib_conn->state == ISER_CONN_DOWN))
  561. rc = -1;
  562. iser_err("ib conn %p rc = %d\n", ib_conn, rc);
  563. if (rc > 0)
  564. return 1; /* success, this is the equivalent of POLLOUT */
  565. else if (!rc)
  566. return 0; /* timeout */
  567. else
  568. return rc; /* signal */
  569. }
  570. static void
  571. iscsi_iser_ep_disconnect(__u64 ep_handle)
  572. {
  573. struct iser_conn *ib_conn = iscsi_iser_ib_conn_lookup(ep_handle);
  574. if (!ib_conn)
  575. return;
  576. iser_err("ib conn %p state %d\n",ib_conn, ib_conn->state);
  577. iser_conn_terminate(ib_conn);
  578. }
  579. static struct scsi_host_template iscsi_iser_sht = {
  580. .name = "iSCSI Initiator over iSER, v." DRV_VER,
  581. .queuecommand = iscsi_queuecommand,
  582. .can_queue = ISCSI_XMIT_CMDS_MAX - 1,
  583. .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
  584. .cmd_per_lun = ISCSI_MAX_CMD_PER_LUN,
  585. .eh_abort_handler = iscsi_eh_abort,
  586. .eh_host_reset_handler = iscsi_eh_host_reset,
  587. .use_clustering = DISABLE_CLUSTERING,
  588. .proc_name = "iscsi_iser",
  589. .this_id = -1,
  590. };
  591. static struct iscsi_transport iscsi_iser_transport = {
  592. .owner = THIS_MODULE,
  593. .name = "iser",
  594. .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T,
  595. .param_mask = ISCSI_MAX_RECV_DLENGTH |
  596. ISCSI_MAX_XMIT_DLENGTH |
  597. ISCSI_HDRDGST_EN |
  598. ISCSI_DATADGST_EN |
  599. ISCSI_INITIAL_R2T_EN |
  600. ISCSI_MAX_R2T |
  601. ISCSI_IMM_DATA_EN |
  602. ISCSI_FIRST_BURST |
  603. ISCSI_MAX_BURST |
  604. ISCSI_PDU_INORDER_EN |
  605. ISCSI_DATASEQ_INORDER_EN,
  606. .host_template = &iscsi_iser_sht,
  607. .conndata_size = sizeof(struct iscsi_conn),
  608. .max_lun = ISCSI_ISER_MAX_LUN,
  609. .max_cmd_len = ISCSI_ISER_MAX_CMD_LEN,
  610. /* session management */
  611. .create_session = iscsi_iser_session_create,
  612. .destroy_session = iscsi_session_teardown,
  613. /* connection management */
  614. .create_conn = iscsi_iser_conn_create,
  615. .bind_conn = iscsi_iser_conn_bind,
  616. .destroy_conn = iscsi_iser_conn_destroy,
  617. .set_param = iscsi_iser_conn_set_param,
  618. .get_conn_param = iscsi_iser_conn_get_param,
  619. .get_session_param = iscsi_iser_session_get_param,
  620. .start_conn = iscsi_iser_conn_start,
  621. .stop_conn = iscsi_conn_stop,
  622. /* these are called as part of conn recovery */
  623. .suspend_conn_recv = NULL, /* FIXME is/how this relvant to iser? */
  624. .terminate_conn = iscsi_iser_conn_terminate,
  625. /* IO */
  626. .send_pdu = iscsi_conn_send_pdu,
  627. .get_stats = iscsi_iser_conn_get_stats,
  628. .init_cmd_task = iscsi_iser_cmd_init,
  629. .xmit_cmd_task = iscsi_iser_ctask_xmit,
  630. .xmit_mgmt_task = iscsi_iser_mtask_xmit,
  631. .cleanup_cmd_task = iscsi_iser_cleanup_ctask,
  632. /* recovery */
  633. .session_recovery_timedout = iscsi_session_recovery_timedout,
  634. .ep_connect = iscsi_iser_ep_connect,
  635. .ep_poll = iscsi_iser_ep_poll,
  636. .ep_disconnect = iscsi_iser_ep_disconnect
  637. };
  638. static int __init iser_init(void)
  639. {
  640. int err;
  641. iser_dbg("Starting iSER datamover...\n");
  642. if (iscsi_max_lun < 1) {
  643. printk(KERN_ERR "Invalid max_lun value of %u\n", iscsi_max_lun);
  644. return -EINVAL;
  645. }
  646. iscsi_iser_transport.max_lun = iscsi_max_lun;
  647. memset(&ig, 0, sizeof(struct iser_global));
  648. ig.desc_cache = kmem_cache_create("iser_descriptors",
  649. sizeof (struct iser_desc),
  650. 0, SLAB_HWCACHE_ALIGN,
  651. NULL, NULL);
  652. if (ig.desc_cache == NULL)
  653. return -ENOMEM;
  654. /* device init is called only after the first addr resolution */
  655. mutex_init(&ig.device_list_mutex);
  656. INIT_LIST_HEAD(&ig.device_list);
  657. mutex_init(&ig.connlist_mutex);
  658. INIT_LIST_HEAD(&ig.connlist);
  659. if (!iscsi_register_transport(&iscsi_iser_transport)) {
  660. iser_err("iscsi_register_transport failed\n");
  661. err = -EINVAL;
  662. goto register_transport_failure;
  663. }
  664. return 0;
  665. register_transport_failure:
  666. kmem_cache_destroy(ig.desc_cache);
  667. return err;
  668. }
  669. static void __exit iser_exit(void)
  670. {
  671. iser_dbg("Removing iSER datamover...\n");
  672. iscsi_unregister_transport(&iscsi_iser_transport);
  673. kmem_cache_destroy(ig.desc_cache);
  674. }
  675. module_init(iser_init);
  676. module_exit(iser_exit);