Commit 6c05561c authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: dsa: bcm_sf2: Fix IPv6 rules and chain ID

We had several issues that would make the programming of IPv6 rules both
inconsistent and error prone:

- the chain ID that we would be asking the hardware to put in the
  packet's Broadcom tag would be off by one, it would return one of the
  two indexes, but not the one user-space specified

- when an user specified a particular location to insert a CFP rule at,
  we would not be returning the same index, which would be confusing if
  nothing else

- finally, like IPv4, it would be possible to overflow the last entry by
  re-programming it

Fix this by swapping the usage of rule_index[0] and rule_index[1] where
relevant in order to return a consistent and correct user-space
experience.

Fixes: ba0696c2 ("net: dsa: bcm_sf2: Add support for IPv6 CFP rules")
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 43a5e00f
...@@ -565,19 +565,21 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, ...@@ -565,19 +565,21 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
* first half because the HW search is by incrementing addresses. * first half because the HW search is by incrementing addresses.
*/ */
if (fs->location == RX_CLS_LOC_ANY) if (fs->location == RX_CLS_LOC_ANY)
rule_index[0] = find_first_zero_bit(priv->cfp.used, rule_index[1] = find_first_zero_bit(priv->cfp.used,
bcm_sf2_cfp_rule_size(priv)); priv->num_cfp_rules);
else else
rule_index[0] = fs->location; rule_index[1] = fs->location;
if (rule_index[1] > bcm_sf2_cfp_rule_size(priv))
return -ENOSPC;
/* Flag it as used (cleared on error path) such that we can immediately /* Flag it as used (cleared on error path) such that we can immediately
* obtain a second one to chain from. * obtain a second one to chain from.
*/ */
set_bit(rule_index[0], priv->cfp.used); set_bit(rule_index[1], priv->cfp.used);
rule_index[1] = find_first_zero_bit(priv->cfp.used, rule_index[0] = find_first_zero_bit(priv->cfp.used,
bcm_sf2_cfp_rule_size(priv)); priv->num_cfp_rules);
if (rule_index[1] > bcm_sf2_cfp_rule_size(priv)) { if (rule_index[0] > bcm_sf2_cfp_rule_size(priv)) {
ret = -ENOSPC; ret = -ENOSPC;
goto out_err; goto out_err;
} }
...@@ -715,14 +717,14 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port, ...@@ -715,14 +717,14 @@ static int bcm_sf2_cfp_ipv6_rule_set(struct bcm_sf2_priv *priv, int port,
/* Flag the second half rule as being used now, return it as the /* Flag the second half rule as being used now, return it as the
* location, and flag it as unique while dumping rules * location, and flag it as unique while dumping rules
*/ */
set_bit(rule_index[1], priv->cfp.used); set_bit(rule_index[0], priv->cfp.used);
set_bit(rule_index[1], priv->cfp.unique); set_bit(rule_index[1], priv->cfp.unique);
fs->location = rule_index[1]; fs->location = rule_index[1];
return ret; return ret;
out_err: out_err:
clear_bit(rule_index[0], priv->cfp.used); clear_bit(rule_index[1], priv->cfp.used);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment