152fa7bf9SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2f844a0eaSJeff Kirsher /*
32732ba56SRasesh Mody * Linux network driver for QLogic BR-series Converged Network Adapter.
4f844a0eaSJeff Kirsher */
5f844a0eaSJeff Kirsher /*
62732ba56SRasesh Mody * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
72732ba56SRasesh Mody * Copyright (c) 2014-2015 QLogic Corporation
8f844a0eaSJeff Kirsher * All rights reserved
92732ba56SRasesh Mody * www.qlogic.com
10f844a0eaSJeff Kirsher */
11f844a0eaSJeff Kirsher
12f844a0eaSJeff Kirsher #include "cna.h"
13f844a0eaSJeff Kirsher
14f844a0eaSJeff Kirsher #include <linux/netdevice.h>
15f844a0eaSJeff Kirsher #include <linux/skbuff.h>
16f844a0eaSJeff Kirsher #include <linux/ethtool.h>
17f844a0eaSJeff Kirsher #include <linux/rtnetlink.h>
18f844a0eaSJeff Kirsher
19f844a0eaSJeff Kirsher #include "bna.h"
20f844a0eaSJeff Kirsher
21f844a0eaSJeff Kirsher #include "bnad.h"
22f844a0eaSJeff Kirsher
23f844a0eaSJeff Kirsher #define BNAD_NUM_TXF_COUNTERS 12
24f844a0eaSJeff Kirsher #define BNAD_NUM_RXF_COUNTERS 10
25078086f3SRasesh Mody #define BNAD_NUM_CQ_COUNTERS (3 + 5)
262835d2d9SIvan Vecera #define BNAD_NUM_RXQ_COUNTERS 7
27f844a0eaSJeff Kirsher #define BNAD_NUM_TXQ_COUNTERS 5
28f844a0eaSJeff Kirsher
2937dd3482SIvan Vecera static const char *bnad_net_stats_strings[] = {
30f844a0eaSJeff Kirsher "rx_packets",
31f844a0eaSJeff Kirsher "tx_packets",
32f844a0eaSJeff Kirsher "rx_bytes",
33f844a0eaSJeff Kirsher "tx_bytes",
34f844a0eaSJeff Kirsher "rx_errors",
35f844a0eaSJeff Kirsher "tx_errors",
36f844a0eaSJeff Kirsher "rx_dropped",
37f844a0eaSJeff Kirsher "tx_dropped",
38f844a0eaSJeff Kirsher "multicast",
39f844a0eaSJeff Kirsher "collisions",
40f844a0eaSJeff Kirsher "rx_length_errors",
41f844a0eaSJeff Kirsher "rx_crc_errors",
42f844a0eaSJeff Kirsher "rx_frame_errors",
43f844a0eaSJeff Kirsher "tx_fifo_errors",
44f844a0eaSJeff Kirsher
45f844a0eaSJeff Kirsher "netif_queue_stop",
46f844a0eaSJeff Kirsher "netif_queue_wakeup",
47f844a0eaSJeff Kirsher "netif_queue_stopped",
48f844a0eaSJeff Kirsher "tso4",
49f844a0eaSJeff Kirsher "tso6",
50f844a0eaSJeff Kirsher "tso_err",
51f844a0eaSJeff Kirsher "tcpcsum_offload",
52f844a0eaSJeff Kirsher "udpcsum_offload",
53f844a0eaSJeff Kirsher "csum_help",
54a2122d95SRasesh Mody "tx_skb_too_short",
55a2122d95SRasesh Mody "tx_skb_stopping",
56a2122d95SRasesh Mody "tx_skb_max_vectors",
57a2122d95SRasesh Mody "tx_skb_mss_too_long",
58a2122d95SRasesh Mody "tx_skb_tso_too_short",
59a2122d95SRasesh Mody "tx_skb_tso_prepare",
60a2122d95SRasesh Mody "tx_skb_non_tso_too_long",
61a2122d95SRasesh Mody "tx_skb_tcp_hdr",
62a2122d95SRasesh Mody "tx_skb_udp_hdr",
63a2122d95SRasesh Mody "tx_skb_csum_err",
64a2122d95SRasesh Mody "tx_skb_headlen_too_long",
65a2122d95SRasesh Mody "tx_skb_headlen_zero",
66a2122d95SRasesh Mody "tx_skb_frag_zero",
67a2122d95SRasesh Mody "tx_skb_len_mismatch",
68ba5ca784SIvan Vecera "tx_skb_map_failed",
69f844a0eaSJeff Kirsher "hw_stats_updates",
70f844a0eaSJeff Kirsher "netif_rx_dropped",
71f844a0eaSJeff Kirsher
72f844a0eaSJeff Kirsher "link_toggle",
73a2122d95SRasesh Mody "cee_toggle",
74f844a0eaSJeff Kirsher
75f844a0eaSJeff Kirsher "rxp_info_alloc_failed",
76f844a0eaSJeff Kirsher "mbox_intr_disabled",
77f844a0eaSJeff Kirsher "mbox_intr_enabled",
78f844a0eaSJeff Kirsher "tx_unmap_q_alloc_failed",
79f844a0eaSJeff Kirsher "rx_unmap_q_alloc_failed",
80f844a0eaSJeff Kirsher "rxbuf_alloc_failed",
81ba5ca784SIvan Vecera "rxbuf_map_failed",
82f844a0eaSJeff Kirsher
83478ab8c9SRasesh Mody "mac_stats_clr_cnt",
84f844a0eaSJeff Kirsher "mac_frame_64",
85f844a0eaSJeff Kirsher "mac_frame_65_127",
86f844a0eaSJeff Kirsher "mac_frame_128_255",
87f844a0eaSJeff Kirsher "mac_frame_256_511",
88f844a0eaSJeff Kirsher "mac_frame_512_1023",
89f844a0eaSJeff Kirsher "mac_frame_1024_1518",
90f844a0eaSJeff Kirsher "mac_frame_1518_1522",
91f844a0eaSJeff Kirsher "mac_rx_bytes",
92f844a0eaSJeff Kirsher "mac_rx_packets",
93f844a0eaSJeff Kirsher "mac_rx_fcs_error",
94f844a0eaSJeff Kirsher "mac_rx_multicast",
95f844a0eaSJeff Kirsher "mac_rx_broadcast",
96f844a0eaSJeff Kirsher "mac_rx_control_frames",
97f844a0eaSJeff Kirsher "mac_rx_pause",
98f844a0eaSJeff Kirsher "mac_rx_unknown_opcode",
99f844a0eaSJeff Kirsher "mac_rx_alignment_error",
100f844a0eaSJeff Kirsher "mac_rx_frame_length_error",
101f844a0eaSJeff Kirsher "mac_rx_code_error",
102f844a0eaSJeff Kirsher "mac_rx_carrier_sense_error",
103f844a0eaSJeff Kirsher "mac_rx_undersize",
104f844a0eaSJeff Kirsher "mac_rx_oversize",
105f844a0eaSJeff Kirsher "mac_rx_fragments",
106f844a0eaSJeff Kirsher "mac_rx_jabber",
107f844a0eaSJeff Kirsher "mac_rx_drop",
108f844a0eaSJeff Kirsher
109f844a0eaSJeff Kirsher "mac_tx_bytes",
110f844a0eaSJeff Kirsher "mac_tx_packets",
111f844a0eaSJeff Kirsher "mac_tx_multicast",
112f844a0eaSJeff Kirsher "mac_tx_broadcast",
113f844a0eaSJeff Kirsher "mac_tx_pause",
114f844a0eaSJeff Kirsher "mac_tx_deferral",
115f844a0eaSJeff Kirsher "mac_tx_excessive_deferral",
116f844a0eaSJeff Kirsher "mac_tx_single_collision",
117*3b882a7bSColin Ian King "mac_tx_multiple_collision",
118f844a0eaSJeff Kirsher "mac_tx_late_collision",
119f844a0eaSJeff Kirsher "mac_tx_excessive_collision",
120f844a0eaSJeff Kirsher "mac_tx_total_collision",
121f844a0eaSJeff Kirsher "mac_tx_pause_honored",
122f844a0eaSJeff Kirsher "mac_tx_drop",
123f844a0eaSJeff Kirsher "mac_tx_jabber",
124f844a0eaSJeff Kirsher "mac_tx_fcs_error",
125f844a0eaSJeff Kirsher "mac_tx_control_frame",
126f844a0eaSJeff Kirsher "mac_tx_oversize",
127f844a0eaSJeff Kirsher "mac_tx_undersize",
128f844a0eaSJeff Kirsher "mac_tx_fragments",
129f844a0eaSJeff Kirsher
130f844a0eaSJeff Kirsher "bpc_tx_pause_0",
131f844a0eaSJeff Kirsher "bpc_tx_pause_1",
132f844a0eaSJeff Kirsher "bpc_tx_pause_2",
133f844a0eaSJeff Kirsher "bpc_tx_pause_3",
134f844a0eaSJeff Kirsher "bpc_tx_pause_4",
135f844a0eaSJeff Kirsher "bpc_tx_pause_5",
136f844a0eaSJeff Kirsher "bpc_tx_pause_6",
137f844a0eaSJeff Kirsher "bpc_tx_pause_7",
138f844a0eaSJeff Kirsher "bpc_tx_zero_pause_0",
139f844a0eaSJeff Kirsher "bpc_tx_zero_pause_1",
140f844a0eaSJeff Kirsher "bpc_tx_zero_pause_2",
141f844a0eaSJeff Kirsher "bpc_tx_zero_pause_3",
142f844a0eaSJeff Kirsher "bpc_tx_zero_pause_4",
143f844a0eaSJeff Kirsher "bpc_tx_zero_pause_5",
144f844a0eaSJeff Kirsher "bpc_tx_zero_pause_6",
145f844a0eaSJeff Kirsher "bpc_tx_zero_pause_7",
146f844a0eaSJeff Kirsher "bpc_tx_first_pause_0",
147f844a0eaSJeff Kirsher "bpc_tx_first_pause_1",
148f844a0eaSJeff Kirsher "bpc_tx_first_pause_2",
149f844a0eaSJeff Kirsher "bpc_tx_first_pause_3",
150f844a0eaSJeff Kirsher "bpc_tx_first_pause_4",
151f844a0eaSJeff Kirsher "bpc_tx_first_pause_5",
152f844a0eaSJeff Kirsher "bpc_tx_first_pause_6",
153f844a0eaSJeff Kirsher "bpc_tx_first_pause_7",
154f844a0eaSJeff Kirsher
155f844a0eaSJeff Kirsher "bpc_rx_pause_0",
156f844a0eaSJeff Kirsher "bpc_rx_pause_1",
157f844a0eaSJeff Kirsher "bpc_rx_pause_2",
158f844a0eaSJeff Kirsher "bpc_rx_pause_3",
159f844a0eaSJeff Kirsher "bpc_rx_pause_4",
160f844a0eaSJeff Kirsher "bpc_rx_pause_5",
161f844a0eaSJeff Kirsher "bpc_rx_pause_6",
162f844a0eaSJeff Kirsher "bpc_rx_pause_7",
163f844a0eaSJeff Kirsher "bpc_rx_zero_pause_0",
164f844a0eaSJeff Kirsher "bpc_rx_zero_pause_1",
165f844a0eaSJeff Kirsher "bpc_rx_zero_pause_2",
166f844a0eaSJeff Kirsher "bpc_rx_zero_pause_3",
167f844a0eaSJeff Kirsher "bpc_rx_zero_pause_4",
168f844a0eaSJeff Kirsher "bpc_rx_zero_pause_5",
169f844a0eaSJeff Kirsher "bpc_rx_zero_pause_6",
170f844a0eaSJeff Kirsher "bpc_rx_zero_pause_7",
171f844a0eaSJeff Kirsher "bpc_rx_first_pause_0",
172f844a0eaSJeff Kirsher "bpc_rx_first_pause_1",
173f844a0eaSJeff Kirsher "bpc_rx_first_pause_2",
174f844a0eaSJeff Kirsher "bpc_rx_first_pause_3",
175f844a0eaSJeff Kirsher "bpc_rx_first_pause_4",
176f844a0eaSJeff Kirsher "bpc_rx_first_pause_5",
177f844a0eaSJeff Kirsher "bpc_rx_first_pause_6",
178f844a0eaSJeff Kirsher "bpc_rx_first_pause_7",
179f844a0eaSJeff Kirsher
180f844a0eaSJeff Kirsher "rad_rx_frames",
181f844a0eaSJeff Kirsher "rad_rx_octets",
182f844a0eaSJeff Kirsher "rad_rx_vlan_frames",
183f844a0eaSJeff Kirsher "rad_rx_ucast",
184f844a0eaSJeff Kirsher "rad_rx_ucast_octets",
185f844a0eaSJeff Kirsher "rad_rx_ucast_vlan",
186f844a0eaSJeff Kirsher "rad_rx_mcast",
187f844a0eaSJeff Kirsher "rad_rx_mcast_octets",
188f844a0eaSJeff Kirsher "rad_rx_mcast_vlan",
189f844a0eaSJeff Kirsher "rad_rx_bcast",
190f844a0eaSJeff Kirsher "rad_rx_bcast_octets",
191f844a0eaSJeff Kirsher "rad_rx_bcast_vlan",
192f844a0eaSJeff Kirsher "rad_rx_drops",
193f844a0eaSJeff Kirsher
194a2122d95SRasesh Mody "rlb_rad_rx_frames",
195a2122d95SRasesh Mody "rlb_rad_rx_octets",
196a2122d95SRasesh Mody "rlb_rad_rx_vlan_frames",
197a2122d95SRasesh Mody "rlb_rad_rx_ucast",
198a2122d95SRasesh Mody "rlb_rad_rx_ucast_octets",
199a2122d95SRasesh Mody "rlb_rad_rx_ucast_vlan",
200a2122d95SRasesh Mody "rlb_rad_rx_mcast",
201a2122d95SRasesh Mody "rlb_rad_rx_mcast_octets",
202a2122d95SRasesh Mody "rlb_rad_rx_mcast_vlan",
203a2122d95SRasesh Mody "rlb_rad_rx_bcast",
204a2122d95SRasesh Mody "rlb_rad_rx_bcast_octets",
205a2122d95SRasesh Mody "rlb_rad_rx_bcast_vlan",
206a2122d95SRasesh Mody "rlb_rad_rx_drops",
207a2122d95SRasesh Mody
208f844a0eaSJeff Kirsher "fc_rx_ucast_octets",
209f844a0eaSJeff Kirsher "fc_rx_ucast",
210f844a0eaSJeff Kirsher "fc_rx_ucast_vlan",
211f844a0eaSJeff Kirsher "fc_rx_mcast_octets",
212f844a0eaSJeff Kirsher "fc_rx_mcast",
213f844a0eaSJeff Kirsher "fc_rx_mcast_vlan",
214f844a0eaSJeff Kirsher "fc_rx_bcast_octets",
215f844a0eaSJeff Kirsher "fc_rx_bcast",
216f844a0eaSJeff Kirsher "fc_rx_bcast_vlan",
217f844a0eaSJeff Kirsher
218f844a0eaSJeff Kirsher "fc_tx_ucast_octets",
219f844a0eaSJeff Kirsher "fc_tx_ucast",
220f844a0eaSJeff Kirsher "fc_tx_ucast_vlan",
221f844a0eaSJeff Kirsher "fc_tx_mcast_octets",
222f844a0eaSJeff Kirsher "fc_tx_mcast",
223f844a0eaSJeff Kirsher "fc_tx_mcast_vlan",
224f844a0eaSJeff Kirsher "fc_tx_bcast_octets",
225f844a0eaSJeff Kirsher "fc_tx_bcast",
226f844a0eaSJeff Kirsher "fc_tx_bcast_vlan",
227f844a0eaSJeff Kirsher "fc_tx_parity_errors",
228f844a0eaSJeff Kirsher "fc_tx_timeout",
229f844a0eaSJeff Kirsher "fc_tx_fid_parity_errors",
230f844a0eaSJeff Kirsher };
231f844a0eaSJeff Kirsher
23237dd3482SIvan Vecera #define BNAD_ETHTOOL_STATS_NUM ARRAY_SIZE(bnad_net_stats_strings)
23337dd3482SIvan Vecera
234f844a0eaSJeff Kirsher static int
bnad_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)235377fa64fSPhilippe Reynes bnad_get_link_ksettings(struct net_device *netdev,
236377fa64fSPhilippe Reynes struct ethtool_link_ksettings *cmd)
237f844a0eaSJeff Kirsher {
2387adf9053SErik Ekman ethtool_link_ksettings_zero_link_mode(cmd, supported);
2397adf9053SErik Ekman ethtool_link_ksettings_zero_link_mode(cmd, advertising);
240377fa64fSPhilippe Reynes
2417adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, supported, 10000baseCR_Full);
2427adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, supported, 10000baseSR_Full);
2437adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, supported, 10000baseLR_Full);
2447adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, advertising, 10000baseCR_Full);
2457adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, advertising, 10000baseSR_Full);
2467adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, advertising, 10000baseLR_Full);
247377fa64fSPhilippe Reynes cmd->base.autoneg = AUTONEG_DISABLE;
2487adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
2497adf9053SErik Ekman ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
250377fa64fSPhilippe Reynes cmd->base.port = PORT_FIBRE;
251377fa64fSPhilippe Reynes cmd->base.phy_address = 0;
252f844a0eaSJeff Kirsher
253f844a0eaSJeff Kirsher if (netif_carrier_ok(netdev)) {
254377fa64fSPhilippe Reynes cmd->base.speed = SPEED_10000;
255377fa64fSPhilippe Reynes cmd->base.duplex = DUPLEX_FULL;
256f844a0eaSJeff Kirsher } else {
257377fa64fSPhilippe Reynes cmd->base.speed = SPEED_UNKNOWN;
258377fa64fSPhilippe Reynes cmd->base.duplex = DUPLEX_UNKNOWN;
259f844a0eaSJeff Kirsher }
260377fa64fSPhilippe Reynes
261f844a0eaSJeff Kirsher return 0;
262f844a0eaSJeff Kirsher }
263f844a0eaSJeff Kirsher
264f844a0eaSJeff Kirsher static int
bnad_set_link_ksettings(struct net_device * netdev,const struct ethtool_link_ksettings * cmd)265377fa64fSPhilippe Reynes bnad_set_link_ksettings(struct net_device *netdev,
266377fa64fSPhilippe Reynes const struct ethtool_link_ksettings *cmd)
267f844a0eaSJeff Kirsher {
268f844a0eaSJeff Kirsher /* 10G full duplex setting supported only */
269377fa64fSPhilippe Reynes if (cmd->base.autoneg == AUTONEG_ENABLE)
270377fa64fSPhilippe Reynes return -EOPNOTSUPP;
271377fa64fSPhilippe Reynes
272377fa64fSPhilippe Reynes if ((cmd->base.speed == SPEED_10000) &&
273377fa64fSPhilippe Reynes (cmd->base.duplex == DUPLEX_FULL))
274f844a0eaSJeff Kirsher return 0;
275f844a0eaSJeff Kirsher
276f844a0eaSJeff Kirsher return -EOPNOTSUPP;
277f844a0eaSJeff Kirsher }
278f844a0eaSJeff Kirsher
279f844a0eaSJeff Kirsher static void
bnad_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)280f844a0eaSJeff Kirsher bnad_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
281f844a0eaSJeff Kirsher {
282f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
283f844a0eaSJeff Kirsher struct bfa_ioc_attr *ioc_attr;
284f844a0eaSJeff Kirsher unsigned long flags;
285f844a0eaSJeff Kirsher
286f029c781SWolfram Sang strscpy(drvinfo->driver, BNAD_NAME, sizeof(drvinfo->driver));
287f844a0eaSJeff Kirsher
288f844a0eaSJeff Kirsher ioc_attr = kzalloc(sizeof(*ioc_attr), GFP_KERNEL);
289f844a0eaSJeff Kirsher if (ioc_attr) {
290f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
291078086f3SRasesh Mody bfa_nw_ioc_get_attr(&bnad->bna.ioceth.ioc, ioc_attr);
292f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
293f844a0eaSJeff Kirsher
294f029c781SWolfram Sang strscpy(drvinfo->fw_version, ioc_attr->adapter_attr.fw_ver,
29568aad78cSRick Jones sizeof(drvinfo->fw_version));
296f844a0eaSJeff Kirsher kfree(ioc_attr);
297f844a0eaSJeff Kirsher }
298f844a0eaSJeff Kirsher
299f029c781SWolfram Sang strscpy(drvinfo->bus_info, pci_name(bnad->pcidev),
30068aad78cSRick Jones sizeof(drvinfo->bus_info));
301f844a0eaSJeff Kirsher }
302f844a0eaSJeff Kirsher
303f844a0eaSJeff Kirsher static void
bnad_get_wol(struct net_device * netdev,struct ethtool_wolinfo * wolinfo)304f844a0eaSJeff Kirsher bnad_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wolinfo)
305f844a0eaSJeff Kirsher {
306f844a0eaSJeff Kirsher wolinfo->supported = 0;
307f844a0eaSJeff Kirsher wolinfo->wolopts = 0;
308f844a0eaSJeff Kirsher }
309f844a0eaSJeff Kirsher
bnad_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * coalesce,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)310f3ccfda1SYufeng Mo static int bnad_get_coalesce(struct net_device *netdev,
311f3ccfda1SYufeng Mo struct ethtool_coalesce *coalesce,
312f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
313f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
314f844a0eaSJeff Kirsher {
315f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
316f844a0eaSJeff Kirsher unsigned long flags;
317f844a0eaSJeff Kirsher
318f844a0eaSJeff Kirsher /* Lock rqd. to access bnad->bna_lock */
319f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
320f844a0eaSJeff Kirsher coalesce->use_adaptive_rx_coalesce =
321f844a0eaSJeff Kirsher (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) ? true : false;
322f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
323f844a0eaSJeff Kirsher
324f844a0eaSJeff Kirsher coalesce->rx_coalesce_usecs = bnad->rx_coalescing_timeo *
325f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT;
326f844a0eaSJeff Kirsher coalesce->tx_coalesce_usecs = bnad->tx_coalescing_timeo *
327f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT;
328f844a0eaSJeff Kirsher coalesce->tx_max_coalesced_frames = BFI_TX_INTERPKT_COUNT;
329f844a0eaSJeff Kirsher
330f844a0eaSJeff Kirsher return 0;
331f844a0eaSJeff Kirsher }
332f844a0eaSJeff Kirsher
bnad_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * coalesce,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)333f3ccfda1SYufeng Mo static int bnad_set_coalesce(struct net_device *netdev,
334f3ccfda1SYufeng Mo struct ethtool_coalesce *coalesce,
335f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
336f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
337f844a0eaSJeff Kirsher {
338f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
339f844a0eaSJeff Kirsher unsigned long flags;
340a2122d95SRasesh Mody int to_del = 0;
341f844a0eaSJeff Kirsher
342f844a0eaSJeff Kirsher if (coalesce->rx_coalesce_usecs == 0 ||
343f844a0eaSJeff Kirsher coalesce->rx_coalesce_usecs >
344f844a0eaSJeff Kirsher BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
345f844a0eaSJeff Kirsher return -EINVAL;
346f844a0eaSJeff Kirsher
347f844a0eaSJeff Kirsher if (coalesce->tx_coalesce_usecs == 0 ||
348f844a0eaSJeff Kirsher coalesce->tx_coalesce_usecs >
349f844a0eaSJeff Kirsher BFI_MAX_COALESCING_TIMEO * BFI_COALESCING_TIMER_UNIT)
350f844a0eaSJeff Kirsher return -EINVAL;
351f844a0eaSJeff Kirsher
352f844a0eaSJeff Kirsher mutex_lock(&bnad->conf_mutex);
353f844a0eaSJeff Kirsher /*
354f844a0eaSJeff Kirsher * Do not need to store rx_coalesce_usecs here
355f844a0eaSJeff Kirsher * Every time DIM is disabled, we can get it from the
356f844a0eaSJeff Kirsher * stack.
357f844a0eaSJeff Kirsher */
358f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
359f844a0eaSJeff Kirsher if (coalesce->use_adaptive_rx_coalesce) {
360f844a0eaSJeff Kirsher if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED)) {
361f844a0eaSJeff Kirsher bnad->cfg_flags |= BNAD_CF_DIM_ENABLED;
362f844a0eaSJeff Kirsher bnad_dim_timer_start(bnad);
363f844a0eaSJeff Kirsher }
364f844a0eaSJeff Kirsher } else {
365f844a0eaSJeff Kirsher if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) {
366f844a0eaSJeff Kirsher bnad->cfg_flags &= ~BNAD_CF_DIM_ENABLED;
367a2122d95SRasesh Mody if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED &&
368a2122d95SRasesh Mody test_bit(BNAD_RF_DIM_TIMER_RUNNING,
369a2122d95SRasesh Mody &bnad->run_flags)) {
370f844a0eaSJeff Kirsher clear_bit(BNAD_RF_DIM_TIMER_RUNNING,
371f844a0eaSJeff Kirsher &bnad->run_flags);
372a2122d95SRasesh Mody to_del = 1;
373a2122d95SRasesh Mody }
374f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
375a2122d95SRasesh Mody if (to_del)
376f844a0eaSJeff Kirsher del_timer_sync(&bnad->dim_timer);
377f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
378f844a0eaSJeff Kirsher bnad_rx_coalescing_timeo_set(bnad);
379f844a0eaSJeff Kirsher }
380f844a0eaSJeff Kirsher }
381f844a0eaSJeff Kirsher if (bnad->tx_coalescing_timeo != coalesce->tx_coalesce_usecs /
382f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT) {
383f844a0eaSJeff Kirsher bnad->tx_coalescing_timeo = coalesce->tx_coalesce_usecs /
384f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT;
385f844a0eaSJeff Kirsher bnad_tx_coalescing_timeo_set(bnad);
386f844a0eaSJeff Kirsher }
387f844a0eaSJeff Kirsher
388f844a0eaSJeff Kirsher if (bnad->rx_coalescing_timeo != coalesce->rx_coalesce_usecs /
389f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT) {
390f844a0eaSJeff Kirsher bnad->rx_coalescing_timeo = coalesce->rx_coalesce_usecs /
391f844a0eaSJeff Kirsher BFI_COALESCING_TIMER_UNIT;
392f844a0eaSJeff Kirsher
393f844a0eaSJeff Kirsher if (!(bnad->cfg_flags & BNAD_CF_DIM_ENABLED))
394f844a0eaSJeff Kirsher bnad_rx_coalescing_timeo_set(bnad);
395f844a0eaSJeff Kirsher
396f844a0eaSJeff Kirsher }
397f844a0eaSJeff Kirsher
398f844a0eaSJeff Kirsher /* Add Tx Inter-pkt DMA count? */
399f844a0eaSJeff Kirsher
400f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
401f844a0eaSJeff Kirsher
402f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
403f844a0eaSJeff Kirsher return 0;
404f844a0eaSJeff Kirsher }
405f844a0eaSJeff Kirsher
406f844a0eaSJeff Kirsher static void
bnad_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ringparam,struct kernel_ethtool_ringparam * kernel_ringparam,struct netlink_ext_ack * extack)407f844a0eaSJeff Kirsher bnad_get_ringparam(struct net_device *netdev,
40874624944SHao Chen struct ethtool_ringparam *ringparam,
40974624944SHao Chen struct kernel_ethtool_ringparam *kernel_ringparam,
41074624944SHao Chen struct netlink_ext_ack *extack)
411f844a0eaSJeff Kirsher {
412f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
413f844a0eaSJeff Kirsher
41441eb5ba4SRasesh Mody ringparam->rx_max_pending = BNAD_MAX_RXQ_DEPTH;
41541eb5ba4SRasesh Mody ringparam->tx_max_pending = BNAD_MAX_TXQ_DEPTH;
416f844a0eaSJeff Kirsher
417f844a0eaSJeff Kirsher ringparam->rx_pending = bnad->rxq_depth;
418f844a0eaSJeff Kirsher ringparam->tx_pending = bnad->txq_depth;
419f844a0eaSJeff Kirsher }
420f844a0eaSJeff Kirsher
421f844a0eaSJeff Kirsher static int
bnad_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ringparam,struct kernel_ethtool_ringparam * kernel_ringparam,struct netlink_ext_ack * extack)422f844a0eaSJeff Kirsher bnad_set_ringparam(struct net_device *netdev,
42374624944SHao Chen struct ethtool_ringparam *ringparam,
42474624944SHao Chen struct kernel_ethtool_ringparam *kernel_ringparam,
42574624944SHao Chen struct netlink_ext_ack *extack)
426f844a0eaSJeff Kirsher {
427f844a0eaSJeff Kirsher int i, current_err, err = 0;
428f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
429a2122d95SRasesh Mody unsigned long flags;
430f844a0eaSJeff Kirsher
431f844a0eaSJeff Kirsher mutex_lock(&bnad->conf_mutex);
432f844a0eaSJeff Kirsher if (ringparam->rx_pending == bnad->rxq_depth &&
433f844a0eaSJeff Kirsher ringparam->tx_pending == bnad->txq_depth) {
434f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
435f844a0eaSJeff Kirsher return 0;
436f844a0eaSJeff Kirsher }
437f844a0eaSJeff Kirsher
438f844a0eaSJeff Kirsher if (ringparam->rx_pending < BNAD_MIN_Q_DEPTH ||
43941eb5ba4SRasesh Mody ringparam->rx_pending > BNAD_MAX_RXQ_DEPTH ||
440a1ac490dSIvan Vecera !is_power_of_2(ringparam->rx_pending)) {
441f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
442f844a0eaSJeff Kirsher return -EINVAL;
443f844a0eaSJeff Kirsher }
444f844a0eaSJeff Kirsher if (ringparam->tx_pending < BNAD_MIN_Q_DEPTH ||
44541eb5ba4SRasesh Mody ringparam->tx_pending > BNAD_MAX_TXQ_DEPTH ||
446a1ac490dSIvan Vecera !is_power_of_2(ringparam->tx_pending)) {
447f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
448f844a0eaSJeff Kirsher return -EINVAL;
449f844a0eaSJeff Kirsher }
450f844a0eaSJeff Kirsher
451f844a0eaSJeff Kirsher if (ringparam->rx_pending != bnad->rxq_depth) {
452f844a0eaSJeff Kirsher bnad->rxq_depth = ringparam->rx_pending;
453a2122d95SRasesh Mody if (!netif_running(netdev)) {
454a2122d95SRasesh Mody mutex_unlock(&bnad->conf_mutex);
455a2122d95SRasesh Mody return 0;
456a2122d95SRasesh Mody }
457a2122d95SRasesh Mody
458f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
459f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
460f844a0eaSJeff Kirsher continue;
461b3cc6e88SJing Huang bnad_destroy_rx(bnad, i);
462f844a0eaSJeff Kirsher current_err = bnad_setup_rx(bnad, i);
463f844a0eaSJeff Kirsher if (current_err && !err)
464f844a0eaSJeff Kirsher err = current_err;
465a2122d95SRasesh Mody }
466a2122d95SRasesh Mody
467a2122d95SRasesh Mody if (!err && bnad->rx_info[0].rx) {
468a2122d95SRasesh Mody /* restore rx configuration */
4693fb9852fSRasesh Mody bnad_restore_vlans(bnad, 0);
470a2122d95SRasesh Mody bnad_enable_default_bcast(bnad);
471a2122d95SRasesh Mody spin_lock_irqsave(&bnad->bna_lock, flags);
472a2122d95SRasesh Mody bnad_mac_addr_set_locked(bnad, netdev->dev_addr);
473a2122d95SRasesh Mody spin_unlock_irqrestore(&bnad->bna_lock, flags);
4743fb9852fSRasesh Mody bnad->cfg_flags &= ~(BNAD_CF_ALLMULTI |
4753fb9852fSRasesh Mody BNAD_CF_PROMISC);
476a2122d95SRasesh Mody bnad_set_rx_mode(netdev);
477f844a0eaSJeff Kirsher }
478f844a0eaSJeff Kirsher }
479f844a0eaSJeff Kirsher if (ringparam->tx_pending != bnad->txq_depth) {
480f844a0eaSJeff Kirsher bnad->txq_depth = ringparam->tx_pending;
481a2122d95SRasesh Mody if (!netif_running(netdev)) {
482a2122d95SRasesh Mody mutex_unlock(&bnad->conf_mutex);
483a2122d95SRasesh Mody return 0;
484a2122d95SRasesh Mody }
485a2122d95SRasesh Mody
486f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_tx; i++) {
487f844a0eaSJeff Kirsher if (!bnad->tx_info[i].tx)
488f844a0eaSJeff Kirsher continue;
489b3cc6e88SJing Huang bnad_destroy_tx(bnad, i);
490f844a0eaSJeff Kirsher current_err = bnad_setup_tx(bnad, i);
491f844a0eaSJeff Kirsher if (current_err && !err)
492f844a0eaSJeff Kirsher err = current_err;
493f844a0eaSJeff Kirsher }
494f844a0eaSJeff Kirsher }
495f844a0eaSJeff Kirsher
496f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
497f844a0eaSJeff Kirsher return err;
498f844a0eaSJeff Kirsher }
499f844a0eaSJeff Kirsher
500f844a0eaSJeff Kirsher static void
bnad_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pauseparam)501f844a0eaSJeff Kirsher bnad_get_pauseparam(struct net_device *netdev,
502f844a0eaSJeff Kirsher struct ethtool_pauseparam *pauseparam)
503f844a0eaSJeff Kirsher {
504f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
505f844a0eaSJeff Kirsher
506f844a0eaSJeff Kirsher pauseparam->autoneg = 0;
507078086f3SRasesh Mody pauseparam->rx_pause = bnad->bna.enet.pause_config.rx_pause;
508078086f3SRasesh Mody pauseparam->tx_pause = bnad->bna.enet.pause_config.tx_pause;
509f844a0eaSJeff Kirsher }
510f844a0eaSJeff Kirsher
511f844a0eaSJeff Kirsher static int
bnad_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pauseparam)512f844a0eaSJeff Kirsher bnad_set_pauseparam(struct net_device *netdev,
513f844a0eaSJeff Kirsher struct ethtool_pauseparam *pauseparam)
514f844a0eaSJeff Kirsher {
515f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
516f844a0eaSJeff Kirsher struct bna_pause_config pause_config;
517f844a0eaSJeff Kirsher unsigned long flags;
518f844a0eaSJeff Kirsher
519f844a0eaSJeff Kirsher if (pauseparam->autoneg == AUTONEG_ENABLE)
520f844a0eaSJeff Kirsher return -EINVAL;
521f844a0eaSJeff Kirsher
522f844a0eaSJeff Kirsher mutex_lock(&bnad->conf_mutex);
523078086f3SRasesh Mody if (pauseparam->rx_pause != bnad->bna.enet.pause_config.rx_pause ||
524078086f3SRasesh Mody pauseparam->tx_pause != bnad->bna.enet.pause_config.tx_pause) {
525f844a0eaSJeff Kirsher pause_config.rx_pause = pauseparam->rx_pause;
526f844a0eaSJeff Kirsher pause_config.tx_pause = pauseparam->tx_pause;
527f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
5281f9883e0SIvan Vecera bna_enet_pause_config(&bnad->bna.enet, &pause_config);
529f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
530f844a0eaSJeff Kirsher }
531f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
532f844a0eaSJeff Kirsher return 0;
533f844a0eaSJeff Kirsher }
534f844a0eaSJeff Kirsher
bnad_get_txf_strings(u8 ** string,int f_num)535b82e8118SAlexander Duyck static void bnad_get_txf_strings(u8 **string, int f_num)
536b82e8118SAlexander Duyck {
537b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_ucast_octets", f_num);
538b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_ucast", f_num);
539b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_ucast_vlan", f_num);
540b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_mcast_octets", f_num);
541b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_mcast", f_num);
542b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_mcast_vlan", f_num);
543b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_bcast_octets", f_num);
544b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_bcast", f_num);
545b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_bcast_vlan", f_num);
546b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_errors", f_num);
547b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_filter_vlan", f_num);
548b82e8118SAlexander Duyck ethtool_sprintf(string, "txf%d_filter_mac_sa", f_num);
549b82e8118SAlexander Duyck }
550b82e8118SAlexander Duyck
bnad_get_rxf_strings(u8 ** string,int f_num)551b82e8118SAlexander Duyck static void bnad_get_rxf_strings(u8 **string, int f_num)
552b82e8118SAlexander Duyck {
553b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_ucast_octets", f_num);
554b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_ucast", f_num);
555b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_ucast_vlan", f_num);
556b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_mcast_octets", f_num);
557b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_mcast", f_num);
558b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_mcast_vlan", f_num);
559b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_bcast_octets", f_num);
560b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_bcast", f_num);
561b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_bcast_vlan", f_num);
562b82e8118SAlexander Duyck ethtool_sprintf(string, "rxf%d_frame_drops", f_num);
563b82e8118SAlexander Duyck }
564b82e8118SAlexander Duyck
bnad_get_cq_strings(u8 ** string,int q_num)565b82e8118SAlexander Duyck static void bnad_get_cq_strings(u8 **string, int q_num)
566b82e8118SAlexander Duyck {
567b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_producer_index", q_num);
568b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_consumer_index", q_num);
569b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_hw_producer_index", q_num);
570b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_intr", q_num);
571b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_poll", q_num);
572b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_schedule", q_num);
573b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_keep_poll", q_num);
574b82e8118SAlexander Duyck ethtool_sprintf(string, "cq%d_complete", q_num);
575b82e8118SAlexander Duyck }
576b82e8118SAlexander Duyck
bnad_get_rxq_strings(u8 ** string,int q_num)577b82e8118SAlexander Duyck static void bnad_get_rxq_strings(u8 **string, int q_num)
578b82e8118SAlexander Duyck {
579b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_packets", q_num);
580b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_bytes", q_num);
581b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_packets_with_error", q_num);
582b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_allocbuf_failed", q_num);
583b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_mapbuf_failed", q_num);
584b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_producer_index", q_num);
585b82e8118SAlexander Duyck ethtool_sprintf(string, "rxq%d_consumer_index", q_num);
586b82e8118SAlexander Duyck }
587b82e8118SAlexander Duyck
bnad_get_txq_strings(u8 ** string,int q_num)588b82e8118SAlexander Duyck static void bnad_get_txq_strings(u8 **string, int q_num)
589b82e8118SAlexander Duyck {
590b82e8118SAlexander Duyck ethtool_sprintf(string, "txq%d_packets", q_num);
591b82e8118SAlexander Duyck ethtool_sprintf(string, "txq%d_bytes", q_num);
592b82e8118SAlexander Duyck ethtool_sprintf(string, "txq%d_producer_index", q_num);
593b82e8118SAlexander Duyck ethtool_sprintf(string, "txq%d_consumer_index", q_num);
594b82e8118SAlexander Duyck ethtool_sprintf(string, "txq%d_hw_consumer_index", q_num);
595b82e8118SAlexander Duyck }
596b82e8118SAlexander Duyck
597f844a0eaSJeff Kirsher static void
bnad_get_strings(struct net_device * netdev,u32 stringset,u8 * string)598f844a0eaSJeff Kirsher bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
599f844a0eaSJeff Kirsher {
600f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
601f844a0eaSJeff Kirsher int i, j, q_num;
602078086f3SRasesh Mody u32 bmap;
603f844a0eaSJeff Kirsher
604b82e8118SAlexander Duyck if (stringset != ETH_SS_STATS)
605b82e8118SAlexander Duyck return;
606b82e8118SAlexander Duyck
607f844a0eaSJeff Kirsher mutex_lock(&bnad->conf_mutex);
608f844a0eaSJeff Kirsher
609f844a0eaSJeff Kirsher for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
610b82e8118SAlexander Duyck BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
611b82e8118SAlexander Duyck ethtool_sprintf(&string, bnad_net_stats_strings[i]);
612f844a0eaSJeff Kirsher }
613b82e8118SAlexander Duyck
614078086f3SRasesh Mody bmap = bna_tx_rid_mask(&bnad->bna);
615078086f3SRasesh Mody for (i = 0; bmap; i++) {
616b82e8118SAlexander Duyck if (bmap & 1)
617b82e8118SAlexander Duyck bnad_get_txf_strings(&string, i);
618f844a0eaSJeff Kirsher bmap >>= 1;
619f844a0eaSJeff Kirsher }
620f844a0eaSJeff Kirsher
621078086f3SRasesh Mody bmap = bna_rx_rid_mask(&bnad->bna);
622b82e8118SAlexander Duyck for (i = 0; bmap; i++, bmap >>= 1) {
623b82e8118SAlexander Duyck if (bmap & 1)
624b82e8118SAlexander Duyck bnad_get_rxf_strings(&string, i);
625f844a0eaSJeff Kirsher bmap >>= 1;
626f844a0eaSJeff Kirsher }
627f844a0eaSJeff Kirsher
628f844a0eaSJeff Kirsher q_num = 0;
629f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
630f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
631f844a0eaSJeff Kirsher continue;
632b82e8118SAlexander Duyck for (j = 0; j < bnad->num_rxp_per_rx; j++)
633b82e8118SAlexander Duyck bnad_get_cq_strings(&string, q_num++);
634f844a0eaSJeff Kirsher }
635f844a0eaSJeff Kirsher
636f844a0eaSJeff Kirsher q_num = 0;
637f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
638f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
639f844a0eaSJeff Kirsher continue;
640f844a0eaSJeff Kirsher for (j = 0; j < bnad->num_rxp_per_rx; j++) {
641b82e8118SAlexander Duyck bnad_get_rxq_strings(&string, q_num++);
642f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb &&
643b82e8118SAlexander Duyck bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
644b82e8118SAlexander Duyck bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
645b82e8118SAlexander Duyck bnad_get_rxq_strings(&string, q_num++);
646f844a0eaSJeff Kirsher }
647f844a0eaSJeff Kirsher }
648f844a0eaSJeff Kirsher
649f844a0eaSJeff Kirsher q_num = 0;
650f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_tx; i++) {
651f844a0eaSJeff Kirsher if (!bnad->tx_info[i].tx)
652f844a0eaSJeff Kirsher continue;
653b82e8118SAlexander Duyck for (j = 0; j < bnad->num_txq_per_tx; j++)
654b82e8118SAlexander Duyck bnad_get_txq_strings(&string, q_num++);
655f844a0eaSJeff Kirsher }
656f844a0eaSJeff Kirsher
657f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
658f844a0eaSJeff Kirsher }
659f844a0eaSJeff Kirsher
660f844a0eaSJeff Kirsher static int
bnad_get_stats_count_locked(struct net_device * netdev)661f844a0eaSJeff Kirsher bnad_get_stats_count_locked(struct net_device *netdev)
662f844a0eaSJeff Kirsher {
663f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
664a2122d95SRasesh Mody int i, j, count = 0, rxf_active_num = 0, txf_active_num = 0;
665078086f3SRasesh Mody u32 bmap;
666f844a0eaSJeff Kirsher
667078086f3SRasesh Mody bmap = bna_tx_rid_mask(&bnad->bna);
668078086f3SRasesh Mody for (i = 0; bmap; i++) {
669f844a0eaSJeff Kirsher if (bmap & 1)
670f844a0eaSJeff Kirsher txf_active_num++;
671f844a0eaSJeff Kirsher bmap >>= 1;
672f844a0eaSJeff Kirsher }
673078086f3SRasesh Mody bmap = bna_rx_rid_mask(&bnad->bna);
674078086f3SRasesh Mody for (i = 0; bmap; i++) {
675f844a0eaSJeff Kirsher if (bmap & 1)
676f844a0eaSJeff Kirsher rxf_active_num++;
677f844a0eaSJeff Kirsher bmap >>= 1;
678f844a0eaSJeff Kirsher }
679f844a0eaSJeff Kirsher count = BNAD_ETHTOOL_STATS_NUM +
680f844a0eaSJeff Kirsher txf_active_num * BNAD_NUM_TXF_COUNTERS +
681f844a0eaSJeff Kirsher rxf_active_num * BNAD_NUM_RXF_COUNTERS;
682f844a0eaSJeff Kirsher
683f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
684f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
685f844a0eaSJeff Kirsher continue;
686f844a0eaSJeff Kirsher count += bnad->num_rxp_per_rx * BNAD_NUM_CQ_COUNTERS;
687f844a0eaSJeff Kirsher count += bnad->num_rxp_per_rx * BNAD_NUM_RXQ_COUNTERS;
688f844a0eaSJeff Kirsher for (j = 0; j < bnad->num_rxp_per_rx; j++)
689f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb &&
690f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
691f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1]->rxq)
692f844a0eaSJeff Kirsher count += BNAD_NUM_RXQ_COUNTERS;
693f844a0eaSJeff Kirsher }
694f844a0eaSJeff Kirsher
695f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_tx; i++) {
696f844a0eaSJeff Kirsher if (!bnad->tx_info[i].tx)
697f844a0eaSJeff Kirsher continue;
698f844a0eaSJeff Kirsher count += bnad->num_txq_per_tx * BNAD_NUM_TXQ_COUNTERS;
699f844a0eaSJeff Kirsher }
700f844a0eaSJeff Kirsher return count;
701f844a0eaSJeff Kirsher }
702f844a0eaSJeff Kirsher
703f844a0eaSJeff Kirsher static int
bnad_per_q_stats_fill(struct bnad * bnad,u64 * buf,int bi)704f844a0eaSJeff Kirsher bnad_per_q_stats_fill(struct bnad *bnad, u64 *buf, int bi)
705f844a0eaSJeff Kirsher {
706f844a0eaSJeff Kirsher int i, j;
707f844a0eaSJeff Kirsher struct bna_rcb *rcb = NULL;
708f844a0eaSJeff Kirsher struct bna_tcb *tcb = NULL;
709f844a0eaSJeff Kirsher
710f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
711f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
712f844a0eaSJeff Kirsher continue;
713f844a0eaSJeff Kirsher for (j = 0; j < bnad->num_rxp_per_rx; j++)
714f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb &&
715f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
716f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0]->rxq) {
717f844a0eaSJeff Kirsher buf[bi++] = bnad->rx_info[i].rx_ctrl[j].
718f844a0eaSJeff Kirsher ccb->producer_index;
719f844a0eaSJeff Kirsher buf[bi++] = 0; /* ccb->consumer_index */
720f844a0eaSJeff Kirsher buf[bi++] = *(bnad->rx_info[i].rx_ctrl[j].
721f844a0eaSJeff Kirsher ccb->hw_producer_index);
722a2122d95SRasesh Mody
723a2122d95SRasesh Mody buf[bi++] = bnad->rx_info[i].
724a2122d95SRasesh Mody rx_ctrl[j].rx_intr_ctr;
725a2122d95SRasesh Mody buf[bi++] = bnad->rx_info[i].
726a2122d95SRasesh Mody rx_ctrl[j].rx_poll_ctr;
727a2122d95SRasesh Mody buf[bi++] = bnad->rx_info[i].
728a2122d95SRasesh Mody rx_ctrl[j].rx_schedule;
729a2122d95SRasesh Mody buf[bi++] = bnad->rx_info[i].
730a2122d95SRasesh Mody rx_ctrl[j].rx_keep_poll;
731a2122d95SRasesh Mody buf[bi++] = bnad->rx_info[i].
732a2122d95SRasesh Mody rx_ctrl[j].rx_complete;
733f844a0eaSJeff Kirsher }
734f844a0eaSJeff Kirsher }
735f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_rx; i++) {
736f844a0eaSJeff Kirsher if (!bnad->rx_info[i].rx)
737f844a0eaSJeff Kirsher continue;
738f844a0eaSJeff Kirsher for (j = 0; j < bnad->num_rxp_per_rx; j++)
739f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb) {
740f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[0] &&
741f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->
742f844a0eaSJeff Kirsher rcb[0]->rxq) {
743f844a0eaSJeff Kirsher rcb = bnad->rx_info[i].rx_ctrl[j].
744f844a0eaSJeff Kirsher ccb->rcb[0];
745f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->rx_packets;
746f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->rx_bytes;
747f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->
748f844a0eaSJeff Kirsher rx_packets_with_error;
749f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->
750f844a0eaSJeff Kirsher rxbuf_alloc_failed;
751ba5ca784SIvan Vecera buf[bi++] = rcb->rxq->rxbuf_map_failed;
752f844a0eaSJeff Kirsher buf[bi++] = rcb->producer_index;
753f844a0eaSJeff Kirsher buf[bi++] = rcb->consumer_index;
754f844a0eaSJeff Kirsher }
755f844a0eaSJeff Kirsher if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] &&
756f844a0eaSJeff Kirsher bnad->rx_info[i].rx_ctrl[j].ccb->
757f844a0eaSJeff Kirsher rcb[1]->rxq) {
758f844a0eaSJeff Kirsher rcb = bnad->rx_info[i].rx_ctrl[j].
759f844a0eaSJeff Kirsher ccb->rcb[1];
760f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->rx_packets;
761f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->rx_bytes;
762f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->
763f844a0eaSJeff Kirsher rx_packets_with_error;
764f844a0eaSJeff Kirsher buf[bi++] = rcb->rxq->
765f844a0eaSJeff Kirsher rxbuf_alloc_failed;
766ba5ca784SIvan Vecera buf[bi++] = rcb->rxq->rxbuf_map_failed;
767f844a0eaSJeff Kirsher buf[bi++] = rcb->producer_index;
768f844a0eaSJeff Kirsher buf[bi++] = rcb->consumer_index;
769f844a0eaSJeff Kirsher }
770f844a0eaSJeff Kirsher }
771f844a0eaSJeff Kirsher }
772f844a0eaSJeff Kirsher
773f844a0eaSJeff Kirsher for (i = 0; i < bnad->num_tx; i++) {
774f844a0eaSJeff Kirsher if (!bnad->tx_info[i].tx)
775f844a0eaSJeff Kirsher continue;
776f844a0eaSJeff Kirsher for (j = 0; j < bnad->num_txq_per_tx; j++)
777f844a0eaSJeff Kirsher if (bnad->tx_info[i].tcb[j] &&
778f844a0eaSJeff Kirsher bnad->tx_info[i].tcb[j]->txq) {
779f844a0eaSJeff Kirsher tcb = bnad->tx_info[i].tcb[j];
780f844a0eaSJeff Kirsher buf[bi++] = tcb->txq->tx_packets;
781f844a0eaSJeff Kirsher buf[bi++] = tcb->txq->tx_bytes;
782f844a0eaSJeff Kirsher buf[bi++] = tcb->producer_index;
783f844a0eaSJeff Kirsher buf[bi++] = tcb->consumer_index;
784f844a0eaSJeff Kirsher buf[bi++] = *(tcb->hw_consumer_index);
785f844a0eaSJeff Kirsher }
786f844a0eaSJeff Kirsher }
787f844a0eaSJeff Kirsher
788f844a0eaSJeff Kirsher return bi;
789f844a0eaSJeff Kirsher }
790f844a0eaSJeff Kirsher
791f844a0eaSJeff Kirsher static void
bnad_get_ethtool_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * buf)792f844a0eaSJeff Kirsher bnad_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats,
793f844a0eaSJeff Kirsher u64 *buf)
794f844a0eaSJeff Kirsher {
795f844a0eaSJeff Kirsher struct bnad *bnad = netdev_priv(netdev);
79637dd3482SIvan Vecera int i, j, bi = 0;
797f844a0eaSJeff Kirsher unsigned long flags;
79837dd3482SIvan Vecera struct rtnl_link_stats64 net_stats64;
799f844a0eaSJeff Kirsher u64 *stats64;
800078086f3SRasesh Mody u32 bmap;
801f844a0eaSJeff Kirsher
802f844a0eaSJeff Kirsher mutex_lock(&bnad->conf_mutex);
803f844a0eaSJeff Kirsher if (bnad_get_stats_count_locked(netdev) != stats->n_stats) {
804f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
805f844a0eaSJeff Kirsher return;
806f844a0eaSJeff Kirsher }
807f844a0eaSJeff Kirsher
808f844a0eaSJeff Kirsher /*
809f844a0eaSJeff Kirsher * Used bna_lock to sync reads from bna_stats, which is written
810f844a0eaSJeff Kirsher * under the same lock
811f844a0eaSJeff Kirsher */
812f844a0eaSJeff Kirsher spin_lock_irqsave(&bnad->bna_lock, flags);
813f844a0eaSJeff Kirsher
81437dd3482SIvan Vecera memset(&net_stats64, 0, sizeof(net_stats64));
81537dd3482SIvan Vecera bnad_netdev_qstats_fill(bnad, &net_stats64);
81637dd3482SIvan Vecera bnad_netdev_hwstats_fill(bnad, &net_stats64);
817f844a0eaSJeff Kirsher
81837dd3482SIvan Vecera buf[bi++] = net_stats64.rx_packets;
81937dd3482SIvan Vecera buf[bi++] = net_stats64.tx_packets;
82037dd3482SIvan Vecera buf[bi++] = net_stats64.rx_bytes;
82137dd3482SIvan Vecera buf[bi++] = net_stats64.tx_bytes;
82237dd3482SIvan Vecera buf[bi++] = net_stats64.rx_errors;
82337dd3482SIvan Vecera buf[bi++] = net_stats64.tx_errors;
82437dd3482SIvan Vecera buf[bi++] = net_stats64.rx_dropped;
82537dd3482SIvan Vecera buf[bi++] = net_stats64.tx_dropped;
82637dd3482SIvan Vecera buf[bi++] = net_stats64.multicast;
82737dd3482SIvan Vecera buf[bi++] = net_stats64.collisions;
82837dd3482SIvan Vecera buf[bi++] = net_stats64.rx_length_errors;
82937dd3482SIvan Vecera buf[bi++] = net_stats64.rx_crc_errors;
83037dd3482SIvan Vecera buf[bi++] = net_stats64.rx_frame_errors;
83137dd3482SIvan Vecera buf[bi++] = net_stats64.tx_fifo_errors;
832f844a0eaSJeff Kirsher
833f844a0eaSJeff Kirsher /* Get netif_queue_stopped from stack */
834f844a0eaSJeff Kirsher bnad->stats.drv_stats.netif_queue_stopped = netif_queue_stopped(netdev);
835f844a0eaSJeff Kirsher
836f844a0eaSJeff Kirsher /* Fill driver stats into ethtool buffers */
837f844a0eaSJeff Kirsher stats64 = (u64 *)&bnad->stats.drv_stats;
838f844a0eaSJeff Kirsher for (i = 0; i < sizeof(struct bnad_drv_stats) / sizeof(u64); i++)
839f844a0eaSJeff Kirsher buf[bi++] = stats64[i];
840f844a0eaSJeff Kirsher
841f844a0eaSJeff Kirsher /* Fill hardware stats excluding the rxf/txf into ethtool bufs */
842078086f3SRasesh Mody stats64 = (u64 *) &bnad->stats.bna_stats->hw_stats;
843f844a0eaSJeff Kirsher for (i = 0;
844078086f3SRasesh Mody i < offsetof(struct bfi_enet_stats, rxf_stats[0]) /
845078086f3SRasesh Mody sizeof(u64);
846f844a0eaSJeff Kirsher i++)
847f844a0eaSJeff Kirsher buf[bi++] = stats64[i];
848f844a0eaSJeff Kirsher
849f844a0eaSJeff Kirsher /* Fill txf stats into ethtool buffers */
850078086f3SRasesh Mody bmap = bna_tx_rid_mask(&bnad->bna);
851078086f3SRasesh Mody for (i = 0; bmap; i++) {
852f844a0eaSJeff Kirsher if (bmap & 1) {
853f844a0eaSJeff Kirsher stats64 = (u64 *)&bnad->stats.bna_stats->
854078086f3SRasesh Mody hw_stats.txf_stats[i];
855078086f3SRasesh Mody for (j = 0; j < sizeof(struct bfi_enet_stats_txf) /
856f844a0eaSJeff Kirsher sizeof(u64); j++)
857f844a0eaSJeff Kirsher buf[bi++] = stats64[j];
858f844a0eaSJeff Kirsher }
859f844a0eaSJeff Kirsher bmap >>= 1;
860f844a0eaSJeff Kirsher }
861f844a0eaSJeff Kirsher
862f844a0eaSJeff Kirsher /* Fill rxf stats into ethtool buffers */
863078086f3SRasesh Mody bmap = bna_rx_rid_mask(&bnad->bna);
864078086f3SRasesh Mody for (i = 0; bmap; i++) {
865f844a0eaSJeff Kirsher if (bmap & 1) {
866f844a0eaSJeff Kirsher stats64 = (u64 *)&bnad->stats.bna_stats->
867078086f3SRasesh Mody hw_stats.rxf_stats[i];
868078086f3SRasesh Mody for (j = 0; j < sizeof(struct bfi_enet_stats_rxf) /
869f844a0eaSJeff Kirsher sizeof(u64); j++)
870f844a0eaSJeff Kirsher buf[bi++] = stats64[j];
871f844a0eaSJeff Kirsher }
872f844a0eaSJeff Kirsher bmap >>= 1;
873f844a0eaSJeff Kirsher }
874f844a0eaSJeff Kirsher
875f844a0eaSJeff Kirsher /* Fill per Q stats into ethtool buffers */
876f844a0eaSJeff Kirsher bi = bnad_per_q_stats_fill(bnad, buf, bi);
877f844a0eaSJeff Kirsher
878f844a0eaSJeff Kirsher spin_unlock_irqrestore(&bnad->bna_lock, flags);
879f844a0eaSJeff Kirsher
880f844a0eaSJeff Kirsher mutex_unlock(&bnad->conf_mutex);
881f844a0eaSJeff Kirsher }
882f844a0eaSJeff Kirsher
883f844a0eaSJeff Kirsher static int
bnad_get_sset_count(struct net_device * netdev,int sset)884f844a0eaSJeff Kirsher bnad_get_sset_count(struct net_device *netdev, int sset)
885f844a0eaSJeff Kirsher {
886f844a0eaSJeff Kirsher switch (sset) {
887f844a0eaSJeff Kirsher case ETH_SS_STATS:
888f844a0eaSJeff Kirsher return bnad_get_stats_count_locked(netdev);
889f844a0eaSJeff Kirsher default:
890f844a0eaSJeff Kirsher return -EOPNOTSUPP;
891f844a0eaSJeff Kirsher }
892f844a0eaSJeff Kirsher }
893f844a0eaSJeff Kirsher
89472a9730bSKrishna Gudipati static u32
bnad_get_flash_partition_by_offset(struct bnad * bnad,u32 offset,u32 * base_offset)89572a9730bSKrishna Gudipati bnad_get_flash_partition_by_offset(struct bnad *bnad, u32 offset,
89672a9730bSKrishna Gudipati u32 *base_offset)
89772a9730bSKrishna Gudipati {
89872a9730bSKrishna Gudipati struct bfa_flash_attr *flash_attr;
89972a9730bSKrishna Gudipati struct bnad_iocmd_comp fcomp;
90072a9730bSKrishna Gudipati u32 i, flash_part = 0, ret;
90172a9730bSKrishna Gudipati unsigned long flags = 0;
90272a9730bSKrishna Gudipati
90372a9730bSKrishna Gudipati flash_attr = kzalloc(sizeof(struct bfa_flash_attr), GFP_KERNEL);
90472a9730bSKrishna Gudipati if (!flash_attr)
905027a3b61SDan Carpenter return 0;
90672a9730bSKrishna Gudipati
90772a9730bSKrishna Gudipati fcomp.bnad = bnad;
90872a9730bSKrishna Gudipati fcomp.comp_status = 0;
90972a9730bSKrishna Gudipati
91072a9730bSKrishna Gudipati init_completion(&fcomp.comp);
91172a9730bSKrishna Gudipati spin_lock_irqsave(&bnad->bna_lock, flags);
91272a9730bSKrishna Gudipati ret = bfa_nw_flash_get_attr(&bnad->bna.flash, flash_attr,
91372a9730bSKrishna Gudipati bnad_cb_completion, &fcomp);
91472a9730bSKrishna Gudipati if (ret != BFA_STATUS_OK) {
91572a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
91672a9730bSKrishna Gudipati kfree(flash_attr);
917027a3b61SDan Carpenter return 0;
91872a9730bSKrishna Gudipati }
91972a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
92072a9730bSKrishna Gudipati wait_for_completion(&fcomp.comp);
92172a9730bSKrishna Gudipati ret = fcomp.comp_status;
92272a9730bSKrishna Gudipati
92372a9730bSKrishna Gudipati /* Check for the flash type & base offset value */
92472a9730bSKrishna Gudipati if (ret == BFA_STATUS_OK) {
92572a9730bSKrishna Gudipati for (i = 0; i < flash_attr->npart; i++) {
92672a9730bSKrishna Gudipati if (offset >= flash_attr->part[i].part_off &&
92772a9730bSKrishna Gudipati offset < (flash_attr->part[i].part_off +
92872a9730bSKrishna Gudipati flash_attr->part[i].part_size)) {
92972a9730bSKrishna Gudipati flash_part = flash_attr->part[i].part_type;
93072a9730bSKrishna Gudipati *base_offset = flash_attr->part[i].part_off;
93172a9730bSKrishna Gudipati break;
93272a9730bSKrishna Gudipati }
93372a9730bSKrishna Gudipati }
93472a9730bSKrishna Gudipati }
93572a9730bSKrishna Gudipati kfree(flash_attr);
93672a9730bSKrishna Gudipati return flash_part;
93772a9730bSKrishna Gudipati }
93872a9730bSKrishna Gudipati
93972a9730bSKrishna Gudipati static int
bnad_get_eeprom_len(struct net_device * netdev)94072a9730bSKrishna Gudipati bnad_get_eeprom_len(struct net_device *netdev)
94172a9730bSKrishna Gudipati {
94272a9730bSKrishna Gudipati return BFA_TOTAL_FLASH_SIZE;
94372a9730bSKrishna Gudipati }
94472a9730bSKrishna Gudipati
94572a9730bSKrishna Gudipati static int
bnad_get_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)94672a9730bSKrishna Gudipati bnad_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
94772a9730bSKrishna Gudipati u8 *bytes)
94872a9730bSKrishna Gudipati {
94972a9730bSKrishna Gudipati struct bnad *bnad = netdev_priv(netdev);
95072a9730bSKrishna Gudipati struct bnad_iocmd_comp fcomp;
95172a9730bSKrishna Gudipati u32 flash_part = 0, base_offset = 0;
95272a9730bSKrishna Gudipati unsigned long flags = 0;
95372a9730bSKrishna Gudipati int ret = 0;
95472a9730bSKrishna Gudipati
955dabf24d1SIvan Vecera /* Fill the magic value */
956dabf24d1SIvan Vecera eeprom->magic = bnad->pcidev->vendor | (bnad->pcidev->device << 16);
95772a9730bSKrishna Gudipati
95872a9730bSKrishna Gudipati /* Query the flash partition based on the offset */
95972a9730bSKrishna Gudipati flash_part = bnad_get_flash_partition_by_offset(bnad,
96072a9730bSKrishna Gudipati eeprom->offset, &base_offset);
961027a3b61SDan Carpenter if (flash_part == 0)
96272a9730bSKrishna Gudipati return -EFAULT;
96372a9730bSKrishna Gudipati
96472a9730bSKrishna Gudipati fcomp.bnad = bnad;
96572a9730bSKrishna Gudipati fcomp.comp_status = 0;
96672a9730bSKrishna Gudipati
96772a9730bSKrishna Gudipati init_completion(&fcomp.comp);
96872a9730bSKrishna Gudipati spin_lock_irqsave(&bnad->bna_lock, flags);
96972a9730bSKrishna Gudipati ret = bfa_nw_flash_read_part(&bnad->bna.flash, flash_part,
97072a9730bSKrishna Gudipati bnad->id, bytes, eeprom->len,
97172a9730bSKrishna Gudipati eeprom->offset - base_offset,
97272a9730bSKrishna Gudipati bnad_cb_completion, &fcomp);
97372a9730bSKrishna Gudipati if (ret != BFA_STATUS_OK) {
97472a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
97572a9730bSKrishna Gudipati goto done;
97672a9730bSKrishna Gudipati }
97772a9730bSKrishna Gudipati
97872a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
97972a9730bSKrishna Gudipati wait_for_completion(&fcomp.comp);
98072a9730bSKrishna Gudipati ret = fcomp.comp_status;
98172a9730bSKrishna Gudipati done:
98272a9730bSKrishna Gudipati return ret;
98372a9730bSKrishna Gudipati }
98472a9730bSKrishna Gudipati
98572a9730bSKrishna Gudipati static int
bnad_set_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)98672a9730bSKrishna Gudipati bnad_set_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
98772a9730bSKrishna Gudipati u8 *bytes)
98872a9730bSKrishna Gudipati {
98972a9730bSKrishna Gudipati struct bnad *bnad = netdev_priv(netdev);
99072a9730bSKrishna Gudipati struct bnad_iocmd_comp fcomp;
99172a9730bSKrishna Gudipati u32 flash_part = 0, base_offset = 0;
99272a9730bSKrishna Gudipati unsigned long flags = 0;
99372a9730bSKrishna Gudipati int ret = 0;
99472a9730bSKrishna Gudipati
99572a9730bSKrishna Gudipati /* Check if the flash update request is valid */
99672a9730bSKrishna Gudipati if (eeprom->magic != (bnad->pcidev->vendor |
99772a9730bSKrishna Gudipati (bnad->pcidev->device << 16)))
99872a9730bSKrishna Gudipati return -EINVAL;
99972a9730bSKrishna Gudipati
100072a9730bSKrishna Gudipati /* Query the flash partition based on the offset */
100172a9730bSKrishna Gudipati flash_part = bnad_get_flash_partition_by_offset(bnad,
100272a9730bSKrishna Gudipati eeprom->offset, &base_offset);
1003027a3b61SDan Carpenter if (flash_part == 0)
100472a9730bSKrishna Gudipati return -EFAULT;
100572a9730bSKrishna Gudipati
100672a9730bSKrishna Gudipati fcomp.bnad = bnad;
100772a9730bSKrishna Gudipati fcomp.comp_status = 0;
100872a9730bSKrishna Gudipati
100972a9730bSKrishna Gudipati init_completion(&fcomp.comp);
101072a9730bSKrishna Gudipati spin_lock_irqsave(&bnad->bna_lock, flags);
101172a9730bSKrishna Gudipati ret = bfa_nw_flash_update_part(&bnad->bna.flash, flash_part,
101272a9730bSKrishna Gudipati bnad->id, bytes, eeprom->len,
101372a9730bSKrishna Gudipati eeprom->offset - base_offset,
101472a9730bSKrishna Gudipati bnad_cb_completion, &fcomp);
101572a9730bSKrishna Gudipati if (ret != BFA_STATUS_OK) {
101672a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
101772a9730bSKrishna Gudipati goto done;
101872a9730bSKrishna Gudipati }
101972a9730bSKrishna Gudipati
102072a9730bSKrishna Gudipati spin_unlock_irqrestore(&bnad->bna_lock, flags);
102172a9730bSKrishna Gudipati wait_for_completion(&fcomp.comp);
102272a9730bSKrishna Gudipati ret = fcomp.comp_status;
102372a9730bSKrishna Gudipati done:
102472a9730bSKrishna Gudipati return ret;
102572a9730bSKrishna Gudipati }
102672a9730bSKrishna Gudipati
102757b9bef0SKrishna Gudipati static int
bnad_flash_device(struct net_device * netdev,struct ethtool_flash * eflash)102857b9bef0SKrishna Gudipati bnad_flash_device(struct net_device *netdev, struct ethtool_flash *eflash)
102957b9bef0SKrishna Gudipati {
103057b9bef0SKrishna Gudipati struct bnad *bnad = netdev_priv(netdev);
103157b9bef0SKrishna Gudipati struct bnad_iocmd_comp fcomp;
103257b9bef0SKrishna Gudipati const struct firmware *fw;
103357b9bef0SKrishna Gudipati int ret = 0;
103457b9bef0SKrishna Gudipati
103557b9bef0SKrishna Gudipati ret = request_firmware(&fw, eflash->data, &bnad->pcidev->dev);
103657b9bef0SKrishna Gudipati if (ret) {
1037ecc46789SIvan Vecera netdev_err(netdev, "can't load firmware %s\n", eflash->data);
103857b9bef0SKrishna Gudipati goto out;
103957b9bef0SKrishna Gudipati }
104057b9bef0SKrishna Gudipati
104157b9bef0SKrishna Gudipati fcomp.bnad = bnad;
104257b9bef0SKrishna Gudipati fcomp.comp_status = 0;
104357b9bef0SKrishna Gudipati
104457b9bef0SKrishna Gudipati init_completion(&fcomp.comp);
104557b9bef0SKrishna Gudipati spin_lock_irq(&bnad->bna_lock);
104657b9bef0SKrishna Gudipati ret = bfa_nw_flash_update_part(&bnad->bna.flash, BFA_FLASH_PART_FWIMG,
104757b9bef0SKrishna Gudipati bnad->id, (u8 *)fw->data, fw->size, 0,
104857b9bef0SKrishna Gudipati bnad_cb_completion, &fcomp);
104957b9bef0SKrishna Gudipati if (ret != BFA_STATUS_OK) {
1050ecc46789SIvan Vecera netdev_warn(netdev, "flash update failed with err=%d\n", ret);
105157b9bef0SKrishna Gudipati ret = -EIO;
105257b9bef0SKrishna Gudipati spin_unlock_irq(&bnad->bna_lock);
105357b9bef0SKrishna Gudipati goto out;
105457b9bef0SKrishna Gudipati }
105557b9bef0SKrishna Gudipati
105657b9bef0SKrishna Gudipati spin_unlock_irq(&bnad->bna_lock);
105757b9bef0SKrishna Gudipati wait_for_completion(&fcomp.comp);
105857b9bef0SKrishna Gudipati if (fcomp.comp_status != BFA_STATUS_OK) {
105957b9bef0SKrishna Gudipati ret = -EIO;
1060ecc46789SIvan Vecera netdev_warn(netdev,
1061ecc46789SIvan Vecera "firmware image update failed with err=%d\n",
106257b9bef0SKrishna Gudipati fcomp.comp_status);
106357b9bef0SKrishna Gudipati }
106457b9bef0SKrishna Gudipati out:
106557b9bef0SKrishna Gudipati release_firmware(fw);
106657b9bef0SKrishna Gudipati return ret;
106757b9bef0SKrishna Gudipati }
106857b9bef0SKrishna Gudipati
1069975419cfSstephen hemminger static const struct ethtool_ops bnad_ethtool_ops = {
1070659d0760SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1071659d0760SJakub Kicinski ETHTOOL_COALESCE_TX_MAX_FRAMES |
1072659d0760SJakub Kicinski ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1073f844a0eaSJeff Kirsher .get_drvinfo = bnad_get_drvinfo,
1074f844a0eaSJeff Kirsher .get_wol = bnad_get_wol,
1075f844a0eaSJeff Kirsher .get_link = ethtool_op_get_link,
1076f844a0eaSJeff Kirsher .get_coalesce = bnad_get_coalesce,
1077f844a0eaSJeff Kirsher .set_coalesce = bnad_set_coalesce,
1078f844a0eaSJeff Kirsher .get_ringparam = bnad_get_ringparam,
1079f844a0eaSJeff Kirsher .set_ringparam = bnad_set_ringparam,
1080f844a0eaSJeff Kirsher .get_pauseparam = bnad_get_pauseparam,
1081f844a0eaSJeff Kirsher .set_pauseparam = bnad_set_pauseparam,
1082f844a0eaSJeff Kirsher .get_strings = bnad_get_strings,
1083f844a0eaSJeff Kirsher .get_ethtool_stats = bnad_get_ethtool_stats,
108472a9730bSKrishna Gudipati .get_sset_count = bnad_get_sset_count,
108572a9730bSKrishna Gudipati .get_eeprom_len = bnad_get_eeprom_len,
108672a9730bSKrishna Gudipati .get_eeprom = bnad_get_eeprom,
108772a9730bSKrishna Gudipati .set_eeprom = bnad_set_eeprom,
108857b9bef0SKrishna Gudipati .flash_device = bnad_flash_device,
1089fee1253eSRasesh Mody .get_ts_info = ethtool_op_get_ts_info,
1090377fa64fSPhilippe Reynes .get_link_ksettings = bnad_get_link_ksettings,
1091377fa64fSPhilippe Reynes .set_link_ksettings = bnad_set_link_ksettings,
1092f844a0eaSJeff Kirsher };
1093f844a0eaSJeff Kirsher
1094f844a0eaSJeff Kirsher void
bnad_set_ethtool_ops(struct net_device * netdev)1095f844a0eaSJeff Kirsher bnad_set_ethtool_ops(struct net_device *netdev)
1096f844a0eaSJeff Kirsher {
10977ad24ea4SWilfried Klaebe netdev->ethtool_ops = &bnad_ethtool_ops;
1098f844a0eaSJeff Kirsher }
1099