Skip to content

Commit 08818c6

Browse files
floatiouskwilczynski
authored andcommitted
misc: pci_endpoint_test: Add support for PCITEST_IRQ_TYPE_AUTO
For PCITEST_MSI we really want to set PCITEST_SET_IRQTYPE explicitly to PCITEST_IRQ_TYPE_MSI, since we want to test if MSI works. For PCITEST_MSIX we really want to set PCITEST_SET_IRQTYPE explicitly to PCITEST_IRQ_TYPE_MSIX, since we want to test if MSI works. For PCITEST_LEGACY_IRQ we really want to set PCITEST_SET_IRQTYPE explicitly to PCITEST_IRQ_TYPE_INTX, since we want to test if INTx works. However, for PCITEST_WRITE, PCITEST_READ, PCITEST_COPY, we really don't care which IRQ type that is used, we just want to use a IRQ type that is supported by the EPC. The old behavior was to always use MSI for PCITEST_WRITE, PCITEST_READ, PCITEST_COPY, was to always set IRQ type to MSI before doing the actual test, however, there are EPC drivers that do not support MSI. Add a new PCITEST_IRQ_TYPE_AUTO, that will use the CAPS register to see which IRQ types the endpoint supports, and use one of the supported IRQ types. For backwards compatibility, if the endpoint does not expose any supported IRQ type in the CAPS register, simply fallback to using MSI, as it was unconditionally done before. Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7c3b54c commit 08818c6

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

drivers/misc/pci_endpoint_test.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666

6767
#define PCI_ENDPOINT_TEST_CAPS 0x30
6868
#define CAP_UNALIGNED_ACCESS BIT(0)
69+
#define CAP_MSI BIT(1)
70+
#define CAP_MSIX BIT(2)
71+
#define CAP_INTX BIT(3)
6972

7073
#define PCI_DEVICE_ID_TI_AM654 0xb00c
7174
#define PCI_DEVICE_ID_TI_J7200 0xb00f
@@ -113,6 +116,7 @@ struct pci_endpoint_test {
113116
struct miscdevice miscdev;
114117
enum pci_barno test_reg_bar;
115118
size_t alignment;
119+
u32 ep_caps;
116120
const char *name;
117121
};
118122

@@ -803,11 +807,23 @@ static int pci_endpoint_test_set_irq(struct pci_endpoint_test *test,
803807
int ret;
804808

805809
if (req_irq_type < PCITEST_IRQ_TYPE_INTX ||
806-
req_irq_type > PCITEST_IRQ_TYPE_MSIX) {
810+
req_irq_type > PCITEST_IRQ_TYPE_AUTO) {
807811
dev_err(dev, "Invalid IRQ type option\n");
808812
return -EINVAL;
809813
}
810814

815+
if (req_irq_type == PCITEST_IRQ_TYPE_AUTO) {
816+
if (test->ep_caps & CAP_MSI)
817+
req_irq_type = PCITEST_IRQ_TYPE_MSI;
818+
else if (test->ep_caps & CAP_MSIX)
819+
req_irq_type = PCITEST_IRQ_TYPE_MSIX;
820+
else if (test->ep_caps & CAP_INTX)
821+
req_irq_type = PCITEST_IRQ_TYPE_INTX;
822+
else
823+
/* fallback to MSI if no caps defined */
824+
req_irq_type = PCITEST_IRQ_TYPE_MSI;
825+
}
826+
811827
if (test->irq_type == req_irq_type)
812828
return 0;
813829

@@ -893,13 +909,12 @@ static void pci_endpoint_test_get_capabilities(struct pci_endpoint_test *test)
893909
{
894910
struct pci_dev *pdev = test->pdev;
895911
struct device *dev = &pdev->dev;
896-
u32 caps;
897912

898-
caps = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CAPS);
899-
dev_dbg(dev, "PCI_ENDPOINT_TEST_CAPS: %#x\n", caps);
913+
test->ep_caps = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CAPS);
914+
dev_dbg(dev, "PCI_ENDPOINT_TEST_CAPS: %#x\n", test->ep_caps);
900915

901916
/* CAP_UNALIGNED_ACCESS is set if the EP can do unaligned access */
902-
if (caps & CAP_UNALIGNED_ACCESS)
917+
if (test->ep_caps & CAP_UNALIGNED_ACCESS)
903918
test->alignment = 0;
904919
}
905920

include/uapi/linux/pcitest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define PCITEST_IRQ_TYPE_INTX 0
2828
#define PCITEST_IRQ_TYPE_MSI 1
2929
#define PCITEST_IRQ_TYPE_MSIX 2
30+
#define PCITEST_IRQ_TYPE_AUTO 3
3031

3132
#define PCITEST_FLAGS_USE_DMA 0x00000001
3233

tools/testing/selftests/pci_endpoint/pci_endpoint_test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ TEST_F(pci_ep_data_transfer, READ_TEST)
181181
if (variant->use_dma)
182182
param.flags = PCITEST_FLAGS_USE_DMA;
183183

184-
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_MSI);
185-
ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type");
184+
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_AUTO);
185+
ASSERT_EQ(0, ret) TH_LOG("Can't set AUTO IRQ type");
186186

187187
for (i = 0; i < ARRAY_SIZE(test_size); i++) {
188188
param.size = test_size[i];
@@ -200,8 +200,8 @@ TEST_F(pci_ep_data_transfer, WRITE_TEST)
200200
if (variant->use_dma)
201201
param.flags = PCITEST_FLAGS_USE_DMA;
202202

203-
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_MSI);
204-
ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type");
203+
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_AUTO);
204+
ASSERT_EQ(0, ret) TH_LOG("Can't set AUTO IRQ type");
205205

206206
for (i = 0; i < ARRAY_SIZE(test_size); i++) {
207207
param.size = test_size[i];
@@ -219,8 +219,8 @@ TEST_F(pci_ep_data_transfer, COPY_TEST)
219219
if (variant->use_dma)
220220
param.flags = PCITEST_FLAGS_USE_DMA;
221221

222-
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_MSI);
223-
ASSERT_EQ(0, ret) TH_LOG("Can't set MSI IRQ type");
222+
pci_ep_ioctl(PCITEST_SET_IRQTYPE, PCITEST_IRQ_TYPE_AUTO);
223+
ASSERT_EQ(0, ret) TH_LOG("Can't set AUTO IRQ type");
224224

225225
for (i = 0; i < ARRAY_SIZE(test_size); i++) {
226226
param.size = test_size[i];

0 commit comments

Comments
 (0)