1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2018, Intel Corporation. */ 3 4 /* ethtool support for ice */ 5 6 #include "ice.h" 7 #include "ice_lib.h" 8 #include "ice_dcb_lib.h" 9 10 struct ice_stats { 11 char stat_string[ETH_GSTRING_LEN]; 12 int sizeof_stat; 13 int stat_offset; 14 }; 15 16 #define ICE_STAT(_type, _name, _stat) { \ 17 .stat_string = _name, \ 18 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \ 19 .stat_offset = offsetof(_type, _stat) \ 20 } 21 22 #define ICE_VSI_STAT(_name, _stat) \ 23 ICE_STAT(struct ice_vsi, _name, _stat) 24 #define ICE_PF_STAT(_name, _stat) \ 25 ICE_STAT(struct ice_pf, _name, _stat) 26 27 static int ice_q_stats_len(struct net_device *netdev) 28 { 29 struct ice_netdev_priv *np = netdev_priv(netdev); 30 31 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) * 32 (sizeof(struct ice_q_stats) / sizeof(u64))); 33 } 34 35 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats) 36 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats) 37 38 #define ICE_PFC_STATS_LEN ( \ 39 (FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_rx) + \ 40 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_rx) + \ 41 FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_tx) + \ 42 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_tx)) \ 43 / sizeof(u64)) 44 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \ 45 ICE_VSI_STATS_LEN + ice_q_stats_len(n)) 46 47 static const struct ice_stats ice_gstrings_vsi_stats[] = { 48 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast), 49 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast), 50 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast), 51 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast), 52 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), 53 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), 54 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes), 55 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes), 56 ICE_VSI_STAT("rx_discards", eth_stats.rx_discards), 57 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors), 58 ICE_VSI_STAT("tx_linearize", tx_linearize), 59 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), 60 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed), 61 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed), 62 }; 63 64 /* These PF_STATs might look like duplicates of some NETDEV_STATs, 65 * but they aren't. This device is capable of supporting multiple 66 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual 67 * netdevs whereas the PF_STATs are for the physical function that's 68 * hosting these netdevs. 69 * 70 * The PF_STATs are appended to the netdev stats only when ethtool -S 71 * is queried on the base PF netdev. 72 */ 73 static const struct ice_stats ice_gstrings_pf_stats[] = { 74 ICE_PF_STAT("port.tx_bytes", stats.eth.tx_bytes), 75 ICE_PF_STAT("port.rx_bytes", stats.eth.rx_bytes), 76 ICE_PF_STAT("port.tx_unicast", stats.eth.tx_unicast), 77 ICE_PF_STAT("port.rx_unicast", stats.eth.rx_unicast), 78 ICE_PF_STAT("port.tx_multicast", stats.eth.tx_multicast), 79 ICE_PF_STAT("port.rx_multicast", stats.eth.rx_multicast), 80 ICE_PF_STAT("port.tx_broadcast", stats.eth.tx_broadcast), 81 ICE_PF_STAT("port.rx_broadcast", stats.eth.rx_broadcast), 82 ICE_PF_STAT("port.tx_errors", stats.eth.tx_errors), 83 ICE_PF_STAT("port.tx_size_64", stats.tx_size_64), 84 ICE_PF_STAT("port.rx_size_64", stats.rx_size_64), 85 ICE_PF_STAT("port.tx_size_127", stats.tx_size_127), 86 ICE_PF_STAT("port.rx_size_127", stats.rx_size_127), 87 ICE_PF_STAT("port.tx_size_255", stats.tx_size_255), 88 ICE_PF_STAT("port.rx_size_255", stats.rx_size_255), 89 ICE_PF_STAT("port.tx_size_511", stats.tx_size_511), 90 ICE_PF_STAT("port.rx_size_511", stats.rx_size_511), 91 ICE_PF_STAT("port.tx_size_1023", stats.tx_size_1023), 92 ICE_PF_STAT("port.rx_size_1023", stats.rx_size_1023), 93 ICE_PF_STAT("port.tx_size_1522", stats.tx_size_1522), 94 ICE_PF_STAT("port.rx_size_1522", stats.rx_size_1522), 95 ICE_PF_STAT("port.tx_size_big", stats.tx_size_big), 96 ICE_PF_STAT("port.rx_size_big", stats.rx_size_big), 97 ICE_PF_STAT("port.link_xon_tx", stats.link_xon_tx), 98 ICE_PF_STAT("port.link_xon_rx", stats.link_xon_rx), 99 ICE_PF_STAT("port.link_xoff_tx", stats.link_xoff_tx), 100 ICE_PF_STAT("port.link_xoff_rx", stats.link_xoff_rx), 101 ICE_PF_STAT("port.tx_dropped_link_down", stats.tx_dropped_link_down), 102 ICE_PF_STAT("port.rx_undersize", stats.rx_undersize), 103 ICE_PF_STAT("port.rx_fragments", stats.rx_fragments), 104 ICE_PF_STAT("port.rx_oversize", stats.rx_oversize), 105 ICE_PF_STAT("port.rx_jabber", stats.rx_jabber), 106 ICE_PF_STAT("port.rx_csum_bad", hw_csum_rx_error), 107 ICE_PF_STAT("port.rx_length_errors", stats.rx_len_errors), 108 ICE_PF_STAT("port.rx_dropped", stats.eth.rx_discards), 109 ICE_PF_STAT("port.rx_crc_errors", stats.crc_errors), 110 ICE_PF_STAT("port.illegal_bytes", stats.illegal_bytes), 111 ICE_PF_STAT("port.mac_local_faults", stats.mac_local_faults), 112 ICE_PF_STAT("port.mac_remote_faults", stats.mac_remote_faults), 113 }; 114 115 static const u32 ice_regs_dump_list[] = { 116 PFGEN_STATE, 117 PRTGEN_STATUS, 118 QRX_CTRL(0), 119 QINT_TQCTL(0), 120 QINT_RQCTL(0), 121 PFINT_OICR_ENA, 122 QRX_ITR(0), 123 }; 124 125 struct ice_priv_flag { 126 char name[ETH_GSTRING_LEN]; 127 u32 bitno; /* bit position in pf->flags */ 128 }; 129 130 #define ICE_PRIV_FLAG(_name, _bitno) { \ 131 .name = _name, \ 132 .bitno = _bitno, \ 133 } 134 135 static const struct ice_priv_flag ice_gstrings_priv_flags[] = { 136 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA), 137 ICE_PRIV_FLAG("disable-fw-lldp", ICE_FLAG_DISABLE_FW_LLDP), 138 }; 139 140 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags) 141 142 /** 143 * ice_nvm_version_str - format the NVM version strings 144 * @hw: ptr to the hardware info 145 */ 146 static char *ice_nvm_version_str(struct ice_hw *hw) 147 { 148 static char buf[ICE_ETHTOOL_FWVER_LEN]; 149 u8 ver, patch; 150 u32 full_ver; 151 u16 build; 152 153 full_ver = hw->nvm.oem_ver; 154 ver = (u8)((full_ver & ICE_OEM_VER_MASK) >> ICE_OEM_VER_SHIFT); 155 build = (u16)((full_ver & ICE_OEM_VER_BUILD_MASK) >> 156 ICE_OEM_VER_BUILD_SHIFT); 157 patch = (u8)(full_ver & ICE_OEM_VER_PATCH_MASK); 158 159 snprintf(buf, sizeof(buf), "%x.%02x 0x%x %d.%d.%d", 160 (hw->nvm.ver & ICE_NVM_VER_HI_MASK) >> ICE_NVM_VER_HI_SHIFT, 161 (hw->nvm.ver & ICE_NVM_VER_LO_MASK) >> ICE_NVM_VER_LO_SHIFT, 162 hw->nvm.eetrack, ver, build, patch); 163 164 return buf; 165 } 166 167 static void 168 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) 169 { 170 struct ice_netdev_priv *np = netdev_priv(netdev); 171 struct ice_vsi *vsi = np->vsi; 172 struct ice_pf *pf = vsi->back; 173 174 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); 175 strlcpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version)); 176 strlcpy(drvinfo->fw_version, ice_nvm_version_str(&pf->hw), 177 sizeof(drvinfo->fw_version)); 178 strlcpy(drvinfo->bus_info, pci_name(pf->pdev), 179 sizeof(drvinfo->bus_info)); 180 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE; 181 } 182 183 static int ice_get_regs_len(struct net_device __always_unused *netdev) 184 { 185 return sizeof(ice_regs_dump_list); 186 } 187 188 static void 189 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) 190 { 191 struct ice_netdev_priv *np = netdev_priv(netdev); 192 struct ice_pf *pf = np->vsi->back; 193 struct ice_hw *hw = &pf->hw; 194 u32 *regs_buf = (u32 *)p; 195 int i; 196 197 regs->version = 1; 198 199 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i) 200 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]); 201 } 202 203 static u32 ice_get_msglevel(struct net_device *netdev) 204 { 205 struct ice_netdev_priv *np = netdev_priv(netdev); 206 struct ice_pf *pf = np->vsi->back; 207 208 #ifndef CONFIG_DYNAMIC_DEBUG 209 if (pf->hw.debug_mask) 210 netdev_info(netdev, "hw debug_mask: 0x%llX\n", 211 pf->hw.debug_mask); 212 #endif /* !CONFIG_DYNAMIC_DEBUG */ 213 214 return pf->msg_enable; 215 } 216 217 static void ice_set_msglevel(struct net_device *netdev, u32 data) 218 { 219 struct ice_netdev_priv *np = netdev_priv(netdev); 220 struct ice_pf *pf = np->vsi->back; 221 222 #ifndef CONFIG_DYNAMIC_DEBUG 223 if (ICE_DBG_USER & data) 224 pf->hw.debug_mask = data; 225 else 226 pf->msg_enable = data; 227 #else 228 pf->msg_enable = data; 229 #endif /* !CONFIG_DYNAMIC_DEBUG */ 230 } 231 232 static int ice_get_eeprom_len(struct net_device *netdev) 233 { 234 struct ice_netdev_priv *np = netdev_priv(netdev); 235 struct ice_pf *pf = np->vsi->back; 236 237 return (int)(pf->hw.nvm.sr_words * sizeof(u16)); 238 } 239 240 static int 241 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, 242 u8 *bytes) 243 { 244 struct ice_netdev_priv *np = netdev_priv(netdev); 245 u16 first_word, last_word, nwords; 246 struct ice_vsi *vsi = np->vsi; 247 struct ice_pf *pf = vsi->back; 248 struct ice_hw *hw = &pf->hw; 249 enum ice_status status; 250 struct device *dev; 251 int ret = 0; 252 u16 *buf; 253 254 dev = &pf->pdev->dev; 255 256 eeprom->magic = hw->vendor_id | (hw->device_id << 16); 257 258 first_word = eeprom->offset >> 1; 259 last_word = (eeprom->offset + eeprom->len - 1) >> 1; 260 nwords = last_word - first_word + 1; 261 262 buf = devm_kcalloc(dev, nwords, sizeof(u16), GFP_KERNEL); 263 if (!buf) 264 return -ENOMEM; 265 266 status = ice_read_sr_buf(hw, first_word, &nwords, buf); 267 if (status) { 268 dev_err(dev, "ice_read_sr_buf failed, err %d aq_err %d\n", 269 status, hw->adminq.sq_last_status); 270 eeprom->len = sizeof(u16) * nwords; 271 ret = -EIO; 272 goto out; 273 } 274 275 memcpy(bytes, (u8 *)buf + (eeprom->offset & 1), eeprom->len); 276 out: 277 devm_kfree(dev, buf); 278 return ret; 279 } 280 281 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 282 { 283 struct ice_netdev_priv *np = netdev_priv(netdev); 284 struct ice_vsi *vsi = np->vsi; 285 char *p = (char *)data; 286 unsigned int i; 287 288 switch (stringset) { 289 case ETH_SS_STATS: 290 for (i = 0; i < ICE_VSI_STATS_LEN; i++) { 291 snprintf(p, ETH_GSTRING_LEN, "%s", 292 ice_gstrings_vsi_stats[i].stat_string); 293 p += ETH_GSTRING_LEN; 294 } 295 296 ice_for_each_alloc_txq(vsi, i) { 297 snprintf(p, ETH_GSTRING_LEN, 298 "tx-queue-%u.tx_packets", i); 299 p += ETH_GSTRING_LEN; 300 snprintf(p, ETH_GSTRING_LEN, "tx-queue-%u.tx_bytes", i); 301 p += ETH_GSTRING_LEN; 302 } 303 304 ice_for_each_alloc_rxq(vsi, i) { 305 snprintf(p, ETH_GSTRING_LEN, 306 "rx-queue-%u.rx_packets", i); 307 p += ETH_GSTRING_LEN; 308 snprintf(p, ETH_GSTRING_LEN, "rx-queue-%u.rx_bytes", i); 309 p += ETH_GSTRING_LEN; 310 } 311 312 if (vsi->type != ICE_VSI_PF) 313 return; 314 315 for (i = 0; i < ICE_PF_STATS_LEN; i++) { 316 snprintf(p, ETH_GSTRING_LEN, "%s", 317 ice_gstrings_pf_stats[i].stat_string); 318 p += ETH_GSTRING_LEN; 319 } 320 321 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { 322 snprintf(p, ETH_GSTRING_LEN, 323 "port.tx-priority-%u-xon", i); 324 p += ETH_GSTRING_LEN; 325 snprintf(p, ETH_GSTRING_LEN, 326 "port.tx-priority-%u-xoff", i); 327 p += ETH_GSTRING_LEN; 328 } 329 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { 330 snprintf(p, ETH_GSTRING_LEN, 331 "port.rx-priority-%u-xon", i); 332 p += ETH_GSTRING_LEN; 333 snprintf(p, ETH_GSTRING_LEN, 334 "port.rx-priority-%u-xoff", i); 335 p += ETH_GSTRING_LEN; 336 } 337 break; 338 case ETH_SS_PRIV_FLAGS: 339 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { 340 snprintf(p, ETH_GSTRING_LEN, "%s", 341 ice_gstrings_priv_flags[i].name); 342 p += ETH_GSTRING_LEN; 343 } 344 break; 345 default: 346 break; 347 } 348 } 349 350 static int 351 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) 352 { 353 struct ice_netdev_priv *np = netdev_priv(netdev); 354 bool led_active; 355 356 switch (state) { 357 case ETHTOOL_ID_ACTIVE: 358 led_active = true; 359 break; 360 case ETHTOOL_ID_INACTIVE: 361 led_active = false; 362 break; 363 default: 364 return -EINVAL; 365 } 366 367 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL)) 368 return -EIO; 369 370 return 0; 371 } 372 373 /** 374 * ice_get_priv_flags - report device private flags 375 * @netdev: network interface device structure 376 * 377 * The get string set count and the string set should be matched for each 378 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags 379 * array. 380 * 381 * Returns a u32 bitmap of flags. 382 */ 383 static u32 ice_get_priv_flags(struct net_device *netdev) 384 { 385 struct ice_netdev_priv *np = netdev_priv(netdev); 386 struct ice_vsi *vsi = np->vsi; 387 struct ice_pf *pf = vsi->back; 388 u32 i, ret_flags = 0; 389 390 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { 391 const struct ice_priv_flag *priv_flag; 392 393 priv_flag = &ice_gstrings_priv_flags[i]; 394 395 if (test_bit(priv_flag->bitno, pf->flags)) 396 ret_flags |= BIT(i); 397 } 398 399 return ret_flags; 400 } 401 402 /** 403 * ice_set_priv_flags - set private flags 404 * @netdev: network interface device structure 405 * @flags: bit flags to be set 406 */ 407 static int ice_set_priv_flags(struct net_device *netdev, u32 flags) 408 { 409 struct ice_netdev_priv *np = netdev_priv(netdev); 410 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS); 411 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS); 412 struct ice_vsi *vsi = np->vsi; 413 struct ice_pf *pf = vsi->back; 414 int ret = 0; 415 u32 i; 416 417 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE)) 418 return -EINVAL; 419 420 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags); 421 422 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS); 423 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { 424 const struct ice_priv_flag *priv_flag; 425 426 priv_flag = &ice_gstrings_priv_flags[i]; 427 428 if (flags & BIT(i)) 429 set_bit(priv_flag->bitno, pf->flags); 430 else 431 clear_bit(priv_flag->bitno, pf->flags); 432 } 433 434 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS); 435 436 if (test_bit(ICE_FLAG_DISABLE_FW_LLDP, change_flags)) { 437 if (test_bit(ICE_FLAG_DISABLE_FW_LLDP, pf->flags)) { 438 enum ice_status status; 439 440 status = ice_aq_cfg_lldp_mib_change(&pf->hw, false, 441 NULL); 442 /* If unregistering for LLDP events fails, this is 443 * not an error state, as there shouldn't be any 444 * events to respond to. 445 */ 446 if (status) 447 dev_info(&pf->pdev->dev, 448 "Failed to unreg for LLDP events\n"); 449 450 /* The AQ call to stop the FW LLDP agent will generate 451 * an error if the agent is already stopped. 452 */ 453 status = ice_aq_stop_lldp(&pf->hw, true, NULL); 454 if (status) 455 dev_warn(&pf->pdev->dev, 456 "Fail to stop LLDP agent\n"); 457 /* Use case for having the FW LLDP agent stopped 458 * will likely not need DCB, so failure to init is 459 * not a concern of ethtool 460 */ 461 status = ice_init_pf_dcb(pf); 462 if (status) 463 dev_warn(&pf->pdev->dev, "Fail to init DCB\n"); 464 } else { 465 enum ice_status status; 466 bool dcbx_agent_status; 467 468 /* AQ command to start FW LLDP agent will return an 469 * error if the agent is already started 470 */ 471 status = ice_aq_start_lldp(&pf->hw, NULL); 472 if (status) 473 dev_warn(&pf->pdev->dev, 474 "Fail to start LLDP Agent\n"); 475 476 /* AQ command to start FW DCBx agent will fail if 477 * the agent is already started 478 */ 479 status = ice_aq_start_stop_dcbx(&pf->hw, true, 480 &dcbx_agent_status, 481 NULL); 482 if (status) 483 dev_dbg(&pf->pdev->dev, 484 "Failed to start FW DCBX\n"); 485 486 dev_info(&pf->pdev->dev, "FW DCBX agent is %s\n", 487 dcbx_agent_status ? "ACTIVE" : "DISABLED"); 488 489 /* Failure to configure MIB change or init DCB is not 490 * relevant to ethtool. Print notification that 491 * registration/init failed but do not return error 492 * state to ethtool 493 */ 494 status = ice_aq_cfg_lldp_mib_change(&pf->hw, false, 495 NULL); 496 if (status) 497 dev_dbg(&pf->pdev->dev, 498 "Fail to reg for MIB change\n"); 499 500 status = ice_init_pf_dcb(pf); 501 if (status) 502 dev_dbg(&pf->pdev->dev, "Fail to init DCB\n"); 503 } 504 } 505 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags); 506 return ret; 507 } 508 509 static int ice_get_sset_count(struct net_device *netdev, int sset) 510 { 511 switch (sset) { 512 case ETH_SS_STATS: 513 /* The number (and order) of strings reported *must* remain 514 * constant for a given netdevice. This function must not 515 * report a different number based on run time parameters 516 * (such as the number of queues in use, or the setting of 517 * a private ethtool flag). This is due to the nature of the 518 * ethtool stats API. 519 * 520 * Userspace programs such as ethtool must make 3 separate 521 * ioctl requests, one for size, one for the strings, and 522 * finally one for the stats. Since these cross into 523 * userspace, changes to the number or size could result in 524 * undefined memory access or incorrect string<->value 525 * correlations for statistics. 526 * 527 * Even if it appears to be safe, changes to the size or 528 * order of strings will suffer from race conditions and are 529 * not safe. 530 */ 531 return ICE_ALL_STATS_LEN(netdev); 532 case ETH_SS_PRIV_FLAGS: 533 return ICE_PRIV_FLAG_ARRAY_SIZE; 534 default: 535 return -EOPNOTSUPP; 536 } 537 } 538 539 static void 540 ice_get_ethtool_stats(struct net_device *netdev, 541 struct ethtool_stats __always_unused *stats, u64 *data) 542 { 543 struct ice_netdev_priv *np = netdev_priv(netdev); 544 struct ice_vsi *vsi = np->vsi; 545 struct ice_pf *pf = vsi->back; 546 struct ice_ring *ring; 547 unsigned int j = 0; 548 int i = 0; 549 char *p; 550 551 for (j = 0; j < ICE_VSI_STATS_LEN; j++) { 552 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset; 553 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat == 554 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 555 } 556 557 /* populate per queue stats */ 558 rcu_read_lock(); 559 560 ice_for_each_alloc_txq(vsi, j) { 561 ring = READ_ONCE(vsi->tx_rings[j]); 562 if (ring) { 563 data[i++] = ring->stats.pkts; 564 data[i++] = ring->stats.bytes; 565 } else { 566 data[i++] = 0; 567 data[i++] = 0; 568 } 569 } 570 571 ice_for_each_alloc_rxq(vsi, j) { 572 ring = READ_ONCE(vsi->rx_rings[j]); 573 if (ring) { 574 data[i++] = ring->stats.pkts; 575 data[i++] = ring->stats.bytes; 576 } else { 577 data[i++] = 0; 578 data[i++] = 0; 579 } 580 } 581 582 rcu_read_unlock(); 583 584 if (vsi->type != ICE_VSI_PF) 585 return; 586 587 for (j = 0; j < ICE_PF_STATS_LEN; j++) { 588 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset; 589 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat == 590 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 591 } 592 593 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) { 594 data[i++] = pf->stats.priority_xon_tx[j]; 595 data[i++] = pf->stats.priority_xoff_tx[j]; 596 } 597 598 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) { 599 data[i++] = pf->stats.priority_xon_rx[j]; 600 data[i++] = pf->stats.priority_xoff_rx[j]; 601 } 602 } 603 604 /** 605 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes 606 * @netdev: network interface device structure 607 * @ks: ethtool link ksettings struct to fill out 608 */ 609 static void 610 ice_phy_type_to_ethtool(struct net_device *netdev, 611 struct ethtool_link_ksettings *ks) 612 { 613 struct ice_netdev_priv *np = netdev_priv(netdev); 614 struct ice_link_status *hw_link_info; 615 bool need_add_adv_mode = false; 616 struct ice_vsi *vsi = np->vsi; 617 u64 phy_types_high; 618 u64 phy_types_low; 619 620 hw_link_info = &vsi->port_info->phy.link_info; 621 phy_types_low = vsi->port_info->phy.phy_type_low; 622 phy_types_high = vsi->port_info->phy.phy_type_high; 623 624 ethtool_link_ksettings_zero_link_mode(ks, supported); 625 ethtool_link_ksettings_zero_link_mode(ks, advertising); 626 627 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX || 628 phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) { 629 ethtool_link_ksettings_add_link_mode(ks, supported, 630 100baseT_Full); 631 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB) 632 ethtool_link_ksettings_add_link_mode(ks, advertising, 633 100baseT_Full); 634 } 635 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T || 636 phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) { 637 ethtool_link_ksettings_add_link_mode(ks, supported, 638 1000baseT_Full); 639 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB) 640 ethtool_link_ksettings_add_link_mode(ks, advertising, 641 1000baseT_Full); 642 } 643 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) { 644 ethtool_link_ksettings_add_link_mode(ks, supported, 645 1000baseKX_Full); 646 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB) 647 ethtool_link_ksettings_add_link_mode(ks, advertising, 648 1000baseKX_Full); 649 } 650 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX || 651 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) { 652 ethtool_link_ksettings_add_link_mode(ks, supported, 653 1000baseX_Full); 654 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB) 655 ethtool_link_ksettings_add_link_mode(ks, advertising, 656 1000baseX_Full); 657 } 658 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) { 659 ethtool_link_ksettings_add_link_mode(ks, supported, 660 2500baseT_Full); 661 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB) 662 ethtool_link_ksettings_add_link_mode(ks, advertising, 663 2500baseT_Full); 664 } 665 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X || 666 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) { 667 ethtool_link_ksettings_add_link_mode(ks, supported, 668 2500baseX_Full); 669 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB) 670 ethtool_link_ksettings_add_link_mode(ks, advertising, 671 2500baseX_Full); 672 } 673 if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T || 674 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) { 675 ethtool_link_ksettings_add_link_mode(ks, supported, 676 5000baseT_Full); 677 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB) 678 ethtool_link_ksettings_add_link_mode(ks, advertising, 679 5000baseT_Full); 680 } 681 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T || 682 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA || 683 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC || 684 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) { 685 ethtool_link_ksettings_add_link_mode(ks, supported, 686 10000baseT_Full); 687 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB) 688 ethtool_link_ksettings_add_link_mode(ks, advertising, 689 10000baseT_Full); 690 } 691 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) { 692 ethtool_link_ksettings_add_link_mode(ks, supported, 693 10000baseKR_Full); 694 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB) 695 ethtool_link_ksettings_add_link_mode(ks, advertising, 696 10000baseKR_Full); 697 } 698 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) { 699 ethtool_link_ksettings_add_link_mode(ks, supported, 700 10000baseSR_Full); 701 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB) 702 ethtool_link_ksettings_add_link_mode(ks, advertising, 703 10000baseSR_Full); 704 } 705 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) { 706 ethtool_link_ksettings_add_link_mode(ks, supported, 707 10000baseLR_Full); 708 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB) 709 ethtool_link_ksettings_add_link_mode(ks, advertising, 710 10000baseLR_Full); 711 } 712 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T || 713 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR || 714 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S || 715 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 || 716 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC || 717 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) { 718 ethtool_link_ksettings_add_link_mode(ks, supported, 719 25000baseCR_Full); 720 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB) 721 ethtool_link_ksettings_add_link_mode(ks, advertising, 722 25000baseCR_Full); 723 } 724 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR || 725 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) { 726 ethtool_link_ksettings_add_link_mode(ks, supported, 727 25000baseSR_Full); 728 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB) 729 ethtool_link_ksettings_add_link_mode(ks, advertising, 730 25000baseSR_Full); 731 } 732 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR || 733 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S || 734 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) { 735 ethtool_link_ksettings_add_link_mode(ks, supported, 736 25000baseKR_Full); 737 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB) 738 ethtool_link_ksettings_add_link_mode(ks, advertising, 739 25000baseKR_Full); 740 } 741 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) { 742 ethtool_link_ksettings_add_link_mode(ks, supported, 743 40000baseKR4_Full); 744 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB) 745 ethtool_link_ksettings_add_link_mode(ks, advertising, 746 40000baseKR4_Full); 747 } 748 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 || 749 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC || 750 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) { 751 ethtool_link_ksettings_add_link_mode(ks, supported, 752 40000baseCR4_Full); 753 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB) 754 ethtool_link_ksettings_add_link_mode(ks, advertising, 755 40000baseCR4_Full); 756 } 757 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) { 758 ethtool_link_ksettings_add_link_mode(ks, supported, 759 40000baseSR4_Full); 760 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB) 761 ethtool_link_ksettings_add_link_mode(ks, advertising, 762 40000baseSR4_Full); 763 } 764 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) { 765 ethtool_link_ksettings_add_link_mode(ks, supported, 766 40000baseLR4_Full); 767 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB) 768 ethtool_link_ksettings_add_link_mode(ks, advertising, 769 40000baseLR4_Full); 770 } 771 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 || 772 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC || 773 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 || 774 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC || 775 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 || 776 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP || 777 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR || 778 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC || 779 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) { 780 ethtool_link_ksettings_add_link_mode(ks, supported, 781 50000baseCR2_Full); 782 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB) 783 ethtool_link_ksettings_add_link_mode(ks, advertising, 784 50000baseCR2_Full); 785 } 786 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 || 787 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) { 788 ethtool_link_ksettings_add_link_mode(ks, supported, 789 50000baseKR2_Full); 790 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB) 791 ethtool_link_ksettings_add_link_mode(ks, advertising, 792 50000baseKR2_Full); 793 } 794 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 || 795 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 || 796 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR || 797 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) { 798 ethtool_link_ksettings_add_link_mode(ks, supported, 799 50000baseSR2_Full); 800 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB) 801 ethtool_link_ksettings_add_link_mode(ks, advertising, 802 50000baseSR2_Full); 803 } 804 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 || 805 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC || 806 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 || 807 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC || 808 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 || 809 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 || 810 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2 || 811 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC || 812 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 || 813 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC || 814 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) { 815 ethtool_link_ksettings_add_link_mode(ks, supported, 816 100000baseCR4_Full); 817 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB) 818 need_add_adv_mode = true; 819 } 820 if (need_add_adv_mode) { 821 need_add_adv_mode = false; 822 ethtool_link_ksettings_add_link_mode(ks, advertising, 823 100000baseCR4_Full); 824 } 825 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 || 826 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) { 827 ethtool_link_ksettings_add_link_mode(ks, supported, 828 100000baseSR4_Full); 829 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB) 830 need_add_adv_mode = true; 831 } 832 if (need_add_adv_mode) { 833 need_add_adv_mode = false; 834 ethtool_link_ksettings_add_link_mode(ks, advertising, 835 100000baseSR4_Full); 836 } 837 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 || 838 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) { 839 ethtool_link_ksettings_add_link_mode(ks, supported, 840 100000baseLR4_ER4_Full); 841 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB) 842 need_add_adv_mode = true; 843 } 844 if (need_add_adv_mode) { 845 need_add_adv_mode = false; 846 ethtool_link_ksettings_add_link_mode(ks, advertising, 847 100000baseLR4_ER4_Full); 848 } 849 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 || 850 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 || 851 phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) { 852 ethtool_link_ksettings_add_link_mode(ks, supported, 853 100000baseKR4_Full); 854 if (hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB) 855 need_add_adv_mode = true; 856 } 857 if (need_add_adv_mode) 858 ethtool_link_ksettings_add_link_mode(ks, advertising, 859 100000baseKR4_Full); 860 861 /* Autoneg PHY types */ 862 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX || 863 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T || 864 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX || 865 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T || 866 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX || 867 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T || 868 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR || 869 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T || 870 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 || 871 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T || 872 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR || 873 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S || 874 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 || 875 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR || 876 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S || 877 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 || 878 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 || 879 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) { 880 ethtool_link_ksettings_add_link_mode(ks, supported, 881 Autoneg); 882 ethtool_link_ksettings_add_link_mode(ks, advertising, 883 Autoneg); 884 } 885 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 || 886 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 || 887 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP || 888 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) { 889 ethtool_link_ksettings_add_link_mode(ks, supported, 890 Autoneg); 891 ethtool_link_ksettings_add_link_mode(ks, advertising, 892 Autoneg); 893 } 894 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 || 895 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 || 896 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 || 897 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) { 898 ethtool_link_ksettings_add_link_mode(ks, supported, 899 Autoneg); 900 ethtool_link_ksettings_add_link_mode(ks, advertising, 901 Autoneg); 902 } 903 } 904 905 #define TEST_SET_BITS_TIMEOUT 50 906 #define TEST_SET_BITS_SLEEP_MAX 2000 907 #define TEST_SET_BITS_SLEEP_MIN 1000 908 909 /** 910 * ice_get_settings_link_up - Get Link settings for when link is up 911 * @ks: ethtool ksettings to fill in 912 * @netdev: network interface device structure 913 */ 914 static void 915 ice_get_settings_link_up(struct ethtool_link_ksettings *ks, 916 struct net_device *netdev) 917 { 918 struct ice_netdev_priv *np = netdev_priv(netdev); 919 struct ethtool_link_ksettings cap_ksettings; 920 struct ice_link_status *link_info; 921 struct ice_vsi *vsi = np->vsi; 922 bool unrecog_phy_high = false; 923 bool unrecog_phy_low = false; 924 925 link_info = &vsi->port_info->phy.link_info; 926 927 /* Initialize supported and advertised settings based on PHY settings */ 928 switch (link_info->phy_type_low) { 929 case ICE_PHY_TYPE_LOW_100BASE_TX: 930 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 931 ethtool_link_ksettings_add_link_mode(ks, supported, 932 100baseT_Full); 933 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 934 ethtool_link_ksettings_add_link_mode(ks, advertising, 935 100baseT_Full); 936 break; 937 case ICE_PHY_TYPE_LOW_100M_SGMII: 938 ethtool_link_ksettings_add_link_mode(ks, supported, 939 100baseT_Full); 940 break; 941 case ICE_PHY_TYPE_LOW_1000BASE_T: 942 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 943 ethtool_link_ksettings_add_link_mode(ks, supported, 944 1000baseT_Full); 945 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 946 ethtool_link_ksettings_add_link_mode(ks, advertising, 947 1000baseT_Full); 948 break; 949 case ICE_PHY_TYPE_LOW_1G_SGMII: 950 ethtool_link_ksettings_add_link_mode(ks, supported, 951 1000baseT_Full); 952 break; 953 case ICE_PHY_TYPE_LOW_1000BASE_SX: 954 case ICE_PHY_TYPE_LOW_1000BASE_LX: 955 ethtool_link_ksettings_add_link_mode(ks, supported, 956 1000baseX_Full); 957 break; 958 case ICE_PHY_TYPE_LOW_1000BASE_KX: 959 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 960 ethtool_link_ksettings_add_link_mode(ks, supported, 961 1000baseKX_Full); 962 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 963 ethtool_link_ksettings_add_link_mode(ks, advertising, 964 1000baseKX_Full); 965 break; 966 case ICE_PHY_TYPE_LOW_2500BASE_T: 967 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 968 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 969 ethtool_link_ksettings_add_link_mode(ks, supported, 970 2500baseT_Full); 971 ethtool_link_ksettings_add_link_mode(ks, advertising, 972 2500baseT_Full); 973 break; 974 case ICE_PHY_TYPE_LOW_2500BASE_X: 975 ethtool_link_ksettings_add_link_mode(ks, supported, 976 2500baseX_Full); 977 break; 978 case ICE_PHY_TYPE_LOW_2500BASE_KX: 979 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 980 ethtool_link_ksettings_add_link_mode(ks, supported, 981 2500baseX_Full); 982 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 983 ethtool_link_ksettings_add_link_mode(ks, advertising, 984 2500baseX_Full); 985 break; 986 case ICE_PHY_TYPE_LOW_5GBASE_T: 987 case ICE_PHY_TYPE_LOW_5GBASE_KR: 988 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 989 ethtool_link_ksettings_add_link_mode(ks, supported, 990 5000baseT_Full); 991 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 992 ethtool_link_ksettings_add_link_mode(ks, advertising, 993 5000baseT_Full); 994 break; 995 case ICE_PHY_TYPE_LOW_10GBASE_T: 996 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 997 ethtool_link_ksettings_add_link_mode(ks, supported, 998 10000baseT_Full); 999 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1000 ethtool_link_ksettings_add_link_mode(ks, advertising, 1001 10000baseT_Full); 1002 break; 1003 case ICE_PHY_TYPE_LOW_10G_SFI_DA: 1004 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC: 1005 case ICE_PHY_TYPE_LOW_10G_SFI_C2C: 1006 ethtool_link_ksettings_add_link_mode(ks, supported, 1007 10000baseT_Full); 1008 break; 1009 case ICE_PHY_TYPE_LOW_10GBASE_SR: 1010 ethtool_link_ksettings_add_link_mode(ks, supported, 1011 10000baseSR_Full); 1012 break; 1013 case ICE_PHY_TYPE_LOW_10GBASE_LR: 1014 ethtool_link_ksettings_add_link_mode(ks, supported, 1015 10000baseLR_Full); 1016 break; 1017 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1: 1018 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1019 ethtool_link_ksettings_add_link_mode(ks, supported, 1020 10000baseKR_Full); 1021 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1022 ethtool_link_ksettings_add_link_mode(ks, advertising, 1023 10000baseKR_Full); 1024 break; 1025 case ICE_PHY_TYPE_LOW_25GBASE_T: 1026 case ICE_PHY_TYPE_LOW_25GBASE_CR: 1027 case ICE_PHY_TYPE_LOW_25GBASE_CR_S: 1028 case ICE_PHY_TYPE_LOW_25GBASE_CR1: 1029 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1030 ethtool_link_ksettings_add_link_mode(ks, supported, 1031 25000baseCR_Full); 1032 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1033 ethtool_link_ksettings_add_link_mode(ks, advertising, 1034 25000baseCR_Full); 1035 break; 1036 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC: 1037 case ICE_PHY_TYPE_LOW_25G_AUI_C2C: 1038 ethtool_link_ksettings_add_link_mode(ks, supported, 1039 25000baseCR_Full); 1040 break; 1041 case ICE_PHY_TYPE_LOW_25GBASE_SR: 1042 case ICE_PHY_TYPE_LOW_25GBASE_LR: 1043 ethtool_link_ksettings_add_link_mode(ks, supported, 1044 25000baseSR_Full); 1045 break; 1046 case ICE_PHY_TYPE_LOW_25GBASE_KR: 1047 case ICE_PHY_TYPE_LOW_25GBASE_KR1: 1048 case ICE_PHY_TYPE_LOW_25GBASE_KR_S: 1049 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1050 ethtool_link_ksettings_add_link_mode(ks, supported, 1051 25000baseKR_Full); 1052 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1053 ethtool_link_ksettings_add_link_mode(ks, advertising, 1054 25000baseKR_Full); 1055 break; 1056 case ICE_PHY_TYPE_LOW_40GBASE_CR4: 1057 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1058 ethtool_link_ksettings_add_link_mode(ks, supported, 1059 40000baseCR4_Full); 1060 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1061 ethtool_link_ksettings_add_link_mode(ks, advertising, 1062 40000baseCR4_Full); 1063 break; 1064 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC: 1065 case ICE_PHY_TYPE_LOW_40G_XLAUI: 1066 ethtool_link_ksettings_add_link_mode(ks, supported, 1067 40000baseCR4_Full); 1068 break; 1069 case ICE_PHY_TYPE_LOW_40GBASE_SR4: 1070 ethtool_link_ksettings_add_link_mode(ks, supported, 1071 40000baseSR4_Full); 1072 break; 1073 case ICE_PHY_TYPE_LOW_40GBASE_LR4: 1074 ethtool_link_ksettings_add_link_mode(ks, supported, 1075 40000baseLR4_Full); 1076 break; 1077 case ICE_PHY_TYPE_LOW_40GBASE_KR4: 1078 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1079 ethtool_link_ksettings_add_link_mode(ks, supported, 1080 40000baseKR4_Full); 1081 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1082 ethtool_link_ksettings_add_link_mode(ks, advertising, 1083 40000baseKR4_Full); 1084 break; 1085 case ICE_PHY_TYPE_LOW_50GBASE_CR2: 1086 case ICE_PHY_TYPE_LOW_50GBASE_CP: 1087 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1088 ethtool_link_ksettings_add_link_mode(ks, supported, 1089 50000baseCR2_Full); 1090 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1091 ethtool_link_ksettings_add_link_mode(ks, advertising, 1092 50000baseCR2_Full); 1093 break; 1094 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC: 1095 case ICE_PHY_TYPE_LOW_50G_LAUI2: 1096 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC: 1097 case ICE_PHY_TYPE_LOW_50G_AUI2: 1098 case ICE_PHY_TYPE_LOW_50GBASE_SR: 1099 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC: 1100 case ICE_PHY_TYPE_LOW_50G_AUI1: 1101 ethtool_link_ksettings_add_link_mode(ks, supported, 1102 50000baseCR2_Full); 1103 break; 1104 case ICE_PHY_TYPE_LOW_50GBASE_KR2: 1105 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4: 1106 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1107 ethtool_link_ksettings_add_link_mode(ks, supported, 1108 50000baseKR2_Full); 1109 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1110 ethtool_link_ksettings_add_link_mode(ks, advertising, 1111 50000baseKR2_Full); 1112 break; 1113 case ICE_PHY_TYPE_LOW_50GBASE_SR2: 1114 case ICE_PHY_TYPE_LOW_50GBASE_LR2: 1115 case ICE_PHY_TYPE_LOW_50GBASE_FR: 1116 case ICE_PHY_TYPE_LOW_50GBASE_LR: 1117 ethtool_link_ksettings_add_link_mode(ks, supported, 1118 50000baseSR2_Full); 1119 break; 1120 case ICE_PHY_TYPE_LOW_100GBASE_CR4: 1121 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1122 ethtool_link_ksettings_add_link_mode(ks, supported, 1123 100000baseCR4_Full); 1124 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1125 ethtool_link_ksettings_add_link_mode(ks, advertising, 1126 100000baseCR4_Full); 1127 break; 1128 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC: 1129 case ICE_PHY_TYPE_LOW_100G_CAUI4: 1130 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC: 1131 case ICE_PHY_TYPE_LOW_100G_AUI4: 1132 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4: 1133 ethtool_link_ksettings_add_link_mode(ks, supported, 1134 100000baseCR4_Full); 1135 break; 1136 case ICE_PHY_TYPE_LOW_100GBASE_CP2: 1137 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1138 ethtool_link_ksettings_add_link_mode(ks, supported, 1139 100000baseCR4_Full); 1140 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1141 ethtool_link_ksettings_add_link_mode(ks, advertising, 1142 100000baseCR4_Full); 1143 break; 1144 case ICE_PHY_TYPE_LOW_100GBASE_SR4: 1145 case ICE_PHY_TYPE_LOW_100GBASE_SR2: 1146 ethtool_link_ksettings_add_link_mode(ks, supported, 1147 100000baseSR4_Full); 1148 break; 1149 case ICE_PHY_TYPE_LOW_100GBASE_LR4: 1150 case ICE_PHY_TYPE_LOW_100GBASE_DR: 1151 ethtool_link_ksettings_add_link_mode(ks, supported, 1152 100000baseLR4_ER4_Full); 1153 break; 1154 case ICE_PHY_TYPE_LOW_100GBASE_KR4: 1155 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4: 1156 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1157 ethtool_link_ksettings_add_link_mode(ks, supported, 1158 100000baseKR4_Full); 1159 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1160 ethtool_link_ksettings_add_link_mode(ks, advertising, 1161 100000baseKR4_Full); 1162 break; 1163 default: 1164 unrecog_phy_low = true; 1165 } 1166 1167 switch (link_info->phy_type_high) { 1168 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4: 1169 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1170 ethtool_link_ksettings_add_link_mode(ks, supported, 1171 100000baseKR4_Full); 1172 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1173 ethtool_link_ksettings_add_link_mode(ks, advertising, 1174 100000baseKR4_Full); 1175 break; 1176 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC: 1177 case ICE_PHY_TYPE_HIGH_100G_CAUI2: 1178 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC: 1179 case ICE_PHY_TYPE_HIGH_100G_AUI2: 1180 ethtool_link_ksettings_add_link_mode(ks, supported, 1181 100000baseCR4_Full); 1182 break; 1183 default: 1184 unrecog_phy_high = true; 1185 } 1186 1187 if (unrecog_phy_low && unrecog_phy_high) { 1188 /* if we got here and link is up something bad is afoot */ 1189 netdev_info(netdev, 1190 "WARNING: Unrecognized PHY_Low (0x%llx).\n", 1191 (u64)link_info->phy_type_low); 1192 netdev_info(netdev, 1193 "WARNING: Unrecognized PHY_High (0x%llx).\n", 1194 (u64)link_info->phy_type_high); 1195 } 1196 1197 /* Now that we've worked out everything that could be supported by the 1198 * current PHY type, get what is supported by the NVM and intersect 1199 * them to get what is truly supported 1200 */ 1201 memset(&cap_ksettings, 0, sizeof(cap_ksettings)); 1202 ice_phy_type_to_ethtool(netdev, &cap_ksettings); 1203 ethtool_intersect_link_masks(ks, &cap_ksettings); 1204 1205 switch (link_info->link_speed) { 1206 case ICE_AQ_LINK_SPEED_100GB: 1207 ks->base.speed = SPEED_100000; 1208 break; 1209 case ICE_AQ_LINK_SPEED_50GB: 1210 ks->base.speed = SPEED_50000; 1211 break; 1212 case ICE_AQ_LINK_SPEED_40GB: 1213 ks->base.speed = SPEED_40000; 1214 break; 1215 case ICE_AQ_LINK_SPEED_25GB: 1216 ks->base.speed = SPEED_25000; 1217 break; 1218 case ICE_AQ_LINK_SPEED_20GB: 1219 ks->base.speed = SPEED_20000; 1220 break; 1221 case ICE_AQ_LINK_SPEED_10GB: 1222 ks->base.speed = SPEED_10000; 1223 break; 1224 case ICE_AQ_LINK_SPEED_5GB: 1225 ks->base.speed = SPEED_5000; 1226 break; 1227 case ICE_AQ_LINK_SPEED_2500MB: 1228 ks->base.speed = SPEED_2500; 1229 break; 1230 case ICE_AQ_LINK_SPEED_1000MB: 1231 ks->base.speed = SPEED_1000; 1232 break; 1233 case ICE_AQ_LINK_SPEED_100MB: 1234 ks->base.speed = SPEED_100; 1235 break; 1236 default: 1237 netdev_info(netdev, 1238 "WARNING: Unrecognized link_speed (0x%x).\n", 1239 link_info->link_speed); 1240 break; 1241 } 1242 ks->base.duplex = DUPLEX_FULL; 1243 } 1244 1245 /** 1246 * ice_get_settings_link_down - Get the Link settings when link is down 1247 * @ks: ethtool ksettings to fill in 1248 * @netdev: network interface device structure 1249 * 1250 * Reports link settings that can be determined when link is down 1251 */ 1252 static void 1253 ice_get_settings_link_down(struct ethtool_link_ksettings *ks, 1254 struct net_device *netdev) 1255 { 1256 /* link is down and the driver needs to fall back on 1257 * supported PHY types to figure out what info to display 1258 */ 1259 ice_phy_type_to_ethtool(netdev, ks); 1260 1261 /* With no link, speed and duplex are unknown */ 1262 ks->base.speed = SPEED_UNKNOWN; 1263 ks->base.duplex = DUPLEX_UNKNOWN; 1264 } 1265 1266 /** 1267 * ice_get_link_ksettings - Get Link Speed and Duplex settings 1268 * @netdev: network interface device structure 1269 * @ks: ethtool ksettings 1270 * 1271 * Reports speed/duplex settings based on media_type 1272 */ 1273 static int 1274 ice_get_link_ksettings(struct net_device *netdev, 1275 struct ethtool_link_ksettings *ks) 1276 { 1277 struct ice_netdev_priv *np = netdev_priv(netdev); 1278 struct ice_link_status *hw_link_info; 1279 struct ice_vsi *vsi = np->vsi; 1280 1281 ethtool_link_ksettings_zero_link_mode(ks, supported); 1282 ethtool_link_ksettings_zero_link_mode(ks, advertising); 1283 hw_link_info = &vsi->port_info->phy.link_info; 1284 1285 /* set speed and duplex */ 1286 if (hw_link_info->link_info & ICE_AQ_LINK_UP) 1287 ice_get_settings_link_up(ks, netdev); 1288 else 1289 ice_get_settings_link_down(ks, netdev); 1290 1291 /* set autoneg settings */ 1292 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ? 1293 AUTONEG_ENABLE : AUTONEG_DISABLE; 1294 1295 /* set media type settings */ 1296 switch (vsi->port_info->phy.media_type) { 1297 case ICE_MEDIA_FIBER: 1298 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 1299 ks->base.port = PORT_FIBRE; 1300 break; 1301 case ICE_MEDIA_BASET: 1302 ethtool_link_ksettings_add_link_mode(ks, supported, TP); 1303 ethtool_link_ksettings_add_link_mode(ks, advertising, TP); 1304 ks->base.port = PORT_TP; 1305 break; 1306 case ICE_MEDIA_BACKPLANE: 1307 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 1308 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane); 1309 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 1310 ethtool_link_ksettings_add_link_mode(ks, advertising, 1311 Backplane); 1312 ks->base.port = PORT_NONE; 1313 break; 1314 case ICE_MEDIA_DA: 1315 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 1316 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE); 1317 ks->base.port = PORT_DA; 1318 break; 1319 default: 1320 ks->base.port = PORT_OTHER; 1321 break; 1322 } 1323 1324 /* flow control is symmetric and always supported */ 1325 ethtool_link_ksettings_add_link_mode(ks, supported, Pause); 1326 1327 switch (vsi->port_info->fc.req_mode) { 1328 case ICE_FC_FULL: 1329 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 1330 break; 1331 case ICE_FC_TX_PAUSE: 1332 ethtool_link_ksettings_add_link_mode(ks, advertising, 1333 Asym_Pause); 1334 break; 1335 case ICE_FC_RX_PAUSE: 1336 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 1337 ethtool_link_ksettings_add_link_mode(ks, advertising, 1338 Asym_Pause); 1339 break; 1340 case ICE_FC_PFC: 1341 default: 1342 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause); 1343 ethtool_link_ksettings_del_link_mode(ks, advertising, 1344 Asym_Pause); 1345 break; 1346 } 1347 1348 return 0; 1349 } 1350 1351 /** 1352 * ice_ksettings_find_adv_link_speed - Find advertising link speed 1353 * @ks: ethtool ksettings 1354 */ 1355 static u16 1356 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks) 1357 { 1358 u16 adv_link_speed = 0; 1359 1360 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1361 100baseT_Full)) 1362 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB; 1363 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1364 1000baseX_Full)) 1365 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB; 1366 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1367 1000baseT_Full) || 1368 ethtool_link_ksettings_test_link_mode(ks, advertising, 1369 1000baseKX_Full)) 1370 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB; 1371 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1372 2500baseT_Full)) 1373 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB; 1374 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1375 2500baseX_Full)) 1376 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB; 1377 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1378 5000baseT_Full)) 1379 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB; 1380 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1381 10000baseT_Full) || 1382 ethtool_link_ksettings_test_link_mode(ks, advertising, 1383 10000baseKR_Full)) 1384 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB; 1385 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1386 10000baseSR_Full) || 1387 ethtool_link_ksettings_test_link_mode(ks, advertising, 1388 10000baseLR_Full)) 1389 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB; 1390 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1391 25000baseCR_Full) || 1392 ethtool_link_ksettings_test_link_mode(ks, advertising, 1393 25000baseSR_Full) || 1394 ethtool_link_ksettings_test_link_mode(ks, advertising, 1395 25000baseKR_Full)) 1396 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB; 1397 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1398 40000baseCR4_Full) || 1399 ethtool_link_ksettings_test_link_mode(ks, advertising, 1400 40000baseSR4_Full) || 1401 ethtool_link_ksettings_test_link_mode(ks, advertising, 1402 40000baseLR4_Full) || 1403 ethtool_link_ksettings_test_link_mode(ks, advertising, 1404 40000baseKR4_Full)) 1405 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB; 1406 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1407 50000baseCR2_Full) || 1408 ethtool_link_ksettings_test_link_mode(ks, advertising, 1409 50000baseKR2_Full)) 1410 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB; 1411 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1412 50000baseSR2_Full)) 1413 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB; 1414 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 1415 100000baseCR4_Full) || 1416 ethtool_link_ksettings_test_link_mode(ks, advertising, 1417 100000baseSR4_Full) || 1418 ethtool_link_ksettings_test_link_mode(ks, advertising, 1419 100000baseLR4_ER4_Full) || 1420 ethtool_link_ksettings_test_link_mode(ks, advertising, 1421 100000baseKR4_Full)) 1422 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB; 1423 1424 return adv_link_speed; 1425 } 1426 1427 /** 1428 * ice_setup_autoneg 1429 * @p: port info 1430 * @ks: ethtool_link_ksettings 1431 * @config: configuration that will be sent down to FW 1432 * @autoneg_enabled: autonegotiation is enabled or not 1433 * @autoneg_changed: will there a change in autonegotiation 1434 * @netdev: network interface device structure 1435 * 1436 * Setup PHY autonegotiation feature 1437 */ 1438 static int 1439 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks, 1440 struct ice_aqc_set_phy_cfg_data *config, 1441 u8 autoneg_enabled, u8 *autoneg_changed, 1442 struct net_device *netdev) 1443 { 1444 int err = 0; 1445 1446 *autoneg_changed = 0; 1447 1448 /* Check autoneg */ 1449 if (autoneg_enabled == AUTONEG_ENABLE) { 1450 /* If autoneg was not already enabled */ 1451 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) { 1452 /* If autoneg is not supported, return error */ 1453 if (!ethtool_link_ksettings_test_link_mode(ks, 1454 supported, 1455 Autoneg)) { 1456 netdev_info(netdev, "Autoneg not supported on this phy.\n"); 1457 err = -EINVAL; 1458 } else { 1459 /* Autoneg is allowed to change */ 1460 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 1461 *autoneg_changed = 1; 1462 } 1463 } 1464 } else { 1465 /* If autoneg is currently enabled */ 1466 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) { 1467 /* If autoneg is supported 10GBASE_T is the only PHY 1468 * that can disable it, so otherwise return error 1469 */ 1470 if (ethtool_link_ksettings_test_link_mode(ks, 1471 supported, 1472 Autoneg)) { 1473 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); 1474 err = -EINVAL; 1475 } else { 1476 /* Autoneg is allowed to change */ 1477 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 1478 *autoneg_changed = 1; 1479 } 1480 } 1481 } 1482 1483 return err; 1484 } 1485 1486 /** 1487 * ice_set_link_ksettings - Set Speed and Duplex 1488 * @netdev: network interface device structure 1489 * @ks: ethtool ksettings 1490 * 1491 * Set speed/duplex per media_types advertised/forced 1492 */ 1493 static int 1494 ice_set_link_ksettings(struct net_device *netdev, 1495 const struct ethtool_link_ksettings *ks) 1496 { 1497 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0; 1498 struct ice_netdev_priv *np = netdev_priv(netdev); 1499 struct ethtool_link_ksettings safe_ks, copy_ks; 1500 struct ice_aqc_get_phy_caps_data *abilities; 1501 u16 adv_link_speed, curr_link_speed, idx; 1502 struct ice_aqc_set_phy_cfg_data config; 1503 struct ice_pf *pf = np->vsi->back; 1504 struct ice_port_info *p; 1505 u8 autoneg_changed = 0; 1506 enum ice_status status; 1507 u64 phy_type_high; 1508 u64 phy_type_low; 1509 int err = 0; 1510 bool linkup; 1511 1512 p = np->vsi->port_info; 1513 1514 if (!p) 1515 return -EOPNOTSUPP; 1516 1517 /* Check if this is LAN VSI */ 1518 ice_for_each_vsi(pf, idx) 1519 if (pf->vsi[idx]->type == ICE_VSI_PF) { 1520 if (np->vsi != pf->vsi[idx]) 1521 return -EOPNOTSUPP; 1522 break; 1523 } 1524 1525 if (p->phy.media_type != ICE_MEDIA_BASET && 1526 p->phy.media_type != ICE_MEDIA_FIBER && 1527 p->phy.media_type != ICE_MEDIA_BACKPLANE && 1528 p->phy.media_type != ICE_MEDIA_DA && 1529 p->phy.link_info.link_info & ICE_AQ_LINK_UP) 1530 return -EOPNOTSUPP; 1531 1532 /* copy the ksettings to copy_ks to avoid modifying the original */ 1533 memcpy(©_ks, ks, sizeof(copy_ks)); 1534 1535 /* save autoneg out of ksettings */ 1536 autoneg = copy_ks.base.autoneg; 1537 1538 memset(&safe_ks, 0, sizeof(safe_ks)); 1539 1540 /* Get link modes supported by hardware.*/ 1541 ice_phy_type_to_ethtool(netdev, &safe_ks); 1542 1543 /* and check against modes requested by user. 1544 * Return an error if unsupported mode was set. 1545 */ 1546 if (!bitmap_subset(copy_ks.link_modes.advertising, 1547 safe_ks.link_modes.supported, 1548 __ETHTOOL_LINK_MODE_MASK_NBITS)) 1549 return -EINVAL; 1550 1551 /* get our own copy of the bits to check against */ 1552 memset(&safe_ks, 0, sizeof(safe_ks)); 1553 safe_ks.base.cmd = copy_ks.base.cmd; 1554 safe_ks.base.link_mode_masks_nwords = 1555 copy_ks.base.link_mode_masks_nwords; 1556 ice_get_link_ksettings(netdev, &safe_ks); 1557 1558 /* set autoneg back to what it currently is */ 1559 copy_ks.base.autoneg = safe_ks.base.autoneg; 1560 /* we don't compare the speed */ 1561 copy_ks.base.speed = safe_ks.base.speed; 1562 1563 /* If copy_ks.base and safe_ks.base are not the same now, then they are 1564 * trying to set something that we do not support. 1565 */ 1566 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) 1567 return -EOPNOTSUPP; 1568 1569 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) { 1570 timeout--; 1571 if (!timeout) 1572 return -EBUSY; 1573 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX); 1574 } 1575 1576 abilities = devm_kzalloc(&pf->pdev->dev, sizeof(*abilities), 1577 GFP_KERNEL); 1578 if (!abilities) 1579 return -ENOMEM; 1580 1581 /* Get the current PHY config */ 1582 status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities, 1583 NULL); 1584 if (status) { 1585 err = -EAGAIN; 1586 goto done; 1587 } 1588 1589 /* Copy abilities to config in case autoneg is not set below */ 1590 memset(&config, 0, sizeof(config)); 1591 config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE; 1592 if (abilities->caps & ICE_AQC_PHY_AN_MODE) 1593 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 1594 1595 /* Check autoneg */ 1596 err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed, 1597 netdev); 1598 1599 if (err) 1600 goto done; 1601 1602 /* Call to get the current link speed */ 1603 p->phy.get_link_info = true; 1604 status = ice_get_link_status(p, &linkup); 1605 if (status) { 1606 err = -EAGAIN; 1607 goto done; 1608 } 1609 1610 curr_link_speed = p->phy.link_info.link_speed; 1611 adv_link_speed = ice_ksettings_find_adv_link_speed(ks); 1612 1613 /* If speed didn't get set, set it to what it currently is. 1614 * This is needed because if advertise is 0 (as it is when autoneg 1615 * is disabled) then speed won't get set. 1616 */ 1617 if (!adv_link_speed) 1618 adv_link_speed = curr_link_speed; 1619 1620 /* Convert the advertise link speeds to their corresponded PHY_TYPE */ 1621 ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed); 1622 1623 if (!autoneg_changed && adv_link_speed == curr_link_speed) { 1624 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); 1625 goto done; 1626 } 1627 1628 /* copy over the rest of the abilities */ 1629 config.low_power_ctrl = abilities->low_power_ctrl; 1630 config.eee_cap = abilities->eee_cap; 1631 config.eeer_value = abilities->eeer_value; 1632 config.link_fec_opt = abilities->link_fec_options; 1633 1634 /* save the requested speeds */ 1635 p->phy.link_info.req_speeds = adv_link_speed; 1636 1637 /* set link and auto negotiation so changes take effect */ 1638 config.caps |= ICE_AQ_PHY_ENA_LINK; 1639 1640 if (phy_type_low || phy_type_high) { 1641 config.phy_type_high = cpu_to_le64(phy_type_high) & 1642 abilities->phy_type_high; 1643 config.phy_type_low = cpu_to_le64(phy_type_low) & 1644 abilities->phy_type_low; 1645 } else { 1646 err = -EAGAIN; 1647 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n"); 1648 goto done; 1649 } 1650 1651 /* If link is up put link down */ 1652 if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) { 1653 /* Tell the OS link is going down, the link will go 1654 * back up when fw says it is ready asynchronously 1655 */ 1656 ice_print_link_msg(np->vsi, false); 1657 netif_carrier_off(netdev); 1658 netif_tx_stop_all_queues(netdev); 1659 } 1660 1661 /* make the aq call */ 1662 status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL); 1663 if (status) { 1664 netdev_info(netdev, "Set phy config failed,\n"); 1665 err = -EAGAIN; 1666 } 1667 1668 done: 1669 devm_kfree(&pf->pdev->dev, abilities); 1670 clear_bit(__ICE_CFG_BUSY, pf->state); 1671 1672 return err; 1673 } 1674 1675 /** 1676 * ice_get_rxnfc - command to get Rx flow classification rules 1677 * @netdev: network interface device structure 1678 * @cmd: ethtool rxnfc command 1679 * @rule_locs: buffer to rturn Rx flow classification rules 1680 * 1681 * Returns Success if the command is supported. 1682 */ 1683 static int 1684 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, 1685 u32 __always_unused *rule_locs) 1686 { 1687 struct ice_netdev_priv *np = netdev_priv(netdev); 1688 struct ice_vsi *vsi = np->vsi; 1689 int ret = -EOPNOTSUPP; 1690 1691 switch (cmd->cmd) { 1692 case ETHTOOL_GRXRINGS: 1693 cmd->data = vsi->rss_size; 1694 ret = 0; 1695 break; 1696 default: 1697 break; 1698 } 1699 1700 return ret; 1701 } 1702 1703 static void 1704 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) 1705 { 1706 struct ice_netdev_priv *np = netdev_priv(netdev); 1707 struct ice_vsi *vsi = np->vsi; 1708 1709 ring->rx_max_pending = ICE_MAX_NUM_DESC; 1710 ring->tx_max_pending = ICE_MAX_NUM_DESC; 1711 ring->rx_pending = vsi->rx_rings[0]->count; 1712 ring->tx_pending = vsi->tx_rings[0]->count; 1713 1714 /* Rx mini and jumbo rings are not supported */ 1715 ring->rx_mini_max_pending = 0; 1716 ring->rx_jumbo_max_pending = 0; 1717 ring->rx_mini_pending = 0; 1718 ring->rx_jumbo_pending = 0; 1719 } 1720 1721 static int 1722 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) 1723 { 1724 struct ice_ring *tx_rings = NULL, *rx_rings = NULL; 1725 struct ice_netdev_priv *np = netdev_priv(netdev); 1726 struct ice_vsi *vsi = np->vsi; 1727 struct ice_pf *pf = vsi->back; 1728 int i, timeout = 50, err = 0; 1729 u32 new_rx_cnt, new_tx_cnt; 1730 1731 if (ring->tx_pending > ICE_MAX_NUM_DESC || 1732 ring->tx_pending < ICE_MIN_NUM_DESC || 1733 ring->rx_pending > ICE_MAX_NUM_DESC || 1734 ring->rx_pending < ICE_MIN_NUM_DESC) { 1735 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n", 1736 ring->tx_pending, ring->rx_pending, 1737 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC, 1738 ICE_REQ_DESC_MULTIPLE); 1739 return -EINVAL; 1740 } 1741 1742 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE); 1743 if (new_tx_cnt != ring->tx_pending) 1744 netdev_info(netdev, 1745 "Requested Tx descriptor count rounded up to %d\n", 1746 new_tx_cnt); 1747 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE); 1748 if (new_rx_cnt != ring->rx_pending) 1749 netdev_info(netdev, 1750 "Requested Rx descriptor count rounded up to %d\n", 1751 new_rx_cnt); 1752 1753 /* if nothing to do return success */ 1754 if (new_tx_cnt == vsi->tx_rings[0]->count && 1755 new_rx_cnt == vsi->rx_rings[0]->count) { 1756 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n"); 1757 return 0; 1758 } 1759 1760 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) { 1761 timeout--; 1762 if (!timeout) 1763 return -EBUSY; 1764 usleep_range(1000, 2000); 1765 } 1766 1767 /* set for the next time the netdev is started */ 1768 if (!netif_running(vsi->netdev)) { 1769 for (i = 0; i < vsi->alloc_txq; i++) 1770 vsi->tx_rings[i]->count = new_tx_cnt; 1771 for (i = 0; i < vsi->alloc_rxq; i++) 1772 vsi->rx_rings[i]->count = new_rx_cnt; 1773 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n"); 1774 goto done; 1775 } 1776 1777 if (new_tx_cnt == vsi->tx_rings[0]->count) 1778 goto process_rx; 1779 1780 /* alloc updated Tx resources */ 1781 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n", 1782 vsi->tx_rings[0]->count, new_tx_cnt); 1783 1784 tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq, 1785 sizeof(*tx_rings), GFP_KERNEL); 1786 if (!tx_rings) { 1787 err = -ENOMEM; 1788 goto done; 1789 } 1790 1791 for (i = 0; i < vsi->alloc_txq; i++) { 1792 /* clone ring and setup updated count */ 1793 tx_rings[i] = *vsi->tx_rings[i]; 1794 tx_rings[i].count = new_tx_cnt; 1795 tx_rings[i].desc = NULL; 1796 tx_rings[i].tx_buf = NULL; 1797 err = ice_setup_tx_ring(&tx_rings[i]); 1798 if (err) { 1799 while (i) { 1800 i--; 1801 ice_clean_tx_ring(&tx_rings[i]); 1802 } 1803 devm_kfree(&pf->pdev->dev, tx_rings); 1804 goto done; 1805 } 1806 } 1807 1808 process_rx: 1809 if (new_rx_cnt == vsi->rx_rings[0]->count) 1810 goto process_link; 1811 1812 /* alloc updated Rx resources */ 1813 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n", 1814 vsi->rx_rings[0]->count, new_rx_cnt); 1815 1816 rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq, 1817 sizeof(*rx_rings), GFP_KERNEL); 1818 if (!rx_rings) { 1819 err = -ENOMEM; 1820 goto done; 1821 } 1822 1823 for (i = 0; i < vsi->alloc_rxq; i++) { 1824 /* clone ring and setup updated count */ 1825 rx_rings[i] = *vsi->rx_rings[i]; 1826 rx_rings[i].count = new_rx_cnt; 1827 rx_rings[i].desc = NULL; 1828 rx_rings[i].rx_buf = NULL; 1829 /* this is to allow wr32 to have something to write to 1830 * during early allocation of Rx buffers 1831 */ 1832 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS; 1833 1834 err = ice_setup_rx_ring(&rx_rings[i]); 1835 if (err) 1836 goto rx_unwind; 1837 1838 /* allocate Rx buffers */ 1839 err = ice_alloc_rx_bufs(&rx_rings[i], 1840 ICE_DESC_UNUSED(&rx_rings[i])); 1841 rx_unwind: 1842 if (err) { 1843 while (i) { 1844 i--; 1845 ice_free_rx_ring(&rx_rings[i]); 1846 } 1847 devm_kfree(&pf->pdev->dev, rx_rings); 1848 err = -ENOMEM; 1849 goto free_tx; 1850 } 1851 } 1852 1853 process_link: 1854 /* Bring interface down, copy in the new ring info, then restore the 1855 * interface. if VSI is up, bring it down and then back up 1856 */ 1857 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) { 1858 ice_down(vsi); 1859 1860 if (tx_rings) { 1861 for (i = 0; i < vsi->alloc_txq; i++) { 1862 ice_free_tx_ring(vsi->tx_rings[i]); 1863 *vsi->tx_rings[i] = tx_rings[i]; 1864 } 1865 devm_kfree(&pf->pdev->dev, tx_rings); 1866 } 1867 1868 if (rx_rings) { 1869 for (i = 0; i < vsi->alloc_rxq; i++) { 1870 ice_free_rx_ring(vsi->rx_rings[i]); 1871 /* copy the real tail offset */ 1872 rx_rings[i].tail = vsi->rx_rings[i]->tail; 1873 /* this is to fake out the allocation routine 1874 * into thinking it has to realloc everything 1875 * but the recycling logic will let us re-use 1876 * the buffers allocated above 1877 */ 1878 rx_rings[i].next_to_use = 0; 1879 rx_rings[i].next_to_clean = 0; 1880 rx_rings[i].next_to_alloc = 0; 1881 *vsi->rx_rings[i] = rx_rings[i]; 1882 } 1883 devm_kfree(&pf->pdev->dev, rx_rings); 1884 } 1885 1886 ice_up(vsi); 1887 } 1888 goto done; 1889 1890 free_tx: 1891 /* error cleanup if the Rx allocations failed after getting Tx */ 1892 if (tx_rings) { 1893 for (i = 0; i < vsi->alloc_txq; i++) 1894 ice_free_tx_ring(&tx_rings[i]); 1895 devm_kfree(&pf->pdev->dev, tx_rings); 1896 } 1897 1898 done: 1899 clear_bit(__ICE_CFG_BUSY, pf->state); 1900 return err; 1901 } 1902 1903 static int ice_nway_reset(struct net_device *netdev) 1904 { 1905 /* restart autonegotiation */ 1906 struct ice_netdev_priv *np = netdev_priv(netdev); 1907 struct ice_vsi *vsi = np->vsi; 1908 struct ice_port_info *pi; 1909 enum ice_status status; 1910 1911 pi = vsi->port_info; 1912 /* If VSI state is up, then restart autoneg with link up */ 1913 if (!test_bit(__ICE_DOWN, vsi->back->state)) 1914 status = ice_aq_set_link_restart_an(pi, true, NULL); 1915 else 1916 status = ice_aq_set_link_restart_an(pi, false, NULL); 1917 1918 if (status) { 1919 netdev_info(netdev, "link restart failed, err %d aq_err %d\n", 1920 status, pi->hw->adminq.sq_last_status); 1921 return -EIO; 1922 } 1923 1924 return 0; 1925 } 1926 1927 /** 1928 * ice_get_pauseparam - Get Flow Control status 1929 * @netdev: network interface device structure 1930 * @pause: ethernet pause (flow control) parameters 1931 */ 1932 static void 1933 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) 1934 { 1935 struct ice_netdev_priv *np = netdev_priv(netdev); 1936 struct ice_port_info *pi = np->vsi->port_info; 1937 struct ice_aqc_get_phy_caps_data *pcaps; 1938 struct ice_vsi *vsi = np->vsi; 1939 struct ice_dcbx_cfg *dcbx_cfg; 1940 enum ice_status status; 1941 1942 /* Initialize pause params */ 1943 pause->rx_pause = 0; 1944 pause->tx_pause = 0; 1945 1946 dcbx_cfg = &pi->local_dcbx_cfg; 1947 1948 pcaps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*pcaps), 1949 GFP_KERNEL); 1950 if (!pcaps) 1951 return; 1952 1953 /* Get current PHY config */ 1954 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps, 1955 NULL); 1956 if (status) 1957 goto out; 1958 1959 pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ? 1960 AUTONEG_ENABLE : AUTONEG_DISABLE); 1961 1962 if (dcbx_cfg->pfc.pfcena) 1963 /* PFC enabled so report LFC as off */ 1964 goto out; 1965 1966 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) 1967 pause->tx_pause = 1; 1968 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) 1969 pause->rx_pause = 1; 1970 1971 out: 1972 devm_kfree(&vsi->back->pdev->dev, pcaps); 1973 } 1974 1975 /** 1976 * ice_set_pauseparam - Set Flow Control parameter 1977 * @netdev: network interface device structure 1978 * @pause: return Tx/Rx flow control status 1979 */ 1980 static int 1981 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) 1982 { 1983 struct ice_netdev_priv *np = netdev_priv(netdev); 1984 struct ice_link_status *hw_link_info; 1985 struct ice_pf *pf = np->vsi->back; 1986 struct ice_dcbx_cfg *dcbx_cfg; 1987 struct ice_vsi *vsi = np->vsi; 1988 struct ice_hw *hw = &pf->hw; 1989 struct ice_port_info *pi; 1990 enum ice_status status; 1991 u8 aq_failures; 1992 bool link_up; 1993 int err = 0; 1994 1995 pi = vsi->port_info; 1996 hw_link_info = &pi->phy.link_info; 1997 dcbx_cfg = &pi->local_dcbx_cfg; 1998 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP; 1999 2000 /* Changing the port's flow control is not supported if this isn't the 2001 * PF VSI 2002 */ 2003 if (vsi->type != ICE_VSI_PF) { 2004 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n"); 2005 return -EOPNOTSUPP; 2006 } 2007 2008 if (pause->autoneg != (hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) { 2009 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); 2010 return -EOPNOTSUPP; 2011 } 2012 2013 /* If we have link and don't have autoneg */ 2014 if (!test_bit(__ICE_DOWN, pf->state) && 2015 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) { 2016 /* Send message that it might not necessarily work*/ 2017 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); 2018 } 2019 2020 if (dcbx_cfg->pfc.pfcena) { 2021 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n"); 2022 return -EOPNOTSUPP; 2023 } 2024 if (pause->rx_pause && pause->tx_pause) 2025 pi->fc.req_mode = ICE_FC_FULL; 2026 else if (pause->rx_pause && !pause->tx_pause) 2027 pi->fc.req_mode = ICE_FC_RX_PAUSE; 2028 else if (!pause->rx_pause && pause->tx_pause) 2029 pi->fc.req_mode = ICE_FC_TX_PAUSE; 2030 else if (!pause->rx_pause && !pause->tx_pause) 2031 pi->fc.req_mode = ICE_FC_NONE; 2032 else 2033 return -EINVAL; 2034 2035 /* Tell the OS link is going down, the link will go back up when fw 2036 * says it is ready asynchronously 2037 */ 2038 ice_print_link_msg(vsi, false); 2039 netif_carrier_off(netdev); 2040 netif_tx_stop_all_queues(netdev); 2041 2042 /* Set the FC mode and only restart AN if link is up */ 2043 status = ice_set_fc(pi, &aq_failures, link_up); 2044 2045 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) { 2046 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n", 2047 status, hw->adminq.sq_last_status); 2048 err = -EAGAIN; 2049 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) { 2050 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n", 2051 status, hw->adminq.sq_last_status); 2052 err = -EAGAIN; 2053 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) { 2054 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n", 2055 status, hw->adminq.sq_last_status); 2056 err = -EAGAIN; 2057 } 2058 2059 if (!test_bit(__ICE_DOWN, pf->state)) { 2060 /* Give it a little more time to try to come back. If still 2061 * down, restart autoneg link or reinitialize the interface. 2062 */ 2063 msleep(75); 2064 if (!test_bit(__ICE_DOWN, pf->state)) 2065 return ice_nway_reset(netdev); 2066 2067 ice_down(vsi); 2068 ice_up(vsi); 2069 } 2070 2071 return err; 2072 } 2073 2074 /** 2075 * ice_get_rxfh_key_size - get the RSS hash key size 2076 * @netdev: network interface device structure 2077 * 2078 * Returns the table size. 2079 */ 2080 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev) 2081 { 2082 return ICE_VSIQF_HKEY_ARRAY_SIZE; 2083 } 2084 2085 /** 2086 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size 2087 * @netdev: network interface device structure 2088 * 2089 * Returns the table size. 2090 */ 2091 static u32 ice_get_rxfh_indir_size(struct net_device *netdev) 2092 { 2093 struct ice_netdev_priv *np = netdev_priv(netdev); 2094 2095 return np->vsi->rss_table_size; 2096 } 2097 2098 /** 2099 * ice_get_rxfh - get the Rx flow hash indirection table 2100 * @netdev: network interface device structure 2101 * @indir: indirection table 2102 * @key: hash key 2103 * @hfunc: hash function 2104 * 2105 * Reads the indirection table directly from the hardware. 2106 */ 2107 static int 2108 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc) 2109 { 2110 struct ice_netdev_priv *np = netdev_priv(netdev); 2111 struct ice_vsi *vsi = np->vsi; 2112 struct ice_pf *pf = vsi->back; 2113 int ret = 0, i; 2114 u8 *lut; 2115 2116 if (hfunc) 2117 *hfunc = ETH_RSS_HASH_TOP; 2118 2119 if (!indir) 2120 return 0; 2121 2122 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { 2123 /* RSS not supported return error here */ 2124 netdev_warn(netdev, "RSS is not configured on this VSI!\n"); 2125 return -EIO; 2126 } 2127 2128 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL); 2129 if (!lut) 2130 return -ENOMEM; 2131 2132 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) { 2133 ret = -EIO; 2134 goto out; 2135 } 2136 2137 for (i = 0; i < vsi->rss_table_size; i++) 2138 indir[i] = (u32)(lut[i]); 2139 2140 out: 2141 devm_kfree(&pf->pdev->dev, lut); 2142 return ret; 2143 } 2144 2145 /** 2146 * ice_set_rxfh - set the Rx flow hash indirection table 2147 * @netdev: network interface device structure 2148 * @indir: indirection table 2149 * @key: hash key 2150 * @hfunc: hash function 2151 * 2152 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise 2153 * returns 0 after programming the table. 2154 */ 2155 static int 2156 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key, 2157 const u8 hfunc) 2158 { 2159 struct ice_netdev_priv *np = netdev_priv(netdev); 2160 struct ice_vsi *vsi = np->vsi; 2161 struct ice_pf *pf = vsi->back; 2162 u8 *seed = NULL; 2163 2164 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 2165 return -EOPNOTSUPP; 2166 2167 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { 2168 /* RSS not supported return error here */ 2169 netdev_warn(netdev, "RSS is not configured on this VSI!\n"); 2170 return -EIO; 2171 } 2172 2173 if (key) { 2174 if (!vsi->rss_hkey_user) { 2175 vsi->rss_hkey_user = 2176 devm_kzalloc(&pf->pdev->dev, 2177 ICE_VSIQF_HKEY_ARRAY_SIZE, 2178 GFP_KERNEL); 2179 if (!vsi->rss_hkey_user) 2180 return -ENOMEM; 2181 } 2182 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE); 2183 seed = vsi->rss_hkey_user; 2184 } 2185 2186 if (!vsi->rss_lut_user) { 2187 vsi->rss_lut_user = devm_kzalloc(&pf->pdev->dev, 2188 vsi->rss_table_size, 2189 GFP_KERNEL); 2190 if (!vsi->rss_lut_user) 2191 return -ENOMEM; 2192 } 2193 2194 /* Each 32 bits pointed by 'indir' is stored with a lut entry */ 2195 if (indir) { 2196 int i; 2197 2198 for (i = 0; i < vsi->rss_table_size; i++) 2199 vsi->rss_lut_user[i] = (u8)(indir[i]); 2200 } else { 2201 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size, 2202 vsi->rss_size); 2203 } 2204 2205 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size)) 2206 return -EIO; 2207 2208 return 0; 2209 } 2210 2211 enum ice_container_type { 2212 ICE_RX_CONTAINER, 2213 ICE_TX_CONTAINER, 2214 }; 2215 2216 /** 2217 * ice_get_rc_coalesce - get ITR values for specific ring container 2218 * @ec: ethtool structure to fill with driver's coalesce settings 2219 * @c_type: container type, Rx or Tx 2220 * @rc: ring container that the ITR values will come from 2221 * 2222 * Query the device for ice_ring_container specific ITR values. This is 2223 * done per ice_ring_container because each q_vector can have 1 or more rings 2224 * and all of said ring(s) will have the same ITR values. 2225 * 2226 * Returns 0 on success, negative otherwise. 2227 */ 2228 static int 2229 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type, 2230 struct ice_ring_container *rc) 2231 { 2232 struct ice_pf *pf; 2233 2234 if (!rc->ring) 2235 return -EINVAL; 2236 2237 pf = rc->ring->vsi->back; 2238 2239 switch (c_type) { 2240 case ICE_RX_CONTAINER: 2241 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting); 2242 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC; 2243 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl; 2244 break; 2245 case ICE_TX_CONTAINER: 2246 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting); 2247 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC; 2248 break; 2249 default: 2250 dev_dbg(&pf->pdev->dev, "Invalid c_type %d\n", c_type); 2251 return -EINVAL; 2252 } 2253 2254 return 0; 2255 } 2256 2257 /** 2258 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings 2259 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings 2260 * @ec: coalesce settings to program the device with 2261 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index 2262 * 2263 * Return 0 on success, and negative under the following conditions: 2264 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed. 2265 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings. 2266 */ 2267 static int 2268 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num) 2269 { 2270 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) { 2271 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER, 2272 &vsi->rx_rings[q_num]->q_vector->rx)) 2273 return -EINVAL; 2274 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER, 2275 &vsi->tx_rings[q_num]->q_vector->tx)) 2276 return -EINVAL; 2277 } else if (q_num < vsi->num_rxq) { 2278 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER, 2279 &vsi->rx_rings[q_num]->q_vector->rx)) 2280 return -EINVAL; 2281 } else if (q_num < vsi->num_txq) { 2282 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER, 2283 &vsi->tx_rings[q_num]->q_vector->tx)) 2284 return -EINVAL; 2285 } else { 2286 return -EINVAL; 2287 } 2288 2289 return 0; 2290 } 2291 2292 /** 2293 * __ice_get_coalesce - get ITR/INTRL values for the device 2294 * @netdev: pointer to the netdev associated with this query 2295 * @ec: ethtool structure to fill with driver's coalesce settings 2296 * @q_num: queue number to get the coalesce settings for 2297 * 2298 * If the caller passes in a negative q_num then we return coalesce settings 2299 * based on queue number 0, else use the actual q_num passed in. 2300 */ 2301 static int 2302 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, 2303 int q_num) 2304 { 2305 struct ice_netdev_priv *np = netdev_priv(netdev); 2306 struct ice_vsi *vsi = np->vsi; 2307 2308 if (q_num < 0) 2309 q_num = 0; 2310 2311 if (ice_get_q_coalesce(vsi, ec, q_num)) 2312 return -EINVAL; 2313 2314 if (q_num < vsi->num_txq) 2315 ec->tx_max_coalesced_frames_irq = vsi->work_lmt; 2316 2317 if (q_num < vsi->num_rxq) 2318 ec->rx_max_coalesced_frames_irq = vsi->work_lmt; 2319 2320 return 0; 2321 } 2322 2323 static int 2324 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec) 2325 { 2326 return __ice_get_coalesce(netdev, ec, -1); 2327 } 2328 2329 static int 2330 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num, 2331 struct ethtool_coalesce *ec) 2332 { 2333 return __ice_get_coalesce(netdev, ec, q_num); 2334 } 2335 2336 /** 2337 * ice_set_rc_coalesce - set ITR values for specific ring container 2338 * @c_type: container type, Rx or Tx 2339 * @ec: ethtool structure from user to update ITR settings 2340 * @rc: ring container that the ITR values will come from 2341 * @vsi: VSI associated to the ring container 2342 * 2343 * Set specific ITR values. This is done per ice_ring_container because each 2344 * q_vector can have 1 or more rings and all of said ring(s) will have the same 2345 * ITR values. 2346 * 2347 * Returns 0 on success, negative otherwise. 2348 */ 2349 static int 2350 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec, 2351 struct ice_ring_container *rc, struct ice_vsi *vsi) 2352 { 2353 struct ice_pf *pf = vsi->back; 2354 u16 itr_setting; 2355 2356 if (!rc->ring) 2357 return -EINVAL; 2358 2359 itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC; 2360 2361 switch (c_type) { 2362 case ICE_RX_CONTAINER: 2363 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL || 2364 (ec->rx_coalesce_usecs_high && 2365 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) { 2366 netdev_info(vsi->netdev, 2367 "Invalid value, rx-usecs-high valid values are 0 (disabled), %d-%d\n", 2368 pf->hw.intrl_gran, ICE_MAX_INTRL); 2369 return -EINVAL; 2370 } 2371 2372 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) { 2373 rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high; 2374 wr32(&pf->hw, GLINT_RATE(vsi->hw_base_vector + 2375 rc->ring->q_vector->v_idx), 2376 ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high, 2377 pf->hw.intrl_gran)); 2378 } 2379 2380 if (ec->rx_coalesce_usecs != itr_setting && 2381 ec->use_adaptive_rx_coalesce) { 2382 netdev_info(vsi->netdev, 2383 "Rx interrupt throttling cannot be changed if adaptive-rx is enabled\n"); 2384 return -EINVAL; 2385 } 2386 2387 if (ec->rx_coalesce_usecs > ICE_ITR_MAX) { 2388 netdev_info(vsi->netdev, 2389 "Invalid value, rx-usecs range is 0-%d\n", 2390 ICE_ITR_MAX); 2391 return -EINVAL; 2392 } 2393 2394 if (ec->use_adaptive_rx_coalesce) { 2395 rc->itr_setting |= ICE_ITR_DYNAMIC; 2396 } else { 2397 rc->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs); 2398 rc->target_itr = ITR_TO_REG(rc->itr_setting); 2399 } 2400 break; 2401 case ICE_TX_CONTAINER: 2402 if (ec->tx_coalesce_usecs_high) { 2403 netdev_info(vsi->netdev, 2404 "setting tx-usecs-high is not supported\n"); 2405 return -EINVAL; 2406 } 2407 2408 if (ec->tx_coalesce_usecs != itr_setting && 2409 ec->use_adaptive_tx_coalesce) { 2410 netdev_info(vsi->netdev, 2411 "Tx interrupt throttling cannot be changed if adaptive-tx is enabled\n"); 2412 return -EINVAL; 2413 } 2414 2415 if (ec->tx_coalesce_usecs > ICE_ITR_MAX) { 2416 netdev_info(vsi->netdev, 2417 "Invalid value, tx-usecs range is 0-%d\n", 2418 ICE_ITR_MAX); 2419 return -EINVAL; 2420 } 2421 2422 if (ec->use_adaptive_tx_coalesce) { 2423 rc->itr_setting |= ICE_ITR_DYNAMIC; 2424 } else { 2425 rc->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs); 2426 rc->target_itr = ITR_TO_REG(rc->itr_setting); 2427 } 2428 break; 2429 default: 2430 dev_dbg(&pf->pdev->dev, "Invalid container type %d\n", c_type); 2431 return -EINVAL; 2432 } 2433 2434 return 0; 2435 } 2436 2437 /** 2438 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings 2439 * @vsi: VSI associated to the queue that need updating 2440 * @ec: coalesce settings to program the device with 2441 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index 2442 * 2443 * Return 0 on success, and negative under the following conditions: 2444 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed. 2445 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings. 2446 */ 2447 static int 2448 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num) 2449 { 2450 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) { 2451 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec, 2452 &vsi->rx_rings[q_num]->q_vector->rx, 2453 vsi)) 2454 return -EINVAL; 2455 2456 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec, 2457 &vsi->tx_rings[q_num]->q_vector->tx, 2458 vsi)) 2459 return -EINVAL; 2460 } else if (q_num < vsi->num_rxq) { 2461 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec, 2462 &vsi->rx_rings[q_num]->q_vector->rx, 2463 vsi)) 2464 return -EINVAL; 2465 } else if (q_num < vsi->num_txq) { 2466 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec, 2467 &vsi->tx_rings[q_num]->q_vector->tx, 2468 vsi)) 2469 return -EINVAL; 2470 } else { 2471 return -EINVAL; 2472 } 2473 2474 return 0; 2475 } 2476 2477 /** 2478 * __ice_set_coalesce - set ITR/INTRL values for the device 2479 * @netdev: pointer to the netdev associated with this query 2480 * @ec: ethtool structure to fill with driver's coalesce settings 2481 * @q_num: queue number to get the coalesce settings for 2482 * 2483 * If the caller passes in a negative q_num then we set the coalesce settings 2484 * for all Tx/Rx queues, else use the actual q_num passed in. 2485 */ 2486 static int 2487 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, 2488 int q_num) 2489 { 2490 struct ice_netdev_priv *np = netdev_priv(netdev); 2491 struct ice_vsi *vsi = np->vsi; 2492 2493 if (q_num < 0) { 2494 int i; 2495 2496 ice_for_each_q_vector(vsi, i) { 2497 if (ice_set_q_coalesce(vsi, ec, i)) 2498 return -EINVAL; 2499 } 2500 goto set_work_lmt; 2501 } 2502 2503 if (ice_set_q_coalesce(vsi, ec, q_num)) 2504 return -EINVAL; 2505 2506 set_work_lmt: 2507 2508 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) 2509 vsi->work_lmt = max(ec->tx_max_coalesced_frames_irq, 2510 ec->rx_max_coalesced_frames_irq); 2511 2512 return 0; 2513 } 2514 2515 static int 2516 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec) 2517 { 2518 return __ice_set_coalesce(netdev, ec, -1); 2519 } 2520 2521 static int 2522 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num, 2523 struct ethtool_coalesce *ec) 2524 { 2525 return __ice_set_coalesce(netdev, ec, q_num); 2526 } 2527 2528 static const struct ethtool_ops ice_ethtool_ops = { 2529 .get_link_ksettings = ice_get_link_ksettings, 2530 .set_link_ksettings = ice_set_link_ksettings, 2531 .get_drvinfo = ice_get_drvinfo, 2532 .get_regs_len = ice_get_regs_len, 2533 .get_regs = ice_get_regs, 2534 .get_msglevel = ice_get_msglevel, 2535 .set_msglevel = ice_set_msglevel, 2536 .get_link = ethtool_op_get_link, 2537 .get_eeprom_len = ice_get_eeprom_len, 2538 .get_eeprom = ice_get_eeprom, 2539 .get_coalesce = ice_get_coalesce, 2540 .set_coalesce = ice_set_coalesce, 2541 .get_strings = ice_get_strings, 2542 .set_phys_id = ice_set_phys_id, 2543 .get_ethtool_stats = ice_get_ethtool_stats, 2544 .get_priv_flags = ice_get_priv_flags, 2545 .set_priv_flags = ice_set_priv_flags, 2546 .get_sset_count = ice_get_sset_count, 2547 .get_rxnfc = ice_get_rxnfc, 2548 .get_ringparam = ice_get_ringparam, 2549 .set_ringparam = ice_set_ringparam, 2550 .nway_reset = ice_nway_reset, 2551 .get_pauseparam = ice_get_pauseparam, 2552 .set_pauseparam = ice_set_pauseparam, 2553 .get_rxfh_key_size = ice_get_rxfh_key_size, 2554 .get_rxfh_indir_size = ice_get_rxfh_indir_size, 2555 .get_rxfh = ice_get_rxfh, 2556 .set_rxfh = ice_set_rxfh, 2557 .get_ts_info = ethtool_op_get_ts_info, 2558 .get_per_queue_coalesce = ice_get_per_q_coalesce, 2559 .set_per_queue_coalesce = ice_set_per_q_coalesce, 2560 }; 2561 2562 /** 2563 * ice_set_ethtool_ops - setup netdev ethtool ops 2564 * @netdev: network interface device structure 2565 * 2566 * setup netdev ethtool ops with ice specific ops 2567 */ 2568 void ice_set_ethtool_ops(struct net_device *netdev) 2569 { 2570 netdev->ethtool_ops = &ice_ethtool_ops; 2571 } 2572