Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: "Manivannan Sadhasivam" <mani@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, Koichiro Den <den@valinux.co.jp>,
	Frank Li <Frank.Li@nxp.com>, Niklas Cassel <cassel@kernel.org>
Subject: [PATCH 1/2] misc: pci_endpoint_test: Fix doorbell success logic
Date: Thu, 30 Jul 2026 14:20:47 +0200	[thread overview]
Message-ID: <20260730122045.1382749-5-cassel@kernel.org> (raw)
In-Reply-To: <20260730122045.1382749-4-cassel@kernel.org>

The following was observed:
pci-endpoint-test 0000:01:00.0: Failed to trigger doorbell in endpoint
ok 23 pcie_ep_doorbell.DOORBELL_TEST

We observed a bug where an EPC driver would send two IRQs during ENABLE
DOORBELL command.

Because we got two IRQs for a single command, test->irq_raised.done was
never decreased to zero by complete(), so the
wait_for_completion_timeout() after the writel() that rings the doorbell
would return immediately, before the endpoint had managed to set
STATUS_DOORBELL_SUCCESS and triggered an IRQ corresponding to that write.

Later, when re-reading the status after disabling the doorbell,
STATUS_DOORBELL_SUCCESS will have been set by the endpoint, thus we would
not fail the test case.

Improve the test case logic such that if we failed to trigger the doorbell
in the endpoint, we make sure that we also fail the test case.

Fixes: eefb83790a0d ("misc: pci_endpoint_test: Add doorbell test case")
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
 drivers/misc/pci_endpoint_test.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 3635741c3e7a..26ab9252251f 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -1071,6 +1071,7 @@ static int pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
 	struct pci_dev *pdev = test->pdev;
 	struct device *dev = &pdev->dev;
 	int irq_type = test->irq_type;
+	int ret = 0;
 	enum pci_barno bar;
 	u32 data, status;
 	u32 addr;
@@ -1119,8 +1120,11 @@ static int pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
 
 	status = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS);
 
-	if (!left || !(status & STATUS_DOORBELL_SUCCESS))
+	if (!left || !(status & STATUS_DOORBELL_SUCCESS)) {
 		dev_err(dev, "Failed to trigger doorbell in endpoint\n");
+		/* Store error code, but continue to disable doorbell. */
+		ret = -EINVAL;
+	}
 
 	pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND,
 				 COMMAND_DISABLE_DOORBELL);
@@ -1134,10 +1138,7 @@ static int pci_endpoint_test_doorbell(struct pci_endpoint_test *test)
 		return -EINVAL;
 	}
 
-	if (!(status & STATUS_DOORBELL_SUCCESS))
-		return -EINVAL;
-
-	return 0;
+	return ret;
 }
 
 static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
-- 
2.55.0


  reply	other threads:[~2026-07-30 12:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 12:20 [PATCH 0/2] misc: pci_endpoint_test: Doorbell fix and improvement Niklas Cassel
2026-07-30 12:20 ` Niklas Cassel [this message]
2026-07-30 12:30   ` [PATCH 1/2] misc: pci_endpoint_test: Fix doorbell success logic sashiko-bot
2026-07-30 12:20 ` [PATCH 2/2] misc: pci_endpoint_test: Improve logic to check status for doorbell test case Niklas Cassel
2026-07-30 12:33   ` sashiko-bot
2026-07-30 12:45     ` Niklas Cassel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260730122045.1382749-5-cassel@kernel.org \
    --to=cassel@kernel.org \
    --cc=Frank.Li@nxp.com \
    --cc=bhelgaas@google.com \
    --cc=den@valinux.co.jp \
    --cc=kwilczynski@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mani@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox