Commit 1afb1eff authored by Swapnil Ingle's avatar Swapnil Ingle Committed by Tomasz Zawadzki
Browse files

nvmf/vfio_user: simplify cq_is_full()



Made cq_is_full() as wrapper around cq_free_slots()

Signed-off-by: default avatarSwapnil Ingle <swapnil.ingle@nutanix.com>
Change-Id: I392f62e959c7e23b4360e77759027ea55c2398b9
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16789


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarJohn Levon <levon@movementarian.org>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
parent 23b518a0
Loading
Loading
Loading
Loading
+25 −29
Original line number Diff line number Diff line
@@ -605,6 +605,25 @@ cq_tail_advance(struct nvmf_vfio_user_cq *cq)
	}
}

static uint32_t
cq_free_slots(struct nvmf_vfio_user_cq *cq)
{
	uint32_t free_slots;

	assert(cq != NULL);

	if (cq->tail == cq->last_head) {
		free_slots = cq->size;
	} else if (cq->tail > cq->last_head) {
		free_slots = cq->size - (cq->tail - cq->last_head);
	} else {
		free_slots = cq->last_head - cq->tail;
	}
	assert(free_slots > 0);

	return free_slots - 1;
}

/*
 * As per NVMe Base spec 3.3.1.2.1, we are supposed to implement CQ flow
 * control: if there is no space in the CQ, we should wait until there is.
@@ -619,22 +638,18 @@ cq_tail_advance(struct nvmf_vfio_user_cq *cq)
static inline bool
cq_is_full(struct nvmf_vfio_user_cq *cq)
{
	uint32_t qindex;
	uint32_t free_cq_slots;

	assert(cq != NULL);

	qindex = *cq_tailp(cq) + 1;
	if (spdk_unlikely(qindex == cq->size)) {
		qindex = 0;
	}

	if (qindex != cq->last_head) {
		return false;
	}
	free_cq_slots = cq_free_slots(cq);

	if (spdk_unlikely(free_cq_slots == 0)) {
		cq->last_head = *cq_dbl_headp(cq);
		free_cq_slots = cq_free_slots(cq);
	}

	return qindex == cq->last_head;
	return free_cq_slots == 0;
}

static bool
@@ -2507,25 +2522,6 @@ consume_cmd(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvmf_vfio_user_sq *sq,
	return handle_cmd_req(ctrlr, cmd, sq);
}

static uint32_t
cq_free_slots(struct nvmf_vfio_user_cq *cq)
{
	uint32_t free_slots;

	assert(cq != NULL);

	if (cq->tail == cq->last_head) {
		free_slots = cq->size;
	} else if (cq->tail > cq->last_head) {
		free_slots = cq->size - (cq->tail - cq->last_head);
	} else {
		free_slots = cq->last_head - cq->tail;
	}
	assert(free_slots > 0);

	return free_slots - 1;
}

/* Returns the number of commands processed, or a negative value on error. */
static int
handle_sq_tdbl_write(struct nvmf_vfio_user_ctrlr *ctrlr, const uint32_t new_tail,