Commit aa4967d8 authored by Andrii Staikov's avatar Andrii Staikov Committed by Tony Nguyen

ice: Add support for packet mirroring using hardware in switchdev mode

Switchdev mode allows to add mirroring rules to mirror incoming and
outgoing packets to the interface's port representor. Previously, this was
available only using software functionality. Add possibility to offload
this functionality to the NIC hardware.

Introduce ICE_MIRROR_PACKET filter action to the ice_sw_fwd_act_type enum
to identify the desired action and pass it to the hardware as well as the
VSI to mirror.

Example of tc mirror command using hardware:
  tc filter add dev ens1f0np0 ingress protocol ip prio 1 flower src_mac
  b4:96:91:a5:c7:a7 skip_sw action mirred egress mirror dev eth1

ens1f0np0 - PF
b4:96:91:a5:c7:a7 - source MAC address
eth1 - PR of a VF to mirror to
Co-developed-by: default avatarMarcin Szycik <marcin.szycik@intel.com>
Signed-off-by: default avatarMarcin Szycik <marcin.szycik@intel.com>
Reviewed-by: default avatarWojciech Drewek <wojciech.drewek@intel.com>
Signed-off-by: default avatarAndrii Staikov <andrii.staikov@intel.com>
Tested-by: default avatarSujai Buvaneswaran <sujai.buvaneswaran@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 82e71b22
...@@ -6059,6 +6059,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, ...@@ -6059,6 +6059,7 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
rinfo->sw_act.fltr_act == ICE_FWD_TO_Q || rinfo->sw_act.fltr_act == ICE_FWD_TO_Q ||
rinfo->sw_act.fltr_act == ICE_FWD_TO_QGRP || rinfo->sw_act.fltr_act == ICE_FWD_TO_QGRP ||
rinfo->sw_act.fltr_act == ICE_DROP_PACKET || rinfo->sw_act.fltr_act == ICE_DROP_PACKET ||
rinfo->sw_act.fltr_act == ICE_MIRROR_PACKET ||
rinfo->sw_act.fltr_act == ICE_NOP)) { rinfo->sw_act.fltr_act == ICE_NOP)) {
status = -EIO; status = -EIO;
goto free_pkt_profile; goto free_pkt_profile;
...@@ -6071,9 +6072,11 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, ...@@ -6071,9 +6072,11 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
} }
if (rinfo->sw_act.fltr_act == ICE_FWD_TO_VSI || if (rinfo->sw_act.fltr_act == ICE_FWD_TO_VSI ||
rinfo->sw_act.fltr_act == ICE_NOP) rinfo->sw_act.fltr_act == ICE_MIRROR_PACKET ||
rinfo->sw_act.fltr_act == ICE_NOP) {
rinfo->sw_act.fwd_id.hw_vsi_id = rinfo->sw_act.fwd_id.hw_vsi_id =
ice_get_hw_vsi_num(hw, vsi_handle); ice_get_hw_vsi_num(hw, vsi_handle);
}
if (rinfo->src_vsi) if (rinfo->src_vsi)
rinfo->sw_act.src = ice_get_hw_vsi_num(hw, rinfo->src_vsi); rinfo->sw_act.src = ice_get_hw_vsi_num(hw, rinfo->src_vsi);
...@@ -6109,12 +6112,15 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, ...@@ -6109,12 +6112,15 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
status = -ENOMEM; status = -ENOMEM;
goto free_pkt_profile; goto free_pkt_profile;
} }
if (!rinfo->flags_info.act_valid) {
act |= ICE_SINGLE_ACT_LAN_ENABLE; if (rinfo->sw_act.fltr_act != ICE_MIRROR_PACKET) {
act |= ICE_SINGLE_ACT_LB_ENABLE; if (!rinfo->flags_info.act_valid) {
} else { act |= ICE_SINGLE_ACT_LAN_ENABLE;
act |= rinfo->flags_info.act & (ICE_SINGLE_ACT_LAN_ENABLE | act |= ICE_SINGLE_ACT_LB_ENABLE;
ICE_SINGLE_ACT_LB_ENABLE); } else {
act |= rinfo->flags_info.act & (ICE_SINGLE_ACT_LAN_ENABLE |
ICE_SINGLE_ACT_LB_ENABLE);
}
} }
switch (rinfo->sw_act.fltr_act) { switch (rinfo->sw_act.fltr_act) {
...@@ -6140,6 +6146,11 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, ...@@ -6140,6 +6146,11 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP | act |= ICE_SINGLE_ACT_VSI_FORWARDING | ICE_SINGLE_ACT_DROP |
ICE_SINGLE_ACT_VALID_BIT; ICE_SINGLE_ACT_VALID_BIT;
break; break;
case ICE_MIRROR_PACKET:
act |= ICE_SINGLE_ACT_OTHER_ACTS;
act |= FIELD_PREP(ICE_SINGLE_ACT_VSI_ID_M,
rinfo->sw_act.fwd_id.hw_vsi_id);
break;
case ICE_NOP: case ICE_NOP:
act |= FIELD_PREP(ICE_SINGLE_ACT_VSI_ID_M, act |= FIELD_PREP(ICE_SINGLE_ACT_VSI_ID_M,
rinfo->sw_act.fwd_id.hw_vsi_id); rinfo->sw_act.fwd_id.hw_vsi_id);
......
...@@ -689,6 +689,41 @@ ice_tc_setup_drop_action(struct net_device *filter_dev, ...@@ -689,6 +689,41 @@ ice_tc_setup_drop_action(struct net_device *filter_dev,
return 0; return 0;
} }
static int ice_tc_setup_mirror_action(struct net_device *filter_dev,
struct ice_tc_flower_fltr *fltr,
struct net_device *target_dev)
{
struct ice_repr *repr;
fltr->action.fltr_act = ICE_MIRROR_PACKET;
if (ice_is_port_repr_netdev(filter_dev) &&
ice_is_port_repr_netdev(target_dev)) {
repr = ice_netdev_to_repr(target_dev);
fltr->dest_vsi = repr->src_vsi;
fltr->direction = ICE_ESWITCH_FLTR_EGRESS;
} else if (ice_is_port_repr_netdev(filter_dev) &&
ice_tc_is_dev_uplink(target_dev)) {
repr = ice_netdev_to_repr(filter_dev);
fltr->dest_vsi = repr->src_vsi->back->eswitch.uplink_vsi;
fltr->direction = ICE_ESWITCH_FLTR_EGRESS;
} else if (ice_tc_is_dev_uplink(filter_dev) &&
ice_is_port_repr_netdev(target_dev)) {
repr = ice_netdev_to_repr(target_dev);
fltr->dest_vsi = repr->src_vsi;
fltr->direction = ICE_ESWITCH_FLTR_INGRESS;
} else {
NL_SET_ERR_MSG_MOD(fltr->extack,
"Unsupported netdevice in switchdev mode");
return -EINVAL;
}
return 0;
}
static int ice_eswitch_tc_parse_action(struct net_device *filter_dev, static int ice_eswitch_tc_parse_action(struct net_device *filter_dev,
struct ice_tc_flower_fltr *fltr, struct ice_tc_flower_fltr *fltr,
struct flow_action_entry *act) struct flow_action_entry *act)
...@@ -710,6 +745,12 @@ static int ice_eswitch_tc_parse_action(struct net_device *filter_dev, ...@@ -710,6 +745,12 @@ static int ice_eswitch_tc_parse_action(struct net_device *filter_dev,
break; break;
case FLOW_ACTION_MIRRED:
err = ice_tc_setup_mirror_action(filter_dev, fltr, act->dev);
if (err)
return err;
break;
default: default:
NL_SET_ERR_MSG_MOD(fltr->extack, "Unsupported action in switchdev mode"); NL_SET_ERR_MSG_MOD(fltr->extack, "Unsupported action in switchdev mode");
return -EINVAL; return -EINVAL;
......
...@@ -1042,6 +1042,7 @@ enum ice_sw_fwd_act_type { ...@@ -1042,6 +1042,7 @@ enum ice_sw_fwd_act_type {
ICE_FWD_TO_Q, ICE_FWD_TO_Q,
ICE_FWD_TO_QGRP, ICE_FWD_TO_QGRP,
ICE_DROP_PACKET, ICE_DROP_PACKET,
ICE_MIRROR_PACKET,
ICE_NOP, ICE_NOP,
ICE_INVAL_ACT ICE_INVAL_ACT
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment