1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2015 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/ethtool.h>
11 #include <linux/interrupt.h>
12 #include <linux/pci.h>
13 #include <linux/etherdevice.h>
14 #include <linux/crc32.h>
15 #include <linux/firmware.h>
18 #include "bnxt_ethtool.h"
19 #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
20 #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
21 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
23 static u32 bnxt_get_msglevel(struct net_device *dev)
25 struct bnxt *bp = netdev_priv(dev);
27 return bp->msg_enable;
30 static void bnxt_set_msglevel(struct net_device *dev, u32 value)
32 struct bnxt *bp = netdev_priv(dev);
34 bp->msg_enable = value;
37 static int bnxt_get_coalesce(struct net_device *dev,
38 struct ethtool_coalesce *coal)
40 struct bnxt *bp = netdev_priv(dev);
42 memset(coal, 0, sizeof(*coal));
44 coal->rx_coalesce_usecs = bp->rx_coal_ticks;
45 /* 2 completion records per rx packet */
46 coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2;
47 coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq;
48 coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2;
50 coal->tx_coalesce_usecs = bp->tx_coal_ticks;
51 coal->tx_max_coalesced_frames = bp->tx_coal_bufs;
52 coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq;
53 coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq;
58 static int bnxt_set_coalesce(struct net_device *dev,
59 struct ethtool_coalesce *coal)
61 struct bnxt *bp = netdev_priv(dev);
64 bp->rx_coal_ticks = coal->rx_coalesce_usecs;
65 /* 2 completion records per rx packet */
66 bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2;
67 bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq;
68 bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2;
70 bp->tx_coal_ticks = coal->tx_coalesce_usecs;
71 bp->tx_coal_bufs = coal->tx_max_coalesced_frames;
72 bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq;
73 bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq;
75 if (netif_running(dev))
76 rc = bnxt_hwrm_set_coal(bp);
81 #define BNXT_NUM_STATS 21
83 static int bnxt_get_sset_count(struct net_device *dev, int sset)
85 struct bnxt *bp = netdev_priv(dev);
89 return BNXT_NUM_STATS * bp->cp_nr_rings;
95 static void bnxt_get_ethtool_stats(struct net_device *dev,
96 struct ethtool_stats *stats, u64 *buf)
99 struct bnxt *bp = netdev_priv(dev);
100 u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings;
101 u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
103 memset(buf, 0, buf_size);
108 for (i = 0; i < bp->cp_nr_rings; i++) {
109 struct bnxt_napi *bnapi = bp->bnapi[i];
110 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
111 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
114 for (k = 0; k < stat_fields; j++, k++)
115 buf[j] = le64_to_cpu(hw_stats[k]);
116 buf[j++] = cpr->rx_l4_csum_errors;
120 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
122 struct bnxt *bp = netdev_priv(dev);
126 /* The number of strings must match BNXT_NUM_STATS defined above. */
128 for (i = 0; i < bp->cp_nr_rings; i++) {
129 sprintf(buf, "[%d]: rx_ucast_packets", i);
130 buf += ETH_GSTRING_LEN;
131 sprintf(buf, "[%d]: rx_mcast_packets", i);
132 buf += ETH_GSTRING_LEN;
133 sprintf(buf, "[%d]: rx_bcast_packets", i);
134 buf += ETH_GSTRING_LEN;
135 sprintf(buf, "[%d]: rx_discards", i);
136 buf += ETH_GSTRING_LEN;
137 sprintf(buf, "[%d]: rx_drops", i);
138 buf += ETH_GSTRING_LEN;
139 sprintf(buf, "[%d]: rx_ucast_bytes", i);
140 buf += ETH_GSTRING_LEN;
141 sprintf(buf, "[%d]: rx_mcast_bytes", i);
142 buf += ETH_GSTRING_LEN;
143 sprintf(buf, "[%d]: rx_bcast_bytes", i);
144 buf += ETH_GSTRING_LEN;
145 sprintf(buf, "[%d]: tx_ucast_packets", i);
146 buf += ETH_GSTRING_LEN;
147 sprintf(buf, "[%d]: tx_mcast_packets", i);
148 buf += ETH_GSTRING_LEN;
149 sprintf(buf, "[%d]: tx_bcast_packets", i);
150 buf += ETH_GSTRING_LEN;
151 sprintf(buf, "[%d]: tx_discards", i);
152 buf += ETH_GSTRING_LEN;
153 sprintf(buf, "[%d]: tx_drops", i);
154 buf += ETH_GSTRING_LEN;
155 sprintf(buf, "[%d]: tx_ucast_bytes", i);
156 buf += ETH_GSTRING_LEN;
157 sprintf(buf, "[%d]: tx_mcast_bytes", i);
158 buf += ETH_GSTRING_LEN;
159 sprintf(buf, "[%d]: tx_bcast_bytes", i);
160 buf += ETH_GSTRING_LEN;
161 sprintf(buf, "[%d]: tpa_packets", i);
162 buf += ETH_GSTRING_LEN;
163 sprintf(buf, "[%d]: tpa_bytes", i);
164 buf += ETH_GSTRING_LEN;
165 sprintf(buf, "[%d]: tpa_events", i);
166 buf += ETH_GSTRING_LEN;
167 sprintf(buf, "[%d]: tpa_aborts", i);
168 buf += ETH_GSTRING_LEN;
169 sprintf(buf, "[%d]: rx_l4_csum_errors", i);
170 buf += ETH_GSTRING_LEN;
174 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
180 static void bnxt_get_ringparam(struct net_device *dev,
181 struct ethtool_ringparam *ering)
183 struct bnxt *bp = netdev_priv(dev);
185 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
186 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
187 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
189 ering->rx_pending = bp->rx_ring_size;
190 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
191 ering->tx_pending = bp->tx_ring_size;
194 static int bnxt_set_ringparam(struct net_device *dev,
195 struct ethtool_ringparam *ering)
197 struct bnxt *bp = netdev_priv(dev);
199 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
200 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
201 (ering->tx_pending <= MAX_SKB_FRAGS))
204 if (netif_running(dev))
205 bnxt_close_nic(bp, false, false);
207 bp->rx_ring_size = ering->rx_pending;
208 bp->tx_ring_size = ering->tx_pending;
209 bnxt_set_ring_params(bp);
211 if (netif_running(dev))
212 return bnxt_open_nic(bp, false, false);
217 static void bnxt_get_channels(struct net_device *dev,
218 struct ethtool_channels *channel)
220 struct bnxt *bp = netdev_priv(dev);
221 int max_rx_rings, max_tx_rings, tcs;
223 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
224 channel->max_combined = max_rx_rings;
226 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false);
227 tcs = netdev_get_num_tc(dev);
231 channel->max_rx = max_rx_rings;
232 channel->max_tx = max_tx_rings;
233 channel->max_other = 0;
234 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
235 channel->combined_count = bp->rx_nr_rings;
237 channel->rx_count = bp->rx_nr_rings;
238 channel->tx_count = bp->tx_nr_rings_per_tc;
242 static int bnxt_set_channels(struct net_device *dev,
243 struct ethtool_channels *channel)
245 struct bnxt *bp = netdev_priv(dev);
246 int max_rx_rings, max_tx_rings, tcs;
250 if (channel->other_count)
253 if (!channel->combined_count &&
254 (!channel->rx_count || !channel->tx_count))
257 if (channel->combined_count &&
258 (channel->rx_count || channel->tx_count))
261 if (channel->combined_count)
264 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh);
266 tcs = netdev_get_num_tc(dev);
270 if (sh && (channel->combined_count > max_rx_rings ||
271 channel->combined_count > max_tx_rings))
274 if (!sh && (channel->rx_count > max_rx_rings ||
275 channel->tx_count > max_tx_rings))
278 if (netif_running(dev)) {
280 /* TODO CHIMP_FW: Send message to all VF's
284 rc = bnxt_close_nic(bp, true, false);
286 netdev_err(bp->dev, "Set channel failure rc :%x\n",
293 bp->flags |= BNXT_FLAG_SHARED_RINGS;
294 bp->rx_nr_rings = channel->combined_count;
295 bp->tx_nr_rings_per_tc = channel->combined_count;
297 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
298 bp->rx_nr_rings = channel->rx_count;
299 bp->tx_nr_rings_per_tc = channel->tx_count;
302 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
304 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
306 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
307 bp->tx_nr_rings + bp->rx_nr_rings;
309 bp->num_stat_ctxs = bp->cp_nr_rings;
311 /* After changing number of rx channels, update NTUPLE feature. */
312 netdev_update_features(dev);
313 if (netif_running(dev)) {
314 rc = bnxt_open_nic(bp, true, false);
315 if ((!rc) && BNXT_PF(bp)) {
316 /* TODO CHIMP_FW: Send message to all VF's
325 #ifdef CONFIG_RFS_ACCEL
326 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
331 cmd->data = bp->ntp_fltr_count;
332 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
333 struct hlist_head *head;
334 struct bnxt_ntuple_filter *fltr;
336 head = &bp->ntp_fltr_hash_tbl[i];
338 hlist_for_each_entry_rcu(fltr, head, hash) {
339 if (j == cmd->rule_cnt)
341 rule_locs[j++] = fltr->sw_id;
344 if (j == cmd->rule_cnt)
351 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
353 struct ethtool_rx_flow_spec *fs =
354 (struct ethtool_rx_flow_spec *)&cmd->fs;
355 struct bnxt_ntuple_filter *fltr;
356 struct flow_keys *fkeys;
359 if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
362 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
363 struct hlist_head *head;
365 head = &bp->ntp_fltr_hash_tbl[i];
367 hlist_for_each_entry_rcu(fltr, head, hash) {
368 if (fltr->sw_id == fs->location)
376 fkeys = &fltr->fkeys;
377 if (fkeys->basic.ip_proto == IPPROTO_TCP)
378 fs->flow_type = TCP_V4_FLOW;
379 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
380 fs->flow_type = UDP_V4_FLOW;
384 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
385 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
387 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
388 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
390 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
391 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
393 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
394 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
396 fs->ring_cookie = fltr->rxq;
405 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
408 struct bnxt *bp = netdev_priv(dev);
412 case ETHTOOL_GRXRINGS:
413 cmd->data = bp->rx_nr_rings;
416 case ETHTOOL_GRXCLSRLCNT:
417 cmd->rule_cnt = bp->ntp_fltr_count;
418 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
421 case ETHTOOL_GRXCLSRLALL:
422 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
425 case ETHTOOL_GRXCLSRULE:
426 rc = bnxt_grxclsrule(bp, cmd);
438 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
440 return HW_HASH_INDEX_SIZE;
443 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
445 return HW_HASH_KEY_SIZE;
448 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
451 struct bnxt *bp = netdev_priv(dev);
452 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
456 *hfunc = ETH_RSS_HASH_TOP;
459 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
460 indir[i] = le16_to_cpu(vnic->rss_table[i]);
463 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
468 static void bnxt_get_drvinfo(struct net_device *dev,
469 struct ethtool_drvinfo *info)
471 struct bnxt *bp = netdev_priv(dev);
473 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
474 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
475 strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version));
476 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
477 info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
478 info->testinfo_len = BNXT_NUM_TESTS(bp);
479 /* TODO CHIMP_FW: eeprom dump details */
480 info->eedump_len = 0;
481 /* TODO CHIMP FW: reg dump details */
482 info->regdump_len = 0;
485 static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info)
487 u16 fw_speeds = link_info->support_speeds;
490 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
491 speed_mask |= SUPPORTED_100baseT_Full;
492 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
493 speed_mask |= SUPPORTED_1000baseT_Full;
494 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
495 speed_mask |= SUPPORTED_2500baseX_Full;
496 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
497 speed_mask |= SUPPORTED_10000baseT_Full;
498 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
499 speed_mask |= SUPPORTED_40000baseCR4_Full;
504 static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info)
506 u16 fw_speeds = link_info->auto_link_speeds;
509 /* TODO: support 25GB, 40GB, 50GB with different cable type */
510 /* set the advertised speeds */
511 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
512 speed_mask |= ADVERTISED_100baseT_Full;
513 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
514 speed_mask |= ADVERTISED_1000baseT_Full;
515 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
516 speed_mask |= ADVERTISED_2500baseX_Full;
517 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
518 speed_mask |= ADVERTISED_10000baseT_Full;
519 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
520 speed_mask |= ADVERTISED_40000baseCR4_Full;
524 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
526 switch (fw_link_speed) {
527 case BNXT_LINK_SPEED_100MB:
529 case BNXT_LINK_SPEED_1GB:
531 case BNXT_LINK_SPEED_2_5GB:
533 case BNXT_LINK_SPEED_10GB:
535 case BNXT_LINK_SPEED_20GB:
537 case BNXT_LINK_SPEED_25GB:
539 case BNXT_LINK_SPEED_40GB:
541 case BNXT_LINK_SPEED_50GB:
544 return SPEED_UNKNOWN;
548 static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
550 struct bnxt *bp = netdev_priv(dev);
551 struct bnxt_link_info *link_info = &bp->link_info;
554 cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info);
555 cmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
557 if (link_info->auto_link_speeds)
558 cmd->supported |= SUPPORTED_Autoneg;
560 if (link_info->autoneg) {
562 bnxt_fw_to_ethtool_advertised_spds(link_info);
563 cmd->advertising |= ADVERTISED_Autoneg;
564 cmd->autoneg = AUTONEG_ENABLE;
566 cmd->autoneg = AUTONEG_DISABLE;
567 cmd->advertising = 0;
569 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) {
570 if ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) ==
571 BNXT_LINK_PAUSE_BOTH) {
572 cmd->advertising |= ADVERTISED_Pause;
574 cmd->advertising |= ADVERTISED_Asym_Pause;
575 if (link_info->auto_pause_setting &
577 cmd->advertising |= ADVERTISED_Pause;
581 cmd->port = PORT_NONE;
582 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
584 cmd->supported |= SUPPORTED_TP;
585 cmd->advertising |= ADVERTISED_TP;
587 cmd->supported |= SUPPORTED_FIBRE;
588 cmd->advertising |= ADVERTISED_FIBRE;
590 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
592 else if (link_info->media_type ==
593 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
594 cmd->port = PORT_FIBRE;
597 if (link_info->phy_link_status == BNXT_LINK_LINK) {
598 if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
599 cmd->duplex = DUPLEX_FULL;
601 cmd->duplex = DUPLEX_UNKNOWN;
603 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
604 ethtool_cmd_speed_set(cmd, ethtool_speed);
605 if (link_info->transceiver ==
606 PORT_PHY_QCFG_RESP_TRANSCEIVER_TYPE_XCVR_INTERNAL)
607 cmd->transceiver = XCVR_INTERNAL;
609 cmd->transceiver = XCVR_EXTERNAL;
610 cmd->phy_address = link_info->phy_addr;
615 static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed)
617 switch (ethtool_speed) {
619 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
621 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
623 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
625 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
627 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
629 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
631 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
633 return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
635 netdev_err(dev, "unsupported speed!\n");
641 static u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
643 u16 fw_speed_mask = 0;
645 /* only support autoneg at speed 100, 1000, and 10000 */
646 if (advertising & (ADVERTISED_100baseT_Full |
647 ADVERTISED_100baseT_Half)) {
648 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
650 if (advertising & (ADVERTISED_1000baseT_Full |
651 ADVERTISED_1000baseT_Half)) {
652 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
654 if (advertising & ADVERTISED_10000baseT_Full)
655 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
657 if (advertising & ADVERTISED_40000baseCR4_Full)
658 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
660 return fw_speed_mask;
663 static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
666 struct bnxt *bp = netdev_priv(dev);
667 struct bnxt_link_info *link_info = &bp->link_info;
668 u32 speed, fw_advertising = 0;
669 bool set_pause = false;
674 if (cmd->autoneg == AUTONEG_ENABLE) {
675 if (link_info->media_type != PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
676 netdev_err(dev, "Media type doesn't support autoneg\n");
678 goto set_setting_exit;
680 if (cmd->advertising & ~(BNXT_ALL_COPPER_ETHTOOL_SPEED |
684 ADVERTISED_Asym_Pause)) {
685 netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n",
688 goto set_setting_exit;
690 fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising);
691 if (fw_advertising & ~link_info->support_speeds) {
692 netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n",
695 goto set_setting_exit;
697 link_info->autoneg |= BNXT_AUTONEG_SPEED;
699 link_info->advertising = link_info->support_speeds;
701 link_info->advertising = fw_advertising;
702 /* any change to autoneg will cause link change, therefore the
703 * driver should put back the original pause setting in autoneg
707 /* TODO: currently don't support half duplex */
708 if (cmd->duplex == DUPLEX_HALF) {
709 netdev_err(dev, "HALF DUPLEX is not supported!\n");
711 goto set_setting_exit;
713 /* If received a request for an unknown duplex, assume full*/
714 if (cmd->duplex == DUPLEX_UNKNOWN)
715 cmd->duplex = DUPLEX_FULL;
716 speed = ethtool_cmd_speed(cmd);
717 link_info->req_link_speed = bnxt_get_fw_speed(dev, speed);
718 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
719 link_info->autoneg = 0;
720 link_info->advertising = 0;
723 if (netif_running(dev))
724 rc = bnxt_hwrm_set_link_setting(bp, set_pause);
730 static void bnxt_get_pauseparam(struct net_device *dev,
731 struct ethtool_pauseparam *epause)
733 struct bnxt *bp = netdev_priv(dev);
734 struct bnxt_link_info *link_info = &bp->link_info;
738 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
739 epause->rx_pause = ((link_info->pause & BNXT_LINK_PAUSE_RX) != 0);
740 epause->tx_pause = ((link_info->pause & BNXT_LINK_PAUSE_TX) != 0);
743 static int bnxt_set_pauseparam(struct net_device *dev,
744 struct ethtool_pauseparam *epause)
747 struct bnxt *bp = netdev_priv(dev);
748 struct bnxt_link_info *link_info = &bp->link_info;
753 if (epause->autoneg) {
754 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
757 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
758 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_BOTH;
760 /* when transition from auto pause to force pause,
761 * force a link change
763 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
764 link_info->force_link_chng = true;
765 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
766 link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_BOTH;
768 if (epause->rx_pause)
769 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
771 link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_RX;
773 if (epause->tx_pause)
774 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
776 link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_TX;
778 if (netif_running(dev))
779 rc = bnxt_hwrm_set_pause(bp);
783 static u32 bnxt_get_link(struct net_device *dev)
785 struct bnxt *bp = netdev_priv(dev);
787 /* TODO: handle MF, VF, driver close case */
788 return bp->link_info.link_up;
791 static int bnxt_flash_nvram(struct net_device *dev,
799 struct bnxt *bp = netdev_priv(dev);
801 struct hwrm_nvm_write_input req = {0};
802 dma_addr_t dma_handle;
805 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
807 req.dir_type = cpu_to_le16(dir_type);
808 req.dir_ordinal = cpu_to_le16(dir_ordinal);
809 req.dir_ext = cpu_to_le16(dir_ext);
810 req.dir_attr = cpu_to_le16(dir_attr);
811 req.dir_data_length = cpu_to_le32(data_len);
813 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
816 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
820 memcpy(kmem, data, data_len);
821 req.host_src_addr = cpu_to_le64(dma_handle);
823 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
824 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
829 static int bnxt_firmware_reset(struct net_device *dev,
832 struct bnxt *bp = netdev_priv(dev);
833 struct hwrm_fw_reset_input req = {0};
835 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
837 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
838 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
839 /* (e.g. when firmware isn't already running) */
841 case BNX_DIR_TYPE_CHIMP_PATCH:
842 case BNX_DIR_TYPE_BOOTCODE:
843 case BNX_DIR_TYPE_BOOTCODE_2:
844 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
845 /* Self-reset ChiMP upon next PCIe reset: */
846 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
848 case BNX_DIR_TYPE_APE_FW:
849 case BNX_DIR_TYPE_APE_PATCH:
850 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
852 case BNX_DIR_TYPE_KONG_FW:
853 case BNX_DIR_TYPE_KONG_PATCH:
854 req.embedded_proc_type =
855 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
857 case BNX_DIR_TYPE_BONO_FW:
858 case BNX_DIR_TYPE_BONO_PATCH:
859 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
865 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
868 static int bnxt_flash_firmware(struct net_device *dev,
877 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
880 case BNX_DIR_TYPE_BOOTCODE:
881 case BNX_DIR_TYPE_BOOTCODE_2:
882 code_type = CODE_BOOT;
884 case BNX_DIR_TYPE_APE_FW:
885 code_type = CODE_MCTP_PASSTHRU;
888 netdev_err(dev, "Unsupported directory entry type: %u\n",
892 if (fw_size < sizeof(struct bnxt_fw_header)) {
893 netdev_err(dev, "Invalid firmware file size: %u\n",
894 (unsigned int)fw_size);
897 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
898 netdev_err(dev, "Invalid firmware signature: %08X\n",
899 le32_to_cpu(header->signature));
902 if (header->code_type != code_type) {
903 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
904 code_type, header->code_type);
907 if (header->device != DEVICE_CUMULUS_FAMILY) {
908 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
909 DEVICE_CUMULUS_FAMILY, header->device);
912 /* Confirm the CRC32 checksum of the file: */
913 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
914 sizeof(stored_crc)));
915 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
916 if (calculated_crc != stored_crc) {
917 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
918 (unsigned long)stored_crc,
919 (unsigned long)calculated_crc);
922 /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */
923 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
924 0, 0, fw_data, fw_size);
925 if (rc == 0) /* Firmware update successful */
926 rc = bnxt_firmware_reset(dev, dir_type);
931 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
934 case BNX_DIR_TYPE_CHIMP_PATCH:
935 case BNX_DIR_TYPE_BOOTCODE:
936 case BNX_DIR_TYPE_BOOTCODE_2:
937 case BNX_DIR_TYPE_APE_FW:
938 case BNX_DIR_TYPE_APE_PATCH:
939 case BNX_DIR_TYPE_KONG_FW:
940 case BNX_DIR_TYPE_KONG_PATCH:
947 static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type)
950 case BNX_DIR_TYPE_AVS:
951 case BNX_DIR_TYPE_EXP_ROM_MBA:
952 case BNX_DIR_TYPE_PCIE:
953 case BNX_DIR_TYPE_TSCF_UCODE:
954 case BNX_DIR_TYPE_EXT_PHY:
955 case BNX_DIR_TYPE_CCM:
956 case BNX_DIR_TYPE_ISCSI_BOOT:
957 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
958 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
965 static bool bnxt_dir_type_is_executable(u16 dir_type)
967 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
968 bnxt_dir_type_is_unprotected_exec_format(dir_type);
971 static int bnxt_flash_firmware_from_file(struct net_device *dev,
973 const char *filename)
975 const struct firmware *fw;
978 if (bnxt_dir_type_is_executable(dir_type) == false)
981 rc = request_firmware(&fw, filename, &dev->dev);
983 netdev_err(dev, "Error %d requesting firmware file: %s\n",
987 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
988 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
990 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
991 0, 0, fw->data, fw->size);
992 release_firmware(fw);
996 static int bnxt_flash_package_from_file(struct net_device *dev,
999 netdev_err(dev, "packages are not yet supported\n");
1003 static int bnxt_flash_device(struct net_device *dev,
1004 struct ethtool_flash *flash)
1006 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1007 netdev_err(dev, "flashdev not supported from a virtual function\n");
1011 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS)
1012 return bnxt_flash_package_from_file(dev, flash->data);
1014 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1017 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1019 struct bnxt *bp = netdev_priv(dev);
1021 struct hwrm_nvm_get_dir_info_input req = {0};
1022 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1024 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1026 mutex_lock(&bp->hwrm_cmd_lock);
1027 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1029 *entries = le32_to_cpu(output->entries);
1030 *length = le32_to_cpu(output->entry_length);
1032 mutex_unlock(&bp->hwrm_cmd_lock);
1036 static int bnxt_get_eeprom_len(struct net_device *dev)
1038 /* The -1 return value allows the entire 32-bit range of offsets to be
1039 * passed via the ethtool command-line utility.
1044 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1046 struct bnxt *bp = netdev_priv(dev);
1052 dma_addr_t dma_handle;
1053 struct hwrm_nvm_get_dir_entries_input req = {0};
1055 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1059 /* Insert 2 bytes of directory info (count and size of entries) */
1063 *data++ = dir_entries;
1064 *data++ = entry_length;
1066 memset(data, 0xff, len);
1068 buflen = dir_entries * entry_length;
1069 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1072 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1076 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1077 req.host_dest_addr = cpu_to_le64(dma_handle);
1078 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1080 memcpy(data, buf, len > buflen ? buflen : len);
1081 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1085 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1086 u32 length, u8 *data)
1088 struct bnxt *bp = netdev_priv(dev);
1091 dma_addr_t dma_handle;
1092 struct hwrm_nvm_read_input req = {0};
1094 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1097 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1101 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1102 req.host_dest_addr = cpu_to_le64(dma_handle);
1103 req.dir_idx = cpu_to_le16(index);
1104 req.offset = cpu_to_le32(offset);
1105 req.len = cpu_to_le32(length);
1107 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1109 memcpy(data, buf, length);
1110 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1114 static int bnxt_get_eeprom(struct net_device *dev,
1115 struct ethtool_eeprom *eeprom,
1121 if (eeprom->offset == 0) /* special offset value to get directory */
1122 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1124 index = eeprom->offset >> 24;
1125 offset = eeprom->offset & 0xffffff;
1128 netdev_err(dev, "unsupported index value: %d\n", index);
1132 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1135 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1137 struct bnxt *bp = netdev_priv(dev);
1138 struct hwrm_nvm_erase_dir_entry_input req = {0};
1140 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1141 req.dir_idx = cpu_to_le16(index);
1142 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1145 static int bnxt_set_eeprom(struct net_device *dev,
1146 struct ethtool_eeprom *eeprom,
1149 struct bnxt *bp = netdev_priv(dev);
1151 u16 type, ext, ordinal, attr;
1154 netdev_err(dev, "NVM write not supported from a virtual function\n");
1158 type = eeprom->magic >> 16;
1160 if (type == 0xffff) { /* special value for directory operations */
1161 index = eeprom->magic & 0xff;
1162 dir_op = eeprom->magic >> 8;
1166 case 0x0e: /* erase */
1167 if (eeprom->offset != ~eeprom->magic)
1169 return bnxt_erase_nvram_directory(dev, index - 1);
1175 /* Create or re-write an NVM item: */
1176 if (bnxt_dir_type_is_executable(type) == true)
1178 ext = eeprom->magic & 0xffff;
1179 ordinal = eeprom->offset >> 16;
1180 attr = eeprom->offset & 0xffff;
1182 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
1186 const struct ethtool_ops bnxt_ethtool_ops = {
1187 .get_settings = bnxt_get_settings,
1188 .set_settings = bnxt_set_settings,
1189 .get_pauseparam = bnxt_get_pauseparam,
1190 .set_pauseparam = bnxt_set_pauseparam,
1191 .get_drvinfo = bnxt_get_drvinfo,
1192 .get_coalesce = bnxt_get_coalesce,
1193 .set_coalesce = bnxt_set_coalesce,
1194 .get_msglevel = bnxt_get_msglevel,
1195 .set_msglevel = bnxt_set_msglevel,
1196 .get_sset_count = bnxt_get_sset_count,
1197 .get_strings = bnxt_get_strings,
1198 .get_ethtool_stats = bnxt_get_ethtool_stats,
1199 .set_ringparam = bnxt_set_ringparam,
1200 .get_ringparam = bnxt_get_ringparam,
1201 .get_channels = bnxt_get_channels,
1202 .set_channels = bnxt_set_channels,
1203 #ifdef CONFIG_RFS_ACCEL
1204 .get_rxnfc = bnxt_get_rxnfc,
1206 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
1207 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
1208 .get_rxfh = bnxt_get_rxfh,
1209 .flash_device = bnxt_flash_device,
1210 .get_eeprom_len = bnxt_get_eeprom_len,
1211 .get_eeprom = bnxt_get_eeprom,
1212 .set_eeprom = bnxt_set_eeprom,
1213 .get_link = bnxt_get_link,