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