IB/iser: Generalize map/unmap dma tasks
Avoid code duplication and add the mapping/unmapping of the protection buffers to the iser_dma_map_task_data/iser_dma_unmap_task_data functions. Link: https://lore.kernel.org/r/20220308145546.8372-4-mgurtovoy@nvidia.com Reviewed-by: Sergey Gorenko <sergeygo@nvidia.com> Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com> Acked-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
ee4efeaea8
commit
80303ee244
@ -531,13 +531,12 @@ int iser_post_recvm(struct iser_conn *iser_conn,
|
||||
int iser_post_send(struct ib_conn *ib_conn, struct iser_tx_desc *tx_desc);
|
||||
|
||||
int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
|
||||
struct iser_data_buf *data,
|
||||
enum iser_data_dir iser_dir,
|
||||
enum dma_data_direction dma_dir);
|
||||
|
||||
void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task,
|
||||
struct iser_data_buf *data,
|
||||
enum dma_data_direction dir);
|
||||
enum iser_data_dir iser_dir,
|
||||
enum dma_data_direction dma_dir);
|
||||
|
||||
int iser_initialize_task_headers(struct iscsi_task *task,
|
||||
struct iser_tx_desc *tx_desc);
|
||||
|
@ -52,26 +52,13 @@ static int iser_prepare_read_cmd(struct iscsi_task *task)
|
||||
struct iser_mem_reg *mem_reg;
|
||||
int err;
|
||||
struct iser_ctrl *hdr = &iser_task->desc.iser_header;
|
||||
struct iser_data_buf *buf_in = &iser_task->data[ISER_DIR_IN];
|
||||
|
||||
err = iser_dma_map_task_data(iser_task,
|
||||
buf_in,
|
||||
ISER_DIR_IN,
|
||||
DMA_FROM_DEVICE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (scsi_prot_sg_count(iser_task->sc)) {
|
||||
struct iser_data_buf *pbuf_in = &iser_task->prot[ISER_DIR_IN];
|
||||
|
||||
err = iser_dma_map_task_data(iser_task,
|
||||
pbuf_in,
|
||||
ISER_DIR_IN,
|
||||
DMA_FROM_DEVICE);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
err = iser_reg_mem_fastreg(iser_task, ISER_DIR_IN, false);
|
||||
if (err) {
|
||||
iser_err("Failed to set up Data-IN RDMA\n");
|
||||
@ -106,23 +93,11 @@ static int iser_prepare_write_cmd(struct iscsi_task *task, unsigned int imm_sz,
|
||||
struct ib_sge *tx_dsg = &iser_task->desc.tx_sg[1];
|
||||
|
||||
err = iser_dma_map_task_data(iser_task,
|
||||
buf_out,
|
||||
ISER_DIR_OUT,
|
||||
DMA_TO_DEVICE);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (scsi_prot_sg_count(iser_task->sc)) {
|
||||
struct iser_data_buf *pbuf_out = &iser_task->prot[ISER_DIR_OUT];
|
||||
|
||||
err = iser_dma_map_task_data(iser_task,
|
||||
pbuf_out,
|
||||
ISER_DIR_OUT,
|
||||
DMA_TO_DEVICE);
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
err = iser_reg_mem_fastreg(iser_task, ISER_DIR_OUT,
|
||||
buf_out->data_len == imm_sz);
|
||||
if (err != 0) {
|
||||
@ -740,27 +715,16 @@ void iser_task_rdma_init(struct iscsi_iser_task *iser_task)
|
||||
|
||||
void iser_task_rdma_finalize(struct iscsi_iser_task *iser_task)
|
||||
{
|
||||
int prot_count = scsi_prot_sg_count(iser_task->sc);
|
||||
|
||||
if (iser_task->dir[ISER_DIR_IN]) {
|
||||
iser_unreg_mem_fastreg(iser_task, ISER_DIR_IN);
|
||||
iser_dma_unmap_task_data(iser_task,
|
||||
&iser_task->data[ISER_DIR_IN],
|
||||
iser_dma_unmap_task_data(iser_task, ISER_DIR_IN,
|
||||
DMA_FROM_DEVICE);
|
||||
if (prot_count)
|
||||
iser_dma_unmap_task_data(iser_task,
|
||||
&iser_task->prot[ISER_DIR_IN],
|
||||
DMA_FROM_DEVICE);
|
||||
}
|
||||
|
||||
if (iser_task->dir[ISER_DIR_OUT]) {
|
||||
iser_unreg_mem_fastreg(iser_task, ISER_DIR_OUT);
|
||||
iser_dma_unmap_task_data(iser_task,
|
||||
&iser_task->data[ISER_DIR_OUT],
|
||||
iser_dma_unmap_task_data(iser_task, ISER_DIR_OUT,
|
||||
DMA_TO_DEVICE);
|
||||
if (prot_count)
|
||||
iser_dma_unmap_task_data(iser_task,
|
||||
&iser_task->prot[ISER_DIR_OUT],
|
||||
DMA_TO_DEVICE);
|
||||
}
|
||||
}
|
||||
|
@ -70,10 +70,10 @@ static void iser_reg_desc_put_fr(struct ib_conn *ib_conn,
|
||||
}
|
||||
|
||||
int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
|
||||
struct iser_data_buf *data,
|
||||
enum iser_data_dir iser_dir,
|
||||
enum dma_data_direction dma_dir)
|
||||
{
|
||||
struct iser_data_buf *data = &iser_task->data[iser_dir];
|
||||
struct ib_device *dev;
|
||||
|
||||
iser_task->dir[iser_dir] = 1;
|
||||
@ -84,17 +84,40 @@ int iser_dma_map_task_data(struct iscsi_iser_task *iser_task,
|
||||
iser_err("dma_map_sg failed!!!\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (scsi_prot_sg_count(iser_task->sc)) {
|
||||
struct iser_data_buf *pdata = &iser_task->prot[iser_dir];
|
||||
|
||||
pdata->dma_nents = ib_dma_map_sg(dev, pdata->sg, pdata->size, dma_dir);
|
||||
if (unlikely(pdata->dma_nents == 0)) {
|
||||
iser_err("protection dma_map_sg failed!!!\n");
|
||||
goto out_unmap;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out_unmap:
|
||||
ib_dma_unmap_sg(dev, data->sg, data->size, dma_dir);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
void iser_dma_unmap_task_data(struct iscsi_iser_task *iser_task,
|
||||
struct iser_data_buf *data,
|
||||
enum dma_data_direction dir)
|
||||
enum iser_data_dir iser_dir,
|
||||
enum dma_data_direction dma_dir)
|
||||
{
|
||||
struct iser_data_buf *data = &iser_task->data[iser_dir];
|
||||
struct ib_device *dev;
|
||||
|
||||
dev = iser_task->iser_conn->ib_conn.device->ib_device;
|
||||
ib_dma_unmap_sg(dev, data->sg, data->size, dir);
|
||||
ib_dma_unmap_sg(dev, data->sg, data->size, dma_dir);
|
||||
|
||||
if (scsi_prot_sg_count(iser_task->sc)) {
|
||||
struct iser_data_buf *pdata = &iser_task->prot[iser_dir];
|
||||
|
||||
ib_dma_unmap_sg(dev, pdata->sg, pdata->size, dma_dir);
|
||||
}
|
||||
}
|
||||
|
||||
static int iser_reg_dma(struct iser_device *device, struct iser_data_buf *mem,
|
||||
|
Loading…
Reference in New Issue
Block a user