hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/tools/pci/pcitest.c
....@@ -1,20 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * Userspace PCI Endpoint Test Module
34 *
45 * Copyright (C) 2017 Texas Instruments
56 * Author: Kishon Vijay Abraham I <kishon@ti.com>
6
- *
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.
10
- *
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.
15
- *
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/>.
187 */
198
209 #include <errno.h>
....@@ -41,14 +30,17 @@
4130 int irqtype;
4231 bool set_irqtype;
4332 bool get_irqtype;
33
+ bool clear_irq;
4434 bool read;
4535 bool write;
4636 bool copy;
4737 unsigned long size;
38
+ bool use_dma;
4839 };
4940
5041 static int run_test(struct pci_test *test)
5142 {
43
+ struct pci_endpoint_test_xfer_param param;
5244 int ret = -EINVAL;
5345 int fd;
5446
....@@ -85,6 +77,15 @@
8577 fprintf(stdout, "%s\n", irq[ret]);
8678 }
8779
80
+ if (test->clear_irq) {
81
+ ret = ioctl(fd, PCITEST_CLEAR_IRQ);
82
+ fprintf(stdout, "CLEAR IRQ:\t\t");
83
+ if (ret < 0)
84
+ fprintf(stdout, "FAILED\n");
85
+ else
86
+ fprintf(stdout, "%s\n", result[ret]);
87
+ }
88
+
8889 if (test->legacyirq) {
8990 ret = ioctl(fd, PCITEST_LEGACY_IRQ, 0);
9091 fprintf(stdout, "LEGACY IRQ:\t");
....@@ -113,7 +114,10 @@
113114 }
114115
115116 if (test->write) {
116
- ret = ioctl(fd, PCITEST_WRITE, test->size);
117
+ param.size = test->size;
118
+ if (test->use_dma)
119
+ param.flags = PCITEST_FLAGS_USE_DMA;
120
+ ret = ioctl(fd, PCITEST_WRITE, &param);
117121 fprintf(stdout, "WRITE (%7ld bytes):\t\t", test->size);
118122 if (ret < 0)
119123 fprintf(stdout, "TEST FAILED\n");
....@@ -122,7 +126,10 @@
122126 }
123127
124128 if (test->read) {
125
- ret = ioctl(fd, PCITEST_READ, test->size);
129
+ param.size = test->size;
130
+ if (test->use_dma)
131
+ param.flags = PCITEST_FLAGS_USE_DMA;
132
+ ret = ioctl(fd, PCITEST_READ, &param);
126133 fprintf(stdout, "READ (%7ld bytes):\t\t", test->size);
127134 if (ret < 0)
128135 fprintf(stdout, "TEST FAILED\n");
....@@ -131,7 +138,10 @@
131138 }
132139
133140 if (test->copy) {
134
- ret = ioctl(fd, PCITEST_COPY, test->size);
141
+ param.size = test->size;
142
+ if (test->use_dma)
143
+ param.flags = PCITEST_FLAGS_USE_DMA;
144
+ ret = ioctl(fd, PCITEST_COPY, &param);
135145 fprintf(stdout, "COPY (%7ld bytes):\t\t", test->size);
136146 if (ret < 0)
137147 fprintf(stdout, "TEST FAILED\n");
....@@ -140,6 +150,8 @@
140150 }
141151
142152 fflush(stdout);
153
+ close(fd);
154
+ return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */
143155 }
144156
145157 int main(int argc, char **argv)
....@@ -162,7 +174,7 @@
162174 /* set default endpoint device */
163175 test->device = "/dev/pci-endpoint-test.0";
164176
165
- while ((c = getopt(argc, argv, "D:b:m:x:i:Ilrwcs:")) != EOF)
177
+ while ((c = getopt(argc, argv, "D:b:m:x:i:deIlhrwcs:")) != EOF)
166178 switch (c) {
167179 case 'D':
168180 test->device = optarg;
....@@ -203,10 +215,15 @@
203215 case 'c':
204216 test->copy = true;
205217 continue;
218
+ case 'e':
219
+ test->clear_irq = true;
220
+ continue;
206221 case 's':
207222 test->size = strtoul(optarg, NULL, 0);
208223 continue;
209
- case '?':
224
+ case 'd':
225
+ test->use_dma = true;
226
+ continue;
210227 case 'h':
211228 default:
212229 usage:
....@@ -218,16 +235,18 @@
218235 "\t-m <msi num> MSI test (msi number between 1..32)\n"
219236 "\t-x <msix num> \tMSI-X test (msix number between 1..2048)\n"
220237 "\t-i <irq type> \tSet IRQ type (0 - Legacy, 1 - MSI, 2 - MSI-X)\n"
238
+ "\t-e Clear IRQ\n"
221239 "\t-I Get current IRQ type configured\n"
240
+ "\t-d Use DMA\n"
222241 "\t-l Legacy IRQ test\n"
223242 "\t-r Read buffer test\n"
224243 "\t-w Write buffer test\n"
225244 "\t-c Copy buffer test\n"
226
- "\t-s <size> Size of buffer {default: 100KB}\n",
245
+ "\t-s <size> Size of buffer {default: 100KB}\n"
246
+ "\t-h Print this help message\n",
227247 argv[0]);
228248 return -EINVAL;
229249 }
230250
231
- run_test(test);
232
- return 0;
251
+ return run_test(test);
233252 }