iser_initiator.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. * Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/kernel.h>
  33. #include <linux/slab.h>
  34. #include <linux/mm.h>
  35. #include <linux/scatterlist.h>
  36. #include <linux/kfifo.h>
  37. #include <scsi/scsi_cmnd.h>
  38. #include <scsi/scsi_host.h>
  39. #include "iscsi_iser.h"
  40. /* Register user buffer memory and initialize passive rdma
  41. * dto descriptor. Total data size is stored in
  42. * iser_task->data[ISER_DIR_IN].data_len
  43. */
  44. static int iser_prepare_read_cmd(struct iscsi_task *task,
  45. unsigned int edtl)
  46. {
  47. struct iscsi_iser_task *iser_task = task->dd_data;
  48. struct iser_regd_buf *regd_buf;
  49. int err;
  50. struct iser_hdr *hdr = &iser_task->desc.iser_header;
  51. struct iser_data_buf *buf_in = &iser_task->data[ISER_DIR_IN];
  52. err = iser_dma_map_task_data(iser_task,
  53. buf_in,
  54. ISER_DIR_IN,
  55. DMA_FROM_DEVICE);
  56. if (err)
  57. return err;
  58. if (edtl > iser_task->data[ISER_DIR_IN].data_len) {
  59. iser_err("Total data length: %ld, less than EDTL: "
  60. "%d, in READ cmd BHS itt: %d, conn: 0x%p\n",
  61. iser_task->data[ISER_DIR_IN].data_len, edtl,
  62. task->itt, iser_task->iser_conn);
  63. return -EINVAL;
  64. }
  65. err = iser_reg_rdma_mem(iser_task,ISER_DIR_IN);
  66. if (err) {
  67. iser_err("Failed to set up Data-IN RDMA\n");
  68. return err;
  69. }
  70. regd_buf = &iser_task->rdma_regd[ISER_DIR_IN];
  71. hdr->flags |= ISER_RSV;
  72. hdr->read_stag = cpu_to_be32(regd_buf->reg.rkey);
  73. hdr->read_va = cpu_to_be64(regd_buf->reg.va);
  74. iser_dbg("Cmd itt:%d READ tags RKEY:%#.4X VA:%#llX\n",
  75. task->itt, regd_buf->reg.rkey,
  76. (unsigned long long)regd_buf->reg.va);
  77. return 0;
  78. }
  79. /* Register user buffer memory and initialize passive rdma
  80. * dto descriptor. Total data size is stored in
  81. * task->data[ISER_DIR_OUT].data_len
  82. */
  83. static int
  84. iser_prepare_write_cmd(struct iscsi_task *task,
  85. unsigned int imm_sz,
  86. unsigned int unsol_sz,
  87. unsigned int edtl)
  88. {
  89. struct iscsi_iser_task *iser_task = task->dd_data;
  90. struct iser_regd_buf *regd_buf;
  91. int err;
  92. struct iser_hdr *hdr = &iser_task->desc.iser_header;
  93. struct iser_data_buf *buf_out = &iser_task->data[ISER_DIR_OUT];
  94. struct ib_sge *tx_dsg = &iser_task->desc.tx_sg[1];
  95. err = iser_dma_map_task_data(iser_task,
  96. buf_out,
  97. ISER_DIR_OUT,
  98. DMA_TO_DEVICE);
  99. if (err)
  100. return err;
  101. if (edtl > iser_task->data[ISER_DIR_OUT].data_len) {
  102. iser_err("Total data length: %ld, less than EDTL: %d, "
  103. "in WRITE cmd BHS itt: %d, conn: 0x%p\n",
  104. iser_task->data[ISER_DIR_OUT].data_len,
  105. edtl, task->itt, task->conn);
  106. return -EINVAL;
  107. }
  108. err = iser_reg_rdma_mem(iser_task,ISER_DIR_OUT);
  109. if (err != 0) {
  110. iser_err("Failed to register write cmd RDMA mem\n");
  111. return err;
  112. }
  113. regd_buf = &iser_task->rdma_regd[ISER_DIR_OUT];
  114. if (unsol_sz < edtl) {
  115. hdr->flags |= ISER_WSV;
  116. hdr->write_stag = cpu_to_be32(regd_buf->reg.rkey);
  117. hdr->write_va = cpu_to_be64(regd_buf->reg.va + unsol_sz);
  118. iser_dbg("Cmd itt:%d, WRITE tags, RKEY:%#.4X "
  119. "VA:%#llX + unsol:%d\n",
  120. task->itt, regd_buf->reg.rkey,
  121. (unsigned long long)regd_buf->reg.va, unsol_sz);
  122. }
  123. if (imm_sz > 0) {
  124. iser_dbg("Cmd itt:%d, WRITE, adding imm.data sz: %d\n",
  125. task->itt, imm_sz);
  126. tx_dsg->addr = regd_buf->reg.va;
  127. tx_dsg->length = imm_sz;
  128. tx_dsg->lkey = regd_buf->reg.lkey;
  129. iser_task->desc.num_sge = 2;
  130. }
  131. return 0;
  132. }
  133. /* creates a new tx descriptor and adds header regd buffer */
  134. static void iser_create_send_desc(struct iser_conn *ib_conn,
  135. struct iser_tx_desc *tx_desc)
  136. {
  137. struct iser_device *device = ib_conn->device;
  138. ib_dma_sync_single_for_cpu(device->ib_device,
  139. tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
  140. memset(&tx_desc->iser_header, 0, sizeof(struct iser_hdr));
  141. tx_desc->iser_header.flags = ISER_VER;
  142. tx_desc->num_sge = 1;
  143. if (tx_desc->tx_sg[0].lkey != device->mr->lkey) {
  144. tx_desc->tx_sg[0].lkey = device->mr->lkey;
  145. iser_dbg("sdesc %p lkey mismatch, fixing\n", tx_desc);
  146. }
  147. }
  148. static int iser_alloc_rx_descriptors(struct iser_conn *ib_conn)
  149. {
  150. int i, j;
  151. u64 dma_addr;
  152. struct iser_rx_desc *rx_desc;
  153. struct ib_sge *rx_sg;
  154. struct iser_device *device = ib_conn->device;
  155. ib_conn->rx_descs = kmalloc(ISER_QP_MAX_RECV_DTOS *
  156. sizeof(struct iser_rx_desc), GFP_KERNEL);
  157. if (!ib_conn->rx_descs)
  158. goto rx_desc_alloc_fail;
  159. rx_desc = ib_conn->rx_descs;
  160. for (i = 0; i < ISER_QP_MAX_RECV_DTOS; i++, rx_desc++) {
  161. dma_addr = ib_dma_map_single(device->ib_device, (void *)rx_desc,
  162. ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
  163. if (ib_dma_mapping_error(device->ib_device, dma_addr))
  164. goto rx_desc_dma_map_failed;
  165. rx_desc->dma_addr = dma_addr;
  166. rx_sg = &rx_desc->rx_sg;
  167. rx_sg->addr = rx_desc->dma_addr;
  168. rx_sg->length = ISER_RX_PAYLOAD_SIZE;
  169. rx_sg->lkey = device->mr->lkey;
  170. }
  171. ib_conn->rx_desc_head = 0;
  172. return 0;
  173. rx_desc_dma_map_failed:
  174. rx_desc = ib_conn->rx_descs;
  175. for (j = 0; j < i; j++, rx_desc++)
  176. ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
  177. ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
  178. kfree(ib_conn->rx_descs);
  179. ib_conn->rx_descs = NULL;
  180. rx_desc_alloc_fail:
  181. iser_err("failed allocating rx descriptors / data buffers\n");
  182. return -ENOMEM;
  183. }
  184. void iser_free_rx_descriptors(struct iser_conn *ib_conn)
  185. {
  186. int i;
  187. struct iser_rx_desc *rx_desc;
  188. struct iser_device *device = ib_conn->device;
  189. if (ib_conn->login_buf) {
  190. if (ib_conn->login_req_dma)
  191. ib_dma_unmap_single(device->ib_device,
  192. ib_conn->login_req_dma,
  193. ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
  194. if (ib_conn->login_resp_dma)
  195. ib_dma_unmap_single(device->ib_device,
  196. ib_conn->login_resp_dma,
  197. ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
  198. kfree(ib_conn->login_buf);
  199. }
  200. if (!ib_conn->rx_descs)
  201. return;
  202. rx_desc = ib_conn->rx_descs;
  203. for (i = 0; i < ISER_QP_MAX_RECV_DTOS; i++, rx_desc++)
  204. ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
  205. ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
  206. kfree(ib_conn->rx_descs);
  207. }
  208. /**
  209. * iser_conn_set_full_featured_mode - (iSER API)
  210. */
  211. int iser_conn_set_full_featured_mode(struct iscsi_conn *conn)
  212. {
  213. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  214. iser_dbg("Initially post: %d\n", ISER_MIN_POSTED_RX);
  215. /* Check that there is no posted recv or send buffers left - */
  216. /* they must be consumed during the login phase */
  217. BUG_ON(iser_conn->ib_conn->post_recv_buf_count != 0);
  218. BUG_ON(atomic_read(&iser_conn->ib_conn->post_send_buf_count) != 0);
  219. if (iser_alloc_rx_descriptors(iser_conn->ib_conn))
  220. return -ENOMEM;
  221. /* Initial post receive buffers */
  222. if (iser_post_recvm(iser_conn->ib_conn, ISER_MIN_POSTED_RX))
  223. return -ENOMEM;
  224. return 0;
  225. }
  226. /**
  227. * iser_send_command - send command PDU
  228. */
  229. int iser_send_command(struct iscsi_conn *conn,
  230. struct iscsi_task *task)
  231. {
  232. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  233. struct iscsi_iser_task *iser_task = task->dd_data;
  234. unsigned long edtl;
  235. int err;
  236. struct iser_data_buf *data_buf;
  237. struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr;
  238. struct scsi_cmnd *sc = task->sc;
  239. struct iser_tx_desc *tx_desc = &iser_task->desc;
  240. edtl = ntohl(hdr->data_length);
  241. /* build the tx desc regd header and add it to the tx desc dto */
  242. tx_desc->type = ISCSI_TX_SCSI_COMMAND;
  243. iser_create_send_desc(iser_conn->ib_conn, tx_desc);
  244. if (hdr->flags & ISCSI_FLAG_CMD_READ)
  245. data_buf = &iser_task->data[ISER_DIR_IN];
  246. else
  247. data_buf = &iser_task->data[ISER_DIR_OUT];
  248. if (scsi_sg_count(sc)) { /* using a scatter list */
  249. data_buf->buf = scsi_sglist(sc);
  250. data_buf->size = scsi_sg_count(sc);
  251. }
  252. data_buf->data_len = scsi_bufflen(sc);
  253. if (hdr->flags & ISCSI_FLAG_CMD_READ) {
  254. err = iser_prepare_read_cmd(task, edtl);
  255. if (err)
  256. goto send_command_error;
  257. }
  258. if (hdr->flags & ISCSI_FLAG_CMD_WRITE) {
  259. err = iser_prepare_write_cmd(task,
  260. task->imm_count,
  261. task->imm_count +
  262. task->unsol_r2t.data_length,
  263. edtl);
  264. if (err)
  265. goto send_command_error;
  266. }
  267. iser_task->status = ISER_TASK_STATUS_STARTED;
  268. err = iser_post_send(iser_conn->ib_conn, tx_desc);
  269. if (!err)
  270. return 0;
  271. send_command_error:
  272. iser_err("conn %p failed task->itt %d err %d\n",conn, task->itt, err);
  273. return err;
  274. }
  275. /**
  276. * iser_send_data_out - send data out PDU
  277. */
  278. int iser_send_data_out(struct iscsi_conn *conn,
  279. struct iscsi_task *task,
  280. struct iscsi_data *hdr)
  281. {
  282. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  283. struct iscsi_iser_task *iser_task = task->dd_data;
  284. struct iser_tx_desc *tx_desc = NULL;
  285. struct iser_regd_buf *regd_buf;
  286. unsigned long buf_offset;
  287. unsigned long data_seg_len;
  288. uint32_t itt;
  289. int err = 0;
  290. struct ib_sge *tx_dsg;
  291. itt = (__force uint32_t)hdr->itt;
  292. data_seg_len = ntoh24(hdr->dlength);
  293. buf_offset = ntohl(hdr->offset);
  294. iser_dbg("%s itt %d dseg_len %d offset %d\n",
  295. __func__,(int)itt,(int)data_seg_len,(int)buf_offset);
  296. tx_desc = kmem_cache_zalloc(ig.desc_cache, GFP_ATOMIC);
  297. if (tx_desc == NULL) {
  298. iser_err("Failed to alloc desc for post dataout\n");
  299. return -ENOMEM;
  300. }
  301. tx_desc->type = ISCSI_TX_DATAOUT;
  302. tx_desc->iser_header.flags = ISER_VER;
  303. memcpy(&tx_desc->iscsi_header, hdr, sizeof(struct iscsi_hdr));
  304. /* build the tx desc */
  305. iser_initialize_task_headers(task, tx_desc);
  306. regd_buf = &iser_task->rdma_regd[ISER_DIR_OUT];
  307. tx_dsg = &tx_desc->tx_sg[1];
  308. tx_dsg->addr = regd_buf->reg.va + buf_offset;
  309. tx_dsg->length = data_seg_len;
  310. tx_dsg->lkey = regd_buf->reg.lkey;
  311. tx_desc->num_sge = 2;
  312. if (buf_offset + data_seg_len > iser_task->data[ISER_DIR_OUT].data_len) {
  313. iser_err("Offset:%ld & DSL:%ld in Data-Out "
  314. "inconsistent with total len:%ld, itt:%d\n",
  315. buf_offset, data_seg_len,
  316. iser_task->data[ISER_DIR_OUT].data_len, itt);
  317. err = -EINVAL;
  318. goto send_data_out_error;
  319. }
  320. iser_dbg("data-out itt: %d, offset: %ld, sz: %ld\n",
  321. itt, buf_offset, data_seg_len);
  322. err = iser_post_send(iser_conn->ib_conn, tx_desc);
  323. if (!err)
  324. return 0;
  325. send_data_out_error:
  326. kmem_cache_free(ig.desc_cache, tx_desc);
  327. iser_err("conn %p failed err %d\n",conn, err);
  328. return err;
  329. }
  330. int iser_send_control(struct iscsi_conn *conn,
  331. struct iscsi_task *task)
  332. {
  333. struct iscsi_iser_conn *iser_conn = conn->dd_data;
  334. struct iscsi_iser_task *iser_task = task->dd_data;
  335. struct iser_tx_desc *mdesc = &iser_task->desc;
  336. unsigned long data_seg_len;
  337. int err = 0;
  338. struct iser_device *device;
  339. struct iser_conn *ib_conn = iser_conn->ib_conn;
  340. /* build the tx desc regd header and add it to the tx desc dto */
  341. mdesc->type = ISCSI_TX_CONTROL;
  342. iser_create_send_desc(iser_conn->ib_conn, mdesc);
  343. device = iser_conn->ib_conn->device;
  344. data_seg_len = ntoh24(task->hdr->dlength);
  345. if (data_seg_len > 0) {
  346. struct ib_sge *tx_dsg = &mdesc->tx_sg[1];
  347. if (task != conn->login_task) {
  348. iser_err("data present on non login task!!!\n");
  349. goto send_control_error;
  350. }
  351. ib_dma_sync_single_for_cpu(device->ib_device,
  352. ib_conn->login_req_dma, task->data_count,
  353. DMA_TO_DEVICE);
  354. memcpy(iser_conn->ib_conn->login_req_buf, task->data,
  355. task->data_count);
  356. ib_dma_sync_single_for_device(device->ib_device,
  357. ib_conn->login_req_dma, task->data_count,
  358. DMA_TO_DEVICE);
  359. tx_dsg->addr = iser_conn->ib_conn->login_req_dma;
  360. tx_dsg->length = task->data_count;
  361. tx_dsg->lkey = device->mr->lkey;
  362. mdesc->num_sge = 2;
  363. }
  364. if (task == conn->login_task) {
  365. err = iser_post_recvl(iser_conn->ib_conn);
  366. if (err)
  367. goto send_control_error;
  368. }
  369. err = iser_post_send(iser_conn->ib_conn, mdesc);
  370. if (!err)
  371. return 0;
  372. send_control_error:
  373. iser_err("conn %p failed err %d\n",conn, err);
  374. return err;
  375. }
  376. /**
  377. * iser_rcv_dto_completion - recv DTO completion
  378. */
  379. void iser_rcv_completion(struct iser_rx_desc *rx_desc,
  380. unsigned long rx_xfer_len,
  381. struct iser_conn *ib_conn)
  382. {
  383. struct iscsi_iser_conn *conn = ib_conn->iser_conn;
  384. struct iscsi_hdr *hdr;
  385. u64 rx_dma;
  386. int rx_buflen, outstanding, count, err;
  387. /* differentiate between login to all other PDUs */
  388. if ((char *)rx_desc == ib_conn->login_resp_buf) {
  389. rx_dma = ib_conn->login_resp_dma;
  390. rx_buflen = ISER_RX_LOGIN_SIZE;
  391. } else {
  392. rx_dma = rx_desc->dma_addr;
  393. rx_buflen = ISER_RX_PAYLOAD_SIZE;
  394. }
  395. ib_dma_sync_single_for_cpu(ib_conn->device->ib_device, rx_dma,
  396. rx_buflen, DMA_FROM_DEVICE);
  397. hdr = &rx_desc->iscsi_header;
  398. iser_dbg("op 0x%x itt 0x%x dlen %d\n", hdr->opcode,
  399. hdr->itt, (int)(rx_xfer_len - ISER_HEADERS_LEN));
  400. iscsi_iser_recv(conn->iscsi_conn, hdr,
  401. rx_desc->data, rx_xfer_len - ISER_HEADERS_LEN);
  402. ib_dma_sync_single_for_device(ib_conn->device->ib_device, rx_dma,
  403. rx_buflen, DMA_FROM_DEVICE);
  404. /* decrementing conn->post_recv_buf_count only --after-- freeing the *
  405. * task eliminates the need to worry on tasks which are completed in *
  406. * parallel to the execution of iser_conn_term. So the code that waits *
  407. * for the posted rx bufs refcount to become zero handles everything */
  408. conn->ib_conn->post_recv_buf_count--;
  409. if (rx_dma == ib_conn->login_resp_dma)
  410. return;
  411. outstanding = ib_conn->post_recv_buf_count;
  412. if (outstanding + ISER_MIN_POSTED_RX <= ISER_QP_MAX_RECV_DTOS) {
  413. count = min(ISER_QP_MAX_RECV_DTOS - outstanding,
  414. ISER_MIN_POSTED_RX);
  415. err = iser_post_recvm(ib_conn, count);
  416. if (err)
  417. iser_err("posting %d rx bufs err %d\n", count, err);
  418. }
  419. }
  420. void iser_snd_completion(struct iser_tx_desc *tx_desc,
  421. struct iser_conn *ib_conn)
  422. {
  423. struct iscsi_task *task;
  424. struct iser_device *device = ib_conn->device;
  425. if (tx_desc->type == ISCSI_TX_DATAOUT) {
  426. ib_dma_unmap_single(device->ib_device, tx_desc->dma_addr,
  427. ISER_HEADERS_LEN, DMA_TO_DEVICE);
  428. kmem_cache_free(ig.desc_cache, tx_desc);
  429. }
  430. atomic_dec(&ib_conn->post_send_buf_count);
  431. if (tx_desc->type == ISCSI_TX_CONTROL) {
  432. /* this arithmetic is legal by libiscsi dd_data allocation */
  433. task = (void *) ((long)(void *)tx_desc -
  434. sizeof(struct iscsi_task));
  435. if (task->hdr->itt == RESERVED_ITT)
  436. iscsi_put_task(task);
  437. }
  438. }
  439. void iser_task_rdma_init(struct iscsi_iser_task *iser_task)
  440. {
  441. iser_task->status = ISER_TASK_STATUS_INIT;
  442. iser_task->dir[ISER_DIR_IN] = 0;
  443. iser_task->dir[ISER_DIR_OUT] = 0;
  444. iser_task->data[ISER_DIR_IN].data_len = 0;
  445. iser_task->data[ISER_DIR_OUT].data_len = 0;
  446. memset(&iser_task->rdma_regd[ISER_DIR_IN], 0,
  447. sizeof(struct iser_regd_buf));
  448. memset(&iser_task->rdma_regd[ISER_DIR_OUT], 0,
  449. sizeof(struct iser_regd_buf));
  450. }
  451. void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task)
  452. {
  453. int is_rdma_aligned = 1;
  454. struct iser_regd_buf *regd;
  455. /* if we were reading, copy back to unaligned sglist,
  456. * anyway dma_unmap and free the copy
  457. */
  458. if (iser_task->data_copy[ISER_DIR_IN].copy_buf != NULL) {
  459. is_rdma_aligned = 0;
  460. iser_finalize_rdma_unaligned_sg(iser_task, ISER_DIR_IN);
  461. }
  462. if (iser_task->data_copy[ISER_DIR_OUT].copy_buf != NULL) {
  463. is_rdma_aligned = 0;
  464. iser_finalize_rdma_unaligned_sg(iser_task, ISER_DIR_OUT);
  465. }
  466. if (iser_task->dir[ISER_DIR_IN]) {
  467. regd = &iser_task->rdma_regd[ISER_DIR_IN];
  468. if (regd->reg.is_fmr)
  469. iser_unreg_mem(&regd->reg);
  470. }
  471. if (iser_task->dir[ISER_DIR_OUT]) {
  472. regd = &iser_task->rdma_regd[ISER_DIR_OUT];
  473. if (regd->reg.is_fmr)
  474. iser_unreg_mem(&regd->reg);
  475. }
  476. /* if the data was unaligned, it was already unmapped and then copied */
  477. if (is_rdma_aligned)
  478. iser_dma_unmap_task_data(iser_task);
  479. }