misc: Improvements to pci_endpoint_test driver
Subsystems (4)
PATCH v2 1/5 misc: pci_endpoint_test: Avoid using module parameter to determine irqtype
In reply to Kishon Vijay Abraham Icommit e03327122e2c ("pci_endpoint_test: Add 2 ioctl commands") uses module parameter 'irqtype' in pci_endpoint_test_set_irq() to check if irq vectors of a particular type (MSI or MSI-X or LEGACY) is already allocated. However with multi-function devices, 'irqtype' will not correctly reflect the irq type of the PCI device. Fix it here by adding 'irqtype' for each PCI device to show the irq type of a particular PCI device.
--- drivers/misc/pci_endpoint_test.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/misc/pci_endpoint_test.c +9 -3
@@ -103,6 +103,7 @@ struct pci_endpoint_test {struct completion irq_raised;int last_irq;int num_irqs; +int irq_type;/* mutex to protect the ioctls */ struct mutex mutex;struct miscdevice miscdev;
@@ -162,6 +163,7 @@ static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test)struct pci_dev *pdev = test->pdev;pci_free_irq_vectors (pdev); + test->irq_type =IRQ_TYPE_UNDEFINED ; } static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test,
@@ -196,6 +198,8 @@ static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test, irq =0 ; res = false; } + + test->irq_type = type; test->num_irqs = irq;return res;
@@ -340,6 +344,7 @@ static bool 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;u32 src_crc32;u32 dst_crc32;int err;
@@ -473,6 +478,7 @@ static bool 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;size_t size;u32 crc32;int err;
@@ -571,6 +577,7 @@ static bool 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;u32 crc32;int err;
@@ -656,7 +663,7 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test,return false; } -if (irq_type == req_irq_type) +if (test->irq_type == req_irq_type)return true;pci_endpoint_test_release_irq (test);
@@ -668,12 +675,10 @@ static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test,if (!pci_endpoint_test_request_irq (test)) goto err; - irq_type = req_irq_type;return true; err:pci_endpoint_test_free_irq_vectors (test); - irq_type =IRQ_TYPE_UNDEFINED ;return false; }
@@ -753,6 +758,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, test->test_reg_bar =0 ; test->alignment =0 ; test->pdev = pdev; + test->irq_type =IRQ_TYPE_UNDEFINED ;if (no_msi) irq_type =IRQ_TYPE_LEGACY ;
Signature · 1 line
2.17.1
v2 cover misc: Improvements to pci_endpoint_test driver
This series adds improvements and fixes to pci_endpoint_test driver mostly applicable when used with multi-function endpoint (or multiple endpoint instances using pci_epf_test).
*) Using module parameter to determine irqtype would indicate all the
pci_endpoint_test device have the same irqtype. Fix it here.
*) Add ioctl to clear irq so that "cat /proc/interrupts" only lists
the entries for the devices that is actually being used.
*) Creating more than 10 pci-endpoint-test devices results in a kernel
error.
*) Use full pci-endpoint-test name in request irq so that it's easy to
profile the interrupt details in "cat /proc/interrupts"
Changes from v1:
*) Removed a patch that references J721E device ID (That patch will
be added as part of J721E support series)
*) Removed a patch that always enable legacy interrupt. That should
be handled by pci_alloc_irq_vectors()
Kishon Vijay Abraham I (5):
misc: pci_endpoint_test: Avoid using module parameter to determine
irqtype
misc: pci_endpoint_test: Add ioctl to clear IRQ
tools: PCI: Add 'e' to clear IRQ
misc: pci_endpoint_test: Fix to support > 10 pci-endpoint-test devices
misc: pci_endpoint_test: Use full pci-endpoint-test name in request
irq
drivers/misc/pci_endpoint_test.c | 49 +++++++++++++++++++++++++------- include/uapi/linux/pcitest.h | 1 + tools/pci/pcitest.c | 16 ++++++++++- 3 files changed, 55 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 2/5 misc: pci_endpoint_test: Add ioctl to clear IRQ
Add ioctl to clear IRQ which can be used to free the allocated IRQ vectors and free the requested IRQ.
--- drivers/misc/pci_endpoint_test.c | 10 ++++++++++ include/uapi/linux/pcitest.h | 1 + 2 files changed, 11 insertions(+)
drivers/misc/pci_endpoint_test.c +10 -0
@@ -652,6 +652,13 @@ static bool pci_endpoint_test_read(struct pci_endpoint_test *test,return ret; } +static bool pci_endpoint_test_clear_irq (struct pci_endpoint_test *test) +{ +pci_endpoint_test_release_irq (test); +pci_endpoint_test_free_irq_vectors (test); +return true; +} +static bool pci_endpoint_test_set_irq (struct pci_endpoint_test *test,int req_irq_type) {
@@ -722,6 +729,9 @@ static long pci_endpoint_test_ioctl(struct file *file, unsigned int cmd,case PCITEST_GET_IRQTYPE : ret = irq_type;break ; +case PCITEST_CLEAR_IRQ : + ret =pci_endpoint_test_clear_irq (test); +break ; } ret:
include/uapi/linux/pcitest.h +1 -0
@@ -19,6 +19,7 @@#define PCITEST_MSIX _IOW('P', 0x7, int)#define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int)#define PCITEST_GET_IRQTYPE _IO('P', 0x9) +#define PCITEST_CLEAR_IRQ _IO('P', 0x10)#define PCITEST_FLAGS_USE_DMA 0x00000001
Signature · 1 line
2.17.1
PATCH v2 4/5 misc: pci_endpoint_test: Fix to support > 10 pci-endpoint-test devices
In reply to Kishon Vijay Abraham IAdding more than 10 pci-endpoint-test devices results in "kobject_add_internal failed for pci-endpoint-test.1 with -EEXIST, don't try to register things with the same name in the same directory". This is because commit 2c156ac71c6b ("misc: Add host side PCI driver for PCI test function device") limited the length of the "name" to 20 characters. Change the length of the name to 24 in order to support upto 10000 pci-endpoint-test devices.
--- drivers/misc/pci_endpoint_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/pci_endpoint_test.c +1 -1
@@ -749,7 +749,7 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, {int err;int id; -char name[20 ]; +char name[24 ];enum pci_barno bar;void __iomem *base;struct device *dev = &pdev->dev;
Signature · 1 line
2.17.1
PATCH v2 3/5 tools: PCI: Add 'e' to clear IRQ
In reply to Kishon Vijay Abraham IAdd a new command line option 'e' to invoke "PCITEST_CLEAR_IRQ" ioctl. This can be used to clear the irqs set using the 'i' option.
--- tools/pci/pcitest.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
tools/pci/pcitest.c +15 -1
@@ -30,6 +30,7 @@ struct pci_test {int irqtype;bool set_irqtype;bool get_irqtype; +bool clear_irq;bool read;bool write;bool copy;
@@ -76,6 +77,15 @@ static int run_test(struct pci_test *test)fprintf (stdout,"%s\n" , irq[ret]); } +if (test->clear_irq) { + ret =ioctl (fd,PCITEST_CLEAR_IRQ ); +fprintf (stdout,"CLEAR IRQ:\t\t" ); +if (ret <0 ) +fprintf (stdout,"FAILED\n" ); +else +fprintf (stdout,"%s\n" , result[ret]); + } +if (test->legacyirq) { ret =ioctl (fd,PCITEST_LEGACY_IRQ ,0 );fprintf (stdout,"LEGACY IRQ:\t" );
@@ -164,7 +174,7 @@ int main(int argc, char **argv)/* set default endpoint device */ test->device ="/dev/pci-endpoint-test.0" ; -while ((c =getopt (argc, argv,"D:b:m:x:i:dIlhrwcs:" )) !=EOF ) +while ((c =getopt (argc, argv,"D:b:m:x:i:deIlhrwcs:" )) !=EOF )switch (c) {case 'D' : test->device = optarg;
@@ -205,6 +215,9 @@ int main(int argc, char **argv)case 'c' : test->copy = true;continue ; +case 'e' : + test->clear_irq = true; +continue ;case 's' : test->size =strtoul (optarg,NULL ,0 );continue ;
@@ -222,6 +235,7 @@ int main(int argc, char **argv)"\t-m <msi num> MSI test (msi number between 1..32)\n" "\t-x <msix num> \tMSI-X test (msix number between 1..2048)\n" "\t-i <irq type> \tSet IRQ type (0 - Legacy, 1 - MSI, 2 - MSI-X)\n" +"\t-e Clear IRQ\n" "\t-I Get current IRQ type configured\n" "\t-d Use DMA\n" "\t-l Legacy IRQ test\n"
Signature · 1 line
2.17.1
PATCH v2 5/5 misc: pci_endpoint_test: Use full pci-endpoint-test name in request irq
In reply to Kishon Vijay Abraham IUse full pci-endpoint-test name in request irq, so that it's easy to profile the device that actually raised the interrupt.
--- drivers/misc/pci_endpoint_test.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/misc/pci_endpoint_test.c +19 -6
@@ -109,6 +109,7 @@ struct pci_endpoint_test {struct miscdevice miscdev;enum pci_barno test_reg_bar;size_t alignment; +const char *name; };struct pci_endpoint_test_data {
@@ -227,7 +228,7 @@ static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test)for (i =0 ; i < test->num_irqs; i++) { err =devm_request_irq (dev,pci_irq_vector (pdev, i), pci_endpoint_test_irqhandler, -IRQF_SHARED ,DRV_MODULE_NAME , test); +IRQF_SHARED , test->name, test);if (err) goto fail; }
@@ -807,9 +808,6 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,if (!pci_endpoint_test_alloc_irq_vectors (test, irq_type)) goto err_disable_irq; -if (!pci_endpoint_test_request_irq (test)) - goto err_disable_irq; -for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) {if (pci_resource_flags (pdev, bar) &IORESOURCE_MEM ) { base =pci_ioremap_bar (pdev, bar);
@@ -839,12 +837,21 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, }snprintf (name,sizeof (name),DRV_MODULE_NAME ".%d" , id); + test->name =kstrdup (name,GFP_KERNEL ); +if (!test->name) { + err = -ENOMEM ; + goto err_ida_remove; + } + +if (!pci_endpoint_test_request_irq (test)) + goto err_kfree_test_name; + misc_device = &test->miscdev; misc_device->minor =MISC_DYNAMIC_MINOR ; misc_device->name =kstrdup (name,GFP_KERNEL );if (!misc_device->name) { err = -ENOMEM ; - goto err_ida_remove; + goto err_release_irq; } misc_device->fops = &pci_endpoint_test_fops,
@@ -859,6 +866,12 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev, err_kfree_name:kfree (misc_device->name); +err_release_irq: +pci_endpoint_test_release_irq (test); + +err_kfree_test_name: +kfree (test->name); + err_ida_remove:ida_simple_remove (&pci_endpoint_test_ida, id);
@@ -867,7 +880,6 @@ static int pci_endpoint_test_probe(struct pci_dev *pdev,if (test->bar[bar])pci_iounmap (pdev, test->bar[bar]); } -pci_endpoint_test_release_irq (test); err_disable_irq:pci_endpoint_test_free_irq_vectors (test);
@@ -893,6 +905,7 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev)misc_deregister (&test->miscdev);kfree (misc_device->name); +kfree (test->name);ida_simple_remove (&pci_endpoint_test_ida, id);for (bar =0 ; bar <PCI_STD_NUM_BARS ; bar++) {if (test->bar[bar])
Signature · 1 line
2.17.1
Lorenzo Pieralisi
AppliedQuoted 28 lines · Kishon Vijay Abraham I
This series adds improvements and fixes to
pci_endpoint_testdriver mostly applicable when used with multi-function endpoint (or multiple endpoint instances usingpci_epf_test).*) Using module parameter to determine irqtype would indicate all the
pci_endpoint_testdevice have the same irqtype. Fix it here.
*) Add ioctl to clear irq so that "cat/proc/interrupts" only lists
the entries for the devices that is actually being used.
*) Creating more than 10 pci-endpoint-test devices results in a kernel
error.
*) Use full pci-endpoint-test name in request irq so that it's easy to
profile the interrupt details in "cat/proc/interrupts"Changes from v1:
*) Removed a patch that references J721E device ID (That patch will
be added as part of J721E support series)
*) Removed a patch that always enable legacy interrupt. That should
be handled bypci_alloc_irq_vectors()Kishon Vijay Abraham I (5):
misc:pci_endpoint_test: Avoid using module parameter to determine
irqtype
misc:pci_endpoint_test: Add ioctl to clear IRQ
tools: PCI: Add 'e' to clear IRQ
misc:pci_endpoint_test: Fix to support > 10 pci-endpoint-test devices
misc:pci_endpoint_test: Use full pci-endpoint-test name in request
irq
Quoted 4 lines
drivers/misc/pci_endpoint_test.c | 49 +++++++++++++++++++++++++------- include/uapi/linux/pcitest.h | 1 + tools/pci/pcitest.c | 16 ++++++++++- 3 files changed, 55 insertions(+), 11 deletions(-)
Applied to pci/endpoint for v5.7.
Thanks,
Lorenzo