Comparing two ice_dcbx_cfg structs with memcmp() is unreliable on non-packed structs due to uninitialised padding bytes. The HW DCB path already has ice_dcb_need_recfg() that compares fields individually; export it and use it in the SW DCB netlink setters (setets, setpfc, setapp, cee_set_all) instead of the unsafe memcmp.
Remove the now-redundant memcmp check from ice_pf_dcb_cfg() so that function always attempts the HW reconfiguration when called. Signed-off-by: Aleksandr Loktionov <[email protected]> --- drivers/net/ethernet/intel/ice/ice_dcb_lib.c | 13 ++------- drivers/net/ethernet/intel/ice/ice_dcb_lib.h | 2 ++ drivers/net/ethernet/intel/ice/ice_dcb_nl.c | 30 ++++++++++++++++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c index bd77f1c..2e85fae 100644 --- a/drivers/net/ethernet/intel/ice/ice_dcb_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_dcb_lib.c @@ -353,15 +353,11 @@ int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked) struct ice_dcbx_cfg *old_cfg, *curr_cfg; struct device *dev = ice_pf_to_dev(pf); struct iidc_rdma_event *event; - int ret = ICE_DCB_NO_HW_CHG; struct ice_vsi *pf_vsi; + int ret; curr_cfg = &pf->hw.port_info->qos_cfg.local_dcbx_cfg; - /* FW does not care if change happened */ - if (!pf->hw.port_info->qos_cfg.is_sw_lldp) - ret = ICE_DCB_HW_CHG_RST; - /* Enable DCB tagging only when more than one TC */ if (ice_dcb_get_num_tc(new_cfg) > 1) { dev_dbg(dev, "DCB tagging enabled (num TC > 1)\n"); @@ -377,11 +373,6 @@ int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked) clear_bit(ICE_FLAG_DCB_ENA, pf->flags); } - if (!memcmp(new_cfg, curr_cfg, sizeof(*new_cfg))) { - dev_dbg(dev, "No change in DCB config required\n"); - return ret; - } - if (ice_dcb_bwchk(pf, new_cfg)) return -EINVAL; @@ -481,7 +472,7 @@ static void ice_cfg_etsrec_defaults(struct ice_port_info *pi) * @old_cfg: current DCB config * @new_cfg: new DCB config */ -static bool +bool ice_dcb_need_recfg(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg, struct ice_dcbx_cfg *new_cfg) { diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_lib.h b/drivers/net/ethernet/intel/ice/ice_dcb_lib.h index da9ba81..a7eaa2f9 100644 --- a/drivers/net/ethernet/intel/ice/ice_dcb_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_dcb_lib.h @@ -20,6 +20,8 @@ u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg); void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi); bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue); u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index); +bool ice_dcb_need_recfg(struct ice_pf *pf, struct ice_dcbx_cfg *old_cfg, + struct ice_dcbx_cfg *new_cfg); int ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked); int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg); diff --git a/drivers/net/ethernet/intel/ice/ice_dcb_nl.c b/drivers/net/ethernet/intel/ice/ice_dcb_nl.c index a10c1c8d..13a52c1 100644 --- a/drivers/net/ethernet/intel/ice/ice_dcb_nl.c +++ b/drivers/net/ethernet/intel/ice/ice_dcb_nl.c @@ -108,11 +108,17 @@ static int ice_dcbnl_setets(struct net_device *netdev, struct ieee_ets *ets) if (!bwrec) new_cfg->etsrec.tcbwtable[0] = 100; + if (!ice_dcb_need_recfg(pf, &pf->hw.port_info->qos_cfg.local_dcbx_cfg, + new_cfg)) { + err = ICE_DCB_NO_HW_CHG; + goto ets_out; + } + err = ice_pf_dcb_cfg(pf, new_cfg, true); /* return of zero indicates new cfg applied */ - if (err == ICE_DCB_HW_CHG_RST) + if (!err) ice_dcbnl_devreset(netdev); - if (err == ICE_DCB_NO_HW_CHG) + else if (err == ICE_DCB_NO_HW_CHG) err = ICE_DCB_HW_CHG_RST; ets_out: @@ -287,11 +293,18 @@ static int ice_dcbnl_setpfc(struct net_device *netdev, struct ieee_pfc *pfc) new_cfg->pfc.pfcena = pfc->pfc_en; + if (!ice_dcb_need_recfg(pf, &pf->hw.port_info->qos_cfg.local_dcbx_cfg, + new_cfg)) { + err = ICE_DCB_NO_HW_CHG; + goto pfc_out; + } + err = ice_pf_dcb_cfg(pf, new_cfg, true); if (err == ICE_DCB_HW_CHG_RST) ice_dcbnl_devreset(netdev); if (err == ICE_DCB_NO_HW_CHG) err = ICE_DCB_HW_CHG_RST; +pfc_out: mutex_unlock(&pf->tc_mutex); return err; } @@ -845,6 +858,12 @@ static int ice_dcbnl_setapp(struct net_device *netdev, struct dcb_app *app) new_cfg->dscp_map[app->protocol] = app->priority; new_cfg->app[new_cfg->numapps++] = new_app; + if (!ice_dcb_need_recfg(pf, &pf->hw.port_info->qos_cfg.local_dcbx_cfg, + new_cfg)) { + ret = ICE_DCB_NO_HW_CHG; + goto setapp_out; + } + ret = ice_pf_dcb_cfg(pf, new_cfg, true); /* return of zero indicates new cfg applied */ if (ret == ICE_DCB_HW_CHG_RST) @@ -991,8 +1010,15 @@ static u8 ice_dcbnl_cee_set_all(struct net_device *netdev) mutex_lock(&pf->tc_mutex); + if (!ice_dcb_need_recfg(pf, &pf->hw.port_info->qos_cfg.local_dcbx_cfg, + new_cfg)) { + err = ICE_DCB_NO_HW_CHG; + goto out; + } + err = ice_pf_dcb_cfg(pf, new_cfg, true); +out: mutex_unlock(&pf->tc_mutex); return (err != ICE_DCB_HW_CHG_RST) ? ICE_DCB_NO_HW_CHG : err; } -- 2.52.0
