diff mbox series

[net-next,6/7] net: dsa: wire up devlink info get

Message ID 20200816194316.2291489-7-andrew@lunn.ch
State Changes Requested
Delegated to: David Miller
Headers show
Series net: dsa: mv88e6xxx: Add devlink regions support | expand

Commit Message

Andrew Lunn Aug. 16, 2020, 7:43 p.m. UTC
Allow the DSA drivers to implement the devlink call to get info info,
e.g. driver name, firmware version, ASIC ID, etc.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h |  5 ++++-
 net/dsa/dsa2.c    | 21 ++++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

Comments

Vladimir Oltean Aug. 16, 2020, 9:56 p.m. UTC | #1
On Sun, Aug 16, 2020 at 09:43:15PM +0200, Andrew Lunn wrote:
> Allow the DSA drivers to implement the devlink call to get info info,
> e.g. driver name, firmware version, ASIC ID, etc.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  include/net/dsa.h |  5 ++++-
>  net/dsa/dsa2.c    | 21 ++++++++++++++++++---
>  2 files changed, 22 insertions(+), 4 deletions(-)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 8963440ec7f8..0e34193d15ba 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -612,11 +612,14 @@ struct dsa_switch_ops {
>  	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
>  				 struct sk_buff *skb, unsigned int type);
>  
> -	/* Devlink parameters */
> +	/* Devlink parameters, etc */
>  	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);
> +	int	(*devlink_info_get)(struct dsa_switch *ds,
> +				    struct devlink_info_req *req,
> +				    struct netlink_ext_ack *extack);
>  
>  	/*
>  	 * MTU change functionality. Switches can also adjust their MRU through
> diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
> index c0ffc7a2b65f..860f2fb22fe0 100644
> --- a/net/dsa/dsa2.c
> +++ b/net/dsa/dsa2.c
> @@ -21,9 +21,6 @@
>  static DEFINE_MUTEX(dsa2_mutex);
>  LIST_HEAD(dsa_tree_list);
>  
> -static const struct devlink_ops dsa_devlink_ops = {
> -};
> -
>  struct dsa_switch *dsa_switch_find(int tree_index, int sw_index)
>  {
>  	struct dsa_switch_tree *dst;
> @@ -382,6 +379,24 @@ static void dsa_port_teardown(struct dsa_port *dp)
>  	dp->setup = false;
>  }
>  
> +static int dsa_devlink_info_get(struct devlink *dl,
> +				struct devlink_info_req *req,
> +				struct netlink_ext_ack *extack)
> +{
> +	struct dsa_switch *ds;
> +
> +	ds = dsa_devlink_to_ds(dl);
> +

Why not place the declaration and the assignment on a single line?

> +	if (ds->ops->devlink_info_get)
> +		return ds->ops->devlink_info_get(ds, req, extack);
> +
> +	return -EOPNOTSUPP;
> +}
> +
> +static const struct devlink_ops dsa_devlink_ops = {
> +	.info_get = dsa_devlink_info_get,
> +};
> +
>  static int dsa_switch_setup(struct dsa_switch *ds)
>  {
>  	struct dsa_devlink_priv *dl_priv;
> -- 
> 2.28.0
> 

Thanks,
-Vladimir
Andrew Lunn Aug. 16, 2020, 10:16 p.m. UTC | #2
> > +static int dsa_devlink_info_get(struct devlink *dl,
> > +				struct devlink_info_req *req,
> > +				struct netlink_ext_ack *extack)
> > +{
> > +	struct dsa_switch *ds;
> > +
> > +	ds = dsa_devlink_to_ds(dl);
> > +
> 
> Why not place the declaration and the assignment on a single line?

This code went through a few refactors. Probably at some point i could
not keep reverse christmass tree so had to split it. And it then never
got put back together again.

I will fix it up for v2.

  Andrew
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 8963440ec7f8..0e34193d15ba 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -612,11 +612,14 @@  struct dsa_switch_ops {
 	bool	(*port_rxtstamp)(struct dsa_switch *ds, int port,
 				 struct sk_buff *skb, unsigned int type);
 
-	/* Devlink parameters */
+	/* Devlink parameters, etc */
 	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);
+	int	(*devlink_info_get)(struct dsa_switch *ds,
+				    struct devlink_info_req *req,
+				    struct netlink_ext_ack *extack);
 
 	/*
 	 * MTU change functionality. Switches can also adjust their MRU through
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index c0ffc7a2b65f..860f2fb22fe0 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -21,9 +21,6 @@ 
 static DEFINE_MUTEX(dsa2_mutex);
 LIST_HEAD(dsa_tree_list);
 
-static const struct devlink_ops dsa_devlink_ops = {
-};
-
 struct dsa_switch *dsa_switch_find(int tree_index, int sw_index)
 {
 	struct dsa_switch_tree *dst;
@@ -382,6 +379,24 @@  static void dsa_port_teardown(struct dsa_port *dp)
 	dp->setup = false;
 }
 
+static int dsa_devlink_info_get(struct devlink *dl,
+				struct devlink_info_req *req,
+				struct netlink_ext_ack *extack)
+{
+	struct dsa_switch *ds;
+
+	ds = dsa_devlink_to_ds(dl);
+
+	if (ds->ops->devlink_info_get)
+		return ds->ops->devlink_info_get(ds, req, extack);
+
+	return -EOPNOTSUPP;
+}
+
+static const struct devlink_ops dsa_devlink_ops = {
+	.info_get = dsa_devlink_info_get,
+};
+
 static int dsa_switch_setup(struct dsa_switch *ds)
 {
 	struct dsa_devlink_priv *dl_priv;