net: dsa: Add support for devlink device parameters
authorAndrew Lunn <andrew@lunn.ch>
Thu, 24 Oct 2019 23:03:51 +0000 (01:03 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Oct 2019 23:21:02 +0000 (16:21 -0700)
Add plumbing to allow DSA drivers to register parameters with devlink.

To keep with the abstraction, the DSA drivers pass the ds structure to
these helpers, and the DSA core then translates that to the devlink
structure associated to the device.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/dsa.h
net/dsa/dsa.c
net/dsa/dsa2.c

index e3c14dc3bab9d1ef5be620005ee61bbcf96f41d5..d5f6e5ccca38b0d133da249d280684cd5a053e9d 100644 (file)
@@ -550,6 +550,29 @@ struct dsa_switch_ops {
         */
        netdev_tx_t (*port_deferred_xmit)(struct dsa_switch *ds, int port,
                                          struct sk_buff *skb);
+       /* Devlink parameters */
+       int     (*devlink_param_get)(struct dsa_switch *ds, u32 id,
+                                    struct devlink_param_gset_ctx *ctx);
+       int     (*devlink_param_set)(struct dsa_switch *ds, u32 id,
+                                    struct devlink_param_gset_ctx *ctx);
+};
+
+#define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes)           \
+       DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes,                \
+                            dsa_devlink_param_get, dsa_devlink_param_set, NULL)
+
+int dsa_devlink_param_get(struct devlink *dl, u32 id,
+                         struct devlink_param_gset_ctx *ctx);
+int dsa_devlink_param_set(struct devlink *dl, u32 id,
+                         struct devlink_param_gset_ctx *ctx);
+int dsa_devlink_params_register(struct dsa_switch *ds,
+                               const struct devlink_param *params,
+                               size_t params_count);
+void dsa_devlink_params_unregister(struct dsa_switch *ds,
+                                  const struct devlink_param *params,
+                                  size_t params_count);
+struct dsa_devlink_priv {
+       struct dsa_switch *ds;
 };
 
 struct dsa_switch_driver {
index a5545762f5e759df2a4ab546c4bec4efc13390a2..db1c1c7e40e96e45a421ae0c4a4f172ac36b0903 100644 (file)
@@ -331,6 +331,54 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev,
 }
 EXPORT_SYMBOL_GPL(call_dsa_notifiers);
 
+int dsa_devlink_param_get(struct devlink *dl, u32 id,
+                         struct devlink_param_gset_ctx *ctx)
+{
+       struct dsa_devlink_priv *dl_priv;
+       struct dsa_switch *ds;
+
+       dl_priv = devlink_priv(dl);
+       ds = dl_priv->ds;
+
+       if (!ds->ops->devlink_param_get)
+               return -EOPNOTSUPP;
+
+       return ds->ops->devlink_param_get(ds, id, ctx);
+}
+EXPORT_SYMBOL_GPL(dsa_devlink_param_get);
+
+int dsa_devlink_param_set(struct devlink *dl, u32 id,
+                         struct devlink_param_gset_ctx *ctx)
+{
+       struct dsa_devlink_priv *dl_priv;
+       struct dsa_switch *ds;
+
+       dl_priv = devlink_priv(dl);
+       ds = dl_priv->ds;
+
+       if (!ds->ops->devlink_param_set)
+               return -EOPNOTSUPP;
+
+       return ds->ops->devlink_param_set(ds, id, ctx);
+}
+EXPORT_SYMBOL_GPL(dsa_devlink_param_set);
+
+int dsa_devlink_params_register(struct dsa_switch *ds,
+                               const struct devlink_param *params,
+                               size_t params_count)
+{
+       return devlink_params_register(ds->devlink, params, params_count);
+}
+EXPORT_SYMBOL_GPL(dsa_devlink_params_register);
+
+void dsa_devlink_params_unregister(struct dsa_switch *ds,
+                                  const struct devlink_param *params,
+                                  size_t params_count)
+{
+       devlink_params_unregister(ds->devlink, params, params_count);
+}
+EXPORT_SYMBOL_GPL(dsa_devlink_params_unregister);
+
 static int __init dsa_init_module(void)
 {
        int rc;
index 214dd703b0ccdc7671bf37f77c98e16fe753b1ed..e7aae96b54bb76470176abbb11846b7b80a4d252 100644 (file)
@@ -349,6 +349,7 @@ static void dsa_port_teardown(struct dsa_port *dp)
 
 static int dsa_switch_setup(struct dsa_switch *ds)
 {
+       struct dsa_devlink_priv *dl_priv;
        int err;
 
        if (ds->setup)
@@ -364,9 +365,11 @@ static int dsa_switch_setup(struct dsa_switch *ds)
        /* Add the switch to devlink before calling setup, so that setup can
         * add dpipe tables
         */
-       ds->devlink = devlink_alloc(&dsa_devlink_ops, 0);
+       ds->devlink = devlink_alloc(&dsa_devlink_ops, sizeof(*dl_priv));
        if (!ds->devlink)
                return -ENOMEM;
+       dl_priv = devlink_priv(ds->devlink);
+       dl_priv->ds = ds;
 
        err = devlink_register(ds->devlink, ds->dev);
        if (err)
@@ -380,6 +383,8 @@ static int dsa_switch_setup(struct dsa_switch *ds)
        if (err < 0)
                goto unregister_notifier;
 
+       devlink_params_publish(ds->devlink);
+
        if (!ds->slave_mii_bus && ds->ops->phy_read) {
                ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
                if (!ds->slave_mii_bus) {