Commit | Line | Data |
---|---|---|
8ceee660 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | |
3 | * Copyright 2005-2006 Fen Systems Ltd. | |
906bb26c | 4 | * Copyright 2006-2009 Solarflare Communications Inc. |
8ceee660 BH |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License version 2 as published | |
8 | * by the Free Software Foundation, incorporated herein by reference. | |
9 | */ | |
10 | ||
11 | #include <linux/netdevice.h> | |
12 | #include <linux/ethtool.h> | |
13 | #include <linux/rtnetlink.h> | |
14 | #include "net_driver.h" | |
04cc8cac | 15 | #include "workarounds.h" |
3273c2e8 | 16 | #include "selftest.h" |
8ceee660 | 17 | #include "efx.h" |
b4187e42 | 18 | #include "filter.h" |
744093c9 | 19 | #include "nic.h" |
8ceee660 | 20 | |
8ceee660 BH |
21 | struct ethtool_string { |
22 | char name[ETH_GSTRING_LEN]; | |
23 | }; | |
24 | ||
25 | struct efx_ethtool_stat { | |
26 | const char *name; | |
27 | enum { | |
28 | EFX_ETHTOOL_STAT_SOURCE_mac_stats, | |
29 | EFX_ETHTOOL_STAT_SOURCE_nic, | |
30 | EFX_ETHTOOL_STAT_SOURCE_channel | |
31 | } source; | |
32 | unsigned offset; | |
33 | u64(*get_stat) (void *field); /* Reader function */ | |
34 | }; | |
35 | ||
36 | /* Initialiser for a struct #efx_ethtool_stat with type-checking */ | |
37 | #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ | |
38 | get_stat_function) { \ | |
39 | .name = #stat_name, \ | |
40 | .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ | |
41 | .offset = ((((field_type *) 0) == \ | |
42 | &((struct efx_##source_name *)0)->field) ? \ | |
43 | offsetof(struct efx_##source_name, field) : \ | |
44 | offsetof(struct efx_##source_name, field)), \ | |
45 | .get_stat = get_stat_function, \ | |
46 | } | |
47 | ||
48 | static u64 efx_get_uint_stat(void *field) | |
49 | { | |
50 | return *(unsigned int *)field; | |
51 | } | |
52 | ||
53 | static u64 efx_get_ulong_stat(void *field) | |
54 | { | |
55 | return *(unsigned long *)field; | |
56 | } | |
57 | ||
58 | static u64 efx_get_u64_stat(void *field) | |
59 | { | |
60 | return *(u64 *) field; | |
61 | } | |
62 | ||
63 | static u64 efx_get_atomic_stat(void *field) | |
64 | { | |
65 | return atomic_read((atomic_t *) field); | |
66 | } | |
67 | ||
68 | #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \ | |
69 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ | |
70 | unsigned long, efx_get_ulong_stat) | |
71 | ||
72 | #define EFX_ETHTOOL_U64_MAC_STAT(field) \ | |
73 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ | |
74 | u64, efx_get_u64_stat) | |
75 | ||
76 | #define EFX_ETHTOOL_UINT_NIC_STAT(name) \ | |
77 | EFX_ETHTOOL_STAT(name, nic, n_##name, \ | |
78 | unsigned int, efx_get_uint_stat) | |
79 | ||
80 | #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ | |
81 | EFX_ETHTOOL_STAT(field, nic, field, \ | |
82 | atomic_t, efx_get_atomic_stat) | |
83 | ||
84 | #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ | |
85 | EFX_ETHTOOL_STAT(field, channel, n_##field, \ | |
86 | unsigned int, efx_get_uint_stat) | |
87 | ||
88 | static struct efx_ethtool_stat efx_ethtool_stats[] = { | |
89 | EFX_ETHTOOL_U64_MAC_STAT(tx_bytes), | |
90 | EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes), | |
91 | EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes), | |
92 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets), | |
93 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad), | |
94 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause), | |
95 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_control), | |
96 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast), | |
97 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast), | |
98 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast), | |
99 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64), | |
100 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_64), | |
101 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127), | |
102 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255), | |
103 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511), | |
104 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023), | |
105 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx), | |
106 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo), | |
107 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo), | |
108 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision), | |
109 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision), | |
110 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision), | |
111 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision), | |
112 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred), | |
113 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision), | |
114 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred), | |
115 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp), | |
116 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error), | |
117 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error), | |
118 | EFX_ETHTOOL_U64_MAC_STAT(rx_bytes), | |
119 | EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes), | |
120 | EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes), | |
121 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets), | |
122 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_good), | |
123 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad), | |
124 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause), | |
125 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_control), | |
126 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast), | |
127 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast), | |
128 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast), | |
129 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64), | |
130 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_64), | |
131 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127), | |
132 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255), | |
133 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511), | |
134 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023), | |
135 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx), | |
136 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo), | |
137 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo), | |
138 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64), | |
139 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx), | |
140 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo), | |
141 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo), | |
142 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow), | |
143 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed), | |
144 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier), | |
145 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error), | |
146 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error), | |
147 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error), | |
148 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error), | |
149 | EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt), | |
150 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), | |
151 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), | |
152 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), | |
153 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), | |
c1ac403b | 154 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
8ceee660 BH |
155 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
156 | }; | |
157 | ||
158 | /* Number of ethtool statistics */ | |
159 | #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats) | |
160 | ||
4a5b504d | 161 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
4a5b504d | 162 | |
8ceee660 BH |
163 | /************************************************************************** |
164 | * | |
165 | * Ethtool operations | |
166 | * | |
167 | ************************************************************************** | |
168 | */ | |
169 | ||
170 | /* Identify device by flashing LEDs */ | |
65f667fb | 171 | static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count) |
8ceee660 | 172 | { |
767e468c | 173 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 174 | |
398468ed | 175 | do { |
06629f07 | 176 | efx->type->set_id_led(efx, EFX_LED_ON); |
398468ed BH |
177 | schedule_timeout_interruptible(HZ / 2); |
178 | ||
06629f07 | 179 | efx->type->set_id_led(efx, EFX_LED_OFF); |
398468ed BH |
180 | schedule_timeout_interruptible(HZ / 2); |
181 | } while (!signal_pending(current) && --count != 0); | |
182 | ||
06629f07 | 183 | efx->type->set_id_led(efx, EFX_LED_DEFAULT); |
8ceee660 BH |
184 | return 0; |
185 | } | |
186 | ||
187 | /* This must be called with rtnl_lock held. */ | |
d215697f | 188 | static int efx_ethtool_get_settings(struct net_device *net_dev, |
189 | struct ethtool_cmd *ecmd) | |
8ceee660 | 190 | { |
767e468c | 191 | struct efx_nic *efx = netdev_priv(net_dev); |
d3245b28 | 192 | struct efx_link_state *link_state = &efx->link_state; |
8ceee660 BH |
193 | |
194 | mutex_lock(&efx->mac_lock); | |
177dfcd8 | 195 | efx->phy_op->get_settings(efx, ecmd); |
8ceee660 BH |
196 | mutex_unlock(&efx->mac_lock); |
197 | ||
754c653a | 198 | /* GMAC does not support 1000Mbps HD */ |
177dfcd8 | 199 | ecmd->supported &= ~SUPPORTED_1000baseT_Half; |
d3245b28 BH |
200 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
201 | ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; | |
202 | ||
203 | if (LOOPBACK_INTERNAL(efx)) { | |
204 | ecmd->speed = link_state->speed; | |
205 | ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; | |
206 | } | |
177dfcd8 BH |
207 | |
208 | return 0; | |
8ceee660 BH |
209 | } |
210 | ||
211 | /* This must be called with rtnl_lock held. */ | |
d215697f | 212 | static int efx_ethtool_set_settings(struct net_device *net_dev, |
213 | struct ethtool_cmd *ecmd) | |
8ceee660 | 214 | { |
767e468c | 215 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
216 | int rc; |
217 | ||
754c653a | 218 | /* GMAC does not support 1000Mbps HD */ |
177dfcd8 | 219 | if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) { |
62776d03 BH |
220 | netif_dbg(efx, drv, efx->net_dev, |
221 | "rejecting unsupported 1000Mbps HD setting\n"); | |
177dfcd8 BH |
222 | return -EINVAL; |
223 | } | |
224 | ||
8ceee660 | 225 | mutex_lock(&efx->mac_lock); |
177dfcd8 | 226 | rc = efx->phy_op->set_settings(efx, ecmd); |
8ceee660 | 227 | mutex_unlock(&efx->mac_lock); |
8ceee660 BH |
228 | return rc; |
229 | } | |
230 | ||
231 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, | |
232 | struct ethtool_drvinfo *info) | |
233 | { | |
767e468c | 234 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 235 | |
c5d5f5fd | 236 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
8ceee660 | 237 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
8880f4ec BH |
238 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
239 | siena_print_fwver(efx, info->fw_version, | |
240 | sizeof(info->fw_version)); | |
8ceee660 BH |
241 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
242 | } | |
243 | ||
5b98c1bf BH |
244 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
245 | { | |
246 | return efx_nic_get_regs_len(netdev_priv(net_dev)); | |
247 | } | |
248 | ||
249 | static void efx_ethtool_get_regs(struct net_device *net_dev, | |
250 | struct ethtool_regs *regs, void *buf) | |
251 | { | |
252 | struct efx_nic *efx = netdev_priv(net_dev); | |
253 | ||
254 | regs->version = efx->type->revision; | |
255 | efx_nic_get_regs(efx, buf); | |
256 | } | |
257 | ||
62776d03 BH |
258 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
259 | { | |
260 | struct efx_nic *efx = netdev_priv(net_dev); | |
261 | return efx->msg_enable; | |
262 | } | |
263 | ||
264 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) | |
265 | { | |
266 | struct efx_nic *efx = netdev_priv(net_dev); | |
267 | efx->msg_enable = msg_enable; | |
268 | } | |
269 | ||
3273c2e8 BH |
270 | /** |
271 | * efx_fill_test - fill in an individual self-test entry | |
272 | * @test_index: Index of the test | |
273 | * @strings: Ethtool strings, or %NULL | |
274 | * @data: Ethtool test results, or %NULL | |
275 | * @test: Pointer to test result (used only if data != %NULL) | |
740ced99 BH |
276 | * @unit_format: Unit name format (e.g. "chan\%d") |
277 | * @unit_id: Unit id (e.g. 0 for "chan0") | |
3273c2e8 | 278 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
740ced99 | 279 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
3273c2e8 BH |
280 | * |
281 | * Fill in an individual self-test entry. | |
282 | */ | |
283 | static void efx_fill_test(unsigned int test_index, | |
284 | struct ethtool_string *strings, u64 *data, | |
285 | int *test, const char *unit_format, int unit_id, | |
286 | const char *test_format, const char *test_id) | |
287 | { | |
288 | struct ethtool_string unit_str, test_str; | |
289 | ||
290 | /* Fill data value, if applicable */ | |
291 | if (data) | |
292 | data[test_index] = *test; | |
293 | ||
294 | /* Fill string, if applicable */ | |
295 | if (strings) { | |
11e66966 BH |
296 | if (strchr(unit_format, '%')) |
297 | snprintf(unit_str.name, sizeof(unit_str.name), | |
298 | unit_format, unit_id); | |
299 | else | |
300 | strcpy(unit_str.name, unit_format); | |
3273c2e8 BH |
301 | snprintf(test_str.name, sizeof(test_str.name), |
302 | test_format, test_id); | |
303 | snprintf(strings[test_index].name, | |
304 | sizeof(strings[test_index].name), | |
740ced99 | 305 | "%-6s %-24s", unit_str.name, test_str.name); |
3273c2e8 BH |
306 | } |
307 | } | |
308 | ||
740ced99 | 309 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
3273c2e8 BH |
310 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
311 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue | |
312 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ | |
c459302d | 313 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
3273c2e8 BH |
314 | |
315 | /** | |
316 | * efx_fill_loopback_test - fill in a block of loopback self-test entries | |
317 | * @efx: Efx NIC | |
318 | * @lb_tests: Efx loopback self-test results structure | |
319 | * @mode: Loopback test mode | |
320 | * @test_index: Starting index of the test | |
321 | * @strings: Ethtool strings, or %NULL | |
322 | * @data: Ethtool test results, or %NULL | |
323 | */ | |
324 | static int efx_fill_loopback_test(struct efx_nic *efx, | |
325 | struct efx_loopback_self_tests *lb_tests, | |
326 | enum efx_loopback_mode mode, | |
327 | unsigned int test_index, | |
328 | struct ethtool_string *strings, u64 *data) | |
329 | { | |
f7d12cdc | 330 | struct efx_channel *channel = efx_get_channel(efx, 0); |
3273c2e8 BH |
331 | struct efx_tx_queue *tx_queue; |
332 | ||
f7d12cdc | 333 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
3273c2e8 BH |
334 | efx_fill_test(test_index++, strings, data, |
335 | &lb_tests->tx_sent[tx_queue->queue], | |
336 | EFX_TX_QUEUE_NAME(tx_queue), | |
337 | EFX_LOOPBACK_NAME(mode, "tx_sent")); | |
338 | efx_fill_test(test_index++, strings, data, | |
339 | &lb_tests->tx_done[tx_queue->queue], | |
340 | EFX_TX_QUEUE_NAME(tx_queue), | |
341 | EFX_LOOPBACK_NAME(mode, "tx_done")); | |
342 | } | |
343 | efx_fill_test(test_index++, strings, data, | |
344 | &lb_tests->rx_good, | |
11e66966 | 345 | "rx", 0, |
3273c2e8 BH |
346 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
347 | efx_fill_test(test_index++, strings, data, | |
348 | &lb_tests->rx_bad, | |
11e66966 | 349 | "rx", 0, |
3273c2e8 BH |
350 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
351 | ||
352 | return test_index; | |
353 | } | |
354 | ||
355 | /** | |
356 | * efx_ethtool_fill_self_tests - get self-test details | |
357 | * @efx: Efx NIC | |
358 | * @tests: Efx self-test results structure, or %NULL | |
359 | * @strings: Ethtool strings, or %NULL | |
360 | * @data: Ethtool test results, or %NULL | |
361 | */ | |
362 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, | |
363 | struct efx_self_tests *tests, | |
364 | struct ethtool_string *strings, | |
365 | u64 *data) | |
366 | { | |
367 | struct efx_channel *channel; | |
1796721a | 368 | unsigned int n = 0, i; |
3273c2e8 BH |
369 | enum efx_loopback_mode mode; |
370 | ||
4f16c073 BH |
371 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
372 | "phy", 0, "alive", NULL); | |
8c8661e4 BH |
373 | efx_fill_test(n++, strings, data, &tests->nvram, |
374 | "core", 0, "nvram", NULL); | |
3273c2e8 BH |
375 | efx_fill_test(n++, strings, data, &tests->interrupt, |
376 | "core", 0, "interrupt", NULL); | |
377 | ||
378 | /* Event queues */ | |
379 | efx_for_each_channel(channel, efx) { | |
380 | efx_fill_test(n++, strings, data, | |
381 | &tests->eventq_dma[channel->channel], | |
382 | EFX_CHANNEL_NAME(channel), | |
383 | "eventq.dma", NULL); | |
384 | efx_fill_test(n++, strings, data, | |
385 | &tests->eventq_int[channel->channel], | |
386 | EFX_CHANNEL_NAME(channel), | |
387 | "eventq.int", NULL); | |
388 | efx_fill_test(n++, strings, data, | |
389 | &tests->eventq_poll[channel->channel], | |
390 | EFX_CHANNEL_NAME(channel), | |
391 | "eventq.poll", NULL); | |
392 | } | |
393 | ||
8c8661e4 BH |
394 | efx_fill_test(n++, strings, data, &tests->registers, |
395 | "core", 0, "registers", NULL); | |
1796721a | 396 | |
c1c4f453 BH |
397 | if (efx->phy_op->run_tests != NULL) { |
398 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); | |
399 | ||
400 | for (i = 0; true; ++i) { | |
401 | const char *name; | |
402 | ||
403 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); | |
404 | name = efx->phy_op->test_name(efx, i); | |
405 | if (name == NULL) | |
406 | break; | |
407 | ||
4f16c073 | 408 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
c1c4f453 BH |
409 | "phy", 0, name, NULL); |
410 | } | |
411 | } | |
3273c2e8 BH |
412 | |
413 | /* Loopback tests */ | |
8c8661e4 | 414 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
3273c2e8 BH |
415 | if (!(efx->loopback_modes & (1 << mode))) |
416 | continue; | |
417 | n = efx_fill_loopback_test(efx, | |
418 | &tests->loopback[mode], mode, n, | |
419 | strings, data); | |
420 | } | |
421 | ||
422 | return n; | |
423 | } | |
424 | ||
3594e131 BH |
425 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
426 | int string_set) | |
8ceee660 | 427 | { |
3594e131 BH |
428 | switch (string_set) { |
429 | case ETH_SS_STATS: | |
430 | return EFX_ETHTOOL_NUM_STATS; | |
431 | case ETH_SS_TEST: | |
432 | return efx_ethtool_fill_self_tests(netdev_priv(net_dev), | |
433 | NULL, NULL, NULL); | |
434 | default: | |
435 | return -EINVAL; | |
436 | } | |
3273c2e8 BH |
437 | } |
438 | ||
8ceee660 BH |
439 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
440 | u32 string_set, u8 *strings) | |
441 | { | |
767e468c | 442 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
443 | struct ethtool_string *ethtool_strings = |
444 | (struct ethtool_string *)strings; | |
445 | int i; | |
446 | ||
3273c2e8 BH |
447 | switch (string_set) { |
448 | case ETH_SS_STATS: | |
8ceee660 BH |
449 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) |
450 | strncpy(ethtool_strings[i].name, | |
451 | efx_ethtool_stats[i].name, | |
452 | sizeof(ethtool_strings[i].name)); | |
3273c2e8 BH |
453 | break; |
454 | case ETH_SS_TEST: | |
455 | efx_ethtool_fill_self_tests(efx, NULL, | |
456 | ethtool_strings, NULL); | |
457 | break; | |
458 | default: | |
459 | /* No other string sets */ | |
460 | break; | |
461 | } | |
8ceee660 BH |
462 | } |
463 | ||
464 | static void efx_ethtool_get_stats(struct net_device *net_dev, | |
465 | struct ethtool_stats *stats, | |
466 | u64 *data) | |
467 | { | |
767e468c | 468 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
469 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
470 | struct efx_ethtool_stat *stat; | |
471 | struct efx_channel *channel; | |
28172739 | 472 | struct rtnl_link_stats64 temp; |
8ceee660 BH |
473 | int i; |
474 | ||
475 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); | |
476 | ||
477 | /* Update MAC and NIC statistics */ | |
28172739 | 478 | dev_get_stats(net_dev, &temp); |
8ceee660 BH |
479 | |
480 | /* Fill detailed statistics buffer */ | |
481 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { | |
482 | stat = &efx_ethtool_stats[i]; | |
483 | switch (stat->source) { | |
484 | case EFX_ETHTOOL_STAT_SOURCE_mac_stats: | |
485 | data[i] = stat->get_stat((void *)mac_stats + | |
486 | stat->offset); | |
487 | break; | |
488 | case EFX_ETHTOOL_STAT_SOURCE_nic: | |
489 | data[i] = stat->get_stat((void *)efx + stat->offset); | |
490 | break; | |
491 | case EFX_ETHTOOL_STAT_SOURCE_channel: | |
492 | data[i] = 0; | |
493 | efx_for_each_channel(channel, efx) | |
494 | data[i] += stat->get_stat((void *)channel + | |
495 | stat->offset); | |
496 | break; | |
497 | } | |
498 | } | |
499 | } | |
500 | ||
738a8f4b BH |
501 | static int efx_ethtool_set_tso(struct net_device *net_dev, u32 enable) |
502 | { | |
503 | struct efx_nic *efx __attribute__ ((unused)) = netdev_priv(net_dev); | |
504 | unsigned long features; | |
505 | ||
506 | features = NETIF_F_TSO; | |
507 | if (efx->type->offload_features & NETIF_F_V6_CSUM) | |
508 | features |= NETIF_F_TSO6; | |
509 | ||
510 | if (enable) | |
511 | net_dev->features |= features; | |
512 | else | |
513 | net_dev->features &= ~features; | |
514 | ||
515 | return 0; | |
516 | } | |
517 | ||
c383b537 BH |
518 | static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable) |
519 | { | |
520 | struct efx_nic *efx = netdev_priv(net_dev); | |
521 | unsigned long features = efx->type->offload_features & NETIF_F_ALL_CSUM; | |
522 | ||
523 | if (enable) | |
524 | net_dev->features |= features; | |
525 | else | |
526 | net_dev->features &= ~features; | |
527 | ||
528 | return 0; | |
529 | } | |
530 | ||
8ceee660 BH |
531 | static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable) |
532 | { | |
767e468c | 533 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
534 | |
535 | /* No way to stop the hardware doing the checks; we just | |
536 | * ignore the result. | |
537 | */ | |
dc8cfa55 | 538 | efx->rx_checksum_enabled = !!enable; |
8ceee660 BH |
539 | |
540 | return 0; | |
541 | } | |
542 | ||
543 | static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev) | |
544 | { | |
767e468c | 545 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
546 | |
547 | return efx->rx_checksum_enabled; | |
548 | } | |
549 | ||
39c9cf07 BH |
550 | static int efx_ethtool_set_flags(struct net_device *net_dev, u32 data) |
551 | { | |
552 | struct efx_nic *efx = netdev_priv(net_dev); | |
b4187e42 BH |
553 | u32 supported = (efx->type->offload_features & |
554 | (ETH_FLAG_RXHASH | ETH_FLAG_NTUPLE)); | |
555 | int rc; | |
556 | ||
557 | rc = ethtool_op_set_flags(net_dev, data, supported); | |
558 | if (rc) | |
559 | return rc; | |
560 | ||
8891681a BH |
561 | if (!(data & ETH_FLAG_NTUPLE)) |
562 | efx_filter_clear_rx(efx, EFX_FILTER_PRI_MANUAL); | |
39c9cf07 | 563 | |
b4187e42 | 564 | return 0; |
39c9cf07 BH |
565 | } |
566 | ||
3273c2e8 BH |
567 | static void efx_ethtool_self_test(struct net_device *net_dev, |
568 | struct ethtool_test *test, u64 *data) | |
569 | { | |
767e468c | 570 | struct efx_nic *efx = netdev_priv(net_dev); |
3273c2e8 | 571 | struct efx_self_tests efx_tests; |
2ef3068e | 572 | int already_up; |
3273c2e8 BH |
573 | int rc; |
574 | ||
575 | ASSERT_RTNL(); | |
576 | if (efx->state != STATE_RUNNING) { | |
577 | rc = -EIO; | |
578 | goto fail1; | |
579 | } | |
580 | ||
ac33ac61 BH |
581 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
582 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
583 | ||
3273c2e8 BH |
584 | /* We need rx buffers and interrupts. */ |
585 | already_up = (efx->net_dev->flags & IFF_UP); | |
586 | if (!already_up) { | |
587 | rc = dev_open(efx->net_dev); | |
588 | if (rc) { | |
62776d03 BH |
589 | netif_err(efx, drv, efx->net_dev, |
590 | "failed opening device.\n"); | |
3273c2e8 BH |
591 | goto fail2; |
592 | } | |
593 | } | |
594 | ||
595 | memset(&efx_tests, 0, sizeof(efx_tests)); | |
3273c2e8 | 596 | |
2ef3068e | 597 | rc = efx_selftest(efx, &efx_tests, test->flags); |
3273c2e8 | 598 | |
3273c2e8 BH |
599 | if (!already_up) |
600 | dev_close(efx->net_dev); | |
601 | ||
ac33ac61 BH |
602 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
603 | rc == 0 ? "passed" : "failed", | |
604 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
3273c2e8 BH |
605 | |
606 | fail2: | |
607 | fail1: | |
608 | /* Fill ethtool results structures */ | |
609 | efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data); | |
610 | if (rc) | |
611 | test->flags |= ETH_TEST_FL_FAILED; | |
612 | } | |
613 | ||
8ceee660 BH |
614 | /* Restart autonegotiation */ |
615 | static int efx_ethtool_nway_reset(struct net_device *net_dev) | |
616 | { | |
767e468c | 617 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 618 | |
68e7f45e | 619 | return mdio45_nway_restart(&efx->mdio); |
8ceee660 BH |
620 | } |
621 | ||
622 | static u32 efx_ethtool_get_link(struct net_device *net_dev) | |
623 | { | |
767e468c | 624 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 625 | |
eb50c0d6 | 626 | return efx->link_state.up; |
8ceee660 BH |
627 | } |
628 | ||
629 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, | |
630 | struct ethtool_coalesce *coalesce) | |
631 | { | |
767e468c | 632 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
633 | struct efx_channel *channel; |
634 | ||
635 | memset(coalesce, 0, sizeof(*coalesce)); | |
636 | ||
637 | /* Find lowest IRQ moderation across all used TX queues */ | |
638 | coalesce->tx_coalesce_usecs_irq = ~((u32) 0); | |
f7d12cdc BH |
639 | efx_for_each_channel(channel, efx) { |
640 | if (!efx_channel_get_tx_queue(channel, 0)) | |
641 | continue; | |
8ceee660 | 642 | if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) { |
a4900ac9 | 643 | if (channel->channel < efx->n_rx_channels) |
8ceee660 BH |
644 | coalesce->tx_coalesce_usecs_irq = |
645 | channel->irq_moderation; | |
646 | else | |
647 | coalesce->tx_coalesce_usecs_irq = 0; | |
648 | } | |
649 | } | |
650 | ||
6fb70fd1 BH |
651 | coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive; |
652 | coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation; | |
8ceee660 | 653 | |
152b6a62 BH |
654 | coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION; |
655 | coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION; | |
0d86ebd8 | 656 | |
8ceee660 BH |
657 | return 0; |
658 | } | |
659 | ||
660 | /* Set coalescing parameters | |
661 | * The difficulties occur for shared channels | |
662 | */ | |
663 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, | |
664 | struct ethtool_coalesce *coalesce) | |
665 | { | |
767e468c | 666 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 667 | struct efx_channel *channel; |
6fb70fd1 | 668 | unsigned tx_usecs, rx_usecs, adaptive; |
8ceee660 | 669 | |
6fb70fd1 | 670 | if (coalesce->use_adaptive_tx_coalesce) |
8ceee660 BH |
671 | return -EOPNOTSUPP; |
672 | ||
673 | if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) { | |
62776d03 BH |
674 | netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. " |
675 | "Only rx/tx_coalesce_usecs_irq are supported\n"); | |
8ceee660 BH |
676 | return -EOPNOTSUPP; |
677 | } | |
678 | ||
679 | rx_usecs = coalesce->rx_coalesce_usecs_irq; | |
680 | tx_usecs = coalesce->tx_coalesce_usecs_irq; | |
6fb70fd1 | 681 | adaptive = coalesce->use_adaptive_rx_coalesce; |
8ceee660 BH |
682 | |
683 | /* If the channel is shared only allow RX parameters to be set */ | |
f7d12cdc BH |
684 | efx_for_each_channel(channel, efx) { |
685 | if (efx_channel_get_rx_queue(channel) && | |
686 | efx_channel_get_tx_queue(channel, 0) && | |
8ceee660 | 687 | tx_usecs) { |
62776d03 BH |
688 | netif_err(efx, drv, efx->net_dev, "Channel is shared. " |
689 | "Only RX coalescing may be set\n"); | |
8ceee660 BH |
690 | return -EOPNOTSUPP; |
691 | } | |
692 | } | |
693 | ||
6fb70fd1 | 694 | efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive); |
8ceee660 | 695 | efx_for_each_channel(channel, efx) |
ef2b90ee | 696 | efx->type->push_irq_moderation(channel); |
8ceee660 BH |
697 | |
698 | return 0; | |
699 | } | |
700 | ||
4642610c BH |
701 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
702 | struct ethtool_ringparam *ring) | |
703 | { | |
704 | struct efx_nic *efx = netdev_priv(net_dev); | |
705 | ||
706 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; | |
707 | ring->tx_max_pending = EFX_MAX_DMAQ_SIZE; | |
708 | ring->rx_mini_max_pending = 0; | |
709 | ring->rx_jumbo_max_pending = 0; | |
710 | ring->rx_pending = efx->rxq_entries; | |
711 | ring->tx_pending = efx->txq_entries; | |
712 | ring->rx_mini_pending = 0; | |
713 | ring->rx_jumbo_pending = 0; | |
714 | } | |
715 | ||
716 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, | |
717 | struct ethtool_ringparam *ring) | |
718 | { | |
719 | struct efx_nic *efx = netdev_priv(net_dev); | |
720 | ||
721 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || | |
722 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || | |
723 | ring->tx_pending > EFX_MAX_DMAQ_SIZE) | |
724 | return -EINVAL; | |
725 | ||
726 | if (ring->rx_pending < EFX_MIN_RING_SIZE || | |
727 | ring->tx_pending < EFX_MIN_RING_SIZE) { | |
728 | netif_err(efx, drv, efx->net_dev, | |
729 | "TX and RX queues cannot be smaller than %ld\n", | |
730 | EFX_MIN_RING_SIZE); | |
731 | return -EINVAL; | |
732 | } | |
733 | ||
734 | return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending); | |
735 | } | |
736 | ||
8ceee660 BH |
737 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
738 | struct ethtool_pauseparam *pause) | |
739 | { | |
767e468c | 740 | struct efx_nic *efx = netdev_priv(net_dev); |
d3245b28 BH |
741 | enum efx_fc_type wanted_fc, old_fc; |
742 | u32 old_adv; | |
04cc8cac | 743 | bool reset; |
d3245b28 BH |
744 | int rc = 0; |
745 | ||
746 | mutex_lock(&efx->mac_lock); | |
8ceee660 | 747 | |
04cc8cac BH |
748 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
749 | (pause->tx_pause ? EFX_FC_TX : 0) | | |
750 | (pause->autoneg ? EFX_FC_AUTO : 0)); | |
751 | ||
752 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { | |
62776d03 BH |
753 | netif_dbg(efx, drv, efx->net_dev, |
754 | "Flow control unsupported: tx ON rx OFF\n"); | |
d3245b28 BH |
755 | rc = -EINVAL; |
756 | goto out; | |
04cc8cac BH |
757 | } |
758 | ||
d3245b28 | 759 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
62776d03 BH |
760 | netif_dbg(efx, drv, efx->net_dev, |
761 | "Autonegotiation is disabled\n"); | |
d3245b28 BH |
762 | rc = -EINVAL; |
763 | goto out; | |
04cc8cac BH |
764 | } |
765 | ||
766 | /* TX flow control may automatically turn itself off if the | |
767 | * link partner (intermittently) stops responding to pause | |
768 | * frames. There isn't any indication that this has happened, | |
769 | * so the best we do is leave it up to the user to spot this | |
770 | * and fix it be cycling transmit flow control on this end. */ | |
771 | reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX); | |
772 | if (EFX_WORKAROUND_11482(efx) && reset) { | |
daeda630 | 773 | if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) { |
04cc8cac | 774 | /* Recover by resetting the EM block */ |
d3245b28 BH |
775 | falcon_stop_nic_stats(efx); |
776 | falcon_drain_tx_fifo(efx); | |
777 | efx->mac_op->reconfigure(efx); | |
778 | falcon_start_nic_stats(efx); | |
04cc8cac BH |
779 | } else { |
780 | /* Schedule a reset to recover */ | |
781 | efx_schedule_reset(efx, RESET_TYPE_INVISIBLE); | |
782 | } | |
783 | } | |
784 | ||
d3245b28 BH |
785 | old_adv = efx->link_advertising; |
786 | old_fc = efx->wanted_fc; | |
787 | efx_link_set_wanted_fc(efx, wanted_fc); | |
788 | if (efx->link_advertising != old_adv || | |
789 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { | |
790 | rc = efx->phy_op->reconfigure(efx); | |
791 | if (rc) { | |
62776d03 BH |
792 | netif_err(efx, drv, efx->net_dev, |
793 | "Unable to advertise requested flow " | |
794 | "control setting\n"); | |
d3245b28 BH |
795 | goto out; |
796 | } | |
797 | } | |
04cc8cac | 798 | |
d3245b28 BH |
799 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
800 | * if the user just changed the advertised capabilities, but there's no | |
801 | * harm doing this twice */ | |
802 | efx->mac_op->reconfigure(efx); | |
04cc8cac | 803 | |
d3245b28 | 804 | out: |
04cc8cac | 805 | mutex_unlock(&efx->mac_lock); |
8ceee660 | 806 | |
d3245b28 | 807 | return rc; |
8ceee660 BH |
808 | } |
809 | ||
810 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, | |
811 | struct ethtool_pauseparam *pause) | |
812 | { | |
767e468c | 813 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 814 | |
04cc8cac BH |
815 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
816 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); | |
817 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); | |
8ceee660 BH |
818 | } |
819 | ||
820 | ||
89c758fa BH |
821 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
822 | struct ethtool_wolinfo *wol) | |
823 | { | |
824 | struct efx_nic *efx = netdev_priv(net_dev); | |
825 | return efx->type->get_wol(efx, wol); | |
826 | } | |
827 | ||
828 | ||
829 | static int efx_ethtool_set_wol(struct net_device *net_dev, | |
830 | struct ethtool_wolinfo *wol) | |
831 | { | |
832 | struct efx_nic *efx = netdev_priv(net_dev); | |
833 | return efx->type->set_wol(efx, wol->wolopts); | |
834 | } | |
835 | ||
d215697f | 836 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
eb9f6744 BH |
837 | { |
838 | struct efx_nic *efx = netdev_priv(net_dev); | |
839 | enum reset_type method; | |
840 | enum { | |
841 | ETH_RESET_EFX_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER | | |
842 | ETH_RESET_OFFLOAD | ETH_RESET_MAC) | |
843 | }; | |
844 | ||
845 | /* Check for minimal reset flags */ | |
846 | if ((*flags & ETH_RESET_EFX_INVISIBLE) != ETH_RESET_EFX_INVISIBLE) | |
847 | return -EINVAL; | |
848 | *flags ^= ETH_RESET_EFX_INVISIBLE; | |
849 | method = RESET_TYPE_INVISIBLE; | |
850 | ||
851 | if (*flags & ETH_RESET_PHY) { | |
852 | *flags ^= ETH_RESET_PHY; | |
853 | method = RESET_TYPE_ALL; | |
854 | } | |
855 | ||
856 | if ((*flags & efx->type->reset_world_flags) == | |
857 | efx->type->reset_world_flags) { | |
858 | *flags ^= efx->type->reset_world_flags; | |
859 | method = RESET_TYPE_WORLD; | |
860 | } | |
861 | ||
862 | return efx_reset(efx, method); | |
863 | } | |
864 | ||
765c9f46 BH |
865 | static int |
866 | efx_ethtool_get_rxnfc(struct net_device *net_dev, | |
867 | struct ethtool_rxnfc *info, void *rules __always_unused) | |
868 | { | |
869 | struct efx_nic *efx = netdev_priv(net_dev); | |
870 | ||
871 | switch (info->cmd) { | |
872 | case ETHTOOL_GRXRINGS: | |
873 | info->data = efx->n_rx_channels; | |
874 | return 0; | |
875 | ||
876 | case ETHTOOL_GRXFH: { | |
877 | unsigned min_revision = 0; | |
878 | ||
879 | info->data = 0; | |
880 | switch (info->flow_type) { | |
881 | case TCP_V4_FLOW: | |
882 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
883 | /* fall through */ | |
884 | case UDP_V4_FLOW: | |
885 | case SCTP_V4_FLOW: | |
886 | case AH_ESP_V4_FLOW: | |
887 | case IPV4_FLOW: | |
888 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
889 | min_revision = EFX_REV_FALCON_B0; | |
890 | break; | |
891 | case TCP_V6_FLOW: | |
892 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
893 | /* fall through */ | |
894 | case UDP_V6_FLOW: | |
895 | case SCTP_V6_FLOW: | |
896 | case AH_ESP_V6_FLOW: | |
897 | case IPV6_FLOW: | |
898 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
899 | min_revision = EFX_REV_SIENA_A0; | |
900 | break; | |
901 | default: | |
902 | break; | |
903 | } | |
904 | if (efx_nic_rev(efx) < min_revision) | |
905 | info->data = 0; | |
906 | return 0; | |
907 | } | |
908 | ||
909 | default: | |
910 | return -EOPNOTSUPP; | |
911 | } | |
912 | } | |
913 | ||
b4187e42 BH |
914 | static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev, |
915 | struct ethtool_rx_ntuple *ntuple) | |
916 | { | |
917 | struct efx_nic *efx = netdev_priv(net_dev); | |
918 | struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec; | |
919 | struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec; | |
920 | struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec; | |
921 | struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec; | |
922 | struct efx_filter_spec filter; | |
923 | ||
924 | /* Range-check action */ | |
925 | if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR || | |
926 | ntuple->fs.action >= (s32)efx->n_rx_channels) | |
927 | return -EINVAL; | |
928 | ||
929 | if (~ntuple->fs.data_mask) | |
930 | return -EINVAL; | |
931 | ||
932 | switch (ntuple->fs.flow_type) { | |
933 | case TCP_V4_FLOW: | |
934 | case UDP_V4_FLOW: | |
935 | /* Must match all of destination, */ | |
936 | if (ip_mask->ip4dst | ip_mask->pdst) | |
937 | return -EINVAL; | |
938 | /* all or none of source, */ | |
939 | if ((ip_mask->ip4src | ip_mask->psrc) && | |
940 | ((__force u32)~ip_mask->ip4src | | |
941 | (__force u16)~ip_mask->psrc)) | |
942 | return -EINVAL; | |
943 | /* and nothing else */ | |
944 | if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask) | |
945 | return -EINVAL; | |
946 | break; | |
947 | case ETHER_FLOW: | |
948 | /* Must match all of destination, */ | |
949 | if (!is_zero_ether_addr(mac_mask->h_dest)) | |
950 | return -EINVAL; | |
951 | /* all or none of VID, */ | |
952 | if (ntuple->fs.vlan_tag_mask != 0xf000 && | |
953 | ntuple->fs.vlan_tag_mask != 0xffff) | |
954 | return -EINVAL; | |
955 | /* and nothing else */ | |
956 | if (!is_broadcast_ether_addr(mac_mask->h_source) || | |
957 | mac_mask->h_proto != htons(0xffff)) | |
958 | return -EINVAL; | |
959 | break; | |
960 | default: | |
961 | return -EINVAL; | |
962 | } | |
963 | ||
964 | filter.priority = EFX_FILTER_PRI_MANUAL; | |
965 | filter.flags = 0; | |
966 | ||
967 | switch (ntuple->fs.flow_type) { | |
968 | case TCP_V4_FLOW: | |
969 | if (!ip_mask->ip4src) | |
970 | efx_filter_set_rx_tcp_full(&filter, | |
971 | htonl(ip_entry->ip4src), | |
972 | htons(ip_entry->psrc), | |
973 | htonl(ip_entry->ip4dst), | |
974 | htons(ip_entry->pdst)); | |
975 | else | |
976 | efx_filter_set_rx_tcp_wild(&filter, | |
977 | htonl(ip_entry->ip4dst), | |
978 | htons(ip_entry->pdst)); | |
979 | break; | |
980 | case UDP_V4_FLOW: | |
981 | if (!ip_mask->ip4src) | |
982 | efx_filter_set_rx_udp_full(&filter, | |
983 | htonl(ip_entry->ip4src), | |
984 | htons(ip_entry->psrc), | |
985 | htonl(ip_entry->ip4dst), | |
986 | htons(ip_entry->pdst)); | |
987 | else | |
988 | efx_filter_set_rx_udp_wild(&filter, | |
989 | htonl(ip_entry->ip4dst), | |
990 | htons(ip_entry->pdst)); | |
991 | break; | |
992 | case ETHER_FLOW: | |
993 | if (ntuple->fs.vlan_tag_mask == 0xf000) | |
994 | efx_filter_set_rx_mac_full(&filter, | |
995 | ntuple->fs.vlan_tag & 0xfff, | |
996 | mac_entry->h_dest); | |
997 | else | |
998 | efx_filter_set_rx_mac_wild(&filter, mac_entry->h_dest); | |
999 | break; | |
1000 | } | |
1001 | ||
1002 | if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR) { | |
1003 | return efx_filter_remove_filter(efx, &filter); | |
1004 | } else { | |
1005 | if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) | |
1006 | filter.dmaq_id = 0xfff; | |
1007 | else | |
1008 | filter.dmaq_id = ntuple->fs.action; | |
1009 | return efx_filter_insert_filter(efx, &filter, true); | |
1010 | } | |
1011 | } | |
1012 | ||
765c9f46 BH |
1013 | static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, |
1014 | struct ethtool_rxfh_indir *indir) | |
1015 | { | |
1016 | struct efx_nic *efx = netdev_priv(net_dev); | |
1017 | size_t copy_size = | |
1018 | min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table)); | |
1019 | ||
1020 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) | |
1021 | return -EOPNOTSUPP; | |
1022 | ||
1023 | indir->size = ARRAY_SIZE(efx->rx_indir_table); | |
1024 | memcpy(indir->ring_index, efx->rx_indir_table, | |
1025 | copy_size * sizeof(indir->ring_index[0])); | |
1026 | return 0; | |
1027 | } | |
1028 | ||
1029 | static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev, | |
1030 | const struct ethtool_rxfh_indir *indir) | |
1031 | { | |
1032 | struct efx_nic *efx = netdev_priv(net_dev); | |
1033 | size_t i; | |
1034 | ||
1035 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) | |
1036 | return -EOPNOTSUPP; | |
1037 | ||
1038 | /* Validate size and indices */ | |
1039 | if (indir->size != ARRAY_SIZE(efx->rx_indir_table)) | |
1040 | return -EINVAL; | |
1041 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) | |
1042 | if (indir->ring_index[i] >= efx->n_rx_channels) | |
1043 | return -EINVAL; | |
1044 | ||
1045 | memcpy(efx->rx_indir_table, indir->ring_index, | |
1046 | sizeof(efx->rx_indir_table)); | |
1047 | efx_nic_push_rx_indir_table(efx); | |
1048 | return 0; | |
1049 | } | |
1050 | ||
0fc0b732 | 1051 | const struct ethtool_ops efx_ethtool_ops = { |
8ceee660 BH |
1052 | .get_settings = efx_ethtool_get_settings, |
1053 | .set_settings = efx_ethtool_set_settings, | |
1054 | .get_drvinfo = efx_ethtool_get_drvinfo, | |
5b98c1bf BH |
1055 | .get_regs_len = efx_ethtool_get_regs_len, |
1056 | .get_regs = efx_ethtool_get_regs, | |
62776d03 BH |
1057 | .get_msglevel = efx_ethtool_get_msglevel, |
1058 | .set_msglevel = efx_ethtool_set_msglevel, | |
8ceee660 BH |
1059 | .nway_reset = efx_ethtool_nway_reset, |
1060 | .get_link = efx_ethtool_get_link, | |
1061 | .get_coalesce = efx_ethtool_get_coalesce, | |
1062 | .set_coalesce = efx_ethtool_set_coalesce, | |
4642610c BH |
1063 | .get_ringparam = efx_ethtool_get_ringparam, |
1064 | .set_ringparam = efx_ethtool_set_ringparam, | |
8ceee660 BH |
1065 | .get_pauseparam = efx_ethtool_get_pauseparam, |
1066 | .set_pauseparam = efx_ethtool_set_pauseparam, | |
1067 | .get_rx_csum = efx_ethtool_get_rx_csum, | |
1068 | .set_rx_csum = efx_ethtool_set_rx_csum, | |
1069 | .get_tx_csum = ethtool_op_get_tx_csum, | |
c383b537 BH |
1070 | /* Need to enable/disable IPv6 too */ |
1071 | .set_tx_csum = efx_ethtool_set_tx_csum, | |
8ceee660 BH |
1072 | .get_sg = ethtool_op_get_sg, |
1073 | .set_sg = ethtool_op_set_sg, | |
b9b39b62 | 1074 | .get_tso = ethtool_op_get_tso, |
738a8f4b BH |
1075 | /* Need to enable/disable TSO-IPv6 too */ |
1076 | .set_tso = efx_ethtool_set_tso, | |
8ceee660 | 1077 | .get_flags = ethtool_op_get_flags, |
39c9cf07 | 1078 | .set_flags = efx_ethtool_set_flags, |
3594e131 | 1079 | .get_sset_count = efx_ethtool_get_sset_count, |
3273c2e8 | 1080 | .self_test = efx_ethtool_self_test, |
8ceee660 BH |
1081 | .get_strings = efx_ethtool_get_strings, |
1082 | .phys_id = efx_ethtool_phys_id, | |
8ceee660 | 1083 | .get_ethtool_stats = efx_ethtool_get_stats, |
89c758fa BH |
1084 | .get_wol = efx_ethtool_get_wol, |
1085 | .set_wol = efx_ethtool_set_wol, | |
eb9f6744 | 1086 | .reset = efx_ethtool_reset, |
765c9f46 | 1087 | .get_rxnfc = efx_ethtool_get_rxnfc, |
b4187e42 | 1088 | .set_rx_ntuple = efx_ethtool_set_rx_ntuple, |
765c9f46 BH |
1089 | .get_rxfh_indir = efx_ethtool_get_rxfh_indir, |
1090 | .set_rxfh_indir = efx_ethtool_set_rxfh_indir, | |
8ceee660 | 1091 | }; |