p_max);
}
-const struct devlink_ops dsa_devlink_ops = {
+static const struct devlink_ops dsa_devlink_ops = {
.info_get = dsa_devlink_info_get,
.sb_pool_get = dsa_devlink_sb_pool_get,
.sb_pool_set = dsa_devlink_sb_pool_set,
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;
+}
#define __DSA_DEVLINK_H
struct dsa_port;
-
-extern const struct devlink_ops dsa_devlink_ops;
+struct dsa_switch;
int dsa_port_devlink_setup(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
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
-#include <net/devlink.h>
#include <net/sch_generic.h>
#include "devlink.h"
static int dsa_switch_setup(struct dsa_switch *ds)
{
- struct dsa_devlink_priv *dl_priv;
struct device_node *dn;
int err;
*/
ds->phys_mii_mask |= dsa_user_ports(ds);
- /* Add the switch to devlink before calling setup, so that setup can
- * add dpipe tables
- */
- 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_devlink_alloc(ds);
+ if (err)
+ return err;
err = dsa_switch_register_notifier(ds);
if (err)
goto free_slave_mii_bus;
}
- devlink_register(ds->devlink);
+ dsa_switch_devlink_register(ds);
ds->setup = true;
return 0;
unregister_notifier:
dsa_switch_unregister_notifier(ds);
devlink_free:
- devlink_free(ds->devlink);
- ds->devlink = NULL;
+ dsa_switch_devlink_free(ds);
return err;
}
if (!ds->setup)
return;
- devlink_unregister(ds->devlink);
+ dsa_switch_devlink_unregister(ds);
if (ds->slave_mii_bus && ds->ops->phy_read) {
mdiobus_unregister(ds->slave_mii_bus);
dsa_switch_unregister_notifier(ds);
- devlink_free(ds->devlink);
- ds->devlink = NULL;
+ dsa_switch_devlink_free(ds);
ds->setup = false;
}