xref: /freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_port.c (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1 /*
2  * Copyright (c) 2007, 2014 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  */
33 
34 #include <sys/types.h>
35 #include <linux/if_vlan.h>
36 
37 #include <dev/mlx4/device.h>
38 #include <dev/mlx4/cmd.h>
39 
40 #include "en_port.h"
41 #include "en.h"
42 #define EN_IFQ_MIN_INTERVAL 3000
43 
44 
45 int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv)
46 {
47 	struct mlx4_cmd_mailbox *mailbox;
48 	struct mlx4_set_vlan_fltr_mbox *filter;
49 	int i;
50 	int j;
51 	int index = 0;
52 	u32 entry;
53 	int err = 0;
54 
55 	mailbox = mlx4_alloc_cmd_mailbox(dev);
56 	if (IS_ERR(mailbox))
57 		return PTR_ERR(mailbox);
58 
59 	filter = mailbox->buf;
60 	memset(filter, 0, sizeof(*filter));
61 	for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) {
62 		entry = 0;
63 		for (j = 0; j < 32; j++) {
64 			if (test_bit(index, priv->active_vlans))
65 				entry |= 1 << j;
66 			index++;
67 		}
68 		filter->entry[i] = cpu_to_be32(entry);
69 	}
70 	err = mlx4_cmd(dev, mailbox->dma, priv->port, 0, MLX4_CMD_SET_VLAN_FLTR,
71 		       MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
72 	mlx4_free_cmd_mailbox(dev, mailbox);
73 	return err;
74 }
75 
76 int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port)
77 {
78 	struct mlx4_en_query_port_context *qport_context;
79 	struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
80 	struct mlx4_en_port_state *state = &priv->port_state;
81 	struct mlx4_cmd_mailbox *mailbox;
82 	int err;
83 
84 	mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
85 	if (IS_ERR(mailbox))
86 		return PTR_ERR(mailbox);
87 	memset(mailbox->buf, 0, sizeof(*qport_context));
88 	err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0,
89 			   MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
90 			   MLX4_CMD_WRAPPED);
91 	if (err)
92 		goto out;
93 	qport_context = mailbox->buf;
94 
95 	/* This command is always accessed from Ethtool context
96 	 * already synchronized, no need in locking */
97 	state->link_state = !!(qport_context->link_up & MLX4_EN_LINK_UP_MASK);
98 	switch (qport_context->link_speed & MLX4_EN_SPEED_MASK) {
99 	case MLX4_EN_1G_SPEED:
100 		state->link_speed = 1000;
101 		break;
102 	case MLX4_EN_10G_SPEED_XAUI:
103 	case MLX4_EN_10G_SPEED_XFI:
104 		state->link_speed = 10000;
105 		break;
106 	case MLX4_EN_20G_SPEED:
107 		state->link_speed = 20000;
108 		break;
109 	case MLX4_EN_40G_SPEED:
110 		state->link_speed = 40000;
111 		break;
112 	case MLX4_EN_56G_SPEED:
113 		state->link_speed = 56000;
114 		break;
115 	default:
116 		state->link_speed = -1;
117 		break;
118 	}
119 	state->transciver = qport_context->transceiver;
120 	state->autoneg = !!(qport_context->autoneg & MLX4_EN_AUTONEG_MASK);
121 
122 out:
123 	mlx4_free_cmd_mailbox(mdev->dev, mailbox);
124 	return err;
125 }
126 
127 int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
128 {
129 	struct mlx4_en_stat_out_mbox *mlx4_en_stats;
130 	struct mlx4_en_stat_out_flow_control_mbox *flowstats;
131 	struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
132 	struct mlx4_en_vport_stats *vport_stats = &priv->vport_stats;
133 	struct mlx4_cmd_mailbox *mailbox = NULL;
134 	struct mlx4_cmd_mailbox *mailbox_flow = NULL;
135 	u64 in_mod = reset << 8 | port;
136 	int err;
137 	int i;
138 	int do_if_stat = 1;
139 	unsigned long period = (unsigned long) (jiffies - priv->last_ifq_jiffies);
140 	struct mlx4_en_vport_stats tmp_vport_stats;
141         struct net_device *dev;
142 
143 	if (jiffies_to_msecs(period) < EN_IFQ_MIN_INTERVAL ||
144 				priv->counter_index == 0xff)
145 		do_if_stat = 0;
146 
147 	mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
148 	if (IS_ERR(mailbox)) {
149 		err = PTR_ERR(mailbox);
150 		goto mailbox_out;
151 	}
152 
153 	mailbox_flow = mlx4_alloc_cmd_mailbox(mdev->dev);
154 	if (IS_ERR(mailbox_flow)) {
155 		mlx4_free_cmd_mailbox(mdev->dev, mailbox);
156 		err = PTR_ERR(mailbox_flow);
157 		goto mailbox_out;
158 	}
159 
160 	/* 0xffs indicates invalid value */
161 	memset(mailbox_flow->buf, 0xff, sizeof(*flowstats) *
162 		MLX4_NUM_PRIORITIES);
163 
164 	if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN) {
165 		memset(mailbox_flow->buf, 0, sizeof(*flowstats));
166 		err = mlx4_cmd_box(mdev->dev, 0, mailbox_flow->dma,
167 				   in_mod | 1<<12, 0, MLX4_CMD_DUMP_ETH_STATS,
168 				   MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
169 
170 		if (err)
171 			goto out;
172 	}
173 
174 	err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
175 			   MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
176 			   MLX4_CMD_NATIVE);
177 	if (err)
178 		goto out;
179 
180 	mlx4_en_stats = mailbox->buf;
181 
182 	spin_lock(&priv->stats_lock);
183 
184 	priv->port_stats.rx_chksum_good = 0;
185 	priv->port_stats.rx_chksum_none = 0;
186 	for (i = 0; i < priv->rx_ring_num; i++) {
187 		priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok;
188 		priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none;
189 	}
190 
191 	priv->port_stats.tx_chksum_offload = 0;
192 	priv->port_stats.queue_stopped = 0;
193 	priv->port_stats.wake_queue = 0;
194 	for (i = 0; i < priv->tx_ring_num; i++) {
195 		priv->port_stats.tx_chksum_offload += priv->tx_ring[i]->tx_csum;
196 		priv->port_stats.queue_stopped += priv->tx_ring[i]->queue_stopped;
197 		priv->port_stats.wake_queue += priv->tx_ring[i]->wake_queue;
198 		priv->port_stats.oversized_packets += priv->tx_ring[i]->oversized_packets;
199 	}
200 	/* RX Statistics */
201 	priv->pkstats.rx_packets = be64_to_cpu(mlx4_en_stats->RTOT_prio_0) +
202 		be64_to_cpu(mlx4_en_stats->RTOT_prio_1) +
203 		be64_to_cpu(mlx4_en_stats->RTOT_prio_2) +
204 		be64_to_cpu(mlx4_en_stats->RTOT_prio_3) +
205 		be64_to_cpu(mlx4_en_stats->RTOT_prio_4) +
206 		be64_to_cpu(mlx4_en_stats->RTOT_prio_5) +
207 		be64_to_cpu(mlx4_en_stats->RTOT_prio_6) +
208 		be64_to_cpu(mlx4_en_stats->RTOT_prio_7) +
209 		be64_to_cpu(mlx4_en_stats->RTOT_novlan);
210 	priv->pkstats.rx_bytes = be64_to_cpu(mlx4_en_stats->ROCT_prio_0) +
211 		be64_to_cpu(mlx4_en_stats->ROCT_prio_1) +
212 		be64_to_cpu(mlx4_en_stats->ROCT_prio_2) +
213 		be64_to_cpu(mlx4_en_stats->ROCT_prio_3) +
214 		be64_to_cpu(mlx4_en_stats->ROCT_prio_4) +
215 		be64_to_cpu(mlx4_en_stats->ROCT_prio_5) +
216 		be64_to_cpu(mlx4_en_stats->ROCT_prio_6) +
217 		be64_to_cpu(mlx4_en_stats->ROCT_prio_7) +
218 		be64_to_cpu(mlx4_en_stats->ROCT_novlan);
219 	priv->pkstats.rx_multicast_packets = be64_to_cpu(mlx4_en_stats->MCAST_prio_0) +
220 		be64_to_cpu(mlx4_en_stats->MCAST_prio_1) +
221 		be64_to_cpu(mlx4_en_stats->MCAST_prio_2) +
222 		be64_to_cpu(mlx4_en_stats->MCAST_prio_3) +
223 		be64_to_cpu(mlx4_en_stats->MCAST_prio_4) +
224 		be64_to_cpu(mlx4_en_stats->MCAST_prio_5) +
225 		be64_to_cpu(mlx4_en_stats->MCAST_prio_6) +
226 		be64_to_cpu(mlx4_en_stats->MCAST_prio_7) +
227 		be64_to_cpu(mlx4_en_stats->MCAST_novlan);
228 	priv->pkstats.rx_broadcast_packets = be64_to_cpu(mlx4_en_stats->RBCAST_prio_0) +
229 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_1) +
230 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_2) +
231 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_3) +
232 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_4) +
233 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_5) +
234 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_6) +
235 		be64_to_cpu(mlx4_en_stats->RBCAST_prio_7) +
236 		be64_to_cpu(mlx4_en_stats->RBCAST_novlan);
237 	priv->pkstats.rx_errors = be64_to_cpu(mlx4_en_stats->PCS) +
238 		be32_to_cpu(mlx4_en_stats->RJBBR) +
239 		be32_to_cpu(mlx4_en_stats->RCRC) +
240 		be32_to_cpu(mlx4_en_stats->RRUNT) +
241 		be64_to_cpu(mlx4_en_stats->RInRangeLengthErr) +
242 		be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr) +
243 		be32_to_cpu(mlx4_en_stats->RSHORT) +
244 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_0) +
245 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_1) +
246 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_2) +
247 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_3) +
248 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_4) +
249 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_5) +
250 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_6) +
251 		be64_to_cpu(mlx4_en_stats->RGIANT_prio_7) +
252 		be64_to_cpu(mlx4_en_stats->RGIANT_novlan);
253 	priv->pkstats.rx_dropped = be32_to_cpu(mlx4_en_stats->RdropOvflw);
254 	priv->pkstats.rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
255 	priv->pkstats.rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
256 	priv->pkstats.rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
257 	priv->pkstats.rx_jabbers = be32_to_cpu(mlx4_en_stats->RJBBR);
258 	priv->pkstats.rx_in_range_length_error = be64_to_cpu(mlx4_en_stats->RInRangeLengthErr);
259 	priv->pkstats.rx_out_range_length_error = be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr);
260 	priv->pkstats.rx_lt_64_bytes_packets = be64_to_cpu(mlx4_en_stats->R64_prio_0) +
261 		be64_to_cpu(mlx4_en_stats->R64_prio_1) +
262 		be64_to_cpu(mlx4_en_stats->R64_prio_2) +
263 		be64_to_cpu(mlx4_en_stats->R64_prio_3) +
264 		be64_to_cpu(mlx4_en_stats->R64_prio_4) +
265 		be64_to_cpu(mlx4_en_stats->R64_prio_5) +
266 		be64_to_cpu(mlx4_en_stats->R64_prio_6) +
267 		be64_to_cpu(mlx4_en_stats->R64_prio_7) +
268 		be64_to_cpu(mlx4_en_stats->R64_novlan);
269 	priv->pkstats.rx_127_bytes_packets = be64_to_cpu(mlx4_en_stats->R127_prio_0) +
270 		be64_to_cpu(mlx4_en_stats->R127_prio_1) +
271 		be64_to_cpu(mlx4_en_stats->R127_prio_2) +
272 		be64_to_cpu(mlx4_en_stats->R127_prio_3) +
273 		be64_to_cpu(mlx4_en_stats->R127_prio_4) +
274 		be64_to_cpu(mlx4_en_stats->R127_prio_5) +
275 		be64_to_cpu(mlx4_en_stats->R127_prio_6) +
276 		be64_to_cpu(mlx4_en_stats->R127_prio_7) +
277 		be64_to_cpu(mlx4_en_stats->R127_novlan);
278 	priv->pkstats.rx_255_bytes_packets = be64_to_cpu(mlx4_en_stats->R255_prio_0) +
279 		be64_to_cpu(mlx4_en_stats->R255_prio_1) +
280 		be64_to_cpu(mlx4_en_stats->R255_prio_2) +
281 		be64_to_cpu(mlx4_en_stats->R255_prio_3) +
282 		be64_to_cpu(mlx4_en_stats->R255_prio_4) +
283 		be64_to_cpu(mlx4_en_stats->R255_prio_5) +
284 		be64_to_cpu(mlx4_en_stats->R255_prio_6) +
285 		be64_to_cpu(mlx4_en_stats->R255_prio_7) +
286 		be64_to_cpu(mlx4_en_stats->R255_novlan);
287 	priv->pkstats.rx_511_bytes_packets = be64_to_cpu(mlx4_en_stats->R511_prio_0) +
288 		be64_to_cpu(mlx4_en_stats->R511_prio_1) +
289 		be64_to_cpu(mlx4_en_stats->R511_prio_2) +
290 		be64_to_cpu(mlx4_en_stats->R511_prio_3) +
291 		be64_to_cpu(mlx4_en_stats->R511_prio_4) +
292 		be64_to_cpu(mlx4_en_stats->R511_prio_5) +
293 		be64_to_cpu(mlx4_en_stats->R511_prio_6) +
294 		be64_to_cpu(mlx4_en_stats->R511_prio_7) +
295 		be64_to_cpu(mlx4_en_stats->R511_novlan);
296 	priv->pkstats.rx_1023_bytes_packets = be64_to_cpu(mlx4_en_stats->R1023_prio_0) +
297 		be64_to_cpu(mlx4_en_stats->R1023_prio_1) +
298 		be64_to_cpu(mlx4_en_stats->R1023_prio_2) +
299 		be64_to_cpu(mlx4_en_stats->R1023_prio_3) +
300 		be64_to_cpu(mlx4_en_stats->R1023_prio_4) +
301 		be64_to_cpu(mlx4_en_stats->R1023_prio_5) +
302 		be64_to_cpu(mlx4_en_stats->R1023_prio_6) +
303 		be64_to_cpu(mlx4_en_stats->R1023_prio_7) +
304 		be64_to_cpu(mlx4_en_stats->R1023_novlan);
305 	priv->pkstats.rx_1518_bytes_packets = be64_to_cpu(mlx4_en_stats->R1518_prio_0) +
306 		be64_to_cpu(mlx4_en_stats->R1518_prio_1) +
307 		be64_to_cpu(mlx4_en_stats->R1518_prio_2) +
308 		be64_to_cpu(mlx4_en_stats->R1518_prio_3) +
309 		be64_to_cpu(mlx4_en_stats->R1518_prio_4) +
310 		be64_to_cpu(mlx4_en_stats->R1518_prio_5) +
311 		be64_to_cpu(mlx4_en_stats->R1518_prio_6) +
312 		be64_to_cpu(mlx4_en_stats->R1518_prio_7) +
313 		be64_to_cpu(mlx4_en_stats->R1518_novlan);
314 	priv->pkstats.rx_1522_bytes_packets = be64_to_cpu(mlx4_en_stats->R1522_prio_0) +
315 		be64_to_cpu(mlx4_en_stats->R1522_prio_1) +
316 		be64_to_cpu(mlx4_en_stats->R1522_prio_2) +
317 		be64_to_cpu(mlx4_en_stats->R1522_prio_3) +
318 		be64_to_cpu(mlx4_en_stats->R1522_prio_4) +
319 		be64_to_cpu(mlx4_en_stats->R1522_prio_5) +
320 		be64_to_cpu(mlx4_en_stats->R1522_prio_6) +
321 		be64_to_cpu(mlx4_en_stats->R1522_prio_7) +
322 		be64_to_cpu(mlx4_en_stats->R1522_novlan);
323 	priv->pkstats.rx_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->R1548_prio_0) +
324 		be64_to_cpu(mlx4_en_stats->R1548_prio_1) +
325 		be64_to_cpu(mlx4_en_stats->R1548_prio_2) +
326 		be64_to_cpu(mlx4_en_stats->R1548_prio_3) +
327 		be64_to_cpu(mlx4_en_stats->R1548_prio_4) +
328 		be64_to_cpu(mlx4_en_stats->R1548_prio_5) +
329 		be64_to_cpu(mlx4_en_stats->R1548_prio_6) +
330 		be64_to_cpu(mlx4_en_stats->R1548_prio_7) +
331 		be64_to_cpu(mlx4_en_stats->R1548_novlan);
332 	priv->pkstats.rx_gt_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->R2MTU_prio_0) +
333 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_1) +
334 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_2) +
335 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_3) +
336 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_4) +
337 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_5) +
338 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_6) +
339 		be64_to_cpu(mlx4_en_stats->R2MTU_prio_7) +
340 		be64_to_cpu(mlx4_en_stats->R2MTU_novlan);
341 
342 	/* Tx Stats */
343 	priv->pkstats.tx_packets = be64_to_cpu(mlx4_en_stats->TTOT_prio_0) +
344 		be64_to_cpu(mlx4_en_stats->TTOT_prio_1) +
345 		be64_to_cpu(mlx4_en_stats->TTOT_prio_2) +
346 		be64_to_cpu(mlx4_en_stats->TTOT_prio_3) +
347 		be64_to_cpu(mlx4_en_stats->TTOT_prio_4) +
348 		be64_to_cpu(mlx4_en_stats->TTOT_prio_5) +
349 		be64_to_cpu(mlx4_en_stats->TTOT_prio_6) +
350 		be64_to_cpu(mlx4_en_stats->TTOT_prio_7) +
351 		be64_to_cpu(mlx4_en_stats->TTOT_novlan);
352 	priv->pkstats.tx_bytes = be64_to_cpu(mlx4_en_stats->TOCT_prio_0) +
353 		be64_to_cpu(mlx4_en_stats->TOCT_prio_1) +
354 		be64_to_cpu(mlx4_en_stats->TOCT_prio_2) +
355 		be64_to_cpu(mlx4_en_stats->TOCT_prio_3) +
356 		be64_to_cpu(mlx4_en_stats->TOCT_prio_4) +
357 		be64_to_cpu(mlx4_en_stats->TOCT_prio_5) +
358 		be64_to_cpu(mlx4_en_stats->TOCT_prio_6) +
359 		be64_to_cpu(mlx4_en_stats->TOCT_prio_7) +
360 		be64_to_cpu(mlx4_en_stats->TOCT_novlan);
361 	priv->pkstats.tx_multicast_packets = be64_to_cpu(mlx4_en_stats->TMCAST_prio_0) +
362 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_1) +
363 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_2) +
364 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_3) +
365 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_4) +
366 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_5) +
367 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_6) +
368 		be64_to_cpu(mlx4_en_stats->TMCAST_prio_7) +
369 		be64_to_cpu(mlx4_en_stats->TMCAST_novlan);
370 	priv->pkstats.tx_broadcast_packets = be64_to_cpu(mlx4_en_stats->TBCAST_prio_0) +
371 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_1) +
372 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_2) +
373 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_3) +
374 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_4) +
375 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_5) +
376 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_6) +
377 		be64_to_cpu(mlx4_en_stats->TBCAST_prio_7) +
378 		be64_to_cpu(mlx4_en_stats->TBCAST_novlan);
379 	priv->pkstats.tx_errors = be64_to_cpu(mlx4_en_stats->TGIANT_prio_0) +
380 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_1) +
381 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_2) +
382 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_3) +
383 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_4) +
384 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_5) +
385 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_6) +
386 		be64_to_cpu(mlx4_en_stats->TGIANT_prio_7) +
387 		be64_to_cpu(mlx4_en_stats->TGIANT_novlan);
388 	priv->pkstats.tx_dropped = be32_to_cpu(mlx4_en_stats->TDROP) -
389 		priv->pkstats.tx_errors;
390 	priv->pkstats.tx_lt_64_bytes_packets = be64_to_cpu(mlx4_en_stats->T64_prio_0) +
391 		be64_to_cpu(mlx4_en_stats->T64_prio_1) +
392 		be64_to_cpu(mlx4_en_stats->T64_prio_2) +
393 		be64_to_cpu(mlx4_en_stats->T64_prio_3) +
394 		be64_to_cpu(mlx4_en_stats->T64_prio_4) +
395 		be64_to_cpu(mlx4_en_stats->T64_prio_5) +
396 		be64_to_cpu(mlx4_en_stats->T64_prio_6) +
397 		be64_to_cpu(mlx4_en_stats->T64_prio_7) +
398 		be64_to_cpu(mlx4_en_stats->T64_novlan);
399 	priv->pkstats.tx_127_bytes_packets = be64_to_cpu(mlx4_en_stats->T127_prio_0) +
400 		be64_to_cpu(mlx4_en_stats->T127_prio_1) +
401 		be64_to_cpu(mlx4_en_stats->T127_prio_2) +
402 		be64_to_cpu(mlx4_en_stats->T127_prio_3) +
403 		be64_to_cpu(mlx4_en_stats->T127_prio_4) +
404 		be64_to_cpu(mlx4_en_stats->T127_prio_5) +
405 		be64_to_cpu(mlx4_en_stats->T127_prio_6) +
406 		be64_to_cpu(mlx4_en_stats->T127_prio_7) +
407 		be64_to_cpu(mlx4_en_stats->T127_novlan);
408 	priv->pkstats.tx_255_bytes_packets = be64_to_cpu(mlx4_en_stats->T255_prio_0) +
409 		be64_to_cpu(mlx4_en_stats->T255_prio_1) +
410 		be64_to_cpu(mlx4_en_stats->T255_prio_2) +
411 		be64_to_cpu(mlx4_en_stats->T255_prio_3) +
412 		be64_to_cpu(mlx4_en_stats->T255_prio_4) +
413 		be64_to_cpu(mlx4_en_stats->T255_prio_5) +
414 		be64_to_cpu(mlx4_en_stats->T255_prio_6) +
415 		be64_to_cpu(mlx4_en_stats->T255_prio_7) +
416 		be64_to_cpu(mlx4_en_stats->T255_novlan);
417 	priv->pkstats.tx_511_bytes_packets = be64_to_cpu(mlx4_en_stats->T511_prio_0) +
418 		be64_to_cpu(mlx4_en_stats->T511_prio_1) +
419 		be64_to_cpu(mlx4_en_stats->T511_prio_2) +
420 		be64_to_cpu(mlx4_en_stats->T511_prio_3) +
421 		be64_to_cpu(mlx4_en_stats->T511_prio_4) +
422 		be64_to_cpu(mlx4_en_stats->T511_prio_5) +
423 		be64_to_cpu(mlx4_en_stats->T511_prio_6) +
424 		be64_to_cpu(mlx4_en_stats->T511_prio_7) +
425 		be64_to_cpu(mlx4_en_stats->T511_novlan);
426 	priv->pkstats.tx_1023_bytes_packets = be64_to_cpu(mlx4_en_stats->T1023_prio_0) +
427 		be64_to_cpu(mlx4_en_stats->T1023_prio_1) +
428 		be64_to_cpu(mlx4_en_stats->T1023_prio_2) +
429 		be64_to_cpu(mlx4_en_stats->T1023_prio_3) +
430 		be64_to_cpu(mlx4_en_stats->T1023_prio_4) +
431 		be64_to_cpu(mlx4_en_stats->T1023_prio_5) +
432 		be64_to_cpu(mlx4_en_stats->T1023_prio_6) +
433 		be64_to_cpu(mlx4_en_stats->T1023_prio_7) +
434 		be64_to_cpu(mlx4_en_stats->T1023_novlan);
435 	priv->pkstats.tx_1518_bytes_packets = be64_to_cpu(mlx4_en_stats->T1518_prio_0) +
436 		be64_to_cpu(mlx4_en_stats->T1518_prio_1) +
437 		be64_to_cpu(mlx4_en_stats->T1518_prio_2) +
438 		be64_to_cpu(mlx4_en_stats->T1518_prio_3) +
439 		be64_to_cpu(mlx4_en_stats->T1518_prio_4) +
440 		be64_to_cpu(mlx4_en_stats->T1518_prio_5) +
441 		be64_to_cpu(mlx4_en_stats->T1518_prio_6) +
442 		be64_to_cpu(mlx4_en_stats->T1518_prio_7) +
443 		be64_to_cpu(mlx4_en_stats->T1518_novlan);
444 	priv->pkstats.tx_1522_bytes_packets = be64_to_cpu(mlx4_en_stats->T1522_prio_0) +
445 		be64_to_cpu(mlx4_en_stats->T1522_prio_1) +
446 		be64_to_cpu(mlx4_en_stats->T1522_prio_2) +
447 		be64_to_cpu(mlx4_en_stats->T1522_prio_3) +
448 		be64_to_cpu(mlx4_en_stats->T1522_prio_4) +
449 		be64_to_cpu(mlx4_en_stats->T1522_prio_5) +
450 		be64_to_cpu(mlx4_en_stats->T1522_prio_6) +
451 		be64_to_cpu(mlx4_en_stats->T1522_prio_7) +
452 		be64_to_cpu(mlx4_en_stats->T1522_novlan);
453 	priv->pkstats.tx_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->T1548_prio_0) +
454 		be64_to_cpu(mlx4_en_stats->T1548_prio_1) +
455 		be64_to_cpu(mlx4_en_stats->T1548_prio_2) +
456 		be64_to_cpu(mlx4_en_stats->T1548_prio_3) +
457 		be64_to_cpu(mlx4_en_stats->T1548_prio_4) +
458 		be64_to_cpu(mlx4_en_stats->T1548_prio_5) +
459 		be64_to_cpu(mlx4_en_stats->T1548_prio_6) +
460 		be64_to_cpu(mlx4_en_stats->T1548_prio_7) +
461 		be64_to_cpu(mlx4_en_stats->T1548_novlan);
462 	priv->pkstats.tx_gt_1548_bytes_packets = be64_to_cpu(mlx4_en_stats->T2MTU_prio_0) +
463 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_1) +
464 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_2) +
465 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_3) +
466 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_4) +
467 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_5) +
468 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_6) +
469 		be64_to_cpu(mlx4_en_stats->T2MTU_prio_7) +
470 		be64_to_cpu(mlx4_en_stats->T2MTU_novlan);
471 
472 	priv->pkstats.rx_prio[0][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
473 	priv->pkstats.rx_prio[0][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_0);
474 	priv->pkstats.rx_prio[1][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
475 	priv->pkstats.rx_prio[1][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_1);
476 	priv->pkstats.rx_prio[2][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
477 	priv->pkstats.rx_prio[2][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_2);
478 	priv->pkstats.rx_prio[3][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
479 	priv->pkstats.rx_prio[3][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_3);
480 	priv->pkstats.rx_prio[4][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
481 	priv->pkstats.rx_prio[4][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_4);
482 	priv->pkstats.rx_prio[5][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
483 	priv->pkstats.rx_prio[5][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_5);
484 	priv->pkstats.rx_prio[6][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
485 	priv->pkstats.rx_prio[6][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_6);
486 	priv->pkstats.rx_prio[7][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
487 	priv->pkstats.rx_prio[7][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_7);
488 	priv->pkstats.rx_prio[8][0] = be64_to_cpu(mlx4_en_stats->RTOT_novlan);
489 	priv->pkstats.rx_prio[8][1] = be64_to_cpu(mlx4_en_stats->ROCT_novlan);
490 	priv->pkstats.tx_prio[0][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
491 	priv->pkstats.tx_prio[0][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_0);
492 	priv->pkstats.tx_prio[1][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
493 	priv->pkstats.tx_prio[1][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_1);
494 	priv->pkstats.tx_prio[2][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
495 	priv->pkstats.tx_prio[2][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_2);
496 	priv->pkstats.tx_prio[3][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
497 	priv->pkstats.tx_prio[3][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_3);
498 	priv->pkstats.tx_prio[4][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
499 	priv->pkstats.tx_prio[4][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_4);
500 	priv->pkstats.tx_prio[5][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
501 	priv->pkstats.tx_prio[5][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_5);
502 	priv->pkstats.tx_prio[6][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
503 	priv->pkstats.tx_prio[6][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_6);
504 	priv->pkstats.tx_prio[7][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
505 	priv->pkstats.tx_prio[7][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_7);
506 	priv->pkstats.tx_prio[8][0] = be64_to_cpu(mlx4_en_stats->TTOT_novlan);
507 	priv->pkstats.tx_prio[8][1] = be64_to_cpu(mlx4_en_stats->TOCT_novlan);
508 
509 	flowstats = mailbox_flow->buf;
510 
511 	for (i = 0; i < MLX4_NUM_PRIORITIES; i++)	{
512 		priv->flowstats[i].rx_pause =
513 			be64_to_cpu(flowstats[i].rx_pause);
514 		priv->flowstats[i].rx_pause_duration =
515 			be64_to_cpu(flowstats[i].rx_pause_duration);
516 		priv->flowstats[i].rx_pause_transition =
517 			be64_to_cpu(flowstats[i].rx_pause_transition);
518 		priv->flowstats[i].tx_pause =
519 			be64_to_cpu(flowstats[i].tx_pause);
520 		priv->flowstats[i].tx_pause_duration =
521 			be64_to_cpu(flowstats[i].tx_pause_duration);
522 		priv->flowstats[i].tx_pause_transition =
523 			be64_to_cpu(flowstats[i].tx_pause_transition);
524 	}
525 
526 	memset(&tmp_vport_stats, 0, sizeof(tmp_vport_stats));
527 	spin_unlock(&priv->stats_lock);
528 	err = mlx4_get_vport_ethtool_stats(mdev->dev, port,
529 					   &tmp_vport_stats, reset);
530 	spin_lock(&priv->stats_lock);
531 	if (!err) {
532 		/* ethtool stats format */
533 		vport_stats->rx_unicast_packets = tmp_vport_stats.rx_unicast_packets;
534 		vport_stats->rx_unicast_bytes = tmp_vport_stats.rx_unicast_bytes;
535 		vport_stats->rx_multicast_packets = tmp_vport_stats.rx_multicast_packets;
536 		vport_stats->rx_multicast_bytes = tmp_vport_stats.rx_multicast_bytes;
537 		vport_stats->rx_broadcast_packets = tmp_vport_stats.rx_broadcast_packets;
538 		vport_stats->rx_broadcast_bytes = tmp_vport_stats.rx_broadcast_bytes;
539 		vport_stats->rx_dropped = tmp_vport_stats.rx_dropped;
540 		vport_stats->rx_errors = tmp_vport_stats.rx_errors;
541 		vport_stats->tx_unicast_packets = tmp_vport_stats.tx_unicast_packets;
542 		vport_stats->tx_unicast_bytes = tmp_vport_stats.tx_unicast_bytes;
543 		vport_stats->tx_multicast_packets = tmp_vport_stats.tx_multicast_packets;
544 		vport_stats->tx_multicast_bytes = tmp_vport_stats.tx_multicast_bytes;
545 		vport_stats->tx_broadcast_packets = tmp_vport_stats.tx_broadcast_packets;
546 		vport_stats->tx_broadcast_bytes = tmp_vport_stats.tx_broadcast_bytes;
547 		vport_stats->tx_errors = tmp_vport_stats.tx_errors;
548 	}
549 
550 	if (!mlx4_is_mfunc(mdev->dev)) {
551 /* netdevice stats format */
552 #if __FreeBSD_version >= 1100000
553 		if (reset == 0) {
554 			dev                     = mdev->pndev[port];
555 			if_inc_counter(dev, IFCOUNTER_IPACKETS,
556 			    priv->pkstats.rx_packets - priv->pkstats_last.rx_packets);
557 			if_inc_counter(dev, IFCOUNTER_OPACKETS,
558 			    priv->pkstats.tx_packets - priv->pkstats_last.tx_packets);
559 			if_inc_counter(dev, IFCOUNTER_IBYTES,
560 			    priv->pkstats.rx_bytes - priv->pkstats_last.rx_bytes);
561 			if_inc_counter(dev, IFCOUNTER_OBYTES,
562 			    priv->pkstats.tx_bytes - priv->pkstats_last.tx_bytes);
563 			if_inc_counter(dev, IFCOUNTER_IERRORS,
564 			    priv->pkstats.rx_errors - priv->pkstats_last.rx_errors);
565 			if_inc_counter(dev, IFCOUNTER_IQDROPS,
566 			    priv->pkstats.rx_dropped - priv->pkstats_last.rx_dropped);
567 			if_inc_counter(dev, IFCOUNTER_IMCASTS,
568 			    priv->pkstats.rx_multicast_packets - priv->pkstats_last.rx_multicast_packets);
569 			if_inc_counter(dev, IFCOUNTER_OMCASTS,
570 			    priv->pkstats.tx_multicast_packets - priv->pkstats_last.tx_multicast_packets);
571 		}
572 		priv->pkstats_last = priv->pkstats;
573 #else
574 		dev			= mdev->pndev[port];
575 		dev->if_ipackets        = priv->pkstats.rx_packets;
576 		dev->if_opackets        = priv->pkstats.tx_packets;
577 		dev->if_ibytes          = priv->pkstats.rx_bytes;
578 		dev->if_obytes          = priv->pkstats.tx_bytes;
579 		dev->if_ierrors         = priv->pkstats.rx_errors;
580 		dev->if_iqdrops         = priv->pkstats.rx_dropped;
581 		dev->if_imcasts         = priv->pkstats.rx_multicast_packets;
582 		dev->if_omcasts         = priv->pkstats.tx_multicast_packets;
583 		dev->if_collisions      = 0;
584 #endif
585 	}
586 
587 	spin_unlock(&priv->stats_lock);
588 
589 out:
590 	mlx4_free_cmd_mailbox(mdev->dev, mailbox_flow);
591 	mlx4_free_cmd_mailbox(mdev->dev, mailbox);
592 
593 mailbox_out:
594 	if (do_if_stat)
595 		priv->last_ifq_jiffies = jiffies;
596 
597 	return err;
598 }
599