Commit 5dc760d1 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Paolo Abeni

net: dsa: use dsa_tree_for_each_cpu_port in dsa_tree_{setup,teardown}_master

More logic will be added to dsa_tree_setup_master() and
dsa_tree_teardown_master() in upcoming changes.

Reduce the indentation by one level in these functions by introducing
and using a dedicated iterator for CPU ports of a tree.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent f41ec1fd
...@@ -559,6 +559,10 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) ...@@ -559,6 +559,10 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
list_for_each_entry((_dp), &(_dst)->ports, list) \ list_for_each_entry((_dp), &(_dst)->ports, list) \
if (dsa_port_is_user((_dp))) if (dsa_port_is_user((_dp)))
#define dsa_tree_for_each_cpu_port(_dp, _dst) \
list_for_each_entry((_dp), &(_dst)->ports, list) \
if (dsa_port_is_cpu((_dp)))
#define dsa_switch_for_each_port(_dp, _ds) \ #define dsa_switch_for_each_port(_dp, _ds) \
list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ list_for_each_entry((_dp), &(_ds)->dst->ports, list) \
if ((_dp)->ds == (_ds)) if ((_dp)->ds == (_ds))
......
...@@ -1060,26 +1060,24 @@ static int dsa_tree_setup_switches(struct dsa_switch_tree *dst) ...@@ -1060,26 +1060,24 @@ static int dsa_tree_setup_switches(struct dsa_switch_tree *dst)
static int dsa_tree_setup_master(struct dsa_switch_tree *dst) static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
{ {
struct dsa_port *dp; struct dsa_port *cpu_dp;
int err = 0; int err = 0;
rtnl_lock(); rtnl_lock();
list_for_each_entry(dp, &dst->ports, list) { dsa_tree_for_each_cpu_port(cpu_dp, dst) {
if (dsa_port_is_cpu(dp)) { struct net_device *master = cpu_dp->master;
struct net_device *master = dp->master; bool admin_up = (master->flags & IFF_UP) &&
bool admin_up = (master->flags & IFF_UP) && !qdisc_tx_is_noop(master);
!qdisc_tx_is_noop(master);
err = dsa_master_setup(master, dp); err = dsa_master_setup(master, cpu_dp);
if (err) if (err)
break; break;
/* Replay master state event */ /* Replay master state event */
dsa_tree_master_admin_state_change(dst, master, admin_up); dsa_tree_master_admin_state_change(dst, master, admin_up);
dsa_tree_master_oper_state_change(dst, master, dsa_tree_master_oper_state_change(dst, master,
netif_oper_up(master)); netif_oper_up(master));
}
} }
rtnl_unlock(); rtnl_unlock();
...@@ -1089,22 +1087,20 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst) ...@@ -1089,22 +1087,20 @@ static int dsa_tree_setup_master(struct dsa_switch_tree *dst)
static void dsa_tree_teardown_master(struct dsa_switch_tree *dst) static void dsa_tree_teardown_master(struct dsa_switch_tree *dst)
{ {
struct dsa_port *dp; struct dsa_port *cpu_dp;
rtnl_lock(); rtnl_lock();
list_for_each_entry(dp, &dst->ports, list) { dsa_tree_for_each_cpu_port(cpu_dp, dst) {
if (dsa_port_is_cpu(dp)) { struct net_device *master = cpu_dp->master;
struct net_device *master = dp->master;
/* Synthesizing an "admin down" state is sufficient for /* Synthesizing an "admin down" state is sufficient for
* the switches to get a notification if the master is * the switches to get a notification if the master is
* currently up and running. * currently up and running.
*/ */
dsa_tree_master_admin_state_change(dst, master, false); dsa_tree_master_admin_state_change(dst, master, false);
dsa_master_teardown(master); dsa_master_teardown(master);
}
} }
rtnl_unlock(); rtnl_unlock();
......
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