diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
index 2b563e44945413b95941776146b05399cda11ab8..095830fb5273ed4164af7955a5485290bf1e9c6e 100644
--- a/drivers/net/dsa/microchip/ksz9477.c
+++ b/drivers/net/dsa/microchip/ksz9477.c
@@ -768,6 +768,19 @@ int ksz9477_port_vlan_del(struct dsa_switch *ds, int port,
return 0;
}
+static bool ksz9477_link_local_is_trapped(struct ksz_device *dev,
+ const unsigned char *addr)
+{
+ return is_link_local_ether_addr(addr) &&
+ (dev->link_local_to_cpu & BIT(addr[5]));
+}
+
+/* The trap already sends these frames to the CPU */
+static int ksz9477_link_local_entry_ret(struct dsa_switch *ds, int port)
+{
+ return dsa_is_user_port(ds, port) ? -EOPNOTSUPP : 0;
+}
+
int ksz9477_fdb_add(struct dsa_switch *ds, int port,
const unsigned char *addr, u16 vid, struct dsa_db db)
{@@ -776,6 +789,9 @@ int ksz9477_fdb_add(struct dsa_switch *ds, int port,
u32 data;
int ret = 0;
+ if (ksz9477_link_local_is_trapped(dev, addr))
+ return ksz9477_link_local_entry_ret(ds, port);
+
mutex_lock(&dev->alu_mutex);
/* find any entry with mac & vid */
@@ -840,6 +856,10 @@ int ksz9477_fdb_del(struct dsa_switch *ds, int port,
u32 data;
int ret = 0;
+ /* never written, see ksz9477_link_local_entry_ret() */
+ if (ksz9477_link_local_is_trapped(dev, addr))
+ return 0;
+
mutex_lock(&dev->alu_mutex);
/* read any entry with mac & vid */
@@ -989,6 +1009,9 @@ int ksz9477_mdb_add(struct dsa_switch *ds, int port,
u32 mac_hi, mac_lo;
int err = 0;
+ if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+ return ksz9477_link_local_entry_ret(ds, port);
+
shifts = dev->info->shifts;
masks = dev->info->masks;
@@ -1069,6 +1092,10 @@ int ksz9477_mdb_del(struct dsa_switch *ds, int port,
int index;
u32 data;
+ /* never written, see ksz9477_link_local_entry_ret() */
+ if (ksz9477_link_local_is_trapped(dev, mdb->addr))
+ return 0;
+
shifts = dev->info->shifts;
masks = dev->info->masks;
@@ -1554,6 +1581,16 @@ static void ksz9477_config_cpu_port(struct dsa_switch *ds)
static u8 reserved_mcast_map[RESV_MCAST_CNT] = { 0, 1, 3, 16, 32, 33, 2, 17 };
+/* Link-local addresses (bit X: 01:80:C2:00:00:0X) of each entry of the
+ * reserved multicast table, indexed like reserved_mcast_map.
+ */
+static const u16 ksz9477_resv_mcast_link_local[RESV_MCAST_CNT] = {
+ [0] = BIT(0), /* STP BPDUs */
+ [1] = BIT(1), /* MAC control (e.g. PAUSE), dropped */
+ [2] = BIT(3), /* 802.1X (EAPOL) */
+ [6] = BIT(2) | GENMASK(15, 4), /* LACP, LLDP and others */
+};
+
int ksz9477_enable_stp_addr(struct ksz_device *dev)
{
u8 i, ports, update;@@ -1563,6 +1600,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
int ret;
masks = dev->info->masks;
+ dev->link_local_to_cpu = 0;
/* Enable Reserved multicast table */
ksz_cfg(dev, REG_SW_LUE_CTRL_0, SW_RESV_MCAST_ENABLE, true);
@@ -1648,6 +1686,14 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev)
if (ret < 0)
return ret;
}
+
+ /* Record entry i only after it is written, so that the bitmap
+ * matches the switch if a later write fails.
+ */
+ if (update == BIT(dev->cpu_port)) {
+ dev->link_local_to_cpu |=
+ ksz9477_resv_mcast_link_local[i];
+ }
}
return 0;diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8819670cbb053eeb73ea4a7685303d9849bd6efb..7b96d110b1f64f4226ee7a371da38cd7e5b3767a 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -243,6 +243,8 @@ struct ksz_device {
u16 mirror_rx;
u16 mirror_tx;
u16 port_mask;
+ /* link-local groups sent to the CPU only, bit X: 01:80:C2:00:00:0X */
+ u16 link_local_to_cpu;
struct mutex lock_irq; /* IRQ Access */
struct ksz_irq girq;
struct ksz_ptp_data ptp_data;
--
2.47.3