blob: 3747b564411073350c930305c941df8e713edd8c [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),
Jon Coopera0ee3542017-02-08 16:50:40 +000080 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err),
81 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err),
82 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err),
83 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err),
84 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err),
Ben Hutchingsc1ac4032009-11-28 05:36:29 +000085 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch),
Ben Hutchings8ceee662008-04-27 12:55:59 +010086 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc),
Ben Hutchings8127d662013-08-29 19:19:29 +010087 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events),
88 EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets),
Ben Hutchings8ceee662008-04-27 12:55:59 +010089};
90
Ben Hutchingscd0ecc92012-12-14 21:52:56 +000091#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc)
Ben Hutchings8ceee662008-04-27 12:55:59 +010092
Ben Hutchings4a5b5042008-09-01 12:47:16 +010093#define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
Ben Hutchings4a5b5042008-09-01 12:47:16 +010094
Ben Hutchings8ceee662008-04-27 12:55:59 +010095/**************************************************************************
96 *
97 * Ethtool operations
98 *
99 **************************************************************************
100 */
101
102/* Identify device by flashing LEDs */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100103static int efx_ethtool_phys_id(struct net_device *net_dev,
104 enum ethtool_phys_id_state state)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100105{
Ben Hutchings767e4682008-09-01 12:43:14 +0100106 struct efx_nic *efx = netdev_priv(net_dev);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000107 enum efx_led_mode mode = EFX_LED_DEFAULT;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100108
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100109 switch (state) {
110 case ETHTOOL_ID_ON:
111 mode = EFX_LED_ON;
112 break;
113 case ETHTOOL_ID_OFF:
114 mode = EFX_LED_OFF;
115 break;
116 case ETHTOOL_ID_INACTIVE:
117 mode = EFX_LED_DEFAULT;
118 break;
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000119 case ETHTOOL_ID_ACTIVE:
120 return 1; /* cycle on/off once per second */
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100121 }
Ben Hutchings398468e2009-11-23 16:03:45 +0000122
Ben Hutchingsc5e129a2011-04-02 00:43:46 +0100123 efx->type->set_id_led(efx, mode);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100124 return 0;
125}
126
127/* This must be called with rtnl_lock held. */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100128static int
129efx_ethtool_get_link_ksettings(struct net_device *net_dev,
130 struct ethtool_link_ksettings *cmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100131{
Ben Hutchings767e4682008-09-01 12:43:14 +0100132 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000133 struct efx_link_state *link_state = &efx->link_state;
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100134 u32 supported;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100135
136 mutex_lock(&efx->mac_lock);
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100137 efx->phy_op->get_link_ksettings(efx, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100138 mutex_unlock(&efx->mac_lock);
139
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000140 /* Both MACs support pause frames (bidirectional and respond-only) */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100141 ethtool_convert_link_mode_to_legacy_u32(&supported,
142 cmd->link_modes.supported);
143
144 supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
145
146 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
147 supported);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000148
149 if (LOOPBACK_INTERNAL(efx)) {
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100150 cmd->base.speed = link_state->speed;
151 cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000152 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800153
154 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100155}
156
157/* This must be called with rtnl_lock held. */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100158static int
159efx_ethtool_set_link_ksettings(struct net_device *net_dev,
160 const struct ethtool_link_ksettings *cmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100161{
Ben Hutchings767e4682008-09-01 12:43:14 +0100162 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100163 int rc;
164
Ben Hutchings754c6532010-02-03 09:31:57 +0000165 /* GMAC does not support 1000Mbps HD */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100166 if ((cmd->base.speed == SPEED_1000) &&
167 (cmd->base.duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000168 netif_dbg(efx, drv, efx->net_dev,
169 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800170 return -EINVAL;
171 }
172
Ben Hutchings8ceee662008-04-27 12:55:59 +0100173 mutex_lock(&efx->mac_lock);
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100174 rc = efx->phy_op->set_link_ksettings(efx, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100175 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100176 return rc;
177}
178
179static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
180 struct ethtool_drvinfo *info)
181{
Ben Hutchings767e4682008-09-01 12:43:14 +0100182 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100183
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000184 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100185 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Edward Cree5a6681e2016-11-28 18:55:34 +0000186 efx_mcdi_print_fwver(efx, info->fw_version,
187 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100188 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
189}
190
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000191static int efx_ethtool_get_regs_len(struct net_device *net_dev)
192{
193 return efx_nic_get_regs_len(netdev_priv(net_dev));
194}
195
196static void efx_ethtool_get_regs(struct net_device *net_dev,
197 struct ethtool_regs *regs, void *buf)
198{
199 struct efx_nic *efx = netdev_priv(net_dev);
200
201 regs->version = efx->type->revision;
202 efx_nic_get_regs(efx, buf);
203}
204
Ben Hutchings62776d02010-06-23 11:30:07 +0000205static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
206{
207 struct efx_nic *efx = netdev_priv(net_dev);
208 return efx->msg_enable;
209}
210
211static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
212{
213 struct efx_nic *efx = netdev_priv(net_dev);
214 efx->msg_enable = msg_enable;
215}
216
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100217/**
218 * efx_fill_test - fill in an individual self-test entry
219 * @test_index: Index of the test
220 * @strings: Ethtool strings, or %NULL
221 * @data: Ethtool test results, or %NULL
222 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800223 * @unit_format: Unit name format (e.g. "chan\%d")
224 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100225 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800226 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100227 *
228 * Fill in an individual self-test entry.
229 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000230static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100231 int *test, const char *unit_format, int unit_id,
232 const char *test_format, const char *test_id)
233{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000234 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100235
236 /* Fill data value, if applicable */
237 if (data)
238 data[test_index] = *test;
239
240 /* Fill string, if applicable */
241 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800242 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000243 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800244 unit_format, unit_id);
245 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000246 strcpy(unit_str, unit_format);
247 snprintf(test_str, sizeof(test_str), test_format, test_id);
248 snprintf(strings + test_index * ETH_GSTRING_LEN,
249 ETH_GSTRING_LEN,
250 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100251 }
252}
253
Ben Hutchings740ced92008-12-12 21:41:55 -0800254#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100255#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
256#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
257#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000258 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100259
260/**
261 * efx_fill_loopback_test - fill in a block of loopback self-test entries
262 * @efx: Efx NIC
263 * @lb_tests: Efx loopback self-test results structure
264 * @mode: Loopback test mode
265 * @test_index: Starting index of the test
266 * @strings: Ethtool strings, or %NULL
267 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000268 *
269 * Fill in a block of loopback self-test entries. Return new test
270 * index.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100271 */
272static int efx_fill_loopback_test(struct efx_nic *efx,
273 struct efx_loopback_self_tests *lb_tests,
274 enum efx_loopback_mode mode,
275 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000276 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100277{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100278 struct efx_channel *channel =
279 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100280 struct efx_tx_queue *tx_queue;
281
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000282 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100283 efx_fill_test(test_index++, strings, data,
284 &lb_tests->tx_sent[tx_queue->queue],
285 EFX_TX_QUEUE_NAME(tx_queue),
286 EFX_LOOPBACK_NAME(mode, "tx_sent"));
287 efx_fill_test(test_index++, strings, data,
288 &lb_tests->tx_done[tx_queue->queue],
289 EFX_TX_QUEUE_NAME(tx_queue),
290 EFX_LOOPBACK_NAME(mode, "tx_done"));
291 }
292 efx_fill_test(test_index++, strings, data,
293 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800294 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100295 EFX_LOOPBACK_NAME(mode, "rx_good"));
296 efx_fill_test(test_index++, strings, data,
297 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800298 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100299 EFX_LOOPBACK_NAME(mode, "rx_bad"));
300
301 return test_index;
302}
303
304/**
305 * efx_ethtool_fill_self_tests - get self-test details
306 * @efx: Efx NIC
307 * @tests: Efx self-test results structure, or %NULL
308 * @strings: Ethtool strings, or %NULL
309 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000310 *
311 * Get self-test number of strings, strings, and/or test results.
312 * Return number of strings (== number of test results).
313 *
314 * The reason for merging these three functions is to make sure that
315 * they can never be inconsistent.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100316 */
317static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
318 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000319 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100320{
321 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800322 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100323 enum efx_loopback_mode mode;
324
Ben Hutchings4f16c072010-02-03 09:30:50 +0000325 efx_fill_test(n++, strings, data, &tests->phy_alive,
326 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100327 efx_fill_test(n++, strings, data, &tests->nvram,
328 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100329 efx_fill_test(n++, strings, data, &tests->interrupt,
330 "core", 0, "interrupt", NULL);
331
332 /* Event queues */
333 efx_for_each_channel(channel, efx) {
334 efx_fill_test(n++, strings, data,
335 &tests->eventq_dma[channel->channel],
336 EFX_CHANNEL_NAME(channel),
337 "eventq.dma", NULL);
338 efx_fill_test(n++, strings, data,
339 &tests->eventq_int[channel->channel],
340 EFX_CHANNEL_NAME(channel),
341 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100342 }
343
Jon Cooper74cd60a2013-09-16 14:18:51 +0100344 efx_fill_test(n++, strings, data, &tests->memory,
345 "core", 0, "memory", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100346 efx_fill_test(n++, strings, data, &tests->registers,
347 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800348
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000349 if (efx->phy_op->run_tests != NULL) {
Edward Creee01b16a2016-12-02 15:51:33 +0000350 EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000351
352 for (i = 0; true; ++i) {
353 const char *name;
354
Edward Creee01b16a2016-12-02 15:51:33 +0000355 EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000356 name = efx->phy_op->test_name(efx, i);
357 if (name == NULL)
358 break;
359
Ben Hutchings4f16c072010-02-03 09:30:50 +0000360 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000361 "phy", 0, name, NULL);
362 }
363 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100364
365 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100366 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100367 if (!(efx->loopback_modes & (1 << mode)))
368 continue;
369 n = efx_fill_loopback_test(efx,
370 &tests->loopback[mode], mode, n,
371 strings, data);
372 }
373
374 return n;
375}
376
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100377static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
378{
379 size_t n_stats = 0;
380 struct efx_channel *channel;
381
382 efx_for_each_channel(channel, efx) {
383 if (efx_channel_has_tx_queues(channel)) {
384 n_stats++;
385 if (strings != NULL) {
386 snprintf(strings, ETH_GSTRING_LEN,
387 "tx-%u.tx_packets",
388 channel->tx_queue[0].queue /
389 EFX_TXQ_TYPES);
390
391 strings += ETH_GSTRING_LEN;
392 }
393 }
394 }
395 efx_for_each_channel(channel, efx) {
396 if (efx_channel_has_rx_queue(channel)) {
397 n_stats++;
398 if (strings != NULL) {
399 snprintf(strings, ETH_GSTRING_LEN,
400 "rx-%d.rx_packets", channel->channel);
401 strings += ETH_GSTRING_LEN;
402 }
403 }
404 }
405 return n_stats;
406}
407
Ben Hutchings3594e132008-09-01 12:48:12 +0100408static int efx_ethtool_get_sset_count(struct net_device *net_dev,
409 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100410{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000411 struct efx_nic *efx = netdev_priv(net_dev);
412
Ben Hutchings3594e132008-09-01 12:48:12 +0100413 switch (string_set) {
414 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000415 return efx->type->describe_stats(efx, NULL) +
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100416 EFX_ETHTOOL_SW_STAT_COUNT +
417 efx_describe_per_queue_stats(efx, NULL) +
418 efx_ptp_describe_stats(efx, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100419 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000420 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100421 default:
422 return -EINVAL;
423 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100424}
425
Ben Hutchings8ceee662008-04-27 12:55:59 +0100426static void efx_ethtool_get_strings(struct net_device *net_dev,
427 u32 string_set, u8 *strings)
428{
Ben Hutchings767e4682008-09-01 12:43:14 +0100429 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100430 int i;
431
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100432 switch (string_set) {
433 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000434 strings += (efx->type->describe_stats(efx, strings) *
435 ETH_GSTRING_LEN);
436 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000437 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000438 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000439 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100440 strings += (efx_describe_per_queue_stats(efx, strings) *
441 ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000442 efx_ptp_describe_stats(efx, strings);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100443 break;
444 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000445 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100446 break;
447 default:
448 /* No other string sets */
449 break;
450 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100451}
452
453static void efx_ethtool_get_stats(struct net_device *net_dev,
454 struct ethtool_stats *stats,
455 u64 *data)
456{
Ben Hutchings767e4682008-09-01 12:43:14 +0100457 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000458 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100459 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000460 struct efx_tx_queue *tx_queue;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100461 struct efx_rx_queue *rx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100462 int i;
463
Ben Hutchings1cb34522011-09-02 23:23:00 +0100464 spin_lock_bh(&efx->stats_lock);
465
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000466 /* Get NIC statistics */
467 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100468
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000469 /* Get software statistics */
470 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
471 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100472 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100473 case EFX_ETHTOOL_STAT_SOURCE_nic:
474 data[i] = stat->get_stat((void *)efx + stat->offset);
475 break;
476 case EFX_ETHTOOL_STAT_SOURCE_channel:
477 data[i] = 0;
478 efx_for_each_channel(channel, efx)
479 data[i] += stat->get_stat((void *)channel +
480 stat->offset);
481 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000482 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
483 data[i] = 0;
484 efx_for_each_channel(channel, efx) {
485 efx_for_each_channel_tx_queue(tx_queue, channel)
486 data[i] +=
487 stat->get_stat((void *)tx_queue
488 + stat->offset);
489 }
490 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100491 }
492 }
Ben Hutchings99691c42013-12-11 02:36:08 +0000493 data += EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings1cb34522011-09-02 23:23:00 +0100494
495 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings99691c42013-12-11 02:36:08 +0000496
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100497 efx_for_each_channel(channel, efx) {
498 if (efx_channel_has_tx_queues(channel)) {
499 *data = 0;
500 efx_for_each_channel_tx_queue(tx_queue, channel) {
501 *data += tx_queue->tx_packets;
502 }
503 data++;
504 }
505 }
506 efx_for_each_channel(channel, efx) {
507 if (efx_channel_has_rx_queue(channel)) {
508 *data = 0;
509 efx_for_each_channel_rx_queue(rx_queue, channel) {
510 *data += rx_queue->rx_packets;
511 }
512 data++;
513 }
514 }
515
Ben Hutchings99691c42013-12-11 02:36:08 +0000516 efx_ptp_update_stats(efx, data);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100517}
518
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100519static void efx_ethtool_self_test(struct net_device *net_dev,
520 struct ethtool_test *test, u64 *data)
521{
Ben Hutchings767e4682008-09-01 12:43:14 +0100522 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000523 struct efx_self_tests *efx_tests;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000524 bool already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000525 int rc = -ENOMEM;
526
527 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
528 if (!efx_tests)
529 goto fail;
530
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100531 if (efx->state != STATE_READY) {
Ben Hutchings5eed1f62014-02-12 19:00:28 +0000532 rc = -EBUSY;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000533 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100534 }
535
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000536 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
537 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
538
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100539 /* We need rx buffers and interrupts. */
540 already_up = (efx->net_dev->flags & IFF_UP);
541 if (!already_up) {
542 rc = dev_open(efx->net_dev);
543 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000544 netif_err(efx, drv, efx->net_dev,
545 "failed opening device.\n");
Ben Hutchings17e678d2014-02-12 19:00:16 +0000546 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100547 }
548 }
549
Eric Dumazet28801f32011-02-16 03:48:38 +0000550 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100551
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100552 if (!already_up)
553 dev_close(efx->net_dev);
554
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000555 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
556 rc == 0 ? "passed" : "failed",
557 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100558
Ben Hutchings17e678d2014-02-12 19:00:16 +0000559out:
Eric Dumazet28801f32011-02-16 03:48:38 +0000560 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
561 kfree(efx_tests);
562fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100563 if (rc)
564 test->flags |= ETH_TEST_FL_FAILED;
565}
566
Ben Hutchings8ceee662008-04-27 12:55:59 +0100567/* Restart autonegotiation */
568static int efx_ethtool_nway_reset(struct net_device *net_dev)
569{
Ben Hutchings767e4682008-09-01 12:43:14 +0100570 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100571
Ben Hutchings68e7f452009-04-29 08:05:08 +0000572 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100573}
574
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000575/*
576 * Each channel has a single IRQ and moderation timer, started by any
577 * completion (or other event). Unless the module parameter
578 * separate_tx_channels is set, IRQs and moderation are therefore
579 * shared between RX and TX completions. In this case, when RX IRQ
580 * moderation is explicitly changed then TX IRQ moderation is
581 * automatically changed too, but otherwise we fail if the two values
582 * are requested to be different.
583 *
Ben Hutchings13225972011-09-05 07:43:49 +0000584 * The hardware does not support a limit on the number of completions
585 * before an IRQ, so we do not use the max_frames fields. We should
586 * report and require that max_frames == (usecs != 0), but this would
587 * invalidate existing user documentation.
588 *
589 * The hardware does not have distinct settings for interrupt
590 * moderation while the previous IRQ is being handled, so we should
591 * not use the 'irq' fields. However, an earlier developer
592 * misunderstood the meaning of the 'irq' fields and the driver did
593 * not support the standard fields. To avoid invalidating existing
594 * user documentation, we report and accept changes through either the
595 * standard or 'irq' fields. If both are changed at the same time, we
596 * prefer the standard field.
597 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000598 * We implement adaptive IRQ moderation, but use a different algorithm
599 * from that assumed in the definition of struct ethtool_coalesce.
600 * Therefore we do not use any of the adaptive moderation parameters
601 * in it.
602 */
603
Ben Hutchings8ceee662008-04-27 12:55:59 +0100604static int efx_ethtool_get_coalesce(struct net_device *net_dev,
605 struct ethtool_coalesce *coalesce)
606{
Ben Hutchings767e4682008-09-01 12:43:14 +0100607 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000608 unsigned int tx_usecs, rx_usecs;
609 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100610
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000611 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100612
Ben Hutchings13225972011-09-05 07:43:49 +0000613 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000614 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000615 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000616 coalesce->rx_coalesce_usecs_irq = rx_usecs;
617 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000618
Ben Hutchings8ceee662008-04-27 12:55:59 +0100619 return 0;
620}
621
Ben Hutchings8ceee662008-04-27 12:55:59 +0100622static int efx_ethtool_set_coalesce(struct net_device *net_dev,
623 struct ethtool_coalesce *coalesce)
624{
Ben Hutchings767e4682008-09-01 12:43:14 +0100625 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100626 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000627 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000628 bool adaptive, rx_may_override_tx;
629 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100630
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000631 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000632 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100633
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000634 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
635
Ben Hutchings13225972011-09-05 07:43:49 +0000636 if (coalesce->rx_coalesce_usecs != rx_usecs)
637 rx_usecs = coalesce->rx_coalesce_usecs;
638 else
639 rx_usecs = coalesce->rx_coalesce_usecs_irq;
640
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000641 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100642
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000643 /* If channels are shared, TX IRQ moderation can be quietly
644 * overridden unless it is changed from its old value.
645 */
Ben Hutchings13225972011-09-05 07:43:49 +0000646 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
647 coalesce->tx_coalesce_usecs_irq == tx_usecs);
648 if (coalesce->tx_coalesce_usecs != tx_usecs)
649 tx_usecs = coalesce->tx_coalesce_usecs;
650 else
651 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100652
Ben Hutchings9e393b32011-09-05 07:43:04 +0000653 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
654 rx_may_override_tx);
655 if (rc != 0)
656 return rc;
657
Ben Hutchings8ceee662008-04-27 12:55:59 +0100658 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000659 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100660
661 return 0;
662}
663
Ben Hutchings46426102010-09-10 06:42:33 +0000664static void efx_ethtool_get_ringparam(struct net_device *net_dev,
665 struct ethtool_ringparam *ring)
666{
667 struct efx_nic *efx = netdev_priv(net_dev);
668
669 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000670 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000671 ring->rx_pending = efx->rxq_entries;
672 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000673}
674
675static int efx_ethtool_set_ringparam(struct net_device *net_dev,
676 struct ethtool_ringparam *ring)
677{
678 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000679 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000680
681 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
682 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000683 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
Ben Hutchings46426102010-09-10 06:42:33 +0000684 return -EINVAL;
685
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000686 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000687 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000688 "RX queues cannot be smaller than %u\n",
689 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000690 return -EINVAL;
691 }
692
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000693 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
694 if (txq_entries != ring->tx_pending)
695 netif_warn(efx, drv, efx->net_dev,
696 "increasing TX queue size to minimum of %u\n",
697 txq_entries);
698
699 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000700}
701
Ben Hutchings8ceee662008-04-27 12:55:59 +0100702static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
703 struct ethtool_pauseparam *pause)
704{
Ben Hutchings767e4682008-09-01 12:43:14 +0100705 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb56269462011-05-17 17:53:22 -0400706 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000707 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000708 int rc = 0;
709
710 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100711
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800712 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
713 (pause->tx_pause ? EFX_FC_TX : 0) |
714 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100715
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800716 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000717 netif_dbg(efx, drv, efx->net_dev,
718 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000719 rc = -EINVAL;
720 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800721 }
722
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000723 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000724 netif_dbg(efx, drv, efx->net_dev,
725 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000726 rc = -EINVAL;
727 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800728 }
729
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100730 /* Hook for Falcon bug 11482 workaround */
731 if (efx->type->prepare_enable_fc_tx &&
732 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
733 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800734
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000735 old_adv = efx->link_advertising;
736 old_fc = efx->wanted_fc;
737 efx_link_set_wanted_fc(efx, wanted_fc);
738 if (efx->link_advertising != old_adv ||
739 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
740 rc = efx->phy_op->reconfigure(efx);
741 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000742 netif_err(efx, drv, efx->net_dev,
743 "Unable to advertise requested flow "
744 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000745 goto out;
746 }
747 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800748
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000749 /* Reconfigure the MAC. The PHY *may* generate a link state change event
750 * if the user just changed the advertised capabilities, but there's no
751 * harm doing this twice */
Edward Cree0d322412015-05-20 11:10:03 +0100752 efx_mac_reconfigure(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800753
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000754out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800755 mutex_unlock(&efx->mac_lock);
756
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000757 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100758}
759
760static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
761 struct ethtool_pauseparam *pause)
762{
Ben Hutchings767e4682008-09-01 12:43:14 +0100763 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100764
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800765 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
766 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
767 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100768}
769
Ben Hutchings89c758f2009-11-29 03:43:07 +0000770static void efx_ethtool_get_wol(struct net_device *net_dev,
771 struct ethtool_wolinfo *wol)
772{
773 struct efx_nic *efx = netdev_priv(net_dev);
774 return efx->type->get_wol(efx, wol);
775}
776
777
778static int efx_ethtool_set_wol(struct net_device *net_dev,
779 struct ethtool_wolinfo *wol)
780{
781 struct efx_nic *efx = netdev_priv(net_dev);
782 return efx->type->set_wol(efx, wol->wolopts);
783}
784
stephen hemmingerd2156972010-10-18 05:27:31 +0000785static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000786{
787 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100788 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000789
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100790 rc = efx->type->map_reset_flags(flags);
791 if (rc < 0)
792 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000793
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100794 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000795}
796
Ben Hutchings7c460d92012-10-27 00:33:28 +0100797/* MAC address mask including only I/G bit */
Edward Creecd84ff42014-03-07 18:27:41 +0000798static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
Ben Hutchingsc274d652012-02-02 22:41:49 +0000799
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100800#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
Edward Creea7ad40d2016-02-05 11:16:50 +0000801#define IP_PROTO_FULL_MASK 0xFF
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100802#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100803#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100804
Edward Creea7ad40d2016-02-05 11:16:50 +0000805static inline void ip6_fill_mask(__be32 *mask)
806{
807 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
808}
809
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000810static int efx_ethtool_get_class_rule(struct efx_nic *efx,
811 struct ethtool_rx_flow_spec *rule)
812{
813 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
814 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +0000815 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
816 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
817 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
818 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
819 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
820 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000821 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
822 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000823 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000824 int rc;
825
826 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
827 rule->location, &spec);
828 if (rc)
829 return rc;
830
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000831 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000832 rule->ring_cookie = RX_CLS_FLOW_DISC;
833 else
834 rule->ring_cookie = spec.dmaq_id;
835
Ben Hutchings7c460d92012-10-27 00:33:28 +0100836 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
837 spec.ether_type == htons(ETH_P_IP) &&
838 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
839 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
840 !(spec.match_flags &
841 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
842 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
843 EFX_FILTER_MATCH_IP_PROTO |
844 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
845 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
846 TCP_V4_FLOW : UDP_V4_FLOW);
847 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
848 ip_entry->ip4dst = spec.loc_host[0];
849 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000850 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100851 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
852 ip_entry->ip4src = spec.rem_host[0];
853 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
854 }
855 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
856 ip_entry->pdst = spec.loc_port;
857 ip_mask->pdst = PORT_FULL_MASK;
858 }
859 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
860 ip_entry->psrc = spec.rem_port;
861 ip_mask->psrc = PORT_FULL_MASK;
862 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000863 } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
864 spec.ether_type == htons(ETH_P_IPV6) &&
865 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
866 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
867 !(spec.match_flags &
868 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
869 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
870 EFX_FILTER_MATCH_IP_PROTO |
871 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
872 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
873 TCP_V6_FLOW : UDP_V6_FLOW);
874 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
875 memcpy(ip6_entry->ip6dst, spec.loc_host,
876 sizeof(ip6_entry->ip6dst));
877 ip6_fill_mask(ip6_mask->ip6dst);
878 }
879 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
880 memcpy(ip6_entry->ip6src, spec.rem_host,
881 sizeof(ip6_entry->ip6src));
882 ip6_fill_mask(ip6_mask->ip6src);
883 }
884 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
885 ip6_entry->pdst = spec.loc_port;
886 ip6_mask->pdst = PORT_FULL_MASK;
887 }
888 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
889 ip6_entry->psrc = spec.rem_port;
890 ip6_mask->psrc = PORT_FULL_MASK;
891 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100892 } else if (!(spec.match_flags &
893 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
894 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
895 EFX_FILTER_MATCH_OUTER_VID))) {
896 rule->flow_type = ETHER_FLOW;
897 if (spec.match_flags &
898 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
Edward Creecd84ff42014-03-07 18:27:41 +0000899 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100900 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
Edward Creecd84ff42014-03-07 18:27:41 +0000901 eth_broadcast_addr(mac_mask->h_dest);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100902 else
Edward Creecd84ff42014-03-07 18:27:41 +0000903 ether_addr_copy(mac_mask->h_dest,
904 mac_addr_ig_mask);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100905 }
906 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
Edward Creecd84ff42014-03-07 18:27:41 +0000907 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
908 eth_broadcast_addr(mac_mask->h_source);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100909 }
910 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
911 mac_entry->h_proto = spec.ether_type;
912 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
913 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000914 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
915 spec.ether_type == htons(ETH_P_IP) &&
916 !(spec.match_flags &
917 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
918 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
919 EFX_FILTER_MATCH_IP_PROTO))) {
920 rule->flow_type = IPV4_USER_FLOW;
921 uip_entry->ip_ver = ETH_RX_NFC_IP4;
922 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
923 uip_mask->proto = IP_PROTO_FULL_MASK;
924 uip_entry->proto = spec.ip_proto;
925 }
926 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
927 uip_entry->ip4dst = spec.loc_host[0];
928 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
929 }
930 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
931 uip_entry->ip4src = spec.rem_host[0];
932 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
933 }
934 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
935 spec.ether_type == htons(ETH_P_IPV6) &&
936 !(spec.match_flags &
937 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
938 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
939 EFX_FILTER_MATCH_IP_PROTO))) {
940 rule->flow_type = IPV6_USER_FLOW;
941 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
942 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
943 uip6_entry->l4_proto = spec.ip_proto;
944 }
945 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
946 memcpy(uip6_entry->ip6dst, spec.loc_host,
947 sizeof(uip6_entry->ip6dst));
948 ip6_fill_mask(uip6_mask->ip6dst);
949 }
950 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
951 memcpy(uip6_entry->ip6src, spec.rem_host,
952 sizeof(uip6_entry->ip6src));
953 ip6_fill_mask(uip6_mask->ip6src);
954 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100955 } else {
956 /* The above should handle all filters that we insert */
957 WARN_ON(1);
958 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000959 }
960
Ben Hutchings7c460d92012-10-27 00:33:28 +0100961 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
962 rule->flow_type |= FLOW_EXT;
963 rule->h_ext.vlan_tci = spec.outer_vid;
964 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000965 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100966
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000967 return rc;
968}
969
Ben Hutchings765c9f42010-06-30 05:06:28 +0000970static int
971efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000972 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000973{
974 struct efx_nic *efx = netdev_priv(net_dev);
975
976 switch (info->cmd) {
977 case ETHTOOL_GRXRINGS:
978 info->data = efx->n_rx_channels;
979 return 0;
980
981 case ETHTOOL_GRXFH: {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000982 info->data = 0;
Edward Cree4fdda952017-01-04 15:10:56 +0000983 if (!efx->rss_active) /* No RSS */
984 return 0;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000985 switch (info->flow_type) {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000986 case UDP_V4_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000987 if (efx->rx_hash_udp_4tuple)
988 /* fall through */
989 case TCP_V4_FLOW:
990 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
991 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000992 case SCTP_V4_FLOW:
993 case AH_ESP_V4_FLOW:
994 case IPV4_FLOW:
995 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000996 break;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000997 case UDP_V6_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000998 if (efx->rx_hash_udp_4tuple)
999 /* fall through */
1000 case TCP_V6_FLOW:
1001 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1002 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +00001003 case SCTP_V6_FLOW:
1004 case AH_ESP_V6_FLOW:
1005 case IPV6_FLOW:
1006 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +00001007 break;
1008 default:
1009 break;
1010 }
Ben Hutchings765c9f42010-06-30 05:06:28 +00001011 return 0;
1012 }
1013
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001014 case ETHTOOL_GRXCLSRLCNT:
1015 info->data = efx_filter_get_rx_id_limit(efx);
1016 if (info->data == 0)
1017 return -EOPNOTSUPP;
1018 info->data |= RX_CLS_LOC_SPECIAL;
1019 info->rule_cnt =
1020 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1021 return 0;
1022
1023 case ETHTOOL_GRXCLSRULE:
1024 if (efx_filter_get_rx_id_limit(efx) == 0)
1025 return -EOPNOTSUPP;
1026 return efx_ethtool_get_class_rule(efx, &info->fs);
1027
1028 case ETHTOOL_GRXCLSRLALL: {
1029 s32 rc;
1030 info->data = efx_filter_get_rx_id_limit(efx);
1031 if (info->data == 0)
1032 return -EOPNOTSUPP;
1033 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1034 rule_locs, info->rule_cnt);
1035 if (rc < 0)
1036 return rc;
1037 info->rule_cnt = rc;
1038 return 0;
1039 }
1040
Ben Hutchings765c9f42010-06-30 05:06:28 +00001041 default:
1042 return -EOPNOTSUPP;
1043 }
1044}
1045
Edward Creea7ad40d2016-02-05 11:16:50 +00001046static inline bool ip6_mask_is_full(__be32 mask[4])
1047{
1048 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1049}
1050
1051static inline bool ip6_mask_is_empty(__be32 mask[4])
1052{
1053 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1054}
1055
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001056static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1057 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001058{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001059 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1060 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +00001061 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1062 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1063 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1064 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1065 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1066 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001067 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1068 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1069 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001070 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001071
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001072 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +01001073 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001074 return -EINVAL;
1075
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001076 /* Range-check ring_cookie */
1077 if (rule->ring_cookie >= efx->n_rx_channels &&
1078 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001079 return -EINVAL;
1080
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001081 /* Check for unsupported extensions */
1082 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +01001083 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001084 rule->m_ext.data[1]))
1085 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001086
Ben Hutchings85740cdf2013-01-29 23:33:15 +00001087 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
1088 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001089 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +00001090 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001091
Ben Hutchings7c460d92012-10-27 00:33:28 +01001092 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001093 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +01001094 case UDP_V4_FLOW:
1095 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1096 EFX_FILTER_MATCH_IP_PROTO);
1097 spec.ether_type = htons(ETH_P_IP);
1098 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1099 IPPROTO_TCP : IPPROTO_UDP);
1100 if (ip_mask->ip4dst) {
1101 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1102 return -EINVAL;
1103 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1104 spec.loc_host[0] = ip_entry->ip4dst;
1105 }
1106 if (ip_mask->ip4src) {
1107 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1108 return -EINVAL;
1109 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1110 spec.rem_host[0] = ip_entry->ip4src;
1111 }
1112 if (ip_mask->pdst) {
1113 if (ip_mask->pdst != PORT_FULL_MASK)
1114 return -EINVAL;
1115 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1116 spec.loc_port = ip_entry->pdst;
1117 }
1118 if (ip_mask->psrc) {
1119 if (ip_mask->psrc != PORT_FULL_MASK)
1120 return -EINVAL;
1121 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1122 spec.rem_port = ip_entry->psrc;
1123 }
1124 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001125 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001126 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001127
Edward Creea7ad40d2016-02-05 11:16:50 +00001128 case TCP_V6_FLOW:
1129 case UDP_V6_FLOW:
1130 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1131 EFX_FILTER_MATCH_IP_PROTO);
1132 spec.ether_type = htons(ETH_P_IPV6);
1133 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1134 IPPROTO_TCP : IPPROTO_UDP);
1135 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1136 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1137 return -EINVAL;
1138 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1139 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1140 }
1141 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1142 if (!ip6_mask_is_full(ip6_mask->ip6src))
1143 return -EINVAL;
1144 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1145 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1146 }
1147 if (ip6_mask->pdst) {
1148 if (ip6_mask->pdst != PORT_FULL_MASK)
1149 return -EINVAL;
1150 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1151 spec.loc_port = ip6_entry->pdst;
1152 }
1153 if (ip6_mask->psrc) {
1154 if (ip6_mask->psrc != PORT_FULL_MASK)
1155 return -EINVAL;
1156 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1157 spec.rem_port = ip6_entry->psrc;
1158 }
1159 if (ip6_mask->tclass)
1160 return -EINVAL;
1161 break;
1162
1163 case IPV4_USER_FLOW:
1164 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1165 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1166 return -EINVAL;
1167 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1168 spec.ether_type = htons(ETH_P_IP);
1169 if (uip_mask->ip4dst) {
1170 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1171 return -EINVAL;
1172 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1173 spec.loc_host[0] = uip_entry->ip4dst;
1174 }
1175 if (uip_mask->ip4src) {
1176 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1177 return -EINVAL;
1178 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1179 spec.rem_host[0] = uip_entry->ip4src;
1180 }
1181 if (uip_mask->proto) {
1182 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1183 return -EINVAL;
1184 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1185 spec.ip_proto = uip_entry->proto;
1186 }
1187 break;
1188
1189 case IPV6_USER_FLOW:
1190 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1191 return -EINVAL;
1192 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1193 spec.ether_type = htons(ETH_P_IPV6);
1194 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1195 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1196 return -EINVAL;
1197 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1198 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1199 }
1200 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1201 if (!ip6_mask_is_full(uip6_mask->ip6src))
1202 return -EINVAL;
1203 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1204 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1205 }
1206 if (uip6_mask->l4_proto) {
1207 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1208 return -EINVAL;
1209 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1210 spec.ip_proto = uip6_entry->l4_proto;
1211 }
1212 break;
1213
Ben Hutchings7c460d92012-10-27 00:33:28 +01001214 case ETHER_FLOW:
1215 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1216 if (ether_addr_equal(mac_mask->h_dest,
1217 mac_addr_ig_mask))
1218 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1219 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1220 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +00001221 else
Ben Hutchings7c460d92012-10-27 00:33:28 +01001222 return -EINVAL;
Edward Creecd84ff42014-03-07 18:27:41 +00001223 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001224 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001225 if (!is_zero_ether_addr(mac_mask->h_source)) {
1226 if (!is_broadcast_ether_addr(mac_mask->h_source))
1227 return -EINVAL;
1228 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
Edward Creecd84ff42014-03-07 18:27:41 +00001229 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001230 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001231 if (mac_mask->h_proto) {
1232 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1233 return -EINVAL;
1234 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1235 spec.ether_type = mac_entry->h_proto;
1236 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001237 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001238
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001239 default:
1240 return -EINVAL;
1241 }
1242
Ben Hutchings7c460d92012-10-27 00:33:28 +01001243 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1244 if (rule->m_ext.vlan_tci != htons(0xfff))
1245 return -EINVAL;
1246 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1247 spec.outer_vid = rule->h_ext.vlan_tci;
1248 }
1249
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001250 rc = efx_filter_insert_filter(efx, &spec, true);
1251 if (rc < 0)
1252 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +01001253
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001254 rule->location = rc;
1255 return 0;
1256}
1257
1258static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1259 struct ethtool_rxnfc *info)
1260{
1261 struct efx_nic *efx = netdev_priv(net_dev);
1262
1263 if (efx_filter_get_rx_id_limit(efx) == 0)
1264 return -EOPNOTSUPP;
1265
1266 switch (info->cmd) {
1267 case ETHTOOL_SRXCLSRLINS:
1268 return efx_ethtool_set_class_rule(efx, &info->fs);
1269
1270 case ETHTOOL_SRXCLSRLDEL:
1271 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1272 info->fs.location);
1273
1274 default:
1275 return -EOPNOTSUPP;
1276 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001277}
1278
Ben Hutchings7850f632011-12-15 13:55:01 +00001279static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001280{
1281 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001282
Edward Cree5a6681e2016-11-28 18:55:34 +00001283 return (efx->n_rx_channels == 1) ? 0 : ARRAY_SIZE(efx->rx_indir_table);
Ben Hutchings7850f632011-12-15 13:55:01 +00001284}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001285
Edward Creef74d1992017-01-17 12:01:53 +00001286static u32 efx_ethtool_get_rxfh_key_size(struct net_device *net_dev)
1287{
1288 struct efx_nic *efx = netdev_priv(net_dev);
1289
1290 return efx->type->rx_hash_key_size;
1291}
1292
Eyal Perry892311f2014-12-02 18:12:10 +02001293static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1294 u8 *hfunc)
Ben Hutchings7850f632011-12-15 13:55:01 +00001295{
1296 struct efx_nic *efx = netdev_priv(net_dev);
Edward Creea707d182017-01-17 12:02:12 +00001297 int rc;
1298
1299 rc = efx->type->rx_pull_rss_config(efx);
1300 if (rc)
1301 return rc;
Ben Hutchings7850f632011-12-15 13:55:01 +00001302
Eyal Perry892311f2014-12-02 18:12:10 +02001303 if (hfunc)
1304 *hfunc = ETH_RSS_HASH_TOP;
1305 if (indir)
1306 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Edward Creef74d1992017-01-17 12:01:53 +00001307 if (key)
1308 memcpy(key, efx->rx_hash_key, efx->type->rx_hash_key_size);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001309 return 0;
1310}
1311
Eyal Perry892311f2014-12-02 18:12:10 +02001312static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1313 const u8 *key, const u8 hfunc)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001314{
1315 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001316
Edward Creef74d1992017-01-17 12:01:53 +00001317 /* Hash function is Toeplitz, cannot be changed */
1318 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
Eyal Perry892311f2014-12-02 18:12:10 +02001319 return -EOPNOTSUPP;
Edward Creef74d1992017-01-17 12:01:53 +00001320 if (!indir && !key)
Eyal Perry892311f2014-12-02 18:12:10 +02001321 return 0;
Jon Cooper267c0152015-05-06 00:59:38 +01001322
Edward Creef74d1992017-01-17 12:01:53 +00001323 if (!key)
1324 key = efx->rx_hash_key;
1325 if (!indir)
1326 indir = efx->rx_indir_table;
1327
1328 return efx->type->rx_push_rss_config(efx, true, indir, key);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001329}
1330
Fengguang Wub51ca342013-07-03 14:07:40 +08001331static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1332 struct ethtool_ts_info *ts_info)
Ben Hutchings62ebac92013-04-08 17:34:58 +01001333{
1334 struct efx_nic *efx = netdev_priv(net_dev);
1335
1336 /* Software capabilities */
1337 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1338 SOF_TIMESTAMPING_SOFTWARE);
1339 ts_info->phc_index = -1;
1340
1341 efx_ptp_get_ts_info(efx, ts_info);
1342 return 0;
1343}
1344
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001345static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1346 struct ethtool_eeprom *ee,
1347 u8 *data)
1348{
1349 struct efx_nic *efx = netdev_priv(net_dev);
1350 int ret;
1351
1352 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1353 return -EOPNOTSUPP;
1354
1355 mutex_lock(&efx->mac_lock);
1356 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1357 mutex_unlock(&efx->mac_lock);
1358
1359 return ret;
1360}
1361
1362static int efx_ethtool_get_module_info(struct net_device *net_dev,
1363 struct ethtool_modinfo *modinfo)
1364{
1365 struct efx_nic *efx = netdev_priv(net_dev);
1366 int ret;
1367
1368 if (!efx->phy_op || !efx->phy_op->get_module_info)
1369 return -EOPNOTSUPP;
1370
1371 mutex_lock(&efx->mac_lock);
1372 ret = efx->phy_op->get_module_info(efx, modinfo);
1373 mutex_unlock(&efx->mac_lock);
1374
1375 return ret;
1376}
1377
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001378const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001379 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001380 .get_regs_len = efx_ethtool_get_regs_len,
1381 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001382 .get_msglevel = efx_ethtool_get_msglevel,
1383 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001384 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001385 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001386 .get_coalesce = efx_ethtool_get_coalesce,
1387 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001388 .get_ringparam = efx_ethtool_get_ringparam,
1389 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001390 .get_pauseparam = efx_ethtool_get_pauseparam,
1391 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001392 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001393 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001394 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001395 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001396 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001397 .get_wol = efx_ethtool_get_wol,
1398 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001399 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001400 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001401 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001402 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Edward Creef74d1992017-01-17 12:01:53 +00001403 .get_rxfh_key_size = efx_ethtool_get_rxfh_key_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001404 .get_rxfh = efx_ethtool_get_rxfh,
1405 .set_rxfh = efx_ethtool_set_rxfh,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001406 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001407 .get_module_info = efx_ethtool_get_module_info,
1408 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Philippe Reynes7cafe8f2016-12-15 00:12:53 +01001409 .get_link_ksettings = efx_ethtool_get_link_ksettings,
1410 .set_link_ksettings = efx_ethtool_set_link_ksettings,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001411};