]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: rtl93xx: dsa: Add support for port based mirroring 20264/head
authorSharadanand Karanjkar <sk@simonwunderlich.de>
Tue, 15 Jul 2025 17:48:05 +0000 (19:48 +0200)
committerRobert Marko <robimarko@gmail.com>
Fri, 3 Oct 2025 17:25:26 +0000 (19:25 +0200)
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>
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/dsa.c
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c

index 288e5361e45c973a398ab2c34752785ef763bb0a..d37a372c0613d773ec11cc7bb995957f50ff14d9 100644 (file)
@@ -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,
index 5ca29e56b11c1710d092cf20ec7653f586fba002..b9639a6b3b3812e917eff809268c458d7772a892 100644 (file)
@@ -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,
index 54f2dc9720ec1c24f627e5ed2f9f44e77abc2cfe..e01e98a2e94e436b2124a0762c4979a4fbe0822d 100644 (file)
@@ -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,