]>
Commit | Line | Data |
---|---|---|
8ceee660 | 1 | /**************************************************************************** |
f7a6d2c4 | 2 | * Driver for Solarflare network controllers and boards |
8ceee660 | 3 | * Copyright 2005-2006 Fen Systems Ltd. |
f7a6d2c4 | 4 | * Copyright 2006-2013 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> | |
c39d35eb | 14 | #include <linux/in.h> |
8ceee660 | 15 | #include "net_driver.h" |
04cc8cac | 16 | #include "workarounds.h" |
3273c2e8 | 17 | #include "selftest.h" |
8ceee660 | 18 | #include "efx.h" |
b4187e42 | 19 | #include "filter.h" |
744093c9 | 20 | #include "nic.h" |
8ceee660 | 21 | |
cd0ecc9a | 22 | struct efx_sw_stat_desc { |
8ceee660 BH |
23 | const char *name; |
24 | enum { | |
8ceee660 | 25 | EFX_ETHTOOL_STAT_SOURCE_nic, |
119226c5 BH |
26 | EFX_ETHTOOL_STAT_SOURCE_channel, |
27 | EFX_ETHTOOL_STAT_SOURCE_tx_queue | |
8ceee660 BH |
28 | } source; |
29 | unsigned offset; | |
30 | u64(*get_stat) (void *field); /* Reader function */ | |
31 | }; | |
32 | ||
cd0ecc9a | 33 | /* Initialiser for a struct efx_sw_stat_desc with type-checking */ |
8ceee660 BH |
34 | #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ |
35 | get_stat_function) { \ | |
36 | .name = #stat_name, \ | |
37 | .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ | |
38 | .offset = ((((field_type *) 0) == \ | |
39 | &((struct efx_##source_name *)0)->field) ? \ | |
40 | offsetof(struct efx_##source_name, field) : \ | |
41 | offsetof(struct efx_##source_name, field)), \ | |
42 | .get_stat = get_stat_function, \ | |
43 | } | |
44 | ||
45 | static u64 efx_get_uint_stat(void *field) | |
46 | { | |
47 | return *(unsigned int *)field; | |
48 | } | |
49 | ||
8ceee660 BH |
50 | static u64 efx_get_atomic_stat(void *field) |
51 | { | |
52 | return atomic_read((atomic_t *) field); | |
53 | } | |
54 | ||
8ceee660 BH |
55 | #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ |
56 | EFX_ETHTOOL_STAT(field, nic, field, \ | |
57 | atomic_t, efx_get_atomic_stat) | |
58 | ||
59 | #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ | |
60 | EFX_ETHTOOL_STAT(field, channel, n_##field, \ | |
61 | unsigned int, efx_get_uint_stat) | |
62 | ||
119226c5 BH |
63 | #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ |
64 | EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ | |
65 | unsigned int, efx_get_uint_stat) | |
66 | ||
cd0ecc9a | 67 | static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { |
02e12165 | 68 | EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), |
119226c5 BH |
69 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), |
70 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), | |
71 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), | |
72 | EFX_ETHTOOL_UINT_TXQ_STAT(pushes), | |
ee45fd92 | 73 | EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), |
8ceee660 BH |
74 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
75 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), | |
76 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), | |
77 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), | |
c1ac403b | 78 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
8ceee660 | 79 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
8127d661 BH |
80 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), |
81 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), | |
8ceee660 BH |
82 | }; |
83 | ||
cd0ecc9a | 84 | #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) |
8ceee660 | 85 | |
4a5b504d | 86 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
4a5b504d | 87 | |
8ceee660 BH |
88 | /************************************************************************** |
89 | * | |
90 | * Ethtool operations | |
91 | * | |
92 | ************************************************************************** | |
93 | */ | |
94 | ||
95 | /* Identify device by flashing LEDs */ | |
c5e129ac BH |
96 | static int efx_ethtool_phys_id(struct net_device *net_dev, |
97 | enum ethtool_phys_id_state state) | |
8ceee660 | 98 | { |
767e468c | 99 | struct efx_nic *efx = netdev_priv(net_dev); |
fce55922 | 100 | enum efx_led_mode mode = EFX_LED_DEFAULT; |
8ceee660 | 101 | |
c5e129ac BH |
102 | switch (state) { |
103 | case ETHTOOL_ID_ON: | |
104 | mode = EFX_LED_ON; | |
105 | break; | |
106 | case ETHTOOL_ID_OFF: | |
107 | mode = EFX_LED_OFF; | |
108 | break; | |
109 | case ETHTOOL_ID_INACTIVE: | |
110 | mode = EFX_LED_DEFAULT; | |
111 | break; | |
fce55922 AB |
112 | case ETHTOOL_ID_ACTIVE: |
113 | return 1; /* cycle on/off once per second */ | |
c5e129ac | 114 | } |
398468ed | 115 | |
c5e129ac | 116 | efx->type->set_id_led(efx, mode); |
8ceee660 BH |
117 | return 0; |
118 | } | |
119 | ||
120 | /* This must be called with rtnl_lock held. */ | |
d215697f | 121 | static int efx_ethtool_get_settings(struct net_device *net_dev, |
122 | struct ethtool_cmd *ecmd) | |
8ceee660 | 123 | { |
767e468c | 124 | struct efx_nic *efx = netdev_priv(net_dev); |
d3245b28 | 125 | struct efx_link_state *link_state = &efx->link_state; |
8ceee660 BH |
126 | |
127 | mutex_lock(&efx->mac_lock); | |
177dfcd8 | 128 | efx->phy_op->get_settings(efx, ecmd); |
8ceee660 BH |
129 | mutex_unlock(&efx->mac_lock); |
130 | ||
d3245b28 BH |
131 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
132 | ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; | |
133 | ||
134 | if (LOOPBACK_INTERNAL(efx)) { | |
70739497 | 135 | ethtool_cmd_speed_set(ecmd, link_state->speed); |
d3245b28 BH |
136 | ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
137 | } | |
177dfcd8 BH |
138 | |
139 | return 0; | |
8ceee660 BH |
140 | } |
141 | ||
142 | /* This must be called with rtnl_lock held. */ | |
d215697f | 143 | static int efx_ethtool_set_settings(struct net_device *net_dev, |
144 | struct ethtool_cmd *ecmd) | |
8ceee660 | 145 | { |
767e468c | 146 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
147 | int rc; |
148 | ||
754c653a | 149 | /* GMAC does not support 1000Mbps HD */ |
25db0338 DD |
150 | if ((ethtool_cmd_speed(ecmd) == SPEED_1000) && |
151 | (ecmd->duplex != DUPLEX_FULL)) { | |
62776d03 BH |
152 | netif_dbg(efx, drv, efx->net_dev, |
153 | "rejecting unsupported 1000Mbps HD setting\n"); | |
177dfcd8 BH |
154 | return -EINVAL; |
155 | } | |
156 | ||
8ceee660 | 157 | mutex_lock(&efx->mac_lock); |
177dfcd8 | 158 | rc = efx->phy_op->set_settings(efx, ecmd); |
8ceee660 | 159 | mutex_unlock(&efx->mac_lock); |
8ceee660 BH |
160 | return rc; |
161 | } | |
162 | ||
163 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, | |
164 | struct ethtool_drvinfo *info) | |
165 | { | |
767e468c | 166 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 167 | |
c5d5f5fd | 168 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
8ceee660 | 169 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
8880f4ec | 170 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
e5f0fd27 BH |
171 | efx_mcdi_print_fwver(efx, info->fw_version, |
172 | sizeof(info->fw_version)); | |
8ceee660 BH |
173 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
174 | } | |
175 | ||
5b98c1bf BH |
176 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
177 | { | |
178 | return efx_nic_get_regs_len(netdev_priv(net_dev)); | |
179 | } | |
180 | ||
181 | static void efx_ethtool_get_regs(struct net_device *net_dev, | |
182 | struct ethtool_regs *regs, void *buf) | |
183 | { | |
184 | struct efx_nic *efx = netdev_priv(net_dev); | |
185 | ||
186 | regs->version = efx->type->revision; | |
187 | efx_nic_get_regs(efx, buf); | |
188 | } | |
189 | ||
62776d03 BH |
190 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
191 | { | |
192 | struct efx_nic *efx = netdev_priv(net_dev); | |
193 | return efx->msg_enable; | |
194 | } | |
195 | ||
196 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) | |
197 | { | |
198 | struct efx_nic *efx = netdev_priv(net_dev); | |
199 | efx->msg_enable = msg_enable; | |
200 | } | |
201 | ||
3273c2e8 BH |
202 | /** |
203 | * efx_fill_test - fill in an individual self-test entry | |
204 | * @test_index: Index of the test | |
205 | * @strings: Ethtool strings, or %NULL | |
206 | * @data: Ethtool test results, or %NULL | |
207 | * @test: Pointer to test result (used only if data != %NULL) | |
740ced99 BH |
208 | * @unit_format: Unit name format (e.g. "chan\%d") |
209 | * @unit_id: Unit id (e.g. 0 for "chan0") | |
3273c2e8 | 210 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
740ced99 | 211 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
3273c2e8 BH |
212 | * |
213 | * Fill in an individual self-test entry. | |
214 | */ | |
b681e57c | 215 | static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, |
3273c2e8 BH |
216 | int *test, const char *unit_format, int unit_id, |
217 | const char *test_format, const char *test_id) | |
218 | { | |
b681e57c | 219 | char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; |
3273c2e8 BH |
220 | |
221 | /* Fill data value, if applicable */ | |
222 | if (data) | |
223 | data[test_index] = *test; | |
224 | ||
225 | /* Fill string, if applicable */ | |
226 | if (strings) { | |
11e66966 | 227 | if (strchr(unit_format, '%')) |
b681e57c | 228 | snprintf(unit_str, sizeof(unit_str), |
11e66966 BH |
229 | unit_format, unit_id); |
230 | else | |
b681e57c BH |
231 | strcpy(unit_str, unit_format); |
232 | snprintf(test_str, sizeof(test_str), test_format, test_id); | |
233 | snprintf(strings + test_index * ETH_GSTRING_LEN, | |
234 | ETH_GSTRING_LEN, | |
235 | "%-6s %-24s", unit_str, test_str); | |
3273c2e8 BH |
236 | } |
237 | } | |
238 | ||
740ced99 | 239 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
3273c2e8 BH |
240 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
241 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue | |
242 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ | |
c459302d | 243 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
3273c2e8 BH |
244 | |
245 | /** | |
246 | * efx_fill_loopback_test - fill in a block of loopback self-test entries | |
247 | * @efx: Efx NIC | |
248 | * @lb_tests: Efx loopback self-test results structure | |
249 | * @mode: Loopback test mode | |
250 | * @test_index: Starting index of the test | |
251 | * @strings: Ethtool strings, or %NULL | |
252 | * @data: Ethtool test results, or %NULL | |
17e678d1 BH |
253 | * |
254 | * Fill in a block of loopback self-test entries. Return new test | |
255 | * index. | |
3273c2e8 BH |
256 | */ |
257 | static int efx_fill_loopback_test(struct efx_nic *efx, | |
258 | struct efx_loopback_self_tests *lb_tests, | |
259 | enum efx_loopback_mode mode, | |
260 | unsigned int test_index, | |
b681e57c | 261 | u8 *strings, u64 *data) |
3273c2e8 | 262 | { |
1ac0226e BH |
263 | struct efx_channel *channel = |
264 | efx_get_channel(efx, efx->tx_channel_offset); | |
3273c2e8 BH |
265 | struct efx_tx_queue *tx_queue; |
266 | ||
f7d12cdc | 267 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
3273c2e8 BH |
268 | efx_fill_test(test_index++, strings, data, |
269 | &lb_tests->tx_sent[tx_queue->queue], | |
270 | EFX_TX_QUEUE_NAME(tx_queue), | |
271 | EFX_LOOPBACK_NAME(mode, "tx_sent")); | |
272 | efx_fill_test(test_index++, strings, data, | |
273 | &lb_tests->tx_done[tx_queue->queue], | |
274 | EFX_TX_QUEUE_NAME(tx_queue), | |
275 | EFX_LOOPBACK_NAME(mode, "tx_done")); | |
276 | } | |
277 | efx_fill_test(test_index++, strings, data, | |
278 | &lb_tests->rx_good, | |
11e66966 | 279 | "rx", 0, |
3273c2e8 BH |
280 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
281 | efx_fill_test(test_index++, strings, data, | |
282 | &lb_tests->rx_bad, | |
11e66966 | 283 | "rx", 0, |
3273c2e8 BH |
284 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
285 | ||
286 | return test_index; | |
287 | } | |
288 | ||
289 | /** | |
290 | * efx_ethtool_fill_self_tests - get self-test details | |
291 | * @efx: Efx NIC | |
292 | * @tests: Efx self-test results structure, or %NULL | |
293 | * @strings: Ethtool strings, or %NULL | |
294 | * @data: Ethtool test results, or %NULL | |
17e678d1 BH |
295 | * |
296 | * Get self-test number of strings, strings, and/or test results. | |
297 | * Return number of strings (== number of test results). | |
298 | * | |
299 | * The reason for merging these three functions is to make sure that | |
300 | * they can never be inconsistent. | |
3273c2e8 BH |
301 | */ |
302 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, | |
303 | struct efx_self_tests *tests, | |
b681e57c | 304 | u8 *strings, u64 *data) |
3273c2e8 BH |
305 | { |
306 | struct efx_channel *channel; | |
1796721a | 307 | unsigned int n = 0, i; |
3273c2e8 BH |
308 | enum efx_loopback_mode mode; |
309 | ||
4f16c073 BH |
310 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
311 | "phy", 0, "alive", NULL); | |
8c8661e4 BH |
312 | efx_fill_test(n++, strings, data, &tests->nvram, |
313 | "core", 0, "nvram", NULL); | |
3273c2e8 BH |
314 | efx_fill_test(n++, strings, data, &tests->interrupt, |
315 | "core", 0, "interrupt", NULL); | |
316 | ||
317 | /* Event queues */ | |
318 | efx_for_each_channel(channel, efx) { | |
319 | efx_fill_test(n++, strings, data, | |
320 | &tests->eventq_dma[channel->channel], | |
321 | EFX_CHANNEL_NAME(channel), | |
322 | "eventq.dma", NULL); | |
323 | efx_fill_test(n++, strings, data, | |
324 | &tests->eventq_int[channel->channel], | |
325 | EFX_CHANNEL_NAME(channel), | |
326 | "eventq.int", NULL); | |
3273c2e8 BH |
327 | } |
328 | ||
74cd60a4 JC |
329 | efx_fill_test(n++, strings, data, &tests->memory, |
330 | "core", 0, "memory", NULL); | |
8c8661e4 BH |
331 | efx_fill_test(n++, strings, data, &tests->registers, |
332 | "core", 0, "registers", NULL); | |
1796721a | 333 | |
c1c4f453 BH |
334 | if (efx->phy_op->run_tests != NULL) { |
335 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); | |
336 | ||
337 | for (i = 0; true; ++i) { | |
338 | const char *name; | |
339 | ||
340 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); | |
341 | name = efx->phy_op->test_name(efx, i); | |
342 | if (name == NULL) | |
343 | break; | |
344 | ||
4f16c073 | 345 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
c1c4f453 BH |
346 | "phy", 0, name, NULL); |
347 | } | |
348 | } | |
3273c2e8 BH |
349 | |
350 | /* Loopback tests */ | |
8c8661e4 | 351 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
3273c2e8 BH |
352 | if (!(efx->loopback_modes & (1 << mode))) |
353 | continue; | |
354 | n = efx_fill_loopback_test(efx, | |
355 | &tests->loopback[mode], mode, n, | |
356 | strings, data); | |
357 | } | |
358 | ||
359 | return n; | |
360 | } | |
361 | ||
8ccf3800 AR |
362 | static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) |
363 | { | |
364 | size_t n_stats = 0; | |
365 | struct efx_channel *channel; | |
366 | ||
367 | efx_for_each_channel(channel, efx) { | |
368 | if (efx_channel_has_tx_queues(channel)) { | |
369 | n_stats++; | |
370 | if (strings != NULL) { | |
371 | snprintf(strings, ETH_GSTRING_LEN, | |
372 | "tx-%u.tx_packets", | |
373 | channel->tx_queue[0].queue / | |
374 | EFX_TXQ_TYPES); | |
375 | ||
376 | strings += ETH_GSTRING_LEN; | |
377 | } | |
378 | } | |
379 | } | |
380 | efx_for_each_channel(channel, efx) { | |
381 | if (efx_channel_has_rx_queue(channel)) { | |
382 | n_stats++; | |
383 | if (strings != NULL) { | |
384 | snprintf(strings, ETH_GSTRING_LEN, | |
385 | "rx-%d.rx_packets", channel->channel); | |
386 | strings += ETH_GSTRING_LEN; | |
387 | } | |
388 | } | |
389 | } | |
390 | return n_stats; | |
391 | } | |
392 | ||
3594e131 BH |
393 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
394 | int string_set) | |
8ceee660 | 395 | { |
cd0ecc9a BH |
396 | struct efx_nic *efx = netdev_priv(net_dev); |
397 | ||
3594e131 BH |
398 | switch (string_set) { |
399 | case ETH_SS_STATS: | |
cd0ecc9a | 400 | return efx->type->describe_stats(efx, NULL) + |
8ccf3800 AR |
401 | EFX_ETHTOOL_SW_STAT_COUNT + |
402 | efx_describe_per_queue_stats(efx, NULL) + | |
403 | efx_ptp_describe_stats(efx, NULL); | |
3594e131 | 404 | case ETH_SS_TEST: |
cd0ecc9a | 405 | return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
3594e131 BH |
406 | default: |
407 | return -EINVAL; | |
408 | } | |
3273c2e8 BH |
409 | } |
410 | ||
8ceee660 BH |
411 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
412 | u32 string_set, u8 *strings) | |
413 | { | |
767e468c | 414 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
415 | int i; |
416 | ||
3273c2e8 BH |
417 | switch (string_set) { |
418 | case ETH_SS_STATS: | |
cd0ecc9a BH |
419 | strings += (efx->type->describe_stats(efx, strings) * |
420 | ETH_GSTRING_LEN); | |
421 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) | |
b681e57c | 422 | strlcpy(strings + i * ETH_GSTRING_LEN, |
cd0ecc9a | 423 | efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); |
99691c4a | 424 | strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; |
8ccf3800 AR |
425 | strings += (efx_describe_per_queue_stats(efx, strings) * |
426 | ETH_GSTRING_LEN); | |
99691c4a | 427 | efx_ptp_describe_stats(efx, strings); |
3273c2e8 BH |
428 | break; |
429 | case ETH_SS_TEST: | |
b681e57c | 430 | efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
3273c2e8 BH |
431 | break; |
432 | default: | |
433 | /* No other string sets */ | |
434 | break; | |
435 | } | |
8ceee660 BH |
436 | } |
437 | ||
438 | static void efx_ethtool_get_stats(struct net_device *net_dev, | |
439 | struct ethtool_stats *stats, | |
440 | u64 *data) | |
441 | { | |
767e468c | 442 | struct efx_nic *efx = netdev_priv(net_dev); |
cd0ecc9a | 443 | const struct efx_sw_stat_desc *stat; |
8ceee660 | 444 | struct efx_channel *channel; |
119226c5 | 445 | struct efx_tx_queue *tx_queue; |
8ccf3800 | 446 | struct efx_rx_queue *rx_queue; |
8ceee660 BH |
447 | int i; |
448 | ||
1cb34522 BH |
449 | spin_lock_bh(&efx->stats_lock); |
450 | ||
cd0ecc9a BH |
451 | /* Get NIC statistics */ |
452 | data += efx->type->update_stats(efx, data, NULL); | |
8ceee660 | 453 | |
cd0ecc9a BH |
454 | /* Get software statistics */ |
455 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { | |
456 | stat = &efx_sw_stat_desc[i]; | |
8ceee660 | 457 | switch (stat->source) { |
8ceee660 BH |
458 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
459 | data[i] = stat->get_stat((void *)efx + stat->offset); | |
460 | break; | |
461 | case EFX_ETHTOOL_STAT_SOURCE_channel: | |
462 | data[i] = 0; | |
463 | efx_for_each_channel(channel, efx) | |
464 | data[i] += stat->get_stat((void *)channel + | |
465 | stat->offset); | |
466 | break; | |
119226c5 BH |
467 | case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
468 | data[i] = 0; | |
469 | efx_for_each_channel(channel, efx) { | |
470 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
471 | data[i] += | |
472 | stat->get_stat((void *)tx_queue | |
473 | + stat->offset); | |
474 | } | |
475 | break; | |
8ceee660 BH |
476 | } |
477 | } | |
99691c4a | 478 | data += EFX_ETHTOOL_SW_STAT_COUNT; |
1cb34522 BH |
479 | |
480 | spin_unlock_bh(&efx->stats_lock); | |
99691c4a | 481 | |
8ccf3800 AR |
482 | efx_for_each_channel(channel, efx) { |
483 | if (efx_channel_has_tx_queues(channel)) { | |
484 | *data = 0; | |
485 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
486 | *data += tx_queue->tx_packets; | |
487 | } | |
488 | data++; | |
489 | } | |
490 | } | |
491 | efx_for_each_channel(channel, efx) { | |
492 | if (efx_channel_has_rx_queue(channel)) { | |
493 | *data = 0; | |
494 | efx_for_each_channel_rx_queue(rx_queue, channel) { | |
495 | *data += rx_queue->rx_packets; | |
496 | } | |
497 | data++; | |
498 | } | |
499 | } | |
500 | ||
99691c4a | 501 | efx_ptp_update_stats(efx, data); |
8ceee660 BH |
502 | } |
503 | ||
3273c2e8 BH |
504 | static void efx_ethtool_self_test(struct net_device *net_dev, |
505 | struct ethtool_test *test, u64 *data) | |
506 | { | |
767e468c | 507 | struct efx_nic *efx = netdev_priv(net_dev); |
28801f35 | 508 | struct efx_self_tests *efx_tests; |
17e678d1 | 509 | bool already_up; |
28801f35 ED |
510 | int rc = -ENOMEM; |
511 | ||
512 | efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL); | |
513 | if (!efx_tests) | |
514 | goto fail; | |
515 | ||
f16aeea0 | 516 | if (efx->state != STATE_READY) { |
5eed1f68 | 517 | rc = -EBUSY; |
17e678d1 | 518 | goto out; |
3273c2e8 BH |
519 | } |
520 | ||
ac33ac61 BH |
521 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
522 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
523 | ||
3273c2e8 BH |
524 | /* We need rx buffers and interrupts. */ |
525 | already_up = (efx->net_dev->flags & IFF_UP); | |
526 | if (!already_up) { | |
527 | rc = dev_open(efx->net_dev); | |
528 | if (rc) { | |
62776d03 BH |
529 | netif_err(efx, drv, efx->net_dev, |
530 | "failed opening device.\n"); | |
17e678d1 | 531 | goto out; |
3273c2e8 BH |
532 | } |
533 | } | |
534 | ||
28801f35 | 535 | rc = efx_selftest(efx, efx_tests, test->flags); |
3273c2e8 | 536 | |
3273c2e8 BH |
537 | if (!already_up) |
538 | dev_close(efx->net_dev); | |
539 | ||
ac33ac61 BH |
540 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
541 | rc == 0 ? "passed" : "failed", | |
542 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
3273c2e8 | 543 | |
17e678d1 | 544 | out: |
28801f35 ED |
545 | efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
546 | kfree(efx_tests); | |
547 | fail: | |
3273c2e8 BH |
548 | if (rc) |
549 | test->flags |= ETH_TEST_FL_FAILED; | |
550 | } | |
551 | ||
8ceee660 BH |
552 | /* Restart autonegotiation */ |
553 | static int efx_ethtool_nway_reset(struct net_device *net_dev) | |
554 | { | |
767e468c | 555 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 556 | |
68e7f45e | 557 | return mdio45_nway_restart(&efx->mdio); |
8ceee660 BH |
558 | } |
559 | ||
a0c4faf5 BH |
560 | /* |
561 | * Each channel has a single IRQ and moderation timer, started by any | |
562 | * completion (or other event). Unless the module parameter | |
563 | * separate_tx_channels is set, IRQs and moderation are therefore | |
564 | * shared between RX and TX completions. In this case, when RX IRQ | |
565 | * moderation is explicitly changed then TX IRQ moderation is | |
566 | * automatically changed too, but otherwise we fail if the two values | |
567 | * are requested to be different. | |
568 | * | |
13225977 BH |
569 | * The hardware does not support a limit on the number of completions |
570 | * before an IRQ, so we do not use the max_frames fields. We should | |
571 | * report and require that max_frames == (usecs != 0), but this would | |
572 | * invalidate existing user documentation. | |
573 | * | |
574 | * The hardware does not have distinct settings for interrupt | |
575 | * moderation while the previous IRQ is being handled, so we should | |
576 | * not use the 'irq' fields. However, an earlier developer | |
577 | * misunderstood the meaning of the 'irq' fields and the driver did | |
578 | * not support the standard fields. To avoid invalidating existing | |
579 | * user documentation, we report and accept changes through either the | |
580 | * standard or 'irq' fields. If both are changed at the same time, we | |
581 | * prefer the standard field. | |
582 | * | |
a0c4faf5 BH |
583 | * We implement adaptive IRQ moderation, but use a different algorithm |
584 | * from that assumed in the definition of struct ethtool_coalesce. | |
585 | * Therefore we do not use any of the adaptive moderation parameters | |
586 | * in it. | |
587 | */ | |
588 | ||
8ceee660 BH |
589 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
590 | struct ethtool_coalesce *coalesce) | |
591 | { | |
767e468c | 592 | struct efx_nic *efx = netdev_priv(net_dev); |
a0c4faf5 BH |
593 | unsigned int tx_usecs, rx_usecs; |
594 | bool rx_adaptive; | |
8ceee660 | 595 | |
a0c4faf5 | 596 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive); |
8ceee660 | 597 | |
13225977 | 598 | coalesce->tx_coalesce_usecs = tx_usecs; |
a0c4faf5 | 599 | coalesce->tx_coalesce_usecs_irq = tx_usecs; |
13225977 | 600 | coalesce->rx_coalesce_usecs = rx_usecs; |
a0c4faf5 BH |
601 | coalesce->rx_coalesce_usecs_irq = rx_usecs; |
602 | coalesce->use_adaptive_rx_coalesce = rx_adaptive; | |
0d86ebd8 | 603 | |
8ceee660 BH |
604 | return 0; |
605 | } | |
606 | ||
8ceee660 BH |
607 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
608 | struct ethtool_coalesce *coalesce) | |
609 | { | |
767e468c | 610 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 611 | struct efx_channel *channel; |
b548f976 | 612 | unsigned int tx_usecs, rx_usecs; |
9e393b30 BH |
613 | bool adaptive, rx_may_override_tx; |
614 | int rc; | |
8ceee660 | 615 | |
6fb70fd1 | 616 | if (coalesce->use_adaptive_tx_coalesce) |
9f85ee9c | 617 | return -EINVAL; |
8ceee660 | 618 | |
a0c4faf5 BH |
619 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive); |
620 | ||
13225977 BH |
621 | if (coalesce->rx_coalesce_usecs != rx_usecs) |
622 | rx_usecs = coalesce->rx_coalesce_usecs; | |
623 | else | |
624 | rx_usecs = coalesce->rx_coalesce_usecs_irq; | |
625 | ||
6fb70fd1 | 626 | adaptive = coalesce->use_adaptive_rx_coalesce; |
8ceee660 | 627 | |
a0c4faf5 BH |
628 | /* If channels are shared, TX IRQ moderation can be quietly |
629 | * overridden unless it is changed from its old value. | |
630 | */ | |
13225977 BH |
631 | rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs && |
632 | coalesce->tx_coalesce_usecs_irq == tx_usecs); | |
633 | if (coalesce->tx_coalesce_usecs != tx_usecs) | |
634 | tx_usecs = coalesce->tx_coalesce_usecs; | |
635 | else | |
636 | tx_usecs = coalesce->tx_coalesce_usecs_irq; | |
8ceee660 | 637 | |
9e393b30 BH |
638 | rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive, |
639 | rx_may_override_tx); | |
640 | if (rc != 0) | |
641 | return rc; | |
642 | ||
8ceee660 | 643 | efx_for_each_channel(channel, efx) |
ef2b90ee | 644 | efx->type->push_irq_moderation(channel); |
8ceee660 BH |
645 | |
646 | return 0; | |
647 | } | |
648 | ||
4642610c BH |
649 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
650 | struct ethtool_ringparam *ring) | |
651 | { | |
652 | struct efx_nic *efx = netdev_priv(net_dev); | |
653 | ||
654 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; | |
d9317aea | 655 | ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx); |
4642610c BH |
656 | ring->rx_pending = efx->rxq_entries; |
657 | ring->tx_pending = efx->txq_entries; | |
4642610c BH |
658 | } |
659 | ||
660 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, | |
661 | struct ethtool_ringparam *ring) | |
662 | { | |
663 | struct efx_nic *efx = netdev_priv(net_dev); | |
7e6d06f0 | 664 | u32 txq_entries; |
4642610c BH |
665 | |
666 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || | |
667 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || | |
d9317aea | 668 | ring->tx_pending > EFX_TXQ_MAX_ENT(efx)) |
4642610c BH |
669 | return -EINVAL; |
670 | ||
7e6d06f0 | 671 | if (ring->rx_pending < EFX_RXQ_MIN_ENT) { |
4642610c | 672 | netif_err(efx, drv, efx->net_dev, |
7e6d06f0 BH |
673 | "RX queues cannot be smaller than %u\n", |
674 | EFX_RXQ_MIN_ENT); | |
4642610c BH |
675 | return -EINVAL; |
676 | } | |
677 | ||
7e6d06f0 BH |
678 | txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); |
679 | if (txq_entries != ring->tx_pending) | |
680 | netif_warn(efx, drv, efx->net_dev, | |
681 | "increasing TX queue size to minimum of %u\n", | |
682 | txq_entries); | |
683 | ||
684 | return efx_realloc_channels(efx, ring->rx_pending, txq_entries); | |
4642610c BH |
685 | } |
686 | ||
8ceee660 BH |
687 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
688 | struct ethtool_pauseparam *pause) | |
689 | { | |
767e468c | 690 | struct efx_nic *efx = netdev_priv(net_dev); |
b5626946 | 691 | u8 wanted_fc, old_fc; |
d3245b28 | 692 | u32 old_adv; |
d3245b28 BH |
693 | int rc = 0; |
694 | ||
695 | mutex_lock(&efx->mac_lock); | |
8ceee660 | 696 | |
04cc8cac BH |
697 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
698 | (pause->tx_pause ? EFX_FC_TX : 0) | | |
699 | (pause->autoneg ? EFX_FC_AUTO : 0)); | |
700 | ||
701 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { | |
62776d03 BH |
702 | netif_dbg(efx, drv, efx->net_dev, |
703 | "Flow control unsupported: tx ON rx OFF\n"); | |
d3245b28 BH |
704 | rc = -EINVAL; |
705 | goto out; | |
04cc8cac BH |
706 | } |
707 | ||
d3245b28 | 708 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
62776d03 BH |
709 | netif_dbg(efx, drv, efx->net_dev, |
710 | "Autonegotiation is disabled\n"); | |
d3245b28 BH |
711 | rc = -EINVAL; |
712 | goto out; | |
04cc8cac BH |
713 | } |
714 | ||
9dd3a13b BH |
715 | /* Hook for Falcon bug 11482 workaround */ |
716 | if (efx->type->prepare_enable_fc_tx && | |
717 | (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) | |
718 | efx->type->prepare_enable_fc_tx(efx); | |
04cc8cac | 719 | |
d3245b28 BH |
720 | old_adv = efx->link_advertising; |
721 | old_fc = efx->wanted_fc; | |
722 | efx_link_set_wanted_fc(efx, wanted_fc); | |
723 | if (efx->link_advertising != old_adv || | |
724 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { | |
725 | rc = efx->phy_op->reconfigure(efx); | |
726 | if (rc) { | |
62776d03 BH |
727 | netif_err(efx, drv, efx->net_dev, |
728 | "Unable to advertise requested flow " | |
729 | "control setting\n"); | |
d3245b28 BH |
730 | goto out; |
731 | } | |
732 | } | |
04cc8cac | 733 | |
d3245b28 BH |
734 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
735 | * if the user just changed the advertised capabilities, but there's no | |
736 | * harm doing this twice */ | |
0d322413 | 737 | efx_mac_reconfigure(efx); |
04cc8cac | 738 | |
d3245b28 | 739 | out: |
04cc8cac | 740 | mutex_unlock(&efx->mac_lock); |
8ceee660 | 741 | |
d3245b28 | 742 | return rc; |
8ceee660 BH |
743 | } |
744 | ||
745 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, | |
746 | struct ethtool_pauseparam *pause) | |
747 | { | |
767e468c | 748 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 749 | |
04cc8cac BH |
750 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
751 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); | |
752 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); | |
8ceee660 BH |
753 | } |
754 | ||
89c758fa BH |
755 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
756 | struct ethtool_wolinfo *wol) | |
757 | { | |
758 | struct efx_nic *efx = netdev_priv(net_dev); | |
759 | return efx->type->get_wol(efx, wol); | |
760 | } | |
761 | ||
762 | ||
763 | static int efx_ethtool_set_wol(struct net_device *net_dev, | |
764 | struct ethtool_wolinfo *wol) | |
765 | { | |
766 | struct efx_nic *efx = netdev_priv(net_dev); | |
767 | return efx->type->set_wol(efx, wol->wolopts); | |
768 | } | |
769 | ||
d215697f | 770 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
eb9f6744 BH |
771 | { |
772 | struct efx_nic *efx = netdev_priv(net_dev); | |
0e2a9c7c | 773 | int rc; |
eb9f6744 | 774 | |
0e2a9c7c BH |
775 | rc = efx->type->map_reset_flags(flags); |
776 | if (rc < 0) | |
777 | return rc; | |
eb9f6744 | 778 | |
0e2a9c7c | 779 | return efx_reset(efx, rc); |
eb9f6744 BH |
780 | } |
781 | ||
7c460d9b | 782 | /* MAC address mask including only I/G bit */ |
cd84ff4d | 783 | static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0}; |
c274d65c | 784 | |
0e0c3408 | 785 | #define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
a7ad40d0 | 786 | #define IP_PROTO_FULL_MASK 0xFF |
0e0c3408 | 787 | #define PORT_FULL_MASK ((__force __be16)~0) |
7c460d9b | 788 | #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
0e0c3408 | 789 | |
a7ad40d0 EC |
790 | static inline void ip6_fill_mask(__be32 *mask) |
791 | { | |
792 | mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0; | |
793 | } | |
794 | ||
b2bb7b77 BH |
795 | static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
796 | struct ethtool_rx_flow_spec *rule) | |
797 | { | |
798 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; | |
799 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
a7ad40d0 EC |
800 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
801 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; | |
802 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; | |
803 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; | |
804 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; | |
805 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; | |
c274d65c BH |
806 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
807 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
b2bb7b77 | 808 | struct efx_filter_spec spec; |
b2bb7b77 BH |
809 | int rc; |
810 | ||
811 | rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, | |
812 | rule->location, &spec); | |
813 | if (rc) | |
814 | return rc; | |
815 | ||
f26e958c | 816 | if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
b2bb7b77 BH |
817 | rule->ring_cookie = RX_CLS_FLOW_DISC; |
818 | else | |
819 | rule->ring_cookie = spec.dmaq_id; | |
820 | ||
7c460d9b BH |
821 | if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
822 | spec.ether_type == htons(ETH_P_IP) && | |
823 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && | |
824 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && | |
825 | !(spec.match_flags & | |
826 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
827 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
828 | EFX_FILTER_MATCH_IP_PROTO | | |
829 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { | |
830 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? | |
831 | TCP_V4_FLOW : UDP_V4_FLOW); | |
832 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
833 | ip_entry->ip4dst = spec.loc_host[0]; | |
834 | ip_mask->ip4dst = IP4_ADDR_FULL_MASK; | |
835 | } | |
836 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
837 | ip_entry->ip4src = spec.rem_host[0]; | |
838 | ip_mask->ip4src = IP4_ADDR_FULL_MASK; | |
839 | } | |
840 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { | |
841 | ip_entry->pdst = spec.loc_port; | |
842 | ip_mask->pdst = PORT_FULL_MASK; | |
843 | } | |
844 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { | |
845 | ip_entry->psrc = spec.rem_port; | |
846 | ip_mask->psrc = PORT_FULL_MASK; | |
847 | } | |
a7ad40d0 EC |
848 | } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
849 | spec.ether_type == htons(ETH_P_IPV6) && | |
850 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && | |
851 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && | |
852 | !(spec.match_flags & | |
853 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
854 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
855 | EFX_FILTER_MATCH_IP_PROTO | | |
856 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { | |
857 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? | |
858 | TCP_V6_FLOW : UDP_V6_FLOW); | |
859 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
860 | memcpy(ip6_entry->ip6dst, spec.loc_host, | |
861 | sizeof(ip6_entry->ip6dst)); | |
862 | ip6_fill_mask(ip6_mask->ip6dst); | |
863 | } | |
864 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
865 | memcpy(ip6_entry->ip6src, spec.rem_host, | |
866 | sizeof(ip6_entry->ip6src)); | |
867 | ip6_fill_mask(ip6_mask->ip6src); | |
868 | } | |
869 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { | |
870 | ip6_entry->pdst = spec.loc_port; | |
871 | ip6_mask->pdst = PORT_FULL_MASK; | |
872 | } | |
873 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { | |
874 | ip6_entry->psrc = spec.rem_port; | |
875 | ip6_mask->psrc = PORT_FULL_MASK; | |
876 | } | |
7c460d9b BH |
877 | } else if (!(spec.match_flags & |
878 | ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | | |
879 | EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | | |
880 | EFX_FILTER_MATCH_OUTER_VID))) { | |
b2bb7b77 | 881 | rule->flow_type = ETHER_FLOW; |
7c460d9b BH |
882 | if (spec.match_flags & |
883 | (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { | |
cd84ff4d | 884 | ether_addr_copy(mac_entry->h_dest, spec.loc_mac); |
7c460d9b | 885 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) |
cd84ff4d | 886 | eth_broadcast_addr(mac_mask->h_dest); |
7c460d9b | 887 | else |
cd84ff4d EC |
888 | ether_addr_copy(mac_mask->h_dest, |
889 | mac_addr_ig_mask); | |
b2bb7b77 | 890 | } |
7c460d9b | 891 | if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
cd84ff4d EC |
892 | ether_addr_copy(mac_entry->h_source, spec.rem_mac); |
893 | eth_broadcast_addr(mac_mask->h_source); | |
7c460d9b BH |
894 | } |
895 | if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { | |
896 | mac_entry->h_proto = spec.ether_type; | |
897 | mac_mask->h_proto = ETHER_TYPE_FULL_MASK; | |
898 | } | |
a7ad40d0 EC |
899 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
900 | spec.ether_type == htons(ETH_P_IP) && | |
901 | !(spec.match_flags & | |
902 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
903 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
904 | EFX_FILTER_MATCH_IP_PROTO))) { | |
905 | rule->flow_type = IPV4_USER_FLOW; | |
906 | uip_entry->ip_ver = ETH_RX_NFC_IP4; | |
907 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { | |
908 | uip_mask->proto = IP_PROTO_FULL_MASK; | |
909 | uip_entry->proto = spec.ip_proto; | |
910 | } | |
911 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
912 | uip_entry->ip4dst = spec.loc_host[0]; | |
913 | uip_mask->ip4dst = IP4_ADDR_FULL_MASK; | |
914 | } | |
915 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
916 | uip_entry->ip4src = spec.rem_host[0]; | |
917 | uip_mask->ip4src = IP4_ADDR_FULL_MASK; | |
918 | } | |
919 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && | |
920 | spec.ether_type == htons(ETH_P_IPV6) && | |
921 | !(spec.match_flags & | |
922 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
923 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
924 | EFX_FILTER_MATCH_IP_PROTO))) { | |
925 | rule->flow_type = IPV6_USER_FLOW; | |
926 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { | |
927 | uip6_mask->l4_proto = IP_PROTO_FULL_MASK; | |
928 | uip6_entry->l4_proto = spec.ip_proto; | |
929 | } | |
930 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
931 | memcpy(uip6_entry->ip6dst, spec.loc_host, | |
932 | sizeof(uip6_entry->ip6dst)); | |
933 | ip6_fill_mask(uip6_mask->ip6dst); | |
934 | } | |
935 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
936 | memcpy(uip6_entry->ip6src, spec.rem_host, | |
937 | sizeof(uip6_entry->ip6src)); | |
938 | ip6_fill_mask(uip6_mask->ip6src); | |
939 | } | |
7c460d9b BH |
940 | } else { |
941 | /* The above should handle all filters that we insert */ | |
942 | WARN_ON(1); | |
943 | return -EINVAL; | |
b2bb7b77 BH |
944 | } |
945 | ||
7c460d9b BH |
946 | if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
947 | rule->flow_type |= FLOW_EXT; | |
948 | rule->h_ext.vlan_tci = spec.outer_vid; | |
949 | rule->m_ext.vlan_tci = htons(0xfff); | |
b2bb7b77 | 950 | } |
7c460d9b | 951 | |
b2bb7b77 BH |
952 | return rc; |
953 | } | |
954 | ||
765c9f46 BH |
955 | static int |
956 | efx_ethtool_get_rxnfc(struct net_device *net_dev, | |
b2bb7b77 | 957 | struct ethtool_rxnfc *info, u32 *rule_locs) |
765c9f46 BH |
958 | { |
959 | struct efx_nic *efx = netdev_priv(net_dev); | |
960 | ||
961 | switch (info->cmd) { | |
962 | case ETHTOOL_GRXRINGS: | |
963 | info->data = efx->n_rx_channels; | |
964 | return 0; | |
965 | ||
966 | case ETHTOOL_GRXFH: { | |
967 | unsigned min_revision = 0; | |
968 | ||
969 | info->data = 0; | |
970 | switch (info->flow_type) { | |
971 | case TCP_V4_FLOW: | |
972 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
973 | /* fall through */ | |
974 | case UDP_V4_FLOW: | |
975 | case SCTP_V4_FLOW: | |
976 | case AH_ESP_V4_FLOW: | |
977 | case IPV4_FLOW: | |
978 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
979 | min_revision = EFX_REV_FALCON_B0; | |
980 | break; | |
981 | case TCP_V6_FLOW: | |
982 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
983 | /* fall through */ | |
984 | case UDP_V6_FLOW: | |
985 | case SCTP_V6_FLOW: | |
986 | case AH_ESP_V6_FLOW: | |
987 | case IPV6_FLOW: | |
988 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
989 | min_revision = EFX_REV_SIENA_A0; | |
990 | break; | |
991 | default: | |
992 | break; | |
993 | } | |
994 | if (efx_nic_rev(efx) < min_revision) | |
995 | info->data = 0; | |
996 | return 0; | |
997 | } | |
998 | ||
b2bb7b77 BH |
999 | case ETHTOOL_GRXCLSRLCNT: |
1000 | info->data = efx_filter_get_rx_id_limit(efx); | |
1001 | if (info->data == 0) | |
1002 | return -EOPNOTSUPP; | |
1003 | info->data |= RX_CLS_LOC_SPECIAL; | |
1004 | info->rule_cnt = | |
1005 | efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); | |
1006 | return 0; | |
1007 | ||
1008 | case ETHTOOL_GRXCLSRULE: | |
1009 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
1010 | return -EOPNOTSUPP; | |
1011 | return efx_ethtool_get_class_rule(efx, &info->fs); | |
1012 | ||
1013 | case ETHTOOL_GRXCLSRLALL: { | |
1014 | s32 rc; | |
1015 | info->data = efx_filter_get_rx_id_limit(efx); | |
1016 | if (info->data == 0) | |
1017 | return -EOPNOTSUPP; | |
1018 | rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, | |
1019 | rule_locs, info->rule_cnt); | |
1020 | if (rc < 0) | |
1021 | return rc; | |
1022 | info->rule_cnt = rc; | |
1023 | return 0; | |
1024 | } | |
1025 | ||
765c9f46 BH |
1026 | default: |
1027 | return -EOPNOTSUPP; | |
1028 | } | |
1029 | } | |
1030 | ||
a7ad40d0 EC |
1031 | static inline bool ip6_mask_is_full(__be32 mask[4]) |
1032 | { | |
1033 | return !~(mask[0] & mask[1] & mask[2] & mask[3]); | |
1034 | } | |
1035 | ||
1036 | static inline bool ip6_mask_is_empty(__be32 mask[4]) | |
1037 | { | |
1038 | return !(mask[0] | mask[1] | mask[2] | mask[3]); | |
1039 | } | |
1040 | ||
b2bb7b77 BH |
1041 | static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
1042 | struct ethtool_rx_flow_spec *rule) | |
b4187e42 | 1043 | { |
b2bb7b77 BH |
1044 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
1045 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
a7ad40d0 EC |
1046 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
1047 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; | |
1048 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; | |
1049 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; | |
1050 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; | |
1051 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; | |
b2bb7b77 BH |
1052 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
1053 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
1054 | struct efx_filter_spec spec; | |
c39d35eb | 1055 | int rc; |
b4187e42 | 1056 | |
b2bb7b77 | 1057 | /* Check that user wants us to choose the location */ |
9e0f9a10 | 1058 | if (rule->location != RX_CLS_LOC_ANY) |
b4187e42 BH |
1059 | return -EINVAL; |
1060 | ||
b2bb7b77 BH |
1061 | /* Range-check ring_cookie */ |
1062 | if (rule->ring_cookie >= efx->n_rx_channels && | |
1063 | rule->ring_cookie != RX_CLS_FLOW_DISC) | |
b4187e42 BH |
1064 | return -EINVAL; |
1065 | ||
b2bb7b77 BH |
1066 | /* Check for unsupported extensions */ |
1067 | if ((rule->flow_type & FLOW_EXT) && | |
0e0c3408 | 1068 | (rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
b2bb7b77 BH |
1069 | rule->m_ext.data[1])) |
1070 | return -EINVAL; | |
1071 | ||
85740cdf BH |
1072 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, |
1073 | efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, | |
b2bb7b77 | 1074 | (rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
f26e958c | 1075 | EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
c39d35eb | 1076 | |
7c460d9b | 1077 | switch (rule->flow_type & ~FLOW_EXT) { |
b4187e42 | 1078 | case TCP_V4_FLOW: |
7c460d9b BH |
1079 | case UDP_V4_FLOW: |
1080 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | | |
1081 | EFX_FILTER_MATCH_IP_PROTO); | |
1082 | spec.ether_type = htons(ETH_P_IP); | |
1083 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? | |
1084 | IPPROTO_TCP : IPPROTO_UDP); | |
1085 | if (ip_mask->ip4dst) { | |
1086 | if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) | |
1087 | return -EINVAL; | |
1088 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1089 | spec.loc_host[0] = ip_entry->ip4dst; | |
1090 | } | |
1091 | if (ip_mask->ip4src) { | |
1092 | if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) | |
1093 | return -EINVAL; | |
1094 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1095 | spec.rem_host[0] = ip_entry->ip4src; | |
1096 | } | |
1097 | if (ip_mask->pdst) { | |
1098 | if (ip_mask->pdst != PORT_FULL_MASK) | |
1099 | return -EINVAL; | |
1100 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; | |
1101 | spec.loc_port = ip_entry->pdst; | |
1102 | } | |
1103 | if (ip_mask->psrc) { | |
1104 | if (ip_mask->psrc != PORT_FULL_MASK) | |
1105 | return -EINVAL; | |
1106 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; | |
1107 | spec.rem_port = ip_entry->psrc; | |
1108 | } | |
1109 | if (ip_mask->tos) | |
b4187e42 BH |
1110 | return -EINVAL; |
1111 | break; | |
c274d65c | 1112 | |
a7ad40d0 EC |
1113 | case TCP_V6_FLOW: |
1114 | case UDP_V6_FLOW: | |
1115 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | | |
1116 | EFX_FILTER_MATCH_IP_PROTO); | |
1117 | spec.ether_type = htons(ETH_P_IPV6); | |
1118 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ? | |
1119 | IPPROTO_TCP : IPPROTO_UDP); | |
1120 | if (!ip6_mask_is_empty(ip6_mask->ip6dst)) { | |
1121 | if (!ip6_mask_is_full(ip6_mask->ip6dst)) | |
1122 | return -EINVAL; | |
1123 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1124 | memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host)); | |
1125 | } | |
1126 | if (!ip6_mask_is_empty(ip6_mask->ip6src)) { | |
1127 | if (!ip6_mask_is_full(ip6_mask->ip6src)) | |
1128 | return -EINVAL; | |
1129 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1130 | memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host)); | |
1131 | } | |
1132 | if (ip6_mask->pdst) { | |
1133 | if (ip6_mask->pdst != PORT_FULL_MASK) | |
1134 | return -EINVAL; | |
1135 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; | |
1136 | spec.loc_port = ip6_entry->pdst; | |
1137 | } | |
1138 | if (ip6_mask->psrc) { | |
1139 | if (ip6_mask->psrc != PORT_FULL_MASK) | |
1140 | return -EINVAL; | |
1141 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; | |
1142 | spec.rem_port = ip6_entry->psrc; | |
1143 | } | |
1144 | if (ip6_mask->tclass) | |
1145 | return -EINVAL; | |
1146 | break; | |
1147 | ||
1148 | case IPV4_USER_FLOW: | |
1149 | if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver || | |
1150 | uip_entry->ip_ver != ETH_RX_NFC_IP4) | |
1151 | return -EINVAL; | |
1152 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; | |
1153 | spec.ether_type = htons(ETH_P_IP); | |
1154 | if (uip_mask->ip4dst) { | |
1155 | if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK) | |
1156 | return -EINVAL; | |
1157 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1158 | spec.loc_host[0] = uip_entry->ip4dst; | |
1159 | } | |
1160 | if (uip_mask->ip4src) { | |
1161 | if (uip_mask->ip4src != IP4_ADDR_FULL_MASK) | |
1162 | return -EINVAL; | |
1163 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1164 | spec.rem_host[0] = uip_entry->ip4src; | |
1165 | } | |
1166 | if (uip_mask->proto) { | |
1167 | if (uip_mask->proto != IP_PROTO_FULL_MASK) | |
1168 | return -EINVAL; | |
1169 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; | |
1170 | spec.ip_proto = uip_entry->proto; | |
1171 | } | |
1172 | break; | |
1173 | ||
1174 | case IPV6_USER_FLOW: | |
1175 | if (uip6_mask->l4_4_bytes || uip6_mask->tclass) | |
1176 | return -EINVAL; | |
1177 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; | |
1178 | spec.ether_type = htons(ETH_P_IPV6); | |
1179 | if (!ip6_mask_is_empty(uip6_mask->ip6dst)) { | |
1180 | if (!ip6_mask_is_full(uip6_mask->ip6dst)) | |
1181 | return -EINVAL; | |
1182 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1183 | memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host)); | |
1184 | } | |
1185 | if (!ip6_mask_is_empty(uip6_mask->ip6src)) { | |
1186 | if (!ip6_mask_is_full(uip6_mask->ip6src)) | |
1187 | return -EINVAL; | |
1188 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1189 | memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host)); | |
1190 | } | |
1191 | if (uip6_mask->l4_proto) { | |
1192 | if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK) | |
1193 | return -EINVAL; | |
1194 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; | |
1195 | spec.ip_proto = uip6_entry->l4_proto; | |
1196 | } | |
1197 | break; | |
1198 | ||
7c460d9b BH |
1199 | case ETHER_FLOW: |
1200 | if (!is_zero_ether_addr(mac_mask->h_dest)) { | |
1201 | if (ether_addr_equal(mac_mask->h_dest, | |
1202 | mac_addr_ig_mask)) | |
1203 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; | |
1204 | else if (is_broadcast_ether_addr(mac_mask->h_dest)) | |
1205 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; | |
c274d65c | 1206 | else |
7c460d9b | 1207 | return -EINVAL; |
cd84ff4d | 1208 | ether_addr_copy(spec.loc_mac, mac_entry->h_dest); |
c274d65c | 1209 | } |
7c460d9b BH |
1210 | if (!is_zero_ether_addr(mac_mask->h_source)) { |
1211 | if (!is_broadcast_ether_addr(mac_mask->h_source)) | |
1212 | return -EINVAL; | |
1213 | spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; | |
cd84ff4d | 1214 | ether_addr_copy(spec.rem_mac, mac_entry->h_source); |
7c460d9b BH |
1215 | } |
1216 | if (mac_mask->h_proto) { | |
1217 | if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) | |
1218 | return -EINVAL; | |
1219 | spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; | |
1220 | spec.ether_type = mac_entry->h_proto; | |
c274d65c | 1221 | } |
b4187e42 | 1222 | break; |
c39d35eb | 1223 | |
b4187e42 BH |
1224 | default: |
1225 | return -EINVAL; | |
1226 | } | |
1227 | ||
7c460d9b BH |
1228 | if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
1229 | if (rule->m_ext.vlan_tci != htons(0xfff)) | |
1230 | return -EINVAL; | |
1231 | spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; | |
1232 | spec.outer_vid = rule->h_ext.vlan_tci; | |
1233 | } | |
1234 | ||
b2bb7b77 BH |
1235 | rc = efx_filter_insert_filter(efx, &spec, true); |
1236 | if (rc < 0) | |
1237 | return rc; | |
47a8467c | 1238 | |
b2bb7b77 BH |
1239 | rule->location = rc; |
1240 | return 0; | |
1241 | } | |
1242 | ||
1243 | static int efx_ethtool_set_rxnfc(struct net_device *net_dev, | |
1244 | struct ethtool_rxnfc *info) | |
1245 | { | |
1246 | struct efx_nic *efx = netdev_priv(net_dev); | |
1247 | ||
1248 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
1249 | return -EOPNOTSUPP; | |
1250 | ||
1251 | switch (info->cmd) { | |
1252 | case ETHTOOL_SRXCLSRLINS: | |
1253 | return efx_ethtool_set_class_rule(efx, &info->fs); | |
1254 | ||
1255 | case ETHTOOL_SRXCLSRLDEL: | |
1256 | return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, | |
1257 | info->fs.location); | |
1258 | ||
1259 | default: | |
1260 | return -EOPNOTSUPP; | |
1261 | } | |
b4187e42 BH |
1262 | } |
1263 | ||
7850f63f | 1264 | static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev) |
765c9f46 BH |
1265 | { |
1266 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1267 | |
cd2d5b52 BH |
1268 | return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 || |
1269 | efx->n_rx_channels == 1) ? | |
7850f63f BH |
1270 | 0 : ARRAY_SIZE(efx->rx_indir_table)); |
1271 | } | |
1272 | ||
892311f6 EP |
1273 | static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key, |
1274 | u8 *hfunc) | |
7850f63f BH |
1275 | { |
1276 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1277 | |
892311f6 EP |
1278 | if (hfunc) |
1279 | *hfunc = ETH_RSS_HASH_TOP; | |
1280 | if (indir) | |
1281 | memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table)); | |
765c9f46 BH |
1282 | return 0; |
1283 | } | |
1284 | ||
892311f6 EP |
1285 | static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir, |
1286 | const u8 *key, const u8 hfunc) | |
765c9f46 BH |
1287 | { |
1288 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1289 | |
892311f6 EP |
1290 | /* We do not allow change in unsupported parameters */ |
1291 | if (key || | |
1292 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) | |
1293 | return -EOPNOTSUPP; | |
1294 | if (!indir) | |
1295 | return 0; | |
267c0157 JC |
1296 | |
1297 | return efx->type->rx_push_rss_config(efx, true, indir); | |
765c9f46 BH |
1298 | } |
1299 | ||
b51ca34a FW |
1300 | static int efx_ethtool_get_ts_info(struct net_device *net_dev, |
1301 | struct ethtool_ts_info *ts_info) | |
62ebac92 BH |
1302 | { |
1303 | struct efx_nic *efx = netdev_priv(net_dev); | |
1304 | ||
1305 | /* Software capabilities */ | |
1306 | ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE | | |
1307 | SOF_TIMESTAMPING_SOFTWARE); | |
1308 | ts_info->phc_index = -1; | |
1309 | ||
1310 | efx_ptp_get_ts_info(efx, ts_info); | |
1311 | return 0; | |
1312 | } | |
1313 | ||
c087bd2c SH |
1314 | static int efx_ethtool_get_module_eeprom(struct net_device *net_dev, |
1315 | struct ethtool_eeprom *ee, | |
1316 | u8 *data) | |
1317 | { | |
1318 | struct efx_nic *efx = netdev_priv(net_dev); | |
1319 | int ret; | |
1320 | ||
1321 | if (!efx->phy_op || !efx->phy_op->get_module_eeprom) | |
1322 | return -EOPNOTSUPP; | |
1323 | ||
1324 | mutex_lock(&efx->mac_lock); | |
1325 | ret = efx->phy_op->get_module_eeprom(efx, ee, data); | |
1326 | mutex_unlock(&efx->mac_lock); | |
1327 | ||
1328 | return ret; | |
1329 | } | |
1330 | ||
1331 | static int efx_ethtool_get_module_info(struct net_device *net_dev, | |
1332 | struct ethtool_modinfo *modinfo) | |
1333 | { | |
1334 | struct efx_nic *efx = netdev_priv(net_dev); | |
1335 | int ret; | |
1336 | ||
1337 | if (!efx->phy_op || !efx->phy_op->get_module_info) | |
1338 | return -EOPNOTSUPP; | |
1339 | ||
1340 | mutex_lock(&efx->mac_lock); | |
1341 | ret = efx->phy_op->get_module_info(efx, modinfo); | |
1342 | mutex_unlock(&efx->mac_lock); | |
1343 | ||
1344 | return ret; | |
1345 | } | |
1346 | ||
0fc0b732 | 1347 | const struct ethtool_ops efx_ethtool_ops = { |
8ceee660 BH |
1348 | .get_settings = efx_ethtool_get_settings, |
1349 | .set_settings = efx_ethtool_set_settings, | |
1350 | .get_drvinfo = efx_ethtool_get_drvinfo, | |
5b98c1bf BH |
1351 | .get_regs_len = efx_ethtool_get_regs_len, |
1352 | .get_regs = efx_ethtool_get_regs, | |
62776d03 BH |
1353 | .get_msglevel = efx_ethtool_get_msglevel, |
1354 | .set_msglevel = efx_ethtool_set_msglevel, | |
8ceee660 | 1355 | .nway_reset = efx_ethtool_nway_reset, |
ed4ba4b5 | 1356 | .get_link = ethtool_op_get_link, |
8ceee660 BH |
1357 | .get_coalesce = efx_ethtool_get_coalesce, |
1358 | .set_coalesce = efx_ethtool_set_coalesce, | |
4642610c BH |
1359 | .get_ringparam = efx_ethtool_get_ringparam, |
1360 | .set_ringparam = efx_ethtool_set_ringparam, | |
8ceee660 BH |
1361 | .get_pauseparam = efx_ethtool_get_pauseparam, |
1362 | .set_pauseparam = efx_ethtool_set_pauseparam, | |
3594e131 | 1363 | .get_sset_count = efx_ethtool_get_sset_count, |
3273c2e8 | 1364 | .self_test = efx_ethtool_self_test, |
8ceee660 | 1365 | .get_strings = efx_ethtool_get_strings, |
c5e129ac | 1366 | .set_phys_id = efx_ethtool_phys_id, |
8ceee660 | 1367 | .get_ethtool_stats = efx_ethtool_get_stats, |
89c758fa BH |
1368 | .get_wol = efx_ethtool_get_wol, |
1369 | .set_wol = efx_ethtool_set_wol, | |
eb9f6744 | 1370 | .reset = efx_ethtool_reset, |
765c9f46 | 1371 | .get_rxnfc = efx_ethtool_get_rxnfc, |
b2bb7b77 | 1372 | .set_rxnfc = efx_ethtool_set_rxnfc, |
7850f63f | 1373 | .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, |
fe62d001 BH |
1374 | .get_rxfh = efx_ethtool_get_rxfh, |
1375 | .set_rxfh = efx_ethtool_set_rxfh, | |
62ebac92 | 1376 | .get_ts_info = efx_ethtool_get_ts_info, |
c087bd2c SH |
1377 | .get_module_info = efx_ethtool_get_module_info, |
1378 | .get_module_eeprom = efx_ethtool_get_module_eeprom, | |
8ceee660 | 1379 | }; |