]> Git Repo - linux.git/blob - drivers/net/ethernet/mellanox/mlx5/core/en_stats.c
efi/x86: add headroom to decompressor BSS to account for setup block
[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 "lib/mlx5.h"
34 #include "en.h"
35 #include "en_accel/ipsec.h"
36 #include "en_accel/tls.h"
37
38 static unsigned int stats_grps_num(struct mlx5e_priv *priv)
39 {
40         return !priv->profile->stats_grps_num ? 0 :
41                 priv->profile->stats_grps_num(priv);
42 }
43
44 unsigned int mlx5e_stats_total_num(struct mlx5e_priv *priv)
45 {
46         mlx5e_stats_grp_t *stats_grps = priv->profile->stats_grps;
47         const unsigned int num_stats_grps = stats_grps_num(priv);
48         unsigned int total = 0;
49         int i;
50
51         for (i = 0; i < num_stats_grps; i++)
52                 total += stats_grps[i]->get_num_stats(priv);
53
54         return total;
55 }
56
57 void mlx5e_stats_update(struct mlx5e_priv *priv)
58 {
59         mlx5e_stats_grp_t *stats_grps = priv->profile->stats_grps;
60         const unsigned int num_stats_grps = stats_grps_num(priv);
61         int i;
62
63         for (i = num_stats_grps - 1; i >= 0; i--)
64                 if (stats_grps[i]->update_stats)
65                         stats_grps[i]->update_stats(priv);
66 }
67
68 void mlx5e_stats_fill(struct mlx5e_priv *priv, u64 *data, int idx)
69 {
70         mlx5e_stats_grp_t *stats_grps = priv->profile->stats_grps;
71         const unsigned int num_stats_grps = stats_grps_num(priv);
72         int i;
73
74         for (i = 0; i < num_stats_grps; i++)
75                 idx = stats_grps[i]->fill_stats(priv, data, idx);
76 }
77
78 void mlx5e_stats_fill_strings(struct mlx5e_priv *priv, u8 *data)
79 {
80         mlx5e_stats_grp_t *stats_grps = priv->profile->stats_grps;
81         const unsigned int num_stats_grps = stats_grps_num(priv);
82         int i, idx = 0;
83
84         for (i = 0; i < num_stats_grps; i++)
85                 idx = stats_grps[i]->fill_strings(priv, data, idx);
86 }
87
88 /* Concrete NIC Stats */
89
90 static const struct counter_desc sw_stats_desc[] = {
91         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
92         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
93         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
94         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
95         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_packets) },
96         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_bytes) },
97         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_packets) },
98         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_bytes) },
99         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_added_vlan_packets) },
100         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_nop) },
101
102 #ifdef CONFIG_MLX5_EN_TLS
103         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_encrypted_packets) },
104         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_encrypted_bytes) },
105         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ctx) },
106         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_ooo) },
107         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_packets) },
108         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_dump_bytes) },
109         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_resync_bytes) },
110         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_skip_no_sync_data) },
111         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_no_sync_data) },
112         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tls_drop_bypass_req) },
113 #endif
114
115         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) },
116         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_bytes) },
117         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_ecn_mark) },
118         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_removed_vlan_packets) },
119         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary) },
120         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
121         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_complete) },
122         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_complete_tail) },
123         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_complete_tail_slow) },
124         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary_inner) },
125         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_drop) },
126         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_redirect) },
127         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_xmit) },
128         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_mpwqe) },
129         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_inlnw) },
130         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_nops) },
131         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_full) },
132         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_err) },
133         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_cqe) },
134         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_none) },
135         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial) },
136         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial_inner) },
137         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
138         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
139         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xmit_more) },
140         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_recover) },
141         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_cqes) },
142         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
143         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_cqe_err) },
144         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_xmit) },
145         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_mpwqe) },
146         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_inlnw) },
147         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_nops) },
148         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_full) },
149         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_err) },
150         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xdp_cqes) },
151         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
152         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler_cqes) },
153         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler_strides) },
154         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_oversize_pkts_sw_drop) },
155         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
156         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_blks) },
157         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_pkts) },
158         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_reuse) },
159         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_full) },
160         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_empty) },
161         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_busy) },
162         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_waive) },
163         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_congst_umr) },
164         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_arfs_err) },
165         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_recover) },
166         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_events) },
167         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_poll) },
168         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_arm) },
169         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_aff_change) },
170         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_force_irq) },
171         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, ch_eq_rearm) },
172         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_packets) },
173         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_bytes) },
174         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_csum_complete) },
175         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_csum_unnecessary) },
176         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_csum_unnecessary_inner) },
177         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_csum_none) },
178         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_ecn_mark) },
179         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_removed_vlan_packets) },
180         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_xdp_drop) },
181         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_xdp_redirect) },
182         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_wqe_err) },
183         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_mpwqe_filler_cqes) },
184         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_mpwqe_filler_strides) },
185         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_oversize_pkts_sw_drop) },
186         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_buff_alloc_err) },
187         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_cqe_compress_blks) },
188         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_cqe_compress_pkts) },
189         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_congst_umr) },
190         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xsk_arfs_err) },
191         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_xmit) },
192         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_mpwqe) },
193         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_inlnw) },
194         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_full) },
195         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_err) },
196         { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xsk_cqes) },
197 };
198
199 #define NUM_SW_COUNTERS                 ARRAY_SIZE(sw_stats_desc)
200
201 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(sw)
202 {
203         return NUM_SW_COUNTERS;
204 }
205
206 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(sw)
207 {
208         int i;
209
210         for (i = 0; i < NUM_SW_COUNTERS; i++)
211                 strcpy(data + (idx++) * ETH_GSTRING_LEN, sw_stats_desc[i].format);
212         return idx;
213 }
214
215 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(sw)
216 {
217         int i;
218
219         for (i = 0; i < NUM_SW_COUNTERS; i++)
220                 data[idx++] = MLX5E_READ_CTR64_CPU(&priv->stats.sw, sw_stats_desc, i);
221         return idx;
222 }
223
224 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(sw)
225 {
226         struct mlx5e_sw_stats *s = &priv->stats.sw;
227         int i;
228
229         memset(s, 0, sizeof(*s));
230
231         for (i = 0; i < priv->max_nch; i++) {
232                 struct mlx5e_channel_stats *channel_stats =
233                         &priv->channel_stats[i];
234                 struct mlx5e_xdpsq_stats *xdpsq_red_stats = &channel_stats->xdpsq;
235                 struct mlx5e_xdpsq_stats *xdpsq_stats = &channel_stats->rq_xdpsq;
236                 struct mlx5e_xdpsq_stats *xsksq_stats = &channel_stats->xsksq;
237                 struct mlx5e_rq_stats *xskrq_stats = &channel_stats->xskrq;
238                 struct mlx5e_rq_stats *rq_stats = &channel_stats->rq;
239                 struct mlx5e_ch_stats *ch_stats = &channel_stats->ch;
240                 int j;
241
242                 s->rx_packets   += rq_stats->packets;
243                 s->rx_bytes     += rq_stats->bytes;
244                 s->rx_lro_packets += rq_stats->lro_packets;
245                 s->rx_lro_bytes += rq_stats->lro_bytes;
246                 s->rx_ecn_mark  += rq_stats->ecn_mark;
247                 s->rx_removed_vlan_packets += rq_stats->removed_vlan_packets;
248                 s->rx_csum_none += rq_stats->csum_none;
249                 s->rx_csum_complete += rq_stats->csum_complete;
250                 s->rx_csum_complete_tail += rq_stats->csum_complete_tail;
251                 s->rx_csum_complete_tail_slow += rq_stats->csum_complete_tail_slow;
252                 s->rx_csum_unnecessary += rq_stats->csum_unnecessary;
253                 s->rx_csum_unnecessary_inner += rq_stats->csum_unnecessary_inner;
254                 s->rx_xdp_drop     += rq_stats->xdp_drop;
255                 s->rx_xdp_redirect += rq_stats->xdp_redirect;
256                 s->rx_xdp_tx_xmit  += xdpsq_stats->xmit;
257                 s->rx_xdp_tx_mpwqe += xdpsq_stats->mpwqe;
258                 s->rx_xdp_tx_inlnw += xdpsq_stats->inlnw;
259                 s->rx_xdp_tx_nops  += xdpsq_stats->nops;
260                 s->rx_xdp_tx_full  += xdpsq_stats->full;
261                 s->rx_xdp_tx_err   += xdpsq_stats->err;
262                 s->rx_xdp_tx_cqe   += xdpsq_stats->cqes;
263                 s->rx_wqe_err   += rq_stats->wqe_err;
264                 s->rx_mpwqe_filler_cqes    += rq_stats->mpwqe_filler_cqes;
265                 s->rx_mpwqe_filler_strides += rq_stats->mpwqe_filler_strides;
266                 s->rx_oversize_pkts_sw_drop += rq_stats->oversize_pkts_sw_drop;
267                 s->rx_buff_alloc_err += rq_stats->buff_alloc_err;
268                 s->rx_cqe_compress_blks += rq_stats->cqe_compress_blks;
269                 s->rx_cqe_compress_pkts += rq_stats->cqe_compress_pkts;
270                 s->rx_cache_reuse += rq_stats->cache_reuse;
271                 s->rx_cache_full  += rq_stats->cache_full;
272                 s->rx_cache_empty += rq_stats->cache_empty;
273                 s->rx_cache_busy  += rq_stats->cache_busy;
274                 s->rx_cache_waive += rq_stats->cache_waive;
275                 s->rx_congst_umr  += rq_stats->congst_umr;
276                 s->rx_arfs_err    += rq_stats->arfs_err;
277                 s->rx_recover     += rq_stats->recover;
278                 s->ch_events      += ch_stats->events;
279                 s->ch_poll        += ch_stats->poll;
280                 s->ch_arm         += ch_stats->arm;
281                 s->ch_aff_change  += ch_stats->aff_change;
282                 s->ch_force_irq   += ch_stats->force_irq;
283                 s->ch_eq_rearm    += ch_stats->eq_rearm;
284                 /* xdp redirect */
285                 s->tx_xdp_xmit    += xdpsq_red_stats->xmit;
286                 s->tx_xdp_mpwqe   += xdpsq_red_stats->mpwqe;
287                 s->tx_xdp_inlnw   += xdpsq_red_stats->inlnw;
288                 s->tx_xdp_nops    += xdpsq_red_stats->nops;
289                 s->tx_xdp_full    += xdpsq_red_stats->full;
290                 s->tx_xdp_err     += xdpsq_red_stats->err;
291                 s->tx_xdp_cqes    += xdpsq_red_stats->cqes;
292                 /* AF_XDP zero-copy */
293                 s->rx_xsk_packets                += xskrq_stats->packets;
294                 s->rx_xsk_bytes                  += xskrq_stats->bytes;
295                 s->rx_xsk_csum_complete          += xskrq_stats->csum_complete;
296                 s->rx_xsk_csum_unnecessary       += xskrq_stats->csum_unnecessary;
297                 s->rx_xsk_csum_unnecessary_inner += xskrq_stats->csum_unnecessary_inner;
298                 s->rx_xsk_csum_none              += xskrq_stats->csum_none;
299                 s->rx_xsk_ecn_mark               += xskrq_stats->ecn_mark;
300                 s->rx_xsk_removed_vlan_packets   += xskrq_stats->removed_vlan_packets;
301                 s->rx_xsk_xdp_drop               += xskrq_stats->xdp_drop;
302                 s->rx_xsk_xdp_redirect           += xskrq_stats->xdp_redirect;
303                 s->rx_xsk_wqe_err                += xskrq_stats->wqe_err;
304                 s->rx_xsk_mpwqe_filler_cqes      += xskrq_stats->mpwqe_filler_cqes;
305                 s->rx_xsk_mpwqe_filler_strides   += xskrq_stats->mpwqe_filler_strides;
306                 s->rx_xsk_oversize_pkts_sw_drop  += xskrq_stats->oversize_pkts_sw_drop;
307                 s->rx_xsk_buff_alloc_err         += xskrq_stats->buff_alloc_err;
308                 s->rx_xsk_cqe_compress_blks      += xskrq_stats->cqe_compress_blks;
309                 s->rx_xsk_cqe_compress_pkts      += xskrq_stats->cqe_compress_pkts;
310                 s->rx_xsk_congst_umr             += xskrq_stats->congst_umr;
311                 s->rx_xsk_arfs_err               += xskrq_stats->arfs_err;
312                 s->tx_xsk_xmit                   += xsksq_stats->xmit;
313                 s->tx_xsk_mpwqe                  += xsksq_stats->mpwqe;
314                 s->tx_xsk_inlnw                  += xsksq_stats->inlnw;
315                 s->tx_xsk_full                   += xsksq_stats->full;
316                 s->tx_xsk_err                    += xsksq_stats->err;
317                 s->tx_xsk_cqes                   += xsksq_stats->cqes;
318
319                 for (j = 0; j < priv->max_opened_tc; j++) {
320                         struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j];
321
322                         s->tx_packets           += sq_stats->packets;
323                         s->tx_bytes             += sq_stats->bytes;
324                         s->tx_tso_packets       += sq_stats->tso_packets;
325                         s->tx_tso_bytes         += sq_stats->tso_bytes;
326                         s->tx_tso_inner_packets += sq_stats->tso_inner_packets;
327                         s->tx_tso_inner_bytes   += sq_stats->tso_inner_bytes;
328                         s->tx_added_vlan_packets += sq_stats->added_vlan_packets;
329                         s->tx_nop               += sq_stats->nop;
330                         s->tx_queue_stopped     += sq_stats->stopped;
331                         s->tx_queue_wake        += sq_stats->wake;
332                         s->tx_queue_dropped     += sq_stats->dropped;
333                         s->tx_cqe_err           += sq_stats->cqe_err;
334                         s->tx_recover           += sq_stats->recover;
335                         s->tx_xmit_more         += sq_stats->xmit_more;
336                         s->tx_csum_partial_inner += sq_stats->csum_partial_inner;
337                         s->tx_csum_none         += sq_stats->csum_none;
338                         s->tx_csum_partial      += sq_stats->csum_partial;
339 #ifdef CONFIG_MLX5_EN_TLS
340                         s->tx_tls_encrypted_packets += sq_stats->tls_encrypted_packets;
341                         s->tx_tls_encrypted_bytes   += sq_stats->tls_encrypted_bytes;
342                         s->tx_tls_ctx               += sq_stats->tls_ctx;
343                         s->tx_tls_ooo               += sq_stats->tls_ooo;
344                         s->tx_tls_dump_bytes        += sq_stats->tls_dump_bytes;
345                         s->tx_tls_dump_packets      += sq_stats->tls_dump_packets;
346                         s->tx_tls_resync_bytes      += sq_stats->tls_resync_bytes;
347                         s->tx_tls_skip_no_sync_data += sq_stats->tls_skip_no_sync_data;
348                         s->tx_tls_drop_no_sync_data += sq_stats->tls_drop_no_sync_data;
349                         s->tx_tls_drop_bypass_req   += sq_stats->tls_drop_bypass_req;
350 #endif
351                         s->tx_cqes              += sq_stats->cqes;
352
353                         /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92657 */
354                         barrier();
355                 }
356         }
357 }
358
359 static const struct counter_desc q_stats_desc[] = {
360         { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
361 };
362
363 static const struct counter_desc drop_rq_stats_desc[] = {
364         { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_if_down_packets) },
365 };
366
367 #define NUM_Q_COUNTERS                  ARRAY_SIZE(q_stats_desc)
368 #define NUM_DROP_RQ_COUNTERS            ARRAY_SIZE(drop_rq_stats_desc)
369
370 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(qcnt)
371 {
372         int num_stats = 0;
373
374         if (priv->q_counter)
375                 num_stats += NUM_Q_COUNTERS;
376
377         if (priv->drop_rq_q_counter)
378                 num_stats += NUM_DROP_RQ_COUNTERS;
379
380         return num_stats;
381 }
382
383 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(qcnt)
384 {
385         int i;
386
387         for (i = 0; i < NUM_Q_COUNTERS && priv->q_counter; i++)
388                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
389                        q_stats_desc[i].format);
390
391         for (i = 0; i < NUM_DROP_RQ_COUNTERS && priv->drop_rq_q_counter; i++)
392                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
393                        drop_rq_stats_desc[i].format);
394
395         return idx;
396 }
397
398 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(qcnt)
399 {
400         int i;
401
402         for (i = 0; i < NUM_Q_COUNTERS && priv->q_counter; i++)
403                 data[idx++] = MLX5E_READ_CTR32_CPU(&priv->stats.qcnt,
404                                                    q_stats_desc, i);
405         for (i = 0; i < NUM_DROP_RQ_COUNTERS && priv->drop_rq_q_counter; i++)
406                 data[idx++] = MLX5E_READ_CTR32_CPU(&priv->stats.qcnt,
407                                                    drop_rq_stats_desc, i);
408         return idx;
409 }
410
411 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(qcnt)
412 {
413         struct mlx5e_qcounter_stats *qcnt = &priv->stats.qcnt;
414         u32 out[MLX5_ST_SZ_DW(query_q_counter_out)];
415
416         if (priv->q_counter &&
417             !mlx5_core_query_q_counter(priv->mdev, priv->q_counter, 0, out,
418                                        sizeof(out)))
419                 qcnt->rx_out_of_buffer = MLX5_GET(query_q_counter_out,
420                                                   out, out_of_buffer);
421         if (priv->drop_rq_q_counter &&
422             !mlx5_core_query_q_counter(priv->mdev, priv->drop_rq_q_counter, 0,
423                                        out, sizeof(out)))
424                 qcnt->rx_if_down_packets = MLX5_GET(query_q_counter_out, out,
425                                                     out_of_buffer);
426 }
427
428 #define VNIC_ENV_OFF(c) MLX5_BYTE_OFF(query_vnic_env_out, c)
429 static const struct counter_desc vnic_env_stats_steer_desc[] = {
430         { "rx_steer_missed_packets",
431                 VNIC_ENV_OFF(vport_env.nic_receive_steering_discard) },
432 };
433
434 static const struct counter_desc vnic_env_stats_dev_oob_desc[] = {
435         { "dev_internal_queue_oob",
436                 VNIC_ENV_OFF(vport_env.internal_rq_out_of_buffer) },
437 };
438
439 #define NUM_VNIC_ENV_STEER_COUNTERS(dev) \
440         (MLX5_CAP_GEN(dev, nic_receive_steering_discard) ? \
441          ARRAY_SIZE(vnic_env_stats_steer_desc) : 0)
442 #define NUM_VNIC_ENV_DEV_OOB_COUNTERS(dev) \
443         (MLX5_CAP_GEN(dev, vnic_env_int_rq_oob) ? \
444          ARRAY_SIZE(vnic_env_stats_dev_oob_desc) : 0)
445
446 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(vnic_env)
447 {
448         return NUM_VNIC_ENV_STEER_COUNTERS(priv->mdev) +
449                 NUM_VNIC_ENV_DEV_OOB_COUNTERS(priv->mdev);
450 }
451
452 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(vnic_env)
453 {
454         int i;
455
456         for (i = 0; i < NUM_VNIC_ENV_STEER_COUNTERS(priv->mdev); i++)
457                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
458                        vnic_env_stats_steer_desc[i].format);
459
460         for (i = 0; i < NUM_VNIC_ENV_DEV_OOB_COUNTERS(priv->mdev); i++)
461                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
462                        vnic_env_stats_dev_oob_desc[i].format);
463         return idx;
464 }
465
466 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(vnic_env)
467 {
468         int i;
469
470         for (i = 0; i < NUM_VNIC_ENV_STEER_COUNTERS(priv->mdev); i++)
471                 data[idx++] = MLX5E_READ_CTR64_BE(priv->stats.vnic.query_vnic_env_out,
472                                                   vnic_env_stats_steer_desc, i);
473
474         for (i = 0; i < NUM_VNIC_ENV_DEV_OOB_COUNTERS(priv->mdev); i++)
475                 data[idx++] = MLX5E_READ_CTR32_BE(priv->stats.vnic.query_vnic_env_out,
476                                                   vnic_env_stats_dev_oob_desc, i);
477         return idx;
478 }
479
480 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vnic_env)
481 {
482         u32 *out = (u32 *)priv->stats.vnic.query_vnic_env_out;
483         int outlen = MLX5_ST_SZ_BYTES(query_vnic_env_out);
484         u32 in[MLX5_ST_SZ_DW(query_vnic_env_in)] = {0};
485         struct mlx5_core_dev *mdev = priv->mdev;
486
487         if (!MLX5_CAP_GEN(priv->mdev, nic_receive_steering_discard))
488                 return;
489
490         MLX5_SET(query_vnic_env_in, in, opcode,
491                  MLX5_CMD_OP_QUERY_VNIC_ENV);
492         MLX5_SET(query_vnic_env_in, in, op_mod, 0);
493         MLX5_SET(query_vnic_env_in, in, other_vport, 0);
494         mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
495 }
496
497 #define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
498 static const struct counter_desc vport_stats_desc[] = {
499         { "rx_vport_unicast_packets",
500                 VPORT_COUNTER_OFF(received_eth_unicast.packets) },
501         { "rx_vport_unicast_bytes",
502                 VPORT_COUNTER_OFF(received_eth_unicast.octets) },
503         { "tx_vport_unicast_packets",
504                 VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
505         { "tx_vport_unicast_bytes",
506                 VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
507         { "rx_vport_multicast_packets",
508                 VPORT_COUNTER_OFF(received_eth_multicast.packets) },
509         { "rx_vport_multicast_bytes",
510                 VPORT_COUNTER_OFF(received_eth_multicast.octets) },
511         { "tx_vport_multicast_packets",
512                 VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
513         { "tx_vport_multicast_bytes",
514                 VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
515         { "rx_vport_broadcast_packets",
516                 VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
517         { "rx_vport_broadcast_bytes",
518                 VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
519         { "tx_vport_broadcast_packets",
520                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
521         { "tx_vport_broadcast_bytes",
522                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
523         { "rx_vport_rdma_unicast_packets",
524                 VPORT_COUNTER_OFF(received_ib_unicast.packets) },
525         { "rx_vport_rdma_unicast_bytes",
526                 VPORT_COUNTER_OFF(received_ib_unicast.octets) },
527         { "tx_vport_rdma_unicast_packets",
528                 VPORT_COUNTER_OFF(transmitted_ib_unicast.packets) },
529         { "tx_vport_rdma_unicast_bytes",
530                 VPORT_COUNTER_OFF(transmitted_ib_unicast.octets) },
531         { "rx_vport_rdma_multicast_packets",
532                 VPORT_COUNTER_OFF(received_ib_multicast.packets) },
533         { "rx_vport_rdma_multicast_bytes",
534                 VPORT_COUNTER_OFF(received_ib_multicast.octets) },
535         { "tx_vport_rdma_multicast_packets",
536                 VPORT_COUNTER_OFF(transmitted_ib_multicast.packets) },
537         { "tx_vport_rdma_multicast_bytes",
538                 VPORT_COUNTER_OFF(transmitted_ib_multicast.octets) },
539 };
540
541 #define NUM_VPORT_COUNTERS              ARRAY_SIZE(vport_stats_desc)
542
543 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(vport)
544 {
545         return NUM_VPORT_COUNTERS;
546 }
547
548 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(vport)
549 {
550         int i;
551
552         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
553                 strcpy(data + (idx++) * ETH_GSTRING_LEN, vport_stats_desc[i].format);
554         return idx;
555 }
556
557 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(vport)
558 {
559         int i;
560
561         for (i = 0; i < NUM_VPORT_COUNTERS; i++)
562                 data[idx++] = MLX5E_READ_CTR64_BE(priv->stats.vport.query_vport_out,
563                                                   vport_stats_desc, i);
564         return idx;
565 }
566
567 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(vport)
568 {
569         int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
570         u32 *out = (u32 *)priv->stats.vport.query_vport_out;
571         u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)] = {0};
572         struct mlx5_core_dev *mdev = priv->mdev;
573
574         MLX5_SET(query_vport_counter_in, in, opcode, MLX5_CMD_OP_QUERY_VPORT_COUNTER);
575         MLX5_SET(query_vport_counter_in, in, op_mod, 0);
576         MLX5_SET(query_vport_counter_in, in, other_vport, 0);
577         mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
578 }
579
580 #define PPORT_802_3_OFF(c) \
581         MLX5_BYTE_OFF(ppcnt_reg, \
582                       counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
583 static const struct counter_desc pport_802_3_stats_desc[] = {
584         { "tx_packets_phy", PPORT_802_3_OFF(a_frames_transmitted_ok) },
585         { "rx_packets_phy", PPORT_802_3_OFF(a_frames_received_ok) },
586         { "rx_crc_errors_phy", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
587         { "tx_bytes_phy", PPORT_802_3_OFF(a_octets_transmitted_ok) },
588         { "rx_bytes_phy", PPORT_802_3_OFF(a_octets_received_ok) },
589         { "tx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
590         { "tx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
591         { "rx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
592         { "rx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
593         { "rx_in_range_len_errors_phy", PPORT_802_3_OFF(a_in_range_length_errors) },
594         { "rx_out_of_range_len_phy", PPORT_802_3_OFF(a_out_of_range_length_field) },
595         { "rx_oversize_pkts_phy", PPORT_802_3_OFF(a_frame_too_long_errors) },
596         { "rx_symbol_err_phy", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
597         { "tx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
598         { "rx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_received) },
599         { "rx_unsupported_op_phy", PPORT_802_3_OFF(a_unsupported_opcodes_received) },
600         { "rx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
601         { "tx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
602 };
603
604 #define NUM_PPORT_802_3_COUNTERS        ARRAY_SIZE(pport_802_3_stats_desc)
605
606 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(802_3)
607 {
608         return NUM_PPORT_802_3_COUNTERS;
609 }
610
611 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(802_3)
612 {
613         int i;
614
615         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
616                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_802_3_stats_desc[i].format);
617         return idx;
618 }
619
620 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(802_3)
621 {
622         int i;
623
624         for (i = 0; i < NUM_PPORT_802_3_COUNTERS; i++)
625                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.IEEE_802_3_counters,
626                                                   pport_802_3_stats_desc, i);
627         return idx;
628 }
629
630 #define MLX5_BASIC_PPCNT_SUPPORTED(mdev) \
631         (MLX5_CAP_GEN(mdev, pcam_reg) ? MLX5_CAP_PCAM_REG(mdev, ppcnt) : 1)
632
633 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(802_3)
634 {
635         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
636         struct mlx5_core_dev *mdev = priv->mdev;
637         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
638         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
639         void *out;
640
641         if (!MLX5_BASIC_PPCNT_SUPPORTED(mdev))
642                 return;
643
644         MLX5_SET(ppcnt_reg, in, local_port, 1);
645         out = pstats->IEEE_802_3_counters;
646         MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP);
647         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
648 }
649
650 #define PPORT_2863_OFF(c) \
651         MLX5_BYTE_OFF(ppcnt_reg, \
652                       counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
653 static const struct counter_desc pport_2863_stats_desc[] = {
654         { "rx_discards_phy", PPORT_2863_OFF(if_in_discards) },
655         { "tx_discards_phy", PPORT_2863_OFF(if_out_discards) },
656         { "tx_errors_phy", PPORT_2863_OFF(if_out_errors) },
657 };
658
659 #define NUM_PPORT_2863_COUNTERS         ARRAY_SIZE(pport_2863_stats_desc)
660
661 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(2863)
662 {
663         return NUM_PPORT_2863_COUNTERS;
664 }
665
666 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(2863)
667 {
668         int i;
669
670         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
671                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_2863_stats_desc[i].format);
672         return idx;
673 }
674
675 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(2863)
676 {
677         int i;
678
679         for (i = 0; i < NUM_PPORT_2863_COUNTERS; i++)
680                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2863_counters,
681                                                   pport_2863_stats_desc, i);
682         return idx;
683 }
684
685 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(2863)
686 {
687         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
688         struct mlx5_core_dev *mdev = priv->mdev;
689         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
690         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
691         void *out;
692
693         MLX5_SET(ppcnt_reg, in, local_port, 1);
694         out = pstats->RFC_2863_counters;
695         MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2863_COUNTERS_GROUP);
696         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
697 }
698
699 #define PPORT_2819_OFF(c) \
700         MLX5_BYTE_OFF(ppcnt_reg, \
701                       counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
702 static const struct counter_desc pport_2819_stats_desc[] = {
703         { "rx_undersize_pkts_phy", PPORT_2819_OFF(ether_stats_undersize_pkts) },
704         { "rx_fragments_phy", PPORT_2819_OFF(ether_stats_fragments) },
705         { "rx_jabbers_phy", PPORT_2819_OFF(ether_stats_jabbers) },
706         { "rx_64_bytes_phy", PPORT_2819_OFF(ether_stats_pkts64octets) },
707         { "rx_65_to_127_bytes_phy", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
708         { "rx_128_to_255_bytes_phy", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
709         { "rx_256_to_511_bytes_phy", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
710         { "rx_512_to_1023_bytes_phy", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
711         { "rx_1024_to_1518_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
712         { "rx_1519_to_2047_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
713         { "rx_2048_to_4095_bytes_phy", PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
714         { "rx_4096_to_8191_bytes_phy", PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
715         { "rx_8192_to_10239_bytes_phy", PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
716 };
717
718 #define NUM_PPORT_2819_COUNTERS         ARRAY_SIZE(pport_2819_stats_desc)
719
720 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(2819)
721 {
722         return NUM_PPORT_2819_COUNTERS;
723 }
724
725 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(2819)
726 {
727         int i;
728
729         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
730                 strcpy(data + (idx++) * ETH_GSTRING_LEN, pport_2819_stats_desc[i].format);
731         return idx;
732 }
733
734 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(2819)
735 {
736         int i;
737
738         for (i = 0; i < NUM_PPORT_2819_COUNTERS; i++)
739                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.RFC_2819_counters,
740                                                   pport_2819_stats_desc, i);
741         return idx;
742 }
743
744 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(2819)
745 {
746         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
747         struct mlx5_core_dev *mdev = priv->mdev;
748         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
749         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
750         void *out;
751
752         if (!MLX5_BASIC_PPCNT_SUPPORTED(mdev))
753                 return;
754
755         MLX5_SET(ppcnt_reg, in, local_port, 1);
756         out = pstats->RFC_2819_counters;
757         MLX5_SET(ppcnt_reg, in, grp, MLX5_RFC_2819_COUNTERS_GROUP);
758         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
759 }
760
761 #define PPORT_PHY_STATISTICAL_OFF(c) \
762         MLX5_BYTE_OFF(ppcnt_reg, \
763                       counter_set.phys_layer_statistical_cntrs.c##_high)
764 static const struct counter_desc pport_phy_statistical_stats_desc[] = {
765         { "rx_pcs_symbol_err_phy", PPORT_PHY_STATISTICAL_OFF(phy_symbol_errors) },
766         { "rx_corrected_bits_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits) },
767 };
768
769 static const struct counter_desc
770 pport_phy_statistical_err_lanes_stats_desc[] = {
771         { "rx_err_lane_0_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane0) },
772         { "rx_err_lane_1_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane1) },
773         { "rx_err_lane_2_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane2) },
774         { "rx_err_lane_3_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits_lane3) },
775 };
776
777 #define NUM_PPORT_PHY_STATISTICAL_COUNTERS \
778         ARRAY_SIZE(pport_phy_statistical_stats_desc)
779 #define NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS \
780         ARRAY_SIZE(pport_phy_statistical_err_lanes_stats_desc)
781
782 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(phy)
783 {
784         struct mlx5_core_dev *mdev = priv->mdev;
785         int num_stats;
786
787         /* "1" for link_down_events special counter */
788         num_stats = 1;
789
790         num_stats += MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group) ?
791                      NUM_PPORT_PHY_STATISTICAL_COUNTERS : 0;
792
793         num_stats += MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters) ?
794                      NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS : 0;
795
796         return num_stats;
797 }
798
799 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(phy)
800 {
801         struct mlx5_core_dev *mdev = priv->mdev;
802         int i;
803
804         strcpy(data + (idx++) * ETH_GSTRING_LEN, "link_down_events_phy");
805
806         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
807                 return idx;
808
809         for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
810                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
811                        pport_phy_statistical_stats_desc[i].format);
812
813         if (MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters))
814                 for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS; i++)
815                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
816                                pport_phy_statistical_err_lanes_stats_desc[i].format);
817
818         return idx;
819 }
820
821 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(phy)
822 {
823         struct mlx5_core_dev *mdev = priv->mdev;
824         int i;
825
826         /* link_down_events_phy has special handling since it is not stored in __be64 format */
827         data[idx++] = MLX5_GET(ppcnt_reg, priv->stats.pport.phy_counters,
828                                counter_set.phys_layer_cntrs.link_down_events);
829
830         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
831                 return idx;
832
833         for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_COUNTERS; i++)
834                 data[idx++] =
835                         MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
836                                             pport_phy_statistical_stats_desc, i);
837
838         if (MLX5_CAP_PCAM_FEATURE(mdev, per_lane_error_counters))
839                 for (i = 0; i < NUM_PPORT_PHY_STATISTICAL_PER_LANE_COUNTERS; i++)
840                         data[idx++] =
841                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.phy_statistical_counters,
842                                                     pport_phy_statistical_err_lanes_stats_desc,
843                                                     i);
844         return idx;
845 }
846
847 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(phy)
848 {
849         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
850         struct mlx5_core_dev *mdev = priv->mdev;
851         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
852         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
853         void *out;
854
855         MLX5_SET(ppcnt_reg, in, local_port, 1);
856         out = pstats->phy_counters;
857         MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_COUNTERS_GROUP);
858         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
859
860         if (!MLX5_CAP_PCAM_FEATURE(mdev, ppcnt_statistical_group))
861                 return;
862
863         out = pstats->phy_statistical_counters;
864         MLX5_SET(ppcnt_reg, in, grp, MLX5_PHYSICAL_LAYER_STATISTICAL_GROUP);
865         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
866 }
867
868 #define PPORT_ETH_EXT_OFF(c) \
869         MLX5_BYTE_OFF(ppcnt_reg, \
870                       counter_set.eth_extended_cntrs_grp_data_layout.c##_high)
871 static const struct counter_desc pport_eth_ext_stats_desc[] = {
872         { "rx_buffer_passed_thres_phy", PPORT_ETH_EXT_OFF(rx_buffer_almost_full) },
873 };
874
875 #define NUM_PPORT_ETH_EXT_COUNTERS      ARRAY_SIZE(pport_eth_ext_stats_desc)
876
877 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(eth_ext)
878 {
879         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
880                 return NUM_PPORT_ETH_EXT_COUNTERS;
881
882         return 0;
883 }
884
885 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(eth_ext)
886 {
887         int i;
888
889         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
890                 for (i = 0; i < NUM_PPORT_ETH_EXT_COUNTERS; i++)
891                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
892                                pport_eth_ext_stats_desc[i].format);
893         return idx;
894 }
895
896 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(eth_ext)
897 {
898         int i;
899
900         if (MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
901                 for (i = 0; i < NUM_PPORT_ETH_EXT_COUNTERS; i++)
902                         data[idx++] =
903                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.eth_ext_counters,
904                                                     pport_eth_ext_stats_desc, i);
905         return idx;
906 }
907
908 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(eth_ext)
909 {
910         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
911         struct mlx5_core_dev *mdev = priv->mdev;
912         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
913         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
914         void *out;
915
916         if (!MLX5_CAP_PCAM_FEATURE(mdev, rx_buffer_fullness_counters))
917                 return;
918
919         MLX5_SET(ppcnt_reg, in, local_port, 1);
920         out = pstats->eth_ext_counters;
921         MLX5_SET(ppcnt_reg, in, grp, MLX5_ETHERNET_EXTENDED_COUNTERS_GROUP);
922         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
923 }
924
925 #define PCIE_PERF_OFF(c) \
926         MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c)
927 static const struct counter_desc pcie_perf_stats_desc[] = {
928         { "rx_pci_signal_integrity", PCIE_PERF_OFF(rx_errors) },
929         { "tx_pci_signal_integrity", PCIE_PERF_OFF(tx_errors) },
930 };
931
932 #define PCIE_PERF_OFF64(c) \
933         MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c##_high)
934 static const struct counter_desc pcie_perf_stats_desc64[] = {
935         { "outbound_pci_buffer_overflow", PCIE_PERF_OFF64(tx_overflow_buffer_pkt) },
936 };
937
938 static const struct counter_desc pcie_perf_stall_stats_desc[] = {
939         { "outbound_pci_stalled_rd", PCIE_PERF_OFF(outbound_stalled_reads) },
940         { "outbound_pci_stalled_wr", PCIE_PERF_OFF(outbound_stalled_writes) },
941         { "outbound_pci_stalled_rd_events", PCIE_PERF_OFF(outbound_stalled_reads_events) },
942         { "outbound_pci_stalled_wr_events", PCIE_PERF_OFF(outbound_stalled_writes_events) },
943 };
944
945 #define NUM_PCIE_PERF_COUNTERS          ARRAY_SIZE(pcie_perf_stats_desc)
946 #define NUM_PCIE_PERF_COUNTERS64        ARRAY_SIZE(pcie_perf_stats_desc64)
947 #define NUM_PCIE_PERF_STALL_COUNTERS    ARRAY_SIZE(pcie_perf_stall_stats_desc)
948
949 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(pcie)
950 {
951         int num_stats = 0;
952
953         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
954                 num_stats += NUM_PCIE_PERF_COUNTERS;
955
956         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
957                 num_stats += NUM_PCIE_PERF_COUNTERS64;
958
959         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
960                 num_stats += NUM_PCIE_PERF_STALL_COUNTERS;
961
962         return num_stats;
963 }
964
965 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(pcie)
966 {
967         int i;
968
969         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
970                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS; i++)
971                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
972                                pcie_perf_stats_desc[i].format);
973
974         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
975                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS64; i++)
976                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
977                                pcie_perf_stats_desc64[i].format);
978
979         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
980                 for (i = 0; i < NUM_PCIE_PERF_STALL_COUNTERS; i++)
981                         strcpy(data + (idx++) * ETH_GSTRING_LEN,
982                                pcie_perf_stall_stats_desc[i].format);
983         return idx;
984 }
985
986 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(pcie)
987 {
988         int i;
989
990         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
991                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS; i++)
992                         data[idx++] =
993                                 MLX5E_READ_CTR32_BE(&priv->stats.pcie.pcie_perf_counters,
994                                                     pcie_perf_stats_desc, i);
995
996         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
997                 for (i = 0; i < NUM_PCIE_PERF_COUNTERS64; i++)
998                         data[idx++] =
999                                 MLX5E_READ_CTR64_BE(&priv->stats.pcie.pcie_perf_counters,
1000                                                     pcie_perf_stats_desc64, i);
1001
1002         if (MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
1003                 for (i = 0; i < NUM_PCIE_PERF_STALL_COUNTERS; i++)
1004                         data[idx++] =
1005                                 MLX5E_READ_CTR32_BE(&priv->stats.pcie.pcie_perf_counters,
1006                                                     pcie_perf_stall_stats_desc, i);
1007         return idx;
1008 }
1009
1010 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(pcie)
1011 {
1012         struct mlx5e_pcie_stats *pcie_stats = &priv->stats.pcie;
1013         struct mlx5_core_dev *mdev = priv->mdev;
1014         u32 in[MLX5_ST_SZ_DW(mpcnt_reg)] = {0};
1015         int sz = MLX5_ST_SZ_BYTES(mpcnt_reg);
1016         void *out;
1017
1018         if (!MLX5_CAP_MCAM_FEATURE(mdev, pcie_performance_group))
1019                 return;
1020
1021         out = pcie_stats->pcie_perf_counters;
1022         MLX5_SET(mpcnt_reg, in, grp, MLX5_PCIE_PERFORMANCE_COUNTERS_GROUP);
1023         mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_MPCNT, 0, 0);
1024 }
1025
1026 #define PPORT_PER_TC_PRIO_OFF(c) \
1027         MLX5_BYTE_OFF(ppcnt_reg, \
1028                       counter_set.eth_per_tc_prio_grp_data_layout.c##_high)
1029
1030 static const struct counter_desc pport_per_tc_prio_stats_desc[] = {
1031         { "rx_prio%d_buf_discard", PPORT_PER_TC_PRIO_OFF(no_buffer_discard_uc) },
1032 };
1033
1034 #define NUM_PPORT_PER_TC_PRIO_COUNTERS  ARRAY_SIZE(pport_per_tc_prio_stats_desc)
1035
1036 #define PPORT_PER_TC_CONGEST_PRIO_OFF(c) \
1037         MLX5_BYTE_OFF(ppcnt_reg, \
1038                       counter_set.eth_per_tc_congest_prio_grp_data_layout.c##_high)
1039
1040 static const struct counter_desc pport_per_tc_congest_prio_stats_desc[] = {
1041         { "rx_prio%d_cong_discard", PPORT_PER_TC_CONGEST_PRIO_OFF(wred_discard) },
1042         { "rx_prio%d_marked", PPORT_PER_TC_CONGEST_PRIO_OFF(ecn_marked_tc) },
1043 };
1044
1045 #define NUM_PPORT_PER_TC_CONGEST_PRIO_COUNTERS \
1046         ARRAY_SIZE(pport_per_tc_congest_prio_stats_desc)
1047
1048 static int mlx5e_grp_per_tc_prio_get_num_stats(struct mlx5e_priv *priv)
1049 {
1050         struct mlx5_core_dev *mdev = priv->mdev;
1051
1052         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1053                 return 0;
1054
1055         return NUM_PPORT_PER_TC_PRIO_COUNTERS * NUM_PPORT_PRIO;
1056 }
1057
1058 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(per_port_buff_congest)
1059 {
1060         struct mlx5_core_dev *mdev = priv->mdev;
1061         int i, prio;
1062
1063         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1064                 return idx;
1065
1066         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1067                 for (i = 0; i < NUM_PPORT_PER_TC_PRIO_COUNTERS; i++)
1068                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1069                                 pport_per_tc_prio_stats_desc[i].format, prio);
1070                 for (i = 0; i < NUM_PPORT_PER_TC_CONGEST_PRIO_COUNTERS; i++)
1071                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1072                                 pport_per_tc_congest_prio_stats_desc[i].format, prio);
1073         }
1074
1075         return idx;
1076 }
1077
1078 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(per_port_buff_congest)
1079 {
1080         struct mlx5e_pport_stats *pport = &priv->stats.pport;
1081         struct mlx5_core_dev *mdev = priv->mdev;
1082         int i, prio;
1083
1084         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1085                 return idx;
1086
1087         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1088                 for (i = 0; i < NUM_PPORT_PER_TC_PRIO_COUNTERS; i++)
1089                         data[idx++] =
1090                                 MLX5E_READ_CTR64_BE(&pport->per_tc_prio_counters[prio],
1091                                                     pport_per_tc_prio_stats_desc, i);
1092                 for (i = 0; i < NUM_PPORT_PER_TC_CONGEST_PRIO_COUNTERS ; i++)
1093                         data[idx++] =
1094                                 MLX5E_READ_CTR64_BE(&pport->per_tc_congest_prio_counters[prio],
1095                                                     pport_per_tc_congest_prio_stats_desc, i);
1096         }
1097
1098         return idx;
1099 }
1100
1101 static void mlx5e_grp_per_tc_prio_update_stats(struct mlx5e_priv *priv)
1102 {
1103         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
1104         struct mlx5_core_dev *mdev = priv->mdev;
1105         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {};
1106         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
1107         void *out;
1108         int prio;
1109
1110         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1111                 return;
1112
1113         MLX5_SET(ppcnt_reg, in, pnat, 2);
1114         MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_TRAFFIC_CLASS_COUNTERS_GROUP);
1115         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1116                 out = pstats->per_tc_prio_counters[prio];
1117                 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
1118                 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
1119         }
1120 }
1121
1122 static int mlx5e_grp_per_tc_congest_prio_get_num_stats(struct mlx5e_priv *priv)
1123 {
1124         struct mlx5_core_dev *mdev = priv->mdev;
1125
1126         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1127                 return 0;
1128
1129         return NUM_PPORT_PER_TC_CONGEST_PRIO_COUNTERS * NUM_PPORT_PRIO;
1130 }
1131
1132 static void mlx5e_grp_per_tc_congest_prio_update_stats(struct mlx5e_priv *priv)
1133 {
1134         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
1135         struct mlx5_core_dev *mdev = priv->mdev;
1136         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {};
1137         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
1138         void *out;
1139         int prio;
1140
1141         if (!MLX5_CAP_GEN(mdev, sbcam_reg))
1142                 return;
1143
1144         MLX5_SET(ppcnt_reg, in, pnat, 2);
1145         MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_TRAFFIC_CLASS_CONGESTION_GROUP);
1146         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1147                 out = pstats->per_tc_congest_prio_counters[prio];
1148                 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
1149                 mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0);
1150         }
1151 }
1152
1153 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(per_port_buff_congest)
1154 {
1155         return mlx5e_grp_per_tc_prio_get_num_stats(priv) +
1156                 mlx5e_grp_per_tc_congest_prio_get_num_stats(priv);
1157 }
1158
1159 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(per_port_buff_congest)
1160 {
1161         mlx5e_grp_per_tc_prio_update_stats(priv);
1162         mlx5e_grp_per_tc_congest_prio_update_stats(priv);
1163 }
1164
1165 #define PPORT_PER_PRIO_OFF(c) \
1166         MLX5_BYTE_OFF(ppcnt_reg, \
1167                       counter_set.eth_per_prio_grp_data_layout.c##_high)
1168 static const struct counter_desc pport_per_prio_traffic_stats_desc[] = {
1169         { "rx_prio%d_bytes", PPORT_PER_PRIO_OFF(rx_octets) },
1170         { "rx_prio%d_packets", PPORT_PER_PRIO_OFF(rx_frames) },
1171         { "rx_prio%d_discards", PPORT_PER_PRIO_OFF(rx_discards) },
1172         { "tx_prio%d_bytes", PPORT_PER_PRIO_OFF(tx_octets) },
1173         { "tx_prio%d_packets", PPORT_PER_PRIO_OFF(tx_frames) },
1174 };
1175
1176 #define NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS     ARRAY_SIZE(pport_per_prio_traffic_stats_desc)
1177
1178 static int mlx5e_grp_per_prio_traffic_get_num_stats(void)
1179 {
1180         return NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS * NUM_PPORT_PRIO;
1181 }
1182
1183 static int mlx5e_grp_per_prio_traffic_fill_strings(struct mlx5e_priv *priv,
1184                                                    u8 *data,
1185                                                    int idx)
1186 {
1187         int i, prio;
1188
1189         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1190                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
1191                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1192                                 pport_per_prio_traffic_stats_desc[i].format, prio);
1193         }
1194
1195         return idx;
1196 }
1197
1198 static int mlx5e_grp_per_prio_traffic_fill_stats(struct mlx5e_priv *priv,
1199                                                  u64 *data,
1200                                                  int idx)
1201 {
1202         int i, prio;
1203
1204         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1205                 for (i = 0; i < NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS; i++)
1206                         data[idx++] =
1207                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
1208                                                     pport_per_prio_traffic_stats_desc, i);
1209         }
1210
1211         return idx;
1212 }
1213
1214 static const struct counter_desc pport_per_prio_pfc_stats_desc[] = {
1215         /* %s is "global" or "prio{i}" */
1216         { "rx_%s_pause", PPORT_PER_PRIO_OFF(rx_pause) },
1217         { "rx_%s_pause_duration", PPORT_PER_PRIO_OFF(rx_pause_duration) },
1218         { "tx_%s_pause", PPORT_PER_PRIO_OFF(tx_pause) },
1219         { "tx_%s_pause_duration", PPORT_PER_PRIO_OFF(tx_pause_duration) },
1220         { "rx_%s_pause_transition", PPORT_PER_PRIO_OFF(rx_pause_transition) },
1221 };
1222
1223 static const struct counter_desc pport_pfc_stall_stats_desc[] = {
1224         { "tx_pause_storm_warning_events", PPORT_PER_PRIO_OFF(device_stall_minor_watermark_cnt) },
1225         { "tx_pause_storm_error_events", PPORT_PER_PRIO_OFF(device_stall_critical_watermark_cnt) },
1226 };
1227
1228 #define NUM_PPORT_PER_PRIO_PFC_COUNTERS         ARRAY_SIZE(pport_per_prio_pfc_stats_desc)
1229 #define NUM_PPORT_PFC_STALL_COUNTERS(priv)      (ARRAY_SIZE(pport_pfc_stall_stats_desc) * \
1230                                                  MLX5_CAP_PCAM_FEATURE((priv)->mdev, pfcc_mask) * \
1231                                                  MLX5_CAP_DEBUG((priv)->mdev, stall_detect))
1232
1233 static unsigned long mlx5e_query_pfc_combined(struct mlx5e_priv *priv)
1234 {
1235         struct mlx5_core_dev *mdev = priv->mdev;
1236         u8 pfc_en_tx;
1237         u8 pfc_en_rx;
1238         int err;
1239
1240         if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
1241                 return 0;
1242
1243         err = mlx5_query_port_pfc(mdev, &pfc_en_tx, &pfc_en_rx);
1244
1245         return err ? 0 : pfc_en_tx | pfc_en_rx;
1246 }
1247
1248 static bool mlx5e_query_global_pause_combined(struct mlx5e_priv *priv)
1249 {
1250         struct mlx5_core_dev *mdev = priv->mdev;
1251         u32 rx_pause;
1252         u32 tx_pause;
1253         int err;
1254
1255         if (MLX5_CAP_GEN(mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
1256                 return false;
1257
1258         err = mlx5_query_port_pause(mdev, &rx_pause, &tx_pause);
1259
1260         return err ? false : rx_pause | tx_pause;
1261 }
1262
1263 static int mlx5e_grp_per_prio_pfc_get_num_stats(struct mlx5e_priv *priv)
1264 {
1265         return (mlx5e_query_global_pause_combined(priv) +
1266                 hweight8(mlx5e_query_pfc_combined(priv))) *
1267                 NUM_PPORT_PER_PRIO_PFC_COUNTERS +
1268                 NUM_PPORT_PFC_STALL_COUNTERS(priv);
1269 }
1270
1271 static int mlx5e_grp_per_prio_pfc_fill_strings(struct mlx5e_priv *priv,
1272                                                u8 *data,
1273                                                int idx)
1274 {
1275         unsigned long pfc_combined;
1276         int i, prio;
1277
1278         pfc_combined = mlx5e_query_pfc_combined(priv);
1279         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
1280                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1281                         char pfc_string[ETH_GSTRING_LEN];
1282
1283                         snprintf(pfc_string, sizeof(pfc_string), "prio%d", prio);
1284                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1285                                 pport_per_prio_pfc_stats_desc[i].format, pfc_string);
1286                 }
1287         }
1288
1289         if (mlx5e_query_global_pause_combined(priv)) {
1290                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1291                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1292                                 pport_per_prio_pfc_stats_desc[i].format, "global");
1293                 }
1294         }
1295
1296         for (i = 0; i < NUM_PPORT_PFC_STALL_COUNTERS(priv); i++)
1297                 strcpy(data + (idx++) * ETH_GSTRING_LEN,
1298                        pport_pfc_stall_stats_desc[i].format);
1299
1300         return idx;
1301 }
1302
1303 static int mlx5e_grp_per_prio_pfc_fill_stats(struct mlx5e_priv *priv,
1304                                              u64 *data,
1305                                              int idx)
1306 {
1307         unsigned long pfc_combined;
1308         int i, prio;
1309
1310         pfc_combined = mlx5e_query_pfc_combined(priv);
1311         for_each_set_bit(prio, &pfc_combined, NUM_PPORT_PRIO) {
1312                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1313                         data[idx++] =
1314                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[prio],
1315                                                     pport_per_prio_pfc_stats_desc, i);
1316                 }
1317         }
1318
1319         if (mlx5e_query_global_pause_combined(priv)) {
1320                 for (i = 0; i < NUM_PPORT_PER_PRIO_PFC_COUNTERS; i++) {
1321                         data[idx++] =
1322                                 MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[0],
1323                                                     pport_per_prio_pfc_stats_desc, i);
1324                 }
1325         }
1326
1327         for (i = 0; i < NUM_PPORT_PFC_STALL_COUNTERS(priv); i++)
1328                 data[idx++] = MLX5E_READ_CTR64_BE(&priv->stats.pport.per_prio_counters[0],
1329                                                   pport_pfc_stall_stats_desc, i);
1330
1331         return idx;
1332 }
1333
1334 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(per_prio)
1335 {
1336         return mlx5e_grp_per_prio_traffic_get_num_stats() +
1337                 mlx5e_grp_per_prio_pfc_get_num_stats(priv);
1338 }
1339
1340 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(per_prio)
1341 {
1342         idx = mlx5e_grp_per_prio_traffic_fill_strings(priv, data, idx);
1343         idx = mlx5e_grp_per_prio_pfc_fill_strings(priv, data, idx);
1344         return idx;
1345 }
1346
1347 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(per_prio)
1348 {
1349         idx = mlx5e_grp_per_prio_traffic_fill_stats(priv, data, idx);
1350         idx = mlx5e_grp_per_prio_pfc_fill_stats(priv, data, idx);
1351         return idx;
1352 }
1353
1354 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(per_prio)
1355 {
1356         struct mlx5e_pport_stats *pstats = &priv->stats.pport;
1357         struct mlx5_core_dev *mdev = priv->mdev;
1358         u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0};
1359         int sz = MLX5_ST_SZ_BYTES(ppcnt_reg);
1360         int prio;
1361         void *out;
1362
1363         if (!MLX5_BASIC_PPCNT_SUPPORTED(mdev))
1364                 return;
1365
1366         MLX5_SET(ppcnt_reg, in, local_port, 1);
1367         MLX5_SET(ppcnt_reg, in, grp, MLX5_PER_PRIORITY_COUNTERS_GROUP);
1368         for (prio = 0; prio < NUM_PPORT_PRIO; prio++) {
1369                 out = pstats->per_prio_counters[prio];
1370                 MLX5_SET(ppcnt_reg, in, prio_tc, prio);
1371                 mlx5_core_access_reg(mdev, in, sz, out, sz,
1372                                      MLX5_REG_PPCNT, 0, 0);
1373         }
1374 }
1375
1376 static const struct counter_desc mlx5e_pme_status_desc[] = {
1377         { "module_unplug",       sizeof(u64) * MLX5_MODULE_STATUS_UNPLUGGED },
1378 };
1379
1380 static const struct counter_desc mlx5e_pme_error_desc[] = {
1381         { "module_bus_stuck",    sizeof(u64) * MLX5_MODULE_EVENT_ERROR_BUS_STUCK },
1382         { "module_high_temp",    sizeof(u64) * MLX5_MODULE_EVENT_ERROR_HIGH_TEMPERATURE },
1383         { "module_bad_shorted",  sizeof(u64) * MLX5_MODULE_EVENT_ERROR_BAD_CABLE },
1384 };
1385
1386 #define NUM_PME_STATUS_STATS            ARRAY_SIZE(mlx5e_pme_status_desc)
1387 #define NUM_PME_ERR_STATS               ARRAY_SIZE(mlx5e_pme_error_desc)
1388
1389 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(pme)
1390 {
1391         return NUM_PME_STATUS_STATS + NUM_PME_ERR_STATS;
1392 }
1393
1394 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(pme)
1395 {
1396         int i;
1397
1398         for (i = 0; i < NUM_PME_STATUS_STATS; i++)
1399                 strcpy(data + (idx++) * ETH_GSTRING_LEN, mlx5e_pme_status_desc[i].format);
1400
1401         for (i = 0; i < NUM_PME_ERR_STATS; i++)
1402                 strcpy(data + (idx++) * ETH_GSTRING_LEN, mlx5e_pme_error_desc[i].format);
1403
1404         return idx;
1405 }
1406
1407 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(pme)
1408 {
1409         struct mlx5_pme_stats pme_stats;
1410         int i;
1411
1412         mlx5_get_pme_stats(priv->mdev, &pme_stats);
1413
1414         for (i = 0; i < NUM_PME_STATUS_STATS; i++)
1415                 data[idx++] = MLX5E_READ_CTR64_CPU(pme_stats.status_counters,
1416                                                    mlx5e_pme_status_desc, i);
1417
1418         for (i = 0; i < NUM_PME_ERR_STATS; i++)
1419                 data[idx++] = MLX5E_READ_CTR64_CPU(pme_stats.error_counters,
1420                                                    mlx5e_pme_error_desc, i);
1421
1422         return idx;
1423 }
1424
1425 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(pme) { return; }
1426
1427 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(ipsec)
1428 {
1429         return mlx5e_ipsec_get_count(priv);
1430 }
1431
1432 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ipsec)
1433 {
1434         return idx + mlx5e_ipsec_get_strings(priv,
1435                                              data + idx * ETH_GSTRING_LEN);
1436 }
1437
1438 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(ipsec)
1439 {
1440         return idx + mlx5e_ipsec_get_stats(priv, data + idx);
1441 }
1442
1443 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(ipsec)
1444 {
1445         mlx5e_ipsec_update_stats(priv);
1446 }
1447
1448 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(tls)
1449 {
1450         return mlx5e_tls_get_count(priv);
1451 }
1452
1453 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(tls)
1454 {
1455         return idx + mlx5e_tls_get_strings(priv, data + idx * ETH_GSTRING_LEN);
1456 }
1457
1458 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(tls)
1459 {
1460         return idx + mlx5e_tls_get_stats(priv, data + idx);
1461 }
1462
1463 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(tls) { return; }
1464
1465 static const struct counter_desc rq_stats_desc[] = {
1466         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, packets) },
1467         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, bytes) },
1468         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_complete) },
1469         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_complete_tail) },
1470         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_complete_tail_slow) },
1471         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_unnecessary) },
1472         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_unnecessary_inner) },
1473         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_none) },
1474         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_drop) },
1475         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_redirect) },
1476         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_packets) },
1477         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_bytes) },
1478         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, ecn_mark) },
1479         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, removed_vlan_packets) },
1480         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, wqe_err) },
1481         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, mpwqe_filler_cqes) },
1482         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, mpwqe_filler_strides) },
1483         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, oversize_pkts_sw_drop) },
1484         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
1485         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_blks) },
1486         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_pkts) },
1487         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_reuse) },
1488         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_full) },
1489         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_empty) },
1490         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_busy) },
1491         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_waive) },
1492         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, congst_umr) },
1493         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, arfs_err) },
1494         { MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, recover) },
1495 };
1496
1497 static const struct counter_desc sq_stats_desc[] = {
1498         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, packets) },
1499         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, bytes) },
1500         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_packets) },
1501         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_bytes) },
1502         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
1503         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
1504         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial) },
1505         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial_inner) },
1506         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, added_vlan_packets) },
1507         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, nop) },
1508 #ifdef CONFIG_MLX5_EN_TLS
1509         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_encrypted_packets) },
1510         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_encrypted_bytes) },
1511         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ctx) },
1512         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_ooo) },
1513         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_packets) },
1514         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_dump_bytes) },
1515         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_resync_bytes) },
1516         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_skip_no_sync_data) },
1517         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_no_sync_data) },
1518         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tls_drop_bypass_req) },
1519 #endif
1520         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) },
1521         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) },
1522         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, dropped) },
1523         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, xmit_more) },
1524         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, recover) },
1525         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, cqes) },
1526         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, wake) },
1527         { MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, cqe_err) },
1528 };
1529
1530 static const struct counter_desc rq_xdpsq_stats_desc[] = {
1531         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, xmit) },
1532         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, mpwqe) },
1533         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, inlnw) },
1534         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, nops) },
1535         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, full) },
1536         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, err) },
1537         { MLX5E_DECLARE_RQ_XDPSQ_STAT(struct mlx5e_xdpsq_stats, cqes) },
1538 };
1539
1540 static const struct counter_desc xdpsq_stats_desc[] = {
1541         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, xmit) },
1542         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, mpwqe) },
1543         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, inlnw) },
1544         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, nops) },
1545         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, full) },
1546         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, err) },
1547         { MLX5E_DECLARE_XDPSQ_STAT(struct mlx5e_xdpsq_stats, cqes) },
1548 };
1549
1550 static const struct counter_desc xskrq_stats_desc[] = {
1551         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, packets) },
1552         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, bytes) },
1553         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, csum_complete) },
1554         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, csum_unnecessary) },
1555         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, csum_unnecessary_inner) },
1556         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, csum_none) },
1557         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, ecn_mark) },
1558         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, removed_vlan_packets) },
1559         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, xdp_drop) },
1560         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, xdp_redirect) },
1561         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, wqe_err) },
1562         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, mpwqe_filler_cqes) },
1563         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, mpwqe_filler_strides) },
1564         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, oversize_pkts_sw_drop) },
1565         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
1566         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, cqe_compress_blks) },
1567         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, cqe_compress_pkts) },
1568         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, congst_umr) },
1569         { MLX5E_DECLARE_XSKRQ_STAT(struct mlx5e_rq_stats, arfs_err) },
1570 };
1571
1572 static const struct counter_desc xsksq_stats_desc[] = {
1573         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, xmit) },
1574         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, mpwqe) },
1575         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, inlnw) },
1576         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, full) },
1577         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, err) },
1578         { MLX5E_DECLARE_XSKSQ_STAT(struct mlx5e_xdpsq_stats, cqes) },
1579 };
1580
1581 static const struct counter_desc ch_stats_desc[] = {
1582         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, events) },
1583         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, poll) },
1584         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, arm) },
1585         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, aff_change) },
1586         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, force_irq) },
1587         { MLX5E_DECLARE_CH_STAT(struct mlx5e_ch_stats, eq_rearm) },
1588 };
1589
1590 #define NUM_RQ_STATS                    ARRAY_SIZE(rq_stats_desc)
1591 #define NUM_SQ_STATS                    ARRAY_SIZE(sq_stats_desc)
1592 #define NUM_XDPSQ_STATS                 ARRAY_SIZE(xdpsq_stats_desc)
1593 #define NUM_RQ_XDPSQ_STATS              ARRAY_SIZE(rq_xdpsq_stats_desc)
1594 #define NUM_XSKRQ_STATS                 ARRAY_SIZE(xskrq_stats_desc)
1595 #define NUM_XSKSQ_STATS                 ARRAY_SIZE(xsksq_stats_desc)
1596 #define NUM_CH_STATS                    ARRAY_SIZE(ch_stats_desc)
1597
1598 static MLX5E_DECLARE_STATS_GRP_OP_NUM_STATS(channels)
1599 {
1600         int max_nch = priv->max_nch;
1601
1602         return (NUM_RQ_STATS * max_nch) +
1603                (NUM_CH_STATS * max_nch) +
1604                (NUM_SQ_STATS * max_nch * priv->max_opened_tc) +
1605                (NUM_RQ_XDPSQ_STATS * max_nch) +
1606                (NUM_XDPSQ_STATS * max_nch) +
1607                (NUM_XSKRQ_STATS * max_nch * priv->xsk.ever_used) +
1608                (NUM_XSKSQ_STATS * max_nch * priv->xsk.ever_used);
1609 }
1610
1611 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(channels)
1612 {
1613         bool is_xsk = priv->xsk.ever_used;
1614         int max_nch = priv->max_nch;
1615         int i, j, tc;
1616
1617         for (i = 0; i < max_nch; i++)
1618                 for (j = 0; j < NUM_CH_STATS; j++)
1619                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1620                                 ch_stats_desc[j].format, i);
1621
1622         for (i = 0; i < max_nch; i++) {
1623                 for (j = 0; j < NUM_RQ_STATS; j++)
1624                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1625                                 rq_stats_desc[j].format, i);
1626                 for (j = 0; j < NUM_XSKRQ_STATS * is_xsk; j++)
1627                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1628                                 xskrq_stats_desc[j].format, i);
1629                 for (j = 0; j < NUM_RQ_XDPSQ_STATS; j++)
1630                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1631                                 rq_xdpsq_stats_desc[j].format, i);
1632         }
1633
1634         for (tc = 0; tc < priv->max_opened_tc; tc++)
1635                 for (i = 0; i < max_nch; i++)
1636                         for (j = 0; j < NUM_SQ_STATS; j++)
1637                                 sprintf(data + (idx++) * ETH_GSTRING_LEN,
1638                                         sq_stats_desc[j].format,
1639                                         i + tc * max_nch);
1640
1641         for (i = 0; i < max_nch; i++) {
1642                 for (j = 0; j < NUM_XSKSQ_STATS * is_xsk; j++)
1643                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1644                                 xsksq_stats_desc[j].format, i);
1645                 for (j = 0; j < NUM_XDPSQ_STATS; j++)
1646                         sprintf(data + (idx++) * ETH_GSTRING_LEN,
1647                                 xdpsq_stats_desc[j].format, i);
1648         }
1649
1650         return idx;
1651 }
1652
1653 static MLX5E_DECLARE_STATS_GRP_OP_FILL_STATS(channels)
1654 {
1655         bool is_xsk = priv->xsk.ever_used;
1656         int max_nch = priv->max_nch;
1657         int i, j, tc;
1658
1659         for (i = 0; i < max_nch; i++)
1660                 for (j = 0; j < NUM_CH_STATS; j++)
1661                         data[idx++] =
1662                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].ch,
1663                                                      ch_stats_desc, j);
1664
1665         for (i = 0; i < max_nch; i++) {
1666                 for (j = 0; j < NUM_RQ_STATS; j++)
1667                         data[idx++] =
1668                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].rq,
1669                                                      rq_stats_desc, j);
1670                 for (j = 0; j < NUM_XSKRQ_STATS * is_xsk; j++)
1671                         data[idx++] =
1672                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].xskrq,
1673                                                      xskrq_stats_desc, j);
1674                 for (j = 0; j < NUM_RQ_XDPSQ_STATS; j++)
1675                         data[idx++] =
1676                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].rq_xdpsq,
1677                                                      rq_xdpsq_stats_desc, j);
1678         }
1679
1680         for (tc = 0; tc < priv->max_opened_tc; tc++)
1681                 for (i = 0; i < max_nch; i++)
1682                         for (j = 0; j < NUM_SQ_STATS; j++)
1683                                 data[idx++] =
1684                                         MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].sq[tc],
1685                                                              sq_stats_desc, j);
1686
1687         for (i = 0; i < max_nch; i++) {
1688                 for (j = 0; j < NUM_XSKSQ_STATS * is_xsk; j++)
1689                         data[idx++] =
1690                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].xsksq,
1691                                                      xsksq_stats_desc, j);
1692                 for (j = 0; j < NUM_XDPSQ_STATS; j++)
1693                         data[idx++] =
1694                                 MLX5E_READ_CTR64_CPU(&priv->channel_stats[i].xdpsq,
1695                                                      xdpsq_stats_desc, j);
1696         }
1697
1698         return idx;
1699 }
1700
1701 static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(channels) { return; }
1702
1703 MLX5E_DEFINE_STATS_GRP(sw, 0);
1704 MLX5E_DEFINE_STATS_GRP(qcnt, MLX5E_NDO_UPDATE_STATS);
1705 MLX5E_DEFINE_STATS_GRP(vnic_env, 0);
1706 MLX5E_DEFINE_STATS_GRP(vport, MLX5E_NDO_UPDATE_STATS);
1707 MLX5E_DEFINE_STATS_GRP(802_3, MLX5E_NDO_UPDATE_STATS);
1708 MLX5E_DEFINE_STATS_GRP(2863, 0);
1709 MLX5E_DEFINE_STATS_GRP(2819, 0);
1710 MLX5E_DEFINE_STATS_GRP(phy, 0);
1711 MLX5E_DEFINE_STATS_GRP(pcie, 0);
1712 MLX5E_DEFINE_STATS_GRP(per_prio, 0);
1713 MLX5E_DEFINE_STATS_GRP(pme, 0);
1714 MLX5E_DEFINE_STATS_GRP(channels, 0);
1715 MLX5E_DEFINE_STATS_GRP(per_port_buff_congest, 0);
1716 MLX5E_DEFINE_STATS_GRP(eth_ext, 0);
1717 static MLX5E_DEFINE_STATS_GRP(ipsec, 0);
1718 static MLX5E_DEFINE_STATS_GRP(tls, 0);
1719
1720 /* The stats groups order is opposite to the update_stats() order calls */
1721 mlx5e_stats_grp_t mlx5e_nic_stats_grps[] = {
1722         &MLX5E_STATS_GRP(sw),
1723         &MLX5E_STATS_GRP(qcnt),
1724         &MLX5E_STATS_GRP(vnic_env),
1725         &MLX5E_STATS_GRP(vport),
1726         &MLX5E_STATS_GRP(802_3),
1727         &MLX5E_STATS_GRP(2863),
1728         &MLX5E_STATS_GRP(2819),
1729         &MLX5E_STATS_GRP(phy),
1730         &MLX5E_STATS_GRP(eth_ext),
1731         &MLX5E_STATS_GRP(pcie),
1732         &MLX5E_STATS_GRP(per_prio),
1733         &MLX5E_STATS_GRP(pme),
1734         &MLX5E_STATS_GRP(ipsec),
1735         &MLX5E_STATS_GRP(tls),
1736         &MLX5E_STATS_GRP(channels),
1737         &MLX5E_STATS_GRP(per_port_buff_congest),
1738 };
1739
1740 unsigned int mlx5e_nic_stats_grps_num(struct mlx5e_priv *priv)
1741 {
1742         return ARRAY_SIZE(mlx5e_nic_stats_grps);
1743 }
This page took 0.146801 seconds and 4 git commands to generate.