blob: aad0d1b36e1c8b16eb59ed355e73100b58bb4fc1 [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>
13#include <linux/rtnetlink.h>
14#include "net_driver.h"
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080015#include "workarounds.h"
Ben Hutchings3273c2e2008-05-07 13:36:19 +010016#include "selftest.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010017#include "efx.h"
18#include "ethtool.h"
19#include "falcon.h"
Ben Hutchings4a5b5042008-09-01 12:47:16 +010020#include "spi.h"
Ben Hutchings04cc8ca2008-12-12 21:50:46 -080021#include "mdio_10g.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010022
Ben Hutchings3273c2e2008-05-07 13:36:19 +010023const char *efx_loopback_mode_names[] = {
24 [LOOPBACK_NONE] = "NONE",
Ben Hutchings177dfcd2008-12-12 21:50:08 -080025 [LOOPBACK_GMAC] = "GMAC",
Ben Hutchings3273c2e2008-05-07 13:36:19 +010026 [LOOPBACK_XGMII] = "XGMII",
27 [LOOPBACK_XGXS] = "XGXS",
28 [LOOPBACK_XAUI] = "XAUI",
Ben Hutchings177dfcd2008-12-12 21:50:08 -080029 [LOOPBACK_GPHY] = "GPHY",
Ben Hutchings740ced92008-12-12 21:41:55 -080030 [LOOPBACK_PHYXS] = "PHYXS",
31 [LOOPBACK_PCS] = "PCS",
32 [LOOPBACK_PMAPMD] = "PMA/PMD",
Ben Hutchings3273c2e2008-05-07 13:36:19 +010033 [LOOPBACK_NETWORK] = "NETWORK",
34};
35
Ben Hutchings8ceee662008-04-27 12:55:59 +010036struct ethtool_string {
37 char name[ETH_GSTRING_LEN];
38};
39
40struct 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 */
49};
50
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, \
61}
62
63static u64 efx_get_uint_stat(void *field)
64{
65 return *(unsigned int *)field;
66}
67
68static u64 efx_get_ulong_stat(void *field)
69{
70 return *(unsigned long *)field;
71}
72
73static u64 efx_get_u64_stat(void *field)
74{
75 return *(u64 *) field;
76}
77
78static u64 efx_get_atomic_stat(void *field)
79{
80 return atomic_read((atomic_t *) field);
81}
82
83#define EFX_ETHTOOL_ULONG_MAC_STAT(field) \
84 EFX_ETHTOOL_STAT(field, mac_stats, field, \
85 unsigned long, efx_get_ulong_stat)
86
87#define EFX_ETHTOOL_U64_MAC_STAT(field) \
88 EFX_ETHTOOL_STAT(field, mac_stats, field, \
89 u64, efx_get_u64_stat)
90
91#define EFX_ETHTOOL_UINT_NIC_STAT(name) \
92 EFX_ETHTOOL_STAT(name, nic, n_##name, \
93 unsigned int, efx_get_uint_stat)
94
95#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
96 EFX_ETHTOOL_STAT(field, nic, field, \
97 atomic_t, efx_get_atomic_stat)
98
99#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
100 EFX_ETHTOOL_STAT(field, channel, n_##field, \
101 unsigned int, efx_get_uint_stat)
102
103static 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),
170};
171
172/* Number of ethtool statistics */
173#define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
174
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100175#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100176
Ben Hutchings8ceee662008-04-27 12:55:59 +0100177/**************************************************************************
178 *
179 * Ethtool operations
180 *
181 **************************************************************************
182 */
183
184/* Identify device by flashing LEDs */
Ben Hutchings65f667f2008-12-12 21:32:10 -0800185static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100186{
Ben Hutchings767e4682008-09-01 12:43:14 +0100187 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188
189 efx->board_info.blink(efx, 1);
Ben Hutchings65f667f2008-12-12 21:32:10 -0800190 set_current_state(TASK_INTERRUPTIBLE);
191 if (count)
192 schedule_timeout(count * HZ);
193 else
194 schedule();
Ben Hutchings8ceee662008-04-27 12:55:59 +0100195 efx->board_info.blink(efx, 0);
196 return 0;
197}
198
199/* This must be called with rtnl_lock held. */
200int efx_ethtool_get_settings(struct net_device *net_dev,
201 struct ethtool_cmd *ecmd)
202{
Ben Hutchings767e4682008-09-01 12:43:14 +0100203 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100204
205 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800206 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100207 mutex_unlock(&efx->mac_lock);
208
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800209 /* Falcon GMAC does not support 1000Mbps HD */
210 ecmd->supported &= ~SUPPORTED_1000baseT_Half;
211
212 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100213}
214
215/* This must be called with rtnl_lock held. */
216int efx_ethtool_set_settings(struct net_device *net_dev,
217 struct ethtool_cmd *ecmd)
218{
Ben Hutchings767e4682008-09-01 12:43:14 +0100219 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100220 int rc;
221
Ben Hutchingse6fa2eb2008-12-12 22:00:17 -0800222 if (EFX_WORKAROUND_13963(efx) && !ecmd->autoneg)
223 return -EINVAL;
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) {
277 snprintf(unit_str.name, sizeof(unit_str.name),
278 unit_format, unit_id);
279 snprintf(test_str.name, sizeof(test_str.name),
280 test_format, test_id);
281 snprintf(strings[test_index].name,
282 sizeof(strings[test_index].name),
Ben Hutchings740ced92008-12-12 21:41:55 -0800283 "%-6s %-24s", unit_str.name, test_str.name);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100284 }
285}
286
287#define EFX_PORT_NAME "port%d", 0
Ben Hutchings740ced92008-12-12 21:41:55 -0800288#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100289#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
290#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
291#define EFX_LOOPBACK_NAME(_mode, _counter) \
292 "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
293
294/**
295 * efx_fill_loopback_test - fill in a block of loopback self-test entries
296 * @efx: Efx NIC
297 * @lb_tests: Efx loopback self-test results structure
298 * @mode: Loopback test mode
299 * @test_index: Starting index of the test
300 * @strings: Ethtool strings, or %NULL
301 * @data: Ethtool test results, or %NULL
302 */
303static int efx_fill_loopback_test(struct efx_nic *efx,
304 struct efx_loopback_self_tests *lb_tests,
305 enum efx_loopback_mode mode,
306 unsigned int test_index,
307 struct ethtool_string *strings, u64 *data)
308{
309 struct efx_tx_queue *tx_queue;
310
311 efx_for_each_tx_queue(tx_queue, efx) {
312 efx_fill_test(test_index++, strings, data,
313 &lb_tests->tx_sent[tx_queue->queue],
314 EFX_TX_QUEUE_NAME(tx_queue),
315 EFX_LOOPBACK_NAME(mode, "tx_sent"));
316 efx_fill_test(test_index++, strings, data,
317 &lb_tests->tx_done[tx_queue->queue],
318 EFX_TX_QUEUE_NAME(tx_queue),
319 EFX_LOOPBACK_NAME(mode, "tx_done"));
320 }
321 efx_fill_test(test_index++, strings, data,
322 &lb_tests->rx_good,
323 EFX_PORT_NAME,
324 EFX_LOOPBACK_NAME(mode, "rx_good"));
325 efx_fill_test(test_index++, strings, data,
326 &lb_tests->rx_bad,
327 EFX_PORT_NAME,
328 EFX_LOOPBACK_NAME(mode, "rx_bad"));
329
330 return test_index;
331}
332
333/**
334 * efx_ethtool_fill_self_tests - get self-test details
335 * @efx: Efx NIC
336 * @tests: Efx self-test results structure, or %NULL
337 * @strings: Ethtool strings, or %NULL
338 * @data: Ethtool test results, or %NULL
339 */
340static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
341 struct efx_self_tests *tests,
342 struct ethtool_string *strings,
343 u64 *data)
344{
345 struct efx_channel *channel;
346 unsigned int n = 0;
347 enum efx_loopback_mode mode;
348
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100349 efx_fill_test(n++, strings, data, &tests->mii,
350 "core", 0, "mii", NULL);
351 efx_fill_test(n++, strings, data, &tests->nvram,
352 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100353 efx_fill_test(n++, strings, data, &tests->interrupt,
354 "core", 0, "interrupt", NULL);
355
356 /* Event queues */
357 efx_for_each_channel(channel, efx) {
358 efx_fill_test(n++, strings, data,
359 &tests->eventq_dma[channel->channel],
360 EFX_CHANNEL_NAME(channel),
361 "eventq.dma", NULL);
362 efx_fill_test(n++, strings, data,
363 &tests->eventq_int[channel->channel],
364 EFX_CHANNEL_NAME(channel),
365 "eventq.int", NULL);
366 efx_fill_test(n++, strings, data,
367 &tests->eventq_poll[channel->channel],
368 EFX_CHANNEL_NAME(channel),
369 "eventq.poll", NULL);
370 }
371
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100372 efx_fill_test(n++, strings, data, &tests->registers,
373 "core", 0, "registers", NULL);
374 efx_fill_test(n++, strings, data, &tests->phy,
375 EFX_PORT_NAME, "phy", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100376
377 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100378 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100379 if (!(efx->loopback_modes & (1 << mode)))
380 continue;
381 n = efx_fill_loopback_test(efx,
382 &tests->loopback[mode], mode, n,
383 strings, data);
384 }
385
386 return n;
387}
388
Ben Hutchings3594e132008-09-01 12:48:12 +0100389static int efx_ethtool_get_sset_count(struct net_device *net_dev,
390 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100391{
Ben Hutchings3594e132008-09-01 12:48:12 +0100392 switch (string_set) {
393 case ETH_SS_STATS:
394 return EFX_ETHTOOL_NUM_STATS;
395 case ETH_SS_TEST:
396 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
397 NULL, NULL, NULL);
398 default:
399 return -EINVAL;
400 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100401}
402
Ben Hutchings8ceee662008-04-27 12:55:59 +0100403static void efx_ethtool_get_strings(struct net_device *net_dev,
404 u32 string_set, u8 *strings)
405{
Ben Hutchings767e4682008-09-01 12:43:14 +0100406 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100407 struct ethtool_string *ethtool_strings =
408 (struct ethtool_string *)strings;
409 int i;
410
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100411 switch (string_set) {
412 case ETH_SS_STATS:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100413 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
414 strncpy(ethtool_strings[i].name,
415 efx_ethtool_stats[i].name,
416 sizeof(ethtool_strings[i].name));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100417 break;
418 case ETH_SS_TEST:
419 efx_ethtool_fill_self_tests(efx, NULL,
420 ethtool_strings, NULL);
421 break;
422 default:
423 /* No other string sets */
424 break;
425 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100426}
427
428static void efx_ethtool_get_stats(struct net_device *net_dev,
429 struct ethtool_stats *stats,
430 u64 *data)
431{
Ben Hutchings767e4682008-09-01 12:43:14 +0100432 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100433 struct efx_mac_stats *mac_stats = &efx->mac_stats;
434 struct efx_ethtool_stat *stat;
435 struct efx_channel *channel;
436 int i;
437
438 EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
439
440 /* Update MAC and NIC statistics */
Stephen Hemmingereeda3fd2008-11-19 21:40:23 -0800441 dev_get_stats(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100442
443 /* Fill detailed statistics buffer */
444 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
445 stat = &efx_ethtool_stats[i];
446 switch (stat->source) {
447 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
448 data[i] = stat->get_stat((void *)mac_stats +
449 stat->offset);
450 break;
451 case EFX_ETHTOOL_STAT_SOURCE_nic:
452 data[i] = stat->get_stat((void *)efx + stat->offset);
453 break;
454 case EFX_ETHTOOL_STAT_SOURCE_channel:
455 data[i] = 0;
456 efx_for_each_channel(channel, efx)
457 data[i] += stat->get_stat((void *)channel +
458 stat->offset);
459 break;
460 }
461 }
462}
463
Ben Hutchings8ceee662008-04-27 12:55:59 +0100464static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
465{
Ben Hutchings767e4682008-09-01 12:43:14 +0100466 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100467
468 /* No way to stop the hardware doing the checks; we just
469 * ignore the result.
470 */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100471 efx->rx_checksum_enabled = !!enable;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100472
473 return 0;
474}
475
476static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
477{
Ben Hutchings767e4682008-09-01 12:43:14 +0100478 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100479
480 return efx->rx_checksum_enabled;
481}
482
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100483static void efx_ethtool_self_test(struct net_device *net_dev,
484 struct ethtool_test *test, u64 *data)
485{
Ben Hutchings767e4682008-09-01 12:43:14 +0100486 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100487 struct efx_self_tests efx_tests;
488 int offline, already_up;
489 int rc;
490
491 ASSERT_RTNL();
492 if (efx->state != STATE_RUNNING) {
493 rc = -EIO;
494 goto fail1;
495 }
496
497 /* We need rx buffers and interrupts. */
498 already_up = (efx->net_dev->flags & IFF_UP);
499 if (!already_up) {
500 rc = dev_open(efx->net_dev);
501 if (rc) {
502 EFX_ERR(efx, "failed opening device.\n");
503 goto fail2;
504 }
505 }
506
507 memset(&efx_tests, 0, sizeof(efx_tests));
508 offline = (test->flags & ETH_TEST_FL_OFFLINE);
509
510 /* Perform online self tests first */
511 rc = efx_online_test(efx, &efx_tests);
512 if (rc)
513 goto out;
514
515 /* Perform offline tests only if online tests passed */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100516 if (offline)
Ben Hutchingsbc3c90a2008-09-01 12:48:46 +0100517 rc = efx_offline_test(efx, &efx_tests,
518 efx->loopback_modes);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100519
520 out:
521 if (!already_up)
522 dev_close(efx->net_dev);
523
524 EFX_LOG(efx, "%s all %sline self-tests\n",
525 rc == 0 ? "passed" : "failed", offline ? "off" : "on");
526
527 fail2:
528 fail1:
529 /* Fill ethtool results structures */
530 efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
531 if (rc)
532 test->flags |= ETH_TEST_FL_FAILED;
533}
534
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535/* Restart autonegotiation */
536static int efx_ethtool_nway_reset(struct net_device *net_dev)
537{
Ben Hutchings767e4682008-09-01 12:43:14 +0100538 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100539
540 return mii_nway_restart(&efx->mii);
541}
542
543static u32 efx_ethtool_get_link(struct net_device *net_dev)
544{
Ben Hutchings767e4682008-09-01 12:43:14 +0100545 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100546
547 return efx->link_up;
548}
549
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100550static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
551{
552 struct efx_nic *efx = netdev_priv(net_dev);
553 struct efx_spi_device *spi = efx->spi_eeprom;
554
555 if (!spi)
556 return 0;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000557 return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
558 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100559}
560
561static int efx_ethtool_get_eeprom(struct net_device *net_dev,
562 struct ethtool_eeprom *eeprom, u8 *buf)
563{
564 struct efx_nic *efx = netdev_priv(net_dev);
565 struct efx_spi_device *spi = efx->spi_eeprom;
566 size_t len;
567 int rc;
568
Ben Hutchingsf4150722008-11-04 20:34:28 +0000569 mutex_lock(&efx->spi_lock);
Ben Hutchings0a95f562008-11-04 20:33:11 +0000570 rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100571 eeprom->len, &len, buf);
Ben Hutchingsf4150722008-11-04 20:34:28 +0000572 mutex_unlock(&efx->spi_lock);
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100573 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
574 eeprom->len = len;
575 return rc;
576}
577
578static int efx_ethtool_set_eeprom(struct net_device *net_dev,
579 struct ethtool_eeprom *eeprom, u8 *buf)
580{
581 struct efx_nic *efx = netdev_priv(net_dev);
582 struct efx_spi_device *spi = efx->spi_eeprom;
583 size_t len;
584 int rc;
585
586 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
587 return -EINVAL;
588
Ben Hutchingsf4150722008-11-04 20:34:28 +0000589 mutex_lock(&efx->spi_lock);
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 Hutchings4a5b5042008-09-01 12:47:16 +0100593 eeprom->len = len;
594 return rc;
595}
596
Ben Hutchings8ceee662008-04-27 12:55:59 +0100597static int efx_ethtool_get_coalesce(struct net_device *net_dev,
598 struct ethtool_coalesce *coalesce)
599{
Ben Hutchings767e4682008-09-01 12:43:14 +0100600 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100601 struct efx_tx_queue *tx_queue;
602 struct efx_rx_queue *rx_queue;
603 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
620 /* Find lowest IRQ moderation across all used RX queues */
621 coalesce->rx_coalesce_usecs_irq = ~((u32) 0);
622 efx_for_each_rx_queue(rx_queue, efx) {
623 channel = rx_queue->channel;
624 if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq)
625 coalesce->rx_coalesce_usecs_irq =
626 channel->irq_moderation;
627 }
628
629 return 0;
630}
631
632/* Set coalescing parameters
633 * The difficulties occur for shared channels
634 */
635static int efx_ethtool_set_coalesce(struct net_device *net_dev,
636 struct ethtool_coalesce *coalesce)
637{
Ben Hutchings767e4682008-09-01 12:43:14 +0100638 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100639 struct efx_channel *channel;
640 struct efx_tx_queue *tx_queue;
641 unsigned tx_usecs, rx_usecs;
642
643 if (coalesce->use_adaptive_rx_coalesce ||
644 coalesce->use_adaptive_tx_coalesce)
645 return -EOPNOTSUPP;
646
647 if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
648 EFX_ERR(efx, "invalid coalescing setting. "
649 "Only rx/tx_coalesce_usecs_irq are supported\n");
650 return -EOPNOTSUPP;
651 }
652
653 rx_usecs = coalesce->rx_coalesce_usecs_irq;
654 tx_usecs = coalesce->tx_coalesce_usecs_irq;
655
656 /* If the channel is shared only allow RX parameters to be set */
657 efx_for_each_tx_queue(tx_queue, efx) {
658 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
659 tx_usecs) {
660 EFX_ERR(efx, "Channel is shared. "
661 "Only RX coalescing may be set\n");
662 return -EOPNOTSUPP;
663 }
664 }
665
666 efx_init_irq_moderation(efx, tx_usecs, rx_usecs);
667
668 /* Reset channel to pick up new moderation value. Note that
669 * this may change the value of the irq_moderation field
670 * (e.g. to allow for hardware timer granularity).
671 */
672 efx_for_each_channel(channel, efx)
673 falcon_set_int_moderation(channel);
674
675 return 0;
676}
677
678static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
679 struct ethtool_pauseparam *pause)
680{
Ben Hutchings767e4682008-09-01 12:43:14 +0100681 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800682 enum efx_fc_type wanted_fc;
683 bool reset;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100684
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800685 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
686 (pause->tx_pause ? EFX_FC_TX : 0) |
687 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100688
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800689 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
690 EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
691 return -EINVAL;
692 }
693
694 if (!(efx->phy_op->mmds & DEV_PRESENT_BIT(MDIO_MMD_AN)) &&
695 (wanted_fc & EFX_FC_AUTO)) {
696 EFX_LOG(efx, "PHY does not support flow control "
697 "autonegotiation\n");
698 return -EINVAL;
699 }
700
701 /* TX flow control may automatically turn itself off if the
702 * link partner (intermittently) stops responding to pause
703 * frames. There isn't any indication that this has happened,
704 * so the best we do is leave it up to the user to spot this
705 * and fix it be cycling transmit flow control on this end. */
706 reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
707 if (EFX_WORKAROUND_11482(efx) && reset) {
708 if (falcon_rev(efx) >= FALCON_REV_B0) {
709 /* Recover by resetting the EM block */
710 if (efx->link_up)
711 falcon_drain_tx_fifo(efx);
712 } else {
713 /* Schedule a reset to recover */
714 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
715 }
716 }
717
718 /* Try to push the pause parameters */
719 mutex_lock(&efx->mac_lock);
720
721 efx->wanted_fc = wanted_fc;
722 mdio_clause45_set_pause(efx);
723 __efx_reconfigure_port(efx);
724
725 mutex_unlock(&efx->mac_lock);
726
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800727 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100728}
729
730static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
731 struct ethtool_pauseparam *pause)
732{
Ben Hutchings767e4682008-09-01 12:43:14 +0100733 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100734
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800735 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
736 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
737 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100738}
739
740
741struct ethtool_ops efx_ethtool_ops = {
742 .get_settings = efx_ethtool_get_settings,
743 .set_settings = efx_ethtool_set_settings,
744 .get_drvinfo = efx_ethtool_get_drvinfo,
745 .nway_reset = efx_ethtool_nway_reset,
746 .get_link = efx_ethtool_get_link,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100747 .get_eeprom_len = efx_ethtool_get_eeprom_len,
748 .get_eeprom = efx_ethtool_get_eeprom,
749 .set_eeprom = efx_ethtool_set_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100750 .get_coalesce = efx_ethtool_get_coalesce,
751 .set_coalesce = efx_ethtool_set_coalesce,
752 .get_pauseparam = efx_ethtool_get_pauseparam,
753 .set_pauseparam = efx_ethtool_set_pauseparam,
754 .get_rx_csum = efx_ethtool_get_rx_csum,
755 .set_rx_csum = efx_ethtool_set_rx_csum,
756 .get_tx_csum = ethtool_op_get_tx_csum,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100757 .set_tx_csum = ethtool_op_set_tx_csum,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100758 .get_sg = ethtool_op_get_sg,
759 .set_sg = ethtool_op_set_sg,
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100760 .get_tso = ethtool_op_get_tso,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100761 .set_tso = ethtool_op_set_tso,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100762 .get_flags = ethtool_op_get_flags,
763 .set_flags = ethtool_op_set_flags,
Ben Hutchings3594e132008-09-01 12:48:12 +0100764 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100765 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100766 .get_strings = efx_ethtool_get_strings,
767 .phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100768 .get_ethtool_stats = efx_ethtool_get_stats,
769};