blob: 63546930f954367af2fb6563f45de618f1cbae90 [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.
Ben Hutchings0a6f40c2011-02-25 00:01:34 +00004 * Copyright 2006-2010 Solarflare Communications Inc.
Ben Hutchings8ceee662008-04-27 12:55:59 +01005 *
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>
Ben Hutchingsc39d35e2010-12-07 19:11:26 +000014#include <linux/in.h>
Ben Hutchings8ceee662008-04-27 12:55:59 +010015#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 Hutchingsb4187e42010-09-20 08:43:42 +000019#include "filter.h"
Ben Hutchings744093c2009-11-29 15:12:08 +000020#include "nic.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010021
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000022struct efx_sw_stat_desc {
Ben Hutchings8ceee662008-04-27 12:55:59 +010023 const char *name;
24 enum {
Ben Hutchings8ceee662008-04-27 12:55:59 +010025 EFX_ETHTOOL_STAT_SOURCE_nic,
Ben Hutchings119226c2011-02-18 19:14:13 +000026 EFX_ETHTOOL_STAT_SOURCE_channel,
27 EFX_ETHTOOL_STAT_SOURCE_tx_queue
Ben Hutchings8ceee662008-04-27 12:55:59 +010028 } source;
29 unsigned offset;
30 u64(*get_stat) (void *field); /* Reader function */
31};
32
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000033/* Initialiser for a struct efx_sw_stat_desc with type-checking */
Ben Hutchings8ceee662008-04-27 12:55:59 +010034#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
35 get_stat_function) { \
36 .name = #stat_name, \
37 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
38 .offset = ((((field_type *) 0) == \
39 &((struct efx_##source_name *)0)->field) ? \
40 offsetof(struct efx_##source_name, field) : \
41 offsetof(struct efx_##source_name, field)), \
42 .get_stat = get_stat_function, \
43}
44
45static u64 efx_get_uint_stat(void *field)
46{
47 return *(unsigned int *)field;
48}
49
Ben Hutchings8ceee662008-04-27 12:55:59 +010050static u64 efx_get_atomic_stat(void *field)
51{
52 return atomic_read((atomic_t *) field);
53}
54
Ben Hutchings8ceee662008-04-27 12:55:59 +010055#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
56 EFX_ETHTOOL_STAT(field, nic, field, \
57 atomic_t, efx_get_atomic_stat)
58
59#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
60 EFX_ETHTOOL_STAT(field, channel, n_##field, \
61 unsigned int, efx_get_uint_stat)
62
Ben Hutchings119226c2011-02-18 19:14:13 +000063#define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
64 EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
65 unsigned int, efx_get_uint_stat)
66
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000067static const struct efx_sw_stat_desc efx_sw_stat_desc[] = {
Ben Hutchings02e12162013-04-27 01:55:21 +010068 EFX_ETHTOOL_UINT_TXQ_STAT(merge_events),
Ben Hutchings119226c2011-02-18 19:14:13 +000069 EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
70 EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
71 EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
72 EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
Ben Hutchings8ceee662008-04-27 12:55:59 +010073 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
74 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
75 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
76 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
Ben Hutchingsc1ac4032009-11-28 05:36:29 +000077 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
Ben Hutchings8ceee662008-04-27 12:55:59 +010078 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
Ben Hutchings85740cdf2013-01-29 23:33:15 +000079 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc),
Ben Hutchings8ceee662008-04-27 12:55:59 +010080};
81
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000082#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
Ben Hutchings8ceee662008-04-27 12:55:59 +010083
Ben Hutchings4a5b5042008-09-01 12:47:16 +010084#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +010085
Ben Hutchings8ceee662008-04-27 12:55:59 +010086/**************************************************************************
87 *
88 * Ethtool operations
89 *
90 **************************************************************************
91 */
92
93/* Identify device by flashing LEDs */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +010094static int efx_ethtool_phys_id(struct net_device *net_dev,
95 enum ethtool_phys_id_state state)
Ben Hutchings8ceee662008-04-27 12:55:59 +010096{
Ben Hutchings767e4682008-09-01 12:43:14 +010097 struct efx_nic *efx = netdev_priv(net_dev);
Allan, Bruce Wfce55922011-04-13 13:09:10 +000098 enum efx_led_mode mode = EFX_LED_DEFAULT;
Ben Hutchings8ceee662008-04-27 12:55:59 +010099
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100100 switch (state) {
101 case ETHTOOL_ID_ON:
102 mode = EFX_LED_ON;
103 break;
104 case ETHTOOL_ID_OFF:
105 mode = EFX_LED_OFF;
106 break;
107 case ETHTOOL_ID_INACTIVE:
108 mode = EFX_LED_DEFAULT;
109 break;
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000110 case ETHTOOL_ID_ACTIVE:
111 return 1; /* cycle on/off once per second */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100112 }
Ben Hutchings398468e2009-11-23 16:03:45 +0000113
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100114 efx->type->set_id_led(efx, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100115 return 0;
116}
117
118/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000119static int efx_ethtool_get_settings(struct net_device *net_dev,
120 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100121{
Ben Hutchings767e4682008-09-01 12:43:14 +0100122 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000123 struct efx_link_state *link_state = &efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100124
125 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800126 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100127 mutex_unlock(&efx->mac_lock);
128
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000129 /* Both MACs support pause frames (bidirectional and respond-only) */
130 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
131
132 if (LOOPBACK_INTERNAL(efx)) {
David Decotigny70739492011-04-27 18:32:40 +0000133 ethtool_cmd_speed_set(ecmd, link_state->speed);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000134 ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
135 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800136
137 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138}
139
140/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000141static int efx_ethtool_set_settings(struct net_device *net_dev,
142 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100143{
Ben Hutchings767e4682008-09-01 12:43:14 +0100144 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100145 int rc;
146
Ben Hutchings754c6532010-02-03 09:31:57 +0000147 /* GMAC does not support 1000Mbps HD */
David Decotigny25db0332011-04-27 18:32:39 +0000148 if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
149 (ecmd->duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000150 netif_dbg(efx, drv, efx->net_dev,
151 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800152 return -EINVAL;
153 }
154
Ben Hutchings8ceee662008-04-27 12:55:59 +0100155 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800156 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100157 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100158 return rc;
159}
160
161static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
162 struct ethtool_drvinfo *info)
163{
Ben Hutchings767e4682008-09-01 12:43:14 +0100164 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100165
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000166 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100167 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000168 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
Ben Hutchingse5f0fd22011-02-24 23:57:47 +0000169 efx_mcdi_print_fwver(efx, info->fw_version,
170 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
172}
173
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000174static int efx_ethtool_get_regs_len(struct net_device *net_dev)
175{
176 return efx_nic_get_regs_len(netdev_priv(net_dev));
177}
178
179static void efx_ethtool_get_regs(struct net_device *net_dev,
180 struct ethtool_regs *regs, void *buf)
181{
182 struct efx_nic *efx = netdev_priv(net_dev);
183
184 regs->version = efx->type->revision;
185 efx_nic_get_regs(efx, buf);
186}
187
Ben Hutchings62776d02010-06-23 11:30:07 +0000188static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
189{
190 struct efx_nic *efx = netdev_priv(net_dev);
191 return efx->msg_enable;
192}
193
194static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
195{
196 struct efx_nic *efx = netdev_priv(net_dev);
197 efx->msg_enable = msg_enable;
198}
199
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100200/**
201 * efx_fill_test - fill in an individual self-test entry
202 * @test_index: Index of the test
203 * @strings: Ethtool strings, or %NULL
204 * @data: Ethtool test results, or %NULL
205 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800206 * @unit_format: Unit name format (e.g. "chan\%d")
207 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100208 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800209 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100210 *
211 * Fill in an individual self-test entry.
212 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000213static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100214 int *test, const char *unit_format, int unit_id,
215 const char *test_format, const char *test_id)
216{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000217 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100218
219 /* Fill data value, if applicable */
220 if (data)
221 data[test_index] = *test;
222
223 /* Fill string, if applicable */
224 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800225 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000226 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800227 unit_format, unit_id);
228 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000229 strcpy(unit_str, unit_format);
230 snprintf(test_str, sizeof(test_str), test_format, test_id);
231 snprintf(strings + test_index * ETH_GSTRING_LEN,
232 ETH_GSTRING_LEN,
233 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100234 }
235}
236
Ben Hutchings740ced92008-12-12 21:41:55 -0800237#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100238#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
239#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
240#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000241 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100242
243/**
244 * efx_fill_loopback_test - fill in a block of loopback self-test entries
245 * @efx: Efx NIC
246 * @lb_tests: Efx loopback self-test results structure
247 * @mode: Loopback test mode
248 * @test_index: Starting index of the test
249 * @strings: Ethtool strings, or %NULL
250 * @data: Ethtool test results, or %NULL
251 */
252static int efx_fill_loopback_test(struct efx_nic *efx,
253 struct efx_loopback_self_tests *lb_tests,
254 enum efx_loopback_mode mode,
255 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000256 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100257{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100258 struct efx_channel *channel =
259 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100260 struct efx_tx_queue *tx_queue;
261
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000262 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100263 efx_fill_test(test_index++, strings, data,
264 &lb_tests->tx_sent[tx_queue->queue],
265 EFX_TX_QUEUE_NAME(tx_queue),
266 EFX_LOOPBACK_NAME(mode, "tx_sent"));
267 efx_fill_test(test_index++, strings, data,
268 &lb_tests->tx_done[tx_queue->queue],
269 EFX_TX_QUEUE_NAME(tx_queue),
270 EFX_LOOPBACK_NAME(mode, "tx_done"));
271 }
272 efx_fill_test(test_index++, strings, data,
273 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800274 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100275 EFX_LOOPBACK_NAME(mode, "rx_good"));
276 efx_fill_test(test_index++, strings, data,
277 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800278 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100279 EFX_LOOPBACK_NAME(mode, "rx_bad"));
280
281 return test_index;
282}
283
284/**
285 * efx_ethtool_fill_self_tests - get self-test details
286 * @efx: Efx NIC
287 * @tests: Efx self-test results structure, or %NULL
288 * @strings: Ethtool strings, or %NULL
289 * @data: Ethtool test results, or %NULL
290 */
291static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
292 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000293 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100294{
295 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800296 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100297 enum efx_loopback_mode mode;
298
Ben Hutchings4f16c072010-02-03 09:30:50 +0000299 efx_fill_test(n++, strings, data, &tests->phy_alive,
300 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100301 efx_fill_test(n++, strings, data, &tests->nvram,
302 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100303 efx_fill_test(n++, strings, data, &tests->interrupt,
304 "core", 0, "interrupt", NULL);
305
306 /* Event queues */
307 efx_for_each_channel(channel, efx) {
308 efx_fill_test(n++, strings, data,
309 &tests->eventq_dma[channel->channel],
310 EFX_CHANNEL_NAME(channel),
311 "eventq.dma", NULL);
312 efx_fill_test(n++, strings, data,
313 &tests->eventq_int[channel->channel],
314 EFX_CHANNEL_NAME(channel),
315 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100316 }
317
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100318 efx_fill_test(n++, strings, data, &tests->registers,
319 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800320
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000321 if (efx->phy_op->run_tests != NULL) {
322 EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
323
324 for (i = 0; true; ++i) {
325 const char *name;
326
327 EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
328 name = efx->phy_op->test_name(efx, i);
329 if (name == NULL)
330 break;
331
Ben Hutchings4f16c072010-02-03 09:30:50 +0000332 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000333 "phy", 0, name, NULL);
334 }
335 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100336
337 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100338 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100339 if (!(efx->loopback_modes & (1 << mode)))
340 continue;
341 n = efx_fill_loopback_test(efx,
342 &tests->loopback[mode], mode, n,
343 strings, data);
344 }
345
346 return n;
347}
348
Ben Hutchings3594e132008-09-01 12:48:12 +0100349static int efx_ethtool_get_sset_count(struct net_device *net_dev,
350 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100351{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000352 struct efx_nic *efx = netdev_priv(net_dev);
353
Ben Hutchings3594e132008-09-01 12:48:12 +0100354 switch (string_set) {
355 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000356 return efx->type->describe_stats(efx, NULL) +
357 EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings3594e132008-09-01 12:48:12 +0100358 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000359 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100360 default:
361 return -EINVAL;
362 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100363}
364
Ben Hutchings8ceee662008-04-27 12:55:59 +0100365static void efx_ethtool_get_strings(struct net_device *net_dev,
366 u32 string_set, u8 *strings)
367{
Ben Hutchings767e4682008-09-01 12:43:14 +0100368 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100369 int i;
370
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100371 switch (string_set) {
372 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000373 strings += (efx->type->describe_stats(efx, strings) *
374 ETH_GSTRING_LEN);
375 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000376 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000377 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100378 break;
379 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000380 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100381 break;
382 default:
383 /* No other string sets */
384 break;
385 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100386}
387
388static void efx_ethtool_get_stats(struct net_device *net_dev,
389 struct ethtool_stats *stats,
390 u64 *data)
391{
Ben Hutchings767e4682008-09-01 12:43:14 +0100392 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000393 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100394 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000395 struct efx_tx_queue *tx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100396 int i;
397
Ben Hutchings1cb34522011-09-02 23:23:00 +0100398 spin_lock_bh(&efx->stats_lock);
399
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000400 /* Get NIC statistics */
401 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100402
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000403 /* Get software statistics */
404 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
405 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100407 case EFX_ETHTOOL_STAT_SOURCE_nic:
408 data[i] = stat->get_stat((void *)efx + stat->offset);
409 break;
410 case EFX_ETHTOOL_STAT_SOURCE_channel:
411 data[i] = 0;
412 efx_for_each_channel(channel, efx)
413 data[i] += stat->get_stat((void *)channel +
414 stat->offset);
415 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000416 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
417 data[i] = 0;
418 efx_for_each_channel(channel, efx) {
419 efx_for_each_channel_tx_queue(tx_queue, channel)
420 data[i] +=
421 stat->get_stat((void *)tx_queue
422 + stat->offset);
423 }
424 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100425 }
426 }
Ben Hutchings1cb34522011-09-02 23:23:00 +0100427
428 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100429}
430
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100431static void efx_ethtool_self_test(struct net_device *net_dev,
432 struct ethtool_test *test, u64 *data)
433{
Ben Hutchings767e4682008-09-01 12:43:14 +0100434 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000435 struct efx_self_tests *efx_tests;
Ben Hutchings2ef30682008-12-26 13:47:04 -0800436 int already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000437 int rc = -ENOMEM;
438
439 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
440 if (!efx_tests)
441 goto fail;
442
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100443 if (efx->state != STATE_READY) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100444 rc = -EIO;
445 goto fail1;
446 }
447
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000448 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
449 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
450
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100451 /* We need rx buffers and interrupts. */
452 already_up = (efx->net_dev->flags & IFF_UP);
453 if (!already_up) {
454 rc = dev_open(efx->net_dev);
455 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000456 netif_err(efx, drv, efx->net_dev,
457 "failed opening device.\n");
Eric Dumazet28801f32011-02-16 03:48:38 +0000458 goto fail1;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100459 }
460 }
461
Eric Dumazet28801f32011-02-16 03:48:38 +0000462 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100463
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100464 if (!already_up)
465 dev_close(efx->net_dev);
466
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000467 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
468 rc == 0 ? "passed" : "failed",
469 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100470
Eric Dumazet28801f32011-02-16 03:48:38 +0000471fail1:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100472 /* Fill ethtool results structures */
Eric Dumazet28801f32011-02-16 03:48:38 +0000473 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
474 kfree(efx_tests);
475fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100476 if (rc)
477 test->flags |= ETH_TEST_FL_FAILED;
478}
479
Ben Hutchings8ceee662008-04-27 12:55:59 +0100480/* Restart autonegotiation */
481static int efx_ethtool_nway_reset(struct net_device *net_dev)
482{
Ben Hutchings767e4682008-09-01 12:43:14 +0100483 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100484
Ben Hutchings68e7f452009-04-29 08:05:08 +0000485 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100486}
487
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000488/*
489 * Each channel has a single IRQ and moderation timer, started by any
490 * completion (or other event). Unless the module parameter
491 * separate_tx_channels is set, IRQs and moderation are therefore
492 * shared between RX and TX completions. In this case, when RX IRQ
493 * moderation is explicitly changed then TX IRQ moderation is
494 * automatically changed too, but otherwise we fail if the two values
495 * are requested to be different.
496 *
Ben Hutchings13225972011-09-05 07:43:49 +0000497 * The hardware does not support a limit on the number of completions
498 * before an IRQ, so we do not use the max_frames fields. We should
499 * report and require that max_frames == (usecs != 0), but this would
500 * invalidate existing user documentation.
501 *
502 * The hardware does not have distinct settings for interrupt
503 * moderation while the previous IRQ is being handled, so we should
504 * not use the 'irq' fields. However, an earlier developer
505 * misunderstood the meaning of the 'irq' fields and the driver did
506 * not support the standard fields. To avoid invalidating existing
507 * user documentation, we report and accept changes through either the
508 * standard or 'irq' fields. If both are changed at the same time, we
509 * prefer the standard field.
510 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000511 * We implement adaptive IRQ moderation, but use a different algorithm
512 * from that assumed in the definition of struct ethtool_coalesce.
513 * Therefore we do not use any of the adaptive moderation parameters
514 * in it.
515 */
516
Ben Hutchings8ceee662008-04-27 12:55:59 +0100517static int efx_ethtool_get_coalesce(struct net_device *net_dev,
518 struct ethtool_coalesce *coalesce)
519{
Ben Hutchings767e4682008-09-01 12:43:14 +0100520 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000521 unsigned int tx_usecs, rx_usecs;
522 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100523
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000524 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100525
Ben Hutchings13225972011-09-05 07:43:49 +0000526 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000527 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000528 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000529 coalesce->rx_coalesce_usecs_irq = rx_usecs;
530 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000531
Ben Hutchings8ceee662008-04-27 12:55:59 +0100532 return 0;
533}
534
Ben Hutchings8ceee662008-04-27 12:55:59 +0100535static int efx_ethtool_set_coalesce(struct net_device *net_dev,
536 struct ethtool_coalesce *coalesce)
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 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000540 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000541 bool adaptive, rx_may_override_tx;
542 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100543
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000544 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000545 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100546
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000547 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
548
Ben Hutchings13225972011-09-05 07:43:49 +0000549 if (coalesce->rx_coalesce_usecs != rx_usecs)
550 rx_usecs = coalesce->rx_coalesce_usecs;
551 else
552 rx_usecs = coalesce->rx_coalesce_usecs_irq;
553
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000554 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100555
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000556 /* If channels are shared, TX IRQ moderation can be quietly
557 * overridden unless it is changed from its old value.
558 */
Ben Hutchings13225972011-09-05 07:43:49 +0000559 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
560 coalesce->tx_coalesce_usecs_irq == tx_usecs);
561 if (coalesce->tx_coalesce_usecs != tx_usecs)
562 tx_usecs = coalesce->tx_coalesce_usecs;
563 else
564 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100565
Ben Hutchings9e393b32011-09-05 07:43:04 +0000566 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
567 rx_may_override_tx);
568 if (rc != 0)
569 return rc;
570
Ben Hutchings8ceee662008-04-27 12:55:59 +0100571 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000572 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100573
574 return 0;
575}
576
Ben Hutchings46426102010-09-10 06:42:33 +0000577static void efx_ethtool_get_ringparam(struct net_device *net_dev,
578 struct ethtool_ringparam *ring)
579{
580 struct efx_nic *efx = netdev_priv(net_dev);
581
582 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
583 ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchings46426102010-09-10 06:42:33 +0000584 ring->rx_pending = efx->rxq_entries;
585 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000586}
587
588static int efx_ethtool_set_ringparam(struct net_device *net_dev,
589 struct ethtool_ringparam *ring)
590{
591 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000592 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000593
594 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
595 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
596 ring->tx_pending > EFX_MAX_DMAQ_SIZE)
597 return -EINVAL;
598
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000599 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000600 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000601 "RX queues cannot be smaller than %u\n",
602 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000603 return -EINVAL;
604 }
605
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000606 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
607 if (txq_entries != ring->tx_pending)
608 netif_warn(efx, drv, efx->net_dev,
609 "increasing TX queue size to minimum of %u\n",
610 txq_entries);
611
612 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000613}
614
Ben Hutchings8ceee662008-04-27 12:55:59 +0100615static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
616 struct ethtool_pauseparam *pause)
617{
Ben Hutchings767e4682008-09-01 12:43:14 +0100618 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb5626942011-05-17 17:53:22 -0400619 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000620 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000621 int rc = 0;
622
623 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100624
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800625 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
626 (pause->tx_pause ? EFX_FC_TX : 0) |
627 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100628
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800629 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000630 netif_dbg(efx, drv, efx->net_dev,
631 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000632 rc = -EINVAL;
633 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800634 }
635
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000636 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000637 netif_dbg(efx, drv, efx->net_dev,
638 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000639 rc = -EINVAL;
640 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800641 }
642
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100643 /* Hook for Falcon bug 11482 workaround */
644 if (efx->type->prepare_enable_fc_tx &&
645 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
646 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800647
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000648 old_adv = efx->link_advertising;
649 old_fc = efx->wanted_fc;
650 efx_link_set_wanted_fc(efx, wanted_fc);
651 if (efx->link_advertising != old_adv ||
652 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
653 rc = efx->phy_op->reconfigure(efx);
654 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000655 netif_err(efx, drv, efx->net_dev,
656 "Unable to advertise requested flow "
657 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000658 goto out;
659 }
660 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800661
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000662 /* Reconfigure the MAC. The PHY *may* generate a link state change event
663 * if the user just changed the advertised capabilities, but there's no
664 * harm doing this twice */
Ben Hutchings710b2082011-09-03 00:15:00 +0100665 efx->type->reconfigure_mac(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800666
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000667out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800668 mutex_unlock(&efx->mac_lock);
669
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000670 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100671}
672
673static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
674 struct ethtool_pauseparam *pause)
675{
Ben Hutchings767e4682008-09-01 12:43:14 +0100676 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100677
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800678 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
679 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
680 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100681}
682
683
Ben Hutchings89c758f2009-11-29 03:43:07 +0000684static void efx_ethtool_get_wol(struct net_device *net_dev,
685 struct ethtool_wolinfo *wol)
686{
687 struct efx_nic *efx = netdev_priv(net_dev);
688 return efx->type->get_wol(efx, wol);
689}
690
691
692static int efx_ethtool_set_wol(struct net_device *net_dev,
693 struct ethtool_wolinfo *wol)
694{
695 struct efx_nic *efx = netdev_priv(net_dev);
696 return efx->type->set_wol(efx, wol->wolopts);
697}
698
stephen hemmingerd2156972010-10-18 05:27:31 +0000699static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000700{
701 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100702 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000703
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100704 rc = efx->type->map_reset_flags(flags);
705 if (rc < 0)
706 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000707
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100708 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000709}
710
Ben Hutchings7c460d92012-10-27 00:33:28 +0100711/* MAC address mask including only I/G bit */
712static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
Ben Hutchingsc274d652012-02-02 22:41:49 +0000713
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100714#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
715#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100716#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100717
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000718static int efx_ethtool_get_class_rule(struct efx_nic *efx,
719 struct ethtool_rx_flow_spec *rule)
720{
721 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
722 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000723 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
724 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000725 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000726 int rc;
727
728 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
729 rule->location, &spec);
730 if (rc)
731 return rc;
732
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000733 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000734 rule->ring_cookie = RX_CLS_FLOW_DISC;
735 else
736 rule->ring_cookie = spec.dmaq_id;
737
Ben Hutchings7c460d92012-10-27 00:33:28 +0100738 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
739 spec.ether_type == htons(ETH_P_IP) &&
740 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
741 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
742 !(spec.match_flags &
743 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
744 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
745 EFX_FILTER_MATCH_IP_PROTO |
746 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
747 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
748 TCP_V4_FLOW : UDP_V4_FLOW);
749 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
750 ip_entry->ip4dst = spec.loc_host[0];
751 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000752 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100753 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
754 ip_entry->ip4src = spec.rem_host[0];
755 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
756 }
757 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
758 ip_entry->pdst = spec.loc_port;
759 ip_mask->pdst = PORT_FULL_MASK;
760 }
761 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
762 ip_entry->psrc = spec.rem_port;
763 ip_mask->psrc = PORT_FULL_MASK;
764 }
765 } else if (!(spec.match_flags &
766 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
767 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
768 EFX_FILTER_MATCH_OUTER_VID))) {
769 rule->flow_type = ETHER_FLOW;
770 if (spec.match_flags &
771 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
772 memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN);
773 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
774 memset(mac_mask->h_dest, ~0, ETH_ALEN);
775 else
776 memcpy(mac_mask->h_dest, mac_addr_ig_mask,
777 ETH_ALEN);
778 }
779 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
780 memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN);
781 memset(mac_mask->h_source, ~0, ETH_ALEN);
782 }
783 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
784 mac_entry->h_proto = spec.ether_type;
785 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
786 }
787 } else {
788 /* The above should handle all filters that we insert */
789 WARN_ON(1);
790 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000791 }
792
Ben Hutchings7c460d92012-10-27 00:33:28 +0100793 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
794 rule->flow_type |= FLOW_EXT;
795 rule->h_ext.vlan_tci = spec.outer_vid;
796 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000797 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100798
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000799 return rc;
800}
801
Ben Hutchings765c9f42010-06-30 05:06:28 +0000802static int
803efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000804 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000805{
806 struct efx_nic *efx = netdev_priv(net_dev);
807
808 switch (info->cmd) {
809 case ETHTOOL_GRXRINGS:
810 info->data = efx->n_rx_channels;
811 return 0;
812
813 case ETHTOOL_GRXFH: {
814 unsigned min_revision = 0;
815
816 info->data = 0;
817 switch (info->flow_type) {
818 case TCP_V4_FLOW:
819 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
820 /* fall through */
821 case UDP_V4_FLOW:
822 case SCTP_V4_FLOW:
823 case AH_ESP_V4_FLOW:
824 case IPV4_FLOW:
825 info->data |= RXH_IP_SRC | RXH_IP_DST;
826 min_revision = EFX_REV_FALCON_B0;
827 break;
828 case TCP_V6_FLOW:
829 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
830 /* fall through */
831 case UDP_V6_FLOW:
832 case SCTP_V6_FLOW:
833 case AH_ESP_V6_FLOW:
834 case IPV6_FLOW:
835 info->data |= RXH_IP_SRC | RXH_IP_DST;
836 min_revision = EFX_REV_SIENA_A0;
837 break;
838 default:
839 break;
840 }
841 if (efx_nic_rev(efx) < min_revision)
842 info->data = 0;
843 return 0;
844 }
845
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000846 case ETHTOOL_GRXCLSRLCNT:
847 info->data = efx_filter_get_rx_id_limit(efx);
848 if (info->data == 0)
849 return -EOPNOTSUPP;
850 info->data |= RX_CLS_LOC_SPECIAL;
851 info->rule_cnt =
852 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
853 return 0;
854
855 case ETHTOOL_GRXCLSRULE:
856 if (efx_filter_get_rx_id_limit(efx) == 0)
857 return -EOPNOTSUPP;
858 return efx_ethtool_get_class_rule(efx, &info->fs);
859
860 case ETHTOOL_GRXCLSRLALL: {
861 s32 rc;
862 info->data = efx_filter_get_rx_id_limit(efx);
863 if (info->data == 0)
864 return -EOPNOTSUPP;
865 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
866 rule_locs, info->rule_cnt);
867 if (rc < 0)
868 return rc;
869 info->rule_cnt = rc;
870 return 0;
871 }
872
Ben Hutchings765c9f42010-06-30 05:06:28 +0000873 default:
874 return -EOPNOTSUPP;
875 }
876}
877
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000878static int efx_ethtool_set_class_rule(struct efx_nic *efx,
879 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000880{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000881 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
882 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
883 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
884 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
885 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000886 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000887
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000888 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +0100889 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000890 return -EINVAL;
891
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000892 /* Range-check ring_cookie */
893 if (rule->ring_cookie >= efx->n_rx_channels &&
894 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000895 return -EINVAL;
896
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000897 /* Check for unsupported extensions */
898 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100899 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000900 rule->m_ext.data[1]))
901 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000902
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000903 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
904 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000905 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000906 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000907
Ben Hutchings7c460d92012-10-27 00:33:28 +0100908 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000909 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +0100910 case UDP_V4_FLOW:
911 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
912 EFX_FILTER_MATCH_IP_PROTO);
913 spec.ether_type = htons(ETH_P_IP);
914 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
915 IPPROTO_TCP : IPPROTO_UDP);
916 if (ip_mask->ip4dst) {
917 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
918 return -EINVAL;
919 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
920 spec.loc_host[0] = ip_entry->ip4dst;
921 }
922 if (ip_mask->ip4src) {
923 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
924 return -EINVAL;
925 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
926 spec.rem_host[0] = ip_entry->ip4src;
927 }
928 if (ip_mask->pdst) {
929 if (ip_mask->pdst != PORT_FULL_MASK)
930 return -EINVAL;
931 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
932 spec.loc_port = ip_entry->pdst;
933 }
934 if (ip_mask->psrc) {
935 if (ip_mask->psrc != PORT_FULL_MASK)
936 return -EINVAL;
937 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
938 spec.rem_port = ip_entry->psrc;
939 }
940 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000941 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000942 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000943
Ben Hutchings7c460d92012-10-27 00:33:28 +0100944 case ETHER_FLOW:
945 if (!is_zero_ether_addr(mac_mask->h_dest)) {
946 if (ether_addr_equal(mac_mask->h_dest,
947 mac_addr_ig_mask))
948 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
949 else if (is_broadcast_ether_addr(mac_mask->h_dest))
950 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000951 else
Ben Hutchings7c460d92012-10-27 00:33:28 +0100952 return -EINVAL;
953 memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN);
Ben Hutchingsc274d652012-02-02 22:41:49 +0000954 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100955 if (!is_zero_ether_addr(mac_mask->h_source)) {
956 if (!is_broadcast_ether_addr(mac_mask->h_source))
957 return -EINVAL;
958 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
959 memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN);
Ben Hutchingsc274d652012-02-02 22:41:49 +0000960 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100961 if (mac_mask->h_proto) {
962 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
963 return -EINVAL;
964 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
965 spec.ether_type = mac_entry->h_proto;
966 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000967 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000968
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000969 default:
970 return -EINVAL;
971 }
972
Ben Hutchings7c460d92012-10-27 00:33:28 +0100973 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
974 if (rule->m_ext.vlan_tci != htons(0xfff))
975 return -EINVAL;
976 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
977 spec.outer_vid = rule->h_ext.vlan_tci;
978 }
979
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000980 rc = efx_filter_insert_filter(efx, &spec, true);
981 if (rc < 0)
982 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +0100983
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000984 rule->location = rc;
985 return 0;
986}
987
988static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
989 struct ethtool_rxnfc *info)
990{
991 struct efx_nic *efx = netdev_priv(net_dev);
992
993 if (efx_filter_get_rx_id_limit(efx) == 0)
994 return -EOPNOTSUPP;
995
996 switch (info->cmd) {
997 case ETHTOOL_SRXCLSRLINS:
998 return efx_ethtool_set_class_rule(efx, &info->fs);
999
1000 case ETHTOOL_SRXCLSRLDEL:
1001 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1002 info->fs.location);
1003
1004 default:
1005 return -EOPNOTSUPP;
1006 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001007}
1008
Ben Hutchings7850f632011-12-15 13:55:01 +00001009static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001010{
1011 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001012
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001013 return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
1014 efx->n_rx_channels == 1) ?
Ben Hutchings7850f632011-12-15 13:55:01 +00001015 0 : ARRAY_SIZE(efx->rx_indir_table));
1016}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001017
Ben Hutchings7850f632011-12-15 13:55:01 +00001018static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
1019{
1020 struct efx_nic *efx = netdev_priv(net_dev);
1021
1022 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001023 return 0;
1024}
1025
1026static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
Ben Hutchings7850f632011-12-15 13:55:01 +00001027 const u32 *indir)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001028{
1029 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001030
Ben Hutchings7850f632011-12-15 13:55:01 +00001031 memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001032 efx_nic_push_rx_indir_table(efx);
1033 return 0;
1034}
1035
Ben Hutchings62ebac92013-04-08 17:34:58 +01001036int efx_ethtool_get_ts_info(struct net_device *net_dev,
1037 struct ethtool_ts_info *ts_info)
1038{
1039 struct efx_nic *efx = netdev_priv(net_dev);
1040
1041 /* Software capabilities */
1042 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1043 SOF_TIMESTAMPING_SOFTWARE);
1044 ts_info->phc_index = -1;
1045
1046 efx_ptp_get_ts_info(efx, ts_info);
1047 return 0;
1048}
1049
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001050static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1051 struct ethtool_eeprom *ee,
1052 u8 *data)
1053{
1054 struct efx_nic *efx = netdev_priv(net_dev);
1055 int ret;
1056
1057 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1058 return -EOPNOTSUPP;
1059
1060 mutex_lock(&efx->mac_lock);
1061 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1062 mutex_unlock(&efx->mac_lock);
1063
1064 return ret;
1065}
1066
1067static int efx_ethtool_get_module_info(struct net_device *net_dev,
1068 struct ethtool_modinfo *modinfo)
1069{
1070 struct efx_nic *efx = netdev_priv(net_dev);
1071 int ret;
1072
1073 if (!efx->phy_op || !efx->phy_op->get_module_info)
1074 return -EOPNOTSUPP;
1075
1076 mutex_lock(&efx->mac_lock);
1077 ret = efx->phy_op->get_module_info(efx, modinfo);
1078 mutex_unlock(&efx->mac_lock);
1079
1080 return ret;
1081}
1082
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001083const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001084 .get_settings = efx_ethtool_get_settings,
1085 .set_settings = efx_ethtool_set_settings,
1086 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001087 .get_regs_len = efx_ethtool_get_regs_len,
1088 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001089 .get_msglevel = efx_ethtool_get_msglevel,
1090 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001091 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001092 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001093 .get_coalesce = efx_ethtool_get_coalesce,
1094 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001095 .get_ringparam = efx_ethtool_get_ringparam,
1096 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001097 .get_pauseparam = efx_ethtool_get_pauseparam,
1098 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001099 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001100 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001101 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001102 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001103 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001104 .get_wol = efx_ethtool_get_wol,
1105 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001106 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001107 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001108 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001109 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001110 .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
1111 .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001112 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001113 .get_module_info = efx_ethtool_get_module_info,
1114 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001115};