ab671816deeb3979145507b21db08ff186e96ce1
[dpdk.git] / drivers / raw / ioat / ioat_rawdev_test.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <inttypes.h>
6 #include "rte_rawdev.h"
7 #include "rte_ioat_rawdev.h"
8
9 int ioat_rawdev_test(uint16_t dev_id); /* pre-define to keep compiler happy */
10
11 int
12 ioat_rawdev_test(uint16_t dev_id)
13 {
14 #define IOAT_TEST_RINGSIZE 512
15         struct rte_ioat_rawdev_config p = { .ring_size = -1 };
16         struct rte_rawdev_info info = { .dev_private = &p };
17         struct rte_rawdev_xstats_name *snames = NULL;
18         uint64_t *stats = NULL;
19         unsigned int *ids = NULL;
20         unsigned int nb_xstats;
21         unsigned int i;
22
23         rte_rawdev_info_get(dev_id, &info);
24         if (p.ring_size != 0) {
25                 printf("Error, initial ring size is non-zero (%d)\n",
26                                 (int)p.ring_size);
27                 return -1;
28         }
29
30         p.ring_size = IOAT_TEST_RINGSIZE;
31         if (rte_rawdev_configure(dev_id, &info) != 0) {
32                 printf("Error with rte_rawdev_configure()\n");
33                 return -1;
34         }
35         rte_rawdev_info_get(dev_id, &info);
36         if (p.ring_size != IOAT_TEST_RINGSIZE) {
37                 printf("Error, ring size is not %d (%d)\n",
38                                 IOAT_TEST_RINGSIZE, (int)p.ring_size);
39                 return -1;
40         }
41
42         if (rte_rawdev_start(dev_id) != 0) {
43                 printf("Error with rte_rawdev_start()\n");
44                 return -1;
45         }
46
47         /* allocate memory for xstats names and values */
48         nb_xstats = rte_rawdev_xstats_names_get(dev_id, NULL, 0);
49
50         snames = malloc(sizeof(*snames) * nb_xstats);
51         if (snames == NULL) {
52                 printf("Error allocating xstat names memory\n");
53                 goto err;
54         }
55         rte_rawdev_xstats_names_get(dev_id, snames, nb_xstats);
56
57         ids = malloc(sizeof(*ids) * nb_xstats);
58         if (ids == NULL) {
59                 printf("Error allocating xstat ids memory\n");
60                 goto err;
61         }
62         for (i = 0; i < nb_xstats; i++)
63                 ids[i] = i;
64
65         stats = malloc(sizeof(*stats) * nb_xstats);
66         if (stats == NULL) {
67                 printf("Error allocating xstat memory\n");
68                 goto err;
69         }
70
71         rte_rawdev_xstats_get(dev_id, ids, stats, nb_xstats);
72         for (i = 0; i < nb_xstats; i++)
73                 printf("%s: %"PRIu64"   ", snames[i].name, stats[i]);
74         printf("\n");
75
76         free(snames);
77         free(stats);
78         free(ids);
79         return 0;
80
81 err:
82         free(snames);
83         free(stats);
84         free(ids);
85         return -1;
86 }