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:
committed by
Jakub Kicinski
parent
066ce9779c
commit
3d4a0a2a46
@@ -163,9 +163,10 @@ struct dsa_switch_tree {
|
||||
unsigned int last_switch;
|
||||
};
|
||||
|
||||
/* LAG IDs are one-based, the dst->lags array is zero-based */
|
||||
#define dsa_lags_foreach_id(_id, _dst) \
|
||||
for ((_id) = 0; (_id) < (_dst)->lags_len; (_id)++) \
|
||||
if ((_dst)->lags[(_id)])
|
||||
for ((_id) = 1; (_id) <= (_dst)->lags_len; (_id)++) \
|
||||
if ((_dst)->lags[(_id) - 1])
|
||||
|
||||
#define dsa_lag_foreach_port(_dp, _dst, _lag) \
|
||||
list_for_each_entry((_dp), &(_dst)->ports, list) \
|
||||
@@ -178,7 +179,8 @@ struct dsa_switch_tree {
|
||||
static inline struct net_device *dsa_lag_dev(struct dsa_switch_tree *dst,
|
||||
unsigned int id)
|
||||
{
|
||||
return dst->lags[id];
|
||||
/* DSA LAG IDs are one-based, dst->lags is zero-based */
|
||||
return dst->lags[id - 1];
|
||||
}
|
||||
|
||||
static inline int dsa_lag_id(struct dsa_switch_tree *dst,
|
||||
|
||||
Reference in New Issue
Block a user