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