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 : xstat = &xstats[ids[i] - start_offset];
161 : 0 : value = *(uint64_t *)((char *)rsp + xstat->offset);
162 : 0 : value = (value >> xstat->shift) & xstat->mask;
163 : :
164 : 0 : values[i] = value;
165 : 0 : values[i] -= xstat->reset_snap[queue_port_id];
166 : : }
167 : :
168 : 0 : return i;
169 : : invalid_value:
170 : : return -EINVAL;
171 : : }
172 : :
173 : : int
174 [ # # # # ]: 0 : cnxk_sso_xstats_reset(struct rte_eventdev *event_dev,
175 : : enum rte_event_dev_xstats_mode mode,
176 : : int16_t queue_port_id, const uint64_t ids[], uint32_t n)
177 : : {
178 : : struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
179 : : struct roc_sso_hwgrp_stats hwgrp_stats;
180 : : struct cnxk_sso_xstats_name *xstats;
181 : : struct cnxk_sso_xstats_name *xstat;
182 : : struct roc_sso_hws_stats hws_stats;
183 : : uint32_t xstats_mode_count = 0;
184 : : uint32_t start_offset = 0;
185 : : unsigned int i;
186 : : uint64_t value;
187 : : void *rsp;
188 : : int rc;
189 : :
190 [ # # # # ]: 0 : switch (mode) {
191 : : case RTE_EVENT_DEV_XSTATS_DEVICE:
192 : : return 0;
193 : 0 : case RTE_EVENT_DEV_XSTATS_PORT:
194 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_ports)
195 : 0 : goto invalid_value;
196 : :
197 : : xstats_mode_count = CNXK_SSO_NUM_HWS_XSTATS;
198 : : xstats = sso_hws_xstats;
199 : 0 : rc = roc_sso_hws_stats_get(&dev->sso, queue_port_id,
200 : : &hws_stats);
201 [ # # ]: 0 : if (rc < 0)
202 : 0 : goto invalid_value;
203 : : rsp = &hws_stats;
204 : : break;
205 : 0 : case RTE_EVENT_DEV_XSTATS_QUEUE:
206 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_queues)
207 : 0 : goto invalid_value;
208 : :
209 : : xstats_mode_count = CNXK_SSO_NUM_GRP_XSTATS;
210 : : start_offset = CNXK_SSO_NUM_HWS_XSTATS;
211 : : xstats = sso_hwgrp_xstats;
212 : :
213 : 0 : rc = roc_sso_hwgrp_stats_get(&dev->sso, queue_port_id,
214 : : &hwgrp_stats);
215 [ # # ]: 0 : if (rc < 0)
216 : 0 : goto invalid_value;
217 : : rsp = &hwgrp_stats;
218 : : break;
219 : 0 : default:
220 : 0 : plt_err("Invalid mode received");
221 : 0 : goto invalid_value;
222 : : };
223 : :
224 [ # # ]: 0 : for (i = 0; i < n && i < xstats_mode_count; i++) {
225 : 0 : xstat = &xstats[ids[i] - start_offset];
226 : 0 : value = *(uint64_t *)((char *)rsp + xstat->offset);
227 : 0 : value = (value >> xstat->shift) & xstat->mask;
228 : :
229 : 0 : xstat->reset_snap[queue_port_id] = value;
230 : : }
231 : 0 : return i;
232 : : invalid_value:
233 : : return -EINVAL;
234 : : }
235 : :
236 : : int
237 : 0 : cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,
238 : : enum rte_event_dev_xstats_mode mode,
239 : : uint8_t queue_port_id,
240 : : struct rte_event_dev_xstats_name *xstats_names,
241 : : uint64_t *ids, unsigned int size)
242 : : {
243 : : struct rte_event_dev_xstats_name xstats_names_copy[CNXK_SSO_NUM_XSTATS];
244 : : struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
245 : : uint32_t xstats_mode_count = 0;
246 : : uint32_t start_offset = 0;
247 : : unsigned int xidx = 0;
248 : : unsigned int i;
249 : :
250 [ # # ]: 0 : for (i = 0; i < CNXK_SSO_NUM_HWS_XSTATS; i++) {
251 : 0 : snprintf(xstats_names_copy[i].name,
252 : : sizeof(xstats_names_copy[i].name), "%s",
253 : 0 : sso_hws_xstats[i].name);
254 : : }
255 : :
256 [ # # ]: 0 : for (; i < CNXK_SSO_NUM_XSTATS; i++) {
257 : 0 : snprintf(xstats_names_copy[i].name,
258 : : sizeof(xstats_names_copy[i].name), "%s",
259 : 0 : sso_hwgrp_xstats[i - CNXK_SSO_NUM_HWS_XSTATS].name);
260 : : }
261 : :
262 [ # # # # ]: 0 : switch (mode) {
263 : : case RTE_EVENT_DEV_XSTATS_DEVICE:
264 : : break;
265 : 0 : case RTE_EVENT_DEV_XSTATS_PORT:
266 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_ports)
267 : : break;
268 : : xstats_mode_count = CNXK_SSO_NUM_HWS_XSTATS;
269 : 0 : break;
270 : 0 : case RTE_EVENT_DEV_XSTATS_QUEUE:
271 [ # # ]: 0 : if (queue_port_id >= (signed int)dev->nb_event_queues)
272 : : break;
273 : : xstats_mode_count = CNXK_SSO_NUM_GRP_XSTATS;
274 : : start_offset = CNXK_SSO_NUM_HWS_XSTATS;
275 : 0 : break;
276 : 0 : default:
277 : 0 : plt_err("Invalid mode received");
278 : 0 : return -EINVAL;
279 : : };
280 : :
281 [ # # # # ]: 0 : if (xstats_mode_count > size || !ids || !xstats_names)
282 : 0 : return xstats_mode_count;
283 : :
284 [ # # ]: 0 : for (i = 0; i < xstats_mode_count; i++) {
285 : 0 : xidx = i + start_offset;
286 : 0 : strncpy(xstats_names[i].name, xstats_names_copy[xidx].name,
287 : : sizeof(xstats_names[i].name));
288 : 0 : ids[i] = xidx;
289 : : }
290 : :
291 : 0 : return i;
292 : : }
|