32 #include <linux/kernel.h>
33 #include <linux/slab.h>
64 iser_err(
"Total data length: %ld, less than EDTL: "
65 "%d, in READ cmd BHS itt: %d, conn: 0x%p\n",
73 iser_err(
"Failed to set up Data-IN RDMA\n");
82 iser_dbg(
"Cmd itt:%d READ tags RKEY:%#.4X VA:%#llX\n",
83 task->
itt, regd_buf->
reg.rkey,
84 (
unsigned long long)regd_buf->
reg.va);
94 iser_prepare_write_cmd(
struct iscsi_task *task,
96 unsigned int unsol_sz,
104 struct ib_sge *tx_dsg = &iser_task->
desc.tx_sg[1];
114 iser_err(
"Total data length: %ld, less than EDTL: %d, "
115 "in WRITE cmd BHS itt: %d, conn: 0x%p\n",
123 iser_err(
"Failed to register write cmd RDMA mem\n");
129 if (unsol_sz < edtl) {
134 iser_dbg(
"Cmd itt:%d, WRITE tags, RKEY:%#.4X "
135 "VA:%#llX + unsol:%d\n",
136 task->
itt, regd_buf->
reg.rkey,
137 (
unsigned long long)regd_buf->
reg.va, unsol_sz);
141 iser_dbg(
"Cmd itt:%d, WRITE, adding imm.data sz: %d\n",
143 tx_dsg->
addr = regd_buf->
reg.va;
145 tx_dsg->
lkey = regd_buf->
reg.lkey;
146 iser_task->
desc.num_sge = 2;
153 static void iser_create_send_desc(
struct iser_conn *ib_conn,
158 ib_dma_sync_single_for_cpu(device->
ib_device,
166 if (tx_desc->
tx_sg[0].lkey != device->
mr->lkey) {
167 tx_desc->
tx_sg[0].lkey = device->
mr->lkey;
168 iser_dbg(
"sdesc %p lkey mismatch, fixing\n", tx_desc);
184 goto rx_desc_alloc_fail;
189 dma_addr = ib_dma_map_single(device->
ib_device, (
void *)rx_desc,
191 if (ib_dma_mapping_error(device->
ib_device, dma_addr))
192 goto rx_desc_dma_map_failed;
196 rx_sg = &rx_desc->
rx_sg;
199 rx_sg->
lkey = device->
mr->lkey;
205 rx_desc_dma_map_failed:
207 for (j = 0; j <
i; j++, rx_desc++)
213 iser_err(
"failed allocating rx descriptors / data buffers\n");
277 iser_create_send_desc(iser_conn->
ib_conn, tx_desc);
284 if (scsi_sg_count(
sc)) {
285 data_buf->
buf = scsi_sglist(
sc);
286 data_buf->
size = scsi_sg_count(
sc);
292 err = iser_prepare_read_cmd(task, edtl);
294 goto send_command_error;
297 err = iser_prepare_write_cmd(task,
303 goto send_command_error;
313 iser_err(
"conn %p failed task->itt %d err %d\n",conn, task->
itt, err);
328 unsigned long buf_offset;
329 unsigned long data_seg_len;
338 iser_dbg(
"%s itt %d dseg_len %d offset %d\n",
339 __func__,(
int)itt,(
int)data_seg_len,(
int)buf_offset);
342 if (tx_desc ==
NULL) {
343 iser_err(
"Failed to alloc desc for post dataout\n");
355 tx_dsg = &tx_desc->
tx_sg[1];
356 tx_dsg->
addr = regd_buf->
reg.va + buf_offset;
357 tx_dsg->
length = data_seg_len;
358 tx_dsg->
lkey = regd_buf->
reg.lkey;
362 iser_err(
"Offset:%ld & DSL:%ld in Data-Out "
363 "inconsistent with total len:%ld, itt:%d\n",
364 buf_offset, data_seg_len,
367 goto send_data_out_error;
369 iser_dbg(
"data-out itt: %d, offset: %ld, sz: %ld\n",
370 itt, buf_offset, data_seg_len);
379 iser_err(
"conn %p failed err %d\n",conn, err);
389 unsigned long data_seg_len;
392 struct iser_conn *ib_conn = iser_conn->
ib_conn;
396 iser_create_send_desc(iser_conn->
ib_conn, mdesc);
398 device = iser_conn->
ib_conn->device;
400 data_seg_len =
ntoh24(task->
hdr->dlength);
402 if (data_seg_len > 0) {
405 iser_err(
"data present on non login task!!!\n");
406 goto send_control_error;
409 ib_dma_sync_single_for_cpu(device->
ib_device,
416 ib_dma_sync_single_for_device(device->
ib_device,
422 tx_dsg->
lkey = device->
mr->lkey;
429 goto send_control_error;
430 err = iser_post_rx_bufs(conn, task->
hdr);
432 goto send_control_error;
440 iser_err(
"conn %p failed err %d\n",conn, err);
448 unsigned long rx_xfer_len,
449 struct iser_conn *ib_conn)
454 int rx_buflen, outstanding,
count,
err;
465 ib_dma_sync_single_for_cpu(ib_conn->
device->ib_device, rx_dma,
476 ib_dma_sync_single_for_device(ib_conn->
device->ib_device, rx_dma,
483 conn->
ib_conn->post_recv_buf_count--;
494 iser_err(
"posting %d rx bufs err %d\n", count, err);
499 struct iser_conn *ib_conn)
514 task = (
void *) ((
long)(
void *)tx_desc -
540 int is_rdma_aligned = 1;
557 if (regd->
reg.is_fmr)
563 if (regd->
reg.is_fmr)