nvmf/vfio_user: simplify cq_is_full()

Made cq_is_full() as wrapper around cq_free_slots()

Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
Change-Id: I392f62e959c7e23b4360e77759027ea55c2398b9
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16789
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: John Levon <levon@movementarian.org>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Swapnil Ingle 2023-02-07 19:36:48 +01:00 committed by Tomasz Zawadzki
parent 23b518a013
commit 1afb1effc4

View File

@ -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 * 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. * 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 static inline bool
cq_is_full(struct nvmf_vfio_user_cq *cq) cq_is_full(struct nvmf_vfio_user_cq *cq)
{ {
uint32_t qindex; uint32_t free_cq_slots;
assert(cq != NULL); assert(cq != NULL);
qindex = *cq_tailp(cq) + 1; free_cq_slots = cq_free_slots(cq);
if (spdk_unlikely(qindex == cq->size)) {
qindex = 0; if (spdk_unlikely(free_cq_slots == 0)) {
cq->last_head = *cq_dbl_headp(cq);
free_cq_slots = cq_free_slots(cq);
} }
if (qindex != cq->last_head) { return free_cq_slots == 0;
return false;
}
cq->last_head = *cq_dbl_headp(cq);
return qindex == cq->last_head;
} }
static bool 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); 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. */ /* Returns the number of commands processed, or a negative value on error. */
static int static int
handle_sq_tdbl_write(struct nvmf_vfio_user_ctrlr *ctrlr, const uint32_t new_tail, handle_sq_tdbl_write(struct nvmf_vfio_user_ctrlr *ctrlr, const uint32_t new_tail,