From 3cd14b66af0ee49b0f4b6fb0d7ae03b4b5cecacf Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 16 Nov 2021 15:34:10 -0700 Subject: [PATCH] idxd: Move batch prep functions up in file No code changes. Move these up so they can be used by some of the regular command submit paths in future patches. Signed-off-by: Ben Walker Change-Id: Ib8e54d47f7df35771b6c89d7c49d5182cae79e47 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10285 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Changpeng Liu Reviewed-by: Paul Luse Reviewed-by: John Kariuki Reviewed-by: Jim Harris --- lib/idxd/idxd.c | 127 ++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 63 deletions(-) diff --git a/lib/idxd/idxd.c b/lib/idxd/idxd.c index 290f6a8c7..9b198dc79 100644 --- a/lib/idxd/idxd.c +++ b/lib/idxd/idxd.c @@ -393,6 +393,70 @@ _idxd_prep_command(struct spdk_idxd_io_channel *chan, spdk_idxd_req_cb cb_fn, return 0; } +static bool +_is_batch_valid(struct idxd_batch *batch, struct spdk_idxd_io_channel *chan) +{ + return batch->chan == chan; +} + +static int +_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_ops **_op) +{ + struct idxd_hw_desc *desc; + struct idxd_ops *op; + + if (_is_batch_valid(batch, chan) == false) { + SPDK_ERRLOG("Attempt to add to an invalid batch.\n"); + return -EINVAL; + } + + assert(batch != NULL); /* suppress scan-build warning. */ + if (batch->index == DESC_PER_BATCH) { + SPDK_ERRLOG("Attempt to add to a batch that is already full.\n"); + return -EINVAL; + } + + desc = *_desc = &batch->user_desc[batch->index]; + op = *_op = &batch->user_ops[batch->index]; + + op->desc = desc; + SPDK_DEBUGLOG(idxd, "Prep batch %p index %u\n", batch, batch->index); + + batch->index++; + + desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; + op->cb_arg = cb_arg; + op->cb_fn = cb_fn; + op->batch = batch; + + return 0; +} + +static int +_idxd_batch_prep_nop(struct spdk_idxd_io_channel *chan, struct idxd_batch *batch) +{ + struct idxd_hw_desc *desc; + struct idxd_ops *op; + int rc; + + /* Common prep. */ + rc = _idxd_prep_batch_cmd(chan, NULL, NULL, batch, &desc, &op); + if (rc) { + return rc; + } + + /* Command specific. */ + desc->opcode = IDXD_OPCODE_NOOP; + + if (chan->idxd->impl->nop_check && chan->idxd->impl->nop_check(chan->idxd)) { + desc->xfer_size = 1; + } + return 0; +} + + int spdk_idxd_submit_copy(struct spdk_idxd_io_channel *chan, void *dst, const void *src, uint64_t nbytes, spdk_idxd_req_cb cb_fn, void *cb_arg) @@ -694,12 +758,6 @@ spdk_idxd_batch_create(struct spdk_idxd_io_channel *chan) return batch; } -static bool -_is_batch_valid(struct idxd_batch *batch, struct spdk_idxd_io_channel *chan) -{ - return batch->chan == chan; -} - static void _free_batch(struct idxd_batch *batch, struct spdk_idxd_io_channel *chan) { @@ -789,63 +847,6 @@ spdk_idxd_batch_submit(struct spdk_idxd_io_channel *chan, struct idxd_batch *bat return 0; } -static int -_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_ops **_op) -{ - struct idxd_hw_desc *desc; - struct idxd_ops *op; - - if (_is_batch_valid(batch, chan) == false) { - SPDK_ERRLOG("Attempt to add to an invalid batch.\n"); - return -EINVAL; - } - - assert(batch != NULL); /* suppress scan-build warning. */ - if (batch->index == DESC_PER_BATCH) { - SPDK_ERRLOG("Attempt to add to a batch that is already full.\n"); - return -EINVAL; - } - - desc = *_desc = &batch->user_desc[batch->index]; - op = *_op = &batch->user_ops[batch->index]; - - op->desc = desc; - SPDK_DEBUGLOG(idxd, "Prep batch %p index %u\n", batch, batch->index); - - batch->index++; - - desc->flags = IDXD_FLAG_COMPLETION_ADDR_VALID | IDXD_FLAG_REQUEST_COMPLETION; - op->cb_arg = cb_arg; - op->cb_fn = cb_fn; - op->batch = batch; - - return 0; -} - -static int -_idxd_batch_prep_nop(struct spdk_idxd_io_channel *chan, struct idxd_batch *batch) -{ - struct idxd_hw_desc *desc; - struct idxd_ops *op; - int rc; - - /* Common prep. */ - rc = _idxd_prep_batch_cmd(chan, NULL, NULL, batch, &desc, &op); - if (rc) { - return rc; - } - - /* Command specific. */ - desc->opcode = IDXD_OPCODE_NOOP; - - if (chan->idxd->impl->nop_check && chan->idxd->impl->nop_check(chan->idxd)) { - desc->xfer_size = 1; - } - 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)