From: Niklas Cassel <cassel@kernel.org>
To: bhelgaas@google.com, kw@linux.com, manivannan.sadhasivam@linaro.org
Cc: linux-pci@vger.kernel.org, Damien Le Moal <dlemoal@kernel.org>,
Kunihiko Hayashi <hayashi.kunihiko@socionext.com>,
Niklas Cassel <cassel@kernel.org>
Subject: [PATCH 3/4] misc: pci_endpoint_test: Let PCITEST_{READ,WRITE,COPY} set IRQ type automatically
Date: Tue, 18 Mar 2025 11:33:34 +0100 [thread overview]
Message-ID: <20250318103330.1840678-9-cassel@kernel.org> (raw)
In-Reply-To: <20250318103330.1840678-6-cassel@kernel.org>
The test cases for read/write/copy currently do:
1) ioctl(PCITEST_SET_IRQTYPE, MSI)
2) ioctl(PCITEST_{READ,WRITE,COPY})
This design is quite bad for a few reasons:
-It assumes that all PCI EPCs support MSI.
-One ioctl should be sufficient for these test cases.
Modify the PCITEST_{READ,WRITE,COPY} ioctls to set IRQ type automatically,
overwriting the currently configured IRQ type. It there are no IRQ types
supported in the CAPS register, fall back to MSI IRQs. This way the
implementation is no worse than before this commit.
Any test case that requires a specific IRQ type, e.g. MSIX_TEST, will do
an explicit PCITEST_SET_IRQTYPE ioctl at the start of the test case, thus
it is safe to always overwrite the configured IRQ type.
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/misc/pci_endpoint_test.c | 126 +++++++++++++++++--------------
1 file changed, 68 insertions(+), 58 deletions(-)
diff --git a/drivers/misc/pci_endpoint_test.c b/drivers/misc/pci_endpoint_test.c
index 3c04121d24733..cfaeeea7642ac 100644
--- a/drivers/misc/pci_endpoint_test.c
+++ b/drivers/misc/pci_endpoint_test.c
@@ -464,6 +464,62 @@ static int pci_endpoint_test_validate_xfer_params(struct device *dev,
return 0;
}
+static int pci_endpoint_test_clear_irq(struct pci_endpoint_test *test)
+{
+ pci_endpoint_test_release_irq(test);
+ pci_endpoint_test_free_irq_vectors(test);
+
+ return 0;
+}
+
+static int pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
+ int req_irq_type)
+{
+ struct pci_dev *pdev = test->pdev;
+ struct device *dev = &pdev->dev;
+ int ret;
+
+ if (req_irq_type < PCITEST_IRQ_TYPE_INTX ||
+ req_irq_type > PCITEST_IRQ_TYPE_MSIX) {
+ dev_err(dev, "Invalid IRQ type option\n");
+ return -EINVAL;
+ }
+
+ if (test->irq_type == req_irq_type)
+ return 0;
+
+ pci_endpoint_test_release_irq(test);
+ pci_endpoint_test_free_irq_vectors(test);
+
+ ret = pci_endpoint_test_alloc_irq_vectors(test, req_irq_type);
+ if (ret)
+ return ret;
+
+ ret = pci_endpoint_test_request_irq(test);
+ if (ret) {
+ pci_endpoint_test_free_irq_vectors(test);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int pci_endpoint_test_set_auto_irq(struct pci_endpoint_test *test,
+ int *irq_type)
+{
+ if (test->ep_caps & CAP_MSI)
+ *irq_type = PCITEST_IRQ_TYPE_MSI;
+ else if (test->ep_caps & CAP_MSIX)
+ *irq_type = PCITEST_IRQ_TYPE_MSIX;
+ else if (test->ep_caps & CAP_INTX)
+ *irq_type = PCITEST_IRQ_TYPE_INTX;
+ else
+ /* fallback to MSI if no caps defined */
+ *irq_type = PCITEST_IRQ_TYPE_MSI;
+
+ return pci_endpoint_test_set_irq(test, *irq_type);
+}
+
static int pci_endpoint_test_copy(struct pci_endpoint_test *test,
unsigned long arg)
{
@@ -483,7 +539,7 @@ static int pci_endpoint_test_copy(struct pci_endpoint_test *test,
dma_addr_t orig_dst_phys_addr;
size_t offset;
size_t alignment = test->alignment;
- int irq_type = test->irq_type;
+ int irq_type;
u32 src_crc32;
u32 dst_crc32;
int ret;
@@ -504,11 +560,9 @@ static int pci_endpoint_test_copy(struct pci_endpoint_test *test,
if (use_dma)
flags |= FLAG_USE_DMA;
- if (irq_type < PCITEST_IRQ_TYPE_INTX ||
- irq_type > PCITEST_IRQ_TYPE_MSIX) {
- dev_err(dev, "Invalid IRQ type option\n");
- return -EINVAL;
- }
+ ret = pci_endpoint_test_set_auto_irq(test, &irq_type);
+ if (ret)
+ return ret;
orig_src_addr = kzalloc(size + alignment, GFP_KERNEL);
if (!orig_src_addr) {
@@ -616,7 +670,7 @@ static int pci_endpoint_test_write(struct pci_endpoint_test *test,
dma_addr_t orig_phys_addr;
size_t offset;
size_t alignment = test->alignment;
- int irq_type = test->irq_type;
+ int irq_type;
size_t size;
u32 crc32;
int ret;
@@ -637,11 +691,9 @@ static int pci_endpoint_test_write(struct pci_endpoint_test *test,
if (use_dma)
flags |= FLAG_USE_DMA;
- if (irq_type < PCITEST_IRQ_TYPE_INTX ||
- irq_type > PCITEST_IRQ_TYPE_MSIX) {
- dev_err(dev, "Invalid IRQ type option\n");
- return -EINVAL;
- }
+ ret = pci_endpoint_test_set_auto_irq(test, &irq_type);
+ if (ret)
+ return ret;
orig_addr = kzalloc(size + alignment, GFP_KERNEL);
if (!orig_addr) {
@@ -714,7 +766,7 @@ static int pci_endpoint_test_read(struct pci_endpoint_test *test,
dma_addr_t orig_phys_addr;
size_t offset;
size_t alignment = test->alignment;
- int irq_type = test->irq_type;
+ int irq_type;
u32 crc32;
int ret;
@@ -734,11 +786,9 @@ static int pci_endpoint_test_read(struct pci_endpoint_test *test,
if (use_dma)
flags |= FLAG_USE_DMA;
- if (irq_type < PCITEST_IRQ_TYPE_INTX ||
- irq_type > PCITEST_IRQ_TYPE_MSIX) {
- dev_err(dev, "Invalid IRQ type option\n");
- return -EINVAL;
- }
+ ret = pci_endpoint_test_set_auto_irq(test, &irq_type);
+ if (ret)
+ return ret;
orig_addr = kzalloc(size + alignment, GFP_KERNEL);
if (!orig_addr) {
@@ -790,46 +840,6 @@ static int pci_endpoint_test_read(struct pci_endpoint_test *test,
return ret;
}
-static int pci_endpoint_test_clear_irq(struct pci_endpoint_test *test)
-{
- pci_endpoint_test_release_irq(test);
- pci_endpoint_test_free_irq_vectors(test);
-
- return 0;
-}
-
-static int pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
- int req_irq_type)
-{
- struct pci_dev *pdev = test->pdev;
- struct device *dev = &pdev->dev;
- int ret;
-
- if (req_irq_type < PCITEST_IRQ_TYPE_INTX ||
- req_irq_type > PCITEST_IRQ_TYPE_MSIX) {
- dev_err(dev, "Invalid IRQ type option\n");
- return -EINVAL;
- }
-
- if (test->irq_type == req_irq_type)
- return 0;
-
- pci_endpoint_test_release_irq(test);
- pci_endpoint_test_free_irq_vectors(test);
-
- ret = pci_endpoint_test_alloc_irq_vectors(test, req_irq_type);
- if (ret)
- return ret;
-
- ret = pci_endpoint_test_request_irq(test);
- if (ret) {
- pci_endpoint_test_free_irq_vectors(test);
- return ret;
- }
-
- return 0;
-}
-
static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
--
2.48.1
next prev parent reply other threads:[~2025-03-18 10:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 10:33 [PATCH 0/4] pci_endpoint_test: Let PCITEST_{READ,WRITE,COPY} set IRQ type automatically Niklas Cassel
2025-03-18 10:33 ` [PATCH 1/4] Revert "misc: pci_endpoint_test: Add support for PCITEST_IRQ_TYPE_AUTO" Niklas Cassel
2025-03-18 10:33 ` [PATCH 2/4] misc: pci_endpoint_test: Fetch supported IRQ types in CAPS register Niklas Cassel
2025-03-18 10:33 ` Niklas Cassel [this message]
2025-03-20 15:27 ` [PATCH 3/4] misc: pci_endpoint_test: Let PCITEST_{READ,WRITE,COPY} set IRQ type automatically Manivannan Sadhasivam
2025-03-21 13:27 ` Niklas Cassel
2025-03-22 2:24 ` Manivannan Sadhasivam
2025-03-22 5:31 ` Niklas Cassel
2025-03-23 11:34 ` Krzysztof Wilczyński
2025-03-24 18:20 ` Niklas Cassel
2025-03-24 18:36 ` Damien Le Moal
2025-03-26 6:23 ` Krzysztof Wilczyński
2025-03-26 14:39 ` Niklas Cassel
2025-03-26 16:17 ` Manivannan Sadhasivam
2025-03-26 19:22 ` Niklas Cassel
2025-03-26 19:58 ` Bjorn Helgaas
2025-04-02 7:24 ` Manivannan Sadhasivam
2025-03-18 10:33 ` [PATCH 4/4] selftests: pci_endpoint: Remove PCITEST_SET_IRQTYPE ioctls for read/write/copy 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=20250318103330.1840678-9-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=bhelgaas@google.com \
--cc=dlemoal@kernel.org \
--cc=hayashi.kunihiko@socionext.com \
--cc=kw@linux.com \
--cc=linux-pci@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.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