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;
74 u64 rx_buff_alloc_err;
76 /* Special handling counters */
80 static const struct counter_desc sw_stats_desc[] = {
81 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
82 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
83 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
84 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
85 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_packets) },
86 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_bytes) },
87 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_packets) },
88 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_bytes) },
89 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_packets) },
90 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_bytes) },
91 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_good) },
92 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
93 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_sw) },
94 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_inner) },
95 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_offload) },
96 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_inner) },
97 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
98 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
99 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
100 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
101 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler) },
102 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_frag) },
103 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
104 { MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, link_down_events) },
107 struct mlx5e_qcounter_stats {
108 u32 rx_out_of_buffer;
111 static const struct counter_desc q_stats_desc[] = {
112 { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
115 #define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
116 #define VPORT_COUNTER_GET(vstats, c) MLX5_GET64(query_vport_counter_out, \
117 vstats->query_vport_out, c)
119 struct mlx5e_vport_stats {
120 __be64 query_vport_out[MLX5_ST_SZ_QW(query_vport_counter_out)];
123 static const struct counter_desc vport_stats_desc[] = {
124 { "rx_vport_error_packets",
125 VPORT_COUNTER_OFF(received_errors.packets) },
126 { "rx_vport_error_bytes", VPORT_COUNTER_OFF(received_errors.octets) },
127 { "tx_vport_error_packets",
128 VPORT_COUNTER_OFF(transmit_errors.packets) },
129 { "tx_vport_error_bytes", VPORT_COUNTER_OFF(transmit_errors.octets) },
130 { "rx_vport_unicast_packets",
131 VPORT_COUNTER_OFF(received_eth_unicast.packets) },
132 { "rx_vport_unicast_bytes",
133 VPORT_COUNTER_OFF(received_eth_unicast.octets) },
134 { "tx_vport_unicast_packets",
135 VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
136 { "tx_vport_unicast_bytes",
137 VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
138 { "rx_vport_multicast_packets",
139 VPORT_COUNTER_OFF(received_eth_multicast.packets) },
140 { "rx_vport_multicast_bytes",
141 VPORT_COUNTER_OFF(received_eth_multicast.octets) },
142 { "tx_vport_multicast_packets",
143 VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
144 { "tx_vport_multicast_bytes",
145 VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
146 { "rx_vport_broadcast_packets",
147 VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
148 { "rx_vport_broadcast_bytes",
149 VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
150 { "tx_vport_broadcast_packets",
151 VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
152 { "tx_vport_broadcast_bytes",
153 VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
156 #define PPORT_802_3_OFF(c) \
157 MLX5_BYTE_OFF(ppcnt_reg, \
158 counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
159 #define PPORT_802_3_GET(pstats, c) \
160 MLX5_GET64(ppcnt_reg, pstats->IEEE_802_3_counters, \
161 counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
162 #define PPORT_2863_OFF(c) \
163 MLX5_BYTE_OFF(ppcnt_reg, \
164 counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
165 #define PPORT_2863_GET(pstats, c) \
166 MLX5_GET64(ppcnt_reg, pstats->RFC_2863_counters, \
167 counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
168 #define PPORT_2819_OFF(c) \
169 MLX5_BYTE_OFF(ppcnt_reg, \
170 counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
171 #define PPORT_2819_GET(pstats, c) \
172 MLX5_GET64(ppcnt_reg, pstats->RFC_2819_counters, \
173 counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
174 #define PPORT_PER_PRIO_OFF(c) \
175 MLX5_BYTE_OFF(ppcnt_reg, \
176 counter_set.eth_per_prio_grp_data_layout.c##_high)
177 #define PPORT_PER_PRIO_GET(pstats, prio, c) \
178 MLX5_GET64(ppcnt_reg, pstats->per_prio_counters[prio], \
179 counter_set.eth_per_prio_grp_data_layout.c##_high)
180 #define NUM_PPORT_PRIO 8
182 struct mlx5e_pport_stats {
183 __be64 IEEE_802_3_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
184 __be64 RFC_2863_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
185 __be64 RFC_2819_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
186 __be64 per_prio_counters[NUM_PPORT_PRIO][MLX5_ST_SZ_QW(ppcnt_reg)];
187 __be64 phy_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
190 static const struct counter_desc pport_802_3_stats_desc[] = {
191 { "frames_tx", PPORT_802_3_OFF(a_frames_transmitted_ok) },
192 { "frames_rx", PPORT_802_3_OFF(a_frames_received_ok) },
193 { "check_seq_err", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
194 { "alignment_err", PPORT_802_3_OFF(a_alignment_errors) },
195 { "octets_tx", PPORT_802_3_OFF(a_octets_transmitted_ok) },
196 { "octets_received", PPORT_802_3_OFF(a_octets_received_ok) },
197 { "multicast_xmitted", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
198 { "broadcast_xmitted", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
199 { "multicast_rx", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
200 { "broadcast_rx", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
201 { "in_range_len_errors", PPORT_802_3_OFF(a_in_range_length_errors) },
202 { "out_of_range_len", PPORT_802_3_OFF(a_out_of_range_length_field) },
203 { "too_long_errors", PPORT_802_3_OFF(a_frame_too_long_errors) },
204 { "symbol_err", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
205 { "mac_control_tx", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
206 { "mac_control_rx", PPORT_802_3_OFF(a_mac_control_frames_received) },
207 { "unsupported_op_rx",
208 PPORT_802_3_OFF(a_unsupported_opcodes_received) },
209 { "pause_ctrl_rx", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
211 PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
214 static const struct counter_desc pport_2863_stats_desc[] = {
215 { "in_octets", PPORT_2863_OFF(if_in_octets) },
216 { "in_ucast_pkts", PPORT_2863_OFF(if_in_ucast_pkts) },
217 { "in_discards", PPORT_2863_OFF(if_in_discards) },
218 { "in_errors", PPORT_2863_OFF(if_in_errors) },
219 { "in_unknown_protos", PPORT_2863_OFF(if_in_unknown_protos) },
220 { "out_octets", PPORT_2863_OFF(if_out_octets) },
221 { "out_ucast_pkts", PPORT_2863_OFF(if_out_ucast_pkts) },
222 { "out_discards", PPORT_2863_OFF(if_out_discards) },
223 { "out_errors", PPORT_2863_OFF(if_out_errors) },
224 { "in_multicast_pkts", PPORT_2863_OFF(if_in_multicast_pkts) },
225 { "in_broadcast_pkts", PPORT_2863_OFF(if_in_broadcast_pkts) },
226 { "out_multicast_pkts", PPORT_2863_OFF(if_out_multicast_pkts) },
227 { "out_broadcast_pkts", PPORT_2863_OFF(if_out_broadcast_pkts) },
230 static const struct counter_desc pport_2819_stats_desc[] = {
231 { "drop_events", PPORT_2819_OFF(ether_stats_drop_events) },
232 { "octets", PPORT_2819_OFF(ether_stats_octets) },
233 { "pkts", PPORT_2819_OFF(ether_stats_pkts) },
234 { "broadcast_pkts", PPORT_2819_OFF(ether_stats_broadcast_pkts) },
235 { "multicast_pkts", PPORT_2819_OFF(ether_stats_multicast_pkts) },
236 { "crc_align_errors", PPORT_2819_OFF(ether_stats_crc_align_errors) },
237 { "undersize_pkts", PPORT_2819_OFF(ether_stats_undersize_pkts) },
238 { "oversize_pkts", PPORT_2819_OFF(ether_stats_oversize_pkts) },
239 { "fragments", PPORT_2819_OFF(ether_stats_fragments) },
240 { "jabbers", PPORT_2819_OFF(ether_stats_jabbers) },
241 { "collisions", PPORT_2819_OFF(ether_stats_collisions) },
242 { "p64octets", PPORT_2819_OFF(ether_stats_pkts64octets) },
243 { "p65to127octets", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
244 { "p128to255octets", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
245 { "p256to511octets", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
246 { "p512to1023octets", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
247 { "p1024to1518octets",
248 PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
249 { "p1519to2047octets",
250 PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
251 { "p2048to4095octets",
252 PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
253 { "p4096to8191octets",
254 PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
255 { "p8192to10239octets",
256 PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
259 static const struct counter_desc pport_per_prio_traffic_stats_desc[] = {
260 { "rx_octets", PPORT_PER_PRIO_OFF(rx_octets) },
261 { "rx_frames", PPORT_PER_PRIO_OFF(rx_frames) },
262 { "tx_octets", PPORT_PER_PRIO_OFF(tx_octets) },
263 { "tx_frames", PPORT_PER_PRIO_OFF(tx_frames) },
266 static const struct counter_desc pport_per_prio_pfc_stats_desc[] = {
267 { "rx_pause", PPORT_PER_PRIO_OFF(rx_pause) },
268 { "rx_pause_duration", PPORT_PER_PRIO_OFF(rx_pause_duration) },
269 { "tx_pause", PPORT_PER_PRIO_OFF(tx_pause) },
270 { "tx_pause_duration", PPORT_PER_PRIO_OFF(tx_pause_duration) },
271 { "rx_pause_transition", PPORT_PER_PRIO_OFF(rx_pause_transition) },
274 struct mlx5e_rq_stats {
288 static const struct counter_desc rq_stats_desc[] = {
289 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, packets) },
290 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, bytes) },
291 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_sw) },
292 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_inner) },
293 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_none) },
294 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_packets) },
295 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_bytes) },
296 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, wqe_err) },
297 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_filler) },
298 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_frag) },
299 { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
302 struct mlx5e_sq_stats {
303 /* commonly accessed in data path */
308 u64 tso_inner_packets;
310 u64 csum_offload_inner;
312 /* less likely accessed in data path */
313 u64 csum_offload_none;
319 static const struct counter_desc sq_stats_desc[] = {
320 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, packets) },
321 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, bytes) },
322 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_packets) },
323 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_bytes) },
324 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
325 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
326 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_inner) },
327 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, nop) },
328 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_none) },
329 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, stopped) },
330 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, wake) },
331 { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, dropped) },
334 #define NUM_SW_COUNTERS ARRAY_SIZE(sw_stats_desc)
335 #define NUM_Q_COUNTERS ARRAY_SIZE(q_stats_desc)
336 #define NUM_VPORT_COUNTERS ARRAY_SIZE(vport_stats_desc)
337 #define NUM_PPORT_802_3_COUNTERS ARRAY_SIZE(pport_802_3_stats_desc)
338 #define NUM_PPORT_2863_COUNTERS ARRAY_SIZE(pport_2863_stats_desc)
339 #define NUM_PPORT_2819_COUNTERS ARRAY_SIZE(pport_2819_stats_desc)
340 #define NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS \
341 ARRAY_SIZE(pport_per_prio_traffic_stats_desc)
342 #define NUM_PPORT_PER_PRIO_PFC_COUNTERS \
343 ARRAY_SIZE(pport_per_prio_pfc_stats_desc)
344 #define NUM_PPORT_COUNTERS (NUM_PPORT_802_3_COUNTERS + \
345 NUM_PPORT_2863_COUNTERS + \
346 NUM_PPORT_2819_COUNTERS + \
347 NUM_PPORT_PER_PRIO_TRAFFIC_COUNTERS * \
349 #define NUM_RQ_STATS ARRAY_SIZE(rq_stats_desc)
350 #define NUM_SQ_STATS ARRAY_SIZE(sq_stats_desc)
353 struct mlx5e_sw_stats sw;
354 struct mlx5e_qcounter_stats qcnt;
355 struct mlx5e_vport_stats vport;
356 struct mlx5e_pport_stats pport;
359 #endif /* __MLX5_EN_STATS_H__ */