blob: 0b8ffdfba3d85eba84edcc4df4523a2880ea1112 [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 Hutchings119226c2011-02-18 19:14:13 +000068 EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts),
69 EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers),
70 EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets),
71 EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
Ben Hutchings8ceee662008-04-27 12:55:59 +010072 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
73 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
74 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
75 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
Ben Hutchingsc1ac4032009-11-28 05:36:29 +000076 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
Ben Hutchings8ceee662008-04-27 12:55:59 +010077 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
Ben Hutchings85740cdf2013-01-29 23:33:15 +000078 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc),
Ben Hutchings8ceee662008-04-27 12:55:59 +010079};
80
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000081#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
Ben Hutchings8ceee662008-04-27 12:55:59 +010082
Ben Hutchings4a5b5042008-09-01 12:47:16 +010083#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +010084
Ben Hutchings8ceee662008-04-27 12:55:59 +010085/**************************************************************************
86 *
87 * Ethtool operations
88 *
89 **************************************************************************
90 */
91
92/* Identify device by flashing LEDs */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +010093static int efx_ethtool_phys_id(struct net_device *net_dev,
94 enum ethtool_phys_id_state state)
Ben Hutchings8ceee662008-04-27 12:55:59 +010095{
Ben Hutchings767e4682008-09-01 12:43:14 +010096 struct efx_nic *efx = netdev_priv(net_dev);
Allan, Bruce Wfce55922011-04-13 13:09:10 +000097 enum efx_led_mode mode = EFX_LED_DEFAULT;
Ben Hutchings8ceee662008-04-27 12:55:59 +010098
Ben Hutchingsc5e129a2011-04-02 00:43:46 +010099 switch (state) {
100 case ETHTOOL_ID_ON:
101 mode = EFX_LED_ON;
102 break;
103 case ETHTOOL_ID_OFF:
104 mode = EFX_LED_OFF;
105 break;
106 case ETHTOOL_ID_INACTIVE:
107 mode = EFX_LED_DEFAULT;
108 break;
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000109 case ETHTOOL_ID_ACTIVE:
110 return 1; /* cycle on/off once per second */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100111 }
Ben Hutchings398468e2009-11-23 16:03:45 +0000112
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100113 efx->type->set_id_led(efx, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100114 return 0;
115}
116
117/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000118static int efx_ethtool_get_settings(struct net_device *net_dev,
119 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100120{
Ben Hutchings767e4682008-09-01 12:43:14 +0100121 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000122 struct efx_link_state *link_state = &efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100123
124 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800125 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126 mutex_unlock(&efx->mac_lock);
127
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000128 /* Both MACs support pause frames (bidirectional and respond-only) */
129 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
130
131 if (LOOPBACK_INTERNAL(efx)) {
David Decotigny70739492011-04-27 18:32:40 +0000132 ethtool_cmd_speed_set(ecmd, link_state->speed);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000133 ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
134 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800135
136 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100137}
138
139/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000140static int efx_ethtool_set_settings(struct net_device *net_dev,
141 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100142{
Ben Hutchings767e4682008-09-01 12:43:14 +0100143 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100144 int rc;
145
Ben Hutchings754c6532010-02-03 09:31:57 +0000146 /* GMAC does not support 1000Mbps HD */
David Decotigny25db0332011-04-27 18:32:39 +0000147 if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
148 (ecmd->duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000149 netif_dbg(efx, drv, efx->net_dev,
150 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800151 return -EINVAL;
152 }
153
Ben Hutchings8ceee662008-04-27 12:55:59 +0100154 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800155 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100157 return rc;
158}
159
160static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
161 struct ethtool_drvinfo *info)
162{
Ben Hutchings767e4682008-09-01 12:43:14 +0100163 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100164
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000165 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100166 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000167 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
Ben Hutchingse5f0fd22011-02-24 23:57:47 +0000168 efx_mcdi_print_fwver(efx, info->fw_version,
169 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100170 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
171}
172
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000173static int efx_ethtool_get_regs_len(struct net_device *net_dev)
174{
175 return efx_nic_get_regs_len(netdev_priv(net_dev));
176}
177
178static void efx_ethtool_get_regs(struct net_device *net_dev,
179 struct ethtool_regs *regs, void *buf)
180{
181 struct efx_nic *efx = netdev_priv(net_dev);
182
183 regs->version = efx->type->revision;
184 efx_nic_get_regs(efx, buf);
185}
186
Ben Hutchings62776d02010-06-23 11:30:07 +0000187static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
188{
189 struct efx_nic *efx = netdev_priv(net_dev);
190 return efx->msg_enable;
191}
192
193static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
194{
195 struct efx_nic *efx = netdev_priv(net_dev);
196 efx->msg_enable = msg_enable;
197}
198
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100199/**
200 * efx_fill_test - fill in an individual self-test entry
201 * @test_index: Index of the test
202 * @strings: Ethtool strings, or %NULL
203 * @data: Ethtool test results, or %NULL
204 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800205 * @unit_format: Unit name format (e.g. "chan\%d")
206 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100207 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800208 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100209 *
210 * Fill in an individual self-test entry.
211 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000212static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100213 int *test, const char *unit_format, int unit_id,
214 const char *test_format, const char *test_id)
215{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000216 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100217
218 /* Fill data value, if applicable */
219 if (data)
220 data[test_index] = *test;
221
222 /* Fill string, if applicable */
223 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800224 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000225 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800226 unit_format, unit_id);
227 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000228 strcpy(unit_str, unit_format);
229 snprintf(test_str, sizeof(test_str), test_format, test_id);
230 snprintf(strings + test_index * ETH_GSTRING_LEN,
231 ETH_GSTRING_LEN,
232 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100233 }
234}
235
Ben Hutchings740ced92008-12-12 21:41:55 -0800236#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100237#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
238#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
239#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000240 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100241
242/**
243 * efx_fill_loopback_test - fill in a block of loopback self-test entries
244 * @efx: Efx NIC
245 * @lb_tests: Efx loopback self-test results structure
246 * @mode: Loopback test mode
247 * @test_index: Starting index of the test
248 * @strings: Ethtool strings, or %NULL
249 * @data: Ethtool test results, or %NULL
250 */
251static int efx_fill_loopback_test(struct efx_nic *efx,
252 struct efx_loopback_self_tests *lb_tests,
253 enum efx_loopback_mode mode,
254 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000255 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100256{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100257 struct efx_channel *channel =
258 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100259 struct efx_tx_queue *tx_queue;
260
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000261 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100262 efx_fill_test(test_index++, strings, data,
263 &lb_tests->tx_sent[tx_queue->queue],
264 EFX_TX_QUEUE_NAME(tx_queue),
265 EFX_LOOPBACK_NAME(mode, "tx_sent"));
266 efx_fill_test(test_index++, strings, data,
267 &lb_tests->tx_done[tx_queue->queue],
268 EFX_TX_QUEUE_NAME(tx_queue),
269 EFX_LOOPBACK_NAME(mode, "tx_done"));
270 }
271 efx_fill_test(test_index++, strings, data,
272 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800273 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100274 EFX_LOOPBACK_NAME(mode, "rx_good"));
275 efx_fill_test(test_index++, strings, data,
276 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800277 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100278 EFX_LOOPBACK_NAME(mode, "rx_bad"));
279
280 return test_index;
281}
282
283/**
284 * efx_ethtool_fill_self_tests - get self-test details
285 * @efx: Efx NIC
286 * @tests: Efx self-test results structure, or %NULL
287 * @strings: Ethtool strings, or %NULL
288 * @data: Ethtool test results, or %NULL
289 */
290static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
291 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000292 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100293{
294 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800295 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100296 enum efx_loopback_mode mode;
297
Ben Hutchings4f16c072010-02-03 09:30:50 +0000298 efx_fill_test(n++, strings, data, &tests->phy_alive,
299 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100300 efx_fill_test(n++, strings, data, &tests->nvram,
301 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100302 efx_fill_test(n++, strings, data, &tests->interrupt,
303 "core", 0, "interrupt", NULL);
304
305 /* Event queues */
306 efx_for_each_channel(channel, efx) {
307 efx_fill_test(n++, strings, data,
308 &tests->eventq_dma[channel->channel],
309 EFX_CHANNEL_NAME(channel),
310 "eventq.dma", NULL);
311 efx_fill_test(n++, strings, data,
312 &tests->eventq_int[channel->channel],
313 EFX_CHANNEL_NAME(channel),
314 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100315 }
316
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100317 efx_fill_test(n++, strings, data, &tests->registers,
318 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800319
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000320 if (efx->phy_op->run_tests != NULL) {
321 EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
322
323 for (i = 0; true; ++i) {
324 const char *name;
325
326 EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
327 name = efx->phy_op->test_name(efx, i);
328 if (name == NULL)
329 break;
330
Ben Hutchings4f16c072010-02-03 09:30:50 +0000331 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000332 "phy", 0, name, NULL);
333 }
334 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100335
336 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100337 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100338 if (!(efx->loopback_modes & (1 << mode)))
339 continue;
340 n = efx_fill_loopback_test(efx,
341 &tests->loopback[mode], mode, n,
342 strings, data);
343 }
344
345 return n;
346}
347
Ben Hutchings3594e132008-09-01 12:48:12 +0100348static int efx_ethtool_get_sset_count(struct net_device *net_dev,
349 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100350{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000351 struct efx_nic *efx = netdev_priv(net_dev);
352
Ben Hutchings3594e132008-09-01 12:48:12 +0100353 switch (string_set) {
354 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000355 return efx->type->describe_stats(efx, NULL) +
356 EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings3594e132008-09-01 12:48:12 +0100357 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000358 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100359 default:
360 return -EINVAL;
361 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100362}
363
Ben Hutchings8ceee662008-04-27 12:55:59 +0100364static void efx_ethtool_get_strings(struct net_device *net_dev,
365 u32 string_set, u8 *strings)
366{
Ben Hutchings767e4682008-09-01 12:43:14 +0100367 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100368 int i;
369
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100370 switch (string_set) {
371 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000372 strings += (efx->type->describe_stats(efx, strings) *
373 ETH_GSTRING_LEN);
374 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000375 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000376 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100377 break;
378 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000379 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100380 break;
381 default:
382 /* No other string sets */
383 break;
384 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100385}
386
387static void efx_ethtool_get_stats(struct net_device *net_dev,
388 struct ethtool_stats *stats,
389 u64 *data)
390{
Ben Hutchings767e4682008-09-01 12:43:14 +0100391 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000392 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100393 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000394 struct efx_tx_queue *tx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100395 int i;
396
Ben Hutchings1cb34522011-09-02 23:23:00 +0100397 spin_lock_bh(&efx->stats_lock);
398
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000399 /* Get NIC statistics */
400 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100401
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000402 /* Get software statistics */
403 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
404 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100405 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100406 case EFX_ETHTOOL_STAT_SOURCE_nic:
407 data[i] = stat->get_stat((void *)efx + stat->offset);
408 break;
409 case EFX_ETHTOOL_STAT_SOURCE_channel:
410 data[i] = 0;
411 efx_for_each_channel(channel, efx)
412 data[i] += stat->get_stat((void *)channel +
413 stat->offset);
414 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000415 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
416 data[i] = 0;
417 efx_for_each_channel(channel, efx) {
418 efx_for_each_channel_tx_queue(tx_queue, channel)
419 data[i] +=
420 stat->get_stat((void *)tx_queue
421 + stat->offset);
422 }
423 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100424 }
425 }
Ben Hutchings1cb34522011-09-02 23:23:00 +0100426
427 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100428}
429
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100430static void efx_ethtool_self_test(struct net_device *net_dev,
431 struct ethtool_test *test, u64 *data)
432{
Ben Hutchings767e4682008-09-01 12:43:14 +0100433 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000434 struct efx_self_tests *efx_tests;
Ben Hutchings2ef30682008-12-26 13:47:04 -0800435 int already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000436 int rc = -ENOMEM;
437
438 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
439 if (!efx_tests)
440 goto fail;
441
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100442 if (efx->state != STATE_READY) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100443 rc = -EIO;
444 goto fail1;
445 }
446
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000447 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
448 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
449
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100450 /* We need rx buffers and interrupts. */
451 already_up = (efx->net_dev->flags & IFF_UP);
452 if (!already_up) {
453 rc = dev_open(efx->net_dev);
454 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000455 netif_err(efx, drv, efx->net_dev,
456 "failed opening device.\n");
Eric Dumazet28801f32011-02-16 03:48:38 +0000457 goto fail1;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100458 }
459 }
460
Eric Dumazet28801f32011-02-16 03:48:38 +0000461 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100462
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100463 if (!already_up)
464 dev_close(efx->net_dev);
465
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000466 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
467 rc == 0 ? "passed" : "failed",
468 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100469
Eric Dumazet28801f32011-02-16 03:48:38 +0000470fail1:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100471 /* Fill ethtool results structures */
Eric Dumazet28801f32011-02-16 03:48:38 +0000472 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
473 kfree(efx_tests);
474fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100475 if (rc)
476 test->flags |= ETH_TEST_FL_FAILED;
477}
478
Ben Hutchings8ceee662008-04-27 12:55:59 +0100479/* Restart autonegotiation */
480static int efx_ethtool_nway_reset(struct net_device *net_dev)
481{
Ben Hutchings767e4682008-09-01 12:43:14 +0100482 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100483
Ben Hutchings68e7f452009-04-29 08:05:08 +0000484 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100485}
486
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000487/*
488 * Each channel has a single IRQ and moderation timer, started by any
489 * completion (or other event). Unless the module parameter
490 * separate_tx_channels is set, IRQs and moderation are therefore
491 * shared between RX and TX completions. In this case, when RX IRQ
492 * moderation is explicitly changed then TX IRQ moderation is
493 * automatically changed too, but otherwise we fail if the two values
494 * are requested to be different.
495 *
Ben Hutchings13225972011-09-05 07:43:49 +0000496 * The hardware does not support a limit on the number of completions
497 * before an IRQ, so we do not use the max_frames fields. We should
498 * report and require that max_frames == (usecs != 0), but this would
499 * invalidate existing user documentation.
500 *
501 * The hardware does not have distinct settings for interrupt
502 * moderation while the previous IRQ is being handled, so we should
503 * not use the 'irq' fields. However, an earlier developer
504 * misunderstood the meaning of the 'irq' fields and the driver did
505 * not support the standard fields. To avoid invalidating existing
506 * user documentation, we report and accept changes through either the
507 * standard or 'irq' fields. If both are changed at the same time, we
508 * prefer the standard field.
509 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000510 * We implement adaptive IRQ moderation, but use a different algorithm
511 * from that assumed in the definition of struct ethtool_coalesce.
512 * Therefore we do not use any of the adaptive moderation parameters
513 * in it.
514 */
515
Ben Hutchings8ceee662008-04-27 12:55:59 +0100516static int efx_ethtool_get_coalesce(struct net_device *net_dev,
517 struct ethtool_coalesce *coalesce)
518{
Ben Hutchings767e4682008-09-01 12:43:14 +0100519 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000520 unsigned int tx_usecs, rx_usecs;
521 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100522
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000523 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100524
Ben Hutchings13225972011-09-05 07:43:49 +0000525 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000526 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000527 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000528 coalesce->rx_coalesce_usecs_irq = rx_usecs;
529 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000530
Ben Hutchings8ceee662008-04-27 12:55:59 +0100531 return 0;
532}
533
Ben Hutchings8ceee662008-04-27 12:55:59 +0100534static int efx_ethtool_set_coalesce(struct net_device *net_dev,
535 struct ethtool_coalesce *coalesce)
536{
Ben Hutchings767e4682008-09-01 12:43:14 +0100537 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100538 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000539 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000540 bool adaptive, rx_may_override_tx;
541 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100542
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000543 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000544 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100545
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000546 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
547
Ben Hutchings13225972011-09-05 07:43:49 +0000548 if (coalesce->rx_coalesce_usecs != rx_usecs)
549 rx_usecs = coalesce->rx_coalesce_usecs;
550 else
551 rx_usecs = coalesce->rx_coalesce_usecs_irq;
552
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000553 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100554
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000555 /* If channels are shared, TX IRQ moderation can be quietly
556 * overridden unless it is changed from its old value.
557 */
Ben Hutchings13225972011-09-05 07:43:49 +0000558 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
559 coalesce->tx_coalesce_usecs_irq == tx_usecs);
560 if (coalesce->tx_coalesce_usecs != tx_usecs)
561 tx_usecs = coalesce->tx_coalesce_usecs;
562 else
563 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100564
Ben Hutchings9e393b32011-09-05 07:43:04 +0000565 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
566 rx_may_override_tx);
567 if (rc != 0)
568 return rc;
569
Ben Hutchings8ceee662008-04-27 12:55:59 +0100570 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000571 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100572
573 return 0;
574}
575
Ben Hutchings46426102010-09-10 06:42:33 +0000576static void efx_ethtool_get_ringparam(struct net_device *net_dev,
577 struct ethtool_ringparam *ring)
578{
579 struct efx_nic *efx = netdev_priv(net_dev);
580
581 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
582 ring->tx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchings46426102010-09-10 06:42:33 +0000583 ring->rx_pending = efx->rxq_entries;
584 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000585}
586
587static int efx_ethtool_set_ringparam(struct net_device *net_dev,
588 struct ethtool_ringparam *ring)
589{
590 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000591 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000592
593 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
594 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
595 ring->tx_pending > EFX_MAX_DMAQ_SIZE)
596 return -EINVAL;
597
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000598 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000599 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000600 "RX queues cannot be smaller than %u\n",
601 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000602 return -EINVAL;
603 }
604
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000605 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
606 if (txq_entries != ring->tx_pending)
607 netif_warn(efx, drv, efx->net_dev,
608 "increasing TX queue size to minimum of %u\n",
609 txq_entries);
610
611 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000612}
613
Ben Hutchings8ceee662008-04-27 12:55:59 +0100614static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
615 struct ethtool_pauseparam *pause)
616{
Ben Hutchings767e4682008-09-01 12:43:14 +0100617 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb56269462011-05-17 17:53:22 -0400618 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000619 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000620 int rc = 0;
621
622 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100623
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800624 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
625 (pause->tx_pause ? EFX_FC_TX : 0) |
626 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800628 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000629 netif_dbg(efx, drv, efx->net_dev,
630 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000631 rc = -EINVAL;
632 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800633 }
634
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000635 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000636 netif_dbg(efx, drv, efx->net_dev,
637 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000638 rc = -EINVAL;
639 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800640 }
641
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100642 /* Hook for Falcon bug 11482 workaround */
643 if (efx->type->prepare_enable_fc_tx &&
644 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
645 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800646
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000647 old_adv = efx->link_advertising;
648 old_fc = efx->wanted_fc;
649 efx_link_set_wanted_fc(efx, wanted_fc);
650 if (efx->link_advertising != old_adv ||
651 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
652 rc = efx->phy_op->reconfigure(efx);
653 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000654 netif_err(efx, drv, efx->net_dev,
655 "Unable to advertise requested flow "
656 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000657 goto out;
658 }
659 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800660
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000661 /* Reconfigure the MAC. The PHY *may* generate a link state change event
662 * if the user just changed the advertised capabilities, but there's no
663 * harm doing this twice */
Ben Hutchings710b2082011-09-03 00:15:00 +0100664 efx->type->reconfigure_mac(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800665
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000666out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800667 mutex_unlock(&efx->mac_lock);
668
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000669 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100670}
671
672static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
673 struct ethtool_pauseparam *pause)
674{
Ben Hutchings767e4682008-09-01 12:43:14 +0100675 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100676
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800677 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
678 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
679 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100680}
681
682
Ben Hutchings89c758f2009-11-29 03:43:07 +0000683static void efx_ethtool_get_wol(struct net_device *net_dev,
684 struct ethtool_wolinfo *wol)
685{
686 struct efx_nic *efx = netdev_priv(net_dev);
687 return efx->type->get_wol(efx, wol);
688}
689
690
691static int efx_ethtool_set_wol(struct net_device *net_dev,
692 struct ethtool_wolinfo *wol)
693{
694 struct efx_nic *efx = netdev_priv(net_dev);
695 return efx->type->set_wol(efx, wol->wolopts);
696}
697
stephen hemmingerd2156972010-10-18 05:27:31 +0000698static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000699{
700 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100701 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000702
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100703 rc = efx->type->map_reset_flags(flags);
704 if (rc < 0)
705 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000706
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100707 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000708}
709
Ben Hutchings7c460d92012-10-27 00:33:28 +0100710/* MAC address mask including only I/G bit */
711static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
Ben Hutchingsc274d652012-02-02 22:41:49 +0000712
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100713#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
714#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100715#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100716
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000717static int efx_ethtool_get_class_rule(struct efx_nic *efx,
718 struct ethtool_rx_flow_spec *rule)
719{
720 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
721 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000722 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
723 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000724 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000725 int rc;
726
727 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
728 rule->location, &spec);
729 if (rc)
730 return rc;
731
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000732 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000733 rule->ring_cookie = RX_CLS_FLOW_DISC;
734 else
735 rule->ring_cookie = spec.dmaq_id;
736
Ben Hutchings7c460d92012-10-27 00:33:28 +0100737 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
738 spec.ether_type == htons(ETH_P_IP) &&
739 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
740 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
741 !(spec.match_flags &
742 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
743 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
744 EFX_FILTER_MATCH_IP_PROTO |
745 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
746 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
747 TCP_V4_FLOW : UDP_V4_FLOW);
748 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
749 ip_entry->ip4dst = spec.loc_host[0];
750 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000751 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100752 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
753 ip_entry->ip4src = spec.rem_host[0];
754 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
755 }
756 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
757 ip_entry->pdst = spec.loc_port;
758 ip_mask->pdst = PORT_FULL_MASK;
759 }
760 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
761 ip_entry->psrc = spec.rem_port;
762 ip_mask->psrc = PORT_FULL_MASK;
763 }
764 } else if (!(spec.match_flags &
765 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
766 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
767 EFX_FILTER_MATCH_OUTER_VID))) {
768 rule->flow_type = ETHER_FLOW;
769 if (spec.match_flags &
770 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
771 memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN);
772 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
773 memset(mac_mask->h_dest, ~0, ETH_ALEN);
774 else
775 memcpy(mac_mask->h_dest, mac_addr_ig_mask,
776 ETH_ALEN);
777 }
778 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
779 memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN);
780 memset(mac_mask->h_source, ~0, ETH_ALEN);
781 }
782 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
783 mac_entry->h_proto = spec.ether_type;
784 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
785 }
786 } else {
787 /* The above should handle all filters that we insert */
788 WARN_ON(1);
789 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000790 }
791
Ben Hutchings7c460d92012-10-27 00:33:28 +0100792 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
793 rule->flow_type |= FLOW_EXT;
794 rule->h_ext.vlan_tci = spec.outer_vid;
795 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000796 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100797
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000798 return rc;
799}
800
Ben Hutchings765c9f42010-06-30 05:06:28 +0000801static int
802efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000803 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000804{
805 struct efx_nic *efx = netdev_priv(net_dev);
806
807 switch (info->cmd) {
808 case ETHTOOL_GRXRINGS:
809 info->data = efx->n_rx_channels;
810 return 0;
811
812 case ETHTOOL_GRXFH: {
813 unsigned min_revision = 0;
814
815 info->data = 0;
816 switch (info->flow_type) {
817 case TCP_V4_FLOW:
818 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
819 /* fall through */
820 case UDP_V4_FLOW:
821 case SCTP_V4_FLOW:
822 case AH_ESP_V4_FLOW:
823 case IPV4_FLOW:
824 info->data |= RXH_IP_SRC | RXH_IP_DST;
825 min_revision = EFX_REV_FALCON_B0;
826 break;
827 case TCP_V6_FLOW:
828 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
829 /* fall through */
830 case UDP_V6_FLOW:
831 case SCTP_V6_FLOW:
832 case AH_ESP_V6_FLOW:
833 case IPV6_FLOW:
834 info->data |= RXH_IP_SRC | RXH_IP_DST;
835 min_revision = EFX_REV_SIENA_A0;
836 break;
837 default:
838 break;
839 }
840 if (efx_nic_rev(efx) < min_revision)
841 info->data = 0;
842 return 0;
843 }
844
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000845 case ETHTOOL_GRXCLSRLCNT:
846 info->data = efx_filter_get_rx_id_limit(efx);
847 if (info->data == 0)
848 return -EOPNOTSUPP;
849 info->data |= RX_CLS_LOC_SPECIAL;
850 info->rule_cnt =
851 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
852 return 0;
853
854 case ETHTOOL_GRXCLSRULE:
855 if (efx_filter_get_rx_id_limit(efx) == 0)
856 return -EOPNOTSUPP;
857 return efx_ethtool_get_class_rule(efx, &info->fs);
858
859 case ETHTOOL_GRXCLSRLALL: {
860 s32 rc;
861 info->data = efx_filter_get_rx_id_limit(efx);
862 if (info->data == 0)
863 return -EOPNOTSUPP;
864 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
865 rule_locs, info->rule_cnt);
866 if (rc < 0)
867 return rc;
868 info->rule_cnt = rc;
869 return 0;
870 }
871
Ben Hutchings765c9f42010-06-30 05:06:28 +0000872 default:
873 return -EOPNOTSUPP;
874 }
875}
876
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000877static int efx_ethtool_set_class_rule(struct efx_nic *efx,
878 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000879{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000880 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
881 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
882 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
883 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
884 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000885 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000886
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000887 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +0100888 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000889 return -EINVAL;
890
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000891 /* Range-check ring_cookie */
892 if (rule->ring_cookie >= efx->n_rx_channels &&
893 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000894 return -EINVAL;
895
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000896 /* Check for unsupported extensions */
897 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100898 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000899 rule->m_ext.data[1]))
900 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000901
Ben Hutchings85740cdf2013-01-29 23:33:15 +0000902 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
903 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000904 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000905 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000906
Ben Hutchings7c460d92012-10-27 00:33:28 +0100907 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000908 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +0100909 case UDP_V4_FLOW:
910 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
911 EFX_FILTER_MATCH_IP_PROTO);
912 spec.ether_type = htons(ETH_P_IP);
913 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
914 IPPROTO_TCP : IPPROTO_UDP);
915 if (ip_mask->ip4dst) {
916 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
917 return -EINVAL;
918 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
919 spec.loc_host[0] = ip_entry->ip4dst;
920 }
921 if (ip_mask->ip4src) {
922 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
923 return -EINVAL;
924 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
925 spec.rem_host[0] = ip_entry->ip4src;
926 }
927 if (ip_mask->pdst) {
928 if (ip_mask->pdst != PORT_FULL_MASK)
929 return -EINVAL;
930 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
931 spec.loc_port = ip_entry->pdst;
932 }
933 if (ip_mask->psrc) {
934 if (ip_mask->psrc != PORT_FULL_MASK)
935 return -EINVAL;
936 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
937 spec.rem_port = ip_entry->psrc;
938 }
939 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000940 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000941 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000942
Ben Hutchings7c460d92012-10-27 00:33:28 +0100943 case ETHER_FLOW:
944 if (!is_zero_ether_addr(mac_mask->h_dest)) {
945 if (ether_addr_equal(mac_mask->h_dest,
946 mac_addr_ig_mask))
947 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
948 else if (is_broadcast_ether_addr(mac_mask->h_dest))
949 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000950 else
Ben Hutchings7c460d92012-10-27 00:33:28 +0100951 return -EINVAL;
952 memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN);
Ben Hutchingsc274d652012-02-02 22:41:49 +0000953 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100954 if (!is_zero_ether_addr(mac_mask->h_source)) {
955 if (!is_broadcast_ether_addr(mac_mask->h_source))
956 return -EINVAL;
957 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
958 memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN);
Ben Hutchingsc274d652012-02-02 22:41:49 +0000959 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100960 if (mac_mask->h_proto) {
961 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
962 return -EINVAL;
963 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
964 spec.ether_type = mac_entry->h_proto;
965 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000966 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +0000967
Ben Hutchingsb4187e42010-09-20 08:43:42 +0000968 default:
969 return -EINVAL;
970 }
971
Ben Hutchings7c460d92012-10-27 00:33:28 +0100972 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
973 if (rule->m_ext.vlan_tci != htons(0xfff))
974 return -EINVAL;
975 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
976 spec.outer_vid = rule->h_ext.vlan_tci;
977 }
978
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000979 rc = efx_filter_insert_filter(efx, &spec, true);
980 if (rc < 0)
981 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +0100982
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000983 rule->location = rc;
984 return 0;
985}
986
987static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
988 struct ethtool_rxnfc *info)
989{
990 struct efx_nic *efx = netdev_priv(net_dev);
991
992 if (efx_filter_get_rx_id_limit(efx) == 0)
993 return -EOPNOTSUPP;
994
995 switch (info->cmd) {
996 case ETHTOOL_SRXCLSRLINS:
997 return efx_ethtool_set_class_rule(efx, &info->fs);
998
999 case ETHTOOL_SRXCLSRLDEL:
1000 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1001 info->fs.location);
1002
1003 default:
1004 return -EOPNOTSUPP;
1005 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001006}
1007
Ben Hutchings7850f632011-12-15 13:55:01 +00001008static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001009{
1010 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001011
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001012 return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
1013 efx->n_rx_channels == 1) ?
Ben Hutchings7850f632011-12-15 13:55:01 +00001014 0 : ARRAY_SIZE(efx->rx_indir_table));
1015}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001016
Ben Hutchings7850f632011-12-15 13:55:01 +00001017static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir)
1018{
1019 struct efx_nic *efx = netdev_priv(net_dev);
1020
1021 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001022 return 0;
1023}
1024
1025static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev,
Ben Hutchings7850f632011-12-15 13:55:01 +00001026 const u32 *indir)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001027{
1028 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001029
Ben Hutchings7850f632011-12-15 13:55:01 +00001030 memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001031 efx_nic_push_rx_indir_table(efx);
1032 return 0;
1033}
1034
Ben Hutchings62ebac92013-04-08 17:34:58 +01001035int efx_ethtool_get_ts_info(struct net_device *net_dev,
1036 struct ethtool_ts_info *ts_info)
1037{
1038 struct efx_nic *efx = netdev_priv(net_dev);
1039
1040 /* Software capabilities */
1041 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1042 SOF_TIMESTAMPING_SOFTWARE);
1043 ts_info->phc_index = -1;
1044
1045 efx_ptp_get_ts_info(efx, ts_info);
1046 return 0;
1047}
1048
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001049static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1050 struct ethtool_eeprom *ee,
1051 u8 *data)
1052{
1053 struct efx_nic *efx = netdev_priv(net_dev);
1054 int ret;
1055
1056 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1057 return -EOPNOTSUPP;
1058
1059 mutex_lock(&efx->mac_lock);
1060 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1061 mutex_unlock(&efx->mac_lock);
1062
1063 return ret;
1064}
1065
1066static int efx_ethtool_get_module_info(struct net_device *net_dev,
1067 struct ethtool_modinfo *modinfo)
1068{
1069 struct efx_nic *efx = netdev_priv(net_dev);
1070 int ret;
1071
1072 if (!efx->phy_op || !efx->phy_op->get_module_info)
1073 return -EOPNOTSUPP;
1074
1075 mutex_lock(&efx->mac_lock);
1076 ret = efx->phy_op->get_module_info(efx, modinfo);
1077 mutex_unlock(&efx->mac_lock);
1078
1079 return ret;
1080}
1081
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001082const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001083 .get_settings = efx_ethtool_get_settings,
1084 .set_settings = efx_ethtool_set_settings,
1085 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001086 .get_regs_len = efx_ethtool_get_regs_len,
1087 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001088 .get_msglevel = efx_ethtool_get_msglevel,
1089 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001090 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001091 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001092 .get_coalesce = efx_ethtool_get_coalesce,
1093 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001094 .get_ringparam = efx_ethtool_get_ringparam,
1095 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001096 .get_pauseparam = efx_ethtool_get_pauseparam,
1097 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001098 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001099 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001100 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001101 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001102 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001103 .get_wol = efx_ethtool_get_wol,
1104 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001105 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001106 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001107 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001108 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001109 .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
1110 .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001111 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001112 .get_module_info = efx_ethtool_get_module_info,
1113 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001114};