This source file includes following definitions.
- bnxt_get_msglevel
- bnxt_set_msglevel
- bnxt_get_coalesce
- bnxt_set_coalesce
- bnxt_get_num_tpa_ring_stats
- bnxt_get_num_ring_stats
- bnxt_get_num_stats
- bnxt_get_sset_count
- bnxt_get_ethtool_stats
- bnxt_get_strings
- bnxt_get_ringparam
- bnxt_set_ringparam
- bnxt_get_channels
- bnxt_set_channels
- bnxt_grxclsrlall
- bnxt_grxclsrule
- get_ethtool_ipv4_rss
- get_ethtool_ipv6_rss
- bnxt_grxfh
- bnxt_srxfh
- bnxt_get_rxnfc
- bnxt_set_rxnfc
- bnxt_get_rxfh_indir_size
- bnxt_get_rxfh_key_size
- bnxt_get_rxfh
- bnxt_get_drvinfo
- bnxt_get_wol
- bnxt_set_wol
- _bnxt_fw_to_ethtool_adv_spds
- bnxt_fw_to_ethtool_advertised_spds
- bnxt_fw_to_ethtool_lp_adv
- bnxt_fw_to_ethtool_support_spds
- bnxt_fw_to_ethtool_speed
- bnxt_get_link_ksettings
- bnxt_get_fw_speed
- bnxt_get_fw_auto_link_speeds
- bnxt_set_link_ksettings
- bnxt_get_pauseparam
- bnxt_set_pauseparam
- bnxt_get_link
- bnxt_print_admin_err
- bnxt_flash_nvram
- bnxt_firmware_reset
- bnxt_flash_firmware
- bnxt_flash_microcode
- bnxt_dir_type_is_ape_bin_format
- bnxt_dir_type_is_other_exec_format
- bnxt_dir_type_is_executable
- bnxt_flash_firmware_from_file
- bnxt_flash_package_from_file
- bnxt_flash_device
- nvm_get_dir_info
- bnxt_get_eeprom_len
- bnxt_get_nvram_directory
- bnxt_get_nvram_item
- bnxt_find_nvram_item
- bnxt_parse_pkglog
- bnxt_get_pkgver
- bnxt_get_eeprom
- bnxt_erase_nvram_directory
- bnxt_set_eeprom
- bnxt_set_eee
- bnxt_get_eee
- bnxt_read_sfp_module_eeprom_info
- bnxt_get_module_info
- bnxt_get_module_eeprom
- bnxt_nway_reset
- bnxt_set_phys_id
- bnxt_hwrm_selftest_irq
- bnxt_test_irq
- bnxt_hwrm_mac_loopback
- bnxt_query_force_speeds
- bnxt_disable_an_for_lpbk
- bnxt_hwrm_phy_loopback
- bnxt_rx_loopback
- bnxt_poll_loopback
- bnxt_run_loopback
- bnxt_run_fw_tests
- bnxt_self_test
- bnxt_reset
- bnxt_hwrm_dbg_dma_data
- bnxt_hwrm_dbg_coredump_list
- bnxt_hwrm_dbg_coredump_initiate
- bnxt_hwrm_dbg_coredump_retrieve
- bnxt_fill_coredump_seg_hdr
- bnxt_fill_coredump_record
- bnxt_get_coredump
- bnxt_get_dump_flag
- bnxt_get_dump_data
- bnxt_ethtool_init
- bnxt_ethtool_free
1
2
3
4
5
6
7
8
9
10
11 #include <linux/ctype.h>
12 #include <linux/stringify.h>
13 #include <linux/ethtool.h>
14 #include <linux/interrupt.h>
15 #include <linux/pci.h>
16 #include <linux/etherdevice.h>
17 #include <linux/crc32.h>
18 #include <linux/firmware.h>
19 #include <linux/utsname.h>
20 #include <linux/time.h>
21 #include "bnxt_hsi.h"
22 #include "bnxt.h"
23 #include "bnxt_xdp.h"
24 #include "bnxt_ethtool.h"
25 #include "bnxt_nvm_defs.h"
26 #include "bnxt_fw_hdr.h"
27 #include "bnxt_coredump.h"
28 #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100)
29 #define FLASH_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
30 #define INSTALL_PACKAGE_TIMEOUT ((HWRM_CMD_TIMEOUT) * 200)
31
32 static u32 bnxt_get_msglevel(struct net_device *dev)
33 {
34 struct bnxt *bp = netdev_priv(dev);
35
36 return bp->msg_enable;
37 }
38
39 static void bnxt_set_msglevel(struct net_device *dev, u32 value)
40 {
41 struct bnxt *bp = netdev_priv(dev);
42
43 bp->msg_enable = value;
44 }
45
46 static int bnxt_get_coalesce(struct net_device *dev,
47 struct ethtool_coalesce *coal)
48 {
49 struct bnxt *bp = netdev_priv(dev);
50 struct bnxt_coal *hw_coal;
51 u16 mult;
52
53 memset(coal, 0, sizeof(*coal));
54
55 coal->use_adaptive_rx_coalesce = bp->flags & BNXT_FLAG_DIM;
56
57 hw_coal = &bp->rx_coal;
58 mult = hw_coal->bufs_per_record;
59 coal->rx_coalesce_usecs = hw_coal->coal_ticks;
60 coal->rx_max_coalesced_frames = hw_coal->coal_bufs / mult;
61 coal->rx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
62 coal->rx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
63
64 hw_coal = &bp->tx_coal;
65 mult = hw_coal->bufs_per_record;
66 coal->tx_coalesce_usecs = hw_coal->coal_ticks;
67 coal->tx_max_coalesced_frames = hw_coal->coal_bufs / mult;
68 coal->tx_coalesce_usecs_irq = hw_coal->coal_ticks_irq;
69 coal->tx_max_coalesced_frames_irq = hw_coal->coal_bufs_irq / mult;
70
71 coal->stats_block_coalesce_usecs = bp->stats_coal_ticks;
72
73 return 0;
74 }
75
76 static int bnxt_set_coalesce(struct net_device *dev,
77 struct ethtool_coalesce *coal)
78 {
79 struct bnxt *bp = netdev_priv(dev);
80 bool update_stats = false;
81 struct bnxt_coal *hw_coal;
82 int rc = 0;
83 u16 mult;
84
85 if (coal->use_adaptive_rx_coalesce) {
86 bp->flags |= BNXT_FLAG_DIM;
87 } else {
88 if (bp->flags & BNXT_FLAG_DIM) {
89 bp->flags &= ~(BNXT_FLAG_DIM);
90 goto reset_coalesce;
91 }
92 }
93
94 hw_coal = &bp->rx_coal;
95 mult = hw_coal->bufs_per_record;
96 hw_coal->coal_ticks = coal->rx_coalesce_usecs;
97 hw_coal->coal_bufs = coal->rx_max_coalesced_frames * mult;
98 hw_coal->coal_ticks_irq = coal->rx_coalesce_usecs_irq;
99 hw_coal->coal_bufs_irq = coal->rx_max_coalesced_frames_irq * mult;
100
101 hw_coal = &bp->tx_coal;
102 mult = hw_coal->bufs_per_record;
103 hw_coal->coal_ticks = coal->tx_coalesce_usecs;
104 hw_coal->coal_bufs = coal->tx_max_coalesced_frames * mult;
105 hw_coal->coal_ticks_irq = coal->tx_coalesce_usecs_irq;
106 hw_coal->coal_bufs_irq = coal->tx_max_coalesced_frames_irq * mult;
107
108 if (bp->stats_coal_ticks != coal->stats_block_coalesce_usecs) {
109 u32 stats_ticks = coal->stats_block_coalesce_usecs;
110
111
112 if (stats_ticks)
113 stats_ticks = clamp_t(u32, stats_ticks,
114 BNXT_MIN_STATS_COAL_TICKS,
115 BNXT_MAX_STATS_COAL_TICKS);
116 stats_ticks = rounddown(stats_ticks, BNXT_MIN_STATS_COAL_TICKS);
117 bp->stats_coal_ticks = stats_ticks;
118 if (bp->stats_coal_ticks)
119 bp->current_interval =
120 bp->stats_coal_ticks * HZ / 1000000;
121 else
122 bp->current_interval = BNXT_TIMER_INTERVAL;
123 update_stats = true;
124 }
125
126 reset_coalesce:
127 if (netif_running(dev)) {
128 if (update_stats) {
129 rc = bnxt_close_nic(bp, true, false);
130 if (!rc)
131 rc = bnxt_open_nic(bp, true, false);
132 } else {
133 rc = bnxt_hwrm_set_coal(bp);
134 }
135 }
136
137 return rc;
138 }
139
140 static const char * const bnxt_ring_stats_str[] = {
141 "rx_ucast_packets",
142 "rx_mcast_packets",
143 "rx_bcast_packets",
144 "rx_discards",
145 "rx_drops",
146 "rx_ucast_bytes",
147 "rx_mcast_bytes",
148 "rx_bcast_bytes",
149 "tx_ucast_packets",
150 "tx_mcast_packets",
151 "tx_bcast_packets",
152 "tx_discards",
153 "tx_drops",
154 "tx_ucast_bytes",
155 "tx_mcast_bytes",
156 "tx_bcast_bytes",
157 };
158
159 static const char * const bnxt_ring_tpa_stats_str[] = {
160 "tpa_packets",
161 "tpa_bytes",
162 "tpa_events",
163 "tpa_aborts",
164 };
165
166 static const char * const bnxt_ring_tpa2_stats_str[] = {
167 "rx_tpa_eligible_pkt",
168 "rx_tpa_eligible_bytes",
169 "rx_tpa_pkt",
170 "rx_tpa_bytes",
171 "rx_tpa_errors",
172 };
173
174 static const char * const bnxt_ring_sw_stats_str[] = {
175 "rx_l4_csum_errors",
176 "rx_buf_errors",
177 "missed_irqs",
178 };
179
180 #define BNXT_RX_STATS_ENTRY(counter) \
181 { BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
182
183 #define BNXT_TX_STATS_ENTRY(counter) \
184 { BNXT_TX_STATS_OFFSET(counter), __stringify(counter) }
185
186 #define BNXT_RX_STATS_EXT_ENTRY(counter) \
187 { BNXT_RX_STATS_EXT_OFFSET(counter), __stringify(counter) }
188
189 #define BNXT_TX_STATS_EXT_ENTRY(counter) \
190 { BNXT_TX_STATS_EXT_OFFSET(counter), __stringify(counter) }
191
192 #define BNXT_RX_STATS_EXT_PFC_ENTRY(n) \
193 BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_duration_us), \
194 BNXT_RX_STATS_EXT_ENTRY(pfc_pri##n##_rx_transitions)
195
196 #define BNXT_TX_STATS_EXT_PFC_ENTRY(n) \
197 BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_duration_us), \
198 BNXT_TX_STATS_EXT_ENTRY(pfc_pri##n##_tx_transitions)
199
200 #define BNXT_RX_STATS_EXT_PFC_ENTRIES \
201 BNXT_RX_STATS_EXT_PFC_ENTRY(0), \
202 BNXT_RX_STATS_EXT_PFC_ENTRY(1), \
203 BNXT_RX_STATS_EXT_PFC_ENTRY(2), \
204 BNXT_RX_STATS_EXT_PFC_ENTRY(3), \
205 BNXT_RX_STATS_EXT_PFC_ENTRY(4), \
206 BNXT_RX_STATS_EXT_PFC_ENTRY(5), \
207 BNXT_RX_STATS_EXT_PFC_ENTRY(6), \
208 BNXT_RX_STATS_EXT_PFC_ENTRY(7)
209
210 #define BNXT_TX_STATS_EXT_PFC_ENTRIES \
211 BNXT_TX_STATS_EXT_PFC_ENTRY(0), \
212 BNXT_TX_STATS_EXT_PFC_ENTRY(1), \
213 BNXT_TX_STATS_EXT_PFC_ENTRY(2), \
214 BNXT_TX_STATS_EXT_PFC_ENTRY(3), \
215 BNXT_TX_STATS_EXT_PFC_ENTRY(4), \
216 BNXT_TX_STATS_EXT_PFC_ENTRY(5), \
217 BNXT_TX_STATS_EXT_PFC_ENTRY(6), \
218 BNXT_TX_STATS_EXT_PFC_ENTRY(7)
219
220 #define BNXT_RX_STATS_EXT_COS_ENTRY(n) \
221 BNXT_RX_STATS_EXT_ENTRY(rx_bytes_cos##n), \
222 BNXT_RX_STATS_EXT_ENTRY(rx_packets_cos##n)
223
224 #define BNXT_TX_STATS_EXT_COS_ENTRY(n) \
225 BNXT_TX_STATS_EXT_ENTRY(tx_bytes_cos##n), \
226 BNXT_TX_STATS_EXT_ENTRY(tx_packets_cos##n)
227
228 #define BNXT_RX_STATS_EXT_COS_ENTRIES \
229 BNXT_RX_STATS_EXT_COS_ENTRY(0), \
230 BNXT_RX_STATS_EXT_COS_ENTRY(1), \
231 BNXT_RX_STATS_EXT_COS_ENTRY(2), \
232 BNXT_RX_STATS_EXT_COS_ENTRY(3), \
233 BNXT_RX_STATS_EXT_COS_ENTRY(4), \
234 BNXT_RX_STATS_EXT_COS_ENTRY(5), \
235 BNXT_RX_STATS_EXT_COS_ENTRY(6), \
236 BNXT_RX_STATS_EXT_COS_ENTRY(7) \
237
238 #define BNXT_TX_STATS_EXT_COS_ENTRIES \
239 BNXT_TX_STATS_EXT_COS_ENTRY(0), \
240 BNXT_TX_STATS_EXT_COS_ENTRY(1), \
241 BNXT_TX_STATS_EXT_COS_ENTRY(2), \
242 BNXT_TX_STATS_EXT_COS_ENTRY(3), \
243 BNXT_TX_STATS_EXT_COS_ENTRY(4), \
244 BNXT_TX_STATS_EXT_COS_ENTRY(5), \
245 BNXT_TX_STATS_EXT_COS_ENTRY(6), \
246 BNXT_TX_STATS_EXT_COS_ENTRY(7) \
247
248 #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(n) \
249 BNXT_RX_STATS_EXT_ENTRY(rx_discard_bytes_cos##n), \
250 BNXT_RX_STATS_EXT_ENTRY(rx_discard_packets_cos##n)
251
252 #define BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES \
253 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(0), \
254 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(1), \
255 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(2), \
256 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(3), \
257 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(4), \
258 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(5), \
259 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(6), \
260 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRY(7)
261
262 #define BNXT_RX_STATS_PRI_ENTRY(counter, n) \
263 { BNXT_RX_STATS_EXT_OFFSET(counter##_cos0), \
264 __stringify(counter##_pri##n) }
265
266 #define BNXT_TX_STATS_PRI_ENTRY(counter, n) \
267 { BNXT_TX_STATS_EXT_OFFSET(counter##_cos0), \
268 __stringify(counter##_pri##n) }
269
270 #define BNXT_RX_STATS_PRI_ENTRIES(counter) \
271 BNXT_RX_STATS_PRI_ENTRY(counter, 0), \
272 BNXT_RX_STATS_PRI_ENTRY(counter, 1), \
273 BNXT_RX_STATS_PRI_ENTRY(counter, 2), \
274 BNXT_RX_STATS_PRI_ENTRY(counter, 3), \
275 BNXT_RX_STATS_PRI_ENTRY(counter, 4), \
276 BNXT_RX_STATS_PRI_ENTRY(counter, 5), \
277 BNXT_RX_STATS_PRI_ENTRY(counter, 6), \
278 BNXT_RX_STATS_PRI_ENTRY(counter, 7)
279
280 #define BNXT_TX_STATS_PRI_ENTRIES(counter) \
281 BNXT_TX_STATS_PRI_ENTRY(counter, 0), \
282 BNXT_TX_STATS_PRI_ENTRY(counter, 1), \
283 BNXT_TX_STATS_PRI_ENTRY(counter, 2), \
284 BNXT_TX_STATS_PRI_ENTRY(counter, 3), \
285 BNXT_TX_STATS_PRI_ENTRY(counter, 4), \
286 BNXT_TX_STATS_PRI_ENTRY(counter, 5), \
287 BNXT_TX_STATS_PRI_ENTRY(counter, 6), \
288 BNXT_TX_STATS_PRI_ENTRY(counter, 7)
289
290 #define BNXT_PCIE_STATS_ENTRY(counter) \
291 { BNXT_PCIE_STATS_OFFSET(counter), __stringify(counter) }
292
293 enum {
294 RX_TOTAL_DISCARDS,
295 TX_TOTAL_DISCARDS,
296 };
297
298 static struct {
299 u64 counter;
300 char string[ETH_GSTRING_LEN];
301 } bnxt_sw_func_stats[] = {
302 {0, "rx_total_discard_pkts"},
303 {0, "tx_total_discard_pkts"},
304 };
305
306 static const struct {
307 long offset;
308 char string[ETH_GSTRING_LEN];
309 } bnxt_port_stats_arr[] = {
310 BNXT_RX_STATS_ENTRY(rx_64b_frames),
311 BNXT_RX_STATS_ENTRY(rx_65b_127b_frames),
312 BNXT_RX_STATS_ENTRY(rx_128b_255b_frames),
313 BNXT_RX_STATS_ENTRY(rx_256b_511b_frames),
314 BNXT_RX_STATS_ENTRY(rx_512b_1023b_frames),
315 BNXT_RX_STATS_ENTRY(rx_1024b_1518b_frames),
316 BNXT_RX_STATS_ENTRY(rx_good_vlan_frames),
317 BNXT_RX_STATS_ENTRY(rx_1519b_2047b_frames),
318 BNXT_RX_STATS_ENTRY(rx_2048b_4095b_frames),
319 BNXT_RX_STATS_ENTRY(rx_4096b_9216b_frames),
320 BNXT_RX_STATS_ENTRY(rx_9217b_16383b_frames),
321 BNXT_RX_STATS_ENTRY(rx_total_frames),
322 BNXT_RX_STATS_ENTRY(rx_ucast_frames),
323 BNXT_RX_STATS_ENTRY(rx_mcast_frames),
324 BNXT_RX_STATS_ENTRY(rx_bcast_frames),
325 BNXT_RX_STATS_ENTRY(rx_fcs_err_frames),
326 BNXT_RX_STATS_ENTRY(rx_ctrl_frames),
327 BNXT_RX_STATS_ENTRY(rx_pause_frames),
328 BNXT_RX_STATS_ENTRY(rx_pfc_frames),
329 BNXT_RX_STATS_ENTRY(rx_align_err_frames),
330 BNXT_RX_STATS_ENTRY(rx_ovrsz_frames),
331 BNXT_RX_STATS_ENTRY(rx_jbr_frames),
332 BNXT_RX_STATS_ENTRY(rx_mtu_err_frames),
333 BNXT_RX_STATS_ENTRY(rx_tagged_frames),
334 BNXT_RX_STATS_ENTRY(rx_double_tagged_frames),
335 BNXT_RX_STATS_ENTRY(rx_good_frames),
336 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri0),
337 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri1),
338 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri2),
339 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri3),
340 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri4),
341 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri5),
342 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri6),
343 BNXT_RX_STATS_ENTRY(rx_pfc_ena_frames_pri7),
344 BNXT_RX_STATS_ENTRY(rx_undrsz_frames),
345 BNXT_RX_STATS_ENTRY(rx_eee_lpi_events),
346 BNXT_RX_STATS_ENTRY(rx_eee_lpi_duration),
347 BNXT_RX_STATS_ENTRY(rx_bytes),
348 BNXT_RX_STATS_ENTRY(rx_runt_bytes),
349 BNXT_RX_STATS_ENTRY(rx_runt_frames),
350 BNXT_RX_STATS_ENTRY(rx_stat_discard),
351 BNXT_RX_STATS_ENTRY(rx_stat_err),
352
353 BNXT_TX_STATS_ENTRY(tx_64b_frames),
354 BNXT_TX_STATS_ENTRY(tx_65b_127b_frames),
355 BNXT_TX_STATS_ENTRY(tx_128b_255b_frames),
356 BNXT_TX_STATS_ENTRY(tx_256b_511b_frames),
357 BNXT_TX_STATS_ENTRY(tx_512b_1023b_frames),
358 BNXT_TX_STATS_ENTRY(tx_1024b_1518b_frames),
359 BNXT_TX_STATS_ENTRY(tx_good_vlan_frames),
360 BNXT_TX_STATS_ENTRY(tx_1519b_2047b_frames),
361 BNXT_TX_STATS_ENTRY(tx_2048b_4095b_frames),
362 BNXT_TX_STATS_ENTRY(tx_4096b_9216b_frames),
363 BNXT_TX_STATS_ENTRY(tx_9217b_16383b_frames),
364 BNXT_TX_STATS_ENTRY(tx_good_frames),
365 BNXT_TX_STATS_ENTRY(tx_total_frames),
366 BNXT_TX_STATS_ENTRY(tx_ucast_frames),
367 BNXT_TX_STATS_ENTRY(tx_mcast_frames),
368 BNXT_TX_STATS_ENTRY(tx_bcast_frames),
369 BNXT_TX_STATS_ENTRY(tx_pause_frames),
370 BNXT_TX_STATS_ENTRY(tx_pfc_frames),
371 BNXT_TX_STATS_ENTRY(tx_jabber_frames),
372 BNXT_TX_STATS_ENTRY(tx_fcs_err_frames),
373 BNXT_TX_STATS_ENTRY(tx_err),
374 BNXT_TX_STATS_ENTRY(tx_fifo_underruns),
375 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri0),
376 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri1),
377 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri2),
378 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri3),
379 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri4),
380 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri5),
381 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri6),
382 BNXT_TX_STATS_ENTRY(tx_pfc_ena_frames_pri7),
383 BNXT_TX_STATS_ENTRY(tx_eee_lpi_events),
384 BNXT_TX_STATS_ENTRY(tx_eee_lpi_duration),
385 BNXT_TX_STATS_ENTRY(tx_total_collisions),
386 BNXT_TX_STATS_ENTRY(tx_bytes),
387 BNXT_TX_STATS_ENTRY(tx_xthol_frames),
388 BNXT_TX_STATS_ENTRY(tx_stat_discard),
389 BNXT_TX_STATS_ENTRY(tx_stat_error),
390 };
391
392 static const struct {
393 long offset;
394 char string[ETH_GSTRING_LEN];
395 } bnxt_port_stats_ext_arr[] = {
396 BNXT_RX_STATS_EXT_ENTRY(link_down_events),
397 BNXT_RX_STATS_EXT_ENTRY(continuous_pause_events),
398 BNXT_RX_STATS_EXT_ENTRY(resume_pause_events),
399 BNXT_RX_STATS_EXT_ENTRY(continuous_roce_pause_events),
400 BNXT_RX_STATS_EXT_ENTRY(resume_roce_pause_events),
401 BNXT_RX_STATS_EXT_COS_ENTRIES,
402 BNXT_RX_STATS_EXT_PFC_ENTRIES,
403 BNXT_RX_STATS_EXT_ENTRY(rx_bits),
404 BNXT_RX_STATS_EXT_ENTRY(rx_buffer_passed_threshold),
405 BNXT_RX_STATS_EXT_ENTRY(rx_pcs_symbol_err),
406 BNXT_RX_STATS_EXT_ENTRY(rx_corrected_bits),
407 BNXT_RX_STATS_EXT_DISCARD_COS_ENTRIES,
408 };
409
410 static const struct {
411 long offset;
412 char string[ETH_GSTRING_LEN];
413 } bnxt_tx_port_stats_ext_arr[] = {
414 BNXT_TX_STATS_EXT_COS_ENTRIES,
415 BNXT_TX_STATS_EXT_PFC_ENTRIES,
416 };
417
418 static const struct {
419 long base_off;
420 char string[ETH_GSTRING_LEN];
421 } bnxt_rx_bytes_pri_arr[] = {
422 BNXT_RX_STATS_PRI_ENTRIES(rx_bytes),
423 };
424
425 static const struct {
426 long base_off;
427 char string[ETH_GSTRING_LEN];
428 } bnxt_rx_pkts_pri_arr[] = {
429 BNXT_RX_STATS_PRI_ENTRIES(rx_packets),
430 };
431
432 static const struct {
433 long base_off;
434 char string[ETH_GSTRING_LEN];
435 } bnxt_tx_bytes_pri_arr[] = {
436 BNXT_TX_STATS_PRI_ENTRIES(tx_bytes),
437 };
438
439 static const struct {
440 long base_off;
441 char string[ETH_GSTRING_LEN];
442 } bnxt_tx_pkts_pri_arr[] = {
443 BNXT_TX_STATS_PRI_ENTRIES(tx_packets),
444 };
445
446 static const struct {
447 long offset;
448 char string[ETH_GSTRING_LEN];
449 } bnxt_pcie_stats_arr[] = {
450 BNXT_PCIE_STATS_ENTRY(pcie_pl_signal_integrity),
451 BNXT_PCIE_STATS_ENTRY(pcie_dl_signal_integrity),
452 BNXT_PCIE_STATS_ENTRY(pcie_tl_signal_integrity),
453 BNXT_PCIE_STATS_ENTRY(pcie_link_integrity),
454 BNXT_PCIE_STATS_ENTRY(pcie_tx_traffic_rate),
455 BNXT_PCIE_STATS_ENTRY(pcie_rx_traffic_rate),
456 BNXT_PCIE_STATS_ENTRY(pcie_tx_dllp_statistics),
457 BNXT_PCIE_STATS_ENTRY(pcie_rx_dllp_statistics),
458 BNXT_PCIE_STATS_ENTRY(pcie_equalization_time),
459 BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[0]),
460 BNXT_PCIE_STATS_ENTRY(pcie_ltssm_histogram[2]),
461 BNXT_PCIE_STATS_ENTRY(pcie_recovery_histogram),
462 };
463
464 #define BNXT_NUM_SW_FUNC_STATS ARRAY_SIZE(bnxt_sw_func_stats)
465 #define BNXT_NUM_PORT_STATS ARRAY_SIZE(bnxt_port_stats_arr)
466 #define BNXT_NUM_STATS_PRI \
467 (ARRAY_SIZE(bnxt_rx_bytes_pri_arr) + \
468 ARRAY_SIZE(bnxt_rx_pkts_pri_arr) + \
469 ARRAY_SIZE(bnxt_tx_bytes_pri_arr) + \
470 ARRAY_SIZE(bnxt_tx_pkts_pri_arr))
471 #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr)
472
473 static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp)
474 {
475 if (BNXT_SUPPORTS_TPA(bp)) {
476 if (bp->max_tpa_v2)
477 return ARRAY_SIZE(bnxt_ring_tpa2_stats_str);
478 return ARRAY_SIZE(bnxt_ring_tpa_stats_str);
479 }
480 return 0;
481 }
482
483 static int bnxt_get_num_ring_stats(struct bnxt *bp)
484 {
485 int num_stats;
486
487 num_stats = ARRAY_SIZE(bnxt_ring_stats_str) +
488 ARRAY_SIZE(bnxt_ring_sw_stats_str) +
489 bnxt_get_num_tpa_ring_stats(bp);
490 return num_stats * bp->cp_nr_rings;
491 }
492
493 static int bnxt_get_num_stats(struct bnxt *bp)
494 {
495 int num_stats = bnxt_get_num_ring_stats(bp);
496
497 num_stats += BNXT_NUM_SW_FUNC_STATS;
498
499 if (bp->flags & BNXT_FLAG_PORT_STATS)
500 num_stats += BNXT_NUM_PORT_STATS;
501
502 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
503 num_stats += bp->fw_rx_stats_ext_size +
504 bp->fw_tx_stats_ext_size;
505 if (bp->pri2cos_valid)
506 num_stats += BNXT_NUM_STATS_PRI;
507 }
508
509 if (bp->flags & BNXT_FLAG_PCIE_STATS)
510 num_stats += BNXT_NUM_PCIE_STATS;
511
512 return num_stats;
513 }
514
515 static int bnxt_get_sset_count(struct net_device *dev, int sset)
516 {
517 struct bnxt *bp = netdev_priv(dev);
518
519 switch (sset) {
520 case ETH_SS_STATS:
521 return bnxt_get_num_stats(bp);
522 case ETH_SS_TEST:
523 if (!bp->num_tests)
524 return -EOPNOTSUPP;
525 return bp->num_tests;
526 default:
527 return -EOPNOTSUPP;
528 }
529 }
530
531 static void bnxt_get_ethtool_stats(struct net_device *dev,
532 struct ethtool_stats *stats, u64 *buf)
533 {
534 u32 i, j = 0;
535 struct bnxt *bp = netdev_priv(dev);
536 u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str) +
537 bnxt_get_num_tpa_ring_stats(bp);
538
539 if (!bp->bnapi) {
540 j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS;
541 goto skip_ring_stats;
542 }
543
544 for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++)
545 bnxt_sw_func_stats[i].counter = 0;
546
547 for (i = 0; i < bp->cp_nr_rings; i++) {
548 struct bnxt_napi *bnapi = bp->bnapi[i];
549 struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
550 __le64 *hw_stats = (__le64 *)cpr->hw_stats;
551 int k;
552
553 for (k = 0; k < stat_fields; j++, k++)
554 buf[j] = le64_to_cpu(hw_stats[k]);
555 buf[j++] = cpr->rx_l4_csum_errors;
556 buf[j++] = cpr->rx_buf_errors;
557 buf[j++] = cpr->missed_irqs;
558
559 bnxt_sw_func_stats[RX_TOTAL_DISCARDS].counter +=
560 le64_to_cpu(cpr->hw_stats->rx_discard_pkts);
561 bnxt_sw_func_stats[TX_TOTAL_DISCARDS].counter +=
562 le64_to_cpu(cpr->hw_stats->tx_discard_pkts);
563 }
564
565 for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++, j++)
566 buf[j] = bnxt_sw_func_stats[i].counter;
567
568 skip_ring_stats:
569 if (bp->flags & BNXT_FLAG_PORT_STATS) {
570 __le64 *port_stats = (__le64 *)bp->hw_rx_port_stats;
571
572 for (i = 0; i < BNXT_NUM_PORT_STATS; i++, j++) {
573 buf[j] = le64_to_cpu(*(port_stats +
574 bnxt_port_stats_arr[i].offset));
575 }
576 }
577 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
578 __le64 *rx_port_stats_ext = (__le64 *)bp->hw_rx_port_stats_ext;
579 __le64 *tx_port_stats_ext = (__le64 *)bp->hw_tx_port_stats_ext;
580
581 for (i = 0; i < bp->fw_rx_stats_ext_size; i++, j++) {
582 buf[j] = le64_to_cpu(*(rx_port_stats_ext +
583 bnxt_port_stats_ext_arr[i].offset));
584 }
585 for (i = 0; i < bp->fw_tx_stats_ext_size; i++, j++) {
586 buf[j] = le64_to_cpu(*(tx_port_stats_ext +
587 bnxt_tx_port_stats_ext_arr[i].offset));
588 }
589 if (bp->pri2cos_valid) {
590 for (i = 0; i < 8; i++, j++) {
591 long n = bnxt_rx_bytes_pri_arr[i].base_off +
592 bp->pri2cos_idx[i];
593
594 buf[j] = le64_to_cpu(*(rx_port_stats_ext + n));
595 }
596 for (i = 0; i < 8; i++, j++) {
597 long n = bnxt_rx_pkts_pri_arr[i].base_off +
598 bp->pri2cos_idx[i];
599
600 buf[j] = le64_to_cpu(*(rx_port_stats_ext + n));
601 }
602 for (i = 0; i < 8; i++, j++) {
603 long n = bnxt_tx_bytes_pri_arr[i].base_off +
604 bp->pri2cos_idx[i];
605
606 buf[j] = le64_to_cpu(*(tx_port_stats_ext + n));
607 }
608 for (i = 0; i < 8; i++, j++) {
609 long n = bnxt_tx_pkts_pri_arr[i].base_off +
610 bp->pri2cos_idx[i];
611
612 buf[j] = le64_to_cpu(*(tx_port_stats_ext + n));
613 }
614 }
615 }
616 if (bp->flags & BNXT_FLAG_PCIE_STATS) {
617 __le64 *pcie_stats = (__le64 *)bp->hw_pcie_stats;
618
619 for (i = 0; i < BNXT_NUM_PCIE_STATS; i++, j++) {
620 buf[j] = le64_to_cpu(*(pcie_stats +
621 bnxt_pcie_stats_arr[i].offset));
622 }
623 }
624 }
625
626 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
627 {
628 struct bnxt *bp = netdev_priv(dev);
629 static const char * const *str;
630 u32 i, j, num_str;
631
632 switch (stringset) {
633 case ETH_SS_STATS:
634 for (i = 0; i < bp->cp_nr_rings; i++) {
635 num_str = ARRAY_SIZE(bnxt_ring_stats_str);
636 for (j = 0; j < num_str; j++) {
637 sprintf(buf, "[%d]: %s", i,
638 bnxt_ring_stats_str[j]);
639 buf += ETH_GSTRING_LEN;
640 }
641 if (!BNXT_SUPPORTS_TPA(bp))
642 goto skip_tpa_stats;
643
644 if (bp->max_tpa_v2) {
645 num_str = ARRAY_SIZE(bnxt_ring_tpa2_stats_str);
646 str = bnxt_ring_tpa2_stats_str;
647 } else {
648 num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str);
649 str = bnxt_ring_tpa_stats_str;
650 }
651 for (j = 0; j < num_str; j++) {
652 sprintf(buf, "[%d]: %s", i, str[j]);
653 buf += ETH_GSTRING_LEN;
654 }
655 skip_tpa_stats:
656 num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str);
657 for (j = 0; j < num_str; j++) {
658 sprintf(buf, "[%d]: %s", i,
659 bnxt_ring_sw_stats_str[j]);
660 buf += ETH_GSTRING_LEN;
661 }
662 }
663 for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) {
664 strcpy(buf, bnxt_sw_func_stats[i].string);
665 buf += ETH_GSTRING_LEN;
666 }
667
668 if (bp->flags & BNXT_FLAG_PORT_STATS) {
669 for (i = 0; i < BNXT_NUM_PORT_STATS; i++) {
670 strcpy(buf, bnxt_port_stats_arr[i].string);
671 buf += ETH_GSTRING_LEN;
672 }
673 }
674 if (bp->flags & BNXT_FLAG_PORT_STATS_EXT) {
675 for (i = 0; i < bp->fw_rx_stats_ext_size; i++) {
676 strcpy(buf, bnxt_port_stats_ext_arr[i].string);
677 buf += ETH_GSTRING_LEN;
678 }
679 for (i = 0; i < bp->fw_tx_stats_ext_size; i++) {
680 strcpy(buf,
681 bnxt_tx_port_stats_ext_arr[i].string);
682 buf += ETH_GSTRING_LEN;
683 }
684 if (bp->pri2cos_valid) {
685 for (i = 0; i < 8; i++) {
686 strcpy(buf,
687 bnxt_rx_bytes_pri_arr[i].string);
688 buf += ETH_GSTRING_LEN;
689 }
690 for (i = 0; i < 8; i++) {
691 strcpy(buf,
692 bnxt_rx_pkts_pri_arr[i].string);
693 buf += ETH_GSTRING_LEN;
694 }
695 for (i = 0; i < 8; i++) {
696 strcpy(buf,
697 bnxt_tx_bytes_pri_arr[i].string);
698 buf += ETH_GSTRING_LEN;
699 }
700 for (i = 0; i < 8; i++) {
701 strcpy(buf,
702 bnxt_tx_pkts_pri_arr[i].string);
703 buf += ETH_GSTRING_LEN;
704 }
705 }
706 }
707 if (bp->flags & BNXT_FLAG_PCIE_STATS) {
708 for (i = 0; i < BNXT_NUM_PCIE_STATS; i++) {
709 strcpy(buf, bnxt_pcie_stats_arr[i].string);
710 buf += ETH_GSTRING_LEN;
711 }
712 }
713 break;
714 case ETH_SS_TEST:
715 if (bp->num_tests)
716 memcpy(buf, bp->test_info->string,
717 bp->num_tests * ETH_GSTRING_LEN);
718 break;
719 default:
720 netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n",
721 stringset);
722 break;
723 }
724 }
725
726 static void bnxt_get_ringparam(struct net_device *dev,
727 struct ethtool_ringparam *ering)
728 {
729 struct bnxt *bp = netdev_priv(dev);
730
731 ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT;
732 ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT;
733 ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT;
734
735 ering->rx_pending = bp->rx_ring_size;
736 ering->rx_jumbo_pending = bp->rx_agg_ring_size;
737 ering->tx_pending = bp->tx_ring_size;
738 }
739
740 static int bnxt_set_ringparam(struct net_device *dev,
741 struct ethtool_ringparam *ering)
742 {
743 struct bnxt *bp = netdev_priv(dev);
744
745 if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) ||
746 (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) ||
747 (ering->tx_pending <= MAX_SKB_FRAGS))
748 return -EINVAL;
749
750 if (netif_running(dev))
751 bnxt_close_nic(bp, false, false);
752
753 bp->rx_ring_size = ering->rx_pending;
754 bp->tx_ring_size = ering->tx_pending;
755 bnxt_set_ring_params(bp);
756
757 if (netif_running(dev))
758 return bnxt_open_nic(bp, false, false);
759
760 return 0;
761 }
762
763 static void bnxt_get_channels(struct net_device *dev,
764 struct ethtool_channels *channel)
765 {
766 struct bnxt *bp = netdev_priv(dev);
767 struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
768 int max_rx_rings, max_tx_rings, tcs;
769 int max_tx_sch_inputs;
770
771
772 if (BNXT_NEW_RM(bp))
773 bnxt_hwrm_func_resc_qcaps(bp, false);
774 max_tx_sch_inputs = hw_resc->max_tx_sch_inputs;
775
776 bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true);
777 if (max_tx_sch_inputs)
778 max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
779 channel->max_combined = min_t(int, max_rx_rings, max_tx_rings);
780
781 if (bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false)) {
782 max_rx_rings = 0;
783 max_tx_rings = 0;
784 }
785 if (max_tx_sch_inputs)
786 max_tx_rings = min_t(int, max_tx_rings, max_tx_sch_inputs);
787
788 tcs = netdev_get_num_tc(dev);
789 if (tcs > 1)
790 max_tx_rings /= tcs;
791
792 channel->max_rx = max_rx_rings;
793 channel->max_tx = max_tx_rings;
794 channel->max_other = 0;
795 if (bp->flags & BNXT_FLAG_SHARED_RINGS) {
796 channel->combined_count = bp->rx_nr_rings;
797 if (BNXT_CHIP_TYPE_NITRO_A0(bp))
798 channel->combined_count--;
799 } else {
800 if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) {
801 channel->rx_count = bp->rx_nr_rings;
802 channel->tx_count = bp->tx_nr_rings_per_tc;
803 }
804 }
805 }
806
807 static int bnxt_set_channels(struct net_device *dev,
808 struct ethtool_channels *channel)
809 {
810 struct bnxt *bp = netdev_priv(dev);
811 int req_tx_rings, req_rx_rings, tcs;
812 bool sh = false;
813 int tx_xdp = 0;
814 int rc = 0;
815
816 if (channel->other_count)
817 return -EINVAL;
818
819 if (!channel->combined_count &&
820 (!channel->rx_count || !channel->tx_count))
821 return -EINVAL;
822
823 if (channel->combined_count &&
824 (channel->rx_count || channel->tx_count))
825 return -EINVAL;
826
827 if (BNXT_CHIP_TYPE_NITRO_A0(bp) && (channel->rx_count ||
828 channel->tx_count))
829 return -EINVAL;
830
831 if (channel->combined_count)
832 sh = true;
833
834 tcs = netdev_get_num_tc(dev);
835
836 req_tx_rings = sh ? channel->combined_count : channel->tx_count;
837 req_rx_rings = sh ? channel->combined_count : channel->rx_count;
838 if (bp->tx_nr_rings_xdp) {
839 if (!sh) {
840 netdev_err(dev, "Only combined mode supported when XDP is enabled.\n");
841 return -EINVAL;
842 }
843 tx_xdp = req_rx_rings;
844 }
845 rc = bnxt_check_rings(bp, req_tx_rings, req_rx_rings, sh, tcs, tx_xdp);
846 if (rc) {
847 netdev_warn(dev, "Unable to allocate the requested rings\n");
848 return rc;
849 }
850
851 if (netif_running(dev)) {
852 if (BNXT_PF(bp)) {
853
854
855
856 }
857 rc = bnxt_close_nic(bp, true, false);
858 if (rc) {
859 netdev_err(bp->dev, "Set channel failure rc :%x\n",
860 rc);
861 return rc;
862 }
863 }
864
865 if (sh) {
866 bp->flags |= BNXT_FLAG_SHARED_RINGS;
867 bp->rx_nr_rings = channel->combined_count;
868 bp->tx_nr_rings_per_tc = channel->combined_count;
869 } else {
870 bp->flags &= ~BNXT_FLAG_SHARED_RINGS;
871 bp->rx_nr_rings = channel->rx_count;
872 bp->tx_nr_rings_per_tc = channel->tx_count;
873 }
874 bp->tx_nr_rings_xdp = tx_xdp;
875 bp->tx_nr_rings = bp->tx_nr_rings_per_tc + tx_xdp;
876 if (tcs > 1)
877 bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs + tx_xdp;
878
879 bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) :
880 bp->tx_nr_rings + bp->rx_nr_rings;
881
882
883 netdev_update_features(dev);
884 if (netif_running(dev)) {
885 rc = bnxt_open_nic(bp, true, false);
886 if ((!rc) && BNXT_PF(bp)) {
887
888
889
890 }
891 } else {
892 rc = bnxt_reserve_rings(bp, true);
893 }
894
895 return rc;
896 }
897
898 #ifdef CONFIG_RFS_ACCEL
899 static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd,
900 u32 *rule_locs)
901 {
902 int i, j = 0;
903
904 cmd->data = bp->ntp_fltr_count;
905 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
906 struct hlist_head *head;
907 struct bnxt_ntuple_filter *fltr;
908
909 head = &bp->ntp_fltr_hash_tbl[i];
910 rcu_read_lock();
911 hlist_for_each_entry_rcu(fltr, head, hash) {
912 if (j == cmd->rule_cnt)
913 break;
914 rule_locs[j++] = fltr->sw_id;
915 }
916 rcu_read_unlock();
917 if (j == cmd->rule_cnt)
918 break;
919 }
920 cmd->rule_cnt = j;
921 return 0;
922 }
923
924 static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd)
925 {
926 struct ethtool_rx_flow_spec *fs =
927 (struct ethtool_rx_flow_spec *)&cmd->fs;
928 struct bnxt_ntuple_filter *fltr;
929 struct flow_keys *fkeys;
930 int i, rc = -EINVAL;
931
932 if (fs->location >= BNXT_NTP_FLTR_MAX_FLTR)
933 return rc;
934
935 for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) {
936 struct hlist_head *head;
937
938 head = &bp->ntp_fltr_hash_tbl[i];
939 rcu_read_lock();
940 hlist_for_each_entry_rcu(fltr, head, hash) {
941 if (fltr->sw_id == fs->location)
942 goto fltr_found;
943 }
944 rcu_read_unlock();
945 }
946 return rc;
947
948 fltr_found:
949 fkeys = &fltr->fkeys;
950 if (fkeys->basic.n_proto == htons(ETH_P_IP)) {
951 if (fkeys->basic.ip_proto == IPPROTO_TCP)
952 fs->flow_type = TCP_V4_FLOW;
953 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
954 fs->flow_type = UDP_V4_FLOW;
955 else
956 goto fltr_err;
957
958 fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src;
959 fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0);
960
961 fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst;
962 fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0);
963
964 fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src;
965 fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0);
966
967 fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst;
968 fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0);
969 } else {
970 int i;
971
972 if (fkeys->basic.ip_proto == IPPROTO_TCP)
973 fs->flow_type = TCP_V6_FLOW;
974 else if (fkeys->basic.ip_proto == IPPROTO_UDP)
975 fs->flow_type = UDP_V6_FLOW;
976 else
977 goto fltr_err;
978
979 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6src[0] =
980 fkeys->addrs.v6addrs.src;
981 *(struct in6_addr *)&fs->h_u.tcp_ip6_spec.ip6dst[0] =
982 fkeys->addrs.v6addrs.dst;
983 for (i = 0; i < 4; i++) {
984 fs->m_u.tcp_ip6_spec.ip6src[i] = cpu_to_be32(~0);
985 fs->m_u.tcp_ip6_spec.ip6dst[i] = cpu_to_be32(~0);
986 }
987 fs->h_u.tcp_ip6_spec.psrc = fkeys->ports.src;
988 fs->m_u.tcp_ip6_spec.psrc = cpu_to_be16(~0);
989
990 fs->h_u.tcp_ip6_spec.pdst = fkeys->ports.dst;
991 fs->m_u.tcp_ip6_spec.pdst = cpu_to_be16(~0);
992 }
993
994 fs->ring_cookie = fltr->rxq;
995 rc = 0;
996
997 fltr_err:
998 rcu_read_unlock();
999
1000 return rc;
1001 }
1002 #endif
1003
1004 static u64 get_ethtool_ipv4_rss(struct bnxt *bp)
1005 {
1006 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4)
1007 return RXH_IP_SRC | RXH_IP_DST;
1008 return 0;
1009 }
1010
1011 static u64 get_ethtool_ipv6_rss(struct bnxt *bp)
1012 {
1013 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6)
1014 return RXH_IP_SRC | RXH_IP_DST;
1015 return 0;
1016 }
1017
1018 static int bnxt_grxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
1019 {
1020 cmd->data = 0;
1021 switch (cmd->flow_type) {
1022 case TCP_V4_FLOW:
1023 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4)
1024 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1025 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1026 cmd->data |= get_ethtool_ipv4_rss(bp);
1027 break;
1028 case UDP_V4_FLOW:
1029 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4)
1030 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1031 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1032
1033 case SCTP_V4_FLOW:
1034 case AH_ESP_V4_FLOW:
1035 case AH_V4_FLOW:
1036 case ESP_V4_FLOW:
1037 case IPV4_FLOW:
1038 cmd->data |= get_ethtool_ipv4_rss(bp);
1039 break;
1040
1041 case TCP_V6_FLOW:
1042 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6)
1043 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1044 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1045 cmd->data |= get_ethtool_ipv6_rss(bp);
1046 break;
1047 case UDP_V6_FLOW:
1048 if (bp->rss_hash_cfg & VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6)
1049 cmd->data |= RXH_IP_SRC | RXH_IP_DST |
1050 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1051
1052 case SCTP_V6_FLOW:
1053 case AH_ESP_V6_FLOW:
1054 case AH_V6_FLOW:
1055 case ESP_V6_FLOW:
1056 case IPV6_FLOW:
1057 cmd->data |= get_ethtool_ipv6_rss(bp);
1058 break;
1059 }
1060 return 0;
1061 }
1062
1063 #define RXH_4TUPLE (RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3)
1064 #define RXH_2TUPLE (RXH_IP_SRC | RXH_IP_DST)
1065
1066 static int bnxt_srxfh(struct bnxt *bp, struct ethtool_rxnfc *cmd)
1067 {
1068 u32 rss_hash_cfg = bp->rss_hash_cfg;
1069 int tuple, rc = 0;
1070
1071 if (cmd->data == RXH_4TUPLE)
1072 tuple = 4;
1073 else if (cmd->data == RXH_2TUPLE)
1074 tuple = 2;
1075 else if (!cmd->data)
1076 tuple = 0;
1077 else
1078 return -EINVAL;
1079
1080 if (cmd->flow_type == TCP_V4_FLOW) {
1081 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
1082 if (tuple == 4)
1083 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4;
1084 } else if (cmd->flow_type == UDP_V4_FLOW) {
1085 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
1086 return -EINVAL;
1087 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
1088 if (tuple == 4)
1089 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4;
1090 } else if (cmd->flow_type == TCP_V6_FLOW) {
1091 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
1092 if (tuple == 4)
1093 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6;
1094 } else if (cmd->flow_type == UDP_V6_FLOW) {
1095 if (tuple == 4 && !(bp->flags & BNXT_FLAG_UDP_RSS_CAP))
1096 return -EINVAL;
1097 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
1098 if (tuple == 4)
1099 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6;
1100 } else if (tuple == 4) {
1101 return -EINVAL;
1102 }
1103
1104 switch (cmd->flow_type) {
1105 case TCP_V4_FLOW:
1106 case UDP_V4_FLOW:
1107 case SCTP_V4_FLOW:
1108 case AH_ESP_V4_FLOW:
1109 case AH_V4_FLOW:
1110 case ESP_V4_FLOW:
1111 case IPV4_FLOW:
1112 if (tuple == 2)
1113 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
1114 else if (!tuple)
1115 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4;
1116 break;
1117
1118 case TCP_V6_FLOW:
1119 case UDP_V6_FLOW:
1120 case SCTP_V6_FLOW:
1121 case AH_ESP_V6_FLOW:
1122 case AH_V6_FLOW:
1123 case ESP_V6_FLOW:
1124 case IPV6_FLOW:
1125 if (tuple == 2)
1126 rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
1127 else if (!tuple)
1128 rss_hash_cfg &= ~VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6;
1129 break;
1130 }
1131
1132 if (bp->rss_hash_cfg == rss_hash_cfg)
1133 return 0;
1134
1135 bp->rss_hash_cfg = rss_hash_cfg;
1136 if (netif_running(bp->dev)) {
1137 bnxt_close_nic(bp, false, false);
1138 rc = bnxt_open_nic(bp, false, false);
1139 }
1140 return rc;
1141 }
1142
1143 static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
1144 u32 *rule_locs)
1145 {
1146 struct bnxt *bp = netdev_priv(dev);
1147 int rc = 0;
1148
1149 switch (cmd->cmd) {
1150 #ifdef CONFIG_RFS_ACCEL
1151 case ETHTOOL_GRXRINGS:
1152 cmd->data = bp->rx_nr_rings;
1153 break;
1154
1155 case ETHTOOL_GRXCLSRLCNT:
1156 cmd->rule_cnt = bp->ntp_fltr_count;
1157 cmd->data = BNXT_NTP_FLTR_MAX_FLTR;
1158 break;
1159
1160 case ETHTOOL_GRXCLSRLALL:
1161 rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs);
1162 break;
1163
1164 case ETHTOOL_GRXCLSRULE:
1165 rc = bnxt_grxclsrule(bp, cmd);
1166 break;
1167 #endif
1168
1169 case ETHTOOL_GRXFH:
1170 rc = bnxt_grxfh(bp, cmd);
1171 break;
1172
1173 default:
1174 rc = -EOPNOTSUPP;
1175 break;
1176 }
1177
1178 return rc;
1179 }
1180
1181 static int bnxt_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
1182 {
1183 struct bnxt *bp = netdev_priv(dev);
1184 int rc;
1185
1186 switch (cmd->cmd) {
1187 case ETHTOOL_SRXFH:
1188 rc = bnxt_srxfh(bp, cmd);
1189 break;
1190
1191 default:
1192 rc = -EOPNOTSUPP;
1193 break;
1194 }
1195 return rc;
1196 }
1197
1198 static u32 bnxt_get_rxfh_indir_size(struct net_device *dev)
1199 {
1200 return HW_HASH_INDEX_SIZE;
1201 }
1202
1203 static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
1204 {
1205 return HW_HASH_KEY_SIZE;
1206 }
1207
1208 static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
1209 u8 *hfunc)
1210 {
1211 struct bnxt *bp = netdev_priv(dev);
1212 struct bnxt_vnic_info *vnic;
1213 int i = 0;
1214
1215 if (hfunc)
1216 *hfunc = ETH_RSS_HASH_TOP;
1217
1218 if (!bp->vnic_info)
1219 return 0;
1220
1221 vnic = &bp->vnic_info[0];
1222 if (indir && vnic->rss_table) {
1223 for (i = 0; i < HW_HASH_INDEX_SIZE; i++)
1224 indir[i] = le16_to_cpu(vnic->rss_table[i]);
1225 }
1226
1227 if (key && vnic->rss_hash_key)
1228 memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
1229
1230 return 0;
1231 }
1232
1233 static void bnxt_get_drvinfo(struct net_device *dev,
1234 struct ethtool_drvinfo *info)
1235 {
1236 struct bnxt *bp = netdev_priv(dev);
1237
1238 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
1239 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
1240 strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version));
1241 strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info));
1242 info->n_stats = bnxt_get_num_stats(bp);
1243 info->testinfo_len = bp->num_tests;
1244
1245 info->eedump_len = 0;
1246
1247 info->regdump_len = 0;
1248 }
1249
1250 static void bnxt_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1251 {
1252 struct bnxt *bp = netdev_priv(dev);
1253
1254 wol->supported = 0;
1255 wol->wolopts = 0;
1256 memset(&wol->sopass, 0, sizeof(wol->sopass));
1257 if (bp->flags & BNXT_FLAG_WOL_CAP) {
1258 wol->supported = WAKE_MAGIC;
1259 if (bp->wol)
1260 wol->wolopts = WAKE_MAGIC;
1261 }
1262 }
1263
1264 static int bnxt_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1265 {
1266 struct bnxt *bp = netdev_priv(dev);
1267
1268 if (wol->wolopts & ~WAKE_MAGIC)
1269 return -EINVAL;
1270
1271 if (wol->wolopts & WAKE_MAGIC) {
1272 if (!(bp->flags & BNXT_FLAG_WOL_CAP))
1273 return -EINVAL;
1274 if (!bp->wol) {
1275 if (bnxt_hwrm_alloc_wol_fltr(bp))
1276 return -EBUSY;
1277 bp->wol = 1;
1278 }
1279 } else {
1280 if (bp->wol) {
1281 if (bnxt_hwrm_free_wol_fltr(bp))
1282 return -EBUSY;
1283 bp->wol = 0;
1284 }
1285 }
1286 return 0;
1287 }
1288
1289 u32 _bnxt_fw_to_ethtool_adv_spds(u16 fw_speeds, u8 fw_pause)
1290 {
1291 u32 speed_mask = 0;
1292
1293
1294
1295 if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB)
1296 speed_mask |= ADVERTISED_100baseT_Full;
1297 if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB)
1298 speed_mask |= ADVERTISED_1000baseT_Full;
1299 if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB)
1300 speed_mask |= ADVERTISED_2500baseX_Full;
1301 if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB)
1302 speed_mask |= ADVERTISED_10000baseT_Full;
1303 if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB)
1304 speed_mask |= ADVERTISED_40000baseCR4_Full;
1305
1306 if ((fw_pause & BNXT_LINK_PAUSE_BOTH) == BNXT_LINK_PAUSE_BOTH)
1307 speed_mask |= ADVERTISED_Pause;
1308 else if (fw_pause & BNXT_LINK_PAUSE_TX)
1309 speed_mask |= ADVERTISED_Asym_Pause;
1310 else if (fw_pause & BNXT_LINK_PAUSE_RX)
1311 speed_mask |= ADVERTISED_Pause | ADVERTISED_Asym_Pause;
1312
1313 return speed_mask;
1314 }
1315
1316 #define BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, name)\
1317 { \
1318 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100MB) \
1319 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1320 100baseT_Full); \
1321 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_1GB) \
1322 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1323 1000baseT_Full); \
1324 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_10GB) \
1325 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1326 10000baseT_Full); \
1327 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_25GB) \
1328 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1329 25000baseCR_Full); \
1330 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_40GB) \
1331 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1332 40000baseCR4_Full);\
1333 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_50GB) \
1334 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1335 50000baseCR2_Full);\
1336 if ((fw_speeds) & BNXT_LINK_SPEED_MSK_100GB) \
1337 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1338 100000baseCR4_Full);\
1339 if ((fw_pause) & BNXT_LINK_PAUSE_RX) { \
1340 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1341 Pause); \
1342 if (!((fw_pause) & BNXT_LINK_PAUSE_TX)) \
1343 ethtool_link_ksettings_add_link_mode( \
1344 lk_ksettings, name, Asym_Pause);\
1345 } else if ((fw_pause) & BNXT_LINK_PAUSE_TX) { \
1346 ethtool_link_ksettings_add_link_mode(lk_ksettings, name,\
1347 Asym_Pause); \
1348 } \
1349 }
1350
1351 #define BNXT_ETHTOOL_TO_FW_SPDS(fw_speeds, lk_ksettings, name) \
1352 { \
1353 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1354 100baseT_Full) || \
1355 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1356 100baseT_Half)) \
1357 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100MB; \
1358 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1359 1000baseT_Full) || \
1360 ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1361 1000baseT_Half)) \
1362 (fw_speeds) |= BNXT_LINK_SPEED_MSK_1GB; \
1363 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1364 10000baseT_Full)) \
1365 (fw_speeds) |= BNXT_LINK_SPEED_MSK_10GB; \
1366 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1367 25000baseCR_Full)) \
1368 (fw_speeds) |= BNXT_LINK_SPEED_MSK_25GB; \
1369 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1370 40000baseCR4_Full)) \
1371 (fw_speeds) |= BNXT_LINK_SPEED_MSK_40GB; \
1372 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1373 50000baseCR2_Full)) \
1374 (fw_speeds) |= BNXT_LINK_SPEED_MSK_50GB; \
1375 if (ethtool_link_ksettings_test_link_mode(lk_ksettings, name, \
1376 100000baseCR4_Full)) \
1377 (fw_speeds) |= BNXT_LINK_SPEED_MSK_100GB; \
1378 }
1379
1380 static void bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info,
1381 struct ethtool_link_ksettings *lk_ksettings)
1382 {
1383 u16 fw_speeds = link_info->advertising;
1384 u8 fw_pause = 0;
1385
1386 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1387 fw_pause = link_info->auto_pause_setting;
1388
1389 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings, advertising);
1390 }
1391
1392 static void bnxt_fw_to_ethtool_lp_adv(struct bnxt_link_info *link_info,
1393 struct ethtool_link_ksettings *lk_ksettings)
1394 {
1395 u16 fw_speeds = link_info->lp_auto_link_speeds;
1396 u8 fw_pause = 0;
1397
1398 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1399 fw_pause = link_info->lp_pause;
1400
1401 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, fw_pause, lk_ksettings,
1402 lp_advertising);
1403 }
1404
1405 static void bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info,
1406 struct ethtool_link_ksettings *lk_ksettings)
1407 {
1408 u16 fw_speeds = link_info->support_speeds;
1409
1410 BNXT_FW_TO_ETHTOOL_SPDS(fw_speeds, 0, lk_ksettings, supported);
1411
1412 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported, Pause);
1413 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1414 Asym_Pause);
1415
1416 if (link_info->support_auto_speeds)
1417 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1418 Autoneg);
1419 }
1420
1421 u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed)
1422 {
1423 switch (fw_link_speed) {
1424 case BNXT_LINK_SPEED_100MB:
1425 return SPEED_100;
1426 case BNXT_LINK_SPEED_1GB:
1427 return SPEED_1000;
1428 case BNXT_LINK_SPEED_2_5GB:
1429 return SPEED_2500;
1430 case BNXT_LINK_SPEED_10GB:
1431 return SPEED_10000;
1432 case BNXT_LINK_SPEED_20GB:
1433 return SPEED_20000;
1434 case BNXT_LINK_SPEED_25GB:
1435 return SPEED_25000;
1436 case BNXT_LINK_SPEED_40GB:
1437 return SPEED_40000;
1438 case BNXT_LINK_SPEED_50GB:
1439 return SPEED_50000;
1440 case BNXT_LINK_SPEED_100GB:
1441 return SPEED_100000;
1442 default:
1443 return SPEED_UNKNOWN;
1444 }
1445 }
1446
1447 static int bnxt_get_link_ksettings(struct net_device *dev,
1448 struct ethtool_link_ksettings *lk_ksettings)
1449 {
1450 struct bnxt *bp = netdev_priv(dev);
1451 struct bnxt_link_info *link_info = &bp->link_info;
1452 struct ethtool_link_settings *base = &lk_ksettings->base;
1453 u32 ethtool_speed;
1454
1455 ethtool_link_ksettings_zero_link_mode(lk_ksettings, supported);
1456 mutex_lock(&bp->link_lock);
1457 bnxt_fw_to_ethtool_support_spds(link_info, lk_ksettings);
1458
1459 ethtool_link_ksettings_zero_link_mode(lk_ksettings, advertising);
1460 if (link_info->autoneg) {
1461 bnxt_fw_to_ethtool_advertised_spds(link_info, lk_ksettings);
1462 ethtool_link_ksettings_add_link_mode(lk_ksettings,
1463 advertising, Autoneg);
1464 base->autoneg = AUTONEG_ENABLE;
1465 if (link_info->phy_link_status == BNXT_LINK_LINK)
1466 bnxt_fw_to_ethtool_lp_adv(link_info, lk_ksettings);
1467 ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed);
1468 if (!netif_carrier_ok(dev))
1469 base->duplex = DUPLEX_UNKNOWN;
1470 else if (link_info->duplex & BNXT_LINK_DUPLEX_FULL)
1471 base->duplex = DUPLEX_FULL;
1472 else
1473 base->duplex = DUPLEX_HALF;
1474 } else {
1475 base->autoneg = AUTONEG_DISABLE;
1476 ethtool_speed =
1477 bnxt_fw_to_ethtool_speed(link_info->req_link_speed);
1478 base->duplex = DUPLEX_HALF;
1479 if (link_info->req_duplex == BNXT_LINK_DUPLEX_FULL)
1480 base->duplex = DUPLEX_FULL;
1481 }
1482 base->speed = ethtool_speed;
1483
1484 base->port = PORT_NONE;
1485 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1486 base->port = PORT_TP;
1487 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1488 TP);
1489 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1490 TP);
1491 } else {
1492 ethtool_link_ksettings_add_link_mode(lk_ksettings, supported,
1493 FIBRE);
1494 ethtool_link_ksettings_add_link_mode(lk_ksettings, advertising,
1495 FIBRE);
1496
1497 if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC)
1498 base->port = PORT_DA;
1499 else if (link_info->media_type ==
1500 PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE)
1501 base->port = PORT_FIBRE;
1502 }
1503 base->phy_address = link_info->phy_addr;
1504 mutex_unlock(&bp->link_lock);
1505
1506 return 0;
1507 }
1508
1509 static u32 bnxt_get_fw_speed(struct net_device *dev, u32 ethtool_speed)
1510 {
1511 struct bnxt *bp = netdev_priv(dev);
1512 struct bnxt_link_info *link_info = &bp->link_info;
1513 u16 support_spds = link_info->support_speeds;
1514 u32 fw_speed = 0;
1515
1516 switch (ethtool_speed) {
1517 case SPEED_100:
1518 if (support_spds & BNXT_LINK_SPEED_MSK_100MB)
1519 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB;
1520 break;
1521 case SPEED_1000:
1522 if (support_spds & BNXT_LINK_SPEED_MSK_1GB)
1523 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB;
1524 break;
1525 case SPEED_2500:
1526 if (support_spds & BNXT_LINK_SPEED_MSK_2_5GB)
1527 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB;
1528 break;
1529 case SPEED_10000:
1530 if (support_spds & BNXT_LINK_SPEED_MSK_10GB)
1531 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB;
1532 break;
1533 case SPEED_20000:
1534 if (support_spds & BNXT_LINK_SPEED_MSK_20GB)
1535 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB;
1536 break;
1537 case SPEED_25000:
1538 if (support_spds & BNXT_LINK_SPEED_MSK_25GB)
1539 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB;
1540 break;
1541 case SPEED_40000:
1542 if (support_spds & BNXT_LINK_SPEED_MSK_40GB)
1543 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB;
1544 break;
1545 case SPEED_50000:
1546 if (support_spds & BNXT_LINK_SPEED_MSK_50GB)
1547 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB;
1548 break;
1549 case SPEED_100000:
1550 if (support_spds & BNXT_LINK_SPEED_MSK_100GB)
1551 fw_speed = PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100GB;
1552 break;
1553 default:
1554 netdev_err(dev, "unsupported speed!\n");
1555 break;
1556 }
1557 return fw_speed;
1558 }
1559
1560 u16 bnxt_get_fw_auto_link_speeds(u32 advertising)
1561 {
1562 u16 fw_speed_mask = 0;
1563
1564
1565 if (advertising & (ADVERTISED_100baseT_Full |
1566 ADVERTISED_100baseT_Half)) {
1567 fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB;
1568 }
1569 if (advertising & (ADVERTISED_1000baseT_Full |
1570 ADVERTISED_1000baseT_Half)) {
1571 fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB;
1572 }
1573 if (advertising & ADVERTISED_10000baseT_Full)
1574 fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB;
1575
1576 if (advertising & ADVERTISED_40000baseCR4_Full)
1577 fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB;
1578
1579 return fw_speed_mask;
1580 }
1581
1582 static int bnxt_set_link_ksettings(struct net_device *dev,
1583 const struct ethtool_link_ksettings *lk_ksettings)
1584 {
1585 struct bnxt *bp = netdev_priv(dev);
1586 struct bnxt_link_info *link_info = &bp->link_info;
1587 const struct ethtool_link_settings *base = &lk_ksettings->base;
1588 bool set_pause = false;
1589 u16 fw_advertising = 0;
1590 u32 speed;
1591 int rc = 0;
1592
1593 if (!BNXT_SINGLE_PF(bp))
1594 return -EOPNOTSUPP;
1595
1596 mutex_lock(&bp->link_lock);
1597 if (base->autoneg == AUTONEG_ENABLE) {
1598 BNXT_ETHTOOL_TO_FW_SPDS(fw_advertising, lk_ksettings,
1599 advertising);
1600 link_info->autoneg |= BNXT_AUTONEG_SPEED;
1601 if (!fw_advertising)
1602 link_info->advertising = link_info->support_auto_speeds;
1603 else
1604 link_info->advertising = fw_advertising;
1605
1606
1607
1608 set_pause = true;
1609 } else {
1610 u16 fw_speed;
1611 u8 phy_type = link_info->phy_type;
1612
1613 if (phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASET ||
1614 phy_type == PORT_PHY_QCFG_RESP_PHY_TYPE_BASETE ||
1615 link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) {
1616 netdev_err(dev, "10GBase-T devices must autoneg\n");
1617 rc = -EINVAL;
1618 goto set_setting_exit;
1619 }
1620 if (base->duplex == DUPLEX_HALF) {
1621 netdev_err(dev, "HALF DUPLEX is not supported!\n");
1622 rc = -EINVAL;
1623 goto set_setting_exit;
1624 }
1625 speed = base->speed;
1626 fw_speed = bnxt_get_fw_speed(dev, speed);
1627 if (!fw_speed) {
1628 rc = -EINVAL;
1629 goto set_setting_exit;
1630 }
1631 link_info->req_link_speed = fw_speed;
1632 link_info->req_duplex = BNXT_LINK_DUPLEX_FULL;
1633 link_info->autoneg = 0;
1634 link_info->advertising = 0;
1635 }
1636
1637 if (netif_running(dev))
1638 rc = bnxt_hwrm_set_link_setting(bp, set_pause, false);
1639
1640 set_setting_exit:
1641 mutex_unlock(&bp->link_lock);
1642 return rc;
1643 }
1644
1645 static void bnxt_get_pauseparam(struct net_device *dev,
1646 struct ethtool_pauseparam *epause)
1647 {
1648 struct bnxt *bp = netdev_priv(dev);
1649 struct bnxt_link_info *link_info = &bp->link_info;
1650
1651 if (BNXT_VF(bp))
1652 return;
1653 epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL);
1654 epause->rx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_RX);
1655 epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX);
1656 }
1657
1658 static int bnxt_set_pauseparam(struct net_device *dev,
1659 struct ethtool_pauseparam *epause)
1660 {
1661 int rc = 0;
1662 struct bnxt *bp = netdev_priv(dev);
1663 struct bnxt_link_info *link_info = &bp->link_info;
1664
1665 if (!BNXT_SINGLE_PF(bp))
1666 return -EOPNOTSUPP;
1667
1668 if (epause->autoneg) {
1669 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
1670 return -EINVAL;
1671
1672 link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL;
1673 if (bp->hwrm_spec_code >= 0x10201)
1674 link_info->req_flow_ctrl =
1675 PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE;
1676 } else {
1677
1678
1679
1680 if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL)
1681 link_info->force_link_chng = true;
1682 link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL;
1683 link_info->req_flow_ctrl = 0;
1684 }
1685 if (epause->rx_pause)
1686 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX;
1687
1688 if (epause->tx_pause)
1689 link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX;
1690
1691 if (netif_running(dev))
1692 rc = bnxt_hwrm_set_pause(bp);
1693 return rc;
1694 }
1695
1696 static u32 bnxt_get_link(struct net_device *dev)
1697 {
1698 struct bnxt *bp = netdev_priv(dev);
1699
1700
1701 return bp->link_info.link_up;
1702 }
1703
1704 static void bnxt_print_admin_err(struct bnxt *bp)
1705 {
1706 netdev_info(bp->dev, "PF does not have admin privileges to flash or reset the device\n");
1707 }
1708
1709 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
1710 u16 ext, u16 *index, u32 *item_length,
1711 u32 *data_length);
1712
1713 static int bnxt_flash_nvram(struct net_device *dev,
1714 u16 dir_type,
1715 u16 dir_ordinal,
1716 u16 dir_ext,
1717 u16 dir_attr,
1718 const u8 *data,
1719 size_t data_len)
1720 {
1721 struct bnxt *bp = netdev_priv(dev);
1722 int rc;
1723 struct hwrm_nvm_write_input req = {0};
1724 dma_addr_t dma_handle;
1725 u8 *kmem;
1726
1727 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1);
1728
1729 req.dir_type = cpu_to_le16(dir_type);
1730 req.dir_ordinal = cpu_to_le16(dir_ordinal);
1731 req.dir_ext = cpu_to_le16(dir_ext);
1732 req.dir_attr = cpu_to_le16(dir_attr);
1733 req.dir_data_length = cpu_to_le32(data_len);
1734
1735 kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle,
1736 GFP_KERNEL);
1737 if (!kmem) {
1738 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
1739 (unsigned)data_len);
1740 return -ENOMEM;
1741 }
1742 memcpy(kmem, data, data_len);
1743 req.host_src_addr = cpu_to_le64(dma_handle);
1744
1745 rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT);
1746 dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle);
1747
1748 if (rc == -EACCES)
1749 bnxt_print_admin_err(bp);
1750 return rc;
1751 }
1752
1753 static int bnxt_firmware_reset(struct net_device *dev,
1754 u16 dir_type)
1755 {
1756 struct hwrm_fw_reset_input req = {0};
1757 struct bnxt *bp = netdev_priv(dev);
1758 int rc;
1759
1760 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1);
1761
1762
1763
1764 switch (dir_type) {
1765 case BNX_DIR_TYPE_CHIMP_PATCH:
1766 case BNX_DIR_TYPE_BOOTCODE:
1767 case BNX_DIR_TYPE_BOOTCODE_2:
1768 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT;
1769
1770 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1771 break;
1772 case BNX_DIR_TYPE_APE_FW:
1773 case BNX_DIR_TYPE_APE_PATCH:
1774 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT;
1775
1776 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST;
1777 break;
1778 case BNX_DIR_TYPE_KONG_FW:
1779 case BNX_DIR_TYPE_KONG_PATCH:
1780 req.embedded_proc_type =
1781 FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL;
1782 break;
1783 case BNX_DIR_TYPE_BONO_FW:
1784 case BNX_DIR_TYPE_BONO_PATCH:
1785 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE;
1786 break;
1787 case BNXT_FW_RESET_CHIP:
1788 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_CHIP;
1789 req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTASAP;
1790 break;
1791 case BNXT_FW_RESET_AP:
1792 req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_AP;
1793 break;
1794 default:
1795 return -EINVAL;
1796 }
1797
1798 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
1799 if (rc == -EACCES)
1800 bnxt_print_admin_err(bp);
1801 return rc;
1802 }
1803
1804 static int bnxt_flash_firmware(struct net_device *dev,
1805 u16 dir_type,
1806 const u8 *fw_data,
1807 size_t fw_size)
1808 {
1809 int rc = 0;
1810 u16 code_type;
1811 u32 stored_crc;
1812 u32 calculated_crc;
1813 struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data;
1814
1815 switch (dir_type) {
1816 case BNX_DIR_TYPE_BOOTCODE:
1817 case BNX_DIR_TYPE_BOOTCODE_2:
1818 code_type = CODE_BOOT;
1819 break;
1820 case BNX_DIR_TYPE_CHIMP_PATCH:
1821 code_type = CODE_CHIMP_PATCH;
1822 break;
1823 case BNX_DIR_TYPE_APE_FW:
1824 code_type = CODE_MCTP_PASSTHRU;
1825 break;
1826 case BNX_DIR_TYPE_APE_PATCH:
1827 code_type = CODE_APE_PATCH;
1828 break;
1829 case BNX_DIR_TYPE_KONG_FW:
1830 code_type = CODE_KONG_FW;
1831 break;
1832 case BNX_DIR_TYPE_KONG_PATCH:
1833 code_type = CODE_KONG_PATCH;
1834 break;
1835 case BNX_DIR_TYPE_BONO_FW:
1836 code_type = CODE_BONO_FW;
1837 break;
1838 case BNX_DIR_TYPE_BONO_PATCH:
1839 code_type = CODE_BONO_PATCH;
1840 break;
1841 default:
1842 netdev_err(dev, "Unsupported directory entry type: %u\n",
1843 dir_type);
1844 return -EINVAL;
1845 }
1846 if (fw_size < sizeof(struct bnxt_fw_header)) {
1847 netdev_err(dev, "Invalid firmware file size: %u\n",
1848 (unsigned int)fw_size);
1849 return -EINVAL;
1850 }
1851 if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) {
1852 netdev_err(dev, "Invalid firmware signature: %08X\n",
1853 le32_to_cpu(header->signature));
1854 return -EINVAL;
1855 }
1856 if (header->code_type != code_type) {
1857 netdev_err(dev, "Expected firmware type: %d, read: %d\n",
1858 code_type, header->code_type);
1859 return -EINVAL;
1860 }
1861 if (header->device != DEVICE_CUMULUS_FAMILY) {
1862 netdev_err(dev, "Expected firmware device family %d, read: %d\n",
1863 DEVICE_CUMULUS_FAMILY, header->device);
1864 return -EINVAL;
1865 }
1866
1867 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1868 sizeof(stored_crc)));
1869 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1870 if (calculated_crc != stored_crc) {
1871 netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n",
1872 (unsigned long)stored_crc,
1873 (unsigned long)calculated_crc);
1874 return -EINVAL;
1875 }
1876 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1877 0, 0, fw_data, fw_size);
1878 if (rc == 0)
1879 rc = bnxt_firmware_reset(dev, dir_type);
1880
1881 return rc;
1882 }
1883
1884 static int bnxt_flash_microcode(struct net_device *dev,
1885 u16 dir_type,
1886 const u8 *fw_data,
1887 size_t fw_size)
1888 {
1889 struct bnxt_ucode_trailer *trailer;
1890 u32 calculated_crc;
1891 u32 stored_crc;
1892 int rc = 0;
1893
1894 if (fw_size < sizeof(struct bnxt_ucode_trailer)) {
1895 netdev_err(dev, "Invalid microcode file size: %u\n",
1896 (unsigned int)fw_size);
1897 return -EINVAL;
1898 }
1899 trailer = (struct bnxt_ucode_trailer *)(fw_data + (fw_size -
1900 sizeof(*trailer)));
1901 if (trailer->sig != cpu_to_le32(BNXT_UCODE_TRAILER_SIGNATURE)) {
1902 netdev_err(dev, "Invalid microcode trailer signature: %08X\n",
1903 le32_to_cpu(trailer->sig));
1904 return -EINVAL;
1905 }
1906 if (le16_to_cpu(trailer->dir_type) != dir_type) {
1907 netdev_err(dev, "Expected microcode type: %d, read: %d\n",
1908 dir_type, le16_to_cpu(trailer->dir_type));
1909 return -EINVAL;
1910 }
1911 if (le16_to_cpu(trailer->trailer_length) <
1912 sizeof(struct bnxt_ucode_trailer)) {
1913 netdev_err(dev, "Invalid microcode trailer length: %d\n",
1914 le16_to_cpu(trailer->trailer_length));
1915 return -EINVAL;
1916 }
1917
1918
1919 stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size -
1920 sizeof(stored_crc)));
1921 calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc));
1922 if (calculated_crc != stored_crc) {
1923 netdev_err(dev,
1924 "CRC32 (%08lX) does not match calculated: %08lX\n",
1925 (unsigned long)stored_crc,
1926 (unsigned long)calculated_crc);
1927 return -EINVAL;
1928 }
1929 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1930 0, 0, fw_data, fw_size);
1931
1932 return rc;
1933 }
1934
1935 static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type)
1936 {
1937 switch (dir_type) {
1938 case BNX_DIR_TYPE_CHIMP_PATCH:
1939 case BNX_DIR_TYPE_BOOTCODE:
1940 case BNX_DIR_TYPE_BOOTCODE_2:
1941 case BNX_DIR_TYPE_APE_FW:
1942 case BNX_DIR_TYPE_APE_PATCH:
1943 case BNX_DIR_TYPE_KONG_FW:
1944 case BNX_DIR_TYPE_KONG_PATCH:
1945 case BNX_DIR_TYPE_BONO_FW:
1946 case BNX_DIR_TYPE_BONO_PATCH:
1947 return true;
1948 }
1949
1950 return false;
1951 }
1952
1953 static bool bnxt_dir_type_is_other_exec_format(u16 dir_type)
1954 {
1955 switch (dir_type) {
1956 case BNX_DIR_TYPE_AVS:
1957 case BNX_DIR_TYPE_EXP_ROM_MBA:
1958 case BNX_DIR_TYPE_PCIE:
1959 case BNX_DIR_TYPE_TSCF_UCODE:
1960 case BNX_DIR_TYPE_EXT_PHY:
1961 case BNX_DIR_TYPE_CCM:
1962 case BNX_DIR_TYPE_ISCSI_BOOT:
1963 case BNX_DIR_TYPE_ISCSI_BOOT_IPV6:
1964 case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6:
1965 return true;
1966 }
1967
1968 return false;
1969 }
1970
1971 static bool bnxt_dir_type_is_executable(u16 dir_type)
1972 {
1973 return bnxt_dir_type_is_ape_bin_format(dir_type) ||
1974 bnxt_dir_type_is_other_exec_format(dir_type);
1975 }
1976
1977 static int bnxt_flash_firmware_from_file(struct net_device *dev,
1978 u16 dir_type,
1979 const char *filename)
1980 {
1981 const struct firmware *fw;
1982 int rc;
1983
1984 rc = request_firmware(&fw, filename, &dev->dev);
1985 if (rc != 0) {
1986 netdev_err(dev, "Error %d requesting firmware file: %s\n",
1987 rc, filename);
1988 return rc;
1989 }
1990 if (bnxt_dir_type_is_ape_bin_format(dir_type) == true)
1991 rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size);
1992 else if (bnxt_dir_type_is_other_exec_format(dir_type) == true)
1993 rc = bnxt_flash_microcode(dev, dir_type, fw->data, fw->size);
1994 else
1995 rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST,
1996 0, 0, fw->data, fw->size);
1997 release_firmware(fw);
1998 return rc;
1999 }
2000
2001 static int bnxt_flash_package_from_file(struct net_device *dev,
2002 char *filename, u32 install_type)
2003 {
2004 struct bnxt *bp = netdev_priv(dev);
2005 struct hwrm_nvm_install_update_output *resp = bp->hwrm_cmd_resp_addr;
2006 struct hwrm_nvm_install_update_input install = {0};
2007 const struct firmware *fw;
2008 u32 item_len;
2009 int rc = 0;
2010 u16 index;
2011
2012 bnxt_hwrm_fw_set_time(bp);
2013
2014 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_UPDATE,
2015 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
2016 &index, &item_len, NULL) != 0) {
2017 netdev_err(dev, "PKG update area not created in nvram\n");
2018 return -ENOBUFS;
2019 }
2020
2021 rc = request_firmware(&fw, filename, &dev->dev);
2022 if (rc != 0) {
2023 netdev_err(dev, "PKG error %d requesting file: %s\n",
2024 rc, filename);
2025 return rc;
2026 }
2027
2028 if (fw->size > item_len) {
2029 netdev_err(dev, "PKG insufficient update area in nvram: %lu",
2030 (unsigned long)fw->size);
2031 rc = -EFBIG;
2032 } else {
2033 dma_addr_t dma_handle;
2034 u8 *kmem;
2035 struct hwrm_nvm_modify_input modify = {0};
2036
2037 bnxt_hwrm_cmd_hdr_init(bp, &modify, HWRM_NVM_MODIFY, -1, -1);
2038
2039 modify.dir_idx = cpu_to_le16(index);
2040 modify.len = cpu_to_le32(fw->size);
2041
2042 kmem = dma_alloc_coherent(&bp->pdev->dev, fw->size,
2043 &dma_handle, GFP_KERNEL);
2044 if (!kmem) {
2045 netdev_err(dev,
2046 "dma_alloc_coherent failure, length = %u\n",
2047 (unsigned int)fw->size);
2048 rc = -ENOMEM;
2049 } else {
2050 memcpy(kmem, fw->data, fw->size);
2051 modify.host_src_addr = cpu_to_le64(dma_handle);
2052
2053 rc = hwrm_send_message(bp, &modify, sizeof(modify),
2054 FLASH_PACKAGE_TIMEOUT);
2055 dma_free_coherent(&bp->pdev->dev, fw->size, kmem,
2056 dma_handle);
2057 }
2058 }
2059 release_firmware(fw);
2060 if (rc)
2061 goto err_exit;
2062
2063 if ((install_type & 0xffff) == 0)
2064 install_type >>= 16;
2065 bnxt_hwrm_cmd_hdr_init(bp, &install, HWRM_NVM_INSTALL_UPDATE, -1, -1);
2066 install.install_type = cpu_to_le32(install_type);
2067
2068 mutex_lock(&bp->hwrm_cmd_lock);
2069 rc = _hwrm_send_message(bp, &install, sizeof(install),
2070 INSTALL_PACKAGE_TIMEOUT);
2071 if (rc) {
2072 u8 error_code = ((struct hwrm_err_output *)resp)->cmd_err;
2073
2074 if (resp->error_code && error_code ==
2075 NVM_INSTALL_UPDATE_CMD_ERR_CODE_FRAG_ERR) {
2076 install.flags |= cpu_to_le16(
2077 NVM_INSTALL_UPDATE_REQ_FLAGS_ALLOWED_TO_DEFRAG);
2078 rc = _hwrm_send_message(bp, &install, sizeof(install),
2079 INSTALL_PACKAGE_TIMEOUT);
2080 }
2081 if (rc)
2082 goto flash_pkg_exit;
2083 }
2084
2085 if (resp->result) {
2086 netdev_err(dev, "PKG install error = %d, problem_item = %d\n",
2087 (s8)resp->result, (int)resp->problem_item);
2088 rc = -ENOPKG;
2089 }
2090 flash_pkg_exit:
2091 mutex_unlock(&bp->hwrm_cmd_lock);
2092 err_exit:
2093 if (rc == -EACCES)
2094 bnxt_print_admin_err(bp);
2095 return rc;
2096 }
2097
2098 static int bnxt_flash_device(struct net_device *dev,
2099 struct ethtool_flash *flash)
2100 {
2101 if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) {
2102 netdev_err(dev, "flashdev not supported from a virtual function\n");
2103 return -EINVAL;
2104 }
2105
2106 if (flash->region == ETHTOOL_FLASH_ALL_REGIONS ||
2107 flash->region > 0xffff)
2108 return bnxt_flash_package_from_file(dev, flash->data,
2109 flash->region);
2110
2111 return bnxt_flash_firmware_from_file(dev, flash->region, flash->data);
2112 }
2113
2114 static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length)
2115 {
2116 struct bnxt *bp = netdev_priv(dev);
2117 int rc;
2118 struct hwrm_nvm_get_dir_info_input req = {0};
2119 struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr;
2120
2121 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1);
2122
2123 mutex_lock(&bp->hwrm_cmd_lock);
2124 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2125 if (!rc) {
2126 *entries = le32_to_cpu(output->entries);
2127 *length = le32_to_cpu(output->entry_length);
2128 }
2129 mutex_unlock(&bp->hwrm_cmd_lock);
2130 return rc;
2131 }
2132
2133 static int bnxt_get_eeprom_len(struct net_device *dev)
2134 {
2135 struct bnxt *bp = netdev_priv(dev);
2136
2137 if (BNXT_VF(bp))
2138 return 0;
2139
2140
2141
2142
2143 return -1;
2144 }
2145
2146 static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
2147 {
2148 struct bnxt *bp = netdev_priv(dev);
2149 int rc;
2150 u32 dir_entries;
2151 u32 entry_length;
2152 u8 *buf;
2153 size_t buflen;
2154 dma_addr_t dma_handle;
2155 struct hwrm_nvm_get_dir_entries_input req = {0};
2156
2157 rc = nvm_get_dir_info(dev, &dir_entries, &entry_length);
2158 if (rc != 0)
2159 return rc;
2160
2161
2162 if (len < 2)
2163 return -EINVAL;
2164
2165 *data++ = dir_entries;
2166 *data++ = entry_length;
2167 len -= 2;
2168 memset(data, 0xff, len);
2169
2170 buflen = dir_entries * entry_length;
2171 buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle,
2172 GFP_KERNEL);
2173 if (!buf) {
2174 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
2175 (unsigned)buflen);
2176 return -ENOMEM;
2177 }
2178 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1);
2179 req.host_dest_addr = cpu_to_le64(dma_handle);
2180 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2181 if (rc == 0)
2182 memcpy(data, buf, len > buflen ? buflen : len);
2183 dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle);
2184 return rc;
2185 }
2186
2187 static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset,
2188 u32 length, u8 *data)
2189 {
2190 struct bnxt *bp = netdev_priv(dev);
2191 int rc;
2192 u8 *buf;
2193 dma_addr_t dma_handle;
2194 struct hwrm_nvm_read_input req = {0};
2195
2196 if (!length)
2197 return -EINVAL;
2198
2199 buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle,
2200 GFP_KERNEL);
2201 if (!buf) {
2202 netdev_err(dev, "dma_alloc_coherent failure, length = %u\n",
2203 (unsigned)length);
2204 return -ENOMEM;
2205 }
2206 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1);
2207 req.host_dest_addr = cpu_to_le64(dma_handle);
2208 req.dir_idx = cpu_to_le16(index);
2209 req.offset = cpu_to_le32(offset);
2210 req.len = cpu_to_le32(length);
2211
2212 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2213 if (rc == 0)
2214 memcpy(data, buf, length);
2215 dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle);
2216 return rc;
2217 }
2218
2219 static int bnxt_find_nvram_item(struct net_device *dev, u16 type, u16 ordinal,
2220 u16 ext, u16 *index, u32 *item_length,
2221 u32 *data_length)
2222 {
2223 struct bnxt *bp = netdev_priv(dev);
2224 int rc;
2225 struct hwrm_nvm_find_dir_entry_input req = {0};
2226 struct hwrm_nvm_find_dir_entry_output *output = bp->hwrm_cmd_resp_addr;
2227
2228 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_FIND_DIR_ENTRY, -1, -1);
2229 req.enables = 0;
2230 req.dir_idx = 0;
2231 req.dir_type = cpu_to_le16(type);
2232 req.dir_ordinal = cpu_to_le16(ordinal);
2233 req.dir_ext = cpu_to_le16(ext);
2234 req.opt_ordinal = NVM_FIND_DIR_ENTRY_REQ_OPT_ORDINAL_EQ;
2235 mutex_lock(&bp->hwrm_cmd_lock);
2236 rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2237 if (rc == 0) {
2238 if (index)
2239 *index = le16_to_cpu(output->dir_idx);
2240 if (item_length)
2241 *item_length = le32_to_cpu(output->dir_item_length);
2242 if (data_length)
2243 *data_length = le32_to_cpu(output->dir_data_length);
2244 }
2245 mutex_unlock(&bp->hwrm_cmd_lock);
2246 return rc;
2247 }
2248
2249 static char *bnxt_parse_pkglog(int desired_field, u8 *data, size_t datalen)
2250 {
2251 char *retval = NULL;
2252 char *p;
2253 char *value;
2254 int field = 0;
2255
2256 if (datalen < 1)
2257 return NULL;
2258
2259 data[datalen - 1] = 0;
2260 for (p = data; *p != 0; p++) {
2261 field = 0;
2262 retval = NULL;
2263 while (*p != 0 && *p != '\n') {
2264 value = p;
2265 while (*p != 0 && *p != '\t' && *p != '\n')
2266 p++;
2267 if (field == desired_field)
2268 retval = value;
2269 if (*p != '\t')
2270 break;
2271 *p = 0;
2272 field++;
2273 p++;
2274 }
2275 if (*p == 0)
2276 break;
2277 *p = 0;
2278 }
2279 return retval;
2280 }
2281
2282 static void bnxt_get_pkgver(struct net_device *dev)
2283 {
2284 struct bnxt *bp = netdev_priv(dev);
2285 u16 index = 0;
2286 char *pkgver;
2287 u32 pkglen;
2288 u8 *pkgbuf;
2289 int len;
2290
2291 if (bnxt_find_nvram_item(dev, BNX_DIR_TYPE_PKG_LOG,
2292 BNX_DIR_ORDINAL_FIRST, BNX_DIR_EXT_NONE,
2293 &index, NULL, &pkglen) != 0)
2294 return;
2295
2296 pkgbuf = kzalloc(pkglen, GFP_KERNEL);
2297 if (!pkgbuf) {
2298 dev_err(&bp->pdev->dev, "Unable to allocate memory for pkg version, length = %u\n",
2299 pkglen);
2300 return;
2301 }
2302
2303 if (bnxt_get_nvram_item(dev, index, 0, pkglen, pkgbuf))
2304 goto err;
2305
2306 pkgver = bnxt_parse_pkglog(BNX_PKG_LOG_FIELD_IDX_PKG_VERSION, pkgbuf,
2307 pkglen);
2308 if (pkgver && *pkgver != 0 && isdigit(*pkgver)) {
2309 len = strlen(bp->fw_ver_str);
2310 snprintf(bp->fw_ver_str + len, FW_VER_STR_LEN - len - 1,
2311 "/pkg %s", pkgver);
2312 }
2313 err:
2314 kfree(pkgbuf);
2315 }
2316
2317 static int bnxt_get_eeprom(struct net_device *dev,
2318 struct ethtool_eeprom *eeprom,
2319 u8 *data)
2320 {
2321 u32 index;
2322 u32 offset;
2323
2324 if (eeprom->offset == 0)
2325 return bnxt_get_nvram_directory(dev, eeprom->len, data);
2326
2327 index = eeprom->offset >> 24;
2328 offset = eeprom->offset & 0xffffff;
2329
2330 if (index == 0) {
2331 netdev_err(dev, "unsupported index value: %d\n", index);
2332 return -EINVAL;
2333 }
2334
2335 return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data);
2336 }
2337
2338 static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index)
2339 {
2340 struct bnxt *bp = netdev_priv(dev);
2341 struct hwrm_nvm_erase_dir_entry_input req = {0};
2342
2343 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1);
2344 req.dir_idx = cpu_to_le16(index);
2345 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2346 }
2347
2348 static int bnxt_set_eeprom(struct net_device *dev,
2349 struct ethtool_eeprom *eeprom,
2350 u8 *data)
2351 {
2352 struct bnxt *bp = netdev_priv(dev);
2353 u8 index, dir_op;
2354 u16 type, ext, ordinal, attr;
2355
2356 if (!BNXT_PF(bp)) {
2357 netdev_err(dev, "NVM write not supported from a virtual function\n");
2358 return -EINVAL;
2359 }
2360
2361 type = eeprom->magic >> 16;
2362
2363 if (type == 0xffff) {
2364 index = eeprom->magic & 0xff;
2365 dir_op = eeprom->magic >> 8;
2366 if (index == 0)
2367 return -EINVAL;
2368 switch (dir_op) {
2369 case 0x0e:
2370 if (eeprom->offset != ~eeprom->magic)
2371 return -EINVAL;
2372 return bnxt_erase_nvram_directory(dev, index - 1);
2373 default:
2374 return -EINVAL;
2375 }
2376 }
2377
2378
2379 if (bnxt_dir_type_is_executable(type) == true)
2380 return -EOPNOTSUPP;
2381 ext = eeprom->magic & 0xffff;
2382 ordinal = eeprom->offset >> 16;
2383 attr = eeprom->offset & 0xffff;
2384
2385 return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data,
2386 eeprom->len);
2387 }
2388
2389 static int bnxt_set_eee(struct net_device *dev, struct ethtool_eee *edata)
2390 {
2391 struct bnxt *bp = netdev_priv(dev);
2392 struct ethtool_eee *eee = &bp->eee;
2393 struct bnxt_link_info *link_info = &bp->link_info;
2394 u32 advertising =
2395 _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0);
2396 int rc = 0;
2397
2398 if (!BNXT_SINGLE_PF(bp))
2399 return -EOPNOTSUPP;
2400
2401 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
2402 return -EOPNOTSUPP;
2403
2404 if (!edata->eee_enabled)
2405 goto eee_ok;
2406
2407 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) {
2408 netdev_warn(dev, "EEE requires autoneg\n");
2409 return -EINVAL;
2410 }
2411 if (edata->tx_lpi_enabled) {
2412 if (bp->lpi_tmr_hi && (edata->tx_lpi_timer > bp->lpi_tmr_hi ||
2413 edata->tx_lpi_timer < bp->lpi_tmr_lo)) {
2414 netdev_warn(dev, "Valid LPI timer range is %d and %d microsecs\n",
2415 bp->lpi_tmr_lo, bp->lpi_tmr_hi);
2416 return -EINVAL;
2417 } else if (!bp->lpi_tmr_hi) {
2418 edata->tx_lpi_timer = eee->tx_lpi_timer;
2419 }
2420 }
2421 if (!edata->advertised) {
2422 edata->advertised = advertising & eee->supported;
2423 } else if (edata->advertised & ~advertising) {
2424 netdev_warn(dev, "EEE advertised %x must be a subset of autoneg advertised speeds %x\n",
2425 edata->advertised, advertising);
2426 return -EINVAL;
2427 }
2428
2429 eee->advertised = edata->advertised;
2430 eee->tx_lpi_enabled = edata->tx_lpi_enabled;
2431 eee->tx_lpi_timer = edata->tx_lpi_timer;
2432 eee_ok:
2433 eee->eee_enabled = edata->eee_enabled;
2434
2435 if (netif_running(dev))
2436 rc = bnxt_hwrm_set_link_setting(bp, false, true);
2437
2438 return rc;
2439 }
2440
2441 static int bnxt_get_eee(struct net_device *dev, struct ethtool_eee *edata)
2442 {
2443 struct bnxt *bp = netdev_priv(dev);
2444
2445 if (!(bp->flags & BNXT_FLAG_EEE_CAP))
2446 return -EOPNOTSUPP;
2447
2448 *edata = bp->eee;
2449 if (!bp->eee.eee_enabled) {
2450
2451
2452
2453 edata->advertised = 0;
2454 edata->tx_lpi_enabled = 0;
2455 }
2456
2457 if (!bp->eee.eee_active)
2458 edata->lp_advertised = 0;
2459
2460 return 0;
2461 }
2462
2463 static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
2464 u16 page_number, u16 start_addr,
2465 u16 data_length, u8 *buf)
2466 {
2467 struct hwrm_port_phy_i2c_read_input req = {0};
2468 struct hwrm_port_phy_i2c_read_output *output = bp->hwrm_cmd_resp_addr;
2469 int rc, byte_offset = 0;
2470
2471 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_I2C_READ, -1, -1);
2472 req.i2c_slave_addr = i2c_addr;
2473 req.page_number = cpu_to_le16(page_number);
2474 req.port_id = cpu_to_le16(bp->pf.port_id);
2475 do {
2476 u16 xfer_size;
2477
2478 xfer_size = min_t(u16, data_length, BNXT_MAX_PHY_I2C_RESP_SIZE);
2479 data_length -= xfer_size;
2480 req.page_offset = cpu_to_le16(start_addr + byte_offset);
2481 req.data_length = xfer_size;
2482 req.enables = cpu_to_le32(start_addr + byte_offset ?
2483 PORT_PHY_I2C_READ_REQ_ENABLES_PAGE_OFFSET : 0);
2484 mutex_lock(&bp->hwrm_cmd_lock);
2485 rc = _hwrm_send_message(bp, &req, sizeof(req),
2486 HWRM_CMD_TIMEOUT);
2487 if (!rc)
2488 memcpy(buf + byte_offset, output->data, xfer_size);
2489 mutex_unlock(&bp->hwrm_cmd_lock);
2490 byte_offset += xfer_size;
2491 } while (!rc && data_length > 0);
2492
2493 return rc;
2494 }
2495
2496 static int bnxt_get_module_info(struct net_device *dev,
2497 struct ethtool_modinfo *modinfo)
2498 {
2499 u8 data[SFF_DIAG_SUPPORT_OFFSET + 1];
2500 struct bnxt *bp = netdev_priv(dev);
2501 int rc;
2502
2503
2504
2505
2506
2507 if (bp->link_info.module_status >
2508 PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG)
2509 return -EOPNOTSUPP;
2510
2511
2512 if (bp->hwrm_spec_code < 0x10202)
2513 return -EOPNOTSUPP;
2514
2515 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0, 0,
2516 SFF_DIAG_SUPPORT_OFFSET + 1,
2517 data);
2518 if (!rc) {
2519 u8 module_id = data[0];
2520 u8 diag_supported = data[SFF_DIAG_SUPPORT_OFFSET];
2521
2522 switch (module_id) {
2523 case SFF_MODULE_ID_SFP:
2524 modinfo->type = ETH_MODULE_SFF_8472;
2525 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
2526 if (!diag_supported)
2527 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
2528 break;
2529 case SFF_MODULE_ID_QSFP:
2530 case SFF_MODULE_ID_QSFP_PLUS:
2531 modinfo->type = ETH_MODULE_SFF_8436;
2532 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
2533 break;
2534 case SFF_MODULE_ID_QSFP28:
2535 modinfo->type = ETH_MODULE_SFF_8636;
2536 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
2537 break;
2538 default:
2539 rc = -EOPNOTSUPP;
2540 break;
2541 }
2542 }
2543 return rc;
2544 }
2545
2546 static int bnxt_get_module_eeprom(struct net_device *dev,
2547 struct ethtool_eeprom *eeprom,
2548 u8 *data)
2549 {
2550 struct bnxt *bp = netdev_priv(dev);
2551 u16 start = eeprom->offset, length = eeprom->len;
2552 int rc = 0;
2553
2554 memset(data, 0, eeprom->len);
2555
2556
2557 if (start < ETH_MODULE_SFF_8436_LEN) {
2558 if (start + eeprom->len > ETH_MODULE_SFF_8436_LEN)
2559 length = ETH_MODULE_SFF_8436_LEN - start;
2560 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A0, 0,
2561 start, length, data);
2562 if (rc)
2563 return rc;
2564 start += length;
2565 data += length;
2566 length = eeprom->len - length;
2567 }
2568
2569
2570 if (length) {
2571 start -= ETH_MODULE_SFF_8436_LEN;
2572 rc = bnxt_read_sfp_module_eeprom_info(bp, I2C_DEV_ADDR_A2, 1,
2573 start, length, data);
2574 }
2575 return rc;
2576 }
2577
2578 static int bnxt_nway_reset(struct net_device *dev)
2579 {
2580 int rc = 0;
2581
2582 struct bnxt *bp = netdev_priv(dev);
2583 struct bnxt_link_info *link_info = &bp->link_info;
2584
2585 if (!BNXT_SINGLE_PF(bp))
2586 return -EOPNOTSUPP;
2587
2588 if (!(link_info->autoneg & BNXT_AUTONEG_SPEED))
2589 return -EINVAL;
2590
2591 if (netif_running(dev))
2592 rc = bnxt_hwrm_set_link_setting(bp, true, false);
2593
2594 return rc;
2595 }
2596
2597 static int bnxt_set_phys_id(struct net_device *dev,
2598 enum ethtool_phys_id_state state)
2599 {
2600 struct hwrm_port_led_cfg_input req = {0};
2601 struct bnxt *bp = netdev_priv(dev);
2602 struct bnxt_pf_info *pf = &bp->pf;
2603 struct bnxt_led_cfg *led_cfg;
2604 u8 led_state;
2605 __le16 duration;
2606 int i, rc;
2607
2608 if (!bp->num_leds || BNXT_VF(bp))
2609 return -EOPNOTSUPP;
2610
2611 if (state == ETHTOOL_ID_ACTIVE) {
2612 led_state = PORT_LED_CFG_REQ_LED0_STATE_BLINKALT;
2613 duration = cpu_to_le16(500);
2614 } else if (state == ETHTOOL_ID_INACTIVE) {
2615 led_state = PORT_LED_CFG_REQ_LED1_STATE_DEFAULT;
2616 duration = cpu_to_le16(0);
2617 } else {
2618 return -EINVAL;
2619 }
2620 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_CFG, -1, -1);
2621 req.port_id = cpu_to_le16(pf->port_id);
2622 req.num_leds = bp->num_leds;
2623 led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
2624 for (i = 0; i < bp->num_leds; i++, led_cfg++) {
2625 req.enables |= BNXT_LED_DFLT_ENABLES(i);
2626 led_cfg->led_id = bp->leds[i].led_id;
2627 led_cfg->led_state = led_state;
2628 led_cfg->led_blink_on = duration;
2629 led_cfg->led_blink_off = duration;
2630 led_cfg->led_group_id = bp->leds[i].led_group_id;
2631 }
2632 rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2633 return rc;
2634 }
2635
2636 static int bnxt_hwrm_selftest_irq(struct bnxt *bp, u16 cmpl_ring)
2637 {
2638 struct hwrm_selftest_irq_input req = {0};
2639
2640 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_IRQ, cmpl_ring, -1);
2641 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2642 }
2643
2644 static int bnxt_test_irq(struct bnxt *bp)
2645 {
2646 int i;
2647
2648 for (i = 0; i < bp->cp_nr_rings; i++) {
2649 u16 cmpl_ring = bp->grp_info[i].cp_fw_ring_id;
2650 int rc;
2651
2652 rc = bnxt_hwrm_selftest_irq(bp, cmpl_ring);
2653 if (rc)
2654 return rc;
2655 }
2656 return 0;
2657 }
2658
2659 static int bnxt_hwrm_mac_loopback(struct bnxt *bp, bool enable)
2660 {
2661 struct hwrm_port_mac_cfg_input req = {0};
2662
2663 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_MAC_CFG, -1, -1);
2664
2665 req.enables = cpu_to_le32(PORT_MAC_CFG_REQ_ENABLES_LPBK);
2666 if (enable)
2667 req.lpbk = PORT_MAC_CFG_REQ_LPBK_LOCAL;
2668 else
2669 req.lpbk = PORT_MAC_CFG_REQ_LPBK_NONE;
2670 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2671 }
2672
2673 static int bnxt_query_force_speeds(struct bnxt *bp, u16 *force_speeds)
2674 {
2675 struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
2676 struct hwrm_port_phy_qcaps_input req = {0};
2677 int rc;
2678
2679 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1);
2680 mutex_lock(&bp->hwrm_cmd_lock);
2681 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2682 if (!rc)
2683 *force_speeds = le16_to_cpu(resp->supported_speeds_force_mode);
2684
2685 mutex_unlock(&bp->hwrm_cmd_lock);
2686 return rc;
2687 }
2688
2689 static int bnxt_disable_an_for_lpbk(struct bnxt *bp,
2690 struct hwrm_port_phy_cfg_input *req)
2691 {
2692 struct bnxt_link_info *link_info = &bp->link_info;
2693 u16 fw_advertising;
2694 u16 fw_speed;
2695 int rc;
2696
2697 if (!link_info->autoneg)
2698 return 0;
2699
2700 rc = bnxt_query_force_speeds(bp, &fw_advertising);
2701 if (rc)
2702 return rc;
2703
2704 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_1GB;
2705 if (netif_carrier_ok(bp->dev))
2706 fw_speed = bp->link_info.link_speed;
2707 else if (fw_advertising & BNXT_LINK_SPEED_MSK_10GB)
2708 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_10GB;
2709 else if (fw_advertising & BNXT_LINK_SPEED_MSK_25GB)
2710 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_25GB;
2711 else if (fw_advertising & BNXT_LINK_SPEED_MSK_40GB)
2712 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_40GB;
2713 else if (fw_advertising & BNXT_LINK_SPEED_MSK_50GB)
2714 fw_speed = PORT_PHY_CFG_REQ_FORCE_LINK_SPEED_50GB;
2715
2716 req->force_link_speed = cpu_to_le16(fw_speed);
2717 req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE |
2718 PORT_PHY_CFG_REQ_FLAGS_RESET_PHY);
2719 rc = hwrm_send_message(bp, req, sizeof(*req), HWRM_CMD_TIMEOUT);
2720 req->flags = 0;
2721 req->force_link_speed = cpu_to_le16(0);
2722 return rc;
2723 }
2724
2725 static int bnxt_hwrm_phy_loopback(struct bnxt *bp, bool enable, bool ext)
2726 {
2727 struct hwrm_port_phy_cfg_input req = {0};
2728
2729 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1);
2730
2731 if (enable) {
2732 bnxt_disable_an_for_lpbk(bp, &req);
2733 if (ext)
2734 req.lpbk = PORT_PHY_CFG_REQ_LPBK_EXTERNAL;
2735 else
2736 req.lpbk = PORT_PHY_CFG_REQ_LPBK_LOCAL;
2737 } else {
2738 req.lpbk = PORT_PHY_CFG_REQ_LPBK_NONE;
2739 }
2740 req.enables = cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_LPBK);
2741 return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
2742 }
2743
2744 static int bnxt_rx_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2745 u32 raw_cons, int pkt_size)
2746 {
2747 struct bnxt_napi *bnapi = cpr->bnapi;
2748 struct bnxt_rx_ring_info *rxr;
2749 struct bnxt_sw_rx_bd *rx_buf;
2750 struct rx_cmp *rxcmp;
2751 u16 cp_cons, cons;
2752 u8 *data;
2753 u32 len;
2754 int i;
2755
2756 rxr = bnapi->rx_ring;
2757 cp_cons = RING_CMP(raw_cons);
2758 rxcmp = (struct rx_cmp *)
2759 &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)];
2760 cons = rxcmp->rx_cmp_opaque;
2761 rx_buf = &rxr->rx_buf_ring[cons];
2762 data = rx_buf->data_ptr;
2763 len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT;
2764 if (len != pkt_size)
2765 return -EIO;
2766 i = ETH_ALEN;
2767 if (!ether_addr_equal(data + i, bnapi->bp->dev->dev_addr))
2768 return -EIO;
2769 i += ETH_ALEN;
2770 for ( ; i < pkt_size; i++) {
2771 if (data[i] != (u8)(i & 0xff))
2772 return -EIO;
2773 }
2774 return 0;
2775 }
2776
2777 static int bnxt_poll_loopback(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
2778 int pkt_size)
2779 {
2780 struct tx_cmp *txcmp;
2781 int rc = -EIO;
2782 u32 raw_cons;
2783 u32 cons;
2784 int i;
2785
2786 raw_cons = cpr->cp_raw_cons;
2787 for (i = 0; i < 200; i++) {
2788 cons = RING_CMP(raw_cons);
2789 txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)];
2790
2791 if (!TX_CMP_VALID(txcmp, raw_cons)) {
2792 udelay(5);
2793 continue;
2794 }
2795
2796
2797
2798
2799 dma_rmb();
2800 if (TX_CMP_TYPE(txcmp) == CMP_TYPE_RX_L2_CMP) {
2801 rc = bnxt_rx_loopback(bp, cpr, raw_cons, pkt_size);
2802 raw_cons = NEXT_RAW_CMP(raw_cons);
2803 raw_cons = NEXT_RAW_CMP(raw_cons);
2804 break;
2805 }
2806 raw_cons = NEXT_RAW_CMP(raw_cons);
2807 }
2808 cpr->cp_raw_cons = raw_cons;
2809 return rc;
2810 }
2811
2812 static int bnxt_run_loopback(struct bnxt *bp)
2813 {
2814 struct bnxt_tx_ring_info *txr = &bp->tx_ring[0];
2815 struct bnxt_rx_ring_info *rxr = &bp->rx_ring[0];
2816 struct bnxt_cp_ring_info *cpr;
2817 int pkt_size, i = 0;
2818 struct sk_buff *skb;
2819 dma_addr_t map;
2820 u8 *data;
2821 int rc;
2822
2823 cpr = &rxr->bnapi->cp_ring;
2824 if (bp->flags & BNXT_FLAG_CHIP_P5)
2825 cpr = cpr->cp_ring_arr[BNXT_RX_HDL];
2826 pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
2827 skb = netdev_alloc_skb(bp->dev, pkt_size);
2828 if (!skb)
2829 return -ENOMEM;
2830 data = skb_put(skb, pkt_size);
2831 eth_broadcast_addr(data);
2832 i += ETH_ALEN;
2833 ether_addr_copy(&data[i], bp->dev->dev_addr);
2834 i += ETH_ALEN;
2835 for ( ; i < pkt_size; i++)
2836 data[i] = (u8)(i & 0xff);
2837
2838 map = dma_map_single(&bp->pdev->dev, skb->data, pkt_size,
2839 PCI_DMA_TODEVICE);
2840 if (dma_mapping_error(&bp->pdev->dev, map)) {
2841 dev_kfree_skb(skb);
2842 return -EIO;
2843 }
2844 bnxt_xmit_bd(bp, txr, map, pkt_size);
2845
2846
2847 wmb();
2848
2849 bnxt_db_write(bp, &txr->tx_db, txr->tx_prod);
2850 rc = bnxt_poll_loopback(bp, cpr, pkt_size);
2851
2852 dma_unmap_single(&bp->pdev->dev, map, pkt_size, PCI_DMA_TODEVICE);
2853 dev_kfree_skb(skb);
2854 return rc;
2855 }
2856
2857 static int bnxt_run_fw_tests(struct bnxt *bp, u8 test_mask, u8 *test_results)
2858 {
2859 struct hwrm_selftest_exec_output *resp = bp->hwrm_cmd_resp_addr;
2860 struct hwrm_selftest_exec_input req = {0};
2861 int rc;
2862
2863 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_EXEC, -1, -1);
2864 mutex_lock(&bp->hwrm_cmd_lock);
2865 resp->test_success = 0;
2866 req.flags = test_mask;
2867 rc = _hwrm_send_message(bp, &req, sizeof(req), bp->test_info->timeout);
2868 *test_results = resp->test_success;
2869 mutex_unlock(&bp->hwrm_cmd_lock);
2870 return rc;
2871 }
2872
2873 #define BNXT_DRV_TESTS 4
2874 #define BNXT_MACLPBK_TEST_IDX (bp->num_tests - BNXT_DRV_TESTS)
2875 #define BNXT_PHYLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 1)
2876 #define BNXT_EXTLPBK_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 2)
2877 #define BNXT_IRQ_TEST_IDX (BNXT_MACLPBK_TEST_IDX + 3)
2878
2879 static void bnxt_self_test(struct net_device *dev, struct ethtool_test *etest,
2880 u64 *buf)
2881 {
2882 struct bnxt *bp = netdev_priv(dev);
2883 bool do_ext_lpbk = false;
2884 bool offline = false;
2885 u8 test_results = 0;
2886 u8 test_mask = 0;
2887 int rc = 0, i;
2888
2889 if (!bp->num_tests || !BNXT_SINGLE_PF(bp))
2890 return;
2891 memset(buf, 0, sizeof(u64) * bp->num_tests);
2892 if (!netif_running(dev)) {
2893 etest->flags |= ETH_TEST_FL_FAILED;
2894 return;
2895 }
2896
2897 if ((etest->flags & ETH_TEST_FL_EXTERNAL_LB) &&
2898 (bp->test_info->flags & BNXT_TEST_FL_EXT_LPBK))
2899 do_ext_lpbk = true;
2900
2901 if (etest->flags & ETH_TEST_FL_OFFLINE) {
2902 if (bp->pf.active_vfs) {
2903 etest->flags |= ETH_TEST_FL_FAILED;
2904 netdev_warn(dev, "Offline tests cannot be run with active VFs\n");
2905 return;
2906 }
2907 offline = true;
2908 }
2909
2910 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2911 u8 bit_val = 1 << i;
2912
2913 if (!(bp->test_info->offline_mask & bit_val))
2914 test_mask |= bit_val;
2915 else if (offline)
2916 test_mask |= bit_val;
2917 }
2918 if (!offline) {
2919 bnxt_run_fw_tests(bp, test_mask, &test_results);
2920 } else {
2921 rc = bnxt_close_nic(bp, false, false);
2922 if (rc)
2923 return;
2924 bnxt_run_fw_tests(bp, test_mask, &test_results);
2925
2926 buf[BNXT_MACLPBK_TEST_IDX] = 1;
2927 bnxt_hwrm_mac_loopback(bp, true);
2928 msleep(250);
2929 rc = bnxt_half_open_nic(bp);
2930 if (rc) {
2931 bnxt_hwrm_mac_loopback(bp, false);
2932 etest->flags |= ETH_TEST_FL_FAILED;
2933 return;
2934 }
2935 if (bnxt_run_loopback(bp))
2936 etest->flags |= ETH_TEST_FL_FAILED;
2937 else
2938 buf[BNXT_MACLPBK_TEST_IDX] = 0;
2939
2940 bnxt_hwrm_mac_loopback(bp, false);
2941 bnxt_hwrm_phy_loopback(bp, true, false);
2942 msleep(1000);
2943 if (bnxt_run_loopback(bp)) {
2944 buf[BNXT_PHYLPBK_TEST_IDX] = 1;
2945 etest->flags |= ETH_TEST_FL_FAILED;
2946 }
2947 if (do_ext_lpbk) {
2948 etest->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
2949 bnxt_hwrm_phy_loopback(bp, true, true);
2950 msleep(1000);
2951 if (bnxt_run_loopback(bp)) {
2952 buf[BNXT_EXTLPBK_TEST_IDX] = 1;
2953 etest->flags |= ETH_TEST_FL_FAILED;
2954 }
2955 }
2956 bnxt_hwrm_phy_loopback(bp, false, false);
2957 bnxt_half_close_nic(bp);
2958 rc = bnxt_open_nic(bp, false, true);
2959 }
2960 if (rc || bnxt_test_irq(bp)) {
2961 buf[BNXT_IRQ_TEST_IDX] = 1;
2962 etest->flags |= ETH_TEST_FL_FAILED;
2963 }
2964 for (i = 0; i < bp->num_tests - BNXT_DRV_TESTS; i++) {
2965 u8 bit_val = 1 << i;
2966
2967 if ((test_mask & bit_val) && !(test_results & bit_val)) {
2968 buf[i] = 1;
2969 etest->flags |= ETH_TEST_FL_FAILED;
2970 }
2971 }
2972 }
2973
2974 static int bnxt_reset(struct net_device *dev, u32 *flags)
2975 {
2976 struct bnxt *bp = netdev_priv(dev);
2977 int rc = 0;
2978
2979 if (!BNXT_PF(bp)) {
2980 netdev_err(dev, "Reset is not supported from a VF\n");
2981 return -EOPNOTSUPP;
2982 }
2983
2984 if (pci_vfs_assigned(bp->pdev)) {
2985 netdev_err(dev,
2986 "Reset not allowed when VFs are assigned to VMs\n");
2987 return -EBUSY;
2988 }
2989
2990 if (*flags == ETH_RESET_ALL) {
2991
2992 if (bp->hwrm_spec_code < 0x10803)
2993 return -EOPNOTSUPP;
2994
2995 rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_CHIP);
2996 if (!rc) {
2997 netdev_info(dev, "Reset request successful. Reload driver to complete reset\n");
2998 *flags = 0;
2999 }
3000 } else if (*flags == ETH_RESET_AP) {
3001
3002 if (bp->hwrm_spec_code < 0x10803)
3003 return -EOPNOTSUPP;
3004
3005 rc = bnxt_firmware_reset(dev, BNXT_FW_RESET_AP);
3006 if (!rc) {
3007 netdev_info(dev, "Reset Application Processor request successful.\n");
3008 *flags = 0;
3009 }
3010 } else {
3011 rc = -EINVAL;
3012 }
3013
3014 return rc;
3015 }
3016
3017 static int bnxt_hwrm_dbg_dma_data(struct bnxt *bp, void *msg, int msg_len,
3018 struct bnxt_hwrm_dbg_dma_info *info)
3019 {
3020 struct hwrm_dbg_cmn_output *cmn_resp = bp->hwrm_cmd_resp_addr;
3021 struct hwrm_dbg_cmn_input *cmn_req = msg;
3022 __le16 *seq_ptr = msg + info->seq_off;
3023 u16 seq = 0, len, segs_off;
3024 void *resp = cmn_resp;
3025 dma_addr_t dma_handle;
3026 int rc, off = 0;
3027 void *dma_buf;
3028
3029 dma_buf = dma_alloc_coherent(&bp->pdev->dev, info->dma_len, &dma_handle,
3030 GFP_KERNEL);
3031 if (!dma_buf)
3032 return -ENOMEM;
3033
3034 segs_off = offsetof(struct hwrm_dbg_coredump_list_output,
3035 total_segments);
3036 cmn_req->host_dest_addr = cpu_to_le64(dma_handle);
3037 cmn_req->host_buf_len = cpu_to_le32(info->dma_len);
3038 mutex_lock(&bp->hwrm_cmd_lock);
3039 while (1) {
3040 *seq_ptr = cpu_to_le16(seq);
3041 rc = _hwrm_send_message(bp, msg, msg_len, HWRM_CMD_TIMEOUT);
3042 if (rc)
3043 break;
3044
3045 len = le16_to_cpu(*((__le16 *)(resp + info->data_len_off)));
3046 if (!seq &&
3047 cmn_req->req_type == cpu_to_le16(HWRM_DBG_COREDUMP_LIST)) {
3048 info->segs = le16_to_cpu(*((__le16 *)(resp +
3049 segs_off)));
3050 if (!info->segs) {
3051 rc = -EIO;
3052 break;
3053 }
3054
3055 info->dest_buf_size = info->segs *
3056 sizeof(struct coredump_segment_record);
3057 info->dest_buf = kmalloc(info->dest_buf_size,
3058 GFP_KERNEL);
3059 if (!info->dest_buf) {
3060 rc = -ENOMEM;
3061 break;
3062 }
3063 }
3064
3065 if (info->dest_buf) {
3066 if ((info->seg_start + off + len) <=
3067 BNXT_COREDUMP_BUF_LEN(info->buf_len)) {
3068 memcpy(info->dest_buf + off, dma_buf, len);
3069 } else {
3070 rc = -ENOBUFS;
3071 break;
3072 }
3073 }
3074
3075 if (cmn_req->req_type ==
3076 cpu_to_le16(HWRM_DBG_COREDUMP_RETRIEVE))
3077 info->dest_buf_size += len;
3078
3079 if (!(cmn_resp->flags & HWRM_DBG_CMN_FLAGS_MORE))
3080 break;
3081
3082 seq++;
3083 off += len;
3084 }
3085 mutex_unlock(&bp->hwrm_cmd_lock);
3086 dma_free_coherent(&bp->pdev->dev, info->dma_len, dma_buf, dma_handle);
3087 return rc;
3088 }
3089
3090 static int bnxt_hwrm_dbg_coredump_list(struct bnxt *bp,
3091 struct bnxt_coredump *coredump)
3092 {
3093 struct hwrm_dbg_coredump_list_input req = {0};
3094 struct bnxt_hwrm_dbg_dma_info info = {NULL};
3095 int rc;
3096
3097 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_LIST, -1, -1);
3098
3099 info.dma_len = COREDUMP_LIST_BUF_LEN;
3100 info.seq_off = offsetof(struct hwrm_dbg_coredump_list_input, seq_no);
3101 info.data_len_off = offsetof(struct hwrm_dbg_coredump_list_output,
3102 data_len);
3103
3104 rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info);
3105 if (!rc) {
3106 coredump->data = info.dest_buf;
3107 coredump->data_size = info.dest_buf_size;
3108 coredump->total_segs = info.segs;
3109 }
3110 return rc;
3111 }
3112
3113 static int bnxt_hwrm_dbg_coredump_initiate(struct bnxt *bp, u16 component_id,
3114 u16 segment_id)
3115 {
3116 struct hwrm_dbg_coredump_initiate_input req = {0};
3117
3118 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_INITIATE, -1, -1);
3119 req.component_id = cpu_to_le16(component_id);
3120 req.segment_id = cpu_to_le16(segment_id);
3121
3122 return hwrm_send_message(bp, &req, sizeof(req), HWRM_COREDUMP_TIMEOUT);
3123 }
3124
3125 static int bnxt_hwrm_dbg_coredump_retrieve(struct bnxt *bp, u16 component_id,
3126 u16 segment_id, u32 *seg_len,
3127 void *buf, u32 buf_len, u32 offset)
3128 {
3129 struct hwrm_dbg_coredump_retrieve_input req = {0};
3130 struct bnxt_hwrm_dbg_dma_info info = {NULL};
3131 int rc;
3132
3133 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_DBG_COREDUMP_RETRIEVE, -1, -1);
3134 req.component_id = cpu_to_le16(component_id);
3135 req.segment_id = cpu_to_le16(segment_id);
3136
3137 info.dma_len = COREDUMP_RETRIEVE_BUF_LEN;
3138 info.seq_off = offsetof(struct hwrm_dbg_coredump_retrieve_input,
3139 seq_no);
3140 info.data_len_off = offsetof(struct hwrm_dbg_coredump_retrieve_output,
3141 data_len);
3142 if (buf) {
3143 info.dest_buf = buf + offset;
3144 info.buf_len = buf_len;
3145 info.seg_start = offset;
3146 }
3147
3148 rc = bnxt_hwrm_dbg_dma_data(bp, &req, sizeof(req), &info);
3149 if (!rc)
3150 *seg_len = info.dest_buf_size;
3151
3152 return rc;
3153 }
3154
3155 static void
3156 bnxt_fill_coredump_seg_hdr(struct bnxt *bp,
3157 struct bnxt_coredump_segment_hdr *seg_hdr,
3158 struct coredump_segment_record *seg_rec, u32 seg_len,
3159 int status, u32 duration, u32 instance)
3160 {
3161 memset(seg_hdr, 0, sizeof(*seg_hdr));
3162 memcpy(seg_hdr->signature, "sEgM", 4);
3163 if (seg_rec) {
3164 seg_hdr->component_id = (__force __le32)seg_rec->component_id;
3165 seg_hdr->segment_id = (__force __le32)seg_rec->segment_id;
3166 seg_hdr->low_version = seg_rec->version_low;
3167 seg_hdr->high_version = seg_rec->version_hi;
3168 } else {
3169
3170
3171
3172 seg_hdr->component_id = cpu_to_le32(2);
3173 seg_hdr->segment_id = 0;
3174 }
3175 seg_hdr->function_id = cpu_to_le16(bp->pdev->devfn);
3176 seg_hdr->length = cpu_to_le32(seg_len);
3177 seg_hdr->status = cpu_to_le32(status);
3178 seg_hdr->duration = cpu_to_le32(duration);
3179 seg_hdr->data_offset = cpu_to_le32(sizeof(*seg_hdr));
3180 seg_hdr->instance = cpu_to_le32(instance);
3181 }
3182
3183 static void
3184 bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
3185 time64_t start, s16 start_utc, u16 total_segs,
3186 int status)
3187 {
3188 time64_t end = ktime_get_real_seconds();
3189 u32 os_ver_major = 0, os_ver_minor = 0;
3190 struct tm tm;
3191
3192 time64_to_tm(start, 0, &tm);
3193 memset(record, 0, sizeof(*record));
3194 memcpy(record->signature, "cOrE", 4);
3195 record->flags = 0;
3196 record->low_version = 0;
3197 record->high_version = 1;
3198 record->asic_state = 0;
3199 strlcpy(record->system_name, utsname()->nodename,
3200 sizeof(record->system_name));
3201 record->year = cpu_to_le16(tm.tm_year + 1900);
3202 record->month = cpu_to_le16(tm.tm_mon + 1);
3203 record->day = cpu_to_le16(tm.tm_mday);
3204 record->hour = cpu_to_le16(tm.tm_hour);
3205 record->minute = cpu_to_le16(tm.tm_min);
3206 record->second = cpu_to_le16(tm.tm_sec);
3207 record->utc_bias = cpu_to_le16(start_utc);
3208 strcpy(record->commandline, "ethtool -w");
3209 record->total_segments = cpu_to_le32(total_segs);
3210
3211 sscanf(utsname()->release, "%u.%u", &os_ver_major, &os_ver_minor);
3212 record->os_ver_major = cpu_to_le32(os_ver_major);
3213 record->os_ver_minor = cpu_to_le32(os_ver_minor);
3214
3215 strlcpy(record->os_name, utsname()->sysname, 32);
3216 time64_to_tm(end, 0, &tm);
3217 record->end_year = cpu_to_le16(tm.tm_year + 1900);
3218 record->end_month = cpu_to_le16(tm.tm_mon + 1);
3219 record->end_day = cpu_to_le16(tm.tm_mday);
3220 record->end_hour = cpu_to_le16(tm.tm_hour);
3221 record->end_minute = cpu_to_le16(tm.tm_min);
3222 record->end_second = cpu_to_le16(tm.tm_sec);
3223 record->end_utc_bias = cpu_to_le16(sys_tz.tz_minuteswest * 60);
3224 record->asic_id1 = cpu_to_le32(bp->chip_num << 16 |
3225 bp->ver_resp.chip_rev << 8 |
3226 bp->ver_resp.chip_metal);
3227 record->asic_id2 = 0;
3228 record->coredump_status = cpu_to_le32(status);
3229 record->ioctl_low_version = 0;
3230 record->ioctl_high_version = 0;
3231 }
3232
3233 static int bnxt_get_coredump(struct bnxt *bp, void *buf, u32 *dump_len)
3234 {
3235 u32 ver_get_resp_len = sizeof(struct hwrm_ver_get_output);
3236 u32 offset = 0, seg_hdr_len, seg_record_len, buf_len = 0;
3237 struct coredump_segment_record *seg_record = NULL;
3238 struct bnxt_coredump_segment_hdr seg_hdr;
3239 struct bnxt_coredump coredump = {NULL};
3240 time64_t start_time;
3241 u16 start_utc;
3242 int rc = 0, i;
3243
3244 if (buf)
3245 buf_len = *dump_len;
3246
3247 start_time = ktime_get_real_seconds();
3248 start_utc = sys_tz.tz_minuteswest * 60;
3249 seg_hdr_len = sizeof(seg_hdr);
3250
3251
3252 *dump_len = seg_hdr_len + ver_get_resp_len;
3253 if (buf) {
3254 bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, NULL, ver_get_resp_len,
3255 0, 0, 0);
3256 memcpy(buf + offset, &seg_hdr, seg_hdr_len);
3257 offset += seg_hdr_len;
3258 memcpy(buf + offset, &bp->ver_resp, ver_get_resp_len);
3259 offset += ver_get_resp_len;
3260 }
3261
3262 rc = bnxt_hwrm_dbg_coredump_list(bp, &coredump);
3263 if (rc) {
3264 netdev_err(bp->dev, "Failed to get coredump segment list\n");
3265 goto err;
3266 }
3267
3268 *dump_len += seg_hdr_len * coredump.total_segs;
3269
3270 seg_record = (struct coredump_segment_record *)coredump.data;
3271 seg_record_len = sizeof(*seg_record);
3272
3273 for (i = 0; i < coredump.total_segs; i++) {
3274 u16 comp_id = le16_to_cpu(seg_record->component_id);
3275 u16 seg_id = le16_to_cpu(seg_record->segment_id);
3276 u32 duration = 0, seg_len = 0;
3277 unsigned long start, end;
3278
3279 if (buf && ((offset + seg_hdr_len) >
3280 BNXT_COREDUMP_BUF_LEN(buf_len))) {
3281 rc = -ENOBUFS;
3282 goto err;
3283 }
3284
3285 start = jiffies;
3286
3287 rc = bnxt_hwrm_dbg_coredump_initiate(bp, comp_id, seg_id);
3288 if (rc) {
3289 netdev_err(bp->dev,
3290 "Failed to initiate coredump for seg = %d\n",
3291 seg_record->segment_id);
3292 goto next_seg;
3293 }
3294
3295
3296 rc = bnxt_hwrm_dbg_coredump_retrieve(bp, comp_id, seg_id,
3297 &seg_len, buf, buf_len,
3298 offset + seg_hdr_len);
3299 if (rc && rc == -ENOBUFS)
3300 goto err;
3301 else if (rc)
3302 netdev_err(bp->dev,
3303 "Failed to retrieve coredump for seg = %d\n",
3304 seg_record->segment_id);
3305
3306 next_seg:
3307 end = jiffies;
3308 duration = jiffies_to_msecs(end - start);
3309 bnxt_fill_coredump_seg_hdr(bp, &seg_hdr, seg_record, seg_len,
3310 rc, duration, 0);
3311
3312 if (buf) {
3313
3314 memcpy(buf + offset, &seg_hdr, seg_hdr_len);
3315 offset += seg_hdr_len + seg_len;
3316 }
3317
3318 *dump_len += seg_len;
3319 seg_record =
3320 (struct coredump_segment_record *)((u8 *)seg_record +
3321 seg_record_len);
3322 }
3323
3324 err:
3325 if (buf)
3326 bnxt_fill_coredump_record(bp, buf + offset, start_time,
3327 start_utc, coredump.total_segs + 1,
3328 rc);
3329 kfree(coredump.data);
3330 *dump_len += sizeof(struct bnxt_coredump_record);
3331 if (rc == -ENOBUFS)
3332 netdev_err(bp->dev, "Firmware returned large coredump buffer");
3333 return rc;
3334 }
3335
3336 static int bnxt_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump)
3337 {
3338 struct bnxt *bp = netdev_priv(dev);
3339
3340 if (bp->hwrm_spec_code < 0x10801)
3341 return -EOPNOTSUPP;
3342
3343 dump->version = bp->ver_resp.hwrm_fw_maj_8b << 24 |
3344 bp->ver_resp.hwrm_fw_min_8b << 16 |
3345 bp->ver_resp.hwrm_fw_bld_8b << 8 |
3346 bp->ver_resp.hwrm_fw_rsvd_8b;
3347
3348 return bnxt_get_coredump(bp, NULL, &dump->len);
3349 }
3350
3351 static int bnxt_get_dump_data(struct net_device *dev, struct ethtool_dump *dump,
3352 void *buf)
3353 {
3354 struct bnxt *bp = netdev_priv(dev);
3355
3356 if (bp->hwrm_spec_code < 0x10801)
3357 return -EOPNOTSUPP;
3358
3359 memset(buf, 0, dump->len);
3360
3361 return bnxt_get_coredump(bp, buf, &dump->len);
3362 }
3363
3364 void bnxt_ethtool_init(struct bnxt *bp)
3365 {
3366 struct hwrm_selftest_qlist_output *resp = bp->hwrm_cmd_resp_addr;
3367 struct hwrm_selftest_qlist_input req = {0};
3368 struct bnxt_test_info *test_info;
3369 struct net_device *dev = bp->dev;
3370 int i, rc;
3371
3372 if (!(bp->fw_cap & BNXT_FW_CAP_PKG_VER))
3373 bnxt_get_pkgver(dev);
3374
3375 bp->num_tests = 0;
3376 if (bp->hwrm_spec_code < 0x10704 || !BNXT_SINGLE_PF(bp))
3377 return;
3378
3379 bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_SELFTEST_QLIST, -1, -1);
3380 mutex_lock(&bp->hwrm_cmd_lock);
3381 rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
3382 if (rc)
3383 goto ethtool_init_exit;
3384
3385 test_info = bp->test_info;
3386 if (!test_info)
3387 test_info = kzalloc(sizeof(*bp->test_info), GFP_KERNEL);
3388 if (!test_info)
3389 goto ethtool_init_exit;
3390
3391 bp->test_info = test_info;
3392 bp->num_tests = resp->num_tests + BNXT_DRV_TESTS;
3393 if (bp->num_tests > BNXT_MAX_TEST)
3394 bp->num_tests = BNXT_MAX_TEST;
3395
3396 test_info->offline_mask = resp->offline_tests;
3397 test_info->timeout = le16_to_cpu(resp->test_timeout);
3398 if (!test_info->timeout)
3399 test_info->timeout = HWRM_CMD_TIMEOUT;
3400 for (i = 0; i < bp->num_tests; i++) {
3401 char *str = test_info->string[i];
3402 char *fw_str = resp->test0_name + i * 32;
3403
3404 if (i == BNXT_MACLPBK_TEST_IDX) {
3405 strcpy(str, "Mac loopback test (offline)");
3406 } else if (i == BNXT_PHYLPBK_TEST_IDX) {
3407 strcpy(str, "Phy loopback test (offline)");
3408 } else if (i == BNXT_EXTLPBK_TEST_IDX) {
3409 strcpy(str, "Ext loopback test (offline)");
3410 } else if (i == BNXT_IRQ_TEST_IDX) {
3411 strcpy(str, "Interrupt_test (offline)");
3412 } else {
3413 strlcpy(str, fw_str, ETH_GSTRING_LEN);
3414 strncat(str, " test", ETH_GSTRING_LEN - strlen(str));
3415 if (test_info->offline_mask & (1 << i))
3416 strncat(str, " (offline)",
3417 ETH_GSTRING_LEN - strlen(str));
3418 else
3419 strncat(str, " (online)",
3420 ETH_GSTRING_LEN - strlen(str));
3421 }
3422 }
3423
3424 ethtool_init_exit:
3425 mutex_unlock(&bp->hwrm_cmd_lock);
3426 }
3427
3428 void bnxt_ethtool_free(struct bnxt *bp)
3429 {
3430 kfree(bp->test_info);
3431 bp->test_info = NULL;
3432 }
3433
3434 const struct ethtool_ops bnxt_ethtool_ops = {
3435 .get_link_ksettings = bnxt_get_link_ksettings,
3436 .set_link_ksettings = bnxt_set_link_ksettings,
3437 .get_pauseparam = bnxt_get_pauseparam,
3438 .set_pauseparam = bnxt_set_pauseparam,
3439 .get_drvinfo = bnxt_get_drvinfo,
3440 .get_wol = bnxt_get_wol,
3441 .set_wol = bnxt_set_wol,
3442 .get_coalesce = bnxt_get_coalesce,
3443 .set_coalesce = bnxt_set_coalesce,
3444 .get_msglevel = bnxt_get_msglevel,
3445 .set_msglevel = bnxt_set_msglevel,
3446 .get_sset_count = bnxt_get_sset_count,
3447 .get_strings = bnxt_get_strings,
3448 .get_ethtool_stats = bnxt_get_ethtool_stats,
3449 .set_ringparam = bnxt_set_ringparam,
3450 .get_ringparam = bnxt_get_ringparam,
3451 .get_channels = bnxt_get_channels,
3452 .set_channels = bnxt_set_channels,
3453 .get_rxnfc = bnxt_get_rxnfc,
3454 .set_rxnfc = bnxt_set_rxnfc,
3455 .get_rxfh_indir_size = bnxt_get_rxfh_indir_size,
3456 .get_rxfh_key_size = bnxt_get_rxfh_key_size,
3457 .get_rxfh = bnxt_get_rxfh,
3458 .flash_device = bnxt_flash_device,
3459 .get_eeprom_len = bnxt_get_eeprom_len,
3460 .get_eeprom = bnxt_get_eeprom,
3461 .set_eeprom = bnxt_set_eeprom,
3462 .get_link = bnxt_get_link,
3463 .get_eee = bnxt_get_eee,
3464 .set_eee = bnxt_set_eee,
3465 .get_module_info = bnxt_get_module_info,
3466 .get_module_eeprom = bnxt_get_module_eeprom,
3467 .nway_reset = bnxt_nway_reset,
3468 .set_phys_id = bnxt_set_phys_id,
3469 .self_test = bnxt_self_test,
3470 .reset = bnxt_reset,
3471 .get_dump_flag = bnxt_get_dump_flag,
3472 .get_dump_data = bnxt_get_dump_data,
3473 };