| // SPDX-License-Identifier: GPL-2.0 |
| /* Copyright (c) 2018, Intel Corporation. */ |
| |
| /* Intel(R) Ethernet Connection E800 Series Linux Driver */ |
| |
| #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| |
| #include <generated/utsrelease.h> |
| #include "ice.h" |
| #include "ice_base.h" |
| #include "ice_lib.h" |
| #include "ice_fltr.h" |
| #include "ice_dcb_lib.h" |
| #include "ice_dcb_nl.h" |
| #include "ice_devlink.h" |
| /* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the |
| * ice tracepoint functions. This must be done exactly once across the |
| * ice driver. |
| */ |
| #define CREATE_TRACE_POINTS |
| #include "ice_trace.h" |
| |
| #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver" |
| static const char ice_driver_string[] = DRV_SUMMARY; |
| static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation."; |
| |
| /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */ |
| #define ICE_DDP_PKG_PATH "intel/ice/ddp/" |
| #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg" |
| |
| MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| MODULE_DESCRIPTION(DRV_SUMMARY); |
| MODULE_LICENSE("GPL v2"); |
| MODULE_FIRMWARE(ICE_DDP_PKG_FILE); |
| |
| static int debug = -1; |
| module_param(debug, int, 0644); |
| #ifndef CONFIG_DYNAMIC_DEBUG |
| MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)"); |
| #else |
| MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)"); |
| #endif /* !CONFIG_DYNAMIC_DEBUG */ |
| |
| static DEFINE_IDA(ice_aux_ida); |
| |
| static struct workqueue_struct *ice_wq; |
| static const struct net_device_ops ice_netdev_safe_mode_ops; |
| static const struct net_device_ops ice_netdev_ops; |
| static int ice_vsi_open(struct ice_vsi *vsi); |
| |
| static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type); |
| |
| static void ice_vsi_release_all(struct ice_pf *pf); |
| |
| bool netif_is_ice(struct net_device *dev) |
| { |
| return dev && (dev->netdev_ops == &ice_netdev_ops); |
| } |
| |
| /** |
| * ice_get_tx_pending - returns number of Tx descriptors not processed |
| * @ring: the ring of descriptors |
| */ |
| static u16 ice_get_tx_pending(struct ice_ring *ring) |
| { |
| u16 head, tail; |
| |
| head = ring->next_to_clean; |
| tail = ring->next_to_use; |
| |
| if (head != tail) |
| return (head < tail) ? |
| tail - head : (tail + ring->count - head); |
| return 0; |
| } |
| |
| /** |
| * ice_check_for_hang_subtask - check for and recover hung queues |
| * @pf: pointer to PF struct |
| */ |
| static void ice_check_for_hang_subtask(struct ice_pf *pf) |
| { |
| struct ice_vsi *vsi = NULL; |
| struct ice_hw *hw; |
| unsigned int i; |
| int packets; |
| u32 v; |
| |
| ice_for_each_vsi(pf, v) |
| if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) { |
| vsi = pf->vsi[v]; |
| break; |
| } |
| |
| if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state)) |
| return; |
| |
| if (!(vsi->netdev && netif_carrier_ok(vsi->netdev))) |
| return; |
| |
| hw = &vsi->back->hw; |
| |
| for (i = 0; i < vsi->num_txq; i++) { |
| struct ice_ring *tx_ring = vsi->tx_rings[i]; |
| |
| if (tx_ring && tx_ring->desc) { |
| /* If packet counter has not changed the queue is |
| * likely stalled, so force an interrupt for this |
| * queue. |
| * |
| * prev_pkt would be negative if there was no |
| * pending work. |
| */ |
| packets = tx_ring->stats.pkts & INT_MAX; |
| if (tx_ring->tx_stats.prev_pkt == packets) { |
| /* Trigger sw interrupt to revive the queue */ |
| ice_trigger_sw_intr(hw, tx_ring->q_vector); |
| continue; |
| } |
| |
| /* Memory barrier between read of packet count and call |
| * to ice_get_tx_pending() |
| */ |
| smp_rmb(); |
| tx_ring->tx_stats.prev_pkt = |
| ice_get_tx_pending(tx_ring) ? packets : -1; |
| } |
| } |
| } |
| |
| /** |
| * ice_init_mac_fltr - Set initial MAC filters |
| * @pf: board private structure |
| * |
| * Set initial set of MAC filters for PF VSI; configure filters for permanent |
| * address and broadcast address. If an error is encountered, netdevice will be |
| * unregistered. |
| */ |
| static int ice_init_mac_fltr(struct ice_pf *pf) |
| { |
| enum ice_status status; |
| struct ice_vsi *vsi; |
| u8 *perm_addr; |
| |
| vsi = ice_get_main_vsi(pf); |
| if (!vsi) |
| return -EINVAL; |
| |
| perm_addr = vsi->port_info->mac.perm_addr; |
| status = ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI); |
| if (status) |
| return -EIO; |
| |
| return 0; |
| } |
| |
| /** |
| * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced |
| * @netdev: the net device on which the sync is happening |
| * @addr: MAC address to sync |
| * |
| * This is a callback function which is called by the in kernel device sync |
| * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only |
| * populates the tmp_sync_list, which is later used by ice_add_mac to add the |
| * MAC filters from the hardware. |
| */ |
| static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr) |
| { |
| struct ice_netdev_priv *np = netdev_priv(netdev); |
| struct ice_vsi *vsi = np->vsi; |
| |
| if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr, |
| ICE_FWD_TO_VSI)) |
| return -EINVAL; |
| |
| return 0; |
| } |
| |
| /** |
| * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced |
| * @netdev: the net device on which the unsync is happening |
| * @addr: MAC address to unsync |
| * |
| * This is a callback function which is called by the in kernel device unsync |
| * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only |
| * populates the tmp_unsync_list, which is later used by ice_remove_mac to |
| * delete the MAC filters from the hardware. |
| */ |
| static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr) |
| { |
| struct ice_netdev_priv *np = netdev_priv(netdev); |
| struct ice_vsi *vsi = np->vsi; |
| |
| /* Under some circumstances, we might receive a request to delete our |
| * own device address from our uc list. Because we store the device |
| * address in the VSI's MAC filter list, we need to ignore such |
| * requests and not delete our device address from this list. |
| */ |
| if (ether_addr_equal(addr, netdev->dev_addr)) |
| return 0; |
| |
| if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr, |
| ICE_FWD_TO_VSI)) |
| return -EINVAL; |
| |
| return 0; |
| } |
| |
| /** |
| * ice_vsi_fltr_changed - check if filter state changed |
| * @vsi: VSI to be checked |
| * |
| * returns true if filter state has changed, false otherwise. |
| */ |
| static bool ice_vsi_fltr_changed(struct ice_vsi *vsi) |
| { |
| return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) || |
| test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state) || |
| test_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state); |
| } |
| |
| /** |
| * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF |
| * @vsi: the VSI being configured |
| * @promisc_m: mask of promiscuous config bits |
| * @set_promisc: enable or disable promisc flag request |
| * |
| */ |
| static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc) |
| { |
| struct ice_hw *hw = &vsi->back->hw; |
| enum ice_status status = 0; |
| |
| if (vsi->type != ICE_VSI_PF) |
| return 0; |
| |
| if (vsi->num_vlan > 1) { |
| status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m, |
| set_promisc); |
| } else { |
| if (set_promisc) |
| status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m, |
| 0); |
| else |
| status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m, |
| 0); |
| } |
| |
| if (status) |
| return -EIO; |
| |
| return 0; |
| } |
| |
| /** |
| * ice_vsi_sync_fltr - Update the VSI filter list to the HW |
| * @vsi: ptr to the VSI |
| * |
| * Push any outstanding VSI filter changes through the AdminQ. |
| */ |
| static int ice_vsi_sync_fltr(struct ice_vsi *vsi) |
| { |
| struct device *dev = ice_pf_to_dev(vsi->back); |
| struct net_device *netdev = vsi->netdev; |
| bool promisc_forced_on = false; |
| struct ice_pf *pf = vsi->back; |
| struct ice_hw *hw = &pf->hw; |
| enum ice_status status = 0; |
| u32 changed_flags = 0; |
| u8 promisc_m; |
| int err = 0; |
| |
| if (!vsi->netdev) |
| return -EINVAL; |
| |
| while (test_and_set_bit(ICE_CFG_BUSY, vsi->state)) |
| usleep_range(1000, 2000); |
| |
| changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags; |
| vsi->current_netdev_flags = vsi->netdev->flags; |
| |
| INIT_LIST_HEAD(&vsi->tmp_sync_list); |
| INIT_LIST_HEAD(&vsi->tmp_unsync_list); |
| |
| if (ice_vsi_fltr_changed(vsi)) { |
| clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state); |
| clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); |
| clear_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state); |
| |
| /* grab the netdev's addr_list_lock */ |
| netif_addr_lock_bh(netdev); |
| __dev_uc_sync(netdev, ice_add_mac_to_sync_list, |
| ice_add_mac_to_unsync_list); |
| __dev_mc_sync(netdev, ice_add_mac_to_sync_list, |
| ice_add_mac_to_unsync_list); |
| /* our temp lists are populated. release lock */ |
| netif_addr_unlock_bh(netdev); |
| } |
| |
| /* Remove MAC addresses in the unsync list */ |
| status = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list); |
| ice_fltr_free_list(dev, &vsi->tmp_unsync_list); |
| if (status) { |
| netdev_err(netdev, "Failed to delete MAC filters\n"); |
| /* if we failed because of alloc failures, just bail */ |
| if (status == ICE_ERR_NO_MEMORY) { |
| err = -ENOMEM; |
| goto out; |
| } |
| } |
| |
| /* Add MAC addresses in the sync list */ |
| status = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list); |
| ice_fltr_free_list(dev, &vsi->tmp_sync_list); |
| /* If filter is added successfully or already exists, do not go into |
| * 'if' condition and report it as error. Instead continue processing |
| * rest of the function. |
| */ |
| if (status && status != ICE_ERR_ALREADY_EXISTS) { |
| netdev_err(netdev, "Failed to add MAC filters\n"); |
| /* If there is no more space for new umac filters, VSI |
| * should go into promiscuous mode. There should be some |
| * space reserved for promiscuous filters. |
| */ |
| if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC && |
| !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC, |
| vsi->state)) { |
| promisc_forced_on = true; |
| netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n", |
| vsi->vsi_num); |
| } else { |
| err = -EIO; |
| goto out; |
| } |
| } |
| /* check for changes in promiscuous modes */ |
| if (changed_flags & IFF_ALLMULTI) { |
| if (vsi->current_netdev_flags & IFF_ALLMULTI) { |
| if (vsi->num_vlan > 1) |
| promisc_m = ICE_MCAST_VLAN_PROMISC_BITS; |
| else |
| promisc_m = ICE_MCAST_PROMISC_BITS; |
| |
| err = ice_cfg_promisc(vsi, promisc_m, true); |
| if (err) { |
| netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n", |
| vsi->vsi_num); |
| vsi->current_netdev_flags &= ~IFF_ALLMULTI; |
| goto out_promisc; |
| } |
| } else { |
| /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */ |
| if (vsi->num_vlan > 1) |
| promisc_m = ICE_MCAST_VLAN_PROMISC_BITS; |
| else |
| promisc_m = ICE_MCAST_PROMISC_BITS; |
| |
| err = ice_cfg_promisc(vsi, promisc_m, false); |
| if (err) { |
| netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n", |
| vsi->vsi_num); |
| vsi->current_netdev_flags |= IFF_ALLMULTI; |
| goto out_promisc; |
| } |
| } |
| } |
| |
| if (((changed_flags & IFF_PROMISC) || promisc_forced_on) || |
| test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) { |
| clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state); |
| if (vsi->current_netdev_flags & IFF_PROMISC) { |
| /* Apply Rx filter rule to get traffic from wire */ |
| if (!ice_is_dflt_vsi_in_use(pf->first_sw)) { |
| err = ice_set_dflt_vsi(pf->first_sw, vsi); |
| if (err && err != -EEXIST) { |
| netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n", |
| err, vsi->vsi_num); |
| vsi->current_netdev_flags &= |
| ~IFF_PROMISC; |
| goto out_promisc; |
| } |
| ice_cfg_vlan_pruning(vsi, false, false); |
| } |
| } else { |
| /* Clear Rx filter to remove traffic from wire */ |
| if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) { |
| err = ice_clear_dflt_vsi(pf->first_sw); |
| if (err) { |
| netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n", |
| err, vsi->vsi_num); |
| vsi->current_netdev_flags |= |
| IFF_PROMISC; |
| goto out_promisc; |
| } |
| if (vsi->num_vlan > 1) |
| ice_cfg_vlan_pruning(vsi, true, false); |
| } |
| } |
| } |
| goto exit; |
| |
| out_promisc: |
| set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state); |
| goto exit; |
| out: |
| /* if something went wrong then set the changed flag so we try again */ |
| set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state); |
| set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state); |
| exit: |
| clear_bit(ICE_CFG_BUSY, vsi->state); |
| return err; |
| } |
| |
| /** |
| * ice_sync_fltr_subtask - Sync the VSI filter list with HW |
| * @pf: board private structure |
| */ |
| static void ice_sync_fltr_subtask(struct ice_pf *pf) |
| { |
| int v; |
| |
| if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags))) |
| return; |
| |
| clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags); |
| |
| ice_for_each_vsi(pf, v) |
| if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) && |
| ice_vsi_sync_fltr(pf->vsi[v])) { |
| /* come back and try again later */ |
| set_bit(ICE_FLAG_FLTR_SYNC, pf->flags); |
| break; |
| } |
| } |
| |
| /** |
| * ice_pf_dis_all_vsi - Pause all VSIs on a PF |
| * @pf: the PF |
| * @locked: is the rtnl_lock already held |
| */ |
| static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked) |
| { |
| int node; |
| int v; |
| |
| ice_for_each_vsi(pf, v) |
| if (pf->vsi[v]) |
| ice_dis_vsi(pf->vsi[v], locked); |
| |
| for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++) |
| pf->pf_agg_node[node].num_vsis = 0; |
| |
| for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++) |
| pf->vf_agg_node[node].num_vsis = 0; |
| } |
| |
| /** |
| * ice_prepare_for_reset - prep for the core to reset |
| * @pf: board private structure |
| * |
| * Inform or close all dependent features in prep for reset. |
| */ |
| static void |
| ice_prepare_for_reset(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| unsigned int i; |
| |
| /* already prepared for reset */ |
| if (test_bit(ICE_PREPARED_FOR_RESET, pf->state)) |
| return; |
| |
| ice_unplug_aux_dev(pf); |
| |
| /* Notify VFs of impending reset */ |
| if (ice_check_sq_alive(hw, &hw->mailboxq)) |
| ice_vc_notify_reset(pf); |
| |
| /* Disable VFs until reset is completed */ |
| ice_for_each_vf(pf, i) |
| ice_set_vf_state_qs_dis(&pf->vf[i]); |
| |
| /* clear SW filtering DB */ |
| ice_clear_hw_tbls(hw); |
| /* disable the VSIs and their queues that are not already DOWN */ |
| ice_pf_dis_all_vsi(pf, false); |
| |
| if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags)) |
| ice_ptp_release(pf); |
| |
| if (hw->port_info) |
| ice_sched_clear_port(hw->port_info); |
| |
| ice_shutdown_all_ctrlq(hw); |
| |
| set_bit(ICE_PREPARED_FOR_RESET, pf->state); |
| } |
| |
| /** |
| * ice_do_reset - Initiate one of many types of resets |
| * @pf: board private structure |
| * @reset_type: reset type requested |
| * before this function was called. |
| */ |
| static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_hw *hw = &pf->hw; |
| |
| dev_dbg(dev, "reset_type 0x%x requested\n", reset_type); |
| |
| ice_prepare_for_reset(pf); |
| |
| /* trigger the reset */ |
| if (ice_reset(hw, reset_type)) { |
| dev_err(dev, "reset %d failed\n", reset_type); |
| set_bit(ICE_RESET_FAILED, pf->state); |
| clear_bit(ICE_RESET_OICR_RECV, pf->state); |
| clear_bit(ICE_PREPARED_FOR_RESET, pf->state); |
| clear_bit(ICE_PFR_REQ, pf->state); |
| clear_bit(ICE_CORER_REQ, pf->state); |
| clear_bit(ICE_GLOBR_REQ, pf->state); |
| wake_up(&pf->reset_wait_queue); |
| return; |
| } |
| |
| /* PFR is a bit of a special case because it doesn't result in an OICR |
| * interrupt. So for PFR, rebuild after the reset and clear the reset- |
| * associated state bits. |
| */ |
| if (reset_type == ICE_RESET_PFR) { |
| pf->pfr_count++; |
| ice_rebuild(pf, reset_type); |
| clear_bit(ICE_PREPARED_FOR_RESET, pf->state); |
| clear_bit(ICE_PFR_REQ, pf->state); |
| wake_up(&pf->reset_wait_queue); |
| ice_reset_all_vfs(pf, true); |
| } |
| } |
| |
| /** |
| * ice_reset_subtask - Set up for resetting the device and driver |
| * @pf: board private structure |
| */ |
| static void ice_reset_subtask(struct ice_pf *pf) |
| { |
| enum ice_reset_req reset_type = ICE_RESET_INVAL; |
| |
| /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an |
| * OICR interrupt. The OICR handler (ice_misc_intr) determines what type |
| * of reset is pending and sets bits in pf->state indicating the reset |
| * type and ICE_RESET_OICR_RECV. So, if the latter bit is set |
| * prepare for pending reset if not already (for PF software-initiated |
| * global resets the software should already be prepared for it as |
| * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated |
| * by firmware or software on other PFs, that bit is not set so prepare |
| * for the reset now), poll for reset done, rebuild and return. |
| */ |
| if (test_bit(ICE_RESET_OICR_RECV, pf->state)) { |
| /* Perform the largest reset requested */ |
| if (test_and_clear_bit(ICE_CORER_RECV, pf->state)) |
| reset_type = ICE_RESET_CORER; |
| if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state)) |
| reset_type = ICE_RESET_GLOBR; |
| if (test_and_clear_bit(ICE_EMPR_RECV, pf->state)) |
| reset_type = ICE_RESET_EMPR; |
| /* return if no valid reset type requested */ |
| if (reset_type == ICE_RESET_INVAL) |
| return; |
| ice_prepare_for_reset(pf); |
| |
| /* make sure we are ready to rebuild */ |
| if (ice_check_reset(&pf->hw)) { |
| set_bit(ICE_RESET_FAILED, pf->state); |
| } else { |
| /* done with reset. start rebuild */ |
| pf->hw.reset_ongoing = false; |
| ice_rebuild(pf, reset_type); |
| /* clear bit to resume normal operations, but |
| * ICE_NEEDS_RESTART bit is set in case rebuild failed |
| */ |
| clear_bit(ICE_RESET_OICR_RECV, pf->state); |
| clear_bit(ICE_PREPARED_FOR_RESET, pf->state); |
| clear_bit(ICE_PFR_REQ, pf->state); |
| clear_bit(ICE_CORER_REQ, pf->state); |
| clear_bit(ICE_GLOBR_REQ, pf->state); |
| wake_up(&pf->reset_wait_queue); |
| ice_reset_all_vfs(pf, true); |
| } |
| |
| return; |
| } |
| |
| /* No pending resets to finish processing. Check for new resets */ |
| if (test_bit(ICE_PFR_REQ, pf->state)) |
| reset_type = ICE_RESET_PFR; |
| if (test_bit(ICE_CORER_REQ, pf->state)) |
| reset_type = ICE_RESET_CORER; |
| if (test_bit(ICE_GLOBR_REQ, pf->state)) |
| reset_type = ICE_RESET_GLOBR; |
| /* If no valid reset type requested just return */ |
| if (reset_type == ICE_RESET_INVAL) |
| return; |
| |
| /* reset if not already down or busy */ |
| if (!test_bit(ICE_DOWN, pf->state) && |
| !test_bit(ICE_CFG_BUSY, pf->state)) { |
| ice_do_reset(pf, reset_type); |
| } |
| } |
| |
| /** |
| * ice_print_topo_conflict - print topology conflict message |
| * @vsi: the VSI whose topology status is being checked |
| */ |
| static void ice_print_topo_conflict(struct ice_vsi *vsi) |
| { |
| switch (vsi->port_info->phy.link_info.topo_media_conflict) { |
| case ICE_AQ_LINK_TOPO_CONFLICT: |
| case ICE_AQ_LINK_MEDIA_CONFLICT: |
| case ICE_AQ_LINK_TOPO_UNREACH_PRT: |
| case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT: |
| case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA: |
| 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"); |
| break; |
| case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA: |
| netdev_info(vsi->netdev, "Rx/Tx is disabled on this device because an unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n"); |
| break; |
| default: |
| break; |
| } |
| } |
| |
| /** |
| * ice_print_link_msg - print link up or down message |
| * @vsi: the VSI whose link status is being queried |
| * @isup: boolean for if the link is now up or down |
| */ |
| void ice_print_link_msg(struct ice_vsi *vsi, bool isup) |
| { |
| struct ice_aqc_get_phy_caps_data *caps; |
| const char *an_advertised; |
| enum ice_status status; |
| const char *fec_req; |
| const char *speed; |
| const char *fec; |
| const char *fc; |
| const char *an; |
| |
| if (!vsi) |
| return; |
| |
| if (vsi->current_isup == isup) |
| return; |
| |
| vsi->current_isup = isup; |
| |
| if (!isup) { |
| netdev_info(vsi->netdev, "NIC Link is Down\n"); |
| return; |
| } |
| |
| switch (vsi->port_info->phy.link_info.link_speed) { |
| case ICE_AQ_LINK_SPEED_100GB: |
| speed = "100 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_50GB: |
| speed = "50 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_40GB: |
| speed = "40 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_25GB: |
| speed = "25 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_20GB: |
| speed = "20 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_10GB: |
| speed = "10 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_5GB: |
| speed = "5 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_2500MB: |
| speed = "2.5 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_1000MB: |
| speed = "1 G"; |
| break; |
| case ICE_AQ_LINK_SPEED_100MB: |
| speed = "100 M"; |
| break; |
| default: |
| speed = "Unknown "; |
| break; |
| } |
| |
| switch (vsi->port_info->fc.current_mode) { |
| case ICE_FC_FULL: |
| fc = "Rx/Tx"; |
| break; |
| case ICE_FC_TX_PAUSE: |
| fc = "Tx"; |
| break; |
| case ICE_FC_RX_PAUSE: |
| fc = "Rx"; |
| break; |
| case ICE_FC_NONE: |
| fc = "None"; |
| break; |
| default: |
| fc = "Unknown"; |
| break; |
| } |
| |
| /* Get FEC mode based on negotiated link info */ |
| switch (vsi->port_info->phy.link_info.fec_info) { |
| case ICE_AQ_LINK_25G_RS_528_FEC_EN: |
| case ICE_AQ_LINK_25G_RS_544_FEC_EN: |
| fec = "RS-FEC"; |
| break; |
| case ICE_AQ_LINK_25G_KR_FEC_EN: |
| fec = "FC-FEC/BASE-R"; |
| break; |
| default: |
| fec = "NONE"; |
| break; |
| } |
| |
| /* check if autoneg completed, might be false due to not supported */ |
| if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) |
| an = "True"; |
| else |
| an = "False"; |
| |
| /* Get FEC mode requested based on PHY caps last SW configuration */ |
| caps = kzalloc(sizeof(*caps), GFP_KERNEL); |
| if (!caps) { |
| fec_req = "Unknown"; |
| an_advertised = "Unknown"; |
| goto done; |
| } |
| |
| status = ice_aq_get_phy_caps(vsi->port_info, false, |
| ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL); |
| if (status) |
| netdev_info(vsi->netdev, "Get phy capability failed.\n"); |
| |
| an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off"; |
| |
| if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ || |
| caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ) |
| fec_req = "RS-FEC"; |
| else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ || |
| caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ) |
| fec_req = "FC-FEC/BASE-R"; |
| else |
| fec_req = "NONE"; |
| |
| kfree(caps); |
| |
| done: |
| 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", |
| speed, fec_req, fec, an_advertised, an, fc); |
| ice_print_topo_conflict(vsi); |
| } |
| |
| /** |
| * ice_vsi_link_event - update the VSI's netdev |
| * @vsi: the VSI on which the link event occurred |
| * @link_up: whether or not the VSI needs to be set up or down |
| */ |
| static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up) |
| { |
| if (!vsi) |
| return; |
| |
| if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev) |
| return; |
| |
| if (vsi->type == ICE_VSI_PF) { |
| if (link_up == netif_carrier_ok(vsi->netdev)) |
| return; |
| |
| if (link_up) { |
| netif_carrier_on(vsi->netdev); |
| netif_tx_wake_all_queues(vsi->netdev); |
| } else { |
| netif_carrier_off(vsi->netdev); |
| netif_tx_stop_all_queues(vsi->netdev); |
| } |
| } |
| } |
| |
| /** |
| * ice_set_dflt_mib - send a default config MIB to the FW |
| * @pf: private PF struct |
| * |
| * This function sends a default configuration MIB to the FW. |
| * |
| * If this function errors out at any point, the driver is still able to |
| * function. The main impact is that LFC may not operate as expected. |
| * Therefore an error state in this function should be treated with a DBG |
| * message and continue on with driver rebuild/reenable. |
| */ |
| static void ice_set_dflt_mib(struct ice_pf *pf) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| u8 mib_type, *buf, *lldpmib = NULL; |
| u16 len, typelen, offset = 0; |
| struct ice_lldp_org_tlv *tlv; |
| struct ice_hw *hw = &pf->hw; |
| u32 ouisubtype; |
| |
| mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB; |
| lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL); |
| if (!lldpmib) { |
| dev_dbg(dev, "%s Failed to allocate MIB memory\n", |
| __func__); |
| return; |
| } |
| |
| /* Add ETS CFG TLV */ |
| tlv = (struct ice_lldp_org_tlv *)lldpmib; |
| typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | |
| ICE_IEEE_ETS_TLV_LEN); |
| tlv->typelen = htons(typelen); |
| ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | |
| ICE_IEEE_SUBTYPE_ETS_CFG); |
| tlv->ouisubtype = htonl(ouisubtype); |
| |
| buf = tlv->tlvinfo; |
| buf[0] = 0; |
| |
| /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0. |
| * Octets 5 - 12 are BW values, set octet 5 to 100% BW. |
| * Octets 13 - 20 are TSA values - leave as zeros |
| */ |
| buf[5] = 0x64; |
| len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S; |
| offset += len + 2; |
| tlv = (struct ice_lldp_org_tlv *) |
| ((char *)tlv + sizeof(tlv->typelen) + len); |
| |
| /* Add ETS REC TLV */ |
| buf = tlv->tlvinfo; |
| tlv->typelen = htons(typelen); |
| |
| ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | |
| ICE_IEEE_SUBTYPE_ETS_REC); |
| tlv->ouisubtype = htonl(ouisubtype); |
| |
| /* First octet of buf is reserved |
| * Octets 1 - 4 map UP to TC - all UPs map to zero |
| * Octets 5 - 12 are BW values - set TC 0 to 100%. |
| * Octets 13 - 20 are TSA value - leave as zeros |
| */ |
| buf[5] = 0x64; |
| offset += len + 2; |
| tlv = (struct ice_lldp_org_tlv *) |
| ((char *)tlv + sizeof(tlv->typelen) + len); |
| |
| /* Add PFC CFG TLV */ |
| typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) | |
| ICE_IEEE_PFC_TLV_LEN); |
| tlv->typelen = htons(typelen); |
| |
| ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) | |
| ICE_IEEE_SUBTYPE_PFC_CFG); |
| tlv->ouisubtype = htonl(ouisubtype); |
| |
| /* Octet 1 left as all zeros - PFC disabled */ |
| buf[0] = 0x08; |
| len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S; |
| offset += len + 2; |
| |
| if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL)) |
| dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__); |
| |
| kfree(lldpmib); |
| } |
| |
| /** |
| * ice_check_module_power |
| * @pf: pointer to PF struct |
| * @link_cfg_err: bitmap from the link info structure |
| * |
| * check module power level returned by a previous call to aq_get_link_info |
| * and print error messages if module power level is not supported |
| */ |
| static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err) |
| { |
| /* if module power level is supported, clear the flag */ |
| if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT | |
| ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) { |
| clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); |
| return; |
| } |
| |
| /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the |
| * above block didn't clear this bit, there's nothing to do |
| */ |
| if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags)) |
| return; |
| |
| if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) { |
| dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n"); |
| set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); |
| } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) { |
| dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n"); |
| set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags); |
| } |
| } |
| |
| /** |
| * ice_link_event - process the link event |
| * @pf: PF that the link event is associated with |
| * @pi: port_info for the port that the link event is associated with |
| * @link_up: true if the physical link is up and false if it is down |
| * @link_speed: current link speed received from the link event |
| * |
| * Returns 0 on success and negative on failure |
| */ |
| static int |
| ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up, |
| u16 link_speed) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_phy_info *phy_info; |
| enum ice_status status; |
| struct ice_vsi *vsi; |
| u16 old_link_speed; |
| bool old_link; |
| |
| phy_info = &pi->phy; |
| phy_info->link_info_old = phy_info->link_info; |
| |
| old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP); |
| old_link_speed = phy_info->link_info_old.link_speed; |
| |
| /* update the link info structures and re-enable link events, |
| * don't bail on failure due to other book keeping needed |
| */ |
| status = ice_update_link_info(pi); |
| if (status) |
| dev_dbg(dev, "Failed to update link status on port %d, err %s aq_err %s\n", |
| pi->lport, ice_stat_str(status), |
| ice_aq_str(pi->hw->adminq.sq_last_status)); |
| |
| ice_check_module_power(pf, pi->phy.link_info.link_cfg_err); |
| |
| /* Check if the link state is up after updating link info, and treat |
| * this event as an UP event since the link is actually UP now. |
| */ |
| if (phy_info->link_info.link_info & ICE_AQ_LINK_UP) |
| link_up = true; |
| |
| vsi = ice_get_main_vsi(pf); |
| if (!vsi || !vsi->port_info) |
| return -EINVAL; |
| |
| /* turn off PHY if media was removed */ |
| if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) && |
| !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) { |
| set_bit(ICE_FLAG_NO_MEDIA, pf->flags); |
| ice_set_link(vsi, false); |
| } |
| |
| /* if the old link up/down and speed is the same as the new */ |
| if (link_up == old_link && link_speed == old_link_speed) |
| return 0; |
| |
| if (ice_is_dcb_active(pf)) { |
| if (test_bit(ICE_FLAG_DCB_ENA, pf->flags)) |
| ice_dcb_rebuild(pf); |
| } else { |
| if (link_up) |
| ice_set_dflt_mib(pf); |
| } |
| ice_vsi_link_event(vsi, link_up); |
| ice_print_link_msg(vsi, link_up); |
| |
| ice_vc_notify_link_state(pf); |
| |
| return 0; |
| } |
| |
| /** |
| * ice_watchdog_subtask - periodic tasks not using event driven scheduling |
| * @pf: board private structure |
| */ |
| static void ice_watchdog_subtask(struct ice_pf *pf) |
| { |
| int i; |
| |
| /* if interface is down do nothing */ |
| if (test_bit(ICE_DOWN, pf->state) || |
| test_bit(ICE_CFG_BUSY, pf->state)) |
| return; |
| |
| /* make sure we don't do these things too often */ |
| if (time_before(jiffies, |
| pf->serv_tmr_prev + pf->serv_tmr_period)) |
| return; |
| |
| pf->serv_tmr_prev = jiffies; |
| |
| /* Update the stats for active netdevs so the network stack |
| * can look at updated numbers whenever it cares to |
| */ |
| ice_update_pf_stats(pf); |
| ice_for_each_vsi(pf, i) |
| if (pf->vsi[i] && pf->vsi[i]->netdev) |
| ice_update_vsi_stats(pf->vsi[i]); |
| } |
| |
| /** |
| * ice_init_link_events - enable/initialize link events |
| * @pi: pointer to the port_info instance |
| * |
| * Returns -EIO on failure, 0 on success |
| */ |
| static int ice_init_link_events(struct ice_port_info *pi) |
| { |
| u16 mask; |
| |
| mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA | |
| ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL)); |
| |
| if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) { |
| dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n", |
| pi->lport); |
| return -EIO; |
| } |
| |
| if (ice_aq_get_link_info(pi, true, NULL, NULL)) { |
| dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n", |
| pi->lport); |
| return -EIO; |
| } |
| |
| return 0; |
| } |
| |
| /** |
| * ice_handle_link_event - handle link event via ARQ |
| * @pf: PF that the link event is associated with |
| * @event: event structure containing link status info |
| */ |
| static int |
| ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event) |
| { |
| struct ice_aqc_get_link_status_data *link_data; |
| struct ice_port_info *port_info; |
| int status; |
| |
| link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf; |
| port_info = pf->hw.port_info; |
| if (!port_info) |
| return -EINVAL; |
| |
| status = ice_link_event(pf, port_info, |
| !!(link_data->link_info & ICE_AQ_LINK_UP), |
| le16_to_cpu(link_data->link_speed)); |
| if (status) |
| dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n", |
| status); |
| |
| return status; |
| } |
| |
| enum ice_aq_task_state { |
| ICE_AQ_TASK_WAITING = 0, |
| ICE_AQ_TASK_COMPLETE, |
| ICE_AQ_TASK_CANCELED, |
| }; |
| |
| struct ice_aq_task { |
| struct hlist_node entry; |
| |
| u16 opcode; |
| struct ice_rq_event_info *event; |
| enum ice_aq_task_state state; |
| }; |
| |
| /** |
| * ice_aq_wait_for_event - Wait for an AdminQ event from firmware |
| * @pf: pointer to the PF private structure |
| * @opcode: the opcode to wait for |
| * @timeout: how long to wait, in jiffies |
| * @event: storage for the event info |
| * |
| * Waits for a specific AdminQ completion event on the ARQ for a given PF. The |
| * current thread will be put to sleep until the specified event occurs or |
| * until the given timeout is reached. |
| * |
| * To obtain only the descriptor contents, pass an event without an allocated |
| * msg_buf. If the complete data buffer is desired, allocate the |
| * event->msg_buf with enough space ahead of time. |
| * |
| * Returns: zero on success, or a negative error code on failure. |
| */ |
| int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout, |
| struct ice_rq_event_info *event) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_aq_task *task; |
| unsigned long start; |
| long ret; |
| int err; |
| |
| task = kzalloc(sizeof(*task), GFP_KERNEL); |
| if (!task) |
| return -ENOMEM; |
| |
| INIT_HLIST_NODE(&task->entry); |
| task->opcode = opcode; |
| task->event = event; |
| task->state = ICE_AQ_TASK_WAITING; |
| |
| spin_lock_bh(&pf->aq_wait_lock); |
| hlist_add_head(&task->entry, &pf->aq_wait_list); |
| spin_unlock_bh(&pf->aq_wait_lock); |
| |
| start = jiffies; |
| |
| ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state, |
| timeout); |
| switch (task->state) { |
| case ICE_AQ_TASK_WAITING: |
| err = ret < 0 ? ret : -ETIMEDOUT; |
| break; |
| case ICE_AQ_TASK_CANCELED: |
| err = ret < 0 ? ret : -ECANCELED; |
| break; |
| case ICE_AQ_TASK_COMPLETE: |
| err = ret < 0 ? ret : 0; |
| break; |
| default: |
| WARN(1, "Unexpected AdminQ wait task state %u", task->state); |
| err = -EINVAL; |
| break; |
| } |
| |
| dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n", |
| jiffies_to_msecs(jiffies - start), |
| jiffies_to_msecs(timeout), |
| opcode); |
| |
| spin_lock_bh(&pf->aq_wait_lock); |
| hlist_del(&task->entry); |
| spin_unlock_bh(&pf->aq_wait_lock); |
| kfree(task); |
| |
| return err; |
| } |
| |
| /** |
| * ice_aq_check_events - Check if any thread is waiting for an AdminQ event |
| * @pf: pointer to the PF private structure |
| * @opcode: the opcode of the event |
| * @event: the event to check |
| * |
| * Loops over the current list of pending threads waiting for an AdminQ event. |
| * For each matching task, copy the contents of the event into the task |
| * structure and wake up the thread. |
| * |
| * If multiple threads wait for the same opcode, they will all be woken up. |
| * |
| * Note that event->msg_buf will only be duplicated if the event has a buffer |
| * with enough space already allocated. Otherwise, only the descriptor and |
| * message length will be copied. |
| * |
| * Returns: true if an event was found, false otherwise |
| */ |
| static void ice_aq_check_events(struct ice_pf *pf, u16 opcode, |
| struct ice_rq_event_info *event) |
| { |
| struct ice_aq_task *task; |
| bool found = false; |
| |
| spin_lock_bh(&pf->aq_wait_lock); |
| hlist_for_each_entry(task, &pf->aq_wait_list, entry) { |
| if (task->state || task->opcode != opcode) |
| continue; |
| |
| memcpy(&task->event->desc, &event->desc, sizeof(event->desc)); |
| task->event->msg_len = event->msg_len; |
| |
| /* Only copy the data buffer if a destination was set */ |
| if (task->event->msg_buf && |
| task->event->buf_len > event->buf_len) { |
| memcpy(task->event->msg_buf, event->msg_buf, |
| event->buf_len); |
| task->event->buf_len = event->buf_len; |
| } |
| |
| task->state = ICE_AQ_TASK_COMPLETE; |
| found = true; |
| } |
| spin_unlock_bh(&pf->aq_wait_lock); |
| |
| if (found) |
| wake_up(&pf->aq_wait_queue); |
| } |
| |
| /** |
| * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks |
| * @pf: the PF private structure |
| * |
| * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads. |
| * This will then cause ice_aq_wait_for_event to exit with -ECANCELED. |
| */ |
| static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf) |
| { |
| struct ice_aq_task *task; |
| |
| spin_lock_bh(&pf->aq_wait_lock); |
| hlist_for_each_entry(task, &pf->aq_wait_list, entry) |
| task->state = ICE_AQ_TASK_CANCELED; |
| spin_unlock_bh(&pf->aq_wait_lock); |
| |
| wake_up(&pf->aq_wait_queue); |
| } |
| |
| /** |
| * __ice_clean_ctrlq - helper function to clean controlq rings |
| * @pf: ptr to struct ice_pf |
| * @q_type: specific Control queue type |
| */ |
| static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_rq_event_info event; |
| struct ice_hw *hw = &pf->hw; |
| struct ice_ctl_q_info *cq; |
| u16 pending, i = 0; |
| const char *qtype; |
| u32 oldval, val; |
| |
| /* Do not clean control queue if/when PF reset fails */ |
| if (test_bit(ICE_RESET_FAILED, pf->state)) |
| return 0; |
| |
| switch (q_type) { |
| case ICE_CTL_Q_ADMIN: |
| cq = &hw->adminq; |
| qtype = "Admin"; |
| break; |
| case ICE_CTL_Q_SB: |
| cq = &hw->sbq; |
| qtype = "Sideband"; |
| break; |
| case ICE_CTL_Q_MAILBOX: |
| cq = &hw->mailboxq; |
| qtype = "Mailbox"; |
| /* we are going to try to detect a malicious VF, so set the |
| * state to begin detection |
| */ |
| hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT; |
| break; |
| default: |
| dev_warn(dev, "Unknown control queue type 0x%x\n", q_type); |
| return 0; |
| } |
| |
| /* check for error indications - PF_xx_AxQLEN register layout for |
| * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN. |
| */ |
| val = rd32(hw, cq->rq.len); |
| if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | |
| PF_FW_ARQLEN_ARQCRIT_M)) { |
| oldval = val; |
| if (val & PF_FW_ARQLEN_ARQVFE_M) |
| dev_dbg(dev, "%s Receive Queue VF Error detected\n", |
| qtype); |
| if (val & PF_FW_ARQLEN_ARQOVFL_M) { |
| dev_dbg(dev, "%s Receive Queue Overflow Error detected\n", |
| qtype); |
| } |
| if (val & PF_FW_ARQLEN_ARQCRIT_M) |
| dev_dbg(dev, "%s Receive Queue Critical Error detected\n", |
| qtype); |
| val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M | |
| PF_FW_ARQLEN_ARQCRIT_M); |
| if (oldval != val) |
| wr32(hw, cq->rq.len, val); |
| } |
| |
| val = rd32(hw, cq->sq.len); |
| if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | |
| PF_FW_ATQLEN_ATQCRIT_M)) { |
| oldval = val; |
| if (val & PF_FW_ATQLEN_ATQVFE_M) |
| dev_dbg(dev, "%s Send Queue VF Error detected\n", |
| qtype); |
| if (val & PF_FW_ATQLEN_ATQOVFL_M) { |
| dev_dbg(dev, "%s Send Queue Overflow Error detected\n", |
| qtype); |
| } |
| if (val & PF_FW_ATQLEN_ATQCRIT_M) |
| dev_dbg(dev, "%s Send Queue Critical Error detected\n", |
| qtype); |
| val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M | |
| PF_FW_ATQLEN_ATQCRIT_M); |
| if (oldval != val) |
| wr32(hw, cq->sq.len, val); |
| } |
| |
| event.buf_len = cq->rq_buf_size; |
| event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL); |
| if (!event.msg_buf) |
| return 0; |
| |
| do { |
| enum ice_status ret; |
| u16 opcode; |
| |
| ret = ice_clean_rq_elem(hw, cq, &event, &pending); |
| if (ret == ICE_ERR_AQ_NO_WORK) |
| break; |
| if (ret) { |
| dev_err(dev, "%s Receive Queue event error %s\n", qtype, |
| ice_stat_str(ret)); |
| break; |
| } |
| |
| opcode = le16_to_cpu(event.desc.opcode); |
| |
| /* Notify any thread that might be waiting for this event */ |
| ice_aq_check_events(pf, opcode, &event); |
| |
| switch (opcode) { |
| case ice_aqc_opc_get_link_status: |
| if (ice_handle_link_event(pf, &event)) |
| dev_err(dev, "Could not handle link event\n"); |
| break; |
| case ice_aqc_opc_event_lan_overflow: |
| ice_vf_lan_overflow_event(pf, &event); |
| break; |
| case ice_mbx_opc_send_msg_to_pf: |
| if (!ice_is_malicious_vf(pf, &event, i, pending)) |
| ice_vc_process_vf_msg(pf, &event); |
| break; |
| case ice_aqc_opc_fw_logging: |
| ice_output_fw_log(hw, &event.desc, event.msg_buf); |
| break; |
| case ice_aqc_opc_lldp_set_mib_change: |
| ice_dcb_process_lldp_set_mib_change(pf, &event); |
| break; |
| default: |
| dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n", |
| qtype, opcode); |
| break; |
| } |
| } while (pending && (i++ < ICE_DFLT_IRQ_WORK)); |
| |
| kfree(event.msg_buf); |
| |
| return pending && (i == ICE_DFLT_IRQ_WORK); |
| } |
| |
| /** |
| * ice_ctrlq_pending - check if there is a difference between ntc and ntu |
| * @hw: pointer to hardware info |
| * @cq: control queue information |
| * |
| * returns true if there are pending messages in a queue, false if there aren't |
| */ |
| static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq) |
| { |
| u16 ntu; |
| |
| ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask); |
| return cq->rq.next_to_clean != ntu; |
| } |
| |
| /** |
| * ice_clean_adminq_subtask - clean the AdminQ rings |
| * @pf: board private structure |
| */ |
| static void ice_clean_adminq_subtask(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| |
| if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state)) |
| return; |
| |
| if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN)) |
| return; |
| |
| clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state); |
| |
| /* There might be a situation where new messages arrive to a control |
| * queue between processing the last message and clearing the |
| * EVENT_PENDING bit. So before exiting, check queue head again (using |
| * ice_ctrlq_pending) and process new messages if any. |
| */ |
| if (ice_ctrlq_pending(hw, &hw->adminq)) |
| __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN); |
| |
| ice_flush(hw); |
| } |
| |
| /** |
| * ice_clean_mailboxq_subtask - clean the MailboxQ rings |
| * @pf: board private structure |
| */ |
| static void ice_clean_mailboxq_subtask(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| |
| if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state)) |
| return; |
| |
| if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX)) |
| return; |
| |
| clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state); |
| |
| if (ice_ctrlq_pending(hw, &hw->mailboxq)) |
| __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX); |
| |
| ice_flush(hw); |
| } |
| |
| /** |
| * ice_clean_sbq_subtask - clean the Sideband Queue rings |
| * @pf: board private structure |
| */ |
| static void ice_clean_sbq_subtask(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| |
| /* Nothing to do here if sideband queue is not supported */ |
| if (!ice_is_sbq_supported(hw)) { |
| clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); |
| return; |
| } |
| |
| if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state)) |
| return; |
| |
| if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB)) |
| return; |
| |
| clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); |
| |
| if (ice_ctrlq_pending(hw, &hw->sbq)) |
| __ice_clean_ctrlq(pf, ICE_CTL_Q_SB); |
| |
| ice_flush(hw); |
| } |
| |
| /** |
| * ice_service_task_schedule - schedule the service task to wake up |
| * @pf: board private structure |
| * |
| * If not already scheduled, this puts the task into the work queue. |
| */ |
| void ice_service_task_schedule(struct ice_pf *pf) |
| { |
| if (!test_bit(ICE_SERVICE_DIS, pf->state) && |
| !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) && |
| !test_bit(ICE_NEEDS_RESTART, pf->state)) |
| queue_work(ice_wq, &pf->serv_task); |
| } |
| |
| /** |
| * ice_service_task_complete - finish up the service task |
| * @pf: board private structure |
| */ |
| static void ice_service_task_complete(struct ice_pf *pf) |
| { |
| WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state)); |
| |
| /* force memory (pf->state) to sync before next service task */ |
| smp_mb__before_atomic(); |
| clear_bit(ICE_SERVICE_SCHED, pf->state); |
| } |
| |
| /** |
| * ice_service_task_stop - stop service task and cancel works |
| * @pf: board private structure |
| * |
| * Return 0 if the ICE_SERVICE_DIS bit was not already set, |
| * 1 otherwise. |
| */ |
| static int ice_service_task_stop(struct ice_pf *pf) |
| { |
| int ret; |
| |
| ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state); |
| |
| if (pf->serv_tmr.function) |
| del_timer_sync(&pf->serv_tmr); |
| if (pf->serv_task.func) |
| cancel_work_sync(&pf->serv_task); |
| |
| clear_bit(ICE_SERVICE_SCHED, pf->state); |
| return ret; |
| } |
| |
| /** |
| * ice_service_task_restart - restart service task and schedule works |
| * @pf: board private structure |
| * |
| * This function is needed for suspend and resume works (e.g WoL scenario) |
| */ |
| static void ice_service_task_restart(struct ice_pf *pf) |
| { |
| clear_bit(ICE_SERVICE_DIS, pf->state); |
| ice_service_task_schedule(pf); |
| } |
| |
| /** |
| * ice_service_timer - timer callback to schedule service task |
| * @t: pointer to timer_list |
| */ |
| static void ice_service_timer(struct timer_list *t) |
| { |
| struct ice_pf *pf = from_timer(pf, t, serv_tmr); |
| |
| mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies)); |
| ice_service_task_schedule(pf); |
| } |
| |
| /** |
| * ice_handle_mdd_event - handle malicious driver detect event |
| * @pf: pointer to the PF structure |
| * |
| * Called from service task. OICR interrupt handler indicates MDD event. |
| * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log |
| * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events |
| * disable the queue, the PF can be configured to reset the VF using ethtool |
| * private flag mdd-auto-reset-vf. |
| */ |
| static void ice_handle_mdd_event(struct ice_pf *pf) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_hw *hw = &pf->hw; |
| unsigned int i; |
| u32 reg; |
| |
| if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) { |
| /* Since the VF MDD event logging is rate limited, check if |
| * there are pending MDD events. |
| */ |
| ice_print_vfs_mdd_events(pf); |
| return; |
| } |
| |
| /* find what triggered an MDD event */ |
| reg = rd32(hw, GL_MDET_TX_PQM); |
| if (reg & GL_MDET_TX_PQM_VALID_M) { |
| u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >> |
| GL_MDET_TX_PQM_PF_NUM_S; |
| u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >> |
| GL_MDET_TX_PQM_VF_NUM_S; |
| u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >> |
| GL_MDET_TX_PQM_MAL_TYPE_S; |
| u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >> |
| GL_MDET_TX_PQM_QNUM_S); |
| |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", |
| event, queue, pf_num, vf_num); |
| wr32(hw, GL_MDET_TX_PQM, 0xffffffff); |
| } |
| |
| reg = rd32(hw, GL_MDET_TX_TCLAN); |
| if (reg & GL_MDET_TX_TCLAN_VALID_M) { |
| u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >> |
| GL_MDET_TX_TCLAN_PF_NUM_S; |
| u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >> |
| GL_MDET_TX_TCLAN_VF_NUM_S; |
| u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >> |
| GL_MDET_TX_TCLAN_MAL_TYPE_S; |
| u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >> |
| GL_MDET_TX_TCLAN_QNUM_S); |
| |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n", |
| event, queue, pf_num, vf_num); |
| wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff); |
| } |
| |
| reg = rd32(hw, GL_MDET_RX); |
| if (reg & GL_MDET_RX_VALID_M) { |
| u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >> |
| GL_MDET_RX_PF_NUM_S; |
| u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >> |
| GL_MDET_RX_VF_NUM_S; |
| u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >> |
| GL_MDET_RX_MAL_TYPE_S; |
| u16 queue = ((reg & GL_MDET_RX_QNUM_M) >> |
| GL_MDET_RX_QNUM_S); |
| |
| if (netif_msg_rx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n", |
| event, queue, pf_num, vf_num); |
| wr32(hw, GL_MDET_RX, 0xffffffff); |
| } |
| |
| /* check to see if this PF caused an MDD event */ |
| reg = rd32(hw, PF_MDET_TX_PQM); |
| if (reg & PF_MDET_TX_PQM_VALID_M) { |
| wr32(hw, PF_MDET_TX_PQM, 0xFFFF); |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n"); |
| } |
| |
| reg = rd32(hw, PF_MDET_TX_TCLAN); |
| if (reg & PF_MDET_TX_TCLAN_VALID_M) { |
| wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF); |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n"); |
| } |
| |
| reg = rd32(hw, PF_MDET_RX); |
| if (reg & PF_MDET_RX_VALID_M) { |
| wr32(hw, PF_MDET_RX, 0xFFFF); |
| if (netif_msg_rx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event RX detected on PF\n"); |
| } |
| |
| /* Check to see if one of the VFs caused an MDD event, and then |
| * increment counters and set print pending |
| */ |
| ice_for_each_vf(pf, i) { |
| struct ice_vf *vf = &pf->vf[i]; |
| |
| reg = rd32(hw, VP_MDET_TX_PQM(i)); |
| if (reg & VP_MDET_TX_PQM_VALID_M) { |
| wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF); |
| vf->mdd_tx_events.count++; |
| set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n", |
| i); |
| } |
| |
| reg = rd32(hw, VP_MDET_TX_TCLAN(i)); |
| if (reg & VP_MDET_TX_TCLAN_VALID_M) { |
| wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF); |
| vf->mdd_tx_events.count++; |
| set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n", |
| i); |
| } |
| |
| reg = rd32(hw, VP_MDET_TX_TDPU(i)); |
| if (reg & VP_MDET_TX_TDPU_VALID_M) { |
| wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF); |
| vf->mdd_tx_events.count++; |
| set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); |
| if (netif_msg_tx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n", |
| i); |
| } |
| |
| reg = rd32(hw, VP_MDET_RX(i)); |
| if (reg & VP_MDET_RX_VALID_M) { |
| wr32(hw, VP_MDET_RX(i), 0xFFFF); |
| vf->mdd_rx_events.count++; |
| set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state); |
| if (netif_msg_rx_err(pf)) |
| dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n", |
| i); |
| |
| /* Since the queue is disabled on VF Rx MDD events, the |
| * PF can be configured to reset the VF through ethtool |
| * private flag mdd-auto-reset-vf. |
| */ |
| if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) { |
| /* VF MDD event counters will be cleared by |
| * reset, so print the event prior to reset. |
| */ |
| ice_print_vf_rx_mdd_event(vf); |
| ice_reset_vf(&pf->vf[i], false); |
| } |
| } |
| } |
| |
| ice_print_vfs_mdd_events(pf); |
| } |
| |
| /** |
| * ice_force_phys_link_state - Force the physical link state |
| * @vsi: VSI to force the physical link state to up/down |
| * @link_up: true/false indicates to set the physical link to up/down |
| * |
| * Force the physical link state by getting the current PHY capabilities from |
| * hardware and setting the PHY config based on the determined capabilities. If |
| * link changes a link event will be triggered because both the Enable Automatic |
| * Link Update and LESM Enable bits are set when setting the PHY capabilities. |
| * |
| * Returns 0 on success, negative on failure |
| */ |
| static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up) |
| { |
| struct ice_aqc_get_phy_caps_data *pcaps; |
| struct ice_aqc_set_phy_cfg_data *cfg; |
| struct ice_port_info *pi; |
| struct device *dev; |
| int retcode; |
| |
| if (!vsi || !vsi->port_info || !vsi->back) |
| return -EINVAL; |
| if (vsi->type != ICE_VSI_PF) |
| return 0; |
| |
| dev = ice_pf_to_dev(vsi->back); |
| |
| pi = vsi->port_info; |
| |
| pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); |
| if (!pcaps) |
| return -ENOMEM; |
| |
| retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, |
| NULL); |
| if (retcode) { |
| dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n", |
| vsi->vsi_num, retcode); |
| retcode = -EIO; |
| goto out; |
| } |
| |
| /* No change in link */ |
| if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) && |
| link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP)) |
| goto out; |
| |
| /* Use the current user PHY configuration. The current user PHY |
| * configuration is initialized during probe from PHY capabilities |
| * software mode, and updated on set PHY configuration. |
| */ |
| cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL); |
| if (!cfg) { |
| retcode = -ENOMEM; |
| goto out; |
| } |
| |
| cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT; |
| if (link_up) |
| cfg->caps |= ICE_AQ_PHY_ENA_LINK; |
| else |
| cfg->caps &= ~ICE_AQ_PHY_ENA_LINK; |
| |
| retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL); |
| if (retcode) { |
| dev_err(dev, "Failed to set phy config, VSI %d error %d\n", |
| vsi->vsi_num, retcode); |
| retcode = -EIO; |
| } |
| |
| kfree(cfg); |
| out: |
| kfree(pcaps); |
| return retcode; |
| } |
| |
| /** |
| * ice_init_nvm_phy_type - Initialize the NVM PHY type |
| * @pi: port info structure |
| * |
| * Initialize nvm_phy_type_[low|high] for link lenient mode support |
| */ |
| static int ice_init_nvm_phy_type(struct ice_port_info *pi) |
| { |
| struct ice_aqc_get_phy_caps_data *pcaps; |
| struct ice_pf *pf = pi->hw->back; |
| enum ice_status status; |
| int err = 0; |
| |
| pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); |
| if (!pcaps) |
| return -ENOMEM; |
| |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA, pcaps, |
| NULL); |
| |
| if (status) { |
| dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); |
| err = -EIO; |
| goto out; |
| } |
| |
| pf->nvm_phy_type_hi = pcaps->phy_type_high; |
| pf->nvm_phy_type_lo = pcaps->phy_type_low; |
| |
| out: |
| kfree(pcaps); |
| return err; |
| } |
| |
| /** |
| * ice_init_link_dflt_override - Initialize link default override |
| * @pi: port info structure |
| * |
| * Initialize link default override and PHY total port shutdown during probe |
| */ |
| static void ice_init_link_dflt_override(struct ice_port_info *pi) |
| { |
| struct ice_link_default_override_tlv *ldo; |
| struct ice_pf *pf = pi->hw->back; |
| |
| ldo = &pf->link_dflt_override; |
| if (ice_get_link_default_override(ldo, pi)) |
| return; |
| |
| if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS)) |
| return; |
| |
| /* Enable Total Port Shutdown (override/replace link-down-on-close |
| * ethtool private flag) for ports with Port Disable bit set. |
| */ |
| set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags); |
| set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags); |
| } |
| |
| /** |
| * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings |
| * @pi: port info structure |
| * |
| * If default override is enabled, initialize the user PHY cfg speed and FEC |
| * settings using the default override mask from the NVM. |
| * |
| * The PHY should only be configured with the default override settings the |
| * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state |
| * is used to indicate that the user PHY cfg default override is initialized |
| * and the PHY has not been configured with the default override settings. The |
| * state is set here, and cleared in ice_configure_phy the first time the PHY is |
| * configured. |
| * |
| * This function should be called only if the FW doesn't support default |
| * configuration mode, as reported by ice_fw_supports_report_dflt_cfg. |
| */ |
| static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi) |
| { |
| struct ice_link_default_override_tlv *ldo; |
| struct ice_aqc_set_phy_cfg_data *cfg; |
| struct ice_phy_info *phy = &pi->phy; |
| struct ice_pf *pf = pi->hw->back; |
| |
| ldo = &pf->link_dflt_override; |
| |
| /* If link default override is enabled, use to mask NVM PHY capabilities |
| * for speed and FEC default configuration. |
| */ |
| cfg = &phy->curr_user_phy_cfg; |
| |
| if (ldo->phy_type_low || ldo->phy_type_high) { |
| cfg->phy_type_low = pf->nvm_phy_type_lo & |
| cpu_to_le64(ldo->phy_type_low); |
| cfg->phy_type_high = pf->nvm_phy_type_hi & |
| cpu_to_le64(ldo->phy_type_high); |
| } |
| cfg->link_fec_opt = ldo->fec_options; |
| phy->curr_user_fec_req = ICE_FEC_AUTO; |
| |
| set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state); |
| } |
| |
| /** |
| * ice_init_phy_user_cfg - Initialize the PHY user configuration |
| * @pi: port info structure |
| * |
| * Initialize the current user PHY configuration, speed, FEC, and FC requested |
| * mode to default. The PHY defaults are from get PHY capabilities topology |
| * with media so call when media is first available. An error is returned if |
| * called when media is not available. The PHY initialization completed state is |
| * set here. |
| * |
| * These configurations are used when setting PHY |
| * configuration. The user PHY configuration is updated on set PHY |
| * configuration. Returns 0 on success, negative on failure |
| */ |
| static int ice_init_phy_user_cfg(struct ice_port_info *pi) |
| { |
| struct ice_aqc_get_phy_caps_data *pcaps; |
| struct ice_phy_info *phy = &pi->phy; |
| struct ice_pf *pf = pi->hw->back; |
| enum ice_status status; |
| int err = 0; |
| |
| if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) |
| return -EIO; |
| |
| pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); |
| if (!pcaps) |
| return -ENOMEM; |
| |
| if (ice_fw_supports_report_dflt_cfg(pi->hw)) |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG, |
| pcaps, NULL); |
| else |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, |
| pcaps, NULL); |
| if (status) { |
| dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n"); |
| err = -EIO; |
| goto err_out; |
| } |
| |
| ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg); |
| |
| /* check if lenient mode is supported and enabled */ |
| if (ice_fw_supports_link_override(pi->hw) && |
| !(pcaps->module_compliance_enforcement & |
| ICE_AQC_MOD_ENFORCE_STRICT_MODE)) { |
| set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags); |
| |
| /* if the FW supports default PHY configuration mode, then the driver |
| * does not have to apply link override settings. If not, |
| * initialize user PHY configuration with link override values |
| */ |
| if (!ice_fw_supports_report_dflt_cfg(pi->hw) && |
| (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) { |
| ice_init_phy_cfg_dflt_override(pi); |
| goto out; |
| } |
| } |
| |
| /* if link default override is not enabled, set user flow control and |
| * FEC settings based on what get_phy_caps returned |
| */ |
| phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps, |
| pcaps->link_fec_options); |
| phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps); |
| |
| out: |
| phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M; |
| set_bit(ICE_PHY_INIT_COMPLETE, pf->state); |
| err_out: |
| kfree(pcaps); |
| return err; |
| } |
| |
| /** |
| * ice_configure_phy - configure PHY |
| * @vsi: VSI of PHY |
| * |
| * Set the PHY configuration. If the current PHY configuration is the same as |
| * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise |
| * configure the based get PHY capabilities for topology with media. |
| */ |
| static int ice_configure_phy(struct ice_vsi *vsi) |
| { |
| struct device *dev = ice_pf_to_dev(vsi->back); |
| struct ice_port_info *pi = vsi->port_info; |
| struct ice_aqc_get_phy_caps_data *pcaps; |
| struct ice_aqc_set_phy_cfg_data *cfg; |
| struct ice_phy_info *phy = &pi->phy; |
| struct ice_pf *pf = vsi->back; |
| enum ice_status status; |
| int err = 0; |
| |
| /* Ensure we have media as we cannot configure a medialess port */ |
| if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) |
| return -EPERM; |
| |
| ice_print_topo_conflict(vsi); |
| |
| if (phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA) |
| return -EPERM; |
| |
| if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) |
| return ice_force_phys_link_state(vsi, true); |
| |
| pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL); |
| if (!pcaps) |
| return -ENOMEM; |
| |
| /* Get current PHY config */ |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps, |
| NULL); |
| if (status) { |
| dev_err(dev, "Failed to get PHY configuration, VSI %d error %s\n", |
| vsi->vsi_num, ice_stat_str(status)); |
| err = -EIO; |
| goto done; |
| } |
| |
| /* If PHY enable link is configured and configuration has not changed, |
| * there's nothing to do |
| */ |
| if (pcaps->caps & ICE_AQC_PHY_EN_LINK && |
| ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg)) |
| goto done; |
| |
| /* Use PHY topology as baseline for configuration */ |
| memset(pcaps, 0, sizeof(*pcaps)); |
| if (ice_fw_supports_report_dflt_cfg(pi->hw)) |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG, |
| pcaps, NULL); |
| else |
| status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA, |
| pcaps, NULL); |
| if (status) { |
| dev_err(dev, "Failed to get PHY caps, VSI %d error %s\n", |
| vsi->vsi_num, ice_stat_str(status)); |
| err = -EIO; |
| goto done; |
| } |
| |
| cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); |
| if (!cfg) { |
| err = -ENOMEM; |
| goto done; |
| } |
| |
| ice_copy_phy_caps_to_cfg(pi, pcaps, cfg); |
| |
| /* Speed - If default override pending, use curr_user_phy_cfg set in |
| * ice_init_phy_user_cfg_ldo. |
| */ |
| if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, |
| vsi->back->state)) { |
| cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low; |
| cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high; |
| } else { |
| u64 phy_low = 0, phy_high = 0; |
| |
| ice_update_phy_type(&phy_low, &phy_high, |
| pi->phy.curr_user_speed_req); |
| cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low); |
| cfg->phy_type_high = pcaps->phy_type_high & |
| cpu_to_le64(phy_high); |
| } |
| |
| /* Can't provide what was requested; use PHY capabilities */ |
| if (!cfg->phy_type_low && !cfg->phy_type_high) { |
| cfg->phy_type_low = pcaps->phy_type_low; |
| cfg->phy_type_high = pcaps->phy_type_high; |
| } |
| |
| /* FEC */ |
| ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req); |
| |
| /* Can't provide what was requested; use PHY capabilities */ |
| if (cfg->link_fec_opt != |
| (cfg->link_fec_opt & pcaps->link_fec_options)) { |
| cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC; |
| cfg->link_fec_opt = pcaps->link_fec_options; |
| } |
| |
| /* Flow Control - always supported; no need to check against |
| * capabilities |
| */ |
| ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req); |
| |
| /* Enable link and link update */ |
| cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK; |
| |
| status = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL); |
| if (status) { |
| dev_err(dev, "Failed to set phy config, VSI %d error %s\n", |
| vsi->vsi_num, ice_stat_str(status)); |
| err = -EIO; |
| } |
| |
| kfree(cfg); |
| done: |
| kfree(pcaps); |
| return err; |
| } |
| |
| /** |
| * ice_check_media_subtask - Check for media |
| * @pf: pointer to PF struct |
| * |
| * If media is available, then initialize PHY user configuration if it is not |
| * been, and configure the PHY if the interface is up. |
| */ |
| static void ice_check_media_subtask(struct ice_pf *pf) |
| { |
| struct ice_port_info *pi; |
| struct ice_vsi *vsi; |
| int err; |
| |
| /* No need to check for media if it's already present */ |
| if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags)) |
| return; |
| |
| vsi = ice_get_main_vsi(pf); |
| if (!vsi) |
| return; |
| |
| /* Refresh link info and check if media is present */ |
| pi = vsi->port_info; |
| err = ice_update_link_info(pi); |
| if (err) |
| return; |
| |
| ice_check_module_power(pf, pi->phy.link_info.link_cfg_err); |
| |
| if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) { |
| if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) |
| ice_init_phy_user_cfg(pi); |
| |
| /* PHY settings are reset on media insertion, reconfigure |
| * PHY to preserve settings. |
| */ |
| if (test_bit(ICE_VSI_DOWN, vsi->state) && |
| test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) |
| return; |
| |
| err = ice_configure_phy(vsi); |
| if (!err) |
| clear_bit(ICE_FLAG_NO_MEDIA, pf->flags); |
| |
| /* A Link Status Event will be generated; the event handler |
| * will complete bringing the interface up |
| */ |
| } |
| } |
| |
| /** |
| * ice_service_task - manage and run subtasks |
| * @work: pointer to work_struct contained by the PF struct |
| */ |
| static void ice_service_task(struct work_struct *work) |
| { |
| struct ice_pf *pf = container_of(work, struct ice_pf, serv_task); |
| unsigned long start_time = jiffies; |
| |
| /* subtasks */ |
| |
| /* process reset requests first */ |
| ice_reset_subtask(pf); |
| |
| /* bail if a reset/recovery cycle is pending or rebuild failed */ |
| if (ice_is_reset_in_progress(pf->state) || |
| test_bit(ICE_SUSPENDED, pf->state) || |
| test_bit(ICE_NEEDS_RESTART, pf->state)) { |
| ice_service_task_complete(pf); |
| return; |
| } |
| |
| ice_clean_adminq_subtask(pf); |
| ice_check_media_subtask(pf); |
| ice_check_for_hang_subtask(pf); |
| ice_sync_fltr_subtask(pf); |
| ice_handle_mdd_event(pf); |
| ice_watchdog_subtask(pf); |
| |
| if (ice_is_safe_mode(pf)) { |
| ice_service_task_complete(pf); |
| return; |
| } |
| |
| ice_process_vflr_event(pf); |
| ice_clean_mailboxq_subtask(pf); |
| ice_clean_sbq_subtask(pf); |
| ice_sync_arfs_fltrs(pf); |
| ice_flush_fdir_ctx(pf); |
| |
| /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */ |
| ice_service_task_complete(pf); |
| |
| /* If the tasks have taken longer than one service timer period |
| * or there is more work to be done, reset the service timer to |
| * schedule the service task now. |
| */ |
| if (time_after(jiffies, (start_time + pf->serv_tmr_period)) || |
| test_bit(ICE_MDD_EVENT_PENDING, pf->state) || |
| test_bit(ICE_VFLR_EVENT_PENDING, pf->state) || |
| test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) || |
| test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) || |
| test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) || |
| test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state)) |
| mod_timer(&pf->serv_tmr, jiffies); |
| } |
| |
| /** |
| * ice_set_ctrlq_len - helper function to set controlq length |
| * @hw: pointer to the HW instance |
| */ |
| static void ice_set_ctrlq_len(struct ice_hw *hw) |
| { |
| hw->adminq.num_rq_entries = ICE_AQ_LEN; |
| hw->adminq.num_sq_entries = ICE_AQ_LEN; |
| hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN; |
| hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN; |
| hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M; |
| hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN; |
| hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN; |
| hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN; |
| hw->sbq.num_rq_entries = ICE_SBQ_LEN; |
| hw->sbq.num_sq_entries = ICE_SBQ_LEN; |
| hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN; |
| hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN; |
| } |
| |
| /** |
| * ice_schedule_reset - schedule a reset |
| * @pf: board private structure |
| * @reset: reset being requested |
| */ |
| int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| |
| /* bail out if earlier reset has failed */ |
| if (test_bit(ICE_RESET_FAILED, pf->state)) { |
| dev_dbg(dev, "earlier reset has failed\n"); |
| return -EIO; |
| } |
| /* bail if reset/recovery already in progress */ |
| if (ice_is_reset_in_progress(pf->state)) { |
| dev_dbg(dev, "Reset already in progress\n"); |
| return -EBUSY; |
| } |
| |
| ice_unplug_aux_dev(pf); |
| |
| switch (reset) { |
| case ICE_RESET_PFR: |
| set_bit(ICE_PFR_REQ, pf->state); |
| break; |
| case ICE_RESET_CORER: |
| set_bit(ICE_CORER_REQ, pf->state); |
| break; |
| case ICE_RESET_GLOBR: |
| set_bit(ICE_GLOBR_REQ, pf->state); |
| break; |
| default: |
| return -EINVAL; |
| } |
| |
| ice_service_task_schedule(pf); |
| return 0; |
| } |
| |
| /** |
| * ice_irq_affinity_notify - Callback for affinity changes |
| * @notify: context as to what irq was changed |
| * @mask: the new affinity mask |
| * |
| * This is a callback function used by the irq_set_affinity_notifier function |
| * so that we may register to receive changes to the irq affinity masks. |
| */ |
| static void |
| ice_irq_affinity_notify(struct irq_affinity_notify *notify, |
| const cpumask_t *mask) |
| { |
| struct ice_q_vector *q_vector = |
| container_of(notify, struct ice_q_vector, affinity_notify); |
| |
| cpumask_copy(&q_vector->affinity_mask, mask); |
| } |
| |
| /** |
| * ice_irq_affinity_release - Callback for affinity notifier release |
| * @ref: internal core kernel usage |
| * |
| * This is a callback function used by the irq_set_affinity_notifier function |
| * to inform the current notification subscriber that they will no longer |
| * receive notifications. |
| */ |
| static void ice_irq_affinity_release(struct kref __always_unused *ref) {} |
| |
| /** |
| * ice_vsi_ena_irq - Enable IRQ for the given VSI |
| * @vsi: the VSI being configured |
| */ |
| static int ice_vsi_ena_irq(struct ice_vsi *vsi) |
| { |
| struct ice_hw *hw = &vsi->back->hw; |
| int i; |
| |
| ice_for_each_q_vector(vsi, i) |
| ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]); |
| |
| ice_flush(hw); |
| return 0; |
| } |
| |
| /** |
| * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI |
| * @vsi: the VSI being configured |
| * @basename: name for the vector |
| */ |
| static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename) |
| { |
| int q_vectors = vsi->num_q_vectors; |
| struct ice_pf *pf = vsi->back; |
| int base = vsi->base_vector; |
| struct device *dev; |
| int rx_int_idx = 0; |
| int tx_int_idx = 0; |
| int vector, err; |
| int irq_num; |
| |
| dev = ice_pf_to_dev(pf); |
| for (vector = 0; vector < q_vectors; vector++) { |
| struct ice_q_vector *q_vector = vsi->q_vectors[vector]; |
| |
| irq_num = pf->msix_entries[base + vector].vector; |
| |
| if (q_vector->tx.ring && q_vector->rx.ring) { |
| snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| "%s-%s-%d", basename, "TxRx", rx_int_idx++); |
| tx_int_idx++; |
| } else if (q_vector->rx.ring) { |
| snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| "%s-%s-%d", basename, "rx", rx_int_idx++); |
| } else if (q_vector->tx.ring) { |
| snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| "%s-%s-%d", basename, "tx", tx_int_idx++); |
| } else { |
| /* skip this unused q_vector */ |
| continue; |
| } |
| if (vsi->type == ICE_VSI_CTRL && vsi->vf_id != ICE_INVAL_VFID) |
| err = devm_request_irq(dev, irq_num, vsi->irq_handler, |
| IRQF_SHARED, q_vector->name, |
| q_vector); |
| else |
| err = devm_request_irq(dev, irq_num, vsi->irq_handler, |
| 0, q_vector->name, q_vector); |
| if (err) { |
| netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n", |
| err); |
| goto free_q_irqs; |
| } |
| |
| /* register for affinity change notifications */ |
| if (!IS_ENABLED(CONFIG_RFS_ACCEL)) { |
| struct irq_affinity_notify *affinity_notify; |
| |
| affinity_notify = &q_vector->affinity_notify; |
| affinity_notify->notify = ice_irq_affinity_notify; |
| affinity_notify->release = ice_irq_affinity_release; |
| irq_set_affinity_notifier(irq_num, affinity_notify); |
| } |
| |
| /* assign the mask for this irq */ |
| irq_set_affinity_hint(irq_num, &q_vector->affinity_mask); |
| } |
| |
| vsi->irqs_ready = true; |
| return 0; |
| |
| free_q_irqs: |
| while (vector) { |
| vector--; |
| irq_num = pf->msix_entries[base + vector].vector; |
| if (!IS_ENABLED(CONFIG_RFS_ACCEL)) |
| irq_set_affinity_notifier(irq_num, NULL); |
| irq_set_affinity_hint(irq_num, NULL); |
| devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]); |
| } |
| return err; |
| } |
| |
| /** |
| * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP |
| * @vsi: VSI to setup Tx rings used by XDP |
| * |
| * Return 0 on success and negative value on error |
| */ |
| static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi) |
| { |
| struct device *dev = ice_pf_to_dev(vsi->back); |
| int i; |
| |
| for (i = 0; i < vsi->num_xdp_txq; i++) { |
| u16 xdp_q_idx = vsi->alloc_txq + i; |
| struct ice_ring *xdp_ring; |
| |
| xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL); |
| |
| if (!xdp_ring) |
| goto free_xdp_rings; |
| |
| xdp_ring->q_index = xdp_q_idx; |
| xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx]; |
| xdp_ring->ring_active = false; |
| xdp_ring->vsi = vsi; |
| xdp_ring->netdev = NULL; |
| xdp_ring->dev = dev; |
| xdp_ring->count = vsi->num_tx_desc; |
| WRITE_ONCE(vsi->xdp_rings[i], xdp_ring); |
| if (ice_setup_tx_ring(xdp_ring)) |
| goto free_xdp_rings; |
| ice_set_ring_xdp(xdp_ring); |
| xdp_ring->xsk_pool = ice_xsk_pool(xdp_ring); |
| } |
| |
| return 0; |
| |
| free_xdp_rings: |
| for (; i >= 0; i--) |
| if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) |
| ice_free_tx_ring(vsi->xdp_rings[i]); |
| return -ENOMEM; |
| } |
| |
| /** |
| * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI |
| * @vsi: VSI to set the bpf prog on |
| * @prog: the bpf prog pointer |
| */ |
| static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog) |
| { |
| struct bpf_prog *old_prog; |
| int i; |
| |
| old_prog = xchg(&vsi->xdp_prog, prog); |
| if (old_prog) |
| bpf_prog_put(old_prog); |
| |
| ice_for_each_rxq(vsi, i) |
| WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog); |
| } |
| |
| /** |
| * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP |
| * @vsi: VSI to bring up Tx rings used by XDP |
| * @prog: bpf program that will be assigned to VSI |
| * |
| * Return 0 on success and negative value on error |
| */ |
| int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog) |
| { |
| u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; |
| int xdp_rings_rem = vsi->num_xdp_txq; |
| struct ice_pf *pf = vsi->back; |
| struct ice_qs_cfg xdp_qs_cfg = { |
| .qs_mutex = &pf->avail_q_mutex, |
| .pf_map = pf->avail_txqs, |
| .pf_map_size = pf->max_pf_txqs, |
| .q_count = vsi->num_xdp_txq, |
| .scatter_count = ICE_MAX_SCATTER_TXQS, |
| .vsi_map = vsi->txq_map, |
| .vsi_map_offset = vsi->alloc_txq, |
| .mapping_mode = ICE_VSI_MAP_CONTIG |
| }; |
| enum ice_status status; |
| struct device *dev; |
| int i, v_idx; |
| |
| dev = ice_pf_to_dev(pf); |
| vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq, |
| sizeof(*vsi->xdp_rings), GFP_KERNEL); |
| if (!vsi->xdp_rings) |
| return -ENOMEM; |
| |
| vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode; |
| if (__ice_vsi_get_qs(&xdp_qs_cfg)) |
| goto err_map_xdp; |
| |
| if (ice_xdp_alloc_setup_rings(vsi)) |
| goto clear_xdp_rings; |
| |
| /* follow the logic from ice_vsi_map_rings_to_vectors */ |
| ice_for_each_q_vector(vsi, v_idx) { |
| struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; |
| int xdp_rings_per_v, q_id, q_base; |
| |
| xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem, |
| vsi->num_q_vectors - v_idx); |
| q_base = vsi->num_xdp_txq - xdp_rings_rem; |
| |
| for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) { |
| struct ice_ring *xdp_ring = vsi->xdp_rings[q_id]; |
| |
| xdp_ring->q_vector = q_vector; |
| xdp_ring->next = q_vector->tx.ring; |
| q_vector->tx.ring = xdp_ring; |
| } |
| xdp_rings_rem -= xdp_rings_per_v; |
| } |
| |
| /* omit the scheduler update if in reset path; XDP queues will be |
| * taken into account at the end of ice_vsi_rebuild, where |
| * ice_cfg_vsi_lan is being called |
| */ |
| if (ice_is_reset_in_progress(pf->state)) |
| return 0; |
| |
| /* tell the Tx scheduler that right now we have |
| * additional queues |
| */ |
| for (i = 0; i < vsi->tc_cfg.numtc; i++) |
| max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq; |
| |
| status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, |
| max_txqs); |
| if (status) { |
| dev_err(dev, "Failed VSI LAN queue config for XDP, error: %s\n", |
| ice_stat_str(status)); |
| goto clear_xdp_rings; |
| } |
| ice_vsi_assign_bpf_prog(vsi, prog); |
| |
| return 0; |
| clear_xdp_rings: |
| for (i = 0; i < vsi->num_xdp_txq; i++) |
| if (vsi->xdp_rings[i]) { |
| kfree_rcu(vsi->xdp_rings[i], rcu); |
| vsi->xdp_rings[i] = NULL; |
| } |
| |
| err_map_xdp: |
| mutex_lock(&pf->avail_q_mutex); |
| for (i = 0; i < vsi->num_xdp_txq; i++) { |
| clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); |
| vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; |
| } |
| mutex_unlock(&pf->avail_q_mutex); |
| |
| devm_kfree(dev, vsi->xdp_rings); |
| return -ENOMEM; |
| } |
| |
| /** |
| * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings |
| * @vsi: VSI to remove XDP rings |
| * |
| * Detach XDP rings from irq vectors, clean up the PF bitmap and free |
| * resources |
| */ |
| int ice_destroy_xdp_rings(struct ice_vsi *vsi) |
| { |
| u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 }; |
| struct ice_pf *pf = vsi->back; |
| int i, v_idx; |
| |
| /* q_vectors are freed in reset path so there's no point in detaching |
| * rings; in case of rebuild being triggered not from reset bits |
| * in pf->state won't be set, so additionally check first q_vector |
| * against NULL |
| */ |
| if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0]) |
| goto free_qmap; |
| |
| ice_for_each_q_vector(vsi, v_idx) { |
| struct ice_q_vector *q_vector = vsi->q_vectors[v_idx]; |
| struct ice_ring *ring; |
| |
| ice_for_each_ring(ring, q_vector->tx) |
| if (!ring->tx_buf || !ice_ring_is_xdp(ring)) |
| break; |
| |
| /* restore the value of last node prior to XDP setup */ |
| q_vector->tx.ring = ring; |
| } |
| |
| free_qmap: |
| mutex_lock(&pf->avail_q_mutex); |
| for (i = 0; i < vsi->num_xdp_txq; i++) { |
| clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs); |
| vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX; |
| } |
| mutex_unlock(&pf->avail_q_mutex); |
| |
| for (i = 0; i < vsi->num_xdp_txq; i++) |
| if (vsi->xdp_rings[i]) { |
| if (vsi->xdp_rings[i]->desc) |
| ice_free_tx_ring(vsi->xdp_rings[i]); |
| kfree_rcu(vsi->xdp_rings[i], rcu); |
| vsi->xdp_rings[i] = NULL; |
| } |
| |
| devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings); |
| vsi->xdp_rings = NULL; |
| |
| if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0]) |
| return 0; |
| |
| ice_vsi_assign_bpf_prog(vsi, NULL); |
| |
| /* notify Tx scheduler that we destroyed XDP queues and bring |
| * back the old number of child nodes |
| */ |
| for (i = 0; i < vsi->tc_cfg.numtc; i++) |
| max_txqs[i] = vsi->num_txq; |
| |
| /* change number of XDP Tx queues to 0 */ |
| vsi->num_xdp_txq = 0; |
| |
| return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc, |
| max_txqs); |
| } |
| |
| /** |
| * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI |
| * @vsi: VSI to schedule napi on |
| */ |
| static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi) |
| { |
| int i; |
| |
| ice_for_each_rxq(vsi, i) { |
| struct ice_ring *rx_ring = vsi->rx_rings[i]; |
| |
| if (rx_ring->xsk_pool) |
| napi_schedule(&rx_ring->q_vector->napi); |
| } |
| } |
| |
| /** |
| * ice_xdp_setup_prog - Add or remove XDP eBPF program |
| * @vsi: VSI to setup XDP for |
| * @prog: XDP program |
| * @extack: netlink extended ack |
| */ |
| static int |
| ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog, |
| struct netlink_ext_ack *extack) |
| { |
| int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD; |
| bool if_running = netif_running(vsi->netdev); |
| int ret = 0, xdp_ring_err = 0; |
| |
| if (frame_size > vsi->rx_buf_len) { |
| NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP"); |
| return -EOPNOTSUPP; |
| } |
| |
| /* need to stop netdev while setting up the program for Rx rings */ |
| if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) { |
| ret = ice_down(vsi); |
| if (ret) { |
| NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed"); |
| return ret; |
| } |
| } |
| |
| if (!ice_is_xdp_ena_vsi(vsi) && prog) { |
| vsi->num_xdp_txq = vsi->alloc_rxq; |
| xdp_ring_err = ice_prepare_xdp_rings(vsi, prog); |
| if (xdp_ring_err) |
| NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed"); |
| } else if (ice_is_xdp_ena_vsi(vsi) && !prog) { |
| xdp_ring_err = ice_destroy_xdp_rings(vsi); |
| if (xdp_ring_err) |
| NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed"); |
| } else { |
| ice_vsi_assign_bpf_prog(vsi, prog); |
| } |
| |
| if (if_running) |
| ret = ice_up(vsi); |
| |
| if (!ret && prog) |
| ice_vsi_rx_napi_schedule(vsi); |
| |
| return (ret || xdp_ring_err) ? -ENOMEM : 0; |
| } |
| |
| /** |
| * ice_xdp_safe_mode - XDP handler for safe mode |
| * @dev: netdevice |
| * @xdp: XDP command |
| */ |
| static int ice_xdp_safe_mode(struct net_device __always_unused *dev, |
| struct netdev_bpf *xdp) |
| { |
| NL_SET_ERR_MSG_MOD(xdp->extack, |
| "Please provide working DDP firmware package in order to use XDP\n" |
| "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst"); |
| return -EOPNOTSUPP; |
| } |
| |
| /** |
| * ice_xdp - implements XDP handler |
| * @dev: netdevice |
| * @xdp: XDP command |
| */ |
| static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
| { |
| struct ice_netdev_priv *np = netdev_priv(dev); |
| struct ice_vsi *vsi = np->vsi; |
| |
| if (vsi->type != ICE_VSI_PF) { |
| NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI"); |
| return -EINVAL; |
| } |
| |
| switch (xdp->command) { |
| case XDP_SETUP_PROG: |
| return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack); |
| case XDP_SETUP_XSK_POOL: |
| return ice_xsk_pool_setup(vsi, xdp->xsk.pool, |
| xdp->xsk.queue_id); |
| default: |
| return -EINVAL; |
| } |
| } |
| |
| /** |
| * ice_ena_misc_vector - enable the non-queue interrupts |
| * @pf: board private structure |
| */ |
| static void ice_ena_misc_vector(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| u32 val; |
| |
| /* Disable anti-spoof detection interrupt to prevent spurious event |
| * interrupts during a function reset. Anti-spoof functionally is |
| * still supported. |
| */ |
| val = rd32(hw, GL_MDCK_TX_TDPU); |
| val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M; |
| wr32(hw, GL_MDCK_TX_TDPU, val); |
| |
| /* clear things first */ |
| wr32(hw, PFINT_OICR_ENA, 0); /* disable all */ |
| rd32(hw, PFINT_OICR); /* read to clear */ |
| |
| val = (PFINT_OICR_ECC_ERR_M | |
| PFINT_OICR_MAL_DETECT_M | |
| PFINT_OICR_GRST_M | |
| PFINT_OICR_PCI_EXCEPTION_M | |
| PFINT_OICR_VFLR_M | |
| PFINT_OICR_HMC_ERR_M | |
| PFINT_OICR_PE_PUSH_M | |
| PFINT_OICR_PE_CRITERR_M); |
| |
| wr32(hw, PFINT_OICR_ENA, val); |
| |
| /* SW_ITR_IDX = 0, but don't change INTENA */ |
| wr32(hw, GLINT_DYN_CTL(pf->oicr_idx), |
| GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M); |
| } |
| |
| /** |
| * ice_misc_intr - misc interrupt handler |
| * @irq: interrupt number |
| * @data: pointer to a q_vector |
| */ |
| static irqreturn_t ice_misc_intr(int __always_unused irq, void *data) |
| { |
| struct ice_pf *pf = (struct ice_pf *)data; |
| struct ice_hw *hw = &pf->hw; |
| irqreturn_t ret = IRQ_NONE; |
| struct device *dev; |
| u32 oicr, ena_mask; |
| |
| dev = ice_pf_to_dev(pf); |
| set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state); |
| set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state); |
| set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state); |
| |
| oicr = rd32(hw, PFINT_OICR); |
| ena_mask = rd32(hw, PFINT_OICR_ENA); |
| |
| if (oicr & PFINT_OICR_SWINT_M) { |
| ena_mask &= ~PFINT_OICR_SWINT_M; |
| pf->sw_int_count++; |
| } |
| |
| if (oicr & PFINT_OICR_MAL_DETECT_M) { |
| ena_mask &= ~PFINT_OICR_MAL_DETECT_M; |
| set_bit(ICE_MDD_EVENT_PENDING, pf->state); |
| } |
| if (oicr & PFINT_OICR_VFLR_M) { |
| /* disable any further VFLR event notifications */ |
| if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) { |
| u32 reg = rd32(hw, PFINT_OICR_ENA); |
| |
| reg &= ~PFINT_OICR_VFLR_M; |
| wr32(hw, PFINT_OICR_ENA, reg); |
| } else { |
| ena_mask &= ~PFINT_OICR_VFLR_M; |
| set_bit(ICE_VFLR_EVENT_PENDING, pf->state); |
| } |
| } |
| |
| if (oicr & PFINT_OICR_GRST_M) { |
| u32 reset; |
| |
| /* we have a reset warning */ |
| ena_mask &= ~PFINT_OICR_GRST_M; |
| reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >> |
| GLGEN_RSTAT_RESET_TYPE_S; |
| |
| if (reset == ICE_RESET_CORER) |
| pf->corer_count++; |
| else if (reset == ICE_RESET_GLOBR) |
| pf->globr_count++; |
| else if (reset == ICE_RESET_EMPR) |
| pf->empr_count++; |
| else |
| dev_dbg(dev, "Invalid reset type %d\n", reset); |
| |
| /* If a reset cycle isn't already in progress, we set a bit in |
| * pf->state so that the service task can start a reset/rebuild. |
| */ |
| if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) { |
| if (reset == ICE_RESET_CORER) |
| set_bit(ICE_CORER_RECV, pf->state); |
| else if (reset == ICE_RESET_GLOBR) |
| set_bit(ICE_GLOBR_RECV, pf->state); |
| else |
| set_bit(ICE_EMPR_RECV, pf->state); |
| |
| /* There are couple of different bits at play here. |
| * hw->reset_ongoing indicates whether the hardware is |
| * in reset. This is set to true when a reset interrupt |
| * is received and set back to false after the driver |
| * has determined that the hardware is out of reset. |
| * |
| * ICE_RESET_OICR_RECV in pf->state indicates |
| * that a post reset rebuild is required before the |
| * driver is operational again. This is set above. |
| * |
| * As this is the start of the reset/rebuild cycle, set |
| * both to indicate that. |
| */ |
| hw->reset_ongoing = true; |
| } |
| } |
| |
| if (oicr & PFINT_OICR_TSYN_TX_M) { |
| ena_mask &= ~PFINT_OICR_TSYN_TX_M; |
| ice_ptp_process_ts(pf); |
| } |
| |
| if (oicr & PFINT_OICR_TSYN_EVNT_M) { |
| u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned; |
| u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx)); |
| |
| /* Save EVENTs from GTSYN register */ |
| pf->ptp.ext_ts_irq |= gltsyn_stat & (GLTSYN_STAT_EVENT0_M | |
| GLTSYN_STAT_EVENT1_M | |
| GLTSYN_STAT_EVENT2_M); |
| ena_mask &= ~PFINT_OICR_TSYN_EVNT_M; |
| kthread_queue_work(pf->ptp.kworker, &pf->ptp.extts_work); |
| } |
| |
| #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M) |
| if (oicr & ICE_AUX_CRIT_ERR) { |
| struct iidc_event *event; |
| |
| ena_mask &= ~ICE_AUX_CRIT_ERR; |
| event = kzalloc(sizeof(*event), GFP_KERNEL); |
| if (event) { |
| set_bit(IIDC_EVENT_CRIT_ERR, event->type); |
| /* report the entire OICR value to AUX driver */ |
| event->reg = oicr; |
| ice_send_event_to_aux(pf, event); |
| kfree(event); |
| } |
| } |
| |
| /* Report any remaining unexpected interrupts */ |
| oicr &= ena_mask; |
| if (oicr) { |
| dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr); |
| /* If a critical error is pending there is no choice but to |
| * reset the device. |
| */ |
| if (oicr & (PFINT_OICR_PCI_EXCEPTION_M | |
| PFINT_OICR_ECC_ERR_M)) { |
| set_bit(ICE_PFR_REQ, pf->state); |
| ice_service_task_schedule(pf); |
| } |
| } |
| ret = IRQ_HANDLED; |
| |
| ice_service_task_schedule(pf); |
| ice_irq_dynamic_ena(hw, NULL, NULL); |
| |
| return ret; |
| } |
| |
| /** |
| * ice_dis_ctrlq_interrupts - disable control queue interrupts |
| * @hw: pointer to HW structure |
| */ |
| static void ice_dis_ctrlq_interrupts(struct ice_hw *hw) |
| { |
| /* disable Admin queue Interrupt causes */ |
| wr32(hw, PFINT_FW_CTL, |
| rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M); |
| |
| /* disable Mailbox queue Interrupt causes */ |
| wr32(hw, PFINT_MBX_CTL, |
| rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M); |
| |
| wr32(hw, PFINT_SB_CTL, |
| rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M); |
| |
| /* disable Control queue Interrupt causes */ |
| wr32(hw, PFINT_OICR_CTL, |
| rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M); |
| |
| ice_flush(hw); |
| } |
| |
| /** |
| * ice_free_irq_msix_misc - Unroll misc vector setup |
| * @pf: board private structure |
| */ |
| static void ice_free_irq_msix_misc(struct ice_pf *pf) |
| { |
| struct ice_hw *hw = &pf->hw; |
| |
| ice_dis_ctrlq_interrupts(hw); |
| |
| /* disable OICR interrupt */ |
| wr32(hw, PFINT_OICR_ENA, 0); |
| ice_flush(hw); |
| |
| if (pf->msix_entries) { |
| synchronize_irq(pf->msix_entries[pf->oicr_idx].vector); |
| devm_free_irq(ice_pf_to_dev(pf), |
| pf->msix_entries[pf->oicr_idx].vector, pf); |
| } |
| |
| pf->num_avail_sw_msix += 1; |
| ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID); |
| } |
| |
| /** |
| * ice_ena_ctrlq_interrupts - enable control queue interrupts |
| * @hw: pointer to HW structure |
| * @reg_idx: HW vector index to associate the control queue interrupts with |
| */ |
| static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx) |
| { |
| u32 val; |
| |
| val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) | |
| PFINT_OICR_CTL_CAUSE_ENA_M); |
| wr32(hw, PFINT_OICR_CTL, val); |
| |
| /* enable Admin queue Interrupt causes */ |
| val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) | |
| PFINT_FW_CTL_CAUSE_ENA_M); |
| wr32(hw, PFINT_FW_CTL, val); |
| |
| /* enable Mailbox queue Interrupt causes */ |
| val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) | |
| PFINT_MBX_CTL_CAUSE_ENA_M); |
| wr32(hw, PFINT_MBX_CTL, val); |
| |
| /* This enables Sideband queue Interrupt causes */ |
| val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) | |
| PFINT_SB_CTL_CAUSE_ENA_M); |
| wr32(hw, PFINT_SB_CTL, val); |
| |
| ice_flush(hw); |
| } |
| |
| /** |
| * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events |
| * @pf: board private structure |
| * |
| * This sets up the handler for MSIX 0, which is used to manage the |
| * non-queue interrupts, e.g. AdminQ and errors. This is not used |
| * when in MSI or Legacy interrupt mode. |
| */ |
| static int ice_req_irq_msix_misc(struct ice_pf *pf) |
| { |
| struct device *dev = ice_pf_to_dev(pf); |
| struct ice_hw *hw = &pf->hw; |
| int oicr_idx, err = 0; |
| |
| if (!pf->int_name[0]) |
| snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc", |
| dev_driver_string(dev), dev_name(dev)); |
| |
| /* Do not request IRQ but do enable OICR interrupt since settings are |
| * lost during reset. Note that this function is called only during |
| * rebuild path and not while reset is in progress. |
| */ |
| if (ice_is_reset_in_progress(pf->state)) |
| goto skip_req_irq; |
| |
| /* reserve one vector in irq_tracker for misc interrupts */ |
| oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID); |
| if (oicr_idx < 0) |
| return oicr_idx; |
| |
| pf->num_avail_sw_msix -= 1; |
| pf->oicr_idx = (u16)oicr_idx; |
| |
| err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector, |
| ice_misc_intr, 0, pf->int_name, pf); |
| if (err) { |
| dev_err(dev, "devm_request_irq for %s failed: %d\n", |
| pf->int_name, err); |
| ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID); |
| pf->num_avail_sw_msix += 1; |
| return err; |
| } |
| |
| skip_req_irq: |
| ice_ena_misc_vector(pf); |
| |
| ice_ena_ctrlq_interrupts(hw, pf->oicr_idx); |
| wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx), |
| ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S); |
| |
| ice_flush(hw); |
| ice_irq_dynamic_ena(hw, NULL, NULL); |
| |
| return 0; |
| } |
| |
| /** |
| * ice_napi_add - register NAPI handler for the VSI |
| * @vsi: VSI for which NAPI handler is to be registered |
| * |
| * This function is only called in the driver's load path. Registering the NAPI |
| * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume, |
| * reset/rebuild, etc.) |
| */ |
| static void ice_napi_add(struct ice_vsi *vsi) |
| { |
| int v_idx; |
| |
| if (!vsi->netdev) |
| return; |
| |
| ice_for_each_q_vector(vsi, v_idx) |
| netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi, |
| ice_napi_poll, NAPI_POLL_WEIGHT); |
| } |
| |
| /** |
| * ice_set_ops - set netdev and ethtools ops for the given netdev |
| * @netdev: netdev instance |
| */ |
| static void ice_set_ops(struct net_device *netdev) |
| { |
| struct ice_pf *pf = ice_netdev_to_pf(netdev); |
| |
| if (ice_is_safe_mode(pf)) { |
| netdev->netdev_ops = &ice_netdev_safe_mode_ops; |
| ice_set_ethtool_safe_mode_ops(netdev); |
| return; |
| } |
| |
| netdev->netdev_ops = &ice_netdev_ops; |
| netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic; |
| ice_set_ethtool_ops(netdev); |
| } |
| |
| /** |
| * ice_set_netdev_features - set features for the given netdev |
| * @netdev: netdev instance |
| */ |
| static void ice_set_netdev_features(struct net_device *netdev) |
| { |
| struct ice_pf *pf = ice_netdev_to_pf(netdev); |
| netdev_features_t csumo_features; |
| netdev_features_t vlano_features; |
| netdev_features_t dflt_features; |
| netdev_features_t tso_features; |
| |
| if (ice_is_safe_mode(pf)) { |
| /* safe mode */ |
| netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA; |
| netdev->hw_features = netdev->features; |
| return; |
| } |
| |
| dflt_features = NETIF_F_SG | |
| NETIF_F_HIGHDMA | |
| NETIF_F_NTUPLE | |
| NETIF_F_RXHASH; |
| |
| csumo_features = NETIF_F_RXCSUM | |
| NETIF_F_IP_CSUM | |
| NETIF_F_SCTP_CRC | |
| NETIF_F_IPV6_CSUM; |
| |
| vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER | |
| NETIF_F_HW_VLAN_CTAG_TX | |
| NETIF_F_HW_VLAN_CTAG_RX; |
| |
| tso_features = NETIF_F_TSO | |
| NETIF_F_TSO_ECN | |
| NETIF_F_TSO6 | |
| NETIF_F_GSO_GRE | |
| NETIF_F_GSO_UDP_TUNNEL | |
| NETIF_F_GSO_GRE_CSUM | |
| NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| NETIF_F_GSO_PARTIAL | |
| NETIF_F_GSO_IPXIP4 | |
| NETIF_F_GSO_IPXIP6 | |
| NETIF_F_GSO_UDP_L4; |
| |
| netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| NETIF_F_GSO_GRE_CSUM; |
| /* set features that user can change */ |
| netdev->hw_features = dflt_features | csumo_features | |
| vlano_features | tso_features; |
| |
| /* add support for HW_CSUM on packets with MPLS header */ |
| netdev->mpls_features = NETIF_F_HW_CSUM; |
| |
| /* enable features */ |
| netdev->features |= netdev->hw_features; |
| /* encap and VLAN devices inherit default, csumo and tso features */ |
| netdev->hw_enc_features |= dflt_features | csumo_features | |
| tso_features; |
| netdev->vlan_features |= dflt_features | csumo_features | |
| tso_features; |
| } |
| |
| /** |
| * ice_cfg_netdev - Allocate, configure and register a netdev |
| * @vsi: the VSI associated with the new netdev |
| * |
| * Returns 0 on success, negative value on failure |
| */ |
| static int ice_cfg_netdev(struct ice_vsi *vsi) |
| { |
| struct ice_netdev_priv *np; |
| struct net_device *netdev; |
| u8 mac_addr[ETH_ALEN]; |
| |
| netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq, |
| vsi->alloc_rxq); |
| if (!netdev) |
| return -ENOMEM; |
| |
| set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state); |
| vsi->netdev = netdev; |
| np = netdev_priv(netdev); |
| np->vsi = vsi; |
| |
| ice_set_netdev_features(netdev); |
| |
| ice_set_ops(netdev); |
| |
| if (vsi->type == ICE_VSI_PF) { |
| SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back)); |
| ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr); |
| ether_addr_copy(netdev->dev_addr, mac_addr); |
| ether_addr_copy(netdev->perm_addr, mac_addr); |
| } |
| |
| netdev->priv_flags |= IFF_UNICAST_FLT; |
| |
| /* Setup netdev TC information */ |
| ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc); |
| |
| /* setup watchdog timeout value to be 5 second */ |
| netdev->watchdog_timeo = 5 * HZ; |
| |
| netdev->min_mtu = ETH_MIN_MTU; |
| netdev->max_mtu = ICE_MAX_MTU; |
| |
| return 0; |
| } |
| |
| /** |
| * ice_fill_rss_lut - Fill the RSS lookup table with default values |
| * @lut: Lookup table |
| * @rss_table_size: Lookup table size |
| * @rss_size: Range of queue number for hashing |
| */ |
| void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size) |
| { |
| u16 i; |
| |
| for (i = 0; i < rss_table_size; i++) |
| lut[i] = i % rss_size; |
| } |
| |
| /** |
| * ice_pf_vsi_setup - Set up a PF VSI |
| * @pf: board private structure |
| * @pi: pointer to the port_info instance |
| * |
| * Returns pointer to the successfully allocated VSI software struct |
|