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