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