.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * Userspace PCI Endpoint Test Module |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2017 Texas Instruments |
---|
5 | 6 | * 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/>. |
---|
18 | 7 | */ |
---|
19 | 8 | |
---|
20 | 9 | #include <errno.h> |
---|
.. | .. |
---|
41 | 30 | int irqtype; |
---|
42 | 31 | bool set_irqtype; |
---|
43 | 32 | bool get_irqtype; |
---|
| 33 | + bool clear_irq; |
---|
44 | 34 | bool read; |
---|
45 | 35 | bool write; |
---|
46 | 36 | bool copy; |
---|
47 | 37 | unsigned long size; |
---|
| 38 | + bool use_dma; |
---|
48 | 39 | }; |
---|
49 | 40 | |
---|
50 | 41 | static int run_test(struct pci_test *test) |
---|
51 | 42 | { |
---|
| 43 | + struct pci_endpoint_test_xfer_param param; |
---|
52 | 44 | int ret = -EINVAL; |
---|
53 | 45 | int fd; |
---|
54 | 46 | |
---|
.. | .. |
---|
85 | 77 | fprintf(stdout, "%s\n", irq[ret]); |
---|
86 | 78 | } |
---|
87 | 79 | |
---|
| 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 | + |
---|
88 | 89 | if (test->legacyirq) { |
---|
89 | 90 | ret = ioctl(fd, PCITEST_LEGACY_IRQ, 0); |
---|
90 | 91 | fprintf(stdout, "LEGACY IRQ:\t"); |
---|
.. | .. |
---|
113 | 114 | } |
---|
114 | 115 | |
---|
115 | 116 | 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, ¶m); |
---|
117 | 121 | fprintf(stdout, "WRITE (%7ld bytes):\t\t", test->size); |
---|
118 | 122 | if (ret < 0) |
---|
119 | 123 | fprintf(stdout, "TEST FAILED\n"); |
---|
.. | .. |
---|
122 | 126 | } |
---|
123 | 127 | |
---|
124 | 128 | 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, ¶m); |
---|
126 | 133 | fprintf(stdout, "READ (%7ld bytes):\t\t", test->size); |
---|
127 | 134 | if (ret < 0) |
---|
128 | 135 | fprintf(stdout, "TEST FAILED\n"); |
---|
.. | .. |
---|
131 | 138 | } |
---|
132 | 139 | |
---|
133 | 140 | 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, ¶m); |
---|
135 | 145 | fprintf(stdout, "COPY (%7ld bytes):\t\t", test->size); |
---|
136 | 146 | if (ret < 0) |
---|
137 | 147 | fprintf(stdout, "TEST FAILED\n"); |
---|
.. | .. |
---|
140 | 150 | } |
---|
141 | 151 | |
---|
142 | 152 | fflush(stdout); |
---|
| 153 | + close(fd); |
---|
| 154 | + return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ |
---|
143 | 155 | } |
---|
144 | 156 | |
---|
145 | 157 | int main(int argc, char **argv) |
---|
.. | .. |
---|
162 | 174 | /* set default endpoint device */ |
---|
163 | 175 | test->device = "/dev/pci-endpoint-test.0"; |
---|
164 | 176 | |
---|
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) |
---|
166 | 178 | switch (c) { |
---|
167 | 179 | case 'D': |
---|
168 | 180 | test->device = optarg; |
---|
.. | .. |
---|
203 | 215 | case 'c': |
---|
204 | 216 | test->copy = true; |
---|
205 | 217 | continue; |
---|
| 218 | + case 'e': |
---|
| 219 | + test->clear_irq = true; |
---|
| 220 | + continue; |
---|
206 | 221 | case 's': |
---|
207 | 222 | test->size = strtoul(optarg, NULL, 0); |
---|
208 | 223 | continue; |
---|
209 | | - case '?': |
---|
| 224 | + case 'd': |
---|
| 225 | + test->use_dma = true; |
---|
| 226 | + continue; |
---|
210 | 227 | case 'h': |
---|
211 | 228 | default: |
---|
212 | 229 | usage: |
---|
.. | .. |
---|
218 | 235 | "\t-m <msi num> MSI test (msi number between 1..32)\n" |
---|
219 | 236 | "\t-x <msix num> \tMSI-X test (msix number between 1..2048)\n" |
---|
220 | 237 | "\t-i <irq type> \tSet IRQ type (0 - Legacy, 1 - MSI, 2 - MSI-X)\n" |
---|
| 238 | + "\t-e Clear IRQ\n" |
---|
221 | 239 | "\t-I Get current IRQ type configured\n" |
---|
| 240 | + "\t-d Use DMA\n" |
---|
222 | 241 | "\t-l Legacy IRQ test\n" |
---|
223 | 242 | "\t-r Read buffer test\n" |
---|
224 | 243 | "\t-w Write buffer test\n" |
---|
225 | 244 | "\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", |
---|
227 | 247 | argv[0]); |
---|
228 | 248 | return -EINVAL; |
---|
229 | 249 | } |
---|
230 | 250 | |
---|
231 | | - run_test(test); |
---|
232 | | - return 0; |
---|
| 251 | + return run_test(test); |
---|
233 | 252 | } |
---|