x86/topology: Fix function name in documentation
[cris-mirror.git] / drivers / net / ethernet / brocade / bna / bnad_ethtool.c
blob31032de5843b158e3a1aca0e742d60d31d1b5669
1 /*
2 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
16 * All rights reserved
17 * www.qlogic.com
20 #include "cna.h"
22 #include <linux/netdevice.h>
23 #include <linux/skbuff.h>
24 #include <linux/ethtool.h>
25 #include <linux/rtnetlink.h>
27 #include "bna.h"
29 #include "bnad.h"
31 #define BNAD_NUM_TXF_COUNTERS 12
32 #define BNAD_NUM_RXF_COUNTERS 10
33 #define BNAD_NUM_CQ_COUNTERS (3 + 5)
34 #define BNAD_NUM_RXQ_COUNTERS 7
35 #define BNAD_NUM_TXQ_COUNTERS 5
37 static const char *bnad_net_stats_strings[] = {
38 "rx_packets",
39 "tx_packets",
40 "rx_bytes",
41 "tx_bytes",
42 "rx_errors",
43 "tx_errors",
44 "rx_dropped",
45 "tx_dropped",
46 "multicast",
47 "collisions",
48 "rx_length_errors",
49 "rx_crc_errors",
50 "rx_frame_errors",
51 "tx_fifo_errors",
53 "netif_queue_stop",
54 "netif_queue_wakeup",
55 "netif_queue_stopped",
56 "tso4",
57 "tso6",
58 "tso_err",
59 "tcpcsum_offload",
60 "udpcsum_offload",
61 "csum_help",
62 "tx_skb_too_short",
63 "tx_skb_stopping",
64 "tx_skb_max_vectors",
65 "tx_skb_mss_too_long",
66 "tx_skb_tso_too_short",
67 "tx_skb_tso_prepare",
68 "tx_skb_non_tso_too_long",
69 "tx_skb_tcp_hdr",
70 "tx_skb_udp_hdr",
71 "tx_skb_csum_err",
72 "tx_skb_headlen_too_long",
73 "tx_skb_headlen_zero",
74 "tx_skb_frag_zero",
75 "tx_skb_len_mismatch",
76 "tx_skb_map_failed",
77 "hw_stats_updates",
78 "netif_rx_dropped",
80 "link_toggle",
81 "cee_toggle",
83 "rxp_info_alloc_failed",
84 "mbox_intr_disabled",
85 "mbox_intr_enabled",
86 "tx_unmap_q_alloc_failed",
87 "rx_unmap_q_alloc_failed",
88 "rxbuf_alloc_failed",
89 "rxbuf_map_failed",
91 "mac_stats_clr_cnt",
92 "mac_frame_64",
93 "mac_frame_65_127",
94 "mac_frame_128_255",
95 "mac_frame_256_511",
96 "mac_frame_512_1023",
97 "mac_frame_1024_1518",
98 "mac_frame_1518_1522",
99 "mac_rx_bytes",
100 "mac_rx_packets",
101 "mac_rx_fcs_error",
102 "mac_rx_multicast",
103 "mac_rx_broadcast",
104 "mac_rx_control_frames",
105 "mac_rx_pause",
106 "mac_rx_unknown_opcode",
107 "mac_rx_alignment_error",
108 "mac_rx_frame_length_error",
109 "mac_rx_code_error",
110 "mac_rx_carrier_sense_error",
111 "mac_rx_undersize",
112 "mac_rx_oversize",
113 "mac_rx_fragments",
114 "mac_rx_jabber",
115 "mac_rx_drop",
117 "mac_tx_bytes",
118 "mac_tx_packets",
119 "mac_tx_multicast",
120 "mac_tx_broadcast",
121 "mac_tx_pause",
122 "mac_tx_deferral",
123 "mac_tx_excessive_deferral",
124 "mac_tx_single_collision",
125 "mac_tx_muliple_collision",
126 "mac_tx_late_collision",
127 "mac_tx_excessive_collision",
128 "mac_tx_total_collision",
129 "mac_tx_pause_honored",
130 "mac_tx_drop",
131 "mac_tx_jabber",
132 "mac_tx_fcs_error",
133 "mac_tx_control_frame",
134 "mac_tx_oversize",
135 "mac_tx_undersize",
136 "mac_tx_fragments",
138 "bpc_tx_pause_0",
139 "bpc_tx_pause_1",
140 "bpc_tx_pause_2",
141 "bpc_tx_pause_3",
142 "bpc_tx_pause_4",
143 "bpc_tx_pause_5",
144 "bpc_tx_pause_6",
145 "bpc_tx_pause_7",
146 "bpc_tx_zero_pause_0",
147 "bpc_tx_zero_pause_1",
148 "bpc_tx_zero_pause_2",
149 "bpc_tx_zero_pause_3",
150 "bpc_tx_zero_pause_4",
151 "bpc_tx_zero_pause_5",
152 "bpc_tx_zero_pause_6",
153 "bpc_tx_zero_pause_7",
154 "bpc_tx_first_pause_0",
155 "bpc_tx_first_pause_1",
156 "bpc_tx_first_pause_2",
157 "bpc_tx_first_pause_3",
158 "bpc_tx_first_pause_4",
159 "bpc_tx_first_pause_5",
160 "bpc_tx_first_pause_6",
161 "bpc_tx_first_pause_7",
163 "bpc_rx_pause_0",
164 "bpc_rx_pause_1",
165 "bpc_rx_pause_2",
166 "bpc_rx_pause_3",
167 "bpc_rx_pause_4",
168 "bpc_rx_pause_5",
169 "bpc_rx_pause_6",
170 "bpc_rx_pause_7",
171 "bpc_rx_zero_pause_0",
172 "bpc_rx_zero_pause_1",
173 "bpc_rx_zero_pause_2",
174 "bpc_rx_zero_pause_3",
175 "bpc_rx_zero_pause_4",
176 "bpc_rx_zero_pause_5",
177 "bpc_rx_zero_pause_6",
178 "bpc_rx_zero_pause_7",
179 "bpc_rx_first_pause_0",
180 "bpc_rx_first_pause_1",
181 "bpc_rx_first_pause_2",
182 "bpc_rx_first_pause_3",
183 "bpc_rx_first_pause_4",
184 "bpc_rx_first_pause_5",
185 "bpc_rx_first_pause_6",
186 "bpc_rx_first_pause_7",
188 "rad_rx_frames",
189 "rad_rx_octets",
190 "rad_rx_vlan_frames",
191 "rad_rx_ucast",
192 "rad_rx_ucast_octets",
193 "rad_rx_ucast_vlan",
194 "rad_rx_mcast",
195 "rad_rx_mcast_octets",
196 "rad_rx_mcast_vlan",
197 "rad_rx_bcast",
198 "rad_rx_bcast_octets",
199 "rad_rx_bcast_vlan",
200 "rad_rx_drops",
202 "rlb_rad_rx_frames",
203 "rlb_rad_rx_octets",
204 "rlb_rad_rx_vlan_frames",
205 "rlb_rad_rx_ucast",
206 "rlb_rad_rx_ucast_octets",
207 "rlb_rad_rx_ucast_vlan",
208 "rlb_rad_rx_mcast",
209 "rlb_rad_rx_mcast_octets",
210 "rlb_rad_rx_mcast_vlan",
211 "rlb_rad_rx_bcast",
212 "rlb_rad_rx_bcast_octets",
213 "rlb_rad_rx_bcast_vlan",
214 "rlb_rad_rx_drops",
216 "fc_rx_ucast_octets",
217 "fc_rx_ucast",
218 "fc_rx_ucast_vlan",
219 "fc_rx_mcast_octets",
220 "fc_rx_mcast",
221 "fc_rx_mcast_vlan",
222 "fc_rx_bcast_octets",
223 "fc_rx_bcast",
224 "fc_rx_bcast_vlan",
226 "fc_tx_ucast_octets",
227 "fc_tx_ucast",
228 "fc_tx_ucast_vlan",
229 "fc_tx_mcast_octets",
230 "fc_tx_mcast",
231 "fc_tx_mcast_vlan",
232 "fc_tx_bcast_octets",
233 "fc_tx_bcast",
234 "fc_tx_bcast_vlan",
235 "fc_tx_parity_errors",
236 "fc_tx_timeout",
237 "fc_tx_fid_parity_errors",
240 #define BNAD_ETHTOOL_STATS_NUM ARRAY_SIZE(bnad_net_stats_strings)
242 static int
243 bnad_get_link_ksettings(struct net_device *netdev,
244 struct ethtool_link_ksettings *cmd)
246 u32 supported, advertising;
248 supported = SUPPORTED_10000baseT_Full;
249 advertising = ADVERTISED_10000baseT_Full;
250 cmd->base.autoneg = AUTONEG_DISABLE;
251 supported |= SUPPORTED_FIBRE;
252 advertising |= ADVERTISED_FIBRE;
253 cmd->base.port = PORT_FIBRE;
254 cmd->base.phy_address = 0;
256 if (netif_carrier_ok(netdev)) {
257 cmd->base.speed = SPEED_10000;
258 cmd->base.duplex = DUPLEX_FULL;
259 } else {
260 cmd->base.speed = SPEED_UNKNOWN;
261 cmd->base.duplex = DUPLEX_UNKNOWN;
264 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
265 supported);
266 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
267 advertising);
269 return 0;
272 static int
273 bnad_set_link_ksettings(struct net_device *netdev,
274 const struct ethtool_link_ksettings *cmd)
276 /* 10G full duplex setting supported only */
277 if (cmd->base.autoneg == AUTONEG_ENABLE)
278 return -EOPNOTSUPP;
280 if ((cmd->base.speed == SPEED_10000) &&
281 (cmd->base.duplex == DUPLEX_FULL))
282 return 0;
284 return -EOPNOTSUPP;
287 static void
288 bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
290 struct bnad *bnad = netdev_priv(netdev);
291 struct bfa_ioc_attr *ioc_attr;
292 unsigned long flags;
294 strlcpy(drvinfo->driver, BNAD_NAME, sizeof(drvinfo->driver));
295 strlcpy(drvinfo->version, BNAD_VERSION, sizeof(drvinfo->version));
297 ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
298 if (ioc_attr) {
299 spin_lock_irqsave(&bnad->bna_lock, flags);
300 bfa_nw_ioc_get_attr(&bnad->bna.ioceth.ioc, ioc_attr);
301 spin_unlock_irqrestore(&bnad->bna_lock, flags);
303 strlcpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
304 sizeof(drvinfo->fw_version));
305 kfree(ioc_attr);
308 strlcpy(drvinfo->bus_info, pci_name(bnad->pcidev),
309 sizeof(drvinfo->bus_info));
312 static void
313 bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
315 wolinfo->supported = 0;
316 wolinfo->wolopts = 0;
319 static int
320 bnad_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
322 struct bnad *bnad = netdev_priv(netdev);
323 unsigned long flags;
325 /* Lock rqd. to access bnad->bna_lock */
326 spin_lock_irqsave(&bnad->bna_lock, flags);
327 coalesce->use_adaptive_rx_coalesce =
328 (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
329 spin_unlock_irqrestore(&bnad->bna_lock, flags);
331 coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
332 BFI_COALESCING_TIMER_UNIT;
333 coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
334 BFI_COALESCING_TIMER_UNIT;
335 coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
337 return 0;
340 static int
341 bnad_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
343 struct bnad *bnad = netdev_priv(netdev);
344 unsigned long flags;
345 int to_del = 0;
347 if (coalesce->rx_coalesce_usecs == 0 ||
348 coalesce->rx_coalesce_usecs >
349 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
350 return -EINVAL;
352 if (coalesce->tx_coalesce_usecs == 0 ||
353 coalesce->tx_coalesce_usecs >
354 BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
355 return -EINVAL;
357 mutex_lock(&bnad->conf_mutex);
359 * Do not need to store rx_coalesce_usecs here
360 * Every time DIM is disabled, we can get it from the
361 * stack.
363 spin_lock_irqsave(&bnad->bna_lock, flags);
364 if (coalesce->use_adaptive_rx_coalesce) {
365 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
366 bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
367 bnad_dim_timer_start(bnad);
369 } else {
370 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
371 bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
372 if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
373 test_bit(BNAD_RF_DIM_TIMER_RUNNING,
374 &bnad->run_flags)) {
375 clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
376 &bnad->run_flags);
377 to_del = 1;
379 spin_unlock_irqrestore(&bnad->bna_lock, flags);
380 if (to_del)
381 del_timer_sync(&bnad->dim_timer);
382 spin_lock_irqsave(&bnad->bna_lock, flags);
383 bnad_rx_coalescing_timeo_set(bnad);
386 if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
387 BFI_COALESCING_TIMER_UNIT) {
388 bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
389 BFI_COALESCING_TIMER_UNIT;
390 bnad_tx_coalescing_timeo_set(bnad);
393 if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
394 BFI_COALESCING_TIMER_UNIT) {
395 bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
396 BFI_COALESCING_TIMER_UNIT;
398 if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
399 bnad_rx_coalescing_timeo_set(bnad);
403 /* Add Tx Inter-pkt DMA count? */
405 spin_unlock_irqrestore(&bnad->bna_lock, flags);
407 mutex_unlock(&bnad->conf_mutex);
408 return 0;
411 static void
412 bnad_get_ringparam(struct net_device *netdev,
413 struct ethtool_ringparam *ringparam)
415 struct bnad *bnad = netdev_priv(netdev);
417 ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
418 ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
420 ringparam->rx_pending = bnad->rxq_depth;
421 ringparam->tx_pending = bnad->txq_depth;
424 static int
425 bnad_set_ringparam(struct net_device *netdev,
426 struct ethtool_ringparam *ringparam)
428 int i, current_err, err = 0;
429 struct bnad *bnad = netdev_priv(netdev);
430 unsigned long flags;
432 mutex_lock(&bnad->conf_mutex);
433 if (ringparam->rx_pending == bnad->rxq_depth &&
434 ringparam->tx_pending == bnad->txq_depth) {
435 mutex_unlock(&bnad->conf_mutex);
436 return 0;
439 if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
440 ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
441 !is_power_of_2(ringparam->rx_pending)) {
442 mutex_unlock(&bnad->conf_mutex);
443 return -EINVAL;
445 if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
446 ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
447 !is_power_of_2(ringparam->tx_pending)) {
448 mutex_unlock(&bnad->conf_mutex);
449 return -EINVAL;
452 if (ringparam->rx_pending != bnad->rxq_depth) {
453 bnad->rxq_depth = ringparam->rx_pending;
454 if (!netif_running(netdev)) {
455 mutex_unlock(&bnad->conf_mutex);
456 return 0;
459 for (i = 0; i < bnad->num_rx; i++) {
460 if (!bnad->rx_info[i].rx)
461 continue;
462 bnad_destroy_rx(bnad, i);
463 current_err = bnad_setup_rx(bnad, i);
464 if (current_err && !err)
465 err = current_err;
468 if (!err && bnad->rx_info[0].rx) {
469 /* restore rx configuration */
470 bnad_restore_vlans(bnad, 0);
471 bnad_enable_default_bcast(bnad);
472 spin_lock_irqsave(&bnad->bna_lock, flags);
473 bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
474 spin_unlock_irqrestore(&bnad->bna_lock, flags);
475 bnad->cfg_flags &= ~(BNAD_CF_ALLMULTI |
476 BNAD_CF_PROMISC);
477 bnad_set_rx_mode(netdev);
480 if (ringparam->tx_pending != bnad->txq_depth) {
481 bnad->txq_depth = ringparam->tx_pending;
482 if (!netif_running(netdev)) {
483 mutex_unlock(&bnad->conf_mutex);
484 return 0;
487 for (i = 0; i < bnad->num_tx; i++) {
488 if (!bnad->tx_info[i].tx)
489 continue;
490 bnad_destroy_tx(bnad, i);
491 current_err = bnad_setup_tx(bnad, i);
492 if (current_err && !err)
493 err = current_err;
497 mutex_unlock(&bnad->conf_mutex);
498 return err;
501 static void
502 bnad_get_pauseparam(struct net_device *netdev,
503 struct ethtool_pauseparam *pauseparam)
505 struct bnad *bnad = netdev_priv(netdev);
507 pauseparam->autoneg = 0;
508 pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
509 pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
512 static int
513 bnad_set_pauseparam(struct net_device *netdev,
514 struct ethtool_pauseparam *pauseparam)
516 struct bnad *bnad = netdev_priv(netdev);
517 struct bna_pause_config pause_config;
518 unsigned long flags;
520 if (pauseparam->autoneg == AUTONEG_ENABLE)
521 return -EINVAL;
523 mutex_lock(&bnad->conf_mutex);
524 if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
525 pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
526 pause_config.rx_pause = pauseparam->rx_pause;
527 pause_config.tx_pause = pauseparam->tx_pause;
528 spin_lock_irqsave(&bnad->bna_lock, flags);
529 bna_enet_pause_config(&bnad->bna.enet, &pause_config);
530 spin_unlock_irqrestore(&bnad->bna_lock, flags);
532 mutex_unlock(&bnad->conf_mutex);
533 return 0;
536 static void
537 bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
539 struct bnad *bnad = netdev_priv(netdev);
540 int i, j, q_num;
541 u32 bmap;
543 mutex_lock(&bnad->conf_mutex);
545 switch (stringset) {
546 case ETH_SS_STATS:
547 for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
548 BUG_ON(!(strlen(bnad_net_stats_strings[i]) <
549 ETH_GSTRING_LEN));
550 strncpy(string, bnad_net_stats_strings[i],
551 ETH_GSTRING_LEN);
552 string += ETH_GSTRING_LEN;
554 bmap = bna_tx_rid_mask(&bnad->bna);
555 for (i = 0; bmap; i++) {
556 if (bmap & 1) {
557 sprintf(string, "txf%d_ucast_octets", i);
558 string += ETH_GSTRING_LEN;
559 sprintf(string, "txf%d_ucast", i);
560 string += ETH_GSTRING_LEN;
561 sprintf(string, "txf%d_ucast_vlan", i);
562 string += ETH_GSTRING_LEN;
563 sprintf(string, "txf%d_mcast_octets", i);
564 string += ETH_GSTRING_LEN;
565 sprintf(string, "txf%d_mcast", i);
566 string += ETH_GSTRING_LEN;
567 sprintf(string, "txf%d_mcast_vlan", i);
568 string += ETH_GSTRING_LEN;
569 sprintf(string, "txf%d_bcast_octets", i);
570 string += ETH_GSTRING_LEN;
571 sprintf(string, "txf%d_bcast", i);
572 string += ETH_GSTRING_LEN;
573 sprintf(string, "txf%d_bcast_vlan", i);
574 string += ETH_GSTRING_LEN;
575 sprintf(string, "txf%d_errors", i);
576 string += ETH_GSTRING_LEN;
577 sprintf(string, "txf%d_filter_vlan", i);
578 string += ETH_GSTRING_LEN;
579 sprintf(string, "txf%d_filter_mac_sa", i);
580 string += ETH_GSTRING_LEN;
582 bmap >>= 1;
585 bmap = bna_rx_rid_mask(&bnad->bna);
586 for (i = 0; bmap; i++) {
587 if (bmap & 1) {
588 sprintf(string, "rxf%d_ucast_octets", i);
589 string += ETH_GSTRING_LEN;
590 sprintf(string, "rxf%d_ucast", i);
591 string += ETH_GSTRING_LEN;
592 sprintf(string, "rxf%d_ucast_vlan", i);
593 string += ETH_GSTRING_LEN;
594 sprintf(string, "rxf%d_mcast_octets", i);
595 string += ETH_GSTRING_LEN;
596 sprintf(string, "rxf%d_mcast", i);
597 string += ETH_GSTRING_LEN;
598 sprintf(string, "rxf%d_mcast_vlan", i);
599 string += ETH_GSTRING_LEN;
600 sprintf(string, "rxf%d_bcast_octets", i);
601 string += ETH_GSTRING_LEN;
602 sprintf(string, "rxf%d_bcast", i);
603 string += ETH_GSTRING_LEN;
604 sprintf(string, "rxf%d_bcast_vlan", i);
605 string += ETH_GSTRING_LEN;
606 sprintf(string, "rxf%d_frame_drops", i);
607 string += ETH_GSTRING_LEN;
609 bmap >>= 1;
612 q_num = 0;
613 for (i = 0; i < bnad->num_rx; i++) {
614 if (!bnad->rx_info[i].rx)
615 continue;
616 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
617 sprintf(string, "cq%d_producer_index", q_num);
618 string += ETH_GSTRING_LEN;
619 sprintf(string, "cq%d_consumer_index", q_num);
620 string += ETH_GSTRING_LEN;
621 sprintf(string, "cq%d_hw_producer_index",
622 q_num);
623 string += ETH_GSTRING_LEN;
624 sprintf(string, "cq%d_intr", q_num);
625 string += ETH_GSTRING_LEN;
626 sprintf(string, "cq%d_poll", q_num);
627 string += ETH_GSTRING_LEN;
628 sprintf(string, "cq%d_schedule", q_num);
629 string += ETH_GSTRING_LEN;
630 sprintf(string, "cq%d_keep_poll", q_num);
631 string += ETH_GSTRING_LEN;
632 sprintf(string, "cq%d_complete", q_num);
633 string += ETH_GSTRING_LEN;
634 q_num++;
638 q_num = 0;
639 for (i = 0; i < bnad->num_rx; i++) {
640 if (!bnad->rx_info[i].rx)
641 continue;
642 for (j = 0; j < bnad->num_rxp_per_rx; j++) {
643 sprintf(string, "rxq%d_packets", q_num);
644 string += ETH_GSTRING_LEN;
645 sprintf(string, "rxq%d_bytes", q_num);
646 string += ETH_GSTRING_LEN;
647 sprintf(string, "rxq%d_packets_with_error",
648 q_num);
649 string += ETH_GSTRING_LEN;
650 sprintf(string, "rxq%d_allocbuf_failed", q_num);
651 string += ETH_GSTRING_LEN;
652 sprintf(string, "rxq%d_mapbuf_failed", q_num);
653 string += ETH_GSTRING_LEN;
654 sprintf(string, "rxq%d_producer_index", q_num);
655 string += ETH_GSTRING_LEN;
656 sprintf(string, "rxq%d_consumer_index", q_num);
657 string += ETH_GSTRING_LEN;
658 q_num++;
659 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
660 bnad->rx_info[i].rx_ctrl[j].ccb->
661 rcb[1] &&
662 bnad->rx_info[i].rx_ctrl[j].ccb->
663 rcb[1]->rxq) {
664 sprintf(string, "rxq%d_packets", q_num);
665 string += ETH_GSTRING_LEN;
666 sprintf(string, "rxq%d_bytes", q_num);
667 string += ETH_GSTRING_LEN;
668 sprintf(string,
669 "rxq%d_packets_with_error", q_num);
670 string += ETH_GSTRING_LEN;
671 sprintf(string, "rxq%d_allocbuf_failed",
672 q_num);
673 string += ETH_GSTRING_LEN;
674 sprintf(string, "rxq%d_mapbuf_failed",
675 q_num);
676 string += ETH_GSTRING_LEN;
677 sprintf(string, "rxq%d_producer_index",
678 q_num);
679 string += ETH_GSTRING_LEN;
680 sprintf(string, "rxq%d_consumer_index",
681 q_num);
682 string += ETH_GSTRING_LEN;
683 q_num++;
688 q_num = 0;
689 for (i = 0; i < bnad->num_tx; i++) {
690 if (!bnad->tx_info[i].tx)
691 continue;
692 for (j = 0; j < bnad->num_txq_per_tx; j++) {
693 sprintf(string, "txq%d_packets", q_num);
694 string += ETH_GSTRING_LEN;
695 sprintf(string, "txq%d_bytes", q_num);
696 string += ETH_GSTRING_LEN;
697 sprintf(string, "txq%d_producer_index", q_num);
698 string += ETH_GSTRING_LEN;
699 sprintf(string, "txq%d_consumer_index", q_num);
700 string += ETH_GSTRING_LEN;
701 sprintf(string, "txq%d_hw_consumer_index",
702 q_num);
703 string += ETH_GSTRING_LEN;
704 q_num++;
708 break;
710 default:
711 break;
714 mutex_unlock(&bnad->conf_mutex);
717 static int
718 bnad_get_stats_count_locked(struct net_device *netdev)
720 struct bnad *bnad = netdev_priv(netdev);
721 int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
722 u32 bmap;
724 bmap = bna_tx_rid_mask(&bnad->bna);
725 for (i = 0; bmap; i++) {
726 if (bmap & 1)
727 txf_active_num++;
728 bmap >>= 1;
730 bmap = bna_rx_rid_mask(&bnad->bna);
731 for (i = 0; bmap; i++) {
732 if (bmap & 1)
733 rxf_active_num++;
734 bmap >>= 1;
736 count = BNAD_ETHTOOL_STATS_NUM +
737 txf_active_num * BNAD_NUM_TXF_COUNTERS +
738 rxf_active_num * BNAD_NUM_RXF_COUNTERS;
740 for (i = 0; i < bnad->num_rx; i++) {
741 if (!bnad->rx_info[i].rx)
742 continue;
743 count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
744 count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
745 for (j = 0; j < bnad->num_rxp_per_rx; j++)
746 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
747 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
748 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
749 count += BNAD_NUM_RXQ_COUNTERS;
752 for (i = 0; i < bnad->num_tx; i++) {
753 if (!bnad->tx_info[i].tx)
754 continue;
755 count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
757 return count;
760 static int
761 bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
763 int i, j;
764 struct bna_rcb *rcb = NULL;
765 struct bna_tcb *tcb = NULL;
767 for (i = 0; i < bnad->num_rx; i++) {
768 if (!bnad->rx_info[i].rx)
769 continue;
770 for (j = 0; j < bnad->num_rxp_per_rx; j++)
771 if (bnad->rx_info[i].rx_ctrl[j].ccb &&
772 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
773 bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
774 buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
775 ccb->producer_index;
776 buf[bi++] = 0; /* ccb->consumer_index */
777 buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
778 ccb->hw_producer_index);
780 buf[bi++] = bnad->rx_info[i].
781 rx_ctrl[j].rx_intr_ctr;
782 buf[bi++] = bnad->rx_info[i].
783 rx_ctrl[j].rx_poll_ctr;
784 buf[bi++] = bnad->rx_info[i].
785 rx_ctrl[j].rx_schedule;
786 buf[bi++] = bnad->rx_info[i].
787 rx_ctrl[j].rx_keep_poll;
788 buf[bi++] = bnad->rx_info[i].
789 rx_ctrl[j].rx_complete;
792 for (i = 0; i < bnad->num_rx; i++) {
793 if (!bnad->rx_info[i].rx)
794 continue;
795 for (j = 0; j < bnad->num_rxp_per_rx; j++)
796 if (bnad->rx_info[i].rx_ctrl[j].ccb) {
797 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
798 bnad->rx_info[i].rx_ctrl[j].ccb->
799 rcb[0]->rxq) {
800 rcb = bnad->rx_info[i].rx_ctrl[j].
801 ccb->rcb[0];
802 buf[bi++] = rcb->rxq->rx_packets;
803 buf[bi++] = rcb->rxq->rx_bytes;
804 buf[bi++] = rcb->rxq->
805 rx_packets_with_error;
806 buf[bi++] = rcb->rxq->
807 rxbuf_alloc_failed;
808 buf[bi++] = rcb->rxq->rxbuf_map_failed;
809 buf[bi++] = rcb->producer_index;
810 buf[bi++] = rcb->consumer_index;
812 if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
813 bnad->rx_info[i].rx_ctrl[j].ccb->
814 rcb[1]->rxq) {
815 rcb = bnad->rx_info[i].rx_ctrl[j].
816 ccb->rcb[1];
817 buf[bi++] = rcb->rxq->rx_packets;
818 buf[bi++] = rcb->rxq->rx_bytes;
819 buf[bi++] = rcb->rxq->
820 rx_packets_with_error;
821 buf[bi++] = rcb->rxq->
822 rxbuf_alloc_failed;
823 buf[bi++] = rcb->rxq->rxbuf_map_failed;
824 buf[bi++] = rcb->producer_index;
825 buf[bi++] = rcb->consumer_index;
830 for (i = 0; i < bnad->num_tx; i++) {
831 if (!bnad->tx_info[i].tx)
832 continue;
833 for (j = 0; j < bnad->num_txq_per_tx; j++)
834 if (bnad->tx_info[i].tcb[j] &&
835 bnad->tx_info[i].tcb[j]->txq) {
836 tcb = bnad->tx_info[i].tcb[j];
837 buf[bi++] = tcb->txq->tx_packets;
838 buf[bi++] = tcb->txq->tx_bytes;
839 buf[bi++] = tcb->producer_index;
840 buf[bi++] = tcb->consumer_index;
841 buf[bi++] = *(tcb->hw_consumer_index);
845 return bi;
848 static void
849 bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
850 u64 *buf)
852 struct bnad *bnad = netdev_priv(netdev);
853 int i, j, bi = 0;
854 unsigned long flags;
855 struct rtnl_link_stats64 net_stats64;
856 u64 *stats64;
857 u32 bmap;
859 mutex_lock(&bnad->conf_mutex);
860 if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
861 mutex_unlock(&bnad->conf_mutex);
862 return;
866 * Used bna_lock to sync reads from bna_stats, which is written
867 * under the same lock
869 spin_lock_irqsave(&bnad->bna_lock, flags);
871 memset(&net_stats64, 0, sizeof(net_stats64));
872 bnad_netdev_qstats_fill(bnad, &net_stats64);
873 bnad_netdev_hwstats_fill(bnad, &net_stats64);
875 buf[bi++] = net_stats64.rx_packets;
876 buf[bi++] = net_stats64.tx_packets;
877 buf[bi++] = net_stats64.rx_bytes;
878 buf[bi++] = net_stats64.tx_bytes;
879 buf[bi++] = net_stats64.rx_errors;
880 buf[bi++] = net_stats64.tx_errors;
881 buf[bi++] = net_stats64.rx_dropped;
882 buf[bi++] = net_stats64.tx_dropped;
883 buf[bi++] = net_stats64.multicast;
884 buf[bi++] = net_stats64.collisions;
885 buf[bi++] = net_stats64.rx_length_errors;
886 buf[bi++] = net_stats64.rx_crc_errors;
887 buf[bi++] = net_stats64.rx_frame_errors;
888 buf[bi++] = net_stats64.tx_fifo_errors;
890 /* Get netif_queue_stopped from stack */
891 bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
893 /* Fill driver stats into ethtool buffers */
894 stats64 = (u64 *)&bnad->stats.drv_stats;
895 for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
896 buf[bi++] = stats64[i];
898 /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
899 stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
900 for (i = 0;
901 i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
902 sizeof(u64);
903 i++)
904 buf[bi++] = stats64[i];
906 /* Fill txf stats into ethtool buffers */
907 bmap = bna_tx_rid_mask(&bnad->bna);
908 for (i = 0; bmap; i++) {
909 if (bmap & 1) {
910 stats64 = (u64 *)&bnad->stats.bna_stats->
911 hw_stats.txf_stats[i];
912 for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
913 sizeof(u64); j++)
914 buf[bi++] = stats64[j];
916 bmap >>= 1;
919 /* Fill rxf stats into ethtool buffers */
920 bmap = bna_rx_rid_mask(&bnad->bna);
921 for (i = 0; bmap; i++) {
922 if (bmap & 1) {
923 stats64 = (u64 *)&bnad->stats.bna_stats->
924 hw_stats.rxf_stats[i];
925 for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
926 sizeof(u64); j++)
927 buf[bi++] = stats64[j];
929 bmap >>= 1;
932 /* Fill per Q stats into ethtool buffers */
933 bi = bnad_per_q_stats_fill(bnad, buf, bi);
935 spin_unlock_irqrestore(&bnad->bna_lock, flags);
937 mutex_unlock(&bnad->conf_mutex);
940 static int
941 bnad_get_sset_count(struct net_device *netdev, int sset)
943 switch (sset) {
944 case ETH_SS_STATS:
945 return bnad_get_stats_count_locked(netdev);
946 default:
947 return -EOPNOTSUPP;
951 static u32
952 bnad_get_flash_partition_by_offset(struct bnad *bnad, u32 offset,
953 u32 *base_offset)
955 struct bfa_flash_attr *flash_attr;
956 struct bnad_iocmd_comp fcomp;
957 u32 i, flash_part = 0, ret;
958 unsigned long flags = 0;
960 flash_attr = kzalloc(sizeof(struct bfa_flash_attr), GFP_KERNEL);
961 if (!flash_attr)
962 return 0;
964 fcomp.bnad = bnad;
965 fcomp.comp_status = 0;
967 init_completion(&fcomp.comp);
968 spin_lock_irqsave(&bnad->bna_lock, flags);
969 ret = bfa_nw_flash_get_attr(&bnad->bna.flash, flash_attr,
970 bnad_cb_completion, &fcomp);
971 if (ret != BFA_STATUS_OK) {
972 spin_unlock_irqrestore(&bnad->bna_lock, flags);
973 kfree(flash_attr);
974 return 0;
976 spin_unlock_irqrestore(&bnad->bna_lock, flags);
977 wait_for_completion(&fcomp.comp);
978 ret = fcomp.comp_status;
980 /* Check for the flash type & base offset value */
981 if (ret == BFA_STATUS_OK) {
982 for (i = 0; i < flash_attr->npart; i++) {
983 if (offset >= flash_attr->part[i].part_off &&
984 offset < (flash_attr->part[i].part_off +
985 flash_attr->part[i].part_size)) {
986 flash_part = flash_attr->part[i].part_type;
987 *base_offset = flash_attr->part[i].part_off;
988 break;
992 kfree(flash_attr);
993 return flash_part;
996 static int
997 bnad_get_eeprom_len(struct net_device *netdev)
999 return BFA_TOTAL_FLASH_SIZE;
1002 static int
1003 bnad_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
1004 u8 *bytes)
1006 struct bnad *bnad = netdev_priv(netdev);
1007 struct bnad_iocmd_comp fcomp;
1008 u32 flash_part = 0, base_offset = 0;
1009 unsigned long flags = 0;
1010 int ret = 0;
1012 /* Fill the magic value */
1013 eeprom->magic = bnad->pcidev->vendor | (bnad->pcidev->device << 16);
1015 /* Query the flash partition based on the offset */
1016 flash_part = bnad_get_flash_partition_by_offset(bnad,
1017 eeprom->offset, &base_offset);
1018 if (flash_part == 0)
1019 return -EFAULT;
1021 fcomp.bnad = bnad;
1022 fcomp.comp_status = 0;
1024 init_completion(&fcomp.comp);
1025 spin_lock_irqsave(&bnad->bna_lock, flags);
1026 ret = bfa_nw_flash_read_part(&bnad->bna.flash, flash_part,
1027 bnad->id, bytes, eeprom->len,
1028 eeprom->offset - base_offset,
1029 bnad_cb_completion, &fcomp);
1030 if (ret != BFA_STATUS_OK) {
1031 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1032 goto done;
1035 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1036 wait_for_completion(&fcomp.comp);
1037 ret = fcomp.comp_status;
1038 done:
1039 return ret;
1042 static int
1043 bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
1044 u8 *bytes)
1046 struct bnad *bnad = netdev_priv(netdev);
1047 struct bnad_iocmd_comp fcomp;
1048 u32 flash_part = 0, base_offset = 0;
1049 unsigned long flags = 0;
1050 int ret = 0;
1052 /* Check if the flash update request is valid */
1053 if (eeprom->magic != (bnad->pcidev->vendor |
1054 (bnad->pcidev->device << 16)))
1055 return -EINVAL;
1057 /* Query the flash partition based on the offset */
1058 flash_part = bnad_get_flash_partition_by_offset(bnad,
1059 eeprom->offset, &base_offset);
1060 if (flash_part == 0)
1061 return -EFAULT;
1063 fcomp.bnad = bnad;
1064 fcomp.comp_status = 0;
1066 init_completion(&fcomp.comp);
1067 spin_lock_irqsave(&bnad->bna_lock, flags);
1068 ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part,
1069 bnad->id, bytes, eeprom->len,
1070 eeprom->offset - base_offset,
1071 bnad_cb_completion, &fcomp);
1072 if (ret != BFA_STATUS_OK) {
1073 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1074 goto done;
1077 spin_unlock_irqrestore(&bnad->bna_lock, flags);
1078 wait_for_completion(&fcomp.comp);
1079 ret = fcomp.comp_status;
1080 done:
1081 return ret;
1084 static int
1085 bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash)
1087 struct bnad *bnad = netdev_priv(netdev);
1088 struct bnad_iocmd_comp fcomp;
1089 const struct firmware *fw;
1090 int ret = 0;
1092 ret = request_firmware(&fw, eflash->data, &bnad->pcidev->dev);
1093 if (ret) {
1094 netdev_err(netdev, "can't load firmware %s\n", eflash->data);
1095 goto out;
1098 fcomp.bnad = bnad;
1099 fcomp.comp_status = 0;
1101 init_completion(&fcomp.comp);
1102 spin_lock_irq(&bnad->bna_lock);
1103 ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG,
1104 bnad->id, (u8 *)fw->data, fw->size, 0,
1105 bnad_cb_completion, &fcomp);
1106 if (ret != BFA_STATUS_OK) {
1107 netdev_warn(netdev, "flash update failed with err=%d\n", ret);
1108 ret = -EIO;
1109 spin_unlock_irq(&bnad->bna_lock);
1110 goto out;
1113 spin_unlock_irq(&bnad->bna_lock);
1114 wait_for_completion(&fcomp.comp);
1115 if (fcomp.comp_status != BFA_STATUS_OK) {
1116 ret = -EIO;
1117 netdev_warn(netdev,
1118 "firmware image update failed with err=%d\n",
1119 fcomp.comp_status);
1121 out:
1122 release_firmware(fw);
1123 return ret;
1126 static const struct ethtool_ops bnad_ethtool_ops = {
1127 .get_drvinfo = bnad_get_drvinfo,
1128 .get_wol = bnad_get_wol,
1129 .get_link = ethtool_op_get_link,
1130 .get_coalesce = bnad_get_coalesce,
1131 .set_coalesce = bnad_set_coalesce,
1132 .get_ringparam = bnad_get_ringparam,
1133 .set_ringparam = bnad_set_ringparam,
1134 .get_pauseparam = bnad_get_pauseparam,
1135 .set_pauseparam = bnad_set_pauseparam,
1136 .get_strings = bnad_get_strings,
1137 .get_ethtool_stats = bnad_get_ethtool_stats,
1138 .get_sset_count = bnad_get_sset_count,
1139 .get_eeprom_len = bnad_get_eeprom_len,
1140 .get_eeprom = bnad_get_eeprom,
1141 .set_eeprom = bnad_set_eeprom,
1142 .flash_device = bnad_flash_device,
1143 .get_ts_info = ethtool_op_get_ts_info,
1144 .get_link_ksettings = bnad_get_link_ksettings,
1145 .set_link_ksettings = bnad_set_link_ksettings,
1148 void
1149 bnad_set_ethtool_ops(struct net_device *netdev)
1151 netdev->ethtool_ops = &bnad_ethtool_ops;