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