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