1 /* Broadcom NetXtreme-C/E network driver.
3 * Copyright (c) 2014-2016 Broadcom Corporation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
10 #include <linux/ctype.h>
11 #include <linux/stringify.h>
12 #include <linux/ethtool.h>
13 #include <linux/interrupt.h>
14 #include <linux/pci.h>
15 #include <linux/etherdevice.h>
16 #include <linux/crc32.h>
17 #include <linux/firmware.h>
20 #include "bnxt_ethtool.h"
21 #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */
22 #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */
23 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
24 #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
25 #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
27 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen);
29 static u32 bnxt_get_msglevel(struct net_device *dev)
31 struct bnxt *bp = netdev_priv(dev);
33 return bp->msg_enable;
36 static void bnxt_set_msglevel(struct net_device *dev, u32 value)
38 struct bnxt *bp = netdev_priv(dev);
40 bp->msg_enable = value;
43 static int bnxt_get_coalesce(struct net_device *dev,
44 struct ethtool_coalesce *coal)
46 struct bnxt *bp = netdev_priv(dev);
48 memset(coal, 0, sizeof(*coal));
50 coal->rx_coalesce_usecs = bp->rx_coal_ticks;
51 /* 2 completion records per rx packet */
52 coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2;
53 coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq;
54 coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2;
56 coal->tx_coalesce_usecs = bp->tx_coal_ticks;
57 coal->tx_max_coalesced_frames = bp->tx_coal_bufs;
58 coal->tx_coalesce_usecs_irq = bp->tx_coal_ticks_irq;
59 coal->tx_max_coalesced_frames_irq = bp->tx_coal_bufs_irq;
61 coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
66 static int bnxt_set_coalesce(struct net_device *dev,
67 struct ethtool_coalesce *coal)
69 struct bnxt *bp = netdev_priv(dev);
70 bool update_stats = false;
73 bp->rx_coal_ticks = coal->rx_coalesce_usecs;
74 /* 2 completion records per rx packet */
75 bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2;
76 bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq;
77 bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2;
79 bp->tx_coal_ticks = coal->tx_coalesce_usecs;
80 bp->tx_coal_bufs = coal->tx_max_coalesced_frames;
81 bp->tx_coal_ticks_irq = coal->tx_coalesce_usecs_irq;
82 bp->tx_coal_bufs_irq = coal->tx_max_coalesced_frames_irq;
84 if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
85 u32 stats_ticks = coal->stats_block_coalesce_usecs;
87 stats_ticks = clamp_t(u32, stats_ticks,
88 BNXT_MIN_STATS_COAL_TICKS,
89 BNXT_MAX_STATS_COAL_TICKS);
90 stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
91 bp->stats_coal_ticks = stats_ticks;
95 if (netif_running(dev)) {
97 rc = bnxt_close_nic(bp, true, false);
99 rc = bnxt_open_nic(bp, true, false);
101 rc = bnxt_hwrm_set_coal(bp);
108 #define BNXT_NUM_STATS 21
110 #define BNXT_RX_STATS_ENTRY(counter) \
111 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
113 #define BNXT_TX_STATS_ENTRY(counter) \
114 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
116 static const struct {
118 char string[ETH_GSTRING_LEN];
119 } bnxt_port_stats_arr[] = {
120 BNXT_RX_STATS_ENTRY(rx_64b_frames),
121 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
122 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
123 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
124 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
125 BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames),
126 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
127 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
128 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
129 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
130 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
131 BNXT_RX_STATS_ENTRY(rx_total_frames),
132 BNXT_RX_STATS_ENTRY(rx_ucast_frames),
133 BNXT_RX_STATS_ENTRY(rx_mcast_frames),
134 BNXT_RX_STATS_ENTRY(rx_bcast_frames),
135 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
136 BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
137 BNXT_RX_STATS_ENTRY(rx_pause_frames),
138 BNXT_RX_STATS_ENTRY(rx_pfc_frames),
139 BNXT_RX_STATS_ENTRY(rx_align_err_frames),
140 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
141 BNXT_RX_STATS_ENTRY(rx_jbr_frames),
142 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
143 BNXT_RX_STATS_ENTRY(rx_tagged_frames),
144 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
145 BNXT_RX_STATS_ENTRY(rx_good_frames),
146 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0),
147 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1),
148 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2),
149 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3),
150 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4),
151 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5),
152 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6),
153 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7),
154 BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
155 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
156 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
157 BNXT_RX_STATS_ENTRY(rx_bytes),
158 BNXT_RX_STATS_ENTRY(rx_runt_bytes),
159 BNXT_RX_STATS_ENTRY(rx_runt_frames),
161 BNXT_TX_STATS_ENTRY(tx_64b_frames),
162 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
163 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
164 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
165 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
166 BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames),
167 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
168 BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames),
169 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
170 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
171 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
172 BNXT_TX_STATS_ENTRY(tx_good_frames),
173 BNXT_TX_STATS_ENTRY(tx_total_frames),
174 BNXT_TX_STATS_ENTRY(tx_ucast_frames),
175 BNXT_TX_STATS_ENTRY(tx_mcast_frames),
176 BNXT_TX_STATS_ENTRY(tx_bcast_frames),
177 BNXT_TX_STATS_ENTRY(tx_pause_frames),
178 BNXT_TX_STATS_ENTRY(tx_pfc_frames),
179 BNXT_TX_STATS_ENTRY(tx_jabber_frames),
180 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
181 BNXT_TX_STATS_ENTRY(tx_err),
182 BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
183 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0),
184 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1),
185 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2),
186 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3),
187 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4),
188 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5),
189 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6),
190 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7),
191 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
192 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
193 BNXT_TX_STATS_ENTRY(tx_total_collisions),
194 BNXT_TX_STATS_ENTRY(tx_bytes),
197 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
199 static int bnxt_get_sset_count(struct net_device *dev, int sset)
201 struct bnxt *bp = netdev_priv(dev);
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;
217 static void bnxt_get_ethtool_stats(struct net_device *dev,
218 struct ethtool_stats *stats, u64 *buf)
221 struct bnxt *bp = netdev_priv(dev);
222 u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings;
223 u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
225 memset(buf, 0, buf_size);
230 for (i = 0; i < bp->cp_nr_rings; i++) {
231 struct bnxt_napi *bnapi = bp->bnapi[i];
232 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
233 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
236 for (k = 0; k < stat_fields; j++, k++)
237 buf[j] = le64_to_cpu(hw_stats[k]);
238 buf[j++] = cpr->rx_l4_csum_errors;
240 if (bp->flags & BNXT_FLAG_PORT_STATS) {
241 __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
243 for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
244 buf[j] = le64_to_cpu(*(port_stats +
245 bnxt_port_stats_arr[i].offset));
250 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
252 struct bnxt *bp = netdev_priv(dev);
256 /* The number of strings must match BNXT_NUM_STATS defined above. */
258 for (i = 0; i < bp->cp_nr_rings; i++) {
259 sprintf(buf, "[%d]: rx_ucast_packets", i);
260 buf += ETH_GSTRING_LEN;
261 sprintf(buf, "[%d]: rx_mcast_packets", i);
262 buf += ETH_GSTRING_LEN;
263 sprintf(buf, "[%d]: rx_bcast_packets", i);
264 buf += ETH_GSTRING_LEN;
265 sprintf(buf, "[%d]: rx_discards", i);
266 buf += ETH_GSTRING_LEN;
267 sprintf(buf, "[%d]: rx_drops", i);
268 buf += ETH_GSTRING_LEN;
269 sprintf(buf, "[%d]: rx_ucast_bytes", i);
270 buf += ETH_GSTRING_LEN;
271 sprintf(buf, "[%d]: rx_mcast_bytes", i);
272 buf += ETH_GSTRING_LEN;
273 sprintf(buf, "[%d]: rx_bcast_bytes", i);
274 buf += ETH_GSTRING_LEN;
275 sprintf(buf, "[%d]: tx_ucast_packets", i);
276 buf += ETH_GSTRING_LEN;
277 sprintf(buf, "[%d]: tx_mcast_packets", i);
278 buf += ETH_GSTRING_LEN;
279 sprintf(buf, "[%d]: tx_bcast_packets", i);
280 buf += ETH_GSTRING_LEN;
281 sprintf(buf, "[%d]: tx_discards", i);
282 buf += ETH_GSTRING_LEN;
283 sprintf(buf, "[%d]: tx_drops", i);
284 buf += ETH_GSTRING_LEN;
285 sprintf(buf, "[%d]: tx_ucast_bytes", i);
286 buf += ETH_GSTRING_LEN;
287 sprintf(buf, "[%d]: tx_mcast_bytes", i);
288 buf += ETH_GSTRING_LEN;
289 sprintf(buf, "[%d]: tx_bcast_bytes", i);
290 buf += ETH_GSTRING_LEN;
291 sprintf(buf, "[%d]: tpa_packets", i);
292 buf += ETH_GSTRING_LEN;
293 sprintf(buf, "[%d]: tpa_bytes", i);
294 buf += ETH_GSTRING_LEN;
295 sprintf(buf, "[%d]: tpa_events", i);
296 buf += ETH_GSTRING_LEN;
297 sprintf(buf, "[%d]: tpa_aborts", i);
298 buf += ETH_GSTRING_LEN;
299 sprintf(buf, "[%d]: rx_l4_csum_errors", i);
300 buf += ETH_GSTRING_LEN;
302 if (bp->flags & BNXT_FLAG_PORT_STATS) {
303 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
304 strcpy(buf, bnxt_port_stats_arr[i].string);
305 buf += ETH_GSTRING_LEN;
310 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
316 static void bnxt_get_ringparam(struct net_device *dev,
317 struct ethtool_ringparam *ering)
319 struct bnxt *bp = netdev_priv(dev);
321 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
322 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
323 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
325 ering->rx_pending = bp->rx_ring_size;
326 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
327 ering->tx_pending = bp->tx_ring_size;
330 static int bnxt_set_ringparam(struct net_device *dev,
331 struct ethtool_ringparam *ering)
333 struct bnxt *bp = netdev_priv(dev);
335 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
336 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
337 (ering->tx_pending <= MAX_SKB_FRAGS))
340 if (netif_running(dev))
341 bnxt_close_nic(bp, false, false);
343 bp->rx_ring_size = ering->rx_pending;
344 bp->tx_ring_size = ering->tx_pending;
345 bnxt_set_ring_params(bp);
347 if (netif_running(dev))
348 return bnxt_open_nic(bp, false, false);
353 static void bnxt_get_channels(struct net_device *dev,
354 struct ethtool_channels *channel)
356 struct bnxt *bp = netdev_priv(dev);
357 int max_rx_rings, max_tx_rings, tcs;
359 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
360 channel->max_combined = max_t(int, max_rx_rings, max_tx_rings);
362 if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
367 tcs = netdev_get_num_tc(dev);
371 channel->max_rx = max_rx_rings;
372 channel->max_tx = max_tx_rings;
373 channel->max_other = 0;
374 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
375 channel->combined_count = bp->rx_nr_rings;
376 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
377 channel->combined_count--;
379 if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
380 channel->rx_count = bp->rx_nr_rings;
381 channel->tx_count = bp->tx_nr_rings_per_tc;
386 static int bnxt_set_channels(struct net_device *dev,
387 struct ethtool_channels *channel)
389 struct bnxt *bp = netdev_priv(dev);
390 int max_rx_rings, max_tx_rings, tcs;
394 if (channel->other_count)
397 if (!channel->combined_count &&
398 (!channel->rx_count || !channel->tx_count))
401 if (channel->combined_count &&
402 (channel->rx_count || channel->tx_count))
405 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
409 if (channel->combined_count)
412 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh);
414 tcs = netdev_get_num_tc(dev);
419 channel->combined_count > max_t(int, max_rx_rings, max_tx_rings))
422 if (!sh && (channel->rx_count > max_rx_rings ||
423 channel->tx_count > max_tx_rings))
426 if (netif_running(dev)) {
428 /* TODO CHIMP_FW: Send message to all VF's
432 rc = bnxt_close_nic(bp, true, false);
434 netdev_err(bp->dev, "Set channel failure rc :%x\n",
441 bp->flags |= BNXT_FLAG_SHARED_RINGS;
442 bp->rx_nr_rings = min_t(int, channel->combined_count,
444 bp->tx_nr_rings_per_tc = min_t(int, channel->combined_count,
447 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
448 bp->rx_nr_rings = channel->rx_count;
449 bp->tx_nr_rings_per_tc = channel->tx_count;
452 bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
454 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs;
456 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
457 bp->tx_nr_rings + bp->rx_nr_rings;
459 bp->num_stat_ctxs = bp->cp_nr_rings;
461 /* After changing number of rx channels, update NTUPLE feature. */
462 netdev_update_features(dev);
463 if (netif_running(dev)) {
464 rc = bnxt_open_nic(bp, true, false);
465 if ((!rc) && BNXT_PF(bp)) {
466 /* TODO CHIMP_FW: Send message to all VF's
475 #ifdef CONFIG_RFS_ACCEL
476 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
481 cmd->data = bp->ntp_fltr_count;
482 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
483 struct hlist_head *head;
484 struct bnxt_ntuple_filter *fltr;
486 head = &bp->ntp_fltr_hash_tbl[i];
488 hlist_for_each_entry_rcu(fltr, head, hash) {
489 if (j == cmd->rule_cnt)
491 rule_locs[j++] = fltr->sw_id;
494 if (j == cmd->rule_cnt)
501 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
503 struct ethtool_rx_flow_spec *fs =
504 (struct ethtool_rx_flow_spec *)&cmd->fs;
505 struct bnxt_ntuple_filter *fltr;
506 struct flow_keys *fkeys;
509 if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
512 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
513 struct hlist_head *head;
515 head = &bp->ntp_fltr_hash_tbl[i];
517 hlist_for_each_entry_rcu(fltr, head, hash) {
518 if (fltr->sw_id == fs->location)
526 fkeys = &fltr->fkeys;
527 if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
528 if (fkeys->basic.ip_proto == IPPROTO_TCP)
529 fs->flow_type = TCP_V4_FLOW;
530 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
531 fs->flow_type = UDP_V4_FLOW;
535 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
536 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
538 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
539 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
541 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
542 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
544 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
545 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
549 if (fkeys->basic.ip_proto == IPPROTO_TCP)
550 fs->flow_type = TCP_V6_FLOW;
551 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
552 fs->flow_type = UDP_V6_FLOW;
556 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] =
557 fkeys->addrs.v6addrs.src;
558 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] =
559 fkeys->addrs.v6addrs.dst;
560 for (i = 0; i < 4; i++) {
561 fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0);
562 fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0);
564 fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src;
565 fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0);
567 fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst;
568 fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0);
571 fs->ring_cookie = fltr->rxq;
581 static u64 get_ethtool_ipv4_rss(struct bnxt *bp)
583 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4)
584 return RXH_IP_SRC | RXH_IP_DST;
588 static u64 get_ethtool_ipv6_rss(struct bnxt *bp)
590 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6)
591 return RXH_IP_SRC | RXH_IP_DST;
595 static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
598 switch (cmd->flow_type) {
600 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4)
601 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
602 RXH_L4_B_0_1 | RXH_L4_B_2_3;
603 cmd->data |= get_ethtool_ipv4_rss(bp);
606 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)
607 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
608 RXH_L4_B_0_1 | RXH_L4_B_2_3;
615 cmd->data |= get_ethtool_ipv4_rss(bp);
619 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6)
620 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
621 RXH_L4_B_0_1 | RXH_L4_B_2_3;
622 cmd->data |= get_ethtool_ipv6_rss(bp);
625 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)
626 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
627 RXH_L4_B_0_1 | RXH_L4_B_2_3;
634 cmd->data |= get_ethtool_ipv6_rss(bp);
640 #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
641 #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
643 static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
645 u32 rss_hash_cfg = bp->rss_hash_cfg;
648 if (cmd->data == RXH_4TUPLE)
650 else if (cmd->data == RXH_2TUPLE)
657 if (cmd->flow_type == TCP_V4_FLOW) {
658 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
660 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
661 } else if (cmd->flow_type == UDP_V4_FLOW) {
662 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
664 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
666 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
667 } else if (cmd->flow_type == TCP_V6_FLOW) {
668 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
670 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
671 } else if (cmd->flow_type == UDP_V6_FLOW) {
672 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
674 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
676 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
677 } else if (tuple == 4) {
681 switch (cmd->flow_type) {
690 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
692 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
703 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
705 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
709 if (bp->rss_hash_cfg == rss_hash_cfg)
712 bp->rss_hash_cfg = rss_hash_cfg;
713 if (netif_running(bp->dev)) {
714 bnxt_close_nic(bp, false, false);
715 rc = bnxt_open_nic(bp, false, false);
720 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
723 struct bnxt *bp = netdev_priv(dev);
727 #ifdef CONFIG_RFS_ACCEL
728 case ETHTOOL_GRXRINGS:
729 cmd->data = bp->rx_nr_rings;
732 case ETHTOOL_GRXCLSRLCNT:
733 cmd->rule_cnt = bp->ntp_fltr_count;
734 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
737 case ETHTOOL_GRXCLSRLALL:
738 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
741 case ETHTOOL_GRXCLSRULE:
742 rc = bnxt_grxclsrule(bp, cmd);
747 rc = bnxt_grxfh(bp, cmd);
758 static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
760 struct bnxt *bp = netdev_priv(dev);
765 rc = bnxt_srxfh(bp, cmd);
775 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
777 return HW_HASH_INDEX_SIZE;
780 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
782 return HW_HASH_KEY_SIZE;
785 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
788 struct bnxt *bp = netdev_priv(dev);
789 struct bnxt_vnic_info *vnic = &bp->vnic_info[0];
793 *hfunc = ETH_RSS_HASH_TOP;
796 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
797 indir[i] = le16_to_cpu(vnic->rss_table[i]);
800 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
805 static void bnxt_get_drvinfo(struct net_device *dev,
806 struct ethtool_drvinfo *info)
808 struct bnxt *bp = netdev_priv(dev);
812 pkglog = kmalloc(BNX_PKG_LOG_MAX_LENGTH, GFP_KERNEL);
814 pkgver = bnxt_get_pkgver(dev, pkglog, BNX_PKG_LOG_MAX_LENGTH);
815 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
816 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
817 if (pkgver && *pkgver != 0 && isdigit(*pkgver))
818 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
819 "%s pkg %s", bp->fw_ver_str, pkgver);
821 strlcpy(info->fw_version, bp->fw_ver_str,
822 sizeof(info->fw_version));
823 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
824 info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
825 info->testinfo_len = BNXT_NUM_TESTS(bp);
826 /* TODO CHIMP_FW: eeprom dump details */
827 info->eedump_len = 0;
828 /* TODO CHIMP FW: reg dump details */
829 info->regdump_len = 0;
833 u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
837 /* TODO: support 25GB, 40GB, 50GB with different cable type */
838 /* set the advertised speeds */
839 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
840 speed_mask |= ADVERTISED_100baseT_Full;
841 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
842 speed_mask |= ADVERTISED_1000baseT_Full;
843 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
844 speed_mask |= ADVERTISED_2500baseX_Full;
845 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
846 speed_mask |= ADVERTISED_10000baseT_Full;
847 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
848 speed_mask |= ADVERTISED_40000baseCR4_Full;
850 if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
851 speed_mask |= ADVERTISED_Pause;
852 else if (fw_pause & BNXT_LINK_PAUSE_TX)
853 speed_mask |= ADVERTISED_Asym_Pause;
854 else if (fw_pause & BNXT_LINK_PAUSE_RX)
855 speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
860 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
862 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
863 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
865 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
866 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
868 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
869 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
871 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
872 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
874 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
875 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
877 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
878 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
880 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
881 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
883 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
884 ethtool_link_ksettings_add_link_mode( \
885 lk_ksettings, name, Asym_Pause);\
886 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
887 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
892 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
894 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
896 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
898 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
899 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
901 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
903 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
904 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
906 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
907 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
909 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
910 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
911 40000baseCR4_Full)) \
912 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
913 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
914 50000baseCR2_Full)) \
915 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
918 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
919 struct ethtool_link_ksettings *lk_ksettings)
921 u16 fw_speeds = link_info->advertising;
924 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
925 fw_pause = link_info->auto_pause_setting;
927 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
930 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
931 struct ethtool_link_ksettings *lk_ksettings)
933 u16 fw_speeds = link_info->lp_auto_link_speeds;
936 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
937 fw_pause = link_info->lp_pause;
939 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
943 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
944 struct ethtool_link_ksettings *lk_ksettings)
946 u16 fw_speeds = link_info->support_speeds;
948 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
950 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
951 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
954 if (link_info->support_auto_speeds)
955 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
959 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
961 switch (fw_link_speed) {
962 case BNXT_LINK_SPEED_100MB:
964 case BNXT_LINK_SPEED_1GB:
966 case BNXT_LINK_SPEED_2_5GB:
968 case BNXT_LINK_SPEED_10GB:
970 case BNXT_LINK_SPEED_20GB:
972 case BNXT_LINK_SPEED_25GB:
974 case BNXT_LINK_SPEED_40GB:
976 case BNXT_LINK_SPEED_50GB:
979 return SPEED_UNKNOWN;
983 static int bnxt_get_link_ksettings(struct net_device *dev,
984 struct ethtool_link_ksettings *lk_ksettings)
986 struct bnxt *bp = netdev_priv(dev);
987 struct bnxt_link_info *link_info = &bp->link_info;
988 struct ethtool_link_settings *base = &lk_ksettings->base;
991 ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
992 bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
994 ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
995 if (link_info->autoneg) {
996 bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
997 ethtool_link_ksettings_add_link_mode(lk_ksettings,
998 advertising, Autoneg);
999 base->autoneg = AUTONEG_ENABLE;
1000 if (link_info->phy_link_status == BNXT_LINK_LINK)
1001 bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
1002 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
1003 if (!netif_carrier_ok(dev))
1004 base->duplex = DUPLEX_UNKNOWN;
1005 else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
1006 base->duplex = DUPLEX_FULL;
1008 base->duplex = DUPLEX_HALF;
1010 base->autoneg = AUTONEG_DISABLE;
1012 bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
1013 base->duplex = DUPLEX_HALF;
1014 if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
1015 base->duplex = DUPLEX_FULL;
1017 base->speed = ethtool_speed;
1019 base->port = PORT_NONE;
1020 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1021 base->port = PORT_TP;
1022 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1024 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1027 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1029 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1032 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
1033 base->port = PORT_DA;
1034 else if (link_info->media_type ==
1035 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
1036 base->port = PORT_FIBRE;
1038 base->phy_address = link_info->phy_addr;
1043 static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed)
1045 struct bnxt *bp = netdev_priv(dev);
1046 struct bnxt_link_info *link_info = &bp->link_info;
1047 u16 support_spds = link_info->support_speeds;
1050 switch (ethtool_speed) {
1052 if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
1053 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
1056 if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
1057 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
1060 if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
1061 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
1064 if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
1065 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
1068 if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
1069 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
1072 if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
1073 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
1076 if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
1077 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
1080 if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
1081 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
1084 netdev_err(dev, "unsupported speed!\n");
1090 u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
1092 u16 fw_speed_mask = 0;
1094 /* only support autoneg at speed 100, 1000, and 10000 */
1095 if (advertising & (ADVERTISED_100baseT_Full |
1096 ADVERTISED_100baseT_Half)) {
1097 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
1099 if (advertising & (ADVERTISED_1000baseT_Full |
1100 ADVERTISED_1000baseT_Half)) {
1101 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
1103 if (advertising & ADVERTISED_10000baseT_Full)
1104 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
1106 if (advertising & ADVERTISED_40000baseCR4_Full)
1107 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
1109 return fw_speed_mask;
1112 static int bnxt_set_link_ksettings(struct net_device *dev,
1113 const struct ethtool_link_ksettings *lk_ksettings)
1115 struct bnxt *bp = netdev_priv(dev);
1116 struct bnxt_link_info *link_info = &bp->link_info;
1117 const struct ethtool_link_settings *base = &lk_ksettings->base;
1118 bool set_pause = false;
1119 u16 fw_advertising = 0;
1123 if (!BNXT_SINGLE_PF(bp))
1126 if (base->autoneg == AUTONEG_ENABLE) {
1127 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
1129 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1130 if (!fw_advertising)
1131 link_info->advertising = link_info->support_auto_speeds;
1133 link_info->advertising = fw_advertising;
1134 /* any change to autoneg will cause link change, therefore the
1135 * driver should put back the original pause setting in autoneg
1140 u8 phy_type = link_info->phy_type;
1142 if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET ||
1143 phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
1144 link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1145 netdev_err(dev, "10GBase-T devices must autoneg\n");
1147 goto set_setting_exit;
1149 if (base->duplex == DUPLEX_HALF) {
1150 netdev_err(dev, "HALF DUPLEX is not supported!\n");
1152 goto set_setting_exit;
1154 speed = base->speed;
1155 fw_speed = bnxt_get_fw_speed(dev, speed);
1158 goto set_setting_exit;
1160 link_info->req_link_speed = fw_speed;
1161 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
1162 link_info->autoneg = 0;
1163 link_info->advertising = 0;
1166 if (netif_running(dev))
1167 rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
1173 static void bnxt_get_pauseparam(struct net_device *dev,
1174 struct ethtool_pauseparam *epause)
1176 struct bnxt *bp = netdev_priv(dev);
1177 struct bnxt_link_info *link_info = &bp->link_info;
1181 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
1182 epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
1183 epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
1186 static int bnxt_set_pauseparam(struct net_device *dev,
1187 struct ethtool_pauseparam *epause)
1190 struct bnxt *bp = netdev_priv(dev);
1191 struct bnxt_link_info *link_info = &bp->link_info;
1193 if (!BNXT_SINGLE_PF(bp))
1196 if (epause->autoneg) {
1197 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1200 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1201 if (bp->hwrm_spec_code >= 0x10201)
1202 link_info->req_flow_ctrl =
1203 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
1205 /* when transition from auto pause to force pause,
1206 * force a link change
1208 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1209 link_info->force_link_chng = true;
1210 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1211 link_info->req_flow_ctrl = 0;
1213 if (epause->rx_pause)
1214 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1216 if (epause->tx_pause)
1217 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1219 if (netif_running(dev))
1220 rc = bnxt_hwrm_set_pause(bp);
1224 static u32 bnxt_get_link(struct net_device *dev)
1226 struct bnxt *bp = netdev_priv(dev);
1228 /* TODO: handle MF, VF, driver close case */
1229 return bp->link_info.link_up;
1232 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1233 u16 ext, u16 *index, u32 *item_length,
1236 static int bnxt_flash_nvram(struct net_device *dev,
1244 struct bnxt *bp = netdev_priv(dev);
1246 struct hwrm_nvm_write_input req = {0};
1247 dma_addr_t dma_handle;
1250 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1252 req.dir_type = cpu_to_le16(dir_type);
1253 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1254 req.dir_ext = cpu_to_le16(dir_ext);
1255 req.dir_attr = cpu_to_le16(dir_attr);
1256 req.dir_data_length = cpu_to_le32(data_len);
1258 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1261 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1262 (unsigned)data_len);
1265 memcpy(kmem, data, data_len);
1266 req.host_src_addr = cpu_to_le64(dma_handle);
1268 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1269 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1274 static int bnxt_firmware_reset(struct net_device *dev,
1277 struct bnxt *bp = netdev_priv(dev);
1278 struct hwrm_fw_reset_input req = {0};
1280 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1282 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1283 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1284 /* (e.g. when firmware isn't already running) */
1286 case BNX_DIR_TYPE_CHIMP_PATCH:
1287 case BNX_DIR_TYPE_BOOTCODE:
1288 case BNX_DIR_TYPE_BOOTCODE_2:
1289 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1290 /* Self-reset ChiMP upon next PCIe reset: */
1291 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1293 case BNX_DIR_TYPE_APE_FW:
1294 case BNX_DIR_TYPE_APE_PATCH:
1295 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1296 /* Self-reset APE upon next PCIe reset: */
1297 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1299 case BNX_DIR_TYPE_KONG_FW:
1300 case BNX_DIR_TYPE_KONG_PATCH:
1301 req.embedded_proc_type =
1302 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1304 case BNX_DIR_TYPE_BONO_FW:
1305 case BNX_DIR_TYPE_BONO_PATCH:
1306 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1312 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1315 static int bnxt_flash_firmware(struct net_device *dev,
1324 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1327 case BNX_DIR_TYPE_BOOTCODE:
1328 case BNX_DIR_TYPE_BOOTCODE_2:
1329 code_type = CODE_BOOT;
1331 case BNX_DIR_TYPE_CHIMP_PATCH:
1332 code_type = CODE_CHIMP_PATCH;
1334 case BNX_DIR_TYPE_APE_FW:
1335 code_type = CODE_MCTP_PASSTHRU;
1337 case BNX_DIR_TYPE_APE_PATCH:
1338 code_type = CODE_APE_PATCH;
1340 case BNX_DIR_TYPE_KONG_FW:
1341 code_type = CODE_KONG_FW;
1343 case BNX_DIR_TYPE_KONG_PATCH:
1344 code_type = CODE_KONG_PATCH;
1346 case BNX_DIR_TYPE_BONO_FW:
1347 code_type = CODE_BONO_FW;
1349 case BNX_DIR_TYPE_BONO_PATCH:
1350 code_type = CODE_BONO_PATCH;
1353 netdev_err(dev, "Unsupported directory entry type: %u\n",
1357 if (fw_size < sizeof(struct bnxt_fw_header)) {
1358 netdev_err(dev, "Invalid firmware file size: %u\n",
1359 (unsigned int)fw_size);
1362 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1363 netdev_err(dev, "Invalid firmware signature: %08X\n",
1364 le32_to_cpu(header->signature));
1367 if (header->code_type != code_type) {
1368 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1369 code_type, header->code_type);
1372 if (header->device != DEVICE_CUMULUS_FAMILY) {
1373 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1374 DEVICE_CUMULUS_FAMILY, header->device);
1377 /* Confirm the CRC32 checksum of the file: */
1378 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1379 sizeof(stored_crc)));
1380 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1381 if (calculated_crc != stored_crc) {
1382 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1383 (unsigned long)stored_crc,
1384 (unsigned long)calculated_crc);
1387 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1388 0, 0, fw_data, fw_size);
1389 if (rc == 0) /* Firmware update successful */
1390 rc = bnxt_firmware_reset(dev, dir_type);
1395 static int bnxt_flash_microcode(struct net_device *dev,
1400 struct bnxt_ucode_trailer *trailer;
1405 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1406 netdev_err(dev, "Invalid microcode file size: %u\n",
1407 (unsigned int)fw_size);
1410 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1412 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1413 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1414 le32_to_cpu(trailer->sig));
1417 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1418 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1419 dir_type, le16_to_cpu(trailer->dir_type));
1422 if (le16_to_cpu(trailer->trailer_length) <
1423 sizeof(struct bnxt_ucode_trailer)) {
1424 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1425 le16_to_cpu(trailer->trailer_length));
1429 /* Confirm the CRC32 checksum of the file: */
1430 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1431 sizeof(stored_crc)));
1432 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1433 if (calculated_crc != stored_crc) {
1435 "CRC32 (%08lX) does not match calculated: %08lX\n",
1436 (unsigned long)stored_crc,
1437 (unsigned long)calculated_crc);
1440 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1441 0, 0, fw_data, fw_size);
1446 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1449 case BNX_DIR_TYPE_CHIMP_PATCH:
1450 case BNX_DIR_TYPE_BOOTCODE:
1451 case BNX_DIR_TYPE_BOOTCODE_2:
1452 case BNX_DIR_TYPE_APE_FW:
1453 case BNX_DIR_TYPE_APE_PATCH:
1454 case BNX_DIR_TYPE_KONG_FW:
1455 case BNX_DIR_TYPE_KONG_PATCH:
1456 case BNX_DIR_TYPE_BONO_FW:
1457 case BNX_DIR_TYPE_BONO_PATCH:
1464 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1467 case BNX_DIR_TYPE_AVS:
1468 case BNX_DIR_TYPE_EXP_ROM_MBA:
1469 case BNX_DIR_TYPE_PCIE:
1470 case BNX_DIR_TYPE_TSCF_UCODE:
1471 case BNX_DIR_TYPE_EXT_PHY:
1472 case BNX_DIR_TYPE_CCM:
1473 case BNX_DIR_TYPE_ISCSI_BOOT:
1474 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1475 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1482 static bool bnxt_dir_type_is_executable(u16 dir_type)
1484 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1485 bnxt_dir_type_is_other_exec_format(dir_type);
1488 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1490 const char *filename)
1492 const struct firmware *fw;
1495 rc = request_firmware(&fw, filename, &dev->dev);
1497 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1501 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1502 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1503 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1504 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1506 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1507 0, 0, fw->data, fw->size);
1508 release_firmware(fw);
1512 static int bnxt_flash_package_from_file(struct net_device *dev,
1513 char *filename, u32 install_type)
1515 struct bnxt *bp = netdev_priv(dev);
1516 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
1517 struct hwrm_nvm_install_update_input install = {0};
1518 const struct firmware *fw;
1523 bnxt_hwrm_fw_set_time(bp);
1525 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
1526 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1527 &index, &item_len, NULL) != 0) {
1528 netdev_err(dev, "PKG update area not created in nvram\n");
1532 rc = request_firmware(&fw, filename, &dev->dev);
1534 netdev_err(dev, "PKG error %d requesting file: %s\n",
1539 if (fw->size > item_len) {
1540 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
1541 (unsigned long)fw->size);
1544 dma_addr_t dma_handle;
1546 struct hwrm_nvm_modify_input modify = {0};
1548 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
1550 modify.dir_idx = cpu_to_le16(index);
1551 modify.len = cpu_to_le32(fw->size);
1553 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
1554 &dma_handle, GFP_KERNEL);
1557 "dma_alloc_coherent failure, length = %u\n",
1558 (unsigned int)fw->size);
1561 memcpy(kmem, fw->data, fw->size);
1562 modify.host_src_addr = cpu_to_le64(dma_handle);
1564 rc = hwrm_send_message(bp, &modify, sizeof(modify),
1565 FLASH_PACKAGE_TIMEOUT);
1566 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
1570 release_firmware(fw);
1574 if ((install_type & 0xffff) == 0)
1575 install_type >>= 16;
1576 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
1577 install.install_type = cpu_to_le32(install_type);
1579 rc = hwrm_send_message(bp, &install, sizeof(install),
1580 INSTALL_PACKAGE_TIMEOUT);
1585 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
1586 (s8)resp->result, (int)resp->problem_item);
1592 static int bnxt_flash_device(struct net_device *dev,
1593 struct ethtool_flash *flash)
1595 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
1596 netdev_err(dev, "flashdev not supported from a virtual function\n");
1600 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
1601 flash->region > 0xffff)
1602 return bnxt_flash_package_from_file(dev, flash->data,
1605 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
1608 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
1610 struct bnxt *bp = netdev_priv(dev);
1612 struct hwrm_nvm_get_dir_info_input req = {0};
1613 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
1615 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
1617 mutex_lock(&bp->hwrm_cmd_lock);
1618 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1620 *entries = le32_to_cpu(output->entries);
1621 *length = le32_to_cpu(output->entry_length);
1623 mutex_unlock(&bp->hwrm_cmd_lock);
1627 static int bnxt_get_eeprom_len(struct net_device *dev)
1629 /* The -1 return value allows the entire 32-bit range of offsets to be
1630 * passed via the ethtool command-line utility.
1635 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1637 struct bnxt *bp = netdev_priv(dev);
1643 dma_addr_t dma_handle;
1644 struct hwrm_nvm_get_dir_entries_input req = {0};
1646 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
1650 /* Insert 2 bytes of directory info (count and size of entries) */
1654 *data++ = dir_entries;
1655 *data++ = entry_length;
1657 memset(data, 0xff, len);
1659 buflen = dir_entries * entry_length;
1660 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
1663 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1667 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
1668 req.host_dest_addr = cpu_to_le64(dma_handle);
1669 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1671 memcpy(data, buf, len > buflen ? buflen : len);
1672 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
1676 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
1677 u32 length, u8 *data)
1679 struct bnxt *bp = netdev_priv(dev);
1682 dma_addr_t dma_handle;
1683 struct hwrm_nvm_read_input req = {0};
1685 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
1688 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1692 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
1693 req.host_dest_addr = cpu_to_le64(dma_handle);
1694 req.dir_idx = cpu_to_le16(index);
1695 req.offset = cpu_to_le32(offset);
1696 req.len = cpu_to_le32(length);
1698 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1700 memcpy(data, buf, length);
1701 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
1705 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1706 u16 ext, u16 *index, u32 *item_length,
1709 struct bnxt *bp = netdev_priv(dev);
1711 struct hwrm_nvm_find_dir_entry_input req = {0};
1712 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
1714 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
1717 req.dir_type = cpu_to_le16(type);
1718 req.dir_ordinal = cpu_to_le16(ordinal);
1719 req.dir_ext = cpu_to_le16(ext);
1720 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
1721 rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1724 *index = le16_to_cpu(output->dir_idx);
1726 *item_length = le32_to_cpu(output->dir_item_length);
1728 *data_length = le32_to_cpu(output->dir_data_length);
1733 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
1735 char *retval = NULL;
1742 /* null-terminate the log data (removing last '\n'): */
1743 data[datalen - 1] = 0;
1744 for (p = data; *p != 0; p++) {
1747 while (*p != 0 && *p != '\n') {
1749 while (*p != 0 && *p != '\t' && *p != '\n')
1751 if (field == desired_field)
1766 static char *bnxt_get_pkgver(struct net_device *dev, char *buf, size_t buflen)
1771 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
1772 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
1773 &index, NULL, &datalen) != 0)
1776 memset(buf, 0, buflen);
1777 if (bnxt_get_nvram_item(dev, index, 0, datalen, buf) != 0)
1780 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, buf,
1784 static int bnxt_get_eeprom(struct net_device *dev,
1785 struct ethtool_eeprom *eeprom,
1791 if (eeprom->offset == 0) /* special offset value to get directory */
1792 return bnxt_get_nvram_directory(dev, eeprom->len, data);
1794 index = eeprom->offset >> 24;
1795 offset = eeprom->offset & 0xffffff;
1798 netdev_err(dev, "unsupported index value: %d\n", index);
1802 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
1805 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
1807 struct bnxt *bp = netdev_priv(dev);
1808 struct hwrm_nvm_erase_dir_entry_input req = {0};
1810 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
1811 req.dir_idx = cpu_to_le16(index);
1812 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1815 static int bnxt_set_eeprom(struct net_device *dev,
1816 struct ethtool_eeprom *eeprom,
1819 struct bnxt *bp = netdev_priv(dev);
1821 u16 type, ext, ordinal, attr;
1824 netdev_err(dev, "NVM write not supported from a virtual function\n");
1828 type = eeprom->magic >> 16;
1830 if (type == 0xffff) { /* special value for directory operations */
1831 index = eeprom->magic & 0xff;
1832 dir_op = eeprom->magic >> 8;
1836 case 0x0e: /* erase */
1837 if (eeprom->offset != ~eeprom->magic)
1839 return bnxt_erase_nvram_directory(dev, index - 1);
1845 /* Create or re-write an NVM item: */
1846 if (bnxt_dir_type_is_executable(type) == true)
1848 ext = eeprom->magic & 0xffff;
1849 ordinal = eeprom->offset >> 16;
1850 attr = eeprom->offset & 0xffff;
1852 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
1856 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1858 struct bnxt *bp = netdev_priv(dev);
1859 struct ethtool_eee *eee = &bp->eee;
1860 struct bnxt_link_info *link_info = &bp->link_info;
1862 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
1865 if (!BNXT_SINGLE_PF(bp))
1868 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1871 if (!edata->eee_enabled)
1874 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
1875 netdev_warn(dev, "EEE requires autoneg\n");
1878 if (edata->tx_lpi_enabled) {
1879 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
1880 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
1881 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
1882 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
1884 } else if (!bp->lpi_tmr_hi) {
1885 edata->tx_lpi_timer = eee->tx_lpi_timer;
1888 if (!edata->advertised) {
1889 edata->advertised = advertising & eee->supported;
1890 } else if (edata->advertised & ~advertising) {
1891 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
1892 edata->advertised, advertising);
1896 eee->advertised = edata->advertised;
1897 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
1898 eee->tx_lpi_timer = edata->tx_lpi_timer;
1900 eee->eee_enabled = edata->eee_enabled;
1902 if (netif_running(dev))
1903 rc = bnxt_hwrm_set_link_setting(bp, false, true);
1908 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1910 struct bnxt *bp = netdev_priv(dev);
1912 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
1916 if (!bp->eee.eee_enabled) {
1917 /* Preserve tx_lpi_timer so that the last value will be used
1918 * by default when it is re-enabled.
1920 edata->advertised = 0;
1921 edata->tx_lpi_enabled = 0;
1924 if (!bp->eee.eee_active)
1925 edata->lp_advertised = 0;
1930 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
1931 u16 page_number, u16 start_addr,
1932 u16 data_length, u8 *buf)
1934 struct hwrm_port_phy_i2c_read_input req = {0};
1935 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1936 int rc, byte_offset = 0;
1938 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1939 req.i2c_slave_addr = i2c_addr;
1940 req.page_number = cpu_to_le16(page_number);
1941 req.port_id = cpu_to_le16(bp->pf.port_id);
1945 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
1946 data_length -= xfer_size;
1947 req.page_offset = cpu_to_le16(start_addr + byte_offset);
1948 req.data_length = xfer_size;
1949 req.enables = cpu_to_le32(start_addr + byte_offset ?
1950 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
1951 mutex_lock(&bp->hwrm_cmd_lock);
1952 rc = _hwrm_send_message(bp, &req, sizeof(req),
1955 memcpy(buf + byte_offset, output->data, xfer_size);
1956 mutex_unlock(&bp->hwrm_cmd_lock);
1957 byte_offset += xfer_size;
1958 } while (!rc && data_length > 0);
1963 static int bnxt_get_module_info(struct net_device *dev,
1964 struct ethtool_modinfo *modinfo)
1966 struct bnxt *bp = netdev_priv(dev);
1967 struct hwrm_port_phy_i2c_read_input req = {0};
1968 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
1971 /* No point in going further if phy status indicates
1972 * module is not inserted or if it is powered down or
1973 * if it is of type 10GBase-T
1975 if (bp->link_info.module_status >
1976 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
1979 /* This feature is not supported in older firmware versions */
1980 if (bp->hwrm_spec_code < 0x10202)
1983 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
1984 req.i2c_slave_addr = I2C_DEV_ADDR_A0;
1985 req.page_number = 0;
1986 req.page_offset = cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR);
1987 req.data_length = SFP_EEPROM_SFF_8472_COMP_SIZE;
1988 req.port_id = cpu_to_le16(bp->pf.port_id);
1989 mutex_lock(&bp->hwrm_cmd_lock);
1990 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1992 u32 module_id = le32_to_cpu(output->data[0]);
1994 switch (module_id) {
1995 case SFF_MODULE_ID_SFP:
1996 modinfo->type = ETH_MODULE_SFF_8472;
1997 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1999 case SFF_MODULE_ID_QSFP:
2000 case SFF_MODULE_ID_QSFP_PLUS:
2001 modinfo->type = ETH_MODULE_SFF_8436;
2002 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
2004 case SFF_MODULE_ID_QSFP28:
2005 modinfo->type = ETH_MODULE_SFF_8636;
2006 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
2013 mutex_unlock(&bp->hwrm_cmd_lock);
2017 static int bnxt_get_module_eeprom(struct net_device *dev,
2018 struct ethtool_eeprom *eeprom,
2021 struct bnxt *bp = netdev_priv(dev);
2022 u16 start = eeprom->offset, length = eeprom->len;
2025 memset(data, 0, eeprom->len);
2027 /* Read A0 portion of the EEPROM */
2028 if (start < ETH_MODULE_SFF_8436_LEN) {
2029 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
2030 length = ETH_MODULE_SFF_8436_LEN - start;
2031 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
2032 start, length, data);
2037 length = eeprom->len - length;
2040 /* Read A2 portion of the EEPROM */
2042 start -= ETH_MODULE_SFF_8436_LEN;
2043 bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1, start,
2049 static int bnxt_nway_reset(struct net_device *dev)
2053 struct bnxt *bp = netdev_priv(dev);
2054 struct bnxt_link_info *link_info = &bp->link_info;
2056 if (!BNXT_SINGLE_PF(bp))
2059 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
2062 if (netif_running(dev))
2063 rc = bnxt_hwrm_set_link_setting(bp, true, false);
2068 const struct ethtool_ops bnxt_ethtool_ops = {
2069 .get_link_ksettings = bnxt_get_link_ksettings,
2070 .set_link_ksettings = bnxt_set_link_ksettings,
2071 .get_pauseparam = bnxt_get_pauseparam,
2072 .set_pauseparam = bnxt_set_pauseparam,
2073 .get_drvinfo = bnxt_get_drvinfo,
2074 .get_coalesce = bnxt_get_coalesce,
2075 .set_coalesce = bnxt_set_coalesce,
2076 .get_msglevel = bnxt_get_msglevel,
2077 .set_msglevel = bnxt_set_msglevel,
2078 .get_sset_count = bnxt_get_sset_count,
2079 .get_strings = bnxt_get_strings,
2080 .get_ethtool_stats = bnxt_get_ethtool_stats,
2081 .set_ringparam = bnxt_set_ringparam,
2082 .get_ringparam = bnxt_get_ringparam,
2083 .get_channels = bnxt_get_channels,
2084 .set_channels = bnxt_set_channels,
2085 .get_rxnfc = bnxt_get_rxnfc,
2086 .set_rxnfc = bnxt_set_rxnfc,
2087 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
2088 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
2089 .get_rxfh = bnxt_get_rxfh,
2090 .flash_device = bnxt_flash_device,
2091 .get_eeprom_len = bnxt_get_eeprom_len,
2092 .get_eeprom = bnxt_get_eeprom,
2093 .set_eeprom = bnxt_set_eeprom,
2094 .get_link = bnxt_get_link,
2095 .get_eee = bnxt_get_eee,
2096 .set_eee = bnxt_set_eee,
2097 .get_module_info = bnxt_get_module_info,
2098 .get_module_eeprom = bnxt_get_module_eeprom,
2099 .nway_reset = bnxt_nway_reset