]> Git Repo - linux.git/blob - drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
x86/MCE/AMD: Fix the thresholding machinery initialization order
[linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_stats.c
1 /*
2  * Copyright (c) 2017, Mellanox Technologies, Ltd.  All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * OpenIB.org BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32
33 #include "en.h"
34 #include "en_accel/ipsec.h"
35 #include "en_accel/tls.h"
36
37 static const struct counter_desc sw_stats_desc[] = {
38         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
39         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
40         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
41         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
42         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_packets) },
43         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_bytes) },
44         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_packets) },
45         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_bytes) },
46         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_added_vlan_packets) },
47         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_nop) },
48
49 #ifdef CONFIG_MLX5_EN_TLS
50         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ooo) },
51         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_resync_bytes) },
52 #endif
53
54         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) },
55         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_bytes) },
56         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_ecn_mark) },
57         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_removed_vlan_packets) },
58         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary) },
59         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
60         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_complete) },
61         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary_inner) },
62         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_drop) },
63         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_redirect) },
64         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_xmit) },
65         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_full) },
66         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_err) },
67         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_cqe) },
68         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_none) },
69         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial) },
70         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial_inner) },
71         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
72         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
73         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xmit_more) },
74         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_recover) },
75         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_cqes) },
76         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
77         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_udp_seg_rem) },
78         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_cqe_err) },
79         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_xmit) },
80         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_full) },
81         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_err) },
82         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_cqes) },
83         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
84         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler_cqes) },
85         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler_strides) },
86         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
87         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_blks) },
88         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_pkts) },
89         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_page_reuse) },
90         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_reuse) },
91         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_full) },
92         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_empty) },
93         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_busy) },
94         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_waive) },
95         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_congst_umr) },
96         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_arfs_err) },
97         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_events) },
98         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_poll) },
99         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_arm) },
100         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_aff_change) },
101         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_eq_rearm) },
102 };
103
104 #define NUM_SW_COUNTERS                 ARRAY_SIZE(sw_stats_desc)
105
106 static int mlx5e_grp_sw_get_num_stats(struct mlx5e_priv *priv)
107 {
108         return NUM_SW_COUNTERS;
109 }
110
111 static int mlx5e_grp_sw_fill_strings(struct mlx5e_priv *priv, u8 *data, int idx)
112 {
113         int i;
114
115         for (i = 0; i < NUM_SW_COUNTERS; i++)
116                 strcpy(data + (idx++) * ETH_GSTRING_LEN, sw_stats_desc[i].format);
117         return idx;
118 }
119
120 static int mlx5e_grp_sw_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
121 {
122         int i;
123
124         for (i = 0; i < NUM_SW_COUNTERS; i++)
125                 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.sw, sw_stats_desc, i);
126         return idx;
127 }
128
129 void mlx5e_grp_sw_update_stats(struct mlx5e_priv *priv)
130 {
131         struct mlx5e_sw_stats temp, *s = &temp;
132         int i;
133
134         memset(s, 0, sizeof(*s));
135
136         for (i = 0; i < mlx5e_get_netdev_max_channels(priv->netdev); i++) {
137                 struct mlx5e_channel_stats *channel_stats =
138                         &priv->channel_stats[i];
139                 struct mlx5e_xdpsq_stats *xdpsq_red_stats = &channel_stats->xdpsq;
140                 struct mlx5e_xdpsq_stats *xdpsq_stats = &channel_stats->rq_xdpsq;
141                 struct mlx5e_rq_stats *rq_stats = &channel_stats->rq;
142                 struct mlx5e_ch_stats *ch_stats = &channel_stats->ch;
143                 int j;
144
145                 s->rx_packets   += rq_stats->packets;
146                 s->rx_bytes     += rq_stats->bytes;
147                 s->rx_lro_packets += rq_stats->lro_packets;
148                 s->rx_lro_bytes += rq_stats->lro_bytes;
149                 s->rx_ecn_mark  += rq_stats->ecn_mark;
150                 s->rx_removed_vlan_packets += rq_stats->removed_vlan_packets;
151                 s->rx_csum_none += rq_stats->csum_none;
152                 s->rx_csum_complete += rq_stats->csum_complete;
153                 s->rx_csum_unnecessary += rq_stats->csum_unnecessary;
154                 s->rx_csum_unnecessary_inner += rq_stats->csum_unnecessary_inner;
155                 s->rx_xdp_drop     += rq_stats->xdp_drop;
156                 s->rx_xdp_redirect += rq_stats->xdp_redirect;
157                 s->rx_xdp_tx_xmit  += xdpsq_stats->xmit;
158                 s->rx_xdp_tx_full  += xdpsq_stats->full;
159                 s->rx_xdp_tx_err   += xdpsq_stats->err;
160                 s->rx_xdp_tx_cqe   += xdpsq_stats->cqes;
161                 s->rx_wqe_err   += rq_stats->wqe_err;
162                 s->rx_mpwqe_filler_cqes    += rq_stats->mpwqe_filler_cqes;
163                 s->rx_mpwqe_filler_strides += rq_stats->mpwqe_filler_strides;
164                 s->rx_buff_alloc_err += rq_stats->buff_alloc_err;
165                 s->rx_cqe_compress_blks += rq_stats->cqe_compress_blks;
166                 s->rx_cqe_compress_pkts += rq_stats->cqe_compress_pkts;
167                 s->rx_page_reuse  += rq_stats->page_reuse;
168                 s->rx_cache_reuse += rq_stats->cache_reuse;
169                 s->rx_cache_full  += rq_stats->cache_full;
170                 s->rx_cache_empty += rq_stats->cache_empty;
171                 s->rx_cache_busy  += rq_stats->cache_busy;
172                 s->rx_cache_waive += rq_stats->cache_waive;
173                 s->rx_congst_umr  += rq_stats->congst_umr;
174                 s->rx_arfs_err    += rq_stats->arfs_err;
175                 s->ch_events      += ch_stats->events;
176                 s->ch_poll        += ch_stats->poll;
177                 s->ch_arm         += ch_stats->arm;
178                 s->ch_aff_change  += ch_stats->aff_change;
179                 s->ch_eq_rearm    += ch_stats->eq_rearm;
180                 /* xdp redirect */
181                 s->tx_xdp_xmit    += xdpsq_red_stats->xmit;
182                 s->tx_xdp_full    += xdpsq_red_stats->full;
183                 s->tx_xdp_err     += xdpsq_red_stats->err;
184                 s->tx_xdp_cqes    += xdpsq_red_stats->cqes;
185
186                 for (j = 0; j < priv->max_opened_tc; j++) {
187                         struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j];
188
189                         s->tx_packets           += sq_stats->packets;
190                         s->tx_bytes             += sq_stats->bytes;
191                         s->tx_tso_packets       += sq_stats->tso_packets;
192                         s->tx_tso_bytes         += sq_stats->tso_bytes;
193                         s->tx_tso_inner_packets += sq_stats->tso_inner_packets;
194                         s->tx_tso_inner_bytes   += sq_stats->tso_inner_bytes;
195                         s->tx_added_vlan_packets += sq_stats->added_vlan_packets;
196                         s->tx_nop               += sq_stats->nop;
197                         s->tx_queue_stopped     += sq_stats->stopped;
198                         s->tx_queue_wake        += sq_stats->wake;
199                         s->tx_udp_seg_rem       += sq_stats->udp_seg_rem;
200                         s->tx_queue_dropped     += sq_stats->dropped;
201                         s->tx_cqe_err           += sq_stats->cqe_err;
202                         s->tx_recover           += sq_stats->recover;
203                         s->tx_xmit_more         += sq_stats->xmit_more;
204                         s->tx_csum_partial_inner += sq_stats->csum_partial_inner;
205                         s->tx_csum_none         += sq_stats->csum_none;
206                         s->tx_csum_partial      += sq_stats->csum_partial;
207 #ifdef CONFIG_MLX5_EN_TLS
208                         s->tx_tls_ooo           += sq_stats->tls_ooo;
209                         s->tx_tls_resync_bytes  += sq_stats->tls_resync_bytes;
210 #endif
211                         s->tx_cqes              += sq_stats->cqes;
212                 }
213         }
214
215         memcpy(&priv->stats.sw, s, sizeof(*s));
216 }
217
218 static const struct counter_desc q_stats_desc[] = {
219         { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
220 };
221
222 static const struct counter_desc drop_rq_stats_desc[] = {
223         { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_if_down_packets) },
224 };
225
226 #define NUM_Q_COUNTERS                  ARRAY_SIZE(q_stats_desc)
227 #define NUM_DROP_RQ_COUNTERS            ARRAY_SIZE(drop_rq_stats_desc)
228
229 static int mlx5e_grp_q_get_num_stats(struct mlx5e_priv *priv)
230 {
231         int num_stats = 0;
232
233         if (priv->q_counter)
234                 num_stats += NUM_Q_COUNTERS;
235
236         if (priv->drop_rq_q_counter)
237                 num_stats += NUM_DROP_RQ_COUNTERS;
238
239         return num_stats;
240 }
241
242 static int mlx5e_grp_q_fill_strings(struct mlx5e_priv *priv, u8 *data, int idx)
243 {
244         int i;
245
246         for (i = 0; i < NUM_Q_COUNTERS && priv->q_counter; i++)
247                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
248                        q_stats_desc[i].format);
249
250         for (i = 0; i < NUM_DROP_RQ_COUNTERS && priv->drop_rq_q_counter; i++)
251                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
252                        drop_rq_stats_desc[i].format);
253
254         return idx;
255 }
256
257 static int mlx5e_grp_q_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
258 {
259         int i;
260
261         for (i = 0; i < NUM_Q_COUNTERS && priv->q_counter; i++)
262                 data[idx++] = MLX5E_READ_CTR32_CPU(&priv->stats.qcnt,
263                                                    q_stats_desc, i);
264         for (i = 0; i < NUM_DROP_RQ_COUNTERS && priv->drop_rq_q_counter; i++)
265                 data[idx++] = MLX5E_READ_CTR32_CPU(&priv->stats.qcnt,
266                                                    drop_rq_stats_desc, i);
267         return idx;
268 }
269
270 static void mlx5e_grp_q_update_stats(struct mlx5e_priv *priv)
271 {
272         struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
273         u32 out[MLX5_ST_SZ_DW(query_q_counter_out)];
274
275         if (priv->q_counter &&
276             !mlx5_core_query_q_counter(priv->mdev, priv->q_counter, 0, out,
277                                        sizeof(out)))
278                 qcnt->rx_out_of_buffer = MLX5_GET(query_q_counter_out,
279                                                   out, out_of_buffer);
280         if (priv->drop_rq_q_counter &&
281             !mlx5_core_query_q_counter(priv->mdev, priv->drop_rq_q_counter, 0,
282                                        out, sizeof(out)))
283                 qcnt->rx_if_down_packets = MLX5_GET(query_q_counter_out, out,
284                                                     out_of_buffer);
285 }
286
287 #define VNIC_ENV_OFF(c) MLX5_BYTE_OFF(query_vnic_env_out, c)
288 static const struct counter_desc vnic_env_stats_desc[] = {
289         { "rx_steer_missed_packets",
290                 VNIC_ENV_OFF(vport_env.nic_receive_steering_discard) },
291 };
292
293 #define NUM_VNIC_ENV_COUNTERS           ARRAY_SIZE(vnic_env_stats_desc)
294
295 static int mlx5e_grp_vnic_env_get_num_stats(struct mlx5e_priv *priv)
296 {
297         return MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard) ?
298                 NUM_VNIC_ENV_COUNTERS : 0;
299 }
300
301 static int mlx5e_grp_vnic_env_fill_strings(struct mlx5e_priv *priv, u8 *data,
302                                            int idx)
303 {
304         int i;
305
306         if (!MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard))
307                 return idx;
308
309         for (i = 0; i < NUM_VNIC_ENV_COUNTERS; i++)
310                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
311                        vnic_env_stats_desc[i].format);
312         return idx;
313 }
314
315 static int mlx5e_grp_vnic_env_fill_stats(struct mlx5e_priv *priv, u64 *data,
316                                          int idx)
317 {
318         int i;
319
320         if (!MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard))
321                 return idx;
322
323         for (i = 0; i < NUM_VNIC_ENV_COUNTERS; i++)
324                 data[idx++] = MLX5E_READ_CTR64_BE(priv->stats.vnic.query_vnic_env_out,
325                                                   vnic_env_stats_desc, i);
326         return idx;
327 }
328
329 static void mlx5e_grp_vnic_env_update_stats(struct mlx5e_priv *priv)
330 {
331         u32 *out = (u32 *)priv->stats.vnic.query_vnic_env_out;
332         int outlen = MLX5_ST_SZ_BYTES(query_vnic_env_out);
333         u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {0};
334         struct mlx5_core_dev *mdev = priv->mdev;
335
336         if (!MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard))
337                 return;
338
339         MLX5_SET(query_vnic_env_in, in, opcode,
340                  MLX5_CMD_OP_QUERY_VNIC_ENV);
341         MLX5_SET(query_vnic_env_in, in, op_mod, 0);
342         MLX5_SET(query_vnic_env_in, in, other_vport, 0);
343         mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
344 }
345
346 #define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
347 static const struct counter_desc vport_stats_desc[] = {
348         { "rx_vport_unicast_packets",
349                 VPORT_COUNTER_OFF(received_eth_unicast.packets) },
350         { "rx_vport_unicast_bytes",
351                 VPORT_COUNTER_OFF(received_eth_unicast.octets) },
352         { "tx_vport_unicast_packets",
353                 VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
354         { "tx_vport_unicast_bytes",
355                 VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
356         { "rx_vport_multicast_packets",
357                 VPORT_COUNTER_OFF(received_eth_multicast.packets) },
358         { "rx_vport_multicast_bytes",
359                 VPORT_COUNTER_OFF(received_eth_multicast.octets) },
360         { "tx_vport_multicast_packets",
361                 VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
362         { "tx_vport_multicast_bytes",
363                 VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
364         { "rx_vport_broadcast_packets",
365                 VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
366         { "rx_vport_broadcast_bytes",
367                 VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
368         { "tx_vport_broadcast_packets",
369                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
370         { "tx_vport_broadcast_bytes",
371                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
372         { "rx_vport_rdma_unicast_packets",
373                 VPORT_COUNTER_OFF(received_ib_unicast.packets) },
374         { "rx_vport_rdma_unicast_bytes",
375                 VPORT_COUNTER_OFF(received_ib_unicast.octets) },
376         { "tx_vport_rdma_unicast_packets",
377                 VPORT_COUNTER_OFF(transmitted_ib_unicast.packets) },
378         { "tx_vport_rdma_unicast_bytes",
379                 VPORT_COUNTER_OFF(transmitted_ib_unicast.octets) },
380         { "rx_vport_rdma_multicast_packets",
381                 VPORT_COUNTER_OFF(received_ib_multicast.packets) },
382         { "rx_vport_rdma_multicast_bytes",
383                 VPORT_COUNTER_OFF(received_ib_multicast.octets) },
384         { "tx_vport_rdma_multicast_packets",
385                 VPORT_COUNTER_OFF(transmitted_ib_multicast.packets) },
386         { "tx_vport_rdma_multicast_bytes",
387                 VPORT_COUNTER_OFF(transmitted_ib_multicast.octets) },
388 };
389
390 #define NUM_VPORT_COUNTERS              ARRAY_SIZE(vport_stats_desc)
391
392 static int mlx5e_grp_vport_get_num_stats(struct mlx5e_priv *priv)
393 {
394         return NUM_VPORT_COUNTERS;
395 }
396
397 static int mlx5e_grp_vport_fill_strings(struct mlx5e_priv *priv, u8 *data,
398                                         int idx)
399 {
400         int i;
401
402         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
403                 strcpy(data + (idx++) * ETH_GSTRING_LEN, vport_stats_desc[i].format);
404         return idx;
405 }
406
407 static int mlx5e_grp_vport_fill_stats(struct mlx5e_priv *priv, u64 *data,
408                                       int idx)
409 {
410         int i;
411
412         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
413                 data[idx++] = MLX5E_READ_CTR64_BE(priv->stats.vport.query_vport_out,
414                                                   vport_stats_desc, i);
415         return idx;
416 }
417
418 static void mlx5e_grp_vport_update_stats(struct mlx5e_priv *priv)
419 {
420         int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
421         u32 *out = (u32 *)priv->stats.vport.query_vport_out;
422         u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)] = {0};
423         struct mlx5_core_dev *mdev = priv->mdev;
424
425         MLX5_SET(query_vport_counter_in, in, opcode, MLX5_CMD_OP_QUERY_VPORT_COUNTER);
426         MLX5_SET(query_vport_counter_in, in, op_mod, 0);
427         MLX5_SET(query_vport_counter_in, in, other_vport, 0);
428         mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
429 }
430
431 #define PPORT_802_3_OFF(c) \
432         MLX5_BYTE_OFF(ppcnt_reg, \
433                       counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
434 static const struct counter_desc pport_802_3_stats_desc[] = {
435         { "tx_packets_phy", PPORT_802_3_OFF(a_frames_transmitted_ok) },
436         { "rx_packets_phy", PPORT_802_3_OFF(a_frames_received_ok) },
437         { "rx_crc_errors_phy", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
438         { "tx_bytes_phy", PPORT_802_3_OFF(a_octets_transmitted_ok) },
439         { "rx_bytes_phy", PPORT_802_3_OFF(a_octets_received_ok) },
440         { "tx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
441         { "tx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
442         { "rx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
443         { "rx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
444         { "rx_in_range_len_errors_phy", PPORT_802_3_OFF(a_in_range_length_errors) },
445         { "rx_out_of_range_len_phy", PPORT_802_3_OFF(a_out_of_range_length_field) },
446         { "rx_oversize_pkts_phy", PPORT_802_3_OFF(a_frame_too_long_errors) },
447         { "rx_symbol_err_phy", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
448         { "tx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
449         { "rx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_received) },
450         { "rx_unsupported_op_phy", PPORT_802_3_OFF(a_unsupported_opcodes_received) },
451         { "rx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
452         { "tx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
453 };
454
455 #define NUM_PPORT_802_3_COUNTERS        ARRAY_SIZE(pport_802_3_stats_desc)
456
457 static int mlx5e_grp_802_3_get_num_stats(struct mlx5e_priv *priv)
458 {
459         return NUM_PPORT_802_3_COUNTERS;
460 }
461
462 static int mlx5e_grp_802_3_fill_strings(struct mlx5e_priv *priv, u8 *data,
463                                         int idx)
464 {
465         int i;
466
467         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
468                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_802_3_stats_desc[i].format);
469         return idx;
470 }
471
472 static int mlx5e_grp_802_3_fill_stats(struct mlx5e_priv *priv, u64 *data,
473                                       int idx)
474 {
475         int i;
476
477         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
478                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.IEEE_802_3_counters,
479                                                   pport_802_3_stats_desc, i);
480         return idx;
481 }
482
483 static void mlx5e_grp_802_3_update_stats(struct mlx5e_priv *priv)
484 {
485         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
486         struct mlx5_core_dev *mdev = priv->mdev;
487         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
488         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
489         void *out;
490
491         MLX5_SET(ppcnt_reg, in, local_port, 1);
492         out = pstats->IEEE_802_3_counters;
493         MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
494         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
495 }
496
497 #define PPORT_2863_OFF(c) \
498         MLX5_BYTE_OFF(ppcnt_reg, \
499                       counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
500 static const struct counter_desc pport_2863_stats_desc[] = {
501         { "rx_discards_phy", PPORT_2863_OFF(if_in_discards) },
502         { "tx_discards_phy", PPORT_2863_OFF(if_out_discards) },
503         { "tx_errors_phy", PPORT_2863_OFF(if_out_errors) },
504 };
505
506 #define NUM_PPORT_2863_COUNTERS         ARRAY_SIZE(pport_2863_stats_desc)
507
508 static int mlx5e_grp_2863_get_num_stats(struct mlx5e_priv *priv)
509 {
510         return NUM_PPORT_2863_COUNTERS;
511 }
512
513 static int mlx5e_grp_2863_fill_strings(struct mlx5e_priv *priv, u8 *data,
514                                        int idx)
515 {
516         int i;
517
518         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
519                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_2863_stats_desc[i].format);
520         return idx;
521 }
522
523 static int mlx5e_grp_2863_fill_stats(struct mlx5e_priv *priv, u64 *data,
524                                      int idx)
525 {
526         int i;
527
528         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
529                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2863_counters,
530                                                   pport_2863_stats_desc, i);
531         return idx;
532 }
533
534 static void mlx5e_grp_2863_update_stats(struct mlx5e_priv *priv)
535 {
536         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
537         struct mlx5_core_dev *mdev = priv->mdev;
538         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
539         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
540         void *out;
541
542         MLX5_SET(ppcnt_reg, in, local_port, 1);
543         out = pstats->RFC_2863_counters;
544         MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
545         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
546 }
547
548 #define PPORT_2819_OFF(c) \
549         MLX5_BYTE_OFF(ppcnt_reg, \
550                       counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
551 static const struct counter_desc pport_2819_stats_desc[] = {
552         { "rx_undersize_pkts_phy", PPORT_2819_OFF(ether_stats_undersize_pkts) },
553         { "rx_fragments_phy", PPORT_2819_OFF(ether_stats_fragments) },
554         { "rx_jabbers_phy", PPORT_2819_OFF(ether_stats_jabbers) },
555         { "rx_64_bytes_phy", PPORT_2819_OFF(ether_stats_pkts64octets) },
556         { "rx_65_to_127_bytes_phy", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
557         { "rx_128_to_255_bytes_phy", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
558         { "rx_256_to_511_bytes_phy", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
559         { "rx_512_to_1023_bytes_phy", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
560         { "rx_1024_to_1518_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
561         { "rx_1519_to_2047_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
562         { "rx_2048_to_4095_bytes_phy", PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
563         { "rx_4096_to_8191_bytes_phy", PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
564         { "rx_8192_to_10239_bytes_phy", PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
565 };
566
567 #define NUM_PPORT_2819_COUNTERS         ARRAY_SIZE(pport_2819_stats_desc)
568
569 static int mlx5e_grp_2819_get_num_stats(struct mlx5e_priv *priv)
570 {
571         return NUM_PPORT_2819_COUNTERS;
572 }
573
574 static int mlx5e_grp_2819_fill_strings(struct mlx5e_priv *priv, u8 *data,
575                                        int idx)
576 {
577         int i;
578
579         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
580                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_2819_stats_desc[i].format);
581         return idx;
582 }
583
584 static int mlx5e_grp_2819_fill_stats(struct mlx5e_priv *priv, u64 *data,
585                                      int idx)
586 {
587         int i;
588
589         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
590                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2819_counters,
591                                                   pport_2819_stats_desc, i);
592         return idx;
593 }
594
595 static void mlx5e_grp_2819_update_stats(struct mlx5e_priv *priv)
596 {
597         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
598         struct mlx5_core_dev *mdev = priv->mdev;
599         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
600         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
601         void *out;
602
603         MLX5_SET(ppcnt_reg, in, local_port, 1);
604         out = pstats->RFC_2819_counters;
605         MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
606         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
607 }
608
609 #define PPORT_PHY_STATISTICAL_OFF(c) \
610         MLX5_BYTE_OFF(ppcnt_reg, \
611                       counter_set.phys_layer_statistical_cntrs.c##_high)
612 static const struct counter_desc pport_phy_statistical_stats_desc[] = {
613         { "rx_pcs_symbol_err_phy", PPORT_PHY_STATISTICAL_OFF(phy_symbol_errors) },
614         { "rx_corrected_bits_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits) },
615 };
616
617 static const struct counter_desc
618 pport_phy_statistical_err_lanes_stats_desc[] = {
619         { "rx_err_lane_0_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane0) },
620         { "rx_err_lane_1_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane1) },
621         { "rx_err_lane_2_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane2) },
622         { "rx_err_lane_3_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane3) },
623 };
624
625 #define NUM_PPORT_PHY_STATISTICAL_COUNTERS \
626         ARRAY_SIZE(pport_phy_statistical_stats_desc)
627 #define NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS \
628         ARRAY_SIZE(pport_phy_statistical_err_lanes_stats_desc)
629
630 static int mlx5e_grp_phy_get_num_stats(struct mlx5e_priv *priv)
631 {
632         struct mlx5_core_dev *mdev = priv->mdev;
633         int num_stats;
634
635         /* "1" for link_down_events special counter */
636         num_stats = 1;
637
638         num_stats += MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group) ?
639                      NUM_PPORT_PHY_STATISTICAL_COUNTERS : 0;
640
641         num_stats += MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters) ?
642                      NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS : 0;
643
644         return num_stats;
645 }
646
647 static int mlx5e_grp_phy_fill_strings(struct mlx5e_priv *priv, u8 *data,
648                                       int idx)
649 {
650         struct mlx5_core_dev *mdev = priv->mdev;
651         int i;
652
653         strcpy(data + (idx++) * ETH_GSTRING_LEN, "link_down_events_phy");
654
655         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
656                 return idx;
657
658         for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
659                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
660                        pport_phy_statistical_stats_desc[i].format);
661
662         if (MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters))
663                 for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS; i++)
664                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
665                                pport_phy_statistical_err_lanes_stats_desc[i].format);
666
667         return idx;
668 }
669
670 static int mlx5e_grp_phy_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
671 {
672         struct mlx5_core_dev *mdev = priv->mdev;
673         int i;
674
675         /* link_down_events_phy has special handling since it is not stored in __be64 format */
676         data[idx++] = MLX5_GET(ppcnt_reg, priv->stats.pport.phy_counters,
677                                counter_set.phys_layer_cntrs.link_down_events);
678
679         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
680                 return idx;
681
682         for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
683                 data[idx++] =
684                         MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
685                                             pport_phy_statistical_stats_desc, i);
686
687         if (MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters))
688                 for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS; i++)
689                         data[idx++] =
690                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
691                                                     pport_phy_statistical_err_lanes_stats_desc,
692                                                     i);
693         return idx;
694 }
695
696 static void mlx5e_grp_phy_update_stats(struct mlx5e_priv *priv)
697 {
698         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
699         struct mlx5_core_dev *mdev = priv->mdev;
700         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
701         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
702         void *out;
703
704         MLX5_SET(ppcnt_reg, in, local_port, 1);
705         out = pstats->phy_counters;
706         MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
707         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
708
709         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
710                 return;
711
712         out = pstats->phy_statistical_counters;
713         MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_STATISTICAL_GROUP);
714         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
715 }
716
717 #define PPORT_ETH_EXT_OFF(c) \
718         MLX5_BYTE_OFF(ppcnt_reg, \
719                       counter_set.eth_extended_cntrs_grp_data_layout.c##_high)
720 static const struct counter_desc pport_eth_ext_stats_desc[] = {
721         { "rx_buffer_passed_thres_phy", PPORT_ETH_EXT_OFF(rx_buffer_almost_full) },
722 };
723
724 #define NUM_PPORT_ETH_EXT_COUNTERS      ARRAY_SIZE(pport_eth_ext_stats_desc)
725
726 static int mlx5e_grp_eth_ext_get_num_stats(struct mlx5e_priv *priv)
727 {
728         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
729                 return NUM_PPORT_ETH_EXT_COUNTERS;
730
731         return 0;
732 }
733
734 static int mlx5e_grp_eth_ext_fill_strings(struct mlx5e_priv *priv, u8 *data,
735                                           int idx)
736 {
737         int i;
738
739         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
740                 for (i = 0; i < NUM_PPORT_ETH_EXT_COUNTERS; i++)
741                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
742                                pport_eth_ext_stats_desc[i].format);
743         return idx;
744 }
745
746 static int mlx5e_grp_eth_ext_fill_stats(struct mlx5e_priv *priv, u64 *data,
747                                         int idx)
748 {
749         int i;
750
751         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
752                 for (i = 0; i < NUM_PPORT_ETH_EXT_COUNTERS; i++)
753                         data[idx++] =
754                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.eth_ext_counters,
755                                                     pport_eth_ext_stats_desc, i);
756         return idx;
757 }
758
759 static void mlx5e_grp_eth_ext_update_stats(struct mlx5e_priv *priv)
760 {
761         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
762         struct mlx5_core_dev *mdev = priv->mdev;
763         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
764         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
765         void *out;
766
767         if (!MLX5_CAP_PCAM_FEATURE(mdev, rx_buffer_fullness_counters))
768                 return;
769
770         MLX5_SET(ppcnt_reg, in, local_port, 1);
771         out = pstats->eth_ext_counters;
772         MLX5_SET(ppcnt_reg, in, grp, MLX5_ETHERNET_EXTENDED_COUNTERS_GROUP);
773         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
774 }
775
776 #define PCIE_PERF_OFF(c) \
777         MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c)
778 static const struct counter_desc pcie_perf_stats_desc[] = {
779         { "rx_pci_signal_integrity", PCIE_PERF_OFF(rx_errors) },
780         { "tx_pci_signal_integrity", PCIE_PERF_OFF(tx_errors) },
781 };
782
783 #define PCIE_PERF_OFF64(c) \
784         MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c##_high)
785 static const struct counter_desc pcie_perf_stats_desc64[] = {
786         { "outbound_pci_buffer_overflow", PCIE_PERF_OFF64(tx_overflow_buffer_pkt) },
787 };
788
789 static const struct counter_desc pcie_perf_stall_stats_desc[] = {
790         { "outbound_pci_stalled_rd", PCIE_PERF_OFF(outbound_stalled_reads) },
791         { "outbound_pci_stalled_wr", PCIE_PERF_OFF(outbound_stalled_writes) },
792         { "outbound_pci_stalled_rd_events", PCIE_PERF_OFF(outbound_stalled_reads_events) },
793         { "outbound_pci_stalled_wr_events", PCIE_PERF_OFF(outbound_stalled_writes_events) },
794 };
795
796 #define NUM_PCIE_PERF_COUNTERS          ARRAY_SIZE(pcie_perf_stats_desc)
797 #define NUM_PCIE_PERF_COUNTERS64        ARRAY_SIZE(pcie_perf_stats_desc64)
798 #define NUM_PCIE_PERF_STALL_COUNTERS    ARRAY_SIZE(pcie_perf_stall_stats_desc)
799
800 static int mlx5e_grp_pcie_get_num_stats(struct mlx5e_priv *priv)
801 {
802         int num_stats = 0;
803
804         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
805                 num_stats += NUM_PCIE_PERF_COUNTERS;
806
807         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
808                 num_stats += NUM_PCIE_PERF_COUNTERS64;
809
810         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
811                 num_stats += NUM_PCIE_PERF_STALL_COUNTERS;
812
813         return num_stats;
814 }
815
816 static int mlx5e_grp_pcie_fill_strings(struct mlx5e_priv *priv, u8 *data,
817                                        int idx)
818 {
819         int i;
820
821         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
822                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS; i++)
823                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
824                                pcie_perf_stats_desc[i].format);
825
826         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
827                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS64; i++)
828                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
829                                pcie_perf_stats_desc64[i].format);
830
831         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
832                 for (i = 0; i < NUM_PCIE_PERF_STALL_COUNTERS; i++)
833                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
834                                pcie_perf_stall_stats_desc[i].format);
835         return idx;
836 }
837
838 static int mlx5e_grp_pcie_fill_stats(struct mlx5e_priv *priv, u64 *data,
839                                      int idx)
840 {
841         int i;
842
843         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
844                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS; i++)
845                         data[idx++] =
846                                 MLX5E_READ_CTR32_BE(&priv->stats.pcie.pcie_perf_counters,
847                                                     pcie_perf_stats_desc, i);
848
849         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
850                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS64; i++)
851                         data[idx++] =
852                                 MLX5E_READ_CTR64_BE(&priv->stats.pcie.pcie_perf_counters,
853                                                     pcie_perf_stats_desc64, i);
854
855         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
856                 for (i = 0; i < NUM_PCIE_PERF_STALL_COUNTERS; i++)
857                         data[idx++] =
858                                 MLX5E_READ_CTR32_BE(&priv->stats.pcie.pcie_perf_counters,
859                                                     pcie_perf_stall_stats_desc, i);
860         return idx;
861 }
862
863 static void mlx5e_grp_pcie_update_stats(struct mlx5e_priv *priv)
864 {
865         struct mlx5e_pcie_stats *pcie_stats = &priv->stats.pcie;
866         struct mlx5_core_dev *mdev = priv->mdev;
867         u32 in[MLX5_ST_SZ_DW(mpcnt_reg)] = {0};
868         int sz = MLX5_ST_SZ_BYTES(mpcnt_reg);
869         void *out;
870
871         if (!MLX5_CAP_MCAM_FEATURE(mdev, pcie_performance_group))
872                 return;
873
874         out = pcie_stats->pcie_perf_counters;
875         MLX5_SET(mpcnt_reg, in, grp, MLX5_PCIE_PERFORMANCE_COUNTERS_GROUP);
876         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_MPCNT, 0, 0);
877 }
878
879 #define PPORT_PER_PRIO_OFF(c) \
880         MLX5_BYTE_OFF(ppcnt_reg, \
881                       counter_set.eth_per_prio_grp_data_layout.c##_high)
882 static const struct counter_desc pport_per_prio_traffic_stats_desc[] = {
883         { "rx_prio%d_bytes", PPORT_PER_PRIO_OFF(rx_octets) },
884         { "rx_prio%d_packets", PPORT_PER_PRIO_OFF(rx_frames) },
885         { "tx_prio%d_bytes", PPORT_PER_PRIO_OFF(tx_octets) },
886         { "tx_prio%d_packets", PPORT_PER_PRIO_OFF(tx_frames) },
887 };
888
889 #define NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS     ARRAY_SIZE(pport_per_prio_traffic_stats_desc)
890
891 static int mlx5e_grp_per_prio_traffic_get_num_stats(void)
892 {
893         return NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS * NUM_PPORT_PRIO;
894 }
895
896 static int mlx5e_grp_per_prio_traffic_fill_strings(struct mlx5e_priv *priv,
897                                                    u8 *data,
898                                                    int idx)
899 {
900         int i, prio;
901
902         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
903                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
904                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
905                                 pport_per_prio_traffic_stats_desc[i].format, prio);
906         }
907
908         return idx;
909 }
910
911 static int mlx5e_grp_per_prio_traffic_fill_stats(struct mlx5e_priv *priv,
912                                                  u64 *data,
913                                                  int idx)
914 {
915         int i, prio;
916
917         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
918                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
919                         data[idx++] =
920                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
921                                                     pport_per_prio_traffic_stats_desc, i);
922         }
923
924         return idx;
925 }
926
927 static const struct counter_desc pport_per_prio_pfc_stats_desc[] = {
928         /* %s is "global" or "prio{i}" */
929         { "rx_%s_pause", PPORT_PER_PRIO_OFF(rx_pause) },
930         { "rx_%s_pause_duration", PPORT_PER_PRIO_OFF(rx_pause_duration) },
931         { "tx_%s_pause", PPORT_PER_PRIO_OFF(tx_pause) },
932         { "tx_%s_pause_duration", PPORT_PER_PRIO_OFF(tx_pause_duration) },
933         { "rx_%s_pause_transition", PPORT_PER_PRIO_OFF(rx_pause_transition) },
934 };
935
936 static const struct counter_desc pport_pfc_stall_stats_desc[] = {
937         { "tx_pause_storm_warning_events ", PPORT_PER_PRIO_OFF(device_stall_minor_watermark_cnt) },
938         { "tx_pause_storm_error_events", PPORT_PER_PRIO_OFF(device_stall_critical_watermark_cnt) },
939 };
940
941 #define NUM_PPORT_PER_PRIO_PFC_COUNTERS         ARRAY_SIZE(pport_per_prio_pfc_stats_desc)
942 #define NUM_PPORT_PFC_STALL_COUNTERS(priv)      (ARRAY_SIZE(pport_pfc_stall_stats_desc) * \
943                                                  MLX5_CAP_PCAM_FEATURE((priv)->mdev, pfcc_mask) * \
944                                                  MLX5_CAP_DEBUG((priv)->mdev, stall_detect))
945
946 static unsigned long mlx5e_query_pfc_combined(struct mlx5e_priv *priv)
947 {
948         struct mlx5_core_dev *mdev = priv->mdev;
949         u8 pfc_en_tx;
950         u8 pfc_en_rx;
951         int err;
952
953         if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
954                 return 0;
955
956         err = mlx5_query_port_pfc(mdev, &pfc_en_tx, &pfc_en_rx);
957
958         return err ? 0 : pfc_en_tx | pfc_en_rx;
959 }
960
961 static bool mlx5e_query_global_pause_combined(struct mlx5e_priv *priv)
962 {
963         struct mlx5_core_dev *mdev = priv->mdev;
964         u32 rx_pause;
965         u32 tx_pause;
966         int err;
967
968         if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
969                 return false;
970
971         err = mlx5_query_port_pause(mdev, &rx_pause, &tx_pause);
972
973         return err ? false : rx_pause | tx_pause;
974 }
975
976 static int mlx5e_grp_per_prio_pfc_get_num_stats(struct mlx5e_priv *priv)
977 {
978         return (mlx5e_query_global_pause_combined(priv) +
979                 hweight8(mlx5e_query_pfc_combined(priv))) *
980                 NUM_PPORT_PER_PRIO_PFC_COUNTERS +
981                 NUM_PPORT_PFC_STALL_COUNTERS(priv);
982 }
983
984 static int mlx5e_grp_per_prio_pfc_fill_strings(struct mlx5e_priv *priv,
985                                                u8 *data,
986                                                int idx)
987 {
988         unsigned long pfc_combined;
989         int i, prio;
990
991         pfc_combined = mlx5e_query_pfc_combined(priv);
992         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
993                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
994                         char pfc_string[ETH_GSTRING_LEN];
995
996                         snprintf(pfc_string, sizeof(pfc_string), "prio%d", prio);
997                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
998                                 pport_per_prio_pfc_stats_desc[i].format, pfc_string);
999                 }
1000         }
1001
1002         if (mlx5e_query_global_pause_combined(priv)) {
1003                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1004                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1005                                 pport_per_prio_pfc_stats_desc[i].format, "global");
1006                 }
1007         }
1008
1009         for (i = 0; i < NUM_PPORT_PFC_STALL_COUNTERS(priv); i++)
1010                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
1011                        pport_pfc_stall_stats_desc[i].format);
1012
1013         return idx;
1014 }
1015
1016 static int mlx5e_grp_per_prio_pfc_fill_stats(struct mlx5e_priv *priv,
1017                                              u64 *data,
1018                                              int idx)
1019 {
1020         unsigned long pfc_combined;
1021         int i, prio;
1022
1023         pfc_combined = mlx5e_query_pfc_combined(priv);
1024         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
1025                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1026                         data[idx++] =
1027                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
1028                                                     pport_per_prio_pfc_stats_desc, i);
1029                 }
1030         }
1031
1032         if (mlx5e_query_global_pause_combined(priv)) {
1033                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1034                         data[idx++] =
1035                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[0],
1036                                                     pport_per_prio_pfc_stats_desc, i);
1037                 }
1038         }
1039
1040         for (i = 0; i < NUM_PPORT_PFC_STALL_COUNTERS(priv); i++)
1041                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[0],
1042                                                   pport_pfc_stall_stats_desc, i);
1043
1044         return idx;
1045 }
1046
1047 static int mlx5e_grp_per_prio_get_num_stats(struct mlx5e_priv *priv)
1048 {
1049         return mlx5e_grp_per_prio_traffic_get_num_stats() +
1050                 mlx5e_grp_per_prio_pfc_get_num_stats(priv);
1051 }
1052
1053 static int mlx5e_grp_per_prio_fill_strings(struct mlx5e_priv *priv, u8 *data,
1054                                            int idx)
1055 {
1056         idx = mlx5e_grp_per_prio_traffic_fill_strings(priv, data, idx);
1057         idx = mlx5e_grp_per_prio_pfc_fill_strings(priv, data, idx);
1058         return idx;
1059 }
1060
1061 static int mlx5e_grp_per_prio_fill_stats(struct mlx5e_priv *priv, u64 *data,
1062                                          int idx)
1063 {
1064         idx = mlx5e_grp_per_prio_traffic_fill_stats(priv, data, idx);
1065         idx = mlx5e_grp_per_prio_pfc_fill_stats(priv, data, idx);
1066         return idx;
1067 }
1068
1069 static void mlx5e_grp_per_prio_update_stats(struct mlx5e_priv *priv)
1070 {
1071         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
1072         struct mlx5_core_dev *mdev = priv->mdev;
1073         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
1074         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
1075         int prio;
1076         void *out;
1077
1078         MLX5_SET(ppcnt_reg, in, local_port, 1);
1079         MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
1080         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1081                 out = pstats->per_prio_counters[prio];
1082                 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
1083                 mlx5_core_access_reg(mdev, in, sz, out, sz,
1084                                      MLX5_REG_PPCNT, 0, 0);
1085         }
1086 }
1087
1088 static const struct counter_desc mlx5e_pme_status_desc[] = {
1089         { "module_unplug", 8 },
1090 };
1091
1092 static const struct counter_desc mlx5e_pme_error_desc[] = {
1093         { "module_bus_stuck", 16 },       /* bus stuck (I2C or data shorted) */
1094         { "module_high_temp", 48 },       /* high temperature */
1095         { "module_bad_shorted", 56 },    /* bad or shorted cable/module */
1096 };
1097
1098 #define NUM_PME_STATUS_STATS            ARRAY_SIZE(mlx5e_pme_status_desc)
1099 #define NUM_PME_ERR_STATS               ARRAY_SIZE(mlx5e_pme_error_desc)
1100
1101 static int mlx5e_grp_pme_get_num_stats(struct mlx5e_priv *priv)
1102 {
1103         return NUM_PME_STATUS_STATS + NUM_PME_ERR_STATS;
1104 }
1105
1106 static int mlx5e_grp_pme_fill_strings(struct mlx5e_priv *priv, u8 *data,
1107                                       int idx)
1108 {
1109         int i;
1110
1111         for (i = 0; i < NUM_PME_STATUS_STATS; i++)
1112                 strcpy(data + (idx++) * ETH_GSTRING_LEN, mlx5e_pme_status_desc[i].format);
1113
1114         for (i = 0; i < NUM_PME_ERR_STATS; i++)
1115                 strcpy(data + (idx++) * ETH_GSTRING_LEN, mlx5e_pme_error_desc[i].format);
1116
1117         return idx;
1118 }
1119
1120 static int mlx5e_grp_pme_fill_stats(struct mlx5e_priv *priv, u64 *data,
1121                                     int idx)
1122 {
1123         struct mlx5_priv *mlx5_priv = &priv->mdev->priv;
1124         int i;
1125
1126         for (i = 0; i < NUM_PME_STATUS_STATS; i++)
1127                 data[idx++] = MLX5E_READ_CTR64_CPU(mlx5_priv->pme_stats.status_counters,
1128                                                    mlx5e_pme_status_desc, i);
1129
1130         for (i = 0; i < NUM_PME_ERR_STATS; i++)
1131                 data[idx++] = MLX5E_READ_CTR64_CPU(mlx5_priv->pme_stats.error_counters,
1132                                                    mlx5e_pme_error_desc, i);
1133
1134         return idx;
1135 }
1136
1137 static int mlx5e_grp_ipsec_get_num_stats(struct mlx5e_priv *priv)
1138 {
1139         return mlx5e_ipsec_get_count(priv);
1140 }
1141
1142 static int mlx5e_grp_ipsec_fill_strings(struct mlx5e_priv *priv, u8 *data,
1143                                         int idx)
1144 {
1145         return idx + mlx5e_ipsec_get_strings(priv,
1146                                              data + idx * ETH_GSTRING_LEN);
1147 }
1148
1149 static int mlx5e_grp_ipsec_fill_stats(struct mlx5e_priv *priv, u64 *data,
1150                                       int idx)
1151 {
1152         return idx + mlx5e_ipsec_get_stats(priv, data + idx);
1153 }
1154
1155 static void mlx5e_grp_ipsec_update_stats(struct mlx5e_priv *priv)
1156 {
1157         mlx5e_ipsec_update_stats(priv);
1158 }
1159
1160 static int mlx5e_grp_tls_get_num_stats(struct mlx5e_priv *priv)
1161 {
1162         return mlx5e_tls_get_count(priv);
1163 }
1164
1165 static int mlx5e_grp_tls_fill_strings(struct mlx5e_priv *priv, u8 *data,
1166                                       int idx)
1167 {
1168         return idx + mlx5e_tls_get_strings(priv, data + idx * ETH_GSTRING_LEN);
1169 }
1170
1171 static int mlx5e_grp_tls_fill_stats(struct mlx5e_priv *priv, u64 *data, int idx)
1172 {
1173         return idx + mlx5e_tls_get_stats(priv, data + idx);
1174 }
1175
1176 static const struct counter_desc rq_stats_desc[] = {
1177         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, packets) },
1178         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, bytes) },
1179         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_complete) },
1180         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_unnecessary) },
1181         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_unnecessary_inner) },
1182         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_none) },
1183         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_drop) },
1184         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_redirect) },
1185         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_packets) },
1186         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_bytes) },
1187         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, ecn_mark) },
1188         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, removed_vlan_packets) },
1189         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, wqe_err) },
1190         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, mpwqe_filler_cqes) },
1191         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, mpwqe_filler_strides) },
1192         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
1193         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_blks) },
1194         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_pkts) },
1195         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, page_reuse) },
1196         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_reuse) },
1197         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_full) },
1198         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_empty) },
1199         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_busy) },
1200         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_waive) },
1201         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, congst_umr) },
1202         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, arfs_err) },
1203 };
1204
1205 static const struct counter_desc sq_stats_desc[] = {
1206         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, packets) },
1207         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, bytes) },
1208         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_packets) },
1209         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_bytes) },
1210         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
1211         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
1212         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial) },
1213         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial_inner) },
1214         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, added_vlan_packets) },
1215         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, nop) },
1216         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) },
1217         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) },
1218         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, dropped) },
1219         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, xmit_more) },
1220         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, recover) },
1221         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, cqes) },
1222         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, wake) },
1223         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, cqe_err) },
1224 };
1225
1226 static const struct counter_desc rq_xdpsq_stats_desc[] = {
1227         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, xmit) },
1228         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, full) },
1229         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, err) },
1230         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, cqes) },
1231 };
1232
1233 static const struct counter_desc xdpsq_stats_desc[] = {
1234         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, xmit) },
1235         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, full) },
1236         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, err) },
1237         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, cqes) },
1238 };
1239
1240 static const struct counter_desc ch_stats_desc[] = {
1241         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, events) },
1242         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, poll) },
1243         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, arm) },
1244         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, aff_change) },
1245         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, eq_rearm) },
1246 };
1247
1248 #define NUM_RQ_STATS                    ARRAY_SIZE(rq_stats_desc)
1249 #define NUM_SQ_STATS                    ARRAY_SIZE(sq_stats_desc)
1250 #define NUM_XDPSQ_STATS                 ARRAY_SIZE(xdpsq_stats_desc)
1251 #define NUM_RQ_XDPSQ_STATS              ARRAY_SIZE(rq_xdpsq_stats_desc)
1252 #define NUM_CH_STATS                    ARRAY_SIZE(ch_stats_desc)
1253
1254 static int mlx5e_grp_channels_get_num_stats(struct mlx5e_priv *priv)
1255 {
1256         int max_nch = mlx5e_get_netdev_max_channels(priv->netdev);
1257
1258         return (NUM_RQ_STATS * max_nch) +
1259                (NUM_CH_STATS * max_nch) +
1260                (NUM_SQ_STATS * max_nch * priv->max_opened_tc) +
1261                (NUM_RQ_XDPSQ_STATS * max_nch) +
1262                (NUM_XDPSQ_STATS * max_nch);
1263 }
1264
1265 static int mlx5e_grp_channels_fill_strings(struct mlx5e_priv *priv, u8 *data,
1266                                            int idx)
1267 {
1268         int max_nch = mlx5e_get_netdev_max_channels(priv->netdev);
1269         int i, j, tc;
1270
1271         for (i = 0; i < max_nch; i++)
1272                 for (j = 0; j < NUM_CH_STATS; j++)
1273                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1274                                 ch_stats_desc[j].format, i);
1275
1276         for (i = 0; i < max_nch; i++) {
1277                 for (j = 0; j < NUM_RQ_STATS; j++)
1278                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1279                                 rq_stats_desc[j].format, i);
1280                 for (j = 0; j < NUM_RQ_XDPSQ_STATS; j++)
1281                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1282                                 rq_xdpsq_stats_desc[j].format, i);
1283         }
1284
1285         for (tc = 0; tc < priv->max_opened_tc; tc++)
1286                 for (i = 0; i < max_nch; i++)
1287                         for (j = 0; j < NUM_SQ_STATS; j++)
1288                                 sprintf(data + (idx++) * ETH_GSTRING_LEN,
1289                                         sq_stats_desc[j].format,
1290                                         priv->channel_tc2txq[i][tc]);
1291
1292         for (i = 0; i < max_nch; i++)
1293                 for (j = 0; j < NUM_XDPSQ_STATS; j++)
1294                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1295                                 xdpsq_stats_desc[j].format, i);
1296
1297         return idx;
1298 }
1299
1300 static int mlx5e_grp_channels_fill_stats(struct mlx5e_priv *priv, u64 *data,
1301                                          int idx)
1302 {
1303         int max_nch = mlx5e_get_netdev_max_channels(priv->netdev);
1304         int i, j, tc;
1305
1306         for (i = 0; i < max_nch; i++)
1307                 for (j = 0; j < NUM_CH_STATS; j++)
1308                         data[idx++] =
1309                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].ch,
1310                                                      ch_stats_desc, j);
1311
1312         for (i = 0; i < max_nch; i++) {
1313                 for (j = 0; j < NUM_RQ_STATS; j++)
1314                         data[idx++] =
1315                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].rq,
1316                                                      rq_stats_desc, j);
1317                 for (j = 0; j < NUM_RQ_XDPSQ_STATS; j++)
1318                         data[idx++] =
1319                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].rq_xdpsq,
1320                                                      rq_xdpsq_stats_desc, j);
1321         }
1322
1323         for (tc = 0; tc < priv->max_opened_tc; tc++)
1324                 for (i = 0; i < max_nch; i++)
1325                         for (j = 0; j < NUM_SQ_STATS; j++)
1326                                 data[idx++] =
1327                                         MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].sq[tc],
1328                                                              sq_stats_desc, j);
1329
1330         for (i = 0; i < max_nch; i++)
1331                 for (j = 0; j < NUM_XDPSQ_STATS; j++)
1332                         data[idx++] =
1333                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].xdpsq,
1334                                                      xdpsq_stats_desc, j);
1335
1336         return idx;
1337 }
1338
1339 /* The stats groups order is opposite to the update_stats() order calls */
1340 const struct mlx5e_stats_grp mlx5e_stats_grps[] = {
1341         {
1342                 .get_num_stats = mlx5e_grp_sw_get_num_stats,
1343                 .fill_strings = mlx5e_grp_sw_fill_strings,
1344                 .fill_stats = mlx5e_grp_sw_fill_stats,
1345                 .update_stats = mlx5e_grp_sw_update_stats,
1346         },
1347         {
1348                 .get_num_stats = mlx5e_grp_q_get_num_stats,
1349                 .fill_strings = mlx5e_grp_q_fill_strings,
1350                 .fill_stats = mlx5e_grp_q_fill_stats,
1351                 .update_stats_mask = MLX5E_NDO_UPDATE_STATS,
1352                 .update_stats = mlx5e_grp_q_update_stats,
1353         },
1354         {
1355                 .get_num_stats = mlx5e_grp_vnic_env_get_num_stats,
1356                 .fill_strings = mlx5e_grp_vnic_env_fill_strings,
1357                 .fill_stats = mlx5e_grp_vnic_env_fill_stats,
1358                 .update_stats = mlx5e_grp_vnic_env_update_stats,
1359         },
1360         {
1361                 .get_num_stats = mlx5e_grp_vport_get_num_stats,
1362                 .fill_strings = mlx5e_grp_vport_fill_strings,
1363                 .fill_stats = mlx5e_grp_vport_fill_stats,
1364                 .update_stats_mask = MLX5E_NDO_UPDATE_STATS,
1365                 .update_stats = mlx5e_grp_vport_update_stats,
1366         },
1367         {
1368                 .get_num_stats = mlx5e_grp_802_3_get_num_stats,
1369                 .fill_strings = mlx5e_grp_802_3_fill_strings,
1370                 .fill_stats = mlx5e_grp_802_3_fill_stats,
1371                 .update_stats_mask = MLX5E_NDO_UPDATE_STATS,
1372                 .update_stats = mlx5e_grp_802_3_update_stats,
1373         },
1374         {
1375                 .get_num_stats = mlx5e_grp_2863_get_num_stats,
1376                 .fill_strings = mlx5e_grp_2863_fill_strings,
1377                 .fill_stats = mlx5e_grp_2863_fill_stats,
1378                 .update_stats = mlx5e_grp_2863_update_stats,
1379         },
1380         {
1381                 .get_num_stats = mlx5e_grp_2819_get_num_stats,
1382                 .fill_strings = mlx5e_grp_2819_fill_strings,
1383                 .fill_stats = mlx5e_grp_2819_fill_stats,
1384                 .update_stats = mlx5e_grp_2819_update_stats,
1385         },
1386         {
1387                 .get_num_stats = mlx5e_grp_phy_get_num_stats,
1388                 .fill_strings = mlx5e_grp_phy_fill_strings,
1389                 .fill_stats = mlx5e_grp_phy_fill_stats,
1390                 .update_stats = mlx5e_grp_phy_update_stats,
1391         },
1392         {
1393                 .get_num_stats = mlx5e_grp_eth_ext_get_num_stats,
1394                 .fill_strings = mlx5e_grp_eth_ext_fill_strings,
1395                 .fill_stats = mlx5e_grp_eth_ext_fill_stats,
1396                 .update_stats = mlx5e_grp_eth_ext_update_stats,
1397         },
1398         {
1399                 .get_num_stats = mlx5e_grp_pcie_get_num_stats,
1400                 .fill_strings = mlx5e_grp_pcie_fill_strings,
1401                 .fill_stats = mlx5e_grp_pcie_fill_stats,
1402                 .update_stats = mlx5e_grp_pcie_update_stats,
1403         },
1404         {
1405                 .get_num_stats = mlx5e_grp_per_prio_get_num_stats,
1406                 .fill_strings = mlx5e_grp_per_prio_fill_strings,
1407                 .fill_stats = mlx5e_grp_per_prio_fill_stats,
1408                 .update_stats = mlx5e_grp_per_prio_update_stats,
1409         },
1410         {
1411                 .get_num_stats = mlx5e_grp_pme_get_num_stats,
1412                 .fill_strings = mlx5e_grp_pme_fill_strings,
1413                 .fill_stats = mlx5e_grp_pme_fill_stats,
1414         },
1415         {
1416                 .get_num_stats = mlx5e_grp_ipsec_get_num_stats,
1417                 .fill_strings = mlx5e_grp_ipsec_fill_strings,
1418                 .fill_stats = mlx5e_grp_ipsec_fill_stats,
1419                 .update_stats = mlx5e_grp_ipsec_update_stats,
1420         },
1421         {
1422                 .get_num_stats = mlx5e_grp_tls_get_num_stats,
1423                 .fill_strings = mlx5e_grp_tls_fill_strings,
1424                 .fill_stats = mlx5e_grp_tls_fill_stats,
1425         },
1426         {
1427                 .get_num_stats = mlx5e_grp_channels_get_num_stats,
1428                 .fill_strings = mlx5e_grp_channels_fill_strings,
1429                 .fill_stats = mlx5e_grp_channels_fill_stats,
1430         }
1431 };
1432
1433 const int mlx5e_num_stats_grps = ARRAY_SIZE(mlx5e_stats_grps);
This page took 0.116498 seconds and 4 git commands to generate.