en_stats.h 12.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/*
 * Copyright (c) 2015-2016, Mellanox Technologies. All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef __MLX5_EN_STATS_H__
#define __MLX5_EN_STATS_H__

#define MLX5E_READ_CTR64_CPU(ptr, dsc, i) \
	(*(u64 *)((char *)ptr + dsc[i].offset))
#define MLX5E_READ_CTR64_BE(ptr, dsc, i) \
	be64_to_cpu(*(__be64 *)((char *)ptr + dsc[i].offset))
#define MLX5E_READ_CTR32_CPU(ptr, dsc, i) \
	(*(u32 *)((char *)ptr + dsc[i].offset))
#define MLX5E_READ_CTR32_BE(ptr, dsc, i) \
	be64_to_cpu(*(__be32 *)((char *)ptr + dsc[i].offset))

#define MLX5E_DECLARE_STAT(type, fld) #fld, offsetof(type, fld)

struct counter_desc {
	char		name[ETH_GSTRING_LEN];
	int		offset; /* Byte offset */
};

struct mlx5e_sw_stats {
	u64 rx_packets;
	u64 rx_bytes;
	u64 tx_packets;
	u64 tx_bytes;
	u64 tso_packets;
	u64 tso_bytes;
	u64 tso_inner_packets;
	u64 tso_inner_bytes;
	u64 lro_packets;
	u64 lro_bytes;
	u64 rx_csum_good;
	u64 rx_csum_none;
	u64 rx_csum_sw;
	u64 tx_csum_offload;
	u64 tx_csum_inner;
	u64 tx_queue_stopped;
	u64 tx_queue_wake;
	u64 tx_queue_dropped;
	u64 rx_wqe_err;
	u64 rx_mpwqe_filler;
	u64 rx_mpwqe_frag;
	u64 rx_buff_alloc_err;
};

static const struct counter_desc sw_stats_desc[] = {
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tso_inner_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, lro_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_good) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_none) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_csum_sw) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_offload) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_csum_inner) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_stopped) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_wake) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, tx_queue_dropped) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_wqe_err) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_filler) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_mpwqe_frag) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sw_stats, rx_buff_alloc_err) },
};

struct mlx5e_qcounter_stats {
	u32 rx_out_of_buffer;
};

static const struct counter_desc q_stats_desc[] = {
	{ MLX5E_DECLARE_STAT(struct mlx5e_qcounter_stats, rx_out_of_buffer) },
};

#define VPORT_COUNTER_OFF(c) MLX5_BYTE_OFF(query_vport_counter_out, c)
#define VPORT_COUNTER_GET(vstats, c) MLX5_GET64(query_vport_counter_out, \
						vstats->query_vport_out, c)

struct mlx5e_vport_stats {
	__be64 query_vport_out[MLX5_ST_SZ_QW(query_vport_counter_out)];
};

static const struct counter_desc vport_stats_desc[] = {
118 119 120 121 122 123 124
	{ "rx_vport_error_packets",
		VPORT_COUNTER_OFF(received_errors.packets) },
	{ "rx_vport_error_bytes", VPORT_COUNTER_OFF(received_errors.octets) },
	{ "tx_vport_error_packets",
		VPORT_COUNTER_OFF(transmit_errors.packets) },
	{ "tx_vport_error_bytes", VPORT_COUNTER_OFF(transmit_errors.octets) },
	{ "rx_vport_unicast_packets",
125
		VPORT_COUNTER_OFF(received_eth_unicast.packets) },
126 127 128
	{ "rx_vport_unicast_bytes",
		VPORT_COUNTER_OFF(received_eth_unicast.octets) },
	{ "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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
		VPORT_COUNTER_OFF(transmitted_eth_broadcast.octets) },
};

#define PPORT_802_3_OFF(c) \
	MLX5_BYTE_OFF(ppcnt_reg, \
		      counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
#define PPORT_802_3_GET(pstats, c) \
	MLX5_GET64(ppcnt_reg, pstats->IEEE_802_3_counters, \
		   counter_set.eth_802_3_cntrs_grp_data_layout.c##_high)
#define PPORT_2863_OFF(c) \
	MLX5_BYTE_OFF(ppcnt_reg, \
		      counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
#define PPORT_2863_GET(pstats, c) \
	MLX5_GET64(ppcnt_reg, pstats->RFC_2863_counters, \
		   counter_set.eth_2863_cntrs_grp_data_layout.c##_high)
#define PPORT_2819_OFF(c) \
	MLX5_BYTE_OFF(ppcnt_reg, \
		      counter_set.eth_2819_cntrs_grp_data_layout.c##_high)
#define PPORT_2819_GET(pstats, c) \
	MLX5_GET64(ppcnt_reg, pstats->RFC_2819_counters, \
		   counter_set.eth_2819_cntrs_grp_data_layout.c##_high)

struct mlx5e_pport_stats {
	__be64 IEEE_802_3_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
	__be64 RFC_2863_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
	__be64 RFC_2819_counters[MLX5_ST_SZ_QW(ppcnt_reg)];
};

static const struct counter_desc pport_802_3_stats_desc[] = {
	{ "frames_tx", PPORT_802_3_OFF(a_frames_transmitted_ok) },
	{ "frames_rx", PPORT_802_3_OFF(a_frames_received_ok) },
	{ "check_seq_err", PPORT_802_3_OFF(a_frame_check_sequence_errors) },
	{ "alignment_err", PPORT_802_3_OFF(a_alignment_errors) },
	{ "octets_tx", PPORT_802_3_OFF(a_octets_transmitted_ok) },
	{ "octets_received", PPORT_802_3_OFF(a_octets_received_ok) },
	{ "multicast_xmitted", PPORT_802_3_OFF(a_multicast_frames_xmitted_ok) },
	{ "broadcast_xmitted", PPORT_802_3_OFF(a_broadcast_frames_xmitted_ok) },
	{ "multicast_rx", PPORT_802_3_OFF(a_multicast_frames_received_ok) },
	{ "broadcast_rx", PPORT_802_3_OFF(a_broadcast_frames_received_ok) },
	{ "in_range_len_errors", PPORT_802_3_OFF(a_in_range_length_errors) },
	{ "out_of_range_len", PPORT_802_3_OFF(a_out_of_range_length_field) },
	{ "too_long_errors", PPORT_802_3_OFF(a_frame_too_long_errors) },
	{ "symbol_err", PPORT_802_3_OFF(a_symbol_error_during_carrier) },
	{ "mac_control_tx", PPORT_802_3_OFF(a_mac_control_frames_transmitted) },
	{ "mac_control_rx", PPORT_802_3_OFF(a_mac_control_frames_received) },
	{ "unsupported_op_rx",
		PPORT_802_3_OFF(a_unsupported_opcodes_received) },
	{ "pause_ctrl_rx", PPORT_802_3_OFF(a_pause_mac_ctrl_frames_received) },
	{ "pause_ctrl_tx",
		PPORT_802_3_OFF(a_pause_mac_ctrl_frames_transmitted) },
};

static const struct counter_desc pport_2863_stats_desc[] = {
	{ "in_octets", PPORT_2863_OFF(if_in_octets) },
	{ "in_ucast_pkts", PPORT_2863_OFF(if_in_ucast_pkts) },
	{ "in_discards", PPORT_2863_OFF(if_in_discards) },
	{ "in_errors", PPORT_2863_OFF(if_in_errors) },
	{ "in_unknown_protos", PPORT_2863_OFF(if_in_unknown_protos) },
	{ "out_octets", PPORT_2863_OFF(if_out_octets) },
	{ "out_ucast_pkts", PPORT_2863_OFF(if_out_ucast_pkts) },
	{ "out_discards", PPORT_2863_OFF(if_out_discards) },
	{ "out_errors", PPORT_2863_OFF(if_out_errors) },
	{ "in_multicast_pkts", PPORT_2863_OFF(if_in_multicast_pkts) },
	{ "in_broadcast_pkts", PPORT_2863_OFF(if_in_broadcast_pkts) },
	{ "out_multicast_pkts", PPORT_2863_OFF(if_out_multicast_pkts) },
	{ "out_broadcast_pkts", PPORT_2863_OFF(if_out_broadcast_pkts) },
};

static const struct counter_desc pport_2819_stats_desc[] = {
	{ "drop_events", PPORT_2819_OFF(ether_stats_drop_events) },
	{ "octets", PPORT_2819_OFF(ether_stats_octets) },
	{ "pkts", PPORT_2819_OFF(ether_stats_pkts) },
	{ "broadcast_pkts", PPORT_2819_OFF(ether_stats_broadcast_pkts) },
	{ "multicast_pkts", PPORT_2819_OFF(ether_stats_multicast_pkts) },
	{ "crc_align_errors", PPORT_2819_OFF(ether_stats_crc_align_errors) },
	{ "undersize_pkts", PPORT_2819_OFF(ether_stats_undersize_pkts) },
	{ "oversize_pkts", PPORT_2819_OFF(ether_stats_oversize_pkts) },
	{ "fragments", PPORT_2819_OFF(ether_stats_fragments) },
	{ "jabbers", PPORT_2819_OFF(ether_stats_jabbers) },
	{ "collisions", PPORT_2819_OFF(ether_stats_collisions) },
	{ "p64octets", PPORT_2819_OFF(ether_stats_pkts64octets) },
	{ "p65to127octets", PPORT_2819_OFF(ether_stats_pkts65to127octets) },
	{ "p128to255octets", PPORT_2819_OFF(ether_stats_pkts128to255octets) },
	{ "p256to511octets", PPORT_2819_OFF(ether_stats_pkts256to511octets) },
	{ "p512to1023octets", PPORT_2819_OFF(ether_stats_pkts512to1023octets) },
	{ "p1024to1518octets",
		PPORT_2819_OFF(ether_stats_pkts1024to1518octets) },
	{ "p1519to2047octets",
		PPORT_2819_OFF(ether_stats_pkts1519to2047octets) },
	{ "p2048to4095octets",
		PPORT_2819_OFF(ether_stats_pkts2048to4095octets) },
	{ "p4096to8191octets",
		PPORT_2819_OFF(ether_stats_pkts4096to8191octets) },
	{ "p8192to10239octets",
		PPORT_2819_OFF(ether_stats_pkts8192to10239octets) },
};

struct mlx5e_rq_stats {
	u64 packets;
	u64 bytes;
	u64 csum_none;
	u64 csum_sw;
	u64 lro_packets;
	u64 lro_bytes;
	u64 wqe_err;
	u64 mpwqe_filler;
	u64 mpwqe_frag;
	u64 buff_alloc_err;
};

static const struct counter_desc rq_stats_desc[] = {
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_none) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, csum_sw) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, lro_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, wqe_err) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_filler) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, mpwqe_frag) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_rq_stats, buff_alloc_err) },
};

struct mlx5e_sq_stats {
	/* commonly accessed in data path */
	u64 packets;
	u64 bytes;
	u64 tso_packets;
	u64 tso_bytes;
	u64 tso_inner_packets;
	u64 tso_inner_bytes;
	u64 csum_offload_inner;
	u64 nop;
	/* less likely accessed in data path */
	u64 csum_offload_none;
	u64 stopped;
	u64 wake;
	u64 dropped;
};

static const struct counter_desc sq_stats_desc[] = {
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_packets) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, tso_inner_bytes) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_inner) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, nop) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, csum_offload_none) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, stopped) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, wake) },
	{ MLX5E_DECLARE_STAT(struct mlx5e_sq_stats, dropped) },
};

#define NUM_SW_COUNTERS			ARRAY_SIZE(sw_stats_desc)
#define NUM_Q_COUNTERS			ARRAY_SIZE(q_stats_desc)
#define NUM_VPORT_COUNTERS		ARRAY_SIZE(vport_stats_desc)
#define NUM_PPORT_802_3_COUNTERS	ARRAY_SIZE(pport_802_3_stats_desc)
#define NUM_PPORT_2863_COUNTERS		ARRAY_SIZE(pport_2863_stats_desc)
#define NUM_PPORT_2819_COUNTERS		ARRAY_SIZE(pport_2819_stats_desc)
#define NUM_PPORT_COUNTERS		(NUM_PPORT_802_3_COUNTERS + \
					 NUM_PPORT_2863_COUNTERS  + \
					 NUM_PPORT_2819_COUNTERS)
#define NUM_RQ_STATS			ARRAY_SIZE(rq_stats_desc)
#define NUM_SQ_STATS			ARRAY_SIZE(sq_stats_desc)

struct mlx5e_stats {
	struct mlx5e_sw_stats sw;
	struct mlx5e_qcounter_stats qcnt;
	struct mlx5e_vport_stats vport;
	struct mlx5e_pport_stats pport;
};

#endif /* __MLX5_EN_STATS_H__ */