Lines Matching full:test
3 * Host side test driver to test endpoint functionality
28 #define DRV_MODULE_NAME "pci-endpoint-test"
128 static inline u32 pci_endpoint_test_readl(struct pci_endpoint_test *test, in pci_endpoint_test_readl() argument
131 return readl(test->base + offset); in pci_endpoint_test_readl()
134 static inline void pci_endpoint_test_writel(struct pci_endpoint_test *test, in pci_endpoint_test_writel() argument
137 writel(value, test->base + offset); in pci_endpoint_test_writel()
140 static inline u32 pci_endpoint_test_bar_readl(struct pci_endpoint_test *test, in pci_endpoint_test_bar_readl() argument
143 return readl(test->bar[bar] + offset); in pci_endpoint_test_bar_readl()
146 static inline void pci_endpoint_test_bar_writel(struct pci_endpoint_test *test, in pci_endpoint_test_bar_writel() argument
149 writel(value, test->bar[bar] + offset); in pci_endpoint_test_bar_writel()
154 struct pci_endpoint_test *test = dev_id; in pci_endpoint_test_irqhandler() local
157 reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); in pci_endpoint_test_irqhandler()
159 test->last_irq = irq; in pci_endpoint_test_irqhandler()
160 complete(&test->irq_raised); in pci_endpoint_test_irqhandler()
163 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_STATUS, in pci_endpoint_test_irqhandler()
169 static void pci_endpoint_test_free_irq_vectors(struct pci_endpoint_test *test) in pci_endpoint_test_free_irq_vectors() argument
171 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_free_irq_vectors()
174 test->irq_type = IRQ_TYPE_UNDEFINED; in pci_endpoint_test_free_irq_vectors()
177 static bool pci_endpoint_test_alloc_irq_vectors(struct pci_endpoint_test *test, in pci_endpoint_test_alloc_irq_vectors() argument
181 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_alloc_irq_vectors()
210 test->irq_type = type; in pci_endpoint_test_alloc_irq_vectors()
211 test->num_irqs = irq; in pci_endpoint_test_alloc_irq_vectors()
216 static void pci_endpoint_test_release_irq(struct pci_endpoint_test *test) in pci_endpoint_test_release_irq() argument
219 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_release_irq()
222 for (i = 0; i < test->num_irqs; i++) in pci_endpoint_test_release_irq()
223 devm_free_irq(dev, pci_irq_vector(pdev, i), test); in pci_endpoint_test_release_irq()
225 test->num_irqs = 0; in pci_endpoint_test_release_irq()
228 static bool pci_endpoint_test_request_irq(struct pci_endpoint_test *test) in pci_endpoint_test_request_irq() argument
232 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_request_irq()
235 for (i = 0; i < test->num_irqs; i++) { in pci_endpoint_test_request_irq()
238 IRQF_SHARED, test->name, test); in pci_endpoint_test_request_irq()
266 static bool pci_endpoint_test_bar(struct pci_endpoint_test *test, in pci_endpoint_test_bar() argument
272 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_bar()
274 if (!test->bar[barno]) in pci_endpoint_test_bar()
279 if (barno == test->test_reg_bar) in pci_endpoint_test_bar()
283 pci_endpoint_test_bar_writel(test, barno, j, 0xA0A0A0A0); in pci_endpoint_test_bar()
286 val = pci_endpoint_test_bar_readl(test, barno, j); in pci_endpoint_test_bar()
294 static bool pci_endpoint_test_legacy_irq(struct pci_endpoint_test *test) in pci_endpoint_test_legacy_irq() argument
298 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, in pci_endpoint_test_legacy_irq()
300 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 0); in pci_endpoint_test_legacy_irq()
301 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, in pci_endpoint_test_legacy_irq()
303 val = wait_for_completion_timeout(&test->irq_raised, in pci_endpoint_test_legacy_irq()
311 static bool pci_endpoint_test_msi_irq(struct pci_endpoint_test *test, in pci_endpoint_test_msi_irq() argument
315 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_msi_irq()
317 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, in pci_endpoint_test_msi_irq()
320 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, msi_num); in pci_endpoint_test_msi_irq()
321 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, in pci_endpoint_test_msi_irq()
324 val = wait_for_completion_timeout(&test->irq_raised, in pci_endpoint_test_msi_irq()
329 if (pci_irq_vector(pdev, msi_num - 1) == test->last_irq) in pci_endpoint_test_msi_irq()
351 static bool pci_endpoint_test_copy(struct pci_endpoint_test *test, in pci_endpoint_test_copy() argument
363 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_copy()
370 size_t alignment = test->alignment; in pci_endpoint_test_copy()
371 int irq_type = test->irq_type; in pci_endpoint_test_copy()
422 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR, in pci_endpoint_test_copy()
425 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR, in pci_endpoint_test_copy()
454 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, in pci_endpoint_test_copy()
456 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR, in pci_endpoint_test_copy()
459 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, in pci_endpoint_test_copy()
462 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); in pci_endpoint_test_copy()
463 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); in pci_endpoint_test_copy()
464 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); in pci_endpoint_test_copy()
465 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, in pci_endpoint_test_copy()
468 wait_for_completion(&test->irq_raised); in pci_endpoint_test_copy()
491 static bool pci_endpoint_test_write(struct pci_endpoint_test *test, in pci_endpoint_test_write() argument
501 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_write()
506 size_t alignment = test->alignment; in pci_endpoint_test_write()
507 int irq_type = test->irq_type; in pci_endpoint_test_write()
560 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_CHECKSUM, in pci_endpoint_test_write()
563 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_SRC_ADDR, in pci_endpoint_test_write()
565 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_SRC_ADDR, in pci_endpoint_test_write()
568 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size); in pci_endpoint_test_write()
570 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); in pci_endpoint_test_write()
571 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); in pci_endpoint_test_write()
572 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); in pci_endpoint_test_write()
573 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, in pci_endpoint_test_write()
576 wait_for_completion(&test->irq_raised); in pci_endpoint_test_write()
578 reg = pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_STATUS); in pci_endpoint_test_write()
592 static bool pci_endpoint_test_read(struct pci_endpoint_test *test, in pci_endpoint_test_read() argument
602 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_read()
607 size_t alignment = test->alignment; in pci_endpoint_test_read()
608 int irq_type = test->irq_type; in pci_endpoint_test_read()
657 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_LOWER_DST_ADDR, in pci_endpoint_test_read()
659 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_UPPER_DST_ADDR, in pci_endpoint_test_read()
662 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_SIZE, size); in pci_endpoint_test_read()
664 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_FLAGS, flags); in pci_endpoint_test_read()
665 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_TYPE, irq_type); in pci_endpoint_test_read()
666 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_IRQ_NUMBER, 1); in pci_endpoint_test_read()
667 pci_endpoint_test_writel(test, PCI_ENDPOINT_TEST_COMMAND, in pci_endpoint_test_read()
670 wait_for_completion(&test->irq_raised); in pci_endpoint_test_read()
676 if (crc32 == pci_endpoint_test_readl(test, PCI_ENDPOINT_TEST_CHECKSUM)) in pci_endpoint_test_read()
685 static bool pci_endpoint_test_clear_irq(struct pci_endpoint_test *test) in pci_endpoint_test_clear_irq() argument
687 pci_endpoint_test_release_irq(test); in pci_endpoint_test_clear_irq()
688 pci_endpoint_test_free_irq_vectors(test); in pci_endpoint_test_clear_irq()
692 static bool pci_endpoint_test_set_irq(struct pci_endpoint_test *test, in pci_endpoint_test_set_irq() argument
695 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_set_irq()
703 if (test->irq_type == req_irq_type) in pci_endpoint_test_set_irq()
706 pci_endpoint_test_release_irq(test); in pci_endpoint_test_set_irq()
707 pci_endpoint_test_free_irq_vectors(test); in pci_endpoint_test_set_irq()
709 if (!pci_endpoint_test_alloc_irq_vectors(test, req_irq_type)) in pci_endpoint_test_set_irq()
712 if (!pci_endpoint_test_request_irq(test)) in pci_endpoint_test_set_irq()
718 pci_endpoint_test_free_irq_vectors(test); in pci_endpoint_test_set_irq()
727 struct pci_endpoint_test *test = to_endpoint_test(file->private_data); in pci_endpoint_test_ioctl() local
728 struct pci_dev *pdev = test->pdev; in pci_endpoint_test_ioctl()
730 mutex_lock(&test->mutex); in pci_endpoint_test_ioctl()
738 ret = pci_endpoint_test_bar(test, bar); in pci_endpoint_test_ioctl()
741 ret = pci_endpoint_test_legacy_irq(test); in pci_endpoint_test_ioctl()
745 ret = pci_endpoint_test_msi_irq(test, arg, cmd == PCITEST_MSIX); in pci_endpoint_test_ioctl()
748 ret = pci_endpoint_test_write(test, arg); in pci_endpoint_test_ioctl()
751 ret = pci_endpoint_test_read(test, arg); in pci_endpoint_test_ioctl()
754 ret = pci_endpoint_test_copy(test, arg); in pci_endpoint_test_ioctl()
757 ret = pci_endpoint_test_set_irq(test, arg); in pci_endpoint_test_ioctl()
763 ret = pci_endpoint_test_clear_irq(test); in pci_endpoint_test_ioctl()
768 mutex_unlock(&test->mutex); in pci_endpoint_test_ioctl()
786 struct pci_endpoint_test *test; in pci_endpoint_test_probe() local
794 test = devm_kzalloc(dev, sizeof(*test), GFP_KERNEL); in pci_endpoint_test_probe()
795 if (!test) in pci_endpoint_test_probe()
798 test->test_reg_bar = 0; in pci_endpoint_test_probe()
799 test->alignment = 0; in pci_endpoint_test_probe()
800 test->pdev = pdev; in pci_endpoint_test_probe()
801 test->irq_type = IRQ_TYPE_UNDEFINED; in pci_endpoint_test_probe()
809 test->test_reg_bar = test_reg_bar; in pci_endpoint_test_probe()
810 test->alignment = data->alignment; in pci_endpoint_test_probe()
814 init_completion(&test->irq_raised); in pci_endpoint_test_probe()
815 mutex_init(&test->mutex); in pci_endpoint_test_probe()
837 if (!pci_endpoint_test_alloc_irq_vectors(test, irq_type)) { in pci_endpoint_test_probe()
849 test->bar[bar] = base; in pci_endpoint_test_probe()
853 test->base = test->bar[test_reg_bar]; in pci_endpoint_test_probe()
854 if (!test->base) { in pci_endpoint_test_probe()
856 dev_err(dev, "Cannot perform PCI test without BAR%d\n", in pci_endpoint_test_probe()
861 pci_set_drvdata(pdev, test); in pci_endpoint_test_probe()
871 test->name = kstrdup(name, GFP_KERNEL); in pci_endpoint_test_probe()
872 if (!test->name) { in pci_endpoint_test_probe()
877 if (!pci_endpoint_test_request_irq(test)) { in pci_endpoint_test_probe()
882 misc_device = &test->miscdev; in pci_endpoint_test_probe()
904 pci_endpoint_test_release_irq(test); in pci_endpoint_test_probe()
907 kfree(test->name); in pci_endpoint_test_probe()
914 if (test->bar[bar]) in pci_endpoint_test_probe()
915 pci_iounmap(pdev, test->bar[bar]); in pci_endpoint_test_probe()
919 pci_endpoint_test_free_irq_vectors(test); in pci_endpoint_test_probe()
932 struct pci_endpoint_test *test = pci_get_drvdata(pdev); in pci_endpoint_test_remove() local
933 struct miscdevice *misc_device = &test->miscdev; in pci_endpoint_test_remove()
940 misc_deregister(&test->miscdev); in pci_endpoint_test_remove()
942 kfree(test->name); in pci_endpoint_test_remove()
945 if (test->bar[bar]) in pci_endpoint_test_remove()
946 pci_iounmap(pdev, test->bar[bar]); in pci_endpoint_test_remove()
949 pci_endpoint_test_release_irq(test); in pci_endpoint_test_remove()
950 pci_endpoint_test_free_irq_vectors(test); in pci_endpoint_test_remove()
1016 MODULE_DESCRIPTION("PCI ENDPOINT TEST HOST DRIVER");