diff mbox series

[v2,1/2] include: net: add dsa_cpu_ports function

Message ID 20210406045041.16283-1-ansuelsmth@gmail.com
State Superseded
Headers show
Series [v2,1/2] include: net: add dsa_cpu_ports function | expand

Commit Message

Christian Marangi April 6, 2021, 4:50 a.m. UTC
In preparation for the future when dsa will support multi cpu port,
dsa_cpu_ports can be useful for switch that has multiple cpu port to
retrieve the cpu mask for ACL and bridge table.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 include/net/dsa.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Andrew Lunn April 7, 2021, 12:41 a.m. UTC | #1
On Tue, Apr 06, 2021 at 06:50:40AM +0200, Ansuel Smith wrote:
> qca8k 83xx switch have 2 cpu ports. Rework the driver to support
> multiple cpu port. All ports can access both cpu ports by default as
> they support the same features.

Do you have more information about how this actually works. How does
the switch decide which port to use when sending a frame towards the
CPU? Is there some sort of load balancing?

How does Linux decide which CPU port to use towards the switch?

    Andrew
Christian Marangi April 9, 2021, 10:25 a.m. UTC | #2
On Fri, Apr 09, 2021 at 11:15:37AM -0700, Florian Fainelli wrote:
> 

> 

> On 4/5/2021 10:16 PM, Ansuel Smith wrote:

> > On Wed, Apr 07, 2021 at 02:41:02AM +0200, Andrew Lunn wrote:

> >> On Tue, Apr 06, 2021 at 06:50:40AM +0200, Ansuel Smith wrote:

> >>> qca8k 83xx switch have 2 cpu ports. Rework the driver to support

> >>> multiple cpu port. All ports can access both cpu ports by default as

> >>> they support the same features.

> >>

> >> Do you have more information about how this actually works. How does

> >> the switch decide which port to use when sending a frame towards the

> >> CPU? Is there some sort of load balancing?

> >>

> >> How does Linux decide which CPU port to use towards the switch?

> >>

> >>     Andrew

> > 

> > I could be very wrong, but in the current dsa code, only the very first

> > cpu port is used and linux use only that to send data.

> 

> That is correct, the first CPU port that is detected by the parsing

> logic gets used.

> 

> > In theory the switch send the frame to both CPU, I'm currently testing a

> > multi-cpu patch for dsa and I can confirm that with the proposed code

> > the packets are transmitted correctly and the 2 cpu ports are used.

> > (The original code has one cpu dedicated to LAN ports and one cpu

> > dedicated to the unique WAN port.) Anyway in the current implementation

> > nothing will change. DSA code still supports one cpu and this change

> > would only allow packet to be received and trasmitted from the second

> > cpu.

> 

> That use case seems to be the most common which makes sense since it

> allows for true Gigabit routing between WAN and LAN by utilizing both

> CPUs's Ethernet controllers.

> 

> How do you currently assign a port of a switch with a particular CPU

> port this is presumably done through a separate patch that you have not

> submitted?

> -- 

> Florian


I reworked an old patch that added multi-cpu support to dsa.
CPUs are assigned in a round-robin way and they can be set with an
additional iproute command. (I read some of the comments in that RFC
series and I'm planning to introduce some type of function where the
switch driver can declare a preferred CPU port). Anyway this series is
just to try to upstream the changes that doesn't require major revision,
since they can be included even without the multi-cpu patch.
Florian Fainelli April 9, 2021, 6:15 p.m. UTC | #3
On 4/5/2021 10:16 PM, Ansuel Smith wrote:
> On Wed, Apr 07, 2021 at 02:41:02AM +0200, Andrew Lunn wrote:

>> On Tue, Apr 06, 2021 at 06:50:40AM +0200, Ansuel Smith wrote:

>>> qca8k 83xx switch have 2 cpu ports. Rework the driver to support

>>> multiple cpu port. All ports can access both cpu ports by default as

>>> they support the same features.

>>

>> Do you have more information about how this actually works. How does

>> the switch decide which port to use when sending a frame towards the

>> CPU? Is there some sort of load balancing?

>>

>> How does Linux decide which CPU port to use towards the switch?

>>

>>     Andrew

> 

> I could be very wrong, but in the current dsa code, only the very first

> cpu port is used and linux use only that to send data.


That is correct, the first CPU port that is detected by the parsing
logic gets used.

> In theory the switch send the frame to both CPU, I'm currently testing a

> multi-cpu patch for dsa and I can confirm that with the proposed code

> the packets are transmitted correctly and the 2 cpu ports are used.

> (The original code has one cpu dedicated to LAN ports and one cpu

> dedicated to the unique WAN port.) Anyway in the current implementation

> nothing will change. DSA code still supports one cpu and this change

> would only allow packet to be received and trasmitted from the second

> cpu.


That use case seems to be the most common which makes sense since it
allows for true Gigabit routing between WAN and LAN by utilizing both
CPUs's Ethernet controllers.

How do you currently assign a port of a switch with a particular CPU
port this is presumably done through a separate patch that you have not
submitted?
-- 
Florian
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index d71b1acd9c3e..6d70a722d63f 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -458,6 +458,18 @@  static inline u32 dsa_cpu_ports(struct dsa_switch *ds)
 	return mask;
 }
 
+static inline u32 dsa_cpu_ports(struct dsa_switch *ds)
+{
+	u32 mask = 0;
+	int p;
+
+	for (p = 0; p < ds->num_ports; p++)
+		if (dsa_is_cpu_port(ds, p))
+			mask |= BIT(p);
+
+	return mask;
+}
+
 /* Return the local port used to reach an arbitrary switch device */
 static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device)
 {