19218b44dSGal Pressman /*
29218b44dSGal Pressman  * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
39218b44dSGal Pressman  *
49218b44dSGal Pressman  * This software is available to you under a choice of one of two
59218b44dSGal Pressman  * licenses.  You may choose to be licensed under the terms of the GNU
69218b44dSGal Pressman  * General Public License (GPL) Version 2, available from the file
79218b44dSGal Pressman  * COPYING in the main directory of this source tree, or the
89218b44dSGal Pressman  * OpenIB.org BSD license below:
99218b44dSGal Pressman  *
109218b44dSGal Pressman  *     Redistribution and use in source and binary forms, with or
119218b44dSGal Pressman  *     without modification, are permitted provided that the following
129218b44dSGal Pressman  *     conditions are met:
139218b44dSGal Pressman  *
149218b44dSGal Pressman  *      - Redistributions of source code must retain the above
159218b44dSGal Pressman  *        copyright notice, this list of conditions and the following
169218b44dSGal Pressman  *        disclaimer.
179218b44dSGal Pressman  *
189218b44dSGal Pressman  *      - Redistributions in binary form must reproduce the above
199218b44dSGal Pressman  *        copyright notice, this list of conditions and the following
209218b44dSGal Pressman  *        disclaimer in the documentation and/or other materials
219218b44dSGal Pressman  *        provided with the distribution.
229218b44dSGal Pressman  *
239218b44dSGal Pressman  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
249218b44dSGal Pressman  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
259218b44dSGal Pressman  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
269218b44dSGal Pressman  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
279218b44dSGal Pressman  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
289218b44dSGal Pressman  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
299218b44dSGal Pressman  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
309218b44dSGal Pressman  * SOFTWARE.
319218b44dSGal Pressman  */
329218b44dSGal Pressman #ifndef __MLX5_EN_STATS_H__
339218b44dSGal Pressman #define __MLX5_EN_STATS_H__
349218b44dSGal Pressman 
359218b44dSGal Pressman #define MLX5E_READ_CTR64_CPU(ptr, dsc, i) \
369218b44dSGal Pressman 	(*(u64 *)((char *)ptr + dsc[i].offset))
379218b44dSGal Pressman #define MLX5E_READ_CTR64_BE(ptr, dsc, i) \
389218b44dSGal Pressman 	be64_to_cpu(*(__be64 *)((char *)ptr + dsc[i].offset))
399218b44dSGal Pressman #define MLX5E_READ_CTR32_CPU(ptr, dsc, i) \
409218b44dSGal Pressman 	(*(u32 *)((char *)ptr + dsc[i].offset))
419218b44dSGal Pressman #define MLX5E_READ_CTR32_BE(ptr, dsc, i) \
420f7f3481SGal Pressman 	be32_to_cpu(*(__be32 *)((char *)ptr + dsc[i].offset))
439218b44dSGal Pressman 
449218b44dSGal Pressman #define MLX5E_DECLARE_STAT(type, fld) #fld, offsetof(type, fld)
45bfe6d8d1SGal Pressman #define MLX5E_DECLARE_RX_STAT(type, fld) "rx%d_"#fld, offsetof(type, fld)
46bfe6d8d1SGal Pressman #define MLX5E_DECLARE_TX_STAT(type, fld) "tx%d_"#fld, offsetof(type, fld)
479218b44dSGal Pressman 
489218b44dSGal Pressman struct counter_desc {
49bfe6d8d1SGal Pressman 	char		format[ETH_GSTRING_LEN];
509da5106cSGal Pressman 	size_t		offset; /* Byte offset */
519218b44dSGal Pressman };
529218b44dSGal Pressman 
539218b44dSGal Pressman struct mlx5e_sw_stats {
549218b44dSGal Pressman 	u64 rx_packets;
559218b44dSGal Pressman 	u64 rx_bytes;
569218b44dSGal Pressman 	u64 tx_packets;
579218b44dSGal Pressman 	u64 tx_bytes;
58bfe6d8d1SGal Pressman 	u64 tx_tso_packets;
59bfe6d8d1SGal Pressman 	u64 tx_tso_bytes;
60bfe6d8d1SGal Pressman 	u64 tx_tso_inner_packets;
61bfe6d8d1SGal Pressman 	u64 tx_tso_inner_bytes;
62bfe6d8d1SGal Pressman 	u64 rx_lro_packets;
63bfe6d8d1SGal Pressman 	u64 rx_lro_bytes;
64bfe6d8d1SGal Pressman 	u64 rx_csum_unnecessary;
659218b44dSGal Pressman 	u64 rx_csum_none;
66bfe6d8d1SGal Pressman 	u64 rx_csum_complete;
67bfe6d8d1SGal Pressman 	u64 rx_csum_unnecessary_inner;
6886994156SRana Shahout 	u64 rx_xdp_drop;
69b5503b99SSaeed Mahameed 	u64 rx_xdp_tx;
70b5503b99SSaeed Mahameed 	u64 rx_xdp_tx_full;
71bfe6d8d1SGal Pressman 	u64 tx_csum_partial;
72bfe6d8d1SGal Pressman 	u64 tx_csum_partial_inner;
739218b44dSGal Pressman 	u64 tx_queue_stopped;
749218b44dSGal Pressman 	u64 tx_queue_wake;
759218b44dSGal Pressman 	u64 tx_queue_dropped;
76c8cf78feSTariq Toukan 	u64 tx_xmit_more;
779218b44dSGal Pressman 	u64 rx_wqe_err;
789218b44dSGal Pressman 	u64 rx_mpwqe_filler;
799218b44dSGal Pressman 	u64 rx_buff_alloc_err;
807219ab34STariq Toukan 	u64 rx_cqe_compress_blks;
817219ab34STariq Toukan 	u64 rx_cqe_compress_pkts;
82accd5883STariq Toukan 	u64 rx_page_reuse;
834415a031STariq Toukan 	u64 rx_cache_reuse;
844415a031STariq Toukan 	u64 rx_cache_full;
854415a031STariq Toukan 	u64 rx_cache_empty;
864415a031STariq Toukan 	u64 rx_cache_busy;
87121fcdc8SGal Pressman 
88121fcdc8SGal Pressman 	/* Special handling counters */
89bfe6d8d1SGal Pressman 	u64 link_down_events_phy;
909218b44dSGal Pressman };
919218b44dSGal Pressman 
929218b44dSGal Pressman static const struct counter_desc sw_stats_desc[] = {
939218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
949218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
959218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
969218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
97bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_packets) },
98bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_bytes) },
99bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_packets) },
100bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_tso_inner_bytes) },
101bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_packets) },
102bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_lro_bytes) },
103bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary) },
1049218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
105bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_complete) },
106bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_unnecessary_inner) },
10786994156SRana Shahout 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_drop) },
108b5503b99SSaeed Mahameed 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx) },
109b5503b99SSaeed Mahameed 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_xdp_tx_full) },
110bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial) },
111bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_partial_inner) },
1129218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
1139218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
1149218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
115c8cf78feSTariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_xmit_more) },
1169218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
1179218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler) },
1189218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
1197219ab34STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_blks) },
1207219ab34STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cqe_compress_pkts) },
121accd5883STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_page_reuse) },
1224415a031STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_reuse) },
1234415a031STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_full) },
1244415a031STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_empty) },
1254415a031STariq Toukan 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_cache_busy) },
126bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, link_down_events_phy) },
1279218b44dSGal Pressman };
1289218b44dSGal Pressman 
1299218b44dSGal Pressman struct mlx5e_qcounter_stats {
1309218b44dSGal Pressman 	u32 rx_out_of_buffer;
1319218b44dSGal Pressman };
1329218b44dSGal Pressman 
1339218b44dSGal Pressman static const struct counter_desc q_stats_desc[] = {
1349218b44dSGal Pressman 	{ MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
1359218b44dSGal Pressman };
1369218b44dSGal Pressman 
1379218b44dSGal Pressman #define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
1389218b44dSGal Pressman #define VPORT_COUNTER_GET(vstats, c) MLX5_GET64(query_vport_counter_out, \
1399218b44dSGal Pressman 						vstats->query_vport_out, c)
1409218b44dSGal Pressman 
1419218b44dSGal Pressman struct mlx5e_vport_stats {
1429218b44dSGal Pressman 	__be64 query_vport_out[MLX5_ST_SZ_QW(query_vport_counter_out)];
1439218b44dSGal Pressman };
1449218b44dSGal Pressman 
1459218b44dSGal Pressman static const struct counter_desc vport_stats_desc[] = {
1468075cb72SGal Pressman 	{ "rx_vport_unicast_packets",
1479218b44dSGal Pressman 		VPORT_COUNTER_OFF(received_eth_unicast.packets) },
1488075cb72SGal Pressman 	{ "rx_vport_unicast_bytes",
1498075cb72SGal Pressman 		VPORT_COUNTER_OFF(received_eth_unicast.octets) },
1508075cb72SGal Pressman 	{ "tx_vport_unicast_packets",
1519218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
1528075cb72SGal Pressman 	{ "tx_vport_unicast_bytes",
1539218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
1548075cb72SGal Pressman 	{ "rx_vport_multicast_packets",
1559218b44dSGal Pressman 		VPORT_COUNTER_OFF(received_eth_multicast.packets) },
1568075cb72SGal Pressman 	{ "rx_vport_multicast_bytes",
1579218b44dSGal Pressman 		VPORT_COUNTER_OFF(received_eth_multicast.octets) },
1588075cb72SGal Pressman 	{ "tx_vport_multicast_packets",
1599218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
1608075cb72SGal Pressman 	{ "tx_vport_multicast_bytes",
1619218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
1628075cb72SGal Pressman 	{ "rx_vport_broadcast_packets",
1639218b44dSGal Pressman 		VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
1648075cb72SGal Pressman 	{ "rx_vport_broadcast_bytes",
1659218b44dSGal Pressman 		VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
1668075cb72SGal Pressman 	{ "tx_vport_broadcast_packets",
1679218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
1688075cb72SGal Pressman 	{ "tx_vport_broadcast_bytes",
1699218b44dSGal Pressman 		VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
170fe6b9bd9SGal Pressman 	{ "rx_vport_rdma_unicast_packets",
171fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(received_ib_unicast.packets) },
172fe6b9bd9SGal Pressman 	{ "rx_vport_rdma_unicast_bytes",
173fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(received_ib_unicast.octets) },
174fe6b9bd9SGal Pressman 	{ "tx_vport_rdma_unicast_packets",
175fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(transmitted_ib_unicast.packets) },
176fe6b9bd9SGal Pressman 	{ "tx_vport_rdma_unicast_bytes",
177fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(transmitted_ib_unicast.octets) },
178fe6b9bd9SGal Pressman 	{ "rx_vport_rdma_multicast_packets",
179fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(received_ib_multicast.packets) },
180fe6b9bd9SGal Pressman 	{ "rx_vport_rdma_multicast_bytes",
181fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(received_ib_multicast.octets) },
182fe6b9bd9SGal Pressman 	{ "tx_vport_rdma_multicast_packets",
183fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(transmitted_ib_multicast.packets) },
184fe6b9bd9SGal Pressman 	{ "tx_vport_rdma_multicast_bytes",
185fe6b9bd9SGal Pressman 		VPORT_COUNTER_OFF(transmitted_ib_multicast.octets) },
1869218b44dSGal Pressman };
1879218b44dSGal Pressman 
1889218b44dSGal Pressman #define PPORT_802_3_OFF(c) \
1899218b44dSGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
1909218b44dSGal Pressman 		      counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
1919218b44dSGal Pressman #define PPORT_802_3_GET(pstats, c) \
1929218b44dSGal Pressman 	MLX5_GET64(ppcnt_reg, pstats->IEEE_802_3_counters, \
1939218b44dSGal Pressman 		   counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
1949218b44dSGal Pressman #define PPORT_2863_OFF(c) \
1959218b44dSGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
1969218b44dSGal Pressman 		      counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
1979218b44dSGal Pressman #define PPORT_2863_GET(pstats, c) \
1989218b44dSGal Pressman 	MLX5_GET64(ppcnt_reg, pstats->RFC_2863_counters, \
1999218b44dSGal Pressman 		   counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
2009218b44dSGal Pressman #define PPORT_2819_OFF(c) \
2019218b44dSGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
2029218b44dSGal Pressman 		      counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
2039218b44dSGal Pressman #define PPORT_2819_GET(pstats, c) \
2049218b44dSGal Pressman 	MLX5_GET64(ppcnt_reg, pstats->RFC_2819_counters, \
2059218b44dSGal Pressman 		   counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
2065db0a4f6SGal Pressman #define PPORT_PHY_STATISTICAL_OFF(c) \
2075db0a4f6SGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
2085db0a4f6SGal Pressman 		      counter_set.phys_layer_statistical_cntrs.c##_high)
2095db0a4f6SGal Pressman #define PPORT_PHY_STATISTICAL_GET(pstats, c) \
2105db0a4f6SGal Pressman 	MLX5_GET64(ppcnt_reg, (pstats)->phy_statistical_counters, \
2115db0a4f6SGal Pressman 		   counter_set.phys_layer_statistical_cntrs.c##_high)
212cf678570SGal Pressman #define PPORT_PER_PRIO_OFF(c) \
213cf678570SGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
214cf678570SGal Pressman 		      counter_set.eth_per_prio_grp_data_layout.c##_high)
215cf678570SGal Pressman #define PPORT_PER_PRIO_GET(pstats, prio, c) \
216cf678570SGal Pressman 	MLX5_GET64(ppcnt_reg, pstats->per_prio_counters[prio], \
217cf678570SGal Pressman 		   counter_set.eth_per_prio_grp_data_layout.c##_high)
218cf678570SGal Pressman #define NUM_PPORT_PRIO				8
219068aef33SGal Pressman #define PPORT_ETH_EXT_OFF(c) \
220068aef33SGal Pressman 	MLX5_BYTE_OFF(ppcnt_reg, \
221068aef33SGal Pressman 		      counter_set.eth_extended_cntrs_grp_data_layout.c##_high)
222068aef33SGal Pressman #define PPORT_ETH_EXT_GET(pstats, c) \
223068aef33SGal Pressman 	MLX5_GET64(ppcnt_reg, (pstats)->eth_ext_counters, \
224068aef33SGal Pressman 		   counter_set.eth_extended_cntrs_grp_data_layout.c##_high)
2259218b44dSGal Pressman 
2269218b44dSGal Pressman struct mlx5e_pport_stats {
2279218b44dSGal Pressman 	__be64 IEEE_802_3_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
2289218b44dSGal Pressman 	__be64 RFC_2863_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
2299218b44dSGal Pressman 	__be64 RFC_2819_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
230cf678570SGal Pressman 	__be64 per_prio_counters[NUM_PPORT_PRIO][MLX5_ST_SZ_QW(ppcnt_reg)];
231121fcdc8SGal Pressman 	__be64 phy_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
2325db0a4f6SGal Pressman 	__be64 phy_statistical_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
233068aef33SGal Pressman 	__be64 eth_ext_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
2349218b44dSGal Pressman };
2359218b44dSGal Pressman 
2369218b44dSGal Pressman static const struct counter_desc pport_802_3_stats_desc[] = {
237bfe6d8d1SGal Pressman 	{ "tx_packets_phy", PPORT_802_3_OFF(a_frames_transmitted_ok) },
238bfe6d8d1SGal Pressman 	{ "rx_packets_phy", PPORT_802_3_OFF(a_frames_received_ok) },
239bfe6d8d1SGal Pressman 	{ "rx_crc_errors_phy", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
240bfe6d8d1SGal Pressman 	{ "tx_bytes_phy", PPORT_802_3_OFF(a_octets_transmitted_ok) },
241bfe6d8d1SGal Pressman 	{ "rx_bytes_phy", PPORT_802_3_OFF(a_octets_received_ok) },
242bfe6d8d1SGal Pressman 	{ "tx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
243bfe6d8d1SGal Pressman 	{ "tx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
244bfe6d8d1SGal Pressman 	{ "rx_multicast_phy", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
245bfe6d8d1SGal Pressman 	{ "rx_broadcast_phy", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
246bfe6d8d1SGal Pressman 	{ "rx_in_range_len_errors_phy", PPORT_802_3_OFF(a_in_range_length_errors) },
247bfe6d8d1SGal Pressman 	{ "rx_out_of_range_len_phy", PPORT_802_3_OFF(a_out_of_range_length_field) },
248bfe6d8d1SGal Pressman 	{ "rx_oversize_pkts_phy", PPORT_802_3_OFF(a_frame_too_long_errors) },
249bfe6d8d1SGal Pressman 	{ "rx_symbol_err_phy", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
250bfe6d8d1SGal Pressman 	{ "tx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
251bfe6d8d1SGal Pressman 	{ "rx_mac_control_phy", PPORT_802_3_OFF(a_mac_control_frames_received) },
252bfe6d8d1SGal Pressman 	{ "rx_unsupported_op_phy", PPORT_802_3_OFF(a_unsupported_opcodes_received) },
253bfe6d8d1SGal Pressman 	{ "rx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
254bfe6d8d1SGal Pressman 	{ "tx_pause_ctrl_phy", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
2559218b44dSGal Pressman };
2569218b44dSGal Pressman 
2579218b44dSGal Pressman static const struct counter_desc pport_2863_stats_desc[] = {
258bfe6d8d1SGal Pressman 	{ "rx_discards_phy", PPORT_2863_OFF(if_in_discards) },
259bfe6d8d1SGal Pressman 	{ "tx_discards_phy", PPORT_2863_OFF(if_out_discards) },
260bfe6d8d1SGal Pressman 	{ "tx_errors_phy", PPORT_2863_OFF(if_out_errors) },
2619218b44dSGal Pressman };
2629218b44dSGal Pressman 
2639218b44dSGal Pressman static const struct counter_desc pport_2819_stats_desc[] = {
264bfe6d8d1SGal Pressman 	{ "rx_undersize_pkts_phy", PPORT_2819_OFF(ether_stats_undersize_pkts) },
265bfe6d8d1SGal Pressman 	{ "rx_fragments_phy", PPORT_2819_OFF(ether_stats_fragments) },
266bfe6d8d1SGal Pressman 	{ "rx_jabbers_phy", PPORT_2819_OFF(ether_stats_jabbers) },
267bfe6d8d1SGal Pressman 	{ "rx_64_bytes_phy", PPORT_2819_OFF(ether_stats_pkts64octets) },
268bfe6d8d1SGal Pressman 	{ "rx_65_to_127_bytes_phy", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
269bfe6d8d1SGal Pressman 	{ "rx_128_to_255_bytes_phy", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
270bfe6d8d1SGal Pressman 	{ "rx_256_to_511_bytes_phy", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
271bfe6d8d1SGal Pressman 	{ "rx_512_to_1023_bytes_phy", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
272bfe6d8d1SGal Pressman 	{ "rx_1024_to_1518_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
273bfe6d8d1SGal Pressman 	{ "rx_1519_to_2047_bytes_phy", PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
274bfe6d8d1SGal Pressman 	{ "rx_2048_to_4095_bytes_phy", PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
275bfe6d8d1SGal Pressman 	{ "rx_4096_to_8191_bytes_phy", PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
276bfe6d8d1SGal Pressman 	{ "rx_8192_to_10239_bytes_phy", PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
2779218b44dSGal Pressman };
2789218b44dSGal Pressman 
2795db0a4f6SGal Pressman static const struct counter_desc pport_phy_statistical_stats_desc[] = {
280ebc88870SGal Pressman 	{ "rx_pcs_symbol_err_phy", PPORT_PHY_STATISTICAL_OFF(phy_symbol_errors) },
2815db0a4f6SGal Pressman 	{ "rx_corrected_bits_phy", PPORT_PHY_STATISTICAL_OFF(phy_corrected_bits) },
2825db0a4f6SGal Pressman };
2835db0a4f6SGal Pressman 
284cf678570SGal Pressman static const struct counter_desc pport_per_prio_traffic_stats_desc[] = {
285bfe6d8d1SGal Pressman 	{ "rx_prio%d_bytes", PPORT_PER_PRIO_OFF(rx_octets) },
286bfe6d8d1SGal Pressman 	{ "rx_prio%d_packets", PPORT_PER_PRIO_OFF(rx_frames) },
287bfe6d8d1SGal Pressman 	{ "tx_prio%d_bytes", PPORT_PER_PRIO_OFF(tx_octets) },
288bfe6d8d1SGal Pressman 	{ "tx_prio%d_packets", PPORT_PER_PRIO_OFF(tx_frames) },
289cf678570SGal Pressman };
290cf678570SGal Pressman 
291cf678570SGal Pressman static const struct counter_desc pport_per_prio_pfc_stats_desc[] = {
292e989d5a5SGal Pressman 	/* %s is "global" or "prio{i}" */
293e989d5a5SGal Pressman 	{ "rx_%s_pause", PPORT_PER_PRIO_OFF(rx_pause) },
294e989d5a5SGal Pressman 	{ "rx_%s_pause_duration", PPORT_PER_PRIO_OFF(rx_pause_duration) },
295e989d5a5SGal Pressman 	{ "tx_%s_pause", PPORT_PER_PRIO_OFF(tx_pause) },
296e989d5a5SGal Pressman 	{ "tx_%s_pause_duration", PPORT_PER_PRIO_OFF(tx_pause_duration) },
297e989d5a5SGal Pressman 	{ "rx_%s_pause_transition", PPORT_PER_PRIO_OFF(rx_pause_transition) },
298cf678570SGal Pressman };
299cf678570SGal Pressman 
300068aef33SGal Pressman static const struct counter_desc pport_eth_ext_stats_desc[] = {
301068aef33SGal Pressman 	{ "rx_buffer_passed_thres_phy", PPORT_ETH_EXT_OFF(rx_buffer_almost_full) },
302068aef33SGal Pressman };
303068aef33SGal Pressman 
3040f7f3481SGal Pressman #define PCIE_PERF_OFF(c) \
3050f7f3481SGal Pressman 	MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c)
3060f7f3481SGal Pressman #define PCIE_PERF_GET(pcie_stats, c) \
3070f7f3481SGal Pressman 	MLX5_GET(mpcnt_reg, (pcie_stats)->pcie_perf_counters, \
3080f7f3481SGal Pressman 		 counter_set.pcie_perf_cntrs_grp_data_layout.c)
3090f7f3481SGal Pressman 
310efae7f78SEran Ben Elisha #define PCIE_PERF_OFF64(c) \
311efae7f78SEran Ben Elisha 	MLX5_BYTE_OFF(mpcnt_reg, counter_set.pcie_perf_cntrs_grp_data_layout.c##_high)
312efae7f78SEran Ben Elisha #define PCIE_PERF_GET64(pcie_stats, c) \
313efae7f78SEran Ben Elisha 	MLX5_GET64(mpcnt_reg, (pcie_stats)->pcie_perf_counters, \
314efae7f78SEran Ben Elisha 		   counter_set.pcie_perf_cntrs_grp_data_layout.c##_high)
315efae7f78SEran Ben Elisha 
3160f7f3481SGal Pressman struct mlx5e_pcie_stats {
3170f7f3481SGal Pressman 	__be64 pcie_perf_counters[MLX5_ST_SZ_QW(mpcnt_reg)];
3180f7f3481SGal Pressman };
3190f7f3481SGal Pressman 
3200f7f3481SGal Pressman static const struct counter_desc pcie_perf_stats_desc[] = {
3210f7f3481SGal Pressman 	{ "rx_pci_signal_integrity", PCIE_PERF_OFF(rx_errors) },
3220f7f3481SGal Pressman 	{ "tx_pci_signal_integrity", PCIE_PERF_OFF(tx_errors) },
3230f7f3481SGal Pressman };
3240f7f3481SGal Pressman 
325efae7f78SEran Ben Elisha static const struct counter_desc pcie_perf_stats_desc64[] = {
326efae7f78SEran Ben Elisha 	{ "outbound_pci_buffer_overflow", PCIE_PERF_OFF64(tx_overflow_buffer_pkt) },
327efae7f78SEran Ben Elisha };
328efae7f78SEran Ben Elisha 
32973e90646SGal Pressman static const struct counter_desc pcie_perf_stall_stats_desc[] = {
33073e90646SGal Pressman 	{ "outbound_pci_stalled_rd", PCIE_PERF_OFF(outbound_stalled_reads) },
33173e90646SGal Pressman 	{ "outbound_pci_stalled_wr", PCIE_PERF_OFF(outbound_stalled_writes) },
33273e90646SGal Pressman 	{ "outbound_pci_stalled_rd_events", PCIE_PERF_OFF(outbound_stalled_reads_events) },
33373e90646SGal Pressman 	{ "outbound_pci_stalled_wr_events", PCIE_PERF_OFF(outbound_stalled_writes_events) },
33473e90646SGal Pressman };
33573e90646SGal Pressman 
3369218b44dSGal Pressman struct mlx5e_rq_stats {
3379218b44dSGal Pressman 	u64 packets;
3389218b44dSGal Pressman 	u64 bytes;
339bfe6d8d1SGal Pressman 	u64 csum_complete;
340bfe6d8d1SGal Pressman 	u64 csum_unnecessary_inner;
3411b223dd3SSaeed Mahameed 	u64 csum_none;
3429218b44dSGal Pressman 	u64 lro_packets;
3439218b44dSGal Pressman 	u64 lro_bytes;
34486994156SRana Shahout 	u64 xdp_drop;
345b5503b99SSaeed Mahameed 	u64 xdp_tx;
346b5503b99SSaeed Mahameed 	u64 xdp_tx_full;
3479218b44dSGal Pressman 	u64 wqe_err;
3489218b44dSGal Pressman 	u64 mpwqe_filler;
3499218b44dSGal Pressman 	u64 buff_alloc_err;
3507219ab34STariq Toukan 	u64 cqe_compress_blks;
3517219ab34STariq Toukan 	u64 cqe_compress_pkts;
352accd5883STariq Toukan 	u64 page_reuse;
3534415a031STariq Toukan 	u64 cache_reuse;
3544415a031STariq Toukan 	u64 cache_full;
3554415a031STariq Toukan 	u64 cache_empty;
3564415a031STariq Toukan 	u64 cache_busy;
3579218b44dSGal Pressman };
3589218b44dSGal Pressman 
3599218b44dSGal Pressman static const struct counter_desc rq_stats_desc[] = {
360bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, packets) },
361bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, bytes) },
362bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_complete) },
363bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_unnecessary_inner) },
364bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, csum_none) },
36586994156SRana Shahout 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_drop) },
366b5503b99SSaeed Mahameed 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_tx) },
367b5503b99SSaeed Mahameed 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, xdp_tx_full) },
368bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_packets) },
369bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, lro_bytes) },
370bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, wqe_err) },
371bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, mpwqe_filler) },
372bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
373bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_blks) },
374bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cqe_compress_pkts) },
375accd5883STariq Toukan 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, page_reuse) },
3764415a031STariq Toukan 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_reuse) },
3774415a031STariq Toukan 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_full) },
3784415a031STariq Toukan 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_empty) },
3794415a031STariq Toukan 	{ MLX5E_DECLARE_RX_STAT(struct mlx5e_rq_stats, cache_busy) },
3809218b44dSGal Pressman };
3819218b44dSGal Pressman 
3829218b44dSGal Pressman struct mlx5e_sq_stats {
3839218b44dSGal Pressman 	/* commonly accessed in data path */
3849218b44dSGal Pressman 	u64 packets;
3859218b44dSGal Pressman 	u64 bytes;
386c8cf78feSTariq Toukan 	u64 xmit_more;
3879218b44dSGal Pressman 	u64 tso_packets;
3889218b44dSGal Pressman 	u64 tso_bytes;
3899218b44dSGal Pressman 	u64 tso_inner_packets;
3909218b44dSGal Pressman 	u64 tso_inner_bytes;
391bfe6d8d1SGal Pressman 	u64 csum_partial_inner;
3929218b44dSGal Pressman 	u64 nop;
3939218b44dSGal Pressman 	/* less likely accessed in data path */
394bfe6d8d1SGal Pressman 	u64 csum_none;
3959218b44dSGal Pressman 	u64 stopped;
3969218b44dSGal Pressman 	u64 wake;
3979218b44dSGal Pressman 	u64 dropped;
3989218b44dSGal Pressman };
3999218b44dSGal Pressman 
4009218b44dSGal Pressman static const struct counter_desc sq_stats_desc[] = {
401bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, packets) },
402bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, bytes) },
403bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_packets) },
404bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_bytes) },
405bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
406bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
407bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_partial_inner) },
408bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, nop) },
409bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, csum_none) },
410bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, stopped) },
411bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, wake) },
412bfe6d8d1SGal Pressman 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, dropped) },
413c8cf78feSTariq Toukan 	{ MLX5E_DECLARE_TX_STAT(struct mlx5e_sq_stats, xmit_more) },
4149218b44dSGal Pressman };
4159218b44dSGal Pressman 
4169218b44dSGal Pressman #define NUM_SW_COUNTERS			ARRAY_SIZE(sw_stats_desc)
4179218b44dSGal Pressman #define NUM_Q_COUNTERS			ARRAY_SIZE(q_stats_desc)
4189218b44dSGal Pressman #define NUM_VPORT_COUNTERS		ARRAY_SIZE(vport_stats_desc)
4199218b44dSGal Pressman #define NUM_PPORT_802_3_COUNTERS	ARRAY_SIZE(pport_802_3_stats_desc)
4209218b44dSGal Pressman #define NUM_PPORT_2863_COUNTERS		ARRAY_SIZE(pport_2863_stats_desc)
4219218b44dSGal Pressman #define NUM_PPORT_2819_COUNTERS		ARRAY_SIZE(pport_2819_stats_desc)
4225db0a4f6SGal Pressman #define NUM_PPORT_PHY_STATISTICAL_COUNTERS(priv) \
4235db0a4f6SGal Pressman 	(ARRAY_SIZE(pport_phy_statistical_stats_desc) * \
4245db0a4f6SGal Pressman 	 MLX5_CAP_PCAM_FEATURE((priv)->mdev, ppcnt_statistical_group))
4250f7f3481SGal Pressman #define NUM_PCIE_PERF_COUNTERS(priv) \
4260f7f3481SGal Pressman 	(ARRAY_SIZE(pcie_perf_stats_desc) * \
4270f7f3481SGal Pressman 	 MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_performance_group))
428efae7f78SEran Ben Elisha #define NUM_PCIE_PERF_COUNTERS64(priv) \
429efae7f78SEran Ben Elisha 	(ARRAY_SIZE(pcie_perf_stats_desc64) * \
430efae7f78SEran Ben Elisha 	 MLX5_CAP_MCAM_FEATURE((priv)->mdev, tx_overflow_buffer_pkt))
43173e90646SGal Pressman #define NUM_PCIE_PERF_STALL_COUNTERS(priv) \
43273e90646SGal Pressman 	(ARRAY_SIZE(pcie_perf_stall_stats_desc) * \
43373e90646SGal Pressman 	 MLX5_CAP_MCAM_FEATURE((priv)->mdev, pcie_outbound_stalled))
434cf678570SGal Pressman #define NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS \
435cf678570SGal Pressman 	ARRAY_SIZE(pport_per_prio_traffic_stats_desc)
436cf678570SGal Pressman #define NUM_PPORT_PER_PRIO_PFC_COUNTERS \
437cf678570SGal Pressman 	ARRAY_SIZE(pport_per_prio_pfc_stats_desc)
438068aef33SGal Pressman #define NUM_PPORT_ETH_EXT_COUNTERS(priv) \
439068aef33SGal Pressman 	(ARRAY_SIZE(pport_eth_ext_stats_desc) * \
440068aef33SGal Pressman 	 MLX5_CAP_PCAM_FEATURE((priv)->mdev, rx_buffer_fullness_counters))
4415db0a4f6SGal Pressman #define NUM_PPORT_COUNTERS(priv)	(NUM_PPORT_802_3_COUNTERS + \
4429218b44dSGal Pressman 					 NUM_PPORT_2863_COUNTERS  + \
443cf678570SGal Pressman 					 NUM_PPORT_2819_COUNTERS  + \
4445db0a4f6SGal Pressman 					 NUM_PPORT_PHY_STATISTICAL_COUNTERS(priv) + \
445cf678570SGal Pressman 					 NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS * \
446068aef33SGal Pressman 					 NUM_PPORT_PRIO + \
447068aef33SGal Pressman 					 NUM_PPORT_ETH_EXT_COUNTERS(priv))
44873e90646SGal Pressman #define NUM_PCIE_COUNTERS(priv)		(NUM_PCIE_PERF_COUNTERS(priv) + \
449efae7f78SEran Ben Elisha 					 NUM_PCIE_PERF_COUNTERS64(priv) +\
45073e90646SGal Pressman 					 NUM_PCIE_PERF_STALL_COUNTERS(priv))
4519218b44dSGal Pressman #define NUM_RQ_STATS			ARRAY_SIZE(rq_stats_desc)
4529218b44dSGal Pressman #define NUM_SQ_STATS			ARRAY_SIZE(sq_stats_desc)
4539218b44dSGal Pressman 
4549218b44dSGal Pressman struct mlx5e_stats {
4559218b44dSGal Pressman 	struct mlx5e_sw_stats sw;
4569218b44dSGal Pressman 	struct mlx5e_qcounter_stats qcnt;
4579218b44dSGal Pressman 	struct mlx5e_vport_stats vport;
4589218b44dSGal Pressman 	struct mlx5e_pport_stats pport;
459370bad0fSOr Gerlitz 	struct rtnl_link_stats64 vf_vport;
4600f7f3481SGal Pressman 	struct mlx5e_pcie_stats pcie;
4619218b44dSGal Pressman };
4629218b44dSGal Pressman 
463bedb7c90SHuy Nguyen static const struct counter_desc mlx5e_pme_status_desc[] = {
464bedb7c90SHuy Nguyen 	{ "module_unplug", 8 },
465bedb7c90SHuy Nguyen };
466bedb7c90SHuy Nguyen 
467bedb7c90SHuy Nguyen static const struct counter_desc mlx5e_pme_error_desc[] = {
468bedb7c90SHuy Nguyen 	{ "module_bus_stuck", 16 },       /* bus stuck (I2C or data shorted) */
469bedb7c90SHuy Nguyen 	{ "module_high_temp", 48 },       /* high temperature */
470bedb7c90SHuy Nguyen 	{ "module_bad_shorted", 56 },    /* bad or shorted cable/module */
471bedb7c90SHuy Nguyen };
472bedb7c90SHuy Nguyen 
4739218b44dSGal Pressman #endif /* __MLX5_EN_STATS_H__ */
474