1 // SPDX-License-Identifier: GPL-2.0 2 /* Marvell OcteonTx2 RVU Ethernet driver 3 * 4 * Copyright (C) 2020 Marvell International Ltd. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 */ 10 11 #include <linux/pci.h> 12 #include <linux/ethtool.h> 13 #include <linux/stddef.h> 14 #include <linux/etherdevice.h> 15 #include <linux/log2.h> 16 #include <linux/net_tstamp.h> 17 18 #include "otx2_common.h" 19 #include "otx2_ptp.h" 20 21 #define DRV_NAME "octeontx2-nicpf" 22 #define DRV_VF_NAME "octeontx2-nicvf" 23 24 struct otx2_stat { 25 char name[ETH_GSTRING_LEN]; 26 unsigned int index; 27 }; 28 29 /* HW device stats */ 30 #define OTX2_DEV_STAT(stat) { \ 31 .name = #stat, \ 32 .index = offsetof(struct otx2_dev_stats, stat) / sizeof(u64), \ 33 } 34 35 static const struct otx2_stat otx2_dev_stats[] = { 36 OTX2_DEV_STAT(rx_ucast_frames), 37 OTX2_DEV_STAT(rx_bcast_frames), 38 OTX2_DEV_STAT(rx_mcast_frames), 39 40 OTX2_DEV_STAT(tx_ucast_frames), 41 OTX2_DEV_STAT(tx_bcast_frames), 42 OTX2_DEV_STAT(tx_mcast_frames), 43 }; 44 45 /* Driver level stats */ 46 #define OTX2_DRV_STAT(stat) { \ 47 .name = #stat, \ 48 .index = offsetof(struct otx2_drv_stats, stat) / sizeof(atomic_t), \ 49 } 50 51 static const struct otx2_stat otx2_drv_stats[] = { 52 OTX2_DRV_STAT(rx_fcs_errs), 53 OTX2_DRV_STAT(rx_oversize_errs), 54 OTX2_DRV_STAT(rx_undersize_errs), 55 OTX2_DRV_STAT(rx_csum_errs), 56 OTX2_DRV_STAT(rx_len_errs), 57 OTX2_DRV_STAT(rx_other_errs), 58 }; 59 60 static const struct otx2_stat otx2_queue_stats[] = { 61 { "bytes", 0 }, 62 { "frames", 1 }, 63 }; 64 65 static const unsigned int otx2_n_dev_stats = ARRAY_SIZE(otx2_dev_stats); 66 static const unsigned int otx2_n_drv_stats = ARRAY_SIZE(otx2_drv_stats); 67 static const unsigned int otx2_n_queue_stats = ARRAY_SIZE(otx2_queue_stats); 68 69 static void otx2_get_drvinfo(struct net_device *netdev, 70 struct ethtool_drvinfo *info) 71 { 72 struct otx2_nic *pfvf = netdev_priv(netdev); 73 74 strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); 75 strlcpy(info->bus_info, pci_name(pfvf->pdev), sizeof(info->bus_info)); 76 } 77 78 static void otx2_get_qset_strings(struct otx2_nic *pfvf, u8 **data, int qset) 79 { 80 int start_qidx = qset * pfvf->hw.rx_queues; 81 int qidx, stats; 82 83 for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) { 84 for (stats = 0; stats < otx2_n_queue_stats; stats++) { 85 sprintf(*data, "rxq%d: %s", qidx + start_qidx, 86 otx2_queue_stats[stats].name); 87 *data += ETH_GSTRING_LEN; 88 } 89 } 90 for (qidx = 0; qidx < pfvf->hw.tx_queues; qidx++) { 91 for (stats = 0; stats < otx2_n_queue_stats; stats++) { 92 sprintf(*data, "txq%d: %s", qidx + start_qidx, 93 otx2_queue_stats[stats].name); 94 *data += ETH_GSTRING_LEN; 95 } 96 } 97 } 98 99 static void otx2_get_strings(struct net_device *netdev, u32 sset, u8 *data) 100 { 101 struct otx2_nic *pfvf = netdev_priv(netdev); 102 int stats; 103 104 if (sset != ETH_SS_STATS) 105 return; 106 107 for (stats = 0; stats < otx2_n_dev_stats; stats++) { 108 memcpy(data, otx2_dev_stats[stats].name, ETH_GSTRING_LEN); 109 data += ETH_GSTRING_LEN; 110 } 111 112 for (stats = 0; stats < otx2_n_drv_stats; stats++) { 113 memcpy(data, otx2_drv_stats[stats].name, ETH_GSTRING_LEN); 114 data += ETH_GSTRING_LEN; 115 } 116 117 otx2_get_qset_strings(pfvf, &data, 0); 118 119 for (stats = 0; stats < CGX_RX_STATS_COUNT; stats++) { 120 sprintf(data, "cgx_rxstat%d: ", stats); 121 data += ETH_GSTRING_LEN; 122 } 123 124 for (stats = 0; stats < CGX_TX_STATS_COUNT; stats++) { 125 sprintf(data, "cgx_txstat%d: ", stats); 126 data += ETH_GSTRING_LEN; 127 } 128 129 strcpy(data, "reset_count"); 130 data += ETH_GSTRING_LEN; 131 } 132 133 static void otx2_get_qset_stats(struct otx2_nic *pfvf, 134 struct ethtool_stats *stats, u64 **data) 135 { 136 int stat, qidx; 137 138 if (!pfvf) 139 return; 140 for (qidx = 0; qidx < pfvf->hw.rx_queues; qidx++) { 141 if (!otx2_update_rq_stats(pfvf, qidx)) { 142 for (stat = 0; stat < otx2_n_queue_stats; stat++) 143 *((*data)++) = 0; 144 continue; 145 } 146 for (stat = 0; stat < otx2_n_queue_stats; stat++) 147 *((*data)++) = ((u64 *)&pfvf->qset.rq[qidx].stats) 148 [otx2_queue_stats[stat].index]; 149 } 150 151 for (qidx = 0; qidx < pfvf->hw.tx_queues; qidx++) { 152 if (!otx2_update_sq_stats(pfvf, qidx)) { 153 for (stat = 0; stat < otx2_n_queue_stats; stat++) 154 *((*data)++) = 0; 155 continue; 156 } 157 for (stat = 0; stat < otx2_n_queue_stats; stat++) 158 *((*data)++) = ((u64 *)&pfvf->qset.sq[qidx].stats) 159 [otx2_queue_stats[stat].index]; 160 } 161 } 162 163 /* Get device and per queue statistics */ 164 static void otx2_get_ethtool_stats(struct net_device *netdev, 165 struct ethtool_stats *stats, u64 *data) 166 { 167 struct otx2_nic *pfvf = netdev_priv(netdev); 168 int stat; 169 170 otx2_get_dev_stats(pfvf); 171 for (stat = 0; stat < otx2_n_dev_stats; stat++) 172 *(data++) = ((u64 *)&pfvf->hw.dev_stats) 173 [otx2_dev_stats[stat].index]; 174 175 for (stat = 0; stat < otx2_n_drv_stats; stat++) 176 *(data++) = atomic_read(&((atomic_t *)&pfvf->hw.drv_stats) 177 [otx2_drv_stats[stat].index]); 178 179 otx2_get_qset_stats(pfvf, stats, &data); 180 otx2_update_lmac_stats(pfvf); 181 for (stat = 0; stat < CGX_RX_STATS_COUNT; stat++) 182 *(data++) = pfvf->hw.cgx_rx_stats[stat]; 183 for (stat = 0; stat < CGX_TX_STATS_COUNT; stat++) 184 *(data++) = pfvf->hw.cgx_tx_stats[stat]; 185 *(data++) = pfvf->reset_count; 186 } 187 188 static int otx2_get_sset_count(struct net_device *netdev, int sset) 189 { 190 struct otx2_nic *pfvf = netdev_priv(netdev); 191 int qstats_count; 192 193 if (sset != ETH_SS_STATS) 194 return -EINVAL; 195 196 qstats_count = otx2_n_queue_stats * 197 (pfvf->hw.rx_queues + pfvf->hw.tx_queues); 198 199 return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + 200 CGX_RX_STATS_COUNT + CGX_TX_STATS_COUNT + 1; 201 } 202 203 /* Get no of queues device supports and current queue count */ 204 static void otx2_get_channels(struct net_device *dev, 205 struct ethtool_channels *channel) 206 { 207 struct otx2_nic *pfvf = netdev_priv(dev); 208 209 channel->max_rx = pfvf->hw.max_queues; 210 channel->max_tx = pfvf->hw.max_queues; 211 212 channel->rx_count = pfvf->hw.rx_queues; 213 channel->tx_count = pfvf->hw.tx_queues; 214 } 215 216 /* Set no of Tx, Rx queues to be used */ 217 static int otx2_set_channels(struct net_device *dev, 218 struct ethtool_channels *channel) 219 { 220 struct otx2_nic *pfvf = netdev_priv(dev); 221 bool if_up = netif_running(dev); 222 int err = 0; 223 224 if (!channel->rx_count || !channel->tx_count) 225 return -EINVAL; 226 227 if (if_up) 228 dev->netdev_ops->ndo_stop(dev); 229 230 err = otx2_set_real_num_queues(dev, channel->tx_count, 231 channel->rx_count); 232 if (err) 233 goto fail; 234 235 pfvf->hw.rx_queues = channel->rx_count; 236 pfvf->hw.tx_queues = channel->tx_count; 237 pfvf->qset.cq_cnt = pfvf->hw.tx_queues + pfvf->hw.rx_queues; 238 239 fail: 240 if (if_up) 241 dev->netdev_ops->ndo_open(dev); 242 243 netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n", 244 pfvf->hw.tx_queues, pfvf->hw.rx_queues); 245 246 return err; 247 } 248 249 static void otx2_get_pauseparam(struct net_device *netdev, 250 struct ethtool_pauseparam *pause) 251 { 252 struct otx2_nic *pfvf = netdev_priv(netdev); 253 struct cgx_pause_frm_cfg *req, *rsp; 254 255 if (is_otx2_lbkvf(pfvf->pdev)) 256 return; 257 258 req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox); 259 if (!req) 260 return; 261 262 if (!otx2_sync_mbox_msg(&pfvf->mbox)) { 263 rsp = (struct cgx_pause_frm_cfg *) 264 otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr); 265 pause->rx_pause = rsp->rx_pause; 266 pause->tx_pause = rsp->tx_pause; 267 } 268 } 269 270 static int otx2_set_pauseparam(struct net_device *netdev, 271 struct ethtool_pauseparam *pause) 272 { 273 struct otx2_nic *pfvf = netdev_priv(netdev); 274 275 if (pause->autoneg) 276 return -EOPNOTSUPP; 277 278 if (is_otx2_lbkvf(pfvf->pdev)) 279 return -EOPNOTSUPP; 280 281 if (pause->rx_pause) 282 pfvf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED; 283 else 284 pfvf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED; 285 286 if (pause->tx_pause) 287 pfvf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED; 288 else 289 pfvf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED; 290 291 return otx2_config_pause_frm(pfvf); 292 } 293 294 static void otx2_get_ringparam(struct net_device *netdev, 295 struct ethtool_ringparam *ring) 296 { 297 struct otx2_nic *pfvf = netdev_priv(netdev); 298 struct otx2_qset *qs = &pfvf->qset; 299 300 ring->rx_max_pending = Q_COUNT(Q_SIZE_MAX); 301 ring->rx_pending = qs->rqe_cnt ? qs->rqe_cnt : Q_COUNT(Q_SIZE_256); 302 ring->tx_max_pending = Q_COUNT(Q_SIZE_MAX); 303 ring->tx_pending = qs->sqe_cnt ? qs->sqe_cnt : Q_COUNT(Q_SIZE_4K); 304 } 305 306 static int otx2_set_ringparam(struct net_device *netdev, 307 struct ethtool_ringparam *ring) 308 { 309 struct otx2_nic *pfvf = netdev_priv(netdev); 310 bool if_up = netif_running(netdev); 311 struct otx2_qset *qs = &pfvf->qset; 312 u32 rx_count, tx_count; 313 314 if (ring->rx_mini_pending || ring->rx_jumbo_pending) 315 return -EINVAL; 316 317 /* Permitted lengths are 16 64 256 1K 4K 16K 64K 256K 1M */ 318 rx_count = ring->rx_pending; 319 /* On some silicon variants a skid or reserved CQEs are 320 * needed to avoid CQ overflow. 321 */ 322 if (rx_count < pfvf->hw.rq_skid) 323 rx_count = pfvf->hw.rq_skid; 324 rx_count = Q_COUNT(Q_SIZE(rx_count, 3)); 325 326 /* Due pipelining impact minimum 2000 unused SQ CQE's 327 * need to be maintained to avoid CQ overflow, hence the 328 * minimum 4K size. 329 */ 330 tx_count = clamp_t(u32, ring->tx_pending, 331 Q_COUNT(Q_SIZE_4K), Q_COUNT(Q_SIZE_MAX)); 332 tx_count = Q_COUNT(Q_SIZE(tx_count, 3)); 333 334 if (tx_count == qs->sqe_cnt && rx_count == qs->rqe_cnt) 335 return 0; 336 337 if (if_up) 338 netdev->netdev_ops->ndo_stop(netdev); 339 340 /* Assigned to the nearest possible exponent. */ 341 qs->sqe_cnt = tx_count; 342 qs->rqe_cnt = rx_count; 343 344 if (if_up) 345 netdev->netdev_ops->ndo_open(netdev); 346 347 return 0; 348 } 349 350 static int otx2_get_coalesce(struct net_device *netdev, 351 struct ethtool_coalesce *cmd) 352 { 353 struct otx2_nic *pfvf = netdev_priv(netdev); 354 struct otx2_hw *hw = &pfvf->hw; 355 356 cmd->rx_coalesce_usecs = hw->cq_time_wait; 357 cmd->rx_max_coalesced_frames = hw->cq_ecount_wait; 358 cmd->tx_coalesce_usecs = hw->cq_time_wait; 359 cmd->tx_max_coalesced_frames = hw->cq_ecount_wait; 360 361 return 0; 362 } 363 364 static int otx2_set_coalesce(struct net_device *netdev, 365 struct ethtool_coalesce *ec) 366 { 367 struct otx2_nic *pfvf = netdev_priv(netdev); 368 struct otx2_hw *hw = &pfvf->hw; 369 int qidx; 370 371 if (!ec->rx_max_coalesced_frames || !ec->tx_max_coalesced_frames) 372 return 0; 373 374 /* 'cq_time_wait' is 8bit and is in multiple of 100ns, 375 * so clamp the user given value to the range of 1 to 25usec. 376 */ 377 ec->rx_coalesce_usecs = clamp_t(u32, ec->rx_coalesce_usecs, 378 1, CQ_TIMER_THRESH_MAX); 379 ec->tx_coalesce_usecs = clamp_t(u32, ec->tx_coalesce_usecs, 380 1, CQ_TIMER_THRESH_MAX); 381 382 /* Rx and Tx are mapped to same CQ, check which one 383 * is changed, if both then choose the min. 384 */ 385 if (hw->cq_time_wait == ec->rx_coalesce_usecs) 386 hw->cq_time_wait = ec->tx_coalesce_usecs; 387 else if (hw->cq_time_wait == ec->tx_coalesce_usecs) 388 hw->cq_time_wait = ec->rx_coalesce_usecs; 389 else 390 hw->cq_time_wait = min_t(u8, ec->rx_coalesce_usecs, 391 ec->tx_coalesce_usecs); 392 393 /* Max ecount_wait supported is 16bit, 394 * so clamp the user given value to the range of 1 to 64k. 395 */ 396 ec->rx_max_coalesced_frames = clamp_t(u32, ec->rx_max_coalesced_frames, 397 1, U16_MAX); 398 ec->tx_max_coalesced_frames = clamp_t(u32, ec->tx_max_coalesced_frames, 399 1, U16_MAX); 400 401 /* Rx and Tx are mapped to same CQ, check which one 402 * is changed, if both then choose the min. 403 */ 404 if (hw->cq_ecount_wait == ec->rx_max_coalesced_frames) 405 hw->cq_ecount_wait = ec->tx_max_coalesced_frames; 406 else if (hw->cq_ecount_wait == ec->tx_max_coalesced_frames) 407 hw->cq_ecount_wait = ec->rx_max_coalesced_frames; 408 else 409 hw->cq_ecount_wait = min_t(u16, ec->rx_max_coalesced_frames, 410 ec->tx_max_coalesced_frames); 411 412 if (netif_running(netdev)) { 413 for (qidx = 0; qidx < pfvf->hw.cint_cnt; qidx++) 414 otx2_config_irq_coalescing(pfvf, qidx); 415 } 416 417 return 0; 418 } 419 420 static int otx2_get_rss_hash_opts(struct otx2_nic *pfvf, 421 struct ethtool_rxnfc *nfc) 422 { 423 struct otx2_rss_info *rss = &pfvf->hw.rss_info; 424 425 if (!(rss->flowkey_cfg & 426 (NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6))) 427 return 0; 428 429 /* Mimimum is IPv4 and IPv6, SIP/DIP */ 430 nfc->data = RXH_IP_SRC | RXH_IP_DST; 431 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_VLAN) 432 nfc->data |= RXH_VLAN; 433 434 switch (nfc->flow_type) { 435 case TCP_V4_FLOW: 436 case TCP_V6_FLOW: 437 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_TCP) 438 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 439 break; 440 case UDP_V4_FLOW: 441 case UDP_V6_FLOW: 442 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_UDP) 443 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 444 break; 445 case SCTP_V4_FLOW: 446 case SCTP_V6_FLOW: 447 if (rss->flowkey_cfg & NIX_FLOW_KEY_TYPE_SCTP) 448 nfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 449 break; 450 case AH_ESP_V4_FLOW: 451 case AH_V4_FLOW: 452 case ESP_V4_FLOW: 453 case IPV4_FLOW: 454 case AH_ESP_V6_FLOW: 455 case AH_V6_FLOW: 456 case ESP_V6_FLOW: 457 case IPV6_FLOW: 458 break; 459 default: 460 return -EINVAL; 461 } 462 return 0; 463 } 464 465 static int otx2_set_rss_hash_opts(struct otx2_nic *pfvf, 466 struct ethtool_rxnfc *nfc) 467 { 468 struct otx2_rss_info *rss = &pfvf->hw.rss_info; 469 u32 rxh_l4 = RXH_L4_B_0_1 | RXH_L4_B_2_3; 470 u32 rss_cfg = rss->flowkey_cfg; 471 472 if (!rss->enable) { 473 netdev_err(pfvf->netdev, 474 "RSS is disabled, cannot change settings\n"); 475 return -EIO; 476 } 477 478 /* Mimimum is IPv4 and IPv6, SIP/DIP */ 479 if (!(nfc->data & RXH_IP_SRC) || !(nfc->data & RXH_IP_DST)) 480 return -EINVAL; 481 482 if (nfc->data & RXH_VLAN) 483 rss_cfg |= NIX_FLOW_KEY_TYPE_VLAN; 484 else 485 rss_cfg &= ~NIX_FLOW_KEY_TYPE_VLAN; 486 487 switch (nfc->flow_type) { 488 case TCP_V4_FLOW: 489 case TCP_V6_FLOW: 490 /* Different config for v4 and v6 is not supported. 491 * Both of them have to be either 4-tuple or 2-tuple. 492 */ 493 switch (nfc->data & rxh_l4) { 494 case 0: 495 rss_cfg &= ~NIX_FLOW_KEY_TYPE_TCP; 496 break; 497 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 498 rss_cfg |= NIX_FLOW_KEY_TYPE_TCP; 499 break; 500 default: 501 return -EINVAL; 502 } 503 break; 504 case UDP_V4_FLOW: 505 case UDP_V6_FLOW: 506 switch (nfc->data & rxh_l4) { 507 case 0: 508 rss_cfg &= ~NIX_FLOW_KEY_TYPE_UDP; 509 break; 510 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 511 rss_cfg |= NIX_FLOW_KEY_TYPE_UDP; 512 break; 513 default: 514 return -EINVAL; 515 } 516 break; 517 case SCTP_V4_FLOW: 518 case SCTP_V6_FLOW: 519 switch (nfc->data & rxh_l4) { 520 case 0: 521 rss_cfg &= ~NIX_FLOW_KEY_TYPE_SCTP; 522 break; 523 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 524 rss_cfg |= NIX_FLOW_KEY_TYPE_SCTP; 525 break; 526 default: 527 return -EINVAL; 528 } 529 break; 530 case IPV4_FLOW: 531 case IPV6_FLOW: 532 rss_cfg = NIX_FLOW_KEY_TYPE_IPV4 | NIX_FLOW_KEY_TYPE_IPV6; 533 break; 534 default: 535 return -EINVAL; 536 } 537 538 rss->flowkey_cfg = rss_cfg; 539 otx2_set_flowkey_cfg(pfvf); 540 return 0; 541 } 542 543 static int otx2_get_rxnfc(struct net_device *dev, 544 struct ethtool_rxnfc *nfc, u32 *rules) 545 { 546 struct otx2_nic *pfvf = netdev_priv(dev); 547 int ret = -EOPNOTSUPP; 548 549 switch (nfc->cmd) { 550 case ETHTOOL_GRXRINGS: 551 nfc->data = pfvf->hw.rx_queues; 552 ret = 0; 553 break; 554 case ETHTOOL_GRXCLSRLCNT: 555 nfc->rule_cnt = pfvf->flow_cfg->nr_flows; 556 ret = 0; 557 break; 558 case ETHTOOL_GRXCLSRULE: 559 ret = otx2_get_flow(pfvf, nfc, nfc->fs.location); 560 break; 561 case ETHTOOL_GRXCLSRLALL: 562 ret = otx2_get_all_flows(pfvf, nfc, rules); 563 break; 564 case ETHTOOL_GRXFH: 565 return otx2_get_rss_hash_opts(pfvf, nfc); 566 default: 567 break; 568 } 569 return ret; 570 } 571 572 static int otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc) 573 { 574 bool ntuple = !!(dev->features & NETIF_F_NTUPLE); 575 struct otx2_nic *pfvf = netdev_priv(dev); 576 int ret = -EOPNOTSUPP; 577 578 switch (nfc->cmd) { 579 case ETHTOOL_SRXFH: 580 ret = otx2_set_rss_hash_opts(pfvf, nfc); 581 break; 582 case ETHTOOL_SRXCLSRLINS: 583 if (netif_running(dev) && ntuple) 584 ret = otx2_add_flow(pfvf, &nfc->fs); 585 break; 586 case ETHTOOL_SRXCLSRLDEL: 587 if (netif_running(dev) && ntuple) 588 ret = otx2_remove_flow(pfvf, nfc->fs.location); 589 break; 590 default: 591 break; 592 } 593 594 return ret; 595 } 596 597 static int otx2vf_get_rxnfc(struct net_device *dev, 598 struct ethtool_rxnfc *nfc, u32 *rules) 599 { 600 struct otx2_nic *pfvf = netdev_priv(dev); 601 int ret = -EOPNOTSUPP; 602 603 switch (nfc->cmd) { 604 case ETHTOOL_GRXRINGS: 605 nfc->data = pfvf->hw.rx_queues; 606 ret = 0; 607 break; 608 case ETHTOOL_GRXFH: 609 return otx2_get_rss_hash_opts(pfvf, nfc); 610 default: 611 break; 612 } 613 return ret; 614 } 615 616 static int otx2vf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc) 617 { 618 struct otx2_nic *pfvf = netdev_priv(dev); 619 int ret = -EOPNOTSUPP; 620 621 switch (nfc->cmd) { 622 case ETHTOOL_SRXFH: 623 ret = otx2_set_rss_hash_opts(pfvf, nfc); 624 break; 625 default: 626 break; 627 } 628 629 return ret; 630 } 631 632 static u32 otx2_get_rxfh_key_size(struct net_device *netdev) 633 { 634 struct otx2_nic *pfvf = netdev_priv(netdev); 635 struct otx2_rss_info *rss; 636 637 rss = &pfvf->hw.rss_info; 638 639 return sizeof(rss->key); 640 } 641 642 static u32 otx2_get_rxfh_indir_size(struct net_device *dev) 643 { 644 struct otx2_nic *pfvf = netdev_priv(dev); 645 646 return pfvf->hw.rss_info.rss_size; 647 } 648 649 /* Get RSS configuration */ 650 static int otx2_get_rxfh(struct net_device *dev, u32 *indir, 651 u8 *hkey, u8 *hfunc) 652 { 653 struct otx2_nic *pfvf = netdev_priv(dev); 654 struct otx2_rss_info *rss; 655 int idx; 656 657 rss = &pfvf->hw.rss_info; 658 659 if (indir) { 660 for (idx = 0; idx < rss->rss_size; idx++) 661 indir[idx] = rss->ind_tbl[idx]; 662 } 663 664 if (hkey) 665 memcpy(hkey, rss->key, sizeof(rss->key)); 666 667 if (hfunc) 668 *hfunc = ETH_RSS_HASH_TOP; 669 670 return 0; 671 } 672 673 /* Configure RSS table and hash key */ 674 static int otx2_set_rxfh(struct net_device *dev, const u32 *indir, 675 const u8 *hkey, const u8 hfunc) 676 { 677 struct otx2_nic *pfvf = netdev_priv(dev); 678 struct otx2_rss_info *rss; 679 int idx; 680 681 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 682 return -EOPNOTSUPP; 683 684 rss = &pfvf->hw.rss_info; 685 686 if (!rss->enable) { 687 netdev_err(dev, "RSS is disabled, cannot change settings\n"); 688 return -EIO; 689 } 690 691 if (indir) { 692 for (idx = 0; idx < rss->rss_size; idx++) 693 rss->ind_tbl[idx] = indir[idx]; 694 } 695 696 if (hkey) { 697 memcpy(rss->key, hkey, sizeof(rss->key)); 698 otx2_set_rss_key(pfvf); 699 } 700 701 otx2_set_rss_table(pfvf); 702 return 0; 703 } 704 705 static u32 otx2_get_msglevel(struct net_device *netdev) 706 { 707 struct otx2_nic *pfvf = netdev_priv(netdev); 708 709 return pfvf->msg_enable; 710 } 711 712 static void otx2_set_msglevel(struct net_device *netdev, u32 val) 713 { 714 struct otx2_nic *pfvf = netdev_priv(netdev); 715 716 pfvf->msg_enable = val; 717 } 718 719 static u32 otx2_get_link(struct net_device *netdev) 720 { 721 struct otx2_nic *pfvf = netdev_priv(netdev); 722 723 /* LBK link is internal and always UP */ 724 if (is_otx2_lbkvf(pfvf->pdev)) 725 return 1; 726 return pfvf->linfo.link_up; 727 } 728 729 static int otx2_get_ts_info(struct net_device *netdev, 730 struct ethtool_ts_info *info) 731 { 732 struct otx2_nic *pfvf = netdev_priv(netdev); 733 734 if (!pfvf->ptp) 735 return ethtool_op_get_ts_info(netdev, info); 736 737 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 738 SOF_TIMESTAMPING_RX_SOFTWARE | 739 SOF_TIMESTAMPING_SOFTWARE | 740 SOF_TIMESTAMPING_TX_HARDWARE | 741 SOF_TIMESTAMPING_RX_HARDWARE | 742 SOF_TIMESTAMPING_RAW_HARDWARE; 743 744 info->phc_index = otx2_ptp_clock_index(pfvf); 745 746 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); 747 748 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | 749 (1 << HWTSTAMP_FILTER_ALL); 750 751 return 0; 752 } 753 754 static const struct ethtool_ops otx2_ethtool_ops = { 755 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 756 ETHTOOL_COALESCE_MAX_FRAMES, 757 .get_link = otx2_get_link, 758 .get_drvinfo = otx2_get_drvinfo, 759 .get_strings = otx2_get_strings, 760 .get_ethtool_stats = otx2_get_ethtool_stats, 761 .get_sset_count = otx2_get_sset_count, 762 .set_channels = otx2_set_channels, 763 .get_channels = otx2_get_channels, 764 .get_ringparam = otx2_get_ringparam, 765 .set_ringparam = otx2_set_ringparam, 766 .get_coalesce = otx2_get_coalesce, 767 .set_coalesce = otx2_set_coalesce, 768 .get_rxnfc = otx2_get_rxnfc, 769 .set_rxnfc = otx2_set_rxnfc, 770 .get_rxfh_key_size = otx2_get_rxfh_key_size, 771 .get_rxfh_indir_size = otx2_get_rxfh_indir_size, 772 .get_rxfh = otx2_get_rxfh, 773 .set_rxfh = otx2_set_rxfh, 774 .get_msglevel = otx2_get_msglevel, 775 .set_msglevel = otx2_set_msglevel, 776 .get_pauseparam = otx2_get_pauseparam, 777 .set_pauseparam = otx2_set_pauseparam, 778 .get_ts_info = otx2_get_ts_info, 779 }; 780 781 void otx2_set_ethtool_ops(struct net_device *netdev) 782 { 783 netdev->ethtool_ops = &otx2_ethtool_ops; 784 } 785 786 /* VF's ethtool APIs */ 787 static void otx2vf_get_drvinfo(struct net_device *netdev, 788 struct ethtool_drvinfo *info) 789 { 790 struct otx2_nic *vf = netdev_priv(netdev); 791 792 strlcpy(info->driver, DRV_VF_NAME, sizeof(info->driver)); 793 strlcpy(info->bus_info, pci_name(vf->pdev), sizeof(info->bus_info)); 794 } 795 796 static void otx2vf_get_strings(struct net_device *netdev, u32 sset, u8 *data) 797 { 798 struct otx2_nic *vf = netdev_priv(netdev); 799 int stats; 800 801 if (sset != ETH_SS_STATS) 802 return; 803 804 for (stats = 0; stats < otx2_n_dev_stats; stats++) { 805 memcpy(data, otx2_dev_stats[stats].name, ETH_GSTRING_LEN); 806 data += ETH_GSTRING_LEN; 807 } 808 809 for (stats = 0; stats < otx2_n_drv_stats; stats++) { 810 memcpy(data, otx2_drv_stats[stats].name, ETH_GSTRING_LEN); 811 data += ETH_GSTRING_LEN; 812 } 813 814 otx2_get_qset_strings(vf, &data, 0); 815 816 strcpy(data, "reset_count"); 817 data += ETH_GSTRING_LEN; 818 } 819 820 static void otx2vf_get_ethtool_stats(struct net_device *netdev, 821 struct ethtool_stats *stats, u64 *data) 822 { 823 struct otx2_nic *vf = netdev_priv(netdev); 824 int stat; 825 826 otx2_get_dev_stats(vf); 827 for (stat = 0; stat < otx2_n_dev_stats; stat++) 828 *(data++) = ((u64 *)&vf->hw.dev_stats) 829 [otx2_dev_stats[stat].index]; 830 831 for (stat = 0; stat < otx2_n_drv_stats; stat++) 832 *(data++) = atomic_read(&((atomic_t *)&vf->hw.drv_stats) 833 [otx2_drv_stats[stat].index]); 834 835 otx2_get_qset_stats(vf, stats, &data); 836 *(data++) = vf->reset_count; 837 } 838 839 static int otx2vf_get_sset_count(struct net_device *netdev, int sset) 840 { 841 struct otx2_nic *vf = netdev_priv(netdev); 842 int qstats_count; 843 844 if (sset != ETH_SS_STATS) 845 return -EINVAL; 846 847 qstats_count = otx2_n_queue_stats * 848 (vf->hw.rx_queues + vf->hw.tx_queues); 849 850 return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + 1; 851 } 852 853 static const struct ethtool_ops otx2vf_ethtool_ops = { 854 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 855 ETHTOOL_COALESCE_MAX_FRAMES, 856 .get_link = otx2_get_link, 857 .get_drvinfo = otx2vf_get_drvinfo, 858 .get_strings = otx2vf_get_strings, 859 .get_ethtool_stats = otx2vf_get_ethtool_stats, 860 .get_sset_count = otx2vf_get_sset_count, 861 .set_channels = otx2_set_channels, 862 .get_channels = otx2_get_channels, 863 .get_rxnfc = otx2vf_get_rxnfc, 864 .set_rxnfc = otx2vf_set_rxnfc, 865 .get_rxfh_key_size = otx2_get_rxfh_key_size, 866 .get_rxfh_indir_size = otx2_get_rxfh_indir_size, 867 .get_rxfh = otx2_get_rxfh, 868 .set_rxfh = otx2_set_rxfh, 869 .get_ringparam = otx2_get_ringparam, 870 .set_ringparam = otx2_set_ringparam, 871 .get_coalesce = otx2_get_coalesce, 872 .set_coalesce = otx2_set_coalesce, 873 .get_msglevel = otx2_get_msglevel, 874 .set_msglevel = otx2_set_msglevel, 875 .get_pauseparam = otx2_get_pauseparam, 876 .set_pauseparam = otx2_set_pauseparam, 877 }; 878 879 void otx2vf_set_ethtool_ops(struct net_device *netdev) 880 { 881 netdev->ethtool_ops = &otx2vf_ethtool_ops; 882 } 883 EXPORT_SYMBOL(otx2vf_set_ethtool_ops); 884