1
2
3
4
5
6
7
8#include <linux/netdevice.h>
9#include <linux/ethtool.h>
10#include <linux/rtnetlink.h>
11#include <linux/in.h>
12#include "net_driver.h"
13#include "workarounds.h"
14#include "selftest.h"
15#include "efx.h"
16#include "filter.h"
17#include "nic.h"
18
19struct ef4_sw_stat_desc {
20 const char *name;
21 enum {
22 EF4_ETHTOOL_STAT_SOURCE_nic,
23 EF4_ETHTOOL_STAT_SOURCE_channel,
24 EF4_ETHTOOL_STAT_SOURCE_tx_queue
25 } source;
26 unsigned offset;
27 u64(*get_stat) (void *field);
28};
29
30
31#define EF4_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
32 get_stat_function) { \
33 .name = #stat_name, \
34 .source = EF4_ETHTOOL_STAT_SOURCE_##source_name, \
35 .offset = ((((field_type *) 0) == \
36 &((struct ef4_##source_name *)0)->field) ? \
37 offsetof(struct ef4_##source_name, field) : \
38 offsetof(struct ef4_##source_name, field)), \
39 .get_stat = get_stat_function, \
40}
41
42static u64 ef4_get_uint_stat(void *field)
43{
44 return *(unsigned int *)field;
45}
46
47static u64 ef4_get_atomic_stat(void *field)
48{
49 return atomic_read((atomic_t *) field);
50}
51
52#define EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
53 EF4_ETHTOOL_STAT(field, nic, field, \
54 atomic_t, ef4_get_atomic_stat)
55
56#define EF4_ETHTOOL_UINT_CHANNEL_STAT(field) \
57 EF4_ETHTOOL_STAT(field, channel, n_##field, \
58 unsigned int, ef4_get_uint_stat)
59
60#define EF4_ETHTOOL_UINT_TXQ_STAT(field) \
61 EF4_ETHTOOL_STAT(tx_##field, tx_queue, field, \
62 unsigned int, ef4_get_uint_stat)
63
64static const struct ef4_sw_stat_desc ef4_sw_stat_desc[] = {
65 EF4_ETHTOOL_UINT_TXQ_STAT(merge_events),
66 EF4_ETHTOOL_UINT_TXQ_STAT(pushes),
67 EF4_ETHTOOL_UINT_TXQ_STAT(cb_packets),
68 EF4_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
69 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
70 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
71 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
72 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
73 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
74 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
75 EF4_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
76};
77
78#define EF4_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(ef4_sw_stat_desc)
79
80#define EF4_ETHTOOL_EEPROM_MAGIC 0xEFAB
81
82
83
84
85
86
87
88
89
90static int ef4_ethtool_phys_id(struct net_device *net_dev,
91 enum ethtool_phys_id_state state)
92{
93 struct ef4_nic *efx = netdev_priv(net_dev);
94 enum ef4_led_mode mode = EF4_LED_DEFAULT;
95
96 switch (state) {
97 case ETHTOOL_ID_ON:
98 mode = EF4_LED_ON;
99 break;
100 case ETHTOOL_ID_OFF:
101 mode = EF4_LED_OFF;
102 break;
103 case ETHTOOL_ID_INACTIVE:
104 mode = EF4_LED_DEFAULT;
105 break;
106 case ETHTOOL_ID_ACTIVE:
107 return 1;
108 }
109
110 efx->type->set_id_led(efx, mode);
111 return 0;
112}
113
114
115static int
116ef4_ethtool_get_link_ksettings(struct net_device *net_dev,
117 struct ethtool_link_ksettings *cmd)
118{
119 struct ef4_nic *efx = netdev_priv(net_dev);
120 struct ef4_link_state *link_state = &efx->link_state;
121
122 mutex_lock(&efx->mac_lock);
123 efx->phy_op->get_link_ksettings(efx, cmd);
124 mutex_unlock(&efx->mac_lock);
125
126
127 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
128 ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause);
129
130 if (LOOPBACK_INTERNAL(efx)) {
131 cmd->base.speed = link_state->speed;
132 cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
133 }
134
135 return 0;
136}
137
138
139static int
140ef4_ethtool_set_link_ksettings(struct net_device *net_dev,
141 const struct ethtool_link_ksettings *cmd)
142{
143 struct ef4_nic *efx = netdev_priv(net_dev);
144 int rc;
145
146
147 if ((cmd->base.speed == SPEED_1000) &&
148 (cmd->base.duplex != DUPLEX_FULL)) {
149 netif_dbg(efx, drv, efx->net_dev,
150 "rejecting unsupported 1000Mbps HD setting\n");
151 return -EINVAL;
152 }
153
154 mutex_lock(&efx->mac_lock);
155 rc = efx->phy_op->set_link_ksettings(efx, cmd);
156 mutex_unlock(&efx->mac_lock);
157 return rc;
158}
159
160static void ef4_ethtool_get_drvinfo(struct net_device *net_dev,
161 struct ethtool_drvinfo *info)
162{
163 struct ef4_nic *efx = netdev_priv(net_dev);
164
165 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
166 strlcpy(info->version, EF4_DRIVER_VERSION, sizeof(info->version));
167 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
168}
169
170static int ef4_ethtool_get_regs_len(struct net_device *net_dev)
171{
172 return ef4_nic_get_regs_len(netdev_priv(net_dev));
173}
174
175static void ef4_ethtool_get_regs(struct net_device *net_dev,
176 struct ethtool_regs *regs, void *buf)
177{
178 struct ef4_nic *efx = netdev_priv(net_dev);
179
180 regs->version = efx->type->revision;
181 ef4_nic_get_regs(efx, buf);
182}
183
184static u32 ef4_ethtool_get_msglevel(struct net_device *net_dev)
185{
186 struct ef4_nic *efx = netdev_priv(net_dev);
187 return efx->msg_enable;
188}
189
190static void ef4_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
191{
192 struct ef4_nic *efx = netdev_priv(net_dev);
193 efx->msg_enable = msg_enable;
194}
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209static void ef4_fill_test(unsigned int test_index, u8 *strings, u64 *data,
210 int *test, const char *unit_format, int unit_id,
211 const char *test_format, const char *test_id)
212{
213 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
214
215
216 if (data)
217 data[test_index] = *test;
218
219
220 if (strings) {
221 if (strchr(unit_format, '%'))
222 snprintf(unit_str, sizeof(unit_str),
223 unit_format, unit_id);
224 else
225 strcpy(unit_str, unit_format);
226 snprintf(test_str, sizeof(test_str), test_format, test_id);
227 snprintf(strings + test_index * ETH_GSTRING_LEN,
228 ETH_GSTRING_LEN,
229 "%-6s %-24s", unit_str, test_str);
230 }
231}
232
233#define EF4_CHANNEL_NAME(_channel) "chan%d", _channel->channel
234#define EF4_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
235#define EF4_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
236#define EF4_LOOPBACK_NAME(_mode, _counter) \
237 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, ef4_loopback_mode)
238
239
240
241
242
243
244
245
246
247
248
249
250
251static int ef4_fill_loopback_test(struct ef4_nic *efx,
252 struct ef4_loopback_self_tests *lb_tests,
253 enum ef4_loopback_mode mode,
254 unsigned int test_index,
255 u8 *strings, u64 *data)
256{
257 struct ef4_channel *channel =
258 ef4_get_channel(efx, efx->tx_channel_offset);
259 struct ef4_tx_queue *tx_queue;
260
261 ef4_for_each_channel_tx_queue(tx_queue, channel) {
262 ef4_fill_test(test_index++, strings, data,
263 &lb_tests->tx_sent[tx_queue->queue],
264 EF4_TX_QUEUE_NAME(tx_queue),
265 EF4_LOOPBACK_NAME(mode, "tx_sent"));
266 ef4_fill_test(test_index++, strings, data,
267 &lb_tests->tx_done[tx_queue->queue],
268 EF4_TX_QUEUE_NAME(tx_queue),
269 EF4_LOOPBACK_NAME(mode, "tx_done"));
270 }
271 ef4_fill_test(test_index++, strings, data,
272 &lb_tests->rx_good,
273 "rx", 0,
274 EF4_LOOPBACK_NAME(mode, "rx_good"));
275 ef4_fill_test(test_index++, strings, data,
276 &lb_tests->rx_bad,
277 "rx", 0,
278 EF4_LOOPBACK_NAME(mode, "rx_bad"));
279
280 return test_index;
281}
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296static int ef4_ethtool_fill_self_tests(struct ef4_nic *efx,
297 struct ef4_self_tests *tests,
298 u8 *strings, u64 *data)
299{
300 struct ef4_channel *channel;
301 unsigned int n = 0, i;
302 enum ef4_loopback_mode mode;
303
304 ef4_fill_test(n++, strings, data, &tests->phy_alive,
305 "phy", 0, "alive", NULL);
306 ef4_fill_test(n++, strings, data, &tests->nvram,
307 "core", 0, "nvram", NULL);
308 ef4_fill_test(n++, strings, data, &tests->interrupt,
309 "core", 0, "interrupt", NULL);
310
311
312 ef4_for_each_channel(channel, efx) {
313 ef4_fill_test(n++, strings, data,
314 &tests->eventq_dma[channel->channel],
315 EF4_CHANNEL_NAME(channel),
316 "eventq.dma", NULL);
317 ef4_fill_test(n++, strings, data,
318 &tests->eventq_int[channel->channel],
319 EF4_CHANNEL_NAME(channel),
320 "eventq.int", NULL);
321 }
322
323 ef4_fill_test(n++, strings, data, &tests->memory,
324 "core", 0, "memory", NULL);
325 ef4_fill_test(n++, strings, data, &tests->registers,
326 "core", 0, "registers", NULL);
327
328 if (efx->phy_op->run_tests != NULL) {
329 EF4_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
330
331 for (i = 0; true; ++i) {
332 const char *name;
333
334 EF4_BUG_ON_PARANOID(i >= EF4_MAX_PHY_TESTS);
335 name = efx->phy_op->test_name(efx, i);
336 if (name == NULL)
337 break;
338
339 ef4_fill_test(n++, strings, data, &tests->phy_ext[i],
340 "phy", 0, name, NULL);
341 }
342 }
343
344
345 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
346 if (!(efx->loopback_modes & (1 << mode)))
347 continue;
348 n = ef4_fill_loopback_test(efx,
349 &tests->loopback[mode], mode, n,
350 strings, data);
351 }
352
353 return n;
354}
355
356static size_t ef4_describe_per_queue_stats(struct ef4_nic *efx, u8 *strings)
357{
358 size_t n_stats = 0;
359 struct ef4_channel *channel;
360
361 ef4_for_each_channel(channel, efx) {
362 if (ef4_channel_has_tx_queues(channel)) {
363 n_stats++;
364 if (strings != NULL) {
365 snprintf(strings, ETH_GSTRING_LEN,
366 "tx-%u.tx_packets",
367 channel->tx_queue[0].queue /
368 EF4_TXQ_TYPES);
369
370 strings += ETH_GSTRING_LEN;
371 }
372 }
373 }
374 ef4_for_each_channel(channel, efx) {
375 if (ef4_channel_has_rx_queue(channel)) {
376 n_stats++;
377 if (strings != NULL) {
378 snprintf(strings, ETH_GSTRING_LEN,
379 "rx-%d.rx_packets", channel->channel);
380 strings += ETH_GSTRING_LEN;
381 }
382 }
383 }
384 return n_stats;
385}
386
387static int ef4_ethtool_get_sset_count(struct net_device *net_dev,
388 int string_set)
389{
390 struct ef4_nic *efx = netdev_priv(net_dev);
391
392 switch (string_set) {
393 case ETH_SS_STATS:
394 return efx->type->describe_stats(efx, NULL) +
395 EF4_ETHTOOL_SW_STAT_COUNT +
396 ef4_describe_per_queue_stats(efx, NULL);
397 case ETH_SS_TEST:
398 return ef4_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
399 default:
400 return -EINVAL;
401 }
402}
403
404static void ef4_ethtool_get_strings(struct net_device *net_dev,
405 u32 string_set, u8 *strings)
406{
407 struct ef4_nic *efx = netdev_priv(net_dev);
408 int i;
409
410 switch (string_set) {
411 case ETH_SS_STATS:
412 strings += (efx->type->describe_stats(efx, strings) *
413 ETH_GSTRING_LEN);
414 for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++)
415 strlcpy(strings + i * ETH_GSTRING_LEN,
416 ef4_sw_stat_desc[i].name, ETH_GSTRING_LEN);
417 strings += EF4_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
418 strings += (ef4_describe_per_queue_stats(efx, strings) *
419 ETH_GSTRING_LEN);
420 break;
421 case ETH_SS_TEST:
422 ef4_ethtool_fill_self_tests(efx, NULL, strings, NULL);
423 break;
424 default:
425
426 break;
427 }
428}
429
430static void ef4_ethtool_get_stats(struct net_device *net_dev,
431 struct ethtool_stats *stats,
432 u64 *data)
433{
434 struct ef4_nic *efx = netdev_priv(net_dev);
435 const struct ef4_sw_stat_desc *stat;
436 struct ef4_channel *channel;
437 struct ef4_tx_queue *tx_queue;
438 struct ef4_rx_queue *rx_queue;
439 int i;
440
441 spin_lock_bh(&efx->stats_lock);
442
443
444 data += efx->type->update_stats(efx, data, NULL);
445
446
447 for (i = 0; i < EF4_ETHTOOL_SW_STAT_COUNT; i++) {
448 stat = &ef4_sw_stat_desc[i];
449 switch (stat->source) {
450 case EF4_ETHTOOL_STAT_SOURCE_nic:
451 data[i] = stat->get_stat((void *)efx + stat->offset);
452 break;
453 case EF4_ETHTOOL_STAT_SOURCE_channel:
454 data[i] = 0;
455 ef4_for_each_channel(channel, efx)
456 data[i] += stat->get_stat((void *)channel +
457 stat->offset);
458 break;
459 case EF4_ETHTOOL_STAT_SOURCE_tx_queue:
460 data[i] = 0;
461 ef4_for_each_channel(channel, efx) {
462 ef4_for_each_channel_tx_queue(tx_queue, channel)
463 data[i] +=
464 stat->get_stat((void *)tx_queue
465 + stat->offset);
466 }
467 break;
468 }
469 }
470 data += EF4_ETHTOOL_SW_STAT_COUNT;
471
472 spin_unlock_bh(&efx->stats_lock);
473
474 ef4_for_each_channel(channel, efx) {
475 if (ef4_channel_has_tx_queues(channel)) {
476 *data = 0;
477 ef4_for_each_channel_tx_queue(tx_queue, channel) {
478 *data += tx_queue->tx_packets;
479 }
480 data++;
481 }
482 }
483 ef4_for_each_channel(channel, efx) {
484 if (ef4_channel_has_rx_queue(channel)) {
485 *data = 0;
486 ef4_for_each_channel_rx_queue(rx_queue, channel) {
487 *data += rx_queue->rx_packets;
488 }
489 data++;
490 }
491 }
492}
493
494static void ef4_ethtool_self_test(struct net_device *net_dev,
495 struct ethtool_test *test, u64 *data)
496{
497 struct ef4_nic *efx = netdev_priv(net_dev);
498 struct ef4_self_tests *ef4_tests;
499 bool already_up;
500 int rc = -ENOMEM;
501
502 ef4_tests = kzalloc(sizeof(*ef4_tests), GFP_KERNEL);
503 if (!ef4_tests)
504 goto fail;
505
506 if (efx->state != STATE_READY) {
507 rc = -EBUSY;
508 goto out;
509 }
510
511 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
512 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
513
514
515 already_up = (efx->net_dev->flags & IFF_UP);
516 if (!already_up) {
517 rc = dev_open(efx->net_dev, NULL);
518 if (rc) {
519 netif_err(efx, drv, efx->net_dev,
520 "failed opening device.\n");
521 goto out;
522 }
523 }
524
525 rc = ef4_selftest(efx, ef4_tests, test->flags);
526
527 if (!already_up)
528 dev_close(efx->net_dev);
529
530 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
531 rc == 0 ? "passed" : "failed",
532 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
533
534out:
535 ef4_ethtool_fill_self_tests(efx, ef4_tests, NULL, data);
536 kfree(ef4_tests);
537fail:
538 if (rc)
539 test->flags |= ETH_TEST_FL_FAILED;
540}
541
542
543static int ef4_ethtool_nway_reset(struct net_device *net_dev)
544{
545 struct ef4_nic *efx = netdev_priv(net_dev);
546
547 return mdio45_nway_restart(&efx->mdio);
548}
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579static int ef4_ethtool_get_coalesce(struct net_device *net_dev,
580 struct ethtool_coalesce *coalesce)
581{
582 struct ef4_nic *efx = netdev_priv(net_dev);
583 unsigned int tx_usecs, rx_usecs;
584 bool rx_adaptive;
585
586 ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
587
588 coalesce->tx_coalesce_usecs = tx_usecs;
589 coalesce->tx_coalesce_usecs_irq = tx_usecs;
590 coalesce->rx_coalesce_usecs = rx_usecs;
591 coalesce->rx_coalesce_usecs_irq = rx_usecs;
592 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
593
594 return 0;
595}
596
597static int ef4_ethtool_set_coalesce(struct net_device *net_dev,
598 struct ethtool_coalesce *coalesce)
599{
600 struct ef4_nic *efx = netdev_priv(net_dev);
601 struct ef4_channel *channel;
602 unsigned int tx_usecs, rx_usecs;
603 bool adaptive, rx_may_override_tx;
604 int rc;
605
606 ef4_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
607
608 if (coalesce->rx_coalesce_usecs != rx_usecs)
609 rx_usecs = coalesce->rx_coalesce_usecs;
610 else
611 rx_usecs = coalesce->rx_coalesce_usecs_irq;
612
613 adaptive = coalesce->use_adaptive_rx_coalesce;
614
615
616
617
618 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
619 coalesce->tx_coalesce_usecs_irq == tx_usecs);
620 if (coalesce->tx_coalesce_usecs != tx_usecs)
621 tx_usecs = coalesce->tx_coalesce_usecs;
622 else
623 tx_usecs = coalesce->tx_coalesce_usecs_irq;
624
625 rc = ef4_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
626 rx_may_override_tx);
627 if (rc != 0)
628 return rc;
629
630 ef4_for_each_channel(channel, efx)
631 efx->type->push_irq_moderation(channel);
632
633 return 0;
634}
635
636static void ef4_ethtool_get_ringparam(struct net_device *net_dev,
637 struct ethtool_ringparam *ring)
638{
639 struct ef4_nic *efx = netdev_priv(net_dev);
640
641 ring->rx_max_pending = EF4_MAX_DMAQ_SIZE;
642 ring->tx_max_pending = EF4_MAX_DMAQ_SIZE;
643 ring->rx_pending = efx->rxq_entries;
644 ring->tx_pending = efx->txq_entries;
645}
646
647static int ef4_ethtool_set_ringparam(struct net_device *net_dev,
648 struct ethtool_ringparam *ring)
649{
650 struct ef4_nic *efx = netdev_priv(net_dev);
651 u32 txq_entries;
652
653 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
654 ring->rx_pending > EF4_MAX_DMAQ_SIZE ||
655 ring->tx_pending > EF4_MAX_DMAQ_SIZE)
656 return -EINVAL;
657
658 if (ring->rx_pending < EF4_RXQ_MIN_ENT) {
659 netif_err(efx, drv, efx->net_dev,
660 "RX queues cannot be smaller than %u\n",
661 EF4_RXQ_MIN_ENT);
662 return -EINVAL;
663 }
664
665 txq_entries = max(ring->tx_pending, EF4_TXQ_MIN_ENT(efx));
666 if (txq_entries != ring->tx_pending)
667 netif_warn(efx, drv, efx->net_dev,
668 "increasing TX queue size to minimum of %u\n",
669 txq_entries);
670
671 return ef4_realloc_channels(efx, ring->rx_pending, txq_entries);
672}
673
674static int ef4_ethtool_set_pauseparam(struct net_device *net_dev,
675 struct ethtool_pauseparam *pause)
676{
677 struct ef4_nic *efx = netdev_priv(net_dev);
678 u8 wanted_fc, old_fc;
679 u32 old_adv;
680 int rc = 0;
681
682 mutex_lock(&efx->mac_lock);
683
684 wanted_fc = ((pause->rx_pause ? EF4_FC_RX : 0) |
685 (pause->tx_pause ? EF4_FC_TX : 0) |
686 (pause->autoneg ? EF4_FC_AUTO : 0));
687
688 if ((wanted_fc & EF4_FC_TX) && !(wanted_fc & EF4_FC_RX)) {
689 netif_dbg(efx, drv, efx->net_dev,
690 "Flow control unsupported: tx ON rx OFF\n");
691 rc = -EINVAL;
692 goto out;
693 }
694
695 if ((wanted_fc & EF4_FC_AUTO) && !efx->link_advertising) {
696 netif_dbg(efx, drv, efx->net_dev,
697 "Autonegotiation is disabled\n");
698 rc = -EINVAL;
699 goto out;
700 }
701
702
703 if (efx->type->prepare_enable_fc_tx &&
704 (wanted_fc & EF4_FC_TX) && !(efx->wanted_fc & EF4_FC_TX))
705 efx->type->prepare_enable_fc_tx(efx);
706
707 old_adv = efx->link_advertising;
708 old_fc = efx->wanted_fc;
709 ef4_link_set_wanted_fc(efx, wanted_fc);
710 if (efx->link_advertising != old_adv ||
711 (efx->wanted_fc ^ old_fc) & EF4_FC_AUTO) {
712 rc = efx->phy_op->reconfigure(efx);
713 if (rc) {
714 netif_err(efx, drv, efx->net_dev,
715 "Unable to advertise requested flow "
716 "control setting\n");
717 goto out;
718 }
719 }
720
721
722
723
724 ef4_mac_reconfigure(efx);
725
726out:
727 mutex_unlock(&efx->mac_lock);
728
729 return rc;
730}
731
732static void ef4_ethtool_get_pauseparam(struct net_device *net_dev,
733 struct ethtool_pauseparam *pause)
734{
735 struct ef4_nic *efx = netdev_priv(net_dev);
736
737 pause->rx_pause = !!(efx->wanted_fc & EF4_FC_RX);
738 pause->tx_pause = !!(efx->wanted_fc & EF4_FC_TX);
739 pause->autoneg = !!(efx->wanted_fc & EF4_FC_AUTO);
740}
741
742static void ef4_ethtool_get_wol(struct net_device *net_dev,
743 struct ethtool_wolinfo *wol)
744{
745 struct ef4_nic *efx = netdev_priv(net_dev);
746 return efx->type->get_wol(efx, wol);
747}
748
749
750static int ef4_ethtool_set_wol(struct net_device *net_dev,
751 struct ethtool_wolinfo *wol)
752{
753 struct ef4_nic *efx = netdev_priv(net_dev);
754 return efx->type->set_wol(efx, wol->wolopts);
755}
756
757static int ef4_ethtool_reset(struct net_device *net_dev, u32 *flags)
758{
759 struct ef4_nic *efx = netdev_priv(net_dev);
760 int rc;
761
762 rc = efx->type->map_reset_flags(flags);
763 if (rc < 0)
764 return rc;
765
766 return ef4_reset(efx, rc);
767}
768
769
770static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
771
772#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
773#define IP_PROTO_FULL_MASK 0xFF
774#define PORT_FULL_MASK ((__force __be16)~0)
775#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
776
777static inline void ip6_fill_mask(__be32 *mask)
778{
779 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
780}
781
782static int ef4_ethtool_get_class_rule(struct ef4_nic *efx,
783 struct ethtool_rx_flow_spec *rule)
784{
785 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
786 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
787 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
788 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
789 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
790 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
791 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
792 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
793 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
794 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
795 struct ef4_filter_spec spec;
796 int rc;
797
798 rc = ef4_filter_get_filter_safe(efx, EF4_FILTER_PRI_MANUAL,
799 rule->location, &spec);
800 if (rc)
801 return rc;
802
803 if (spec.dmaq_id == EF4_FILTER_RX_DMAQ_ID_DROP)
804 rule->ring_cookie = RX_CLS_FLOW_DISC;
805 else
806 rule->ring_cookie = spec.dmaq_id;
807
808 if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
809 spec.ether_type == htons(ETH_P_IP) &&
810 (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
811 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
812 !(spec.match_flags &
813 ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
814 EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
815 EF4_FILTER_MATCH_IP_PROTO |
816 EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
817 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
818 TCP_V4_FLOW : UDP_V4_FLOW);
819 if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
820 ip_entry->ip4dst = spec.loc_host[0];
821 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
822 }
823 if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
824 ip_entry->ip4src = spec.rem_host[0];
825 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
826 }
827 if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
828 ip_entry->pdst = spec.loc_port;
829 ip_mask->pdst = PORT_FULL_MASK;
830 }
831 if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
832 ip_entry->psrc = spec.rem_port;
833 ip_mask->psrc = PORT_FULL_MASK;
834 }
835 } else if ((spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) &&
836 spec.ether_type == htons(ETH_P_IPV6) &&
837 (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) &&
838 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
839 !(spec.match_flags &
840 ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
841 EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
842 EF4_FILTER_MATCH_IP_PROTO |
843 EF4_FILTER_MATCH_LOC_PORT | EF4_FILTER_MATCH_REM_PORT))) {
844 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
845 TCP_V6_FLOW : UDP_V6_FLOW);
846 if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
847 memcpy(ip6_entry->ip6dst, spec.loc_host,
848 sizeof(ip6_entry->ip6dst));
849 ip6_fill_mask(ip6_mask->ip6dst);
850 }
851 if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
852 memcpy(ip6_entry->ip6src, spec.rem_host,
853 sizeof(ip6_entry->ip6src));
854 ip6_fill_mask(ip6_mask->ip6src);
855 }
856 if (spec.match_flags & EF4_FILTER_MATCH_LOC_PORT) {
857 ip6_entry->pdst = spec.loc_port;
858 ip6_mask->pdst = PORT_FULL_MASK;
859 }
860 if (spec.match_flags & EF4_FILTER_MATCH_REM_PORT) {
861 ip6_entry->psrc = spec.rem_port;
862 ip6_mask->psrc = PORT_FULL_MASK;
863 }
864 } else if (!(spec.match_flags &
865 ~(EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG |
866 EF4_FILTER_MATCH_REM_MAC | EF4_FILTER_MATCH_ETHER_TYPE |
867 EF4_FILTER_MATCH_OUTER_VID))) {
868 rule->flow_type = ETHER_FLOW;
869 if (spec.match_flags &
870 (EF4_FILTER_MATCH_LOC_MAC | EF4_FILTER_MATCH_LOC_MAC_IG)) {
871 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
872 if (spec.match_flags & EF4_FILTER_MATCH_LOC_MAC)
873 eth_broadcast_addr(mac_mask->h_dest);
874 else
875 ether_addr_copy(mac_mask->h_dest,
876 mac_addr_ig_mask);
877 }
878 if (spec.match_flags & EF4_FILTER_MATCH_REM_MAC) {
879 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
880 eth_broadcast_addr(mac_mask->h_source);
881 }
882 if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE) {
883 mac_entry->h_proto = spec.ether_type;
884 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
885 }
886 } else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
887 spec.ether_type == htons(ETH_P_IP) &&
888 !(spec.match_flags &
889 ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
890 EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
891 EF4_FILTER_MATCH_IP_PROTO))) {
892 rule->flow_type = IPV4_USER_FLOW;
893 uip_entry->ip_ver = ETH_RX_NFC_IP4;
894 if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
895 uip_mask->proto = IP_PROTO_FULL_MASK;
896 uip_entry->proto = spec.ip_proto;
897 }
898 if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
899 uip_entry->ip4dst = spec.loc_host[0];
900 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
901 }
902 if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
903 uip_entry->ip4src = spec.rem_host[0];
904 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
905 }
906 } else if (spec.match_flags & EF4_FILTER_MATCH_ETHER_TYPE &&
907 spec.ether_type == htons(ETH_P_IPV6) &&
908 !(spec.match_flags &
909 ~(EF4_FILTER_MATCH_ETHER_TYPE | EF4_FILTER_MATCH_OUTER_VID |
910 EF4_FILTER_MATCH_LOC_HOST | EF4_FILTER_MATCH_REM_HOST |
911 EF4_FILTER_MATCH_IP_PROTO))) {
912 rule->flow_type = IPV6_USER_FLOW;
913 if (spec.match_flags & EF4_FILTER_MATCH_IP_PROTO) {
914 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
915 uip6_entry->l4_proto = spec.ip_proto;
916 }
917 if (spec.match_flags & EF4_FILTER_MATCH_LOC_HOST) {
918 memcpy(uip6_entry->ip6dst, spec.loc_host,
919 sizeof(uip6_entry->ip6dst));
920 ip6_fill_mask(uip6_mask->ip6dst);
921 }
922 if (spec.match_flags & EF4_FILTER_MATCH_REM_HOST) {
923 memcpy(uip6_entry->ip6src, spec.rem_host,
924 sizeof(uip6_entry->ip6src));
925 ip6_fill_mask(uip6_mask->ip6src);
926 }
927 } else {
928
929 WARN_ON(1);
930 return -EINVAL;
931 }
932
933 if (spec.match_flags & EF4_FILTER_MATCH_OUTER_VID) {
934 rule->flow_type |= FLOW_EXT;
935 rule->h_ext.vlan_tci = spec.outer_vid;
936 rule->m_ext.vlan_tci = htons(0xfff);
937 }
938
939 return rc;
940}
941
942static int
943ef4_ethtool_get_rxnfc(struct net_device *net_dev,
944 struct ethtool_rxnfc *info, u32 *rule_locs)
945{
946 struct ef4_nic *efx = netdev_priv(net_dev);
947
948 switch (info->cmd) {
949 case ETHTOOL_GRXRINGS:
950 info->data = efx->n_rx_channels;
951 return 0;
952
953 case ETHTOOL_GRXFH: {
954 unsigned min_revision = 0;
955
956 info->data = 0;
957 switch (info->flow_type) {
958 case TCP_V4_FLOW:
959 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
960 case UDP_V4_FLOW:
961 case SCTP_V4_FLOW:
962 case AH_ESP_V4_FLOW:
963 case IPV4_FLOW:
964 info->data |= RXH_IP_SRC | RXH_IP_DST;
965 min_revision = EF4_REV_FALCON_B0;
966 break;
967 default:
968 break;
969 }
970 if (ef4_nic_rev(efx) < min_revision)
971 info->data = 0;
972 return 0;
973 }
974
975 case ETHTOOL_GRXCLSRLCNT:
976 info->data = ef4_filter_get_rx_id_limit(efx);
977 if (info->data == 0)
978 return -EOPNOTSUPP;
979 info->data |= RX_CLS_LOC_SPECIAL;
980 info->rule_cnt =
981 ef4_filter_count_rx_used(efx, EF4_FILTER_PRI_MANUAL);
982 return 0;
983
984 case ETHTOOL_GRXCLSRULE:
985 if (ef4_filter_get_rx_id_limit(efx) == 0)
986 return -EOPNOTSUPP;
987 return ef4_ethtool_get_class_rule(efx, &info->fs);
988
989 case ETHTOOL_GRXCLSRLALL: {
990 s32 rc;
991 info->data = ef4_filter_get_rx_id_limit(efx);
992 if (info->data == 0)
993 return -EOPNOTSUPP;
994 rc = ef4_filter_get_rx_ids(efx, EF4_FILTER_PRI_MANUAL,
995 rule_locs, info->rule_cnt);
996 if (rc < 0)
997 return rc;
998 info->rule_cnt = rc;
999 return 0;
1000 }
1001
1002 default:
1003 return -EOPNOTSUPP;
1004 }
1005}
1006
1007static inline bool ip6_mask_is_full(__be32 mask[4])
1008{
1009 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1010}
1011
1012static inline bool ip6_mask_is_empty(__be32 mask[4])
1013{
1014 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1015}
1016
1017static int ef4_ethtool_set_class_rule(struct ef4_nic *efx,
1018 struct ethtool_rx_flow_spec *rule)
1019{
1020 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1021 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
1022 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1023 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1024 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1025 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1026 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1027 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
1028 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1029 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1030 struct ef4_filter_spec spec;
1031 int rc;
1032
1033
1034 if (rule->location != RX_CLS_LOC_ANY)
1035 return -EINVAL;
1036
1037
1038 if (rule->ring_cookie >= efx->n_rx_channels &&
1039 rule->ring_cookie != RX_CLS_FLOW_DISC)
1040 return -EINVAL;
1041
1042
1043 if ((rule->flow_type & FLOW_EXT) &&
1044 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
1045 rule->m_ext.data[1]))
1046 return -EINVAL;
1047
1048 ef4_filter_init_rx(&spec, EF4_FILTER_PRI_MANUAL,
1049 efx->rx_scatter ? EF4_FILTER_FLAG_RX_SCATTER : 0,
1050 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
1051 EF4_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
1052
1053 switch (rule->flow_type & ~FLOW_EXT) {
1054 case TCP_V4_FLOW:
1055 case UDP_V4_FLOW:
1056 spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1057 EF4_FILTER_MATCH_IP_PROTO);
1058 spec.ether_type = htons(ETH_P_IP);
1059 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1060 IPPROTO_TCP : IPPROTO_UDP);
1061 if (ip_mask->ip4dst) {
1062 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1063 return -EINVAL;
1064 spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1065 spec.loc_host[0] = ip_entry->ip4dst;
1066 }
1067 if (ip_mask->ip4src) {
1068 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1069 return -EINVAL;
1070 spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1071 spec.rem_host[0] = ip_entry->ip4src;
1072 }
1073 if (ip_mask->pdst) {
1074 if (ip_mask->pdst != PORT_FULL_MASK)
1075 return -EINVAL;
1076 spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1077 spec.loc_port = ip_entry->pdst;
1078 }
1079 if (ip_mask->psrc) {
1080 if (ip_mask->psrc != PORT_FULL_MASK)
1081 return -EINVAL;
1082 spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1083 spec.rem_port = ip_entry->psrc;
1084 }
1085 if (ip_mask->tos)
1086 return -EINVAL;
1087 break;
1088
1089 case TCP_V6_FLOW:
1090 case UDP_V6_FLOW:
1091 spec.match_flags = (EF4_FILTER_MATCH_ETHER_TYPE |
1092 EF4_FILTER_MATCH_IP_PROTO);
1093 spec.ether_type = htons(ETH_P_IPV6);
1094 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1095 IPPROTO_TCP : IPPROTO_UDP);
1096 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1097 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1098 return -EINVAL;
1099 spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1100 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1101 }
1102 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1103 if (!ip6_mask_is_full(ip6_mask->ip6src))
1104 return -EINVAL;
1105 spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1106 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1107 }
1108 if (ip6_mask->pdst) {
1109 if (ip6_mask->pdst != PORT_FULL_MASK)
1110 return -EINVAL;
1111 spec.match_flags |= EF4_FILTER_MATCH_LOC_PORT;
1112 spec.loc_port = ip6_entry->pdst;
1113 }
1114 if (ip6_mask->psrc) {
1115 if (ip6_mask->psrc != PORT_FULL_MASK)
1116 return -EINVAL;
1117 spec.match_flags |= EF4_FILTER_MATCH_REM_PORT;
1118 spec.rem_port = ip6_entry->psrc;
1119 }
1120 if (ip6_mask->tclass)
1121 return -EINVAL;
1122 break;
1123
1124 case IPV4_USER_FLOW:
1125 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1126 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1127 return -EINVAL;
1128 spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1129 spec.ether_type = htons(ETH_P_IP);
1130 if (uip_mask->ip4dst) {
1131 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1132 return -EINVAL;
1133 spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1134 spec.loc_host[0] = uip_entry->ip4dst;
1135 }
1136 if (uip_mask->ip4src) {
1137 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1138 return -EINVAL;
1139 spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1140 spec.rem_host[0] = uip_entry->ip4src;
1141 }
1142 if (uip_mask->proto) {
1143 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1144 return -EINVAL;
1145 spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1146 spec.ip_proto = uip_entry->proto;
1147 }
1148 break;
1149
1150 case IPV6_USER_FLOW:
1151 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1152 return -EINVAL;
1153 spec.match_flags = EF4_FILTER_MATCH_ETHER_TYPE;
1154 spec.ether_type = htons(ETH_P_IPV6);
1155 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1156 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1157 return -EINVAL;
1158 spec.match_flags |= EF4_FILTER_MATCH_LOC_HOST;
1159 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1160 }
1161 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1162 if (!ip6_mask_is_full(uip6_mask->ip6src))
1163 return -EINVAL;
1164 spec.match_flags |= EF4_FILTER_MATCH_REM_HOST;
1165 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1166 }
1167 if (uip6_mask->l4_proto) {
1168 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1169 return -EINVAL;
1170 spec.match_flags |= EF4_FILTER_MATCH_IP_PROTO;
1171 spec.ip_proto = uip6_entry->l4_proto;
1172 }
1173 break;
1174
1175 case ETHER_FLOW:
1176 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1177 if (ether_addr_equal(mac_mask->h_dest,
1178 mac_addr_ig_mask))
1179 spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC_IG;
1180 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1181 spec.match_flags |= EF4_FILTER_MATCH_LOC_MAC;
1182 else
1183 return -EINVAL;
1184 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
1185 }
1186 if (!is_zero_ether_addr(mac_mask->h_source)) {
1187 if (!is_broadcast_ether_addr(mac_mask->h_source))
1188 return -EINVAL;
1189 spec.match_flags |= EF4_FILTER_MATCH_REM_MAC;
1190 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
1191 }
1192 if (mac_mask->h_proto) {
1193 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1194 return -EINVAL;
1195 spec.match_flags |= EF4_FILTER_MATCH_ETHER_TYPE;
1196 spec.ether_type = mac_entry->h_proto;
1197 }
1198 break;
1199
1200 default:
1201 return -EINVAL;
1202 }
1203
1204 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1205 if (rule->m_ext.vlan_tci != htons(0xfff))
1206 return -EINVAL;
1207 spec.match_flags |= EF4_FILTER_MATCH_OUTER_VID;
1208 spec.outer_vid = rule->h_ext.vlan_tci;
1209 }
1210
1211 rc = ef4_filter_insert_filter(efx, &spec, true);
1212 if (rc < 0)
1213 return rc;
1214
1215 rule->location = rc;
1216 return 0;
1217}
1218
1219static int ef4_ethtool_set_rxnfc(struct net_device *net_dev,
1220 struct ethtool_rxnfc *info)
1221{
1222 struct ef4_nic *efx = netdev_priv(net_dev);
1223
1224 if (ef4_filter_get_rx_id_limit(efx) == 0)
1225 return -EOPNOTSUPP;
1226
1227 switch (info->cmd) {
1228 case ETHTOOL_SRXCLSRLINS:
1229 return ef4_ethtool_set_class_rule(efx, &info->fs);
1230
1231 case ETHTOOL_SRXCLSRLDEL:
1232 return ef4_filter_remove_id_safe(efx, EF4_FILTER_PRI_MANUAL,
1233 info->fs.location);
1234
1235 default:
1236 return -EOPNOTSUPP;
1237 }
1238}
1239
1240static u32 ef4_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1241{
1242 struct ef4_nic *efx = netdev_priv(net_dev);
1243
1244 return ((ef4_nic_rev(efx) < EF4_REV_FALCON_B0 ||
1245 efx->n_rx_channels == 1) ?
1246 0 : ARRAY_SIZE(efx->rx_indir_table));
1247}
1248
1249static int ef4_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1250 u8 *hfunc)
1251{
1252 struct ef4_nic *efx = netdev_priv(net_dev);
1253
1254 if (hfunc)
1255 *hfunc = ETH_RSS_HASH_TOP;
1256 if (indir)
1257 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
1258 return 0;
1259}
1260
1261static int ef4_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1262 const u8 *key, const u8 hfunc)
1263{
1264 struct ef4_nic *efx = netdev_priv(net_dev);
1265
1266
1267 if (key ||
1268 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1269 return -EOPNOTSUPP;
1270 if (!indir)
1271 return 0;
1272
1273 return efx->type->rx_push_rss_config(efx, true, indir);
1274}
1275
1276static int ef4_ethtool_get_module_eeprom(struct net_device *net_dev,
1277 struct ethtool_eeprom *ee,
1278 u8 *data)
1279{
1280 struct ef4_nic *efx = netdev_priv(net_dev);
1281 int ret;
1282
1283 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1284 return -EOPNOTSUPP;
1285
1286 mutex_lock(&efx->mac_lock);
1287 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1288 mutex_unlock(&efx->mac_lock);
1289
1290 return ret;
1291}
1292
1293static int ef4_ethtool_get_module_info(struct net_device *net_dev,
1294 struct ethtool_modinfo *modinfo)
1295{
1296 struct ef4_nic *efx = netdev_priv(net_dev);
1297 int ret;
1298
1299 if (!efx->phy_op || !efx->phy_op->get_module_info)
1300 return -EOPNOTSUPP;
1301
1302 mutex_lock(&efx->mac_lock);
1303 ret = efx->phy_op->get_module_info(efx, modinfo);
1304 mutex_unlock(&efx->mac_lock);
1305
1306 return ret;
1307}
1308
1309const struct ethtool_ops ef4_ethtool_ops = {
1310 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1311 ETHTOOL_COALESCE_USECS_IRQ |
1312 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1313 .get_drvinfo = ef4_ethtool_get_drvinfo,
1314 .get_regs_len = ef4_ethtool_get_regs_len,
1315 .get_regs = ef4_ethtool_get_regs,
1316 .get_msglevel = ef4_ethtool_get_msglevel,
1317 .set_msglevel = ef4_ethtool_set_msglevel,
1318 .nway_reset = ef4_ethtool_nway_reset,
1319 .get_link = ethtool_op_get_link,
1320 .get_coalesce = ef4_ethtool_get_coalesce,
1321 .set_coalesce = ef4_ethtool_set_coalesce,
1322 .get_ringparam = ef4_ethtool_get_ringparam,
1323 .set_ringparam = ef4_ethtool_set_ringparam,
1324 .get_pauseparam = ef4_ethtool_get_pauseparam,
1325 .set_pauseparam = ef4_ethtool_set_pauseparam,
1326 .get_sset_count = ef4_ethtool_get_sset_count,
1327 .self_test = ef4_ethtool_self_test,
1328 .get_strings = ef4_ethtool_get_strings,
1329 .set_phys_id = ef4_ethtool_phys_id,
1330 .get_ethtool_stats = ef4_ethtool_get_stats,
1331 .get_wol = ef4_ethtool_get_wol,
1332 .set_wol = ef4_ethtool_set_wol,
1333 .reset = ef4_ethtool_reset,
1334 .get_rxnfc = ef4_ethtool_get_rxnfc,
1335 .set_rxnfc = ef4_ethtool_set_rxnfc,
1336 .get_rxfh_indir_size = ef4_ethtool_get_rxfh_indir_size,
1337 .get_rxfh = ef4_ethtool_get_rxfh,
1338 .set_rxfh = ef4_ethtool_set_rxfh,
1339 .get_module_info = ef4_ethtool_get_module_info,
1340 .get_module_eeprom = ef4_ethtool_get_module_eeprom,
1341 .get_link_ksettings = ef4_ethtool_get_link_ksettings,
1342 .set_link_ksettings = ef4_ethtool_set_link_ksettings,
1343};
1344