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