Lines Matching +full:cmd +full:- +full:db
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 #include <linux/dma-mapping.h>
30 q->pool = kcalloc(max, sizeof(struct iu_entry *), GFP_KERNEL); in srp_iu_pool_alloc()
31 if (!q->pool) in srp_iu_pool_alloc()
32 return -ENOMEM; in srp_iu_pool_alloc()
33 q->items = kcalloc(max, sizeof(struct iu_entry), GFP_KERNEL); in srp_iu_pool_alloc()
34 if (!q->items) in srp_iu_pool_alloc()
37 spin_lock_init(&q->lock); in srp_iu_pool_alloc()
38 kfifo_init(&q->queue, (void *)q->pool, max * sizeof(void *)); in srp_iu_pool_alloc()
40 for (i = 0, iue = q->items; i < max; i++) { in srp_iu_pool_alloc()
41 kfifo_in(&q->queue, (void *)&iue, sizeof(void *)); in srp_iu_pool_alloc()
42 iue->sbuf = ring[i]; in srp_iu_pool_alloc()
48 kfree(q->pool); in srp_iu_pool_alloc()
49 return -ENOMEM; in srp_iu_pool_alloc()
54 kfree(q->items); in srp_iu_pool_free()
55 kfree(q->pool); in srp_iu_pool_free()
72 ring[i]->buf = dma_alloc_coherent(dev, size, &ring[i]->dma, in srp_ring_alloc()
74 if (!ring[i]->buf) in srp_ring_alloc()
81 if (ring[i]->buf) { in srp_ring_alloc()
82 dma_free_coherent(dev, size, ring[i]->buf, in srp_ring_alloc()
83 ring[i]->dma); in srp_ring_alloc()
98 dma_free_coherent(dev, size, ring[i]->buf, ring[i]->dma); in srp_ring_free()
109 spin_lock_init(&target->lock); in srp_target_alloc()
111 target->dev = dev; in srp_target_alloc()
113 target->srp_iu_size = iu_size; in srp_target_alloc()
114 target->rx_ring_size = nr; in srp_target_alloc()
115 target->rx_ring = srp_ring_alloc(target->dev, nr, iu_size); in srp_target_alloc()
116 if (!target->rx_ring) in srp_target_alloc()
117 return -ENOMEM; in srp_target_alloc()
118 err = srp_iu_pool_alloc(&target->iu_queue, nr, target->rx_ring); in srp_target_alloc()
122 dev_set_drvdata(target->dev, target); in srp_target_alloc()
126 srp_ring_free(target->dev, target->rx_ring, nr, iu_size); in srp_target_alloc()
127 return -ENOMEM; in srp_target_alloc()
132 dev_set_drvdata(target->dev, NULL); in srp_target_free()
133 srp_ring_free(target->dev, target->rx_ring, target->rx_ring_size, in srp_target_free()
134 target->srp_iu_size); in srp_target_free()
135 srp_iu_pool_free(&target->iu_queue); in srp_target_free()
142 if (kfifo_out_locked(&target->iu_queue.queue, (void *)&iue, in srp_iu_get()
144 &target->iu_queue.lock) != sizeof(void *)) { in srp_iu_get()
150 iue->target = target; in srp_iu_get()
151 iue->flags = 0; in srp_iu_get()
157 kfifo_in_locked(&iue->target->iu_queue.queue, (void *)&iue, in srp_iu_put()
158 sizeof(void *), &iue->target->iu_queue.lock); in srp_iu_put()
161 static int srp_direct_data(struct ibmvscsis_cmd *cmd, struct srp_direct_buf *md, in srp_direct_data() argument
170 iue = cmd->iue; in srp_direct_data()
171 sg = cmd->se_cmd.t_data_sg; in srp_direct_data()
172 nsg = dma_map_sg(iue->target->dev, sg, cmd->se_cmd.t_data_nents, in srp_direct_data()
176 cmd->se_cmd.t_data_nents); in srp_direct_data()
179 len = min(cmd->se_cmd.data_length, be32_to_cpu(md->len)); in srp_direct_data()
181 len = be32_to_cpu(md->len); in srp_direct_data()
184 err = rdma_io(cmd, sg, nsg, md, 1, dir, len); in srp_direct_data()
187 dma_unmap_sg(iue->target->dev, sg, nsg, DMA_BIDIRECTIONAL); in srp_direct_data()
192 static int srp_indirect_data(struct ibmvscsis_cmd *cmd, struct srp_cmd *srp_cmd, in srp_indirect_data() argument
205 iue = cmd->iue; in srp_indirect_data()
206 sg = cmd->se_cmd.t_data_sg; in srp_indirect_data()
209 nmd = be32_to_cpu(id->table_desc.len) / sizeof(struct srp_direct_buf); in srp_indirect_data()
211 if ((dir == DMA_FROM_DEVICE && nmd == srp_cmd->data_in_desc_cnt) || in srp_indirect_data()
212 (dir == DMA_TO_DEVICE && nmd == srp_cmd->data_out_desc_cnt)) { in srp_indirect_data()
213 md = &id->desc_list[0]; in srp_indirect_data()
218 md = dma_alloc_coherent(iue->target->dev, in srp_indirect_data()
219 be32_to_cpu(id->table_desc.len), in srp_indirect_data()
223 be32_to_cpu(id->table_desc.len)); in srp_indirect_data()
224 return -ENOMEM; in srp_indirect_data()
227 sg_init_one(&dummy, md, be32_to_cpu(id->table_desc.len)); in srp_indirect_data()
229 sg_dma_len(&dummy) = be32_to_cpu(id->table_desc.len); in srp_indirect_data()
230 err = rdma_io(cmd, &dummy, 1, &id->table_desc, 1, DMA_TO_DEVICE, in srp_indirect_data()
231 be32_to_cpu(id->table_desc.len)); in srp_indirect_data()
238 return -EINVAL; in srp_indirect_data()
243 nsg = dma_map_sg(iue->target->dev, sg, cmd->se_cmd.t_data_nents, in srp_indirect_data()
247 cmd->se_cmd.t_data_nents); in srp_indirect_data()
248 err = -EIO; in srp_indirect_data()
251 len = min(cmd->se_cmd.data_length, be32_to_cpu(id->len)); in srp_indirect_data()
253 len = be32_to_cpu(id->len); in srp_indirect_data()
256 err = rdma_io(cmd, sg, nsg, md, nmd, dir, len); in srp_indirect_data()
259 dma_unmap_sg(iue->target->dev, sg, nsg, DMA_BIDIRECTIONAL); in srp_indirect_data()
263 dma_free_coherent(iue->target->dev, in srp_indirect_data()
264 be32_to_cpu(id->table_desc.len), md, token); in srp_indirect_data()
269 static int data_out_desc_size(struct srp_cmd *cmd) in data_out_desc_size() argument
272 u8 fmt = cmd->buf_fmt >> 4; in data_out_desc_size()
282 sizeof(struct srp_direct_buf) * cmd->data_out_desc_cnt; in data_out_desc_size()
295 int srp_transfer_data(struct ibmvscsis_cmd *cmd, struct srp_cmd *srp_cmd, in srp_transfer_data() argument
304 if (!cmd->se_cmd.t_data_nents) in srp_transfer_data()
307 offset = srp_cmd->add_cdb_len & ~3; in srp_transfer_data()
314 format = srp_cmd->buf_fmt >> 4; in srp_transfer_data()
316 format = srp_cmd->buf_fmt & ((1U << 4) - 1); in srp_transfer_data()
322 md = (struct srp_direct_buf *)(srp_cmd->add_data + offset); in srp_transfer_data()
323 err = srp_direct_data(cmd, md, dir, rdma_io, dma_map, ext_desc); in srp_transfer_data()
326 id = (struct srp_indirect_buf *)(srp_cmd->add_data + offset); in srp_transfer_data()
327 err = srp_indirect_data(cmd, srp_cmd, id, dir, rdma_io, dma_map, in srp_transfer_data()
332 err = -EINVAL; in srp_transfer_data()
338 u64 srp_data_length(struct srp_cmd *cmd, enum dma_data_direction dir) in srp_data_length() argument
343 uint offset = cmd->add_cdb_len & ~3; in srp_data_length()
347 fmt = cmd->buf_fmt >> 4; in srp_data_length()
349 fmt = cmd->buf_fmt & ((1U << 4) - 1); in srp_data_length()
350 offset += data_out_desc_size(cmd); in srp_data_length()
357 md = (struct srp_direct_buf *)(cmd->add_data + offset); in srp_data_length()
358 len = be32_to_cpu(md->len); in srp_data_length()
361 id = (struct srp_indirect_buf *)(cmd->add_data + offset); in srp_data_length()
362 len = be32_to_cpu(id->len); in srp_data_length()
375 struct srp_direct_buf *db; in srp_get_desc_table() local
384 BUILD_BUG_ON(!__same_type(srp_cmd->add_data[0], (s8)0) in srp_get_desc_table()
385 && !__same_type(srp_cmd->add_data[0], (u8)0)); in srp_get_desc_table()
395 if (srp_cmd->buf_fmt & 0xf) in srp_get_desc_table()
397 else if (srp_cmd->buf_fmt >> 4) in srp_get_desc_table()
400 add_cdb_offset = srp_cmd->add_cdb_len & ~3; in srp_get_desc_table()
401 if (((srp_cmd->buf_fmt & 0xf) == SRP_DATA_DESC_DIRECT) || in srp_get_desc_table()
402 ((srp_cmd->buf_fmt >> 4) == SRP_DATA_DESC_DIRECT)) { in srp_get_desc_table()
403 db = (struct srp_direct_buf *)(srp_cmd->add_data in srp_get_desc_table()
405 *data_len = be32_to_cpu(db->len); in srp_get_desc_table()
406 } else if (((srp_cmd->buf_fmt & 0xf) == SRP_DATA_DESC_INDIRECT) || in srp_get_desc_table()
407 ((srp_cmd->buf_fmt >> 4) == SRP_DATA_DESC_INDIRECT)) { in srp_get_desc_table()
408 idb = (struct srp_indirect_buf *)(srp_cmd->add_data in srp_get_desc_table()
411 *data_len = be32_to_cpu(idb->len); in srp_get_desc_table()