Skip to content

Commit 73c5762

Browse files
kishonLorenzo Pieralisi
authored andcommitted
tools: PCI: Add 'd' command line option to support DMA
Add a new command line option 'd' to use DMA for data transfers. It should be used with read, write or copy commands. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Tested-by: Alan Mikhak <[email protected]>
1 parent 0a121f9 commit 73c5762

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

include/uapi/linux/pcitest.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,11 @@
2020
#define PCITEST_SET_IRQTYPE _IOW('P', 0x8, int)
2121
#define PCITEST_GET_IRQTYPE _IO('P', 0x9)
2222

23+
#define PCITEST_FLAGS_USE_DMA 0x00000001
24+
25+
struct pci_endpoint_test_xfer_param {
26+
unsigned long size;
27+
unsigned char flags;
28+
};
29+
2330
#endif /* __UAPI_LINUX_PCITEST_H */

tools/pci/pcitest.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ struct pci_test {
3434
bool write;
3535
bool copy;
3636
unsigned long size;
37+
bool use_dma;
3738
};
3839

3940
static int run_test(struct pci_test *test)
4041
{
42+
struct pci_endpoint_test_xfer_param param;
4143
int ret = -EINVAL;
4244
int fd;
4345

@@ -102,7 +104,10 @@ static int run_test(struct pci_test *test)
102104
}
103105

104106
if (test->write) {
105-
ret = ioctl(fd, PCITEST_WRITE, test->size);
107+
param.size = test->size;
108+
if (test->use_dma)
109+
param.flags = PCITEST_FLAGS_USE_DMA;
110+
ret = ioctl(fd, PCITEST_WRITE, &param);
106111
fprintf(stdout, "WRITE (%7ld bytes):\t\t", test->size);
107112
if (ret < 0)
108113
fprintf(stdout, "TEST FAILED\n");
@@ -111,7 +116,10 @@ static int run_test(struct pci_test *test)
111116
}
112117

113118
if (test->read) {
114-
ret = ioctl(fd, PCITEST_READ, test->size);
119+
param.size = test->size;
120+
if (test->use_dma)
121+
param.flags = PCITEST_FLAGS_USE_DMA;
122+
ret = ioctl(fd, PCITEST_READ, &param);
115123
fprintf(stdout, "READ (%7ld bytes):\t\t", test->size);
116124
if (ret < 0)
117125
fprintf(stdout, "TEST FAILED\n");
@@ -120,7 +128,10 @@ static int run_test(struct pci_test *test)
120128
}
121129

122130
if (test->copy) {
123-
ret = ioctl(fd, PCITEST_COPY, test->size);
131+
param.size = test->size;
132+
if (test->use_dma)
133+
param.flags = PCITEST_FLAGS_USE_DMA;
134+
ret = ioctl(fd, PCITEST_COPY, &param);
124135
fprintf(stdout, "COPY (%7ld bytes):\t\t", test->size);
125136
if (ret < 0)
126137
fprintf(stdout, "TEST FAILED\n");
@@ -153,7 +164,7 @@ int main(int argc, char **argv)
153164
/* set default endpoint device */
154165
test->device = "/dev/pci-endpoint-test.0";
155166

156-
while ((c = getopt(argc, argv, "D:b:m:x:i:Ilhrwcs:")) != EOF)
167+
while ((c = getopt(argc, argv, "D:b:m:x:i:dIlhrwcs:")) != EOF)
157168
switch (c) {
158169
case 'D':
159170
test->device = optarg;
@@ -197,6 +208,9 @@ int main(int argc, char **argv)
197208
case 's':
198209
test->size = strtoul(optarg, NULL, 0);
199210
continue;
211+
case 'd':
212+
test->use_dma = true;
213+
continue;
200214
case 'h':
201215
default:
202216
usage:
@@ -209,6 +223,7 @@ int main(int argc, char **argv)
209223
"\t-x <msix num> \tMSI-X test (msix number between 1..2048)\n"
210224
"\t-i <irq type> \tSet IRQ type (0 - Legacy, 1 - MSI, 2 - MSI-X)\n"
211225
"\t-I Get current IRQ type configured\n"
226+
"\t-d Use DMA\n"
212227
"\t-l Legacy IRQ test\n"
213228
"\t-r Read buffer test\n"
214229
"\t-w Write buffer test\n"

0 commit comments

Comments
 (0)