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 if (bp->hwrm_spec_code >= 0x10201)
1012 link_info->req_flow_ctrl =
1013 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
1015 /* when transition from auto pause to force pause,
1016 * force a link change
1018 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1019 link_info->force_link_chng = true;
1020 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1021 link_info->req_flow_ctrl = 0;
1023 if (epause->rx_pause)
1024 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1026 if (epause->tx_pause)
1027 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1029 if (netif_running(dev))
1030 rc = bnxt_hwrm_set_pause(bp);
1033 mutex_unlock(&bp->link_lock);
1037 static u32 bnxt_get_link(struct net_device *dev)
1039 struct bnxt *bp = netdev_priv(dev);
1041 /* TODO: handle MF, VF, driver close case */
1042 return bp->link_info.link_up;
1045 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1046 u16 ext, u16 *index, u32 *item_length,
1049 static int bnxt_flash_nvram(struct net_device *dev,
1057 struct bnxt *bp = netdev_priv(dev);
1059 struct hwrm_nvm_write_input req = {0};
1060 dma_addr_t dma_handle;
1063 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1065 req.dir_type = cpu_to_le16(dir_type);
1066 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1067 req.dir_ext = cpu_to_le16(dir_ext);
1068 req.dir_attr = cpu_to_le16(dir_attr);
1069 req.dir_data_length = cpu_to_le32(data_len);
1071 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1074 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1075 (unsigned)data_len);
1078 memcpy(kmem, data, data_len);
1079 req.host_src_addr = cpu_to_le64(dma_handle);
1081 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1082 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1087 static int bnxt_firmware_reset(struct net_device *dev,
1090 struct bnxt *bp = netdev_priv(dev);
1091 struct hwrm_fw_reset_input req = {0};
1093 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1095 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1096 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1097 /* (e.g. when firmware isn't already running) */
1099 case BNX_DIR_TYPE_CHIMP_PATCH:
1100 case BNX_DIR_TYPE_BOOTCODE:
1101 case BNX_DIR_TYPE_BOOTCODE_2:
1102 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1103 /* Self-reset ChiMP upon next PCIe reset: */
1104 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1106 case BNX_DIR_TYPE_APE_FW:
1107 case BNX_DIR_TYPE_APE_PATCH:
1108 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1109 /* Self-reset APE upon next PCIe reset: */
1110 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1112 case BNX_DIR_TYPE_KONG_FW:
1113 case BNX_DIR_TYPE_KONG_PATCH:
1114 req.embedded_proc_type =
1115 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1117 case BNX_DIR_TYPE_BONO_FW:
1118 case BNX_DIR_TYPE_BONO_PATCH:
1119 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1125 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1128 static int bnxt_flash_firmware(struct net_device *dev,
1137 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1140 case BNX_DIR_TYPE_BOOTCODE:
1141 case BNX_DIR_TYPE_BOOTCODE_2:
1142 code_type = CODE_BOOT;
1144 case BNX_DIR_TYPE_CHIMP_PATCH:
1145 code_type = CODE_CHIMP_PATCH;
1147 case BNX_DIR_TYPE_APE_FW:
1148 code_type = CODE_MCTP_PASSTHRU;
1150 case BNX_DIR_TYPE_APE_PATCH:
1151 code_type = CODE_APE_PATCH;
1153 case BNX_DIR_TYPE_KONG_FW:
1154 code_type = CODE_KONG_FW;
1156 case BNX_DIR_TYPE_KONG_PATCH:
1157 code_type = CODE_KONG_PATCH;
1159 case BNX_DIR_TYPE_BONO_FW:
1160 code_type = CODE_BONO_FW;
1162 case BNX_DIR_TYPE_BONO_PATCH:
1163 code_type = CODE_BONO_PATCH;
1166 netdev_err(dev, "Unsupported directory entry type: %u\n",
1170 if (fw_size < sizeof(struct bnxt_fw_header)) {
1171 netdev_err(dev, "Invalid firmware file size: %u\n",
1172 (unsigned int)fw_size);
1175 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1176 netdev_err(dev, "Invalid firmware signature: %08X\n",
1177 le32_to_cpu(header->signature));
1180 if (header->code_type != code_type) {
1181 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1182 code_type, header->code_type);
1185 if (header->device != DEVICE_CUMULUS_FAMILY) {
1186 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1187 DEVICE_CUMULUS_FAMILY, header->device);
1190 /* Confirm the CRC32 checksum of the file: */
1191 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1192 sizeof(stored_crc)));
1193 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1194 if (calculated_crc != stored_crc) {
1195 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1196 (unsigned long)stored_crc,
1197 (unsigned long)calculated_crc);
1200 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1201 0, 0, fw_data, fw_size);
1202 if (rc == 0) /* Firmware update successful */
1203 rc = bnxt_firmware_reset(dev, dir_type);
1208 static int bnxt_flash_microcode(struct net_device *dev,
1213 struct bnxt_ucode_trailer *trailer;
1218 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1219 netdev_err(dev, "Invalid microcode file size: %u\n",
1220 (unsigned int)fw_size);
1223 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1225 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1226 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1227 le32_to_cpu(trailer->sig));
1230 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1231 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1232 dir_type, le16_to_cpu(trailer->dir_type));
1235 if (le16_to_cpu(trailer->trailer_length) <
1236 sizeof(struct bnxt_ucode_trailer)) {
1237 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1238 le16_to_cpu(trailer->trailer_length));
1242 /* Confirm the CRC32 checksum of the file: */
1243 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1244 sizeof(stored_crc)));
1245 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1246 if (calculated_crc != stored_crc) {
1248 "CRC32 (%08lX) does not match calculated: %08lX\n",
1249 (unsigned long)stored_crc,
1250 (unsigned long)calculated_crc);
1253 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1254 0, 0, fw_data, fw_size);
1259 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1262 case BNX_DIR_TYPE_CHIMP_PATCH:
1263 case BNX_DIR_TYPE_BOOTCODE:
1264 case BNX_DIR_TYPE_BOOTCODE_2:
1265 case BNX_DIR_TYPE_APE_FW:
1266 case BNX_DIR_TYPE_APE_PATCH:
1267 case BNX_DIR_TYPE_KONG_FW:
1268 case BNX_DIR_TYPE_KONG_PATCH:
1269 case BNX_DIR_TYPE_BONO_FW:
1270 case BNX_DIR_TYPE_BONO_PATCH:
1277 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1280 case BNX_DIR_TYPE_AVS:
1281 case BNX_DIR_TYPE_EXP_ROM_MBA:
1282 case BNX_DIR_TYPE_PCIE:
1283 case BNX_DIR_TYPE_TSCF_UCODE:
1284 case BNX_DIR_TYPE_EXT_PHY:
1285 case BNX_DIR_TYPE_CCM:
1286 case BNX_DIR_TYPE_ISCSI_BOOT:
1287 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1288 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1295 static bool bnxt_dir_type_is_executable(u16 dir_type)
1297 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1298 bnxt_dir_type_is_other_exec_format(dir_type);
1301 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1303 const char *filename)
1305 const struct firmware *fw;
1308 rc = request_firmware(&fw, filename, &dev->dev);
1310 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1314 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1315 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1316 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1317 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1319 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1320 0, 0, fw->data, fw->size);
1321 release_firmware(fw);
1325 static int bnxt_flash_package_from_file(struct net_device *dev,
1326 char *filename, u32 install_type)
1328 struct bnxt *bp = netdev_priv(dev);
1329 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
1330 struct hwrm_nvm_install_update_input install = {0};
1331 const struct firmware *fw;
1336 bnxt_hwrm_fw_set_time(bp);
1338 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
1339 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1340 &index, &item_len, NULL) != 0) {
1341 netdev_err(dev, "PKG update area not created in nvram\n");
1345 rc = request_firmware(&fw, filename, &dev->dev);
1347 netdev_err(dev, "PKG error %d requesting file: %s\n",
1352 if (fw->size > item_len) {
1353 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
1354 (unsigned long)fw->size);
1357 dma_addr_t dma_handle;
1359 struct hwrm_nvm_modify_input modify = {0};
1361 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
1363 modify.dir_idx = cpu_to_le16(index);
1364 modify.len = cpu_to_le32(fw->size);
1366 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
1367 &dma_handle, GFP_KERNEL);
1370 "dma_alloc_coherent failure, length = %u\n",
1371 (unsigned int)fw->size);
1374 memcpy(kmem, fw->data, fw->size);
1375 modify.host_src_addr = cpu_to_le64(dma_handle);
1377 rc = hwrm_send_message(bp, &modify, sizeof(modify),
1378 FLASH_PACKAGE_TIMEOUT);
1379 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
1383 release_firmware(fw);
1387 if ((install_type & 0xffff) == 0)
1388 install_type >>= 16;
1389 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
1390 install.install_type = cpu_to_le32(install_type);
1392 rc = hwrm_send_message(bp, &install, sizeof(install),
1393 INSTALL_PACKAGE_TIMEOUT);
1398 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
1399 (s8)resp->result, (int)resp->problem_item);
1405 static int bnxt_flash_device(struct net_device *dev,
1406 struct ethtool_flash *flash)
1408 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1409 netdev_err(dev, "flashdev not supported from a virtual function\n");
1413 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
1414 flash->region > 0xffff)
1415 return bnxt_flash_package_from_file(dev, flash->data,
1418 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1421 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1423 struct bnxt *bp = netdev_priv(dev);
1425 struct hwrm_nvm_get_dir_info_input req = {0};
1426 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1428 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1430 mutex_lock(&bp->hwrm_cmd_lock);
1431 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1433 *entries = le32_to_cpu(output->entries);
1434 *length = le32_to_cpu(output->entry_length);
1436 mutex_unlock(&bp->hwrm_cmd_lock);
1440 static int bnxt_get_eeprom_len(struct net_device *dev)
1442 /* The -1 return value allows the entire 32-bit range of offsets to be
1443 * passed via the ethtool command-line utility.
1448 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1450 struct bnxt *bp = netdev_priv(dev);
1456 dma_addr_t dma_handle;
1457 struct hwrm_nvm_get_dir_entries_input req = {0};
1459 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1463 if (!dir_entries || !entry_length)
1466 /* Insert 2 bytes of directory info (count and size of entries) */
1470 *data++ = dir_entries;
1471 *data++ = entry_length;
1473 memset(data, 0xff, len);
1475 buflen = dir_entries * entry_length;
1476 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1479 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1483 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1484 req.host_dest_addr = cpu_to_le64(dma_handle);
1485 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1487 memcpy(data, buf, len > buflen ? buflen : len);
1488 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1492 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1493 u32 length, u8 *data)
1495 struct bnxt *bp = netdev_priv(dev);
1498 dma_addr_t dma_handle;
1499 struct hwrm_nvm_read_input req = {0};
1501 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1504 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1508 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1509 req.host_dest_addr = cpu_to_le64(dma_handle);
1510 req.dir_idx = cpu_to_le16(index);
1511 req.offset = cpu_to_le32(offset);
1512 req.len = cpu_to_le32(length);
1514 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1516 memcpy(data, buf, length);
1517 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1521 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1522 u16 ext, u16 *index, u32 *item_length,
1525 struct bnxt *bp = netdev_priv(dev);
1527 struct hwrm_nvm_find_dir_entry_input req = {0};
1528 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
1530 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
1533 req.dir_type = cpu_to_le16(type);
1534 req.dir_ordinal = cpu_to_le16(ordinal);
1535 req.dir_ext = cpu_to_le16(ext);
1536 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
1537 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1540 *index = le16_to_cpu(output->dir_idx);
1542 *item_length = le32_to_cpu(output->dir_item_length);
1544 *data_length = le32_to_cpu(output->dir_data_length);
1549 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
1551 char *retval = NULL;
1558 /* null-terminate the log data (removing last '\n'): */
1559 data[datalen - 1] = 0;
1560 for (p = data; *p != 0; p++) {
1563 while (*p != 0 && *p != '\n') {
1565 while (*p != 0 && *p != '\t' && *p != '\n')
1567 if (field == desired_field)
1582 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen)
1587 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
1588 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1589 &index, NULL, &datalen) != 0)
1592 memset(buf, 0, buflen);
1593 if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0)
1596 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf,
1600 static int bnxt_get_eeprom(struct net_device *dev,
1601 struct ethtool_eeprom *eeprom,
1607 if (eeprom->offset == 0) /* special offset value to get directory */
1608 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1610 index = eeprom->offset >> 24;
1611 offset = eeprom->offset & 0xffffff;
1614 netdev_err(dev, "unsupported index value: %d\n", index);
1618 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1621 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1623 struct bnxt *bp = netdev_priv(dev);
1624 struct hwrm_nvm_erase_dir_entry_input req = {0};
1626 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1627 req.dir_idx = cpu_to_le16(index);
1628 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1631 static int bnxt_set_eeprom(struct net_device *dev,
1632 struct ethtool_eeprom *eeprom,
1635 struct bnxt *bp = netdev_priv(dev);
1637 u16 type, ext, ordinal, attr;
1640 netdev_err(dev, "NVM write not supported from a virtual function\n");
1644 type = eeprom->magic >> 16;
1646 if (type == 0xffff) { /* special value for directory operations */
1647 index = eeprom->magic & 0xff;
1648 dir_op = eeprom->magic >> 8;
1652 case 0x0e: /* erase */
1653 if (eeprom->offset != ~eeprom->magic)
1655 return bnxt_erase_nvram_directory(dev, index - 1);
1661 /* Create or re-write an NVM item: */
1662 if (bnxt_dir_type_is_executable(type) == true)
1664 ext = eeprom->magic & 0xffff;
1665 ordinal = eeprom->offset >> 16;
1666 attr = eeprom->offset & 0xffff;
1668 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
1672 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1674 struct bnxt *bp = netdev_priv(dev);
1675 struct ethtool_eee *eee = &bp->eee;
1676 struct bnxt_link_info *link_info = &bp->link_info;
1680 if (!BNXT_SINGLE_PF(bp))
1683 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1686 mutex_lock(&bp->link_lock);
1687 advertising = _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
1688 if (!edata->eee_enabled)
1691 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1692 netdev_warn(dev, "EEE requires autoneg\n");
1696 if (edata->tx_lpi_enabled) {
1697 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
1698 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
1699 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
1700 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
1703 } else if (!bp->lpi_tmr_hi) {
1704 edata->tx_lpi_timer = eee->tx_lpi_timer;
1707 if (!edata->advertised) {
1708 edata->advertised = advertising & eee->supported;
1709 } else if (edata->advertised & ~advertising) {
1710 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
1711 edata->advertised, advertising);
1716 eee->advertised = edata->advertised;
1717 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
1718 eee->tx_lpi_timer = edata->tx_lpi_timer;
1720 eee->eee_enabled = edata->eee_enabled;
1722 if (netif_running(dev))
1723 rc = bnxt_hwrm_set_link_setting(bp, false, true);
1726 mutex_unlock(&bp->link_lock);
1730 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1732 struct bnxt *bp = netdev_priv(dev);
1734 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1738 if (!bp->eee.eee_enabled) {
1739 /* Preserve tx_lpi_timer so that the last value will be used
1740 * by default when it is re-enabled.
1742 edata->advertised = 0;
1743 edata->tx_lpi_enabled = 0;
1746 if (!bp->eee.eee_active)
1747 edata->lp_advertised = 0;
1752 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
1753 u16 page_number, u16 start_addr,
1754 u16 data_length, u8 *buf)
1756 struct hwrm_port_phy_i2c_read_input req = {0};
1757 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1758 int rc, byte_offset = 0;
1760 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1761 req.i2c_slave_addr = i2c_addr;
1762 req.page_number = cpu_to_le16(page_number);
1763 req.port_id = cpu_to_le16(bp->pf.port_id);
1767 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
1768 data_length -= xfer_size;
1769 req.page_offset = cpu_to_le16(start_addr + byte_offset);
1770 req.data_length = xfer_size;
1771 req.enables = cpu_to_le32(start_addr + byte_offset ?
1772 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
1773 mutex_lock(&bp->hwrm_cmd_lock);
1774 rc = _hwrm_send_message(bp, &req, sizeof(req),
1777 memcpy(buf + byte_offset, output->data, xfer_size);
1778 mutex_unlock(&bp->hwrm_cmd_lock);
1779 byte_offset += xfer_size;
1780 } while (!rc && data_length > 0);
1785 static int bnxt_get_module_info(struct net_device *dev,
1786 struct ethtool_modinfo *modinfo)
1788 struct bnxt *bp = netdev_priv(dev);
1789 struct hwrm_port_phy_i2c_read_input req = {0};
1790 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1793 /* No point in going further if phy status indicates
1794 * module is not inserted or if it is powered down or
1795 * if it is of type 10GBase-T
1797 if (bp->link_info.module_status >
1798 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
1801 /* This feature is not supported in older firmware versions */
1802 if (bp->hwrm_spec_code < 0x10202)
1805 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1806 req.i2c_slave_addr = I2C_DEV_ADDR_A0;
1807 req.page_number = 0;
1808 req.page_offset = cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR);
1809 req.data_length = SFP_EEPROM_SFF_8472_COMP_SIZE;
1810 req.port_id = cpu_to_le16(bp->pf.port_id);
1811 mutex_lock(&bp->hwrm_cmd_lock);
1812 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1814 u32 module_id = le32_to_cpu(output->data[0]);
1816 switch (module_id) {
1817 case SFF_MODULE_ID_SFP:
1818 modinfo->type = ETH_MODULE_SFF_8472;
1819 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1821 case SFF_MODULE_ID_QSFP:
1822 case SFF_MODULE_ID_QSFP_PLUS:
1823 modinfo->type = ETH_MODULE_SFF_8436;
1824 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1826 case SFF_MODULE_ID_QSFP28:
1827 modinfo->type = ETH_MODULE_SFF_8636;
1828 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1835 mutex_unlock(&bp->hwrm_cmd_lock);
1839 static int bnxt_get_module_eeprom(struct net_device *dev,
1840 struct ethtool_eeprom *eeprom,
1843 struct bnxt *bp = netdev_priv(dev);
1844 u16 start = eeprom->offset, length = eeprom->len;
1847 memset(data, 0, eeprom->len);
1849 /* Read A0 portion of the EEPROM */
1850 if (start < ETH_MODULE_SFF_8436_LEN) {
1851 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
1852 length = ETH_MODULE_SFF_8436_LEN - start;
1853 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
1854 start, length, data);
1859 length = eeprom->len - length;
1862 /* Read A2 portion of the EEPROM */
1864 start -= ETH_MODULE_SFF_8436_LEN;
1865 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 0,
1866 start, length, data);
1871 static int bnxt_nway_reset(struct net_device *dev)
1875 struct bnxt *bp = netdev_priv(dev);
1876 struct bnxt_link_info *link_info = &bp->link_info;
1878 if (!BNXT_SINGLE_PF(bp))
1881 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1884 if (netif_running(dev))
1885 rc = bnxt_hwrm_set_link_setting(bp, true, false);
1890 const struct ethtool_ops bnxt_ethtool_ops = {
1891 .get_link_ksettings = bnxt_get_link_ksettings,
1892 .set_link_ksettings = bnxt_set_link_ksettings,
1893 .get_pauseparam = bnxt_get_pauseparam,
1894 .set_pauseparam = bnxt_set_pauseparam,
1895 .get_drvinfo = bnxt_get_drvinfo,
1896 .get_coalesce = bnxt_get_coalesce,
1897 .set_coalesce = bnxt_set_coalesce,
1898 .get_msglevel = bnxt_get_msglevel,
1899 .set_msglevel = bnxt_set_msglevel,
1900 .get_sset_count = bnxt_get_sset_count,
1901 .get_strings = bnxt_get_strings,
1902 .get_ethtool_stats = bnxt_get_ethtool_stats,
1903 .set_ringparam = bnxt_set_ringparam,
1904 .get_ringparam = bnxt_get_ringparam,
1905 .get_channels = bnxt_get_channels,
1906 .set_channels = bnxt_set_channels,
1907 #ifdef CONFIG_RFS_ACCEL
1908 .get_rxnfc = bnxt_get_rxnfc,
1910 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
1911 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
1912 .get_rxfh = bnxt_get_rxfh,
1913 .flash_device = bnxt_flash_device,
1914 .get_eeprom_len = bnxt_get_eeprom_len,
1915 .get_eeprom = bnxt_get_eeprom,
1916 .set_eeprom = bnxt_set_eeprom,
1917 .get_link = bnxt_get_link,
1918 .get_eee = bnxt_get_eee,
1919 .set_eee = bnxt_set_eee,
1920 .get_module_info = bnxt_get_module_info,
1921 .get_module_eeprom = bnxt_get_module_eeprom,
1922 .nway_reset = bnxt_nway_reset