net: dsa: make LAG IDs one-based

The DSA LAG API will be changed to become more similar with the bridge
data structures, where struct dsa_bridge holds an unsigned int num,
which is generated by DSA and is one-based. We have a similar thing
going with the DSA LAG, except that isn't stored anywhere, it is
calculated dynamically by dsa_lag_id() by iterating through dst->lags.

The idea of encoding an invalid (or not requested) LAG ID as zero for
the purpose of simplifying checks in drivers means that the LAG IDs
passed by DSA to drivers need to be one-based too. So back-and-forth
conversion is needed when indexing the dst->lags array, as well as in
drivers which assume a zero-based index.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Vladimir Oltean
2022-02-23 16:00:47 +02:00
committed by Jakub Kicinski
parent 066ce9779c
commit 3d4a0a2a46
5 changed files with 21 additions and 15 deletions

View File

@@ -2654,7 +2654,7 @@ qca8k_lag_can_offload(struct dsa_switch *ds,
int id, members = 0;
id = dsa_lag_id(ds->dst, lag_dev);
if (id < 0 || id >= ds->num_lag_ids)
if (id <= 0 || id > ds->num_lag_ids)
return false;
dsa_lag_foreach_port(dp, ds->dst, lag_dev)
@@ -2732,7 +2732,8 @@ qca8k_lag_refresh_portmap(struct dsa_switch *ds, int port,
int ret, id, i;
u32 val;
id = dsa_lag_id(ds->dst, lag_dev);
/* DSA LAG IDs are one-based, hardware is zero-based */
id = dsa_lag_id(ds->dst, lag_dev) - 1;
/* Read current port member */
ret = regmap_read(priv->regmap, QCA8K_REG_GOL_TRUNK_CTRL0, &val);