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