Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include "roc_api.h"
6 : :
7 : : #include "cnxk_eventdev.h"
8 : : #include "cnxk_eventdev_dp.h"
9 : :
10 : : struct cnxk_sso_xstats_name {
11 : : const char name[RTE_EVENT_DEV_XSTATS_NAME_SIZE];
12 : : const size_t offset;
13 : : const uint64_t mask;
14 : : const uint8_t shift;
15 : : uint64_t reset_snap[CNXK_SSO_MAX_HWGRP];
16 : : };
17 : :
18 : : static struct cnxk_sso_xstats_name sso_hws_xstats[] = {
19 : : {
20 : : "last_grp_serviced",
21 : : offsetof(struct roc_sso_hws_stats, arbitration),
22 : : 0x3FF,
23 : : 0,
24 : : {0},
25 : : },
26 : : {
27 : : "affinity_arbitration_credits",
28 : : offsetof(struct roc_sso_hws_stats, arbitration),
29 : : 0xF,
30 : : 16,
31 : : {0},
32 : : },
33 : : };
34 : :
35 : : static struct cnxk_sso_xstats_name sso_hwgrp_xstats[] = {
36 : : {
37 : : "wrk_sched",
38 : : offsetof(struct roc_sso_hwgrp_stats, ws_pc),
39 : : ~0x0,
40 : : 0,
41 : : {0},
42 : : },
43 : : {
44 : : "xaq_dram",
45 : : offsetof(struct roc_sso_hwgrp_stats, ext_pc),
46 : : ~0x0,
47 : : 0,
48 : : {0},
49 : : },
50 : : {
51 : : "add_wrk",
52 : : offsetof(struct roc_sso_hwgrp_stats, wa_pc),
53 : : ~0x0,
54 : : 0,
55 : : {0},
56 : : },
57 : : {
58 : : "tag_switch_req",
59 : : offsetof(struct roc_sso_hwgrp_stats, ts_pc),
60 : : ~0x0,
61 : : 0,
62 : : {0},
63 : : },
64 : : {
65 : : "desched_req",
66 : : offsetof(struct roc_sso_hwgrp_stats, ds_pc),
67 : : ~0x0,
68 : : 0,
69 : : {0},
70 : : },
71 : : {
72 : : "desched_wrk",
73 : : offsetof(struct roc_sso_hwgrp_stats, dq_pc),
74 : : ~0x0,
75 : : 0,
76 : : {0},
77 : : },
78 : : {
79 : : "xaq_cached",
80 : : offsetof(struct roc_sso_hwgrp_stats, aw_status),
81 : : 0x3,
82 : : 0,
83 : : {0},
84 : : },
85 : : {
86 : : "work_inflight",
87 : : offsetof(struct roc_sso_hwgrp_stats, aw_status),
88 : : 0x3F,
89 : : 16,
90 : : {0},
91 : : },
92 : : {
93 : : "inuse_pages",
94 : : offsetof(struct roc_sso_hwgrp_stats, page_cnt),
95 : : 0xFFFFFFFF,
96 : : 0,
97 : : {0},
98 : : },
99 : : };
100 : :
101 : : #define CNXK_SSO_NUM_HWS_XSTATS RTE_DIM(sso_hws_xstats)
102 : : #define CNXK_SSO_NUM_GRP_XSTATS RTE_DIM(sso_hwgrp_xstats)
103 : :
104 : : #define CNXK_SSO_NUM_XSTATS (CNXK_SSO_NUM_HWS_XSTATS + CNXK_SSO_NUM_GRP_XSTATS)
105 : :
106 : : int
107 [ # # # # ]: 0 : cnxk_sso_xstats_get(const struct rte_eventdev *event_dev,
108 : : enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
109 : : const uint64_t ids[], uint64_t values[], unsigned int n)
110 : : {
111 : : struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
112 : : struct roc_sso_hwgrp_stats hwgrp_stats;
113 : : struct cnxk_sso_xstats_name *xstats;
114 : : struct cnxk_sso_xstats_name *xstat;
115 : : struct roc_sso_hws_stats hws_stats;
116 : : uint32_t xstats_mode_count = 0;
117 : : uint32_t start_offset = 0;
118 : : unsigned int i;
119 : : uint64_t value;
120 : : void *rsp;
121 : : int rc;
122 : :
123 [ # # # # ]: 0 : switch (mode) {
124 : : case RTE_EVENT_DEV_XSTATS_DEVICE:
125 : : return 0;
126 : 0 : case RTE_EVENT_DEV_XSTATS_PORT:
127 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_ports)
128 : 0 : goto invalid_value;
129 : :
130 : : xstats_mode_count = CNXK_SSO_NUM_HWS_XSTATS;
131 : : xstats = sso_hws_xstats;
132 : :
133 : 0 : rc = roc_sso_hws_stats_get(&dev->sso, queue_port_id,
134 : : &hws_stats);
135 [ # # ]: 0 : if (rc < 0)
136 : 0 : goto invalid_value;
137 : : rsp = &hws_stats;
138 : : break;
139 : 0 : case RTE_EVENT_DEV_XSTATS_QUEUE:
140 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_queues)
141 : 0 : goto invalid_value;
142 : :
143 : : xstats_mode_count = CNXK_SSO_NUM_GRP_XSTATS;
144 : : start_offset = CNXK_SSO_NUM_HWS_XSTATS;
145 : : xstats = sso_hwgrp_xstats;
146 : :
147 : 0 : rc = roc_sso_hwgrp_stats_get(&dev->sso, queue_port_id,
148 : : &hwgrp_stats);
149 [ # # ]: 0 : if (rc < 0)
150 : 0 : goto invalid_value;
151 : : rsp = &hwgrp_stats;
152 : :
153 : : break;
154 : 0 : default:
155 : 0 : plt_err("Invalid mode received");
156 : 0 : goto invalid_value;
157 : : };
158 : :
159 [ # # ]: 0 : for (i = 0; i < n && i < xstats_mode_count; i++) {
160 [ # # # # ]: 0 : if (ids[i] < start_offset || (ids[i] - start_offset) >= xstats_mode_count)
161 : 0 : goto invalid_value;
162 : 0 : xstat = &xstats[ids[i] - start_offset];
163 : 0 : value = *(uint64_t *)((char *)rsp + xstat->offset);
164 : 0 : value = (value >> xstat->shift) & xstat->mask;
165 : :
166 : 0 : values[i] = value;
167 : 0 : values[i] -= xstat->reset_snap[queue_port_id];
168 : : }
169 : :
170 : 0 : return i;
171 : : invalid_value:
172 : : return -EINVAL;
173 : : }
174 : :
175 : : int
176 [ # # # # ]: 0 : cnxk_sso_xstats_reset(struct rte_eventdev *event_dev,
177 : : enum rte_event_dev_xstats_mode mode,
178 : : int16_t queue_port_id, const uint64_t ids[], uint32_t n)
179 : : {
180 : : struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
181 : : struct roc_sso_hwgrp_stats hwgrp_stats;
182 : : struct cnxk_sso_xstats_name *xstats;
183 : : struct cnxk_sso_xstats_name *xstat;
184 : : struct roc_sso_hws_stats hws_stats;
185 : : uint32_t xstats_mode_count = 0;
186 : : int16_t first_id, last_id, id;
187 : : uint32_t start_offset = 0;
188 : : unsigned int i;
189 : : uint64_t value;
190 : : void *rsp;
191 : : int rc;
192 : :
193 [ # # # # ]: 0 : switch (mode) {
194 : : case RTE_EVENT_DEV_XSTATS_DEVICE:
195 : : return 0;
196 : 0 : case RTE_EVENT_DEV_XSTATS_PORT:
197 [ # # ]: 0 : if (queue_port_id >= (int16_t)dev->nb_event_ports)
198 : 0 : goto invalid_value;
199 : :
200 : : xstats_mode_count = CNXK_SSO_NUM_HWS_XSTATS;
201 : : xstats = sso_hws_xstats;
202 : : /* Negative id requests a reset of all ports. */
203 : 0 : first_id = (queue_port_id < 0) ? 0 : queue_port_id;
204 [ # # ]: 0 : last_id = (queue_port_id < 0) ? (int16_t)dev->nb_event_ports - 1 : queue_port_id;
205 : : break;
206 : 0 : case RTE_EVENT_DEV_XSTATS_QUEUE:
207 [ # # ]: 0 : if (queue_port_id >= (int16_t)dev->nb_event_queues)
208 : 0 : goto invalid_value;
209 : :
210 : : xstats_mode_count = CNXK_SSO_NUM_GRP_XSTATS;
211 : : start_offset = CNXK_SSO_NUM_HWS_XSTATS;
212 : : xstats = sso_hwgrp_xstats;
213 : : /* Negative id requests a reset of all queues. */
214 : 0 : first_id = (queue_port_id < 0) ? 0 : queue_port_id;
215 [ # # ]: 0 : last_id = (queue_port_id < 0) ? (int16_t)dev->nb_event_queues - 1 : queue_port_id;
216 : : break;
217 : 0 : default:
218 : 0 : plt_err("Invalid mode received");
219 : 0 : goto invalid_value;
220 : : };
221 : :
222 [ # # ]: 0 : for (id = first_id; id <= last_id; id++) {
223 [ # # ]: 0 : if (mode == RTE_EVENT_DEV_XSTATS_PORT) {
224 : 0 : rc = roc_sso_hws_stats_get(&dev->sso, id, &hws_stats);
225 [ # # ]: 0 : if (rc < 0)
226 : 0 : goto invalid_value;
227 : : rsp = &hws_stats;
228 : : } else {
229 : 0 : rc = roc_sso_hwgrp_stats_get(&dev->sso, id, &hwgrp_stats);
230 [ # # ]: 0 : if (rc < 0)
231 : 0 : goto invalid_value;
232 : : rsp = &hwgrp_stats;
233 : : }
234 : :
235 [ # # ]: 0 : if (ids == NULL) {
236 [ # # ]: 0 : for (i = 0; i < xstats_mode_count; i++) {
237 : 0 : xstat = &xstats[i];
238 : 0 : value = *(uint64_t *)((char *)rsp + xstat->offset);
239 : 0 : value = (value >> xstat->shift) & xstat->mask;
240 : :
241 : 0 : xstat->reset_snap[id] = value;
242 : : }
243 : 0 : continue;
244 : : }
245 : :
246 [ # # ]: 0 : for (i = 0; i < n; i++) {
247 [ # # # # ]: 0 : if (ids[i] < start_offset || (ids[i] - start_offset) >= xstats_mode_count)
248 : 0 : goto invalid_value;
249 : 0 : xstat = &xstats[ids[i] - start_offset];
250 : 0 : value = *(uint64_t *)((char *)rsp + xstat->offset);
251 : 0 : value = (value >> xstat->shift) & xstat->mask;
252 : :
253 : 0 : xstat->reset_snap[id] = value;
254 : : }
255 : : }
256 : :
257 : : return 0;
258 : : invalid_value:
259 : : return -EINVAL;
260 : : }
261 : :
262 : : int
263 : 0 : cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,
264 : : enum rte_event_dev_xstats_mode mode,
265 : : uint8_t queue_port_id,
266 : : struct rte_event_dev_xstats_name *xstats_names,
267 : : uint64_t *ids, unsigned int size)
268 : : {
269 : : struct rte_event_dev_xstats_name xstats_names_copy[CNXK_SSO_NUM_XSTATS];
270 : : struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
271 : : uint32_t xstats_mode_count = 0;
272 : : uint32_t start_offset = 0;
273 : : unsigned int xidx = 0;
274 : : unsigned int i;
275 : :
276 [ # # ]: 0 : for (i = 0; i < CNXK_SSO_NUM_HWS_XSTATS; i++) {
277 : 0 : snprintf(xstats_names_copy[i].name,
278 : : sizeof(xstats_names_copy[i].name), "%s",
279 : 0 : sso_hws_xstats[i].name);
280 : : }
281 : :
282 [ # # ]: 0 : for (; i < CNXK_SSO_NUM_XSTATS; i++) {
283 : 0 : snprintf(xstats_names_copy[i].name,
284 : : sizeof(xstats_names_copy[i].name), "%s",
285 : 0 : sso_hwgrp_xstats[i - CNXK_SSO_NUM_HWS_XSTATS].name);
286 : : }
287 : :
288 [ # # # # ]: 0 : switch (mode) {
289 : : case RTE_EVENT_DEV_XSTATS_DEVICE:
290 : : break;
291 : 0 : case RTE_EVENT_DEV_XSTATS_PORT:
292 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_ports)
293 : : break;
294 : : xstats_mode_count = CNXK_SSO_NUM_HWS_XSTATS;
295 : 0 : break;
296 : 0 : case RTE_EVENT_DEV_XSTATS_QUEUE:
297 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_queues)
298 : : break;
299 : : xstats_mode_count = CNXK_SSO_NUM_GRP_XSTATS;
300 : : start_offset = CNXK_SSO_NUM_HWS_XSTATS;
301 : 0 : break;
302 : 0 : default:
303 : 0 : plt_err("Invalid mode received");
304 : 0 : return -EINVAL;
305 : : };
306 : :
307 [ # # # # ]: 0 : if (xstats_mode_count > size || !ids || !xstats_names)
308 : 0 : return xstats_mode_count;
309 : :
310 [ # # ]: 0 : for (i = 0; i < xstats_mode_count; i++) {
311 : 0 : xidx = i + start_offset;
312 : 0 : strncpy(xstats_names[i].name, xstats_names_copy[xidx].name,
313 : : sizeof(xstats_names[i].name));
314 : 0 : ids[i] = xidx;
315 : : }
316 : :
317 : 0 : return i;
318 : : }
|