Commit 6b71006d authored by Thanos Makatos's avatar Thanos Makatos Committed by Tomasz Zawadzki
Browse files

nvmf/vfio-user: refactor nvmf_vfio_user_prop_req_rsp



Signed-off-by: default avatarThanos Makatos <thanos.makatos@nutanix.com>
Change-Id: Id6b0a4bc12aa8799fdb1ce1b286c308c9a79083b
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15389


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJohn Levon <levon@movementarian.org>
parent 82b2c192
Loading
Loading
Loading
Loading
+45 −37
Original line number Diff line number Diff line
@@ -2720,36 +2720,26 @@ enable_ctrlr(struct nvmf_vfio_user_ctrlr *vu_ctrlr)
}

static int
nvmf_vfio_user_prop_req_rsp(struct nvmf_vfio_user_req *req, void *cb_arg)
nvmf_vfio_user_prop_req_rsp_set(struct nvmf_vfio_user_req *req,
				struct nvmf_vfio_user_sq *sq)
{
	struct nvmf_vfio_user_sq *sq = cb_arg;
	struct nvmf_vfio_user_ctrlr *vu_ctrlr;
	int ret;

	assert(sq != NULL);
	assert(req != NULL);

	if (req->req.cmd->prop_get_cmd.fctype == SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET) {
		assert(sq->ctrlr != NULL);
		assert(req != NULL);
	union spdk_nvme_cc_register cc, diff;

		memcpy(req->req.data,
		       &req->req.rsp->prop_get_rsp.value.u64,
		       req->req.length);
	} else {
	assert(req->req.cmd->prop_set_cmd.fctype == SPDK_NVMF_FABRIC_COMMAND_PROPERTY_SET);
	assert(sq->ctrlr != NULL);
	vu_ctrlr = sq->ctrlr;

		if (req->req.cmd->prop_set_cmd.ofst == offsetof(struct spdk_nvme_registers, cc)) {
			union spdk_nvme_cc_register cc, diff;
	if (req->req.cmd->prop_set_cmd.ofst != offsetof(struct spdk_nvme_registers, cc)) {
		return 0;
	}

	cc.raw = req->req.cmd->prop_set_cmd.value.u64;
	diff.raw = cc.raw ^ req->cc.raw;

	if (diff.bits.en) {
		if (cc.bits.en) {
					ret = enable_ctrlr(vu_ctrlr);
			int ret = enable_ctrlr(vu_ctrlr);
			if (ret) {
				SPDK_ERRLOG("%s: failed to enable ctrlr\n", ctrlr_id(vu_ctrlr));
				return ret;
@@ -2769,12 +2759,30 @@ nvmf_vfio_user_prop_req_rsp(struct nvmf_vfio_user_req *req, void *cb_arg)
	if (vu_ctrlr->reset_shn) {
		disable_ctrlr(vu_ctrlr);
	}
	return 0;
}
	}

static int
nvmf_vfio_user_prop_req_rsp(struct nvmf_vfio_user_req *req, void *cb_arg)
{
	struct nvmf_vfio_user_sq *sq = cb_arg;

	assert(sq != NULL);
	assert(req != NULL);

	if (req->req.cmd->prop_get_cmd.fctype == SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET) {
		assert(sq->ctrlr != NULL);
		assert(req != NULL);

		memcpy(req->req.data,
		       &req->req.rsp->prop_get_rsp.value.u64,
		       req->req.length);
		return 0;
	}

	return nvmf_vfio_user_prop_req_rsp_set(req, sq);
}

/*
 * Handles a write at offset 0x1000 or more; this is the non-mapped path when a
 * doorbell is written via access_bar0_fn().