Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2015 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <inttypes.h>
7 : : #include <stdint.h>
8 : : #include <stdio.h>
9 : : #include <unistd.h>
10 : :
11 : : #include <ethdev_driver.h>
12 : : #include <rte_common.h>
13 : : #include <rte_malloc.h>
14 : :
15 : : #include <mlx5_common.h>
16 : :
17 : : #include "mlx5_defs.h"
18 : : #include "mlx5.h"
19 : : #include "mlx5_rx.h"
20 : : #include "mlx5_tx.h"
21 : : #include "mlx5_malloc.h"
22 : :
23 : :
24 : : static const struct mlx5_xstats_name_off mlx5_rxq_stats_strings[] = {
25 : : {"out_of_buffer", offsetof(struct mlx5_rq_stats, q_oobs)},
26 : : };
27 : :
28 : : #define NB_RXQ_STATS RTE_DIM(mlx5_rxq_stats_strings)
29 : :
30 : : /**
31 : : * Retrieve extended device statistics
32 : : * for Rx queues. It appends the specific statistics
33 : : * before the parts filled by preceding modules (eth stats, etc.)
34 : : *
35 : : * @param dev
36 : : * Pointer to Ethernet device.
37 : : * @param[out] stats
38 : : * Pointer to an array to store the retrieved statistics.
39 : : * @return
40 : : * Number of extended stats is filled,
41 : : * negative on error and rte_errno is set.
42 : : */
43 : : static int
44 : 0 : mlx5_rq_xstats_get(struct rte_eth_dev *dev,
45 : : struct rte_eth_xstat *stats)
46 : : {
47 : 0 : uint16_t n_stats_rq = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
48 : : int cnt_used_entries = 0;
49 : :
50 [ # # ]: 0 : for (unsigned int idx = 0; idx < n_stats_rq; idx++) {
51 : 0 : struct mlx5_rxq_data *rxq_data = mlx5_rxq_data_get(dev, idx);
52 : 0 : struct mlx5_rxq_priv *rxq_priv = mlx5_rxq_get(dev, idx);
53 : :
54 [ # # ]: 0 : if (rxq_data == NULL)
55 : 0 : continue;
56 : :
57 : : struct mlx5_rxq_stat *rxq_stat = &rxq_data->stats.oobs;
58 : : if (rxq_stat == NULL)
59 : : continue;
60 : :
61 : : /* Handle initial stats setup - Flag uninitialized stat */
62 : 0 : rxq_stat->id = -1;
63 : :
64 : : /* Handle hairpin statistics */
65 [ # # # # ]: 0 : if (rxq_priv && rxq_priv->ctrl->is_hairpin) {
66 [ # # ]: 0 : if (stats) {
67 : 0 : mlx5_read_queue_counter(rxq_priv->q_counter, "hairpin_out_of_buffer",
68 : : &rxq_stat->count);
69 : :
70 : 0 : stats[cnt_used_entries].id = cnt_used_entries;
71 : 0 : stats[cnt_used_entries].value = rxq_stat->count -
72 : 0 : rxq_data->stats_reset.oobs.count;
73 : : }
74 : 0 : rxq_stat->ctrl.enable = mlx5_enable_per_queue_hairpin_counter;
75 : 0 : rxq_stat->ctrl.disable = mlx5_disable_per_queue_hairpin_counter;
76 : 0 : rxq_stat->id = cnt_used_entries;
77 : 0 : cnt_used_entries++;
78 : : }
79 : : }
80 : 0 : return cnt_used_entries;
81 : : }
82 : :
83 : : /**
84 : : * Retrieve names of extended device statistics
85 : : * for Rx queues. It appends the specific stats names
86 : : * before the parts filled by preceding modules (eth stats, etc.)
87 : : *
88 : : * @param dev
89 : : * Pointer to Ethernet device structure.
90 : : * @param[out] xstats_names
91 : : * Buffer to insert names into.
92 : : *
93 : : * @return
94 : : * Number of xstats names.
95 : : */
96 : : static int
97 : 0 : mlx5_rq_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
98 : : struct rte_eth_xstat_name *xstats_names)
99 : : {
100 : : struct mlx5_rxq_priv *rxq;
101 : : unsigned int i;
102 : : int cnt_used_entries = 0;
103 : :
104 : 0 : uint16_t n_stats_rq = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
105 : :
106 [ # # ]: 0 : for (i = 0; (i != n_stats_rq); ++i) {
107 : 0 : rxq = mlx5_rxq_get(dev, i);
108 : :
109 [ # # ]: 0 : if (rxq == NULL)
110 : 0 : continue;
111 : :
112 [ # # ]: 0 : if (rxq->ctrl->is_hairpin) {
113 [ # # ]: 0 : if (xstats_names)
114 : 0 : snprintf(xstats_names[cnt_used_entries].name,
115 : : sizeof(xstats_names[0].name),
116 : : "hairpin_%s_rxq%u",
117 : : mlx5_rxq_stats_strings[0].name, i);
118 : 0 : cnt_used_entries++;
119 : : }
120 : : }
121 : 0 : return cnt_used_entries;
122 : : }
123 : :
124 : : /**
125 : : * DPDK callback to get extended device statistics.
126 : : *
127 : : * @param dev
128 : : * Pointer to Ethernet device.
129 : : * @param[out] stats
130 : : * Pointer to rte extended stats table.
131 : : * @param n
132 : : * The size of the stats table.
133 : : *
134 : : * @return
135 : : * Number of extended stats on success and stats is filled,
136 : : * negative on error and rte_errno is set.
137 : : */
138 : : int
139 : 0 : mlx5_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *stats,
140 : : unsigned int n)
141 : : {
142 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
143 : : uint64_t counters[MLX5_MAX_XSTATS];
144 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
145 : : unsigned int i;
146 : 0 : uint16_t stats_n = 0;
147 : 0 : uint16_t stats_n_2nd = 0;
148 : 0 : uint16_t mlx5_stats_n = xstats_ctrl->mlx5_stats_n;
149 [ # # # # ]: 0 : bool bond_master = (priv->master && priv->pf_bond >= 0);
150 : 0 : int n_used = mlx5_rq_xstats_get(dev, stats);
151 : :
152 [ # # # # ]: 0 : if (n >= mlx5_stats_n && stats) {
153 : : int ret;
154 : :
155 : 0 : ret = mlx5_os_get_stats_n(dev, bond_master, &stats_n, &stats_n_2nd);
156 [ # # ]: 0 : if (ret < 0)
157 : : return ret;
158 : : /*
159 : : * The number of statistics fetched via "ETH_SS_STATS" may vary because
160 : : * of the port configuration each time. This is also true between 2
161 : : * ports. There might be a case that the numbers are the same even if
162 : : * configurations are different.
163 : : * It is not recommended to change the configuration without using
164 : : * RTE API. The port(traffic) restart may trigger another initialization
165 : : * to make sure the map are correct.
166 : : */
167 [ # # # # ]: 0 : if (xstats_ctrl->stats_n != stats_n ||
168 [ # # ]: 0 : (bond_master && xstats_ctrl->stats_n_2nd != stats_n_2nd))
169 : 0 : mlx5_os_stats_init(dev);
170 : 0 : ret = mlx5_os_read_dev_counters(dev, bond_master, counters);
171 [ # # ]: 0 : if (ret < 0)
172 : : return ret;
173 [ # # ]: 0 : for (i = 0; i != mlx5_stats_n; i++) {
174 : 0 : stats[i + n_used].id = i + n_used;
175 [ # # ]: 0 : if (xstats_ctrl->info[i].dev) {
176 : : uint64_t wrap_n;
177 : 0 : uint64_t hw_stat = xstats_ctrl->hw_stats[i];
178 : :
179 : 0 : stats[i + n_used].value = (counters[i] -
180 : 0 : xstats_ctrl->base[i]) &
181 : : (uint64_t)UINT32_MAX;
182 : 0 : wrap_n = hw_stat >> 32;
183 : 0 : if (stats[i + n_used].value <
184 [ # # ]: 0 : (hw_stat & (uint64_t)UINT32_MAX))
185 : 0 : wrap_n++;
186 : 0 : stats[i + n_used].value |= (wrap_n) << 32;
187 : 0 : xstats_ctrl->hw_stats[i] = stats[i + n_used].value;
188 : : } else {
189 : 0 : stats[i + n_used].value =
190 : 0 : (counters[i] - xstats_ctrl->base[i]);
191 : : }
192 : : }
193 : : }
194 : 0 : mlx5_stats_n = mlx5_txpp_xstats_get(dev, stats, n, mlx5_stats_n + n_used);
195 : 0 : return mlx5_stats_n;
196 : : }
197 : :
198 : : /**
199 : : * DPDK callback to get device statistics.
200 : : *
201 : : * @param dev
202 : : * Pointer to Ethernet device structure.
203 : : * @param[out] stats
204 : : * Stats structure output buffer.
205 : : *
206 : : * @return
207 : : * 0 on success and stats is filled, negative errno value otherwise and
208 : : * rte_errno is set.
209 : : */
210 : : int
211 : 0 : mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
212 : : struct eth_queue_stats *qstats)
213 : : {
214 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
215 : : struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
216 : : struct rte_eth_stats tmp;
217 : : unsigned int i;
218 : : unsigned int idx;
219 : : uint64_t wrap_n;
220 : : int ret;
221 : :
222 : : memset(&tmp, 0, sizeof(tmp));
223 : : /* Add software counters. */
224 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i) {
225 : 0 : struct mlx5_rxq_data *rxq = mlx5_rxq_data_get(dev, i);
226 : :
227 [ # # ]: 0 : if (rxq == NULL)
228 : 0 : continue;
229 : 0 : idx = rxq->idx;
230 [ # # ]: 0 : if (qstats != NULL && idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
231 : : #ifdef MLX5_PMD_SOFT_COUNTERS
232 : 0 : qstats->q_ipackets[idx] += rxq->stats.ipackets -
233 : 0 : rxq->stats_reset.ipackets;
234 : 0 : qstats->q_ibytes[idx] += rxq->stats.ibytes -
235 : 0 : rxq->stats_reset.ibytes;
236 : : #endif
237 : 0 : qstats->q_errors[idx] += (rxq->stats.idropped +
238 : 0 : rxq->stats.rx_nombuf) -
239 : 0 : (rxq->stats_reset.idropped +
240 : 0 : rxq->stats_reset.rx_nombuf);
241 : : }
242 : : #ifdef MLX5_PMD_SOFT_COUNTERS
243 : 0 : tmp.ipackets += rxq->stats.ipackets - rxq->stats_reset.ipackets;
244 : 0 : tmp.ibytes += rxq->stats.ibytes - rxq->stats_reset.ibytes;
245 : : #endif
246 : 0 : tmp.ierrors += rxq->stats.idropped - rxq->stats_reset.idropped;
247 : 0 : tmp.rx_nombuf += rxq->stats.rx_nombuf -
248 : 0 : rxq->stats_reset.rx_nombuf;
249 : : }
250 [ # # ]: 0 : for (i = 0; (i != priv->txqs_n); ++i) {
251 : 0 : struct mlx5_txq_data *txq = (*priv->txqs)[i];
252 : :
253 [ # # ]: 0 : if (txq == NULL)
254 : 0 : continue;
255 : 0 : idx = txq->idx;
256 [ # # ]: 0 : if (qstats != NULL && idx < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
257 : : #ifdef MLX5_PMD_SOFT_COUNTERS
258 : 0 : qstats->q_opackets[idx] += txq->stats.opackets -
259 : 0 : txq->stats_reset.opackets;
260 : 0 : qstats->q_obytes[idx] += txq->stats.obytes -
261 : 0 : txq->stats_reset.obytes;
262 : : #endif
263 : : }
264 : : #ifdef MLX5_PMD_SOFT_COUNTERS
265 : 0 : tmp.opackets += txq->stats.opackets - txq->stats_reset.opackets;
266 : 0 : tmp.obytes += txq->stats.obytes - txq->stats_reset.obytes;
267 : : #endif
268 : 0 : tmp.oerrors += txq->stats.oerrors - txq->stats_reset.oerrors;
269 : : }
270 : 0 : ret = mlx5_os_read_dev_stat(priv, "out_of_buffer", &tmp.imissed);
271 [ # # ]: 0 : if (ret == 0) {
272 : 0 : tmp.imissed = (tmp.imissed - stats_ctrl->imissed_base) &
273 : : (uint64_t)UINT32_MAX;
274 : 0 : wrap_n = stats_ctrl->imissed >> 32;
275 [ # # ]: 0 : if (tmp.imissed < (stats_ctrl->imissed & (uint64_t)UINT32_MAX))
276 : 0 : wrap_n++;
277 : 0 : tmp.imissed |= (wrap_n) << 32;
278 : 0 : stats_ctrl->imissed = tmp.imissed;
279 : : } else {
280 : 0 : tmp.imissed = stats_ctrl->imissed;
281 : : }
282 : : #ifndef MLX5_PMD_SOFT_COUNTERS
283 : : /* FIXME: retrieve and add hardware counters. */
284 : : #endif
285 : 0 : *stats = tmp;
286 : 0 : return 0;
287 : : }
288 : :
289 : : /**
290 : : * DPDK callback to clear device statistics.
291 : : *
292 : : * @param dev
293 : : * Pointer to Ethernet device structure.
294 : : *
295 : : * @return
296 : : * always 0 on success and stats is reset
297 : : */
298 : : int
299 : 0 : mlx5_stats_reset(struct rte_eth_dev *dev)
300 : : {
301 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
302 : : struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl;
303 : : unsigned int i;
304 : :
305 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i) {
306 : 0 : struct mlx5_rxq_data *rxq_data = mlx5_rxq_data_get(dev, i);
307 : :
308 [ # # ]: 0 : if (rxq_data == NULL)
309 : 0 : continue;
310 : 0 : rxq_data->stats_reset = rxq_data->stats;
311 : : }
312 [ # # ]: 0 : for (i = 0; (i != priv->txqs_n); ++i) {
313 : 0 : struct mlx5_txq_data *txq_data = (*priv->txqs)[i];
314 : :
315 [ # # ]: 0 : if (txq_data == NULL)
316 : 0 : continue;
317 : 0 : txq_data->stats_reset = txq_data->stats;
318 : : }
319 : 0 : mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base);
320 : 0 : stats_ctrl->imissed = 0;
321 : : #ifndef MLX5_PMD_SOFT_COUNTERS
322 : : /* FIXME: reset hardware counters. */
323 : : #endif
324 : :
325 : 0 : return 0;
326 : : }
327 : :
328 : : /**
329 : : * DPDK callback to clear device extended statistics.
330 : : *
331 : : * @param dev
332 : : * Pointer to Ethernet device structure.
333 : : *
334 : : * @return
335 : : * 0 on success and stats is reset, negative errno value otherwise and
336 : : * rte_errno is set.
337 : : */
338 : : int
339 : 0 : mlx5_xstats_reset(struct rte_eth_dev *dev)
340 : : {
341 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
342 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
343 : : unsigned int i;
344 : : uint64_t *counters;
345 : : int ret;
346 : 0 : uint16_t stats_n = 0;
347 : 0 : uint16_t stats_n_2nd = 0;
348 [ # # # # ]: 0 : bool bond_master = (priv->master && priv->pf_bond >= 0);
349 : :
350 : 0 : ret = mlx5_os_get_stats_n(dev, bond_master, &stats_n, &stats_n_2nd);
351 [ # # ]: 0 : if (ret < 0) {
352 : 0 : DRV_LOG(ERR, "port %u cannot get stats: %s", dev->data->port_id,
353 : : strerror(-ret));
354 : 0 : return ret;
355 : : }
356 [ # # # # ]: 0 : if (xstats_ctrl->stats_n != stats_n ||
357 [ # # ]: 0 : (bond_master && xstats_ctrl->stats_n_2nd != stats_n_2nd))
358 : 0 : mlx5_os_stats_init(dev);
359 : : /* Considering to use stack directly. */
360 : 0 : counters = mlx5_malloc(MLX5_MEM_SYS, sizeof(*counters) * xstats_ctrl->mlx5_stats_n,
361 : : 0, SOCKET_ID_ANY);
362 [ # # ]: 0 : if (!counters) {
363 : 0 : DRV_LOG(WARNING, "port %u unable to allocate memory for xstats counters",
364 : : dev->data->port_id);
365 : 0 : rte_errno = ENOMEM;
366 : 0 : return -rte_errno;
367 : : }
368 : 0 : ret = mlx5_os_read_dev_counters(dev, bond_master, counters);
369 [ # # ]: 0 : if (ret) {
370 : 0 : DRV_LOG(ERR, "port %u cannot read device counters: %s",
371 : : dev->data->port_id, strerror(rte_errno));
372 : 0 : mlx5_free(counters);
373 : 0 : return ret;
374 : : }
375 [ # # ]: 0 : for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) {
376 : 0 : xstats_ctrl->base[i] = counters[i];
377 : 0 : xstats_ctrl->hw_stats[i] = 0;
378 : : }
379 : 0 : mlx5_reset_xstats_rq(dev);
380 : 0 : mlx5_txpp_xstats_reset(dev);
381 : 0 : mlx5_free(counters);
382 : 0 : return 0;
383 : : }
384 : :
385 : : void
386 : 0 : mlx5_reset_xstats_by_name(struct mlx5_priv *priv, const char *ctr_name)
387 : : {
388 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
389 : 0 : unsigned int mlx5_xstats_n = xstats_ctrl->mlx5_stats_n;
390 : : unsigned int i;
391 : :
392 [ # # ]: 0 : for (i = 0; i != mlx5_xstats_n; ++i) {
393 [ # # ]: 0 : if (strcmp(xstats_ctrl->info[i].ctr_name, ctr_name) == 0) {
394 : 0 : xstats_ctrl->base[i] = 0;
395 : 0 : xstats_ctrl->hw_stats[i] = 0;
396 : 0 : xstats_ctrl->xstats[i] = 0;
397 : 0 : return;
398 : : }
399 : : }
400 : : }
401 : :
402 : : /**
403 : : * Clear device extended statistics for each Rx queue.
404 : : *
405 : : * @param dev
406 : : * Pointer to Ethernet device structure.
407 : : */
408 : : void
409 : 0 : mlx5_reset_xstats_rq(struct rte_eth_dev *dev)
410 : : {
411 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
412 : : struct mlx5_rxq_priv *rxq;
413 : : struct mlx5_rxq_data *rxq_data;
414 : : unsigned int i;
415 : :
416 [ # # ]: 0 : for (i = 0; (i != priv->rxqs_n); ++i) {
417 : 0 : rxq = mlx5_rxq_get(dev, i);
418 : 0 : rxq_data = mlx5_rxq_data_get(dev, i);
419 : :
420 [ # # # # ]: 0 : if (rxq == NULL || rxq_data == NULL || rxq->q_counter == NULL)
421 : 0 : continue;
422 [ # # ]: 0 : if (rxq->ctrl->is_hairpin)
423 : 0 : mlx5_read_queue_counter(rxq->q_counter,
424 : : "hairpin_out_of_buffer", &rxq_data->stats_reset.oobs.count);
425 : : else
426 : 0 : mlx5_read_queue_counter(rxq->q_counter,
427 : : "out_of_buffer", &rxq_data->stats_reset.oobs.count);
428 : : }
429 : 0 : }
430 : :
431 : : /**
432 : : * DPDK callback to retrieve names of extended device statistics
433 : : *
434 : : * @param dev
435 : : * Pointer to Ethernet device structure.
436 : : * @param[out] xstats_names
437 : : * Buffer to insert names into.
438 : : * @param n
439 : : * Number of names.
440 : : *
441 : : * @return
442 : : * Number of xstats names.
443 : : */
444 : : int
445 : 0 : mlx5_xstats_get_names(struct rte_eth_dev *dev,
446 : : struct rte_eth_xstat_name *xstats_names, unsigned int n)
447 : : {
448 : : unsigned int i;
449 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
450 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
451 : 0 : unsigned int mlx5_xstats_n = xstats_ctrl->mlx5_stats_n;
452 : 0 : unsigned int n_used = mlx5_rq_xstats_get_names(dev, xstats_names);
453 : :
454 [ # # ]: 0 : if (n >= mlx5_xstats_n && xstats_names) {
455 [ # # ]: 0 : for (i = 0; i != mlx5_xstats_n; ++i) {
456 : 0 : rte_strscpy(xstats_names[i + n_used].name,
457 : 0 : xstats_ctrl->info[i].dpdk_name,
458 : : RTE_ETH_XSTATS_NAME_SIZE);
459 : 0 : xstats_names[i + n_used].name[RTE_ETH_XSTATS_NAME_SIZE - 1] = 0;
460 : : }
461 : : }
462 : 0 : mlx5_xstats_n = mlx5_txpp_xstats_get_names(dev, xstats_names,
463 : : n, mlx5_xstats_n + n_used);
464 : 0 : return mlx5_xstats_n;
465 : : }
466 : :
467 : : static struct mlx5_stat_counter_ctrl*
468 : 0 : mlx5_rxq_get_counter_by_id(struct rte_eth_dev *dev, uint64_t id, uint64_t *rq_id)
469 : : {
470 : 0 : uint16_t n_stats_rq = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
471 : :
472 [ # # ]: 0 : for (int i = 0; (i != n_stats_rq); i++) {
473 : 0 : struct mlx5_rxq_data *rxq_data = mlx5_rxq_data_get(dev, i);
474 [ # # # # ]: 0 : if (rxq_data == NULL || rxq_data->stats.oobs.id == -1)
475 : 0 : continue;
476 : :
477 [ # # ]: 0 : if ((uint64_t)rxq_data->stats.oobs.id == id) {
478 : 0 : *rq_id = rxq_data->idx;
479 : 0 : return &rxq_data->stats.oobs.ctrl;
480 : : }
481 : : }
482 : :
483 : : return NULL;
484 : : }
485 : :
486 : : /**
487 : : * Callback to enable an xstat counter of the given id.
488 : : *
489 : : * @param dev
490 : : * Pointer to Ethernet device structure.
491 : : * @param id
492 : : * The ID of the counter to enable
493 : : *
494 : : * @return
495 : : * 1 xstat is enabled, 0 if xstat is disabled,
496 : : * -ENOTSUP if enabling/disabling is not implemented and -EINVAL if xstat id is invalid.
497 : : */
498 : : int
499 : 0 : mlx5_xstats_enable(struct rte_eth_dev *dev, uint64_t id)
500 : : {
501 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
502 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
503 : : struct mlx5_stat_counter_ctrl *counter_ctrl = NULL;
504 : 0 : uint16_t n_stats_rq = mlx5_rq_xstats_get(dev, NULL);
505 : :
506 [ # # ]: 0 : if (id < n_stats_rq)
507 : 0 : counter_ctrl = mlx5_rxq_get_counter_by_id(dev, id, &id);
508 : : else
509 : 0 : counter_ctrl = &xstats_ctrl->info[id - n_stats_rq].ctrl;
510 : :
511 [ # # ]: 0 : if (counter_ctrl == NULL)
512 : : return -EINVAL;
513 : :
514 [ # # ]: 0 : if (counter_ctrl->enable == NULL)
515 : : return -ENOTSUP;
516 : :
517 : 0 : counter_ctrl->enabled = counter_ctrl->enable(dev, id) == 0 ? 1 : 0;
518 : 0 : return counter_ctrl->enabled;
519 : : }
520 : :
521 : : /**
522 : : * Callback to disable an xstat counter of the given id.
523 : : *
524 : : * @param dev
525 : : * Pointer to Ethernet device structure.
526 : : * @param id
527 : : * The ID of the counter to enable
528 : : *
529 : : * @return
530 : : * 1 if xstat is disabled, 0 xstat is enabled,
531 : : * -ENOTSUP if enabling/disabling is not implemented and -EINVAL if xstat id is invalid.
532 : : */
533 : : int
534 : 0 : mlx5_xstats_disable(struct rte_eth_dev *dev, uint64_t id)
535 : : {
536 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
537 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
538 : : struct mlx5_stat_counter_ctrl *counter_ctrl = NULL;
539 : :
540 : 0 : uint16_t n_stats_rq = mlx5_rq_xstats_get(dev, NULL);
541 [ # # ]: 0 : if (id < n_stats_rq)
542 : 0 : counter_ctrl = mlx5_rxq_get_counter_by_id(dev, id, &id);
543 : : else
544 : 0 : counter_ctrl = &xstats_ctrl->info[id - n_stats_rq].ctrl;
545 : :
546 [ # # ]: 0 : if (counter_ctrl == NULL)
547 : : return -EINVAL;
548 : :
549 [ # # ]: 0 : if (counter_ctrl->disable == NULL)
550 : : return -ENOTSUP;
551 : :
552 : 0 : counter_ctrl->enabled = counter_ctrl->disable(dev, id) == 0 ? 0 : 1;
553 : 0 : return counter_ctrl->enabled;
554 : : }
555 : :
556 : : /**
557 : : * Query the state of the xstat counter.
558 : : *
559 : : * @param dev
560 : : * Pointer to Ethernet device structure.
561 : : * @param id
562 : : * The ID of the counter to enable
563 : : *
564 : : * @return
565 : : * 1 if xstat is disabled, 0 xstat is enabled,
566 : : * -ENOTSUP if enabling/disabling is not implemented and -EINVAL if xstat id is invalid.
567 : : */
568 : : int
569 : 0 : mlx5_xstats_query_state(struct rte_eth_dev *dev, uint64_t id)
570 : : {
571 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
572 : : struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl;
573 : : struct mlx5_stat_counter_ctrl *counter_ctrl = NULL;
574 : :
575 : 0 : uint16_t n_stats_rq = mlx5_rq_xstats_get(dev, NULL);
576 [ # # ]: 0 : if (id < n_stats_rq)
577 : 0 : counter_ctrl = mlx5_rxq_get_counter_by_id(dev, id, &id);
578 : : else
579 : 0 : counter_ctrl = &xstats_ctrl->info[id - n_stats_rq].ctrl;
580 : :
581 [ # # ]: 0 : if (counter_ctrl == NULL)
582 : : return -EINVAL;
583 : :
584 [ # # ]: 0 : if (counter_ctrl->disable == NULL)
585 : : return -ENOTSUP;
586 : :
587 : 0 : return counter_ctrl->enabled;
588 : : }
|