netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Andrew Lunn <andrew@lunn.ch>
Cc: David Miller <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH net-next v3 1/2] net: dsa: Add support for devlink device parameters
Date: Fri, 18 Oct 2019 07:54:36 +0200	[thread overview]
Message-ID: <20191018055436.GC2185@nanopsycho> (raw)
In-Reply-To: <20191017192055.23770-2-andrew@lunn.ch>

Thu, Oct 17, 2019 at 09:20:54PM CEST, andrew@lunn.ch wrote:
>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>
>---
> include/net/dsa.h | 23 +++++++++++++++++++++++
> net/dsa/dsa.c     | 48 +++++++++++++++++++++++++++++++++++++++++++++++
> net/dsa/dsa2.c    |  7 ++++++-
> 3 files changed, 77 insertions(+), 1 deletion(-)
>
>diff --git a/include/net/dsa.h b/include/net/dsa.h
>index 8c3ea0530f65..6623f4428930 100644
>--- a/include/net/dsa.h
>+++ b/include/net/dsa.h
>@@ -541,6 +541,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_dl_param_get,	dsa_dl_param_set, NULL)
>+
>+int dsa_dl_param_get(struct devlink *dl, u32 id,
>+		     struct devlink_param_gset_ctx *ctx);
>+int dsa_dl_param_set(struct devlink *dl, u32 id,
>+		     struct devlink_param_gset_ctx *ctx);
>+int dsa_devlink_params_register(struct dsa_switch *ds,

"dl/devlink". I think that the names should be consistent.


>+				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 {
>diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
>index 43120a3fb06f..ea7678650d8c 100644
>--- a/net/dsa/dsa.c
>+++ b/net/dsa/dsa.c
>@@ -329,6 +329,54 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev,
> }
> EXPORT_SYMBOL_GPL(call_dsa_notifiers);
> 
>+int dsa_dl_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_dl_param_get);
>+
>+int dsa_dl_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_dl_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;
>diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
>index 73002022c9d8..d74cc82fb44a 100644
>--- a/net/dsa/dsa2.c
>+++ b/net/dsa/dsa2.c
>@@ -367,6 +367,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 = 0;
> 
> 	/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
>@@ -379,9 +380,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(*devlink_priv));

This should most likely be:
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)
>@@ -395,6 +398,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) {
>-- 
>2.23.0
>

  reply	other threads:[~2019-10-18  5:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 19:20 [PATCH net-next v3 0/2] mv88e6xxx: Allow config of ATU hash algorithm Andrew Lunn
2019-10-17 19:20 ` [PATCH net-next v3 1/2] net: dsa: Add support for devlink device parameters Andrew Lunn
2019-10-18  5:54   ` Jiri Pirko [this message]
2019-10-17 19:20 ` [PATCH net-next v3 2/2] net: dsa: mv88e6xxx: Add devlink param for ATU hash algorithm Andrew Lunn
2019-10-17 19:47   ` Jakub Kicinski
2019-10-18  6:11   ` Jiri Pirko
2019-10-18 21:48   ` Vivien Didelot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191018055436.GC2185@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).