2 * Copyright (c) 2004, 2005, 2006 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2013-2014 Mellanox Technologies. All rights reserved.
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:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
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.
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
33 #include <linux/kernel.h>
34 #include <linux/slab.h>
36 #include <linux/scatterlist.h>
37 #include <linux/kfifo.h>
38 #include <scsi/scsi_cmnd.h>
39 #include <scsi/scsi_host.h>
41 #include "iscsi_iser.h"
43 /* Register user buffer memory and initialize passive rdma
44 * dto descriptor. Total data size is stored in
45 * iser_task->data[ISER_DIR_IN].data_len
47 static int iser_prepare_read_cmd(struct iscsi_task *task,
51 struct iscsi_iser_task *iser_task = task->dd_data;
52 struct iser_device *device = iser_task->ib_conn->device;
53 struct iser_regd_buf *regd_buf;
55 struct iser_hdr *hdr = &iser_task->desc.iser_header;
56 struct iser_data_buf *buf_in = &iser_task->data[ISER_DIR_IN];
58 err = iser_dma_map_task_data(iser_task,
65 if (scsi_prot_sg_count(iser_task->sc)) {
66 struct iser_data_buf *pbuf_in = &iser_task->prot[ISER_DIR_IN];
68 err = iser_dma_map_task_data(iser_task,
76 if (edtl > iser_task->data[ISER_DIR_IN].data_len) {
77 iser_err("Total data length: %ld, less than EDTL: "
78 "%d, in READ cmd BHS itt: %d, conn: 0x%p\n",
79 iser_task->data[ISER_DIR_IN].data_len, edtl,
80 task->itt, iser_task->ib_conn);
84 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_IN);
86 iser_err("Failed to set up Data-IN RDMA\n");
89 regd_buf = &iser_task->rdma_regd[ISER_DIR_IN];
91 hdr->flags |= ISER_RSV;
92 hdr->read_stag = cpu_to_be32(regd_buf->reg.rkey);
93 hdr->read_va = cpu_to_be64(regd_buf->reg.va);
95 iser_dbg("Cmd itt:%d READ tags RKEY:%#.4X VA:%#llX\n",
96 task->itt, regd_buf->reg.rkey,
97 (unsigned long long)regd_buf->reg.va);
102 /* Register user buffer memory and initialize passive rdma
103 * dto descriptor. Total data size is stored in
104 * task->data[ISER_DIR_OUT].data_len
107 iser_prepare_write_cmd(struct iscsi_task *task,
109 unsigned int unsol_sz,
112 struct iscsi_iser_task *iser_task = task->dd_data;
113 struct iser_device *device = iser_task->ib_conn->device;
114 struct iser_regd_buf *regd_buf;
116 struct iser_hdr *hdr = &iser_task->desc.iser_header;
117 struct iser_data_buf *buf_out = &iser_task->data[ISER_DIR_OUT];
118 struct ib_sge *tx_dsg = &iser_task->desc.tx_sg[1];
120 err = iser_dma_map_task_data(iser_task,
127 if (scsi_prot_sg_count(iser_task->sc)) {
128 struct iser_data_buf *pbuf_out = &iser_task->prot[ISER_DIR_OUT];
130 err = iser_dma_map_task_data(iser_task,
138 if (edtl > iser_task->data[ISER_DIR_OUT].data_len) {
139 iser_err("Total data length: %ld, less than EDTL: %d, "
140 "in WRITE cmd BHS itt: %d, conn: 0x%p\n",
141 iser_task->data[ISER_DIR_OUT].data_len,
142 edtl, task->itt, task->conn);
146 err = device->iser_reg_rdma_mem(iser_task, ISER_DIR_OUT);
148 iser_err("Failed to register write cmd RDMA mem\n");
152 regd_buf = &iser_task->rdma_regd[ISER_DIR_OUT];
154 if (unsol_sz < edtl) {
155 hdr->flags |= ISER_WSV;
156 hdr->write_stag = cpu_to_be32(regd_buf->reg.rkey);
157 hdr->write_va = cpu_to_be64(regd_buf->reg.va + unsol_sz);
159 iser_dbg("Cmd itt:%d, WRITE tags, RKEY:%#.4X "
160 "VA:%#llX + unsol:%d\n",
161 task->itt, regd_buf->reg.rkey,
162 (unsigned long long)regd_buf->reg.va, unsol_sz);
166 iser_dbg("Cmd itt:%d, WRITE, adding imm.data sz: %d\n",
168 tx_dsg->addr = regd_buf->reg.va;
169 tx_dsg->length = imm_sz;
170 tx_dsg->lkey = regd_buf->reg.lkey;
171 iser_task->desc.num_sge = 2;
177 /* creates a new tx descriptor and adds header regd buffer */
178 static void iser_create_send_desc(struct iser_conn *ib_conn,
179 struct iser_tx_desc *tx_desc)
181 struct iser_device *device = ib_conn->device;
183 ib_dma_sync_single_for_cpu(device->ib_device,
184 tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
186 memset(&tx_desc->iser_header, 0, sizeof(struct iser_hdr));
187 tx_desc->iser_header.flags = ISER_VER;
189 tx_desc->num_sge = 1;
191 if (tx_desc->tx_sg[0].lkey != device->mr->lkey) {
192 tx_desc->tx_sg[0].lkey = device->mr->lkey;
193 iser_dbg("sdesc %p lkey mismatch, fixing\n", tx_desc);
197 static void iser_free_login_buf(struct iser_conn *ib_conn)
199 if (!ib_conn->login_buf)
202 if (ib_conn->login_req_dma)
203 ib_dma_unmap_single(ib_conn->device->ib_device,
204 ib_conn->login_req_dma,
205 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
207 if (ib_conn->login_resp_dma)
208 ib_dma_unmap_single(ib_conn->device->ib_device,
209 ib_conn->login_resp_dma,
210 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
212 kfree(ib_conn->login_buf);
214 /* make sure we never redo any unmapping */
215 ib_conn->login_req_dma = 0;
216 ib_conn->login_resp_dma = 0;
217 ib_conn->login_buf = NULL;
220 static int iser_alloc_login_buf(struct iser_conn *ib_conn)
222 struct iser_device *device;
223 int req_err, resp_err;
225 BUG_ON(ib_conn->device == NULL);
227 device = ib_conn->device;
229 ib_conn->login_buf = kmalloc(ISCSI_DEF_MAX_RECV_SEG_LEN +
230 ISER_RX_LOGIN_SIZE, GFP_KERNEL);
231 if (!ib_conn->login_buf)
234 ib_conn->login_req_buf = ib_conn->login_buf;
235 ib_conn->login_resp_buf = ib_conn->login_buf +
236 ISCSI_DEF_MAX_RECV_SEG_LEN;
238 ib_conn->login_req_dma = ib_dma_map_single(ib_conn->device->ib_device,
239 (void *)ib_conn->login_req_buf,
240 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
242 ib_conn->login_resp_dma = ib_dma_map_single(ib_conn->device->ib_device,
243 (void *)ib_conn->login_resp_buf,
244 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
246 req_err = ib_dma_mapping_error(device->ib_device,
247 ib_conn->login_req_dma);
248 resp_err = ib_dma_mapping_error(device->ib_device,
249 ib_conn->login_resp_dma);
251 if (req_err || resp_err) {
253 ib_conn->login_req_dma = 0;
255 ib_conn->login_resp_dma = 0;
261 iser_free_login_buf(ib_conn);
264 iser_err("unable to alloc or map login buf\n");
268 int iser_alloc_rx_descriptors(struct iser_conn *ib_conn, struct iscsi_session *session)
272 struct iser_rx_desc *rx_desc;
273 struct ib_sge *rx_sg;
274 struct iser_device *device = ib_conn->device;
276 ib_conn->qp_max_recv_dtos = session->cmds_max;
277 ib_conn->qp_max_recv_dtos_mask = session->cmds_max - 1; /* cmds_max is 2^N */
278 ib_conn->min_posted_rx = ib_conn->qp_max_recv_dtos >> 2;
280 if (device->iser_alloc_rdma_reg_res(ib_conn, session->scsi_cmds_max))
281 goto create_rdma_reg_res_failed;
283 if (iser_alloc_login_buf(ib_conn))
284 goto alloc_login_buf_fail;
286 ib_conn->rx_descs = kmalloc(session->cmds_max *
287 sizeof(struct iser_rx_desc), GFP_KERNEL);
288 if (!ib_conn->rx_descs)
289 goto rx_desc_alloc_fail;
291 rx_desc = ib_conn->rx_descs;
293 for (i = 0; i < ib_conn->qp_max_recv_dtos; i++, rx_desc++) {
294 dma_addr = ib_dma_map_single(device->ib_device, (void *)rx_desc,
295 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
296 if (ib_dma_mapping_error(device->ib_device, dma_addr))
297 goto rx_desc_dma_map_failed;
299 rx_desc->dma_addr = dma_addr;
301 rx_sg = &rx_desc->rx_sg;
302 rx_sg->addr = rx_desc->dma_addr;
303 rx_sg->length = ISER_RX_PAYLOAD_SIZE;
304 rx_sg->lkey = device->mr->lkey;
307 ib_conn->rx_desc_head = 0;
310 rx_desc_dma_map_failed:
311 rx_desc = ib_conn->rx_descs;
312 for (j = 0; j < i; j++, rx_desc++)
313 ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
314 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
315 kfree(ib_conn->rx_descs);
316 ib_conn->rx_descs = NULL;
318 iser_free_login_buf(ib_conn);
319 alloc_login_buf_fail:
320 device->iser_free_rdma_reg_res(ib_conn);
321 create_rdma_reg_res_failed:
322 iser_err("failed allocating rx descriptors / data buffers\n");
326 void iser_free_rx_descriptors(struct iser_conn *ib_conn)
329 struct iser_rx_desc *rx_desc;
330 struct iser_device *device = ib_conn->device;
332 if (!ib_conn->rx_descs)
335 if (device->iser_free_rdma_reg_res)
336 device->iser_free_rdma_reg_res(ib_conn);
338 rx_desc = ib_conn->rx_descs;
339 for (i = 0; i < ib_conn->qp_max_recv_dtos; i++, rx_desc++)
340 ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
341 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
342 kfree(ib_conn->rx_descs);
343 /* make sure we never redo any unmapping */
344 ib_conn->rx_descs = NULL;
347 iser_free_login_buf(ib_conn);
350 static int iser_post_rx_bufs(struct iscsi_conn *conn, struct iscsi_hdr *req)
352 struct iser_conn *ib_conn = conn->dd_data;
353 struct iscsi_session *session = conn->session;
355 iser_dbg("req op %x flags %x\n", req->opcode, req->flags);
356 /* check if this is the last login - going to full feature phase */
357 if ((req->flags & ISCSI_FULL_FEATURE_PHASE) != ISCSI_FULL_FEATURE_PHASE)
361 * Check that there is one posted recv buffer (for the last login
362 * response) and no posted send buffers left - they must have been
363 * consumed during previous login phases.
365 WARN_ON(ib_conn->post_recv_buf_count != 1);
366 WARN_ON(atomic_read(&ib_conn->post_send_buf_count) != 0);
368 if (session->discovery_sess) {
369 iser_info("Discovery session, re-using login RX buffer\n");
372 iser_info("Normal session, posting batch of RX %d buffers\n",
373 ib_conn->min_posted_rx);
375 /* Initial post receive buffers */
376 if (iser_post_recvm(ib_conn, ib_conn->min_posted_rx))
383 * iser_send_command - send command PDU
385 int iser_send_command(struct iscsi_conn *conn,
386 struct iscsi_task *task)
388 struct iser_conn *ib_conn = conn->dd_data;
389 struct iscsi_iser_task *iser_task = task->dd_data;
392 struct iser_data_buf *data_buf, *prot_buf;
393 struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr;
394 struct scsi_cmnd *sc = task->sc;
395 struct iser_tx_desc *tx_desc = &iser_task->desc;
397 edtl = ntohl(hdr->data_length);
399 /* build the tx desc regd header and add it to the tx desc dto */
400 tx_desc->type = ISCSI_TX_SCSI_COMMAND;
401 iser_create_send_desc(ib_conn, tx_desc);
403 if (hdr->flags & ISCSI_FLAG_CMD_READ) {
404 data_buf = &iser_task->data[ISER_DIR_IN];
405 prot_buf = &iser_task->prot[ISER_DIR_IN];
407 data_buf = &iser_task->data[ISER_DIR_OUT];
408 prot_buf = &iser_task->prot[ISER_DIR_OUT];
411 if (scsi_sg_count(sc)) { /* using a scatter list */
412 data_buf->buf = scsi_sglist(sc);
413 data_buf->size = scsi_sg_count(sc);
415 data_buf->data_len = scsi_bufflen(sc);
417 if (scsi_prot_sg_count(sc)) {
418 prot_buf->buf = scsi_prot_sglist(sc);
419 prot_buf->size = scsi_prot_sg_count(sc);
420 prot_buf->data_len = sc->prot_sdb->length;
423 if (hdr->flags & ISCSI_FLAG_CMD_READ) {
424 err = iser_prepare_read_cmd(task, edtl);
426 goto send_command_error;
428 if (hdr->flags & ISCSI_FLAG_CMD_WRITE) {
429 err = iser_prepare_write_cmd(task,
432 task->unsol_r2t.data_length,
435 goto send_command_error;
438 iser_task->status = ISER_TASK_STATUS_STARTED;
440 err = iser_post_send(ib_conn, tx_desc);
445 iser_err("conn %p failed task->itt %d err %d\n",conn, task->itt, err);
450 * iser_send_data_out - send data out PDU
452 int iser_send_data_out(struct iscsi_conn *conn,
453 struct iscsi_task *task,
454 struct iscsi_data *hdr)
456 struct iser_conn *ib_conn = conn->dd_data;
457 struct iscsi_iser_task *iser_task = task->dd_data;
458 struct iser_tx_desc *tx_desc = NULL;
459 struct iser_regd_buf *regd_buf;
460 unsigned long buf_offset;
461 unsigned long data_seg_len;
464 struct ib_sge *tx_dsg;
466 itt = (__force uint32_t)hdr->itt;
467 data_seg_len = ntoh24(hdr->dlength);
468 buf_offset = ntohl(hdr->offset);
470 iser_dbg("%s itt %d dseg_len %d offset %d\n",
471 __func__,(int)itt,(int)data_seg_len,(int)buf_offset);
473 tx_desc = kmem_cache_zalloc(ig.desc_cache, GFP_ATOMIC);
474 if (tx_desc == NULL) {
475 iser_err("Failed to alloc desc for post dataout\n");
479 tx_desc->type = ISCSI_TX_DATAOUT;
480 tx_desc->iser_header.flags = ISER_VER;
481 memcpy(&tx_desc->iscsi_header, hdr, sizeof(struct iscsi_hdr));
483 /* build the tx desc */
484 iser_initialize_task_headers(task, tx_desc);
486 regd_buf = &iser_task->rdma_regd[ISER_DIR_OUT];
487 tx_dsg = &tx_desc->tx_sg[1];
488 tx_dsg->addr = regd_buf->reg.va + buf_offset;
489 tx_dsg->length = data_seg_len;
490 tx_dsg->lkey = regd_buf->reg.lkey;
491 tx_desc->num_sge = 2;
493 if (buf_offset + data_seg_len > iser_task->data[ISER_DIR_OUT].data_len) {
494 iser_err("Offset:%ld & DSL:%ld in Data-Out "
495 "inconsistent with total len:%ld, itt:%d\n",
496 buf_offset, data_seg_len,
497 iser_task->data[ISER_DIR_OUT].data_len, itt);
499 goto send_data_out_error;
501 iser_dbg("data-out itt: %d, offset: %ld, sz: %ld\n",
502 itt, buf_offset, data_seg_len);
505 err = iser_post_send(ib_conn, tx_desc);
510 kmem_cache_free(ig.desc_cache, tx_desc);
511 iser_err("conn %p failed err %d\n",conn, err);
515 int iser_send_control(struct iscsi_conn *conn,
516 struct iscsi_task *task)
518 struct iser_conn *ib_conn = conn->dd_data;
519 struct iscsi_iser_task *iser_task = task->dd_data;
520 struct iser_tx_desc *mdesc = &iser_task->desc;
521 unsigned long data_seg_len;
523 struct iser_device *device;
525 /* build the tx desc regd header and add it to the tx desc dto */
526 mdesc->type = ISCSI_TX_CONTROL;
527 iser_create_send_desc(ib_conn, mdesc);
529 device = ib_conn->device;
531 data_seg_len = ntoh24(task->hdr->dlength);
533 if (data_seg_len > 0) {
534 struct ib_sge *tx_dsg = &mdesc->tx_sg[1];
535 if (task != conn->login_task) {
536 iser_err("data present on non login task!!!\n");
537 goto send_control_error;
540 ib_dma_sync_single_for_cpu(device->ib_device,
541 ib_conn->login_req_dma, task->data_count,
544 memcpy(ib_conn->login_req_buf, task->data, task->data_count);
546 ib_dma_sync_single_for_device(device->ib_device,
547 ib_conn->login_req_dma, task->data_count,
550 tx_dsg->addr = ib_conn->login_req_dma;
551 tx_dsg->length = task->data_count;
552 tx_dsg->lkey = device->mr->lkey;
556 if (task == conn->login_task) {
557 iser_dbg("op %x dsl %lx, posting login rx buffer\n",
558 task->hdr->opcode, data_seg_len);
559 err = iser_post_recvl(ib_conn);
561 goto send_control_error;
562 err = iser_post_rx_bufs(conn, task->hdr);
564 goto send_control_error;
567 err = iser_post_send(ib_conn, mdesc);
572 iser_err("conn %p failed err %d\n",conn, err);
577 * iser_rcv_dto_completion - recv DTO completion
579 void iser_rcv_completion(struct iser_rx_desc *rx_desc,
580 unsigned long rx_xfer_len,
581 struct iser_conn *ib_conn)
583 struct iscsi_hdr *hdr;
585 int rx_buflen, outstanding, count, err;
587 /* differentiate between login to all other PDUs */
588 if ((char *)rx_desc == ib_conn->login_resp_buf) {
589 rx_dma = ib_conn->login_resp_dma;
590 rx_buflen = ISER_RX_LOGIN_SIZE;
592 rx_dma = rx_desc->dma_addr;
593 rx_buflen = ISER_RX_PAYLOAD_SIZE;
596 ib_dma_sync_single_for_cpu(ib_conn->device->ib_device, rx_dma,
597 rx_buflen, DMA_FROM_DEVICE);
599 hdr = &rx_desc->iscsi_header;
601 iser_dbg("op 0x%x itt 0x%x dlen %d\n", hdr->opcode,
602 hdr->itt, (int)(rx_xfer_len - ISER_HEADERS_LEN));
604 iscsi_iser_recv(ib_conn->iscsi_conn, hdr, rx_desc->data,
605 rx_xfer_len - ISER_HEADERS_LEN);
607 ib_dma_sync_single_for_device(ib_conn->device->ib_device, rx_dma,
608 rx_buflen, DMA_FROM_DEVICE);
610 /* decrementing conn->post_recv_buf_count only --after-- freeing the *
611 * task eliminates the need to worry on tasks which are completed in *
612 * parallel to the execution of iser_conn_term. So the code that waits *
613 * for the posted rx bufs refcount to become zero handles everything */
614 ib_conn->post_recv_buf_count--;
616 if (rx_dma == ib_conn->login_resp_dma)
619 outstanding = ib_conn->post_recv_buf_count;
620 if (outstanding + ib_conn->min_posted_rx <= ib_conn->qp_max_recv_dtos) {
621 count = min(ib_conn->qp_max_recv_dtos - outstanding,
622 ib_conn->min_posted_rx);
623 err = iser_post_recvm(ib_conn, count);
625 iser_err("posting %d rx bufs err %d\n", count, err);
629 void iser_snd_completion(struct iser_tx_desc *tx_desc,
630 struct iser_conn *ib_conn)
632 struct iscsi_task *task;
633 struct iser_device *device = ib_conn->device;
635 if (tx_desc->type == ISCSI_TX_DATAOUT) {
636 ib_dma_unmap_single(device->ib_device, tx_desc->dma_addr,
637 ISER_HEADERS_LEN, DMA_TO_DEVICE);
638 kmem_cache_free(ig.desc_cache, tx_desc);
642 atomic_dec(&ib_conn->post_send_buf_count);
644 if (tx_desc && tx_desc->type == ISCSI_TX_CONTROL) {
645 /* this arithmetic is legal by libiscsi dd_data allocation */
646 task = (void *) ((long)(void *)tx_desc -
647 sizeof(struct iscsi_task));
648 if (task->hdr->itt == RESERVED_ITT)
649 iscsi_put_task(task);
653 void iser_task_rdma_init(struct iscsi_iser_task *iser_task)
656 iser_task->status = ISER_TASK_STATUS_INIT;
658 iser_task->dir[ISER_DIR_IN] = 0;
659 iser_task->dir[ISER_DIR_OUT] = 0;
661 iser_task->data[ISER_DIR_IN].data_len = 0;
662 iser_task->data[ISER_DIR_OUT].data_len = 0;
664 iser_task->prot[ISER_DIR_IN].data_len = 0;
665 iser_task->prot[ISER_DIR_OUT].data_len = 0;
667 memset(&iser_task->rdma_regd[ISER_DIR_IN], 0,
668 sizeof(struct iser_regd_buf));
669 memset(&iser_task->rdma_regd[ISER_DIR_OUT], 0,
670 sizeof(struct iser_regd_buf));
673 void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task)
675 struct iser_device *device = iser_task->ib_conn->device;
676 int is_rdma_data_aligned = 1;
677 int is_rdma_prot_aligned = 1;
678 int prot_count = scsi_prot_sg_count(iser_task->sc);
680 /* if we were reading, copy back to unaligned sglist,
681 * anyway dma_unmap and free the copy
683 if (iser_task->data_copy[ISER_DIR_IN].copy_buf != NULL) {
684 is_rdma_data_aligned = 0;
685 iser_finalize_rdma_unaligned_sg(iser_task,
686 &iser_task->data[ISER_DIR_IN],
687 &iser_task->data_copy[ISER_DIR_IN],
691 if (iser_task->data_copy[ISER_DIR_OUT].copy_buf != NULL) {
692 is_rdma_data_aligned = 0;
693 iser_finalize_rdma_unaligned_sg(iser_task,
694 &iser_task->data[ISER_DIR_OUT],
695 &iser_task->data_copy[ISER_DIR_OUT],
699 if (iser_task->prot_copy[ISER_DIR_IN].copy_buf != NULL) {
700 is_rdma_prot_aligned = 0;
701 iser_finalize_rdma_unaligned_sg(iser_task,
702 &iser_task->prot[ISER_DIR_IN],
703 &iser_task->prot_copy[ISER_DIR_IN],
707 if (iser_task->prot_copy[ISER_DIR_OUT].copy_buf != NULL) {
708 is_rdma_prot_aligned = 0;
709 iser_finalize_rdma_unaligned_sg(iser_task,
710 &iser_task->prot[ISER_DIR_OUT],
711 &iser_task->prot_copy[ISER_DIR_OUT],
715 if (iser_task->dir[ISER_DIR_IN]) {
716 device->iser_unreg_rdma_mem(iser_task, ISER_DIR_IN);
717 if (is_rdma_data_aligned)
718 iser_dma_unmap_task_data(iser_task,
719 &iser_task->data[ISER_DIR_IN]);
720 if (prot_count && is_rdma_prot_aligned)
721 iser_dma_unmap_task_data(iser_task,
722 &iser_task->prot[ISER_DIR_IN]);
725 if (iser_task->dir[ISER_DIR_OUT]) {
726 device->iser_unreg_rdma_mem(iser_task, ISER_DIR_OUT);
727 if (is_rdma_data_aligned)
728 iser_dma_unmap_task_data(iser_task,
729 &iser_task->data[ISER_DIR_OUT]);
730 if (prot_count && is_rdma_prot_aligned)
731 iser_dma_unmap_task_data(iser_task,
732 &iser_task->prot[ISER_DIR_OUT]);