enum efx_encap_type efx_tc_indr_netdev_type(struct net_device *net_dev)
{ if (netif_is_vxlan(net_dev)) return EFX_ENCAP_TYPE_VXLAN; if (netif_is_geneve(net_dev)) return EFX_ENCAP_TYPE_GENEVE;
return EFX_ENCAP_TYPE_NONE;
}
#define EFX_TC_HDR_TYPE_TTL_MASK ((u32)0xff) /* Hoplimit is stored in the most significant byte in the pedit ipv6 header action */ #define EFX_TC_HDR_TYPE_HLIMIT_MASK ~((u32)0xff000000) #define EFX_EFV_PF NULL /* Look up the representor information (efv) for a device. *MayreturnNULLforthePF(us),oranerrorpointerforadevicethat *isn'tsupportedasaTCoffloadendpoint
*/ struct efx_rep *efx_tc_flower_lookup_efv(struct efx_nic *efx, struct net_device *dev)
{ struct efx_rep *efv;
if (!dev) return ERR_PTR(-EOPNOTSUPP); /* Is it us (the PF)? */ if (dev == efx->net_dev) return EFX_EFV_PF; /* Is it an efx vfrep at all? */ if (dev->netdev_ops != &efx_ef100_rep_netdev_ops) return ERR_PTR(-EOPNOTSUPP); /* Is it ours? We don't support TC rules that include another *EF100'snetdevices(notevenonanotherportofthesameNIC).
*/
efv = netdev_priv(dev); if (efv->parent != efx) return ERR_PTR(-EOPNOTSUPP); return efv;
}
/* Convert a driver-internal vport ID into an internal device (PF or VF) */ static s64 efx_tc_flower_internal_mport(struct efx_nic *efx, struct efx_rep *efv)
{
u32 mport;
if (IS_ERR(efv)) return PTR_ERR(efv); if (!efv) /* device is PF (us) */
efx_mae_mport_uplink(efx, &mport); else/* device is repr */
efx_mae_mport_mport(efx, efv->mport, &mport); return mport;
}
/* Convert a driver-internal vport ID into an external device (wire or VF) */
s64 efx_tc_flower_external_mport(struct efx_nic *efx, struct efx_rep *efv)
{
u32 mport;
if (IS_ERR(efv)) return PTR_ERR(efv); if (!efv) /* device is PF (us) */
efx_mae_mport_wire(efx, &mport); else/* device is repr */
efx_mae_mport_mport(efx, efv->mport, &mport); return mport;
}
staticvoid efx_tc_flower_put_mac(struct efx_nic *efx, struct efx_tc_mac_pedit_action *ped)
{ if (!refcount_dec_and_test(&ped->ref)) return; /* still in use */
rhashtable_remove_fast(&efx->tc->mac_ht, &ped->linkage,
efx_tc_mac_ht_params);
efx_mae_free_pedit_mac(efx, ped);
kfree(ped);
}
staticvoid efx_tc_free_action_set(struct efx_nic *efx, struct efx_tc_action_set *act, bool in_hw)
{ /* Failure paths calling this on the 'cursor' action set in_hw=false, *becauseiftheallochadsucceededwe'd'veputitinacts.listand *notstillhaveitinact.
*/ if (in_hw) {
efx_mae_free_action_set(efx, act->fw_id); /* in_hw is true iff we are on an acts.list; make sure to *removeourselvesfromthatlistbeforewearefreed.
*/
list_del(&act->list);
} if (act->count) {
spin_lock_bh(&act->count->cnt->lock); if (!list_empty(&act->count_user))
list_del(&act->count_user);
spin_unlock_bh(&act->count->cnt->lock);
efx_tc_flower_put_counter_index(efx, act->count);
} if (act->encap_md) {
list_del(&act->encap_user);
efx_tc_flower_release_encap_md(efx, act->encap_md);
} if (act->src_mac)
efx_tc_flower_put_mac(efx, act->src_mac); if (act->dst_mac)
efx_tc_flower_put_mac(efx, act->dst_mac);
kfree(act);
}
/* Failure paths set in_hw=false, because usually the acts didn't get *toefx_mae_alloc_action_set_list();iftheydid,thefailuretree *hasaseparateefx_mae_free_action_set_list()beforecallingus.
*/ if (in_hw)
efx_mae_free_action_set_list(efx, acts); /* Any act that's on the list will be in_hw even if the list isn't */
list_for_each_entry_safe(act, next, &acts->list, list)
efx_tc_free_action_set(efx, act, true); /* Don't kfree, as acts is embedded inside a struct efx_tc_flow_rule */
}
/* Owing to internal TC infelicities, the IPV6_ADDRS key might be set *evenonIPv4filters;soratherthanrelyingondissector->used_keys *wechecktheaddr_typeintheCONTROLkey.Ifwedon'tfindit(or *it'smasked,whichshouldneverhappen),wetreatbothIPV4_ADDRS *andIPV6_ADDRSasabsent.
*/ if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL)) { struct flow_match_control fm;
flow_rule_match_control(rule, &fm); if (IS_ALL_ONES(fm.mask->addr_type)) switch (fm.key->addr_type) { case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
ipv = 4; break; case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
ipv = 6; break; default: break;
}
if (memchr_inv(fm.mask->ct_labels, 0, sizeof(fm.mask->ct_labels))) {
NL_SET_ERR_MSG_MOD(extack, "Matching on ct_label not supported"); return -EOPNOTSUPP;
}
}
return0;
}
staticvoid efx_tc_flower_release_encap_match(struct efx_nic *efx, struct efx_tc_encap_match *encap)
{ int rc;
if (!refcount_dec_and_test(&encap->ref)) return; /* still in use */
if (encap->type == EFX_TC_EM_DIRECT) {
rc = efx_mae_unregister_encap_match(efx, encap); if (rc) /* Display message but carry on and remove entry from our *SWtables,becausethere'snotmuchwecandoaboutit.
*/
netif_err(efx, drv, efx->net_dev, "Failed to release encap match %#x, rc %d\n",
encap->fw_id, rc);
}
rhashtable_remove_fast(&efx->tc->encap_match_ht, &encap->linkage,
efx_tc_encap_match_ht_params); if (encap->pseudo)
efx_tc_flower_release_encap_match(efx, encap->pseudo);
kfree(encap);
}
/* We require that the socket-defining fields (IP addrs and UDP dest *port)arepresentandexact-match.Otherfieldsmayonlybeused *ifthefield-set(andanymasks)arethesameforallencap *matchesonthesame<sip,dip,dport>tuple;thisisenforcedby *pseudoencapmatches.
*/ if (match->mask.enc_dst_ip | match->mask.enc_src_ip) { if (!IS_ALL_ONES(match->mask.enc_dst_ip)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on dst IP address"); return -EOPNOTSUPP;
} if (!IS_ALL_ONES(match->mask.enc_src_ip)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on src IP address"); return -EOPNOTSUPP;
} #ifdef CONFIG_IPV6 if (!ipv6_addr_any(&match->mask.enc_dst_ip6) ||
!ipv6_addr_any(&match->mask.enc_src_ip6)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match on both IPv4 and IPv6, don't understand"); return -EOPNOTSUPP;
}
} else {
ipv6 = true; if (!efx_ipv6_addr_all_ones(&match->mask.enc_dst_ip6)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on dst IP address"); return -EOPNOTSUPP;
} if (!efx_ipv6_addr_all_ones(&match->mask.enc_src_ip6)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on src IP address"); return -EOPNOTSUPP;
} #endif
} if (!IS_ALL_ONES(match->mask.enc_dport)) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match is not exact on dst UDP port"); return -EOPNOTSUPP;
} if (match->mask.enc_sport || match->mask.enc_ip_tos) { struct efx_tc_match pmatch = *match;
if (em_type == EFX_TC_EM_PSEUDO_MASK) { /* can't happen */
NL_SET_ERR_MSG_MOD(extack, "Bad recursion in egress encap match handler"); return -EOPNOTSUPP;
}
pmatch.value.enc_ip_tos = 0;
pmatch.mask.enc_ip_tos = 0;
pmatch.value.enc_sport = 0;
pmatch.mask.enc_sport = 0;
rc = efx_tc_flower_record_encap_match(efx, &pmatch, type,
EFX_TC_EM_PSEUDO_MASK,
match->mask.enc_ip_tos,
match->mask.enc_sport,
extack); if (rc) return rc;
pseudo = pmatch.encap;
} if (match->mask.enc_ip_ttl) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match on IP TTL not supported");
rc = -EOPNOTSUPP; goto fail_pseudo;
}
encap = kzalloc(sizeof(*encap), GFP_USER); if (!encap) {
rc = -ENOMEM; goto fail_pseudo;
}
encap->src_ip = match->value.enc_src_ip;
encap->dst_ip = match->value.enc_dst_ip; #ifdef CONFIG_IPV6
encap->src_ip6 = match->value.enc_src_ip6;
encap->dst_ip6 = match->value.enc_dst_ip6; #endif
encap->udp_dport = match->value.enc_dport;
encap->tun_type = type;
encap->ip_tos = match->value.enc_ip_tos;
encap->ip_tos_mask = match->mask.enc_ip_tos;
encap->child_ip_tos_mask = child_ip_tos_mask;
encap->udp_sport = match->value.enc_sport;
encap->udp_sport_mask = match->mask.enc_sport;
encap->child_udp_sport_mask = child_udp_sport_mask;
encap->type = em_type;
encap->pseudo = pseudo;
old = rhashtable_lookup_get_insert_fast(&efx->tc->encap_match_ht,
&encap->linkage,
efx_tc_encap_match_ht_params); if (old) { /* don't need our new entry */
kfree(encap); if (pseudo) /* don't need our new pseudo either */
efx_tc_flower_release_encap_match(efx, pseudo); if (IS_ERR(old)) /* oh dear, it's actually an error */ return PTR_ERR(old); /* check old and new em_types are compatible */ switch (old->type) { case EFX_TC_EM_DIRECT: /* old EM is in hardware, so mustn't overlap with a *pseudo,butmaybesharedwithanotherdirectEM
*/ if (em_type == EFX_TC_EM_DIRECT) break;
NL_SET_ERR_MSG_MOD(extack, "Pseudo encap match conflicts with existing direct entry"); return -EEXIST; case EFX_TC_EM_PSEUDO_MASK: /* old EM is protecting a ToS- or src port-qualified *filter,somayonlybesharedwithanotherpseudo *forthesameToSandsrcportmasks.
*/ if (em_type != EFX_TC_EM_PSEUDO_MASK) {
NL_SET_ERR_MSG_FMT_MOD(extack, "%s encap match conflicts with existing pseudo(MASK) entry",
em_type ? "Pseudo" : "Direct"); return -EEXIST;
} if (child_ip_tos_mask != old->child_ip_tos_mask) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Pseudo encap match for TOS mask %#04x conflicts with existing mask %#04x",
child_ip_tos_mask,
old->child_ip_tos_mask); return -EEXIST;
} if (child_udp_sport_mask != old->child_udp_sport_mask) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Pseudo encap match for UDP src port mask %#x conflicts with existing mask %#x",
child_udp_sport_mask,
old->child_udp_sport_mask); return -EEXIST;
} break; case EFX_TC_EM_PSEUDO_OR: /* old EM corresponds to an OR that has to be unique *(itmustnotoverlapwithanyotherOR,whether *direct-EMorpseudo).
*/
NL_SET_ERR_MSG_FMT_MOD(extack, "%s encap match conflicts with existing pseudo(OR) entry",
em_type ? "Pseudo" : "Direct"); return -EEXIST; default: /* Unrecognised pseudo-type. Just say no */
NL_SET_ERR_MSG_FMT_MOD(extack, "%s encap match conflicts with existing pseudo(%d) entry",
em_type ? "Pseudo" : "Direct",
old->type); return -EEXIST;
} /* check old and new tun_types are compatible */ if (old->tun_type != type) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Egress encap match with conflicting tun_type %u != %u",
old->tun_type, type); return -EEXIST;
} if (!refcount_inc_not_zero(&old->ref)) return -EAGAIN; /* existing entry found */
encap = old;
} else { if (em_type == EFX_TC_EM_DIRECT) {
rc = efx_mae_register_encap_match(efx, encap); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to record egress encap match in HW"); goto fail;
}
}
refcount_set(&encap->ref, 1);
}
match->encap = encap; return0;
fail:
rhashtable_remove_fast(&efx->tc->encap_match_ht, &encap->linkage,
efx_tc_encap_match_ht_params);
kfree(encap);
fail_pseudo: if (pseudo)
efx_tc_flower_release_encap_match(efx, pseudo); return rc;
}
/* Release entries in subsidiary tables */
efx_tc_free_action_set_list(efx, &rule->acts, true); if (rule->match.rid)
efx_tc_put_recirc_id(efx, rule->match.rid); if (rule->match.encap)
efx_tc_flower_release_encap_match(efx, rule->match.encap);
rule->fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
}
staticconstchar *efx_tc_encap_type_name(enum efx_encap_type typ)
{ switch (typ) { case EFX_ENCAP_TYPE_NONE: return"none"; case EFX_ENCAP_TYPE_VXLAN: return"vxlan"; case EFX_ENCAP_TYPE_GENEVE: return"geneve"; default:
pr_warn_once("Unknown efx_encap_type %d encountered\n", typ); return"unknown";
}
}
/* For details of action order constraints refer to SF-123102-TC-1§12.6.1 */ enum efx_tc_action_order {
EFX_TC_AO_DECAP,
EFX_TC_AO_DEC_TTL,
EFX_TC_AO_PEDIT_MAC_ADDRS,
EFX_TC_AO_VLAN_POP,
EFX_TC_AO_VLAN_PUSH,
EFX_TC_AO_COUNT,
EFX_TC_AO_ENCAP,
EFX_TC_AO_DELIVER
}; /* Determine whether we can add @new action without violating order */ staticbool efx_tc_flower_action_order_ok(conststruct efx_tc_action_set *act, enum efx_tc_action_order new)
{ switch (new) { case EFX_TC_AO_DECAP: if (act->decap) returnfalse; /* PEDIT_MAC_ADDRS must not happen before DECAP, though it *canwaituntilmuchlater
*/ if (act->dst_mac || act->src_mac) returnfalse;
/* Decrementing ttl must not happen before DECAP */ if (act->do_ttl_dec) returnfalse;
fallthrough; case EFX_TC_AO_VLAN_POP: if (act->vlan_pop >= 2) returnfalse; /* If we've already pushed a VLAN, we can't then pop it; *thehardwarewouldinsteadtrytopopanexistingVLAN *beforepushingthenewone.
*/ if (act->vlan_push) returnfalse;
fallthrough; case EFX_TC_AO_VLAN_PUSH: if (act->vlan_push >= 2) returnfalse;
fallthrough; case EFX_TC_AO_COUNT: if (act->count) returnfalse;
fallthrough; case EFX_TC_AO_PEDIT_MAC_ADDRS: case EFX_TC_AO_ENCAP: if (act->encap_md) returnfalse;
fallthrough; case EFX_TC_AO_DELIVER: return !act->deliver; case EFX_TC_AO_DEC_TTL: if (act->encap_md) returnfalse; return !act->do_ttl_dec; default: /* Bad caller. Whatever they wanted to do, say they can't. */
WARN_ON_ONCE(1); returnfalse;
}
}
flow_action_for_each(i, fa, &fr->action) { switch (fa->id) { case FLOW_ACTION_GOTO: returntrue; case FLOW_ACTION_CT: /* If rule is -trk, or doesn't mention trk at all, then *aCTactionimpliesaconntracklookup(henceit'san *LHSrule).Ifruleis+trk,thenaCTactioncould *justbect(nat)orevenct(commit)(thoughthelatter *can'tbeoffloaded).
*/ if (!match->mask.ct_state_trk || !match->value.ct_state_trk) returntrue; break; default: break;
}
} returnfalse;
}
/* A foreign LHS rule has matches on enc_ keys at the TC layer (including an *impliedmatchonenc_ip_protoUDP).Translatetheseintonon-enc_keys, *sothatwecanusethesameMAEmachineryaslocalLHSrules(andsothat *thelhs_rulesentrieshaveuniformsemantics).Itmayseemoddtodoit *thiswayround,giventhatthecorrespondingfieldsintheMAEMCDIsare *allENC_,but(a)wedon'thaveenc_L2orenc_ip_protoinstruct *efx_tc_match_fieldsand(b)semanticallyanLHSruledoesn'thaveinner *fieldssoit'sjustmatchingon*the*headerratherthantheouterheader. *Makesurethatthenon-enc_keyswerenotalreadybeingmatchedon,asthat *wouldimplyarulethatneededatriplelookup.(Hardwarecandothat, *withOR-AR-CT-AR,butithalvespacketratesoweavoiditwherepossible; *seeefx_tc_flower_flhs_needs_ar().)
*/ staticint efx_tc_flower_translate_flhs_match(struct efx_tc_match *match)
{ int rc = 0;
#define COPY_MASK_AND_VALUE(_key, _ekey) ({ \ if (match->mask._key) { \
rc = -EOPNOTSUPP; \
} else { \
match->mask._key = match->mask._ekey; \
match->mask._ekey = 0; \
match->value._key = match->value._ekey; \
match->value._ekey = 0; \
} \
rc; \
}) #define COPY_FROM_ENC(_key) COPY_MASK_AND_VALUE(_key, enc_##_key) if (match->mask.ip_proto) return -EOPNOTSUPP;
match->mask.ip_proto = ~0;
match->value.ip_proto = IPPROTO_UDP; if (COPY_FROM_ENC(src_ip) || COPY_FROM_ENC(dst_ip)) return rc; #ifdef CONFIG_IPV6 if (!ipv6_addr_any(&match->mask.src_ip6)) return -EOPNOTSUPP;
match->mask.src_ip6 = match->mask.enc_src_ip6;
memset(&match->mask.enc_src_ip6, 0, sizeof(struct in6_addr)); if (!ipv6_addr_any(&match->mask.dst_ip6)) return -EOPNOTSUPP;
match->mask.dst_ip6 = match->mask.enc_dst_ip6;
memset(&match->mask.enc_dst_ip6, 0, sizeof(struct in6_addr)); #endif if (COPY_FROM_ENC(ip_tos) || COPY_FROM_ENC(ip_ttl)) return rc; /* should really copy enc_ip_frag but we don't have that in *parse_matchyet
*/ if (COPY_MASK_AND_VALUE(l4_sport, enc_sport) ||
COPY_MASK_AND_VALUE(l4_dport, enc_dport)) return rc; return0; #undef COPY_FROM_ENC #undef COPY_MASK_AND_VALUE
}
/* If a foreign LHS rule wants to match on keys that are only available after *encapheaderidentificationandparsing,thenitcan'tbedoneintheOuter *Rulelookup,becausethatlookupdeterminestheencaptypeusedtoparse *beyondtheouterheaders.Thus,suchrulesmustusetheOR-AR-CT-ARlookup *sequence,withanEM(structefx_tc_encap_match)intheORstep. *Returntrueiffthepassedmatchrequiresthis.
*/ staticbool efx_tc_flower_flhs_needs_ar(struct efx_tc_match *match)
{ /* matches on inner-header keys can't be done in OR */ return match->mask.eth_proto ||
match->mask.vlan_tci[0] || match->mask.vlan_tci[1] ||
match->mask.vlan_proto[0] || match->mask.vlan_proto[1] ||
memchr_inv(match->mask.eth_saddr, 0, ETH_ALEN) ||
memchr_inv(match->mask.eth_daddr, 0, ETH_ALEN) ||
match->mask.ip_proto ||
match->mask.ip_tos || match->mask.ip_ttl ||
match->mask.src_ip || match->mask.dst_ip || #ifdef CONFIG_IPV6
!ipv6_addr_any(&match->mask.src_ip6) ||
!ipv6_addr_any(&match->mask.dst_ip6) || #endif
match->mask.ip_frag || match->mask.ip_firstfrag ||
match->mask.l4_sport || match->mask.l4_dport ||
match->mask.tcp_flags || /* nor can VNI */
match->mask.enc_keyid;
}
if (!pipe) { /* more actions after a non-pipe action */
NL_SET_ERR_MSG_MOD(extack, "Action follows non-pipe action"); return -EINVAL;
} switch (fa->id) { case FLOW_ACTION_GOTO: if (!fa->chain_index) {
NL_SET_ERR_MSG_MOD(extack, "Can't goto chain 0, no looping in hw"); return -EOPNOTSUPP;
}
rid = efx_tc_get_recirc_id(efx, fa->chain_index,
net_dev); if (IS_ERR(rid)) {
NL_SET_ERR_MSG_MOD(extack, "Failed to allocate a hardware recirculation ID for this chain_index"); return PTR_ERR(rid);
}
act->rid = rid; if (fa->hw_stats) { struct efx_tc_counter_index *cnt;
if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')",
fa->hw_stats); return -EOPNOTSUPP;
}
cnt = efx_tc_flower_get_counter_index(efx, tc->cookie,
ctype); if (IS_ERR(cnt)) {
NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter"); return PTR_ERR(cnt);
}
WARN_ON(act->count); /* can't happen */
act->count = cnt;
}
pipe = false; break; case FLOW_ACTION_CT: if (act->zone) {
NL_SET_ERR_MSG_MOD(extack, "Can't offload multiple ct actions"); return -EOPNOTSUPP;
} if (fa->ct.action & (TCA_CT_ACT_COMMIT |
TCA_CT_ACT_FORCE)) {
NL_SET_ERR_MSG_MOD(extack, "Can't offload ct commit/force"); return -EOPNOTSUPP;
} if (fa->ct.action & TCA_CT_ACT_CLEAR) {
NL_SET_ERR_MSG_MOD(extack, "Can't clear ct in LHS rule"); return -EOPNOTSUPP;
} if (fa->ct.action & (TCA_CT_ACT_NAT |
TCA_CT_ACT_NAT_SRC |
TCA_CT_ACT_NAT_DST)) {
NL_SET_ERR_MSG_MOD(extack, "Can't perform NAT in LHS rule - packet isn't conntracked yet"); return -EOPNOTSUPP;
} if (fa->ct.action) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled ct.action %u for LHS rule",
fa->ct.action); return -EOPNOTSUPP;
}
ct_zone = efx_tc_ct_register_zone(efx, fa->ct.zone,
fa->ct.flow_table); if (IS_ERR(ct_zone)) {
NL_SET_ERR_MSG_MOD(extack, "Failed to register for CT updates"); return PTR_ERR(ct_zone);
}
act->zone = ct_zone; break; default:
NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled action %u for LHS rule",
fa->id); return -EOPNOTSUPP;
}
}
if (pipe) {
NL_SET_ERR_MSG_MOD(extack, "Missing goto chain in LHS rule"); return -EOPNOTSUPP;
} return0;
}
staticvoid efx_tc_flower_release_lhs_actions(struct efx_nic *efx, struct efx_tc_lhs_action *act)
{ if (act->rid)
efx_tc_put_recirc_id(efx, act->rid); if (act->zone)
efx_tc_ct_unregister_zone(efx, act->zone); if (act->count)
efx_tc_flower_put_counter_index(efx, act->count);
}
if (mung->dst_mac_32 && mung->dst_mac_16) {
ped = efx_tc_flower_get_mac(efx, mung->dst_mac, extack); if (IS_ERR(ped)) return PTR_ERR(ped);
/* Check that we have not already populated dst_mac */ if (act->dst_mac)
efx_tc_flower_put_mac(efx, act->dst_mac);
act->dst_mac = ped;
/* consume the incomplete state */
mung->dst_mac_32 = 0;
mung->dst_mac_16 = 0;
} if (mung->src_mac_16 && mung->src_mac_32) {
ped = efx_tc_flower_get_mac(efx, mung->src_mac, extack); if (IS_ERR(ped)) return PTR_ERR(ped);
/* Check that we have not already populated src_mac */ if (act->src_mac)
efx_tc_flower_put_mac(efx, act->src_mac);
act->src_mac = ped;
/* consume the incomplete state */
mung->src_mac_32 = 0;
mung->src_mac_16 = 0;
} return0;
}
staticint efx_tc_pedit_add(struct efx_nic *efx, struct efx_tc_action_set *act, conststruct flow_action_entry *fa, struct netlink_ext_ack *extack)
{ switch (fa->mangle.htype) { case FLOW_ACT_MANGLE_HDR_TYPE_IP4: switch (fa->mangle.offset) { case offsetof(struct iphdr, ttl): /* check that pedit applies to ttl only */ if (fa->mangle.mask != ~EFX_TC_HDR_TYPE_TTL_MASK) break;
/* Adding 0xff is equivalent to decrementing the ttl. *Otheraddedvaluesarenotsupported.
*/ if ((fa->mangle.val & EFX_TC_HDR_TYPE_TTL_MASK) != U8_MAX) break;
/* check that we do not decrement ttl twice */ if (!efx_tc_flower_action_order_ok(act,
EFX_TC_AO_DEC_TTL)) {
NL_SET_ERR_MSG_MOD(extack, "multiple dec ttl are not supported"); return -EOPNOTSUPP;
}
act->do_ttl_dec = 1; return0; default: break;
} break; case FLOW_ACT_MANGLE_HDR_TYPE_IP6: switch (fa->mangle.offset) { case round_down(offsetof(struct ipv6hdr, hop_limit), 4): /* check that pedit applies to hoplimit only */ if (fa->mangle.mask != EFX_TC_HDR_TYPE_HLIMIT_MASK) break;
/* Adding 0xff is equivalent to decrementing the hoplimit. *Otheraddedvaluesarenotsupported.
*/ if ((fa->mangle.val >> 24) != U8_MAX) break;
/* check that we do not decrement hoplimit twice */ if (!efx_tc_flower_action_order_ok(act,
EFX_TC_AO_DEC_TTL)) {
NL_SET_ERR_MSG_MOD(extack, "multiple dec ttl are not supported"); return -EOPNOTSUPP;
}
act->do_ttl_dec = 1; return0; default: break;
} break; default: break;
}
NL_SET_ERR_MSG_FMT_MOD(extack, "ttl add action type %x %x %x/%x is not supported",
fa->mangle.htype, fa->mangle.offset,
fa->mangle.val, fa->mangle.mask); return -EOPNOTSUPP;
}
switch (fa->mangle.htype) { case FLOW_ACT_MANGLE_HDR_TYPE_ETH:
BUILD_BUG_ON(offsetof(struct ethhdr, h_dest) != 0);
BUILD_BUG_ON(offsetof(struct ethhdr, h_source) != 6); if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_PEDIT_MAC_ADDRS)) {
NL_SET_ERR_MSG_MOD(extack, "Pedit mangle mac action violates action order"); return -EOPNOTSUPP;
} switch (fa->mangle.offset) { case0: if (fa->mangle.mask) {
NL_SET_ERR_MSG_FMT_MOD(extack, "mask (%#x) of eth.dst32 mangle is not supported",
fa->mangle.mask); return -EOPNOTSUPP;
} /* Ethernet address is little-endian */
mac32 = cpu_to_le32(fa->mangle.val);
memcpy(mung->dst_mac, &mac32, sizeof(mac32));
mung->dst_mac_32 = 1; return efx_tc_complete_mac_mangle(efx, act, mung, extack); case4: if (fa->mangle.mask == 0xffff) {
mac16 = cpu_to_le16(fa->mangle.val >> 16);
memcpy(mung->src_mac, &mac16, sizeof(mac16));
mung->src_mac_16 = 1;
} elseif (fa->mangle.mask == 0xffff0000) {
mac16 = cpu_to_le16((u16)fa->mangle.val);
memcpy(mung->dst_mac + 4, &mac16, sizeof(mac16));
mung->dst_mac_16 = 1;
} else {
NL_SET_ERR_MSG_FMT_MOD(extack, "mask (%#x) of eth+4 mangle is not high or low 16b",
fa->mangle.mask); return -EOPNOTSUPP;
} return efx_tc_complete_mac_mangle(efx, act, mung, extack); case8: if (fa->mangle.mask) {
NL_SET_ERR_MSG_FMT_MOD(extack, "mask (%#x) of eth.src32 mangle is not supported",
fa->mangle.mask); return -EOPNOTSUPP;
}
mac32 = cpu_to_le32(fa->mangle.val);
memcpy(mung->src_mac + 2, &mac32, sizeof(mac32));
mung->src_mac_32 = 1; return efx_tc_complete_mac_mangle(efx, act, mung, extack); default:
NL_SET_ERR_MSG_FMT_MOD(extack, "mangle eth+%u %x/%x is not supported",
fa->mangle.offset, fa->mangle.val, fa->mangle.mask); return -EOPNOTSUPP;
} break; case FLOW_ACT_MANGLE_HDR_TYPE_IP4: switch (fa->mangle.offset) { case offsetof(struct iphdr, ttl): /* we currently only support pedit IP4 when it applies *toTTLandthenonlywhenitcanbeachievedwitha *decrementttlaction
*/
/* check that pedit applies to ttl only */ if (fa->mangle.mask != ~EFX_TC_HDR_TYPE_TTL_MASK) {
NL_SET_ERR_MSG_FMT_MOD(extack, "mask (%#x) out of range, only support mangle action on ipv4.ttl",
fa->mangle.mask); return -EOPNOTSUPP;
}
/* we can only convert to a dec ttl when we have an *exactmatchonthettlfield
*/ if (match->mask.ip_ttl != U8_MAX) {
NL_SET_ERR_MSG_FMT_MOD(extack, "only support mangle ttl when we have an exact match, current mask (%#x)",
match->mask.ip_ttl); return -EOPNOTSUPP;
}
/* check that we don't try to decrement 0, which equates *tosettingthettlto0xff
*/ if (match->value.ip_ttl == 0) {
NL_SET_ERR_MSG_MOD(extack, "decrement ttl past 0 is not supported"); return -EOPNOTSUPP;
}
/* check that we do not decrement ttl twice */ if (!efx_tc_flower_action_order_ok(act,
EFX_TC_AO_DEC_TTL)) {
NL_SET_ERR_MSG_MOD(extack, "multiple dec ttl is not supported"); return -EOPNOTSUPP;
}
/* check pedit can be achieved with decrement action */
tr_ttl = match->value.ip_ttl - 1; if ((fa->mangle.val & EFX_TC_HDR_TYPE_TTL_MASK) == tr_ttl) {
act->do_ttl_dec = 1; return0;
}
fallthrough; default:
NL_SET_ERR_MSG_FMT_MOD(extack, "only support mangle on the ttl field (offset is %u)",
fa->mangle.offset); return -EOPNOTSUPP;
} break; case FLOW_ACT_MANGLE_HDR_TYPE_IP6: switch (fa->mangle.offset) { case round_down(offsetof(struct ipv6hdr, hop_limit), 4): /* we currently only support pedit IP6 when it applies *tothehoplimitandthenonlywhenitcanbeachieved *withadecrementhoplimitaction
*/
/* check that pedit applies to ttl only */ if (fa->mangle.mask != EFX_TC_HDR_TYPE_HLIMIT_MASK) {
NL_SET_ERR_MSG_FMT_MOD(extack, "mask (%#x) out of range, only support mangle action on ipv6.hop_limit",
fa->mangle.mask);
return -EOPNOTSUPP;
}
/* we can only convert to a dec ttl when we have an *exactmatchonthettlfield
*/ if (match->mask.ip_ttl != U8_MAX) {
NL_SET_ERR_MSG_FMT_MOD(extack, "only support hop_limit when we have an exact match, current mask (%#x)",
match->mask.ip_ttl); return -EOPNOTSUPP;
}
/* check that we don't try to decrement 0, which equates *tosettingthettlto0xff
*/ if (match->value.ip_ttl == 0) {
NL_SET_ERR_MSG_MOD(extack, "decrementing hop_limit past 0 is not supported"); return -EOPNOTSUPP;
}
/* check that we do not decrement hoplimit twice */ if (!efx_tc_flower_action_order_ok(act,
EFX_TC_AO_DEC_TTL)) {
NL_SET_ERR_MSG_MOD(extack, "multiple dec ttl is not supported"); return -EOPNOTSUPP;
}
/* check pedit can be achieved with decrement action */
tr_ttl = match->value.ip_ttl - 1; if ((fa->mangle.val >> 24) == tr_ttl) {
act->do_ttl_dec = 1; return0;
}
fallthrough; default:
NL_SET_ERR_MSG_FMT_MOD(extack, "only support mangle on the hop_limit field"); return -EOPNOTSUPP;
} default:
NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled mangle htype %u for action rule",
fa->mangle.htype); return -EOPNOTSUPP;
} return0;
}
type = efx_tc_indr_netdev_type(net_dev); if (type == EFX_ENCAP_TYPE_NONE) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match on unsupported tunnel device"); return -EOPNOTSUPP;
}
rc = efx_mae_check_encap_type_supported(efx, type); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Firmware reports no support for %s encap match",
efx_tc_encap_type_name(type)); return rc;
} /* This is an Action Rule, so it needs a separate Encap Match in the *OuterRuletable.Insertthatnow.
*/
rc = efx_tc_flower_record_encap_match(efx, match, type,
EFX_TC_EM_DIRECT, 0, 0, extack); if (rc) return rc;
match->mask.recirc_id = 0xff; if (match->mask.ct_state_trk && match->value.ct_state_trk) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule can never match +trk");
rc = -EOPNOTSUPP; goto release_encap_match;
} /* LHS rules are always -trk, so we don't need to match on that */
match->mask.ct_state_trk = 0;
match->value.ct_state_trk = 0; /* We must inhibit match on TCP SYN/FIN/RST, so that SW can see *thepacketandupdatetheconntracktable. *OuterRuleswilldothatwithCT_TCP_FLAGS_INHIBIT,butAction *Rulesdon'thavethat;insteadtheysupportmatchingon *TCP_SYN_FIN_RST(akaTCP_INTERESTING_FLAGS),sousethat. *ThisisonlystrictlyneedediftherewillbeaDO_CTaction, *whichwedon'tknowyet,buttypicallytherewillbeandit's *simplernottobothercheckinghere.
*/
match->mask.tcp_syn_fin_rst = true;
rc = efx_mae_match_check_caps(efx, &match->mask, extack); if (rc) goto release_encap_match;
if (tc->common.chain_index) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule only allowed in chain 0"); return -EOPNOTSUPP;
}
if (!efx_tc_match_is_encap(&match->mask)) { /* This is not a tunnel decap rule, ignore it */
netif_dbg(efx, drv, efx->net_dev, "Ignoring foreign LHS filter without encap match\n"); return -EOPNOTSUPP;
}
if (efx_tc_flower_flhs_needs_ar(match)) return efx_tc_flower_replace_foreign_lhs_ar(efx, tc, fr, match,
net_dev);
type = efx_tc_indr_netdev_type(net_dev); if (type == EFX_ENCAP_TYPE_NONE) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match on unsupported tunnel device"); return -EOPNOTSUPP;
}
rc = efx_mae_check_encap_type_supported(efx, type); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Firmware reports no support for %s encap match",
efx_tc_encap_type_name(type)); return rc;
} /* Reserve the outer tuple with a pseudo Encap Match */
rc = efx_tc_flower_record_encap_match(efx, match, type,
EFX_TC_EM_PSEUDO_OR, 0, 0,
extack); if (rc) return rc;
if (match->mask.ct_state_trk && match->value.ct_state_trk) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule can never match +trk");
rc = -EOPNOTSUPP; goto release_encap_match;
} /* LHS rules are always -trk, so we don't need to match on that */
match->mask.ct_state_trk = 0;
match->value.ct_state_trk = 0;
rc = efx_tc_flower_translate_flhs_match(match); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule cannot match on inner fields"); goto release_encap_match;
}
rc = efx_mae_match_check_caps_lhs(efx, &match->mask, extack); if (rc) goto release_encap_match;
/* Parse match */
memset(&match, 0, sizeof(match));
rc = efx_tc_flower_parse_match(efx, fr, &match, extack); if (rc) return rc; /* The rule as given to us doesn't specify a source netdevice. *But,determiningwhetherpacketsfromaVFshouldmatchitis *complicated,soleavethosetothesoftwareslowpath:qualify *thefilterwithsourcem-port==wire.
*/
rc = efx_tc_flower_external_mport(efx, EFX_EFV_PF); if (rc < 0) {
NL_SET_ERR_MSG_MOD(extack, "Failed to identify ingress m-port for foreign filter"); return rc;
}
match.value.ingress_port = rc;
match.mask.ingress_port = ~0;
if (efx_tc_rule_is_lhs_rule(fr, &match)) return efx_tc_flower_replace_foreign_lhs(efx, tc, fr, &match,
net_dev);
if (tc->common.chain_index) { struct efx_tc_recirc_id *rid;
rid = efx_tc_get_recirc_id(efx, tc->common.chain_index, net_dev); if (IS_ERR(rid)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Failed to allocate a hardware recirculation ID for chain_index %u",
tc->common.chain_index); return PTR_ERR(rid);
}
match.rid = rid;
match.value.recirc_id = rid->fw_id;
}
match.mask.recirc_id = 0xff;
/* AR table can't match on DO_CT (+trk). But a commonly used pattern is *+trk+est,whichisstrictlyimpliedby+est,sorewriteittothat.
*/ if (match.mask.ct_state_trk && match.value.ct_state_trk &&
match.mask.ct_state_est && match.value.ct_state_est)
match.mask.ct_state_trk = 0; /* Thanks to CT_TCP_FLAGS_INHIBIT, packets with interesting flags could *match+trk-est(CT_HIT=0)despitebeingonanestablishedconnection. *Somake-estimply-tcp_syn_fin_rstmatchtoensurethesepackets *stillhitthesoftwarepath.
*/ if (match.mask.ct_state_est && !match.value.ct_state_est) { if (match.value.tcp_syn_fin_rst) { /* Can't offload this combination */
NL_SET_ERR_MSG_MOD(extack, "TCP flags and -est conflict for offload");
rc = -EOPNOTSUPP; goto release;
}
match.mask.tcp_syn_fin_rst = true;
}
flow_action_for_each(i, fa, &fr->action) { switch (fa->id) { case FLOW_ACTION_REDIRECT: case FLOW_ACTION_MIRRED: /* mirred means mirror here */
to_efv = efx_tc_flower_lookup_efv(efx, fa->dev); if (IS_ERR(to_efv)) continue;
found = true; break; default: break;
}
} if (!found) { /* We don't care. */
netif_dbg(efx, drv, efx->net_dev, "Ignoring foreign filter that doesn't egdev us\n");
rc = -EOPNOTSUPP; goto release;
}
rc = efx_mae_match_check_caps(efx, &match.mask, extack); if (rc) goto release;
if (efx_tc_match_is_encap(&match.mask)) { enum efx_encap_type type;
type = efx_tc_indr_netdev_type(net_dev); if (type == EFX_ENCAP_TYPE_NONE) {
NL_SET_ERR_MSG_MOD(extack, "Egress encap match on unsupported tunnel device");
rc = -EOPNOTSUPP; goto release;
}
rc = efx_mae_check_encap_type_supported(efx, type); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Firmware reports no support for %s encap match",
efx_tc_encap_type_name(type)); goto release;
}
rc = efx_tc_flower_record_encap_match(efx, &match, type,
EFX_TC_EM_DIRECT, 0, 0,
extack); if (rc) goto release;
} elseif (!tc->common.chain_index) { /* This is not a tunnel decap rule, ignore it */
netif_dbg(efx, drv, efx->net_dev, "Ignoring foreign filter without encap match\n");
rc = -EOPNOTSUPP; goto release;
}
/* Parse actions. For foreign rules we only support decap & redirect. *Seecorrespondingcodeinefx_tc_flower_replace()fortheoryof *operation&how'act'cursorisused.
*/
flow_action_for_each(i, fa, &fr->action) { struct efx_tc_action_set save;
switch (fa->id) { case FLOW_ACTION_REDIRECT: case FLOW_ACTION_MIRRED: /* See corresponding code in efx_tc_flower_replace() for *longexplanationsofwhat'sgoingonhere.
*/
save = *act; if (fa->hw_stats) { struct efx_tc_counter_index *ctr;
if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')",
fa->hw_stats);
rc = -EOPNOTSUPP; goto release;
} if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_COUNT)) {
NL_SET_ERR_MSG_MOD(extack, "Count action violates action order (can't happen)");
rc = -EOPNOTSUPP; goto release;
}
ctr = efx_tc_flower_get_counter_index(efx,
tc->cookie,
EFX_TC_COUNTER_TYPE_AR); if (IS_ERR(ctr)) {
rc = PTR_ERR(ctr);
NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter"); goto release;
}
act->count = ctr;
INIT_LIST_HEAD(&act->count_user);
}
if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DELIVER)) { /* can't happen */
rc = -EOPNOTSUPP;
NL_SET_ERR_MSG_MOD(extack, "Deliver action violates action order (can't happen)"); goto release;
}
to_efv = efx_tc_flower_lookup_efv(efx, fa->dev); /* PF implies egdev is us, in which case we really *wanttodelivertotheuplink(becausethisisan *ingressfilter).Ifwedon'trecognisetheegdev *atall,thenwe'dbettertrapsoSWcanhandleit.
*/ if (IS_ERR(to_efv))
to_efv = EFX_EFV_PF; if (to_efv == EFX_EFV_PF) { if (uplinked) break;
uplinked = true;
}
rc = efx_tc_flower_internal_mport(efx, to_efv); if (rc < 0) {
NL_SET_ERR_MSG_MOD(extack, "Failed to identify egress m-port"); goto release;
}
act->dest_mport = rc;
act->deliver = 1;
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (mirred)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act = NULL; if (fa->id == FLOW_ACTION_REDIRECT) break; /* end of the line */ /* Mirror, so continue on with saved act */
act = kzalloc(sizeof(*act), GFP_USER); if (!act) {
rc = -ENOMEM; goto release;
}
*act = save; break; case FLOW_ACTION_TUNNEL_DECAP: if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_DECAP)) {
rc = -EINVAL;
NL_SET_ERR_MSG_MOD(extack, "Decap action violates action order"); goto release;
}
act->decap = 1; /* If we previously delivered/trapped to uplink, now *thatwe'vedecappedwe'llwantanothercopyifwe *trytodeliver/traptouplinkagain.
*/
uplinked = false; break; default:
NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled action %u",
fa->id);
rc = -EOPNOTSUPP; goto release;
}
}
if (act) { if (!uplinked) { /* Not shot/redirected, so deliver to default dest (which is *theuplink,asthisisaningressfilter)
*/
efx_mae_mport_uplink(efx, &act->dest_mport);
act->deliver = 1;
}
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (deliver)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act = NULL; /* Prevent double-free in error path */
}
rc = efx_mae_alloc_action_set_list(efx, &rule->acts); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set list to hw"); goto release;
}
rc = efx_mae_insert_rule(efx, &rule->match, EFX_TC_PRIO_TC,
rule->acts.fw_id, &rule->fw_id); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to insert rule in hw"); goto release_acts;
} return0;
release_acts:
efx_mae_free_action_set_list(efx, &rule->acts);
release: /* We failed to insert the rule, so free up any entries we created in *subsidiarytables.
*/ if (match.rid)
efx_tc_put_recirc_id(efx, match.rid); if (act)
efx_tc_free_action_set(efx, act, false); if (rule) { if (!old)
rhashtable_remove_fast(&efx->tc->match_action_ht,
&rule->linkage,
efx_tc_match_action_ht_params);
efx_tc_free_action_set_list(efx, &rule->acts, false);
}
kfree(rule); if (match.encap)
efx_tc_flower_release_encap_match(efx, match.encap); return rc;
}
if (tc->common.chain_index) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule only allowed in chain 0"); return -EOPNOTSUPP;
}
if (match->mask.ct_state_trk && match->value.ct_state_trk) {
NL_SET_ERR_MSG_MOD(extack, "LHS rule can never match +trk"); return -EOPNOTSUPP;
} /* LHS rules are always -trk, so we don't need to match on that */
match->mask.ct_state_trk = 0;
match->value.ct_state_trk = 0;
rc = efx_mae_match_check_caps_lhs(efx, &match->mask, extack); if (rc) return rc;
if (!tc_can_offload_extack(efx->net_dev, extack)) return -EOPNOTSUPP; if (WARN_ON(!efx->tc)) return -ENETDOWN; if (WARN_ON(!efx->tc->up)) return -ENETDOWN;
from_efv = efx_tc_flower_lookup_efv(efx, net_dev); if (IS_ERR(from_efv)) { /* Not from our PF or representors, so probably a tunnel dev */ return efx_tc_flower_replace_foreign(efx, net_dev, tc);
}
if (efv != from_efv) { /* can't happen */
NL_SET_ERR_MSG_FMT_MOD(extack, "for %s efv is %snull but from_efv is %snull (can't happen)",
netdev_name(net_dev), efv ? "non-" : "",
from_efv ? "non-" : ""); return -EINVAL;
}
/* Parse match */
memset(&match, 0, sizeof(match));
rc = efx_tc_flower_external_mport(efx, from_efv); if (rc < 0) {
NL_SET_ERR_MSG_MOD(extack, "Failed to identify ingress m-port"); return rc;
}
match.value.ingress_port = rc;
match.mask.ingress_port = ~0;
rc = efx_tc_flower_parse_match(efx, fr, &match, extack); if (rc) return rc; if (efx_tc_match_is_encap(&match.mask)) {
NL_SET_ERR_MSG_MOD(extack, "Ingress enc_key matches not supported"); return -EOPNOTSUPP;
}
if (efx_tc_rule_is_lhs_rule(fr, &match)) return efx_tc_flower_replace_lhs(efx, tc, fr, &match, efv,
net_dev);
/* chain_index 0 is always recirc_id 0 (and does not appear in recirc_ht). *Conveniently,match.rid==NULLandmatch.value.recirc_id==0owing *totheinitialmemset(),sowedon'tneedtodoanythinginthatcase.
*/ if (tc->common.chain_index) { struct efx_tc_recirc_id *rid;
/* Note regarding passed net_dev: *VFrepsandPFcansharechainnamespace,astheyhave *distinctingress_mports.Sowedon'tneedtoburnan *extrarecirc_idifbothusethesamechain_index. *(Strictlyspeaking,wecouldgiveeachVFrepitsown *recirc_idnamespacethatdoesn'ttakeIDsawayfromthe *PF,butthatwouldrequireabunchofadditionalIDAs- *oneforeachrepresentor-andthat'snotlikelytobe *themaincauseofrecirc_idexhaustionanyway.)
*/
rid = efx_tc_get_recirc_id(efx, tc->common.chain_index,
efx->net_dev); if (IS_ERR(rid)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "Failed to allocate a hardware recirculation ID for chain_index %u",
tc->common.chain_index); return PTR_ERR(rid);
}
match.rid = rid;
match.value.recirc_id = rid->fw_id;
}
match.mask.recirc_id = 0xff;
/* AR table can't match on DO_CT (+trk). But a commonly used pattern is *+trk+est,whichisstrictlyimpliedby+est,sorewriteittothat.
*/ if (match.mask.ct_state_trk && match.value.ct_state_trk &&
match.mask.ct_state_est && match.value.ct_state_est)
match.mask.ct_state_trk = 0; /* Thanks to CT_TCP_FLAGS_INHIBIT, packets with interesting flags could *match+trk-est(CT_HIT=0)despitebeingonanestablishedconnection. *Somake-estimply-tcp_syn_fin_rstmatchtoensurethesepackets *stillhitthesoftwarepath.
*/ if (match.mask.ct_state_est && !match.value.ct_state_est) { if (match.value.tcp_syn_fin_rst) { /* Can't offload this combination */
rc = -EOPNOTSUPP; goto release;
}
match.mask.tcp_syn_fin_rst = true;
}
rc = efx_mae_match_check_caps(efx, &match.mask, extack); if (rc) goto release;
/* Currently the only actions that want stats are *mirredandgact(ok,shot,trap,goto-chain),which *meanswewantstatsjustbeforedelivery.Also, *notethattunnel_keysetshouldn'tchangethelength *—it'sonlythesubsequentmirredthatdoesthat, *andthestatsaretaken_before_themirredaction *happens.
*/ if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_COUNT)) { /* All supported actions that count either steal *(gactshot,mirredredirect)orcloneact *(mirredmirror),soweshouldnevergettwo *countactionsononeaction_set.
*/
NL_SET_ERR_MSG_MOD(extack, "Count-action conflict (can't happen)");
rc = -EOPNOTSUPP; goto release;
}
if (!(fa->hw_stats & FLOW_ACTION_HW_STATS_DELAYED)) {
NL_SET_ERR_MSG_FMT_MOD(extack, "hw_stats_type %u not supported (only 'delayed')",
fa->hw_stats);
rc = -EOPNOTSUPP; goto release;
}
ctr = efx_tc_flower_get_counter_index(efx, tc->cookie,
EFX_TC_COUNTER_TYPE_AR); if (IS_ERR(ctr)) {
rc = PTR_ERR(ctr);
NL_SET_ERR_MSG_MOD(extack, "Failed to obtain a counter"); goto release;
}
act->count = ctr;
INIT_LIST_HEAD(&act->count_user);
}
switch (fa->id) { case FLOW_ACTION_DROP:
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (drop)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act = NULL; /* end of the line */ break; case FLOW_ACTION_REDIRECT: case FLOW_ACTION_MIRRED:
save = *act;
if (encap_info) { struct efx_tc_encap_action *encap;
if (!efx_tc_flower_action_order_ok(act,
EFX_TC_AO_ENCAP)) {
rc = -EOPNOTSUPP;
NL_SET_ERR_MSG_MOD(extack, "Encap action violates action order"); goto release;
}
encap = efx_tc_flower_create_encap_md(
efx, encap_info, fa->dev, extack); if (IS_ERR_OR_NULL(encap)) {
rc = PTR_ERR(encap); if (!rc)
rc = -EIO; /* arbitrary */ goto release;
}
act->encap_md = encap;
list_add_tail(&act->encap_user, &encap->users);
act->dest_mport = encap->dest_mport;
act->deliver = 1; if (act->count && !WARN_ON(!act->count->cnt)) { /* This counter is used by an encap *action,whichneedsareferenceback *soitcanprodneighbouringwhenever *trafficisseen.
*/
spin_lock_bh(&act->count->cnt->lock);
list_add_tail(&act->count_user,
&act->count->cnt->users);
spin_unlock_bh(&act->count->cnt->lock);
}
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (encap)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act->user = &rule->acts;
act = NULL; if (fa->id == FLOW_ACTION_REDIRECT) break; /* end of the line */ /* Mirror, so continue on with saved act */
save.count = NULL;
act = kzalloc(sizeof(*act), GFP_USER); if (!act) {
rc = -ENOMEM; goto release;
}
*act = save; break;
}
to_efv = efx_tc_flower_lookup_efv(efx, fa->dev); if (IS_ERR(to_efv)) {
NL_SET_ERR_MSG_MOD(extack, "Mirred egress device not on switch");
rc = PTR_ERR(to_efv); goto release;
}
rc = efx_tc_flower_external_mport(efx, to_efv); if (rc < 0) {
NL_SET_ERR_MSG_MOD(extack, "Failed to identify egress m-port"); goto release;
}
act->dest_mport = rc;
act->deliver = 1;
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (mirred)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act = NULL; if (fa->id == FLOW_ACTION_REDIRECT) break; /* end of the line */ /* Mirror, so continue on with saved act */
save.count = NULL;
act = kzalloc(sizeof(*act), GFP_USER); if (!act) {
rc = -ENOMEM; goto release;
}
*act = save; break; case FLOW_ACTION_VLAN_POP: if (act->vlan_push) {
act->vlan_push--;
} elseif (efx_tc_flower_action_order_ok(act, EFX_TC_AO_VLAN_POP)) {
act->vlan_pop++;
} else {
NL_SET_ERR_MSG_MOD(extack, "More than two VLAN pops, or action order violated");
rc = -EINVAL; goto release;
} break; case FLOW_ACTION_VLAN_PUSH: if (!efx_tc_flower_action_order_ok(act, EFX_TC_AO_VLAN_PUSH)) {
rc = -EINVAL;
NL_SET_ERR_MSG_MOD(extack, "More than two VLAN pushes, or action order violated"); goto release;
}
tci = fa->vlan.vid & VLAN_VID_MASK;
tci |= fa->vlan.prio << VLAN_PRIO_SHIFT;
act->vlan_tci[act->vlan_push] = cpu_to_be16(tci);
act->vlan_proto[act->vlan_push] = fa->vlan.proto;
act->vlan_push++; break; case FLOW_ACTION_ADD:
rc = efx_tc_pedit_add(efx, act, fa, extack); if (rc < 0) goto release; break; case FLOW_ACTION_MANGLE:
rc = efx_tc_mangle(efx, act, fa, &mung, extack, &match); if (rc < 0) goto release; break; case FLOW_ACTION_TUNNEL_ENCAP: if (encap_info) { /* Can't specify encap multiple times. *Ifyouwanttooverwriteanexisting *encap_info,useanintervening *FLOW_ACTION_TUNNEL_DECAPtoclearit.
*/
NL_SET_ERR_MSG_MOD(extack, "Tunnel key set when already set");
rc = -EINVAL; goto release;
} if (!fa->tunnel) {
NL_SET_ERR_MSG_MOD(extack, "Tunnel key set is missing key");
rc = -EOPNOTSUPP; goto release;
}
encap_info = fa->tunnel; break; case FLOW_ACTION_TUNNEL_DECAP: if (encap_info) {
encap_info = NULL; break;
} /* Since we don't support enc_key matches on ingress *(andifwedidthere'dbenotunnel-devicetogive *usatype),wecan'toffloadadecapthat'snot *justundoingapreviousencapaction.
*/
NL_SET_ERR_MSG_MOD(extack, "Cannot offload tunnel decap action without tunnel device");
rc = -EOPNOTSUPP; goto release; case FLOW_ACTION_CT: if (fa->ct.action != TCA_CT_ACT_NAT) {
rc = -EOPNOTSUPP;
NL_SET_ERR_MSG_FMT_MOD(extack, "Can only offload CT 'nat' action in RHS rules, not %d", fa->ct.action); goto release;
}
act->do_nat = 1; break; default:
NL_SET_ERR_MSG_FMT_MOD(extack, "Unhandled action %u",
fa->id);
rc = -EOPNOTSUPP; goto release;
}
}
rc = efx_tc_incomplete_mangle(&mung, extack); if (rc < 0) goto release; if (act) { /* Not shot/redirected, so deliver to default dest */ if (from_efv == EFX_EFV_PF) /* Rule applies to traffic from the wire, *anddefaultdestisthusthePF
*/
efx_mae_mport_uplink(efx, &act->dest_mport); else /* Representor, so rule applies to traffic from *representee,anddefaultdestisthustherep. *Allrepsusethesamemportfordelivery
*/
efx_mae_mport_mport(efx, efx->tc->reps_mport_id,
&act->dest_mport);
act->deliver = 1;
rc = efx_mae_alloc_action_set(efx, act); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set to hw (deliver)"); goto release;
}
list_add_tail(&act->list, &rule->acts.list);
act = NULL; /* Prevent double-free in error path */
}
rc = efx_mae_alloc_action_set_list(efx, &rule->acts); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to write action set list to hw"); goto release;
} if (from_efv == EFX_EFV_PF) /* PF netdev, so rule applies to traffic from wire */
rule->fallback = &efx->tc->facts.pf; else /* repdev, so rule applies to traffic from representee */
rule->fallback = &efx->tc->facts.reps; if (!efx_tc_check_ready(efx, rule)) {
netif_dbg(efx, drv, efx->net_dev, "action not ready for hw\n");
acts_id = rule->fallback->fw_id;
} else {
netif_dbg(efx, drv, efx->net_dev, "ready for hw\n");
acts_id = rule->acts.fw_id;
}
rc = efx_mae_insert_rule(efx, &rule->match, EFX_TC_PRIO_TC,
acts_id, &rule->fw_id); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to insert rule in hw"); goto release_acts;
} return0;
release_acts:
efx_mae_free_action_set_list(efx, &rule->acts);
release: /* We failed to insert the rule, so free up any entries we created in *subsidiarytables.
*/ if (match.rid)
efx_tc_put_recirc_id(efx, match.rid); if (act)
efx_tc_free_action_set(efx, act, false); if (rule) { if (!old)
rhashtable_remove_fast(&efx->tc->match_action_ht,
&rule->linkage,
efx_tc_match_action_ht_params);
efx_tc_free_action_set_list(efx, &rule->acts, false);
}
kfree(rule); return rc;
}
lhs_rule = rhashtable_lookup_fast(&efx->tc->lhs_rule_ht, &tc->cookie,
efx_tc_lhs_rule_ht_params); if (lhs_rule) { /* Remove it from HW */
efx_mae_remove_lhs_rule(efx, lhs_rule); /* Delete it from SW */
efx_tc_flower_release_lhs_actions(efx, &lhs_rule->lhs_act);
rhashtable_remove_fast(&efx->tc->lhs_rule_ht, &lhs_rule->linkage,
efx_tc_lhs_rule_ht_params); if (lhs_rule->match.encap)
efx_tc_flower_release_encap_match(efx, lhs_rule->match.encap);
netif_dbg(efx, drv, efx->net_dev, "Removed (lhs) filter %lx\n",
lhs_rule->cookie);
kfree(lhs_rule); return0;
}
rule = rhashtable_lookup_fast(&efx->tc->match_action_ht, &tc->cookie,
efx_tc_match_action_ht_params); if (!rule) { /* Only log a message if we're the ingress device. Otherwise *it'saforeignfilterandwemightjustnothavebeen *interested(e.g.wemightnothavebeentheegressdevice *either).
*/ if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev)))
netif_warn(efx, drv, efx->net_dev, "Filter %lx not found to remove\n", tc->cookie);
NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules"); return -ENOENT;
}
/* Remove it from HW */
efx_tc_delete_rule(efx, rule); /* Delete it from SW */
rhashtable_remove_fast(&efx->tc->match_action_ht, &rule->linkage,
efx_tc_match_action_ht_params);
netif_dbg(efx, drv, efx->net_dev, "Removed filter %lx\n", rule->cookie);
kfree(rule); return0;
}
ctr = efx_tc_flower_find_counter_index(efx, tc->cookie); if (!ctr) { /* See comment in efx_tc_flower_destroy() */ if (!IS_ERR(efx_tc_flower_lookup_efv(efx, net_dev))) if (net_ratelimit())
netif_warn(efx, drv, efx->net_dev, "Filter %lx not found for stats\n",
tc->cookie);
NL_SET_ERR_MSG_MOD(extack, "Flow cookie not found in offloaded rules"); return -ENOENT;
} if (WARN_ON(!ctr->cnt)) /* can't happen */ return -EIO;
cnt = ctr->cnt;
spin_lock_bh(&cnt->lock); /* Report only new pkts/bytes since last time TC asked */
packets = cnt->packets;
bytes = cnt->bytes;
flow_stats_update(&tc->stats, bytes - cnt->old_bytes,
packets - cnt->old_packets, 0, cnt->touched,
FLOW_ACTION_HW_STATS_DELAYED);
cnt->old_packets = packets;
cnt->old_bytes = bytes;
spin_unlock_bh(&cnt->lock); return0;
}
int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev, struct flow_cls_offload *tc, struct efx_rep *efv)
{ int rc;
void efx_tc_remove_rep_filters(struct efx_nic *efx)
{ if (efx->type->is_vf) return; if (!efx->tc) return; if (efx->tc->reps_filter_mc >= 0)
efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_mc);
efx->tc->reps_filter_mc = -1; if (efx->tc->reps_filter_uc >= 0)
efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_uc);
efx->tc->reps_filter_uc = -1;
}
int efx_init_tc(struct efx_nic *efx)
{ int rc;
rc = efx_mae_get_caps(efx, efx->tc->caps); if (rc) return rc; if (efx->tc->caps->match_field_count > MAE_NUM_FIELDS) /* Firmware supports some match fields the driver doesn't know *about.Notfatal,unlessanyofthosefieldsarerequired *(MAE_FIELD_SUPPORTED_MATCH_ALWAYS)butifsowedon'tknow.
*/
netif_warn(efx, probe, efx->net_dev, "FW reports additional match fields %u\n",
efx->tc->caps->match_field_count); if (efx->tc->caps->action_prios < EFX_TC_PRIO__NUM) {
netif_err(efx, probe, efx->net_dev, "Too few action prios supported (have %u, need %u)\n",
efx->tc->caps->action_prios, EFX_TC_PRIO__NUM); return -EIO;
}
rc = efx_tc_configure_default_rule_pf(efx); if (rc) return rc;
rc = efx_tc_configure_default_rule_wire(efx); if (rc) return rc;
rc = efx_tc_configure_rep_mport(efx); if (rc) return rc;
rc = efx_tc_configure_fallback_acts_pf(efx); if (rc) return rc;
rc = efx_tc_configure_fallback_acts_reps(efx); if (rc) return rc;
rc = efx_mae_get_tables(efx); if (rc) return rc;
rc = flow_indr_dev_register(efx_tc_indr_setup_cb, efx); if (rc) goto out_free;
efx->tc->up = true; return0;
out_free:
efx_mae_free_tables(efx); return rc;
}
void efx_fini_tc(struct efx_nic *efx)
{ /* We can get called even if efx_init_struct_tc() failed */ if (!efx->tc) return; if (efx->tc->up)
flow_indr_dev_unregister(efx_tc_indr_setup_cb, efx, efx_tc_block_unbind);
efx_tc_deconfigure_rep_mport(efx);
efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.pf);
efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.wire);
efx_tc_deconfigure_fallback_acts(efx, &efx->tc->facts.pf);
efx_tc_deconfigure_fallback_acts(efx, &efx->tc->facts.reps);
efx->tc->up = false;
efx_mae_free_tables(efx);
}
/* At teardown time, all TC filter rules (and thus all resources they created) *shouldalreadyhavebeenremoved.Ifwefindanyinourhashtables,makea *cursoryattempttocleanupthesoftwareside.
*/ staticvoid efx_tc_encap_match_free(void *ptr, void *__unused)
{ struct efx_tc_encap_match *encap = ptr;
netif_err(efx, drv, efx->net_dev, "tc lhs_rule %lx still present at teardown, removing\n",
rule->cookie);
if (rule->lhs_act.zone)
efx_tc_ct_unregister_zone(efx, rule->lhs_act.zone); if (rule->lhs_act.count)
efx_tc_flower_put_counter_index(efx, rule->lhs_act.count);
efx_mae_remove_lhs_rule(efx, rule);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.101Bemerkung:
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.