116320d8fc424df67785e043c9a8a3c64e8938f6
[sfrench/cifs-2.6.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_stats.h
1 /*
2  * Copyright (c) 2015-2016, Mellanox Technologies. 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 #ifndef __MLX5_EN_STATS_H__
33 #define __MLX5_EN_STATS_H__
34
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))
43
44 #define MLX5E_DECLARE_STAT(type, fld) #fld, offsetof(type, fld)
45
46 struct counter_desc {
47         char            name[ETH_GSTRING_LEN];
48         int             offset; /* Byte offset */
49 };
50
51 struct mlx5e_sw_stats {
52         u64 rx_packets;
53         u64 rx_bytes;
54         u64 tx_packets;
55         u64 tx_bytes;
56         u64 tso_packets;
57         u64 tso_bytes;
58         u64 tso_inner_packets;
59         u64 tso_inner_bytes;
60         u64 lro_packets;
61         u64 lro_bytes;
62         u64 rx_csum_good;
63         u64 rx_csum_none;
64         u64 rx_csum_sw;
65         u64 tx_csum_offload;
66         u64 tx_csum_inner;
67         u64 tx_queue_stopped;
68         u64 tx_queue_wake;
69         u64 tx_queue_dropped;
70         u64 rx_wqe_err;
71         u64 rx_mpwqe_filler;
72         u64 rx_mpwqe_frag;
73         u64 rx_buff_alloc_err;
74 };
75
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) },
99 };
100
101 struct mlx5e_qcounter_stats {
102         u32 rx_out_of_buffer;
103 };
104
105 static const struct counter_desc q_stats_desc[] = {
106         { MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
107 };
108
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)
112
113 struct mlx5e_vport_stats {
114         __be64 query_vport_out[MLX5_ST_SZ_QW(query_vport_counter_out)];
115 };
116
117 static const struct counter_desc vport_stats_desc[] = {
118         { "rx_error_packets", VPORT_COUNTER_OFF(received_errors.packets) },
119         { "rx_error_bytes", VPORT_COUNTER_OFF(received_errors.octets) },
120         { "tx_error_packets", VPORT_COUNTER_OFF(transmit_errors.packets) },
121         { "tx_error_bytes", VPORT_COUNTER_OFF(transmit_errors.octets) },
122         { "rx_unicast_packets",
123                 VPORT_COUNTER_OFF(received_eth_unicast.packets) },
124         { "rx_unicast_bytes", VPORT_COUNTER_OFF(received_eth_unicast.octets) },
125         { "tx_unicast_packets",
126                 VPORT_COUNTER_OFF(transmitted_eth_unicast.packets) },
127         { "tx_unicast_bytes",
128                 VPORT_COUNTER_OFF(transmitted_eth_unicast.octets) },
129         { "rx_multicast_packets",
130                 VPORT_COUNTER_OFF(received_eth_multicast.packets) },
131         { "rx_multicast_bytes",
132                 VPORT_COUNTER_OFF(received_eth_multicast.octets) },
133         { "tx_multicast_packets",
134                 VPORT_COUNTER_OFF(transmitted_eth_multicast.packets) },
135         { "tx_multicast_bytes",
136                 VPORT_COUNTER_OFF(transmitted_eth_multicast.octets) },
137         { "rx_broadcast_packets",
138                 VPORT_COUNTER_OFF(received_eth_broadcast.packets) },
139         { "rx_broadcast_bytes",
140                 VPORT_COUNTER_OFF(received_eth_broadcast.octets) },
141         { "tx_broadcast_packets",
142                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.packets) },
143         { "tx_broadcast_bytes",
144                 VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
145 };
146
147 #define PPORT_802_3_OFF(c) \
148         MLX5_BYTE_OFF(ppcnt_reg, \
149                       counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
150 #define PPORT_802_3_GET(pstats, c) \
151         MLX5_GET64(ppcnt_reg, pstats->IEEE_802_3_counters, \
152                    counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
153 #define PPORT_2863_OFF(c) \
154         MLX5_BYTE_OFF(ppcnt_reg, \
155                       counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
156 #define PPORT_2863_GET(pstats, c) \
157         MLX5_GET64(ppcnt_reg, pstats->RFC_2863_counters, \
158                    counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
159 #define PPORT_2819_OFF(c) \
160         MLX5_BYTE_OFF(ppcnt_reg, \
161                       counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
162 #define PPORT_2819_GET(pstats, c) \
163         MLX5_GET64(ppcnt_reg, pstats->RFC_2819_counters, \
164                    counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
165
166 struct mlx5e_pport_stats {
167         __be64 IEEE_802_3_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
168         __be64 RFC_2863_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
169         __be64 RFC_2819_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
170 };
171
172 static const struct counter_desc pport_802_3_stats_desc[] = {
173         { "frames_tx", PPORT_802_3_OFF(a_frames_transmitted_ok) },
174         { "frames_rx", PPORT_802_3_OFF(a_frames_received_ok) },
175         { "check_seq_err", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
176         { "alignment_err", PPORT_802_3_OFF(a_alignment_errors) },
177         { "octets_tx", PPORT_802_3_OFF(a_octets_transmitted_ok) },
178         { "octets_received", PPORT_802_3_OFF(a_octets_received_ok) },
179         { "multicast_xmitted", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
180         { "broadcast_xmitted", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
181         { "multicast_rx", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
182         { "broadcast_rx", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
183         { "in_range_len_errors", PPORT_802_3_OFF(a_in_range_length_errors) },
184         { "out_of_range_len", PPORT_802_3_OFF(a_out_of_range_length_field) },
185         { "too_long_errors", PPORT_802_3_OFF(a_frame_too_long_errors) },
186         { "symbol_err", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
187         { "mac_control_tx", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
188         { "mac_control_rx", PPORT_802_3_OFF(a_mac_control_frames_received) },
189         { "unsupported_op_rx",
190                 PPORT_802_3_OFF(a_unsupported_opcodes_received) },
191         { "pause_ctrl_rx", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
192         { "pause_ctrl_tx",
193                 PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
194 };
195
196 static const struct counter_desc pport_2863_stats_desc[] = {
197         { "in_octets", PPORT_2863_OFF(if_in_octets) },
198         { "in_ucast_pkts", PPORT_2863_OFF(if_in_ucast_pkts) },
199         { "in_discards", PPORT_2863_OFF(if_in_discards) },
200         { "in_errors", PPORT_2863_OFF(if_in_errors) },
201         { "in_unknown_protos", PPORT_2863_OFF(if_in_unknown_protos) },
202         { "out_octets", PPORT_2863_OFF(if_out_octets) },
203         { "out_ucast_pkts", PPORT_2863_OFF(if_out_ucast_pkts) },
204         { "out_discards", PPORT_2863_OFF(if_out_discards) },
205         { "out_errors", PPORT_2863_OFF(if_out_errors) },
206         { "in_multicast_pkts", PPORT_2863_OFF(if_in_multicast_pkts) },
207         { "in_broadcast_pkts", PPORT_2863_OFF(if_in_broadcast_pkts) },
208         { "out_multicast_pkts", PPORT_2863_OFF(if_out_multicast_pkts) },
209         { "out_broadcast_pkts", PPORT_2863_OFF(if_out_broadcast_pkts) },
210 };
211
212 static const struct counter_desc pport_2819_stats_desc[] = {
213         { "drop_events", PPORT_2819_OFF(ether_stats_drop_events) },
214         { "octets", PPORT_2819_OFF(ether_stats_octets) },
215         { "pkts", PPORT_2819_OFF(ether_stats_pkts) },
216         { "broadcast_pkts", PPORT_2819_OFF(ether_stats_broadcast_pkts) },
217         { "multicast_pkts", PPORT_2819_OFF(ether_stats_multicast_pkts) },
218         { "crc_align_errors", PPORT_2819_OFF(ether_stats_crc_align_errors) },
219         { "undersize_pkts", PPORT_2819_OFF(ether_stats_undersize_pkts) },
220         { "oversize_pkts", PPORT_2819_OFF(ether_stats_oversize_pkts) },
221         { "fragments", PPORT_2819_OFF(ether_stats_fragments) },
222         { "jabbers", PPORT_2819_OFF(ether_stats_jabbers) },
223         { "collisions", PPORT_2819_OFF(ether_stats_collisions) },
224         { "p64octets", PPORT_2819_OFF(ether_stats_pkts64octets) },
225         { "p65to127octets", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
226         { "p128to255octets", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
227         { "p256to511octets", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
228         { "p512to1023octets", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
229         { "p1024to1518octets",
230                 PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
231         { "p1519to2047octets",
232                 PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
233         { "p2048to4095octets",
234                 PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
235         { "p4096to8191octets",
236                 PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
237         { "p8192to10239octets",
238                 PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
239 };
240
241 struct mlx5e_rq_stats {
242         u64 packets;
243         u64 bytes;
244         u64 csum_none;
245         u64 csum_sw;
246         u64 lro_packets;
247         u64 lro_bytes;
248         u64 wqe_err;
249         u64 mpwqe_filler;
250         u64 mpwqe_frag;
251         u64 buff_alloc_err;
252 };
253
254 static const struct counter_desc rq_stats_desc[] = {
255         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, packets) },
256         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, bytes) },
257         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_none) },
258         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_sw) },
259         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_packets) },
260         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_bytes) },
261         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, wqe_err) },
262         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_filler) },
263         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_frag) },
264         { MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
265 };
266
267 struct mlx5e_sq_stats {
268         /* commonly accessed in data path */
269         u64 packets;
270         u64 bytes;
271         u64 tso_packets;
272         u64 tso_bytes;
273         u64 tso_inner_packets;
274         u64 tso_inner_bytes;
275         u64 csum_offload_inner;
276         u64 nop;
277         /* less likely accessed in data path */
278         u64 csum_offload_none;
279         u64 stopped;
280         u64 wake;
281         u64 dropped;
282 };
283
284 static const struct counter_desc sq_stats_desc[] = {
285         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, packets) },
286         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, bytes) },
287         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_packets) },
288         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_bytes) },
289         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
290         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
291         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_inner) },
292         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, nop) },
293         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_none) },
294         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, stopped) },
295         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, wake) },
296         { MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, dropped) },
297 };
298
299 #define NUM_SW_COUNTERS                 ARRAY_SIZE(sw_stats_desc)
300 #define NUM_Q_COUNTERS                  ARRAY_SIZE(q_stats_desc)
301 #define NUM_VPORT_COUNTERS              ARRAY_SIZE(vport_stats_desc)
302 #define NUM_PPORT_802_3_COUNTERS        ARRAY_SIZE(pport_802_3_stats_desc)
303 #define NUM_PPORT_2863_COUNTERS         ARRAY_SIZE(pport_2863_stats_desc)
304 #define NUM_PPORT_2819_COUNTERS         ARRAY_SIZE(pport_2819_stats_desc)
305 #define NUM_PPORT_COUNTERS              (NUM_PPORT_802_3_COUNTERS + \
306                                          NUM_PPORT_2863_COUNTERS  + \
307                                          NUM_PPORT_2819_COUNTERS)
308 #define NUM_RQ_STATS                    ARRAY_SIZE(rq_stats_desc)
309 #define NUM_SQ_STATS                    ARRAY_SIZE(sq_stats_desc)
310
311 struct mlx5e_stats {
312         struct mlx5e_sw_stats sw;
313         struct mlx5e_qcounter_stats qcnt;
314         struct mlx5e_vport_stats vport;
315         struct mlx5e_pport_stats pport;
316 };
317
318 #endif /* __MLX5_EN_STATS_H__ */