diff options
| author | Sharadanand Karanjkar | 2025-07-15 17:48:05 +0000 |
|---|---|---|
| committer | Robert Marko | 2025-10-03 17:25:26 +0000 |
| commit | be84bb3a7808cefb906ba50ecab5170ce4623040 (patch) | |
| tree | 9a101e84ee333bb16d6cd4379c5007ce8deb7622 | |
| parent | 8e2284857d386200cde05a34d934815896c44a8e (diff) | |
| download | openwrt-be84bb3a7808cefb906ba50ecab5170ce4623040.tar.gz | |
realtek: rtl93xx: dsa: Add support for port based mirroring
The RTL930X and RTL931X SoCs support port-based, flow-based, and
RSPAN-based mirroring. Like for other SoCs from the realtek target, only
the port based port mirroring can be exposed using Linux's tc subsystem.
The port_mirror_add() implementation was updated with the following
considerations for RTL93xx SoCs:
* mirrored packets must pass through the TX pipeline of the mirroring
port, so they are subject to configuration such as VLAN tagging,
remarking, and EVC
* when a packet hits both source ports (SPM) and destination port (DPM) of
a mirror group, the egress port traffic will be mirrored
The port_mirror_del() function doesn't require any modifications.
Signed-off-by: Sharadanand Karanjkar <sk@simonwunderlich.de>
Co-developed-by: Sven Eckelmann <se@simonwunderlich.de>
Signed-off-by: Sven Eckelmann <se@simonwunderlich.de>
Link: https://github.com/openwrt/openwrt/pull/20264
Signed-off-by: Robert Marko <robimarko@gmail.com>
3 files changed, 53 insertions, 0 deletions
diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c index 288e5361e4..d37a372c06 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c @@ -2647,6 +2647,9 @@ const struct dsa_switch_ops rtl930x_switch_ops = { .port_mdb_add = rtl83xx_port_mdb_add, .port_mdb_del = rtl83xx_port_mdb_del, + .port_mirror_add = rtldsa_port_mirror_add, + .port_mirror_del = rtldsa_port_mirror_del, + .port_lag_change = rtl83xx_port_lag_change, .port_lag_join = rtl83xx_port_lag_join, .port_lag_leave = rtl83xx_port_lag_leave, diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c index 5ca29e56b1..b9639a6b3b 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c @@ -166,6 +166,30 @@ static inline int rtl930x_l2_port_new_sa_fwd(int p) return RTL930X_L2_PORT_NEW_SA_FWD(p); } +static int rtldsa_930x_get_mirror_config(struct rtldsa_mirror_config *config, + int group, int port) +{ + config->ctrl = RTL930X_MIR_CTRL + group * 4; + config->spm = RTL930X_MIR_SPM_CTRL + group * 4; + config->dpm = RTL930X_MIR_DPM_CTRL + group * 4; + + /* Enable mirroring to destination port */ + config->val = BIT(0); + config->val |= port << 9; + + /* mirror mode: let mirrored packets follow TX settings of + * mirroring port + */ + config->val |= BIT(5); + + /* direction of traffic to be mirrored when a packet + * hits both SPM and DPM ports: prefer egress + */ + config->val |= BIT(4); + + return 0; +} + inline static int rtl930x_trk_mbr_ctr(int group) { return RTL930X_TRK_MBR_CTRL + (group << 2); @@ -2446,6 +2470,7 @@ const struct rtl838x_reg rtl930x_reg = { .mac_port_ctrl = rtl930x_mac_port_ctrl, .l2_port_new_salrn = rtl930x_l2_port_new_salrn, .l2_port_new_sa_fwd = rtl930x_l2_port_new_sa_fwd, + .get_mirror_config = rtldsa_930x_get_mirror_config, .read_l2_entry_using_hash = rtl930x_read_l2_entry_using_hash, .write_l2_entry_using_hash = rtl930x_write_l2_entry_using_hash, .read_cam = rtl930x_read_cam, diff --git a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c index 54f2dc9720..e01e98a2e9 100644 --- a/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c +++ b/target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c @@ -280,6 +280,30 @@ static inline int rtl931x_l2_port_new_sa_fwd(int p) return RTL931X_L2_PORT_NEW_SA_FWD(p); } +static int rtldsa_931x_get_mirror_config(struct rtldsa_mirror_config *config, + int group, int port) +{ + config->ctrl = RTL931X_MIR_CTRL + group * 4; + config->spm = RTL931X_MIR_SPM_CTRL + group * 8; + config->dpm = RTL931X_MIR_DPM_CTRL + group * 8; + + /* Enable mirroring to destination port */ + config->val = BIT(0); + config->val |= port << 9; + + /* mirror mode: let mirrored packets follow TX settings of + * mirroring port + */ + config->val |= BIT(5); + + /* direction of traffic to be mirrored when a packet + * hits both SPM and DPM ports: prefer egress + */ + config->val |= BIT(4); + + return 0; +} + irqreturn_t rtl931x_switch_irq(int irq, void *dev_id) { struct dsa_switch *ds = dev_id; @@ -1561,6 +1585,7 @@ const struct rtl838x_reg rtl931x_reg = { .mac_port_ctrl = rtl931x_mac_port_ctrl, .l2_port_new_salrn = rtl931x_l2_port_new_salrn, .l2_port_new_sa_fwd = rtl931x_l2_port_new_sa_fwd, + .get_mirror_config = rtldsa_931x_get_mirror_config, .read_l2_entry_using_hash = rtl931x_read_l2_entry_using_hash, .write_l2_entry_using_hash = rtl931x_write_l2_entry_using_hash, .read_cam = rtl931x_read_cam, |