[openwrt/openwrt] realtek: cleanup rtl83{8x,9x}_enable_learning/flood

LEDE Commits lede-commits at lists.infradead.org
Sat Oct 8 03:05:30 PDT 2022


svanheule pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/629f2de1a772bbfc6bbc37a3aacb67805dc9fb39

commit 629f2de1a772bbfc6bbc37a3aacb67805dc9fb39
Author: INAGAKI Hiroshi <musashino.open at gmail.com>
AuthorDate: Sat Sep 17 13:30:05 2022 +0900

    realtek: cleanup rtl83{8x,9x}_enable_learning/flood
    
    In *_enable_learning() only address learning should be configured, so
    remove enabling forwarding. Forwarding is configured by the respective
    *_enable_flood() functions.
    
    Clean up both functions for RTL838x and RTL839x, and fix the comment on
    the number of entries.
    
    Signed-off-by: INAGAKI Hiroshi <musashino.open at gmail.com>
    [squash RTL838x, RTL839x changes]
    Signed-off-by: Sander Vanheule <sander at svanheule.net>
---
 .../files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c   | 32 +++++++-------------
 .../files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c   | 34 +++++++---------------
 2 files changed, 22 insertions(+), 44 deletions(-)

diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c
index 76b6cde7be..93fab7e6e3 100644
--- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c
+++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c
@@ -515,32 +515,22 @@ static void rtl838x_l2_learning_setup(void)
 
 static void rtl838x_enable_learning(int port, bool enable)
 {
-	// Limit learning to maximum: 32k entries, after that just flood (bits 0-1)
+	// Limit learning to maximum: 16k entries
 
-	if (enable)  {
-		// flood after 32k entries
-		sw_w32((0x3fff << 2) | 0, RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
-	} else {
-		// just forward
-		sw_w32(0, RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
-	}
+	sw_w32_mask(0x3fff << 2, enable ? (0x3fff << 2) : 0,
+		    RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
 }
 
 static void rtl838x_enable_flood(int port, bool enable)
 {
-	u32 flood_mask = sw_r32(RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
-
-	if (enable)  {
-		// flood
-		flood_mask &= ~3;
-		flood_mask |= 0;
-		sw_w32(flood_mask, RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
-	} else {
-		// drop (bit 1)
-		flood_mask &= ~3;
-		flood_mask |= 1;
-		sw_w32(flood_mask, RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
-	}
+	/*
+	 * 0: Forward
+	 * 1: Disable
+	 * 2: to CPU
+	 * 3: Copy to CPU
+	 */
+	sw_w32_mask(0x3, enable ? 0 : 1,
+		    RTL838X_L2_PORT_LRN_CONSTRT + (port << 2));
 }
 
 static void rtl838x_enable_mcast_flood(int port, bool enable)
diff --git a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c
index 7b838cb76b..199ba347da 100644
--- a/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c
+++ b/target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl839x.c
@@ -560,34 +560,22 @@ static void rtl839x_l2_learning_setup(void)
 
 static void rtl839x_enable_learning(int port, bool enable)
 {
-	// Limit learning to maximum: 32k entries, after that just flood (bits 0-1)
-
-	if (enable) {
-		// flood after 32k entries
-		sw_w32((0x7fff << 2) | 0, RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
-	} else {
-		// just forward
-		sw_w32(0, RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
-	}
+	// Limit learning to maximum: 32k entries
 
+	sw_w32_mask(0x7fff << 2, enable ? (0x7fff << 2) : 0,
+		    RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
 }
 
 static void rtl839x_enable_flood(int port, bool enable)
 {
-	u32 flood_mask = sw_r32(RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
-
-	if (enable)  {
-		// flood
-		flood_mask &= ~3;
-		flood_mask |= 0;
-		sw_w32(flood_mask, RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
-	} else {
-		// drop (bit 1)
-		flood_mask &= ~3;
-		flood_mask |= 1;
-		sw_w32(flood_mask, RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
-	}
-
+	/*
+	 * 0: Forward
+	 * 1: Disable
+	 * 2: to CPU
+	 * 3: Copy to CPU
+	 */
+	sw_w32_mask(0x3, enable ? 0 : 1,
+		    RTL839X_L2_PORT_LRN_CONSTRT + (port << 2));
 }
 
 static void rtl839x_enable_mcast_flood(int port, bool enable)




More information about the lede-commits mailing list