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>
This commit is contained in:
Sharadanand Karanjkar
2025-07-15 19:48:05 +02:00
committed by Robert Marko
parent 8e2284857d
commit be84bb3a78
3 changed files with 53 additions and 0 deletions

View 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,

View 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,

View 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,