diff mbox series

[RFC,net-next,2/6] net: dsa: add groundwork for cross chip mirroring

Message ID 7133d2507c0619e7727c1c44250241fdc9625d2c.1704449760.git.ante.knezic@helmholz.de (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series add dsa cross-chip port mirroring | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1131 this patch: 1131
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1146 this patch: 1146
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1158 this patch: 1158
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 62 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Ante Knezic Jan. 5, 2024, 10:46 a.m. UTC
cross chip mirroring require routing mirrored data
from source to destination switch. Add the necessary
groundwork.

Signed-off-by: Ante Knezic <ante.knezic@helmholz.de>
---
 include/net/dsa.h | 18 ++++++++++++++++++
 net/dsa/dsa.c     | 14 ++++++++++++++
 2 files changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/include/net/dsa.h b/include/net/dsa.h
index c1fbe89f8f81..aa0e97150bc3 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -162,6 +162,9 @@  struct dsa_switch_tree {
 
 	/* Track the largest switch index within a tree */
 	unsigned int last_switch;
+
+	/* List of port mirror routes */
+	struct list_head mirrors;
 };
 
 /* LAG IDs are one-based, the dst->lags array is zero-based */
@@ -368,6 +371,21 @@  struct dsa_vlan {
 	struct list_head list;
 };
 
+struct dsa_mirror {
+	struct list_head list;
+	const struct dsa_port *from_dp;
+	const struct dsa_port *to_dp;
+	bool ingress;
+	struct list_head route;
+};
+
+struct dsa_route {
+	struct list_head list;
+	int sw_index;
+	int from_local_p;
+	int to_local_p;
+};
+
 struct dsa_switch {
 	struct device *dev;
 
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index ac7be864e80d..304c7100cf55 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -228,6 +228,8 @@  static struct dsa_switch_tree *dsa_tree_alloc(int index)
 
 	kref_init(&dst->refcount);
 
+	INIT_LIST_HEAD(&dst->mirrors);
+
 	return dst;
 }
 
@@ -923,6 +925,8 @@  static int dsa_tree_setup(struct dsa_switch_tree *dst)
 static void dsa_tree_teardown(struct dsa_switch_tree *dst)
 {
 	struct dsa_link *dl, *next;
+	struct dsa_mirror *dm, *m;
+	struct dsa_route *dr, *r;
 
 	if (!dst->setup)
 		return;
@@ -942,6 +946,16 @@  static void dsa_tree_teardown(struct dsa_switch_tree *dst)
 		kfree(dl);
 	}
 
+	list_for_each_entry_safe(dm, m, &dst->mirrors, list) {
+		list_for_each_entry_safe(dr, r, &dm->route, list) {
+			list_del(&dr->list);
+			kfree(dr);
+		}
+
+		list_del(&dm->list);
+		kfree(dm);
+	}
+
 	pr_info("DSA: tree %d torn down\n", dst->index);
 
 	dst->setup = false;