| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/**************************************************************************** |
| 3 |
* Driver for Solarflare network controllers and boards |
| 4 |
* Copyright 2019 Solarflare Communications Inc. |
| 5 |
* |
| 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 |
#include <linux/module.h> |
| 11 |
#include <linux/netdevice.h> |
| 12 |
#include "net_driver.h" |
| 13 |
#include "mcdi.h" |
| 14 |
#include "nic.h" |
| 15 |
#include "selftest.h" |
| 16 |
#include "rx_common.h" |
| 17 |
#include "ethtool_common.h" |
| 18 |
#include "mcdi_port_common.h" |
| 19 |
|
| 20 |
struct efx_sw_stat_desc { |
| 21 |
const char *name; |
| 22 |
enum { |
| 23 |
EFX_ETHTOOL_STAT_SOURCE_nic, |
| 24 |
EFX_ETHTOOL_STAT_SOURCE_channel, |
| 25 |
EFX_ETHTOOL_STAT_SOURCE_tx_queue |
| 26 |
} source; |
| 27 |
unsigned int offset; |
| 28 |
u64 (*get_stat)(void *field); /* Reader function */ |
| 29 |
}; |
| 30 |
|
| 31 |
/* Initialiser for a struct efx_sw_stat_desc with type-checking */ |
| 32 |
#define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ |
| 33 |
get_stat_function) { \ |
| 34 |
.name = #stat_name, \ |
| 35 |
.source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ |
| 36 |
.offset = ((((field_type *) 0) == \ |
| 37 |
&((struct efx_##source_name *)0)->field) ? \ |
| 38 |
offsetof(struct efx_##source_name, field) : \ |
| 39 |
offsetof(struct efx_##source_name, field)), \ |
| 40 |
.get_stat = get_stat_function, \ |
| 41 |
} |
| 42 |
|
| 43 |
static u64 efx_get_uint_stat(void *field) |
| 44 |
{ |
| 45 |
return *(unsigned int *)field; |
| 46 |
} |
| 47 |
|
| 48 |
static u64 efx_get_atomic_stat(void *field) |
| 49 |
{ |
| 50 |
return atomic_read((atomic_t *) field); |
| 51 |
} |
| 52 |
|
| 53 |
#define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ |
| 54 |
EFX_ETHTOOL_STAT(field, nic, field, \ |
| 55 |
atomic_t, efx_get_atomic_stat) |
| 56 |
|
| 57 |
#define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ |
| 58 |
EFX_ETHTOOL_STAT(field, channel, n_##field, \ |
| 59 |
unsigned int, efx_get_uint_stat) |
| 60 |
#define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field) \ |
| 61 |
EFX_ETHTOOL_STAT(field, channel, field, \ |
| 62 |
unsigned int, efx_get_uint_stat) |
| 63 |
|
| 64 |
#define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ |
| 65 |
EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ |
| 66 |
unsigned int, efx_get_uint_stat) |
| 67 |
|
| 68 |
static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { |
| 69 |
EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), |
| 70 |
EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), |
| 71 |
EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), |
| 72 |
EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), |
| 73 |
EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks), |
| 74 |
EFX_ETHTOOL_UINT_TXQ_STAT(pushes), |
| 75 |
EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), |
| 76 |
EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), |
| 77 |
EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
| 78 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), |
| 79 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), |
| 80 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), |
| 81 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err), |
| 82 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err), |
| 83 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err), |
| 84 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err), |
| 85 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err), |
| 86 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
| 87 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
| 88 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), |
| 89 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), |
| 90 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops), |
| 91 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops), |
| 92 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx), |
| 93 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect), |
| 94 |
#ifdef CONFIG_RFS_ACCEL |
| 95 |
EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count), |
| 96 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded), |
| 97 |
EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed), |
| 98 |
#endif |
| 99 |
}; |
| 100 |
|
| 101 |
#define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) |
| 102 |
|
| 103 |
void efx_siena_ethtool_get_drvinfo(struct net_device *net_dev, |
| 104 |
struct ethtool_drvinfo *info) |
| 105 |
{ |
| 106 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 107 |
|
| 108 |
strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
| 109 |
efx_siena_mcdi_print_fwver(efx, info->fw_version, |
| 110 |
sizeof(info->fw_version)); |
| 111 |
strscpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
| 112 |
} |
| 113 |
|
| 114 |
u32 efx_siena_ethtool_get_msglevel(struct net_device *net_dev) |
| 115 |
{ |
| 116 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 117 |
|
| 118 |
return efx->msg_enable; |
| 119 |
} |
| 120 |
|
| 121 |
void efx_siena_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) |
| 122 |
{ |
| 123 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 124 |
|
| 125 |
efx->msg_enable = msg_enable; |
| 126 |
} |
| 127 |
|
| 128 |
void efx_siena_ethtool_get_pauseparam(struct net_device *net_dev, |
| 129 |
struct ethtool_pauseparam *pause) |
| 130 |
{ |
| 131 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 132 |
|
| 133 |
pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
| 134 |
pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); |
| 135 |
pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); |
| 136 |
} |
| 137 |
|
| 138 |
int efx_siena_ethtool_set_pauseparam(struct net_device *net_dev, |
| 139 |
struct ethtool_pauseparam *pause) |
| 140 |
{ |
| 141 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 142 |
u8 wanted_fc, old_fc; |
| 143 |
u32 old_adv; |
| 144 |
int rc = 0; |
| 145 |
|
| 146 |
mutex_lock(&efx->mac_lock); |
| 147 |
|
| 148 |
wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
| 149 |
(pause->tx_pause ? EFX_FC_TX : 0) | |
| 150 |
(pause->autoneg ? EFX_FC_AUTO : 0)); |
| 151 |
|
| 152 |
if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { |
| 153 |
netif_dbg(efx, drv, efx->net_dev, |
| 154 |
"Flow control unsupported: tx ON rx OFF\n"); |
| 155 |
rc = -EINVAL; |
| 156 |
goto out; |
| 157 |
} |
| 158 |
|
| 159 |
if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising[0]) { |
| 160 |
netif_dbg(efx, drv, efx->net_dev, |
| 161 |
"Autonegotiation is disabled\n"); |
| 162 |
rc = -EINVAL; |
| 163 |
goto out; |
| 164 |
} |
| 165 |
|
| 166 |
/* Hook for Falcon bug 11482 workaround */ |
| 167 |
if (efx->type->prepare_enable_fc_tx && |
| 168 |
(wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) |
| 169 |
efx->type->prepare_enable_fc_tx(efx); |
| 170 |
|
| 171 |
old_adv = efx->link_advertising[0]; |
| 172 |
old_fc = efx->wanted_fc; |
| 173 |
efx_siena_link_set_wanted_fc(efx, wanted_fc); |
| 174 |
if (efx->link_advertising[0] != old_adv || |
| 175 |
(efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { |
| 176 |
rc = efx_siena_mcdi_port_reconfigure(efx); |
| 177 |
if (rc) { |
| 178 |
netif_err(efx, drv, efx->net_dev, |
| 179 |
"Unable to advertise requested flow " |
| 180 |
"control setting\n"); |
| 181 |
goto out; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
/* Reconfigure the MAC. The PHY *may* generate a link state change event |
| 186 |
* if the user just changed the advertised capabilities, but there's no |
| 187 |
* harm doing this twice */ |
| 188 |
efx_siena_mac_reconfigure(efx, false); |
| 189 |
|
| 190 |
out: |
| 191 |
mutex_unlock(&efx->mac_lock); |
| 192 |
|
| 193 |
return rc; |
| 194 |
} |
| 195 |
|
| 196 |
/** |
| 197 |
* efx_fill_test - fill in an individual self-test entry |
| 198 |
* @test_index: Index of the test |
| 199 |
* @strings: Ethtool strings, or %NULL |
| 200 |
* @data: Ethtool test results, or %NULL |
| 201 |
* @test: Pointer to test result (used only if data != %NULL) |
| 202 |
* @unit_format: Unit name format (e.g. "chan\%d") |
| 203 |
* @unit_id: Unit id (e.g. 0 for "chan0") |
| 204 |
* @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
| 205 |
* @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
| 206 |
* |
| 207 |
* Fill in an individual self-test entry. |
| 208 |
*/ |
| 209 |
static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, |
| 210 |
int *test, const char *unit_format, int unit_id, |
| 211 |
const char *test_format, const char *test_id) |
| 212 |
{ |
| 213 |
char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; |
| 214 |
|
| 215 |
/* Fill data value, if applicable */ |
| 216 |
if (data) |
| 217 |
data[test_index] = *test; |
| 218 |
|
| 219 |
/* Fill string, if applicable */ |
| 220 |
if (strings) { |
| 221 |
if (strchr(unit_format, '%')) |
| 222 |
snprintf(unit_str, sizeof(unit_str), |
| 223 |
unit_format, unit_id); |
| 224 |
else |
| 225 |
strcpy(unit_str, unit_format); |
| 226 |
snprintf(test_str, sizeof(test_str), test_format, test_id); |
| 227 |
snprintf(strings + test_index * ETH_GSTRING_LEN, |
| 228 |
ETH_GSTRING_LEN, |
| 229 |
"%-6s %-24s", unit_str, test_str); |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
#define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
| 234 |
#define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->label |
| 235 |
#define EFX_LOOPBACK_NAME(_mode, _counter) \ |
| 236 |
"loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_siena_loopback_mode) |
| 237 |
|
| 238 |
/** |
| 239 |
* efx_fill_loopback_test - fill in a block of loopback self-test entries |
| 240 |
* @efx: Efx NIC |
| 241 |
* @lb_tests: Efx loopback self-test results structure |
| 242 |
* @mode: Loopback test mode |
| 243 |
* @test_index: Starting index of the test |
| 244 |
* @strings: Ethtool strings, or %NULL |
| 245 |
* @data: Ethtool test results, or %NULL |
| 246 |
* |
| 247 |
* Fill in a block of loopback self-test entries. Return new test |
| 248 |
* index. |
| 249 |
*/ |
| 250 |
static int efx_fill_loopback_test(struct efx_nic *efx, |
| 251 |
struct efx_loopback_self_tests *lb_tests, |
| 252 |
enum efx_loopback_mode mode, |
| 253 |
unsigned int test_index, |
| 254 |
u8 *strings, u64 *data) |
| 255 |
{ |
| 256 |
struct efx_channel *channel = |
| 257 |
efx_get_channel(efx, efx->tx_channel_offset); |
| 258 |
struct efx_tx_queue *tx_queue; |
| 259 |
|
| 260 |
efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 261 |
efx_fill_test(test_index++, strings, data, |
| 262 |
&lb_tests->tx_sent[tx_queue->label], |
| 263 |
EFX_TX_QUEUE_NAME(tx_queue), |
| 264 |
EFX_LOOPBACK_NAME(mode, "tx_sent")); |
| 265 |
efx_fill_test(test_index++, strings, data, |
| 266 |
&lb_tests->tx_done[tx_queue->label], |
| 267 |
EFX_TX_QUEUE_NAME(tx_queue), |
| 268 |
EFX_LOOPBACK_NAME(mode, "tx_done")); |
| 269 |
} |
| 270 |
efx_fill_test(test_index++, strings, data, |
| 271 |
&lb_tests->rx_good, |
| 272 |
"rx", 0, |
| 273 |
EFX_LOOPBACK_NAME(mode, "rx_good")); |
| 274 |
efx_fill_test(test_index++, strings, data, |
| 275 |
&lb_tests->rx_bad, |
| 276 |
"rx", 0, |
| 277 |
EFX_LOOPBACK_NAME(mode, "rx_bad")); |
| 278 |
|
| 279 |
return test_index; |
| 280 |
} |
| 281 |
|
| 282 |
/** |
| 283 |
* efx_ethtool_fill_self_tests - get self-test details |
| 284 |
* @efx: Efx NIC |
| 285 |
* @tests: Efx self-test results structure, or %NULL |
| 286 |
* @strings: Ethtool strings, or %NULL |
| 287 |
* @data: Ethtool test results, or %NULL |
| 288 |
* |
| 289 |
* Get self-test number of strings, strings, and/or test results. |
| 290 |
* Return number of strings (== number of test results). |
| 291 |
* |
| 292 |
* The reason for merging these three functions is to make sure that |
| 293 |
* they can never be inconsistent. |
| 294 |
*/ |
| 295 |
static int efx_ethtool_fill_self_tests(struct efx_nic *efx, |
| 296 |
struct efx_self_tests *tests, |
| 297 |
u8 *strings, u64 *data) |
| 298 |
{ |
| 299 |
struct efx_channel *channel; |
| 300 |
unsigned int n = 0, i; |
| 301 |
enum efx_loopback_mode mode; |
| 302 |
|
| 303 |
efx_fill_test(n++, strings, data, &tests->phy_alive, |
| 304 |
"phy", 0, "alive", NULL); |
| 305 |
efx_fill_test(n++, strings, data, &tests->nvram, |
| 306 |
"core", 0, "nvram", NULL); |
| 307 |
efx_fill_test(n++, strings, data, &tests->interrupt, |
| 308 |
"core", 0, "interrupt", NULL); |
| 309 |
|
| 310 |
/* Event queues */ |
| 311 |
efx_for_each_channel(channel, efx) { |
| 312 |
efx_fill_test(n++, strings, data, |
| 313 |
&tests->eventq_dma[channel->channel], |
| 314 |
EFX_CHANNEL_NAME(channel), |
| 315 |
"eventq.dma", NULL); |
| 316 |
efx_fill_test(n++, strings, data, |
| 317 |
&tests->eventq_int[channel->channel], |
| 318 |
EFX_CHANNEL_NAME(channel), |
| 319 |
"eventq.int", NULL); |
| 320 |
} |
| 321 |
|
| 322 |
efx_fill_test(n++, strings, data, &tests->memory, |
| 323 |
"core", 0, "memory", NULL); |
| 324 |
efx_fill_test(n++, strings, data, &tests->registers, |
| 325 |
"core", 0, "registers", NULL); |
| 326 |
|
| 327 |
for (i = 0; true; ++i) { |
| 328 |
const char *name; |
| 329 |
|
| 330 |
EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); |
| 331 |
name = efx_siena_mcdi_phy_test_name(efx, i); |
| 332 |
if (name == NULL) |
| 333 |
break; |
| 334 |
|
| 335 |
efx_fill_test(n++, strings, data, &tests->phy_ext[i], "phy", 0, name, NULL); |
| 336 |
} |
| 337 |
|
| 338 |
/* Loopback tests */ |
| 339 |
for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
| 340 |
if (!(efx->loopback_modes & (1 << mode))) |
| 341 |
continue; |
| 342 |
n = efx_fill_loopback_test(efx, |
| 343 |
&tests->loopback[mode], mode, n, |
| 344 |
strings, data); |
| 345 |
} |
| 346 |
|
| 347 |
return n; |
| 348 |
} |
| 349 |
|
| 350 |
void efx_siena_ethtool_self_test(struct net_device *net_dev, |
| 351 |
struct ethtool_test *test, u64 *data) |
| 352 |
{ |
| 353 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 354 |
struct efx_self_tests *efx_tests; |
| 355 |
bool already_up; |
| 356 |
int rc = -ENOMEM; |
| 357 |
|
| 358 |
efx_tests = kzalloc_obj(*efx_tests); |
| 359 |
if (!efx_tests) |
| 360 |
goto fail; |
| 361 |
|
| 362 |
if (efx->state != STATE_READY) { |
| 363 |
rc = -EBUSY; |
| 364 |
goto out; |
| 365 |
} |
| 366 |
|
| 367 |
netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
| 368 |
(test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
| 369 |
|
| 370 |
/* We need rx buffers and interrupts. */ |
| 371 |
already_up = (efx->net_dev->flags & IFF_UP); |
| 372 |
if (!already_up) { |
| 373 |
rc = dev_open(efx->net_dev, NULL); |
| 374 |
if (rc) { |
| 375 |
netif_err(efx, drv, efx->net_dev, |
| 376 |
"failed opening device.\n"); |
| 377 |
goto out; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
rc = efx_siena_selftest(efx, efx_tests, test->flags); |
| 382 |
|
| 383 |
if (!already_up) |
| 384 |
dev_close(efx->net_dev); |
| 385 |
|
| 386 |
netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
| 387 |
rc == 0 ? "passed" : "failed", |
| 388 |
(test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
| 389 |
|
| 390 |
out: |
| 391 |
efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
| 392 |
kfree(efx_tests); |
| 393 |
fail: |
| 394 |
if (rc) |
| 395 |
test->flags |= ETH_TEST_FL_FAILED; |
| 396 |
} |
| 397 |
|
| 398 |
static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 **strings) |
| 399 |
{ |
| 400 |
size_t n_stats = 0; |
| 401 |
struct efx_channel *channel; |
| 402 |
|
| 403 |
efx_for_each_channel(channel, efx) { |
| 404 |
if (efx_channel_has_tx_queues(channel)) { |
| 405 |
n_stats++; |
| 406 |
if (!strings) |
| 407 |
continue; |
| 408 |
|
| 409 |
ethtool_sprintf(strings, "tx-%u.tx_packets", |
| 410 |
channel->tx_queue[0].queue / |
| 411 |
EFX_MAX_TXQ_PER_CHANNEL); |
| 412 |
} |
| 413 |
} |
| 414 |
efx_for_each_channel(channel, efx) { |
| 415 |
if (efx_channel_has_rx_queue(channel)) { |
| 416 |
n_stats++; |
| 417 |
if (!strings) |
| 418 |
continue; |
| 419 |
|
| 420 |
ethtool_sprintf(strings, "rx-%d.rx_packets", |
| 421 |
channel->channel); |
| 422 |
} |
| 423 |
} |
| 424 |
if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { |
| 425 |
unsigned short xdp; |
| 426 |
|
| 427 |
for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { |
| 428 |
n_stats++; |
| 429 |
if (!strings) |
| 430 |
continue; |
| 431 |
|
| 432 |
ethtool_sprintf(strings, "tx-xdp-cpu-%hu.tx_packets", |
| 433 |
xdp); |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
return n_stats; |
| 438 |
} |
| 439 |
|
| 440 |
int efx_siena_ethtool_get_sset_count(struct net_device *net_dev, int string_set) |
| 441 |
{ |
| 442 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 443 |
|
| 444 |
switch (string_set) { |
| 445 |
case ETH_SS_STATS: |
| 446 |
return efx->type->describe_stats(efx, NULL) + |
| 447 |
EFX_ETHTOOL_SW_STAT_COUNT + |
| 448 |
efx_describe_per_queue_stats(efx, NULL) + |
| 449 |
efx_siena_ptp_describe_stats(efx, NULL); |
| 450 |
case ETH_SS_TEST: |
| 451 |
return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
| 452 |
default: |
| 453 |
return -EINVAL; |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
void efx_siena_ethtool_get_strings(struct net_device *net_dev, |
| 458 |
u32 string_set, u8 *strings) |
| 459 |
{ |
| 460 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 461 |
int i; |
| 462 |
|
| 463 |
switch (string_set) { |
| 464 |
case ETH_SS_STATS: |
| 465 |
efx->type->describe_stats(efx, &strings); |
| 466 |
for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) |
| 467 |
ethtool_puts(&strings, efx_sw_stat_desc[i].name); |
| 468 |
efx_describe_per_queue_stats(efx, &strings); |
| 469 |
efx_siena_ptp_describe_stats(efx, &strings); |
| 470 |
break; |
| 471 |
case ETH_SS_TEST: |
| 472 |
efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
| 473 |
break; |
| 474 |
default: |
| 475 |
/* No other string sets */ |
| 476 |
break; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
void efx_siena_ethtool_get_stats(struct net_device *net_dev, |
| 481 |
struct ethtool_stats *stats, |
| 482 |
u64 *data) |
| 483 |
{ |
| 484 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 485 |
const struct efx_sw_stat_desc *stat; |
| 486 |
struct efx_channel *channel; |
| 487 |
struct efx_tx_queue *tx_queue; |
| 488 |
struct efx_rx_queue *rx_queue; |
| 489 |
int i; |
| 490 |
|
| 491 |
spin_lock_bh(&efx->stats_lock); |
| 492 |
|
| 493 |
/* Get NIC statistics */ |
| 494 |
data += efx->type->update_stats(efx, data, NULL); |
| 495 |
|
| 496 |
/* Get software statistics */ |
| 497 |
for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { |
| 498 |
stat = &efx_sw_stat_desc[i]; |
| 499 |
switch (stat->source) { |
| 500 |
case EFX_ETHTOOL_STAT_SOURCE_nic: |
| 501 |
data[i] = stat->get_stat((void *)efx + stat->offset); |
| 502 |
break; |
| 503 |
case EFX_ETHTOOL_STAT_SOURCE_channel: |
| 504 |
data[i] = 0; |
| 505 |
efx_for_each_channel(channel, efx) |
| 506 |
data[i] += stat->get_stat((void *)channel + |
| 507 |
stat->offset); |
| 508 |
break; |
| 509 |
case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
| 510 |
data[i] = 0; |
| 511 |
efx_for_each_channel(channel, efx) { |
| 512 |
efx_for_each_channel_tx_queue(tx_queue, channel) |
| 513 |
data[i] += |
| 514 |
stat->get_stat((void *)tx_queue |
| 515 |
+ stat->offset); |
| 516 |
} |
| 517 |
break; |
| 518 |
} |
| 519 |
} |
| 520 |
data += EFX_ETHTOOL_SW_STAT_COUNT; |
| 521 |
|
| 522 |
spin_unlock_bh(&efx->stats_lock); |
| 523 |
|
| 524 |
efx_for_each_channel(channel, efx) { |
| 525 |
if (efx_channel_has_tx_queues(channel)) { |
| 526 |
*data = 0; |
| 527 |
efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 528 |
*data += tx_queue->tx_packets; |
| 529 |
} |
| 530 |
data++; |
| 531 |
} |
| 532 |
} |
| 533 |
efx_for_each_channel(channel, efx) { |
| 534 |
if (efx_channel_has_rx_queue(channel)) { |
| 535 |
*data = 0; |
| 536 |
efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 537 |
*data += rx_queue->rx_packets; |
| 538 |
} |
| 539 |
data++; |
| 540 |
} |
| 541 |
} |
| 542 |
if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { |
| 543 |
int xdp; |
| 544 |
|
| 545 |
for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { |
| 546 |
data[0] = efx->xdp_tx_queues[xdp]->tx_packets; |
| 547 |
data++; |
| 548 |
} |
| 549 |
} |
| 550 |
|
| 551 |
efx_siena_ptp_update_stats(efx, data); |
| 552 |
} |
| 553 |
|
| 554 |
/* This must be called with rtnl_lock held. */ |
| 555 |
int efx_siena_ethtool_get_link_ksettings(struct net_device *net_dev, |
| 556 |
struct ethtool_link_ksettings *cmd) |
| 557 |
{ |
| 558 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 559 |
struct efx_link_state *link_state = &efx->link_state; |
| 560 |
|
| 561 |
mutex_lock(&efx->mac_lock); |
| 562 |
efx_siena_mcdi_phy_get_link_ksettings(efx, cmd); |
| 563 |
mutex_unlock(&efx->mac_lock); |
| 564 |
|
| 565 |
/* Both MACs support pause frames (bidirectional and respond-only) */ |
| 566 |
ethtool_link_ksettings_add_link_mode(cmd, supported, Pause); |
| 567 |
ethtool_link_ksettings_add_link_mode(cmd, supported, Asym_Pause); |
| 568 |
|
| 569 |
if (LOOPBACK_INTERNAL(efx)) { |
| 570 |
cmd->base.speed = link_state->speed; |
| 571 |
cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
| 572 |
} |
| 573 |
|
| 574 |
return 0; |
| 575 |
} |
| 576 |
|
| 577 |
/* This must be called with rtnl_lock held. */ |
| 578 |
int |
| 579 |
efx_siena_ethtool_set_link_ksettings(struct net_device *net_dev, |
| 580 |
const struct ethtool_link_ksettings *cmd) |
| 581 |
{ |
| 582 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 583 |
int rc; |
| 584 |
|
| 585 |
/* GMAC does not support 1000Mbps HD */ |
| 586 |
if ((cmd->base.speed == SPEED_1000) && |
| 587 |
(cmd->base.duplex != DUPLEX_FULL)) { |
| 588 |
netif_dbg(efx, drv, efx->net_dev, |
| 589 |
"rejecting unsupported 1000Mbps HD setting\n"); |
| 590 |
return -EINVAL; |
| 591 |
} |
| 592 |
|
| 593 |
mutex_lock(&efx->mac_lock); |
| 594 |
rc = efx_siena_mcdi_phy_set_link_ksettings(efx, cmd); |
| 595 |
mutex_unlock(&efx->mac_lock); |
| 596 |
return rc; |
| 597 |
} |
| 598 |
|
| 599 |
int efx_siena_ethtool_get_fecparam(struct net_device *net_dev, |
| 600 |
struct ethtool_fecparam *fecparam) |
| 601 |
{ |
| 602 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 603 |
int rc; |
| 604 |
|
| 605 |
mutex_lock(&efx->mac_lock); |
| 606 |
rc = efx_siena_mcdi_phy_get_fecparam(efx, fecparam); |
| 607 |
mutex_unlock(&efx->mac_lock); |
| 608 |
|
| 609 |
return rc; |
| 610 |
} |
| 611 |
|
| 612 |
int efx_siena_ethtool_set_fecparam(struct net_device *net_dev, |
| 613 |
struct ethtool_fecparam *fecparam) |
| 614 |
{ |
| 615 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 616 |
int rc; |
| 617 |
|
| 618 |
mutex_lock(&efx->mac_lock); |
| 619 |
rc = efx_siena_mcdi_phy_set_fecparam(efx, fecparam); |
| 620 |
mutex_unlock(&efx->mac_lock); |
| 621 |
|
| 622 |
return rc; |
| 623 |
} |
| 624 |
|
| 625 |
/* MAC address mask including only I/G bit */ |
| 626 |
static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0}; |
| 627 |
|
| 628 |
#define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
| 629 |
#define IP_PROTO_FULL_MASK 0xFF |
| 630 |
#define PORT_FULL_MASK ((__force __be16)~0) |
| 631 |
#define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
| 632 |
|
| 633 |
static inline void ip6_fill_mask(__be32 *mask) |
| 634 |
{ |
| 635 |
mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0; |
| 636 |
} |
| 637 |
|
| 638 |
static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
| 639 |
struct ethtool_rx_flow_spec *rule, |
| 640 |
u32 *rss_context) |
| 641 |
{ |
| 642 |
struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 643 |
struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
| 644 |
struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
| 645 |
struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; |
| 646 |
struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; |
| 647 |
struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; |
| 648 |
struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; |
| 649 |
struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; |
| 650 |
struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 651 |
struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
| 652 |
struct efx_filter_spec spec; |
| 653 |
int rc; |
| 654 |
|
| 655 |
rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 656 |
rule->location, &spec); |
| 657 |
if (rc) |
| 658 |
return rc; |
| 659 |
|
| 660 |
if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
| 661 |
rule->ring_cookie = RX_CLS_FLOW_DISC; |
| 662 |
else |
| 663 |
rule->ring_cookie = spec.dmaq_id; |
| 664 |
|
| 665 |
if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
| 666 |
spec.ether_type == htons(ETH_P_IP) && |
| 667 |
(spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && |
| 668 |
(spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && |
| 669 |
!(spec.match_flags & |
| 670 |
~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 671 |
EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 672 |
EFX_FILTER_MATCH_IP_PROTO | |
| 673 |
EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { |
| 674 |
rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? |
| 675 |
TCP_V4_FLOW : UDP_V4_FLOW); |
| 676 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 677 |
ip_entry->ip4dst = spec.loc_host[0]; |
| 678 |
ip_mask->ip4dst = IP4_ADDR_FULL_MASK; |
| 679 |
} |
| 680 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 681 |
ip_entry->ip4src = spec.rem_host[0]; |
| 682 |
ip_mask->ip4src = IP4_ADDR_FULL_MASK; |
| 683 |
} |
| 684 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { |
| 685 |
ip_entry->pdst = spec.loc_port; |
| 686 |
ip_mask->pdst = PORT_FULL_MASK; |
| 687 |
} |
| 688 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { |
| 689 |
ip_entry->psrc = spec.rem_port; |
| 690 |
ip_mask->psrc = PORT_FULL_MASK; |
| 691 |
} |
| 692 |
} else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
| 693 |
spec.ether_type == htons(ETH_P_IPV6) && |
| 694 |
(spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && |
| 695 |
(spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && |
| 696 |
!(spec.match_flags & |
| 697 |
~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 698 |
EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 699 |
EFX_FILTER_MATCH_IP_PROTO | |
| 700 |
EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { |
| 701 |
rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? |
| 702 |
TCP_V6_FLOW : UDP_V6_FLOW); |
| 703 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 704 |
memcpy(ip6_entry->ip6dst, spec.loc_host, |
| 705 |
sizeof(ip6_entry->ip6dst)); |
| 706 |
ip6_fill_mask(ip6_mask->ip6dst); |
| 707 |
} |
| 708 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 709 |
memcpy(ip6_entry->ip6src, spec.rem_host, |
| 710 |
sizeof(ip6_entry->ip6src)); |
| 711 |
ip6_fill_mask(ip6_mask->ip6src); |
| 712 |
} |
| 713 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { |
| 714 |
ip6_entry->pdst = spec.loc_port; |
| 715 |
ip6_mask->pdst = PORT_FULL_MASK; |
| 716 |
} |
| 717 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { |
| 718 |
ip6_entry->psrc = spec.rem_port; |
| 719 |
ip6_mask->psrc = PORT_FULL_MASK; |
| 720 |
} |
| 721 |
} else if (!(spec.match_flags & |
| 722 |
~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | |
| 723 |
EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | |
| 724 |
EFX_FILTER_MATCH_OUTER_VID))) { |
| 725 |
rule->flow_type = ETHER_FLOW; |
| 726 |
if (spec.match_flags & |
| 727 |
(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { |
| 728 |
ether_addr_copy(mac_entry->h_dest, spec.loc_mac); |
| 729 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) |
| 730 |
eth_broadcast_addr(mac_mask->h_dest); |
| 731 |
else |
| 732 |
ether_addr_copy(mac_mask->h_dest, |
| 733 |
mac_addr_ig_mask); |
| 734 |
} |
| 735 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
| 736 |
ether_addr_copy(mac_entry->h_source, spec.rem_mac); |
| 737 |
eth_broadcast_addr(mac_mask->h_source); |
| 738 |
} |
| 739 |
if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { |
| 740 |
mac_entry->h_proto = spec.ether_type; |
| 741 |
mac_mask->h_proto = ETHER_TYPE_FULL_MASK; |
| 742 |
} |
| 743 |
} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
| 744 |
spec.ether_type == htons(ETH_P_IP) && |
| 745 |
!(spec.match_flags & |
| 746 |
~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 747 |
EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 748 |
EFX_FILTER_MATCH_IP_PROTO))) { |
| 749 |
rule->flow_type = IPV4_USER_FLOW; |
| 750 |
uip_entry->ip_ver = ETH_RX_NFC_IP4; |
| 751 |
if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { |
| 752 |
uip_mask->proto = IP_PROTO_FULL_MASK; |
| 753 |
uip_entry->proto = spec.ip_proto; |
| 754 |
} |
| 755 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 756 |
uip_entry->ip4dst = spec.loc_host[0]; |
| 757 |
uip_mask->ip4dst = IP4_ADDR_FULL_MASK; |
| 758 |
} |
| 759 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 760 |
uip_entry->ip4src = spec.rem_host[0]; |
| 761 |
uip_mask->ip4src = IP4_ADDR_FULL_MASK; |
| 762 |
} |
| 763 |
} else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
| 764 |
spec.ether_type == htons(ETH_P_IPV6) && |
| 765 |
!(spec.match_flags & |
| 766 |
~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 767 |
EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 768 |
EFX_FILTER_MATCH_IP_PROTO))) { |
| 769 |
rule->flow_type = IPV6_USER_FLOW; |
| 770 |
if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { |
| 771 |
uip6_mask->l4_proto = IP_PROTO_FULL_MASK; |
| 772 |
uip6_entry->l4_proto = spec.ip_proto; |
| 773 |
} |
| 774 |
if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 775 |
memcpy(uip6_entry->ip6dst, spec.loc_host, |
| 776 |
sizeof(uip6_entry->ip6dst)); |
| 777 |
ip6_fill_mask(uip6_mask->ip6dst); |
| 778 |
} |
| 779 |
if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 780 |
memcpy(uip6_entry->ip6src, spec.rem_host, |
| 781 |
sizeof(uip6_entry->ip6src)); |
| 782 |
ip6_fill_mask(uip6_mask->ip6src); |
| 783 |
} |
| 784 |
} else { |
| 785 |
/* The above should handle all filters that we insert */ |
| 786 |
WARN_ON(1); |
| 787 |
return -EINVAL; |
| 788 |
} |
| 789 |
|
| 790 |
if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
| 791 |
rule->flow_type |= FLOW_EXT; |
| 792 |
rule->h_ext.vlan_tci = spec.outer_vid; |
| 793 |
rule->m_ext.vlan_tci = htons(0xfff); |
| 794 |
} |
| 795 |
|
| 796 |
if (spec.flags & EFX_FILTER_FLAG_RX_RSS) { |
| 797 |
rule->flow_type |= FLOW_RSS; |
| 798 |
*rss_context = spec.rss_context; |
| 799 |
} |
| 800 |
|
| 801 |
return rc; |
| 802 |
} |
| 803 |
|
| 804 |
int efx_siena_ethtool_get_rxfh_fields(struct net_device *net_dev, |
| 805 |
struct ethtool_rxfh_fields *info) |
| 806 |
{ |
| 807 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 808 |
__u64 data; |
| 809 |
|
| 810 |
data = 0; |
| 811 |
if (!efx_rss_active(&efx->rss_context)) /* No RSS */ |
| 812 |
goto out_setdata; |
| 813 |
|
| 814 |
switch (info->flow_type) { |
| 815 |
case UDP_V4_FLOW: |
| 816 |
case UDP_V6_FLOW: |
| 817 |
if (efx->rss_context.rx_hash_udp_4tuple) |
| 818 |
data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 | |
| 819 |
RXH_IP_SRC | RXH_IP_DST); |
| 820 |
else |
| 821 |
data = RXH_IP_SRC | RXH_IP_DST; |
| 822 |
break; |
| 823 |
case TCP_V4_FLOW: |
| 824 |
case TCP_V6_FLOW: |
| 825 |
data = (RXH_L4_B_0_1 | RXH_L4_B_2_3 | |
| 826 |
RXH_IP_SRC | RXH_IP_DST); |
| 827 |
break; |
| 828 |
case SCTP_V4_FLOW: |
| 829 |
case SCTP_V6_FLOW: |
| 830 |
case AH_ESP_V4_FLOW: |
| 831 |
case AH_ESP_V6_FLOW: |
| 832 |
case IPV4_FLOW: |
| 833 |
case IPV6_FLOW: |
| 834 |
data = RXH_IP_SRC | RXH_IP_DST; |
| 835 |
break; |
| 836 |
default: |
| 837 |
break; |
| 838 |
} |
| 839 |
out_setdata: |
| 840 |
info->data = data; |
| 841 |
return 0; |
| 842 |
} |
| 843 |
|
| 844 |
u32 efx_siena_ethtool_get_rx_ring_count(struct net_device *net_dev) |
| 845 |
{ |
| 846 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 847 |
|
| 848 |
return efx->n_rx_channels; |
| 849 |
} |
| 850 |
|
| 851 |
int efx_siena_ethtool_get_rxnfc(struct net_device *net_dev, |
| 852 |
struct ethtool_rxnfc *info, u32 *rule_locs) |
| 853 |
{ |
| 854 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 855 |
u32 rss_context = 0; |
| 856 |
s32 rc = 0; |
| 857 |
|
| 858 |
switch (info->cmd) { |
| 859 |
case ETHTOOL_GRXCLSRLCNT: |
| 860 |
info->data = efx_filter_get_rx_id_limit(efx); |
| 861 |
if (info->data == 0) |
| 862 |
return -EOPNOTSUPP; |
| 863 |
info->data |= RX_CLS_LOC_SPECIAL; |
| 864 |
info->rule_cnt = |
| 865 |
efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); |
| 866 |
return 0; |
| 867 |
|
| 868 |
case ETHTOOL_GRXCLSRULE: |
| 869 |
if (efx_filter_get_rx_id_limit(efx) == 0) |
| 870 |
return -EOPNOTSUPP; |
| 871 |
rc = efx_ethtool_get_class_rule(efx, &info->fs, &rss_context); |
| 872 |
if (rc < 0) |
| 873 |
return rc; |
| 874 |
if (info->fs.flow_type & FLOW_RSS) |
| 875 |
info->rss_context = rss_context; |
| 876 |
return 0; |
| 877 |
|
| 878 |
case ETHTOOL_GRXCLSRLALL: |
| 879 |
info->data = efx_filter_get_rx_id_limit(efx); |
| 880 |
if (info->data == 0) |
| 881 |
return -EOPNOTSUPP; |
| 882 |
rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, |
| 883 |
rule_locs, info->rule_cnt); |
| 884 |
if (rc < 0) |
| 885 |
return rc; |
| 886 |
info->rule_cnt = rc; |
| 887 |
return 0; |
| 888 |
|
| 889 |
default: |
| 890 |
return -EOPNOTSUPP; |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
static inline bool ip6_mask_is_full(__be32 mask[4]) |
| 895 |
{ |
| 896 |
return !~(mask[0] & mask[1] & mask[2] & mask[3]); |
| 897 |
} |
| 898 |
|
| 899 |
static inline bool ip6_mask_is_empty(__be32 mask[4]) |
| 900 |
{ |
| 901 |
return !(mask[0] | mask[1] | mask[2] | mask[3]); |
| 902 |
} |
| 903 |
|
| 904 |
static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
| 905 |
struct ethtool_rx_flow_spec *rule, |
| 906 |
u32 rss_context) |
| 907 |
{ |
| 908 |
struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 909 |
struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
| 910 |
struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
| 911 |
struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; |
| 912 |
struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; |
| 913 |
struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; |
| 914 |
struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; |
| 915 |
struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; |
| 916 |
u32 flow_type = rule->flow_type & ~(FLOW_EXT | FLOW_RSS); |
| 917 |
struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 918 |
struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
| 919 |
enum efx_filter_flags flags = 0; |
| 920 |
struct efx_filter_spec spec; |
| 921 |
int rc; |
| 922 |
|
| 923 |
/* Check that user wants us to choose the location */ |
| 924 |
if (rule->location != RX_CLS_LOC_ANY) |
| 925 |
return -EINVAL; |
| 926 |
|
| 927 |
/* Range-check ring_cookie */ |
| 928 |
if (rule->ring_cookie >= efx->n_rx_channels && |
| 929 |
rule->ring_cookie != RX_CLS_FLOW_DISC) |
| 930 |
return -EINVAL; |
| 931 |
|
| 932 |
/* Check for unsupported extensions */ |
| 933 |
if ((rule->flow_type & FLOW_EXT) && |
| 934 |
(rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
| 935 |
rule->m_ext.data[1])) |
| 936 |
return -EINVAL; |
| 937 |
|
| 938 |
if (efx->rx_scatter) |
| 939 |
flags |= EFX_FILTER_FLAG_RX_SCATTER; |
| 940 |
if (rule->flow_type & FLOW_RSS) |
| 941 |
flags |= EFX_FILTER_FLAG_RX_RSS; |
| 942 |
|
| 943 |
efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, flags, |
| 944 |
(rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
| 945 |
EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
| 946 |
|
| 947 |
if (rule->flow_type & FLOW_RSS) |
| 948 |
spec.rss_context = rss_context; |
| 949 |
|
| 950 |
switch (flow_type) { |
| 951 |
case TCP_V4_FLOW: |
| 952 |
case UDP_V4_FLOW: |
| 953 |
spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | |
| 954 |
EFX_FILTER_MATCH_IP_PROTO); |
| 955 |
spec.ether_type = htons(ETH_P_IP); |
| 956 |
spec.ip_proto = flow_type == TCP_V4_FLOW ? IPPROTO_TCP |
| 957 |
: IPPROTO_UDP; |
| 958 |
if (ip_mask->ip4dst) { |
| 959 |
if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) |
| 960 |
return -EINVAL; |
| 961 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 962 |
spec.loc_host[0] = ip_entry->ip4dst; |
| 963 |
} |
| 964 |
if (ip_mask->ip4src) { |
| 965 |
if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) |
| 966 |
return -EINVAL; |
| 967 |
spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 968 |
spec.rem_host[0] = ip_entry->ip4src; |
| 969 |
} |
| 970 |
if (ip_mask->pdst) { |
| 971 |
if (ip_mask->pdst != PORT_FULL_MASK) |
| 972 |
return -EINVAL; |
| 973 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; |
| 974 |
spec.loc_port = ip_entry->pdst; |
| 975 |
} |
| 976 |
if (ip_mask->psrc) { |
| 977 |
if (ip_mask->psrc != PORT_FULL_MASK) |
| 978 |
return -EINVAL; |
| 979 |
spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; |
| 980 |
spec.rem_port = ip_entry->psrc; |
| 981 |
} |
| 982 |
if (ip_mask->tos) |
| 983 |
return -EINVAL; |
| 984 |
break; |
| 985 |
|
| 986 |
case TCP_V6_FLOW: |
| 987 |
case UDP_V6_FLOW: |
| 988 |
spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | |
| 989 |
EFX_FILTER_MATCH_IP_PROTO); |
| 990 |
spec.ether_type = htons(ETH_P_IPV6); |
| 991 |
spec.ip_proto = flow_type == TCP_V6_FLOW ? IPPROTO_TCP |
| 992 |
: IPPROTO_UDP; |
| 993 |
if (!ip6_mask_is_empty(ip6_mask->ip6dst)) { |
| 994 |
if (!ip6_mask_is_full(ip6_mask->ip6dst)) |
| 995 |
return -EINVAL; |
| 996 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 997 |
memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host)); |
| 998 |
} |
| 999 |
if (!ip6_mask_is_empty(ip6_mask->ip6src)) { |
| 1000 |
if (!ip6_mask_is_full(ip6_mask->ip6src)) |
| 1001 |
return -EINVAL; |
| 1002 |
spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1003 |
memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host)); |
| 1004 |
} |
| 1005 |
if (ip6_mask->pdst) { |
| 1006 |
if (ip6_mask->pdst != PORT_FULL_MASK) |
| 1007 |
return -EINVAL; |
| 1008 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; |
| 1009 |
spec.loc_port = ip6_entry->pdst; |
| 1010 |
} |
| 1011 |
if (ip6_mask->psrc) { |
| 1012 |
if (ip6_mask->psrc != PORT_FULL_MASK) |
| 1013 |
return -EINVAL; |
| 1014 |
spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; |
| 1015 |
spec.rem_port = ip6_entry->psrc; |
| 1016 |
} |
| 1017 |
if (ip6_mask->tclass) |
| 1018 |
return -EINVAL; |
| 1019 |
break; |
| 1020 |
|
| 1021 |
case IPV4_USER_FLOW: |
| 1022 |
if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver || |
| 1023 |
uip_entry->ip_ver != ETH_RX_NFC_IP4) |
| 1024 |
return -EINVAL; |
| 1025 |
spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; |
| 1026 |
spec.ether_type = htons(ETH_P_IP); |
| 1027 |
if (uip_mask->ip4dst) { |
| 1028 |
if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK) |
| 1029 |
return -EINVAL; |
| 1030 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1031 |
spec.loc_host[0] = uip_entry->ip4dst; |
| 1032 |
} |
| 1033 |
if (uip_mask->ip4src) { |
| 1034 |
if (uip_mask->ip4src != IP4_ADDR_FULL_MASK) |
| 1035 |
return -EINVAL; |
| 1036 |
spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1037 |
spec.rem_host[0] = uip_entry->ip4src; |
| 1038 |
} |
| 1039 |
if (uip_mask->proto) { |
| 1040 |
if (uip_mask->proto != IP_PROTO_FULL_MASK) |
| 1041 |
return -EINVAL; |
| 1042 |
spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; |
| 1043 |
spec.ip_proto = uip_entry->proto; |
| 1044 |
} |
| 1045 |
break; |
| 1046 |
|
| 1047 |
case IPV6_USER_FLOW: |
| 1048 |
if (uip6_mask->l4_4_bytes || uip6_mask->tclass) |
| 1049 |
return -EINVAL; |
| 1050 |
spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; |
| 1051 |
spec.ether_type = htons(ETH_P_IPV6); |
| 1052 |
if (!ip6_mask_is_empty(uip6_mask->ip6dst)) { |
| 1053 |
if (!ip6_mask_is_full(uip6_mask->ip6dst)) |
| 1054 |
return -EINVAL; |
| 1055 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1056 |
memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host)); |
| 1057 |
} |
| 1058 |
if (!ip6_mask_is_empty(uip6_mask->ip6src)) { |
| 1059 |
if (!ip6_mask_is_full(uip6_mask->ip6src)) |
| 1060 |
return -EINVAL; |
| 1061 |
spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1062 |
memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host)); |
| 1063 |
} |
| 1064 |
if (uip6_mask->l4_proto) { |
| 1065 |
if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK) |
| 1066 |
return -EINVAL; |
| 1067 |
spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; |
| 1068 |
spec.ip_proto = uip6_entry->l4_proto; |
| 1069 |
} |
| 1070 |
break; |
| 1071 |
|
| 1072 |
case ETHER_FLOW: |
| 1073 |
if (!is_zero_ether_addr(mac_mask->h_dest)) { |
| 1074 |
if (ether_addr_equal(mac_mask->h_dest, |
| 1075 |
mac_addr_ig_mask)) |
| 1076 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; |
| 1077 |
else if (is_broadcast_ether_addr(mac_mask->h_dest)) |
| 1078 |
spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; |
| 1079 |
else |
| 1080 |
return -EINVAL; |
| 1081 |
ether_addr_copy(spec.loc_mac, mac_entry->h_dest); |
| 1082 |
} |
| 1083 |
if (!is_zero_ether_addr(mac_mask->h_source)) { |
| 1084 |
if (!is_broadcast_ether_addr(mac_mask->h_source)) |
| 1085 |
return -EINVAL; |
| 1086 |
spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; |
| 1087 |
ether_addr_copy(spec.rem_mac, mac_entry->h_source); |
| 1088 |
} |
| 1089 |
if (mac_mask->h_proto) { |
| 1090 |
if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) |
| 1091 |
return -EINVAL; |
| 1092 |
spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; |
| 1093 |
spec.ether_type = mac_entry->h_proto; |
| 1094 |
} |
| 1095 |
break; |
| 1096 |
|
| 1097 |
default: |
| 1098 |
return -EINVAL; |
| 1099 |
} |
| 1100 |
|
| 1101 |
if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
| 1102 |
if (rule->m_ext.vlan_tci != htons(0xfff)) |
| 1103 |
return -EINVAL; |
| 1104 |
spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; |
| 1105 |
spec.outer_vid = rule->h_ext.vlan_tci; |
| 1106 |
} |
| 1107 |
|
| 1108 |
rc = efx_filter_insert_filter(efx, &spec, true); |
| 1109 |
if (rc < 0) |
| 1110 |
return rc; |
| 1111 |
|
| 1112 |
rule->location = rc; |
| 1113 |
return 0; |
| 1114 |
} |
| 1115 |
|
| 1116 |
int efx_siena_ethtool_set_rxnfc(struct net_device *net_dev, |
| 1117 |
struct ethtool_rxnfc *info) |
| 1118 |
{ |
| 1119 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1120 |
|
| 1121 |
if (efx_filter_get_rx_id_limit(efx) == 0) |
| 1122 |
return -EOPNOTSUPP; |
| 1123 |
|
| 1124 |
switch (info->cmd) { |
| 1125 |
case ETHTOOL_SRXCLSRLINS: |
| 1126 |
return efx_ethtool_set_class_rule(efx, &info->fs, |
| 1127 |
info->rss_context); |
| 1128 |
|
| 1129 |
case ETHTOOL_SRXCLSRLDEL: |
| 1130 |
return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 1131 |
info->fs.location); |
| 1132 |
|
| 1133 |
default: |
| 1134 |
return -EOPNOTSUPP; |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
u32 efx_siena_ethtool_get_rxfh_indir_size(struct net_device *net_dev) |
| 1139 |
{ |
| 1140 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1141 |
|
| 1142 |
if (efx->n_rx_channels == 1) |
| 1143 |
return 0; |
| 1144 |
return ARRAY_SIZE(efx->rss_context.rx_indir_table); |
| 1145 |
} |
| 1146 |
|
| 1147 |
u32 efx_siena_ethtool_get_rxfh_key_size(struct net_device *net_dev) |
| 1148 |
{ |
| 1149 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1150 |
|
| 1151 |
return efx->type->rx_hash_key_size; |
| 1152 |
} |
| 1153 |
|
| 1154 |
int efx_siena_ethtool_get_rxfh(struct net_device *net_dev, |
| 1155 |
struct ethtool_rxfh_param *rxfh) |
| 1156 |
{ |
| 1157 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1158 |
int rc; |
| 1159 |
|
| 1160 |
rc = efx->type->rx_pull_rss_config(efx); |
| 1161 |
if (rc) |
| 1162 |
return rc; |
| 1163 |
|
| 1164 |
rxfh->hfunc = ETH_RSS_HASH_TOP; |
| 1165 |
if (rxfh->indir) |
| 1166 |
memcpy(rxfh->indir, efx->rss_context.rx_indir_table, |
| 1167 |
sizeof(efx->rss_context.rx_indir_table)); |
| 1168 |
if (rxfh->key) |
| 1169 |
memcpy(rxfh->key, efx->rss_context.rx_hash_key, |
| 1170 |
efx->type->rx_hash_key_size); |
| 1171 |
return 0; |
| 1172 |
} |
| 1173 |
|
| 1174 |
int efx_siena_ethtool_set_rxfh(struct net_device *net_dev, |
| 1175 |
struct ethtool_rxfh_param *rxfh, |
| 1176 |
struct netlink_ext_ack *extack) |
| 1177 |
{ |
| 1178 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1179 |
u32 *indir = rxfh->indir; |
| 1180 |
u8 *key = rxfh->key; |
| 1181 |
|
| 1182 |
/* Hash function is Toeplitz, cannot be changed */ |
| 1183 |
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && |
| 1184 |
rxfh->hfunc != ETH_RSS_HASH_TOP) |
| 1185 |
return -EOPNOTSUPP; |
| 1186 |
|
| 1187 |
if (!indir && !key) |
| 1188 |
return 0; |
| 1189 |
|
| 1190 |
if (!key) |
| 1191 |
key = efx->rss_context.rx_hash_key; |
| 1192 |
if (!indir) |
| 1193 |
indir = efx->rss_context.rx_indir_table; |
| 1194 |
|
| 1195 |
return efx->type->rx_push_rss_config(efx, true, indir, key); |
| 1196 |
} |
| 1197 |
|
| 1198 |
int efx_siena_ethtool_reset(struct net_device *net_dev, u32 *flags) |
| 1199 |
{ |
| 1200 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1201 |
int rc; |
| 1202 |
|
| 1203 |
rc = efx->type->map_reset_flags(flags); |
| 1204 |
if (rc < 0) |
| 1205 |
return rc; |
| 1206 |
|
| 1207 |
return efx_siena_reset(efx, rc); |
| 1208 |
} |
| 1209 |
|
| 1210 |
int efx_siena_ethtool_get_module_eeprom(struct net_device *net_dev, |
| 1211 |
struct ethtool_eeprom *ee, |
| 1212 |
u8 *data) |
| 1213 |
{ |
| 1214 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1215 |
int ret; |
| 1216 |
|
| 1217 |
mutex_lock(&efx->mac_lock); |
| 1218 |
ret = efx_siena_mcdi_phy_get_module_eeprom(efx, ee, data); |
| 1219 |
mutex_unlock(&efx->mac_lock); |
| 1220 |
|
| 1221 |
return ret; |
| 1222 |
} |
| 1223 |
|
| 1224 |
int efx_siena_ethtool_get_module_info(struct net_device *net_dev, |
| 1225 |
struct ethtool_modinfo *modinfo) |
| 1226 |
{ |
| 1227 |
struct efx_nic *efx = netdev_priv(net_dev); |
| 1228 |
int ret; |
| 1229 |
|
| 1230 |
mutex_lock(&efx->mac_lock); |
| 1231 |
ret = efx_siena_mcdi_phy_get_module_info(efx, modinfo); |
| 1232 |
mutex_unlock(&efx->mac_lock); |
| 1233 |
|
| 1234 |
return ret; |
| 1235 |
} |