test: use SPDX tags in 6WIND copyrighted files
[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         uint32_t j;
90         for (j = 0; j < max_num_port_xstat; j++) {
91
92                 strcpy(xstats_names[j].name,
93                                 device->port_xstat[j + port_idx].stat.name);
94                 ids[j] = device->port_xstat[j + port_idx].id;
95         }
96
97         return max_num_port_xstat;
98 }
99
100 int
101 opdl_xstats_get(const struct rte_eventdev *dev,
102                 enum rte_event_dev_xstats_mode mode,
103                 uint8_t queue_port_id,
104                 const unsigned int ids[],
105                 uint64_t values[], unsigned int n)
106 {
107         struct opdl_evdev *device = opdl_pmd_priv(dev);
108
109         if (!device->do_validation)
110                 return -ENOTSUP;
111
112         if (mode == RTE_EVENT_DEV_XSTATS_DEVICE ||
113                         mode == RTE_EVENT_DEV_XSTATS_QUEUE)
114                 return -EINVAL;
115
116         if (queue_port_id >= device->max_port_nb)
117                 return -EINVAL;
118
119         if (n > max_num_port_xstat)
120                 return -EINVAL;
121
122         uint32_t p_start = queue_port_id * max_num_port_xstat;
123         uint32_t p_finish = p_start + max_num_port_xstat;
124
125         uint32_t i;
126         for (i = 0; i < n; i++) {
127                 if (ids[i] < p_start || ids[i] >= p_finish)
128                         return -EINVAL;
129
130                 values[i] = *(device->port_xstat[ids[i]].value);
131         }
132
133         return n;
134 }
135
136 uint64_t
137 opdl_xstats_get_by_name(const struct rte_eventdev *dev,
138                 const char *name, unsigned int *id)
139 {
140         struct opdl_evdev *device = opdl_pmd_priv(dev);
141
142         if (!device->do_validation)
143                 return -ENOTSUP;
144
145         uint32_t max_index = device->max_port_nb * max_num_port_xstat;
146
147         uint32_t i;
148         for (i = 0; i < max_index; i++) {
149
150                 if (strncmp(name,
151                            device->port_xstat[i].stat.name,
152                            RTE_EVENT_DEV_XSTATS_NAME_SIZE) == 0) {
153                         if (id != NULL)
154                                 *id = i;
155                         if (device->port_xstat[i].value)
156                                 return *(device->port_xstat[i].value);
157                         break;
158                 }
159         }
160         return -EINVAL;
161 }
162
163 int
164 opdl_xstats_reset(struct rte_eventdev *dev,
165                 enum rte_event_dev_xstats_mode mode,
166                 int16_t queue_port_id, const uint32_t ids[],
167                 uint32_t nb_ids)
168 {
169         struct opdl_evdev *device = opdl_pmd_priv(dev);
170
171         if (!device->do_validation)
172                 return -ENOTSUP;
173
174         RTE_SET_USED(dev);
175         RTE_SET_USED(mode);
176         RTE_SET_USED(queue_port_id);
177         RTE_SET_USED(ids);
178         RTE_SET_USED(nb_ids);
179
180         return -ENOTSUP;
181 }