1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2017 Broadcom Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
11 #include <linux/ctype.h>
12 #include <linux/stringify.h>
13 #include <linux/ethtool.h>
14 #include <linux/interrupt.h>
15 #include <linux/pci.h>
16 #include <linux/etherdevice.h>
17 #include <linux/crc32.h>
18 #include <linux/firmware.h>
22 #include "bnxt_ethtool.h"
23 #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
24 #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
25 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
26 #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
27 #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
29 static u32 bnxt_get_msglevel(struct net_device *dev)
31 struct bnxt *bp = netdev_priv(dev);
33 return bp->msg_enable;
36 static void bnxt_set_msglevel(struct net_device *dev, u32 value)
38 struct bnxt *bp = netdev_priv(dev);
40 bp->msg_enable = value;
43 static int bnxt_get_coalesce(struct net_device *dev,
44 struct ethtool_coalesce *coal)
46 struct bnxt *bp = netdev_priv(dev);
47 struct bnxt_coal *hw_coal;
50 memset(coal, 0, sizeof(*coal));
52 coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM;
54 hw_coal = &bp->rx_coal;
55 mult = hw_coal->bufs_per_record;
56 coal->rx_coalesce_usecs = hw_coal->coal_ticks;
57 coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult;
58 coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
59 coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
61 hw_coal = &bp->tx_coal;
62 mult = hw_coal->bufs_per_record;
63 coal->tx_coalesce_usecs = hw_coal->coal_ticks;
64 coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult;
65 coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
66 coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
68 coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
73 static int bnxt_set_coalesce(struct net_device *dev,
74 struct ethtool_coalesce *coal)
76 struct bnxt *bp = netdev_priv(dev);
77 bool update_stats = false;
78 struct bnxt_coal *hw_coal;
82 if (coal->use_adaptive_rx_coalesce) {
83 bp->flags |= BNXT_FLAG_DIM;
85 if (bp->flags & BNXT_FLAG_DIM) {
86 bp->flags &= ~(BNXT_FLAG_DIM);
91 hw_coal = &bp->rx_coal;
92 mult = hw_coal->bufs_per_record;
93 hw_coal->coal_ticks = coal->rx_coalesce_usecs;
94 hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult;
95 hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq;
96 hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult;
98 hw_coal = &bp->tx_coal;
99 mult = hw_coal->bufs_per_record;
100 hw_coal->coal_ticks = coal->tx_coalesce_usecs;
101 hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult;
102 hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq;
103 hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult;
105 if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
106 u32 stats_ticks = coal->stats_block_coalesce_usecs;
108 /* Allow 0, which means disable. */
110 stats_ticks = clamp_t(u32, stats_ticks,
111 BNXT_MIN_STATS_COAL_TICKS,
112 BNXT_MAX_STATS_COAL_TICKS);
113 stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
114 bp->stats_coal_ticks = stats_ticks;
119 if (netif_running(dev)) {
121 rc = bnxt_close_nic(bp, true, false);
123 rc = bnxt_open_nic(bp, true, false);
125 rc = bnxt_hwrm_set_coal(bp);
132 #define BNXT_NUM_STATS 21
134 #define BNXT_RX_STATS_ENTRY(counter) \
135 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
137 #define BNXT_TX_STATS_ENTRY(counter) \
138 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
140 #define BNXT_RX_STATS_EXT_ENTRY(counter) \
141 { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) }
143 static const struct {
145 char string[ETH_GSTRING_LEN];
146 } bnxt_port_stats_arr[] = {
147 BNXT_RX_STATS_ENTRY(rx_64b_frames),
148 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
149 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
150 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
151 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
152 BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames),
153 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
154 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
155 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
156 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
157 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
158 BNXT_RX_STATS_ENTRY(rx_total_frames),
159 BNXT_RX_STATS_ENTRY(rx_ucast_frames),
160 BNXT_RX_STATS_ENTRY(rx_mcast_frames),
161 BNXT_RX_STATS_ENTRY(rx_bcast_frames),
162 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
163 BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
164 BNXT_RX_STATS_ENTRY(rx_pause_frames),
165 BNXT_RX_STATS_ENTRY(rx_pfc_frames),
166 BNXT_RX_STATS_ENTRY(rx_align_err_frames),
167 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
168 BNXT_RX_STATS_ENTRY(rx_jbr_frames),
169 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
170 BNXT_RX_STATS_ENTRY(rx_tagged_frames),
171 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
172 BNXT_RX_STATS_ENTRY(rx_good_frames),
173 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0),
174 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1),
175 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2),
176 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3),
177 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4),
178 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5),
179 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6),
180 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7),
181 BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
182 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
183 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
184 BNXT_RX_STATS_ENTRY(rx_bytes),
185 BNXT_RX_STATS_ENTRY(rx_runt_bytes),
186 BNXT_RX_STATS_ENTRY(rx_runt_frames),
187 BNXT_RX_STATS_ENTRY(rx_stat_discard),
188 BNXT_RX_STATS_ENTRY(rx_stat_err),
190 BNXT_TX_STATS_ENTRY(tx_64b_frames),
191 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
192 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
193 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
194 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
195 BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames),
196 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
197 BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames),
198 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
199 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
200 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
201 BNXT_TX_STATS_ENTRY(tx_good_frames),
202 BNXT_TX_STATS_ENTRY(tx_total_frames),
203 BNXT_TX_STATS_ENTRY(tx_ucast_frames),
204 BNXT_TX_STATS_ENTRY(tx_mcast_frames),
205 BNXT_TX_STATS_ENTRY(tx_bcast_frames),
206 BNXT_TX_STATS_ENTRY(tx_pause_frames),
207 BNXT_TX_STATS_ENTRY(tx_pfc_frames),
208 BNXT_TX_STATS_ENTRY(tx_jabber_frames),
209 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
210 BNXT_TX_STATS_ENTRY(tx_err),
211 BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
212 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0),
213 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1),
214 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2),
215 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3),
216 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4),
217 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5),
218 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6),
219 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7),
220 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
221 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
222 BNXT_TX_STATS_ENTRY(tx_total_collisions),
223 BNXT_TX_STATS_ENTRY(tx_bytes),
224 BNXT_TX_STATS_ENTRY(tx_xthol_frames),
225 BNXT_TX_STATS_ENTRY(tx_stat_discard),
226 BNXT_TX_STATS_ENTRY(tx_stat_error),
229 static const struct {
231 char string[ETH_GSTRING_LEN];
232 } bnxt_port_stats_ext_arr[] = {
233 BNXT_RX_STATS_EXT_ENTRY(link_down_events),
234 BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events),
235 BNXT_RX_STATS_EXT_ENTRY(resume_pause_events),
236 BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events),
237 BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events),
240 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
241 #define BNXT_NUM_PORT_STATS_EXT ARRAY_SIZE(bnxt_port_stats_ext_arr)
243 static int bnxt_get_num_stats(struct bnxt *bp)
245 int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
247 if (bp->flags & BNXT_FLAG_PORT_STATS)
248 num_stats += BNXT_NUM_PORT_STATS;
250 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT)
251 num_stats += BNXT_NUM_PORT_STATS_EXT;
256 static int bnxt_get_sset_count(struct net_device *dev, int sset)
258 struct bnxt *bp = netdev_priv(dev);
262 return bnxt_get_num_stats(bp);
266 return bp->num_tests;
272 static void bnxt_get_ethtool_stats(struct net_device *dev,
273 struct ethtool_stats *stats, u64 *buf)
276 struct bnxt *bp = netdev_priv(dev);
277 u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
282 for (i = 0; i < bp->cp_nr_rings; i++) {
283 struct bnxt_napi *bnapi = bp->bnapi[i];
284 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
285 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
288 for (k = 0; k < stat_fields; j++, k++)
289 buf[j] = le64_to_cpu(hw_stats[k]);
290 buf[j++] = cpr->rx_l4_csum_errors;
292 if (bp->flags & BNXT_FLAG_PORT_STATS) {
293 __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
295 for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
296 buf[j] = le64_to_cpu(*(port_stats +
297 bnxt_port_stats_arr[i].offset));
300 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
301 __le64 *port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext;
303 for (i = 0; i < BNXT_NUM_PORT_STATS_EXT; i++, j++) {
304 buf[j] = le64_to_cpu(*(port_stats_ext +
305 bnxt_port_stats_ext_arr[i].offset));
310 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
312 struct bnxt *bp = netdev_priv(dev);
316 /* The number of strings must match BNXT_NUM_STATS defined above. */
318 for (i = 0; i < bp->cp_nr_rings; i++) {
319 sprintf(buf, "[%d]: rx_ucast_packets", i);
320 buf += ETH_GSTRING_LEN;
321 sprintf(buf, "[%d]: rx_mcast_packets", i);
322 buf += ETH_GSTRING_LEN;
323 sprintf(buf, "[%d]: rx_bcast_packets", i);
324 buf += ETH_GSTRING_LEN;
325 sprintf(buf, "[%d]: rx_discards", i);
326 buf += ETH_GSTRING_LEN;
327 sprintf(buf, "[%d]: rx_drops", i);
328 buf += ETH_GSTRING_LEN;
329 sprintf(buf, "[%d]: rx_ucast_bytes", i);
330 buf += ETH_GSTRING_LEN;
331 sprintf(buf, "[%d]: rx_mcast_bytes", i);
332 buf += ETH_GSTRING_LEN;
333 sprintf(buf, "[%d]: rx_bcast_bytes", i);
334 buf += ETH_GSTRING_LEN;
335 sprintf(buf, "[%d]: tx_ucast_packets", i);
336 buf += ETH_GSTRING_LEN;
337 sprintf(buf, "[%d]: tx_mcast_packets", i);
338 buf += ETH_GSTRING_LEN;
339 sprintf(buf, "[%d]: tx_bcast_packets", i);
340 buf += ETH_GSTRING_LEN;
341 sprintf(buf, "[%d]: tx_discards", i);
342 buf += ETH_GSTRING_LEN;
343 sprintf(buf, "[%d]: tx_drops", i);
344 buf += ETH_GSTRING_LEN;
345 sprintf(buf, "[%d]: tx_ucast_bytes", i);
346 buf += ETH_GSTRING_LEN;
347 sprintf(buf, "[%d]: tx_mcast_bytes", i);
348 buf += ETH_GSTRING_LEN;
349 sprintf(buf, "[%d]: tx_bcast_bytes", i);
350 buf += ETH_GSTRING_LEN;
351 sprintf(buf, "[%d]: tpa_packets", i);
352 buf += ETH_GSTRING_LEN;
353 sprintf(buf, "[%d]: tpa_bytes", i);
354 buf += ETH_GSTRING_LEN;
355 sprintf(buf, "[%d]: tpa_events", i);
356 buf += ETH_GSTRING_LEN;
357 sprintf(buf, "[%d]: tpa_aborts", i);
358 buf += ETH_GSTRING_LEN;
359 sprintf(buf, "[%d]: rx_l4_csum_errors", i);
360 buf += ETH_GSTRING_LEN;
362 if (bp->flags & BNXT_FLAG_PORT_STATS) {
363 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
364 strcpy(buf, bnxt_port_stats_arr[i].string);
365 buf += ETH_GSTRING_LEN;
368 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
369 for (i = 0; i < BNXT_NUM_PORT_STATS_EXT; i++) {
370 strcpy(buf, bnxt_port_stats_ext_arr[i].string);
371 buf += ETH_GSTRING_LEN;
377 memcpy(buf, bp->test_info->string,
378 bp->num_tests * ETH_GSTRING_LEN);
381 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
387 static void bnxt_get_ringparam(struct net_device *dev,
388 struct ethtool_ringparam *ering)
390 struct bnxt *bp = netdev_priv(dev);
392 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
393 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
394 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
396 ering->rx_pending = bp->rx_ring_size;
397 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
398 ering->tx_pending = bp->tx_ring_size;
401 static int bnxt_set_ringparam(struct net_device *dev,
402 struct ethtool_ringparam *ering)
404 struct bnxt *bp = netdev_priv(dev);
406 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
407 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
408 (ering->tx_pending <= MAX_SKB_FRAGS))
411 if (netif_running(dev))
412 bnxt_close_nic(bp, false, false);
414 bp->rx_ring_size = ering->rx_pending;
415 bp->tx_ring_size = ering->tx_pending;
416 bnxt_set_ring_params(bp);
418 if (netif_running(dev))
419 return bnxt_open_nic(bp, false, false);
424 static void bnxt_get_channels(struct net_device *dev,
425 struct ethtool_channels *channel)
427 struct bnxt *bp = netdev_priv(dev);
428 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
429 int max_rx_rings, max_tx_rings, tcs;
430 int max_tx_sch_inputs;
432 /* Get the most up-to-date max_tx_sch_inputs. */
433 if (bp->flags & BNXT_FLAG_NEW_RM)
434 bnxt_hwrm_func_resc_qcaps(bp, false);
435 max_tx_sch_inputs = hw_resc->max_tx_sch_inputs;
437 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
438 if (max_tx_sch_inputs)
439 max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
440 channel->max_combined = min_t(int, max_rx_rings, max_tx_rings);
442 if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
446 if (max_tx_sch_inputs)
447 max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
449 tcs = netdev_get_num_tc(dev);
453 channel->max_rx = max_rx_rings;
454 channel->max_tx = max_tx_rings;
455 channel->max_other = 0;
456 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
457 channel->combined_count = bp->rx_nr_rings;
458 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
459 channel->combined_count--;
461 if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
462 channel->rx_count = bp->rx_nr_rings;
463 channel->tx_count = bp->tx_nr_rings_per_tc;
468 static int bnxt_set_channels(struct net_device *dev,
469 struct ethtool_channels *channel)
471 struct bnxt *bp = netdev_priv(dev);
472 int req_tx_rings, req_rx_rings, tcs;
477 if (channel->other_count)
480 if (!channel->combined_count &&
481 (!channel->rx_count || !channel->tx_count))
484 if (channel->combined_count &&
485 (channel->rx_count || channel->tx_count))
488 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
492 if (channel->combined_count)
495 tcs = netdev_get_num_tc(dev);
497 req_tx_rings = sh ? channel->combined_count : channel->tx_count;
498 req_rx_rings = sh ? channel->combined_count : channel->rx_count;
499 if (bp->tx_nr_rings_xdp) {
501 netdev_err(dev, "Only combined mode supported when XDP is enabled.\n");
504 tx_xdp = req_rx_rings;
506 rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp);
508 netdev_warn(dev, "Unable to allocate the requested rings\n");
512 if (netif_running(dev)) {
514 /* TODO CHIMP_FW: Send message to all VF's
518 rc = bnxt_close_nic(bp, true, false);
520 netdev_err(bp->dev, "Set channel failure rc :%x\n",
527 bp->flags |= BNXT_FLAG_SHARED_RINGS;
528 bp->rx_nr_rings = channel->combined_count;
529 bp->tx_nr_rings_per_tc = channel->combined_count;
531 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
532 bp->rx_nr_rings = channel->rx_count;
533 bp->tx_nr_rings_per_tc = channel->tx_count;
535 bp->tx_nr_rings_xdp = tx_xdp;
536 bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp;
538 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
540 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
541 bp->tx_nr_rings + bp->rx_nr_rings;
543 bp->num_stat_ctxs = bp->cp_nr_rings;
545 /* After changing number of rx channels, update NTUPLE feature. */
546 netdev_update_features(dev);
547 if (netif_running(dev)) {
548 rc = bnxt_open_nic(bp, true, false);
549 if ((!rc) && BNXT_PF(bp)) {
550 /* TODO CHIMP_FW: Send message to all VF's
559 #ifdef CONFIG_RFS_ACCEL
560 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
565 cmd->data = bp->ntp_fltr_count;
566 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
567 struct hlist_head *head;
568 struct bnxt_ntuple_filter *fltr;
570 head = &bp->ntp_fltr_hash_tbl[i];
572 hlist_for_each_entry_rcu(fltr, head, hash) {
573 if (j == cmd->rule_cnt)
575 rule_locs[j++] = fltr->sw_id;
578 if (j == cmd->rule_cnt)
585 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
587 struct ethtool_rx_flow_spec *fs =
588 (struct ethtool_rx_flow_spec *)&cmd->fs;
589 struct bnxt_ntuple_filter *fltr;
590 struct flow_keys *fkeys;
593 if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
596 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
597 struct hlist_head *head;
599 head = &bp->ntp_fltr_hash_tbl[i];
601 hlist_for_each_entry_rcu(fltr, head, hash) {
602 if (fltr->sw_id == fs->location)
610 fkeys = &fltr->fkeys;
611 if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
612 if (fkeys->basic.ip_proto == IPPROTO_TCP)
613 fs->flow_type = TCP_V4_FLOW;
614 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
615 fs->flow_type = UDP_V4_FLOW;
619 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
620 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
622 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
623 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
625 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
626 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
628 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
629 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
633 if (fkeys->basic.ip_proto == IPPROTO_TCP)
634 fs->flow_type = TCP_V6_FLOW;
635 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
636 fs->flow_type = UDP_V6_FLOW;
640 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] =
641 fkeys->addrs.v6addrs.src;
642 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] =
643 fkeys->addrs.v6addrs.dst;
644 for (i = 0; i < 4; i++) {
645 fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0);
646 fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0);
648 fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src;
649 fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0);
651 fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst;
652 fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0);
655 fs->ring_cookie = fltr->rxq;
665 static u64 get_ethtool_ipv4_rss(struct bnxt *bp)
667 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4)
668 return RXH_IP_SRC | RXH_IP_DST;
672 static u64 get_ethtool_ipv6_rss(struct bnxt *bp)
674 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6)
675 return RXH_IP_SRC | RXH_IP_DST;
679 static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
682 switch (cmd->flow_type) {
684 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4)
685 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
686 RXH_L4_B_0_1 | RXH_L4_B_2_3;
687 cmd->data |= get_ethtool_ipv4_rss(bp);
690 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)
691 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
692 RXH_L4_B_0_1 | RXH_L4_B_2_3;
699 cmd->data |= get_ethtool_ipv4_rss(bp);
703 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6)
704 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
705 RXH_L4_B_0_1 | RXH_L4_B_2_3;
706 cmd->data |= get_ethtool_ipv6_rss(bp);
709 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)
710 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
711 RXH_L4_B_0_1 | RXH_L4_B_2_3;
718 cmd->data |= get_ethtool_ipv6_rss(bp);
724 #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
725 #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
727 static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
729 u32 rss_hash_cfg = bp->rss_hash_cfg;
732 if (cmd->data == RXH_4TUPLE)
734 else if (cmd->data == RXH_2TUPLE)
741 if (cmd->flow_type == TCP_V4_FLOW) {
742 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
744 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
745 } else if (cmd->flow_type == UDP_V4_FLOW) {
746 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
748 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
750 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
751 } else if (cmd->flow_type == TCP_V6_FLOW) {
752 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
754 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
755 } else if (cmd->flow_type == UDP_V6_FLOW) {
756 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
758 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
760 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
761 } else if (tuple == 4) {
765 switch (cmd->flow_type) {
774 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
776 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
787 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
789 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
793 if (bp->rss_hash_cfg == rss_hash_cfg)
796 bp->rss_hash_cfg = rss_hash_cfg;
797 if (netif_running(bp->dev)) {
798 bnxt_close_nic(bp, false, false);
799 rc = bnxt_open_nic(bp, false, false);
804 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
807 struct bnxt *bp = netdev_priv(dev);
811 #ifdef CONFIG_RFS_ACCEL
812 case ETHTOOL_GRXRINGS:
813 cmd->data = bp->rx_nr_rings;
816 case ETHTOOL_GRXCLSRLCNT:
817 cmd->rule_cnt = bp->ntp_fltr_count;
818 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
821 case ETHTOOL_GRXCLSRLALL:
822 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
825 case ETHTOOL_GRXCLSRULE:
826 rc = bnxt_grxclsrule(bp, cmd);
831 rc = bnxt_grxfh(bp, cmd);
842 static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
844 struct bnxt *bp = netdev_priv(dev);
849 rc = bnxt_srxfh(bp, cmd);
859 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
861 return HW_HASH_INDEX_SIZE;
864 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
866 return HW_HASH_KEY_SIZE;
869 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
872 struct bnxt *bp = netdev_priv(dev);
873 struct bnxt_vnic_info *vnic;
877 *hfunc = ETH_RSS_HASH_TOP;
882 vnic = &bp->vnic_info[0];
883 if (indir && vnic->rss_table) {
884 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
885 indir[i] = le16_to_cpu(vnic->rss_table[i]);
888 if (key && vnic->rss_hash_key)
889 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
894 static void bnxt_get_drvinfo(struct net_device *dev,
895 struct ethtool_drvinfo *info)
897 struct bnxt *bp = netdev_priv(dev);
899 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
900 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
901 strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version));
902 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
903 info->n_stats = bnxt_get_num_stats(bp);
904 info->testinfo_len = bp->num_tests;
905 /* TODO CHIMP_FW: eeprom dump details */
906 info->eedump_len = 0;
907 /* TODO CHIMP FW: reg dump details */
908 info->regdump_len = 0;
911 static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
913 struct bnxt *bp = netdev_priv(dev);
917 memset(&wol->sopass, 0, sizeof(wol->sopass));
918 if (bp->flags & BNXT_FLAG_WOL_CAP) {
919 wol->supported = WAKE_MAGIC;
921 wol->wolopts = WAKE_MAGIC;
925 static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
927 struct bnxt *bp = netdev_priv(dev);
929 if (wol->wolopts & ~WAKE_MAGIC)
932 if (wol->wolopts & WAKE_MAGIC) {
933 if (!(bp->flags & BNXT_FLAG_WOL_CAP))
936 if (bnxt_hwrm_alloc_wol_fltr(bp))
942 if (bnxt_hwrm_free_wol_fltr(bp))
950 u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
954 /* TODO: support 25GB, 40GB, 50GB with different cable type */
955 /* set the advertised speeds */
956 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
957 speed_mask |= ADVERTISED_100baseT_Full;
958 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
959 speed_mask |= ADVERTISED_1000baseT_Full;
960 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
961 speed_mask |= ADVERTISED_2500baseX_Full;
962 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
963 speed_mask |= ADVERTISED_10000baseT_Full;
964 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
965 speed_mask |= ADVERTISED_40000baseCR4_Full;
967 if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
968 speed_mask |= ADVERTISED_Pause;
969 else if (fw_pause & BNXT_LINK_PAUSE_TX)
970 speed_mask |= ADVERTISED_Asym_Pause;
971 else if (fw_pause & BNXT_LINK_PAUSE_RX)
972 speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
977 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
979 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
980 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
982 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
983 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
985 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
986 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
988 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
989 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
991 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
992 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
994 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
995 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
997 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \
998 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
999 100000baseCR4_Full);\
1000 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
1001 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1003 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
1004 ethtool_link_ksettings_add_link_mode( \
1005 lk_ksettings, name, Asym_Pause);\
1006 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
1007 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1012 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
1014 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1016 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1018 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
1019 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1020 1000baseT_Full) || \
1021 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1023 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
1024 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1026 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
1027 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1028 25000baseCR_Full)) \
1029 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
1030 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1031 40000baseCR4_Full)) \
1032 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
1033 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1034 50000baseCR2_Full)) \
1035 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
1036 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1037 100000baseCR4_Full)) \
1038 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \
1041 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
1042 struct ethtool_link_ksettings *lk_ksettings)
1044 u16 fw_speeds = link_info->advertising;
1047 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1048 fw_pause = link_info->auto_pause_setting;
1050 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
1053 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
1054 struct ethtool_link_ksettings *lk_ksettings)
1056 u16 fw_speeds = link_info->lp_auto_link_speeds;
1059 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1060 fw_pause = link_info->lp_pause;
1062 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
1066 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
1067 struct ethtool_link_ksettings *lk_ksettings)
1069 u16 fw_speeds = link_info->support_speeds;
1071 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
1073 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
1074 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1077 if (link_info->support_auto_speeds)
1078 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1082 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
1084 switch (fw_link_speed) {
1085 case BNXT_LINK_SPEED_100MB:
1087 case BNXT_LINK_SPEED_1GB:
1089 case BNXT_LINK_SPEED_2_5GB:
1091 case BNXT_LINK_SPEED_10GB:
1093 case BNXT_LINK_SPEED_20GB:
1095 case BNXT_LINK_SPEED_25GB:
1097 case BNXT_LINK_SPEED_40GB:
1099 case BNXT_LINK_SPEED_50GB:
1101 case BNXT_LINK_SPEED_100GB:
1102 return SPEED_100000;
1104 return SPEED_UNKNOWN;
1108 static int bnxt_get_link_ksettings(struct net_device *dev,
1109 struct ethtool_link_ksettings *lk_ksettings)
1111 struct bnxt *bp = netdev_priv(dev);
1112 struct bnxt_link_info *link_info = &bp->link_info;
1113 struct ethtool_link_settings *base = &lk_ksettings->base;
1116 ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
1117 mutex_lock(&bp->link_lock);
1118 bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
1120 ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
1121 if (link_info->autoneg) {
1122 bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
1123 ethtool_link_ksettings_add_link_mode(lk_ksettings,
1124 advertising, Autoneg);
1125 base->autoneg = AUTONEG_ENABLE;
1126 if (link_info->phy_link_status == BNXT_LINK_LINK)
1127 bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
1128 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
1129 if (!netif_carrier_ok(dev))
1130 base->duplex = DUPLEX_UNKNOWN;
1131 else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
1132 base->duplex = DUPLEX_FULL;
1134 base->duplex = DUPLEX_HALF;
1136 base->autoneg = AUTONEG_DISABLE;
1138 bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
1139 base->duplex = DUPLEX_HALF;
1140 if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
1141 base->duplex = DUPLEX_FULL;
1143 base->speed = ethtool_speed;
1145 base->port = PORT_NONE;
1146 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1147 base->port = PORT_TP;
1148 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1150 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1153 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1155 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1158 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
1159 base->port = PORT_DA;
1160 else if (link_info->media_type ==
1161 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
1162 base->port = PORT_FIBRE;
1164 base->phy_address = link_info->phy_addr;
1165 mutex_unlock(&bp->link_lock);
1170 static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed)
1172 struct bnxt *bp = netdev_priv(dev);
1173 struct bnxt_link_info *link_info = &bp->link_info;
1174 u16 support_spds = link_info->support_speeds;
1177 switch (ethtool_speed) {
1179 if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
1180 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
1183 if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
1184 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
1187 if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
1188 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
1191 if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
1192 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
1195 if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
1196 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
1199 if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
1200 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
1203 if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
1204 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
1207 if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
1208 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
1211 if (support_spds & BNXT_LINK_SPEED_MSK_100GB)
1212 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB;
1215 netdev_err(dev, "unsupported speed!\n");
1221 u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
1223 u16 fw_speed_mask = 0;
1225 /* only support autoneg at speed 100, 1000, and 10000 */
1226 if (advertising & (ADVERTISED_100baseT_Full |
1227 ADVERTISED_100baseT_Half)) {
1228 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
1230 if (advertising & (ADVERTISED_1000baseT_Full |
1231 ADVERTISED_1000baseT_Half)) {
1232 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
1234 if (advertising & ADVERTISED_10000baseT_Full)
1235 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
1237 if (advertising & ADVERTISED_40000baseCR4_Full)
1238 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
1240 return fw_speed_mask;
1243 static int bnxt_set_link_ksettings(struct net_device *dev,
1244 const struct ethtool_link_ksettings *lk_ksettings)
1246 struct bnxt *bp = netdev_priv(dev);
1247 struct bnxt_link_info *link_info = &bp->link_info;
1248 const struct ethtool_link_settings *base = &lk_ksettings->base;
1249 bool set_pause = false;
1250 u16 fw_advertising = 0;
1254 if (!BNXT_SINGLE_PF(bp))
1257 mutex_lock(&bp->link_lock);
1258 if (base->autoneg == AUTONEG_ENABLE) {
1259 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
1261 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1262 if (!fw_advertising)
1263 link_info->advertising = link_info->support_auto_speeds;
1265 link_info->advertising = fw_advertising;
1266 /* any change to autoneg will cause link change, therefore the
1267 * driver should put back the original pause setting in autoneg
1272 u8 phy_type = link_info->phy_type;
1274 if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET ||
1275 phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
1276 link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1277 netdev_err(dev, "10GBase-T devices must autoneg\n");
1279 goto set_setting_exit;
1281 if (base->duplex == DUPLEX_HALF) {
1282 netdev_err(dev, "HALF DUPLEX is not supported!\n");
1284 goto set_setting_exit;
1286 speed = base->speed;
1287 fw_speed = bnxt_get_fw_speed(dev, speed);
1290 goto set_setting_exit;
1292 link_info->req_link_speed = fw_speed;
1293 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
1294 link_info->autoneg = 0;
1295 link_info->advertising = 0;
1298 if (netif_running(dev))
1299 rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
1302 mutex_unlock(&bp->link_lock);
1306 static void bnxt_get_pauseparam(struct net_device *dev,
1307 struct ethtool_pauseparam *epause)
1309 struct bnxt *bp = netdev_priv(dev);
1310 struct bnxt_link_info *link_info = &bp->link_info;
1314 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
1315 epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
1316 epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
1319 static int bnxt_set_pauseparam(struct net_device *dev,
1320 struct ethtool_pauseparam *epause)
1323 struct bnxt *bp = netdev_priv(dev);
1324 struct bnxt_link_info *link_info = &bp->link_info;
1326 if (!BNXT_SINGLE_PF(bp))
1329 if (epause->autoneg) {
1330 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1333 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1334 if (bp->hwrm_spec_code >= 0x10201)
1335 link_info->req_flow_ctrl =
1336 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
1338 /* when transition from auto pause to force pause,
1339 * force a link change
1341 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1342 link_info->force_link_chng = true;
1343 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1344 link_info->req_flow_ctrl = 0;
1346 if (epause->rx_pause)
1347 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1349 if (epause->tx_pause)
1350 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1352 if (netif_running(dev))
1353 rc = bnxt_hwrm_set_pause(bp);
1357 static u32 bnxt_get_link(struct net_device *dev)
1359 struct bnxt *bp = netdev_priv(dev);
1361 /* TODO: handle MF, VF, driver close case */
1362 return bp->link_info.link_up;
1365 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1366 u16 ext, u16 *index, u32 *item_length,
1369 static int bnxt_flash_nvram(struct net_device *dev,
1377 struct bnxt *bp = netdev_priv(dev);
1379 struct hwrm_nvm_write_input req = {0};
1380 dma_addr_t dma_handle;
1383 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1385 req.dir_type = cpu_to_le16(dir_type);
1386 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1387 req.dir_ext = cpu_to_le16(dir_ext);
1388 req.dir_attr = cpu_to_le16(dir_attr);
1389 req.dir_data_length = cpu_to_le32(data_len);
1391 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1394 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1395 (unsigned)data_len);
1398 memcpy(kmem, data, data_len);
1399 req.host_src_addr = cpu_to_le64(dma_handle);
1401 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1402 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1407 static int bnxt_firmware_reset(struct net_device *dev,
1410 struct bnxt *bp = netdev_priv(dev);
1411 struct hwrm_fw_reset_input req = {0};
1413 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1415 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1416 /* (e.g. when firmware isn't already running) */
1418 case BNX_DIR_TYPE_CHIMP_PATCH:
1419 case BNX_DIR_TYPE_BOOTCODE:
1420 case BNX_DIR_TYPE_BOOTCODE_2:
1421 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1422 /* Self-reset ChiMP upon next PCIe reset: */
1423 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1425 case BNX_DIR_TYPE_APE_FW:
1426 case BNX_DIR_TYPE_APE_PATCH:
1427 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1428 /* Self-reset APE upon next PCIe reset: */
1429 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1431 case BNX_DIR_TYPE_KONG_FW:
1432 case BNX_DIR_TYPE_KONG_PATCH:
1433 req.embedded_proc_type =
1434 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1436 case BNX_DIR_TYPE_BONO_FW:
1437 case BNX_DIR_TYPE_BONO_PATCH:
1438 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1440 case BNXT_FW_RESET_CHIP:
1441 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP;
1442 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP;
1444 case BNXT_FW_RESET_AP:
1445 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP;
1451 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1454 static int bnxt_flash_firmware(struct net_device *dev,
1463 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1466 case BNX_DIR_TYPE_BOOTCODE:
1467 case BNX_DIR_TYPE_BOOTCODE_2:
1468 code_type = CODE_BOOT;
1470 case BNX_DIR_TYPE_CHIMP_PATCH:
1471 code_type = CODE_CHIMP_PATCH;
1473 case BNX_DIR_TYPE_APE_FW:
1474 code_type = CODE_MCTP_PASSTHRU;
1476 case BNX_DIR_TYPE_APE_PATCH:
1477 code_type = CODE_APE_PATCH;
1479 case BNX_DIR_TYPE_KONG_FW:
1480 code_type = CODE_KONG_FW;
1482 case BNX_DIR_TYPE_KONG_PATCH:
1483 code_type = CODE_KONG_PATCH;
1485 case BNX_DIR_TYPE_BONO_FW:
1486 code_type = CODE_BONO_FW;
1488 case BNX_DIR_TYPE_BONO_PATCH:
1489 code_type = CODE_BONO_PATCH;
1492 netdev_err(dev, "Unsupported directory entry type: %u\n",
1496 if (fw_size < sizeof(struct bnxt_fw_header)) {
1497 netdev_err(dev, "Invalid firmware file size: %u\n",
1498 (unsigned int)fw_size);
1501 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1502 netdev_err(dev, "Invalid firmware signature: %08X\n",
1503 le32_to_cpu(header->signature));
1506 if (header->code_type != code_type) {
1507 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1508 code_type, header->code_type);
1511 if (header->device != DEVICE_CUMULUS_FAMILY) {
1512 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1513 DEVICE_CUMULUS_FAMILY, header->device);
1516 /* Confirm the CRC32 checksum of the file: */
1517 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1518 sizeof(stored_crc)));
1519 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1520 if (calculated_crc != stored_crc) {
1521 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1522 (unsigned long)stored_crc,
1523 (unsigned long)calculated_crc);
1526 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1527 0, 0, fw_data, fw_size);
1528 if (rc == 0) /* Firmware update successful */
1529 rc = bnxt_firmware_reset(dev, dir_type);
1534 static int bnxt_flash_microcode(struct net_device *dev,
1539 struct bnxt_ucode_trailer *trailer;
1544 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1545 netdev_err(dev, "Invalid microcode file size: %u\n",
1546 (unsigned int)fw_size);
1549 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1551 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1552 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1553 le32_to_cpu(trailer->sig));
1556 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1557 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1558 dir_type, le16_to_cpu(trailer->dir_type));
1561 if (le16_to_cpu(trailer->trailer_length) <
1562 sizeof(struct bnxt_ucode_trailer)) {
1563 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1564 le16_to_cpu(trailer->trailer_length));
1568 /* Confirm the CRC32 checksum of the file: */
1569 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1570 sizeof(stored_crc)));
1571 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1572 if (calculated_crc != stored_crc) {
1574 "CRC32 (%08lX) does not match calculated: %08lX\n",
1575 (unsigned long)stored_crc,
1576 (unsigned long)calculated_crc);
1579 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1580 0, 0, fw_data, fw_size);
1585 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1588 case BNX_DIR_TYPE_CHIMP_PATCH:
1589 case BNX_DIR_TYPE_BOOTCODE:
1590 case BNX_DIR_TYPE_BOOTCODE_2:
1591 case BNX_DIR_TYPE_APE_FW:
1592 case BNX_DIR_TYPE_APE_PATCH:
1593 case BNX_DIR_TYPE_KONG_FW:
1594 case BNX_DIR_TYPE_KONG_PATCH:
1595 case BNX_DIR_TYPE_BONO_FW:
1596 case BNX_DIR_TYPE_BONO_PATCH:
1603 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1606 case BNX_DIR_TYPE_AVS:
1607 case BNX_DIR_TYPE_EXP_ROM_MBA:
1608 case BNX_DIR_TYPE_PCIE:
1609 case BNX_DIR_TYPE_TSCF_UCODE:
1610 case BNX_DIR_TYPE_EXT_PHY:
1611 case BNX_DIR_TYPE_CCM:
1612 case BNX_DIR_TYPE_ISCSI_BOOT:
1613 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1614 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1621 static bool bnxt_dir_type_is_executable(u16 dir_type)
1623 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1624 bnxt_dir_type_is_other_exec_format(dir_type);
1627 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1629 const char *filename)
1631 const struct firmware *fw;
1634 rc = request_firmware(&fw, filename, &dev->dev);
1636 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1640 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1641 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1642 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1643 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1645 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1646 0, 0, fw->data, fw->size);
1647 release_firmware(fw);
1651 static int bnxt_flash_package_from_file(struct net_device *dev,
1652 char *filename, u32 install_type)
1654 struct bnxt *bp = netdev_priv(dev);
1655 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
1656 struct hwrm_nvm_install_update_input install = {0};
1657 const struct firmware *fw;
1662 bnxt_hwrm_fw_set_time(bp);
1664 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
1665 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1666 &index, &item_len, NULL) != 0) {
1667 netdev_err(dev, "PKG update area not created in nvram\n");
1671 rc = request_firmware(&fw, filename, &dev->dev);
1673 netdev_err(dev, "PKG error %d requesting file: %s\n",
1678 if (fw->size > item_len) {
1679 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
1680 (unsigned long)fw->size);
1683 dma_addr_t dma_handle;
1685 struct hwrm_nvm_modify_input modify = {0};
1687 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
1689 modify.dir_idx = cpu_to_le16(index);
1690 modify.len = cpu_to_le32(fw->size);
1692 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
1693 &dma_handle, GFP_KERNEL);
1696 "dma_alloc_coherent failure, length = %u\n",
1697 (unsigned int)fw->size);
1700 memcpy(kmem, fw->data, fw->size);
1701 modify.host_src_addr = cpu_to_le64(dma_handle);
1703 rc = hwrm_send_message(bp, &modify, sizeof(modify),
1704 FLASH_PACKAGE_TIMEOUT);
1705 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
1709 release_firmware(fw);
1713 if ((install_type & 0xffff) == 0)
1714 install_type >>= 16;
1715 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
1716 install.install_type = cpu_to_le32(install_type);
1718 mutex_lock(&bp->hwrm_cmd_lock);
1719 rc = _hwrm_send_message(bp, &install, sizeof(install),
1720 INSTALL_PACKAGE_TIMEOUT);
1723 goto flash_pkg_exit;
1726 if (resp->error_code) {
1727 u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err;
1729 if (error_code == NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) {
1730 install.flags |= cpu_to_le16(
1731 NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG);
1732 rc = _hwrm_send_message(bp, &install, sizeof(install),
1733 INSTALL_PACKAGE_TIMEOUT);
1736 goto flash_pkg_exit;
1742 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
1743 (s8)resp->result, (int)resp->problem_item);
1747 mutex_unlock(&bp->hwrm_cmd_lock);
1751 static int bnxt_flash_device(struct net_device *dev,
1752 struct ethtool_flash *flash)
1754 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1755 netdev_err(dev, "flashdev not supported from a virtual function\n");
1759 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
1760 flash->region > 0xffff)
1761 return bnxt_flash_package_from_file(dev, flash->data,
1764 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1767 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1769 struct bnxt *bp = netdev_priv(dev);
1771 struct hwrm_nvm_get_dir_info_input req = {0};
1772 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1774 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1776 mutex_lock(&bp->hwrm_cmd_lock);
1777 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1779 *entries = le32_to_cpu(output->entries);
1780 *length = le32_to_cpu(output->entry_length);
1782 mutex_unlock(&bp->hwrm_cmd_lock);
1786 static int bnxt_get_eeprom_len(struct net_device *dev)
1788 /* The -1 return value allows the entire 32-bit range of offsets to be
1789 * passed via the ethtool command-line utility.
1794 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1796 struct bnxt *bp = netdev_priv(dev);
1802 dma_addr_t dma_handle;
1803 struct hwrm_nvm_get_dir_entries_input req = {0};
1805 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1809 /* Insert 2 bytes of directory info (count and size of entries) */
1813 *data++ = dir_entries;
1814 *data++ = entry_length;
1816 memset(data, 0xff, len);
1818 buflen = dir_entries * entry_length;
1819 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1822 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1826 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1827 req.host_dest_addr = cpu_to_le64(dma_handle);
1828 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1830 memcpy(data, buf, len > buflen ? buflen : len);
1831 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1835 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1836 u32 length, u8 *data)
1838 struct bnxt *bp = netdev_priv(dev);
1841 dma_addr_t dma_handle;
1842 struct hwrm_nvm_read_input req = {0};
1847 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1850 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1854 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1855 req.host_dest_addr = cpu_to_le64(dma_handle);
1856 req.dir_idx = cpu_to_le16(index);
1857 req.offset = cpu_to_le32(offset);
1858 req.len = cpu_to_le32(length);
1860 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1862 memcpy(data, buf, length);
1863 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1867 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1868 u16 ext, u16 *index, u32 *item_length,
1871 struct bnxt *bp = netdev_priv(dev);
1873 struct hwrm_nvm_find_dir_entry_input req = {0};
1874 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
1876 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
1879 req.dir_type = cpu_to_le16(type);
1880 req.dir_ordinal = cpu_to_le16(ordinal);
1881 req.dir_ext = cpu_to_le16(ext);
1882 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
1883 mutex_lock(&bp->hwrm_cmd_lock);
1884 rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1887 *index = le16_to_cpu(output->dir_idx);
1889 *item_length = le32_to_cpu(output->dir_item_length);
1891 *data_length = le32_to_cpu(output->dir_data_length);
1893 mutex_unlock(&bp->hwrm_cmd_lock);
1897 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
1899 char *retval = NULL;
1906 /* null-terminate the log data (removing last '\n'): */
1907 data[datalen - 1] = 0;
1908 for (p = data; *p != 0; p++) {
1911 while (*p != 0 && *p != '\n') {
1913 while (*p != 0 && *p != '\t' && *p != '\n')
1915 if (field == desired_field)
1930 static void bnxt_get_pkgver(struct net_device *dev)
1932 struct bnxt *bp = netdev_priv(dev);
1939 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
1940 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1941 &index, NULL, &pkglen) != 0)
1944 pkgbuf = kzalloc(pkglen, GFP_KERNEL);
1946 dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n",
1951 if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf))
1954 pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf,
1956 if (pkgver && *pkgver != 0 && isdigit(*pkgver)) {
1957 len = strlen(bp->fw_ver_str);
1958 snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1,
1965 static int bnxt_get_eeprom(struct net_device *dev,
1966 struct ethtool_eeprom *eeprom,
1972 if (eeprom->offset == 0) /* special offset value to get directory */
1973 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1975 index = eeprom->offset >> 24;
1976 offset = eeprom->offset & 0xffffff;
1979 netdev_err(dev, "unsupported index value: %d\n", index);
1983 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1986 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1988 struct bnxt *bp = netdev_priv(dev);
1989 struct hwrm_nvm_erase_dir_entry_input req = {0};
1991 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1992 req.dir_idx = cpu_to_le16(index);
1993 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1996 static int bnxt_set_eeprom(struct net_device *dev,
1997 struct ethtool_eeprom *eeprom,
2000 struct bnxt *bp = netdev_priv(dev);
2002 u16 type, ext, ordinal, attr;
2005 netdev_err(dev, "NVM write not supported from a virtual function\n");
2009 type = eeprom->magic >> 16;
2011 if (type == 0xffff) { /* special value for directory operations */
2012 index = eeprom->magic & 0xff;
2013 dir_op = eeprom->magic >> 8;
2017 case 0x0e: /* erase */
2018 if (eeprom->offset != ~eeprom->magic)
2020 return bnxt_erase_nvram_directory(dev, index - 1);
2026 /* Create or re-write an NVM item: */
2027 if (bnxt_dir_type_is_executable(type) == true)
2029 ext = eeprom->magic & 0xffff;
2030 ordinal = eeprom->offset >> 16;
2031 attr = eeprom->offset & 0xffff;
2033 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
2037 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
2039 struct bnxt *bp = netdev_priv(dev);
2040 struct ethtool_eee *eee = &bp->eee;
2041 struct bnxt_link_info *link_info = &bp->link_info;
2043 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
2046 if (!BNXT_SINGLE_PF(bp))
2049 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
2052 if (!edata->eee_enabled)
2055 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
2056 netdev_warn(dev, "EEE requires autoneg\n");
2059 if (edata->tx_lpi_enabled) {
2060 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
2061 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
2062 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
2063 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
2065 } else if (!bp->lpi_tmr_hi) {
2066 edata->tx_lpi_timer = eee->tx_lpi_timer;
2069 if (!edata->advertised) {
2070 edata->advertised = advertising & eee->supported;
2071 } else if (edata->advertised & ~advertising) {
2072 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
2073 edata->advertised, advertising);
2077 eee->advertised = edata->advertised;
2078 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
2079 eee->tx_lpi_timer = edata->tx_lpi_timer;
2081 eee->eee_enabled = edata->eee_enabled;
2083 if (netif_running(dev))
2084 rc = bnxt_hwrm_set_link_setting(bp, false, true);
2089 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
2091 struct bnxt *bp = netdev_priv(dev);
2093 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
2097 if (!bp->eee.eee_enabled) {
2098 /* Preserve tx_lpi_timer so that the last value will be used
2099 * by default when it is re-enabled.
2101 edata->advertised = 0;
2102 edata->tx_lpi_enabled = 0;
2105 if (!bp->eee.eee_active)
2106 edata->lp_advertised = 0;
2111 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
2112 u16 page_number, u16 start_addr,
2113 u16 data_length, u8 *buf)
2115 struct hwrm_port_phy_i2c_read_input req = {0};
2116 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
2117 int rc, byte_offset = 0;
2119 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
2120 req.i2c_slave_addr = i2c_addr;
2121 req.page_number = cpu_to_le16(page_number);
2122 req.port_id = cpu_to_le16(bp->pf.port_id);
2126 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
2127 data_length -= xfer_size;
2128 req.page_offset = cpu_to_le16(start_addr + byte_offset);
2129 req.data_length = xfer_size;
2130 req.enables = cpu_to_le32(start_addr + byte_offset ?
2131 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
2132 mutex_lock(&bp->hwrm_cmd_lock);
2133 rc = _hwrm_send_message(bp, &req, sizeof(req),
2136 memcpy(buf + byte_offset, output->data, xfer_size);
2137 mutex_unlock(&bp->hwrm_cmd_lock);
2138 byte_offset += xfer_size;
2139 } while (!rc && data_length > 0);
2144 static int bnxt_get_module_info(struct net_device *dev,
2145 struct ethtool_modinfo *modinfo)
2147 struct bnxt *bp = netdev_priv(dev);
2148 struct hwrm_port_phy_i2c_read_input req = {0};
2149 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
2152 /* No point in going further if phy status indicates
2153 * module is not inserted or if it is powered down or
2154 * if it is of type 10GBase-T
2156 if (bp->link_info.module_status >
2157 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
2160 /* This feature is not supported in older firmware versions */
2161 if (bp->hwrm_spec_code < 0x10202)
2164 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
2165 req.i2c_slave_addr = I2C_DEV_ADDR_A0;
2166 req.page_number = 0;
2167 req.page_offset = cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR);
2168 req.data_length = SFP_EEPROM_SFF_8472_COMP_SIZE;
2169 req.port_id = cpu_to_le16(bp->pf.port_id);
2170 mutex_lock(&bp->hwrm_cmd_lock);
2171 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2173 u32 module_id = le32_to_cpu(output->data[0]);
2175 switch (module_id) {
2176 case SFF_MODULE_ID_SFP:
2177 modinfo->type = ETH_MODULE_SFF_8472;
2178 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2180 case SFF_MODULE_ID_QSFP:
2181 case SFF_MODULE_ID_QSFP_PLUS:
2182 modinfo->type = ETH_MODULE_SFF_8436;
2183 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
2185 case SFF_MODULE_ID_QSFP28:
2186 modinfo->type = ETH_MODULE_SFF_8636;
2187 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
2194 mutex_unlock(&bp->hwrm_cmd_lock);
2198 static int bnxt_get_module_eeprom(struct net_device *dev,
2199 struct ethtool_eeprom *eeprom,
2202 struct bnxt *bp = netdev_priv(dev);
2203 u16 start = eeprom->offset, length = eeprom->len;
2206 memset(data, 0, eeprom->len);
2208 /* Read A0 portion of the EEPROM */
2209 if (start < ETH_MODULE_SFF_8436_LEN) {
2210 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
2211 length = ETH_MODULE_SFF_8436_LEN - start;
2212 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
2213 start, length, data);
2218 length = eeprom->len - length;
2221 /* Read A2 portion of the EEPROM */
2223 start -= ETH_MODULE_SFF_8436_LEN;
2224 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1,
2225 start, length, data);
2230 static int bnxt_nway_reset(struct net_device *dev)
2234 struct bnxt *bp = netdev_priv(dev);
2235 struct bnxt_link_info *link_info = &bp->link_info;
2237 if (!BNXT_SINGLE_PF(bp))
2240 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
2243 if (netif_running(dev))
2244 rc = bnxt_hwrm_set_link_setting(bp, true, false);
2249 static int bnxt_set_phys_id(struct net_device *dev,
2250 enum ethtool_phys_id_state state)
2252 struct hwrm_port_led_cfg_input req = {0};
2253 struct bnxt *bp = netdev_priv(dev);
2254 struct bnxt_pf_info *pf = &bp->pf;
2255 struct bnxt_led_cfg *led_cfg;
2260 if (!bp->num_leds || BNXT_VF(bp))
2263 if (state == ETHTOOL_ID_ACTIVE) {
2264 led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT;
2265 duration = cpu_to_le16(500);
2266 } else if (state == ETHTOOL_ID_INACTIVE) {
2267 led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT;
2268 duration = cpu_to_le16(0);
2272 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1);
2273 req.port_id = cpu_to_le16(pf->port_id);
2274 req.num_leds = bp->num_leds;
2275 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
2276 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
2277 req.enables |= BNXT_LED_DFLT_ENABLES(i);
2278 led_cfg->led_id = bp->leds[i].led_id;
2279 led_cfg->led_state = led_state;
2280 led_cfg->led_blink_on = duration;
2281 led_cfg->led_blink_off = duration;
2282 led_cfg->led_group_id = bp->leds[i].led_group_id;
2284 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2290 static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring)
2292 struct hwrm_selftest_irq_input req = {0};
2294 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1);
2295 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2298 static int bnxt_test_irq(struct bnxt *bp)
2302 for (i = 0; i < bp->cp_nr_rings; i++) {
2303 u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id;
2306 rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring);
2313 static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable)
2315 struct hwrm_port_mac_cfg_input req = {0};
2317 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1);
2319 req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK);
2321 req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL;
2323 req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE;
2324 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2327 static int bnxt_disable_an_for_lpbk(struct bnxt *bp,
2328 struct hwrm_port_phy_cfg_input *req)
2330 struct bnxt_link_info *link_info = &bp->link_info;
2331 u16 fw_advertising = link_info->advertising;
2335 if (!link_info->autoneg)
2338 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB;
2339 if (netif_carrier_ok(bp->dev))
2340 fw_speed = bp->link_info.link_speed;
2341 else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB)
2342 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB;
2343 else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB)
2344 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB;
2345 else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB)
2346 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB;
2347 else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB)
2348 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB;
2350 req->force_link_speed = cpu_to_le16(fw_speed);
2351 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE |
2352 PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
2353 rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT);
2355 req->force_link_speed = cpu_to_le16(0);
2359 static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable)
2361 struct hwrm_port_phy_cfg_input req = {0};
2363 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
2366 bnxt_disable_an_for_lpbk(bp, &req);
2367 req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL;
2369 req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE;
2371 req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK);
2372 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2375 static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_napi *bnapi,
2376 u32 raw_cons, int pkt_size)
2378 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2379 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
2380 struct bnxt_sw_rx_bd *rx_buf;
2381 struct rx_cmp *rxcmp;
2387 cp_cons = RING_CMP(raw_cons);
2388 rxcmp = (struct rx_cmp *)
2389 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
2390 cons = rxcmp->rx_cmp_opaque;
2391 rx_buf = &rxr->rx_buf_ring[cons];
2392 data = rx_buf->data_ptr;
2393 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
2394 if (len != pkt_size)
2397 if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr))
2400 for ( ; i < pkt_size; i++) {
2401 if (data[i] != (u8)(i & 0xff))
2407 static int bnxt_poll_loopback(struct bnxt *bp, int pkt_size)
2409 struct bnxt_napi *bnapi = bp->bnapi[0];
2410 struct bnxt_cp_ring_info *cpr;
2411 struct tx_cmp *txcmp;
2417 cpr = &bnapi->cp_ring;
2418 raw_cons = cpr->cp_raw_cons;
2419 for (i = 0; i < 200; i++) {
2420 cons = RING_CMP(raw_cons);
2421 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
2423 if (!TX_CMP_VALID(txcmp, raw_cons)) {
2428 /* The valid test of the entry must be done first before
2429 * reading any further.
2432 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) {
2433 rc = bnxt_rx_loopback(bp, bnapi, raw_cons, pkt_size);
2434 raw_cons = NEXT_RAW_CMP(raw_cons);
2435 raw_cons = NEXT_RAW_CMP(raw_cons);
2438 raw_cons = NEXT_RAW_CMP(raw_cons);
2440 cpr->cp_raw_cons = raw_cons;
2444 static int bnxt_run_loopback(struct bnxt *bp)
2446 struct bnxt_tx_ring_info *txr = &bp->tx_ring[0];
2447 int pkt_size, i = 0;
2448 struct sk_buff *skb;
2453 pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
2454 skb = netdev_alloc_skb(bp->dev, pkt_size);
2457 data = skb_put(skb, pkt_size);
2458 eth_broadcast_addr(data);
2460 ether_addr_copy(&data[i], bp->dev->dev_addr);
2462 for ( ; i < pkt_size; i++)
2463 data[i] = (u8)(i & 0xff);
2465 map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size,
2467 if (dma_mapping_error(&bp->pdev->dev, map)) {
2471 bnxt_xmit_xdp(bp, txr, map, pkt_size, 0);
2473 /* Sync BD data before updating doorbell */
2476 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | txr->tx_prod);
2477 rc = bnxt_poll_loopback(bp, pkt_size);
2479 dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE);
2484 static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results)
2486 struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr;
2487 struct hwrm_selftest_exec_input req = {0};
2490 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1);
2491 mutex_lock(&bp->hwrm_cmd_lock);
2492 resp->test_success = 0;
2493 req.flags = test_mask;
2494 rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout);
2495 *test_results = resp->test_success;
2496 mutex_unlock(&bp->hwrm_cmd_lock);
2500 #define BNXT_DRV_TESTS 3
2501 #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS)
2502 #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1)
2503 #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2)
2505 static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
2508 struct bnxt *bp = netdev_priv(dev);
2509 bool offline = false;
2510 u8 test_results = 0;
2514 if (!bp->num_tests || !BNXT_SINGLE_PF(bp))
2516 memset(buf, 0, sizeof(u64) * bp->num_tests);
2517 if (!netif_running(dev)) {
2518 etest->flags |= ETH_TEST_FL_FAILED;
2522 if (etest->flags & ETH_TEST_FL_OFFLINE) {
2523 if (bp->pf.active_vfs) {
2524 etest->flags |= ETH_TEST_FL_FAILED;
2525 netdev_warn(dev, "Offline tests cannot be run with active VFs\n");
2531 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2532 u8 bit_val = 1 << i;
2534 if (!(bp->test_info->offline_mask & bit_val))
2535 test_mask |= bit_val;
2537 test_mask |= bit_val;
2540 bnxt_run_fw_tests(bp, test_mask, &test_results);
2542 rc = bnxt_close_nic(bp, false, false);
2545 bnxt_run_fw_tests(bp, test_mask, &test_results);
2547 buf[BNXT_MACLPBK_TEST_IDX] = 1;
2548 bnxt_hwrm_mac_loopback(bp, true);
2550 rc = bnxt_half_open_nic(bp);
2552 bnxt_hwrm_mac_loopback(bp, false);
2553 etest->flags |= ETH_TEST_FL_FAILED;
2556 if (bnxt_run_loopback(bp))
2557 etest->flags |= ETH_TEST_FL_FAILED;
2559 buf[BNXT_MACLPBK_TEST_IDX] = 0;
2561 bnxt_hwrm_mac_loopback(bp, false);
2562 bnxt_hwrm_phy_loopback(bp, true);
2564 if (bnxt_run_loopback(bp)) {
2565 buf[BNXT_PHYLPBK_TEST_IDX] = 1;
2566 etest->flags |= ETH_TEST_FL_FAILED;
2568 bnxt_hwrm_phy_loopback(bp, false);
2569 bnxt_half_close_nic(bp);
2570 bnxt_open_nic(bp, false, true);
2572 if (bnxt_test_irq(bp)) {
2573 buf[BNXT_IRQ_TEST_IDX] = 1;
2574 etest->flags |= ETH_TEST_FL_FAILED;
2576 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2577 u8 bit_val = 1 << i;
2579 if ((test_mask & bit_val) && !(test_results & bit_val)) {
2581 etest->flags |= ETH_TEST_FL_FAILED;
2586 static int bnxt_reset(struct net_device *dev, u32 *flags)
2588 struct bnxt *bp = netdev_priv(dev);
2592 netdev_err(dev, "Reset is not supported from a VF\n");
2596 if (pci_vfs_assigned(bp->pdev)) {
2598 "Reset not allowed when VFs are assigned to VMs\n");
2602 if (*flags == ETH_RESET_ALL) {
2603 /* This feature is not supported in older firmware versions */
2604 if (bp->hwrm_spec_code < 0x10803)
2607 rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP);
2609 netdev_info(dev, "Reset request successful. Reload driver to complete reset\n");
2612 } else if (*flags == ETH_RESET_AP) {
2613 /* This feature is not supported in older firmware versions */
2614 if (bp->hwrm_spec_code < 0x10803)
2617 rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP);
2619 netdev_info(dev, "Reset Application Processor request successful.\n");
2629 void bnxt_ethtool_init(struct bnxt *bp)
2631 struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr;
2632 struct hwrm_selftest_qlist_input req = {0};
2633 struct bnxt_test_info *test_info;
2634 struct net_device *dev = bp->dev;
2637 bnxt_get_pkgver(dev);
2639 if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp))
2642 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1);
2643 mutex_lock(&bp->hwrm_cmd_lock);
2644 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2646 goto ethtool_init_exit;
2648 test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL);
2650 goto ethtool_init_exit;
2652 bp->test_info = test_info;
2653 bp->num_tests = resp->num_tests + BNXT_DRV_TESTS;
2654 if (bp->num_tests > BNXT_MAX_TEST)
2655 bp->num_tests = BNXT_MAX_TEST;
2657 test_info->offline_mask = resp->offline_tests;
2658 test_info->timeout = le16_to_cpu(resp->test_timeout);
2659 if (!test_info->timeout)
2660 test_info->timeout = HWRM_CMD_TIMEOUT;
2661 for (i = 0; i < bp->num_tests; i++) {
2662 char *str = test_info->string[i];
2663 char *fw_str = resp->test0_name + i * 32;
2665 if (i == BNXT_MACLPBK_TEST_IDX) {
2666 strcpy(str, "Mac loopback test (offline)");
2667 } else if (i == BNXT_PHYLPBK_TEST_IDX) {
2668 strcpy(str, "Phy loopback test (offline)");
2669 } else if (i == BNXT_IRQ_TEST_IDX) {
2670 strcpy(str, "Interrupt_test (offline)");
2672 strlcpy(str, fw_str, ETH_GSTRING_LEN);
2673 strncat(str, " test", ETH_GSTRING_LEN - strlen(str));
2674 if (test_info->offline_mask & (1 << i))
2675 strncat(str, " (offline)",
2676 ETH_GSTRING_LEN - strlen(str));
2678 strncat(str, " (online)",
2679 ETH_GSTRING_LEN - strlen(str));
2684 mutex_unlock(&bp->hwrm_cmd_lock);
2687 void bnxt_ethtool_free(struct bnxt *bp)
2689 kfree(bp->test_info);
2690 bp->test_info = NULL;
2693 const struct ethtool_ops bnxt_ethtool_ops = {
2694 .get_link_ksettings = bnxt_get_link_ksettings,
2695 .set_link_ksettings = bnxt_set_link_ksettings,
2696 .get_pauseparam = bnxt_get_pauseparam,
2697 .set_pauseparam = bnxt_set_pauseparam,
2698 .get_drvinfo = bnxt_get_drvinfo,
2699 .get_wol = bnxt_get_wol,
2700 .set_wol = bnxt_set_wol,
2701 .get_coalesce = bnxt_get_coalesce,
2702 .set_coalesce = bnxt_set_coalesce,
2703 .get_msglevel = bnxt_get_msglevel,
2704 .set_msglevel = bnxt_set_msglevel,
2705 .get_sset_count = bnxt_get_sset_count,
2706 .get_strings = bnxt_get_strings,
2707 .get_ethtool_stats = bnxt_get_ethtool_stats,
2708 .set_ringparam = bnxt_set_ringparam,
2709 .get_ringparam = bnxt_get_ringparam,
2710 .get_channels = bnxt_get_channels,
2711 .set_channels = bnxt_set_channels,
2712 .get_rxnfc = bnxt_get_rxnfc,
2713 .set_rxnfc = bnxt_set_rxnfc,
2714 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
2715 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
2716 .get_rxfh = bnxt_get_rxfh,
2717 .flash_device = bnxt_flash_device,
2718 .get_eeprom_len = bnxt_get_eeprom_len,
2719 .get_eeprom = bnxt_get_eeprom,
2720 .set_eeprom = bnxt_set_eeprom,
2721 .get_link = bnxt_get_link,
2722 .get_eee = bnxt_get_eee,
2723 .set_eee = bnxt_set_eee,
2724 .get_module_info = bnxt_get_module_info,
2725 .get_module_eeprom = bnxt_get_module_eeprom,
2726 .nway_reset = bnxt_nway_reset,
2727 .set_phys_id = bnxt_set_phys_id,
2728 .self_test = bnxt_self_test,
2729 .reset = bnxt_reset,