mirror of
				https://github.com/Ysurac/openmptcprouter.git
				synced 2025-03-09 15:40:20 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			86 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
From 90adf38283688d8c25feeb7e3989cc2da3d58122 Mon Sep 17 00:00:00 2001
 | 
						|
From: Frank Wunderlich <frank-w@public-files.de>
 | 
						|
Date: Thu, 29 Nov 2018 11:27:12 +0100
 | 
						|
Subject: [PATCH 20/77] net: dsa: add helper functions
 | 
						|
 | 
						|
for using mutliple cpu-Ports 3 additional functions are defined to read
 | 
						|
dts-option (dsa_user_parse) and check if current port is a upstream-port
 | 
						|
(dsa_port_upstream_port, dsa_is_upstream_port)
 | 
						|
 | 
						|
based on
 | 
						|
https://github.com/openwrt/openwrt/blob/master/target/linux/mediatek/patches-4.14/0033-dsa-multi-cpu.patch
 | 
						|
 | 
						|
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
 | 
						|
---
 | 
						|
 include/net/dsa.h | 18 ++++++++++++++++++
 | 
						|
 net/dsa/dsa2.c    | 18 ++++++++++++++++++
 | 
						|
 2 files changed, 36 insertions(+)
 | 
						|
 | 
						|
diff --git a/include/net/dsa.h b/include/net/dsa.h
 | 
						|
index 6e0c95625a21..36db2ee83da6 100644
 | 
						|
--- a/include/net/dsa.h
 | 
						|
+++ b/include/net/dsa.h
 | 
						|
@@ -318,6 +318,12 @@ static inline unsigned int dsa_towards_port(struct dsa_switch *ds, int device,
 | 
						|
 		return ds->rtable[device];
 | 
						|
 }
 | 
						|
 
 | 
						|
+
 | 
						|
+static inline bool dsa_is_upstream_port(struct dsa_switch *ds, int p)
 | 
						|
+{
 | 
						|
+	return dsa_is_cpu_port(ds, p) || dsa_is_dsa_port(ds, p);
 | 
						|
+}
 | 
						|
+
 | 
						|
 /* Return the local port used to reach the dedicated CPU port */
 | 
						|
 static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
 | 
						|
 {
 | 
						|
@@ -330,6 +336,18 @@ static inline unsigned int dsa_upstream_port(struct dsa_switch *ds, int port)
 | 
						|
 	return dsa_towards_port(ds, cpu_dp->ds->index, cpu_dp->index);
 | 
						|
 }
 | 
						|
 
 | 
						|
+static inline u8 dsa_port_upstream_port(struct dsa_switch *ds, int port)
 | 
						|
+{
 | 
						|
+	/*
 | 
						|
+	 * If this port has a specific upstream cpu port, use it,
 | 
						|
+	 * otherwise use the switch default.
 | 
						|
+	 */
 | 
						|
+	if (ds->ports[port].upstream)
 | 
						|
+		return ds->ports[port].upstream;
 | 
						|
+	else
 | 
						|
+		return dsa_upstream_port(ds, port);
 | 
						|
+}
 | 
						|
+
 | 
						|
 typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid,
 | 
						|
 			      bool is_static, void *data);
 | 
						|
 struct dsa_switch_ops {
 | 
						|
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
 | 
						|
index a1917025e155..b7c6da2f1f08 100644
 | 
						|
--- a/net/dsa/dsa2.c
 | 
						|
+++ b/net/dsa/dsa2.c
 | 
						|
@@ -255,6 +255,24 @@ static void dsa_tree_teardown_default_cpu(struct dsa_switch_tree *dst)
 | 
						|
 	dst->cpu_dp = NULL;
 | 
						|
 }
 | 
						|
 
 | 
						|
+static int dsa_user_parse(struct dsa_port *port, u32 index,
 | 
						|
+			  struct dsa_switch *ds)
 | 
						|
+{
 | 
						|
+	struct device_node *cpu_port;
 | 
						|
+	const unsigned int *cpu_port_reg;
 | 
						|
+	int cpu_port_index;
 | 
						|
+
 | 
						|
+	cpu_port = of_parse_phandle(port->dn, "default_cpu", 0);
 | 
						|
+	if (cpu_port) {
 | 
						|
+		cpu_port_reg = of_get_property(cpu_port, "reg", NULL);
 | 
						|
+		if (!cpu_port_reg)
 | 
						|
+			return -EINVAL;
 | 
						|
+		cpu_port_index = be32_to_cpup(cpu_port_reg);
 | 
						|
+		ds->ports[index].upstream = cpu_port_index;
 | 
						|
+	}
 | 
						|
+	return 0;
 | 
						|
+}
 | 
						|
+
 | 
						|
 static int dsa_port_setup(struct dsa_port *dp)
 | 
						|
 {
 | 
						|
 	struct dsa_switch *ds = dp->ds;
 | 
						|
-- 
 | 
						|
2.19.1
 | 
						|
 |