From 22600b447a2904230ea0cf32e2ffffcade432f50 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 30 Dec 2021 22:47:02 +0800 Subject: [PATCH] nvmf/vfio-user: break bar0 access into 2 functions With the new added property access API, we can send a internal property access request to NVMf library, and we can use it to reset controller. Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/10952 (master) (cherry picked from commit 82a95325ceba4945dc7dc69c5876e304e61889f7) Change-Id: Iee8b1146d9eb31bc98a9b297e5c635e43e6fdb12 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11338 Reviewed-by: Tomasz Zawadzki Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins --- lib/nvmf/vfio_user.c | 77 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index aad847a64..2c4cb866a 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -1967,14 +1967,54 @@ handle_dbl_access(struct nvmf_vfio_user_ctrlr *ctrlr, uint32_t *buf, return 0; } +static size_t +vfio_user_property_access(struct nvmf_vfio_user_ctrlr *vu_ctrlr, + char *buf, size_t count, loff_t pos, + bool is_write) +{ + struct nvmf_vfio_user_req *req; + const struct spdk_nvmf_registers *regs; + + /* Construct a Fabric Property Get/Set command and send it */ + req = get_nvmf_vfio_user_req(vu_ctrlr->sqs[0]); + if (req == NULL) { + errno = ENOBUFS; + return -1; + } + regs = spdk_nvmf_ctrlr_get_regs(vu_ctrlr->ctrlr); + req->cc.raw = regs->cc.raw; + + req->cb_fn = nvmf_vfio_user_prop_req_rsp; + req->cb_arg = vu_ctrlr->sqs[0]; + req->req.cmd->prop_set_cmd.opcode = SPDK_NVME_OPC_FABRIC; + req->req.cmd->prop_set_cmd.cid = 0; + req->req.cmd->prop_set_cmd.attrib.size = (count / 4) - 1; + req->req.cmd->prop_set_cmd.ofst = pos; + if (is_write) { + req->req.cmd->prop_set_cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_SET; + if (req->req.cmd->prop_set_cmd.attrib.size) { + req->req.cmd->prop_set_cmd.value.u64 = *(uint64_t *)buf; + } else { + req->req.cmd->prop_set_cmd.value.u32.high = 0; + req->req.cmd->prop_set_cmd.value.u32.low = *(uint32_t *)buf; + } + } else { + req->req.cmd->prop_get_cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET; + } + req->req.length = count; + req->req.data = buf; + + spdk_nvmf_request_exec_fabrics(&req->req); + + return count; +} + static ssize_t access_bar0_fn(vfu_ctx_t *vfu_ctx, char *buf, size_t count, loff_t pos, bool is_write) { struct nvmf_vfio_user_endpoint *endpoint = vfu_get_private(vfu_ctx); struct nvmf_vfio_user_ctrlr *ctrlr; - struct nvmf_vfio_user_req *req; - const struct spdk_nvmf_registers *regs; int ret; ctrlr = endpoint->ctrlr; @@ -2003,38 +2043,7 @@ access_bar0_fn(vfu_ctx_t *vfu_ctx, char *buf, size_t count, loff_t pos, return ret; } - /* Construct a Fabric Property Get/Set command and send it */ - req = get_nvmf_vfio_user_req(ctrlr->sqs[0]); - if (req == NULL) { - errno = ENOBUFS; - return -1; - } - regs = spdk_nvmf_ctrlr_get_regs(ctrlr->ctrlr); - req->cc.raw = regs->cc.raw; - - req->cb_fn = nvmf_vfio_user_prop_req_rsp; - req->cb_arg = ctrlr->sqs[0]; - req->req.cmd->prop_set_cmd.opcode = SPDK_NVME_OPC_FABRIC; - req->req.cmd->prop_set_cmd.cid = 0; - req->req.cmd->prop_set_cmd.attrib.size = (count / 4) - 1; - req->req.cmd->prop_set_cmd.ofst = pos; - if (is_write) { - req->req.cmd->prop_set_cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_SET; - if (req->req.cmd->prop_set_cmd.attrib.size) { - req->req.cmd->prop_set_cmd.value.u64 = *(uint64_t *)buf; - } else { - req->req.cmd->prop_set_cmd.value.u32.high = 0; - req->req.cmd->prop_set_cmd.value.u32.low = *(uint32_t *)buf; - } - } else { - req->req.cmd->prop_get_cmd.fctype = SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET; - } - req->req.length = count; - req->req.data = buf; - - spdk_nvmf_request_exec_fabrics(&req->req); - - return count; + return vfio_user_property_access(ctrlr, buf, count, pos, is_write); } static ssize_t