Commit | Line | Data |
---|---|---|
c0c050c5 MC |
1 | /* Broadcom NetXtreme-C/E network driver. |
2 | * | |
3 | * Copyright (c) 2014-2015 Broadcom Corporation | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation. | |
8 | */ | |
9 | ||
10 | #include <linux/ethtool.h> | |
11 | #include <linux/interrupt.h> | |
12 | #include <linux/pci.h> | |
13 | #include <linux/etherdevice.h> | |
14 | #include <linux/crc32.h> | |
15 | #include <linux/firmware.h> | |
16 | #include "bnxt_hsi.h" | |
17 | #include "bnxt.h" | |
18 | #include "bnxt_ethtool.h" | |
19 | #include "bnxt_nvm_defs.h" /* NVRAM content constant and structure defs */ | |
20 | #include "bnxt_fw_hdr.h" /* Firmware hdr constant and structure defs */ | |
21 | #define FLASH_NVRAM_TIMEOUT ((HWRM_CMD_TIMEOUT) * 100) | |
22 | ||
23 | static u32 bnxt_get_msglevel(struct net_device *dev) | |
24 | { | |
25 | struct bnxt *bp = netdev_priv(dev); | |
26 | ||
27 | return bp->msg_enable; | |
28 | } | |
29 | ||
30 | static void bnxt_set_msglevel(struct net_device *dev, u32 value) | |
31 | { | |
32 | struct bnxt *bp = netdev_priv(dev); | |
33 | ||
34 | bp->msg_enable = value; | |
35 | } | |
36 | ||
37 | static int bnxt_get_coalesce(struct net_device *dev, | |
38 | struct ethtool_coalesce *coal) | |
39 | { | |
40 | struct bnxt *bp = netdev_priv(dev); | |
41 | ||
42 | memset(coal, 0, sizeof(*coal)); | |
43 | ||
dfb5b894 MC |
44 | coal->rx_coalesce_usecs = bp->rx_coal_ticks; |
45 | /* 2 completion records per rx packet */ | |
46 | coal->rx_max_coalesced_frames = bp->rx_coal_bufs / 2; | |
47 | coal->rx_coalesce_usecs_irq = bp->rx_coal_ticks_irq; | |
48 | coal->rx_max_coalesced_frames_irq = bp->rx_coal_bufs_irq / 2; | |
c0c050c5 MC |
49 | |
50 | return 0; | |
51 | } | |
52 | ||
53 | static int bnxt_set_coalesce(struct net_device *dev, | |
54 | struct ethtool_coalesce *coal) | |
55 | { | |
56 | struct bnxt *bp = netdev_priv(dev); | |
57 | int rc = 0; | |
58 | ||
dfb5b894 MC |
59 | bp->rx_coal_ticks = coal->rx_coalesce_usecs; |
60 | /* 2 completion records per rx packet */ | |
61 | bp->rx_coal_bufs = coal->rx_max_coalesced_frames * 2; | |
62 | bp->rx_coal_ticks_irq = coal->rx_coalesce_usecs_irq; | |
63 | bp->rx_coal_bufs_irq = coal->rx_max_coalesced_frames_irq * 2; | |
c0c050c5 MC |
64 | |
65 | if (netif_running(dev)) | |
66 | rc = bnxt_hwrm_set_coal(bp); | |
67 | ||
68 | return rc; | |
69 | } | |
70 | ||
71 | #define BNXT_NUM_STATS 21 | |
72 | ||
73 | static int bnxt_get_sset_count(struct net_device *dev, int sset) | |
74 | { | |
75 | struct bnxt *bp = netdev_priv(dev); | |
76 | ||
77 | switch (sset) { | |
78 | case ETH_SS_STATS: | |
79 | return BNXT_NUM_STATS * bp->cp_nr_rings; | |
80 | default: | |
81 | return -EOPNOTSUPP; | |
82 | } | |
83 | } | |
84 | ||
85 | static void bnxt_get_ethtool_stats(struct net_device *dev, | |
86 | struct ethtool_stats *stats, u64 *buf) | |
87 | { | |
88 | u32 i, j = 0; | |
89 | struct bnxt *bp = netdev_priv(dev); | |
90 | u32 buf_size = sizeof(struct ctx_hw_stats) * bp->cp_nr_rings; | |
91 | u32 stat_fields = sizeof(struct ctx_hw_stats) / 8; | |
92 | ||
93 | memset(buf, 0, buf_size); | |
94 | ||
95 | if (!bp->bnapi) | |
96 | return; | |
97 | ||
98 | for (i = 0; i < bp->cp_nr_rings; i++) { | |
99 | struct bnxt_napi *bnapi = bp->bnapi[i]; | |
100 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; | |
101 | __le64 *hw_stats = (__le64 *)cpr->hw_stats; | |
102 | int k; | |
103 | ||
104 | for (k = 0; k < stat_fields; j++, k++) | |
105 | buf[j] = le64_to_cpu(hw_stats[k]); | |
106 | buf[j++] = cpr->rx_l4_csum_errors; | |
107 | } | |
108 | } | |
109 | ||
110 | static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf) | |
111 | { | |
112 | struct bnxt *bp = netdev_priv(dev); | |
113 | u32 i; | |
114 | ||
115 | switch (stringset) { | |
116 | /* The number of strings must match BNXT_NUM_STATS defined above. */ | |
117 | case ETH_SS_STATS: | |
118 | for (i = 0; i < bp->cp_nr_rings; i++) { | |
119 | sprintf(buf, "[%d]: rx_ucast_packets", i); | |
120 | buf += ETH_GSTRING_LEN; | |
121 | sprintf(buf, "[%d]: rx_mcast_packets", i); | |
122 | buf += ETH_GSTRING_LEN; | |
123 | sprintf(buf, "[%d]: rx_bcast_packets", i); | |
124 | buf += ETH_GSTRING_LEN; | |
125 | sprintf(buf, "[%d]: rx_discards", i); | |
126 | buf += ETH_GSTRING_LEN; | |
127 | sprintf(buf, "[%d]: rx_drops", i); | |
128 | buf += ETH_GSTRING_LEN; | |
129 | sprintf(buf, "[%d]: rx_ucast_bytes", i); | |
130 | buf += ETH_GSTRING_LEN; | |
131 | sprintf(buf, "[%d]: rx_mcast_bytes", i); | |
132 | buf += ETH_GSTRING_LEN; | |
133 | sprintf(buf, "[%d]: rx_bcast_bytes", i); | |
134 | buf += ETH_GSTRING_LEN; | |
135 | sprintf(buf, "[%d]: tx_ucast_packets", i); | |
136 | buf += ETH_GSTRING_LEN; | |
137 | sprintf(buf, "[%d]: tx_mcast_packets", i); | |
138 | buf += ETH_GSTRING_LEN; | |
139 | sprintf(buf, "[%d]: tx_bcast_packets", i); | |
140 | buf += ETH_GSTRING_LEN; | |
141 | sprintf(buf, "[%d]: tx_discards", i); | |
142 | buf += ETH_GSTRING_LEN; | |
143 | sprintf(buf, "[%d]: tx_drops", i); | |
144 | buf += ETH_GSTRING_LEN; | |
145 | sprintf(buf, "[%d]: tx_ucast_bytes", i); | |
146 | buf += ETH_GSTRING_LEN; | |
147 | sprintf(buf, "[%d]: tx_mcast_bytes", i); | |
148 | buf += ETH_GSTRING_LEN; | |
149 | sprintf(buf, "[%d]: tx_bcast_bytes", i); | |
150 | buf += ETH_GSTRING_LEN; | |
151 | sprintf(buf, "[%d]: tpa_packets", i); | |
152 | buf += ETH_GSTRING_LEN; | |
153 | sprintf(buf, "[%d]: tpa_bytes", i); | |
154 | buf += ETH_GSTRING_LEN; | |
155 | sprintf(buf, "[%d]: tpa_events", i); | |
156 | buf += ETH_GSTRING_LEN; | |
157 | sprintf(buf, "[%d]: tpa_aborts", i); | |
158 | buf += ETH_GSTRING_LEN; | |
159 | sprintf(buf, "[%d]: rx_l4_csum_errors", i); | |
160 | buf += ETH_GSTRING_LEN; | |
161 | } | |
162 | break; | |
163 | default: | |
164 | netdev_err(bp->dev, "bnxt_get_strings invalid request %x\n", | |
165 | stringset); | |
166 | break; | |
167 | } | |
168 | } | |
169 | ||
170 | static void bnxt_get_ringparam(struct net_device *dev, | |
171 | struct ethtool_ringparam *ering) | |
172 | { | |
173 | struct bnxt *bp = netdev_priv(dev); | |
174 | ||
175 | ering->rx_max_pending = BNXT_MAX_RX_DESC_CNT; | |
176 | ering->rx_jumbo_max_pending = BNXT_MAX_RX_JUM_DESC_CNT; | |
177 | ering->tx_max_pending = BNXT_MAX_TX_DESC_CNT; | |
178 | ||
179 | ering->rx_pending = bp->rx_ring_size; | |
180 | ering->rx_jumbo_pending = bp->rx_agg_ring_size; | |
181 | ering->tx_pending = bp->tx_ring_size; | |
182 | } | |
183 | ||
184 | static int bnxt_set_ringparam(struct net_device *dev, | |
185 | struct ethtool_ringparam *ering) | |
186 | { | |
187 | struct bnxt *bp = netdev_priv(dev); | |
188 | ||
189 | if ((ering->rx_pending > BNXT_MAX_RX_DESC_CNT) || | |
190 | (ering->tx_pending > BNXT_MAX_TX_DESC_CNT) || | |
191 | (ering->tx_pending <= MAX_SKB_FRAGS)) | |
192 | return -EINVAL; | |
193 | ||
194 | if (netif_running(dev)) | |
195 | bnxt_close_nic(bp, false, false); | |
196 | ||
197 | bp->rx_ring_size = ering->rx_pending; | |
198 | bp->tx_ring_size = ering->tx_pending; | |
199 | bnxt_set_ring_params(bp); | |
200 | ||
201 | if (netif_running(dev)) | |
202 | return bnxt_open_nic(bp, false, false); | |
203 | ||
204 | return 0; | |
205 | } | |
206 | ||
207 | static void bnxt_get_channels(struct net_device *dev, | |
208 | struct ethtool_channels *channel) | |
209 | { | |
210 | struct bnxt *bp = netdev_priv(dev); | |
211 | int max_rx_rings, max_tx_rings, tcs; | |
212 | ||
6e6c5a57 | 213 | bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, true); |
068c9ec6 MC |
214 | channel->max_combined = max_rx_rings; |
215 | ||
216 | bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, false); | |
c0c050c5 MC |
217 | tcs = netdev_get_num_tc(dev); |
218 | if (tcs > 1) | |
219 | max_tx_rings /= tcs; | |
220 | ||
221 | channel->max_rx = max_rx_rings; | |
222 | channel->max_tx = max_tx_rings; | |
223 | channel->max_other = 0; | |
068c9ec6 MC |
224 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) { |
225 | channel->combined_count = bp->rx_nr_rings; | |
226 | } else { | |
227 | channel->rx_count = bp->rx_nr_rings; | |
228 | channel->tx_count = bp->tx_nr_rings_per_tc; | |
229 | } | |
c0c050c5 MC |
230 | } |
231 | ||
232 | static int bnxt_set_channels(struct net_device *dev, | |
233 | struct ethtool_channels *channel) | |
234 | { | |
235 | struct bnxt *bp = netdev_priv(dev); | |
236 | int max_rx_rings, max_tx_rings, tcs; | |
237 | u32 rc = 0; | |
068c9ec6 | 238 | bool sh = false; |
c0c050c5 | 239 | |
068c9ec6 | 240 | if (channel->other_count) |
c0c050c5 MC |
241 | return -EINVAL; |
242 | ||
068c9ec6 MC |
243 | if (!channel->combined_count && |
244 | (!channel->rx_count || !channel->tx_count)) | |
245 | return -EINVAL; | |
246 | ||
247 | if (channel->combined_count && | |
248 | (channel->rx_count || channel->tx_count)) | |
249 | return -EINVAL; | |
250 | ||
251 | if (channel->combined_count) | |
252 | sh = true; | |
253 | ||
254 | bnxt_get_max_rings(bp, &max_rx_rings, &max_tx_rings, sh); | |
255 | ||
c0c050c5 MC |
256 | tcs = netdev_get_num_tc(dev); |
257 | if (tcs > 1) | |
258 | max_tx_rings /= tcs; | |
259 | ||
068c9ec6 MC |
260 | if (sh && (channel->combined_count > max_rx_rings || |
261 | channel->combined_count > max_tx_rings)) | |
262 | return -ENOMEM; | |
263 | ||
264 | if (!sh && (channel->rx_count > max_rx_rings || | |
265 | channel->tx_count > max_tx_rings)) | |
266 | return -ENOMEM; | |
c0c050c5 MC |
267 | |
268 | if (netif_running(dev)) { | |
269 | if (BNXT_PF(bp)) { | |
270 | /* TODO CHIMP_FW: Send message to all VF's | |
271 | * before PF unload | |
272 | */ | |
273 | } | |
274 | rc = bnxt_close_nic(bp, true, false); | |
275 | if (rc) { | |
276 | netdev_err(bp->dev, "Set channel failure rc :%x\n", | |
277 | rc); | |
278 | return rc; | |
279 | } | |
280 | } | |
281 | ||
068c9ec6 MC |
282 | if (sh) { |
283 | bp->flags |= BNXT_FLAG_SHARED_RINGS; | |
284 | bp->rx_nr_rings = channel->combined_count; | |
285 | bp->tx_nr_rings_per_tc = channel->combined_count; | |
286 | } else { | |
287 | bp->flags &= ~BNXT_FLAG_SHARED_RINGS; | |
288 | bp->rx_nr_rings = channel->rx_count; | |
289 | bp->tx_nr_rings_per_tc = channel->tx_count; | |
290 | } | |
291 | ||
c0c050c5 MC |
292 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
293 | if (tcs > 1) | |
294 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tcs; | |
068c9ec6 MC |
295 | |
296 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : | |
297 | bp->tx_nr_rings + bp->rx_nr_rings; | |
298 | ||
c0c050c5 MC |
299 | bp->num_stat_ctxs = bp->cp_nr_rings; |
300 | ||
2bcfa6f6 MC |
301 | /* After changing number of rx channels, update NTUPLE feature. */ |
302 | netdev_update_features(dev); | |
c0c050c5 MC |
303 | if (netif_running(dev)) { |
304 | rc = bnxt_open_nic(bp, true, false); | |
305 | if ((!rc) && BNXT_PF(bp)) { | |
306 | /* TODO CHIMP_FW: Send message to all VF's | |
307 | * to renable | |
308 | */ | |
309 | } | |
310 | } | |
311 | ||
312 | return rc; | |
313 | } | |
314 | ||
315 | #ifdef CONFIG_RFS_ACCEL | |
316 | static int bnxt_grxclsrlall(struct bnxt *bp, struct ethtool_rxnfc *cmd, | |
317 | u32 *rule_locs) | |
318 | { | |
319 | int i, j = 0; | |
320 | ||
321 | cmd->data = bp->ntp_fltr_count; | |
322 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { | |
323 | struct hlist_head *head; | |
324 | struct bnxt_ntuple_filter *fltr; | |
325 | ||
326 | head = &bp->ntp_fltr_hash_tbl[i]; | |
327 | rcu_read_lock(); | |
328 | hlist_for_each_entry_rcu(fltr, head, hash) { | |
329 | if (j == cmd->rule_cnt) | |
330 | break; | |
331 | rule_locs[j++] = fltr->sw_id; | |
332 | } | |
333 | rcu_read_unlock(); | |
334 | if (j == cmd->rule_cnt) | |
335 | break; | |
336 | } | |
337 | cmd->rule_cnt = j; | |
338 | return 0; | |
339 | } | |
340 | ||
341 | static int bnxt_grxclsrule(struct bnxt *bp, struct ethtool_rxnfc *cmd) | |
342 | { | |
343 | struct ethtool_rx_flow_spec *fs = | |
344 | (struct ethtool_rx_flow_spec *)&cmd->fs; | |
345 | struct bnxt_ntuple_filter *fltr; | |
346 | struct flow_keys *fkeys; | |
347 | int i, rc = -EINVAL; | |
348 | ||
349 | if (fs->location < 0 || fs->location >= BNXT_NTP_FLTR_MAX_FLTR) | |
350 | return rc; | |
351 | ||
352 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { | |
353 | struct hlist_head *head; | |
354 | ||
355 | head = &bp->ntp_fltr_hash_tbl[i]; | |
356 | rcu_read_lock(); | |
357 | hlist_for_each_entry_rcu(fltr, head, hash) { | |
358 | if (fltr->sw_id == fs->location) | |
359 | goto fltr_found; | |
360 | } | |
361 | rcu_read_unlock(); | |
362 | } | |
363 | return rc; | |
364 | ||
365 | fltr_found: | |
366 | fkeys = &fltr->fkeys; | |
367 | if (fkeys->basic.ip_proto == IPPROTO_TCP) | |
368 | fs->flow_type = TCP_V4_FLOW; | |
369 | else if (fkeys->basic.ip_proto == IPPROTO_UDP) | |
370 | fs->flow_type = UDP_V4_FLOW; | |
371 | else | |
372 | goto fltr_err; | |
373 | ||
374 | fs->h_u.tcp_ip4_spec.ip4src = fkeys->addrs.v4addrs.src; | |
375 | fs->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(~0); | |
376 | ||
377 | fs->h_u.tcp_ip4_spec.ip4dst = fkeys->addrs.v4addrs.dst; | |
378 | fs->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(~0); | |
379 | ||
380 | fs->h_u.tcp_ip4_spec.psrc = fkeys->ports.src; | |
381 | fs->m_u.tcp_ip4_spec.psrc = cpu_to_be16(~0); | |
382 | ||
383 | fs->h_u.tcp_ip4_spec.pdst = fkeys->ports.dst; | |
384 | fs->m_u.tcp_ip4_spec.pdst = cpu_to_be16(~0); | |
385 | ||
386 | fs->ring_cookie = fltr->rxq; | |
387 | rc = 0; | |
388 | ||
389 | fltr_err: | |
390 | rcu_read_unlock(); | |
391 | ||
392 | return rc; | |
393 | } | |
394 | ||
395 | static int bnxt_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, | |
396 | u32 *rule_locs) | |
397 | { | |
398 | struct bnxt *bp = netdev_priv(dev); | |
399 | int rc = 0; | |
400 | ||
401 | switch (cmd->cmd) { | |
402 | case ETHTOOL_GRXRINGS: | |
403 | cmd->data = bp->rx_nr_rings; | |
404 | break; | |
405 | ||
406 | case ETHTOOL_GRXCLSRLCNT: | |
407 | cmd->rule_cnt = bp->ntp_fltr_count; | |
408 | cmd->data = BNXT_NTP_FLTR_MAX_FLTR; | |
409 | break; | |
410 | ||
411 | case ETHTOOL_GRXCLSRLALL: | |
412 | rc = bnxt_grxclsrlall(bp, cmd, (u32 *)rule_locs); | |
413 | break; | |
414 | ||
415 | case ETHTOOL_GRXCLSRULE: | |
416 | rc = bnxt_grxclsrule(bp, cmd); | |
417 | break; | |
418 | ||
419 | default: | |
420 | rc = -EOPNOTSUPP; | |
421 | break; | |
422 | } | |
423 | ||
424 | return rc; | |
425 | } | |
426 | #endif | |
427 | ||
428 | static u32 bnxt_get_rxfh_indir_size(struct net_device *dev) | |
429 | { | |
430 | return HW_HASH_INDEX_SIZE; | |
431 | } | |
432 | ||
433 | static u32 bnxt_get_rxfh_key_size(struct net_device *dev) | |
434 | { | |
435 | return HW_HASH_KEY_SIZE; | |
436 | } | |
437 | ||
438 | static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, | |
439 | u8 *hfunc) | |
440 | { | |
441 | struct bnxt *bp = netdev_priv(dev); | |
442 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; | |
443 | int i = 0; | |
444 | ||
445 | if (hfunc) | |
446 | *hfunc = ETH_RSS_HASH_TOP; | |
447 | ||
448 | if (indir) | |
449 | for (i = 0; i < HW_HASH_INDEX_SIZE; i++) | |
450 | indir[i] = le16_to_cpu(vnic->rss_table[i]); | |
451 | ||
452 | if (key) | |
453 | memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE); | |
454 | ||
455 | return 0; | |
456 | } | |
457 | ||
458 | static void bnxt_get_drvinfo(struct net_device *dev, | |
459 | struct ethtool_drvinfo *info) | |
460 | { | |
461 | struct bnxt *bp = netdev_priv(dev); | |
462 | ||
463 | strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); | |
464 | strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); | |
465 | strlcpy(info->fw_version, bp->fw_ver_str, sizeof(info->fw_version)); | |
466 | strlcpy(info->bus_info, pci_name(bp->pdev), sizeof(info->bus_info)); | |
467 | info->n_stats = BNXT_NUM_STATS * bp->cp_nr_rings; | |
468 | info->testinfo_len = BNXT_NUM_TESTS(bp); | |
469 | /* TODO CHIMP_FW: eeprom dump details */ | |
470 | info->eedump_len = 0; | |
471 | /* TODO CHIMP FW: reg dump details */ | |
472 | info->regdump_len = 0; | |
473 | } | |
474 | ||
475 | static u32 bnxt_fw_to_ethtool_support_spds(struct bnxt_link_info *link_info) | |
476 | { | |
477 | u16 fw_speeds = link_info->support_speeds; | |
478 | u32 speed_mask = 0; | |
479 | ||
480 | if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) | |
481 | speed_mask |= SUPPORTED_100baseT_Full; | |
482 | if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) | |
483 | speed_mask |= SUPPORTED_1000baseT_Full; | |
484 | if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) | |
485 | speed_mask |= SUPPORTED_2500baseX_Full; | |
486 | if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) | |
487 | speed_mask |= SUPPORTED_10000baseT_Full; | |
c0c050c5 | 488 | if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) |
1c49c421 | 489 | speed_mask |= SUPPORTED_40000baseCR4_Full; |
c0c050c5 MC |
490 | |
491 | return speed_mask; | |
492 | } | |
493 | ||
494 | static u32 bnxt_fw_to_ethtool_advertised_spds(struct bnxt_link_info *link_info) | |
495 | { | |
496 | u16 fw_speeds = link_info->auto_link_speeds; | |
497 | u32 speed_mask = 0; | |
498 | ||
499 | /* TODO: support 25GB, 40GB, 50GB with different cable type */ | |
500 | /* set the advertised speeds */ | |
501 | if (fw_speeds & BNXT_LINK_SPEED_MSK_100MB) | |
502 | speed_mask |= ADVERTISED_100baseT_Full; | |
503 | if (fw_speeds & BNXT_LINK_SPEED_MSK_1GB) | |
504 | speed_mask |= ADVERTISED_1000baseT_Full; | |
505 | if (fw_speeds & BNXT_LINK_SPEED_MSK_2_5GB) | |
506 | speed_mask |= ADVERTISED_2500baseX_Full; | |
507 | if (fw_speeds & BNXT_LINK_SPEED_MSK_10GB) | |
508 | speed_mask |= ADVERTISED_10000baseT_Full; | |
c0c050c5 | 509 | if (fw_speeds & BNXT_LINK_SPEED_MSK_40GB) |
1c49c421 | 510 | speed_mask |= ADVERTISED_40000baseCR4_Full; |
c0c050c5 MC |
511 | return speed_mask; |
512 | } | |
513 | ||
514 | u32 bnxt_fw_to_ethtool_speed(u16 fw_link_speed) | |
515 | { | |
516 | switch (fw_link_speed) { | |
517 | case BNXT_LINK_SPEED_100MB: | |
518 | return SPEED_100; | |
519 | case BNXT_LINK_SPEED_1GB: | |
520 | return SPEED_1000; | |
521 | case BNXT_LINK_SPEED_2_5GB: | |
522 | return SPEED_2500; | |
523 | case BNXT_LINK_SPEED_10GB: | |
524 | return SPEED_10000; | |
525 | case BNXT_LINK_SPEED_20GB: | |
526 | return SPEED_20000; | |
527 | case BNXT_LINK_SPEED_25GB: | |
528 | return SPEED_25000; | |
529 | case BNXT_LINK_SPEED_40GB: | |
530 | return SPEED_40000; | |
531 | case BNXT_LINK_SPEED_50GB: | |
532 | return SPEED_50000; | |
533 | default: | |
534 | return SPEED_UNKNOWN; | |
535 | } | |
536 | } | |
537 | ||
538 | static int bnxt_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
539 | { | |
540 | struct bnxt *bp = netdev_priv(dev); | |
541 | struct bnxt_link_info *link_info = &bp->link_info; | |
542 | u16 ethtool_speed; | |
543 | ||
544 | cmd->supported = bnxt_fw_to_ethtool_support_spds(link_info); | |
0d8abf02 | 545 | cmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; |
c0c050c5 MC |
546 | |
547 | if (link_info->auto_link_speeds) | |
548 | cmd->supported |= SUPPORTED_Autoneg; | |
549 | ||
b763499e | 550 | if (link_info->autoneg) { |
c0c050c5 MC |
551 | cmd->advertising = |
552 | bnxt_fw_to_ethtool_advertised_spds(link_info); | |
553 | cmd->advertising |= ADVERTISED_Autoneg; | |
554 | cmd->autoneg = AUTONEG_ENABLE; | |
555 | } else { | |
556 | cmd->autoneg = AUTONEG_DISABLE; | |
557 | cmd->advertising = 0; | |
558 | } | |
0d8abf02 | 559 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) { |
c0c050c5 MC |
560 | if ((link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) == |
561 | BNXT_LINK_PAUSE_BOTH) { | |
562 | cmd->advertising |= ADVERTISED_Pause; | |
c0c050c5 MC |
563 | } else { |
564 | cmd->advertising |= ADVERTISED_Asym_Pause; | |
c0c050c5 MC |
565 | if (link_info->auto_pause_setting & |
566 | BNXT_LINK_PAUSE_RX) | |
567 | cmd->advertising |= ADVERTISED_Pause; | |
568 | } | |
c0c050c5 MC |
569 | } |
570 | ||
571 | cmd->port = PORT_NONE; | |
572 | if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { | |
573 | cmd->port = PORT_TP; | |
574 | cmd->supported |= SUPPORTED_TP; | |
575 | cmd->advertising |= ADVERTISED_TP; | |
576 | } else { | |
577 | cmd->supported |= SUPPORTED_FIBRE; | |
578 | cmd->advertising |= ADVERTISED_FIBRE; | |
579 | ||
580 | if (link_info->media_type == PORT_PHY_QCFG_RESP_MEDIA_TYPE_DAC) | |
581 | cmd->port = PORT_DA; | |
582 | else if (link_info->media_type == | |
583 | PORT_PHY_QCFG_RESP_MEDIA_TYPE_FIBRE) | |
584 | cmd->port = PORT_FIBRE; | |
585 | } | |
586 | ||
587 | if (link_info->phy_link_status == BNXT_LINK_LINK) { | |
588 | if (link_info->duplex & BNXT_LINK_DUPLEX_FULL) | |
589 | cmd->duplex = DUPLEX_FULL; | |
590 | } else { | |
591 | cmd->duplex = DUPLEX_UNKNOWN; | |
592 | } | |
593 | ethtool_speed = bnxt_fw_to_ethtool_speed(link_info->link_speed); | |
594 | ethtool_cmd_speed_set(cmd, ethtool_speed); | |
595 | if (link_info->transceiver == | |
596 | PORT_PHY_QCFG_RESP_TRANSCEIVER_TYPE_XCVR_INTERNAL) | |
597 | cmd->transceiver = XCVR_INTERNAL; | |
598 | else | |
599 | cmd->transceiver = XCVR_EXTERNAL; | |
600 | cmd->phy_address = link_info->phy_addr; | |
601 | ||
602 | return 0; | |
603 | } | |
604 | ||
605 | static u32 bnxt_get_fw_speed(struct net_device *dev, u16 ethtool_speed) | |
606 | { | |
607 | switch (ethtool_speed) { | |
608 | case SPEED_100: | |
609 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_100MB; | |
610 | case SPEED_1000: | |
611 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_1GB; | |
612 | case SPEED_2500: | |
613 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_2_5GB; | |
614 | case SPEED_10000: | |
615 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_10GB; | |
616 | case SPEED_20000: | |
617 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_20GB; | |
618 | case SPEED_25000: | |
619 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_25GB; | |
620 | case SPEED_40000: | |
621 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_40GB; | |
622 | case SPEED_50000: | |
623 | return PORT_PHY_CFG_REQ_AUTO_LINK_SPEED_50GB; | |
624 | default: | |
625 | netdev_err(dev, "unsupported speed!\n"); | |
626 | break; | |
627 | } | |
628 | return 0; | |
629 | } | |
630 | ||
631 | static u16 bnxt_get_fw_auto_link_speeds(u32 advertising) | |
632 | { | |
633 | u16 fw_speed_mask = 0; | |
634 | ||
635 | /* only support autoneg at speed 100, 1000, and 10000 */ | |
636 | if (advertising & (ADVERTISED_100baseT_Full | | |
637 | ADVERTISED_100baseT_Half)) { | |
638 | fw_speed_mask |= BNXT_LINK_SPEED_MSK_100MB; | |
639 | } | |
640 | if (advertising & (ADVERTISED_1000baseT_Full | | |
641 | ADVERTISED_1000baseT_Half)) { | |
642 | fw_speed_mask |= BNXT_LINK_SPEED_MSK_1GB; | |
643 | } | |
644 | if (advertising & ADVERTISED_10000baseT_Full) | |
645 | fw_speed_mask |= BNXT_LINK_SPEED_MSK_10GB; | |
646 | ||
1c49c421 MC |
647 | if (advertising & ADVERTISED_40000baseCR4_Full) |
648 | fw_speed_mask |= BNXT_LINK_SPEED_MSK_40GB; | |
649 | ||
c0c050c5 MC |
650 | return fw_speed_mask; |
651 | } | |
652 | ||
653 | static int bnxt_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | |
654 | { | |
655 | int rc = 0; | |
656 | struct bnxt *bp = netdev_priv(dev); | |
657 | struct bnxt_link_info *link_info = &bp->link_info; | |
658 | u32 speed, fw_advertising = 0; | |
659 | bool set_pause = false; | |
660 | ||
661 | if (BNXT_VF(bp)) | |
662 | return rc; | |
663 | ||
664 | if (cmd->autoneg == AUTONEG_ENABLE) { | |
665 | if (link_info->media_type != PORT_PHY_QCFG_RESP_MEDIA_TYPE_TP) { | |
666 | netdev_err(dev, "Media type doesn't support autoneg\n"); | |
667 | rc = -EINVAL; | |
668 | goto set_setting_exit; | |
669 | } | |
670 | if (cmd->advertising & ~(BNXT_ALL_COPPER_ETHTOOL_SPEED | | |
671 | ADVERTISED_Autoneg | | |
672 | ADVERTISED_TP | | |
673 | ADVERTISED_Pause | | |
674 | ADVERTISED_Asym_Pause)) { | |
675 | netdev_err(dev, "Unsupported advertising mask (adv: 0x%x)\n", | |
676 | cmd->advertising); | |
677 | rc = -EINVAL; | |
678 | goto set_setting_exit; | |
679 | } | |
680 | fw_advertising = bnxt_get_fw_auto_link_speeds(cmd->advertising); | |
681 | if (fw_advertising & ~link_info->support_speeds) { | |
682 | netdev_err(dev, "Advertising parameters are not supported! (adv: 0x%x)\n", | |
683 | cmd->advertising); | |
684 | rc = -EINVAL; | |
685 | goto set_setting_exit; | |
686 | } | |
687 | link_info->autoneg |= BNXT_AUTONEG_SPEED; | |
688 | if (!fw_advertising) | |
689 | link_info->advertising = link_info->support_speeds; | |
690 | else | |
691 | link_info->advertising = fw_advertising; | |
692 | /* any change to autoneg will cause link change, therefore the | |
693 | * driver should put back the original pause setting in autoneg | |
694 | */ | |
695 | set_pause = true; | |
696 | } else { | |
697 | /* TODO: currently don't support half duplex */ | |
698 | if (cmd->duplex == DUPLEX_HALF) { | |
699 | netdev_err(dev, "HALF DUPLEX is not supported!\n"); | |
700 | rc = -EINVAL; | |
701 | goto set_setting_exit; | |
702 | } | |
703 | /* If received a request for an unknown duplex, assume full*/ | |
704 | if (cmd->duplex == DUPLEX_UNKNOWN) | |
705 | cmd->duplex = DUPLEX_FULL; | |
706 | speed = ethtool_cmd_speed(cmd); | |
707 | link_info->req_link_speed = bnxt_get_fw_speed(dev, speed); | |
708 | link_info->req_duplex = BNXT_LINK_DUPLEX_FULL; | |
b763499e | 709 | link_info->autoneg = 0; |
c0c050c5 MC |
710 | link_info->advertising = 0; |
711 | } | |
712 | ||
713 | if (netif_running(dev)) | |
714 | rc = bnxt_hwrm_set_link_setting(bp, set_pause); | |
715 | ||
716 | set_setting_exit: | |
717 | return rc; | |
718 | } | |
719 | ||
720 | static void bnxt_get_pauseparam(struct net_device *dev, | |
721 | struct ethtool_pauseparam *epause) | |
722 | { | |
723 | struct bnxt *bp = netdev_priv(dev); | |
724 | struct bnxt_link_info *link_info = &bp->link_info; | |
725 | ||
726 | if (BNXT_VF(bp)) | |
727 | return; | |
b763499e | 728 | epause->autoneg = !!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL); |
c0c050c5 MC |
729 | epause->rx_pause = ((link_info->pause & BNXT_LINK_PAUSE_RX) != 0); |
730 | epause->tx_pause = ((link_info->pause & BNXT_LINK_PAUSE_TX) != 0); | |
731 | } | |
732 | ||
733 | static int bnxt_set_pauseparam(struct net_device *dev, | |
734 | struct ethtool_pauseparam *epause) | |
735 | { | |
736 | int rc = 0; | |
737 | struct bnxt *bp = netdev_priv(dev); | |
738 | struct bnxt_link_info *link_info = &bp->link_info; | |
739 | ||
740 | if (BNXT_VF(bp)) | |
741 | return rc; | |
742 | ||
743 | if (epause->autoneg) { | |
b763499e MC |
744 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) |
745 | return -EINVAL; | |
746 | ||
c0c050c5 MC |
747 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
748 | link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_BOTH; | |
749 | } else { | |
750 | /* when transition from auto pause to force pause, | |
751 | * force a link change | |
752 | */ | |
753 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) | |
754 | link_info->force_link_chng = true; | |
755 | link_info->autoneg &= ~BNXT_AUTONEG_FLOW_CTRL; | |
756 | link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_BOTH; | |
757 | } | |
758 | if (epause->rx_pause) | |
759 | link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_RX; | |
760 | else | |
761 | link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_RX; | |
762 | ||
763 | if (epause->tx_pause) | |
764 | link_info->req_flow_ctrl |= BNXT_LINK_PAUSE_TX; | |
765 | else | |
766 | link_info->req_flow_ctrl &= ~BNXT_LINK_PAUSE_TX; | |
767 | ||
768 | if (netif_running(dev)) | |
769 | rc = bnxt_hwrm_set_pause(bp); | |
770 | return rc; | |
771 | } | |
772 | ||
773 | static u32 bnxt_get_link(struct net_device *dev) | |
774 | { | |
775 | struct bnxt *bp = netdev_priv(dev); | |
776 | ||
777 | /* TODO: handle MF, VF, driver close case */ | |
778 | return bp->link_info.link_up; | |
779 | } | |
780 | ||
781 | static int bnxt_flash_nvram(struct net_device *dev, | |
782 | u16 dir_type, | |
783 | u16 dir_ordinal, | |
784 | u16 dir_ext, | |
785 | u16 dir_attr, | |
786 | const u8 *data, | |
787 | size_t data_len) | |
788 | { | |
789 | struct bnxt *bp = netdev_priv(dev); | |
790 | int rc; | |
791 | struct hwrm_nvm_write_input req = {0}; | |
792 | dma_addr_t dma_handle; | |
793 | u8 *kmem; | |
794 | ||
795 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_WRITE, -1, -1); | |
796 | ||
797 | req.dir_type = cpu_to_le16(dir_type); | |
798 | req.dir_ordinal = cpu_to_le16(dir_ordinal); | |
799 | req.dir_ext = cpu_to_le16(dir_ext); | |
800 | req.dir_attr = cpu_to_le16(dir_attr); | |
801 | req.dir_data_length = cpu_to_le32(data_len); | |
802 | ||
803 | kmem = dma_alloc_coherent(&bp->pdev->dev, data_len, &dma_handle, | |
804 | GFP_KERNEL); | |
805 | if (!kmem) { | |
806 | netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", | |
807 | (unsigned)data_len); | |
808 | return -ENOMEM; | |
809 | } | |
810 | memcpy(kmem, data, data_len); | |
811 | req.host_src_addr = cpu_to_le64(dma_handle); | |
812 | ||
813 | rc = hwrm_send_message(bp, &req, sizeof(req), FLASH_NVRAM_TIMEOUT); | |
814 | dma_free_coherent(&bp->pdev->dev, data_len, kmem, dma_handle); | |
815 | ||
816 | return rc; | |
817 | } | |
818 | ||
d2d6318c RS |
819 | static int bnxt_firmware_reset(struct net_device *dev, |
820 | u16 dir_type) | |
821 | { | |
822 | struct bnxt *bp = netdev_priv(dev); | |
823 | struct hwrm_fw_reset_input req = {0}; | |
824 | ||
825 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_RESET, -1, -1); | |
826 | ||
827 | /* TODO: Support ASAP ChiMP self-reset (e.g. upon PF driver unload) */ | |
828 | /* TODO: Address self-reset of APE/KONG/BONO/TANG or ungraceful reset */ | |
829 | /* (e.g. when firmware isn't already running) */ | |
830 | switch (dir_type) { | |
831 | case BNX_DIR_TYPE_CHIMP_PATCH: | |
832 | case BNX_DIR_TYPE_BOOTCODE: | |
833 | case BNX_DIR_TYPE_BOOTCODE_2: | |
834 | req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_BOOT; | |
835 | /* Self-reset ChiMP upon next PCIe reset: */ | |
836 | req.selfrst_status = FW_RESET_REQ_SELFRST_STATUS_SELFRSTPCIERST; | |
837 | break; | |
838 | case BNX_DIR_TYPE_APE_FW: | |
839 | case BNX_DIR_TYPE_APE_PATCH: | |
840 | req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_MGMT; | |
841 | break; | |
842 | case BNX_DIR_TYPE_KONG_FW: | |
843 | case BNX_DIR_TYPE_KONG_PATCH: | |
844 | req.embedded_proc_type = | |
845 | FW_RESET_REQ_EMBEDDED_PROC_TYPE_NETCTRL; | |
846 | break; | |
847 | case BNX_DIR_TYPE_BONO_FW: | |
848 | case BNX_DIR_TYPE_BONO_PATCH: | |
849 | req.embedded_proc_type = FW_RESET_REQ_EMBEDDED_PROC_TYPE_ROCE; | |
850 | break; | |
851 | default: | |
852 | return -EINVAL; | |
853 | } | |
854 | ||
855 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); | |
856 | } | |
857 | ||
c0c050c5 MC |
858 | static int bnxt_flash_firmware(struct net_device *dev, |
859 | u16 dir_type, | |
860 | const u8 *fw_data, | |
861 | size_t fw_size) | |
862 | { | |
863 | int rc = 0; | |
864 | u16 code_type; | |
865 | u32 stored_crc; | |
866 | u32 calculated_crc; | |
867 | struct bnxt_fw_header *header = (struct bnxt_fw_header *)fw_data; | |
868 | ||
869 | switch (dir_type) { | |
870 | case BNX_DIR_TYPE_BOOTCODE: | |
871 | case BNX_DIR_TYPE_BOOTCODE_2: | |
872 | code_type = CODE_BOOT; | |
873 | break; | |
2731d70f RS |
874 | case BNX_DIR_TYPE_APE_FW: |
875 | code_type = CODE_MCTP_PASSTHRU; | |
876 | break; | |
c0c050c5 MC |
877 | default: |
878 | netdev_err(dev, "Unsupported directory entry type: %u\n", | |
879 | dir_type); | |
880 | return -EINVAL; | |
881 | } | |
882 | if (fw_size < sizeof(struct bnxt_fw_header)) { | |
883 | netdev_err(dev, "Invalid firmware file size: %u\n", | |
884 | (unsigned int)fw_size); | |
885 | return -EINVAL; | |
886 | } | |
887 | if (header->signature != cpu_to_le32(BNXT_FIRMWARE_BIN_SIGNATURE)) { | |
888 | netdev_err(dev, "Invalid firmware signature: %08X\n", | |
889 | le32_to_cpu(header->signature)); | |
890 | return -EINVAL; | |
891 | } | |
892 | if (header->code_type != code_type) { | |
893 | netdev_err(dev, "Expected firmware type: %d, read: %d\n", | |
894 | code_type, header->code_type); | |
895 | return -EINVAL; | |
896 | } | |
897 | if (header->device != DEVICE_CUMULUS_FAMILY) { | |
898 | netdev_err(dev, "Expected firmware device family %d, read: %d\n", | |
899 | DEVICE_CUMULUS_FAMILY, header->device); | |
900 | return -EINVAL; | |
901 | } | |
902 | /* Confirm the CRC32 checksum of the file: */ | |
903 | stored_crc = le32_to_cpu(*(__le32 *)(fw_data + fw_size - | |
904 | sizeof(stored_crc))); | |
905 | calculated_crc = ~crc32(~0, fw_data, fw_size - sizeof(stored_crc)); | |
906 | if (calculated_crc != stored_crc) { | |
907 | netdev_err(dev, "Firmware file CRC32 checksum (%08lX) does not match calculated checksum (%08lX)\n", | |
908 | (unsigned long)stored_crc, | |
909 | (unsigned long)calculated_crc); | |
910 | return -EINVAL; | |
911 | } | |
912 | /* TODO: Validate digital signature (RSA-encrypted SHA-256 hash) here */ | |
913 | rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, | |
914 | 0, 0, fw_data, fw_size); | |
d2d6318c RS |
915 | if (rc == 0) /* Firmware update successful */ |
916 | rc = bnxt_firmware_reset(dev, dir_type); | |
917 | ||
c0c050c5 MC |
918 | return rc; |
919 | } | |
920 | ||
921 | static bool bnxt_dir_type_is_ape_bin_format(u16 dir_type) | |
922 | { | |
923 | switch (dir_type) { | |
924 | case BNX_DIR_TYPE_CHIMP_PATCH: | |
925 | case BNX_DIR_TYPE_BOOTCODE: | |
926 | case BNX_DIR_TYPE_BOOTCODE_2: | |
927 | case BNX_DIR_TYPE_APE_FW: | |
928 | case BNX_DIR_TYPE_APE_PATCH: | |
929 | case BNX_DIR_TYPE_KONG_FW: | |
930 | case BNX_DIR_TYPE_KONG_PATCH: | |
931 | return true; | |
932 | } | |
933 | ||
934 | return false; | |
935 | } | |
936 | ||
937 | static bool bnxt_dir_type_is_unprotected_exec_format(u16 dir_type) | |
938 | { | |
939 | switch (dir_type) { | |
940 | case BNX_DIR_TYPE_AVS: | |
941 | case BNX_DIR_TYPE_EXP_ROM_MBA: | |
942 | case BNX_DIR_TYPE_PCIE: | |
943 | case BNX_DIR_TYPE_TSCF_UCODE: | |
944 | case BNX_DIR_TYPE_EXT_PHY: | |
945 | case BNX_DIR_TYPE_CCM: | |
946 | case BNX_DIR_TYPE_ISCSI_BOOT: | |
947 | case BNX_DIR_TYPE_ISCSI_BOOT_IPV6: | |
948 | case BNX_DIR_TYPE_ISCSI_BOOT_IPV4N6: | |
949 | return true; | |
950 | } | |
951 | ||
952 | return false; | |
953 | } | |
954 | ||
955 | static bool bnxt_dir_type_is_executable(u16 dir_type) | |
956 | { | |
957 | return bnxt_dir_type_is_ape_bin_format(dir_type) || | |
958 | bnxt_dir_type_is_unprotected_exec_format(dir_type); | |
959 | } | |
960 | ||
961 | static int bnxt_flash_firmware_from_file(struct net_device *dev, | |
962 | u16 dir_type, | |
963 | const char *filename) | |
964 | { | |
965 | const struct firmware *fw; | |
966 | int rc; | |
967 | ||
968 | if (bnxt_dir_type_is_executable(dir_type) == false) | |
969 | return -EINVAL; | |
970 | ||
971 | rc = request_firmware(&fw, filename, &dev->dev); | |
972 | if (rc != 0) { | |
973 | netdev_err(dev, "Error %d requesting firmware file: %s\n", | |
974 | rc, filename); | |
975 | return rc; | |
976 | } | |
977 | if (bnxt_dir_type_is_ape_bin_format(dir_type) == true) | |
978 | rc = bnxt_flash_firmware(dev, dir_type, fw->data, fw->size); | |
979 | else | |
980 | rc = bnxt_flash_nvram(dev, dir_type, BNX_DIR_ORDINAL_FIRST, | |
981 | 0, 0, fw->data, fw->size); | |
982 | release_firmware(fw); | |
983 | return rc; | |
984 | } | |
985 | ||
986 | static int bnxt_flash_package_from_file(struct net_device *dev, | |
987 | char *filename) | |
988 | { | |
989 | netdev_err(dev, "packages are not yet supported\n"); | |
990 | return -EINVAL; | |
991 | } | |
992 | ||
993 | static int bnxt_flash_device(struct net_device *dev, | |
994 | struct ethtool_flash *flash) | |
995 | { | |
996 | if (!BNXT_PF((struct bnxt *)netdev_priv(dev))) { | |
997 | netdev_err(dev, "flashdev not supported from a virtual function\n"); | |
998 | return -EINVAL; | |
999 | } | |
1000 | ||
1001 | if (flash->region == ETHTOOL_FLASH_ALL_REGIONS) | |
1002 | return bnxt_flash_package_from_file(dev, flash->data); | |
1003 | ||
1004 | return bnxt_flash_firmware_from_file(dev, flash->region, flash->data); | |
1005 | } | |
1006 | ||
1007 | static int nvm_get_dir_info(struct net_device *dev, u32 *entries, u32 *length) | |
1008 | { | |
1009 | struct bnxt *bp = netdev_priv(dev); | |
1010 | int rc; | |
1011 | struct hwrm_nvm_get_dir_info_input req = {0}; | |
1012 | struct hwrm_nvm_get_dir_info_output *output = bp->hwrm_cmd_resp_addr; | |
1013 | ||
1014 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_INFO, -1, -1); | |
1015 | ||
1016 | mutex_lock(&bp->hwrm_cmd_lock); | |
1017 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); | |
1018 | if (!rc) { | |
1019 | *entries = le32_to_cpu(output->entries); | |
1020 | *length = le32_to_cpu(output->entry_length); | |
1021 | } | |
1022 | mutex_unlock(&bp->hwrm_cmd_lock); | |
1023 | return rc; | |
1024 | } | |
1025 | ||
1026 | static int bnxt_get_eeprom_len(struct net_device *dev) | |
1027 | { | |
1028 | /* The -1 return value allows the entire 32-bit range of offsets to be | |
1029 | * passed via the ethtool command-line utility. | |
1030 | */ | |
1031 | return -1; | |
1032 | } | |
1033 | ||
1034 | static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data) | |
1035 | { | |
1036 | struct bnxt *bp = netdev_priv(dev); | |
1037 | int rc; | |
1038 | u32 dir_entries; | |
1039 | u32 entry_length; | |
1040 | u8 *buf; | |
1041 | size_t buflen; | |
1042 | dma_addr_t dma_handle; | |
1043 | struct hwrm_nvm_get_dir_entries_input req = {0}; | |
1044 | ||
1045 | rc = nvm_get_dir_info(dev, &dir_entries, &entry_length); | |
1046 | if (rc != 0) | |
1047 | return rc; | |
1048 | ||
1049 | /* Insert 2 bytes of directory info (count and size of entries) */ | |
1050 | if (len < 2) | |
1051 | return -EINVAL; | |
1052 | ||
1053 | *data++ = dir_entries; | |
1054 | *data++ = entry_length; | |
1055 | len -= 2; | |
1056 | memset(data, 0xff, len); | |
1057 | ||
1058 | buflen = dir_entries * entry_length; | |
1059 | buf = dma_alloc_coherent(&bp->pdev->dev, buflen, &dma_handle, | |
1060 | GFP_KERNEL); | |
1061 | if (!buf) { | |
1062 | netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", | |
1063 | (unsigned)buflen); | |
1064 | return -ENOMEM; | |
1065 | } | |
1066 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_GET_DIR_ENTRIES, -1, -1); | |
1067 | req.host_dest_addr = cpu_to_le64(dma_handle); | |
1068 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); | |
1069 | if (rc == 0) | |
1070 | memcpy(data, buf, len > buflen ? buflen : len); | |
1071 | dma_free_coherent(&bp->pdev->dev, buflen, buf, dma_handle); | |
1072 | return rc; | |
1073 | } | |
1074 | ||
1075 | static int bnxt_get_nvram_item(struct net_device *dev, u32 index, u32 offset, | |
1076 | u32 length, u8 *data) | |
1077 | { | |
1078 | struct bnxt *bp = netdev_priv(dev); | |
1079 | int rc; | |
1080 | u8 *buf; | |
1081 | dma_addr_t dma_handle; | |
1082 | struct hwrm_nvm_read_input req = {0}; | |
1083 | ||
1084 | buf = dma_alloc_coherent(&bp->pdev->dev, length, &dma_handle, | |
1085 | GFP_KERNEL); | |
1086 | if (!buf) { | |
1087 | netdev_err(dev, "dma_alloc_coherent failure, length = %u\n", | |
1088 | (unsigned)length); | |
1089 | return -ENOMEM; | |
1090 | } | |
1091 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_READ, -1, -1); | |
1092 | req.host_dest_addr = cpu_to_le64(dma_handle); | |
1093 | req.dir_idx = cpu_to_le16(index); | |
1094 | req.offset = cpu_to_le32(offset); | |
1095 | req.len = cpu_to_le32(length); | |
1096 | ||
1097 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); | |
1098 | if (rc == 0) | |
1099 | memcpy(data, buf, length); | |
1100 | dma_free_coherent(&bp->pdev->dev, length, buf, dma_handle); | |
1101 | return rc; | |
1102 | } | |
1103 | ||
1104 | static int bnxt_get_eeprom(struct net_device *dev, | |
1105 | struct ethtool_eeprom *eeprom, | |
1106 | u8 *data) | |
1107 | { | |
1108 | u32 index; | |
1109 | u32 offset; | |
1110 | ||
1111 | if (eeprom->offset == 0) /* special offset value to get directory */ | |
1112 | return bnxt_get_nvram_directory(dev, eeprom->len, data); | |
1113 | ||
1114 | index = eeprom->offset >> 24; | |
1115 | offset = eeprom->offset & 0xffffff; | |
1116 | ||
1117 | if (index == 0) { | |
1118 | netdev_err(dev, "unsupported index value: %d\n", index); | |
1119 | return -EINVAL; | |
1120 | } | |
1121 | ||
1122 | return bnxt_get_nvram_item(dev, index - 1, offset, eeprom->len, data); | |
1123 | } | |
1124 | ||
1125 | static int bnxt_erase_nvram_directory(struct net_device *dev, u8 index) | |
1126 | { | |
1127 | struct bnxt *bp = netdev_priv(dev); | |
1128 | struct hwrm_nvm_erase_dir_entry_input req = {0}; | |
1129 | ||
1130 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_NVM_ERASE_DIR_ENTRY, -1, -1); | |
1131 | req.dir_idx = cpu_to_le16(index); | |
1132 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); | |
1133 | } | |
1134 | ||
1135 | static int bnxt_set_eeprom(struct net_device *dev, | |
1136 | struct ethtool_eeprom *eeprom, | |
1137 | u8 *data) | |
1138 | { | |
1139 | struct bnxt *bp = netdev_priv(dev); | |
1140 | u8 index, dir_op; | |
1141 | u16 type, ext, ordinal, attr; | |
1142 | ||
1143 | if (!BNXT_PF(bp)) { | |
1144 | netdev_err(dev, "NVM write not supported from a virtual function\n"); | |
1145 | return -EINVAL; | |
1146 | } | |
1147 | ||
1148 | type = eeprom->magic >> 16; | |
1149 | ||
1150 | if (type == 0xffff) { /* special value for directory operations */ | |
1151 | index = eeprom->magic & 0xff; | |
1152 | dir_op = eeprom->magic >> 8; | |
1153 | if (index == 0) | |
1154 | return -EINVAL; | |
1155 | switch (dir_op) { | |
1156 | case 0x0e: /* erase */ | |
1157 | if (eeprom->offset != ~eeprom->magic) | |
1158 | return -EINVAL; | |
1159 | return bnxt_erase_nvram_directory(dev, index - 1); | |
1160 | default: | |
1161 | return -EINVAL; | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | /* Create or re-write an NVM item: */ | |
1166 | if (bnxt_dir_type_is_executable(type) == true) | |
1167 | return -EINVAL; | |
1168 | ext = eeprom->magic & 0xffff; | |
1169 | ordinal = eeprom->offset >> 16; | |
1170 | attr = eeprom->offset & 0xffff; | |
1171 | ||
1172 | return bnxt_flash_nvram(dev, type, ordinal, ext, attr, data, | |
1173 | eeprom->len); | |
1174 | } | |
1175 | ||
1176 | const struct ethtool_ops bnxt_ethtool_ops = { | |
1177 | .get_settings = bnxt_get_settings, | |
1178 | .set_settings = bnxt_set_settings, | |
1179 | .get_pauseparam = bnxt_get_pauseparam, | |
1180 | .set_pauseparam = bnxt_set_pauseparam, | |
1181 | .get_drvinfo = bnxt_get_drvinfo, | |
1182 | .get_coalesce = bnxt_get_coalesce, | |
1183 | .set_coalesce = bnxt_set_coalesce, | |
1184 | .get_msglevel = bnxt_get_msglevel, | |
1185 | .set_msglevel = bnxt_set_msglevel, | |
1186 | .get_sset_count = bnxt_get_sset_count, | |
1187 | .get_strings = bnxt_get_strings, | |
1188 | .get_ethtool_stats = bnxt_get_ethtool_stats, | |
1189 | .set_ringparam = bnxt_set_ringparam, | |
1190 | .get_ringparam = bnxt_get_ringparam, | |
1191 | .get_channels = bnxt_get_channels, | |
1192 | .set_channels = bnxt_set_channels, | |
1193 | #ifdef CONFIG_RFS_ACCEL | |
1194 | .get_rxnfc = bnxt_get_rxnfc, | |
1195 | #endif | |
1196 | .get_rxfh_indir_size = bnxt_get_rxfh_indir_size, | |
1197 | .get_rxfh_key_size = bnxt_get_rxfh_key_size, | |
1198 | .get_rxfh = bnxt_get_rxfh, | |
1199 | .flash_device = bnxt_flash_device, | |
1200 | .get_eeprom_len = bnxt_get_eeprom_len, | |
1201 | .get_eeprom = bnxt_get_eeprom, | |
1202 | .set_eeprom = bnxt_set_eeprom, | |
1203 | .get_link = bnxt_get_link, | |
1204 | }; |