From 8d0334726f22dda2a971c7369d5c01504a890656 Mon Sep 17 00:00:00 2001 From: paul luse Date: Thu, 18 Jun 2020 18:32:32 -0400 Subject: [PATCH] lib/idxd: factor out common code used in prep'ing batch commands Create helper function. Signed-off-by: paul luse Change-Id: I264f0ed067e4657f21ee38d875235b3410d9d04b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2957 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins --- lib/idxd/idxd.c | 112 ++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 76 deletions(-) diff --git a/lib/idxd/idxd.c b/lib/idxd/idxd.c index 8fc39ff2b..97dc8998e 100644 --- a/lib/idxd/idxd.c +++ b/lib/idxd/idxd.c @@ -730,7 +730,6 @@ _idxd_prep_command(struct spdk_idxd_io_channel *chan, spdk_idxd_req_cb cb_fn, comp->cb_arg = cb_arg; comp->cb_fn = cb_fn; if (batch) { - assert(comp->batch == NULL); comp->batch = batch; batch->batch_desc_index = index; } @@ -966,21 +965,21 @@ spdk_idxd_batch_submit(struct spdk_idxd_io_channel *chan, struct idxd_batch *bat return 0; } -int -spdk_idxd_batch_prep_copy(struct spdk_idxd_io_channel *chan, struct idxd_batch *batch, - void *dst, const void *src, uint64_t nbytes, spdk_idxd_req_cb cb_fn, void *cb_arg) +static struct idxd_hw_desc * +_idxd_prep_batch_cmd(struct spdk_idxd_io_channel *chan, spdk_idxd_req_cb cb_fn, + void *cb_arg, struct idxd_batch *batch) { struct idxd_hw_desc *desc; struct idxd_comp *comp; if (_does_batch_exist(batch, chan) == false) { SPDK_ERRLOG("Attempt to add to a batch that doesn't exist\n."); - return -EINVAL; + return NULL; } if ((batch->cur_index - batch->start_index) == DESC_PER_BATCH) { SPDK_ERRLOG("Attempt to add to a batch that is already full\n."); - return -ENOMEM; + return NULL; } desc = &chan->ring_ctrl.user_desc[batch->cur_index]; @@ -991,16 +990,32 @@ spdk_idxd_batch_prep_copy(struct spdk_idxd_io_channel *chan, struct idxd_batch * assert(batch->cur_index > batch->start_index); desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; - desc->opcode = IDXD_OPCODE_MEMMOVE; - desc->src_addr = (uintptr_t)src; - desc->dst_addr = (uintptr_t)dst; - desc->xfer_size = nbytes; - desc->completion_addr = (uintptr_t)&comp->hw; comp->cb_arg = cb_arg; comp->cb_fn = cb_fn; comp->batch = batch; + return desc; +} + +int +spdk_idxd_batch_prep_copy(struct spdk_idxd_io_channel *chan, struct idxd_batch *batch, + void *dst, const void *src, uint64_t nbytes, spdk_idxd_req_cb cb_fn, void *cb_arg) +{ + struct idxd_hw_desc *desc; + + /* Common prep. */ + desc = _idxd_prep_batch_cmd(chan, cb_fn, cb_arg, batch); + if (desc == NULL) { + return -EINVAL; + } + + /* Command specific. */ + desc->opcode = IDXD_OPCODE_MEMMOVE; + desc->src_addr = (uintptr_t)src; + desc->dst_addr = (uintptr_t)dst; + desc->xfer_size = nbytes; + return 0; } @@ -1010,36 +1025,19 @@ spdk_idxd_batch_prep_fill(struct spdk_idxd_io_channel *chan, struct idxd_batch * spdk_idxd_req_cb cb_fn, void *cb_arg) { struct idxd_hw_desc *desc; - struct idxd_comp *comp; - if (_does_batch_exist(batch, chan) == false) { - SPDK_ERRLOG("Attempt to add to a batch that doesn't exist\n."); + /* Common prep. */ + desc = _idxd_prep_batch_cmd(chan, cb_fn, cb_arg, batch); + if (desc == NULL) { return -EINVAL; } - if ((batch->cur_index - batch->start_index) == DESC_PER_BATCH) { - SPDK_ERRLOG("Attempt to add to a batch that is already full\n."); - return -ENOMEM; - } - - desc = &chan->ring_ctrl.user_desc[batch->cur_index]; - comp = &chan->ring_ctrl.user_completions[batch->cur_index]; - SPDK_DEBUGLOG(SPDK_LOG_IDXD, "Prep batch %p index %u\n", batch, batch->cur_index); - - batch->cur_index++; - assert(batch->cur_index > batch->start_index); - - desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; + /* Command specific. */ desc->opcode = IDXD_OPCODE_MEMFILL; desc->pattern = fill_pattern; desc->dst_addr = (uintptr_t)dst; desc->xfer_size = nbytes; - desc->completion_addr = (uintptr_t)&comp->hw; - comp->cb_arg = cb_arg; - comp->cb_fn = cb_fn; - comp->batch = batch; - return 0; } @@ -1048,42 +1046,23 @@ spdk_idxd_batch_prep_dualcast(struct spdk_idxd_io_channel *chan, struct idxd_bat void *dst1, void *dst2, const void *src, uint64_t nbytes, spdk_idxd_req_cb cb_fn, void *cb_arg) { struct idxd_hw_desc *desc; - struct idxd_comp *comp; if ((uintptr_t)dst1 & (ALIGN_4K - 1) || (uintptr_t)dst2 & (ALIGN_4K - 1)) { SPDK_ERRLOG("Dualcast requires 4K alignment on dst addresses\n"); return -EINVAL; } - if (_does_batch_exist(batch, chan) == false) { - SPDK_ERRLOG("Attempt to add to a batch that doesn't exist\n."); + /* Common prep. */ + desc = _idxd_prep_batch_cmd(chan, cb_fn, cb_arg, batch); + if (desc == NULL) { return -EINVAL; } - - if ((batch->cur_index - batch->start_index) == DESC_PER_BATCH) { - SPDK_ERRLOG("Attempt to add to a batch that is already full\n."); - return -ENOMEM; - } - - desc = &chan->ring_ctrl.user_desc[batch->cur_index]; - comp = &chan->ring_ctrl.user_completions[batch->cur_index]; - SPDK_DEBUGLOG(SPDK_LOG_IDXD, "Prep batch %p index %u\n", batch, batch->cur_index); - - batch->cur_index++; - assert(batch->cur_index > batch->start_index); - - desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; desc->opcode = IDXD_OPCODE_DUALCAST; desc->src_addr = (uintptr_t)src; desc->dst_addr = (uintptr_t)dst1; desc->dest2 = (uintptr_t)dst2; desc->xfer_size = nbytes; - desc->completion_addr = (uintptr_t)&comp->hw; - comp->cb_arg = cb_arg; - comp->cb_fn = cb_fn; - comp->batch = batch; - return 0; } @@ -1093,38 +1072,19 @@ spdk_idxd_batch_prep_crc32c(struct spdk_idxd_io_channel *chan, struct idxd_batch spdk_idxd_req_cb cb_fn, void *cb_arg) { struct idxd_hw_desc *desc; - struct idxd_comp *comp; - - if (_does_batch_exist(batch, chan) == false) { - SPDK_ERRLOG("Attempt to add to a batch that doesn't exist\n."); + /* Common prep. */ + desc = _idxd_prep_batch_cmd(chan, cb_fn, cb_arg, batch); + if (desc == NULL) { return -EINVAL; } - if ((batch->cur_index - batch->start_index) == DESC_PER_BATCH) { - SPDK_ERRLOG("Attempt to add to a batch that is already full\n."); - return -ENOMEM; - } - - desc = &chan->ring_ctrl.user_desc[batch->cur_index]; - comp = &chan->ring_ctrl.user_completions[batch->cur_index]; - SPDK_DEBUGLOG(SPDK_LOG_IDXD, "Prep batch %p index %u\n", batch, batch->cur_index); - - batch->cur_index++; - assert(batch->cur_index > batch->start_index); - desc->opcode = IDXD_OPCODE_CRC32C_GEN; desc->dst_addr = (uintptr_t)dst; desc->src_addr = (uintptr_t)src; - desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; desc->flags &= IDXD_CLEAR_CRC_FLAGS; desc->crc32c.seed = seed; desc->xfer_size = nbytes; - desc->completion_addr = (uintptr_t)&comp->hw; - comp->cb_arg = cb_arg; - comp->cb_fn = cb_fn; - comp->batch = batch; - return 0; }