Commit 32e54c6b authored by John Levon's avatar John Levon Committed by Tomasz Zawadzki
Browse files

nvmf/vfio-user: refactor suppressed IRQ handling



No functional change; this just makes the poll code a little easier to
read.

Signed-off-by: default avatarJohn Levon <john.levon@nutanix.com>
Change-Id: If6d1dcd940ed5b461856b535b1bf01c4efa8612a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12076


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent f41248ff
Loading
Loading
Loading
Loading
+42 −25
Original line number Diff line number Diff line
@@ -4332,33 +4332,36 @@ handle_cmd_req(struct nvmf_vfio_user_ctrlr *ctrlr, struct spdk_nvme_cmd *cmd,
	return 0;
}

/* Returns the number of commands processed, or a negative value on error. */
static int
nvmf_vfio_user_sq_poll(struct nvmf_vfio_user_sq *sq)
/*
 * If we suppressed an IRQ in post_completion(), check if it needs to be fired
 * here: if the host isn't up to date, and is apparently not actively processing
 * the queue (i.e. ->last_head isn't changing), we need an IRQ.
 */
static void
handle_suppressed_irq(struct nvmf_vfio_user_ctrlr *ctrlr,
		      struct nvmf_vfio_user_sq *sq)
{
	struct nvmf_vfio_user_ctrlr *ctrlr;
	struct nvmf_vfio_user_cq *cq;
	uint32_t new_tail;
	int count = 0;
	struct nvmf_vfio_user_cq *cq = ctrlr->cqs[sq->cqid];
	uint32_t cq_head;
	uint32_t cq_tail;
	int err;

	assert(sq != NULL);

	ctrlr = sq->ctrlr;
	cq = ctrlr->cqs[sq->cqid];
	if (!cq->ien || !ctrlr_interrupt_enabled(ctrlr) ||
	    !adaptive_irq_enabled(ctrlr, cq)) {
		return;
	}

	if (cq->ien && ctrlr_interrupt_enabled(ctrlr) &&
	    adaptive_irq_enabled(ctrlr, cq)) {
	cq_tail = *cq_tailp(cq);

		if (cq_tail != cq->last_trigger_irq_tail) {
	/* Already sent? */
	if (cq_tail == cq->last_trigger_irq_tail) {
		return;
	}

	spdk_ivdt_dcache(cq_dbl_headp(cq));
	cq_head = *cq_dbl_headp(cq);

	if (cq_head != cq_tail && cq_head == cq->last_head) {
				err = vfu_irq_trigger(ctrlr->endpoint->vfu_ctx, cq->iv);
		int err = vfu_irq_trigger(ctrlr->endpoint->vfu_ctx, cq->iv);
		if (err != 0) {
			SPDK_ERRLOG("%s: failed to trigger interrupt: %m\n",
				    ctrlr_id(ctrlr));
@@ -4366,9 +4369,23 @@ nvmf_vfio_user_sq_poll(struct nvmf_vfio_user_sq *sq)
			cq->last_trigger_irq_tail = cq_tail;
		}
	}

	cq->last_head = cq_head;
}
	}

/* Returns the number of commands processed, or a negative value on error. */
static int
nvmf_vfio_user_sq_poll(struct nvmf_vfio_user_sq *sq)
{
	struct nvmf_vfio_user_ctrlr *ctrlr;
	uint32_t new_tail;
	int count = 0;

	assert(sq != NULL);

	ctrlr = sq->ctrlr;

	handle_suppressed_irq(ctrlr, sq);

	/* On aarch64 platforms, doorbells update from guest VM may not be seen
	 * on SPDK target side. This is because there is memory type mismatch