Skip to contentSkip to conversation

net: dsa: add DSA support for the LAN9645x switch chip family

PATCH Superseded Jens Emil Schulz Østergaard 3 participants 36 messages Aug 5 – Aug 19

Subsystems (5)

v11 of 17 Superseded Latest is v17 →

lore
Share & tools
lore
#0 lore raw

v11 cover net: dsa: add DSA support for the LAN9645x switch chip family

This series provides the Microchip LAN9645X Switch driver.

The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.

The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.

The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.

The chip supports a variety of network features such as

* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing

The LAN9645x family consists of the following SKUs:

LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S

The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.

The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.

This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver

drivers/net/dsa/ocelot/ocelot_ext.c

which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.

The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.

Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.

The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf

This series will deliver the following features:

* Standalone ports
* Bridge forwarding and FDB offloading
* VLAN-aware bridge
* Stats integration

More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:

* Add LAG support.
* Add MDB support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.

For completeness I include tentative plan of planned patches for LAN9645x peripherals:

* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.

---
Changes in v11:
- Update comment about vlan tag hwaccel use in tag driver.
- Bump DSA_TAG_PROTO value in include/net/dsa.h.
- stats: add comment about calling contexts of sw_lock in
lan9645x_stats_get_stats64
- Link to v10: https://lore.kernel.org/r/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com

Changes in v10:
- Individual patches mention specific v10 changes
- Update tag driver after skb ownership model change in DSA taggers.
- Link to v9: https://lore.kernel.org/r/20260708-dsa_lan9645x_switch_driver_base-v9-0-0d1512a326d7@microchip.com

Changes in v9:
- Individual patches mention specific v9 changes
- Drop RGMII muxing to port 4.
- Link to v8: https://lore.kernel.org/r/20260702-dsa_lan9645x_switch_driver_base-v8-0-90228d8bba58@microchip.com

Changes in v8:
- Individual patches mention specific v8 changes
- Do not use the name CPU_PORT for the chips internal CPU port module,
as it collides with the DSA CPU port (the NPI front port). Drop the
CPU_PORT macro and reference the module as lan9645x->num_phys_ports,
mirroring ocelot/felix.
- Reword the port map and related comments to distinguish the chip CPU
port modules (indices 9-10) from the DSA CPU port.
- Add a port_mux_lock mutex to serialize port mux arbitration in
the phylink mac_prepare path.
- Link to v7: https://lore.kernel.org/r/20260603-dsa_lan9645x_switch_driver_base-v7-0-b2f90e676707@microchip.com

Changes in v7:
- Individual patches mention specific v7 changes
- Do not mark the BPDU range 01:80:C2:00:00:0X as offloaded in the tag driver.
- Refactor cpu queue based frame classification to use categories default, trap
and copy, which mirrors usage instead of being based on frame types.
- Add registers ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.
- Use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames.
- Refactor IGMP/MLD/IPMC_CTRL to use new LAN9645X_CPUQ_DEF,
LAN9645X_CPUQ_TRAP and LAN9645X_CPUQ_COPY queues.
- Add __aligned(2) to mac variable in lan9645x_mdb_update_dest.
- Link to v6: https://lore.kernel.org/r/20260527-dsa_lan9645x_switch_driver_base-v6-0-4d409ae64f3c@microchip.com

Changes in v6:
- Individual patches mention specific v6 changes
- Rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34
- Link to v5: https://lore.kernel.org/r/20260518-dsa_lan9645x_switch_driver_base-v5-0-968fbf34ffa3@microchip.com

Changes in v5:
- Individual patches mention specific v5 changes
- Undo offset fix in postpull_rcsum. The original logic was correct for
CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask
- remove unused fields dd_dis and tsn_dis, and add SKU supported port validation
during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully
dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4
and 7.
- rx/tx-internal-delay-ps checked against supported 2ns value
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit
- use ds->ageing_time_max
- use packed p->host_flood_req for atomic r/w
- fix typo in set_ageing_time comment
- include lan9645x->bridge deref under lock in brige_join
- switch -EBUSY to -EINVAL for vlan add/del in the reserved range.
- remove reserved HSR vlan
- lan9645x_mac_init returns error on table init timeout
- add comment about skipping LOCKED entries on fdb dump
- skip igmp/mld redir for npi port
- make lan9645x_stats_init void
- add SCNT_TX_BUFDROP to tx_dropped
- change rmon range {0,64} -> {64, 64}. Runt frames counted elsewhere.
- remove rx_crc, rx_symbol_err from rx_packets, as they are already
counted in SZ_* buckets.
- add defensive cancel_delayed_work_sync in stats_free
- Link to v4: https://lore.kernel.org/r/20260430-dsa_lan9645x_switch_driver_base-v4-0-f1b6005fa8b7@microchip.com

Changes in v4:
- v3 was deferred, but I made some changes based on the Sashiko review
- Individual patches mention specific v4 changes
- Fix offset in postpull_rcsum so prefix eth header is cleared, not
actual eth header, so tag driver works with CHECKSUM_COMPLETE host
NICs
- Fix untagged rx on vlan aware port with pvid
- Add comment to QSYS_RES_CFG configuration
- Phylink_mac_prepare: fix to make sure we can dynamically change rgmii
on port 4
- Move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- Skip WARN_ON in lan9645x_to_port
- set_host_flood changed to per port work to coalesce values and skip
atomic allocations
- Fix clear HOST_PVID vlan membership when a port joins a bridge.
- Explicit default value write to tag type register for untagged frames
- Use lan_rmw for ANA_DROP_CFG
- Add comment for error path in lan9645x_vlan_hw_wr
- Remove mac_entries list and just do direct IO to mac table from
fdb_add/fdb_del.
- Clean up fresh mdb when hw mac table write fails.
- Remove rx_uc and tx_uc from ethtool stats list, as they are derivable
from the eth-mac group
- Split stats_init into stats_alloc and stats_init, use alloc in probe
and init in dsa_setup
- Link to v3: https://lore.kernel.org/r/20260410-dsa_lan9645x_switch_driver_base-v3-0-aadc8595306d@microchip.com

Changes in v3:
- Individual patches mention specific v3 changes.
- Add guard before vlan_remove_tag on xmit
- Add pskb_may_pull checks on rx
- Remove additionalProperties: true in bindings
- Remove unnecessary | from description in bindings
- Change top level $ref to dsa.yaml#/$defs/ethernet-ports
- Use ethernet-ports and ethernet-port
- Move ethernet-ports under properties instead of patternProperties
- Move unevaluatedProperties: false after $ref
- Update bindings example to use ethernet-ports and ethernet-port
- Move DEV_MAC_TAGS_CFG to port setup, instead of vlan config, so vlan
overhead is always included in port frame maxlen calculation.
- Remove code disabling ipv6 on conduit
- Use of_property_read_u32 for {rx,tx}-internal-delay-ps
- Use dsa_user_ports(ds) instead of
GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- Add comment explaining obey vlan
- Allow disabling aging with explicit zero parameters.
- Fix non-forwarding STP states in bridge fwd calculation.
- Restore host flood state on bridge leave.
- Avoid mac_entry dealloc when mac table writes fail.
- Avoid mdb_entry dealloc when mac table writes fail.
- Dealloc mac_entries on deinit.
- Dealloc mdb_entries on deinit.
- Link to v2: https://lore.kernel.org/r/20260324-dsa_lan9645x_switch_driver_base-v2-0-f7504e3b0681@microchip.com

Changes in v2:
- Individual patches have specific v2 changes.
- Ran DSA, and std counters, selftests, which prompted several changes.
The following selftests pass, except for some expected failures:
- bridge_vlan_aware.sh
- bridge_vlan_unaware.sh
- bridge_vlan_mcast.sh
- no_forwarding.sh
- bridge_mdb.sh
- bridge_mld.sh
- test_fdb_stress_test.sh
- .../drivers/net/hw/ethtool_rmon.sh
- .../drivers/net/hw/ethtool_std_stats.sh (from Ioana's series)
- Added new patch for MDB management, as this was required for selftests.
- Added port_set_host_flood to enable unknown traffic to standalone during
promisc/ALL_MULTI (selftests).
- Remove the dubugfs.
- Link to v1: https://lore.kernel.org/r/20260303-dsa_lan9645x_switch_driver_base-v1-0-bff8ca1396f5@microchip.com

---
Jens Emil Schulz Østergaard (9):
net: dsa: add tag driver for LAN9645X
dt-bindings: net: lan9645x: add LAN9645X switch bindings
net: dsa: lan9645x: add autogenerated register macros
net: dsa: lan9645x: add basic dsa driver for LAN9645X
net: dsa: lan9645x: add bridge support
net: dsa: lan9645x: add vlan support
net: dsa: lan9645x: add mac table integration
net: dsa: lan9645x: add mdb management
net: dsa: lan9645x: add port statistics

 .../net/dsa/microchip,lan96455s-switch.yaml        |  111 ++
 MAINTAINERS                                        |   10 +
 drivers/net/dsa/Kconfig                            |    2 +
 drivers/net/dsa/microchip/Makefile                 |    1 +
 drivers/net/dsa/microchip/lan9645x/Kconfig         |   11 +
 drivers/net/dsa/microchip/lan9645x/Makefile        |   12 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c  |  307 ++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 1038 +++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |  439 +++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c  |  398 ++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c  |   85 +
 .../net/dsa/microchip/lan9645x/lan9645x_phylink.c  |  382 ++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_port.c |  226 +++
 drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1937 ++++++++++++++++++++
 .../net/dsa/microchip/lan9645x/lan9645x_stats.c    |  935 ++++++++++
 .../net/dsa/microchip/lan9645x/lan9645x_stats.h    |  279 +++
 drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c |  403 ++++
 include/linux/dsa/lan9645x.h                       |  144 ++
 include/net/dsa.h                                  |    2 +
 net/dsa/Kconfig                                    |   11 +
 net/dsa/Makefile                                   |    1 +
 net/dsa/tag_lan9645x.c                             |  317 ++++
 22 files changed, 7051 insertions(+)

---
base-commit: 5b4f243f78a533abf414bfd96325aa2c96e711a3
change-id: 20260210-dsa_lan9645x_switch_driver_base-312bbfc37edb

Best regards,

Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
#1 lore raw

PATCH v11 1/9 net: dsa: add tag driver for LAN9645X

Add tag driver for LAN9645x using a front port as CPU port. This mode is called an NPI port in the datasheet.
Use long prefix on extraction (RX) and no prefix on injection (TX). A long prefix on extraction helps get through the conduit port on host side, since it will see a broadcast MAC.

The LAN9645x chip is in the same design architecture family as ocelot and lan966x. The tagging protocol has the same structure as these chips, but the particular fields are different or have different sizes. Therefore, this tag driver is similar to tag_ocelot.c, but the differences in fields makes it hard to reuse.

LAN9645x supports 3 different tag formats for extraction/injection of frames from a CPU port: long prefix, short prefix and no prefix.

The tag is prepended to the frame. The critical data for the chip is contained in an internal frame header (IFH) which is 28 bytes. The prefix formats look like this:

Long prefix (16 bytes) + IFH:

- DMAC    = 0xffffffffffff on extraction.
- SMAC    = 0xfeffffffffff on extraction.
- ETYPE   = 0x8880

- payload = 0x0011
- IFH

Short prefix (4 bytes) + IFH:
- 0x8880
- 0x0011
- IFH

No prefix:
- IFH

The format can be configured asymmetrically on RX and TX.

The IFH get/set functions are declared as inline. All the field constants are compile-time known, so when these calls are inlined efficient code is generated with branches pruned and loops unrolled. During testing it was observed that without explicit inlining GCC would have trouble inlining the functions, which hurt performance.

---
Changes in v11:
- Update comment about vlan tag hwaccel use in tag driver.
- Bump DSA_TAG_PROTO value in include/net/dsa.h.

Changes in v10:
- Update tag driver after skb ownership model change in DSA taggers. Explicitly freeing the skb at rcv/xmit return points.

Changes in v8:
- Drop the cpu_port local and use ds->num_ports directly as the IFH source port (the CPU port module index).
- Reword the reflection comment to refer to "the CPU".

Changes in v7:
- Introduce cpu queue based frame classification, and refactor to the categories default, trap and copy, which mirrors usage instead of being based on frame types.

Changes in v6:
- rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34

Changes in v5:
- Undo offset fix in postpull_rcsum. The original logic was correct for CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask

Changes in v4:
- Fix offset in postpull_rcsum so prefix eth header is cleared, not actual eth header, so tag driver works with CHECKSUM_COMPLETE host NICs
- Fix untagged rx on vlan aware port with pvid

Changes in v3:
- guard vlan_remove_tag behind skb_headlen(skb) >= VLAN_ETH_HLEN on xmit
- add pskb_may_pull checks in rx path

Changes in v2:
- sorting in net/dsa/Kconfig
- sorting in net/dsa/Makefile
- remove default zero promisc_on_conduit
- move functions to to .c file
- add justification for inline usage to commit message
- add __skb_put_padto on xmit path
- fix hwaccel_put_tag

---
 MAINTAINERS                  |   8 ++
 include/linux/dsa/lan9645x.h | 144 ++++++++++++++++++++
 include/net/dsa.h            |   2 +
 net/dsa/Kconfig              |  11 ++
 net/dsa/Makefile             |   1 +
 net/dsa/tag_lan9645x.c       | 317 +++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 483 insertions(+)
MAINTAINERS +8 -0
index 932ea1db048e..d4117b6cf9a3 100644
@@ -17640,6 +17640,14 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/phy/microchip_t1.c
 
+MICROCHIP LAN9645X ETHERNET SWITCH DRIVER
+M:	Jens Emil Schulz Østergaard <[email protected]>
+M:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	include/linux/dsa/lan9645x.h
+F:	net/dsa/tag_lan9645x.c
+
 MICROCHIP LAN966X ETHERNET DRIVER
 M:	Horatiu Vultur <[email protected]>
 M:	[email protected]
include/linux/dsa/lan9645x.h new file +144 -0

144 lines not on this page · raw message

include/net/dsa.h +2 -0
index 6f7f5c17b532..82990c0eafad 100644
@@ -60,6 +60,7 @@ struct tc_action;
 #define DSA_TAG_PROTO_MXL862_VALUE		32
 #define DSA_TAG_PROTO_NETC_VALUE		33
 #define DSA_TAG_PROTO_KSZ8463_VALUE		34
+#define DSA_TAG_PROTO_LAN9645X_VALUE		35
 
 enum dsa_tag_protocol {
 	DSA_TAG_PROTO_NONE		= DSA_TAG_PROTO_NONE_VALUE,
@@ -97,6 +98,7 @@ enum dsa_tag_protocol {
 	DSA_TAG_PROTO_MXL862		= DSA_TAG_PROTO_MXL862_VALUE,
 	DSA_TAG_PROTO_NETC		= DSA_TAG_PROTO_NETC_VALUE,
 	DSA_TAG_PROTO_KSZ8463		= DSA_TAG_PROTO_KSZ8463_VALUE,
+	DSA_TAG_PROTO_LAN9645X		= DSA_TAG_PROTO_LAN9645X_VALUE,
 };
 
 struct dsa_switch;
net/dsa/Kconfig +11 -0
index d5e725b90d78..a0a0096e7e43 100644
@@ -75,6 +75,17 @@ config NET_DSA_TAG_HELLCREEK
 	  Say Y or M if you want to enable support for tagging frames
 	  for the Hirschmann Hellcreek TSN switches.
 
+config NET_DSA_TAG_LAN9645X
+	tristate "Tag driver for Lan9645x switches"
+	help
+	  Say Y or M if you want to enable NPI tagging for the Lan9645x switches.
+	  In this mode, the frames over the Ethernet CPU port are prepended with
+	  a hardware-defined injection/extraction frame header.
+	  On injection a 28 byte internal frame header (IFH) is used. On
+	  extraction a 16 byte prefix is prepended before the internal frame
+	  header. This prefix starts with a broadcast MAC, to ease passage
+	  through the host side RX filter.
+
 config NET_DSA_TAG_GSWIP
 	tristate "Tag driver for Lantiq / Intel GSWIP switches"
 	help
net/dsa/Makefile +1 -0
index b8c2667cd14a..600975e0f2f7 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o
 obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o
 obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o
 obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o
+obj-$(CONFIG_NET_DSA_TAG_LAN9645X) += tag_lan9645x.o
 obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o
 obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o
net/dsa/tag_lan9645x.c new file +317 -0

317 lines not on this page · raw message

Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] The tag driver drops hardware-accelerated VLAN tags on transmit, leading to switch…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The tag driver drops hardware-accelerated VLAN tags on transmit, leading to switch misclassification and double tagging. --

--- Patch [1]: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X --- commit 97f24952991b201e3d0f1948d98e9534914b9db3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: add tag driver for LAN9645X

This commit introduces a new DSA tag driver for the LAN9645X switch family, using an NPI port for CPU connection. It supports prepending a 28-byte internal frame header (IFH) on injection and handling a long prefix on extraction.

Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0 -0
new file mode 100644
index 0000000000000..6a33216c7792f

[ ... ]

Quoted 16 lines
net/dsa/tag_lan9645x.c new file +16 -0
+static void lan9645x_xmit_get_vlan_info(struct sk_buff *skb,
+					struct net_device *br,
+					u32 *vlan_tci, u32 *tag_type)
+{
+	struct vlan_ethhdr *hdr;
+	u16 proto, tci;
+
+	if (!br || !br_vlan_enabled(br)) {
+		*vlan_tci = 0;
+		*tag_type = LAN9645X_IFH_TAG_TYPE_C;
+		return;
+	}
+
+	hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+	br_vlan_get_proto(br, &proto);
+

net/dsa/tag_lan9645x.c line 152

Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10 -0
+	if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
+	    ntohs(hdr->h_vlan_proto) == proto) {
+		vlan_remove_tag(skb, &tci);
+		*vlan_tci = tci;
+	} else {
+		rcu_read_lock();
+		br_vlan_get_pvid_rcu(br, &tci);
+		rcu_read_unlock();
+		*vlan_tci = tci;
+	}

[Severity: High]
Does this code drop hardware-accelerated VLAN tags on transmit?

When the network stack transmits a frame through the DSA user port with a hardware-accelerated VLAN tag, the tag is stored out-of-band in skb->vlan_tci.

By only checking the inline Ethernet header, ntohs(hdr->h_vlan_proto) will evaluate to the inner network protocol (like IPv4) instead of ETH_P_8021Q. This causes the check to fail and fall back to using the bridge PVID instead of extracting the existing out-of-band VLAN tag.

Because the out-of-band tag is ignored and never removed from the socket buffer, will the conduit driver eventually insert the original VLAN tag into the payload, resulting in a double-tagged frame on the wire?

Quoted 4 lines
net/dsa/tag_lan9645x.c new file +4 -0
+
+	*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S :
+					     LAN9645X_IFH_TAG_TYPE_C;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=1
#3 lore raw

Re: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X

Quoted 58 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The tag driver drops hardware-accelerated VLAN tags on transmit, leading to switch misclassification and double tagging. --

--- Patch [1]: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X --- commit 97f24952991b201e3d0f1948d98e9534914b9db3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: add tag driver for LAN9645X

This commit introduces a new DSA tag driver for the LAN9645X switch family, using an NPI port for CPU connection. It supports prepending a 28-byte internal frame header (IFH) on injection and handling a long prefix on extraction.

Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0 -0
new file mode 100644
index 0000000000000..6a33216c7792f

[ ... ]

Quoted 16 lines
net/dsa/tag_lan9645x.c new file +16 -0
+static void lan9645x_xmit_get_vlan_info(struct sk_buff *skb,
+                                     struct net_device *br,
+                                     u32 *vlan_tci, u32 *tag_type)
+{
+     struct vlan_ethhdr *hdr;
+     u16 proto, tci;
+
+     if (!br || !br_vlan_enabled(br)) {
+             *vlan_tci = 0;
+             *tag_type = LAN9645X_IFH_TAG_TYPE_C;
+             return;
+     }
+
+     hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+     br_vlan_get_proto(br, &proto);
+

net/dsa/tag_lan9645x.c line 152

Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10 -0
+     if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
+         ntohs(hdr->h_vlan_proto) == proto) {
+             vlan_remove_tag(skb, &tci);
+             *vlan_tci = tci;
+     } else {
+             rcu_read_lock();
+             br_vlan_get_pvid_rcu(br, &tci);
+             rcu_read_unlock();
+             *vlan_tci = tci;
+     }

[Severity: High]
Does this code drop hardware-accelerated VLAN tags on transmit?

When the network stack transmits a frame through the DSA user port with a hardware-accelerated VLAN tag, the tag is stored out-of-band in skb->vlan_tci.

Quoted 8 lines

By only checking the inline Ethernet header, ntohs(hdr->h_vlan_proto) will evaluate to the inner network protocol (like IPv4) instead of ETH_P_8021Q. This causes the check to fail and fall back to using the bridge PVID instead of extracting the existing out-of-band VLAN tag.

Because the out-of-band tag is ignored and never removed from the socket buffer, will the conduit driver eventually insert the original VLAN tag into the payload, resulting in a double-tagged frame on the wire?

If the conduit sets NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX) in conduit->vlan_features, then I think the analysis is correct.

__dev_queue_xmit() calls validate_xmit_skb() -> validate_xmit_vlan() before ndo_start_xmit():

	if (skb_vlan_tag_present(skb) &&
	    !vlan_hw_offload_capable(features, skb->vlan_proto))
		skb = __vlan_hwaccel_push_inside(skb);

vlan_hw_offload_capable() requires NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX). A DSA user port inherits its features from the conduit

user->features = conduit->vlan_features | NETIF_F_HW_TC;

and user->hw_features only ever gains NETIF_F_HW_TC and NETIF_F_HW_VLAN_CTAG_FILTER, so ethtool cannot turn the TX offload on.

But if a conduit sets those offload flags, the tag driver could receive an skb with the vlan tag in the hwaccel area.

I will normalise the tag into the payload at the top of lan9645x_xmit_get_vlan_info(), following the precedent in sja1105_pvid_tag_control_pkt():

if (unlikely(skb_vlan_tag_present(skb))) {
        skb = __vlan_hwaccel_push_inside(skb);
        if (!skb)
                return NULL;
}

But the outcome would probably be worse than a double-tagged frame? We prepend the dsa tag, and the conduit would not know anything about that, so my guess is it would insert the vlan tag into the dsa tag.

Quoted 8 lines

net/dsa/tag_lan9645x.c line 156

Quoted 5 lines
net/dsa/tag_lan9645x.c new file +4 -0
+
+     *tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S :
+                                          LAN9645X_IFH_TAG_TYPE_C;
+}

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=1

maintainer
#4 lore raw

Re: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X

Quoted 99 lines · On 8/7/26 4:41 PM, [email protected] wrote:
Quoted 58 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The tag driver drops hardware-accelerated VLAN tags on transmit, leading to switch misclassification and double tagging. --

--- Patch [1]: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X --- commit 97f24952991b201e3d0f1948d98e9534914b9db3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: add tag driver for LAN9645X

This commit introduces a new DSA tag driver for the LAN9645X switch family, using an NPI port for CPU connection. It supports prepending a 28-byte internal frame header (IFH) on injection and handling a long prefix on extraction.

Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0 -0
new file mode 100644
index 0000000000000..6a33216c7792f

[ ... ]

Quoted 16 lines
net/dsa/tag_lan9645x.c new file +16 -0
+static void lan9645x_xmit_get_vlan_info(struct sk_buff *skb,
+                                     struct net_device *br,
+                                     u32 *vlan_tci, u32 *tag_type)
+{
+     struct vlan_ethhdr *hdr;
+     u16 proto, tci;
+
+     if (!br || !br_vlan_enabled(br)) {
+             *vlan_tci = 0;
+             *tag_type = LAN9645X_IFH_TAG_TYPE_C;
+             return;
+     }
+
+     hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+     br_vlan_get_proto(br, &proto);
+

net/dsa/tag_lan9645x.c line 152

Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10 -0
+     if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
+         ntohs(hdr->h_vlan_proto) == proto) {
+             vlan_remove_tag(skb, &tci);
+             *vlan_tci = tci;
+     } else {
+             rcu_read_lock();
+             br_vlan_get_pvid_rcu(br, &tci);
+             rcu_read_unlock();
+             *vlan_tci = tci;
+     }

[Severity: High]
Does this code drop hardware-accelerated VLAN tags on transmit?

When the network stack transmits a frame through the DSA user port with a hardware-accelerated VLAN tag, the tag is stored out-of-band in skb->vlan_tci.

Quoted 8 lines

By only checking the inline Ethernet header, ntohs(hdr->h_vlan_proto) will evaluate to the inner network protocol (like IPv4) instead of ETH_P_8021Q. This causes the check to fail and fall back to using the bridge PVID instead of extracting the existing out-of-band VLAN tag.

Because the out-of-band tag is ignored and never removed from the socket buffer, will the conduit driver eventually insert the original VLAN tag into the payload, resulting in a double-tagged frame on the wire?

If the conduit sets NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX) in conduit->vlan_features, then I think the analysis is correct.

__dev_queue_xmit() calls validate_xmit_skb() -> validate_xmit_vlan() before ndo_start_xmit():

	if (skb_vlan_tag_present(skb) &&
	    !vlan_hw_offload_capable(features, skb->vlan_proto))
		skb = __vlan_hwaccel_push_inside(skb);

vlan_hw_offload_capable() requires NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX). A DSA user port inherits its features from the conduit

user->features = conduit->vlan_features | NETIF_F_HW_TC;

and user->hw_features only ever gains NETIF_F_HW_TC and NETIF_F_HW_VLAN_CTAG_FILTER, so ethtool cannot turn the TX offload on.

But if a conduit sets those offload flags, the tag driver could receive an skb with the vlan tag in the hwaccel area.

I will normalise the tag into the payload at the top of lan9645x_xmit_get_vlan_info(), following the precedent in sja1105_pvid_tag_control_pkt():

if (unlikely(skb_vlan_tag_present(skb))) {
        skb = __vlan_hwaccel_push_inside(skb);
        if (!skb)
                return NULL;
}
Quoted 3 lines

But the outcome would probably be worse than a double-tagged frame? We prepend the dsa tag, and the conduit would not know anything about that, so my guess is it would insert the vlan tag into the dsa tag.

What about something alike the following?

	if (skb_vlan_tag_present(skb)) {
		*vlan_tci = skb_vlan_tag_get(__skb);
	} else if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
		 ntohs(hdr->h_vlan_proto) == proto) {
	// ...

Side note: I *think* the unlikely() on skb_vlan_tag_present() is not needed; the like-wood depends on the actual traffic pattern.

/P

#5 lore raw

Re: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X

Quoted 113 lines · Paolo Abeni

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

Quoted 99 lines · On 8/7/26 4:41 PM, [email protected] wrote:
Quoted 58 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The tag driver drops hardware-accelerated VLAN tags on transmit, leading to switch misclassification and double tagging. --

--- Patch [1]: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X --- commit 97f24952991b201e3d0f1948d98e9534914b9db3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: add tag driver for LAN9645X

This commit introduces a new DSA tag driver for the LAN9645X switch family, using an NPI port for CPU connection. It supports prepending a 28-byte internal frame header (IFH) on injection and handling a long prefix on extraction.

Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0 -0
new file mode 100644
index 0000000000000..6a33216c7792f

[ ... ]

Quoted 16 lines
net/dsa/tag_lan9645x.c new file +16 -0
+static void lan9645x_xmit_get_vlan_info(struct sk_buff *skb,
+                                     struct net_device *br,
+                                     u32 *vlan_tci, u32 *tag_type)
+{
+     struct vlan_ethhdr *hdr;
+     u16 proto, tci;
+
+     if (!br || !br_vlan_enabled(br)) {
+             *vlan_tci = 0;
+             *tag_type = LAN9645X_IFH_TAG_TYPE_C;
+             return;
+     }
+
+     hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
+     br_vlan_get_proto(br, &proto);
+

net/dsa/tag_lan9645x.c line 152

Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10 -0
+     if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
+         ntohs(hdr->h_vlan_proto) == proto) {
+             vlan_remove_tag(skb, &tci);
+             *vlan_tci = tci;
+     } else {
+             rcu_read_lock();
+             br_vlan_get_pvid_rcu(br, &tci);
+             rcu_read_unlock();
+             *vlan_tci = tci;
+     }

[Severity: High]
Does this code drop hardware-accelerated VLAN tags on transmit?

When the network stack transmits a frame through the DSA user port with a hardware-accelerated VLAN tag, the tag is stored out-of-band in skb->vlan_tci.

Quoted 8 lines

By only checking the inline Ethernet header, ntohs(hdr->h_vlan_proto) will evaluate to the inner network protocol (like IPv4) instead of ETH_P_8021Q. This causes the check to fail and fall back to using the bridge PVID instead of extracting the existing out-of-band VLAN tag.

Because the out-of-band tag is ignored and never removed from the socket buffer, will the conduit driver eventually insert the original VLAN tag into the payload, resulting in a double-tagged frame on the wire?

If the conduit sets NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX) in conduit->vlan_features, then I think the analysis is correct.

__dev_queue_xmit() calls validate_xmit_skb() -> validate_xmit_vlan() before ndo_start_xmit():

      if (skb_vlan_tag_present(skb) &&
          !vlan_hw_offload_capable(features, skb->vlan_proto))
              skb = __vlan_hwaccel_push_inside(skb);

vlan_hw_offload_capable() requires NETIF_F_HW_VLAN_CTAG_TX (or STAG_TX). A DSA user port inherits its features from the conduit

user->features = conduit->vlan_features | NETIF_F_HW_TC;

and user->hw_features only ever gains NETIF_F_HW_TC and NETIF_F_HW_VLAN_CTAG_FILTER, so ethtool cannot turn the TX offload on.

But if a conduit sets those offload flags, the tag driver could receive an skb with the vlan tag in the hwaccel area.

I will normalise the tag into the payload at the top of lan9645x_xmit_get_vlan_info(), following the precedent in sja1105_pvid_tag_control_pkt():

if (unlikely(skb_vlan_tag_present(skb))) {
        skb = __vlan_hwaccel_push_inside(skb);
        if (!skb)
                return NULL;
}
Quoted 3 lines

But the outcome would probably be worse than a double-tagged frame? We prepend the dsa tag, and the conduit would not know anything about that, so my guess is it would insert the vlan tag into the dsa tag.

What about something alike the following?

        if (skb_vlan_tag_present(skb)) {
                *vlan_tci = skb_vlan_tag_get(__skb);
        } else if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
                 ntohs(hdr->h_vlan_proto) == proto) {
        // ...
Quoted 5 lines

Side note: I *think* the unlikely() on skb_vlan_tag_present() is not needed; the like-wood depends on the actual traffic pattern.

/P

I do not think it will work as written,

1) If conduit advertises CTAG_TX/STAG_TX, we need to clear the hwaccel area to make sure the driver does not take the *TAG_TX offload path and insert a vlan tag into our dsa tag. We would have to add __vlan_hwaccel_clear_tag.

2) If conduit does not advertise, validate_xmit_vlan() on the conduits __dev_queue_xmit() calls __vlan_hwaccel_push_inside(), which inserts at skb->data + ETH_HLEN. Same problem as 1).

3) We also need to look at the TPID in the hwaccel area. If it does not match the bridge we need the vlan tag inlined in the payload.

4) In the non-vlan-bridge case we also need __vlan_hwaccel_push_inside.

If the goal is to avoid the 2x memmove in one of the cases I think you have to end up with something like:

if (!br || !br_vlan_enabled(br)) {
        if (skb_vlan_tag_present(skb)) {
                skb = __vlan_hwaccel_push_inside(skb);
                if (!skb)
                        return NULL;
        }
        *vlan_tci = 0;
        ...
}

hdr = (struct vlan_ethhdr *)skb_mac_header(skb);
br_vlan_get_proto(br, &proto);

if (skb_vlan_tag_present(skb)) {
        if (ntohs(skb->vlan_proto) == proto) {
                *vlan_tci = skb_vlan_tag_get(skb);
                __vlan_hwaccel_clear_tag(skb);
        } else {
                skb = __vlan_hwaccel_push_inside(skb);
                if (!skb)
                        return NULL;
                /* fall through to pvid case */
        }
} else if (skb_headlen(skb) >= VLAN_ETH_HLEN &&
                ntohs(hdr->h_vlan_proto) == proto) {
        ...

If the vlan tag is inlined at the top of lan9645x_xmit_get_vlan_info with

if (skb_vlan_tag_present(skb)) {
        skb = __vlan_hwaccel_push_inside(skb);
        if (!skb)
                return NULL;
}

it makes the downstream logic simpler, at the price of the 2x memmove in the vlan-aware case.

Thanks
Emil

#6 lore raw

Re: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X

In reply to Jens Emil Schulz Østergaard

This is my reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=1

Quoted 58 lines

--- Patch [1]: [PATCH net-next v11 1/9] net: dsa: add tag driver for LAN9645X --- commit 16799f4195f9118fdca9d3ba803a3d4d2e6a9414
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: add tag driver for LAN9645X

This adds a DSA tag driver for the LAN9645x family used with a front port as CPU port (NPI mode), with a long prefix on extraction and no prefix on injection. A new header exports the 28 byte internal frame header (IFH) field table, and the tagger encodes/decodes it in lan9645x_xmit() and lan9645x_rcv().

A few questions below.

Quoted 6 lines
include/linux/dsa/lan9645x.h new file +0 -0
new file mode 100644
index 0000000000000..9896fab649c4d
@@ -0,0 +1,144 @@

[ ... ]

Quoted 8 lines
include/linux/dsa/lan9645x.h new file +8 -0
+#define LAN9645X_IFH_TAG_TYPE_C	0
+#define LAN9645X_IFH_TAG_TYPE_S	1
+#define LAN9645X_IFH_LEN_U32		7
+#define LAN9645X_IFH_LEN		(LAN9645X_IFH_LEN_U32 * sizeof(u32))
+#define LAN9645X_IFH_BITS		(LAN9645X_IFH_LEN * BITS_PER_BYTE)
+#define LAN9645X_SHORT_PREFIX_LEN	4
+#define LAN9645X_LONG_PREFIX_LEN	16
+#define LAN9645X_TOTAL_TAG_LEN (LAN9645X_LONG_PREFIX_LEN + LAN9645X_IFH_LEN)

include/linux/dsa/lan9645x.h line 52

Quoted 10 lines
include/linux/dsa/lan9645x.h new file +10 -0
+
+#define IFH_INJ_TIMESTAMP		192
+#define IFH_BYPASS			191
+#define IFH_MASQ			190
+#define IFH_TIMESTAMP			186
+#define IFH_TIMESTAMP_NS		194
+#define IFH_TIMESTAMP_SUBNS		186
+#define IFH_MASQ_PORT			186
+#define IFH_RCT_INJ			185
+#define IFH_LEN				171

Discovered by: opus-5 · Missed by: sashiko-gemini
Can this IFH_LEN definition clash with the existing ones? There are already two in-tree macros with that name and a different meaning:

drivers/net/ethernet/microchip/lan966x/lan966x_ifh.h:

    #define IFH_LEN                      7
    #define IFH_LEN_BYTES                (IFH_LEN * sizeof(u32))

drivers/net/ethernet/microchip/sparx5/sparx5_main.h:

    #define IFH_LEN                9 /* 36 bytes */

Both are u32 word counts for the IFH of sibling chips in the same family, while here IFH_LEN is the bit position 171 of the length field. A translation unit that includes this header plus either of those gets a redefinition warning, or silently expands 7 or 9 where bit 171 was meant.

Quoted 5 lines

The same header also exports LAN9645X_IFH_LEN (28 bytes), so two macros differing only by prefix carry unrelated quantities. The length/format and tag type macros already got the LAN9645X_ prefix - would it make sense to prefix the whole field table exported from include/linux/dsa/ as well?

I will rename LAN9645X_IFH_LEN to LAN9645X_IFH_LEN_BYTES and move the field table to tag_lan9645x.c.

Quoted 32 lines
Quoted 3 lines
include/linux/dsa/lan9645x.h new file +3 -0
+#define IFH_WRDMODE			169
+#define IFH_RTAGD			167
+#define IFH_CUTTHRU			166

[ ... ]

Quoted 4 lines
include/linux/dsa/lan9645x.h new file +4 -0
+#define IFH_RTE_INB_UPDATE		148
+#define IFH_POP_CNT			146
+#define IFH_ETYPE_OFS			144
+#define IFH_SRCPORT			140

[ ... ]

include/linux/dsa/lan9645x.h line 92

Quoted 4 lines
include/linux/dsa/lan9645x.h new file +4 -0
+#define IFH_INJ_TIMESTAMP_SZ		32
+#define IFH_BYPASS_SZ			1
+#define IFH_MASQ_SZ			1
+#define IFH_TIMESTAMP_SZ		38

Discovered by: opus-5 · Missed by: sashiko-gemini
Is IFH_TIMESTAMP usable with the accessors added by this patch? Both lan9645x_ifh_set() and lan9645x_ifh_get() carry:

    BUILD_BUG_ON_MSG(length > 32, "IFH field size wider than 32.");

and pass the value through u32, so a consumer calling

lan9645x_ifh_get(ifh, IFH_TIMESTAMP, IFH_TIMESTAMP_SZ)

fails to build. The usable split already exists as IFH_TIMESTAMP_NS (30 bits) plus IFH_TIMESTAMP_SUBNS (8 bits), so should the 38 bit alias be dropped or annotated?

Quoted 6 lines

Related, the table mixes the injection and extraction layouts without marking which is which: IFH_TIMESTAMP, IFH_TIMESTAMP_SUBNS and IFH_MASQ_PORT all start at bit 186, and IFH_INJ_TIMESTAMP (32 bits at 192) overlaps IFH_BYPASS and IFH_MASQ. Only the .c file mentions that "There are two field layouts, one for extraction and one for injection". Could the header note the direction per field?

I will remove IFH_TIMESTAMP and just keep the NS/SUBNS subfield split, and annotate each field with whether it is used in the injection, extraction or both headers.

Quoted 50 lines
Quoted 3 lines
include/linux/dsa/lan9645x.h new file +2 -0
+#define IFH_TIMESTAMP_NS_SZ		30
+#define IFH_TIMESTAMP_SUBNS_SZ		8

[ ... ]

Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0 -0
new file mode 100644
index 0000000000000..6a33216c7792f
@@ -0,0 +1,317 @@

[ ... ]

Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3 -0
+static struct sk_buff *lan9645x_xmit(struct sk_buff *skb,
+				     struct net_device *ndev)
+{

[ ... ]

net/dsa/tag_lan9645x.c line 200

Quoted 6 lines
net/dsa/tag_lan9645x.c new file +6 -0
+	lan9645x_ifh_set(ifh, 1, IFH_BYPASS, IFH_BYPASS_SZ);
+	lan9645x_ifh_set(ifh, ds->num_ports, IFH_SRCPORT, IFH_SRCPORT_SZ);
+	lan9645x_ifh_set(ifh, tag_type, IFH_TAG_TYPE, IFH_TAG_TYPE_SZ);
+	lan9645x_ifh_set(ifh, vlan_tci, IFH_TCI, IFH_TCI_SZ);
+	lan9645x_ifh_set(ifh, qos_class, IFH_QOS_CLASS, IFH_QOS_CLASS_SZ);
+	lan9645x_ifh_set(ifh, BIT(dp->index), IFH_DSTS, IFH_DSTS_SZ);

Discovered by: opus-5 · Missed by: sashiko-gemini This isn't a bug today, but should the destination set use dsa_xmit_port_mask() instead of open-coding BIT(dp->index)?

net/dsa/tag.h:dsa_xmit_port_mask() is BIT(dp->index) plus the HSR duplication fan-out:

    unsigned long mask = BIT(dp->index);

    if (IS_ENABLED(CONFIG_HSR) &&
        unlikely(dev->features & NETIF_F_HW_HSR_DUP)) {
            struct net_device *hsr_dev = dp->hsr_dev;
            struct dsa_port *other_dp;

            dsa_hsr_foreach_port(other_dp, dp->ds, hsr_dev)
                    mask |= BIT(other_dp->index);
    }

tag_ocelot.c writes the same IFH DSTS concept through the helper:

    ocelot_ifh_set_dest(injection, dsa_xmit_port_mask(skb, netdev));
Quoted 8 lines

and net/dsa/dsa.c documents the contract as "Helpers for switches without specific HSR offloads, but which can implement NETIF_F_HW_HSR_DUP because their tagger uses dsa_xmit_port_mask()". I checked the companion switch driver in this series and it implements no HSR offload, so there is no functional effect right now; a later HSR/PRP offload would however duplicate to a single port only, since the partner bit never reaches IFH DSTS.

I think this would be a bug on this chip, for HSR/PRP v1. When multiple ports are set in the IFH_DSTS mask, each port receives a byte-identical copy. But HSR/PRP v1 require the 2 duplicates differ in a bit (lan_id) in the tag which tells from which port the frame egresses. Typically 0 for port A and 1 for port B.

This chip is also capable of offloading several HSR and PRP features such as duplication and duplicate discard. When I implement the callbacks I plan on using those capabilities.

Quoted 40 lines
Quoted 7 lines
net/dsa/tag_lan9645x.c new file +7 -0
+
+	return skb;
+}
+
+static struct sk_buff *lan9645x_rcv(struct sk_buff *skb,
+				    struct net_device *ndev)
+{

[ ... ]

Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3 -0
+	popcnt = lan9645x_ifh_get(ifh, IFH_POP_CNT, IFH_POP_CNT_SZ);
+	etype_ofs = lan9645x_ifh_get(ifh, IFH_ETYPE_OFS, IFH_ETYPE_OFS_SZ);
+	src_port = lan9645x_ifh_get(ifh, IFH_SRCPORT, IFH_SRCPORT_SZ);

[ ... ]

net/dsa/tag_lan9645x.c line 244

Quoted 4 lines
net/dsa/tag_lan9645x.c new file +4 -0
+	if (popcnt == 0 && etype_ofs == 0)
+		ifh_gap_len = 2 * VLAN_HLEN;
+	else if (popcnt == 3)
+		ifh_gap_len = VLAN_HLEN;

Discovered by: opus-5 · Missed by: sashiko-gemini
Which extraction encodings does this cover? IFH_POP_CNT and IFH_ETYPE_OFS are 2 bits each, so there are 16 combinations, and only two of them get a non-zero gap here. Everything else, including popcnt == 1, popcnt == 2 and (popcnt == 0, etype_ofs == 1), falls through to the initialiser ifh_gap_len = 0.

The mapping also looks internally inconsistent: on one port an untagged frame (popcnt == 0, etype_ofs == 0) gets an 8 byte gap, while a single-tagged frame on the same port (popcnt == 0, etype_ofs == 1) gets a 0 byte gap. That is an 8 byte difference for one 4 byte tag. The two handled values do differ by exactly one tag, which suggests the real discriminator is the number of tags left in the delivered frame (ETYPE_OFS) rather than the two POP_CNT comparisons. Could the full datasheet mapping be spelled out here?

The companion switch driver added later in this series programs a pop count of 1 on every VLAN-aware port:

Quoted 7 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c:

        val |= ANA_VLAN_CFG_VLAN_AWARE_ENA_SET(1) |
               ANA_VLAN_CFG_VLAN_POP_CNT_SET(1);

so POP_CNT == 1 seems to be an expected extraction encoding that lands in the zero-gap default.

No the current logic covers all cases properly. The values encoded in the fields are not intuitive. On a vlan aware port ifh.pop_cnt will not be 1 for instance.

This is how the calculation goes:

DMAC_DT = (ifh.pop_cnt == 0 && ifh.etype_ofs == 0) ? 4 : ifh.pop_cnt DMAC_OFFSET = TAG_SIZE + 4*(DMAC_DT - 2)

With tag pushing disabled we have either

popcnt=0 and etype_ofs=0     => 2x pop
popcnt=3 and etype_ofs=*     => 1x pop
popcnt=2 and etype_ofs=*     => no pop

The remaining combinations indicate a push and will not occur.

I will include this in a comment, and add WARN_ON_ONCE and a bailout for the impossible combinations.

Quoted 86 lines

net/dsa/tag_lan9645x.c line 256

Quoted 12 lines
net/dsa/tag_lan9645x.c new file +12 -0
+
+	skb_pull(skb, LAN9645X_IFH_LEN);
+
+	if (unlikely(!pskb_may_pull(skb, ifh_gap_len + ETH_HLEN))) {
+		kfree_skb(skb);
+		return NULL;
+	}
+
+	skb_pull(skb, ifh_gap_len);
+	skb_reset_mac_header(skb);
+	skb_set_network_header(skb, ETH_HLEN);
+	skb_reset_mac_len(skb);

Discovered by: opus-5 · Missed by: sashiko-gemini
Following on from the gap computation above: if ifh_gap_len is smaller than the real gap, do these calls describe a header the hardware did not put there, so that eth_type_trans() in dsa_switch_rcv() derives a protocol from leftover tag bytes? And if it is larger, are up to 8 bytes of the real DMAC pushed back into the headroom and lost?

Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3 -0
+
+	/* Reset skb->data past the actual ethernet header. */
+	skb_pull(skb, ETH_HLEN);

[ ... ]

net/dsa/tag_lan9645x.c line 268

Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3 -0
+	skb_postpull_rcsum(skb,
+			   skb->data - LAN9645X_TOTAL_TAG_LEN - ifh_gap_len,
+			   LAN9645X_TOTAL_TAG_LEN + ifh_gap_len);

Discovered by: opus-5 · Missed by: sashiko-gemini
The same ifh_gap_len is reused as the checksum fixup length here. Can a wrong gap corrupt skb->csum on a CHECKSUM_COMPLETE conduit, since the subtracted byte range then does not match the bytes the conduit actually summed?

net/dsa/tag_lan9645x.c line 277

Quoted 9 lines
net/dsa/tag_lan9645x.c new file +9 -0
+
+	skb->dev = dsa_conduit_find_user(ndev, 0, src_port);
+	if (WARN_ON_ONCE(!skb->dev)) {
+		/* This should never happen since we have disabled reflection
+		 * back to the CPU.
+		 */
+		kfree_skb(skb);
+		return NULL;
+	}

Discovered by: opus-5 · Missed by: sashiko-gemini
Is this WARN_ON_ONCE() reachable from frame data? src_port comes straight out of the received IFH:

    src_port = lan9645x_ifh_get(ifh, IFH_SRCPORT, IFH_SRCPORT_SZ);

That is a 4 bit field, so any value 0..15 can arrive, and dsa_conduit_find_user() returns NULL for every index that is not a registered user port. Candidates for such an index are the NPI port index itself (registered as DSA_PORT_TYPE_CPU), physical ports left unused by the device tree, and masqueraded source ports from a frame injected on the bare conduit, which the hardware parses as a bare IFH because no injection prefix is configured. With panic_on_warn=1 that becomes a panic from the receive path.

The comment relies on reflection being disabled, but the guard in the companion driver only covers src_port equal to the CPU port module:

drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c:

    /* Make sure frames with src_port=<CPU port module> are not reflected
     * back via the NPI port. ... The *_CPU_KILL_ENA flags above only have an
     * effect when a frame is output due to a CPU forwarding decision such as
     * trapping or cpu copy.
     */
    lan_rmw(0, BIT(port), lan9645x,
            ANA_PGID(PGID_SRC + lan9645x->num_phys_ports));

The tagger for the same hardware family deliberately drops silently here:

net/dsa/tag_ocelot.c:ocelot_rcv()

    skb->dev = dsa_conduit_find_user(netdev, 0, src_port);
    if (!skb->dev) {
            /* The switch will reflect back some frames sent through
             * sockets opened on the bare DSA conduit. ... So don't print any
             * error message here (ignore and drop those frames).
             */
            kfree_skb(skb);
            return NULL;
    }
Quoted 3 lines

The kfree_skb() and return NULL here are already right - would dropping the WARN_ON_ONCE() be preferable?

I think it is right that a carefully constructed frame on a raw socket for the conduit, could be reflected. I will remove the WARN_ON_ONCE().

Quoted 1 line

[ ... ]

#7 lore raw

PATCH v11 2/9 dt-bindings: net: lan9645x: add LAN9645X switch bindings

In reply to Jens Emil Schulz Østergaard

Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch.

---
Changes in v5:
- No changes.

Changes in v4:
- No changes.

Changes in v3:
- remove additionalProperties: true
- remove unnecessary | from description
- change top level $ref to dsa.yaml#/$defs/ethernet-ports
- use ethernet-ports and ethernet-port
- move ethernet-ports under properties instead of patternProperties
- move unevaluatedProperties: false after $ref
- update example to use ethernet-ports and ethernet-port

Changes in v2:
- rename file to microchip,lan96455s-switch.yaml
- remove led vendor property
- add {rx,tx}-internal-delay-ps for rgmii delay
- remove labels from example
- remove container node from example

---
 .../net/dsa/microchip,lan96455s-switch.yaml        | 111 +++++++++++++++++++++
 MAINTAINERS                                        |   1 +
 2 files changed, 112 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +111 -0
new file mode 100644
index 000000000000..043fb48922b4
@@ -0,0 +1,111 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/microchip,lan96455s-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip LAN9645x Ethernet switch
+
+maintainers:
+  - Jens Emil Schulz Østergaard <[email protected]>
+
+description:
+  The LAN9645x switch is a multi-port Gigabit AVB/TSN Ethernet switch with
+  five integrated 10/100/1000Base-T PHYs. In addition to the integrated PHYs,
+  it supports up to 2 RGMII/RMII, up to 2 BASE-X/SERDES/2.5GBASE-X and one
+  Quad-SGMII interfaces.
+
+properties:
+  compatible:
+    oneOf:
+      - enum:
+          - microchip,lan96455s-switch
+      - items:
+          - enum:
+              - microchip,lan96455f-switch
+              - microchip,lan96457f-switch
+              - microchip,lan96459f-switch
+              - microchip,lan96457s-switch
+              - microchip,lan96459s-switch
+          - const: microchip,lan96455s-switch
+
+  reg:
+    maxItems: 1
+
+  ethernet-ports:
+    type: object
+    patternProperties:
+      "^ethernet-port@[0-8]$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          rx-internal-delay-ps:
+            const: 2000
+
+          tx-internal-delay-ps:
+            const: 2000
+
+$ref: dsa.yaml#/$defs/ethernet-ports
+
+required:
+  - compatible
+  - reg
+  - ethernet-ports
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ethernet-switch@4000 {
+        compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch";
+        reg = <0x4000 0x244>;
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            ethernet-port@0 {
+                reg = <0>;
+                phy-mode = "gmii";
+                phy-handle = <&cuphy0>;
+            };
+
+            ethernet-port@1 {
+                reg = <1>;
+                phy-mode = "gmii";
+                phy-handle = <&cuphy1>;
+            };
+
+            ethernet-port@2 {
+                reg = <2>;
+                phy-mode = "gmii";
+                phy-handle = <&cuphy2>;
+            };
+
+            ethernet-port@3 {
+                reg = <3>;
+                phy-mode = "gmii";
+                phy-handle = <&cuphy3>;
+            };
+
+            ethernet-port@7 {
+                reg = <7>;
+                phy-mode = "rgmii";
+                ethernet = <&cpu_host_port>;
+                rx-internal-delay-ps = <2000>;
+                tx-internal-delay-ps = <2000>;
+
+                fixed-link {
+                    speed = <1000>;
+                    full-duplex;
+                    pause;
+                };
+            };
+        };
+    };
+...
+
MAINTAINERS +1 -0
index d4117b6cf9a3..da03885eb0d0 100644
@@ -17645,6 +17645,7 @@ M:	Jens Emil Schulz Østergaard <[email protected]>
 M:	[email protected]
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml
 F:	include/linux/dsa/lan9645x.h
 F:	net/dsa/tag_lan9645x.c
 
Signature · 1 line
2.52.0
#8 lore raw

Re: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The schema lacks an `mdio` node definition while setting `unevaluatedProperties: false` at the…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The schema lacks an mdio node definition while setting unevaluatedProperties: false at the root, which inadvertently prevents instantiation of the integrated PHYs referenced in the example.
- [Medium] Invalid constraint and usage of RGMII internal delay properties in combination with phy-mode = "rgmii".
--

--- Patch [2]: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings --- commit 36eb3256c1e8bdeb280de04a105905650e50438f
Author: Jens Emil Schulz Østergaard <[email protected]>

dt-bindings: net: lan9645x: add LAN9645X switch bindings

Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch.

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0 -0
new file mode 100644
index 0000000000000..043fb48922b41
@@ -0,0 +1,111 @@

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 50

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+        properties:
+          rx-internal-delay-ps:
+            const: 2000
+
+          tx-internal-delay-ps:
+            const: 2000

[Severity: Medium]
Is it intended to restrict the rx-internal-delay-ps and tx-internal-delay-ps properties to exactly 2000?

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 59

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+required:
+  - compatible
+  - reg
+  - ethernet-ports
+
+unevaluatedProperties: false

[Severity: Medium]
Since the switch has integrated PHYs, will users need to define them in an mdio node to correctly resolve the phy-handle references?

If so, won't this unevaluatedProperties: false at the root level reject the device tree, as the mdio node is not defined in the properties block or inherited from dsa.yaml?

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 100

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+            ethernet-port@7 {
+                reg = <7>;
+                phy-mode = "rgmii";
+                ethernet = <&cpu_host_port>;
+                rx-internal-delay-ps = <2000>;
+                tx-internal-delay-ps = <2000>;

[Severity: Medium]
Can this combination of phy-mode = "rgmii" and a 2000ps internal delay be used here?

According to the ethernet controller bindings, phy-mode = "rgmii" implies the delay is implemented on the PCB. Adding a 2000ps internal MAC delay on top of this might result in a double delay.

If the hardware has fixed internal delays, should this use phy-mode = "rgmii-id" instead?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=2
#9 lore raw

Re: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings

Quoted 30 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The schema lacks an mdio node definition while setting unevaluatedProperties: false at the root, which inadvertently prevents instantiation of the integrated PHYs referenced in the example.
- [Medium] Invalid constraint and usage of RGMII internal delay properties in combination with phy-mode = "rgmii".
--

--- Patch [2]: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings --- commit 36eb3256c1e8bdeb280de04a105905650e50438f
Author: Jens Emil Schulz Østergaard <[email protected]>

dt-bindings: net: lan9645x: add LAN9645X switch bindings

Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch.

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0 -0
new file mode 100644
index 0000000000000..043fb48922b41
@@ -0,0 +1,111 @@

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 50

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+        properties:
+          rx-internal-delay-ps:
+            const: 2000
+
+          tx-internal-delay-ps:
+            const: 2000
Quoted 3 lines

[Severity: Medium]
Is it intended to restrict the rx-internal-delay-ps and tx-internal-delay-ps properties to exactly 2000?

Yes, these are the only delay values supported by the mac.

Quoted 13 lines

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 59

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+required:
+  - compatible
+  - reg
+  - ethernet-ports
+
+unevaluatedProperties: false

[Severity: Medium]
Since the switch has integrated PHYs, will users need to define them in an mdio node to correctly resolve the phy-handle references?

Quoted 3 lines

If so, won't this unevaluatedProperties: false at the root level reject the device tree, as the mdio node is not defined in the properties block or inherited from dsa.yaml?

No, any peripherals such as MDIO controllers are meant to be child nodes of an MFD device, as siblings of this switch node. The MDIO bus devices will not be subnodes of this switch node, so they are not meant to be accomodated by this schema.

Quoted 13 lines

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 100

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6 -0
+            ethernet-port@7 {
+                reg = <7>;
+                phy-mode = "rgmii";
+                ethernet = <&cpu_host_port>;
+                rx-internal-delay-ps = <2000>;
+                tx-internal-delay-ps = <2000>;

[Severity: Medium]
Can this combination of phy-mode = "rgmii" and a 2000ps internal delay be used here?

Quoted 6 lines

According to the ethernet controller bindings, phy-mode = "rgmii" implies the delay is implemented on the PCB. Adding a 2000ps internal MAC delay on top of this might result in a double delay.

If the hardware has fixed internal delays, should this use phy-mode = "rgmii-id" instead?

No, the intention here is to describe the situation where the CPU port and the conduit are connected mac-to-mac. Documentation/networking/phy.rst:

* PHY_INTERFACE_MODE_RGMII: the PHY is not responsible for inserting any internal delay by itself, it assumes that either the Ethernet MAC (if capable) or the PCB traces insert the correct 1.5-2ns delay

RGMII_ID means the PHY should insert delays on both rx and tx, which would be incorrect here.

Quoted 3 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=2

#10 lore raw

Re: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings

In reply to Jens Emil Schulz Østergaard

This is my reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=2

Quoted 11 lines

--- Patch [2]: [PATCH net-next v11 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings --- commit 1b95e77c1cab7610f3d242846549a69514641335
Author: Jens Emil Schulz Østergaard <[email protected]>

dt-bindings: net: lan9645x: add LAN9645X switch bindings

This adds a new DSA binding for the Microchip LAN9645x switch family, using the smallest SKU (microchip,lan96455s-switch) as the fallback compatible, and adds the file to the existing MAINTAINERS entry.

Review

Quoted 1 line
(quoted diff) +0 -0

b/Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml

Quoted 48 lines
Quoted 5 lines

new file mode 100644
index 0000000000000..043fb48922b41

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0 -0
@@ -0,0 +1,111 @@

[ ... ]

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +4 -0
+  ethernet-ports:
+    type: object
+    patternProperties:
+      "^ethernet-port@[0-8]$":

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 Are the constraints under this pattern actually reachable for all legal port node names?

The top-level $ref pulls in dsa.yaml#/$defs/ethernet-ports, which accepts:

patternProperties:

    "^(ethernet-)?ports$":
      patternProperties:
        "^(ethernet-)?port@[0-9a-f]+$":
          description: Ethernet switch ports
          $ref: dsa-port.yaml#
          unevaluatedProperties: false

So both port@N and ethernet-port@N are valid spellings, and indices are not limited to 0-8. The local ethernet-ports object here has no additionalProperties or unevaluatedProperties of its own, so children whose names do not match "^ethernet-port@[0-8]$" are simply not checked against the local constraints.

That means these two both pass dt_binding_check:

  ethernet-ports {
      port@7 {
          phy-mode = "rgmii";
          rx-internal-delay-ps = <500>;   /* const: 2000 not applied */
      };
  };

  ethernet-ports {
      ethernet-port@9 {                   /* index > 8 not rejected */
          reg = <9>;
      };
  };
Quoted 4 lines

Would using the "^(ethernet-)?port@[0-8]$" spelling here, as Documentation/devicetree/bindings/net/dsa/vitesse,vsc73xx.yaml does with "^(ethernet-)?port@6$", make the new per-port constraints effective?

Yes, I will update the regex.

Quoted 49 lines

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 50

Quoted 12 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +12 -0
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          rx-internal-delay-ps:
+            const: 2000
+
+          tx-internal-delay-ps:
+            const: 2000

Discovered by: opus-5, sashiko-gemini · Missed by: sonnet-5 · Confirmed by: sonnet-5 Should these two properties be guarded by an rgmii phy-mode conditional?

As written they are declared for every port index 0-8 with no phy-mode condition, and since they live in the same schema object that carries
unevaluatedProperties: false, they count as evaluated for any phy-mode. This passes validation:

  ethernet-port@0 {
      reg = <0>;
      phy-mode = "gmii";
      rx-internal-delay-ps = <2000>;
  };

Per the driver, only ports 7 and 8 have RGMII pins (lan9645x_phylink_get_caps(): 0..4 GMII/cuphy, 5..6 SerDes, 7..8 RGMII), and only lan9645x_rgmii_dll_config() programs the delay lines, with RGMII_IDX(port) defined for ports 4/7/8 only. On a gmii port the value is stored in p->rx_internal_delay by lan9645x_port_setup() and then never used, with no diagnostic.

The existing pattern is a conditional, see Documentation/devicetree/bindings/net/dsa/vitesse,vsc73xx.yaml:

"^(ethernet-)?port@6$":
allOf:
- if:
properties:
phy-mode:
contains:
enum:
- rgmii
then:
properties:
rx-internal-delay-ps: ...

Quoted 2 lines

Documentation/devicetree/bindings/net/ethernet-controller.yaml also defines these properties only inside an rgmii* phy-mode conditional.

Yes, I will a conditional here.

Quoted 10 lines

Separately, ethernet-controller.yaml states:

A value of 2000ps, i.e 2ns, and a phy-mode of "rgmii" will not be accepted by Reviewers

which is the combination this binding mandates with const: 2000 and shows in the example below. Is a phy-mode of "rgmii" together with a 2000 ps internal delay intended here, rather than one of the rgmii-rxid / rgmii-txid / rgmii-id modes?

I think ethernet-controller.yaml talks about the situation where there is a PHY present. The intent here is a mac to mac connection. I was specifically instructed to model it like this, and not do use rgmii-*id as a way to communicate delay programming of the MAC. It is also clear from Documentation/networking/phy.rst
that this is the right way to model mac to mac.

Quoted 49 lines
Quoted 26 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +25 -0
+
+$ref: dsa.yaml#/$defs/ethernet-ports
+
+required:
+  - compatible
+  - reg
+  - ethernet-ports
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ethernet-switch@4000 {
+        compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch";
+        reg = <0x4000 0x244>;
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            ethernet-port@0 {
+                reg = <0>;
+                phy-mode = "gmii";
+                phy-handle = <&cuphy0>;
+            };

[ ... ]

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +8 -0
+
+            ethernet-port@7 {
+                reg = <7>;
+                phy-mode = "rgmii";
+                ethernet = <&cpu_host_port>;
+                rx-internal-delay-ps = <2000>;
+                tx-internal-delay-ps = <2000>;
+

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 111

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +10 -0
+                fixed-link {
+                    speed = <1000>;
+                    full-duplex;
+                    pause;
+                };
+            };
+        };
+    };
+...
+
      ^^^
Quoted 5 lines

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 This isn't a bug, but there is a blank line after the end-of-document marker at the end of the file, which git diff --check reports as "new blank line at EOF". The other bindings in this directory end with "..." and nothing after it.

I will remove this.

Quoted 2 lines

Cross-instance finding from sashiko-gemini

(008974e58f4042f8866239fc681c104931d4e9cd342a5b5be37f42504a115cf0):

Quoted 2 lines

Discovered by: sashiko-gemini, opus-5 · Missed by: sonnet-5 · Confirmed by: opus-5 The schema lacks an mdio node definition while setting unevaluatedProperties: false at the root,

which inadvertently prevents instantiation of the integrated PHYs referenced in the example.

#11 lore raw

PATCH v11 3/9 net: dsa: lan9645x: add autogenerated register macros

In reply to Jens Emil Schulz Østergaard

Add autogenerated register macros and update MAINTAINERS file. The register macros are generated using the same tool we use for lan966x, sparx5 and lan969x.

---
Changes in v7:
- Add ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.

Changes in v3:
- No changes

Changes in v2:
- Add cpuq registers

---
 MAINTAINERS                                        |    1 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1937 ++++++++++++++++++++
 2 files changed, 1938 insertions(+)
MAINTAINERS +1 -0
index da03885eb0d0..f2cbe6209bb4 100644
@@ -17646,6 +17646,7 @@ M:	[email protected]
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml
+F:	drivers/net/dsa/microchip/lan9645x/*
 F:	include/linux/dsa/lan9645x.h
 F:	net/dsa/tag_lan9645x.c
 
drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h new file +1937 -0

1,937 lines not on this page · raw message

Signature · 1 line
2.52.0
#12 lore raw

PATCH v11 4/9 net: dsa: lan9645x: add basic dsa driver for LAN9645X

In reply to Jens Emil Schulz Østergaard

Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.

This patch only wires up the internal CuPHYs (ports 0-4) and the RGMII paths for ports 7 and 8. The supported SerDes-based modes: SGMII, QSGMII, 1000BASE-X and 2500BASE-X on ports 5-8 are deferred, and support will be added in follow-up patches. Port 5-6 have no usable interface mode in this patch, and should not be declared in DT until SerDes support lands.

The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.

This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver

drivers/net/dsa/ocelot/ocelot_ext.c

which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.

The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.

---
Changes in v9:
- Drop the DEV4 RGMII muxing support.

Changes in v8:
- Remove the CPU_PORT macro, which named the chips internal CPU port module and collided with the DSA CPU port terminology. Reference the module as lan9645x->num_phys_ports.
- Rework the port map comment to distinguish the chip CPU port modules (indices 9-10) from the DSA CPU port (the NPI front port).
- Derive PGID_GP_START from NUM_PHYS_PORTS instead of CPU_PORT.
- Add a port_mux_lock mutex to serialize port mux arbitration in lan9645x_phylink_mac_prepare().

Changes in v7:
- use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames

Changes in v5:
- remove dd_dis and tsn_dis, and add SKU supported port validation during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4 and 7.
- rx/tx-internal-delay-ps checked against support 2ns value
- update commit message
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit

Changes in v4:
- add comment to QSYS_RES_CFG configuration
- phylink_mac_prepare: fix to make sure we can dynamically change rgmii on port 4
- move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- skip WARN_ON in lan9645x_to_port

Changes in v3:
- move DEV_MAC_TAGS_CFG config to port setup, for vlan overhead in port frame maxlen
- remove code disabling ipv6 on conduit
- use of_property_read_u32 for {rx,tx}-internal-delay-ps
- use dsa_user_ports(ds) instead of GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- update obey vlan comment

Changes in v2:
- source Kconfig from drivers/net/dsa/Kconfig
- sorting in Kconfig and Makefiles
- remove unused struct fields
- remote path delays
- use port_setup and dp->dn instead of DTS parsing
- phylink: split rgmii setup into dll and speed config
- phylink: remove pcs/sgmii/qsgmii related code
- phylink: simplify mac_prepare
- phylink: remove phylink_ops wrappers
- phylink: remove unrelated config from link up
- phylink: reorder functions according to phylink call order

---
 drivers/net/dsa/Kconfig                            |   2 +
 drivers/net/dsa/microchip/Makefile                 |   1 +
 drivers/net/dsa/microchip/lan9645x/Kconfig         |  11 +
 drivers/net/dsa/microchip/lan9645x/Makefile        |   8 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 447 +++++++++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 332 +++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c  |  85 ++++
 .../net/dsa/microchip/lan9645x/lan9645x_phylink.c  | 382 ++++++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 214 ++++++++++
 9 files changed, 1482 insertions(+)
drivers/net/dsa/Kconfig +2 -0
index 4ab567c5bbaf..91431ef6c425 100644
@@ -72,6 +72,8 @@ config NET_DSA_MV88E6060
 
 source "drivers/net/dsa/microchip/Kconfig"
 
+source "drivers/net/dsa/microchip/lan9645x/Kconfig"
+
 source "drivers/net/dsa/mv88e6xxx/Kconfig"
 
 source "drivers/net/dsa/mxl862xx/Kconfig"
drivers/net/dsa/microchip/Makefile +1 -0
index 9347cfb3d0b5..e75f17888f75 100644
@@ -12,3 +12,4 @@ endif
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C)	+= ksz9477_i2c.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI)		+= ksz_spi.o
 obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI)	+= ksz8863_smi.o
+obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X)	+= lan9645x/
drivers/net/dsa/microchip/lan9645x/Kconfig new file +11 -0
new file mode 100644
index 000000000000..4d9fdf34104e
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config NET_DSA_MICROCHIP_LAN9645X
+	tristate "Microchip Lan9645x switch support"
+	depends on NET_DSA
+	select NET_DSA_TAG_LAN9645X
+	help
+	  This driver adds DSA support for Microchip Lan9645x switch chips.
+	  The lan9645x switch is a multi-port Gigabit AVB/TSN Ethernet Switch
+	  with five integrated 10/100/1000Base-T PHYs. In addition to the
+	  integrated PHYs, it supports up to 2 RGMII/RMII, up to 2
+	  BASE-X/SERDES/2.5GBASE-X and one Quad-SGMII/Quad-USGMII interfaces.
drivers/net/dsa/microchip/lan9645x/Makefile new file +8 -0
new file mode 100644
index 000000000000..7cc0ae0ada40
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o
+
+mchp-lan9645x-objs := \
+	lan9645x_main.o \
+	lan9645x_npi.o \
+	lan9645x_phylink.o \
+	lan9645x_port.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +447 -0

447 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +332 -0

332 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c new file +85 -0

85 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +382 -0

382 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +214 -0

214 lines not on this page · raw message

Signature · 1 line
2.52.0
#13 lore raw

Re: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Standalone ports drop all normal data plane traffic destined for the CPU because the CPU port…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Standalone ports drop all normal data plane traffic destined for the CPU because the CPU port module is missing from the source port forwarding masks (PGID_SRC) and the flooding masks (PGID_UC, PGID_MC).
- [Medium] Pause frame start watermark (PAUSE_START) exceeds the port's maximum allowed memory (ATOP) for jumbo frames, breaking flow control and causing silent tail drops.
--

--- Patch [4]: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X --- commit dd8bddd9c4ac1f2dbff1feda2560552c682fa913

Author: Jens Emil Schulz Østergaard <[email protected]>
Date:   Wed Aug 5 14:34:52 2026 +0000

net: dsa: lan9645x: add basic dsa driver for LAN9645X

Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2 -0
+static int lan9645x_setup(struct dsa_switch *ds)
+{

[ ... ]

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+	/* Disable bridging by default */
+	for (int p = 0; p < lan9645x->num_phys_ports; p++) {
+		lan_wr(0, lan9645x, ANA_PGID(PGID_SRC + p));
+
+		/* Do not forward BPDU frames to the front ports and copy them
+		 * to CPU
+		 */
+		lan_wr(ANA_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA,
+		       lan9645x, ANA_CPU_FWD_BPDU_CFG(p));
+	}

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +9 -0
+	/* Multicast to all front ports */
+	lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MC));
+
+	/* IP multicast to all front ports */
+	lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MCIPV4));
+	lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MCIPV6));
+
+	/* Unicast to all front ports */
+	lan_wr(front_ports, lan9645x, ANA_PGID(PGID_UC));

[Severity: High]
Does this configuration drop normal data plane traffic intended for the CPU on standalone ports? Setting the source forwarding mask (PGID_SRC) to 0 for all user ports seems to block them from forwarding frames to any destination, including the NPI or CPU port module.

Furthermore, deriving front_ports from dsa_user_ports(ds) excludes the CPU port from the flooding masks. Should the CPU port be included in the source forwarding and flooding masks to ensure host traffic is not blackholed?

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +0 -0

[ ... ]

Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +15 -0
+void lan9645x_port_set_tail_drop_wm(struct lan9645x *lan9645x)
+{
+	int shared_per_port;
+	struct dsa_port *dp;
+
+	/* Configure tail dropping watermark */
+	shared_per_port =
+		lan9645x->shared_queue_sz / (lan9645x->num_phys_ports + 1);
+
+	/* The total memory size is divided by number of front ports plus CPU
+	 * port.
+	 */
+	dsa_switch_for_each_available_port(dp, lan9645x->ds)
+		lan_wr(lan9645x_wm_enc(shared_per_port), lan9645x,
+		       SYS_ATOP(dp->index));

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +4 -0
+int lan9645x_port_set_maxlen(struct lan9645x *lan9645x, int port, size_t sdu)
+{
+	struct lan9645x_port *p = lan9645x_to_port(lan9645x, port);
+	int maxlen = sdu + ETH_HLEN + ETH_FCS_LEN;

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c line 124

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +10 -0
+	/* Set Pause WM hysteresis */
+	lan_rmw(SYS_PAUSE_CFG_PAUSE_STOP_SET(lan9645x_wm_enc(4 * maxlen)) |
+		SYS_PAUSE_CFG_PAUSE_START_SET(lan9645x_wm_enc(6 * maxlen)),
+		SYS_PAUSE_CFG_PAUSE_START |
+		SYS_PAUSE_CFG_PAUSE_STOP,
+		lan9645x,
+		SYS_PAUSE_CFG(p->chip_port));
+
+	return 0;
+}

[Severity: Medium]
Will jumbo frames hit the tail drop watermark before triggering flow control?

The tail drop watermark (SYS_ATOP) in lan9645x_port_set_tail_drop_wm() appears to be statically set to around 16KB. However, PAUSE_START dynamically scales with maxlen (6 * maxlen) in lan9645x_port_set_maxlen().

For MTUs larger than roughly 2.7KB, PAUSE_START will exceed SYS_ATOP. Could this cause the port to silently drop frames because it hits the tail drop limit before ever reaching the threshold to emit pause frames?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=4
#14 lore raw

Re: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X

Quoted 35 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Standalone ports drop all normal data plane traffic destined for the CPU because the CPU port module is missing from the source port forwarding masks (PGID_SRC) and the flooding masks (PGID_UC, PGID_MC).
- [Medium] Pause frame start watermark (PAUSE_START) exceeds the port's maximum allowed memory (ATOP) for jumbo frames, breaking flow control and causing silent tail drops.
--

--- Patch [4]: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X --- commit dd8bddd9c4ac1f2dbff1feda2560552c682fa913

Author: Jens Emil Schulz Østergaard <[email protected]>
Date:   Wed Aug 5 14:34:52 2026 +0000

net: dsa: lan9645x: add basic dsa driver for LAN9645X

Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2 -0
+static int lan9645x_setup(struct dsa_switch *ds)
+{

[ ... ]

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+     /* Disable bridging by default */
+     for (int p = 0; p < lan9645x->num_phys_ports; p++) {
+             lan_wr(0, lan9645x, ANA_PGID(PGID_SRC + p));
+
+             /* Do not forward BPDU frames to the front ports and copy them
+              * to CPU
+              */
+             lan_wr(ANA_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA,
+                    lan9645x, ANA_CPU_FWD_BPDU_CFG(p));
+     }

[ ... ]

Quoted 15 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +9 -0
+     /* Multicast to all front ports */
+     lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MC));
+
+     /* IP multicast to all front ports */
+     lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MCIPV4));
+     lan_wr(front_ports, lan9645x, ANA_PGID(PGID_MCIPV6));
+
+     /* Unicast to all front ports */
+     lan_wr(front_ports, lan9645x, ANA_PGID(PGID_UC));

[Severity: High]
Does this configuration drop normal data plane traffic intended for the CPU on standalone ports? Setting the source forwarding mask (PGID_SRC) to 0 for all user ports seems to block them from forwarding frames to any destination, including the NPI or CPU port module.

False positive. The CPU port module is ignored in PGID_SRC. Setting this to 0 for standalone ports is exactly what we want. They must not forward to their siblings. Copy or redirect to the CPU is not inhibited by this.

Quoted 4 lines

Furthermore, deriving front_ports from dsa_user_ports(ds) excludes the CPU port from the flooding masks. Should the CPU port be included in the source forwarding and flooding masks to ensure host traffic is not blackholed?

False positive. I have split the patches to make review easier. The callbacks

port_fdb_add
port_mdb_add
port_set_host_flood

are added in later patches in the same series. These handle unknown and known traffic toward the CPU. For standalone ports flooding of unknown traffic to the cpu can be configured with promiscuous mode and all_multi. So nothing is blackholed.

Quoted 39 lines
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +0 -0

[ ... ]

Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +15 -0
+void lan9645x_port_set_tail_drop_wm(struct lan9645x *lan9645x)
+{
+     int shared_per_port;
+     struct dsa_port *dp;
+
+     /* Configure tail dropping watermark */
+     shared_per_port =
+             lan9645x->shared_queue_sz / (lan9645x->num_phys_ports + 1);
+
+     /* The total memory size is divided by number of front ports plus CPU
+      * port.
+      */
+     dsa_switch_for_each_available_port(dp, lan9645x->ds)
+             lan_wr(lan9645x_wm_enc(shared_per_port), lan9645x,
+                    SYS_ATOP(dp->index));

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +4 -0
+int lan9645x_port_set_maxlen(struct lan9645x *lan9645x, int port, size_t sdu)
+{
+     struct lan9645x_port *p = lan9645x_to_port(lan9645x, port);
+     int maxlen = sdu + ETH_HLEN + ETH_FCS_LEN;

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c line 124

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +10 -0
+     /* Set Pause WM hysteresis */
+     lan_rmw(SYS_PAUSE_CFG_PAUSE_STOP_SET(lan9645x_wm_enc(4 * maxlen)) |
+             SYS_PAUSE_CFG_PAUSE_START_SET(lan9645x_wm_enc(6 * maxlen)),
+             SYS_PAUSE_CFG_PAUSE_START |
+             SYS_PAUSE_CFG_PAUSE_STOP,
+             lan9645x,
+             SYS_PAUSE_CFG(p->chip_port));
+
+     return 0;
+}

[Severity: Medium]
Will jumbo frames hit the tail drop watermark before triggering flow control?

Quoted 8 lines

The tail drop watermark (SYS_ATOP) in lan9645x_port_set_tail_drop_wm() appears to be statically set to around 16KB. However, PAUSE_START dynamically scales with maxlen (6 * maxlen) in lan9645x_port_set_maxlen().

For MTUs larger than roughly 2.7KB, PAUSE_START will exceed SYS_ATOP. Could this cause the port to silently drop frames because it hits the tail drop limit before ever reaching the threshold to emit pause frames?

The failure mode does not occur, even though the arithmetic is right. However, this is due to another problem. The SYS_ATOP writes are inert now because the taildrop watermarks only apply when cut-through is enabled. I will remove the function lan9645x_port_set_tail_drop_wm

Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=4

#15 lore raw

Re: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X

In reply to Jens Emil Schulz Østergaard

This is my reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=4

Quoted 12 lines

--- Patch [4]: [PATCH net-next v11 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X --- commit 7179961df7a02e02ab3f219d400994a3b9653f9b
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add basic dsa driver for LAN9645X

Adds a new DSA driver for the Microchip LAN9645X switch family, wiring up switch reset/initialization, NPI and CPU port module setup, per-port setup and phylink MAC integration. Register access is done through named regmaps requested from a parent device. Only the internal CuPHYs (ports 0-4) and the RGMII paths on ports 7-8 are supported in this patch.

Quoted 3 lines

A few questions below.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/Kconfig

Quoted 30 lines

drivers/net/dsa/microchip/lan9645x/Kconfig line 5

Quoted 10 lines

new file mode 100644
index 0000000000000..4d9fdf34104eb

drivers/net/dsa/microchip/lan9645x/Kconfig new file +5 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config NET_DSA_MICROCHIP_LAN9645X
+	tristate "Microchip Lan9645x switch support"
+	depends on NET_DSA
+	select NET_DSA_TAG_LAN9645X

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 Should this also depend on REGMAP?

Every register access in the driver goes through the regmap API:
dev_get_regmap() in lan9645x_request_target_regmaps(), and regmap_read()/regmap_write()/regmap_update_bits()/regmap_bulk_read()/ regmap_read_poll_timeout() inside lan_rd()/lan_wr()/lan_rmw()/ lan_bulk_rd()/lan9645x_rd_poll_timeout() in lan9645x_main.h.

With CONFIG_REGMAP=n the module still builds, because include/linux/regmap.h provides stubs:

include/linux/regmap.h

    static inline struct regmap *dev_get_regmap(struct device *dev,
						const char *name)
    {
	    return NULL;
    }
Quoted 6 lines

so lan9645x_request_target_regmaps() always fails and probe returns -ENODEV. REGMAP is not user-selectable, so NET_DSA=y with REGMAP=n is a normal randconfig outcome. The neighbouring Microchip switch drivers state the dependency (NET_DSA_MICROCHIP_KSZ9477_I2C selects REGMAP_I2C, NET_DSA_MICROCHIP_KSZ_SPI selects REGMAP_SPI).

I will add select REGMAP.

Quoted 3 lines

[ ... ]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_main.h

Quoted 65 lines
Quoted 5 lines

new file mode 100644
index 0000000000000..b9168052fcbc1

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +0 -0
@@ -0,0 +1,332 @@

[ ... ]

Quoted 7 lines

+ * 0-63: Destination analysis
+ * 64-79: Aggregation analysis
+ * 80-(80+10-1): Source port analysis
+ *
+ * Destination: By default the first 9 port masks == BIT(port_num). Never change
+ * these except for aggregation. Remaining dst masks are for L2 MC and
+ * flooding. (See FLOODING and FLOODING_IPMC).

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h line 82

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +9 -0
+#define PGID_AGGR			64
+#define PGID_SRC			80
+#define PGID_ENTRIES			89
+
+#define PGID_AGGR_NUM			(PGID_SRC - PGID_AGGR)
+
+/* General purpose PGIDs. */
+#define PGID_GP_START			NUM_PHYS_PORTS
+#define PGID_GP_END			PGID_MRP

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 Is destination PGID 9 really free for general purpose use?

The comment above says the first 9 destination masks are the per-port defaults, and PGID_GP_START is NUM_PHYS_PORTS (9). But this same header describes index 9 as a port module:

/* Port modules 0-8 are front (user) ports. The chip additionally has two
* logical CPU port modules at indices 9 and 10.
...
* Therefore the CPU datapath has two port module indices of interest,
* lan9645x->npi and the cpu port module at index 9.
*/

and lan9645x_port_cpu_init() programs ANA_PORT_CFG(9), QSYS_SW_PORT_MODE(9), REW_PORT_CFG(9) and uses BIT(9) masks. The register definitions also point at 10 addressable port modules:

    #define ANA_PGID(g)               __REG(TARGET_ANA,\
					0, 1, 27648, g, 90, 8, 0, 0, 1, 4)
    #define ANA_PGID_PGID                            GENMASK(9, 0)

with 90 replications (64 destination + 16 aggregation + 10 source), and IFH_DSTS_SZ is 10 in include/linux/dsa/lan9645x.h.

The register-compatible ocelot driver skips num_phys_ports + 1 per-port destination entries, i.e. it treats the CPU port module's entry as reserved:

include/soc/mscc/ocelot.h

    #define for_each_nonreserved_multicast_dest_pgid(ocelot, pgid)	\
	    for ((pgid) = (ocelot)->num_phys_ports + 1;			\
		 (pgid) < PGID_BLACKHOLE;				\
		 (pgid)++)

PGID_GP_START is unused in this patch, but later in the series lan9645x_mdb_pgid_entry_create() allocates from it:

Quoted 7 lines
    for (index = PGID_GP_START; index < PGID_GP_END; index++) {

so the first offloaded MDB group would rewrite ANA_PGID(9), which looks like the CPU port module's own default destination mask. Should PGID_GP_START be NUM_PHYS_PORTS + 1 instead, and the "first 9 port masks" comment be updated to 10?

No the current configuration is correct, and the suggestion would waste PGID[9]. Only the first 9 PGIDs are special (or 'reserved'), in the sense they are used by the forwarding engine for dynamic learning, so dynamically learned mac table entries point to one of these. This is also reflected in the hardware reset default values. PGID[i] = BIT(i) for i=0,...,8 (front ports), but PGID[9] = 0, like the rest of the destination pgids.

We use PGID_CPU=58 for to get known traffic to the CPU, PGID[9] is unused and fine to use as a general purpose PGID.

It is right the mask is 10 bits wide. But CPU port module bit is inert in the aggregation pgids and source pgids, so setting the BIT(9) has no effect. But it is active in the destination pgids, which is how PGID_CPU works.

I will update the comments about PGIDs and the the forwarding decisions.

Quoted 3 lines

[ ... ]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c

Quoted 23 lines
Quoted 6 lines

new file mode 100644
index 0000000000000..836abc74b6f7a

drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +1 -0
@@ -0,0 +1,382 @@
+// SPDX-License-Identifier: GPL-2.0+

drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 11

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +10 -0
+/* Copyright (C) 2026 Microchip Technology Inc.
+ */
+
+#include <linux/phy.h>
+#include <linux/phy/phy.h>
+
+#include "lan9645x_main.h"
+
+/* Port 4 or 7 is RGMII_0 and port 8 is RGMII_1 */
+#define RGMII_IDX(port) ((port) == 8 ? 1 : 0)

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 This isn't a bug, but is this comment left over from the DEV4 muxing that v9 dropped? Ports 0-4 only advertise GMII now, so RGMII_IDX() is only ever evaluated for ports 7 and 8, and lan9645x_phylink_mac_prepare() in this same file says the opposite:

Quoted 4 lines
	/* DEV4 is cuphy-only, so RGMII_0 is always routed to DEV7 (its reset
	 * default); make it explicit on a DEV7 RGMII bring-up.
	 */

I will update the comment.

Quoted 14 lines
Quoted 14 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +14 -0
+
+void lan9645x_phylink_get_caps(struct lan9645x *lan9645x, int port,
+			       struct phylink_config *c)
+{
+	c->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | MAC_10 |
+			      MAC_100 | MAC_1000FD;
+
+	switch (port) {
+	case 0 ... 4:
+		__set_bit(PHY_INTERFACE_MODE_GMII, c->supported_interfaces);
+		break;
+	case 5 ... 6:
+		/* SerDes ports: QSGMII/SGMII/1000BASEX/2500BASEX modes
+		 * require PCS support which is not yet implemented.
Quoted 8 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 30

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +5 -0
+		 * With empty supported_interfaces, these will end up being
+		 * marked unused by the DSA core, if they are declared in the
+		 * DT.
+		 */
+		break;

Discovered by: opus-5 · Missed by: sonnet-5, sashiko-gemini · Confirmed by: sonnet-5 Does the DSA core actually mark such a port unused?

Yes, if port 5 or 6 is declared as a user port. If they are declared as the CPU port, the probe does fail.

Quoted 19 lines

dsa_port_phylink_create() passes dp->pl_config straight to phylink_create(), and the first thing phylink_create() does is:

drivers/net/phy/phylink.c:phylink_create()

	if (phy_interface_empty(config->supported_interfaces)) {
		dev_err(config->dev,
			"phylink: error: empty supported_interfaces\n");
		return ERR_PTR(-EINVAL);
	}

net/dsa/port.c:dsa_port_phylink_create()

	pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), mode,
			    mac_ops);
	if (IS_ERR(pl)) {
		pr_err("error creating PHYLINK: %ld\n", PTR_ERR(pl));
		return PTR_ERR(pl);
	}
Quoted 6 lines

That -EINVAL propagates through dsa_port_setup() and dsa_tree_setup_ports() to dsa_register_switch(), so declaring an enabled port 5 or 6 in DT fails registration of the whole switch, including the working ports. Nothing in net/dsa demotes a port to DSA_PORT_TYPE_UNUSED based on supported_interfaces.

The agent seems to have stopped short of reading the callsite it mentions in dsa_tree_setup_ports():

net/dsa/dsa.c:dsa_tree_setup_ports()

list_for_each_entry(dp, &dst->ports, list) {
        if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) {
                err = dsa_port_setup(dp);
                if (err)
                        goto teardown;
        }
}
list_for_each_entry(dp, &dst->ports, list) {
        if (dsa_port_is_user(dp) || dsa_port_is_unused(dp)) {
                err = dsa_port_setup(dp);
                if (err) {
                        err = dsa_port_setup_as_unused(dp);
                        if (err)
                                goto teardown;
                }
        }
}

You also get helpful errors from DSA in the user port case, but in the CPU port case, it does not tell you the offending port. So I can add a error log in the npi port setup to help the user figure out why it failed to probe.

Quoted 10 lines

The binding added in this series allows those nodes:

Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml

      "^ethernet-port@[0-8]$":

so a schema-valid DT can hit this, with only "phylink: error: empty supported_interfaces" and "error creating PHYLINK: -22" to go on. Would it be clearer to reject ports 5-6 explicitly in port_setup with a message naming the port, and to reword the comment?

Quoted 8 lines

The commit message makes the same claim indirectly:

Port 5-6 have no usable interface mode in this patch, and should not be declared in DT until SerDes support lands.

Could this mention that declaring them fails the whole switch registration rather than just disabling those ports?

But as user ports the do come up as unused, switch registration only fails if they are declared as CPU ports.

Quoted 1 line

[ ... ]

#16 lore raw

PATCH v11 5/9 net: dsa: lan9645x: add bridge support

In reply to Jens Emil Schulz Østergaard

Add support for hardware offloading of the bridge. We support a single bridge device.

---
Changes in v9:
- Drop the port_mux_lock teardown from the setup error path, as the mutex has been removed.

Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module in the port pgid and host flood helpers.

Changes in v5:
- use ds->ageing_time_max
- use packed p->host_flood_req for atomic r/w
- fix typo in set_ageing_time comment
- include lan9645x->bridge deref under lock in brige_join

Changes in v4:
- set_host_flood changed to per port work to coalesce values and skip atomic allocations

Changes in v3:
- allow disabling aging with explicit zero parameters.
- fix non-forwarding stp states
- fix restore host_flood requests on bridge leave
- destroy fwd_domain_lock mutex on setup err path

Changes in v2:
- variable name consistency
- port_set_learning use stp_state before writing to hw
- add set_host_flood for selftests, which need promic/all_multi on standalone interfaces

---
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 309 +++++++++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |  27 ++
 2 files changed, 336 insertions(+)
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +309 -0
index b253813518c2..c145d28ffbb9 100644
@@ -67,7 +67,9 @@ static void lan9645x_teardown(struct dsa_switch *ds)
 {
 	struct lan9645x *lan9645x = ds->priv;
 
+	destroy_workqueue(lan9645x->owq);
 	lan9645x_npi_port_deinit(lan9645x, lan9645x->npi);
+	mutex_destroy(&lan9645x->fwd_domain_lock);
 }
 
 static int lan9645x_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
@@ -146,6 +148,8 @@ static int lan9645x_setup(struct dsa_switch *ds)
 		return err;
 	}
 
+	mutex_init(&lan9645x->fwd_domain_lock);
+
 	/* Link Aggregation Mode: NETDEV_LAG_HASH_L2 */
 	lan_wr(ANA_AGGR_CFG_AC_SMAC_ENA |
 	       ANA_AGGR_CFG_AC_DMAC_ENA,
@@ -265,15 +269,34 @@ static int lan9645x_setup(struct dsa_switch *ds)
 
 	lan9645x_port_set_tail_drop_wm(lan9645x);
 
+	lan9645x->owq = alloc_ordered_workqueue("%s-owq", 0,
+						dev_name(lan9645x->dev));
+	if (!lan9645x->owq) {
+		err = -ENOMEM;
+		goto err_mutex;
+	}
+
 	ds->mtu_enforcement_ingress = true;
 	ds->assisted_learning_on_cpu_port = true;
 	ds->fdb_isolation = true;
 
+	/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are
+	 * aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of
+	 * maximum aging.
+	 */
+	ds->ageing_time_max = 2U * MSEC_PER_SEC *
+			      FIELD_MAX(ANA_AUTOAGE_AGE_PERIOD);
+
 	dev_info(lan9645x->dev,
 		 "SKU features: max_ports=%d\n",
 		 lan9645x->num_phys_ports - lan9645x->num_port_dis);
 
 	return 0;
+
+err_mutex:
+	mutex_destroy(&lan9645x->fwd_domain_lock);
+	lan9645x_npi_port_deinit(lan9645x, lan9645x->npi);
+	return err;
 }
 
 static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,
@@ -282,6 +305,282 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,
 	lan9645x_phylink_get_caps(ds->priv, port, config);
 }
 
+static int lan9645x_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
+{
+	u32 age_secs = max(1, msecs / MSEC_PER_SEC / 2);
+	struct lan9645x *lan9645x = ds->priv;
+
+	/* Entry must suffer two aging scans before it is removed, so it is
+	 * aged after 2*AGE_PERIOD, and the unit is in seconds.
+	 * An age period of 0 disables automatic aging.
+	 */
+	lan_rmw(ANA_AUTOAGE_AGE_PERIOD_SET(msecs ? age_secs : 0),
+		ANA_AUTOAGE_AGE_PERIOD,
+		lan9645x, ANA_AUTOAGE);
+	return 0;
+}
+
+static int lan9645x_port_pre_bridge_flags(struct dsa_switch *ds, int port,
+					  struct switchdev_brport_flags flags,
+					  struct netlink_ext_ack *extack)
+{
+	if (flags.mask &
+	    ~(BR_LEARNING | BR_FLOOD | BR_MCAST_FLOOD | BR_BCAST_FLOOD))
+		return -EINVAL;
+
+	return 0;
+}
+
+static void lan9645x_port_pgid_set(struct lan9645x *lan9645x, u16 pgid,
+				   int chip_port, bool enabled)
+{
+	u32 reg_msk, port_msk;
+
+	WARN_ON(chip_port > lan9645x->num_phys_ports);
+
+	port_msk = ANA_PGID_PGID_SET(enabled ? BIT(chip_port) : 0);
+	reg_msk = ANA_PGID_PGID_SET(BIT(chip_port));
+
+	lan_rmw(port_msk, reg_msk, lan9645x, ANA_PGID(pgid));
+}
+
+static void lan9645x_port_set_learning(struct lan9645x *lan9645x, int port,
+				       bool enabled)
+{
+	struct lan9645x_port *p = lan9645x_to_port(lan9645x, port);
+
+	p->learn_ena = enabled;
+
+	enabled = enabled && (p->stp_state == BR_STATE_LEARNING ||
+			      p->stp_state == BR_STATE_FORWARDING);
+
+	lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(enabled), ANA_PORT_CFG_LEARN_ENA,
+		lan9645x, ANA_PORT_CFG(port));
+}
+
+static int lan9645x_port_bridge_flags(struct dsa_switch *ds, int port,
+				      struct switchdev_brport_flags f,
+				      struct netlink_ext_ack *extack)
+{
+	struct lan9645x *lan9645x = ds->priv;
+
+	if (WARN_ON(port == lan9645x->npi))
+		return -EINVAL;
+
+	if (f.mask & BR_LEARNING)
+		lan9645x_port_set_learning(lan9645x, port,
+					   !!(f.val & BR_LEARNING));
+
+	if (f.mask & BR_FLOOD)
+		lan9645x_port_pgid_set(lan9645x, PGID_UC, port,
+				       !!(f.val & BR_FLOOD));
+
+	if (f.mask & BR_MCAST_FLOOD) {
+		bool ena = !!(f.val & BR_MCAST_FLOOD);
+
+		lan9645x_port_pgid_set(lan9645x, PGID_MC, port, ena);
+		lan9645x_port_pgid_set(lan9645x, PGID_MCIPV4, port, ena);
+		lan9645x_port_pgid_set(lan9645x, PGID_MCIPV6, port, ena);
+	}
+
+	if (f.mask & BR_BCAST_FLOOD)
+		lan9645x_port_pgid_set(lan9645x, PGID_BC, port,
+				       !!(f.val & BR_BCAST_FLOOD));
+
+	return 0;
+}
+
+static void lan9645x_update_fwd_mask(struct lan9645x *lan9645x)
+{
+	struct lan9645x_port *p;
+	struct dsa_port *dp;
+
+	lockdep_assert_held(&lan9645x->fwd_domain_lock);
+
+	/* Updates the source port PGIDs, making sure frames from p
+	 * are only forwarded to ports q != p, where q is relevant to forward
+	 */
+	dsa_switch_for_each_available_port(dp, lan9645x->ds) {
+		u32 mask = 0;
+
+		p = lan9645x_to_port(lan9645x, dp->index);
+
+		if (lan9645x_port_is_bridged(p) &&
+		    (lan9645x->bridge_fwd_mask & BIT(dp->index))) {
+			mask = lan9645x->bridge_mask &
+			       lan9645x->bridge_fwd_mask & ~BIT(dp->index);
+		}
+
+		lan_wr(mask, lan9645x, ANA_PGID(PGID_SRC + dp->index));
+	}
+}
+
+static void __lan9645x_port_mark_host_flood(struct lan9645x *lan9645x, int port,
+					    bool uc, bool mc)
+{
+	lockdep_assert_held(&lan9645x->fwd_domain_lock);
+
+	if (uc)
+		lan9645x->host_flood_uc_mask |= BIT(port);
+	else
+		lan9645x->host_flood_uc_mask &= ~BIT(port);
+
+	if (mc)
+		lan9645x->host_flood_mc_mask |= BIT(port);
+	else
+		lan9645x->host_flood_mc_mask &= ~BIT(port);
+}
+
+static void __lan9645x_port_set_host_flood(struct lan9645x *lan9645x)
+{
+	bool mc_ena, uc_ena;
+	u16 unbridged;
+
+	lockdep_assert_held(&lan9645x->fwd_domain_lock);
+
+	/* We want promiscuous and all_multi to affect standalone ports, for
+	 * debug and test purposes.
+	 *
+	 * However, the linux bridge is incredibly eager to put bridged ports in
+	 * promiscuous mode.
+	 *
+	 * This is unfortunate since lan9645x flood masks are global and not per
+	 * ingress port. When some port triggers unknown uc/mc to the CPU, the
+	 * traffic from any port is forwarded to the CPU.
+	 *
+	 * If the host CPU is weak, this can cause tremendous stress. Therefore,
+	 * we compromise by ignoring this host flood request for bridged ports.
+	 */
+	unbridged = ~lan9645x->bridge_mask & GENMASK(NUM_PHYS_PORTS - 1, 0);
+
+	uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged);
+	lan9645x_port_pgid_set(lan9645x, PGID_UC, lan9645x->num_phys_ports,
+			       uc_ena);
+
+	mc_ena = !!(lan9645x->host_flood_mc_mask & unbridged);
+	lan9645x_port_pgid_set(lan9645x, PGID_MC, lan9645x->num_phys_ports,
+			       mc_ena);
+	lan9645x_port_pgid_set(lan9645x, PGID_MCIPV4, lan9645x->num_phys_ports,
+			       mc_ena);
+	lan9645x_port_pgid_set(lan9645x, PGID_MCIPV6, lan9645x->num_phys_ports,
+			       mc_ena);
+}
+
+static void lan9645x_host_flood_work_fn(struct work_struct *work)
+{
+	struct lan9645x_port *p = container_of(work, struct lan9645x_port,
+					       host_flood_work);
+	struct lan9645x *lan9645x = p->lan9645x;
+	u8 req;
+
+	req = READ_ONCE(p->host_flood_req);
+
+	mutex_lock(&lan9645x->fwd_domain_lock);
+	__lan9645x_port_mark_host_flood(lan9645x, p->chip_port,
+					req & LAN9645X_HOST_FLOOD_UC,
+					req & LAN9645X_HOST_FLOOD_MC);
+	__lan9645x_port_set_host_flood(lan9645x);
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+}
+
+/* Called in atomic context. */
+static void lan9645x_port_set_host_flood(struct dsa_switch *ds, int port,
+					 bool uc, bool mc)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+
+	p = lan9645x_to_port(lan9645x, port);
+
+	WRITE_ONCE(p->host_flood_req,
+		   (uc ? LAN9645X_HOST_FLOOD_UC : 0) |
+		   (mc ? LAN9645X_HOST_FLOOD_MC : 0));
+	queue_work(lan9645x->owq, &p->host_flood_work);
+}
+
+static int lan9645x_port_bridge_join(struct dsa_switch *ds, int port,
+				     struct dsa_bridge bridge,
+				     bool *tx_fwd_offload,
+				     struct netlink_ext_ack *extack)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+
+	p = lan9645x_to_port(lan9645x, port);
+
+	mutex_lock(&lan9645x->fwd_domain_lock);
+	if (lan9645x->bridge && lan9645x->bridge != bridge.dev) {
+		mutex_unlock(&lan9645x->fwd_domain_lock);
+		NL_SET_ERR_MSG_MOD(extack, "Only one bridge supported");
+		return -EBUSY;
+	}
+
+	/* First bridged port sets bridge dev */
+	if (!lan9645x->bridge_mask)
+		lan9645x->bridge = bridge.dev;
+
+	lan9645x->bridge_mask |= BIT(p->chip_port);
+	__lan9645x_port_set_host_flood(lan9645x);
+
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+
+	/* Later: stp_state_set updates forwarding */
+
+	return 0;
+}
+
+static void lan9645x_port_bridge_stp_state_set(struct dsa_switch *ds, int port,
+					       u8 state)
+{
+	struct lan9645x *lan9645x;
+	struct lan9645x_port *p;
+	bool learn_ena;
+
+	lan9645x = ds->priv;
+	p = lan9645x_to_port(lan9645x, port);
+
+	mutex_lock(&lan9645x->fwd_domain_lock);
+
+	p->stp_state = state;
+
+	if (state == BR_STATE_FORWARDING)
+		lan9645x->bridge_fwd_mask |= BIT(p->chip_port);
+	else
+		lan9645x->bridge_fwd_mask &= ~BIT(p->chip_port);
+
+	learn_ena = (state == BR_STATE_LEARNING ||
+		     state == BR_STATE_FORWARDING) && p->learn_ena;
+
+	lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(learn_ena),
+		ANA_PORT_CFG_LEARN_ENA, lan9645x,
+		ANA_PORT_CFG(p->chip_port));
+
+	lan9645x_update_fwd_mask(lan9645x);
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+}
+
+static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,
+				       struct dsa_bridge bridge)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+
+	p = lan9645x_to_port(lan9645x, port);
+
+	mutex_lock(&lan9645x->fwd_domain_lock);
+
+	lan9645x->bridge_mask &= ~BIT(p->chip_port);
+
+	/* Last port leaving clears bridge dev */
+	if (!lan9645x->bridge_mask)
+		lan9645x->bridge = NULL;
+
+	__lan9645x_port_set_host_flood(lan9645x);
+	lan9645x_update_fwd_mask(lan9645x);
+
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+}
+
 static const struct dsa_switch_ops lan9645x_switch_ops = {
 	.get_tag_protocol		= lan9645x_get_tag_protocol,
 
@@ -295,6 +594,15 @@ static const struct dsa_switch_ops lan9645x_switch_ops = {
 	/* MTU  */
 	.port_change_mtu		= lan9645x_change_mtu,
 	.port_max_mtu			= lan9645x_get_max_mtu,
+
+	/* Bridge integration */
+	.set_ageing_time		= lan9645x_set_ageing_time,
+	.port_pre_bridge_flags		= lan9645x_port_pre_bridge_flags,
+	.port_bridge_flags		= lan9645x_port_bridge_flags,
+	.port_bridge_join		= lan9645x_port_bridge_join,
+	.port_bridge_leave		= lan9645x_port_bridge_leave,
+	.port_stp_state_set		= lan9645x_port_bridge_stp_state_set,
+	.port_set_host_flood		= lan9645x_port_set_host_flood,
 };
 
 static int lan9645x_request_target_regmaps(struct lan9645x *lan9645x)
@@ -376,6 +684,7 @@ static int lan9645x_probe(struct platform_device *pdev)
 
 		p->lan9645x = lan9645x;
 		p->chip_port = port;
+		INIT_WORK(&p->host_flood_work, lan9645x_host_flood_work_fn);
 		lan9645x->ports[port] = p;
 	}
 
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +27 -0
index b9168052fcbc..a0cd1707e114 100644
@@ -117,6 +117,9 @@
 				 (_cond), SLOW_RD_SLEEP_US,		\
 				 SLOW_RD_SLEEPTIMEOUT_US)
 
+#define LAN9645X_HOST_FLOOD_UC		BIT(0)
+#define LAN9645X_HOST_FLOOD_MC		BIT(1)
+
 /* NPI port prefix config encoding
  *
  * 0: No CPU extraction header (normal frames)
@@ -158,6 +161,11 @@ struct lan9645x {
 	struct dsa_switch *ds;
 	struct regmap *rmap[NUM_TARGETS];
 
+	u16 host_flood_uc_mask;
+	u16 host_flood_mc_mask;
+
+	struct workqueue_struct *owq;
+
 	int shared_queue_sz;
 
 	/* NPI chip_port */
@@ -166,6 +174,12 @@ struct lan9645x {
 	u8 num_phys_ports;
 	struct lan9645x_port **ports;
 
+	/* Forwarding Database */
+	struct net_device *bridge; /* Only support single bridge */
+	u16 bridge_mask; /* Mask for bridged ports */
+	u16 bridge_fwd_mask; /* Mask for forwarding bridged ports */
+	struct mutex fwd_domain_lock; /* lock forwarding configuration */
+
 	int num_port_dis;
 };
 
@@ -173,9 +187,17 @@ struct lan9645x_port {
 	struct lan9645x *lan9645x;
 
 	u8 chip_port;
+	u8 stp_state;
+	bool learn_ena;
 
 	bool rx_internal_delay;
 	bool tx_internal_delay;
+
+	struct work_struct host_flood_work;
+	/* Packed host flood request deposited by port_set_host_flood (atomic
+	 * context) and consumed by host_flood_work_fn.
+	 */
+	u8 host_flood_req;
 };
 
 extern const struct phylink_mac_ops lan9645x_phylink_mac_ops;
@@ -222,6 +244,11 @@ static inline struct lan9645x_port *lan9645x_to_port(struct lan9645x *lan9645x,
 	return lan9645x->ports[port];
 }
 
+static inline bool lan9645x_port_is_bridged(struct lan9645x_port *p)
+{
+	return p && (p->lan9645x->bridge_mask & BIT(p->chip_port));
+}
+
 static inline struct regmap *lan_tgt2rmap(struct lan9645x *lan9645x,
 					  enum lan9645x_target t, int tinst)
 {
Signature · 1 line
2.52.0
#17 lore raw

Re: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Hardware learning is not disabled when a port leaves a bridge, causing cross-port FDB pollution…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Hardware learning is not disabled when a port leaves a bridge, causing cross-port FDB pollution that breaks software bridging/routing for standalone ports. --

--- Patch [5]: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support --- commit f959003f0679008432479a15ff4b25747ede3826
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add bridge support

Add support for hardware offloading of the bridge. We support a single bridge device.

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
index b253813518c20..c145d28ffbb99 100644

[ ... ]

Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -282,6 +305,282 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,

[ ... ]

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +11 -0
+static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,
+				       struct dsa_bridge bridge)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+
+	p = lan9645x_to_port(lan9645x, port);
+
+	mutex_lock(&lan9645x->fwd_domain_lock);
+
+	lan9645x->bridge_mask &= ~BIT(p->chip_port);

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 582

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+
+	/* Last port leaving clears bridge dev */
+	if (!lan9645x->bridge_mask)
+		lan9645x->bridge = NULL;
+
+	__lan9645x_port_set_host_flood(lan9645x);
+	lan9645x_update_fwd_mask(lan9645x);
+
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+}

[Severity: High]
Does this code need to clear p->learn_ena when a port leaves the bridge?

When a port is removed from the hardware bridge, its learning state incorrectly remains enabled. If this port and another port are later added to a software bridge (for example, if the hardware only supports one offloaded bridge), the DSA core transitions the standalone port to BR_STATE_FORWARDING.

Because p->learn_ena was not cleared during bridge leave, the call to lan9645x_port_bridge_stp_state_set() will incorrectly re-enable hardware learning for the standalone port:

	learn_ena = (state == BR_STATE_LEARNING ||
		     state == BR_STATE_FORWARDING) && p->learn_ena;

	lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(learn_ena), ...

This causes the port to learn MAC addresses into the shared HOST_PVID FDB used by standalone ports. When the other software-bridged port (which expects to send unknown unicast traffic to the CPU) receives traffic for a MAC dynamically learned by this port, the hardware resolves the destination.

However, since PGID_SRC for standalone ports is 0, the packet is silently dropped in hardware instead of being forwarded to the CPU, breaking network connectivity for the fallback software bridge.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=5
#18 lore raw

Re: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support

Quoted 47 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Hardware learning is not disabled when a port leaves a bridge, causing cross-port FDB pollution that breaks software bridging/routing for standalone ports. --

--- Patch [5]: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support --- commit f959003f0679008432479a15ff4b25747ede3826
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add bridge support

Add support for hardware offloading of the bridge. We support a single bridge device.

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
index b253813518c20..c145d28ffbb99 100644

[ ... ]

Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -282,6 +305,282 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,

[ ... ]

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +11 -0
+static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,
+                                    struct dsa_bridge bridge)
+{
+     struct lan9645x *lan9645x = ds->priv;
+     struct lan9645x_port *p;
+
+     p = lan9645x_to_port(lan9645x, port);
+
+     mutex_lock(&lan9645x->fwd_domain_lock);
+
+     lan9645x->bridge_mask &= ~BIT(p->chip_port);

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 582

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+
+     /* Last port leaving clears bridge dev */
+     if (!lan9645x->bridge_mask)
+             lan9645x->bridge = NULL;
+
+     __lan9645x_port_set_host_flood(lan9645x);
+     lan9645x_update_fwd_mask(lan9645x);
+
+     mutex_unlock(&lan9645x->fwd_domain_lock);
+}

[Severity: High]
Does this code need to clear p->learn_ena when a port leaves the bridge?

Quoted 3 lines

When a port is removed from the hardware bridge, its learning state incorrectly remains enabled.

It does not remain enabled. The DSA core resets the bridge port flags on bridge leave, learning included, and it does so before it puts the port back into BR_STATE_FORWARDING.

dsa_port_bridge_leave() ends in dsa_port_switchdev_unsync_attrs(), which calls dsa_port_clear_brport_flags() first and dsa_port_set_state_now(dp, BR_STATE_FORWARDING, true) second. BR_LEARNING is in that helpers mask but not in its val, so the driver is called with mask = BR_LEARNING, val = 0, and lan9645x_port_set_learning() clears p->learn_ena and writes ANA_PORT_CFG.LEARN_ENA = 0 immediately.

So by the time lan9645x_port_bridge_stp_state_set() evaluates

      (state == BR_STATE_LEARNING || state == BR_STATE_FORWARDING) &&
      p->learn_ena

p->learn_ena is already false and hardware learning stays off. Clearing it in lan9645x_port_bridge_leave() would be redundant.

Quoted 24 lines

If this port and another port are later added to a software
bridge (for example, if the hardware only supports one offloaded bridge), the DSA core transitions the standalone port to BR_STATE_FORWARDING.

Because p->learn_ena was not cleared during bridge leave, the call to lan9645x_port_bridge_stp_state_set() will incorrectly re-enable hardware learning for the standalone port:

        learn_ena = (state == BR_STATE_LEARNING ||
                     state == BR_STATE_FORWARDING) && p->learn_ena;

        lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(learn_ena), ...

This causes the port to learn MAC addresses into the shared HOST_PVID FDB used by standalone ports. When the other software-bridged port (which expects to send unknown unicast traffic to the CPU) receives traffic for a MAC dynamically learned by this port, the hardware resolves the destination.

However, since PGID_SRC for standalone ports is 0, the packet is silently dropped in hardware instead of being forwarded to the CPU, breaking network connectivity for the fallback software bridge.

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=5

#19 lore raw

Re: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support

In reply to Jens Emil Schulz Østergaard

This is my reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=5

Quoted 6 lines

--- Patch [5]: [PATCH net-next v11 5/9] net: dsa: lan9645x: add bridge support --- commit a6410541102bca5214b00713a7a5b063ffd47ab2
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add bridge support

Quoted 8 lines

This adds bridge offload to the lan9645x DSA driver: bridge join/leave, STP state and learning, port flooding flags, host flood handling through an ordered workqueue, and an ageing time setter. A single bridge device is supported.

A few questions about the bridge integration below.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_main.c

Quoted 48 lines
Quoted 3 lines

index b253813518c20..c145d28ffbb99 100644

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -265,15 +269,34 @@ static int lan9645x_setup(struct dsa_switch *ds)
 
 	lan9645x_port_set_tail_drop_wm(lan9645x);
 

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 281

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7 -0
+	lan9645x->owq = alloc_ordered_workqueue("%s-owq", 0,
+						dev_name(lan9645x->dev));
+	if (!lan9645x->owq) {
+		err = -ENOMEM;
+		goto err_mutex;
+	}
+
 	ds->mtu_enforcement_ingress = true;
 	ds->assisted_learning_on_cpu_port = true;
 	ds->fdb_isolation = true;

Discovered by: opus-5 · Missed by: fable-5, sashiko-gemini · Confirmed by: fable-5 Should ds->max_num_bridges be set to 1 here as well, next to ds->fdb_isolation?

In net/dsa/dsa.c, dsa_bridge_num_get() treats a zero maximum as "no FDB isolation" and hands back a constant bridge number:

	/* Switches without FDB isolation support don't get unique
	 * bridge numbering
	 */
	if (!max)
		return 0;

and net/dsa/port.c dsa_port_bridge_create() skips the range check for the same reason:

	bridge->num = dsa_bridge_num_get(br, ds->max_num_bridges);
	if (ds->max_num_bridges && !bridge->num) {
		NL_SET_ERR_MSG_MOD(extack,
				   "Range of offloadable bridges exceeded");

So the driver requests FDB isolation while the isolation key the core returns is always 0, and the single-bridge limit is then open coded in lan9645x_port_bridge_join() with -EBUSY and "Only one bridge supported". The other in-tree drivers that set fdb_isolation (felix, sja1105, vitesse-vsc73xx-core, rtl8365mb, netc) also set max_num_bridges.

Quoted 4 lines

The driver does not consume db.bridge.num anywhere in the final series, so nothing is mis-keyed today; it is the mismatch between the two fields that looks unintended.

Yes, i think this is right. I will set max_num_bridges=1 and remove the open coded single-bridge limit.

Quoted 31 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 289

Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7 -0
+	/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are
+	 * aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of
+	 * maximum aging.
+	 */
+	ds->ageing_time_max = 2U * MSEC_PER_SEC *
+			      FIELD_MAX(ANA_AUTOAGE_AGE_PERIOD);
+

Discovered by: opus-5 · Missed by: fable-5, sashiko-gemini · Confirmed by: fable-5 Only the upper ageing bound is published to the core here, leaving ds->ageing_time_min at 0. Should ds->ageing_time_min = 2 * MSEC_PER_SEC be set too?

net/dsa/switch.c dsa_switch_ageing_time() only rejects out-of-range requests when the corresponding limit is nonzero:

	if (ds->ageing_time_min && ageing_time < ds->ageing_time_min)
		return -ERANGE;

	if (ds->ageing_time_max && ageing_time > ds->ageing_time_max)
		return -ERANGE;

net/bridge/br_stp.c br_set_ageing_time() imposes no lower bound either, so a request below 2000 ms reaches lan9645x_set_ageing_time() and is clamped while success is reported:

	ip link set br0 type bridge ageing_time 100
	  -> lan9645x_set_ageing_time(ds, 1000)
	     age_secs = max(1, 1000 / 1000 / 2) = max(1, 0) = 1
	     ANA_AUTOAGE_AGE_PERIOD = 1, i.e. entries age after 2 s
Quoted 5 lines

For any msecs in 1..3999 the division yields 0 or 1 and the clamp forces 1, so every sub-2 s request silently becomes an effective 2 s hardware ageing while the bridge keeps and reports the value userspace asked for. drivers/net/dsa/netc/netc_main.c sets ds->ageing_time_min alongside ds->ageing_time_max.

We intentionally do not set ds->ageing_time_min because we would like to support disabling ageing with an explicit zero value.

We generally round down to a 2s multiple, but I decided to round up in the (0,2s] interval. If a user requests a very fast ageing time, I think it is better to configure it to 2s, than to disable ageing.

Quoted 73 lines
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +5 -0
 	dev_info(lan9645x->dev,
 		 "SKU features: max_ports=%d\n",
 		 lan9645x->num_phys_ports - lan9645x->num_port_dis);
 
 	return 0;
+
+err_mutex:
+	mutex_destroy(&lan9645x->fwd_domain_lock);
+	lan9645x_npi_port_deinit(lan9645x, lan9645x->npi);
+	return err;
 }

[ ... ]

Quoted 18 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +14 -0
@@ -282,6 +305,282 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,
 	lan9645x_phylink_get_caps(ds->priv, port, config);
 }
 
+static int lan9645x_set_ageing_time(struct dsa_switch *ds, unsigned int msecs)
+{
+	u32 age_secs = max(1, msecs / MSEC_PER_SEC / 2);
+	struct lan9645x *lan9645x = ds->priv;
+
+	/* Entry must suffer two aging scans before it is removed, so it is
+	 * aged after 2*AGE_PERIOD, and the unit is in seconds.
+	 * An age period of 0 disables automatic aging.
+	 */
+	lan_rmw(ANA_AUTOAGE_AGE_PERIOD_SET(msecs ? age_secs : 0),
+		ANA_AUTOAGE_AGE_PERIOD,
+		lan9645x, ANA_AUTOAGE);
+	return 0;
+}

[ ... ]

Quoted 13 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +13 -0
+static void __lan9645x_port_set_host_flood(struct lan9645x *lan9645x)
+{
+	bool mc_ena, uc_ena;
+	u16 unbridged;
+
+	lockdep_assert_held(&lan9645x->fwd_domain_lock);
+
+	/* We want promiscuous and all_multi to affect standalone ports, for
+	 * debug and test purposes.
+	 *
+	 * However, the linux bridge is incredibly eager to put bridged ports in
+	 * promiscuous mode.
+	 *

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 456

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+	 * This is unfortunate since lan9645x flood masks are global and not per
+	 * ingress port. When some port triggers unknown uc/mc to the CPU, the
+	 * traffic from any port is forwarded to the CPU.
+	 *
+	 * If the host CPU is weak, this can cause tremendous stress. Therefore,
+	 * we compromise by ignoring this host flood request for bridged ports.
+	 */
+	unbridged = ~lan9645x->bridge_mask & GENMASK(NUM_PHYS_PORTS - 1, 0);
+
+	uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged);

Discovered by: fable-5, opus-5 · Missed by: sashiko-gemini This isn't a bug, but could the commit message mention the two user visible behaviours added here?

The log says only "Add support for hardware offloading of the bridge. We support a single bridge device.", while this masking means a .port_set_host_flood request for a bridged port is accepted and then dropped:

net/dsa/user.c dsa_user_change_rx_flags() -> dsa_user_manage_host_flood() -> net/dsa/port.c dsa_port_set_host_flood() -> lan9645x_port_set_host_flood() -> lan9645x_host_flood_work_fn() -> __lan9645x_port_set_host_flood()

Quoted 9 lines

Since br_manage_promisc() puts bridge ports in promiscuous mode when the bridge has VLAN filtering disabled, the CPU port bit is never set in PGID_UC/PGID_MC/PGID_MCIPV4/PGID_MCIPV6 for a bridged port, and no error is returned to userspace. lan9645x_port_bridge_join() also revokes an already granted request through __lan9645x_port_set_host_flood(), and lan9645x_port_bridge_leave() restores it. The sibling driver for the same hardware family, felix_port_set_host_flood() in drivers/net/dsa/ocelot/felix.c, honours the request unconditionally.

I can mention this in the commit message. I would add that even when VLAN filtering is enabled, the conditions for when a bridged port is not put in promiscuous mode are narrow. In most regular situations a bridged port is put into promiscuous mode, even with VLAN filtering.

Quoted 55 lines

The second omission is .set_ageing_time, ds->ageing_time_max and the "msecs == 0 disables automatic ageing" semantic, which are described only in the comment above and in the changelog below the --- marker.

[ ... ]

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3 -0
+static void lan9645x_port_bridge_stp_state_set(struct dsa_switch *ds, int port,
+					       u8 state)
+{

[ ... ]

Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7 -0
+	lan_rmw(ANA_PORT_CFG_LEARN_ENA_SET(learn_ena),
+		ANA_PORT_CFG_LEARN_ENA, lan9645x,
+		ANA_PORT_CFG(p->chip_port));
+
+	lan9645x_update_fwd_mask(lan9645x);
+	mutex_unlock(&lan9645x->fwd_domain_lock);
+}

[ ... ]

Quoted 7 lines

static const struct dsa_switch_ops lan9645x_switch_ops = {

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
 	.get_tag_protocol		= lan9645x_get_tag_protocol,
@@ -295,6 +594,15 @@ static const struct dsa_switch_ops lan9645x_switch_ops = {
 	/* MTU  */
 	.port_change_mtu		= lan9645x_change_mtu,
 	.port_max_mtu			= lan9645x_get_max_mtu,

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static const struct dsa_switch_ops lan9645x_switch_ops = { · line 606

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +9 -0
+
+	/* Bridge integration */
+	.set_ageing_time		= lan9645x_set_ageing_time,
+	.port_pre_bridge_flags		= lan9645x_port_pre_bridge_flags,
+	.port_bridge_flags		= lan9645x_port_bridge_flags,
+	.port_bridge_join		= lan9645x_port_bridge_join,
+	.port_bridge_leave		= lan9645x_port_bridge_leave,
+	.port_stp_state_set		= lan9645x_port_bridge_stp_state_set,
+	.port_set_host_flood		= lan9645x_port_set_host_flood,
 };

Discovered by: fable-5, opus-5 · Missed by: sashiko-gemini
STP state and learning offload are registered here without .port_fast_age, so when net/dsa/port.c dsa_port_set_state() calls dsa_port_fast_age() there is no hardware MAC table flush. Dynamic entries learned on a port would stay in the ANA MAC table after the port leaves BR_STATE_FORWARDING or BR_STATE_LEARNING, after BR_LEARNING is cleared, and after bridge leave.

This is resolved later in the same series: the follow-up patch "net: dsa:
lan9645x: add mac table integration" adds lan9645x_port_fast_age() calling lan9645x_mact_flush() and registers ".port_fast_age = lan9645x_port_fast_age", with the per-port flush implemented in lan9645x_mac.c using ANA_ANAGEFIL_PID_EN/PID_VAL plus two CMD_AGE scans. So the gap exists only at this intermediate patch; mentioning it here is just for completeness.

Quoted 2 lines

Would it be worth reordering so the flush hook lands together with the STP offload, or is the intermediate state acceptable?

I will reorganize the commit order so bridge support lands after vlan, mactable and mdb.

#20 lore raw

PATCH v11 6/9 net: dsa: lan9645x: add vlan support

In reply to Jens Emil Schulz Østergaard

Add VLAN support for VLAN-aware and VLAN-unaware bridges.

VID 4095 (HOST_PVID) is reserved and used internally as the port VLAN for standalone (non-bridged) ports so their FDB domain is isolated from bridged traffic.

VID 0 is used internally as the port VLAN for VLAN-unaware bridge ports (UNAWARE_PVID).

---
Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module, and reword the portmask comment.

Changes in v5:
- switch -EBUSY to -EINVAL for vlan add/del in the reserved range.
- remove reserved HSR vlan
- update commit message

Changes in v4:
- fix clear HOST_PVID vlan membership when a port joins a bridge
- explicit default value write to tag type register for untagged frames
- use lan_rmw for ANA_DROP_CFG
- add comment for error path in lan9645x_vlan_hw_wr
- use dsa_switch_for_each_user_port to iterate ports

Changes in v3:
- use SET register macros in vlan_hw_wr
- add vlan id bounds check to vlan_del
- return vlan_hw_wr timeout err on init
- move cpu vlan action after bounds check

Changes in v2:
- redesign based on selftests which rely on changing vlan_default_pvid. Our HW limitations were too forward. Following Vladimirs changes to ocelot VLAN implementation, we now dynamically change egress tag configuration, allowing more states.
- selftests are passing, except an expected failure w.r.t ctag/stag conformance, which is a hw limitation.

---
 drivers/net/dsa/microchip/lan9645x/Makefile        |   1 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c |  50 +++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |  29 ++
 drivers/net/dsa/microchip/lan9645x/lan9645x_port.c |   3 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 403 +++++++++++++++++++++
 5 files changed, 486 insertions(+)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
index 7cc0ae0ada40..e049114b3563 100644
@@ -6,3 +6,4 @@ mchp-lan9645x-objs := \
 	lan9645x_npi.o \
 	lan9645x_phylink.o \
 	lan9645x_port.o \
+	lan9645x_vlan.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +50 -0

79 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +29 -0
index a0cd1707e114..248c4ab59f1a 100644
@@ -7,6 +7,7 @@
 
 #include <linux/dsa/lan9645x.h>
 #include <linux/if_bridge.h>
+#include <linux/if_vlan.h>
 #include <linux/regmap.h>
 #include <net/dsa.h>
 
@@ -156,6 +157,17 @@ enum lan9645x_vlan_port_tag {
 	LAN9645X_TAG_ALL = 3,
 };
 
+struct lan9645x_vlan {
+	u32 portmask: 10, /* ports 0-8 + CPU port module */
+	    untagged: 9, /* ports 0-8 */
+	    src_chk: 1,
+	    mir: 1,
+	    lrn_dis: 1,
+	    prv_vlan: 1,
+	    fld_dis: 1,
+	    s_fwd_ena: 1;
+};
+
 struct lan9645x {
 	struct device *dev;
 	struct dsa_switch *ds;
@@ -180,6 +192,9 @@ struct lan9645x {
 	u16 bridge_fwd_mask; /* Mask for forwarding bridged ports */
 	struct mutex fwd_domain_lock; /* lock forwarding configuration */
 
+	/* VLAN entries */
+	struct lan9645x_vlan vlans[VLAN_N_VID];
+
 	int num_port_dis;
 };
 
@@ -190,6 +205,9 @@ struct lan9645x_port {
 	u8 stp_state;
 	bool learn_ena;
 
+	bool vlan_aware;
+	u16 pvid;
+
 	bool rx_internal_delay;
 	bool tx_internal_delay;
 
@@ -356,4 +374,15 @@ void lan9645x_phylink_get_caps(struct lan9645x *lan9645x, int port,
 			       struct phylink_config *c);
 void lan9645x_phylink_port_down(struct lan9645x *lan9645x, int port);
 
+/* VLAN lan9645x_vlan.c */
+int lan9645x_vlan_init(struct lan9645x *lan9645x);
+u16 lan9645x_vlan_unaware_pvid(bool is_bridged);
+void lan9645x_vlan_port_apply(struct lan9645x_port *p);
+int lan9645x_vlan_port_add_vlan(struct lan9645x_port *p, u16 vid, bool pvid,
+				bool untagged,
+				struct netlink_ext_ack *extack);
+int lan9645x_vlan_port_del_vlan(struct lan9645x_port *p, u16 vid);
+void lan9645x_vlan_set_hostmode(struct lan9645x_port *p);
+void lan9645x_vlan_clear_hostmode(struct lan9645x_port *p);
+
 #endif /* __LAN9645X_MAIN_H__ */
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +3 -0
index 0642b59419c2..0548904dc4bd 100644
@@ -210,5 +210,8 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)
 		ANA_PORT_CFG_PORTID_VAL,
 		lan9645x, ANA_PORT_CFG(p->chip_port));
 
+	if (p->chip_port != lan9645x->npi)
+		lan9645x_vlan_set_hostmode(p);
+
 	return 0;
 }
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +403 -0

403 lines not on this page · raw message

Signature · 1 line
2.52.0
#21 lore raw

Re: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Code Fix needed in lan9645x_port_vlan_filtering to explicitly ignore the NPI port, preventing REW_TAG_CFG corruption.

Pre-existing issues:
- [High] The MAC table dump function lan9645x_mact_dsa_dump acquires a sleepable mutex and performs sleep-polling within an atomic RCU read-side critical section. --

--- Patch [6]: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support --- commit 7eb00c9a8e8dbdc6e13b0734d6fc7a8d54af0360
Author: Jens Emil Schulz Østergaard <[email protected]>
Subject: net: dsa: lan9645x: add vlan support

This commit adds VLAN support for VLAN-aware and VLAN-unaware bridges. VID 4095 is reserved for standalone ports and VID 0 is used for VLAN-unaware bridge ports to isolate their FDB domains.

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -576,11 +580,52 @@ static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port, · line 598

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+static int lan9645x_port_vlan_filtering(struct dsa_switch *ds, int port,
+					bool enabled,
+					struct netlink_ext_ack *extack)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+
+	p = lan9645x_to_port(lan9645x, port);
+	p->vlan_aware = enabled;
+	lan9645x_vlan_port_apply(p);

[Severity: High]
Does this code inadvertently apply standard VLAN configurations to the NPI (CPU) port?

When the bridge's VLAN filtering state changes, the DSA core propagates the change to all ports in the bridge tree, including the CPU port. Here, lan9645x_port_vlan_filtering() unconditionally executes lan9645x_vlan_port_apply() which proceeds to modify the egress tagging.

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0 -0

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +4 -0
+static void
+lan9645x_vlan_port_apply_egress(struct lan9645x_port *p,
+				struct lan9645x_vlan_port_info *info)
+{

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 170

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +5 -0
+	lan_rmw(REW_TAG_CFG_TAG_TPID_CFG_SET(3) |
+		REW_TAG_CFG_TAG_CFG_SET(tag_cfg),
+		REW_TAG_CFG_TAG_TPID_CFG |
+		REW_TAG_CFG_TAG_CFG,
+		lan9645x, REW_TAG_CFG(p->chip_port));

[Severity: High]
Is it safe to rewrite the egress tag configuration for the NPI port here?

Writing the dynamically evaluated egress tag configuration to the REW_TAG_CFG register erases the mandatory LAN9645X_TAG_DISABLED configuration that is normally set during CPU port initialization.

If IFH extraction and packet rewriting conflict, a pushed VLAN tag could overwrite the end of the extraction header with the top 4 bytes of the DMAC, breaking CPU traffic. Should lan9645x_port_vlan_filtering() explicitly ignore the NPI port?

[Severity: High]
This is a pre-existing issue, but does the MAC table dump function sleep while holding rcu_read_lock()?

A user-space request to dump the Forwarding Database (e.g., via bridge fdb show) invokes the netlink rtnl_fdb_dump() handler. This handler takes rcu_read_lock() and iterates over devices, calling ndo_fdb_dump(). DSA passes this down to the driver's lan9645x_mact_dsa_dump().

Inside the RCU critical section, the driver acquires mact_lock (a sleepable mutex) and uses lan9645x_mac_wait_for_completion() to poll the hardware, which uses a regmap poll with a non-zero sleep interval:

drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c:lan9645x_mact_dsa_dump() {
	...
	mutex_lock(&lan9645x->mact_lock);
	...
	err = lan9645x_mac_wait_for_completion(lan9645x, &maca);
	...
}

Could this trigger a "scheduling while atomic" kernel panic or cause a deadlock?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=6
#22 lore raw

Re: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support

Quoted 41 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [High] Code Fix needed in lan9645x_port_vlan_filtering to explicitly ignore the NPI port, preventing REW_TAG_CFG corruption.

Pre-existing issues:
- [High] The MAC table dump function lan9645x_mact_dsa_dump acquires a sleepable mutex and performs sleep-polling within an atomic RCU read-side critical section. --

--- Patch [6]: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support --- commit 7eb00c9a8e8dbdc6e13b0734d6fc7a8d54af0360
Author: Jens Emil Schulz Østergaard <[email protected]>
Subject: net: dsa: lan9645x: add vlan support

This commit adds VLAN support for VLAN-aware and VLAN-unaware bridges. VID 4095 is reserved for standalone ports and VID 0 is used for VLAN-unaware bridge ports to isolate their FDB domains.

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -576,11 +580,52 @@ static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port, · line 598

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+static int lan9645x_port_vlan_filtering(struct dsa_switch *ds, int port,
+                                     bool enabled,
+                                     struct netlink_ext_ack *extack)
+{
+     struct lan9645x *lan9645x = ds->priv;
+     struct lan9645x_port *p;
+
+     p = lan9645x_to_port(lan9645x, port);
+     p->vlan_aware = enabled;
+     lan9645x_vlan_port_apply(p);

[Severity: High]
Does this code inadvertently apply standard VLAN configurations to the NPI (CPU) port?

Quoted 2 lines

When the bridge's VLAN filtering state changes, the DSA core propagates the change to all ports in the bridge tree, including the CPU port. Here,

It does not. .port_vlan_filtering is only ever called for a user port.

There is a single invocation in the core, in dsa_port_vlan_filtering():

      err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering,
                                         extack);

and its callers all pass the port whose bridge membership or switchdev attribute changed: the SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING handler, dsa_port_switchdev_sync_attrs() on bridge join, and dsa_port_reset_vlan_filtering() on bridge leave. Never a CPU or DSA port.

In the vlan_filtering_is_global case the core iterates dsa_switch_for_each_user_port() and calls dsa_user_manage_vlan_filtering(), which takes a struct net_device *user and only flips NETIF_F_HW_VLAN_CTAG_FILTER and walks vlan_for_each(). It does not re-enter the driver op.

Quoted 12 lines

lan9645x_port_vlan_filtering() unconditionally executes lan9645x_vlan_port_apply() which proceeds to modify the egress tagging.

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0 -0

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +4 -0
+static void
+lan9645x_vlan_port_apply_egress(struct lan9645x_port *p,
+                             struct lan9645x_vlan_port_info *info)
+{

[ ... ]

Quoted 8 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 170

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +5 -0
+     lan_rmw(REW_TAG_CFG_TAG_TPID_CFG_SET(3) |
+             REW_TAG_CFG_TAG_CFG_SET(tag_cfg),
+             REW_TAG_CFG_TAG_TPID_CFG |
+             REW_TAG_CFG_TAG_CFG,
+             lan9645x, REW_TAG_CFG(p->chip_port));

[Severity: High]
Is it safe to rewrite the egress tag configuration for the NPI port here?

The NPI port never reaches this function. Every path to lan9645x_vlan_port_apply_egress() either diverts the NPI port first or is a user-port-only DSA op:

- lan9645x_vlan_port_add_vlan() and _del_vlan() check p->chip_port == lan9645x->npi and divert to lan9645x_vlan_cpu_add() / lan9645x_vlan_cpu_del(). Those deliberately call only lan9645x_vlan_port_apply_ingress(), never the egress half, precisely because the CPU port needs its VLAN classification updated for host VLANs while REW must be left as lan9645x_npi_port_init() configured it. That is why the apply step is split in two.

- lan9645x_vlan_set_hostmode() is called from lan9645x_port_bridge_leave() and from lan9645x_port_setup(). The latter is called for the CPU port but it is guarded by p->chip_port != lan9645x->npi

- lan9645x_vlan_clear_hostmode() is called only from lan9645x_port_bridge_join(), and the NPI port is never bridged.

- lan9645x_port_vlan_filtering() is only ever invoked by the core for a user port, as mentioned above.

Quoted 31 lines

Writing the dynamically evaluated egress tag configuration to the REW_TAG_CFG register erases the mandatory LAN9645X_TAG_DISABLED configuration that is normally set during CPU port initialization.

If IFH extraction and packet rewriting conflict, a pushed VLAN tag could overwrite the end of the extraction header with the top 4 bytes of the DMAC, breaking CPU traffic. Should lan9645x_port_vlan_filtering() explicitly ignore the NPI port?

[Severity: High]
This is a pre-existing issue, but does the MAC table dump function sleep while holding rcu_read_lock()?

A user-space request to dump the Forwarding Database (e.g., via bridge fdb show) invokes the netlink rtnl_fdb_dump() handler. This handler takes rcu_read_lock() and iterates over devices, calling ndo_fdb_dump(). DSA passes this down to the driver's lan9645x_mact_dsa_dump().

Inside the RCU critical section, the driver acquires mact_lock (a sleepable mutex) and uses lan9645x_mac_wait_for_completion() to poll the hardware, which uses a regmap poll with a non-zero sleep interval:

drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c:lan9645x_mact_dsa_dump() {
        ...
        mutex_lock(&lan9645x->mact_lock);
        ...
        err = lan9645x_mac_wait_for_completion(lan9645x, &maca);
        ...
}
Quoted 3 lines

Could this trigger a "scheduling while atomic" kernel panic or cause a deadlock?

This is a false positive. No RCU is held here. The RCU section inside br_fdb_dump at net/bridge/br_fdb.c:1062 takes rcu_read_lock() for its own br->fdb_list walk and drops it before returning.

So RCU is not held when the ports ndo_fdb_dump is called, and dsa_user_fdb_dump is never nested inside the bridges rcu critical section.

Quoted 2 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=6

maintainer
#23 lore raw

Re: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support

In reply to Jens Emil Schulz Østergaard

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
--- Patch [6]: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support --- commit 48ea20348797be1134c296e1f56d305fbc50bbe3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add vlan support

This adds a new lan9645x_vlan.c implementing port_vlan_filtering, port_vlan_add and port_vlan_del, backed by a software shadow of the hardware VLAN table in lan9645x->vlans[]. VID 4095 is reserved as the port VLAN of standalone ports and VID 0 is used for VLAN-unaware bridge ports.

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
index c145d28ffbb99..3281726284dc2 100644

[ ... ]

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1 -0
@@ -521,6 +524,7 @@ static int lan9645x_port_bridge_join(struct dsa_switch *ds, int port,
 
 	lan9645x->bridge_mask |= BIT(p->chip_port);
 	__lan9645x_port_set_host_flood(lan9645x);
+	lan9645x_vlan_clear_hostmode(p);
 
 	mutex_unlock(&lan9645x->fwd_domain_lock);
 

[ ... ]

Quoted 16 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +15 -0
@@ -576,11 +580,52 @@ static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,
+static int lan9645x_port_vlan_add(struct dsa_switch *ds, int port,
+				  const struct switchdev_obj_port_vlan *vlan,
+				  struct netlink_ext_ack *extack)
+{
+	struct lan9645x *lan9645x = ds->priv;
+	struct lan9645x_port *p;
+	bool pvid, untagged;
+
+	p = lan9645x_to_port(lan9645x, port);
+	pvid = !!(vlan->flags & BRIDGE_VLAN_INFO_PVID);
+	untagged = !!(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED);
+
+	return lan9645x_vlan_port_add_vlan(p, vlan->vid, pvid, untagged,
+					   extack);
+}

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +0 -0
index a0cd1707e1149..248c4ab59f1a8 100644

[ ... ]

Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +11 -0
@@ -156,6 +157,17 @@ enum lan9645x_vlan_port_tag {
 	LAN9645X_TAG_ALL = 3,
 };
 
+struct lan9645x_vlan {
+	u32 portmask: 10, /* ports 0-8 + CPU port module */
+	    untagged: 9, /* ports 0-8 */
+	    src_chk: 1,
+	    mir: 1,
+	    lrn_dis: 1,
+	    prv_vlan: 1,
+	    fld_dis: 1,
+	    s_fwd_ena: 1;
+};
+

[ ... ]

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +3 -0
@@ -180,6 +192,9 @@ struct lan9645x {
 	u16 bridge_fwd_mask; /* Mask for forwarding bridged ports */
 	struct mutex fwd_domain_lock; /* lock forwarding configuration */
 
+	/* VLAN entries */
+	struct lan9645x_vlan vlans[VLAN_N_VID];
+
 	int num_port_dis;
 };

[ ... ]

Quoted 19 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +3 -0
index 0642b59419c25..0548904dc4bd2 100644
@@ -210,5 +210,8 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)
 		ANA_PORT_CFG_PORTID_VAL,
 		lan9645x, ANA_PORT_CFG(p->chip_port));
 
+	if (p->chip_port != lan9645x->npi)
+		lan9645x_vlan_set_hostmode(p);
+
 	return 0;
 }
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0 -0
new file mode 100644
index 0000000000000..e2116132b4d48

[ ... ]

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +11 -0
+static int lan9645x_vlan_hw_wr(struct lan9645x *lan9645x, u16 vid)
+{
+	struct lan9645x_vlan *v = &lan9645x->vlans[vid];
+	bool cpu_dis = !(v->portmask & BIT(lan9645x->num_phys_ports));
+	u32 val;
+	int err;
+
+	val = ANA_VLANTIDX_VLAN_PGID_CPU_DIS_SET(cpu_dis) |
+	      ANA_VLANTIDX_V_INDEX_SET(vid) |
+	      ANA_VLANTIDX_VLAN_SEC_FWD_ENA_SET(v->s_fwd_ena) |
+	      ANA_VLANTIDX_VLAN_FLOOD_DIS_SET(v->fld_dis) |

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 76

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +10 -0
+	      ANA_VLANTIDX_VLAN_PRIV_VLAN_SET(v->prv_vlan) |
+	      ANA_VLANTIDX_VLAN_LEARN_DISABLED_SET(v->lrn_dis) |
+	      ANA_VLANTIDX_VLAN_MIRROR_SET(v->mir) |
+	      ANA_VLANTIDX_VLAN_SRC_CHK_SET(v->src_chk);
+
+	lan_wr(val, lan9645x, ANA_VLANTIDX);
+	lan_wr(ANA_VLAN_PORT_MASK_VLAN_PORT_MASK_SET(v->portmask),
+	       lan9645x, ANA_VLAN_PORT_MASK);
+	lan_wr(ANA_VLANACCESS_VLAN_TBL_CMD_SET(VLANACCESS_CMD_WRITE),
+	       lan9645x, ANA_VLANACCESS);

[Severity: High]
[Finding: main-5-5]
[Sources: opus-5]
Should this three-register indirect transaction be serialized by a lock?

The MAC table engine in this driver is protected by mact_lock:

struct mutex mact_lock; /* serialize mac table register access */

but the VLAN table access engine has no equivalent, and there is no lockdep_assert_held() here.

lan9645x_vlan_set_hostmode() is now called from .port_setup:

lan9645x_port_setup()

    if (p->chip_port != lan9645x->npi)
        lan9645x_vlan_set_hostmode(p)
            lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID)

and .port_setup runs from the DSA probe path without rtnl_lock and without fwd_domain_lock:

net/dsa/devlink.c:dsa_port_devlink_setup() {
	if (ds->ops->port_setup) {
		err = ds->ops->port_setup(ds, dp->index);
	...
}

dsa_port_devlink_setup() runs at the start of dsa_port_setup(), before dsa_user_create() registers this port's netdev, while the netdevs of the ports already processed are live. So while swp1..swpN are still going through lan9645x_port_setup(), userspace can enslave swp0:

CPU0 (probe, no locks held) CPU1 (rtnl, bridge join / vlan add)
lan9645x_vlan_set_hostmode() lan9645x_port_vlan_add()
lan9645x_vlan_hw_wr(.., 4095) lan9645x_vlan_port_add_vlan()

                                         lan9645x_vlan_hw_wr(.., 100)

Can the two transactions interleave like this?

CPU1: lan_wr(V_INDEX=100, ANA_VLANTIDX)
CPU0: lan_wr(V_INDEX=4095, ANA_VLANTIDX)
CPU0: lan_wr(mask(4095), ANA_VLAN_PORT_MASK)
CPU0: lan_wr(CMD_WRITE, ANA_VLANACCESS)
CPU1: lan_wr(mask(100), ANA_VLAN_PORT_MASK)
CPU1: lan_wr(CMD_WRITE, ANA_VLANACCESS)

That would commit mask(100) into the HOST_PVID (4095) entry and leave vid 100 without a member mask, i.e. either standalone ports lose their isolation domain or the new VLAN blackholes traffic.

There is also the shadow update itself. lan9645x_vlan_set_hostmode() and lan9645x_vlan_clear_hostmode() both do a non-atomic read-modify-write of the same u32 bitfield word:

	p->lan9645x->vlans[HOST_PVID].portmask |= BIT(p->chip_port);
	...
	p->lan9645x->vlans[HOST_PVID].portmask &= ~BIT(p->chip_port);

portmask:10 shares the word with untagged:9 and the flag bits, and lan9645x_port_bridge_join() calls lan9645x_vlan_clear_hostmode() under fwd_domain_lock while lan9645x_port_setup() calls lan9645x_vlan_set_hostmode() with no lock at all, so the lock sets do not intersect. Can one of these updates be lost?

Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +15 -0
+
+	/* The VLAN access engine completes in a fixed ~1us vs the polling
+	 * timeout of 100_000 us. A timeout here therefore likely means the
+	 * register bus itself is dead, not that the VLAN op failed. There is no
+	 * meaningful recovery at runtime, so this function logs via dev_err()
+	 * and runtime callers discard the return value. Only
+	 * lan9645x_vlan_init() treats this as fatal so that probe fails early
+	 * on a broken bus.
+	 */
+	err = lan9645x_vlan_wait_for_completion(lan9645x);
+	if (err)
+		dev_err(lan9645x->dev, "Vlan set mask failed\n");
+
+	return err;
+}

[ ... ]

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3 -0
+int lan9645x_vlan_port_add_vlan(struct lan9645x_port *p, u16 vid, bool pvid,
+				bool untagged, struct netlink_ext_ack *extack)
+{

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 293

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8 -0
+	lan9645x_vlan_port_get_info(lan9645x, p->chip_port, &info);
+
+	if (info.untagged > 1 && info.tagged) {
+		*v = old_vlan;
+		p->pvid = old_pvid;
+		NL_SET_ERR_MSG_MOD(extack, "Only support 1 untagged port VLAN");
+		return -EBUSY;
+	}

[Severity: Low]
[Finding: main-1-1]
[Sources: opus-5]
This isn't a bug, but could the commit message mention this restriction?

The commit message says only "Add VLAN support for VLAN-aware and VLAN-unaware bridges", while this rejects an otherwise legal bridge
configuration: a second

bridge vlan add dev swpN vid B untagged

fails with -EBUSY once the port already has one untagged VLAN plus at least one tagged VLAN.

The changelog also notes an expected selftest failure with respect to ctag/stag conformance, but that text is below the --- line and is dropped when the patch is applied, so nothing about either limitation survives in the tree.

Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +7 -0
+
+	lan9645x_vlan_hw_wr(lan9645x, vid);
+	lan9645x_vlan_port_apply_ingress(p);
+	lan9645x_vlan_port_apply_egress(p, &info);
+
+	return 0;
+}

[ ... ]

Quoted 14 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +14 -0
+void lan9645x_vlan_set_hostmode(struct lan9645x_port *p)
+{
+	p->vlan_aware = false;
+	p->lan9645x->vlans[HOST_PVID].portmask |= BIT(p->chip_port);
+	lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID);
+	lan9645x_vlan_port_apply(p);
+}
+
+void lan9645x_vlan_clear_hostmode(struct lan9645x_port *p)
+{
+	p->lan9645x->vlans[HOST_PVID].portmask &= ~BIT(p->chip_port);
+	lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID);
+	lan9645x_vlan_port_apply(p);
+}

[ ... ]

Signature · 1 line
This is an AI-generated review.
#24 lore raw

Re: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support

Quoted 195 lines · Paolo Abeni

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

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible. Full review at: https://netdev-ai.bots.linux.dev/sashiko/
---
--- Patch [6]: [PATCH net-next v11 6/9] net: dsa: lan9645x: add vlan support --- commit 48ea20348797be1134c296e1f56d305fbc50bbe3
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add vlan support

This adds a new lan9645x_vlan.c implementing port_vlan_filtering, port_vlan_add and port_vlan_del, backed by a software shadow of the hardware VLAN table in lan9645x->vlans[]. VID 4095 is reserved as the port VLAN of standalone ports and VID 0 is used for VLAN-unaware bridge ports.

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
index c145d28ffbb99..3281726284dc2 100644

[ ... ]

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1 -0
@@ -521,6 +524,7 @@ static int lan9645x_port_bridge_join(struct dsa_switch *ds, int port,
 
      lan9645x->bridge_mask |= BIT(p->chip_port);
      __lan9645x_port_set_host_flood(lan9645x);
+     lan9645x_vlan_clear_hostmode(p);
 
      mutex_unlock(&lan9645x->fwd_domain_lock);
 

[ ... ]

Quoted 16 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +15 -0
@@ -576,11 +580,52 @@ static void lan9645x_port_bridge_leave(struct dsa_switch *ds, int port,
+static int lan9645x_port_vlan_add(struct dsa_switch *ds, int port,
+                               const struct switchdev_obj_port_vlan *vlan,
+                               struct netlink_ext_ack *extack)
+{
+     struct lan9645x *lan9645x = ds->priv;
+     struct lan9645x_port *p;
+     bool pvid, untagged;
+
+     p = lan9645x_to_port(lan9645x, port);
+     pvid = !!(vlan->flags & BRIDGE_VLAN_INFO_PVID);
+     untagged = !!(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED);
+
+     return lan9645x_vlan_port_add_vlan(p, vlan->vid, pvid, untagged,
+                                        extack);
+}

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +0 -0
index a0cd1707e1149..248c4ab59f1a8 100644

[ ... ]

Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +11 -0
@@ -156,6 +157,17 @@ enum lan9645x_vlan_port_tag {
      LAN9645X_TAG_ALL = 3,
 };
 
+struct lan9645x_vlan {
+     u32 portmask: 10, /* ports 0-8 + CPU port module */
+         untagged: 9, /* ports 0-8 */
+         src_chk: 1,
+         mir: 1,
+         lrn_dis: 1,
+         prv_vlan: 1,
+         fld_dis: 1,
+         s_fwd_ena: 1;
+};
+

[ ... ]

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +3 -0
@@ -180,6 +192,9 @@ struct lan9645x {
      u16 bridge_fwd_mask; /* Mask for forwarding bridged ports */
      struct mutex fwd_domain_lock; /* lock forwarding configuration */
 
+     /* VLAN entries */
+     struct lan9645x_vlan vlans[VLAN_N_VID];
+
      int num_port_dis;
 };

[ ... ]

Quoted 19 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +3 -0
index 0642b59419c25..0548904dc4bd2 100644
@@ -210,5 +210,8 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)
              ANA_PORT_CFG_PORTID_VAL,
              lan9645x, ANA_PORT_CFG(p->chip_port));
 
+     if (p->chip_port != lan9645x->npi)
+             lan9645x_vlan_set_hostmode(p);
+
      return 0;
 }
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0 -0
new file mode 100644
index 0000000000000..e2116132b4d48

[ ... ]

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +11 -0
+static int lan9645x_vlan_hw_wr(struct lan9645x *lan9645x, u16 vid)
+{
+     struct lan9645x_vlan *v = &lan9645x->vlans[vid];
+     bool cpu_dis = !(v->portmask & BIT(lan9645x->num_phys_ports));
+     u32 val;
+     int err;
+
+     val = ANA_VLANTIDX_VLAN_PGID_CPU_DIS_SET(cpu_dis) |
+           ANA_VLANTIDX_V_INDEX_SET(vid) |
+           ANA_VLANTIDX_VLAN_SEC_FWD_ENA_SET(v->s_fwd_ena) |
+           ANA_VLANTIDX_VLAN_FLOOD_DIS_SET(v->fld_dis) |

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 76

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +10 -0
+           ANA_VLANTIDX_VLAN_PRIV_VLAN_SET(v->prv_vlan) |
+           ANA_VLANTIDX_VLAN_LEARN_DISABLED_SET(v->lrn_dis) |
+           ANA_VLANTIDX_VLAN_MIRROR_SET(v->mir) |
+           ANA_VLANTIDX_VLAN_SRC_CHK_SET(v->src_chk);
+
+     lan_wr(val, lan9645x, ANA_VLANTIDX);
+     lan_wr(ANA_VLAN_PORT_MASK_VLAN_PORT_MASK_SET(v->portmask),
+            lan9645x, ANA_VLAN_PORT_MASK);
+     lan_wr(ANA_VLANACCESS_VLAN_TBL_CMD_SET(VLANACCESS_CMD_WRITE),
+            lan9645x, ANA_VLANACCESS);

[Severity: High]
[Finding: main-5-5]
[Sources: opus-5]
Should this three-register indirect transaction be serialized by a lock?

The MAC table engine in this driver is protected by mact_lock:

struct mutex mact_lock; /* serialize mac table register access */

but the VLAN table access engine has no equivalent, and there is no lockdep_assert_held() here.

lan9645x_vlan_set_hostmode() is now called from .port_setup:

lan9645x_port_setup()

    if (p->chip_port != lan9645x->npi)
        lan9645x_vlan_set_hostmode(p)
            lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID)

and .port_setup runs from the DSA probe path without rtnl_lock and without fwd_domain_lock:

net/dsa/devlink.c:dsa_port_devlink_setup() {
        if (ds->ops->port_setup) {
                err = ds->ops->port_setup(ds, dp->index);
        ...
}

dsa_port_devlink_setup() runs at the start of dsa_port_setup(), before dsa_user_create() registers this port's netdev, while the netdevs of the ports already processed are live. So while swp1..swpN are still going through lan9645x_port_setup(), userspace can enslave swp0:

CPU0 (probe, no locks held) CPU1 (rtnl, bridge join / vlan add)
lan9645x_vlan_set_hostmode() lan9645x_port_vlan_add()
lan9645x_vlan_hw_wr(.., 4095) lan9645x_vlan_port_add_vlan()

                                         lan9645x_vlan_hw_wr(.., 100)

Can the two transactions interleave like this?

CPU1: lan_wr(V_INDEX=100, ANA_VLANTIDX)
CPU0: lan_wr(V_INDEX=4095, ANA_VLANTIDX)
CPU0: lan_wr(mask(4095), ANA_VLAN_PORT_MASK)
CPU0: lan_wr(CMD_WRITE, ANA_VLANACCESS)
CPU1: lan_wr(mask(100), ANA_VLAN_PORT_MASK)
CPU1: lan_wr(CMD_WRITE, ANA_VLANACCESS)

That would commit mask(100) into the HOST_PVID (4095) entry and leave vid 100 without a member mask, i.e. either standalone ports lose their isolation domain or the new VLAN blackholes traffic.

There is also the shadow update itself. lan9645x_vlan_set_hostmode() and lan9645x_vlan_clear_hostmode() both do a non-atomic read-modify-write of the same u32 bitfield word:

        p->lan9645x->vlans[HOST_PVID].portmask |= BIT(p->chip_port);
        ...
        p->lan9645x->vlans[HOST_PVID].portmask &= ~BIT(p->chip_port);
Quoted 6 lines

portmask:10 shares the word with untagged:9 and the flag bits, and lan9645x_port_bridge_join() calls lan9645x_vlan_clear_hostmode() under fwd_domain_lock while lan9645x_port_setup() calls lan9645x_vlan_set_hostmode() with no lock at all, so the lock sets do not intersect. Can one of these updates be lost?

Yes, this is right, I will move vlan modifications under the existing fwd_domain_lock.

Quoted 44 lines
Quoted 15 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +15 -0
+
+     /* The VLAN access engine completes in a fixed ~1us vs the polling
+      * timeout of 100_000 us. A timeout here therefore likely means the
+      * register bus itself is dead, not that the VLAN op failed. There is no
+      * meaningful recovery at runtime, so this function logs via dev_err()
+      * and runtime callers discard the return value. Only
+      * lan9645x_vlan_init() treats this as fatal so that probe fails early
+      * on a broken bus.
+      */
+     err = lan9645x_vlan_wait_for_completion(lan9645x);
+     if (err)
+             dev_err(lan9645x->dev, "Vlan set mask failed\n");
+
+     return err;
+}

[ ... ]

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3 -0
+int lan9645x_vlan_port_add_vlan(struct lan9645x_port *p, u16 vid, bool pvid,
+                             bool untagged, struct netlink_ext_ack *extack)
+{

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 293

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8 -0
+     lan9645x_vlan_port_get_info(lan9645x, p->chip_port, &info);
+
+     if (info.untagged > 1 && info.tagged) {
+             *v = old_vlan;
+             p->pvid = old_pvid;
+             NL_SET_ERR_MSG_MOD(extack, "Only support 1 untagged port VLAN");
+             return -EBUSY;
+     }

[Severity: Low]
[Finding: main-1-1]
[Sources: opus-5]
This isn't a bug, but could the commit message mention this restriction?

The commit message says only "Add VLAN support for VLAN-aware and VLAN-unaware bridges", while this rejects an otherwise legal bridge
configuration: a second

bridge vlan add dev swpN vid B untagged

Quoted 8 lines

fails with -EBUSY once the port already has one untagged VLAN plus at least one tagged VLAN.

The changelog also notes an expected selftest failure with respect to ctag/stag conformance, but that text is below the --- line and is dropped when the patch is applied, so nothing about either limitation survives in the tree.

I can mention these restrictions in the commit message, that is a good idea. Both are hardware limitations.

The stag/ctag limitation is that the switch considers both stagged and ctagged frames as tagged, and the conformance requires you accept 1 as tagged and the other as untagged.

I see ocelot has a workaround for this using the VCAP. We may be able to do the same once the required features land, but not in this series.

Quoted 20 lines
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +7 -0
+
+     lan9645x_vlan_hw_wr(lan9645x, vid);
+     lan9645x_vlan_port_apply_ingress(p);
+     lan9645x_vlan_port_apply_egress(p, &info);
+
+     return 0;
+}

[ ... ]

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +10 -0
+void lan9645x_vlan_set_hostmode(struct lan9645x_port *p)
+{
+     p->vlan_aware = false;
+     p->lan9645x->vlans[HOST_PVID].portmask |= BIT(p->chip_port);
+     lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID);
+     lan9645x_vlan_port_apply(p);
+}
+
+void lan9645x_vlan_clear_hostmode(struct lan9645x_port *p)
+{
Quoted 9 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 349

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +4 -0
+     p->lan9645x->vlans[HOST_PVID].portmask &= ~BIT(p->chip_port);
+     lan9645x_vlan_hw_wr(p->lan9645x, HOST_PVID);
+     lan9645x_vlan_port_apply(p);
+}

[ ... ]
--
This is an AI-generated review.

Thanks,
Emil

#25 lore raw

PATCH v11 7/9 net: dsa: lan9645x: add mac table integration

In reply to Jens Emil Schulz Østergaard

Add MAC table support, and dsa fdb callback integration. The mactable is keyed on (vid,mac) and each bucket has 4 slots. A mac table entry typically points to a PGID index, the first 9 of which represent a front port.

Mac table entries for L2 multicast will use a PGID containing a group port mask. For IP multicast entries in the mac table a trick us used, where the group port mask is packed into the MAC data, exploiting the fact that the top bits are fixed, and that the number of switch ports is small enough to fit in the redundant bits.

Therefore, we can avoid using sparse PGID resources for IP multicast entries in the mac table.

---
Changes in v8:
- Pass lan9645x into lan9645x_mac_ports_use_cpu() and reference the CPU port module as lan9645x->num_phys_ports instead of CPU_PORT.

Changes in v5:
- lan9645x_mac_init returns error on table init timeout
- add comment about skipping LOCKED entries on fdb dump

Changes in v4:
- remove mac_entries list and just do direct IO to mac table from fdb_add/fdb_del

Changes in v3:
- avoid mac add/del dealloc when mac table writes fail
- add mact_lock to change ageing time
- dealloc all mac_entries on deinit
- dsa_dump returns mac table timeout error

Changes in v2:
- use a single lock for hw and sw
- remove unused row struct field and define
- remove list element INIT_LIST_HEAD
- consistent use of err vs ret
- remove mutex_lock in init
- use empty initializer { 0 } -> {}
- do not move fwd_domain_lock init to this unit
- add newline to dev_* log statements

---
 drivers/net/dsa/microchip/lan9645x/Makefile        |   1 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c  | 293 +++++++++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c |  87 +++++-
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |  27 ++
 4 files changed, 407 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
index e049114b3563..70815edca5b9 100644
@@ -2,6 +2,7 @@
 obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o
 
 mchp-lan9645x-objs := \
+	lan9645x_mac.o \
 	lan9645x_main.o \
 	lan9645x_npi.o \
 	lan9645x_phylink.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +293 -0

293 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +86 -1

135 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +27 -0
index 248c4ab59f1a..318082d6df35 100644
@@ -168,6 +168,19 @@ struct lan9645x_vlan {
 	    s_fwd_ena: 1;
 };
 
+/* MAC table entry types.
+ * ENTRYTYPE_NORMAL is subject to aging.
+ * ENTRYTYPE_LOCKED is not subject to aging.
+ * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
+ * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
+ */
+enum macaccess_entry_type {
+	ENTRYTYPE_NORMAL = 0,
+	ENTRYTYPE_LOCKED,
+	ENTRYTYPE_MACV4,
+	ENTRYTYPE_MACV6,
+};
+
 struct lan9645x {
 	struct device *dev;
 	struct dsa_switch *ds;
@@ -191,6 +204,7 @@ struct lan9645x {
 	u16 bridge_mask; /* Mask for bridged ports */
 	u16 bridge_fwd_mask; /* Mask for forwarding bridged ports */
 	struct mutex fwd_domain_lock; /* lock forwarding configuration */
+	struct mutex mact_lock; /* serialize mac table register access */
 
 	/* VLAN entries */
 	struct lan9645x_vlan vlans[VLAN_N_VID];
@@ -385,4 +399,17 @@ int lan9645x_vlan_port_del_vlan(struct lan9645x_port *p, u16 vid);
 void lan9645x_vlan_set_hostmode(struct lan9645x_port *p);
 void lan9645x_vlan_clear_hostmode(struct lan9645x_port *p);
 
+/* MAC table: lan9645x_mac.c */
+int lan9645x_mact_flush(struct lan9645x *lan9645x, int port);
+int lan9645x_mact_learn(struct lan9645x *lan9645x, int port,
+			const unsigned char *addr, u16 vid,
+			enum macaccess_entry_type type);
+int lan9645x_mact_forget(struct lan9645x *lan9645x,
+			 const unsigned char mac[ETH_ALEN], unsigned int vid,
+			 enum macaccess_entry_type type);
+int lan9645x_mac_init(struct lan9645x *lan9645x);
+void lan9645x_mac_deinit(struct lan9645x *lan9645x);
+int lan9645x_mact_dsa_dump(struct lan9645x *lan9645x, int port,
+			   dsa_fdb_dump_cb_t *cb, void *data);
+
 #endif /* __LAN9645X_MAIN_H__ */
Signature · 1 line
2.52.0
#26 lore raw

Re: [PATCH net-next v11 7/9] net: dsa: lan9645x: add mac table integration

This is a reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=7

Quoted 6 lines

--- Patch [7]: [PATCH net-next v11 7/9] net: dsa: lan9645x: add mac table integration --- commit c7af50889a34728dc6c99946b25b62bfb26fc31e
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add mac table integration

Quoted 7 lines

This adds a new lan9645x_mac.c unit that drives the ANA MAC table through the ANA_MACACCESS/ANA_MACHDATA/ANA_MACLDATA registers, and wires it up to the DSA .port_fdb_add, .port_fdb_del, .port_fdb_dump and .port_fast_age callbacks. A new mact_lock mutex serializes all MAC table register access, including the aging period updates.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c

Quoted 69 lines
Quoted 5 lines

new file mode 100644
index 0000000000000..9d5282754b7a0

drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +0 -0
@@ -0,0 +1,293 @@

[ ... ]

Quoted 32 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +32 -0
+int lan9645x_mact_flush(struct lan9645x *lan9645x, int port)
+{
+	int err;
+
+	mutex_lock(&lan9645x->mact_lock);
+	/* MAC table entries with dst index matching port are aged on scan. */
+	lan_wr(ANA_ANAGEFIL_PID_EN_SET(1) |
+	       ANA_ANAGEFIL_PID_VAL_SET(port),
+	       lan9645x, ANA_ANAGEFIL);
+
+	/* Flushing requires two scans. First sets AGE_FLAG=1, second removes
+	 * entries with AGE_FLAG=1.
+	 */
+	lan_wr(ANA_MACACCESS_MAC_TABLE_CMD_SET(CMD_AGE),
+	       lan9645x,
+	       ANA_MACACCESS);
+
+	err = lan9645x_mac_wait_for_completion(lan9645x, NULL);
+	if (err)
+		goto mact_unlock;
+
+	lan_wr(ANA_MACACCESS_MAC_TABLE_CMD_SET(CMD_AGE),
+	       lan9645x,
+	       ANA_MACACCESS);
+
+	err = lan9645x_mac_wait_for_completion(lan9645x, NULL);
+
+mact_unlock:
+	lan_wr(0, lan9645x, ANA_ANAGEFIL);
+	mutex_unlock(&lan9645x->mact_lock);
+	return err;
+}

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c line 270

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +9 -0
+		/* Only dynamic entries are surfaced through the user port dump.
+		 * ENTRYTYPE_LOCKED entries are already reported by the bridge
+		 * master's ndo_fdb_dump as NTF_MASTER, so we avoid duplicating
+		 * them as NTF_SELF.
+		 * Entries toward the host (NTF_SELF) have DEST_IDX == the CPU
+		 * port module and are filtered out by the DEST_IDX check.
+		 */
+		if (ANA_MACACCESS_DEST_IDX_GET(maca) == port &&
+		    type == ENTRYTYPE_NORMAL) {

Discovered by: opus-5 · Missed by: sashiko-gemini
Is the comment in lan9645x_mact_dsa_dump() accurate about what DEST_IDX holds for host entries?

lan9645x_fdb_add() programs the destination as PGID_CPU:

	dest = dsa_port_is_cpu(dp) ? PGID_CPU : port;

	return lan9645x_mact_learn(lan9645x, dest, addr, vid, ENTRYTYPE_LOCKED);

and lan9645x_main.h defines PGID_CPU as (PGID_AGGR - 6), i.e. 58. The CPU port module itself is denoted by lan9645x->num_phys_ports elsewhere in the driver, for instance ANA_VLAN_CFG(num_phys_ports) in lan9645x_vlan_init() and BIT(num_phys_ports) in the PGID_BC/PGID_CPU masks written by lan9645x_port_cpu_init():

Quoted 8 lines
	lan_wr(BIT(lan9645x->num_phys_ports), lan9645x, ANA_PGID(PGID_CPU));

So the value stored in DEST_IDX for host entries is the reserved PGID index 58, not the CPU port module index. Nothing misbehaves today, since both 58 and num_phys_ports fail the comparison against a user port index, but would it be clearer to say the entries carry DEST_IDX == PGID_CPU? A later change that adds an explicit host-entry test against num_phys_ports based on this comment would not match any entry.

Yes, I will update this comment.

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_main.c

Quoted 31 lines
Quoted 3 lines

index 3281726284dc2..af158d4461aee 100644

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port, · line 642

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4 -0
@@ -626,6 +636,75 @@ static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port,
 	return lan9645x_vlan_port_del_vlan(p, vlan->vid);
 }
 
+static void lan9645x_port_fast_age(struct dsa_switch *ds, int port)
+{
+	lan9645x_mact_flush(ds->priv, port);
+}

Discovered by: opus-5 · Missed by: sashiko-gemini Should lan9645x_port_fast_age() log the dropped error here?

lan9645x_mact_flush() returns the result of both lan9645x_mac_wait_for_completion() calls, which yield -ETIMEDOUT when ANA_MACACCESS.MAC_TABLE_CMD does not return to CMD_IDLE within the poll timeout. Since the DSA .port_fast_age op returns void, this callback is the only place the failure can be observed, and the value is discarded.

On a failed flush the ANA_ANAGEFIL filter is cleared and CMD_AGE is not retried, so the port's dynamic entries stay in the MAC table after an STP topology change or bridge leave, with no kernel message. If aging was disabled with a zero ageing time in lan9645x_set_ageing_time() (ANA_AUTOAGE_AGE_PERIOD == 0), the stale entries are not aged out later either.

Quoted 8 lines

felix_port_fast_age() handles the same situation for the related IP by reporting it:

	err = ocelot_mact_flush(ocelot, port);
	if (err)
		dev_err(ds->dev, "Flushing MAC table on port %d returned %pe\n",
			port, ERR_PTR(err));

Sure, I will add an error log here.

Quoted 8 lines
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6 -0
+
+static int lan9645x_fdb_dump(struct dsa_switch *ds, int port,
+			     dsa_fdb_dump_cb_t *cb, void *data)
+{
+	return lan9645x_mact_dsa_dump(ds->priv, port, cb, data);
+}

[ ... ]

#27 lore raw

PATCH v11 8/9 net: dsa: lan9645x: add mdb management

In reply to Jens Emil Schulz Østergaard

Add support for dsa mdb callbacks. L2 multicast and IP multicast is handled differently. IP multicast stores the port group mask inline in the mac table. L2 multicast points to a PGID index, which encodes the port group mask.

---
Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module, and reword the related comments.

Changes in v7:
- refactor IGMP/MLD/IPMC_CTRL to use new LAN9645X_CPUQ_DEF, LAN9645X_CPUQ_TRAP and LAN9645X_CPUQ_COPY queues
- add __aligned(2) to mac variable in lan9645x_mdb_update_dest

Changes in v5:
- skip igmp/mld redir for npi port

Changes in v4:
- clean up fresh mdb when hw mac table write fails.
- avoid void return in lan9645x_offload_fwd_mark

Changes in v3:
- avoid mdb add/del dealloc when mac table writes fail
- dealloc mdb entries on deinit

Changes in v2:
- New file: selftests required implementation of the mdb callbacks.

---
 drivers/net/dsa/microchip/lan9645x/Makefile        |   1 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c  |  14 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c |  62 ++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |  21 ++
 drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c  | 398 +++++++++++++++++++++
 drivers/net/dsa/microchip/lan9645x/lan9645x_port.c |  11 +-
 6 files changed, 506 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
index 70815edca5b9..2413d11fe849 100644
@@ -4,6 +4,7 @@ obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o
 mchp-lan9645x-objs := \
 	lan9645x_mac.o \
 	lan9645x_main.o \
+	lan9645x_mdb.o \
 	lan9645x_npi.o \
 	lan9645x_phylink.o \
 	lan9645x_port.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c +14 -0
index 9d5282754b7a..aefb3c58370a 100644
@@ -143,6 +143,20 @@ int lan9645x_mact_learn(struct lan9645x *lan9645x, int port,
 	return err;
 }
 
+int lan9645x_mact_learn_cpu_copy(struct lan9645x *lan9645x, int port,
+				 const unsigned char *addr, u16 vid,
+				 enum macaccess_entry_type type, bool cpu_copy)
+{
+	int err;
+
+	mutex_lock(&lan9645x->mact_lock);
+	err = __lan9645x_mact_learn_cpu_copy(lan9645x, port, addr, vid, type,
+					     cpu_copy);
+	mutex_unlock(&lan9645x->mact_lock);
+
+	return err;
+}
+
 int lan9645x_mact_flush(struct lan9645x *lan9645x, int port)
 {
 	int err;
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +62 -0

92 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +21 -0
index 318082d6df35..0e523b975619 100644
@@ -209,6 +209,14 @@ struct lan9645x {
 	/* VLAN entries */
 	struct lan9645x_vlan vlans[VLAN_N_VID];
 
+	/* Multicast Forwarding Database */
+	struct list_head mdb_entries;
+	struct list_head pgid_entries;
+	/* lock for mdb_entries and pgid_entries. Must be taken before mact_lock
+	 * if both are taken.
+	 */
+	struct mutex mdb_lock;
+
 	int num_port_dis;
 };
 
@@ -411,5 +419,18 @@ int lan9645x_mac_init(struct lan9645x *lan9645x);
 void lan9645x_mac_deinit(struct lan9645x *lan9645x);
 int lan9645x_mact_dsa_dump(struct lan9645x *lan9645x, int port,
 			   dsa_fdb_dump_cb_t *cb, void *data);
+int lan9645x_mact_learn_cpu_copy(struct lan9645x *lan9645x, int port,
+				 const unsigned char *addr, u16 vid,
+				 enum macaccess_entry_type type, bool cpu_copy);
+
+/* Multicast Database lan9645x_mdb.c */
+int lan9645x_mdb_port_add(struct lan9645x *lan9645x, int port,
+			  const struct switchdev_obj_port_mdb *mdb,
+			  struct net_device *bridge);
+int lan9645x_mdb_port_del(struct lan9645x *lan9645x, int port,
+			  const struct switchdev_obj_port_mdb *mdb,
+			  struct net_device *bridge);
+void lan9645x_mdb_init(struct lan9645x *lan9645x);
+void lan9645x_mdb_deinit(struct lan9645x *lan9645x);
 
 #endif /* __LAN9645X_MAIN_H__ */
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +398 -0

398 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +10 -1
index 0548904dc4bd..407d7eb1d064 100644
@@ -210,8 +210,17 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)
 		ANA_PORT_CFG_PORTID_VAL,
 		lan9645x, ANA_PORT_CFG(p->chip_port));
 
-	if (p->chip_port != lan9645x->npi)
+	if (p->chip_port != lan9645x->npi) {
 		lan9645x_vlan_set_hostmode(p);
 
+		lan_rmw(ANA_CPU_FWD_CFG_IGMP_REDIR_ENA_SET(true) |
+			ANA_CPU_FWD_CFG_MLD_REDIR_ENA_SET(true) |
+			ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA_SET(true),
+			ANA_CPU_FWD_CFG_IGMP_REDIR_ENA |
+			ANA_CPU_FWD_CFG_MLD_REDIR_ENA |
+			ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA,
+			lan9645x, ANA_CPU_FWD_CFG(p->chip_port));
+	}
+
 	return 0;
 }
Signature · 1 line
2.52.0
#28 lore raw

Re: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Duplicate CPU packet delivery on IP multicast MDB matches - [Low] Inverted teardown sequence…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Duplicate CPU packet delivery on IP multicast MDB matches
- [Low] Inverted teardown sequence between MAC and MDB initialization
--

--- Patch [8]: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management --- commit c8677da78fd630673d16e31ac732c8854e853dbe
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add mdb management

Add support for dsa mdb callbacks. L2 multicast and IP multicast is handled differently. IP multicast stores the port group mask inline in the mac table. L2 multicast points to a PGID index, which encodes the port group mask.

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_teardown(struct dsa_switch *ds) · line 73

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1 -0
index af158d4461aee..fc604edb309b9 100644
@@ -70,6 +70,7 @@ static void lan9645x_teardown(struct dsa_switch *ds)
 	destroy_workqueue(lan9645x->owq);
 	lan9645x_npi_port_deinit(lan9645x, lan9645x->npi);
 	lan9645x_mac_deinit(lan9645x);
+	lan9645x_mdb_deinit(lan9645x);

[Severity: Low]
In lan9645x_setup(), lan9645x_mac_init() is called before lan9645x_mdb_init(). However, lan9645x_teardown() and the err_mac path destroy these in the forward order (lan9645x_mac_deinit() followed by lan9645x_mdb_deinit()).

Since lan9645x_mac_deinit() destroys mact_lock, could calling it before lan9645x_mdb_deinit() cause a use-after-destroy if MDB cleanup ever needs to take mact_lock?

[ ... ]

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0 -0
new file mode 100644
index 0000000000000..ea37bb660273c

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4 -0
+static int lan9645x_mdb_update_dest(struct lan9645x *lan9645x,
+				    struct lan9645x_mdb_entry *mdb_entry,
+				    enum macaccess_entry_type type,
+				    struct lan9645x_pgid_entry *new_pgid,

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 234

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10 -0
+				    u16 new_ports)
+{
+	unsigned char mac[ETH_ALEN] __aligned(2);
+	struct lan9645x_pgid_entry *old_pgid;
+	int err, pgid_index;
+	bool cpu_copy;
+
+	old_pgid = mdb_entry->pgid;
+	lan9645x_mdb_encode_mac(mac, mdb_entry->mac, new_ports, type);
+	cpu_copy = !!(new_ports & BIT(lan9645x->num_phys_ports));

[Severity: Medium]
For IP multicast entries, the port mask is stored inline in the high bytes of the MAC address via lan9645x_mdb_encode_mac().

Because new_ports includes the CPU port bit, the hardware will forward the packet to the CPU port according to the inline mask. The code also sets the MAC_CPU_COPY bit via cpu_copy.

If the hardware acts on both the inline port mask and the MAC_CPU_COPY bit, will this result in duplicate packets being delivered to the CPU?

Should the CPU port bit be stripped from the new_ports mask before encoding it into the MAC address, similarly to how it is stripped from L2 multicast PGID entries in lan9645x_mdb_pgid_entry_get()?

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10 -0
+	pgid_index = PGID_INDEX(new_pgid);
+
+	/* For IP multicast, the hardware lookup uses the DMAC
+	 * (01:00:5E:.. / 33:33:..) as the (mac, vid) key, not the encoded mac.
+	 * Therefore, this CMD_LEARN will atomically rewrite the existing
+	 * hardware entry. We intentionally do not do a forget before learn
+	 * sequence, as that would not be atomic, and leave a forwarding gap.
+	 */
+	err = lan9645x_mact_learn_cpu_copy(lan9645x, pgid_index, mac,
+					   mdb_entry->vid, type, cpu_copy);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=8
#29 lore raw

Re: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management

Quoted 33 lines · On Thu, 2026-08-06 at 14:38 +0000, [email protected] wrote:

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

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Duplicate CPU packet delivery on IP multicast MDB matches
- [Low] Inverted teardown sequence between MAC and MDB initialization
--

--- Patch [8]: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management --- commit c8677da78fd630673d16e31ac732c8854e853dbe
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add mdb management

Add support for dsa mdb callbacks. L2 multicast and IP multicast is handled differently. IP multicast stores the port group mask inline in the mac table. L2 multicast points to a PGID index, which encodes the port group mask.

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_teardown(struct dsa_switch *ds) · line 73

Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1 -0
index af158d4461aee..fc604edb309b9 100644
@@ -70,6 +70,7 @@ static void lan9645x_teardown(struct dsa_switch *ds)
      destroy_workqueue(lan9645x->owq);
      lan9645x_npi_port_deinit(lan9645x, lan9645x->npi);
      lan9645x_mac_deinit(lan9645x);
+     lan9645x_mdb_deinit(lan9645x);

[Severity: Low]
In lan9645x_setup(), lan9645x_mac_init() is called before lan9645x_mdb_init(). However, lan9645x_teardown() and the err_mac path destroy these in the forward order (lan9645x_mac_deinit() followed by lan9645x_mdb_deinit()).

Quoted 4 lines

Since lan9645x_mac_deinit() destroys mact_lock, could calling it before lan9645x_mdb_deinit() cause a use-after-destroy if MDB cleanup ever needs to take mact_lock?

I will change the order in the next version.

Quoted 31 lines

[ ... ]

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0 -0
new file mode 100644
index 0000000000000..ea37bb660273c

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4 -0
+static int lan9645x_mdb_update_dest(struct lan9645x *lan9645x,
+                                 struct lan9645x_mdb_entry *mdb_entry,
+                                 enum macaccess_entry_type type,
+                                 struct lan9645x_pgid_entry *new_pgid,

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 234

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10 -0
+                                 u16 new_ports)
+{
+     unsigned char mac[ETH_ALEN] __aligned(2);
+     struct lan9645x_pgid_entry *old_pgid;
+     int err, pgid_index;
+     bool cpu_copy;
+
+     old_pgid = mdb_entry->pgid;
+     lan9645x_mdb_encode_mac(mac, mdb_entry->mac, new_ports, type);
+     cpu_copy = !!(new_ports & BIT(lan9645x->num_phys_ports));

[Severity: Medium]
For IP multicast entries, the port mask is stored inline in the high bytes of the MAC address via lan9645x_mdb_encode_mac().

Because new_ports includes the CPU port bit, the hardware will forward the packet to the CPU port according to the inline mask. The code also sets the MAC_CPU_COPY bit via cpu_copy.

Quoted 6 lines

If the hardware acts on both the inline port mask and the MAC_CPU_COPY bit, will this result in duplicate packets being delivered to the CPU?

Should the CPU port bit be stripped from the new_ports mask before encoding it into the MAC address, similarly to how it is stripped from L2 multicast PGID entries in lan9645x_mdb_pgid_entry_get()?

No, it will not cause duplicate packets. The chip does not act on both, the inline mask in the mac table has no effect for the CPU port. The MAC_CPU_COPY flag in is how IP multicast entries each the CPU.

For L2MC where we must use the limited PGID resource, we strip the CPU port from the PGID mask and let the mac table entries use cpu_copy as necessary. This allows better sharing of PGID entries, because two L2 MDB groups differing only in the CPU port can reuse the same PGID.

Quoted 14 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 244

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10 -0
+     pgid_index = PGID_INDEX(new_pgid);
+
+     /* For IP multicast, the hardware lookup uses the DMAC
+      * (01:00:5E:.. / 33:33:..) as the (mac, vid) key, not the encoded mac.
+      * Therefore, this CMD_LEARN will atomically rewrite the existing
+      * hardware entry. We intentionally do not do a forget before learn
+      * sequence, as that would not be atomic, and leave a forwarding gap.
+      */
+     err = lan9645x_mact_learn_cpu_copy(lan9645x, pgid_index, mac,
+                                        mdb_entry->vid, type, cpu_copy);

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com?part=8

#30 lore raw

Re: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management

In reply to Jens Emil Schulz Østergaard

This is a reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=8

Quoted 4 lines

--- Patch [8]: [PATCH net-next v11 8/9] net: dsa: lan9645x: add mdb management --- commit f98510fb218c27ef1092f8176a5d379f8499735c
Author: Jens Emil Schulz Østergaard <[email protected]>

Quoted 8 lines

net: dsa: lan9645x: add mdb management

This adds the DSA port_mdb_add/port_mdb_del callbacks to the lan9645x driver, with a new lan9645x_mdb.c tracking software mdb entries and a pool of PGID indices. IP multicast entries encode the port mask into the high DMAC bytes, while L2 multicast entries point at an allocated PGID index.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c

Quoted 49 lines
Quoted 14 lines

new file mode 100644
index 0000000000000..ea37bb660273c

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +9 -0
@@ -0,0 +1,398 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2026 Microchip Technology Inc.
+ */
+
+#include "lan9645x_main.h"
+
+/* HW ignores dest_idx for IPv4/IPv6 types, so we use this dummy index */
+#define IP_ENTRY_PGID		0
+#define PGID_INDEX(pgid)	((pgid) ? (pgid)->index : IP_ENTRY_PGID)

[ ... ]

Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5 -0
+void lan9645x_mdb_init(struct lan9645x *lan9645x)
+{
+	INIT_LIST_HEAD(&lan9645x->mdb_entries);
+	INIT_LIST_HEAD(&lan9645x->pgid_entries);
+	mutex_init(&lan9645x->mdb_lock);

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 40

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10 -0
+
+	/* Use CPU queues to communicate frame classification to the CPU */
+	lan_rmw(ANA_CPUQ_CFG_CPUQ_IGMP_SET(LAN9645X_CPUQ_TRAP) |
+		ANA_CPUQ_CFG_CPUQ_MLD_SET(LAN9645X_CPUQ_TRAP) |
+		ANA_CPUQ_CFG_CPUQ_IPMC_CTRL_SET(LAN9645X_CPUQ_COPY),
+		ANA_CPUQ_CFG_CPUQ_IGMP |
+		ANA_CPUQ_CFG_CPUQ_MLD |
+		ANA_CPUQ_CFG_CPUQ_IPMC_CTRL,
+		lan9645x, ANA_CPUQ_CFG);
+}

Discovered by: opus-5 · Missed by: sashiko-gemini
Could the commit message mention the forwarding behaviour change that comes with this patch? The changelog only says:

Add support for dsa mdb callbacks. L2 multicast and IP multicast is handled differently.

but besides the callbacks, lan9645x_mdb_init() writes the global ANA_CPUQ_CFG register (IGMP and MLD to LAN9645X_CPUQ_TRAP, IPMC_CTRL to LAN9645X_CPUQ_COPY), and lan9645x_port_setup() unconditionally sets IGMP_REDIR_ENA / MLD_REDIR_ENA / IPMC_CTRL_COPY_ENA on every non-NPI port.

After this patch IGMP/MLD frames arriving on a user port are trapped to the CPU instead of being forwarded by hardware, and lan9645x_offload_fwd_mark() in net/dsa/tag_lan9645x.c clears skb->offload_fwd_mark for the trap queue:

Quoted 9 lines
    if (cpuq & BIT(LAN9645X_CPUQ_TRAP)) {
            skb->offload_fwd_mark = 0;
            return;
    }

so the software bridge takes over forwarding for those frames. This happens for every non-NPI port regardless of whether any mdb entry is ever offloaded.

I will update the commit message.

Quoted 4 lines

Also, is lan9645x_mdb_init() the right place for a write to a global classification register, given the name suggests only software list initialisation?

I will move the register write to lan9645x_setup().

Quoted 77 lines

[ ... ]

Quoted 22 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +22 -0
+static void lan9645x_mdb_encode_mac(unsigned char *dst, unsigned char *mac,
+				    u16 ports, enum macaccess_entry_type type)
+{
+	ether_addr_copy(dst, mac);
+
+	/* The HW encodes the portmask in the high bits of the mac for ip
+	 * multicast entries, to save on the limited PGID resources.
+	 *
+	 * IPv4 Multicast DMAC: 0x01005Exxxxxx
+	 * IPv6 Multicast DMAC: 0x3333xxxxxxxx
+	 *
+	 * which gives us 24 or 16 bits to encode the portmask.
+	 */
+	if (type == ENTRYTYPE_MACV4) {
+		dst[0] = 0;
+		dst[1] = ports >> 8;
+		dst[2] = ports & 0xff;
+	} else if (type == ENTRYTYPE_MACV6) {
+		dst[0] = ports >> 8;
+		dst[1] = ports & 0xff;
+	}
+}

[ ... ]

Quoted 23 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +23 -0
+static struct lan9645x_pgid_entry *
+lan9645x_mdb_pgid_entry_create(struct lan9645x *lan9645x, u16 ports)
+{
+	struct lan9645x_pgid_entry *pgid_entry = NULL;
+	int index;
+
+	for (index = PGID_GP_START; index < PGID_GP_END; index++) {
+		bool used = false;
+
+		list_for_each_entry(pgid_entry, &lan9645x->pgid_entries, list) {
+			if (pgid_entry->index == index) {
+				used = true;
+				break;
+			}
+		}
+
+		if (!used)
+			return lan9645x_pgid_entry_alloc(lan9645x, index,
+							 ports);
+	}
+
+	return ERR_PTR(-ENOSPC);
+}

[ ... ]

Quoted 24 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +24 -0
+static int lan9645x_mdb_update_dest(struct lan9645x *lan9645x,
+				    struct lan9645x_mdb_entry *mdb_entry,
+				    enum macaccess_entry_type type,
+				    struct lan9645x_pgid_entry *new_pgid,
+				    u16 new_ports)
+{
+	unsigned char mac[ETH_ALEN] __aligned(2);
+	struct lan9645x_pgid_entry *old_pgid;
+	int err, pgid_index;
+	bool cpu_copy;
+
+	old_pgid = mdb_entry->pgid;
+	lan9645x_mdb_encode_mac(mac, mdb_entry->mac, new_ports, type);
+	cpu_copy = !!(new_ports & BIT(lan9645x->num_phys_ports));
+	pgid_index = PGID_INDEX(new_pgid);
+
+	/* For IP multicast, the hardware lookup uses the DMAC
+	 * (01:00:5E:.. / 33:33:..) as the (mac, vid) key, not the encoded mac.
+	 * Therefore, this CMD_LEARN will atomically rewrite the existing
+	 * hardware entry. We intentionally do not do a forget before learn
+	 * sequence, as that would not be atomic, and leave a forwarding gap.
+	 */
+	err = lan9645x_mact_learn_cpu_copy(lan9645x, pgid_index, mac,
+					   mdb_entry->vid, type, cpu_copy);
Quoted 9 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 248

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4 -0
+	if (err) {
+		lan9645x_pgid_entry_put(lan9645x, new_pgid);
+		return err;
+	}

Discovered by: opus-5 · Missed by: sashiko-gemini
Is it safe to assume here that a failing lan9645x_mact_learn_cpu_copy() means nothing reached the hardware?

On a healthy bus I expect no errors at all. An error means the bus misbehaved, and we can not infer from it whether the command landed.

The mac commands CMD_LEARN/CMD_FORGET complete in a few microseconds, so the only way to get here with an entry actually written is for the register bus to fail between the command and the status read. I think that is close to impossible. But the forget costs nothing here: it is a noop if the entry was never written, and it fails harmlessly if the bus is still down. I will add the forget.

Quoted 19 lines

Looking at __lan9645x_mact_learn_cpu_copy() in lan9645x_mac.c, the CMD_LEARN is written before the completion poll, and the only failure returned is from the poll itself:

    lan_wr(... ANA_MACACCESS_MAC_TABLE_CMD_SET(CMD_LEARN), lan9645x, ANA_MACACCESS);

    return lan9645x_mac_wait_for_completion(lan9645x, NULL);

If the LEARN did take effect while the poll timed out, this error path calls lan9645x_pgid_entry_put(lan9645x, new_pgid), which for a freshly created PGID drops the last reference and returns the index to the free pool used by lan9645x_mdb_pgid_entry_create(), and __lan9645x_mdb_add() then destroys the fresh mdb entry:

    err = lan9645x_mdb_update_dest(lan9645x, mdb_entry, type, new_pgid,
                                   new_ports);
    if (err && !mdb_entry->ports)
            lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);
Quoted 9 lines

Does that leave a hardware MAC table entry whose DEST_IDX points at an index no software entry references any more, so it can never be forgotten? When lan9645x_pgid_entry_alloc() later reuses that index and rewrites ANA_PGID(index) with a different mask, would the orphaned entry start forwarding that group to an unrelated port set?

Would attempting lan9645x_mact_forget() for the (mac, vid) before dropping the software state be enough to keep the two views in sync?

I will add the forget here and a comment.

Quoted 35 lines
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5 -0
+	mdb_entry->pgid = new_pgid;
+	mdb_entry->ports = new_ports;
+	lan9645x_pgid_entry_put(lan9645x, old_pgid);
+	return 0;
+}

[ ... ]

Quoted 27 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +27 -0
+static int __lan9645x_mdb_del(struct lan9645x *lan9645x, int chip_port,
+			      const unsigned char addr[ETH_ALEN], u16 vid,
+			      enum macaccess_entry_type type)
+{
+	struct lan9645x_pgid_entry *new_pgid;
+	struct lan9645x_mdb_entry *mdb_entry;
+	u16 new_ports;
+	int err;
+
+	mdb_entry = lan9645x_mdb_entry_lookup(lan9645x, addr, vid);
+	if (!mdb_entry)
+		return -ENOENT;
+
+	if (!(mdb_entry->ports & BIT(chip_port)))
+		return 0;
+
+	new_ports = mdb_entry->ports & ~BIT(chip_port);
+
+	if (!new_ports) {
+		/* For IP multicast hardware uses DMAC as key (mac,vid) not
+		 * encoded mac.
+		 */
+		err = lan9645x_mact_forget(lan9645x, mdb_entry->mac,
+					   mdb_entry->vid, type);
+		if (err)
+			return err;
+		lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);
Quoted 8 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c

Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +2 -0
+		return 0;
+	}

Discovered by: opus-5 · Missed by: sashiko-gemini
For MACV4/MACV6 entries, the CMD_LEARN in lan9645x_mdb_update_dest() uses the mask-encoded address from lan9645x_mdb_encode_mac(), but this CMD_FORGET uses the plain mdb_entry->mac. Can the two commands address the same hardware entry?

Yes the two commands address the same hardware entry. The encoded bytes are not part of the (mac, vid) key used for lookups, for entries of type 2 and 3. Otherwise the HW could not work, because ingressing frames do not carry the port mask. The MAC which is used for the key depends on the mac table entry type.

Type 2 (IPv4 multicast):
KEY_MAC = 0x01005E000000 | MACLDATA[23:0]

Type 3 (IPv6 multicast):
KEY_MAC = 0x333300000000 | MACLDATA[31:0]

The CPU access path is no different. Encoding the mac before the forget makes no difference, because it changes bytes which are unused for the lookup.

Quoted 9 lines

The comment says the encoded bytes are not part of the (mac, vid) key, but both in-tree drivers for this silicon family re-encode the current mask before forgetting. ocelot_port_mdb_del() in drivers/net/ethernet/mscc/ocelot.c does:

    ocelot_encode_ports_to_mdb(addr, mc);
    ocelot_mact_forget(ocelot, addr, vid);
Quoted 8 lines

and lan966x_mdb_ip_del() in drivers/net/ethernet/microchip/lan966x/lan966x_mdb.c does the same:

    lan966x_mdb_encode_mac(mac, mdb_entry, type);
    lan966x_mac_forget(lan966x, mac, mdb_entry->vid, type);

ocelot also does forget-then-learn on every mask change rather than relying on LEARN rewriting an entry keyed by a different address.

I intentionally do not forget then learn, as that leaves a forwarding gap. Overwriting an existing entry updates the group mask atomically.

Quoted 3 lines

If the encoded bytes do participate in the MAC table key on the CPU access path,

But they do not. The encoding is necessary when learning because you need to store the mask in the entry for the forwarding engine. But the hash for the lookup is calculated based on the KEY_MAC.

Quoted 7 lines

then deleting the last member of an IPv4/IPv6 group here frees the software mdb_entry while the hardware entry survives and keeps forwarding to the old port mask, and every mask change inserts an extra entry instead of rewriting the existing one. Could the encoded address be used for CMD_FORGET as the peer drivers do, or the comment be backed by the datasheet's MAC table key definition for the MACv4/MACv6 entry types?

I will add the mac key derivation above for type 2 and 3 in the comment.

Quoted 10 lines

drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 330

Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +6 -0
+
+	/* Update PGID ptr for non-IP entries (L2 multicast) */
+	new_pgid = lan9645x_mdb_pgid_entry_get(lan9645x, new_ports, type);
+	if (IS_ERR(new_pgid))
+		/* Continue forwarding to old port group. */
+		return PTR_ERR(new_pgid);

Discovered by: opus-5 · Missed by: sashiko-gemini
Can this early return leave an mdb entry that can never be reclaimed?

Yes this is right. Continuing to forward to the old group is a bad fallback strategy. We need the mdb_entry->ports to be a subset of the kernel mdb entry.

Instead I will fallback to forward to the multicast flood mask, when we run out of PGIDs.

I will change __lan9645x_mdb_del() like so:

If lan9645x_mdb_pgid_entry_get() fails due to exhaustion, then if the pgid is not shared, we can safely overwrite it and update destinations.

If it is not shared, we are exhausted and can not service the mdb_del. We fallback to using PGID_MC, and keep mdb_entry->ports updated. And in __lan9645x_mdb_add() handle the entries on the fallback pgid. This should make sure entries do not get wedged, we can still configure forwarding to the CPU on a fallback entry and if a fallback entry is later reconfigured while there is PGID space available, it will become offloaded again.

Quoted 34 lines

For an L2 multicast group (ENTRYTYPE_LOCKED) with more than one member, new_ports is non-zero, so lan9645x_mdb_pgid_entry_get() runs and can return -ENOSPC once all general purpose indices between PGID_GP_START and PGID_GP_END are taken, or -ENOMEM from lan9645x_pgid_entry_alloc(). On that path BIT(chip_port) is never cleared from mdb_entry->ports.

The bridge has already removed the port from the group, and for user ports dsa_port_do_mdb_del() in net/dsa/switch.c just propagates the error with no refcount bookkeeping and no retry:

    if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
            err = ds->ops->port_mdb_del(ds, port, mdb, db);
            ...
            return err;
    }

so the driver is never asked to delete that port again. Does hardware then keep forwarding the group to a port that has left it, including after that port leaves the bridge entirely?

And since mdb_entry->ports can no longer reach zero, is the

    if (!new_ports) {

branch above (the one that calls lan9645x_mact_forget() and lan9645x_mdb_entry_dealloc()) unreachable for this (mac, vid), leaking the struct lan9645x_mdb_entry, its reference on a PGID index and the hardware MAC table entry until lan9645x_mdb_deinit() at teardown?

ocelot_port_mdb_del() orders this differently: it forgets the hardware entry and updates mc->ports before attempting the PGID allocation, so an -ENOSPC there cannot leave stale forwarding. The add path here does clean up on failure; would the same be appropriate for the delete path?

Quoted 8 lines
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4 -0
+
+	return lan9645x_mdb_update_dest(lan9645x, mdb_entry, type, new_pgid,
+					new_ports);
+}

[ ... ]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_port.c

Quoted 26 lines
Quoted 12 lines

index 0548904dc4bd2..407d7eb1d0640 100644

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +2 -1
@@ -210,8 +210,17 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)
 		ANA_PORT_CFG_PORTID_VAL,
 		lan9645x, ANA_PORT_CFG(p->chip_port));
 
-	if (p->chip_port != lan9645x->npi)
+	if (p->chip_port != lan9645x->npi) {
 		lan9645x_vlan_set_hostmode(p);
 
+		lan_rmw(ANA_CPU_FWD_CFG_IGMP_REDIR_ENA_SET(true) |

drivers/net/dsa/microchip/lan9645x/lan9645x_port.c int lan9645x_port_setup(struct dsa_switch *ds, int port) · line 226

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +8 -0
+			ANA_CPU_FWD_CFG_MLD_REDIR_ENA_SET(true) |
+			ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA_SET(true),
+			ANA_CPU_FWD_CFG_IGMP_REDIR_ENA |
+			ANA_CPU_FWD_CFG_MLD_REDIR_ENA |
+			ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA,
+			lan9645x, ANA_CPU_FWD_CFG(p->chip_port));
+	}
+
 	return 0;
 }

This is the per-port half of the forwarding change discussed above at lan9645x_mdb_init().

Quoted 1 line

Cross-instance finding from sashiko-gemini

(0d61a27e1fab704dbadd735055165f5f04176e88a680485b744c1f2e2be051cf):

Quoted 1 line

Duplicate CPU packet delivery on IP multicast MDB matches

#31 lore raw

PATCH v11 9/9 net: dsa: lan9645x: add port statistics

In reply to Jens Emil Schulz Østergaard

Add statistics support for the port counters. Chip registers are 32 bit, so this unit is responsible maintaining a 64bit software cache, and updating it frequently to handle overflows in hardware.

---
Changes in v11:
- add comment about calling contexts of sw_lock in lan9645x_stats_get_stats64

Changes in v5:
- make lan9645x_stats_init void
- add SCNT_TX_BUFDROP to tx_dropped
- change rmon range {0,64} -> {64, 64}. Runt frames counted elsewhere.
- remove rx_crc, rx_symbol_err from rx_packets, as they are already counted in SZ_* buckets.
- add defensive cancel_delayed_work_sync in stats_free

Changes in v4:
- remove rx_uc and tx_uc from ethtool stats list, as they are derivable from the eth-mac group
- split stats_init into stats_alloc and stats_init, use alloc in probe and init in dsa_setup

Changes in v3:
- No changes

Changes in v2:
- introduce spinlock sw_lock protecting software counters and region buffer.
- ran Ioana's selftest for standard counters drivers/net/hw/ethtool_std_stats.sh
along with
selftests/drivers/net/hw/ethtool_rmon.sh
they pass except for software injected pause frames.
- remove strings/counters covered by standard counters from get_strings/get_ethtool_stats.
- fix proper use of 'src' in standard counters
- remove static region table, and use stats_prepare_regions for dynamic region calculation inspired by ocelot.
- fix queue leak in error path.

---
 drivers/net/dsa/microchip/lan9645x/Makefile        |   1 +
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.c |  87 +-
 drivers/net/dsa/microchip/lan9645x/lan9645x_main.h |   3 +
 .../net/dsa/microchip/lan9645x/lan9645x_stats.c    | 935 +++++++++++++++++++++
 .../net/dsa/microchip/lan9645x/lan9645x_stats.h    | 279 ++++++
 5 files changed, 1304 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
index 2413d11fe849..cd994943c1c0 100644
@@ -8,4 +8,5 @@ mchp-lan9645x-objs := \
 	lan9645x_npi.o \
 	lan9645x_phylink.o \
 	lan9645x_port.o \
+	lan9645x_stats.o \
 	lan9645x_vlan.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +86 -1

131 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +3 -0
index 0e523b975619..6423fa415330 100644
@@ -217,6 +217,9 @@ struct lan9645x {
 	 */
 	struct mutex mdb_lock;
 
+	/* Statistics  */
+	struct lan9645x_stats *stats;
+
 	int num_port_dis;
 };
 
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +935 -0

935 lines not on this page · raw message

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +279 -0

279 lines not on this page · raw message

Signature · 1 line
2.52.0
#32 lore raw

Re: [PATCH net-next v11 9/9] net: dsa: lan9645x: add port statistics

This is a reply to:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com?part=9

Quoted 12 lines

--- Patch [9]: [PATCH net-next v11 9/9] net: dsa: lan9645x: add port statistics --- commit 237edd60065db45a5dc8339c001c3205645d61b0
Author: Jens Emil Schulz Østergaard <[email protected]>

net: dsa: lan9645x: add port statistics

This adds a new lan9645x_stats unit which exposes the per-port hardware counters through the DSA ethtool hooks and ndo_get_stats64. Since the chip counters are 32 bit, a 64-bit software shadow is kept and refreshed by a delayed work every three seconds. No Link: tags are present in the commit header.

Quoted 3 lines

A few questions below.

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_main.c

Quoted 50 lines
Quoted 3 lines

index fc604edb309b9..6a14ba3661625 100644

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0

[ ... ]

Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0 -0
@@ -800,6 +866,18 @@ static const struct dsa_switch_ops lan9645x_switch_ops = {
 	/* Multicast database */
 	.port_mdb_add			= lan9645x_mdb_add,
 	.port_mdb_del			= lan9645x_mdb_del,

drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static const struct dsa_switch_ops lan9645x_switch_ops = { · line 878

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10 -0
+
+	/* Port statistics counters. */
+	.get_strings			= lan9645x_get_strings,
+	.get_ethtool_stats		= lan9645x_get_ethtool_stats,
+	.get_sset_count			= lan9645x_get_sset_count,
+	.get_eth_mac_stats		= lan9645x_get_eth_mac_stats,
+	.get_rmon_stats			= lan9645x_get_rmon_stats,
+	.get_stats64			= lan9645x_get_stats64,
+	.get_pause_stats		= lan9645x_get_pause_stats,
+	.get_mm_stats			= lan9645x_get_mm_stats,

Discovered by: opus-5 · Missed by: sashiko-gemini

Is .get_mm_stats reachable without a .get_mm implementation? A grep over drivers/net/dsa/microchip/lan9645x/ finds only get_mm_stats, neither .get_mm nor .set_mm is provided.

dsa_user_get_mm() refuses the request in that case:

net/dsa/user.c:dsa_user_get_mm() {
	if (!ds->ops->get_mm)
		return -EOPNOTSUPP;
	...
}

and mm_prepare_data() leaves before ->get_mm_stats() is invoked:

net/ethtool/mm.c:mm_prepare_data() {
	ret = ops->get_mm(dev, &data->state);
	if (ret)
		goto out_complete;

	if (ops->get_mm_stats && (req_base->flags & ETHTOOL_FLAG_STATS))
		ops->get_mm_stats(dev, &data->stats);
	...
}

So does lan9645x_stats_get_mm_stats() ever run, and does ethtool --show-mm --include-statistics just return -EOPNOTSUPP?

Quoted 10 lines

The same missing .get_mm makes __ethtool_dev_mm_supported() always return false, and both stats_prepare_data() (net/ethtool/stats.c) and pause_prepare_data() (net/ethtool/pause.c) reject requests carrying src == EMAC or src == PMAC on that basis. Does that leave the ETHTOOL_MAC_STATS_SRC_EMAC and ETHTOOL_MAC_STATS_SRC_PMAC branches of lan9645x_stats_get_eth_mac_stats(), lan9645x_stats_get_rmon_stats(), lan9645x_stats_get_pause_stats(), lan9645x_stats_get_eth_phy_stats() and lan9645x_stats_get_eth_ctrl_stats() unreachable as well, with only the default aggregate branch ever executing?

Yes, this is also correct. I will remove the mac merge related code until mac merge itself lands in the driver.

Quoted 7 lines
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2 -0
+	.get_eth_phy_stats		= lan9645x_get_eth_phy_stats,
+	.get_eth_ctrl_stats		= lan9645x_get_eth_ctrl_stats,
 };

[ ... ]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c

Quoted 38 lines
Quoted 5 lines

new file mode 100644
index 0000000000000..f9c4bcb308991

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0 -0
@@ -0,0 +1,935 @@

[ ... ]

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +3 -0
+void lan9645x_stats_get_stats64(struct lan9645x *lan9645x, int port,
+				struct rtnl_link_stats64 *stats)
+{

[ ... ]

Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +11 -0
+	stats->rx_packets = c[SCNT_RX_SHORT] +
+			    c[SCNT_RX_FRAG] +
+			    c[SCNT_RX_JABBER] +
+			    c[SCNT_RX_SZ_64] +
+			    c[SCNT_RX_SZ_65_127] +
+			    c[SCNT_RX_SZ_128_255] +
+			    c[SCNT_RX_SZ_256_511] +
+			    c[SCNT_RX_SZ_512_1023] +
+			    c[SCNT_RX_SZ_1024_1526] +
+			    c[SCNT_RX_SZ_JUMBO] +
+			    c[SCNT_RX_LONG] +

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 638

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10 -0
+			    c[SCNT_RX_PMAC_SHORT] +
+			    c[SCNT_RX_PMAC_FRAG] +
+			    c[SCNT_RX_PMAC_JABBER] +
+			    c[SCNT_RX_PMAC_SZ_64] +
+			    c[SCNT_RX_PMAC_SZ_65_127] +
+			    c[SCNT_RX_PMAC_SZ_128_255] +
+			    c[SCNT_RX_PMAC_SZ_256_511] +
+			    c[SCNT_RX_PMAC_SZ_512_1023] +
+			    c[SCNT_RX_PMAC_SZ_1024_1526] +
+			    c[SCNT_RX_PMAC_SZ_JUMBO];

Discovered by: opus-5 · Missed by: sashiko-gemini

Quoted 5 lines

Is the missing c[SCNT_RX_PMAC_LONG] here intentional? The eMAC oversize counter c[SCNT_RX_LONG] is summed into rx_packets, but the pMAC term list stops at SCNT_RX_PMAC_SZ_JUMBO. The same asymmetry appears in stats->rx_dropped below, which also starts from c[SCNT_RX_LONG] alone.

Yes, this is a mistake, I will add it.

Quoted 51 lines

Every other term in this function is paired, and rx_errors does include the pMAC counterpart:

	stats->rx_errors = c[SCNT_RX_SHORT] +
			   ...
			   c[SCNT_RX_PMAC_LONG];

SCNT_RX_PMAC_LONG (offset 0x42) is present in lan9645x_port_stats_layout[] and is accumulated by __lan9645x_stats_view_idx_transfer(), so on a port running frame preemption, would oversize frames on the preemptible MAC show up in rx_errors while being absent from rx_packets and rx_dropped?

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10 -0
+
+	stats->multicast = c[SCNT_RX_MC] + c[SCNT_RX_PMAC_MC];
+
+	stats->rx_errors = c[SCNT_RX_SHORT] +
+			   c[SCNT_RX_FRAG] +
+			   c[SCNT_RX_JABBER] +
+			   c[SCNT_RX_CRC] +
+			   c[SCNT_RX_SYMBOL_ERR] +
+			   c[SCNT_RX_LONG] +
+			   c[SCNT_RX_PMAC_SHORT] +

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 658

Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10 -0
+			   c[SCNT_RX_PMAC_FRAG] +
+			   c[SCNT_RX_PMAC_JABBER] +
+			   c[SCNT_RX_PMAC_CRC] +
+			   c[SCNT_RX_PMAC_SYMBOL_ERR] +
+			   c[SCNT_RX_PMAC_LONG];
+
+	stats->rx_dropped = c[SCNT_RX_LONG] +
+			    c[SCNT_DR_LOCAL] +
+			    c[SCNT_DR_TAIL] +
+			    c[SCNT_RX_CAT_DROP] +

Discovered by: opus-5 · Missed by: sashiko-gemini

Should one oversize frame be reported three times? c[SCNT_RX_LONG] is added to rx_packets, to rx_errors and to rx_dropped, so a single frame appears in all three fields of ip -s link and /proc/net/dev. The same applies, twice over, to c[SCNT_RX_SHORT], c[SCNT_RX_FRAG], c[SCNT_RX_JABBER] and their pMAC twins, which land in both rx_packets and rx_errors.

The uAPI kernel-doc in include/uapi/linux/if_link.h describes these as distinct categories:

* @rx_packets: Number of good packets received by the interface.
* @rx_errors: Total number of bad packets received on this network device.
* @rx_dropped: Number of packets received but not processed, e.g. due to
* lack of resources or unsupported protocol.

Quoted 8 lines

and points length violations at @rx_length_errors, which this driver leaves at zero.

For comparison, ocelot_port_get_stats64() (drivers/net/ethernet/mscc/ocelot_stats.c) does fold SHORTS, FRAGMENTS, JABBERS and LONGS into rx_packets, but it does not populate rx_errors at all and does not add RX_LONGS to rx_dropped. Was RX_LONG in rx_dropped meant to be rx_length_errors instead?

I will add rx_length_errors, and move RX_LONG from rx_dropped to there.

Quoted 57 lines
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +1 -0
+			    c[SCNT_RX_RED_PRIO_0] +

[ ... ]

Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +1 -0
+			    c[SCNT_RX_RED_PRIO_7];

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 930

Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +7 -0
+void lan9645x_stats_init(struct lan9645x *lan9645x)
+{
+	struct lan9645x_stats *stats = lan9645x->stats;
+
+	queue_delayed_work(stats->queue, &stats->work,
+			   LAN9645X_STATS_CHECK_DELAY);
+}

Discovered by: opus-5 · Missed by: sashiko-gemini

Where does the software shadow and the hardware counter get a common baseline?

lan9645x_stats_add_cnt() keeps the previous hardware value in the low half of the shadow and infers a wrap from it:

	if (val < (*cnt & U32_MAX))
		*cnt += (u64)1 << 32; /* value has wrapped */

	*cnt = (*cnt & ~(u64)U32_MAX) + val;

vstat->cnts is devm_kcalloc()'d once in lan9645x_stats_alloc() during probe and never re-zeroed, and SYS_STAT_CFG.STAT_CLEAR_SHOT is defined in lan9645x_regs.h but never written. lan9645x_stats_init() runs from lan9645x_setup() after lan9645x_reset_switch() has driven SYS_RESET_CFG.CORE_ENA=0 and run SYS_RAM_INIT, and it only re-arms the poll work.

If the core reset does clear the counter RAM, then on a second .setup() of an already-probed instance (DSA tree teardown and re-setup, which the .setup/.teardown stats hooks appear written for) hardware restarts at 0 while the shadow still holds the old values, so the first poll sees val = 0 < (*cnt & U32_MAX) for every non-zero counter and adds 4294967296 to each, permanently.

If the reset does not clear them, an unbind/rebind starts with a zeroed shadow against non-zero hardware, so the fresh interface reports traffic it never saw.

ocelot_init() clears the counters explicitly for the same block:

drivers/net/ethernet/mscc/ocelot.c:ocelot_init() {
		/* Clear all counters (5 groups) */
		ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(port) |
				     SYS_STAT_CFG_STAT_CLEAR_SHOT(0x7f),
			     SYS_STAT_CFG);
}
Quoted 3 lines

Would it make sense to clear the hardware counters and/or memset the shadow in lan9645x_stats_init() so the two always start together?

Yes I think this makes sense, I will add this.

Quoted 3 lines

[ ... ]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h

Quoted 45 lines
Quoted 5 lines

new file mode 100644
index 0000000000000..cd5db16258a09

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +0 -0
@@ -0,0 +1,279 @@

[ ... ]

Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +3 -0
+/* Counter indices into stat layout structs */
+#define SCNT_FRER_SID_IN_PKT             0
+#define SCNT_ISDX_GREEN_OCT              1

[ ... ]

Quoted 1 line

+#define SCNT_SF_MATCHING_FRAMES_COUNT 0

[ ... ]

Quoted 1 line

+#define SCNT_ESDX_GREEN_OCT 0

[ ... ]

drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h line 180

Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +8 -0
+enum lan9645x_view_stat_type {
+	LAN9645X_STAT_PORTS = 0,
+	LAN9645X_STAT_ISDX,
+	LAN9645X_STAT_ESDX,
+	LAN9645X_STAT_SFID,
+
+	LAN9645X_STAT_NUM,
+};

Discovered by: opus-5 · Missed by: sashiko-gemini

This isn't a bug, but the ISDX, ESDX, SFID and FRER parts of this framework have no user in the patch. A grep over drivers/net/dsa/microchip/lan9645x/ shows SCNT_ISDX_*, SCNT_SF_*, SCNT_ESDX_* and SCNT_FRER_SID_IN_PKT matching only in this header, and lan9645x_view_stat_cfgs[] populates just [LAN9645X_STAT_PORTS].

lan9645x_stats_view_update() has PORTS as its only non-default case, so the loop in lan9645x_stats_update():

	for (int vtype = 0; vtype < LAN9645X_STAT_NUM; vtype++)
		lan9645x_stats_view_update(lan9645x, vtype);
Quoted 9 lines

does three no-op iterations over zeroed view[] entries on every poll.

Also, struct lan9645x_view_stats.name is only ever written (.name = "ports") and never read, and the back-pointer assignment vstat->stats = lan9645x->stats in lan9645x_view_stat_init() has no reader. Since the commit message only describes adding "statistics support for the port counters", could the unused infrastructure be dropped until the view that needs it lands?

Yes I will remove the unused views and fields.

Quoted 1 line

[ ... ]

maintainer
#33 lore raw
In reply to Jens Emil Schulz Østergaard
Quoted 103 lines · Jens Emil Schulz Østergaard

This series provides the Microchip LAN9645X Switch driver.

The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.

The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.

The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.

The chip supports a variety of network features such as

* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing

The LAN9645x family consists of the following SKUs:

LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S

The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.

The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.

This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver

drivers/net/dsa/ocelot/ocelot_ext.c

which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.

The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.

Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.

The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf

This series will deliver the following features:

* Standalone ports
* Bridge forwarding and FDB offloading
* VLAN-aware bridge
* Stats integration

More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:

* Add LAG support.
* Add MDB support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.

For completeness I include tentative plan of planned patches for LAN9645x peripherals:

* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.

Quoted 1 line

I forwarded the feedback from sashiko/nipa, but sashiko gemini has more comments:

https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com

please have a look and also to net-next commit c82ff94592fb

/P

maintainer
#34 lore raw
Quoted 104 lines · Paolo Abeni
Quoted 103 lines · Jens Emil Schulz Østergaard

This series provides the Microchip LAN9645X Switch driver.

The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.

The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.

The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.

The chip supports a variety of network features such as

* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing

The LAN9645x family consists of the following SKUs:

LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S

The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.

The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.

This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver

drivers/net/dsa/ocelot/ocelot_ext.c

which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.

The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.

Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.

The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf

This series will deliver the following features:

* Standalone ports
* Bridge forwarding and FDB offloading
* VLAN-aware bridge
* Stats integration

More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:

* Add LAG support.
* Add MDB support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.

For completeness I include tentative plan of planned patches for LAN9645x peripherals:

* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.

Quoted 7 lines
Quoted 1 line

I forwarded the feedback from sashiko/nipa, but sashiko gemini has more comments:

https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com

please have a look and also to net-next commit c82ff94592fb

Whoops, sorry I missed part of netdev traffic. Please ignore this one.

/P

#35 lore raw
In reply to Paolo Abeni
Quoted 107 lines · Paolo Abeni

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

Quoted 103 lines · Jens Emil Schulz Østergaard

This series provides the Microchip LAN9645X Switch driver.

The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.

The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.

The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.

The chip supports a variety of network features such as

* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing

The LAN9645x family consists of the following SKUs:

LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S

The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.

The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.

This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver

drivers/net/dsa/ocelot/ocelot_ext.c

which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.

The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.

Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.

The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf

This series will deliver the following features:

* Standalone ports
* Bridge forwarding and FDB offloading
* VLAN-aware bridge
* Stats integration

More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:

* Add LAG support.
* Add MDB support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.

For completeness I include tentative plan of planned patches for LAN9645x peripherals:

* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.

Quoted 1 line
Quoted 9 lines

I forwarded the feedback from sashiko/nipa, but sashiko gemini has more comments:

https://sashiko.dev/#/patchset/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a%40microchip.com

please have a look and also to net-next commit c82ff94592fb

/P

I will go through the comments from the sashiko brothers.

Thanks
Emil