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