Skip to content

Commit c67672f

Browse files
mfijalkoanguy11
authored andcommitted
ice: compress branches in ice_set_features()
Instead of rather verbose comparison of current netdev->features bits vs the incoming ones from user, let us compress them by a helper features set that will be the result of netdev->features XOR features. This way, current, extensive branches: if (features & NETIF_F_BIT && !(netdev->features & NETIF_F_BIT)) set_feature(true); else if (!(features & NETIF_F_BIT) && netdev->features & NETIF_F_BIT) set_feature(false); can become: netdev_features_t changed = netdev->features ^ features; if (changed & NETIF_F_BIT) set_feature(!!(features & NETIF_F_BIT)); This is nothing new as currently several other drivers use this approach, which I find much more convenient. Acked-by: John Fastabend <[email protected]> Signed-off-by: Maciej Fijalkowski <[email protected]> Tested-by: George Kuruvinakunnel <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent a419526 commit c67672f

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5918,44 +5918,41 @@ ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
59185918
static int
59195919
ice_set_features(struct net_device *netdev, netdev_features_t features)
59205920
{
5921+
netdev_features_t changed = netdev->features ^ features;
59215922
struct ice_netdev_priv *np = netdev_priv(netdev);
59225923
struct ice_vsi *vsi = np->vsi;
59235924
struct ice_pf *pf = vsi->back;
59245925
int ret = 0;
59255926

59265927
/* Don't set any netdev advanced features with device in Safe Mode */
5927-
if (ice_is_safe_mode(vsi->back)) {
5928-
dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
5928+
if (ice_is_safe_mode(pf)) {
5929+
dev_err(ice_pf_to_dev(pf),
5930+
"Device is in Safe Mode - not enabling advanced netdev features\n");
59295931
return ret;
59305932
}
59315933

59325934
/* Do not change setting during reset */
59335935
if (ice_is_reset_in_progress(pf->state)) {
5934-
dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
5936+
dev_err(ice_pf_to_dev(pf),
5937+
"Device is resetting, changing advanced netdev features temporarily unavailable.\n");
59355938
return -EBUSY;
59365939
}
59375940

59385941
/* Multiple features can be changed in one call so keep features in
59395942
* separate if/else statements to guarantee each feature is checked
59405943
*/
5941-
if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
5942-
ice_vsi_manage_rss_lut(vsi, true);
5943-
else if (!(features & NETIF_F_RXHASH) &&
5944-
netdev->features & NETIF_F_RXHASH)
5945-
ice_vsi_manage_rss_lut(vsi, false);
5944+
if (changed & NETIF_F_RXHASH)
5945+
ice_vsi_manage_rss_lut(vsi, !!(features & NETIF_F_RXHASH));
59465946

59475947
ret = ice_set_vlan_features(netdev, features);
59485948
if (ret)
59495949
return ret;
59505950

5951-
if ((features & NETIF_F_NTUPLE) &&
5952-
!(netdev->features & NETIF_F_NTUPLE)) {
5953-
ice_vsi_manage_fdir(vsi, true);
5954-
ice_init_arfs(vsi);
5955-
} else if (!(features & NETIF_F_NTUPLE) &&
5956-
(netdev->features & NETIF_F_NTUPLE)) {
5957-
ice_vsi_manage_fdir(vsi, false);
5958-
ice_clear_arfs(vsi);
5951+
if (changed & NETIF_F_NTUPLE) {
5952+
bool ena = !!(features & NETIF_F_NTUPLE);
5953+
5954+
ice_vsi_manage_fdir(vsi, ena);
5955+
ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi);
59595956
}
59605957

59615958
/* don't turn off hw_tc_offload when ADQ is already enabled */
@@ -5964,11 +5961,12 @@ ice_set_features(struct net_device *netdev, netdev_features_t features)
59645961
return -EACCES;
59655962
}
59665963

5967-
if ((features & NETIF_F_HW_TC) &&
5968-
!(netdev->features & NETIF_F_HW_TC))
5969-
set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5970-
else
5971-
clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5964+
if (changed & NETIF_F_HW_TC) {
5965+
bool ena = !!(features & NETIF_F_HW_TC);
5966+
5967+
ena ? set_bit(ICE_FLAG_CLS_FLOWER, pf->flags) :
5968+
clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5969+
}
59725970

59735971
return 0;
59745972
}

0 commit comments

Comments
 (0)