xref: /freebsd/sys/dev/mlx4/mlx4_en/mlx4_en_port.c (revision 6be3386466ab79a84b48429ae66244f21526d3df)
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 
43 
44 int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv)
45 {
46 	struct mlx4_cmd_mailbox *mailbox;
47 	struct mlx4_set_vlan_fltr_mbox *filter;
48 	int i;
49 	int j;
50 	int index = 0;
51 	u32 entry;
52 	int err = 0;
53 
54 	mailbox = mlx4_alloc_cmd_mailbox(dev);
55 	if (IS_ERR(mailbox))
56 		return PTR_ERR(mailbox);
57 
58 	filter = mailbox->buf;
59 	for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) {
60 		entry = 0;
61 		for (j = 0; j < 32; j++) {
62 			if (test_bit(index, priv->active_vlans))
63 				entry |= 1 << j;
64 			index++;
65 		}
66 		filter->entry[i] = cpu_to_be32(entry);
67 	}
68 	err = mlx4_cmd(dev, mailbox->dma, priv->port, 0, MLX4_CMD_SET_VLAN_FLTR,
69 		       MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
70 	mlx4_free_cmd_mailbox(dev, mailbox);
71 	return err;
72 }
73 
74 int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port)
75 {
76 	struct mlx4_en_query_port_context *qport_context;
77 	struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
78 	struct mlx4_en_port_state *state = &priv->port_state;
79 	struct mlx4_cmd_mailbox *mailbox;
80 	int err;
81 
82 	mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
83 	if (IS_ERR(mailbox))
84 		return PTR_ERR(mailbox);
85 	err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0,
86 			   MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
87 			   MLX4_CMD_WRAPPED);
88 	if (err)
89 		goto out;
90 	qport_context = mailbox->buf;
91 
92 	/* This command is always accessed from Ethtool context
93 	 * already synchronized, no need in locking */
94 	state->link_state = !!(qport_context->link_up & MLX4_EN_LINK_UP_MASK);
95 	switch (qport_context->link_speed & MLX4_EN_SPEED_MASK) {
96 	case MLX4_EN_100M_SPEED:
97 		state->link_speed = 100;
98 		break;
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 
120 	state->transceiver = qport_context->transceiver;
121 
122 	state->flags = 0; /* Reset and recalculate the port flags */
123 	state->flags |= (qport_context->link_up & MLX4_EN_ANC_MASK) ?
124 		MLX4_EN_PORT_ANC : 0;
125 	state->flags |= (qport_context->autoneg & MLX4_EN_AUTONEG_MASK) ?
126 		MLX4_EN_PORT_ANE : 0;
127 
128 out:
129 	mlx4_free_cmd_mailbox(mdev->dev, mailbox);
130 	return err;
131 }
132 
133 /* Each counter set is located in struct mlx4_en_stat_out_mbox
134  * with a const offset between its prio components.
135  * This function runs over a counter set and sum all of it's prio components.
136  */
137 static u64 en_stats_adder(__be64 *start, __be64 *next, int num)
138 {
139 	__be64 *curr = start;
140 	u64 ret = 0;
141 	int i;
142 	int offset = next - start;
143 
144 	for (i = 0; i < num; i++) {
145 		ret += be64_to_cpu(*curr);
146 		curr += offset;
147 	}
148 
149 	return ret;
150 }
151 
152 static void mlx4_en_fold_software_stats(struct net_device *dev)
153 {
154 	struct mlx4_en_priv *priv = netdev_priv(dev);
155 	struct mlx4_en_dev *mdev = priv->mdev;
156 	u64 packets, bytes;
157 	int i;
158 
159 	if (!priv->port_up || mlx4_is_master(mdev->dev))
160 		return;
161 
162 	packets = 0;
163 	bytes = 0;
164 	for (i = 0; i < priv->rx_ring_num; i++) {
165 		const struct mlx4_en_rx_ring *ring = priv->rx_ring[i];
166 
167 		packets += READ_ONCE(ring->packets);
168 		bytes += READ_ONCE(ring->bytes);
169 	}
170 	priv->pkstats.rx_packets = packets;
171 	priv->pkstats.rx_bytes = bytes;
172 
173 	packets = 0;
174 	bytes = 0;
175 	for (i = 0; i < priv->tx_ring_num; i++) {
176 		const struct mlx4_en_tx_ring *ring = priv->tx_ring[i];
177 
178 		packets += READ_ONCE(ring->packets);
179 		bytes += READ_ONCE(ring->bytes);
180 	}
181 	priv->pkstats.tx_packets = packets;
182 	priv->pkstats.tx_bytes = bytes;
183 }
184 
185 int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
186 {
187 	struct mlx4_counter tmp_vport_stats;
188 	struct mlx4_en_stat_out_mbox *mlx4_en_stats;
189 	struct mlx4_en_stat_out_flow_control_mbox *flowstats;
190 	struct net_device *dev = mdev->pndev[port];
191 	struct mlx4_en_priv *priv = netdev_priv(dev);
192 	struct mlx4_en_vport_stats *vport_stats = &priv->vport_stats;
193 	struct mlx4_cmd_mailbox *mailbox;
194 	u64 in_mod = reset << 8 | port;
195 	int err;
196 	int i, counter_index;
197 
198 	mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
199 	if (IS_ERR(mailbox))
200 		return PTR_ERR(mailbox);
201 	err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
202 			   MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
203 			   MLX4_CMD_NATIVE);
204 	if (err)
205 		goto out;
206 
207 	mlx4_en_stats = mailbox->buf;
208 
209 	spin_lock(&priv->stats_lock);
210 
211 	priv->port_stats.rx_chksum_good = 0;
212 	priv->port_stats.rx_chksum_none = 0;
213 	for (i = 0; i < priv->rx_ring_num; i++) {
214 		priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok;
215 		priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none;
216 	}
217 	priv->port_stats.tx_chksum_offload = 0;
218 	priv->port_stats.queue_stopped = 0;
219 	priv->port_stats.wake_queue = 0;
220 	priv->port_stats.oversized_packets = 0;
221 	priv->port_stats.tso_packets = 0;
222 	priv->port_stats.defrag_attempts = 0;
223 
224 	for (i = 0; i < priv->tx_ring_num; i++) {
225 		const struct mlx4_en_tx_ring *ring;
226 		ring = priv->tx_ring[i];
227 
228 		priv->port_stats.tx_chksum_offload += ring->tx_csum;
229 		priv->port_stats.queue_stopped     += ring->queue_stopped;
230 		priv->port_stats.wake_queue        += ring->wake_queue;
231 		priv->port_stats.oversized_packets += ring->oversized_packets;
232 		priv->port_stats.tso_packets       += ring->tso_packets;
233 		priv->port_stats.defrag_attempts   += ring->defrag_attempts;
234 	}
235 
236 	priv->pkstats.rx_errors =
237 			   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 			   en_stats_adder(&mlx4_en_stats->RGIANT_prio_0,
245 					  &mlx4_en_stats->RGIANT_prio_1,
246 					  NUM_PRIORITIES);
247 	priv->pkstats.tx_errors =
248 	    en_stats_adder(&mlx4_en_stats->TGIANT_prio_0,
249 					  &mlx4_en_stats->TGIANT_prio_1,
250 					  NUM_PRIORITIES);
251 	priv->pkstats.rx_multicast_packets =
252 	    en_stats_adder(&mlx4_en_stats->MCAST_prio_0,
253 					  &mlx4_en_stats->MCAST_prio_1,
254 					  NUM_PRIORITIES);
255 	priv->pkstats.rx_dropped = be32_to_cpu(mlx4_en_stats->RDROP);
256 	priv->pkstats.rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
257 	priv->pkstats.rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
258 	priv->pkstats.rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
259 	priv->pkstats.tx_dropped = be32_to_cpu(mlx4_en_stats->TDROP);
260 
261 	/* RX stats */
262 	priv->pkstats.rx_packets = en_stats_adder(&mlx4_en_stats->RTOT_prio_0,
263 					   &mlx4_en_stats->RTOT_prio_1,
264 					   NUM_PRIORITIES);
265 	priv->pkstats.rx_bytes = en_stats_adder(&mlx4_en_stats->ROCT_prio_0,
266 					 &mlx4_en_stats->ROCT_prio_1,
267 					 NUM_PRIORITIES);
268 	priv->pkstats.rx_broadcast_packets =
269 			en_stats_adder(&mlx4_en_stats->RBCAST_prio_0,
270 				       &mlx4_en_stats->RBCAST_prio_1,
271 				       NUM_PRIORITIES);
272 	priv->pkstats.rx_jabbers = be32_to_cpu(mlx4_en_stats->RJBBR);
273 	priv->pkstats.rx_in_range_length_error =
274 		be64_to_cpu(mlx4_en_stats->RInRangeLengthErr);
275 	priv->pkstats.rx_out_range_length_error =
276 		be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr);
277 
278 	/* Tx stats */
279 	priv->pkstats.tx_packets = en_stats_adder(&mlx4_en_stats->TTOT_prio_0,
280 					   &mlx4_en_stats->TTOT_prio_1,
281 					   NUM_PRIORITIES);
282 	priv->pkstats.tx_bytes = en_stats_adder(&mlx4_en_stats->TOCT_prio_0,
283 					 &mlx4_en_stats->TOCT_prio_1,
284 					 NUM_PRIORITIES);
285 	priv->pkstats.tx_multicast_packets =
286 		en_stats_adder(&mlx4_en_stats->TMCAST_prio_0,
287 			       &mlx4_en_stats->TMCAST_prio_1,
288 			       NUM_PRIORITIES);
289 	priv->pkstats.tx_broadcast_packets =
290 		en_stats_adder(&mlx4_en_stats->TBCAST_prio_0,
291 			       &mlx4_en_stats->TBCAST_prio_1,
292 			       NUM_PRIORITIES);
293 
294 	priv->pkstats.rx_prio[0][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
295 	priv->pkstats.rx_prio[0][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_0);
296 	priv->pkstats.rx_prio[1][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
297 	priv->pkstats.rx_prio[1][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_1);
298 	priv->pkstats.rx_prio[2][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
299 	priv->pkstats.rx_prio[2][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_2);
300 	priv->pkstats.rx_prio[3][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
301 	priv->pkstats.rx_prio[3][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_3);
302 	priv->pkstats.rx_prio[4][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
303 	priv->pkstats.rx_prio[4][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_4);
304 	priv->pkstats.rx_prio[5][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
305 	priv->pkstats.rx_prio[5][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_5);
306 	priv->pkstats.rx_prio[6][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
307 	priv->pkstats.rx_prio[6][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_6);
308 	priv->pkstats.rx_prio[7][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
309 	priv->pkstats.rx_prio[7][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_7);
310 	priv->pkstats.rx_prio[8][0] = be64_to_cpu(mlx4_en_stats->RTOT_novlan);
311 	priv->pkstats.rx_prio[8][1] = be64_to_cpu(mlx4_en_stats->ROCT_novlan);
312 	priv->pkstats.tx_prio[0][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
313 	priv->pkstats.tx_prio[0][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_0);
314 	priv->pkstats.tx_prio[1][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
315 	priv->pkstats.tx_prio[1][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_1);
316 	priv->pkstats.tx_prio[2][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
317 	priv->pkstats.tx_prio[2][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_2);
318 	priv->pkstats.tx_prio[3][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
319 	priv->pkstats.tx_prio[3][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_3);
320 	priv->pkstats.tx_prio[4][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
321 	priv->pkstats.tx_prio[4][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_4);
322 	priv->pkstats.tx_prio[5][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
323 	priv->pkstats.tx_prio[5][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_5);
324 	priv->pkstats.tx_prio[6][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
325 	priv->pkstats.tx_prio[6][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_6);
326 	priv->pkstats.tx_prio[7][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
327 	priv->pkstats.tx_prio[7][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_7);
328 	priv->pkstats.tx_prio[8][0] = be64_to_cpu(mlx4_en_stats->TTOT_novlan);
329 	priv->pkstats.tx_prio[8][1] = be64_to_cpu(mlx4_en_stats->TOCT_novlan);
330 
331 	mlx4_en_fold_software_stats(dev);
332 
333 	spin_unlock(&priv->stats_lock);
334 
335 	memset(&tmp_vport_stats, 0, sizeof(tmp_vport_stats));
336 	counter_index = mlx4_get_default_counter_index(mdev->dev, port);
337 	err = mlx4_get_counter_stats(mdev->dev, counter_index,
338 				     &tmp_vport_stats, reset);
339 
340 	spin_lock(&priv->stats_lock);
341 	if (!err) {
342 		/* ethtool stats format */
343 		vport_stats->rx_bytes = be64_to_cpu(tmp_vport_stats.rx_bytes);
344 		vport_stats->rx_frames = be64_to_cpu(tmp_vport_stats.rx_frames);
345 		vport_stats->tx_bytes = be64_to_cpu(tmp_vport_stats.tx_bytes);
346 		vport_stats->tx_frames = be64_to_cpu(tmp_vport_stats.tx_frames);
347 	}
348 
349 #if __FreeBSD_version >= 1100000
350 	if (reset == 0) {
351 		if_inc_counter(dev, IFCOUNTER_IPACKETS,
352 		    priv->pkstats.rx_packets - priv->pkstats_last.rx_packets);
353 		if_inc_counter(dev, IFCOUNTER_OPACKETS,
354 		    priv->pkstats.tx_packets - priv->pkstats_last.tx_packets);
355 		if_inc_counter(dev, IFCOUNTER_IBYTES,
356 		    priv->pkstats.rx_bytes - priv->pkstats_last.rx_bytes);
357 		if_inc_counter(dev, IFCOUNTER_OBYTES,
358 		    priv->pkstats.tx_bytes - priv->pkstats_last.tx_bytes);
359 		if_inc_counter(dev, IFCOUNTER_IERRORS,
360 		    priv->pkstats.rx_errors - priv->pkstats_last.rx_errors);
361 		if_inc_counter(dev, IFCOUNTER_IQDROPS,
362 		    priv->pkstats.rx_dropped - priv->pkstats_last.rx_dropped);
363 		if_inc_counter(dev, IFCOUNTER_IMCASTS,
364 		    priv->pkstats.rx_multicast_packets - priv->pkstats_last.rx_multicast_packets);
365 		if_inc_counter(dev, IFCOUNTER_OMCASTS,
366 		    priv->pkstats.tx_multicast_packets - priv->pkstats_last.tx_multicast_packets);
367 	}
368 	priv->pkstats_last = priv->pkstats;
369 #else
370 	dev->if_ipackets        = priv->pkstats.rx_packets;
371 	dev->if_opackets        = priv->pkstats.tx_packets;
372 	dev->if_ibytes          = priv->pkstats.rx_bytes;
373 	dev->if_obytes          = priv->pkstats.tx_bytes;
374 	dev->if_ierrors         = priv->pkstats.rx_errors;
375 	dev->if_iqdrops         = priv->pkstats.rx_dropped;
376 	dev->if_imcasts         = priv->pkstats.rx_multicast_packets;
377 	dev->if_omcasts         = priv->pkstats.tx_multicast_packets;
378 	dev->if_collisions      = 0;
379 #endif
380 
381 	spin_unlock(&priv->stats_lock);
382 
383 	/* 0xffs indicates invalid value */
384 	memset(mailbox->buf, 0xff, sizeof(*flowstats) * MLX4_NUM_PRIORITIES);
385 
386 	if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN) {
387 		memset(mailbox->buf, 0,
388 		       sizeof(*flowstats) * MLX4_NUM_PRIORITIES);
389 		err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma,
390 				   in_mod | MLX4_DUMP_ETH_STATS_FLOW_CONTROL,
391 				   0, MLX4_CMD_DUMP_ETH_STATS,
392 				   MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
393 		if (err)
394 			goto out;
395 	}
396 
397 	flowstats = mailbox->buf;
398 
399 	spin_lock(&priv->stats_lock);
400 
401 	for (i = 0; i < MLX4_NUM_PRIORITIES; i++)	{
402 		priv->rx_priority_flowstats[i].rx_pause =
403 			be64_to_cpu(flowstats[i].rx_pause);
404 		priv->rx_priority_flowstats[i].rx_pause_duration =
405 			be64_to_cpu(flowstats[i].rx_pause_duration);
406 		priv->rx_priority_flowstats[i].rx_pause_transition =
407 			be64_to_cpu(flowstats[i].rx_pause_transition);
408 		priv->tx_priority_flowstats[i].tx_pause =
409 			be64_to_cpu(flowstats[i].tx_pause);
410 		priv->tx_priority_flowstats[i].tx_pause_duration =
411 			be64_to_cpu(flowstats[i].tx_pause_duration);
412 		priv->tx_priority_flowstats[i].tx_pause_transition =
413 			be64_to_cpu(flowstats[i].tx_pause_transition);
414 	}
415 
416 	/* if pfc is not in use, all priorities counters have the same value */
417 	priv->rx_flowstats.rx_pause =
418 		be64_to_cpu(flowstats[0].rx_pause);
419 	priv->rx_flowstats.rx_pause_duration =
420 		be64_to_cpu(flowstats[0].rx_pause_duration);
421 	priv->rx_flowstats.rx_pause_transition =
422 		be64_to_cpu(flowstats[0].rx_pause_transition);
423 	priv->tx_flowstats.tx_pause =
424 		be64_to_cpu(flowstats[0].tx_pause);
425 	priv->tx_flowstats.tx_pause_duration =
426 		be64_to_cpu(flowstats[0].tx_pause_duration);
427 	priv->tx_flowstats.tx_pause_transition =
428 		be64_to_cpu(flowstats[0].tx_pause_transition);
429 
430 	spin_unlock(&priv->stats_lock);
431 
432 out:
433 	mlx4_free_cmd_mailbox(mdev->dev, mailbox);
434 	return err;
435 }
436 
437 int mlx4_en_get_vport_stats(struct mlx4_en_dev *mdev, u8 port)
438 {
439 	struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
440 	struct mlx4_counter tmp_vport_stats;
441 	struct mlx4_en_vf_stats *vf_stats = &priv->vf_stats;
442 	int err, i, counter_index;
443 
444 	spin_lock(&priv->stats_lock);
445 
446 	priv->pkstats.rx_packets = 0;
447 	priv->pkstats.rx_bytes = 0;
448 	priv->port_stats.rx_chksum_good = 0;
449 	priv->port_stats.rx_chksum_none = 0;
450 	for (i = 0; i < priv->rx_ring_num; i++) {
451 		priv->pkstats.rx_packets += priv->rx_ring[i]->packets;
452 		priv->pkstats.rx_bytes += priv->rx_ring[i]->bytes;
453 		priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok;
454 		priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none;
455 	}
456 	priv->pkstats.tx_packets = 0;
457 	priv->pkstats.tx_bytes = 0;
458 	priv->port_stats.tx_chksum_offload = 0;
459 	priv->port_stats.queue_stopped = 0;
460 	priv->port_stats.wake_queue = 0;
461 
462 	for (i = 0; i < priv->tx_ring_num; i++) {
463 		const struct mlx4_en_tx_ring *ring = priv->tx_ring[i];
464 
465 		priv->pkstats.tx_packets += ring->packets;
466 		priv->pkstats.tx_bytes += ring->bytes;
467 		priv->port_stats.tx_chksum_offload += ring->tx_csum;
468 		priv->port_stats.queue_stopped     += ring->queue_stopped;
469 		priv->port_stats.wake_queue        += ring->wake_queue;
470 		priv->port_stats.oversized_packets += priv->tx_ring[i]->oversized_packets;
471 	}
472 
473 	spin_unlock(&priv->stats_lock);
474 
475 	memset(&tmp_vport_stats, 0, sizeof(tmp_vport_stats));
476 
477 	counter_index = mlx4_get_default_counter_index(mdev->dev, port);
478 	err = mlx4_get_counter_stats(mdev->dev, counter_index,
479 				     &tmp_vport_stats, 0);
480 
481 	if (!err) {
482 		spin_lock(&priv->stats_lock);
483 
484 		vf_stats->rx_bytes = be64_to_cpu(tmp_vport_stats.rx_bytes);
485 		vf_stats->rx_frames = be64_to_cpu(tmp_vport_stats.rx_frames);
486 		vf_stats->tx_bytes = be64_to_cpu(tmp_vport_stats.tx_bytes);
487 		vf_stats->tx_frames = be64_to_cpu(tmp_vport_stats.tx_frames);
488 
489 		priv->pkstats.rx_packets = vf_stats->rx_frames;
490 		priv->pkstats.rx_bytes = vf_stats->rx_bytes;
491 		priv->pkstats.tx_packets = vf_stats->tx_frames;
492 		priv->pkstats.tx_bytes = vf_stats->tx_bytes;
493 
494 		/* PF&VFs are not expected to report errors in ifconfig.
495 		 * rx_errors will be reprted in PF's ethtool statistics,
496 		 * see: mlx4_en_DUMP_ETH_STATS
497 		 */
498 		priv->pkstats.rx_errors = 0;
499 		priv->pkstats.rx_dropped = 0;
500 		priv->pkstats.tx_dropped = 0;
501 		priv->pkstats.rx_multicast_packets = 0;
502 
503 		spin_unlock(&priv->stats_lock);
504 	}
505 
506 	return err;
507 }
508