Skip to content

Commit c5e6bd9

Browse files
Marcin Szycikanguy11
authored andcommitted
ice: Deduplicate tc action setup
ice_tc_setup_redirect_action() and ice_tc_setup_mirror_action() are almost identical, except for setting filter action. Reduce them to one function with an extra param, which handles both cases. Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com> Signed-off-by: Marcin Szycik <marcin.szycik@linux.intel.com> Reviewed-by: Simon Horman <horms@kernel.org> Tested-by: Sujai Buvaneswaran <sujai.buvaneswaran@intel.com> Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
1 parent a8e682f commit c5e6bd9

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

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

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,19 @@ static bool ice_tc_is_dev_uplink(struct net_device *dev)
669669
return netif_is_ice(dev) || ice_is_tunnel_supported(dev);
670670
}
671671

672-
static int ice_tc_setup_redirect_action(struct net_device *filter_dev,
673-
struct ice_tc_flower_fltr *fltr,
674-
struct net_device *target_dev)
672+
static int ice_tc_setup_action(struct net_device *filter_dev,
673+
struct ice_tc_flower_fltr *fltr,
674+
struct net_device *target_dev,
675+
enum ice_sw_fwd_act_type action)
675676
{
676677
struct ice_repr *repr;
677678

678-
fltr->action.fltr_act = ICE_FWD_TO_VSI;
679+
if (action != ICE_FWD_TO_VSI && action != ICE_MIRROR_PACKET) {
680+
NL_SET_ERR_MSG_MOD(fltr->extack, "Unsupported action to setup provided");
681+
return -EINVAL;
682+
}
683+
684+
fltr->action.fltr_act = action;
679685

680686
if (ice_is_port_repr_netdev(filter_dev) &&
681687
ice_is_port_repr_netdev(target_dev)) {
@@ -723,41 +729,6 @@ ice_tc_setup_drop_action(struct net_device *filter_dev,
723729
return 0;
724730
}
725731

726-
static int ice_tc_setup_mirror_action(struct net_device *filter_dev,
727-
struct ice_tc_flower_fltr *fltr,
728-
struct net_device *target_dev)
729-
{
730-
struct ice_repr *repr;
731-
732-
fltr->action.fltr_act = ICE_MIRROR_PACKET;
733-
734-
if (ice_is_port_repr_netdev(filter_dev) &&
735-
ice_is_port_repr_netdev(target_dev)) {
736-
repr = ice_netdev_to_repr(target_dev);
737-
738-
fltr->dest_vsi = repr->src_vsi;
739-
fltr->direction = ICE_ESWITCH_FLTR_EGRESS;
740-
} else if (ice_is_port_repr_netdev(filter_dev) &&
741-
ice_tc_is_dev_uplink(target_dev)) {
742-
repr = ice_netdev_to_repr(filter_dev);
743-
744-
fltr->dest_vsi = repr->src_vsi->back->eswitch.uplink_vsi;
745-
fltr->direction = ICE_ESWITCH_FLTR_EGRESS;
746-
} else if (ice_tc_is_dev_uplink(filter_dev) &&
747-
ice_is_port_repr_netdev(target_dev)) {
748-
repr = ice_netdev_to_repr(target_dev);
749-
750-
fltr->dest_vsi = repr->src_vsi;
751-
fltr->direction = ICE_ESWITCH_FLTR_INGRESS;
752-
} else {
753-
NL_SET_ERR_MSG_MOD(fltr->extack,
754-
"Unsupported netdevice in switchdev mode");
755-
return -EINVAL;
756-
}
757-
758-
return 0;
759-
}
760-
761732
static int ice_eswitch_tc_parse_action(struct net_device *filter_dev,
762733
struct ice_tc_flower_fltr *fltr,
763734
struct flow_action_entry *act)
@@ -773,16 +744,19 @@ static int ice_eswitch_tc_parse_action(struct net_device *filter_dev,
773744
break;
774745

775746
case FLOW_ACTION_REDIRECT:
776-
err = ice_tc_setup_redirect_action(filter_dev, fltr, act->dev);
747+
err = ice_tc_setup_action(filter_dev, fltr,
748+
act->dev, ICE_FWD_TO_VSI);
777749
if (err)
778750
return err;
779751

780752
break;
781753

782754
case FLOW_ACTION_MIRRED:
783-
err = ice_tc_setup_mirror_action(filter_dev, fltr, act->dev);
755+
err = ice_tc_setup_action(filter_dev, fltr,
756+
act->dev, ICE_MIRROR_PACKET);
784757
if (err)
785758
return err;
759+
786760
break;
787761

788762
default:

0 commit comments

Comments
 (0)