22 #include <linux/slab.h>
26 #include <linux/module.h>
27 #include <scsi/scsi.h>
42 #define eprintk(fmt, args...) \
44 printk("%s(%d) " fmt, __func__, __LINE__, ##args); \
47 #define dprintk(fmt, args...)
65 for (i = 0, iue = q->
items; i < max; i++) {
78 static void srp_iu_pool_free(
struct srp_queue *
q)
94 for (i = 0; i <
max; i++) {
106 for (i = 0; i < max && ring[
i]; i++) {
116 static void srp_ring_free(
struct device *dev,
struct srp_buf **ring,
size_t max,
121 for (i = 0; i <
max; i++) {
129 size_t nr,
size_t iu_size)
141 target->
rx_ring = srp_ring_alloc(target->
dev, nr, iu_size);
151 srp_ring_free(target->
dev, target->
rx_ring, nr, iu_size);
160 srp_iu_pool_free(&target->
iu_queue);
169 sizeof(
void *), &target->
iu_queue.lock) !=
sizeof(
void *)) {
176 INIT_LIST_HEAD(&iue->
ilist);
185 sizeof(
void *), &iue->
target->iu_queue.lock);
191 int dma_map,
int ext_desc)
199 sg = scsi_sglist(sc);
201 dprintk(
"%p %u %u %d\n", iue, scsi_bufflen(sc),
202 md->
len, scsi_sg_count(sc));
207 printk(
"fail to map %p %d\n", iue, scsi_sg_count(sc));
214 err = rdma_io(sc, sg, nsg, md, 1, dir, len);
225 int dma_map,
int ext_desc)
232 int nmd, nsg = 0,
len;
234 if (dma_map || ext_desc) {
236 sg = scsi_sglist(sc);
239 iue, scsi_bufflen(sc), id->
len,
247 md = &
id->desc_list[0];
251 if (ext_desc && dma_map) {
265 eprintk(
"Error copying indirect table %d\n", err);
269 eprintk(
"This command uses external indirect buffer\n");
278 eprintk(
"fail to map %p %d\n", iue, scsi_sg_count(sc));
286 err = rdma_io(sc, sg, nsg, md, nmd, dir,
len);
292 if (token && dma_map)
298 static int data_out_desc_size(
struct srp_cmd *cmd)
314 eprintk(
"client error. Invalid data_out_format %x\n", fmt);
325 srp_rdma_t rdma_io,
int dma_map,
int ext_desc)
335 dir = srp_cmd_direction(cmd);
337 offset += data_out_desc_size(cmd);
342 format = cmd->
buf_fmt & ((1
U << 4) - 1);
350 err = srp_direct_data(sc, md, dir, rdma_io, dma_map, ext_desc);
355 err = srp_indirect_data(sc, cmd,
id, dir, rdma_io, dma_map,
359 eprintk(
"Unknown format %d %x\n", dir, format);
377 fmt = cmd->
buf_fmt & ((1
U << 4) - 1);
378 offset += data_out_desc_size(cmd);
393 eprintk(
"invalid data format %x\n", fmt);
421 dir = srp_cmd_direction(cmd);
422 len = vscsis_data_length(cmd, dir);
424 dprintk(
"%p %x %lx %d %d %d %llx\n", info, cmd->
cdb[0],
425 cmd->lun, dir, len, tag, (
unsigned long long) cmd->
tag);
433 sc->
sdb.length = len;
434 sc->
sdb.table.sgl = (
void *) (
unsigned long)
addr;