of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / drivers / infiniband / ulp / iser / iser_initiator.c
blobffd00c42072959ed6747b5094e159cb34532675f
1 /*
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
13 * conditions are met:
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
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
31 * SOFTWARE.
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>
41 #include "iscsi_iser.h"
43 /* Register user buffer memory and initialize passive rdma
44 * dto descriptor. Data size is stored in
45 * task->data[ISER_DIR_IN].data_len, Protection size
46 * os stored in task->prot[ISER_DIR_IN].data_len
48 static int iser_prepare_read_cmd(struct iscsi_task *task)
51 struct iscsi_iser_task *iser_task = task->dd_data;
52 struct iser_mem_reg *mem_reg;
53 int err;
54 struct iser_hdr *hdr = &iser_task->desc.iser_header;
55 struct iser_data_buf *buf_in = &iser_task->data[ISER_DIR_IN];
57 err = iser_dma_map_task_data(iser_task,
58 buf_in,
59 ISER_DIR_IN,
60 DMA_FROM_DEVICE);
61 if (err)
62 return err;
64 if (scsi_prot_sg_count(iser_task->sc)) {
65 struct iser_data_buf *pbuf_in = &iser_task->prot[ISER_DIR_IN];
67 err = iser_dma_map_task_data(iser_task,
68 pbuf_in,
69 ISER_DIR_IN,
70 DMA_FROM_DEVICE);
71 if (err)
72 return err;
75 err = iser_reg_rdma_mem(iser_task, ISER_DIR_IN);
76 if (err) {
77 iser_err("Failed to set up Data-IN RDMA\n");
78 return err;
80 mem_reg = &iser_task->rdma_reg[ISER_DIR_IN];
82 hdr->flags |= ISER_RSV;
83 hdr->read_stag = cpu_to_be32(mem_reg->rkey);
84 hdr->read_va = cpu_to_be64(mem_reg->sge.addr);
86 iser_dbg("Cmd itt:%d READ tags RKEY:%#.4X VA:%#llX\n",
87 task->itt, mem_reg->rkey,
88 (unsigned long long)mem_reg->sge.addr);
90 return 0;
93 /* Register user buffer memory and initialize passive rdma
94 * dto descriptor. Data size is stored in
95 * task->data[ISER_DIR_OUT].data_len, Protection size
96 * is stored at task->prot[ISER_DIR_OUT].data_len
98 static int
99 iser_prepare_write_cmd(struct iscsi_task *task,
100 unsigned int imm_sz,
101 unsigned int unsol_sz,
102 unsigned int edtl)
104 struct iscsi_iser_task *iser_task = task->dd_data;
105 struct iser_mem_reg *mem_reg;
106 int err;
107 struct iser_hdr *hdr = &iser_task->desc.iser_header;
108 struct iser_data_buf *buf_out = &iser_task->data[ISER_DIR_OUT];
109 struct ib_sge *tx_dsg = &iser_task->desc.tx_sg[1];
111 err = iser_dma_map_task_data(iser_task,
112 buf_out,
113 ISER_DIR_OUT,
114 DMA_TO_DEVICE);
115 if (err)
116 return err;
118 if (scsi_prot_sg_count(iser_task->sc)) {
119 struct iser_data_buf *pbuf_out = &iser_task->prot[ISER_DIR_OUT];
121 err = iser_dma_map_task_data(iser_task,
122 pbuf_out,
123 ISER_DIR_OUT,
124 DMA_TO_DEVICE);
125 if (err)
126 return err;
129 err = iser_reg_rdma_mem(iser_task, ISER_DIR_OUT);
130 if (err != 0) {
131 iser_err("Failed to register write cmd RDMA mem\n");
132 return err;
135 mem_reg = &iser_task->rdma_reg[ISER_DIR_OUT];
137 if (unsol_sz < edtl) {
138 hdr->flags |= ISER_WSV;
139 hdr->write_stag = cpu_to_be32(mem_reg->rkey);
140 hdr->write_va = cpu_to_be64(mem_reg->sge.addr + unsol_sz);
142 iser_dbg("Cmd itt:%d, WRITE tags, RKEY:%#.4X "
143 "VA:%#llX + unsol:%d\n",
144 task->itt, mem_reg->rkey,
145 (unsigned long long)mem_reg->sge.addr, unsol_sz);
148 if (imm_sz > 0) {
149 iser_dbg("Cmd itt:%d, WRITE, adding imm.data sz: %d\n",
150 task->itt, imm_sz);
151 tx_dsg->addr = mem_reg->sge.addr;
152 tx_dsg->length = imm_sz;
153 tx_dsg->lkey = mem_reg->sge.lkey;
154 iser_task->desc.num_sge = 2;
157 return 0;
160 /* creates a new tx descriptor and adds header regd buffer */
161 static void iser_create_send_desc(struct iser_conn *iser_conn,
162 struct iser_tx_desc *tx_desc)
164 struct iser_device *device = iser_conn->ib_conn.device;
166 ib_dma_sync_single_for_cpu(device->ib_device,
167 tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
169 memset(&tx_desc->iser_header, 0, sizeof(struct iser_hdr));
170 tx_desc->iser_header.flags = ISER_VER;
171 tx_desc->num_sge = 1;
174 static void iser_free_login_buf(struct iser_conn *iser_conn)
176 struct iser_device *device = iser_conn->ib_conn.device;
178 if (!iser_conn->login_buf)
179 return;
181 if (iser_conn->login_req_dma)
182 ib_dma_unmap_single(device->ib_device,
183 iser_conn->login_req_dma,
184 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
186 if (iser_conn->login_resp_dma)
187 ib_dma_unmap_single(device->ib_device,
188 iser_conn->login_resp_dma,
189 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
191 kfree(iser_conn->login_buf);
193 /* make sure we never redo any unmapping */
194 iser_conn->login_req_dma = 0;
195 iser_conn->login_resp_dma = 0;
196 iser_conn->login_buf = NULL;
199 static int iser_alloc_login_buf(struct iser_conn *iser_conn)
201 struct iser_device *device = iser_conn->ib_conn.device;
202 int req_err, resp_err;
204 BUG_ON(device == NULL);
206 iser_conn->login_buf = kmalloc(ISCSI_DEF_MAX_RECV_SEG_LEN +
207 ISER_RX_LOGIN_SIZE, GFP_KERNEL);
208 if (!iser_conn->login_buf)
209 goto out_err;
211 iser_conn->login_req_buf = iser_conn->login_buf;
212 iser_conn->login_resp_buf = iser_conn->login_buf +
213 ISCSI_DEF_MAX_RECV_SEG_LEN;
215 iser_conn->login_req_dma = ib_dma_map_single(device->ib_device,
216 iser_conn->login_req_buf,
217 ISCSI_DEF_MAX_RECV_SEG_LEN,
218 DMA_TO_DEVICE);
220 iser_conn->login_resp_dma = ib_dma_map_single(device->ib_device,
221 iser_conn->login_resp_buf,
222 ISER_RX_LOGIN_SIZE,
223 DMA_FROM_DEVICE);
225 req_err = ib_dma_mapping_error(device->ib_device,
226 iser_conn->login_req_dma);
227 resp_err = ib_dma_mapping_error(device->ib_device,
228 iser_conn->login_resp_dma);
230 if (req_err || resp_err) {
231 if (req_err)
232 iser_conn->login_req_dma = 0;
233 if (resp_err)
234 iser_conn->login_resp_dma = 0;
235 goto free_login_buf;
237 return 0;
239 free_login_buf:
240 iser_free_login_buf(iser_conn);
242 out_err:
243 iser_err("unable to alloc or map login buf\n");
244 return -ENOMEM;
247 int iser_alloc_rx_descriptors(struct iser_conn *iser_conn,
248 struct iscsi_session *session)
250 int i, j;
251 u64 dma_addr;
252 struct iser_rx_desc *rx_desc;
253 struct ib_sge *rx_sg;
254 struct ib_conn *ib_conn = &iser_conn->ib_conn;
255 struct iser_device *device = ib_conn->device;
257 iser_conn->qp_max_recv_dtos = session->cmds_max;
258 iser_conn->qp_max_recv_dtos_mask = session->cmds_max - 1; /* cmds_max is 2^N */
259 iser_conn->min_posted_rx = iser_conn->qp_max_recv_dtos >> 2;
261 if (device->reg_ops->alloc_reg_res(ib_conn, session->scsi_cmds_max,
262 iser_conn->scsi_sg_tablesize))
263 goto create_rdma_reg_res_failed;
265 if (iser_alloc_login_buf(iser_conn))
266 goto alloc_login_buf_fail;
268 iser_conn->num_rx_descs = session->cmds_max;
269 iser_conn->rx_descs = kmalloc(iser_conn->num_rx_descs *
270 sizeof(struct iser_rx_desc), GFP_KERNEL);
271 if (!iser_conn->rx_descs)
272 goto rx_desc_alloc_fail;
274 rx_desc = iser_conn->rx_descs;
276 for (i = 0; i < iser_conn->qp_max_recv_dtos; i++, rx_desc++) {
277 dma_addr = ib_dma_map_single(device->ib_device, (void *)rx_desc,
278 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
279 if (ib_dma_mapping_error(device->ib_device, dma_addr))
280 goto rx_desc_dma_map_failed;
282 rx_desc->dma_addr = dma_addr;
284 rx_sg = &rx_desc->rx_sg;
285 rx_sg->addr = rx_desc->dma_addr;
286 rx_sg->length = ISER_RX_PAYLOAD_SIZE;
287 rx_sg->lkey = device->pd->local_dma_lkey;
290 iser_conn->rx_desc_head = 0;
291 return 0;
293 rx_desc_dma_map_failed:
294 rx_desc = iser_conn->rx_descs;
295 for (j = 0; j < i; j++, rx_desc++)
296 ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
297 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
298 kfree(iser_conn->rx_descs);
299 iser_conn->rx_descs = NULL;
300 rx_desc_alloc_fail:
301 iser_free_login_buf(iser_conn);
302 alloc_login_buf_fail:
303 device->reg_ops->free_reg_res(ib_conn);
304 create_rdma_reg_res_failed:
305 iser_err("failed allocating rx descriptors / data buffers\n");
306 return -ENOMEM;
309 void iser_free_rx_descriptors(struct iser_conn *iser_conn)
311 int i;
312 struct iser_rx_desc *rx_desc;
313 struct ib_conn *ib_conn = &iser_conn->ib_conn;
314 struct iser_device *device = ib_conn->device;
316 if (device->reg_ops->free_reg_res)
317 device->reg_ops->free_reg_res(ib_conn);
319 rx_desc = iser_conn->rx_descs;
320 for (i = 0; i < iser_conn->qp_max_recv_dtos; i++, rx_desc++)
321 ib_dma_unmap_single(device->ib_device, rx_desc->dma_addr,
322 ISER_RX_PAYLOAD_SIZE, DMA_FROM_DEVICE);
323 kfree(iser_conn->rx_descs);
324 /* make sure we never redo any unmapping */
325 iser_conn->rx_descs = NULL;
327 iser_free_login_buf(iser_conn);
330 static int iser_post_rx_bufs(struct iscsi_conn *conn, struct iscsi_hdr *req)
332 struct iser_conn *iser_conn = conn->dd_data;
333 struct ib_conn *ib_conn = &iser_conn->ib_conn;
334 struct iscsi_session *session = conn->session;
336 iser_dbg("req op %x flags %x\n", req->opcode, req->flags);
337 /* check if this is the last login - going to full feature phase */
338 if ((req->flags & ISCSI_FULL_FEATURE_PHASE) != ISCSI_FULL_FEATURE_PHASE)
339 return 0;
342 * Check that there is one posted recv buffer
343 * (for the last login response).
345 WARN_ON(ib_conn->post_recv_buf_count != 1);
347 if (session->discovery_sess) {
348 iser_info("Discovery session, re-using login RX buffer\n");
349 return 0;
350 } else
351 iser_info("Normal session, posting batch of RX %d buffers\n",
352 iser_conn->min_posted_rx);
354 /* Initial post receive buffers */
355 if (iser_post_recvm(iser_conn, iser_conn->min_posted_rx))
356 return -ENOMEM;
358 return 0;
361 static inline bool iser_signal_comp(u8 sig_count)
363 return ((sig_count % ISER_SIGNAL_CMD_COUNT) == 0);
367 * iser_send_command - send command PDU
369 int iser_send_command(struct iscsi_conn *conn,
370 struct iscsi_task *task)
372 struct iser_conn *iser_conn = conn->dd_data;
373 struct iscsi_iser_task *iser_task = task->dd_data;
374 unsigned long edtl;
375 int err;
376 struct iser_data_buf *data_buf, *prot_buf;
377 struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr;
378 struct scsi_cmnd *sc = task->sc;
379 struct iser_tx_desc *tx_desc = &iser_task->desc;
380 u8 sig_count = ++iser_conn->ib_conn.sig_count;
382 edtl = ntohl(hdr->data_length);
384 /* build the tx desc regd header and add it to the tx desc dto */
385 tx_desc->type = ISCSI_TX_SCSI_COMMAND;
386 iser_create_send_desc(iser_conn, tx_desc);
388 if (hdr->flags & ISCSI_FLAG_CMD_READ) {
389 data_buf = &iser_task->data[ISER_DIR_IN];
390 prot_buf = &iser_task->prot[ISER_DIR_IN];
391 } else {
392 data_buf = &iser_task->data[ISER_DIR_OUT];
393 prot_buf = &iser_task->prot[ISER_DIR_OUT];
396 if (scsi_sg_count(sc)) { /* using a scatter list */
397 data_buf->sg = scsi_sglist(sc);
398 data_buf->size = scsi_sg_count(sc);
400 data_buf->data_len = scsi_bufflen(sc);
402 if (scsi_prot_sg_count(sc)) {
403 prot_buf->sg = scsi_prot_sglist(sc);
404 prot_buf->size = scsi_prot_sg_count(sc);
405 prot_buf->data_len = (data_buf->data_len >>
406 ilog2(sc->device->sector_size)) * 8;
409 if (hdr->flags & ISCSI_FLAG_CMD_READ) {
410 err = iser_prepare_read_cmd(task);
411 if (err)
412 goto send_command_error;
414 if (hdr->flags & ISCSI_FLAG_CMD_WRITE) {
415 err = iser_prepare_write_cmd(task,
416 task->imm_count,
417 task->imm_count +
418 task->unsol_r2t.data_length,
419 edtl);
420 if (err)
421 goto send_command_error;
424 iser_task->status = ISER_TASK_STATUS_STARTED;
426 err = iser_post_send(&iser_conn->ib_conn, tx_desc,
427 iser_signal_comp(sig_count));
428 if (!err)
429 return 0;
431 send_command_error:
432 iser_err("conn %p failed task->itt %d err %d\n",conn, task->itt, err);
433 return err;
437 * iser_send_data_out - send data out PDU
439 int iser_send_data_out(struct iscsi_conn *conn,
440 struct iscsi_task *task,
441 struct iscsi_data *hdr)
443 struct iser_conn *iser_conn = conn->dd_data;
444 struct iscsi_iser_task *iser_task = task->dd_data;
445 struct iser_tx_desc *tx_desc = NULL;
446 struct iser_mem_reg *mem_reg;
447 unsigned long buf_offset;
448 unsigned long data_seg_len;
449 uint32_t itt;
450 int err;
451 struct ib_sge *tx_dsg;
453 itt = (__force uint32_t)hdr->itt;
454 data_seg_len = ntoh24(hdr->dlength);
455 buf_offset = ntohl(hdr->offset);
457 iser_dbg("%s itt %d dseg_len %d offset %d\n",
458 __func__,(int)itt,(int)data_seg_len,(int)buf_offset);
460 tx_desc = kmem_cache_zalloc(ig.desc_cache, GFP_ATOMIC);
461 if (tx_desc == NULL) {
462 iser_err("Failed to alloc desc for post dataout\n");
463 return -ENOMEM;
466 tx_desc->type = ISCSI_TX_DATAOUT;
467 tx_desc->iser_header.flags = ISER_VER;
468 memcpy(&tx_desc->iscsi_header, hdr, sizeof(struct iscsi_hdr));
470 /* build the tx desc */
471 err = iser_initialize_task_headers(task, tx_desc);
472 if (err)
473 goto send_data_out_error;
475 mem_reg = &iser_task->rdma_reg[ISER_DIR_OUT];
476 tx_dsg = &tx_desc->tx_sg[1];
477 tx_dsg->addr = mem_reg->sge.addr + buf_offset;
478 tx_dsg->length = data_seg_len;
479 tx_dsg->lkey = mem_reg->sge.lkey;
480 tx_desc->num_sge = 2;
482 if (buf_offset + data_seg_len > iser_task->data[ISER_DIR_OUT].data_len) {
483 iser_err("Offset:%ld & DSL:%ld in Data-Out "
484 "inconsistent with total len:%ld, itt:%d\n",
485 buf_offset, data_seg_len,
486 iser_task->data[ISER_DIR_OUT].data_len, itt);
487 err = -EINVAL;
488 goto send_data_out_error;
490 iser_dbg("data-out itt: %d, offset: %ld, sz: %ld\n",
491 itt, buf_offset, data_seg_len);
494 err = iser_post_send(&iser_conn->ib_conn, tx_desc, true);
495 if (!err)
496 return 0;
498 send_data_out_error:
499 kmem_cache_free(ig.desc_cache, tx_desc);
500 iser_err("conn %p failed err %d\n", conn, err);
501 return err;
504 int iser_send_control(struct iscsi_conn *conn,
505 struct iscsi_task *task)
507 struct iser_conn *iser_conn = conn->dd_data;
508 struct iscsi_iser_task *iser_task = task->dd_data;
509 struct iser_tx_desc *mdesc = &iser_task->desc;
510 unsigned long data_seg_len;
511 int err = 0;
512 struct iser_device *device;
514 /* build the tx desc regd header and add it to the tx desc dto */
515 mdesc->type = ISCSI_TX_CONTROL;
516 iser_create_send_desc(iser_conn, mdesc);
518 device = iser_conn->ib_conn.device;
520 data_seg_len = ntoh24(task->hdr->dlength);
522 if (data_seg_len > 0) {
523 struct ib_sge *tx_dsg = &mdesc->tx_sg[1];
524 if (task != conn->login_task) {
525 iser_err("data present on non login task!!!\n");
526 goto send_control_error;
529 ib_dma_sync_single_for_cpu(device->ib_device,
530 iser_conn->login_req_dma, task->data_count,
531 DMA_TO_DEVICE);
533 memcpy(iser_conn->login_req_buf, task->data, task->data_count);
535 ib_dma_sync_single_for_device(device->ib_device,
536 iser_conn->login_req_dma, task->data_count,
537 DMA_TO_DEVICE);
539 tx_dsg->addr = iser_conn->login_req_dma;
540 tx_dsg->length = task->data_count;
541 tx_dsg->lkey = device->pd->local_dma_lkey;
542 mdesc->num_sge = 2;
545 if (task == conn->login_task) {
546 iser_dbg("op %x dsl %lx, posting login rx buffer\n",
547 task->hdr->opcode, data_seg_len);
548 err = iser_post_recvl(iser_conn);
549 if (err)
550 goto send_control_error;
551 err = iser_post_rx_bufs(conn, task->hdr);
552 if (err)
553 goto send_control_error;
556 err = iser_post_send(&iser_conn->ib_conn, mdesc, true);
557 if (!err)
558 return 0;
560 send_control_error:
561 iser_err("conn %p failed err %d\n",conn, err);
562 return err;
566 * iser_rcv_dto_completion - recv DTO completion
568 void iser_rcv_completion(struct iser_rx_desc *rx_desc,
569 unsigned long rx_xfer_len,
570 struct ib_conn *ib_conn)
572 struct iser_conn *iser_conn = container_of(ib_conn, struct iser_conn,
573 ib_conn);
574 struct iscsi_hdr *hdr;
575 u64 rx_dma;
576 int rx_buflen, outstanding, count, err;
578 /* differentiate between login to all other PDUs */
579 if ((char *)rx_desc == iser_conn->login_resp_buf) {
580 rx_dma = iser_conn->login_resp_dma;
581 rx_buflen = ISER_RX_LOGIN_SIZE;
582 } else {
583 rx_dma = rx_desc->dma_addr;
584 rx_buflen = ISER_RX_PAYLOAD_SIZE;
587 ib_dma_sync_single_for_cpu(ib_conn->device->ib_device, rx_dma,
588 rx_buflen, DMA_FROM_DEVICE);
590 hdr = &rx_desc->iscsi_header;
592 iser_dbg("op 0x%x itt 0x%x dlen %d\n", hdr->opcode,
593 hdr->itt, (int)(rx_xfer_len - ISER_HEADERS_LEN));
595 iscsi_iser_recv(iser_conn->iscsi_conn, hdr, rx_desc->data,
596 rx_xfer_len - ISER_HEADERS_LEN);
598 ib_dma_sync_single_for_device(ib_conn->device->ib_device, rx_dma,
599 rx_buflen, DMA_FROM_DEVICE);
601 /* decrementing conn->post_recv_buf_count only --after-- freeing the *
602 * task eliminates the need to worry on tasks which are completed in *
603 * parallel to the execution of iser_conn_term. So the code that waits *
604 * for the posted rx bufs refcount to become zero handles everything */
605 ib_conn->post_recv_buf_count--;
607 if (rx_dma == iser_conn->login_resp_dma)
608 return;
610 outstanding = ib_conn->post_recv_buf_count;
611 if (outstanding + iser_conn->min_posted_rx <= iser_conn->qp_max_recv_dtos) {
612 count = min(iser_conn->qp_max_recv_dtos - outstanding,
613 iser_conn->min_posted_rx);
614 err = iser_post_recvm(iser_conn, count);
615 if (err)
616 iser_err("posting %d rx bufs err %d\n", count, err);
620 void iser_snd_completion(struct iser_tx_desc *tx_desc,
621 struct ib_conn *ib_conn)
623 struct iscsi_task *task;
624 struct iser_device *device = ib_conn->device;
626 if (tx_desc->type == ISCSI_TX_DATAOUT) {
627 ib_dma_unmap_single(device->ib_device, tx_desc->dma_addr,
628 ISER_HEADERS_LEN, DMA_TO_DEVICE);
629 kmem_cache_free(ig.desc_cache, tx_desc);
630 tx_desc = NULL;
633 if (tx_desc && tx_desc->type == ISCSI_TX_CONTROL) {
634 /* this arithmetic is legal by libiscsi dd_data allocation */
635 task = (void *) ((long)(void *)tx_desc -
636 sizeof(struct iscsi_task));
637 if (task->hdr->itt == RESERVED_ITT)
638 iscsi_put_task(task);
642 void iser_task_rdma_init(struct iscsi_iser_task *iser_task)
645 iser_task->status = ISER_TASK_STATUS_INIT;
647 iser_task->dir[ISER_DIR_IN] = 0;
648 iser_task->dir[ISER_DIR_OUT] = 0;
650 iser_task->data[ISER_DIR_IN].data_len = 0;
651 iser_task->data[ISER_DIR_OUT].data_len = 0;
653 iser_task->prot[ISER_DIR_IN].data_len = 0;
654 iser_task->prot[ISER_DIR_OUT].data_len = 0;
656 memset(&iser_task->rdma_reg[ISER_DIR_IN], 0,
657 sizeof(struct iser_mem_reg));
658 memset(&iser_task->rdma_reg[ISER_DIR_OUT], 0,
659 sizeof(struct iser_mem_reg));
662 void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task)
664 int prot_count = scsi_prot_sg_count(iser_task->sc);
666 if (iser_task->dir[ISER_DIR_IN]) {
667 iser_unreg_rdma_mem(iser_task, ISER_DIR_IN);
668 iser_dma_unmap_task_data(iser_task,
669 &iser_task->data[ISER_DIR_IN],
670 DMA_FROM_DEVICE);
671 if (prot_count)
672 iser_dma_unmap_task_data(iser_task,
673 &iser_task->prot[ISER_DIR_IN],
674 DMA_FROM_DEVICE);
677 if (iser_task->dir[ISER_DIR_OUT]) {
678 iser_unreg_rdma_mem(iser_task, ISER_DIR_OUT);
679 iser_dma_unmap_task_data(iser_task,
680 &iser_task->data[ISER_DIR_OUT],
681 DMA_TO_DEVICE);
682 if (prot_count)
683 iser_dma_unmap_task_data(iser_task,
684 &iser_task->prot[ISER_DIR_OUT],
685 DMA_TO_DEVICE);