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_flow.h" 8 #include "ice_fltr.h" 9 #include "ice_lib.h" 10 #include "ice_dcb_lib.h" 11 #include <net/dcbnl.h> 12 13 struct ice_stats { 14 char stat_string[ETH_GSTRING_LEN]; 15 int sizeof_stat; 16 int stat_offset; 17 }; 18 19 #define ICE_STAT(_type, _name, _stat) { \ 20 .stat_string = _name, \ 21 .sizeof_stat = sizeof_field(_type, _stat), \ 22 .stat_offset = offsetof(_type, _stat) \ 23 } 24 25 #define ICE_VSI_STAT(_name, _stat) \ 26 ICE_STAT(struct ice_vsi, _name, _stat) 27 #define ICE_PF_STAT(_name, _stat) \ 28 ICE_STAT(struct ice_pf, _name, _stat) 29 30 static int ice_q_stats_len(struct net_device *netdev) 31 { 32 struct ice_netdev_priv *np = netdev_priv(netdev); 33 34 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) * 35 (sizeof(struct ice_q_stats) / sizeof(u64))); 36 } 37 38 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats) 39 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats) 40 41 #define ICE_PFC_STATS_LEN ( \ 42 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \ 43 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \ 44 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \ 45 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \ 46 / sizeof(u64)) 47 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \ 48 ICE_VSI_STATS_LEN + ice_q_stats_len(n)) 49 50 static const struct ice_stats ice_gstrings_vsi_stats[] = { 51 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast), 52 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast), 53 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast), 54 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast), 55 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), 56 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), 57 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes), 58 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes), 59 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards), 60 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), 61 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed), 62 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed), 63 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors), 64 ICE_VSI_STAT("tx_linearize", tx_linearize), 65 ICE_VSI_STAT("tx_busy", tx_busy), 66 ICE_VSI_STAT("tx_restart", tx_restart), 67 }; 68 69 enum ice_ethtool_test_id { 70 ICE_ETH_TEST_REG = 0, 71 ICE_ETH_TEST_EEPROM, 72 ICE_ETH_TEST_INTR, 73 ICE_ETH_TEST_LOOP, 74 ICE_ETH_TEST_LINK, 75 }; 76 77 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = { 78 "Register test (offline)", 79 "EEPROM test (offline)", 80 "Interrupt test (offline)", 81 "Loopback test (offline)", 82 "Link test (on/offline)", 83 }; 84 85 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN) 86 87 /* These PF_STATs might look like duplicates of some NETDEV_STATs, 88 * but they aren't. This device is capable of supporting multiple 89 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual 90 * netdevs whereas the PF_STATs are for the physical function that's 91 * hosting these netdevs. 92 * 93 * The PF_STATs are appended to the netdev stats only when ethtool -S 94 * is queried on the base PF netdev. 95 */ 96 static const struct ice_stats ice_gstrings_pf_stats[] = { 97 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes), 98 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes), 99 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast), 100 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast), 101 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast), 102 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast), 103 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast), 104 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast), 105 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors), 106 ICE_PF_STAT("tx_timeout.nic", tx_timeout_count), 107 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64), 108 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64), 109 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127), 110 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127), 111 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255), 112 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255), 113 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511), 114 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511), 115 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023), 116 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023), 117 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522), 118 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522), 119 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big), 120 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big), 121 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx), 122 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx), 123 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx), 124 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx), 125 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down), 126 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize), 127 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments), 128 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize), 129 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber), 130 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error), 131 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors), 132 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards), 133 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors), 134 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes), 135 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults), 136 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults), 137 ICE_PF_STAT("fdir_sb_match.nic", stats.fd_sb_match), 138 ICE_PF_STAT("fdir_sb_status.nic", stats.fd_sb_status), 139 }; 140 141 static const u32 ice_regs_dump_list[] = { 142 PFGEN_STATE, 143 PRTGEN_STATUS, 144 QRX_CTRL(0), 145 QINT_TQCTL(0), 146 QINT_RQCTL(0), 147 PFINT_OICR_ENA, 148 QRX_ITR(0), 149 }; 150 151 struct ice_priv_flag { 152 char name[ETH_GSTRING_LEN]; 153 u32 bitno; /* bit position in pf->flags */ 154 }; 155 156 #define ICE_PRIV_FLAG(_name, _bitno) { \ 157 .name = _name, \ 158 .bitno = _bitno, \ 159 } 160 161 static const struct ice_priv_flag ice_gstrings_priv_flags[] = { 162 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA), 163 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT), 164 ICE_PRIV_FLAG("vf-true-promisc-support", 165 ICE_FLAG_VF_TRUE_PROMISC_ENA), 166 ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF), 167 ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX), 168 }; 169 170 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags) 171 172 static void 173 __ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo, 174 struct ice_vsi *vsi) 175 { 176 struct ice_pf *pf = vsi->back; 177 struct ice_hw *hw = &pf->hw; 178 struct ice_orom_info *orom; 179 struct ice_nvm_info *nvm; 180 181 nvm = &hw->flash.nvm; 182 orom = &hw->flash.orom; 183 184 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); 185 186 /* Display NVM version (from which the firmware version can be 187 * determined) which contains more pertinent information. 188 */ 189 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), 190 "%x.%02x 0x%x %d.%d.%d", nvm->major, nvm->minor, 191 nvm->eetrack, orom->major, orom->build, orom->patch); 192 } 193 194 static void 195 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) 196 { 197 struct ice_netdev_priv *np = netdev_priv(netdev); 198 struct ice_pf *pf = np->vsi->back; 199 200 __ice_get_drvinfo(netdev, drvinfo, np->vsi); 201 202 strscpy(drvinfo->bus_info, pci_name(pf->pdev), 203 sizeof(drvinfo->bus_info)); 204 205 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE; 206 } 207 208 static int ice_get_regs_len(struct net_device __always_unused *netdev) 209 { 210 return sizeof(ice_regs_dump_list); 211 } 212 213 static void 214 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) 215 { 216 struct ice_netdev_priv *np = netdev_priv(netdev); 217 struct ice_pf *pf = np->vsi->back; 218 struct ice_hw *hw = &pf->hw; 219 u32 *regs_buf = (u32 *)p; 220 unsigned int i; 221 222 regs->version = 1; 223 224 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i) 225 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]); 226 } 227 228 static u32 ice_get_msglevel(struct net_device *netdev) 229 { 230 struct ice_netdev_priv *np = netdev_priv(netdev); 231 struct ice_pf *pf = np->vsi->back; 232 233 #ifndef CONFIG_DYNAMIC_DEBUG 234 if (pf->hw.debug_mask) 235 netdev_info(netdev, "hw debug_mask: 0x%llX\n", 236 pf->hw.debug_mask); 237 #endif /* !CONFIG_DYNAMIC_DEBUG */ 238 239 return pf->msg_enable; 240 } 241 242 static void ice_set_msglevel(struct net_device *netdev, u32 data) 243 { 244 struct ice_netdev_priv *np = netdev_priv(netdev); 245 struct ice_pf *pf = np->vsi->back; 246 247 #ifndef CONFIG_DYNAMIC_DEBUG 248 if (ICE_DBG_USER & data) 249 pf->hw.debug_mask = data; 250 else 251 pf->msg_enable = data; 252 #else 253 pf->msg_enable = data; 254 #endif /* !CONFIG_DYNAMIC_DEBUG */ 255 } 256 257 static int ice_get_eeprom_len(struct net_device *netdev) 258 { 259 struct ice_netdev_priv *np = netdev_priv(netdev); 260 struct ice_pf *pf = np->vsi->back; 261 262 return (int)pf->hw.flash.flash_size; 263 } 264 265 static int 266 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, 267 u8 *bytes) 268 { 269 struct ice_netdev_priv *np = netdev_priv(netdev); 270 struct ice_vsi *vsi = np->vsi; 271 struct ice_pf *pf = vsi->back; 272 struct ice_hw *hw = &pf->hw; 273 enum ice_status status; 274 struct device *dev; 275 int ret = 0; 276 u8 *buf; 277 278 dev = ice_pf_to_dev(pf); 279 280 eeprom->magic = hw->vendor_id | (hw->device_id << 16); 281 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n", 282 eeprom->cmd, eeprom->offset, eeprom->len); 283 284 buf = kzalloc(eeprom->len, GFP_KERNEL); 285 if (!buf) 286 return -ENOMEM; 287 288 status = ice_acquire_nvm(hw, ICE_RES_READ); 289 if (status) { 290 dev_err(dev, "ice_acquire_nvm failed, err %s aq_err %s\n", 291 ice_stat_str(status), 292 ice_aq_str(hw->adminq.sq_last_status)); 293 ret = -EIO; 294 goto out; 295 } 296 297 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf, 298 false); 299 if (status) { 300 dev_err(dev, "ice_read_flat_nvm failed, err %s aq_err %s\n", 301 ice_stat_str(status), 302 ice_aq_str(hw->adminq.sq_last_status)); 303 ret = -EIO; 304 goto release; 305 } 306 307 memcpy(bytes, buf, eeprom->len); 308 release: 309 ice_release_nvm(hw); 310 out: 311 kfree(buf); 312 return ret; 313 } 314 315 /** 316 * ice_active_vfs - check if there are any active VFs 317 * @pf: board private structure 318 * 319 * Returns true if an active VF is found, otherwise returns false 320 */ 321 static bool ice_active_vfs(struct ice_pf *pf) 322 { 323 unsigned int i; 324 325 ice_for_each_vf(pf, i) { 326 struct ice_vf *vf = &pf->vf[i]; 327 328 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) 329 return true; 330 } 331 332 return false; 333 } 334 335 /** 336 * ice_link_test - perform a link test on a given net_device 337 * @netdev: network interface device structure 338 * 339 * This function performs one of the self-tests required by ethtool. 340 * Returns 0 on success, non-zero on failure. 341 */ 342 static u64 ice_link_test(struct net_device *netdev) 343 { 344 struct ice_netdev_priv *np = netdev_priv(netdev); 345 enum ice_status status; 346 bool link_up = false; 347 348 netdev_info(netdev, "link test\n"); 349 status = ice_get_link_status(np->vsi->port_info, &link_up); 350 if (status) { 351 netdev_err(netdev, "link query error, status = %s\n", 352 ice_stat_str(status)); 353 return 1; 354 } 355 356 if (!link_up) 357 return 2; 358 359 return 0; 360 } 361 362 /** 363 * ice_eeprom_test - perform an EEPROM test on a given net_device 364 * @netdev: network interface device structure 365 * 366 * This function performs one of the self-tests required by ethtool. 367 * Returns 0 on success, non-zero on failure. 368 */ 369 static u64 ice_eeprom_test(struct net_device *netdev) 370 { 371 struct ice_netdev_priv *np = netdev_priv(netdev); 372 struct ice_pf *pf = np->vsi->back; 373 374 netdev_info(netdev, "EEPROM test\n"); 375 return !!(ice_nvm_validate_checksum(&pf->hw)); 376 } 377 378 /** 379 * ice_reg_pattern_test 380 * @hw: pointer to the HW struct 381 * @reg: reg to be tested 382 * @mask: bits to be touched 383 */ 384 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask) 385 { 386 struct ice_pf *pf = (struct ice_pf *)hw->back; 387 struct device *dev = ice_pf_to_dev(pf); 388 static const u32 patterns[] = { 389 0x5A5A5A5A, 0xA5A5A5A5, 390 0x00000000, 0xFFFFFFFF 391 }; 392 u32 val, orig_val; 393 unsigned int i; 394 395 orig_val = rd32(hw, reg); 396 for (i = 0; i < ARRAY_SIZE(patterns); ++i) { 397 u32 pattern = patterns[i] & mask; 398 399 wr32(hw, reg, pattern); 400 val = rd32(hw, reg); 401 if (val == pattern) 402 continue; 403 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n" 404 , __func__, reg, pattern, val); 405 return 1; 406 } 407 408 wr32(hw, reg, orig_val); 409 val = rd32(hw, reg); 410 if (val != orig_val) { 411 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n" 412 , __func__, reg, orig_val, val); 413 return 1; 414 } 415 416 return 0; 417 } 418 419 /** 420 * ice_reg_test - perform a register test on a given net_device 421 * @netdev: network interface device structure 422 * 423 * This function performs one of the self-tests required by ethtool. 424 * Returns 0 on success, non-zero on failure. 425 */ 426 static u64 ice_reg_test(struct net_device *netdev) 427 { 428 struct ice_netdev_priv *np = netdev_priv(netdev); 429 struct ice_hw *hw = np->vsi->port_info->hw; 430 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ? 431 hw->func_caps.common_cap.num_msix_vectors - 1 : 1; 432 struct ice_diag_reg_test_info { 433 u32 address; 434 u32 mask; 435 u32 elem_num; 436 u32 elem_size; 437 } ice_reg_list[] = { 438 {GLINT_ITR(0, 0), 0x00000fff, int_elements, 439 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)}, 440 {GLINT_ITR(1, 0), 0x00000fff, int_elements, 441 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)}, 442 {GLINT_ITR(0, 0), 0x00000fff, int_elements, 443 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)}, 444 {GLINT_CTL, 0xffff0001, 1, 0} 445 }; 446 unsigned int i; 447 448 netdev_dbg(netdev, "Register test\n"); 449 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) { 450 u32 j; 451 452 for (j = 0; j < ice_reg_list[i].elem_num; ++j) { 453 u32 mask = ice_reg_list[i].mask; 454 u32 reg = ice_reg_list[i].address + 455 (j * ice_reg_list[i].elem_size); 456 457 /* bail on failure (non-zero return) */ 458 if (ice_reg_pattern_test(hw, reg, mask)) 459 return 1; 460 } 461 } 462 463 return 0; 464 } 465 466 /** 467 * ice_lbtest_prepare_rings - configure Tx/Rx test rings 468 * @vsi: pointer to the VSI structure 469 * 470 * Function configures rings of a VSI for loopback test without 471 * enabling interrupts or informing the kernel about new queues. 472 * 473 * Returns 0 on success, negative on failure. 474 */ 475 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi) 476 { 477 int status; 478 479 status = ice_vsi_setup_tx_rings(vsi); 480 if (status) 481 goto err_setup_tx_ring; 482 483 status = ice_vsi_setup_rx_rings(vsi); 484 if (status) 485 goto err_setup_rx_ring; 486 487 status = ice_vsi_cfg(vsi); 488 if (status) 489 goto err_setup_rx_ring; 490 491 status = ice_vsi_start_all_rx_rings(vsi); 492 if (status) 493 goto err_start_rx_ring; 494 495 return status; 496 497 err_start_rx_ring: 498 ice_vsi_free_rx_rings(vsi); 499 err_setup_rx_ring: 500 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0); 501 err_setup_tx_ring: 502 ice_vsi_free_tx_rings(vsi); 503 504 return status; 505 } 506 507 /** 508 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test 509 * @vsi: pointer to the VSI structure 510 * 511 * Function stops and frees VSI rings after a loopback test. 512 * Returns 0 on success, negative on failure. 513 */ 514 static int ice_lbtest_disable_rings(struct ice_vsi *vsi) 515 { 516 int status; 517 518 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0); 519 if (status) 520 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n", 521 vsi->vsi_num, status); 522 523 status = ice_vsi_stop_all_rx_rings(vsi); 524 if (status) 525 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n", 526 vsi->vsi_num, status); 527 528 ice_vsi_free_tx_rings(vsi); 529 ice_vsi_free_rx_rings(vsi); 530 531 return status; 532 } 533 534 /** 535 * ice_lbtest_create_frame - create test packet 536 * @pf: pointer to the PF structure 537 * @ret_data: allocated frame buffer 538 * @size: size of the packet data 539 * 540 * Function allocates a frame with a test pattern on specific offsets. 541 * Returns 0 on success, non-zero on failure. 542 */ 543 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size) 544 { 545 u8 *data; 546 547 if (!pf) 548 return -EINVAL; 549 550 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL); 551 if (!data) 552 return -ENOMEM; 553 554 /* Since the ethernet test frame should always be at least 555 * 64 bytes long, fill some octets in the payload with test data. 556 */ 557 memset(data, 0xFF, size); 558 data[32] = 0xDE; 559 data[42] = 0xAD; 560 data[44] = 0xBE; 561 data[46] = 0xEF; 562 563 *ret_data = data; 564 565 return 0; 566 } 567 568 /** 569 * ice_lbtest_check_frame - verify received loopback frame 570 * @frame: pointer to the raw packet data 571 * 572 * Function verifies received test frame with a pattern. 573 * Returns true if frame matches the pattern, false otherwise. 574 */ 575 static bool ice_lbtest_check_frame(u8 *frame) 576 { 577 /* Validate bytes of a frame under offsets chosen earlier */ 578 if (frame[32] == 0xDE && 579 frame[42] == 0xAD && 580 frame[44] == 0xBE && 581 frame[46] == 0xEF && 582 frame[48] == 0xFF) 583 return true; 584 585 return false; 586 } 587 588 /** 589 * ice_diag_send - send test frames to the test ring 590 * @tx_ring: pointer to the transmit ring 591 * @data: pointer to the raw packet data 592 * @size: size of the packet to send 593 * 594 * Function sends loopback packets on a test Tx ring. 595 */ 596 static int ice_diag_send(struct ice_tx_ring *tx_ring, u8 *data, u16 size) 597 { 598 struct ice_tx_desc *tx_desc; 599 struct ice_tx_buf *tx_buf; 600 dma_addr_t dma; 601 u64 td_cmd; 602 603 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use); 604 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use]; 605 606 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE); 607 if (dma_mapping_error(tx_ring->dev, dma)) 608 return -EINVAL; 609 610 tx_desc->buf_addr = cpu_to_le64(dma); 611 612 /* These flags are required for a descriptor to be pushed out */ 613 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS); 614 tx_desc->cmd_type_offset_bsz = 615 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA | 616 (td_cmd << ICE_TXD_QW1_CMD_S) | 617 ((u64)0 << ICE_TXD_QW1_OFFSET_S) | 618 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) | 619 ((u64)0 << ICE_TXD_QW1_L2TAG1_S)); 620 621 tx_buf->next_to_watch = tx_desc; 622 623 /* Force memory write to complete before letting h/w know 624 * there are new descriptors to fetch. 625 */ 626 wmb(); 627 628 tx_ring->next_to_use++; 629 if (tx_ring->next_to_use >= tx_ring->count) 630 tx_ring->next_to_use = 0; 631 632 writel_relaxed(tx_ring->next_to_use, tx_ring->tail); 633 634 /* Wait until the packets get transmitted to the receive queue. */ 635 usleep_range(1000, 2000); 636 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE); 637 638 return 0; 639 } 640 641 #define ICE_LB_FRAME_SIZE 64 642 /** 643 * ice_lbtest_receive_frames - receive and verify test frames 644 * @rx_ring: pointer to the receive ring 645 * 646 * Function receives loopback packets and verify their correctness. 647 * Returns number of received valid frames. 648 */ 649 static int ice_lbtest_receive_frames(struct ice_rx_ring *rx_ring) 650 { 651 struct ice_rx_buf *rx_buf; 652 int valid_frames, i; 653 u8 *received_buf; 654 655 valid_frames = 0; 656 657 for (i = 0; i < rx_ring->count; i++) { 658 union ice_32b_rx_flex_desc *rx_desc; 659 660 rx_desc = ICE_RX_DESC(rx_ring, i); 661 662 if (!(rx_desc->wb.status_error0 & 663 cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS))) 664 continue; 665 666 rx_buf = &rx_ring->rx_buf[i]; 667 received_buf = page_address(rx_buf->page) + rx_buf->page_offset; 668 669 if (ice_lbtest_check_frame(received_buf)) 670 valid_frames++; 671 } 672 673 return valid_frames; 674 } 675 676 /** 677 * ice_loopback_test - perform a loopback test on a given net_device 678 * @netdev: network interface device structure 679 * 680 * This function performs one of the self-tests required by ethtool. 681 * Returns 0 on success, non-zero on failure. 682 */ 683 static u64 ice_loopback_test(struct net_device *netdev) 684 { 685 struct ice_netdev_priv *np = netdev_priv(netdev); 686 struct ice_vsi *orig_vsi = np->vsi, *test_vsi; 687 struct ice_pf *pf = orig_vsi->back; 688 u8 broadcast[ETH_ALEN], ret = 0; 689 int num_frames, valid_frames; 690 struct ice_tx_ring *tx_ring; 691 struct ice_rx_ring *rx_ring; 692 struct device *dev; 693 u8 *tx_frame; 694 int i; 695 696 dev = ice_pf_to_dev(pf); 697 netdev_info(netdev, "loopback test\n"); 698 699 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info); 700 if (!test_vsi) { 701 netdev_err(netdev, "Failed to create a VSI for the loopback test\n"); 702 return 1; 703 } 704 705 test_vsi->netdev = netdev; 706 tx_ring = test_vsi->tx_rings[0]; 707 rx_ring = test_vsi->rx_rings[0]; 708 709 if (ice_lbtest_prepare_rings(test_vsi)) { 710 ret = 2; 711 goto lbtest_vsi_close; 712 } 713 714 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) { 715 ret = 3; 716 goto lbtest_rings_dis; 717 } 718 719 /* Enable MAC loopback in firmware */ 720 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) { 721 ret = 4; 722 goto lbtest_mac_dis; 723 } 724 725 /* Test VSI needs to receive broadcast packets */ 726 eth_broadcast_addr(broadcast); 727 if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) { 728 ret = 5; 729 goto lbtest_mac_dis; 730 } 731 732 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) { 733 ret = 7; 734 goto remove_mac_filters; 735 } 736 737 num_frames = min_t(int, tx_ring->count, 32); 738 for (i = 0; i < num_frames; i++) { 739 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) { 740 ret = 8; 741 goto lbtest_free_frame; 742 } 743 } 744 745 valid_frames = ice_lbtest_receive_frames(rx_ring); 746 if (!valid_frames) 747 ret = 9; 748 else if (valid_frames != num_frames) 749 ret = 10; 750 751 lbtest_free_frame: 752 devm_kfree(dev, tx_frame); 753 remove_mac_filters: 754 if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) 755 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n"); 756 lbtest_mac_dis: 757 /* Disable MAC loopback after the test is completed. */ 758 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL)) 759 netdev_err(netdev, "Could not disable MAC loopback\n"); 760 lbtest_rings_dis: 761 if (ice_lbtest_disable_rings(test_vsi)) 762 netdev_err(netdev, "Could not disable test rings\n"); 763 lbtest_vsi_close: 764 test_vsi->netdev = NULL; 765 if (ice_vsi_release(test_vsi)) 766 netdev_err(netdev, "Failed to remove the test VSI\n"); 767 768 return ret; 769 } 770 771 /** 772 * ice_intr_test - perform an interrupt test on a given net_device 773 * @netdev: network interface device structure 774 * 775 * This function performs one of the self-tests required by ethtool. 776 * Returns 0 on success, non-zero on failure. 777 */ 778 static u64 ice_intr_test(struct net_device *netdev) 779 { 780 struct ice_netdev_priv *np = netdev_priv(netdev); 781 struct ice_pf *pf = np->vsi->back; 782 u16 swic_old = pf->sw_int_count; 783 784 netdev_info(netdev, "interrupt test\n"); 785 786 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx), 787 GLINT_DYN_CTL_SW_ITR_INDX_M | 788 GLINT_DYN_CTL_INTENA_MSK_M | 789 GLINT_DYN_CTL_SWINT_TRIG_M); 790 791 usleep_range(1000, 2000); 792 return (swic_old == pf->sw_int_count); 793 } 794 795 /** 796 * ice_self_test - handler function for performing a self-test by ethtool 797 * @netdev: network interface device structure 798 * @eth_test: ethtool_test structure 799 * @data: required by ethtool.self_test 800 * 801 * This function is called after invoking 'ethtool -t devname' command where 802 * devname is the name of the network device on which ethtool should operate. 803 * It performs a set of self-tests to check if a device works properly. 804 */ 805 static void 806 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test, 807 u64 *data) 808 { 809 struct ice_netdev_priv *np = netdev_priv(netdev); 810 bool if_running = netif_running(netdev); 811 struct ice_pf *pf = np->vsi->back; 812 struct device *dev; 813 814 dev = ice_pf_to_dev(pf); 815 816 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 817 netdev_info(netdev, "offline testing starting\n"); 818 819 set_bit(ICE_TESTING, pf->state); 820 821 if (ice_active_vfs(pf)) { 822 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n"); 823 data[ICE_ETH_TEST_REG] = 1; 824 data[ICE_ETH_TEST_EEPROM] = 1; 825 data[ICE_ETH_TEST_INTR] = 1; 826 data[ICE_ETH_TEST_LOOP] = 1; 827 data[ICE_ETH_TEST_LINK] = 1; 828 eth_test->flags |= ETH_TEST_FL_FAILED; 829 clear_bit(ICE_TESTING, pf->state); 830 goto skip_ol_tests; 831 } 832 /* If the device is online then take it offline */ 833 if (if_running) 834 /* indicate we're in test mode */ 835 ice_stop(netdev); 836 837 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev); 838 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev); 839 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev); 840 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev); 841 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev); 842 843 if (data[ICE_ETH_TEST_LINK] || 844 data[ICE_ETH_TEST_EEPROM] || 845 data[ICE_ETH_TEST_LOOP] || 846 data[ICE_ETH_TEST_INTR] || 847 data[ICE_ETH_TEST_REG]) 848 eth_test->flags |= ETH_TEST_FL_FAILED; 849 850 clear_bit(ICE_TESTING, pf->state); 851 852 if (if_running) { 853 int status = ice_open(netdev); 854 855 if (status) { 856 dev_err(dev, "Could not open device %s, err %d\n", 857 pf->int_name, status); 858 } 859 } 860 } else { 861 /* Online tests */ 862 netdev_info(netdev, "online testing starting\n"); 863 864 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev); 865 if (data[ICE_ETH_TEST_LINK]) 866 eth_test->flags |= ETH_TEST_FL_FAILED; 867 868 /* Offline only tests, not run in online; pass by default */ 869 data[ICE_ETH_TEST_REG] = 0; 870 data[ICE_ETH_TEST_EEPROM] = 0; 871 data[ICE_ETH_TEST_INTR] = 0; 872 data[ICE_ETH_TEST_LOOP] = 0; 873 } 874 875 skip_ol_tests: 876 netdev_info(netdev, "testing finished\n"); 877 } 878 879 static void 880 __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data, 881 struct ice_vsi *vsi) 882 { 883 unsigned int i; 884 u8 *p = data; 885 886 switch (stringset) { 887 case ETH_SS_STATS: 888 for (i = 0; i < ICE_VSI_STATS_LEN; i++) 889 ethtool_sprintf(&p, 890 ice_gstrings_vsi_stats[i].stat_string); 891 892 if (ice_is_port_repr_netdev(netdev)) 893 return; 894 895 ice_for_each_alloc_txq(vsi, i) { 896 ethtool_sprintf(&p, "tx_queue_%u_packets", i); 897 ethtool_sprintf(&p, "tx_queue_%u_bytes", i); 898 } 899 900 ice_for_each_alloc_rxq(vsi, i) { 901 ethtool_sprintf(&p, "rx_queue_%u_packets", i); 902 ethtool_sprintf(&p, "rx_queue_%u_bytes", i); 903 } 904 905 if (vsi->type != ICE_VSI_PF) 906 return; 907 908 for (i = 0; i < ICE_PF_STATS_LEN; i++) 909 ethtool_sprintf(&p, 910 ice_gstrings_pf_stats[i].stat_string); 911 912 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { 913 ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i); 914 ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i); 915 } 916 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) { 917 ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i); 918 ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i); 919 } 920 break; 921 case ETH_SS_TEST: 922 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN); 923 break; 924 case ETH_SS_PRIV_FLAGS: 925 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) 926 ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name); 927 break; 928 default: 929 break; 930 } 931 } 932 933 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 934 { 935 struct ice_netdev_priv *np = netdev_priv(netdev); 936 937 __ice_get_strings(netdev, stringset, data, np->vsi); 938 } 939 940 static int 941 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state) 942 { 943 struct ice_netdev_priv *np = netdev_priv(netdev); 944 bool led_active; 945 946 switch (state) { 947 case ETHTOOL_ID_ACTIVE: 948 led_active = true; 949 break; 950 case ETHTOOL_ID_INACTIVE: 951 led_active = false; 952 break; 953 default: 954 return -EINVAL; 955 } 956 957 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL)) 958 return -EIO; 959 960 return 0; 961 } 962 963 /** 964 * ice_set_fec_cfg - Set link FEC options 965 * @netdev: network interface device structure 966 * @req_fec: FEC mode to configure 967 */ 968 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec) 969 { 970 struct ice_netdev_priv *np = netdev_priv(netdev); 971 struct ice_aqc_set_phy_cfg_data config = { 0 }; 972 struct ice_vsi *vsi = np->vsi; 973 struct ice_port_info *pi; 974 975 pi = vsi->port_info; 976 if (!pi) 977 return -EOPNOTSUPP; 978 979 /* Changing the FEC parameters is not supported if not the PF VSI */ 980 if (vsi->type != ICE_VSI_PF) { 981 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n"); 982 return -EOPNOTSUPP; 983 } 984 985 /* Proceed only if requesting different FEC mode */ 986 if (pi->phy.curr_user_fec_req == req_fec) 987 return 0; 988 989 /* Copy the current user PHY configuration. The current user PHY 990 * configuration is initialized during probe from PHY capabilities 991 * software mode, and updated on set PHY configuration. 992 */ 993 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config)); 994 995 ice_cfg_phy_fec(pi, &config, req_fec); 996 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 997 998 if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL)) 999 return -EAGAIN; 1000 1001 /* Save requested FEC config */ 1002 pi->phy.curr_user_fec_req = req_fec; 1003 1004 return 0; 1005 } 1006 1007 /** 1008 * ice_set_fecparam - Set FEC link options 1009 * @netdev: network interface device structure 1010 * @fecparam: Ethtool structure to retrieve FEC parameters 1011 */ 1012 static int 1013 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam) 1014 { 1015 struct ice_netdev_priv *np = netdev_priv(netdev); 1016 struct ice_vsi *vsi = np->vsi; 1017 enum ice_fec_mode fec; 1018 1019 switch (fecparam->fec) { 1020 case ETHTOOL_FEC_AUTO: 1021 fec = ICE_FEC_AUTO; 1022 break; 1023 case ETHTOOL_FEC_RS: 1024 fec = ICE_FEC_RS; 1025 break; 1026 case ETHTOOL_FEC_BASER: 1027 fec = ICE_FEC_BASER; 1028 break; 1029 case ETHTOOL_FEC_OFF: 1030 case ETHTOOL_FEC_NONE: 1031 fec = ICE_FEC_NONE; 1032 break; 1033 default: 1034 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n", 1035 fecparam->fec); 1036 return -EINVAL; 1037 } 1038 1039 return ice_set_fec_cfg(netdev, fec); 1040 } 1041 1042 /** 1043 * ice_get_fecparam - Get link FEC options 1044 * @netdev: network interface device structure 1045 * @fecparam: Ethtool structure to retrieve FEC parameters 1046 */ 1047 static int 1048 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam) 1049 { 1050 struct ice_netdev_priv *np = netdev_priv(netdev); 1051 struct ice_aqc_get_phy_caps_data *caps; 1052 struct ice_link_status *link_info; 1053 struct ice_vsi *vsi = np->vsi; 1054 struct ice_port_info *pi; 1055 enum ice_status status; 1056 int err = 0; 1057 1058 pi = vsi->port_info; 1059 1060 if (!pi) 1061 return -EOPNOTSUPP; 1062 link_info = &pi->phy.link_info; 1063 1064 /* Set FEC mode based on negotiated link info */ 1065 switch (link_info->fec_info) { 1066 case ICE_AQ_LINK_25G_KR_FEC_EN: 1067 fecparam->active_fec = ETHTOOL_FEC_BASER; 1068 break; 1069 case ICE_AQ_LINK_25G_RS_528_FEC_EN: 1070 case ICE_AQ_LINK_25G_RS_544_FEC_EN: 1071 fecparam->active_fec = ETHTOOL_FEC_RS; 1072 break; 1073 default: 1074 fecparam->active_fec = ETHTOOL_FEC_OFF; 1075 break; 1076 } 1077 1078 caps = kzalloc(sizeof(*caps), GFP_KERNEL); 1079 if (!caps) 1080 return -ENOMEM; 1081 1082 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, 1083 caps, NULL); 1084 if (status) { 1085 err = -EAGAIN; 1086 goto done; 1087 } 1088 1089 /* Set supported/configured FEC modes based on PHY capability */ 1090 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC) 1091 fecparam->fec |= ETHTOOL_FEC_AUTO; 1092 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN || 1093 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ || 1094 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN || 1095 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ) 1096 fecparam->fec |= ETHTOOL_FEC_BASER; 1097 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ || 1098 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ || 1099 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN) 1100 fecparam->fec |= ETHTOOL_FEC_RS; 1101 if (caps->link_fec_options == 0) 1102 fecparam->fec |= ETHTOOL_FEC_OFF; 1103 1104 done: 1105 kfree(caps); 1106 return err; 1107 } 1108 1109 /** 1110 * ice_nway_reset - restart autonegotiation 1111 * @netdev: network interface device structure 1112 */ 1113 static int ice_nway_reset(struct net_device *netdev) 1114 { 1115 struct ice_netdev_priv *np = netdev_priv(netdev); 1116 struct ice_vsi *vsi = np->vsi; 1117 int err; 1118 1119 /* If VSI state is up, then restart autoneg with link up */ 1120 if (!test_bit(ICE_DOWN, vsi->back->state)) 1121 err = ice_set_link(vsi, true); 1122 else 1123 err = ice_set_link(vsi, false); 1124 1125 return err; 1126 } 1127 1128 /** 1129 * ice_get_priv_flags - report device private flags 1130 * @netdev: network interface device structure 1131 * 1132 * The get string set count and the string set should be matched for each 1133 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags 1134 * array. 1135 * 1136 * Returns a u32 bitmap of flags. 1137 */ 1138 static u32 ice_get_priv_flags(struct net_device *netdev) 1139 { 1140 struct ice_netdev_priv *np = netdev_priv(netdev); 1141 struct ice_vsi *vsi = np->vsi; 1142 struct ice_pf *pf = vsi->back; 1143 u32 i, ret_flags = 0; 1144 1145 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { 1146 const struct ice_priv_flag *priv_flag; 1147 1148 priv_flag = &ice_gstrings_priv_flags[i]; 1149 1150 if (test_bit(priv_flag->bitno, pf->flags)) 1151 ret_flags |= BIT(i); 1152 } 1153 1154 return ret_flags; 1155 } 1156 1157 /** 1158 * ice_set_priv_flags - set private flags 1159 * @netdev: network interface device structure 1160 * @flags: bit flags to be set 1161 */ 1162 static int ice_set_priv_flags(struct net_device *netdev, u32 flags) 1163 { 1164 struct ice_netdev_priv *np = netdev_priv(netdev); 1165 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS); 1166 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS); 1167 struct ice_vsi *vsi = np->vsi; 1168 struct ice_pf *pf = vsi->back; 1169 struct device *dev; 1170 int ret = 0; 1171 u32 i; 1172 1173 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE)) 1174 return -EINVAL; 1175 1176 dev = ice_pf_to_dev(pf); 1177 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags); 1178 1179 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS); 1180 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) { 1181 const struct ice_priv_flag *priv_flag; 1182 1183 priv_flag = &ice_gstrings_priv_flags[i]; 1184 1185 if (flags & BIT(i)) 1186 set_bit(priv_flag->bitno, pf->flags); 1187 else 1188 clear_bit(priv_flag->bitno, pf->flags); 1189 } 1190 1191 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS); 1192 1193 /* Do not allow change to link-down-on-close when Total Port Shutdown 1194 * is enabled. 1195 */ 1196 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) && 1197 test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) { 1198 dev_err(dev, "Setting link-down-on-close not supported on this port\n"); 1199 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags); 1200 ret = -EINVAL; 1201 goto ethtool_exit; 1202 } 1203 1204 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) { 1205 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) { 1206 enum ice_status status; 1207 1208 /* Disable FW LLDP engine */ 1209 status = ice_cfg_lldp_mib_change(&pf->hw, false); 1210 1211 /* If unregistering for LLDP events fails, this is 1212 * not an error state, as there shouldn't be any 1213 * events to respond to. 1214 */ 1215 if (status) 1216 dev_info(dev, "Failed to unreg for LLDP events\n"); 1217 1218 /* The AQ call to stop the FW LLDP agent will generate 1219 * an error if the agent is already stopped. 1220 */ 1221 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL); 1222 if (status) 1223 dev_warn(dev, "Fail to stop LLDP agent\n"); 1224 /* Use case for having the FW LLDP agent stopped 1225 * will likely not need DCB, so failure to init is 1226 * not a concern of ethtool 1227 */ 1228 status = ice_init_pf_dcb(pf, true); 1229 if (status) 1230 dev_warn(dev, "Fail to init DCB\n"); 1231 1232 pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED; 1233 pf->dcbx_cap |= DCB_CAP_DCBX_HOST; 1234 } else { 1235 enum ice_status status; 1236 bool dcbx_agent_status; 1237 1238 if (ice_get_pfc_mode(pf) == ICE_QOS_MODE_DSCP) { 1239 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags); 1240 dev_err(dev, "QoS in L3 DSCP mode, FW Agent not allowed to start\n"); 1241 ret = -EOPNOTSUPP; 1242 goto ethtool_exit; 1243 } 1244 1245 /* Remove rule to direct LLDP packets to default VSI. 1246 * The FW LLDP engine will now be consuming them. 1247 */ 1248 ice_cfg_sw_lldp(vsi, false, false); 1249 1250 /* AQ command to start FW LLDP agent will return an 1251 * error if the agent is already started 1252 */ 1253 status = ice_aq_start_lldp(&pf->hw, true, NULL); 1254 if (status) 1255 dev_warn(dev, "Fail to start LLDP Agent\n"); 1256 1257 /* AQ command to start FW DCBX agent will fail if 1258 * the agent is already started 1259 */ 1260 status = ice_aq_start_stop_dcbx(&pf->hw, true, 1261 &dcbx_agent_status, 1262 NULL); 1263 if (status) 1264 dev_dbg(dev, "Failed to start FW DCBX\n"); 1265 1266 dev_info(dev, "FW DCBX agent is %s\n", 1267 dcbx_agent_status ? "ACTIVE" : "DISABLED"); 1268 1269 /* Failure to configure MIB change or init DCB is not 1270 * relevant to ethtool. Print notification that 1271 * registration/init failed but do not return error 1272 * state to ethtool 1273 */ 1274 status = ice_init_pf_dcb(pf, true); 1275 if (status) 1276 dev_dbg(dev, "Fail to init DCB\n"); 1277 1278 /* Register for MIB change events */ 1279 status = ice_cfg_lldp_mib_change(&pf->hw, true); 1280 if (status) 1281 dev_dbg(dev, "Fail to enable MIB change events\n"); 1282 1283 pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST; 1284 pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED; 1285 1286 ice_nway_reset(netdev); 1287 } 1288 } 1289 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) { 1290 /* down and up VSI so that changes of Rx cfg are reflected. */ 1291 ice_down(vsi); 1292 ice_up(vsi); 1293 } 1294 /* don't allow modification of this flag when a single VF is in 1295 * promiscuous mode because it's not supported 1296 */ 1297 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) && 1298 ice_is_any_vf_in_promisc(pf)) { 1299 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n"); 1300 /* toggle bit back to previous state */ 1301 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags); 1302 ret = -EAGAIN; 1303 } 1304 ethtool_exit: 1305 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags); 1306 return ret; 1307 } 1308 1309 static int ice_get_sset_count(struct net_device *netdev, int sset) 1310 { 1311 switch (sset) { 1312 case ETH_SS_STATS: 1313 /* The number (and order) of strings reported *must* remain 1314 * constant for a given netdevice. This function must not 1315 * report a different number based on run time parameters 1316 * (such as the number of queues in use, or the setting of 1317 * a private ethtool flag). This is due to the nature of the 1318 * ethtool stats API. 1319 * 1320 * Userspace programs such as ethtool must make 3 separate 1321 * ioctl requests, one for size, one for the strings, and 1322 * finally one for the stats. Since these cross into 1323 * userspace, changes to the number or size could result in 1324 * undefined memory access or incorrect string<->value 1325 * correlations for statistics. 1326 * 1327 * Even if it appears to be safe, changes to the size or 1328 * order of strings will suffer from race conditions and are 1329 * not safe. 1330 */ 1331 return ICE_ALL_STATS_LEN(netdev); 1332 case ETH_SS_TEST: 1333 return ICE_TEST_LEN; 1334 case ETH_SS_PRIV_FLAGS: 1335 return ICE_PRIV_FLAG_ARRAY_SIZE; 1336 default: 1337 return -EOPNOTSUPP; 1338 } 1339 } 1340 1341 static void 1342 __ice_get_ethtool_stats(struct net_device *netdev, 1343 struct ethtool_stats __always_unused *stats, u64 *data, 1344 struct ice_vsi *vsi) 1345 { 1346 struct ice_pf *pf = vsi->back; 1347 struct ice_tx_ring *tx_ring; 1348 struct ice_rx_ring *rx_ring; 1349 unsigned int j; 1350 int i = 0; 1351 char *p; 1352 1353 ice_update_pf_stats(pf); 1354 ice_update_vsi_stats(vsi); 1355 1356 for (j = 0; j < ICE_VSI_STATS_LEN; j++) { 1357 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset; 1358 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat == 1359 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1360 } 1361 1362 if (ice_is_port_repr_netdev(netdev)) 1363 return; 1364 1365 /* populate per queue stats */ 1366 rcu_read_lock(); 1367 1368 ice_for_each_alloc_txq(vsi, j) { 1369 tx_ring = READ_ONCE(vsi->tx_rings[j]); 1370 if (tx_ring) { 1371 data[i++] = tx_ring->stats.pkts; 1372 data[i++] = tx_ring->stats.bytes; 1373 } else { 1374 data[i++] = 0; 1375 data[i++] = 0; 1376 } 1377 } 1378 1379 ice_for_each_alloc_rxq(vsi, j) { 1380 rx_ring = READ_ONCE(vsi->rx_rings[j]); 1381 if (rx_ring) { 1382 data[i++] = rx_ring->stats.pkts; 1383 data[i++] = rx_ring->stats.bytes; 1384 } else { 1385 data[i++] = 0; 1386 data[i++] = 0; 1387 } 1388 } 1389 1390 rcu_read_unlock(); 1391 1392 if (vsi->type != ICE_VSI_PF) 1393 return; 1394 1395 for (j = 0; j < ICE_PF_STATS_LEN; j++) { 1396 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset; 1397 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat == 1398 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1399 } 1400 1401 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) { 1402 data[i++] = pf->stats.priority_xon_tx[j]; 1403 data[i++] = pf->stats.priority_xoff_tx[j]; 1404 } 1405 1406 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) { 1407 data[i++] = pf->stats.priority_xon_rx[j]; 1408 data[i++] = pf->stats.priority_xoff_rx[j]; 1409 } 1410 } 1411 1412 static void 1413 ice_get_ethtool_stats(struct net_device *netdev, 1414 struct ethtool_stats __always_unused *stats, u64 *data) 1415 { 1416 struct ice_netdev_priv *np = netdev_priv(netdev); 1417 1418 __ice_get_ethtool_stats(netdev, stats, data, np->vsi); 1419 } 1420 1421 #define ICE_PHY_TYPE_LOW_MASK_MIN_1G (ICE_PHY_TYPE_LOW_100BASE_TX | \ 1422 ICE_PHY_TYPE_LOW_100M_SGMII) 1423 1424 #define ICE_PHY_TYPE_LOW_MASK_MIN_25G (ICE_PHY_TYPE_LOW_MASK_MIN_1G | \ 1425 ICE_PHY_TYPE_LOW_1000BASE_T | \ 1426 ICE_PHY_TYPE_LOW_1000BASE_SX | \ 1427 ICE_PHY_TYPE_LOW_1000BASE_LX | \ 1428 ICE_PHY_TYPE_LOW_1000BASE_KX | \ 1429 ICE_PHY_TYPE_LOW_1G_SGMII | \ 1430 ICE_PHY_TYPE_LOW_2500BASE_T | \ 1431 ICE_PHY_TYPE_LOW_2500BASE_X | \ 1432 ICE_PHY_TYPE_LOW_2500BASE_KX | \ 1433 ICE_PHY_TYPE_LOW_5GBASE_T | \ 1434 ICE_PHY_TYPE_LOW_5GBASE_KR | \ 1435 ICE_PHY_TYPE_LOW_10GBASE_T | \ 1436 ICE_PHY_TYPE_LOW_10G_SFI_DA | \ 1437 ICE_PHY_TYPE_LOW_10GBASE_SR | \ 1438 ICE_PHY_TYPE_LOW_10GBASE_LR | \ 1439 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \ 1440 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \ 1441 ICE_PHY_TYPE_LOW_10G_SFI_C2C) 1442 1443 #define ICE_PHY_TYPE_LOW_MASK_100G (ICE_PHY_TYPE_LOW_100GBASE_CR4 | \ 1444 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \ 1445 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \ 1446 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \ 1447 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \ 1448 ICE_PHY_TYPE_LOW_100G_CAUI4 | \ 1449 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \ 1450 ICE_PHY_TYPE_LOW_100G_AUI4 | \ 1451 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \ 1452 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \ 1453 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \ 1454 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \ 1455 ICE_PHY_TYPE_LOW_100GBASE_DR) 1456 1457 #define ICE_PHY_TYPE_HIGH_MASK_100G (ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \ 1458 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\ 1459 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \ 1460 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \ 1461 ICE_PHY_TYPE_HIGH_100G_AUI2) 1462 1463 /** 1464 * ice_mask_min_supported_speeds 1465 * @phy_types_high: PHY type high 1466 * @phy_types_low: PHY type low to apply minimum supported speeds mask 1467 * 1468 * Apply minimum supported speeds mask to PHY type low. These are the speeds 1469 * for ethtool supported link mode. 1470 */ 1471 static 1472 void ice_mask_min_supported_speeds(u64 phy_types_high, u64 *phy_types_low) 1473 { 1474 /* if QSFP connection with 100G speed, minimum supported speed is 25G */ 1475 if (*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G || 1476 phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G) 1477 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G; 1478 else 1479 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G; 1480 } 1481 1482 #define ice_ethtool_advertise_link_mode(aq_link_speed, ethtool_link_mode) \ 1483 do { \ 1484 if (req_speeds & (aq_link_speed) || \ 1485 (!req_speeds && \ 1486 (advert_phy_type_lo & phy_type_mask_lo || \ 1487 advert_phy_type_hi & phy_type_mask_hi))) \ 1488 ethtool_link_ksettings_add_link_mode(ks, advertising,\ 1489 ethtool_link_mode); \ 1490 } while (0) 1491 1492 /** 1493 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes 1494 * @netdev: network interface device structure 1495 * @ks: ethtool link ksettings struct to fill out 1496 */ 1497 static void 1498 ice_phy_type_to_ethtool(struct net_device *netdev, 1499 struct ethtool_link_ksettings *ks) 1500 { 1501 struct ice_netdev_priv *np = netdev_priv(netdev); 1502 struct ice_vsi *vsi = np->vsi; 1503 struct ice_pf *pf = vsi->back; 1504 u64 advert_phy_type_lo = 0; 1505 u64 advert_phy_type_hi = 0; 1506 u64 phy_type_mask_lo = 0; 1507 u64 phy_type_mask_hi = 0; 1508 u64 phy_types_high = 0; 1509 u64 phy_types_low = 0; 1510 u16 req_speeds; 1511 1512 req_speeds = vsi->port_info->phy.link_info.req_speeds; 1513 1514 /* Check if lenient mode is supported and enabled, or in strict mode. 1515 * 1516 * In lenient mode the Supported link modes are the PHY types without 1517 * media. The Advertising link mode is either 1. the user requested 1518 * speed, 2. the override PHY mask, or 3. the PHY types with media. 1519 * 1520 * In strict mode Supported link mode are the PHY type with media, 1521 * and Advertising link modes are the media PHY type or the speed 1522 * requested by user. 1523 */ 1524 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) { 1525 phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo); 1526 phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi); 1527 1528 ice_mask_min_supported_speeds(phy_types_high, &phy_types_low); 1529 /* determine advertised modes based on link override only 1530 * if it's supported and if the FW doesn't abstract the 1531 * driver from having to account for link overrides 1532 */ 1533 if (ice_fw_supports_link_override(&pf->hw) && 1534 !ice_fw_supports_report_dflt_cfg(&pf->hw)) { 1535 struct ice_link_default_override_tlv *ldo; 1536 1537 ldo = &pf->link_dflt_override; 1538 /* If override enabled and PHY mask set, then 1539 * Advertising link mode is the intersection of the PHY 1540 * types without media and the override PHY mask. 1541 */ 1542 if (ldo->options & ICE_LINK_OVERRIDE_EN && 1543 (ldo->phy_type_low || ldo->phy_type_high)) { 1544 advert_phy_type_lo = 1545 le64_to_cpu(pf->nvm_phy_type_lo) & 1546 ldo->phy_type_low; 1547 advert_phy_type_hi = 1548 le64_to_cpu(pf->nvm_phy_type_hi) & 1549 ldo->phy_type_high; 1550 } 1551 } 1552 } else { 1553 /* strict mode */ 1554 phy_types_low = vsi->port_info->phy.phy_type_low; 1555 phy_types_high = vsi->port_info->phy.phy_type_high; 1556 } 1557 1558 /* If Advertising link mode PHY type is not using override PHY type, 1559 * then use PHY type with media. 1560 */ 1561 if (!advert_phy_type_lo && !advert_phy_type_hi) { 1562 advert_phy_type_lo = vsi->port_info->phy.phy_type_low; 1563 advert_phy_type_hi = vsi->port_info->phy.phy_type_high; 1564 } 1565 1566 ethtool_link_ksettings_zero_link_mode(ks, supported); 1567 ethtool_link_ksettings_zero_link_mode(ks, advertising); 1568 1569 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100BASE_TX | 1570 ICE_PHY_TYPE_LOW_100M_SGMII; 1571 if (phy_types_low & phy_type_mask_lo) { 1572 ethtool_link_ksettings_add_link_mode(ks, supported, 1573 100baseT_Full); 1574 1575 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100MB, 1576 100baseT_Full); 1577 } 1578 1579 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_T | 1580 ICE_PHY_TYPE_LOW_1G_SGMII; 1581 if (phy_types_low & phy_type_mask_lo) { 1582 ethtool_link_ksettings_add_link_mode(ks, supported, 1583 1000baseT_Full); 1584 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB, 1585 1000baseT_Full); 1586 } 1587 1588 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_KX; 1589 if (phy_types_low & phy_type_mask_lo) { 1590 ethtool_link_ksettings_add_link_mode(ks, supported, 1591 1000baseKX_Full); 1592 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB, 1593 1000baseKX_Full); 1594 } 1595 1596 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_SX | 1597 ICE_PHY_TYPE_LOW_1000BASE_LX; 1598 if (phy_types_low & phy_type_mask_lo) { 1599 ethtool_link_ksettings_add_link_mode(ks, supported, 1600 1000baseX_Full); 1601 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB, 1602 1000baseX_Full); 1603 } 1604 1605 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_T; 1606 if (phy_types_low & phy_type_mask_lo) { 1607 ethtool_link_ksettings_add_link_mode(ks, supported, 1608 2500baseT_Full); 1609 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_2500MB, 1610 2500baseT_Full); 1611 } 1612 1613 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_X | 1614 ICE_PHY_TYPE_LOW_2500BASE_KX; 1615 if (phy_types_low & phy_type_mask_lo) { 1616 ethtool_link_ksettings_add_link_mode(ks, supported, 1617 2500baseX_Full); 1618 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_2500MB, 1619 2500baseX_Full); 1620 } 1621 1622 phy_type_mask_lo = ICE_PHY_TYPE_LOW_5GBASE_T | 1623 ICE_PHY_TYPE_LOW_5GBASE_KR; 1624 if (phy_types_low & phy_type_mask_lo) { 1625 ethtool_link_ksettings_add_link_mode(ks, supported, 1626 5000baseT_Full); 1627 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_5GB, 1628 5000baseT_Full); 1629 } 1630 1631 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_T | 1632 ICE_PHY_TYPE_LOW_10G_SFI_DA | 1633 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | 1634 ICE_PHY_TYPE_LOW_10G_SFI_C2C; 1635 if (phy_types_low & phy_type_mask_lo) { 1636 ethtool_link_ksettings_add_link_mode(ks, supported, 1637 10000baseT_Full); 1638 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB, 1639 10000baseT_Full); 1640 } 1641 1642 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_KR_CR1; 1643 if (phy_types_low & phy_type_mask_lo) { 1644 ethtool_link_ksettings_add_link_mode(ks, supported, 1645 10000baseKR_Full); 1646 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB, 1647 10000baseKR_Full); 1648 } 1649 1650 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_SR; 1651 if (phy_types_low & phy_type_mask_lo) { 1652 ethtool_link_ksettings_add_link_mode(ks, supported, 1653 10000baseSR_Full); 1654 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB, 1655 10000baseSR_Full); 1656 } 1657 1658 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_LR; 1659 if (phy_types_low & phy_type_mask_lo) { 1660 ethtool_link_ksettings_add_link_mode(ks, supported, 1661 10000baseLR_Full); 1662 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB, 1663 10000baseLR_Full); 1664 } 1665 1666 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_T | 1667 ICE_PHY_TYPE_LOW_25GBASE_CR | 1668 ICE_PHY_TYPE_LOW_25GBASE_CR_S | 1669 ICE_PHY_TYPE_LOW_25GBASE_CR1 | 1670 ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC | 1671 ICE_PHY_TYPE_LOW_25G_AUI_C2C; 1672 if (phy_types_low & phy_type_mask_lo) { 1673 ethtool_link_ksettings_add_link_mode(ks, supported, 1674 25000baseCR_Full); 1675 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB, 1676 25000baseCR_Full); 1677 } 1678 1679 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_SR | 1680 ICE_PHY_TYPE_LOW_25GBASE_LR; 1681 if (phy_types_low & phy_type_mask_lo) { 1682 ethtool_link_ksettings_add_link_mode(ks, supported, 1683 25000baseSR_Full); 1684 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB, 1685 25000baseSR_Full); 1686 } 1687 1688 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_KR | 1689 ICE_PHY_TYPE_LOW_25GBASE_KR_S | 1690 ICE_PHY_TYPE_LOW_25GBASE_KR1; 1691 if (phy_types_low & phy_type_mask_lo) { 1692 ethtool_link_ksettings_add_link_mode(ks, supported, 1693 25000baseKR_Full); 1694 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB, 1695 25000baseKR_Full); 1696 } 1697 1698 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_KR4; 1699 if (phy_types_low & phy_type_mask_lo) { 1700 ethtool_link_ksettings_add_link_mode(ks, supported, 1701 40000baseKR4_Full); 1702 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB, 1703 40000baseKR4_Full); 1704 } 1705 1706 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_CR4 | 1707 ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC | 1708 ICE_PHY_TYPE_LOW_40G_XLAUI; 1709 if (phy_types_low & phy_type_mask_lo) { 1710 ethtool_link_ksettings_add_link_mode(ks, supported, 1711 40000baseCR4_Full); 1712 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB, 1713 40000baseCR4_Full); 1714 } 1715 1716 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_SR4; 1717 if (phy_types_low & phy_type_mask_lo) { 1718 ethtool_link_ksettings_add_link_mode(ks, supported, 1719 40000baseSR4_Full); 1720 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB, 1721 40000baseSR4_Full); 1722 } 1723 1724 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_LR4; 1725 if (phy_types_low & phy_type_mask_lo) { 1726 ethtool_link_ksettings_add_link_mode(ks, supported, 1727 40000baseLR4_Full); 1728 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB, 1729 40000baseLR4_Full); 1730 } 1731 1732 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_CR2 | 1733 ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC | 1734 ICE_PHY_TYPE_LOW_50G_LAUI2 | 1735 ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC | 1736 ICE_PHY_TYPE_LOW_50G_AUI2 | 1737 ICE_PHY_TYPE_LOW_50GBASE_CP | 1738 ICE_PHY_TYPE_LOW_50GBASE_SR | 1739 ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC | 1740 ICE_PHY_TYPE_LOW_50G_AUI1; 1741 if (phy_types_low & phy_type_mask_lo) { 1742 ethtool_link_ksettings_add_link_mode(ks, supported, 1743 50000baseCR2_Full); 1744 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB, 1745 50000baseCR2_Full); 1746 } 1747 1748 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_KR2 | 1749 ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4; 1750 if (phy_types_low & phy_type_mask_lo) { 1751 ethtool_link_ksettings_add_link_mode(ks, supported, 1752 50000baseKR2_Full); 1753 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB, 1754 50000baseKR2_Full); 1755 } 1756 1757 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_SR2 | 1758 ICE_PHY_TYPE_LOW_50GBASE_LR2 | 1759 ICE_PHY_TYPE_LOW_50GBASE_FR | 1760 ICE_PHY_TYPE_LOW_50GBASE_LR; 1761 if (phy_types_low & phy_type_mask_lo) { 1762 ethtool_link_ksettings_add_link_mode(ks, supported, 1763 50000baseSR2_Full); 1764 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB, 1765 50000baseSR2_Full); 1766 } 1767 1768 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_CR4 | 1769 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | 1770 ICE_PHY_TYPE_LOW_100G_CAUI4 | 1771 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | 1772 ICE_PHY_TYPE_LOW_100G_AUI4 | 1773 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | 1774 ICE_PHY_TYPE_LOW_100GBASE_CP2; 1775 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC | 1776 ICE_PHY_TYPE_HIGH_100G_CAUI2 | 1777 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | 1778 ICE_PHY_TYPE_HIGH_100G_AUI2; 1779 if (phy_types_low & phy_type_mask_lo || 1780 phy_types_high & phy_type_mask_hi) { 1781 ethtool_link_ksettings_add_link_mode(ks, supported, 1782 100000baseCR4_Full); 1783 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB, 1784 100000baseCR4_Full); 1785 } 1786 1787 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_SR4 | 1788 ICE_PHY_TYPE_LOW_100GBASE_SR2; 1789 if (phy_types_low & phy_type_mask_lo) { 1790 ethtool_link_ksettings_add_link_mode(ks, supported, 1791 100000baseSR4_Full); 1792 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB, 1793 100000baseSR4_Full); 1794 } 1795 1796 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_LR4 | 1797 ICE_PHY_TYPE_LOW_100GBASE_DR; 1798 if (phy_types_low & phy_type_mask_lo) { 1799 ethtool_link_ksettings_add_link_mode(ks, supported, 1800 100000baseLR4_ER4_Full); 1801 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB, 1802 100000baseLR4_ER4_Full); 1803 } 1804 1805 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_KR4 | 1806 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4; 1807 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4; 1808 if (phy_types_low & phy_type_mask_lo || 1809 phy_types_high & phy_type_mask_hi) { 1810 ethtool_link_ksettings_add_link_mode(ks, supported, 1811 100000baseKR4_Full); 1812 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB, 1813 100000baseKR4_Full); 1814 } 1815 } 1816 1817 #define TEST_SET_BITS_TIMEOUT 50 1818 #define TEST_SET_BITS_SLEEP_MAX 2000 1819 #define TEST_SET_BITS_SLEEP_MIN 1000 1820 1821 /** 1822 * ice_get_settings_link_up - Get Link settings for when link is up 1823 * @ks: ethtool ksettings to fill in 1824 * @netdev: network interface device structure 1825 */ 1826 static void 1827 ice_get_settings_link_up(struct ethtool_link_ksettings *ks, 1828 struct net_device *netdev) 1829 { 1830 struct ice_netdev_priv *np = netdev_priv(netdev); 1831 struct ice_port_info *pi = np->vsi->port_info; 1832 struct ice_link_status *link_info; 1833 struct ice_vsi *vsi = np->vsi; 1834 1835 link_info = &vsi->port_info->phy.link_info; 1836 1837 /* Get supported and advertised settings from PHY ability with media */ 1838 ice_phy_type_to_ethtool(netdev, ks); 1839 1840 switch (link_info->link_speed) { 1841 case ICE_AQ_LINK_SPEED_100GB: 1842 ks->base.speed = SPEED_100000; 1843 break; 1844 case ICE_AQ_LINK_SPEED_50GB: 1845 ks->base.speed = SPEED_50000; 1846 break; 1847 case ICE_AQ_LINK_SPEED_40GB: 1848 ks->base.speed = SPEED_40000; 1849 break; 1850 case ICE_AQ_LINK_SPEED_25GB: 1851 ks->base.speed = SPEED_25000; 1852 break; 1853 case ICE_AQ_LINK_SPEED_20GB: 1854 ks->base.speed = SPEED_20000; 1855 break; 1856 case ICE_AQ_LINK_SPEED_10GB: 1857 ks->base.speed = SPEED_10000; 1858 break; 1859 case ICE_AQ_LINK_SPEED_5GB: 1860 ks->base.speed = SPEED_5000; 1861 break; 1862 case ICE_AQ_LINK_SPEED_2500MB: 1863 ks->base.speed = SPEED_2500; 1864 break; 1865 case ICE_AQ_LINK_SPEED_1000MB: 1866 ks->base.speed = SPEED_1000; 1867 break; 1868 case ICE_AQ_LINK_SPEED_100MB: 1869 ks->base.speed = SPEED_100; 1870 break; 1871 default: 1872 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n", 1873 link_info->link_speed); 1874 break; 1875 } 1876 ks->base.duplex = DUPLEX_FULL; 1877 1878 if (link_info->an_info & ICE_AQ_AN_COMPLETED) 1879 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, 1880 Autoneg); 1881 1882 /* Set flow control negotiated Rx/Tx pause */ 1883 switch (pi->fc.current_mode) { 1884 case ICE_FC_FULL: 1885 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause); 1886 break; 1887 case ICE_FC_TX_PAUSE: 1888 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause); 1889 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, 1890 Asym_Pause); 1891 break; 1892 case ICE_FC_RX_PAUSE: 1893 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, 1894 Asym_Pause); 1895 break; 1896 case ICE_FC_PFC: 1897 default: 1898 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause); 1899 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, 1900 Asym_Pause); 1901 break; 1902 } 1903 } 1904 1905 /** 1906 * ice_get_settings_link_down - Get the Link settings when link is down 1907 * @ks: ethtool ksettings to fill in 1908 * @netdev: network interface device structure 1909 * 1910 * Reports link settings that can be determined when link is down 1911 */ 1912 static void 1913 ice_get_settings_link_down(struct ethtool_link_ksettings *ks, 1914 struct net_device *netdev) 1915 { 1916 /* link is down and the driver needs to fall back on 1917 * supported PHY types to figure out what info to display 1918 */ 1919 ice_phy_type_to_ethtool(netdev, ks); 1920 1921 /* With no link, speed and duplex are unknown */ 1922 ks->base.speed = SPEED_UNKNOWN; 1923 ks->base.duplex = DUPLEX_UNKNOWN; 1924 } 1925 1926 /** 1927 * ice_get_link_ksettings - Get Link Speed and Duplex settings 1928 * @netdev: network interface device structure 1929 * @ks: ethtool ksettings 1930 * 1931 * Reports speed/duplex settings based on media_type 1932 */ 1933 static int 1934 ice_get_link_ksettings(struct net_device *netdev, 1935 struct ethtool_link_ksettings *ks) 1936 { 1937 struct ice_netdev_priv *np = netdev_priv(netdev); 1938 struct ice_aqc_get_phy_caps_data *caps; 1939 struct ice_link_status *hw_link_info; 1940 struct ice_vsi *vsi = np->vsi; 1941 enum ice_status status; 1942 int err = 0; 1943 1944 ethtool_link_ksettings_zero_link_mode(ks, supported); 1945 ethtool_link_ksettings_zero_link_mode(ks, advertising); 1946 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising); 1947 hw_link_info = &vsi->port_info->phy.link_info; 1948 1949 /* set speed and duplex */ 1950 if (hw_link_info->link_info & ICE_AQ_LINK_UP) 1951 ice_get_settings_link_up(ks, netdev); 1952 else 1953 ice_get_settings_link_down(ks, netdev); 1954 1955 /* set autoneg settings */ 1956 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ? 1957 AUTONEG_ENABLE : AUTONEG_DISABLE; 1958 1959 /* set media type settings */ 1960 switch (vsi->port_info->phy.media_type) { 1961 case ICE_MEDIA_FIBER: 1962 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 1963 ks->base.port = PORT_FIBRE; 1964 break; 1965 case ICE_MEDIA_BASET: 1966 ethtool_link_ksettings_add_link_mode(ks, supported, TP); 1967 ethtool_link_ksettings_add_link_mode(ks, advertising, TP); 1968 ks->base.port = PORT_TP; 1969 break; 1970 case ICE_MEDIA_BACKPLANE: 1971 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane); 1972 ethtool_link_ksettings_add_link_mode(ks, advertising, 1973 Backplane); 1974 ks->base.port = PORT_NONE; 1975 break; 1976 case ICE_MEDIA_DA: 1977 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE); 1978 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE); 1979 ks->base.port = PORT_DA; 1980 break; 1981 default: 1982 ks->base.port = PORT_OTHER; 1983 break; 1984 } 1985 1986 /* flow control is symmetric and always supported */ 1987 ethtool_link_ksettings_add_link_mode(ks, supported, Pause); 1988 1989 caps = kzalloc(sizeof(*caps), GFP_KERNEL); 1990 if (!caps) 1991 return -ENOMEM; 1992 1993 status = ice_aq_get_phy_caps(vsi->port_info, false, 1994 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL); 1995 if (status) { 1996 err = -EIO; 1997 goto done; 1998 } 1999 2000 /* Set the advertised flow control based on the PHY capability */ 2001 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) && 2002 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) { 2003 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 2004 ethtool_link_ksettings_add_link_mode(ks, advertising, 2005 Asym_Pause); 2006 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) { 2007 ethtool_link_ksettings_add_link_mode(ks, advertising, 2008 Asym_Pause); 2009 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) { 2010 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause); 2011 ethtool_link_ksettings_add_link_mode(ks, advertising, 2012 Asym_Pause); 2013 } else { 2014 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause); 2015 ethtool_link_ksettings_del_link_mode(ks, advertising, 2016 Asym_Pause); 2017 } 2018 2019 /* Set advertised FEC modes based on PHY capability */ 2020 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE); 2021 2022 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ || 2023 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ) 2024 ethtool_link_ksettings_add_link_mode(ks, advertising, 2025 FEC_BASER); 2026 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ || 2027 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ) 2028 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS); 2029 2030 status = ice_aq_get_phy_caps(vsi->port_info, false, 2031 ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL); 2032 if (status) { 2033 err = -EIO; 2034 goto done; 2035 } 2036 2037 /* Set supported FEC modes based on PHY capability */ 2038 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE); 2039 2040 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN || 2041 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN) 2042 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER); 2043 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN) 2044 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS); 2045 2046 /* Set supported and advertised autoneg */ 2047 if (ice_is_phy_caps_an_enabled(caps)) { 2048 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg); 2049 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg); 2050 } 2051 2052 done: 2053 kfree(caps); 2054 return err; 2055 } 2056 2057 /** 2058 * ice_ksettings_find_adv_link_speed - Find advertising link speed 2059 * @ks: ethtool ksettings 2060 */ 2061 static u16 2062 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks) 2063 { 2064 u16 adv_link_speed = 0; 2065 2066 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2067 100baseT_Full)) 2068 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB; 2069 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2070 1000baseX_Full)) 2071 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB; 2072 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2073 1000baseT_Full) || 2074 ethtool_link_ksettings_test_link_mode(ks, advertising, 2075 1000baseKX_Full)) 2076 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB; 2077 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2078 2500baseT_Full)) 2079 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB; 2080 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2081 2500baseX_Full)) 2082 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB; 2083 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2084 5000baseT_Full)) 2085 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB; 2086 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2087 10000baseT_Full) || 2088 ethtool_link_ksettings_test_link_mode(ks, advertising, 2089 10000baseKR_Full)) 2090 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB; 2091 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2092 10000baseSR_Full) || 2093 ethtool_link_ksettings_test_link_mode(ks, advertising, 2094 10000baseLR_Full)) 2095 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB; 2096 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2097 25000baseCR_Full) || 2098 ethtool_link_ksettings_test_link_mode(ks, advertising, 2099 25000baseSR_Full) || 2100 ethtool_link_ksettings_test_link_mode(ks, advertising, 2101 25000baseKR_Full)) 2102 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB; 2103 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2104 40000baseCR4_Full) || 2105 ethtool_link_ksettings_test_link_mode(ks, advertising, 2106 40000baseSR4_Full) || 2107 ethtool_link_ksettings_test_link_mode(ks, advertising, 2108 40000baseLR4_Full) || 2109 ethtool_link_ksettings_test_link_mode(ks, advertising, 2110 40000baseKR4_Full)) 2111 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB; 2112 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2113 50000baseCR2_Full) || 2114 ethtool_link_ksettings_test_link_mode(ks, advertising, 2115 50000baseKR2_Full)) 2116 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB; 2117 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2118 50000baseSR2_Full)) 2119 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB; 2120 if (ethtool_link_ksettings_test_link_mode(ks, advertising, 2121 100000baseCR4_Full) || 2122 ethtool_link_ksettings_test_link_mode(ks, advertising, 2123 100000baseSR4_Full) || 2124 ethtool_link_ksettings_test_link_mode(ks, advertising, 2125 100000baseLR4_ER4_Full) || 2126 ethtool_link_ksettings_test_link_mode(ks, advertising, 2127 100000baseKR4_Full)) 2128 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB; 2129 2130 return adv_link_speed; 2131 } 2132 2133 /** 2134 * ice_setup_autoneg 2135 * @p: port info 2136 * @ks: ethtool_link_ksettings 2137 * @config: configuration that will be sent down to FW 2138 * @autoneg_enabled: autonegotiation is enabled or not 2139 * @autoneg_changed: will there a change in autonegotiation 2140 * @netdev: network interface device structure 2141 * 2142 * Setup PHY autonegotiation feature 2143 */ 2144 static int 2145 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks, 2146 struct ice_aqc_set_phy_cfg_data *config, 2147 u8 autoneg_enabled, u8 *autoneg_changed, 2148 struct net_device *netdev) 2149 { 2150 int err = 0; 2151 2152 *autoneg_changed = 0; 2153 2154 /* Check autoneg */ 2155 if (autoneg_enabled == AUTONEG_ENABLE) { 2156 /* If autoneg was not already enabled */ 2157 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) { 2158 /* If autoneg is not supported, return error */ 2159 if (!ethtool_link_ksettings_test_link_mode(ks, 2160 supported, 2161 Autoneg)) { 2162 netdev_info(netdev, "Autoneg not supported on this phy.\n"); 2163 err = -EINVAL; 2164 } else { 2165 /* Autoneg is allowed to change */ 2166 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 2167 *autoneg_changed = 1; 2168 } 2169 } 2170 } else { 2171 /* If autoneg is currently enabled */ 2172 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) { 2173 /* If autoneg is supported 10GBASE_T is the only PHY 2174 * that can disable it, so otherwise return error 2175 */ 2176 if (ethtool_link_ksettings_test_link_mode(ks, 2177 supported, 2178 Autoneg)) { 2179 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); 2180 err = -EINVAL; 2181 } else { 2182 /* Autoneg is allowed to change */ 2183 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 2184 *autoneg_changed = 1; 2185 } 2186 } 2187 } 2188 2189 return err; 2190 } 2191 2192 /** 2193 * ice_set_link_ksettings - Set Speed and Duplex 2194 * @netdev: network interface device structure 2195 * @ks: ethtool ksettings 2196 * 2197 * Set speed/duplex per media_types advertised/forced 2198 */ 2199 static int 2200 ice_set_link_ksettings(struct net_device *netdev, 2201 const struct ethtool_link_ksettings *ks) 2202 { 2203 struct ice_netdev_priv *np = netdev_priv(netdev); 2204 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT; 2205 struct ethtool_link_ksettings copy_ks = *ks; 2206 struct ethtool_link_ksettings safe_ks = {}; 2207 struct ice_aqc_get_phy_caps_data *phy_caps; 2208 struct ice_aqc_set_phy_cfg_data config; 2209 u16 adv_link_speed, curr_link_speed; 2210 struct ice_pf *pf = np->vsi->back; 2211 struct ice_port_info *pi; 2212 u8 autoneg_changed = 0; 2213 enum ice_status status; 2214 u64 phy_type_high = 0; 2215 u64 phy_type_low = 0; 2216 int err = 0; 2217 bool linkup; 2218 2219 pi = np->vsi->port_info; 2220 2221 if (!pi) 2222 return -EIO; 2223 2224 if (pi->phy.media_type != ICE_MEDIA_BASET && 2225 pi->phy.media_type != ICE_MEDIA_FIBER && 2226 pi->phy.media_type != ICE_MEDIA_BACKPLANE && 2227 pi->phy.media_type != ICE_MEDIA_DA && 2228 pi->phy.link_info.link_info & ICE_AQ_LINK_UP) 2229 return -EOPNOTSUPP; 2230 2231 phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL); 2232 if (!phy_caps) 2233 return -ENOMEM; 2234 2235 /* Get the PHY capabilities based on media */ 2236 if (ice_fw_supports_report_dflt_cfg(pi->hw)) 2237 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG, 2238 phy_caps, NULL); 2239 else 2240 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, 2241 phy_caps, NULL); 2242 if (status) { 2243 err = -EIO; 2244 goto done; 2245 } 2246 2247 /* save autoneg out of ksettings */ 2248 autoneg = copy_ks.base.autoneg; 2249 2250 /* Get link modes supported by hardware.*/ 2251 ice_phy_type_to_ethtool(netdev, &safe_ks); 2252 2253 /* and check against modes requested by user. 2254 * Return an error if unsupported mode was set. 2255 */ 2256 if (!bitmap_subset(copy_ks.link_modes.advertising, 2257 safe_ks.link_modes.supported, 2258 __ETHTOOL_LINK_MODE_MASK_NBITS)) { 2259 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) 2260 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n"); 2261 err = -EOPNOTSUPP; 2262 goto done; 2263 } 2264 2265 /* get our own copy of the bits to check against */ 2266 memset(&safe_ks, 0, sizeof(safe_ks)); 2267 safe_ks.base.cmd = copy_ks.base.cmd; 2268 safe_ks.base.link_mode_masks_nwords = 2269 copy_ks.base.link_mode_masks_nwords; 2270 ice_get_link_ksettings(netdev, &safe_ks); 2271 2272 /* set autoneg back to what it currently is */ 2273 copy_ks.base.autoneg = safe_ks.base.autoneg; 2274 /* we don't compare the speed */ 2275 copy_ks.base.speed = safe_ks.base.speed; 2276 2277 /* If copy_ks.base and safe_ks.base are not the same now, then they are 2278 * trying to set something that we do not support. 2279 */ 2280 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) { 2281 err = -EOPNOTSUPP; 2282 goto done; 2283 } 2284 2285 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) { 2286 timeout--; 2287 if (!timeout) { 2288 err = -EBUSY; 2289 goto done; 2290 } 2291 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX); 2292 } 2293 2294 /* Copy the current user PHY configuration. The current user PHY 2295 * configuration is initialized during probe from PHY capabilities 2296 * software mode, and updated on set PHY configuration. 2297 */ 2298 config = pi->phy.curr_user_phy_cfg; 2299 2300 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 2301 2302 /* Check autoneg */ 2303 err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed, 2304 netdev); 2305 2306 if (err) 2307 goto done; 2308 2309 /* Call to get the current link speed */ 2310 pi->phy.get_link_info = true; 2311 status = ice_get_link_status(pi, &linkup); 2312 if (status) { 2313 err = -EIO; 2314 goto done; 2315 } 2316 2317 curr_link_speed = pi->phy.link_info.link_speed; 2318 adv_link_speed = ice_ksettings_find_adv_link_speed(ks); 2319 2320 /* If speed didn't get set, set it to what it currently is. 2321 * This is needed because if advertise is 0 (as it is when autoneg 2322 * is disabled) then speed won't get set. 2323 */ 2324 if (!adv_link_speed) 2325 adv_link_speed = curr_link_speed; 2326 2327 /* Convert the advertise link speeds to their corresponded PHY_TYPE */ 2328 ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed); 2329 2330 if (!autoneg_changed && adv_link_speed == curr_link_speed) { 2331 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); 2332 goto done; 2333 } 2334 2335 /* save the requested speeds */ 2336 pi->phy.link_info.req_speeds = adv_link_speed; 2337 2338 /* set link and auto negotiation so changes take effect */ 2339 config.caps |= ICE_AQ_PHY_ENA_LINK; 2340 2341 /* check if there is a PHY type for the requested advertised speed */ 2342 if (!(phy_type_low || phy_type_high)) { 2343 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n"); 2344 err = -EOPNOTSUPP; 2345 goto done; 2346 } 2347 2348 /* intersect requested advertised speed PHY types with media PHY types 2349 * for set PHY configuration 2350 */ 2351 config.phy_type_high = cpu_to_le64(phy_type_high) & 2352 phy_caps->phy_type_high; 2353 config.phy_type_low = cpu_to_le64(phy_type_low) & 2354 phy_caps->phy_type_low; 2355 2356 if (!(config.phy_type_high || config.phy_type_low)) { 2357 /* If there is no intersection and lenient mode is enabled, then 2358 * intersect the requested advertised speed with NVM media type 2359 * PHY types. 2360 */ 2361 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) { 2362 config.phy_type_high = cpu_to_le64(phy_type_high) & 2363 pf->nvm_phy_type_hi; 2364 config.phy_type_low = cpu_to_le64(phy_type_low) & 2365 pf->nvm_phy_type_lo; 2366 } else { 2367 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n"); 2368 err = -EOPNOTSUPP; 2369 goto done; 2370 } 2371 } 2372 2373 /* If link is up put link down */ 2374 if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) { 2375 /* Tell the OS link is going down, the link will go 2376 * back up when fw says it is ready asynchronously 2377 */ 2378 ice_print_link_msg(np->vsi, false); 2379 netif_carrier_off(netdev); 2380 netif_tx_stop_all_queues(netdev); 2381 } 2382 2383 /* make the aq call */ 2384 status = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL); 2385 if (status) { 2386 netdev_info(netdev, "Set phy config failed,\n"); 2387 err = -EIO; 2388 goto done; 2389 } 2390 2391 /* Save speed request */ 2392 pi->phy.curr_user_speed_req = adv_link_speed; 2393 done: 2394 kfree(phy_caps); 2395 clear_bit(ICE_CFG_BUSY, pf->state); 2396 2397 return err; 2398 } 2399 2400 /** 2401 * ice_parse_hdrs - parses headers from RSS hash input 2402 * @nfc: ethtool rxnfc command 2403 * 2404 * This function parses the rxnfc command and returns intended 2405 * header types for RSS configuration 2406 */ 2407 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc) 2408 { 2409 u32 hdrs = ICE_FLOW_SEG_HDR_NONE; 2410 2411 switch (nfc->flow_type) { 2412 case TCP_V4_FLOW: 2413 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4; 2414 break; 2415 case UDP_V4_FLOW: 2416 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4; 2417 break; 2418 case SCTP_V4_FLOW: 2419 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4; 2420 break; 2421 case TCP_V6_FLOW: 2422 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6; 2423 break; 2424 case UDP_V6_FLOW: 2425 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6; 2426 break; 2427 case SCTP_V6_FLOW: 2428 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6; 2429 break; 2430 default: 2431 break; 2432 } 2433 return hdrs; 2434 } 2435 2436 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) 2437 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) 2438 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) 2439 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) 2440 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) 2441 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT) 2442 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) 2443 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT) 2444 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \ 2445 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) 2446 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \ 2447 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT) 2448 2449 /** 2450 * ice_parse_hash_flds - parses hash fields from RSS hash input 2451 * @nfc: ethtool rxnfc command 2452 * 2453 * This function parses the rxnfc command and returns intended 2454 * hash fields for RSS configuration 2455 */ 2456 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc) 2457 { 2458 u64 hfld = ICE_HASH_INVALID; 2459 2460 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) { 2461 switch (nfc->flow_type) { 2462 case TCP_V4_FLOW: 2463 case UDP_V4_FLOW: 2464 case SCTP_V4_FLOW: 2465 if (nfc->data & RXH_IP_SRC) 2466 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA; 2467 if (nfc->data & RXH_IP_DST) 2468 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA; 2469 break; 2470 case TCP_V6_FLOW: 2471 case UDP_V6_FLOW: 2472 case SCTP_V6_FLOW: 2473 if (nfc->data & RXH_IP_SRC) 2474 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA; 2475 if (nfc->data & RXH_IP_DST) 2476 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA; 2477 break; 2478 default: 2479 break; 2480 } 2481 } 2482 2483 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) { 2484 switch (nfc->flow_type) { 2485 case TCP_V4_FLOW: 2486 case TCP_V6_FLOW: 2487 if (nfc->data & RXH_L4_B_0_1) 2488 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT; 2489 if (nfc->data & RXH_L4_B_2_3) 2490 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT; 2491 break; 2492 case UDP_V4_FLOW: 2493 case UDP_V6_FLOW: 2494 if (nfc->data & RXH_L4_B_0_1) 2495 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT; 2496 if (nfc->data & RXH_L4_B_2_3) 2497 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT; 2498 break; 2499 case SCTP_V4_FLOW: 2500 case SCTP_V6_FLOW: 2501 if (nfc->data & RXH_L4_B_0_1) 2502 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT; 2503 if (nfc->data & RXH_L4_B_2_3) 2504 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT; 2505 break; 2506 default: 2507 break; 2508 } 2509 } 2510 2511 return hfld; 2512 } 2513 2514 /** 2515 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash 2516 * @vsi: the VSI being configured 2517 * @nfc: ethtool rxnfc command 2518 * 2519 * Returns Success if the flow input set is supported. 2520 */ 2521 static int 2522 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc) 2523 { 2524 struct ice_pf *pf = vsi->back; 2525 enum ice_status status; 2526 struct device *dev; 2527 u64 hashed_flds; 2528 u32 hdrs; 2529 2530 dev = ice_pf_to_dev(pf); 2531 if (ice_is_safe_mode(pf)) { 2532 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n", 2533 vsi->vsi_num); 2534 return -EINVAL; 2535 } 2536 2537 hashed_flds = ice_parse_hash_flds(nfc); 2538 if (hashed_flds == ICE_HASH_INVALID) { 2539 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n", 2540 vsi->vsi_num); 2541 return -EINVAL; 2542 } 2543 2544 hdrs = ice_parse_hdrs(nfc); 2545 if (hdrs == ICE_FLOW_SEG_HDR_NONE) { 2546 dev_dbg(dev, "Header type is not valid, vsi num = %d\n", 2547 vsi->vsi_num); 2548 return -EINVAL; 2549 } 2550 2551 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs); 2552 if (status) { 2553 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %s\n", 2554 vsi->vsi_num, ice_stat_str(status)); 2555 return -EINVAL; 2556 } 2557 2558 return 0; 2559 } 2560 2561 /** 2562 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type 2563 * @vsi: the VSI being configured 2564 * @nfc: ethtool rxnfc command 2565 */ 2566 static void 2567 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc) 2568 { 2569 struct ice_pf *pf = vsi->back; 2570 struct device *dev; 2571 u64 hash_flds; 2572 u32 hdrs; 2573 2574 dev = ice_pf_to_dev(pf); 2575 2576 nfc->data = 0; 2577 if (ice_is_safe_mode(pf)) { 2578 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n", 2579 vsi->vsi_num); 2580 return; 2581 } 2582 2583 hdrs = ice_parse_hdrs(nfc); 2584 if (hdrs == ICE_FLOW_SEG_HDR_NONE) { 2585 dev_dbg(dev, "Header type is not valid, vsi num = %d\n", 2586 vsi->vsi_num); 2587 return; 2588 } 2589 2590 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs); 2591 if (hash_flds == ICE_HASH_INVALID) { 2592 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n", 2593 vsi->vsi_num); 2594 return; 2595 } 2596 2597 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA || 2598 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA) 2599 nfc->data |= (u64)RXH_IP_SRC; 2600 2601 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA || 2602 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA) 2603 nfc->data |= (u64)RXH_IP_DST; 2604 2605 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT || 2606 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT || 2607 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT) 2608 nfc->data |= (u64)RXH_L4_B_0_1; 2609 2610 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT || 2611 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT || 2612 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT) 2613 nfc->data |= (u64)RXH_L4_B_2_3; 2614 } 2615 2616 /** 2617 * ice_set_rxnfc - command to set Rx flow rules. 2618 * @netdev: network interface device structure 2619 * @cmd: ethtool rxnfc command 2620 * 2621 * Returns 0 for success and negative values for errors 2622 */ 2623 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) 2624 { 2625 struct ice_netdev_priv *np = netdev_priv(netdev); 2626 struct ice_vsi *vsi = np->vsi; 2627 2628 switch (cmd->cmd) { 2629 case ETHTOOL_SRXCLSRLINS: 2630 return ice_add_fdir_ethtool(vsi, cmd); 2631 case ETHTOOL_SRXCLSRLDEL: 2632 return ice_del_fdir_ethtool(vsi, cmd); 2633 case ETHTOOL_SRXFH: 2634 return ice_set_rss_hash_opt(vsi, cmd); 2635 default: 2636 break; 2637 } 2638 return -EOPNOTSUPP; 2639 } 2640 2641 /** 2642 * ice_get_rxnfc - command to get Rx flow classification rules 2643 * @netdev: network interface device structure 2644 * @cmd: ethtool rxnfc command 2645 * @rule_locs: buffer to rturn Rx flow classification rules 2646 * 2647 * Returns Success if the command is supported. 2648 */ 2649 static int 2650 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, 2651 u32 __always_unused *rule_locs) 2652 { 2653 struct ice_netdev_priv *np = netdev_priv(netdev); 2654 struct ice_vsi *vsi = np->vsi; 2655 int ret = -EOPNOTSUPP; 2656 struct ice_hw *hw; 2657 2658 hw = &vsi->back->hw; 2659 2660 switch (cmd->cmd) { 2661 case ETHTOOL_GRXRINGS: 2662 cmd->data = vsi->rss_size; 2663 ret = 0; 2664 break; 2665 case ETHTOOL_GRXCLSRLCNT: 2666 cmd->rule_cnt = hw->fdir_active_fltr; 2667 /* report total rule count */ 2668 cmd->data = ice_get_fdir_cnt_all(hw); 2669 ret = 0; 2670 break; 2671 case ETHTOOL_GRXCLSRULE: 2672 ret = ice_get_ethtool_fdir_entry(hw, cmd); 2673 break; 2674 case ETHTOOL_GRXCLSRLALL: 2675 ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs); 2676 break; 2677 case ETHTOOL_GRXFH: 2678 ice_get_rss_hash_opt(vsi, cmd); 2679 ret = 0; 2680 break; 2681 default: 2682 break; 2683 } 2684 2685 return ret; 2686 } 2687 2688 static void 2689 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, 2690 struct kernel_ethtool_ringparam *kernel_ring, 2691 struct netlink_ext_ack *extack) 2692 { 2693 struct ice_netdev_priv *np = netdev_priv(netdev); 2694 struct ice_vsi *vsi = np->vsi; 2695 2696 ring->rx_max_pending = ICE_MAX_NUM_DESC; 2697 ring->tx_max_pending = ICE_MAX_NUM_DESC; 2698 ring->rx_pending = vsi->rx_rings[0]->count; 2699 ring->tx_pending = vsi->tx_rings[0]->count; 2700 2701 /* Rx mini and jumbo rings are not supported */ 2702 ring->rx_mini_max_pending = 0; 2703 ring->rx_jumbo_max_pending = 0; 2704 ring->rx_mini_pending = 0; 2705 ring->rx_jumbo_pending = 0; 2706 } 2707 2708 static int 2709 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring, 2710 struct kernel_ethtool_ringparam *kernel_ring, 2711 struct netlink_ext_ack *extack) 2712 { 2713 struct ice_netdev_priv *np = netdev_priv(netdev); 2714 struct ice_tx_ring *xdp_rings = NULL; 2715 struct ice_tx_ring *tx_rings = NULL; 2716 struct ice_rx_ring *rx_rings = NULL; 2717 struct ice_vsi *vsi = np->vsi; 2718 struct ice_pf *pf = vsi->back; 2719 int i, timeout = 50, err = 0; 2720 u16 new_rx_cnt, new_tx_cnt; 2721 2722 if (ring->tx_pending > ICE_MAX_NUM_DESC || 2723 ring->tx_pending < ICE_MIN_NUM_DESC || 2724 ring->rx_pending > ICE_MAX_NUM_DESC || 2725 ring->rx_pending < ICE_MIN_NUM_DESC) { 2726 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n", 2727 ring->tx_pending, ring->rx_pending, 2728 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC, 2729 ICE_REQ_DESC_MULTIPLE); 2730 return -EINVAL; 2731 } 2732 2733 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE); 2734 if (new_tx_cnt != ring->tx_pending) 2735 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n", 2736 new_tx_cnt); 2737 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE); 2738 if (new_rx_cnt != ring->rx_pending) 2739 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n", 2740 new_rx_cnt); 2741 2742 /* if nothing to do return success */ 2743 if (new_tx_cnt == vsi->tx_rings[0]->count && 2744 new_rx_cnt == vsi->rx_rings[0]->count) { 2745 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n"); 2746 return 0; 2747 } 2748 2749 /* If there is a AF_XDP UMEM attached to any of Rx rings, 2750 * disallow changing the number of descriptors -- regardless 2751 * if the netdev is running or not. 2752 */ 2753 if (ice_xsk_any_rx_ring_ena(vsi)) 2754 return -EBUSY; 2755 2756 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) { 2757 timeout--; 2758 if (!timeout) 2759 return -EBUSY; 2760 usleep_range(1000, 2000); 2761 } 2762 2763 /* set for the next time the netdev is started */ 2764 if (!netif_running(vsi->netdev)) { 2765 ice_for_each_alloc_txq(vsi, i) 2766 vsi->tx_rings[i]->count = new_tx_cnt; 2767 ice_for_each_alloc_rxq(vsi, i) 2768 vsi->rx_rings[i]->count = new_rx_cnt; 2769 if (ice_is_xdp_ena_vsi(vsi)) 2770 ice_for_each_xdp_txq(vsi, i) 2771 vsi->xdp_rings[i]->count = new_tx_cnt; 2772 vsi->num_tx_desc = (u16)new_tx_cnt; 2773 vsi->num_rx_desc = (u16)new_rx_cnt; 2774 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n"); 2775 goto done; 2776 } 2777 2778 if (new_tx_cnt == vsi->tx_rings[0]->count) 2779 goto process_rx; 2780 2781 /* alloc updated Tx resources */ 2782 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n", 2783 vsi->tx_rings[0]->count, new_tx_cnt); 2784 2785 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL); 2786 if (!tx_rings) { 2787 err = -ENOMEM; 2788 goto done; 2789 } 2790 2791 ice_for_each_txq(vsi, i) { 2792 /* clone ring and setup updated count */ 2793 tx_rings[i] = *vsi->tx_rings[i]; 2794 tx_rings[i].count = new_tx_cnt; 2795 tx_rings[i].desc = NULL; 2796 tx_rings[i].tx_buf = NULL; 2797 err = ice_setup_tx_ring(&tx_rings[i]); 2798 if (err) { 2799 while (i--) 2800 ice_clean_tx_ring(&tx_rings[i]); 2801 kfree(tx_rings); 2802 goto done; 2803 } 2804 } 2805 2806 if (!ice_is_xdp_ena_vsi(vsi)) 2807 goto process_rx; 2808 2809 /* alloc updated XDP resources */ 2810 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n", 2811 vsi->xdp_rings[0]->count, new_tx_cnt); 2812 2813 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL); 2814 if (!xdp_rings) { 2815 err = -ENOMEM; 2816 goto free_tx; 2817 } 2818 2819 ice_for_each_xdp_txq(vsi, i) { 2820 /* clone ring and setup updated count */ 2821 xdp_rings[i] = *vsi->xdp_rings[i]; 2822 xdp_rings[i].count = new_tx_cnt; 2823 xdp_rings[i].desc = NULL; 2824 xdp_rings[i].tx_buf = NULL; 2825 err = ice_setup_tx_ring(&xdp_rings[i]); 2826 if (err) { 2827 while (i--) 2828 ice_clean_tx_ring(&xdp_rings[i]); 2829 kfree(xdp_rings); 2830 goto free_tx; 2831 } 2832 ice_set_ring_xdp(&xdp_rings[i]); 2833 } 2834 2835 process_rx: 2836 if (new_rx_cnt == vsi->rx_rings[0]->count) 2837 goto process_link; 2838 2839 /* alloc updated Rx resources */ 2840 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n", 2841 vsi->rx_rings[0]->count, new_rx_cnt); 2842 2843 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL); 2844 if (!rx_rings) { 2845 err = -ENOMEM; 2846 goto done; 2847 } 2848 2849 ice_for_each_rxq(vsi, i) { 2850 /* clone ring and setup updated count */ 2851 rx_rings[i] = *vsi->rx_rings[i]; 2852 rx_rings[i].count = new_rx_cnt; 2853 rx_rings[i].desc = NULL; 2854 rx_rings[i].rx_buf = NULL; 2855 /* this is to allow wr32 to have something to write to 2856 * during early allocation of Rx buffers 2857 */ 2858 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS; 2859 2860 err = ice_setup_rx_ring(&rx_rings[i]); 2861 if (err) 2862 goto rx_unwind; 2863 2864 /* allocate Rx buffers */ 2865 err = ice_alloc_rx_bufs(&rx_rings[i], 2866 ICE_DESC_UNUSED(&rx_rings[i])); 2867 rx_unwind: 2868 if (err) { 2869 while (i) { 2870 i--; 2871 ice_free_rx_ring(&rx_rings[i]); 2872 } 2873 kfree(rx_rings); 2874 err = -ENOMEM; 2875 goto free_tx; 2876 } 2877 } 2878 2879 process_link: 2880 /* Bring interface down, copy in the new ring info, then restore the 2881 * interface. if VSI is up, bring it down and then back up 2882 */ 2883 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) { 2884 ice_down(vsi); 2885 2886 if (tx_rings) { 2887 ice_for_each_txq(vsi, i) { 2888 ice_free_tx_ring(vsi->tx_rings[i]); 2889 *vsi->tx_rings[i] = tx_rings[i]; 2890 } 2891 kfree(tx_rings); 2892 } 2893 2894 if (rx_rings) { 2895 ice_for_each_rxq(vsi, i) { 2896 ice_free_rx_ring(vsi->rx_rings[i]); 2897 /* copy the real tail offset */ 2898 rx_rings[i].tail = vsi->rx_rings[i]->tail; 2899 /* this is to fake out the allocation routine 2900 * into thinking it has to realloc everything 2901 * but the recycling logic will let us re-use 2902 * the buffers allocated above 2903 */ 2904 rx_rings[i].next_to_use = 0; 2905 rx_rings[i].next_to_clean = 0; 2906 rx_rings[i].next_to_alloc = 0; 2907 *vsi->rx_rings[i] = rx_rings[i]; 2908 } 2909 kfree(rx_rings); 2910 } 2911 2912 if (xdp_rings) { 2913 ice_for_each_xdp_txq(vsi, i) { 2914 ice_free_tx_ring(vsi->xdp_rings[i]); 2915 *vsi->xdp_rings[i] = xdp_rings[i]; 2916 } 2917 kfree(xdp_rings); 2918 } 2919 2920 vsi->num_tx_desc = new_tx_cnt; 2921 vsi->num_rx_desc = new_rx_cnt; 2922 ice_up(vsi); 2923 } 2924 goto done; 2925 2926 free_tx: 2927 /* error cleanup if the Rx allocations failed after getting Tx */ 2928 if (tx_rings) { 2929 ice_for_each_txq(vsi, i) 2930 ice_free_tx_ring(&tx_rings[i]); 2931 kfree(tx_rings); 2932 } 2933 2934 done: 2935 clear_bit(ICE_CFG_BUSY, pf->state); 2936 return err; 2937 } 2938 2939 /** 2940 * ice_get_pauseparam - Get Flow Control status 2941 * @netdev: network interface device structure 2942 * @pause: ethernet pause (flow control) parameters 2943 * 2944 * Get requested flow control status from PHY capability. 2945 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which 2946 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report 2947 * the negotiated Rx/Tx pause via lp_advertising. 2948 */ 2949 static void 2950 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) 2951 { 2952 struct ice_netdev_priv *np = netdev_priv(netdev); 2953 struct ice_port_info *pi = np->vsi->port_info; 2954 struct ice_aqc_get_phy_caps_data *pcaps; 2955 struct ice_dcbx_cfg *dcbx_cfg; 2956 enum ice_status status; 2957 2958 /* Initialize pause params */ 2959 pause->rx_pause = 0; 2960 pause->tx_pause = 0; 2961 2962 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg; 2963 2964 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 2965 if (!pcaps) 2966 return; 2967 2968 /* Get current PHY config */ 2969 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, 2970 NULL); 2971 if (status) 2972 goto out; 2973 2974 pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE : 2975 AUTONEG_DISABLE; 2976 2977 if (dcbx_cfg->pfc.pfcena) 2978 /* PFC enabled so report LFC as off */ 2979 goto out; 2980 2981 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) 2982 pause->tx_pause = 1; 2983 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) 2984 pause->rx_pause = 1; 2985 2986 out: 2987 kfree(pcaps); 2988 } 2989 2990 /** 2991 * ice_set_pauseparam - Set Flow Control parameter 2992 * @netdev: network interface device structure 2993 * @pause: return Tx/Rx flow control status 2994 */ 2995 static int 2996 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) 2997 { 2998 struct ice_netdev_priv *np = netdev_priv(netdev); 2999 struct ice_aqc_get_phy_caps_data *pcaps; 3000 struct ice_link_status *hw_link_info; 3001 struct ice_pf *pf = np->vsi->back; 3002 struct ice_dcbx_cfg *dcbx_cfg; 3003 struct ice_vsi *vsi = np->vsi; 3004 struct ice_hw *hw = &pf->hw; 3005 struct ice_port_info *pi; 3006 enum ice_status status; 3007 u8 aq_failures; 3008 bool link_up; 3009 int err = 0; 3010 u32 is_an; 3011 3012 pi = vsi->port_info; 3013 hw_link_info = &pi->phy.link_info; 3014 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg; 3015 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP; 3016 3017 /* Changing the port's flow control is not supported if this isn't the 3018 * PF VSI 3019 */ 3020 if (vsi->type != ICE_VSI_PF) { 3021 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n"); 3022 return -EOPNOTSUPP; 3023 } 3024 3025 /* Get pause param reports configured and negotiated flow control pause 3026 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is 3027 * defined get pause param pause->autoneg reports SW configured setting, 3028 * so compare pause->autoneg with SW configured to prevent the user from 3029 * using set pause param to chance autoneg. 3030 */ 3031 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 3032 if (!pcaps) 3033 return -ENOMEM; 3034 3035 /* Get current PHY config */ 3036 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, 3037 NULL); 3038 if (status) { 3039 kfree(pcaps); 3040 return -EIO; 3041 } 3042 3043 is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE : 3044 AUTONEG_DISABLE; 3045 3046 kfree(pcaps); 3047 3048 if (pause->autoneg != is_an) { 3049 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); 3050 return -EOPNOTSUPP; 3051 } 3052 3053 /* If we have link and don't have autoneg */ 3054 if (!test_bit(ICE_DOWN, pf->state) && 3055 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) { 3056 /* Send message that it might not necessarily work*/ 3057 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); 3058 } 3059 3060 if (dcbx_cfg->pfc.pfcena) { 3061 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n"); 3062 return -EOPNOTSUPP; 3063 } 3064 if (pause->rx_pause && pause->tx_pause) 3065 pi->fc.req_mode = ICE_FC_FULL; 3066 else if (pause->rx_pause && !pause->tx_pause) 3067 pi->fc.req_mode = ICE_FC_RX_PAUSE; 3068 else if (!pause->rx_pause && pause->tx_pause) 3069 pi->fc.req_mode = ICE_FC_TX_PAUSE; 3070 else if (!pause->rx_pause && !pause->tx_pause) 3071 pi->fc.req_mode = ICE_FC_NONE; 3072 else 3073 return -EINVAL; 3074 3075 /* Set the FC mode and only restart AN if link is up */ 3076 status = ice_set_fc(pi, &aq_failures, link_up); 3077 3078 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) { 3079 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n", 3080 ice_stat_str(status), 3081 ice_aq_str(hw->adminq.sq_last_status)); 3082 err = -EAGAIN; 3083 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) { 3084 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n", 3085 ice_stat_str(status), 3086 ice_aq_str(hw->adminq.sq_last_status)); 3087 err = -EAGAIN; 3088 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) { 3089 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n", 3090 ice_stat_str(status), 3091 ice_aq_str(hw->adminq.sq_last_status)); 3092 err = -EAGAIN; 3093 } 3094 3095 return err; 3096 } 3097 3098 /** 3099 * ice_get_rxfh_key_size - get the RSS hash key size 3100 * @netdev: network interface device structure 3101 * 3102 * Returns the table size. 3103 */ 3104 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev) 3105 { 3106 return ICE_VSIQF_HKEY_ARRAY_SIZE; 3107 } 3108 3109 /** 3110 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size 3111 * @netdev: network interface device structure 3112 * 3113 * Returns the table size. 3114 */ 3115 static u32 ice_get_rxfh_indir_size(struct net_device *netdev) 3116 { 3117 struct ice_netdev_priv *np = netdev_priv(netdev); 3118 3119 return np->vsi->rss_table_size; 3120 } 3121 3122 /** 3123 * ice_get_rxfh - get the Rx flow hash indirection table 3124 * @netdev: network interface device structure 3125 * @indir: indirection table 3126 * @key: hash key 3127 * @hfunc: hash function 3128 * 3129 * Reads the indirection table directly from the hardware. 3130 */ 3131 static int 3132 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc) 3133 { 3134 struct ice_netdev_priv *np = netdev_priv(netdev); 3135 struct ice_vsi *vsi = np->vsi; 3136 struct ice_pf *pf = vsi->back; 3137 int err, i; 3138 u8 *lut; 3139 3140 if (hfunc) 3141 *hfunc = ETH_RSS_HASH_TOP; 3142 3143 if (!indir) 3144 return 0; 3145 3146 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { 3147 /* RSS not supported return error here */ 3148 netdev_warn(netdev, "RSS is not configured on this VSI!\n"); 3149 return -EIO; 3150 } 3151 3152 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); 3153 if (!lut) 3154 return -ENOMEM; 3155 3156 err = ice_get_rss_key(vsi, key); 3157 if (err) 3158 goto out; 3159 3160 err = ice_get_rss_lut(vsi, lut, vsi->rss_table_size); 3161 if (err) 3162 goto out; 3163 3164 for (i = 0; i < vsi->rss_table_size; i++) 3165 indir[i] = (u32)(lut[i]); 3166 3167 out: 3168 kfree(lut); 3169 return err; 3170 } 3171 3172 /** 3173 * ice_set_rxfh - set the Rx flow hash indirection table 3174 * @netdev: network interface device structure 3175 * @indir: indirection table 3176 * @key: hash key 3177 * @hfunc: hash function 3178 * 3179 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise 3180 * returns 0 after programming the table. 3181 */ 3182 static int 3183 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key, 3184 const u8 hfunc) 3185 { 3186 struct ice_netdev_priv *np = netdev_priv(netdev); 3187 struct ice_vsi *vsi = np->vsi; 3188 struct ice_pf *pf = vsi->back; 3189 struct device *dev; 3190 int err; 3191 3192 dev = ice_pf_to_dev(pf); 3193 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 3194 return -EOPNOTSUPP; 3195 3196 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) { 3197 /* RSS not supported return error here */ 3198 netdev_warn(netdev, "RSS is not configured on this VSI!\n"); 3199 return -EIO; 3200 } 3201 3202 if (ice_is_adq_active(pf)) { 3203 netdev_err(netdev, "Cannot change RSS params with ADQ configured.\n"); 3204 return -EOPNOTSUPP; 3205 } 3206 3207 if (key) { 3208 if (!vsi->rss_hkey_user) { 3209 vsi->rss_hkey_user = 3210 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE, 3211 GFP_KERNEL); 3212 if (!vsi->rss_hkey_user) 3213 return -ENOMEM; 3214 } 3215 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE); 3216 3217 err = ice_set_rss_key(vsi, vsi->rss_hkey_user); 3218 if (err) 3219 return err; 3220 } 3221 3222 if (!vsi->rss_lut_user) { 3223 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size, 3224 GFP_KERNEL); 3225 if (!vsi->rss_lut_user) 3226 return -ENOMEM; 3227 } 3228 3229 /* Each 32 bits pointed by 'indir' is stored with a lut entry */ 3230 if (indir) { 3231 int i; 3232 3233 for (i = 0; i < vsi->rss_table_size; i++) 3234 vsi->rss_lut_user[i] = (u8)(indir[i]); 3235 } else { 3236 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size, 3237 vsi->rss_size); 3238 } 3239 3240 err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size); 3241 if (err) 3242 return err; 3243 3244 return 0; 3245 } 3246 3247 static int 3248 ice_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) 3249 { 3250 struct ice_pf *pf = ice_netdev_to_pf(dev); 3251 3252 /* only report timestamping if PTP is enabled */ 3253 if (!test_bit(ICE_FLAG_PTP, pf->flags)) 3254 return ethtool_op_get_ts_info(dev, info); 3255 3256 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 3257 SOF_TIMESTAMPING_RX_SOFTWARE | 3258 SOF_TIMESTAMPING_SOFTWARE | 3259 SOF_TIMESTAMPING_TX_HARDWARE | 3260 SOF_TIMESTAMPING_RX_HARDWARE | 3261 SOF_TIMESTAMPING_RAW_HARDWARE; 3262 3263 info->phc_index = ice_get_ptp_clock_index(pf); 3264 3265 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); 3266 3267 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL); 3268 3269 return 0; 3270 } 3271 3272 /** 3273 * ice_get_max_txq - return the maximum number of Tx queues for in a PF 3274 * @pf: PF structure 3275 */ 3276 static int ice_get_max_txq(struct ice_pf *pf) 3277 { 3278 return min3(pf->num_lan_msix, (u16)num_online_cpus(), 3279 (u16)pf->hw.func_caps.common_cap.num_txq); 3280 } 3281 3282 /** 3283 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF 3284 * @pf: PF structure 3285 */ 3286 static int ice_get_max_rxq(struct ice_pf *pf) 3287 { 3288 return min3(pf->num_lan_msix, (u16)num_online_cpus(), 3289 (u16)pf->hw.func_caps.common_cap.num_rxq); 3290 } 3291 3292 /** 3293 * ice_get_combined_cnt - return the current number of combined channels 3294 * @vsi: PF VSI pointer 3295 * 3296 * Go through all queue vectors and count ones that have both Rx and Tx ring 3297 * attached 3298 */ 3299 static u32 ice_get_combined_cnt(struct ice_vsi *vsi) 3300 { 3301 u32 combined = 0; 3302 int q_idx; 3303 3304 ice_for_each_q_vector(vsi, q_idx) { 3305 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx]; 3306 3307 if (q_vector->rx.rx_ring && q_vector->tx.tx_ring) 3308 combined++; 3309 } 3310 3311 return combined; 3312 } 3313 3314 /** 3315 * ice_get_channels - get the current and max supported channels 3316 * @dev: network interface device structure 3317 * @ch: ethtool channel data structure 3318 */ 3319 static void 3320 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch) 3321 { 3322 struct ice_netdev_priv *np = netdev_priv(dev); 3323 struct ice_vsi *vsi = np->vsi; 3324 struct ice_pf *pf = vsi->back; 3325 3326 /* report maximum channels */ 3327 ch->max_rx = ice_get_max_rxq(pf); 3328 ch->max_tx = ice_get_max_txq(pf); 3329 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx); 3330 3331 /* report current channels */ 3332 ch->combined_count = ice_get_combined_cnt(vsi); 3333 ch->rx_count = vsi->num_rxq - ch->combined_count; 3334 ch->tx_count = vsi->num_txq - ch->combined_count; 3335 3336 /* report other queues */ 3337 ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0; 3338 ch->max_other = ch->other_count; 3339 } 3340 3341 /** 3342 * ice_get_valid_rss_size - return valid number of RSS queues 3343 * @hw: pointer to the HW structure 3344 * @new_size: requested RSS queues 3345 */ 3346 static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size) 3347 { 3348 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap; 3349 3350 return min_t(int, new_size, BIT(caps->rss_table_entry_width)); 3351 } 3352 3353 /** 3354 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size 3355 * @vsi: VSI to reconfigure RSS LUT on 3356 * @req_rss_size: requested range of queue numbers for hashing 3357 * 3358 * Set the VSI's RSS parameters, configure the RSS LUT based on these. 3359 */ 3360 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size) 3361 { 3362 struct ice_pf *pf = vsi->back; 3363 struct device *dev; 3364 struct ice_hw *hw; 3365 int err; 3366 u8 *lut; 3367 3368 dev = ice_pf_to_dev(pf); 3369 hw = &pf->hw; 3370 3371 if (!req_rss_size) 3372 return -EINVAL; 3373 3374 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); 3375 if (!lut) 3376 return -ENOMEM; 3377 3378 /* set RSS LUT parameters */ 3379 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) 3380 vsi->rss_size = 1; 3381 else 3382 vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size); 3383 3384 /* create/set RSS LUT */ 3385 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size); 3386 err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size); 3387 if (err) 3388 dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err, 3389 ice_aq_str(hw->adminq.sq_last_status)); 3390 3391 kfree(lut); 3392 return err; 3393 } 3394 3395 /** 3396 * ice_set_channels - set the number channels 3397 * @dev: network interface device structure 3398 * @ch: ethtool channel data structure 3399 */ 3400 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch) 3401 { 3402 struct ice_netdev_priv *np = netdev_priv(dev); 3403 struct ice_vsi *vsi = np->vsi; 3404 struct ice_pf *pf = vsi->back; 3405 int new_rx = 0, new_tx = 0; 3406 u32 curr_combined; 3407 3408 /* do not support changing channels in Safe Mode */ 3409 if (ice_is_safe_mode(pf)) { 3410 netdev_err(dev, "Changing channel in Safe Mode is not supported\n"); 3411 return -EOPNOTSUPP; 3412 } 3413 /* do not support changing other_count */ 3414 if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U)) 3415 return -EINVAL; 3416 3417 if (ice_is_adq_active(pf)) { 3418 netdev_err(dev, "Cannot set channels with ADQ configured.\n"); 3419 return -EOPNOTSUPP; 3420 } 3421 3422 if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) { 3423 netdev_err(dev, "Cannot set channels when Flow Director filters are active\n"); 3424 return -EOPNOTSUPP; 3425 } 3426 3427 curr_combined = ice_get_combined_cnt(vsi); 3428 3429 /* these checks are for cases where user didn't specify a particular 3430 * value on cmd line but we get non-zero value anyway via 3431 * get_channels(); look at ethtool.c in ethtool repository (the user 3432 * space part), particularly, do_schannels() routine 3433 */ 3434 if (ch->rx_count == vsi->num_rxq - curr_combined) 3435 ch->rx_count = 0; 3436 if (ch->tx_count == vsi->num_txq - curr_combined) 3437 ch->tx_count = 0; 3438 if (ch->combined_count == curr_combined) 3439 ch->combined_count = 0; 3440 3441 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) { 3442 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n"); 3443 return -EINVAL; 3444 } 3445 3446 new_rx = ch->combined_count + ch->rx_count; 3447 new_tx = ch->combined_count + ch->tx_count; 3448 3449 if (new_rx > ice_get_max_rxq(pf)) { 3450 netdev_err(dev, "Maximum allowed Rx channels is %d\n", 3451 ice_get_max_rxq(pf)); 3452 return -EINVAL; 3453 } 3454 if (new_tx > ice_get_max_txq(pf)) { 3455 netdev_err(dev, "Maximum allowed Tx channels is %d\n", 3456 ice_get_max_txq(pf)); 3457 return -EINVAL; 3458 } 3459 3460 ice_vsi_recfg_qs(vsi, new_rx, new_tx); 3461 3462 if (!netif_is_rxfh_configured(dev)) 3463 return ice_vsi_set_dflt_rss_lut(vsi, new_rx); 3464 3465 /* Update rss_size due to change in Rx queues */ 3466 vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx); 3467 3468 return 0; 3469 } 3470 3471 /** 3472 * ice_get_wol - get current Wake on LAN configuration 3473 * @netdev: network interface device structure 3474 * @wol: Ethtool structure to retrieve WoL settings 3475 */ 3476 static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 3477 { 3478 struct ice_netdev_priv *np = netdev_priv(netdev); 3479 struct ice_pf *pf = np->vsi->back; 3480 3481 if (np->vsi->type != ICE_VSI_PF) 3482 netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n"); 3483 3484 /* Get WoL settings based on the HW capability */ 3485 if (ice_is_wol_supported(&pf->hw)) { 3486 wol->supported = WAKE_MAGIC; 3487 wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0; 3488 } else { 3489 wol->supported = 0; 3490 wol->wolopts = 0; 3491 } 3492 } 3493 3494 /** 3495 * ice_set_wol - set Wake on LAN on supported device 3496 * @netdev: network interface device structure 3497 * @wol: Ethtool structure to set WoL 3498 */ 3499 static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 3500 { 3501 struct ice_netdev_priv *np = netdev_priv(netdev); 3502 struct ice_vsi *vsi = np->vsi; 3503 struct ice_pf *pf = vsi->back; 3504 3505 if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw)) 3506 return -EOPNOTSUPP; 3507 3508 /* only magic packet is supported */ 3509 if (wol->wolopts && wol->wolopts != WAKE_MAGIC) 3510 return -EOPNOTSUPP; 3511 3512 /* Set WoL only if there is a new value */ 3513 if (pf->wol_ena != !!wol->wolopts) { 3514 pf->wol_ena = !!wol->wolopts; 3515 device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena); 3516 netdev_dbg(netdev, "WoL magic packet %sabled\n", 3517 pf->wol_ena ? "en" : "dis"); 3518 } 3519 3520 return 0; 3521 } 3522 3523 /** 3524 * ice_get_rc_coalesce - get ITR values for specific ring container 3525 * @ec: ethtool structure to fill with driver's coalesce settings 3526 * @rc: ring container that the ITR values will come from 3527 * 3528 * Query the device for ice_ring_container specific ITR values. This is 3529 * done per ice_ring_container because each q_vector can have 1 or more rings 3530 * and all of said ring(s) will have the same ITR values. 3531 * 3532 * Returns 0 on success, negative otherwise. 3533 */ 3534 static int 3535 ice_get_rc_coalesce(struct ethtool_coalesce *ec, struct ice_ring_container *rc) 3536 { 3537 if (!rc->rx_ring) 3538 return -EINVAL; 3539 3540 switch (rc->type) { 3541 case ICE_RX_CONTAINER: 3542 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc); 3543 ec->rx_coalesce_usecs = rc->itr_setting; 3544 ec->rx_coalesce_usecs_high = rc->rx_ring->q_vector->intrl; 3545 break; 3546 case ICE_TX_CONTAINER: 3547 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc); 3548 ec->tx_coalesce_usecs = rc->itr_setting; 3549 break; 3550 default: 3551 dev_dbg(ice_pf_to_dev(rc->rx_ring->vsi->back), "Invalid c_type %d\n", rc->type); 3552 return -EINVAL; 3553 } 3554 3555 return 0; 3556 } 3557 3558 /** 3559 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings 3560 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings 3561 * @ec: coalesce settings to program the device with 3562 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index 3563 * 3564 * Return 0 on success, and negative under the following conditions: 3565 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed. 3566 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings. 3567 */ 3568 static int 3569 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num) 3570 { 3571 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) { 3572 if (ice_get_rc_coalesce(ec, 3573 &vsi->rx_rings[q_num]->q_vector->rx)) 3574 return -EINVAL; 3575 if (ice_get_rc_coalesce(ec, 3576 &vsi->tx_rings[q_num]->q_vector->tx)) 3577 return -EINVAL; 3578 } else if (q_num < vsi->num_rxq) { 3579 if (ice_get_rc_coalesce(ec, 3580 &vsi->rx_rings[q_num]->q_vector->rx)) 3581 return -EINVAL; 3582 } else if (q_num < vsi->num_txq) { 3583 if (ice_get_rc_coalesce(ec, 3584 &vsi->tx_rings[q_num]->q_vector->tx)) 3585 return -EINVAL; 3586 } else { 3587 return -EINVAL; 3588 } 3589 3590 return 0; 3591 } 3592 3593 /** 3594 * __ice_get_coalesce - get ITR/INTRL values for the device 3595 * @netdev: pointer to the netdev associated with this query 3596 * @ec: ethtool structure to fill with driver's coalesce settings 3597 * @q_num: queue number to get the coalesce settings for 3598 * 3599 * If the caller passes in a negative q_num then we return coalesce settings 3600 * based on queue number 0, else use the actual q_num passed in. 3601 */ 3602 static int 3603 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, 3604 int q_num) 3605 { 3606 struct ice_netdev_priv *np = netdev_priv(netdev); 3607 struct ice_vsi *vsi = np->vsi; 3608 3609 if (q_num < 0) 3610 q_num = 0; 3611 3612 if (ice_get_q_coalesce(vsi, ec, q_num)) 3613 return -EINVAL; 3614 3615 return 0; 3616 } 3617 3618 static int ice_get_coalesce(struct net_device *netdev, 3619 struct ethtool_coalesce *ec, 3620 struct kernel_ethtool_coalesce *kernel_coal, 3621 struct netlink_ext_ack *extack) 3622 { 3623 return __ice_get_coalesce(netdev, ec, -1); 3624 } 3625 3626 static int 3627 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num, 3628 struct ethtool_coalesce *ec) 3629 { 3630 return __ice_get_coalesce(netdev, ec, q_num); 3631 } 3632 3633 /** 3634 * ice_set_rc_coalesce - set ITR values for specific ring container 3635 * @ec: ethtool structure from user to update ITR settings 3636 * @rc: ring container that the ITR values will come from 3637 * @vsi: VSI associated to the ring container 3638 * 3639 * Set specific ITR values. This is done per ice_ring_container because each 3640 * q_vector can have 1 or more rings and all of said ring(s) will have the same 3641 * ITR values. 3642 * 3643 * Returns 0 on success, negative otherwise. 3644 */ 3645 static int 3646 ice_set_rc_coalesce(struct ethtool_coalesce *ec, 3647 struct ice_ring_container *rc, struct ice_vsi *vsi) 3648 { 3649 const char *c_type_str = (rc->type == ICE_RX_CONTAINER) ? "rx" : "tx"; 3650 u32 use_adaptive_coalesce, coalesce_usecs; 3651 struct ice_pf *pf = vsi->back; 3652 u16 itr_setting; 3653 3654 if (!rc->rx_ring) 3655 return -EINVAL; 3656 3657 switch (rc->type) { 3658 case ICE_RX_CONTAINER: 3659 { 3660 struct ice_q_vector *q_vector = rc->rx_ring->q_vector; 3661 3662 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL || 3663 (ec->rx_coalesce_usecs_high && 3664 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) { 3665 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n", 3666 c_type_str, pf->hw.intrl_gran, 3667 ICE_MAX_INTRL); 3668 return -EINVAL; 3669 } 3670 if (ec->rx_coalesce_usecs_high != q_vector->intrl && 3671 (ec->use_adaptive_rx_coalesce || ec->use_adaptive_tx_coalesce)) { 3672 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high cannot be changed if adaptive-tx or adaptive-rx is enabled\n", 3673 c_type_str); 3674 return -EINVAL; 3675 } 3676 if (ec->rx_coalesce_usecs_high != q_vector->intrl) 3677 q_vector->intrl = ec->rx_coalesce_usecs_high; 3678 3679 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce; 3680 coalesce_usecs = ec->rx_coalesce_usecs; 3681 3682 break; 3683 } 3684 case ICE_TX_CONTAINER: 3685 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce; 3686 coalesce_usecs = ec->tx_coalesce_usecs; 3687 3688 break; 3689 default: 3690 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n", 3691 rc->type); 3692 return -EINVAL; 3693 } 3694 3695 itr_setting = rc->itr_setting; 3696 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) { 3697 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n", 3698 c_type_str, c_type_str); 3699 return -EINVAL; 3700 } 3701 3702 if (coalesce_usecs > ICE_ITR_MAX) { 3703 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n", 3704 c_type_str, ICE_ITR_MAX); 3705 return -EINVAL; 3706 } 3707 3708 if (use_adaptive_coalesce) { 3709 rc->itr_mode = ITR_DYNAMIC; 3710 } else { 3711 rc->itr_mode = ITR_STATIC; 3712 /* store user facing value how it was set */ 3713 rc->itr_setting = coalesce_usecs; 3714 /* write the change to the register */ 3715 ice_write_itr(rc, coalesce_usecs); 3716 /* force writes to take effect immediately, the flush shouldn't 3717 * be done in the functions above because the intent is for 3718 * them to do lazy writes. 3719 */ 3720 ice_flush(&pf->hw); 3721 } 3722 3723 return 0; 3724 } 3725 3726 /** 3727 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings 3728 * @vsi: VSI associated to the queue that need updating 3729 * @ec: coalesce settings to program the device with 3730 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index 3731 * 3732 * Return 0 on success, and negative under the following conditions: 3733 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed. 3734 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings. 3735 */ 3736 static int 3737 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num) 3738 { 3739 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) { 3740 if (ice_set_rc_coalesce(ec, 3741 &vsi->rx_rings[q_num]->q_vector->rx, 3742 vsi)) 3743 return -EINVAL; 3744 3745 if (ice_set_rc_coalesce(ec, 3746 &vsi->tx_rings[q_num]->q_vector->tx, 3747 vsi)) 3748 return -EINVAL; 3749 } else if (q_num < vsi->num_rxq) { 3750 if (ice_set_rc_coalesce(ec, 3751 &vsi->rx_rings[q_num]->q_vector->rx, 3752 vsi)) 3753 return -EINVAL; 3754 } else if (q_num < vsi->num_txq) { 3755 if (ice_set_rc_coalesce(ec, 3756 &vsi->tx_rings[q_num]->q_vector->tx, 3757 vsi)) 3758 return -EINVAL; 3759 } else { 3760 return -EINVAL; 3761 } 3762 3763 return 0; 3764 } 3765 3766 /** 3767 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs 3768 * @netdev: netdev used for print 3769 * @itr_setting: previous user setting 3770 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled 3771 * @coalesce_usecs: requested value of [tx|rx]-usecs 3772 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs 3773 */ 3774 static void 3775 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting, 3776 u32 use_adaptive_coalesce, u32 coalesce_usecs, 3777 const char *c_type_str) 3778 { 3779 if (use_adaptive_coalesce) 3780 return; 3781 3782 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2)) 3783 netdev_info(netdev, "User set %s-usecs to %d, device only supports even values. Rounding down and attempting to set %s-usecs to %d\n", 3784 c_type_str, coalesce_usecs, c_type_str, 3785 ITR_REG_ALIGN(coalesce_usecs)); 3786 } 3787 3788 /** 3789 * __ice_set_coalesce - set ITR/INTRL values for the device 3790 * @netdev: pointer to the netdev associated with this query 3791 * @ec: ethtool structure to fill with driver's coalesce settings 3792 * @q_num: queue number to get the coalesce settings for 3793 * 3794 * If the caller passes in a negative q_num then we set the coalesce settings 3795 * for all Tx/Rx queues, else use the actual q_num passed in. 3796 */ 3797 static int 3798 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec, 3799 int q_num) 3800 { 3801 struct ice_netdev_priv *np = netdev_priv(netdev); 3802 struct ice_vsi *vsi = np->vsi; 3803 3804 if (q_num < 0) { 3805 struct ice_q_vector *q_vector = vsi->q_vectors[0]; 3806 int v_idx; 3807 3808 if (q_vector) { 3809 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting, 3810 ec->use_adaptive_rx_coalesce, 3811 ec->rx_coalesce_usecs, "rx"); 3812 3813 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting, 3814 ec->use_adaptive_tx_coalesce, 3815 ec->tx_coalesce_usecs, "tx"); 3816 } 3817 3818 ice_for_each_q_vector(vsi, v_idx) { 3819 /* In some cases if DCB is configured the num_[rx|tx]q 3820 * can be less than vsi->num_q_vectors. This check 3821 * accounts for that so we don't report a false failure 3822 */ 3823 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq) 3824 goto set_complete; 3825 3826 if (ice_set_q_coalesce(vsi, ec, v_idx)) 3827 return -EINVAL; 3828 3829 ice_set_q_vector_intrl(vsi->q_vectors[v_idx]); 3830 } 3831 goto set_complete; 3832 } 3833 3834 if (ice_set_q_coalesce(vsi, ec, q_num)) 3835 return -EINVAL; 3836 3837 ice_set_q_vector_intrl(vsi->q_vectors[q_num]); 3838 3839 set_complete: 3840 return 0; 3841 } 3842 3843 static int ice_set_coalesce(struct net_device *netdev, 3844 struct ethtool_coalesce *ec, 3845 struct kernel_ethtool_coalesce *kernel_coal, 3846 struct netlink_ext_ack *extack) 3847 { 3848 return __ice_set_coalesce(netdev, ec, -1); 3849 } 3850 3851 static int 3852 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num, 3853 struct ethtool_coalesce *ec) 3854 { 3855 return __ice_set_coalesce(netdev, ec, q_num); 3856 } 3857 3858 static void 3859 ice_repr_get_drvinfo(struct net_device *netdev, 3860 struct ethtool_drvinfo *drvinfo) 3861 { 3862 struct ice_repr *repr = ice_netdev_to_repr(netdev); 3863 3864 if (ice_check_vf_ready_for_cfg(repr->vf)) 3865 return; 3866 3867 __ice_get_drvinfo(netdev, drvinfo, repr->src_vsi); 3868 } 3869 3870 static void 3871 ice_repr_get_strings(struct net_device *netdev, u32 stringset, u8 *data) 3872 { 3873 struct ice_repr *repr = ice_netdev_to_repr(netdev); 3874 3875 /* for port representors only ETH_SS_STATS is supported */ 3876 if (ice_check_vf_ready_for_cfg(repr->vf) || 3877 stringset != ETH_SS_STATS) 3878 return; 3879 3880 __ice_get_strings(netdev, stringset, data, repr->src_vsi); 3881 } 3882 3883 static void 3884 ice_repr_get_ethtool_stats(struct net_device *netdev, 3885 struct ethtool_stats __always_unused *stats, 3886 u64 *data) 3887 { 3888 struct ice_repr *repr = ice_netdev_to_repr(netdev); 3889 3890 if (ice_check_vf_ready_for_cfg(repr->vf)) 3891 return; 3892 3893 __ice_get_ethtool_stats(netdev, stats, data, repr->src_vsi); 3894 } 3895 3896 static int ice_repr_get_sset_count(struct net_device *netdev, int sset) 3897 { 3898 switch (sset) { 3899 case ETH_SS_STATS: 3900 return ICE_VSI_STATS_LEN; 3901 default: 3902 return -EOPNOTSUPP; 3903 } 3904 } 3905 3906 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0 3907 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2 3908 #define ICE_MODULE_TYPE_SFP 0x03 3909 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D 3910 #define ICE_MODULE_TYPE_QSFP28 0x11 3911 #define ICE_MODULE_SFF_ADDR_MODE 0x04 3912 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40 3913 #define ICE_MODULE_REVISION_ADDR 0x01 3914 #define ICE_MODULE_SFF_8472_COMP 0x5E 3915 #define ICE_MODULE_SFF_8472_SWAP 0x5C 3916 #define ICE_MODULE_QSFP_MAX_LEN 640 3917 3918 /** 3919 * ice_get_module_info - get SFF module type and revision information 3920 * @netdev: network interface device structure 3921 * @modinfo: module EEPROM size and layout information structure 3922 */ 3923 static int 3924 ice_get_module_info(struct net_device *netdev, 3925 struct ethtool_modinfo *modinfo) 3926 { 3927 struct ice_netdev_priv *np = netdev_priv(netdev); 3928 struct ice_vsi *vsi = np->vsi; 3929 struct ice_pf *pf = vsi->back; 3930 struct ice_hw *hw = &pf->hw; 3931 enum ice_status status; 3932 u8 sff8472_comp = 0; 3933 u8 sff8472_swap = 0; 3934 u8 sff8636_rev = 0; 3935 u8 value = 0; 3936 3937 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00, 3938 0, &value, 1, 0, NULL); 3939 if (status) 3940 return -EIO; 3941 3942 switch (value) { 3943 case ICE_MODULE_TYPE_SFP: 3944 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 3945 ICE_MODULE_SFF_8472_COMP, 0x00, 0, 3946 &sff8472_comp, 1, 0, NULL); 3947 if (status) 3948 return -EIO; 3949 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 3950 ICE_MODULE_SFF_8472_SWAP, 0x00, 0, 3951 &sff8472_swap, 1, 0, NULL); 3952 if (status) 3953 return -EIO; 3954 3955 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) { 3956 modinfo->type = ETH_MODULE_SFF_8079; 3957 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 3958 } else if (sff8472_comp && 3959 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) { 3960 modinfo->type = ETH_MODULE_SFF_8472; 3961 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; 3962 } else { 3963 modinfo->type = ETH_MODULE_SFF_8079; 3964 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; 3965 } 3966 break; 3967 case ICE_MODULE_TYPE_QSFP_PLUS: 3968 case ICE_MODULE_TYPE_QSFP28: 3969 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 3970 ICE_MODULE_REVISION_ADDR, 0x00, 0, 3971 &sff8636_rev, 1, 0, NULL); 3972 if (status) 3973 return -EIO; 3974 /* Check revision compliance */ 3975 if (sff8636_rev > 0x02) { 3976 /* Module is SFF-8636 compliant */ 3977 modinfo->type = ETH_MODULE_SFF_8636; 3978 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN; 3979 } else { 3980 modinfo->type = ETH_MODULE_SFF_8436; 3981 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN; 3982 } 3983 break; 3984 default: 3985 netdev_warn(netdev, "SFF Module Type not recognized.\n"); 3986 return -EINVAL; 3987 } 3988 return 0; 3989 } 3990 3991 /** 3992 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents 3993 * @netdev: network interface device structure 3994 * @ee: EEPROM dump request structure 3995 * @data: buffer to be filled with EEPROM contents 3996 */ 3997 static int 3998 ice_get_module_eeprom(struct net_device *netdev, 3999 struct ethtool_eeprom *ee, u8 *data) 4000 { 4001 struct ice_netdev_priv *np = netdev_priv(netdev); 4002 #define SFF_READ_BLOCK_SIZE 8 4003 u8 value[SFF_READ_BLOCK_SIZE] = { 0 }; 4004 u8 addr = ICE_I2C_EEPROM_DEV_ADDR; 4005 struct ice_vsi *vsi = np->vsi; 4006 struct ice_pf *pf = vsi->back; 4007 struct ice_hw *hw = &pf->hw; 4008 enum ice_status status; 4009 bool is_sfp = false; 4010 unsigned int i, j; 4011 u16 offset = 0; 4012 u8 page = 0; 4013 4014 if (!ee || !ee->len || !data) 4015 return -EINVAL; 4016 4017 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0, 4018 NULL); 4019 if (status) 4020 return -EIO; 4021 4022 if (value[0] == ICE_MODULE_TYPE_SFP) 4023 is_sfp = true; 4024 4025 memset(data, 0, ee->len); 4026 for (i = 0; i < ee->len; i += SFF_READ_BLOCK_SIZE) { 4027 offset = i + ee->offset; 4028 page = 0; 4029 4030 /* Check if we need to access the other memory page */ 4031 if (is_sfp) { 4032 if (offset >= ETH_MODULE_SFF_8079_LEN) { 4033 offset -= ETH_MODULE_SFF_8079_LEN; 4034 addr = ICE_I2C_EEPROM_DEV_ADDR2; 4035 } 4036 } else { 4037 while (offset >= ETH_MODULE_SFF_8436_LEN) { 4038 /* Compute memory page number and offset. */ 4039 offset -= ETH_MODULE_SFF_8436_LEN / 2; 4040 page++; 4041 } 4042 } 4043 4044 /* Bit 2 of EEPROM address 0x02 declares upper 4045 * pages are disabled on QSFP modules. 4046 * SFP modules only ever use page 0. 4047 */ 4048 if (page == 0 || !(data[0x2] & 0x4)) { 4049 /* If i2c bus is busy due to slow page change or 4050 * link management access, call can fail. This is normal. 4051 * So we retry this a few times. 4052 */ 4053 for (j = 0; j < 4; j++) { 4054 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 4055 !is_sfp, value, 4056 SFF_READ_BLOCK_SIZE, 4057 0, NULL); 4058 netdev_dbg(netdev, "SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%X)\n", 4059 addr, offset, page, is_sfp, 4060 value[0], value[1], value[2], value[3], 4061 value[4], value[5], value[6], value[7], 4062 status); 4063 if (status) { 4064 usleep_range(1500, 2500); 4065 memset(value, 0, SFF_READ_BLOCK_SIZE); 4066 continue; 4067 } 4068 break; 4069 } 4070 4071 /* Make sure we have enough room for the new block */ 4072 if ((i + SFF_READ_BLOCK_SIZE) < ee->len) 4073 memcpy(data + i, value, SFF_READ_BLOCK_SIZE); 4074 } 4075 } 4076 return 0; 4077 } 4078 4079 static const struct ethtool_ops ice_ethtool_ops = { 4080 .supported_coalesce_params = ETHTOOL_COALESCE_USECS | 4081 ETHTOOL_COALESCE_USE_ADAPTIVE | 4082 ETHTOOL_COALESCE_RX_USECS_HIGH, 4083 .get_link_ksettings = ice_get_link_ksettings, 4084 .set_link_ksettings = ice_set_link_ksettings, 4085 .get_drvinfo = ice_get_drvinfo, 4086 .get_regs_len = ice_get_regs_len, 4087 .get_regs = ice_get_regs, 4088 .get_wol = ice_get_wol, 4089 .set_wol = ice_set_wol, 4090 .get_msglevel = ice_get_msglevel, 4091 .set_msglevel = ice_set_msglevel, 4092 .self_test = ice_self_test, 4093 .get_link = ethtool_op_get_link, 4094 .get_eeprom_len = ice_get_eeprom_len, 4095 .get_eeprom = ice_get_eeprom, 4096 .get_coalesce = ice_get_coalesce, 4097 .set_coalesce = ice_set_coalesce, 4098 .get_strings = ice_get_strings, 4099 .set_phys_id = ice_set_phys_id, 4100 .get_ethtool_stats = ice_get_ethtool_stats, 4101 .get_priv_flags = ice_get_priv_flags, 4102 .set_priv_flags = ice_set_priv_flags, 4103 .get_sset_count = ice_get_sset_count, 4104 .get_rxnfc = ice_get_rxnfc, 4105 .set_rxnfc = ice_set_rxnfc, 4106 .get_ringparam = ice_get_ringparam, 4107 .set_ringparam = ice_set_ringparam, 4108 .nway_reset = ice_nway_reset, 4109 .get_pauseparam = ice_get_pauseparam, 4110 .set_pauseparam = ice_set_pauseparam, 4111 .get_rxfh_key_size = ice_get_rxfh_key_size, 4112 .get_rxfh_indir_size = ice_get_rxfh_indir_size, 4113 .get_rxfh = ice_get_rxfh, 4114 .set_rxfh = ice_set_rxfh, 4115 .get_channels = ice_get_channels, 4116 .set_channels = ice_set_channels, 4117 .get_ts_info = ice_get_ts_info, 4118 .get_per_queue_coalesce = ice_get_per_q_coalesce, 4119 .set_per_queue_coalesce = ice_set_per_q_coalesce, 4120 .get_fecparam = ice_get_fecparam, 4121 .set_fecparam = ice_set_fecparam, 4122 .get_module_info = ice_get_module_info, 4123 .get_module_eeprom = ice_get_module_eeprom, 4124 }; 4125 4126 static const struct ethtool_ops ice_ethtool_safe_mode_ops = { 4127 .get_link_ksettings = ice_get_link_ksettings, 4128 .set_link_ksettings = ice_set_link_ksettings, 4129 .get_drvinfo = ice_get_drvinfo, 4130 .get_regs_len = ice_get_regs_len, 4131 .get_regs = ice_get_regs, 4132 .get_wol = ice_get_wol, 4133 .set_wol = ice_set_wol, 4134 .get_msglevel = ice_get_msglevel, 4135 .set_msglevel = ice_set_msglevel, 4136 .get_link = ethtool_op_get_link, 4137 .get_eeprom_len = ice_get_eeprom_len, 4138 .get_eeprom = ice_get_eeprom, 4139 .get_strings = ice_get_strings, 4140 .get_ethtool_stats = ice_get_ethtool_stats, 4141 .get_sset_count = ice_get_sset_count, 4142 .get_ringparam = ice_get_ringparam, 4143 .set_ringparam = ice_set_ringparam, 4144 .nway_reset = ice_nway_reset, 4145 .get_channels = ice_get_channels, 4146 }; 4147 4148 /** 4149 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops 4150 * @netdev: network interface device structure 4151 */ 4152 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev) 4153 { 4154 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops; 4155 } 4156 4157 static const struct ethtool_ops ice_ethtool_repr_ops = { 4158 .get_drvinfo = ice_repr_get_drvinfo, 4159 .get_link = ethtool_op_get_link, 4160 .get_strings = ice_repr_get_strings, 4161 .get_ethtool_stats = ice_repr_get_ethtool_stats, 4162 .get_sset_count = ice_repr_get_sset_count, 4163 }; 4164 4165 /** 4166 * ice_set_ethtool_repr_ops - setup VF's port representor ethtool ops 4167 * @netdev: network interface device structure 4168 */ 4169 void ice_set_ethtool_repr_ops(struct net_device *netdev) 4170 { 4171 netdev->ethtool_ops = &ice_ethtool_repr_ops; 4172 } 4173 4174 /** 4175 * ice_set_ethtool_ops - setup netdev ethtool ops 4176 * @netdev: network interface device structure 4177 * 4178 * setup netdev ethtool ops with ice specific ops 4179 */ 4180 void ice_set_ethtool_ops(struct net_device *netdev) 4181 { 4182 netdev->ethtool_ops = &ice_ethtool_ops; 4183 } 4184