diff mbox series

[net-next,2/6] net: dsa: export the dsa_port_is_{user,cpu,dsa} helpers

Message ID 20210618183017.3340769-3-olteanv@gmail.com
State Superseded
Headers show
Series Improvement for DSA cross-chip setups | expand

Commit Message

Vladimir Oltean June 18, 2021, 6:30 p.m. UTC
From: Vladimir Oltean <vladimir.oltean@nxp.com>

The difference between dsa_is_user_port and dsa_port_is_user is that the
former needs to look up the list of ports of the DSA switch tree in
order to find the struct dsa_port, while the latter directly receives it
as an argument.

dsa_is_user_port is already in widespread use and has its place, so
there isn't any chance of converting all callers to a single form.
But being able to do:
	dsa_port_is_user(dp)
instead of
	dsa_is_user_port(dp->ds, dp->index)

is much more efficient too, especially when the "dp" comes from an
iterator over the DSA switch tree - this reduces the complexity from
quadratic to linear.

Move these helpers from dsa2.c to include/net/dsa.h so that others can
use them too.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 include/net/dsa.h | 15 +++++++++++++++
 net/dsa/dsa2.c    | 15 ---------------
 2 files changed, 15 insertions(+), 15 deletions(-)

Comments

Florian Fainelli June 19, 2021, 2 a.m. UTC | #1
On 6/18/2021 11:30 AM, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>

> 

> The difference between dsa_is_user_port and dsa_port_is_user is that the

> former needs to look up the list of ports of the DSA switch tree in

> order to find the struct dsa_port, while the latter directly receives it

> as an argument.

> 

> dsa_is_user_port is already in widespread use and has its place, so

> there isn't any chance of converting all callers to a single form.

> But being able to do:

> 	dsa_port_is_user(dp)

> instead of

> 	dsa_is_user_port(dp->ds, dp->index)

> 

> is much more efficient too, especially when the "dp" comes from an

> iterator over the DSA switch tree - this reduces the complexity from

> quadratic to linear.

> 

> Move these helpers from dsa2.c to include/net/dsa.h so that others can

> use them too.

> 

> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>


Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

-- 
Florian
Andrew Lunn June 21, 2021, 1:55 p.m. UTC | #2
On Fri, Jun 18, 2021 at 09:30:13PM +0300, Vladimir Oltean wrote:
> From: Vladimir Oltean <vladimir.oltean@nxp.com>

> 

> The difference between dsa_is_user_port and dsa_port_is_user is that the

> former needs to look up the list of ports of the DSA switch tree in

> order to find the struct dsa_port, while the latter directly receives it

> as an argument.

> 

> dsa_is_user_port is already in widespread use and has its place, so

> there isn't any chance of converting all callers to a single form.

> But being able to do:

> 	dsa_port_is_user(dp)

> instead of

> 	dsa_is_user_port(dp->ds, dp->index)

> 

> is much more efficient too, especially when the "dp" comes from an

> iterator over the DSA switch tree - this reduces the complexity from

> quadratic to linear.

> 

> Move these helpers from dsa2.c to include/net/dsa.h so that others can

> use them too.

> 

> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>


Reviewed-by: Andrew Lunn <andrew@lunn.ch>


    Andrew
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 289d68e82da0..ea47783d5695 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -409,6 +409,21 @@  static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
 	return NULL;
 }
 
+static inline bool dsa_port_is_dsa(struct dsa_port *port)
+{
+	return port->type == DSA_PORT_TYPE_DSA;
+}
+
+static inline bool dsa_port_is_cpu(struct dsa_port *port)
+{
+	return port->type == DSA_PORT_TYPE_CPU;
+}
+
+static inline bool dsa_port_is_user(struct dsa_port *dp)
+{
+	return dp->type == DSA_PORT_TYPE_USER;
+}
+
 static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
 {
 	return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_UNUSED;
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index ba244fbd9646..9000a8c84baf 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -219,21 +219,6 @@  static void dsa_tree_put(struct dsa_switch_tree *dst)
 		kref_put(&dst->refcount, dsa_tree_release);
 }
 
-static bool dsa_port_is_dsa(struct dsa_port *port)
-{
-	return port->type == DSA_PORT_TYPE_DSA;
-}
-
-static bool dsa_port_is_cpu(struct dsa_port *port)
-{
-	return port->type == DSA_PORT_TYPE_CPU;
-}
-
-static bool dsa_port_is_user(struct dsa_port *dp)
-{
-	return dp->type == DSA_PORT_TYPE_USER;
-}
-
 static struct dsa_port *dsa_tree_find_port_by_node(struct dsa_switch_tree *dst,
 						   struct device_node *dn)
 {