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_GRXFH: 555 return otx2_get_rss_hash_opts(pfvf, nfc); 556 default: 557 break; 558 } 559 return ret; 560 } 561 562 static int otx2_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *nfc) 563 { 564 struct otx2_nic *pfvf = netdev_priv(dev); 565 int ret = -EOPNOTSUPP; 566 567 switch (nfc->cmd) { 568 case ETHTOOL_SRXFH: 569 ret = otx2_set_rss_hash_opts(pfvf, nfc); 570 break; 571 default: 572 break; 573 } 574 575 return ret; 576 } 577 578 static u32 otx2_get_rxfh_key_size(struct net_device *netdev) 579 { 580 struct otx2_nic *pfvf = netdev_priv(netdev); 581 struct otx2_rss_info *rss; 582 583 rss = &pfvf->hw.rss_info; 584 585 return sizeof(rss->key); 586 } 587 588 static u32 otx2_get_rxfh_indir_size(struct net_device *dev) 589 { 590 struct otx2_nic *pfvf = netdev_priv(dev); 591 592 return pfvf->hw.rss_info.rss_size; 593 } 594 595 /* Get RSS configuration */ 596 static int otx2_get_rxfh(struct net_device *dev, u32 *indir, 597 u8 *hkey, u8 *hfunc) 598 { 599 struct otx2_nic *pfvf = netdev_priv(dev); 600 struct otx2_rss_info *rss; 601 int idx; 602 603 rss = &pfvf->hw.rss_info; 604 605 if (indir) { 606 for (idx = 0; idx < rss->rss_size; idx++) 607 indir[idx] = rss->ind_tbl[idx]; 608 } 609 610 if (hkey) 611 memcpy(hkey, rss->key, sizeof(rss->key)); 612 613 if (hfunc) 614 *hfunc = ETH_RSS_HASH_TOP; 615 616 return 0; 617 } 618 619 /* Configure RSS table and hash key */ 620 static int otx2_set_rxfh(struct net_device *dev, const u32 *indir, 621 const u8 *hkey, const u8 hfunc) 622 { 623 struct otx2_nic *pfvf = netdev_priv(dev); 624 struct otx2_rss_info *rss; 625 int idx; 626 627 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 628 return -EOPNOTSUPP; 629 630 rss = &pfvf->hw.rss_info; 631 632 if (!rss->enable) { 633 netdev_err(dev, "RSS is disabled, cannot change settings\n"); 634 return -EIO; 635 } 636 637 if (indir) { 638 for (idx = 0; idx < rss->rss_size; idx++) 639 rss->ind_tbl[idx] = indir[idx]; 640 } 641 642 if (hkey) { 643 memcpy(rss->key, hkey, sizeof(rss->key)); 644 otx2_set_rss_key(pfvf); 645 } 646 647 otx2_set_rss_table(pfvf); 648 return 0; 649 } 650 651 static u32 otx2_get_msglevel(struct net_device *netdev) 652 { 653 struct otx2_nic *pfvf = netdev_priv(netdev); 654 655 return pfvf->msg_enable; 656 } 657 658 static void otx2_set_msglevel(struct net_device *netdev, u32 val) 659 { 660 struct otx2_nic *pfvf = netdev_priv(netdev); 661 662 pfvf->msg_enable = val; 663 } 664 665 static u32 otx2_get_link(struct net_device *netdev) 666 { 667 struct otx2_nic *pfvf = netdev_priv(netdev); 668 669 /* LBK link is internal and always UP */ 670 if (is_otx2_lbkvf(pfvf->pdev)) 671 return 1; 672 return pfvf->linfo.link_up; 673 } 674 675 static int otx2_get_ts_info(struct net_device *netdev, 676 struct ethtool_ts_info *info) 677 { 678 struct otx2_nic *pfvf = netdev_priv(netdev); 679 680 if (!pfvf->ptp) 681 return ethtool_op_get_ts_info(netdev, info); 682 683 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 684 SOF_TIMESTAMPING_RX_SOFTWARE | 685 SOF_TIMESTAMPING_SOFTWARE | 686 SOF_TIMESTAMPING_TX_HARDWARE | 687 SOF_TIMESTAMPING_RX_HARDWARE | 688 SOF_TIMESTAMPING_RAW_HARDWARE; 689 690 info->phc_index = otx2_ptp_clock_index(pfvf); 691 692 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); 693 694 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | 695 (1 << HWTSTAMP_FILTER_ALL); 696 697 return 0; 698 } 699 700 static const struct ethtool_ops otx2_ethtool_ops = { 701 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 702 ETHTOOL_COALESCE_MAX_FRAMES, 703 .get_link = otx2_get_link, 704 .get_drvinfo = otx2_get_drvinfo, 705 .get_strings = otx2_get_strings, 706 .get_ethtool_stats = otx2_get_ethtool_stats, 707 .get_sset_count = otx2_get_sset_count, 708 .set_channels = otx2_set_channels, 709 .get_channels = otx2_get_channels, 710 .get_ringparam = otx2_get_ringparam, 711 .set_ringparam = otx2_set_ringparam, 712 .get_coalesce = otx2_get_coalesce, 713 .set_coalesce = otx2_set_coalesce, 714 .get_rxnfc = otx2_get_rxnfc, 715 .set_rxnfc = otx2_set_rxnfc, 716 .get_rxfh_key_size = otx2_get_rxfh_key_size, 717 .get_rxfh_indir_size = otx2_get_rxfh_indir_size, 718 .get_rxfh = otx2_get_rxfh, 719 .set_rxfh = otx2_set_rxfh, 720 .get_msglevel = otx2_get_msglevel, 721 .set_msglevel = otx2_set_msglevel, 722 .get_pauseparam = otx2_get_pauseparam, 723 .set_pauseparam = otx2_set_pauseparam, 724 .get_ts_info = otx2_get_ts_info, 725 }; 726 727 void otx2_set_ethtool_ops(struct net_device *netdev) 728 { 729 netdev->ethtool_ops = &otx2_ethtool_ops; 730 } 731 732 /* VF's ethtool APIs */ 733 static void otx2vf_get_drvinfo(struct net_device *netdev, 734 struct ethtool_drvinfo *info) 735 { 736 struct otx2_nic *vf = netdev_priv(netdev); 737 738 strlcpy(info->driver, DRV_VF_NAME, sizeof(info->driver)); 739 strlcpy(info->bus_info, pci_name(vf->pdev), sizeof(info->bus_info)); 740 } 741 742 static void otx2vf_get_strings(struct net_device *netdev, u32 sset, u8 *data) 743 { 744 struct otx2_nic *vf = netdev_priv(netdev); 745 int stats; 746 747 if (sset != ETH_SS_STATS) 748 return; 749 750 for (stats = 0; stats < otx2_n_dev_stats; stats++) { 751 memcpy(data, otx2_dev_stats[stats].name, ETH_GSTRING_LEN); 752 data += ETH_GSTRING_LEN; 753 } 754 755 for (stats = 0; stats < otx2_n_drv_stats; stats++) { 756 memcpy(data, otx2_drv_stats[stats].name, ETH_GSTRING_LEN); 757 data += ETH_GSTRING_LEN; 758 } 759 760 otx2_get_qset_strings(vf, &data, 0); 761 762 strcpy(data, "reset_count"); 763 data += ETH_GSTRING_LEN; 764 } 765 766 static void otx2vf_get_ethtool_stats(struct net_device *netdev, 767 struct ethtool_stats *stats, u64 *data) 768 { 769 struct otx2_nic *vf = netdev_priv(netdev); 770 int stat; 771 772 otx2_get_dev_stats(vf); 773 for (stat = 0; stat < otx2_n_dev_stats; stat++) 774 *(data++) = ((u64 *)&vf->hw.dev_stats) 775 [otx2_dev_stats[stat].index]; 776 777 for (stat = 0; stat < otx2_n_drv_stats; stat++) 778 *(data++) = atomic_read(&((atomic_t *)&vf->hw.drv_stats) 779 [otx2_drv_stats[stat].index]); 780 781 otx2_get_qset_stats(vf, stats, &data); 782 *(data++) = vf->reset_count; 783 } 784 785 static int otx2vf_get_sset_count(struct net_device *netdev, int sset) 786 { 787 struct otx2_nic *vf = netdev_priv(netdev); 788 int qstats_count; 789 790 if (sset != ETH_SS_STATS) 791 return -EINVAL; 792 793 qstats_count = otx2_n_queue_stats * 794 (vf->hw.rx_queues + vf->hw.tx_queues); 795 796 return otx2_n_dev_stats + otx2_n_drv_stats + qstats_count + 1; 797 } 798 799 static const struct ethtool_ops otx2vf_ethtool_ops = { 800 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 801 ETHTOOL_COALESCE_MAX_FRAMES, 802 .get_link = otx2_get_link, 803 .get_drvinfo = otx2vf_get_drvinfo, 804 .get_strings = otx2vf_get_strings, 805 .get_ethtool_stats = otx2vf_get_ethtool_stats, 806 .get_sset_count = otx2vf_get_sset_count, 807 .set_channels = otx2_set_channels, 808 .get_channels = otx2_get_channels, 809 .get_rxnfc = otx2_get_rxnfc, 810 .set_rxnfc = otx2_set_rxnfc, 811 .get_rxfh_key_size = otx2_get_rxfh_key_size, 812 .get_rxfh_indir_size = otx2_get_rxfh_indir_size, 813 .get_rxfh = otx2_get_rxfh, 814 .set_rxfh = otx2_set_rxfh, 815 .get_ringparam = otx2_get_ringparam, 816 .set_ringparam = otx2_set_ringparam, 817 .get_coalesce = otx2_get_coalesce, 818 .set_coalesce = otx2_set_coalesce, 819 .get_msglevel = otx2_get_msglevel, 820 .set_msglevel = otx2_set_msglevel, 821 .get_pauseparam = otx2_get_pauseparam, 822 .set_pauseparam = otx2_set_pauseparam, 823 }; 824 825 void otx2vf_set_ethtool_ops(struct net_device *netdev) 826 { 827 netdev->ethtool_ops = &otx2vf_ethtool_ops; 828 } 829 EXPORT_SYMBOL(otx2vf_set_ethtool_ops); 830