New upstream version 18.02
[deb_dpdk.git] / drivers / event / opdl / opdl_evdev_xstats.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include "opdl_evdev.h"
6 #include "opdl_log.h"
7
8 static const char * const port_xstat_str[] = {
9
10         "claim_pkts_requested",
11         "claim_pkts_granted",
12         "claim_non_empty",
13         "claim_empty",
14         "total_cycles",
15 };
16
17
18 void
19 opdl_xstats_init(struct rte_eventdev *dev)
20 {
21         uint32_t i, j;
22
23         struct opdl_evdev *device = opdl_pmd_priv(dev);
24
25         if (!device->do_validation)
26                 return;
27
28         for (i = 0; i < device->max_port_nb; i++) {
29                 struct opdl_port *port = &device->ports[i];
30
31                 for (j = 0; j < max_num_port_xstat; j++) {
32                         uint32_t index = (i * max_num_port_xstat) + j;
33
34                         /* Name */
35                         sprintf(device->port_xstat[index].stat.name,
36                                "port_%02u_%s",
37                                i,
38                                port_xstat_str[j]);
39
40                         /* ID */
41                         device->port_xstat[index].id = index;
42
43                         /* Stats ptr */
44                         device->port_xstat[index].value = &port->port_stat[j];
45                 }
46         }
47 }
48
49 int
50 opdl_xstats_uninit(struct rte_eventdev *dev)
51 {
52         struct opdl_evdev *device = opdl_pmd_priv(dev);
53
54         if (!device->do_validation)
55                 return 0;
56
57         memset(device->port_xstat,
58                0,
59                sizeof(device->port_xstat));
60
61         return 0;
62 }
63
64 int
65 opdl_xstats_get_names(const struct rte_eventdev *dev,
66                 enum rte_event_dev_xstats_mode mode,
67                 uint8_t queue_port_id,
68                 struct rte_event_dev_xstats_name *xstats_names,
69                 unsigned int *ids, unsigned int size)
70 {
71         struct opdl_evdev *device = opdl_pmd_priv(dev);
72
73         if (!device->do_validation)
74                 return -ENOTSUP;
75
76         if (mode == RTE_EVENT_DEV_XSTATS_DEVICE ||
77                         mode == RTE_EVENT_DEV_XSTATS_QUEUE)
78                 return -EINVAL;
79
80         if (queue_port_id >= device->max_port_nb)
81                 return -EINVAL;
82
83         if (size < max_num_port_xstat)
84                 return max_num_port_xstat;
85
86         uint32_t port_idx = queue_port_id * max_num_port_xstat;
87
88         uint32_t j;
89         for (j = 0; j < max_num_port_xstat; j++) {
90
91                 strcpy(xstats_names[j].name,
92                                 device->port_xstat[j + port_idx].stat.name);
93                 ids[j] = device->port_xstat[j + port_idx].id;
94         }
95
96         return max_num_port_xstat;
97 }
98
99 int
100 opdl_xstats_get(const struct rte_eventdev *dev,
101                 enum rte_event_dev_xstats_mode mode,
102                 uint8_t queue_port_id,
103                 const unsigned int ids[],
104                 uint64_t values[], unsigned int n)
105 {
106         struct opdl_evdev *device = opdl_pmd_priv(dev);
107
108         if (!device->do_validation)
109                 return -ENOTSUP;
110
111         if (mode == RTE_EVENT_DEV_XSTATS_DEVICE ||
112                         mode == RTE_EVENT_DEV_XSTATS_QUEUE)
113                 return -EINVAL;
114
115         if (queue_port_id >= device->max_port_nb)
116                 return -EINVAL;
117
118         if (n > max_num_port_xstat)
119                 return -EINVAL;
120
121         uint32_t p_start = queue_port_id * max_num_port_xstat;
122         uint32_t p_finish = p_start + max_num_port_xstat;
123
124         uint32_t i;
125         for (i = 0; i < n; i++) {
126                 if (ids[i] < p_start || ids[i] >= p_finish)
127                         return -EINVAL;
128
129                 values[i] = *(device->port_xstat[ids[i]].value);
130         }
131
132         return n;
133 }
134
135 uint64_t
136 opdl_xstats_get_by_name(const struct rte_eventdev *dev,
137                 const char *name, unsigned int *id)
138 {
139         struct opdl_evdev *device = opdl_pmd_priv(dev);
140
141         if (!device->do_validation)
142                 return -ENOTSUP;
143
144         uint32_t max_index = device->max_port_nb * max_num_port_xstat;
145
146         uint32_t i;
147         for (i = 0; i < max_index; i++) {
148
149                 if (strncmp(name,
150                            device->port_xstat[i].stat.name,
151                            RTE_EVENT_DEV_XSTATS_NAME_SIZE) == 0) {
152                         if (id != NULL)
153                                 *id = i;
154                         if (device->port_xstat[i].value)
155                                 return *(device->port_xstat[i].value);
156                         break;
157                 }
158         }
159         return -EINVAL;
160 }
161
162 int
163 opdl_xstats_reset(struct rte_eventdev *dev,
164                 enum rte_event_dev_xstats_mode mode,
165                 int16_t queue_port_id, const uint32_t ids[],
166                 uint32_t nb_ids)
167 {
168         struct opdl_evdev *device = opdl_pmd_priv(dev);
169
170         if (!device->do_validation)
171                 return -ENOTSUP;
172
173         RTE_SET_USED(dev);
174         RTE_SET_USED(mode);
175         RTE_SET_USED(queue_port_id);
176         RTE_SET_USED(ids);
177         RTE_SET_USED(nb_ids);
178
179         return -ENOTSUP;
180 }