1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2018, Intel Corporation. */ 3 4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */ 5 6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 8 #include <generated/utsrelease.h> 9 #include "ice.h" 10 #include "ice_base.h" 11 #include "ice_lib.h" 12 #include "ice_fltr.h" 13 #include "ice_dcb_lib.h" 14 #include "ice_dcb_nl.h" 15 #include "ice_devlink.h" 16 17 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver" 18 static const char ice_driver_string[] = DRV_SUMMARY; 19 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation."; 20 21 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */ 22 #define ICE_DDP_PKG_PATH "intel/ice/ddp/" 23 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg" 24 25 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); 26 MODULE_DESCRIPTION(DRV_SUMMARY); 27 MODULE_LICENSE("GPL v2"); 28 MODULE_FIRMWARE(ICE_DDP_PKG_FILE); 29 30 static int debug = -1; 31 module_param(debug, int, 0644); 32 #ifndef CONFIG_DYNAMIC_DEBUG 33 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)"); 34 #else 35 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)"); 36 #endif /* !CONFIG_DYNAMIC_DEBUG */ 37 38 static struct workqueue_struct *ice_wq; 39 static const struct net_device_ops ice_netdev_safe_mode_ops; 40 static const struct net_device_ops ice_netdev_ops; 41 static int ice_vsi_open(struct ice_vsi *vsi); 42 43 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type); 44 45 static void ice_vsi_release_all(struct ice_pf *pf); 46 47 bool netif_is_ice(struct net_device *dev) 48 { 49 return dev && (dev->netdev_ops == &ice_netdev_ops); 50 } 51 52 /** 53 * ice_get_tx_pending - returns number of Tx descriptors not processed 54 * @ring: the ring of descriptors 55 */ 56 static u16 ice_get_tx_pending(struct ice_ring *ring) 57 { 58 u16 head, tail; 59 60 head = ring->next_to_clean; 61 tail = ring->next_to_use; 62 63 if (head != tail) 64 return (head < tail) ? 65 tail - head : (tail + ring->count - head); 66 return 0; 67 } 68 69 /** 70 * ice_check_for_hang_subtask - check for and recover hung queues 71 * @pf: pointer to PF struct 72 */ 73 static void ice_check_for_hang_subtask(struct ice_pf *pf) 74 { 75 struct ice_vsi *vsi = NULL; 76 struct ice_hw *hw; 77 unsigned int i; 78 int packets; 79 u32 v; 80 81 ice_for_each_vsi(pf, v) 82 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) { 83 vsi = pf->vsi[v]; 84 break; 85 } 86 87 if (!vsi || test_bit(__ICE_DOWN, vsi->state)) 88 return; 89 90 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev))) 91 return; 92 93 hw = &vsi->back->hw; 94 95 for (i = 0; i < vsi->num_txq; i++) { 96 struct ice_ring *tx_ring = vsi->tx_rings[i]; 97 98 if (tx_ring && tx_ring->desc) { 99 /* If packet counter has not changed the queue is 100 * likely stalled, so force an interrupt for this 101 * queue. 102 * 103 * prev_pkt would be negative if there was no 104 * pending work. 105 */ 106 packets = tx_ring->stats.pkts & INT_MAX; 107 if (tx_ring->tx_stats.prev_pkt == packets) { 108 /* Trigger sw interrupt to revive the queue */ 109 ice_trigger_sw_intr(hw, tx_ring->q_vector); 110 continue; 111 } 112 113 /* Memory barrier between read of packet count and call 114 * to ice_get_tx_pending() 115 */ 116 smp_rmb(); 117 tx_ring->tx_stats.prev_pkt = 118 ice_get_tx_pending(tx_ring) ? packets : -1; 119 } 120 } 121 } 122 123 /** 124 * ice_init_mac_fltr - Set initial MAC filters 125 * @pf: board private structure 126 * 127 * Set initial set of MAC filters for PF VSI; configure filters for permanent 128 * address and broadcast address. If an error is encountered, netdevice will be 129 * unregistered. 130 */ 131 static int ice_init_mac_fltr(struct ice_pf *pf) 132 { 133 enum ice_status status; 134 struct ice_vsi *vsi; 135 u8 *perm_addr; 136 137 vsi = ice_get_main_vsi(pf); 138 if (!vsi) 139 return -EINVAL; 140 141 perm_addr = vsi->port_info->mac.perm_addr; 142 status = ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI); 143 if (!status) 144 return 0; 145 146 /* We aren't useful with no MAC filters, so unregister if we 147 * had an error 148 */ 149 if (vsi->netdev->reg_state == NETREG_REGISTERED) { 150 dev_err(ice_pf_to_dev(pf), "Could not add MAC filters error %s. Unregistering device\n", 151 ice_stat_str(status)); 152 unregister_netdev(vsi->netdev); 153 free_netdev(vsi->netdev); 154 vsi->netdev = NULL; 155 } 156 157 return -EIO; 158 } 159 160 /** 161 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced 162 * @netdev: the net device on which the sync is happening 163 * @addr: MAC address to sync 164 * 165 * This is a callback function which is called by the in kernel device sync 166 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only 167 * populates the tmp_sync_list, which is later used by ice_add_mac to add the 168 * MAC filters from the hardware. 169 */ 170 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr) 171 { 172 struct ice_netdev_priv *np = netdev_priv(netdev); 173 struct ice_vsi *vsi = np->vsi; 174 175 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr, 176 ICE_FWD_TO_VSI)) 177 return -EINVAL; 178 179 return 0; 180 } 181 182 /** 183 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced 184 * @netdev: the net device on which the unsync is happening 185 * @addr: MAC address to unsync 186 * 187 * This is a callback function which is called by the in kernel device unsync 188 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only 189 * populates the tmp_unsync_list, which is later used by ice_remove_mac to 190 * delete the MAC filters from the hardware. 191 */ 192 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr) 193 { 194 struct ice_netdev_priv *np = netdev_priv(netdev); 195 struct ice_vsi *vsi = np->vsi; 196 197 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr, 198 ICE_FWD_TO_VSI)) 199 return -EINVAL; 200 201 return 0; 202 } 203 204 /** 205 * ice_vsi_fltr_changed - check if filter state changed 206 * @vsi: VSI to be checked 207 * 208 * returns true if filter state has changed, false otherwise. 209 */ 210 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi) 211 { 212 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) || 213 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) || 214 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags); 215 } 216 217 /** 218 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF 219 * @vsi: the VSI being configured 220 * @promisc_m: mask of promiscuous config bits 221 * @set_promisc: enable or disable promisc flag request 222 * 223 */ 224 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc) 225 { 226 struct ice_hw *hw = &vsi->back->hw; 227 enum ice_status status = 0; 228 229 if (vsi->type != ICE_VSI_PF) 230 return 0; 231 232 if (vsi->num_vlan > 1) { 233 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m, 234 set_promisc); 235 } else { 236 if (set_promisc) 237 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m, 238 0); 239 else 240 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m, 241 0); 242 } 243 244 if (status) 245 return -EIO; 246 247 return 0; 248 } 249 250 /** 251 * ice_vsi_sync_fltr - Update the VSI filter list to the HW 252 * @vsi: ptr to the VSI 253 * 254 * Push any outstanding VSI filter changes through the AdminQ. 255 */ 256 static int ice_vsi_sync_fltr(struct ice_vsi *vsi) 257 { 258 struct device *dev = ice_pf_to_dev(vsi->back); 259 struct net_device *netdev = vsi->netdev; 260 bool promisc_forced_on = false; 261 struct ice_pf *pf = vsi->back; 262 struct ice_hw *hw = &pf->hw; 263 enum ice_status status = 0; 264 u32 changed_flags = 0; 265 u8 promisc_m; 266 int err = 0; 267 268 if (!vsi->netdev) 269 return -EINVAL; 270 271 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state)) 272 usleep_range(1000, 2000); 273 274 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; 275 vsi->current_netdev_flags = vsi->netdev->flags; 276 277 INIT_LIST_HEAD(&vsi->tmp_sync_list); 278 INIT_LIST_HEAD(&vsi->tmp_unsync_list); 279 280 if (ice_vsi_fltr_changed(vsi)) { 281 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags); 282 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags); 283 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags); 284 285 /* grab the netdev's addr_list_lock */ 286 netif_addr_lock_bh(netdev); 287 __dev_uc_sync(netdev, ice_add_mac_to_sync_list, 288 ice_add_mac_to_unsync_list); 289 __dev_mc_sync(netdev, ice_add_mac_to_sync_list, 290 ice_add_mac_to_unsync_list); 291 /* our temp lists are populated. release lock */ 292 netif_addr_unlock_bh(netdev); 293 } 294 295 /* Remove MAC addresses in the unsync list */ 296 status = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list); 297 ice_fltr_free_list(dev, &vsi->tmp_unsync_list); 298 if (status) { 299 netdev_err(netdev, "Failed to delete MAC filters\n"); 300 /* if we failed because of alloc failures, just bail */ 301 if (status == ICE_ERR_NO_MEMORY) { 302 err = -ENOMEM; 303 goto out; 304 } 305 } 306 307 /* Add MAC addresses in the sync list */ 308 status = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list); 309 ice_fltr_free_list(dev, &vsi->tmp_sync_list); 310 /* If filter is added successfully or already exists, do not go into 311 * 'if' condition and report it as error. Instead continue processing 312 * rest of the function. 313 */ 314 if (status && status != ICE_ERR_ALREADY_EXISTS) { 315 netdev_err(netdev, "Failed to add MAC filters\n"); 316 /* If there is no more space for new umac filters, VSI 317 * should go into promiscuous mode. There should be some 318 * space reserved for promiscuous filters. 319 */ 320 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC && 321 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC, 322 vsi->state)) { 323 promisc_forced_on = true; 324 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n", 325 vsi->vsi_num); 326 } else { 327 err = -EIO; 328 goto out; 329 } 330 } 331 /* check for changes in promiscuous modes */ 332 if (changed_flags & IFF_ALLMULTI) { 333 if (vsi->current_netdev_flags & IFF_ALLMULTI) { 334 if (vsi->num_vlan > 1) 335 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS; 336 else 337 promisc_m = ICE_MCAST_PROMISC_BITS; 338 339 err = ice_cfg_promisc(vsi, promisc_m, true); 340 if (err) { 341 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n", 342 vsi->vsi_num); 343 vsi->current_netdev_flags &= ~IFF_ALLMULTI; 344 goto out_promisc; 345 } 346 } else { 347 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */ 348 if (vsi->num_vlan > 1) 349 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS; 350 else 351 promisc_m = ICE_MCAST_PROMISC_BITS; 352 353 err = ice_cfg_promisc(vsi, promisc_m, false); 354 if (err) { 355 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n", 356 vsi->vsi_num); 357 vsi->current_netdev_flags |= IFF_ALLMULTI; 358 goto out_promisc; 359 } 360 } 361 } 362 363 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) || 364 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) { 365 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags); 366 if (vsi->current_netdev_flags & IFF_PROMISC) { 367 /* Apply Rx filter rule to get traffic from wire */ 368 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) { 369 err = ice_set_dflt_vsi(pf->first_sw, vsi); 370 if (err && err != -EEXIST) { 371 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n", 372 err, vsi->vsi_num); 373 vsi->current_netdev_flags &= 374 ~IFF_PROMISC; 375 goto out_promisc; 376 } 377 ice_cfg_vlan_pruning(vsi, false, false); 378 } 379 } else { 380 /* Clear Rx filter to remove traffic from wire */ 381 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) { 382 err = ice_clear_dflt_vsi(pf->first_sw); 383 if (err) { 384 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n", 385 err, vsi->vsi_num); 386 vsi->current_netdev_flags |= 387 IFF_PROMISC; 388 goto out_promisc; 389 } 390 if (vsi->num_vlan > 1) 391 ice_cfg_vlan_pruning(vsi, true, false); 392 } 393 } 394 } 395 goto exit; 396 397 out_promisc: 398 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags); 399 goto exit; 400 out: 401 /* if something went wrong then set the changed flag so we try again */ 402 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags); 403 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags); 404 exit: 405 clear_bit(__ICE_CFG_BUSY, vsi->state); 406 return err; 407 } 408 409 /** 410 * ice_sync_fltr_subtask - Sync the VSI filter list with HW 411 * @pf: board private structure 412 */ 413 static void ice_sync_fltr_subtask(struct ice_pf *pf) 414 { 415 int v; 416 417 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags))) 418 return; 419 420 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags); 421 422 ice_for_each_vsi(pf, v) 423 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) && 424 ice_vsi_sync_fltr(pf->vsi[v])) { 425 /* come back and try again later */ 426 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags); 427 break; 428 } 429 } 430 431 /** 432 * ice_pf_dis_all_vsi - Pause all VSIs on a PF 433 * @pf: the PF 434 * @locked: is the rtnl_lock already held 435 */ 436 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked) 437 { 438 int node; 439 int v; 440 441 ice_for_each_vsi(pf, v) 442 if (pf->vsi[v]) 443 ice_dis_vsi(pf->vsi[v], locked); 444 445 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++) 446 pf->pf_agg_node[node].num_vsis = 0; 447 448 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++) 449 pf->vf_agg_node[node].num_vsis = 0; 450 451 } 452 453 /** 454 * ice_prepare_for_reset - prep for the core to reset 455 * @pf: board private structure 456 * 457 * Inform or close all dependent features in prep for reset. 458 */ 459 static void 460 ice_prepare_for_reset(struct ice_pf *pf) 461 { 462 struct ice_hw *hw = &pf->hw; 463 unsigned int i; 464 465 /* already prepared for reset */ 466 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) 467 return; 468 469 /* Notify VFs of impending reset */ 470 if (ice_check_sq_alive(hw, &hw->mailboxq)) 471 ice_vc_notify_reset(pf); 472 473 /* Disable VFs until reset is completed */ 474 ice_for_each_vf(pf, i) 475 ice_set_vf_state_qs_dis(&pf->vf[i]); 476 477 /* clear SW filtering DB */ 478 ice_clear_hw_tbls(hw); 479 /* disable the VSIs and their queues that are not already DOWN */ 480 ice_pf_dis_all_vsi(pf, false); 481 482 if (hw->port_info) 483 ice_sched_clear_port(hw->port_info); 484 485 ice_shutdown_all_ctrlq(hw); 486 487 set_bit(__ICE_PREPARED_FOR_RESET, pf->state); 488 } 489 490 /** 491 * ice_do_reset - Initiate one of many types of resets 492 * @pf: board private structure 493 * @reset_type: reset type requested 494 * before this function was called. 495 */ 496 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type) 497 { 498 struct device *dev = ice_pf_to_dev(pf); 499 struct ice_hw *hw = &pf->hw; 500 501 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type); 502 503 ice_prepare_for_reset(pf); 504 505 /* trigger the reset */ 506 if (ice_reset(hw, reset_type)) { 507 dev_err(dev, "reset %d failed\n", reset_type); 508 set_bit(__ICE_RESET_FAILED, pf->state); 509 clear_bit(__ICE_RESET_OICR_RECV, pf->state); 510 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state); 511 clear_bit(__ICE_PFR_REQ, pf->state); 512 clear_bit(__ICE_CORER_REQ, pf->state); 513 clear_bit(__ICE_GLOBR_REQ, pf->state); 514 return; 515 } 516 517 /* PFR is a bit of a special case because it doesn't result in an OICR 518 * interrupt. So for PFR, rebuild after the reset and clear the reset- 519 * associated state bits. 520 */ 521 if (reset_type == ICE_RESET_PFR) { 522 pf->pfr_count++; 523 ice_rebuild(pf, reset_type); 524 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state); 525 clear_bit(__ICE_PFR_REQ, pf->state); 526 ice_reset_all_vfs(pf, true); 527 } 528 } 529 530 /** 531 * ice_reset_subtask - Set up for resetting the device and driver 532 * @pf: board private structure 533 */ 534 static void ice_reset_subtask(struct ice_pf *pf) 535 { 536 enum ice_reset_req reset_type = ICE_RESET_INVAL; 537 538 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an 539 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type 540 * of reset is pending and sets bits in pf->state indicating the reset 541 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set 542 * prepare for pending reset if not already (for PF software-initiated 543 * global resets the software should already be prepared for it as 544 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated 545 * by firmware or software on other PFs, that bit is not set so prepare 546 * for the reset now), poll for reset done, rebuild and return. 547 */ 548 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) { 549 /* Perform the largest reset requested */ 550 if (test_and_clear_bit(__ICE_CORER_RECV, pf->state)) 551 reset_type = ICE_RESET_CORER; 552 if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state)) 553 reset_type = ICE_RESET_GLOBR; 554 if (test_and_clear_bit(__ICE_EMPR_RECV, pf->state)) 555 reset_type = ICE_RESET_EMPR; 556 /* return if no valid reset type requested */ 557 if (reset_type == ICE_RESET_INVAL) 558 return; 559 ice_prepare_for_reset(pf); 560 561 /* make sure we are ready to rebuild */ 562 if (ice_check_reset(&pf->hw)) { 563 set_bit(__ICE_RESET_FAILED, pf->state); 564 } else { 565 /* done with reset. start rebuild */ 566 pf->hw.reset_ongoing = false; 567 ice_rebuild(pf, reset_type); 568 /* clear bit to resume normal operations, but 569 * ICE_NEEDS_RESTART bit is set in case rebuild failed 570 */ 571 clear_bit(__ICE_RESET_OICR_RECV, pf->state); 572 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state); 573 clear_bit(__ICE_PFR_REQ, pf->state); 574 clear_bit(__ICE_CORER_REQ, pf->state); 575 clear_bit(__ICE_GLOBR_REQ, pf->state); 576 ice_reset_all_vfs(pf, true); 577 } 578 579 return; 580 } 581 582 /* No pending resets to finish processing. Check for new resets */ 583 if (test_bit(__ICE_PFR_REQ, pf->state)) 584 reset_type = ICE_RESET_PFR; 585 if (test_bit(__ICE_CORER_REQ, pf->state)) 586 reset_type = ICE_RESET_CORER; 587 if (test_bit(__ICE_GLOBR_REQ, pf->state)) 588 reset_type = ICE_RESET_GLOBR; 589 /* If no valid reset type requested just return */ 590 if (reset_type == ICE_RESET_INVAL) 591 return; 592 593 /* reset if not already down or busy */ 594 if (!test_bit(__ICE_DOWN, pf->state) && 595 !test_bit(__ICE_CFG_BUSY, pf->state)) { 596 ice_do_reset(pf, reset_type); 597 } 598 } 599 600 /** 601 * ice_print_topo_conflict - print topology conflict message 602 * @vsi: the VSI whose topology status is being checked 603 */ 604 static void ice_print_topo_conflict(struct ice_vsi *vsi) 605 { 606 switch (vsi->port_info->phy.link_info.topo_media_conflict) { 607 case ICE_AQ_LINK_TOPO_CONFLICT: 608 case ICE_AQ_LINK_MEDIA_CONFLICT: 609 case ICE_AQ_LINK_TOPO_UNREACH_PRT: 610 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT: 611 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA: 612 netdev_info(vsi->netdev, "Possible mis-configuration of the Ethernet port detected, please use the Intel(R) Ethernet Port Configuration Tool application to address the issue.\n"); 613 break; 614 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA: 615 netdev_info(vsi->netdev, "Rx/Tx is disabled on this device because an unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); 616 break; 617 default: 618 break; 619 } 620 } 621 622 /** 623 * ice_print_link_msg - print link up or down message 624 * @vsi: the VSI whose link status is being queried 625 * @isup: boolean for if the link is now up or down 626 */ 627 void ice_print_link_msg(struct ice_vsi *vsi, bool isup) 628 { 629 struct ice_aqc_get_phy_caps_data *caps; 630 const char *an_advertised; 631 enum ice_status status; 632 const char *fec_req; 633 const char *speed; 634 const char *fec; 635 const char *fc; 636 const char *an; 637 638 if (!vsi) 639 return; 640 641 if (vsi->current_isup == isup) 642 return; 643 644 vsi->current_isup = isup; 645 646 if (!isup) { 647 netdev_info(vsi->netdev, "NIC Link is Down\n"); 648 return; 649 } 650 651 switch (vsi->port_info->phy.link_info.link_speed) { 652 case ICE_AQ_LINK_SPEED_100GB: 653 speed = "100 G"; 654 break; 655 case ICE_AQ_LINK_SPEED_50GB: 656 speed = "50 G"; 657 break; 658 case ICE_AQ_LINK_SPEED_40GB: 659 speed = "40 G"; 660 break; 661 case ICE_AQ_LINK_SPEED_25GB: 662 speed = "25 G"; 663 break; 664 case ICE_AQ_LINK_SPEED_20GB: 665 speed = "20 G"; 666 break; 667 case ICE_AQ_LINK_SPEED_10GB: 668 speed = "10 G"; 669 break; 670 case ICE_AQ_LINK_SPEED_5GB: 671 speed = "5 G"; 672 break; 673 case ICE_AQ_LINK_SPEED_2500MB: 674 speed = "2.5 G"; 675 break; 676 case ICE_AQ_LINK_SPEED_1000MB: 677 speed = "1 G"; 678 break; 679 case ICE_AQ_LINK_SPEED_100MB: 680 speed = "100 M"; 681 break; 682 default: 683 speed = "Unknown "; 684 break; 685 } 686 687 switch (vsi->port_info->fc.current_mode) { 688 case ICE_FC_FULL: 689 fc = "Rx/Tx"; 690 break; 691 case ICE_FC_TX_PAUSE: 692 fc = "Tx"; 693 break; 694 case ICE_FC_RX_PAUSE: 695 fc = "Rx"; 696 break; 697 case ICE_FC_NONE: 698 fc = "None"; 699 break; 700 default: 701 fc = "Unknown"; 702 break; 703 } 704 705 /* Get FEC mode based on negotiated link info */ 706 switch (vsi->port_info->phy.link_info.fec_info) { 707 case ICE_AQ_LINK_25G_RS_528_FEC_EN: 708 case ICE_AQ_LINK_25G_RS_544_FEC_EN: 709 fec = "RS-FEC"; 710 break; 711 case ICE_AQ_LINK_25G_KR_FEC_EN: 712 fec = "FC-FEC/BASE-R"; 713 break; 714 default: 715 fec = "NONE"; 716 break; 717 } 718 719 /* check if autoneg completed, might be false due to not supported */ 720 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) 721 an = "True"; 722 else 723 an = "False"; 724 725 /* Get FEC mode requested based on PHY caps last SW configuration */ 726 caps = kzalloc(sizeof(*caps), GFP_KERNEL); 727 if (!caps) { 728 fec_req = "Unknown"; 729 an_advertised = "Unknown"; 730 goto done; 731 } 732 733 status = ice_aq_get_phy_caps(vsi->port_info, false, 734 ICE_AQC_REPORT_SW_CFG, caps, NULL); 735 if (status) 736 netdev_info(vsi->netdev, "Get phy capability failed.\n"); 737 738 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off"; 739 740 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ || 741 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ) 742 fec_req = "RS-FEC"; 743 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ || 744 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ) 745 fec_req = "FC-FEC/BASE-R"; 746 else 747 fec_req = "NONE"; 748 749 kfree(caps); 750 751 done: 752 netdev_info(vsi->netdev, "NIC Link is up %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg Advertised: %s, Autoneg Negotiated: %s, Flow Control: %s\n", 753 speed, fec_req, fec, an_advertised, an, fc); 754 ice_print_topo_conflict(vsi); 755 } 756 757 /** 758 * ice_vsi_link_event - update the VSI's netdev 759 * @vsi: the VSI on which the link event occurred 760 * @link_up: whether or not the VSI needs to be set up or down 761 */ 762 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) 763 { 764 if (!vsi) 765 return; 766 767 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev) 768 return; 769 770 if (vsi->type == ICE_VSI_PF) { 771 if (link_up == netif_carrier_ok(vsi->netdev)) 772 return; 773 774 if (link_up) { 775 netif_carrier_on(vsi->netdev); 776 netif_tx_wake_all_queues(vsi->netdev); 777 } else { 778 netif_carrier_off(vsi->netdev); 779 netif_tx_stop_all_queues(vsi->netdev); 780 } 781 } 782 } 783 784 /** 785 * ice_set_dflt_mib - send a default config MIB to the FW 786 * @pf: private PF struct 787 * 788 * This function sends a default configuration MIB to the FW. 789 * 790 * If this function errors out at any point, the driver is still able to 791 * function. The main impact is that LFC may not operate as expected. 792 * Therefore an error state in this function should be treated with a DBG 793 * message and continue on with driver rebuild/reenable. 794 */ 795 static void ice_set_dflt_mib(struct ice_pf *pf) 796 { 797 struct device *dev = ice_pf_to_dev(pf); 798 u8 mib_type, *buf, *lldpmib = NULL; 799 u16 len, typelen, offset = 0; 800 struct ice_lldp_org_tlv *tlv; 801 struct ice_hw *hw = &pf->hw; 802 u32 ouisubtype; 803 804 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB; 805 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL); 806 if (!lldpmib) { 807 dev_dbg(dev, "%s Failed to allocate MIB memory\n", 808 __func__); 809 return; 810 } 811 812 /* Add ETS CFG TLV */ 813 tlv = (struct ice_lldp_org_tlv *)lldpmib; 814 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | 815 ICE_IEEE_ETS_TLV_LEN); 816 tlv->typelen = htons(typelen); 817 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 818 ICE_IEEE_SUBTYPE_ETS_CFG); 819 tlv->ouisubtype = htonl(ouisubtype); 820 821 buf = tlv->tlvinfo; 822 buf[0] = 0; 823 824 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0. 825 * Octets 5 - 12 are BW values, set octet 5 to 100% BW. 826 * Octets 13 - 20 are TSA values - leave as zeros 827 */ 828 buf[5] = 0x64; 829 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S; 830 offset += len + 2; 831 tlv = (struct ice_lldp_org_tlv *) 832 ((char *)tlv + sizeof(tlv->typelen) + len); 833 834 /* Add ETS REC TLV */ 835 buf = tlv->tlvinfo; 836 tlv->typelen = htons(typelen); 837 838 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 839 ICE_IEEE_SUBTYPE_ETS_REC); 840 tlv->ouisubtype = htonl(ouisubtype); 841 842 /* First octet of buf is reserved 843 * Octets 1 - 4 map UP to TC - all UPs map to zero 844 * Octets 5 - 12 are BW values - set TC 0 to 100%. 845 * Octets 13 - 20 are TSA value - leave as zeros 846 */ 847 buf[5] = 0x64; 848 offset += len + 2; 849 tlv = (struct ice_lldp_org_tlv *) 850 ((char *)tlv + sizeof(tlv->typelen) + len); 851 852 /* Add PFC CFG TLV */ 853 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | 854 ICE_IEEE_PFC_TLV_LEN); 855 tlv->typelen = htons(typelen); 856 857 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 858 ICE_IEEE_SUBTYPE_PFC_CFG); 859 tlv->ouisubtype = htonl(ouisubtype); 860 861 /* Octet 1 left as all zeros - PFC disabled */ 862 buf[0] = 0x08; 863 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S; 864 offset += len + 2; 865 866 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL)) 867 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__); 868 869 kfree(lldpmib); 870 } 871 872 /** 873 * ice_link_event - process the link event 874 * @pf: PF that the link event is associated with 875 * @pi: port_info for the port that the link event is associated with 876 * @link_up: true if the physical link is up and false if it is down 877 * @link_speed: current link speed received from the link event 878 * 879 * Returns 0 on success and negative on failure 880 */ 881 static int 882 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up, 883 u16 link_speed) 884 { 885 struct device *dev = ice_pf_to_dev(pf); 886 struct ice_phy_info *phy_info; 887 struct ice_vsi *vsi; 888 u16 old_link_speed; 889 bool old_link; 890 int result; 891 892 phy_info = &pi->phy; 893 phy_info->link_info_old = phy_info->link_info; 894 895 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP); 896 old_link_speed = phy_info->link_info_old.link_speed; 897 898 /* update the link info structures and re-enable link events, 899 * don't bail on failure due to other book keeping needed 900 */ 901 result = ice_update_link_info(pi); 902 if (result) 903 dev_dbg(dev, "Failed to update link status and re-enable link events for port %d\n", 904 pi->lport); 905 906 /* Check if the link state is up after updating link info, and treat 907 * this event as an UP event since the link is actually UP now. 908 */ 909 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP) 910 link_up = true; 911 912 vsi = ice_get_main_vsi(pf); 913 if (!vsi || !vsi->port_info) 914 return -EINVAL; 915 916 /* turn off PHY if media was removed */ 917 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) && 918 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) { 919 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 920 921 result = ice_aq_set_link_restart_an(pi, false, NULL); 922 if (result) { 923 dev_dbg(dev, "Failed to set link down, VSI %d error %d\n", 924 vsi->vsi_num, result); 925 return result; 926 } 927 } 928 929 /* if the old link up/down and speed is the same as the new */ 930 if (link_up == old_link && link_speed == old_link_speed) 931 return result; 932 933 if (ice_is_dcb_active(pf)) { 934 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags)) 935 ice_dcb_rebuild(pf); 936 } else { 937 if (link_up) 938 ice_set_dflt_mib(pf); 939 } 940 ice_vsi_link_event(vsi, link_up); 941 ice_print_link_msg(vsi, link_up); 942 943 ice_vc_notify_link_state(pf); 944 945 return result; 946 } 947 948 /** 949 * ice_watchdog_subtask - periodic tasks not using event driven scheduling 950 * @pf: board private structure 951 */ 952 static void ice_watchdog_subtask(struct ice_pf *pf) 953 { 954 int i; 955 956 /* if interface is down do nothing */ 957 if (test_bit(__ICE_DOWN, pf->state) || 958 test_bit(__ICE_CFG_BUSY, pf->state)) 959 return; 960 961 /* make sure we don't do these things too often */ 962 if (time_before(jiffies, 963 pf->serv_tmr_prev + pf->serv_tmr_period)) 964 return; 965 966 pf->serv_tmr_prev = jiffies; 967 968 /* Update the stats for active netdevs so the network stack 969 * can look at updated numbers whenever it cares to 970 */ 971 ice_update_pf_stats(pf); 972 ice_for_each_vsi(pf, i) 973 if (pf->vsi[i] && pf->vsi[i]->netdev) 974 ice_update_vsi_stats(pf->vsi[i]); 975 } 976 977 /** 978 * ice_init_link_events - enable/initialize link events 979 * @pi: pointer to the port_info instance 980 * 981 * Returns -EIO on failure, 0 on success 982 */ 983 static int ice_init_link_events(struct ice_port_info *pi) 984 { 985 u16 mask; 986 987 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA | 988 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL)); 989 990 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) { 991 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n", 992 pi->lport); 993 return -EIO; 994 } 995 996 if (ice_aq_get_link_info(pi, true, NULL, NULL)) { 997 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n", 998 pi->lport); 999 return -EIO; 1000 } 1001 1002 return 0; 1003 } 1004 1005 /** 1006 * ice_handle_link_event - handle link event via ARQ 1007 * @pf: PF that the link event is associated with 1008 * @event: event structure containing link status info 1009 */ 1010 static int 1011 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event) 1012 { 1013 struct ice_aqc_get_link_status_data *link_data; 1014 struct ice_port_info *port_info; 1015 int status; 1016 1017 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf; 1018 port_info = pf->hw.port_info; 1019 if (!port_info) 1020 return -EINVAL; 1021 1022 status = ice_link_event(pf, port_info, 1023 !!(link_data->link_info & ICE_AQ_LINK_UP), 1024 le16_to_cpu(link_data->link_speed)); 1025 if (status) 1026 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n", 1027 status); 1028 1029 return status; 1030 } 1031 1032 enum ice_aq_task_state { 1033 ICE_AQ_TASK_WAITING = 0, 1034 ICE_AQ_TASK_COMPLETE, 1035 ICE_AQ_TASK_CANCELED, 1036 }; 1037 1038 struct ice_aq_task { 1039 struct hlist_node entry; 1040 1041 u16 opcode; 1042 struct ice_rq_event_info *event; 1043 enum ice_aq_task_state state; 1044 }; 1045 1046 /** 1047 * ice_wait_for_aq_event - Wait for an AdminQ event from firmware 1048 * @pf: pointer to the PF private structure 1049 * @opcode: the opcode to wait for 1050 * @timeout: how long to wait, in jiffies 1051 * @event: storage for the event info 1052 * 1053 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The 1054 * current thread will be put to sleep until the specified event occurs or 1055 * until the given timeout is reached. 1056 * 1057 * To obtain only the descriptor contents, pass an event without an allocated 1058 * msg_buf. If the complete data buffer is desired, allocate the 1059 * event->msg_buf with enough space ahead of time. 1060 * 1061 * Returns: zero on success, or a negative error code on failure. 1062 */ 1063 int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout, 1064 struct ice_rq_event_info *event) 1065 { 1066 struct device *dev = ice_pf_to_dev(pf); 1067 struct ice_aq_task *task; 1068 unsigned long start; 1069 long ret; 1070 int err; 1071 1072 task = kzalloc(sizeof(*task), GFP_KERNEL); 1073 if (!task) 1074 return -ENOMEM; 1075 1076 INIT_HLIST_NODE(&task->entry); 1077 task->opcode = opcode; 1078 task->event = event; 1079 task->state = ICE_AQ_TASK_WAITING; 1080 1081 spin_lock_bh(&pf->aq_wait_lock); 1082 hlist_add_head(&task->entry, &pf->aq_wait_list); 1083 spin_unlock_bh(&pf->aq_wait_lock); 1084 1085 start = jiffies; 1086 1087 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state, 1088 timeout); 1089 switch (task->state) { 1090 case ICE_AQ_TASK_WAITING: 1091 err = ret < 0 ? ret : -ETIMEDOUT; 1092 break; 1093 case ICE_AQ_TASK_CANCELED: 1094 err = ret < 0 ? ret : -ECANCELED; 1095 break; 1096 case ICE_AQ_TASK_COMPLETE: 1097 err = ret < 0 ? ret : 0; 1098 break; 1099 default: 1100 WARN(1, "Unexpected AdminQ wait task state %u", task->state); 1101 err = -EINVAL; 1102 break; 1103 } 1104 1105 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n", 1106 jiffies_to_msecs(jiffies - start), 1107 jiffies_to_msecs(timeout), 1108 opcode); 1109 1110 spin_lock_bh(&pf->aq_wait_lock); 1111 hlist_del(&task->entry); 1112 spin_unlock_bh(&pf->aq_wait_lock); 1113 kfree(task); 1114 1115 return err; 1116 } 1117 1118 /** 1119 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event 1120 * @pf: pointer to the PF private structure 1121 * @opcode: the opcode of the event 1122 * @event: the event to check 1123 * 1124 * Loops over the current list of pending threads waiting for an AdminQ event. 1125 * For each matching task, copy the contents of the event into the task 1126 * structure and wake up the thread. 1127 * 1128 * If multiple threads wait for the same opcode, they will all be woken up. 1129 * 1130 * Note that event->msg_buf will only be duplicated if the event has a buffer 1131 * with enough space already allocated. Otherwise, only the descriptor and 1132 * message length will be copied. 1133 * 1134 * Returns: true if an event was found, false otherwise 1135 */ 1136 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode, 1137 struct ice_rq_event_info *event) 1138 { 1139 struct ice_aq_task *task; 1140 bool found = false; 1141 1142 spin_lock_bh(&pf->aq_wait_lock); 1143 hlist_for_each_entry(task, &pf->aq_wait_list, entry) { 1144 if (task->state || task->opcode != opcode) 1145 continue; 1146 1147 memcpy(&task->event->desc, &event->desc, sizeof(event->desc)); 1148 task->event->msg_len = event->msg_len; 1149 1150 /* Only copy the data buffer if a destination was set */ 1151 if (task->event->msg_buf && 1152 task->event->buf_len > event->buf_len) { 1153 memcpy(task->event->msg_buf, event->msg_buf, 1154 event->buf_len); 1155 task->event->buf_len = event->buf_len; 1156 } 1157 1158 task->state = ICE_AQ_TASK_COMPLETE; 1159 found = true; 1160 } 1161 spin_unlock_bh(&pf->aq_wait_lock); 1162 1163 if (found) 1164 wake_up(&pf->aq_wait_queue); 1165 } 1166 1167 /** 1168 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks 1169 * @pf: the PF private structure 1170 * 1171 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads. 1172 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED. 1173 */ 1174 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf) 1175 { 1176 struct ice_aq_task *task; 1177 1178 spin_lock_bh(&pf->aq_wait_lock); 1179 hlist_for_each_entry(task, &pf->aq_wait_list, entry) 1180 task->state = ICE_AQ_TASK_CANCELED; 1181 spin_unlock_bh(&pf->aq_wait_lock); 1182 1183 wake_up(&pf->aq_wait_queue); 1184 } 1185 1186 /** 1187 * __ice_clean_ctrlq - helper function to clean controlq rings 1188 * @pf: ptr to struct ice_pf 1189 * @q_type: specific Control queue type 1190 */ 1191 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type) 1192 { 1193 struct device *dev = ice_pf_to_dev(pf); 1194 struct ice_rq_event_info event; 1195 struct ice_hw *hw = &pf->hw; 1196 struct ice_ctl_q_info *cq; 1197 u16 pending, i = 0; 1198 const char *qtype; 1199 u32 oldval, val; 1200 1201 /* Do not clean control queue if/when PF reset fails */ 1202 if (test_bit(__ICE_RESET_FAILED, pf->state)) 1203 return 0; 1204 1205 switch (q_type) { 1206 case ICE_CTL_Q_ADMIN: 1207 cq = &hw->adminq; 1208 qtype = "Admin"; 1209 break; 1210 case ICE_CTL_Q_MAILBOX: 1211 cq = &hw->mailboxq; 1212 qtype = "Mailbox"; 1213 break; 1214 default: 1215 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type); 1216 return 0; 1217 } 1218 1219 /* check for error indications - PF_xx_AxQLEN register layout for 1220 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN. 1221 */ 1222 val = rd32(hw, cq->rq.len); 1223 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | 1224 PF_FW_ARQLEN_ARQCRIT_M)) { 1225 oldval = val; 1226 if (val & PF_FW_ARQLEN_ARQVFE_M) 1227 dev_dbg(dev, "%s Receive Queue VF Error detected\n", 1228 qtype); 1229 if (val & PF_FW_ARQLEN_ARQOVFL_M) { 1230 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n", 1231 qtype); 1232 } 1233 if (val & PF_FW_ARQLEN_ARQCRIT_M) 1234 dev_dbg(dev, "%s Receive Queue Critical Error detected\n", 1235 qtype); 1236 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | 1237 PF_FW_ARQLEN_ARQCRIT_M); 1238 if (oldval != val) 1239 wr32(hw, cq->rq.len, val); 1240 } 1241 1242 val = rd32(hw, cq->sq.len); 1243 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | 1244 PF_FW_ATQLEN_ATQCRIT_M)) { 1245 oldval = val; 1246 if (val & PF_FW_ATQLEN_ATQVFE_M) 1247 dev_dbg(dev, "%s Send Queue VF Error detected\n", 1248 qtype); 1249 if (val & PF_FW_ATQLEN_ATQOVFL_M) { 1250 dev_dbg(dev, "%s Send Queue Overflow Error detected\n", 1251 qtype); 1252 } 1253 if (val & PF_FW_ATQLEN_ATQCRIT_M) 1254 dev_dbg(dev, "%s Send Queue Critical Error detected\n", 1255 qtype); 1256 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | 1257 PF_FW_ATQLEN_ATQCRIT_M); 1258 if (oldval != val) 1259 wr32(hw, cq->sq.len, val); 1260 } 1261 1262 event.buf_len = cq->rq_buf_size; 1263 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 1264 if (!event.msg_buf) 1265 return 0; 1266 1267 do { 1268 enum ice_status ret; 1269 u16 opcode; 1270 1271 ret = ice_clean_rq_elem(hw, cq, &event, &pending); 1272 if (ret == ICE_ERR_AQ_NO_WORK) 1273 break; 1274 if (ret) { 1275 dev_err(dev, "%s Receive Queue event error %s\n", qtype, 1276 ice_stat_str(ret)); 1277 break; 1278 } 1279 1280 opcode = le16_to_cpu(event.desc.opcode); 1281 1282 /* Notify any thread that might be waiting for this event */ 1283 ice_aq_check_events(pf, opcode, &event); 1284 1285 switch (opcode) { 1286 case ice_aqc_opc_get_link_status: 1287 if (ice_handle_link_event(pf, &event)) 1288 dev_err(dev, "Could not handle link event\n"); 1289 break; 1290 case ice_aqc_opc_event_lan_overflow: 1291 ice_vf_lan_overflow_event(pf, &event); 1292 break; 1293 case ice_mbx_opc_send_msg_to_pf: 1294 ice_vc_process_vf_msg(pf, &event); 1295 break; 1296 case ice_aqc_opc_fw_logging: 1297 ice_output_fw_log(hw, &event.desc, event.msg_buf); 1298 break; 1299 case ice_aqc_opc_lldp_set_mib_change: 1300 ice_dcb_process_lldp_set_mib_change(pf, &event); 1301 break; 1302 default: 1303 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n", 1304 qtype, opcode); 1305 break; 1306 } 1307 } while (pending && (i++ < ICE_DFLT_IRQ_WORK)); 1308 1309 kfree(event.msg_buf); 1310 1311 return pending && (i == ICE_DFLT_IRQ_WORK); 1312 } 1313 1314 /** 1315 * ice_ctrlq_pending - check if there is a difference between ntc and ntu 1316 * @hw: pointer to hardware info 1317 * @cq: control queue information 1318 * 1319 * returns true if there are pending messages in a queue, false if there aren't 1320 */ 1321 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq) 1322 { 1323 u16 ntu; 1324 1325 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask); 1326 return cq->rq.next_to_clean != ntu; 1327 } 1328 1329 /** 1330 * ice_clean_adminq_subtask - clean the AdminQ rings 1331 * @pf: board private structure 1332 */ 1333 static void ice_clean_adminq_subtask(struct ice_pf *pf) 1334 { 1335 struct ice_hw *hw = &pf->hw; 1336 1337 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state)) 1338 return; 1339 1340 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN)) 1341 return; 1342 1343 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state); 1344 1345 /* There might be a situation where new messages arrive to a control 1346 * queue between processing the last message and clearing the 1347 * EVENT_PENDING bit. So before exiting, check queue head again (using 1348 * ice_ctrlq_pending) and process new messages if any. 1349 */ 1350 if (ice_ctrlq_pending(hw, &hw->adminq)) 1351 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN); 1352 1353 ice_flush(hw); 1354 } 1355 1356 /** 1357 * ice_clean_mailboxq_subtask - clean the MailboxQ rings 1358 * @pf: board private structure 1359 */ 1360 static void ice_clean_mailboxq_subtask(struct ice_pf *pf) 1361 { 1362 struct ice_hw *hw = &pf->hw; 1363 1364 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state)) 1365 return; 1366 1367 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX)) 1368 return; 1369 1370 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state); 1371 1372 if (ice_ctrlq_pending(hw, &hw->mailboxq)) 1373 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX); 1374 1375 ice_flush(hw); 1376 } 1377 1378 /** 1379 * ice_service_task_schedule - schedule the service task to wake up 1380 * @pf: board private structure 1381 * 1382 * If not already scheduled, this puts the task into the work queue. 1383 */ 1384 void ice_service_task_schedule(struct ice_pf *pf) 1385 { 1386 if (!test_bit(__ICE_SERVICE_DIS, pf->state) && 1387 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) && 1388 !test_bit(__ICE_NEEDS_RESTART, pf->state)) 1389 queue_work(ice_wq, &pf->serv_task); 1390 } 1391 1392 /** 1393 * ice_service_task_complete - finish up the service task 1394 * @pf: board private structure 1395 */ 1396 static void ice_service_task_complete(struct ice_pf *pf) 1397 { 1398 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state)); 1399 1400 /* force memory (pf->state) to sync before next service task */ 1401 smp_mb__before_atomic(); 1402 clear_bit(__ICE_SERVICE_SCHED, pf->state); 1403 } 1404 1405 /** 1406 * ice_service_task_stop - stop service task and cancel works 1407 * @pf: board private structure 1408 * 1409 * Return 0 if the __ICE_SERVICE_DIS bit was not already set, 1410 * 1 otherwise. 1411 */ 1412 static int ice_service_task_stop(struct ice_pf *pf) 1413 { 1414 int ret; 1415 1416 ret = test_and_set_bit(__ICE_SERVICE_DIS, pf->state); 1417 1418 if (pf->serv_tmr.function) 1419 del_timer_sync(&pf->serv_tmr); 1420 if (pf->serv_task.func) 1421 cancel_work_sync(&pf->serv_task); 1422 1423 clear_bit(__ICE_SERVICE_SCHED, pf->state); 1424 return ret; 1425 } 1426 1427 /** 1428 * ice_service_task_restart - restart service task and schedule works 1429 * @pf: board private structure 1430 * 1431 * This function is needed for suspend and resume works (e.g WoL scenario) 1432 */ 1433 static void ice_service_task_restart(struct ice_pf *pf) 1434 { 1435 clear_bit(__ICE_SERVICE_DIS, pf->state); 1436 ice_service_task_schedule(pf); 1437 } 1438 1439 /** 1440 * ice_service_timer - timer callback to schedule service task 1441 * @t: pointer to timer_list 1442 */ 1443 static void ice_service_timer(struct timer_list *t) 1444 { 1445 struct ice_pf *pf = from_timer(pf, t, serv_tmr); 1446 1447 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies)); 1448 ice_service_task_schedule(pf); 1449 } 1450 1451 /** 1452 * ice_handle_mdd_event - handle malicious driver detect event 1453 * @pf: pointer to the PF structure 1454 * 1455 * Called from service task. OICR interrupt handler indicates MDD event. 1456 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log 1457 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events 1458 * disable the queue, the PF can be configured to reset the VF using ethtool 1459 * private flag mdd-auto-reset-vf. 1460 */ 1461 static void ice_handle_mdd_event(struct ice_pf *pf) 1462 { 1463 struct device *dev = ice_pf_to_dev(pf); 1464 struct ice_hw *hw = &pf->hw; 1465 unsigned int i; 1466 u32 reg; 1467 1468 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state)) { 1469 /* Since the VF MDD event logging is rate limited, check if 1470 * there are pending MDD events. 1471 */ 1472 ice_print_vfs_mdd_events(pf); 1473 return; 1474 } 1475 1476 /* find what triggered an MDD event */ 1477 reg = rd32(hw, GL_MDET_TX_PQM); 1478 if (reg & GL_MDET_TX_PQM_VALID_M) { 1479 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >> 1480 GL_MDET_TX_PQM_PF_NUM_S; 1481 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >> 1482 GL_MDET_TX_PQM_VF_NUM_S; 1483 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >> 1484 GL_MDET_TX_PQM_MAL_TYPE_S; 1485 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >> 1486 GL_MDET_TX_PQM_QNUM_S); 1487 1488 if (netif_msg_tx_err(pf)) 1489 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", 1490 event, queue, pf_num, vf_num); 1491 wr32(hw, GL_MDET_TX_PQM, 0xffffffff); 1492 } 1493 1494 reg = rd32(hw, GL_MDET_TX_TCLAN); 1495 if (reg & GL_MDET_TX_TCLAN_VALID_M) { 1496 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >> 1497 GL_MDET_TX_TCLAN_PF_NUM_S; 1498 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >> 1499 GL_MDET_TX_TCLAN_VF_NUM_S; 1500 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >> 1501 GL_MDET_TX_TCLAN_MAL_TYPE_S; 1502 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >> 1503 GL_MDET_TX_TCLAN_QNUM_S); 1504 1505 if (netif_msg_tx_err(pf)) 1506 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", 1507 event, queue, pf_num, vf_num); 1508 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff); 1509 } 1510 1511 reg = rd32(hw, GL_MDET_RX); 1512 if (reg & GL_MDET_RX_VALID_M) { 1513 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >> 1514 GL_MDET_RX_PF_NUM_S; 1515 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >> 1516 GL_MDET_RX_VF_NUM_S; 1517 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >> 1518 GL_MDET_RX_MAL_TYPE_S; 1519 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >> 1520 GL_MDET_RX_QNUM_S); 1521 1522 if (netif_msg_rx_err(pf)) 1523 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n", 1524 event, queue, pf_num, vf_num); 1525 wr32(hw, GL_MDET_RX, 0xffffffff); 1526 } 1527 1528 /* check to see if this PF caused an MDD event */ 1529 reg = rd32(hw, PF_MDET_TX_PQM); 1530 if (reg & PF_MDET_TX_PQM_VALID_M) { 1531 wr32(hw, PF_MDET_TX_PQM, 0xFFFF); 1532 if (netif_msg_tx_err(pf)) 1533 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n"); 1534 } 1535 1536 reg = rd32(hw, PF_MDET_TX_TCLAN); 1537 if (reg & PF_MDET_TX_TCLAN_VALID_M) { 1538 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF); 1539 if (netif_msg_tx_err(pf)) 1540 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n"); 1541 } 1542 1543 reg = rd32(hw, PF_MDET_RX); 1544 if (reg & PF_MDET_RX_VALID_M) { 1545 wr32(hw, PF_MDET_RX, 0xFFFF); 1546 if (netif_msg_rx_err(pf)) 1547 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n"); 1548 } 1549 1550 /* Check to see if one of the VFs caused an MDD event, and then 1551 * increment counters and set print pending 1552 */ 1553 ice_for_each_vf(pf, i) { 1554 struct ice_vf *vf = &pf->vf[i]; 1555 1556 reg = rd32(hw, VP_MDET_TX_PQM(i)); 1557 if (reg & VP_MDET_TX_PQM_VALID_M) { 1558 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF); 1559 vf->mdd_tx_events.count++; 1560 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state); 1561 if (netif_msg_tx_err(pf)) 1562 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n", 1563 i); 1564 } 1565 1566 reg = rd32(hw, VP_MDET_TX_TCLAN(i)); 1567 if (reg & VP_MDET_TX_TCLAN_VALID_M) { 1568 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF); 1569 vf->mdd_tx_events.count++; 1570 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state); 1571 if (netif_msg_tx_err(pf)) 1572 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n", 1573 i); 1574 } 1575 1576 reg = rd32(hw, VP_MDET_TX_TDPU(i)); 1577 if (reg & VP_MDET_TX_TDPU_VALID_M) { 1578 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF); 1579 vf->mdd_tx_events.count++; 1580 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state); 1581 if (netif_msg_tx_err(pf)) 1582 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n", 1583 i); 1584 } 1585 1586 reg = rd32(hw, VP_MDET_RX(i)); 1587 if (reg & VP_MDET_RX_VALID_M) { 1588 wr32(hw, VP_MDET_RX(i), 0xFFFF); 1589 vf->mdd_rx_events.count++; 1590 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state); 1591 if (netif_msg_rx_err(pf)) 1592 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n", 1593 i); 1594 1595 /* Since the queue is disabled on VF Rx MDD events, the 1596 * PF can be configured to reset the VF through ethtool 1597 * private flag mdd-auto-reset-vf. 1598 */ 1599 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) { 1600 /* VF MDD event counters will be cleared by 1601 * reset, so print the event prior to reset. 1602 */ 1603 ice_print_vf_rx_mdd_event(vf); 1604 ice_reset_vf(&pf->vf[i], false); 1605 } 1606 } 1607 } 1608 1609 ice_print_vfs_mdd_events(pf); 1610 } 1611 1612 /** 1613 * ice_force_phys_link_state - Force the physical link state 1614 * @vsi: VSI to force the physical link state to up/down 1615 * @link_up: true/false indicates to set the physical link to up/down 1616 * 1617 * Force the physical link state by getting the current PHY capabilities from 1618 * hardware and setting the PHY config based on the determined capabilities. If 1619 * link changes a link event will be triggered because both the Enable Automatic 1620 * Link Update and LESM Enable bits are set when setting the PHY capabilities. 1621 * 1622 * Returns 0 on success, negative on failure 1623 */ 1624 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up) 1625 { 1626 struct ice_aqc_get_phy_caps_data *pcaps; 1627 struct ice_aqc_set_phy_cfg_data *cfg; 1628 struct ice_port_info *pi; 1629 struct device *dev; 1630 int retcode; 1631 1632 if (!vsi || !vsi->port_info || !vsi->back) 1633 return -EINVAL; 1634 if (vsi->type != ICE_VSI_PF) 1635 return 0; 1636 1637 dev = ice_pf_to_dev(vsi->back); 1638 1639 pi = vsi->port_info; 1640 1641 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 1642 if (!pcaps) 1643 return -ENOMEM; 1644 1645 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps, 1646 NULL); 1647 if (retcode) { 1648 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n", 1649 vsi->vsi_num, retcode); 1650 retcode = -EIO; 1651 goto out; 1652 } 1653 1654 /* No change in link */ 1655 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) && 1656 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP)) 1657 goto out; 1658 1659 /* Use the current user PHY configuration. The current user PHY 1660 * configuration is initialized during probe from PHY capabilities 1661 * software mode, and updated on set PHY configuration. 1662 */ 1663 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL); 1664 if (!cfg) { 1665 retcode = -ENOMEM; 1666 goto out; 1667 } 1668 1669 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 1670 if (link_up) 1671 cfg->caps |= ICE_AQ_PHY_ENA_LINK; 1672 else 1673 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK; 1674 1675 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL); 1676 if (retcode) { 1677 dev_err(dev, "Failed to set phy config, VSI %d error %d\n", 1678 vsi->vsi_num, retcode); 1679 retcode = -EIO; 1680 } 1681 1682 kfree(cfg); 1683 out: 1684 kfree(pcaps); 1685 return retcode; 1686 } 1687 1688 /** 1689 * ice_init_nvm_phy_type - Initialize the NVM PHY type 1690 * @pi: port info structure 1691 * 1692 * Initialize nvm_phy_type_[low|high] for link lenient mode support 1693 */ 1694 static int ice_init_nvm_phy_type(struct ice_port_info *pi) 1695 { 1696 struct ice_aqc_get_phy_caps_data *pcaps; 1697 struct ice_pf *pf = pi->hw->back; 1698 enum ice_status status; 1699 int err = 0; 1700 1701 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 1702 if (!pcaps) 1703 return -ENOMEM; 1704 1705 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_NVM_CAP, pcaps, 1706 NULL); 1707 1708 if (status) { 1709 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); 1710 err = -EIO; 1711 goto out; 1712 } 1713 1714 pf->nvm_phy_type_hi = pcaps->phy_type_high; 1715 pf->nvm_phy_type_lo = pcaps->phy_type_low; 1716 1717 out: 1718 kfree(pcaps); 1719 return err; 1720 } 1721 1722 /** 1723 * ice_init_link_dflt_override - Initialize link default override 1724 * @pi: port info structure 1725 * 1726 * Initialize link default override and PHY total port shutdown during probe 1727 */ 1728 static void ice_init_link_dflt_override(struct ice_port_info *pi) 1729 { 1730 struct ice_link_default_override_tlv *ldo; 1731 struct ice_pf *pf = pi->hw->back; 1732 1733 ldo = &pf->link_dflt_override; 1734 if (ice_get_link_default_override(ldo, pi)) 1735 return; 1736 1737 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS)) 1738 return; 1739 1740 /* Enable Total Port Shutdown (override/replace link-down-on-close 1741 * ethtool private flag) for ports with Port Disable bit set. 1742 */ 1743 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags); 1744 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags); 1745 } 1746 1747 /** 1748 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings 1749 * @pi: port info structure 1750 * 1751 * If default override is enabled, initialized the user PHY cfg speed and FEC 1752 * settings using the default override mask from the NVM. 1753 * 1754 * The PHY should only be configured with the default override settings the 1755 * first time media is available. The __ICE_LINK_DEFAULT_OVERRIDE_PENDING state 1756 * is used to indicate that the user PHY cfg default override is initialized 1757 * and the PHY has not been configured with the default override settings. The 1758 * state is set here, and cleared in ice_configure_phy the first time the PHY is 1759 * configured. 1760 */ 1761 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi) 1762 { 1763 struct ice_link_default_override_tlv *ldo; 1764 struct ice_aqc_set_phy_cfg_data *cfg; 1765 struct ice_phy_info *phy = &pi->phy; 1766 struct ice_pf *pf = pi->hw->back; 1767 1768 ldo = &pf->link_dflt_override; 1769 1770 /* If link default override is enabled, use to mask NVM PHY capabilities 1771 * for speed and FEC default configuration. 1772 */ 1773 cfg = &phy->curr_user_phy_cfg; 1774 1775 if (ldo->phy_type_low || ldo->phy_type_high) { 1776 cfg->phy_type_low = pf->nvm_phy_type_lo & 1777 cpu_to_le64(ldo->phy_type_low); 1778 cfg->phy_type_high = pf->nvm_phy_type_hi & 1779 cpu_to_le64(ldo->phy_type_high); 1780 } 1781 cfg->link_fec_opt = ldo->fec_options; 1782 phy->curr_user_fec_req = ICE_FEC_AUTO; 1783 1784 set_bit(__ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state); 1785 } 1786 1787 /** 1788 * ice_init_phy_user_cfg - Initialize the PHY user configuration 1789 * @pi: port info structure 1790 * 1791 * Initialize the current user PHY configuration, speed, FEC, and FC requested 1792 * mode to default. The PHY defaults are from get PHY capabilities topology 1793 * with media so call when media is first available. An error is returned if 1794 * called when media is not available. The PHY initialization completed state is 1795 * set here. 1796 * 1797 * These configurations are used when setting PHY 1798 * configuration. The user PHY configuration is updated on set PHY 1799 * configuration. Returns 0 on success, negative on failure 1800 */ 1801 static int ice_init_phy_user_cfg(struct ice_port_info *pi) 1802 { 1803 struct ice_aqc_get_phy_caps_data *pcaps; 1804 struct ice_phy_info *phy = &pi->phy; 1805 struct ice_pf *pf = pi->hw->back; 1806 enum ice_status status; 1807 struct ice_vsi *vsi; 1808 int err = 0; 1809 1810 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) 1811 return -EIO; 1812 1813 vsi = ice_get_main_vsi(pf); 1814 if (!vsi) 1815 return -EINVAL; 1816 1817 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 1818 if (!pcaps) 1819 return -ENOMEM; 1820 1821 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP, pcaps, 1822 NULL); 1823 if (status) { 1824 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); 1825 err = -EIO; 1826 goto err_out; 1827 } 1828 1829 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg); 1830 1831 /* check if lenient mode is supported and enabled */ 1832 if (ice_fw_supports_link_override(&vsi->back->hw) && 1833 !(pcaps->module_compliance_enforcement & 1834 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) { 1835 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags); 1836 1837 /* if link default override is enabled, initialize user PHY 1838 * configuration with link default override values 1839 */ 1840 if (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN) { 1841 ice_init_phy_cfg_dflt_override(pi); 1842 goto out; 1843 } 1844 } 1845 1846 /* if link default override is not enabled, initialize PHY using 1847 * topology with media 1848 */ 1849 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps, 1850 pcaps->link_fec_options); 1851 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps); 1852 1853 out: 1854 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M; 1855 set_bit(__ICE_PHY_INIT_COMPLETE, pf->state); 1856 err_out: 1857 kfree(pcaps); 1858 return err; 1859 } 1860 1861 /** 1862 * ice_configure_phy - configure PHY 1863 * @vsi: VSI of PHY 1864 * 1865 * Set the PHY configuration. If the current PHY configuration is the same as 1866 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise 1867 * configure the based get PHY capabilities for topology with media. 1868 */ 1869 static int ice_configure_phy(struct ice_vsi *vsi) 1870 { 1871 struct device *dev = ice_pf_to_dev(vsi->back); 1872 struct ice_aqc_get_phy_caps_data *pcaps; 1873 struct ice_aqc_set_phy_cfg_data *cfg; 1874 struct ice_port_info *pi; 1875 enum ice_status status; 1876 int err = 0; 1877 1878 pi = vsi->port_info; 1879 if (!pi) 1880 return -EINVAL; 1881 1882 /* Ensure we have media as we cannot configure a medialess port */ 1883 if (!(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) 1884 return -EPERM; 1885 1886 ice_print_topo_conflict(vsi); 1887 1888 if (vsi->port_info->phy.link_info.topo_media_conflict == 1889 ICE_AQ_LINK_TOPO_UNSUPP_MEDIA) 1890 return -EPERM; 1891 1892 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) 1893 return ice_force_phys_link_state(vsi, true); 1894 1895 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 1896 if (!pcaps) 1897 return -ENOMEM; 1898 1899 /* Get current PHY config */ 1900 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps, 1901 NULL); 1902 if (status) { 1903 dev_err(dev, "Failed to get PHY configuration, VSI %d error %s\n", 1904 vsi->vsi_num, ice_stat_str(status)); 1905 err = -EIO; 1906 goto done; 1907 } 1908 1909 /* If PHY enable link is configured and configuration has not changed, 1910 * there's nothing to do 1911 */ 1912 if (pcaps->caps & ICE_AQC_PHY_EN_LINK && 1913 ice_phy_caps_equals_cfg(pcaps, &pi->phy.curr_user_phy_cfg)) 1914 goto done; 1915 1916 /* Use PHY topology as baseline for configuration */ 1917 memset(pcaps, 0, sizeof(*pcaps)); 1918 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP, pcaps, 1919 NULL); 1920 if (status) { 1921 dev_err(dev, "Failed to get PHY topology, VSI %d error %s\n", 1922 vsi->vsi_num, ice_stat_str(status)); 1923 err = -EIO; 1924 goto done; 1925 } 1926 1927 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); 1928 if (!cfg) { 1929 err = -ENOMEM; 1930 goto done; 1931 } 1932 1933 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg); 1934 1935 /* Speed - If default override pending, use curr_user_phy_cfg set in 1936 * ice_init_phy_user_cfg_ldo. 1937 */ 1938 if (test_and_clear_bit(__ICE_LINK_DEFAULT_OVERRIDE_PENDING, 1939 vsi->back->state)) { 1940 cfg->phy_type_low = pi->phy.curr_user_phy_cfg.phy_type_low; 1941 cfg->phy_type_high = pi->phy.curr_user_phy_cfg.phy_type_high; 1942 } else { 1943 u64 phy_low = 0, phy_high = 0; 1944 1945 ice_update_phy_type(&phy_low, &phy_high, 1946 pi->phy.curr_user_speed_req); 1947 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low); 1948 cfg->phy_type_high = pcaps->phy_type_high & 1949 cpu_to_le64(phy_high); 1950 } 1951 1952 /* Can't provide what was requested; use PHY capabilities */ 1953 if (!cfg->phy_type_low && !cfg->phy_type_high) { 1954 cfg->phy_type_low = pcaps->phy_type_low; 1955 cfg->phy_type_high = pcaps->phy_type_high; 1956 } 1957 1958 /* FEC */ 1959 ice_cfg_phy_fec(pi, cfg, pi->phy.curr_user_fec_req); 1960 1961 /* Can't provide what was requested; use PHY capabilities */ 1962 if (cfg->link_fec_opt != 1963 (cfg->link_fec_opt & pcaps->link_fec_options)) { 1964 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC; 1965 cfg->link_fec_opt = pcaps->link_fec_options; 1966 } 1967 1968 /* Flow Control - always supported; no need to check against 1969 * capabilities 1970 */ 1971 ice_cfg_phy_fc(pi, cfg, pi->phy.curr_user_fc_req); 1972 1973 /* Enable link and link update */ 1974 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK; 1975 1976 status = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL); 1977 if (status) { 1978 dev_err(dev, "Failed to set phy config, VSI %d error %s\n", 1979 vsi->vsi_num, ice_stat_str(status)); 1980 err = -EIO; 1981 } 1982 1983 kfree(cfg); 1984 done: 1985 kfree(pcaps); 1986 return err; 1987 } 1988 1989 /** 1990 * ice_check_media_subtask - Check for media 1991 * @pf: pointer to PF struct 1992 * 1993 * If media is available, then initialize PHY user configuration if it is not 1994 * been, and configure the PHY if the interface is up. 1995 */ 1996 static void ice_check_media_subtask(struct ice_pf *pf) 1997 { 1998 struct ice_port_info *pi; 1999 struct ice_vsi *vsi; 2000 int err; 2001 2002 /* No need to check for media if it's already present */ 2003 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags)) 2004 return; 2005 2006 vsi = ice_get_main_vsi(pf); 2007 if (!vsi) 2008 return; 2009 2010 /* Refresh link info and check if media is present */ 2011 pi = vsi->port_info; 2012 err = ice_update_link_info(pi); 2013 if (err) 2014 return; 2015 2016 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { 2017 if (!test_bit(__ICE_PHY_INIT_COMPLETE, pf->state)) 2018 ice_init_phy_user_cfg(pi); 2019 2020 /* PHY settings are reset on media insertion, reconfigure 2021 * PHY to preserve settings. 2022 */ 2023 if (test_bit(__ICE_DOWN, vsi->state) && 2024 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) 2025 return; 2026 2027 err = ice_configure_phy(vsi); 2028 if (!err) 2029 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags); 2030 2031 /* A Link Status Event will be generated; the event handler 2032 * will complete bringing the interface up 2033 */ 2034 } 2035 } 2036 2037 /** 2038 * ice_service_task - manage and run subtasks 2039 * @work: pointer to work_struct contained by the PF struct 2040 */ 2041 static void ice_service_task(struct work_struct *work) 2042 { 2043 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task); 2044 unsigned long start_time = jiffies; 2045 2046 /* subtasks */ 2047 2048 /* process reset requests first */ 2049 ice_reset_subtask(pf); 2050 2051 /* bail if a reset/recovery cycle is pending or rebuild failed */ 2052 if (ice_is_reset_in_progress(pf->state) || 2053 test_bit(__ICE_SUSPENDED, pf->state) || 2054 test_bit(__ICE_NEEDS_RESTART, pf->state)) { 2055 ice_service_task_complete(pf); 2056 return; 2057 } 2058 2059 ice_clean_adminq_subtask(pf); 2060 ice_check_media_subtask(pf); 2061 ice_check_for_hang_subtask(pf); 2062 ice_sync_fltr_subtask(pf); 2063 ice_handle_mdd_event(pf); 2064 ice_watchdog_subtask(pf); 2065 2066 if (ice_is_safe_mode(pf)) { 2067 ice_service_task_complete(pf); 2068 return; 2069 } 2070 2071 ice_process_vflr_event(pf); 2072 ice_clean_mailboxq_subtask(pf); 2073 ice_sync_arfs_fltrs(pf); 2074 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */ 2075 ice_service_task_complete(pf); 2076 2077 /* If the tasks have taken longer than one service timer period 2078 * or there is more work to be done, reset the service timer to 2079 * schedule the service task now. 2080 */ 2081 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) || 2082 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) || 2083 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) || 2084 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) || 2085 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state)) 2086 mod_timer(&pf->serv_tmr, jiffies); 2087 } 2088 2089 /** 2090 * ice_set_ctrlq_len - helper function to set controlq length 2091 * @hw: pointer to the HW instance 2092 */ 2093 static void ice_set_ctrlq_len(struct ice_hw *hw) 2094 { 2095 hw->adminq.num_rq_entries = ICE_AQ_LEN; 2096 hw->adminq.num_sq_entries = ICE_AQ_LEN; 2097 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN; 2098 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN; 2099 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M; 2100 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN; 2101 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN; 2102 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN; 2103 } 2104 2105 /** 2106 * ice_schedule_reset - schedule a reset 2107 * @pf: board private structure 2108 * @reset: reset being requested 2109 */ 2110 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset) 2111 { 2112 struct device *dev = ice_pf_to_dev(pf); 2113 2114 /* bail out if earlier reset has failed */ 2115 if (test_bit(__ICE_RESET_FAILED, pf->state)) { 2116 dev_dbg(dev, "earlier reset has failed\n"); 2117 return -EIO; 2118 } 2119 /* bail if reset/recovery already in progress */ 2120 if (ice_is_reset_in_progress(pf->state)) { 2121 dev_dbg(dev, "Reset already in progress\n"); 2122 return -EBUSY; 2123 } 2124 2125 switch (reset) { 2126 case ICE_RESET_PFR: 2127 set_bit(__ICE_PFR_REQ, pf->state); 2128 break; 2129 case ICE_RESET_CORER: 2130 set_bit(__ICE_CORER_REQ, pf->state); 2131 break; 2132 case ICE_RESET_GLOBR: 2133 set_bit(__ICE_GLOBR_REQ, pf->state); 2134 break; 2135 default: 2136 return -EINVAL; 2137 } 2138 2139 ice_service_task_schedule(pf); 2140 return 0; 2141 } 2142 2143 /** 2144 * ice_irq_affinity_notify - Callback for affinity changes 2145 * @notify: context as to what irq was changed 2146 * @mask: the new affinity mask 2147 * 2148 * This is a callback function used by the irq_set_affinity_notifier function 2149 * so that we may register to receive changes to the irq affinity masks. 2150 */ 2151 static void 2152 ice_irq_affinity_notify(struct irq_affinity_notify *notify, 2153 const cpumask_t *mask) 2154 { 2155 struct ice_q_vector *q_vector = 2156 container_of(notify, struct ice_q_vector, affinity_notify); 2157 2158 cpumask_copy(&q_vector->affinity_mask, mask); 2159 } 2160 2161 /** 2162 * ice_irq_affinity_release - Callback for affinity notifier release 2163 * @ref: internal core kernel usage 2164 * 2165 * This is a callback function used by the irq_set_affinity_notifier function 2166 * to inform the current notification subscriber that they will no longer 2167 * receive notifications. 2168 */ 2169 static void ice_irq_affinity_release(struct kref __always_unused *ref) {} 2170 2171 /** 2172 * ice_vsi_ena_irq - Enable IRQ for the given VSI 2173 * @vsi: the VSI being configured 2174 */ 2175 static int ice_vsi_ena_irq(struct ice_vsi *vsi) 2176 { 2177 struct ice_hw *hw = &vsi->back->hw; 2178 int i; 2179 2180 ice_for_each_q_vector(vsi, i) 2181 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]); 2182 2183 ice_flush(hw); 2184 return 0; 2185 } 2186 2187 /** 2188 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI 2189 * @vsi: the VSI being configured 2190 * @basename: name for the vector 2191 */ 2192 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename) 2193 { 2194 int q_vectors = vsi->num_q_vectors; 2195 struct ice_pf *pf = vsi->back; 2196 int base = vsi->base_vector; 2197 struct device *dev; 2198 int rx_int_idx = 0; 2199 int tx_int_idx = 0; 2200 int vector, err; 2201 int irq_num; 2202 2203 dev = ice_pf_to_dev(pf); 2204 for (vector = 0; vector < q_vectors; vector++) { 2205 struct ice_q_vector *q_vector = vsi->q_vectors[vector]; 2206 2207 irq_num = pf->msix_entries[base + vector].vector; 2208 2209 if (q_vector->tx.ring && q_vector->rx.ring) { 2210 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2211 "%s-%s-%d", basename, "TxRx", rx_int_idx++); 2212 tx_int_idx++; 2213 } else if (q_vector->rx.ring) { 2214 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2215 "%s-%s-%d", basename, "rx", rx_int_idx++); 2216 } else if (q_vector->tx.ring) { 2217 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2218 "%s-%s-%d", basename, "tx", tx_int_idx++); 2219 } else { 2220 /* skip this unused q_vector */ 2221 continue; 2222 } 2223 err = devm_request_irq(dev, irq_num, vsi->irq_handler, 0, 2224 q_vector->name, q_vector); 2225 if (err) { 2226 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n", 2227 err); 2228 goto free_q_irqs; 2229 } 2230 2231 /* register for affinity change notifications */ 2232 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) { 2233 struct irq_affinity_notify *affinity_notify; 2234 2235 affinity_notify = &q_vector->affinity_notify; 2236 affinity_notify->notify = ice_irq_affinity_notify; 2237 affinity_notify->release = ice_irq_affinity_release; 2238 irq_set_affinity_notifier(irq_num, affinity_notify); 2239 } 2240 2241 /* assign the mask for this irq */ 2242 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); 2243 } 2244 2245 vsi->irqs_ready = true; 2246 return 0; 2247 2248 free_q_irqs: 2249 while (vector) { 2250 vector--; 2251 irq_num = pf->msix_entries[base + vector].vector; 2252 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) 2253 irq_set_affinity_notifier(irq_num, NULL); 2254 irq_set_affinity_hint(irq_num, NULL); 2255 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]); 2256 } 2257 return err; 2258 } 2259 2260 /** 2261 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP 2262 * @vsi: VSI to setup Tx rings used by XDP 2263 * 2264 * Return 0 on success and negative value on error 2265 */ 2266 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi) 2267 { 2268 struct device *dev = ice_pf_to_dev(vsi->back); 2269 int i; 2270 2271 for (i = 0; i < vsi->num_xdp_txq; i++) { 2272 u16 xdp_q_idx = vsi->alloc_txq + i; 2273 struct ice_ring *xdp_ring; 2274 2275 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL); 2276 2277 if (!xdp_ring) 2278 goto free_xdp_rings; 2279 2280 xdp_ring->q_index = xdp_q_idx; 2281 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx]; 2282 xdp_ring->ring_active = false; 2283 xdp_ring->vsi = vsi; 2284 xdp_ring->netdev = NULL; 2285 xdp_ring->dev = dev; 2286 xdp_ring->count = vsi->num_tx_desc; 2287 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring); 2288 if (ice_setup_tx_ring(xdp_ring)) 2289 goto free_xdp_rings; 2290 ice_set_ring_xdp(xdp_ring); 2291 xdp_ring->xsk_pool = ice_xsk_pool(xdp_ring); 2292 } 2293 2294 return 0; 2295 2296 free_xdp_rings: 2297 for (; i >= 0; i--) 2298 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) 2299 ice_free_tx_ring(vsi->xdp_rings[i]); 2300 return -ENOMEM; 2301 } 2302 2303 /** 2304 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI 2305 * @vsi: VSI to set the bpf prog on 2306 * @prog: the bpf prog pointer 2307 */ 2308 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog) 2309 { 2310 struct bpf_prog *old_prog; 2311 int i; 2312 2313 old_prog = xchg(&vsi->xdp_prog, prog); 2314 if (old_prog) 2315 bpf_prog_put(old_prog); 2316 2317 ice_for_each_rxq(vsi, i) 2318 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); 2319 } 2320 2321 /** 2322 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP 2323 * @vsi: VSI to bring up Tx rings used by XDP 2324 * @prog: bpf program that will be assigned to VSI 2325 * 2326 * Return 0 on success and negative value on error 2327 */ 2328 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog) 2329 { 2330 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 2331 int xdp_rings_rem = vsi->num_xdp_txq; 2332 struct ice_pf *pf = vsi->back; 2333 struct ice_qs_cfg xdp_qs_cfg = { 2334 .qs_mutex = &pf->avail_q_mutex, 2335 .pf_map = pf->avail_txqs, 2336 .pf_map_size = pf->max_pf_txqs, 2337 .q_count = vsi->num_xdp_txq, 2338 .scatter_count = ICE_MAX_SCATTER_TXQS, 2339 .vsi_map = vsi->txq_map, 2340 .vsi_map_offset = vsi->alloc_txq, 2341 .mapping_mode = ICE_VSI_MAP_CONTIG 2342 }; 2343 enum ice_status status; 2344 struct device *dev; 2345 int i, v_idx; 2346 2347 dev = ice_pf_to_dev(pf); 2348 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq, 2349 sizeof(*vsi->xdp_rings), GFP_KERNEL); 2350 if (!vsi->xdp_rings) 2351 return -ENOMEM; 2352 2353 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode; 2354 if (__ice_vsi_get_qs(&xdp_qs_cfg)) 2355 goto err_map_xdp; 2356 2357 if (ice_xdp_alloc_setup_rings(vsi)) 2358 goto clear_xdp_rings; 2359 2360 /* follow the logic from ice_vsi_map_rings_to_vectors */ 2361 ice_for_each_q_vector(vsi, v_idx) { 2362 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; 2363 int xdp_rings_per_v, q_id, q_base; 2364 2365 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem, 2366 vsi->num_q_vectors - v_idx); 2367 q_base = vsi->num_xdp_txq - xdp_rings_rem; 2368 2369 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) { 2370 struct ice_ring *xdp_ring = vsi->xdp_rings[q_id]; 2371 2372 xdp_ring->q_vector = q_vector; 2373 xdp_ring->next = q_vector->tx.ring; 2374 q_vector->tx.ring = xdp_ring; 2375 } 2376 xdp_rings_rem -= xdp_rings_per_v; 2377 } 2378 2379 /* omit the scheduler update if in reset path; XDP queues will be 2380 * taken into account at the end of ice_vsi_rebuild, where 2381 * ice_cfg_vsi_lan is being called 2382 */ 2383 if (ice_is_reset_in_progress(pf->state)) 2384 return 0; 2385 2386 /* tell the Tx scheduler that right now we have 2387 * additional queues 2388 */ 2389 for (i = 0; i < vsi->tc_cfg.numtc; i++) 2390 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq; 2391 2392 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2393 max_txqs); 2394 if (status) { 2395 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %s\n", 2396 ice_stat_str(status)); 2397 goto clear_xdp_rings; 2398 } 2399 ice_vsi_assign_bpf_prog(vsi, prog); 2400 2401 return 0; 2402 clear_xdp_rings: 2403 for (i = 0; i < vsi->num_xdp_txq; i++) 2404 if (vsi->xdp_rings[i]) { 2405 kfree_rcu(vsi->xdp_rings[i], rcu); 2406 vsi->xdp_rings[i] = NULL; 2407 } 2408 2409 err_map_xdp: 2410 mutex_lock(&pf->avail_q_mutex); 2411 for (i = 0; i < vsi->num_xdp_txq; i++) { 2412 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); 2413 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; 2414 } 2415 mutex_unlock(&pf->avail_q_mutex); 2416 2417 devm_kfree(dev, vsi->xdp_rings); 2418 return -ENOMEM; 2419 } 2420 2421 /** 2422 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings 2423 * @vsi: VSI to remove XDP rings 2424 * 2425 * Detach XDP rings from irq vectors, clean up the PF bitmap and free 2426 * resources 2427 */ 2428 int ice_destroy_xdp_rings(struct ice_vsi *vsi) 2429 { 2430 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 2431 struct ice_pf *pf = vsi->back; 2432 int i, v_idx; 2433 2434 /* q_vectors are freed in reset path so there's no point in detaching 2435 * rings; in case of rebuild being triggered not from reset bits 2436 * in pf->state won't be set, so additionally check first q_vector 2437 * against NULL 2438 */ 2439 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0]) 2440 goto free_qmap; 2441 2442 ice_for_each_q_vector(vsi, v_idx) { 2443 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; 2444 struct ice_ring *ring; 2445 2446 ice_for_each_ring(ring, q_vector->tx) 2447 if (!ring->tx_buf || !ice_ring_is_xdp(ring)) 2448 break; 2449 2450 /* restore the value of last node prior to XDP setup */ 2451 q_vector->tx.ring = ring; 2452 } 2453 2454 free_qmap: 2455 mutex_lock(&pf->avail_q_mutex); 2456 for (i = 0; i < vsi->num_xdp_txq; i++) { 2457 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); 2458 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; 2459 } 2460 mutex_unlock(&pf->avail_q_mutex); 2461 2462 for (i = 0; i < vsi->num_xdp_txq; i++) 2463 if (vsi->xdp_rings[i]) { 2464 if (vsi->xdp_rings[i]->desc) 2465 ice_free_tx_ring(vsi->xdp_rings[i]); 2466 kfree_rcu(vsi->xdp_rings[i], rcu); 2467 vsi->xdp_rings[i] = NULL; 2468 } 2469 2470 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings); 2471 vsi->xdp_rings = NULL; 2472 2473 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0]) 2474 return 0; 2475 2476 ice_vsi_assign_bpf_prog(vsi, NULL); 2477 2478 /* notify Tx scheduler that we destroyed XDP queues and bring 2479 * back the old number of child nodes 2480 */ 2481 for (i = 0; i < vsi->tc_cfg.numtc; i++) 2482 max_txqs[i] = vsi->num_txq; 2483 2484 /* change number of XDP Tx queues to 0 */ 2485 vsi->num_xdp_txq = 0; 2486 2487 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2488 max_txqs); 2489 } 2490 2491 /** 2492 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI 2493 * @vsi: VSI to schedule napi on 2494 */ 2495 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi) 2496 { 2497 int i; 2498 2499 ice_for_each_rxq(vsi, i) { 2500 struct ice_ring *rx_ring = vsi->rx_rings[i]; 2501 2502 if (rx_ring->xsk_pool) 2503 napi_schedule(&rx_ring->q_vector->napi); 2504 } 2505 } 2506 2507 /** 2508 * ice_xdp_setup_prog - Add or remove XDP eBPF program 2509 * @vsi: VSI to setup XDP for 2510 * @prog: XDP program 2511 * @extack: netlink extended ack 2512 */ 2513 static int 2514 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog, 2515 struct netlink_ext_ack *extack) 2516 { 2517 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD; 2518 bool if_running = netif_running(vsi->netdev); 2519 int ret = 0, xdp_ring_err = 0; 2520 2521 if (frame_size > vsi->rx_buf_len) { 2522 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP"); 2523 return -EOPNOTSUPP; 2524 } 2525 2526 /* need to stop netdev while setting up the program for Rx rings */ 2527 if (if_running && !test_and_set_bit(__ICE_DOWN, vsi->state)) { 2528 ret = ice_down(vsi); 2529 if (ret) { 2530 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed"); 2531 return ret; 2532 } 2533 } 2534 2535 if (!ice_is_xdp_ena_vsi(vsi) && prog) { 2536 vsi->num_xdp_txq = vsi->alloc_rxq; 2537 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog); 2538 if (xdp_ring_err) 2539 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed"); 2540 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) { 2541 xdp_ring_err = ice_destroy_xdp_rings(vsi); 2542 if (xdp_ring_err) 2543 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed"); 2544 } else { 2545 ice_vsi_assign_bpf_prog(vsi, prog); 2546 } 2547 2548 if (if_running) 2549 ret = ice_up(vsi); 2550 2551 if (!ret && prog) 2552 ice_vsi_rx_napi_schedule(vsi); 2553 2554 return (ret || xdp_ring_err) ? -ENOMEM : 0; 2555 } 2556 2557 /** 2558 * ice_xdp - implements XDP handler 2559 * @dev: netdevice 2560 * @xdp: XDP command 2561 */ 2562 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp) 2563 { 2564 struct ice_netdev_priv *np = netdev_priv(dev); 2565 struct ice_vsi *vsi = np->vsi; 2566 2567 if (vsi->type != ICE_VSI_PF) { 2568 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI"); 2569 return -EINVAL; 2570 } 2571 2572 switch (xdp->command) { 2573 case XDP_SETUP_PROG: 2574 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack); 2575 case XDP_SETUP_XSK_POOL: 2576 return ice_xsk_pool_setup(vsi, xdp->xsk.pool, 2577 xdp->xsk.queue_id); 2578 default: 2579 return -EINVAL; 2580 } 2581 } 2582 2583 /** 2584 * ice_ena_misc_vector - enable the non-queue interrupts 2585 * @pf: board private structure 2586 */ 2587 static void ice_ena_misc_vector(struct ice_pf *pf) 2588 { 2589 struct ice_hw *hw = &pf->hw; 2590 u32 val; 2591 2592 /* Disable anti-spoof detection interrupt to prevent spurious event 2593 * interrupts during a function reset. Anti-spoof functionally is 2594 * still supported. 2595 */ 2596 val = rd32(hw, GL_MDCK_TX_TDPU); 2597 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M; 2598 wr32(hw, GL_MDCK_TX_TDPU, val); 2599 2600 /* clear things first */ 2601 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */ 2602 rd32(hw, PFINT_OICR); /* read to clear */ 2603 2604 val = (PFINT_OICR_ECC_ERR_M | 2605 PFINT_OICR_MAL_DETECT_M | 2606 PFINT_OICR_GRST_M | 2607 PFINT_OICR_PCI_EXCEPTION_M | 2608 PFINT_OICR_VFLR_M | 2609 PFINT_OICR_HMC_ERR_M | 2610 PFINT_OICR_PE_CRITERR_M); 2611 2612 wr32(hw, PFINT_OICR_ENA, val); 2613 2614 /* SW_ITR_IDX = 0, but don't change INTENA */ 2615 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx), 2616 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M); 2617 } 2618 2619 /** 2620 * ice_misc_intr - misc interrupt handler 2621 * @irq: interrupt number 2622 * @data: pointer to a q_vector 2623 */ 2624 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) 2625 { 2626 struct ice_pf *pf = (struct ice_pf *)data; 2627 struct ice_hw *hw = &pf->hw; 2628 irqreturn_t ret = IRQ_NONE; 2629 struct device *dev; 2630 u32 oicr, ena_mask; 2631 2632 dev = ice_pf_to_dev(pf); 2633 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state); 2634 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state); 2635 2636 oicr = rd32(hw, PFINT_OICR); 2637 ena_mask = rd32(hw, PFINT_OICR_ENA); 2638 2639 if (oicr & PFINT_OICR_SWINT_M) { 2640 ena_mask &= ~PFINT_OICR_SWINT_M; 2641 pf->sw_int_count++; 2642 } 2643 2644 if (oicr & PFINT_OICR_MAL_DETECT_M) { 2645 ena_mask &= ~PFINT_OICR_MAL_DETECT_M; 2646 set_bit(__ICE_MDD_EVENT_PENDING, pf->state); 2647 } 2648 if (oicr & PFINT_OICR_VFLR_M) { 2649 /* disable any further VFLR event notifications */ 2650 if (test_bit(__ICE_VF_RESETS_DISABLED, pf->state)) { 2651 u32 reg = rd32(hw, PFINT_OICR_ENA); 2652 2653 reg &= ~PFINT_OICR_VFLR_M; 2654 wr32(hw, PFINT_OICR_ENA, reg); 2655 } else { 2656 ena_mask &= ~PFINT_OICR_VFLR_M; 2657 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state); 2658 } 2659 } 2660 2661 if (oicr & PFINT_OICR_GRST_M) { 2662 u32 reset; 2663 2664 /* we have a reset warning */ 2665 ena_mask &= ~PFINT_OICR_GRST_M; 2666 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >> 2667 GLGEN_RSTAT_RESET_TYPE_S; 2668 2669 if (reset == ICE_RESET_CORER) 2670 pf->corer_count++; 2671 else if (reset == ICE_RESET_GLOBR) 2672 pf->globr_count++; 2673 else if (reset == ICE_RESET_EMPR) 2674 pf->empr_count++; 2675 else 2676 dev_dbg(dev, "Invalid reset type %d\n", reset); 2677 2678 /* If a reset cycle isn't already in progress, we set a bit in 2679 * pf->state so that the service task can start a reset/rebuild. 2680 * We also make note of which reset happened so that peer 2681 * devices/drivers can be informed. 2682 */ 2683 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) { 2684 if (reset == ICE_RESET_CORER) 2685 set_bit(__ICE_CORER_RECV, pf->state); 2686 else if (reset == ICE_RESET_GLOBR) 2687 set_bit(__ICE_GLOBR_RECV, pf->state); 2688 else 2689 set_bit(__ICE_EMPR_RECV, pf->state); 2690 2691 /* There are couple of different bits at play here. 2692 * hw->reset_ongoing indicates whether the hardware is 2693 * in reset. This is set to true when a reset interrupt 2694 * is received and set back to false after the driver 2695 * has determined that the hardware is out of reset. 2696 * 2697 * __ICE_RESET_OICR_RECV in pf->state indicates 2698 * that a post reset rebuild is required before the 2699 * driver is operational again. This is set above. 2700 * 2701 * As this is the start of the reset/rebuild cycle, set 2702 * both to indicate that. 2703 */ 2704 hw->reset_ongoing = true; 2705 } 2706 } 2707 2708 if (oicr & PFINT_OICR_HMC_ERR_M) { 2709 ena_mask &= ~PFINT_OICR_HMC_ERR_M; 2710 dev_dbg(dev, "HMC Error interrupt - info 0x%x, data 0x%x\n", 2711 rd32(hw, PFHMC_ERRORINFO), 2712 rd32(hw, PFHMC_ERRORDATA)); 2713 } 2714 2715 /* Report any remaining unexpected interrupts */ 2716 oicr &= ena_mask; 2717 if (oicr) { 2718 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr); 2719 /* If a critical error is pending there is no choice but to 2720 * reset the device. 2721 */ 2722 if (oicr & (PFINT_OICR_PE_CRITERR_M | 2723 PFINT_OICR_PCI_EXCEPTION_M | 2724 PFINT_OICR_ECC_ERR_M)) { 2725 set_bit(__ICE_PFR_REQ, pf->state); 2726 ice_service_task_schedule(pf); 2727 } 2728 } 2729 ret = IRQ_HANDLED; 2730 2731 ice_service_task_schedule(pf); 2732 ice_irq_dynamic_ena(hw, NULL, NULL); 2733 2734 return ret; 2735 } 2736 2737 /** 2738 * ice_dis_ctrlq_interrupts - disable control queue interrupts 2739 * @hw: pointer to HW structure 2740 */ 2741 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw) 2742 { 2743 /* disable Admin queue Interrupt causes */ 2744 wr32(hw, PFINT_FW_CTL, 2745 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M); 2746 2747 /* disable Mailbox queue Interrupt causes */ 2748 wr32(hw, PFINT_MBX_CTL, 2749 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M); 2750 2751 /* disable Control queue Interrupt causes */ 2752 wr32(hw, PFINT_OICR_CTL, 2753 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M); 2754 2755 ice_flush(hw); 2756 } 2757 2758 /** 2759 * ice_free_irq_msix_misc - Unroll misc vector setup 2760 * @pf: board private structure 2761 */ 2762 static void ice_free_irq_msix_misc(struct ice_pf *pf) 2763 { 2764 struct ice_hw *hw = &pf->hw; 2765 2766 ice_dis_ctrlq_interrupts(hw); 2767 2768 /* disable OICR interrupt */ 2769 wr32(hw, PFINT_OICR_ENA, 0); 2770 ice_flush(hw); 2771 2772 if (pf->msix_entries) { 2773 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector); 2774 devm_free_irq(ice_pf_to_dev(pf), 2775 pf->msix_entries[pf->oicr_idx].vector, pf); 2776 } 2777 2778 pf->num_avail_sw_msix += 1; 2779 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID); 2780 } 2781 2782 /** 2783 * ice_ena_ctrlq_interrupts - enable control queue interrupts 2784 * @hw: pointer to HW structure 2785 * @reg_idx: HW vector index to associate the control queue interrupts with 2786 */ 2787 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx) 2788 { 2789 u32 val; 2790 2791 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) | 2792 PFINT_OICR_CTL_CAUSE_ENA_M); 2793 wr32(hw, PFINT_OICR_CTL, val); 2794 2795 /* enable Admin queue Interrupt causes */ 2796 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) | 2797 PFINT_FW_CTL_CAUSE_ENA_M); 2798 wr32(hw, PFINT_FW_CTL, val); 2799 2800 /* enable Mailbox queue Interrupt causes */ 2801 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) | 2802 PFINT_MBX_CTL_CAUSE_ENA_M); 2803 wr32(hw, PFINT_MBX_CTL, val); 2804 2805 ice_flush(hw); 2806 } 2807 2808 /** 2809 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events 2810 * @pf: board private structure 2811 * 2812 * This sets up the handler for MSIX 0, which is used to manage the 2813 * non-queue interrupts, e.g. AdminQ and errors. This is not used 2814 * when in MSI or Legacy interrupt mode. 2815 */ 2816 static int ice_req_irq_msix_misc(struct ice_pf *pf) 2817 { 2818 struct device *dev = ice_pf_to_dev(pf); 2819 struct ice_hw *hw = &pf->hw; 2820 int oicr_idx, err = 0; 2821 2822 if (!pf->int_name[0]) 2823 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc", 2824 dev_driver_string(dev), dev_name(dev)); 2825 2826 /* Do not request IRQ but do enable OICR interrupt since settings are 2827 * lost during reset. Note that this function is called only during 2828 * rebuild path and not while reset is in progress. 2829 */ 2830 if (ice_is_reset_in_progress(pf->state)) 2831 goto skip_req_irq; 2832 2833 /* reserve one vector in irq_tracker for misc interrupts */ 2834 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID); 2835 if (oicr_idx < 0) 2836 return oicr_idx; 2837 2838 pf->num_avail_sw_msix -= 1; 2839 pf->oicr_idx = (u16)oicr_idx; 2840 2841 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector, 2842 ice_misc_intr, 0, pf->int_name, pf); 2843 if (err) { 2844 dev_err(dev, "devm_request_irq for %s failed: %d\n", 2845 pf->int_name, err); 2846 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID); 2847 pf->num_avail_sw_msix += 1; 2848 return err; 2849 } 2850 2851 skip_req_irq: 2852 ice_ena_misc_vector(pf); 2853 2854 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx); 2855 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx), 2856 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S); 2857 2858 ice_flush(hw); 2859 ice_irq_dynamic_ena(hw, NULL, NULL); 2860 2861 return 0; 2862 } 2863 2864 /** 2865 * ice_napi_add - register NAPI handler for the VSI 2866 * @vsi: VSI for which NAPI handler is to be registered 2867 * 2868 * This function is only called in the driver's load path. Registering the NAPI 2869 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume, 2870 * reset/rebuild, etc.) 2871 */ 2872 static void ice_napi_add(struct ice_vsi *vsi) 2873 { 2874 int v_idx; 2875 2876 if (!vsi->netdev) 2877 return; 2878 2879 ice_for_each_q_vector(vsi, v_idx) 2880 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi, 2881 ice_napi_poll, NAPI_POLL_WEIGHT); 2882 } 2883 2884 /** 2885 * ice_set_ops - set netdev and ethtools ops for the given netdev 2886 * @netdev: netdev instance 2887 */ 2888 static void ice_set_ops(struct net_device *netdev) 2889 { 2890 struct ice_pf *pf = ice_netdev_to_pf(netdev); 2891 2892 if (ice_is_safe_mode(pf)) { 2893 netdev->netdev_ops = &ice_netdev_safe_mode_ops; 2894 ice_set_ethtool_safe_mode_ops(netdev); 2895 return; 2896 } 2897 2898 netdev->netdev_ops = &ice_netdev_ops; 2899 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic; 2900 ice_set_ethtool_ops(netdev); 2901 } 2902 2903 /** 2904 * ice_set_netdev_features - set features for the given netdev 2905 * @netdev: netdev instance 2906 */ 2907 static void ice_set_netdev_features(struct net_device *netdev) 2908 { 2909 struct ice_pf *pf = ice_netdev_to_pf(netdev); 2910 netdev_features_t csumo_features; 2911 netdev_features_t vlano_features; 2912 netdev_features_t dflt_features; 2913 netdev_features_t tso_features; 2914 2915 if (ice_is_safe_mode(pf)) { 2916 /* safe mode */ 2917 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA; 2918 netdev->hw_features = netdev->features; 2919 return; 2920 } 2921 2922 dflt_features = NETIF_F_SG | 2923 NETIF_F_HIGHDMA | 2924 NETIF_F_NTUPLE | 2925 NETIF_F_RXHASH; 2926 2927 csumo_features = NETIF_F_RXCSUM | 2928 NETIF_F_IP_CSUM | 2929 NETIF_F_SCTP_CRC | 2930 NETIF_F_IPV6_CSUM; 2931 2932 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER | 2933 NETIF_F_HW_VLAN_CTAG_TX | 2934 NETIF_F_HW_VLAN_CTAG_RX; 2935 2936 tso_features = NETIF_F_TSO | 2937 NETIF_F_TSO_ECN | 2938 NETIF_F_TSO6 | 2939 NETIF_F_GSO_GRE | 2940 NETIF_F_GSO_UDP_TUNNEL | 2941 NETIF_F_GSO_GRE_CSUM | 2942 NETIF_F_GSO_UDP_TUNNEL_CSUM | 2943 NETIF_F_GSO_PARTIAL | 2944 NETIF_F_GSO_IPXIP4 | 2945 NETIF_F_GSO_IPXIP6 | 2946 NETIF_F_GSO_UDP_L4; 2947 2948 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM | 2949 NETIF_F_GSO_GRE_CSUM; 2950 /* set features that user can change */ 2951 netdev->hw_features = dflt_features | csumo_features | 2952 vlano_features | tso_features; 2953 2954 /* add support for HW_CSUM on packets with MPLS header */ 2955 netdev->mpls_features = NETIF_F_HW_CSUM; 2956 2957 /* enable features */ 2958 netdev->features |= netdev->hw_features; 2959 /* encap and VLAN devices inherit default, csumo and tso features */ 2960 netdev->hw_enc_features |= dflt_features | csumo_features | 2961 tso_features; 2962 netdev->vlan_features |= dflt_features | csumo_features | 2963 tso_features; 2964 } 2965 2966 /** 2967 * ice_cfg_netdev - Allocate, configure and register a netdev 2968 * @vsi: the VSI associated with the new netdev 2969 * 2970 * Returns 0 on success, negative value on failure 2971 */ 2972 static int ice_cfg_netdev(struct ice_vsi *vsi) 2973 { 2974 struct ice_pf *pf = vsi->back; 2975 struct ice_netdev_priv *np; 2976 struct net_device *netdev; 2977 u8 mac_addr[ETH_ALEN]; 2978 int err; 2979 2980 err = ice_devlink_create_port(vsi); 2981 if (err) 2982 return err; 2983 2984 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, 2985 vsi->alloc_rxq); 2986 if (!netdev) { 2987 err = -ENOMEM; 2988 goto err_destroy_devlink_port; 2989 } 2990 2991 vsi->netdev = netdev; 2992 np = netdev_priv(netdev); 2993 np->vsi = vsi; 2994 2995 ice_set_netdev_features(netdev); 2996 2997 ice_set_ops(netdev); 2998 2999 if (vsi->type == ICE_VSI_PF) { 3000 SET_NETDEV_DEV(netdev, ice_pf_to_dev(pf)); 3001 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 3002 ether_addr_copy(netdev->dev_addr, mac_addr); 3003 ether_addr_copy(netdev->perm_addr, mac_addr); 3004 } 3005 3006 netdev->priv_flags |= IFF_UNICAST_FLT; 3007 3008 /* Setup netdev TC information */ 3009 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); 3010 3011 /* setup watchdog timeout value to be 5 second */ 3012 netdev->watchdog_timeo = 5 * HZ; 3013 3014 netdev->min_mtu = ETH_MIN_MTU; 3015 netdev->max_mtu = ICE_MAX_MTU; 3016 3017 err = register_netdev(vsi->netdev); 3018 if (err) 3019 goto err_free_netdev; 3020 3021 devlink_port_type_eth_set(&vsi->devlink_port, vsi->netdev); 3022 3023 netif_carrier_off(vsi->netdev); 3024 3025 /* make sure transmit queues start off as stopped */ 3026 netif_tx_stop_all_queues(vsi->netdev); 3027 3028 return 0; 3029 3030 err_free_netdev: 3031 free_netdev(vsi->netdev); 3032 vsi->netdev = NULL; 3033 err_destroy_devlink_port: 3034 ice_devlink_destroy_port(vsi); 3035 return err; 3036 } 3037 3038 /** 3039 * ice_fill_rss_lut - Fill the RSS lookup table with default values 3040 * @lut: Lookup table 3041 * @rss_table_size: Lookup table size 3042 * @rss_size: Range of queue number for hashing 3043 */ 3044 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size) 3045 { 3046 u16 i; 3047 3048 for (i = 0; i < rss_table_size; i++) 3049 lut[i] = i % rss_size; 3050 } 3051 3052 /** 3053 * ice_pf_vsi_setup - Set up a PF VSI 3054 * @pf: board private structure 3055 * @pi: pointer to the port_info instance 3056 * 3057 * Returns pointer to the successfully allocated VSI software struct 3058 * on success, otherwise returns NULL on failure. 3059 */ 3060 static struct ice_vsi * 3061 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3062 { 3063 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID); 3064 } 3065 3066 /** 3067 * ice_ctrl_vsi_setup - Set up a control VSI 3068 * @pf: board private structure 3069 * @pi: pointer to the port_info instance 3070 * 3071 * Returns pointer to the successfully allocated VSI software struct 3072 * on success, otherwise returns NULL on failure. 3073 */ 3074 static struct ice_vsi * 3075 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3076 { 3077 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, ICE_INVAL_VFID); 3078 } 3079 3080 /** 3081 * ice_lb_vsi_setup - Set up a loopback VSI 3082 * @pf: board private structure 3083 * @pi: pointer to the port_info instance 3084 * 3085 * Returns pointer to the successfully allocated VSI software struct 3086 * on success, otherwise returns NULL on failure. 3087 */ 3088 struct ice_vsi * 3089 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3090 { 3091 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID); 3092 } 3093 3094 /** 3095 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload 3096 * @netdev: network interface to be adjusted 3097 * @proto: unused protocol 3098 * @vid: VLAN ID to be added 3099 * 3100 * net_device_ops implementation for adding VLAN IDs 3101 */ 3102 static int 3103 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto, 3104 u16 vid) 3105 { 3106 struct ice_netdev_priv *np = netdev_priv(netdev); 3107 struct ice_vsi *vsi = np->vsi; 3108 int ret; 3109 3110 if (vid >= VLAN_N_VID) { 3111 netdev_err(netdev, "VLAN id requested %d is out of range %d\n", 3112 vid, VLAN_N_VID); 3113 return -EINVAL; 3114 } 3115 3116 if (vsi->info.pvid) 3117 return -EINVAL; 3118 3119 /* VLAN 0 is added by default during load/reset */ 3120 if (!vid) 3121 return 0; 3122 3123 /* Enable VLAN pruning when a VLAN other than 0 is added */ 3124 if (!ice_vsi_is_vlan_pruning_ena(vsi)) { 3125 ret = ice_cfg_vlan_pruning(vsi, true, false); 3126 if (ret) 3127 return ret; 3128 } 3129 3130 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged 3131 * packets aren't pruned by the device's internal switch on Rx 3132 */ 3133 ret = ice_vsi_add_vlan(vsi, vid, ICE_FWD_TO_VSI); 3134 if (!ret) 3135 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags); 3136 3137 return ret; 3138 } 3139 3140 /** 3141 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload 3142 * @netdev: network interface to be adjusted 3143 * @proto: unused protocol 3144 * @vid: VLAN ID to be removed 3145 * 3146 * net_device_ops implementation for removing VLAN IDs 3147 */ 3148 static int 3149 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto, 3150 u16 vid) 3151 { 3152 struct ice_netdev_priv *np = netdev_priv(netdev); 3153 struct ice_vsi *vsi = np->vsi; 3154 int ret; 3155 3156 if (vsi->info.pvid) 3157 return -EINVAL; 3158 3159 /* don't allow removal of VLAN 0 */ 3160 if (!vid) 3161 return 0; 3162 3163 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN 3164 * information 3165 */ 3166 ret = ice_vsi_kill_vlan(vsi, vid); 3167 if (ret) 3168 return ret; 3169 3170 /* Disable pruning when VLAN 0 is the only VLAN rule */ 3171 if (vsi->num_vlan == 1 && ice_vsi_is_vlan_pruning_ena(vsi)) 3172 ret = ice_cfg_vlan_pruning(vsi, false, false); 3173 3174 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags); 3175 return ret; 3176 } 3177 3178 /** 3179 * ice_setup_pf_sw - Setup the HW switch on startup or after reset 3180 * @pf: board private structure 3181 * 3182 * Returns 0 on success, negative value on failure 3183 */ 3184 static int ice_setup_pf_sw(struct ice_pf *pf) 3185 { 3186 struct ice_vsi *vsi; 3187 int status = 0; 3188 3189 if (ice_is_reset_in_progress(pf->state)) 3190 return -EBUSY; 3191 3192 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info); 3193 if (!vsi) 3194 return -ENOMEM; 3195 3196 status = ice_cfg_netdev(vsi); 3197 if (status) { 3198 status = -ENODEV; 3199 goto unroll_vsi_setup; 3200 } 3201 /* netdev has to be configured before setting frame size */ 3202 ice_vsi_cfg_frame_size(vsi); 3203 3204 /* Setup DCB netlink interface */ 3205 ice_dcbnl_setup(vsi); 3206 3207 /* registering the NAPI handler requires both the queues and 3208 * netdev to be created, which are done in ice_pf_vsi_setup() 3209 * and ice_cfg_netdev() respectively 3210 */ 3211 ice_napi_add(vsi); 3212 3213 status = ice_set_cpu_rx_rmap(vsi); 3214 if (status) { 3215 dev_err(ice_pf_to_dev(pf), "Failed to set CPU Rx map VSI %d error %d\n", 3216 vsi->vsi_num, status); 3217 status = -EINVAL; 3218 goto unroll_napi_add; 3219 } 3220 status = ice_init_mac_fltr(pf); 3221 if (status) 3222 goto free_cpu_rx_map; 3223 3224 return status; 3225 3226 free_cpu_rx_map: 3227 ice_free_cpu_rx_rmap(vsi); 3228 3229 unroll_napi_add: 3230 if (vsi) { 3231 ice_napi_del(vsi); 3232 if (vsi->netdev) { 3233 if (vsi->netdev->reg_state == NETREG_REGISTERED) 3234 unregister_netdev(vsi->netdev); 3235 free_netdev(vsi->netdev); 3236 vsi->netdev = NULL; 3237 } 3238 } 3239 3240 unroll_vsi_setup: 3241 ice_vsi_release(vsi); 3242 return status; 3243 } 3244 3245 /** 3246 * ice_get_avail_q_count - Get count of queues in use 3247 * @pf_qmap: bitmap to get queue use count from 3248 * @lock: pointer to a mutex that protects access to pf_qmap 3249 * @size: size of the bitmap 3250 */ 3251 static u16 3252 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size) 3253 { 3254 unsigned long bit; 3255 u16 count = 0; 3256 3257 mutex_lock(lock); 3258 for_each_clear_bit(bit, pf_qmap, size) 3259 count++; 3260 mutex_unlock(lock); 3261 3262 return count; 3263 } 3264 3265 /** 3266 * ice_get_avail_txq_count - Get count of Tx queues in use 3267 * @pf: pointer to an ice_pf instance 3268 */ 3269 u16 ice_get_avail_txq_count(struct ice_pf *pf) 3270 { 3271 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex, 3272 pf->max_pf_txqs); 3273 } 3274 3275 /** 3276 * ice_get_avail_rxq_count - Get count of Rx queues in use 3277 * @pf: pointer to an ice_pf instance 3278 */ 3279 u16 ice_get_avail_rxq_count(struct ice_pf *pf) 3280 { 3281 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex, 3282 pf->max_pf_rxqs); 3283 } 3284 3285 /** 3286 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf 3287 * @pf: board private structure to initialize 3288 */ 3289 static void ice_deinit_pf(struct ice_pf *pf) 3290 { 3291 ice_service_task_stop(pf); 3292 mutex_destroy(&pf->sw_mutex); 3293 mutex_destroy(&pf->tc_mutex); 3294 mutex_destroy(&pf->avail_q_mutex); 3295 3296 if (pf->avail_txqs) { 3297 bitmap_free(pf->avail_txqs); 3298 pf->avail_txqs = NULL; 3299 } 3300 3301 if (pf->avail_rxqs) { 3302 bitmap_free(pf->avail_rxqs); 3303 pf->avail_rxqs = NULL; 3304 } 3305 } 3306 3307 /** 3308 * ice_set_pf_caps - set PFs capability flags 3309 * @pf: pointer to the PF instance 3310 */ 3311 static void ice_set_pf_caps(struct ice_pf *pf) 3312 { 3313 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps; 3314 3315 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 3316 if (func_caps->common_cap.dcb) 3317 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 3318 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags); 3319 if (func_caps->common_cap.sr_iov_1_1) { 3320 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags); 3321 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs, 3322 ICE_MAX_VF_COUNT); 3323 } 3324 clear_bit(ICE_FLAG_RSS_ENA, pf->flags); 3325 if (func_caps->common_cap.rss_table_size) 3326 set_bit(ICE_FLAG_RSS_ENA, pf->flags); 3327 3328 clear_bit(ICE_FLAG_FD_ENA, pf->flags); 3329 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) { 3330 u16 unused; 3331 3332 /* ctrl_vsi_idx will be set to a valid value when flow director 3333 * is setup by ice_init_fdir 3334 */ 3335 pf->ctrl_vsi_idx = ICE_NO_VSI; 3336 set_bit(ICE_FLAG_FD_ENA, pf->flags); 3337 /* force guaranteed filter pool for PF */ 3338 ice_alloc_fd_guar_item(&pf->hw, &unused, 3339 func_caps->fd_fltr_guar); 3340 /* force shared filter pool for PF */ 3341 ice_alloc_fd_shrd_item(&pf->hw, &unused, 3342 func_caps->fd_fltr_best_effort); 3343 } 3344 3345 pf->max_pf_txqs = func_caps->common_cap.num_txq; 3346 pf->max_pf_rxqs = func_caps->common_cap.num_rxq; 3347 } 3348 3349 /** 3350 * ice_init_pf - Initialize general software structures (struct ice_pf) 3351 * @pf: board private structure to initialize 3352 */ 3353 static int ice_init_pf(struct ice_pf *pf) 3354 { 3355 ice_set_pf_caps(pf); 3356 3357 mutex_init(&pf->sw_mutex); 3358 mutex_init(&pf->tc_mutex); 3359 3360 INIT_HLIST_HEAD(&pf->aq_wait_list); 3361 spin_lock_init(&pf->aq_wait_lock); 3362 init_waitqueue_head(&pf->aq_wait_queue); 3363 3364 /* setup service timer and periodic service task */ 3365 timer_setup(&pf->serv_tmr, ice_service_timer, 0); 3366 pf->serv_tmr_period = HZ; 3367 INIT_WORK(&pf->serv_task, ice_service_task); 3368 clear_bit(__ICE_SERVICE_SCHED, pf->state); 3369 3370 mutex_init(&pf->avail_q_mutex); 3371 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL); 3372 if (!pf->avail_txqs) 3373 return -ENOMEM; 3374 3375 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL); 3376 if (!pf->avail_rxqs) { 3377 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs); 3378 pf->avail_txqs = NULL; 3379 return -ENOMEM; 3380 } 3381 3382 return 0; 3383 } 3384 3385 /** 3386 * ice_ena_msix_range - Request a range of MSIX vectors from the OS 3387 * @pf: board private structure 3388 * 3389 * compute the number of MSIX vectors required (v_budget) and request from 3390 * the OS. Return the number of vectors reserved or negative on failure 3391 */ 3392 static int ice_ena_msix_range(struct ice_pf *pf) 3393 { 3394 int v_left, v_actual, v_other, v_budget = 0; 3395 struct device *dev = ice_pf_to_dev(pf); 3396 int needed, err, i; 3397 3398 v_left = pf->hw.func_caps.common_cap.num_msix_vectors; 3399 3400 /* reserve for LAN miscellaneous handler */ 3401 needed = ICE_MIN_LAN_OICR_MSIX; 3402 if (v_left < needed) 3403 goto no_hw_vecs_left_err; 3404 v_budget += needed; 3405 v_left -= needed; 3406 3407 /* reserve for flow director */ 3408 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) { 3409 needed = ICE_FDIR_MSIX; 3410 if (v_left < needed) 3411 goto no_hw_vecs_left_err; 3412 v_budget += needed; 3413 v_left -= needed; 3414 } 3415 3416 /* total used for non-traffic vectors */ 3417 v_other = v_budget; 3418 3419 /* reserve vectors for LAN traffic */ 3420 needed = min_t(int, num_online_cpus(), v_left); 3421 if (v_left < needed) 3422 goto no_hw_vecs_left_err; 3423 pf->num_lan_msix = needed; 3424 v_budget += needed; 3425 v_left -= needed; 3426 3427 pf->msix_entries = devm_kcalloc(dev, v_budget, 3428 sizeof(*pf->msix_entries), GFP_KERNEL); 3429 if (!pf->msix_entries) { 3430 err = -ENOMEM; 3431 goto exit_err; 3432 } 3433 3434 for (i = 0; i < v_budget; i++) 3435 pf->msix_entries[i].entry = i; 3436 3437 /* actually reserve the vectors */ 3438 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries, 3439 ICE_MIN_MSIX, v_budget); 3440 if (v_actual < 0) { 3441 dev_err(dev, "unable to reserve MSI-X vectors\n"); 3442 err = v_actual; 3443 goto msix_err; 3444 } 3445 3446 if (v_actual < v_budget) { 3447 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n", 3448 v_budget, v_actual); 3449 3450 if (v_actual < ICE_MIN_MSIX) { 3451 /* error if we can't get minimum vectors */ 3452 pci_disable_msix(pf->pdev); 3453 err = -ERANGE; 3454 goto msix_err; 3455 } else { 3456 int v_traffic = v_actual - v_other; 3457 3458 if (v_actual == ICE_MIN_MSIX || 3459 v_traffic < ICE_MIN_LAN_TXRX_MSIX) 3460 pf->num_lan_msix = ICE_MIN_LAN_TXRX_MSIX; 3461 else 3462 pf->num_lan_msix = v_traffic; 3463 3464 dev_notice(dev, "Enabled %d MSI-X vectors for LAN traffic.\n", 3465 pf->num_lan_msix); 3466 } 3467 } 3468 3469 return v_actual; 3470 3471 msix_err: 3472 devm_kfree(dev, pf->msix_entries); 3473 goto exit_err; 3474 3475 no_hw_vecs_left_err: 3476 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n", 3477 needed, v_left); 3478 err = -ERANGE; 3479 exit_err: 3480 pf->num_lan_msix = 0; 3481 return err; 3482 } 3483 3484 /** 3485 * ice_dis_msix - Disable MSI-X interrupt setup in OS 3486 * @pf: board private structure 3487 */ 3488 static void ice_dis_msix(struct ice_pf *pf) 3489 { 3490 pci_disable_msix(pf->pdev); 3491 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries); 3492 pf->msix_entries = NULL; 3493 } 3494 3495 /** 3496 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme 3497 * @pf: board private structure 3498 */ 3499 static void ice_clear_interrupt_scheme(struct ice_pf *pf) 3500 { 3501 ice_dis_msix(pf); 3502 3503 if (pf->irq_tracker) { 3504 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker); 3505 pf->irq_tracker = NULL; 3506 } 3507 } 3508 3509 /** 3510 * ice_init_interrupt_scheme - Determine proper interrupt scheme 3511 * @pf: board private structure to initialize 3512 */ 3513 static int ice_init_interrupt_scheme(struct ice_pf *pf) 3514 { 3515 int vectors; 3516 3517 vectors = ice_ena_msix_range(pf); 3518 3519 if (vectors < 0) 3520 return vectors; 3521 3522 /* set up vector assignment tracking */ 3523 pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf), 3524 struct_size(pf->irq_tracker, list, vectors), 3525 GFP_KERNEL); 3526 if (!pf->irq_tracker) { 3527 ice_dis_msix(pf); 3528 return -ENOMEM; 3529 } 3530 3531 /* populate SW interrupts pool with number of OS granted IRQs. */ 3532 pf->num_avail_sw_msix = (u16)vectors; 3533 pf->irq_tracker->num_entries = (u16)vectors; 3534 pf->irq_tracker->end = pf->irq_tracker->num_entries; 3535 3536 return 0; 3537 } 3538 3539 /** 3540 * ice_is_wol_supported - check if WoL is supported 3541 * @hw: pointer to hardware info 3542 * 3543 * Check if WoL is supported based on the HW configuration. 3544 * Returns true if NVM supports and enables WoL for this port, false otherwise 3545 */ 3546 bool ice_is_wol_supported(struct ice_hw *hw) 3547 { 3548 u16 wol_ctrl; 3549 3550 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control 3551 * word) indicates WoL is not supported on the corresponding PF ID. 3552 */ 3553 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl)) 3554 return false; 3555 3556 return !(BIT(hw->port_info->lport) & wol_ctrl); 3557 } 3558 3559 /** 3560 * ice_vsi_recfg_qs - Change the number of queues on a VSI 3561 * @vsi: VSI being changed 3562 * @new_rx: new number of Rx queues 3563 * @new_tx: new number of Tx queues 3564 * 3565 * Only change the number of queues if new_tx, or new_rx is non-0. 3566 * 3567 * Returns 0 on success. 3568 */ 3569 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx) 3570 { 3571 struct ice_pf *pf = vsi->back; 3572 int err = 0, timeout = 50; 3573 3574 if (!new_rx && !new_tx) 3575 return -EINVAL; 3576 3577 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) { 3578 timeout--; 3579 if (!timeout) 3580 return -EBUSY; 3581 usleep_range(1000, 2000); 3582 } 3583 3584 if (new_tx) 3585 vsi->req_txq = (u16)new_tx; 3586 if (new_rx) 3587 vsi->req_rxq = (u16)new_rx; 3588 3589 /* set for the next time the netdev is started */ 3590 if (!netif_running(vsi->netdev)) { 3591 ice_vsi_rebuild(vsi, false); 3592 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n"); 3593 goto done; 3594 } 3595 3596 ice_vsi_close(vsi); 3597 ice_vsi_rebuild(vsi, false); 3598 ice_pf_dcb_recfg(pf); 3599 ice_vsi_open(vsi); 3600 done: 3601 clear_bit(__ICE_CFG_BUSY, pf->state); 3602 return err; 3603 } 3604 3605 /** 3606 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode 3607 * @pf: PF to configure 3608 * 3609 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF 3610 * VSI can still Tx/Rx VLAN tagged packets. 3611 */ 3612 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf) 3613 { 3614 struct ice_vsi *vsi = ice_get_main_vsi(pf); 3615 struct ice_vsi_ctx *ctxt; 3616 enum ice_status status; 3617 struct ice_hw *hw; 3618 3619 if (!vsi) 3620 return; 3621 3622 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL); 3623 if (!ctxt) 3624 return; 3625 3626 hw = &pf->hw; 3627 ctxt->info = vsi->info; 3628 3629 ctxt->info.valid_sections = 3630 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID | 3631 ICE_AQ_VSI_PROP_SECURITY_VALID | 3632 ICE_AQ_VSI_PROP_SW_VALID); 3633 3634 /* disable VLAN anti-spoof */ 3635 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA << 3636 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S); 3637 3638 /* disable VLAN pruning and keep all other settings */ 3639 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA; 3640 3641 /* allow all VLANs on Tx and don't strip on Rx */ 3642 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL | 3643 ICE_AQ_VSI_VLAN_EMOD_NOTHING; 3644 3645 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL); 3646 if (status) { 3647 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %s aq_err %s\n", 3648 ice_stat_str(status), 3649 ice_aq_str(hw->adminq.sq_last_status)); 3650 } else { 3651 vsi->info.sec_flags = ctxt->info.sec_flags; 3652 vsi->info.sw_flags2 = ctxt->info.sw_flags2; 3653 vsi->info.vlan_flags = ctxt->info.vlan_flags; 3654 } 3655 3656 kfree(ctxt); 3657 } 3658 3659 /** 3660 * ice_log_pkg_init - log result of DDP package load 3661 * @hw: pointer to hardware info 3662 * @status: status of package load 3663 */ 3664 static void 3665 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status) 3666 { 3667 struct ice_pf *pf = (struct ice_pf *)hw->back; 3668 struct device *dev = ice_pf_to_dev(pf); 3669 3670 switch (*status) { 3671 case ICE_SUCCESS: 3672 /* The package download AdminQ command returned success because 3673 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is 3674 * already a package loaded on the device. 3675 */ 3676 if (hw->pkg_ver.major == hw->active_pkg_ver.major && 3677 hw->pkg_ver.minor == hw->active_pkg_ver.minor && 3678 hw->pkg_ver.update == hw->active_pkg_ver.update && 3679 hw->pkg_ver.draft == hw->active_pkg_ver.draft && 3680 !memcmp(hw->pkg_name, hw->active_pkg_name, 3681 sizeof(hw->pkg_name))) { 3682 if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST) 3683 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n", 3684 hw->active_pkg_name, 3685 hw->active_pkg_ver.major, 3686 hw->active_pkg_ver.minor, 3687 hw->active_pkg_ver.update, 3688 hw->active_pkg_ver.draft); 3689 else 3690 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n", 3691 hw->active_pkg_name, 3692 hw->active_pkg_ver.major, 3693 hw->active_pkg_ver.minor, 3694 hw->active_pkg_ver.update, 3695 hw->active_pkg_ver.draft); 3696 } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ || 3697 hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) { 3698 dev_err(dev, "The device has a DDP package that is not supported by the driver. The device has package '%s' version %d.%d.x.x. The driver requires version %d.%d.x.x. Entering Safe Mode.\n", 3699 hw->active_pkg_name, 3700 hw->active_pkg_ver.major, 3701 hw->active_pkg_ver.minor, 3702 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR); 3703 *status = ICE_ERR_NOT_SUPPORTED; 3704 } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ && 3705 hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) { 3706 dev_info(dev, "The driver could not load the DDP package file because a compatible DDP package is already present on the device. The device has package '%s' version %d.%d.%d.%d. The package file found by the driver: '%s' version %d.%d.%d.%d.\n", 3707 hw->active_pkg_name, 3708 hw->active_pkg_ver.major, 3709 hw->active_pkg_ver.minor, 3710 hw->active_pkg_ver.update, 3711 hw->active_pkg_ver.draft, 3712 hw->pkg_name, 3713 hw->pkg_ver.major, 3714 hw->pkg_ver.minor, 3715 hw->pkg_ver.update, 3716 hw->pkg_ver.draft); 3717 } else { 3718 dev_err(dev, "An unknown error occurred when loading the DDP package, please reboot the system. If the problem persists, update the NVM. Entering Safe Mode.\n"); 3719 *status = ICE_ERR_NOT_SUPPORTED; 3720 } 3721 break; 3722 case ICE_ERR_FW_DDP_MISMATCH: 3723 dev_err(dev, "The firmware loaded on the device is not compatible with the DDP package. Please update the device's NVM. Entering safe mode.\n"); 3724 break; 3725 case ICE_ERR_BUF_TOO_SHORT: 3726 case ICE_ERR_CFG: 3727 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n"); 3728 break; 3729 case ICE_ERR_NOT_SUPPORTED: 3730 /* Package File version not supported */ 3731 if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ || 3732 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ && 3733 hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR)) 3734 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n"); 3735 else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ || 3736 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ && 3737 hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR)) 3738 dev_err(dev, "The DDP package file version is lower than the driver supports. The driver requires version %d.%d.x.x. Please use an updated DDP Package file. Entering Safe Mode.\n", 3739 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR); 3740 break; 3741 case ICE_ERR_AQ_ERROR: 3742 switch (hw->pkg_dwnld_status) { 3743 case ICE_AQ_RC_ENOSEC: 3744 case ICE_AQ_RC_EBADSIG: 3745 dev_err(dev, "The DDP package could not be loaded because its signature is not valid. Please use a valid DDP Package. Entering Safe Mode.\n"); 3746 return; 3747 case ICE_AQ_RC_ESVN: 3748 dev_err(dev, "The DDP Package could not be loaded because its security revision is too low. Please use an updated DDP Package. Entering Safe Mode.\n"); 3749 return; 3750 case ICE_AQ_RC_EBADMAN: 3751 case ICE_AQ_RC_EBADBUF: 3752 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n"); 3753 /* poll for reset to complete */ 3754 if (ice_check_reset(hw)) 3755 dev_err(dev, "Error resetting device. Please reload the driver\n"); 3756 return; 3757 default: 3758 break; 3759 } 3760 fallthrough; 3761 default: 3762 dev_err(dev, "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n", 3763 *status); 3764 break; 3765 } 3766 } 3767 3768 /** 3769 * ice_load_pkg - load/reload the DDP Package file 3770 * @firmware: firmware structure when firmware requested or NULL for reload 3771 * @pf: pointer to the PF instance 3772 * 3773 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and 3774 * initialize HW tables. 3775 */ 3776 static void 3777 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf) 3778 { 3779 enum ice_status status = ICE_ERR_PARAM; 3780 struct device *dev = ice_pf_to_dev(pf); 3781 struct ice_hw *hw = &pf->hw; 3782 3783 /* Load DDP Package */ 3784 if (firmware && !hw->pkg_copy) { 3785 status = ice_copy_and_init_pkg(hw, firmware->data, 3786 firmware->size); 3787 ice_log_pkg_init(hw, &status); 3788 } else if (!firmware && hw->pkg_copy) { 3789 /* Reload package during rebuild after CORER/GLOBR reset */ 3790 status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size); 3791 ice_log_pkg_init(hw, &status); 3792 } else { 3793 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n"); 3794 } 3795 3796 if (status) { 3797 /* Safe Mode */ 3798 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags); 3799 return; 3800 } 3801 3802 /* Successful download package is the precondition for advanced 3803 * features, hence setting the ICE_FLAG_ADV_FEATURES flag 3804 */ 3805 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags); 3806 } 3807 3808 /** 3809 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines 3810 * @pf: pointer to the PF structure 3811 * 3812 * There is no error returned here because the driver should be able to handle 3813 * 128 Byte cache lines, so we only print a warning in case issues are seen, 3814 * specifically with Tx. 3815 */ 3816 static void ice_verify_cacheline_size(struct ice_pf *pf) 3817 { 3818 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M) 3819 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n", 3820 ICE_CACHE_LINE_BYTES); 3821 } 3822 3823 /** 3824 * ice_send_version - update firmware with driver version 3825 * @pf: PF struct 3826 * 3827 * Returns ICE_SUCCESS on success, else error code 3828 */ 3829 static enum ice_status ice_send_version(struct ice_pf *pf) 3830 { 3831 struct ice_driver_ver dv; 3832 3833 dv.major_ver = 0xff; 3834 dv.minor_ver = 0xff; 3835 dv.build_ver = 0xff; 3836 dv.subbuild_ver = 0; 3837 strscpy((char *)dv.driver_string, UTS_RELEASE, 3838 sizeof(dv.driver_string)); 3839 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL); 3840 } 3841 3842 /** 3843 * ice_init_fdir - Initialize flow director VSI and configuration 3844 * @pf: pointer to the PF instance 3845 * 3846 * returns 0 on success, negative on error 3847 */ 3848 static int ice_init_fdir(struct ice_pf *pf) 3849 { 3850 struct device *dev = ice_pf_to_dev(pf); 3851 struct ice_vsi *ctrl_vsi; 3852 int err; 3853 3854 /* Side Band Flow Director needs to have a control VSI. 3855 * Allocate it and store it in the PF. 3856 */ 3857 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info); 3858 if (!ctrl_vsi) { 3859 dev_dbg(dev, "could not create control VSI\n"); 3860 return -ENOMEM; 3861 } 3862 3863 err = ice_vsi_open_ctrl(ctrl_vsi); 3864 if (err) { 3865 dev_dbg(dev, "could not open control VSI\n"); 3866 goto err_vsi_open; 3867 } 3868 3869 mutex_init(&pf->hw.fdir_fltr_lock); 3870 3871 err = ice_fdir_create_dflt_rules(pf); 3872 if (err) 3873 goto err_fdir_rule; 3874 3875 return 0; 3876 3877 err_fdir_rule: 3878 ice_fdir_release_flows(&pf->hw); 3879 ice_vsi_close(ctrl_vsi); 3880 err_vsi_open: 3881 ice_vsi_release(ctrl_vsi); 3882 if (pf->ctrl_vsi_idx != ICE_NO_VSI) { 3883 pf->vsi[pf->ctrl_vsi_idx] = NULL; 3884 pf->ctrl_vsi_idx = ICE_NO_VSI; 3885 } 3886 return err; 3887 } 3888 3889 /** 3890 * ice_get_opt_fw_name - return optional firmware file name or NULL 3891 * @pf: pointer to the PF instance 3892 */ 3893 static char *ice_get_opt_fw_name(struct ice_pf *pf) 3894 { 3895 /* Optional firmware name same as default with additional dash 3896 * followed by a EUI-64 identifier (PCIe Device Serial Number) 3897 */ 3898 struct pci_dev *pdev = pf->pdev; 3899 char *opt_fw_filename; 3900 u64 dsn; 3901 3902 /* Determine the name of the optional file using the DSN (two 3903 * dwords following the start of the DSN Capability). 3904 */ 3905 dsn = pci_get_dsn(pdev); 3906 if (!dsn) 3907 return NULL; 3908 3909 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL); 3910 if (!opt_fw_filename) 3911 return NULL; 3912 3913 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg", 3914 ICE_DDP_PKG_PATH, dsn); 3915 3916 return opt_fw_filename; 3917 } 3918 3919 /** 3920 * ice_request_fw - Device initialization routine 3921 * @pf: pointer to the PF instance 3922 */ 3923 static void ice_request_fw(struct ice_pf *pf) 3924 { 3925 char *opt_fw_filename = ice_get_opt_fw_name(pf); 3926 const struct firmware *firmware = NULL; 3927 struct device *dev = ice_pf_to_dev(pf); 3928 int err = 0; 3929 3930 /* optional device-specific DDP (if present) overrides the default DDP 3931 * package file. kernel logs a debug message if the file doesn't exist, 3932 * and warning messages for other errors. 3933 */ 3934 if (opt_fw_filename) { 3935 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev); 3936 if (err) { 3937 kfree(opt_fw_filename); 3938 goto dflt_pkg_load; 3939 } 3940 3941 /* request for firmware was successful. Download to device */ 3942 ice_load_pkg(firmware, pf); 3943 kfree(opt_fw_filename); 3944 release_firmware(firmware); 3945 return; 3946 } 3947 3948 dflt_pkg_load: 3949 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev); 3950 if (err) { 3951 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n"); 3952 return; 3953 } 3954 3955 /* request for firmware was successful. Download to device */ 3956 ice_load_pkg(firmware, pf); 3957 release_firmware(firmware); 3958 } 3959 3960 /** 3961 * ice_print_wake_reason - show the wake up cause in the log 3962 * @pf: pointer to the PF struct 3963 */ 3964 static void ice_print_wake_reason(struct ice_pf *pf) 3965 { 3966 u32 wus = pf->wakeup_reason; 3967 const char *wake_str; 3968 3969 /* if no wake event, nothing to print */ 3970 if (!wus) 3971 return; 3972 3973 if (wus & PFPM_WUS_LNKC_M) 3974 wake_str = "Link\n"; 3975 else if (wus & PFPM_WUS_MAG_M) 3976 wake_str = "Magic Packet\n"; 3977 else if (wus & PFPM_WUS_MNG_M) 3978 wake_str = "Management\n"; 3979 else if (wus & PFPM_WUS_FW_RST_WK_M) 3980 wake_str = "Firmware Reset\n"; 3981 else 3982 wake_str = "Unknown\n"; 3983 3984 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str); 3985 } 3986 3987 /** 3988 * ice_probe - Device initialization routine 3989 * @pdev: PCI device information struct 3990 * @ent: entry in ice_pci_tbl 3991 * 3992 * Returns 0 on success, negative on failure 3993 */ 3994 static int 3995 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent) 3996 { 3997 struct device *dev = &pdev->dev; 3998 struct ice_pf *pf; 3999 struct ice_hw *hw; 4000 int i, err; 4001 4002 /* this driver uses devres, see 4003 * Documentation/driver-api/driver-model/devres.rst 4004 */ 4005 err = pcim_enable_device(pdev); 4006 if (err) 4007 return err; 4008 4009 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev)); 4010 if (err) { 4011 dev_err(dev, "BAR0 I/O map error %d\n", err); 4012 return err; 4013 } 4014 4015 pf = ice_allocate_pf(dev); 4016 if (!pf) 4017 return -ENOMEM; 4018 4019 /* set up for high or low DMA */ 4020 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); 4021 if (err) 4022 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 4023 if (err) { 4024 dev_err(dev, "DMA configuration failed: 0x%x\n", err); 4025 return err; 4026 } 4027 4028 pci_enable_pcie_error_reporting(pdev); 4029 pci_set_master(pdev); 4030 4031 pf->pdev = pdev; 4032 pci_set_drvdata(pdev, pf); 4033 set_bit(__ICE_DOWN, pf->state); 4034 /* Disable service task until DOWN bit is cleared */ 4035 set_bit(__ICE_SERVICE_DIS, pf->state); 4036 4037 hw = &pf->hw; 4038 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0]; 4039 pci_save_state(pdev); 4040 4041 hw->back = pf; 4042 hw->vendor_id = pdev->vendor; 4043 hw->device_id = pdev->device; 4044 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); 4045 hw->subsystem_vendor_id = pdev->subsystem_vendor; 4046 hw->subsystem_device_id = pdev->subsystem_device; 4047 hw->bus.device = PCI_SLOT(pdev->devfn); 4048 hw->bus.func = PCI_FUNC(pdev->devfn); 4049 ice_set_ctrlq_len(hw); 4050 4051 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M); 4052 4053 err = ice_devlink_register(pf); 4054 if (err) { 4055 dev_err(dev, "ice_devlink_register failed: %d\n", err); 4056 goto err_exit_unroll; 4057 } 4058 4059 #ifndef CONFIG_DYNAMIC_DEBUG 4060 if (debug < -1) 4061 hw->debug_mask = debug; 4062 #endif 4063 4064 err = ice_init_hw(hw); 4065 if (err) { 4066 dev_err(dev, "ice_init_hw failed: %d\n", err); 4067 err = -EIO; 4068 goto err_exit_unroll; 4069 } 4070 4071 ice_request_fw(pf); 4072 4073 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be 4074 * set in pf->state, which will cause ice_is_safe_mode to return 4075 * true 4076 */ 4077 if (ice_is_safe_mode(pf)) { 4078 dev_err(dev, "Package download failed. Advanced features disabled - Device now in Safe Mode\n"); 4079 /* we already got function/device capabilities but these don't 4080 * reflect what the driver needs to do in safe mode. Instead of 4081 * adding conditional logic everywhere to ignore these 4082 * device/function capabilities, override them. 4083 */ 4084 ice_set_safe_mode_caps(hw); 4085 } 4086 4087 err = ice_init_pf(pf); 4088 if (err) { 4089 dev_err(dev, "ice_init_pf failed: %d\n", err); 4090 goto err_init_pf_unroll; 4091 } 4092 4093 ice_devlink_init_regions(pf); 4094 4095 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port; 4096 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port; 4097 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP; 4098 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared; 4099 i = 0; 4100 if (pf->hw.tnl.valid_count[TNL_VXLAN]) { 4101 pf->hw.udp_tunnel_nic.tables[i].n_entries = 4102 pf->hw.tnl.valid_count[TNL_VXLAN]; 4103 pf->hw.udp_tunnel_nic.tables[i].tunnel_types = 4104 UDP_TUNNEL_TYPE_VXLAN; 4105 i++; 4106 } 4107 if (pf->hw.tnl.valid_count[TNL_GENEVE]) { 4108 pf->hw.udp_tunnel_nic.tables[i].n_entries = 4109 pf->hw.tnl.valid_count[TNL_GENEVE]; 4110 pf->hw.udp_tunnel_nic.tables[i].tunnel_types = 4111 UDP_TUNNEL_TYPE_GENEVE; 4112 i++; 4113 } 4114 4115 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi; 4116 if (!pf->num_alloc_vsi) { 4117 err = -EIO; 4118 goto err_init_pf_unroll; 4119 } 4120 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) { 4121 dev_warn(&pf->pdev->dev, 4122 "limiting the VSI count due to UDP tunnel limitation %d > %d\n", 4123 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES); 4124 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES; 4125 } 4126 4127 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi), 4128 GFP_KERNEL); 4129 if (!pf->vsi) { 4130 err = -ENOMEM; 4131 goto err_init_pf_unroll; 4132 } 4133 4134 err = ice_init_interrupt_scheme(pf); 4135 if (err) { 4136 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err); 4137 err = -EIO; 4138 goto err_init_vsi_unroll; 4139 } 4140 4141 /* In case of MSIX we are going to setup the misc vector right here 4142 * to handle admin queue events etc. In case of legacy and MSI 4143 * the misc functionality and queue processing is combined in 4144 * the same vector and that gets setup at open. 4145 */ 4146 err = ice_req_irq_msix_misc(pf); 4147 if (err) { 4148 dev_err(dev, "setup of misc vector failed: %d\n", err); 4149 goto err_init_interrupt_unroll; 4150 } 4151 4152 /* create switch struct for the switch element created by FW on boot */ 4153 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL); 4154 if (!pf->first_sw) { 4155 err = -ENOMEM; 4156 goto err_msix_misc_unroll; 4157 } 4158 4159 if (hw->evb_veb) 4160 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB; 4161 else 4162 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA; 4163 4164 pf->first_sw->pf = pf; 4165 4166 /* record the sw_id available for later use */ 4167 pf->first_sw->sw_id = hw->port_info->sw_id; 4168 4169 err = ice_setup_pf_sw(pf); 4170 if (err) { 4171 dev_err(dev, "probe failed due to setup PF switch: %d\n", err); 4172 goto err_alloc_sw_unroll; 4173 } 4174 4175 clear_bit(__ICE_SERVICE_DIS, pf->state); 4176 4177 /* tell the firmware we are up */ 4178 err = ice_send_version(pf); 4179 if (err) { 4180 dev_err(dev, "probe failed sending driver version %s. error: %d\n", 4181 UTS_RELEASE, err); 4182 goto err_send_version_unroll; 4183 } 4184 4185 /* since everything is good, start the service timer */ 4186 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 4187 4188 err = ice_init_link_events(pf->hw.port_info); 4189 if (err) { 4190 dev_err(dev, "ice_init_link_events failed: %d\n", err); 4191 goto err_send_version_unroll; 4192 } 4193 4194 /* not a fatal error if this fails */ 4195 err = ice_init_nvm_phy_type(pf->hw.port_info); 4196 if (err) 4197 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err); 4198 4199 /* not a fatal error if this fails */ 4200 err = ice_update_link_info(pf->hw.port_info); 4201 if (err) 4202 dev_err(dev, "ice_update_link_info failed: %d\n", err); 4203 4204 ice_init_link_dflt_override(pf->hw.port_info); 4205 4206 /* if media available, initialize PHY settings */ 4207 if (pf->hw.port_info->phy.link_info.link_info & 4208 ICE_AQ_MEDIA_AVAILABLE) { 4209 /* not a fatal error if this fails */ 4210 err = ice_init_phy_user_cfg(pf->hw.port_info); 4211 if (err) 4212 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err); 4213 4214 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) { 4215 struct ice_vsi *vsi = ice_get_main_vsi(pf); 4216 4217 if (vsi) 4218 ice_configure_phy(vsi); 4219 } 4220 } else { 4221 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 4222 } 4223 4224 ice_verify_cacheline_size(pf); 4225 4226 /* Save wakeup reason register for later use */ 4227 pf->wakeup_reason = rd32(hw, PFPM_WUS); 4228 4229 /* check for a power management event */ 4230 ice_print_wake_reason(pf); 4231 4232 /* clear wake status, all bits */ 4233 wr32(hw, PFPM_WUS, U32_MAX); 4234 4235 /* Disable WoL at init, wait for user to enable */ 4236 device_set_wakeup_enable(dev, false); 4237 4238 if (ice_is_safe_mode(pf)) { 4239 ice_set_safe_mode_vlan_cfg(pf); 4240 goto probe_done; 4241 } 4242 4243 /* initialize DDP driven features */ 4244 4245 /* Note: Flow director init failure is non-fatal to load */ 4246 if (ice_init_fdir(pf)) 4247 dev_err(dev, "could not initialize flow director\n"); 4248 4249 /* Note: DCB init failure is non-fatal to load */ 4250 if (ice_init_pf_dcb(pf, false)) { 4251 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 4252 clear_bit(ICE_FLAG_DCB_ENA, pf->flags); 4253 } else { 4254 ice_cfg_lldp_mib_change(&pf->hw, true); 4255 } 4256 4257 if (ice_init_lag(pf)) 4258 dev_warn(dev, "Failed to init link aggregation support\n"); 4259 4260 /* print PCI link speed and width */ 4261 pcie_print_link_status(pf->pdev); 4262 4263 probe_done: 4264 /* ready to go, so clear down state bit */ 4265 clear_bit(__ICE_DOWN, pf->state); 4266 return 0; 4267 4268 err_send_version_unroll: 4269 ice_vsi_release_all(pf); 4270 err_alloc_sw_unroll: 4271 set_bit(__ICE_SERVICE_DIS, pf->state); 4272 set_bit(__ICE_DOWN, pf->state); 4273 devm_kfree(dev, pf->first_sw); 4274 err_msix_misc_unroll: 4275 ice_free_irq_msix_misc(pf); 4276 err_init_interrupt_unroll: 4277 ice_clear_interrupt_scheme(pf); 4278 err_init_vsi_unroll: 4279 devm_kfree(dev, pf->vsi); 4280 err_init_pf_unroll: 4281 ice_deinit_pf(pf); 4282 ice_devlink_destroy_regions(pf); 4283 ice_deinit_hw(hw); 4284 err_exit_unroll: 4285 ice_devlink_unregister(pf); 4286 pci_disable_pcie_error_reporting(pdev); 4287 pci_disable_device(pdev); 4288 return err; 4289 } 4290 4291 /** 4292 * ice_set_wake - enable or disable Wake on LAN 4293 * @pf: pointer to the PF struct 4294 * 4295 * Simple helper for WoL control 4296 */ 4297 static void ice_set_wake(struct ice_pf *pf) 4298 { 4299 struct ice_hw *hw = &pf->hw; 4300 bool wol = pf->wol_ena; 4301 4302 /* clear wake state, otherwise new wake events won't fire */ 4303 wr32(hw, PFPM_WUS, U32_MAX); 4304 4305 /* enable / disable APM wake up, no RMW needed */ 4306 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0); 4307 4308 /* set magic packet filter enabled */ 4309 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0); 4310 } 4311 4312 /** 4313 * ice_setup_magic_mc_wake - setup device to wake on multicast magic packet 4314 * @pf: pointer to the PF struct 4315 * 4316 * Issue firmware command to enable multicast magic wake, making 4317 * sure that any locally administered address (LAA) is used for 4318 * wake, and that PF reset doesn't undo the LAA. 4319 */ 4320 static void ice_setup_mc_magic_wake(struct ice_pf *pf) 4321 { 4322 struct device *dev = ice_pf_to_dev(pf); 4323 struct ice_hw *hw = &pf->hw; 4324 enum ice_status status; 4325 u8 mac_addr[ETH_ALEN]; 4326 struct ice_vsi *vsi; 4327 u8 flags; 4328 4329 if (!pf->wol_ena) 4330 return; 4331 4332 vsi = ice_get_main_vsi(pf); 4333 if (!vsi) 4334 return; 4335 4336 /* Get current MAC address in case it's an LAA */ 4337 if (vsi->netdev) 4338 ether_addr_copy(mac_addr, vsi->netdev->dev_addr); 4339 else 4340 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 4341 4342 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN | 4343 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL | 4344 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP; 4345 4346 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL); 4347 if (status) 4348 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %s aq_err %s\n", 4349 ice_stat_str(status), 4350 ice_aq_str(hw->adminq.sq_last_status)); 4351 } 4352 4353 /** 4354 * ice_remove - Device removal routine 4355 * @pdev: PCI device information struct 4356 */ 4357 static void ice_remove(struct pci_dev *pdev) 4358 { 4359 struct ice_pf *pf = pci_get_drvdata(pdev); 4360 int i; 4361 4362 if (!pf) 4363 return; 4364 4365 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) { 4366 if (!ice_is_reset_in_progress(pf->state)) 4367 break; 4368 msleep(100); 4369 } 4370 4371 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) { 4372 set_bit(__ICE_VF_RESETS_DISABLED, pf->state); 4373 ice_free_vfs(pf); 4374 } 4375 4376 set_bit(__ICE_DOWN, pf->state); 4377 ice_service_task_stop(pf); 4378 4379 ice_aq_cancel_waiting_tasks(pf); 4380 4381 mutex_destroy(&(&pf->hw)->fdir_fltr_lock); 4382 ice_deinit_lag(pf); 4383 if (!ice_is_safe_mode(pf)) 4384 ice_remove_arfs(pf); 4385 ice_setup_mc_magic_wake(pf); 4386 ice_vsi_release_all(pf); 4387 ice_set_wake(pf); 4388 ice_free_irq_msix_misc(pf); 4389 ice_for_each_vsi(pf, i) { 4390 if (!pf->vsi[i]) 4391 continue; 4392 ice_vsi_free_q_vectors(pf->vsi[i]); 4393 } 4394 ice_deinit_pf(pf); 4395 ice_devlink_destroy_regions(pf); 4396 ice_deinit_hw(&pf->hw); 4397 ice_devlink_unregister(pf); 4398 4399 /* Issue a PFR as part of the prescribed driver unload flow. Do not 4400 * do it via ice_schedule_reset() since there is no need to rebuild 4401 * and the service task is already stopped. 4402 */ 4403 ice_reset(&pf->hw, ICE_RESET_PFR); 4404 pci_wait_for_pending_transaction(pdev); 4405 ice_clear_interrupt_scheme(pf); 4406 pci_disable_pcie_error_reporting(pdev); 4407 pci_disable_device(pdev); 4408 } 4409 4410 /** 4411 * ice_shutdown - PCI callback for shutting down device 4412 * @pdev: PCI device information struct 4413 */ 4414 static void ice_shutdown(struct pci_dev *pdev) 4415 { 4416 struct ice_pf *pf = pci_get_drvdata(pdev); 4417 4418 ice_remove(pdev); 4419 4420 if (system_state == SYSTEM_POWER_OFF) { 4421 pci_wake_from_d3(pdev, pf->wol_ena); 4422 pci_set_power_state(pdev, PCI_D3hot); 4423 } 4424 } 4425 4426 #ifdef CONFIG_PM 4427 /** 4428 * ice_prepare_for_shutdown - prep for PCI shutdown 4429 * @pf: board private structure 4430 * 4431 * Inform or close all dependent features in prep for PCI device shutdown 4432 */ 4433 static void ice_prepare_for_shutdown(struct ice_pf *pf) 4434 { 4435 struct ice_hw *hw = &pf->hw; 4436 u32 v; 4437 4438 /* Notify VFs of impending reset */ 4439 if (ice_check_sq_alive(hw, &hw->mailboxq)) 4440 ice_vc_notify_reset(pf); 4441 4442 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n"); 4443 4444 /* disable the VSIs and their queues that are not already DOWN */ 4445 ice_pf_dis_all_vsi(pf, false); 4446 4447 ice_for_each_vsi(pf, v) 4448 if (pf->vsi[v]) 4449 pf->vsi[v]->vsi_num = 0; 4450 4451 ice_shutdown_all_ctrlq(hw); 4452 } 4453 4454 /** 4455 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme 4456 * @pf: board private structure to reinitialize 4457 * 4458 * This routine reinitialize interrupt scheme that was cleared during 4459 * power management suspend callback. 4460 * 4461 * This should be called during resume routine to re-allocate the q_vectors 4462 * and reacquire interrupts. 4463 */ 4464 static int ice_reinit_interrupt_scheme(struct ice_pf *pf) 4465 { 4466 struct device *dev = ice_pf_to_dev(pf); 4467 int ret, v; 4468 4469 /* Since we clear MSIX flag during suspend, we need to 4470 * set it back during resume... 4471 */ 4472 4473 ret = ice_init_interrupt_scheme(pf); 4474 if (ret) { 4475 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret); 4476 return ret; 4477 } 4478 4479 /* Remap vectors and rings, after successful re-init interrupts */ 4480 ice_for_each_vsi(pf, v) { 4481 if (!pf->vsi[v]) 4482 continue; 4483 4484 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]); 4485 if (ret) 4486 goto err_reinit; 4487 ice_vsi_map_rings_to_vectors(pf->vsi[v]); 4488 } 4489 4490 ret = ice_req_irq_msix_misc(pf); 4491 if (ret) { 4492 dev_err(dev, "Setting up misc vector failed after device suspend %d\n", 4493 ret); 4494 goto err_reinit; 4495 } 4496 4497 return 0; 4498 4499 err_reinit: 4500 while (v--) 4501 if (pf->vsi[v]) 4502 ice_vsi_free_q_vectors(pf->vsi[v]); 4503 4504 return ret; 4505 } 4506 4507 /** 4508 * ice_suspend 4509 * @dev: generic device information structure 4510 * 4511 * Power Management callback to quiesce the device and prepare 4512 * for D3 transition. 4513 */ 4514 static int __maybe_unused ice_suspend(struct device *dev) 4515 { 4516 struct pci_dev *pdev = to_pci_dev(dev); 4517 struct ice_pf *pf; 4518 int disabled, v; 4519 4520 pf = pci_get_drvdata(pdev); 4521 4522 if (!ice_pf_state_is_nominal(pf)) { 4523 dev_err(dev, "Device is not ready, no need to suspend it\n"); 4524 return -EBUSY; 4525 } 4526 4527 /* Stop watchdog tasks until resume completion. 4528 * Even though it is most likely that the service task is 4529 * disabled if the device is suspended or down, the service task's 4530 * state is controlled by a different state bit, and we should 4531 * store and honor whatever state that bit is in at this point. 4532 */ 4533 disabled = ice_service_task_stop(pf); 4534 4535 /* Already suspended?, then there is nothing to do */ 4536 if (test_and_set_bit(__ICE_SUSPENDED, pf->state)) { 4537 if (!disabled) 4538 ice_service_task_restart(pf); 4539 return 0; 4540 } 4541 4542 if (test_bit(__ICE_DOWN, pf->state) || 4543 ice_is_reset_in_progress(pf->state)) { 4544 dev_err(dev, "can't suspend device in reset or already down\n"); 4545 if (!disabled) 4546 ice_service_task_restart(pf); 4547 return 0; 4548 } 4549 4550 ice_setup_mc_magic_wake(pf); 4551 4552 ice_prepare_for_shutdown(pf); 4553 4554 ice_set_wake(pf); 4555 4556 /* Free vectors, clear the interrupt scheme and release IRQs 4557 * for proper hibernation, especially with large number of CPUs. 4558 * Otherwise hibernation might fail when mapping all the vectors back 4559 * to CPU0. 4560 */ 4561 ice_free_irq_msix_misc(pf); 4562 ice_for_each_vsi(pf, v) { 4563 if (!pf->vsi[v]) 4564 continue; 4565 ice_vsi_free_q_vectors(pf->vsi[v]); 4566 } 4567 ice_free_cpu_rx_rmap(ice_get_main_vsi(pf)); 4568 ice_clear_interrupt_scheme(pf); 4569 4570 pci_save_state(pdev); 4571 pci_wake_from_d3(pdev, pf->wol_ena); 4572 pci_set_power_state(pdev, PCI_D3hot); 4573 return 0; 4574 } 4575 4576 /** 4577 * ice_resume - PM callback for waking up from D3 4578 * @dev: generic device information structure 4579 */ 4580 static int __maybe_unused ice_resume(struct device *dev) 4581 { 4582 struct pci_dev *pdev = to_pci_dev(dev); 4583 enum ice_reset_req reset_type; 4584 struct ice_pf *pf; 4585 struct ice_hw *hw; 4586 int ret; 4587 4588 pci_set_power_state(pdev, PCI_D0); 4589 pci_restore_state(pdev); 4590 pci_save_state(pdev); 4591 4592 if (!pci_device_is_present(pdev)) 4593 return -ENODEV; 4594 4595 ret = pci_enable_device_mem(pdev); 4596 if (ret) { 4597 dev_err(dev, "Cannot enable device after suspend\n"); 4598 return ret; 4599 } 4600 4601 pf = pci_get_drvdata(pdev); 4602 hw = &pf->hw; 4603 4604 pf->wakeup_reason = rd32(hw, PFPM_WUS); 4605 ice_print_wake_reason(pf); 4606 4607 /* We cleared the interrupt scheme when we suspended, so we need to 4608 * restore it now to resume device functionality. 4609 */ 4610 ret = ice_reinit_interrupt_scheme(pf); 4611 if (ret) 4612 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret); 4613 4614 clear_bit(__ICE_DOWN, pf->state); 4615 /* Now perform PF reset and rebuild */ 4616 reset_type = ICE_RESET_PFR; 4617 /* re-enable service task for reset, but allow reset to schedule it */ 4618 clear_bit(__ICE_SERVICE_DIS, pf->state); 4619 4620 if (ice_schedule_reset(pf, reset_type)) 4621 dev_err(dev, "Reset during resume failed.\n"); 4622 4623 clear_bit(__ICE_SUSPENDED, pf->state); 4624 ice_service_task_restart(pf); 4625 4626 /* Restart the service task */ 4627 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 4628 4629 return 0; 4630 } 4631 #endif /* CONFIG_PM */ 4632 4633 /** 4634 * ice_pci_err_detected - warning that PCI error has been detected 4635 * @pdev: PCI device information struct 4636 * @err: the type of PCI error 4637 * 4638 * Called to warn that something happened on the PCI bus and the error handling 4639 * is in progress. Allows the driver to gracefully prepare/handle PCI errors. 4640 */ 4641 static pci_ers_result_t 4642 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err) 4643 { 4644 struct ice_pf *pf = pci_get_drvdata(pdev); 4645 4646 if (!pf) { 4647 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n", 4648 __func__, err); 4649 return PCI_ERS_RESULT_DISCONNECT; 4650 } 4651 4652 if (!test_bit(__ICE_SUSPENDED, pf->state)) { 4653 ice_service_task_stop(pf); 4654 4655 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) { 4656 set_bit(__ICE_PFR_REQ, pf->state); 4657 ice_prepare_for_reset(pf); 4658 } 4659 } 4660 4661 return PCI_ERS_RESULT_NEED_RESET; 4662 } 4663 4664 /** 4665 * ice_pci_err_slot_reset - a PCI slot reset has just happened 4666 * @pdev: PCI device information struct 4667 * 4668 * Called to determine if the driver can recover from the PCI slot reset by 4669 * using a register read to determine if the device is recoverable. 4670 */ 4671 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev) 4672 { 4673 struct ice_pf *pf = pci_get_drvdata(pdev); 4674 pci_ers_result_t result; 4675 int err; 4676 u32 reg; 4677 4678 err = pci_enable_device_mem(pdev); 4679 if (err) { 4680 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n", 4681 err); 4682 result = PCI_ERS_RESULT_DISCONNECT; 4683 } else { 4684 pci_set_master(pdev); 4685 pci_restore_state(pdev); 4686 pci_save_state(pdev); 4687 pci_wake_from_d3(pdev, false); 4688 4689 /* Check for life */ 4690 reg = rd32(&pf->hw, GLGEN_RTRIG); 4691 if (!reg) 4692 result = PCI_ERS_RESULT_RECOVERED; 4693 else 4694 result = PCI_ERS_RESULT_DISCONNECT; 4695 } 4696 4697 err = pci_aer_clear_nonfatal_status(pdev); 4698 if (err) 4699 dev_dbg(&pdev->dev, "pci_aer_clear_nonfatal_status() failed, error %d\n", 4700 err); 4701 /* non-fatal, continue */ 4702 4703 return result; 4704 } 4705 4706 /** 4707 * ice_pci_err_resume - restart operations after PCI error recovery 4708 * @pdev: PCI device information struct 4709 * 4710 * Called to allow the driver to bring things back up after PCI error and/or 4711 * reset recovery have finished 4712 */ 4713 static void ice_pci_err_resume(struct pci_dev *pdev) 4714 { 4715 struct ice_pf *pf = pci_get_drvdata(pdev); 4716 4717 if (!pf) { 4718 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n", 4719 __func__); 4720 return; 4721 } 4722 4723 if (test_bit(__ICE_SUSPENDED, pf->state)) { 4724 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n", 4725 __func__); 4726 return; 4727 } 4728 4729 ice_restore_all_vfs_msi_state(pdev); 4730 4731 ice_do_reset(pf, ICE_RESET_PFR); 4732 ice_service_task_restart(pf); 4733 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 4734 } 4735 4736 /** 4737 * ice_pci_err_reset_prepare - prepare device driver for PCI reset 4738 * @pdev: PCI device information struct 4739 */ 4740 static void ice_pci_err_reset_prepare(struct pci_dev *pdev) 4741 { 4742 struct ice_pf *pf = pci_get_drvdata(pdev); 4743 4744 if (!test_bit(__ICE_SUSPENDED, pf->state)) { 4745 ice_service_task_stop(pf); 4746 4747 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) { 4748 set_bit(__ICE_PFR_REQ, pf->state); 4749 ice_prepare_for_reset(pf); 4750 } 4751 } 4752 } 4753 4754 /** 4755 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin 4756 * @pdev: PCI device information struct 4757 */ 4758 static void ice_pci_err_reset_done(struct pci_dev *pdev) 4759 { 4760 ice_pci_err_resume(pdev); 4761 } 4762 4763 /* ice_pci_tbl - PCI Device ID Table 4764 * 4765 * Wildcard entries (PCI_ANY_ID) should come last 4766 * Last entry must be all 0s 4767 * 4768 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, 4769 * Class, Class Mask, private data (not used) } 4770 */ 4771 static const struct pci_device_id ice_pci_tbl[] = { 4772 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 }, 4773 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 }, 4774 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 }, 4775 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 }, 4776 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 }, 4777 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 }, 4778 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 }, 4779 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 }, 4780 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 }, 4781 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 }, 4782 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 }, 4783 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 }, 4784 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 }, 4785 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 }, 4786 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 }, 4787 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 }, 4788 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 }, 4789 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 }, 4790 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 }, 4791 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 }, 4792 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 }, 4793 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 }, 4794 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 }, 4795 /* required last entry */ 4796 { 0, } 4797 }; 4798 MODULE_DEVICE_TABLE(pci, ice_pci_tbl); 4799 4800 static __maybe_unused SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume); 4801 4802 static const struct pci_error_handlers ice_pci_err_handler = { 4803 .error_detected = ice_pci_err_detected, 4804 .slot_reset = ice_pci_err_slot_reset, 4805 .reset_prepare = ice_pci_err_reset_prepare, 4806 .reset_done = ice_pci_err_reset_done, 4807 .resume = ice_pci_err_resume 4808 }; 4809 4810 static struct pci_driver ice_driver = { 4811 .name = KBUILD_MODNAME, 4812 .id_table = ice_pci_tbl, 4813 .probe = ice_probe, 4814 .remove = ice_remove, 4815 #ifdef CONFIG_PM 4816 .driver.pm = &ice_pm_ops, 4817 #endif /* CONFIG_PM */ 4818 .shutdown = ice_shutdown, 4819 .sriov_configure = ice_sriov_configure, 4820 .err_handler = &ice_pci_err_handler 4821 }; 4822 4823 /** 4824 * ice_module_init - Driver registration routine 4825 * 4826 * ice_module_init is the first routine called when the driver is 4827 * loaded. All it does is register with the PCI subsystem. 4828 */ 4829 static int __init ice_module_init(void) 4830 { 4831 int status; 4832 4833 pr_info("%s\n", ice_driver_string); 4834 pr_info("%s\n", ice_copyright); 4835 4836 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME); 4837 if (!ice_wq) { 4838 pr_err("Failed to create workqueue\n"); 4839 return -ENOMEM; 4840 } 4841 4842 status = pci_register_driver(&ice_driver); 4843 if (status) { 4844 pr_err("failed to register PCI driver, err %d\n", status); 4845 destroy_workqueue(ice_wq); 4846 } 4847 4848 return status; 4849 } 4850 module_init(ice_module_init); 4851 4852 /** 4853 * ice_module_exit - Driver exit cleanup routine 4854 * 4855 * ice_module_exit is called just before the driver is removed 4856 * from memory. 4857 */ 4858 static void __exit ice_module_exit(void) 4859 { 4860 pci_unregister_driver(&ice_driver); 4861 destroy_workqueue(ice_wq); 4862 pr_info("module unloaded\n"); 4863 } 4864 module_exit(ice_module_exit); 4865 4866 /** 4867 * ice_set_mac_address - NDO callback to set MAC address 4868 * @netdev: network interface device structure 4869 * @pi: pointer to an address structure 4870 * 4871 * Returns 0 on success, negative on failure 4872 */ 4873 static int ice_set_mac_address(struct net_device *netdev, void *pi) 4874 { 4875 struct ice_netdev_priv *np = netdev_priv(netdev); 4876 struct ice_vsi *vsi = np->vsi; 4877 struct ice_pf *pf = vsi->back; 4878 struct ice_hw *hw = &pf->hw; 4879 struct sockaddr *addr = pi; 4880 enum ice_status status; 4881 u8 flags = 0; 4882 int err = 0; 4883 u8 *mac; 4884 4885 mac = (u8 *)addr->sa_data; 4886 4887 if (!is_valid_ether_addr(mac)) 4888 return -EADDRNOTAVAIL; 4889 4890 if (ether_addr_equal(netdev->dev_addr, mac)) { 4891 netdev_warn(netdev, "already using mac %pM\n", mac); 4892 return 0; 4893 } 4894 4895 if (test_bit(__ICE_DOWN, pf->state) || 4896 ice_is_reset_in_progress(pf->state)) { 4897 netdev_err(netdev, "can't set mac %pM. device not ready\n", 4898 mac); 4899 return -EBUSY; 4900 } 4901 4902 /* Clean up old MAC filter. Not an error if old filter doesn't exist */ 4903 status = ice_fltr_remove_mac(vsi, netdev->dev_addr, ICE_FWD_TO_VSI); 4904 if (status && status != ICE_ERR_DOES_NOT_EXIST) { 4905 err = -EADDRNOTAVAIL; 4906 goto err_update_filters; 4907 } 4908 4909 /* Add filter for new MAC. If filter exists, return success */ 4910 status = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI); 4911 if (status == ICE_ERR_ALREADY_EXISTS) { 4912 /* Although this MAC filter is already present in hardware it's 4913 * possible in some cases (e.g. bonding) that dev_addr was 4914 * modified outside of the driver and needs to be restored back 4915 * to this value. 4916 */ 4917 memcpy(netdev->dev_addr, mac, netdev->addr_len); 4918 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac); 4919 return 0; 4920 } 4921 4922 /* error if the new filter addition failed */ 4923 if (status) 4924 err = -EADDRNOTAVAIL; 4925 4926 err_update_filters: 4927 if (err) { 4928 netdev_err(netdev, "can't set MAC %pM. filter update failed\n", 4929 mac); 4930 return err; 4931 } 4932 4933 /* change the netdev's MAC address */ 4934 memcpy(netdev->dev_addr, mac, netdev->addr_len); 4935 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n", 4936 netdev->dev_addr); 4937 4938 /* write new MAC address to the firmware */ 4939 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL; 4940 status = ice_aq_manage_mac_write(hw, mac, flags, NULL); 4941 if (status) { 4942 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %s\n", 4943 mac, ice_stat_str(status)); 4944 } 4945 return 0; 4946 } 4947 4948 /** 4949 * ice_set_rx_mode - NDO callback to set the netdev filters 4950 * @netdev: network interface device structure 4951 */ 4952 static void ice_set_rx_mode(struct net_device *netdev) 4953 { 4954 struct ice_netdev_priv *np = netdev_priv(netdev); 4955 struct ice_vsi *vsi = np->vsi; 4956 4957 if (!vsi) 4958 return; 4959 4960 /* Set the flags to synchronize filters 4961 * ndo_set_rx_mode may be triggered even without a change in netdev 4962 * flags 4963 */ 4964 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags); 4965 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags); 4966 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags); 4967 4968 /* schedule our worker thread which will take care of 4969 * applying the new filter changes 4970 */ 4971 ice_service_task_schedule(vsi->back); 4972 } 4973 4974 /** 4975 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate 4976 * @netdev: network interface device structure 4977 * @queue_index: Queue ID 4978 * @maxrate: maximum bandwidth in Mbps 4979 */ 4980 static int 4981 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate) 4982 { 4983 struct ice_netdev_priv *np = netdev_priv(netdev); 4984 struct ice_vsi *vsi = np->vsi; 4985 enum ice_status status; 4986 u16 q_handle; 4987 u8 tc; 4988 4989 /* Validate maxrate requested is within permitted range */ 4990 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) { 4991 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n", 4992 maxrate, queue_index); 4993 return -EINVAL; 4994 } 4995 4996 q_handle = vsi->tx_rings[queue_index]->q_handle; 4997 tc = ice_dcb_get_tc(vsi, queue_index); 4998 4999 /* Set BW back to default, when user set maxrate to 0 */ 5000 if (!maxrate) 5001 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc, 5002 q_handle, ICE_MAX_BW); 5003 else 5004 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc, 5005 q_handle, ICE_MAX_BW, maxrate * 1000); 5006 if (status) { 5007 netdev_err(netdev, "Unable to set Tx max rate, error %s\n", 5008 ice_stat_str(status)); 5009 return -EIO; 5010 } 5011 5012 return 0; 5013 } 5014 5015 /** 5016 * ice_fdb_add - add an entry to the hardware database 5017 * @ndm: the input from the stack 5018 * @tb: pointer to array of nladdr (unused) 5019 * @dev: the net device pointer 5020 * @addr: the MAC address entry being added 5021 * @vid: VLAN ID 5022 * @flags: instructions from stack about fdb operation 5023 * @extack: netlink extended ack 5024 */ 5025 static int 5026 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[], 5027 struct net_device *dev, const unsigned char *addr, u16 vid, 5028 u16 flags, struct netlink_ext_ack __always_unused *extack) 5029 { 5030 int err; 5031 5032 if (vid) { 5033 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n"); 5034 return -EINVAL; 5035 } 5036 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { 5037 netdev_err(dev, "FDB only supports static addresses\n"); 5038 return -EINVAL; 5039 } 5040 5041 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) 5042 err = dev_uc_add_excl(dev, addr); 5043 else if (is_multicast_ether_addr(addr)) 5044 err = dev_mc_add_excl(dev, addr); 5045 else 5046 err = -EINVAL; 5047 5048 /* Only return duplicate errors if NLM_F_EXCL is set */ 5049 if (err == -EEXIST && !(flags & NLM_F_EXCL)) 5050 err = 0; 5051 5052 return err; 5053 } 5054 5055 /** 5056 * ice_fdb_del - delete an entry from the hardware database 5057 * @ndm: the input from the stack 5058 * @tb: pointer to array of nladdr (unused) 5059 * @dev: the net device pointer 5060 * @addr: the MAC address entry being added 5061 * @vid: VLAN ID 5062 */ 5063 static int 5064 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[], 5065 struct net_device *dev, const unsigned char *addr, 5066 __always_unused u16 vid) 5067 { 5068 int err; 5069 5070 if (ndm->ndm_state & NUD_PERMANENT) { 5071 netdev_err(dev, "FDB only supports static addresses\n"); 5072 return -EINVAL; 5073 } 5074 5075 if (is_unicast_ether_addr(addr)) 5076 err = dev_uc_del(dev, addr); 5077 else if (is_multicast_ether_addr(addr)) 5078 err = dev_mc_del(dev, addr); 5079 else 5080 err = -EINVAL; 5081 5082 return err; 5083 } 5084 5085 /** 5086 * ice_set_features - set the netdev feature flags 5087 * @netdev: ptr to the netdev being adjusted 5088 * @features: the feature set that the stack is suggesting 5089 */ 5090 static int 5091 ice_set_features(struct net_device *netdev, netdev_features_t features) 5092 { 5093 struct ice_netdev_priv *np = netdev_priv(netdev); 5094 struct ice_vsi *vsi = np->vsi; 5095 struct ice_pf *pf = vsi->back; 5096 int ret = 0; 5097 5098 /* Don't set any netdev advanced features with device in Safe Mode */ 5099 if (ice_is_safe_mode(vsi->back)) { 5100 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n"); 5101 return ret; 5102 } 5103 5104 /* Do not change setting during reset */ 5105 if (ice_is_reset_in_progress(pf->state)) { 5106 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n"); 5107 return -EBUSY; 5108 } 5109 5110 /* Multiple features can be changed in one call so keep features in 5111 * separate if/else statements to guarantee each feature is checked 5112 */ 5113 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH)) 5114 ret = ice_vsi_manage_rss_lut(vsi, true); 5115 else if (!(features & NETIF_F_RXHASH) && 5116 netdev->features & NETIF_F_RXHASH) 5117 ret = ice_vsi_manage_rss_lut(vsi, false); 5118 5119 if ((features & NETIF_F_HW_VLAN_CTAG_RX) && 5120 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) 5121 ret = ice_vsi_manage_vlan_stripping(vsi, true); 5122 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) && 5123 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)) 5124 ret = ice_vsi_manage_vlan_stripping(vsi, false); 5125 5126 if ((features & NETIF_F_HW_VLAN_CTAG_TX) && 5127 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX)) 5128 ret = ice_vsi_manage_vlan_insertion(vsi); 5129 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) && 5130 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX)) 5131 ret = ice_vsi_manage_vlan_insertion(vsi); 5132 5133 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && 5134 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) 5135 ret = ice_cfg_vlan_pruning(vsi, true, false); 5136 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && 5137 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) 5138 ret = ice_cfg_vlan_pruning(vsi, false, false); 5139 5140 if ((features & NETIF_F_NTUPLE) && 5141 !(netdev->features & NETIF_F_NTUPLE)) { 5142 ice_vsi_manage_fdir(vsi, true); 5143 ice_init_arfs(vsi); 5144 } else if (!(features & NETIF_F_NTUPLE) && 5145 (netdev->features & NETIF_F_NTUPLE)) { 5146 ice_vsi_manage_fdir(vsi, false); 5147 ice_clear_arfs(vsi); 5148 } 5149 5150 return ret; 5151 } 5152 5153 /** 5154 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI 5155 * @vsi: VSI to setup VLAN properties for 5156 */ 5157 static int ice_vsi_vlan_setup(struct ice_vsi *vsi) 5158 { 5159 int ret = 0; 5160 5161 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX) 5162 ret = ice_vsi_manage_vlan_stripping(vsi, true); 5163 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX) 5164 ret = ice_vsi_manage_vlan_insertion(vsi); 5165 5166 return ret; 5167 } 5168 5169 /** 5170 * ice_vsi_cfg - Setup the VSI 5171 * @vsi: the VSI being configured 5172 * 5173 * Return 0 on success and negative value on error 5174 */ 5175 int ice_vsi_cfg(struct ice_vsi *vsi) 5176 { 5177 int err; 5178 5179 if (vsi->netdev) { 5180 ice_set_rx_mode(vsi->netdev); 5181 5182 err = ice_vsi_vlan_setup(vsi); 5183 5184 if (err) 5185 return err; 5186 } 5187 ice_vsi_cfg_dcb_rings(vsi); 5188 5189 err = ice_vsi_cfg_lan_txqs(vsi); 5190 if (!err && ice_is_xdp_ena_vsi(vsi)) 5191 err = ice_vsi_cfg_xdp_txqs(vsi); 5192 if (!err) 5193 err = ice_vsi_cfg_rxqs(vsi); 5194 5195 return err; 5196 } 5197 5198 /** 5199 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI 5200 * @vsi: the VSI being configured 5201 */ 5202 static void ice_napi_enable_all(struct ice_vsi *vsi) 5203 { 5204 int q_idx; 5205 5206 if (!vsi->netdev) 5207 return; 5208 5209 ice_for_each_q_vector(vsi, q_idx) { 5210 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx]; 5211 5212 if (q_vector->rx.ring || q_vector->tx.ring) 5213 napi_enable(&q_vector->napi); 5214 } 5215 } 5216 5217 /** 5218 * ice_up_complete - Finish the last steps of bringing up a connection 5219 * @vsi: The VSI being configured 5220 * 5221 * Return 0 on success and negative value on error 5222 */ 5223 static int ice_up_complete(struct ice_vsi *vsi) 5224 { 5225 struct ice_pf *pf = vsi->back; 5226 int err; 5227 5228 ice_vsi_cfg_msix(vsi); 5229 5230 /* Enable only Rx rings, Tx rings were enabled by the FW when the 5231 * Tx queue group list was configured and the context bits were 5232 * programmed using ice_vsi_cfg_txqs 5233 */ 5234 err = ice_vsi_start_all_rx_rings(vsi); 5235 if (err) 5236 return err; 5237 5238 clear_bit(__ICE_DOWN, vsi->state); 5239 ice_napi_enable_all(vsi); 5240 ice_vsi_ena_irq(vsi); 5241 5242 if (vsi->port_info && 5243 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) && 5244 vsi->netdev) { 5245 ice_print_link_msg(vsi, true); 5246 netif_tx_start_all_queues(vsi->netdev); 5247 netif_carrier_on(vsi->netdev); 5248 } 5249 5250 ice_service_task_schedule(pf); 5251 5252 return 0; 5253 } 5254 5255 /** 5256 * ice_up - Bring the connection back up after being down 5257 * @vsi: VSI being configured 5258 */ 5259 int ice_up(struct ice_vsi *vsi) 5260 { 5261 int err; 5262 5263 err = ice_vsi_cfg(vsi); 5264 if (!err) 5265 err = ice_up_complete(vsi); 5266 5267 return err; 5268 } 5269 5270 /** 5271 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring 5272 * @ring: Tx or Rx ring to read stats from 5273 * @pkts: packets stats counter 5274 * @bytes: bytes stats counter 5275 * 5276 * This function fetches stats from the ring considering the atomic operations 5277 * that needs to be performed to read u64 values in 32 bit machine. 5278 */ 5279 static void 5280 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes) 5281 { 5282 unsigned int start; 5283 *pkts = 0; 5284 *bytes = 0; 5285 5286 if (!ring) 5287 return; 5288 do { 5289 start = u64_stats_fetch_begin_irq(&ring->syncp); 5290 *pkts = ring->stats.pkts; 5291 *bytes = ring->stats.bytes; 5292 } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); 5293 } 5294 5295 /** 5296 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters 5297 * @vsi: the VSI to be updated 5298 * @rings: rings to work on 5299 * @count: number of rings 5300 */ 5301 static void 5302 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi, struct ice_ring **rings, 5303 u16 count) 5304 { 5305 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats; 5306 u16 i; 5307 5308 for (i = 0; i < count; i++) { 5309 struct ice_ring *ring; 5310 u64 pkts, bytes; 5311 5312 ring = READ_ONCE(rings[i]); 5313 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes); 5314 vsi_stats->tx_packets += pkts; 5315 vsi_stats->tx_bytes += bytes; 5316 vsi->tx_restart += ring->tx_stats.restart_q; 5317 vsi->tx_busy += ring->tx_stats.tx_busy; 5318 vsi->tx_linearize += ring->tx_stats.tx_linearize; 5319 } 5320 } 5321 5322 /** 5323 * ice_update_vsi_ring_stats - Update VSI stats counters 5324 * @vsi: the VSI to be updated 5325 */ 5326 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi) 5327 { 5328 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats; 5329 struct ice_ring *ring; 5330 u64 pkts, bytes; 5331 int i; 5332 5333 /* reset netdev stats */ 5334 vsi_stats->tx_packets = 0; 5335 vsi_stats->tx_bytes = 0; 5336 vsi_stats->rx_packets = 0; 5337 vsi_stats->rx_bytes = 0; 5338 5339 /* reset non-netdev (extended) stats */ 5340 vsi->tx_restart = 0; 5341 vsi->tx_busy = 0; 5342 vsi->tx_linearize = 0; 5343 vsi->rx_buf_failed = 0; 5344 vsi->rx_page_failed = 0; 5345 vsi->rx_gro_dropped = 0; 5346 5347 rcu_read_lock(); 5348 5349 /* update Tx rings counters */ 5350 ice_update_vsi_tx_ring_stats(vsi, vsi->tx_rings, vsi->num_txq); 5351 5352 /* update Rx rings counters */ 5353 ice_for_each_rxq(vsi, i) { 5354 ring = READ_ONCE(vsi->rx_rings[i]); 5355 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes); 5356 vsi_stats->rx_packets += pkts; 5357 vsi_stats->rx_bytes += bytes; 5358 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed; 5359 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed; 5360 vsi->rx_gro_dropped += ring->rx_stats.gro_dropped; 5361 } 5362 5363 /* update XDP Tx rings counters */ 5364 if (ice_is_xdp_ena_vsi(vsi)) 5365 ice_update_vsi_tx_ring_stats(vsi, vsi->xdp_rings, 5366 vsi->num_xdp_txq); 5367 5368 rcu_read_unlock(); 5369 } 5370 5371 /** 5372 * ice_update_vsi_stats - Update VSI stats counters 5373 * @vsi: the VSI to be updated 5374 */ 5375 void ice_update_vsi_stats(struct ice_vsi *vsi) 5376 { 5377 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats; 5378 struct ice_eth_stats *cur_es = &vsi->eth_stats; 5379 struct ice_pf *pf = vsi->back; 5380 5381 if (test_bit(__ICE_DOWN, vsi->state) || 5382 test_bit(__ICE_CFG_BUSY, pf->state)) 5383 return; 5384 5385 /* get stats as recorded by Tx/Rx rings */ 5386 ice_update_vsi_ring_stats(vsi); 5387 5388 /* get VSI stats as recorded by the hardware */ 5389 ice_update_eth_stats(vsi); 5390 5391 cur_ns->tx_errors = cur_es->tx_errors; 5392 cur_ns->rx_dropped = cur_es->rx_discards + vsi->rx_gro_dropped; 5393 cur_ns->tx_dropped = cur_es->tx_discards; 5394 cur_ns->multicast = cur_es->rx_multicast; 5395 5396 /* update some more netdev stats if this is main VSI */ 5397 if (vsi->type == ICE_VSI_PF) { 5398 cur_ns->rx_crc_errors = pf->stats.crc_errors; 5399 cur_ns->rx_errors = pf->stats.crc_errors + 5400 pf->stats.illegal_bytes + 5401 pf->stats.rx_len_errors + 5402 pf->stats.rx_undersize + 5403 pf->hw_csum_rx_error + 5404 pf->stats.rx_jabber + 5405 pf->stats.rx_fragments + 5406 pf->stats.rx_oversize; 5407 cur_ns->rx_length_errors = pf->stats.rx_len_errors; 5408 /* record drops from the port level */ 5409 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards; 5410 } 5411 } 5412 5413 /** 5414 * ice_update_pf_stats - Update PF port stats counters 5415 * @pf: PF whose stats needs to be updated 5416 */ 5417 void ice_update_pf_stats(struct ice_pf *pf) 5418 { 5419 struct ice_hw_port_stats *prev_ps, *cur_ps; 5420 struct ice_hw *hw = &pf->hw; 5421 u16 fd_ctr_base; 5422 u8 port; 5423 5424 port = hw->port_info->lport; 5425 prev_ps = &pf->stats_prev; 5426 cur_ps = &pf->stats; 5427 5428 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded, 5429 &prev_ps->eth.rx_bytes, 5430 &cur_ps->eth.rx_bytes); 5431 5432 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded, 5433 &prev_ps->eth.rx_unicast, 5434 &cur_ps->eth.rx_unicast); 5435 5436 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded, 5437 &prev_ps->eth.rx_multicast, 5438 &cur_ps->eth.rx_multicast); 5439 5440 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded, 5441 &prev_ps->eth.rx_broadcast, 5442 &cur_ps->eth.rx_broadcast); 5443 5444 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded, 5445 &prev_ps->eth.rx_discards, 5446 &cur_ps->eth.rx_discards); 5447 5448 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded, 5449 &prev_ps->eth.tx_bytes, 5450 &cur_ps->eth.tx_bytes); 5451 5452 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded, 5453 &prev_ps->eth.tx_unicast, 5454 &cur_ps->eth.tx_unicast); 5455 5456 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded, 5457 &prev_ps->eth.tx_multicast, 5458 &cur_ps->eth.tx_multicast); 5459 5460 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded, 5461 &prev_ps->eth.tx_broadcast, 5462 &cur_ps->eth.tx_broadcast); 5463 5464 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded, 5465 &prev_ps->tx_dropped_link_down, 5466 &cur_ps->tx_dropped_link_down); 5467 5468 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded, 5469 &prev_ps->rx_size_64, &cur_ps->rx_size_64); 5470 5471 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded, 5472 &prev_ps->rx_size_127, &cur_ps->rx_size_127); 5473 5474 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded, 5475 &prev_ps->rx_size_255, &cur_ps->rx_size_255); 5476 5477 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded, 5478 &prev_ps->rx_size_511, &cur_ps->rx_size_511); 5479 5480 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded, 5481 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023); 5482 5483 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded, 5484 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522); 5485 5486 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded, 5487 &prev_ps->rx_size_big, &cur_ps->rx_size_big); 5488 5489 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded, 5490 &prev_ps->tx_size_64, &cur_ps->tx_size_64); 5491 5492 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded, 5493 &prev_ps->tx_size_127, &cur_ps->tx_size_127); 5494 5495 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded, 5496 &prev_ps->tx_size_255, &cur_ps->tx_size_255); 5497 5498 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded, 5499 &prev_ps->tx_size_511, &cur_ps->tx_size_511); 5500 5501 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded, 5502 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023); 5503 5504 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded, 5505 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522); 5506 5507 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded, 5508 &prev_ps->tx_size_big, &cur_ps->tx_size_big); 5509 5510 fd_ctr_base = hw->fd_ctr_base; 5511 5512 ice_stat_update40(hw, 5513 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)), 5514 pf->stat_prev_loaded, &prev_ps->fd_sb_match, 5515 &cur_ps->fd_sb_match); 5516 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded, 5517 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx); 5518 5519 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded, 5520 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx); 5521 5522 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded, 5523 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx); 5524 5525 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded, 5526 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx); 5527 5528 ice_update_dcb_stats(pf); 5529 5530 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded, 5531 &prev_ps->crc_errors, &cur_ps->crc_errors); 5532 5533 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded, 5534 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes); 5535 5536 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded, 5537 &prev_ps->mac_local_faults, 5538 &cur_ps->mac_local_faults); 5539 5540 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded, 5541 &prev_ps->mac_remote_faults, 5542 &cur_ps->mac_remote_faults); 5543 5544 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded, 5545 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors); 5546 5547 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded, 5548 &prev_ps->rx_undersize, &cur_ps->rx_undersize); 5549 5550 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded, 5551 &prev_ps->rx_fragments, &cur_ps->rx_fragments); 5552 5553 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded, 5554 &prev_ps->rx_oversize, &cur_ps->rx_oversize); 5555 5556 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded, 5557 &prev_ps->rx_jabber, &cur_ps->rx_jabber); 5558 5559 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0; 5560 5561 pf->stat_prev_loaded = true; 5562 } 5563 5564 /** 5565 * ice_get_stats64 - get statistics for network device structure 5566 * @netdev: network interface device structure 5567 * @stats: main device statistics structure 5568 */ 5569 static 5570 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) 5571 { 5572 struct ice_netdev_priv *np = netdev_priv(netdev); 5573 struct rtnl_link_stats64 *vsi_stats; 5574 struct ice_vsi *vsi = np->vsi; 5575 5576 vsi_stats = &vsi->net_stats; 5577 5578 if (!vsi->num_txq || !vsi->num_rxq) 5579 return; 5580 5581 /* netdev packet/byte stats come from ring counter. These are obtained 5582 * by summing up ring counters (done by ice_update_vsi_ring_stats). 5583 * But, only call the update routine and read the registers if VSI is 5584 * not down. 5585 */ 5586 if (!test_bit(__ICE_DOWN, vsi->state)) 5587 ice_update_vsi_ring_stats(vsi); 5588 stats->tx_packets = vsi_stats->tx_packets; 5589 stats->tx_bytes = vsi_stats->tx_bytes; 5590 stats->rx_packets = vsi_stats->rx_packets; 5591 stats->rx_bytes = vsi_stats->rx_bytes; 5592 5593 /* The rest of the stats can be read from the hardware but instead we 5594 * just return values that the watchdog task has already obtained from 5595 * the hardware. 5596 */ 5597 stats->multicast = vsi_stats->multicast; 5598 stats->tx_errors = vsi_stats->tx_errors; 5599 stats->tx_dropped = vsi_stats->tx_dropped; 5600 stats->rx_errors = vsi_stats->rx_errors; 5601 stats->rx_dropped = vsi_stats->rx_dropped; 5602 stats->rx_crc_errors = vsi_stats->rx_crc_errors; 5603 stats->rx_length_errors = vsi_stats->rx_length_errors; 5604 } 5605 5606 /** 5607 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI 5608 * @vsi: VSI having NAPI disabled 5609 */ 5610 static void ice_napi_disable_all(struct ice_vsi *vsi) 5611 { 5612 int q_idx; 5613 5614 if (!vsi->netdev) 5615 return; 5616 5617 ice_for_each_q_vector(vsi, q_idx) { 5618 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx]; 5619 5620 if (q_vector->rx.ring || q_vector->tx.ring) 5621 napi_disable(&q_vector->napi); 5622 } 5623 } 5624 5625 /** 5626 * ice_down - Shutdown the connection 5627 * @vsi: The VSI being stopped 5628 */ 5629 int ice_down(struct ice_vsi *vsi) 5630 { 5631 int i, tx_err, rx_err, link_err = 0; 5632 5633 /* Caller of this function is expected to set the 5634 * vsi->state __ICE_DOWN bit 5635 */ 5636 if (vsi->netdev) { 5637 netif_carrier_off(vsi->netdev); 5638 netif_tx_disable(vsi->netdev); 5639 } 5640 5641 ice_vsi_dis_irq(vsi); 5642 5643 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0); 5644 if (tx_err) 5645 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n", 5646 vsi->vsi_num, tx_err); 5647 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) { 5648 tx_err = ice_vsi_stop_xdp_tx_rings(vsi); 5649 if (tx_err) 5650 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n", 5651 vsi->vsi_num, tx_err); 5652 } 5653 5654 rx_err = ice_vsi_stop_all_rx_rings(vsi); 5655 if (rx_err) 5656 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n", 5657 vsi->vsi_num, rx_err); 5658 5659 ice_napi_disable_all(vsi); 5660 5661 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) { 5662 link_err = ice_force_phys_link_state(vsi, false); 5663 if (link_err) 5664 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n", 5665 vsi->vsi_num, link_err); 5666 } 5667 5668 ice_for_each_txq(vsi, i) 5669 ice_clean_tx_ring(vsi->tx_rings[i]); 5670 5671 ice_for_each_rxq(vsi, i) 5672 ice_clean_rx_ring(vsi->rx_rings[i]); 5673 5674 if (tx_err || rx_err || link_err) { 5675 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n", 5676 vsi->vsi_num, vsi->vsw->sw_id); 5677 return -EIO; 5678 } 5679 5680 return 0; 5681 } 5682 5683 /** 5684 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources 5685 * @vsi: VSI having resources allocated 5686 * 5687 * Return 0 on success, negative on failure 5688 */ 5689 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi) 5690 { 5691 int i, err = 0; 5692 5693 if (!vsi->num_txq) { 5694 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n", 5695 vsi->vsi_num); 5696 return -EINVAL; 5697 } 5698 5699 ice_for_each_txq(vsi, i) { 5700 struct ice_ring *ring = vsi->tx_rings[i]; 5701 5702 if (!ring) 5703 return -EINVAL; 5704 5705 ring->netdev = vsi->netdev; 5706 err = ice_setup_tx_ring(ring); 5707 if (err) 5708 break; 5709 } 5710 5711 return err; 5712 } 5713 5714 /** 5715 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources 5716 * @vsi: VSI having resources allocated 5717 * 5718 * Return 0 on success, negative on failure 5719 */ 5720 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi) 5721 { 5722 int i, err = 0; 5723 5724 if (!vsi->num_rxq) { 5725 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n", 5726 vsi->vsi_num); 5727 return -EINVAL; 5728 } 5729 5730 ice_for_each_rxq(vsi, i) { 5731 struct ice_ring *ring = vsi->rx_rings[i]; 5732 5733 if (!ring) 5734 return -EINVAL; 5735 5736 ring->netdev = vsi->netdev; 5737 err = ice_setup_rx_ring(ring); 5738 if (err) 5739 break; 5740 } 5741 5742 return err; 5743 } 5744 5745 /** 5746 * ice_vsi_open_ctrl - open control VSI for use 5747 * @vsi: the VSI to open 5748 * 5749 * Initialization of the Control VSI 5750 * 5751 * Returns 0 on success, negative value on error 5752 */ 5753 int ice_vsi_open_ctrl(struct ice_vsi *vsi) 5754 { 5755 char int_name[ICE_INT_NAME_STR_LEN]; 5756 struct ice_pf *pf = vsi->back; 5757 struct device *dev; 5758 int err; 5759 5760 dev = ice_pf_to_dev(pf); 5761 /* allocate descriptors */ 5762 err = ice_vsi_setup_tx_rings(vsi); 5763 if (err) 5764 goto err_setup_tx; 5765 5766 err = ice_vsi_setup_rx_rings(vsi); 5767 if (err) 5768 goto err_setup_rx; 5769 5770 err = ice_vsi_cfg(vsi); 5771 if (err) 5772 goto err_setup_rx; 5773 5774 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl", 5775 dev_driver_string(dev), dev_name(dev)); 5776 err = ice_vsi_req_irq_msix(vsi, int_name); 5777 if (err) 5778 goto err_setup_rx; 5779 5780 ice_vsi_cfg_msix(vsi); 5781 5782 err = ice_vsi_start_all_rx_rings(vsi); 5783 if (err) 5784 goto err_up_complete; 5785 5786 clear_bit(__ICE_DOWN, vsi->state); 5787 ice_vsi_ena_irq(vsi); 5788 5789 return 0; 5790 5791 err_up_complete: 5792 ice_down(vsi); 5793 err_setup_rx: 5794 ice_vsi_free_rx_rings(vsi); 5795 err_setup_tx: 5796 ice_vsi_free_tx_rings(vsi); 5797 5798 return err; 5799 } 5800 5801 /** 5802 * ice_vsi_open - Called when a network interface is made active 5803 * @vsi: the VSI to open 5804 * 5805 * Initialization of the VSI 5806 * 5807 * Returns 0 on success, negative value on error 5808 */ 5809 static int ice_vsi_open(struct ice_vsi *vsi) 5810 { 5811 char int_name[ICE_INT_NAME_STR_LEN]; 5812 struct ice_pf *pf = vsi->back; 5813 int err; 5814 5815 /* allocate descriptors */ 5816 err = ice_vsi_setup_tx_rings(vsi); 5817 if (err) 5818 goto err_setup_tx; 5819 5820 err = ice_vsi_setup_rx_rings(vsi); 5821 if (err) 5822 goto err_setup_rx; 5823 5824 err = ice_vsi_cfg(vsi); 5825 if (err) 5826 goto err_setup_rx; 5827 5828 snprintf(int_name, sizeof(int_name) - 1, "%s-%s", 5829 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name); 5830 err = ice_vsi_req_irq_msix(vsi, int_name); 5831 if (err) 5832 goto err_setup_rx; 5833 5834 /* Notify the stack of the actual queue counts. */ 5835 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq); 5836 if (err) 5837 goto err_set_qs; 5838 5839 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq); 5840 if (err) 5841 goto err_set_qs; 5842 5843 err = ice_up_complete(vsi); 5844 if (err) 5845 goto err_up_complete; 5846 5847 return 0; 5848 5849 err_up_complete: 5850 ice_down(vsi); 5851 err_set_qs: 5852 ice_vsi_free_irq(vsi); 5853 err_setup_rx: 5854 ice_vsi_free_rx_rings(vsi); 5855 err_setup_tx: 5856 ice_vsi_free_tx_rings(vsi); 5857 5858 return err; 5859 } 5860 5861 /** 5862 * ice_vsi_release_all - Delete all VSIs 5863 * @pf: PF from which all VSIs are being removed 5864 */ 5865 static void ice_vsi_release_all(struct ice_pf *pf) 5866 { 5867 int err, i; 5868 5869 if (!pf->vsi) 5870 return; 5871 5872 ice_for_each_vsi(pf, i) { 5873 if (!pf->vsi[i]) 5874 continue; 5875 5876 err = ice_vsi_release(pf->vsi[i]); 5877 if (err) 5878 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n", 5879 i, err, pf->vsi[i]->vsi_num); 5880 } 5881 } 5882 5883 /** 5884 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type 5885 * @pf: pointer to the PF instance 5886 * @type: VSI type to rebuild 5887 * 5888 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type 5889 */ 5890 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type) 5891 { 5892 struct device *dev = ice_pf_to_dev(pf); 5893 enum ice_status status; 5894 int i, err; 5895 5896 ice_for_each_vsi(pf, i) { 5897 struct ice_vsi *vsi = pf->vsi[i]; 5898 5899 if (!vsi || vsi->type != type) 5900 continue; 5901 5902 /* rebuild the VSI */ 5903 err = ice_vsi_rebuild(vsi, true); 5904 if (err) { 5905 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n", 5906 err, vsi->idx, ice_vsi_type_str(type)); 5907 return err; 5908 } 5909 5910 /* replay filters for the VSI */ 5911 status = ice_replay_vsi(&pf->hw, vsi->idx); 5912 if (status) { 5913 dev_err(dev, "replay VSI failed, status %s, VSI index %d, type %s\n", 5914 ice_stat_str(status), vsi->idx, 5915 ice_vsi_type_str(type)); 5916 return -EIO; 5917 } 5918 5919 /* Re-map HW VSI number, using VSI handle that has been 5920 * previously validated in ice_replay_vsi() call above 5921 */ 5922 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx); 5923 5924 /* enable the VSI */ 5925 err = ice_ena_vsi(vsi, false); 5926 if (err) { 5927 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n", 5928 err, vsi->idx, ice_vsi_type_str(type)); 5929 return err; 5930 } 5931 5932 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx, 5933 ice_vsi_type_str(type)); 5934 } 5935 5936 return 0; 5937 } 5938 5939 /** 5940 * ice_update_pf_netdev_link - Update PF netdev link status 5941 * @pf: pointer to the PF instance 5942 */ 5943 static void ice_update_pf_netdev_link(struct ice_pf *pf) 5944 { 5945 bool link_up; 5946 int i; 5947 5948 ice_for_each_vsi(pf, i) { 5949 struct ice_vsi *vsi = pf->vsi[i]; 5950 5951 if (!vsi || vsi->type != ICE_VSI_PF) 5952 return; 5953 5954 ice_get_link_status(pf->vsi[i]->port_info, &link_up); 5955 if (link_up) { 5956 netif_carrier_on(pf->vsi[i]->netdev); 5957 netif_tx_wake_all_queues(pf->vsi[i]->netdev); 5958 } else { 5959 netif_carrier_off(pf->vsi[i]->netdev); 5960 netif_tx_stop_all_queues(pf->vsi[i]->netdev); 5961 } 5962 } 5963 } 5964 5965 /** 5966 * ice_rebuild - rebuild after reset 5967 * @pf: PF to rebuild 5968 * @reset_type: type of reset 5969 * 5970 * Do not rebuild VF VSI in this flow because that is already handled via 5971 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a 5972 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want 5973 * to reset/rebuild all the VF VSI twice. 5974 */ 5975 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) 5976 { 5977 struct device *dev = ice_pf_to_dev(pf); 5978 struct ice_hw *hw = &pf->hw; 5979 enum ice_status ret; 5980 int err; 5981 5982 if (test_bit(__ICE_DOWN, pf->state)) 5983 goto clear_recovery; 5984 5985 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type); 5986 5987 ret = ice_init_all_ctrlq(hw); 5988 if (ret) { 5989 dev_err(dev, "control queues init failed %s\n", 5990 ice_stat_str(ret)); 5991 goto err_init_ctrlq; 5992 } 5993 5994 /* if DDP was previously loaded successfully */ 5995 if (!ice_is_safe_mode(pf)) { 5996 /* reload the SW DB of filter tables */ 5997 if (reset_type == ICE_RESET_PFR) 5998 ice_fill_blk_tbls(hw); 5999 else 6000 /* Reload DDP Package after CORER/GLOBR reset */ 6001 ice_load_pkg(NULL, pf); 6002 } 6003 6004 ret = ice_clear_pf_cfg(hw); 6005 if (ret) { 6006 dev_err(dev, "clear PF configuration failed %s\n", 6007 ice_stat_str(ret)); 6008 goto err_init_ctrlq; 6009 } 6010 6011 if (pf->first_sw->dflt_vsi_ena) 6012 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n"); 6013 /* clear the default VSI configuration if it exists */ 6014 pf->first_sw->dflt_vsi = NULL; 6015 pf->first_sw->dflt_vsi_ena = false; 6016 6017 ice_clear_pxe_mode(hw); 6018 6019 ret = ice_get_caps(hw); 6020 if (ret) { 6021 dev_err(dev, "ice_get_caps failed %s\n", ice_stat_str(ret)); 6022 goto err_init_ctrlq; 6023 } 6024 6025 ret = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL); 6026 if (ret) { 6027 dev_err(dev, "set_mac_cfg failed %s\n", ice_stat_str(ret)); 6028 goto err_init_ctrlq; 6029 } 6030 6031 err = ice_sched_init_port(hw->port_info); 6032 if (err) 6033 goto err_sched_init_port; 6034 6035 /* start misc vector */ 6036 err = ice_req_irq_msix_misc(pf); 6037 if (err) { 6038 dev_err(dev, "misc vector setup failed: %d\n", err); 6039 goto err_sched_init_port; 6040 } 6041 6042 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) { 6043 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M); 6044 if (!rd32(hw, PFQF_FD_SIZE)) { 6045 u16 unused, guar, b_effort; 6046 6047 guar = hw->func_caps.fd_fltr_guar; 6048 b_effort = hw->func_caps.fd_fltr_best_effort; 6049 6050 /* force guaranteed filter pool for PF */ 6051 ice_alloc_fd_guar_item(hw, &unused, guar); 6052 /* force shared filter pool for PF */ 6053 ice_alloc_fd_shrd_item(hw, &unused, b_effort); 6054 } 6055 } 6056 6057 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags)) 6058 ice_dcb_rebuild(pf); 6059 6060 /* rebuild PF VSI */ 6061 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF); 6062 if (err) { 6063 dev_err(dev, "PF VSI rebuild failed: %d\n", err); 6064 goto err_vsi_rebuild; 6065 } 6066 6067 /* If Flow Director is active */ 6068 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) { 6069 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL); 6070 if (err) { 6071 dev_err(dev, "control VSI rebuild failed: %d\n", err); 6072 goto err_vsi_rebuild; 6073 } 6074 6075 /* replay HW Flow Director recipes */ 6076 if (hw->fdir_prof) 6077 ice_fdir_replay_flows(hw); 6078 6079 /* replay Flow Director filters */ 6080 ice_fdir_replay_fltrs(pf); 6081 6082 ice_rebuild_arfs(pf); 6083 } 6084 6085 ice_update_pf_netdev_link(pf); 6086 6087 /* tell the firmware we are up */ 6088 ret = ice_send_version(pf); 6089 if (ret) { 6090 dev_err(dev, "Rebuild failed due to error sending driver version: %s\n", 6091 ice_stat_str(ret)); 6092 goto err_vsi_rebuild; 6093 } 6094 6095 ice_replay_post(hw); 6096 6097 /* if we get here, reset flow is successful */ 6098 clear_bit(__ICE_RESET_FAILED, pf->state); 6099 return; 6100 6101 err_vsi_rebuild: 6102 err_sched_init_port: 6103 ice_sched_cleanup_all(hw); 6104 err_init_ctrlq: 6105 ice_shutdown_all_ctrlq(hw); 6106 set_bit(__ICE_RESET_FAILED, pf->state); 6107 clear_recovery: 6108 /* set this bit in PF state to control service task scheduling */ 6109 set_bit(__ICE_NEEDS_RESTART, pf->state); 6110 dev_err(dev, "Rebuild failed, unload and reload driver\n"); 6111 } 6112 6113 /** 6114 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP 6115 * @vsi: Pointer to VSI structure 6116 */ 6117 static int ice_max_xdp_frame_size(struct ice_vsi *vsi) 6118 { 6119 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) 6120 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM; 6121 else 6122 return ICE_RXBUF_3072; 6123 } 6124 6125 /** 6126 * ice_change_mtu - NDO callback to change the MTU 6127 * @netdev: network interface device structure 6128 * @new_mtu: new value for maximum frame size 6129 * 6130 * Returns 0 on success, negative on failure 6131 */ 6132 static int ice_change_mtu(struct net_device *netdev, int new_mtu) 6133 { 6134 struct ice_netdev_priv *np = netdev_priv(netdev); 6135 struct ice_vsi *vsi = np->vsi; 6136 struct ice_pf *pf = vsi->back; 6137 u8 count = 0; 6138 6139 if (new_mtu == (int)netdev->mtu) { 6140 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu); 6141 return 0; 6142 } 6143 6144 if (ice_is_xdp_ena_vsi(vsi)) { 6145 int frame_size = ice_max_xdp_frame_size(vsi); 6146 6147 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) { 6148 netdev_err(netdev, "max MTU for XDP usage is %d\n", 6149 frame_size - ICE_ETH_PKT_HDR_PAD); 6150 return -EINVAL; 6151 } 6152 } 6153 6154 /* if a reset is in progress, wait for some time for it to complete */ 6155 do { 6156 if (ice_is_reset_in_progress(pf->state)) { 6157 count++; 6158 usleep_range(1000, 2000); 6159 } else { 6160 break; 6161 } 6162 6163 } while (count < 100); 6164 6165 if (count == 100) { 6166 netdev_err(netdev, "can't change MTU. Device is busy\n"); 6167 return -EBUSY; 6168 } 6169 6170 netdev->mtu = (unsigned int)new_mtu; 6171 6172 /* if VSI is up, bring it down and then back up */ 6173 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) { 6174 int err; 6175 6176 err = ice_down(vsi); 6177 if (err) { 6178 netdev_err(netdev, "change MTU if_down err %d\n", err); 6179 return err; 6180 } 6181 6182 err = ice_up(vsi); 6183 if (err) { 6184 netdev_err(netdev, "change MTU if_up err %d\n", err); 6185 return err; 6186 } 6187 } 6188 6189 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu); 6190 return 0; 6191 } 6192 6193 /** 6194 * ice_aq_str - convert AQ err code to a string 6195 * @aq_err: the AQ error code to convert 6196 */ 6197 const char *ice_aq_str(enum ice_aq_err aq_err) 6198 { 6199 switch (aq_err) { 6200 case ICE_AQ_RC_OK: 6201 return "OK"; 6202 case ICE_AQ_RC_EPERM: 6203 return "ICE_AQ_RC_EPERM"; 6204 case ICE_AQ_RC_ENOENT: 6205 return "ICE_AQ_RC_ENOENT"; 6206 case ICE_AQ_RC_ENOMEM: 6207 return "ICE_AQ_RC_ENOMEM"; 6208 case ICE_AQ_RC_EBUSY: 6209 return "ICE_AQ_RC_EBUSY"; 6210 case ICE_AQ_RC_EEXIST: 6211 return "ICE_AQ_RC_EEXIST"; 6212 case ICE_AQ_RC_EINVAL: 6213 return "ICE_AQ_RC_EINVAL"; 6214 case ICE_AQ_RC_ENOSPC: 6215 return "ICE_AQ_RC_ENOSPC"; 6216 case ICE_AQ_RC_ENOSYS: 6217 return "ICE_AQ_RC_ENOSYS"; 6218 case ICE_AQ_RC_EMODE: 6219 return "ICE_AQ_RC_EMODE"; 6220 case ICE_AQ_RC_ENOSEC: 6221 return "ICE_AQ_RC_ENOSEC"; 6222 case ICE_AQ_RC_EBADSIG: 6223 return "ICE_AQ_RC_EBADSIG"; 6224 case ICE_AQ_RC_ESVN: 6225 return "ICE_AQ_RC_ESVN"; 6226 case ICE_AQ_RC_EBADMAN: 6227 return "ICE_AQ_RC_EBADMAN"; 6228 case ICE_AQ_RC_EBADBUF: 6229 return "ICE_AQ_RC_EBADBUF"; 6230 } 6231 6232 return "ICE_AQ_RC_UNKNOWN"; 6233 } 6234 6235 /** 6236 * ice_stat_str - convert status err code to a string 6237 * @stat_err: the status error code to convert 6238 */ 6239 const char *ice_stat_str(enum ice_status stat_err) 6240 { 6241 switch (stat_err) { 6242 case ICE_SUCCESS: 6243 return "OK"; 6244 case ICE_ERR_PARAM: 6245 return "ICE_ERR_PARAM"; 6246 case ICE_ERR_NOT_IMPL: 6247 return "ICE_ERR_NOT_IMPL"; 6248 case ICE_ERR_NOT_READY: 6249 return "ICE_ERR_NOT_READY"; 6250 case ICE_ERR_NOT_SUPPORTED: 6251 return "ICE_ERR_NOT_SUPPORTED"; 6252 case ICE_ERR_BAD_PTR: 6253 return "ICE_ERR_BAD_PTR"; 6254 case ICE_ERR_INVAL_SIZE: 6255 return "ICE_ERR_INVAL_SIZE"; 6256 case ICE_ERR_DEVICE_NOT_SUPPORTED: 6257 return "ICE_ERR_DEVICE_NOT_SUPPORTED"; 6258 case ICE_ERR_RESET_FAILED: 6259 return "ICE_ERR_RESET_FAILED"; 6260 case ICE_ERR_FW_API_VER: 6261 return "ICE_ERR_FW_API_VER"; 6262 case ICE_ERR_NO_MEMORY: 6263 return "ICE_ERR_NO_MEMORY"; 6264 case ICE_ERR_CFG: 6265 return "ICE_ERR_CFG"; 6266 case ICE_ERR_OUT_OF_RANGE: 6267 return "ICE_ERR_OUT_OF_RANGE"; 6268 case ICE_ERR_ALREADY_EXISTS: 6269 return "ICE_ERR_ALREADY_EXISTS"; 6270 case ICE_ERR_NVM: 6271 return "ICE_ERR_NVM"; 6272 case ICE_ERR_NVM_CHECKSUM: 6273 return "ICE_ERR_NVM_CHECKSUM"; 6274 case ICE_ERR_BUF_TOO_SHORT: 6275 return "ICE_ERR_BUF_TOO_SHORT"; 6276 case ICE_ERR_NVM_BLANK_MODE: 6277 return "ICE_ERR_NVM_BLANK_MODE"; 6278 case ICE_ERR_IN_USE: 6279 return "ICE_ERR_IN_USE"; 6280 case ICE_ERR_MAX_LIMIT: 6281 return "ICE_ERR_MAX_LIMIT"; 6282 case ICE_ERR_RESET_ONGOING: 6283 return "ICE_ERR_RESET_ONGOING"; 6284 case ICE_ERR_HW_TABLE: 6285 return "ICE_ERR_HW_TABLE"; 6286 case ICE_ERR_DOES_NOT_EXIST: 6287 return "ICE_ERR_DOES_NOT_EXIST"; 6288 case ICE_ERR_FW_DDP_MISMATCH: 6289 return "ICE_ERR_FW_DDP_MISMATCH"; 6290 case ICE_ERR_AQ_ERROR: 6291 return "ICE_ERR_AQ_ERROR"; 6292 case ICE_ERR_AQ_TIMEOUT: 6293 return "ICE_ERR_AQ_TIMEOUT"; 6294 case ICE_ERR_AQ_FULL: 6295 return "ICE_ERR_AQ_FULL"; 6296 case ICE_ERR_AQ_NO_WORK: 6297 return "ICE_ERR_AQ_NO_WORK"; 6298 case ICE_ERR_AQ_EMPTY: 6299 return "ICE_ERR_AQ_EMPTY"; 6300 case ICE_ERR_AQ_FW_CRITICAL: 6301 return "ICE_ERR_AQ_FW_CRITICAL"; 6302 } 6303 6304 return "ICE_ERR_UNKNOWN"; 6305 } 6306 6307 /** 6308 * ice_set_rss - Set RSS keys and lut 6309 * @vsi: Pointer to VSI structure 6310 * @seed: RSS hash seed 6311 * @lut: Lookup table 6312 * @lut_size: Lookup table size 6313 * 6314 * Returns 0 on success, negative on failure 6315 */ 6316 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) 6317 { 6318 struct ice_pf *pf = vsi->back; 6319 struct ice_hw *hw = &pf->hw; 6320 enum ice_status status; 6321 struct device *dev; 6322 6323 dev = ice_pf_to_dev(pf); 6324 if (seed) { 6325 struct ice_aqc_get_set_rss_keys *buf = 6326 (struct ice_aqc_get_set_rss_keys *)seed; 6327 6328 status = ice_aq_set_rss_key(hw, vsi->idx, buf); 6329 6330 if (status) { 6331 dev_err(dev, "Cannot set RSS key, err %s aq_err %s\n", 6332 ice_stat_str(status), 6333 ice_aq_str(hw->adminq.sq_last_status)); 6334 return -EIO; 6335 } 6336 } 6337 6338 if (lut) { 6339 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type, 6340 lut, lut_size); 6341 if (status) { 6342 dev_err(dev, "Cannot set RSS lut, err %s aq_err %s\n", 6343 ice_stat_str(status), 6344 ice_aq_str(hw->adminq.sq_last_status)); 6345 return -EIO; 6346 } 6347 } 6348 6349 return 0; 6350 } 6351 6352 /** 6353 * ice_get_rss - Get RSS keys and lut 6354 * @vsi: Pointer to VSI structure 6355 * @seed: Buffer to store the keys 6356 * @lut: Buffer to store the lookup table entries 6357 * @lut_size: Size of buffer to store the lookup table entries 6358 * 6359 * Returns 0 on success, negative on failure 6360 */ 6361 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size) 6362 { 6363 struct ice_pf *pf = vsi->back; 6364 struct ice_hw *hw = &pf->hw; 6365 enum ice_status status; 6366 struct device *dev; 6367 6368 dev = ice_pf_to_dev(pf); 6369 if (seed) { 6370 struct ice_aqc_get_set_rss_keys *buf = 6371 (struct ice_aqc_get_set_rss_keys *)seed; 6372 6373 status = ice_aq_get_rss_key(hw, vsi->idx, buf); 6374 if (status) { 6375 dev_err(dev, "Cannot get RSS key, err %s aq_err %s\n", 6376 ice_stat_str(status), 6377 ice_aq_str(hw->adminq.sq_last_status)); 6378 return -EIO; 6379 } 6380 } 6381 6382 if (lut) { 6383 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type, 6384 lut, lut_size); 6385 if (status) { 6386 dev_err(dev, "Cannot get RSS lut, err %s aq_err %s\n", 6387 ice_stat_str(status), 6388 ice_aq_str(hw->adminq.sq_last_status)); 6389 return -EIO; 6390 } 6391 } 6392 6393 return 0; 6394 } 6395 6396 /** 6397 * ice_bridge_getlink - Get the hardware bridge mode 6398 * @skb: skb buff 6399 * @pid: process ID 6400 * @seq: RTNL message seq 6401 * @dev: the netdev being configured 6402 * @filter_mask: filter mask passed in 6403 * @nlflags: netlink flags passed in 6404 * 6405 * Return the bridge mode (VEB/VEPA) 6406 */ 6407 static int 6408 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 6409 struct net_device *dev, u32 filter_mask, int nlflags) 6410 { 6411 struct ice_netdev_priv *np = netdev_priv(dev); 6412 struct ice_vsi *vsi = np->vsi; 6413 struct ice_pf *pf = vsi->back; 6414 u16 bmode; 6415 6416 bmode = pf->first_sw->bridge_mode; 6417 6418 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags, 6419 filter_mask, NULL); 6420 } 6421 6422 /** 6423 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA) 6424 * @vsi: Pointer to VSI structure 6425 * @bmode: Hardware bridge mode (VEB/VEPA) 6426 * 6427 * Returns 0 on success, negative on failure 6428 */ 6429 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode) 6430 { 6431 struct ice_aqc_vsi_props *vsi_props; 6432 struct ice_hw *hw = &vsi->back->hw; 6433 struct ice_vsi_ctx *ctxt; 6434 enum ice_status status; 6435 int ret = 0; 6436 6437 vsi_props = &vsi->info; 6438 6439 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL); 6440 if (!ctxt) 6441 return -ENOMEM; 6442 6443 ctxt->info = vsi->info; 6444 6445 if (bmode == BRIDGE_MODE_VEB) 6446 /* change from VEPA to VEB mode */ 6447 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB; 6448 else 6449 /* change from VEB to VEPA mode */ 6450 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB; 6451 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID); 6452 6453 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL); 6454 if (status) { 6455 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %s aq_err %s\n", 6456 bmode, ice_stat_str(status), 6457 ice_aq_str(hw->adminq.sq_last_status)); 6458 ret = -EIO; 6459 goto out; 6460 } 6461 /* Update sw flags for book keeping */ 6462 vsi_props->sw_flags = ctxt->info.sw_flags; 6463 6464 out: 6465 kfree(ctxt); 6466 return ret; 6467 } 6468 6469 /** 6470 * ice_bridge_setlink - Set the hardware bridge mode 6471 * @dev: the netdev being configured 6472 * @nlh: RTNL message 6473 * @flags: bridge setlink flags 6474 * @extack: netlink extended ack 6475 * 6476 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is 6477 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if 6478 * not already set for all VSIs connected to this switch. And also update the 6479 * unicast switch filter rules for the corresponding switch of the netdev. 6480 */ 6481 static int 6482 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, 6483 u16 __always_unused flags, 6484 struct netlink_ext_ack __always_unused *extack) 6485 { 6486 struct ice_netdev_priv *np = netdev_priv(dev); 6487 struct ice_pf *pf = np->vsi->back; 6488 struct nlattr *attr, *br_spec; 6489 struct ice_hw *hw = &pf->hw; 6490 enum ice_status status; 6491 struct ice_sw *pf_sw; 6492 int rem, v, err = 0; 6493 6494 pf_sw = pf->first_sw; 6495 /* find the attribute in the netlink message */ 6496 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 6497 6498 nla_for_each_nested(attr, br_spec, rem) { 6499 __u16 mode; 6500 6501 if (nla_type(attr) != IFLA_BRIDGE_MODE) 6502 continue; 6503 mode = nla_get_u16(attr); 6504 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) 6505 return -EINVAL; 6506 /* Continue if bridge mode is not being flipped */ 6507 if (mode == pf_sw->bridge_mode) 6508 continue; 6509 /* Iterates through the PF VSI list and update the loopback 6510 * mode of the VSI 6511 */ 6512 ice_for_each_vsi(pf, v) { 6513 if (!pf->vsi[v]) 6514 continue; 6515 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode); 6516 if (err) 6517 return err; 6518 } 6519 6520 hw->evb_veb = (mode == BRIDGE_MODE_VEB); 6521 /* Update the unicast switch filter rules for the corresponding 6522 * switch of the netdev 6523 */ 6524 status = ice_update_sw_rule_bridge_mode(hw); 6525 if (status) { 6526 netdev_err(dev, "switch rule update failed, mode = %d err %s aq_err %s\n", 6527 mode, ice_stat_str(status), 6528 ice_aq_str(hw->adminq.sq_last_status)); 6529 /* revert hw->evb_veb */ 6530 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB); 6531 return -EIO; 6532 } 6533 6534 pf_sw->bridge_mode = mode; 6535 } 6536 6537 return 0; 6538 } 6539 6540 /** 6541 * ice_tx_timeout - Respond to a Tx Hang 6542 * @netdev: network interface device structure 6543 * @txqueue: Tx queue 6544 */ 6545 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue) 6546 { 6547 struct ice_netdev_priv *np = netdev_priv(netdev); 6548 struct ice_ring *tx_ring = NULL; 6549 struct ice_vsi *vsi = np->vsi; 6550 struct ice_pf *pf = vsi->back; 6551 u32 i; 6552 6553 pf->tx_timeout_count++; 6554 6555 /* Check if PFC is enabled for the TC to which the queue belongs 6556 * to. If yes then Tx timeout is not caused by a hung queue, no 6557 * need to reset and rebuild 6558 */ 6559 if (ice_is_pfc_causing_hung_q(pf, txqueue)) { 6560 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n", 6561 txqueue); 6562 return; 6563 } 6564 6565 /* now that we have an index, find the tx_ring struct */ 6566 for (i = 0; i < vsi->num_txq; i++) 6567 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) 6568 if (txqueue == vsi->tx_rings[i]->q_index) { 6569 tx_ring = vsi->tx_rings[i]; 6570 break; 6571 } 6572 6573 /* Reset recovery level if enough time has elapsed after last timeout. 6574 * Also ensure no new reset action happens before next timeout period. 6575 */ 6576 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20))) 6577 pf->tx_timeout_recovery_level = 1; 6578 else if (time_before(jiffies, (pf->tx_timeout_last_recovery + 6579 netdev->watchdog_timeo))) 6580 return; 6581 6582 if (tx_ring) { 6583 struct ice_hw *hw = &pf->hw; 6584 u32 head, val = 0; 6585 6586 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) & 6587 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S; 6588 /* Read interrupt register */ 6589 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx)); 6590 6591 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n", 6592 vsi->vsi_num, txqueue, tx_ring->next_to_clean, 6593 head, tx_ring->next_to_use, val); 6594 } 6595 6596 pf->tx_timeout_last_recovery = jiffies; 6597 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n", 6598 pf->tx_timeout_recovery_level, txqueue); 6599 6600 switch (pf->tx_timeout_recovery_level) { 6601 case 1: 6602 set_bit(__ICE_PFR_REQ, pf->state); 6603 break; 6604 case 2: 6605 set_bit(__ICE_CORER_REQ, pf->state); 6606 break; 6607 case 3: 6608 set_bit(__ICE_GLOBR_REQ, pf->state); 6609 break; 6610 default: 6611 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n"); 6612 set_bit(__ICE_DOWN, pf->state); 6613 set_bit(__ICE_NEEDS_RESTART, vsi->state); 6614 set_bit(__ICE_SERVICE_DIS, pf->state); 6615 break; 6616 } 6617 6618 ice_service_task_schedule(pf); 6619 pf->tx_timeout_recovery_level++; 6620 } 6621 6622 /** 6623 * ice_open - Called when a network interface becomes active 6624 * @netdev: network interface device structure 6625 * 6626 * The open entry point is called when a network interface is made 6627 * active by the system (IFF_UP). At this point all resources needed 6628 * for transmit and receive operations are allocated, the interrupt 6629 * handler is registered with the OS, the netdev watchdog is enabled, 6630 * and the stack is notified that the interface is ready. 6631 * 6632 * Returns 0 on success, negative value on failure 6633 */ 6634 int ice_open(struct net_device *netdev) 6635 { 6636 struct ice_netdev_priv *np = netdev_priv(netdev); 6637 struct ice_pf *pf = np->vsi->back; 6638 6639 if (ice_is_reset_in_progress(pf->state)) { 6640 netdev_err(netdev, "can't open net device while reset is in progress"); 6641 return -EBUSY; 6642 } 6643 6644 return ice_open_internal(netdev); 6645 } 6646 6647 /** 6648 * ice_open_internal - Called when a network interface becomes active 6649 * @netdev: network interface device structure 6650 * 6651 * Internal ice_open implementation. Should not be used directly except for ice_open and reset 6652 * handling routine 6653 * 6654 * Returns 0 on success, negative value on failure 6655 */ 6656 int ice_open_internal(struct net_device *netdev) 6657 { 6658 struct ice_netdev_priv *np = netdev_priv(netdev); 6659 struct ice_vsi *vsi = np->vsi; 6660 struct ice_pf *pf = vsi->back; 6661 struct ice_port_info *pi; 6662 int err; 6663 6664 if (test_bit(__ICE_NEEDS_RESTART, pf->state)) { 6665 netdev_err(netdev, "driver needs to be unloaded and reloaded\n"); 6666 return -EIO; 6667 } 6668 6669 if (test_bit(__ICE_DOWN, pf->state)) { 6670 netdev_err(netdev, "device is not ready yet\n"); 6671 return -EBUSY; 6672 } 6673 6674 netif_carrier_off(netdev); 6675 6676 pi = vsi->port_info; 6677 err = ice_update_link_info(pi); 6678 if (err) { 6679 netdev_err(netdev, "Failed to get link info, error %d\n", 6680 err); 6681 return err; 6682 } 6683 6684 /* Set PHY if there is media, otherwise, turn off PHY */ 6685 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { 6686 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags); 6687 if (!test_bit(__ICE_PHY_INIT_COMPLETE, pf->state)) { 6688 err = ice_init_phy_user_cfg(pi); 6689 if (err) { 6690 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n", 6691 err); 6692 return err; 6693 } 6694 } 6695 6696 err = ice_configure_phy(vsi); 6697 if (err) { 6698 netdev_err(netdev, "Failed to set physical link up, error %d\n", 6699 err); 6700 return err; 6701 } 6702 } else { 6703 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 6704 err = ice_aq_set_link_restart_an(pi, false, NULL); 6705 if (err) { 6706 netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n", 6707 vsi->vsi_num, err); 6708 return err; 6709 } 6710 } 6711 6712 err = ice_vsi_open(vsi); 6713 if (err) 6714 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n", 6715 vsi->vsi_num, vsi->vsw->sw_id); 6716 6717 /* Update existing tunnels information */ 6718 udp_tunnel_get_rx_info(netdev); 6719 6720 return err; 6721 } 6722 6723 /** 6724 * ice_stop - Disables a network interface 6725 * @netdev: network interface device structure 6726 * 6727 * The stop entry point is called when an interface is de-activated by the OS, 6728 * and the netdevice enters the DOWN state. The hardware is still under the 6729 * driver's control, but the netdev interface is disabled. 6730 * 6731 * Returns success only - not allowed to fail 6732 */ 6733 int ice_stop(struct net_device *netdev) 6734 { 6735 struct ice_netdev_priv *np = netdev_priv(netdev); 6736 struct ice_vsi *vsi = np->vsi; 6737 struct ice_pf *pf = vsi->back; 6738 6739 if (ice_is_reset_in_progress(pf->state)) { 6740 netdev_err(netdev, "can't stop net device while reset is in progress"); 6741 return -EBUSY; 6742 } 6743 6744 ice_vsi_close(vsi); 6745 6746 return 0; 6747 } 6748 6749 /** 6750 * ice_features_check - Validate encapsulated packet conforms to limits 6751 * @skb: skb buffer 6752 * @netdev: This port's netdev 6753 * @features: Offload features that the stack believes apply 6754 */ 6755 static netdev_features_t 6756 ice_features_check(struct sk_buff *skb, 6757 struct net_device __always_unused *netdev, 6758 netdev_features_t features) 6759 { 6760 size_t len; 6761 6762 /* No point in doing any of this if neither checksum nor GSO are 6763 * being requested for this frame. We can rule out both by just 6764 * checking for CHECKSUM_PARTIAL 6765 */ 6766 if (skb->ip_summed != CHECKSUM_PARTIAL) 6767 return features; 6768 6769 /* We cannot support GSO if the MSS is going to be less than 6770 * 64 bytes. If it is then we need to drop support for GSO. 6771 */ 6772 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64)) 6773 features &= ~NETIF_F_GSO_MASK; 6774 6775 len = skb_network_header(skb) - skb->data; 6776 if (len > ICE_TXD_MACLEN_MAX || len & 0x1) 6777 goto out_rm_features; 6778 6779 len = skb_transport_header(skb) - skb_network_header(skb); 6780 if (len > ICE_TXD_IPLEN_MAX || len & 0x1) 6781 goto out_rm_features; 6782 6783 if (skb->encapsulation) { 6784 len = skb_inner_network_header(skb) - skb_transport_header(skb); 6785 if (len > ICE_TXD_L4LEN_MAX || len & 0x1) 6786 goto out_rm_features; 6787 6788 len = skb_inner_transport_header(skb) - 6789 skb_inner_network_header(skb); 6790 if (len > ICE_TXD_IPLEN_MAX || len & 0x1) 6791 goto out_rm_features; 6792 } 6793 6794 return features; 6795 out_rm_features: 6796 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); 6797 } 6798 6799 static const struct net_device_ops ice_netdev_safe_mode_ops = { 6800 .ndo_open = ice_open, 6801 .ndo_stop = ice_stop, 6802 .ndo_start_xmit = ice_start_xmit, 6803 .ndo_set_mac_address = ice_set_mac_address, 6804 .ndo_validate_addr = eth_validate_addr, 6805 .ndo_change_mtu = ice_change_mtu, 6806 .ndo_get_stats64 = ice_get_stats64, 6807 .ndo_tx_timeout = ice_tx_timeout, 6808 }; 6809 6810 static const struct net_device_ops ice_netdev_ops = { 6811 .ndo_open = ice_open, 6812 .ndo_stop = ice_stop, 6813 .ndo_start_xmit = ice_start_xmit, 6814 .ndo_features_check = ice_features_check, 6815 .ndo_set_rx_mode = ice_set_rx_mode, 6816 .ndo_set_mac_address = ice_set_mac_address, 6817 .ndo_validate_addr = eth_validate_addr, 6818 .ndo_change_mtu = ice_change_mtu, 6819 .ndo_get_stats64 = ice_get_stats64, 6820 .ndo_set_tx_maxrate = ice_set_tx_maxrate, 6821 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk, 6822 .ndo_set_vf_mac = ice_set_vf_mac, 6823 .ndo_get_vf_config = ice_get_vf_cfg, 6824 .ndo_set_vf_trust = ice_set_vf_trust, 6825 .ndo_set_vf_vlan = ice_set_vf_port_vlan, 6826 .ndo_set_vf_link_state = ice_set_vf_link_state, 6827 .ndo_get_vf_stats = ice_get_vf_stats, 6828 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid, 6829 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid, 6830 .ndo_set_features = ice_set_features, 6831 .ndo_bridge_getlink = ice_bridge_getlink, 6832 .ndo_bridge_setlink = ice_bridge_setlink, 6833 .ndo_fdb_add = ice_fdb_add, 6834 .ndo_fdb_del = ice_fdb_del, 6835 #ifdef CONFIG_RFS_ACCEL 6836 .ndo_rx_flow_steer = ice_rx_flow_steer, 6837 #endif 6838 .ndo_tx_timeout = ice_tx_timeout, 6839 .ndo_bpf = ice_xdp, 6840 .ndo_xdp_xmit = ice_xdp_xmit, 6841 .ndo_xsk_wakeup = ice_xsk_wakeup, 6842 }; 6843