blob: 18ebaea44e8257255c6a910958e4b00466600903 [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. */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100123static int
124efx_ethtool_get_link_ksettings(struct net_device *net_dev,
125 struct ethtool_link_ksettings *cmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126{
Ben Hutchings767e4682008-09-01 12:43:14 +0100127 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000128 struct efx_link_state *link_state = &efx->link_state;
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100129 u32 supported;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100130
131 mutex_lock(&efx->mac_lock);
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100132 efx->phy_op->get_link_ksettings(efx, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133 mutex_unlock(&efx->mac_lock);
134
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000135 /* Both MACs support pause frames (bidirectional and respond-only) */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100136 ethtool_convert_link_mode_to_legacy_u32(&supported,
137 cmd->link_modes.supported);
138
139 supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause;
140
141 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
142 supported);
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000143
144 if (LOOPBACK_INTERNAL(efx)) {
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100145 cmd->base.speed = link_state->speed;
146 cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000147 }
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800148
149 return 0;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100150}
151
152/* This must be called with rtnl_lock held. */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100153static int
154efx_ethtool_set_link_ksettings(struct net_device *net_dev,
155 const struct ethtool_link_ksettings *cmd)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100156{
Ben Hutchings767e4682008-09-01 12:43:14 +0100157 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100158 int rc;
159
Ben Hutchings754c6532010-02-03 09:31:57 +0000160 /* GMAC does not support 1000Mbps HD */
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100161 if ((cmd->base.speed == SPEED_1000) &&
162 (cmd->base.duplex != DUPLEX_FULL)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000163 netif_dbg(efx, drv, efx->net_dev,
164 "rejecting unsupported 1000Mbps HD setting\n");
Ben Hutchings177dfcd2008-12-12 21:50:08 -0800165 return -EINVAL;
166 }
167
Ben Hutchings8ceee662008-04-27 12:55:59 +0100168 mutex_lock(&efx->mac_lock);
Philippe Reynes7cafe8f2016-12-15 00:12:53 +0100169 rc = efx->phy_op->set_link_ksettings(efx, cmd);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100170 mutex_unlock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100171 return rc;
172}
173
174static void efx_ethtool_get_drvinfo(struct net_device *net_dev,
175 struct ethtool_drvinfo *info)
176{
Ben Hutchings767e4682008-09-01 12:43:14 +0100177 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100178
Ben Hutchingsc5d5f5f2010-06-23 11:30:26 +0000179 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100180 strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version));
Edward Cree5a6681e2016-11-28 18:55:34 +0000181 efx_mcdi_print_fwver(efx, info->fw_version,
182 sizeof(info->fw_version));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100183 strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info));
184}
185
Ben Hutchings5b98c1b2010-06-21 03:06:53 +0000186static int efx_ethtool_get_regs_len(struct net_device *net_dev)
187{
188 return efx_nic_get_regs_len(netdev_priv(net_dev));
189}
190
191static void efx_ethtool_get_regs(struct net_device *net_dev,
192 struct ethtool_regs *regs, void *buf)
193{
194 struct efx_nic *efx = netdev_priv(net_dev);
195
196 regs->version = efx->type->revision;
197 efx_nic_get_regs(efx, buf);
198}
199
Ben Hutchings62776d02010-06-23 11:30:07 +0000200static u32 efx_ethtool_get_msglevel(struct net_device *net_dev)
201{
202 struct efx_nic *efx = netdev_priv(net_dev);
203 return efx->msg_enable;
204}
205
206static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable)
207{
208 struct efx_nic *efx = netdev_priv(net_dev);
209 efx->msg_enable = msg_enable;
210}
211
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100212/**
213 * efx_fill_test - fill in an individual self-test entry
214 * @test_index: Index of the test
215 * @strings: Ethtool strings, or %NULL
216 * @data: Ethtool test results, or %NULL
217 * @test: Pointer to test result (used only if data != %NULL)
Ben Hutchings740ced92008-12-12 21:41:55 -0800218 * @unit_format: Unit name format (e.g. "chan\%d")
219 * @unit_id: Unit id (e.g. 0 for "chan0")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100220 * @test_format: Test name format (e.g. "loopback.\%s.tx.sent")
Ben Hutchings740ced92008-12-12 21:41:55 -0800221 * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent")
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100222 *
223 * Fill in an individual self-test entry.
224 */
Ben Hutchingsb681e572012-12-14 22:18:55 +0000225static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100226 int *test, const char *unit_format, int unit_id,
227 const char *test_format, const char *test_id)
228{
Ben Hutchingsb681e572012-12-14 22:18:55 +0000229 char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN];
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100230
231 /* Fill data value, if applicable */
232 if (data)
233 data[test_index] = *test;
234
235 /* Fill string, if applicable */
236 if (strings) {
Ben Hutchings11e66962008-12-12 22:05:48 -0800237 if (strchr(unit_format, '%'))
Ben Hutchingsb681e572012-12-14 22:18:55 +0000238 snprintf(unit_str, sizeof(unit_str),
Ben Hutchings11e66962008-12-12 22:05:48 -0800239 unit_format, unit_id);
240 else
Ben Hutchingsb681e572012-12-14 22:18:55 +0000241 strcpy(unit_str, unit_format);
242 snprintf(test_str, sizeof(test_str), test_format, test_id);
243 snprintf(strings + test_index * ETH_GSTRING_LEN,
244 ETH_GSTRING_LEN,
245 "%-6s %-24s", unit_str, test_str);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100246 }
247}
248
Ben Hutchings740ced92008-12-12 21:41:55 -0800249#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100250#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
251#define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
252#define EFX_LOOPBACK_NAME(_mode, _counter) \
Ben Hutchingsc4593022009-11-23 16:08:17 +0000253 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100254
255/**
256 * efx_fill_loopback_test - fill in a block of loopback self-test entries
257 * @efx: Efx NIC
258 * @lb_tests: Efx loopback self-test results structure
259 * @mode: Loopback test mode
260 * @test_index: Starting index of the test
261 * @strings: Ethtool strings, or %NULL
262 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000263 *
264 * Fill in a block of loopback self-test entries. Return new test
265 * index.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100266 */
267static int efx_fill_loopback_test(struct efx_nic *efx,
268 struct efx_loopback_self_tests *lb_tests,
269 enum efx_loopback_mode mode,
270 unsigned int test_index,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000271 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100272{
Ben Hutchings1ac02262012-09-13 02:22:52 +0100273 struct efx_channel *channel =
274 efx_get_channel(efx, efx->tx_channel_offset);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100275 struct efx_tx_queue *tx_queue;
276
Ben Hutchingsf7d12cd2010-09-10 06:41:47 +0000277 efx_for_each_channel_tx_queue(tx_queue, channel) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100278 efx_fill_test(test_index++, strings, data,
279 &lb_tests->tx_sent[tx_queue->queue],
280 EFX_TX_QUEUE_NAME(tx_queue),
281 EFX_LOOPBACK_NAME(mode, "tx_sent"));
282 efx_fill_test(test_index++, strings, data,
283 &lb_tests->tx_done[tx_queue->queue],
284 EFX_TX_QUEUE_NAME(tx_queue),
285 EFX_LOOPBACK_NAME(mode, "tx_done"));
286 }
287 efx_fill_test(test_index++, strings, data,
288 &lb_tests->rx_good,
Ben Hutchings11e66962008-12-12 22:05:48 -0800289 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100290 EFX_LOOPBACK_NAME(mode, "rx_good"));
291 efx_fill_test(test_index++, strings, data,
292 &lb_tests->rx_bad,
Ben Hutchings11e66962008-12-12 22:05:48 -0800293 "rx", 0,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100294 EFX_LOOPBACK_NAME(mode, "rx_bad"));
295
296 return test_index;
297}
298
299/**
300 * efx_ethtool_fill_self_tests - get self-test details
301 * @efx: Efx NIC
302 * @tests: Efx self-test results structure, or %NULL
303 * @strings: Ethtool strings, or %NULL
304 * @data: Ethtool test results, or %NULL
Ben Hutchings17e678d2014-02-12 19:00:16 +0000305 *
306 * Get self-test number of strings, strings, and/or test results.
307 * Return number of strings (== number of test results).
308 *
309 * The reason for merging these three functions is to make sure that
310 * they can never be inconsistent.
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100311 */
312static int efx_ethtool_fill_self_tests(struct efx_nic *efx,
313 struct efx_self_tests *tests,
Ben Hutchingsb681e572012-12-14 22:18:55 +0000314 u8 *strings, u64 *data)
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100315{
316 struct efx_channel *channel;
Ben Hutchings17967212008-12-26 13:47:25 -0800317 unsigned int n = 0, i;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100318 enum efx_loopback_mode mode;
319
Ben Hutchings4f16c072010-02-03 09:30:50 +0000320 efx_fill_test(n++, strings, data, &tests->phy_alive,
321 "phy", 0, "alive", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100322 efx_fill_test(n++, strings, data, &tests->nvram,
323 "core", 0, "nvram", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100324 efx_fill_test(n++, strings, data, &tests->interrupt,
325 "core", 0, "interrupt", NULL);
326
327 /* Event queues */
328 efx_for_each_channel(channel, efx) {
329 efx_fill_test(n++, strings, data,
330 &tests->eventq_dma[channel->channel],
331 EFX_CHANNEL_NAME(channel),
332 "eventq.dma", NULL);
333 efx_fill_test(n++, strings, data,
334 &tests->eventq_int[channel->channel],
335 EFX_CHANNEL_NAME(channel),
336 "eventq.int", NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100337 }
338
Jon Cooper74cd60a2013-09-16 14:18:51 +0100339 efx_fill_test(n++, strings, data, &tests->memory,
340 "core", 0, "memory", NULL);
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100341 efx_fill_test(n++, strings, data, &tests->registers,
342 "core", 0, "registers", NULL);
Ben Hutchings17967212008-12-26 13:47:25 -0800343
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000344 if (efx->phy_op->run_tests != NULL) {
Edward Creee01b16a2016-12-02 15:51:33 +0000345 EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000346
347 for (i = 0; true; ++i) {
348 const char *name;
349
Edward Creee01b16a2016-12-02 15:51:33 +0000350 EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS);
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000351 name = efx->phy_op->test_name(efx, i);
352 if (name == NULL)
353 break;
354
Ben Hutchings4f16c072010-02-03 09:30:50 +0000355 efx_fill_test(n++, strings, data, &tests->phy_ext[i],
Ben Hutchingsc1c4f452009-11-29 15:08:55 +0000356 "phy", 0, name, NULL);
357 }
358 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100359
360 /* Loopback tests */
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100361 for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) {
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100362 if (!(efx->loopback_modes & (1 << mode)))
363 continue;
364 n = efx_fill_loopback_test(efx,
365 &tests->loopback[mode], mode, n,
366 strings, data);
367 }
368
369 return n;
370}
371
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100372static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings)
373{
374 size_t n_stats = 0;
375 struct efx_channel *channel;
376
377 efx_for_each_channel(channel, efx) {
378 if (efx_channel_has_tx_queues(channel)) {
379 n_stats++;
380 if (strings != NULL) {
381 snprintf(strings, ETH_GSTRING_LEN,
382 "tx-%u.tx_packets",
383 channel->tx_queue[0].queue /
384 EFX_TXQ_TYPES);
385
386 strings += ETH_GSTRING_LEN;
387 }
388 }
389 }
390 efx_for_each_channel(channel, efx) {
391 if (efx_channel_has_rx_queue(channel)) {
392 n_stats++;
393 if (strings != NULL) {
394 snprintf(strings, ETH_GSTRING_LEN,
395 "rx-%d.rx_packets", channel->channel);
396 strings += ETH_GSTRING_LEN;
397 }
398 }
399 }
400 return n_stats;
401}
402
Ben Hutchings3594e132008-09-01 12:48:12 +0100403static int efx_ethtool_get_sset_count(struct net_device *net_dev,
404 int string_set)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100405{
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000406 struct efx_nic *efx = netdev_priv(net_dev);
407
Ben Hutchings3594e132008-09-01 12:48:12 +0100408 switch (string_set) {
409 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000410 return efx->type->describe_stats(efx, NULL) +
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100411 EFX_ETHTOOL_SW_STAT_COUNT +
412 efx_describe_per_queue_stats(efx, NULL) +
413 efx_ptp_describe_stats(efx, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100414 case ETH_SS_TEST:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000415 return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL);
Ben Hutchings3594e132008-09-01 12:48:12 +0100416 default:
417 return -EINVAL;
418 }
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100419}
420
Ben Hutchings8ceee662008-04-27 12:55:59 +0100421static void efx_ethtool_get_strings(struct net_device *net_dev,
422 u32 string_set, u8 *strings)
423{
Ben Hutchings767e4682008-09-01 12:43:14 +0100424 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100425 int i;
426
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100427 switch (string_set) {
428 case ETH_SS_STATS:
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000429 strings += (efx->type->describe_stats(efx, strings) *
430 ETH_GSTRING_LEN);
431 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++)
Ben Hutchingsb681e572012-12-14 22:18:55 +0000432 strlcpy(strings + i * ETH_GSTRING_LEN,
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000433 efx_sw_stat_desc[i].name, ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000434 strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100435 strings += (efx_describe_per_queue_stats(efx, strings) *
436 ETH_GSTRING_LEN);
Ben Hutchings99691c42013-12-11 02:36:08 +0000437 efx_ptp_describe_stats(efx, strings);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100438 break;
439 case ETH_SS_TEST:
Ben Hutchingsb681e572012-12-14 22:18:55 +0000440 efx_ethtool_fill_self_tests(efx, NULL, strings, NULL);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100441 break;
442 default:
443 /* No other string sets */
444 break;
445 }
Ben Hutchings8ceee662008-04-27 12:55:59 +0100446}
447
448static void efx_ethtool_get_stats(struct net_device *net_dev,
449 struct ethtool_stats *stats,
450 u64 *data)
451{
Ben Hutchings767e4682008-09-01 12:43:14 +0100452 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000453 const struct efx_sw_stat_desc *stat;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100454 struct efx_channel *channel;
Ben Hutchings119226c2011-02-18 19:14:13 +0000455 struct efx_tx_queue *tx_queue;
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100456 struct efx_rx_queue *rx_queue;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100457 int i;
458
Ben Hutchings1cb34522011-09-02 23:23:00 +0100459 spin_lock_bh(&efx->stats_lock);
460
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000461 /* Get NIC statistics */
462 data += efx->type->update_stats(efx, data, NULL);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100463
Ben Hutchingscd0ecc92012-12-14 21:52:56 +0000464 /* Get software statistics */
465 for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) {
466 stat = &efx_sw_stat_desc[i];
Ben Hutchings8ceee662008-04-27 12:55:59 +0100467 switch (stat->source) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100468 case EFX_ETHTOOL_STAT_SOURCE_nic:
469 data[i] = stat->get_stat((void *)efx + stat->offset);
470 break;
471 case EFX_ETHTOOL_STAT_SOURCE_channel:
472 data[i] = 0;
473 efx_for_each_channel(channel, efx)
474 data[i] += stat->get_stat((void *)channel +
475 stat->offset);
476 break;
Ben Hutchings119226c2011-02-18 19:14:13 +0000477 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
478 data[i] = 0;
479 efx_for_each_channel(channel, efx) {
480 efx_for_each_channel_tx_queue(tx_queue, channel)
481 data[i] +=
482 stat->get_stat((void *)tx_queue
483 + stat->offset);
484 }
485 break;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100486 }
487 }
Ben Hutchings99691c42013-12-11 02:36:08 +0000488 data += EFX_ETHTOOL_SW_STAT_COUNT;
Ben Hutchings1cb34522011-09-02 23:23:00 +0100489
490 spin_unlock_bh(&efx->stats_lock);
Ben Hutchings99691c42013-12-11 02:36:08 +0000491
Andrew Rybchenko8ccf38002014-07-17 12:10:43 +0100492 efx_for_each_channel(channel, efx) {
493 if (efx_channel_has_tx_queues(channel)) {
494 *data = 0;
495 efx_for_each_channel_tx_queue(tx_queue, channel) {
496 *data += tx_queue->tx_packets;
497 }
498 data++;
499 }
500 }
501 efx_for_each_channel(channel, efx) {
502 if (efx_channel_has_rx_queue(channel)) {
503 *data = 0;
504 efx_for_each_channel_rx_queue(rx_queue, channel) {
505 *data += rx_queue->rx_packets;
506 }
507 data++;
508 }
509 }
510
Ben Hutchings99691c42013-12-11 02:36:08 +0000511 efx_ptp_update_stats(efx, data);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100512}
513
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100514static void efx_ethtool_self_test(struct net_device *net_dev,
515 struct ethtool_test *test, u64 *data)
516{
Ben Hutchings767e4682008-09-01 12:43:14 +0100517 struct efx_nic *efx = netdev_priv(net_dev);
Eric Dumazet28801f32011-02-16 03:48:38 +0000518 struct efx_self_tests *efx_tests;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000519 bool already_up;
Eric Dumazet28801f32011-02-16 03:48:38 +0000520 int rc = -ENOMEM;
521
522 efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL);
523 if (!efx_tests)
524 goto fail;
525
Ben Hutchingsf16aeea2012-07-27 19:31:16 +0100526 if (efx->state != STATE_READY) {
Ben Hutchings5eed1f62014-02-12 19:00:28 +0000527 rc = -EBUSY;
Ben Hutchings17e678d2014-02-12 19:00:16 +0000528 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100529 }
530
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000531 netif_info(efx, drv, efx->net_dev, "starting %sline testing\n",
532 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
533
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100534 /* We need rx buffers and interrupts. */
535 already_up = (efx->net_dev->flags & IFF_UP);
536 if (!already_up) {
537 rc = dev_open(efx->net_dev);
538 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000539 netif_err(efx, drv, efx->net_dev,
540 "failed opening device.\n");
Ben Hutchings17e678d2014-02-12 19:00:16 +0000541 goto out;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100542 }
543 }
544
Eric Dumazet28801f32011-02-16 03:48:38 +0000545 rc = efx_selftest(efx, efx_tests, test->flags);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100546
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100547 if (!already_up)
548 dev_close(efx->net_dev);
549
Ben Hutchingsac33ac62010-12-07 18:29:52 +0000550 netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n",
551 rc == 0 ? "passed" : "failed",
552 (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on");
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100553
Ben Hutchings17e678d2014-02-12 19:00:16 +0000554out:
Eric Dumazet28801f32011-02-16 03:48:38 +0000555 efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data);
556 kfree(efx_tests);
557fail:
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100558 if (rc)
559 test->flags |= ETH_TEST_FL_FAILED;
560}
561
Ben Hutchings8ceee662008-04-27 12:55:59 +0100562/* Restart autonegotiation */
563static int efx_ethtool_nway_reset(struct net_device *net_dev)
564{
Ben Hutchings767e4682008-09-01 12:43:14 +0100565 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100566
Ben Hutchings68e7f452009-04-29 08:05:08 +0000567 return mdio45_nway_restart(&efx->mdio);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100568}
569
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000570/*
571 * Each channel has a single IRQ and moderation timer, started by any
572 * completion (or other event). Unless the module parameter
573 * separate_tx_channels is set, IRQs and moderation are therefore
574 * shared between RX and TX completions. In this case, when RX IRQ
575 * moderation is explicitly changed then TX IRQ moderation is
576 * automatically changed too, but otherwise we fail if the two values
577 * are requested to be different.
578 *
Ben Hutchings13225972011-09-05 07:43:49 +0000579 * The hardware does not support a limit on the number of completions
580 * before an IRQ, so we do not use the max_frames fields. We should
581 * report and require that max_frames == (usecs != 0), but this would
582 * invalidate existing user documentation.
583 *
584 * The hardware does not have distinct settings for interrupt
585 * moderation while the previous IRQ is being handled, so we should
586 * not use the 'irq' fields. However, an earlier developer
587 * misunderstood the meaning of the 'irq' fields and the driver did
588 * not support the standard fields. To avoid invalidating existing
589 * user documentation, we report and accept changes through either the
590 * standard or 'irq' fields. If both are changed at the same time, we
591 * prefer the standard field.
592 *
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000593 * We implement adaptive IRQ moderation, but use a different algorithm
594 * from that assumed in the definition of struct ethtool_coalesce.
595 * Therefore we do not use any of the adaptive moderation parameters
596 * in it.
597 */
598
Ben Hutchings8ceee662008-04-27 12:55:59 +0100599static int efx_ethtool_get_coalesce(struct net_device *net_dev,
600 struct ethtool_coalesce *coalesce)
601{
Ben Hutchings767e4682008-09-01 12:43:14 +0100602 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000603 unsigned int tx_usecs, rx_usecs;
604 bool rx_adaptive;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100605
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000606 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100607
Ben Hutchings13225972011-09-05 07:43:49 +0000608 coalesce->tx_coalesce_usecs = tx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000609 coalesce->tx_coalesce_usecs_irq = tx_usecs;
Ben Hutchings13225972011-09-05 07:43:49 +0000610 coalesce->rx_coalesce_usecs = rx_usecs;
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000611 coalesce->rx_coalesce_usecs_irq = rx_usecs;
612 coalesce->use_adaptive_rx_coalesce = rx_adaptive;
Ben Hutchings0d86ebd2009-10-23 08:32:13 +0000613
Ben Hutchings8ceee662008-04-27 12:55:59 +0100614 return 0;
615}
616
Ben Hutchings8ceee662008-04-27 12:55:59 +0100617static int efx_ethtool_set_coalesce(struct net_device *net_dev,
618 struct ethtool_coalesce *coalesce)
619{
Ben Hutchings767e4682008-09-01 12:43:14 +0100620 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100621 struct efx_channel *channel;
Ben Hutchingsb548f972011-09-05 07:41:44 +0000622 unsigned int tx_usecs, rx_usecs;
Ben Hutchings9e393b32011-09-05 07:43:04 +0000623 bool adaptive, rx_may_override_tx;
624 int rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100625
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000626 if (coalesce->use_adaptive_tx_coalesce)
Ben Hutchings9f85ee92011-09-05 07:41:27 +0000627 return -EINVAL;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100628
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000629 efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive);
630
Ben Hutchings13225972011-09-05 07:43:49 +0000631 if (coalesce->rx_coalesce_usecs != rx_usecs)
632 rx_usecs = coalesce->rx_coalesce_usecs;
633 else
634 rx_usecs = coalesce->rx_coalesce_usecs_irq;
635
Ben Hutchings6fb70fd2009-03-20 13:30:37 +0000636 adaptive = coalesce->use_adaptive_rx_coalesce;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100637
Ben Hutchingsa0c4faf2011-09-05 07:42:25 +0000638 /* If channels are shared, TX IRQ moderation can be quietly
639 * overridden unless it is changed from its old value.
640 */
Ben Hutchings13225972011-09-05 07:43:49 +0000641 rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs &&
642 coalesce->tx_coalesce_usecs_irq == tx_usecs);
643 if (coalesce->tx_coalesce_usecs != tx_usecs)
644 tx_usecs = coalesce->tx_coalesce_usecs;
645 else
646 tx_usecs = coalesce->tx_coalesce_usecs_irq;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100647
Ben Hutchings9e393b32011-09-05 07:43:04 +0000648 rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive,
649 rx_may_override_tx);
650 if (rc != 0)
651 return rc;
652
Ben Hutchings8ceee662008-04-27 12:55:59 +0100653 efx_for_each_channel(channel, efx)
Ben Hutchingsef2b90e2009-11-29 03:42:31 +0000654 efx->type->push_irq_moderation(channel);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100655
656 return 0;
657}
658
Ben Hutchings46426102010-09-10 06:42:33 +0000659static void efx_ethtool_get_ringparam(struct net_device *net_dev,
660 struct ethtool_ringparam *ring)
661{
662 struct efx_nic *efx = netdev_priv(net_dev);
663
664 ring->rx_max_pending = EFX_MAX_DMAQ_SIZE;
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000665 ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx);
Ben Hutchings46426102010-09-10 06:42:33 +0000666 ring->rx_pending = efx->rxq_entries;
667 ring->tx_pending = efx->txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000668}
669
670static int efx_ethtool_set_ringparam(struct net_device *net_dev,
671 struct ethtool_ringparam *ring)
672{
673 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000674 u32 txq_entries;
Ben Hutchings46426102010-09-10 06:42:33 +0000675
676 if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
677 ring->rx_pending > EFX_MAX_DMAQ_SIZE ||
Ben Hutchingsd9317ae2014-01-23 14:35:48 +0000678 ring->tx_pending > EFX_TXQ_MAX_ENT(efx))
Ben Hutchings46426102010-09-10 06:42:33 +0000679 return -EINVAL;
680
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000681 if (ring->rx_pending < EFX_RXQ_MIN_ENT) {
Ben Hutchings46426102010-09-10 06:42:33 +0000682 netif_err(efx, drv, efx->net_dev,
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000683 "RX queues cannot be smaller than %u\n",
684 EFX_RXQ_MIN_ENT);
Ben Hutchings46426102010-09-10 06:42:33 +0000685 return -EINVAL;
686 }
687
Ben Hutchings7e6d06f2012-07-30 15:57:44 +0000688 txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx));
689 if (txq_entries != ring->tx_pending)
690 netif_warn(efx, drv, efx->net_dev,
691 "increasing TX queue size to minimum of %u\n",
692 txq_entries);
693
694 return efx_realloc_channels(efx, ring->rx_pending, txq_entries);
Ben Hutchings46426102010-09-10 06:42:33 +0000695}
696
Ben Hutchings8ceee662008-04-27 12:55:59 +0100697static int efx_ethtool_set_pauseparam(struct net_device *net_dev,
698 struct ethtool_pauseparam *pause)
699{
Ben Hutchings767e4682008-09-01 12:43:14 +0100700 struct efx_nic *efx = netdev_priv(net_dev);
David S. Millerb56269462011-05-17 17:53:22 -0400701 u8 wanted_fc, old_fc;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000702 u32 old_adv;
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000703 int rc = 0;
704
705 mutex_lock(&efx->mac_lock);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100706
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800707 wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) |
708 (pause->tx_pause ? EFX_FC_TX : 0) |
709 (pause->autoneg ? EFX_FC_AUTO : 0));
Ben Hutchings8ceee662008-04-27 12:55:59 +0100710
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800711 if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000712 netif_dbg(efx, drv, efx->net_dev,
713 "Flow control unsupported: tx ON rx OFF\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000714 rc = -EINVAL;
715 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800716 }
717
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000718 if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000719 netif_dbg(efx, drv, efx->net_dev,
720 "Autonegotiation is disabled\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000721 rc = -EINVAL;
722 goto out;
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800723 }
724
Ben Hutchings9dd3a132012-09-13 01:11:25 +0100725 /* Hook for Falcon bug 11482 workaround */
726 if (efx->type->prepare_enable_fc_tx &&
727 (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX))
728 efx->type->prepare_enable_fc_tx(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800729
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000730 old_adv = efx->link_advertising;
731 old_fc = efx->wanted_fc;
732 efx_link_set_wanted_fc(efx, wanted_fc);
733 if (efx->link_advertising != old_adv ||
734 (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) {
735 rc = efx->phy_op->reconfigure(efx);
736 if (rc) {
Ben Hutchings62776d02010-06-23 11:30:07 +0000737 netif_err(efx, drv, efx->net_dev,
738 "Unable to advertise requested flow "
739 "control setting\n");
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000740 goto out;
741 }
742 }
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800743
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000744 /* Reconfigure the MAC. The PHY *may* generate a link state change event
745 * if the user just changed the advertised capabilities, but there's no
746 * harm doing this twice */
Edward Cree0d322412015-05-20 11:10:03 +0100747 efx_mac_reconfigure(efx);
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800748
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000749out:
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800750 mutex_unlock(&efx->mac_lock);
751
Ben Hutchingsd3245b22009-11-29 03:42:41 +0000752 return rc;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100753}
754
755static void efx_ethtool_get_pauseparam(struct net_device *net_dev,
756 struct ethtool_pauseparam *pause)
757{
Ben Hutchings767e4682008-09-01 12:43:14 +0100758 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100759
Ben Hutchings04cc8ca2008-12-12 21:50:46 -0800760 pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX);
761 pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX);
762 pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100763}
764
Ben Hutchings89c758f2009-11-29 03:43:07 +0000765static void efx_ethtool_get_wol(struct net_device *net_dev,
766 struct ethtool_wolinfo *wol)
767{
768 struct efx_nic *efx = netdev_priv(net_dev);
769 return efx->type->get_wol(efx, wol);
770}
771
772
773static int efx_ethtool_set_wol(struct net_device *net_dev,
774 struct ethtool_wolinfo *wol)
775{
776 struct efx_nic *efx = netdev_priv(net_dev);
777 return efx->type->set_wol(efx, wol->wolopts);
778}
779
stephen hemmingerd2156972010-10-18 05:27:31 +0000780static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000781{
782 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100783 int rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000784
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100785 rc = efx->type->map_reset_flags(flags);
786 if (rc < 0)
787 return rc;
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000788
Ben Hutchings0e2a9c72011-06-24 20:50:07 +0100789 return efx_reset(efx, rc);
Ben Hutchingseb9f6742009-11-29 03:43:15 +0000790}
791
Ben Hutchings7c460d92012-10-27 00:33:28 +0100792/* MAC address mask including only I/G bit */
Edward Creecd84ff42014-03-07 18:27:41 +0000793static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0};
Ben Hutchingsc274d652012-02-02 22:41:49 +0000794
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100795#define IP4_ADDR_FULL_MASK ((__force __be32)~0)
Edward Creea7ad40d2016-02-05 11:16:50 +0000796#define IP_PROTO_FULL_MASK 0xFF
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100797#define PORT_FULL_MASK ((__force __be16)~0)
Ben Hutchings7c460d92012-10-27 00:33:28 +0100798#define ETHER_TYPE_FULL_MASK ((__force __be16)~0)
Ben Hutchings0e0c3402012-09-06 02:11:04 +0100799
Edward Creea7ad40d2016-02-05 11:16:50 +0000800static inline void ip6_fill_mask(__be32 *mask)
801{
802 mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
803}
804
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000805static int efx_ethtool_get_class_rule(struct efx_nic *efx,
806 struct ethtool_rx_flow_spec *rule)
807{
808 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
809 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +0000810 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
811 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
812 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
813 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
814 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
815 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsc274d652012-02-02 22:41:49 +0000816 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
817 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000818 struct efx_filter_spec spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000819 int rc;
820
821 rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
822 rule->location, &spec);
823 if (rc)
824 return rc;
825
Ben Hutchingsf26e9582012-10-30 01:01:52 +0000826 if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP)
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000827 rule->ring_cookie = RX_CLS_FLOW_DISC;
828 else
829 rule->ring_cookie = spec.dmaq_id;
830
Ben Hutchings7c460d92012-10-27 00:33:28 +0100831 if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
832 spec.ether_type == htons(ETH_P_IP) &&
833 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
834 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
835 !(spec.match_flags &
836 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
837 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
838 EFX_FILTER_MATCH_IP_PROTO |
839 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
840 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
841 TCP_V4_FLOW : UDP_V4_FLOW);
842 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
843 ip_entry->ip4dst = spec.loc_host[0];
844 ip_mask->ip4dst = IP4_ADDR_FULL_MASK;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000845 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100846 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
847 ip_entry->ip4src = spec.rem_host[0];
848 ip_mask->ip4src = IP4_ADDR_FULL_MASK;
849 }
850 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
851 ip_entry->pdst = spec.loc_port;
852 ip_mask->pdst = PORT_FULL_MASK;
853 }
854 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
855 ip_entry->psrc = spec.rem_port;
856 ip_mask->psrc = PORT_FULL_MASK;
857 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000858 } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) &&
859 spec.ether_type == htons(ETH_P_IPV6) &&
860 (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) &&
861 (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) &&
862 !(spec.match_flags &
863 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
864 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
865 EFX_FILTER_MATCH_IP_PROTO |
866 EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) {
867 rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ?
868 TCP_V6_FLOW : UDP_V6_FLOW);
869 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
870 memcpy(ip6_entry->ip6dst, spec.loc_host,
871 sizeof(ip6_entry->ip6dst));
872 ip6_fill_mask(ip6_mask->ip6dst);
873 }
874 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
875 memcpy(ip6_entry->ip6src, spec.rem_host,
876 sizeof(ip6_entry->ip6src));
877 ip6_fill_mask(ip6_mask->ip6src);
878 }
879 if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) {
880 ip6_entry->pdst = spec.loc_port;
881 ip6_mask->pdst = PORT_FULL_MASK;
882 }
883 if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) {
884 ip6_entry->psrc = spec.rem_port;
885 ip6_mask->psrc = PORT_FULL_MASK;
886 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100887 } else if (!(spec.match_flags &
888 ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG |
889 EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE |
890 EFX_FILTER_MATCH_OUTER_VID))) {
891 rule->flow_type = ETHER_FLOW;
892 if (spec.match_flags &
893 (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) {
Edward Creecd84ff42014-03-07 18:27:41 +0000894 ether_addr_copy(mac_entry->h_dest, spec.loc_mac);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100895 if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC)
Edward Creecd84ff42014-03-07 18:27:41 +0000896 eth_broadcast_addr(mac_mask->h_dest);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100897 else
Edward Creecd84ff42014-03-07 18:27:41 +0000898 ether_addr_copy(mac_mask->h_dest,
899 mac_addr_ig_mask);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100900 }
901 if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) {
Edward Creecd84ff42014-03-07 18:27:41 +0000902 ether_addr_copy(mac_entry->h_source, spec.rem_mac);
903 eth_broadcast_addr(mac_mask->h_source);
Ben Hutchings7c460d92012-10-27 00:33:28 +0100904 }
905 if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
906 mac_entry->h_proto = spec.ether_type;
907 mac_mask->h_proto = ETHER_TYPE_FULL_MASK;
908 }
Edward Creea7ad40d2016-02-05 11:16:50 +0000909 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
910 spec.ether_type == htons(ETH_P_IP) &&
911 !(spec.match_flags &
912 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
913 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
914 EFX_FILTER_MATCH_IP_PROTO))) {
915 rule->flow_type = IPV4_USER_FLOW;
916 uip_entry->ip_ver = ETH_RX_NFC_IP4;
917 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
918 uip_mask->proto = IP_PROTO_FULL_MASK;
919 uip_entry->proto = spec.ip_proto;
920 }
921 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
922 uip_entry->ip4dst = spec.loc_host[0];
923 uip_mask->ip4dst = IP4_ADDR_FULL_MASK;
924 }
925 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
926 uip_entry->ip4src = spec.rem_host[0];
927 uip_mask->ip4src = IP4_ADDR_FULL_MASK;
928 }
929 } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
930 spec.ether_type == htons(ETH_P_IPV6) &&
931 !(spec.match_flags &
932 ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID |
933 EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST |
934 EFX_FILTER_MATCH_IP_PROTO))) {
935 rule->flow_type = IPV6_USER_FLOW;
936 if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) {
937 uip6_mask->l4_proto = IP_PROTO_FULL_MASK;
938 uip6_entry->l4_proto = spec.ip_proto;
939 }
940 if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) {
941 memcpy(uip6_entry->ip6dst, spec.loc_host,
942 sizeof(uip6_entry->ip6dst));
943 ip6_fill_mask(uip6_mask->ip6dst);
944 }
945 if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) {
946 memcpy(uip6_entry->ip6src, spec.rem_host,
947 sizeof(uip6_entry->ip6src));
948 ip6_fill_mask(uip6_mask->ip6src);
949 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100950 } else {
951 /* The above should handle all filters that we insert */
952 WARN_ON(1);
953 return -EINVAL;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000954 }
955
Ben Hutchings7c460d92012-10-27 00:33:28 +0100956 if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) {
957 rule->flow_type |= FLOW_EXT;
958 rule->h_ext.vlan_tci = spec.outer_vid;
959 rule->m_ext.vlan_tci = htons(0xfff);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000960 }
Ben Hutchings7c460d92012-10-27 00:33:28 +0100961
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000962 return rc;
963}
964
Ben Hutchings765c9f42010-06-30 05:06:28 +0000965static int
966efx_ethtool_get_rxnfc(struct net_device *net_dev,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +0000967 struct ethtool_rxnfc *info, u32 *rule_locs)
Ben Hutchings765c9f42010-06-30 05:06:28 +0000968{
969 struct efx_nic *efx = netdev_priv(net_dev);
970
971 switch (info->cmd) {
972 case ETHTOOL_GRXRINGS:
973 info->data = efx->n_rx_channels;
974 return 0;
975
976 case ETHTOOL_GRXFH: {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000977 info->data = 0;
Edward Cree4fdda952017-01-04 15:10:56 +0000978 if (!efx->rss_active) /* No RSS */
979 return 0;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000980 switch (info->flow_type) {
Ben Hutchings765c9f42010-06-30 05:06:28 +0000981 case UDP_V4_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000982 if (efx->rx_hash_udp_4tuple)
983 /* fall through */
984 case TCP_V4_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_V4_FLOW:
988 case AH_ESP_V4_FLOW:
989 case IPV4_FLOW:
990 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000991 break;
Ben Hutchings765c9f42010-06-30 05:06:28 +0000992 case UDP_V6_FLOW:
Edward Creeb718c882016-11-03 22:12:58 +0000993 if (efx->rx_hash_udp_4tuple)
994 /* fall through */
995 case TCP_V6_FLOW:
996 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
997 /* fall through */
Ben Hutchings765c9f42010-06-30 05:06:28 +0000998 case SCTP_V6_FLOW:
999 case AH_ESP_V6_FLOW:
1000 case IPV6_FLOW:
1001 info->data |= RXH_IP_SRC | RXH_IP_DST;
Ben Hutchings765c9f42010-06-30 05:06:28 +00001002 break;
1003 default:
1004 break;
1005 }
Ben Hutchings765c9f42010-06-30 05:06:28 +00001006 return 0;
1007 }
1008
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001009 case ETHTOOL_GRXCLSRLCNT:
1010 info->data = efx_filter_get_rx_id_limit(efx);
1011 if (info->data == 0)
1012 return -EOPNOTSUPP;
1013 info->data |= RX_CLS_LOC_SPECIAL;
1014 info->rule_cnt =
1015 efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
1016 return 0;
1017
1018 case ETHTOOL_GRXCLSRULE:
1019 if (efx_filter_get_rx_id_limit(efx) == 0)
1020 return -EOPNOTSUPP;
1021 return efx_ethtool_get_class_rule(efx, &info->fs);
1022
1023 case ETHTOOL_GRXCLSRLALL: {
1024 s32 rc;
1025 info->data = efx_filter_get_rx_id_limit(efx);
1026 if (info->data == 0)
1027 return -EOPNOTSUPP;
1028 rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
1029 rule_locs, info->rule_cnt);
1030 if (rc < 0)
1031 return rc;
1032 info->rule_cnt = rc;
1033 return 0;
1034 }
1035
Ben Hutchings765c9f42010-06-30 05:06:28 +00001036 default:
1037 return -EOPNOTSUPP;
1038 }
1039}
1040
Edward Creea7ad40d2016-02-05 11:16:50 +00001041static inline bool ip6_mask_is_full(__be32 mask[4])
1042{
1043 return !~(mask[0] & mask[1] & mask[2] & mask[3]);
1044}
1045
1046static inline bool ip6_mask_is_empty(__be32 mask[4])
1047{
1048 return !(mask[0] | mask[1] | mask[2] | mask[3]);
1049}
1050
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001051static int efx_ethtool_set_class_rule(struct efx_nic *efx,
1052 struct ethtool_rx_flow_spec *rule)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001053{
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001054 struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
1055 struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
Edward Creea7ad40d2016-02-05 11:16:50 +00001056 struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec;
1057 struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec;
1058 struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec;
1059 struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec;
1060 struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec;
1061 struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec;
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001062 struct ethhdr *mac_entry = &rule->h_u.ether_spec;
1063 struct ethhdr *mac_mask = &rule->m_u.ether_spec;
1064 struct efx_filter_spec spec;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001065 int rc;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001066
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001067 /* Check that user wants us to choose the location */
Ben Hutchings9e0f9a12012-09-04 18:57:25 +01001068 if (rule->location != RX_CLS_LOC_ANY)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001069 return -EINVAL;
1070
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001071 /* Range-check ring_cookie */
1072 if (rule->ring_cookie >= efx->n_rx_channels &&
1073 rule->ring_cookie != RX_CLS_FLOW_DISC)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001074 return -EINVAL;
1075
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001076 /* Check for unsupported extensions */
1077 if ((rule->flow_type & FLOW_EXT) &&
Ben Hutchings0e0c3402012-09-06 02:11:04 +01001078 (rule->m_ext.vlan_etype || rule->m_ext.data[0] ||
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001079 rule->m_ext.data[1]))
1080 return -EINVAL;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001081
Ben Hutchings85740cdf2013-01-29 23:33:15 +00001082 efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
1083 efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001084 (rule->ring_cookie == RX_CLS_FLOW_DISC) ?
Ben Hutchingsf26e9582012-10-30 01:01:52 +00001085 EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie);
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001086
Ben Hutchings7c460d92012-10-27 00:33:28 +01001087 switch (rule->flow_type & ~FLOW_EXT) {
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001088 case TCP_V4_FLOW:
Ben Hutchings7c460d92012-10-27 00:33:28 +01001089 case UDP_V4_FLOW:
1090 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1091 EFX_FILTER_MATCH_IP_PROTO);
1092 spec.ether_type = htons(ETH_P_IP);
1093 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ?
1094 IPPROTO_TCP : IPPROTO_UDP);
1095 if (ip_mask->ip4dst) {
1096 if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1097 return -EINVAL;
1098 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1099 spec.loc_host[0] = ip_entry->ip4dst;
1100 }
1101 if (ip_mask->ip4src) {
1102 if (ip_mask->ip4src != IP4_ADDR_FULL_MASK)
1103 return -EINVAL;
1104 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1105 spec.rem_host[0] = ip_entry->ip4src;
1106 }
1107 if (ip_mask->pdst) {
1108 if (ip_mask->pdst != PORT_FULL_MASK)
1109 return -EINVAL;
1110 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1111 spec.loc_port = ip_entry->pdst;
1112 }
1113 if (ip_mask->psrc) {
1114 if (ip_mask->psrc != PORT_FULL_MASK)
1115 return -EINVAL;
1116 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1117 spec.rem_port = ip_entry->psrc;
1118 }
1119 if (ip_mask->tos)
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001120 return -EINVAL;
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001121 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001122
Edward Creea7ad40d2016-02-05 11:16:50 +00001123 case TCP_V6_FLOW:
1124 case UDP_V6_FLOW:
1125 spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE |
1126 EFX_FILTER_MATCH_IP_PROTO);
1127 spec.ether_type = htons(ETH_P_IPV6);
1128 spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ?
1129 IPPROTO_TCP : IPPROTO_UDP);
1130 if (!ip6_mask_is_empty(ip6_mask->ip6dst)) {
1131 if (!ip6_mask_is_full(ip6_mask->ip6dst))
1132 return -EINVAL;
1133 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1134 memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host));
1135 }
1136 if (!ip6_mask_is_empty(ip6_mask->ip6src)) {
1137 if (!ip6_mask_is_full(ip6_mask->ip6src))
1138 return -EINVAL;
1139 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1140 memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host));
1141 }
1142 if (ip6_mask->pdst) {
1143 if (ip6_mask->pdst != PORT_FULL_MASK)
1144 return -EINVAL;
1145 spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT;
1146 spec.loc_port = ip6_entry->pdst;
1147 }
1148 if (ip6_mask->psrc) {
1149 if (ip6_mask->psrc != PORT_FULL_MASK)
1150 return -EINVAL;
1151 spec.match_flags |= EFX_FILTER_MATCH_REM_PORT;
1152 spec.rem_port = ip6_entry->psrc;
1153 }
1154 if (ip6_mask->tclass)
1155 return -EINVAL;
1156 break;
1157
1158 case IPV4_USER_FLOW:
1159 if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver ||
1160 uip_entry->ip_ver != ETH_RX_NFC_IP4)
1161 return -EINVAL;
1162 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1163 spec.ether_type = htons(ETH_P_IP);
1164 if (uip_mask->ip4dst) {
1165 if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK)
1166 return -EINVAL;
1167 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1168 spec.loc_host[0] = uip_entry->ip4dst;
1169 }
1170 if (uip_mask->ip4src) {
1171 if (uip_mask->ip4src != IP4_ADDR_FULL_MASK)
1172 return -EINVAL;
1173 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1174 spec.rem_host[0] = uip_entry->ip4src;
1175 }
1176 if (uip_mask->proto) {
1177 if (uip_mask->proto != IP_PROTO_FULL_MASK)
1178 return -EINVAL;
1179 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1180 spec.ip_proto = uip_entry->proto;
1181 }
1182 break;
1183
1184 case IPV6_USER_FLOW:
1185 if (uip6_mask->l4_4_bytes || uip6_mask->tclass)
1186 return -EINVAL;
1187 spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE;
1188 spec.ether_type = htons(ETH_P_IPV6);
1189 if (!ip6_mask_is_empty(uip6_mask->ip6dst)) {
1190 if (!ip6_mask_is_full(uip6_mask->ip6dst))
1191 return -EINVAL;
1192 spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST;
1193 memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host));
1194 }
1195 if (!ip6_mask_is_empty(uip6_mask->ip6src)) {
1196 if (!ip6_mask_is_full(uip6_mask->ip6src))
1197 return -EINVAL;
1198 spec.match_flags |= EFX_FILTER_MATCH_REM_HOST;
1199 memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host));
1200 }
1201 if (uip6_mask->l4_proto) {
1202 if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK)
1203 return -EINVAL;
1204 spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO;
1205 spec.ip_proto = uip6_entry->l4_proto;
1206 }
1207 break;
1208
Ben Hutchings7c460d92012-10-27 00:33:28 +01001209 case ETHER_FLOW:
1210 if (!is_zero_ether_addr(mac_mask->h_dest)) {
1211 if (ether_addr_equal(mac_mask->h_dest,
1212 mac_addr_ig_mask))
1213 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG;
1214 else if (is_broadcast_ether_addr(mac_mask->h_dest))
1215 spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC;
Ben Hutchingsc274d652012-02-02 22:41:49 +00001216 else
Ben Hutchings7c460d92012-10-27 00:33:28 +01001217 return -EINVAL;
Edward Creecd84ff42014-03-07 18:27:41 +00001218 ether_addr_copy(spec.loc_mac, mac_entry->h_dest);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001219 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001220 if (!is_zero_ether_addr(mac_mask->h_source)) {
1221 if (!is_broadcast_ether_addr(mac_mask->h_source))
1222 return -EINVAL;
1223 spec.match_flags |= EFX_FILTER_MATCH_REM_MAC;
Edward Creecd84ff42014-03-07 18:27:41 +00001224 ether_addr_copy(spec.rem_mac, mac_entry->h_source);
Ben Hutchingsc274d652012-02-02 22:41:49 +00001225 }
Ben Hutchings7c460d92012-10-27 00:33:28 +01001226 if (mac_mask->h_proto) {
1227 if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK)
1228 return -EINVAL;
1229 spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1230 spec.ether_type = mac_entry->h_proto;
1231 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001232 break;
Ben Hutchingsc39d35e2010-12-07 19:11:26 +00001233
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001234 default:
1235 return -EINVAL;
1236 }
1237
Ben Hutchings7c460d92012-10-27 00:33:28 +01001238 if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) {
1239 if (rule->m_ext.vlan_tci != htons(0xfff))
1240 return -EINVAL;
1241 spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID;
1242 spec.outer_vid = rule->h_ext.vlan_tci;
1243 }
1244
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001245 rc = efx_filter_insert_filter(efx, &spec, true);
1246 if (rc < 0)
1247 return rc;
Ben Hutchings47a84672011-05-14 02:35:25 +01001248
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001249 rule->location = rc;
1250 return 0;
1251}
1252
1253static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1254 struct ethtool_rxnfc *info)
1255{
1256 struct efx_nic *efx = netdev_priv(net_dev);
1257
1258 if (efx_filter_get_rx_id_limit(efx) == 0)
1259 return -EOPNOTSUPP;
1260
1261 switch (info->cmd) {
1262 case ETHTOOL_SRXCLSRLINS:
1263 return efx_ethtool_set_class_rule(efx, &info->fs);
1264
1265 case ETHTOOL_SRXCLSRLDEL:
1266 return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1267 info->fs.location);
1268
1269 default:
1270 return -EOPNOTSUPP;
1271 }
Ben Hutchingsb4187e42010-09-20 08:43:42 +00001272}
1273
Ben Hutchings7850f632011-12-15 13:55:01 +00001274static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001275{
1276 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001277
Edward Cree5a6681e2016-11-28 18:55:34 +00001278 return (efx->n_rx_channels == 1) ? 0 : ARRAY_SIZE(efx->rx_indir_table);
Ben Hutchings7850f632011-12-15 13:55:01 +00001279}
Ben Hutchings765c9f42010-06-30 05:06:28 +00001280
Eyal Perry892311f2014-12-02 18:12:10 +02001281static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key,
1282 u8 *hfunc)
Ben Hutchings7850f632011-12-15 13:55:01 +00001283{
1284 struct efx_nic *efx = netdev_priv(net_dev);
1285
Eyal Perry892311f2014-12-02 18:12:10 +02001286 if (hfunc)
1287 *hfunc = ETH_RSS_HASH_TOP;
1288 if (indir)
1289 memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table));
Ben Hutchings765c9f42010-06-30 05:06:28 +00001290 return 0;
1291}
1292
Eyal Perry892311f2014-12-02 18:12:10 +02001293static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir,
1294 const u8 *key, const u8 hfunc)
Ben Hutchings765c9f42010-06-30 05:06:28 +00001295{
1296 struct efx_nic *efx = netdev_priv(net_dev);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001297
Eyal Perry892311f2014-12-02 18:12:10 +02001298 /* We do not allow change in unsupported parameters */
1299 if (key ||
1300 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1301 return -EOPNOTSUPP;
1302 if (!indir)
1303 return 0;
Jon Cooper267c0152015-05-06 00:59:38 +01001304
1305 return efx->type->rx_push_rss_config(efx, true, indir);
Ben Hutchings765c9f42010-06-30 05:06:28 +00001306}
1307
Fengguang Wub51ca342013-07-03 14:07:40 +08001308static int efx_ethtool_get_ts_info(struct net_device *net_dev,
1309 struct ethtool_ts_info *ts_info)
Ben Hutchings62ebac92013-04-08 17:34:58 +01001310{
1311 struct efx_nic *efx = netdev_priv(net_dev);
1312
1313 /* Software capabilities */
1314 ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE |
1315 SOF_TIMESTAMPING_SOFTWARE);
1316 ts_info->phc_index = -1;
1317
1318 efx_ptp_get_ts_info(efx, ts_info);
1319 return 0;
1320}
1321
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001322static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
1323 struct ethtool_eeprom *ee,
1324 u8 *data)
1325{
1326 struct efx_nic *efx = netdev_priv(net_dev);
1327 int ret;
1328
1329 if (!efx->phy_op || !efx->phy_op->get_module_eeprom)
1330 return -EOPNOTSUPP;
1331
1332 mutex_lock(&efx->mac_lock);
1333 ret = efx->phy_op->get_module_eeprom(efx, ee, data);
1334 mutex_unlock(&efx->mac_lock);
1335
1336 return ret;
1337}
1338
1339static int efx_ethtool_get_module_info(struct net_device *net_dev,
1340 struct ethtool_modinfo *modinfo)
1341{
1342 struct efx_nic *efx = netdev_priv(net_dev);
1343 int ret;
1344
1345 if (!efx->phy_op || !efx->phy_op->get_module_info)
1346 return -EOPNOTSUPP;
1347
1348 mutex_lock(&efx->mac_lock);
1349 ret = efx->phy_op->get_module_info(efx, modinfo);
1350 mutex_unlock(&efx->mac_lock);
1351
1352 return ret;
1353}
1354
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001355const struct ethtool_ops efx_ethtool_ops = {
Ben Hutchings8ceee662008-04-27 12:55:59 +01001356 .get_drvinfo = efx_ethtool_get_drvinfo,
Ben Hutchings5b98c1b2010-06-21 03:06:53 +00001357 .get_regs_len = efx_ethtool_get_regs_len,
1358 .get_regs = efx_ethtool_get_regs,
Ben Hutchings62776d02010-06-23 11:30:07 +00001359 .get_msglevel = efx_ethtool_get_msglevel,
1360 .set_msglevel = efx_ethtool_set_msglevel,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001361 .nway_reset = efx_ethtool_nway_reset,
Ben Hutchingsed4ba4b2010-12-09 12:10:25 +00001362 .get_link = ethtool_op_get_link,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001363 .get_coalesce = efx_ethtool_get_coalesce,
1364 .set_coalesce = efx_ethtool_set_coalesce,
Ben Hutchings46426102010-09-10 06:42:33 +00001365 .get_ringparam = efx_ethtool_get_ringparam,
1366 .set_ringparam = efx_ethtool_set_ringparam,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001367 .get_pauseparam = efx_ethtool_get_pauseparam,
1368 .set_pauseparam = efx_ethtool_set_pauseparam,
Ben Hutchings3594e132008-09-01 12:48:12 +01001369 .get_sset_count = efx_ethtool_get_sset_count,
Ben Hutchings3273c2e2008-05-07 13:36:19 +01001370 .self_test = efx_ethtool_self_test,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001371 .get_strings = efx_ethtool_get_strings,
Ben Hutchingsc5e129a2011-04-02 00:43:46 +01001372 .set_phys_id = efx_ethtool_phys_id,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001373 .get_ethtool_stats = efx_ethtool_get_stats,
Ben Hutchings89c758f2009-11-29 03:43:07 +00001374 .get_wol = efx_ethtool_get_wol,
1375 .set_wol = efx_ethtool_set_wol,
Ben Hutchingseb9f6742009-11-29 03:43:15 +00001376 .reset = efx_ethtool_reset,
Ben Hutchings765c9f42010-06-30 05:06:28 +00001377 .get_rxnfc = efx_ethtool_get_rxnfc,
Ben Hutchingsb2bb7b72012-01-03 12:05:47 +00001378 .set_rxnfc = efx_ethtool_set_rxnfc,
Ben Hutchings7850f632011-12-15 13:55:01 +00001379 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
Ben Hutchingsfe62d002014-05-15 01:25:27 +01001380 .get_rxfh = efx_ethtool_get_rxfh,
1381 .set_rxfh = efx_ethtool_set_rxfh,
Ben Hutchings62ebac92013-04-08 17:34:58 +01001382 .get_ts_info = efx_ethtool_get_ts_info,
Stuart Hodgsonc087bd22012-05-01 18:50:43 +01001383 .get_module_info = efx_ethtool_get_module_info,
1384 .get_module_eeprom = efx_ethtool_get_module_eeprom,
Philippe Reynes7cafe8f2016-12-15 00:12:53 +01001385 .get_link_ksettings = efx_ethtool_get_link_ksettings,
1386 .set_link_ksettings = efx_ethtool_set_link_ksettings,
Ben Hutchings8ceee662008-04-27 12:55:59 +01001387};