1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 3 4 #include <linux/module.h> 5 #include <linux/netdevice.h> 6 7 #include "ionic.h" 8 #include "ionic_bus.h" 9 #include "ionic_lif.h" 10 #include "ionic_ethtool.h" 11 #include "ionic_stats.h" 12 13 static const char ionic_priv_flags_strings[][ETH_GSTRING_LEN] = { 14 #define PRIV_F_SW_DBG_STATS BIT(0) 15 "sw-dbg-stats", 16 }; 17 #define PRIV_FLAGS_COUNT ARRAY_SIZE(ionic_priv_flags_strings) 18 19 static void ionic_get_stats_strings(struct ionic_lif *lif, u8 *buf) 20 { 21 u32 i; 22 23 for (i = 0; i < ionic_num_stats_grps; i++) 24 ionic_stats_groups[i].get_strings(lif, &buf); 25 } 26 27 static void ionic_get_stats(struct net_device *netdev, 28 struct ethtool_stats *stats, u64 *buf) 29 { 30 struct ionic_lif *lif; 31 u32 i; 32 33 lif = netdev_priv(netdev); 34 35 memset(buf, 0, stats->n_stats * sizeof(*buf)); 36 for (i = 0; i < ionic_num_stats_grps; i++) 37 ionic_stats_groups[i].get_values(lif, &buf); 38 } 39 40 static int ionic_get_stats_count(struct ionic_lif *lif) 41 { 42 int i, num_stats = 0; 43 44 for (i = 0; i < ionic_num_stats_grps; i++) 45 num_stats += ionic_stats_groups[i].get_count(lif); 46 47 return num_stats; 48 } 49 50 static int ionic_get_sset_count(struct net_device *netdev, int sset) 51 { 52 struct ionic_lif *lif = netdev_priv(netdev); 53 int count = 0; 54 55 switch (sset) { 56 case ETH_SS_STATS: 57 count = ionic_get_stats_count(lif); 58 break; 59 case ETH_SS_PRIV_FLAGS: 60 count = PRIV_FLAGS_COUNT; 61 break; 62 } 63 return count; 64 } 65 66 static void ionic_get_strings(struct net_device *netdev, 67 u32 sset, u8 *buf) 68 { 69 struct ionic_lif *lif = netdev_priv(netdev); 70 71 switch (sset) { 72 case ETH_SS_STATS: 73 ionic_get_stats_strings(lif, buf); 74 break; 75 case ETH_SS_PRIV_FLAGS: 76 memcpy(buf, ionic_priv_flags_strings, 77 PRIV_FLAGS_COUNT * ETH_GSTRING_LEN); 78 break; 79 } 80 } 81 82 static void ionic_get_drvinfo(struct net_device *netdev, 83 struct ethtool_drvinfo *drvinfo) 84 { 85 struct ionic_lif *lif = netdev_priv(netdev); 86 struct ionic *ionic = lif->ionic; 87 88 strlcpy(drvinfo->driver, IONIC_DRV_NAME, sizeof(drvinfo->driver)); 89 strlcpy(drvinfo->version, IONIC_DRV_VERSION, sizeof(drvinfo->version)); 90 strlcpy(drvinfo->fw_version, ionic->idev.dev_info.fw_version, 91 sizeof(drvinfo->fw_version)); 92 strlcpy(drvinfo->bus_info, ionic_bus_info(ionic), 93 sizeof(drvinfo->bus_info)); 94 } 95 96 static int ionic_get_regs_len(struct net_device *netdev) 97 { 98 return (IONIC_DEV_INFO_REG_COUNT + IONIC_DEV_CMD_REG_COUNT) * sizeof(u32); 99 } 100 101 static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs, 102 void *p) 103 { 104 struct ionic_lif *lif = netdev_priv(netdev); 105 unsigned int size; 106 107 regs->version = IONIC_DEV_CMD_REG_VERSION; 108 109 size = IONIC_DEV_INFO_REG_COUNT * sizeof(u32); 110 memcpy_fromio(p, lif->ionic->idev.dev_info_regs->words, size); 111 112 size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32); 113 memcpy_fromio(p, lif->ionic->idev.dev_cmd_regs->words, size); 114 } 115 116 static int ionic_get_link_ksettings(struct net_device *netdev, 117 struct ethtool_link_ksettings *ks) 118 { 119 struct ionic_lif *lif = netdev_priv(netdev); 120 struct ionic_dev *idev = &lif->ionic->idev; 121 int copper_seen = 0; 122 123 ethtool_link_ksettings_zero_link_mode(ks, supported); 124 125 /* The port_info data is found in a DMA space that the NIC keeps 126 * up-to-date, so there's no need to request the data from the 127 * NIC, we already have it in our memory space. 128 */ 129 130 switch (le16_to_cpu(idev->port_info->status.xcvr.pid)) { 131 /* Copper */ 132 case IONIC_XCVR_PID_QSFP_100G_CR4: 133 ethtool_link_ksettings_add_link_mode(ks, supported, 134 100000baseCR4_Full); 135 copper_seen++; 136 break; 137 case IONIC_XCVR_PID_QSFP_40GBASE_CR4: 138 ethtool_link_ksettings_add_link_mode(ks, supported, 139 40000baseCR4_Full); 140 copper_seen++; 141 break; 142 case IONIC_XCVR_PID_SFP_25GBASE_CR_S: 143 case IONIC_XCVR_PID_SFP_25GBASE_CR_L: 144 case IONIC_XCVR_PID_SFP_25GBASE_CR_N: 145 ethtool_link_ksettings_add_link_mode(ks, supported, 146 25000baseCR_Full); 147 copper_seen++; 148 break; 149 case IONIC_XCVR_PID_SFP_10GBASE_AOC: 150 case IONIC_XCVR_PID_SFP_10GBASE_CU: 151 ethtool_link_ksettings_add_link_mode(ks, supported, 152 10000baseCR_Full); 153 copper_seen++; 154 break; 155 156 /* Fibre */ 157 case IONIC_XCVR_PID_QSFP_100G_SR4: 158 case IONIC_XCVR_PID_QSFP_100G_AOC: 159 ethtool_link_ksettings_add_link_mode(ks, supported, 160 100000baseSR4_Full); 161 break; 162 case IONIC_XCVR_PID_QSFP_100G_LR4: 163 ethtool_link_ksettings_add_link_mode(ks, supported, 164 100000baseLR4_ER4_Full); 165 break; 166 case IONIC_XCVR_PID_QSFP_100G_ER4: 167 ethtool_link_ksettings_add_link_mode(ks, supported, 168 100000baseLR4_ER4_Full); 169 break; 170 case IONIC_XCVR_PID_QSFP_40GBASE_SR4: 171 case IONIC_XCVR_PID_QSFP_40GBASE_AOC: 172 ethtool_link_ksettings_add_link_mode(ks, supported, 173 40000baseSR4_Full); 174 break; 175 case IONIC_XCVR_PID_QSFP_40GBASE_LR4: 176 ethtool_link_ksettings_add_link_mode(ks, supported, 177 40000baseLR4_Full); 178 break; 179 case IONIC_XCVR_PID_SFP_25GBASE_SR: 180 case IONIC_XCVR_PID_SFP_25GBASE_AOC: 181 ethtool_link_ksettings_add_link_mode(ks, supported, 182 25000baseSR_Full); 183 break; 184 case IONIC_XCVR_PID_SFP_10GBASE_SR: 185 ethtool_link_ksettings_add_link_mode(ks, supported, 186 10000baseSR_Full); 187 break; 188 case IONIC_XCVR_PID_SFP_10GBASE_LR: 189 ethtool_link_ksettings_add_link_mode(ks, supported, 190 10000baseLR_Full); 191 break; 192 case IONIC_XCVR_PID_SFP_10GBASE_LRM: 193 ethtool_link_ksettings_add_link_mode(ks, supported, 194 10000baseLRM_Full); 195 break; 196 case IONIC_XCVR_PID_SFP_10GBASE_ER: 197 ethtool_link_ksettings_add_link_mode(ks, supported, 198 10000baseER_Full); 199 break; 200 case IONIC_XCVR_PID_UNKNOWN: 201 /* This means there's no module plugged in */ 202 break; 203 default: 204 dev_info(lif->ionic->dev, "unknown xcvr type pid=%d / 0x%x\n", 205 idev->port_info->status.xcvr.pid, 206 idev->port_info->status.xcvr.pid); 207 break; 208 } 209 210 bitmap_copy(ks->link_modes.advertising, ks->link_modes.supported, 211 __ETHTOOL_LINK_MODE_MASK_NBITS); 212 213 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER); 214 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS); 215 if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC) 216 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_BASER); 217 else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_RS) 218 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS); 219 220 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 221 ethtool_link_ksettings_add_link_mode(ks, supported, Pause); 222 223 if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_COPPER || 224 copper_seen) 225 ks->base.port = PORT_DA; 226 else if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_FIBER) 227 ks->base.port = PORT_FIBRE; 228 else 229 ks->base.port = PORT_NONE; 230 231 if (ks->base.port != PORT_NONE) { 232 ks->base.speed = le32_to_cpu(lif->info->status.link_speed); 233 234 if (le16_to_cpu(lif->info->status.link_status)) 235 ks->base.duplex = DUPLEX_FULL; 236 else 237 ks->base.duplex = DUPLEX_UNKNOWN; 238 239 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 240 241 if (idev->port_info->config.an_enable) { 242 ethtool_link_ksettings_add_link_mode(ks, advertising, 243 Autoneg); 244 ks->base.autoneg = AUTONEG_ENABLE; 245 } 246 } 247 248 return 0; 249 } 250 251 static int ionic_set_link_ksettings(struct net_device *netdev, 252 const struct ethtool_link_ksettings *ks) 253 { 254 struct ionic_lif *lif = netdev_priv(netdev); 255 struct ionic *ionic = lif->ionic; 256 struct ionic_dev *idev; 257 int err = 0; 258 259 idev = &lif->ionic->idev; 260 261 /* set autoneg */ 262 if (ks->base.autoneg != idev->port_info->config.an_enable) { 263 mutex_lock(&ionic->dev_cmd_lock); 264 ionic_dev_cmd_port_autoneg(idev, ks->base.autoneg); 265 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); 266 mutex_unlock(&ionic->dev_cmd_lock); 267 if (err) 268 return err; 269 } 270 271 /* set speed */ 272 if (ks->base.speed != le32_to_cpu(idev->port_info->config.speed)) { 273 mutex_lock(&ionic->dev_cmd_lock); 274 ionic_dev_cmd_port_speed(idev, ks->base.speed); 275 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); 276 mutex_unlock(&ionic->dev_cmd_lock); 277 if (err) 278 return err; 279 } 280 281 return 0; 282 } 283 284 static void ionic_get_pauseparam(struct net_device *netdev, 285 struct ethtool_pauseparam *pause) 286 { 287 struct ionic_lif *lif = netdev_priv(netdev); 288 u8 pause_type; 289 290 pause->autoneg = 0; 291 292 pause_type = lif->ionic->idev.port_info->config.pause_type; 293 if (pause_type) { 294 pause->rx_pause = pause_type & IONIC_PAUSE_F_RX ? 1 : 0; 295 pause->tx_pause = pause_type & IONIC_PAUSE_F_TX ? 1 : 0; 296 } 297 } 298 299 static int ionic_set_pauseparam(struct net_device *netdev, 300 struct ethtool_pauseparam *pause) 301 { 302 struct ionic_lif *lif = netdev_priv(netdev); 303 struct ionic *ionic = lif->ionic; 304 u32 requested_pause; 305 int err; 306 307 if (pause->autoneg) 308 return -EOPNOTSUPP; 309 310 /* change both at the same time */ 311 requested_pause = IONIC_PORT_PAUSE_TYPE_LINK; 312 if (pause->rx_pause) 313 requested_pause |= IONIC_PAUSE_F_RX; 314 if (pause->tx_pause) 315 requested_pause |= IONIC_PAUSE_F_TX; 316 317 if (requested_pause == lif->ionic->idev.port_info->config.pause_type) 318 return 0; 319 320 mutex_lock(&ionic->dev_cmd_lock); 321 ionic_dev_cmd_port_pause(&lif->ionic->idev, requested_pause); 322 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); 323 mutex_unlock(&ionic->dev_cmd_lock); 324 if (err) 325 return err; 326 327 return 0; 328 } 329 330 static int ionic_get_fecparam(struct net_device *netdev, 331 struct ethtool_fecparam *fec) 332 { 333 struct ionic_lif *lif = netdev_priv(netdev); 334 335 switch (lif->ionic->idev.port_info->config.fec_type) { 336 case IONIC_PORT_FEC_TYPE_NONE: 337 fec->active_fec = ETHTOOL_FEC_OFF; 338 break; 339 case IONIC_PORT_FEC_TYPE_RS: 340 fec->active_fec = ETHTOOL_FEC_RS; 341 break; 342 case IONIC_PORT_FEC_TYPE_FC: 343 fec->active_fec = ETHTOOL_FEC_BASER; 344 break; 345 } 346 347 fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER; 348 349 return 0; 350 } 351 352 static int ionic_set_fecparam(struct net_device *netdev, 353 struct ethtool_fecparam *fec) 354 { 355 struct ionic_lif *lif = netdev_priv(netdev); 356 u8 fec_type; 357 int ret = 0; 358 359 if (lif->ionic->idev.port_info->config.an_enable) { 360 netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n"); 361 return -EINVAL; 362 } 363 364 switch (fec->fec) { 365 case ETHTOOL_FEC_NONE: 366 fec_type = IONIC_PORT_FEC_TYPE_NONE; 367 break; 368 case ETHTOOL_FEC_OFF: 369 fec_type = IONIC_PORT_FEC_TYPE_NONE; 370 break; 371 case ETHTOOL_FEC_RS: 372 fec_type = IONIC_PORT_FEC_TYPE_RS; 373 break; 374 case ETHTOOL_FEC_BASER: 375 fec_type = IONIC_PORT_FEC_TYPE_FC; 376 break; 377 case ETHTOOL_FEC_AUTO: 378 default: 379 netdev_err(netdev, "FEC request 0x%04x not supported\n", 380 fec->fec); 381 return -EINVAL; 382 } 383 384 if (fec_type != lif->ionic->idev.port_info->config.fec_type) { 385 mutex_lock(&lif->ionic->dev_cmd_lock); 386 ionic_dev_cmd_port_fec(&lif->ionic->idev, fec_type); 387 ret = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT); 388 mutex_unlock(&lif->ionic->dev_cmd_lock); 389 } 390 391 return ret; 392 } 393 394 static int ionic_get_coalesce(struct net_device *netdev, 395 struct ethtool_coalesce *coalesce) 396 { 397 struct ionic_lif *lif = netdev_priv(netdev); 398 399 /* Tx uses Rx interrupt */ 400 coalesce->tx_coalesce_usecs = lif->rx_coalesce_usecs; 401 coalesce->rx_coalesce_usecs = lif->rx_coalesce_usecs; 402 403 return 0; 404 } 405 406 static int ionic_set_coalesce(struct net_device *netdev, 407 struct ethtool_coalesce *coalesce) 408 { 409 struct ionic_lif *lif = netdev_priv(netdev); 410 struct ionic_identity *ident; 411 struct ionic_qcq *qcq; 412 unsigned int i; 413 u32 coal; 414 415 if (coalesce->rx_max_coalesced_frames || 416 coalesce->rx_coalesce_usecs_irq || 417 coalesce->rx_max_coalesced_frames_irq || 418 coalesce->tx_max_coalesced_frames || 419 coalesce->tx_coalesce_usecs_irq || 420 coalesce->tx_max_coalesced_frames_irq || 421 coalesce->stats_block_coalesce_usecs || 422 coalesce->use_adaptive_rx_coalesce || 423 coalesce->use_adaptive_tx_coalesce || 424 coalesce->pkt_rate_low || 425 coalesce->rx_coalesce_usecs_low || 426 coalesce->rx_max_coalesced_frames_low || 427 coalesce->tx_coalesce_usecs_low || 428 coalesce->tx_max_coalesced_frames_low || 429 coalesce->pkt_rate_high || 430 coalesce->rx_coalesce_usecs_high || 431 coalesce->rx_max_coalesced_frames_high || 432 coalesce->tx_coalesce_usecs_high || 433 coalesce->tx_max_coalesced_frames_high || 434 coalesce->rate_sample_interval) 435 return -EINVAL; 436 437 ident = &lif->ionic->ident; 438 if (ident->dev.intr_coal_div == 0) { 439 netdev_warn(netdev, "bad HW value in dev.intr_coal_div = %d\n", 440 ident->dev.intr_coal_div); 441 return -EIO; 442 } 443 444 /* Tx uses Rx interrupt, so only change Rx */ 445 if (coalesce->tx_coalesce_usecs != lif->rx_coalesce_usecs) { 446 netdev_warn(netdev, "only the rx-usecs can be changed\n"); 447 return -EINVAL; 448 } 449 450 /* Convert the usec request to a HW useable value. If they asked 451 * for non-zero and it resolved to zero, bump it up 452 */ 453 coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs); 454 if (!coal && coalesce->rx_coalesce_usecs) 455 coal = 1; 456 457 if (coal > IONIC_INTR_CTRL_COAL_MAX) 458 return -ERANGE; 459 460 /* Save the new value */ 461 lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs; 462 if (coal != lif->rx_coalesce_hw) { 463 lif->rx_coalesce_hw = coal; 464 465 if (test_bit(IONIC_LIF_UP, lif->state)) { 466 for (i = 0; i < lif->nxqs; i++) { 467 qcq = lif->rxqcqs[i].qcq; 468 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl, 469 qcq->intr.index, 470 lif->rx_coalesce_hw); 471 } 472 } 473 } 474 475 return 0; 476 } 477 478 static void ionic_get_ringparam(struct net_device *netdev, 479 struct ethtool_ringparam *ring) 480 { 481 struct ionic_lif *lif = netdev_priv(netdev); 482 483 ring->tx_max_pending = IONIC_MAX_TXRX_DESC; 484 ring->tx_pending = lif->ntxq_descs; 485 ring->rx_max_pending = IONIC_MAX_TXRX_DESC; 486 ring->rx_pending = lif->nrxq_descs; 487 } 488 489 static int ionic_set_ringparam(struct net_device *netdev, 490 struct ethtool_ringparam *ring) 491 { 492 struct ionic_lif *lif = netdev_priv(netdev); 493 bool running; 494 int err; 495 496 if (ring->rx_mini_pending || ring->rx_jumbo_pending) { 497 netdev_info(netdev, "Changing jumbo or mini descriptors not supported\n"); 498 return -EINVAL; 499 } 500 501 if (!is_power_of_2(ring->tx_pending) || 502 !is_power_of_2(ring->rx_pending)) { 503 netdev_info(netdev, "Descriptor count must be a power of 2\n"); 504 return -EINVAL; 505 } 506 507 /* if nothing to do return success */ 508 if (ring->tx_pending == lif->ntxq_descs && 509 ring->rx_pending == lif->nrxq_descs) 510 return 0; 511 512 err = ionic_wait_for_bit(lif, IONIC_LIF_QUEUE_RESET); 513 if (err) 514 return err; 515 516 running = test_bit(IONIC_LIF_UP, lif->state); 517 if (running) 518 ionic_stop(netdev); 519 520 lif->ntxq_descs = ring->tx_pending; 521 lif->nrxq_descs = ring->rx_pending; 522 523 if (running) 524 ionic_open(netdev); 525 clear_bit(IONIC_LIF_QUEUE_RESET, lif->state); 526 527 return 0; 528 } 529 530 static void ionic_get_channels(struct net_device *netdev, 531 struct ethtool_channels *ch) 532 { 533 struct ionic_lif *lif = netdev_priv(netdev); 534 535 /* report maximum channels */ 536 ch->max_combined = lif->ionic->ntxqs_per_lif; 537 538 /* report current channels */ 539 ch->combined_count = lif->nxqs; 540 } 541 542 static int ionic_set_channels(struct net_device *netdev, 543 struct ethtool_channels *ch) 544 { 545 struct ionic_lif *lif = netdev_priv(netdev); 546 bool running; 547 int err; 548 549 if (!ch->combined_count || ch->other_count || 550 ch->rx_count || ch->tx_count) 551 return -EINVAL; 552 553 if (ch->combined_count == lif->nxqs) 554 return 0; 555 556 err = ionic_wait_for_bit(lif, IONIC_LIF_QUEUE_RESET); 557 if (err) 558 return err; 559 560 running = test_bit(IONIC_LIF_UP, lif->state); 561 if (running) 562 ionic_stop(netdev); 563 564 lif->nxqs = ch->combined_count; 565 566 if (running) 567 ionic_open(netdev); 568 clear_bit(IONIC_LIF_QUEUE_RESET, lif->state); 569 570 return 0; 571 } 572 573 static u32 ionic_get_priv_flags(struct net_device *netdev) 574 { 575 struct ionic_lif *lif = netdev_priv(netdev); 576 u32 priv_flags = 0; 577 578 if (test_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state)) 579 priv_flags |= PRIV_F_SW_DBG_STATS; 580 581 return priv_flags; 582 } 583 584 static int ionic_set_priv_flags(struct net_device *netdev, u32 priv_flags) 585 { 586 struct ionic_lif *lif = netdev_priv(netdev); 587 u32 flags = lif->flags; 588 589 clear_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state); 590 if (priv_flags & PRIV_F_SW_DBG_STATS) 591 set_bit(IONIC_LIF_SW_DEBUG_STATS, lif->state); 592 593 if (flags != lif->flags) 594 lif->flags = flags; 595 596 return 0; 597 } 598 599 static int ionic_get_rxnfc(struct net_device *netdev, 600 struct ethtool_rxnfc *info, u32 *rules) 601 { 602 struct ionic_lif *lif = netdev_priv(netdev); 603 int err = 0; 604 605 switch (info->cmd) { 606 case ETHTOOL_GRXRINGS: 607 info->data = lif->nxqs; 608 break; 609 default: 610 netdev_err(netdev, "Command parameter %d is not supported\n", 611 info->cmd); 612 err = -EOPNOTSUPP; 613 } 614 615 return err; 616 } 617 618 static u32 ionic_get_rxfh_indir_size(struct net_device *netdev) 619 { 620 struct ionic_lif *lif = netdev_priv(netdev); 621 622 return le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz); 623 } 624 625 static u32 ionic_get_rxfh_key_size(struct net_device *netdev) 626 { 627 return IONIC_RSS_HASH_KEY_SIZE; 628 } 629 630 static int ionic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 631 u8 *hfunc) 632 { 633 struct ionic_lif *lif = netdev_priv(netdev); 634 unsigned int i, tbl_sz; 635 636 if (indir) { 637 tbl_sz = le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz); 638 for (i = 0; i < tbl_sz; i++) 639 indir[i] = lif->rss_ind_tbl[i]; 640 } 641 642 if (key) 643 memcpy(key, lif->rss_hash_key, IONIC_RSS_HASH_KEY_SIZE); 644 645 if (hfunc) 646 *hfunc = ETH_RSS_HASH_TOP; 647 648 return 0; 649 } 650 651 static int ionic_set_rxfh(struct net_device *netdev, const u32 *indir, 652 const u8 *key, const u8 hfunc) 653 { 654 struct ionic_lif *lif = netdev_priv(netdev); 655 int err; 656 657 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 658 return -EOPNOTSUPP; 659 660 err = ionic_lif_rss_config(lif, lif->rss_types, key, indir); 661 if (err) 662 return err; 663 664 return 0; 665 } 666 667 static int ionic_set_tunable(struct net_device *dev, 668 const struct ethtool_tunable *tuna, 669 const void *data) 670 { 671 struct ionic_lif *lif = netdev_priv(dev); 672 673 switch (tuna->id) { 674 case ETHTOOL_RX_COPYBREAK: 675 lif->rx_copybreak = *(u32 *)data; 676 break; 677 default: 678 return -EOPNOTSUPP; 679 } 680 681 return 0; 682 } 683 684 static int ionic_get_tunable(struct net_device *netdev, 685 const struct ethtool_tunable *tuna, void *data) 686 { 687 struct ionic_lif *lif = netdev_priv(netdev); 688 689 switch (tuna->id) { 690 case ETHTOOL_RX_COPYBREAK: 691 *(u32 *)data = lif->rx_copybreak; 692 break; 693 default: 694 return -EOPNOTSUPP; 695 } 696 697 return 0; 698 } 699 700 static int ionic_get_module_info(struct net_device *netdev, 701 struct ethtool_modinfo *modinfo) 702 703 { 704 struct ionic_lif *lif = netdev_priv(netdev); 705 struct ionic_dev *idev = &lif->ionic->idev; 706 struct ionic_xcvr_status *xcvr; 707 708 xcvr = &idev->port_info->status.xcvr; 709 710 /* report the module data type and length */ 711 switch (xcvr->sprom[0]) { 712 case 0x03: /* SFP */ 713 modinfo->type = ETH_MODULE_SFF_8079; 714 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 715 break; 716 case 0x0D: /* QSFP */ 717 case 0x11: /* QSFP28 */ 718 modinfo->type = ETH_MODULE_SFF_8436; 719 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN; 720 break; 721 default: 722 netdev_info(netdev, "unknown xcvr type 0x%02x\n", 723 xcvr->sprom[0]); 724 break; 725 } 726 727 return 0; 728 } 729 730 static int ionic_get_module_eeprom(struct net_device *netdev, 731 struct ethtool_eeprom *ee, 732 u8 *data) 733 { 734 struct ionic_lif *lif = netdev_priv(netdev); 735 struct ionic_dev *idev = &lif->ionic->idev; 736 struct ionic_xcvr_status *xcvr; 737 char tbuf[sizeof(xcvr->sprom)]; 738 int count = 10; 739 u32 len; 740 741 /* The NIC keeps the module prom up-to-date in the DMA space 742 * so we can simply copy the module bytes into the data buffer. 743 */ 744 xcvr = &idev->port_info->status.xcvr; 745 len = min_t(u32, sizeof(xcvr->sprom), ee->len); 746 747 do { 748 memcpy(data, xcvr->sprom, len); 749 memcpy(tbuf, xcvr->sprom, len); 750 751 /* Let's make sure we got a consistent copy */ 752 if (!memcmp(data, tbuf, len)) 753 break; 754 755 } while (--count); 756 757 if (!count) 758 return -ETIMEDOUT; 759 760 return 0; 761 } 762 763 static int ionic_nway_reset(struct net_device *netdev) 764 { 765 struct ionic_lif *lif = netdev_priv(netdev); 766 struct ionic *ionic = lif->ionic; 767 int err = 0; 768 769 /* flap the link to force auto-negotiation */ 770 771 mutex_lock(&ionic->dev_cmd_lock); 772 773 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_DOWN); 774 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); 775 776 if (!err) { 777 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_UP); 778 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT); 779 } 780 781 mutex_unlock(&ionic->dev_cmd_lock); 782 783 return err; 784 } 785 786 static const struct ethtool_ops ionic_ethtool_ops = { 787 .get_drvinfo = ionic_get_drvinfo, 788 .get_regs_len = ionic_get_regs_len, 789 .get_regs = ionic_get_regs, 790 .get_link = ethtool_op_get_link, 791 .get_link_ksettings = ionic_get_link_ksettings, 792 .set_link_ksettings = ionic_set_link_ksettings, 793 .get_coalesce = ionic_get_coalesce, 794 .set_coalesce = ionic_set_coalesce, 795 .get_ringparam = ionic_get_ringparam, 796 .set_ringparam = ionic_set_ringparam, 797 .get_channels = ionic_get_channels, 798 .set_channels = ionic_set_channels, 799 .get_strings = ionic_get_strings, 800 .get_ethtool_stats = ionic_get_stats, 801 .get_sset_count = ionic_get_sset_count, 802 .get_priv_flags = ionic_get_priv_flags, 803 .set_priv_flags = ionic_set_priv_flags, 804 .get_rxnfc = ionic_get_rxnfc, 805 .get_rxfh_indir_size = ionic_get_rxfh_indir_size, 806 .get_rxfh_key_size = ionic_get_rxfh_key_size, 807 .get_rxfh = ionic_get_rxfh, 808 .set_rxfh = ionic_set_rxfh, 809 .get_tunable = ionic_get_tunable, 810 .set_tunable = ionic_set_tunable, 811 .get_module_info = ionic_get_module_info, 812 .get_module_eeprom = ionic_get_module_eeprom, 813 .get_pauseparam = ionic_get_pauseparam, 814 .set_pauseparam = ionic_set_pauseparam, 815 .get_fecparam = ionic_get_fecparam, 816 .set_fecparam = ionic_set_fecparam, 817 .nway_reset = ionic_nway_reset, 818 }; 819 820 void ionic_ethtool_set_ops(struct net_device *netdev) 821 { 822 netdev->ethtool_ops = &ionic_ethtool_ops; 823 } 824