1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2018-2023, 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 <linux/crash_dump.h> 10 #include "ice.h" 11 #include "ice_base.h" 12 #include "ice_lib.h" 13 #include "ice_fltr.h" 14 #include "ice_dcb_lib.h" 15 #include "ice_dcb_nl.h" 16 #include "devlink/devlink.h" 17 #include "devlink/port.h" 18 #include "ice_sf_eth.h" 19 #include "ice_hwmon.h" 20 /* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the 21 * ice tracepoint functions. This must be done exactly once across the 22 * ice driver. 23 */ 24 #define CREATE_TRACE_POINTS 25 #include "ice_trace.h" 26 #include "ice_eswitch.h" 27 #include "ice_tc_lib.h" 28 #include "ice_vsi_vlan_ops.h" 29 #include <net/xdp_sock_drv.h> 30 31 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver" 32 static const char ice_driver_string[] = DRV_SUMMARY; 33 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation."; 34 35 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */ 36 #define ICE_DDP_PKG_PATH "intel/ice/ddp/" 37 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg" 38 39 MODULE_DESCRIPTION(DRV_SUMMARY); 40 MODULE_IMPORT_NS("LIBIE"); 41 MODULE_LICENSE("GPL v2"); 42 MODULE_FIRMWARE(ICE_DDP_PKG_FILE); 43 44 static int debug = -1; 45 module_param(debug, int, 0644); 46 #ifndef CONFIG_DYNAMIC_DEBUG 47 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)"); 48 #else 49 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)"); 50 #endif /* !CONFIG_DYNAMIC_DEBUG */ 51 52 DEFINE_STATIC_KEY_FALSE(ice_xdp_locking_key); 53 EXPORT_SYMBOL(ice_xdp_locking_key); 54 55 /** 56 * ice_hw_to_dev - Get device pointer from the hardware structure 57 * @hw: pointer to the device HW structure 58 * 59 * Used to access the device pointer from compilation units which can't easily 60 * include the definition of struct ice_pf without leading to circular header 61 * dependencies. 62 */ 63 struct device *ice_hw_to_dev(struct ice_hw *hw) 64 { 65 struct ice_pf *pf = container_of(hw, struct ice_pf, hw); 66 67 return &pf->pdev->dev; 68 } 69 70 static struct workqueue_struct *ice_wq; 71 struct workqueue_struct *ice_lag_wq; 72 static const struct net_device_ops ice_netdev_safe_mode_ops; 73 static const struct net_device_ops ice_netdev_ops; 74 75 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type); 76 77 static void ice_vsi_release_all(struct ice_pf *pf); 78 79 static int ice_rebuild_channels(struct ice_pf *pf); 80 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_adv_fltr); 81 82 static int 83 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, 84 void *cb_priv, enum tc_setup_type type, void *type_data, 85 void *data, 86 void (*cleanup)(struct flow_block_cb *block_cb)); 87 88 bool netif_is_ice(const struct net_device *dev) 89 { 90 return dev && (dev->netdev_ops == &ice_netdev_ops || 91 dev->netdev_ops == &ice_netdev_safe_mode_ops); 92 } 93 94 /** 95 * ice_get_tx_pending - returns number of Tx descriptors not processed 96 * @ring: the ring of descriptors 97 */ 98 static u16 ice_get_tx_pending(struct ice_tx_ring *ring) 99 { 100 u16 head, tail; 101 102 head = ring->next_to_clean; 103 tail = ring->next_to_use; 104 105 if (head != tail) 106 return (head < tail) ? 107 tail - head : (tail + ring->count - head); 108 return 0; 109 } 110 111 /** 112 * ice_check_for_hang_subtask - check for and recover hung queues 113 * @pf: pointer to PF struct 114 */ 115 static void ice_check_for_hang_subtask(struct ice_pf *pf) 116 { 117 struct ice_vsi *vsi = NULL; 118 struct ice_hw *hw; 119 unsigned int i; 120 int packets; 121 u32 v; 122 123 ice_for_each_vsi(pf, v) 124 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) { 125 vsi = pf->vsi[v]; 126 break; 127 } 128 129 if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state)) 130 return; 131 132 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev))) 133 return; 134 135 hw = &vsi->back->hw; 136 137 ice_for_each_txq(vsi, i) { 138 struct ice_tx_ring *tx_ring = vsi->tx_rings[i]; 139 struct ice_ring_stats *ring_stats; 140 141 if (!tx_ring) 142 continue; 143 if (ice_ring_ch_enabled(tx_ring)) 144 continue; 145 146 ring_stats = tx_ring->ring_stats; 147 if (!ring_stats) 148 continue; 149 150 if (tx_ring->desc) { 151 /* If packet counter has not changed the queue is 152 * likely stalled, so force an interrupt for this 153 * queue. 154 * 155 * prev_pkt would be negative if there was no 156 * pending work. 157 */ 158 packets = ring_stats->stats.pkts & INT_MAX; 159 if (ring_stats->tx_stats.prev_pkt == packets) { 160 /* Trigger sw interrupt to revive the queue */ 161 ice_trigger_sw_intr(hw, tx_ring->q_vector); 162 continue; 163 } 164 165 /* Memory barrier between read of packet count and call 166 * to ice_get_tx_pending() 167 */ 168 smp_rmb(); 169 ring_stats->tx_stats.prev_pkt = 170 ice_get_tx_pending(tx_ring) ? packets : -1; 171 } 172 } 173 } 174 175 /** 176 * ice_init_mac_fltr - Set initial MAC filters 177 * @pf: board private structure 178 * 179 * Set initial set of MAC filters for PF VSI; configure filters for permanent 180 * address and broadcast address. If an error is encountered, netdevice will be 181 * unregistered. 182 */ 183 static int ice_init_mac_fltr(struct ice_pf *pf) 184 { 185 struct ice_vsi *vsi; 186 u8 *perm_addr; 187 188 vsi = ice_get_main_vsi(pf); 189 if (!vsi) 190 return -EINVAL; 191 192 perm_addr = vsi->port_info->mac.perm_addr; 193 return ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI); 194 } 195 196 /** 197 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced 198 * @netdev: the net device on which the sync is happening 199 * @addr: MAC address to sync 200 * 201 * This is a callback function which is called by the in kernel device sync 202 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only 203 * populates the tmp_sync_list, which is later used by ice_add_mac to add the 204 * MAC filters from the hardware. 205 */ 206 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr) 207 { 208 struct ice_netdev_priv *np = netdev_priv(netdev); 209 struct ice_vsi *vsi = np->vsi; 210 211 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr, 212 ICE_FWD_TO_VSI)) 213 return -EINVAL; 214 215 return 0; 216 } 217 218 /** 219 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced 220 * @netdev: the net device on which the unsync is happening 221 * @addr: MAC address to unsync 222 * 223 * This is a callback function which is called by the in kernel device unsync 224 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only 225 * populates the tmp_unsync_list, which is later used by ice_remove_mac to 226 * delete the MAC filters from the hardware. 227 */ 228 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr) 229 { 230 struct ice_netdev_priv *np = netdev_priv(netdev); 231 struct ice_vsi *vsi = np->vsi; 232 233 /* Under some circumstances, we might receive a request to delete our 234 * own device address from our uc list. Because we store the device 235 * address in the VSI's MAC filter list, we need to ignore such 236 * requests and not delete our device address from this list. 237 */ 238 if (ether_addr_equal(addr, netdev->dev_addr)) 239 return 0; 240 241 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr, 242 ICE_FWD_TO_VSI)) 243 return -EINVAL; 244 245 return 0; 246 } 247 248 /** 249 * ice_vsi_fltr_changed - check if filter state changed 250 * @vsi: VSI to be checked 251 * 252 * returns true if filter state has changed, false otherwise. 253 */ 254 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi) 255 { 256 return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) || 257 test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); 258 } 259 260 /** 261 * ice_set_promisc - Enable promiscuous mode for a given PF 262 * @vsi: the VSI being configured 263 * @promisc_m: mask of promiscuous config bits 264 * 265 */ 266 static int ice_set_promisc(struct ice_vsi *vsi, u8 promisc_m) 267 { 268 int status; 269 270 if (vsi->type != ICE_VSI_PF) 271 return 0; 272 273 if (ice_vsi_has_non_zero_vlans(vsi)) { 274 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX); 275 status = ice_fltr_set_vlan_vsi_promisc(&vsi->back->hw, vsi, 276 promisc_m); 277 } else { 278 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, 279 promisc_m, 0); 280 } 281 if (status && status != -EEXIST) 282 return status; 283 284 netdev_dbg(vsi->netdev, "set promisc filter bits for VSI %i: 0x%x\n", 285 vsi->vsi_num, promisc_m); 286 return 0; 287 } 288 289 /** 290 * ice_clear_promisc - Disable promiscuous mode for a given PF 291 * @vsi: the VSI being configured 292 * @promisc_m: mask of promiscuous config bits 293 * 294 */ 295 static int ice_clear_promisc(struct ice_vsi *vsi, u8 promisc_m) 296 { 297 int status; 298 299 if (vsi->type != ICE_VSI_PF) 300 return 0; 301 302 if (ice_vsi_has_non_zero_vlans(vsi)) { 303 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX); 304 status = ice_fltr_clear_vlan_vsi_promisc(&vsi->back->hw, vsi, 305 promisc_m); 306 } else { 307 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, 308 promisc_m, 0); 309 } 310 311 netdev_dbg(vsi->netdev, "clear promisc filter bits for VSI %i: 0x%x\n", 312 vsi->vsi_num, promisc_m); 313 return status; 314 } 315 316 /** 317 * ice_vsi_sync_fltr - Update the VSI filter list to the HW 318 * @vsi: ptr to the VSI 319 * 320 * Push any outstanding VSI filter changes through the AdminQ. 321 */ 322 static int ice_vsi_sync_fltr(struct ice_vsi *vsi) 323 { 324 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 325 struct device *dev = ice_pf_to_dev(vsi->back); 326 struct net_device *netdev = vsi->netdev; 327 bool promisc_forced_on = false; 328 struct ice_pf *pf = vsi->back; 329 struct ice_hw *hw = &pf->hw; 330 u32 changed_flags = 0; 331 int err; 332 333 if (!vsi->netdev) 334 return -EINVAL; 335 336 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state)) 337 usleep_range(1000, 2000); 338 339 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; 340 vsi->current_netdev_flags = vsi->netdev->flags; 341 342 INIT_LIST_HEAD(&vsi->tmp_sync_list); 343 INIT_LIST_HEAD(&vsi->tmp_unsync_list); 344 345 if (ice_vsi_fltr_changed(vsi)) { 346 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state); 347 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); 348 349 /* grab the netdev's addr_list_lock */ 350 netif_addr_lock_bh(netdev); 351 __dev_uc_sync(netdev, ice_add_mac_to_sync_list, 352 ice_add_mac_to_unsync_list); 353 __dev_mc_sync(netdev, ice_add_mac_to_sync_list, 354 ice_add_mac_to_unsync_list); 355 /* our temp lists are populated. release lock */ 356 netif_addr_unlock_bh(netdev); 357 } 358 359 /* Remove MAC addresses in the unsync list */ 360 err = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list); 361 ice_fltr_free_list(dev, &vsi->tmp_unsync_list); 362 if (err) { 363 netdev_err(netdev, "Failed to delete MAC filters\n"); 364 /* if we failed because of alloc failures, just bail */ 365 if (err == -ENOMEM) 366 goto out; 367 } 368 369 /* Add MAC addresses in the sync list */ 370 err = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list); 371 ice_fltr_free_list(dev, &vsi->tmp_sync_list); 372 /* If filter is added successfully or already exists, do not go into 373 * 'if' condition and report it as error. Instead continue processing 374 * rest of the function. 375 */ 376 if (err && err != -EEXIST) { 377 netdev_err(netdev, "Failed to add MAC filters\n"); 378 /* If there is no more space for new umac filters, VSI 379 * should go into promiscuous mode. There should be some 380 * space reserved for promiscuous filters. 381 */ 382 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC && 383 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC, 384 vsi->state)) { 385 promisc_forced_on = true; 386 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n", 387 vsi->vsi_num); 388 } else { 389 goto out; 390 } 391 } 392 err = 0; 393 /* check for changes in promiscuous modes */ 394 if (changed_flags & IFF_ALLMULTI) { 395 if (vsi->current_netdev_flags & IFF_ALLMULTI) { 396 err = ice_set_promisc(vsi, ICE_MCAST_PROMISC_BITS); 397 if (err) { 398 vsi->current_netdev_flags &= ~IFF_ALLMULTI; 399 goto out_promisc; 400 } 401 } else { 402 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */ 403 err = ice_clear_promisc(vsi, ICE_MCAST_PROMISC_BITS); 404 if (err) { 405 vsi->current_netdev_flags |= IFF_ALLMULTI; 406 goto out_promisc; 407 } 408 } 409 } 410 411 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) || 412 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) { 413 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state); 414 if (vsi->current_netdev_flags & IFF_PROMISC) { 415 /* Apply Rx filter rule to get traffic from wire */ 416 if (!ice_is_dflt_vsi_in_use(vsi->port_info)) { 417 err = ice_set_dflt_vsi(vsi); 418 if (err && err != -EEXIST) { 419 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n", 420 err, vsi->vsi_num); 421 vsi->current_netdev_flags &= 422 ~IFF_PROMISC; 423 goto out_promisc; 424 } 425 err = 0; 426 vlan_ops->dis_rx_filtering(vsi); 427 428 /* promiscuous mode implies allmulticast so 429 * that VSIs that are in promiscuous mode are 430 * subscribed to multicast packets coming to 431 * the port 432 */ 433 err = ice_set_promisc(vsi, 434 ICE_MCAST_PROMISC_BITS); 435 if (err) 436 goto out_promisc; 437 } 438 } else { 439 /* Clear Rx filter to remove traffic from wire */ 440 if (ice_is_vsi_dflt_vsi(vsi)) { 441 err = ice_clear_dflt_vsi(vsi); 442 if (err) { 443 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n", 444 err, vsi->vsi_num); 445 vsi->current_netdev_flags |= 446 IFF_PROMISC; 447 goto out_promisc; 448 } 449 if (vsi->netdev->features & 450 NETIF_F_HW_VLAN_CTAG_FILTER) 451 vlan_ops->ena_rx_filtering(vsi); 452 } 453 454 /* disable allmulti here, but only if allmulti is not 455 * still enabled for the netdev 456 */ 457 if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) { 458 err = ice_clear_promisc(vsi, 459 ICE_MCAST_PROMISC_BITS); 460 if (err) { 461 netdev_err(netdev, "Error %d clearing multicast promiscuous on VSI %i\n", 462 err, vsi->vsi_num); 463 } 464 } 465 } 466 } 467 goto exit; 468 469 out_promisc: 470 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state); 471 goto exit; 472 out: 473 /* if something went wrong then set the changed flag so we try again */ 474 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state); 475 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); 476 exit: 477 clear_bit(ICE_CFG_BUSY, vsi->state); 478 return err; 479 } 480 481 /** 482 * ice_sync_fltr_subtask - Sync the VSI filter list with HW 483 * @pf: board private structure 484 */ 485 static void ice_sync_fltr_subtask(struct ice_pf *pf) 486 { 487 int v; 488 489 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags))) 490 return; 491 492 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags); 493 494 ice_for_each_vsi(pf, v) 495 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) && 496 ice_vsi_sync_fltr(pf->vsi[v])) { 497 /* come back and try again later */ 498 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags); 499 break; 500 } 501 } 502 503 /** 504 * ice_pf_dis_all_vsi - Pause all VSIs on a PF 505 * @pf: the PF 506 * @locked: is the rtnl_lock already held 507 */ 508 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked) 509 { 510 int node; 511 int v; 512 513 ice_for_each_vsi(pf, v) 514 if (pf->vsi[v]) 515 ice_dis_vsi(pf->vsi[v], locked); 516 517 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++) 518 pf->pf_agg_node[node].num_vsis = 0; 519 520 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++) 521 pf->vf_agg_node[node].num_vsis = 0; 522 } 523 524 /** 525 * ice_prepare_for_reset - prep for reset 526 * @pf: board private structure 527 * @reset_type: reset type requested 528 * 529 * Inform or close all dependent features in prep for reset. 530 */ 531 static void 532 ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type) 533 { 534 struct ice_hw *hw = &pf->hw; 535 struct ice_vsi *vsi; 536 struct ice_vf *vf; 537 unsigned int bkt; 538 539 dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type); 540 541 /* already prepared for reset */ 542 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state)) 543 return; 544 545 synchronize_irq(pf->oicr_irq.virq); 546 547 ice_unplug_aux_dev(pf); 548 549 /* Notify VFs of impending reset */ 550 if (ice_check_sq_alive(hw, &hw->mailboxq)) 551 ice_vc_notify_reset(pf); 552 553 /* Disable VFs until reset is completed */ 554 mutex_lock(&pf->vfs.table_lock); 555 ice_for_each_vf(pf, bkt, vf) 556 ice_set_vf_state_dis(vf); 557 mutex_unlock(&pf->vfs.table_lock); 558 559 if (ice_is_eswitch_mode_switchdev(pf)) { 560 rtnl_lock(); 561 ice_eswitch_br_fdb_flush(pf->eswitch.br_offloads->bridge); 562 rtnl_unlock(); 563 } 564 565 /* release ADQ specific HW and SW resources */ 566 vsi = ice_get_main_vsi(pf); 567 if (!vsi) 568 goto skip; 569 570 /* to be on safe side, reset orig_rss_size so that normal flow 571 * of deciding rss_size can take precedence 572 */ 573 vsi->orig_rss_size = 0; 574 575 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) { 576 if (reset_type == ICE_RESET_PFR) { 577 vsi->old_ena_tc = vsi->all_enatc; 578 vsi->old_numtc = vsi->all_numtc; 579 } else { 580 ice_remove_q_channels(vsi, true); 581 582 /* for other reset type, do not support channel rebuild 583 * hence reset needed info 584 */ 585 vsi->old_ena_tc = 0; 586 vsi->all_enatc = 0; 587 vsi->old_numtc = 0; 588 vsi->all_numtc = 0; 589 vsi->req_txq = 0; 590 vsi->req_rxq = 0; 591 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags); 592 memset(&vsi->mqprio_qopt, 0, sizeof(vsi->mqprio_qopt)); 593 } 594 } 595 596 if (vsi->netdev) 597 netif_device_detach(vsi->netdev); 598 skip: 599 600 /* clear SW filtering DB */ 601 ice_clear_hw_tbls(hw); 602 /* disable the VSIs and their queues that are not already DOWN */ 603 set_bit(ICE_VSI_REBUILD_PENDING, ice_get_main_vsi(pf)->state); 604 ice_pf_dis_all_vsi(pf, false); 605 606 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 607 ice_ptp_prepare_for_reset(pf, reset_type); 608 609 if (ice_is_feature_supported(pf, ICE_F_GNSS)) 610 ice_gnss_exit(pf); 611 612 if (hw->port_info) 613 ice_sched_clear_port(hw->port_info); 614 615 ice_shutdown_all_ctrlq(hw, false); 616 617 set_bit(ICE_PREPARED_FOR_RESET, pf->state); 618 } 619 620 /** 621 * ice_do_reset - Initiate one of many types of resets 622 * @pf: board private structure 623 * @reset_type: reset type requested before this function was called. 624 */ 625 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type) 626 { 627 struct device *dev = ice_pf_to_dev(pf); 628 struct ice_hw *hw = &pf->hw; 629 630 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type); 631 632 if (pf->lag && pf->lag->bonded && reset_type == ICE_RESET_PFR) { 633 dev_dbg(dev, "PFR on a bonded interface, promoting to CORER\n"); 634 reset_type = ICE_RESET_CORER; 635 } 636 637 ice_prepare_for_reset(pf, reset_type); 638 639 /* trigger the reset */ 640 if (ice_reset(hw, reset_type)) { 641 dev_err(dev, "reset %d failed\n", reset_type); 642 set_bit(ICE_RESET_FAILED, pf->state); 643 clear_bit(ICE_RESET_OICR_RECV, pf->state); 644 clear_bit(ICE_PREPARED_FOR_RESET, pf->state); 645 clear_bit(ICE_PFR_REQ, pf->state); 646 clear_bit(ICE_CORER_REQ, pf->state); 647 clear_bit(ICE_GLOBR_REQ, pf->state); 648 wake_up(&pf->reset_wait_queue); 649 return; 650 } 651 652 /* PFR is a bit of a special case because it doesn't result in an OICR 653 * interrupt. So for PFR, rebuild after the reset and clear the reset- 654 * associated state bits. 655 */ 656 if (reset_type == ICE_RESET_PFR) { 657 pf->pfr_count++; 658 ice_rebuild(pf, reset_type); 659 clear_bit(ICE_PREPARED_FOR_RESET, pf->state); 660 clear_bit(ICE_PFR_REQ, pf->state); 661 wake_up(&pf->reset_wait_queue); 662 ice_reset_all_vfs(pf); 663 } 664 } 665 666 /** 667 * ice_reset_subtask - Set up for resetting the device and driver 668 * @pf: board private structure 669 */ 670 static void ice_reset_subtask(struct ice_pf *pf) 671 { 672 enum ice_reset_req reset_type = ICE_RESET_INVAL; 673 674 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an 675 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type 676 * of reset is pending and sets bits in pf->state indicating the reset 677 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set 678 * prepare for pending reset if not already (for PF software-initiated 679 * global resets the software should already be prepared for it as 680 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated 681 * by firmware or software on other PFs, that bit is not set so prepare 682 * for the reset now), poll for reset done, rebuild and return. 683 */ 684 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) { 685 /* Perform the largest reset requested */ 686 if (test_and_clear_bit(ICE_CORER_RECV, pf->state)) 687 reset_type = ICE_RESET_CORER; 688 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state)) 689 reset_type = ICE_RESET_GLOBR; 690 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state)) 691 reset_type = ICE_RESET_EMPR; 692 /* return if no valid reset type requested */ 693 if (reset_type == ICE_RESET_INVAL) 694 return; 695 ice_prepare_for_reset(pf, reset_type); 696 697 /* make sure we are ready to rebuild */ 698 if (ice_check_reset(&pf->hw)) { 699 set_bit(ICE_RESET_FAILED, pf->state); 700 } else { 701 /* done with reset. start rebuild */ 702 pf->hw.reset_ongoing = false; 703 ice_rebuild(pf, reset_type); 704 /* clear bit to resume normal operations, but 705 * ICE_NEEDS_RESTART bit is set in case rebuild failed 706 */ 707 clear_bit(ICE_RESET_OICR_RECV, pf->state); 708 clear_bit(ICE_PREPARED_FOR_RESET, pf->state); 709 clear_bit(ICE_PFR_REQ, pf->state); 710 clear_bit(ICE_CORER_REQ, pf->state); 711 clear_bit(ICE_GLOBR_REQ, pf->state); 712 wake_up(&pf->reset_wait_queue); 713 ice_reset_all_vfs(pf); 714 } 715 716 return; 717 } 718 719 /* No pending resets to finish processing. Check for new resets */ 720 if (test_bit(ICE_PFR_REQ, pf->state)) { 721 reset_type = ICE_RESET_PFR; 722 if (pf->lag && pf->lag->bonded) { 723 dev_dbg(ice_pf_to_dev(pf), "PFR on a bonded interface, promoting to CORER\n"); 724 reset_type = ICE_RESET_CORER; 725 } 726 } 727 if (test_bit(ICE_CORER_REQ, pf->state)) 728 reset_type = ICE_RESET_CORER; 729 if (test_bit(ICE_GLOBR_REQ, pf->state)) 730 reset_type = ICE_RESET_GLOBR; 731 /* If no valid reset type requested just return */ 732 if (reset_type == ICE_RESET_INVAL) 733 return; 734 735 /* reset if not already down or busy */ 736 if (!test_bit(ICE_DOWN, pf->state) && 737 !test_bit(ICE_CFG_BUSY, pf->state)) { 738 ice_do_reset(pf, reset_type); 739 } 740 } 741 742 /** 743 * ice_print_topo_conflict - print topology conflict message 744 * @vsi: the VSI whose topology status is being checked 745 */ 746 static void ice_print_topo_conflict(struct ice_vsi *vsi) 747 { 748 switch (vsi->port_info->phy.link_info.topo_media_conflict) { 749 case ICE_AQ_LINK_TOPO_CONFLICT: 750 case ICE_AQ_LINK_MEDIA_CONFLICT: 751 case ICE_AQ_LINK_TOPO_UNREACH_PRT: 752 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT: 753 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA: 754 netdev_info(vsi->netdev, "Potential misconfiguration of the Ethernet port detected. If it was not intended, please use the Intel (R) Ethernet Port Configuration Tool to address the issue.\n"); 755 break; 756 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA: 757 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, vsi->back->flags)) 758 netdev_warn(vsi->netdev, "An unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules\n"); 759 else 760 netdev_err(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"); 761 break; 762 default: 763 break; 764 } 765 } 766 767 /** 768 * ice_print_link_msg - print link up or down message 769 * @vsi: the VSI whose link status is being queried 770 * @isup: boolean for if the link is now up or down 771 */ 772 void ice_print_link_msg(struct ice_vsi *vsi, bool isup) 773 { 774 struct ice_aqc_get_phy_caps_data *caps; 775 const char *an_advertised; 776 const char *fec_req; 777 const char *speed; 778 const char *fec; 779 const char *fc; 780 const char *an; 781 int status; 782 783 if (!vsi) 784 return; 785 786 if (vsi->current_isup == isup) 787 return; 788 789 vsi->current_isup = isup; 790 791 if (!isup) { 792 netdev_info(vsi->netdev, "NIC Link is Down\n"); 793 return; 794 } 795 796 switch (vsi->port_info->phy.link_info.link_speed) { 797 case ICE_AQ_LINK_SPEED_200GB: 798 speed = "200 G"; 799 break; 800 case ICE_AQ_LINK_SPEED_100GB: 801 speed = "100 G"; 802 break; 803 case ICE_AQ_LINK_SPEED_50GB: 804 speed = "50 G"; 805 break; 806 case ICE_AQ_LINK_SPEED_40GB: 807 speed = "40 G"; 808 break; 809 case ICE_AQ_LINK_SPEED_25GB: 810 speed = "25 G"; 811 break; 812 case ICE_AQ_LINK_SPEED_20GB: 813 speed = "20 G"; 814 break; 815 case ICE_AQ_LINK_SPEED_10GB: 816 speed = "10 G"; 817 break; 818 case ICE_AQ_LINK_SPEED_5GB: 819 speed = "5 G"; 820 break; 821 case ICE_AQ_LINK_SPEED_2500MB: 822 speed = "2.5 G"; 823 break; 824 case ICE_AQ_LINK_SPEED_1000MB: 825 speed = "1 G"; 826 break; 827 case ICE_AQ_LINK_SPEED_100MB: 828 speed = "100 M"; 829 break; 830 default: 831 speed = "Unknown "; 832 break; 833 } 834 835 switch (vsi->port_info->fc.current_mode) { 836 case ICE_FC_FULL: 837 fc = "Rx/Tx"; 838 break; 839 case ICE_FC_TX_PAUSE: 840 fc = "Tx"; 841 break; 842 case ICE_FC_RX_PAUSE: 843 fc = "Rx"; 844 break; 845 case ICE_FC_NONE: 846 fc = "None"; 847 break; 848 default: 849 fc = "Unknown"; 850 break; 851 } 852 853 /* Get FEC mode based on negotiated link info */ 854 switch (vsi->port_info->phy.link_info.fec_info) { 855 case ICE_AQ_LINK_25G_RS_528_FEC_EN: 856 case ICE_AQ_LINK_25G_RS_544_FEC_EN: 857 fec = "RS-FEC"; 858 break; 859 case ICE_AQ_LINK_25G_KR_FEC_EN: 860 fec = "FC-FEC/BASE-R"; 861 break; 862 default: 863 fec = "NONE"; 864 break; 865 } 866 867 /* check if autoneg completed, might be false due to not supported */ 868 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) 869 an = "True"; 870 else 871 an = "False"; 872 873 /* Get FEC mode requested based on PHY caps last SW configuration */ 874 caps = kzalloc(sizeof(*caps), GFP_KERNEL); 875 if (!caps) { 876 fec_req = "Unknown"; 877 an_advertised = "Unknown"; 878 goto done; 879 } 880 881 status = ice_aq_get_phy_caps(vsi->port_info, false, 882 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL); 883 if (status) 884 netdev_info(vsi->netdev, "Get phy capability failed.\n"); 885 886 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off"; 887 888 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ || 889 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ) 890 fec_req = "RS-FEC"; 891 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ || 892 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ) 893 fec_req = "FC-FEC/BASE-R"; 894 else 895 fec_req = "NONE"; 896 897 kfree(caps); 898 899 done: 900 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", 901 speed, fec_req, fec, an_advertised, an, fc); 902 ice_print_topo_conflict(vsi); 903 } 904 905 /** 906 * ice_vsi_link_event - update the VSI's netdev 907 * @vsi: the VSI on which the link event occurred 908 * @link_up: whether or not the VSI needs to be set up or down 909 */ 910 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) 911 { 912 if (!vsi) 913 return; 914 915 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev) 916 return; 917 918 if (vsi->type == ICE_VSI_PF) { 919 if (link_up == netif_carrier_ok(vsi->netdev)) 920 return; 921 922 if (link_up) { 923 netif_carrier_on(vsi->netdev); 924 netif_tx_wake_all_queues(vsi->netdev); 925 } else { 926 netif_carrier_off(vsi->netdev); 927 netif_tx_stop_all_queues(vsi->netdev); 928 } 929 } 930 } 931 932 /** 933 * ice_set_dflt_mib - send a default config MIB to the FW 934 * @pf: private PF struct 935 * 936 * This function sends a default configuration MIB to the FW. 937 * 938 * If this function errors out at any point, the driver is still able to 939 * function. The main impact is that LFC may not operate as expected. 940 * Therefore an error state in this function should be treated with a DBG 941 * message and continue on with driver rebuild/reenable. 942 */ 943 static void ice_set_dflt_mib(struct ice_pf *pf) 944 { 945 struct device *dev = ice_pf_to_dev(pf); 946 u8 mib_type, *buf, *lldpmib = NULL; 947 u16 len, typelen, offset = 0; 948 struct ice_lldp_org_tlv *tlv; 949 struct ice_hw *hw = &pf->hw; 950 u32 ouisubtype; 951 952 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB; 953 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL); 954 if (!lldpmib) { 955 dev_dbg(dev, "%s Failed to allocate MIB memory\n", 956 __func__); 957 return; 958 } 959 960 /* Add ETS CFG TLV */ 961 tlv = (struct ice_lldp_org_tlv *)lldpmib; 962 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | 963 ICE_IEEE_ETS_TLV_LEN); 964 tlv->typelen = htons(typelen); 965 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 966 ICE_IEEE_SUBTYPE_ETS_CFG); 967 tlv->ouisubtype = htonl(ouisubtype); 968 969 buf = tlv->tlvinfo; 970 buf[0] = 0; 971 972 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0. 973 * Octets 5 - 12 are BW values, set octet 5 to 100% BW. 974 * Octets 13 - 20 are TSA values - leave as zeros 975 */ 976 buf[5] = 0x64; 977 len = FIELD_GET(ICE_LLDP_TLV_LEN_M, typelen); 978 offset += len + 2; 979 tlv = (struct ice_lldp_org_tlv *) 980 ((char *)tlv + sizeof(tlv->typelen) + len); 981 982 /* Add ETS REC TLV */ 983 buf = tlv->tlvinfo; 984 tlv->typelen = htons(typelen); 985 986 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 987 ICE_IEEE_SUBTYPE_ETS_REC); 988 tlv->ouisubtype = htonl(ouisubtype); 989 990 /* First octet of buf is reserved 991 * Octets 1 - 4 map UP to TC - all UPs map to zero 992 * Octets 5 - 12 are BW values - set TC 0 to 100%. 993 * Octets 13 - 20 are TSA value - leave as zeros 994 */ 995 buf[5] = 0x64; 996 offset += len + 2; 997 tlv = (struct ice_lldp_org_tlv *) 998 ((char *)tlv + sizeof(tlv->typelen) + len); 999 1000 /* Add PFC CFG TLV */ 1001 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | 1002 ICE_IEEE_PFC_TLV_LEN); 1003 tlv->typelen = htons(typelen); 1004 1005 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | 1006 ICE_IEEE_SUBTYPE_PFC_CFG); 1007 tlv->ouisubtype = htonl(ouisubtype); 1008 1009 /* Octet 1 left as all zeros - PFC disabled */ 1010 buf[0] = 0x08; 1011 len = FIELD_GET(ICE_LLDP_TLV_LEN_M, typelen); 1012 offset += len + 2; 1013 1014 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL)) 1015 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__); 1016 1017 kfree(lldpmib); 1018 } 1019 1020 /** 1021 * ice_check_phy_fw_load - check if PHY FW load failed 1022 * @pf: pointer to PF struct 1023 * @link_cfg_err: bitmap from the link info structure 1024 * 1025 * check if external PHY FW load failed and print an error message if it did 1026 */ 1027 static void ice_check_phy_fw_load(struct ice_pf *pf, u8 link_cfg_err) 1028 { 1029 if (!(link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE)) { 1030 clear_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags); 1031 return; 1032 } 1033 1034 if (test_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags)) 1035 return; 1036 1037 if (link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE) { 1038 dev_err(ice_pf_to_dev(pf), "Device failed to load the FW for the external PHY. Please download and install the latest NVM for your device and try again\n"); 1039 set_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags); 1040 } 1041 } 1042 1043 /** 1044 * ice_check_module_power 1045 * @pf: pointer to PF struct 1046 * @link_cfg_err: bitmap from the link info structure 1047 * 1048 * check module power level returned by a previous call to aq_get_link_info 1049 * and print error messages if module power level is not supported 1050 */ 1051 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err) 1052 { 1053 /* if module power level is supported, clear the flag */ 1054 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT | 1055 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) { 1056 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); 1057 return; 1058 } 1059 1060 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the 1061 * above block didn't clear this bit, there's nothing to do 1062 */ 1063 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags)) 1064 return; 1065 1066 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) { 1067 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n"); 1068 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); 1069 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) { 1070 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n"); 1071 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); 1072 } 1073 } 1074 1075 /** 1076 * ice_check_link_cfg_err - check if link configuration failed 1077 * @pf: pointer to the PF struct 1078 * @link_cfg_err: bitmap from the link info structure 1079 * 1080 * print if any link configuration failure happens due to the value in the 1081 * link_cfg_err parameter in the link info structure 1082 */ 1083 static void ice_check_link_cfg_err(struct ice_pf *pf, u8 link_cfg_err) 1084 { 1085 ice_check_module_power(pf, link_cfg_err); 1086 ice_check_phy_fw_load(pf, link_cfg_err); 1087 } 1088 1089 /** 1090 * ice_link_event - process the link event 1091 * @pf: PF that the link event is associated with 1092 * @pi: port_info for the port that the link event is associated with 1093 * @link_up: true if the physical link is up and false if it is down 1094 * @link_speed: current link speed received from the link event 1095 * 1096 * Returns 0 on success and negative on failure 1097 */ 1098 static int 1099 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up, 1100 u16 link_speed) 1101 { 1102 struct device *dev = ice_pf_to_dev(pf); 1103 struct ice_phy_info *phy_info; 1104 struct ice_vsi *vsi; 1105 u16 old_link_speed; 1106 bool old_link; 1107 int status; 1108 1109 phy_info = &pi->phy; 1110 phy_info->link_info_old = phy_info->link_info; 1111 1112 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP); 1113 old_link_speed = phy_info->link_info_old.link_speed; 1114 1115 /* update the link info structures and re-enable link events, 1116 * don't bail on failure due to other book keeping needed 1117 */ 1118 status = ice_update_link_info(pi); 1119 if (status) 1120 dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n", 1121 pi->lport, status, 1122 ice_aq_str(pi->hw->adminq.sq_last_status)); 1123 1124 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err); 1125 1126 /* Check if the link state is up after updating link info, and treat 1127 * this event as an UP event since the link is actually UP now. 1128 */ 1129 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP) 1130 link_up = true; 1131 1132 vsi = ice_get_main_vsi(pf); 1133 if (!vsi || !vsi->port_info) 1134 return -EINVAL; 1135 1136 /* turn off PHY if media was removed */ 1137 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) && 1138 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) { 1139 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 1140 ice_set_link(vsi, false); 1141 } 1142 1143 /* if the old link up/down and speed is the same as the new */ 1144 if (link_up == old_link && link_speed == old_link_speed) 1145 return 0; 1146 1147 ice_ptp_link_change(pf, link_up); 1148 1149 if (ice_is_dcb_active(pf)) { 1150 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags)) 1151 ice_dcb_rebuild(pf); 1152 } else { 1153 if (link_up) 1154 ice_set_dflt_mib(pf); 1155 } 1156 ice_vsi_link_event(vsi, link_up); 1157 ice_print_link_msg(vsi, link_up); 1158 1159 ice_vc_notify_link_state(pf); 1160 1161 return 0; 1162 } 1163 1164 /** 1165 * ice_watchdog_subtask - periodic tasks not using event driven scheduling 1166 * @pf: board private structure 1167 */ 1168 static void ice_watchdog_subtask(struct ice_pf *pf) 1169 { 1170 int i; 1171 1172 /* if interface is down do nothing */ 1173 if (test_bit(ICE_DOWN, pf->state) || 1174 test_bit(ICE_CFG_BUSY, pf->state)) 1175 return; 1176 1177 /* make sure we don't do these things too often */ 1178 if (time_before(jiffies, 1179 pf->serv_tmr_prev + pf->serv_tmr_period)) 1180 return; 1181 1182 pf->serv_tmr_prev = jiffies; 1183 1184 /* Update the stats for active netdevs so the network stack 1185 * can look at updated numbers whenever it cares to 1186 */ 1187 ice_update_pf_stats(pf); 1188 ice_for_each_vsi(pf, i) 1189 if (pf->vsi[i] && pf->vsi[i]->netdev) 1190 ice_update_vsi_stats(pf->vsi[i]); 1191 } 1192 1193 /** 1194 * ice_init_link_events - enable/initialize link events 1195 * @pi: pointer to the port_info instance 1196 * 1197 * Returns -EIO on failure, 0 on success 1198 */ 1199 static int ice_init_link_events(struct ice_port_info *pi) 1200 { 1201 u16 mask; 1202 1203 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA | 1204 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL | 1205 ICE_AQ_LINK_EVENT_PHY_FW_LOAD_FAIL)); 1206 1207 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) { 1208 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n", 1209 pi->lport); 1210 return -EIO; 1211 } 1212 1213 if (ice_aq_get_link_info(pi, true, NULL, NULL)) { 1214 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n", 1215 pi->lport); 1216 return -EIO; 1217 } 1218 1219 return 0; 1220 } 1221 1222 /** 1223 * ice_handle_link_event - handle link event via ARQ 1224 * @pf: PF that the link event is associated with 1225 * @event: event structure containing link status info 1226 */ 1227 static int 1228 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event) 1229 { 1230 struct ice_aqc_get_link_status_data *link_data; 1231 struct ice_port_info *port_info; 1232 int status; 1233 1234 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf; 1235 port_info = pf->hw.port_info; 1236 if (!port_info) 1237 return -EINVAL; 1238 1239 status = ice_link_event(pf, port_info, 1240 !!(link_data->link_info & ICE_AQ_LINK_UP), 1241 le16_to_cpu(link_data->link_speed)); 1242 if (status) 1243 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n", 1244 status); 1245 1246 return status; 1247 } 1248 1249 /** 1250 * ice_get_fwlog_data - copy the FW log data from ARQ event 1251 * @pf: PF that the FW log event is associated with 1252 * @event: event structure containing FW log data 1253 */ 1254 static void 1255 ice_get_fwlog_data(struct ice_pf *pf, struct ice_rq_event_info *event) 1256 { 1257 struct ice_fwlog_data *fwlog; 1258 struct ice_hw *hw = &pf->hw; 1259 1260 fwlog = &hw->fwlog_ring.rings[hw->fwlog_ring.tail]; 1261 1262 memset(fwlog->data, 0, PAGE_SIZE); 1263 fwlog->data_size = le16_to_cpu(event->desc.datalen); 1264 1265 memcpy(fwlog->data, event->msg_buf, fwlog->data_size); 1266 ice_fwlog_ring_increment(&hw->fwlog_ring.tail, hw->fwlog_ring.size); 1267 1268 if (ice_fwlog_ring_full(&hw->fwlog_ring)) { 1269 /* the rings are full so bump the head to create room */ 1270 ice_fwlog_ring_increment(&hw->fwlog_ring.head, 1271 hw->fwlog_ring.size); 1272 } 1273 } 1274 1275 /** 1276 * ice_aq_prep_for_event - Prepare to wait for an AdminQ event from firmware 1277 * @pf: pointer to the PF private structure 1278 * @task: intermediate helper storage and identifier for waiting 1279 * @opcode: the opcode to wait for 1280 * 1281 * Prepares to wait for a specific AdminQ completion event on the ARQ for 1282 * a given PF. Actual wait would be done by a call to ice_aq_wait_for_event(). 1283 * 1284 * Calls are separated to allow caller registering for event before sending 1285 * the command, which mitigates a race between registering and FW responding. 1286 * 1287 * To obtain only the descriptor contents, pass an task->event with null 1288 * msg_buf. If the complete data buffer is desired, allocate the 1289 * task->event.msg_buf with enough space ahead of time. 1290 */ 1291 void ice_aq_prep_for_event(struct ice_pf *pf, struct ice_aq_task *task, 1292 u16 opcode) 1293 { 1294 INIT_HLIST_NODE(&task->entry); 1295 task->opcode = opcode; 1296 task->state = ICE_AQ_TASK_WAITING; 1297 1298 spin_lock_bh(&pf->aq_wait_lock); 1299 hlist_add_head(&task->entry, &pf->aq_wait_list); 1300 spin_unlock_bh(&pf->aq_wait_lock); 1301 } 1302 1303 /** 1304 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware 1305 * @pf: pointer to the PF private structure 1306 * @task: ptr prepared by ice_aq_prep_for_event() 1307 * @timeout: how long to wait, in jiffies 1308 * 1309 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The 1310 * current thread will be put to sleep until the specified event occurs or 1311 * until the given timeout is reached. 1312 * 1313 * Returns: zero on success, or a negative error code on failure. 1314 */ 1315 int ice_aq_wait_for_event(struct ice_pf *pf, struct ice_aq_task *task, 1316 unsigned long timeout) 1317 { 1318 enum ice_aq_task_state *state = &task->state; 1319 struct device *dev = ice_pf_to_dev(pf); 1320 unsigned long start = jiffies; 1321 long ret; 1322 int err; 1323 1324 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, 1325 *state != ICE_AQ_TASK_WAITING, 1326 timeout); 1327 switch (*state) { 1328 case ICE_AQ_TASK_NOT_PREPARED: 1329 WARN(1, "call to %s without ice_aq_prep_for_event()", __func__); 1330 err = -EINVAL; 1331 break; 1332 case ICE_AQ_TASK_WAITING: 1333 err = ret < 0 ? ret : -ETIMEDOUT; 1334 break; 1335 case ICE_AQ_TASK_CANCELED: 1336 err = ret < 0 ? ret : -ECANCELED; 1337 break; 1338 case ICE_AQ_TASK_COMPLETE: 1339 err = ret < 0 ? ret : 0; 1340 break; 1341 default: 1342 WARN(1, "Unexpected AdminQ wait task state %u", *state); 1343 err = -EINVAL; 1344 break; 1345 } 1346 1347 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n", 1348 jiffies_to_msecs(jiffies - start), 1349 jiffies_to_msecs(timeout), 1350 task->opcode); 1351 1352 spin_lock_bh(&pf->aq_wait_lock); 1353 hlist_del(&task->entry); 1354 spin_unlock_bh(&pf->aq_wait_lock); 1355 1356 return err; 1357 } 1358 1359 /** 1360 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event 1361 * @pf: pointer to the PF private structure 1362 * @opcode: the opcode of the event 1363 * @event: the event to check 1364 * 1365 * Loops over the current list of pending threads waiting for an AdminQ event. 1366 * For each matching task, copy the contents of the event into the task 1367 * structure and wake up the thread. 1368 * 1369 * If multiple threads wait for the same opcode, they will all be woken up. 1370 * 1371 * Note that event->msg_buf will only be duplicated if the event has a buffer 1372 * with enough space already allocated. Otherwise, only the descriptor and 1373 * message length will be copied. 1374 * 1375 * Returns: true if an event was found, false otherwise 1376 */ 1377 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode, 1378 struct ice_rq_event_info *event) 1379 { 1380 struct ice_rq_event_info *task_ev; 1381 struct ice_aq_task *task; 1382 bool found = false; 1383 1384 spin_lock_bh(&pf->aq_wait_lock); 1385 hlist_for_each_entry(task, &pf->aq_wait_list, entry) { 1386 if (task->state != ICE_AQ_TASK_WAITING) 1387 continue; 1388 if (task->opcode != opcode) 1389 continue; 1390 1391 task_ev = &task->event; 1392 memcpy(&task_ev->desc, &event->desc, sizeof(event->desc)); 1393 task_ev->msg_len = event->msg_len; 1394 1395 /* Only copy the data buffer if a destination was set */ 1396 if (task_ev->msg_buf && task_ev->buf_len >= event->buf_len) { 1397 memcpy(task_ev->msg_buf, event->msg_buf, 1398 event->buf_len); 1399 task_ev->buf_len = event->buf_len; 1400 } 1401 1402 task->state = ICE_AQ_TASK_COMPLETE; 1403 found = true; 1404 } 1405 spin_unlock_bh(&pf->aq_wait_lock); 1406 1407 if (found) 1408 wake_up(&pf->aq_wait_queue); 1409 } 1410 1411 /** 1412 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks 1413 * @pf: the PF private structure 1414 * 1415 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads. 1416 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED. 1417 */ 1418 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf) 1419 { 1420 struct ice_aq_task *task; 1421 1422 spin_lock_bh(&pf->aq_wait_lock); 1423 hlist_for_each_entry(task, &pf->aq_wait_list, entry) 1424 task->state = ICE_AQ_TASK_CANCELED; 1425 spin_unlock_bh(&pf->aq_wait_lock); 1426 1427 wake_up(&pf->aq_wait_queue); 1428 } 1429 1430 #define ICE_MBX_OVERFLOW_WATERMARK 64 1431 1432 /** 1433 * __ice_clean_ctrlq - helper function to clean controlq rings 1434 * @pf: ptr to struct ice_pf 1435 * @q_type: specific Control queue type 1436 */ 1437 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type) 1438 { 1439 struct device *dev = ice_pf_to_dev(pf); 1440 struct ice_rq_event_info event; 1441 struct ice_hw *hw = &pf->hw; 1442 struct ice_ctl_q_info *cq; 1443 u16 pending, i = 0; 1444 const char *qtype; 1445 u32 oldval, val; 1446 1447 /* Do not clean control queue if/when PF reset fails */ 1448 if (test_bit(ICE_RESET_FAILED, pf->state)) 1449 return 0; 1450 1451 switch (q_type) { 1452 case ICE_CTL_Q_ADMIN: 1453 cq = &hw->adminq; 1454 qtype = "Admin"; 1455 break; 1456 case ICE_CTL_Q_SB: 1457 cq = &hw->sbq; 1458 qtype = "Sideband"; 1459 break; 1460 case ICE_CTL_Q_MAILBOX: 1461 cq = &hw->mailboxq; 1462 qtype = "Mailbox"; 1463 /* we are going to try to detect a malicious VF, so set the 1464 * state to begin detection 1465 */ 1466 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT; 1467 break; 1468 default: 1469 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type); 1470 return 0; 1471 } 1472 1473 /* check for error indications - PF_xx_AxQLEN register layout for 1474 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN. 1475 */ 1476 val = rd32(hw, cq->rq.len); 1477 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | 1478 PF_FW_ARQLEN_ARQCRIT_M)) { 1479 oldval = val; 1480 if (val & PF_FW_ARQLEN_ARQVFE_M) 1481 dev_dbg(dev, "%s Receive Queue VF Error detected\n", 1482 qtype); 1483 if (val & PF_FW_ARQLEN_ARQOVFL_M) { 1484 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n", 1485 qtype); 1486 } 1487 if (val & PF_FW_ARQLEN_ARQCRIT_M) 1488 dev_dbg(dev, "%s Receive Queue Critical Error detected\n", 1489 qtype); 1490 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | 1491 PF_FW_ARQLEN_ARQCRIT_M); 1492 if (oldval != val) 1493 wr32(hw, cq->rq.len, val); 1494 } 1495 1496 val = rd32(hw, cq->sq.len); 1497 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | 1498 PF_FW_ATQLEN_ATQCRIT_M)) { 1499 oldval = val; 1500 if (val & PF_FW_ATQLEN_ATQVFE_M) 1501 dev_dbg(dev, "%s Send Queue VF Error detected\n", 1502 qtype); 1503 if (val & PF_FW_ATQLEN_ATQOVFL_M) { 1504 dev_dbg(dev, "%s Send Queue Overflow Error detected\n", 1505 qtype); 1506 } 1507 if (val & PF_FW_ATQLEN_ATQCRIT_M) 1508 dev_dbg(dev, "%s Send Queue Critical Error detected\n", 1509 qtype); 1510 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | 1511 PF_FW_ATQLEN_ATQCRIT_M); 1512 if (oldval != val) 1513 wr32(hw, cq->sq.len, val); 1514 } 1515 1516 event.buf_len = cq->rq_buf_size; 1517 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); 1518 if (!event.msg_buf) 1519 return 0; 1520 1521 do { 1522 struct ice_mbx_data data = {}; 1523 u16 opcode; 1524 int ret; 1525 1526 ret = ice_clean_rq_elem(hw, cq, &event, &pending); 1527 if (ret == -EALREADY) 1528 break; 1529 if (ret) { 1530 dev_err(dev, "%s Receive Queue event error %d\n", qtype, 1531 ret); 1532 break; 1533 } 1534 1535 opcode = le16_to_cpu(event.desc.opcode); 1536 1537 /* Notify any thread that might be waiting for this event */ 1538 ice_aq_check_events(pf, opcode, &event); 1539 1540 switch (opcode) { 1541 case ice_aqc_opc_get_link_status: 1542 if (ice_handle_link_event(pf, &event)) 1543 dev_err(dev, "Could not handle link event\n"); 1544 break; 1545 case ice_aqc_opc_event_lan_overflow: 1546 ice_vf_lan_overflow_event(pf, &event); 1547 break; 1548 case ice_mbx_opc_send_msg_to_pf: 1549 if (ice_is_feature_supported(pf, ICE_F_MBX_LIMIT)) { 1550 ice_vc_process_vf_msg(pf, &event, NULL); 1551 ice_mbx_vf_dec_trig_e830(hw, &event); 1552 } else { 1553 u16 val = hw->mailboxq.num_rq_entries; 1554 1555 data.max_num_msgs_mbx = val; 1556 val = ICE_MBX_OVERFLOW_WATERMARK; 1557 data.async_watermark_val = val; 1558 data.num_msg_proc = i; 1559 data.num_pending_arq = pending; 1560 1561 ice_vc_process_vf_msg(pf, &event, &data); 1562 } 1563 break; 1564 case ice_aqc_opc_fw_logs_event: 1565 ice_get_fwlog_data(pf, &event); 1566 break; 1567 case ice_aqc_opc_lldp_set_mib_change: 1568 ice_dcb_process_lldp_set_mib_change(pf, &event); 1569 break; 1570 case ice_aqc_opc_get_health_status: 1571 ice_process_health_status_event(pf, &event); 1572 break; 1573 default: 1574 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n", 1575 qtype, opcode); 1576 break; 1577 } 1578 } while (pending && (i++ < ICE_DFLT_IRQ_WORK)); 1579 1580 kfree(event.msg_buf); 1581 1582 return pending && (i == ICE_DFLT_IRQ_WORK); 1583 } 1584 1585 /** 1586 * ice_ctrlq_pending - check if there is a difference between ntc and ntu 1587 * @hw: pointer to hardware info 1588 * @cq: control queue information 1589 * 1590 * returns true if there are pending messages in a queue, false if there aren't 1591 */ 1592 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq) 1593 { 1594 u16 ntu; 1595 1596 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask); 1597 return cq->rq.next_to_clean != ntu; 1598 } 1599 1600 /** 1601 * ice_clean_adminq_subtask - clean the AdminQ rings 1602 * @pf: board private structure 1603 */ 1604 static void ice_clean_adminq_subtask(struct ice_pf *pf) 1605 { 1606 struct ice_hw *hw = &pf->hw; 1607 1608 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state)) 1609 return; 1610 1611 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN)) 1612 return; 1613 1614 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state); 1615 1616 /* There might be a situation where new messages arrive to a control 1617 * queue between processing the last message and clearing the 1618 * EVENT_PENDING bit. So before exiting, check queue head again (using 1619 * ice_ctrlq_pending) and process new messages if any. 1620 */ 1621 if (ice_ctrlq_pending(hw, &hw->adminq)) 1622 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN); 1623 1624 ice_flush(hw); 1625 } 1626 1627 /** 1628 * ice_clean_mailboxq_subtask - clean the MailboxQ rings 1629 * @pf: board private structure 1630 */ 1631 static void ice_clean_mailboxq_subtask(struct ice_pf *pf) 1632 { 1633 struct ice_hw *hw = &pf->hw; 1634 1635 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state)) 1636 return; 1637 1638 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX)) 1639 return; 1640 1641 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state); 1642 1643 if (ice_ctrlq_pending(hw, &hw->mailboxq)) 1644 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX); 1645 1646 ice_flush(hw); 1647 } 1648 1649 /** 1650 * ice_clean_sbq_subtask - clean the Sideband Queue rings 1651 * @pf: board private structure 1652 */ 1653 static void ice_clean_sbq_subtask(struct ice_pf *pf) 1654 { 1655 struct ice_hw *hw = &pf->hw; 1656 1657 /* if mac_type is not generic, sideband is not supported 1658 * and there's nothing to do here 1659 */ 1660 if (!ice_is_generic_mac(hw)) { 1661 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); 1662 return; 1663 } 1664 1665 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state)) 1666 return; 1667 1668 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB)) 1669 return; 1670 1671 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); 1672 1673 if (ice_ctrlq_pending(hw, &hw->sbq)) 1674 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB); 1675 1676 ice_flush(hw); 1677 } 1678 1679 /** 1680 * ice_service_task_schedule - schedule the service task to wake up 1681 * @pf: board private structure 1682 * 1683 * If not already scheduled, this puts the task into the work queue. 1684 */ 1685 void ice_service_task_schedule(struct ice_pf *pf) 1686 { 1687 if (!test_bit(ICE_SERVICE_DIS, pf->state) && 1688 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) && 1689 !test_bit(ICE_NEEDS_RESTART, pf->state)) 1690 queue_work(ice_wq, &pf->serv_task); 1691 } 1692 1693 /** 1694 * ice_service_task_complete - finish up the service task 1695 * @pf: board private structure 1696 */ 1697 static void ice_service_task_complete(struct ice_pf *pf) 1698 { 1699 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state)); 1700 1701 /* force memory (pf->state) to sync before next service task */ 1702 smp_mb__before_atomic(); 1703 clear_bit(ICE_SERVICE_SCHED, pf->state); 1704 } 1705 1706 /** 1707 * ice_service_task_stop - stop service task and cancel works 1708 * @pf: board private structure 1709 * 1710 * Return 0 if the ICE_SERVICE_DIS bit was not already set, 1711 * 1 otherwise. 1712 */ 1713 static int ice_service_task_stop(struct ice_pf *pf) 1714 { 1715 int ret; 1716 1717 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state); 1718 1719 if (pf->serv_tmr.function) 1720 del_timer_sync(&pf->serv_tmr); 1721 if (pf->serv_task.func) 1722 cancel_work_sync(&pf->serv_task); 1723 1724 clear_bit(ICE_SERVICE_SCHED, pf->state); 1725 return ret; 1726 } 1727 1728 /** 1729 * ice_service_task_restart - restart service task and schedule works 1730 * @pf: board private structure 1731 * 1732 * This function is needed for suspend and resume works (e.g WoL scenario) 1733 */ 1734 static void ice_service_task_restart(struct ice_pf *pf) 1735 { 1736 clear_bit(ICE_SERVICE_DIS, pf->state); 1737 ice_service_task_schedule(pf); 1738 } 1739 1740 /** 1741 * ice_service_timer - timer callback to schedule service task 1742 * @t: pointer to timer_list 1743 */ 1744 static void ice_service_timer(struct timer_list *t) 1745 { 1746 struct ice_pf *pf = from_timer(pf, t, serv_tmr); 1747 1748 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies)); 1749 ice_service_task_schedule(pf); 1750 } 1751 1752 /** 1753 * ice_mdd_maybe_reset_vf - reset VF after MDD event 1754 * @pf: pointer to the PF structure 1755 * @vf: pointer to the VF structure 1756 * @reset_vf_tx: whether Tx MDD has occurred 1757 * @reset_vf_rx: whether Rx MDD has occurred 1758 * 1759 * Since the queue can get stuck on VF MDD events, the PF can be configured to 1760 * automatically reset the VF by enabling the private ethtool flag 1761 * mdd-auto-reset-vf. 1762 */ 1763 static void ice_mdd_maybe_reset_vf(struct ice_pf *pf, struct ice_vf *vf, 1764 bool reset_vf_tx, bool reset_vf_rx) 1765 { 1766 struct device *dev = ice_pf_to_dev(pf); 1767 1768 if (!test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) 1769 return; 1770 1771 /* VF MDD event counters will be cleared by reset, so print the event 1772 * prior to reset. 1773 */ 1774 if (reset_vf_tx) 1775 ice_print_vf_tx_mdd_event(vf); 1776 1777 if (reset_vf_rx) 1778 ice_print_vf_rx_mdd_event(vf); 1779 1780 dev_info(dev, "PF-to-VF reset on PF %d VF %d due to MDD event\n", 1781 pf->hw.pf_id, vf->vf_id); 1782 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY | ICE_VF_RESET_LOCK); 1783 } 1784 1785 /** 1786 * ice_handle_mdd_event - handle malicious driver detect event 1787 * @pf: pointer to the PF structure 1788 * 1789 * Called from service task. OICR interrupt handler indicates MDD event. 1790 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log 1791 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events 1792 * disable the queue, the PF can be configured to reset the VF using ethtool 1793 * private flag mdd-auto-reset-vf. 1794 */ 1795 static void ice_handle_mdd_event(struct ice_pf *pf) 1796 { 1797 struct device *dev = ice_pf_to_dev(pf); 1798 struct ice_hw *hw = &pf->hw; 1799 struct ice_vf *vf; 1800 unsigned int bkt; 1801 u32 reg; 1802 1803 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) { 1804 /* Since the VF MDD event logging is rate limited, check if 1805 * there are pending MDD events. 1806 */ 1807 ice_print_vfs_mdd_events(pf); 1808 return; 1809 } 1810 1811 /* find what triggered an MDD event */ 1812 reg = rd32(hw, GL_MDET_TX_PQM); 1813 if (reg & GL_MDET_TX_PQM_VALID_M) { 1814 u8 pf_num = FIELD_GET(GL_MDET_TX_PQM_PF_NUM_M, reg); 1815 u16 vf_num = FIELD_GET(GL_MDET_TX_PQM_VF_NUM_M, reg); 1816 u8 event = FIELD_GET(GL_MDET_TX_PQM_MAL_TYPE_M, reg); 1817 u16 queue = FIELD_GET(GL_MDET_TX_PQM_QNUM_M, reg); 1818 1819 if (netif_msg_tx_err(pf)) 1820 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", 1821 event, queue, pf_num, vf_num); 1822 ice_report_mdd_event(pf, ICE_MDD_SRC_TX_PQM, pf_num, vf_num, 1823 event, queue); 1824 wr32(hw, GL_MDET_TX_PQM, 0xffffffff); 1825 } 1826 1827 reg = rd32(hw, GL_MDET_TX_TCLAN_BY_MAC(hw)); 1828 if (reg & GL_MDET_TX_TCLAN_VALID_M) { 1829 u8 pf_num = FIELD_GET(GL_MDET_TX_TCLAN_PF_NUM_M, reg); 1830 u16 vf_num = FIELD_GET(GL_MDET_TX_TCLAN_VF_NUM_M, reg); 1831 u8 event = FIELD_GET(GL_MDET_TX_TCLAN_MAL_TYPE_M, reg); 1832 u16 queue = FIELD_GET(GL_MDET_TX_TCLAN_QNUM_M, reg); 1833 1834 if (netif_msg_tx_err(pf)) 1835 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", 1836 event, queue, pf_num, vf_num); 1837 ice_report_mdd_event(pf, ICE_MDD_SRC_TX_TCLAN, pf_num, vf_num, 1838 event, queue); 1839 wr32(hw, GL_MDET_TX_TCLAN_BY_MAC(hw), U32_MAX); 1840 } 1841 1842 reg = rd32(hw, GL_MDET_RX); 1843 if (reg & GL_MDET_RX_VALID_M) { 1844 u8 pf_num = FIELD_GET(GL_MDET_RX_PF_NUM_M, reg); 1845 u16 vf_num = FIELD_GET(GL_MDET_RX_VF_NUM_M, reg); 1846 u8 event = FIELD_GET(GL_MDET_RX_MAL_TYPE_M, reg); 1847 u16 queue = FIELD_GET(GL_MDET_RX_QNUM_M, reg); 1848 1849 if (netif_msg_rx_err(pf)) 1850 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n", 1851 event, queue, pf_num, vf_num); 1852 ice_report_mdd_event(pf, ICE_MDD_SRC_RX, pf_num, vf_num, event, 1853 queue); 1854 wr32(hw, GL_MDET_RX, 0xffffffff); 1855 } 1856 1857 /* check to see if this PF caused an MDD event */ 1858 reg = rd32(hw, PF_MDET_TX_PQM); 1859 if (reg & PF_MDET_TX_PQM_VALID_M) { 1860 wr32(hw, PF_MDET_TX_PQM, 0xFFFF); 1861 if (netif_msg_tx_err(pf)) 1862 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n"); 1863 } 1864 1865 reg = rd32(hw, PF_MDET_TX_TCLAN_BY_MAC(hw)); 1866 if (reg & PF_MDET_TX_TCLAN_VALID_M) { 1867 wr32(hw, PF_MDET_TX_TCLAN_BY_MAC(hw), 0xffff); 1868 if (netif_msg_tx_err(pf)) 1869 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n"); 1870 } 1871 1872 reg = rd32(hw, PF_MDET_RX); 1873 if (reg & PF_MDET_RX_VALID_M) { 1874 wr32(hw, PF_MDET_RX, 0xFFFF); 1875 if (netif_msg_rx_err(pf)) 1876 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n"); 1877 } 1878 1879 /* Check to see if one of the VFs caused an MDD event, and then 1880 * increment counters and set print pending 1881 */ 1882 mutex_lock(&pf->vfs.table_lock); 1883 ice_for_each_vf(pf, bkt, vf) { 1884 bool reset_vf_tx = false, reset_vf_rx = false; 1885 1886 reg = rd32(hw, VP_MDET_TX_PQM(vf->vf_id)); 1887 if (reg & VP_MDET_TX_PQM_VALID_M) { 1888 wr32(hw, VP_MDET_TX_PQM(vf->vf_id), 0xFFFF); 1889 vf->mdd_tx_events.count++; 1890 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); 1891 if (netif_msg_tx_err(pf)) 1892 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n", 1893 vf->vf_id); 1894 1895 reset_vf_tx = true; 1896 } 1897 1898 reg = rd32(hw, VP_MDET_TX_TCLAN(vf->vf_id)); 1899 if (reg & VP_MDET_TX_TCLAN_VALID_M) { 1900 wr32(hw, VP_MDET_TX_TCLAN(vf->vf_id), 0xFFFF); 1901 vf->mdd_tx_events.count++; 1902 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); 1903 if (netif_msg_tx_err(pf)) 1904 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n", 1905 vf->vf_id); 1906 1907 reset_vf_tx = true; 1908 } 1909 1910 reg = rd32(hw, VP_MDET_TX_TDPU(vf->vf_id)); 1911 if (reg & VP_MDET_TX_TDPU_VALID_M) { 1912 wr32(hw, VP_MDET_TX_TDPU(vf->vf_id), 0xFFFF); 1913 vf->mdd_tx_events.count++; 1914 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); 1915 if (netif_msg_tx_err(pf)) 1916 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n", 1917 vf->vf_id); 1918 1919 reset_vf_tx = true; 1920 } 1921 1922 reg = rd32(hw, VP_MDET_RX(vf->vf_id)); 1923 if (reg & VP_MDET_RX_VALID_M) { 1924 wr32(hw, VP_MDET_RX(vf->vf_id), 0xFFFF); 1925 vf->mdd_rx_events.count++; 1926 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); 1927 if (netif_msg_rx_err(pf)) 1928 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n", 1929 vf->vf_id); 1930 1931 reset_vf_rx = true; 1932 } 1933 1934 if (reset_vf_tx || reset_vf_rx) 1935 ice_mdd_maybe_reset_vf(pf, vf, reset_vf_tx, 1936 reset_vf_rx); 1937 } 1938 mutex_unlock(&pf->vfs.table_lock); 1939 1940 ice_print_vfs_mdd_events(pf); 1941 } 1942 1943 /** 1944 * ice_force_phys_link_state - Force the physical link state 1945 * @vsi: VSI to force the physical link state to up/down 1946 * @link_up: true/false indicates to set the physical link to up/down 1947 * 1948 * Force the physical link state by getting the current PHY capabilities from 1949 * hardware and setting the PHY config based on the determined capabilities. If 1950 * link changes a link event will be triggered because both the Enable Automatic 1951 * Link Update and LESM Enable bits are set when setting the PHY capabilities. 1952 * 1953 * Returns 0 on success, negative on failure 1954 */ 1955 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up) 1956 { 1957 struct ice_aqc_get_phy_caps_data *pcaps; 1958 struct ice_aqc_set_phy_cfg_data *cfg; 1959 struct ice_port_info *pi; 1960 struct device *dev; 1961 int retcode; 1962 1963 if (!vsi || !vsi->port_info || !vsi->back) 1964 return -EINVAL; 1965 if (vsi->type != ICE_VSI_PF) 1966 return 0; 1967 1968 dev = ice_pf_to_dev(vsi->back); 1969 1970 pi = vsi->port_info; 1971 1972 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 1973 if (!pcaps) 1974 return -ENOMEM; 1975 1976 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, 1977 NULL); 1978 if (retcode) { 1979 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n", 1980 vsi->vsi_num, retcode); 1981 retcode = -EIO; 1982 goto out; 1983 } 1984 1985 /* No change in link */ 1986 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) && 1987 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP)) 1988 goto out; 1989 1990 /* Use the current user PHY configuration. The current user PHY 1991 * configuration is initialized during probe from PHY capabilities 1992 * software mode, and updated on set PHY configuration. 1993 */ 1994 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL); 1995 if (!cfg) { 1996 retcode = -ENOMEM; 1997 goto out; 1998 } 1999 2000 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; 2001 if (link_up) 2002 cfg->caps |= ICE_AQ_PHY_ENA_LINK; 2003 else 2004 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK; 2005 2006 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL); 2007 if (retcode) { 2008 dev_err(dev, "Failed to set phy config, VSI %d error %d\n", 2009 vsi->vsi_num, retcode); 2010 retcode = -EIO; 2011 } 2012 2013 kfree(cfg); 2014 out: 2015 kfree(pcaps); 2016 return retcode; 2017 } 2018 2019 /** 2020 * ice_init_nvm_phy_type - Initialize the NVM PHY type 2021 * @pi: port info structure 2022 * 2023 * Initialize nvm_phy_type_[low|high] for link lenient mode support 2024 */ 2025 static int ice_init_nvm_phy_type(struct ice_port_info *pi) 2026 { 2027 struct ice_aqc_get_phy_caps_data *pcaps; 2028 struct ice_pf *pf = pi->hw->back; 2029 int err; 2030 2031 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 2032 if (!pcaps) 2033 return -ENOMEM; 2034 2035 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA, 2036 pcaps, NULL); 2037 2038 if (err) { 2039 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); 2040 goto out; 2041 } 2042 2043 pf->nvm_phy_type_hi = pcaps->phy_type_high; 2044 pf->nvm_phy_type_lo = pcaps->phy_type_low; 2045 2046 out: 2047 kfree(pcaps); 2048 return err; 2049 } 2050 2051 /** 2052 * ice_init_link_dflt_override - Initialize link default override 2053 * @pi: port info structure 2054 * 2055 * Initialize link default override and PHY total port shutdown during probe 2056 */ 2057 static void ice_init_link_dflt_override(struct ice_port_info *pi) 2058 { 2059 struct ice_link_default_override_tlv *ldo; 2060 struct ice_pf *pf = pi->hw->back; 2061 2062 ldo = &pf->link_dflt_override; 2063 if (ice_get_link_default_override(ldo, pi)) 2064 return; 2065 2066 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS)) 2067 return; 2068 2069 /* Enable Total Port Shutdown (override/replace link-down-on-close 2070 * ethtool private flag) for ports with Port Disable bit set. 2071 */ 2072 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags); 2073 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags); 2074 } 2075 2076 /** 2077 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings 2078 * @pi: port info structure 2079 * 2080 * If default override is enabled, initialize the user PHY cfg speed and FEC 2081 * settings using the default override mask from the NVM. 2082 * 2083 * The PHY should only be configured with the default override settings the 2084 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state 2085 * is used to indicate that the user PHY cfg default override is initialized 2086 * and the PHY has not been configured with the default override settings. The 2087 * state is set here, and cleared in ice_configure_phy the first time the PHY is 2088 * configured. 2089 * 2090 * This function should be called only if the FW doesn't support default 2091 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg. 2092 */ 2093 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi) 2094 { 2095 struct ice_link_default_override_tlv *ldo; 2096 struct ice_aqc_set_phy_cfg_data *cfg; 2097 struct ice_phy_info *phy = &pi->phy; 2098 struct ice_pf *pf = pi->hw->back; 2099 2100 ldo = &pf->link_dflt_override; 2101 2102 /* If link default override is enabled, use to mask NVM PHY capabilities 2103 * for speed and FEC default configuration. 2104 */ 2105 cfg = &phy->curr_user_phy_cfg; 2106 2107 if (ldo->phy_type_low || ldo->phy_type_high) { 2108 cfg->phy_type_low = pf->nvm_phy_type_lo & 2109 cpu_to_le64(ldo->phy_type_low); 2110 cfg->phy_type_high = pf->nvm_phy_type_hi & 2111 cpu_to_le64(ldo->phy_type_high); 2112 } 2113 cfg->link_fec_opt = ldo->fec_options; 2114 phy->curr_user_fec_req = ICE_FEC_AUTO; 2115 2116 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state); 2117 } 2118 2119 /** 2120 * ice_init_phy_user_cfg - Initialize the PHY user configuration 2121 * @pi: port info structure 2122 * 2123 * Initialize the current user PHY configuration, speed, FEC, and FC requested 2124 * mode to default. The PHY defaults are from get PHY capabilities topology 2125 * with media so call when media is first available. An error is returned if 2126 * called when media is not available. The PHY initialization completed state is 2127 * set here. 2128 * 2129 * These configurations are used when setting PHY 2130 * configuration. The user PHY configuration is updated on set PHY 2131 * configuration. Returns 0 on success, negative on failure 2132 */ 2133 static int ice_init_phy_user_cfg(struct ice_port_info *pi) 2134 { 2135 struct ice_aqc_get_phy_caps_data *pcaps; 2136 struct ice_phy_info *phy = &pi->phy; 2137 struct ice_pf *pf = pi->hw->back; 2138 int err; 2139 2140 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) 2141 return -EIO; 2142 2143 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 2144 if (!pcaps) 2145 return -ENOMEM; 2146 2147 if (ice_fw_supports_report_dflt_cfg(pi->hw)) 2148 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG, 2149 pcaps, NULL); 2150 else 2151 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, 2152 pcaps, NULL); 2153 if (err) { 2154 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); 2155 goto err_out; 2156 } 2157 2158 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg); 2159 2160 /* check if lenient mode is supported and enabled */ 2161 if (ice_fw_supports_link_override(pi->hw) && 2162 !(pcaps->module_compliance_enforcement & 2163 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) { 2164 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags); 2165 2166 /* if the FW supports default PHY configuration mode, then the driver 2167 * does not have to apply link override settings. If not, 2168 * initialize user PHY configuration with link override values 2169 */ 2170 if (!ice_fw_supports_report_dflt_cfg(pi->hw) && 2171 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) { 2172 ice_init_phy_cfg_dflt_override(pi); 2173 goto out; 2174 } 2175 } 2176 2177 /* if link default override is not enabled, set user flow control and 2178 * FEC settings based on what get_phy_caps returned 2179 */ 2180 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps, 2181 pcaps->link_fec_options); 2182 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps); 2183 2184 out: 2185 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M; 2186 set_bit(ICE_PHY_INIT_COMPLETE, pf->state); 2187 err_out: 2188 kfree(pcaps); 2189 return err; 2190 } 2191 2192 /** 2193 * ice_configure_phy - configure PHY 2194 * @vsi: VSI of PHY 2195 * 2196 * Set the PHY configuration. If the current PHY configuration is the same as 2197 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise 2198 * configure the based get PHY capabilities for topology with media. 2199 */ 2200 static int ice_configure_phy(struct ice_vsi *vsi) 2201 { 2202 struct device *dev = ice_pf_to_dev(vsi->back); 2203 struct ice_port_info *pi = vsi->port_info; 2204 struct ice_aqc_get_phy_caps_data *pcaps; 2205 struct ice_aqc_set_phy_cfg_data *cfg; 2206 struct ice_phy_info *phy = &pi->phy; 2207 struct ice_pf *pf = vsi->back; 2208 int err; 2209 2210 /* Ensure we have media as we cannot configure a medialess port */ 2211 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) 2212 return -ENOMEDIUM; 2213 2214 ice_print_topo_conflict(vsi); 2215 2216 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags) && 2217 phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA) 2218 return -EPERM; 2219 2220 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) 2221 return ice_force_phys_link_state(vsi, true); 2222 2223 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); 2224 if (!pcaps) 2225 return -ENOMEM; 2226 2227 /* Get current PHY config */ 2228 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, 2229 NULL); 2230 if (err) { 2231 dev_err(dev, "Failed to get PHY configuration, VSI %d error %d\n", 2232 vsi->vsi_num, err); 2233 goto done; 2234 } 2235 2236 /* If PHY enable link is configured and configuration has not changed, 2237 * there's nothing to do 2238 */ 2239 if (pcaps->caps & ICE_AQC_PHY_EN_LINK && 2240 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg)) 2241 goto done; 2242 2243 /* Use PHY topology as baseline for configuration */ 2244 memset(pcaps, 0, sizeof(*pcaps)); 2245 if (ice_fw_supports_report_dflt_cfg(pi->hw)) 2246 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG, 2247 pcaps, NULL); 2248 else 2249 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, 2250 pcaps, NULL); 2251 if (err) { 2252 dev_err(dev, "Failed to get PHY caps, VSI %d error %d\n", 2253 vsi->vsi_num, err); 2254 goto done; 2255 } 2256 2257 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); 2258 if (!cfg) { 2259 err = -ENOMEM; 2260 goto done; 2261 } 2262 2263 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg); 2264 2265 /* Speed - If default override pending, use curr_user_phy_cfg set in 2266 * ice_init_phy_user_cfg_ldo. 2267 */ 2268 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, 2269 vsi->back->state)) { 2270 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low; 2271 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high; 2272 } else { 2273 u64 phy_low = 0, phy_high = 0; 2274 2275 ice_update_phy_type(&phy_low, &phy_high, 2276 pi->phy.curr_user_speed_req); 2277 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low); 2278 cfg->phy_type_high = pcaps->phy_type_high & 2279 cpu_to_le64(phy_high); 2280 } 2281 2282 /* Can't provide what was requested; use PHY capabilities */ 2283 if (!cfg->phy_type_low && !cfg->phy_type_high) { 2284 cfg->phy_type_low = pcaps->phy_type_low; 2285 cfg->phy_type_high = pcaps->phy_type_high; 2286 } 2287 2288 /* FEC */ 2289 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req); 2290 2291 /* Can't provide what was requested; use PHY capabilities */ 2292 if (cfg->link_fec_opt != 2293 (cfg->link_fec_opt & pcaps->link_fec_options)) { 2294 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC; 2295 cfg->link_fec_opt = pcaps->link_fec_options; 2296 } 2297 2298 /* Flow Control - always supported; no need to check against 2299 * capabilities 2300 */ 2301 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req); 2302 2303 /* Enable link and link update */ 2304 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK; 2305 2306 err = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL); 2307 if (err) 2308 dev_err(dev, "Failed to set phy config, VSI %d error %d\n", 2309 vsi->vsi_num, err); 2310 2311 kfree(cfg); 2312 done: 2313 kfree(pcaps); 2314 return err; 2315 } 2316 2317 /** 2318 * ice_check_media_subtask - Check for media 2319 * @pf: pointer to PF struct 2320 * 2321 * If media is available, then initialize PHY user configuration if it is not 2322 * been, and configure the PHY if the interface is up. 2323 */ 2324 static void ice_check_media_subtask(struct ice_pf *pf) 2325 { 2326 struct ice_port_info *pi; 2327 struct ice_vsi *vsi; 2328 int err; 2329 2330 /* No need to check for media if it's already present */ 2331 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags)) 2332 return; 2333 2334 vsi = ice_get_main_vsi(pf); 2335 if (!vsi) 2336 return; 2337 2338 /* Refresh link info and check if media is present */ 2339 pi = vsi->port_info; 2340 err = ice_update_link_info(pi); 2341 if (err) 2342 return; 2343 2344 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err); 2345 2346 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { 2347 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) 2348 ice_init_phy_user_cfg(pi); 2349 2350 /* PHY settings are reset on media insertion, reconfigure 2351 * PHY to preserve settings. 2352 */ 2353 if (test_bit(ICE_VSI_DOWN, vsi->state) && 2354 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) 2355 return; 2356 2357 err = ice_configure_phy(vsi); 2358 if (!err) 2359 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags); 2360 2361 /* A Link Status Event will be generated; the event handler 2362 * will complete bringing the interface up 2363 */ 2364 } 2365 } 2366 2367 static void ice_service_task_recovery_mode(struct work_struct *work) 2368 { 2369 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task); 2370 2371 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state); 2372 ice_clean_adminq_subtask(pf); 2373 2374 ice_service_task_complete(pf); 2375 2376 mod_timer(&pf->serv_tmr, jiffies + msecs_to_jiffies(100)); 2377 } 2378 2379 /** 2380 * ice_service_task - manage and run subtasks 2381 * @work: pointer to work_struct contained by the PF struct 2382 */ 2383 static void ice_service_task(struct work_struct *work) 2384 { 2385 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task); 2386 unsigned long start_time = jiffies; 2387 2388 if (pf->health_reporters.tx_hang_buf.tx_ring) { 2389 ice_report_tx_hang(pf); 2390 pf->health_reporters.tx_hang_buf.tx_ring = NULL; 2391 } 2392 2393 ice_reset_subtask(pf); 2394 2395 /* bail if a reset/recovery cycle is pending or rebuild failed */ 2396 if (ice_is_reset_in_progress(pf->state) || 2397 test_bit(ICE_SUSPENDED, pf->state) || 2398 test_bit(ICE_NEEDS_RESTART, pf->state)) { 2399 ice_service_task_complete(pf); 2400 return; 2401 } 2402 2403 if (test_and_clear_bit(ICE_AUX_ERR_PENDING, pf->state)) { 2404 struct iidc_event *event; 2405 2406 event = kzalloc(sizeof(*event), GFP_KERNEL); 2407 if (event) { 2408 set_bit(IIDC_EVENT_CRIT_ERR, event->type); 2409 /* report the entire OICR value to AUX driver */ 2410 swap(event->reg, pf->oicr_err_reg); 2411 ice_send_event_to_aux(pf, event); 2412 kfree(event); 2413 } 2414 } 2415 2416 /* unplug aux dev per request, if an unplug request came in 2417 * while processing a plug request, this will handle it 2418 */ 2419 if (test_and_clear_bit(ICE_FLAG_UNPLUG_AUX_DEV, pf->flags)) 2420 ice_unplug_aux_dev(pf); 2421 2422 /* Plug aux device per request */ 2423 if (test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags)) 2424 ice_plug_aux_dev(pf); 2425 2426 if (test_and_clear_bit(ICE_FLAG_MTU_CHANGED, pf->flags)) { 2427 struct iidc_event *event; 2428 2429 event = kzalloc(sizeof(*event), GFP_KERNEL); 2430 if (event) { 2431 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type); 2432 ice_send_event_to_aux(pf, event); 2433 kfree(event); 2434 } 2435 } 2436 2437 ice_clean_adminq_subtask(pf); 2438 ice_check_media_subtask(pf); 2439 ice_check_for_hang_subtask(pf); 2440 ice_sync_fltr_subtask(pf); 2441 ice_handle_mdd_event(pf); 2442 ice_watchdog_subtask(pf); 2443 2444 if (ice_is_safe_mode(pf)) { 2445 ice_service_task_complete(pf); 2446 return; 2447 } 2448 2449 ice_process_vflr_event(pf); 2450 ice_clean_mailboxq_subtask(pf); 2451 ice_clean_sbq_subtask(pf); 2452 ice_sync_arfs_fltrs(pf); 2453 ice_flush_fdir_ctx(pf); 2454 2455 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */ 2456 ice_service_task_complete(pf); 2457 2458 /* If the tasks have taken longer than one service timer period 2459 * or there is more work to be done, reset the service timer to 2460 * schedule the service task now. 2461 */ 2462 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) || 2463 test_bit(ICE_MDD_EVENT_PENDING, pf->state) || 2464 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) || 2465 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) || 2466 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) || 2467 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) || 2468 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state)) 2469 mod_timer(&pf->serv_tmr, jiffies); 2470 } 2471 2472 /** 2473 * ice_set_ctrlq_len - helper function to set controlq length 2474 * @hw: pointer to the HW instance 2475 */ 2476 static void ice_set_ctrlq_len(struct ice_hw *hw) 2477 { 2478 hw->adminq.num_rq_entries = ICE_AQ_LEN; 2479 hw->adminq.num_sq_entries = ICE_AQ_LEN; 2480 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN; 2481 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN; 2482 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M; 2483 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN; 2484 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN; 2485 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN; 2486 hw->sbq.num_rq_entries = ICE_SBQ_LEN; 2487 hw->sbq.num_sq_entries = ICE_SBQ_LEN; 2488 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN; 2489 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN; 2490 } 2491 2492 /** 2493 * ice_schedule_reset - schedule a reset 2494 * @pf: board private structure 2495 * @reset: reset being requested 2496 */ 2497 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset) 2498 { 2499 struct device *dev = ice_pf_to_dev(pf); 2500 2501 /* bail out if earlier reset has failed */ 2502 if (test_bit(ICE_RESET_FAILED, pf->state)) { 2503 dev_dbg(dev, "earlier reset has failed\n"); 2504 return -EIO; 2505 } 2506 /* bail if reset/recovery already in progress */ 2507 if (ice_is_reset_in_progress(pf->state)) { 2508 dev_dbg(dev, "Reset already in progress\n"); 2509 return -EBUSY; 2510 } 2511 2512 switch (reset) { 2513 case ICE_RESET_PFR: 2514 set_bit(ICE_PFR_REQ, pf->state); 2515 break; 2516 case ICE_RESET_CORER: 2517 set_bit(ICE_CORER_REQ, pf->state); 2518 break; 2519 case ICE_RESET_GLOBR: 2520 set_bit(ICE_GLOBR_REQ, pf->state); 2521 break; 2522 default: 2523 return -EINVAL; 2524 } 2525 2526 ice_service_task_schedule(pf); 2527 return 0; 2528 } 2529 2530 /** 2531 * ice_vsi_ena_irq - Enable IRQ for the given VSI 2532 * @vsi: the VSI being configured 2533 */ 2534 static int ice_vsi_ena_irq(struct ice_vsi *vsi) 2535 { 2536 struct ice_hw *hw = &vsi->back->hw; 2537 int i; 2538 2539 ice_for_each_q_vector(vsi, i) 2540 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]); 2541 2542 ice_flush(hw); 2543 return 0; 2544 } 2545 2546 /** 2547 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI 2548 * @vsi: the VSI being configured 2549 * @basename: name for the vector 2550 */ 2551 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename) 2552 { 2553 int q_vectors = vsi->num_q_vectors; 2554 struct ice_pf *pf = vsi->back; 2555 struct device *dev; 2556 int rx_int_idx = 0; 2557 int tx_int_idx = 0; 2558 int vector, err; 2559 int irq_num; 2560 2561 dev = ice_pf_to_dev(pf); 2562 for (vector = 0; vector < q_vectors; vector++) { 2563 struct ice_q_vector *q_vector = vsi->q_vectors[vector]; 2564 2565 irq_num = q_vector->irq.virq; 2566 2567 if (q_vector->tx.tx_ring && q_vector->rx.rx_ring) { 2568 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2569 "%s-%s-%d", basename, "TxRx", rx_int_idx++); 2570 tx_int_idx++; 2571 } else if (q_vector->rx.rx_ring) { 2572 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2573 "%s-%s-%d", basename, "rx", rx_int_idx++); 2574 } else if (q_vector->tx.tx_ring) { 2575 snprintf(q_vector->name, sizeof(q_vector->name) - 1, 2576 "%s-%s-%d", basename, "tx", tx_int_idx++); 2577 } else { 2578 /* skip this unused q_vector */ 2579 continue; 2580 } 2581 if (vsi->type == ICE_VSI_CTRL && vsi->vf) 2582 err = devm_request_irq(dev, irq_num, vsi->irq_handler, 2583 IRQF_SHARED, q_vector->name, 2584 q_vector); 2585 else 2586 err = devm_request_irq(dev, irq_num, vsi->irq_handler, 2587 0, q_vector->name, q_vector); 2588 if (err) { 2589 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n", 2590 err); 2591 goto free_q_irqs; 2592 } 2593 } 2594 2595 err = ice_set_cpu_rx_rmap(vsi); 2596 if (err) { 2597 netdev_err(vsi->netdev, "Failed to setup CPU RMAP on VSI %u: %pe\n", 2598 vsi->vsi_num, ERR_PTR(err)); 2599 goto free_q_irqs; 2600 } 2601 2602 vsi->irqs_ready = true; 2603 return 0; 2604 2605 free_q_irqs: 2606 while (vector--) { 2607 irq_num = vsi->q_vectors[vector]->irq.virq; 2608 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]); 2609 } 2610 return err; 2611 } 2612 2613 /** 2614 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP 2615 * @vsi: VSI to setup Tx rings used by XDP 2616 * 2617 * Return 0 on success and negative value on error 2618 */ 2619 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi) 2620 { 2621 struct device *dev = ice_pf_to_dev(vsi->back); 2622 struct ice_tx_desc *tx_desc; 2623 int i, j; 2624 2625 ice_for_each_xdp_txq(vsi, i) { 2626 u16 xdp_q_idx = vsi->alloc_txq + i; 2627 struct ice_ring_stats *ring_stats; 2628 struct ice_tx_ring *xdp_ring; 2629 2630 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL); 2631 if (!xdp_ring) 2632 goto free_xdp_rings; 2633 2634 ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL); 2635 if (!ring_stats) { 2636 ice_free_tx_ring(xdp_ring); 2637 goto free_xdp_rings; 2638 } 2639 2640 xdp_ring->ring_stats = ring_stats; 2641 xdp_ring->q_index = xdp_q_idx; 2642 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx]; 2643 xdp_ring->vsi = vsi; 2644 xdp_ring->netdev = NULL; 2645 xdp_ring->dev = dev; 2646 xdp_ring->count = vsi->num_tx_desc; 2647 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring); 2648 if (ice_setup_tx_ring(xdp_ring)) 2649 goto free_xdp_rings; 2650 ice_set_ring_xdp(xdp_ring); 2651 spin_lock_init(&xdp_ring->tx_lock); 2652 for (j = 0; j < xdp_ring->count; j++) { 2653 tx_desc = ICE_TX_DESC(xdp_ring, j); 2654 tx_desc->cmd_type_offset_bsz = 0; 2655 } 2656 } 2657 2658 return 0; 2659 2660 free_xdp_rings: 2661 for (; i >= 0; i--) { 2662 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) { 2663 kfree_rcu(vsi->xdp_rings[i]->ring_stats, rcu); 2664 vsi->xdp_rings[i]->ring_stats = NULL; 2665 ice_free_tx_ring(vsi->xdp_rings[i]); 2666 } 2667 } 2668 return -ENOMEM; 2669 } 2670 2671 /** 2672 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI 2673 * @vsi: VSI to set the bpf prog on 2674 * @prog: the bpf prog pointer 2675 */ 2676 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog) 2677 { 2678 struct bpf_prog *old_prog; 2679 int i; 2680 2681 old_prog = xchg(&vsi->xdp_prog, prog); 2682 ice_for_each_rxq(vsi, i) 2683 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); 2684 2685 if (old_prog) 2686 bpf_prog_put(old_prog); 2687 } 2688 2689 static struct ice_tx_ring *ice_xdp_ring_from_qid(struct ice_vsi *vsi, int qid) 2690 { 2691 struct ice_q_vector *q_vector; 2692 struct ice_tx_ring *ring; 2693 2694 if (static_key_enabled(&ice_xdp_locking_key)) 2695 return vsi->xdp_rings[qid % vsi->num_xdp_txq]; 2696 2697 q_vector = vsi->rx_rings[qid]->q_vector; 2698 ice_for_each_tx_ring(ring, q_vector->tx) 2699 if (ice_ring_is_xdp(ring)) 2700 return ring; 2701 2702 return NULL; 2703 } 2704 2705 /** 2706 * ice_map_xdp_rings - Map XDP rings to interrupt vectors 2707 * @vsi: the VSI with XDP rings being configured 2708 * 2709 * Map XDP rings to interrupt vectors and perform the configuration steps 2710 * dependent on the mapping. 2711 */ 2712 void ice_map_xdp_rings(struct ice_vsi *vsi) 2713 { 2714 int xdp_rings_rem = vsi->num_xdp_txq; 2715 int v_idx, q_idx; 2716 2717 /* follow the logic from ice_vsi_map_rings_to_vectors */ 2718 ice_for_each_q_vector(vsi, v_idx) { 2719 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; 2720 int xdp_rings_per_v, q_id, q_base; 2721 2722 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem, 2723 vsi->num_q_vectors - v_idx); 2724 q_base = vsi->num_xdp_txq - xdp_rings_rem; 2725 2726 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) { 2727 struct ice_tx_ring *xdp_ring = vsi->xdp_rings[q_id]; 2728 2729 xdp_ring->q_vector = q_vector; 2730 xdp_ring->next = q_vector->tx.tx_ring; 2731 q_vector->tx.tx_ring = xdp_ring; 2732 } 2733 xdp_rings_rem -= xdp_rings_per_v; 2734 } 2735 2736 ice_for_each_rxq(vsi, q_idx) { 2737 vsi->rx_rings[q_idx]->xdp_ring = ice_xdp_ring_from_qid(vsi, 2738 q_idx); 2739 ice_tx_xsk_pool(vsi, q_idx); 2740 } 2741 } 2742 2743 /** 2744 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP 2745 * @vsi: VSI to bring up Tx rings used by XDP 2746 * @prog: bpf program that will be assigned to VSI 2747 * @cfg_type: create from scratch or restore the existing configuration 2748 * 2749 * Return 0 on success and negative value on error 2750 */ 2751 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog, 2752 enum ice_xdp_cfg cfg_type) 2753 { 2754 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 2755 struct ice_pf *pf = vsi->back; 2756 struct ice_qs_cfg xdp_qs_cfg = { 2757 .qs_mutex = &pf->avail_q_mutex, 2758 .pf_map = pf->avail_txqs, 2759 .pf_map_size = pf->max_pf_txqs, 2760 .q_count = vsi->num_xdp_txq, 2761 .scatter_count = ICE_MAX_SCATTER_TXQS, 2762 .vsi_map = vsi->txq_map, 2763 .vsi_map_offset = vsi->alloc_txq, 2764 .mapping_mode = ICE_VSI_MAP_CONTIG 2765 }; 2766 struct device *dev; 2767 int status, i; 2768 2769 dev = ice_pf_to_dev(pf); 2770 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq, 2771 sizeof(*vsi->xdp_rings), GFP_KERNEL); 2772 if (!vsi->xdp_rings) 2773 return -ENOMEM; 2774 2775 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode; 2776 if (__ice_vsi_get_qs(&xdp_qs_cfg)) 2777 goto err_map_xdp; 2778 2779 if (static_key_enabled(&ice_xdp_locking_key)) 2780 netdev_warn(vsi->netdev, 2781 "Could not allocate one XDP Tx ring per CPU, XDP_TX/XDP_REDIRECT actions will be slower\n"); 2782 2783 if (ice_xdp_alloc_setup_rings(vsi)) 2784 goto clear_xdp_rings; 2785 2786 /* omit the scheduler update if in reset path; XDP queues will be 2787 * taken into account at the end of ice_vsi_rebuild, where 2788 * ice_cfg_vsi_lan is being called 2789 */ 2790 if (cfg_type == ICE_XDP_CFG_PART) 2791 return 0; 2792 2793 ice_map_xdp_rings(vsi); 2794 2795 /* tell the Tx scheduler that right now we have 2796 * additional queues 2797 */ 2798 for (i = 0; i < vsi->tc_cfg.numtc; i++) 2799 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq; 2800 2801 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2802 max_txqs); 2803 if (status) { 2804 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %d\n", 2805 status); 2806 goto clear_xdp_rings; 2807 } 2808 2809 /* assign the prog only when it's not already present on VSI; 2810 * this flow is a subject of both ethtool -L and ndo_bpf flows; 2811 * VSI rebuild that happens under ethtool -L can expose us to 2812 * the bpf_prog refcount issues as we would be swapping same 2813 * bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put 2814 * on it as it would be treated as an 'old_prog'; for ndo_bpf 2815 * this is not harmful as dev_xdp_install bumps the refcount 2816 * before calling the op exposed by the driver; 2817 */ 2818 if (!ice_is_xdp_ena_vsi(vsi)) 2819 ice_vsi_assign_bpf_prog(vsi, prog); 2820 2821 return 0; 2822 clear_xdp_rings: 2823 ice_for_each_xdp_txq(vsi, i) 2824 if (vsi->xdp_rings[i]) { 2825 kfree_rcu(vsi->xdp_rings[i], rcu); 2826 vsi->xdp_rings[i] = NULL; 2827 } 2828 2829 err_map_xdp: 2830 mutex_lock(&pf->avail_q_mutex); 2831 ice_for_each_xdp_txq(vsi, i) { 2832 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); 2833 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; 2834 } 2835 mutex_unlock(&pf->avail_q_mutex); 2836 2837 devm_kfree(dev, vsi->xdp_rings); 2838 return -ENOMEM; 2839 } 2840 2841 /** 2842 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings 2843 * @vsi: VSI to remove XDP rings 2844 * @cfg_type: disable XDP permanently or allow it to be restored later 2845 * 2846 * Detach XDP rings from irq vectors, clean up the PF bitmap and free 2847 * resources 2848 */ 2849 int ice_destroy_xdp_rings(struct ice_vsi *vsi, enum ice_xdp_cfg cfg_type) 2850 { 2851 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; 2852 struct ice_pf *pf = vsi->back; 2853 int i, v_idx; 2854 2855 /* q_vectors are freed in reset path so there's no point in detaching 2856 * rings 2857 */ 2858 if (cfg_type == ICE_XDP_CFG_PART) 2859 goto free_qmap; 2860 2861 ice_for_each_q_vector(vsi, v_idx) { 2862 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; 2863 struct ice_tx_ring *ring; 2864 2865 ice_for_each_tx_ring(ring, q_vector->tx) 2866 if (!ring->tx_buf || !ice_ring_is_xdp(ring)) 2867 break; 2868 2869 /* restore the value of last node prior to XDP setup */ 2870 q_vector->tx.tx_ring = ring; 2871 } 2872 2873 free_qmap: 2874 mutex_lock(&pf->avail_q_mutex); 2875 ice_for_each_xdp_txq(vsi, i) { 2876 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); 2877 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; 2878 } 2879 mutex_unlock(&pf->avail_q_mutex); 2880 2881 ice_for_each_xdp_txq(vsi, i) 2882 if (vsi->xdp_rings[i]) { 2883 if (vsi->xdp_rings[i]->desc) { 2884 synchronize_rcu(); 2885 ice_free_tx_ring(vsi->xdp_rings[i]); 2886 } 2887 kfree_rcu(vsi->xdp_rings[i]->ring_stats, rcu); 2888 vsi->xdp_rings[i]->ring_stats = NULL; 2889 kfree_rcu(vsi->xdp_rings[i], rcu); 2890 vsi->xdp_rings[i] = NULL; 2891 } 2892 2893 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings); 2894 vsi->xdp_rings = NULL; 2895 2896 if (static_key_enabled(&ice_xdp_locking_key)) 2897 static_branch_dec(&ice_xdp_locking_key); 2898 2899 if (cfg_type == ICE_XDP_CFG_PART) 2900 return 0; 2901 2902 ice_vsi_assign_bpf_prog(vsi, NULL); 2903 2904 /* notify Tx scheduler that we destroyed XDP queues and bring 2905 * back the old number of child nodes 2906 */ 2907 for (i = 0; i < vsi->tc_cfg.numtc; i++) 2908 max_txqs[i] = vsi->num_txq; 2909 2910 /* change number of XDP Tx queues to 0 */ 2911 vsi->num_xdp_txq = 0; 2912 2913 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, 2914 max_txqs); 2915 } 2916 2917 /** 2918 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI 2919 * @vsi: VSI to schedule napi on 2920 */ 2921 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi) 2922 { 2923 int i; 2924 2925 ice_for_each_rxq(vsi, i) { 2926 struct ice_rx_ring *rx_ring = vsi->rx_rings[i]; 2927 2928 if (READ_ONCE(rx_ring->xsk_pool)) 2929 napi_schedule(&rx_ring->q_vector->napi); 2930 } 2931 } 2932 2933 /** 2934 * ice_vsi_determine_xdp_res - figure out how many Tx qs can XDP have 2935 * @vsi: VSI to determine the count of XDP Tx qs 2936 * 2937 * returns 0 if Tx qs count is higher than at least half of CPU count, 2938 * -ENOMEM otherwise 2939 */ 2940 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi) 2941 { 2942 u16 avail = ice_get_avail_txq_count(vsi->back); 2943 u16 cpus = num_possible_cpus(); 2944 2945 if (avail < cpus / 2) 2946 return -ENOMEM; 2947 2948 if (vsi->type == ICE_VSI_SF) 2949 avail = vsi->alloc_txq; 2950 2951 vsi->num_xdp_txq = min_t(u16, avail, cpus); 2952 2953 if (vsi->num_xdp_txq < cpus) 2954 static_branch_inc(&ice_xdp_locking_key); 2955 2956 return 0; 2957 } 2958 2959 /** 2960 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP 2961 * @vsi: Pointer to VSI structure 2962 */ 2963 static int ice_max_xdp_frame_size(struct ice_vsi *vsi) 2964 { 2965 if (test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) 2966 return ICE_RXBUF_1664; 2967 else 2968 return ICE_RXBUF_3072; 2969 } 2970 2971 /** 2972 * ice_xdp_setup_prog - Add or remove XDP eBPF program 2973 * @vsi: VSI to setup XDP for 2974 * @prog: XDP program 2975 * @extack: netlink extended ack 2976 */ 2977 static int 2978 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog, 2979 struct netlink_ext_ack *extack) 2980 { 2981 unsigned int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD; 2982 int ret = 0, xdp_ring_err = 0; 2983 bool if_running; 2984 2985 if (prog && !prog->aux->xdp_has_frags) { 2986 if (frame_size > ice_max_xdp_frame_size(vsi)) { 2987 NL_SET_ERR_MSG_MOD(extack, 2988 "MTU is too large for linear frames and XDP prog does not support frags"); 2989 return -EOPNOTSUPP; 2990 } 2991 } 2992 2993 /* hot swap progs and avoid toggling link */ 2994 if (ice_is_xdp_ena_vsi(vsi) == !!prog || 2995 test_bit(ICE_VSI_REBUILD_PENDING, vsi->state)) { 2996 ice_vsi_assign_bpf_prog(vsi, prog); 2997 return 0; 2998 } 2999 3000 if_running = netif_running(vsi->netdev) && 3001 !test_and_set_bit(ICE_VSI_DOWN, vsi->state); 3002 3003 /* need to stop netdev while setting up the program for Rx rings */ 3004 if (if_running) { 3005 ret = ice_down(vsi); 3006 if (ret) { 3007 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed"); 3008 return ret; 3009 } 3010 } 3011 3012 if (!ice_is_xdp_ena_vsi(vsi) && prog) { 3013 xdp_ring_err = ice_vsi_determine_xdp_res(vsi); 3014 if (xdp_ring_err) { 3015 NL_SET_ERR_MSG_MOD(extack, "Not enough Tx resources for XDP"); 3016 } else { 3017 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog, 3018 ICE_XDP_CFG_FULL); 3019 if (xdp_ring_err) 3020 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed"); 3021 } 3022 xdp_features_set_redirect_target(vsi->netdev, true); 3023 /* reallocate Rx queues that are used for zero-copy */ 3024 xdp_ring_err = ice_realloc_zc_buf(vsi, true); 3025 if (xdp_ring_err) 3026 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Rx resources failed"); 3027 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) { 3028 xdp_features_clear_redirect_target(vsi->netdev); 3029 xdp_ring_err = ice_destroy_xdp_rings(vsi, ICE_XDP_CFG_FULL); 3030 if (xdp_ring_err) 3031 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed"); 3032 /* reallocate Rx queues that were used for zero-copy */ 3033 xdp_ring_err = ice_realloc_zc_buf(vsi, false); 3034 if (xdp_ring_err) 3035 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Rx resources failed"); 3036 } 3037 3038 if (if_running) 3039 ret = ice_up(vsi); 3040 3041 if (!ret && prog) 3042 ice_vsi_rx_napi_schedule(vsi); 3043 3044 return (ret || xdp_ring_err) ? -ENOMEM : 0; 3045 } 3046 3047 /** 3048 * ice_xdp_safe_mode - XDP handler for safe mode 3049 * @dev: netdevice 3050 * @xdp: XDP command 3051 */ 3052 static int ice_xdp_safe_mode(struct net_device __always_unused *dev, 3053 struct netdev_bpf *xdp) 3054 { 3055 NL_SET_ERR_MSG_MOD(xdp->extack, 3056 "Please provide working DDP firmware package in order to use XDP\n" 3057 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst"); 3058 return -EOPNOTSUPP; 3059 } 3060 3061 /** 3062 * ice_xdp - implements XDP handler 3063 * @dev: netdevice 3064 * @xdp: XDP command 3065 */ 3066 int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp) 3067 { 3068 struct ice_netdev_priv *np = netdev_priv(dev); 3069 struct ice_vsi *vsi = np->vsi; 3070 int ret; 3071 3072 if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_SF) { 3073 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF or SF VSI"); 3074 return -EINVAL; 3075 } 3076 3077 mutex_lock(&vsi->xdp_state_lock); 3078 3079 switch (xdp->command) { 3080 case XDP_SETUP_PROG: 3081 ret = ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack); 3082 break; 3083 case XDP_SETUP_XSK_POOL: 3084 ret = ice_xsk_pool_setup(vsi, xdp->xsk.pool, xdp->xsk.queue_id); 3085 break; 3086 default: 3087 ret = -EINVAL; 3088 } 3089 3090 mutex_unlock(&vsi->xdp_state_lock); 3091 return ret; 3092 } 3093 3094 /** 3095 * ice_ena_misc_vector - enable the non-queue interrupts 3096 * @pf: board private structure 3097 */ 3098 static void ice_ena_misc_vector(struct ice_pf *pf) 3099 { 3100 struct ice_hw *hw = &pf->hw; 3101 u32 pf_intr_start_offset; 3102 u32 val; 3103 3104 /* Disable anti-spoof detection interrupt to prevent spurious event 3105 * interrupts during a function reset. Anti-spoof functionally is 3106 * still supported. 3107 */ 3108 val = rd32(hw, GL_MDCK_TX_TDPU); 3109 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M; 3110 wr32(hw, GL_MDCK_TX_TDPU, val); 3111 3112 /* clear things first */ 3113 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */ 3114 rd32(hw, PFINT_OICR); /* read to clear */ 3115 3116 val = (PFINT_OICR_ECC_ERR_M | 3117 PFINT_OICR_MAL_DETECT_M | 3118 PFINT_OICR_GRST_M | 3119 PFINT_OICR_PCI_EXCEPTION_M | 3120 PFINT_OICR_VFLR_M | 3121 PFINT_OICR_HMC_ERR_M | 3122 PFINT_OICR_PE_PUSH_M | 3123 PFINT_OICR_PE_CRITERR_M); 3124 3125 wr32(hw, PFINT_OICR_ENA, val); 3126 3127 /* SW_ITR_IDX = 0, but don't change INTENA */ 3128 wr32(hw, GLINT_DYN_CTL(pf->oicr_irq.index), 3129 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M); 3130 3131 if (!pf->hw.dev_caps.ts_dev_info.ts_ll_int_read) 3132 return; 3133 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST; 3134 wr32(hw, GLINT_DYN_CTL(pf->ll_ts_irq.index + pf_intr_start_offset), 3135 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M); 3136 } 3137 3138 /** 3139 * ice_ll_ts_intr - ll_ts interrupt handler 3140 * @irq: interrupt number 3141 * @data: pointer to a q_vector 3142 */ 3143 static irqreturn_t ice_ll_ts_intr(int __always_unused irq, void *data) 3144 { 3145 struct ice_pf *pf = data; 3146 u32 pf_intr_start_offset; 3147 struct ice_ptp_tx *tx; 3148 unsigned long flags; 3149 struct ice_hw *hw; 3150 u32 val; 3151 u8 idx; 3152 3153 hw = &pf->hw; 3154 tx = &pf->ptp.port.tx; 3155 spin_lock_irqsave(&tx->lock, flags); 3156 ice_ptp_complete_tx_single_tstamp(tx); 3157 3158 idx = find_next_bit_wrap(tx->in_use, tx->len, 3159 tx->last_ll_ts_idx_read + 1); 3160 if (idx != tx->len) 3161 ice_ptp_req_tx_single_tstamp(tx, idx); 3162 spin_unlock_irqrestore(&tx->lock, flags); 3163 3164 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M | 3165 (ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S); 3166 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST; 3167 wr32(hw, GLINT_DYN_CTL(pf->ll_ts_irq.index + pf_intr_start_offset), 3168 val); 3169 3170 return IRQ_HANDLED; 3171 } 3172 3173 /** 3174 * ice_misc_intr - misc interrupt handler 3175 * @irq: interrupt number 3176 * @data: pointer to a q_vector 3177 */ 3178 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) 3179 { 3180 struct ice_pf *pf = (struct ice_pf *)data; 3181 irqreturn_t ret = IRQ_HANDLED; 3182 struct ice_hw *hw = &pf->hw; 3183 struct device *dev; 3184 u32 oicr, ena_mask; 3185 3186 dev = ice_pf_to_dev(pf); 3187 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state); 3188 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state); 3189 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); 3190 3191 oicr = rd32(hw, PFINT_OICR); 3192 ena_mask = rd32(hw, PFINT_OICR_ENA); 3193 3194 if (oicr & PFINT_OICR_SWINT_M) { 3195 ena_mask &= ~PFINT_OICR_SWINT_M; 3196 pf->sw_int_count++; 3197 } 3198 3199 if (oicr & PFINT_OICR_MAL_DETECT_M) { 3200 ena_mask &= ~PFINT_OICR_MAL_DETECT_M; 3201 set_bit(ICE_MDD_EVENT_PENDING, pf->state); 3202 } 3203 if (oicr & PFINT_OICR_VFLR_M) { 3204 /* disable any further VFLR event notifications */ 3205 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) { 3206 u32 reg = rd32(hw, PFINT_OICR_ENA); 3207 3208 reg &= ~PFINT_OICR_VFLR_M; 3209 wr32(hw, PFINT_OICR_ENA, reg); 3210 } else { 3211 ena_mask &= ~PFINT_OICR_VFLR_M; 3212 set_bit(ICE_VFLR_EVENT_PENDING, pf->state); 3213 } 3214 } 3215 3216 if (oicr & PFINT_OICR_GRST_M) { 3217 u32 reset; 3218 3219 /* we have a reset warning */ 3220 ena_mask &= ~PFINT_OICR_GRST_M; 3221 reset = FIELD_GET(GLGEN_RSTAT_RESET_TYPE_M, 3222 rd32(hw, GLGEN_RSTAT)); 3223 3224 if (reset == ICE_RESET_CORER) 3225 pf->corer_count++; 3226 else if (reset == ICE_RESET_GLOBR) 3227 pf->globr_count++; 3228 else if (reset == ICE_RESET_EMPR) 3229 pf->empr_count++; 3230 else 3231 dev_dbg(dev, "Invalid reset type %d\n", reset); 3232 3233 /* If a reset cycle isn't already in progress, we set a bit in 3234 * pf->state so that the service task can start a reset/rebuild. 3235 */ 3236 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) { 3237 if (reset == ICE_RESET_CORER) 3238 set_bit(ICE_CORER_RECV, pf->state); 3239 else if (reset == ICE_RESET_GLOBR) 3240 set_bit(ICE_GLOBR_RECV, pf->state); 3241 else 3242 set_bit(ICE_EMPR_RECV, pf->state); 3243 3244 /* There are couple of different bits at play here. 3245 * hw->reset_ongoing indicates whether the hardware is 3246 * in reset. This is set to true when a reset interrupt 3247 * is received and set back to false after the driver 3248 * has determined that the hardware is out of reset. 3249 * 3250 * ICE_RESET_OICR_RECV in pf->state indicates 3251 * that a post reset rebuild is required before the 3252 * driver is operational again. This is set above. 3253 * 3254 * As this is the start of the reset/rebuild cycle, set 3255 * both to indicate that. 3256 */ 3257 hw->reset_ongoing = true; 3258 } 3259 } 3260 3261 if (oicr & PFINT_OICR_TSYN_TX_M) { 3262 ena_mask &= ~PFINT_OICR_TSYN_TX_M; 3263 3264 ret = ice_ptp_ts_irq(pf); 3265 } 3266 3267 if (oicr & PFINT_OICR_TSYN_EVNT_M) { 3268 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; 3269 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx)); 3270 3271 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M; 3272 3273 if (ice_pf_src_tmr_owned(pf)) { 3274 /* Save EVENTs from GLTSYN register */ 3275 pf->ptp.ext_ts_irq |= gltsyn_stat & 3276 (GLTSYN_STAT_EVENT0_M | 3277 GLTSYN_STAT_EVENT1_M | 3278 GLTSYN_STAT_EVENT2_M); 3279 3280 ice_ptp_extts_event(pf); 3281 } 3282 } 3283 3284 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M) 3285 if (oicr & ICE_AUX_CRIT_ERR) { 3286 pf->oicr_err_reg |= oicr; 3287 set_bit(ICE_AUX_ERR_PENDING, pf->state); 3288 ena_mask &= ~ICE_AUX_CRIT_ERR; 3289 } 3290 3291 /* Report any remaining unexpected interrupts */ 3292 oicr &= ena_mask; 3293 if (oicr) { 3294 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr); 3295 /* If a critical error is pending there is no choice but to 3296 * reset the device. 3297 */ 3298 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M | 3299 PFINT_OICR_ECC_ERR_M)) { 3300 set_bit(ICE_PFR_REQ, pf->state); 3301 } 3302 } 3303 ice_service_task_schedule(pf); 3304 if (ret == IRQ_HANDLED) 3305 ice_irq_dynamic_ena(hw, NULL, NULL); 3306 3307 return ret; 3308 } 3309 3310 /** 3311 * ice_misc_intr_thread_fn - misc interrupt thread function 3312 * @irq: interrupt number 3313 * @data: pointer to a q_vector 3314 */ 3315 static irqreturn_t ice_misc_intr_thread_fn(int __always_unused irq, void *data) 3316 { 3317 struct ice_pf *pf = data; 3318 struct ice_hw *hw; 3319 3320 hw = &pf->hw; 3321 3322 if (ice_is_reset_in_progress(pf->state)) 3323 goto skip_irq; 3324 3325 if (test_and_clear_bit(ICE_MISC_THREAD_TX_TSTAMP, pf->misc_thread)) { 3326 /* Process outstanding Tx timestamps. If there is more work, 3327 * re-arm the interrupt to trigger again. 3328 */ 3329 if (ice_ptp_process_ts(pf) == ICE_TX_TSTAMP_WORK_PENDING) { 3330 wr32(hw, PFINT_OICR, PFINT_OICR_TSYN_TX_M); 3331 ice_flush(hw); 3332 } 3333 } 3334 3335 skip_irq: 3336 ice_irq_dynamic_ena(hw, NULL, NULL); 3337 3338 return IRQ_HANDLED; 3339 } 3340 3341 /** 3342 * ice_dis_ctrlq_interrupts - disable control queue interrupts 3343 * @hw: pointer to HW structure 3344 */ 3345 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw) 3346 { 3347 /* disable Admin queue Interrupt causes */ 3348 wr32(hw, PFINT_FW_CTL, 3349 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M); 3350 3351 /* disable Mailbox queue Interrupt causes */ 3352 wr32(hw, PFINT_MBX_CTL, 3353 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M); 3354 3355 wr32(hw, PFINT_SB_CTL, 3356 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M); 3357 3358 /* disable Control queue Interrupt causes */ 3359 wr32(hw, PFINT_OICR_CTL, 3360 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M); 3361 3362 ice_flush(hw); 3363 } 3364 3365 /** 3366 * ice_free_irq_msix_ll_ts- Unroll ll_ts vector setup 3367 * @pf: board private structure 3368 */ 3369 static void ice_free_irq_msix_ll_ts(struct ice_pf *pf) 3370 { 3371 int irq_num = pf->ll_ts_irq.virq; 3372 3373 synchronize_irq(irq_num); 3374 devm_free_irq(ice_pf_to_dev(pf), irq_num, pf); 3375 3376 ice_free_irq(pf, pf->ll_ts_irq); 3377 } 3378 3379 /** 3380 * ice_free_irq_msix_misc - Unroll misc vector setup 3381 * @pf: board private structure 3382 */ 3383 static void ice_free_irq_msix_misc(struct ice_pf *pf) 3384 { 3385 int misc_irq_num = pf->oicr_irq.virq; 3386 struct ice_hw *hw = &pf->hw; 3387 3388 ice_dis_ctrlq_interrupts(hw); 3389 3390 /* disable OICR interrupt */ 3391 wr32(hw, PFINT_OICR_ENA, 0); 3392 ice_flush(hw); 3393 3394 synchronize_irq(misc_irq_num); 3395 devm_free_irq(ice_pf_to_dev(pf), misc_irq_num, pf); 3396 3397 ice_free_irq(pf, pf->oicr_irq); 3398 if (pf->hw.dev_caps.ts_dev_info.ts_ll_int_read) 3399 ice_free_irq_msix_ll_ts(pf); 3400 } 3401 3402 /** 3403 * ice_ena_ctrlq_interrupts - enable control queue interrupts 3404 * @hw: pointer to HW structure 3405 * @reg_idx: HW vector index to associate the control queue interrupts with 3406 */ 3407 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx) 3408 { 3409 u32 val; 3410 3411 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) | 3412 PFINT_OICR_CTL_CAUSE_ENA_M); 3413 wr32(hw, PFINT_OICR_CTL, val); 3414 3415 /* enable Admin queue Interrupt causes */ 3416 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) | 3417 PFINT_FW_CTL_CAUSE_ENA_M); 3418 wr32(hw, PFINT_FW_CTL, val); 3419 3420 /* enable Mailbox queue Interrupt causes */ 3421 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) | 3422 PFINT_MBX_CTL_CAUSE_ENA_M); 3423 wr32(hw, PFINT_MBX_CTL, val); 3424 3425 if (!hw->dev_caps.ts_dev_info.ts_ll_int_read) { 3426 /* enable Sideband queue Interrupt causes */ 3427 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) | 3428 PFINT_SB_CTL_CAUSE_ENA_M); 3429 wr32(hw, PFINT_SB_CTL, val); 3430 } 3431 3432 ice_flush(hw); 3433 } 3434 3435 /** 3436 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events 3437 * @pf: board private structure 3438 * 3439 * This sets up the handler for MSIX 0, which is used to manage the 3440 * non-queue interrupts, e.g. AdminQ and errors. This is not used 3441 * when in MSI or Legacy interrupt mode. 3442 */ 3443 static int ice_req_irq_msix_misc(struct ice_pf *pf) 3444 { 3445 struct device *dev = ice_pf_to_dev(pf); 3446 struct ice_hw *hw = &pf->hw; 3447 u32 pf_intr_start_offset; 3448 struct msi_map irq; 3449 int err = 0; 3450 3451 if (!pf->int_name[0]) 3452 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc", 3453 dev_driver_string(dev), dev_name(dev)); 3454 3455 if (!pf->int_name_ll_ts[0]) 3456 snprintf(pf->int_name_ll_ts, sizeof(pf->int_name_ll_ts) - 1, 3457 "%s-%s:ll_ts", dev_driver_string(dev), dev_name(dev)); 3458 /* Do not request IRQ but do enable OICR interrupt since settings are 3459 * lost during reset. Note that this function is called only during 3460 * rebuild path and not while reset is in progress. 3461 */ 3462 if (ice_is_reset_in_progress(pf->state)) 3463 goto skip_req_irq; 3464 3465 /* reserve one vector in irq_tracker for misc interrupts */ 3466 irq = ice_alloc_irq(pf, false); 3467 if (irq.index < 0) 3468 return irq.index; 3469 3470 pf->oicr_irq = irq; 3471 err = devm_request_threaded_irq(dev, pf->oicr_irq.virq, ice_misc_intr, 3472 ice_misc_intr_thread_fn, 0, 3473 pf->int_name, pf); 3474 if (err) { 3475 dev_err(dev, "devm_request_threaded_irq for %s failed: %d\n", 3476 pf->int_name, err); 3477 ice_free_irq(pf, pf->oicr_irq); 3478 return err; 3479 } 3480 3481 /* reserve one vector in irq_tracker for ll_ts interrupt */ 3482 if (!pf->hw.dev_caps.ts_dev_info.ts_ll_int_read) 3483 goto skip_req_irq; 3484 3485 irq = ice_alloc_irq(pf, false); 3486 if (irq.index < 0) 3487 return irq.index; 3488 3489 pf->ll_ts_irq = irq; 3490 err = devm_request_irq(dev, pf->ll_ts_irq.virq, ice_ll_ts_intr, 0, 3491 pf->int_name_ll_ts, pf); 3492 if (err) { 3493 dev_err(dev, "devm_request_irq for %s failed: %d\n", 3494 pf->int_name_ll_ts, err); 3495 ice_free_irq(pf, pf->ll_ts_irq); 3496 return err; 3497 } 3498 3499 skip_req_irq: 3500 ice_ena_misc_vector(pf); 3501 3502 ice_ena_ctrlq_interrupts(hw, pf->oicr_irq.index); 3503 /* This enables LL TS interrupt */ 3504 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST; 3505 if (pf->hw.dev_caps.ts_dev_info.ts_ll_int_read) 3506 wr32(hw, PFINT_SB_CTL, 3507 ((pf->ll_ts_irq.index + pf_intr_start_offset) & 3508 PFINT_SB_CTL_MSIX_INDX_M) | PFINT_SB_CTL_CAUSE_ENA_M); 3509 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_irq.index), 3510 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S); 3511 3512 ice_flush(hw); 3513 ice_irq_dynamic_ena(hw, NULL, NULL); 3514 3515 return 0; 3516 } 3517 3518 /** 3519 * ice_set_ops - set netdev and ethtools ops for the given netdev 3520 * @vsi: the VSI associated with the new netdev 3521 */ 3522 static void ice_set_ops(struct ice_vsi *vsi) 3523 { 3524 struct net_device *netdev = vsi->netdev; 3525 struct ice_pf *pf = ice_netdev_to_pf(netdev); 3526 3527 if (ice_is_safe_mode(pf)) { 3528 netdev->netdev_ops = &ice_netdev_safe_mode_ops; 3529 ice_set_ethtool_safe_mode_ops(netdev); 3530 return; 3531 } 3532 3533 netdev->netdev_ops = &ice_netdev_ops; 3534 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic; 3535 netdev->xdp_metadata_ops = &ice_xdp_md_ops; 3536 ice_set_ethtool_ops(netdev); 3537 3538 if (vsi->type != ICE_VSI_PF) 3539 return; 3540 3541 netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT | 3542 NETDEV_XDP_ACT_XSK_ZEROCOPY | 3543 NETDEV_XDP_ACT_RX_SG; 3544 netdev->xdp_zc_max_segs = ICE_MAX_BUF_TXD; 3545 } 3546 3547 /** 3548 * ice_set_netdev_features - set features for the given netdev 3549 * @netdev: netdev instance 3550 */ 3551 void ice_set_netdev_features(struct net_device *netdev) 3552 { 3553 struct ice_pf *pf = ice_netdev_to_pf(netdev); 3554 bool is_dvm_ena = ice_is_dvm_ena(&pf->hw); 3555 netdev_features_t csumo_features; 3556 netdev_features_t vlano_features; 3557 netdev_features_t dflt_features; 3558 netdev_features_t tso_features; 3559 3560 if (ice_is_safe_mode(pf)) { 3561 /* safe mode */ 3562 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA; 3563 netdev->hw_features = netdev->features; 3564 return; 3565 } 3566 3567 dflt_features = NETIF_F_SG | 3568 NETIF_F_HIGHDMA | 3569 NETIF_F_NTUPLE | 3570 NETIF_F_RXHASH; 3571 3572 csumo_features = NETIF_F_RXCSUM | 3573 NETIF_F_IP_CSUM | 3574 NETIF_F_SCTP_CRC | 3575 NETIF_F_IPV6_CSUM; 3576 3577 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER | 3578 NETIF_F_HW_VLAN_CTAG_TX | 3579 NETIF_F_HW_VLAN_CTAG_RX; 3580 3581 /* Enable CTAG/STAG filtering by default in Double VLAN Mode (DVM) */ 3582 if (is_dvm_ena) 3583 vlano_features |= NETIF_F_HW_VLAN_STAG_FILTER; 3584 3585 tso_features = NETIF_F_TSO | 3586 NETIF_F_TSO_ECN | 3587 NETIF_F_TSO6 | 3588 NETIF_F_GSO_GRE | 3589 NETIF_F_GSO_UDP_TUNNEL | 3590 NETIF_F_GSO_GRE_CSUM | 3591 NETIF_F_GSO_UDP_TUNNEL_CSUM | 3592 NETIF_F_GSO_PARTIAL | 3593 NETIF_F_GSO_IPXIP4 | 3594 NETIF_F_GSO_IPXIP6 | 3595 NETIF_F_GSO_UDP_L4; 3596 3597 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM | 3598 NETIF_F_GSO_GRE_CSUM; 3599 /* set features that user can change */ 3600 netdev->hw_features = dflt_features | csumo_features | 3601 vlano_features | tso_features; 3602 3603 /* add support for HW_CSUM on packets with MPLS header */ 3604 netdev->mpls_features = NETIF_F_HW_CSUM | 3605 NETIF_F_TSO | 3606 NETIF_F_TSO6; 3607 3608 /* enable features */ 3609 netdev->features |= netdev->hw_features; 3610 3611 netdev->hw_features |= NETIF_F_HW_TC; 3612 netdev->hw_features |= NETIF_F_LOOPBACK; 3613 3614 /* encap and VLAN devices inherit default, csumo and tso features */ 3615 netdev->hw_enc_features |= dflt_features | csumo_features | 3616 tso_features; 3617 netdev->vlan_features |= dflt_features | csumo_features | 3618 tso_features; 3619 3620 /* advertise support but don't enable by default since only one type of 3621 * VLAN offload can be enabled at a time (i.e. CTAG or STAG). When one 3622 * type turns on the other has to be turned off. This is enforced by the 3623 * ice_fix_features() ndo callback. 3624 */ 3625 if (is_dvm_ena) 3626 netdev->hw_features |= NETIF_F_HW_VLAN_STAG_RX | 3627 NETIF_F_HW_VLAN_STAG_TX; 3628 3629 /* Leave CRC / FCS stripping enabled by default, but allow the value to 3630 * be changed at runtime 3631 */ 3632 netdev->hw_features |= NETIF_F_RXFCS; 3633 3634 /* Allow core to manage IRQs affinity */ 3635 netif_set_affinity_auto(netdev); 3636 3637 netif_set_tso_max_size(netdev, ICE_MAX_TSO_SIZE); 3638 } 3639 3640 /** 3641 * ice_fill_rss_lut - Fill the RSS lookup table with default values 3642 * @lut: Lookup table 3643 * @rss_table_size: Lookup table size 3644 * @rss_size: Range of queue number for hashing 3645 */ 3646 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size) 3647 { 3648 u16 i; 3649 3650 for (i = 0; i < rss_table_size; i++) 3651 lut[i] = i % rss_size; 3652 } 3653 3654 /** 3655 * ice_pf_vsi_setup - Set up a PF VSI 3656 * @pf: board private structure 3657 * @pi: pointer to the port_info instance 3658 * 3659 * Returns pointer to the successfully allocated VSI software struct 3660 * on success, otherwise returns NULL on failure. 3661 */ 3662 static struct ice_vsi * 3663 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3664 { 3665 struct ice_vsi_cfg_params params = {}; 3666 3667 params.type = ICE_VSI_PF; 3668 params.port_info = pi; 3669 params.flags = ICE_VSI_FLAG_INIT; 3670 3671 return ice_vsi_setup(pf, ¶ms); 3672 } 3673 3674 static struct ice_vsi * 3675 ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, 3676 struct ice_channel *ch) 3677 { 3678 struct ice_vsi_cfg_params params = {}; 3679 3680 params.type = ICE_VSI_CHNL; 3681 params.port_info = pi; 3682 params.ch = ch; 3683 params.flags = ICE_VSI_FLAG_INIT; 3684 3685 return ice_vsi_setup(pf, ¶ms); 3686 } 3687 3688 /** 3689 * ice_ctrl_vsi_setup - Set up a control VSI 3690 * @pf: board private structure 3691 * @pi: pointer to the port_info instance 3692 * 3693 * Returns pointer to the successfully allocated VSI software struct 3694 * on success, otherwise returns NULL on failure. 3695 */ 3696 static struct ice_vsi * 3697 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3698 { 3699 struct ice_vsi_cfg_params params = {}; 3700 3701 params.type = ICE_VSI_CTRL; 3702 params.port_info = pi; 3703 params.flags = ICE_VSI_FLAG_INIT; 3704 3705 return ice_vsi_setup(pf, ¶ms); 3706 } 3707 3708 /** 3709 * ice_lb_vsi_setup - Set up a loopback VSI 3710 * @pf: board private structure 3711 * @pi: pointer to the port_info instance 3712 * 3713 * Returns pointer to the successfully allocated VSI software struct 3714 * on success, otherwise returns NULL on failure. 3715 */ 3716 struct ice_vsi * 3717 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi) 3718 { 3719 struct ice_vsi_cfg_params params = {}; 3720 3721 params.type = ICE_VSI_LB; 3722 params.port_info = pi; 3723 params.flags = ICE_VSI_FLAG_INIT; 3724 3725 return ice_vsi_setup(pf, ¶ms); 3726 } 3727 3728 /** 3729 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload 3730 * @netdev: network interface to be adjusted 3731 * @proto: VLAN TPID 3732 * @vid: VLAN ID to be added 3733 * 3734 * net_device_ops implementation for adding VLAN IDs 3735 */ 3736 int ice_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid) 3737 { 3738 struct ice_netdev_priv *np = netdev_priv(netdev); 3739 struct ice_vsi_vlan_ops *vlan_ops; 3740 struct ice_vsi *vsi = np->vsi; 3741 struct ice_vlan vlan; 3742 int ret; 3743 3744 /* VLAN 0 is added by default during load/reset */ 3745 if (!vid) 3746 return 0; 3747 3748 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state)) 3749 usleep_range(1000, 2000); 3750 3751 /* Add multicast promisc rule for the VLAN ID to be added if 3752 * all-multicast is currently enabled. 3753 */ 3754 if (vsi->current_netdev_flags & IFF_ALLMULTI) { 3755 ret = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, 3756 ICE_MCAST_VLAN_PROMISC_BITS, 3757 vid); 3758 if (ret) 3759 goto finish; 3760 } 3761 3762 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 3763 3764 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged 3765 * packets aren't pruned by the device's internal switch on Rx 3766 */ 3767 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0); 3768 ret = vlan_ops->add_vlan(vsi, &vlan); 3769 if (ret) 3770 goto finish; 3771 3772 /* If all-multicast is currently enabled and this VLAN ID is only one 3773 * besides VLAN-0 we have to update look-up type of multicast promisc 3774 * rule for VLAN-0 from ICE_SW_LKUP_PROMISC to ICE_SW_LKUP_PROMISC_VLAN. 3775 */ 3776 if ((vsi->current_netdev_flags & IFF_ALLMULTI) && 3777 ice_vsi_num_non_zero_vlans(vsi) == 1) { 3778 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, 3779 ICE_MCAST_PROMISC_BITS, 0); 3780 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, 3781 ICE_MCAST_VLAN_PROMISC_BITS, 0); 3782 } 3783 3784 finish: 3785 clear_bit(ICE_CFG_BUSY, vsi->state); 3786 3787 return ret; 3788 } 3789 3790 /** 3791 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload 3792 * @netdev: network interface to be adjusted 3793 * @proto: VLAN TPID 3794 * @vid: VLAN ID to be removed 3795 * 3796 * net_device_ops implementation for removing VLAN IDs 3797 */ 3798 int ice_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid) 3799 { 3800 struct ice_netdev_priv *np = netdev_priv(netdev); 3801 struct ice_vsi_vlan_ops *vlan_ops; 3802 struct ice_vsi *vsi = np->vsi; 3803 struct ice_vlan vlan; 3804 int ret; 3805 3806 /* don't allow removal of VLAN 0 */ 3807 if (!vid) 3808 return 0; 3809 3810 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state)) 3811 usleep_range(1000, 2000); 3812 3813 ret = ice_clear_vsi_promisc(&vsi->back->hw, vsi->idx, 3814 ICE_MCAST_VLAN_PROMISC_BITS, vid); 3815 if (ret) { 3816 netdev_err(netdev, "Error clearing multicast promiscuous mode on VSI %i\n", 3817 vsi->vsi_num); 3818 vsi->current_netdev_flags |= IFF_ALLMULTI; 3819 } 3820 3821 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 3822 3823 /* Make sure VLAN delete is successful before updating VLAN 3824 * information 3825 */ 3826 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0); 3827 ret = vlan_ops->del_vlan(vsi, &vlan); 3828 if (ret) 3829 goto finish; 3830 3831 /* Remove multicast promisc rule for the removed VLAN ID if 3832 * all-multicast is enabled. 3833 */ 3834 if (vsi->current_netdev_flags & IFF_ALLMULTI) 3835 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, 3836 ICE_MCAST_VLAN_PROMISC_BITS, vid); 3837 3838 if (!ice_vsi_has_non_zero_vlans(vsi)) { 3839 /* Update look-up type of multicast promisc rule for VLAN 0 3840 * from ICE_SW_LKUP_PROMISC_VLAN to ICE_SW_LKUP_PROMISC when 3841 * all-multicast is enabled and VLAN 0 is the only VLAN rule. 3842 */ 3843 if (vsi->current_netdev_flags & IFF_ALLMULTI) { 3844 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, 3845 ICE_MCAST_VLAN_PROMISC_BITS, 3846 0); 3847 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, 3848 ICE_MCAST_PROMISC_BITS, 0); 3849 } 3850 } 3851 3852 finish: 3853 clear_bit(ICE_CFG_BUSY, vsi->state); 3854 3855 return ret; 3856 } 3857 3858 /** 3859 * ice_rep_indr_tc_block_unbind 3860 * @cb_priv: indirection block private data 3861 */ 3862 static void ice_rep_indr_tc_block_unbind(void *cb_priv) 3863 { 3864 struct ice_indr_block_priv *indr_priv = cb_priv; 3865 3866 list_del(&indr_priv->list); 3867 kfree(indr_priv); 3868 } 3869 3870 /** 3871 * ice_tc_indir_block_unregister - Unregister TC indirect block notifications 3872 * @vsi: VSI struct which has the netdev 3873 */ 3874 static void ice_tc_indir_block_unregister(struct ice_vsi *vsi) 3875 { 3876 struct ice_netdev_priv *np = netdev_priv(vsi->netdev); 3877 3878 flow_indr_dev_unregister(ice_indr_setup_tc_cb, np, 3879 ice_rep_indr_tc_block_unbind); 3880 } 3881 3882 /** 3883 * ice_tc_indir_block_register - Register TC indirect block notifications 3884 * @vsi: VSI struct which has the netdev 3885 * 3886 * Returns 0 on success, negative value on failure 3887 */ 3888 static int ice_tc_indir_block_register(struct ice_vsi *vsi) 3889 { 3890 struct ice_netdev_priv *np; 3891 3892 if (!vsi || !vsi->netdev) 3893 return -EINVAL; 3894 3895 np = netdev_priv(vsi->netdev); 3896 3897 INIT_LIST_HEAD(&np->tc_indr_block_priv_list); 3898 return flow_indr_dev_register(ice_indr_setup_tc_cb, np); 3899 } 3900 3901 /** 3902 * ice_get_avail_q_count - Get count of queues in use 3903 * @pf_qmap: bitmap to get queue use count from 3904 * @lock: pointer to a mutex that protects access to pf_qmap 3905 * @size: size of the bitmap 3906 */ 3907 static u16 3908 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size) 3909 { 3910 unsigned long bit; 3911 u16 count = 0; 3912 3913 mutex_lock(lock); 3914 for_each_clear_bit(bit, pf_qmap, size) 3915 count++; 3916 mutex_unlock(lock); 3917 3918 return count; 3919 } 3920 3921 /** 3922 * ice_get_avail_txq_count - Get count of Tx queues in use 3923 * @pf: pointer to an ice_pf instance 3924 */ 3925 u16 ice_get_avail_txq_count(struct ice_pf *pf) 3926 { 3927 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex, 3928 pf->max_pf_txqs); 3929 } 3930 3931 /** 3932 * ice_get_avail_rxq_count - Get count of Rx queues in use 3933 * @pf: pointer to an ice_pf instance 3934 */ 3935 u16 ice_get_avail_rxq_count(struct ice_pf *pf) 3936 { 3937 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex, 3938 pf->max_pf_rxqs); 3939 } 3940 3941 /** 3942 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf 3943 * @pf: board private structure to initialize 3944 */ 3945 static void ice_deinit_pf(struct ice_pf *pf) 3946 { 3947 ice_service_task_stop(pf); 3948 mutex_destroy(&pf->lag_mutex); 3949 mutex_destroy(&pf->adev_mutex); 3950 mutex_destroy(&pf->sw_mutex); 3951 mutex_destroy(&pf->tc_mutex); 3952 mutex_destroy(&pf->avail_q_mutex); 3953 mutex_destroy(&pf->vfs.table_lock); 3954 3955 if (pf->avail_txqs) { 3956 bitmap_free(pf->avail_txqs); 3957 pf->avail_txqs = NULL; 3958 } 3959 3960 if (pf->avail_rxqs) { 3961 bitmap_free(pf->avail_rxqs); 3962 pf->avail_rxqs = NULL; 3963 } 3964 3965 if (pf->ptp.clock) 3966 ptp_clock_unregister(pf->ptp.clock); 3967 3968 xa_destroy(&pf->dyn_ports); 3969 xa_destroy(&pf->sf_nums); 3970 } 3971 3972 /** 3973 * ice_set_pf_caps - set PFs capability flags 3974 * @pf: pointer to the PF instance 3975 */ 3976 static void ice_set_pf_caps(struct ice_pf *pf) 3977 { 3978 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps; 3979 3980 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags); 3981 if (func_caps->common_cap.rdma) 3982 set_bit(ICE_FLAG_RDMA_ENA, pf->flags); 3983 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 3984 if (func_caps->common_cap.dcb) 3985 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 3986 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags); 3987 if (func_caps->common_cap.sr_iov_1_1) { 3988 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags); 3989 pf->vfs.num_supported = min_t(int, func_caps->num_allocd_vfs, 3990 ICE_MAX_SRIOV_VFS); 3991 } 3992 clear_bit(ICE_FLAG_RSS_ENA, pf->flags); 3993 if (func_caps->common_cap.rss_table_size) 3994 set_bit(ICE_FLAG_RSS_ENA, pf->flags); 3995 3996 clear_bit(ICE_FLAG_FD_ENA, pf->flags); 3997 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) { 3998 u16 unused; 3999 4000 /* ctrl_vsi_idx will be set to a valid value when flow director 4001 * is setup by ice_init_fdir 4002 */ 4003 pf->ctrl_vsi_idx = ICE_NO_VSI; 4004 set_bit(ICE_FLAG_FD_ENA, pf->flags); 4005 /* force guaranteed filter pool for PF */ 4006 ice_alloc_fd_guar_item(&pf->hw, &unused, 4007 func_caps->fd_fltr_guar); 4008 /* force shared filter pool for PF */ 4009 ice_alloc_fd_shrd_item(&pf->hw, &unused, 4010 func_caps->fd_fltr_best_effort); 4011 } 4012 4013 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags); 4014 if (func_caps->common_cap.ieee_1588) 4015 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags); 4016 4017 pf->max_pf_txqs = func_caps->common_cap.num_txq; 4018 pf->max_pf_rxqs = func_caps->common_cap.num_rxq; 4019 } 4020 4021 /** 4022 * ice_init_pf - Initialize general software structures (struct ice_pf) 4023 * @pf: board private structure to initialize 4024 */ 4025 static int ice_init_pf(struct ice_pf *pf) 4026 { 4027 ice_set_pf_caps(pf); 4028 4029 mutex_init(&pf->sw_mutex); 4030 mutex_init(&pf->tc_mutex); 4031 mutex_init(&pf->adev_mutex); 4032 mutex_init(&pf->lag_mutex); 4033 4034 INIT_HLIST_HEAD(&pf->aq_wait_list); 4035 spin_lock_init(&pf->aq_wait_lock); 4036 init_waitqueue_head(&pf->aq_wait_queue); 4037 4038 init_waitqueue_head(&pf->reset_wait_queue); 4039 4040 /* setup service timer and periodic service task */ 4041 timer_setup(&pf->serv_tmr, ice_service_timer, 0); 4042 pf->serv_tmr_period = HZ; 4043 INIT_WORK(&pf->serv_task, ice_service_task); 4044 clear_bit(ICE_SERVICE_SCHED, pf->state); 4045 4046 mutex_init(&pf->avail_q_mutex); 4047 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL); 4048 if (!pf->avail_txqs) 4049 return -ENOMEM; 4050 4051 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL); 4052 if (!pf->avail_rxqs) { 4053 bitmap_free(pf->avail_txqs); 4054 pf->avail_txqs = NULL; 4055 return -ENOMEM; 4056 } 4057 4058 mutex_init(&pf->vfs.table_lock); 4059 hash_init(pf->vfs.table); 4060 if (ice_is_feature_supported(pf, ICE_F_MBX_LIMIT)) 4061 wr32(&pf->hw, E830_MBX_PF_IN_FLIGHT_VF_MSGS_THRESH, 4062 ICE_MBX_OVERFLOW_WATERMARK); 4063 else 4064 ice_mbx_init_snapshot(&pf->hw); 4065 4066 xa_init(&pf->dyn_ports); 4067 xa_init(&pf->sf_nums); 4068 4069 return 0; 4070 } 4071 4072 /** 4073 * ice_is_wol_supported - check if WoL is supported 4074 * @hw: pointer to hardware info 4075 * 4076 * Check if WoL is supported based on the HW configuration. 4077 * Returns true if NVM supports and enables WoL for this port, false otherwise 4078 */ 4079 bool ice_is_wol_supported(struct ice_hw *hw) 4080 { 4081 u16 wol_ctrl; 4082 4083 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control 4084 * word) indicates WoL is not supported on the corresponding PF ID. 4085 */ 4086 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl)) 4087 return false; 4088 4089 return !(BIT(hw->port_info->lport) & wol_ctrl); 4090 } 4091 4092 /** 4093 * ice_vsi_recfg_qs - Change the number of queues on a VSI 4094 * @vsi: VSI being changed 4095 * @new_rx: new number of Rx queues 4096 * @new_tx: new number of Tx queues 4097 * @locked: is adev device_lock held 4098 * 4099 * Only change the number of queues if new_tx, or new_rx is non-0. 4100 * 4101 * Returns 0 on success. 4102 */ 4103 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx, bool locked) 4104 { 4105 struct ice_pf *pf = vsi->back; 4106 int i, err = 0, timeout = 50; 4107 4108 if (!new_rx && !new_tx) 4109 return -EINVAL; 4110 4111 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) { 4112 timeout--; 4113 if (!timeout) 4114 return -EBUSY; 4115 usleep_range(1000, 2000); 4116 } 4117 4118 if (new_tx) 4119 vsi->req_txq = (u16)new_tx; 4120 if (new_rx) 4121 vsi->req_rxq = (u16)new_rx; 4122 4123 /* set for the next time the netdev is started */ 4124 if (!netif_running(vsi->netdev)) { 4125 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 4126 if (err) 4127 goto rebuild_err; 4128 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n"); 4129 goto done; 4130 } 4131 4132 ice_vsi_close(vsi); 4133 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 4134 if (err) 4135 goto rebuild_err; 4136 4137 ice_for_each_traffic_class(i) { 4138 if (vsi->tc_cfg.ena_tc & BIT(i)) 4139 netdev_set_tc_queue(vsi->netdev, 4140 vsi->tc_cfg.tc_info[i].netdev_tc, 4141 vsi->tc_cfg.tc_info[i].qcount_tx, 4142 vsi->tc_cfg.tc_info[i].qoffset); 4143 } 4144 ice_pf_dcb_recfg(pf, locked); 4145 ice_vsi_open(vsi); 4146 goto done; 4147 4148 rebuild_err: 4149 dev_err(ice_pf_to_dev(pf), "Error during VSI rebuild: %d. Unload and reload the driver.\n", 4150 err); 4151 done: 4152 clear_bit(ICE_CFG_BUSY, pf->state); 4153 return err; 4154 } 4155 4156 /** 4157 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode 4158 * @pf: PF to configure 4159 * 4160 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF 4161 * VSI can still Tx/Rx VLAN tagged packets. 4162 */ 4163 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf) 4164 { 4165 struct ice_vsi *vsi = ice_get_main_vsi(pf); 4166 struct ice_vsi_ctx *ctxt; 4167 struct ice_hw *hw; 4168 int status; 4169 4170 if (!vsi) 4171 return; 4172 4173 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL); 4174 if (!ctxt) 4175 return; 4176 4177 hw = &pf->hw; 4178 ctxt->info = vsi->info; 4179 4180 ctxt->info.valid_sections = 4181 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID | 4182 ICE_AQ_VSI_PROP_SECURITY_VALID | 4183 ICE_AQ_VSI_PROP_SW_VALID); 4184 4185 /* disable VLAN anti-spoof */ 4186 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA << 4187 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S); 4188 4189 /* disable VLAN pruning and keep all other settings */ 4190 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA; 4191 4192 /* allow all VLANs on Tx and don't strip on Rx */ 4193 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL | 4194 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING; 4195 4196 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL); 4197 if (status) { 4198 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %d aq_err %s\n", 4199 status, ice_aq_str(hw->adminq.sq_last_status)); 4200 } else { 4201 vsi->info.sec_flags = ctxt->info.sec_flags; 4202 vsi->info.sw_flags2 = ctxt->info.sw_flags2; 4203 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags; 4204 } 4205 4206 kfree(ctxt); 4207 } 4208 4209 /** 4210 * ice_log_pkg_init - log result of DDP package load 4211 * @hw: pointer to hardware info 4212 * @state: state of package load 4213 */ 4214 static void ice_log_pkg_init(struct ice_hw *hw, enum ice_ddp_state state) 4215 { 4216 struct ice_pf *pf = hw->back; 4217 struct device *dev; 4218 4219 dev = ice_pf_to_dev(pf); 4220 4221 switch (state) { 4222 case ICE_DDP_PKG_SUCCESS: 4223 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n", 4224 hw->active_pkg_name, 4225 hw->active_pkg_ver.major, 4226 hw->active_pkg_ver.minor, 4227 hw->active_pkg_ver.update, 4228 hw->active_pkg_ver.draft); 4229 break; 4230 case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED: 4231 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n", 4232 hw->active_pkg_name, 4233 hw->active_pkg_ver.major, 4234 hw->active_pkg_ver.minor, 4235 hw->active_pkg_ver.update, 4236 hw->active_pkg_ver.draft); 4237 break; 4238 case ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED: 4239 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", 4240 hw->active_pkg_name, 4241 hw->active_pkg_ver.major, 4242 hw->active_pkg_ver.minor, 4243 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR); 4244 break; 4245 case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED: 4246 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", 4247 hw->active_pkg_name, 4248 hw->active_pkg_ver.major, 4249 hw->active_pkg_ver.minor, 4250 hw->active_pkg_ver.update, 4251 hw->active_pkg_ver.draft, 4252 hw->pkg_name, 4253 hw->pkg_ver.major, 4254 hw->pkg_ver.minor, 4255 hw->pkg_ver.update, 4256 hw->pkg_ver.draft); 4257 break; 4258 case ICE_DDP_PKG_FW_MISMATCH: 4259 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"); 4260 break; 4261 case ICE_DDP_PKG_INVALID_FILE: 4262 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n"); 4263 break; 4264 case ICE_DDP_PKG_FILE_VERSION_TOO_HIGH: 4265 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n"); 4266 break; 4267 case ICE_DDP_PKG_FILE_VERSION_TOO_LOW: 4268 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", 4269 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR); 4270 break; 4271 case ICE_DDP_PKG_FILE_SIGNATURE_INVALID: 4272 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"); 4273 break; 4274 case ICE_DDP_PKG_FILE_REVISION_TOO_LOW: 4275 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"); 4276 break; 4277 case ICE_DDP_PKG_LOAD_ERROR: 4278 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n"); 4279 /* poll for reset to complete */ 4280 if (ice_check_reset(hw)) 4281 dev_err(dev, "Error resetting device. Please reload the driver\n"); 4282 break; 4283 case ICE_DDP_PKG_ERR: 4284 default: 4285 dev_err(dev, "An unknown error occurred when loading the DDP package. Entering Safe Mode.\n"); 4286 break; 4287 } 4288 } 4289 4290 /** 4291 * ice_load_pkg - load/reload the DDP Package file 4292 * @firmware: firmware structure when firmware requested or NULL for reload 4293 * @pf: pointer to the PF instance 4294 * 4295 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and 4296 * initialize HW tables. 4297 */ 4298 static void 4299 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf) 4300 { 4301 enum ice_ddp_state state = ICE_DDP_PKG_ERR; 4302 struct device *dev = ice_pf_to_dev(pf); 4303 struct ice_hw *hw = &pf->hw; 4304 4305 /* Load DDP Package */ 4306 if (firmware && !hw->pkg_copy) { 4307 state = ice_copy_and_init_pkg(hw, firmware->data, 4308 firmware->size); 4309 ice_log_pkg_init(hw, state); 4310 } else if (!firmware && hw->pkg_copy) { 4311 /* Reload package during rebuild after CORER/GLOBR reset */ 4312 state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size); 4313 ice_log_pkg_init(hw, state); 4314 } else { 4315 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n"); 4316 } 4317 4318 if (!ice_is_init_pkg_successful(state)) { 4319 /* Safe Mode */ 4320 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags); 4321 return; 4322 } 4323 4324 /* Successful download package is the precondition for advanced 4325 * features, hence setting the ICE_FLAG_ADV_FEATURES flag 4326 */ 4327 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags); 4328 } 4329 4330 /** 4331 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines 4332 * @pf: pointer to the PF structure 4333 * 4334 * There is no error returned here because the driver should be able to handle 4335 * 128 Byte cache lines, so we only print a warning in case issues are seen, 4336 * specifically with Tx. 4337 */ 4338 static void ice_verify_cacheline_size(struct ice_pf *pf) 4339 { 4340 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M) 4341 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n", 4342 ICE_CACHE_LINE_BYTES); 4343 } 4344 4345 /** 4346 * ice_send_version - update firmware with driver version 4347 * @pf: PF struct 4348 * 4349 * Returns 0 on success, else error code 4350 */ 4351 static int ice_send_version(struct ice_pf *pf) 4352 { 4353 struct ice_driver_ver dv; 4354 4355 dv.major_ver = 0xff; 4356 dv.minor_ver = 0xff; 4357 dv.build_ver = 0xff; 4358 dv.subbuild_ver = 0; 4359 strscpy((char *)dv.driver_string, UTS_RELEASE, 4360 sizeof(dv.driver_string)); 4361 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL); 4362 } 4363 4364 /** 4365 * ice_init_fdir - Initialize flow director VSI and configuration 4366 * @pf: pointer to the PF instance 4367 * 4368 * returns 0 on success, negative on error 4369 */ 4370 static int ice_init_fdir(struct ice_pf *pf) 4371 { 4372 struct device *dev = ice_pf_to_dev(pf); 4373 struct ice_vsi *ctrl_vsi; 4374 int err; 4375 4376 /* Side Band Flow Director needs to have a control VSI. 4377 * Allocate it and store it in the PF. 4378 */ 4379 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info); 4380 if (!ctrl_vsi) { 4381 dev_dbg(dev, "could not create control VSI\n"); 4382 return -ENOMEM; 4383 } 4384 4385 err = ice_vsi_open_ctrl(ctrl_vsi); 4386 if (err) { 4387 dev_dbg(dev, "could not open control VSI\n"); 4388 goto err_vsi_open; 4389 } 4390 4391 mutex_init(&pf->hw.fdir_fltr_lock); 4392 4393 err = ice_fdir_create_dflt_rules(pf); 4394 if (err) 4395 goto err_fdir_rule; 4396 4397 return 0; 4398 4399 err_fdir_rule: 4400 ice_fdir_release_flows(&pf->hw); 4401 ice_vsi_close(ctrl_vsi); 4402 err_vsi_open: 4403 ice_vsi_release(ctrl_vsi); 4404 if (pf->ctrl_vsi_idx != ICE_NO_VSI) { 4405 pf->vsi[pf->ctrl_vsi_idx] = NULL; 4406 pf->ctrl_vsi_idx = ICE_NO_VSI; 4407 } 4408 return err; 4409 } 4410 4411 static void ice_deinit_fdir(struct ice_pf *pf) 4412 { 4413 struct ice_vsi *vsi = ice_get_ctrl_vsi(pf); 4414 4415 if (!vsi) 4416 return; 4417 4418 ice_vsi_manage_fdir(vsi, false); 4419 ice_vsi_release(vsi); 4420 if (pf->ctrl_vsi_idx != ICE_NO_VSI) { 4421 pf->vsi[pf->ctrl_vsi_idx] = NULL; 4422 pf->ctrl_vsi_idx = ICE_NO_VSI; 4423 } 4424 4425 mutex_destroy(&(&pf->hw)->fdir_fltr_lock); 4426 } 4427 4428 /** 4429 * ice_get_opt_fw_name - return optional firmware file name or NULL 4430 * @pf: pointer to the PF instance 4431 */ 4432 static char *ice_get_opt_fw_name(struct ice_pf *pf) 4433 { 4434 /* Optional firmware name same as default with additional dash 4435 * followed by a EUI-64 identifier (PCIe Device Serial Number) 4436 */ 4437 struct pci_dev *pdev = pf->pdev; 4438 char *opt_fw_filename; 4439 u64 dsn; 4440 4441 /* Determine the name of the optional file using the DSN (two 4442 * dwords following the start of the DSN Capability). 4443 */ 4444 dsn = pci_get_dsn(pdev); 4445 if (!dsn) 4446 return NULL; 4447 4448 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL); 4449 if (!opt_fw_filename) 4450 return NULL; 4451 4452 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg", 4453 ICE_DDP_PKG_PATH, dsn); 4454 4455 return opt_fw_filename; 4456 } 4457 4458 /** 4459 * ice_request_fw - Device initialization routine 4460 * @pf: pointer to the PF instance 4461 * @firmware: double pointer to firmware struct 4462 * 4463 * Return: zero when successful, negative values otherwise. 4464 */ 4465 static int ice_request_fw(struct ice_pf *pf, const struct firmware **firmware) 4466 { 4467 char *opt_fw_filename = ice_get_opt_fw_name(pf); 4468 struct device *dev = ice_pf_to_dev(pf); 4469 int err = 0; 4470 4471 /* optional device-specific DDP (if present) overrides the default DDP 4472 * package file. kernel logs a debug message if the file doesn't exist, 4473 * and warning messages for other errors. 4474 */ 4475 if (opt_fw_filename) { 4476 err = firmware_request_nowarn(firmware, opt_fw_filename, dev); 4477 kfree(opt_fw_filename); 4478 if (!err) 4479 return err; 4480 } 4481 err = request_firmware(firmware, ICE_DDP_PKG_FILE, dev); 4482 if (err) 4483 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n"); 4484 4485 return err; 4486 } 4487 4488 /** 4489 * ice_init_tx_topology - performs Tx topology initialization 4490 * @hw: pointer to the hardware structure 4491 * @firmware: pointer to firmware structure 4492 * 4493 * Return: zero when init was successful, negative values otherwise. 4494 */ 4495 static int 4496 ice_init_tx_topology(struct ice_hw *hw, const struct firmware *firmware) 4497 { 4498 u8 num_tx_sched_layers = hw->num_tx_sched_layers; 4499 struct ice_pf *pf = hw->back; 4500 struct device *dev; 4501 int err; 4502 4503 dev = ice_pf_to_dev(pf); 4504 err = ice_cfg_tx_topo(hw, firmware->data, firmware->size); 4505 if (!err) { 4506 if (hw->num_tx_sched_layers > num_tx_sched_layers) 4507 dev_info(dev, "Tx scheduling layers switching feature disabled\n"); 4508 else 4509 dev_info(dev, "Tx scheduling layers switching feature enabled\n"); 4510 /* if there was a change in topology ice_cfg_tx_topo triggered 4511 * a CORER and we need to re-init hw 4512 */ 4513 ice_deinit_hw(hw); 4514 err = ice_init_hw(hw); 4515 4516 return err; 4517 } else if (err == -EIO) { 4518 dev_info(dev, "DDP package does not support Tx scheduling layers switching feature - please update to the latest DDP package and try again\n"); 4519 } 4520 4521 return 0; 4522 } 4523 4524 /** 4525 * ice_init_supported_rxdids - Initialize supported Rx descriptor IDs 4526 * @hw: pointer to the hardware structure 4527 * @pf: pointer to pf structure 4528 * 4529 * The pf->supported_rxdids bitmap is used to indicate to VFs which descriptor 4530 * formats the PF hardware supports. The exact list of supported RXDIDs 4531 * depends on the loaded DDP package. The IDs can be determined by reading the 4532 * GLFLXP_RXDID_FLAGS register after the DDP package is loaded. 4533 * 4534 * Note that the legacy 32-byte RXDID 0 is always supported but is not listed 4535 * in the DDP package. The 16-byte legacy descriptor is never supported by 4536 * VFs. 4537 */ 4538 static void ice_init_supported_rxdids(struct ice_hw *hw, struct ice_pf *pf) 4539 { 4540 pf->supported_rxdids = BIT(ICE_RXDID_LEGACY_1); 4541 4542 for (int i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) { 4543 u32 regval; 4544 4545 regval = rd32(hw, GLFLXP_RXDID_FLAGS(i, 0)); 4546 if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S) 4547 & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M) 4548 pf->supported_rxdids |= BIT(i); 4549 } 4550 } 4551 4552 /** 4553 * ice_init_ddp_config - DDP related configuration 4554 * @hw: pointer to the hardware structure 4555 * @pf: pointer to pf structure 4556 * 4557 * This function loads DDP file from the disk, then initializes Tx 4558 * topology. At the end DDP package is loaded on the card. 4559 * 4560 * Return: zero when init was successful, negative values otherwise. 4561 */ 4562 static int ice_init_ddp_config(struct ice_hw *hw, struct ice_pf *pf) 4563 { 4564 struct device *dev = ice_pf_to_dev(pf); 4565 const struct firmware *firmware = NULL; 4566 int err; 4567 4568 err = ice_request_fw(pf, &firmware); 4569 if (err) { 4570 dev_err(dev, "Fail during requesting FW: %d\n", err); 4571 return err; 4572 } 4573 4574 err = ice_init_tx_topology(hw, firmware); 4575 if (err) { 4576 dev_err(dev, "Fail during initialization of Tx topology: %d\n", 4577 err); 4578 release_firmware(firmware); 4579 return err; 4580 } 4581 4582 /* Download firmware to device */ 4583 ice_load_pkg(firmware, pf); 4584 release_firmware(firmware); 4585 4586 /* Initialize the supported Rx descriptor IDs after loading DDP */ 4587 ice_init_supported_rxdids(hw, pf); 4588 4589 return 0; 4590 } 4591 4592 /** 4593 * ice_print_wake_reason - show the wake up cause in the log 4594 * @pf: pointer to the PF struct 4595 */ 4596 static void ice_print_wake_reason(struct ice_pf *pf) 4597 { 4598 u32 wus = pf->wakeup_reason; 4599 const char *wake_str; 4600 4601 /* if no wake event, nothing to print */ 4602 if (!wus) 4603 return; 4604 4605 if (wus & PFPM_WUS_LNKC_M) 4606 wake_str = "Link\n"; 4607 else if (wus & PFPM_WUS_MAG_M) 4608 wake_str = "Magic Packet\n"; 4609 else if (wus & PFPM_WUS_MNG_M) 4610 wake_str = "Management\n"; 4611 else if (wus & PFPM_WUS_FW_RST_WK_M) 4612 wake_str = "Firmware Reset\n"; 4613 else 4614 wake_str = "Unknown\n"; 4615 4616 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str); 4617 } 4618 4619 /** 4620 * ice_pf_fwlog_update_module - update 1 module 4621 * @pf: pointer to the PF struct 4622 * @log_level: log_level to use for the @module 4623 * @module: module to update 4624 */ 4625 void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module) 4626 { 4627 struct ice_hw *hw = &pf->hw; 4628 4629 hw->fwlog_cfg.module_entries[module].log_level = log_level; 4630 } 4631 4632 /** 4633 * ice_register_netdev - register netdev 4634 * @vsi: pointer to the VSI struct 4635 */ 4636 static int ice_register_netdev(struct ice_vsi *vsi) 4637 { 4638 int err; 4639 4640 if (!vsi || !vsi->netdev) 4641 return -EIO; 4642 4643 err = register_netdev(vsi->netdev); 4644 if (err) 4645 return err; 4646 4647 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); 4648 netif_carrier_off(vsi->netdev); 4649 netif_tx_stop_all_queues(vsi->netdev); 4650 4651 return 0; 4652 } 4653 4654 static void ice_unregister_netdev(struct ice_vsi *vsi) 4655 { 4656 if (!vsi || !vsi->netdev) 4657 return; 4658 4659 unregister_netdev(vsi->netdev); 4660 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state); 4661 } 4662 4663 /** 4664 * ice_cfg_netdev - Allocate, configure and register a netdev 4665 * @vsi: the VSI associated with the new netdev 4666 * 4667 * Returns 0 on success, negative value on failure 4668 */ 4669 static int ice_cfg_netdev(struct ice_vsi *vsi) 4670 { 4671 struct ice_netdev_priv *np; 4672 struct net_device *netdev; 4673 u8 mac_addr[ETH_ALEN]; 4674 4675 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, 4676 vsi->alloc_rxq); 4677 if (!netdev) 4678 return -ENOMEM; 4679 4680 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 4681 vsi->netdev = netdev; 4682 np = netdev_priv(netdev); 4683 np->vsi = vsi; 4684 4685 ice_set_netdev_features(netdev); 4686 ice_set_ops(vsi); 4687 4688 if (vsi->type == ICE_VSI_PF) { 4689 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back)); 4690 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 4691 eth_hw_addr_set(netdev, mac_addr); 4692 } 4693 4694 netdev->priv_flags |= IFF_UNICAST_FLT; 4695 4696 /* Setup netdev TC information */ 4697 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); 4698 4699 netdev->max_mtu = ICE_MAX_MTU; 4700 4701 return 0; 4702 } 4703 4704 static void ice_decfg_netdev(struct ice_vsi *vsi) 4705 { 4706 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); 4707 free_netdev(vsi->netdev); 4708 vsi->netdev = NULL; 4709 } 4710 4711 int ice_init_dev(struct ice_pf *pf) 4712 { 4713 struct device *dev = ice_pf_to_dev(pf); 4714 struct ice_hw *hw = &pf->hw; 4715 int err; 4716 4717 ice_init_feature_support(pf); 4718 4719 err = ice_init_ddp_config(hw, pf); 4720 4721 /* if ice_init_ddp_config fails, ICE_FLAG_ADV_FEATURES bit won't be 4722 * set in pf->state, which will cause ice_is_safe_mode to return 4723 * true 4724 */ 4725 if (err || ice_is_safe_mode(pf)) { 4726 /* we already got function/device capabilities but these don't 4727 * reflect what the driver needs to do in safe mode. Instead of 4728 * adding conditional logic everywhere to ignore these 4729 * device/function capabilities, override them. 4730 */ 4731 ice_set_safe_mode_caps(hw); 4732 } 4733 4734 err = ice_init_pf(pf); 4735 if (err) { 4736 dev_err(dev, "ice_init_pf failed: %d\n", err); 4737 return err; 4738 } 4739 4740 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port; 4741 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port; 4742 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP; 4743 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared; 4744 if (pf->hw.tnl.valid_count[TNL_VXLAN]) { 4745 pf->hw.udp_tunnel_nic.tables[0].n_entries = 4746 pf->hw.tnl.valid_count[TNL_VXLAN]; 4747 pf->hw.udp_tunnel_nic.tables[0].tunnel_types = 4748 UDP_TUNNEL_TYPE_VXLAN; 4749 } 4750 if (pf->hw.tnl.valid_count[TNL_GENEVE]) { 4751 pf->hw.udp_tunnel_nic.tables[1].n_entries = 4752 pf->hw.tnl.valid_count[TNL_GENEVE]; 4753 pf->hw.udp_tunnel_nic.tables[1].tunnel_types = 4754 UDP_TUNNEL_TYPE_GENEVE; 4755 } 4756 4757 err = ice_init_interrupt_scheme(pf); 4758 if (err) { 4759 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err); 4760 err = -EIO; 4761 goto unroll_pf_init; 4762 } 4763 4764 /* In case of MSIX we are going to setup the misc vector right here 4765 * to handle admin queue events etc. In case of legacy and MSI 4766 * the misc functionality and queue processing is combined in 4767 * the same vector and that gets setup at open. 4768 */ 4769 err = ice_req_irq_msix_misc(pf); 4770 if (err) { 4771 dev_err(dev, "setup of misc vector failed: %d\n", err); 4772 goto unroll_irq_scheme_init; 4773 } 4774 4775 return 0; 4776 4777 unroll_irq_scheme_init: 4778 ice_clear_interrupt_scheme(pf); 4779 unroll_pf_init: 4780 ice_deinit_pf(pf); 4781 return err; 4782 } 4783 4784 void ice_deinit_dev(struct ice_pf *pf) 4785 { 4786 ice_free_irq_msix_misc(pf); 4787 ice_deinit_pf(pf); 4788 ice_deinit_hw(&pf->hw); 4789 4790 /* Service task is already stopped, so call reset directly. */ 4791 ice_reset(&pf->hw, ICE_RESET_PFR); 4792 pci_wait_for_pending_transaction(pf->pdev); 4793 ice_clear_interrupt_scheme(pf); 4794 } 4795 4796 static void ice_init_features(struct ice_pf *pf) 4797 { 4798 struct device *dev = ice_pf_to_dev(pf); 4799 4800 if (ice_is_safe_mode(pf)) 4801 return; 4802 4803 /* initialize DDP driven features */ 4804 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 4805 ice_ptp_init(pf); 4806 4807 if (ice_is_feature_supported(pf, ICE_F_GNSS)) 4808 ice_gnss_init(pf); 4809 4810 if (ice_is_feature_supported(pf, ICE_F_CGU) || 4811 ice_is_feature_supported(pf, ICE_F_PHY_RCLK)) 4812 ice_dpll_init(pf); 4813 4814 /* Note: Flow director init failure is non-fatal to load */ 4815 if (ice_init_fdir(pf)) 4816 dev_err(dev, "could not initialize flow director\n"); 4817 4818 /* Note: DCB init failure is non-fatal to load */ 4819 if (ice_init_pf_dcb(pf, false)) { 4820 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags); 4821 clear_bit(ICE_FLAG_DCB_ENA, pf->flags); 4822 } else { 4823 ice_cfg_lldp_mib_change(&pf->hw, true); 4824 } 4825 4826 if (ice_init_lag(pf)) 4827 dev_warn(dev, "Failed to init link aggregation support\n"); 4828 4829 ice_hwmon_init(pf); 4830 } 4831 4832 static void ice_deinit_features(struct ice_pf *pf) 4833 { 4834 if (ice_is_safe_mode(pf)) 4835 return; 4836 4837 ice_deinit_lag(pf); 4838 if (test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags)) 4839 ice_cfg_lldp_mib_change(&pf->hw, false); 4840 ice_deinit_fdir(pf); 4841 if (ice_is_feature_supported(pf, ICE_F_GNSS)) 4842 ice_gnss_exit(pf); 4843 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 4844 ice_ptp_release(pf); 4845 if (test_bit(ICE_FLAG_DPLL, pf->flags)) 4846 ice_dpll_deinit(pf); 4847 if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) 4848 xa_destroy(&pf->eswitch.reprs); 4849 } 4850 4851 static void ice_init_wakeup(struct ice_pf *pf) 4852 { 4853 /* Save wakeup reason register for later use */ 4854 pf->wakeup_reason = rd32(&pf->hw, PFPM_WUS); 4855 4856 /* check for a power management event */ 4857 ice_print_wake_reason(pf); 4858 4859 /* clear wake status, all bits */ 4860 wr32(&pf->hw, PFPM_WUS, U32_MAX); 4861 4862 /* Disable WoL at init, wait for user to enable */ 4863 device_set_wakeup_enable(ice_pf_to_dev(pf), false); 4864 } 4865 4866 static int ice_init_link(struct ice_pf *pf) 4867 { 4868 struct device *dev = ice_pf_to_dev(pf); 4869 int err; 4870 4871 err = ice_init_link_events(pf->hw.port_info); 4872 if (err) { 4873 dev_err(dev, "ice_init_link_events failed: %d\n", err); 4874 return err; 4875 } 4876 4877 /* not a fatal error if this fails */ 4878 err = ice_init_nvm_phy_type(pf->hw.port_info); 4879 if (err) 4880 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err); 4881 4882 /* not a fatal error if this fails */ 4883 err = ice_update_link_info(pf->hw.port_info); 4884 if (err) 4885 dev_err(dev, "ice_update_link_info failed: %d\n", err); 4886 4887 ice_init_link_dflt_override(pf->hw.port_info); 4888 4889 ice_check_link_cfg_err(pf, 4890 pf->hw.port_info->phy.link_info.link_cfg_err); 4891 4892 /* if media available, initialize PHY settings */ 4893 if (pf->hw.port_info->phy.link_info.link_info & 4894 ICE_AQ_MEDIA_AVAILABLE) { 4895 /* not a fatal error if this fails */ 4896 err = ice_init_phy_user_cfg(pf->hw.port_info); 4897 if (err) 4898 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err); 4899 4900 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) { 4901 struct ice_vsi *vsi = ice_get_main_vsi(pf); 4902 4903 if (vsi) 4904 ice_configure_phy(vsi); 4905 } 4906 } else { 4907 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 4908 } 4909 4910 return err; 4911 } 4912 4913 static int ice_init_pf_sw(struct ice_pf *pf) 4914 { 4915 bool dvm = ice_is_dvm_ena(&pf->hw); 4916 struct ice_vsi *vsi; 4917 int err; 4918 4919 /* create switch struct for the switch element created by FW on boot */ 4920 pf->first_sw = kzalloc(sizeof(*pf->first_sw), GFP_KERNEL); 4921 if (!pf->first_sw) 4922 return -ENOMEM; 4923 4924 if (pf->hw.evb_veb) 4925 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB; 4926 else 4927 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA; 4928 4929 pf->first_sw->pf = pf; 4930 4931 /* record the sw_id available for later use */ 4932 pf->first_sw->sw_id = pf->hw.port_info->sw_id; 4933 4934 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL); 4935 if (err) 4936 goto err_aq_set_port_params; 4937 4938 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info); 4939 if (!vsi) { 4940 err = -ENOMEM; 4941 goto err_pf_vsi_setup; 4942 } 4943 4944 return 0; 4945 4946 err_pf_vsi_setup: 4947 err_aq_set_port_params: 4948 kfree(pf->first_sw); 4949 return err; 4950 } 4951 4952 static void ice_deinit_pf_sw(struct ice_pf *pf) 4953 { 4954 struct ice_vsi *vsi = ice_get_main_vsi(pf); 4955 4956 if (!vsi) 4957 return; 4958 4959 ice_vsi_release(vsi); 4960 kfree(pf->first_sw); 4961 } 4962 4963 static int ice_alloc_vsis(struct ice_pf *pf) 4964 { 4965 struct device *dev = ice_pf_to_dev(pf); 4966 4967 pf->num_alloc_vsi = pf->hw.func_caps.guar_num_vsi; 4968 if (!pf->num_alloc_vsi) 4969 return -EIO; 4970 4971 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) { 4972 dev_warn(dev, 4973 "limiting the VSI count due to UDP tunnel limitation %d > %d\n", 4974 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES); 4975 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES; 4976 } 4977 4978 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi), 4979 GFP_KERNEL); 4980 if (!pf->vsi) 4981 return -ENOMEM; 4982 4983 pf->vsi_stats = devm_kcalloc(dev, pf->num_alloc_vsi, 4984 sizeof(*pf->vsi_stats), GFP_KERNEL); 4985 if (!pf->vsi_stats) { 4986 devm_kfree(dev, pf->vsi); 4987 return -ENOMEM; 4988 } 4989 4990 return 0; 4991 } 4992 4993 static void ice_dealloc_vsis(struct ice_pf *pf) 4994 { 4995 devm_kfree(ice_pf_to_dev(pf), pf->vsi_stats); 4996 pf->vsi_stats = NULL; 4997 4998 pf->num_alloc_vsi = 0; 4999 devm_kfree(ice_pf_to_dev(pf), pf->vsi); 5000 pf->vsi = NULL; 5001 } 5002 5003 static int ice_init_devlink(struct ice_pf *pf) 5004 { 5005 int err; 5006 5007 err = ice_devlink_register_params(pf); 5008 if (err) 5009 return err; 5010 5011 ice_devlink_init_regions(pf); 5012 ice_devlink_register(pf); 5013 ice_health_init(pf); 5014 5015 return 0; 5016 } 5017 5018 static void ice_deinit_devlink(struct ice_pf *pf) 5019 { 5020 ice_health_deinit(pf); 5021 ice_devlink_unregister(pf); 5022 ice_devlink_destroy_regions(pf); 5023 ice_devlink_unregister_params(pf); 5024 } 5025 5026 static int ice_init(struct ice_pf *pf) 5027 { 5028 int err; 5029 5030 err = ice_init_dev(pf); 5031 if (err) 5032 return err; 5033 5034 if (pf->hw.mac_type == ICE_MAC_E830) { 5035 err = pci_enable_ptm(pf->pdev, NULL); 5036 if (err) 5037 dev_dbg(ice_pf_to_dev(pf), "PCIe PTM not supported by PCIe bus/controller\n"); 5038 } 5039 5040 err = ice_alloc_vsis(pf); 5041 if (err) 5042 goto err_alloc_vsis; 5043 5044 err = ice_init_pf_sw(pf); 5045 if (err) 5046 goto err_init_pf_sw; 5047 5048 ice_init_wakeup(pf); 5049 5050 err = ice_init_link(pf); 5051 if (err) 5052 goto err_init_link; 5053 5054 err = ice_send_version(pf); 5055 if (err) 5056 goto err_init_link; 5057 5058 ice_verify_cacheline_size(pf); 5059 5060 if (ice_is_safe_mode(pf)) 5061 ice_set_safe_mode_vlan_cfg(pf); 5062 else 5063 /* print PCI link speed and width */ 5064 pcie_print_link_status(pf->pdev); 5065 5066 /* ready to go, so clear down state bit */ 5067 clear_bit(ICE_DOWN, pf->state); 5068 clear_bit(ICE_SERVICE_DIS, pf->state); 5069 5070 /* since everything is good, start the service timer */ 5071 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 5072 5073 return 0; 5074 5075 err_init_link: 5076 ice_deinit_pf_sw(pf); 5077 err_init_pf_sw: 5078 ice_dealloc_vsis(pf); 5079 err_alloc_vsis: 5080 ice_deinit_dev(pf); 5081 return err; 5082 } 5083 5084 static void ice_deinit(struct ice_pf *pf) 5085 { 5086 set_bit(ICE_SERVICE_DIS, pf->state); 5087 set_bit(ICE_DOWN, pf->state); 5088 5089 ice_deinit_pf_sw(pf); 5090 ice_dealloc_vsis(pf); 5091 ice_deinit_dev(pf); 5092 } 5093 5094 /** 5095 * ice_load - load pf by init hw and starting VSI 5096 * @pf: pointer to the pf instance 5097 * 5098 * This function has to be called under devl_lock. 5099 */ 5100 int ice_load(struct ice_pf *pf) 5101 { 5102 struct ice_vsi *vsi; 5103 int err; 5104 5105 devl_assert_locked(priv_to_devlink(pf)); 5106 5107 vsi = ice_get_main_vsi(pf); 5108 5109 /* init channel list */ 5110 INIT_LIST_HEAD(&vsi->ch_list); 5111 5112 err = ice_cfg_netdev(vsi); 5113 if (err) 5114 return err; 5115 5116 /* Setup DCB netlink interface */ 5117 ice_dcbnl_setup(vsi); 5118 5119 err = ice_init_mac_fltr(pf); 5120 if (err) 5121 goto err_init_mac_fltr; 5122 5123 err = ice_devlink_create_pf_port(pf); 5124 if (err) 5125 goto err_devlink_create_pf_port; 5126 5127 SET_NETDEV_DEVLINK_PORT(vsi->netdev, &pf->devlink_port); 5128 5129 err = ice_register_netdev(vsi); 5130 if (err) 5131 goto err_register_netdev; 5132 5133 err = ice_tc_indir_block_register(vsi); 5134 if (err) 5135 goto err_tc_indir_block_register; 5136 5137 ice_napi_add(vsi); 5138 5139 ice_init_features(pf); 5140 5141 err = ice_init_rdma(pf); 5142 if (err) 5143 goto err_init_rdma; 5144 5145 ice_service_task_restart(pf); 5146 5147 clear_bit(ICE_DOWN, pf->state); 5148 5149 return 0; 5150 5151 err_init_rdma: 5152 ice_deinit_features(pf); 5153 ice_tc_indir_block_unregister(vsi); 5154 err_tc_indir_block_register: 5155 ice_unregister_netdev(vsi); 5156 err_register_netdev: 5157 ice_devlink_destroy_pf_port(pf); 5158 err_devlink_create_pf_port: 5159 err_init_mac_fltr: 5160 ice_decfg_netdev(vsi); 5161 return err; 5162 } 5163 5164 /** 5165 * ice_unload - unload pf by stopping VSI and deinit hw 5166 * @pf: pointer to the pf instance 5167 * 5168 * This function has to be called under devl_lock. 5169 */ 5170 void ice_unload(struct ice_pf *pf) 5171 { 5172 struct ice_vsi *vsi = ice_get_main_vsi(pf); 5173 5174 devl_assert_locked(priv_to_devlink(pf)); 5175 5176 ice_deinit_rdma(pf); 5177 ice_deinit_features(pf); 5178 ice_tc_indir_block_unregister(vsi); 5179 ice_unregister_netdev(vsi); 5180 ice_devlink_destroy_pf_port(pf); 5181 ice_decfg_netdev(vsi); 5182 } 5183 5184 static int ice_probe_recovery_mode(struct ice_pf *pf) 5185 { 5186 struct device *dev = ice_pf_to_dev(pf); 5187 int err; 5188 5189 dev_err(dev, "Firmware recovery mode detected. Limiting functionality. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for details on firmware recovery mode\n"); 5190 5191 INIT_HLIST_HEAD(&pf->aq_wait_list); 5192 spin_lock_init(&pf->aq_wait_lock); 5193 init_waitqueue_head(&pf->aq_wait_queue); 5194 5195 timer_setup(&pf->serv_tmr, ice_service_timer, 0); 5196 pf->serv_tmr_period = HZ; 5197 INIT_WORK(&pf->serv_task, ice_service_task_recovery_mode); 5198 clear_bit(ICE_SERVICE_SCHED, pf->state); 5199 err = ice_create_all_ctrlq(&pf->hw); 5200 if (err) 5201 return err; 5202 5203 scoped_guard(devl, priv_to_devlink(pf)) { 5204 err = ice_init_devlink(pf); 5205 if (err) 5206 return err; 5207 } 5208 5209 ice_service_task_restart(pf); 5210 5211 return 0; 5212 } 5213 5214 /** 5215 * ice_probe - Device initialization routine 5216 * @pdev: PCI device information struct 5217 * @ent: entry in ice_pci_tbl 5218 * 5219 * Returns 0 on success, negative on failure 5220 */ 5221 static int 5222 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent) 5223 { 5224 struct device *dev = &pdev->dev; 5225 struct ice_adapter *adapter; 5226 struct ice_pf *pf; 5227 struct ice_hw *hw; 5228 int err; 5229 5230 if (pdev->is_virtfn) { 5231 dev_err(dev, "can't probe a virtual function\n"); 5232 return -EINVAL; 5233 } 5234 5235 /* when under a kdump kernel initiate a reset before enabling the 5236 * device in order to clear out any pending DMA transactions. These 5237 * transactions can cause some systems to machine check when doing 5238 * the pcim_enable_device() below. 5239 */ 5240 if (is_kdump_kernel()) { 5241 pci_save_state(pdev); 5242 pci_clear_master(pdev); 5243 err = pcie_flr(pdev); 5244 if (err) 5245 return err; 5246 pci_restore_state(pdev); 5247 } 5248 5249 /* this driver uses devres, see 5250 * Documentation/driver-api/driver-model/devres.rst 5251 */ 5252 err = pcim_enable_device(pdev); 5253 if (err) 5254 return err; 5255 5256 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev)); 5257 if (err) { 5258 dev_err(dev, "BAR0 I/O map error %d\n", err); 5259 return err; 5260 } 5261 5262 pf = ice_allocate_pf(dev); 5263 if (!pf) 5264 return -ENOMEM; 5265 5266 /* initialize Auxiliary index to invalid value */ 5267 pf->aux_idx = -1; 5268 5269 /* set up for high or low DMA */ 5270 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); 5271 if (err) { 5272 dev_err(dev, "DMA configuration failed: 0x%x\n", err); 5273 return err; 5274 } 5275 5276 pci_set_master(pdev); 5277 pf->pdev = pdev; 5278 pci_set_drvdata(pdev, pf); 5279 set_bit(ICE_DOWN, pf->state); 5280 /* Disable service task until DOWN bit is cleared */ 5281 set_bit(ICE_SERVICE_DIS, pf->state); 5282 5283 hw = &pf->hw; 5284 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0]; 5285 pci_save_state(pdev); 5286 5287 hw->back = pf; 5288 hw->port_info = NULL; 5289 hw->vendor_id = pdev->vendor; 5290 hw->device_id = pdev->device; 5291 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); 5292 hw->subsystem_vendor_id = pdev->subsystem_vendor; 5293 hw->subsystem_device_id = pdev->subsystem_device; 5294 hw->bus.device = PCI_SLOT(pdev->devfn); 5295 hw->bus.func = PCI_FUNC(pdev->devfn); 5296 ice_set_ctrlq_len(hw); 5297 5298 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M); 5299 5300 #ifndef CONFIG_DYNAMIC_DEBUG 5301 if (debug < -1) 5302 hw->debug_mask = debug; 5303 #endif 5304 5305 if (ice_is_recovery_mode(hw)) 5306 return ice_probe_recovery_mode(pf); 5307 5308 err = ice_init_hw(hw); 5309 if (err) { 5310 dev_err(dev, "ice_init_hw failed: %d\n", err); 5311 return err; 5312 } 5313 5314 adapter = ice_adapter_get(pdev); 5315 if (IS_ERR(adapter)) { 5316 err = PTR_ERR(adapter); 5317 goto unroll_hw_init; 5318 } 5319 pf->adapter = adapter; 5320 5321 err = ice_init(pf); 5322 if (err) 5323 goto unroll_adapter; 5324 5325 devl_lock(priv_to_devlink(pf)); 5326 err = ice_load(pf); 5327 if (err) 5328 goto unroll_init; 5329 5330 err = ice_init_devlink(pf); 5331 if (err) 5332 goto unroll_load; 5333 devl_unlock(priv_to_devlink(pf)); 5334 5335 return 0; 5336 5337 unroll_load: 5338 ice_unload(pf); 5339 unroll_init: 5340 devl_unlock(priv_to_devlink(pf)); 5341 ice_deinit(pf); 5342 unroll_adapter: 5343 ice_adapter_put(pdev); 5344 unroll_hw_init: 5345 ice_deinit_hw(hw); 5346 return err; 5347 } 5348 5349 /** 5350 * ice_set_wake - enable or disable Wake on LAN 5351 * @pf: pointer to the PF struct 5352 * 5353 * Simple helper for WoL control 5354 */ 5355 static void ice_set_wake(struct ice_pf *pf) 5356 { 5357 struct ice_hw *hw = &pf->hw; 5358 bool wol = pf->wol_ena; 5359 5360 /* clear wake state, otherwise new wake events won't fire */ 5361 wr32(hw, PFPM_WUS, U32_MAX); 5362 5363 /* enable / disable APM wake up, no RMW needed */ 5364 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0); 5365 5366 /* set magic packet filter enabled */ 5367 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0); 5368 } 5369 5370 /** 5371 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet 5372 * @pf: pointer to the PF struct 5373 * 5374 * Issue firmware command to enable multicast magic wake, making 5375 * sure that any locally administered address (LAA) is used for 5376 * wake, and that PF reset doesn't undo the LAA. 5377 */ 5378 static void ice_setup_mc_magic_wake(struct ice_pf *pf) 5379 { 5380 struct device *dev = ice_pf_to_dev(pf); 5381 struct ice_hw *hw = &pf->hw; 5382 u8 mac_addr[ETH_ALEN]; 5383 struct ice_vsi *vsi; 5384 int status; 5385 u8 flags; 5386 5387 if (!pf->wol_ena) 5388 return; 5389 5390 vsi = ice_get_main_vsi(pf); 5391 if (!vsi) 5392 return; 5393 5394 /* Get current MAC address in case it's an LAA */ 5395 if (vsi->netdev) 5396 ether_addr_copy(mac_addr, vsi->netdev->dev_addr); 5397 else 5398 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); 5399 5400 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN | 5401 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL | 5402 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP; 5403 5404 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL); 5405 if (status) 5406 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %d aq_err %s\n", 5407 status, ice_aq_str(hw->adminq.sq_last_status)); 5408 } 5409 5410 /** 5411 * ice_remove - Device removal routine 5412 * @pdev: PCI device information struct 5413 */ 5414 static void ice_remove(struct pci_dev *pdev) 5415 { 5416 struct ice_pf *pf = pci_get_drvdata(pdev); 5417 int i; 5418 5419 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) { 5420 if (!ice_is_reset_in_progress(pf->state)) 5421 break; 5422 msleep(100); 5423 } 5424 5425 if (ice_is_recovery_mode(&pf->hw)) { 5426 ice_service_task_stop(pf); 5427 scoped_guard(devl, priv_to_devlink(pf)) { 5428 ice_deinit_devlink(pf); 5429 } 5430 return; 5431 } 5432 5433 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) { 5434 set_bit(ICE_VF_RESETS_DISABLED, pf->state); 5435 ice_free_vfs(pf); 5436 } 5437 5438 ice_hwmon_exit(pf); 5439 5440 ice_service_task_stop(pf); 5441 ice_aq_cancel_waiting_tasks(pf); 5442 set_bit(ICE_DOWN, pf->state); 5443 5444 if (!ice_is_safe_mode(pf)) 5445 ice_remove_arfs(pf); 5446 5447 devl_lock(priv_to_devlink(pf)); 5448 ice_dealloc_all_dynamic_ports(pf); 5449 ice_deinit_devlink(pf); 5450 5451 ice_unload(pf); 5452 devl_unlock(priv_to_devlink(pf)); 5453 5454 ice_deinit(pf); 5455 ice_vsi_release_all(pf); 5456 5457 ice_setup_mc_magic_wake(pf); 5458 ice_set_wake(pf); 5459 5460 ice_adapter_put(pdev); 5461 } 5462 5463 /** 5464 * ice_shutdown - PCI callback for shutting down device 5465 * @pdev: PCI device information struct 5466 */ 5467 static void ice_shutdown(struct pci_dev *pdev) 5468 { 5469 struct ice_pf *pf = pci_get_drvdata(pdev); 5470 5471 ice_remove(pdev); 5472 5473 if (system_state == SYSTEM_POWER_OFF) { 5474 pci_wake_from_d3(pdev, pf->wol_ena); 5475 pci_set_power_state(pdev, PCI_D3hot); 5476 } 5477 } 5478 5479 /** 5480 * ice_prepare_for_shutdown - prep for PCI shutdown 5481 * @pf: board private structure 5482 * 5483 * Inform or close all dependent features in prep for PCI device shutdown 5484 */ 5485 static void ice_prepare_for_shutdown(struct ice_pf *pf) 5486 { 5487 struct ice_hw *hw = &pf->hw; 5488 u32 v; 5489 5490 /* Notify VFs of impending reset */ 5491 if (ice_check_sq_alive(hw, &hw->mailboxq)) 5492 ice_vc_notify_reset(pf); 5493 5494 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n"); 5495 5496 /* disable the VSIs and their queues that are not already DOWN */ 5497 ice_pf_dis_all_vsi(pf, false); 5498 5499 ice_for_each_vsi(pf, v) 5500 if (pf->vsi[v]) 5501 pf->vsi[v]->vsi_num = 0; 5502 5503 ice_shutdown_all_ctrlq(hw, true); 5504 } 5505 5506 /** 5507 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme 5508 * @pf: board private structure to reinitialize 5509 * 5510 * This routine reinitialize interrupt scheme that was cleared during 5511 * power management suspend callback. 5512 * 5513 * This should be called during resume routine to re-allocate the q_vectors 5514 * and reacquire interrupts. 5515 */ 5516 static int ice_reinit_interrupt_scheme(struct ice_pf *pf) 5517 { 5518 struct device *dev = ice_pf_to_dev(pf); 5519 int ret, v; 5520 5521 /* Since we clear MSIX flag during suspend, we need to 5522 * set it back during resume... 5523 */ 5524 5525 ret = ice_init_interrupt_scheme(pf); 5526 if (ret) { 5527 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret); 5528 return ret; 5529 } 5530 5531 /* Remap vectors and rings, after successful re-init interrupts */ 5532 ice_for_each_vsi(pf, v) { 5533 if (!pf->vsi[v]) 5534 continue; 5535 5536 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]); 5537 if (ret) 5538 goto err_reinit; 5539 ice_vsi_map_rings_to_vectors(pf->vsi[v]); 5540 rtnl_lock(); 5541 ice_vsi_set_napi_queues(pf->vsi[v]); 5542 rtnl_unlock(); 5543 } 5544 5545 ret = ice_req_irq_msix_misc(pf); 5546 if (ret) { 5547 dev_err(dev, "Setting up misc vector failed after device suspend %d\n", 5548 ret); 5549 goto err_reinit; 5550 } 5551 5552 return 0; 5553 5554 err_reinit: 5555 while (v--) 5556 if (pf->vsi[v]) { 5557 rtnl_lock(); 5558 ice_vsi_clear_napi_queues(pf->vsi[v]); 5559 rtnl_unlock(); 5560 ice_vsi_free_q_vectors(pf->vsi[v]); 5561 } 5562 5563 return ret; 5564 } 5565 5566 /** 5567 * ice_suspend 5568 * @dev: generic device information structure 5569 * 5570 * Power Management callback to quiesce the device and prepare 5571 * for D3 transition. 5572 */ 5573 static int ice_suspend(struct device *dev) 5574 { 5575 struct pci_dev *pdev = to_pci_dev(dev); 5576 struct ice_pf *pf; 5577 int disabled, v; 5578 5579 pf = pci_get_drvdata(pdev); 5580 5581 if (!ice_pf_state_is_nominal(pf)) { 5582 dev_err(dev, "Device is not ready, no need to suspend it\n"); 5583 return -EBUSY; 5584 } 5585 5586 /* Stop watchdog tasks until resume completion. 5587 * Even though it is most likely that the service task is 5588 * disabled if the device is suspended or down, the service task's 5589 * state is controlled by a different state bit, and we should 5590 * store and honor whatever state that bit is in at this point. 5591 */ 5592 disabled = ice_service_task_stop(pf); 5593 5594 ice_deinit_rdma(pf); 5595 5596 /* Already suspended?, then there is nothing to do */ 5597 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) { 5598 if (!disabled) 5599 ice_service_task_restart(pf); 5600 return 0; 5601 } 5602 5603 if (test_bit(ICE_DOWN, pf->state) || 5604 ice_is_reset_in_progress(pf->state)) { 5605 dev_err(dev, "can't suspend device in reset or already down\n"); 5606 if (!disabled) 5607 ice_service_task_restart(pf); 5608 return 0; 5609 } 5610 5611 ice_setup_mc_magic_wake(pf); 5612 5613 ice_prepare_for_shutdown(pf); 5614 5615 ice_set_wake(pf); 5616 5617 /* Free vectors, clear the interrupt scheme and release IRQs 5618 * for proper hibernation, especially with large number of CPUs. 5619 * Otherwise hibernation might fail when mapping all the vectors back 5620 * to CPU0. 5621 */ 5622 ice_free_irq_msix_misc(pf); 5623 ice_for_each_vsi(pf, v) { 5624 if (!pf->vsi[v]) 5625 continue; 5626 rtnl_lock(); 5627 ice_vsi_clear_napi_queues(pf->vsi[v]); 5628 rtnl_unlock(); 5629 ice_vsi_free_q_vectors(pf->vsi[v]); 5630 } 5631 ice_clear_interrupt_scheme(pf); 5632 5633 pci_save_state(pdev); 5634 pci_wake_from_d3(pdev, pf->wol_ena); 5635 pci_set_power_state(pdev, PCI_D3hot); 5636 return 0; 5637 } 5638 5639 /** 5640 * ice_resume - PM callback for waking up from D3 5641 * @dev: generic device information structure 5642 */ 5643 static int ice_resume(struct device *dev) 5644 { 5645 struct pci_dev *pdev = to_pci_dev(dev); 5646 enum ice_reset_req reset_type; 5647 struct ice_pf *pf; 5648 struct ice_hw *hw; 5649 int ret; 5650 5651 pci_set_power_state(pdev, PCI_D0); 5652 pci_restore_state(pdev); 5653 pci_save_state(pdev); 5654 5655 if (!pci_device_is_present(pdev)) 5656 return -ENODEV; 5657 5658 ret = pci_enable_device_mem(pdev); 5659 if (ret) { 5660 dev_err(dev, "Cannot enable device after suspend\n"); 5661 return ret; 5662 } 5663 5664 pf = pci_get_drvdata(pdev); 5665 hw = &pf->hw; 5666 5667 pf->wakeup_reason = rd32(hw, PFPM_WUS); 5668 ice_print_wake_reason(pf); 5669 5670 /* We cleared the interrupt scheme when we suspended, so we need to 5671 * restore it now to resume device functionality. 5672 */ 5673 ret = ice_reinit_interrupt_scheme(pf); 5674 if (ret) 5675 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret); 5676 5677 ret = ice_init_rdma(pf); 5678 if (ret) 5679 dev_err(dev, "Reinitialize RDMA during resume failed: %d\n", 5680 ret); 5681 5682 clear_bit(ICE_DOWN, pf->state); 5683 /* Now perform PF reset and rebuild */ 5684 reset_type = ICE_RESET_PFR; 5685 /* re-enable service task for reset, but allow reset to schedule it */ 5686 clear_bit(ICE_SERVICE_DIS, pf->state); 5687 5688 if (ice_schedule_reset(pf, reset_type)) 5689 dev_err(dev, "Reset during resume failed.\n"); 5690 5691 clear_bit(ICE_SUSPENDED, pf->state); 5692 ice_service_task_restart(pf); 5693 5694 /* Restart the service task */ 5695 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 5696 5697 return 0; 5698 } 5699 5700 /** 5701 * ice_pci_err_detected - warning that PCI error has been detected 5702 * @pdev: PCI device information struct 5703 * @err: the type of PCI error 5704 * 5705 * Called to warn that something happened on the PCI bus and the error handling 5706 * is in progress. Allows the driver to gracefully prepare/handle PCI errors. 5707 */ 5708 static pci_ers_result_t 5709 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err) 5710 { 5711 struct ice_pf *pf = pci_get_drvdata(pdev); 5712 5713 if (!pf) { 5714 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n", 5715 __func__, err); 5716 return PCI_ERS_RESULT_DISCONNECT; 5717 } 5718 5719 if (!test_bit(ICE_SUSPENDED, pf->state)) { 5720 ice_service_task_stop(pf); 5721 5722 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) { 5723 set_bit(ICE_PFR_REQ, pf->state); 5724 ice_prepare_for_reset(pf, ICE_RESET_PFR); 5725 } 5726 } 5727 5728 return PCI_ERS_RESULT_NEED_RESET; 5729 } 5730 5731 /** 5732 * ice_pci_err_slot_reset - a PCI slot reset has just happened 5733 * @pdev: PCI device information struct 5734 * 5735 * Called to determine if the driver can recover from the PCI slot reset by 5736 * using a register read to determine if the device is recoverable. 5737 */ 5738 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev) 5739 { 5740 struct ice_pf *pf = pci_get_drvdata(pdev); 5741 pci_ers_result_t result; 5742 int err; 5743 u32 reg; 5744 5745 err = pci_enable_device_mem(pdev); 5746 if (err) { 5747 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n", 5748 err); 5749 result = PCI_ERS_RESULT_DISCONNECT; 5750 } else { 5751 pci_set_master(pdev); 5752 pci_restore_state(pdev); 5753 pci_save_state(pdev); 5754 pci_wake_from_d3(pdev, false); 5755 5756 /* Check for life */ 5757 reg = rd32(&pf->hw, GLGEN_RTRIG); 5758 if (!reg) 5759 result = PCI_ERS_RESULT_RECOVERED; 5760 else 5761 result = PCI_ERS_RESULT_DISCONNECT; 5762 } 5763 5764 return result; 5765 } 5766 5767 /** 5768 * ice_pci_err_resume - restart operations after PCI error recovery 5769 * @pdev: PCI device information struct 5770 * 5771 * Called to allow the driver to bring things back up after PCI error and/or 5772 * reset recovery have finished 5773 */ 5774 static void ice_pci_err_resume(struct pci_dev *pdev) 5775 { 5776 struct ice_pf *pf = pci_get_drvdata(pdev); 5777 5778 if (!pf) { 5779 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n", 5780 __func__); 5781 return; 5782 } 5783 5784 if (test_bit(ICE_SUSPENDED, pf->state)) { 5785 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n", 5786 __func__); 5787 return; 5788 } 5789 5790 ice_restore_all_vfs_msi_state(pf); 5791 5792 ice_do_reset(pf, ICE_RESET_PFR); 5793 ice_service_task_restart(pf); 5794 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period)); 5795 } 5796 5797 /** 5798 * ice_pci_err_reset_prepare - prepare device driver for PCI reset 5799 * @pdev: PCI device information struct 5800 */ 5801 static void ice_pci_err_reset_prepare(struct pci_dev *pdev) 5802 { 5803 struct ice_pf *pf = pci_get_drvdata(pdev); 5804 5805 if (!test_bit(ICE_SUSPENDED, pf->state)) { 5806 ice_service_task_stop(pf); 5807 5808 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) { 5809 set_bit(ICE_PFR_REQ, pf->state); 5810 ice_prepare_for_reset(pf, ICE_RESET_PFR); 5811 } 5812 } 5813 } 5814 5815 /** 5816 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin 5817 * @pdev: PCI device information struct 5818 */ 5819 static void ice_pci_err_reset_done(struct pci_dev *pdev) 5820 { 5821 ice_pci_err_resume(pdev); 5822 } 5823 5824 /* ice_pci_tbl - PCI Device ID Table 5825 * 5826 * Wildcard entries (PCI_ANY_ID) should come last 5827 * Last entry must be all 0s 5828 * 5829 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, 5830 * Class, Class Mask, private data (not used) } 5831 */ 5832 static const struct pci_device_id ice_pci_tbl[] = { 5833 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE) }, 5834 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP) }, 5835 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP) }, 5836 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_BACKPLANE) }, 5837 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_QSFP) }, 5838 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP) }, 5839 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE) }, 5840 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP) }, 5841 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP) }, 5842 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T) }, 5843 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII) }, 5844 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE) }, 5845 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP) }, 5846 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP) }, 5847 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T) }, 5848 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII) }, 5849 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE) }, 5850 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP) }, 5851 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T) }, 5852 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII) }, 5853 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE) }, 5854 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP) }, 5855 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T) }, 5856 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE) }, 5857 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP) }, 5858 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822_SI_DFLT) }, 5859 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_BACKPLANE), }, 5860 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_QSFP), }, 5861 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_SFP), }, 5862 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_SGMII), }, 5863 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_BACKPLANE) }, 5864 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_QSFP56) }, 5865 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_SFP) }, 5866 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_SFP_DD) }, 5867 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_BACKPLANE), }, 5868 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_BACKPLANE), }, 5869 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_QSFP), }, 5870 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_QSFP), }, 5871 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_SFP), }, 5872 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_SFP), }, 5873 /* required last entry */ 5874 {} 5875 }; 5876 MODULE_DEVICE_TABLE(pci, ice_pci_tbl); 5877 5878 static DEFINE_SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume); 5879 5880 static const struct pci_error_handlers ice_pci_err_handler = { 5881 .error_detected = ice_pci_err_detected, 5882 .slot_reset = ice_pci_err_slot_reset, 5883 .reset_prepare = ice_pci_err_reset_prepare, 5884 .reset_done = ice_pci_err_reset_done, 5885 .resume = ice_pci_err_resume 5886 }; 5887 5888 static struct pci_driver ice_driver = { 5889 .name = KBUILD_MODNAME, 5890 .id_table = ice_pci_tbl, 5891 .probe = ice_probe, 5892 .remove = ice_remove, 5893 .driver.pm = pm_sleep_ptr(&ice_pm_ops), 5894 .shutdown = ice_shutdown, 5895 .sriov_configure = ice_sriov_configure, 5896 .sriov_get_vf_total_msix = ice_sriov_get_vf_total_msix, 5897 .sriov_set_msix_vec_count = ice_sriov_set_msix_vec_count, 5898 .err_handler = &ice_pci_err_handler 5899 }; 5900 5901 /** 5902 * ice_module_init - Driver registration routine 5903 * 5904 * ice_module_init is the first routine called when the driver is 5905 * loaded. All it does is register with the PCI subsystem. 5906 */ 5907 static int __init ice_module_init(void) 5908 { 5909 int status = -ENOMEM; 5910 5911 pr_info("%s\n", ice_driver_string); 5912 pr_info("%s\n", ice_copyright); 5913 5914 ice_adv_lnk_speed_maps_init(); 5915 5916 ice_wq = alloc_workqueue("%s", WQ_UNBOUND, 0, KBUILD_MODNAME); 5917 if (!ice_wq) { 5918 pr_err("Failed to create workqueue\n"); 5919 return status; 5920 } 5921 5922 ice_lag_wq = alloc_ordered_workqueue("ice_lag_wq", 0); 5923 if (!ice_lag_wq) { 5924 pr_err("Failed to create LAG workqueue\n"); 5925 goto err_dest_wq; 5926 } 5927 5928 ice_debugfs_init(); 5929 5930 status = pci_register_driver(&ice_driver); 5931 if (status) { 5932 pr_err("failed to register PCI driver, err %d\n", status); 5933 goto err_dest_lag_wq; 5934 } 5935 5936 status = ice_sf_driver_register(); 5937 if (status) { 5938 pr_err("Failed to register SF driver, err %d\n", status); 5939 goto err_sf_driver; 5940 } 5941 5942 return 0; 5943 5944 err_sf_driver: 5945 pci_unregister_driver(&ice_driver); 5946 err_dest_lag_wq: 5947 destroy_workqueue(ice_lag_wq); 5948 ice_debugfs_exit(); 5949 err_dest_wq: 5950 destroy_workqueue(ice_wq); 5951 return status; 5952 } 5953 module_init(ice_module_init); 5954 5955 /** 5956 * ice_module_exit - Driver exit cleanup routine 5957 * 5958 * ice_module_exit is called just before the driver is removed 5959 * from memory. 5960 */ 5961 static void __exit ice_module_exit(void) 5962 { 5963 ice_sf_driver_unregister(); 5964 pci_unregister_driver(&ice_driver); 5965 ice_debugfs_exit(); 5966 destroy_workqueue(ice_wq); 5967 destroy_workqueue(ice_lag_wq); 5968 pr_info("module unloaded\n"); 5969 } 5970 module_exit(ice_module_exit); 5971 5972 /** 5973 * ice_set_mac_address - NDO callback to set MAC address 5974 * @netdev: network interface device structure 5975 * @pi: pointer to an address structure 5976 * 5977 * Returns 0 on success, negative on failure 5978 */ 5979 static int ice_set_mac_address(struct net_device *netdev, void *pi) 5980 { 5981 struct ice_netdev_priv *np = netdev_priv(netdev); 5982 struct ice_vsi *vsi = np->vsi; 5983 struct ice_pf *pf = vsi->back; 5984 struct ice_hw *hw = &pf->hw; 5985 struct sockaddr *addr = pi; 5986 u8 old_mac[ETH_ALEN]; 5987 u8 flags = 0; 5988 u8 *mac; 5989 int err; 5990 5991 mac = (u8 *)addr->sa_data; 5992 5993 if (!is_valid_ether_addr(mac)) 5994 return -EADDRNOTAVAIL; 5995 5996 if (test_bit(ICE_DOWN, pf->state) || 5997 ice_is_reset_in_progress(pf->state)) { 5998 netdev_err(netdev, "can't set mac %pM. device not ready\n", 5999 mac); 6000 return -EBUSY; 6001 } 6002 6003 if (ice_chnl_dmac_fltr_cnt(pf)) { 6004 netdev_err(netdev, "can't set mac %pM. Device has tc-flower filters, delete all of them and try again\n", 6005 mac); 6006 return -EAGAIN; 6007 } 6008 6009 netif_addr_lock_bh(netdev); 6010 ether_addr_copy(old_mac, netdev->dev_addr); 6011 /* change the netdev's MAC address */ 6012 eth_hw_addr_set(netdev, mac); 6013 netif_addr_unlock_bh(netdev); 6014 6015 /* Clean up old MAC filter. Not an error if old filter doesn't exist */ 6016 err = ice_fltr_remove_mac(vsi, old_mac, ICE_FWD_TO_VSI); 6017 if (err && err != -ENOENT) { 6018 err = -EADDRNOTAVAIL; 6019 goto err_update_filters; 6020 } 6021 6022 /* Add filter for new MAC. If filter exists, return success */ 6023 err = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI); 6024 if (err == -EEXIST) { 6025 /* Although this MAC filter is already present in hardware it's 6026 * possible in some cases (e.g. bonding) that dev_addr was 6027 * modified outside of the driver and needs to be restored back 6028 * to this value. 6029 */ 6030 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac); 6031 6032 return 0; 6033 } else if (err) { 6034 /* error if the new filter addition failed */ 6035 err = -EADDRNOTAVAIL; 6036 } 6037 6038 err_update_filters: 6039 if (err) { 6040 netdev_err(netdev, "can't set MAC %pM. filter update failed\n", 6041 mac); 6042 netif_addr_lock_bh(netdev); 6043 eth_hw_addr_set(netdev, old_mac); 6044 netif_addr_unlock_bh(netdev); 6045 return err; 6046 } 6047 6048 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n", 6049 netdev->dev_addr); 6050 6051 /* write new MAC address to the firmware */ 6052 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL; 6053 err = ice_aq_manage_mac_write(hw, mac, flags, NULL); 6054 if (err) { 6055 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n", 6056 mac, err); 6057 } 6058 return 0; 6059 } 6060 6061 /** 6062 * ice_set_rx_mode - NDO callback to set the netdev filters 6063 * @netdev: network interface device structure 6064 */ 6065 static void ice_set_rx_mode(struct net_device *netdev) 6066 { 6067 struct ice_netdev_priv *np = netdev_priv(netdev); 6068 struct ice_vsi *vsi = np->vsi; 6069 6070 if (!vsi || ice_is_switchdev_running(vsi->back)) 6071 return; 6072 6073 /* Set the flags to synchronize filters 6074 * ndo_set_rx_mode may be triggered even without a change in netdev 6075 * flags 6076 */ 6077 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state); 6078 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); 6079 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags); 6080 6081 /* schedule our worker thread which will take care of 6082 * applying the new filter changes 6083 */ 6084 ice_service_task_schedule(vsi->back); 6085 } 6086 6087 /** 6088 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate 6089 * @netdev: network interface device structure 6090 * @queue_index: Queue ID 6091 * @maxrate: maximum bandwidth in Mbps 6092 */ 6093 static int 6094 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate) 6095 { 6096 struct ice_netdev_priv *np = netdev_priv(netdev); 6097 struct ice_vsi *vsi = np->vsi; 6098 u16 q_handle; 6099 int status; 6100 u8 tc; 6101 6102 /* Validate maxrate requested is within permitted range */ 6103 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) { 6104 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n", 6105 maxrate, queue_index); 6106 return -EINVAL; 6107 } 6108 6109 q_handle = vsi->tx_rings[queue_index]->q_handle; 6110 tc = ice_dcb_get_tc(vsi, queue_index); 6111 6112 vsi = ice_locate_vsi_using_queue(vsi, queue_index); 6113 if (!vsi) { 6114 netdev_err(netdev, "Invalid VSI for given queue %d\n", 6115 queue_index); 6116 return -EINVAL; 6117 } 6118 6119 /* Set BW back to default, when user set maxrate to 0 */ 6120 if (!maxrate) 6121 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc, 6122 q_handle, ICE_MAX_BW); 6123 else 6124 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc, 6125 q_handle, ICE_MAX_BW, maxrate * 1000); 6126 if (status) 6127 netdev_err(netdev, "Unable to set Tx max rate, error %d\n", 6128 status); 6129 6130 return status; 6131 } 6132 6133 /** 6134 * ice_fdb_add - add an entry to the hardware database 6135 * @ndm: the input from the stack 6136 * @tb: pointer to array of nladdr (unused) 6137 * @dev: the net device pointer 6138 * @addr: the MAC address entry being added 6139 * @vid: VLAN ID 6140 * @flags: instructions from stack about fdb operation 6141 * @notified: whether notification was emitted 6142 * @extack: netlink extended ack 6143 */ 6144 static int 6145 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[], 6146 struct net_device *dev, const unsigned char *addr, u16 vid, 6147 u16 flags, bool *notified, 6148 struct netlink_ext_ack __always_unused *extack) 6149 { 6150 int err; 6151 6152 if (vid) { 6153 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n"); 6154 return -EINVAL; 6155 } 6156 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { 6157 netdev_err(dev, "FDB only supports static addresses\n"); 6158 return -EINVAL; 6159 } 6160 6161 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) 6162 err = dev_uc_add_excl(dev, addr); 6163 else if (is_multicast_ether_addr(addr)) 6164 err = dev_mc_add_excl(dev, addr); 6165 else 6166 err = -EINVAL; 6167 6168 /* Only return duplicate errors if NLM_F_EXCL is set */ 6169 if (err == -EEXIST && !(flags & NLM_F_EXCL)) 6170 err = 0; 6171 6172 return err; 6173 } 6174 6175 /** 6176 * ice_fdb_del - delete an entry from the hardware database 6177 * @ndm: the input from the stack 6178 * @tb: pointer to array of nladdr (unused) 6179 * @dev: the net device pointer 6180 * @addr: the MAC address entry being added 6181 * @vid: VLAN ID 6182 * @notified: whether notification was emitted 6183 * @extack: netlink extended ack 6184 */ 6185 static int 6186 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[], 6187 struct net_device *dev, const unsigned char *addr, 6188 __always_unused u16 vid, bool *notified, 6189 struct netlink_ext_ack *extack) 6190 { 6191 int err; 6192 6193 if (ndm->ndm_state & NUD_PERMANENT) { 6194 netdev_err(dev, "FDB only supports static addresses\n"); 6195 return -EINVAL; 6196 } 6197 6198 if (is_unicast_ether_addr(addr)) 6199 err = dev_uc_del(dev, addr); 6200 else if (is_multicast_ether_addr(addr)) 6201 err = dev_mc_del(dev, addr); 6202 else 6203 err = -EINVAL; 6204 6205 return err; 6206 } 6207 6208 #define NETIF_VLAN_OFFLOAD_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \ 6209 NETIF_F_HW_VLAN_CTAG_TX | \ 6210 NETIF_F_HW_VLAN_STAG_RX | \ 6211 NETIF_F_HW_VLAN_STAG_TX) 6212 6213 #define NETIF_VLAN_STRIPPING_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \ 6214 NETIF_F_HW_VLAN_STAG_RX) 6215 6216 #define NETIF_VLAN_FILTERING_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \ 6217 NETIF_F_HW_VLAN_STAG_FILTER) 6218 6219 /** 6220 * ice_fix_features - fix the netdev features flags based on device limitations 6221 * @netdev: ptr to the netdev that flags are being fixed on 6222 * @features: features that need to be checked and possibly fixed 6223 * 6224 * Make sure any fixups are made to features in this callback. This enables the 6225 * driver to not have to check unsupported configurations throughout the driver 6226 * because that's the responsiblity of this callback. 6227 * 6228 * Single VLAN Mode (SVM) Supported Features: 6229 * NETIF_F_HW_VLAN_CTAG_FILTER 6230 * NETIF_F_HW_VLAN_CTAG_RX 6231 * NETIF_F_HW_VLAN_CTAG_TX 6232 * 6233 * Double VLAN Mode (DVM) Supported Features: 6234 * NETIF_F_HW_VLAN_CTAG_FILTER 6235 * NETIF_F_HW_VLAN_CTAG_RX 6236 * NETIF_F_HW_VLAN_CTAG_TX 6237 * 6238 * NETIF_F_HW_VLAN_STAG_FILTER 6239 * NETIF_HW_VLAN_STAG_RX 6240 * NETIF_HW_VLAN_STAG_TX 6241 * 6242 * Features that need fixing: 6243 * Cannot simultaneously enable CTAG and STAG stripping and/or insertion. 6244 * These are mutually exlusive as the VSI context cannot support multiple 6245 * VLAN ethertypes simultaneously for stripping and/or insertion. If this 6246 * is not done, then default to clearing the requested STAG offload 6247 * settings. 6248 * 6249 * All supported filtering has to be enabled or disabled together. For 6250 * example, in DVM, CTAG and STAG filtering have to be enabled and disabled 6251 * together. If this is not done, then default to VLAN filtering disabled. 6252 * These are mutually exclusive as there is currently no way to 6253 * enable/disable VLAN filtering based on VLAN ethertype when using VLAN 6254 * prune rules. 6255 */ 6256 static netdev_features_t 6257 ice_fix_features(struct net_device *netdev, netdev_features_t features) 6258 { 6259 struct ice_netdev_priv *np = netdev_priv(netdev); 6260 netdev_features_t req_vlan_fltr, cur_vlan_fltr; 6261 bool cur_ctag, cur_stag, req_ctag, req_stag; 6262 6263 cur_vlan_fltr = netdev->features & NETIF_VLAN_FILTERING_FEATURES; 6264 cur_ctag = cur_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER; 6265 cur_stag = cur_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER; 6266 6267 req_vlan_fltr = features & NETIF_VLAN_FILTERING_FEATURES; 6268 req_ctag = req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER; 6269 req_stag = req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER; 6270 6271 if (req_vlan_fltr != cur_vlan_fltr) { 6272 if (ice_is_dvm_ena(&np->vsi->back->hw)) { 6273 if (req_ctag && req_stag) { 6274 features |= NETIF_VLAN_FILTERING_FEATURES; 6275 } else if (!req_ctag && !req_stag) { 6276 features &= ~NETIF_VLAN_FILTERING_FEATURES; 6277 } else if ((!cur_ctag && req_ctag && !cur_stag) || 6278 (!cur_stag && req_stag && !cur_ctag)) { 6279 features |= NETIF_VLAN_FILTERING_FEATURES; 6280 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been enabled for both types.\n"); 6281 } else if ((cur_ctag && !req_ctag && cur_stag) || 6282 (cur_stag && !req_stag && cur_ctag)) { 6283 features &= ~NETIF_VLAN_FILTERING_FEATURES; 6284 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been disabled for both types.\n"); 6285 } 6286 } else { 6287 if (req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER) 6288 netdev_warn(netdev, "cannot support requested 802.1ad filtering setting in SVM mode\n"); 6289 6290 if (req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER) 6291 features |= NETIF_F_HW_VLAN_CTAG_FILTER; 6292 } 6293 } 6294 6295 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) && 6296 (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))) { 6297 netdev_warn(netdev, "cannot support CTAG and STAG VLAN stripping and/or insertion simultaneously since CTAG and STAG offloads are mutually exclusive, clearing STAG offload settings\n"); 6298 features &= ~(NETIF_F_HW_VLAN_STAG_RX | 6299 NETIF_F_HW_VLAN_STAG_TX); 6300 } 6301 6302 if (!(netdev->features & NETIF_F_RXFCS) && 6303 (features & NETIF_F_RXFCS) && 6304 (features & NETIF_VLAN_STRIPPING_FEATURES) && 6305 !ice_vsi_has_non_zero_vlans(np->vsi)) { 6306 netdev_warn(netdev, "Disabling VLAN stripping as FCS/CRC stripping is also disabled and there is no VLAN configured\n"); 6307 features &= ~NETIF_VLAN_STRIPPING_FEATURES; 6308 } 6309 6310 return features; 6311 } 6312 6313 /** 6314 * ice_set_rx_rings_vlan_proto - update rings with new stripped VLAN proto 6315 * @vsi: PF's VSI 6316 * @vlan_ethertype: VLAN ethertype (802.1Q or 802.1ad) in network byte order 6317 * 6318 * Store current stripped VLAN proto in ring packet context, 6319 * so it can be accessed more efficiently by packet processing code. 6320 */ 6321 static void 6322 ice_set_rx_rings_vlan_proto(struct ice_vsi *vsi, __be16 vlan_ethertype) 6323 { 6324 u16 i; 6325 6326 ice_for_each_alloc_rxq(vsi, i) 6327 vsi->rx_rings[i]->pkt_ctx.vlan_proto = vlan_ethertype; 6328 } 6329 6330 /** 6331 * ice_set_vlan_offload_features - set VLAN offload features for the PF VSI 6332 * @vsi: PF's VSI 6333 * @features: features used to determine VLAN offload settings 6334 * 6335 * First, determine the vlan_ethertype based on the VLAN offload bits in 6336 * features. Then determine if stripping and insertion should be enabled or 6337 * disabled. Finally enable or disable VLAN stripping and insertion. 6338 */ 6339 static int 6340 ice_set_vlan_offload_features(struct ice_vsi *vsi, netdev_features_t features) 6341 { 6342 bool enable_stripping = true, enable_insertion = true; 6343 struct ice_vsi_vlan_ops *vlan_ops; 6344 int strip_err = 0, insert_err = 0; 6345 u16 vlan_ethertype = 0; 6346 6347 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 6348 6349 if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX)) 6350 vlan_ethertype = ETH_P_8021AD; 6351 else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) 6352 vlan_ethertype = ETH_P_8021Q; 6353 6354 if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX))) 6355 enable_stripping = false; 6356 if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX))) 6357 enable_insertion = false; 6358 6359 if (enable_stripping) 6360 strip_err = vlan_ops->ena_stripping(vsi, vlan_ethertype); 6361 else 6362 strip_err = vlan_ops->dis_stripping(vsi); 6363 6364 if (enable_insertion) 6365 insert_err = vlan_ops->ena_insertion(vsi, vlan_ethertype); 6366 else 6367 insert_err = vlan_ops->dis_insertion(vsi); 6368 6369 if (strip_err || insert_err) 6370 return -EIO; 6371 6372 ice_set_rx_rings_vlan_proto(vsi, enable_stripping ? 6373 htons(vlan_ethertype) : 0); 6374 6375 return 0; 6376 } 6377 6378 /** 6379 * ice_set_vlan_filtering_features - set VLAN filtering features for the PF VSI 6380 * @vsi: PF's VSI 6381 * @features: features used to determine VLAN filtering settings 6382 * 6383 * Enable or disable Rx VLAN filtering based on the VLAN filtering bits in the 6384 * features. 6385 */ 6386 static int 6387 ice_set_vlan_filtering_features(struct ice_vsi *vsi, netdev_features_t features) 6388 { 6389 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi); 6390 int err = 0; 6391 6392 /* support Single VLAN Mode (SVM) and Double VLAN Mode (DVM) by checking 6393 * if either bit is set. In switchdev mode Rx filtering should never be 6394 * enabled. 6395 */ 6396 if ((features & 6397 (NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER)) && 6398 !ice_is_eswitch_mode_switchdev(vsi->back)) 6399 err = vlan_ops->ena_rx_filtering(vsi); 6400 else 6401 err = vlan_ops->dis_rx_filtering(vsi); 6402 6403 return err; 6404 } 6405 6406 /** 6407 * ice_set_vlan_features - set VLAN settings based on suggested feature set 6408 * @netdev: ptr to the netdev being adjusted 6409 * @features: the feature set that the stack is suggesting 6410 * 6411 * Only update VLAN settings if the requested_vlan_features are different than 6412 * the current_vlan_features. 6413 */ 6414 static int 6415 ice_set_vlan_features(struct net_device *netdev, netdev_features_t features) 6416 { 6417 netdev_features_t current_vlan_features, requested_vlan_features; 6418 struct ice_netdev_priv *np = netdev_priv(netdev); 6419 struct ice_vsi *vsi = np->vsi; 6420 int err; 6421 6422 current_vlan_features = netdev->features & NETIF_VLAN_OFFLOAD_FEATURES; 6423 requested_vlan_features = features & NETIF_VLAN_OFFLOAD_FEATURES; 6424 if (current_vlan_features ^ requested_vlan_features) { 6425 if ((features & NETIF_F_RXFCS) && 6426 (features & NETIF_VLAN_STRIPPING_FEATURES)) { 6427 dev_err(ice_pf_to_dev(vsi->back), 6428 "To enable VLAN stripping, you must first enable FCS/CRC stripping\n"); 6429 return -EIO; 6430 } 6431 6432 err = ice_set_vlan_offload_features(vsi, features); 6433 if (err) 6434 return err; 6435 } 6436 6437 current_vlan_features = netdev->features & 6438 NETIF_VLAN_FILTERING_FEATURES; 6439 requested_vlan_features = features & NETIF_VLAN_FILTERING_FEATURES; 6440 if (current_vlan_features ^ requested_vlan_features) { 6441 err = ice_set_vlan_filtering_features(vsi, features); 6442 if (err) 6443 return err; 6444 } 6445 6446 return 0; 6447 } 6448 6449 /** 6450 * ice_set_loopback - turn on/off loopback mode on underlying PF 6451 * @vsi: ptr to VSI 6452 * @ena: flag to indicate the on/off setting 6453 */ 6454 static int ice_set_loopback(struct ice_vsi *vsi, bool ena) 6455 { 6456 bool if_running = netif_running(vsi->netdev); 6457 int ret; 6458 6459 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) { 6460 ret = ice_down(vsi); 6461 if (ret) { 6462 netdev_err(vsi->netdev, "Preparing device to toggle loopback failed\n"); 6463 return ret; 6464 } 6465 } 6466 ret = ice_aq_set_mac_loopback(&vsi->back->hw, ena, NULL); 6467 if (ret) 6468 netdev_err(vsi->netdev, "Failed to toggle loopback state\n"); 6469 if (if_running) 6470 ret = ice_up(vsi); 6471 6472 return ret; 6473 } 6474 6475 /** 6476 * ice_set_features - set the netdev feature flags 6477 * @netdev: ptr to the netdev being adjusted 6478 * @features: the feature set that the stack is suggesting 6479 */ 6480 static int 6481 ice_set_features(struct net_device *netdev, netdev_features_t features) 6482 { 6483 netdev_features_t changed = netdev->features ^ features; 6484 struct ice_netdev_priv *np = netdev_priv(netdev); 6485 struct ice_vsi *vsi = np->vsi; 6486 struct ice_pf *pf = vsi->back; 6487 int ret = 0; 6488 6489 /* Don't set any netdev advanced features with device in Safe Mode */ 6490 if (ice_is_safe_mode(pf)) { 6491 dev_err(ice_pf_to_dev(pf), 6492 "Device is in Safe Mode - not enabling advanced netdev features\n"); 6493 return ret; 6494 } 6495 6496 /* Do not change setting during reset */ 6497 if (ice_is_reset_in_progress(pf->state)) { 6498 dev_err(ice_pf_to_dev(pf), 6499 "Device is resetting, changing advanced netdev features temporarily unavailable.\n"); 6500 return -EBUSY; 6501 } 6502 6503 /* Multiple features can be changed in one call so keep features in 6504 * separate if/else statements to guarantee each feature is checked 6505 */ 6506 if (changed & NETIF_F_RXHASH) 6507 ice_vsi_manage_rss_lut(vsi, !!(features & NETIF_F_RXHASH)); 6508 6509 ret = ice_set_vlan_features(netdev, features); 6510 if (ret) 6511 return ret; 6512 6513 /* Turn on receive of FCS aka CRC, and after setting this 6514 * flag the packet data will have the 4 byte CRC appended 6515 */ 6516 if (changed & NETIF_F_RXFCS) { 6517 if ((features & NETIF_F_RXFCS) && 6518 (features & NETIF_VLAN_STRIPPING_FEATURES)) { 6519 dev_err(ice_pf_to_dev(vsi->back), 6520 "To disable FCS/CRC stripping, you must first disable VLAN stripping\n"); 6521 return -EIO; 6522 } 6523 6524 ice_vsi_cfg_crc_strip(vsi, !!(features & NETIF_F_RXFCS)); 6525 ret = ice_down_up(vsi); 6526 if (ret) 6527 return ret; 6528 } 6529 6530 if (changed & NETIF_F_NTUPLE) { 6531 bool ena = !!(features & NETIF_F_NTUPLE); 6532 6533 ice_vsi_manage_fdir(vsi, ena); 6534 ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi); 6535 } 6536 6537 /* don't turn off hw_tc_offload when ADQ is already enabled */ 6538 if (!(features & NETIF_F_HW_TC) && ice_is_adq_active(pf)) { 6539 dev_err(ice_pf_to_dev(pf), "ADQ is active, can't turn hw_tc_offload off\n"); 6540 return -EACCES; 6541 } 6542 6543 if (changed & NETIF_F_HW_TC) { 6544 bool ena = !!(features & NETIF_F_HW_TC); 6545 6546 assign_bit(ICE_FLAG_CLS_FLOWER, pf->flags, ena); 6547 } 6548 6549 if (changed & NETIF_F_LOOPBACK) 6550 ret = ice_set_loopback(vsi, !!(features & NETIF_F_LOOPBACK)); 6551 6552 return ret; 6553 } 6554 6555 /** 6556 * ice_vsi_vlan_setup - Setup VLAN offload properties on a PF VSI 6557 * @vsi: VSI to setup VLAN properties for 6558 */ 6559 static int ice_vsi_vlan_setup(struct ice_vsi *vsi) 6560 { 6561 int err; 6562 6563 err = ice_set_vlan_offload_features(vsi, vsi->netdev->features); 6564 if (err) 6565 return err; 6566 6567 err = ice_set_vlan_filtering_features(vsi, vsi->netdev->features); 6568 if (err) 6569 return err; 6570 6571 return ice_vsi_add_vlan_zero(vsi); 6572 } 6573 6574 /** 6575 * ice_vsi_cfg_lan - Setup the VSI lan related config 6576 * @vsi: the VSI being configured 6577 * 6578 * Return 0 on success and negative value on error 6579 */ 6580 int ice_vsi_cfg_lan(struct ice_vsi *vsi) 6581 { 6582 int err; 6583 6584 if (vsi->netdev && vsi->type == ICE_VSI_PF) { 6585 ice_set_rx_mode(vsi->netdev); 6586 6587 err = ice_vsi_vlan_setup(vsi); 6588 if (err) 6589 return err; 6590 } 6591 ice_vsi_cfg_dcb_rings(vsi); 6592 6593 err = ice_vsi_cfg_lan_txqs(vsi); 6594 if (!err && ice_is_xdp_ena_vsi(vsi)) 6595 err = ice_vsi_cfg_xdp_txqs(vsi); 6596 if (!err) 6597 err = ice_vsi_cfg_rxqs(vsi); 6598 6599 return err; 6600 } 6601 6602 /* THEORY OF MODERATION: 6603 * The ice driver hardware works differently than the hardware that DIMLIB was 6604 * originally made for. ice hardware doesn't have packet count limits that 6605 * can trigger an interrupt, but it *does* have interrupt rate limit support, 6606 * which is hard-coded to a limit of 250,000 ints/second. 6607 * If not using dynamic moderation, the INTRL value can be modified 6608 * by ethtool rx-usecs-high. 6609 */ 6610 struct ice_dim { 6611 /* the throttle rate for interrupts, basically worst case delay before 6612 * an initial interrupt fires, value is stored in microseconds. 6613 */ 6614 u16 itr; 6615 }; 6616 6617 /* Make a different profile for Rx that doesn't allow quite so aggressive 6618 * moderation at the high end (it maxes out at 126us or about 8k interrupts a 6619 * second. 6620 */ 6621 static const struct ice_dim rx_profile[] = { 6622 {2}, /* 500,000 ints/s, capped at 250K by INTRL */ 6623 {8}, /* 125,000 ints/s */ 6624 {16}, /* 62,500 ints/s */ 6625 {62}, /* 16,129 ints/s */ 6626 {126} /* 7,936 ints/s */ 6627 }; 6628 6629 /* The transmit profile, which has the same sorts of values 6630 * as the previous struct 6631 */ 6632 static const struct ice_dim tx_profile[] = { 6633 {2}, /* 500,000 ints/s, capped at 250K by INTRL */ 6634 {8}, /* 125,000 ints/s */ 6635 {40}, /* 16,125 ints/s */ 6636 {128}, /* 7,812 ints/s */ 6637 {256} /* 3,906 ints/s */ 6638 }; 6639 6640 static void ice_tx_dim_work(struct work_struct *work) 6641 { 6642 struct ice_ring_container *rc; 6643 struct dim *dim; 6644 u16 itr; 6645 6646 dim = container_of(work, struct dim, work); 6647 rc = dim->priv; 6648 6649 WARN_ON(dim->profile_ix >= ARRAY_SIZE(tx_profile)); 6650 6651 /* look up the values in our local table */ 6652 itr = tx_profile[dim->profile_ix].itr; 6653 6654 ice_trace(tx_dim_work, container_of(rc, struct ice_q_vector, tx), dim); 6655 ice_write_itr(rc, itr); 6656 6657 dim->state = DIM_START_MEASURE; 6658 } 6659 6660 static void ice_rx_dim_work(struct work_struct *work) 6661 { 6662 struct ice_ring_container *rc; 6663 struct dim *dim; 6664 u16 itr; 6665 6666 dim = container_of(work, struct dim, work); 6667 rc = dim->priv; 6668 6669 WARN_ON(dim->profile_ix >= ARRAY_SIZE(rx_profile)); 6670 6671 /* look up the values in our local table */ 6672 itr = rx_profile[dim->profile_ix].itr; 6673 6674 ice_trace(rx_dim_work, container_of(rc, struct ice_q_vector, rx), dim); 6675 ice_write_itr(rc, itr); 6676 6677 dim->state = DIM_START_MEASURE; 6678 } 6679 6680 #define ICE_DIM_DEFAULT_PROFILE_IX 1 6681 6682 /** 6683 * ice_init_moderation - set up interrupt moderation 6684 * @q_vector: the vector containing rings to be configured 6685 * 6686 * Set up interrupt moderation registers, with the intent to do the right thing 6687 * when called from reset or from probe, and whether or not dynamic moderation 6688 * is enabled or not. Take special care to write all the registers in both 6689 * dynamic moderation mode or not in order to make sure hardware is in a known 6690 * state. 6691 */ 6692 static void ice_init_moderation(struct ice_q_vector *q_vector) 6693 { 6694 struct ice_ring_container *rc; 6695 bool tx_dynamic, rx_dynamic; 6696 6697 rc = &q_vector->tx; 6698 INIT_WORK(&rc->dim.work, ice_tx_dim_work); 6699 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; 6700 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX; 6701 rc->dim.priv = rc; 6702 tx_dynamic = ITR_IS_DYNAMIC(rc); 6703 6704 /* set the initial TX ITR to match the above */ 6705 ice_write_itr(rc, tx_dynamic ? 6706 tx_profile[rc->dim.profile_ix].itr : rc->itr_setting); 6707 6708 rc = &q_vector->rx; 6709 INIT_WORK(&rc->dim.work, ice_rx_dim_work); 6710 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; 6711 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX; 6712 rc->dim.priv = rc; 6713 rx_dynamic = ITR_IS_DYNAMIC(rc); 6714 6715 /* set the initial RX ITR to match the above */ 6716 ice_write_itr(rc, rx_dynamic ? rx_profile[rc->dim.profile_ix].itr : 6717 rc->itr_setting); 6718 6719 ice_set_q_vector_intrl(q_vector); 6720 } 6721 6722 /** 6723 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI 6724 * @vsi: the VSI being configured 6725 */ 6726 static void ice_napi_enable_all(struct ice_vsi *vsi) 6727 { 6728 int q_idx; 6729 6730 if (!vsi->netdev) 6731 return; 6732 6733 ice_for_each_q_vector(vsi, q_idx) { 6734 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx]; 6735 6736 ice_init_moderation(q_vector); 6737 6738 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring) 6739 napi_enable(&q_vector->napi); 6740 } 6741 } 6742 6743 /** 6744 * ice_up_complete - Finish the last steps of bringing up a connection 6745 * @vsi: The VSI being configured 6746 * 6747 * Return 0 on success and negative value on error 6748 */ 6749 static int ice_up_complete(struct ice_vsi *vsi) 6750 { 6751 struct ice_pf *pf = vsi->back; 6752 int err; 6753 6754 ice_vsi_cfg_msix(vsi); 6755 6756 /* Enable only Rx rings, Tx rings were enabled by the FW when the 6757 * Tx queue group list was configured and the context bits were 6758 * programmed using ice_vsi_cfg_txqs 6759 */ 6760 err = ice_vsi_start_all_rx_rings(vsi); 6761 if (err) 6762 return err; 6763 6764 clear_bit(ICE_VSI_DOWN, vsi->state); 6765 ice_napi_enable_all(vsi); 6766 ice_vsi_ena_irq(vsi); 6767 6768 if (vsi->port_info && 6769 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) && 6770 ((vsi->netdev && (vsi->type == ICE_VSI_PF || 6771 vsi->type == ICE_VSI_SF)))) { 6772 ice_print_link_msg(vsi, true); 6773 netif_tx_start_all_queues(vsi->netdev); 6774 netif_carrier_on(vsi->netdev); 6775 ice_ptp_link_change(pf, true); 6776 } 6777 6778 /* Perform an initial read of the statistics registers now to 6779 * set the baseline so counters are ready when interface is up 6780 */ 6781 ice_update_eth_stats(vsi); 6782 6783 if (vsi->type == ICE_VSI_PF) 6784 ice_service_task_schedule(pf); 6785 6786 return 0; 6787 } 6788 6789 /** 6790 * ice_up - Bring the connection back up after being down 6791 * @vsi: VSI being configured 6792 */ 6793 int ice_up(struct ice_vsi *vsi) 6794 { 6795 int err; 6796 6797 err = ice_vsi_cfg_lan(vsi); 6798 if (!err) 6799 err = ice_up_complete(vsi); 6800 6801 return err; 6802 } 6803 6804 /** 6805 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring 6806 * @syncp: pointer to u64_stats_sync 6807 * @stats: stats that pkts and bytes count will be taken from 6808 * @pkts: packets stats counter 6809 * @bytes: bytes stats counter 6810 * 6811 * This function fetches stats from the ring considering the atomic operations 6812 * that needs to be performed to read u64 values in 32 bit machine. 6813 */ 6814 void 6815 ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp, 6816 struct ice_q_stats stats, u64 *pkts, u64 *bytes) 6817 { 6818 unsigned int start; 6819 6820 do { 6821 start = u64_stats_fetch_begin(syncp); 6822 *pkts = stats.pkts; 6823 *bytes = stats.bytes; 6824 } while (u64_stats_fetch_retry(syncp, start)); 6825 } 6826 6827 /** 6828 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters 6829 * @vsi: the VSI to be updated 6830 * @vsi_stats: the stats struct to be updated 6831 * @rings: rings to work on 6832 * @count: number of rings 6833 */ 6834 static void 6835 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi, 6836 struct rtnl_link_stats64 *vsi_stats, 6837 struct ice_tx_ring **rings, u16 count) 6838 { 6839 u16 i; 6840 6841 for (i = 0; i < count; i++) { 6842 struct ice_tx_ring *ring; 6843 u64 pkts = 0, bytes = 0; 6844 6845 ring = READ_ONCE(rings[i]); 6846 if (!ring || !ring->ring_stats) 6847 continue; 6848 ice_fetch_u64_stats_per_ring(&ring->ring_stats->syncp, 6849 ring->ring_stats->stats, &pkts, 6850 &bytes); 6851 vsi_stats->tx_packets += pkts; 6852 vsi_stats->tx_bytes += bytes; 6853 vsi->tx_restart += ring->ring_stats->tx_stats.restart_q; 6854 vsi->tx_busy += ring->ring_stats->tx_stats.tx_busy; 6855 vsi->tx_linearize += ring->ring_stats->tx_stats.tx_linearize; 6856 } 6857 } 6858 6859 /** 6860 * ice_update_vsi_ring_stats - Update VSI stats counters 6861 * @vsi: the VSI to be updated 6862 */ 6863 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi) 6864 { 6865 struct rtnl_link_stats64 *net_stats, *stats_prev; 6866 struct rtnl_link_stats64 *vsi_stats; 6867 struct ice_pf *pf = vsi->back; 6868 u64 pkts, bytes; 6869 int i; 6870 6871 vsi_stats = kzalloc(sizeof(*vsi_stats), GFP_ATOMIC); 6872 if (!vsi_stats) 6873 return; 6874 6875 /* reset non-netdev (extended) stats */ 6876 vsi->tx_restart = 0; 6877 vsi->tx_busy = 0; 6878 vsi->tx_linearize = 0; 6879 vsi->rx_buf_failed = 0; 6880 vsi->rx_page_failed = 0; 6881 6882 rcu_read_lock(); 6883 6884 /* update Tx rings counters */ 6885 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->tx_rings, 6886 vsi->num_txq); 6887 6888 /* update Rx rings counters */ 6889 ice_for_each_rxq(vsi, i) { 6890 struct ice_rx_ring *ring = READ_ONCE(vsi->rx_rings[i]); 6891 struct ice_ring_stats *ring_stats; 6892 6893 ring_stats = ring->ring_stats; 6894 ice_fetch_u64_stats_per_ring(&ring_stats->syncp, 6895 ring_stats->stats, &pkts, 6896 &bytes); 6897 vsi_stats->rx_packets += pkts; 6898 vsi_stats->rx_bytes += bytes; 6899 vsi->rx_buf_failed += ring_stats->rx_stats.alloc_buf_failed; 6900 vsi->rx_page_failed += ring_stats->rx_stats.alloc_page_failed; 6901 } 6902 6903 /* update XDP Tx rings counters */ 6904 if (ice_is_xdp_ena_vsi(vsi)) 6905 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->xdp_rings, 6906 vsi->num_xdp_txq); 6907 6908 rcu_read_unlock(); 6909 6910 net_stats = &vsi->net_stats; 6911 stats_prev = &vsi->net_stats_prev; 6912 6913 /* Update netdev counters, but keep in mind that values could start at 6914 * random value after PF reset. And as we increase the reported stat by 6915 * diff of Prev-Cur, we need to be sure that Prev is valid. If it's not, 6916 * let's skip this round. 6917 */ 6918 if (likely(pf->stat_prev_loaded)) { 6919 net_stats->tx_packets += vsi_stats->tx_packets - stats_prev->tx_packets; 6920 net_stats->tx_bytes += vsi_stats->tx_bytes - stats_prev->tx_bytes; 6921 net_stats->rx_packets += vsi_stats->rx_packets - stats_prev->rx_packets; 6922 net_stats->rx_bytes += vsi_stats->rx_bytes - stats_prev->rx_bytes; 6923 } 6924 6925 stats_prev->tx_packets = vsi_stats->tx_packets; 6926 stats_prev->tx_bytes = vsi_stats->tx_bytes; 6927 stats_prev->rx_packets = vsi_stats->rx_packets; 6928 stats_prev->rx_bytes = vsi_stats->rx_bytes; 6929 6930 kfree(vsi_stats); 6931 } 6932 6933 /** 6934 * ice_update_vsi_stats - Update VSI stats counters 6935 * @vsi: the VSI to be updated 6936 */ 6937 void ice_update_vsi_stats(struct ice_vsi *vsi) 6938 { 6939 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats; 6940 struct ice_eth_stats *cur_es = &vsi->eth_stats; 6941 struct ice_pf *pf = vsi->back; 6942 6943 if (test_bit(ICE_VSI_DOWN, vsi->state) || 6944 test_bit(ICE_CFG_BUSY, pf->state)) 6945 return; 6946 6947 /* get stats as recorded by Tx/Rx rings */ 6948 ice_update_vsi_ring_stats(vsi); 6949 6950 /* get VSI stats as recorded by the hardware */ 6951 ice_update_eth_stats(vsi); 6952 6953 cur_ns->tx_errors = cur_es->tx_errors; 6954 cur_ns->rx_dropped = cur_es->rx_discards; 6955 cur_ns->tx_dropped = cur_es->tx_discards; 6956 cur_ns->multicast = cur_es->rx_multicast; 6957 6958 /* update some more netdev stats if this is main VSI */ 6959 if (vsi->type == ICE_VSI_PF) { 6960 cur_ns->rx_crc_errors = pf->stats.crc_errors; 6961 cur_ns->rx_errors = pf->stats.crc_errors + 6962 pf->stats.illegal_bytes + 6963 pf->stats.rx_undersize + 6964 pf->hw_csum_rx_error + 6965 pf->stats.rx_jabber + 6966 pf->stats.rx_fragments + 6967 pf->stats.rx_oversize; 6968 /* record drops from the port level */ 6969 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards; 6970 } 6971 } 6972 6973 /** 6974 * ice_update_pf_stats - Update PF port stats counters 6975 * @pf: PF whose stats needs to be updated 6976 */ 6977 void ice_update_pf_stats(struct ice_pf *pf) 6978 { 6979 struct ice_hw_port_stats *prev_ps, *cur_ps; 6980 struct ice_hw *hw = &pf->hw; 6981 u16 fd_ctr_base; 6982 u8 port; 6983 6984 port = hw->port_info->lport; 6985 prev_ps = &pf->stats_prev; 6986 cur_ps = &pf->stats; 6987 6988 if (ice_is_reset_in_progress(pf->state)) 6989 pf->stat_prev_loaded = false; 6990 6991 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded, 6992 &prev_ps->eth.rx_bytes, 6993 &cur_ps->eth.rx_bytes); 6994 6995 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded, 6996 &prev_ps->eth.rx_unicast, 6997 &cur_ps->eth.rx_unicast); 6998 6999 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded, 7000 &prev_ps->eth.rx_multicast, 7001 &cur_ps->eth.rx_multicast); 7002 7003 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded, 7004 &prev_ps->eth.rx_broadcast, 7005 &cur_ps->eth.rx_broadcast); 7006 7007 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded, 7008 &prev_ps->eth.rx_discards, 7009 &cur_ps->eth.rx_discards); 7010 7011 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded, 7012 &prev_ps->eth.tx_bytes, 7013 &cur_ps->eth.tx_bytes); 7014 7015 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded, 7016 &prev_ps->eth.tx_unicast, 7017 &cur_ps->eth.tx_unicast); 7018 7019 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded, 7020 &prev_ps->eth.tx_multicast, 7021 &cur_ps->eth.tx_multicast); 7022 7023 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded, 7024 &prev_ps->eth.tx_broadcast, 7025 &cur_ps->eth.tx_broadcast); 7026 7027 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded, 7028 &prev_ps->tx_dropped_link_down, 7029 &cur_ps->tx_dropped_link_down); 7030 7031 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded, 7032 &prev_ps->rx_size_64, &cur_ps->rx_size_64); 7033 7034 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded, 7035 &prev_ps->rx_size_127, &cur_ps->rx_size_127); 7036 7037 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded, 7038 &prev_ps->rx_size_255, &cur_ps->rx_size_255); 7039 7040 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded, 7041 &prev_ps->rx_size_511, &cur_ps->rx_size_511); 7042 7043 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded, 7044 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023); 7045 7046 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded, 7047 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522); 7048 7049 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded, 7050 &prev_ps->rx_size_big, &cur_ps->rx_size_big); 7051 7052 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded, 7053 &prev_ps->tx_size_64, &cur_ps->tx_size_64); 7054 7055 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded, 7056 &prev_ps->tx_size_127, &cur_ps->tx_size_127); 7057 7058 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded, 7059 &prev_ps->tx_size_255, &cur_ps->tx_size_255); 7060 7061 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded, 7062 &prev_ps->tx_size_511, &cur_ps->tx_size_511); 7063 7064 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded, 7065 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023); 7066 7067 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded, 7068 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522); 7069 7070 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded, 7071 &prev_ps->tx_size_big, &cur_ps->tx_size_big); 7072 7073 fd_ctr_base = hw->fd_ctr_base; 7074 7075 ice_stat_update40(hw, 7076 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)), 7077 pf->stat_prev_loaded, &prev_ps->fd_sb_match, 7078 &cur_ps->fd_sb_match); 7079 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded, 7080 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx); 7081 7082 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded, 7083 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx); 7084 7085 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded, 7086 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx); 7087 7088 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded, 7089 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx); 7090 7091 ice_update_dcb_stats(pf); 7092 7093 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded, 7094 &prev_ps->crc_errors, &cur_ps->crc_errors); 7095 7096 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded, 7097 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes); 7098 7099 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded, 7100 &prev_ps->mac_local_faults, 7101 &cur_ps->mac_local_faults); 7102 7103 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded, 7104 &prev_ps->mac_remote_faults, 7105 &cur_ps->mac_remote_faults); 7106 7107 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded, 7108 &prev_ps->rx_undersize, &cur_ps->rx_undersize); 7109 7110 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded, 7111 &prev_ps->rx_fragments, &cur_ps->rx_fragments); 7112 7113 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded, 7114 &prev_ps->rx_oversize, &cur_ps->rx_oversize); 7115 7116 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded, 7117 &prev_ps->rx_jabber, &cur_ps->rx_jabber); 7118 7119 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0; 7120 7121 pf->stat_prev_loaded = true; 7122 } 7123 7124 /** 7125 * ice_get_stats64 - get statistics for network device structure 7126 * @netdev: network interface device structure 7127 * @stats: main device statistics structure 7128 */ 7129 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) 7130 { 7131 struct ice_netdev_priv *np = netdev_priv(netdev); 7132 struct rtnl_link_stats64 *vsi_stats; 7133 struct ice_vsi *vsi = np->vsi; 7134 7135 vsi_stats = &vsi->net_stats; 7136 7137 if (!vsi->num_txq || !vsi->num_rxq) 7138 return; 7139 7140 /* netdev packet/byte stats come from ring counter. These are obtained 7141 * by summing up ring counters (done by ice_update_vsi_ring_stats). 7142 * But, only call the update routine and read the registers if VSI is 7143 * not down. 7144 */ 7145 if (!test_bit(ICE_VSI_DOWN, vsi->state)) 7146 ice_update_vsi_ring_stats(vsi); 7147 stats->tx_packets = vsi_stats->tx_packets; 7148 stats->tx_bytes = vsi_stats->tx_bytes; 7149 stats->rx_packets = vsi_stats->rx_packets; 7150 stats->rx_bytes = vsi_stats->rx_bytes; 7151 7152 /* The rest of the stats can be read from the hardware but instead we 7153 * just return values that the watchdog task has already obtained from 7154 * the hardware. 7155 */ 7156 stats->multicast = vsi_stats->multicast; 7157 stats->tx_errors = vsi_stats->tx_errors; 7158 stats->tx_dropped = vsi_stats->tx_dropped; 7159 stats->rx_errors = vsi_stats->rx_errors; 7160 stats->rx_dropped = vsi_stats->rx_dropped; 7161 stats->rx_crc_errors = vsi_stats->rx_crc_errors; 7162 stats->rx_length_errors = vsi_stats->rx_length_errors; 7163 } 7164 7165 /** 7166 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI 7167 * @vsi: VSI having NAPI disabled 7168 */ 7169 static void ice_napi_disable_all(struct ice_vsi *vsi) 7170 { 7171 int q_idx; 7172 7173 if (!vsi->netdev) 7174 return; 7175 7176 ice_for_each_q_vector(vsi, q_idx) { 7177 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx]; 7178 7179 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring) 7180 napi_disable(&q_vector->napi); 7181 7182 cancel_work_sync(&q_vector->tx.dim.work); 7183 cancel_work_sync(&q_vector->rx.dim.work); 7184 } 7185 } 7186 7187 /** 7188 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI 7189 * @vsi: the VSI being un-configured 7190 */ 7191 static void ice_vsi_dis_irq(struct ice_vsi *vsi) 7192 { 7193 struct ice_pf *pf = vsi->back; 7194 struct ice_hw *hw = &pf->hw; 7195 u32 val; 7196 int i; 7197 7198 /* disable interrupt causation from each Rx queue; Tx queues are 7199 * handled in ice_vsi_stop_tx_ring() 7200 */ 7201 if (vsi->rx_rings) { 7202 ice_for_each_rxq(vsi, i) { 7203 if (vsi->rx_rings[i]) { 7204 u16 reg; 7205 7206 reg = vsi->rx_rings[i]->reg_idx; 7207 val = rd32(hw, QINT_RQCTL(reg)); 7208 val &= ~QINT_RQCTL_CAUSE_ENA_M; 7209 wr32(hw, QINT_RQCTL(reg), val); 7210 } 7211 } 7212 } 7213 7214 /* disable each interrupt */ 7215 ice_for_each_q_vector(vsi, i) { 7216 if (!vsi->q_vectors[i]) 7217 continue; 7218 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0); 7219 } 7220 7221 ice_flush(hw); 7222 7223 /* don't call synchronize_irq() for VF's from the host */ 7224 if (vsi->type == ICE_VSI_VF) 7225 return; 7226 7227 ice_for_each_q_vector(vsi, i) 7228 synchronize_irq(vsi->q_vectors[i]->irq.virq); 7229 } 7230 7231 /** 7232 * ice_down - Shutdown the connection 7233 * @vsi: The VSI being stopped 7234 * 7235 * Caller of this function is expected to set the vsi->state ICE_DOWN bit 7236 */ 7237 int ice_down(struct ice_vsi *vsi) 7238 { 7239 int i, tx_err, rx_err, vlan_err = 0; 7240 7241 WARN_ON(!test_bit(ICE_VSI_DOWN, vsi->state)); 7242 7243 if (vsi->netdev) { 7244 vlan_err = ice_vsi_del_vlan_zero(vsi); 7245 ice_ptp_link_change(vsi->back, false); 7246 netif_carrier_off(vsi->netdev); 7247 netif_tx_disable(vsi->netdev); 7248 } 7249 7250 ice_vsi_dis_irq(vsi); 7251 7252 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0); 7253 if (tx_err) 7254 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n", 7255 vsi->vsi_num, tx_err); 7256 if (!tx_err && vsi->xdp_rings) { 7257 tx_err = ice_vsi_stop_xdp_tx_rings(vsi); 7258 if (tx_err) 7259 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n", 7260 vsi->vsi_num, tx_err); 7261 } 7262 7263 rx_err = ice_vsi_stop_all_rx_rings(vsi); 7264 if (rx_err) 7265 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n", 7266 vsi->vsi_num, rx_err); 7267 7268 ice_napi_disable_all(vsi); 7269 7270 ice_for_each_txq(vsi, i) 7271 ice_clean_tx_ring(vsi->tx_rings[i]); 7272 7273 if (vsi->xdp_rings) 7274 ice_for_each_xdp_txq(vsi, i) 7275 ice_clean_tx_ring(vsi->xdp_rings[i]); 7276 7277 ice_for_each_rxq(vsi, i) 7278 ice_clean_rx_ring(vsi->rx_rings[i]); 7279 7280 if (tx_err || rx_err || vlan_err) { 7281 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n", 7282 vsi->vsi_num, vsi->vsw->sw_id); 7283 return -EIO; 7284 } 7285 7286 return 0; 7287 } 7288 7289 /** 7290 * ice_down_up - shutdown the VSI connection and bring it up 7291 * @vsi: the VSI to be reconnected 7292 */ 7293 int ice_down_up(struct ice_vsi *vsi) 7294 { 7295 int ret; 7296 7297 /* if DOWN already set, nothing to do */ 7298 if (test_and_set_bit(ICE_VSI_DOWN, vsi->state)) 7299 return 0; 7300 7301 ret = ice_down(vsi); 7302 if (ret) 7303 return ret; 7304 7305 ret = ice_up(vsi); 7306 if (ret) { 7307 netdev_err(vsi->netdev, "reallocating resources failed during netdev features change, may need to reload driver\n"); 7308 return ret; 7309 } 7310 7311 return 0; 7312 } 7313 7314 /** 7315 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources 7316 * @vsi: VSI having resources allocated 7317 * 7318 * Return 0 on success, negative on failure 7319 */ 7320 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi) 7321 { 7322 int i, err = 0; 7323 7324 if (!vsi->num_txq) { 7325 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n", 7326 vsi->vsi_num); 7327 return -EINVAL; 7328 } 7329 7330 ice_for_each_txq(vsi, i) { 7331 struct ice_tx_ring *ring = vsi->tx_rings[i]; 7332 7333 if (!ring) 7334 return -EINVAL; 7335 7336 if (vsi->netdev) 7337 ring->netdev = vsi->netdev; 7338 err = ice_setup_tx_ring(ring); 7339 if (err) 7340 break; 7341 } 7342 7343 return err; 7344 } 7345 7346 /** 7347 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources 7348 * @vsi: VSI having resources allocated 7349 * 7350 * Return 0 on success, negative on failure 7351 */ 7352 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi) 7353 { 7354 int i, err = 0; 7355 7356 if (!vsi->num_rxq) { 7357 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n", 7358 vsi->vsi_num); 7359 return -EINVAL; 7360 } 7361 7362 ice_for_each_rxq(vsi, i) { 7363 struct ice_rx_ring *ring = vsi->rx_rings[i]; 7364 7365 if (!ring) 7366 return -EINVAL; 7367 7368 if (vsi->netdev) 7369 ring->netdev = vsi->netdev; 7370 err = ice_setup_rx_ring(ring); 7371 if (err) 7372 break; 7373 } 7374 7375 return err; 7376 } 7377 7378 /** 7379 * ice_vsi_open_ctrl - open control VSI for use 7380 * @vsi: the VSI to open 7381 * 7382 * Initialization of the Control VSI 7383 * 7384 * Returns 0 on success, negative value on error 7385 */ 7386 int ice_vsi_open_ctrl(struct ice_vsi *vsi) 7387 { 7388 char int_name[ICE_INT_NAME_STR_LEN]; 7389 struct ice_pf *pf = vsi->back; 7390 struct device *dev; 7391 int err; 7392 7393 dev = ice_pf_to_dev(pf); 7394 /* allocate descriptors */ 7395 err = ice_vsi_setup_tx_rings(vsi); 7396 if (err) 7397 goto err_setup_tx; 7398 7399 err = ice_vsi_setup_rx_rings(vsi); 7400 if (err) 7401 goto err_setup_rx; 7402 7403 err = ice_vsi_cfg_lan(vsi); 7404 if (err) 7405 goto err_setup_rx; 7406 7407 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl", 7408 dev_driver_string(dev), dev_name(dev)); 7409 err = ice_vsi_req_irq_msix(vsi, int_name); 7410 if (err) 7411 goto err_setup_rx; 7412 7413 ice_vsi_cfg_msix(vsi); 7414 7415 err = ice_vsi_start_all_rx_rings(vsi); 7416 if (err) 7417 goto err_up_complete; 7418 7419 clear_bit(ICE_VSI_DOWN, vsi->state); 7420 ice_vsi_ena_irq(vsi); 7421 7422 return 0; 7423 7424 err_up_complete: 7425 ice_down(vsi); 7426 err_setup_rx: 7427 ice_vsi_free_rx_rings(vsi); 7428 err_setup_tx: 7429 ice_vsi_free_tx_rings(vsi); 7430 7431 return err; 7432 } 7433 7434 /** 7435 * ice_vsi_open - Called when a network interface is made active 7436 * @vsi: the VSI to open 7437 * 7438 * Initialization of the VSI 7439 * 7440 * Returns 0 on success, negative value on error 7441 */ 7442 int ice_vsi_open(struct ice_vsi *vsi) 7443 { 7444 char int_name[ICE_INT_NAME_STR_LEN]; 7445 struct ice_pf *pf = vsi->back; 7446 int err; 7447 7448 /* allocate descriptors */ 7449 err = ice_vsi_setup_tx_rings(vsi); 7450 if (err) 7451 goto err_setup_tx; 7452 7453 err = ice_vsi_setup_rx_rings(vsi); 7454 if (err) 7455 goto err_setup_rx; 7456 7457 err = ice_vsi_cfg_lan(vsi); 7458 if (err) 7459 goto err_setup_rx; 7460 7461 snprintf(int_name, sizeof(int_name) - 1, "%s-%s", 7462 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name); 7463 err = ice_vsi_req_irq_msix(vsi, int_name); 7464 if (err) 7465 goto err_setup_rx; 7466 7467 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); 7468 7469 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_SF) { 7470 /* Notify the stack of the actual queue counts. */ 7471 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq); 7472 if (err) 7473 goto err_set_qs; 7474 7475 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq); 7476 if (err) 7477 goto err_set_qs; 7478 7479 ice_vsi_set_napi_queues(vsi); 7480 } 7481 7482 err = ice_up_complete(vsi); 7483 if (err) 7484 goto err_up_complete; 7485 7486 return 0; 7487 7488 err_up_complete: 7489 ice_down(vsi); 7490 err_set_qs: 7491 ice_vsi_free_irq(vsi); 7492 err_setup_rx: 7493 ice_vsi_free_rx_rings(vsi); 7494 err_setup_tx: 7495 ice_vsi_free_tx_rings(vsi); 7496 7497 return err; 7498 } 7499 7500 /** 7501 * ice_vsi_release_all - Delete all VSIs 7502 * @pf: PF from which all VSIs are being removed 7503 */ 7504 static void ice_vsi_release_all(struct ice_pf *pf) 7505 { 7506 int err, i; 7507 7508 if (!pf->vsi) 7509 return; 7510 7511 ice_for_each_vsi(pf, i) { 7512 if (!pf->vsi[i]) 7513 continue; 7514 7515 if (pf->vsi[i]->type == ICE_VSI_CHNL) 7516 continue; 7517 7518 err = ice_vsi_release(pf->vsi[i]); 7519 if (err) 7520 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n", 7521 i, err, pf->vsi[i]->vsi_num); 7522 } 7523 } 7524 7525 /** 7526 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type 7527 * @pf: pointer to the PF instance 7528 * @type: VSI type to rebuild 7529 * 7530 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type 7531 */ 7532 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type) 7533 { 7534 struct device *dev = ice_pf_to_dev(pf); 7535 int i, err; 7536 7537 ice_for_each_vsi(pf, i) { 7538 struct ice_vsi *vsi = pf->vsi[i]; 7539 7540 if (!vsi || vsi->type != type) 7541 continue; 7542 7543 /* rebuild the VSI */ 7544 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT); 7545 if (err) { 7546 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n", 7547 err, vsi->idx, ice_vsi_type_str(type)); 7548 return err; 7549 } 7550 7551 /* replay filters for the VSI */ 7552 err = ice_replay_vsi(&pf->hw, vsi->idx); 7553 if (err) { 7554 dev_err(dev, "replay VSI failed, error %d, VSI index %d, type %s\n", 7555 err, vsi->idx, ice_vsi_type_str(type)); 7556 return err; 7557 } 7558 7559 /* Re-map HW VSI number, using VSI handle that has been 7560 * previously validated in ice_replay_vsi() call above 7561 */ 7562 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx); 7563 7564 /* enable the VSI */ 7565 err = ice_ena_vsi(vsi, false); 7566 if (err) { 7567 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n", 7568 err, vsi->idx, ice_vsi_type_str(type)); 7569 return err; 7570 } 7571 7572 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx, 7573 ice_vsi_type_str(type)); 7574 } 7575 7576 return 0; 7577 } 7578 7579 /** 7580 * ice_update_pf_netdev_link - Update PF netdev link status 7581 * @pf: pointer to the PF instance 7582 */ 7583 static void ice_update_pf_netdev_link(struct ice_pf *pf) 7584 { 7585 bool link_up; 7586 int i; 7587 7588 ice_for_each_vsi(pf, i) { 7589 struct ice_vsi *vsi = pf->vsi[i]; 7590 7591 if (!vsi || vsi->type != ICE_VSI_PF) 7592 return; 7593 7594 ice_get_link_status(pf->vsi[i]->port_info, &link_up); 7595 if (link_up) { 7596 netif_carrier_on(pf->vsi[i]->netdev); 7597 netif_tx_wake_all_queues(pf->vsi[i]->netdev); 7598 } else { 7599 netif_carrier_off(pf->vsi[i]->netdev); 7600 netif_tx_stop_all_queues(pf->vsi[i]->netdev); 7601 } 7602 } 7603 } 7604 7605 /** 7606 * ice_rebuild - rebuild after reset 7607 * @pf: PF to rebuild 7608 * @reset_type: type of reset 7609 * 7610 * Do not rebuild VF VSI in this flow because that is already handled via 7611 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a 7612 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want 7613 * to reset/rebuild all the VF VSI twice. 7614 */ 7615 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type) 7616 { 7617 struct ice_vsi *vsi = ice_get_main_vsi(pf); 7618 struct device *dev = ice_pf_to_dev(pf); 7619 struct ice_hw *hw = &pf->hw; 7620 bool dvm; 7621 int err; 7622 7623 if (test_bit(ICE_DOWN, pf->state)) 7624 goto clear_recovery; 7625 7626 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type); 7627 7628 #define ICE_EMP_RESET_SLEEP_MS 5000 7629 if (reset_type == ICE_RESET_EMPR) { 7630 /* If an EMP reset has occurred, any previously pending flash 7631 * update will have completed. We no longer know whether or 7632 * not the NVM update EMP reset is restricted. 7633 */ 7634 pf->fw_emp_reset_disabled = false; 7635 7636 msleep(ICE_EMP_RESET_SLEEP_MS); 7637 } 7638 7639 err = ice_init_all_ctrlq(hw); 7640 if (err) { 7641 dev_err(dev, "control queues init failed %d\n", err); 7642 goto err_init_ctrlq; 7643 } 7644 7645 /* if DDP was previously loaded successfully */ 7646 if (!ice_is_safe_mode(pf)) { 7647 /* reload the SW DB of filter tables */ 7648 if (reset_type == ICE_RESET_PFR) 7649 ice_fill_blk_tbls(hw); 7650 else 7651 /* Reload DDP Package after CORER/GLOBR reset */ 7652 ice_load_pkg(NULL, pf); 7653 } 7654 7655 err = ice_clear_pf_cfg(hw); 7656 if (err) { 7657 dev_err(dev, "clear PF configuration failed %d\n", err); 7658 goto err_init_ctrlq; 7659 } 7660 7661 ice_clear_pxe_mode(hw); 7662 7663 err = ice_init_nvm(hw); 7664 if (err) { 7665 dev_err(dev, "ice_init_nvm failed %d\n", err); 7666 goto err_init_ctrlq; 7667 } 7668 7669 err = ice_get_caps(hw); 7670 if (err) { 7671 dev_err(dev, "ice_get_caps failed %d\n", err); 7672 goto err_init_ctrlq; 7673 } 7674 7675 err = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL); 7676 if (err) { 7677 dev_err(dev, "set_mac_cfg failed %d\n", err); 7678 goto err_init_ctrlq; 7679 } 7680 7681 dvm = ice_is_dvm_ena(hw); 7682 7683 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL); 7684 if (err) 7685 goto err_init_ctrlq; 7686 7687 err = ice_sched_init_port(hw->port_info); 7688 if (err) 7689 goto err_sched_init_port; 7690 7691 /* start misc vector */ 7692 err = ice_req_irq_msix_misc(pf); 7693 if (err) { 7694 dev_err(dev, "misc vector setup failed: %d\n", err); 7695 goto err_sched_init_port; 7696 } 7697 7698 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) { 7699 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M); 7700 if (!rd32(hw, PFQF_FD_SIZE)) { 7701 u16 unused, guar, b_effort; 7702 7703 guar = hw->func_caps.fd_fltr_guar; 7704 b_effort = hw->func_caps.fd_fltr_best_effort; 7705 7706 /* force guaranteed filter pool for PF */ 7707 ice_alloc_fd_guar_item(hw, &unused, guar); 7708 /* force shared filter pool for PF */ 7709 ice_alloc_fd_shrd_item(hw, &unused, b_effort); 7710 } 7711 } 7712 7713 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags)) 7714 ice_dcb_rebuild(pf); 7715 7716 /* If the PF previously had enabled PTP, PTP init needs to happen before 7717 * the VSI rebuild. If not, this causes the PTP link status events to 7718 * fail. 7719 */ 7720 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) 7721 ice_ptp_rebuild(pf, reset_type); 7722 7723 if (ice_is_feature_supported(pf, ICE_F_GNSS)) 7724 ice_gnss_init(pf); 7725 7726 /* rebuild PF VSI */ 7727 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF); 7728 if (err) { 7729 dev_err(dev, "PF VSI rebuild failed: %d\n", err); 7730 goto err_vsi_rebuild; 7731 } 7732 7733 if (reset_type == ICE_RESET_PFR) { 7734 err = ice_rebuild_channels(pf); 7735 if (err) { 7736 dev_err(dev, "failed to rebuild and replay ADQ VSIs, err %d\n", 7737 err); 7738 goto err_vsi_rebuild; 7739 } 7740 } 7741 7742 /* If Flow Director is active */ 7743 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) { 7744 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL); 7745 if (err) { 7746 dev_err(dev, "control VSI rebuild failed: %d\n", err); 7747 goto err_vsi_rebuild; 7748 } 7749 7750 /* replay HW Flow Director recipes */ 7751 if (hw->fdir_prof) 7752 ice_fdir_replay_flows(hw); 7753 7754 /* replay Flow Director filters */ 7755 ice_fdir_replay_fltrs(pf); 7756 7757 ice_rebuild_arfs(pf); 7758 } 7759 7760 if (vsi && vsi->netdev) 7761 netif_device_attach(vsi->netdev); 7762 7763 ice_update_pf_netdev_link(pf); 7764 7765 /* tell the firmware we are up */ 7766 err = ice_send_version(pf); 7767 if (err) { 7768 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n", 7769 err); 7770 goto err_vsi_rebuild; 7771 } 7772 7773 ice_replay_post(hw); 7774 7775 /* if we get here, reset flow is successful */ 7776 clear_bit(ICE_RESET_FAILED, pf->state); 7777 7778 ice_health_clear(pf); 7779 7780 ice_plug_aux_dev(pf); 7781 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG)) 7782 ice_lag_rebuild(pf); 7783 7784 /* Restore timestamp mode settings after VSI rebuild */ 7785 ice_ptp_restore_timestamp_mode(pf); 7786 return; 7787 7788 err_vsi_rebuild: 7789 err_sched_init_port: 7790 ice_sched_cleanup_all(hw); 7791 err_init_ctrlq: 7792 ice_shutdown_all_ctrlq(hw, false); 7793 set_bit(ICE_RESET_FAILED, pf->state); 7794 clear_recovery: 7795 /* set this bit in PF state to control service task scheduling */ 7796 set_bit(ICE_NEEDS_RESTART, pf->state); 7797 dev_err(dev, "Rebuild failed, unload and reload driver\n"); 7798 } 7799 7800 /** 7801 * ice_change_mtu - NDO callback to change the MTU 7802 * @netdev: network interface device structure 7803 * @new_mtu: new value for maximum frame size 7804 * 7805 * Returns 0 on success, negative on failure 7806 */ 7807 int ice_change_mtu(struct net_device *netdev, int new_mtu) 7808 { 7809 struct ice_netdev_priv *np = netdev_priv(netdev); 7810 struct ice_vsi *vsi = np->vsi; 7811 struct ice_pf *pf = vsi->back; 7812 struct bpf_prog *prog; 7813 u8 count = 0; 7814 int err = 0; 7815 7816 if (new_mtu == (int)netdev->mtu) { 7817 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu); 7818 return 0; 7819 } 7820 7821 prog = vsi->xdp_prog; 7822 if (prog && !prog->aux->xdp_has_frags) { 7823 int frame_size = ice_max_xdp_frame_size(vsi); 7824 7825 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) { 7826 netdev_err(netdev, "max MTU for XDP usage is %d\n", 7827 frame_size - ICE_ETH_PKT_HDR_PAD); 7828 return -EINVAL; 7829 } 7830 } else if (test_bit(ICE_FLAG_LEGACY_RX, pf->flags)) { 7831 if (new_mtu + ICE_ETH_PKT_HDR_PAD > ICE_MAX_FRAME_LEGACY_RX) { 7832 netdev_err(netdev, "Too big MTU for legacy-rx; Max is %d\n", 7833 ICE_MAX_FRAME_LEGACY_RX - ICE_ETH_PKT_HDR_PAD); 7834 return -EINVAL; 7835 } 7836 } 7837 7838 /* if a reset is in progress, wait for some time for it to complete */ 7839 do { 7840 if (ice_is_reset_in_progress(pf->state)) { 7841 count++; 7842 usleep_range(1000, 2000); 7843 } else { 7844 break; 7845 } 7846 7847 } while (count < 100); 7848 7849 if (count == 100) { 7850 netdev_err(netdev, "can't change MTU. Device is busy\n"); 7851 return -EBUSY; 7852 } 7853 7854 WRITE_ONCE(netdev->mtu, (unsigned int)new_mtu); 7855 err = ice_down_up(vsi); 7856 if (err) 7857 return err; 7858 7859 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu); 7860 set_bit(ICE_FLAG_MTU_CHANGED, pf->flags); 7861 7862 return err; 7863 } 7864 7865 /** 7866 * ice_eth_ioctl - Access the hwtstamp interface 7867 * @netdev: network interface device structure 7868 * @ifr: interface request data 7869 * @cmd: ioctl command 7870 */ 7871 static int ice_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) 7872 { 7873 struct ice_netdev_priv *np = netdev_priv(netdev); 7874 struct ice_pf *pf = np->vsi->back; 7875 7876 switch (cmd) { 7877 case SIOCGHWTSTAMP: 7878 return ice_ptp_get_ts_config(pf, ifr); 7879 case SIOCSHWTSTAMP: 7880 return ice_ptp_set_ts_config(pf, ifr); 7881 default: 7882 return -EOPNOTSUPP; 7883 } 7884 } 7885 7886 /** 7887 * ice_aq_str - convert AQ err code to a string 7888 * @aq_err: the AQ error code to convert 7889 */ 7890 const char *ice_aq_str(enum ice_aq_err aq_err) 7891 { 7892 switch (aq_err) { 7893 case ICE_AQ_RC_OK: 7894 return "OK"; 7895 case ICE_AQ_RC_EPERM: 7896 return "ICE_AQ_RC_EPERM"; 7897 case ICE_AQ_RC_ENOENT: 7898 return "ICE_AQ_RC_ENOENT"; 7899 case ICE_AQ_RC_ENOMEM: 7900 return "ICE_AQ_RC_ENOMEM"; 7901 case ICE_AQ_RC_EBUSY: 7902 return "ICE_AQ_RC_EBUSY"; 7903 case ICE_AQ_RC_EEXIST: 7904 return "ICE_AQ_RC_EEXIST"; 7905 case ICE_AQ_RC_EINVAL: 7906 return "ICE_AQ_RC_EINVAL"; 7907 case ICE_AQ_RC_ENOSPC: 7908 return "ICE_AQ_RC_ENOSPC"; 7909 case ICE_AQ_RC_ENOSYS: 7910 return "ICE_AQ_RC_ENOSYS"; 7911 case ICE_AQ_RC_EMODE: 7912 return "ICE_AQ_RC_EMODE"; 7913 case ICE_AQ_RC_ENOSEC: 7914 return "ICE_AQ_RC_ENOSEC"; 7915 case ICE_AQ_RC_EBADSIG: 7916 return "ICE_AQ_RC_EBADSIG"; 7917 case ICE_AQ_RC_ESVN: 7918 return "ICE_AQ_RC_ESVN"; 7919 case ICE_AQ_RC_EBADMAN: 7920 return "ICE_AQ_RC_EBADMAN"; 7921 case ICE_AQ_RC_EBADBUF: 7922 return "ICE_AQ_RC_EBADBUF"; 7923 } 7924 7925 return "ICE_AQ_RC_UNKNOWN"; 7926 } 7927 7928 /** 7929 * ice_set_rss_lut - Set RSS LUT 7930 * @vsi: Pointer to VSI structure 7931 * @lut: Lookup table 7932 * @lut_size: Lookup table size 7933 * 7934 * Returns 0 on success, negative on failure 7935 */ 7936 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size) 7937 { 7938 struct ice_aq_get_set_rss_lut_params params = {}; 7939 struct ice_hw *hw = &vsi->back->hw; 7940 int status; 7941 7942 if (!lut) 7943 return -EINVAL; 7944 7945 params.vsi_handle = vsi->idx; 7946 params.lut_size = lut_size; 7947 params.lut_type = vsi->rss_lut_type; 7948 params.lut = lut; 7949 7950 status = ice_aq_set_rss_lut(hw, ¶ms); 7951 if (status) 7952 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %d aq_err %s\n", 7953 status, ice_aq_str(hw->adminq.sq_last_status)); 7954 7955 return status; 7956 } 7957 7958 /** 7959 * ice_set_rss_key - Set RSS key 7960 * @vsi: Pointer to the VSI structure 7961 * @seed: RSS hash seed 7962 * 7963 * Returns 0 on success, negative on failure 7964 */ 7965 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed) 7966 { 7967 struct ice_hw *hw = &vsi->back->hw; 7968 int status; 7969 7970 if (!seed) 7971 return -EINVAL; 7972 7973 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed); 7974 if (status) 7975 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %d aq_err %s\n", 7976 status, ice_aq_str(hw->adminq.sq_last_status)); 7977 7978 return status; 7979 } 7980 7981 /** 7982 * ice_get_rss_lut - Get RSS LUT 7983 * @vsi: Pointer to VSI structure 7984 * @lut: Buffer to store the lookup table entries 7985 * @lut_size: Size of buffer to store the lookup table entries 7986 * 7987 * Returns 0 on success, negative on failure 7988 */ 7989 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size) 7990 { 7991 struct ice_aq_get_set_rss_lut_params params = {}; 7992 struct ice_hw *hw = &vsi->back->hw; 7993 int status; 7994 7995 if (!lut) 7996 return -EINVAL; 7997 7998 params.vsi_handle = vsi->idx; 7999 params.lut_size = lut_size; 8000 params.lut_type = vsi->rss_lut_type; 8001 params.lut = lut; 8002 8003 status = ice_aq_get_rss_lut(hw, ¶ms); 8004 if (status) 8005 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %d aq_err %s\n", 8006 status, ice_aq_str(hw->adminq.sq_last_status)); 8007 8008 return status; 8009 } 8010 8011 /** 8012 * ice_get_rss_key - Get RSS key 8013 * @vsi: Pointer to VSI structure 8014 * @seed: Buffer to store the key in 8015 * 8016 * Returns 0 on success, negative on failure 8017 */ 8018 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed) 8019 { 8020 struct ice_hw *hw = &vsi->back->hw; 8021 int status; 8022 8023 if (!seed) 8024 return -EINVAL; 8025 8026 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed); 8027 if (status) 8028 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %d aq_err %s\n", 8029 status, ice_aq_str(hw->adminq.sq_last_status)); 8030 8031 return status; 8032 } 8033 8034 /** 8035 * ice_set_rss_hfunc - Set RSS HASH function 8036 * @vsi: Pointer to VSI structure 8037 * @hfunc: hash function (ICE_AQ_VSI_Q_OPT_RSS_*) 8038 * 8039 * Returns 0 on success, negative on failure 8040 */ 8041 int ice_set_rss_hfunc(struct ice_vsi *vsi, u8 hfunc) 8042 { 8043 struct ice_hw *hw = &vsi->back->hw; 8044 struct ice_vsi_ctx *ctx; 8045 bool symm; 8046 int err; 8047 8048 if (hfunc == vsi->rss_hfunc) 8049 return 0; 8050 8051 if (hfunc != ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ && 8052 hfunc != ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ) 8053 return -EOPNOTSUPP; 8054 8055 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 8056 if (!ctx) 8057 return -ENOMEM; 8058 8059 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID); 8060 ctx->info.q_opt_rss = vsi->info.q_opt_rss; 8061 ctx->info.q_opt_rss &= ~ICE_AQ_VSI_Q_OPT_RSS_HASH_M; 8062 ctx->info.q_opt_rss |= 8063 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hfunc); 8064 ctx->info.q_opt_tc = vsi->info.q_opt_tc; 8065 ctx->info.q_opt_flags = vsi->info.q_opt_rss; 8066 8067 err = ice_update_vsi(hw, vsi->idx, ctx, NULL); 8068 if (err) { 8069 dev_err(ice_pf_to_dev(vsi->back), "Failed to configure RSS hash for VSI %d, error %d\n", 8070 vsi->vsi_num, err); 8071 } else { 8072 vsi->info.q_opt_rss = ctx->info.q_opt_rss; 8073 vsi->rss_hfunc = hfunc; 8074 netdev_info(vsi->netdev, "Hash function set to: %sToeplitz\n", 8075 hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ ? 8076 "Symmetric " : ""); 8077 } 8078 kfree(ctx); 8079 if (err) 8080 return err; 8081 8082 /* Fix the symmetry setting for all existing RSS configurations */ 8083 symm = !!(hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ); 8084 return ice_set_rss_cfg_symm(hw, vsi, symm); 8085 } 8086 8087 /** 8088 * ice_bridge_getlink - Get the hardware bridge mode 8089 * @skb: skb buff 8090 * @pid: process ID 8091 * @seq: RTNL message seq 8092 * @dev: the netdev being configured 8093 * @filter_mask: filter mask passed in 8094 * @nlflags: netlink flags passed in 8095 * 8096 * Return the bridge mode (VEB/VEPA) 8097 */ 8098 static int 8099 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, 8100 struct net_device *dev, u32 filter_mask, int nlflags) 8101 { 8102 struct ice_netdev_priv *np = netdev_priv(dev); 8103 struct ice_vsi *vsi = np->vsi; 8104 struct ice_pf *pf = vsi->back; 8105 u16 bmode; 8106 8107 bmode = pf->first_sw->bridge_mode; 8108 8109 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags, 8110 filter_mask, NULL); 8111 } 8112 8113 /** 8114 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA) 8115 * @vsi: Pointer to VSI structure 8116 * @bmode: Hardware bridge mode (VEB/VEPA) 8117 * 8118 * Returns 0 on success, negative on failure 8119 */ 8120 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode) 8121 { 8122 struct ice_aqc_vsi_props *vsi_props; 8123 struct ice_hw *hw = &vsi->back->hw; 8124 struct ice_vsi_ctx *ctxt; 8125 int ret; 8126 8127 vsi_props = &vsi->info; 8128 8129 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL); 8130 if (!ctxt) 8131 return -ENOMEM; 8132 8133 ctxt->info = vsi->info; 8134 8135 if (bmode == BRIDGE_MODE_VEB) 8136 /* change from VEPA to VEB mode */ 8137 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB; 8138 else 8139 /* change from VEB to VEPA mode */ 8140 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB; 8141 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID); 8142 8143 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL); 8144 if (ret) { 8145 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %s\n", 8146 bmode, ret, ice_aq_str(hw->adminq.sq_last_status)); 8147 goto out; 8148 } 8149 /* Update sw flags for book keeping */ 8150 vsi_props->sw_flags = ctxt->info.sw_flags; 8151 8152 out: 8153 kfree(ctxt); 8154 return ret; 8155 } 8156 8157 /** 8158 * ice_bridge_setlink - Set the hardware bridge mode 8159 * @dev: the netdev being configured 8160 * @nlh: RTNL message 8161 * @flags: bridge setlink flags 8162 * @extack: netlink extended ack 8163 * 8164 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is 8165 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if 8166 * not already set for all VSIs connected to this switch. And also update the 8167 * unicast switch filter rules for the corresponding switch of the netdev. 8168 */ 8169 static int 8170 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, 8171 u16 __always_unused flags, 8172 struct netlink_ext_ack __always_unused *extack) 8173 { 8174 struct ice_netdev_priv *np = netdev_priv(dev); 8175 struct ice_pf *pf = np->vsi->back; 8176 struct nlattr *attr, *br_spec; 8177 struct ice_hw *hw = &pf->hw; 8178 struct ice_sw *pf_sw; 8179 int rem, v, err = 0; 8180 8181 pf_sw = pf->first_sw; 8182 /* find the attribute in the netlink message */ 8183 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 8184 if (!br_spec) 8185 return -EINVAL; 8186 8187 nla_for_each_nested_type(attr, IFLA_BRIDGE_MODE, br_spec, rem) { 8188 __u16 mode = nla_get_u16(attr); 8189 8190 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) 8191 return -EINVAL; 8192 /* Continue if bridge mode is not being flipped */ 8193 if (mode == pf_sw->bridge_mode) 8194 continue; 8195 /* Iterates through the PF VSI list and update the loopback 8196 * mode of the VSI 8197 */ 8198 ice_for_each_vsi(pf, v) { 8199 if (!pf->vsi[v]) 8200 continue; 8201 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode); 8202 if (err) 8203 return err; 8204 } 8205 8206 hw->evb_veb = (mode == BRIDGE_MODE_VEB); 8207 /* Update the unicast switch filter rules for the corresponding 8208 * switch of the netdev 8209 */ 8210 err = ice_update_sw_rule_bridge_mode(hw); 8211 if (err) { 8212 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %s\n", 8213 mode, err, 8214 ice_aq_str(hw->adminq.sq_last_status)); 8215 /* revert hw->evb_veb */ 8216 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB); 8217 return err; 8218 } 8219 8220 pf_sw->bridge_mode = mode; 8221 } 8222 8223 return 0; 8224 } 8225 8226 /** 8227 * ice_tx_timeout - Respond to a Tx Hang 8228 * @netdev: network interface device structure 8229 * @txqueue: Tx queue 8230 */ 8231 void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue) 8232 { 8233 struct ice_netdev_priv *np = netdev_priv(netdev); 8234 struct ice_tx_ring *tx_ring = NULL; 8235 struct ice_vsi *vsi = np->vsi; 8236 struct ice_pf *pf = vsi->back; 8237 u32 i; 8238 8239 pf->tx_timeout_count++; 8240 8241 /* Check if PFC is enabled for the TC to which the queue belongs 8242 * to. If yes then Tx timeout is not caused by a hung queue, no 8243 * need to reset and rebuild 8244 */ 8245 if (ice_is_pfc_causing_hung_q(pf, txqueue)) { 8246 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n", 8247 txqueue); 8248 return; 8249 } 8250 8251 /* now that we have an index, find the tx_ring struct */ 8252 ice_for_each_txq(vsi, i) 8253 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) 8254 if (txqueue == vsi->tx_rings[i]->q_index) { 8255 tx_ring = vsi->tx_rings[i]; 8256 break; 8257 } 8258 8259 /* Reset recovery level if enough time has elapsed after last timeout. 8260 * Also ensure no new reset action happens before next timeout period. 8261 */ 8262 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20))) 8263 pf->tx_timeout_recovery_level = 1; 8264 else if (time_before(jiffies, (pf->tx_timeout_last_recovery + 8265 netdev->watchdog_timeo))) 8266 return; 8267 8268 if (tx_ring) { 8269 struct ice_hw *hw = &pf->hw; 8270 u32 head, intr = 0; 8271 8272 head = FIELD_GET(QTX_COMM_HEAD_HEAD_M, 8273 rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue]))); 8274 /* Read interrupt register */ 8275 intr = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx)); 8276 8277 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n", 8278 vsi->vsi_num, txqueue, tx_ring->next_to_clean, 8279 head, tx_ring->next_to_use, intr); 8280 8281 ice_prep_tx_hang_report(pf, tx_ring, vsi->vsi_num, head, intr); 8282 } 8283 8284 pf->tx_timeout_last_recovery = jiffies; 8285 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n", 8286 pf->tx_timeout_recovery_level, txqueue); 8287 8288 switch (pf->tx_timeout_recovery_level) { 8289 case 1: 8290 set_bit(ICE_PFR_REQ, pf->state); 8291 break; 8292 case 2: 8293 set_bit(ICE_CORER_REQ, pf->state); 8294 break; 8295 case 3: 8296 set_bit(ICE_GLOBR_REQ, pf->state); 8297 break; 8298 default: 8299 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n"); 8300 set_bit(ICE_DOWN, pf->state); 8301 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state); 8302 set_bit(ICE_SERVICE_DIS, pf->state); 8303 break; 8304 } 8305 8306 ice_service_task_schedule(pf); 8307 pf->tx_timeout_recovery_level++; 8308 } 8309 8310 /** 8311 * ice_setup_tc_cls_flower - flower classifier offloads 8312 * @np: net device to configure 8313 * @filter_dev: device on which filter is added 8314 * @cls_flower: offload data 8315 */ 8316 static int 8317 ice_setup_tc_cls_flower(struct ice_netdev_priv *np, 8318 struct net_device *filter_dev, 8319 struct flow_cls_offload *cls_flower) 8320 { 8321 struct ice_vsi *vsi = np->vsi; 8322 8323 if (cls_flower->common.chain_index) 8324 return -EOPNOTSUPP; 8325 8326 switch (cls_flower->command) { 8327 case FLOW_CLS_REPLACE: 8328 return ice_add_cls_flower(filter_dev, vsi, cls_flower); 8329 case FLOW_CLS_DESTROY: 8330 return ice_del_cls_flower(vsi, cls_flower); 8331 default: 8332 return -EINVAL; 8333 } 8334 } 8335 8336 /** 8337 * ice_setup_tc_block_cb - callback handler registered for TC block 8338 * @type: TC SETUP type 8339 * @type_data: TC flower offload data that contains user input 8340 * @cb_priv: netdev private data 8341 */ 8342 static int 8343 ice_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv) 8344 { 8345 struct ice_netdev_priv *np = cb_priv; 8346 8347 switch (type) { 8348 case TC_SETUP_CLSFLOWER: 8349 return ice_setup_tc_cls_flower(np, np->vsi->netdev, 8350 type_data); 8351 default: 8352 return -EOPNOTSUPP; 8353 } 8354 } 8355 8356 /** 8357 * ice_validate_mqprio_qopt - Validate TCF input parameters 8358 * @vsi: Pointer to VSI 8359 * @mqprio_qopt: input parameters for mqprio queue configuration 8360 * 8361 * This function validates MQPRIO params, such as qcount (power of 2 wherever 8362 * needed), and make sure user doesn't specify qcount and BW rate limit 8363 * for TCs, which are more than "num_tc" 8364 */ 8365 static int 8366 ice_validate_mqprio_qopt(struct ice_vsi *vsi, 8367 struct tc_mqprio_qopt_offload *mqprio_qopt) 8368 { 8369 int non_power_of_2_qcount = 0; 8370 struct ice_pf *pf = vsi->back; 8371 int max_rss_q_cnt = 0; 8372 u64 sum_min_rate = 0; 8373 struct device *dev; 8374 int i, speed; 8375 u8 num_tc; 8376 8377 if (vsi->type != ICE_VSI_PF) 8378 return -EINVAL; 8379 8380 if (mqprio_qopt->qopt.offset[0] != 0 || 8381 mqprio_qopt->qopt.num_tc < 1 || 8382 mqprio_qopt->qopt.num_tc > ICE_CHNL_MAX_TC) 8383 return -EINVAL; 8384 8385 dev = ice_pf_to_dev(pf); 8386 vsi->ch_rss_size = 0; 8387 num_tc = mqprio_qopt->qopt.num_tc; 8388 speed = ice_get_link_speed_kbps(vsi); 8389 8390 for (i = 0; num_tc; i++) { 8391 int qcount = mqprio_qopt->qopt.count[i]; 8392 u64 max_rate, min_rate, rem; 8393 8394 if (!qcount) 8395 return -EINVAL; 8396 8397 if (is_power_of_2(qcount)) { 8398 if (non_power_of_2_qcount && 8399 qcount > non_power_of_2_qcount) { 8400 dev_err(dev, "qcount[%d] cannot be greater than non power of 2 qcount[%d]\n", 8401 qcount, non_power_of_2_qcount); 8402 return -EINVAL; 8403 } 8404 if (qcount > max_rss_q_cnt) 8405 max_rss_q_cnt = qcount; 8406 } else { 8407 if (non_power_of_2_qcount && 8408 qcount != non_power_of_2_qcount) { 8409 dev_err(dev, "Only one non power of 2 qcount allowed[%d,%d]\n", 8410 qcount, non_power_of_2_qcount); 8411 return -EINVAL; 8412 } 8413 if (qcount < max_rss_q_cnt) { 8414 dev_err(dev, "non power of 2 qcount[%d] cannot be less than other qcount[%d]\n", 8415 qcount, max_rss_q_cnt); 8416 return -EINVAL; 8417 } 8418 max_rss_q_cnt = qcount; 8419 non_power_of_2_qcount = qcount; 8420 } 8421 8422 /* TC command takes input in K/N/Gbps or K/M/Gbit etc but 8423 * converts the bandwidth rate limit into Bytes/s when 8424 * passing it down to the driver. So convert input bandwidth 8425 * from Bytes/s to Kbps 8426 */ 8427 max_rate = mqprio_qopt->max_rate[i]; 8428 max_rate = div_u64(max_rate, ICE_BW_KBPS_DIVISOR); 8429 8430 /* min_rate is minimum guaranteed rate and it can't be zero */ 8431 min_rate = mqprio_qopt->min_rate[i]; 8432 min_rate = div_u64(min_rate, ICE_BW_KBPS_DIVISOR); 8433 sum_min_rate += min_rate; 8434 8435 if (min_rate && min_rate < ICE_MIN_BW_LIMIT) { 8436 dev_err(dev, "TC%d: min_rate(%llu Kbps) < %u Kbps\n", i, 8437 min_rate, ICE_MIN_BW_LIMIT); 8438 return -EINVAL; 8439 } 8440 8441 if (max_rate && max_rate > speed) { 8442 dev_err(dev, "TC%d: max_rate(%llu Kbps) > link speed of %u Kbps\n", 8443 i, max_rate, speed); 8444 return -EINVAL; 8445 } 8446 8447 iter_div_u64_rem(min_rate, ICE_MIN_BW_LIMIT, &rem); 8448 if (rem) { 8449 dev_err(dev, "TC%d: Min Rate not multiple of %u Kbps", 8450 i, ICE_MIN_BW_LIMIT); 8451 return -EINVAL; 8452 } 8453 8454 iter_div_u64_rem(max_rate, ICE_MIN_BW_LIMIT, &rem); 8455 if (rem) { 8456 dev_err(dev, "TC%d: Max Rate not multiple of %u Kbps", 8457 i, ICE_MIN_BW_LIMIT); 8458 return -EINVAL; 8459 } 8460 8461 /* min_rate can't be more than max_rate, except when max_rate 8462 * is zero (implies max_rate sought is max line rate). In such 8463 * a case min_rate can be more than max. 8464 */ 8465 if (max_rate && min_rate > max_rate) { 8466 dev_err(dev, "min_rate %llu Kbps can't be more than max_rate %llu Kbps\n", 8467 min_rate, max_rate); 8468 return -EINVAL; 8469 } 8470 8471 if (i >= mqprio_qopt->qopt.num_tc - 1) 8472 break; 8473 if (mqprio_qopt->qopt.offset[i + 1] != 8474 (mqprio_qopt->qopt.offset[i] + qcount)) 8475 return -EINVAL; 8476 } 8477 if (vsi->num_rxq < 8478 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) 8479 return -EINVAL; 8480 if (vsi->num_txq < 8481 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i])) 8482 return -EINVAL; 8483 8484 if (sum_min_rate && sum_min_rate > (u64)speed) { 8485 dev_err(dev, "Invalid min Tx rate(%llu) Kbps > speed (%u) Kbps specified\n", 8486 sum_min_rate, speed); 8487 return -EINVAL; 8488 } 8489 8490 /* make sure vsi->ch_rss_size is set correctly based on TC's qcount */ 8491 vsi->ch_rss_size = max_rss_q_cnt; 8492 8493 return 0; 8494 } 8495 8496 /** 8497 * ice_add_vsi_to_fdir - add a VSI to the flow director group for PF 8498 * @pf: ptr to PF device 8499 * @vsi: ptr to VSI 8500 */ 8501 static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi) 8502 { 8503 struct device *dev = ice_pf_to_dev(pf); 8504 bool added = false; 8505 struct ice_hw *hw; 8506 int flow; 8507 8508 if (!(vsi->num_gfltr || vsi->num_bfltr)) 8509 return -EINVAL; 8510 8511 hw = &pf->hw; 8512 for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) { 8513 struct ice_fd_hw_prof *prof; 8514 int tun, status; 8515 u64 entry_h; 8516 8517 if (!(hw->fdir_prof && hw->fdir_prof[flow] && 8518 hw->fdir_prof[flow]->cnt)) 8519 continue; 8520 8521 for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) { 8522 enum ice_flow_priority prio; 8523 8524 /* add this VSI to FDir profile for this flow */ 8525 prio = ICE_FLOW_PRIO_NORMAL; 8526 prof = hw->fdir_prof[flow]; 8527 status = ice_flow_add_entry(hw, ICE_BLK_FD, 8528 prof->prof_id[tun], 8529 prof->vsi_h[0], vsi->idx, 8530 prio, prof->fdir_seg[tun], 8531 &entry_h); 8532 if (status) { 8533 dev_err(dev, "channel VSI idx %d, not able to add to group %d\n", 8534 vsi->idx, flow); 8535 continue; 8536 } 8537 8538 prof->entry_h[prof->cnt][tun] = entry_h; 8539 } 8540 8541 /* store VSI for filter replay and delete */ 8542 prof->vsi_h[prof->cnt] = vsi->idx; 8543 prof->cnt++; 8544 8545 added = true; 8546 dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx, 8547 flow); 8548 } 8549 8550 if (!added) 8551 dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx); 8552 8553 return 0; 8554 } 8555 8556 /** 8557 * ice_add_channel - add a channel by adding VSI 8558 * @pf: ptr to PF device 8559 * @sw_id: underlying HW switching element ID 8560 * @ch: ptr to channel structure 8561 * 8562 * Add a channel (VSI) using add_vsi and queue_map 8563 */ 8564 static int ice_add_channel(struct ice_pf *pf, u16 sw_id, struct ice_channel *ch) 8565 { 8566 struct device *dev = ice_pf_to_dev(pf); 8567 struct ice_vsi *vsi; 8568 8569 if (ch->type != ICE_VSI_CHNL) { 8570 dev_err(dev, "add new VSI failed, ch->type %d\n", ch->type); 8571 return -EINVAL; 8572 } 8573 8574 vsi = ice_chnl_vsi_setup(pf, pf->hw.port_info, ch); 8575 if (!vsi || vsi->type != ICE_VSI_CHNL) { 8576 dev_err(dev, "create chnl VSI failure\n"); 8577 return -EINVAL; 8578 } 8579 8580 ice_add_vsi_to_fdir(pf, vsi); 8581 8582 ch->sw_id = sw_id; 8583 ch->vsi_num = vsi->vsi_num; 8584 ch->info.mapping_flags = vsi->info.mapping_flags; 8585 ch->ch_vsi = vsi; 8586 /* set the back pointer of channel for newly created VSI */ 8587 vsi->ch = ch; 8588 8589 memcpy(&ch->info.q_mapping, &vsi->info.q_mapping, 8590 sizeof(vsi->info.q_mapping)); 8591 memcpy(&ch->info.tc_mapping, vsi->info.tc_mapping, 8592 sizeof(vsi->info.tc_mapping)); 8593 8594 return 0; 8595 } 8596 8597 /** 8598 * ice_chnl_cfg_res 8599 * @vsi: the VSI being setup 8600 * @ch: ptr to channel structure 8601 * 8602 * Configure channel specific resources such as rings, vector. 8603 */ 8604 static void ice_chnl_cfg_res(struct ice_vsi *vsi, struct ice_channel *ch) 8605 { 8606 int i; 8607 8608 for (i = 0; i < ch->num_txq; i++) { 8609 struct ice_q_vector *tx_q_vector, *rx_q_vector; 8610 struct ice_ring_container *rc; 8611 struct ice_tx_ring *tx_ring; 8612 struct ice_rx_ring *rx_ring; 8613 8614 tx_ring = vsi->tx_rings[ch->base_q + i]; 8615 rx_ring = vsi->rx_rings[ch->base_q + i]; 8616 if (!tx_ring || !rx_ring) 8617 continue; 8618 8619 /* setup ring being channel enabled */ 8620 tx_ring->ch = ch; 8621 rx_ring->ch = ch; 8622 8623 /* following code block sets up vector specific attributes */ 8624 tx_q_vector = tx_ring->q_vector; 8625 rx_q_vector = rx_ring->q_vector; 8626 if (!tx_q_vector && !rx_q_vector) 8627 continue; 8628 8629 if (tx_q_vector) { 8630 tx_q_vector->ch = ch; 8631 /* setup Tx and Rx ITR setting if DIM is off */ 8632 rc = &tx_q_vector->tx; 8633 if (!ITR_IS_DYNAMIC(rc)) 8634 ice_write_itr(rc, rc->itr_setting); 8635 } 8636 if (rx_q_vector) { 8637 rx_q_vector->ch = ch; 8638 /* setup Tx and Rx ITR setting if DIM is off */ 8639 rc = &rx_q_vector->rx; 8640 if (!ITR_IS_DYNAMIC(rc)) 8641 ice_write_itr(rc, rc->itr_setting); 8642 } 8643 } 8644 8645 /* it is safe to assume that, if channel has non-zero num_t[r]xq, then 8646 * GLINT_ITR register would have written to perform in-context 8647 * update, hence perform flush 8648 */ 8649 if (ch->num_txq || ch->num_rxq) 8650 ice_flush(&vsi->back->hw); 8651 } 8652 8653 /** 8654 * ice_cfg_chnl_all_res - configure channel resources 8655 * @vsi: pte to main_vsi 8656 * @ch: ptr to channel structure 8657 * 8658 * This function configures channel specific resources such as flow-director 8659 * counter index, and other resources such as queues, vectors, ITR settings 8660 */ 8661 static void 8662 ice_cfg_chnl_all_res(struct ice_vsi *vsi, struct ice_channel *ch) 8663 { 8664 /* configure channel (aka ADQ) resources such as queues, vectors, 8665 * ITR settings for channel specific vectors and anything else 8666 */ 8667 ice_chnl_cfg_res(vsi, ch); 8668 } 8669 8670 /** 8671 * ice_setup_hw_channel - setup new channel 8672 * @pf: ptr to PF device 8673 * @vsi: the VSI being setup 8674 * @ch: ptr to channel structure 8675 * @sw_id: underlying HW switching element ID 8676 * @type: type of channel to be created (VMDq2/VF) 8677 * 8678 * Setup new channel (VSI) based on specified type (VMDq2/VF) 8679 * and configures Tx rings accordingly 8680 */ 8681 static int 8682 ice_setup_hw_channel(struct ice_pf *pf, struct ice_vsi *vsi, 8683 struct ice_channel *ch, u16 sw_id, u8 type) 8684 { 8685 struct device *dev = ice_pf_to_dev(pf); 8686 int ret; 8687 8688 ch->base_q = vsi->next_base_q; 8689 ch->type = type; 8690 8691 ret = ice_add_channel(pf, sw_id, ch); 8692 if (ret) { 8693 dev_err(dev, "failed to add_channel using sw_id %u\n", sw_id); 8694 return ret; 8695 } 8696 8697 /* configure/setup ADQ specific resources */ 8698 ice_cfg_chnl_all_res(vsi, ch); 8699 8700 /* make sure to update the next_base_q so that subsequent channel's 8701 * (aka ADQ) VSI queue map is correct 8702 */ 8703 vsi->next_base_q = vsi->next_base_q + ch->num_rxq; 8704 dev_dbg(dev, "added channel: vsi_num %u, num_rxq %u\n", ch->vsi_num, 8705 ch->num_rxq); 8706 8707 return 0; 8708 } 8709 8710 /** 8711 * ice_setup_channel - setup new channel using uplink element 8712 * @pf: ptr to PF device 8713 * @vsi: the VSI being setup 8714 * @ch: ptr to channel structure 8715 * 8716 * Setup new channel (VSI) based on specified type (VMDq2/VF) 8717 * and uplink switching element 8718 */ 8719 static bool 8720 ice_setup_channel(struct ice_pf *pf, struct ice_vsi *vsi, 8721 struct ice_channel *ch) 8722 { 8723 struct device *dev = ice_pf_to_dev(pf); 8724 u16 sw_id; 8725 int ret; 8726 8727 if (vsi->type != ICE_VSI_PF) { 8728 dev_err(dev, "unsupported parent VSI type(%d)\n", vsi->type); 8729 return false; 8730 } 8731 8732 sw_id = pf->first_sw->sw_id; 8733 8734 /* create channel (VSI) */ 8735 ret = ice_setup_hw_channel(pf, vsi, ch, sw_id, ICE_VSI_CHNL); 8736 if (ret) { 8737 dev_err(dev, "failed to setup hw_channel\n"); 8738 return false; 8739 } 8740 dev_dbg(dev, "successfully created channel()\n"); 8741 8742 return ch->ch_vsi ? true : false; 8743 } 8744 8745 /** 8746 * ice_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate 8747 * @vsi: VSI to be configured 8748 * @max_tx_rate: max Tx rate in Kbps to be configured as maximum BW limit 8749 * @min_tx_rate: min Tx rate in Kbps to be configured as minimum BW limit 8750 */ 8751 static int 8752 ice_set_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate, u64 min_tx_rate) 8753 { 8754 int err; 8755 8756 err = ice_set_min_bw_limit(vsi, min_tx_rate); 8757 if (err) 8758 return err; 8759 8760 return ice_set_max_bw_limit(vsi, max_tx_rate); 8761 } 8762 8763 /** 8764 * ice_create_q_channel - function to create channel 8765 * @vsi: VSI to be configured 8766 * @ch: ptr to channel (it contains channel specific params) 8767 * 8768 * This function creates channel (VSI) using num_queues specified by user, 8769 * reconfigs RSS if needed. 8770 */ 8771 static int ice_create_q_channel(struct ice_vsi *vsi, struct ice_channel *ch) 8772 { 8773 struct ice_pf *pf = vsi->back; 8774 struct device *dev; 8775 8776 if (!ch) 8777 return -EINVAL; 8778 8779 dev = ice_pf_to_dev(pf); 8780 if (!ch->num_txq || !ch->num_rxq) { 8781 dev_err(dev, "Invalid num_queues requested: %d\n", ch->num_rxq); 8782 return -EINVAL; 8783 } 8784 8785 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_txq) { 8786 dev_err(dev, "cnt_q_avail (%u) less than num_queues %d\n", 8787 vsi->cnt_q_avail, ch->num_txq); 8788 return -EINVAL; 8789 } 8790 8791 if (!ice_setup_channel(pf, vsi, ch)) { 8792 dev_info(dev, "Failed to setup channel\n"); 8793 return -EINVAL; 8794 } 8795 /* configure BW rate limit */ 8796 if (ch->ch_vsi && (ch->max_tx_rate || ch->min_tx_rate)) { 8797 int ret; 8798 8799 ret = ice_set_bw_limit(ch->ch_vsi, ch->max_tx_rate, 8800 ch->min_tx_rate); 8801 if (ret) 8802 dev_err(dev, "failed to set Tx rate of %llu Kbps for VSI(%u)\n", 8803 ch->max_tx_rate, ch->ch_vsi->vsi_num); 8804 else 8805 dev_dbg(dev, "set Tx rate of %llu Kbps for VSI(%u)\n", 8806 ch->max_tx_rate, ch->ch_vsi->vsi_num); 8807 } 8808 8809 vsi->cnt_q_avail -= ch->num_txq; 8810 8811 return 0; 8812 } 8813 8814 /** 8815 * ice_rem_all_chnl_fltrs - removes all channel filters 8816 * @pf: ptr to PF, TC-flower based filter are tracked at PF level 8817 * 8818 * Remove all advanced switch filters only if they are channel specific 8819 * tc-flower based filter 8820 */ 8821 static void ice_rem_all_chnl_fltrs(struct ice_pf *pf) 8822 { 8823 struct ice_tc_flower_fltr *fltr; 8824 struct hlist_node *node; 8825 8826 /* to remove all channel filters, iterate an ordered list of filters */ 8827 hlist_for_each_entry_safe(fltr, node, 8828 &pf->tc_flower_fltr_list, 8829 tc_flower_node) { 8830 struct ice_rule_query_data rule; 8831 int status; 8832 8833 /* for now process only channel specific filters */ 8834 if (!ice_is_chnl_fltr(fltr)) 8835 continue; 8836 8837 rule.rid = fltr->rid; 8838 rule.rule_id = fltr->rule_id; 8839 rule.vsi_handle = fltr->dest_vsi_handle; 8840 status = ice_rem_adv_rule_by_id(&pf->hw, &rule); 8841 if (status) { 8842 if (status == -ENOENT) 8843 dev_dbg(ice_pf_to_dev(pf), "TC flower filter (rule_id %u) does not exist\n", 8844 rule.rule_id); 8845 else 8846 dev_err(ice_pf_to_dev(pf), "failed to delete TC flower filter, status %d\n", 8847 status); 8848 } else if (fltr->dest_vsi) { 8849 /* update advanced switch filter count */ 8850 if (fltr->dest_vsi->type == ICE_VSI_CHNL) { 8851 u32 flags = fltr->flags; 8852 8853 fltr->dest_vsi->num_chnl_fltr--; 8854 if (flags & (ICE_TC_FLWR_FIELD_DST_MAC | 8855 ICE_TC_FLWR_FIELD_ENC_DST_MAC)) 8856 pf->num_dmac_chnl_fltrs--; 8857 } 8858 } 8859 8860 hlist_del(&fltr->tc_flower_node); 8861 kfree(fltr); 8862 } 8863 } 8864 8865 /** 8866 * ice_remove_q_channels - Remove queue channels for the TCs 8867 * @vsi: VSI to be configured 8868 * @rem_fltr: delete advanced switch filter or not 8869 * 8870 * Remove queue channels for the TCs 8871 */ 8872 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_fltr) 8873 { 8874 struct ice_channel *ch, *ch_tmp; 8875 struct ice_pf *pf = vsi->back; 8876 int i; 8877 8878 /* remove all tc-flower based filter if they are channel filters only */ 8879 if (rem_fltr) 8880 ice_rem_all_chnl_fltrs(pf); 8881 8882 /* remove ntuple filters since queue configuration is being changed */ 8883 if (vsi->netdev->features & NETIF_F_NTUPLE) { 8884 struct ice_hw *hw = &pf->hw; 8885 8886 mutex_lock(&hw->fdir_fltr_lock); 8887 ice_fdir_del_all_fltrs(vsi); 8888 mutex_unlock(&hw->fdir_fltr_lock); 8889 } 8890 8891 /* perform cleanup for channels if they exist */ 8892 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) { 8893 struct ice_vsi *ch_vsi; 8894 8895 list_del(&ch->list); 8896 ch_vsi = ch->ch_vsi; 8897 if (!ch_vsi) { 8898 kfree(ch); 8899 continue; 8900 } 8901 8902 /* Reset queue contexts */ 8903 for (i = 0; i < ch->num_rxq; i++) { 8904 struct ice_tx_ring *tx_ring; 8905 struct ice_rx_ring *rx_ring; 8906 8907 tx_ring = vsi->tx_rings[ch->base_q + i]; 8908 rx_ring = vsi->rx_rings[ch->base_q + i]; 8909 if (tx_ring) { 8910 tx_ring->ch = NULL; 8911 if (tx_ring->q_vector) 8912 tx_ring->q_vector->ch = NULL; 8913 } 8914 if (rx_ring) { 8915 rx_ring->ch = NULL; 8916 if (rx_ring->q_vector) 8917 rx_ring->q_vector->ch = NULL; 8918 } 8919 } 8920 8921 /* Release FD resources for the channel VSI */ 8922 ice_fdir_rem_adq_chnl(&pf->hw, ch->ch_vsi->idx); 8923 8924 /* clear the VSI from scheduler tree */ 8925 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx); 8926 8927 /* Delete VSI from FW, PF and HW VSI arrays */ 8928 ice_vsi_delete(ch->ch_vsi); 8929 8930 /* free the channel */ 8931 kfree(ch); 8932 } 8933 8934 /* clear the channel VSI map which is stored in main VSI */ 8935 ice_for_each_chnl_tc(i) 8936 vsi->tc_map_vsi[i] = NULL; 8937 8938 /* reset main VSI's all TC information */ 8939 vsi->all_enatc = 0; 8940 vsi->all_numtc = 0; 8941 } 8942 8943 /** 8944 * ice_rebuild_channels - rebuild channel 8945 * @pf: ptr to PF 8946 * 8947 * Recreate channel VSIs and replay filters 8948 */ 8949 static int ice_rebuild_channels(struct ice_pf *pf) 8950 { 8951 struct device *dev = ice_pf_to_dev(pf); 8952 struct ice_vsi *main_vsi; 8953 bool rem_adv_fltr = true; 8954 struct ice_channel *ch; 8955 struct ice_vsi *vsi; 8956 int tc_idx = 1; 8957 int i, err; 8958 8959 main_vsi = ice_get_main_vsi(pf); 8960 if (!main_vsi) 8961 return 0; 8962 8963 if (!test_bit(ICE_FLAG_TC_MQPRIO, pf->flags) || 8964 main_vsi->old_numtc == 1) 8965 return 0; /* nothing to be done */ 8966 8967 /* reconfigure main VSI based on old value of TC and cached values 8968 * for MQPRIO opts 8969 */ 8970 err = ice_vsi_cfg_tc(main_vsi, main_vsi->old_ena_tc); 8971 if (err) { 8972 dev_err(dev, "failed configuring TC(ena_tc:0x%02x) for HW VSI=%u\n", 8973 main_vsi->old_ena_tc, main_vsi->vsi_num); 8974 return err; 8975 } 8976 8977 /* rebuild ADQ VSIs */ 8978 ice_for_each_vsi(pf, i) { 8979 enum ice_vsi_type type; 8980 8981 vsi = pf->vsi[i]; 8982 if (!vsi || vsi->type != ICE_VSI_CHNL) 8983 continue; 8984 8985 type = vsi->type; 8986 8987 /* rebuild ADQ VSI */ 8988 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT); 8989 if (err) { 8990 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n", 8991 ice_vsi_type_str(type), vsi->idx, err); 8992 goto cleanup; 8993 } 8994 8995 /* Re-map HW VSI number, using VSI handle that has been 8996 * previously validated in ice_replay_vsi() call above 8997 */ 8998 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx); 8999 9000 /* replay filters for the VSI */ 9001 err = ice_replay_vsi(&pf->hw, vsi->idx); 9002 if (err) { 9003 dev_err(dev, "VSI (type:%s) replay failed, err %d, VSI index %d\n", 9004 ice_vsi_type_str(type), err, vsi->idx); 9005 rem_adv_fltr = false; 9006 goto cleanup; 9007 } 9008 dev_info(dev, "VSI (type:%s) at index %d rebuilt successfully\n", 9009 ice_vsi_type_str(type), vsi->idx); 9010 9011 /* store ADQ VSI at correct TC index in main VSI's 9012 * map of TC to VSI 9013 */ 9014 main_vsi->tc_map_vsi[tc_idx++] = vsi; 9015 } 9016 9017 /* ADQ VSI(s) has been rebuilt successfully, so setup 9018 * channel for main VSI's Tx and Rx rings 9019 */ 9020 list_for_each_entry(ch, &main_vsi->ch_list, list) { 9021 struct ice_vsi *ch_vsi; 9022 9023 ch_vsi = ch->ch_vsi; 9024 if (!ch_vsi) 9025 continue; 9026 9027 /* reconfig channel resources */ 9028 ice_cfg_chnl_all_res(main_vsi, ch); 9029 9030 /* replay BW rate limit if it is non-zero */ 9031 if (!ch->max_tx_rate && !ch->min_tx_rate) 9032 continue; 9033 9034 err = ice_set_bw_limit(ch_vsi, ch->max_tx_rate, 9035 ch->min_tx_rate); 9036 if (err) 9037 dev_err(dev, "failed (err:%d) to rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n", 9038 err, ch->max_tx_rate, ch->min_tx_rate, 9039 ch_vsi->vsi_num); 9040 else 9041 dev_dbg(dev, "successfully rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n", 9042 ch->max_tx_rate, ch->min_tx_rate, 9043 ch_vsi->vsi_num); 9044 } 9045 9046 /* reconfig RSS for main VSI */ 9047 if (main_vsi->ch_rss_size) 9048 ice_vsi_cfg_rss_lut_key(main_vsi); 9049 9050 return 0; 9051 9052 cleanup: 9053 ice_remove_q_channels(main_vsi, rem_adv_fltr); 9054 return err; 9055 } 9056 9057 /** 9058 * ice_create_q_channels - Add queue channel for the given TCs 9059 * @vsi: VSI to be configured 9060 * 9061 * Configures queue channel mapping to the given TCs 9062 */ 9063 static int ice_create_q_channels(struct ice_vsi *vsi) 9064 { 9065 struct ice_pf *pf = vsi->back; 9066 struct ice_channel *ch; 9067 int ret = 0, i; 9068 9069 ice_for_each_chnl_tc(i) { 9070 if (!(vsi->all_enatc & BIT(i))) 9071 continue; 9072 9073 ch = kzalloc(sizeof(*ch), GFP_KERNEL); 9074 if (!ch) { 9075 ret = -ENOMEM; 9076 goto err_free; 9077 } 9078 INIT_LIST_HEAD(&ch->list); 9079 ch->num_rxq = vsi->mqprio_qopt.qopt.count[i]; 9080 ch->num_txq = vsi->mqprio_qopt.qopt.count[i]; 9081 ch->base_q = vsi->mqprio_qopt.qopt.offset[i]; 9082 ch->max_tx_rate = vsi->mqprio_qopt.max_rate[i]; 9083 ch->min_tx_rate = vsi->mqprio_qopt.min_rate[i]; 9084 9085 /* convert to Kbits/s */ 9086 if (ch->max_tx_rate) 9087 ch->max_tx_rate = div_u64(ch->max_tx_rate, 9088 ICE_BW_KBPS_DIVISOR); 9089 if (ch->min_tx_rate) 9090 ch->min_tx_rate = div_u64(ch->min_tx_rate, 9091 ICE_BW_KBPS_DIVISOR); 9092 9093 ret = ice_create_q_channel(vsi, ch); 9094 if (ret) { 9095 dev_err(ice_pf_to_dev(pf), 9096 "failed creating channel TC:%d\n", i); 9097 kfree(ch); 9098 goto err_free; 9099 } 9100 list_add_tail(&ch->list, &vsi->ch_list); 9101 vsi->tc_map_vsi[i] = ch->ch_vsi; 9102 dev_dbg(ice_pf_to_dev(pf), 9103 "successfully created channel: VSI %pK\n", ch->ch_vsi); 9104 } 9105 return 0; 9106 9107 err_free: 9108 ice_remove_q_channels(vsi, false); 9109 9110 return ret; 9111 } 9112 9113 /** 9114 * ice_setup_tc_mqprio_qdisc - configure multiple traffic classes 9115 * @netdev: net device to configure 9116 * @type_data: TC offload data 9117 */ 9118 static int ice_setup_tc_mqprio_qdisc(struct net_device *netdev, void *type_data) 9119 { 9120 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data; 9121 struct ice_netdev_priv *np = netdev_priv(netdev); 9122 struct ice_vsi *vsi = np->vsi; 9123 struct ice_pf *pf = vsi->back; 9124 u16 mode, ena_tc_qdisc = 0; 9125 int cur_txq, cur_rxq; 9126 u8 hw = 0, num_tcf; 9127 struct device *dev; 9128 int ret, i; 9129 9130 dev = ice_pf_to_dev(pf); 9131 num_tcf = mqprio_qopt->qopt.num_tc; 9132 hw = mqprio_qopt->qopt.hw; 9133 mode = mqprio_qopt->mode; 9134 if (!hw) { 9135 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags); 9136 vsi->ch_rss_size = 0; 9137 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt)); 9138 goto config_tcf; 9139 } 9140 9141 /* Generate queue region map for number of TCF requested */ 9142 for (i = 0; i < num_tcf; i++) 9143 ena_tc_qdisc |= BIT(i); 9144 9145 switch (mode) { 9146 case TC_MQPRIO_MODE_CHANNEL: 9147 9148 if (pf->hw.port_info->is_custom_tx_enabled) { 9149 dev_err(dev, "Custom Tx scheduler feature enabled, can't configure ADQ\n"); 9150 return -EBUSY; 9151 } 9152 ice_tear_down_devlink_rate_tree(pf); 9153 9154 ret = ice_validate_mqprio_qopt(vsi, mqprio_qopt); 9155 if (ret) { 9156 netdev_err(netdev, "failed to validate_mqprio_qopt(), ret %d\n", 9157 ret); 9158 return ret; 9159 } 9160 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt)); 9161 set_bit(ICE_FLAG_TC_MQPRIO, pf->flags); 9162 /* don't assume state of hw_tc_offload during driver load 9163 * and set the flag for TC flower filter if hw_tc_offload 9164 * already ON 9165 */ 9166 if (vsi->netdev->features & NETIF_F_HW_TC) 9167 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags); 9168 break; 9169 default: 9170 return -EINVAL; 9171 } 9172 9173 config_tcf: 9174 9175 /* Requesting same TCF configuration as already enabled */ 9176 if (ena_tc_qdisc == vsi->tc_cfg.ena_tc && 9177 mode != TC_MQPRIO_MODE_CHANNEL) 9178 return 0; 9179 9180 /* Pause VSI queues */ 9181 ice_dis_vsi(vsi, true); 9182 9183 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) 9184 ice_remove_q_channels(vsi, true); 9185 9186 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) { 9187 vsi->req_txq = min_t(int, ice_get_avail_txq_count(pf), 9188 num_online_cpus()); 9189 vsi->req_rxq = min_t(int, ice_get_avail_rxq_count(pf), 9190 num_online_cpus()); 9191 } else { 9192 /* logic to rebuild VSI, same like ethtool -L */ 9193 u16 offset = 0, qcount_tx = 0, qcount_rx = 0; 9194 9195 for (i = 0; i < num_tcf; i++) { 9196 if (!(ena_tc_qdisc & BIT(i))) 9197 continue; 9198 9199 offset = vsi->mqprio_qopt.qopt.offset[i]; 9200 qcount_rx = vsi->mqprio_qopt.qopt.count[i]; 9201 qcount_tx = vsi->mqprio_qopt.qopt.count[i]; 9202 } 9203 vsi->req_txq = offset + qcount_tx; 9204 vsi->req_rxq = offset + qcount_rx; 9205 9206 /* store away original rss_size info, so that it gets reused 9207 * form ice_vsi_rebuild during tc-qdisc delete stage - to 9208 * determine, what should be the rss_sizefor main VSI 9209 */ 9210 vsi->orig_rss_size = vsi->rss_size; 9211 } 9212 9213 /* save current values of Tx and Rx queues before calling VSI rebuild 9214 * for fallback option 9215 */ 9216 cur_txq = vsi->num_txq; 9217 cur_rxq = vsi->num_rxq; 9218 9219 /* proceed with rebuild main VSI using correct number of queues */ 9220 ret = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT); 9221 if (ret) { 9222 /* fallback to current number of queues */ 9223 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n"); 9224 vsi->req_txq = cur_txq; 9225 vsi->req_rxq = cur_rxq; 9226 clear_bit(ICE_RESET_FAILED, pf->state); 9227 if (ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT)) { 9228 dev_err(dev, "Rebuild of main VSI failed again\n"); 9229 return ret; 9230 } 9231 } 9232 9233 vsi->all_numtc = num_tcf; 9234 vsi->all_enatc = ena_tc_qdisc; 9235 ret = ice_vsi_cfg_tc(vsi, ena_tc_qdisc); 9236 if (ret) { 9237 netdev_err(netdev, "failed configuring TC for VSI id=%d\n", 9238 vsi->vsi_num); 9239 goto exit; 9240 } 9241 9242 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) { 9243 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0]; 9244 u64 min_tx_rate = vsi->mqprio_qopt.min_rate[0]; 9245 9246 /* set TC0 rate limit if specified */ 9247 if (max_tx_rate || min_tx_rate) { 9248 /* convert to Kbits/s */ 9249 if (max_tx_rate) 9250 max_tx_rate = div_u64(max_tx_rate, ICE_BW_KBPS_DIVISOR); 9251 if (min_tx_rate) 9252 min_tx_rate = div_u64(min_tx_rate, ICE_BW_KBPS_DIVISOR); 9253 9254 ret = ice_set_bw_limit(vsi, max_tx_rate, min_tx_rate); 9255 if (!ret) { 9256 dev_dbg(dev, "set Tx rate max %llu min %llu for VSI(%u)\n", 9257 max_tx_rate, min_tx_rate, vsi->vsi_num); 9258 } else { 9259 dev_err(dev, "failed to set Tx rate max %llu min %llu for VSI(%u)\n", 9260 max_tx_rate, min_tx_rate, vsi->vsi_num); 9261 goto exit; 9262 } 9263 } 9264 ret = ice_create_q_channels(vsi); 9265 if (ret) { 9266 netdev_err(netdev, "failed configuring queue channels\n"); 9267 goto exit; 9268 } else { 9269 netdev_dbg(netdev, "successfully configured channels\n"); 9270 } 9271 } 9272 9273 if (vsi->ch_rss_size) 9274 ice_vsi_cfg_rss_lut_key(vsi); 9275 9276 exit: 9277 /* if error, reset the all_numtc and all_enatc */ 9278 if (ret) { 9279 vsi->all_numtc = 0; 9280 vsi->all_enatc = 0; 9281 } 9282 /* resume VSI */ 9283 ice_ena_vsi(vsi, true); 9284 9285 return ret; 9286 } 9287 9288 static LIST_HEAD(ice_block_cb_list); 9289 9290 static int 9291 ice_setup_tc(struct net_device *netdev, enum tc_setup_type type, 9292 void *type_data) 9293 { 9294 struct ice_netdev_priv *np = netdev_priv(netdev); 9295 struct ice_pf *pf = np->vsi->back; 9296 bool locked = false; 9297 int err; 9298 9299 switch (type) { 9300 case TC_SETUP_BLOCK: 9301 return flow_block_cb_setup_simple(type_data, 9302 &ice_block_cb_list, 9303 ice_setup_tc_block_cb, 9304 np, np, true); 9305 case TC_SETUP_QDISC_MQPRIO: 9306 if (ice_is_eswitch_mode_switchdev(pf)) { 9307 netdev_err(netdev, "TC MQPRIO offload not supported, switchdev is enabled\n"); 9308 return -EOPNOTSUPP; 9309 } 9310 9311 if (pf->adev) { 9312 mutex_lock(&pf->adev_mutex); 9313 device_lock(&pf->adev->dev); 9314 locked = true; 9315 if (pf->adev->dev.driver) { 9316 netdev_err(netdev, "Cannot change qdisc when RDMA is active\n"); 9317 err = -EBUSY; 9318 goto adev_unlock; 9319 } 9320 } 9321 9322 /* setup traffic classifier for receive side */ 9323 mutex_lock(&pf->tc_mutex); 9324 err = ice_setup_tc_mqprio_qdisc(netdev, type_data); 9325 mutex_unlock(&pf->tc_mutex); 9326 9327 adev_unlock: 9328 if (locked) { 9329 device_unlock(&pf->adev->dev); 9330 mutex_unlock(&pf->adev_mutex); 9331 } 9332 return err; 9333 default: 9334 return -EOPNOTSUPP; 9335 } 9336 return -EOPNOTSUPP; 9337 } 9338 9339 static struct ice_indr_block_priv * 9340 ice_indr_block_priv_lookup(struct ice_netdev_priv *np, 9341 struct net_device *netdev) 9342 { 9343 struct ice_indr_block_priv *cb_priv; 9344 9345 list_for_each_entry(cb_priv, &np->tc_indr_block_priv_list, list) { 9346 if (!cb_priv->netdev) 9347 return NULL; 9348 if (cb_priv->netdev == netdev) 9349 return cb_priv; 9350 } 9351 return NULL; 9352 } 9353 9354 static int 9355 ice_indr_setup_block_cb(enum tc_setup_type type, void *type_data, 9356 void *indr_priv) 9357 { 9358 struct ice_indr_block_priv *priv = indr_priv; 9359 struct ice_netdev_priv *np = priv->np; 9360 9361 switch (type) { 9362 case TC_SETUP_CLSFLOWER: 9363 return ice_setup_tc_cls_flower(np, priv->netdev, 9364 (struct flow_cls_offload *) 9365 type_data); 9366 default: 9367 return -EOPNOTSUPP; 9368 } 9369 } 9370 9371 static int 9372 ice_indr_setup_tc_block(struct net_device *netdev, struct Qdisc *sch, 9373 struct ice_netdev_priv *np, 9374 struct flow_block_offload *f, void *data, 9375 void (*cleanup)(struct flow_block_cb *block_cb)) 9376 { 9377 struct ice_indr_block_priv *indr_priv; 9378 struct flow_block_cb *block_cb; 9379 9380 if (!ice_is_tunnel_supported(netdev) && 9381 !(is_vlan_dev(netdev) && 9382 vlan_dev_real_dev(netdev) == np->vsi->netdev)) 9383 return -EOPNOTSUPP; 9384 9385 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS) 9386 return -EOPNOTSUPP; 9387 9388 switch (f->command) { 9389 case FLOW_BLOCK_BIND: 9390 indr_priv = ice_indr_block_priv_lookup(np, netdev); 9391 if (indr_priv) 9392 return -EEXIST; 9393 9394 indr_priv = kzalloc(sizeof(*indr_priv), GFP_KERNEL); 9395 if (!indr_priv) 9396 return -ENOMEM; 9397 9398 indr_priv->netdev = netdev; 9399 indr_priv->np = np; 9400 list_add(&indr_priv->list, &np->tc_indr_block_priv_list); 9401 9402 block_cb = 9403 flow_indr_block_cb_alloc(ice_indr_setup_block_cb, 9404 indr_priv, indr_priv, 9405 ice_rep_indr_tc_block_unbind, 9406 f, netdev, sch, data, np, 9407 cleanup); 9408 9409 if (IS_ERR(block_cb)) { 9410 list_del(&indr_priv->list); 9411 kfree(indr_priv); 9412 return PTR_ERR(block_cb); 9413 } 9414 flow_block_cb_add(block_cb, f); 9415 list_add_tail(&block_cb->driver_list, &ice_block_cb_list); 9416 break; 9417 case FLOW_BLOCK_UNBIND: 9418 indr_priv = ice_indr_block_priv_lookup(np, netdev); 9419 if (!indr_priv) 9420 return -ENOENT; 9421 9422 block_cb = flow_block_cb_lookup(f->block, 9423 ice_indr_setup_block_cb, 9424 indr_priv); 9425 if (!block_cb) 9426 return -ENOENT; 9427 9428 flow_indr_block_cb_remove(block_cb, f); 9429 9430 list_del(&block_cb->driver_list); 9431 break; 9432 default: 9433 return -EOPNOTSUPP; 9434 } 9435 return 0; 9436 } 9437 9438 static int 9439 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, 9440 void *cb_priv, enum tc_setup_type type, void *type_data, 9441 void *data, 9442 void (*cleanup)(struct flow_block_cb *block_cb)) 9443 { 9444 switch (type) { 9445 case TC_SETUP_BLOCK: 9446 return ice_indr_setup_tc_block(netdev, sch, cb_priv, type_data, 9447 data, cleanup); 9448 9449 default: 9450 return -EOPNOTSUPP; 9451 } 9452 } 9453 9454 /** 9455 * ice_open - Called when a network interface becomes active 9456 * @netdev: network interface device structure 9457 * 9458 * The open entry point is called when a network interface is made 9459 * active by the system (IFF_UP). At this point all resources needed 9460 * for transmit and receive operations are allocated, the interrupt 9461 * handler is registered with the OS, the netdev watchdog is enabled, 9462 * and the stack is notified that the interface is ready. 9463 * 9464 * Returns 0 on success, negative value on failure 9465 */ 9466 int ice_open(struct net_device *netdev) 9467 { 9468 struct ice_netdev_priv *np = netdev_priv(netdev); 9469 struct ice_pf *pf = np->vsi->back; 9470 9471 if (ice_is_reset_in_progress(pf->state)) { 9472 netdev_err(netdev, "can't open net device while reset is in progress"); 9473 return -EBUSY; 9474 } 9475 9476 return ice_open_internal(netdev); 9477 } 9478 9479 /** 9480 * ice_open_internal - Called when a network interface becomes active 9481 * @netdev: network interface device structure 9482 * 9483 * Internal ice_open implementation. Should not be used directly except for ice_open and reset 9484 * handling routine 9485 * 9486 * Returns 0 on success, negative value on failure 9487 */ 9488 int ice_open_internal(struct net_device *netdev) 9489 { 9490 struct ice_netdev_priv *np = netdev_priv(netdev); 9491 struct ice_vsi *vsi = np->vsi; 9492 struct ice_pf *pf = vsi->back; 9493 struct ice_port_info *pi; 9494 int err; 9495 9496 if (test_bit(ICE_NEEDS_RESTART, pf->state)) { 9497 netdev_err(netdev, "driver needs to be unloaded and reloaded\n"); 9498 return -EIO; 9499 } 9500 9501 netif_carrier_off(netdev); 9502 9503 pi = vsi->port_info; 9504 err = ice_update_link_info(pi); 9505 if (err) { 9506 netdev_err(netdev, "Failed to get link info, error %d\n", err); 9507 return err; 9508 } 9509 9510 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err); 9511 9512 /* Set PHY if there is media, otherwise, turn off PHY */ 9513 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { 9514 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags); 9515 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) { 9516 err = ice_init_phy_user_cfg(pi); 9517 if (err) { 9518 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n", 9519 err); 9520 return err; 9521 } 9522 } 9523 9524 err = ice_configure_phy(vsi); 9525 if (err) { 9526 netdev_err(netdev, "Failed to set physical link up, error %d\n", 9527 err); 9528 return err; 9529 } 9530 } else { 9531 set_bit(ICE_FLAG_NO_MEDIA, pf->flags); 9532 ice_set_link(vsi, false); 9533 } 9534 9535 err = ice_vsi_open(vsi); 9536 if (err) 9537 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n", 9538 vsi->vsi_num, vsi->vsw->sw_id); 9539 9540 /* Update existing tunnels information */ 9541 udp_tunnel_get_rx_info(netdev); 9542 9543 return err; 9544 } 9545 9546 /** 9547 * ice_stop - Disables a network interface 9548 * @netdev: network interface device structure 9549 * 9550 * The stop entry point is called when an interface is de-activated by the OS, 9551 * and the netdevice enters the DOWN state. The hardware is still under the 9552 * driver's control, but the netdev interface is disabled. 9553 * 9554 * Returns success only - not allowed to fail 9555 */ 9556 int ice_stop(struct net_device *netdev) 9557 { 9558 struct ice_netdev_priv *np = netdev_priv(netdev); 9559 struct ice_vsi *vsi = np->vsi; 9560 struct ice_pf *pf = vsi->back; 9561 9562 if (ice_is_reset_in_progress(pf->state)) { 9563 netdev_err(netdev, "can't stop net device while reset is in progress"); 9564 return -EBUSY; 9565 } 9566 9567 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) { 9568 int link_err = ice_force_phys_link_state(vsi, false); 9569 9570 if (link_err) { 9571 if (link_err == -ENOMEDIUM) 9572 netdev_info(vsi->netdev, "Skipping link reconfig - no media attached, VSI %d\n", 9573 vsi->vsi_num); 9574 else 9575 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n", 9576 vsi->vsi_num, link_err); 9577 9578 ice_vsi_close(vsi); 9579 return -EIO; 9580 } 9581 } 9582 9583 ice_vsi_close(vsi); 9584 9585 return 0; 9586 } 9587 9588 /** 9589 * ice_features_check - Validate encapsulated packet conforms to limits 9590 * @skb: skb buffer 9591 * @netdev: This port's netdev 9592 * @features: Offload features that the stack believes apply 9593 */ 9594 static netdev_features_t 9595 ice_features_check(struct sk_buff *skb, 9596 struct net_device __always_unused *netdev, 9597 netdev_features_t features) 9598 { 9599 bool gso = skb_is_gso(skb); 9600 size_t len; 9601 9602 /* No point in doing any of this if neither checksum nor GSO are 9603 * being requested for this frame. We can rule out both by just 9604 * checking for CHECKSUM_PARTIAL 9605 */ 9606 if (skb->ip_summed != CHECKSUM_PARTIAL) 9607 return features; 9608 9609 /* We cannot support GSO if the MSS is going to be less than 9610 * 64 bytes. If it is then we need to drop support for GSO. 9611 */ 9612 if (gso && (skb_shinfo(skb)->gso_size < ICE_TXD_CTX_MIN_MSS)) 9613 features &= ~NETIF_F_GSO_MASK; 9614 9615 len = skb_network_offset(skb); 9616 if (len > ICE_TXD_MACLEN_MAX || len & 0x1) 9617 goto out_rm_features; 9618 9619 len = skb_network_header_len(skb); 9620 if (len > ICE_TXD_IPLEN_MAX || len & 0x1) 9621 goto out_rm_features; 9622 9623 if (skb->encapsulation) { 9624 /* this must work for VXLAN frames AND IPIP/SIT frames, and in 9625 * the case of IPIP frames, the transport header pointer is 9626 * after the inner header! So check to make sure that this 9627 * is a GRE or UDP_TUNNEL frame before doing that math. 9628 */ 9629 if (gso && (skb_shinfo(skb)->gso_type & 9630 (SKB_GSO_GRE | SKB_GSO_UDP_TUNNEL))) { 9631 len = skb_inner_network_header(skb) - 9632 skb_transport_header(skb); 9633 if (len > ICE_TXD_L4LEN_MAX || len & 0x1) 9634 goto out_rm_features; 9635 } 9636 9637 len = skb_inner_network_header_len(skb); 9638 if (len > ICE_TXD_IPLEN_MAX || len & 0x1) 9639 goto out_rm_features; 9640 } 9641 9642 return features; 9643 out_rm_features: 9644 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK); 9645 } 9646 9647 static const struct net_device_ops ice_netdev_safe_mode_ops = { 9648 .ndo_open = ice_open, 9649 .ndo_stop = ice_stop, 9650 .ndo_start_xmit = ice_start_xmit, 9651 .ndo_set_mac_address = ice_set_mac_address, 9652 .ndo_validate_addr = eth_validate_addr, 9653 .ndo_change_mtu = ice_change_mtu, 9654 .ndo_get_stats64 = ice_get_stats64, 9655 .ndo_tx_timeout = ice_tx_timeout, 9656 .ndo_bpf = ice_xdp_safe_mode, 9657 }; 9658 9659 static const struct net_device_ops ice_netdev_ops = { 9660 .ndo_open = ice_open, 9661 .ndo_stop = ice_stop, 9662 .ndo_start_xmit = ice_start_xmit, 9663 .ndo_select_queue = ice_select_queue, 9664 .ndo_features_check = ice_features_check, 9665 .ndo_fix_features = ice_fix_features, 9666 .ndo_set_rx_mode = ice_set_rx_mode, 9667 .ndo_set_mac_address = ice_set_mac_address, 9668 .ndo_validate_addr = eth_validate_addr, 9669 .ndo_change_mtu = ice_change_mtu, 9670 .ndo_get_stats64 = ice_get_stats64, 9671 .ndo_set_tx_maxrate = ice_set_tx_maxrate, 9672 .ndo_eth_ioctl = ice_eth_ioctl, 9673 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk, 9674 .ndo_set_vf_mac = ice_set_vf_mac, 9675 .ndo_get_vf_config = ice_get_vf_cfg, 9676 .ndo_set_vf_trust = ice_set_vf_trust, 9677 .ndo_set_vf_vlan = ice_set_vf_port_vlan, 9678 .ndo_set_vf_link_state = ice_set_vf_link_state, 9679 .ndo_get_vf_stats = ice_get_vf_stats, 9680 .ndo_set_vf_rate = ice_set_vf_bw, 9681 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid, 9682 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid, 9683 .ndo_setup_tc = ice_setup_tc, 9684 .ndo_set_features = ice_set_features, 9685 .ndo_bridge_getlink = ice_bridge_getlink, 9686 .ndo_bridge_setlink = ice_bridge_setlink, 9687 .ndo_fdb_add = ice_fdb_add, 9688 .ndo_fdb_del = ice_fdb_del, 9689 #ifdef CONFIG_RFS_ACCEL 9690 .ndo_rx_flow_steer = ice_rx_flow_steer, 9691 #endif 9692 .ndo_tx_timeout = ice_tx_timeout, 9693 .ndo_bpf = ice_xdp, 9694 .ndo_xdp_xmit = ice_xdp_xmit, 9695 .ndo_xsk_wakeup = ice_xsk_wakeup, 9696 }; 9697