iser_initiator.c 16 KB

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