Skip to content

Commit

Permalink
net: dsa: Call driver's setup callback after setting up its switchdev…
Browse files Browse the repository at this point in the history
… 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
chain).

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 <olteanv@gmail.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Vivien Didelot <vivien.didelot@gmail.com>-
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vladimir Oltean authored and David S. Miller committed May 6, 2019
1 parent e7ba0fa commit b2243b3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,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)
Expand Down

0 comments on commit b2243b3

Please sign in to comment.