Skip to contentSkip to conversation

net: dsa: microchip: Fix reserved multicast address table programming

PATCH Superseded [email protected] 3 participants 4 messages Nov 1, 2025 – Nov 5, 2025

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: dsa: microchip: Fix reserved multicast address table programming

From: Tristram Ha <[email protected]>

KSZ9477/KSZ9897 and LAN937X families of switches use a reserved multicast address table for some specific forwarding with some multicast addresses, like the one used in STP. The hardware assumes the host port is the last port in KSZ9897 family and port 5 in LAN937X family. Most of the time this assumption is correct but not in other cases like KSZ9477. Originally the function just setups the first entry, but the others still need update, especially for one common multicast address that is used by PTP operation.

LAN937x also uses different register bits when accessing the reserved table.

Fixes 457c182af597 ("net: dsa: microchip: generic access to ksz9477 static and reserved table")
---
 drivers/net/dsa/microchip/ksz9477.c     | 103 ++++++++++++++++++++----
 drivers/net/dsa/microchip/ksz9477_reg.h |   3 +-
 drivers/net/dsa/microchip/ksz_common.c  |   4 +
 drivers/net/dsa/microchip/ksz_common.h  |   2 +
 4 files changed, 96 insertions(+), 16 deletions(-)
drivers/net/dsa/microchip/ksz9477.c +89 -14
index d747ea1c41a7..9b6731de52a7 100644
@@ -1355,8 +1355,12 @@ void ksz9477_config_cpu_port(struct dsa_switch *ds)
 	}
 }
 
+static u8 reserved_mcast_map[8] = { 0, 1, 3, 16, 32, 33, 2, 17 };
+
 int ksz9477_enable_stp_addr(struct ksz_device *dev)
 {
+	u8 all_ports = (1 << dev->info->port_cnt) - 1;
+	u8 i, def_port, ports, update;
 	const u32 *masks;
 	u32 data;
 	int ret;
@@ -1366,23 +1370,94 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
 	/* Enable Reserved multicast table */
 	ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);
 
-	/* Set the Override bit for forwarding BPDU packet to CPU */
-	ret = ksz_write32(dev, REG_SW_ALU_VAL_B,
-			  ALU_V_OVERRIDE | BIT(dev->cpu_port));
-	if (ret < 0)
-		return ret;
+	/* The reserved multicast address table has 8 entries.  Each entry has
+	 * a default value of which port to forward.  It is assumed the host
+	 * port is the last port in most of the switches, but that is not the
+	 * case for KSZ9477 or maybe KSZ9897.  For LAN937X family the default
+	 * port is port 5, the first RGMII port.  It is okay for LAN9370, a
+	 * 5-port switch, but may not be correct for the other 8-port
+	 * versions.  It is necessary to update the whole table to forward to
+	 * the right ports.
+	 * Furthermore PTP messages can use a reserved multicast address and
+	 * the host will not receive them if this table is not correct.
+	 */
+	def_port = BIT(dev->info->port_cnt - 1);
+	if (is_lan937x(dev))
+		def_port = BIT(4);
+	for (i = 0; i < 8; i++) {
+		data = reserved_mcast_map[i] <<
+			dev->info->shifts[ALU_STAT_INDEX];
+		data |= ALU_STAT_START |
+			masks[ALU_STAT_DIRECT] |
+			masks[ALU_RESV_MCAST_ADDR] |
+			masks[ALU_STAT_READ];
+		ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
+		if (ret < 0)
+			return ret;
 
-	data = ALU_STAT_START | ALU_RESV_MCAST_ADDR | masks[ALU_STAT_WRITE];
+		/* wait to be finished */
+		ret = ksz9477_wait_alu_sta_ready(dev);
+		if (ret < 0)
+			return ret;
 
-	ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
-	if (ret < 0)
-		return ret;
+		ret = ksz_read32(dev, REG_SW_ALU_VAL_B, &data);
+		if (ret < 0)
+			return ret;
 
-	/* wait to be finished */
-	ret = ksz9477_wait_alu_sta_ready(dev);
-	if (ret < 0) {
-		dev_err(dev->dev, "Failed to update Reserved Multicast table\n");
-		return ret;
+		ports = data & dev->port_mask;
+		if (ports == def_port) {
+			/* Change the host port. */
+			update = BIT(dev->cpu_port);
+
+			/* The host port is correct so no need to update the
+			 * the whole table but the first entry still needs to
+			 * set the Override bit for STP.
+			 */
+			if (update == def_port && i == 0)
+				ports = 0;
+		} else if (ports == 0) {
+			/* No change to entry. */
+			update = 0;
+		} else if (ports == (all_ports & ~def_port)) {
+			/* This entry does not forward to host port.  But if
+			 * the host needs to process protocols like MVRP and
+			 * MMRP the host port needs to be set.
+			 */
+			update = ports & ~BIT(dev->cpu_port);
+			update |= def_port;
+		} else {
+			/* No change to entry. */
+			update = ports;
+		}
+		if (update != ports) {
+			data &= ~dev->port_mask;
+			data |= update;
+			/* Set Override bit for STP in the first entry. */
+			if (i == 0)
+				data |= ALU_V_OVERRIDE;
+			ret = ksz_write32(dev, REG_SW_ALU_VAL_B, data);
+			if (ret < 0)
+				return ret;
+
+			data = reserved_mcast_map[i] <<
+			       dev->info->shifts[ALU_STAT_INDEX];
+			data |= ALU_STAT_START |
+				masks[ALU_STAT_DIRECT] |
+				masks[ALU_RESV_MCAST_ADDR] |
+				masks[ALU_STAT_WRITE];
+			ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
+			if (ret < 0)
+				return ret;
+
+			/* wait to be finished */
+			ret = ksz9477_wait_alu_sta_ready(dev);
+			if (ret < 0)
+				return ret;
+
+			/* No need to check the whole table. */
+			if (i == 0 && !ports)
+				break;
+		}
 	}
 
 	return 0;
drivers/net/dsa/microchip/ksz9477_reg.h +1 -2
index ff579920078e..61ea11e3338e 100644
@@ -2,7 +2,7 @@
 /*
  * Microchip KSZ9477 register definitions
  *
- * Copyright (C) 2017-2024 Microchip Technology Inc.
+ * Copyright (C) 2017-2025 Microchip Technology Inc.
  */
 
 #ifndef __KSZ9477_REGS_H
@@ -397,7 +397,6 @@
 
 #define ALU_RESV_MCAST_INDEX_M		(BIT(6) - 1)
 #define ALU_STAT_START			BIT(7)
-#define ALU_RESV_MCAST_ADDR		BIT(1)
 
 #define REG_SW_ALU_VAL_A		0x0420
 
drivers/net/dsa/microchip/ksz_common.c +4 -0
index a962055bfdbd..933ae8dc6337 100644
@@ -808,6 +808,8 @@ static const u16 ksz9477_regs[] = {
 static const u32 ksz9477_masks[] = {
 	[ALU_STAT_WRITE]		= 0,
 	[ALU_STAT_READ]			= 1,
+	[ALU_STAT_DIRECT]		= 0,
+	[ALU_RESV_MCAST_ADDR]		= BIT(1),
 	[P_MII_TX_FLOW_CTRL]		= BIT(5),
 	[P_MII_RX_FLOW_CTRL]		= BIT(3),
 };
@@ -835,6 +837,8 @@ static const u8 ksz9477_xmii_ctrl1[] = {
 static const u32 lan937x_masks[] = {
 	[ALU_STAT_WRITE]		= 1,
 	[ALU_STAT_READ]			= 2,
+	[ALU_STAT_DIRECT]		= BIT(3),
+	[ALU_RESV_MCAST_ADDR]		= BIT(2),
 	[P_MII_TX_FLOW_CTRL]		= BIT(5),
 	[P_MII_RX_FLOW_CTRL]		= BIT(3),
 };
drivers/net/dsa/microchip/ksz_common.h +2 -0
index a1eb39771bb9..c65188cd3c0a 100644
@@ -294,6 +294,8 @@ enum ksz_masks {
 	DYNAMIC_MAC_TABLE_TIMESTAMP,
 	ALU_STAT_WRITE,
 	ALU_STAT_READ,
+	ALU_STAT_DIRECT,
+	ALU_RESV_MCAST_ADDR,
 	P_MII_TX_FLOW_CTRL,
 	P_MII_RX_FLOW_CTRL,
 };
Signature · 1 line
2.34.1
Tested-by on v1 1/1
#1 lore raw

Hi Tristram,

Quoted 216 lines

From: Tristram Ha <[email protected]>

KSZ9477/KSZ9897 and LAN937X families of switches use a reserved multicast address table for some specific forwarding with some multicast addresses, like the one used in STP. The hardware assumes the host port is the last port in KSZ9897 family and port 5 in LAN937X family. Most of the time this assumption is correct but not in other cases like KSZ9477. Originally the function just setups the first entry, but the others still need update, especially for one common multicast address that is used by PTP operation.

LAN937x also uses different register bits when accessing the reserved table.

Fixes 457c182af597 ("net: dsa: microchip: generic access to ksz9477

static and reserved table") Signed-off-by: Tristram Ha <[email protected]> ---

 drivers/net/dsa/microchip/ksz9477.c     | 103
++++++++++++++++++++---- drivers/net/dsa/microchip/ksz9477_reg.h |
3 +- drivers/net/dsa/microchip/ksz_common.c  |   4 +
 drivers/net/dsa/microchip/ksz_common.h  |   2 +
 4 files changed, 96 insertions(+), 16 deletions(-)
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/ksz9477.c index d747ea1c41a7..9b6731de52a7 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1355,8 +1355,12 @@ void ksz9477_config_cpu_port(struct dsa_switch *ds) }
}

drivers/net/dsa/microchip/ksz9477.c +5 -5
+static u8 reserved_mcast_map[8] = { 0, 1, 3, 16, 32, 33, 2, 17 };
+
 int ksz9477_enable_stp_addr(struct ksz_device *dev)
 {
+	u8 all_ports = (1 << dev->info->port_cnt) - 1;
+	u8 i, def_port, ports, update;
 	const u32 *masks;
 	u32 data;
 	int ret;
@@ -1366,23 +1370,94 @@ int ksz9477_enable_stp_addr(struct ksz_device
 *dev) /* Enable Reserved multicast table */
 	ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);
 
-	/* Set the Override bit for forwarding BPDU packet to CPU */
-	ret = ksz_write32(dev, REG_SW_ALU_VAL_B,
-			  ALU_V_OVERRIDE | BIT(dev->cpu_port));
-	if (ret < 0)
-		return ret;
+	/* The reserved multicast address table has 8 entries.  Each

entry has

(quoted diff) +1 -0
+	 * a default value of which port to forward.  It is assumed

the host

(quoted diff) +1 -0
+	 * port is the last port in most of the switches, but that

is not the

(quoted diff) +1 -0
+	 * case for KSZ9477 or maybe KSZ9897.  For LAN937X family

the default

(quoted diff) +1 -0
+	 * port is port 5, the first RGMII port.  It is okay for

LAN9370, a

(quoted diff) +2 -0
+	 * 5-port switch, but may not be correct for the other 8-port
+	 * versions.  It is necessary to update the whole table to

forward to

(quoted diff) +2 -0
+	 * the right ports.
+	 * Furthermore PTP messages can use a reserved multicast

address and

(quoted diff) +1 -0
+	 * the host will not receive them if this table is not

correct.

drivers/net/dsa/microchip/ksz9477.c +12 -0
+	 */
+	def_port = BIT(dev->info->port_cnt - 1);
+	if (is_lan937x(dev))
+		def_port = BIT(4);
+	for (i = 0; i < 8; i++) {
+		data = reserved_mcast_map[i] <<
+			dev->info->shifts[ALU_STAT_INDEX];
+		data |= ALU_STAT_START |
+			masks[ALU_STAT_DIRECT] |
+			masks[ALU_RESV_MCAST_ADDR] |
+			masks[ALU_STAT_READ];
+		ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4,

data);

drivers/net/dsa/microchip/ksz9477.c +2 -1
+		if (ret < 0)
+			return ret;
 
-	data = ALU_STAT_START | ALU_RESV_MCAST_ADDR |

masks[ALU_STAT_WRITE];

drivers/net/dsa/microchip/ksz9477.c +7 -7
+		/* wait to be finished */
+		ret = ksz9477_wait_alu_sta_ready(dev);
+		if (ret < 0)
+			return ret;
 
-	ret = ksz_write32(dev, REG_SW_ALU_STAT_CTRL__4, data);
-	if (ret < 0)
-		return ret;
+		ret = ksz_read32(dev, REG_SW_ALU_VAL_B, &data);
+		if (ret < 0)
+			return ret;
 
-	/* wait to be finished */
-	ret = ksz9477_wait_alu_sta_ready(dev);
-	if (ret < 0) {
-		dev_err(dev->dev, "Failed to update Reserved

Multicast table\n");

drivers/net/dsa/microchip/ksz9477.c +6 -1
-		return ret;
+		ports = data & dev->port_mask;
+		if (ports == def_port) {
+			/* Change the host port. */
+			update = BIT(dev->cpu_port);
+
+			/* The host port is correct so no need to

update the

(quoted diff) +1 -0
+			 * the whole table but the first entry still

needs to

drivers/net/dsa/microchip/ksz9477.c +10 -0
+			 * set the Override bit for STP.
+			 */
+			if (update == def_port && i == 0)
+				ports = 0;
+		} else if (ports == 0) {
+			/* No change to entry. */
+			update = 0;
+		} else if (ports == (all_ports & ~def_port)) {
+			/* This entry does not forward to host port.
 But if
+			 * the host needs to process protocols like

MVRP and

drivers/net/dsa/microchip/ksz9477.c +12 -0
+			 * MMRP the host port needs to be set.
+			 */
+			update = ports & ~BIT(dev->cpu_port);
+			update |= def_port;
+		} else {
+			/* No change to entry. */
+			update = ports;
+		}
+		if (update != ports) {
+			data &= ~dev->port_mask;
+			data |= update;
+			/* Set Override bit for STP in the first

entry. */

drivers/net/dsa/microchip/ksz9477.c +3 -0
+			if (i == 0)
+				data |= ALU_V_OVERRIDE;
+			ret = ksz_write32(dev, REG_SW_ALU_VAL_B,

data);

drivers/net/dsa/microchip/ksz9477.c +10 -0
+			if (ret < 0)
+				return ret;
+
+			data = reserved_mcast_map[i] <<
+			       dev->info->shifts[ALU_STAT_INDEX];
+			data |= ALU_STAT_START |
+				masks[ALU_STAT_DIRECT] |
+				masks[ALU_RESV_MCAST_ADDR] |
+				masks[ALU_STAT_WRITE];
+			ret = ksz_write32(dev,

REG_SW_ALU_STAT_CTRL__4, data);

drivers/net/dsa/microchip/ksz9477.c +12 -0
+			if (ret < 0)
+				return ret;
+
+			/* wait to be finished */
+			ret = ksz9477_wait_alu_sta_ready(dev);
+			if (ret < 0)
+				return ret;
+
+			/* No need to check the whole table. */
+			if (i == 0 && !ports)
+				break;
+		}
 	}
 
 	return 0;
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/ksz9477_reg.h index ff579920078e..61ea11e3338e 100644 --- a/drivers/net/dsa/microchip/ksz9477_reg.h +++ b/drivers/net/dsa/microchip/ksz9477_reg.h @@ -2,7 +2,7 @@
/*
* Microchip KSZ9477 register definitions
*
- * Copyright (C) 2017-2024 Microchip Technology Inc.
+ * Copyright (C) 2017-2025 Microchip Technology Inc. */

#ifndef __KSZ9477_REGS_H

drivers/net/dsa/microchip/ksz9477_reg.h +0 -1
@@ -397,7 +397,6 @@
 
 #define ALU_RESV_MCAST_INDEX_M		(BIT(6) - 1)
 #define ALU_STAT_START			BIT(7)
-#define ALU_RESV_MCAST_ADDR		BIT(1)
 
 #define REG_SW_ALU_VAL_A		0x0420
 
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/ksz_common.c index a962055bfdbd..933ae8dc6337 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -808,6 +808,8 @@ static const u16 ksz9477_regs[] = { static const u32 ksz9477_masks[] = {

drivers/net/dsa/microchip/ksz_common.c +4 -0
 	[ALU_STAT_WRITE]		= 0,
 	[ALU_STAT_READ]			= 1,
+	[ALU_STAT_DIRECT]		= 0,
+	[ALU_RESV_MCAST_ADDR]		= BIT(1),
 	[P_MII_TX_FLOW_CTRL]		= BIT(5),
 	[P_MII_RX_FLOW_CTRL]		= BIT(3),
 };
@@ -835,6 +837,8 @@ static const u8 ksz9477_xmii_ctrl1[] = {
 static const u32 lan937x_masks[] = {
 	[ALU_STAT_WRITE]		= 1,
 	[ALU_STAT_READ]			= 2,
+	[ALU_STAT_DIRECT]		= BIT(3),
+	[ALU_RESV_MCAST_ADDR]		= BIT(2),
 	[P_MII_TX_FLOW_CTRL]		= BIT(5),
 	[P_MII_RX_FLOW_CTRL]		= BIT(3),
 };
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/ksz_common.h index a1eb39771bb9..c65188cd3c0a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -294,6 +294,8 @@ enum ksz_masks { DYNAMIC_MAC_TABLE_TIMESTAMP,

drivers/net/dsa/microchip/ksz_common.h enum ksz_masks { · line 301

Quoted 7 lines
drivers/net/dsa/microchip/ksz_common.h +2 -0
 	ALU_STAT_WRITE,
 	ALU_STAT_READ,
+	ALU_STAT_DIRECT,
+	ALU_RESV_MCAST_ADDR,
 	P_MII_TX_FLOW_CTRL,
 	P_MII_RX_FLOW_CTRL,
 };

Thank you for the patch.

Now I'm able to synchronize device connected to KSZ9477 (port6 host port).
I've applied and tested this patch on v6.6. LTS kernel (and hopefully it can be backported to LTS kernels as well).

Signature · 10 lines
Best regards,

Lukasz Majewski

--
Nabla Software Engineering GmbH
HRB 40522 Augsburg
Phone: +49 821 45592596
E-Mail: [email protected]
Geschftsfhrer : Stefano Babic
maintainer
#2 lore raw
In reply to [email protected]
Quoted 4 lines
drivers/net/dsa/microchip/ksz9477.c +4 -0
+	/* The reserved multicast address table has 8 entries.  Each entry has
+	 * a default value of which port to forward.  It is assumed the host
+	 * port is the last port in most of the switches, but that is not the
+	 * case for KSZ9477 or maybe KSZ9897.  For LAN937X family the default

drivers/net/dsa/microchip/ksz9477.c int ksz9477_enable_stp_addr(struct ksz_device *dev) · line 1386

Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +10 -0
+	 * port is port 5, the first RGMII port.  It is okay for LAN9370, a
+	 * 5-port switch, but may not be correct for the other 8-port
+	 * versions.  It is necessary to update the whole table to forward to
+	 * the right ports.
+	 * Furthermore PTP messages can use a reserved multicast address and
+	 * the host will not receive them if this table is not correct.
+	 */
+	def_port = BIT(dev->info->port_cnt - 1);
+	if (is_lan937x(dev))
+		def_port = BIT(4);

Why not just def_port = dsa_cpu_ports(ds)?

The aim here is to send frames to the CPU. You then don't need the comment about different switch versions.

drivers/net/dsa/microchip/ksz9477.c int ksz9477_enable_stp_addr(struct ksz_device *dev) · line 1387

Quoted 1 line
drivers/net/dsa/microchip/ksz9477.c +1 -0
+	for (i = 0; i < 8; i++) {

Please replace the 8 with a #define.

Quoted 20 lines
drivers/net/dsa/microchip/ksz9477.c +20 -0
+		if (ports == def_port) {
+			/* Change the host port. */
+			update = BIT(dev->cpu_port);
+
+			/* The host port is correct so no need to update the
+			 * the whole table but the first entry still needs to
+			 * set the Override bit for STP.
+			 */
+			if (update == def_port && i == 0)
+				ports = 0;
+		} else if (ports == 0) {
+			/* No change to entry. */
+			update = 0;
+		} else if (ports == (all_ports & ~def_port)) {
+			/* This entry does not forward to host port.  But if
+			 * the host needs to process protocols like MVRP and
+			 * MMRP the host port needs to be set.
+			 */
+			update = ports & ~BIT(dev->cpu_port);
+			update |= def_port;

drivers/net/dsa/microchip/ksz9477.c int ksz9477_enable_stp_addr(struct ksz_device *dev) · line 1437

Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +10 -0
+		} else {
+			/* No change to entry. */
+			update = ports;
+		}
+		if (update != ports) {
+			data &= ~dev->port_mask;
+			data |= update;
+			/* Set Override bit for STP in the first entry. */
+			if (i == 0)
+				data |= ALU_V_OVERRIDE;

You have already made this comparison once before. Maybe

	update |= ALU_V_OVERRIDE

higher up?

Andrew

#3 lore raw
Quoted 21 lines

Subject: Re: [PATCH net] net: dsa: microchip: Fix reserved multicast address table programming

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 4 lines
drivers/net/dsa/microchip/ksz9477.c +4 -0
+     /* The reserved multicast address table has 8 entries.  Each entry has
+      * a default value of which port to forward.  It is assumed the host
+      * port is the last port in most of the switches, but that is not the
+      * case for KSZ9477 or maybe KSZ9897.  For LAN937X family the default

drivers/net/dsa/microchip/ksz9477.c int ksz9477_enable_stp_addr(struct ksz_device *dev) · line 1386

Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +10 -0
+      * port is port 5, the first RGMII port.  It is okay for LAN9370, a
+      * 5-port switch, but may not be correct for the other 8-port
+      * versions.  It is necessary to update the whole table to forward to
+      * the right ports.
+      * Furthermore PTP messages can use a reserved multicast address and
+      * the host will not receive them if this table is not correct.
+      */
+     def_port = BIT(dev->info->port_cnt - 1);
+     if (is_lan937x(dev))
+             def_port = BIT(4);
Quoted 5 lines

Why not just def_port = dsa_cpu_ports(ds)?

The aim here is to send frames to the CPU. You then don't need the comment about different switch versions.

There are 8 entries in the reserved multicast address table to support multiple multicast addresses. They look like this for 7-port switch:

0=0x40
1=0x00
2=0x40
3=0x7F
4=0x3F
5=0x3F
6=0x40
7=0x3F

For 3-port switch:

0=0x04
1=0x00
2=0x04
3=0x07
4=0x03
5=0x03
6=0x04
7=0x03

When the host port is not the expected last port like in KSZ9477 then some entries in the table need to be updated like the ones with 0x40 and 0x3F port forwarding.

The design of LAN937X is a little bit different in that all host port candidates are in the middle. The first RGMII port starts at 5, probably because there is a 5-port version.

0=0x10
1=0x00
2=0x10
3=0xFF
4=0xEF
5=0xEF
6=0x10
7=0xEF

So when the host port is port 6 or port 4 then the table needs to be changed like this:

0=0x20
1=0x00
2=0x20
3=0xFF
4=0xDF
5=0xDF
6=0x20
7=0xDF

The code is to check each entry and only update it if it is necessary.

On the other hand software knows what the final mapping should be and can just write the required entries.

Quoted 35 lines
Quoted 1 line

+ for (i = 0; i < 8; i++) {

Please replace the 8 with a #define.

Quoted 20 lines
drivers/net/dsa/microchip/ksz9477.c +20 -0
+             if (ports == def_port) {
+                     /* Change the host port. */
+                     update = BIT(dev->cpu_port);
+
+                     /* The host port is correct so no need to update the
+                      * the whole table but the first entry still needs to
+                      * set the Override bit for STP.
+                      */
+                     if (update == def_port && i == 0)
+                             ports = 0;
+             } else if (ports == 0) {
+                     /* No change to entry. */
+                     update = 0;
+             } else if (ports == (all_ports & ~def_port)) {
+                     /* This entry does not forward to host port.  But if
+                      * the host needs to process protocols like MVRP and
+                      * MMRP the host port needs to be set.
+                      */
+                     update = ports & ~BIT(dev->cpu_port);
+                     update |= def_port;

drivers/net/dsa/microchip/ksz9477.c int ksz9477_enable_stp_addr(struct ksz_device *dev) · line 1437

Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +10 -0
+             } else {
+                     /* No change to entry. */
+                     update = ports;
+             }
+             if (update != ports) {
+                     data &= ~dev->port_mask;
+                     data |= update;
+                     /* Set Override bit for STP in the first entry. */
+                     if (i == 0)
+                             data |= ALU_V_OVERRIDE;
Quoted 5 lines

You have already made this comparison once before. Maybe

        update |= ALU_V_OVERRIDE

higher up?

The first entry is used for STP, so the override bit needs to be set regardless the host port is same or not as the host needs to receive BPDU even when the port receive is turned off.

The six entry is responsible for multiple multicast addresses including 01:80:C2:00:00:0E, which is used for Layer 2 Pdelay PTP messages. The override bit also needs to be set as it is required to receive such PTP messages even though the port is closed. This change will be updated in next patch.