Commit | Line | Data |
---|---|---|
6e9ef509 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
6b7c5b94 | 2 | /* |
7dfbe7d7 | 3 | * Copyright (C) 2005 - 2016 Broadcom |
6b7c5b94 SP |
4 | * All rights reserved. |
5 | * | |
6b7c5b94 | 6 | * Contact Information: |
d2145cde | 7 | * linux-drivers@emulex.com |
6b7c5b94 | 8 | * |
d2145cde AK |
9 | * Emulex |
10 | * 3333 Susan Street | |
11 | * Costa Mesa, CA 92626 | |
6b7c5b94 SP |
12 | */ |
13 | ||
14 | #include "be.h" | |
8788fdc2 | 15 | #include "be_cmds.h" |
6b7c5b94 SP |
16 | #include <linux/ethtool.h> |
17 | ||
18 | struct be_ethtool_stat { | |
19 | char desc[ETH_GSTRING_LEN]; | |
20 | int type; | |
21 | int size; | |
22 | int offset; | |
23 | }; | |
24 | ||
ac124ff9 | 25 | enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT}; |
c593642c | 26 | #define FIELDINFO(_struct, field) sizeof_field(_struct, field), \ |
6b7c5b94 | 27 | offsetof(_struct, field) |
3abcdeda SP |
28 | #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\ |
29 | FIELDINFO(struct be_tx_stats, field) | |
30 | #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\ | |
31 | FIELDINFO(struct be_rx_stats, field) | |
609ff3bb | 32 | #define DRVSTAT_INFO(field) #field, DRVSTAT,\ |
ac124ff9 | 33 | FIELDINFO(struct be_drv_stats, field) |
6b7c5b94 SP |
34 | |
35 | static const struct be_ethtool_stat et_stats[] = { | |
89a88ab8 AK |
36 | {DRVSTAT_INFO(rx_crc_errors)}, |
37 | {DRVSTAT_INFO(rx_alignment_symbol_errors)}, | |
38 | {DRVSTAT_INFO(rx_pause_frames)}, | |
39 | {DRVSTAT_INFO(rx_control_frames)}, | |
d45b9d39 SP |
40 | /* Received packets dropped when the Ethernet length field |
41 | * is not equal to the actual Ethernet data length. | |
42 | */ | |
89a88ab8 | 43 | {DRVSTAT_INFO(rx_in_range_errors)}, |
d45b9d39 SP |
44 | /* Received packets dropped when their length field is >= 1501 bytes |
45 | * and <= 1535 bytes. | |
46 | */ | |
89a88ab8 | 47 | {DRVSTAT_INFO(rx_out_range_errors)}, |
d45b9d39 | 48 | /* Received packets dropped when they are longer than 9216 bytes */ |
89a88ab8 | 49 | {DRVSTAT_INFO(rx_frame_too_long)}, |
d45b9d39 SP |
50 | /* Received packets dropped when they don't pass the unicast or |
51 | * multicast address filtering. | |
52 | */ | |
18fb06a1 | 53 | {DRVSTAT_INFO(rx_address_filtered)}, |
d45b9d39 SP |
54 | /* Received packets dropped when IP packet length field is less than |
55 | * the IP header length field. | |
56 | */ | |
89a88ab8 | 57 | {DRVSTAT_INFO(rx_dropped_too_small)}, |
d45b9d39 SP |
58 | /* Received packets dropped when IP length field is greater than |
59 | * the actual packet length. | |
60 | */ | |
89a88ab8 | 61 | {DRVSTAT_INFO(rx_dropped_too_short)}, |
d45b9d39 SP |
62 | /* Received packets dropped when the IP header length field is less |
63 | * than 5. | |
64 | */ | |
89a88ab8 | 65 | {DRVSTAT_INFO(rx_dropped_header_too_small)}, |
d45b9d39 SP |
66 | /* Received packets dropped when the TCP header length field is less |
67 | * than 5 or the TCP header length + IP header length is more | |
68 | * than IP packet length. | |
69 | */ | |
89a88ab8 AK |
70 | {DRVSTAT_INFO(rx_dropped_tcp_length)}, |
71 | {DRVSTAT_INFO(rx_dropped_runt)}, | |
d45b9d39 SP |
72 | /* Number of received packets dropped when a fifo for descriptors going |
73 | * into the packet demux block overflows. In normal operation, this | |
74 | * fifo must never overflow. | |
75 | */ | |
89a88ab8 | 76 | {DRVSTAT_INFO(rxpp_fifo_overflow_drop)}, |
acbd6ff8 SP |
77 | /* Received packets dropped when the RX block runs out of space in |
78 | * one of its input FIFOs. This could happen due a long burst of | |
79 | * minimum-sized (64b) frames in the receive path. | |
80 | * This counter may also be erroneously incremented rarely. | |
81 | */ | |
89a88ab8 AK |
82 | {DRVSTAT_INFO(rx_input_fifo_overflow_drop)}, |
83 | {DRVSTAT_INFO(rx_ip_checksum_errs)}, | |
84 | {DRVSTAT_INFO(rx_tcp_checksum_errs)}, | |
85 | {DRVSTAT_INFO(rx_udp_checksum_errs)}, | |
89a88ab8 AK |
86 | {DRVSTAT_INFO(tx_pauseframes)}, |
87 | {DRVSTAT_INFO(tx_controlframes)}, | |
88 | {DRVSTAT_INFO(rx_priority_pause_frames)}, | |
b5adffc4 | 89 | {DRVSTAT_INFO(tx_priority_pauseframes)}, |
d45b9d39 SP |
90 | /* Received packets dropped when an internal fifo going into |
91 | * main packet buffer tank (PMEM) overflows. | |
92 | */ | |
89a88ab8 AK |
93 | {DRVSTAT_INFO(pmem_fifo_overflow_drop)}, |
94 | {DRVSTAT_INFO(jabber_events)}, | |
d45b9d39 SP |
95 | /* Received packets dropped due to lack of available HW packet buffers |
96 | * used to temporarily hold the received packets. | |
97 | */ | |
89a88ab8 | 98 | {DRVSTAT_INFO(rx_drops_no_pbuf)}, |
d45b9d39 SP |
99 | /* Received packets dropped due to input receive buffer |
100 | * descriptor fifo overflowing. | |
101 | */ | |
89a88ab8 | 102 | {DRVSTAT_INFO(rx_drops_no_erx_descr)}, |
d45b9d39 SP |
103 | /* Packets dropped because the internal FIFO to the offloaded TCP |
104 | * receive processing block is full. This could happen only for | |
105 | * offloaded iSCSI or FCoE trarffic. | |
106 | */ | |
89a88ab8 | 107 | {DRVSTAT_INFO(rx_drops_no_tpre_descr)}, |
d45b9d39 SP |
108 | /* Received packets dropped when they need more than 8 |
109 | * receive buffers. This cannot happen as the driver configures | |
110 | * 2048 byte receive buffers. | |
111 | */ | |
89a88ab8 | 112 | {DRVSTAT_INFO(rx_drops_too_many_frags)}, |
89a88ab8 | 113 | {DRVSTAT_INFO(forwarded_packets)}, |
d45b9d39 SP |
114 | /* Received packets dropped when the frame length |
115 | * is more than 9018 bytes | |
116 | */ | |
89a88ab8 | 117 | {DRVSTAT_INFO(rx_drops_mtu)}, |
d3de1540 VV |
118 | /* Number of dma mapping errors */ |
119 | {DRVSTAT_INFO(dma_map_errors)}, | |
d45b9d39 | 120 | /* Number of packets dropped due to random early drop function */ |
89a88ab8 | 121 | {DRVSTAT_INFO(eth_red_drops)}, |
461ae379 AK |
122 | {DRVSTAT_INFO(rx_roce_bytes_lsd)}, |
123 | {DRVSTAT_INFO(rx_roce_bytes_msd)}, | |
124 | {DRVSTAT_INFO(rx_roce_frames)}, | |
125 | {DRVSTAT_INFO(roce_drops_payload_len)}, | |
126 | {DRVSTAT_INFO(roce_drops_crc)} | |
6b7c5b94 | 127 | }; |
e2fb1afa | 128 | |
6b7c5b94 SP |
129 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) |
130 | ||
ab1594e9 SP |
131 | /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts |
132 | * are first and second members respectively. | |
133 | */ | |
3abcdeda | 134 | static const struct be_ethtool_stat et_rx_stats[] = { |
ab1594e9 SP |
135 | {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */ |
136 | {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */ | |
8670f2a5 | 137 | {DRVSTAT_RX_INFO(rx_vxlan_offload_pkts)}, |
3abcdeda | 138 | {DRVSTAT_RX_INFO(rx_compl)}, |
5c29c09b | 139 | {DRVSTAT_RX_INFO(rx_compl_err)}, |
3abcdeda | 140 | {DRVSTAT_RX_INFO(rx_mcast_pkts)}, |
d45b9d39 SP |
141 | /* Number of page allocation failures while posting receive buffers |
142 | * to HW. | |
143 | */ | |
3abcdeda | 144 | {DRVSTAT_RX_INFO(rx_post_fail)}, |
d45b9d39 | 145 | /* Recevied packets dropped due to skb allocation failure */ |
ac124ff9 | 146 | {DRVSTAT_RX_INFO(rx_drops_no_skbs)}, |
d45b9d39 SP |
147 | /* Received packets dropped due to lack of available fetched buffers |
148 | * posted by the driver. | |
149 | */ | |
ac124ff9 | 150 | {DRVSTAT_RX_INFO(rx_drops_no_frags)} |
3abcdeda | 151 | }; |
e2fb1afa | 152 | |
3abcdeda SP |
153 | #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) |
154 | ||
ab1594e9 SP |
155 | /* Stats related to multi TX queues: get_stats routine assumes compl is the |
156 | * first member | |
157 | */ | |
3c8def97 | 158 | static const struct be_ethtool_stat et_tx_stats[] = { |
ab1594e9 | 159 | {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */ |
512bb8a2 KA |
160 | /* This counter is incremented when the HW encounters an error while |
161 | * parsing the packet header of an outgoing TX request. This counter is | |
162 | * applicable only for BE2, BE3 and Skyhawk based adapters. | |
163 | */ | |
164 | {DRVSTAT_TX_INFO(tx_hdr_parse_err)}, | |
165 | /* This counter is incremented when an error occurs in the DMA | |
166 | * operation associated with the TX request from the host to the device. | |
167 | */ | |
168 | {DRVSTAT_TX_INFO(tx_dma_err)}, | |
169 | /* This counter is incremented when MAC or VLAN spoof checking is | |
170 | * enabled on the interface and the TX request fails the spoof check | |
171 | * in HW. | |
172 | */ | |
173 | {DRVSTAT_TX_INFO(tx_spoof_check_err)}, | |
174 | /* This counter is incremented when the HW encounters an error while | |
175 | * performing TSO offload. This counter is applicable only for Lancer | |
176 | * adapters. | |
177 | */ | |
178 | {DRVSTAT_TX_INFO(tx_tso_err)}, | |
179 | /* This counter is incremented when the HW detects Q-in-Q style VLAN | |
180 | * tagging in a packet and such tagging is not expected on the outgoing | |
181 | * interface. This counter is applicable only for Lancer adapters. | |
182 | */ | |
183 | {DRVSTAT_TX_INFO(tx_qinq_err)}, | |
184 | /* This counter is incremented when the HW detects parity errors in the | |
185 | * packet data. This counter is applicable only for Lancer adapters. | |
186 | */ | |
187 | {DRVSTAT_TX_INFO(tx_internal_parity_err)}, | |
ffc39620 | 188 | {DRVSTAT_TX_INFO(tx_sge_err)}, |
ac124ff9 SP |
189 | {DRVSTAT_TX_INFO(tx_bytes)}, |
190 | {DRVSTAT_TX_INFO(tx_pkts)}, | |
8670f2a5 | 191 | {DRVSTAT_TX_INFO(tx_vxlan_offload_pkts)}, |
d45b9d39 | 192 | /* Number of skbs queued for trasmission by the driver */ |
ac124ff9 | 193 | {DRVSTAT_TX_INFO(tx_reqs)}, |
d45b9d39 SP |
194 | /* Number of times the TX queue was stopped due to lack |
195 | * of spaces in the TXQ. | |
196 | */ | |
bc617526 SP |
197 | {DRVSTAT_TX_INFO(tx_stops)}, |
198 | /* Pkts dropped in the driver's transmit path */ | |
199 | {DRVSTAT_TX_INFO(tx_drv_drops)} | |
3c8def97 | 200 | }; |
e2fb1afa | 201 | |
3c8def97 SP |
202 | #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats)) |
203 | ||
ff33a6e2 S |
204 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
205 | "MAC Loopback test", | |
206 | "PHY Loopback test", | |
207 | "External Loopback test", | |
4ee77214 | 208 | "DDR DMA test", |
4276e47e | 209 | "Link test" |
ff33a6e2 S |
210 | }; |
211 | ||
212 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) | |
213 | #define BE_MAC_LOOPBACK 0x0 | |
214 | #define BE_PHY_LOOPBACK 0x1 | |
215 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 | |
fced9999 | 216 | #define BE_NO_LOOPBACK 0xff |
ff33a6e2 | 217 | |
04b71175 | 218 | static void be_get_drvinfo(struct net_device *netdev, |
05e4c6a3 | 219 | struct ethtool_drvinfo *drvinfo) |
6b7c5b94 SP |
220 | { |
221 | struct be_adapter *adapter = netdev_priv(netdev); | |
222 | ||
f029c781 | 223 | strscpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver)); |
eeb65ced | 224 | if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN)) |
f029c781 | 225 | strscpy(drvinfo->fw_version, adapter->fw_ver, |
7826d43f JP |
226 | sizeof(drvinfo->fw_version)); |
227 | else | |
228 | snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), | |
eeb65ced | 229 | "%s [%s]", adapter->fw_ver, adapter->fw_on_flash); |
04b71175 | 230 | |
f029c781 | 231 | strscpy(drvinfo->bus_info, pci_name(adapter->pdev), |
68aad78c | 232 | sizeof(drvinfo->bus_info)); |
6b7c5b94 SP |
233 | } |
234 | ||
05e4c6a3 | 235 | static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name) |
de49bd5a PR |
236 | { |
237 | u32 data_read = 0, eof; | |
238 | u8 addn_status; | |
239 | struct be_dma_mem data_len_cmd; | |
de49bd5a PR |
240 | |
241 | memset(&data_len_cmd, 0, sizeof(data_len_cmd)); | |
242 | /* data_offset and data_size should be 0 to get reg len */ | |
d37b4c0a IV |
243 | lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0, file_name, |
244 | &data_read, &eof, &addn_status); | |
de49bd5a PR |
245 | |
246 | return data_read; | |
247 | } | |
248 | ||
fd7ff6f0 VD |
249 | static int be_get_dump_len(struct be_adapter *adapter) |
250 | { | |
251 | u32 dump_size = 0; | |
252 | ||
253 | if (lancer_chip(adapter)) | |
254 | dump_size = lancer_cmd_get_file_len(adapter, | |
255 | LANCER_FW_DUMP_FILE); | |
256 | else | |
257 | dump_size = adapter->fat_dump_len; | |
258 | ||
259 | return dump_size; | |
260 | } | |
261 | ||
05e4c6a3 SP |
262 | static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name, |
263 | u32 buf_len, void *buf) | |
de49bd5a PR |
264 | { |
265 | struct be_dma_mem read_cmd; | |
266 | u32 read_len = 0, total_read_len = 0, chunk_size; | |
267 | u32 eof = 0; | |
268 | u8 addn_status; | |
269 | int status = 0; | |
270 | ||
271 | read_cmd.size = LANCER_READ_FILE_CHUNK; | |
750afb08 LC |
272 | read_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, read_cmd.size, |
273 | &read_cmd.dma, GFP_ATOMIC); | |
de49bd5a PR |
274 | |
275 | if (!read_cmd.va) { | |
276 | dev_err(&adapter->pdev->dev, | |
05e4c6a3 | 277 | "Memory allocation failure while reading dump\n"); |
de49bd5a PR |
278 | return -ENOMEM; |
279 | } | |
280 | ||
281 | while ((total_read_len < buf_len) && !eof) { | |
282 | chunk_size = min_t(u32, (buf_len - total_read_len), | |
cd3307aa | 283 | LANCER_READ_FILE_CHUNK); |
de49bd5a PR |
284 | chunk_size = ALIGN(chunk_size, 4); |
285 | status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size, | |
05e4c6a3 SP |
286 | total_read_len, file_name, |
287 | &read_len, &eof, &addn_status); | |
de49bd5a PR |
288 | if (!status) { |
289 | memcpy(buf + total_read_len, read_cmd.va, read_len); | |
290 | total_read_len += read_len; | |
291 | eof &= LANCER_READ_FILE_EOF_MASK; | |
292 | } else { | |
293 | status = -EIO; | |
294 | break; | |
295 | } | |
296 | } | |
e51000db SB |
297 | dma_free_coherent(&adapter->pdev->dev, read_cmd.size, read_cmd.va, |
298 | read_cmd.dma); | |
de49bd5a PR |
299 | |
300 | return status; | |
301 | } | |
302 | ||
fd7ff6f0 VD |
303 | static int be_read_dump_data(struct be_adapter *adapter, u32 dump_len, |
304 | void *buf) | |
311fddc7 | 305 | { |
fd7ff6f0 | 306 | int status = 0; |
311fddc7 | 307 | |
fd7ff6f0 VD |
308 | if (lancer_chip(adapter)) |
309 | status = lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE, | |
310 | dump_len, buf); | |
311 | else | |
312 | status = be_cmd_get_fat_dump(adapter, dump_len, buf); | |
311fddc7 | 313 | |
fd7ff6f0 | 314 | return status; |
311fddc7 SK |
315 | } |
316 | ||
10ef9ab4 | 317 | static int be_get_coalesce(struct net_device *netdev, |
f3ccfda1 YM |
318 | struct ethtool_coalesce *et, |
319 | struct kernel_ethtool_coalesce *kernel_coal, | |
320 | struct netlink_ext_ack *extack) | |
6b7c5b94 SP |
321 | { |
322 | struct be_adapter *adapter = netdev_priv(netdev); | |
2632bafd | 323 | struct be_aic_obj *aic = &adapter->aic_obj[0]; |
10ef9ab4 | 324 | |
2632bafd SP |
325 | et->rx_coalesce_usecs = aic->prev_eqd; |
326 | et->rx_coalesce_usecs_high = aic->max_eqd; | |
327 | et->rx_coalesce_usecs_low = aic->min_eqd; | |
6b7c5b94 | 328 | |
2632bafd SP |
329 | et->tx_coalesce_usecs = aic->prev_eqd; |
330 | et->tx_coalesce_usecs_high = aic->max_eqd; | |
331 | et->tx_coalesce_usecs_low = aic->min_eqd; | |
6b7c5b94 | 332 | |
9041f047 IV |
333 | et->use_adaptive_rx_coalesce = adapter->aic_enabled; |
334 | et->use_adaptive_tx_coalesce = adapter->aic_enabled; | |
6b7c5b94 SP |
335 | |
336 | return 0; | |
337 | } | |
338 | ||
10ef9ab4 SP |
339 | /* TX attributes are ignored. Only RX attributes are considered |
340 | * eqd cmd is issued in the worker thread. | |
6b7c5b94 | 341 | */ |
10ef9ab4 | 342 | static int be_set_coalesce(struct net_device *netdev, |
f3ccfda1 YM |
343 | struct ethtool_coalesce *et, |
344 | struct kernel_ethtool_coalesce *kernel_coal, | |
345 | struct netlink_ext_ack *extack) | |
6b7c5b94 SP |
346 | { |
347 | struct be_adapter *adapter = netdev_priv(netdev); | |
2632bafd | 348 | struct be_aic_obj *aic = &adapter->aic_obj[0]; |
10ef9ab4 SP |
349 | struct be_eq_obj *eqo; |
350 | int i; | |
351 | ||
9041f047 IV |
352 | adapter->aic_enabled = et->use_adaptive_rx_coalesce; |
353 | ||
10ef9ab4 | 354 | for_all_evt_queues(adapter, eqo, i) { |
2632bafd SP |
355 | aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD); |
356 | aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd); | |
357 | aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd); | |
358 | aic->et_eqd = max(aic->et_eqd, aic->min_eqd); | |
359 | aic++; | |
6b7c5b94 SP |
360 | } |
361 | ||
20947770 PR |
362 | /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled. |
363 | * When AIC is disabled, persistently force set EQD value via the | |
364 | * FW cmd, so that we don't have to calculate the delay multiplier | |
365 | * encode value each time EQ_DB is rung | |
366 | */ | |
367 | if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter)) | |
368 | be_eqd_update(adapter, true); | |
369 | ||
6b7c5b94 SP |
370 | return 0; |
371 | } | |
372 | ||
05e4c6a3 SP |
373 | static void be_get_ethtool_stats(struct net_device *netdev, |
374 | struct ethtool_stats *stats, uint64_t *data) | |
6b7c5b94 SP |
375 | { |
376 | struct be_adapter *adapter = netdev_priv(netdev); | |
3abcdeda | 377 | struct be_rx_obj *rxo; |
3c8def97 | 378 | struct be_tx_obj *txo; |
ac124ff9 | 379 | void *p; |
ab1594e9 | 380 | unsigned int i, j, base = 0, start; |
6b7c5b94 SP |
381 | |
382 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { | |
ac124ff9 | 383 | p = (u8 *)&adapter->drv_stats + et_stats[i].offset; |
ab1594e9 | 384 | data[i] = *(u32 *)p; |
6b7c5b94 | 385 | } |
ab1594e9 | 386 | base += ETHTOOL_STATS_NUM; |
3abcdeda SP |
387 | |
388 | for_all_rx_queues(adapter, rxo, j) { | |
ab1594e9 SP |
389 | struct be_rx_stats *stats = rx_stats(rxo); |
390 | ||
391 | do { | |
068c38ad | 392 | start = u64_stats_fetch_begin(&stats->sync); |
ab1594e9 SP |
393 | data[base] = stats->rx_bytes; |
394 | data[base + 1] = stats->rx_pkts; | |
068c38ad | 395 | } while (u64_stats_fetch_retry(&stats->sync, start)); |
ab1594e9 SP |
396 | |
397 | for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) { | |
398 | p = (u8 *)stats + et_rx_stats[i].offset; | |
399 | data[base + i] = *(u32 *)p; | |
3abcdeda | 400 | } |
ab1594e9 | 401 | base += ETHTOOL_RXSTATS_NUM; |
3abcdeda | 402 | } |
3c8def97 | 403 | |
3c8def97 | 404 | for_all_tx_queues(adapter, txo, j) { |
ab1594e9 SP |
405 | struct be_tx_stats *stats = tx_stats(txo); |
406 | ||
407 | do { | |
068c38ad | 408 | start = u64_stats_fetch_begin(&stats->sync_compl); |
ab1594e9 | 409 | data[base] = stats->tx_compl; |
068c38ad | 410 | } while (u64_stats_fetch_retry(&stats->sync_compl, start)); |
ab1594e9 SP |
411 | |
412 | do { | |
068c38ad | 413 | start = u64_stats_fetch_begin(&stats->sync); |
ab1594e9 SP |
414 | for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) { |
415 | p = (u8 *)stats + et_tx_stats[i].offset; | |
416 | data[base + i] = | |
417 | (et_tx_stats[i].size == sizeof(u64)) ? | |
418 | *(u64 *)p : *(u32 *)p; | |
419 | } | |
068c38ad | 420 | } while (u64_stats_fetch_retry(&stats->sync, start)); |
ab1594e9 | 421 | base += ETHTOOL_TXSTATS_NUM; |
3c8def97 | 422 | } |
6b7c5b94 SP |
423 | } |
424 | ||
710f3e59 SB |
425 | static const char be_priv_flags[][ETH_GSTRING_LEN] = { |
426 | "disable-tpe-recovery" | |
427 | }; | |
428 | ||
05e4c6a3 SP |
429 | static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset, |
430 | uint8_t *data) | |
6b7c5b94 | 431 | { |
3abcdeda SP |
432 | struct be_adapter *adapter = netdev_priv(netdev); |
433 | int i, j; | |
434 | ||
6b7c5b94 SP |
435 | switch (stringset) { |
436 | case ETH_SS_STATS: | |
437 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { | |
438 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); | |
439 | data += ETH_GSTRING_LEN; | |
440 | } | |
3abcdeda SP |
441 | for (i = 0; i < adapter->num_rx_qs; i++) { |
442 | for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { | |
443 | sprintf(data, "rxq%d: %s", i, | |
444 | et_rx_stats[j].desc); | |
445 | data += ETH_GSTRING_LEN; | |
446 | } | |
447 | } | |
3c8def97 SP |
448 | for (i = 0; i < adapter->num_tx_qs; i++) { |
449 | for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) { | |
450 | sprintf(data, "txq%d: %s", i, | |
451 | et_tx_stats[j].desc); | |
452 | data += ETH_GSTRING_LEN; | |
453 | } | |
454 | } | |
6b7c5b94 | 455 | break; |
ff33a6e2 S |
456 | case ETH_SS_TEST: |
457 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { | |
458 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); | |
459 | data += ETH_GSTRING_LEN; | |
460 | } | |
461 | break; | |
710f3e59 SB |
462 | case ETH_SS_PRIV_FLAGS: |
463 | for (i = 0; i < ARRAY_SIZE(be_priv_flags); i++) | |
464 | strcpy(data + i * ETH_GSTRING_LEN, be_priv_flags[i]); | |
465 | break; | |
6b7c5b94 SP |
466 | } |
467 | } | |
468 | ||
15f0a394 | 469 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
6b7c5b94 | 470 | { |
3abcdeda SP |
471 | struct be_adapter *adapter = netdev_priv(netdev); |
472 | ||
15f0a394 | 473 | switch (stringset) { |
ff33a6e2 S |
474 | case ETH_SS_TEST: |
475 | return ETHTOOL_TESTS_NUM; | |
15f0a394 | 476 | case ETH_SS_STATS: |
3abcdeda | 477 | return ETHTOOL_STATS_NUM + |
3c8def97 SP |
478 | adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM + |
479 | adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM; | |
710f3e59 SB |
480 | case ETH_SS_PRIV_FLAGS: |
481 | return ARRAY_SIZE(be_priv_flags); | |
15f0a394 BH |
482 | default: |
483 | return -EINVAL; | |
484 | } | |
6b7c5b94 SP |
485 | } |
486 | ||
6809cee0 | 487 | static u32 be_get_port_type(struct be_adapter *adapter) |
42f11cf2 AK |
488 | { |
489 | u32 port; | |
490 | ||
6809cee0 | 491 | switch (adapter->phy.interface_type) { |
42f11cf2 AK |
492 | case PHY_TYPE_BASET_1GB: |
493 | case PHY_TYPE_BASEX_1GB: | |
494 | case PHY_TYPE_SGMII: | |
495 | port = PORT_TP; | |
496 | break; | |
497 | case PHY_TYPE_SFP_PLUS_10GB: | |
6809cee0 RN |
498 | if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE) |
499 | port = PORT_DA; | |
500 | else | |
501 | port = PORT_FIBRE; | |
502 | break; | |
503 | case PHY_TYPE_QSFP: | |
504 | if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE) | |
505 | port = PORT_DA; | |
506 | else | |
507 | port = PORT_FIBRE; | |
42f11cf2 AK |
508 | break; |
509 | case PHY_TYPE_XFP_10GB: | |
510 | case PHY_TYPE_SFP_1GB: | |
511 | port = PORT_FIBRE; | |
512 | break; | |
513 | case PHY_TYPE_BASET_10GB: | |
514 | port = PORT_TP; | |
515 | break; | |
516 | default: | |
517 | port = PORT_OTHER; | |
518 | } | |
519 | ||
520 | return port; | |
521 | } | |
522 | ||
6809cee0 | 523 | static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds) |
42f11cf2 AK |
524 | { |
525 | u32 val = 0; | |
526 | ||
6809cee0 | 527 | switch (adapter->phy.interface_type) { |
42f11cf2 AK |
528 | case PHY_TYPE_BASET_1GB: |
529 | case PHY_TYPE_BASEX_1GB: | |
530 | case PHY_TYPE_SGMII: | |
531 | val |= SUPPORTED_TP; | |
532 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) | |
533 | val |= SUPPORTED_1000baseT_Full; | |
534 | if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) | |
535 | val |= SUPPORTED_100baseT_Full; | |
536 | if (if_speeds & BE_SUPPORTED_SPEED_10MBPS) | |
537 | val |= SUPPORTED_10baseT_Full; | |
538 | break; | |
539 | case PHY_TYPE_KX4_10GB: | |
540 | val |= SUPPORTED_Backplane; | |
541 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) | |
542 | val |= SUPPORTED_1000baseKX_Full; | |
543 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) | |
544 | val |= SUPPORTED_10000baseKX4_Full; | |
545 | break; | |
d6b7a9b7 VV |
546 | case PHY_TYPE_KR2_20GB: |
547 | val |= SUPPORTED_Backplane; | |
548 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) | |
549 | val |= SUPPORTED_10000baseKR_Full; | |
550 | if (if_speeds & BE_SUPPORTED_SPEED_20GBPS) | |
551 | val |= SUPPORTED_20000baseKR2_Full; | |
552 | break; | |
42f11cf2 AK |
553 | case PHY_TYPE_KR_10GB: |
554 | val |= SUPPORTED_Backplane | | |
555 | SUPPORTED_10000baseKR_Full; | |
556 | break; | |
ca39076c KA |
557 | case PHY_TYPE_KR4_40GB: |
558 | val |= SUPPORTED_Backplane; | |
559 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) | |
560 | val |= SUPPORTED_10000baseKR_Full; | |
561 | if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) | |
562 | val |= SUPPORTED_40000baseKR4_Full; | |
563 | break; | |
6809cee0 RN |
564 | case PHY_TYPE_QSFP: |
565 | if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) { | |
566 | switch (adapter->phy.cable_type) { | |
567 | case QSFP_PLUS_CR4_CABLE: | |
568 | val |= SUPPORTED_40000baseCR4_Full; | |
569 | break; | |
570 | case QSFP_PLUS_LR4_CABLE: | |
571 | val |= SUPPORTED_40000baseLR4_Full; | |
572 | break; | |
573 | default: | |
574 | val |= SUPPORTED_40000baseSR4_Full; | |
575 | break; | |
576 | } | |
577 | } | |
df561f66 | 578 | fallthrough; |
42f11cf2 AK |
579 | case PHY_TYPE_SFP_PLUS_10GB: |
580 | case PHY_TYPE_XFP_10GB: | |
581 | case PHY_TYPE_SFP_1GB: | |
582 | val |= SUPPORTED_FIBRE; | |
583 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) | |
584 | val |= SUPPORTED_10000baseT_Full; | |
585 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) | |
586 | val |= SUPPORTED_1000baseT_Full; | |
587 | break; | |
588 | case PHY_TYPE_BASET_10GB: | |
589 | val |= SUPPORTED_TP; | |
590 | if (if_speeds & BE_SUPPORTED_SPEED_10GBPS) | |
591 | val |= SUPPORTED_10000baseT_Full; | |
592 | if (if_speeds & BE_SUPPORTED_SPEED_1GBPS) | |
593 | val |= SUPPORTED_1000baseT_Full; | |
594 | if (if_speeds & BE_SUPPORTED_SPEED_100MBPS) | |
595 | val |= SUPPORTED_100baseT_Full; | |
596 | break; | |
597 | default: | |
598 | val |= SUPPORTED_TP; | |
599 | } | |
600 | ||
601 | return val; | |
602 | } | |
603 | ||
42f11cf2 AK |
604 | bool be_pause_supported(struct be_adapter *adapter) |
605 | { | |
606 | return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB || | |
607 | adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ? | |
608 | false : true; | |
609 | } | |
610 | ||
fd90095d PR |
611 | static int be_get_link_ksettings(struct net_device *netdev, |
612 | struct ethtool_link_ksettings *cmd) | |
6b7c5b94 | 613 | { |
0388f251 | 614 | struct be_adapter *adapter = netdev_priv(netdev); |
b236916a | 615 | u8 link_status; |
323ff71e | 616 | u16 link_speed = 0; |
0dffc83e | 617 | int status; |
db15dfa9 PR |
618 | u32 auto_speeds; |
619 | u32 fixed_speeds; | |
fd90095d | 620 | u32 supported = 0, advertising = 0; |
0dffc83e | 621 | |
323ff71e SP |
622 | if (adapter->phy.link_speed < 0) { |
623 | status = be_cmd_link_status_query(adapter, &link_speed, | |
624 | &link_status, 0); | |
625 | if (!status) | |
626 | be_link_status_update(adapter, link_status); | |
fd90095d | 627 | cmd->base.speed = link_speed; |
42f11cf2 AK |
628 | |
629 | status = be_cmd_get_phy_info(adapter); | |
db15dfa9 | 630 | if (!status) { |
db15dfa9 PR |
631 | auto_speeds = adapter->phy.auto_speeds_supported; |
632 | fixed_speeds = adapter->phy.fixed_speeds_supported; | |
6809cee0 RN |
633 | |
634 | be_cmd_query_cable_type(adapter); | |
db15dfa9 | 635 | |
fd90095d | 636 | supported = |
6809cee0 | 637 | convert_to_et_setting(adapter, |
db15dfa9 PR |
638 | auto_speeds | |
639 | fixed_speeds); | |
fd90095d | 640 | advertising = |
6809cee0 | 641 | convert_to_et_setting(adapter, auto_speeds); |
db15dfa9 | 642 | |
fd90095d | 643 | cmd->base.port = be_get_port_type(adapter); |
db15dfa9 PR |
644 | |
645 | if (adapter->phy.auto_speeds_supported) { | |
fd90095d PR |
646 | supported |= SUPPORTED_Autoneg; |
647 | cmd->base.autoneg = AUTONEG_ENABLE; | |
648 | advertising |= ADVERTISED_Autoneg; | |
db15dfa9 | 649 | } |
42f11cf2 | 650 | |
fd90095d | 651 | supported |= SUPPORTED_Pause; |
db15dfa9 | 652 | if (be_pause_supported(adapter)) |
fd90095d | 653 | advertising |= ADVERTISED_Pause; |
db15dfa9 | 654 | } else { |
fd90095d PR |
655 | cmd->base.port = PORT_OTHER; |
656 | cmd->base.autoneg = AUTONEG_DISABLE; | |
0388f251 | 657 | } |
0dffc83e AK |
658 | |
659 | /* Save for future use */ | |
fd90095d PR |
660 | adapter->phy.link_speed = cmd->base.speed; |
661 | adapter->phy.port_type = cmd->base.port; | |
662 | adapter->phy.autoneg = cmd->base.autoneg; | |
663 | adapter->phy.advertising = advertising; | |
664 | adapter->phy.supported = supported; | |
0dffc83e | 665 | } else { |
fd90095d PR |
666 | cmd->base.speed = adapter->phy.link_speed; |
667 | cmd->base.port = adapter->phy.port_type; | |
668 | cmd->base.autoneg = adapter->phy.autoneg; | |
669 | advertising = adapter->phy.advertising; | |
670 | supported = adapter->phy.supported; | |
0388f251 | 671 | } |
0dffc83e | 672 | |
fd90095d PR |
673 | cmd->base.duplex = netif_carrier_ok(netdev) ? |
674 | DUPLEX_FULL : DUPLEX_UNKNOWN; | |
675 | cmd->base.phy_address = adapter->port_num; | |
676 | ||
677 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, | |
678 | supported); | |
679 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, | |
680 | advertising); | |
ee3cb629 | 681 | |
6b7c5b94 SP |
682 | return 0; |
683 | } | |
684 | ||
110b82bc | 685 | static void be_get_ringparam(struct net_device *netdev, |
74624944 HC |
686 | struct ethtool_ringparam *ring, |
687 | struct kernel_ethtool_ringparam *kernel_ring, | |
688 | struct netlink_ext_ack *extack) | |
6b7c5b94 SP |
689 | { |
690 | struct be_adapter *adapter = netdev_priv(netdev); | |
691 | ||
5f820b6c KA |
692 | ring->rx_max_pending = adapter->rx_obj[0].q.len; |
693 | ring->rx_pending = adapter->rx_obj[0].q.len; | |
694 | ring->tx_max_pending = adapter->tx_obj[0].q.len; | |
695 | ring->tx_pending = adapter->tx_obj[0].q.len; | |
6b7c5b94 SP |
696 | } |
697 | ||
698 | static void | |
699 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) | |
700 | { | |
701 | struct be_adapter *adapter = netdev_priv(netdev); | |
702 | ||
8788fdc2 | 703 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
42f11cf2 | 704 | ecmd->autoneg = adapter->phy.fc_autoneg; |
6b7c5b94 SP |
705 | } |
706 | ||
707 | static int | |
708 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) | |
709 | { | |
710 | struct be_adapter *adapter = netdev_priv(netdev); | |
711 | int status; | |
712 | ||
c871c5f2 | 713 | if (ecmd->autoneg != adapter->phy.fc_autoneg) |
6b7c5b94 SP |
714 | return -EINVAL; |
715 | ||
00d594c3 KA |
716 | status = be_cmd_set_flow_control(adapter, ecmd->tx_pause, |
717 | ecmd->rx_pause); | |
718 | if (status) { | |
50762667 | 719 | dev_warn(&adapter->pdev->dev, "Pause param set failed\n"); |
00d594c3 KA |
720 | return be_cmd_status(status); |
721 | } | |
6b7c5b94 | 722 | |
00d594c3 KA |
723 | adapter->tx_fc = ecmd->tx_pause; |
724 | adapter->rx_fc = ecmd->rx_pause; | |
725 | return 0; | |
6b7c5b94 SP |
726 | } |
727 | ||
05e4c6a3 SP |
728 | static int be_set_phys_id(struct net_device *netdev, |
729 | enum ethtool_phys_id_state state) | |
fad9ab2c SB |
730 | { |
731 | struct be_adapter *adapter = netdev_priv(netdev); | |
a5a773a5 | 732 | int status = 0; |
fad9ab2c | 733 | |
1a642469 | 734 | switch (state) { |
735 | case ETHTOOL_ID_ACTIVE: | |
a5a773a5 SR |
736 | status = be_cmd_get_beacon_state(adapter, adapter->hba_port_num, |
737 | &adapter->beacon_state); | |
738 | if (status) | |
739 | return be_cmd_status(status); | |
740 | return 1; /* cycle on/off once per second */ | |
fad9ab2c | 741 | |
1a642469 | 742 | case ETHTOOL_ID_ON: |
a5a773a5 SR |
743 | status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, |
744 | 0, 0, BEACON_STATE_ENABLED); | |
1a642469 | 745 | break; |
fad9ab2c | 746 | |
1a642469 | 747 | case ETHTOOL_ID_OFF: |
a5a773a5 SR |
748 | status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, |
749 | 0, 0, BEACON_STATE_DISABLED); | |
1a642469 | 750 | break; |
fad9ab2c | 751 | |
1a642469 | 752 | case ETHTOOL_ID_INACTIVE: |
a5a773a5 SR |
753 | status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, |
754 | 0, 0, adapter->beacon_state); | |
1a642469 | 755 | } |
fad9ab2c | 756 | |
a5a773a5 | 757 | return be_cmd_status(status); |
fad9ab2c SB |
758 | } |
759 | ||
5c510811 SK |
760 | static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump) |
761 | { | |
762 | struct be_adapter *adapter = netdev_priv(netdev); | |
763 | struct device *dev = &adapter->pdev->dev; | |
764 | int status; | |
765 | ||
f0613380 KA |
766 | if (!lancer_chip(adapter) || |
767 | !check_privilege(adapter, MAX_PRIVILEGES)) | |
5c510811 | 768 | return -EOPNOTSUPP; |
5c510811 SK |
769 | |
770 | switch (dump->flag) { | |
771 | case LANCER_INITIATE_FW_DUMP: | |
772 | status = lancer_initiate_dump(adapter); | |
773 | if (!status) | |
f0613380 | 774 | dev_info(dev, "FW dump initiated successfully\n"); |
5c510811 | 775 | break; |
f0613380 KA |
776 | case LANCER_DELETE_FW_DUMP: |
777 | status = lancer_delete_dump(adapter); | |
778 | if (!status) | |
779 | dev_info(dev, "FW dump deleted successfully\n"); | |
780 | break; | |
5c510811 SK |
781 | default: |
782 | dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag); | |
783 | return -EINVAL; | |
784 | } | |
785 | return status; | |
786 | } | |
dcf96f1f | 787 | |
05e4c6a3 | 788 | static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
71d8d1b5 AK |
789 | { |
790 | struct be_adapter *adapter = netdev_priv(netdev); | |
791 | ||
76a9e08e | 792 | if (adapter->wol_cap & BE_WOL_CAP) { |
4762f6ce | 793 | wol->supported |= WAKE_MAGIC; |
76a9e08e | 794 | if (adapter->wol_en) |
b424332d | 795 | wol->wolopts |= WAKE_MAGIC; |
76a9e08e | 796 | } else { |
71d8d1b5 | 797 | wol->wolopts = 0; |
76a9e08e | 798 | } |
71d8d1b5 | 799 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
71d8d1b5 AK |
800 | } |
801 | ||
05e4c6a3 | 802 | static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
71d8d1b5 AK |
803 | { |
804 | struct be_adapter *adapter = netdev_priv(netdev); | |
45f13df7 SB |
805 | struct device *dev = &adapter->pdev->dev; |
806 | struct be_dma_mem cmd; | |
807 | u8 mac[ETH_ALEN]; | |
808 | bool enable; | |
809 | int status; | |
71d8d1b5 AK |
810 | |
811 | if (wol->wolopts & ~WAKE_MAGIC) | |
4762f6ce AK |
812 | return -EOPNOTSUPP; |
813 | ||
76a9e08e | 814 | if (!(adapter->wol_cap & BE_WOL_CAP)) { |
4762f6ce AK |
815 | dev_warn(&adapter->pdev->dev, "WOL not supported\n"); |
816 | return -EOPNOTSUPP; | |
817 | } | |
71d8d1b5 | 818 | |
45f13df7 | 819 | cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config); |
750afb08 | 820 | cmd.va = dma_alloc_coherent(dev, cmd.size, &cmd.dma, GFP_KERNEL); |
45f13df7 SB |
821 | if (!cmd.va) |
822 | return -ENOMEM; | |
71d8d1b5 | 823 | |
45f13df7 SB |
824 | eth_zero_addr(mac); |
825 | ||
826 | enable = wol->wolopts & WAKE_MAGIC; | |
827 | if (enable) | |
828 | ether_addr_copy(mac, adapter->netdev->dev_addr); | |
829 | ||
830 | status = be_cmd_enable_magic_wol(adapter, mac, &cmd); | |
831 | if (status) { | |
832 | dev_err(dev, "Could not set Wake-on-lan mac address\n"); | |
833 | status = be_cmd_status(status); | |
834 | goto err; | |
835 | } | |
836 | ||
837 | pci_enable_wake(adapter->pdev, PCI_D3hot, enable); | |
838 | pci_enable_wake(adapter->pdev, PCI_D3cold, enable); | |
839 | ||
840 | adapter->wol_en = enable ? true : false; | |
841 | ||
842 | err: | |
843 | dma_free_coherent(dev, cmd.size, cmd.va, cmd.dma); | |
844 | return status; | |
71d8d1b5 AK |
845 | } |
846 | ||
05e4c6a3 | 847 | static int be_test_ddr_dma(struct be_adapter *adapter) |
ff33a6e2 S |
848 | { |
849 | int ret, i; | |
850 | struct be_dma_mem ddrdma_cmd; | |
215faf9c JP |
851 | static const u64 pattern[2] = { |
852 | 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL | |
853 | }; | |
ff33a6e2 S |
854 | |
855 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); | |
750afb08 LC |
856 | ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, |
857 | ddrdma_cmd.size, &ddrdma_cmd.dma, | |
858 | GFP_KERNEL); | |
d0320f75 | 859 | if (!ddrdma_cmd.va) |
ff33a6e2 | 860 | return -ENOMEM; |
ff33a6e2 S |
861 | |
862 | for (i = 0; i < 2; i++) { | |
863 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], | |
05e4c6a3 | 864 | 4096, &ddrdma_cmd); |
ff33a6e2 S |
865 | if (ret != 0) |
866 | goto err; | |
867 | } | |
868 | ||
869 | err: | |
2b7bcebf IV |
870 | dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, |
871 | ddrdma_cmd.dma); | |
0532d4e3 | 872 | return be_cmd_status(ret); |
ff33a6e2 S |
873 | } |
874 | ||
fced9999 | 875 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
05e4c6a3 | 876 | u64 *status) |
fced9999 | 877 | { |
9c855975 SR |
878 | int ret; |
879 | ||
880 | ret = be_cmd_set_loopback(adapter, adapter->hba_port_num, | |
881 | loopback_type, 1); | |
882 | if (ret) | |
883 | return ret; | |
884 | ||
9e1453c5 | 885 | *status = be_cmd_loopback_test(adapter, adapter->hba_port_num, |
05e4c6a3 | 886 | loopback_type, 1500, 2, 0xabc); |
9c855975 SR |
887 | |
888 | ret = be_cmd_set_loopback(adapter, adapter->hba_port_num, | |
889 | BE_NO_LOOPBACK, 1); | |
890 | if (ret) | |
891 | return ret; | |
892 | ||
fced9999 SB |
893 | return *status; |
894 | } | |
895 | ||
05e4c6a3 SP |
896 | static void be_self_test(struct net_device *netdev, struct ethtool_test *test, |
897 | u64 *data) | |
ff33a6e2 S |
898 | { |
899 | struct be_adapter *adapter = netdev_priv(netdev); | |
2e5db6eb | 900 | int status, cnt; |
323ff71e | 901 | u8 link_status = 0; |
ff33a6e2 | 902 | |
78d0b11d SR |
903 | if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) { |
904 | dev_err(&adapter->pdev->dev, "Self test not supported\n"); | |
905 | test->flags |= ETH_TEST_FL_FAILED; | |
906 | return; | |
907 | } | |
908 | ||
ff33a6e2 S |
909 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); |
910 | ||
2e5db6eb PO |
911 | /* check link status before offline tests */ |
912 | link_status = netif_carrier_ok(netdev); | |
913 | ||
ff33a6e2 | 914 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
05e4c6a3 | 915 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0) |
ff33a6e2 | 916 | test->flags |= ETH_TEST_FL_FAILED; |
5a8a1ab7 | 917 | |
05e4c6a3 | 918 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0) |
ff33a6e2 | 919 | test->flags |= ETH_TEST_FL_FAILED; |
5a8a1ab7 IV |
920 | |
921 | if (test->flags & ETH_TEST_FL_EXTERNAL_LB) { | |
922 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, | |
923 | &data[2]) != 0) | |
924 | test->flags |= ETH_TEST_FL_FAILED; | |
925 | test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE; | |
fced9999 | 926 | } |
8f47afe0 | 927 | } |
ff33a6e2 | 928 | |
a7047394 | 929 | if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) { |
8f47afe0 SB |
930 | data[3] = 1; |
931 | test->flags |= ETH_TEST_FL_FAILED; | |
ff33a6e2 S |
932 | } |
933 | ||
2e5db6eb PO |
934 | /* link status was down prior to test */ |
935 | if (!link_status) { | |
4ee77214 | 936 | test->flags |= ETH_TEST_FL_FAILED; |
4276e47e | 937 | data[4] = 1; |
2e5db6eb PO |
938 | return; |
939 | } | |
940 | ||
941 | for (cnt = 10; cnt; cnt--) { | |
942 | status = be_cmd_link_status_query(adapter, NULL, &link_status, | |
943 | 0); | |
944 | if (status) { | |
945 | test->flags |= ETH_TEST_FL_FAILED; | |
946 | data[4] = -1; | |
947 | break; | |
948 | } | |
949 | ||
950 | if (link_status) | |
951 | break; | |
952 | ||
953 | msleep_interruptible(500); | |
4276e47e | 954 | } |
ff33a6e2 S |
955 | } |
956 | ||
05e4c6a3 | 957 | static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) |
84517482 AK |
958 | { |
959 | struct be_adapter *adapter = netdev_priv(netdev); | |
84517482 | 960 | |
786f5281 | 961 | return be_load_fw(adapter, efl->data); |
84517482 AK |
962 | } |
963 | ||
fd7ff6f0 VD |
964 | static int |
965 | be_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump) | |
966 | { | |
967 | struct be_adapter *adapter = netdev_priv(netdev); | |
968 | ||
969 | if (!check_privilege(adapter, MAX_PRIVILEGES)) | |
970 | return -EOPNOTSUPP; | |
971 | ||
972 | dump->len = be_get_dump_len(adapter); | |
973 | dump->version = 1; | |
974 | dump->flag = 0x1; /* FW dump is enabled */ | |
975 | return 0; | |
976 | } | |
977 | ||
978 | static int | |
979 | be_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump, | |
980 | void *buf) | |
981 | { | |
982 | struct be_adapter *adapter = netdev_priv(netdev); | |
983 | int status; | |
984 | ||
985 | if (!check_privilege(adapter, MAX_PRIVILEGES)) | |
986 | return -EOPNOTSUPP; | |
987 | ||
988 | status = be_read_dump_data(adapter, dump->len, buf); | |
989 | return be_cmd_status(status); | |
990 | } | |
991 | ||
05e4c6a3 | 992 | static int be_get_eeprom_len(struct net_device *netdev) |
368c0ca2 | 993 | { |
af5875bd | 994 | struct be_adapter *adapter = netdev_priv(netdev); |
f25b119c PR |
995 | |
996 | if (!check_privilege(adapter, MAX_PRIVILEGES)) | |
997 | return 0; | |
998 | ||
af5875bd PR |
999 | if (lancer_chip(adapter)) { |
1000 | if (be_physfn(adapter)) | |
1001 | return lancer_cmd_get_file_len(adapter, | |
05e4c6a3 | 1002 | LANCER_VPD_PF_FILE); |
af5875bd PR |
1003 | else |
1004 | return lancer_cmd_get_file_len(adapter, | |
05e4c6a3 | 1005 | LANCER_VPD_VF_FILE); |
af5875bd PR |
1006 | } else { |
1007 | return BE_READ_SEEPROM_LEN; | |
1008 | } | |
368c0ca2 SB |
1009 | } |
1010 | ||
05e4c6a3 SP |
1011 | static int be_read_eeprom(struct net_device *netdev, |
1012 | struct ethtool_eeprom *eeprom, uint8_t *data) | |
368c0ca2 SB |
1013 | { |
1014 | struct be_adapter *adapter = netdev_priv(netdev); | |
1015 | struct be_dma_mem eeprom_cmd; | |
1016 | struct be_cmd_resp_seeprom_read *resp; | |
1017 | int status; | |
1018 | ||
1019 | if (!eeprom->len) | |
1020 | return -EINVAL; | |
1021 | ||
af5875bd PR |
1022 | if (lancer_chip(adapter)) { |
1023 | if (be_physfn(adapter)) | |
1024 | return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE, | |
05e4c6a3 | 1025 | eeprom->len, data); |
af5875bd PR |
1026 | else |
1027 | return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE, | |
05e4c6a3 | 1028 | eeprom->len, data); |
af5875bd PR |
1029 | } |
1030 | ||
368c0ca2 SB |
1031 | eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); |
1032 | ||
1033 | memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); | |
1034 | eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); | |
750afb08 LC |
1035 | eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, |
1036 | eeprom_cmd.size, &eeprom_cmd.dma, | |
1037 | GFP_KERNEL); | |
368c0ca2 | 1038 | |
d0320f75 | 1039 | if (!eeprom_cmd.va) |
368c0ca2 | 1040 | return -ENOMEM; |
368c0ca2 SB |
1041 | |
1042 | status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); | |
1043 | ||
1044 | if (!status) { | |
43d620c8 | 1045 | resp = eeprom_cmd.va; |
c0ad9845 | 1046 | memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); |
368c0ca2 | 1047 | } |
2b7bcebf IV |
1048 | dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, |
1049 | eeprom_cmd.dma); | |
368c0ca2 | 1050 | |
0532d4e3 | 1051 | return be_cmd_status(status); |
368c0ca2 SB |
1052 | } |
1053 | ||
941a77d5 SK |
1054 | static u32 be_get_msg_level(struct net_device *netdev) |
1055 | { | |
1056 | struct be_adapter *adapter = netdev_priv(netdev); | |
1057 | ||
941a77d5 SK |
1058 | return adapter->msg_enable; |
1059 | } | |
1060 | ||
941a77d5 SK |
1061 | static void be_set_msg_level(struct net_device *netdev, u32 level) |
1062 | { | |
1063 | struct be_adapter *adapter = netdev_priv(netdev); | |
1064 | ||
941a77d5 SK |
1065 | if (adapter->msg_enable == level) |
1066 | return; | |
1067 | ||
1068 | if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW)) | |
baaa08d1 VV |
1069 | if (BEx_chip(adapter)) |
1070 | be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ? | |
1071 | FW_LOG_LEVEL_DEFAULT : | |
1072 | FW_LOG_LEVEL_FATAL); | |
941a77d5 | 1073 | adapter->msg_enable = level; |
941a77d5 SK |
1074 | } |
1075 | ||
594ad54a SR |
1076 | static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type) |
1077 | { | |
1078 | u64 data = 0; | |
1079 | ||
1080 | switch (flow_type) { | |
1081 | case TCP_V4_FLOW: | |
e2557877 | 1082 | if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4) |
594ad54a | 1083 | data |= RXH_IP_DST | RXH_IP_SRC; |
e2557877 | 1084 | if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4) |
594ad54a SR |
1085 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
1086 | break; | |
1087 | case UDP_V4_FLOW: | |
e2557877 | 1088 | if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4) |
594ad54a | 1089 | data |= RXH_IP_DST | RXH_IP_SRC; |
e2557877 | 1090 | if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4) |
594ad54a SR |
1091 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
1092 | break; | |
1093 | case TCP_V6_FLOW: | |
e2557877 | 1094 | if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6) |
594ad54a | 1095 | data |= RXH_IP_DST | RXH_IP_SRC; |
e2557877 | 1096 | if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6) |
594ad54a SR |
1097 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
1098 | break; | |
1099 | case UDP_V6_FLOW: | |
e2557877 | 1100 | if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6) |
594ad54a | 1101 | data |= RXH_IP_DST | RXH_IP_SRC; |
e2557877 | 1102 | if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6) |
594ad54a SR |
1103 | data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
1104 | break; | |
1105 | } | |
1106 | ||
1107 | return data; | |
1108 | } | |
1109 | ||
1110 | static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, | |
05e4c6a3 | 1111 | u32 *rule_locs) |
594ad54a SR |
1112 | { |
1113 | struct be_adapter *adapter = netdev_priv(netdev); | |
1114 | ||
1115 | if (!be_multi_rxq(adapter)) { | |
1116 | dev_info(&adapter->pdev->dev, | |
1117 | "ethtool::get_rxnfc: RX flow hashing is disabled\n"); | |
1118 | return -EINVAL; | |
1119 | } | |
1120 | ||
1121 | switch (cmd->cmd) { | |
1122 | case ETHTOOL_GRXFH: | |
1123 | cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type); | |
1124 | break; | |
1125 | case ETHTOOL_GRXRINGS: | |
718f4a25 | 1126 | cmd->data = adapter->num_rx_qs; |
594ad54a SR |
1127 | break; |
1128 | default: | |
1129 | return -EINVAL; | |
1130 | } | |
1131 | ||
1132 | return 0; | |
1133 | } | |
1134 | ||
1135 | static int be_set_rss_hash_opts(struct be_adapter *adapter, | |
1136 | struct ethtool_rxnfc *cmd) | |
1137 | { | |
4114ec90 | 1138 | int status; |
e2557877 | 1139 | u32 rss_flags = adapter->rss_info.rss_flags; |
594ad54a SR |
1140 | |
1141 | if (cmd->data != L3_RSS_FLAGS && | |
1142 | cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS)) | |
1143 | return -EINVAL; | |
1144 | ||
1145 | switch (cmd->flow_type) { | |
1146 | case TCP_V4_FLOW: | |
1147 | if (cmd->data == L3_RSS_FLAGS) | |
1148 | rss_flags &= ~RSS_ENABLE_TCP_IPV4; | |
1149 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) | |
1150 | rss_flags |= RSS_ENABLE_IPV4 | | |
1151 | RSS_ENABLE_TCP_IPV4; | |
1152 | break; | |
1153 | case TCP_V6_FLOW: | |
1154 | if (cmd->data == L3_RSS_FLAGS) | |
1155 | rss_flags &= ~RSS_ENABLE_TCP_IPV6; | |
1156 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) | |
1157 | rss_flags |= RSS_ENABLE_IPV6 | | |
1158 | RSS_ENABLE_TCP_IPV6; | |
1159 | break; | |
1160 | case UDP_V4_FLOW: | |
1161 | if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && | |
1162 | BEx_chip(adapter)) | |
1163 | return -EINVAL; | |
1164 | ||
1165 | if (cmd->data == L3_RSS_FLAGS) | |
1166 | rss_flags &= ~RSS_ENABLE_UDP_IPV4; | |
1167 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) | |
1168 | rss_flags |= RSS_ENABLE_IPV4 | | |
1169 | RSS_ENABLE_UDP_IPV4; | |
1170 | break; | |
1171 | case UDP_V6_FLOW: | |
1172 | if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) && | |
1173 | BEx_chip(adapter)) | |
1174 | return -EINVAL; | |
1175 | ||
1176 | if (cmd->data == L3_RSS_FLAGS) | |
1177 | rss_flags &= ~RSS_ENABLE_UDP_IPV6; | |
1178 | else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) | |
1179 | rss_flags |= RSS_ENABLE_IPV6 | | |
1180 | RSS_ENABLE_UDP_IPV6; | |
1181 | break; | |
1182 | default: | |
1183 | return -EINVAL; | |
1184 | } | |
1185 | ||
e2557877 | 1186 | if (rss_flags == adapter->rss_info.rss_flags) |
4114ec90 | 1187 | return 0; |
e2557877 VD |
1188 | |
1189 | status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable, | |
d5d30981 IV |
1190 | rss_flags, RSS_INDIR_TABLE_LEN, |
1191 | adapter->rss_info.rss_hkey); | |
594ad54a | 1192 | if (!status) |
e2557877 | 1193 | adapter->rss_info.rss_flags = rss_flags; |
594ad54a | 1194 | |
0532d4e3 | 1195 | return be_cmd_status(status); |
594ad54a SR |
1196 | } |
1197 | ||
1198 | static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) | |
1199 | { | |
1200 | struct be_adapter *adapter = netdev_priv(netdev); | |
1201 | int status = 0; | |
1202 | ||
1203 | if (!be_multi_rxq(adapter)) { | |
1204 | dev_err(&adapter->pdev->dev, | |
1205 | "ethtool::set_rxnfc: RX flow hashing is disabled\n"); | |
1206 | return -EINVAL; | |
1207 | } | |
1208 | ||
1209 | switch (cmd->cmd) { | |
1210 | case ETHTOOL_SRXFH: | |
1211 | status = be_set_rss_hash_opts(adapter, cmd); | |
1212 | break; | |
1213 | default: | |
1214 | return -EINVAL; | |
1215 | } | |
1216 | ||
1217 | return status; | |
1218 | } | |
1219 | ||
68d7bdcb SP |
1220 | static void be_get_channels(struct net_device *netdev, |
1221 | struct ethtool_channels *ch) | |
1222 | { | |
1223 | struct be_adapter *adapter = netdev_priv(netdev); | |
e261768e | 1224 | u16 num_rx_irqs = max_t(u16, adapter->num_rss_qs, 1); |
68d7bdcb | 1225 | |
e261768e SP |
1226 | /* num_tx_qs is always same as the number of irqs used for TX */ |
1227 | ch->combined_count = min(adapter->num_tx_qs, num_rx_irqs); | |
1228 | ch->rx_count = num_rx_irqs - ch->combined_count; | |
1229 | ch->tx_count = adapter->num_tx_qs - ch->combined_count; | |
1230 | ||
1231 | ch->max_combined = be_max_qp_irqs(adapter); | |
1232 | /* The user must create atleast one combined channel */ | |
1233 | ch->max_rx = be_max_rx_irqs(adapter) - 1; | |
1234 | ch->max_tx = be_max_tx_irqs(adapter) - 1; | |
68d7bdcb SP |
1235 | } |
1236 | ||
1237 | static int be_set_channels(struct net_device *netdev, | |
1238 | struct ethtool_channels *ch) | |
1239 | { | |
1240 | struct be_adapter *adapter = netdev_priv(netdev); | |
0532d4e3 | 1241 | int status; |
68d7bdcb | 1242 | |
e261768e SP |
1243 | /* we support either only combined channels or a combination of |
1244 | * combined and either RX-only or TX-only channels. | |
1245 | */ | |
1246 | if (ch->other_count || !ch->combined_count || | |
1247 | (ch->rx_count && ch->tx_count)) | |
1248 | return -EINVAL; | |
1249 | ||
1250 | if (ch->combined_count > be_max_qp_irqs(adapter) || | |
1251 | (ch->rx_count && | |
1252 | (ch->rx_count + ch->combined_count) > be_max_rx_irqs(adapter)) || | |
1253 | (ch->tx_count && | |
1254 | (ch->tx_count + ch->combined_count) > be_max_tx_irqs(adapter))) | |
68d7bdcb SP |
1255 | return -EINVAL; |
1256 | ||
e261768e SP |
1257 | adapter->cfg_num_rx_irqs = ch->combined_count + ch->rx_count; |
1258 | adapter->cfg_num_tx_irqs = ch->combined_count + ch->tx_count; | |
68d7bdcb | 1259 | |
0532d4e3 KA |
1260 | status = be_update_queues(adapter); |
1261 | return be_cmd_status(status); | |
68d7bdcb SP |
1262 | } |
1263 | ||
e2557877 VD |
1264 | static u32 be_get_rxfh_indir_size(struct net_device *netdev) |
1265 | { | |
1266 | return RSS_INDIR_TABLE_LEN; | |
1267 | } | |
1268 | ||
1269 | static u32 be_get_rxfh_key_size(struct net_device *netdev) | |
1270 | { | |
1271 | return RSS_HASH_KEY_LEN; | |
1272 | } | |
1273 | ||
fb6e30a7 AZ |
1274 | static int be_get_rxfh(struct net_device *netdev, |
1275 | struct ethtool_rxfh_param *rxfh) | |
e2557877 VD |
1276 | { |
1277 | struct be_adapter *adapter = netdev_priv(netdev); | |
1278 | int i; | |
1279 | struct rss_info *rss = &adapter->rss_info; | |
1280 | ||
fb6e30a7 | 1281 | if (rxfh->indir) { |
e2557877 | 1282 | for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) |
fb6e30a7 | 1283 | rxfh->indir[i] = rss->rss_queue[i]; |
e2557877 VD |
1284 | } |
1285 | ||
fb6e30a7 AZ |
1286 | if (rxfh->key) |
1287 | memcpy(rxfh->key, rss->rss_hkey, RSS_HASH_KEY_LEN); | |
e2557877 | 1288 | |
fb6e30a7 | 1289 | rxfh->hfunc = ETH_RSS_HASH_TOP; |
892311f6 | 1290 | |
e2557877 VD |
1291 | return 0; |
1292 | } | |
1293 | ||
fb6e30a7 AZ |
1294 | static int be_set_rxfh(struct net_device *netdev, |
1295 | struct ethtool_rxfh_param *rxfh, | |
1296 | struct netlink_ext_ack *extack) | |
e2557877 VD |
1297 | { |
1298 | int rc = 0, i, j; | |
1299 | struct be_adapter *adapter = netdev_priv(netdev); | |
fb6e30a7 | 1300 | u8 *hkey = rxfh->key; |
e2557877 VD |
1301 | u8 rsstable[RSS_INDIR_TABLE_LEN]; |
1302 | ||
892311f6 | 1303 | /* We do not allow change in unsupported parameters */ |
fb6e30a7 AZ |
1304 | if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && |
1305 | rxfh->hfunc != ETH_RSS_HASH_TOP) | |
892311f6 EP |
1306 | return -EOPNOTSUPP; |
1307 | ||
fb6e30a7 | 1308 | if (rxfh->indir) { |
e2557877 | 1309 | struct be_rx_obj *rxo; |
03d28ffe | 1310 | |
e2557877 | 1311 | for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) { |
fb6e30a7 | 1312 | j = rxfh->indir[i]; |
e2557877 VD |
1313 | rxo = &adapter->rx_obj[j]; |
1314 | rsstable[i] = rxo->rss_id; | |
1315 | adapter->rss_info.rss_queue[i] = j; | |
1316 | } | |
1317 | } else { | |
1318 | memcpy(rsstable, adapter->rss_info.rsstable, | |
1319 | RSS_INDIR_TABLE_LEN); | |
1320 | } | |
1321 | ||
1322 | if (!hkey) | |
1323 | hkey = adapter->rss_info.rss_hkey; | |
1324 | ||
1325 | rc = be_cmd_rss_config(adapter, rsstable, | |
cd3307aa KA |
1326 | adapter->rss_info.rss_flags, |
1327 | RSS_INDIR_TABLE_LEN, hkey); | |
e2557877 VD |
1328 | if (rc) { |
1329 | adapter->rss_info.rss_flags = RSS_ENABLE_NONE; | |
1330 | return -EIO; | |
1331 | } | |
1332 | memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN); | |
1333 | memcpy(adapter->rss_info.rsstable, rsstable, | |
1334 | RSS_INDIR_TABLE_LEN); | |
1335 | return 0; | |
1336 | } | |
1337 | ||
e36edd9d ML |
1338 | static int be_get_module_info(struct net_device *netdev, |
1339 | struct ethtool_modinfo *modinfo) | |
1340 | { | |
1341 | struct be_adapter *adapter = netdev_priv(netdev); | |
1342 | u8 page_data[PAGE_DATA_LEN]; | |
1343 | int status; | |
1344 | ||
1345 | if (!check_privilege(adapter, MAX_PRIVILEGES)) | |
1346 | return -EOPNOTSUPP; | |
1347 | ||
1348 | status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, | |
d7241f67 | 1349 | 0, PAGE_DATA_LEN, page_data); |
e36edd9d ML |
1350 | if (!status) { |
1351 | if (!page_data[SFP_PLUS_SFF_8472_COMP]) { | |
1352 | modinfo->type = ETH_MODULE_SFF_8079; | |
1353 | modinfo->eeprom_len = PAGE_DATA_LEN; | |
1354 | } else { | |
1355 | modinfo->type = ETH_MODULE_SFF_8472; | |
1356 | modinfo->eeprom_len = 2 * PAGE_DATA_LEN; | |
1357 | } | |
1358 | } | |
1359 | return be_cmd_status(status); | |
1360 | } | |
1361 | ||
1362 | static int be_get_module_eeprom(struct net_device *netdev, | |
1363 | struct ethtool_eeprom *eeprom, u8 *data) | |
1364 | { | |
1365 | struct be_adapter *adapter = netdev_priv(netdev); | |
1366 | int status; | |
d7241f67 | 1367 | u32 begin, end; |
e36edd9d ML |
1368 | |
1369 | if (!check_privilege(adapter, MAX_PRIVILEGES)) | |
1370 | return -EOPNOTSUPP; | |
1371 | ||
d7241f67 HV |
1372 | begin = eeprom->offset; |
1373 | end = eeprom->offset + eeprom->len; | |
1374 | ||
1375 | if (begin < PAGE_DATA_LEN) { | |
1376 | status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0, begin, | |
1377 | min_t(u32, end, PAGE_DATA_LEN) - begin, | |
1378 | data); | |
1379 | if (status) | |
1380 | goto err; | |
1381 | ||
1382 | data += PAGE_DATA_LEN - begin; | |
1383 | begin = PAGE_DATA_LEN; | |
1384 | } | |
e36edd9d | 1385 | |
d7241f67 HV |
1386 | if (end > PAGE_DATA_LEN) { |
1387 | status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A2, | |
1388 | begin - PAGE_DATA_LEN, | |
1389 | end - begin, data); | |
e36edd9d ML |
1390 | if (status) |
1391 | goto err; | |
1392 | } | |
e36edd9d ML |
1393 | err: |
1394 | return be_cmd_status(status); | |
1395 | } | |
1396 | ||
710f3e59 SB |
1397 | static u32 be_get_priv_flags(struct net_device *netdev) |
1398 | { | |
1399 | struct be_adapter *adapter = netdev_priv(netdev); | |
1400 | ||
1401 | return adapter->priv_flags; | |
1402 | } | |
1403 | ||
1404 | static int be_set_priv_flags(struct net_device *netdev, u32 flags) | |
1405 | { | |
1406 | struct be_adapter *adapter = netdev_priv(netdev); | |
1407 | bool tpe_old = !!(adapter->priv_flags & BE_DISABLE_TPE_RECOVERY); | |
1408 | bool tpe_new = !!(flags & BE_DISABLE_TPE_RECOVERY); | |
1409 | ||
1410 | if (tpe_old != tpe_new) { | |
1411 | if (tpe_new) { | |
1412 | adapter->priv_flags |= BE_DISABLE_TPE_RECOVERY; | |
1413 | dev_info(&adapter->pdev->dev, | |
1414 | "HW error recovery is disabled\n"); | |
1415 | } else { | |
1416 | adapter->priv_flags &= ~BE_DISABLE_TPE_RECOVERY; | |
1417 | dev_info(&adapter->pdev->dev, | |
1418 | "HW error recovery is enabled\n"); | |
1419 | } | |
1420 | } | |
1421 | ||
1422 | return 0; | |
1423 | } | |
1424 | ||
0fc0b732 | 1425 | const struct ethtool_ops be_ethtool_ops = { |
8213f6c9 JK |
1426 | .supported_coalesce_params = ETHTOOL_COALESCE_USECS | |
1427 | ETHTOOL_COALESCE_USE_ADAPTIVE | | |
1428 | ETHTOOL_COALESCE_USECS_LOW_HIGH, | |
6b7c5b94 | 1429 | .get_drvinfo = be_get_drvinfo, |
71d8d1b5 AK |
1430 | .get_wol = be_get_wol, |
1431 | .set_wol = be_set_wol, | |
6b7c5b94 | 1432 | .get_link = ethtool_op_get_link, |
368c0ca2 SB |
1433 | .get_eeprom_len = be_get_eeprom_len, |
1434 | .get_eeprom = be_read_eeprom, | |
6b7c5b94 SP |
1435 | .get_coalesce = be_get_coalesce, |
1436 | .set_coalesce = be_set_coalesce, | |
1437 | .get_ringparam = be_get_ringparam, | |
1438 | .get_pauseparam = be_get_pauseparam, | |
1439 | .set_pauseparam = be_set_pauseparam, | |
710f3e59 SB |
1440 | .set_priv_flags = be_set_priv_flags, |
1441 | .get_priv_flags = be_get_priv_flags, | |
6b7c5b94 | 1442 | .get_strings = be_get_stat_strings, |
1a642469 | 1443 | .set_phys_id = be_set_phys_id, |
5c510811 | 1444 | .set_dump = be_set_dump, |
941a77d5 SK |
1445 | .get_msglevel = be_get_msg_level, |
1446 | .set_msglevel = be_set_msg_level, | |
15f0a394 | 1447 | .get_sset_count = be_get_sset_count, |
6b7c5b94 | 1448 | .get_ethtool_stats = be_get_ethtool_stats, |
84517482 | 1449 | .flash_device = be_do_flash, |
ff33a6e2 | 1450 | .self_test = be_self_test, |
594ad54a SR |
1451 | .get_rxnfc = be_get_rxnfc, |
1452 | .set_rxnfc = be_set_rxnfc, | |
e2557877 VD |
1453 | .get_rxfh_indir_size = be_get_rxfh_indir_size, |
1454 | .get_rxfh_key_size = be_get_rxfh_key_size, | |
1455 | .get_rxfh = be_get_rxfh, | |
1456 | .set_rxfh = be_set_rxfh, | |
fd7ff6f0 VD |
1457 | .get_dump_flag = be_get_dump_flag, |
1458 | .get_dump_data = be_get_dump_data, | |
68d7bdcb | 1459 | .get_channels = be_get_channels, |
e36edd9d ML |
1460 | .set_channels = be_set_channels, |
1461 | .get_module_info = be_get_module_info, | |
fd90095d PR |
1462 | .get_module_eeprom = be_get_module_eeprom, |
1463 | .get_link_ksettings = be_get_link_ksettings, | |
6b7c5b94 | 1464 | }; |