Skip to content

Commit

Permalink
ice: Add support for VLAN priority filters in switchdev
Browse files Browse the repository at this point in the history
Enable support for adding TC rules that filter on the VLAN priority
in switchdev mode.

VLAN priority are the first 3 bits of 16b switch field vector word
which contain also vlan id value within its last 12 bits.
When getting vlan priority value from tc match.key it
has to be shifted first to proper bits positions (by VLAN_PRIO_SHIFT)
and then can be added to the joint 'vlan' field in ice_vlan_hdr
in lookup element.

The mask of lookup changes accordingly.
0x0FFF - when only vlan id is added in filter
0xE000 - when only vlan priority is added in filter
0xEFFF - when both these values are specified

Signed-off-by: Martyna Szapar-Mudlaw <martyna.szapar-mudlaw@linux.intel.com>
Tested-by: Sujai Buvaneswaran <sujai.buvaneswaran@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
  • Loading branch information
Martyna Szapar-Mudlaw authored and anguy11 committed Sep 28, 2022
1 parent 793189a commit 3480017
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 17 deletions.
73 changes: 57 additions & 16 deletions drivers/net/ethernet/intel/ice/ice_tc_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
lkups_cnt++;

/* is VLAN specified? */
if (flags & ICE_TC_FLWR_FIELD_VLAN)
if (flags & (ICE_TC_FLWR_FIELD_VLAN | ICE_TC_FLWR_FIELD_VLAN_PRIO))
lkups_cnt++;

/* is CVLAN specified? */
if (flags & ICE_TC_FLWR_FIELD_CVLAN)
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO))
lkups_cnt++;

/* are PPPoE options specified? */
Expand Down Expand Up @@ -389,7 +389,7 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
}

/* copy VLAN info */
if (flags & ICE_TC_FLWR_FIELD_VLAN) {
if (flags & (ICE_TC_FLWR_FIELD_VLAN | ICE_TC_FLWR_FIELD_VLAN_PRIO)) {
vlan_tpid = be16_to_cpu(headers->vlan_hdr.vlan_tpid);
rule_info->vlan_type =
ice_check_supported_vlan_tpid(vlan_tpid);
Expand All @@ -398,15 +398,45 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
list[i].type = ICE_VLAN_EX;
else
list[i].type = ICE_VLAN_OFOS;
list[i].h_u.vlan_hdr.vlan = headers->vlan_hdr.vlan_id;
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xFFFF);

if (flags & ICE_TC_FLWR_FIELD_VLAN) {
list[i].h_u.vlan_hdr.vlan = headers->vlan_hdr.vlan_id;
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0x0FFF);
}

if (flags & ICE_TC_FLWR_FIELD_VLAN_PRIO) {
if (flags & ICE_TC_FLWR_FIELD_VLAN) {
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xEFFF);
} else {
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xE000);
list[i].h_u.vlan_hdr.vlan = 0;
}
list[i].h_u.vlan_hdr.vlan |=
headers->vlan_hdr.vlan_prio;
}

i++;
}

if (flags & ICE_TC_FLWR_FIELD_CVLAN) {
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO)) {
list[i].type = ICE_VLAN_IN;
list[i].h_u.vlan_hdr.vlan = headers->cvlan_hdr.vlan_id;
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xFFFF);

if (flags & ICE_TC_FLWR_FIELD_CVLAN) {
list[i].h_u.vlan_hdr.vlan = headers->cvlan_hdr.vlan_id;
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0x0FFF);
}

if (flags & ICE_TC_FLWR_FIELD_CVLAN_PRIO) {
if (flags & ICE_TC_FLWR_FIELD_CVLAN) {
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xEFFF);
} else {
list[i].m_u.vlan_hdr.vlan = cpu_to_be16(0xE000);
list[i].h_u.vlan_hdr.vlan = 0;
}
list[i].h_u.vlan_hdr.vlan |=
headers->cvlan_hdr.vlan_prio;
}

i++;
}

Expand Down Expand Up @@ -1280,16 +1310,22 @@ ice_parse_cls_flower(struct net_device *filter_dev, struct ice_vsi *vsi,
if (match.mask->vlan_id) {
if (match.mask->vlan_id == VLAN_VID_MASK) {
fltr->flags |= ICE_TC_FLWR_FIELD_VLAN;
headers->vlan_hdr.vlan_id =
cpu_to_be16(match.key->vlan_id &
VLAN_VID_MASK);
} else {
NL_SET_ERR_MSG_MOD(fltr->extack, "Bad VLAN mask");
return -EINVAL;
}
}

headers->vlan_hdr.vlan_id =
cpu_to_be16(match.key->vlan_id & VLAN_VID_MASK);
if (match.mask->vlan_priority)
headers->vlan_hdr.vlan_prio = match.key->vlan_priority;
if (match.mask->vlan_priority) {
fltr->flags |= ICE_TC_FLWR_FIELD_VLAN_PRIO;
headers->vlan_hdr.vlan_prio =
cpu_to_be16((match.key->vlan_priority <<
VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK);
}

if (match.mask->vlan_tpid)
headers->vlan_hdr.vlan_tpid = match.key->vlan_tpid;
}
Expand All @@ -1307,17 +1343,22 @@ ice_parse_cls_flower(struct net_device *filter_dev, struct ice_vsi *vsi,
if (match.mask->vlan_id) {
if (match.mask->vlan_id == VLAN_VID_MASK) {
fltr->flags |= ICE_TC_FLWR_FIELD_CVLAN;
headers->cvlan_hdr.vlan_id =
cpu_to_be16(match.key->vlan_id &
VLAN_VID_MASK);
} else {
NL_SET_ERR_MSG_MOD(fltr->extack,
"Bad CVLAN mask");
return -EINVAL;
}
}

headers->cvlan_hdr.vlan_id =
cpu_to_be16(match.key->vlan_id & VLAN_VID_MASK);
if (match.mask->vlan_priority)
headers->cvlan_hdr.vlan_prio = match.key->vlan_priority;
if (match.mask->vlan_priority) {
fltr->flags |= ICE_TC_FLWR_FIELD_CVLAN_PRIO;
headers->cvlan_hdr.vlan_prio =
cpu_to_be16((match.key->vlan_priority <<
VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK);
}
}

if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_PPPOE)) {
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/ethernet/intel/ice/ice_tc_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#define ICE_TC_FLWR_FIELD_ENC_IP_TOS BIT(24)
#define ICE_TC_FLWR_FIELD_ENC_IP_TTL BIT(25)
#define ICE_TC_FLWR_FIELD_L2TPV3_SESSID BIT(26)
#define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27)
#define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28)

#define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF

Expand All @@ -49,7 +51,7 @@ struct ice_tc_flower_action {

struct ice_tc_vlan_hdr {
__be16 vlan_id; /* Only last 12 bits valid */
u16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
__be16 vlan_prio; /* Only last 3 bits valid (valid values: 0..7) */
__be16 vlan_tpid;
};

Expand Down

0 comments on commit 3480017

Please sign in to comment.