blob: 18e02712818cf7805e19a4b6e81f6d97fc6f1290 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 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>
Ben Hutchings68e7f452009-04-29 08:05:08 +000013#include <linux/mdio.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010014#include <linux/rtnetlink.h>
15#include "net_driver.h"
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080016#include "workarounds.h"
Ben Hutchings3273c2e2008-05-07 13:36:19 +010017#include "selftest.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010018#include "efx.h"
19#include "ethtool.h"
20#include "falcon.h"
Ben Hutchings4a5b5042008-09-01 12:47:16 +010021#include "spi.h"
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080022#include "mdio_10g.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010023
Ben Hutchings3273c2e2008-05-07 13:36:19 +010024const char *efx_loopback_mode_names[] = {
25 [LOOPBACK_NONE] = "NONE",
Ben Hutchings177dfcd2008-12-12 21:50:08 -080026 [LOOPBACK_GMAC] = "GMAC",
Ben Hutchings3273c2e2008-05-07 13:36:19 +010027 [LOOPBACK_XGMII] = "XGMII",
28 [LOOPBACK_XGXS] = "XGXS",
29 [LOOPBACK_XAUI] = "XAUI",
Ben Hutchings177dfcd2008-12-12 21:50:08 -080030 [LOOPBACK_GPHY] = "GPHY",
Ben Hutchings740ced92008-12-12 21:41:55 -080031 [LOOPBACK_PHYXS] = "PHYXS",
32 [LOOPBACK_PCS] = "PCS",
33 [LOOPBACK_PMAPMD] = "PMA/PMD",
Ben Hutchings3273c2e2008-05-07 13:36:19 +010034 [LOOPBACK_NETWORK] = "NETWORK",
35};
36
Ben Hutchings8ceee662008-04-27 12:55:59 +010037struct ethtool_string {
38 char name[ETH_GSTRING_LEN];
39};
40
41struct efx_ethtool_stat {
42 const char *name;
43 enum {
44 EFX_ETHTOOL_STAT_SOURCE_mac_stats,
45 EFX_ETHTOOL_STAT_SOURCE_nic,
46 EFX_ETHTOOL_STAT_SOURCE_channel
47 } source;
48 unsigned offset;
49 u64(*get_stat) (void *field); /* Reader function */
50};
51
52/* Initialiser for a struct #efx_ethtool_stat with type-checking */
53#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
54 get_stat_function) { \
55 .name = #stat_name, \
56 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
57 .offset = ((((field_type *) 0) == \
58 &((struct efx_##source_name *)0)->field) ? \
59 offsetof(struct efx_##source_name, field) : \
60 offsetof(struct efx_##source_name, field)), \
61 .get_stat = get_stat_function, \
62}
63
64static u64 efx_get_uint_stat(void *field)
65{
66 return *(unsigned int *)field;
67}
68
69static u64 efx_get_ulong_stat(void *field)
70{
71 return *(unsigned long *)field;
72}
73
74static u64 efx_get_u64_stat(void *field)
75{
76 return *(u64 *) field;
77}
78
79static u64 efx_get_atomic_stat(void *field)
80{
81 return atomic_read((atomic_t *) field);
82}
83
84#define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
85 EFX_ETHTOOL_STAT(field, mac_stats, field, \
86 unsigned long, efx_get_ulong_stat)
87
88#define EFX_ETHTOOL_U64_MAC_STAT(field) \
89 EFX_ETHTOOL_STAT(field, mac_stats, field, \
90 u64, efx_get_u64_stat)
91
92#define EFX_ETHTOOL_UINT_NIC_STAT(name) \
93 EFX_ETHTOOL_STAT(name, nic, n_##name, \
94 unsigned int, efx_get_uint_stat)
95
96#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
97 EFX_ETHTOOL_STAT(field, nic, field, \
98 atomic_t, efx_get_atomic_stat)
99
100#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
101 EFX_ETHTOOL_STAT(field, channel, n_##field, \
102 unsigned int, efx_get_uint_stat)
103
104static struct efx_ethtool_stat efx_ethtool_stats[] = {
105 EFX_ETHTOOL_U64_MAC_STAT(tx_bytes),
106 EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes),
107 EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes),
108 EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets),
109 EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad),
110 EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause),
111 EFX_ETHTOOL_ULONG_MAC_STAT(tx_control),
112 EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast),
113 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast),
114 EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast),
115 EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64),
116 EFX_ETHTOOL_ULONG_MAC_STAT(tx_64),
117 EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127),
118 EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255),
119 EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511),
120 EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023),
121 EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx),
122 EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo),
123 EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo),
124 EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision),
125 EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision),
126 EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision),
127 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision),
128 EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred),
129 EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision),
130 EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred),
131 EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp),
132 EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error),
133 EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error),
134 EFX_ETHTOOL_U64_MAC_STAT(rx_bytes),
135 EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes),
136 EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes),
137 EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets),
138 EFX_ETHTOOL_ULONG_MAC_STAT(rx_good),
139 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad),
140 EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause),
141 EFX_ETHTOOL_ULONG_MAC_STAT(rx_control),
142 EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast),
143 EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast),
144 EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast),
145 EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64),
146 EFX_ETHTOOL_ULONG_MAC_STAT(rx_64),
147 EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127),
148 EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255),
149 EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511),
150 EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023),
151 EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx),
152 EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo),
153 EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo),
154 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64),
155 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx),
156 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo),
157 EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo),
158 EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow),
159 EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed),
160 EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier),
161 EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error),
162 EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error),
163 EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error),
164 EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error),
165 EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt),
166 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
167 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
168 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
169 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
170 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
171};
172
173/* Number of ethtool statistics */
174#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
175
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100176#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100177
Ben Hutchings8ceee662008-04-27 12:55:59 +0100178/**************************************************************************
179 *
180 * Ethtool operations
181 *
182 **************************************************************************
183 */
184
185/* Identify device by flashing LEDs */
Ben Hutchings65f667f2008-12-12 21:32:10 -0800186static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100187{
Ben Hutchings767e4682008-09-01 12:43:14 +0100188 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100189
Ben Hutchings398468e2009-11-23 16:03:45 +0000190 do {
191 efx->board_info.set_id_led(efx, EFX_LED_ON);
192 schedule_timeout_interruptible(HZ / 2);
193
194 efx->board_info.set_id_led(efx, EFX_LED_OFF);
195 schedule_timeout_interruptible(HZ / 2);
196 } while (!signal_pending(current) && --count != 0);
197
198 efx->board_info.set_id_led(efx, EFX_LED_DEFAULT);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100199 return 0;
200}
201
202/* This must be called with rtnl_lock held. */
203int efx_ethtool_get_settings(struct net_device *net_dev,
204 struct ethtool_cmd *ecmd)
205{
Ben Hutchings767e4682008-09-01 12:43:14 +0100206 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100207
208 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800209 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100210 mutex_unlock(&efx->mac_lock);
211
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800212 /* Falcon GMAC does not support 1000Mbps HD */
213 ecmd->supported &= ~SUPPORTED_1000baseT_Half;
214
215 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100216}
217
218/* This must be called with rtnl_lock held. */
219int efx_ethtool_set_settings(struct net_device *net_dev,
220 struct ethtool_cmd *ecmd)
221{
Ben Hutchings767e4682008-09-01 12:43:14 +0100222 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100223 int rc;
224
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800225 /* Falcon GMAC does not support 1000Mbps HD */
226 if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
227 EFX_LOG(efx, "rejecting unsupported 1000Mbps HD"
228 " setting\n");
229 return -EINVAL;
230 }
231
Ben Hutchings8ceee662008-04-27 12:55:59 +0100232 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800233 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100234 mutex_unlock(&efx->mac_lock);
235 if (!rc)
236 efx_reconfigure_port(efx);
237
238 return rc;
239}
240
241static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
242 struct ethtool_drvinfo *info)
243{
Ben Hutchings767e4682008-09-01 12:43:14 +0100244 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100245
246 strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
247 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
248 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
249}
250
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100251/**
252 * efx_fill_test - fill in an individual self-test entry
253 * @test_index: Index of the test
254 * @strings: Ethtool strings, or %NULL
255 * @data: Ethtool test results, or %NULL
256 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800257 * @unit_format: Unit name format (e.g. "chan\%d")
258 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100259 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800260 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100261 *
262 * Fill in an individual self-test entry.
263 */
264static void efx_fill_test(unsigned int test_index,
265 struct ethtool_string *strings, u64 *data,
266 int *test, const char *unit_format, int unit_id,
267 const char *test_format, const char *test_id)
268{
269 struct ethtool_string unit_str, test_str;
270
271 /* Fill data value, if applicable */
272 if (data)
273 data[test_index] = *test;
274
275 /* Fill string, if applicable */
276 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800277 if (strchr(unit_format, '%'))
278 snprintf(unit_str.name, sizeof(unit_str.name),
279 unit_format, unit_id);
280 else
281 strcpy(unit_str.name, unit_format);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100282 snprintf(test_str.name, sizeof(test_str.name),
283 test_format, test_id);
284 snprintf(strings[test_index].name,
285 sizeof(strings[test_index].name),
Ben Hutchings740ced92008-12-12 21:41:55 -0800286 "%-6s %-24s", unit_str.name, test_str.name);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100287 }
288}
289
Ben Hutchings740ced92008-12-12 21:41:55 -0800290#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100291#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
292#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
293#define EFX_LOOPBACK_NAME(_mode, _counter) \
294 "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
295
296/**
297 * efx_fill_loopback_test - fill in a block of loopback self-test entries
298 * @efx: Efx NIC
299 * @lb_tests: Efx loopback self-test results structure
300 * @mode: Loopback test mode
301 * @test_index: Starting index of the test
302 * @strings: Ethtool strings, or %NULL
303 * @data: Ethtool test results, or %NULL
304 */
305static int efx_fill_loopback_test(struct efx_nic *efx,
306 struct efx_loopback_self_tests *lb_tests,
307 enum efx_loopback_mode mode,
308 unsigned int test_index,
309 struct ethtool_string *strings, u64 *data)
310{
311 struct efx_tx_queue *tx_queue;
312
313 efx_for_each_tx_queue(tx_queue, efx) {
314 efx_fill_test(test_index++, strings, data,
315 &lb_tests->tx_sent[tx_queue->queue],
316 EFX_TX_QUEUE_NAME(tx_queue),
317 EFX_LOOPBACK_NAME(mode, "tx_sent"));
318 efx_fill_test(test_index++, strings, data,
319 &lb_tests->tx_done[tx_queue->queue],
320 EFX_TX_QUEUE_NAME(tx_queue),
321 EFX_LOOPBACK_NAME(mode, "tx_done"));
322 }
323 efx_fill_test(test_index++, strings, data,
324 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800325 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100326 EFX_LOOPBACK_NAME(mode, "rx_good"));
327 efx_fill_test(test_index++, strings, data,
328 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800329 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100330 EFX_LOOPBACK_NAME(mode, "rx_bad"));
331
332 return test_index;
333}
334
335/**
336 * efx_ethtool_fill_self_tests - get self-test details
337 * @efx: Efx NIC
338 * @tests: Efx self-test results structure, or %NULL
339 * @strings: Ethtool strings, or %NULL
340 * @data: Ethtool test results, or %NULL
341 */
342static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
343 struct efx_self_tests *tests,
344 struct ethtool_string *strings,
345 u64 *data)
346{
347 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800348 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100349 enum efx_loopback_mode mode;
350
Ben Hutchings68e7f452009-04-29 08:05:08 +0000351 efx_fill_test(n++, strings, data, &tests->mdio,
352 "core", 0, "mdio", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100353 efx_fill_test(n++, strings, data, &tests->nvram,
354 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100355 efx_fill_test(n++, strings, data, &tests->interrupt,
356 "core", 0, "interrupt", NULL);
357
358 /* Event queues */
359 efx_for_each_channel(channel, efx) {
360 efx_fill_test(n++, strings, data,
361 &tests->eventq_dma[channel->channel],
362 EFX_CHANNEL_NAME(channel),
363 "eventq.dma", NULL);
364 efx_fill_test(n++, strings, data,
365 &tests->eventq_int[channel->channel],
366 EFX_CHANNEL_NAME(channel),
367 "eventq.int", NULL);
368 efx_fill_test(n++, strings, data,
369 &tests->eventq_poll[channel->channel],
370 EFX_CHANNEL_NAME(channel),
371 "eventq.poll", NULL);
372 }
373
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100374 efx_fill_test(n++, strings, data, &tests->registers,
375 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800376
377 for (i = 0; i < efx->phy_op->num_tests; i++)
378 efx_fill_test(n++, strings, data, &tests->phy[i],
379 "phy", 0, efx->phy_op->test_names[i], NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100380
381 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100382 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100383 if (!(efx->loopback_modes & (1 << mode)))
384 continue;
385 n = efx_fill_loopback_test(efx,
386 &tests->loopback[mode], mode, n,
387 strings, data);
388 }
389
390 return n;
391}
392
Ben Hutchings3594e132008-09-01 12:48:12 +0100393static int efx_ethtool_get_sset_count(struct net_device *net_dev,
394 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100395{
Ben Hutchings3594e132008-09-01 12:48:12 +0100396 switch (string_set) {
397 case ETH_SS_STATS:
398 return EFX_ETHTOOL_NUM_STATS;
399 case ETH_SS_TEST:
400 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
401 NULL, NULL, NULL);
402 default:
403 return -EINVAL;
404 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100405}
406
Ben Hutchings8ceee662008-04-27 12:55:59 +0100407static void efx_ethtool_get_strings(struct net_device *net_dev,
408 u32 string_set, u8 *strings)
409{
Ben Hutchings767e4682008-09-01 12:43:14 +0100410 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100411 struct ethtool_string *ethtool_strings =
412 (struct ethtool_string *)strings;
413 int i;
414
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100415 switch (string_set) {
416 case ETH_SS_STATS:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100417 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
418 strncpy(ethtool_strings[i].name,
419 efx_ethtool_stats[i].name,
420 sizeof(ethtool_strings[i].name));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100421 break;
422 case ETH_SS_TEST:
423 efx_ethtool_fill_self_tests(efx, NULL,
424 ethtool_strings, NULL);
425 break;
426 default:
427 /* No other string sets */
428 break;
429 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100430}
431
432static void efx_ethtool_get_stats(struct net_device *net_dev,
433 struct ethtool_stats *stats,
434 u64 *data)
435{
Ben Hutchings767e4682008-09-01 12:43:14 +0100436 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437 struct efx_mac_stats *mac_stats = &efx->mac_stats;
438 struct efx_ethtool_stat *stat;
439 struct efx_channel *channel;
440 int i;
441
442 EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
443
444 /* Update MAC and NIC statistics */
Stephen Hemmingereeda3fd2008-11-19 21:40:23 -0800445 dev_get_stats(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100446
447 /* Fill detailed statistics buffer */
448 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
449 stat = &efx_ethtool_stats[i];
450 switch (stat->source) {
451 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
452 data[i] = stat->get_stat((void *)mac_stats +
453 stat->offset);
454 break;
455 case EFX_ETHTOOL_STAT_SOURCE_nic:
456 data[i] = stat->get_stat((void *)efx + stat->offset);
457 break;
458 case EFX_ETHTOOL_STAT_SOURCE_channel:
459 data[i] = 0;
460 efx_for_each_channel(channel, efx)
461 data[i] += stat->get_stat((void *)channel +
462 stat->offset);
463 break;
464 }
465 }
466}
467
Ben Hutchings8ceee662008-04-27 12:55:59 +0100468static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
469{
Ben Hutchings767e4682008-09-01 12:43:14 +0100470 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100471
472 /* No way to stop the hardware doing the checks; we just
473 * ignore the result.
474 */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100475 efx->rx_checksum_enabled = !!enable;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476
477 return 0;
478}
479
480static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
481{
Ben Hutchings767e4682008-09-01 12:43:14 +0100482 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100483
484 return efx->rx_checksum_enabled;
485}
486
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100487static void efx_ethtool_self_test(struct net_device *net_dev,
488 struct ethtool_test *test, u64 *data)
489{
Ben Hutchings767e4682008-09-01 12:43:14 +0100490 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100491 struct efx_self_tests efx_tests;
Ben Hutchings2ef30682008-12-26 13:47:04 -0800492 int already_up;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100493 int rc;
494
495 ASSERT_RTNL();
496 if (efx->state != STATE_RUNNING) {
497 rc = -EIO;
498 goto fail1;
499 }
500
501 /* We need rx buffers and interrupts. */
502 already_up = (efx->net_dev->flags & IFF_UP);
503 if (!already_up) {
504 rc = dev_open(efx->net_dev);
505 if (rc) {
506 EFX_ERR(efx, "failed opening device.\n");
507 goto fail2;
508 }
509 }
510
511 memset(&efx_tests, 0, sizeof(efx_tests));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100512
Ben Hutchings2ef30682008-12-26 13:47:04 -0800513 rc = efx_selftest(efx, &efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100514
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100515 if (!already_up)
516 dev_close(efx->net_dev);
517
Ben Hutchings2ef30682008-12-26 13:47:04 -0800518 EFX_LOG(efx, "%s %sline self-tests\n",
519 rc == 0 ? "passed" : "failed",
520 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100521
522 fail2:
523 fail1:
524 /* Fill ethtool results structures */
525 efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
526 if (rc)
527 test->flags |= ETH_TEST_FL_FAILED;
528}
529
Ben Hutchings8ceee662008-04-27 12:55:59 +0100530/* Restart autonegotiation */
531static int efx_ethtool_nway_reset(struct net_device *net_dev)
532{
Ben Hutchings767e4682008-09-01 12:43:14 +0100533 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100534
Ben Hutchings68e7f452009-04-29 08:05:08 +0000535 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100536}
537
538static u32 efx_ethtool_get_link(struct net_device *net_dev)
539{
Ben Hutchings767e4682008-09-01 12:43:14 +0100540 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100541
542 return efx->link_up;
543}
544
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100545static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
546{
547 struct efx_nic *efx = netdev_priv(net_dev);
548 struct efx_spi_device *spi = efx->spi_eeprom;
549
550 if (!spi)
551 return 0;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000552 return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
553 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100554}
555
556static int efx_ethtool_get_eeprom(struct net_device *net_dev,
557 struct ethtool_eeprom *eeprom, u8 *buf)
558{
559 struct efx_nic *efx = netdev_priv(net_dev);
560 struct efx_spi_device *spi = efx->spi_eeprom;
561 size_t len;
562 int rc;
563
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800564 rc = mutex_lock_interruptible(&efx->spi_lock);
565 if (rc)
566 return rc;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000567 rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100568 eeprom->len, &len, buf);
Ben Hutchingsf4150722008-11-04 20:34:28 +0000569 mutex_unlock(&efx->spi_lock);
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800570
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100571 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
572 eeprom->len = len;
573 return rc;
574}
575
576static int efx_ethtool_set_eeprom(struct net_device *net_dev,
577 struct ethtool_eeprom *eeprom, u8 *buf)
578{
579 struct efx_nic *efx = netdev_priv(net_dev);
580 struct efx_spi_device *spi = efx->spi_eeprom;
581 size_t len;
582 int rc;
583
584 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
585 return -EINVAL;
586
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800587 rc = mutex_lock_interruptible(&efx->spi_lock);
588 if (rc)
589 return rc;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000590 rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100591 eeprom->len, &len, buf);
Ben Hutchingsf4150722008-11-04 20:34:28 +0000592 mutex_unlock(&efx->spi_lock);
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800593
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100594 eeprom->len = len;
595 return rc;
596}
597
Ben Hutchings8ceee662008-04-27 12:55:59 +0100598static int efx_ethtool_get_coalesce(struct net_device *net_dev,
599 struct ethtool_coalesce *coalesce)
600{
Ben Hutchings767e4682008-09-01 12:43:14 +0100601 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100602 struct efx_tx_queue *tx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100603 struct efx_channel *channel;
604
605 memset(coalesce, 0, sizeof(*coalesce));
606
607 /* Find lowest IRQ moderation across all used TX queues */
608 coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
609 efx_for_each_tx_queue(tx_queue, efx) {
610 channel = tx_queue->channel;
611 if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
612 if (channel->used_flags != EFX_USED_BY_RX_TX)
613 coalesce->tx_coalesce_usecs_irq =
614 channel->irq_moderation;
615 else
616 coalesce->tx_coalesce_usecs_irq = 0;
617 }
618 }
619
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000620 coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
621 coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100622
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000623 coalesce->tx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
624 coalesce->rx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
625
Ben Hutchings8ceee662008-04-27 12:55:59 +0100626 return 0;
627}
628
629/* Set coalescing parameters
630 * The difficulties occur for shared channels
631 */
632static int efx_ethtool_set_coalesce(struct net_device *net_dev,
633 struct ethtool_coalesce *coalesce)
634{
Ben Hutchings767e4682008-09-01 12:43:14 +0100635 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100636 struct efx_channel *channel;
637 struct efx_tx_queue *tx_queue;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000638 unsigned tx_usecs, rx_usecs, adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100639
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000640 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100641 return -EOPNOTSUPP;
642
643 if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
644 EFX_ERR(efx, "invalid coalescing setting. "
645 "Only rx/tx_coalesce_usecs_irq are supported\n");
646 return -EOPNOTSUPP;
647 }
648
649 rx_usecs = coalesce->rx_coalesce_usecs_irq;
650 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000651 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100652
653 /* If the channel is shared only allow RX parameters to be set */
654 efx_for_each_tx_queue(tx_queue, efx) {
655 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
656 tx_usecs) {
657 EFX_ERR(efx, "Channel is shared. "
658 "Only RX coalescing may be set\n");
659 return -EOPNOTSUPP;
660 }
661 }
662
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000663 efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100664 efx_for_each_channel(channel, efx)
665 falcon_set_int_moderation(channel);
666
667 return 0;
668}
669
670static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
671 struct ethtool_pauseparam *pause)
672{
Ben Hutchings767e4682008-09-01 12:43:14 +0100673 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800674 enum efx_fc_type wanted_fc;
675 bool reset;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100676
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800677 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
678 (pause->tx_pause ? EFX_FC_TX : 0) |
679 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100680
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800681 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
682 EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
683 return -EINVAL;
684 }
685
Ben Hutchings68e7f452009-04-29 08:05:08 +0000686 if (!(efx->phy_op->mmds & MDIO_DEVS_AN) &&
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800687 (wanted_fc & EFX_FC_AUTO)) {
688 EFX_LOG(efx, "PHY does not support flow control "
689 "autonegotiation\n");
690 return -EINVAL;
691 }
692
693 /* TX flow control may automatically turn itself off if the
694 * link partner (intermittently) stops responding to pause
695 * frames. There isn't any indication that this has happened,
696 * so the best we do is leave it up to the user to spot this
697 * and fix it be cycling transmit flow control on this end. */
698 reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
699 if (EFX_WORKAROUND_11482(efx) && reset) {
700 if (falcon_rev(efx) >= FALCON_REV_B0) {
701 /* Recover by resetting the EM block */
702 if (efx->link_up)
703 falcon_drain_tx_fifo(efx);
704 } else {
705 /* Schedule a reset to recover */
706 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
707 }
708 }
709
710 /* Try to push the pause parameters */
711 mutex_lock(&efx->mac_lock);
712
713 efx->wanted_fc = wanted_fc;
Ben Hutchings3f926da2009-04-29 08:20:37 +0000714 if (efx->phy_op->mmds & MDIO_DEVS_AN)
715 mdio45_ethtool_spauseparam_an(&efx->mdio, pause);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800716 __efx_reconfigure_port(efx);
717
718 mutex_unlock(&efx->mac_lock);
719
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800720 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100721}
722
723static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
724 struct ethtool_pauseparam *pause)
725{
Ben Hutchings767e4682008-09-01 12:43:14 +0100726 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100727
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800728 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
729 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
730 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100731}
732
733
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700734const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100735 .get_settings = efx_ethtool_get_settings,
736 .set_settings = efx_ethtool_set_settings,
737 .get_drvinfo = efx_ethtool_get_drvinfo,
738 .nway_reset = efx_ethtool_nway_reset,
739 .get_link = efx_ethtool_get_link,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100740 .get_eeprom_len = efx_ethtool_get_eeprom_len,
741 .get_eeprom = efx_ethtool_get_eeprom,
742 .set_eeprom = efx_ethtool_set_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100743 .get_coalesce = efx_ethtool_get_coalesce,
744 .set_coalesce = efx_ethtool_set_coalesce,
745 .get_pauseparam = efx_ethtool_get_pauseparam,
746 .set_pauseparam = efx_ethtool_set_pauseparam,
747 .get_rx_csum = efx_ethtool_get_rx_csum,
748 .set_rx_csum = efx_ethtool_set_rx_csum,
749 .get_tx_csum = ethtool_op_get_tx_csum,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100750 .set_tx_csum = ethtool_op_set_tx_csum,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100751 .get_sg = ethtool_op_get_sg,
752 .set_sg = ethtool_op_set_sg,
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100753 .get_tso = ethtool_op_get_tso,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100754 .set_tso = ethtool_op_set_tso,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100755 .get_flags = ethtool_op_get_flags,
756 .set_flags = ethtool_op_set_flags,
Ben Hutchings3594e132008-09-01 12:48:12 +0100757 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100758 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100759 .get_strings = efx_ethtool_get_strings,
760 .phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100761 .get_ethtool_stats = efx_ethtool_get_stats,
762};