sfc: Add TX merged completion counter
[deliverable/linux.git] / drivers / net / ethernet / sfc / ethtool.c
1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2010 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(pushes),
73 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
74 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
75 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
76 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
79 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc),
80 };
81
82 #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
83
84 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
85
86 /**************************************************************************
87 *
88 * Ethtool operations
89 *
90 **************************************************************************
91 */
92
93 /* Identify device by flashing LEDs */
94 static int efx_ethtool_phys_id(struct net_device *net_dev,
95 enum ethtool_phys_id_state state)
96 {
97 struct efx_nic *efx = netdev_priv(net_dev);
98 enum efx_led_mode mode = EFX_LED_DEFAULT;
99
100 switch (state) {
101 case ETHTOOL_ID_ON:
102 mode = EFX_LED_ON;
103 break;
104 case ETHTOOL_ID_OFF:
105 mode = EFX_LED_OFF;
106 break;
107 case ETHTOOL_ID_INACTIVE:
108 mode = EFX_LED_DEFAULT;
109 break;
110 case ETHTOOL_ID_ACTIVE:
111 return 1; /* cycle on/off once per second */
112 }
113
114 efx->type->set_id_led(efx, mode);
115 return 0;
116 }
117
118 /* This must be called with rtnl_lock held. */
119 static int efx_ethtool_get_settings(struct net_device *net_dev,
120 struct ethtool_cmd *ecmd)
121 {
122 struct efx_nic *efx = netdev_priv(net_dev);
123 struct efx_link_state *link_state = &efx->link_state;
124
125 mutex_lock(&efx->mac_lock);
126 efx->phy_op->get_settings(efx, ecmd);
127 mutex_unlock(&efx->mac_lock);
128
129 /* Both MACs support pause frames (bidirectional and respond-only) */
130 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
131
132 if (LOOPBACK_INTERNAL(efx)) {
133 ethtool_cmd_speed_set(ecmd, link_state->speed);
134 ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
135 }
136
137 return 0;
138 }
139
140 /* This must be called with rtnl_lock held. */
141 static int efx_ethtool_set_settings(struct net_device *net_dev,
142 struct ethtool_cmd *ecmd)
143 {
144 struct efx_nic *efx = netdev_priv(net_dev);
145 int rc;
146
147 /* GMAC does not support 1000Mbps HD */
148 if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
149 (ecmd->duplex != DUPLEX_FULL)) {
150 netif_dbg(efx, drv, efx->net_dev,
151 "rejecting unsupported 1000Mbps HD setting\n");
152 return -EINVAL;
153 }
154
155 mutex_lock(&efx->mac_lock);
156 rc = efx->phy_op->set_settings(efx, ecmd);
157 mutex_unlock(&efx->mac_lock);
158 return rc;
159 }
160
161 static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
162 struct ethtool_drvinfo *info)
163 {
164 struct efx_nic *efx = netdev_priv(net_dev);
165
166 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
167 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
168 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
169 efx_mcdi_print_fwver(efx, info->fw_version,
170 sizeof(info->fw_version));
171 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
172 }
173
174 static int efx_ethtool_get_regs_len(struct net_device *net_dev)
175 {
176 return efx_nic_get_regs_len(netdev_priv(net_dev));
177 }
178
179 static void efx_ethtool_get_regs(struct net_device *net_dev,
180 struct ethtool_regs *regs, void *buf)
181 {
182 struct efx_nic *efx = netdev_priv(net_dev);
183
184 regs->version = efx->type->revision;
185 efx_nic_get_regs(efx, buf);
186 }
187
188 static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
189 {
190 struct efx_nic *efx = netdev_priv(net_dev);
191 return efx->msg_enable;
192 }
193
194 static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
195 {
196 struct efx_nic *efx = netdev_priv(net_dev);
197 efx->msg_enable = msg_enable;
198 }
199
200 /**
201 * efx_fill_test - fill in an individual self-test entry
202 * @test_index: Index of the test
203 * @strings: Ethtool strings, or %NULL
204 * @data: Ethtool test results, or %NULL
205 * @test: Pointer to test result (used only if data != %NULL)
206 * @unit_format: Unit name format (e.g. "chan\%d")
207 * @unit_id: Unit id (e.g. 0 for "chan0")
208 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
209 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
210 *
211 * Fill in an individual self-test entry.
212 */
213 static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
214 int *test, const char *unit_format, int unit_id,
215 const char *test_format, const char *test_id)
216 {
217 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
218
219 /* Fill data value, if applicable */
220 if (data)
221 data[test_index] = *test;
222
223 /* Fill string, if applicable */
224 if (strings) {
225 if (strchr(unit_format, '%'))
226 snprintf(unit_str, sizeof(unit_str),
227 unit_format, unit_id);
228 else
229 strcpy(unit_str, unit_format);
230 snprintf(test_str, sizeof(test_str), test_format, test_id);
231 snprintf(strings + test_index * ETH_GSTRING_LEN,
232 ETH_GSTRING_LEN,
233 "%-6s %-24s", unit_str, test_str);
234 }
235 }
236
237 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
238 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
239 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
240 #define EFX_LOOPBACK_NAME(_mode, _counter) \
241 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
242
243 /**
244 * efx_fill_loopback_test - fill in a block of loopback self-test entries
245 * @efx: Efx NIC
246 * @lb_tests: Efx loopback self-test results structure
247 * @mode: Loopback test mode
248 * @test_index: Starting index of the test
249 * @strings: Ethtool strings, or %NULL
250 * @data: Ethtool test results, or %NULL
251 */
252 static int efx_fill_loopback_test(struct efx_nic *efx,
253 struct efx_loopback_self_tests *lb_tests,
254 enum efx_loopback_mode mode,
255 unsigned int test_index,
256 u8 *strings, u64 *data)
257 {
258 struct efx_channel *channel =
259 efx_get_channel(efx, efx->tx_channel_offset);
260 struct efx_tx_queue *tx_queue;
261
262 efx_for_each_channel_tx_queue(tx_queue, channel) {
263 efx_fill_test(test_index++, strings, data,
264 &lb_tests->tx_sent[tx_queue->queue],
265 EFX_TX_QUEUE_NAME(tx_queue),
266 EFX_LOOPBACK_NAME(mode, "tx_sent"));
267 efx_fill_test(test_index++, strings, data,
268 &lb_tests->tx_done[tx_queue->queue],
269 EFX_TX_QUEUE_NAME(tx_queue),
270 EFX_LOOPBACK_NAME(mode, "tx_done"));
271 }
272 efx_fill_test(test_index++, strings, data,
273 &lb_tests->rx_good,
274 "rx", 0,
275 EFX_LOOPBACK_NAME(mode, "rx_good"));
276 efx_fill_test(test_index++, strings, data,
277 &lb_tests->rx_bad,
278 "rx", 0,
279 EFX_LOOPBACK_NAME(mode, "rx_bad"));
280
281 return test_index;
282 }
283
284 /**
285 * efx_ethtool_fill_self_tests - get self-test details
286 * @efx: Efx NIC
287 * @tests: Efx self-test results structure, or %NULL
288 * @strings: Ethtool strings, or %NULL
289 * @data: Ethtool test results, or %NULL
290 */
291 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
292 struct efx_self_tests *tests,
293 u8 *strings, u64 *data)
294 {
295 struct efx_channel *channel;
296 unsigned int n = 0, i;
297 enum efx_loopback_mode mode;
298
299 efx_fill_test(n++, strings, data, &tests->phy_alive,
300 "phy", 0, "alive", NULL);
301 efx_fill_test(n++, strings, data, &tests->nvram,
302 "core", 0, "nvram", NULL);
303 efx_fill_test(n++, strings, data, &tests->interrupt,
304 "core", 0, "interrupt", NULL);
305
306 /* Event queues */
307 efx_for_each_channel(channel, efx) {
308 efx_fill_test(n++, strings, data,
309 &tests->eventq_dma[channel->channel],
310 EFX_CHANNEL_NAME(channel),
311 "eventq.dma", NULL);
312 efx_fill_test(n++, strings, data,
313 &tests->eventq_int[channel->channel],
314 EFX_CHANNEL_NAME(channel),
315 "eventq.int", NULL);
316 }
317
318 efx_fill_test(n++, strings, data, &tests->registers,
319 "core", 0, "registers", NULL);
320
321 if (efx->phy_op->run_tests != NULL) {
322 EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
323
324 for (i = 0; true; ++i) {
325 const char *name;
326
327 EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
328 name = efx->phy_op->test_name(efx, i);
329 if (name == NULL)
330 break;
331
332 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
333 "phy", 0, name, NULL);
334 }
335 }
336
337 /* Loopback tests */
338 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
339 if (!(efx->loopback_modes & (1 << mode)))
340 continue;
341 n = efx_fill_loopback_test(efx,
342 &tests->loopback[mode], mode, n,
343 strings, data);
344 }
345
346 return n;
347 }
348
349 static int efx_ethtool_get_sset_count(struct net_device *net_dev,
350 int string_set)
351 {
352 struct efx_nic *efx = netdev_priv(net_dev);
353
354 switch (string_set) {
355 case ETH_SS_STATS:
356 return efx->type->describe_stats(efx, NULL) +
357 EFX_ETHTOOL_SW_STAT_COUNT;
358 case ETH_SS_TEST:
359 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
360 default:
361 return -EINVAL;
362 }
363 }
364
365 static void efx_ethtool_get_strings(struct net_device *net_dev,
366 u32 string_set, u8 *strings)
367 {
368 struct efx_nic *efx = netdev_priv(net_dev);
369 int i;
370
371 switch (string_set) {
372 case ETH_SS_STATS:
373 strings += (efx->type->describe_stats(efx, strings) *
374 ETH_GSTRING_LEN);
375 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
376 strlcpy(strings + i * ETH_GSTRING_LEN,
377 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
378 break;
379 case ETH_SS_TEST:
380 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
381 break;
382 default:
383 /* No other string sets */
384 break;
385 }
386 }
387
388 static void efx_ethtool_get_stats(struct net_device *net_dev,
389 struct ethtool_stats *stats,
390 u64 *data)
391 {
392 struct efx_nic *efx = netdev_priv(net_dev);
393 const struct efx_sw_stat_desc *stat;
394 struct efx_channel *channel;
395 struct efx_tx_queue *tx_queue;
396 int i;
397
398 spin_lock_bh(&efx->stats_lock);
399
400 /* Get NIC statistics */
401 data += efx->type->update_stats(efx, data, NULL);
402
403 /* Get software statistics */
404 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
405 stat = &efx_sw_stat_desc[i];
406 switch (stat->source) {
407 case EFX_ETHTOOL_STAT_SOURCE_nic:
408 data[i] = stat->get_stat((void *)efx + stat->offset);
409 break;
410 case EFX_ETHTOOL_STAT_SOURCE_channel:
411 data[i] = 0;
412 efx_for_each_channel(channel, efx)
413 data[i] += stat->get_stat((void *)channel +
414 stat->offset);
415 break;
416 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
417 data[i] = 0;
418 efx_for_each_channel(channel, efx) {
419 efx_for_each_channel_tx_queue(tx_queue, channel)
420 data[i] +=
421 stat->get_stat((void *)tx_queue
422 + stat->offset);
423 }
424 break;
425 }
426 }
427
428 spin_unlock_bh(&efx->stats_lock);
429 }
430
431 static void efx_ethtool_self_test(struct net_device *net_dev,
432 struct ethtool_test *test, u64 *data)
433 {
434 struct efx_nic *efx = netdev_priv(net_dev);
435 struct efx_self_tests *efx_tests;
436 int already_up;
437 int rc = -ENOMEM;
438
439 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
440 if (!efx_tests)
441 goto fail;
442
443 if (efx->state != STATE_READY) {
444 rc = -EIO;
445 goto fail1;
446 }
447
448 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
449 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
450
451 /* We need rx buffers and interrupts. */
452 already_up = (efx->net_dev->flags & IFF_UP);
453 if (!already_up) {
454 rc = dev_open(efx->net_dev);
455 if (rc) {
456 netif_err(efx, drv, efx->net_dev,
457 "failed opening device.\n");
458 goto fail1;
459 }
460 }
461
462 rc = efx_selftest(efx, efx_tests, test->flags);
463
464 if (!already_up)
465 dev_close(efx->net_dev);
466
467 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
468 rc == 0 ? "passed" : "failed",
469 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
470
471 fail1:
472 /* Fill ethtool results structures */
473 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
474 kfree(efx_tests);
475 fail:
476 if (rc)
477 test->flags |= ETH_TEST_FL_FAILED;
478 }
479
480 /* Restart autonegotiation */
481 static int efx_ethtool_nway_reset(struct net_device *net_dev)
482 {
483 struct efx_nic *efx = netdev_priv(net_dev);
484
485 return mdio45_nway_restart(&efx->mdio);
486 }
487
488 /*
489 * Each channel has a single IRQ and moderation timer, started by any
490 * completion (or other event). Unless the module parameter
491 * separate_tx_channels is set, IRQs and moderation are therefore
492 * shared between RX and TX completions. In this case, when RX IRQ
493 * moderation is explicitly changed then TX IRQ moderation is
494 * automatically changed too, but otherwise we fail if the two values
495 * are requested to be different.
496 *
497 * The hardware does not support a limit on the number of completions
498 * before an IRQ, so we do not use the max_frames fields. We should
499 * report and require that max_frames == (usecs != 0), but this would
500 * invalidate existing user documentation.
501 *
502 * The hardware does not have distinct settings for interrupt
503 * moderation while the previous IRQ is being handled, so we should
504 * not use the 'irq' fields. However, an earlier developer
505 * misunderstood the meaning of the 'irq' fields and the driver did
506 * not support the standard fields. To avoid invalidating existing
507 * user documentation, we report and accept changes through either the
508 * standard or 'irq' fields. If both are changed at the same time, we
509 * prefer the standard field.
510 *
511 * We implement adaptive IRQ moderation, but use a different algorithm
512 * from that assumed in the definition of struct ethtool_coalesce.
513 * Therefore we do not use any of the adaptive moderation parameters
514 * in it.
515 */
516
517 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
518 struct ethtool_coalesce *coalesce)
519 {
520 struct efx_nic *efx = netdev_priv(net_dev);
521 unsigned int tx_usecs, rx_usecs;
522 bool rx_adaptive;
523
524 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
525
526 coalesce->tx_coalesce_usecs = tx_usecs;
527 coalesce->tx_coalesce_usecs_irq = tx_usecs;
528 coalesce->rx_coalesce_usecs = rx_usecs;
529 coalesce->rx_coalesce_usecs_irq = rx_usecs;
530 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
531
532 return 0;
533 }
534
535 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
536 struct ethtool_coalesce *coalesce)
537 {
538 struct efx_nic *efx = netdev_priv(net_dev);
539 struct efx_channel *channel;
540 unsigned int tx_usecs, rx_usecs;
541 bool adaptive, rx_may_override_tx;
542 int rc;
543
544 if (coalesce->use_adaptive_tx_coalesce)
545 return -EINVAL;
546
547 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
548
549 if (coalesce->rx_coalesce_usecs != rx_usecs)
550 rx_usecs = coalesce->rx_coalesce_usecs;
551 else
552 rx_usecs = coalesce->rx_coalesce_usecs_irq;
553
554 adaptive = coalesce->use_adaptive_rx_coalesce;
555
556 /* If channels are shared, TX IRQ moderation can be quietly
557 * overridden unless it is changed from its old value.
558 */
559 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
560 coalesce->tx_coalesce_usecs_irq == tx_usecs);
561 if (coalesce->tx_coalesce_usecs != tx_usecs)
562 tx_usecs = coalesce->tx_coalesce_usecs;
563 else
564 tx_usecs = coalesce->tx_coalesce_usecs_irq;
565
566 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
567 rx_may_override_tx);
568 if (rc != 0)
569 return rc;
570
571 efx_for_each_channel(channel, efx)
572 efx->type->push_irq_moderation(channel);
573
574 return 0;
575 }
576
577 static void efx_ethtool_get_ringparam(struct net_device *net_dev,
578 struct ethtool_ringparam *ring)
579 {
580 struct efx_nic *efx = netdev_priv(net_dev);
581
582 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
583 ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
584 ring->rx_pending = efx->rxq_entries;
585 ring->tx_pending = efx->txq_entries;
586 }
587
588 static int efx_ethtool_set_ringparam(struct net_device *net_dev,
589 struct ethtool_ringparam *ring)
590 {
591 struct efx_nic *efx = netdev_priv(net_dev);
592 u32 txq_entries;
593
594 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
595 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
596 ring->tx_pending > EFX_MAX_DMAQ_SIZE)
597 return -EINVAL;
598
599 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
600 netif_err(efx, drv, efx->net_dev,
601 "RX queues cannot be smaller than %u\n",
602 EFX_RXQ_MIN_ENT);
603 return -EINVAL;
604 }
605
606 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
607 if (txq_entries != ring->tx_pending)
608 netif_warn(efx, drv, efx->net_dev,
609 "increasing TX queue size to minimum of %u\n",
610 txq_entries);
611
612 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
613 }
614
615 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
616 struct ethtool_pauseparam *pause)
617 {
618 struct efx_nic *efx = netdev_priv(net_dev);
619 u8 wanted_fc, old_fc;
620 u32 old_adv;
621 int rc = 0;
622
623 mutex_lock(&efx->mac_lock);
624
625 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
626 (pause->tx_pause ? EFX_FC_TX : 0) |
627 (pause->autoneg ? EFX_FC_AUTO : 0));
628
629 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
630 netif_dbg(efx, drv, efx->net_dev,
631 "Flow control unsupported: tx ON rx OFF\n");
632 rc = -EINVAL;
633 goto out;
634 }
635
636 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
637 netif_dbg(efx, drv, efx->net_dev,
638 "Autonegotiation is disabled\n");
639 rc = -EINVAL;
640 goto out;
641 }
642
643 /* Hook for Falcon bug 11482 workaround */
644 if (efx->type->prepare_enable_fc_tx &&
645 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
646 efx->type->prepare_enable_fc_tx(efx);
647
648 old_adv = efx->link_advertising;
649 old_fc = efx->wanted_fc;
650 efx_link_set_wanted_fc(efx, wanted_fc);
651 if (efx->link_advertising != old_adv ||
652 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
653 rc = efx->phy_op->reconfigure(efx);
654 if (rc) {
655 netif_err(efx, drv, efx->net_dev,
656 "Unable to advertise requested flow "
657 "control setting\n");
658 goto out;
659 }
660 }
661
662 /* Reconfigure the MAC. The PHY *may* generate a link state change event
663 * if the user just changed the advertised capabilities, but there's no
664 * harm doing this twice */
665 efx->type->reconfigure_mac(efx);
666
667 out:
668 mutex_unlock(&efx->mac_lock);
669
670 return rc;
671 }
672
673 static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
674 struct ethtool_pauseparam *pause)
675 {
676 struct efx_nic *efx = netdev_priv(net_dev);
677
678 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
679 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
680 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
681 }
682
683
684 static void efx_ethtool_get_wol(struct net_device *net_dev,
685 struct ethtool_wolinfo *wol)
686 {
687 struct efx_nic *efx = netdev_priv(net_dev);
688 return efx->type->get_wol(efx, wol);
689 }
690
691
692 static int efx_ethtool_set_wol(struct net_device *net_dev,
693 struct ethtool_wolinfo *wol)
694 {
695 struct efx_nic *efx = netdev_priv(net_dev);
696 return efx->type->set_wol(efx, wol->wolopts);
697 }
698
699 static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
700 {
701 struct efx_nic *efx = netdev_priv(net_dev);
702 int rc;
703
704 rc = efx->type->map_reset_flags(flags);
705 if (rc < 0)
706 return rc;
707
708 return efx_reset(efx, rc);
709 }
710
711 /* MAC address mask including only I/G bit */
712 static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
713
714 #define IP4_ADDR_FULL_MASK ((__force __be32)~0)
715 #define PORT_FULL_MASK ((__force __be16)~0)
716 #define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
717
718 static int efx_ethtool_get_class_rule(struct efx_nic *efx,
719 struct ethtool_rx_flow_spec *rule)
720 {
721 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
722 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
723 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
724 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
725 struct efx_filter_spec spec;
726 int rc;
727
728 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
729 rule->location, &spec);
730 if (rc)
731 return rc;
732
733 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
734 rule->ring_cookie = RX_CLS_FLOW_DISC;
735 else
736 rule->ring_cookie = spec.dmaq_id;
737
738 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
739 spec.ether_type == htons(ETH_P_IP) &&
740 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
741 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
742 !(spec.match_flags &
743 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
744 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
745 EFX_FILTER_MATCH_IP_PROTO |
746 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
747 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
748 TCP_V4_FLOW : UDP_V4_FLOW);
749 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
750 ip_entry->ip4dst = spec.loc_host[0];
751 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
752 }
753 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
754 ip_entry->ip4src = spec.rem_host[0];
755 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
756 }
757 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
758 ip_entry->pdst = spec.loc_port;
759 ip_mask->pdst = PORT_FULL_MASK;
760 }
761 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
762 ip_entry->psrc = spec.rem_port;
763 ip_mask->psrc = PORT_FULL_MASK;
764 }
765 } else if (!(spec.match_flags &
766 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
767 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
768 EFX_FILTER_MATCH_OUTER_VID))) {
769 rule->flow_type = ETHER_FLOW;
770 if (spec.match_flags &
771 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
772 memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN);
773 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
774 memset(mac_mask->h_dest, ~0, ETH_ALEN);
775 else
776 memcpy(mac_mask->h_dest, mac_addr_ig_mask,
777 ETH_ALEN);
778 }
779 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
780 memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN);
781 memset(mac_mask->h_source, ~0, ETH_ALEN);
782 }
783 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
784 mac_entry->h_proto = spec.ether_type;
785 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
786 }
787 } else {
788 /* The above should handle all filters that we insert */
789 WARN_ON(1);
790 return -EINVAL;
791 }
792
793 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
794 rule->flow_type |= FLOW_EXT;
795 rule->h_ext.vlan_tci = spec.outer_vid;
796 rule->m_ext.vlan_tci = htons(0xfff);
797 }
798
799 return rc;
800 }
801
802 static int
803 efx_ethtool_get_rxnfc(struct net_device *net_dev,
804 struct ethtool_rxnfc *info, u32 *rule_locs)
805 {
806 struct efx_nic *efx = netdev_priv(net_dev);
807
808 switch (info->cmd) {
809 case ETHTOOL_GRXRINGS:
810 info->data = efx->n_rx_channels;
811 return 0;
812
813 case ETHTOOL_GRXFH: {
814 unsigned min_revision = 0;
815
816 info->data = 0;
817 switch (info->flow_type) {
818 case TCP_V4_FLOW:
819 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
820 /* fall through */
821 case UDP_V4_FLOW:
822 case SCTP_V4_FLOW:
823 case AH_ESP_V4_FLOW:
824 case IPV4_FLOW:
825 info->data |= RXH_IP_SRC | RXH_IP_DST;
826 min_revision = EFX_REV_FALCON_B0;
827 break;
828 case TCP_V6_FLOW:
829 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
830 /* fall through */
831 case UDP_V6_FLOW:
832 case SCTP_V6_FLOW:
833 case AH_ESP_V6_FLOW:
834 case IPV6_FLOW:
835 info->data |= RXH_IP_SRC | RXH_IP_DST;
836 min_revision = EFX_REV_SIENA_A0;
837 break;
838 default:
839 break;
840 }
841 if (efx_nic_rev(efx) < min_revision)
842 info->data = 0;
843 return 0;
844 }
845
846 case ETHTOOL_GRXCLSRLCNT:
847 info->data = efx_filter_get_rx_id_limit(efx);
848 if (info->data == 0)
849 return -EOPNOTSUPP;
850 info->data |= RX_CLS_LOC_SPECIAL;
851 info->rule_cnt =
852 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
853 return 0;
854
855 case ETHTOOL_GRXCLSRULE:
856 if (efx_filter_get_rx_id_limit(efx) == 0)
857 return -EOPNOTSUPP;
858 return efx_ethtool_get_class_rule(efx, &info->fs);
859
860 case ETHTOOL_GRXCLSRLALL: {
861 s32 rc;
862 info->data = efx_filter_get_rx_id_limit(efx);
863 if (info->data == 0)
864 return -EOPNOTSUPP;
865 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
866 rule_locs, info->rule_cnt);
867 if (rc < 0)
868 return rc;
869 info->rule_cnt = rc;
870 return 0;
871 }
872
873 default:
874 return -EOPNOTSUPP;
875 }
876 }
877
878 static int efx_ethtool_set_class_rule(struct efx_nic *efx,
879 struct ethtool_rx_flow_spec *rule)
880 {
881 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
882 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
883 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
884 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
885 struct efx_filter_spec spec;
886 int rc;
887
888 /* Check that user wants us to choose the location */
889 if (rule->location != RX_CLS_LOC_ANY)
890 return -EINVAL;
891
892 /* Range-check ring_cookie */
893 if (rule->ring_cookie >= efx->n_rx_channels &&
894 rule->ring_cookie != RX_CLS_FLOW_DISC)
895 return -EINVAL;
896
897 /* Check for unsupported extensions */
898 if ((rule->flow_type & FLOW_EXT) &&
899 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
900 rule->m_ext.data[1]))
901 return -EINVAL;
902
903 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
904 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
905 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
906 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
907
908 switch (rule->flow_type & ~FLOW_EXT) {
909 case TCP_V4_FLOW:
910 case UDP_V4_FLOW:
911 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
912 EFX_FILTER_MATCH_IP_PROTO);
913 spec.ether_type = htons(ETH_P_IP);
914 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
915 IPPROTO_TCP : IPPROTO_UDP);
916 if (ip_mask->ip4dst) {
917 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
918 return -EINVAL;
919 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
920 spec.loc_host[0] = ip_entry->ip4dst;
921 }
922 if (ip_mask->ip4src) {
923 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
924 return -EINVAL;
925 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
926 spec.rem_host[0] = ip_entry->ip4src;
927 }
928 if (ip_mask->pdst) {
929 if (ip_mask->pdst != PORT_FULL_MASK)
930 return -EINVAL;
931 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
932 spec.loc_port = ip_entry->pdst;
933 }
934 if (ip_mask->psrc) {
935 if (ip_mask->psrc != PORT_FULL_MASK)
936 return -EINVAL;
937 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
938 spec.rem_port = ip_entry->psrc;
939 }
940 if (ip_mask->tos)
941 return -EINVAL;
942 break;
943
944 case ETHER_FLOW:
945 if (!is_zero_ether_addr(mac_mask->h_dest)) {
946 if (ether_addr_equal(mac_mask->h_dest,
947 mac_addr_ig_mask))
948 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
949 else if (is_broadcast_ether_addr(mac_mask->h_dest))
950 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
951 else
952 return -EINVAL;
953 memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN);
954 }
955 if (!is_zero_ether_addr(mac_mask->h_source)) {
956 if (!is_broadcast_ether_addr(mac_mask->h_source))
957 return -EINVAL;
958 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
959 memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN);
960 }
961 if (mac_mask->h_proto) {
962 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
963 return -EINVAL;
964 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
965 spec.ether_type = mac_entry->h_proto;
966 }
967 break;
968
969 default:
970 return -EINVAL;
971 }
972
973 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
974 if (rule->m_ext.vlan_tci != htons(0xfff))
975 return -EINVAL;
976 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
977 spec.outer_vid = rule->h_ext.vlan_tci;
978 }
979
980 rc = efx_filter_insert_filter(efx, &spec, true);
981 if (rc < 0)
982 return rc;
983
984 rule->location = rc;
985 return 0;
986 }
987
988 static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
989 struct ethtool_rxnfc *info)
990 {
991 struct efx_nic *efx = netdev_priv(net_dev);
992
993 if (efx_filter_get_rx_id_limit(efx) == 0)
994 return -EOPNOTSUPP;
995
996 switch (info->cmd) {
997 case ETHTOOL_SRXCLSRLINS:
998 return efx_ethtool_set_class_rule(efx, &info->fs);
999
1000 case ETHTOOL_SRXCLSRLDEL:
1001 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1002 info->fs.location);
1003
1004 default:
1005 return -EOPNOTSUPP;
1006 }
1007 }
1008
1009 static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
1010 {
1011 struct efx_nic *efx = netdev_priv(net_dev);
1012
1013 return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
1014 efx->n_rx_channels == 1) ?
1015 0 : ARRAY_SIZE(efx->rx_indir_table));
1016 }
1017
1018 static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
1019 {
1020 struct efx_nic *efx = netdev_priv(net_dev);
1021
1022 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
1023 return 0;
1024 }
1025
1026 static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
1027 const u32 *indir)
1028 {
1029 struct efx_nic *efx = netdev_priv(net_dev);
1030
1031 memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
1032 efx_nic_push_rx_indir_table(efx);
1033 return 0;
1034 }
1035
1036 int efx_ethtool_get_ts_info(struct net_device *net_dev,
1037 struct ethtool_ts_info *ts_info)
1038 {
1039 struct efx_nic *efx = netdev_priv(net_dev);
1040
1041 /* Software capabilities */
1042 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1043 SOF_TIMESTAMPING_SOFTWARE);
1044 ts_info->phc_index = -1;
1045
1046 efx_ptp_get_ts_info(efx, ts_info);
1047 return 0;
1048 }
1049
1050 static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1051 struct ethtool_eeprom *ee,
1052 u8 *data)
1053 {
1054 struct efx_nic *efx = netdev_priv(net_dev);
1055 int ret;
1056
1057 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1058 return -EOPNOTSUPP;
1059
1060 mutex_lock(&efx->mac_lock);
1061 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1062 mutex_unlock(&efx->mac_lock);
1063
1064 return ret;
1065 }
1066
1067 static int efx_ethtool_get_module_info(struct net_device *net_dev,
1068 struct ethtool_modinfo *modinfo)
1069 {
1070 struct efx_nic *efx = netdev_priv(net_dev);
1071 int ret;
1072
1073 if (!efx->phy_op || !efx->phy_op->get_module_info)
1074 return -EOPNOTSUPP;
1075
1076 mutex_lock(&efx->mac_lock);
1077 ret = efx->phy_op->get_module_info(efx, modinfo);
1078 mutex_unlock(&efx->mac_lock);
1079
1080 return ret;
1081 }
1082
1083 const struct ethtool_ops efx_ethtool_ops = {
1084 .get_settings = efx_ethtool_get_settings,
1085 .set_settings = efx_ethtool_set_settings,
1086 .get_drvinfo = efx_ethtool_get_drvinfo,
1087 .get_regs_len = efx_ethtool_get_regs_len,
1088 .get_regs = efx_ethtool_get_regs,
1089 .get_msglevel = efx_ethtool_get_msglevel,
1090 .set_msglevel = efx_ethtool_set_msglevel,
1091 .nway_reset = efx_ethtool_nway_reset,
1092 .get_link = ethtool_op_get_link,
1093 .get_coalesce = efx_ethtool_get_coalesce,
1094 .set_coalesce = efx_ethtool_set_coalesce,
1095 .get_ringparam = efx_ethtool_get_ringparam,
1096 .set_ringparam = efx_ethtool_set_ringparam,
1097 .get_pauseparam = efx_ethtool_get_pauseparam,
1098 .set_pauseparam = efx_ethtool_set_pauseparam,
1099 .get_sset_count = efx_ethtool_get_sset_count,
1100 .self_test = efx_ethtool_self_test,
1101 .get_strings = efx_ethtool_get_strings,
1102 .set_phys_id = efx_ethtool_phys_id,
1103 .get_ethtool_stats = efx_ethtool_get_stats,
1104 .get_wol = efx_ethtool_get_wol,
1105 .set_wol = efx_ethtool_set_wol,
1106 .reset = efx_ethtool_reset,
1107 .get_rxnfc = efx_ethtool_get_rxnfc,
1108 .set_rxnfc = efx_ethtool_set_rxnfc,
1109 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
1110 .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
1111 .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
1112 .get_ts_info = efx_ethtool_get_ts_info,
1113 .get_module_info = efx_ethtool_get_module_info,
1114 .get_module_eeprom = efx_ethtool_get_module_eeprom,
1115 };
This page took 0.074496 seconds and 6 git commands to generate.