blob: e8afd784e6b2857057f9417472b0effe0249465d [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"
Ben Hutchings8ceee662008-04-27 12:55:59 +010019#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
Ben Hutchings398468e2009-11-23 16:03:45 +0000189 do {
Ben Hutchings278c0622009-11-23 16:05:12 +0000190 falcon_board(efx)->set_id_led(efx, EFX_LED_ON);
Ben Hutchings398468e2009-11-23 16:03:45 +0000191 schedule_timeout_interruptible(HZ / 2);
192
Ben Hutchings278c0622009-11-23 16:05:12 +0000193 falcon_board(efx)->set_id_led(efx, EFX_LED_OFF);
Ben Hutchings398468e2009-11-23 16:03:45 +0000194 schedule_timeout_interruptible(HZ / 2);
195 } while (!signal_pending(current) && --count != 0);
196
Ben Hutchings278c0622009-11-23 16:05:12 +0000197 falcon_board(efx)->set_id_led(efx, EFX_LED_DEFAULT);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100198 return 0;
199}
200
201/* This must be called with rtnl_lock held. */
202int efx_ethtool_get_settings(struct net_device *net_dev,
203 struct ethtool_cmd *ecmd)
204{
Ben Hutchings767e4682008-09-01 12:43:14 +0100205 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100206
207 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800208 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100209 mutex_unlock(&efx->mac_lock);
210
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800211 /* Falcon GMAC does not support 1000Mbps HD */
212 ecmd->supported &= ~SUPPORTED_1000baseT_Half;
213
214 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100215}
216
217/* This must be called with rtnl_lock held. */
218int efx_ethtool_set_settings(struct net_device *net_dev,
219 struct ethtool_cmd *ecmd)
220{
Ben Hutchings767e4682008-09-01 12:43:14 +0100221 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100222 int rc;
223
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800224 /* Falcon GMAC does not support 1000Mbps HD */
225 if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) {
226 EFX_LOG(efx, "rejecting unsupported 1000Mbps HD"
227 " setting\n");
228 return -EINVAL;
229 }
230
Ben Hutchings8ceee662008-04-27 12:55:59 +0100231 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800232 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100233 mutex_unlock(&efx->mac_lock);
234 if (!rc)
235 efx_reconfigure_port(efx);
236
237 return rc;
238}
239
240static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
241 struct ethtool_drvinfo *info)
242{
Ben Hutchings767e4682008-09-01 12:43:14 +0100243 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100244
245 strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver));
246 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
247 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
248}
249
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100250/**
251 * efx_fill_test - fill in an individual self-test entry
252 * @test_index: Index of the test
253 * @strings: Ethtool strings, or %NULL
254 * @data: Ethtool test results, or %NULL
255 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800256 * @unit_format: Unit name format (e.g. "chan\%d")
257 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100258 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800259 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100260 *
261 * Fill in an individual self-test entry.
262 */
263static void efx_fill_test(unsigned int test_index,
264 struct ethtool_string *strings, u64 *data,
265 int *test, const char *unit_format, int unit_id,
266 const char *test_format, const char *test_id)
267{
268 struct ethtool_string unit_str, test_str;
269
270 /* Fill data value, if applicable */
271 if (data)
272 data[test_index] = *test;
273
274 /* Fill string, if applicable */
275 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800276 if (strchr(unit_format, '%'))
277 snprintf(unit_str.name, sizeof(unit_str.name),
278 unit_format, unit_id);
279 else
280 strcpy(unit_str.name, unit_format);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100281 snprintf(test_str.name, sizeof(test_str.name),
282 test_format, test_id);
283 snprintf(strings[test_index].name,
284 sizeof(strings[test_index].name),
Ben Hutchings740ced92008-12-12 21:41:55 -0800285 "%-6s %-24s", unit_str.name, test_str.name);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100286 }
287}
288
Ben Hutchings740ced92008-12-12 21:41:55 -0800289#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100290#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
291#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
292#define EFX_LOOPBACK_NAME(_mode, _counter) \
293 "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode)
294
295/**
296 * efx_fill_loopback_test - fill in a block of loopback self-test entries
297 * @efx: Efx NIC
298 * @lb_tests: Efx loopback self-test results structure
299 * @mode: Loopback test mode
300 * @test_index: Starting index of the test
301 * @strings: Ethtool strings, or %NULL
302 * @data: Ethtool test results, or %NULL
303 */
304static int efx_fill_loopback_test(struct efx_nic *efx,
305 struct efx_loopback_self_tests *lb_tests,
306 enum efx_loopback_mode mode,
307 unsigned int test_index,
308 struct ethtool_string *strings, u64 *data)
309{
310 struct efx_tx_queue *tx_queue;
311
312 efx_for_each_tx_queue(tx_queue, efx) {
313 efx_fill_test(test_index++, strings, data,
314 &lb_tests->tx_sent[tx_queue->queue],
315 EFX_TX_QUEUE_NAME(tx_queue),
316 EFX_LOOPBACK_NAME(mode, "tx_sent"));
317 efx_fill_test(test_index++, strings, data,
318 &lb_tests->tx_done[tx_queue->queue],
319 EFX_TX_QUEUE_NAME(tx_queue),
320 EFX_LOOPBACK_NAME(mode, "tx_done"));
321 }
322 efx_fill_test(test_index++, strings, data,
323 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800324 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100325 EFX_LOOPBACK_NAME(mode, "rx_good"));
326 efx_fill_test(test_index++, strings, data,
327 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800328 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100329 EFX_LOOPBACK_NAME(mode, "rx_bad"));
330
331 return test_index;
332}
333
334/**
335 * efx_ethtool_fill_self_tests - get self-test details
336 * @efx: Efx NIC
337 * @tests: Efx self-test results structure, or %NULL
338 * @strings: Ethtool strings, or %NULL
339 * @data: Ethtool test results, or %NULL
340 */
341static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
342 struct efx_self_tests *tests,
343 struct ethtool_string *strings,
344 u64 *data)
345{
346 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800347 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100348 enum efx_loopback_mode mode;
349
Ben Hutchings68e7f452009-04-29 08:05:08 +0000350 efx_fill_test(n++, strings, data, &tests->mdio,
351 "core", 0, "mdio", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100352 efx_fill_test(n++, strings, data, &tests->nvram,
353 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100354 efx_fill_test(n++, strings, data, &tests->interrupt,
355 "core", 0, "interrupt", NULL);
356
357 /* Event queues */
358 efx_for_each_channel(channel, efx) {
359 efx_fill_test(n++, strings, data,
360 &tests->eventq_dma[channel->channel],
361 EFX_CHANNEL_NAME(channel),
362 "eventq.dma", NULL);
363 efx_fill_test(n++, strings, data,
364 &tests->eventq_int[channel->channel],
365 EFX_CHANNEL_NAME(channel),
366 "eventq.int", NULL);
367 efx_fill_test(n++, strings, data,
368 &tests->eventq_poll[channel->channel],
369 EFX_CHANNEL_NAME(channel),
370 "eventq.poll", NULL);
371 }
372
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100373 efx_fill_test(n++, strings, data, &tests->registers,
374 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800375
376 for (i = 0; i < efx->phy_op->num_tests; i++)
377 efx_fill_test(n++, strings, data, &tests->phy[i],
378 "phy", 0, efx->phy_op->test_names[i], NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100379
380 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100381 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100382 if (!(efx->loopback_modes & (1 << mode)))
383 continue;
384 n = efx_fill_loopback_test(efx,
385 &tests->loopback[mode], mode, n,
386 strings, data);
387 }
388
389 return n;
390}
391
Ben Hutchings3594e132008-09-01 12:48:12 +0100392static int efx_ethtool_get_sset_count(struct net_device *net_dev,
393 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100394{
Ben Hutchings3594e132008-09-01 12:48:12 +0100395 switch (string_set) {
396 case ETH_SS_STATS:
397 return EFX_ETHTOOL_NUM_STATS;
398 case ETH_SS_TEST:
399 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
400 NULL, NULL, NULL);
401 default:
402 return -EINVAL;
403 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100404}
405
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406static void efx_ethtool_get_strings(struct net_device *net_dev,
407 u32 string_set, u8 *strings)
408{
Ben Hutchings767e4682008-09-01 12:43:14 +0100409 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100410 struct ethtool_string *ethtool_strings =
411 (struct ethtool_string *)strings;
412 int i;
413
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100414 switch (string_set) {
415 case ETH_SS_STATS:
Ben Hutchings8ceee662008-04-27 12:55:59 +0100416 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++)
417 strncpy(ethtool_strings[i].name,
418 efx_ethtool_stats[i].name,
419 sizeof(ethtool_strings[i].name));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100420 break;
421 case ETH_SS_TEST:
422 efx_ethtool_fill_self_tests(efx, NULL,
423 ethtool_strings, NULL);
424 break;
425 default:
426 /* No other string sets */
427 break;
428 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100429}
430
431static void efx_ethtool_get_stats(struct net_device *net_dev,
432 struct ethtool_stats *stats,
433 u64 *data)
434{
Ben Hutchings767e4682008-09-01 12:43:14 +0100435 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436 struct efx_mac_stats *mac_stats = &efx->mac_stats;
437 struct efx_ethtool_stat *stat;
438 struct efx_channel *channel;
439 int i;
440
441 EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS);
442
443 /* Update MAC and NIC statistics */
Stephen Hemmingereeda3fd2008-11-19 21:40:23 -0800444 dev_get_stats(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100445
446 /* Fill detailed statistics buffer */
447 for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) {
448 stat = &efx_ethtool_stats[i];
449 switch (stat->source) {
450 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
451 data[i] = stat->get_stat((void *)mac_stats +
452 stat->offset);
453 break;
454 case EFX_ETHTOOL_STAT_SOURCE_nic:
455 data[i] = stat->get_stat((void *)efx + stat->offset);
456 break;
457 case EFX_ETHTOOL_STAT_SOURCE_channel:
458 data[i] = 0;
459 efx_for_each_channel(channel, efx)
460 data[i] += stat->get_stat((void *)channel +
461 stat->offset);
462 break;
463 }
464 }
465}
466
Ben Hutchings8ceee662008-04-27 12:55:59 +0100467static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable)
468{
Ben Hutchings767e4682008-09-01 12:43:14 +0100469 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100470
471 /* No way to stop the hardware doing the checks; we just
472 * ignore the result.
473 */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100474 efx->rx_checksum_enabled = !!enable;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100475
476 return 0;
477}
478
479static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev)
480{
Ben Hutchings767e4682008-09-01 12:43:14 +0100481 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100482
483 return efx->rx_checksum_enabled;
484}
485
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100486static void efx_ethtool_self_test(struct net_device *net_dev,
487 struct ethtool_test *test, u64 *data)
488{
Ben Hutchings767e4682008-09-01 12:43:14 +0100489 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100490 struct efx_self_tests efx_tests;
Ben Hutchings2ef30682008-12-26 13:47:04 -0800491 int already_up;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100492 int rc;
493
494 ASSERT_RTNL();
495 if (efx->state != STATE_RUNNING) {
496 rc = -EIO;
497 goto fail1;
498 }
499
500 /* We need rx buffers and interrupts. */
501 already_up = (efx->net_dev->flags & IFF_UP);
502 if (!already_up) {
503 rc = dev_open(efx->net_dev);
504 if (rc) {
505 EFX_ERR(efx, "failed opening device.\n");
506 goto fail2;
507 }
508 }
509
510 memset(&efx_tests, 0, sizeof(efx_tests));
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100511
Ben Hutchings2ef30682008-12-26 13:47:04 -0800512 rc = efx_selftest(efx, &efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100513
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100514 if (!already_up)
515 dev_close(efx->net_dev);
516
Ben Hutchings2ef30682008-12-26 13:47:04 -0800517 EFX_LOG(efx, "%s %sline self-tests\n",
518 rc == 0 ? "passed" : "failed",
519 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100520
521 fail2:
522 fail1:
523 /* Fill ethtool results structures */
524 efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data);
525 if (rc)
526 test->flags |= ETH_TEST_FL_FAILED;
527}
528
Ben Hutchings8ceee662008-04-27 12:55:59 +0100529/* Restart autonegotiation */
530static int efx_ethtool_nway_reset(struct net_device *net_dev)
531{
Ben Hutchings767e4682008-09-01 12:43:14 +0100532 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100533
Ben Hutchings68e7f452009-04-29 08:05:08 +0000534 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535}
536
537static u32 efx_ethtool_get_link(struct net_device *net_dev)
538{
Ben Hutchings767e4682008-09-01 12:43:14 +0100539 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100540
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000541 return efx->link_state.up;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100542}
543
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100544static int efx_ethtool_get_eeprom_len(struct net_device *net_dev)
545{
546 struct efx_nic *efx = netdev_priv(net_dev);
547 struct efx_spi_device *spi = efx->spi_eeprom;
548
549 if (!spi)
550 return 0;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000551 return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) -
552 min(spi->size, EFX_EEPROM_BOOTCONFIG_START);
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100553}
554
555static int efx_ethtool_get_eeprom(struct net_device *net_dev,
556 struct ethtool_eeprom *eeprom, u8 *buf)
557{
558 struct efx_nic *efx = netdev_priv(net_dev);
559 struct efx_spi_device *spi = efx->spi_eeprom;
560 size_t len;
561 int rc;
562
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800563 rc = mutex_lock_interruptible(&efx->spi_lock);
564 if (rc)
565 return rc;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000566 rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100567 eeprom->len, &len, buf);
Ben Hutchingsf4150722008-11-04 20:34:28 +0000568 mutex_unlock(&efx->spi_lock);
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800569
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100570 eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC;
571 eeprom->len = len;
572 return rc;
573}
574
575static int efx_ethtool_set_eeprom(struct net_device *net_dev,
576 struct ethtool_eeprom *eeprom, u8 *buf)
577{
578 struct efx_nic *efx = netdev_priv(net_dev);
579 struct efx_spi_device *spi = efx->spi_eeprom;
580 size_t len;
581 int rc;
582
583 if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC)
584 return -EINVAL;
585
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800586 rc = mutex_lock_interruptible(&efx->spi_lock);
587 if (rc)
588 return rc;
Ben Hutchings0a95f562008-11-04 20:33:11 +0000589 rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100590 eeprom->len, &len, buf);
Ben Hutchingsf4150722008-11-04 20:34:28 +0000591 mutex_unlock(&efx->spi_lock);
Ben Hutchingsca54a9f2008-12-12 22:06:24 -0800592
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;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100602 struct efx_channel *channel;
603
604 memset(coalesce, 0, sizeof(*coalesce));
605
606 /* Find lowest IRQ moderation across all used TX queues */
607 coalesce->tx_coalesce_usecs_irq = ~((u32) 0);
608 efx_for_each_tx_queue(tx_queue, efx) {
609 channel = tx_queue->channel;
610 if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) {
611 if (channel->used_flags != EFX_USED_BY_RX_TX)
612 coalesce->tx_coalesce_usecs_irq =
613 channel->irq_moderation;
614 else
615 coalesce->tx_coalesce_usecs_irq = 0;
616 }
617 }
618
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000619 coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive;
620 coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100621
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000622 coalesce->tx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
623 coalesce->rx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION;
624
Ben Hutchings8ceee662008-04-27 12:55:59 +0100625 return 0;
626}
627
628/* Set coalescing parameters
629 * The difficulties occur for shared channels
630 */
631static int efx_ethtool_set_coalesce(struct net_device *net_dev,
632 struct ethtool_coalesce *coalesce)
633{
Ben Hutchings767e4682008-09-01 12:43:14 +0100634 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100635 struct efx_channel *channel;
636 struct efx_tx_queue *tx_queue;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000637 unsigned tx_usecs, rx_usecs, adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100638
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000639 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100640 return -EOPNOTSUPP;
641
642 if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) {
643 EFX_ERR(efx, "invalid coalescing setting. "
644 "Only rx/tx_coalesce_usecs_irq are supported\n");
645 return -EOPNOTSUPP;
646 }
647
648 rx_usecs = coalesce->rx_coalesce_usecs_irq;
649 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000650 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100651
652 /* If the channel is shared only allow RX parameters to be set */
653 efx_for_each_tx_queue(tx_queue, efx) {
654 if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) &&
655 tx_usecs) {
656 EFX_ERR(efx, "Channel is shared. "
657 "Only RX coalescing may be set\n");
658 return -EOPNOTSUPP;
659 }
660 }
661
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000662 efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100663 efx_for_each_channel(channel, efx)
664 falcon_set_int_moderation(channel);
665
666 return 0;
667}
668
669static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
670 struct ethtool_pauseparam *pause)
671{
Ben Hutchings767e4682008-09-01 12:43:14 +0100672 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800673 enum efx_fc_type wanted_fc;
674 bool reset;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100675
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800676 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
677 (pause->tx_pause ? EFX_FC_TX : 0) |
678 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100679
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800680 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
681 EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n");
682 return -EINVAL;
683 }
684
Ben Hutchings68e7f452009-04-29 08:05:08 +0000685 if (!(efx->phy_op->mmds & MDIO_DEVS_AN) &&
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800686 (wanted_fc & EFX_FC_AUTO)) {
687 EFX_LOG(efx, "PHY does not support flow control "
688 "autonegotiation\n");
689 return -EINVAL;
690 }
691
692 /* TX flow control may automatically turn itself off if the
693 * link partner (intermittently) stops responding to pause
694 * frames. There isn't any indication that this has happened,
695 * so the best we do is leave it up to the user to spot this
696 * and fix it be cycling transmit flow control on this end. */
697 reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX);
698 if (EFX_WORKAROUND_11482(efx) && reset) {
699 if (falcon_rev(efx) >= FALCON_REV_B0) {
700 /* Recover by resetting the EM block */
Ben Hutchingseb50c0d2009-11-23 16:06:30 +0000701 if (efx->link_state.up)
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800702 falcon_drain_tx_fifo(efx);
703 } else {
704 /* Schedule a reset to recover */
705 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
706 }
707 }
708
709 /* Try to push the pause parameters */
710 mutex_lock(&efx->mac_lock);
711
712 efx->wanted_fc = wanted_fc;
Ben Hutchings3f926da2009-04-29 08:20:37 +0000713 if (efx->phy_op->mmds & MDIO_DEVS_AN)
714 mdio45_ethtool_spauseparam_an(&efx->mdio, pause);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800715 __efx_reconfigure_port(efx);
716
717 mutex_unlock(&efx->mac_lock);
718
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800719 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100720}
721
722static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
723 struct ethtool_pauseparam *pause)
724{
Ben Hutchings767e4682008-09-01 12:43:14 +0100725 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100726
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800727 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
728 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
729 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100730}
731
732
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700733const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100734 .get_settings = efx_ethtool_get_settings,
735 .set_settings = efx_ethtool_set_settings,
736 .get_drvinfo = efx_ethtool_get_drvinfo,
737 .nway_reset = efx_ethtool_nway_reset,
738 .get_link = efx_ethtool_get_link,
Ben Hutchings4a5b5042008-09-01 12:47:16 +0100739 .get_eeprom_len = efx_ethtool_get_eeprom_len,
740 .get_eeprom = efx_ethtool_get_eeprom,
741 .set_eeprom = efx_ethtool_set_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100742 .get_coalesce = efx_ethtool_get_coalesce,
743 .set_coalesce = efx_ethtool_set_coalesce,
744 .get_pauseparam = efx_ethtool_get_pauseparam,
745 .set_pauseparam = efx_ethtool_set_pauseparam,
746 .get_rx_csum = efx_ethtool_get_rx_csum,
747 .set_rx_csum = efx_ethtool_set_rx_csum,
748 .get_tx_csum = ethtool_op_get_tx_csum,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100749 .set_tx_csum = ethtool_op_set_tx_csum,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100750 .get_sg = ethtool_op_get_sg,
751 .set_sg = ethtool_op_set_sg,
Ben Hutchingsb9b39b62008-05-07 12:51:12 +0100752 .get_tso = ethtool_op_get_tso,
Ben Hutchings60ac1062008-09-01 12:44:59 +0100753 .set_tso = ethtool_op_set_tso,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100754 .get_flags = ethtool_op_get_flags,
755 .set_flags = ethtool_op_set_flags,
Ben Hutchings3594e132008-09-01 12:48:12 +0100756 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100757 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100758 .get_strings = efx_ethtool_get_strings,
759 .phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100760 .get_ethtool_stats = efx_ethtool_get_stats,
761};