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