1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
4 * Copyright (c) 2016-2017 Broadcom Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
11 #include <linux/ctype.h>
12 #include <linux/stringify.h>
13 #include <linux/ethtool.h>
14 #include <linux/interrupt.h>
15 #include <linux/pci.h>
16 #include <linux/etherdevice.h>
17 #include <linux/crc32.h>
18 #include <linux/firmware.h>
22 #include "bnxt_ethtool.h"
23 #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
24 #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
25 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
26 #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
27 #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
29 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen);
31 static u32 bnxt_get_msglevel(struct net_device *dev)
33 struct bnxt *bp = netdev_priv(dev);
35 return bp->msg_enable;
38 static void bnxt_set_msglevel(struct net_device *dev, u32 value)
40 struct bnxt *bp = netdev_priv(dev);
42 bp->msg_enable = value;
45 static int bnxt_get_coalesce(struct net_device *dev,
46 struct ethtool_coalesce *coal)
48 struct bnxt *bp = netdev_priv(dev);
50 memset(coal, 0, sizeof(*coal));
52 coal->rx_coalesce_usecs = bp->rx_coal_ticks;
53 /* 2 completion records per rx packet */
54 coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2;
55 coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq;
56 coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2;
58 coal->tx_coalesce_usecs = bp->tx_coal_ticks;
59 coal->tx_max_coalesced_frames = bp->tx_coal_bufs;
60 coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq;
61 coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq;
63 coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
68 static int bnxt_set_coalesce(struct net_device *dev,
69 struct ethtool_coalesce *coal)
71 struct bnxt *bp = netdev_priv(dev);
72 bool update_stats = false;
75 bp->rx_coal_ticks = coal->rx_coalesce_usecs;
76 /* 2 completion records per rx packet */
77 bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2;
78 bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq;
79 bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2;
81 bp->tx_coal_ticks = coal->tx_coalesce_usecs;
82 bp->tx_coal_bufs = coal->tx_max_coalesced_frames;
83 bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq;
84 bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq;
86 if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
87 u32 stats_ticks = coal->stats_block_coalesce_usecs;
89 /* Allow 0, which means disable. */
91 stats_ticks = clamp_t(u32, stats_ticks,
92 BNXT_MIN_STATS_COAL_TICKS,
93 BNXT_MAX_STATS_COAL_TICKS);
94 stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
95 bp->stats_coal_ticks = stats_ticks;
99 if (netif_running(dev)) {
101 rc = bnxt_close_nic(bp, true, false);
103 rc = bnxt_open_nic(bp, true, false);
105 rc = bnxt_hwrm_set_coal(bp);
112 #define BNXT_NUM_STATS 21
114 #define BNXT_RX_STATS_ENTRY(counter) \
115 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
117 #define BNXT_TX_STATS_ENTRY(counter) \
118 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
120 static const struct {
122 char string[ETH_GSTRING_LEN];
123 } bnxt_port_stats_arr[] = {
124 BNXT_RX_STATS_ENTRY(rx_64b_frames),
125 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
126 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
127 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
128 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
129 BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames),
130 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
131 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
132 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
133 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
134 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
135 BNXT_RX_STATS_ENTRY(rx_total_frames),
136 BNXT_RX_STATS_ENTRY(rx_ucast_frames),
137 BNXT_RX_STATS_ENTRY(rx_mcast_frames),
138 BNXT_RX_STATS_ENTRY(rx_bcast_frames),
139 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
140 BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
141 BNXT_RX_STATS_ENTRY(rx_pause_frames),
142 BNXT_RX_STATS_ENTRY(rx_pfc_frames),
143 BNXT_RX_STATS_ENTRY(rx_align_err_frames),
144 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
145 BNXT_RX_STATS_ENTRY(rx_jbr_frames),
146 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
147 BNXT_RX_STATS_ENTRY(rx_tagged_frames),
148 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
149 BNXT_RX_STATS_ENTRY(rx_good_frames),
150 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0),
151 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1),
152 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2),
153 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3),
154 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4),
155 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5),
156 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6),
157 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7),
158 BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
159 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
160 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
161 BNXT_RX_STATS_ENTRY(rx_bytes),
162 BNXT_RX_STATS_ENTRY(rx_runt_bytes),
163 BNXT_RX_STATS_ENTRY(rx_runt_frames),
165 BNXT_TX_STATS_ENTRY(tx_64b_frames),
166 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
167 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
168 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
169 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
170 BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames),
171 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
172 BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames),
173 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
174 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
175 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
176 BNXT_TX_STATS_ENTRY(tx_good_frames),
177 BNXT_TX_STATS_ENTRY(tx_total_frames),
178 BNXT_TX_STATS_ENTRY(tx_ucast_frames),
179 BNXT_TX_STATS_ENTRY(tx_mcast_frames),
180 BNXT_TX_STATS_ENTRY(tx_bcast_frames),
181 BNXT_TX_STATS_ENTRY(tx_pause_frames),
182 BNXT_TX_STATS_ENTRY(tx_pfc_frames),
183 BNXT_TX_STATS_ENTRY(tx_jabber_frames),
184 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
185 BNXT_TX_STATS_ENTRY(tx_err),
186 BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
187 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0),
188 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1),
189 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2),
190 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3),
191 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4),
192 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5),
193 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6),
194 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7),
195 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
196 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
197 BNXT_TX_STATS_ENTRY(tx_total_collisions),
198 BNXT_TX_STATS_ENTRY(tx_bytes),
201 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
203 static int bnxt_get_num_stats(struct bnxt *bp)
205 int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
207 if (bp->flags & BNXT_FLAG_PORT_STATS)
208 num_stats += BNXT_NUM_PORT_STATS;
213 static int bnxt_get_sset_count(struct net_device *dev, int sset)
215 struct bnxt *bp = netdev_priv(dev);
219 return bnxt_get_num_stats(bp);
223 return bp->num_tests;
229 static void bnxt_get_ethtool_stats(struct net_device *dev,
230 struct ethtool_stats *stats, u64 *buf)
233 struct bnxt *bp = netdev_priv(dev);
234 u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
239 for (i = 0; i < bp->cp_nr_rings; i++) {
240 struct bnxt_napi *bnapi = bp->bnapi[i];
241 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
242 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
245 for (k = 0; k < stat_fields; j++, k++)
246 buf[j] = le64_to_cpu(hw_stats[k]);
247 buf[j++] = cpr->rx_l4_csum_errors;
249 if (bp->flags & BNXT_FLAG_PORT_STATS) {
250 __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
252 for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
253 buf[j] = le64_to_cpu(*(port_stats +
254 bnxt_port_stats_arr[i].offset));
259 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
261 struct bnxt *bp = netdev_priv(dev);
265 /* The number of strings must match BNXT_NUM_STATS defined above. */
267 for (i = 0; i < bp->cp_nr_rings; i++) {
268 sprintf(buf, "[%d]: rx_ucast_packets", i);
269 buf += ETH_GSTRING_LEN;
270 sprintf(buf, "[%d]: rx_mcast_packets", i);
271 buf += ETH_GSTRING_LEN;
272 sprintf(buf, "[%d]: rx_bcast_packets", i);
273 buf += ETH_GSTRING_LEN;
274 sprintf(buf, "[%d]: rx_discards", i);
275 buf += ETH_GSTRING_LEN;
276 sprintf(buf, "[%d]: rx_drops", i);
277 buf += ETH_GSTRING_LEN;
278 sprintf(buf, "[%d]: rx_ucast_bytes", i);
279 buf += ETH_GSTRING_LEN;
280 sprintf(buf, "[%d]: rx_mcast_bytes", i);
281 buf += ETH_GSTRING_LEN;
282 sprintf(buf, "[%d]: rx_bcast_bytes", i);
283 buf += ETH_GSTRING_LEN;
284 sprintf(buf, "[%d]: tx_ucast_packets", i);
285 buf += ETH_GSTRING_LEN;
286 sprintf(buf, "[%d]: tx_mcast_packets", i);
287 buf += ETH_GSTRING_LEN;
288 sprintf(buf, "[%d]: tx_bcast_packets", i);
289 buf += ETH_GSTRING_LEN;
290 sprintf(buf, "[%d]: tx_discards", i);
291 buf += ETH_GSTRING_LEN;
292 sprintf(buf, "[%d]: tx_drops", i);
293 buf += ETH_GSTRING_LEN;
294 sprintf(buf, "[%d]: tx_ucast_bytes", i);
295 buf += ETH_GSTRING_LEN;
296 sprintf(buf, "[%d]: tx_mcast_bytes", i);
297 buf += ETH_GSTRING_LEN;
298 sprintf(buf, "[%d]: tx_bcast_bytes", i);
299 buf += ETH_GSTRING_LEN;
300 sprintf(buf, "[%d]: tpa_packets", i);
301 buf += ETH_GSTRING_LEN;
302 sprintf(buf, "[%d]: tpa_bytes", i);
303 buf += ETH_GSTRING_LEN;
304 sprintf(buf, "[%d]: tpa_events", i);
305 buf += ETH_GSTRING_LEN;
306 sprintf(buf, "[%d]: tpa_aborts", i);
307 buf += ETH_GSTRING_LEN;
308 sprintf(buf, "[%d]: rx_l4_csum_errors", i);
309 buf += ETH_GSTRING_LEN;
311 if (bp->flags & BNXT_FLAG_PORT_STATS) {
312 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
313 strcpy(buf, bnxt_port_stats_arr[i].string);
314 buf += ETH_GSTRING_LEN;
320 memcpy(buf, bp->test_info->string,
321 bp->num_tests * ETH_GSTRING_LEN);
324 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
330 static void bnxt_get_ringparam(struct net_device *dev,
331 struct ethtool_ringparam *ering)
333 struct bnxt *bp = netdev_priv(dev);
335 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
336 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
337 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
339 ering->rx_pending = bp->rx_ring_size;
340 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
341 ering->tx_pending = bp->tx_ring_size;
344 static int bnxt_set_ringparam(struct net_device *dev,
345 struct ethtool_ringparam *ering)
347 struct bnxt *bp = netdev_priv(dev);
349 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
350 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
351 (ering->tx_pending < BNXT_MIN_TX_DESC_CNT))
354 if (netif_running(dev))
355 bnxt_close_nic(bp, false, false);
357 bp->rx_ring_size = ering->rx_pending;
358 bp->tx_ring_size = ering->tx_pending;
359 bnxt_set_ring_params(bp);
361 if (netif_running(dev))
362 return bnxt_open_nic(bp, false, false);
367 static void bnxt_get_channels(struct net_device *dev,
368 struct ethtool_channels *channel)
370 struct bnxt *bp = netdev_priv(dev);
371 int max_rx_rings, max_tx_rings, tcs;
373 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
374 channel->max_combined = min_t(int, max_rx_rings, max_tx_rings);
376 if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
381 tcs = netdev_get_num_tc(dev);
385 channel->max_rx = max_rx_rings;
386 channel->max_tx = max_tx_rings;
387 channel->max_other = 0;
388 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
389 channel->combined_count = bp->rx_nr_rings;
390 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
391 channel->combined_count--;
393 if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
394 channel->rx_count = bp->rx_nr_rings;
395 channel->tx_count = bp->tx_nr_rings_per_tc;
400 static int bnxt_set_channels(struct net_device *dev,
401 struct ethtool_channels *channel)
403 struct bnxt *bp = netdev_priv(dev);
404 int req_tx_rings, req_rx_rings, tcs;
409 if (channel->other_count)
412 if (!channel->combined_count &&
413 (!channel->rx_count || !channel->tx_count))
416 if (channel->combined_count &&
417 (channel->rx_count || channel->tx_count))
420 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
424 if (channel->combined_count)
427 tcs = netdev_get_num_tc(dev);
429 req_tx_rings = sh ? channel->combined_count : channel->tx_count;
430 req_rx_rings = sh ? channel->combined_count : channel->rx_count;
431 if (bp->tx_nr_rings_xdp) {
433 netdev_err(dev, "Only combined mode supported when XDP is enabled.\n");
436 tx_xdp = req_rx_rings;
438 rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp);
440 netdev_warn(dev, "Unable to allocate the requested rings\n");
444 if (netif_running(dev)) {
446 /* TODO CHIMP_FW: Send message to all VF's
450 rc = bnxt_close_nic(bp, true, false);
452 netdev_err(bp->dev, "Set channel failure rc :%x\n",
459 bp->flags |= BNXT_FLAG_SHARED_RINGS;
460 bp->rx_nr_rings = channel->combined_count;
461 bp->tx_nr_rings_per_tc = channel->combined_count;
463 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
464 bp->rx_nr_rings = channel->rx_count;
465 bp->tx_nr_rings_per_tc = channel->tx_count;
467 bp->tx_nr_rings_xdp = tx_xdp;
468 bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp;
470 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
472 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
473 bp->tx_nr_rings + bp->rx_nr_rings;
475 bp->num_stat_ctxs = bp->cp_nr_rings;
477 /* After changing number of rx channels, update NTUPLE feature. */
478 netdev_update_features(dev);
479 if (netif_running(dev)) {
480 rc = bnxt_open_nic(bp, true, false);
481 if ((!rc) && BNXT_PF(bp)) {
482 /* TODO CHIMP_FW: Send message to all VF's
491 #ifdef CONFIG_RFS_ACCEL
492 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
497 cmd->data = bp->ntp_fltr_count;
498 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
499 struct hlist_head *head;
500 struct bnxt_ntuple_filter *fltr;
502 head = &bp->ntp_fltr_hash_tbl[i];
504 hlist_for_each_entry_rcu(fltr, head, hash) {
505 if (j == cmd->rule_cnt)
507 rule_locs[j++] = fltr->sw_id;
510 if (j == cmd->rule_cnt)
517 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
519 struct ethtool_rx_flow_spec *fs =
520 (struct ethtool_rx_flow_spec *)&cmd->fs;
521 struct bnxt_ntuple_filter *fltr;
522 struct flow_keys *fkeys;
525 if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
528 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
529 struct hlist_head *head;
531 head = &bp->ntp_fltr_hash_tbl[i];
533 hlist_for_each_entry_rcu(fltr, head, hash) {
534 if (fltr->sw_id == fs->location)
542 fkeys = &fltr->fkeys;
543 if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
544 if (fkeys->basic.ip_proto == IPPROTO_TCP)
545 fs->flow_type = TCP_V4_FLOW;
546 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
547 fs->flow_type = UDP_V4_FLOW;
551 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
552 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
554 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
555 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
557 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
558 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
560 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
561 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
565 if (fkeys->basic.ip_proto == IPPROTO_TCP)
566 fs->flow_type = TCP_V6_FLOW;
567 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
568 fs->flow_type = UDP_V6_FLOW;
572 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] =
573 fkeys->addrs.v6addrs.src;
574 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] =
575 fkeys->addrs.v6addrs.dst;
576 for (i = 0; i < 4; i++) {
577 fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0);
578 fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0);
580 fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src;
581 fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0);
583 fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst;
584 fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0);
587 fs->ring_cookie = fltr->rxq;
597 static u64 get_ethtool_ipv4_rss(struct bnxt *bp)
599 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4)
600 return RXH_IP_SRC | RXH_IP_DST;
604 static u64 get_ethtool_ipv6_rss(struct bnxt *bp)
606 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6)
607 return RXH_IP_SRC | RXH_IP_DST;
611 static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
614 switch (cmd->flow_type) {
616 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4)
617 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
618 RXH_L4_B_0_1 | RXH_L4_B_2_3;
619 cmd->data |= get_ethtool_ipv4_rss(bp);
622 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)
623 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
624 RXH_L4_B_0_1 | RXH_L4_B_2_3;
631 cmd->data |= get_ethtool_ipv4_rss(bp);
635 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6)
636 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
637 RXH_L4_B_0_1 | RXH_L4_B_2_3;
638 cmd->data |= get_ethtool_ipv6_rss(bp);
641 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)
642 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
643 RXH_L4_B_0_1 | RXH_L4_B_2_3;
650 cmd->data |= get_ethtool_ipv6_rss(bp);
656 #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
657 #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
659 static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
661 u32 rss_hash_cfg = bp->rss_hash_cfg;
664 if (cmd->data == RXH_4TUPLE)
666 else if (cmd->data == RXH_2TUPLE)
673 if (cmd->flow_type == TCP_V4_FLOW) {
674 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
676 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
677 } else if (cmd->flow_type == UDP_V4_FLOW) {
678 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
680 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
682 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
683 } else if (cmd->flow_type == TCP_V6_FLOW) {
684 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
686 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
687 } else if (cmd->flow_type == UDP_V6_FLOW) {
688 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
690 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
692 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
693 } else if (tuple == 4) {
697 switch (cmd->flow_type) {
706 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
708 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
719 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
721 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
725 if (bp->rss_hash_cfg == rss_hash_cfg)
728 bp->rss_hash_cfg = rss_hash_cfg;
729 if (netif_running(bp->dev)) {
730 bnxt_close_nic(bp, false, false);
731 rc = bnxt_open_nic(bp, false, false);
736 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
739 struct bnxt *bp = netdev_priv(dev);
743 #ifdef CONFIG_RFS_ACCEL
744 case ETHTOOL_GRXRINGS:
745 cmd->data = bp->rx_nr_rings;
748 case ETHTOOL_GRXCLSRLCNT:
749 cmd->rule_cnt = bp->ntp_fltr_count;
750 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
753 case ETHTOOL_GRXCLSRLALL:
754 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
757 case ETHTOOL_GRXCLSRULE:
758 rc = bnxt_grxclsrule(bp, cmd);
763 rc = bnxt_grxfh(bp, cmd);
774 static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
776 struct bnxt *bp = netdev_priv(dev);
781 rc = bnxt_srxfh(bp, cmd);
791 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
793 return HW_HASH_INDEX_SIZE;
796 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
798 return HW_HASH_KEY_SIZE;
801 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
804 struct bnxt *bp = netdev_priv(dev);
805 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
809 *hfunc = ETH_RSS_HASH_TOP;
812 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
813 indir[i] = le16_to_cpu(vnic->rss_table[i]);
816 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
821 static void bnxt_get_drvinfo(struct net_device *dev,
822 struct ethtool_drvinfo *info)
824 struct bnxt *bp = netdev_priv(dev);
828 pkglog = kmalloc(BNX_PKG_LOG_MAX_LENGTH, GFP_KERNEL);
830 pkgver = bnxt_get_pkgver(dev, pkglog, BNX_PKG_LOG_MAX_LENGTH);
831 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
832 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
833 if (pkgver && *pkgver != 0 && isdigit(*pkgver))
834 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
835 "%s pkg %s", bp->fw_ver_str, pkgver);
837 strlcpy(info->fw_version, bp->fw_ver_str,
838 sizeof(info->fw_version));
839 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
840 info->n_stats = bnxt_get_num_stats(bp);
841 info->testinfo_len = bp->num_tests;
842 /* TODO CHIMP_FW: eeprom dump details */
843 info->eedump_len = 0;
844 /* TODO CHIMP FW: reg dump details */
845 info->regdump_len = 0;
849 static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
851 struct bnxt *bp = netdev_priv(dev);
855 memset(&wol->sopass, 0, sizeof(wol->sopass));
856 if (bp->flags & BNXT_FLAG_WOL_CAP) {
857 wol->supported = WAKE_MAGIC;
859 wol->wolopts = WAKE_MAGIC;
863 static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
865 struct bnxt *bp = netdev_priv(dev);
867 if (wol->wolopts & ~WAKE_MAGIC)
870 if (wol->wolopts & WAKE_MAGIC) {
871 if (!(bp->flags & BNXT_FLAG_WOL_CAP))
874 if (bnxt_hwrm_alloc_wol_fltr(bp))
880 if (bnxt_hwrm_free_wol_fltr(bp))
888 u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
892 /* TODO: support 25GB, 40GB, 50GB with different cable type */
893 /* set the advertised speeds */
894 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
895 speed_mask |= ADVERTISED_100baseT_Full;
896 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
897 speed_mask |= ADVERTISED_1000baseT_Full;
898 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
899 speed_mask |= ADVERTISED_2500baseX_Full;
900 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
901 speed_mask |= ADVERTISED_10000baseT_Full;
902 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
903 speed_mask |= ADVERTISED_40000baseCR4_Full;
905 if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
906 speed_mask |= ADVERTISED_Pause;
907 else if (fw_pause & BNXT_LINK_PAUSE_TX)
908 speed_mask |= ADVERTISED_Asym_Pause;
909 else if (fw_pause & BNXT_LINK_PAUSE_RX)
910 speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
915 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
917 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
918 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
920 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
921 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
923 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
924 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
926 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
927 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
929 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
930 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
932 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
933 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
935 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \
936 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
937 100000baseCR4_Full);\
938 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
939 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
941 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
942 ethtool_link_ksettings_add_link_mode( \
943 lk_ksettings, name, Asym_Pause);\
944 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
945 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
950 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
952 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
954 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
956 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
957 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
959 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
961 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
962 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
964 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
965 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
967 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
968 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
969 40000baseCR4_Full)) \
970 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
971 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
972 50000baseCR2_Full)) \
973 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
974 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
975 100000baseCR4_Full)) \
976 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \
979 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
980 struct ethtool_link_ksettings *lk_ksettings)
982 u16 fw_speeds = link_info->advertising;
985 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
986 fw_pause = link_info->auto_pause_setting;
988 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
991 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
992 struct ethtool_link_ksettings *lk_ksettings)
994 u16 fw_speeds = link_info->lp_auto_link_speeds;
997 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
998 fw_pause = link_info->lp_pause;
1000 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
1004 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
1005 struct ethtool_link_ksettings *lk_ksettings)
1007 u16 fw_speeds = link_info->support_speeds;
1009 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
1011 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
1012 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1015 if (link_info->support_auto_speeds)
1016 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1020 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
1022 switch (fw_link_speed) {
1023 case BNXT_LINK_SPEED_100MB:
1025 case BNXT_LINK_SPEED_1GB:
1027 case BNXT_LINK_SPEED_2_5GB:
1029 case BNXT_LINK_SPEED_10GB:
1031 case BNXT_LINK_SPEED_20GB:
1033 case BNXT_LINK_SPEED_25GB:
1035 case BNXT_LINK_SPEED_40GB:
1037 case BNXT_LINK_SPEED_50GB:
1039 case BNXT_LINK_SPEED_100GB:
1040 return SPEED_100000;
1042 return SPEED_UNKNOWN;
1046 static int bnxt_get_link_ksettings(struct net_device *dev,
1047 struct ethtool_link_ksettings *lk_ksettings)
1049 struct bnxt *bp = netdev_priv(dev);
1050 struct bnxt_link_info *link_info = &bp->link_info;
1051 struct ethtool_link_settings *base = &lk_ksettings->base;
1054 ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
1055 mutex_lock(&bp->link_lock);
1056 bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
1058 ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
1059 if (link_info->autoneg) {
1060 bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
1061 ethtool_link_ksettings_add_link_mode(lk_ksettings,
1062 advertising, Autoneg);
1063 base->autoneg = AUTONEG_ENABLE;
1064 if (link_info->phy_link_status == BNXT_LINK_LINK)
1065 bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
1066 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
1067 if (!netif_carrier_ok(dev))
1068 base->duplex = DUPLEX_UNKNOWN;
1069 else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
1070 base->duplex = DUPLEX_FULL;
1072 base->duplex = DUPLEX_HALF;
1074 base->autoneg = AUTONEG_DISABLE;
1076 bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
1077 base->duplex = DUPLEX_HALF;
1078 if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
1079 base->duplex = DUPLEX_FULL;
1081 base->speed = ethtool_speed;
1083 base->port = PORT_NONE;
1084 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1085 base->port = PORT_TP;
1086 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1088 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1091 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1093 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1096 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
1097 base->port = PORT_DA;
1098 else if (link_info->media_type ==
1099 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
1100 base->port = PORT_FIBRE;
1102 base->phy_address = link_info->phy_addr;
1103 mutex_unlock(&bp->link_lock);
1108 static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed)
1110 struct bnxt *bp = netdev_priv(dev);
1111 struct bnxt_link_info *link_info = &bp->link_info;
1112 u16 support_spds = link_info->support_speeds;
1115 switch (ethtool_speed) {
1117 if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
1118 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
1121 if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
1122 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
1125 if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
1126 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
1129 if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
1130 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
1133 if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
1134 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
1137 if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
1138 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
1141 if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
1142 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
1145 if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
1146 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
1149 if (support_spds & BNXT_LINK_SPEED_MSK_100GB)
1150 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB;
1153 netdev_err(dev, "unsupported speed!\n");
1159 u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
1161 u16 fw_speed_mask = 0;
1163 /* only support autoneg at speed 100, 1000, and 10000 */
1164 if (advertising & (ADVERTISED_100baseT_Full |
1165 ADVERTISED_100baseT_Half)) {
1166 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
1168 if (advertising & (ADVERTISED_1000baseT_Full |
1169 ADVERTISED_1000baseT_Half)) {
1170 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
1172 if (advertising & ADVERTISED_10000baseT_Full)
1173 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
1175 if (advertising & ADVERTISED_40000baseCR4_Full)
1176 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
1178 return fw_speed_mask;
1181 static int bnxt_set_link_ksettings(struct net_device *dev,
1182 const struct ethtool_link_ksettings *lk_ksettings)
1184 struct bnxt *bp = netdev_priv(dev);
1185 struct bnxt_link_info *link_info = &bp->link_info;
1186 const struct ethtool_link_settings *base = &lk_ksettings->base;
1187 bool set_pause = false;
1188 u16 fw_advertising = 0;
1192 if (!BNXT_SINGLE_PF(bp))
1195 mutex_lock(&bp->link_lock);
1196 if (base->autoneg == AUTONEG_ENABLE) {
1197 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
1199 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1200 if (!fw_advertising)
1201 link_info->advertising = link_info->support_auto_speeds;
1203 link_info->advertising = fw_advertising;
1204 /* any change to autoneg will cause link change, therefore the
1205 * driver should put back the original pause setting in autoneg
1210 u8 phy_type = link_info->phy_type;
1212 if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET ||
1213 phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
1214 link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1215 netdev_err(dev, "10GBase-T devices must autoneg\n");
1217 goto set_setting_exit;
1219 if (base->duplex == DUPLEX_HALF) {
1220 netdev_err(dev, "HALF DUPLEX is not supported!\n");
1222 goto set_setting_exit;
1224 speed = base->speed;
1225 fw_speed = bnxt_get_fw_speed(dev, speed);
1228 goto set_setting_exit;
1230 link_info->req_link_speed = fw_speed;
1231 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
1232 link_info->autoneg = 0;
1233 link_info->advertising = 0;
1236 if (netif_running(dev))
1237 rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
1240 mutex_unlock(&bp->link_lock);
1244 static void bnxt_get_pauseparam(struct net_device *dev,
1245 struct ethtool_pauseparam *epause)
1247 struct bnxt *bp = netdev_priv(dev);
1248 struct bnxt_link_info *link_info = &bp->link_info;
1252 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
1253 epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
1254 epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
1257 static int bnxt_set_pauseparam(struct net_device *dev,
1258 struct ethtool_pauseparam *epause)
1261 struct bnxt *bp = netdev_priv(dev);
1262 struct bnxt_link_info *link_info = &bp->link_info;
1264 if (!BNXT_SINGLE_PF(bp))
1267 mutex_lock(&bp->link_lock);
1268 if (epause->autoneg) {
1269 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1274 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1275 link_info->req_flow_ctrl = 0;
1277 /* when transition from auto pause to force pause,
1278 * force a link change
1280 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1281 link_info->force_link_chng = true;
1282 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1283 link_info->req_flow_ctrl = 0;
1285 if (epause->rx_pause)
1286 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1288 if (epause->tx_pause)
1289 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1291 if (netif_running(dev))
1292 rc = bnxt_hwrm_set_pause(bp);
1295 mutex_unlock(&bp->link_lock);
1299 static u32 bnxt_get_link(struct net_device *dev)
1301 struct bnxt *bp = netdev_priv(dev);
1303 /* TODO: handle MF, VF, driver close case */
1304 return bp->link_info.link_up;
1307 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1308 u16 ext, u16 *index, u32 *item_length,
1311 static int bnxt_flash_nvram(struct net_device *dev,
1319 struct bnxt *bp = netdev_priv(dev);
1321 struct hwrm_nvm_write_input req = {0};
1322 dma_addr_t dma_handle;
1325 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1327 req.dir_type = cpu_to_le16(dir_type);
1328 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1329 req.dir_ext = cpu_to_le16(dir_ext);
1330 req.dir_attr = cpu_to_le16(dir_attr);
1331 req.dir_data_length = cpu_to_le32(data_len);
1333 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1336 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1337 (unsigned)data_len);
1340 memcpy(kmem, data, data_len);
1341 req.host_src_addr = cpu_to_le64(dma_handle);
1343 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1344 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1346 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
1348 "PF does not have admin privileges to flash the device\n");
1356 static int bnxt_firmware_reset(struct net_device *dev,
1359 struct hwrm_fw_reset_input req = {0};
1360 struct bnxt *bp = netdev_priv(dev);
1363 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1365 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1366 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1367 /* (e.g. when firmware isn't already running) */
1369 case BNX_DIR_TYPE_CHIMP_PATCH:
1370 case BNX_DIR_TYPE_BOOTCODE:
1371 case BNX_DIR_TYPE_BOOTCODE_2:
1372 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1373 /* Self-reset ChiMP upon next PCIe reset: */
1374 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1376 case BNX_DIR_TYPE_APE_FW:
1377 case BNX_DIR_TYPE_APE_PATCH:
1378 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1379 /* Self-reset APE upon next PCIe reset: */
1380 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1382 case BNX_DIR_TYPE_KONG_FW:
1383 case BNX_DIR_TYPE_KONG_PATCH:
1384 req.embedded_proc_type =
1385 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1387 case BNX_DIR_TYPE_BONO_FW:
1388 case BNX_DIR_TYPE_BONO_PATCH:
1389 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1395 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1396 if (rc == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
1398 "PF does not have admin privileges to reset the device\n");
1406 static int bnxt_flash_firmware(struct net_device *dev,
1415 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1418 case BNX_DIR_TYPE_BOOTCODE:
1419 case BNX_DIR_TYPE_BOOTCODE_2:
1420 code_type = CODE_BOOT;
1422 case BNX_DIR_TYPE_CHIMP_PATCH:
1423 code_type = CODE_CHIMP_PATCH;
1425 case BNX_DIR_TYPE_APE_FW:
1426 code_type = CODE_MCTP_PASSTHRU;
1428 case BNX_DIR_TYPE_APE_PATCH:
1429 code_type = CODE_APE_PATCH;
1431 case BNX_DIR_TYPE_KONG_FW:
1432 code_type = CODE_KONG_FW;
1434 case BNX_DIR_TYPE_KONG_PATCH:
1435 code_type = CODE_KONG_PATCH;
1437 case BNX_DIR_TYPE_BONO_FW:
1438 code_type = CODE_BONO_FW;
1440 case BNX_DIR_TYPE_BONO_PATCH:
1441 code_type = CODE_BONO_PATCH;
1444 netdev_err(dev, "Unsupported directory entry type: %u\n",
1448 if (fw_size < sizeof(struct bnxt_fw_header)) {
1449 netdev_err(dev, "Invalid firmware file size: %u\n",
1450 (unsigned int)fw_size);
1453 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1454 netdev_err(dev, "Invalid firmware signature: %08X\n",
1455 le32_to_cpu(header->signature));
1458 if (header->code_type != code_type) {
1459 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1460 code_type, header->code_type);
1463 if (header->device != DEVICE_CUMULUS_FAMILY) {
1464 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1465 DEVICE_CUMULUS_FAMILY, header->device);
1468 /* Confirm the CRC32 checksum of the file: */
1469 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1470 sizeof(stored_crc)));
1471 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1472 if (calculated_crc != stored_crc) {
1473 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1474 (unsigned long)stored_crc,
1475 (unsigned long)calculated_crc);
1478 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1479 0, 0, fw_data, fw_size);
1480 if (rc == 0) /* Firmware update successful */
1481 rc = bnxt_firmware_reset(dev, dir_type);
1486 static int bnxt_flash_microcode(struct net_device *dev,
1491 struct bnxt_ucode_trailer *trailer;
1496 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1497 netdev_err(dev, "Invalid microcode file size: %u\n",
1498 (unsigned int)fw_size);
1501 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1503 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1504 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1505 le32_to_cpu(trailer->sig));
1508 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1509 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1510 dir_type, le16_to_cpu(trailer->dir_type));
1513 if (le16_to_cpu(trailer->trailer_length) <
1514 sizeof(struct bnxt_ucode_trailer)) {
1515 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1516 le16_to_cpu(trailer->trailer_length));
1520 /* Confirm the CRC32 checksum of the file: */
1521 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1522 sizeof(stored_crc)));
1523 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1524 if (calculated_crc != stored_crc) {
1526 "CRC32 (%08lX) does not match calculated: %08lX\n",
1527 (unsigned long)stored_crc,
1528 (unsigned long)calculated_crc);
1531 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1532 0, 0, fw_data, fw_size);
1537 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1540 case BNX_DIR_TYPE_CHIMP_PATCH:
1541 case BNX_DIR_TYPE_BOOTCODE:
1542 case BNX_DIR_TYPE_BOOTCODE_2:
1543 case BNX_DIR_TYPE_APE_FW:
1544 case BNX_DIR_TYPE_APE_PATCH:
1545 case BNX_DIR_TYPE_KONG_FW:
1546 case BNX_DIR_TYPE_KONG_PATCH:
1547 case BNX_DIR_TYPE_BONO_FW:
1548 case BNX_DIR_TYPE_BONO_PATCH:
1555 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1558 case BNX_DIR_TYPE_AVS:
1559 case BNX_DIR_TYPE_EXP_ROM_MBA:
1560 case BNX_DIR_TYPE_PCIE:
1561 case BNX_DIR_TYPE_TSCF_UCODE:
1562 case BNX_DIR_TYPE_EXT_PHY:
1563 case BNX_DIR_TYPE_CCM:
1564 case BNX_DIR_TYPE_ISCSI_BOOT:
1565 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1566 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1573 static bool bnxt_dir_type_is_executable(u16 dir_type)
1575 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1576 bnxt_dir_type_is_other_exec_format(dir_type);
1579 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1581 const char *filename)
1583 const struct firmware *fw;
1586 rc = request_firmware(&fw, filename, &dev->dev);
1588 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1592 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1593 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1594 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1595 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1597 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1598 0, 0, fw->data, fw->size);
1599 release_firmware(fw);
1603 static int bnxt_flash_package_from_file(struct net_device *dev,
1604 char *filename, u32 install_type)
1606 struct bnxt *bp = netdev_priv(dev);
1607 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
1608 struct hwrm_nvm_install_update_input install = {0};
1609 const struct firmware *fw;
1610 int rc, hwrm_err = 0;
1614 bnxt_hwrm_fw_set_time(bp);
1616 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
1617 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1618 &index, &item_len, NULL) != 0) {
1619 netdev_err(dev, "PKG update area not created in nvram\n");
1623 rc = request_firmware(&fw, filename, &dev->dev);
1625 netdev_err(dev, "PKG error %d requesting file: %s\n",
1630 if (fw->size > item_len) {
1631 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
1632 (unsigned long)fw->size);
1635 dma_addr_t dma_handle;
1637 struct hwrm_nvm_modify_input modify = {0};
1639 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
1641 modify.dir_idx = cpu_to_le16(index);
1642 modify.len = cpu_to_le32(fw->size);
1644 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
1645 &dma_handle, GFP_KERNEL);
1648 "dma_alloc_coherent failure, length = %u\n",
1649 (unsigned int)fw->size);
1652 memcpy(kmem, fw->data, fw->size);
1653 modify.host_src_addr = cpu_to_le64(dma_handle);
1655 hwrm_err = hwrm_send_message(bp, &modify,
1657 FLASH_PACKAGE_TIMEOUT);
1658 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
1662 release_firmware(fw);
1666 if ((install_type & 0xffff) == 0)
1667 install_type >>= 16;
1668 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
1669 install.install_type = cpu_to_le32(install_type);
1671 mutex_lock(&bp->hwrm_cmd_lock);
1672 hwrm_err = _hwrm_send_message(bp, &install, sizeof(install),
1673 INSTALL_PACKAGE_TIMEOUT);
1675 u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err;
1677 if (resp->error_code && error_code ==
1678 NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) {
1679 install.flags |= cpu_to_le16(
1680 NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG);
1681 hwrm_err = _hwrm_send_message(bp, &install,
1683 INSTALL_PACKAGE_TIMEOUT);
1686 goto flash_pkg_exit;
1690 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
1691 (s8)resp->result, (int)resp->problem_item);
1695 mutex_unlock(&bp->hwrm_cmd_lock);
1697 if (hwrm_err == HWRM_ERR_CODE_RESOURCE_ACCESS_DENIED) {
1699 "PF does not have admin privileges to flash the device\n");
1701 } else if (hwrm_err) {
1707 static int bnxt_flash_device(struct net_device *dev,
1708 struct ethtool_flash *flash)
1710 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1711 netdev_err(dev, "flashdev not supported from a virtual function\n");
1715 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
1716 flash->region > 0xffff)
1717 return bnxt_flash_package_from_file(dev, flash->data,
1720 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1723 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1725 struct bnxt *bp = netdev_priv(dev);
1727 struct hwrm_nvm_get_dir_info_input req = {0};
1728 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1730 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1732 mutex_lock(&bp->hwrm_cmd_lock);
1733 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1735 *entries = le32_to_cpu(output->entries);
1736 *length = le32_to_cpu(output->entry_length);
1738 mutex_unlock(&bp->hwrm_cmd_lock);
1742 static int bnxt_get_eeprom_len(struct net_device *dev)
1744 /* The -1 return value allows the entire 32-bit range of offsets to be
1745 * passed via the ethtool command-line utility.
1750 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1752 struct bnxt *bp = netdev_priv(dev);
1758 dma_addr_t dma_handle;
1759 struct hwrm_nvm_get_dir_entries_input req = {0};
1761 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1765 if (!dir_entries || !entry_length)
1768 /* Insert 2 bytes of directory info (count and size of entries) */
1772 *data++ = dir_entries;
1773 *data++ = entry_length;
1775 memset(data, 0xff, len);
1777 buflen = dir_entries * entry_length;
1778 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1781 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1785 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1786 req.host_dest_addr = cpu_to_le64(dma_handle);
1787 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1789 memcpy(data, buf, len > buflen ? buflen : len);
1790 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1794 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1795 u32 length, u8 *data)
1797 struct bnxt *bp = netdev_priv(dev);
1800 dma_addr_t dma_handle;
1801 struct hwrm_nvm_read_input req = {0};
1803 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1806 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1810 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1811 req.host_dest_addr = cpu_to_le64(dma_handle);
1812 req.dir_idx = cpu_to_le16(index);
1813 req.offset = cpu_to_le32(offset);
1814 req.len = cpu_to_le32(length);
1816 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1818 memcpy(data, buf, length);
1819 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1823 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1824 u16 ext, u16 *index, u32 *item_length,
1827 struct bnxt *bp = netdev_priv(dev);
1829 struct hwrm_nvm_find_dir_entry_input req = {0};
1830 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
1832 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
1835 req.dir_type = cpu_to_le16(type);
1836 req.dir_ordinal = cpu_to_le16(ordinal);
1837 req.dir_ext = cpu_to_le16(ext);
1838 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
1839 mutex_lock(&bp->hwrm_cmd_lock);
1840 rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1843 *index = le16_to_cpu(output->dir_idx);
1845 *item_length = le32_to_cpu(output->dir_item_length);
1847 *data_length = le32_to_cpu(output->dir_data_length);
1849 mutex_unlock(&bp->hwrm_cmd_lock);
1853 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
1855 char *retval = NULL;
1862 /* null-terminate the log data (removing last '\n'): */
1863 data[datalen - 1] = 0;
1864 for (p = data; *p != 0; p++) {
1867 while (*p != 0 && *p != '\n') {
1869 while (*p != 0 && *p != '\t' && *p != '\n')
1871 if (field == desired_field)
1886 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen)
1891 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
1892 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1893 &index, NULL, &datalen) != 0)
1896 memset(buf, 0, buflen);
1897 if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0)
1900 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf,
1904 static int bnxt_get_eeprom(struct net_device *dev,
1905 struct ethtool_eeprom *eeprom,
1911 if (eeprom->offset == 0) /* special offset value to get directory */
1912 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1914 index = eeprom->offset >> 24;
1915 offset = eeprom->offset & 0xffffff;
1918 netdev_err(dev, "unsupported index value: %d\n", index);
1922 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1925 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1927 struct bnxt *bp = netdev_priv(dev);
1928 struct hwrm_nvm_erase_dir_entry_input req = {0};
1930 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1931 req.dir_idx = cpu_to_le16(index);
1932 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1935 static int bnxt_set_eeprom(struct net_device *dev,
1936 struct ethtool_eeprom *eeprom,
1939 struct bnxt *bp = netdev_priv(dev);
1941 u16 type, ext, ordinal, attr;
1944 netdev_err(dev, "NVM write not supported from a virtual function\n");
1948 type = eeprom->magic >> 16;
1950 if (type == 0xffff) { /* special value for directory operations */
1951 index = eeprom->magic & 0xff;
1952 dir_op = eeprom->magic >> 8;
1956 case 0x0e: /* erase */
1957 if (eeprom->offset != ~eeprom->magic)
1959 return bnxt_erase_nvram_directory(dev, index - 1);
1965 /* Create or re-write an NVM item: */
1966 if (bnxt_dir_type_is_executable(type) == true)
1968 ext = eeprom->magic & 0xffff;
1969 ordinal = eeprom->offset >> 16;
1970 attr = eeprom->offset & 0xffff;
1972 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
1976 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1978 struct bnxt *bp = netdev_priv(dev);
1979 struct ethtool_eee *eee = &bp->eee;
1980 struct bnxt_link_info *link_info = &bp->link_info;
1984 if (!BNXT_SINGLE_PF(bp))
1987 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1990 mutex_lock(&bp->link_lock);
1991 advertising = _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
1992 if (!edata->eee_enabled)
1995 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1996 netdev_warn(dev, "EEE requires autoneg\n");
2000 if (edata->tx_lpi_enabled) {
2001 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
2002 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
2003 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
2004 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
2007 } else if (!bp->lpi_tmr_hi) {
2008 edata->tx_lpi_timer = eee->tx_lpi_timer;
2011 if (!edata->advertised) {
2012 edata->advertised = advertising & eee->supported;
2013 } else if (edata->advertised & ~advertising) {
2014 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
2015 edata->advertised, advertising);
2020 eee->advertised = edata->advertised;
2021 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
2022 eee->tx_lpi_timer = edata->tx_lpi_timer;
2024 eee->eee_enabled = edata->eee_enabled;
2026 if (netif_running(dev))
2027 rc = bnxt_hwrm_set_link_setting(bp, false, true);
2030 mutex_unlock(&bp->link_lock);
2034 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
2036 struct bnxt *bp = netdev_priv(dev);
2038 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
2042 if (!bp->eee.eee_enabled) {
2043 /* Preserve tx_lpi_timer so that the last value will be used
2044 * by default when it is re-enabled.
2046 edata->advertised = 0;
2047 edata->tx_lpi_enabled = 0;
2050 if (!bp->eee.eee_active)
2051 edata->lp_advertised = 0;
2056 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
2057 u16 page_number, u16 start_addr,
2058 u16 data_length, u8 *buf)
2060 struct hwrm_port_phy_i2c_read_input req = {0};
2061 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
2062 int rc, byte_offset = 0;
2064 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
2065 req.i2c_slave_addr = i2c_addr;
2066 req.page_number = cpu_to_le16(page_number);
2067 req.port_id = cpu_to_le16(bp->pf.port_id);
2071 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
2072 data_length -= xfer_size;
2073 req.page_offset = cpu_to_le16(start_addr + byte_offset);
2074 req.data_length = xfer_size;
2075 req.enables = cpu_to_le32(start_addr + byte_offset ?
2076 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
2077 mutex_lock(&bp->hwrm_cmd_lock);
2078 rc = _hwrm_send_message(bp, &req, sizeof(req),
2081 memcpy(buf + byte_offset, output->data, xfer_size);
2082 mutex_unlock(&bp->hwrm_cmd_lock);
2083 byte_offset += xfer_size;
2084 } while (!rc && data_length > 0);
2089 static int bnxt_get_module_info(struct net_device *dev,
2090 struct ethtool_modinfo *modinfo)
2092 struct bnxt *bp = netdev_priv(dev);
2093 struct hwrm_port_phy_i2c_read_input req = {0};
2094 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
2097 /* No point in going further if phy status indicates
2098 * module is not inserted or if it is powered down or
2099 * if it is of type 10GBase-T
2101 if (bp->link_info.module_status >
2102 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
2105 /* This feature is not supported in older firmware versions */
2106 if (bp->hwrm_spec_code < 0x10202)
2109 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
2110 req.i2c_slave_addr = I2C_DEV_ADDR_A0;
2111 req.page_number = 0;
2112 req.page_offset = cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR);
2113 req.data_length = SFP_EEPROM_SFF_8472_COMP_SIZE;
2114 req.port_id = cpu_to_le16(bp->pf.port_id);
2115 mutex_lock(&bp->hwrm_cmd_lock);
2116 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2118 u32 module_id = le32_to_cpu(output->data[0]);
2120 switch (module_id) {
2121 case SFF_MODULE_ID_SFP:
2122 modinfo->type = ETH_MODULE_SFF_8472;
2123 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2125 case SFF_MODULE_ID_QSFP:
2126 case SFF_MODULE_ID_QSFP_PLUS:
2127 modinfo->type = ETH_MODULE_SFF_8436;
2128 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
2130 case SFF_MODULE_ID_QSFP28:
2131 modinfo->type = ETH_MODULE_SFF_8636;
2132 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
2139 mutex_unlock(&bp->hwrm_cmd_lock);
2143 static int bnxt_get_module_eeprom(struct net_device *dev,
2144 struct ethtool_eeprom *eeprom,
2147 struct bnxt *bp = netdev_priv(dev);
2148 u16 start = eeprom->offset, length = eeprom->len;
2151 memset(data, 0, eeprom->len);
2153 /* Read A0 portion of the EEPROM */
2154 if (start < ETH_MODULE_SFF_8436_LEN) {
2155 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
2156 length = ETH_MODULE_SFF_8436_LEN - start;
2157 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
2158 start, length, data);
2163 length = eeprom->len - length;
2166 /* Read A2 portion of the EEPROM */
2168 start -= ETH_MODULE_SFF_8436_LEN;
2169 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 0,
2170 start, length, data);
2175 static int bnxt_nway_reset(struct net_device *dev)
2179 struct bnxt *bp = netdev_priv(dev);
2180 struct bnxt_link_info *link_info = &bp->link_info;
2182 if (!BNXT_SINGLE_PF(bp))
2185 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
2188 if (netif_running(dev))
2189 rc = bnxt_hwrm_set_link_setting(bp, true, false);
2194 static int bnxt_set_phys_id(struct net_device *dev,
2195 enum ethtool_phys_id_state state)
2197 struct hwrm_port_led_cfg_input req = {0};
2198 struct bnxt *bp = netdev_priv(dev);
2199 struct bnxt_pf_info *pf = &bp->pf;
2200 struct bnxt_led_cfg *led_cfg;
2205 if (!bp->num_leds || BNXT_VF(bp))
2208 if (state == ETHTOOL_ID_ACTIVE) {
2209 led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT;
2210 duration = cpu_to_le16(500);
2211 } else if (state == ETHTOOL_ID_INACTIVE) {
2212 led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT;
2213 duration = cpu_to_le16(0);
2217 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1);
2218 req.port_id = cpu_to_le16(pf->port_id);
2219 req.num_leds = bp->num_leds;
2220 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
2221 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
2222 req.enables |= BNXT_LED_DFLT_ENABLES(i);
2223 led_cfg->led_id = bp->leds[i].led_id;
2224 led_cfg->led_state = led_state;
2225 led_cfg->led_blink_on = duration;
2226 led_cfg->led_blink_off = duration;
2227 led_cfg->led_group_id = bp->leds[i].led_group_id;
2229 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2235 static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring)
2237 struct hwrm_selftest_irq_input req = {0};
2239 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1);
2240 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2243 static int bnxt_test_irq(struct bnxt *bp)
2247 for (i = 0; i < bp->cp_nr_rings; i++) {
2248 u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id;
2251 rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring);
2258 static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable)
2260 struct hwrm_port_mac_cfg_input req = {0};
2262 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1);
2264 req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK);
2266 req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL;
2268 req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE;
2269 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2272 static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds)
2274 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2275 struct hwrm_port_phy_qcaps_input req = {0};
2278 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
2279 mutex_lock(&bp->hwrm_cmd_lock);
2280 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2282 *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode);
2284 mutex_unlock(&bp->hwrm_cmd_lock);
2288 static int bnxt_disable_an_for_lpbk(struct bnxt *bp,
2289 struct hwrm_port_phy_cfg_input *req)
2291 struct bnxt_link_info *link_info = &bp->link_info;
2296 if (!link_info->autoneg)
2299 rc = bnxt_query_force_speeds(bp, &fw_advertising);
2303 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB;
2304 if (netif_carrier_ok(bp->dev))
2305 fw_speed = bp->link_info.link_speed;
2306 else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB)
2307 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB;
2308 else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB)
2309 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB;
2310 else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB)
2311 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB;
2312 else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB)
2313 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB;
2315 req->force_link_speed = cpu_to_le16(fw_speed);
2316 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE |
2317 PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
2318 rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT);
2320 req->force_link_speed = cpu_to_le16(0);
2324 static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable)
2326 struct hwrm_port_phy_cfg_input req = {0};
2328 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
2331 bnxt_disable_an_for_lpbk(bp, &req);
2332 req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL;
2334 req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE;
2336 req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK);
2337 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2340 static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_napi *bnapi,
2341 u32 raw_cons, int pkt_size)
2343 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
2344 struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
2345 struct bnxt_sw_rx_bd *rx_buf;
2346 struct rx_cmp *rxcmp;
2352 cp_cons = RING_CMP(raw_cons);
2353 rxcmp = (struct rx_cmp *)
2354 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
2355 cons = rxcmp->rx_cmp_opaque;
2356 rx_buf = &rxr->rx_buf_ring[cons];
2357 data = rx_buf->data_ptr;
2358 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
2359 if (len != pkt_size)
2362 if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr))
2365 for ( ; i < pkt_size; i++) {
2366 if (data[i] != (u8)(i & 0xff))
2372 static int bnxt_poll_loopback(struct bnxt *bp, int pkt_size)
2374 struct bnxt_napi *bnapi = bp->bnapi[0];
2375 struct bnxt_cp_ring_info *cpr;
2376 struct tx_cmp *txcmp;
2382 cpr = &bnapi->cp_ring;
2383 raw_cons = cpr->cp_raw_cons;
2384 for (i = 0; i < 200; i++) {
2385 cons = RING_CMP(raw_cons);
2386 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
2388 if (!TX_CMP_VALID(txcmp, raw_cons)) {
2393 /* The valid test of the entry must be done first before
2394 * reading any further.
2397 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) {
2398 rc = bnxt_rx_loopback(bp, bnapi, raw_cons, pkt_size);
2399 raw_cons = NEXT_RAW_CMP(raw_cons);
2400 raw_cons = NEXT_RAW_CMP(raw_cons);
2403 raw_cons = NEXT_RAW_CMP(raw_cons);
2405 cpr->cp_raw_cons = raw_cons;
2409 static int bnxt_run_loopback(struct bnxt *bp)
2411 struct bnxt_tx_ring_info *txr = &bp->tx_ring[0];
2412 int pkt_size, i = 0;
2413 struct sk_buff *skb;
2418 pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
2419 skb = netdev_alloc_skb(bp->dev, pkt_size);
2422 data = skb_put(skb, pkt_size);
2423 eth_broadcast_addr(data);
2425 ether_addr_copy(&data[i], bp->dev->dev_addr);
2427 for ( ; i < pkt_size; i++)
2428 data[i] = (u8)(i & 0xff);
2430 map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size,
2432 if (dma_mapping_error(&bp->pdev->dev, map)) {
2436 bnxt_xmit_xdp(bp, txr, map, pkt_size, 0);
2438 /* Sync BD data before updating doorbell */
2441 bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | txr->tx_prod);
2442 rc = bnxt_poll_loopback(bp, pkt_size);
2444 dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE);
2449 static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results)
2451 struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr;
2452 struct hwrm_selftest_exec_input req = {0};
2455 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1);
2456 mutex_lock(&bp->hwrm_cmd_lock);
2457 resp->test_success = 0;
2458 req.flags = test_mask;
2459 rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout);
2460 *test_results = resp->test_success;
2461 mutex_unlock(&bp->hwrm_cmd_lock);
2465 #define BNXT_DRV_TESTS 3
2466 #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS)
2467 #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1)
2468 #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2)
2470 static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
2473 struct bnxt *bp = netdev_priv(dev);
2474 bool offline = false;
2475 u8 test_results = 0;
2479 if (!bp->num_tests || !BNXT_SINGLE_PF(bp))
2481 memset(buf, 0, sizeof(u64) * bp->num_tests);
2482 if (!netif_running(dev)) {
2483 etest->flags |= ETH_TEST_FL_FAILED;
2487 if (etest->flags & ETH_TEST_FL_OFFLINE) {
2488 if (bp->pf.active_vfs) {
2489 etest->flags |= ETH_TEST_FL_FAILED;
2490 netdev_warn(dev, "Offline tests cannot be run with active VFs\n");
2496 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2497 u8 bit_val = 1 << i;
2499 if (!(bp->test_info->offline_mask & bit_val))
2500 test_mask |= bit_val;
2502 test_mask |= bit_val;
2505 bnxt_run_fw_tests(bp, test_mask, &test_results);
2507 rc = bnxt_close_nic(bp, false, false);
2510 bnxt_run_fw_tests(bp, test_mask, &test_results);
2512 buf[BNXT_MACLPBK_TEST_IDX] = 1;
2513 bnxt_hwrm_mac_loopback(bp, true);
2515 rc = bnxt_half_open_nic(bp);
2517 bnxt_hwrm_mac_loopback(bp, false);
2518 etest->flags |= ETH_TEST_FL_FAILED;
2521 if (bnxt_run_loopback(bp))
2522 etest->flags |= ETH_TEST_FL_FAILED;
2524 buf[BNXT_MACLPBK_TEST_IDX] = 0;
2526 bnxt_hwrm_mac_loopback(bp, false);
2527 bnxt_hwrm_phy_loopback(bp, true);
2529 if (bnxt_run_loopback(bp)) {
2530 buf[BNXT_PHYLPBK_TEST_IDX] = 1;
2531 etest->flags |= ETH_TEST_FL_FAILED;
2533 bnxt_hwrm_phy_loopback(bp, false);
2534 bnxt_half_close_nic(bp);
2535 rc = bnxt_open_nic(bp, false, true);
2537 if (rc || bnxt_test_irq(bp)) {
2538 buf[BNXT_IRQ_TEST_IDX] = 1;
2539 etest->flags |= ETH_TEST_FL_FAILED;
2541 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2542 u8 bit_val = 1 << i;
2544 if ((test_mask & bit_val) && !(test_results & bit_val)) {
2546 etest->flags |= ETH_TEST_FL_FAILED;
2551 void bnxt_ethtool_init(struct bnxt *bp)
2553 struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr;
2554 struct hwrm_selftest_qlist_input req = {0};
2555 struct bnxt_test_info *test_info;
2558 if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp))
2561 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1);
2562 mutex_lock(&bp->hwrm_cmd_lock);
2563 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2565 goto ethtool_init_exit;
2567 test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL);
2569 goto ethtool_init_exit;
2571 bp->test_info = test_info;
2572 bp->num_tests = resp->num_tests + BNXT_DRV_TESTS;
2573 if (bp->num_tests > BNXT_MAX_TEST)
2574 bp->num_tests = BNXT_MAX_TEST;
2576 test_info->offline_mask = resp->offline_tests;
2577 test_info->timeout = le16_to_cpu(resp->test_timeout);
2578 if (!test_info->timeout)
2579 test_info->timeout = HWRM_CMD_TIMEOUT;
2580 for (i = 0; i < bp->num_tests; i++) {
2581 char *str = test_info->string[i];
2582 char *fw_str = resp->test0_name + i * 32;
2584 if (i == BNXT_MACLPBK_TEST_IDX) {
2585 strcpy(str, "Mac loopback test (offline)");
2586 } else if (i == BNXT_PHYLPBK_TEST_IDX) {
2587 strcpy(str, "Phy loopback test (offline)");
2588 } else if (i == BNXT_IRQ_TEST_IDX) {
2589 strcpy(str, "Interrupt_test (offline)");
2591 strlcpy(str, fw_str, ETH_GSTRING_LEN);
2592 strncat(str, " test", ETH_GSTRING_LEN - strlen(str));
2593 if (test_info->offline_mask & (1 << i))
2594 strncat(str, " (offline)",
2595 ETH_GSTRING_LEN - strlen(str));
2597 strncat(str, " (online)",
2598 ETH_GSTRING_LEN - strlen(str));
2603 mutex_unlock(&bp->hwrm_cmd_lock);
2606 void bnxt_ethtool_free(struct bnxt *bp)
2608 kfree(bp->test_info);
2609 bp->test_info = NULL;
2612 const struct ethtool_ops bnxt_ethtool_ops = {
2613 .get_link_ksettings = bnxt_get_link_ksettings,
2614 .set_link_ksettings = bnxt_set_link_ksettings,
2615 .get_pauseparam = bnxt_get_pauseparam,
2616 .set_pauseparam = bnxt_set_pauseparam,
2617 .get_drvinfo = bnxt_get_drvinfo,
2618 .get_wol = bnxt_get_wol,
2619 .set_wol = bnxt_set_wol,
2620 .get_coalesce = bnxt_get_coalesce,
2621 .set_coalesce = bnxt_set_coalesce,
2622 .get_msglevel = bnxt_get_msglevel,
2623 .set_msglevel = bnxt_set_msglevel,
2624 .get_sset_count = bnxt_get_sset_count,
2625 .get_strings = bnxt_get_strings,
2626 .get_ethtool_stats = bnxt_get_ethtool_stats,
2627 .set_ringparam = bnxt_set_ringparam,
2628 .get_ringparam = bnxt_get_ringparam,
2629 .get_channels = bnxt_get_channels,
2630 .set_channels = bnxt_set_channels,
2631 .get_rxnfc = bnxt_get_rxnfc,
2632 .set_rxnfc = bnxt_set_rxnfc,
2633 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
2634 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
2635 .get_rxfh = bnxt_get_rxfh,
2636 .flash_device = bnxt_flash_device,
2637 .get_eeprom_len = bnxt_get_eeprom_len,
2638 .get_eeprom = bnxt_get_eeprom,
2639 .set_eeprom = bnxt_set_eeprom,
2640 .get_link = bnxt_get_link,
2641 .get_eee = bnxt_get_eee,
2642 .set_eee = bnxt_set_eee,
2643 .get_module_info = bnxt_get_module_info,
2644 .get_module_eeprom = bnxt_get_module_eeprom,
2645 .nway_reset = bnxt_nway_reset,
2646 .set_phys_id = bnxt_set_phys_id,
2647 .self_test = bnxt_self_test,