]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/pci/pcitest.c
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>
29 #include <linux/pcitest.h>
33 static char *result
[] = { "NOT OKAY", "OKAY" };
46 static int run_test(struct pci_test
*test
)
50 struct timespec start
, end
;
53 fd
= open(test
->device
, O_RDWR
);
55 perror("can't open PCI Endpoint Test device");
59 if (test
->barnum
>= 0 && test
->barnum
<= 5) {
60 ret
= ioctl(fd
, PCITEST_BAR
, test
->barnum
);
61 fprintf(stdout
, "BAR%d:\t\t", test
->barnum
);
63 fprintf(stdout
, "TEST FAILED\n");
65 fprintf(stdout
, "%s\n", result
[ret
]);
68 if (test
->legacyirq
) {
69 ret
= ioctl(fd
, PCITEST_LEGACY_IRQ
, 0);
70 fprintf(stdout
, "LEGACY IRQ:\t");
72 fprintf(stdout
, "TEST FAILED\n");
74 fprintf(stdout
, "%s\n", result
[ret
]);
77 if (test
->msinum
> 0 && test
->msinum
<= 32) {
78 ret
= ioctl(fd
, PCITEST_MSI
, test
->msinum
);
79 fprintf(stdout
, "MSI%d:\t\t", test
->msinum
);
81 fprintf(stdout
, "TEST FAILED\n");
83 fprintf(stdout
, "%s\n", result
[ret
]);
87 ret
= ioctl(fd
, PCITEST_WRITE
, test
->size
);
88 fprintf(stdout
, "WRITE (%7ld bytes):\t\t", test
->size
);
90 fprintf(stdout
, "TEST FAILED\n");
92 fprintf(stdout
, "%s\n", result
[ret
]);
96 ret
= ioctl(fd
, PCITEST_READ
, test
->size
);
97 fprintf(stdout
, "READ (%7ld bytes):\t\t", test
->size
);
99 fprintf(stdout
, "TEST FAILED\n");
101 fprintf(stdout
, "%s\n", result
[ret
]);
105 ret
= ioctl(fd
, PCITEST_COPY
, test
->size
);
106 fprintf(stdout
, "COPY (%7ld bytes):\t\t", test
->size
);
108 fprintf(stdout
, "TEST FAILED\n");
110 fprintf(stdout
, "%s\n", result
[ret
]);
116 int main(int argc
, char **argv
)
119 struct pci_test
*test
;
121 test
= calloc(1, sizeof(*test
));
123 perror("Fail to allocate memory for pci_test\n");
127 /* since '0' is a valid BAR number, initialize it to -1 */
130 /* set default size as 100KB */
131 test
->size
= 0x19000;
133 /* set default endpoint device */
134 test
->device
= "/dev/pci-endpoint-test.0";
136 while ((c
= getopt(argc
, argv
, "D:b:m:lrwcs:")) != EOF
)
139 test
->device
= optarg
;
142 test
->barnum
= atoi(optarg
);
143 if (test
->barnum
< 0 || test
->barnum
> 5)
147 test
->legacyirq
= true;
150 test
->msinum
= atoi(optarg
);
151 if (test
->msinum
< 1 || test
->msinum
> 32)
164 test
->size
= strtoul(optarg
, NULL
, 0);
171 "usage: %s [options]\n"
173 "\t-D <dev> PCI endpoint test device {default: /dev/pci-endpoint-test.0}\n"
174 "\t-b <bar num> BAR test (bar number between 0..5)\n"
175 "\t-m <msi num> MSI test (msi number between 1..32)\n"
176 "\t-l Legacy IRQ test\n"
177 "\t-r Read buffer test\n"
178 "\t-w Write buffer test\n"
179 "\t-c Copy buffer test\n"
180 "\t-s <size> Size of buffer {default: 100KB}\n",