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