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
= min_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 req_tx_rings
, req_rx_rings
, tcs
;
395 if (channel
->other_count
)
398 if (!channel
->combined_count
&&
399 (!channel
->rx_count
|| !channel
->tx_count
))
402 if (channel
->combined_count
&&
403 (channel
->rx_count
|| channel
->tx_count
))
406 if (BNXT_CHIP_TYPE_NITRO_A0(bp
) && (channel
->rx_count
||
410 if (channel
->combined_count
)
413 tcs
= netdev_get_num_tc(dev
);
415 req_tx_rings
= sh
? channel
->combined_count
: channel
->tx_count
;
416 req_rx_rings
= sh
? channel
->combined_count
: channel
->rx_count
;
417 if (bp
->tx_nr_rings_xdp
) {
419 netdev_err(dev
, "Only combined mode supported when XDP is enabled.\n");
422 tx_xdp
= req_rx_rings
;
424 rc
= bnxt_reserve_rings(bp
, req_tx_rings
, req_rx_rings
, tcs
, tx_xdp
);
426 netdev_warn(dev
, "Unable to allocate the requested rings\n");
430 if (netif_running(dev
)) {
432 /* TODO CHIMP_FW: Send message to all VF's
436 rc
= bnxt_close_nic(bp
, true, false);
438 netdev_err(bp
->dev
, "Set channel failure rc :%x\n",
445 bp
->flags
|= BNXT_FLAG_SHARED_RINGS
;
446 bp
->rx_nr_rings
= channel
->combined_count
;
447 bp
->tx_nr_rings_per_tc
= channel
->combined_count
;
449 bp
->flags
&= ~BNXT_FLAG_SHARED_RINGS
;
450 bp
->rx_nr_rings
= channel
->rx_count
;
451 bp
->tx_nr_rings_per_tc
= channel
->tx_count
;
453 bp
->tx_nr_rings_xdp
= tx_xdp
;
454 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
+ tx_xdp
;
456 bp
->tx_nr_rings
= bp
->tx_nr_rings_per_tc
* tcs
+ tx_xdp
;
458 bp
->cp_nr_rings
= sh
? max_t(int, bp
->tx_nr_rings
, bp
->rx_nr_rings
) :
459 bp
->tx_nr_rings
+ bp
->rx_nr_rings
;
461 bp
->num_stat_ctxs
= bp
->cp_nr_rings
;
463 /* After changing number of rx channels, update NTUPLE feature. */
464 netdev_update_features(dev
);
465 if (netif_running(dev
)) {
466 rc
= bnxt_open_nic(bp
, true, false);
467 if ((!rc
) && BNXT_PF(bp
)) {
468 /* TODO CHIMP_FW: Send message to all VF's
477 #ifdef CONFIG_RFS_ACCEL
478 static int bnxt_grxclsrlall(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
,
483 cmd
->data
= bp
->ntp_fltr_count
;
484 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
485 struct hlist_head
*head
;
486 struct bnxt_ntuple_filter
*fltr
;
488 head
= &bp
->ntp_fltr_hash_tbl
[i
];
490 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
491 if (j
== cmd
->rule_cnt
)
493 rule_locs
[j
++] = fltr
->sw_id
;
496 if (j
== cmd
->rule_cnt
)
503 static int bnxt_grxclsrule(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
)
505 struct ethtool_rx_flow_spec
*fs
=
506 (struct ethtool_rx_flow_spec
*)&cmd
->fs
;
507 struct bnxt_ntuple_filter
*fltr
;
508 struct flow_keys
*fkeys
;
511 if (fs
->location
< 0 || fs
->location
>= BNXT_NTP_FLTR_MAX_FLTR
)
514 for (i
= 0; i
< BNXT_NTP_FLTR_HASH_SIZE
; i
++) {
515 struct hlist_head
*head
;
517 head
= &bp
->ntp_fltr_hash_tbl
[i
];
519 hlist_for_each_entry_rcu(fltr
, head
, hash
) {
520 if (fltr
->sw_id
== fs
->location
)
528 fkeys
= &fltr
->fkeys
;
529 if (fkeys
->basic
.n_proto
== htons(ETH_P_IP
)) {
530 if (fkeys
->basic
.ip_proto
== IPPROTO_TCP
)
531 fs
->flow_type
= TCP_V4_FLOW
;
532 else if (fkeys
->basic
.ip_proto
== IPPROTO_UDP
)
533 fs
->flow_type
= UDP_V4_FLOW
;
537 fs
->h_u
.tcp_ip4_spec
.ip4src
= fkeys
->addrs
.v4addrs
.src
;
538 fs
->m_u
.tcp_ip4_spec
.ip4src
= cpu_to_be32(~0);
540 fs
->h_u
.tcp_ip4_spec
.ip4dst
= fkeys
->addrs
.v4addrs
.dst
;
541 fs
->m_u
.tcp_ip4_spec
.ip4dst
= cpu_to_be32(~0);
543 fs
->h_u
.tcp_ip4_spec
.psrc
= fkeys
->ports
.src
;
544 fs
->m_u
.tcp_ip4_spec
.psrc
= cpu_to_be16(~0);
546 fs
->h_u
.tcp_ip4_spec
.pdst
= fkeys
->ports
.dst
;
547 fs
->m_u
.tcp_ip4_spec
.pdst
= cpu_to_be16(~0);
551 if (fkeys
->basic
.ip_proto
== IPPROTO_TCP
)
552 fs
->flow_type
= TCP_V6_FLOW
;
553 else if (fkeys
->basic
.ip_proto
== IPPROTO_UDP
)
554 fs
->flow_type
= UDP_V6_FLOW
;
558 *(struct in6_addr
*)&fs
->h_u
.tcp_ip6_spec
.ip6src
[0] =
559 fkeys
->addrs
.v6addrs
.src
;
560 *(struct in6_addr
*)&fs
->h_u
.tcp_ip6_spec
.ip6dst
[0] =
561 fkeys
->addrs
.v6addrs
.dst
;
562 for (i
= 0; i
< 4; i
++) {
563 fs
->m_u
.tcp_ip6_spec
.ip6src
[i
] = cpu_to_be32(~0);
564 fs
->m_u
.tcp_ip6_spec
.ip6dst
[i
] = cpu_to_be32(~0);
566 fs
->h_u
.tcp_ip6_spec
.psrc
= fkeys
->ports
.src
;
567 fs
->m_u
.tcp_ip6_spec
.psrc
= cpu_to_be16(~0);
569 fs
->h_u
.tcp_ip6_spec
.pdst
= fkeys
->ports
.dst
;
570 fs
->m_u
.tcp_ip6_spec
.pdst
= cpu_to_be16(~0);
573 fs
->ring_cookie
= fltr
->rxq
;
583 static u64
get_ethtool_ipv4_rss(struct bnxt
*bp
)
585 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
)
586 return RXH_IP_SRC
| RXH_IP_DST
;
590 static u64
get_ethtool_ipv6_rss(struct bnxt
*bp
)
592 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
)
593 return RXH_IP_SRC
| RXH_IP_DST
;
597 static int bnxt_grxfh(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
)
600 switch (cmd
->flow_type
) {
602 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
)
603 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
|
604 RXH_L4_B_0_1
| RXH_L4_B_2_3
;
605 cmd
->data
|= get_ethtool_ipv4_rss(bp
);
608 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
)
609 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
|
610 RXH_L4_B_0_1
| RXH_L4_B_2_3
;
617 cmd
->data
|= get_ethtool_ipv4_rss(bp
);
621 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
)
622 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
|
623 RXH_L4_B_0_1
| RXH_L4_B_2_3
;
624 cmd
->data
|= get_ethtool_ipv6_rss(bp
);
627 if (bp
->rss_hash_cfg
& VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
)
628 cmd
->data
|= RXH_IP_SRC
| RXH_IP_DST
|
629 RXH_L4_B_0_1
| RXH_L4_B_2_3
;
636 cmd
->data
|= get_ethtool_ipv6_rss(bp
);
642 #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
643 #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
645 static int bnxt_srxfh(struct bnxt
*bp
, struct ethtool_rxnfc
*cmd
)
647 u32 rss_hash_cfg
= bp
->rss_hash_cfg
;
650 if (cmd
->data
== RXH_4TUPLE
)
652 else if (cmd
->data
== RXH_2TUPLE
)
659 if (cmd
->flow_type
== TCP_V4_FLOW
) {
660 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
;
662 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4
;
663 } else if (cmd
->flow_type
== UDP_V4_FLOW
) {
664 if (tuple
== 4 && !(bp
->flags
& BNXT_FLAG_UDP_RSS_CAP
))
666 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
;
668 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4
;
669 } else if (cmd
->flow_type
== TCP_V6_FLOW
) {
670 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
672 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6
;
673 } else if (cmd
->flow_type
== UDP_V6_FLOW
) {
674 if (tuple
== 4 && !(bp
->flags
& BNXT_FLAG_UDP_RSS_CAP
))
676 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
678 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6
;
679 } else if (tuple
== 4) {
683 switch (cmd
->flow_type
) {
692 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
;
694 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4
;
705 rss_hash_cfg
|= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
;
707 rss_hash_cfg
&= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6
;
711 if (bp
->rss_hash_cfg
== rss_hash_cfg
)
714 bp
->rss_hash_cfg
= rss_hash_cfg
;
715 if (netif_running(bp
->dev
)) {
716 bnxt_close_nic(bp
, false, false);
717 rc
= bnxt_open_nic(bp
, false, false);
722 static int bnxt_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
,
725 struct bnxt
*bp
= netdev_priv(dev
);
729 #ifdef CONFIG_RFS_ACCEL
730 case ETHTOOL_GRXRINGS
:
731 cmd
->data
= bp
->rx_nr_rings
;
734 case ETHTOOL_GRXCLSRLCNT
:
735 cmd
->rule_cnt
= bp
->ntp_fltr_count
;
736 cmd
->data
= BNXT_NTP_FLTR_MAX_FLTR
;
739 case ETHTOOL_GRXCLSRLALL
:
740 rc
= bnxt_grxclsrlall(bp
, cmd
, (u32
*)rule_locs
);
743 case ETHTOOL_GRXCLSRULE
:
744 rc
= bnxt_grxclsrule(bp
, cmd
);
749 rc
= bnxt_grxfh(bp
, cmd
);
760 static int bnxt_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*cmd
)
762 struct bnxt
*bp
= netdev_priv(dev
);
767 rc
= bnxt_srxfh(bp
, cmd
);
777 static u32
bnxt_get_rxfh_indir_size(struct net_device
*dev
)
779 return HW_HASH_INDEX_SIZE
;
782 static u32
bnxt_get_rxfh_key_size(struct net_device
*dev
)
784 return HW_HASH_KEY_SIZE
;
787 static int bnxt_get_rxfh(struct net_device
*dev
, u32
*indir
, u8
*key
,
790 struct bnxt
*bp
= netdev_priv(dev
);
791 struct bnxt_vnic_info
*vnic
= &bp
->vnic_info
[0];
795 *hfunc
= ETH_RSS_HASH_TOP
;
798 for (i
= 0; i
< HW_HASH_INDEX_SIZE
; i
++)
799 indir
[i
] = le16_to_cpu(vnic
->rss_table
[i
]);
802 memcpy(key
, vnic
->rss_hash_key
, HW_HASH_KEY_SIZE
);
807 static void bnxt_get_drvinfo(struct net_device
*dev
,
808 struct ethtool_drvinfo
*info
)
810 struct bnxt
*bp
= netdev_priv(dev
);
814 pkglog
= kmalloc(BNX_PKG_LOG_MAX_LENGTH
, GFP_KERNEL
);
816 pkgver
= bnxt_get_pkgver(dev
, pkglog
, BNX_PKG_LOG_MAX_LENGTH
);
817 strlcpy(info
->driver
, DRV_MODULE_NAME
, sizeof(info
->driver
));
818 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
819 if (pkgver
&& *pkgver
!= 0 && isdigit(*pkgver
))
820 snprintf(info
->fw_version
, sizeof(info
->fw_version
) - 1,
821 "%s pkg %s", bp
->fw_ver_str
, pkgver
);
823 strlcpy(info
->fw_version
, bp
->fw_ver_str
,
824 sizeof(info
->fw_version
));
825 strlcpy(info
->bus_info
, pci_name(bp
->pdev
), sizeof(info
->bus_info
));
826 info
->n_stats
= BNXT_NUM_STATS
* bp
->cp_nr_rings
;
827 info
->testinfo_len
= BNXT_NUM_TESTS(bp
);
828 /* TODO CHIMP_FW: eeprom dump details */
829 info
->eedump_len
= 0;
830 /* TODO CHIMP FW: reg dump details */
831 info
->regdump_len
= 0;
835 u32
_bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds
, u8 fw_pause
)
839 /* TODO: support 25GB, 40GB, 50GB with different cable type */
840 /* set the advertised speeds */
841 if (fw_speeds
& BNXT_LINK_SPEED_MSK_100MB
)
842 speed_mask
|= ADVERTISED_100baseT_Full
;
843 if (fw_speeds
& BNXT_LINK_SPEED_MSK_1GB
)
844 speed_mask
|= ADVERTISED_1000baseT_Full
;
845 if (fw_speeds
& BNXT_LINK_SPEED_MSK_2_5GB
)
846 speed_mask
|= ADVERTISED_2500baseX_Full
;
847 if (fw_speeds
& BNXT_LINK_SPEED_MSK_10GB
)
848 speed_mask
|= ADVERTISED_10000baseT_Full
;
849 if (fw_speeds
& BNXT_LINK_SPEED_MSK_40GB
)
850 speed_mask
|= ADVERTISED_40000baseCR4_Full
;
852 if ((fw_pause
& BNXT_LINK_PAUSE_BOTH
) == BNXT_LINK_PAUSE_BOTH
)
853 speed_mask
|= ADVERTISED_Pause
;
854 else if (fw_pause
& BNXT_LINK_PAUSE_TX
)
855 speed_mask
|= ADVERTISED_Asym_Pause
;
856 else if (fw_pause
& BNXT_LINK_PAUSE_RX
)
857 speed_mask
|= ADVERTISED_Pause
| ADVERTISED_Asym_Pause
;
862 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
864 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
865 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
867 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
868 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
870 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
871 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
873 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
874 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
876 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
877 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
879 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
880 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
882 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
883 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
885 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
886 ethtool_link_ksettings_add_link_mode( \
887 lk_ksettings, name, Asym_Pause);\
888 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
889 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
894 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
896 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
898 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
900 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
901 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
903 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
905 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
906 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
908 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
909 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
911 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
912 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
913 40000baseCR4_Full)) \
914 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
915 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
916 50000baseCR2_Full)) \
917 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
920 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info
*link_info
,
921 struct ethtool_link_ksettings
*lk_ksettings
)
923 u16 fw_speeds
= link_info
->advertising
;
926 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
927 fw_pause
= link_info
->auto_pause_setting
;
929 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, fw_pause
, lk_ksettings
, advertising
);
932 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info
*link_info
,
933 struct ethtool_link_ksettings
*lk_ksettings
)
935 u16 fw_speeds
= link_info
->lp_auto_link_speeds
;
938 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
939 fw_pause
= link_info
->lp_pause
;
941 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, fw_pause
, lk_ksettings
,
945 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info
*link_info
,
946 struct ethtool_link_ksettings
*lk_ksettings
)
948 u16 fw_speeds
= link_info
->support_speeds
;
950 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds
, 0, lk_ksettings
, supported
);
952 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
, Pause
);
953 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
956 if (link_info
->support_auto_speeds
)
957 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
961 u32
bnxt_fw_to_ethtool_speed(u16 fw_link_speed
)
963 switch (fw_link_speed
) {
964 case BNXT_LINK_SPEED_100MB
:
966 case BNXT_LINK_SPEED_1GB
:
968 case BNXT_LINK_SPEED_2_5GB
:
970 case BNXT_LINK_SPEED_10GB
:
972 case BNXT_LINK_SPEED_20GB
:
974 case BNXT_LINK_SPEED_25GB
:
976 case BNXT_LINK_SPEED_40GB
:
978 case BNXT_LINK_SPEED_50GB
:
981 return SPEED_UNKNOWN
;
985 static int bnxt_get_link_ksettings(struct net_device
*dev
,
986 struct ethtool_link_ksettings
*lk_ksettings
)
988 struct bnxt
*bp
= netdev_priv(dev
);
989 struct bnxt_link_info
*link_info
= &bp
->link_info
;
990 struct ethtool_link_settings
*base
= &lk_ksettings
->base
;
993 ethtool_link_ksettings_zero_link_mode(lk_ksettings
, supported
);
994 bnxt_fw_to_ethtool_support_spds(link_info
, lk_ksettings
);
996 ethtool_link_ksettings_zero_link_mode(lk_ksettings
, advertising
);
997 if (link_info
->autoneg
) {
998 bnxt_fw_to_ethtool_advertised_spds(link_info
, lk_ksettings
);
999 ethtool_link_ksettings_add_link_mode(lk_ksettings
,
1000 advertising
, Autoneg
);
1001 base
->autoneg
= AUTONEG_ENABLE
;
1002 if (link_info
->phy_link_status
== BNXT_LINK_LINK
)
1003 bnxt_fw_to_ethtool_lp_adv(link_info
, lk_ksettings
);
1004 ethtool_speed
= bnxt_fw_to_ethtool_speed(link_info
->link_speed
);
1005 if (!netif_carrier_ok(dev
))
1006 base
->duplex
= DUPLEX_UNKNOWN
;
1007 else if (link_info
->duplex
& BNXT_LINK_DUPLEX_FULL
)
1008 base
->duplex
= DUPLEX_FULL
;
1010 base
->duplex
= DUPLEX_HALF
;
1012 base
->autoneg
= AUTONEG_DISABLE
;
1014 bnxt_fw_to_ethtool_speed(link_info
->req_link_speed
);
1015 base
->duplex
= DUPLEX_HALF
;
1016 if (link_info
->req_duplex
== BNXT_LINK_DUPLEX_FULL
)
1017 base
->duplex
= DUPLEX_FULL
;
1019 base
->speed
= ethtool_speed
;
1021 base
->port
= PORT_NONE
;
1022 if (link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP
) {
1023 base
->port
= PORT_TP
;
1024 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
1026 ethtool_link_ksettings_add_link_mode(lk_ksettings
, advertising
,
1029 ethtool_link_ksettings_add_link_mode(lk_ksettings
, supported
,
1031 ethtool_link_ksettings_add_link_mode(lk_ksettings
, advertising
,
1034 if (link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC
)
1035 base
->port
= PORT_DA
;
1036 else if (link_info
->media_type
==
1037 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE
)
1038 base
->port
= PORT_FIBRE
;
1040 base
->phy_address
= link_info
->phy_addr
;
1045 static u32
bnxt_get_fw_speed(struct net_device
*dev
, u16 ethtool_speed
)
1047 struct bnxt
*bp
= netdev_priv(dev
);
1048 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1049 u16 support_spds
= link_info
->support_speeds
;
1052 switch (ethtool_speed
) {
1054 if (support_spds
& BNXT_LINK_SPEED_MSK_100MB
)
1055 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB
;
1058 if (support_spds
& BNXT_LINK_SPEED_MSK_1GB
)
1059 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB
;
1062 if (support_spds
& BNXT_LINK_SPEED_MSK_2_5GB
)
1063 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB
;
1066 if (support_spds
& BNXT_LINK_SPEED_MSK_10GB
)
1067 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB
;
1070 if (support_spds
& BNXT_LINK_SPEED_MSK_20GB
)
1071 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB
;
1074 if (support_spds
& BNXT_LINK_SPEED_MSK_25GB
)
1075 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB
;
1078 if (support_spds
& BNXT_LINK_SPEED_MSK_40GB
)
1079 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB
;
1082 if (support_spds
& BNXT_LINK_SPEED_MSK_50GB
)
1083 fw_speed
= PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB
;
1086 netdev_err(dev
, "unsupported speed!\n");
1092 u16
bnxt_get_fw_auto_link_speeds(u32 advertising
)
1094 u16 fw_speed_mask
= 0;
1096 /* only support autoneg at speed 100, 1000, and 10000 */
1097 if (advertising
& (ADVERTISED_100baseT_Full
|
1098 ADVERTISED_100baseT_Half
)) {
1099 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_100MB
;
1101 if (advertising
& (ADVERTISED_1000baseT_Full
|
1102 ADVERTISED_1000baseT_Half
)) {
1103 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_1GB
;
1105 if (advertising
& ADVERTISED_10000baseT_Full
)
1106 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_10GB
;
1108 if (advertising
& ADVERTISED_40000baseCR4_Full
)
1109 fw_speed_mask
|= BNXT_LINK_SPEED_MSK_40GB
;
1111 return fw_speed_mask
;
1114 static int bnxt_set_link_ksettings(struct net_device
*dev
,
1115 const struct ethtool_link_ksettings
*lk_ksettings
)
1117 struct bnxt
*bp
= netdev_priv(dev
);
1118 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1119 const struct ethtool_link_settings
*base
= &lk_ksettings
->base
;
1120 bool set_pause
= false;
1121 u16 fw_advertising
= 0;
1125 if (!BNXT_SINGLE_PF(bp
))
1128 if (base
->autoneg
== AUTONEG_ENABLE
) {
1129 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising
, lk_ksettings
,
1131 link_info
->autoneg
|= BNXT_AUTONEG_SPEED
;
1132 if (!fw_advertising
)
1133 link_info
->advertising
= link_info
->support_auto_speeds
;
1135 link_info
->advertising
= fw_advertising
;
1136 /* any change to autoneg will cause link change, therefore the
1137 * driver should put back the original pause setting in autoneg
1142 u8 phy_type
= link_info
->phy_type
;
1144 if (phy_type
== PORT_PHY_QCFG_RESP_PHY_TYPE_BASET
||
1145 phy_type
== PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE
||
1146 link_info
->media_type
== PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP
) {
1147 netdev_err(dev
, "10GBase-T devices must autoneg\n");
1149 goto set_setting_exit
;
1151 if (base
->duplex
== DUPLEX_HALF
) {
1152 netdev_err(dev
, "HALF DUPLEX is not supported!\n");
1154 goto set_setting_exit
;
1156 speed
= base
->speed
;
1157 fw_speed
= bnxt_get_fw_speed(dev
, speed
);
1160 goto set_setting_exit
;
1162 link_info
->req_link_speed
= fw_speed
;
1163 link_info
->req_duplex
= BNXT_LINK_DUPLEX_FULL
;
1164 link_info
->autoneg
= 0;
1165 link_info
->advertising
= 0;
1168 if (netif_running(dev
))
1169 rc
= bnxt_hwrm_set_link_setting(bp
, set_pause
, false);
1175 static void bnxt_get_pauseparam(struct net_device
*dev
,
1176 struct ethtool_pauseparam
*epause
)
1178 struct bnxt
*bp
= netdev_priv(dev
);
1179 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1183 epause
->autoneg
= !!(link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
);
1184 epause
->rx_pause
= !!(link_info
->req_flow_ctrl
& BNXT_LINK_PAUSE_RX
);
1185 epause
->tx_pause
= !!(link_info
->req_flow_ctrl
& BNXT_LINK_PAUSE_TX
);
1188 static int bnxt_set_pauseparam(struct net_device
*dev
,
1189 struct ethtool_pauseparam
*epause
)
1192 struct bnxt
*bp
= netdev_priv(dev
);
1193 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1195 if (!BNXT_SINGLE_PF(bp
))
1198 if (epause
->autoneg
) {
1199 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
))
1202 link_info
->autoneg
|= BNXT_AUTONEG_FLOW_CTRL
;
1203 if (bp
->hwrm_spec_code
>= 0x10201)
1204 link_info
->req_flow_ctrl
=
1205 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE
;
1207 /* when transition from auto pause to force pause,
1208 * force a link change
1210 if (link_info
->autoneg
& BNXT_AUTONEG_FLOW_CTRL
)
1211 link_info
->force_link_chng
= true;
1212 link_info
->autoneg
&= ~BNXT_AUTONEG_FLOW_CTRL
;
1213 link_info
->req_flow_ctrl
= 0;
1215 if (epause
->rx_pause
)
1216 link_info
->req_flow_ctrl
|= BNXT_LINK_PAUSE_RX
;
1218 if (epause
->tx_pause
)
1219 link_info
->req_flow_ctrl
|= BNXT_LINK_PAUSE_TX
;
1221 if (netif_running(dev
))
1222 rc
= bnxt_hwrm_set_pause(bp
);
1226 static u32
bnxt_get_link(struct net_device
*dev
)
1228 struct bnxt
*bp
= netdev_priv(dev
);
1230 /* TODO: handle MF, VF, driver close case */
1231 return bp
->link_info
.link_up
;
1234 static int bnxt_find_nvram_item(struct net_device
*dev
, u16 type
, u16 ordinal
,
1235 u16 ext
, u16
*index
, u32
*item_length
,
1238 static int bnxt_flash_nvram(struct net_device
*dev
,
1246 struct bnxt
*bp
= netdev_priv(dev
);
1248 struct hwrm_nvm_write_input req
= {0};
1249 dma_addr_t dma_handle
;
1252 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_WRITE
, -1, -1);
1254 req
.dir_type
= cpu_to_le16(dir_type
);
1255 req
.dir_ordinal
= cpu_to_le16(dir_ordinal
);
1256 req
.dir_ext
= cpu_to_le16(dir_ext
);
1257 req
.dir_attr
= cpu_to_le16(dir_attr
);
1258 req
.dir_data_length
= cpu_to_le32(data_len
);
1260 kmem
= dma_alloc_coherent(&bp
->pdev
->dev
, data_len
, &dma_handle
,
1263 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1264 (unsigned)data_len
);
1267 memcpy(kmem
, data
, data_len
);
1268 req
.host_src_addr
= cpu_to_le64(dma_handle
);
1270 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), FLASH_NVRAM_TIMEOUT
);
1271 dma_free_coherent(&bp
->pdev
->dev
, data_len
, kmem
, dma_handle
);
1276 static int bnxt_firmware_reset(struct net_device
*dev
,
1279 struct bnxt
*bp
= netdev_priv(dev
);
1280 struct hwrm_fw_reset_input req
= {0};
1282 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_FW_RESET
, -1, -1);
1284 /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */
1285 /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */
1286 /* (e.g. when firmware isn't already running) */
1288 case BNX_DIR_TYPE_CHIMP_PATCH
:
1289 case BNX_DIR_TYPE_BOOTCODE
:
1290 case BNX_DIR_TYPE_BOOTCODE_2
:
1291 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT
;
1292 /* Self-reset ChiMP upon next PCIe reset: */
1293 req
.selfrst_status
= FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST
;
1295 case BNX_DIR_TYPE_APE_FW
:
1296 case BNX_DIR_TYPE_APE_PATCH
:
1297 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT
;
1298 /* Self-reset APE upon next PCIe reset: */
1299 req
.selfrst_status
= FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST
;
1301 case BNX_DIR_TYPE_KONG_FW
:
1302 case BNX_DIR_TYPE_KONG_PATCH
:
1303 req
.embedded_proc_type
=
1304 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL
;
1306 case BNX_DIR_TYPE_BONO_FW
:
1307 case BNX_DIR_TYPE_BONO_PATCH
:
1308 req
.embedded_proc_type
= FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE
;
1314 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1317 static int bnxt_flash_firmware(struct net_device
*dev
,
1326 struct bnxt_fw_header
*header
= (struct bnxt_fw_header
*)fw_data
;
1329 case BNX_DIR_TYPE_BOOTCODE
:
1330 case BNX_DIR_TYPE_BOOTCODE_2
:
1331 code_type
= CODE_BOOT
;
1333 case BNX_DIR_TYPE_CHIMP_PATCH
:
1334 code_type
= CODE_CHIMP_PATCH
;
1336 case BNX_DIR_TYPE_APE_FW
:
1337 code_type
= CODE_MCTP_PASSTHRU
;
1339 case BNX_DIR_TYPE_APE_PATCH
:
1340 code_type
= CODE_APE_PATCH
;
1342 case BNX_DIR_TYPE_KONG_FW
:
1343 code_type
= CODE_KONG_FW
;
1345 case BNX_DIR_TYPE_KONG_PATCH
:
1346 code_type
= CODE_KONG_PATCH
;
1348 case BNX_DIR_TYPE_BONO_FW
:
1349 code_type
= CODE_BONO_FW
;
1351 case BNX_DIR_TYPE_BONO_PATCH
:
1352 code_type
= CODE_BONO_PATCH
;
1355 netdev_err(dev
, "Unsupported directory entry type: %u\n",
1359 if (fw_size
< sizeof(struct bnxt_fw_header
)) {
1360 netdev_err(dev
, "Invalid firmware file size: %u\n",
1361 (unsigned int)fw_size
);
1364 if (header
->signature
!= cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE
)) {
1365 netdev_err(dev
, "Invalid firmware signature: %08X\n",
1366 le32_to_cpu(header
->signature
));
1369 if (header
->code_type
!= code_type
) {
1370 netdev_err(dev
, "Expected firmware type: %d, read: %d\n",
1371 code_type
, header
->code_type
);
1374 if (header
->device
!= DEVICE_CUMULUS_FAMILY
) {
1375 netdev_err(dev
, "Expected firmware device family %d, read: %d\n",
1376 DEVICE_CUMULUS_FAMILY
, header
->device
);
1379 /* Confirm the CRC32 checksum of the file: */
1380 stored_crc
= le32_to_cpu(*(__le32
*)(fw_data
+ fw_size
-
1381 sizeof(stored_crc
)));
1382 calculated_crc
= ~crc32(~0, fw_data
, fw_size
- sizeof(stored_crc
));
1383 if (calculated_crc
!= stored_crc
) {
1384 netdev_err(dev
, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1385 (unsigned long)stored_crc
,
1386 (unsigned long)calculated_crc
);
1389 rc
= bnxt_flash_nvram(dev
, dir_type
, BNX_DIR_ORDINAL_FIRST
,
1390 0, 0, fw_data
, fw_size
);
1391 if (rc
== 0) /* Firmware update successful */
1392 rc
= bnxt_firmware_reset(dev
, dir_type
);
1397 static int bnxt_flash_microcode(struct net_device
*dev
,
1402 struct bnxt_ucode_trailer
*trailer
;
1407 if (fw_size
< sizeof(struct bnxt_ucode_trailer
)) {
1408 netdev_err(dev
, "Invalid microcode file size: %u\n",
1409 (unsigned int)fw_size
);
1412 trailer
= (struct bnxt_ucode_trailer
*)(fw_data
+ (fw_size
-
1414 if (trailer
->sig
!= cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE
)) {
1415 netdev_err(dev
, "Invalid microcode trailer signature: %08X\n",
1416 le32_to_cpu(trailer
->sig
));
1419 if (le16_to_cpu(trailer
->dir_type
) != dir_type
) {
1420 netdev_err(dev
, "Expected microcode type: %d, read: %d\n",
1421 dir_type
, le16_to_cpu(trailer
->dir_type
));
1424 if (le16_to_cpu(trailer
->trailer_length
) <
1425 sizeof(struct bnxt_ucode_trailer
)) {
1426 netdev_err(dev
, "Invalid microcode trailer length: %d\n",
1427 le16_to_cpu(trailer
->trailer_length
));
1431 /* Confirm the CRC32 checksum of the file: */
1432 stored_crc
= le32_to_cpu(*(__le32
*)(fw_data
+ fw_size
-
1433 sizeof(stored_crc
)));
1434 calculated_crc
= ~crc32(~0, fw_data
, fw_size
- sizeof(stored_crc
));
1435 if (calculated_crc
!= stored_crc
) {
1437 "CRC32 (%08lX) does not match calculated: %08lX\n",
1438 (unsigned long)stored_crc
,
1439 (unsigned long)calculated_crc
);
1442 rc
= bnxt_flash_nvram(dev
, dir_type
, BNX_DIR_ORDINAL_FIRST
,
1443 0, 0, fw_data
, fw_size
);
1448 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type
)
1451 case BNX_DIR_TYPE_CHIMP_PATCH
:
1452 case BNX_DIR_TYPE_BOOTCODE
:
1453 case BNX_DIR_TYPE_BOOTCODE_2
:
1454 case BNX_DIR_TYPE_APE_FW
:
1455 case BNX_DIR_TYPE_APE_PATCH
:
1456 case BNX_DIR_TYPE_KONG_FW
:
1457 case BNX_DIR_TYPE_KONG_PATCH
:
1458 case BNX_DIR_TYPE_BONO_FW
:
1459 case BNX_DIR_TYPE_BONO_PATCH
:
1466 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type
)
1469 case BNX_DIR_TYPE_AVS
:
1470 case BNX_DIR_TYPE_EXP_ROM_MBA
:
1471 case BNX_DIR_TYPE_PCIE
:
1472 case BNX_DIR_TYPE_TSCF_UCODE
:
1473 case BNX_DIR_TYPE_EXT_PHY
:
1474 case BNX_DIR_TYPE_CCM
:
1475 case BNX_DIR_TYPE_ISCSI_BOOT
:
1476 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6
:
1477 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6
:
1484 static bool bnxt_dir_type_is_executable(u16 dir_type
)
1486 return bnxt_dir_type_is_ape_bin_format(dir_type
) ||
1487 bnxt_dir_type_is_other_exec_format(dir_type
);
1490 static int bnxt_flash_firmware_from_file(struct net_device
*dev
,
1492 const char *filename
)
1494 const struct firmware
*fw
;
1497 rc
= request_firmware(&fw
, filename
, &dev
->dev
);
1499 netdev_err(dev
, "Error %d requesting firmware file: %s\n",
1503 if (bnxt_dir_type_is_ape_bin_format(dir_type
) == true)
1504 rc
= bnxt_flash_firmware(dev
, dir_type
, fw
->data
, fw
->size
);
1505 else if (bnxt_dir_type_is_other_exec_format(dir_type
) == true)
1506 rc
= bnxt_flash_microcode(dev
, dir_type
, fw
->data
, fw
->size
);
1508 rc
= bnxt_flash_nvram(dev
, dir_type
, BNX_DIR_ORDINAL_FIRST
,
1509 0, 0, fw
->data
, fw
->size
);
1510 release_firmware(fw
);
1514 static int bnxt_flash_package_from_file(struct net_device
*dev
,
1515 char *filename
, u32 install_type
)
1517 struct bnxt
*bp
= netdev_priv(dev
);
1518 struct hwrm_nvm_install_update_output
*resp
= bp
->hwrm_cmd_resp_addr
;
1519 struct hwrm_nvm_install_update_input install
= {0};
1520 const struct firmware
*fw
;
1525 bnxt_hwrm_fw_set_time(bp
);
1527 if (bnxt_find_nvram_item(dev
, BNX_DIR_TYPE_UPDATE
,
1528 BNX_DIR_ORDINAL_FIRST
, BNX_DIR_EXT_NONE
,
1529 &index
, &item_len
, NULL
) != 0) {
1530 netdev_err(dev
, "PKG update area not created in nvram\n");
1534 rc
= request_firmware(&fw
, filename
, &dev
->dev
);
1536 netdev_err(dev
, "PKG error %d requesting file: %s\n",
1541 if (fw
->size
> item_len
) {
1542 netdev_err(dev
, "PKG insufficient update area in nvram: %lu",
1543 (unsigned long)fw
->size
);
1546 dma_addr_t dma_handle
;
1548 struct hwrm_nvm_modify_input modify
= {0};
1550 bnxt_hwrm_cmd_hdr_init(bp
, &modify
, HWRM_NVM_MODIFY
, -1, -1);
1552 modify
.dir_idx
= cpu_to_le16(index
);
1553 modify
.len
= cpu_to_le32(fw
->size
);
1555 kmem
= dma_alloc_coherent(&bp
->pdev
->dev
, fw
->size
,
1556 &dma_handle
, GFP_KERNEL
);
1559 "dma_alloc_coherent failure, length = %u\n",
1560 (unsigned int)fw
->size
);
1563 memcpy(kmem
, fw
->data
, fw
->size
);
1564 modify
.host_src_addr
= cpu_to_le64(dma_handle
);
1566 rc
= hwrm_send_message(bp
, &modify
, sizeof(modify
),
1567 FLASH_PACKAGE_TIMEOUT
);
1568 dma_free_coherent(&bp
->pdev
->dev
, fw
->size
, kmem
,
1572 release_firmware(fw
);
1576 if ((install_type
& 0xffff) == 0)
1577 install_type
>>= 16;
1578 bnxt_hwrm_cmd_hdr_init(bp
, &install
, HWRM_NVM_INSTALL_UPDATE
, -1, -1);
1579 install
.install_type
= cpu_to_le32(install_type
);
1581 mutex_lock(&bp
->hwrm_cmd_lock
);
1582 rc
= _hwrm_send_message(bp
, &install
, sizeof(install
),
1583 INSTALL_PACKAGE_TIMEOUT
);
1586 goto flash_pkg_exit
;
1589 if (resp
->error_code
) {
1590 u8 error_code
= ((struct hwrm_err_output
*)resp
)->cmd_err
;
1592 if (error_code
== NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR
) {
1593 install
.flags
|= cpu_to_le16(
1594 NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG
);
1595 rc
= _hwrm_send_message(bp
, &install
, sizeof(install
),
1596 INSTALL_PACKAGE_TIMEOUT
);
1599 goto flash_pkg_exit
;
1605 netdev_err(dev
, "PKG install error = %d, problem_item = %d\n",
1606 (s8
)resp
->result
, (int)resp
->problem_item
);
1610 mutex_unlock(&bp
->hwrm_cmd_lock
);
1614 static int bnxt_flash_device(struct net_device
*dev
,
1615 struct ethtool_flash
*flash
)
1617 if (!BNXT_PF((struct bnxt
*)netdev_priv(dev
))) {
1618 netdev_err(dev
, "flashdev not supported from a virtual function\n");
1622 if (flash
->region
== ETHTOOL_FLASH_ALL_REGIONS
||
1623 flash
->region
> 0xffff)
1624 return bnxt_flash_package_from_file(dev
, flash
->data
,
1627 return bnxt_flash_firmware_from_file(dev
, flash
->region
, flash
->data
);
1630 static int nvm_get_dir_info(struct net_device
*dev
, u32
*entries
, u32
*length
)
1632 struct bnxt
*bp
= netdev_priv(dev
);
1634 struct hwrm_nvm_get_dir_info_input req
= {0};
1635 struct hwrm_nvm_get_dir_info_output
*output
= bp
->hwrm_cmd_resp_addr
;
1637 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_GET_DIR_INFO
, -1, -1);
1639 mutex_lock(&bp
->hwrm_cmd_lock
);
1640 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1642 *entries
= le32_to_cpu(output
->entries
);
1643 *length
= le32_to_cpu(output
->entry_length
);
1645 mutex_unlock(&bp
->hwrm_cmd_lock
);
1649 static int bnxt_get_eeprom_len(struct net_device
*dev
)
1651 /* The -1 return value allows the entire 32-bit range of offsets to be
1652 * passed via the ethtool command-line utility.
1657 static int bnxt_get_nvram_directory(struct net_device
*dev
, u32 len
, u8
*data
)
1659 struct bnxt
*bp
= netdev_priv(dev
);
1665 dma_addr_t dma_handle
;
1666 struct hwrm_nvm_get_dir_entries_input req
= {0};
1668 rc
= nvm_get_dir_info(dev
, &dir_entries
, &entry_length
);
1672 /* Insert 2 bytes of directory info (count and size of entries) */
1676 *data
++ = dir_entries
;
1677 *data
++ = entry_length
;
1679 memset(data
, 0xff, len
);
1681 buflen
= dir_entries
* entry_length
;
1682 buf
= dma_alloc_coherent(&bp
->pdev
->dev
, buflen
, &dma_handle
,
1685 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1689 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_GET_DIR_ENTRIES
, -1, -1);
1690 req
.host_dest_addr
= cpu_to_le64(dma_handle
);
1691 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1693 memcpy(data
, buf
, len
> buflen
? buflen
: len
);
1694 dma_free_coherent(&bp
->pdev
->dev
, buflen
, buf
, dma_handle
);
1698 static int bnxt_get_nvram_item(struct net_device
*dev
, u32 index
, u32 offset
,
1699 u32 length
, u8
*data
)
1701 struct bnxt
*bp
= netdev_priv(dev
);
1704 dma_addr_t dma_handle
;
1705 struct hwrm_nvm_read_input req
= {0};
1707 buf
= dma_alloc_coherent(&bp
->pdev
->dev
, length
, &dma_handle
,
1710 netdev_err(dev
, "dma_alloc_coherent failure, length = %u\n",
1714 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_READ
, -1, -1);
1715 req
.host_dest_addr
= cpu_to_le64(dma_handle
);
1716 req
.dir_idx
= cpu_to_le16(index
);
1717 req
.offset
= cpu_to_le32(offset
);
1718 req
.len
= cpu_to_le32(length
);
1720 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1722 memcpy(data
, buf
, length
);
1723 dma_free_coherent(&bp
->pdev
->dev
, length
, buf
, dma_handle
);
1727 static int bnxt_find_nvram_item(struct net_device
*dev
, u16 type
, u16 ordinal
,
1728 u16 ext
, u16
*index
, u32
*item_length
,
1731 struct bnxt
*bp
= netdev_priv(dev
);
1733 struct hwrm_nvm_find_dir_entry_input req
= {0};
1734 struct hwrm_nvm_find_dir_entry_output
*output
= bp
->hwrm_cmd_resp_addr
;
1736 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_FIND_DIR_ENTRY
, -1, -1);
1739 req
.dir_type
= cpu_to_le16(type
);
1740 req
.dir_ordinal
= cpu_to_le16(ordinal
);
1741 req
.dir_ext
= cpu_to_le16(ext
);
1742 req
.opt_ordinal
= NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ
;
1743 rc
= hwrm_send_message_silent(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1746 *index
= le16_to_cpu(output
->dir_idx
);
1748 *item_length
= le32_to_cpu(output
->dir_item_length
);
1750 *data_length
= le32_to_cpu(output
->dir_data_length
);
1755 static char *bnxt_parse_pkglog(int desired_field
, u8
*data
, size_t datalen
)
1757 char *retval
= NULL
;
1764 /* null-terminate the log data (removing last '\n'): */
1765 data
[datalen
- 1] = 0;
1766 for (p
= data
; *p
!= 0; p
++) {
1769 while (*p
!= 0 && *p
!= '\n') {
1771 while (*p
!= 0 && *p
!= '\t' && *p
!= '\n')
1773 if (field
== desired_field
)
1788 static char *bnxt_get_pkgver(struct net_device
*dev
, char *buf
, size_t buflen
)
1793 if (bnxt_find_nvram_item(dev
, BNX_DIR_TYPE_PKG_LOG
,
1794 BNX_DIR_ORDINAL_FIRST
, BNX_DIR_EXT_NONE
,
1795 &index
, NULL
, &datalen
) != 0)
1798 memset(buf
, 0, buflen
);
1799 if (bnxt_get_nvram_item(dev
, index
, 0, datalen
, buf
) != 0)
1802 return bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION
, buf
,
1806 static int bnxt_get_eeprom(struct net_device
*dev
,
1807 struct ethtool_eeprom
*eeprom
,
1813 if (eeprom
->offset
== 0) /* special offset value to get directory */
1814 return bnxt_get_nvram_directory(dev
, eeprom
->len
, data
);
1816 index
= eeprom
->offset
>> 24;
1817 offset
= eeprom
->offset
& 0xffffff;
1820 netdev_err(dev
, "unsupported index value: %d\n", index
);
1824 return bnxt_get_nvram_item(dev
, index
- 1, offset
, eeprom
->len
, data
);
1827 static int bnxt_erase_nvram_directory(struct net_device
*dev
, u8 index
)
1829 struct bnxt
*bp
= netdev_priv(dev
);
1830 struct hwrm_nvm_erase_dir_entry_input req
= {0};
1832 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_NVM_ERASE_DIR_ENTRY
, -1, -1);
1833 req
.dir_idx
= cpu_to_le16(index
);
1834 return hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
1837 static int bnxt_set_eeprom(struct net_device
*dev
,
1838 struct ethtool_eeprom
*eeprom
,
1841 struct bnxt
*bp
= netdev_priv(dev
);
1843 u16 type
, ext
, ordinal
, attr
;
1846 netdev_err(dev
, "NVM write not supported from a virtual function\n");
1850 type
= eeprom
->magic
>> 16;
1852 if (type
== 0xffff) { /* special value for directory operations */
1853 index
= eeprom
->magic
& 0xff;
1854 dir_op
= eeprom
->magic
>> 8;
1858 case 0x0e: /* erase */
1859 if (eeprom
->offset
!= ~eeprom
->magic
)
1861 return bnxt_erase_nvram_directory(dev
, index
- 1);
1867 /* Create or re-write an NVM item: */
1868 if (bnxt_dir_type_is_executable(type
) == true)
1870 ext
= eeprom
->magic
& 0xffff;
1871 ordinal
= eeprom
->offset
>> 16;
1872 attr
= eeprom
->offset
& 0xffff;
1874 return bnxt_flash_nvram(dev
, type
, ordinal
, ext
, attr
, data
,
1878 static int bnxt_set_eee(struct net_device
*dev
, struct ethtool_eee
*edata
)
1880 struct bnxt
*bp
= netdev_priv(dev
);
1881 struct ethtool_eee
*eee
= &bp
->eee
;
1882 struct bnxt_link_info
*link_info
= &bp
->link_info
;
1884 _bnxt_fw_to_ethtool_adv_spds(link_info
->advertising
, 0);
1887 if (!BNXT_SINGLE_PF(bp
))
1890 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
1893 if (!edata
->eee_enabled
)
1896 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
)) {
1897 netdev_warn(dev
, "EEE requires autoneg\n");
1900 if (edata
->tx_lpi_enabled
) {
1901 if (bp
->lpi_tmr_hi
&& (edata
->tx_lpi_timer
> bp
->lpi_tmr_hi
||
1902 edata
->tx_lpi_timer
< bp
->lpi_tmr_lo
)) {
1903 netdev_warn(dev
, "Valid LPI timer range is %d and %d microsecs\n",
1904 bp
->lpi_tmr_lo
, bp
->lpi_tmr_hi
);
1906 } else if (!bp
->lpi_tmr_hi
) {
1907 edata
->tx_lpi_timer
= eee
->tx_lpi_timer
;
1910 if (!edata
->advertised
) {
1911 edata
->advertised
= advertising
& eee
->supported
;
1912 } else if (edata
->advertised
& ~advertising
) {
1913 netdev_warn(dev
, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
1914 edata
->advertised
, advertising
);
1918 eee
->advertised
= edata
->advertised
;
1919 eee
->tx_lpi_enabled
= edata
->tx_lpi_enabled
;
1920 eee
->tx_lpi_timer
= edata
->tx_lpi_timer
;
1922 eee
->eee_enabled
= edata
->eee_enabled
;
1924 if (netif_running(dev
))
1925 rc
= bnxt_hwrm_set_link_setting(bp
, false, true);
1930 static int bnxt_get_eee(struct net_device
*dev
, struct ethtool_eee
*edata
)
1932 struct bnxt
*bp
= netdev_priv(dev
);
1934 if (!(bp
->flags
& BNXT_FLAG_EEE_CAP
))
1938 if (!bp
->eee
.eee_enabled
) {
1939 /* Preserve tx_lpi_timer so that the last value will be used
1940 * by default when it is re-enabled.
1942 edata
->advertised
= 0;
1943 edata
->tx_lpi_enabled
= 0;
1946 if (!bp
->eee
.eee_active
)
1947 edata
->lp_advertised
= 0;
1952 static int bnxt_read_sfp_module_eeprom_info(struct bnxt
*bp
, u16 i2c_addr
,
1953 u16 page_number
, u16 start_addr
,
1954 u16 data_length
, u8
*buf
)
1956 struct hwrm_port_phy_i2c_read_input req
= {0};
1957 struct hwrm_port_phy_i2c_read_output
*output
= bp
->hwrm_cmd_resp_addr
;
1958 int rc
, byte_offset
= 0;
1960 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_I2C_READ
, -1, -1);
1961 req
.i2c_slave_addr
= i2c_addr
;
1962 req
.page_number
= cpu_to_le16(page_number
);
1963 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
1967 xfer_size
= min_t(u16
, data_length
, BNXT_MAX_PHY_I2C_RESP_SIZE
);
1968 data_length
-= xfer_size
;
1969 req
.page_offset
= cpu_to_le16(start_addr
+ byte_offset
);
1970 req
.data_length
= xfer_size
;
1971 req
.enables
= cpu_to_le32(start_addr
+ byte_offset
?
1972 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET
: 0);
1973 mutex_lock(&bp
->hwrm_cmd_lock
);
1974 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
),
1977 memcpy(buf
+ byte_offset
, output
->data
, xfer_size
);
1978 mutex_unlock(&bp
->hwrm_cmd_lock
);
1979 byte_offset
+= xfer_size
;
1980 } while (!rc
&& data_length
> 0);
1985 static int bnxt_get_module_info(struct net_device
*dev
,
1986 struct ethtool_modinfo
*modinfo
)
1988 struct bnxt
*bp
= netdev_priv(dev
);
1989 struct hwrm_port_phy_i2c_read_input req
= {0};
1990 struct hwrm_port_phy_i2c_read_output
*output
= bp
->hwrm_cmd_resp_addr
;
1993 /* No point in going further if phy status indicates
1994 * module is not inserted or if it is powered down or
1995 * if it is of type 10GBase-T
1997 if (bp
->link_info
.module_status
>
1998 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG
)
2001 /* This feature is not supported in older firmware versions */
2002 if (bp
->hwrm_spec_code
< 0x10202)
2005 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_PHY_I2C_READ
, -1, -1);
2006 req
.i2c_slave_addr
= I2C_DEV_ADDR_A0
;
2007 req
.page_number
= 0;
2008 req
.page_offset
= cpu_to_le16(SFP_EEPROM_SFF_8472_COMP_ADDR
);
2009 req
.data_length
= SFP_EEPROM_SFF_8472_COMP_SIZE
;
2010 req
.port_id
= cpu_to_le16(bp
->pf
.port_id
);
2011 mutex_lock(&bp
->hwrm_cmd_lock
);
2012 rc
= _hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2014 u32 module_id
= le32_to_cpu(output
->data
[0]);
2016 switch (module_id
) {
2017 case SFF_MODULE_ID_SFP
:
2018 modinfo
->type
= ETH_MODULE_SFF_8472
;
2019 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
2021 case SFF_MODULE_ID_QSFP
:
2022 case SFF_MODULE_ID_QSFP_PLUS
:
2023 modinfo
->type
= ETH_MODULE_SFF_8436
;
2024 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
2026 case SFF_MODULE_ID_QSFP28
:
2027 modinfo
->type
= ETH_MODULE_SFF_8636
;
2028 modinfo
->eeprom_len
= ETH_MODULE_SFF_8636_LEN
;
2035 mutex_unlock(&bp
->hwrm_cmd_lock
);
2039 static int bnxt_get_module_eeprom(struct net_device
*dev
,
2040 struct ethtool_eeprom
*eeprom
,
2043 struct bnxt
*bp
= netdev_priv(dev
);
2044 u16 start
= eeprom
->offset
, length
= eeprom
->len
;
2047 memset(data
, 0, eeprom
->len
);
2049 /* Read A0 portion of the EEPROM */
2050 if (start
< ETH_MODULE_SFF_8436_LEN
) {
2051 if (start
+ eeprom
->len
> ETH_MODULE_SFF_8436_LEN
)
2052 length
= ETH_MODULE_SFF_8436_LEN
- start
;
2053 rc
= bnxt_read_sfp_module_eeprom_info(bp
, I2C_DEV_ADDR_A0
, 0,
2054 start
, length
, data
);
2059 length
= eeprom
->len
- length
;
2062 /* Read A2 portion of the EEPROM */
2064 start
-= ETH_MODULE_SFF_8436_LEN
;
2065 bnxt_read_sfp_module_eeprom_info(bp
, I2C_DEV_ADDR_A2
, 1, start
,
2071 static int bnxt_nway_reset(struct net_device
*dev
)
2075 struct bnxt
*bp
= netdev_priv(dev
);
2076 struct bnxt_link_info
*link_info
= &bp
->link_info
;
2078 if (!BNXT_SINGLE_PF(bp
))
2081 if (!(link_info
->autoneg
& BNXT_AUTONEG_SPEED
))
2084 if (netif_running(dev
))
2085 rc
= bnxt_hwrm_set_link_setting(bp
, true, false);
2090 static int bnxt_set_phys_id(struct net_device
*dev
,
2091 enum ethtool_phys_id_state state
)
2093 struct hwrm_port_led_cfg_input req
= {0};
2094 struct bnxt
*bp
= netdev_priv(dev
);
2095 struct bnxt_pf_info
*pf
= &bp
->pf
;
2096 struct bnxt_led_cfg
*led_cfg
;
2101 if (!bp
->num_leds
|| BNXT_VF(bp
))
2104 if (state
== ETHTOOL_ID_ACTIVE
) {
2105 led_state
= PORT_LED_CFG_REQ_LED0_STATE_BLINKALT
;
2106 duration
= cpu_to_le16(500);
2107 } else if (state
== ETHTOOL_ID_INACTIVE
) {
2108 led_state
= PORT_LED_CFG_REQ_LED1_STATE_DEFAULT
;
2109 duration
= cpu_to_le16(0);
2113 bnxt_hwrm_cmd_hdr_init(bp
, &req
, HWRM_PORT_LED_CFG
, -1, -1);
2114 req
.port_id
= cpu_to_le16(pf
->port_id
);
2115 req
.num_leds
= bp
->num_leds
;
2116 led_cfg
= (struct bnxt_led_cfg
*)&req
.led0_id
;
2117 for (i
= 0; i
< bp
->num_leds
; i
++, led_cfg
++) {
2118 req
.enables
|= BNXT_LED_DFLT_ENABLES(i
);
2119 led_cfg
->led_id
= bp
->leds
[i
].led_id
;
2120 led_cfg
->led_state
= led_state
;
2121 led_cfg
->led_blink_on
= duration
;
2122 led_cfg
->led_blink_off
= duration
;
2123 led_cfg
->led_group_id
= bp
->leds
[i
].led_group_id
;
2125 rc
= hwrm_send_message(bp
, &req
, sizeof(req
), HWRM_CMD_TIMEOUT
);
2131 const struct ethtool_ops bnxt_ethtool_ops
= {
2132 .get_link_ksettings
= bnxt_get_link_ksettings
,
2133 .set_link_ksettings
= bnxt_set_link_ksettings
,
2134 .get_pauseparam
= bnxt_get_pauseparam
,
2135 .set_pauseparam
= bnxt_set_pauseparam
,
2136 .get_drvinfo
= bnxt_get_drvinfo
,
2137 .get_coalesce
= bnxt_get_coalesce
,
2138 .set_coalesce
= bnxt_set_coalesce
,
2139 .get_msglevel
= bnxt_get_msglevel
,
2140 .set_msglevel
= bnxt_set_msglevel
,
2141 .get_sset_count
= bnxt_get_sset_count
,
2142 .get_strings
= bnxt_get_strings
,
2143 .get_ethtool_stats
= bnxt_get_ethtool_stats
,
2144 .set_ringparam
= bnxt_set_ringparam
,
2145 .get_ringparam
= bnxt_get_ringparam
,
2146 .get_channels
= bnxt_get_channels
,
2147 .set_channels
= bnxt_set_channels
,
2148 .get_rxnfc
= bnxt_get_rxnfc
,
2149 .set_rxnfc
= bnxt_set_rxnfc
,
2150 .get_rxfh_indir_size
= bnxt_get_rxfh_indir_size
,
2151 .get_rxfh_key_size
= bnxt_get_rxfh_key_size
,
2152 .get_rxfh
= bnxt_get_rxfh
,
2153 .flash_device
= bnxt_flash_device
,
2154 .get_eeprom_len
= bnxt_get_eeprom_len
,
2155 .get_eeprom
= bnxt_get_eeprom
,
2156 .set_eeprom
= bnxt_set_eeprom
,
2157 .get_link
= bnxt_get_link
,
2158 .get_eee
= bnxt_get_eee
,
2159 .set_eee
= bnxt_set_eee
,
2160 .get_module_info
= bnxt_get_module_info
,
2161 .get_module_eeprom
= bnxt_get_module_eeprom
,
2162 .nway_reset
= bnxt_nway_reset
,
2163 .set_phys_id
= bnxt_set_phys_id
,