The RSS LUT of a VSI can be changed via devlink at runtime, later in this series. Prepare the RSS LUT config for that. Add pf->rss_lut_lock, to protect the RSS LUT config of a VSI: the LUT type and size, the LUT set by the user, and q_opt_rss of the VSI context, which carries the LUT type. Take it in ethtool RSS ops, in the RSS LUT setup of a VSI, and around VSI context writes that include q_opt_rss. Set the default RSS LUT type and size of a VSI only on its init, so a VSI rebuild will keep a LUT changed via devlink. Cap the RSS queue count of a VSI to what its RSS LUT type can address: 16 for a VSI LUT, 64 for a GLOBAL LUT, 256 for a PF LUT. Do it on ethtool -L, when setting the default LUT, and on each RSS config of the VSI. VFs and SFs have up to 16 queues yet, so nothing changes for them. Take the Q_OPT section from vsi->info when toggling the RDMA filter. The cached VSI context misses later changes, like the RSS hash function set via ethtool, which the toggle reverted. Signed-off-by: Przemek Kitszel --- v7: * new patch, split out of "ice: represent RSS LUTs as devlink resources" and "ice: support up to 256 VF queues" (Jakub) --- drivers/net/ethernet/intel/ice/ice.h | 1 + drivers/net/ethernet/intel/ice/ice_lib.h | 2 + drivers/net/ethernet/intel/ice/ice_switch.h | 3 +- drivers/net/ethernet/intel/ice/ice_ethtool.c | 90 ++++++++------- drivers/net/ethernet/intel/ice/ice_idc.c | 24 ++-- drivers/net/ethernet/intel/ice/ice_lib.c | 112 ++++++++++++++----- drivers/net/ethernet/intel/ice/ice_main.c | 2 + drivers/net/ethernet/intel/ice/ice_switch.c | 11 +- 8 files changed, 161 insertions(+), 84 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h index 432da05c48c0..f614b9360f7b 100644 --- a/drivers/net/ethernet/intel/ice/ice.h +++ b/drivers/net/ethernet/intel/ice/ice.h @@ -595,6 +595,7 @@ struct ice_pf { struct mutex tc_mutex; /* lock to protect TC changes */ struct mutex adev_mutex; /* lock to protect aux device access */ struct mutex lag_mutex; /* protect ice_lag struct in PF */ + struct mutex rss_lut_lock; /* protect VSI RSS LUT config */ u32 msg_enable; struct ice_ptp ptp; struct gnss_serial *gnss_serial; diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/ethernet/intel/ice/ice_lib.h index 49454d98dcfe..e0d3ae067f35 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_lib.h @@ -18,6 +18,8 @@ enum ice_l2tsel { ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1, }; +u16 ice_lut_type_to_qs_num(enum ice_lut_type lut_type); + const char *ice_vsi_type_str(enum ice_vsi_type vsi_type); bool ice_pf_state_is_nominal(struct ice_pf *pf); diff --git a/drivers/net/ethernet/intel/ice/ice_switch.h b/drivers/net/ethernet/intel/ice/ice_switch.h index 671d7a5f359f..0d1ef9cd0535 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.h +++ b/drivers/net/ethernet/intel/ice/ice_switch.h @@ -361,7 +361,8 @@ int ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst); bool ice_vlan_fltr_exist(struct ice_hw *hw, u16 vlan_id, u16 vsi_handle); int ice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list); int ice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list); -int ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable); +int ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, + const struct ice_aqc_vsi_props *info, bool enable); void ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle); /* Promisc/defport setup for VSIs */ diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c index dffa213734f1..6d1e506b69cd 100644 --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c @@ -3645,11 +3645,13 @@ ice_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh) if (!rxfh->indir) return 0; - lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); - if (!lut) - return -ENOMEM; + scoped_guard(mutex, &pf->rss_lut_lock) { + lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); + if (!lut) + return -ENOMEM; - err = ice_get_rss(vsi, rxfh->key, lut, vsi->rss_table_size); + err = ice_get_rss(vsi, rxfh->key, lut, vsi->rss_table_size); + } if (err) goto out; @@ -3707,7 +3709,8 @@ ice_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh, if (rxfh->input_xfrm & RXH_XFRM_SYM_XOR) hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ; - err = ice_set_rss_hfunc(vsi, hfunc); + scoped_guard(mutex, &pf->rss_lut_lock) + err = ice_set_rss_hfunc(vsi, hfunc); if (err) return err; @@ -3727,29 +3730,31 @@ ice_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh, return err; } - if (!vsi->rss_lut_user) { - vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size, - GFP_KERNEL); - if (!vsi->rss_lut_user) - return -ENOMEM; - } + scoped_guard(mutex, &pf->rss_lut_lock) { + if (!vsi->rss_lut_user) { + vsi->rss_lut_user = devm_kzalloc(dev, + vsi->rss_table_size, + GFP_KERNEL); + if (!vsi->rss_lut_user) + return -ENOMEM; + } - /* Each 32 bits pointed by 'indir' is stored with a lut entry */ - if (rxfh->indir) { - int i; + /* Each 32 bits pointed by 'indir' is stored with a lut entry */ + if (rxfh->indir) { + int i; - for (i = 0; i < vsi->rss_table_size; i++) - vsi->rss_lut_user[i] = (u8)(rxfh->indir[i]); - } else { - ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size, - vsi->rss_size); - } + for (i = 0; i < vsi->rss_table_size; i++) + vsi->rss_lut_user[i] = (u8)(rxfh->indir[i]); + } else { + ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size, + vsi->rss_size); + } - err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size); - if (err) - return err; + err = ice_set_rss_lut(vsi, vsi->rss_lut_user, + vsi->rss_table_size); + } - return 0; + return err; } static int @@ -3825,14 +3830,15 @@ ice_get_channels(struct net_device *dev, struct ethtool_channels *ch) /** * ice_get_valid_rss_size - return valid number of RSS queues - * @hw: pointer to the HW structure + * @vsi: VSI to get the RSS LUT type of * @new_size: requested RSS queues */ -static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size) +static int ice_get_valid_rss_size(struct ice_vsi *vsi, int new_size) { - struct ice_hw_common_caps *caps = &hw->func_caps.common_cap; + struct ice_hw_common_caps *caps = &vsi->back->hw.func_caps.common_cap; - return min_t(int, new_size, BIT(caps->rss_table_entry_width)); + new_size = min_t(int, new_size, BIT(caps->rss_table_entry_width)); + return min_t(int, new_size, ice_lut_type_to_qs_num(vsi->rss_lut_type)); } /** @@ -3856,19 +3862,22 @@ static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size) if (!req_rss_size) return -EINVAL; - lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); - if (!lut) - return -ENOMEM; + scoped_guard(mutex, &pf->rss_lut_lock) { + lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); + if (!lut) + return -ENOMEM; - /* set RSS LUT parameters */ - if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) - vsi->rss_size = 1; - else - vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size); + /* set RSS LUT parameters */ + if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) + vsi->rss_size = 1; + else + vsi->rss_size = ice_get_valid_rss_size(vsi, + req_rss_size); - /* create/set RSS LUT */ - ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size); - err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + /* create/set RSS LUT */ + ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size); + err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + } if (err) dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err, libie_aq_str(hw->adminq.sq_last_status)); @@ -3959,7 +3968,8 @@ static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch) } /* Update rss_size due to change in Rx queues */ - vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx); + scoped_guard(mutex, &pf->rss_lut_lock) + vsi->rss_size = ice_get_valid_rss_size(vsi, new_rx); adev_unlock: if (locked) { diff --git a/drivers/net/ethernet/intel/ice/ice_idc.c b/drivers/net/ethernet/intel/ice/ice_idc.c index 102d63c3018b..3827d7b490aa 100644 --- a/drivers/net/ethernet/intel/ice/ice_idc.c +++ b/drivers/net/ethernet/intel/ice/ice_idc.c @@ -207,15 +207,21 @@ int ice_rdma_update_vsi_filter(struct iidc_rdma_core_dev_info *cdev, if (!vsi) return -EINVAL; - status = ice_cfg_rdma_fltr(&pf->hw, vsi->idx, enable); - if (status) { - dev_err(ice_pf_to_dev(pf), "Failed to %sable RDMA filtering\n", - enable ? "en" : "dis"); - } else { - if (enable) - vsi->info.q_opt_flags |= ICE_AQ_VSI_Q_OPT_PE_FLTR_EN; - else - vsi->info.q_opt_flags &= ~ICE_AQ_VSI_Q_OPT_PE_FLTR_EN; + scoped_guard(mutex, &pf->rss_lut_lock) { + status = ice_cfg_rdma_fltr(&pf->hw, vsi->idx, &vsi->info, + enable); + if (status) { + dev_err(ice_pf_to_dev(pf), + "Failed to %sable RDMA filtering\n", + enable ? "en" : "dis"); + } else { + if (enable) + vsi->info.q_opt_flags |= + ICE_AQ_VSI_Q_OPT_PE_FLTR_EN; + else + vsi->info.q_opt_flags &= + ~ICE_AQ_VSI_Q_OPT_PE_FLTR_EN; + } } return status; diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 977cd8dd6e31..bd59c0a12215 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -10,6 +10,23 @@ #include "ice_type.h" #include "ice_vsi_vlan_ops.h" +#define ICE_LUT_VSI_MAX_QS 16 +#define ICE_LUT_GLOBAL_MAX_QS 64 +#define ICE_LUT_PF_MAX_QS 256 + +u16 ice_lut_type_to_qs_num(enum ice_lut_type lut_type) +{ + switch (lut_type) { + case ICE_LUT_PF: + return ICE_LUT_PF_MAX_QS; + case ICE_LUT_GLOBAL: + return ICE_LUT_GLOBAL_MAX_QS; + case ICE_LUT_VSI: + default: + return ICE_LUT_VSI_MAX_QS; + } +} + /** * ice_vsi_type_str - maps VSI type enum to string equivalents * @vsi_type: VSI type enum @@ -982,6 +999,37 @@ static void ice_rss_clean(struct ice_vsi *vsi) ice_rem_vsi_rss_list(&pf->hw, vsi->idx); } +/** + * ice_vsi_set_dflt_rss_lut_type - Setup default RSS LUT per VSI type + * @vsi: the VSI being configured + */ +static void ice_vsi_set_dflt_rss_lut_type(struct ice_vsi *vsi) +{ + struct ice_hw_common_caps *cap = &vsi->back->hw.func_caps.common_cap; + + if (!test_bit(ICE_FLAG_RSS_ENA, vsi->back->flags)) + return; + + switch (vsi->type) { + case ICE_VSI_CHNL: + case ICE_VSI_PF: + /* PF VSI will inherit RSS instance of PF */ + vsi->rss_table_size = (u16)cap->rss_table_size; + vsi->rss_lut_type = ICE_LUT_PF; + break; + case ICE_VSI_SF: + case ICE_VSI_VF: + /* VF and SF VSIs will get a small RSS table. + * For VSI_LUT, LUT size should be set to 64 bytes. + */ + vsi->rss_table_size = ICE_LUT_VSI_SIZE; + vsi->rss_lut_type = ICE_LUT_VSI; + break; + default: + break; + } +} + /** * ice_vsi_set_rss_params - Setup RSS capabilities per VSI type * @vsi: the VSI being configured @@ -1002,29 +1050,19 @@ static void ice_vsi_set_rss_params(struct ice_vsi *vsi) switch (vsi->type) { case ICE_VSI_CHNL: case ICE_VSI_PF: - /* PF VSI will inherit RSS instance of PF */ - vsi->rss_table_size = (u16)cap->rss_table_size; if (vsi->type == ICE_VSI_CHNL) vsi->rss_size = min_t(u16, vsi->num_rxq, max_rss_size); else vsi->rss_size = min_t(u16, netif_get_num_default_rss_queues(), max_rss_size); - vsi->rss_lut_type = ICE_LUT_PF; break; case ICE_VSI_SF: - vsi->rss_table_size = ICE_LUT_VSI_SIZE; vsi->rss_size = min_t(u16, netif_get_num_default_rss_queues(), max_rss_size); - vsi->rss_lut_type = ICE_LUT_VSI; break; case ICE_VSI_VF: - /* VF VSI will get a small RSS table. - * For VSI_LUT, LUT size should be set to 64 bytes. - */ - vsi->rss_table_size = ICE_LUT_VSI_SIZE; vsi->rss_size = ICE_MAX_RSS_QS_PER_VF; - vsi->rss_lut_type = ICE_LUT_VSI; break; case ICE_VSI_LB: break; @@ -1558,19 +1596,22 @@ void ice_vsi_manage_rss_lut(struct ice_vsi *vsi, bool ena) { u8 *lut; - lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); - if (!lut) - return; + scoped_guard(mutex, &vsi->back->rss_lut_lock) { + lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); + if (!lut) + return; - if (ena) { - if (vsi->rss_lut_user) - memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); - else - ice_fill_rss_lut(lut, vsi->rss_table_size, - vsi->rss_size); - } + if (ena) { + if (vsi->rss_lut_user) + memcpy(lut, vsi->rss_lut_user, + vsi->rss_table_size); + else + ice_fill_rss_lut(lut, vsi->rss_table_size, + vsi->rss_size); + } - ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + } kfree(lut); } @@ -1622,16 +1663,21 @@ int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi) } } - lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); - if (!lut) - return -ENOMEM; + scoped_guard(mutex, &pf->rss_lut_lock) { + vsi->rss_size = min(vsi->rss_size, + ice_lut_type_to_qs_num(vsi->rss_lut_type)); + lut = kzalloc(vsi->rss_table_size, GFP_KERNEL); + if (!lut) + return -ENOMEM; - if (vsi->rss_lut_user) - memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); - else - ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size); + if (vsi->rss_lut_user) + memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size); + else + ice_fill_rss_lut(lut, vsi->rss_table_size, + vsi->rss_size); - err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size); + } if (err) { dev_err(dev, "set_rss_lut failed, error %d\n", err); goto ice_vsi_cfg_rss_exit; @@ -2404,6 +2450,11 @@ static int ice_vsi_cfg_def(struct ice_vsi *vsi) vsi->vsw = pf->first_sw; + if (vsi->flags & ICE_VSI_FLAG_INIT) { + scoped_guard(mutex, &pf->rss_lut_lock) + ice_vsi_set_dflt_rss_lut_type(vsi); + } + ret = ice_vsi_alloc_def(vsi, vsi->ch); if (ret) return ret; @@ -2429,7 +2480,8 @@ static int ice_vsi_cfg_def(struct ice_vsi *vsi) ice_vsi_set_tc_cfg(vsi); /* create the VSI */ - ret = ice_vsi_init(vsi, vsi->flags); + scoped_guard(mutex, &pf->rss_lut_lock) + ret = ice_vsi_init(vsi, vsi->flags); if (ret) goto unroll_get_qs; diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index c8f06c3d0fdf..0bc53f404957 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3873,6 +3873,7 @@ void ice_deinit_pf(struct ice_pf *pf) { /* note that we unroll also on ice_init_pf() failure here */ + mutex_destroy(&pf->rss_lut_lock); mutex_destroy(&pf->lag_mutex); mutex_destroy(&pf->adev_mutex); mutex_destroy(&pf->sw_mutex); @@ -3978,6 +3979,7 @@ int ice_init_pf(struct ice_pf *pf) mutex_init(&pf->tc_mutex); mutex_init(&pf->adev_mutex); mutex_init(&pf->lag_mutex); + mutex_init(&pf->rss_lut_lock); INIT_HLIST_HEAD(&pf->aq_wait_list); spin_lock_init(&pf->aq_wait_lock); diff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c index d873eda9af82..70eed3bcc404 100644 --- a/drivers/net/ethernet/intel/ice/ice_switch.c +++ b/drivers/net/ethernet/intel/ice/ice_switch.c @@ -1834,10 +1834,12 @@ ice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, * ice_cfg_rdma_fltr - enable/disable RDMA filtering on VSI * @hw: pointer to HW struct * @vsi_handle: VSI SW index + * @info: current VSI properties, the rest of the Q_OPT section is kept * @enable: boolean for enable/disable */ int -ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable) +ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, + const struct ice_aqc_vsi_props *info, bool enable) { struct ice_vsi_ctx *ctx, *cached_ctx; int status; @@ -1850,9 +1852,10 @@ ice_cfg_rdma_fltr(struct ice_hw *hw, u16 vsi_handle, bool enable) if (!ctx) return -ENOMEM; - ctx->info.q_opt_rss = cached_ctx->info.q_opt_rss; - ctx->info.q_opt_tc = cached_ctx->info.q_opt_tc; - ctx->info.q_opt_flags = cached_ctx->info.q_opt_flags; + /* not from the cached ctx, that misses later RSS changes */ + ctx->info.q_opt_rss = info->q_opt_rss; + ctx->info.q_opt_tc = info->q_opt_tc; + ctx->info.q_opt_flags = info->q_opt_flags; ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID); -- 2.51.1