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)
25 static char *bnxt_get_pkgver(struct net_device
*dev
, char *buf
, size_t buflen
);
27 static u32
bnxt_get_msglevel(struct net_device
*dev
)
29 struct bnxt
*bp
= netdev_priv(dev
);
31 return bp
->msg_enable
;
34 static void bnxt_set_msglevel(struct net_device
*dev
, u32 value
)
36 struct bnxt
*bp
= netdev_priv(dev
);
38 bp
->msg_enable
= value
;
41 static int bnxt_get_coalesce(struct net_device
*dev
,
42 struct ethtool_coalesce
*coal
)
44 struct bnxt
*bp
= netdev_priv(dev
);
46 memset(coal
, 0, sizeof(*coal
));
48 coal
->rx_coalesce_usecs
= bp
->rx_coal_ticks
;
49 /* 2 completion records per rx packet */
50 coal
->rx_max_coalesced_frames
= bp
->rx_coal_bufs
/ 2;
51 coal
->rx_coalesce_usecs_irq
= bp
->rx_coal_ticks_irq
;
52 coal
->rx_max_coalesced_frames_irq
= bp
->rx_coal_bufs_irq
/ 2;
54 coal
->tx_coalesce_usecs
= bp
->tx_coal_ticks
;
55 coal
->tx_max_coalesced_frames
= bp
->tx_coal_bufs
;
56 coal
->tx_coalesce_usecs_irq
= bp
->tx_coal_ticks_irq
;
57 coal
->tx_max_coalesced_frames_irq
= bp
->tx_coal_bufs_irq
;
62 static int bnxt_set_coalesce(struct net_device
*dev
,
63 struct ethtool_coalesce
*coal
)
65 struct bnxt
*bp
= netdev_priv(dev
);
68 bp
->rx_coal_ticks
= coal
->rx_coalesce_usecs
;
69 /* 2 completion records per rx packet */
70 bp
->rx_coal_bufs
= coal
->rx_max_coalesced_frames
* 2;
71 bp
->rx_coal_ticks_irq
= coal
->rx_coalesce_usecs_irq
;
72 bp
->rx_coal_bufs_irq
= coal
->rx_max_coalesced_frames_irq
* 2;
74 bp
->tx_coal_ticks
= coal
->tx_coalesce_usecs
;
75 bp
->tx_coal_bufs
= coal
->tx_max_coalesced_frames
;
76 bp
->tx_coal_ticks_irq
= coal
->tx_coalesce_usecs_irq
;
77 bp
->tx_coal_bufs_irq
= coal
->tx_max_coalesced_frames_irq
;
79 if (netif_running(dev
))
80 rc
= bnxt_hwrm_set_coal(bp
);
85 #define BNXT_NUM_STATS 21
87 #define BNXT_RX_STATS_OFFSET(counter) \
88 (offsetof(struct rx_port_stats, counter) / 8)
90 #define BNXT_RX_STATS_ENTRY(counter) \
91 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
93 #define BNXT_TX_STATS_OFFSET(counter) \
94 ((offsetof(struct tx_port_stats, counter) + \
95 sizeof(struct rx_port_stats) + 512) / 8)
97 #define BNXT_TX_STATS_ENTRY(counter) \
98 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
100 static const struct {
102 char string
[ETH_GSTRING_LEN
];
103 } bnxt_port_stats_arr
[] = {
104 BNXT_RX_STATS_ENTRY(rx_64b_frames
),
105 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames
),
106 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames
),
107 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames
),
108 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames
),
109 BNXT_RX_STATS_ENTRY(rx_1024b_1518_frames
),
110 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames
),
111 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames
),
112 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames
),
113 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames
),
114 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames
),
115 BNXT_RX_STATS_ENTRY(rx_total_frames
),
116 BNXT_RX_STATS_ENTRY(rx_ucast_frames
),
117 BNXT_RX_STATS_ENTRY(rx_mcast_frames
),
118 BNXT_RX_STATS_ENTRY(rx_bcast_frames
),
119 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames
),
120 BNXT_RX_STATS_ENTRY(rx_ctrl_frames
),
121 BNXT_RX_STATS_ENTRY(rx_pause_frames
),
122 BNXT_RX_STATS_ENTRY(rx_pfc_frames
),
123 BNXT_RX_STATS_ENTRY(rx_align_err_frames
),
124 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames
),
125 BNXT_RX_STATS_ENTRY(rx_jbr_frames
),
126 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames
),
127 BNXT_RX_STATS_ENTRY(rx_tagged_frames
),
128 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames
),
129 BNXT_RX_STATS_ENTRY(rx_good_frames
),
130 BNXT_RX_STATS_ENTRY(rx_undrsz_frames
),
131 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events
),
132 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration
),
133 BNXT_RX_STATS_ENTRY(rx_bytes
),
134 BNXT_RX_STATS_ENTRY(rx_runt_bytes
),
135 BNXT_RX_STATS_ENTRY(rx_runt_frames
),
137 BNXT_TX_STATS_ENTRY(tx_64b_frames
),
138 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames
),
139 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames
),
140 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames
),
141 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames
),
142 BNXT_TX_STATS_ENTRY(tx_1024b_1518_frames
),
143 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames
),
144 BNXT_TX_STATS_ENTRY(tx_1519b_2047_frames
),
145 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames
),
146 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames
),
147 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames
),
148 BNXT_TX_STATS_ENTRY(tx_good_frames
),
149 BNXT_TX_STATS_ENTRY(tx_total_frames
),
150 BNXT_TX_STATS_ENTRY(tx_ucast_frames
),
151 BNXT_TX_STATS_ENTRY(tx_mcast_frames
),
152 BNXT_TX_STATS_ENTRY(tx_bcast_frames
),
153 BNXT_TX_STATS_ENTRY(tx_pause_frames
),
154 BNXT_TX_STATS_ENTRY(tx_pfc_frames
),
155 BNXT_TX_STATS_ENTRY(tx_jabber_frames
),
156 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames
),
157 BNXT_TX_STATS_ENTRY(tx_err
),
158 BNXT_TX_STATS_ENTRY(tx_fifo_underruns
),
159 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events
),
160 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration
),
161 BNXT_TX_STATS_ENTRY(tx_total_collisions
),
162 BNXT_TX_STATS_ENTRY(tx_bytes
),
165 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
167 static int bnxt_get_sset_count(struct net_device
*dev
, int sset
)
169 struct bnxt
*bp
= netdev_priv(dev
);
173 int num_stats
= BNXT_NUM_STATS
* bp
->cp_nr_rings
;
175 if (bp
->flags
& BNXT_FLAG_PORT_STATS
)
176 num_stats
+= BNXT_NUM_PORT_STATS
;
185 static void bnxt_get_ethtool_stats(struct net_device
*dev
,
186 struct ethtool_stats
*stats
, u64
*buf
)
189 struct bnxt
*bp
= netdev_priv(dev
);
190 u32 buf_size
= sizeof(struct ctx_hw_stats
) * bp
->cp_nr_rings
;
191 u32 stat_fields
= sizeof(struct ctx_hw_stats
) / 8;
193 memset(buf
, 0, buf_size
);
198 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
199 struct bnxt_napi
*bnapi
= bp
->bnapi
[i
];
200 struct bnxt_cp_ring_info
*cpr
= &bnapi
->cp_ring
;
201 __le64
*hw_stats
= (__le64
*)cpr
->hw_stats
;
204 for (k
= 0; k
< stat_fields
; j
++, k
++)
205 buf
[j
] = le64_to_cpu(hw_stats
[k
]);
206 buf
[j
++] = cpr
->rx_l4_csum_errors
;
208 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
209 __le64
*port_stats
= (__le64
*)bp
->hw_rx_port_stats
;
211 for (i
= 0; i
< BNXT_NUM_PORT_STATS
; i
++, j
++) {
212 buf
[j
] = le64_to_cpu(*(port_stats
+
213 bnxt_port_stats_arr
[i
].offset
));
218 static void bnxt_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
220 struct bnxt
*bp
= netdev_priv(dev
);
224 /* The number of strings must match BNXT_NUM_STATS defined above. */
226 for (i
= 0; i
< bp
->cp_nr_rings
; i
++) {
227 sprintf(buf
, "[%d]: rx_ucast_packets", i
);
228 buf
+= ETH_GSTRING_LEN
;
229 sprintf(buf
, "[%d]: rx_mcast_packets", i
);
230 buf
+= ETH_GSTRING_LEN
;
231 sprintf(buf
, "[%d]: rx_bcast_packets", i
);
232 buf
+= ETH_GSTRING_LEN
;
233 sprintf(buf
, "[%d]: rx_discards", i
);
234 buf
+= ETH_GSTRING_LEN
;
235 sprintf(buf
, "[%d]: rx_drops", i
);
236 buf
+= ETH_GSTRING_LEN
;
237 sprintf(buf
, "[%d]: rx_ucast_bytes", i
);
238 buf
+= ETH_GSTRING_LEN
;
239 sprintf(buf
, "[%d]: rx_mcast_bytes", i
);
240 buf
+= ETH_GSTRING_LEN
;
241 sprintf(buf
, "[%d]: rx_bcast_bytes", i
);
242 buf
+= ETH_GSTRING_LEN
;
243 sprintf(buf
, "[%d]: tx_ucast_packets", i
);
244 buf
+= ETH_GSTRING_LEN
;
245 sprintf(buf
, "[%d]: tx_mcast_packets", i
);
246 buf
+= ETH_GSTRING_LEN
;
247 sprintf(buf
, "[%d]: tx_bcast_packets", i
);
248 buf
+= ETH_GSTRING_LEN
;
249 sprintf(buf
, "[%d]: tx_discards", i
);
250 buf
+= ETH_GSTRING_LEN
;
251 sprintf(buf
, "[%d]: tx_drops", i
);
252 buf
+= ETH_GSTRING_LEN
;
253 sprintf(buf
, "[%d]: tx_ucast_bytes", i
);
254 buf
+= ETH_GSTRING_LEN
;
255 sprintf(buf
, "[%d]: tx_mcast_bytes", i
);
256 buf
+= ETH_GSTRING_LEN
;
257 sprintf(buf
, "[%d]: tx_bcast_bytes", i
);
258 buf
+= ETH_GSTRING_LEN
;
259 sprintf(buf
, "[%d]: tpa_packets", i
);
260 buf
+= ETH_GSTRING_LEN
;
261 sprintf(buf
, "[%d]: tpa_bytes", i
);
262 buf
+= ETH_GSTRING_LEN
;
263 sprintf(buf
, "[%d]: tpa_events", i
);
264 buf
+= ETH_GSTRING_LEN
;
265 sprintf(buf
, "[%d]: tpa_aborts", i
);
266 buf
+= ETH_GSTRING_LEN
;
267 sprintf(buf
, "[%d]: rx_l4_csum_errors", i
);
268 buf
+= ETH_GSTRING_LEN
;
270 if (bp
->flags
& BNXT_FLAG_PORT_STATS
) {
271 for (i
= 0; i
< BNXT_NUM_PORT_STATS
; i
++) {
272 strcpy(buf
, bnxt_port_stats_arr
[i
].string
);
273 buf
+= ETH_GSTRING_LEN
;
278 netdev_err(bp
->dev
, "bnxt_get_strings invalid request %x\n",
284 static void bnxt_get_ringparam(struct net_device
*dev
,
285 struct ethtool_ringparam
*ering
)
287 struct bnxt
*bp
= netdev_priv(dev
);
289 ering
->rx_max_pending
= BNXT_MAX_RX_DESC_CNT
;
290 ering
->rx_jumbo_max_pending
= BNXT_MAX_RX_JUM_DESC_CNT
;
291 ering
->tx_max_pending
= BNXT_MAX_TX_DESC_CNT
;
293 ering
->rx_pending
= bp
->rx_ring_size
;
294 ering
->rx_jumbo_pending
= bp
->rx_agg_ring_size
;
295 ering
->tx_pending
= bp
->tx_ring_size
;
298 static int bnxt_set_ringparam(struct net_device
*dev
,
299 struct ethtool_ringparam
*ering
)
301 struct bnxt
*bp
= netdev_priv(dev
);
303 if ((ering
->rx_pending
> BNXT_MAX_RX_DESC_CNT
) ||
304 (ering
->tx_pending
> BNXT_MAX_TX_DESC_CNT
) ||
305 (ering
->tx_pending
<= MAX_SKB_FRAGS
))
308 if (netif_running(dev
))
309 bnxt_close_nic(bp
, false, false);
311 bp
->rx_ring_size
= ering
->rx_pending
;
312 bp
->tx_ring_size
= ering
->tx_pending
;
313 bnxt_set_ring_params(bp
);
315 if (netif_running(dev
))
316 return bnxt_open_nic(bp
, false, false);
321 static void bnxt_get_channels(struct net_device
*dev
,
322 struct ethtool_channels
*channel
)
324 struct bnxt
*bp
= netdev_priv(dev
);
325 int max_rx_rings
, max_tx_rings
, tcs
;
327 bnxt_get_max_rings(bp
, &max_rx_rings
, &max_tx_rings
, true);
328 channel
->max_combined
= max_rx_rings
;
330 if (bnxt_get_max_rings(bp
, &max_rx_rings
, &max_tx_rings
, false)) {
335 tcs
= netdev_get_num_tc(dev
);
339 channel
->max_rx
= max_rx_rings
;
340 channel
->max_tx
= max_tx_rings
;
341 channel
->max_other
= 0;
342 if (bp
->flags
& BNXT_FLAG_SHARED_RINGS
) {
343 channel
->combined_count
= bp
->rx_nr_rings
;
345 channel
->rx_count
= bp
->rx_nr_rings
;
346 channel
->tx_count
= bp
->tx_nr_rings_per_tc
;
350 static int bnxt_set_channels(struct net_device
*dev
,
351 struct ethtool_channels
*channel
)
353 struct bnxt
*bp
= netdev_priv(dev
);
354 int max_rx_rings
, max_tx_rings
, tcs
;
358 if (channel
->other_count
)
361 if (!channel
->combined_count
&&
362 (!channel
->rx_count
|| !channel
->tx_count
))
365 if (channel
->combined_count
&&
366 (channel
->rx_count
|| channel
->tx_count
))
369 if (channel
->combined_count
)
372 bnxt_get_max_rings(bp
, &max_rx_rings
, &max_tx_rings
, sh
);
374 tcs
= netdev_get_num_tc(dev
);
378 if (sh
&& (channel
->combined_count
> max_rx_rings
||
379 channel
->combined_count
> max_tx_rings
))
382 if (!sh
&& (channel
->rx_count
> max_rx_rings
||
383 channel
->tx_count
> max_tx_rings
))
386 if (netif_running(dev
)) {
388 /* TODO CHIMP_FW: Send message to all VF's
392 rc
= bnxt_close_nic(bp
, true, false);
394 netdev_err(bp
->dev
, "Set channel failure rc :%x\n",
401 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
402 bp
->rx_nr_rings
= channel
->combined_count
;
403 bp
->tx_nr_rings_per_tc
= channel
->combined_count
;
405 bp
->flags
&= ~BNXT_FLAG_SHARED_RINGS
;
406 bp
->rx_nr_rings
= channel
->rx_count
;
407 bp
->tx_nr_rings_per_tc
= channel
->tx_count
;
410 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
;
412 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tcs
;
414 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
415 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
417 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
419 /* After changing number of rx channels, update NTUPLE feature. */
420 netdev_update_features(dev
);
421 if (netif_running(dev
)) {
422 rc
= bnxt_open_nic(bp
, true, false);
423 if ((!rc
) && BNXT_PF(bp
)) {
424 /* TODO CHIMP_FW: Send message to all VF's
433 #ifdef CONFIG_RFS_ACCEL
434 static int bnxt_grxclsrlall(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
,
439 cmd
->data
= bp
->ntp_fltr_count
;
440 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
441 struct hlist_head
*head
;
442 struct bnxt_ntuple_filter
*fltr
;
444 head
= &bp
->ntp_fltr_hash_tbl
[i
];
446 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
447 if (j
== cmd
->rule_cnt
)
449 rule_locs
[j
++] = fltr
->sw_id
;
452 if (j
== cmd
->rule_cnt
)
459 static int bnxt_grxclsrule(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
)
461 struct ethtool_rx_flow_spec
*fs
=
462 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
463 struct bnxt_ntuple_filter
*fltr
;
464 struct flow_keys
*fkeys
;
467 if (fs
->location
< 0 || fs
->location
>= BNXT_NTP_FLTR_MAX_FLTR
)
470 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
471 struct hlist_head
*head
;
473 head
= &bp
->ntp_fltr_hash_tbl
[i
];
475 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
476 if (fltr
->sw_id
== fs
->location
)
484 fkeys
= &fltr
->fkeys
;
485 if (fkeys
->basic
.ip_proto
== IPPROTO_TCP
)
486 fs
->flow_type
= TCP_V4_FLOW
;
487 else if (fkeys
->basic
.ip_proto
== IPPROTO_UDP
)
488 fs
->flow_type
= UDP_V4_FLOW
;
492 fs
->h_u
.tcp_ip4_spec
.ip4src
= fkeys
->addrs
.v4addrs
.src
;
493 fs
->m_u
.tcp_ip4_spec
.ip4src
= cpu_to_be32(~0);
495 fs
->h_u
.tcp_ip4_spec
.ip4dst
= fkeys
->addrs
.v4addrs
.dst
;
496 fs
->m_u
.tcp_ip4_spec
.ip4dst
= cpu_to_be32(~0);
498 fs
->h_u
.tcp_ip4_spec
.psrc
= fkeys
->ports
.src
;
499 fs
->m_u
.tcp_ip4_spec
.psrc
= cpu_to_be16(~0);
501 fs
->h_u
.tcp_ip4_spec
.pdst
= fkeys
->ports
.dst
;
502 fs
->m_u
.tcp_ip4_spec
.pdst
= cpu_to_be16(~0);
504 fs
->ring_cookie
= fltr
->rxq
;
513 static int bnxt_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
516 struct bnxt
*bp
= netdev_priv(dev
);
520 case ETHTOOL_GRXRINGS
:
521 cmd
->data
= bp
->rx_nr_rings
;
524 case ETHTOOL_GRXCLSRLCNT
:
525 cmd
->rule_cnt
= bp
->ntp_fltr_count
;
526 cmd
->data
= BNXT_NTP_FLTR_MAX_FLTR
;
529 case ETHTOOL_GRXCLSRLALL
:
530 rc
= bnxt_grxclsrlall(bp
, cmd
, (u32
*)rule_locs
);
533 case ETHTOOL_GRXCLSRULE
:
534 rc
= bnxt_grxclsrule(bp
, cmd
);
546 static u32
bnxt_get_rxfh_indir_size(struct net_device
*dev
)
548 return HW_HASH_INDEX_SIZE
;
551 static u32
bnxt_get_rxfh_key_size(struct net_device
*dev
)
553 return HW_HASH_KEY_SIZE
;
556 static int bnxt_get_rxfh(struct net_device
*dev
, u32
*indir
, u8
*key
,
559 struct bnxt
*bp
= netdev_priv(dev
);
560 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
564 *hfunc
= ETH_RSS_HASH_TOP
;
567 for (i
= 0; i
< HW_HASH_INDEX_SIZE
; i
++)
568 indir
[i
] = le16_to_cpu(vnic
->rss_table
[i
]);
571 memcpy(key
, vnic
->rss_hash_key
, HW_HASH_KEY_SIZE
);
576 static void bnxt_get_drvinfo(struct net_device
*dev
,
577 struct ethtool_drvinfo
*info
)
579 struct bnxt
*bp
= netdev_priv(dev
);
583 pkglog
= kmalloc(BNX_PKG_LOG_MAX_LENGTH
, GFP_KERNEL
);
585 pkgver
= bnxt_get_pkgver(dev
, pkglog
, BNX_PKG_LOG_MAX_LENGTH
);
586 strlcpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
587 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
588 if (pkgver
&& *pkgver
!= 0 && isdigit(*pkgver
))
589 snprintf(info
->fw_version
, sizeof(info
->fw_version
) - 1,
590 "%s pkg %s", bp
->fw_ver_str
, pkgver
);
592 strlcpy(info
->fw_version
, bp
->fw_ver_str
,
593 sizeof(info
->fw_version
));
594 strlcpy(info
->bus_info
, pci_name(bp
->pdev
), sizeof(info
->bus_info
));
595 info
->n_stats
= BNXT_NUM_STATS
* bp
->cp_nr_rings
;
596 info
->testinfo_len
= BNXT_NUM_TESTS(bp
);
597 /* TODO CHIMP_FW: eeprom dump details */
598 info
->eedump_len
= 0;
599 /* TODO CHIMP FW: reg dump details */
600 info
->regdump_len
= 0;
604 u32
_bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds
, u8 fw_pause
)
608 /* TODO: support 25GB, 40GB, 50GB with different cable type */
609 /* set the advertised speeds */
610 if (fw_speeds
& BNXT_LINK_SPEED_MSK_100MB
)
611 speed_mask
|= ADVERTISED_100baseT_Full
;
612 if (fw_speeds
& BNXT_LINK_SPEED_MSK_1GB
)
613 speed_mask
|= ADVERTISED_1000baseT_Full
;
614 if (fw_speeds
& BNXT_LINK_SPEED_MSK_2_5GB
)
615 speed_mask
|= ADVERTISED_2500baseX_Full
;
616 if (fw_speeds
& BNXT_LINK_SPEED_MSK_10GB
)
617 speed_mask
|= ADVERTISED_10000baseT_Full
;
618 if (fw_speeds
& BNXT_LINK_SPEED_MSK_40GB
)
619 speed_mask
|= ADVERTISED_40000baseCR4_Full
;
621 if ((fw_pause
& BNXT_LINK_PAUSE_BOTH
) == BNXT_LINK_PAUSE_BOTH
)
622 speed_mask
|= ADVERTISED_Pause
;
623 else if (fw_pause
& BNXT_LINK_PAUSE_TX
)
624 speed_mask
|= ADVERTISED_Asym_Pause
;
625 else if (fw_pause
& BNXT_LINK_PAUSE_RX
)
626 speed_mask
|= ADVERTISED_Pause
| ADVERTISED_Asym_Pause
;
631 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
633 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
634 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
636 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
637 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
639 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
640 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
642 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
643 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
645 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
646 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
648 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
649 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
651 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
652 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
654 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
655 ethtool_link_ksettings_add_link_mode( \
656 lk_ksettings, name, Asym_Pause);\
657 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
658 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
663 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
665 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
667 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
669 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
670 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
672 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
674 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
675 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
677 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
678 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
680 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
681 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
682 40000baseCR4_Full)) \
683 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
684 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
685 50000baseCR2_Full)) \
686 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
689 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info
*link_info
,
690 struct ethtool_link_ksettings
*lk_ksettings
)
692 u16 fw_speeds
= link_info
->auto_link_speeds
;
695 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
696 fw_pause
= link_info
->auto_pause_setting
;
698 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, fw_pause
, lk_ksettings
, advertising
);
701 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info
*link_info
,
702 struct ethtool_link_ksettings
*lk_ksettings
)
704 u16 fw_speeds
= link_info
->lp_auto_link_speeds
;
707 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
708 fw_pause
= link_info
->lp_pause
;
710 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, fw_pause
, lk_ksettings
,
714 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info
*link_info
,
715 struct ethtool_link_ksettings
*lk_ksettings
)
717 u16 fw_speeds
= link_info
->support_speeds
;
719 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, 0, lk_ksettings
, supported
);
721 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
, Pause
);
722 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
725 if (link_info
->support_auto_speeds
)
726 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
730 u32
bnxt_fw_to_ethtool_speed(u16 fw_link_speed
)
732 switch (fw_link_speed
) {
733 case BNXT_LINK_SPEED_100MB
:
735 case BNXT_LINK_SPEED_1GB
:
737 case BNXT_LINK_SPEED_2_5GB
:
739 case BNXT_LINK_SPEED_10GB
:
741 case BNXT_LINK_SPEED_20GB
:
743 case BNXT_LINK_SPEED_25GB
:
745 case BNXT_LINK_SPEED_40GB
:
747 case BNXT_LINK_SPEED_50GB
:
750 return SPEED_UNKNOWN
;
754 static int bnxt_get_link_ksettings(struct net_device
*dev
,
755 struct ethtool_link_ksettings
*lk_ksettings
)
757 struct bnxt
*bp
= netdev_priv(dev
);
758 struct bnxt_link_info
*link_info
= &bp
->link_info
;
759 struct ethtool_link_settings
*base
= &lk_ksettings
->base
;
762 ethtool_link_ksettings_zero_link_mode(lk_ksettings
, supported
);
763 bnxt_fw_to_ethtool_support_spds(link_info
, lk_ksettings
);
765 ethtool_link_ksettings_zero_link_mode(lk_ksettings
, advertising
);
766 if (link_info
->autoneg
) {
767 bnxt_fw_to_ethtool_advertised_spds(link_info
, lk_ksettings
);
768 ethtool_link_ksettings_add_link_mode(lk_ksettings
,
769 advertising
, Autoneg
);
770 base
->autoneg
= AUTONEG_ENABLE
;
771 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
772 bnxt_fw_to_ethtool_lp_adv(link_info
, lk_ksettings
);
773 ethtool_speed
= bnxt_fw_to_ethtool_speed(link_info
->link_speed
);
774 if (!netif_carrier_ok(dev
))
775 base
->duplex
= DUPLEX_UNKNOWN
;
776 else if (link_info
->duplex
& BNXT_LINK_DUPLEX_FULL
)
777 base
->duplex
= DUPLEX_FULL
;
779 base
->duplex
= DUPLEX_HALF
;
781 base
->autoneg
= AUTONEG_DISABLE
;
783 bnxt_fw_to_ethtool_speed(link_info
->req_link_speed
);
784 base
->duplex
= DUPLEX_HALF
;
785 if (link_info
->req_duplex
== BNXT_LINK_DUPLEX_FULL
)
786 base
->duplex
= DUPLEX_FULL
;
788 base
->speed
= ethtool_speed
;
790 base
->port
= PORT_NONE
;
791 if (link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP
) {
792 base
->port
= PORT_TP
;
793 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
795 ethtool_link_ksettings_add_link_mode(lk_ksettings
, advertising
,
798 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
800 ethtool_link_ksettings_add_link_mode(lk_ksettings
, advertising
,
803 if (link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC
)
804 base
->port
= PORT_DA
;
805 else if (link_info
->media_type
==
806 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE
)
807 base
->port
= PORT_FIBRE
;
809 base
->phy_address
= link_info
->phy_addr
;
814 static u32
bnxt_get_fw_speed(struct net_device
*dev
, u16 ethtool_speed
)
816 struct bnxt
*bp
= netdev_priv(dev
);
817 struct bnxt_link_info
*link_info
= &bp
->link_info
;
818 u16 support_spds
= link_info
->support_speeds
;
821 switch (ethtool_speed
) {
823 if (support_spds
& BNXT_LINK_SPEED_MSK_100MB
)
824 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB
;
827 if (support_spds
& BNXT_LINK_SPEED_MSK_1GB
)
828 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB
;
831 if (support_spds
& BNXT_LINK_SPEED_MSK_2_5GB
)
832 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB
;
835 if (support_spds
& BNXT_LINK_SPEED_MSK_10GB
)
836 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB
;
839 if (support_spds
& BNXT_LINK_SPEED_MSK_20GB
)
840 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB
;
843 if (support_spds
& BNXT_LINK_SPEED_MSK_25GB
)
844 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB
;
847 if (support_spds
& BNXT_LINK_SPEED_MSK_40GB
)
848 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB
;
851 if (support_spds
& BNXT_LINK_SPEED_MSK_50GB
)
852 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB
;
855 netdev_err(dev
, "unsupported speed!\n");
861 u16
bnxt_get_fw_auto_link_speeds(u32 advertising
)
863 u16 fw_speed_mask
= 0;
865 /* only support autoneg at speed 100, 1000, and 10000 */
866 if (advertising
& (ADVERTISED_100baseT_Full
|
867 ADVERTISED_100baseT_Half
)) {
868 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_100MB
;
870 if (advertising
& (ADVERTISED_1000baseT_Full
|
871 ADVERTISED_1000baseT_Half
)) {
872 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_1GB
;
874 if (advertising
& ADVERTISED_10000baseT_Full
)
875 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_10GB
;
877 if (advertising
& ADVERTISED_40000baseCR4_Full
)
878 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_40GB
;
880 return fw_speed_mask
;
883 static int bnxt_set_link_ksettings(struct net_device
*dev
,
884 const struct ethtool_link_ksettings
*lk_ksettings
)
886 struct bnxt
*bp
= netdev_priv(dev
);
887 struct bnxt_link_info
*link_info
= &bp
->link_info
;
888 const struct ethtool_link_settings
*base
= &lk_ksettings
->base
;
889 u32 speed
, fw_advertising
= 0;
890 bool set_pause
= false;
893 if (!BNXT_SINGLE_PF(bp
))
896 if (base
->autoneg
== AUTONEG_ENABLE
) {
897 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising
, lk_ksettings
,
899 link_info
->autoneg
|= BNXT_AUTONEG_SPEED
;
901 link_info
->advertising
= link_info
->support_auto_speeds
;
903 link_info
->advertising
= fw_advertising
;
904 /* any change to autoneg will cause link change, therefore the
905 * driver should put back the original pause setting in autoneg
910 u8 phy_type
= link_info
->phy_type
;
912 if (phy_type
== PORT_PHY_QCFG_RESP_PHY_TYPE_BASET
||
913 phy_type
== PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE
||
914 link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP
) {
915 netdev_err(dev
, "10GBase-T devices must autoneg\n");
917 goto set_setting_exit
;
919 if (base
->duplex
== DUPLEX_HALF
) {
920 netdev_err(dev
, "HALF DUPLEX is not supported!\n");
922 goto set_setting_exit
;
925 fw_speed
= bnxt_get_fw_speed(dev
, speed
);
928 goto set_setting_exit
;
930 link_info
->req_link_speed
= fw_speed
;
931 link_info
->req_duplex
= BNXT_LINK_DUPLEX_FULL
;
932 link_info
->autoneg
= 0;
933 link_info
->advertising
= 0;
936 if (netif_running(dev
))
937 rc
= bnxt_hwrm_set_link_setting(bp
, set_pause
, false);
943 static void bnxt_get_pauseparam(struct net_device
*dev
,
944 struct ethtool_pauseparam
*epause
)
946 struct bnxt
*bp
= netdev_priv(dev
);
947 struct bnxt_link_info
*link_info
= &bp
->link_info
;
951 epause
->autoneg
= !!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
);
952 epause
->rx_pause
= !!(link_info
->req_flow_ctrl
& BNXT_LINK_PAUSE_RX
);
953 epause
->tx_pause
= !!(link_info
->req_flow_ctrl
& BNXT_LINK_PAUSE_TX
);
956 static int bnxt_set_pauseparam(struct net_device
*dev
,
957 struct ethtool_pauseparam
*epause
)
960 struct bnxt
*bp
= netdev_priv(dev
);
961 struct bnxt_link_info
*link_info
= &bp
->link_info
;
963 if (!BNXT_SINGLE_PF(bp
))
966 if (epause
->autoneg
) {
967 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
))
970 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
971 if (bp
->hwrm_spec_code
>= 0x10201)
972 link_info
->req_flow_ctrl
=
973 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
975 /* when transition from auto pause to force pause,
976 * force a link change
978 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
979 link_info
->force_link_chng
= true;
980 link_info
->autoneg
&= ~BNXT_AUTONEG_FLOW_CTRL
;
981 link_info
->req_flow_ctrl
= 0;
983 if (epause
->rx_pause
)
984 link_info
->req_flow_ctrl
|= BNXT_LINK_PAUSE_RX
;
986 if (epause
->tx_pause
)
987 link_info
->req_flow_ctrl
|= BNXT_LINK_PAUSE_TX
;
989 if (netif_running(dev
))
990 rc
= bnxt_hwrm_set_pause(bp
);
994 static u32
bnxt_get_link(struct net_device
*dev
)
996 struct bnxt
*bp
= netdev_priv(dev
);
998 /* TODO: handle MF, VF, driver close case */
999 return bp
->link_info
.link_up
;
1002 static int bnxt_flash_nvram(struct net_device
*dev
,
1010 struct bnxt
*bp
= netdev_priv(dev
);
1012 struct hwrm_nvm_write_input req
= {0};
1013 dma_addr_t dma_handle
;
1016 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_WRITE
, -1, -1);
1018 req
.dir_type
= cpu_to_le16(dir_type
);
1019 req
.dir_ordinal
= cpu_to_le16(dir_ordinal
);
1020 req
.dir_ext
= cpu_to_le16(dir_ext
);
1021 req
.dir_attr
= cpu_to_le16(dir_attr
);
1022 req
.dir_data_length
= cpu_to_le32(data_len
);
1024 kmem
= dma_alloc_coherent(&bp
->pdev
->dev
, data_len
, &dma_handle
,
1027 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1028 (unsigned)data_len
);
1031 memcpy(kmem
, data
, data_len
);
1032 req
.host_src_addr
= cpu_to_le64(dma_handle
);
1034 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), FLASH_NVRAM_TIMEOUT
);
1035 dma_free_coherent(&bp
->pdev
->dev
, data_len
, kmem
, dma_handle
);
1040 static int bnxt_firmware_reset(struct net_device
*dev
,
1043 struct bnxt
*bp
= netdev_priv(dev
);
1044 struct hwrm_fw_reset_input req
= {0};
1046 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_RESET
, -1, -1);
1048 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1049 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1050 /* (e.g. when firmware isn't already running) */
1052 case BNX_DIR_TYPE_CHIMP_PATCH
:
1053 case BNX_DIR_TYPE_BOOTCODE
:
1054 case BNX_DIR_TYPE_BOOTCODE_2
:
1055 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT
;
1056 /* Self-reset ChiMP upon next PCIe reset: */
1057 req
.selfrst_status
= FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST
;
1059 case BNX_DIR_TYPE_APE_FW
:
1060 case BNX_DIR_TYPE_APE_PATCH
:
1061 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT
;
1063 case BNX_DIR_TYPE_KONG_FW
:
1064 case BNX_DIR_TYPE_KONG_PATCH
:
1065 req
.embedded_proc_type
=
1066 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL
;
1068 case BNX_DIR_TYPE_BONO_FW
:
1069 case BNX_DIR_TYPE_BONO_PATCH
:
1070 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE
;
1076 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1079 static int bnxt_flash_firmware(struct net_device
*dev
,
1088 struct bnxt_fw_header
*header
= (struct bnxt_fw_header
*)fw_data
;
1091 case BNX_DIR_TYPE_BOOTCODE
:
1092 case BNX_DIR_TYPE_BOOTCODE_2
:
1093 code_type
= CODE_BOOT
;
1095 case BNX_DIR_TYPE_APE_FW
:
1096 code_type
= CODE_MCTP_PASSTHRU
;
1099 netdev_err(dev
, "Unsupported directory entry type: %u\n",
1103 if (fw_size
< sizeof(struct bnxt_fw_header
)) {
1104 netdev_err(dev
, "Invalid firmware file size: %u\n",
1105 (unsigned int)fw_size
);
1108 if (header
->signature
!= cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE
)) {
1109 netdev_err(dev
, "Invalid firmware signature: %08X\n",
1110 le32_to_cpu(header
->signature
));
1113 if (header
->code_type
!= code_type
) {
1114 netdev_err(dev
, "Expected firmware type: %d, read: %d\n",
1115 code_type
, header
->code_type
);
1118 if (header
->device
!= DEVICE_CUMULUS_FAMILY
) {
1119 netdev_err(dev
, "Expected firmware device family %d, read: %d\n",
1120 DEVICE_CUMULUS_FAMILY
, header
->device
);
1123 /* Confirm the CRC32 checksum of the file: */
1124 stored_crc
= le32_to_cpu(*(__le32
*)(fw_data
+ fw_size
-
1125 sizeof(stored_crc
)));
1126 calculated_crc
= ~crc32(~0, fw_data
, fw_size
- sizeof(stored_crc
));
1127 if (calculated_crc
!= stored_crc
) {
1128 netdev_err(dev
, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1129 (unsigned long)stored_crc
,
1130 (unsigned long)calculated_crc
);
1133 /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */
1134 rc
= bnxt_flash_nvram(dev
, dir_type
, BNX_DIR_ORDINAL_FIRST
,
1135 0, 0, fw_data
, fw_size
);
1136 if (rc
== 0) /* Firmware update successful */
1137 rc
= bnxt_firmware_reset(dev
, dir_type
);
1142 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type
)
1145 case BNX_DIR_TYPE_CHIMP_PATCH
:
1146 case BNX_DIR_TYPE_BOOTCODE
:
1147 case BNX_DIR_TYPE_BOOTCODE_2
:
1148 case BNX_DIR_TYPE_APE_FW
:
1149 case BNX_DIR_TYPE_APE_PATCH
:
1150 case BNX_DIR_TYPE_KONG_FW
:
1151 case BNX_DIR_TYPE_KONG_PATCH
:
1158 static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type
)
1161 case BNX_DIR_TYPE_AVS
:
1162 case BNX_DIR_TYPE_EXP_ROM_MBA
:
1163 case BNX_DIR_TYPE_PCIE
:
1164 case BNX_DIR_TYPE_TSCF_UCODE
:
1165 case BNX_DIR_TYPE_EXT_PHY
:
1166 case BNX_DIR_TYPE_CCM
:
1167 case BNX_DIR_TYPE_ISCSI_BOOT
:
1168 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6
:
1169 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6
:
1176 static bool bnxt_dir_type_is_executable(u16 dir_type
)
1178 return bnxt_dir_type_is_ape_bin_format(dir_type
) ||
1179 bnxt_dir_type_is_unprotected_exec_format(dir_type
);
1182 static int bnxt_flash_firmware_from_file(struct net_device
*dev
,
1184 const char *filename
)
1186 const struct firmware
*fw
;
1189 if (bnxt_dir_type_is_executable(dir_type
) == false)
1192 rc
= request_firmware(&fw
, filename
, &dev
->dev
);
1194 netdev_err(dev
, "Error %d requesting firmware file: %s\n",
1198 if (bnxt_dir_type_is_ape_bin_format(dir_type
) == true)
1199 rc
= bnxt_flash_firmware(dev
, dir_type
, fw
->data
, fw
->size
);
1201 rc
= bnxt_flash_nvram(dev
, dir_type
, BNX_DIR_ORDINAL_FIRST
,
1202 0, 0, fw
->data
, fw
->size
);
1203 release_firmware(fw
);
1207 static int bnxt_flash_package_from_file(struct net_device
*dev
,
1210 netdev_err(dev
, "packages are not yet supported\n");
1214 static int bnxt_flash_device(struct net_device
*dev
,
1215 struct ethtool_flash
*flash
)
1217 if (!BNXT_PF((struct bnxt
*)netdev_priv(dev
))) {
1218 netdev_err(dev
, "flashdev not supported from a virtual function\n");
1222 if (flash
->region
== ETHTOOL_FLASH_ALL_REGIONS
)
1223 return bnxt_flash_package_from_file(dev
, flash
->data
);
1225 return bnxt_flash_firmware_from_file(dev
, flash
->region
, flash
->data
);
1228 static int nvm_get_dir_info(struct net_device
*dev
, u32
*entries
, u32
*length
)
1230 struct bnxt
*bp
= netdev_priv(dev
);
1232 struct hwrm_nvm_get_dir_info_input req
= {0};
1233 struct hwrm_nvm_get_dir_info_output
*output
= bp
->hwrm_cmd_resp_addr
;
1235 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_GET_DIR_INFO
, -1, -1);
1237 mutex_lock(&bp
->hwrm_cmd_lock
);
1238 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1240 *entries
= le32_to_cpu(output
->entries
);
1241 *length
= le32_to_cpu(output
->entry_length
);
1243 mutex_unlock(&bp
->hwrm_cmd_lock
);
1247 static int bnxt_get_eeprom_len(struct net_device
*dev
)
1249 /* The -1 return value allows the entire 32-bit range of offsets to be
1250 * passed via the ethtool command-line utility.
1255 static int bnxt_get_nvram_directory(struct net_device
*dev
, u32 len
, u8
*data
)
1257 struct bnxt
*bp
= netdev_priv(dev
);
1263 dma_addr_t dma_handle
;
1264 struct hwrm_nvm_get_dir_entries_input req
= {0};
1266 rc
= nvm_get_dir_info(dev
, &dir_entries
, &entry_length
);
1270 /* Insert 2 bytes of directory info (count and size of entries) */
1274 *data
++ = dir_entries
;
1275 *data
++ = entry_length
;
1277 memset(data
, 0xff, len
);
1279 buflen
= dir_entries
* entry_length
;
1280 buf
= dma_alloc_coherent(&bp
->pdev
->dev
, buflen
, &dma_handle
,
1283 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1287 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_GET_DIR_ENTRIES
, -1, -1);
1288 req
.host_dest_addr
= cpu_to_le64(dma_handle
);
1289 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1291 memcpy(data
, buf
, len
> buflen
? buflen
: len
);
1292 dma_free_coherent(&bp
->pdev
->dev
, buflen
, buf
, dma_handle
);
1296 static int bnxt_get_nvram_item(struct net_device
*dev
, u32 index
, u32 offset
,
1297 u32 length
, u8
*data
)
1299 struct bnxt
*bp
= netdev_priv(dev
);
1302 dma_addr_t dma_handle
;
1303 struct hwrm_nvm_read_input req
= {0};
1305 buf
= dma_alloc_coherent(&bp
->pdev
->dev
, length
, &dma_handle
,
1308 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1312 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_READ
, -1, -1);
1313 req
.host_dest_addr
= cpu_to_le64(dma_handle
);
1314 req
.dir_idx
= cpu_to_le16(index
);
1315 req
.offset
= cpu_to_le32(offset
);
1316 req
.len
= cpu_to_le32(length
);
1318 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1320 memcpy(data
, buf
, length
);
1321 dma_free_coherent(&bp
->pdev
->dev
, length
, buf
, dma_handle
);
1325 static int bnxt_find_nvram_item(struct net_device
*dev
, u16 type
, u16 ordinal
,
1326 u16 ext
, u16
*index
, u32
*item_length
,
1329 struct bnxt
*bp
= netdev_priv(dev
);
1331 struct hwrm_nvm_find_dir_entry_input req
= {0};
1332 struct hwrm_nvm_find_dir_entry_output
*output
= bp
->hwrm_cmd_resp_addr
;
1334 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_FIND_DIR_ENTRY
, -1, -1);
1337 req
.dir_type
= cpu_to_le16(type
);
1338 req
.dir_ordinal
= cpu_to_le16(ordinal
);
1339 req
.dir_ext
= cpu_to_le16(ext
);
1340 req
.opt_ordinal
= NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ
;
1341 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1344 *index
= le16_to_cpu(output
->dir_idx
);
1346 *item_length
= le32_to_cpu(output
->dir_item_length
);
1348 *data_length
= le32_to_cpu(output
->dir_data_length
);
1353 static char *bnxt_parse_pkglog(int desired_field
, u8
*data
, size_t datalen
)
1355 char *retval
= NULL
;
1362 /* null-terminate the log data (removing last '\n'): */
1363 data
[datalen
- 1] = 0;
1364 for (p
= data
; *p
!= 0; p
++) {
1367 while (*p
!= 0 && *p
!= '\n') {
1369 while (*p
!= 0 && *p
!= '\t' && *p
!= '\n')
1371 if (field
== desired_field
)
1386 static char *bnxt_get_pkgver(struct net_device
*dev
, char *buf
, size_t buflen
)
1391 if (bnxt_find_nvram_item(dev
, BNX_DIR_TYPE_PKG_LOG
,
1392 BNX_DIR_ORDINAL_FIRST
, BNX_DIR_EXT_NONE
,
1393 &index
, NULL
, &datalen
) != 0)
1396 memset(buf
, 0, buflen
);
1397 if (bnxt_get_nvram_item(dev
, index
, 0, datalen
, buf
) != 0)
1400 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION
, buf
,
1404 static int bnxt_get_eeprom(struct net_device
*dev
,
1405 struct ethtool_eeprom
*eeprom
,
1411 if (eeprom
->offset
== 0) /* special offset value to get directory */
1412 return bnxt_get_nvram_directory(dev
, eeprom
->len
, data
);
1414 index
= eeprom
->offset
>> 24;
1415 offset
= eeprom
->offset
& 0xffffff;
1418 netdev_err(dev
, "unsupported index value: %d\n", index
);
1422 return bnxt_get_nvram_item(dev
, index
- 1, offset
, eeprom
->len
, data
);
1425 static int bnxt_erase_nvram_directory(struct net_device
*dev
, u8 index
)
1427 struct bnxt
*bp
= netdev_priv(dev
);
1428 struct hwrm_nvm_erase_dir_entry_input req
= {0};
1430 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_ERASE_DIR_ENTRY
, -1, -1);
1431 req
.dir_idx
= cpu_to_le16(index
);
1432 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1435 static int bnxt_set_eeprom(struct net_device
*dev
,
1436 struct ethtool_eeprom
*eeprom
,
1439 struct bnxt
*bp
= netdev_priv(dev
);
1441 u16 type
, ext
, ordinal
, attr
;
1444 netdev_err(dev
, "NVM write not supported from a virtual function\n");
1448 type
= eeprom
->magic
>> 16;
1450 if (type
== 0xffff) { /* special value for directory operations */
1451 index
= eeprom
->magic
& 0xff;
1452 dir_op
= eeprom
->magic
>> 8;
1456 case 0x0e: /* erase */
1457 if (eeprom
->offset
!= ~eeprom
->magic
)
1459 return bnxt_erase_nvram_directory(dev
, index
- 1);
1465 /* Create or re-write an NVM item: */
1466 if (bnxt_dir_type_is_executable(type
) == true)
1468 ext
= eeprom
->magic
& 0xffff;
1469 ordinal
= eeprom
->offset
>> 16;
1470 attr
= eeprom
->offset
& 0xffff;
1472 return bnxt_flash_nvram(dev
, type
, ordinal
, ext
, attr
, data
,
1476 static int bnxt_set_eee(struct net_device
*dev
, struct ethtool_eee
*edata
)
1478 struct bnxt
*bp
= netdev_priv(dev
);
1479 struct ethtool_eee
*eee
= &bp
->eee
;
1480 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1482 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
1485 if (!BNXT_SINGLE_PF(bp
))
1488 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
1491 if (!edata
->eee_enabled
)
1494 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
1495 netdev_warn(dev
, "EEE requires autoneg\n");
1498 if (edata
->tx_lpi_enabled
) {
1499 if (bp
->lpi_tmr_hi
&& (edata
->tx_lpi_timer
> bp
->lpi_tmr_hi
||
1500 edata
->tx_lpi_timer
< bp
->lpi_tmr_lo
)) {
1501 netdev_warn(dev
, "Valid LPI timer range is %d and %d microsecs\n",
1502 bp
->lpi_tmr_lo
, bp
->lpi_tmr_hi
);
1504 } else if (!bp
->lpi_tmr_hi
) {
1505 edata
->tx_lpi_timer
= eee
->tx_lpi_timer
;
1508 if (!edata
->advertised
) {
1509 edata
->advertised
= advertising
& eee
->supported
;
1510 } else if (edata
->advertised
& ~advertising
) {
1511 netdev_warn(dev
, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
1512 edata
->advertised
, advertising
);
1516 eee
->advertised
= edata
->advertised
;
1517 eee
->tx_lpi_enabled
= edata
->tx_lpi_enabled
;
1518 eee
->tx_lpi_timer
= edata
->tx_lpi_timer
;
1520 eee
->eee_enabled
= edata
->eee_enabled
;
1522 if (netif_running(dev
))
1523 rc
= bnxt_hwrm_set_link_setting(bp
, false, true);
1528 static int bnxt_get_eee(struct net_device
*dev
, struct ethtool_eee
*edata
)
1530 struct bnxt
*bp
= netdev_priv(dev
);
1532 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
1536 if (!bp
->eee
.eee_enabled
) {
1537 /* Preserve tx_lpi_timer so that the last value will be used
1538 * by default when it is re-enabled.
1540 edata
->advertised
= 0;
1541 edata
->tx_lpi_enabled
= 0;
1544 if (!bp
->eee
.eee_active
)
1545 edata
->lp_advertised
= 0;
1550 static int bnxt_read_sfp_module_eeprom_info(struct bnxt
*bp
, u16 i2c_addr
,
1551 u16 page_number
, u16 start_addr
,
1552 u16 data_length
, u8
*buf
)
1554 struct hwrm_port_phy_i2c_read_input req
= {0};
1555 struct hwrm_port_phy_i2c_read_output
*output
= bp
->hwrm_cmd_resp_addr
;
1556 int rc
, byte_offset
= 0;
1558 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_I2C_READ
, -1, -1);
1559 req
.i2c_slave_addr
= i2c_addr
;
1560 req
.page_number
= cpu_to_le16(page_number
);
1561 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
1565 xfer_size
= min_t(u16
, data_length
, BNXT_MAX_PHY_I2C_RESP_SIZE
);
1566 data_length
-= xfer_size
;
1567 req
.page_offset
= cpu_to_le16(start_addr
+ byte_offset
);
1568 req
.data_length
= xfer_size
;
1569 req
.enables
= cpu_to_le32(start_addr
+ byte_offset
?
1570 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET
: 0);
1571 mutex_lock(&bp
->hwrm_cmd_lock
);
1572 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
1575 memcpy(buf
+ byte_offset
, output
->data
, xfer_size
);
1576 mutex_unlock(&bp
->hwrm_cmd_lock
);
1577 byte_offset
+= xfer_size
;
1578 } while (!rc
&& data_length
> 0);
1583 static int bnxt_get_module_info(struct net_device
*dev
,
1584 struct ethtool_modinfo
*modinfo
)
1586 struct bnxt
*bp
= netdev_priv(dev
);
1587 struct hwrm_port_phy_i2c_read_input req
= {0};
1588 struct hwrm_port_phy_i2c_read_output
*output
= bp
->hwrm_cmd_resp_addr
;
1591 /* No point in going further if phy status indicates
1592 * module is not inserted or if it is powered down or
1593 * if it is of type 10GBase-T
1595 if (bp
->link_info
.module_status
>
1596 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
)
1599 /* This feature is not supported in older firmware versions */
1600 if (bp
->hwrm_spec_code
< 0x10202)
1603 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_I2C_READ
, -1, -1);
1604 req
.i2c_slave_addr
= I2C_DEV_ADDR_A0
;
1605 req
.page_number
= 0;
1606 req
.page_offset
= cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR
);
1607 req
.data_length
= SFP_EEPROM_SFF_8472_COMP_SIZE
;
1608 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
1609 mutex_lock(&bp
->hwrm_cmd_lock
);
1610 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1612 u32 module_id
= le32_to_cpu(output
->data
[0]);
1614 switch (module_id
) {
1615 case SFF_MODULE_ID_SFP
:
1616 modinfo
->type
= ETH_MODULE_SFF_8472
;
1617 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
1619 case SFF_MODULE_ID_QSFP
:
1620 case SFF_MODULE_ID_QSFP_PLUS
:
1621 modinfo
->type
= ETH_MODULE_SFF_8436
;
1622 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
1624 case SFF_MODULE_ID_QSFP28
:
1625 modinfo
->type
= ETH_MODULE_SFF_8636
;
1626 modinfo
->eeprom_len
= ETH_MODULE_SFF_8636_LEN
;
1633 mutex_unlock(&bp
->hwrm_cmd_lock
);
1637 static int bnxt_get_module_eeprom(struct net_device
*dev
,
1638 struct ethtool_eeprom
*eeprom
,
1641 struct bnxt
*bp
= netdev_priv(dev
);
1642 u16 start
= eeprom
->offset
, length
= eeprom
->len
;
1645 memset(data
, 0, eeprom
->len
);
1647 /* Read A0 portion of the EEPROM */
1648 if (start
< ETH_MODULE_SFF_8436_LEN
) {
1649 if (start
+ eeprom
->len
> ETH_MODULE_SFF_8436_LEN
)
1650 length
= ETH_MODULE_SFF_8436_LEN
- start
;
1651 rc
= bnxt_read_sfp_module_eeprom_info(bp
, I2C_DEV_ADDR_A0
, 0,
1652 start
, length
, data
);
1657 length
= eeprom
->len
- length
;
1660 /* Read A2 portion of the EEPROM */
1662 start
-= ETH_MODULE_SFF_8436_LEN
;
1663 bnxt_read_sfp_module_eeprom_info(bp
, I2C_DEV_ADDR_A2
, 1, start
,
1669 const struct ethtool_ops bnxt_ethtool_ops
= {
1670 .get_link_ksettings
= bnxt_get_link_ksettings
,
1671 .set_link_ksettings
= bnxt_set_link_ksettings
,
1672 .get_pauseparam
= bnxt_get_pauseparam
,
1673 .set_pauseparam
= bnxt_set_pauseparam
,
1674 .get_drvinfo
= bnxt_get_drvinfo
,
1675 .get_coalesce
= bnxt_get_coalesce
,
1676 .set_coalesce
= bnxt_set_coalesce
,
1677 .get_msglevel
= bnxt_get_msglevel
,
1678 .set_msglevel
= bnxt_set_msglevel
,
1679 .get_sset_count
= bnxt_get_sset_count
,
1680 .get_strings
= bnxt_get_strings
,
1681 .get_ethtool_stats
= bnxt_get_ethtool_stats
,
1682 .set_ringparam
= bnxt_set_ringparam
,
1683 .get_ringparam
= bnxt_get_ringparam
,
1684 .get_channels
= bnxt_get_channels
,
1685 .set_channels
= bnxt_set_channels
,
1686 #ifdef CONFIG_RFS_ACCEL
1687 .get_rxnfc
= bnxt_get_rxnfc
,
1689 .get_rxfh_indir_size
= bnxt_get_rxfh_indir_size
,
1690 .get_rxfh_key_size
= bnxt_get_rxfh_key_size
,
1691 .get_rxfh
= bnxt_get_rxfh
,
1692 .flash_device
= bnxt_flash_device
,
1693 .get_eeprom_len
= bnxt_get_eeprom_len
,
1694 .get_eeprom
= bnxt_get_eeprom
,
1695 .set_eeprom
= bnxt_set_eeprom
,
1696 .get_link
= bnxt_get_link
,
1697 .get_eee
= bnxt_get_eee
,
1698 .set_eee
= bnxt_set_eee
,
1699 .get_module_info
= bnxt_get_module_info
,
1700 .get_module_eeprom
= bnxt_get_module_eeprom
,