Commit 7aea535d authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Jakub Kicinski

net: dsa: move rest of devlink setup/teardown to devlink.c

The code that needed further refactoring into dedicated functions in
dsa2.c was left aside. Move it now to devlink.c, and make dsa2.c stop
including net/devlink.h.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent d95fa750
...@@ -167,7 +167,7 @@ dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_port *dlp, ...@@ -167,7 +167,7 @@ dsa_devlink_sb_occ_tc_port_bind_get(struct devlink_port *dlp,
p_max); p_max);
} }
const struct devlink_ops dsa_devlink_ops = { static const struct devlink_ops dsa_devlink_ops = {
.info_get = dsa_devlink_info_get, .info_get = dsa_devlink_info_get,
.sb_pool_get = dsa_devlink_sb_pool_get, .sb_pool_get = dsa_devlink_sb_pool_get,
.sb_pool_set = dsa_devlink_sb_pool_set, .sb_pool_set = dsa_devlink_sb_pool_set,
...@@ -353,3 +353,39 @@ void dsa_port_devlink_teardown(struct dsa_port *dp) ...@@ -353,3 +353,39 @@ void dsa_port_devlink_teardown(struct dsa_port *dp)
devlink_port_fini(dlp); devlink_port_fini(dlp);
} }
void dsa_switch_devlink_register(struct dsa_switch *ds)
{
devlink_register(ds->devlink);
}
void dsa_switch_devlink_unregister(struct dsa_switch *ds)
{
devlink_unregister(ds->devlink);
}
int dsa_switch_devlink_alloc(struct dsa_switch *ds)
{
struct dsa_devlink_priv *dl_priv;
struct devlink *dl;
/* Add the switch to devlink before calling setup, so that setup can
* add dpipe tables
*/
dl = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev);
if (!dl)
return -ENOMEM;
ds->devlink = dl;
dl_priv = devlink_priv(ds->devlink);
dl_priv->ds = ds;
return 0;
}
void dsa_switch_devlink_free(struct dsa_switch *ds)
{
devlink_free(ds->devlink);
ds->devlink = NULL;
}
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
#define __DSA_DEVLINK_H #define __DSA_DEVLINK_H
struct dsa_port; struct dsa_port;
struct dsa_switch;
extern const struct devlink_ops dsa_devlink_ops;
int dsa_port_devlink_setup(struct dsa_port *dp); int dsa_port_devlink_setup(struct dsa_port *dp);
void dsa_port_devlink_teardown(struct dsa_port *dp); void dsa_port_devlink_teardown(struct dsa_port *dp);
void dsa_switch_devlink_register(struct dsa_switch *ds);
void dsa_switch_devlink_unregister(struct dsa_switch *ds);
int dsa_switch_devlink_alloc(struct dsa_switch *ds);
void dsa_switch_devlink_free(struct dsa_switch *ds);
#endif #endif
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_mdio.h> #include <linux/of_mdio.h>
#include <linux/of_net.h> #include <linux/of_net.h>
#include <net/devlink.h>
#include <net/sch_generic.h> #include <net/sch_generic.h>
#include "devlink.h" #include "devlink.h"
...@@ -627,7 +626,6 @@ static void dsa_switch_teardown_tag_protocol(struct dsa_switch *ds) ...@@ -627,7 +626,6 @@ static void dsa_switch_teardown_tag_protocol(struct dsa_switch *ds)
static int dsa_switch_setup(struct dsa_switch *ds) static int dsa_switch_setup(struct dsa_switch *ds)
{ {
struct dsa_devlink_priv *dl_priv;
struct device_node *dn; struct device_node *dn;
int err; int err;
...@@ -641,15 +639,9 @@ static int dsa_switch_setup(struct dsa_switch *ds) ...@@ -641,15 +639,9 @@ static int dsa_switch_setup(struct dsa_switch *ds)
*/ */
ds->phys_mii_mask |= dsa_user_ports(ds); ds->phys_mii_mask |= dsa_user_ports(ds);
/* Add the switch to devlink before calling setup, so that setup can err = dsa_switch_devlink_alloc(ds);
* add dpipe tables if (err)
*/ return err;
ds->devlink =
devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv), ds->dev);
if (!ds->devlink)
return -ENOMEM;
dl_priv = devlink_priv(ds->devlink);
dl_priv->ds = ds;
err = dsa_switch_register_notifier(ds); err = dsa_switch_register_notifier(ds);
if (err) if (err)
...@@ -682,7 +674,7 @@ static int dsa_switch_setup(struct dsa_switch *ds) ...@@ -682,7 +674,7 @@ static int dsa_switch_setup(struct dsa_switch *ds)
goto free_slave_mii_bus; goto free_slave_mii_bus;
} }
devlink_register(ds->devlink); dsa_switch_devlink_register(ds);
ds->setup = true; ds->setup = true;
return 0; return 0;
...@@ -696,8 +688,7 @@ static int dsa_switch_setup(struct dsa_switch *ds) ...@@ -696,8 +688,7 @@ static int dsa_switch_setup(struct dsa_switch *ds)
unregister_notifier: unregister_notifier:
dsa_switch_unregister_notifier(ds); dsa_switch_unregister_notifier(ds);
devlink_free: devlink_free:
devlink_free(ds->devlink); dsa_switch_devlink_free(ds);
ds->devlink = NULL;
return err; return err;
} }
...@@ -706,7 +697,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds) ...@@ -706,7 +697,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
if (!ds->setup) if (!ds->setup)
return; return;
devlink_unregister(ds->devlink); dsa_switch_devlink_unregister(ds);
if (ds->slave_mii_bus && ds->ops->phy_read) { if (ds->slave_mii_bus && ds->ops->phy_read) {
mdiobus_unregister(ds->slave_mii_bus); mdiobus_unregister(ds->slave_mii_bus);
...@@ -721,8 +712,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds) ...@@ -721,8 +712,7 @@ static void dsa_switch_teardown(struct dsa_switch *ds)
dsa_switch_unregister_notifier(ds); dsa_switch_unregister_notifier(ds);
devlink_free(ds->devlink); dsa_switch_devlink_free(ds);
ds->devlink = NULL;
ds->setup = false; ds->setup = false;
} }
......
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