Skip to content

Commit

Permalink
net: dsa: introduce a dsa_switch_find function
Browse files Browse the repository at this point in the history
Somewhat similar to dsa_tree_find, dsa_switch_find returns a dsa_switch
structure pointer by searching for its tree index and switch index (the
parameters from dsa,member). To be used, for example, by drivers who
implement .crosschip_bridge_join and need a reference to the other
switch indicated to by the tree_index and sw_index arguments.

Signed-off-by: Vladimir Oltean <[email protected]>
Reviewed-by: Florian Fainelli <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
vladimiroltean authored and kuba-moo committed May 11, 2020
1 parent f66a6a6 commit 3b7bc1f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ static inline bool dsa_can_decode(const struct sk_buff *skb,

void dsa_unregister_switch(struct dsa_switch *ds);
int dsa_register_switch(struct dsa_switch *ds);
struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
#ifdef CONFIG_PM_SLEEP
int dsa_switch_suspend(struct dsa_switch *ds);
int dsa_switch_resume(struct dsa_switch *ds);
Expand Down
21 changes: 21 additions & 0 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ LIST_HEAD(dsa_tree_list);
static const struct devlink_ops dsa_devlink_ops = {
};

struct dsa_switch *dsa_switch_find(int tree_index, int sw_index)
{
struct dsa_switch_tree *dst;
struct dsa_port *dp;

list_for_each_entry(dst, &dsa_tree_list, list) {
if (dst->index != tree_index)
continue;

list_for_each_entry(dp, &dst->ports, list) {
if (dp->ds->index != sw_index)
continue;

return dp->ds;
}
}

return NULL;
}
EXPORT_SYMBOL_GPL(dsa_switch_find);

static struct dsa_switch_tree *dsa_tree_find(int index)
{
struct dsa_switch_tree *dst;
Expand Down

0 comments on commit 3b7bc1f

Please sign in to comment.