blob: bf126f935ade1b68005bc36112aeab43aff97542 [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01002 * Driver for Solarflare network controllers and boards
Ben Hutchings8ceee662008-04-27 12:55:59 +01003 * Copyright 2005-2006 Fen Systems Ltd.
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01004 * Copyright 2006-2013 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),
Jon Cooperee45fd92c2013-09-02 18:24:29 +010073 EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
Ben Hutchings8ceee662008-04-27 12:55:59 +010074 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
75 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
76 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
Ben Hutchingsc1ac4032009-11-28 05:36:29 +000078 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
Ben Hutchings8ceee662008-04-27 12:55:59 +010079 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
Ben Hutchings8127d662013-08-29 19:19:29 +010080 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
81 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
Ben Hutchings8ceee662008-04-27 12:55:59 +010082};
83
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000084#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
Ben Hutchings8ceee662008-04-27 12:55:59 +010085
Ben Hutchings4a5b5042008-09-01 12:47:16 +010086#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +010087
Ben Hutchings8ceee662008-04-27 12:55:59 +010088/**************************************************************************
89 *
90 * Ethtool operations
91 *
92 **************************************************************************
93 */
94
95/* Identify device by flashing LEDs */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +010096static int efx_ethtool_phys_id(struct net_device *net_dev,
97 enum ethtool_phys_id_state state)
Ben Hutchings8ceee662008-04-27 12:55:59 +010098{
Ben Hutchings767e4682008-09-01 12:43:14 +010099 struct efx_nic *efx = netdev_priv(net_dev);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000100 enum efx_led_mode mode = EFX_LED_DEFAULT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100101
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100102 switch (state) {
103 case ETHTOOL_ID_ON:
104 mode = EFX_LED_ON;
105 break;
106 case ETHTOOL_ID_OFF:
107 mode = EFX_LED_OFF;
108 break;
109 case ETHTOOL_ID_INACTIVE:
110 mode = EFX_LED_DEFAULT;
111 break;
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000112 case ETHTOOL_ID_ACTIVE:
113 return 1; /* cycle on/off once per second */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100114 }
Ben Hutchings398468e2009-11-23 16:03:45 +0000115
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100116 efx->type->set_id_led(efx, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100117 return 0;
118}
119
120/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000121static int efx_ethtool_get_settings(struct net_device *net_dev,
122 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100123{
Ben Hutchings767e4682008-09-01 12:43:14 +0100124 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000125 struct efx_link_state *link_state = &efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126
127 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800128 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100129 mutex_unlock(&efx->mac_lock);
130
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000131 /* Both MACs support pause frames (bidirectional and respond-only) */
132 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
133
134 if (LOOPBACK_INTERNAL(efx)) {
David Decotigny70739492011-04-27 18:32:40 +0000135 ethtool_cmd_speed_set(ecmd, link_state->speed);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000136 ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
137 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800138
139 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100140}
141
142/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000143static int efx_ethtool_set_settings(struct net_device *net_dev,
144 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100145{
Ben Hutchings767e4682008-09-01 12:43:14 +0100146 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100147 int rc;
148
Ben Hutchings754c6532010-02-03 09:31:57 +0000149 /* GMAC does not support 1000Mbps HD */
David Decotigny25db0332011-04-27 18:32:39 +0000150 if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
151 (ecmd->duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000152 netif_dbg(efx, drv, efx->net_dev,
153 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800154 return -EINVAL;
155 }
156
Ben Hutchings8ceee662008-04-27 12:55:59 +0100157 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800158 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100159 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100160 return rc;
161}
162
163static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
164 struct ethtool_drvinfo *info)
165{
Ben Hutchings767e4682008-09-01 12:43:14 +0100166 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100167
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000168 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100169 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Ben Hutchings8880f4e2009-11-29 15:15:41 +0000170 if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0)
Ben Hutchingse5f0fd22011-02-24 23:57:47 +0000171 efx_mcdi_print_fwver(efx, info->fw_version,
172 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100173 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
174}
175
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000176static int efx_ethtool_get_regs_len(struct net_device *net_dev)
177{
178 return efx_nic_get_regs_len(netdev_priv(net_dev));
179}
180
181static void efx_ethtool_get_regs(struct net_device *net_dev,
182 struct ethtool_regs *regs, void *buf)
183{
184 struct efx_nic *efx = netdev_priv(net_dev);
185
186 regs->version = efx->type->revision;
187 efx_nic_get_regs(efx, buf);
188}
189
Ben Hutchings62776d02010-06-23 11:30:07 +0000190static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
191{
192 struct efx_nic *efx = netdev_priv(net_dev);
193 return efx->msg_enable;
194}
195
196static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
197{
198 struct efx_nic *efx = netdev_priv(net_dev);
199 efx->msg_enable = msg_enable;
200}
201
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100202/**
203 * efx_fill_test - fill in an individual self-test entry
204 * @test_index: Index of the test
205 * @strings: Ethtool strings, or %NULL
206 * @data: Ethtool test results, or %NULL
207 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800208 * @unit_format: Unit name format (e.g. "chan\%d")
209 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100210 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800211 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100212 *
213 * Fill in an individual self-test entry.
214 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000215static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100216 int *test, const char *unit_format, int unit_id,
217 const char *test_format, const char *test_id)
218{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000219 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100220
221 /* Fill data value, if applicable */
222 if (data)
223 data[test_index] = *test;
224
225 /* Fill string, if applicable */
226 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800227 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000228 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800229 unit_format, unit_id);
230 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000231 strcpy(unit_str, unit_format);
232 snprintf(test_str, sizeof(test_str), test_format, test_id);
233 snprintf(strings + test_index * ETH_GSTRING_LEN,
234 ETH_GSTRING_LEN,
235 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100236 }
237}
238
Ben Hutchings740ced92008-12-12 21:41:55 -0800239#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100240#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
241#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
242#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000243 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100244
245/**
246 * efx_fill_loopback_test - fill in a block of loopback self-test entries
247 * @efx: Efx NIC
248 * @lb_tests: Efx loopback self-test results structure
249 * @mode: Loopback test mode
250 * @test_index: Starting index of the test
251 * @strings: Ethtool strings, or %NULL
252 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000253 *
254 * Fill in a block of loopback self-test entries. Return new test
255 * index.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100256 */
257static int efx_fill_loopback_test(struct efx_nic *efx,
258 struct efx_loopback_self_tests *lb_tests,
259 enum efx_loopback_mode mode,
260 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000261 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100262{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100263 struct efx_channel *channel =
264 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100265 struct efx_tx_queue *tx_queue;
266
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000267 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100268 efx_fill_test(test_index++, strings, data,
269 &lb_tests->tx_sent[tx_queue->queue],
270 EFX_TX_QUEUE_NAME(tx_queue),
271 EFX_LOOPBACK_NAME(mode, "tx_sent"));
272 efx_fill_test(test_index++, strings, data,
273 &lb_tests->tx_done[tx_queue->queue],
274 EFX_TX_QUEUE_NAME(tx_queue),
275 EFX_LOOPBACK_NAME(mode, "tx_done"));
276 }
277 efx_fill_test(test_index++, strings, data,
278 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800279 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100280 EFX_LOOPBACK_NAME(mode, "rx_good"));
281 efx_fill_test(test_index++, strings, data,
282 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800283 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100284 EFX_LOOPBACK_NAME(mode, "rx_bad"));
285
286 return test_index;
287}
288
289/**
290 * efx_ethtool_fill_self_tests - get self-test details
291 * @efx: Efx NIC
292 * @tests: Efx self-test results structure, or %NULL
293 * @strings: Ethtool strings, or %NULL
294 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000295 *
296 * Get self-test number of strings, strings, and/or test results.
297 * Return number of strings (== number of test results).
298 *
299 * The reason for merging these three functions is to make sure that
300 * they can never be inconsistent.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100301 */
302static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
303 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000304 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100305{
306 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800307 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100308 enum efx_loopback_mode mode;
309
Ben Hutchings4f16c072010-02-03 09:30:50 +0000310 efx_fill_test(n++, strings, data, &tests->phy_alive,
311 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100312 efx_fill_test(n++, strings, data, &tests->nvram,
313 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100314 efx_fill_test(n++, strings, data, &tests->interrupt,
315 "core", 0, "interrupt", NULL);
316
317 /* Event queues */
318 efx_for_each_channel(channel, efx) {
319 efx_fill_test(n++, strings, data,
320 &tests->eventq_dma[channel->channel],
321 EFX_CHANNEL_NAME(channel),
322 "eventq.dma", NULL);
323 efx_fill_test(n++, strings, data,
324 &tests->eventq_int[channel->channel],
325 EFX_CHANNEL_NAME(channel),
326 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100327 }
328
Jon Cooper74cd60a2013-09-16 14:18:51 +0100329 efx_fill_test(n++, strings, data, &tests->memory,
330 "core", 0, "memory", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100331 efx_fill_test(n++, strings, data, &tests->registers,
332 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800333
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000334 if (efx->phy_op->run_tests != NULL) {
335 EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL);
336
337 for (i = 0; true; ++i) {
338 const char *name;
339
340 EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
341 name = efx->phy_op->test_name(efx, i);
342 if (name == NULL)
343 break;
344
Ben Hutchings4f16c072010-02-03 09:30:50 +0000345 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000346 "phy", 0, name, NULL);
347 }
348 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100349
350 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100351 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100352 if (!(efx->loopback_modes & (1 << mode)))
353 continue;
354 n = efx_fill_loopback_test(efx,
355 &tests->loopback[mode], mode, n,
356 strings, data);
357 }
358
359 return n;
360}
361
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100362static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
363{
364 size_t n_stats = 0;
365 struct efx_channel *channel;
366
367 efx_for_each_channel(channel, efx) {
368 if (efx_channel_has_tx_queues(channel)) {
369 n_stats++;
370 if (strings != NULL) {
371 snprintf(strings, ETH_GSTRING_LEN,
372 "tx-%u.tx_packets",
373 channel->tx_queue[0].queue /
374 EFX_TXQ_TYPES);
375
376 strings += ETH_GSTRING_LEN;
377 }
378 }
379 }
380 efx_for_each_channel(channel, efx) {
381 if (efx_channel_has_rx_queue(channel)) {
382 n_stats++;
383 if (strings != NULL) {
384 snprintf(strings, ETH_GSTRING_LEN,
385 "rx-%d.rx_packets", channel->channel);
386 strings += ETH_GSTRING_LEN;
387 }
388 }
389 }
390 return n_stats;
391}
392
Ben Hutchings3594e132008-09-01 12:48:12 +0100393static int efx_ethtool_get_sset_count(struct net_device *net_dev,
394 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100395{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000396 struct efx_nic *efx = netdev_priv(net_dev);
397
Ben Hutchings3594e132008-09-01 12:48:12 +0100398 switch (string_set) {
399 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000400 return efx->type->describe_stats(efx, NULL) +
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100401 EFX_ETHTOOL_SW_STAT_COUNT +
402 efx_describe_per_queue_stats(efx, NULL) +
403 efx_ptp_describe_stats(efx, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100404 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000405 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100406 default:
407 return -EINVAL;
408 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100409}
410
Ben Hutchings8ceee662008-04-27 12:55:59 +0100411static void efx_ethtool_get_strings(struct net_device *net_dev,
412 u32 string_set, u8 *strings)
413{
Ben Hutchings767e4682008-09-01 12:43:14 +0100414 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100415 int i;
416
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100417 switch (string_set) {
418 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000419 strings += (efx->type->describe_stats(efx, strings) *
420 ETH_GSTRING_LEN);
421 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000422 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000423 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000424 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100425 strings += (efx_describe_per_queue_stats(efx, strings) *
426 ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000427 efx_ptp_describe_stats(efx, strings);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100428 break;
429 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000430 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100431 break;
432 default:
433 /* No other string sets */
434 break;
435 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436}
437
438static void efx_ethtool_get_stats(struct net_device *net_dev,
439 struct ethtool_stats *stats,
440 u64 *data)
441{
Ben Hutchings767e4682008-09-01 12:43:14 +0100442 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000443 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100444 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000445 struct efx_tx_queue *tx_queue;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100446 struct efx_rx_queue *rx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100447 int i;
448
Ben Hutchings1cb34522011-09-02 23:23:00 +0100449 spin_lock_bh(&efx->stats_lock);
450
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000451 /* Get NIC statistics */
452 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100453
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000454 /* Get software statistics */
455 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
456 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100457 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100458 case EFX_ETHTOOL_STAT_SOURCE_nic:
459 data[i] = stat->get_stat((void *)efx + stat->offset);
460 break;
461 case EFX_ETHTOOL_STAT_SOURCE_channel:
462 data[i] = 0;
463 efx_for_each_channel(channel, efx)
464 data[i] += stat->get_stat((void *)channel +
465 stat->offset);
466 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000467 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
468 data[i] = 0;
469 efx_for_each_channel(channel, efx) {
470 efx_for_each_channel_tx_queue(tx_queue, channel)
471 data[i] +=
472 stat->get_stat((void *)tx_queue
473 + stat->offset);
474 }
475 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100476 }
477 }
Ben Hutchings99691c42013-12-11 02:36:08 +0000478 data += EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings1cb34522011-09-02 23:23:00 +0100479
480 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings99691c42013-12-11 02:36:08 +0000481
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100482 efx_for_each_channel(channel, efx) {
483 if (efx_channel_has_tx_queues(channel)) {
484 *data = 0;
485 efx_for_each_channel_tx_queue(tx_queue, channel) {
486 *data += tx_queue->tx_packets;
487 }
488 data++;
489 }
490 }
491 efx_for_each_channel(channel, efx) {
492 if (efx_channel_has_rx_queue(channel)) {
493 *data = 0;
494 efx_for_each_channel_rx_queue(rx_queue, channel) {
495 *data += rx_queue->rx_packets;
496 }
497 data++;
498 }
499 }
500
Ben Hutchings99691c42013-12-11 02:36:08 +0000501 efx_ptp_update_stats(efx, data);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100502}
503
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100504static void efx_ethtool_self_test(struct net_device *net_dev,
505 struct ethtool_test *test, u64 *data)
506{
Ben Hutchings767e4682008-09-01 12:43:14 +0100507 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000508 struct efx_self_tests *efx_tests;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000509 bool already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000510 int rc = -ENOMEM;
511
512 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
513 if (!efx_tests)
514 goto fail;
515
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100516 if (efx->state != STATE_READY) {
Ben Hutchings5eed1f62014-02-12 19:00:28 +0000517 rc = -EBUSY;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000518 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100519 }
520
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000521 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
522 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
523
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100524 /* We need rx buffers and interrupts. */
525 already_up = (efx->net_dev->flags & IFF_UP);
526 if (!already_up) {
527 rc = dev_open(efx->net_dev);
528 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000529 netif_err(efx, drv, efx->net_dev,
530 "failed opening device.\n");
Ben Hutchings17e678d2014-02-12 19:00:16 +0000531 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100532 }
533 }
534
Eric Dumazet28801f32011-02-16 03:48:38 +0000535 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100536
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100537 if (!already_up)
538 dev_close(efx->net_dev);
539
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000540 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
541 rc == 0 ? "passed" : "failed",
542 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100543
Ben Hutchings17e678d2014-02-12 19:00:16 +0000544out:
Eric Dumazet28801f32011-02-16 03:48:38 +0000545 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
546 kfree(efx_tests);
547fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100548 if (rc)
549 test->flags |= ETH_TEST_FL_FAILED;
550}
551
Ben Hutchings8ceee662008-04-27 12:55:59 +0100552/* Restart autonegotiation */
553static int efx_ethtool_nway_reset(struct net_device *net_dev)
554{
Ben Hutchings767e4682008-09-01 12:43:14 +0100555 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100556
Ben Hutchings68e7f452009-04-29 08:05:08 +0000557 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100558}
559
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000560/*
561 * Each channel has a single IRQ and moderation timer, started by any
562 * completion (or other event). Unless the module parameter
563 * separate_tx_channels is set, IRQs and moderation are therefore
564 * shared between RX and TX completions. In this case, when RX IRQ
565 * moderation is explicitly changed then TX IRQ moderation is
566 * automatically changed too, but otherwise we fail if the two values
567 * are requested to be different.
568 *
Ben Hutchings13225972011-09-05 07:43:49 +0000569 * The hardware does not support a limit on the number of completions
570 * before an IRQ, so we do not use the max_frames fields. We should
571 * report and require that max_frames == (usecs != 0), but this would
572 * invalidate existing user documentation.
573 *
574 * The hardware does not have distinct settings for interrupt
575 * moderation while the previous IRQ is being handled, so we should
576 * not use the 'irq' fields. However, an earlier developer
577 * misunderstood the meaning of the 'irq' fields and the driver did
578 * not support the standard fields. To avoid invalidating existing
579 * user documentation, we report and accept changes through either the
580 * standard or 'irq' fields. If both are changed at the same time, we
581 * prefer the standard field.
582 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000583 * We implement adaptive IRQ moderation, but use a different algorithm
584 * from that assumed in the definition of struct ethtool_coalesce.
585 * Therefore we do not use any of the adaptive moderation parameters
586 * in it.
587 */
588
Ben Hutchings8ceee662008-04-27 12:55:59 +0100589static int efx_ethtool_get_coalesce(struct net_device *net_dev,
590 struct ethtool_coalesce *coalesce)
591{
Ben Hutchings767e4682008-09-01 12:43:14 +0100592 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000593 unsigned int tx_usecs, rx_usecs;
594 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100595
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000596 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100597
Ben Hutchings13225972011-09-05 07:43:49 +0000598 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000599 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000600 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000601 coalesce->rx_coalesce_usecs_irq = rx_usecs;
602 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000603
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604 return 0;
605}
606
Ben Hutchings8ceee662008-04-27 12:55:59 +0100607static int efx_ethtool_set_coalesce(struct net_device *net_dev,
608 struct ethtool_coalesce *coalesce)
609{
Ben Hutchings767e4682008-09-01 12:43:14 +0100610 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100611 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000612 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000613 bool adaptive, rx_may_override_tx;
614 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100615
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000616 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000617 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100618
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000619 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
620
Ben Hutchings13225972011-09-05 07:43:49 +0000621 if (coalesce->rx_coalesce_usecs != rx_usecs)
622 rx_usecs = coalesce->rx_coalesce_usecs;
623 else
624 rx_usecs = coalesce->rx_coalesce_usecs_irq;
625
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000626 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100627
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000628 /* If channels are shared, TX IRQ moderation can be quietly
629 * overridden unless it is changed from its old value.
630 */
Ben Hutchings13225972011-09-05 07:43:49 +0000631 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
632 coalesce->tx_coalesce_usecs_irq == tx_usecs);
633 if (coalesce->tx_coalesce_usecs != tx_usecs)
634 tx_usecs = coalesce->tx_coalesce_usecs;
635 else
636 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100637
Ben Hutchings9e393b32011-09-05 07:43:04 +0000638 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
639 rx_may_override_tx);
640 if (rc != 0)
641 return rc;
642
Ben Hutchings8ceee662008-04-27 12:55:59 +0100643 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000644 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100645
646 return 0;
647}
648
Ben Hutchings46426102010-09-10 06:42:33 +0000649static void efx_ethtool_get_ringparam(struct net_device *net_dev,
650 struct ethtool_ringparam *ring)
651{
652 struct efx_nic *efx = netdev_priv(net_dev);
653
654 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000655 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000656 ring->rx_pending = efx->rxq_entries;
657 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000658}
659
660static int efx_ethtool_set_ringparam(struct net_device *net_dev,
661 struct ethtool_ringparam *ring)
662{
663 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000664 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000665
666 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
667 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000668 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
Ben Hutchings46426102010-09-10 06:42:33 +0000669 return -EINVAL;
670
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000671 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000672 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000673 "RX queues cannot be smaller than %u\n",
674 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000675 return -EINVAL;
676 }
677
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000678 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
679 if (txq_entries != ring->tx_pending)
680 netif_warn(efx, drv, efx->net_dev,
681 "increasing TX queue size to minimum of %u\n",
682 txq_entries);
683
684 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000685}
686
Ben Hutchings8ceee662008-04-27 12:55:59 +0100687static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
688 struct ethtool_pauseparam *pause)
689{
Ben Hutchings767e4682008-09-01 12:43:14 +0100690 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb56269462011-05-17 17:53:22 -0400691 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000692 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000693 int rc = 0;
694
695 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100696
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800697 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
698 (pause->tx_pause ? EFX_FC_TX : 0) |
699 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100700
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800701 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000702 netif_dbg(efx, drv, efx->net_dev,
703 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000704 rc = -EINVAL;
705 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800706 }
707
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000708 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000709 netif_dbg(efx, drv, efx->net_dev,
710 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000711 rc = -EINVAL;
712 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800713 }
714
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100715 /* Hook for Falcon bug 11482 workaround */
716 if (efx->type->prepare_enable_fc_tx &&
717 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
718 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800719
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000720 old_adv = efx->link_advertising;
721 old_fc = efx->wanted_fc;
722 efx_link_set_wanted_fc(efx, wanted_fc);
723 if (efx->link_advertising != old_adv ||
724 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
725 rc = efx->phy_op->reconfigure(efx);
726 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000727 netif_err(efx, drv, efx->net_dev,
728 "Unable to advertise requested flow "
729 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000730 goto out;
731 }
732 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800733
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000734 /* Reconfigure the MAC. The PHY *may* generate a link state change event
735 * if the user just changed the advertised capabilities, but there's no
736 * harm doing this twice */
Edward Cree0d322412015-05-20 11:10:03 +0100737 efx_mac_reconfigure(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800738
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000739out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800740 mutex_unlock(&efx->mac_lock);
741
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000742 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100743}
744
745static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
746 struct ethtool_pauseparam *pause)
747{
Ben Hutchings767e4682008-09-01 12:43:14 +0100748 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100749
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800750 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
751 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
752 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100753}
754
Ben Hutchings89c758f2009-11-29 03:43:07 +0000755static void efx_ethtool_get_wol(struct net_device *net_dev,
756 struct ethtool_wolinfo *wol)
757{
758 struct efx_nic *efx = netdev_priv(net_dev);
759 return efx->type->get_wol(efx, wol);
760}
761
762
763static int efx_ethtool_set_wol(struct net_device *net_dev,
764 struct ethtool_wolinfo *wol)
765{
766 struct efx_nic *efx = netdev_priv(net_dev);
767 return efx->type->set_wol(efx, wol->wolopts);
768}
769
stephen hemmingerd2156972010-10-18 05:27:31 +0000770static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000771{
772 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100773 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000774
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100775 rc = efx->type->map_reset_flags(flags);
776 if (rc < 0)
777 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000778
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100779 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000780}
781
Ben Hutchings7c460d92012-10-27 00:33:28 +0100782/* MAC address mask including only I/G bit */
Edward Creecd84ff42014-03-07 18:27:41 +0000783static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
Ben Hutchingsc274d652012-02-02 22:41:49 +0000784
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100785#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
Edward Creea7ad40d2016-02-05 11:16:50 +0000786#define IP_PROTO_FULL_MASK 0xFF
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100787#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100788#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100789
Edward Creea7ad40d2016-02-05 11:16:50 +0000790static inline void ip6_fill_mask(__be32 *mask)
791{
792 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
793}
794
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000795static int efx_ethtool_get_class_rule(struct efx_nic *efx,
796 struct ethtool_rx_flow_spec *rule)
797{
798 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
799 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +0000800 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
801 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
802 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
803 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
804 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
805 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000806 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
807 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000808 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000809 int rc;
810
811 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
812 rule->location, &spec);
813 if (rc)
814 return rc;
815
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000816 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000817 rule->ring_cookie = RX_CLS_FLOW_DISC;
818 else
819 rule->ring_cookie = spec.dmaq_id;
820
Ben Hutchings7c460d92012-10-27 00:33:28 +0100821 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
822 spec.ether_type == htons(ETH_P_IP) &&
823 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
824 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
825 !(spec.match_flags &
826 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
827 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
828 EFX_FILTER_MATCH_IP_PROTO |
829 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
830 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
831 TCP_V4_FLOW : UDP_V4_FLOW);
832 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
833 ip_entry->ip4dst = spec.loc_host[0];
834 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000835 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100836 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
837 ip_entry->ip4src = spec.rem_host[0];
838 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
839 }
840 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
841 ip_entry->pdst = spec.loc_port;
842 ip_mask->pdst = PORT_FULL_MASK;
843 }
844 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
845 ip_entry->psrc = spec.rem_port;
846 ip_mask->psrc = PORT_FULL_MASK;
847 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000848 } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
849 spec.ether_type == htons(ETH_P_IPV6) &&
850 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
851 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
852 !(spec.match_flags &
853 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
854 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
855 EFX_FILTER_MATCH_IP_PROTO |
856 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
857 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
858 TCP_V6_FLOW : UDP_V6_FLOW);
859 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
860 memcpy(ip6_entry->ip6dst, spec.loc_host,
861 sizeof(ip6_entry->ip6dst));
862 ip6_fill_mask(ip6_mask->ip6dst);
863 }
864 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
865 memcpy(ip6_entry->ip6src, spec.rem_host,
866 sizeof(ip6_entry->ip6src));
867 ip6_fill_mask(ip6_mask->ip6src);
868 }
869 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
870 ip6_entry->pdst = spec.loc_port;
871 ip6_mask->pdst = PORT_FULL_MASK;
872 }
873 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
874 ip6_entry->psrc = spec.rem_port;
875 ip6_mask->psrc = PORT_FULL_MASK;
876 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100877 } else if (!(spec.match_flags &
878 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
879 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
880 EFX_FILTER_MATCH_OUTER_VID))) {
881 rule->flow_type = ETHER_FLOW;
882 if (spec.match_flags &
883 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
Edward Creecd84ff42014-03-07 18:27:41 +0000884 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100885 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
Edward Creecd84ff42014-03-07 18:27:41 +0000886 eth_broadcast_addr(mac_mask->h_dest);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100887 else
Edward Creecd84ff42014-03-07 18:27:41 +0000888 ether_addr_copy(mac_mask->h_dest,
889 mac_addr_ig_mask);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100890 }
891 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
Edward Creecd84ff42014-03-07 18:27:41 +0000892 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
893 eth_broadcast_addr(mac_mask->h_source);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100894 }
895 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
896 mac_entry->h_proto = spec.ether_type;
897 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
898 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000899 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
900 spec.ether_type == htons(ETH_P_IP) &&
901 !(spec.match_flags &
902 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
903 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
904 EFX_FILTER_MATCH_IP_PROTO))) {
905 rule->flow_type = IPV4_USER_FLOW;
906 uip_entry->ip_ver = ETH_RX_NFC_IP4;
907 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
908 uip_mask->proto = IP_PROTO_FULL_MASK;
909 uip_entry->proto = spec.ip_proto;
910 }
911 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
912 uip_entry->ip4dst = spec.loc_host[0];
913 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
914 }
915 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
916 uip_entry->ip4src = spec.rem_host[0];
917 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
918 }
919 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
920 spec.ether_type == htons(ETH_P_IPV6) &&
921 !(spec.match_flags &
922 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
923 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
924 EFX_FILTER_MATCH_IP_PROTO))) {
925 rule->flow_type = IPV6_USER_FLOW;
926 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
927 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
928 uip6_entry->l4_proto = spec.ip_proto;
929 }
930 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
931 memcpy(uip6_entry->ip6dst, spec.loc_host,
932 sizeof(uip6_entry->ip6dst));
933 ip6_fill_mask(uip6_mask->ip6dst);
934 }
935 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
936 memcpy(uip6_entry->ip6src, spec.rem_host,
937 sizeof(uip6_entry->ip6src));
938 ip6_fill_mask(uip6_mask->ip6src);
939 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100940 } else {
941 /* The above should handle all filters that we insert */
942 WARN_ON(1);
943 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000944 }
945
Ben Hutchings7c460d92012-10-27 00:33:28 +0100946 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
947 rule->flow_type |= FLOW_EXT;
948 rule->h_ext.vlan_tci = spec.outer_vid;
949 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000950 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100951
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000952 return rc;
953}
954
Ben Hutchings765c9f42010-06-30 05:06:28 +0000955static int
956efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000957 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000958{
959 struct efx_nic *efx = netdev_priv(net_dev);
960
961 switch (info->cmd) {
962 case ETHTOOL_GRXRINGS:
963 info->data = efx->n_rx_channels;
964 return 0;
965
966 case ETHTOOL_GRXFH: {
967 unsigned min_revision = 0;
968
969 info->data = 0;
970 switch (info->flow_type) {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000971 case UDP_V4_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000972 if (efx->rx_hash_udp_4tuple)
973 /* fall through */
974 case TCP_V4_FLOW:
975 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
976 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000977 case SCTP_V4_FLOW:
978 case AH_ESP_V4_FLOW:
979 case IPV4_FLOW:
980 info->data |= RXH_IP_SRC | RXH_IP_DST;
981 min_revision = EFX_REV_FALCON_B0;
982 break;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000983 case UDP_V6_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000984 if (efx->rx_hash_udp_4tuple)
985 /* fall through */
986 case TCP_V6_FLOW:
987 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
988 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000989 case SCTP_V6_FLOW:
990 case AH_ESP_V6_FLOW:
991 case IPV6_FLOW:
992 info->data |= RXH_IP_SRC | RXH_IP_DST;
993 min_revision = EFX_REV_SIENA_A0;
994 break;
995 default:
996 break;
997 }
998 if (efx_nic_rev(efx) < min_revision)
999 info->data = 0;
1000 return 0;
1001 }
1002
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001003 case ETHTOOL_GRXCLSRLCNT:
1004 info->data = efx_filter_get_rx_id_limit(efx);
1005 if (info->data == 0)
1006 return -EOPNOTSUPP;
1007 info->data |= RX_CLS_LOC_SPECIAL;
1008 info->rule_cnt =
1009 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1010 return 0;
1011
1012 case ETHTOOL_GRXCLSRULE:
1013 if (efx_filter_get_rx_id_limit(efx) == 0)
1014 return -EOPNOTSUPP;
1015 return efx_ethtool_get_class_rule(efx, &info->fs);
1016
1017 case ETHTOOL_GRXCLSRLALL: {
1018 s32 rc;
1019 info->data = efx_filter_get_rx_id_limit(efx);
1020 if (info->data == 0)
1021 return -EOPNOTSUPP;
1022 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1023 rule_locs, info->rule_cnt);
1024 if (rc < 0)
1025 return rc;
1026 info->rule_cnt = rc;
1027 return 0;
1028 }
1029
Ben Hutchings765c9f42010-06-30 05:06:28 +00001030 default:
1031 return -EOPNOTSUPP;
1032 }
1033}
1034
Edward Creea7ad40d2016-02-05 11:16:50 +00001035static inline bool ip6_mask_is_full(__be32 mask[4])
1036{
1037 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1038}
1039
1040static inline bool ip6_mask_is_empty(__be32 mask[4])
1041{
1042 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1043}
1044
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001045static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1046 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001047{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001048 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1049 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +00001050 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1051 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1052 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1053 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1054 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1055 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001056 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1057 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1058 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001059 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001060
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001061 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +01001062 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001063 return -EINVAL;
1064
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001065 /* Range-check ring_cookie */
1066 if (rule->ring_cookie >= efx->n_rx_channels &&
1067 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001068 return -EINVAL;
1069
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001070 /* Check for unsupported extensions */
1071 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +01001072 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001073 rule->m_ext.data[1]))
1074 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001075
Ben Hutchings85740cdf2013-01-29 23:33:15 +00001076 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
1077 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001078 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +00001079 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001080
Ben Hutchings7c460d92012-10-27 00:33:28 +01001081 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001082 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +01001083 case UDP_V4_FLOW:
1084 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1085 EFX_FILTER_MATCH_IP_PROTO);
1086 spec.ether_type = htons(ETH_P_IP);
1087 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1088 IPPROTO_TCP : IPPROTO_UDP);
1089 if (ip_mask->ip4dst) {
1090 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1091 return -EINVAL;
1092 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1093 spec.loc_host[0] = ip_entry->ip4dst;
1094 }
1095 if (ip_mask->ip4src) {
1096 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1097 return -EINVAL;
1098 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1099 spec.rem_host[0] = ip_entry->ip4src;
1100 }
1101 if (ip_mask->pdst) {
1102 if (ip_mask->pdst != PORT_FULL_MASK)
1103 return -EINVAL;
1104 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1105 spec.loc_port = ip_entry->pdst;
1106 }
1107 if (ip_mask->psrc) {
1108 if (ip_mask->psrc != PORT_FULL_MASK)
1109 return -EINVAL;
1110 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1111 spec.rem_port = ip_entry->psrc;
1112 }
1113 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001114 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001115 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001116
Edward Creea7ad40d2016-02-05 11:16:50 +00001117 case TCP_V6_FLOW:
1118 case UDP_V6_FLOW:
1119 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1120 EFX_FILTER_MATCH_IP_PROTO);
1121 spec.ether_type = htons(ETH_P_IPV6);
1122 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1123 IPPROTO_TCP : IPPROTO_UDP);
1124 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1125 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1126 return -EINVAL;
1127 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1128 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1129 }
1130 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1131 if (!ip6_mask_is_full(ip6_mask->ip6src))
1132 return -EINVAL;
1133 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1134 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1135 }
1136 if (ip6_mask->pdst) {
1137 if (ip6_mask->pdst != PORT_FULL_MASK)
1138 return -EINVAL;
1139 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1140 spec.loc_port = ip6_entry->pdst;
1141 }
1142 if (ip6_mask->psrc) {
1143 if (ip6_mask->psrc != PORT_FULL_MASK)
1144 return -EINVAL;
1145 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1146 spec.rem_port = ip6_entry->psrc;
1147 }
1148 if (ip6_mask->tclass)
1149 return -EINVAL;
1150 break;
1151
1152 case IPV4_USER_FLOW:
1153 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1154 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1155 return -EINVAL;
1156 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1157 spec.ether_type = htons(ETH_P_IP);
1158 if (uip_mask->ip4dst) {
1159 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1160 return -EINVAL;
1161 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1162 spec.loc_host[0] = uip_entry->ip4dst;
1163 }
1164 if (uip_mask->ip4src) {
1165 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1166 return -EINVAL;
1167 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1168 spec.rem_host[0] = uip_entry->ip4src;
1169 }
1170 if (uip_mask->proto) {
1171 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1172 return -EINVAL;
1173 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1174 spec.ip_proto = uip_entry->proto;
1175 }
1176 break;
1177
1178 case IPV6_USER_FLOW:
1179 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1180 return -EINVAL;
1181 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1182 spec.ether_type = htons(ETH_P_IPV6);
1183 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1184 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1185 return -EINVAL;
1186 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1187 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1188 }
1189 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1190 if (!ip6_mask_is_full(uip6_mask->ip6src))
1191 return -EINVAL;
1192 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1193 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1194 }
1195 if (uip6_mask->l4_proto) {
1196 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1197 return -EINVAL;
1198 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1199 spec.ip_proto = uip6_entry->l4_proto;
1200 }
1201 break;
1202
Ben Hutchings7c460d92012-10-27 00:33:28 +01001203 case ETHER_FLOW:
1204 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1205 if (ether_addr_equal(mac_mask->h_dest,
1206 mac_addr_ig_mask))
1207 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1208 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1209 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +00001210 else
Ben Hutchings7c460d92012-10-27 00:33:28 +01001211 return -EINVAL;
Edward Creecd84ff42014-03-07 18:27:41 +00001212 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001213 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001214 if (!is_zero_ether_addr(mac_mask->h_source)) {
1215 if (!is_broadcast_ether_addr(mac_mask->h_source))
1216 return -EINVAL;
1217 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
Edward Creecd84ff42014-03-07 18:27:41 +00001218 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001219 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001220 if (mac_mask->h_proto) {
1221 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1222 return -EINVAL;
1223 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1224 spec.ether_type = mac_entry->h_proto;
1225 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001226 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001227
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001228 default:
1229 return -EINVAL;
1230 }
1231
Ben Hutchings7c460d92012-10-27 00:33:28 +01001232 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1233 if (rule->m_ext.vlan_tci != htons(0xfff))
1234 return -EINVAL;
1235 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1236 spec.outer_vid = rule->h_ext.vlan_tci;
1237 }
1238
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001239 rc = efx_filter_insert_filter(efx, &spec, true);
1240 if (rc < 0)
1241 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +01001242
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001243 rule->location = rc;
1244 return 0;
1245}
1246
1247static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1248 struct ethtool_rxnfc *info)
1249{
1250 struct efx_nic *efx = netdev_priv(net_dev);
1251
1252 if (efx_filter_get_rx_id_limit(efx) == 0)
1253 return -EOPNOTSUPP;
1254
1255 switch (info->cmd) {
1256 case ETHTOOL_SRXCLSRLINS:
1257 return efx_ethtool_set_class_rule(efx, &info->fs);
1258
1259 case ETHTOOL_SRXCLSRLDEL:
1260 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1261 info->fs.location);
1262
1263 default:
1264 return -EOPNOTSUPP;
1265 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001266}
1267
Ben Hutchings7850f632011-12-15 13:55:01 +00001268static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001269{
1270 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001271
Ben Hutchingscd2d5b52012-02-14 00:48:07 +00001272 return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 ||
1273 efx->n_rx_channels == 1) ?
Ben Hutchings7850f632011-12-15 13:55:01 +00001274 0 : ARRAY_SIZE(efx->rx_indir_table));
1275}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001276
Eyal Perry892311f2014-12-02 18:12:10 +02001277static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1278 u8 *hfunc)
Ben Hutchings7850f632011-12-15 13:55:01 +00001279{
1280 struct efx_nic *efx = netdev_priv(net_dev);
1281
Eyal Perry892311f2014-12-02 18:12:10 +02001282 if (hfunc)
1283 *hfunc = ETH_RSS_HASH_TOP;
1284 if (indir)
1285 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001286 return 0;
1287}
1288
Eyal Perry892311f2014-12-02 18:12:10 +02001289static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1290 const u8 *key, const u8 hfunc)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001291{
1292 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001293
Eyal Perry892311f2014-12-02 18:12:10 +02001294 /* We do not allow change in unsupported parameters */
1295 if (key ||
1296 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1297 return -EOPNOTSUPP;
1298 if (!indir)
1299 return 0;
Jon Cooper267c0152015-05-06 00:59:38 +01001300
1301 return efx->type->rx_push_rss_config(efx, true, indir);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001302}
1303
Fengguang Wub51ca342013-07-03 14:07:40 +08001304static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1305 struct ethtool_ts_info *ts_info)
Ben Hutchings62ebac92013-04-08 17:34:58 +01001306{
1307 struct efx_nic *efx = netdev_priv(net_dev);
1308
1309 /* Software capabilities */
1310 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1311 SOF_TIMESTAMPING_SOFTWARE);
1312 ts_info->phc_index = -1;
1313
1314 efx_ptp_get_ts_info(efx, ts_info);
1315 return 0;
1316}
1317
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001318static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1319 struct ethtool_eeprom *ee,
1320 u8 *data)
1321{
1322 struct efx_nic *efx = netdev_priv(net_dev);
1323 int ret;
1324
1325 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1326 return -EOPNOTSUPP;
1327
1328 mutex_lock(&efx->mac_lock);
1329 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1330 mutex_unlock(&efx->mac_lock);
1331
1332 return ret;
1333}
1334
1335static int efx_ethtool_get_module_info(struct net_device *net_dev,
1336 struct ethtool_modinfo *modinfo)
1337{
1338 struct efx_nic *efx = netdev_priv(net_dev);
1339 int ret;
1340
1341 if (!efx->phy_op || !efx->phy_op->get_module_info)
1342 return -EOPNOTSUPP;
1343
1344 mutex_lock(&efx->mac_lock);
1345 ret = efx->phy_op->get_module_info(efx, modinfo);
1346 mutex_unlock(&efx->mac_lock);
1347
1348 return ret;
1349}
1350
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001351const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001352 .get_settings = efx_ethtool_get_settings,
1353 .set_settings = efx_ethtool_set_settings,
1354 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001355 .get_regs_len = efx_ethtool_get_regs_len,
1356 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001357 .get_msglevel = efx_ethtool_get_msglevel,
1358 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001359 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001360 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001361 .get_coalesce = efx_ethtool_get_coalesce,
1362 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001363 .get_ringparam = efx_ethtool_get_ringparam,
1364 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001365 .get_pauseparam = efx_ethtool_get_pauseparam,
1366 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001367 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001368 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001369 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001370 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001371 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001372 .get_wol = efx_ethtool_get_wol,
1373 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001374 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001375 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001376 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001377 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001378 .get_rxfh = efx_ethtool_get_rxfh,
1379 .set_rxfh = efx_ethtool_set_rxfh,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001380 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001381 .get_module_info = efx_ethtool_get_module_info,
1382 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001383};