diff mbox series

[net-next,RFC,v1,3/4] net: dsa: Add helper for converting devlink port to ds and port

Message ID 20200919144332.3665538-4-andrew@lunn.ch
State RFC
Delegated to: David Miller
Headers show
Series Add per port devlink regions | expand

Commit Message

Andrew Lunn Sept. 19, 2020, 2:43 p.m. UTC
Hide away from DSA drivers how devlink works.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 include/net/dsa.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Vladimir Oltean Sept. 20, 2020, 11:52 p.m. UTC | #1
On Sat, Sep 19, 2020 at 04:43:31PM +0200, Andrew Lunn wrote:
> Hide away from DSA drivers how devlink works.
> 
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
>  include/net/dsa.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 01da896b2998..a24d5158ee0c 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -685,6 +685,20 @@ static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
>  	return dl_priv->ds;
>  }
>  
> +static inline
> +struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
> +{
> +	struct devlink *dl = port->devlink;
> +	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
> +
> +	return dl_priv->ds;
> +}
> +
> +static inline int dsa_devlink_port_to_port(struct devlink_port *port)

How about dsa_devlink_port_to_index?
It avoids the repetition and it also indicates more clearly that it
returns an index rather than a struct dsa_port, without needing to fire
up ctags.

> +{
> +	return port->index;
> +}
> +
>  struct dsa_switch_driver {
>  	struct list_head	list;
>  	const struct dsa_switch_ops *ops;
> -- 
> 2.28.0
> 

Thanks,
-Vladimir
Andrew Lunn Sept. 26, 2020, 5:28 p.m. UTC | #2
On Sun, Sep 20, 2020 at 11:52:03PM +0000, Vladimir Oltean wrote:
> On Sat, Sep 19, 2020 at 04:43:31PM +0200, Andrew Lunn wrote:
> > Hide away from DSA drivers how devlink works.
> > 
> > Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> > ---
> >  include/net/dsa.h | 14 ++++++++++++++
> >  1 file changed, 14 insertions(+)
> > 
> > diff --git a/include/net/dsa.h b/include/net/dsa.h
> > index 01da896b2998..a24d5158ee0c 100644
> > --- a/include/net/dsa.h
> > +++ b/include/net/dsa.h
> > @@ -685,6 +685,20 @@ static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
> >  	return dl_priv->ds;
> >  }
> >  
> > +static inline
> > +struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
> > +{
> > +	struct devlink *dl = port->devlink;
> > +	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
> > +
> > +	return dl_priv->ds;
> > +}
> > +
> > +static inline int dsa_devlink_port_to_port(struct devlink_port *port)
> 
> How about dsa_devlink_port_to_index?
> It avoids the repetition and it also indicates more clearly that it
> returns an index rather than a struct dsa_port, without needing to fire
> up ctags.

Hi Vladimir

Just finishing off the next version of these patches, and i looped
back to check i addressed all the comments.

This one i tend to disagree with. If you look at DSA drivers, a port
variable is always an integer index. dp is used to refer to a
dsa_port.

If anything, i would suggest we rename dsa_to_port() to dsa_to_dp(),
and dsa_port_from_netdev to dsa_dp_from_netdev() or maybe
dsa_netdev_to_dp().

    Andrew
Vladimir Oltean Sept. 26, 2020, 5:45 p.m. UTC | #3
On Sat, Sep 26, 2020 at 07:28:26PM +0200, Andrew Lunn wrote:
> Hi Vladimir
>
> Just finishing off the next version of these patches, and i looped
> back to check i addressed all the comments.
>
> This one i tend to disagree with. If you look at DSA drivers, a port
> variable is always an integer index. dp is used to refer to a
> dsa_port.
>
> If anything, i would suggest we rename dsa_to_port() to dsa_to_dp(),
> and dsa_port_from_netdev to dsa_dp_from_netdev() or maybe
> dsa_netdev_to_dp().

Maybe it's just me, but I don't like the "dp" name too much, and I think
all conversions of those functions sound worse with the new names.
But you do have a point with the inconsistency, so I suppose you could
leave the name as it is? Or maybe dsa_dlp_to_port() if you fancy that
abbreviation for a devlink port?
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 01da896b2998..a24d5158ee0c 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -685,6 +685,20 @@  static inline struct dsa_switch *dsa_devlink_to_ds(struct devlink *dl)
 	return dl_priv->ds;
 }
 
+static inline
+struct dsa_switch *dsa_devlink_port_to_ds(struct devlink_port *port)
+{
+	struct devlink *dl = port->devlink;
+	struct dsa_devlink_priv *dl_priv = devlink_priv(dl);
+
+	return dl_priv->ds;
+}
+
+static inline int dsa_devlink_port_to_port(struct devlink_port *port)
+{
+	return port->index;
+}
+
 struct dsa_switch_driver {
 	struct list_head	list;
 	const struct dsa_switch_ops *ops;