Port isolation takes after REDIR judgment, but software delivers such frames. Either route such rules to the software, or reject offloading. Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support") Signed-off-by: David Yang <mmya…@gmail.com> --- drivers/net/dsa/motorcomm/chip.c | 9 +++++++++ drivers/net/dsa/motorcomm/chip.h | 2 ++ drivers/net/dsa/motorcomm/tc.c | 33 ++++++++++++++++++++++++++++++-- drivers/net/dsa/motorcomm/tc.h | 6 +++++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 567ce8716acd..a71a8dd5dc63 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1412,6 +1412,15 @@ yt921x_isolation_calc_ports(struct yt921x_priv *priv, u16 *ports_maskp, } } +u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port) +{ + u16 isolation_masks[YT921X_PORT_NUM]; + u16 ports_mask = BIT(port); + + yt921x_isolation_calc_ports(priv, &ports_mask, isolation_masks); + return isolation_masks[port]; +} + static int yt921x_isolation_commit(struct yt921x_priv *priv, u16 ports_mask, const u16 *isolation_masks) diff --git a/drivers/net/dsa/motorcomm/chip.h b/drivers/net/dsa/motorcomm/chip.h index 22381009db51..749fe12fa852 100644 --- a/drivers/net/dsa/motorcomm/chip.h +++ b/drivers/net/dsa/motorcomm/chip.h @@ -559,4 +559,6 @@ static inline u32 ethaddr_lo2_to_u32(const unsigned char *addr) return (addr[4] << 8) | addr[5]; } +u16 yt921x_isolation_calc_port(struct yt921x_priv *priv, int port); + #endif diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index e3f057ed580f..e65baccda99e 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1041,6 +1041,8 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, int res; memset(action, 0, 3 * sizeof(*action)); + ruleext->r.sw_assisting = false; + flow_action_for_each(i, act, flow_action) { /* The flow action entry carries no mirred control, so there * is no way to tell whether software would continue past a @@ -1072,6 +1074,21 @@ yt921x_acl_rule_ext_parse_flow_action(struct yt921x_acl_rule_ext *ruleext, goto fallback; } + /* Port isolation takes after REDIR judgment, but + * software delivers such frames. + */ + if (yt921x_isolation_calc_port(priv, port) & + BIT(to_dp->index)) { + if (cls->common.skip_sw) { + if (to_dp->index == port) + reason = "Redirect to self, which is not hairpinning"; + else + reason = "Redirect target isolated, or not in the same bridge"; + goto fallback; + } + ruleext->r.sw_assisting = true; + } + action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_REDIR | YT921X_ACL_ACTc_FWD_REDIR_DPORTn(to_dp->index); @@ -1301,8 +1318,19 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) aclrule = aclblk->rules[binid]; /* Write actions */ - res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), - aclrule ? aclrule->action : zeros); + if (!aclrule || !aclrule->sw_assisting) { + res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), + aclrule ? aclrule->action : zeros); + } else { + u32 action[3]; + + memcpy(action, aclrule->action, sizeof(action)); + action[2] &= ~YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M & + ~YT921X_ACL_ACTc_FWD_M; + action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_TRAP; + + res = yt921x_reg96_write(priv, YT921X_ACLn_ACT(entid), action); + } if (res) return res; @@ -1502,6 +1530,7 @@ yt921x_acl_add(struct yt921x_priv *priv, ~YT921X_ACL_ACTc_FWD_M; aclrule->action[2] |= YT921X_ACL_ACTc_FWD_EN | YT921X_ACL_ACTc_FWD_TRAP; + aclrule->sw_assisting = false; } if (meterid < YT921X_METER_NUM) aclrule->action[0] |= YT921X_ACL_ACTa_METER_ID(meterid); diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h index cc53f148d690..81c29a8eec5a 100644 --- a/drivers/net/dsa/motorcomm/tc.h +++ b/drivers/net/dsa/motorcomm/tc.h @@ -349,7 +349,11 @@ struct yt921x_acl_rule { enum tc_setup_type type; u32 action[3]; - bool sw_assisted; + bool sw_assisted:1; + /* not a TRAP rule, but installed as trapped as some conditions are not + * met + */ + bool sw_assisting:1; u8 mask; struct yt921x_acl_entry entries[YT921X_ACL_ENT_PER_BLK];
-- 2.53.0