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