[lkml]   [2019]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v3 net-next 06/24] net: dsa: Call driver's setup callback after setting up its switchdev notifier
This allows the driver to perform some manipulations of its own during
setup, using generic switchdev calls. Having the notifiers registered at
setup time is important because otherwise any switchdev transaction
emitted during this time would be ignored (dispatched to an empty call

One current usage scenario is for the driver to request DSA to set up
802.1Q based switch tagging for its ports.

There is no danger for the driver setup code to start racing now with
switchdev events emitted from the network stack (such as bridge core)
even if the notifier is registered earlier. This is because the network
stack needs a net_device as a vehicle to perform switchdev operations,
and the slave net_devices are registered later than the core driver
setup anyway (ds->ops->setup in dsa_switch_setup vs dsa_port_setup).

Luckily DSA doesn't need a net_device to carry out switchdev callbacks,
and therefore drivers shouldn't assume either that net_devices are
available at the time their switchdev callbacks get invoked.

Signed-off-by: Vladimir Oltean <>
Reviewed-by: Florian Fainelli <>
Changes in v3:

Changes in v2:
More verbiage in commit message.

net/dsa/dsa2.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index d122f1bcdab2..17817c1a7fbd 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -369,14 +369,14 @@ static int dsa_switch_setup(struct dsa_switch *ds)
if (err)
return err;

- err = ds->ops->setup(ds);
- if (err < 0)
- return err;
err = dsa_switch_register_notifier(ds);
if (err)
return err;

+ err = ds->ops->setup(ds);
+ if (err < 0)
+ return err;
if (!ds->slave_mii_bus && ds->ops->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
if (!ds->slave_mii_bus)
 \ /
  Last update: 2019-04-13 03:29    [W:0.205 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site