2 * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
32 #ifndef __MLX5_EN_STATS_H__
33 #define __MLX5_EN_STATS_H__
35 #define MLX5E_READ_CTR64_CPU(ptr, dsc, i) \
36 (*(u64 *)((char *)ptr + dsc[i].offset))
37 #define MLX5E_READ_CTR64_BE(ptr, dsc, i) \
38 be64_to_cpu(*(__be64 *)((char *)ptr + dsc[i].offset))
39 #define MLX5E_READ_CTR32_CPU(ptr, dsc, i) \
40 (*(u32 *)((char *)ptr + dsc[i].offset))
41 #define MLX5E_READ_CTR32_BE(ptr, dsc, i) \
42 be64_to_cpu(*(__be32 *)((char *)ptr + dsc[i].offset))
44 #define MLX5E_DECLARE_STAT(type, fld) #fld, offsetof(type, fld)
47 char name[ETH_GSTRING_LEN];
48 int offset; /* Byte offset */
51 struct mlx5e_sw_stats {
58 u64 tso_inner_packets;
73 u64 rx_buff_alloc_err;
76 static const struct counter_desc sw_stats_desc[] = {
77 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
78 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
79 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
80 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
81 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_packets) },
82 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_bytes) },
83 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_packets) },
84 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_bytes) },
85 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_packets) },
86 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_bytes) },
87 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_good) },
88 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
89 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_sw) },
90 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_offload) },
91 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_inner) },
92 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
93 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
94 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
95 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
96 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler) },
97 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_frag) },
98 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
101 struct mlx5e_qcounter_stats {
102 u32 rx_out_of_buffer;
105 static const struct counter_desc q_stats_desc[] = {
106 { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
109 #define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
110 #define VPORT_COUNTER_GET(vstats, c) MLX5_GET64(query_vport_counter_out, \
111 vstats->query_vport_out, c)
113 struct mlx5e_vport_stats {
114 __be64 query_vport_out[MLX5_ST_SZ_QW(query_vport_counter_out)];
117 static const struct counter_desc vport_stats_desc[] = {
118 { "rx_vport_error_packets",
119 VPORT_COUNTER_OFF(received_errors.packets) },
120 { "rx_vport_error_bytes", VPORT_COUNTER_OFF(received_errors.octets) },
121 { "tx_vport_error_packets",
122 VPORT_COUNTER_OFF(transmit_errors.packets) },
123 { "tx_vport_error_bytes", VPORT_COUNTER_OFF(transmit_errors.octets) },
124 { "rx_vport_unicast_packets",
125 VPORT_COUNTER_OFF(received_eth_unicast.packets) },
126 { "rx_vport_unicast_bytes",
127 VPORT_COUNTER_OFF(received_eth_unicast.octets) },
128 { "tx_vport_unicast_packets",
129 VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
130 { "tx_vport_unicast_bytes",
131 VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
132 { "rx_vport_multicast_packets",
133 VPORT_COUNTER_OFF(received_eth_multicast.packets) },
134 { "rx_vport_multicast_bytes",
135 VPORT_COUNTER_OFF(received_eth_multicast.octets) },
136 { "tx_vport_multicast_packets",
137 VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
138 { "tx_vport_multicast_bytes",
139 VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
140 { "rx_vport_broadcast_packets",
141 VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
142 { "rx_vport_broadcast_bytes",
143 VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
144 { "tx_vport_broadcast_packets",
145 VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
146 { "tx_vport_broadcast_bytes",
147 VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
150 #define PPORT_802_3_OFF(c) \
151 MLX5_BYTE_OFF(ppcnt_reg, \
152 counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
153 #define PPORT_802_3_GET(pstats, c) \
154 MLX5_GET64(ppcnt_reg, pstats->IEEE_802_3_counters, \
155 counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
156 #define PPORT_2863_OFF(c) \
157 MLX5_BYTE_OFF(ppcnt_reg, \
158 counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
159 #define PPORT_2863_GET(pstats, c) \
160 MLX5_GET64(ppcnt_reg, pstats->RFC_2863_counters, \
161 counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
162 #define PPORT_2819_OFF(c) \
163 MLX5_BYTE_OFF(ppcnt_reg, \
164 counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
165 #define PPORT_2819_GET(pstats, c) \
166 MLX5_GET64(ppcnt_reg, pstats->RFC_2819_counters, \
167 counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
169 struct mlx5e_pport_stats {
170 __be64 IEEE_802_3_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
171 __be64 RFC_2863_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
172 __be64 RFC_2819_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
175 static const struct counter_desc pport_802_3_stats_desc[] = {
176 { "frames_tx", PPORT_802_3_OFF(a_frames_transmitted_ok) },
177 { "frames_rx", PPORT_802_3_OFF(a_frames_received_ok) },
178 { "check_seq_err", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
179 { "alignment_err", PPORT_802_3_OFF(a_alignment_errors) },
180 { "octets_tx", PPORT_802_3_OFF(a_octets_transmitted_ok) },
181 { "octets_received", PPORT_802_3_OFF(a_octets_received_ok) },
182 { "multicast_xmitted", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
183 { "broadcast_xmitted", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
184 { "multicast_rx", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
185 { "broadcast_rx", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
186 { "in_range_len_errors", PPORT_802_3_OFF(a_in_range_length_errors) },
187 { "out_of_range_len", PPORT_802_3_OFF(a_out_of_range_length_field) },
188 { "too_long_errors", PPORT_802_3_OFF(a_frame_too_long_errors) },
189 { "symbol_err", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
190 { "mac_control_tx", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
191 { "mac_control_rx", PPORT_802_3_OFF(a_mac_control_frames_received) },
192 { "unsupported_op_rx",
193 PPORT_802_3_OFF(a_unsupported_opcodes_received) },
194 { "pause_ctrl_rx", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
196 PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
199 static const struct counter_desc pport_2863_stats_desc[] = {
200 { "in_octets", PPORT_2863_OFF(if_in_octets) },
201 { "in_ucast_pkts", PPORT_2863_OFF(if_in_ucast_pkts) },
202 { "in_discards", PPORT_2863_OFF(if_in_discards) },
203 { "in_errors", PPORT_2863_OFF(if_in_errors) },
204 { "in_unknown_protos", PPORT_2863_OFF(if_in_unknown_protos) },
205 { "out_octets", PPORT_2863_OFF(if_out_octets) },
206 { "out_ucast_pkts", PPORT_2863_OFF(if_out_ucast_pkts) },
207 { "out_discards", PPORT_2863_OFF(if_out_discards) },
208 { "out_errors", PPORT_2863_OFF(if_out_errors) },
209 { "in_multicast_pkts", PPORT_2863_OFF(if_in_multicast_pkts) },
210 { "in_broadcast_pkts", PPORT_2863_OFF(if_in_broadcast_pkts) },
211 { "out_multicast_pkts", PPORT_2863_OFF(if_out_multicast_pkts) },
212 { "out_broadcast_pkts", PPORT_2863_OFF(if_out_broadcast_pkts) },
215 static const struct counter_desc pport_2819_stats_desc[] = {
216 { "drop_events", PPORT_2819_OFF(ether_stats_drop_events) },
217 { "octets", PPORT_2819_OFF(ether_stats_octets) },
218 { "pkts", PPORT_2819_OFF(ether_stats_pkts) },
219 { "broadcast_pkts", PPORT_2819_OFF(ether_stats_broadcast_pkts) },
220 { "multicast_pkts", PPORT_2819_OFF(ether_stats_multicast_pkts) },
221 { "crc_align_errors", PPORT_2819_OFF(ether_stats_crc_align_errors) },
222 { "undersize_pkts", PPORT_2819_OFF(ether_stats_undersize_pkts) },
223 { "oversize_pkts", PPORT_2819_OFF(ether_stats_oversize_pkts) },
224 { "fragments", PPORT_2819_OFF(ether_stats_fragments) },
225 { "jabbers", PPORT_2819_OFF(ether_stats_jabbers) },
226 { "collisions", PPORT_2819_OFF(ether_stats_collisions) },
227 { "p64octets", PPORT_2819_OFF(ether_stats_pkts64octets) },
228 { "p65to127octets", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
229 { "p128to255octets", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
230 { "p256to511octets", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
231 { "p512to1023octets", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
232 { "p1024to1518octets",
233 PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
234 { "p1519to2047octets",
235 PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
236 { "p2048to4095octets",
237 PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
238 { "p4096to8191octets",
239 PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
240 { "p8192to10239octets",
241 PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
244 struct mlx5e_rq_stats {
257 static const struct counter_desc rq_stats_desc[] = {
258 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, packets) },
259 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, bytes) },
260 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_none) },
261 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_sw) },
262 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_packets) },
263 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_bytes) },
264 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, wqe_err) },
265 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_filler) },
266 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_frag) },
267 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
270 struct mlx5e_sq_stats {
271 /* commonly accessed in data path */
276 u64 tso_inner_packets;
278 u64 csum_offload_inner;
280 /* less likely accessed in data path */
281 u64 csum_offload_none;
287 static const struct counter_desc sq_stats_desc[] = {
288 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, packets) },
289 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, bytes) },
290 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_packets) },
291 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_bytes) },
292 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
293 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
294 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_inner) },
295 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, nop) },
296 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_none) },
297 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, stopped) },
298 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, wake) },
299 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, dropped) },
302 #define NUM_SW_COUNTERS ARRAY_SIZE(sw_stats_desc)
303 #define NUM_Q_COUNTERS ARRAY_SIZE(q_stats_desc)
304 #define NUM_VPORT_COUNTERS ARRAY_SIZE(vport_stats_desc)
305 #define NUM_PPORT_802_3_COUNTERS ARRAY_SIZE(pport_802_3_stats_desc)
306 #define NUM_PPORT_2863_COUNTERS ARRAY_SIZE(pport_2863_stats_desc)
307 #define NUM_PPORT_2819_COUNTERS ARRAY_SIZE(pport_2819_stats_desc)
308 #define NUM_PPORT_COUNTERS (NUM_PPORT_802_3_COUNTERS + \
309 NUM_PPORT_2863_COUNTERS + \
310 NUM_PPORT_2819_COUNTERS)
311 #define NUM_RQ_STATS ARRAY_SIZE(rq_stats_desc)
312 #define NUM_SQ_STATS ARRAY_SIZE(sq_stats_desc)
315 struct mlx5e_sw_stats sw;
316 struct mlx5e_qcounter_stats qcnt;
317 struct mlx5e_vport_stats vport;
318 struct mlx5e_pport_stats pport;
321 #endif /* __MLX5_EN_STATS_H__ */