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 <mmya…@gmail.com> --- drivers/net/dsa/motorcomm/chip.c | 34 ++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.c | 50 ++++++++++++++++++++++++++++++++ drivers/net/dsa/motorcomm/tc.h | 2 ++ 3 files changed, 86 insertions(+) diff --git a/drivers/net/dsa/motorcomm/chip.c b/drivers/net/dsa/motorcomm/chip.c index bd89823aac55..7282bc0693eb 100644 --- a/drivers/net/dsa/motorcomm/chip.c +++ b/drivers/net/dsa/motorcomm/chip.c @@ -1401,6 +1401,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); struct yt921x_port *pp = &priv->ports[port]; bool do_flush; u32 mask; @@ -1446,6 +1447,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; @@ -1492,7 +1501,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) @@ -1506,6 +1527,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; @@ -1522,9 +1544,21 @@ yt921x_dsa_port_bridge_join(struct dsa_switch *ds, int port, brport_dev = dsa_port_to_bridge_port(dp); mutex_lock(&priv->reg_lock); + 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 20edfd53b230..146db2a37c26 100644 --- a/drivers/net/dsa/motorcomm/tc.c +++ b/drivers/net/dsa/motorcomm/tc.c @@ -1394,6 +1394,56 @@ yt921x_acl_commit(struct yt921x_priv *priv, unsigned int entid, u8 entsmask) 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; + u32 *action; + u32 dsts; + int src; + + aclrule = aclblk->rules[i]; + if (!aclrule || !aclrule->sw_assisted) + continue; + + action = aclrule->action; + if (!(action[2] & YT921X_ACL_ACTc_FWD_EN) || + (action[2] & YT921X_ACL_ACTc_FWD_M) != + YT921X_ACL_ACTc_FWD_REDIR) + continue; + + src = ffs(aclrule->entries[0].key[1] & + YT921X_ACL_KEYb_SPORTS_M) - 1; + dsts = FIELD_GET(YT921X_ACL_ACTc_FWD_REDIR_DPORTS_M, + action[2]); + if (src != port && !(dsts & BIT(port))) + continue; + + aclrule->sw_assisting = + !!(dsts & priv->ports[src].isolation_mask); + entid = YT921X_ACL_ENT_PER_BLK * blkid + i; + res = yt921x_acl_commit(priv, entid, aclrule->mask); + 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