Bridge join, leave and flag changes rewrite the isolation masks, so a redirect rule that was trapped because of isolation may become reachable again, and a reachable one may become trapped. Reload such non-skip_sw redirect rules accordingly. skip_sw rules are not touched at all: they cannot be degraded, port_bridge_leave() cannot be rejected (return value is void), nor can tc be told which rule got invalidated. Fixes: 8eb9e7520b17 ("net: dsa: yt921x: Add ACL support") Signed-off-by: David Yang --- drivers/net/dsa/motorcomm/chip.c | 33 +++++++++++++ drivers/net/dsa/motorcomm/tc.c | 79 ++++++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 2 + 3 files changed, 114 insertions(+) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index 0bc5da2b80d7..a5e673a69355 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1398,6 +1398,7 @@ static int yt921x_bridge_flags(struct yt921x_priv *priv, int port, struct switchdev_brport_flags flags) { + struct device *dev = yt921x_priv_to_device(priv); u32 mask; int res; @@ -1431,6 +1432,14 @@ yt921x_bridge_flags(struct yt921x_priv *priv, int port, if (res) return res; } + + res = yt921x_acl_recompute(priv, port); + if (res) { + dev_err(dev, + "Failed to refresh ACL rules for port %d: %i\n", + port, res); + res = 0; + } } return 0; @@ -1531,7 +1540,19 @@ yt921x_dsa_port_bridge_leave(struct dsa_switch *ds, int port, return; mutex_lock(&priv->reg_lock); + res = yt921x_bridge_leave(priv, port); + if (res) + goto end; + + res = yt921x_acl_recompute(priv, port); + if (res) { + dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n", + port, res); + res = 0; + } + +end: mutex_unlock(&priv->reg_lock); if (res) @@ -1545,6 +1566,7 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack) { struct yt921x_priv *priv = dsa_to_yt921x_priv(ds); + struct device *dev = yt921x_priv_to_device(priv); struct yt921x_port *pp = &priv->ports[port]; struct net_device *brport_dev; struct dsa_port *dp; @@ -1564,6 +1586,17 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, pp->isolated = br_port_flag_is_set(brport_dev, BR_ISOLATED); pp->hairpin = br_port_flag_is_set(brport_dev, BR_HAIRPIN_MODE); res = yt921x_bridge_join(priv, port, ports_mask); + if (res) + goto end; + + res = yt921x_acl_recompute(priv, port); + if (res) { + dev_err(dev, "Failed to refresh ACL rules for port %d: %i\n", + port, res); + res = 0; + } + +end: mutex_unlock(&priv->reg_lock); return res; diff --git a/drivers/net/dsa/motorcomm/tc.c b/drivers/net/dsa/motorcomm/tc.c index 9a19ee7d4358..210f7af3a206 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1393,6 +1393,85 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) return 0; } +static int +yt921x_acl_recompute_rule(struct yt921x_priv *priv, int port, + unsigned int entid) +{ + const struct yt921x_acl_blk *aclblk; + struct yt921x_acl_rule *aclrule; + unsigned int blkid; + unsigned int binid; + unsigned long dsts; + unsigned long srcs; + unsigned int o; + bool assisting; + int res; + + blkid = entid / YT921X_ACL_ENT_PER_BLK; + binid = entid % YT921X_ACL_ENT_PER_BLK; + aclblk = priv->acl_blks[blkid]; + aclrule = aclblk->rules[binid]; + + if (!(aclrule->action[2] & YT921X_ACL_ACTc_FWD_EN) || + (aclrule->action[2] & YT921X_ACL_ACTc_FWD_M) != + YT921X_ACL_ACTc_FWD_REDIR) + return 0; + + srcs = FIELD_GET(YT921X_ACL_KEYb_SPORTS_M, aclrule->entries[0].key[1]); + dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M, + aclrule->action[2]); + if (!((srcs | dsts) & BIT(port))) + return 0; + + assisting = false; + for_each_set_bit(o, &srcs, YT921X_PORT_NUM) + if (dsts & priv->ports[o].isolation_mask) { + assisting = true; + break; + } + + if (aclrule->sw_assisting != assisting) { + aclrule->sw_assisting = assisting; + res = yt921x_acl_commit(priv, entid, aclrule->mask); + if (res) + return res; + } + + return 0; +} + +/* Only non-skip_sw rules are refreshes; skip_sw rules cannot be degraded, + * port_bridge_leave() cannot be rejected (return value is void), nor can tc be + * told which rule got invalidated. + */ +int yt921x_acl_recompute(struct yt921x_priv *priv, int port) +{ + int res; + + for (unsigned int blkid = 0; blkid < YT921X_ACL_BLK_NUM; blkid++) { + const struct yt921x_acl_blk *aclblk = priv->acl_blks[blkid]; + + if (!aclblk) + continue; + + for (unsigned int i = 0; i < YT921X_ACL_ENT_PER_BLK; i++) { + struct yt921x_acl_rule *aclrule; + unsigned int entid; + + aclrule = aclblk->rules[i]; + if (!aclrule || !aclrule->sw_assisted) + continue; + + entid = YT921X_ACL_ENT_PER_BLK * blkid + i; + res = yt921x_acl_recompute_rule(priv, port, entid); + if (res) + return res; + } + } + + return 0; +} + static int yt921x_acl_del(struct yt921x_priv *priv, enum tc_setup_type type, unsigned long tag, u16 ports_mask) diff --git a/drivers/net/dsa/motorcomm/tc.h b/drivers/net/dsa/motorcomm/tc.h index 81c29a8eec5a..be4c258873b8 100644 --- a/drivers/net/dsa/motorcomm/tc.h +++ b/drivers/net/dsa/motorcomm/tc.h @@ -371,6 +371,8 @@ yt921x_dsa_port_policer_add(struct dsa_switch *ds, int port, int yt921x_dsa_port_setup_tc(struct dsa_switch *ds, int port, enum tc_setup_type type, void *type_data); + +int yt921x_acl_recompute(struct yt921x_priv *priv, int port); int yt921x_dsa_cls_flower_del(struct dsa_switch *ds, int port, struct flow_cls_offload *cls, bool ingress); -- 2.53.0