Skip to content

Commit 03592a1

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: allow matching on meta data
Add meta data matching criteria in the same place as protocol matching criteria. There is no need to add meta data as special words after parsing all lookups. Trade meta data in the same why as other lookups. The one difference between meta data lookups and protocol lookups is that meta data doesn't impact how the packets looks like. Because of that ignore it when filling testing packet. Match on tunnel type meta data always if tunnel type is different than TNL_LAST. Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Piotr Raczynski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 17c6d83 commit 03592a1

File tree

5 files changed

+95
-105
lines changed

5 files changed

+95
-105
lines changed

drivers/net/ethernet/intel/ice/ice_protocol_type.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum ice_protocol_type {
4747
ICE_L2TPV3,
4848
ICE_VLAN_EX,
4949
ICE_VLAN_IN,
50+
ICE_HW_METADATA,
5051
ICE_VXLAN_GPE,
5152
ICE_SCTP_IL,
5253
ICE_PROTOCOL_LAST
@@ -387,6 +388,13 @@ enum ice_hw_metadata_offset {
387388
ICE_PKT_ERROR_MDID_OFFSET = ICE_MDID_SIZE * ICE_PKT_ERROR_MDID,
388389
};
389390

391+
enum ice_pkt_flags {
392+
ICE_PKT_FLAGS_VLAN = 0,
393+
ICE_PKT_FLAGS_TUNNEL = 1,
394+
ICE_PKT_FLAGS_TCP = 2,
395+
ICE_PKT_FLAGS_ERROR = 3,
396+
};
397+
390398
struct ice_hw_metadata {
391399
__be16 source_port;
392400
__be16 ptype;

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

Lines changed: 58 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -4578,6 +4578,15 @@ static const struct ice_prot_ext_tbl_entry ice_prot_ext[ICE_PROTOCOL_LAST] = {
45784578
ICE_PROTOCOL_ENTRY(ICE_L2TPV3, 0, 2, 4, 6, 8, 10),
45794579
ICE_PROTOCOL_ENTRY(ICE_VLAN_EX, 2, 0),
45804580
ICE_PROTOCOL_ENTRY(ICE_VLAN_IN, 2, 0),
4581+
ICE_PROTOCOL_ENTRY(ICE_HW_METADATA,
4582+
ICE_SOURCE_PORT_MDID_OFFSET,
4583+
ICE_PTYPE_MDID_OFFSET,
4584+
ICE_PACKET_LENGTH_MDID_OFFSET,
4585+
ICE_SOURCE_VSI_MDID_OFFSET,
4586+
ICE_PKT_VLAN_MDID_OFFSET,
4587+
ICE_PKT_TUNNEL_MDID_OFFSET,
4588+
ICE_PKT_TCP_MDID_OFFSET,
4589+
ICE_PKT_ERROR_MDID_OFFSET),
45814590
};
45824591

45834592
static struct ice_protocol_entry ice_prot_id_tbl[ICE_PROTOCOL_LAST] = {
@@ -4602,6 +4611,7 @@ static struct ice_protocol_entry ice_prot_id_tbl[ICE_PROTOCOL_LAST] = {
46024611
{ ICE_L2TPV3, ICE_L2TPV3_HW },
46034612
{ ICE_VLAN_EX, ICE_VLAN_OF_HW },
46044613
{ ICE_VLAN_IN, ICE_VLAN_OL_HW },
4614+
{ ICE_HW_METADATA, ICE_META_DATA_ID_HW },
46054615
};
46064616

46074617
/**
@@ -5260,72 +5270,6 @@ ice_create_recipe_group(struct ice_hw *hw, struct ice_sw_recipe *rm,
52605270
return status;
52615271
}
52625272

5263-
/**
5264-
* ice_tun_type_match_word - determine if tun type needs a match mask
5265-
* @tun_type: tunnel type
5266-
* @mask: mask to be used for the tunnel
5267-
*/
5268-
static bool ice_tun_type_match_word(enum ice_sw_tunnel_type tun_type, u16 *mask)
5269-
{
5270-
switch (tun_type) {
5271-
case ICE_SW_TUN_GENEVE:
5272-
case ICE_SW_TUN_VXLAN:
5273-
case ICE_SW_TUN_NVGRE:
5274-
case ICE_SW_TUN_GTPU:
5275-
case ICE_SW_TUN_GTPC:
5276-
*mask = ICE_PKT_TUNNEL_MASK;
5277-
return true;
5278-
5279-
default:
5280-
*mask = 0;
5281-
return false;
5282-
}
5283-
}
5284-
5285-
/**
5286-
* ice_add_special_words - Add words that are not protocols, such as metadata
5287-
* @rinfo: other information regarding the rule e.g. priority and action info
5288-
* @lkup_exts: lookup word structure
5289-
* @dvm_ena: is double VLAN mode enabled
5290-
*/
5291-
static int
5292-
ice_add_special_words(struct ice_adv_rule_info *rinfo,
5293-
struct ice_prot_lkup_ext *lkup_exts, bool dvm_ena)
5294-
{
5295-
u16 mask;
5296-
5297-
/* If this is a tunneled packet, then add recipe index to match the
5298-
* tunnel bit in the packet metadata flags.
5299-
*/
5300-
if (ice_tun_type_match_word(rinfo->tun_type, &mask)) {
5301-
if (lkup_exts->n_val_words < ICE_MAX_CHAIN_WORDS) {
5302-
u8 word = lkup_exts->n_val_words++;
5303-
5304-
lkup_exts->fv_words[word].prot_id = ICE_META_DATA_ID_HW;
5305-
lkup_exts->fv_words[word].off =
5306-
ICE_PKT_TUNNEL_MDID_OFFSET;
5307-
lkup_exts->field_mask[word] = mask;
5308-
} else {
5309-
return -ENOSPC;
5310-
}
5311-
}
5312-
5313-
if (rinfo->vlan_type != 0 && dvm_ena) {
5314-
if (lkup_exts->n_val_words < ICE_MAX_CHAIN_WORDS) {
5315-
u8 word = lkup_exts->n_val_words++;
5316-
5317-
lkup_exts->fv_words[word].prot_id = ICE_META_DATA_ID_HW;
5318-
lkup_exts->fv_words[word].off =
5319-
ICE_PKT_VLAN_MDID_OFFSET;
5320-
lkup_exts->field_mask[word] = ICE_PKT_VLAN_MASK;
5321-
} else {
5322-
return -ENOSPC;
5323-
}
5324-
}
5325-
5326-
return 0;
5327-
}
5328-
53295273
/* ice_get_compat_fv_bitmap - Get compatible field vector bitmap for rule
53305274
* @hw: pointer to hardware structure
53315275
* @rinfo: other information regarding the rule e.g. priority and action info
@@ -5439,13 +5383,6 @@ ice_add_adv_recipe(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
54395383
if (status)
54405384
goto err_unroll;
54415385

5442-
/* Create any special protocol/offset pairs, such as looking at tunnel
5443-
* bits by extracting metadata
5444-
*/
5445-
status = ice_add_special_words(rinfo, lkup_exts, ice_is_dvm_ena(hw));
5446-
if (status)
5447-
goto err_unroll;
5448-
54495386
/* Group match words into recipes using preferred recipe grouping
54505387
* criteria.
54515388
*/
@@ -5731,6 +5668,10 @@ ice_fill_adv_dummy_packet(struct ice_adv_lkup_elem *lkups, u16 lkups_cnt,
57315668
* was already checked when search for the dummy packet
57325669
*/
57335670
type = lkups[i].type;
5671+
/* metadata isn't present in the packet */
5672+
if (type == ICE_HW_METADATA)
5673+
continue;
5674+
57345675
for (j = 0; offsets[j].type != ICE_PROTOCOL_LAST; j++) {
57355676
if (type == offsets[j].type) {
57365677
offset = offsets[j].offset;
@@ -5866,16 +5807,21 @@ ice_fill_adv_packet_tun(struct ice_hw *hw, enum ice_sw_tunnel_type tun_type,
58665807

58675808
/**
58685809
* ice_fill_adv_packet_vlan - fill dummy packet with VLAN tag type
5810+
* @hw: pointer to hw structure
58695811
* @vlan_type: VLAN tag type
58705812
* @pkt: dummy packet to fill in
58715813
* @offsets: offset info for the dummy packet
58725814
*/
58735815
static int
5874-
ice_fill_adv_packet_vlan(u16 vlan_type, u8 *pkt,
5816+
ice_fill_adv_packet_vlan(struct ice_hw *hw, u16 vlan_type, u8 *pkt,
58755817
const struct ice_dummy_pkt_offsets *offsets)
58765818
{
58775819
u16 i;
58785820

5821+
/* Check if there is something to do */
5822+
if (!vlan_type || !ice_is_dvm_ena(hw))
5823+
return 0;
5824+
58795825
/* Find VLAN header and insert VLAN TPID */
58805826
for (i = 0; offsets[i].type != ICE_PROTOCOL_LAST; i++) {
58815827
if (offsets[i].type == ICE_VLAN_OFOS ||
@@ -5894,6 +5840,15 @@ ice_fill_adv_packet_vlan(u16 vlan_type, u8 *pkt,
58945840
return -EIO;
58955841
}
58965842

5843+
static bool ice_rules_equal(const struct ice_adv_rule_info *first,
5844+
const struct ice_adv_rule_info *second)
5845+
{
5846+
return first->sw_act.flag == second->sw_act.flag &&
5847+
first->tun_type == second->tun_type &&
5848+
first->vlan_type == second->vlan_type &&
5849+
first->src_vsi == second->src_vsi;
5850+
}
5851+
58975852
/**
58985853
* ice_find_adv_rule_entry - Search a rule entry
58995854
* @hw: pointer to the hardware structure
@@ -5927,9 +5882,7 @@ ice_find_adv_rule_entry(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
59275882
lkups_matched = false;
59285883
break;
59295884
}
5930-
if (rinfo->sw_act.flag == list_itr->rule_info.sw_act.flag &&
5931-
rinfo->tun_type == list_itr->rule_info.tun_type &&
5932-
rinfo->vlan_type == list_itr->rule_info.vlan_type &&
5885+
if (ice_rules_equal(rinfo, &list_itr->rule_info) &&
59335886
lkups_matched)
59345887
return list_itr;
59355888
}
@@ -6045,6 +5998,20 @@ ice_adv_add_update_vsi_list(struct ice_hw *hw,
60455998
return status;
60465999
}
60476000

6001+
void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup)
6002+
{
6003+
lkup->type = ICE_HW_METADATA;
6004+
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_TUNNEL] =
6005+
cpu_to_be16(ICE_PKT_TUNNEL_MASK);
6006+
}
6007+
6008+
void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup)
6009+
{
6010+
lkup->type = ICE_HW_METADATA;
6011+
lkup->m_u.metadata.flags[ICE_PKT_FLAGS_VLAN] =
6012+
cpu_to_be16(ICE_PKT_VLAN_MASK);
6013+
}
6014+
60486015
/**
60496016
* ice_add_adv_rule - helper function to create an advanced switch rule
60506017
* @hw: pointer to the hardware structure
@@ -6126,7 +6093,11 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
61266093
if (rinfo->sw_act.fltr_act == ICE_FWD_TO_VSI)
61276094
rinfo->sw_act.fwd_id.hw_vsi_id =
61286095
ice_get_hw_vsi_num(hw, vsi_handle);
6129-
rinfo->sw_act.src = ice_get_hw_vsi_num(hw, vsi_handle);
6096+
6097+
if (rinfo->src_vsi)
6098+
rinfo->sw_act.src = ice_get_hw_vsi_num(hw, rinfo->src_vsi);
6099+
else
6100+
rinfo->sw_act.src = ice_get_hw_vsi_num(hw, vsi_handle);
61306101

61316102
status = ice_add_adv_recipe(hw, lkups, lkups_cnt, rinfo, &rid);
61326103
if (status)
@@ -6217,22 +6188,16 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
62176188
if (status)
62186189
goto err_ice_add_adv_rule;
62196190

6220-
if (rinfo->tun_type != ICE_NON_TUN &&
6221-
rinfo->tun_type != ICE_SW_TUN_AND_NON_TUN) {
6222-
status = ice_fill_adv_packet_tun(hw, rinfo->tun_type,
6223-
s_rule->hdr_data,
6224-
profile->offsets);
6225-
if (status)
6226-
goto err_ice_add_adv_rule;
6227-
}
6191+
status = ice_fill_adv_packet_tun(hw, rinfo->tun_type, s_rule->hdr_data,
6192+
profile->offsets);
6193+
if (status)
6194+
goto err_ice_add_adv_rule;
62286195

6229-
if (rinfo->vlan_type != 0 && ice_is_dvm_ena(hw)) {
6230-
status = ice_fill_adv_packet_vlan(rinfo->vlan_type,
6231-
s_rule->hdr_data,
6232-
profile->offsets);
6233-
if (status)
6234-
goto err_ice_add_adv_rule;
6235-
}
6196+
status = ice_fill_adv_packet_vlan(hw, rinfo->vlan_type,
6197+
s_rule->hdr_data,
6198+
profile->offsets);
6199+
if (status)
6200+
goto err_ice_add_adv_rule;
62366201

62376202
status = ice_aq_sw_rules(hw, (struct ice_aqc_sw_rules *)s_rule,
62386203
rule_buf_sz, 1, ice_aqc_opc_add_sw_rules,
@@ -6475,13 +6440,6 @@ ice_rem_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
64756440
return -EIO;
64766441
}
64776442

6478-
/* Create any special protocol/offset pairs, such as looking at tunnel
6479-
* bits by extracting metadata
6480-
*/
6481-
status = ice_add_special_words(rinfo, &lkup_exts, ice_is_dvm_ena(hw));
6482-
if (status)
6483-
return status;
6484-
64856443
rid = ice_find_recp(hw, &lkup_exts, rinfo->tun_type);
64866444
/* If did not find a recipe that match the existing criteria */
64876445
if (rid == ICE_MAX_NUM_RECIPES)

drivers/net/ethernet/intel/ice/ice_switch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,12 @@ struct ice_adv_rule_flags_info {
186186
};
187187

188188
struct ice_adv_rule_info {
189+
/* Store metadata values in rule info */
189190
enum ice_sw_tunnel_type tun_type;
190191
u16 vlan_type;
191192
u16 fltr_rule_id;
192193
u32 priority;
194+
u16 src_vsi;
193195
struct ice_sw_act_ctrl sw_act;
194196
struct ice_adv_rule_flags_info flags_info;
195197
};
@@ -340,6 +342,8 @@ ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
340342
u16 counter_id);
341343

342344
/* Switch/bridge related commands */
345+
void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup);
346+
void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup);
343347
int
344348
ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
345349
u16 lkups_cnt, struct ice_adv_rule_info *rinfo,

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
5454
if (flags & (ICE_TC_FLWR_FIELD_VLAN | ICE_TC_FLWR_FIELD_VLAN_PRIO))
5555
lkups_cnt++;
5656

57+
/* is VLAN TPID specified */
58+
if (flags & ICE_TC_FLWR_FIELD_VLAN_TPID)
59+
lkups_cnt++;
60+
5761
/* is CVLAN specified? */
5862
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO))
5963
lkups_cnt++;
@@ -80,6 +84,10 @@ ice_tc_count_lkups(u32 flags, struct ice_tc_flower_lyr_2_4_hdrs *headers,
8084
ICE_TC_FLWR_FIELD_SRC_L4_PORT))
8185
lkups_cnt++;
8286

87+
/* matching for tunneled packets in metadata */
88+
if (fltr->tunnel_type != TNL_LAST)
89+
lkups_cnt++;
90+
8391
return lkups_cnt;
8492
}
8593

@@ -320,6 +328,10 @@ ice_tc_fill_tunnel_outer(u32 flags, struct ice_tc_flower_fltr *fltr,
320328
i++;
321329
}
322330

331+
/* always fill matching on tunneled packets in metadata */
332+
ice_rule_add_tunnel_metadata(&list[i]);
333+
i++;
334+
323335
return i;
324336
}
325337

@@ -390,10 +402,6 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
390402

391403
/* copy VLAN info */
392404
if (flags & (ICE_TC_FLWR_FIELD_VLAN | ICE_TC_FLWR_FIELD_VLAN_PRIO)) {
393-
vlan_tpid = be16_to_cpu(headers->vlan_hdr.vlan_tpid);
394-
rule_info->vlan_type =
395-
ice_check_supported_vlan_tpid(vlan_tpid);
396-
397405
if (flags & ICE_TC_FLWR_FIELD_CVLAN)
398406
list[i].type = ICE_VLAN_EX;
399407
else
@@ -418,6 +426,15 @@ ice_tc_fill_rules(struct ice_hw *hw, u32 flags,
418426
i++;
419427
}
420428

429+
if (flags & ICE_TC_FLWR_FIELD_VLAN_TPID) {
430+
vlan_tpid = be16_to_cpu(headers->vlan_hdr.vlan_tpid);
431+
rule_info->vlan_type =
432+
ice_check_supported_vlan_tpid(vlan_tpid);
433+
434+
ice_rule_add_vlan_metadata(&list[i]);
435+
i++;
436+
}
437+
421438
if (flags & (ICE_TC_FLWR_FIELD_CVLAN | ICE_TC_FLWR_FIELD_CVLAN_PRIO)) {
422439
list[i].type = ICE_VLAN_IN;
423440

@@ -1455,8 +1472,10 @@ ice_parse_cls_flower(struct net_device *filter_dev, struct ice_vsi *vsi,
14551472
VLAN_PRIO_MASK);
14561473
}
14571474

1458-
if (match.mask->vlan_tpid)
1475+
if (match.mask->vlan_tpid) {
14591476
headers->vlan_hdr.vlan_tpid = match.key->vlan_tpid;
1477+
fltr->flags |= ICE_TC_FLWR_FIELD_VLAN_TPID;
1478+
}
14601479
}
14611480

14621481
if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CVLAN)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define ICE_TC_FLWR_FIELD_L2TPV3_SESSID BIT(26)
3434
#define ICE_TC_FLWR_FIELD_VLAN_PRIO BIT(27)
3535
#define ICE_TC_FLWR_FIELD_CVLAN_PRIO BIT(28)
36+
#define ICE_TC_FLWR_FIELD_VLAN_TPID BIT(29)
3637

3738
#define ICE_TC_FLOWER_MASK_32 0xFFFFFFFF
3839

0 commit comments

Comments
 (0)