Skip to content

Commit

Permalink
ice: allow toggling loopback mode via ndo_set_features callback
Browse files Browse the repository at this point in the history
Add support for NETIF_F_LOOPBACK. This feature can be set via:
$ ethtool -K eth0 loopback <on|off>

Feature can be useful for local data path tests.

Acked-by: Jakub Kicinski <[email protected]>
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]>
  • Loading branch information
mfijalko authored and anguy11 committed Jul 28, 2022
1 parent c67672f commit 44ece4e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion drivers/net/ethernet/intel/ice/ice_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3358,6 +3358,7 @@ static void ice_set_netdev_features(struct net_device *netdev)
netdev->features |= netdev->hw_features;

netdev->hw_features |= NETIF_F_HW_TC;
netdev->hw_features |= NETIF_F_LOOPBACK;

/* encap and VLAN devices inherit default, csumo and tso features */
netdev->hw_enc_features |= dflt_features | csumo_features |
Expand Down Expand Up @@ -5910,6 +5911,32 @@ ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
return 0;
}

/**
* ice_set_loopback - turn on/off loopback mode on underlying PF
* @vsi: ptr to VSI
* @ena: flag to indicate the on/off setting
*/
static int ice_set_loopback(struct ice_vsi *vsi, bool ena)
{
bool if_running = netif_running(vsi->netdev);
int ret;

if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
ret = ice_down(vsi);
if (ret) {
netdev_err(vsi->netdev, "Preparing device to toggle loopback failed\n");
return ret;
}
}
ret = ice_aq_set_mac_loopback(&vsi->back->hw, ena, NULL);
if (ret)
netdev_err(vsi->netdev, "Failed to toggle loopback state\n");
if (if_running)
ret = ice_up(vsi);

return ret;
}

/**
* ice_set_features - set the netdev feature flags
* @netdev: ptr to the netdev being adjusted
Expand Down Expand Up @@ -5968,7 +5995,10 @@ ice_set_features(struct net_device *netdev, netdev_features_t features)
clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
}

return 0;
if (changed & NETIF_F_LOOPBACK)
ret = ice_set_loopback(vsi, !!(features & NETIF_F_LOOPBACK));

return ret;
}

/**
Expand Down

0 comments on commit 44ece4e

Please sign in to comment.