1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
10 #include <linux/ctype.h>
11 #include <linux/stringify.h>
12 #include <linux/ethtool.h>
13 #include <linux/interrupt.h>
14 #include <linux/pci.h>
15 #include <linux/etherdevice.h>
16 #include <linux/crc32.h>
17 #include <linux/firmware.h>
20 #include "bnxt_ethtool.h"
21 #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
22 #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
23 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
24 #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
25 #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
27 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen);
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);
48 memset(coal, 0, sizeof(*coal));
50 coal->rx_coalesce_usecs = bp->rx_coal_ticks;
51 /* 2 completion records per rx packet */
52 coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2;
53 coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq;
54 coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2;
56 coal->tx_coalesce_usecs = bp->tx_coal_ticks;
57 coal->tx_max_coalesced_frames = bp->tx_coal_bufs;
58 coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq;
59 coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq;
61 coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
66 static int bnxt_set_coalesce(struct net_device *dev,
67 struct ethtool_coalesce *coal)
69 struct bnxt *bp = netdev_priv(dev);
70 bool update_stats = false;
73 bp->rx_coal_ticks = coal->rx_coalesce_usecs;
74 /* 2 completion records per rx packet */
75 bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2;
76 bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq;
77 bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2;
79 bp->tx_coal_ticks = coal->tx_coalesce_usecs;
80 bp->tx_coal_bufs = coal->tx_max_coalesced_frames;
81 bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq;
82 bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq;
84 if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
85 u32 stats_ticks = coal->stats_block_coalesce_usecs;
87 stats_ticks = clamp_t(u32, stats_ticks,
88 BNXT_MIN_STATS_COAL_TICKS,
89 BNXT_MAX_STATS_COAL_TICKS);
90 stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
91 bp->stats_coal_ticks = stats_ticks;
95 if (netif_running(dev)) {
97 rc = bnxt_close_nic(bp, true, false);
99 rc = bnxt_open_nic(bp, true, false);
101 rc = bnxt_hwrm_set_coal(bp);
108 #define BNXT_NUM_STATS 21
110 #define BNXT_RX_STATS_OFFSET(counter) \
111 (offsetof(struct rx_port_stats, counter) / 8)
113 #define BNXT_RX_STATS_ENTRY(counter) \
114 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
116 #define BNXT_TX_STATS_OFFSET(counter) \
117 ((offsetof(struct tx_port_stats, counter) + \
118 sizeof(struct rx_port_stats) + 512) / 8)
120 #define BNXT_TX_STATS_ENTRY(counter) \
121 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
123 static const struct {
125 char string[ETH_GSTRING_LEN];
126 } bnxt_port_stats_arr[] = {
127 BNXT_RX_STATS_ENTRY(rx_64b_frames),
128 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
129 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
130 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
131 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
132 BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames),
133 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
134 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
135 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
136 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
137 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
138 BNXT_RX_STATS_ENTRY(rx_total_frames),
139 BNXT_RX_STATS_ENTRY(rx_ucast_frames),
140 BNXT_RX_STATS_ENTRY(rx_mcast_frames),
141 BNXT_RX_STATS_ENTRY(rx_bcast_frames),
142 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
143 BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
144 BNXT_RX_STATS_ENTRY(rx_pause_frames),
145 BNXT_RX_STATS_ENTRY(rx_pfc_frames),
146 BNXT_RX_STATS_ENTRY(rx_align_err_frames),
147 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
148 BNXT_RX_STATS_ENTRY(rx_jbr_frames),
149 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
150 BNXT_RX_STATS_ENTRY(rx_tagged_frames),
151 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
152 BNXT_RX_STATS_ENTRY(rx_good_frames),
153 BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
154 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
155 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
156 BNXT_RX_STATS_ENTRY(rx_bytes),
157 BNXT_RX_STATS_ENTRY(rx_runt_bytes),
158 BNXT_RX_STATS_ENTRY(rx_runt_frames),
160 BNXT_TX_STATS_ENTRY(tx_64b_frames),
161 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
162 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
163 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
164 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
165 BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames),
166 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
167 BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames),
168 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
169 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
170 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
171 BNXT_TX_STATS_ENTRY(tx_good_frames),
172 BNXT_TX_STATS_ENTRY(tx_total_frames),
173 BNXT_TX_STATS_ENTRY(tx_ucast_frames),
174 BNXT_TX_STATS_ENTRY(tx_mcast_frames),
175 BNXT_TX_STATS_ENTRY(tx_bcast_frames),
176 BNXT_TX_STATS_ENTRY(tx_pause_frames),
177 BNXT_TX_STATS_ENTRY(tx_pfc_frames),
178 BNXT_TX_STATS_ENTRY(tx_jabber_frames),
179 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
180 BNXT_TX_STATS_ENTRY(tx_err),
181 BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
182 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
183 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
184 BNXT_TX_STATS_ENTRY(tx_total_collisions),
185 BNXT_TX_STATS_ENTRY(tx_bytes),
188 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
190 static int bnxt_get_sset_count(struct net_device *dev, int sset)
192 struct bnxt *bp = netdev_priv(dev);
196 int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
198 if (bp->flags & BNXT_FLAG_PORT_STATS)
199 num_stats += BNXT_NUM_PORT_STATS;
208 static void bnxt_get_ethtool_stats(struct net_device *dev,
209 struct ethtool_stats *stats, u64 *buf)
212 struct bnxt *bp = netdev_priv(dev);
213 u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings;
214 u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
216 memset(buf, 0, buf_size);
221 for (i = 0; i < bp->cp_nr_rings; i++) {
222 struct bnxt_napi *bnapi = bp->bnapi[i];
223 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
224 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
227 for (k = 0; k < stat_fields; j++, k++)
228 buf[j] = le64_to_cpu(hw_stats[k]);
229 buf[j++] = cpr->rx_l4_csum_errors;
231 if (bp->flags & BNXT_FLAG_PORT_STATS) {
232 __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
234 for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
235 buf[j] = le64_to_cpu(*(port_stats +
236 bnxt_port_stats_arr[i].offset));
241 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
243 struct bnxt *bp = netdev_priv(dev);
247 /* The number of strings must match BNXT_NUM_STATS defined above. */
249 for (i = 0; i < bp->cp_nr_rings; i++) {
250 sprintf(buf, "[%d]: rx_ucast_packets", i);
251 buf += ETH_GSTRING_LEN;
252 sprintf(buf, "[%d]: rx_mcast_packets", i);
253 buf += ETH_GSTRING_LEN;
254 sprintf(buf, "[%d]: rx_bcast_packets", i);
255 buf += ETH_GSTRING_LEN;
256 sprintf(buf, "[%d]: rx_discards", i);
257 buf += ETH_GSTRING_LEN;
258 sprintf(buf, "[%d]: rx_drops", i);
259 buf += ETH_GSTRING_LEN;
260 sprintf(buf, "[%d]: rx_ucast_bytes", i);
261 buf += ETH_GSTRING_LEN;
262 sprintf(buf, "[%d]: rx_mcast_bytes", i);
263 buf += ETH_GSTRING_LEN;
264 sprintf(buf, "[%d]: rx_bcast_bytes", i);
265 buf += ETH_GSTRING_LEN;
266 sprintf(buf, "[%d]: tx_ucast_packets", i);
267 buf += ETH_GSTRING_LEN;
268 sprintf(buf, "[%d]: tx_mcast_packets", i);
269 buf += ETH_GSTRING_LEN;
270 sprintf(buf, "[%d]: tx_bcast_packets", i);
271 buf += ETH_GSTRING_LEN;
272 sprintf(buf, "[%d]: tx_discards", i);
273 buf += ETH_GSTRING_LEN;
274 sprintf(buf, "[%d]: tx_drops", i);
275 buf += ETH_GSTRING_LEN;
276 sprintf(buf, "[%d]: tx_ucast_bytes", i);
277 buf += ETH_GSTRING_LEN;
278 sprintf(buf, "[%d]: tx_mcast_bytes", i);
279 buf += ETH_GSTRING_LEN;
280 sprintf(buf, "[%d]: tx_bcast_bytes", i);
281 buf += ETH_GSTRING_LEN;
282 sprintf(buf, "[%d]: tpa_packets", i);
283 buf += ETH_GSTRING_LEN;
284 sprintf(buf, "[%d]: tpa_bytes", i);
285 buf += ETH_GSTRING_LEN;
286 sprintf(buf, "[%d]: tpa_events", i);
287 buf += ETH_GSTRING_LEN;
288 sprintf(buf, "[%d]: tpa_aborts", i);
289 buf += ETH_GSTRING_LEN;
290 sprintf(buf, "[%d]: rx_l4_csum_errors", i);
291 buf += ETH_GSTRING_LEN;
293 if (bp->flags & BNXT_FLAG_PORT_STATS) {
294 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
295 strcpy(buf, bnxt_port_stats_arr[i].string);
296 buf += ETH_GSTRING_LEN;
301 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
307 static void bnxt_get_ringparam(struct net_device *dev,
308 struct ethtool_ringparam *ering)
310 struct bnxt *bp = netdev_priv(dev);
312 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
313 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
314 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
316 ering->rx_pending = bp->rx_ring_size;
317 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
318 ering->tx_pending = bp->tx_ring_size;
321 static int bnxt_set_ringparam(struct net_device *dev,
322 struct ethtool_ringparam *ering)
324 struct bnxt *bp = netdev_priv(dev);
326 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
327 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
328 (ering->tx_pending <= MAX_SKB_FRAGS))
331 if (netif_running(dev))
332 bnxt_close_nic(bp, false, false);
334 bp->rx_ring_size = ering->rx_pending;
335 bp->tx_ring_size = ering->tx_pending;
336 bnxt_set_ring_params(bp);
338 if (netif_running(dev))
339 return bnxt_open_nic(bp, false, false);
344 static void bnxt_get_channels(struct net_device *dev,
345 struct ethtool_channels *channel)
347 struct bnxt *bp = netdev_priv(dev);
348 int max_rx_rings, max_tx_rings, tcs;
350 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
351 channel->max_combined = max_t(int, max_rx_rings, max_tx_rings);
353 if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
358 tcs = netdev_get_num_tc(dev);
362 channel->max_rx = max_rx_rings;
363 channel->max_tx = max_tx_rings;
364 channel->max_other = 0;
365 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
366 channel->combined_count = bp->rx_nr_rings;
367 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
368 channel->combined_count--;
370 if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
371 channel->rx_count = bp->rx_nr_rings;
372 channel->tx_count = bp->tx_nr_rings_per_tc;
377 static int bnxt_set_channels(struct net_device *dev,
378 struct ethtool_channels *channel)
380 struct bnxt *bp = netdev_priv(dev);
381 int max_rx_rings, max_tx_rings, tcs;
385 if (channel->other_count)
388 if (!channel->combined_count &&
389 (!channel->rx_count || !channel->tx_count))
392 if (channel->combined_count &&
393 (channel->rx_count || channel->tx_count))
396 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
400 if (channel->combined_count)
403 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh);
405 tcs = netdev_get_num_tc(dev);
410 channel->combined_count > max_t(int, max_rx_rings, max_tx_rings))
413 if (!sh && (channel->rx_count > max_rx_rings ||
414 channel->tx_count > max_tx_rings))
417 if (netif_running(dev)) {
419 /* TODO CHIMP_FW: Send message to all VF's
423 rc = bnxt_close_nic(bp, true, false);
425 netdev_err(bp->dev, "Set channel failure rc :%x\n",
432 bp->flags |= BNXT_FLAG_SHARED_RINGS;
433 bp->rx_nr_rings = min_t(int, channel->combined_count,
435 bp->tx_nr_rings_per_tc = min_t(int, channel->combined_count,
438 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
439 bp->rx_nr_rings = channel->rx_count;
440 bp->tx_nr_rings_per_tc = channel->tx_count;
443 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
445 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
447 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
448 bp->tx_nr_rings + bp->rx_nr_rings;
450 bp->num_stat_ctxs = bp->cp_nr_rings;
452 /* After changing number of rx channels, update NTUPLE feature. */
453 netdev_update_features(dev);
454 if (netif_running(dev)) {
455 rc = bnxt_open_nic(bp, true, false);
456 if ((!rc) && BNXT_PF(bp)) {
457 /* TODO CHIMP_FW: Send message to all VF's
466 #ifdef CONFIG_RFS_ACCEL
467 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
472 cmd->data = bp->ntp_fltr_count;
473 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
474 struct hlist_head *head;
475 struct bnxt_ntuple_filter *fltr;
477 head = &bp->ntp_fltr_hash_tbl[i];
479 hlist_for_each_entry_rcu(fltr, head, hash) {
480 if (j == cmd->rule_cnt)
482 rule_locs[j++] = fltr->sw_id;
485 if (j == cmd->rule_cnt)
492 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
494 struct ethtool_rx_flow_spec *fs =
495 (struct ethtool_rx_flow_spec *)&cmd->fs;
496 struct bnxt_ntuple_filter *fltr;
497 struct flow_keys *fkeys;
500 if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
503 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
504 struct hlist_head *head;
506 head = &bp->ntp_fltr_hash_tbl[i];
508 hlist_for_each_entry_rcu(fltr, head, hash) {
509 if (fltr->sw_id == fs->location)
517 fkeys = &fltr->fkeys;
518 if (fkeys->basic.ip_proto == IPPROTO_TCP)
519 fs->flow_type = TCP_V4_FLOW;
520 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
521 fs->flow_type = UDP_V4_FLOW;
525 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
526 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
528 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
529 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
531 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
532 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
534 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
535 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
537 fs->ring_cookie = fltr->rxq;
546 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
549 struct bnxt *bp = netdev_priv(dev);
553 case ETHTOOL_GRXRINGS:
554 cmd->data = bp->rx_nr_rings;
557 case ETHTOOL_GRXCLSRLCNT:
558 cmd->rule_cnt = bp->ntp_fltr_count;
559 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
562 case ETHTOOL_GRXCLSRLALL:
563 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
566 case ETHTOOL_GRXCLSRULE:
567 rc = bnxt_grxclsrule(bp, cmd);
579 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
581 return HW_HASH_INDEX_SIZE;
584 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
586 return HW_HASH_KEY_SIZE;
589 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
592 struct bnxt *bp = netdev_priv(dev);
593 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
597 *hfunc = ETH_RSS_HASH_TOP;
600 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
601 indir[i] = le16_to_cpu(vnic->rss_table[i]);
604 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
609 static void bnxt_get_drvinfo(struct net_device *dev,
610 struct ethtool_drvinfo *info)
612 struct bnxt *bp = netdev_priv(dev);
616 pkglog = kmalloc(BNX_PKG_LOG_MAX_LENGTH, GFP_KERNEL);
618 pkgver = bnxt_get_pkgver(dev, pkglog, BNX_PKG_LOG_MAX_LENGTH);
619 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
620 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
621 if (pkgver && *pkgver != 0 && isdigit(*pkgver))
622 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
623 "%s pkg %s", bp->fw_ver_str, pkgver);
625 strlcpy(info->fw_version, bp->fw_ver_str,
626 sizeof(info->fw_version));
627 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
628 info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
629 info->testinfo_len = BNXT_NUM_TESTS(bp);
630 /* TODO CHIMP_FW: eeprom dump details */
631 info->eedump_len = 0;
632 /* TODO CHIMP FW: reg dump details */
633 info->regdump_len = 0;
637 u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
641 /* TODO: support 25GB, 40GB, 50GB with different cable type */
642 /* set the advertised speeds */
643 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
644 speed_mask |= ADVERTISED_100baseT_Full;
645 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
646 speed_mask |= ADVERTISED_1000baseT_Full;
647 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
648 speed_mask |= ADVERTISED_2500baseX_Full;
649 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
650 speed_mask |= ADVERTISED_10000baseT_Full;
651 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
652 speed_mask |= ADVERTISED_40000baseCR4_Full;
654 if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
655 speed_mask |= ADVERTISED_Pause;
656 else if (fw_pause & BNXT_LINK_PAUSE_TX)
657 speed_mask |= ADVERTISED_Asym_Pause;
658 else if (fw_pause & BNXT_LINK_PAUSE_RX)
659 speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
664 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
666 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
667 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
669 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
670 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
672 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
673 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
675 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
676 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
678 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
679 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
681 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
682 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
684 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
685 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
687 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
688 ethtool_link_ksettings_add_link_mode( \
689 lk_ksettings, name, Asym_Pause);\
690 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
691 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
696 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
698 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
700 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
702 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
703 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
705 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
707 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
708 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
710 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
711 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
713 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
714 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
715 40000baseCR4_Full)) \
716 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
717 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
718 50000baseCR2_Full)) \
719 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
722 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
723 struct ethtool_link_ksettings *lk_ksettings)
725 u16 fw_speeds = link_info->auto_link_speeds;
728 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
729 fw_pause = link_info->auto_pause_setting;
731 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
734 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
735 struct ethtool_link_ksettings *lk_ksettings)
737 u16 fw_speeds = link_info->lp_auto_link_speeds;
740 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
741 fw_pause = link_info->lp_pause;
743 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
747 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
748 struct ethtool_link_ksettings *lk_ksettings)
750 u16 fw_speeds = link_info->support_speeds;
752 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
754 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
755 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
758 if (link_info->support_auto_speeds)
759 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
763 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
765 switch (fw_link_speed) {
766 case BNXT_LINK_SPEED_100MB:
768 case BNXT_LINK_SPEED_1GB:
770 case BNXT_LINK_SPEED_2_5GB:
772 case BNXT_LINK_SPEED_10GB:
774 case BNXT_LINK_SPEED_20GB:
776 case BNXT_LINK_SPEED_25GB:
778 case BNXT_LINK_SPEED_40GB:
780 case BNXT_LINK_SPEED_50GB:
783 return SPEED_UNKNOWN;
787 static int bnxt_get_link_ksettings(struct net_device *dev,
788 struct ethtool_link_ksettings *lk_ksettings)
790 struct bnxt *bp = netdev_priv(dev);
791 struct bnxt_link_info *link_info = &bp->link_info;
792 struct ethtool_link_settings *base = &lk_ksettings->base;
795 ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
796 mutex_lock(&bp->link_lock);
797 bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
799 ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
800 if (link_info->autoneg) {
801 bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
802 ethtool_link_ksettings_add_link_mode(lk_ksettings,
803 advertising, Autoneg);
804 base->autoneg = AUTONEG_ENABLE;
805 if (link_info->phy_link_status == BNXT_LINK_LINK)
806 bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
807 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
808 if (!netif_carrier_ok(dev))
809 base->duplex = DUPLEX_UNKNOWN;
810 else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
811 base->duplex = DUPLEX_FULL;
813 base->duplex = DUPLEX_HALF;
815 base->autoneg = AUTONEG_DISABLE;
817 bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
818 base->duplex = DUPLEX_HALF;
819 if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
820 base->duplex = DUPLEX_FULL;
822 base->speed = ethtool_speed;
824 base->port = PORT_NONE;
825 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
826 base->port = PORT_TP;
827 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
829 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
832 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
834 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
837 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
838 base->port = PORT_DA;
839 else if (link_info->media_type ==
840 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
841 base->port = PORT_FIBRE;
843 base->phy_address = link_info->phy_addr;
844 mutex_unlock(&bp->link_lock);
849 static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed)
851 struct bnxt *bp = netdev_priv(dev);
852 struct bnxt_link_info *link_info = &bp->link_info;
853 u16 support_spds = link_info->support_speeds;
856 switch (ethtool_speed) {
858 if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
859 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
862 if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
863 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
866 if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
867 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
870 if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
871 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
874 if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
875 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
878 if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
879 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
882 if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
883 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
886 if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
887 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
890 netdev_err(dev, "unsupported speed!\n");
896 u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
898 u16 fw_speed_mask = 0;
900 /* only support autoneg at speed 100, 1000, and 10000 */
901 if (advertising & (ADVERTISED_100baseT_Full |
902 ADVERTISED_100baseT_Half)) {
903 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
905 if (advertising & (ADVERTISED_1000baseT_Full |
906 ADVERTISED_1000baseT_Half)) {
907 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
909 if (advertising & ADVERTISED_10000baseT_Full)
910 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
912 if (advertising & ADVERTISED_40000baseCR4_Full)
913 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
915 return fw_speed_mask;
918 static int bnxt_set_link_ksettings(struct net_device *dev,
919 const struct ethtool_link_ksettings *lk_ksettings)
921 struct bnxt *bp = netdev_priv(dev);
922 struct bnxt_link_info *link_info = &bp->link_info;
923 const struct ethtool_link_settings *base = &lk_ksettings->base;
924 u32 speed, fw_advertising = 0;
925 bool set_pause = false;
928 if (!BNXT_SINGLE_PF(bp))
931 mutex_lock(&bp->link_lock);
932 if (base->autoneg == AUTONEG_ENABLE) {
933 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
935 link_info->autoneg |= BNXT_AUTONEG_SPEED;
937 link_info->advertising = link_info->support_auto_speeds;
939 link_info->advertising = fw_advertising;
940 /* any change to autoneg will cause link change, therefore the
941 * driver should put back the original pause setting in autoneg
946 u8 phy_type = link_info->phy_type;
948 if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET ||
949 phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
950 link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
951 netdev_err(dev, "10GBase-T devices must autoneg\n");
953 goto set_setting_exit;
955 if (base->duplex == DUPLEX_HALF) {
956 netdev_err(dev, "HALF DUPLEX is not supported!\n");
958 goto set_setting_exit;
961 fw_speed = bnxt_get_fw_speed(dev, speed);
964 goto set_setting_exit;
966 link_info->req_link_speed = fw_speed;
967 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
968 link_info->autoneg = 0;
969 link_info->advertising = 0;
972 if (netif_running(dev))
973 rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
976 mutex_unlock(&bp->link_lock);
980 static void bnxt_get_pauseparam(struct net_device *dev,
981 struct ethtool_pauseparam *epause)
983 struct bnxt *bp = netdev_priv(dev);
984 struct bnxt_link_info *link_info = &bp->link_info;
988 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
989 epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
990 epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
993 static int bnxt_set_pauseparam(struct net_device *dev,
994 struct ethtool_pauseparam *epause)
997 struct bnxt *bp = netdev_priv(dev);
998 struct bnxt_link_info *link_info = &bp->link_info;
1000 if (!BNXT_SINGLE_PF(bp))
1003 mutex_lock(&bp->link_lock);
1004 if (epause->autoneg) {
1005 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1010 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1011 link_info->req_flow_ctrl = 0;
1013 /* when transition from auto pause to force pause,
1014 * force a link change
1016 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1017 link_info->force_link_chng = true;
1018 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1019 link_info->req_flow_ctrl = 0;
1021 if (epause->rx_pause)
1022 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1024 if (epause->tx_pause)
1025 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1027 if (netif_running(dev))
1028 rc = bnxt_hwrm_set_pause(bp);
1031 mutex_unlock(&bp->link_lock);
1035 static u32 bnxt_get_link(struct net_device *dev)
1037 struct bnxt *bp = netdev_priv(dev);
1039 /* TODO: handle MF, VF, driver close case */
1040 return bp->link_info.link_up;
1043 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1044 u16 ext, u16 *index, u32 *item_length,
1047 static int bnxt_flash_nvram(struct net_device *dev,
1055 struct bnxt *bp = netdev_priv(dev);
1057 struct hwrm_nvm_write_input req = {0};
1058 dma_addr_t dma_handle;
1061 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1063 req.dir_type = cpu_to_le16(dir_type);
1064 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1065 req.dir_ext = cpu_to_le16(dir_ext);
1066 req.dir_attr = cpu_to_le16(dir_attr);
1067 req.dir_data_length = cpu_to_le32(data_len);
1069 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1072 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1073 (unsigned)data_len);
1076 memcpy(kmem, data, data_len);
1077 req.host_src_addr = cpu_to_le64(dma_handle);
1079 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1080 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1085 static int bnxt_firmware_reset(struct net_device *dev,
1088 struct bnxt *bp = netdev_priv(dev);
1089 struct hwrm_fw_reset_input req = {0};
1091 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1093 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1094 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1095 /* (e.g. when firmware isn't already running) */
1097 case BNX_DIR_TYPE_CHIMP_PATCH:
1098 case BNX_DIR_TYPE_BOOTCODE:
1099 case BNX_DIR_TYPE_BOOTCODE_2:
1100 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1101 /* Self-reset ChiMP upon next PCIe reset: */
1102 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1104 case BNX_DIR_TYPE_APE_FW:
1105 case BNX_DIR_TYPE_APE_PATCH:
1106 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1107 /* Self-reset APE upon next PCIe reset: */
1108 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1110 case BNX_DIR_TYPE_KONG_FW:
1111 case BNX_DIR_TYPE_KONG_PATCH:
1112 req.embedded_proc_type =
1113 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1115 case BNX_DIR_TYPE_BONO_FW:
1116 case BNX_DIR_TYPE_BONO_PATCH:
1117 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1123 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1126 static int bnxt_flash_firmware(struct net_device *dev,
1135 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1138 case BNX_DIR_TYPE_BOOTCODE:
1139 case BNX_DIR_TYPE_BOOTCODE_2:
1140 code_type = CODE_BOOT;
1142 case BNX_DIR_TYPE_CHIMP_PATCH:
1143 code_type = CODE_CHIMP_PATCH;
1145 case BNX_DIR_TYPE_APE_FW:
1146 code_type = CODE_MCTP_PASSTHRU;
1148 case BNX_DIR_TYPE_APE_PATCH:
1149 code_type = CODE_APE_PATCH;
1151 case BNX_DIR_TYPE_KONG_FW:
1152 code_type = CODE_KONG_FW;
1154 case BNX_DIR_TYPE_KONG_PATCH:
1155 code_type = CODE_KONG_PATCH;
1157 case BNX_DIR_TYPE_BONO_FW:
1158 code_type = CODE_BONO_FW;
1160 case BNX_DIR_TYPE_BONO_PATCH:
1161 code_type = CODE_BONO_PATCH;
1164 netdev_err(dev, "Unsupported directory entry type: %u\n",
1168 if (fw_size < sizeof(struct bnxt_fw_header)) {
1169 netdev_err(dev, "Invalid firmware file size: %u\n",
1170 (unsigned int)fw_size);
1173 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1174 netdev_err(dev, "Invalid firmware signature: %08X\n",
1175 le32_to_cpu(header->signature));
1178 if (header->code_type != code_type) {
1179 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1180 code_type, header->code_type);
1183 if (header->device != DEVICE_CUMULUS_FAMILY) {
1184 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1185 DEVICE_CUMULUS_FAMILY, header->device);
1188 /* Confirm the CRC32 checksum of the file: */
1189 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1190 sizeof(stored_crc)));
1191 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1192 if (calculated_crc != stored_crc) {
1193 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1194 (unsigned long)stored_crc,
1195 (unsigned long)calculated_crc);
1198 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1199 0, 0, fw_data, fw_size);
1200 if (rc == 0) /* Firmware update successful */
1201 rc = bnxt_firmware_reset(dev, dir_type);
1206 static int bnxt_flash_microcode(struct net_device *dev,
1211 struct bnxt_ucode_trailer *trailer;
1216 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1217 netdev_err(dev, "Invalid microcode file size: %u\n",
1218 (unsigned int)fw_size);
1221 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1223 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1224 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1225 le32_to_cpu(trailer->sig));
1228 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1229 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1230 dir_type, le16_to_cpu(trailer->dir_type));
1233 if (le16_to_cpu(trailer->trailer_length) <
1234 sizeof(struct bnxt_ucode_trailer)) {
1235 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1236 le16_to_cpu(trailer->trailer_length));
1240 /* Confirm the CRC32 checksum of the file: */
1241 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1242 sizeof(stored_crc)));
1243 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1244 if (calculated_crc != stored_crc) {
1246 "CRC32 (%08lX) does not match calculated: %08lX\n",
1247 (unsigned long)stored_crc,
1248 (unsigned long)calculated_crc);
1251 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1252 0, 0, fw_data, fw_size);
1257 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1260 case BNX_DIR_TYPE_CHIMP_PATCH:
1261 case BNX_DIR_TYPE_BOOTCODE:
1262 case BNX_DIR_TYPE_BOOTCODE_2:
1263 case BNX_DIR_TYPE_APE_FW:
1264 case BNX_DIR_TYPE_APE_PATCH:
1265 case BNX_DIR_TYPE_KONG_FW:
1266 case BNX_DIR_TYPE_KONG_PATCH:
1267 case BNX_DIR_TYPE_BONO_FW:
1268 case BNX_DIR_TYPE_BONO_PATCH:
1275 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1278 case BNX_DIR_TYPE_AVS:
1279 case BNX_DIR_TYPE_EXP_ROM_MBA:
1280 case BNX_DIR_TYPE_PCIE:
1281 case BNX_DIR_TYPE_TSCF_UCODE:
1282 case BNX_DIR_TYPE_EXT_PHY:
1283 case BNX_DIR_TYPE_CCM:
1284 case BNX_DIR_TYPE_ISCSI_BOOT:
1285 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1286 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1293 static bool bnxt_dir_type_is_executable(u16 dir_type)
1295 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1296 bnxt_dir_type_is_other_exec_format(dir_type);
1299 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1301 const char *filename)
1303 const struct firmware *fw;
1306 rc = request_firmware(&fw, filename, &dev->dev);
1308 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1312 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1313 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1314 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1315 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1317 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1318 0, 0, fw->data, fw->size);
1319 release_firmware(fw);
1323 static int bnxt_flash_package_from_file(struct net_device *dev,
1324 char *filename, u32 install_type)
1326 struct bnxt *bp = netdev_priv(dev);
1327 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
1328 struct hwrm_nvm_install_update_input install = {0};
1329 const struct firmware *fw;
1334 bnxt_hwrm_fw_set_time(bp);
1336 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
1337 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1338 &index, &item_len, NULL) != 0) {
1339 netdev_err(dev, "PKG update area not created in nvram\n");
1343 rc = request_firmware(&fw, filename, &dev->dev);
1345 netdev_err(dev, "PKG error %d requesting file: %s\n",
1350 if (fw->size > item_len) {
1351 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
1352 (unsigned long)fw->size);
1355 dma_addr_t dma_handle;
1357 struct hwrm_nvm_modify_input modify = {0};
1359 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
1361 modify.dir_idx = cpu_to_le16(index);
1362 modify.len = cpu_to_le32(fw->size);
1364 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
1365 &dma_handle, GFP_KERNEL);
1368 "dma_alloc_coherent failure, length = %u\n",
1369 (unsigned int)fw->size);
1372 memcpy(kmem, fw->data, fw->size);
1373 modify.host_src_addr = cpu_to_le64(dma_handle);
1375 rc = hwrm_send_message(bp, &modify, sizeof(modify),
1376 FLASH_PACKAGE_TIMEOUT);
1377 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
1381 release_firmware(fw);
1385 if ((install_type & 0xffff) == 0)
1386 install_type >>= 16;
1387 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
1388 install.install_type = cpu_to_le32(install_type);
1390 rc = hwrm_send_message(bp, &install, sizeof(install),
1391 INSTALL_PACKAGE_TIMEOUT);
1396 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
1397 (s8)resp->result, (int)resp->problem_item);
1403 static int bnxt_flash_device(struct net_device *dev,
1404 struct ethtool_flash *flash)
1406 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1407 netdev_err(dev, "flashdev not supported from a virtual function\n");
1411 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
1412 flash->region > 0xffff)
1413 return bnxt_flash_package_from_file(dev, flash->data,
1416 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1419 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1421 struct bnxt *bp = netdev_priv(dev);
1423 struct hwrm_nvm_get_dir_info_input req = {0};
1424 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1426 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1428 mutex_lock(&bp->hwrm_cmd_lock);
1429 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1431 *entries = le32_to_cpu(output->entries);
1432 *length = le32_to_cpu(output->entry_length);
1434 mutex_unlock(&bp->hwrm_cmd_lock);
1438 static int bnxt_get_eeprom_len(struct net_device *dev)
1440 /* The -1 return value allows the entire 32-bit range of offsets to be
1441 * passed via the ethtool command-line utility.
1446 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1448 struct bnxt *bp = netdev_priv(dev);
1454 dma_addr_t dma_handle;
1455 struct hwrm_nvm_get_dir_entries_input req = {0};
1457 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1461 if (!dir_entries || !entry_length)
1464 /* Insert 2 bytes of directory info (count and size of entries) */
1468 *data++ = dir_entries;
1469 *data++ = entry_length;
1471 memset(data, 0xff, len);
1473 buflen = dir_entries * entry_length;
1474 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1477 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1481 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1482 req.host_dest_addr = cpu_to_le64(dma_handle);
1483 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1485 memcpy(data, buf, len > buflen ? buflen : len);
1486 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1490 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1491 u32 length, u8 *data)
1493 struct bnxt *bp = netdev_priv(dev);
1496 dma_addr_t dma_handle;
1497 struct hwrm_nvm_read_input req = {0};
1499 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1502 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1506 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1507 req.host_dest_addr = cpu_to_le64(dma_handle);
1508 req.dir_idx = cpu_to_le16(index);
1509 req.offset = cpu_to_le32(offset);
1510 req.len = cpu_to_le32(length);
1512 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1514 memcpy(data, buf, length);
1515 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1519 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1520 u16 ext, u16 *index, u32 *item_length,
1523 struct bnxt *bp = netdev_priv(dev);
1525 struct hwrm_nvm_find_dir_entry_input req = {0};
1526 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
1528 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
1531 req.dir_type = cpu_to_le16(type);
1532 req.dir_ordinal = cpu_to_le16(ordinal);
1533 req.dir_ext = cpu_to_le16(ext);
1534 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
1535 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1538 *index = le16_to_cpu(output->dir_idx);
1540 *item_length = le32_to_cpu(output->dir_item_length);
1542 *data_length = le32_to_cpu(output->dir_data_length);
1547 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
1549 char *retval = NULL;
1556 /* null-terminate the log data (removing last '\n'): */
1557 data[datalen - 1] = 0;
1558 for (p = data; *p != 0; p++) {
1561 while (*p != 0 && *p != '\n') {
1563 while (*p != 0 && *p != '\t' && *p != '\n')
1565 if (field == desired_field)
1580 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen)
1585 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
1586 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1587 &index, NULL, &datalen) != 0)
1590 memset(buf, 0, buflen);
1591 if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0)
1594 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf,
1598 static int bnxt_get_eeprom(struct net_device *dev,
1599 struct ethtool_eeprom *eeprom,
1605 if (eeprom->offset == 0) /* special offset value to get directory */
1606 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1608 index = eeprom->offset >> 24;
1609 offset = eeprom->offset & 0xffffff;
1612 netdev_err(dev, "unsupported index value: %d\n", index);
1616 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1619 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1621 struct bnxt *bp = netdev_priv(dev);
1622 struct hwrm_nvm_erase_dir_entry_input req = {0};
1624 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1625 req.dir_idx = cpu_to_le16(index);
1626 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1629 static int bnxt_set_eeprom(struct net_device *dev,
1630 struct ethtool_eeprom *eeprom,
1633 struct bnxt *bp = netdev_priv(dev);
1635 u16 type, ext, ordinal, attr;
1638 netdev_err(dev, "NVM write not supported from a virtual function\n");
1642 type = eeprom->magic >> 16;
1644 if (type == 0xffff) { /* special value for directory operations */
1645 index = eeprom->magic & 0xff;
1646 dir_op = eeprom->magic >> 8;
1650 case 0x0e: /* erase */
1651 if (eeprom->offset != ~eeprom->magic)
1653 return bnxt_erase_nvram_directory(dev, index - 1);
1659 /* Create or re-write an NVM item: */
1660 if (bnxt_dir_type_is_executable(type) == true)
1662 ext = eeprom->magic & 0xffff;
1663 ordinal = eeprom->offset >> 16;
1664 attr = eeprom->offset & 0xffff;
1666 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
1670 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1672 struct bnxt *bp = netdev_priv(dev);
1673 struct ethtool_eee *eee = &bp->eee;
1674 struct bnxt_link_info *link_info = &bp->link_info;
1678 if (!BNXT_SINGLE_PF(bp))
1681 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1684 mutex_lock(&bp->link_lock);
1685 advertising = _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
1686 if (!edata->eee_enabled)
1689 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1690 netdev_warn(dev, "EEE requires autoneg\n");
1694 if (edata->tx_lpi_enabled) {
1695 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
1696 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
1697 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
1698 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
1701 } else if (!bp->lpi_tmr_hi) {
1702 edata->tx_lpi_timer = eee->tx_lpi_timer;
1705 if (!edata->advertised) {
1706 edata->advertised = advertising & eee->supported;
1707 } else if (edata->advertised & ~advertising) {
1708 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
1709 edata->advertised, advertising);
1714 eee->advertised = edata->advertised;
1715 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
1716 eee->tx_lpi_timer = edata->tx_lpi_timer;
1718 eee->eee_enabled = edata->eee_enabled;
1720 if (netif_running(dev))
1721 rc = bnxt_hwrm_set_link_setting(bp, false, true);
1724 mutex_unlock(&bp->link_lock);
1728 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1730 struct bnxt *bp = netdev_priv(dev);
1732 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1736 if (!bp->eee.eee_enabled) {
1737 /* Preserve tx_lpi_timer so that the last value will be used
1738 * by default when it is re-enabled.
1740 edata->advertised = 0;
1741 edata->tx_lpi_enabled = 0;
1744 if (!bp->eee.eee_active)
1745 edata->lp_advertised = 0;
1750 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
1751 u16 page_number, u16 start_addr,
1752 u16 data_length, u8 *buf)
1754 struct hwrm_port_phy_i2c_read_input req = {0};
1755 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1756 int rc, byte_offset = 0;
1758 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1759 req.i2c_slave_addr = i2c_addr;
1760 req.page_number = cpu_to_le16(page_number);
1761 req.port_id = cpu_to_le16(bp->pf.port_id);
1765 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
1766 data_length -= xfer_size;
1767 req.page_offset = cpu_to_le16(start_addr + byte_offset);
1768 req.data_length = xfer_size;
1769 req.enables = cpu_to_le32(start_addr + byte_offset ?
1770 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
1771 mutex_lock(&bp->hwrm_cmd_lock);
1772 rc = _hwrm_send_message(bp, &req, sizeof(req),
1775 memcpy(buf + byte_offset, output->data, xfer_size);
1776 mutex_unlock(&bp->hwrm_cmd_lock);
1777 byte_offset += xfer_size;
1778 } while (!rc && data_length > 0);
1783 static int bnxt_get_module_info(struct net_device *dev,
1784 struct ethtool_modinfo *modinfo)
1786 struct bnxt *bp = netdev_priv(dev);
1787 struct hwrm_port_phy_i2c_read_input req = {0};
1788 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1791 /* No point in going further if phy status indicates
1792 * module is not inserted or if it is powered down or
1793 * if it is of type 10GBase-T
1795 if (bp->link_info.module_status >
1796 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
1799 /* This feature is not supported in older firmware versions */
1800 if (bp->hwrm_spec_code < 0x10202)
1803 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1804 req.i2c_slave_addr = I2C_DEV_ADDR_A0;
1805 req.page_number = 0;
1806 req.page_offset = cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR);
1807 req.data_length = SFP_EEPROM_SFF_8472_COMP_SIZE;
1808 req.port_id = cpu_to_le16(bp->pf.port_id);
1809 mutex_lock(&bp->hwrm_cmd_lock);
1810 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1812 u32 module_id = le32_to_cpu(output->data[0]);
1814 switch (module_id) {
1815 case SFF_MODULE_ID_SFP:
1816 modinfo->type = ETH_MODULE_SFF_8472;
1817 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1819 case SFF_MODULE_ID_QSFP:
1820 case SFF_MODULE_ID_QSFP_PLUS:
1821 modinfo->type = ETH_MODULE_SFF_8436;
1822 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1824 case SFF_MODULE_ID_QSFP28:
1825 modinfo->type = ETH_MODULE_SFF_8636;
1826 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1833 mutex_unlock(&bp->hwrm_cmd_lock);
1837 static int bnxt_get_module_eeprom(struct net_device *dev,
1838 struct ethtool_eeprom *eeprom,
1841 struct bnxt *bp = netdev_priv(dev);
1842 u16 start = eeprom->offset, length = eeprom->len;
1845 memset(data, 0, eeprom->len);
1847 /* Read A0 portion of the EEPROM */
1848 if (start < ETH_MODULE_SFF_8436_LEN) {
1849 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
1850 length = ETH_MODULE_SFF_8436_LEN - start;
1851 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
1852 start, length, data);
1857 length = eeprom->len - length;
1860 /* Read A2 portion of the EEPROM */
1862 start -= ETH_MODULE_SFF_8436_LEN;
1863 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 0,
1864 start, length, data);
1869 static int bnxt_nway_reset(struct net_device *dev)
1873 struct bnxt *bp = netdev_priv(dev);
1874 struct bnxt_link_info *link_info = &bp->link_info;
1876 if (!BNXT_SINGLE_PF(bp))
1879 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1882 if (netif_running(dev))
1883 rc = bnxt_hwrm_set_link_setting(bp, true, false);
1888 const struct ethtool_ops bnxt_ethtool_ops = {
1889 .get_link_ksettings = bnxt_get_link_ksettings,
1890 .set_link_ksettings = bnxt_set_link_ksettings,
1891 .get_pauseparam = bnxt_get_pauseparam,
1892 .set_pauseparam = bnxt_set_pauseparam,
1893 .get_drvinfo = bnxt_get_drvinfo,
1894 .get_coalesce = bnxt_get_coalesce,
1895 .set_coalesce = bnxt_set_coalesce,
1896 .get_msglevel = bnxt_get_msglevel,
1897 .set_msglevel = bnxt_set_msglevel,
1898 .get_sset_count = bnxt_get_sset_count,
1899 .get_strings = bnxt_get_strings,
1900 .get_ethtool_stats = bnxt_get_ethtool_stats,
1901 .set_ringparam = bnxt_set_ringparam,
1902 .get_ringparam = bnxt_get_ringparam,
1903 .get_channels = bnxt_get_channels,
1904 .set_channels = bnxt_set_channels,
1905 #ifdef CONFIG_RFS_ACCEL
1906 .get_rxnfc = bnxt_get_rxnfc,
1908 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
1909 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
1910 .get_rxfh = bnxt_get_rxfh,
1911 .flash_device = bnxt_flash_device,
1912 .get_eeprom_len = bnxt_get_eeprom_len,
1913 .get_eeprom = bnxt_get_eeprom,
1914 .set_eeprom = bnxt_set_eeprom,
1915 .get_link = bnxt_get_link,
1916 .get_eee = bnxt_get_eee,
1917 .set_eee = bnxt_set_eee,
1918 .get_module_info = bnxt_get_module_info,
1919 .get_module_eeprom = bnxt_get_module_eeprom,
1920 .nway_reset = bnxt_nway_reset