blob: f644216eda1b5c5d1d925cf8427c0e29c87c6616 [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),
Edward Cree46d1efd2016-11-17 10:52:36 +000072 EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks),
Ben Hutchings119226c2011-02-18 19:14:13 +000073 EFX_ETHTOOL_UINT_TXQ_STAT(pushes),
Jon Cooperee45fd92c2013-09-02 18:24:29 +010074 EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets),
Bert Kenwarde9117e52016-11-17 10:51:54 +000075 EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets),
Ben Hutchings8ceee662008-04-27 12:55:59 +010076 EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset),
77 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc),
78 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err),
79 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err),
Ben Hutchingsc1ac4032009-11-28 05:36:29 +000080 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
Ben Hutchings8ceee662008-04-27 12:55:59 +010081 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
Ben Hutchings8127d662013-08-29 19:19:29 +010082 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
83 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
Ben Hutchings8ceee662008-04-27 12:55:59 +010084};
85
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000086#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
Ben Hutchings8ceee662008-04-27 12:55:59 +010087
Ben Hutchings4a5b5042008-09-01 12:47:16 +010088#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +010089
Ben Hutchings8ceee662008-04-27 12:55:59 +010090/**************************************************************************
91 *
92 * Ethtool operations
93 *
94 **************************************************************************
95 */
96
97/* Identify device by flashing LEDs */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +010098static int efx_ethtool_phys_id(struct net_device *net_dev,
99 enum ethtool_phys_id_state state)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100100{
Ben Hutchings767e4682008-09-01 12:43:14 +0100101 struct efx_nic *efx = netdev_priv(net_dev);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000102 enum efx_led_mode mode = EFX_LED_DEFAULT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100103
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100104 switch (state) {
105 case ETHTOOL_ID_ON:
106 mode = EFX_LED_ON;
107 break;
108 case ETHTOOL_ID_OFF:
109 mode = EFX_LED_OFF;
110 break;
111 case ETHTOOL_ID_INACTIVE:
112 mode = EFX_LED_DEFAULT;
113 break;
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000114 case ETHTOOL_ID_ACTIVE:
115 return 1; /* cycle on/off once per second */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100116 }
Ben Hutchings398468e2009-11-23 16:03:45 +0000117
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100118 efx->type->set_id_led(efx, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100119 return 0;
120}
121
122/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000123static int efx_ethtool_get_settings(struct net_device *net_dev,
124 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100125{
Ben Hutchings767e4682008-09-01 12:43:14 +0100126 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000127 struct efx_link_state *link_state = &efx->link_state;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100128
129 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800130 efx->phy_op->get_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100131 mutex_unlock(&efx->mac_lock);
132
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000133 /* Both MACs support pause frames (bidirectional and respond-only) */
134 ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
135
136 if (LOOPBACK_INTERNAL(efx)) {
David Decotigny70739492011-04-27 18:32:40 +0000137 ethtool_cmd_speed_set(ecmd, link_state->speed);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000138 ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
139 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800140
141 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100142}
143
144/* This must be called with rtnl_lock held. */
stephen hemmingerd2156972010-10-18 05:27:31 +0000145static int efx_ethtool_set_settings(struct net_device *net_dev,
146 struct ethtool_cmd *ecmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100147{
Ben Hutchings767e4682008-09-01 12:43:14 +0100148 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100149 int rc;
150
Ben Hutchings754c6532010-02-03 09:31:57 +0000151 /* GMAC does not support 1000Mbps HD */
David Decotigny25db0332011-04-27 18:32:39 +0000152 if ((ethtool_cmd_speed(ecmd) == SPEED_1000) &&
153 (ecmd->duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000154 netif_dbg(efx, drv, efx->net_dev,
155 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800156 return -EINVAL;
157 }
158
Ben Hutchings8ceee662008-04-27 12:55:59 +0100159 mutex_lock(&efx->mac_lock);
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800160 rc = efx->phy_op->set_settings(efx, ecmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100161 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100162 return rc;
163}
164
165static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
166 struct ethtool_drvinfo *info)
167{
Ben Hutchings767e4682008-09-01 12:43:14 +0100168 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100169
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000170 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Edward Cree5a6681e2016-11-28 18:55:34 +0000172 efx_mcdi_print_fwver(efx, info->fw_version,
173 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100174 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
175}
176
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000177static int efx_ethtool_get_regs_len(struct net_device *net_dev)
178{
179 return efx_nic_get_regs_len(netdev_priv(net_dev));
180}
181
182static void efx_ethtool_get_regs(struct net_device *net_dev,
183 struct ethtool_regs *regs, void *buf)
184{
185 struct efx_nic *efx = netdev_priv(net_dev);
186
187 regs->version = efx->type->revision;
188 efx_nic_get_regs(efx, buf);
189}
190
Ben Hutchings62776d02010-06-23 11:30:07 +0000191static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
192{
193 struct efx_nic *efx = netdev_priv(net_dev);
194 return efx->msg_enable;
195}
196
197static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
198{
199 struct efx_nic *efx = netdev_priv(net_dev);
200 efx->msg_enable = msg_enable;
201}
202
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100203/**
204 * efx_fill_test - fill in an individual self-test entry
205 * @test_index: Index of the test
206 * @strings: Ethtool strings, or %NULL
207 * @data: Ethtool test results, or %NULL
208 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800209 * @unit_format: Unit name format (e.g. "chan\%d")
210 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100211 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800212 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100213 *
214 * Fill in an individual self-test entry.
215 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000216static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100217 int *test, const char *unit_format, int unit_id,
218 const char *test_format, const char *test_id)
219{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000220 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100221
222 /* Fill data value, if applicable */
223 if (data)
224 data[test_index] = *test;
225
226 /* Fill string, if applicable */
227 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800228 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000229 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800230 unit_format, unit_id);
231 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000232 strcpy(unit_str, unit_format);
233 snprintf(test_str, sizeof(test_str), test_format, test_id);
234 snprintf(strings + test_index * ETH_GSTRING_LEN,
235 ETH_GSTRING_LEN,
236 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100237 }
238}
239
Ben Hutchings740ced92008-12-12 21:41:55 -0800240#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100241#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
242#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
243#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000244 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100245
246/**
247 * efx_fill_loopback_test - fill in a block of loopback self-test entries
248 * @efx: Efx NIC
249 * @lb_tests: Efx loopback self-test results structure
250 * @mode: Loopback test mode
251 * @test_index: Starting index of the test
252 * @strings: Ethtool strings, or %NULL
253 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000254 *
255 * Fill in a block of loopback self-test entries. Return new test
256 * index.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100257 */
258static int efx_fill_loopback_test(struct efx_nic *efx,
259 struct efx_loopback_self_tests *lb_tests,
260 enum efx_loopback_mode mode,
261 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000262 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100263{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100264 struct efx_channel *channel =
265 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100266 struct efx_tx_queue *tx_queue;
267
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000268 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100269 efx_fill_test(test_index++, strings, data,
270 &lb_tests->tx_sent[tx_queue->queue],
271 EFX_TX_QUEUE_NAME(tx_queue),
272 EFX_LOOPBACK_NAME(mode, "tx_sent"));
273 efx_fill_test(test_index++, strings, data,
274 &lb_tests->tx_done[tx_queue->queue],
275 EFX_TX_QUEUE_NAME(tx_queue),
276 EFX_LOOPBACK_NAME(mode, "tx_done"));
277 }
278 efx_fill_test(test_index++, strings, data,
279 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800280 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100281 EFX_LOOPBACK_NAME(mode, "rx_good"));
282 efx_fill_test(test_index++, strings, data,
283 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800284 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100285 EFX_LOOPBACK_NAME(mode, "rx_bad"));
286
287 return test_index;
288}
289
290/**
291 * efx_ethtool_fill_self_tests - get self-test details
292 * @efx: Efx NIC
293 * @tests: Efx self-test results structure, or %NULL
294 * @strings: Ethtool strings, or %NULL
295 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000296 *
297 * Get self-test number of strings, strings, and/or test results.
298 * Return number of strings (== number of test results).
299 *
300 * The reason for merging these three functions is to make sure that
301 * they can never be inconsistent.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100302 */
303static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
304 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000305 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100306{
307 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800308 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100309 enum efx_loopback_mode mode;
310
Ben Hutchings4f16c072010-02-03 09:30:50 +0000311 efx_fill_test(n++, strings, data, &tests->phy_alive,
312 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100313 efx_fill_test(n++, strings, data, &tests->nvram,
314 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100315 efx_fill_test(n++, strings, data, &tests->interrupt,
316 "core", 0, "interrupt", NULL);
317
318 /* Event queues */
319 efx_for_each_channel(channel, efx) {
320 efx_fill_test(n++, strings, data,
321 &tests->eventq_dma[channel->channel],
322 EFX_CHANNEL_NAME(channel),
323 "eventq.dma", NULL);
324 efx_fill_test(n++, strings, data,
325 &tests->eventq_int[channel->channel],
326 EFX_CHANNEL_NAME(channel),
327 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100328 }
329
Jon Cooper74cd60a2013-09-16 14:18:51 +0100330 efx_fill_test(n++, strings, data, &tests->memory,
331 "core", 0, "memory", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100332 efx_fill_test(n++, strings, data, &tests->registers,
333 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800334
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000335 if (efx->phy_op->run_tests != NULL) {
Edward Creee01b16a2016-12-02 15:51:33 +0000336 EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000337
338 for (i = 0; true; ++i) {
339 const char *name;
340
Edward Creee01b16a2016-12-02 15:51:33 +0000341 EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000342 name = efx->phy_op->test_name(efx, i);
343 if (name == NULL)
344 break;
345
Ben Hutchings4f16c072010-02-03 09:30:50 +0000346 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000347 "phy", 0, name, NULL);
348 }
349 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100350
351 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100352 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100353 if (!(efx->loopback_modes & (1 << mode)))
354 continue;
355 n = efx_fill_loopback_test(efx,
356 &tests->loopback[mode], mode, n,
357 strings, data);
358 }
359
360 return n;
361}
362
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100363static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
364{
365 size_t n_stats = 0;
366 struct efx_channel *channel;
367
368 efx_for_each_channel(channel, efx) {
369 if (efx_channel_has_tx_queues(channel)) {
370 n_stats++;
371 if (strings != NULL) {
372 snprintf(strings, ETH_GSTRING_LEN,
373 "tx-%u.tx_packets",
374 channel->tx_queue[0].queue /
375 EFX_TXQ_TYPES);
376
377 strings += ETH_GSTRING_LEN;
378 }
379 }
380 }
381 efx_for_each_channel(channel, efx) {
382 if (efx_channel_has_rx_queue(channel)) {
383 n_stats++;
384 if (strings != NULL) {
385 snprintf(strings, ETH_GSTRING_LEN,
386 "rx-%d.rx_packets", channel->channel);
387 strings += ETH_GSTRING_LEN;
388 }
389 }
390 }
391 return n_stats;
392}
393
Ben Hutchings3594e132008-09-01 12:48:12 +0100394static int efx_ethtool_get_sset_count(struct net_device *net_dev,
395 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100396{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000397 struct efx_nic *efx = netdev_priv(net_dev);
398
Ben Hutchings3594e132008-09-01 12:48:12 +0100399 switch (string_set) {
400 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000401 return efx->type->describe_stats(efx, NULL) +
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100402 EFX_ETHTOOL_SW_STAT_COUNT +
403 efx_describe_per_queue_stats(efx, NULL) +
404 efx_ptp_describe_stats(efx, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100405 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000406 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100407 default:
408 return -EINVAL;
409 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100410}
411
Ben Hutchings8ceee662008-04-27 12:55:59 +0100412static void efx_ethtool_get_strings(struct net_device *net_dev,
413 u32 string_set, u8 *strings)
414{
Ben Hutchings767e4682008-09-01 12:43:14 +0100415 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100416 int i;
417
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100418 switch (string_set) {
419 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000420 strings += (efx->type->describe_stats(efx, strings) *
421 ETH_GSTRING_LEN);
422 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000423 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000424 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000425 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100426 strings += (efx_describe_per_queue_stats(efx, strings) *
427 ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000428 efx_ptp_describe_stats(efx, strings);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100429 break;
430 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000431 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100432 break;
433 default:
434 /* No other string sets */
435 break;
436 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100437}
438
439static void efx_ethtool_get_stats(struct net_device *net_dev,
440 struct ethtool_stats *stats,
441 u64 *data)
442{
Ben Hutchings767e4682008-09-01 12:43:14 +0100443 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000444 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100445 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000446 struct efx_tx_queue *tx_queue;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100447 struct efx_rx_queue *rx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100448 int i;
449
Ben Hutchings1cb34522011-09-02 23:23:00 +0100450 spin_lock_bh(&efx->stats_lock);
451
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000452 /* Get NIC statistics */
453 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100454
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000455 /* Get software statistics */
456 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
457 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100458 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100459 case EFX_ETHTOOL_STAT_SOURCE_nic:
460 data[i] = stat->get_stat((void *)efx + stat->offset);
461 break;
462 case EFX_ETHTOOL_STAT_SOURCE_channel:
463 data[i] = 0;
464 efx_for_each_channel(channel, efx)
465 data[i] += stat->get_stat((void *)channel +
466 stat->offset);
467 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000468 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
469 data[i] = 0;
470 efx_for_each_channel(channel, efx) {
471 efx_for_each_channel_tx_queue(tx_queue, channel)
472 data[i] +=
473 stat->get_stat((void *)tx_queue
474 + stat->offset);
475 }
476 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100477 }
478 }
Ben Hutchings99691c42013-12-11 02:36:08 +0000479 data += EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings1cb34522011-09-02 23:23:00 +0100480
481 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings99691c42013-12-11 02:36:08 +0000482
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100483 efx_for_each_channel(channel, efx) {
484 if (efx_channel_has_tx_queues(channel)) {
485 *data = 0;
486 efx_for_each_channel_tx_queue(tx_queue, channel) {
487 *data += tx_queue->tx_packets;
488 }
489 data++;
490 }
491 }
492 efx_for_each_channel(channel, efx) {
493 if (efx_channel_has_rx_queue(channel)) {
494 *data = 0;
495 efx_for_each_channel_rx_queue(rx_queue, channel) {
496 *data += rx_queue->rx_packets;
497 }
498 data++;
499 }
500 }
501
Ben Hutchings99691c42013-12-11 02:36:08 +0000502 efx_ptp_update_stats(efx, data);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100503}
504
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100505static void efx_ethtool_self_test(struct net_device *net_dev,
506 struct ethtool_test *test, u64 *data)
507{
Ben Hutchings767e4682008-09-01 12:43:14 +0100508 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000509 struct efx_self_tests *efx_tests;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000510 bool already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000511 int rc = -ENOMEM;
512
513 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
514 if (!efx_tests)
515 goto fail;
516
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100517 if (efx->state != STATE_READY) {
Ben Hutchings5eed1f62014-02-12 19:00:28 +0000518 rc = -EBUSY;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000519 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100520 }
521
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000522 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
523 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
524
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100525 /* We need rx buffers and interrupts. */
526 already_up = (efx->net_dev->flags & IFF_UP);
527 if (!already_up) {
528 rc = dev_open(efx->net_dev);
529 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000530 netif_err(efx, drv, efx->net_dev,
531 "failed opening device.\n");
Ben Hutchings17e678d2014-02-12 19:00:16 +0000532 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100533 }
534 }
535
Eric Dumazet28801f32011-02-16 03:48:38 +0000536 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100537
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100538 if (!already_up)
539 dev_close(efx->net_dev);
540
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000541 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
542 rc == 0 ? "passed" : "failed",
543 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100544
Ben Hutchings17e678d2014-02-12 19:00:16 +0000545out:
Eric Dumazet28801f32011-02-16 03:48:38 +0000546 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
547 kfree(efx_tests);
548fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100549 if (rc)
550 test->flags |= ETH_TEST_FL_FAILED;
551}
552
Ben Hutchings8ceee662008-04-27 12:55:59 +0100553/* Restart autonegotiation */
554static int efx_ethtool_nway_reset(struct net_device *net_dev)
555{
Ben Hutchings767e4682008-09-01 12:43:14 +0100556 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100557
Ben Hutchings68e7f452009-04-29 08:05:08 +0000558 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100559}
560
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000561/*
562 * Each channel has a single IRQ and moderation timer, started by any
563 * completion (or other event). Unless the module parameter
564 * separate_tx_channels is set, IRQs and moderation are therefore
565 * shared between RX and TX completions. In this case, when RX IRQ
566 * moderation is explicitly changed then TX IRQ moderation is
567 * automatically changed too, but otherwise we fail if the two values
568 * are requested to be different.
569 *
Ben Hutchings13225972011-09-05 07:43:49 +0000570 * The hardware does not support a limit on the number of completions
571 * before an IRQ, so we do not use the max_frames fields. We should
572 * report and require that max_frames == (usecs != 0), but this would
573 * invalidate existing user documentation.
574 *
575 * The hardware does not have distinct settings for interrupt
576 * moderation while the previous IRQ is being handled, so we should
577 * not use the 'irq' fields. However, an earlier developer
578 * misunderstood the meaning of the 'irq' fields and the driver did
579 * not support the standard fields. To avoid invalidating existing
580 * user documentation, we report and accept changes through either the
581 * standard or 'irq' fields. If both are changed at the same time, we
582 * prefer the standard field.
583 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000584 * We implement adaptive IRQ moderation, but use a different algorithm
585 * from that assumed in the definition of struct ethtool_coalesce.
586 * Therefore we do not use any of the adaptive moderation parameters
587 * in it.
588 */
589
Ben Hutchings8ceee662008-04-27 12:55:59 +0100590static int efx_ethtool_get_coalesce(struct net_device *net_dev,
591 struct ethtool_coalesce *coalesce)
592{
Ben Hutchings767e4682008-09-01 12:43:14 +0100593 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000594 unsigned int tx_usecs, rx_usecs;
595 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100596
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000597 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100598
Ben Hutchings13225972011-09-05 07:43:49 +0000599 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000600 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000601 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000602 coalesce->rx_coalesce_usecs_irq = rx_usecs;
603 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000604
Ben Hutchings8ceee662008-04-27 12:55:59 +0100605 return 0;
606}
607
Ben Hutchings8ceee662008-04-27 12:55:59 +0100608static int efx_ethtool_set_coalesce(struct net_device *net_dev,
609 struct ethtool_coalesce *coalesce)
610{
Ben Hutchings767e4682008-09-01 12:43:14 +0100611 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100612 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000613 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000614 bool adaptive, rx_may_override_tx;
615 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100616
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000617 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000618 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100619
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000620 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
621
Ben Hutchings13225972011-09-05 07:43:49 +0000622 if (coalesce->rx_coalesce_usecs != rx_usecs)
623 rx_usecs = coalesce->rx_coalesce_usecs;
624 else
625 rx_usecs = coalesce->rx_coalesce_usecs_irq;
626
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000627 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100628
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000629 /* If channels are shared, TX IRQ moderation can be quietly
630 * overridden unless it is changed from its old value.
631 */
Ben Hutchings13225972011-09-05 07:43:49 +0000632 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
633 coalesce->tx_coalesce_usecs_irq == tx_usecs);
634 if (coalesce->tx_coalesce_usecs != tx_usecs)
635 tx_usecs = coalesce->tx_coalesce_usecs;
636 else
637 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100638
Ben Hutchings9e393b32011-09-05 07:43:04 +0000639 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
640 rx_may_override_tx);
641 if (rc != 0)
642 return rc;
643
Ben Hutchings8ceee662008-04-27 12:55:59 +0100644 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000645 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100646
647 return 0;
648}
649
Ben Hutchings46426102010-09-10 06:42:33 +0000650static void efx_ethtool_get_ringparam(struct net_device *net_dev,
651 struct ethtool_ringparam *ring)
652{
653 struct efx_nic *efx = netdev_priv(net_dev);
654
655 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000656 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000657 ring->rx_pending = efx->rxq_entries;
658 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000659}
660
661static int efx_ethtool_set_ringparam(struct net_device *net_dev,
662 struct ethtool_ringparam *ring)
663{
664 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000665 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000666
667 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
668 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000669 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
Ben Hutchings46426102010-09-10 06:42:33 +0000670 return -EINVAL;
671
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000672 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000673 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000674 "RX queues cannot be smaller than %u\n",
675 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000676 return -EINVAL;
677 }
678
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000679 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
680 if (txq_entries != ring->tx_pending)
681 netif_warn(efx, drv, efx->net_dev,
682 "increasing TX queue size to minimum of %u\n",
683 txq_entries);
684
685 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000686}
687
Ben Hutchings8ceee662008-04-27 12:55:59 +0100688static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
689 struct ethtool_pauseparam *pause)
690{
Ben Hutchings767e4682008-09-01 12:43:14 +0100691 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb56269462011-05-17 17:53:22 -0400692 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000693 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000694 int rc = 0;
695
696 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100697
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800698 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
699 (pause->tx_pause ? EFX_FC_TX : 0) |
700 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100701
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800702 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000703 netif_dbg(efx, drv, efx->net_dev,
704 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000705 rc = -EINVAL;
706 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800707 }
708
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000709 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000710 netif_dbg(efx, drv, efx->net_dev,
711 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000712 rc = -EINVAL;
713 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800714 }
715
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100716 /* Hook for Falcon bug 11482 workaround */
717 if (efx->type->prepare_enable_fc_tx &&
718 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
719 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800720
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000721 old_adv = efx->link_advertising;
722 old_fc = efx->wanted_fc;
723 efx_link_set_wanted_fc(efx, wanted_fc);
724 if (efx->link_advertising != old_adv ||
725 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
726 rc = efx->phy_op->reconfigure(efx);
727 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000728 netif_err(efx, drv, efx->net_dev,
729 "Unable to advertise requested flow "
730 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000731 goto out;
732 }
733 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800734
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000735 /* Reconfigure the MAC. The PHY *may* generate a link state change event
736 * if the user just changed the advertised capabilities, but there's no
737 * harm doing this twice */
Edward Cree0d322412015-05-20 11:10:03 +0100738 efx_mac_reconfigure(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800739
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000740out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800741 mutex_unlock(&efx->mac_lock);
742
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000743 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100744}
745
746static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
747 struct ethtool_pauseparam *pause)
748{
Ben Hutchings767e4682008-09-01 12:43:14 +0100749 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100750
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800751 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
752 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
753 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100754}
755
Ben Hutchings89c758f2009-11-29 03:43:07 +0000756static void efx_ethtool_get_wol(struct net_device *net_dev,
757 struct ethtool_wolinfo *wol)
758{
759 struct efx_nic *efx = netdev_priv(net_dev);
760 return efx->type->get_wol(efx, wol);
761}
762
763
764static int efx_ethtool_set_wol(struct net_device *net_dev,
765 struct ethtool_wolinfo *wol)
766{
767 struct efx_nic *efx = netdev_priv(net_dev);
768 return efx->type->set_wol(efx, wol->wolopts);
769}
770
stephen hemmingerd2156972010-10-18 05:27:31 +0000771static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000772{
773 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100774 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000775
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100776 rc = efx->type->map_reset_flags(flags);
777 if (rc < 0)
778 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000779
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100780 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000781}
782
Ben Hutchings7c460d92012-10-27 00:33:28 +0100783/* MAC address mask including only I/G bit */
Edward Creecd84ff42014-03-07 18:27:41 +0000784static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
Ben Hutchingsc274d652012-02-02 22:41:49 +0000785
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100786#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
Edward Creea7ad40d2016-02-05 11:16:50 +0000787#define IP_PROTO_FULL_MASK 0xFF
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100788#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100789#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100790
Edward Creea7ad40d2016-02-05 11:16:50 +0000791static inline void ip6_fill_mask(__be32 *mask)
792{
793 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
794}
795
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000796static int efx_ethtool_get_class_rule(struct efx_nic *efx,
797 struct ethtool_rx_flow_spec *rule)
798{
799 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
800 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +0000801 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
802 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
803 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
804 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
805 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
806 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000807 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
808 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000809 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000810 int rc;
811
812 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
813 rule->location, &spec);
814 if (rc)
815 return rc;
816
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000817 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000818 rule->ring_cookie = RX_CLS_FLOW_DISC;
819 else
820 rule->ring_cookie = spec.dmaq_id;
821
Ben Hutchings7c460d92012-10-27 00:33:28 +0100822 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
823 spec.ether_type == htons(ETH_P_IP) &&
824 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
825 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
826 !(spec.match_flags &
827 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
828 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
829 EFX_FILTER_MATCH_IP_PROTO |
830 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
831 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
832 TCP_V4_FLOW : UDP_V4_FLOW);
833 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
834 ip_entry->ip4dst = spec.loc_host[0];
835 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000836 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100837 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
838 ip_entry->ip4src = spec.rem_host[0];
839 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
840 }
841 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
842 ip_entry->pdst = spec.loc_port;
843 ip_mask->pdst = PORT_FULL_MASK;
844 }
845 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
846 ip_entry->psrc = spec.rem_port;
847 ip_mask->psrc = PORT_FULL_MASK;
848 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000849 } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
850 spec.ether_type == htons(ETH_P_IPV6) &&
851 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
852 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
853 !(spec.match_flags &
854 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
855 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
856 EFX_FILTER_MATCH_IP_PROTO |
857 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
858 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
859 TCP_V6_FLOW : UDP_V6_FLOW);
860 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
861 memcpy(ip6_entry->ip6dst, spec.loc_host,
862 sizeof(ip6_entry->ip6dst));
863 ip6_fill_mask(ip6_mask->ip6dst);
864 }
865 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
866 memcpy(ip6_entry->ip6src, spec.rem_host,
867 sizeof(ip6_entry->ip6src));
868 ip6_fill_mask(ip6_mask->ip6src);
869 }
870 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
871 ip6_entry->pdst = spec.loc_port;
872 ip6_mask->pdst = PORT_FULL_MASK;
873 }
874 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
875 ip6_entry->psrc = spec.rem_port;
876 ip6_mask->psrc = PORT_FULL_MASK;
877 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100878 } else if (!(spec.match_flags &
879 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
880 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
881 EFX_FILTER_MATCH_OUTER_VID))) {
882 rule->flow_type = ETHER_FLOW;
883 if (spec.match_flags &
884 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
Edward Creecd84ff42014-03-07 18:27:41 +0000885 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100886 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
Edward Creecd84ff42014-03-07 18:27:41 +0000887 eth_broadcast_addr(mac_mask->h_dest);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100888 else
Edward Creecd84ff42014-03-07 18:27:41 +0000889 ether_addr_copy(mac_mask->h_dest,
890 mac_addr_ig_mask);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100891 }
892 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
Edward Creecd84ff42014-03-07 18:27:41 +0000893 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
894 eth_broadcast_addr(mac_mask->h_source);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100895 }
896 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
897 mac_entry->h_proto = spec.ether_type;
898 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
899 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000900 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
901 spec.ether_type == htons(ETH_P_IP) &&
902 !(spec.match_flags &
903 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
904 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
905 EFX_FILTER_MATCH_IP_PROTO))) {
906 rule->flow_type = IPV4_USER_FLOW;
907 uip_entry->ip_ver = ETH_RX_NFC_IP4;
908 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
909 uip_mask->proto = IP_PROTO_FULL_MASK;
910 uip_entry->proto = spec.ip_proto;
911 }
912 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
913 uip_entry->ip4dst = spec.loc_host[0];
914 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
915 }
916 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
917 uip_entry->ip4src = spec.rem_host[0];
918 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
919 }
920 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
921 spec.ether_type == htons(ETH_P_IPV6) &&
922 !(spec.match_flags &
923 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
924 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
925 EFX_FILTER_MATCH_IP_PROTO))) {
926 rule->flow_type = IPV6_USER_FLOW;
927 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
928 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
929 uip6_entry->l4_proto = spec.ip_proto;
930 }
931 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
932 memcpy(uip6_entry->ip6dst, spec.loc_host,
933 sizeof(uip6_entry->ip6dst));
934 ip6_fill_mask(uip6_mask->ip6dst);
935 }
936 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
937 memcpy(uip6_entry->ip6src, spec.rem_host,
938 sizeof(uip6_entry->ip6src));
939 ip6_fill_mask(uip6_mask->ip6src);
940 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100941 } else {
942 /* The above should handle all filters that we insert */
943 WARN_ON(1);
944 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000945 }
946
Ben Hutchings7c460d92012-10-27 00:33:28 +0100947 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
948 rule->flow_type |= FLOW_EXT;
949 rule->h_ext.vlan_tci = spec.outer_vid;
950 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000951 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100952
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000953 return rc;
954}
955
Ben Hutchings765c9f42010-06-30 05:06:28 +0000956static int
957efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000958 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000959{
960 struct efx_nic *efx = netdev_priv(net_dev);
961
962 switch (info->cmd) {
963 case ETHTOOL_GRXRINGS:
964 info->data = efx->n_rx_channels;
965 return 0;
966
967 case ETHTOOL_GRXFH: {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000968 info->data = 0;
969 switch (info->flow_type) {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000970 case UDP_V4_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000971 if (efx->rx_hash_udp_4tuple)
972 /* fall through */
973 case TCP_V4_FLOW:
974 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
975 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000976 case SCTP_V4_FLOW:
977 case AH_ESP_V4_FLOW:
978 case IPV4_FLOW:
979 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000980 break;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000981 case UDP_V6_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000982 if (efx->rx_hash_udp_4tuple)
983 /* fall through */
984 case TCP_V6_FLOW:
985 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
986 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000987 case SCTP_V6_FLOW:
988 case AH_ESP_V6_FLOW:
989 case IPV6_FLOW:
990 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000991 break;
992 default:
993 break;
994 }
Ben Hutchings765c9f42010-06-30 05:06:28 +0000995 return 0;
996 }
997
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000998 case ETHTOOL_GRXCLSRLCNT:
999 info->data = efx_filter_get_rx_id_limit(efx);
1000 if (info->data == 0)
1001 return -EOPNOTSUPP;
1002 info->data |= RX_CLS_LOC_SPECIAL;
1003 info->rule_cnt =
1004 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1005 return 0;
1006
1007 case ETHTOOL_GRXCLSRULE:
1008 if (efx_filter_get_rx_id_limit(efx) == 0)
1009 return -EOPNOTSUPP;
1010 return efx_ethtool_get_class_rule(efx, &info->fs);
1011
1012 case ETHTOOL_GRXCLSRLALL: {
1013 s32 rc;
1014 info->data = efx_filter_get_rx_id_limit(efx);
1015 if (info->data == 0)
1016 return -EOPNOTSUPP;
1017 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1018 rule_locs, info->rule_cnt);
1019 if (rc < 0)
1020 return rc;
1021 info->rule_cnt = rc;
1022 return 0;
1023 }
1024
Ben Hutchings765c9f42010-06-30 05:06:28 +00001025 default:
1026 return -EOPNOTSUPP;
1027 }
1028}
1029
Edward Creea7ad40d2016-02-05 11:16:50 +00001030static inline bool ip6_mask_is_full(__be32 mask[4])
1031{
1032 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1033}
1034
1035static inline bool ip6_mask_is_empty(__be32 mask[4])
1036{
1037 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1038}
1039
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001040static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1041 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001042{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001043 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1044 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +00001045 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1046 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1047 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1048 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1049 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1050 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001051 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1052 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1053 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001054 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001055
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001056 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +01001057 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001058 return -EINVAL;
1059
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001060 /* Range-check ring_cookie */
1061 if (rule->ring_cookie >= efx->n_rx_channels &&
1062 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001063 return -EINVAL;
1064
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001065 /* Check for unsupported extensions */
1066 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +01001067 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001068 rule->m_ext.data[1]))
1069 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001070
Ben Hutchings85740cdf2013-01-29 23:33:15 +00001071 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
1072 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001073 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +00001074 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001075
Ben Hutchings7c460d92012-10-27 00:33:28 +01001076 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001077 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +01001078 case UDP_V4_FLOW:
1079 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1080 EFX_FILTER_MATCH_IP_PROTO);
1081 spec.ether_type = htons(ETH_P_IP);
1082 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1083 IPPROTO_TCP : IPPROTO_UDP);
1084 if (ip_mask->ip4dst) {
1085 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1086 return -EINVAL;
1087 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1088 spec.loc_host[0] = ip_entry->ip4dst;
1089 }
1090 if (ip_mask->ip4src) {
1091 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1092 return -EINVAL;
1093 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1094 spec.rem_host[0] = ip_entry->ip4src;
1095 }
1096 if (ip_mask->pdst) {
1097 if (ip_mask->pdst != PORT_FULL_MASK)
1098 return -EINVAL;
1099 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1100 spec.loc_port = ip_entry->pdst;
1101 }
1102 if (ip_mask->psrc) {
1103 if (ip_mask->psrc != PORT_FULL_MASK)
1104 return -EINVAL;
1105 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1106 spec.rem_port = ip_entry->psrc;
1107 }
1108 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001109 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001110 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001111
Edward Creea7ad40d2016-02-05 11:16:50 +00001112 case TCP_V6_FLOW:
1113 case UDP_V6_FLOW:
1114 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1115 EFX_FILTER_MATCH_IP_PROTO);
1116 spec.ether_type = htons(ETH_P_IPV6);
1117 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1118 IPPROTO_TCP : IPPROTO_UDP);
1119 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1120 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1121 return -EINVAL;
1122 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1123 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1124 }
1125 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1126 if (!ip6_mask_is_full(ip6_mask->ip6src))
1127 return -EINVAL;
1128 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1129 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1130 }
1131 if (ip6_mask->pdst) {
1132 if (ip6_mask->pdst != PORT_FULL_MASK)
1133 return -EINVAL;
1134 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1135 spec.loc_port = ip6_entry->pdst;
1136 }
1137 if (ip6_mask->psrc) {
1138 if (ip6_mask->psrc != PORT_FULL_MASK)
1139 return -EINVAL;
1140 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1141 spec.rem_port = ip6_entry->psrc;
1142 }
1143 if (ip6_mask->tclass)
1144 return -EINVAL;
1145 break;
1146
1147 case IPV4_USER_FLOW:
1148 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1149 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1150 return -EINVAL;
1151 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1152 spec.ether_type = htons(ETH_P_IP);
1153 if (uip_mask->ip4dst) {
1154 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1155 return -EINVAL;
1156 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1157 spec.loc_host[0] = uip_entry->ip4dst;
1158 }
1159 if (uip_mask->ip4src) {
1160 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1161 return -EINVAL;
1162 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1163 spec.rem_host[0] = uip_entry->ip4src;
1164 }
1165 if (uip_mask->proto) {
1166 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1167 return -EINVAL;
1168 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1169 spec.ip_proto = uip_entry->proto;
1170 }
1171 break;
1172
1173 case IPV6_USER_FLOW:
1174 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1175 return -EINVAL;
1176 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1177 spec.ether_type = htons(ETH_P_IPV6);
1178 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1179 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1180 return -EINVAL;
1181 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1182 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1183 }
1184 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1185 if (!ip6_mask_is_full(uip6_mask->ip6src))
1186 return -EINVAL;
1187 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1188 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1189 }
1190 if (uip6_mask->l4_proto) {
1191 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1192 return -EINVAL;
1193 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1194 spec.ip_proto = uip6_entry->l4_proto;
1195 }
1196 break;
1197
Ben Hutchings7c460d92012-10-27 00:33:28 +01001198 case ETHER_FLOW:
1199 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1200 if (ether_addr_equal(mac_mask->h_dest,
1201 mac_addr_ig_mask))
1202 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1203 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1204 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +00001205 else
Ben Hutchings7c460d92012-10-27 00:33:28 +01001206 return -EINVAL;
Edward Creecd84ff42014-03-07 18:27:41 +00001207 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001208 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001209 if (!is_zero_ether_addr(mac_mask->h_source)) {
1210 if (!is_broadcast_ether_addr(mac_mask->h_source))
1211 return -EINVAL;
1212 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
Edward Creecd84ff42014-03-07 18:27:41 +00001213 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001214 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001215 if (mac_mask->h_proto) {
1216 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1217 return -EINVAL;
1218 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1219 spec.ether_type = mac_entry->h_proto;
1220 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001221 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001222
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001223 default:
1224 return -EINVAL;
1225 }
1226
Ben Hutchings7c460d92012-10-27 00:33:28 +01001227 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1228 if (rule->m_ext.vlan_tci != htons(0xfff))
1229 return -EINVAL;
1230 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1231 spec.outer_vid = rule->h_ext.vlan_tci;
1232 }
1233
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001234 rc = efx_filter_insert_filter(efx, &spec, true);
1235 if (rc < 0)
1236 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +01001237
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001238 rule->location = rc;
1239 return 0;
1240}
1241
1242static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1243 struct ethtool_rxnfc *info)
1244{
1245 struct efx_nic *efx = netdev_priv(net_dev);
1246
1247 if (efx_filter_get_rx_id_limit(efx) == 0)
1248 return -EOPNOTSUPP;
1249
1250 switch (info->cmd) {
1251 case ETHTOOL_SRXCLSRLINS:
1252 return efx_ethtool_set_class_rule(efx, &info->fs);
1253
1254 case ETHTOOL_SRXCLSRLDEL:
1255 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1256 info->fs.location);
1257
1258 default:
1259 return -EOPNOTSUPP;
1260 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001261}
1262
Ben Hutchings7850f632011-12-15 13:55:01 +00001263static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001264{
1265 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001266
Edward Cree5a6681e2016-11-28 18:55:34 +00001267 return (efx->n_rx_channels == 1) ? 0 : ARRAY_SIZE(efx->rx_indir_table);
Ben Hutchings7850f632011-12-15 13:55:01 +00001268}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001269
Eyal Perry892311f2014-12-02 18:12:10 +02001270static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1271 u8 *hfunc)
Ben Hutchings7850f632011-12-15 13:55:01 +00001272{
1273 struct efx_nic *efx = netdev_priv(net_dev);
1274
Eyal Perry892311f2014-12-02 18:12:10 +02001275 if (hfunc)
1276 *hfunc = ETH_RSS_HASH_TOP;
1277 if (indir)
1278 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001279 return 0;
1280}
1281
Eyal Perry892311f2014-12-02 18:12:10 +02001282static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1283 const u8 *key, const u8 hfunc)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001284{
1285 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001286
Eyal Perry892311f2014-12-02 18:12:10 +02001287 /* We do not allow change in unsupported parameters */
1288 if (key ||
1289 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1290 return -EOPNOTSUPP;
1291 if (!indir)
1292 return 0;
Jon Cooper267c0152015-05-06 00:59:38 +01001293
1294 return efx->type->rx_push_rss_config(efx, true, indir);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001295}
1296
Fengguang Wub51ca342013-07-03 14:07:40 +08001297static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1298 struct ethtool_ts_info *ts_info)
Ben Hutchings62ebac92013-04-08 17:34:58 +01001299{
1300 struct efx_nic *efx = netdev_priv(net_dev);
1301
1302 /* Software capabilities */
1303 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1304 SOF_TIMESTAMPING_SOFTWARE);
1305 ts_info->phc_index = -1;
1306
1307 efx_ptp_get_ts_info(efx, ts_info);
1308 return 0;
1309}
1310
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001311static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1312 struct ethtool_eeprom *ee,
1313 u8 *data)
1314{
1315 struct efx_nic *efx = netdev_priv(net_dev);
1316 int ret;
1317
1318 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1319 return -EOPNOTSUPP;
1320
1321 mutex_lock(&efx->mac_lock);
1322 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1323 mutex_unlock(&efx->mac_lock);
1324
1325 return ret;
1326}
1327
1328static int efx_ethtool_get_module_info(struct net_device *net_dev,
1329 struct ethtool_modinfo *modinfo)
1330{
1331 struct efx_nic *efx = netdev_priv(net_dev);
1332 int ret;
1333
1334 if (!efx->phy_op || !efx->phy_op->get_module_info)
1335 return -EOPNOTSUPP;
1336
1337 mutex_lock(&efx->mac_lock);
1338 ret = efx->phy_op->get_module_info(efx, modinfo);
1339 mutex_unlock(&efx->mac_lock);
1340
1341 return ret;
1342}
1343
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001344const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001345 .get_settings = efx_ethtool_get_settings,
1346 .set_settings = efx_ethtool_set_settings,
1347 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001348 .get_regs_len = efx_ethtool_get_regs_len,
1349 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001350 .get_msglevel = efx_ethtool_get_msglevel,
1351 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001352 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001353 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001354 .get_coalesce = efx_ethtool_get_coalesce,
1355 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001356 .get_ringparam = efx_ethtool_get_ringparam,
1357 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001358 .get_pauseparam = efx_ethtool_get_pauseparam,
1359 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001360 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001361 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001362 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001363 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001364 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001365 .get_wol = efx_ethtool_get_wol,
1366 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001367 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001368 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001369 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001370 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001371 .get_rxfh = efx_ethtool_get_rxfh,
1372 .set_rxfh = efx_ethtool_set_rxfh,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001373 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001374 .get_module_info = efx_ethtool_get_module_info,
1375 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001376};