2 * Userspace PCI Endpoint Test Module
4 * Copyright (C) 2017 Texas Instruments
5 * Author: Kishon Vijay Abraham I <kishon@ti.com>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 of
9 * the License as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/ioctl.h>
28 #include <linux/pcitest.h>
32 static char *result[] = { "NOT OKAY", "OKAY" };
45 static int run_test(struct pci_test *test)
50 fd = open(test->device, O_RDWR);
52 perror("can't open PCI Endpoint Test device");
56 if (test->barnum >= 0 && test->barnum <= 5) {
57 ret = ioctl(fd, PCITEST_BAR, test->barnum);
58 fprintf(stdout, "BAR%d:\t\t", test->barnum);
60 fprintf(stdout, "TEST FAILED\n");
62 fprintf(stdout, "%s\n", result[ret]);
65 if (test->legacyirq) {
66 ret = ioctl(fd, PCITEST_LEGACY_IRQ, 0);
67 fprintf(stdout, "LEGACY IRQ:\t");
69 fprintf(stdout, "TEST FAILED\n");
71 fprintf(stdout, "%s\n", result[ret]);
74 if (test->msinum > 0 && test->msinum <= 32) {
75 ret = ioctl(fd, PCITEST_MSI, test->msinum);
76 fprintf(stdout, "MSI%d:\t\t", test->msinum);
78 fprintf(stdout, "TEST FAILED\n");
80 fprintf(stdout, "%s\n", result[ret]);
84 ret = ioctl(fd, PCITEST_WRITE, test->size);
85 fprintf(stdout, "WRITE (%7ld bytes):\t\t", test->size);
87 fprintf(stdout, "TEST FAILED\n");
89 fprintf(stdout, "%s\n", result[ret]);
93 ret = ioctl(fd, PCITEST_READ, test->size);
94 fprintf(stdout, "READ (%7ld bytes):\t\t", test->size);
96 fprintf(stdout, "TEST FAILED\n");
98 fprintf(stdout, "%s\n", result[ret]);
102 ret = ioctl(fd, PCITEST_COPY, test->size);
103 fprintf(stdout, "COPY (%7ld bytes):\t\t", test->size);
105 fprintf(stdout, "TEST FAILED\n");
107 fprintf(stdout, "%s\n", result[ret]);
113 int main(int argc, char **argv)
116 struct pci_test *test;
118 test = calloc(1, sizeof(*test));
120 perror("Fail to allocate memory for pci_test\n");
124 /* since '0' is a valid BAR number, initialize it to -1 */
127 /* set default size as 100KB */
128 test->size = 0x19000;
130 /* set default endpoint device */
131 test->device = "/dev/pci-endpoint-test.0";
133 while ((c = getopt(argc, argv, "D:b:m:lrwcs:")) != EOF)
136 test->device = optarg;
139 test->barnum = atoi(optarg);
140 if (test->barnum < 0 || test->barnum > 5)
144 test->legacyirq = true;
147 test->msinum = atoi(optarg);
148 if (test->msinum < 1 || test->msinum > 32)
161 test->size = strtoul(optarg, NULL, 0);
168 "usage: %s [options]\n"
170 "\t-D <dev> PCI endpoint test device {default: /dev/pci-endpoint-test.0}\n"
171 "\t-b <bar num> BAR test (bar number between 0..5)\n"
172 "\t-m <msi num> MSI test (msi number between 1..32)\n"
173 "\t-l Legacy IRQ test\n"
174 "\t-r Read buffer test\n"
175 "\t-w Write buffer test\n"
176 "\t-c Copy buffer test\n"
177 "\t-s <size> Size of buffer {default: 100KB}\n",