sfc: Correct interpretation of second param to ethtool phys_id()
[linux-2.6/mini2440.git] / drivers / net / sfc / ethtool.c
blob9c533e036a0047b38a1b626ec558ee2025cf5b97
1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 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 "selftest.h"
16 #include "efx.h"
17 #include "ethtool.h"
18 #include "falcon.h"
19 #include "gmii.h"
20 #include "spi.h"
21 #include "mac.h"
23 const char *efx_loopback_mode_names[] = {
24 [LOOPBACK_NONE] = "NONE",
25 [LOOPBACK_MAC] = "MAC",
26 [LOOPBACK_XGMII] = "XGMII",
27 [LOOPBACK_XGXS] = "XGXS",
28 [LOOPBACK_XAUI] = "XAUI",
29 [LOOPBACK_PHY] = "PHY",
30 [LOOPBACK_PHYXS] = "PHY(XS)",
31 [LOOPBACK_PCS] = "PHY(PCS)",
32 [LOOPBACK_PMAPMD] = "PHY(PMAPMD)",
33 [LOOPBACK_NETWORK] = "NETWORK",
36 struct ethtool_string {
37 char name[ETH_GSTRING_LEN];
40 struct efx_ethtool_stat {
41 const char *name;
42 enum {
43 EFX_ETHTOOL_STAT_SOURCE_mac_stats,
44 EFX_ETHTOOL_STAT_SOURCE_nic,
45 EFX_ETHTOOL_STAT_SOURCE_channel
46 } source;
47 unsigned offset;
48 u64(*get_stat) (void *field); /* Reader function */
51 /* Initialiser for a struct #efx_ethtool_stat with type-checking */
52 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
53 get_stat_function) { \
54 .name = #stat_name, \
55 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
56 .offset = ((((field_type *) 0) == \
57 &((struct efx_##source_name *)0)->field) ? \
58 offsetof(struct efx_##source_name, field) : \
59 offsetof(struct efx_##source_name, field)), \
60 .get_stat = get_stat_function, \
63 static u64 efx_get_uint_stat(void *field)
65 return *(unsigned int *)field;
68 static u64 efx_get_ulong_stat(void *field)
70 return *(unsigned long *)field;
73 static u64 efx_get_u64_stat(void *field)
75 return *(u64 *) field;
78 static u64 efx_get_atomic_stat(void *field)
80 return atomic_read((atomic_t *) field);
83 #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
84 EFX_ETHTOOL_STAT(field, mac_stats, field, \
85 unsigned long, efx_get_ulong_stat)
87 #define EFX_ETHTOOL_U64_MAC_STAT(field) \
88 EFX_ETHTOOL_STAT(field, mac_stats, field, \
89 u64, efx_get_u64_stat)
91 #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
92 EFX_ETHTOOL_STAT(name, nic, n_##name, \
93 unsigned int, efx_get_uint_stat)
95 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
96 EFX_ETHTOOL_STAT(field, nic, field, \
97 atomic_t, efx_get_atomic_stat)
99 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
100 EFX_ETHTOOL_STAT(field, channel, n_##field, \
101 unsigned int, efx_get_uint_stat)
103 static struct efx_ethtool_stat efx_ethtool_stats[] = {
104 EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
105 EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
106 EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
107 EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
108 EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
109 EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
110 EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
111 EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
112 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
113 EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
114 EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
115 EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
116 EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
117 EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
118 EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
119 EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
120 EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
121 EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
122 EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
123 EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
124 EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
125 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
126 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
127 EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
128 EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
129 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
130 EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
131 EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
132 EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
133 EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
134 EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
135 EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
136 EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
137 EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
138 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
139 EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
140 EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
141 EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
142 EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
143 EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
144 EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
145 EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
146 EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
147 EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
148 EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
149 EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
150 EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
151 EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
152 EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
153 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
154 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
155 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
156 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
157 EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
158 EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
159 EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
160 EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
161 EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
162 EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
163 EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
164 EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
165 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
166 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
167 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
168 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
169 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
172 /* Number of ethtool statistics */
173 #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
175 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
177 /**************************************************************************
179 * Ethtool operations
181 **************************************************************************
184 /* Identify device by flashing LEDs */
185 static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
187 struct efx_nic *efx = netdev_priv(net_dev);
189 efx->board_info.blink(efx, 1);
190 set_current_state(TASK_INTERRUPTIBLE);
191 if (count)
192 schedule_timeout(count * HZ);
193 else
194 schedule();
195 efx->board_info.blink(efx, 0);
196 return 0;
199 /* This must be called with rtnl_lock held. */
200 int efx_ethtool_get_settings(struct net_device *net_dev,
201 struct ethtool_cmd *ecmd)
203 struct efx_nic *efx = netdev_priv(net_dev);
204 int rc;
206 mutex_lock(&efx->mac_lock);
207 rc = falcon_xmac_get_settings(efx, ecmd);
208 mutex_unlock(&efx->mac_lock);
210 return rc;
213 /* This must be called with rtnl_lock held. */
214 int efx_ethtool_set_settings(struct net_device *net_dev,
215 struct ethtool_cmd *ecmd)
217 struct efx_nic *efx = netdev_priv(net_dev);
218 int rc;
220 mutex_lock(&efx->mac_lock);
221 rc = falcon_xmac_set_settings(efx, ecmd);
222 mutex_unlock(&efx->mac_lock);
223 if (!rc)
224 efx_reconfigure_port(efx);
226 return rc;
229 static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
230 struct ethtool_drvinfo *info)
232 struct efx_nic *efx = netdev_priv(net_dev);
234 strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
235 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
236 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
240 * efx_fill_test - fill in an individual self-test entry
241 * @test_index: Index of the test
242 * @strings: Ethtool strings, or %NULL
243 * @data: Ethtool test results, or %NULL
244 * @test: Pointer to test result (used only if data != %NULL)
245 * @unit_format: Unit name format (e.g. "channel\%d")
246 * @unit_id: Unit id (e.g. 0 for "channel0")
247 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
248 * @test_id: Test id (e.g. "PHY" for "loopback.PHY.tx_sent")
250 * Fill in an individual self-test entry.
252 static void efx_fill_test(unsigned int test_index,
253 struct ethtool_string *strings, u64 *data,
254 int *test, const char *unit_format, int unit_id,
255 const char *test_format, const char *test_id)
257 struct ethtool_string unit_str, test_str;
259 /* Fill data value, if applicable */
260 if (data)
261 data[test_index] = *test;
263 /* Fill string, if applicable */
264 if (strings) {
265 snprintf(unit_str.name, sizeof(unit_str.name),
266 unit_format, unit_id);
267 snprintf(test_str.name, sizeof(test_str.name),
268 test_format, test_id);
269 snprintf(strings[test_index].name,
270 sizeof(strings[test_index].name),
271 "%-9s%-17s", unit_str.name, test_str.name);
275 #define EFX_PORT_NAME "port%d", 0
276 #define EFX_CHANNEL_NAME(_channel) "channel%d", _channel->channel
277 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
278 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
279 #define EFX_LOOPBACK_NAME(_mode, _counter) \
280 "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
283 * efx_fill_loopback_test - fill in a block of loopback self-test entries
284 * @efx: Efx NIC
285 * @lb_tests: Efx loopback self-test results structure
286 * @mode: Loopback test mode
287 * @test_index: Starting index of the test
288 * @strings: Ethtool strings, or %NULL
289 * @data: Ethtool test results, or %NULL
291 static int efx_fill_loopback_test(struct efx_nic *efx,
292 struct efx_loopback_self_tests *lb_tests,
293 enum efx_loopback_mode mode,
294 unsigned int test_index,
295 struct ethtool_string *strings, u64 *data)
297 struct efx_tx_queue *tx_queue;
299 efx_for_each_tx_queue(tx_queue, efx) {
300 efx_fill_test(test_index++, strings, data,
301 &lb_tests->tx_sent[tx_queue->queue],
302 EFX_TX_QUEUE_NAME(tx_queue),
303 EFX_LOOPBACK_NAME(mode, "tx_sent"));
304 efx_fill_test(test_index++, strings, data,
305 &lb_tests->tx_done[tx_queue->queue],
306 EFX_TX_QUEUE_NAME(tx_queue),
307 EFX_LOOPBACK_NAME(mode, "tx_done"));
309 efx_fill_test(test_index++, strings, data,
310 &lb_tests->rx_good,
311 EFX_PORT_NAME,
312 EFX_LOOPBACK_NAME(mode, "rx_good"));
313 efx_fill_test(test_index++, strings, data,
314 &lb_tests->rx_bad,
315 EFX_PORT_NAME,
316 EFX_LOOPBACK_NAME(mode, "rx_bad"));
318 return test_index;
322 * efx_ethtool_fill_self_tests - get self-test details
323 * @efx: Efx NIC
324 * @tests: Efx self-test results structure, or %NULL
325 * @strings: Ethtool strings, or %NULL
326 * @data: Ethtool test results, or %NULL
328 static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
329 struct efx_self_tests *tests,
330 struct ethtool_string *strings,
331 u64 *data)
333 struct efx_channel *channel;
334 unsigned int n = 0;
335 enum efx_loopback_mode mode;
337 efx_fill_test(n++, strings, data, &tests->mii,
338 "core", 0, "mii", NULL);
339 efx_fill_test(n++, strings, data, &tests->nvram,
340 "core", 0, "nvram", NULL);
341 efx_fill_test(n++, strings, data, &tests->interrupt,
342 "core", 0, "interrupt", NULL);
344 /* Event queues */
345 efx_for_each_channel(channel, efx) {
346 efx_fill_test(n++, strings, data,
347 &tests->eventq_dma[channel->channel],
348 EFX_CHANNEL_NAME(channel),
349 "eventq.dma", NULL);
350 efx_fill_test(n++, strings, data,
351 &tests->eventq_int[channel->channel],
352 EFX_CHANNEL_NAME(channel),
353 "eventq.int", NULL);
354 efx_fill_test(n++, strings, data,
355 &tests->eventq_poll[channel->channel],
356 EFX_CHANNEL_NAME(channel),
357 "eventq.poll", NULL);
360 efx_fill_test(n++, strings, data, &tests->registers,
361 "core", 0, "registers", NULL);
362 efx_fill_test(n++, strings, data, &tests->phy,
363 EFX_PORT_NAME, "phy", NULL);
365 /* Loopback tests */
366 efx_fill_test(n++, strings, data, &tests->loopback_speed,
367 EFX_PORT_NAME, "loopback.speed", NULL);
368 efx_fill_test(n++, strings, data, &tests->loopback_full_duplex,
369 EFX_PORT_NAME, "loopback.full_duplex", NULL);
370 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
371 if (!(efx->loopback_modes & (1 << mode)))
372 continue;
373 n = efx_fill_loopback_test(efx,
374 &tests->loopback[mode], mode, n,
375 strings, data);
378 return n;
381 static int efx_ethtool_get_sset_count(struct net_device *net_dev,
382 int string_set)
384 switch (string_set) {
385 case ETH_SS_STATS:
386 return EFX_ETHTOOL_NUM_STATS;
387 case ETH_SS_TEST:
388 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
389 NULL, NULL, NULL);
390 default:
391 return -EINVAL;
395 static void efx_ethtool_get_strings(struct net_device *net_dev,
396 u32 string_set, u8 *strings)
398 struct efx_nic *efx = netdev_priv(net_dev);
399 struct ethtool_string *ethtool_strings =
400 (struct ethtool_string *)strings;
401 int i;
403 switch (string_set) {
404 case ETH_SS_STATS:
405 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
406 strncpy(ethtool_strings[i].name,
407 efx_ethtool_stats[i].name,
408 sizeof(ethtool_strings[i].name));
409 break;
410 case ETH_SS_TEST:
411 efx_ethtool_fill_self_tests(efx, NULL,
412 ethtool_strings, NULL);
413 break;
414 default:
415 /* No other string sets */
416 break;
420 static void efx_ethtool_get_stats(struct net_device *net_dev,
421 struct ethtool_stats *stats,
422 u64 *data)
424 struct efx_nic *efx = netdev_priv(net_dev);
425 struct efx_mac_stats *mac_stats = &efx->mac_stats;
426 struct efx_ethtool_stat *stat;
427 struct efx_channel *channel;
428 int i;
430 EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
432 /* Update MAC and NIC statistics */
433 dev_get_stats(net_dev);
435 /* Fill detailed statistics buffer */
436 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
437 stat = &efx_ethtool_stats[i];
438 switch (stat->source) {
439 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
440 data[i] = stat->get_stat((void *)mac_stats +
441 stat->offset);
442 break;
443 case EFX_ETHTOOL_STAT_SOURCE_nic:
444 data[i] = stat->get_stat((void *)efx + stat->offset);
445 break;
446 case EFX_ETHTOOL_STAT_SOURCE_channel:
447 data[i] = 0;
448 efx_for_each_channel(channel, efx)
449 data[i] += stat->get_stat((void *)channel +
450 stat->offset);
451 break;
456 static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
458 struct efx_nic *efx = netdev_priv(net_dev);
460 /* No way to stop the hardware doing the checks; we just
461 * ignore the result.
463 efx->rx_checksum_enabled = !!enable;
465 return 0;
468 static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
470 struct efx_nic *efx = netdev_priv(net_dev);
472 return efx->rx_checksum_enabled;
475 static void efx_ethtool_self_test(struct net_device *net_dev,
476 struct ethtool_test *test, u64 *data)
478 struct efx_nic *efx = netdev_priv(net_dev);
479 struct efx_self_tests efx_tests;
480 int offline, already_up;
481 int rc;
483 ASSERT_RTNL();
484 if (efx->state != STATE_RUNNING) {
485 rc = -EIO;
486 goto fail1;
489 /* We need rx buffers and interrupts. */
490 already_up = (efx->net_dev->flags & IFF_UP);
491 if (!already_up) {
492 rc = dev_open(efx->net_dev);
493 if (rc) {
494 EFX_ERR(efx, "failed opening device.\n");
495 goto fail2;
499 memset(&efx_tests, 0, sizeof(efx_tests));
500 offline = (test->flags & ETH_TEST_FL_OFFLINE);
502 /* Perform online self tests first */
503 rc = efx_online_test(efx, &efx_tests);
504 if (rc)
505 goto out;
507 /* Perform offline tests only if online tests passed */
508 if (offline)
509 rc = efx_offline_test(efx, &efx_tests,
510 efx->loopback_modes);
512 out:
513 if (!already_up)
514 dev_close(efx->net_dev);
516 EFX_LOG(efx, "%s all %sline self-tests\n",
517 rc == 0 ? "passed" : "failed", offline ? "off" : "on");
519 fail2:
520 fail1:
521 /* Fill ethtool results structures */
522 efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
523 if (rc)
524 test->flags |= ETH_TEST_FL_FAILED;
527 /* Restart autonegotiation */
528 static int efx_ethtool_nway_reset(struct net_device *net_dev)
530 struct efx_nic *efx = netdev_priv(net_dev);
532 return mii_nway_restart(&efx->mii);
535 static u32 efx_ethtool_get_link(struct net_device *net_dev)
537 struct efx_nic *efx = netdev_priv(net_dev);
539 return efx->link_up;
542 static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
544 struct efx_nic *efx = netdev_priv(net_dev);
545 struct efx_spi_device *spi = efx->spi_eeprom;
547 if (!spi)
548 return 0;
549 return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
550 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
553 static int efx_ethtool_get_eeprom(struct net_device *net_dev,
554 struct ethtool_eeprom *eeprom, u8 *buf)
556 struct efx_nic *efx = netdev_priv(net_dev);
557 struct efx_spi_device *spi = efx->spi_eeprom;
558 size_t len;
559 int rc;
561 mutex_lock(&efx->spi_lock);
562 rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
563 eeprom->len, &len, buf);
564 mutex_unlock(&efx->spi_lock);
565 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
566 eeprom->len = len;
567 return rc;
570 static int efx_ethtool_set_eeprom(struct net_device *net_dev,
571 struct ethtool_eeprom *eeprom, u8 *buf)
573 struct efx_nic *efx = netdev_priv(net_dev);
574 struct efx_spi_device *spi = efx->spi_eeprom;
575 size_t len;
576 int rc;
578 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
579 return -EINVAL;
581 mutex_lock(&efx->spi_lock);
582 rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
583 eeprom->len, &len, buf);
584 mutex_unlock(&efx->spi_lock);
585 eeprom->len = len;
586 return rc;
589 static int efx_ethtool_get_coalesce(struct net_device *net_dev,
590 struct ethtool_coalesce *coalesce)
592 struct efx_nic *efx = netdev_priv(net_dev);
593 struct efx_tx_queue *tx_queue;
594 struct efx_rx_queue *rx_queue;
595 struct efx_channel *channel;
597 memset(coalesce, 0, sizeof(*coalesce));
599 /* Find lowest IRQ moderation across all used TX queues */
600 coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
601 efx_for_each_tx_queue(tx_queue, efx) {
602 channel = tx_queue->channel;
603 if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
604 if (channel->used_flags != EFX_USED_BY_RX_TX)
605 coalesce->tx_coalesce_usecs_irq =
606 channel->irq_moderation;
607 else
608 coalesce->tx_coalesce_usecs_irq = 0;
612 /* Find lowest IRQ moderation across all used RX queues */
613 coalesce->rx_coalesce_usecs_irq = ~((u32) 0);
614 efx_for_each_rx_queue(rx_queue, efx) {
615 channel = rx_queue->channel;
616 if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq)
617 coalesce->rx_coalesce_usecs_irq =
618 channel->irq_moderation;
621 return 0;
624 /* Set coalescing parameters
625 * The difficulties occur for shared channels
627 static int efx_ethtool_set_coalesce(struct net_device *net_dev,
628 struct ethtool_coalesce *coalesce)
630 struct efx_nic *efx = netdev_priv(net_dev);
631 struct efx_channel *channel;
632 struct efx_tx_queue *tx_queue;
633 unsigned tx_usecs, rx_usecs;
635 if (coalesce->use_adaptive_rx_coalesce ||
636 coalesce->use_adaptive_tx_coalesce)
637 return -EOPNOTSUPP;
639 if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
640 EFX_ERR(efx, "invalid coalescing setting. "
641 "Only rx/tx_coalesce_usecs_irq are supported\n");
642 return -EOPNOTSUPP;
645 rx_usecs = coalesce->rx_coalesce_usecs_irq;
646 tx_usecs = coalesce->tx_coalesce_usecs_irq;
648 /* If the channel is shared only allow RX parameters to be set */
649 efx_for_each_tx_queue(tx_queue, efx) {
650 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
651 tx_usecs) {
652 EFX_ERR(efx, "Channel is shared. "
653 "Only RX coalescing may be set\n");
654 return -EOPNOTSUPP;
658 efx_init_irq_moderation(efx, tx_usecs, rx_usecs);
660 /* Reset channel to pick up new moderation value. Note that
661 * this may change the value of the irq_moderation field
662 * (e.g. to allow for hardware timer granularity).
664 efx_for_each_channel(channel, efx)
665 falcon_set_int_moderation(channel);
667 return 0;
670 static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
671 struct ethtool_pauseparam *pause)
673 struct efx_nic *efx = netdev_priv(net_dev);
674 enum efx_fc_type flow_control = efx->flow_control;
675 int rc;
677 flow_control &= ~(EFX_FC_RX | EFX_FC_TX | EFX_FC_AUTO);
678 flow_control |= pause->rx_pause ? EFX_FC_RX : 0;
679 flow_control |= pause->tx_pause ? EFX_FC_TX : 0;
680 flow_control |= pause->autoneg ? EFX_FC_AUTO : 0;
682 /* Try to push the pause parameters */
683 mutex_lock(&efx->mac_lock);
684 rc = falcon_xmac_set_pause(efx, flow_control);
685 mutex_unlock(&efx->mac_lock);
687 if (!rc)
688 efx_reconfigure_port(efx);
690 return rc;
693 static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
694 struct ethtool_pauseparam *pause)
696 struct efx_nic *efx = netdev_priv(net_dev);
698 pause->rx_pause = !!(efx->flow_control & EFX_FC_RX);
699 pause->tx_pause = !!(efx->flow_control & EFX_FC_TX);
700 pause->autoneg = !!(efx->flow_control & EFX_FC_AUTO);
704 struct ethtool_ops efx_ethtool_ops = {
705 .get_settings = efx_ethtool_get_settings,
706 .set_settings = efx_ethtool_set_settings,
707 .get_drvinfo = efx_ethtool_get_drvinfo,
708 .nway_reset = efx_ethtool_nway_reset,
709 .get_link = efx_ethtool_get_link,
710 .get_eeprom_len = efx_ethtool_get_eeprom_len,
711 .get_eeprom = efx_ethtool_get_eeprom,
712 .set_eeprom = efx_ethtool_set_eeprom,
713 .get_coalesce = efx_ethtool_get_coalesce,
714 .set_coalesce = efx_ethtool_set_coalesce,
715 .get_pauseparam = efx_ethtool_get_pauseparam,
716 .set_pauseparam = efx_ethtool_set_pauseparam,
717 .get_rx_csum = efx_ethtool_get_rx_csum,
718 .set_rx_csum = efx_ethtool_set_rx_csum,
719 .get_tx_csum = ethtool_op_get_tx_csum,
720 .set_tx_csum = ethtool_op_set_tx_csum,
721 .get_sg = ethtool_op_get_sg,
722 .set_sg = ethtool_op_set_sg,
723 .get_tso = ethtool_op_get_tso,
724 .set_tso = ethtool_op_set_tso,
725 .get_flags = ethtool_op_get_flags,
726 .set_flags = ethtool_op_set_flags,
727 .get_sset_count = efx_ethtool_get_sset_count,
728 .self_test = efx_ethtool_self_test,
729 .get_strings = efx_ethtool_get_strings,
730 .phys_id = efx_ethtool_phys_id,
731 .get_ethtool_stats = efx_ethtool_get_stats,