iscsi_iser.c 21 KB

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