net: dsa: add DSA support for the LAN9645x switch chip family
Subsystems (5)
v14 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, which also resets the chip before it instantiates its children.
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
* Multicast forwarding and MDB 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 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 v14:
- Individual patches mention specific v14 changes
- tag: classify untagged and priority tagged frames to VID 0 on xmit,
pull the VLAN header before reading it, restore the VLAN tag on rcv
whenever one was popped, and add a .flow_dissect callback that
accounts for popped VLAN tags.
- bindings: use the dt-bindings: net: dsa: subject prefix, and describe
all switch register targets and the analyzer and PTP interrupts.
- vlan: use TAG_NO_UNAWARE on ports with only tagged VLANs.
- mac table: keep a CPU port host entry while another database uses the
same MAC table key.
- mdb: keep the PGID reference when a mac table write fails while
widening a group, drop it on a failed narrow that keeps the same PGID,
and keep a CPU port host entry while another database uses the same
mac table key.
- bridge: only enable learning on bridged ports, start a joining port
disabled so it does not learn before its STP state is applied, and
honour host flood requests from bridged ports.
- stats: return 0 from get_sset_count() for other string sets, leave
RMON fragments unset, and describe the pMAC counters correctly.
- Link to v13: https://lore.kernel.org/r/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2@microchip.com
Changes in v13:
- Individual patches mention specific v13 changes
- bindings: Drop the commit message paragraph citing
Documentation/networking/phy.rst.
- basic: only redirect the CPU extraction queues to the NPI port while
its link is up, and flush the CPU port module on NPI link up.
- Rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 37
- Link to v12: https://lore.kernel.org/r/20260908-dsa_lan9645x_switch_driver_base-v12-0-2d6aa59350cd@microchip.com
Changes in v12:
- reorder the series so bridge support lands after vlan, mac table and
mdb support. port_fast_age() now exists before the STP state handling
that needs it, and host address filtering is in place before bridging.
- include the CPU port module in the flood masks from the start, and
remove it again in the bridge patch where port_set_host_flood() takes
over on demand host flooding. Previously the host could not receive
unicast until the mac table patch.
- vlan: serialize the VLAN table with fwd_domain_lock, and describe the
untagged VLAN, TPID and C-component conformance limitations.
- tag driver: move an out-of-band VLAN tag into the payload before
reading it, instead of relying on the conduit never advertising a VLAN
TX offload.
- tag driver: restore the classified VLAN as a C-tag rather than following
the IFH tag type, so a terminated frame lands on the VID the hardware
forwarded it on.
- basic: drop the tail drop watermark setup, which programmed a
condition that could not trigger.
- mdb: handle PGID exhaustion on both the add and delete paths, rather
than leaving a departed port in the group.
- mdb: classify IPv4 multicast on the 01:00:5E prefix alone. Hardware does
not apply the 23-bit rule, so some groups were programmed as entries it
never matches.
- stats: give the hardware counters and the software shadow a common
baseline, fix some rtnl_link_stats64 fields, and stop reporting the
three eth-mac fields the hardware cannot measure.
- stats: stop the counter poller in .shutdown, which kept reading
registers after the parent had been shut down.
- Link to v11: https://lore.kernel.org/r/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com
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: dsa: add Microchip LAN9645x switch
net: dsa: lan9645x: add autogenerated register macros
net: dsa: lan9645x: add basic dsa driver for LAN9645X
net: dsa: lan9645x: add vlan support
net: dsa: lan9645x: add mac table integration
net: dsa: lan9645x: add mdb management
net: dsa: lan9645x: add bridge support
net: dsa: lan9645x: add port statistics
.../net/dsa/microchip,lan96455s-switch.yaml | 208 +++ MAINTAINERS | 10 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 12 + drivers/net/dsa/microchip/lan9645x/Makefile | 12 + drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c | 268 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 1060 +++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 435 +++++ drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 582 ++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 116 ++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 371 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 180 ++ drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1932 ++++++++++++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.c | 854 +++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.h | 229 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 411 +++++ include/linux/dsa/lan9645x.h | 54 + include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 514 ++++++ 22 files changed, 7265 insertions(+)
---
base-commit: 45ad84d2800e4a092fb8d96006a533b2d0ab13f6
change-id: 20260210-dsa_lan9645x_switch_driver_base-312bbfc37edb
Best regards,
Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
PATCH v14 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.
A frame extracted from a VLAN-aware port arrives without its VLAN tag. REW_PORT_CFG.NO_REWRITE is clear on the NPI port, so the rewriter applies the classified VLAN_POP_CNT, and the classified VID reaches the CPU only through the IFH. The tagger restores it as a hwaccel tag when the IFH reports that a tag was popped. An untagged frame is classified to the port pvid without a pop and is delivered untagged, which the bridge also classifies to the pvid.
The restored tag is always a C-tag, not the TPID the IFH TAG_TYPE reports. Both TPIDs are recognized as VLAN tags unconditionally, with no per port control to treat one as untagged customer data, so an S-tag is already consumed as the VLAN tag before extraction. Restoring 802.1AD would make the bridge push the tag back into the payload and reclassify the frame to the port pvid, placing it on a different VID than the one the hardware forwarded it on. Normalizing to a C-tag keeps the terminated path consistent with the forwarded path, at the cost of not preserving the S-tag TPID towards the CPU. This assumes a bridge vlan_protocol of 802.1Q, which is the only protocol the driver offloads.
On injection the IFH carries the classified VID used by the rewriter to decide whether to add a port tag. On a VLAN-aware port, a VLAN tag with a non-zero VID is moved from the payload into the IFH. Untagged and priority tagged frames are injected with classified VID 0 and left as they are, so the rewriter adds no tag to them.
---
Changes in v14:
- Classify untagged and priority tagged frames to VID 0 on xmit instead of the bridge pvid, and leave priority tags in the payload.
- Restore the VLAN tag on rcv whenever the rewriter popped one, instead of only when the VID differs from the port pvid.
- Add a .flow_dissect callback that accounts for the gap left by VLAN tags popped on extraction. The generic dissector assumes the tag length is needed_headroom.
- Pull the VLAN header with pskb_may_pull() before reading it on xmit, so a tag in paged data is handled like a linear one, and drop the frame if the pull fails.
Changes in v12:
- Move an out-of-band VLAN tag into the payload with __vlan_hwaccel_push_inside() before reading it, rather than relying on the conduit never advertising NETIF_F_HW_VLAN_CTAG_TX or NETIF_F_HW_VLAN_STAG_TX in vlan_features.
- Return the skb from lan9645x_xmit_get_vlan_info(), since __vlan_hwaccel_push_inside() may reallocate and frees the skb on failure.
- Annotate the IFH field defines with injection/extraction applicability
- Drop IFH_TIMESTAMP because it is 38 bits wide. Rely on NS/SUB_NS subfields.
- Document how HW derives the DMAC offset from pop_cnt and etype_ofs, and drop frames whose encoding only a tag push could produce.
- Drop unncessary IFH_SRCPORT on injection.
- Drop the WARN_ON_ONCE() when the source port does not resolve to a user port.
- Move the IFH field position and size defines from include/linux/dsa/lan9645x.h into net/dsa/tag_lan9645x.c.
- Rename LAN9645X_IFH_LEN to LAN9645X_IFH_LEN_BYTES, so it does not read as the position of the IFH LEN field.
- Use skb_vlan_eth_hdr() in lan9645x_xmit_get_vlan_info().
- Drop BTM_MSK() TOP_MSK() helpers for GENMASK().
- Rename set_merge_mask() to lan9645x_ifh_merge_byte().
- Name the vendor in the Kconfig prompt, spell the part LAN9645x, and move the entry to its sorted position after NET_DSA_TAG_KSZ.
- Clamp the classified QoS class to the width of IFH_QOS_CLASS. A skb->priority above 7 aliased down onto an unrelated class.
- Comment why needed_headroom covers the extraction prefix.
- Restore the classified VLAN as a C-tag rather than following the IFH TAG_TYPE, so a terminated S-tagged frame lands on the same VID the hardware forwards it on.
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 | 54 +++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 514 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 590 insertions(+)
MAINTAINERS +8 -0
@@ -17814,6 +17814,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 +54 -0
54 lines not on this page · raw message
include/net/dsa.h +2 -0
@@ -62,6 +62,7 @@ struct tc_action;#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35#define DSA_TAG_PROTO_KS8995_VALUE 36 +#define DSA_TAG_PROTO_LAN9645X_VALUE 37enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -101,6 +102,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE ,DSA_TAG_PROTO_KS8995 =DSA_TAG_PROTO_KS8995_VALUE , + DSA_TAG_PROTO_LAN9645X = DSA_TAG_PROTO_LAN9645X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +11 -0
@@ -137,6 +137,17 @@ config NET_DSA_TAG_KSZ Say Y if you want to enable support for tagging frames for the Microchip 8795/937x/9477/9893 families of switches. +config NET_DSA_TAG_LAN9645X + tristate "Tag driver for Microchip LAN9645x switches" + help + Say Y or M if you want to enable NPI tagging for the Microchip + 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_NETC tristate "Tag driver for NXP NETC switches" help
net/dsa/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KS8995) += tag_ks8995.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_MT7628) += tag_mt7628.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o
net/dsa/tag_lan9645x.c new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v14 1/9] net: dsa: add tag driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] net/dsa: lan9645x: Stale skb->mac_header and skb->network_header after vlan_remove_tag() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] net/dsa: lan9645x: Stale skb->mac_header and skb->network_header after vlan_remove_tag() --
commit 2bf43370c466c901725bcb460aaa53654797d172
Author: Jens Emil Schulz Østergaard <[email protected]>
Subject: net: dsa: add tag driver for LAN9645X
This commit adds a tag driver for the LAN9645x family of switches, using a front port configured as an NPI port for CPU traffic. It handles frame extraction and injection using internal frame headers and prefix formatting.
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0
-0
[ ... ]
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+static struct sk_buff *lan9645x_xmit_get_vlan_info (struct sk_buff *skb, +struct net_device *br, +u32 *vlan_tci, +u32 *tag_type) +{
[ ... ]
net/dsa/tag_lan9645x.c line 272
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+ hdr =skb_vlan_eth_hdr (skb); +if (ntohs (hdr->h_vlan_proto) == proto && +ntohs (hdr->h_vlan_TCI) &VLAN_VID_MASK ) { +vlan_remove_tag (skb, &tci); + *vlan_tci = tci;
[Severity: Medium]
When calling vlan_remove_tag() here, are the skb mac_header and network_header metadata offsets left pointing to stale locations?
The vlan_remove_tag() function removes the vlan tag and moves the payload, but it expects the caller to update skb->mac_header and skb->network_header. This is why the standard helper __skb_vlan_pop() is usually preferred.
Because this tag driver does not adjust skb->mac_header, the offset becomes stale. After lan9645x_xmit() pushes the 28-byte internal frame header, won't skb_mac_header(skb) incorrectly point to bytes inside the new header rather than the actual start of the destination address?
If the conduit device driver or network stack relies on skb_mac_header(skb) for transmit processing, this could cause it to read incorrect bytes for packets that had a vlan tag stripped.
Quoted 8 lines
net/dsa/tag_lan9645x.c new file +8
-0+ } + } + + *tag_type = (proto !=ETH_P_8021Q ) ?LAN9645X_IFH_TAG_TYPE_S : +LAN9645X_IFH_TAG_TYPE_C ; + +return skb; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213@microchip.com?part=1
[email protected]
AI reviewRe: [PATCH net-next v14 1/9] net: dsa: add tag driver for LAN9645X
In reply to Jens Emil Schulz ØstergaardThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In lan9645x_rcv() (net/dsa/tag_lan9645x.c:459), every tag popped by the hardware is restored as an 802.1Q hwaccel tag with…
- [Low] The comment above skb_postpull_rcsum() in lan9645x_rcv() (net/dsa/tag_lan9645x.c:416-421) says the bytes to subtract are "what…
- [Low] lan9645x_rcv() (net/dsa/tag_lan9645x.c:450) restores the popped VLAN tag only when dsa_port_is_vlan_filtering(dp) && ifh_gap_len.
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the new tagger adds another lockless reader of it.
--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch when a front port is used as the CPU (NPI) port. Extraction uses a long prefix plus a 28 byte IFH, and injection uses only the IFH. VLAN tags popped by the hardware are restored on receive as 802.1Q hwaccel tags, and on transmit the VLAN tag is moved from the payload into the IFH.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,514 @@
[ ... ]
net/dsa/tag_lan9645x.c line 302
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+static struct sk_buff *lan9645x_xmit (struct sk_buff *skb, +struct net_device *ndev) +{ +struct dsa_port *dp =dsa_user_to_port (ndev); +u32 vlan_tci, tag_type; +u32 qos_class; +void *ifh; + + skb =lan9645x_xmit_get_vlan_info (skb,dsa_port_bridge_dev_get (dp), + &vlan_tci, &tag_type);
[Severity: Medium]
This isn't a bug introduced by this patch, but this adds one more lockless reader of dp->bridge in the xmit path.
dsa_port_bridge_dev_get() does this with no READ_ONCE() and no lifetime protection:
return dp->bridge ? dp->bridge->dev : NULL;
On bridge leave, dsa_port_bridge_leave()->dsa_port_bridge_destroy() clears the pointer and frees the last reference right away:
dp->bridge = NULL; if (!refcount_dec_and_test(&bridge->refcount)) return; ... kfree(bridge);
There is no RCU grace period between the two. Can a transmit on the user port that races with the bridge leave load the old dp->bridge and then read ->dev from a freed dsa_bridge?
The window is narrow. tag_ocelot.c, tag_sja1105.c and the dsa_software_vlan_untag() helpers use the same pattern, so the root cause is in the DSA core and not in this tagger.
[ ... ]
net/dsa/tag_lan9645x.c line 425
Quoted 13 lines
net/dsa/tag_lan9645x.c new file +13
-0+/* Reset skb->data past the actual ethernet header. */ +skb_pull (skb,ETH_HLEN ); + +/* We must deliver the skb so skb->csum only covers the data beyond the +* real ethernet header. The fake ethernet header in the prefix is +* not part of skb->csum already. We must subtract what remains of the +* prefix, the ifh and the gap. The start is derived from the current +* skb->data rather than saved on entry, because the pskb_may_pull() +* calls above may have reallocated skb->head. +*/ +skb_postpull_rcsum (skb, + skb->data -LAN9645X_TOTAL_TAG_LEN - ifh_gap_len, +LAN9645X_TOTAL_TAG_LEN + ifh_gap_len);
[Severity: Low]
This isn't a bug, but the comment doesn't list everything the call subtracts.
The length is LAN9645X_TOTAL_TAG_LEN + ifh_gap_len, which is 44 + gap bytes. That is 2 bytes of prefix remainder, plus 28 bytes of IFH, plus the gap, plus the 14 byte real Ethernet header.
The code looks right, because dsa_switch_rcv() does skb_push(ETH_HLEN) and then eth_type_trans() without adjusting the checksum. Could the comment also mention the real Ethernet header? Otherwise someone might later shorten the length to match the comment.
[ ... ]
net/dsa/tag_lan9645x.c line 451
Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3
-0+ dp =dsa_user_to_port (skb->dev); + +if (dsa_port_is_vlan_filtering (dp) && ifh_gap_len) {
[Severity: Low]
Can frames lose their VLAN tag while vlan_filtering is changing?
dsa_port_vlan_filtering() calls the driver op before it updates the software flag:
err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering, extack); ... dp->vlan_filtering = vlan_filtering;
In this series, lan9645x_port_vlan_filtering() programs VLAN_POP_CNT right away through lan9645x_vlan_port_apply(). Frames that the hardware pops in that window reach lan9645x_rcv() with ifh_gap_len != 0 while dsa_port_is_vlan_filtering(dp) is still false. They are delivered with no tag.
The reverse transition has the same problem, including bridge leave via lan9645x_vlan_set_hostmode(). Frames popped before the change but handled after dp->vlan_filtering is cleared also lose their tag.
POP_CNT is 0 on non-filtering ports, so the gap is already 0 there. Would checking only ifh_gap_len keep the CPU view consistent with what the hardware did?
net/dsa/tag_lan9645x.c line 461
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH +* reports. The classifier recognizes both TPIDs as VLAN tags, +* so an S-tag has already been used for classification by the +* time we get here. Restoring it as 802.1AD would make the +* bridge push it back into the payload and reclassify the frame +* to the port pvid, on a different VID than the one the +* hardware forwarded it on. +*/ +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), vlan_tci); + }
[Severity: Medium]
Is the 802.1Q-only assumption enforced anywhere? The commit message says:
This assumes a bridge vlan_protocol of 802.1Q, which is the only protocol the driver offloads.
The xmit side of this file does handle non-802.1Q bridges, in lan9645x_xmit_get_vlan_info():
br_vlan_get_proto(br, &proto);
...
if (ntohs(hdr->h_vlan_proto) == proto &&
ntohs(hdr->h_vlan_TCI) & VLAN_VID_MASK) {
...
*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S :
LAN9645X_IFH_TAG_TYPE_C;DSA doesn't handle SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL. __br_vlan_set_proto() sends that attribute with SWITCHDEV_F_SKIP_EOPNOTSUPP, so setting "vlan_protocol 802.1ad" on the bridge seems to succeed while the lan9645x ports stay offloaded. The switch driver in this series doesn't appear to check the bridge vlan_protocol either.
On such a bridge, every tag restored here has an 0x8100 TPID, and __allowed_ingress() in net/bridge/br_vlan.c then does:
if (skb->vlan_proto != br->vlan_proto) {
/* Protocol-mismatch, empty out vlan_tci for new tag */
skb_push(skb, ETH_HLEN);
skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
skb_vlan_tag_get(skb));This pushes the tag back into the payload and classifies the frame to the pvid. Wouldn't frames trapped or copied to the CPU then land on the pvid? That is the same misclassification the C-tag normalization is meant to avoid, only in the opposite configuration.
Should rcv follow the bridge vlan_protocol the way xmit does? Or should the driver refuse 802.1ad bridges?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 1/9] net: dsa: add tag driver for LAN9645X
Quoted 73 lines · On Mon, 2026-10-12 at 11:24 +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 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In
lan9645x_rcv()(net/dsa/tag_lan9645x.c:459), every tag popped by the hardware is restored as an 802.1Q hwaccel tag with…
- [Low] The comment aboveskb_postpull_rcsum()inlan9645x_rcv()(net/dsa/tag_lan9645x.c:416-421) says the bytes to subtract are "what…
- [Low]lan9645x_rcv()(net/dsa/tag_lan9645x.c:450) restores the popped VLAN tag only whendsa_port_is_vlan_filtering(dp) && ifh_gap_len.Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the new tagger adds another lockless reader of it.--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch when a front port is used as the CPU (NPI) port. Extraction uses a long prefix plus a 28 byte IFH, and injection uses only the IFH. VLAN tags popped by the hardware are restored on receive as 802.1Q hwaccel tags, and on transmit the VLAN tag is moved from the payload into the IFH.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,514 @@[ ... ]
net/dsa/tag_lan9645x.c line 302
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+static struct sk_buff *lan9645x_xmit (struct sk_buff *skb, +struct net_device *ndev) +{ +struct dsa_port *dp =dsa_user_to_port (ndev); +u32 vlan_tci, tag_type; +u32 qos_class; +void *ifh; + + skb =lan9645x_xmit_get_vlan_info (skb,dsa_port_bridge_dev_get (dp), + &vlan_tci, &tag_type);[Severity: Medium]
This isn't a bug introduced by this patch, but this adds one more lockless reader ofdp->bridgein the xmit path.
dsa_port_bridge_dev_get()does this with noREAD_ONCE()and no lifetime protection:return dp->bridge ? dp->bridge->dev : NULL;On bridge leave, dsa_port_bridge_leave()->dsa_port_bridge_destroy() clears the pointer and frees the last reference right away:
dp->bridge = NULL; if (!refcount_dec_and_test(&bridge->refcount)) return; ... kfree(bridge);
Quoted 8 lines
There is no RCU grace period between the two. Can a transmit on the user port that races with the bridge leave load the old
dp->bridgeand then read ->dev from a freeddsa_bridge?The window is narrow.
tag_ocelot.c,tag_sja1105.cand thedsa_software_vlan_untag()helpers use the same pattern, so the root cause is in the DSA core and not in this tagger.
Dismissed, preexisting.
This is the existing DSA core pattern, shared with tag_dsa, tag_ocelot, tag_sja1105, tag_vsc73xx_8021q and dsa_software_vlan_untag(). dsa_port_bridge_destroy() frees the dsa_bridge without waiting for a grace period, so a tagger cannot fix this locally. The fix belongs in the DSA core.
Quoted 104 lines
[ ... ]
net/dsa/tag_lan9645x.c line 425
Quoted 13 lines
net/dsa/tag_lan9645x.c new file +13
-0+/* Reset skb->data past the actual ethernet header. */ +skb_pull (skb,ETH_HLEN ); + +/* We must deliver the skb so skb->csum only covers the data beyond the +* real ethernet header. The fake ethernet header in the prefix is +* not part of skb->csum already. We must subtract what remains of the +* prefix, the ifh and the gap. The start is derived from the current +* skb->data rather than saved on entry, because the pskb_may_pull() +* calls above may have reallocated skb->head. +*/ +skb_postpull_rcsum (skb, + skb->data -LAN9645X_TOTAL_TAG_LEN - ifh_gap_len, +LAN9645X_TOTAL_TAG_LEN + ifh_gap_len);[Severity: Low]
This isn't a bug, but the comment doesn't list everything the call subtracts.The length is
LAN9645X_TOTAL_TAG_LEN+ifh_gap_len, which is 44 + gap bytes. That is 2 bytes of prefix remainder, plus 28 bytes of IFH, plus the gap, plus the 14 byte real Ethernet header.The code looks right, because
dsa_switch_rcv()doesskb_push(ETH_HLEN)and theneth_type_trans()without adjusting the checksum. Could the comment also mention the real Ethernet header? Otherwise someone might later shorten the length to match the comment.[ ... ]
net/dsa/tag_lan9645x.c line 451
Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3
-0+ dp =dsa_user_to_port (skb->dev); + +if (dsa_port_is_vlan_filtering (dp) && ifh_gap_len) {[Severity: Low]
Can frames lose their VLAN tag whilevlan_filteringis changing?
dsa_port_vlan_filtering()calls the driver op before it updates the software flag:err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering, extack); ... dp->vlan_filtering = vlan_filtering;In this series,
lan9645x_port_vlan_filtering()programsVLAN_POP_CNTright away throughlan9645x_vlan_port_apply(). Frames that the hardware pops in that window reachlan9645x_rcv()withifh_gap_len!= 0 whiledsa_port_is_vlan_filtering(dp)is still false. They are delivered with no tag.The reverse transition has the same problem, including bridge leave via
lan9645x_vlan_set_hostmode(). Frames popped before the change but handled afterdp->vlan_filteringis cleared also lose their tag.
POP_CNTis 0 on non-filtering ports, so the gap is already 0 there. Would checking onlyifh_gap_lenkeep the CPU view consistent with what the hardware did?net/dsa/tag_lan9645x.c line 461
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH +* reports. The classifier recognizes both TPIDs as VLAN tags, +* so an S-tag has already been used for classification by the +* time we get here. Restoring it as 802.1AD would make the +* bridge push it back into the payload and reclassify the frame +* to the port pvid, on a different VID than the one the +* hardware forwarded it on. +*/ +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), vlan_tci); + }[Severity: Medium]
Is the 802.1Q-only assumption enforced anywhere? The commit message says:This assumes a bridge
vlan_protocolof 802.1Q, which is the only protocol the driver offloads.The xmit side of this file does handle non-802.1Q bridges, in
lan9645x_xmit_get_vlan_info():br_vlan_get_proto(br, &proto); ... if (ntohs(hdr->h_vlan_proto) == proto && ntohs(hdr->h_vlan_TCI) & VLAN_VID_MASK) { ... *tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S : LAN9645X_IFH_TAG_TYPE_C;DSA doesn't handle
SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL.__br_vlan_set_proto()sends that attribute withSWITCHDEV_F_SKIP_EOPNOTSUPP, so setting "vlan_protocol802.1ad" on the bridge seems to succeed while the lan9645x ports stay offloaded. The switch driver in this series doesn't appear to check the bridgevlan_protocoleither.On such a bridge, every tag restored here has an
0x8100TPID, and__allowed_ingress()innet/bridge/br_vlan.cthen does:if (skb->vlan_proto != br->vlan_proto) { /* Protocol-mismatch, empty out vlan_tci for new tag */ skb_push(skb, ETH_HLEN); skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto, skb_vlan_tag_get(skb));
Quoted 7 lines
This pushes the tag back into the payload and classifies the frame to the pvid. Wouldn't frames trapped or copied to the CPU then land on the pvid? That is the same misclassification the C-tag normalization is meant to avoid, only in the opposite configuration.
Should rcv follow the bridge
vlan_protocolthe way xmit does? Or should the driver refuse 802.1ad bridges?
The driver does not support 802.1ad bridges, and rcv is only one part of that. The hardware forwarding path does not follow the bridge vlan_protocol. The classifier treats both TPIDs as VLAN tags, and the egress TPID follows the ingress tag type. Restoring the tag with the bridge protocol in rcv would hide one symptom without making 802.1ad work. On xmit the protocol is taken from the bridge because the stack picks the TPID of the frames it sends.
In v15 I will refuse VLAN filtering on a bridge whose vlan_protocol is not 802.1Q. That covers creating or joining a VLAN-aware 802.1ad bridge, but not a later protocol change, since DSA does not propagate SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL.
Quoted 3 lines
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
pw-bot: cr
PATCH v14 2/9 dt-bindings: net: dsa: add Microchip LAN9645x switch
In reply to Jens Emil Schulz ØstergaardAdd bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch. The last digit of the part number is the number of usable front ports and the letter is the feature set.
The switch is a child of an externally controlled parent that hands out one regmap per register target, so reg and reg-names describe the target layout the way mscc,vsc7514-switch.yaml does for the equivalent mscc,vsc7512-switch node. That binding, and the mfd parent it hangs off in mscc,ocelot.yaml, is the model this driver and its parent follow.
---
Changes in v14:
- Use the dt-bindings: net: dsa: subject prefix and do not repeat "bindings" in the subject.
- Describe all switch register targets in reg, and the analyzer and PTP interrupts.
Changes in v13:
- Remove section quoting Documentation/networking/phy.rst from commit message.
- Remove rx/tx-internal-delay-ps from example.
Changes in v12:
- Remove Rob's Reviewed-by
- Match both the port@ and ethernet-port@ spellings, so the per port constraints apply. dsa.yaml accepts either, and the local pattern only matched the long form.
- Allow 0 as well as 2000 for rx/tx-internal-delay-ps, matching what the driver accepts, and restrict them to those two values on RGMII ports.
- Constrain the ethernet-ports node the way renesas,rzn1-a5psw.yaml does, with additionalProperties instead of a local dsa-port.yaml $ref.
- Put the example properties in canonical order, so dt-check-style --mode=strict is clean.
- Describe the switch register targets in reg, with a matching reg-names, following mscc,vsc7514-switch.yaml.
- Document the default of rx/tx-internal-delay-ps, as microchip,lan937x.yaml does.
- Describe the SKU naming in the binding description.
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 | 208 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 209 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +208 -0
@@ -0,0 +1,208 @@ +# 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. + + The part number encodes the SKU. The last digit is the number of usable + front ports, 5, 7 or 9. The letter is the feature set, f for full and s for + standard, where full adds HSR, PRP, TAS, frame preemption and PSFP. + +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: + items: + - description: General configuration block target + - description: + CPU device queue system target, the register based frame injection + and extraction interface + - description: Precision Time Protocol target + - description: Chip top level target + - description: Time aware shaper target + - description: Rewriter target + - description: VCAP ES0 target, egress stage 0 classification + - description: OAM MEP target + - description: VCAP S1 target, ingress stage 1 classification + - description: VCAP S2 target, ingress stage 2 classification + - description: Switching engine target + - description: HSIO target + - description: Port 0 device target + - description: Port 1 device target + - description: Port 2 device target + - description: Port 3 device target + - description: Port 4 device target + - description: Port 5 device target + - description: Port 6 device target + - description: Port 7 device target + - description: Port 8 device target + - description: Queue system target + - description: Automatic frame injector target + - description: Analyzer target + + reg-names: + items: + - const: gcb + - const: qs + - const: ptp + - const: chip_top + - const: tas + - const: rew + - const: vcap0 + - const: mep + - const: vcap1 + - const: vcap2 + - const: sys + - const: hsio + - const: dev0 + - const: dev1 + - const: dev2 + - const: dev3 + - const: dev4 + - const: dev5 + - const: dev6 + - const: dev7 + - const: dev8 + - const: qsys + - const: afi + - const: ana + + interrupts: + items: + - description: PTP timestamp ready interrupt + - description: PTP synchronization interrupt from the PTP pins + - description: Analyzer interrupt + + interrupt-names: + items: + - const: ptp + - const: ptp-ext + - const: ana + + ethernet-ports: + type: object + additionalProperties: true + patternProperties: + "^(ethernet-)?port@[0-8]$": + type: object + description: Ethernet switch ports + additionalProperties: true + + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + +$ref: dsa.yaml#/$defs/ethernet-ports + +required: + - compatible + - reg + - reg-names + - ethernet-ports + +unevaluatedProperties: false + +$defs: + internal-delay-ps: + description: + Disable the delay line using 0 ps, or enable the 2000 ps delay. The + delay line is not tunable, so no other phase can be selected. + enum: [0, 2000] + default: 0 + +examples: + - | + ethernet-switch@4000 { + compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch"; + reg = <0x4000 0x244>, <0x8000 0x4c>, <0xc000 0x1f0>, + <0x10000 0x134>, <0x14000 0x2c8>, <0x18000 0x1910>, + <0x1c000 0x468>, <0x20000 0x1480>, <0x24000 0x468>, + <0x28000 0x468>, <0x2c000 0x12d4>, <0x30000 0xe4>, + <0x38000 0xb8>, <0x3c000 0xb8>, <0x40000 0xb8>, + <0x44000 0xb8>, <0x48000 0xb8>, <0x4c000 0xb8>, + <0x50000 0xb8>, <0x54000 0xb8>, <0x58000 0xb8>, + <0x100000 0xa000>, <0x120000 0x1998>, <0x140000 0x7468>; + reg-names = "gcb", "qs", "ptp", "chip_top", "tas", "rew", "vcap0", + "mep", "vcap1", "vcap2", "sys", "hsio", "dev0", "dev1", + "dev2", "dev3", "dev4", "dev5", "dev6", "dev7", "dev8", + "qsys", "afi", "ana"; + interrupts = <27>, <26>, <17>; + interrupt-names = "ptp", "ptp-ext", "ana"; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + phy-handle = <&cuphy0>; + phy-mode = "gmii"; + }; + + ethernet-port@1 { + reg = <1>; + phy-handle = <&cuphy1>; + phy-mode = "gmii"; + }; + + ethernet-port@2 { + reg = <2>; + phy-handle = <&cuphy2>; + phy-mode = "gmii"; + }; + + ethernet-port@3 { + reg = <3>; + phy-handle = <&cuphy3>; + phy-mode = "gmii"; + }; + + ethernet-port@7 { + reg = <7>; + ethernet = <&cpu_host_port>; + phy-mode = "rgmii"; + + fixed-link { + full-duplex; + pause; + speed = <1000>; + }; + }; + }; + }; +...
MAINTAINERS +1 -0
@@ -17819,6 +17819,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
Re: [PATCH net-next v14 2/9] dt-bindings: net: dsa: add Microchip LAN9645x switch
Quoted 62 lines · Jens Emil Schulz Østergaard
Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch. The last digit of the part number is the number of usable front ports and the letter is the feature set.
The switch is a child of an externally controlled parent that hands out one regmap per register target, so reg and reg-names describe the target layout the way mscc,vsc7514-switch.yaml does for the equivalent mscc,vsc7512-switch node. That binding, and the mfd parent it hangs off in mscc,ocelot.yaml, is the model this driver and its parent follow.
Reviewed-by Steen Hegelund <[email protected]>Signed-off-by Jens Emil Schulz Østergaard <[email protected]>---
Changes in v14:
- Use the dt-bindings: net: dsa: subject prefix and do not repeat "bindings" in the subject.
- Describe all switch register targets in reg, and the analyzer and PTP interrupts.Changes in v13:
- Remove section quotingDocumentation/networking/phy.rstfrom commit message.
- Remove rx/tx-internal-delay-ps from example.Changes in v12:
- Remove Rob's Reviewed-by
- Match both the port@ and ethernet-port@ spellings, so the per port constraints apply.dsa.yamlaccepts either, and the local pattern only matched the long form.
- Allow 0 as well as 2000 for rx/tx-internal-delay-ps, matching what the driver accepts, and restrict them to those two values on RGMII ports.
- Constrain the ethernet-ports node the way renesas,rzn1-a5psw.yaml does, with additionalProperties instead of a localdsa-port.yaml$ref.
- Put the example properties in canonical order, so dt-check-style --mode=strict is clean.
- Describe the switch register targets in reg, with a matching reg-names, following mscc,vsc7514-switch.yaml.
- Document the default of rx/tx-internal-delay-ps, as microchip,lan937x.yaml does.
- Describe the SKU naming in the binding description.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-portChanges 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
Quoted 5 lines
--- .../net/dsa/microchip,lan96455s-switch.yaml | 208 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 209 insertions(+)
[email protected]
AI reviewRe: [PATCH net-next v14 2/9] dt-bindings: net: dsa: add Microchip LAN9645x switch
In reply to Jens Emil Schulz ØstergaardThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In microchip,lan96455s-switch.yaml, the port-level allOf/if (lines 113-128) applies $defs/internal-delay-ps (enum [0, 2000], lines…
- [Low] In microchip,lan96455s-switch.yaml, properties/ethernet-ports (lines 104-111) uses the pattern "^(ethernet-)?port@[0-8]$" but sets…
--
dt-bindings: net: dsa: add Microchip LAN9645x switch
This patch adds a DT binding schema for the Microchip LAN9645x family of DSA switches, with microchip,lan96455s-switch as the fallback compatible. The switch sits under an externally controlled parent, and reg/reg-names describe its register targets in the same way as mscc,vsc7514-switch.yaml. On RGMII ports, rx/tx-internal-delay-ps are limited to 0 or 2000.
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0
-0@@ -0,0 +1,208 @@
[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 108
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +5
-0+ ethernet-ports: + type: object + additionalProperties: true + patternProperties: + "^(ethernet-)?port@[0-8]$":
[Severity: Low]
ethernet-ports has additionalProperties: true. Will nodes such as port@9, port@a or port@10 still pass validation?
The inherited dsa.yaml#/$defs/ethernet-ports matches any hex index:
"^(ethernet-)?port@[0-9a-f]+$":
description: Ethernet switch ports
$ref: dsa-port.yaml#
So these nodes are accepted and checked only against dsa-port.yaml. They also skip the local allOf/if below. For example, phy-mode = "rgmii" with rx-internal-delay-ps = <1500> would validate on port@9, even though the hardware only supports 0 or 2000.
The binding lists only the dev0 to dev8 register targets. An out of range port is therefore caught only at runtime, in dsa_switch_parse_ports_of():
if (reg >= ds->num_ports) {
dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n",
port, reg, ds->num_ports);and the switch probe then fails with -EINVAL.
renesas,rzn1-a5psw.yaml, which this binding copies for the ethernet-ports constraint, has the same gap.
Should the local schema reject port nodes outside 0-8?
Quoted 20 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +20
-0+ type: object + description: Ethernet switch ports + additionalProperties: true + + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps"
[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 146
Quoted 7 lines
+$defs:
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6
-0+ internal-delay-ps: + description: + Disable the delay line using 0 ps, or enable the 2000 ps delay. The + delay line is not tunable, so no other phase can be selected. + enum: [0, 2000] + default: 0
[Severity: Low]
Does this allow combinations that ethernet-controller.yaml says are invalid?
The if block above applies the 0/2000 enum to all of rgmii, rgmii-rxid, rgmii-txid and rgmii-id.
For phy-mode = "rgmii" with 2000 ps, ethernet-controller.yaml says:
# be used to indicate fine tuning performed by the MAC. The values
# expected here are small. A value of 2000ps, i.e 2ns, and a phy-mode
# of 'rgmii' will not be accepted by Reviewers.The description here also calls this a fixed, non-tunable 2 ns delay line, not a fine-tuning value.
For phy-mode = "rgmii-id" (or -rxid/-txid) with 2000 ps on a port with an external PHY, ethernet-controller.yaml says:
# ensure that the PHY does not also implement the same delay. So it
# must modify the phy-mode it passes to the PHY, removing the delay it
# has added. Failure to remove the delay will result in a
# non-functioning link.Later in the series, lan9645x_parse_mac_delay() accepts the value for any RGMII mode without checking it against phy-mode:
if (val != 0 && val != 2000) {lan9645x_rgmii_dll_config() is called from mac_config for any RGMII interface, and it then turns on the MAC delay:
HSIO_DLL_CFG_DLL_ENA_SET(p->rx_internal_delay) |
HSIO_DLL_CFG_DELAY_ENA_SET(p->rx_internal_delay),Nothing changes the interface that phylink passes to the PHY. With rgmii-id, the MAC and the PHY would both add 2 ns. Would that give a non-working RGMII link on ports 7/8 that still passes dtbs_check?
There is in-tree precedent for this pattern. vitesse,vsc73xx.yaml uses a similar enum that allows 2000 on rgmii. The realtek.yaml examples use 2000 with 'rgmii' on fixed-link CPU ports.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
PATCH v14 3/9 net: dsa: lan9645x: add autogenerated register macros
In reply to Jens Emil Schulz ØstergaardAdd 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 v13:
- Add QS:XTR:XTR_GRP_CFG for extraction mode configuration.
Changes in v12:
- Regenerate without the unused AFI target.
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 | 1932 ++++++++++++++++++++ 2 files changed, 1933 insertions(+)
MAINTAINERS +1 -0
@@ -17820,6 +17820,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 +1932 -0
1,932 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v14 4/9 net: dsa: lan9645x: add basic dsa driver for LAN9645X
In reply to Jens Emil Schulz ØstergaardAdd 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.
If port 5 or 6 is declared in DT as a user port, phylink_create() rejects the empty supported_interfaces and dsa_tree_setup_ports() falls back to setting the port up as unused, so the switch still probes. DSA logs an error including the port number. Declared as a CPU port there is no such fallback, and the probe fails, and our driver logs an error including the port number.
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, which also resets the chip before it instantiates its children.
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 v13:
- Only redirect the CPU extraction queues to the NPI port while the NPI port link is up. This avoids queuing CPU frames to the NPI port while its MAC is held in reset.
- Configure CPU extraction group 0 for manual extraction, instead of the default where the VRAP engine owns it, so QSYS_SW_STATUS.EQ_AVAIL of the CPU port module can be polled when flushing it on NPI link up.
Changes in v12:
- Drop lan9645x_port_set_tail_drop_wm(). This tail dropping config is only active under cut through forwarding, which we never enable.
- lan9645x_reset_switch(): skip the memory init when the switch core is already enabled. We expect parent device to reset before probe, but if it does not, we must skip memory init if switch core is already enabled.
- Drop unused shared_queue_sz field and LAN9645X_BUFFER_MEMORY define.
- Set ds->max_num_bridges = 1 next to ds->fdb_isolation. We support a single offloaded bridge, so let the core enforce it.
- Reject an NPI port with no usable interface mode.
- Kconfig: select REGMAP.
- Include the CPU port module in the unicast and multicast flood masks. Host address filtering needs the fdb and mdb operations, and unknown traffic needs port_set_host_flood(), so until bridge support lands the host depends on flooding to receive anything.
- Describe in the commit what happens if port 5 or 6 is declared in DT.
- Drop unused register writes from lan9645x_port_cpu_init().
- Update PGID table comment.
- Drop the unused PGID_AGGR_NUM, LAN9645X_ISDX_MAX, LAN9645X_ESDX_MAX and LAN9645X_SFID_MAX defines, along with PGID_ENTRIES.
- Follow the LAN9645X_IFH_LEN rename in the tag driver.
- Drop ds->dscp_prio_mapping_is_global. It is only consulted after port_add_dscp_prio() or port_del_dscp_prio() succeeds, neither of which this series implements.
- Program QSYS_RES_CFG through lan9645x_wm_enc().
- Return -ENOMEM directly, not via dev_err_probe(), and add the missing newlines to the remaining probe messages.
- lan9645x_npi_port_deinit(): restore the NPI bit in the CPU port module source PGID that lan9645x_npi_port_init() cleared.
- Spell the part LAN9645x in the Kconfig prompt, the help text and MODULE_DESCRIPTION.
- Drop the unread NULL sentinel from lan9645x_resource_names[].
- Resolve the regmap and the register address once in lan9645x_rd_poll_timeout() and lan9645x_rd_poll_slow().
- lan9645x_get_max_mtu(): drop the NPI case. DSA only asks for the user port limit and adds the tag overhead back itself when it sizes the conduit MTU.
- lan9645x_phylink_mac_prepare(): drop the port range check. Ports 5 and 6 get no phylink instance, and ds->num_ports bounds the rest.
- lan9645x_phylink_mac_link_up(): drop the unreachable SPEED_2500 case, and the DEV_CLOCK_CFG.LINK_SPEED fixup it forced. lan9645x_phylink_get_caps() does not advertise MAC_2500FD.
- Fix DEV_MAC_IFG_CFG.TX_IFG, which had its full and half duplex values swapped.
- Drop the unused afi target regmap request.
- Name the first per port regmap dev0 rather than dev, so the nine read uniformly.
- Bound the ANA_PGID_CFG.OBEY_VLAN loop at PGID_AGGR.
- lan9645x_phylink_mac_prepare(): drop the HSIO_HW_CFG.RGMII_0_CFG write. The field resets to DEV7 and nothing else writes it.
- lan9645x_phylink_port_down(): restore QSYS_SW_PORT_MODE.AGING_MODE to 2 after the flush, which is the reset value, rather than 1. Mode 1 exempts frames from the CPU interface from the transmit ageing that lan9645x_setup() enables, and every port sat in it from probe.
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 | 12 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 456 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 348 ++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 116 ++++++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 371 +++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 166 ++++++++ 9 files changed, 1480 insertions(+)
drivers/net/dsa/Kconfig +2 -0
@@ -82,6 +82,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/microchip/lan9645x/Kconfig" + source "drivers/net/dsa/motorcomm/Kconfig" source "drivers/net/dsa/mv88e6xxx/Kconfig"
drivers/net/dsa/microchip/Makefile +1 -0
@@ -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 +12 -0
@@ -0,0 +1,12 @@ +# 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 + select REGMAP + 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
@@ -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 +456 -0
456 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +348 -0
348 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c new file +116 -0
116 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +371 -0
371 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v14 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In lan9645x_phylink_mac_link_up() (drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c),…
- [Low] lan_rd(), lan_wr() and lan_rmw() in lan9645x_main.h discard regmap errors.
- [Low] On RGMII ports, the MAC delay handling ignores phy-mode.
- [Low] Nothing in the tree can bind this driver.
--
net: dsa: lan9645x: add basic dsa driver for LAN9645X
This commit adds a basic DSA driver for the Microchip LAN9645x switch. It covers switch init, named regmaps obtained from a parent device, NPI/CPU/front port setup and phylink MAC configuration. Only the internal CuPHY ports 0-4 and the RGMII ports 7-8 are wired up. The SerDes modes and the MFD parent are left for later series.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,456 @@
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +u32 val =0 ; +int err;
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 112
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ +/* The parent must reset the whole chip before instantiating its +* children, so the switch core is disabled when we get here. The +* sequence below must not run more than once: initializing the +* memories on a running core corrupts pointers inside the queue +* system, which eventually fills up and stops passing traffic. If the +* core is already enabled the chip was not reset, so skip it. +*/ +if (SYS_RESET_CFG_CORE_ENA_GET (lan_rd (lan9645x,SYS_RESET_CFG ))) +return 0 ;
[Severity: Low]
What happens here if the regmap_read() under lan_rd() fails? In lan9645x_main.h, lan_rd() only warns and then returns the value it was initialised with:
u32 addr, val = 0;
...
WARN_ON_ONCE(regmap_read(lan_tgt2rmap(lan9645x, t, tinst), addr, &val));
return val;A failed read would look like CORE_ENA=0. The CORE_ENA=0 / RAM_INIT sequence would then run on a core that may already be enabled. The comment above says that corrupts pointers inside the queue system. The parent is expected to be SPI based, like ocelot-spi, so bus errors can happen.
The RAM_INIT write can't be checked either. lan_wr() returns void, and the self-clearing bit already reads back as 0 if the write was lost.
The same thing happens in two other places:
- lan9645x_set_feat_dis() turns a failed GCB_FEAT_DISABLE read into num_port_dis = 0. That skips the SKU port limit check in lan9645x_setup().
- lan9645x_port_set_maxlen() always returns 0. dsa_user_change_mtu()
therefore raises dev->mtu even when the DEV_MAC_MAXLEN_CFG write
failed.Could lan_rd(), lan_wr() and lan_rmw() pass the regmap error back, at least on these paths?
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +3
-0+ +lan_wr (SYS_RESET_CFG_CORE_ENA_SET (0 ), lan9645x,SYS_RESET_CFG ); +lan_wr (SYS_RAM_INIT_RAM_INIT_SET (1 ), lan9645x,SYS_RAM_INIT );
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +6
-0+static int lan9645x_request_target_regmaps (struct lan9645x *lan9645x) +{ +const char *resource_name; +struct regmap *tgt_map; + +for (int i =0 ; i <NUM_TARGETS ; i++) {
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 329
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ resource_name = lan9645x_resource_names[i]; +if (!resource_name) +continue ; + + tgt_map =dev_get_regmap (lan9645x->dev->parent, resource_name); +if (IS_ERR_OR_NULL (tgt_map)) { +dev_err (lan9645x->dev,"Failed to get regmap=%s\n" , + resource_name); +return -ENODEV ; + }
[Severity: Low]
Does anything in the tree provide these regmaps? lan9645x_request_target_regmaps() needs all 17 named regmaps from dev->parent ("gcb", "qs", ..., "dev0" to "dev8", "qsys", "ana"). If any is missing it returns -ENODEV. Nothing under drivers/mfd refers to lan9645x or lan96455.
The commit message says:
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.
Until that lands, the driver cannot probe on any in-tree configuration. Two things can't be tested in-tree:
- the regmap naming contract with the parent
- the assumption in lan9645x_reset_switch() that the parent has already reset the chip
The ocelot_ext driver cited as precedent was merged together with its drivers/mfd/ocelot-spi.c parent.
Could the parent driver be merged in the same series?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +0
-0@@ -0,0 +1,371 @@
[ ... ]
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +8
-0+static void lan9645x_rgmii_dll_config (struct lan9645x_port *p) +{ +u32 rx_idx, tx_idx; + +/* DLL register layout: +* (N*2): RGMII_N_RX +* (N*2)+1: RGMII_N_TX +*/
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 78
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +10
-0+ rx_idx =RGMII_IDX (p->chip_port) *2 ; + tx_idx =RGMII_IDX (p->chip_port) *2 +1 ; + +/* Enable DLL in RGMII clock paths, deassert DLL reset, and start the +* delay tune FSM. +*/ + lan_rmw(HSIO_DLL_CFG_DLL_CLK_ENA_SET(1) | + HSIO_DLL_CFG_DLL_RST_SET(0) | + HSIO_DLL_CFG_DLL_ENA_SET(p->rx_internal_delay) | + HSIO_DLL_CFG_DELAY_ENA_SET(p->rx_internal_delay),
[Severity: Low]
Should the MAC delay here depend on the RGMII phy-mode? lan9645x_rgmii_dll_config() enables the RX/TX DLL delays based only on the rx-/tx-internal-delay-ps values parsed by lan9645x_parse_mac_delay(). dsa_port_phylink_create() passes the DT phy-mode unchanged to phylink and the PHY.
The binding (microchip,lan96455s-switch.yaml) allows 2000 ps for all four RGMII modes, including rgmii-id. Take port 7 or 8 with an external PHY, phy-mode = "rgmii-id" and rx/tx-internal-delay-ps = <2000>. Both the MAC and the PHY would add 2ns.
ethernet-controller.yaml says:
When the MAC implements the delay, it must
ensure that the PHY does not also implement the same delay. So it must modify the phy-mode it passes to the PHY, removing the delay it has added. Failure to remove the delay will result in a non-functioning link.
It also says:
A value of 2000ps, i.e 2ns, and a phy-mode
of 'rgmii' will not be accepted by Reviewers.
Should the driver reject this combination, or remove the MAC-added delay from the phy-mode it passes to the PHY?
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +7
-0+if (lan9645x_port_is_cuphy (lan9645x, port, interface)) { +lan_rmw (CHIP_TOP_CUPHY_PORT_CFG_GTX_CLK_ENA_SET (gtx_clk), +CHIP_TOP_CUPHY_PORT_CFG_GTX_CLK_ENA , lan9645x, +CHIP_TOP_CUPHY_PORT_CFG (p->chip_port)); + } + + lan_rmw(SYS_PAUSE_CFG_PAUSE_ENA_SET(1),
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 306
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +10
-0+SYS_PAUSE_CFG_PAUSE_ENA , + lan9645x, SYS_PAUSE_CFG(p->chip_port)); + +/* Flow control */ + lan_rmw(SYS_MAC_FC_CFG_FC_LINK_SPEED_SET(fc_spd) | + SYS_MAC_FC_CFG_FC_LATENCY_CFG_SET(0x7) | + SYS_MAC_FC_CFG_ZERO_PAUSE_ENA_SET(1) | + SYS_MAC_FC_CFG_PAUSE_VAL_CFG_SET(0xffff) | + SYS_MAC_FC_CFG_RX_FC_ENA_SET(rx_pause ? 1 : 0) | + SYS_MAC_FC_CFG_TX_FC_ENA_SET(tx_pause ? 1 : 0),
[Severity: Medium]
Can this turn on PAUSE frame transmission on the NPI port? On link up, lan9645x_phylink_mac_link_up() sets PAUSE_ENA to 1 on every port. TX_FC_ENA follows tx_pause, with no exception for lan9645x->npi. lan9645x_npi_port_init() doesn't disable pause on the NPI port either.
The NPI port has the long prefix extraction header enabled:
lan9645x_npi_port_init()
lan_rmw(SYS_PORT_MODE_INCL_XTR_HDR_SET(LAN9645X_TAG_PREFIX_LONG) |
...A PAUSE frame sent on the NPI port would get the prefix and IFH like any other extracted frame, so the conduit would not recognise it as PAUSE. The port would run in lossless mode while the link partner never honours the pause.
The DT example in the lan9645x binding gives the NPI port a fixed-link with pause. MAC_SYM_PAUSE is advertised, so phylink resolves tx_pause = rx_pause = true for the documented example.
mscc/ocelot uses the same NPI model and had this problem. It was fixed by commit 33cb0ff30cff ("net: mscc: ocelot: don't let phylink re-enable TX PAUSE on the NPI port"). That commit measured CPU termination throughput at 271 Mbit/s before the fix and 926 Mbit/s after.
felix_npi_port_init() clears SYS_PAUSE_CFG_PAUSE_ENA on the NPI port, and ocelot_phylink_mac_link_up() does:
/* Don't attempt to send PAUSE frames on the NPI port, it's broken */
if (port != ocelot->npi)
ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA,
tx_pause);This also seems to still be the case at the end of the series.
Should PAUSE_ENA and TX_FC_ENA stay at 0 for lan9645x->npi? And should PAUSE_ENA follow tx_pause on the other ports?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Quoted 247 lines · On Mon, 2026-10-12 at 11:24 +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 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] In
lan9645x_phylink_mac_link_up()(drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c),…
- [Low]lan_rd(),lan_wr()andlan_rmw()inlan9645x_main.hdiscard regmap errors.
- [Low] On RGMII ports, the MAC delay handling ignores phy-mode.
- [Low] Nothing in the tree can bind this driver.--
net: dsa: lan9645x: add basic dsa driver for LAN9645X
This commit adds a basic DSA driver for the Microchip LAN9645x switch. It covers switch init, named regmaps obtained from a parent device, NPI/CPU/front port setup and phylink MAC configuration. Only the internal CuPHY ports 0-4 and the RGMII ports 7-8 are wired up. The SerDes modes and the MFD parent are left for later series.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,456 @@[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +u32 val =0 ; +int err;drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 112
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ +/* The parent must reset the whole chip before instantiating its +* children, so the switch core is disabled when we get here. The +* sequence below must not run more than once: initializing the +* memories on a running core corrupts pointers inside the queue +* system, which eventually fills up and stops passing traffic. If the +* core is already enabled the chip was not reset, so skip it. +*/ +if (SYS_RESET_CFG_CORE_ENA_GET (lan_rd (lan9645x,SYS_RESET_CFG ))) +return 0 ;[Severity: Low]
What happens here if theregmap_read()underlan_rd()fails? Inlan9645x_main.h,lan_rd()only warns and then returns the value it was initialised with:u32 addr, val = 0; ... WARN_ON_ONCE(regmap_read(lan_tgt2rmap(lan9645x, t, tinst), addr, &val)); return val;A failed read would look like CORE_ENA=0. The CORE_ENA=0 /
RAM_INITsequence would then run on a core that may already be enabled. The comment above says that corrupts pointers inside the queue system. The parent is expected to be SPI based, like ocelot-spi, so bus errors can happen.The
RAM_INITwrite can't be checked either.lan_wr()returns void, and the self-clearing bit already reads back as 0 if the write was lost.The same thing happens in two other places:
-
lan9645x_set_feat_dis()turns a failedGCB_FEAT_DISABLEread intonum_port_dis= 0. That skips the SKU port limit check inlan9645x_setup().-
lan9645x_port_set_maxlen()always returns 0.dsa_user_change_mtu()therefore raises dev->mtu even when the DEV_MAC_MAXLEN_CFG write failed.Could
lan_rd(),lan_wr()andlan_rmw()pass the regmap error back, at least on these paths?Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +3
-0+ +lan_wr (SYS_RESET_CFG_CORE_ENA_SET (0 ), lan9645x,SYS_RESET_CFG ); +lan_wr (SYS_RAM_INIT_RAM_INIT_SET (1 ), lan9645x,SYS_RAM_INIT );[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +6
-0+static int lan9645x_request_target_regmaps (struct lan9645x *lan9645x) +{ +const char *resource_name; +struct regmap *tgt_map; + +for (int i =0 ; i <NUM_TARGETS ; i++) {drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 329
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ resource_name = lan9645x_resource_names[i]; +if (!resource_name) +continue ; + + tgt_map =dev_get_regmap (lan9645x->dev->parent, resource_name); +if (IS_ERR_OR_NULL (tgt_map)) { +dev_err (lan9645x->dev,"Failed to get regmap=%s\n" , + resource_name); +return -ENODEV ; + }[Severity: Low]
Does anything in the tree provide these regmaps?lan9645x_request_target_regmaps()needs all 17 named regmaps fromdev->parent("gcb", "qs", ..., "dev0" to "dev8", "qsys", "ana"). If any is missing it returns-ENODEV. Nothing underdrivers/mfdrefers to lan9645x or lan96455.The commit message says:
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.
Until that lands, the driver cannot probe on any in-tree configuration. Two things can't be tested in-tree:
- the regmap naming contract with the parent
- the assumption in
lan9645x_reset_switch()that the parent has already reset the chipThe
ocelot_extdriver cited as precedent was merged together with itsdrivers/mfd/ocelot-spi.cparent.Could the parent driver be merged in the same series?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +0
-0@@ -0,0 +1,371 @@[ ... ]
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +8
-0+static void lan9645x_rgmii_dll_config (struct lan9645x_port *p) +{ +u32 rx_idx, tx_idx; + +/* DLL register layout: +* (N*2): RGMII_N_RX +* (N*2)+1: RGMII_N_TX +*/ drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 78
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +10
-0+ rx_idx =RGMII_IDX (p->chip_port) *2 ; + tx_idx =RGMII_IDX (p->chip_port) *2 +1 ; + +/* Enable DLL in RGMII clock paths, deassert DLL reset, and start the +* delay tune FSM. +*/ + lan_rmw(HSIO_DLL_CFG_DLL_CLK_ENA_SET(1) | + HSIO_DLL_CFG_DLL_RST_SET(0) | + HSIO_DLL_CFG_DLL_ENA_SET(p->rx_internal_delay) | + HSIO_DLL_CFG_DELAY_ENA_SET(p->rx_internal_delay),[Severity: Low]
Should the MAC delay here depend on the RGMII phy-mode?lan9645x_rgmii_dll_config()enables the RX/TX DLL delays based only on the rx-/tx-internal-delay-ps values parsed bylan9645x_parse_mac_delay().dsa_port_phylink_create()passes the DT phy-mode unchanged to phylink and the PHY.The binding (microchip,lan96455s-switch.yaml) allows 2000 ps for all four RGMII modes, including rgmii-id. Take port 7 or 8 with an external PHY, phy-mode = "rgmii-id" and rx/tx-internal-delay-ps = <2000>. Both the MAC and the PHY would add 2ns.
ethernet-controller.yamlsays:When the MAC implements the delay, it must
ensure that the PHY does not also implement the same delay. So it must modify the phy-mode it passes to the PHY, removing the delay it has added. Failure to remove the delay will result in a non-functioning link.It also says:
A value of 2000ps, i.e 2ns, and a phy-mode
of 'rgmii' will not be accepted by Reviewers.Should the driver reject this combination, or remove the MAC-added delay from the phy-mode it passes to the PHY?
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +7
-0+if (lan9645x_port_is_cuphy (lan9645x, port, interface)) { +lan_rmw (CHIP_TOP_CUPHY_PORT_CFG_GTX_CLK_ENA_SET (gtx_clk), +CHIP_TOP_CUPHY_PORT_CFG_GTX_CLK_ENA , lan9645x, +CHIP_TOP_CUPHY_PORT_CFG (p->chip_port)); + } + + lan_rmw(SYS_PAUSE_CFG_PAUSE_ENA_SET(1),drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 306
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +10
-0+SYS_PAUSE_CFG_PAUSE_ENA , + lan9645x, SYS_PAUSE_CFG(p->chip_port)); + +/* Flow control */ + lan_rmw(SYS_MAC_FC_CFG_FC_LINK_SPEED_SET(fc_spd) | + SYS_MAC_FC_CFG_FC_LATENCY_CFG_SET(0x7) | + SYS_MAC_FC_CFG_ZERO_PAUSE_ENA_SET(1) | + SYS_MAC_FC_CFG_PAUSE_VAL_CFG_SET(0xffff) | + SYS_MAC_FC_CFG_RX_FC_ENA_SET(rx_pause ? 1 : 0) | + SYS_MAC_FC_CFG_TX_FC_ENA_SET(tx_pause ? 1 : 0),[Severity: Medium]
Can this turn on PAUSE frame transmission on the NPI port? On link up,lan9645x_phylink_mac_link_up()setsPAUSE_ENAto 1 on every port.TX_FC_ENAfollowstx_pause, with no exception forlan9645x->npi.lan9645x_npi_port_init()doesn't disable pause on the NPI port either.The NPI port has the long prefix extraction header enabled:
lan9645x_npi_port_init()lan_rmw(SYS_PORT_MODE_INCL_XTR_HDR_SET(LAN9645X_TAG_PREFIX_LONG) | ...A PAUSE frame sent on the NPI port would get the prefix and IFH like any other extracted frame, so the conduit would not recognise it as PAUSE. The port would run in lossless mode while the link partner never honours the pause.
The DT example in the lan9645x binding gives the NPI port a fixed-link with pause.
MAC_SYM_PAUSEis advertised, so phylink resolvestx_pause=rx_pause= true for the documented example.mscc/ocelot uses the same NPI model and had this problem. It was fixed by commit
33cb0ff30cff("net: mscc: ocelot: don't let phylink re-enable TX PAUSE on the NPI port"). That commit measured CPU termination throughput at 271 Mbit/s before the fix and 926 Mbit/s after.
felix_npi_port_init()clearsSYS_PAUSE_CFG_PAUSE_ENAon the NPI port, andocelot_phylink_mac_link_up()does:/* Don't attempt to send PAUSE frames on the NPI port, it's broken */ if (port != ocelot->npi) ocelot_fields_write(ocelot, port, SYS_PAUSE_CFG_PAUSE_ENA, tx_pause);
Quoted 4 lines
This also seems to still be the case at the end of the series.
Should
PAUSE_ENAandTX_FC_ENAstay at 0 forlan9645x->npi? And shouldPAUSE_ENAfollowtx_pauseon the other ports?
Dismissed, false positive.
In this respect, the chip functions differently from ocelot. The issue has been fixed. On lan9645x the MAC formats and transmits PAUSE frames itself, after the queue system, so INCL_XTR_HDR does not apply to them and they leave the NPI port without the prefix and IFH. Flow control on the NPI port works as intended.
PAUSE_ENA only enables the pause request from the queue system to the MAC. TX_FC_ENA decides whether the MAC turns it into PAUSE frames, and RX_FC_ENA is handled by the MAC on its own. With tx_pause off no PAUSE frames are sent and the port tail drops as usual.
Quoted 5 lines
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
PATCH v14 5/9 net: dsa: lan9645x: add vlan support
In reply to Jens Emil Schulz ØstergaardAdd 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).
The VLAN table and the per port VLAN configuration are serialized with fwd_domain_lock, since .port_setup runs without rtnl held.
There are two chip limitations. Only one egress-untagged VLAN is supported on a port that also has tagged VLANs. The rewriter can exempt a single PORT_VID from tagging, so adding a second untagged VLAN alongside tagged ones is rejected with -EBUSY.
Both TPIDs are recognized as VLAN tags unconditionally. There is no per port control to classify one TPID as tagged while treating the other as untagged customer data.
Only bridge vlan_protocol 802.1Q is offloaded. DSA does not pass SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL to drivers, so an 802.1ad bridge cannot be refused, and the classifier does not honour it.
S-tag and C-tag are always treated as interchangeable. Full C-component conformance would need S-tagged frames treated as untagged by a VLAN aware bridge, dropped on a port without a pvid and classified to the pvid on a port with one.
Of those, only the drop is expressible, through ANA_DROP_CFG.DROP_S_TAGGED_ENA. The reclassification needs the VCAP to match on tag type and overwrite the classified VID, see ocelot_update_vlan_reclassify_rule().
We program neither, since dropping without reclassifying is less consistent than treating both tag types alike.
---
Changes in v14:
- Use TAG_NO_UNAWARE instead of TAG_ALL on ports with only tagged VLANs, so frames injected with classified VID 0 are not tagged.
Changes in v12:
- Serialize the VLAN table with fwd_domain_lock, and assert it in the lan9645x_vlan.c entry points. .port_setup runs outside rtnl, so a registered user port can be bridged while a later port is still being set up.
- Move this patch before bridge support. It now carries bridge_mask, fwd_domain_lock and lan9645x_port_is_bridged().
- Move lan9645x_vlan_clear_hostmode() to the bridge patch, together with its only caller.
- Describe the untagged VLAN limit, and why S-tag and C-tag are treated as interchangeable.
- Say that only bridge vlan_protocol 802.1Q is offloaded.
- lan9645x_teardown(): destroy fwd_domain_lock before the NPI port deinit, so teardown unwinds in reverse order of setup.
- Drop the six unused lan9645x_vlan bitfields.
- Spell VLAN in upper case in the two dev_err() strings.
- Split the extack in lan9645x_vlan_port_add_vlan(). The condition also fires when a tagged VLAN is added to a port with several untagged ones, where there is no native VLAN to report.
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 | 69 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 32 ++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 6 + drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 402 +++++++++++++++++++++ 5 files changed, 510 insertions(+)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -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 +69 -0
99 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +32 -0
@@ -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>
@@ -171,6 +172,11 @@ 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 */ +}; +struct lan9645x {struct device *dev;struct dsa_switch *ds;
@@ -182,7 +188,15 @@ struct lan9645x {u8 num_phys_ports;struct lan9645x_port **ports; +/* Forwarding Database */ +u16 bridge_mask;/* Mask for bridged ports */ +/* lock forwarding configuration and vlan table */ +struct mutex fwd_domain_lock; +int num_port_dis; + +/* VLAN entries */ +struct lan9645x_vlan vlans[VLAN_N_VID ]; };struct lan9645x_port {
@@ -190,6 +204,9 @@ struct lan9645x_port {u8 chip_port; +bool vlan_aware; +u16 pvid; +bool rx_internal_delay;bool tx_internal_delay; };
@@ -238,6 +255,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->lan9645x->bridge_mask &BIT (p->chip_port); +} +static inline struct regmap *lan_tgt2rmap (struct lan9645x *lan9645x,enum lan9645x_target t,int tinst) {
@@ -345,4 +367,14 @@ 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); +#endif /* __LAN9645X_MAIN_H__ */
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +6 -0
@@ -162,5 +162,11 @@ 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) { +mutex_lock (&lan9645x->fwd_domain_lock); +lan9645x_vlan_set_hostmode (p); +mutex_unlock (&lan9645x->fwd_domain_lock); + } +return 0 ; }
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +402 -0
402 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v14 5/9] net: dsa: lan9645x: add vlan support
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message says "DSA does not pass SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL to drivers, so an 802.1ad…
- [Low] Concern: the commit message promises VLAN support for VLAN-aware and VLAN-unaware bridges, but at this commit no .port_bridge_join…
- [Low] Concern: runtime VLAN table writes ignore lan9645x_vlan_hw_wr() failures.
--
net: dsa: lan9645x: add vlan support
This patch adds VLAN support to the lan9645x DSA driver. HOST_PVID (4095) is the port VLAN for standalone ports and UNAWARE_PVID (0) is the port VLAN for VLAN-unaware bridge ports. The VLAN table and the per-port VLAN state are serialized with fwd_domain_lock.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0
[ ... ]
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0@@ -296,6 +307,59 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,lan9645x_phylink_get_caps (ds->priv, port, config); } +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;
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 325
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +/* DSA core does not call this for the CPU port */ + p =lan9645x_to_port (lan9645x, port); +mutex_lock (&lan9645x->fwd_domain_lock); + p->vlan_aware = enabled; +lan9645x_vlan_port_apply (p); +mutex_unlock (&lan9645x->fwd_domain_lock); + +return 0 ; +}
[Severity: Medium]
The commit message says:
"Only bridge vlan_protocol 802.1Q is offloaded. DSA does not pass SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL to drivers, so an 802.1ad bridge cannot be refused, and the classifier does not honour it."
Is "cannot be refused" accurate? dsa_port_vlan_filtering() in net/dsa/port.c passes the driver's error back to the bridge:
err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering,
extack);
if (err)
return err;Could lan9645x_port_vlan_filtering() call br_vlan_get_proto() on the port's bridge and refuse with an extack when the result is not ETH_P_8021Q?
That would cover two cases: turning on vlan_filtering on an 802.1ad bridge, and joining an 802.1ad bridge that already filters, because the join path syncs vlan_filtering through the same callback. Only a vlan_protocol change on a bridge that is already filtering would still get through.
As written, an 802.1ad VLAN-aware bridge is offloaded silently with 802.1Q semantics. lan9645x_vlan_port_apply_ingress() always marks untagged frames as C-tag:
val = ANA_VLAN_CFG_VLAN_VID_SET(pvid) |
ANA_VLAN_CFG_VLAN_TAG_TYPE_SET(0);
With TAG_TPID_CFG=3, those frames would egress tagged with 0x8100, not 0x88a8. C-tagged frames would be classified by their C-VID, not by the pvid.
The tagger already reads br_vlan_get_proto() in lan9645x_xmit_get_vlan_info() in net/dsa/tag_lan9645x.c:
*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S :
LAN9645X_IFH_TAG_TYPE_C;So on such a bridge, would the CPU injection path and the switch datapath disagree? The later "net: dsa: lan9645x: add bridge support" patch also leaves lan9645x_port_vlan_filtering() unchanged.
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +0
-0
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h static inline struct lan9645x_port *lan9645x_to_port(struct lan9645x *lan9645x, · line 261
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +4
-0@@ -238,6 +255,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->lan9645x->bridge_mask &BIT (p->chip_port); +}
[Severity: Low]
This isn't a bug, but at this commit nothing writes bridge_mask and there is no .port_bridge_join, so lan9645x_port_is_bridged() always returns false. The bridged branches in lan9645x_vlan_port_get_pvid() and lan9645x_vlan_port_apply_egress() can't be reached until the later "net:
dsa: lan9645x: add bridge support" patch adds lan9645x_port_bridge_join().
Standalone ports look fine in the meantime. HOST_PVID contains all ports and the CPU, so enabling ANA_VLANMASK drops nothing.
Could the commit message line "Add VLAN support for VLAN-aware and VLAN-unaware bridges." say that the bridged paths only become active with the bridge support patch?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0
-0@@ -0,0 +1,402 @@
[ ... ]
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) +{
[ ... ]
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8
-0+if (p->chip_port == lan9645x->npi) +return lan9645x_vlan_cpu_add (p, vid); + + old_vlan = lan9645x->vlans[vid]; + old_pvid = p->pvid; + + v =lan9645x_vlan_port_modify (p, vid, pvid, untagged); + v->portmask |=BIT (p->chip_port);
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 303
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +6
-0+lan9645x_vlan_hw_wr (lan9645x, vid); +lan9645x_vlan_port_apply_ingress (p); +lan9645x_vlan_port_apply_egress (p, &info); + +return 0 ; +}
[Severity: Low]
The return value of lan9645x_vlan_hw_wr() is dropped here. The same happens in lan9645x_vlan_cpu_add(), lan9645x_vlan_cpu_del(), lan9645x_vlan_port_del_vlan() and lan9645x_vlan_set_hostmode(). In each case vlans[vid] is updated and 0 is returned even if the table write timed out.
The comment in lan9645x_vlan_hw_wr() says this is intentional: a timeout most likely means the register bus is dead. Also, the next write for the same VID rewrites the whole entry from the shadow portmask.
If the parent regmap bus can have transient errors, though, would it be better to return the error and restore the old shadow state, as ocelot_vlan_member_add() does? That would keep DSA's refcounted CPU port VLAN state in sync with the hardware.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 5/9] net: dsa: lan9645x: add vlan support
Quoted 96 lines · On Mon, 2026-10-12 at 11:24 +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 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message says "DSA does not pass
SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOLto drivers, so an 802.1ad…
- [Low] Concern: the commit message promises VLAN support for VLAN-aware and VLAN-unaware bridges, but at this commit no .port_bridge_join…
- [Low] Concern: runtime VLAN table writes ignorelan9645x_vlan_hw_wr()failures.--
net: dsa: lan9645x: add vlan support
This patch adds VLAN support to the lan9645x DSA driver.
HOST_PVID(4095) is the port VLAN for standalone ports andUNAWARE_PVID(0) is the port VLAN for VLAN-unaware bridge ports. The VLAN table and the per-port VLAN state are serialized withfwd_domain_lock.Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0@@ -296,6 +307,59 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,lan9645x_phylink_get_caps (ds->priv, port, config); } +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;drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 325
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +/* DSA core does not call this for the CPU port */ + p =lan9645x_to_port (lan9645x, port); +mutex_lock (&lan9645x->fwd_domain_lock); + p->vlan_aware = enabled; +lan9645x_vlan_port_apply (p); +mutex_unlock (&lan9645x->fwd_domain_lock); + +return 0 ; +}[Severity: Medium]
The commit message says:"Only bridge
vlan_protocol802.1Q is offloaded. DSA does not passSWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOLto drivers, so an 802.1ad bridge cannot be refused, and the classifier does not honour it."Is "cannot be refused" accurate?
dsa_port_vlan_filtering()innet/dsa/port.cpasses the driver's error back to the bridge:err = ds->ops->port_vlan_filtering(ds, dp->index, vlan_filtering, extack); if (err) return err;Could
lan9645x_port_vlan_filtering()callbr_vlan_get_proto()on the port's bridge and refuse with an extack when the result is notETH_P_8021Q?That would cover two cases: turning on
vlan_filteringon an 802.1ad bridge, and joining an 802.1ad bridge that already filters, because the join path syncsvlan_filteringthrough the same callback. Only avlan_protocolchange on a bridge that is already filtering would still get through.As written, an 802.1ad VLAN-aware bridge is offloaded silently with 802.1Q semantics.
lan9645x_vlan_port_apply_ingress()always marks untagged frames as C-tag:val =
ANA_VLAN_CFG_VLAN_VID_SET(pvid)|
ANA_VLAN_CFG_VLAN_TAG_TYPE_SET(0);With TAG_TPID_CFG=3, those frames would egress tagged with
0x8100, not0x88a8. C-tagged frames would be classified by their C-VID, not by the pvid.The tagger already reads
br_vlan_get_proto()inlan9645x_xmit_get_vlan_info()innet/dsa/tag_lan9645x.c:
Quoted 6 lines
*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S : LAN9645X_IFH_TAG_TYPE_C;So on such a bridge, would the CPU injection path and the switch datapath disagree? The later "net: dsa: lan9645x: add bridge support" patch also leaves
lan9645x_port_vlan_filtering()unchanged.
Right, the next version refuses enabling VLAN filtering in port_vlan_filtering() when the bridge vlan_protocol is not 802.1Q, which also covers joining a VLAN-aware 802.1ad bridge. That leaves the remaining case of a vlan_protocol change on a bridge that already filters. This is not handled since DSA does not pass SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL.
Quoted 88 lines
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +0
-0[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h static inline struct lan9645x_port *lan9645x_to_port(struct lan9645x *lan9645x, · line 261
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +4
-0@@ -238,6 +255,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->lan9645x->bridge_mask &BIT (p->chip_port); +}[Severity: Low]
This isn't a bug, but at this commit nothing writesbridge_maskand there is no .port_bridge_join, solan9645x_port_is_bridged()always returns false. The bridged branches inlan9645x_vlan_port_get_pvid()andlan9645x_vlan_port_apply_egress()can't be reached until the later "net:
dsa: lan9645x: add bridge support" patch addslan9645x_port_bridge_join().Standalone ports look fine in the meantime.
HOST_PVIDcontains all ports and the CPU, so enablingANA_VLANMASKdrops nothing.Could the commit message line "Add VLAN support for VLAN-aware and VLAN-unaware bridges." say that the bridged paths only become active with the bridge support patch?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0
-0@@ -0,0 +1,402 @@[ ... ]
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) +{[ ... ]
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8
-0+if (p->chip_port == lan9645x->npi) +return lan9645x_vlan_cpu_add (p, vid); + + old_vlan = lan9645x->vlans[vid]; + old_pvid = p->pvid; + + v =lan9645x_vlan_port_modify (p, vid, pvid, untagged); + v->portmask |=BIT (p->chip_port);[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 303
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +6
-0+lan9645x_vlan_hw_wr (lan9645x, vid); +lan9645x_vlan_port_apply_ingress (p); +lan9645x_vlan_port_apply_egress (p, &info); + +return 0 ; +}[Severity: Low]
The return value oflan9645x_vlan_hw_wr()is dropped here. The same happens inlan9645x_vlan_cpu_add(),lan9645x_vlan_cpu_del(),lan9645x_vlan_port_del_vlan()andlan9645x_vlan_set_hostmode(). In each case vlans[vid] is updated and 0 is returned even if the table write timed out.The comment in
lan9645x_vlan_hw_wr()says this is intentional: a timeout most likely means the register bus is dead. Also, the next write for the same VID rewrites the whole entry from the shadow portmask.If the parent regmap bus can have transient errors, though, would it be better to return the error and restore the old shadow state, as
ocelot_vlan_member_add()does? That would keep DSA's refcounted CPU port VLAN state in sync with the hardware.[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
PATCH v14 6/9 net: dsa: lan9645x: add mac table integration
In reply to Jens Emil Schulz ØstergaardAdd MAC table support, and dsa fdb callback integration. The mactable is keyed on (vid,mac) and each row has 4 buckets. 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 is 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 v14:
- Only forget a CPU port host entry when no other database still uses the same MAC table key, including databases of a different type.
Changes in v12:
- Log a failure from lan9645x_mact_flush() in port_fast_age(), which returns void and cannot propagate it.
- Fix a comment to name PGID_CPU rather than the CPU port module.
- Move this patch before bridge support, so .port_fast_age exists when port_stp_state_set() is introduced.
- Give lan9645x_mact_learn() a cpu_copy argument, and drop lan9645x_mac_ports_use_cpu() and the wrapper that used it to derive the flag from the encoded mac. The helper could only return false, since its one caller passes ENTRYTYPE_LOCKED, and the mdb path needs the flag passed in rather than derived.
- Bound the CMD_GET_NEXT walk in lan9645x_mact_dsa_dump() at the mac table size plus one, derived from ANA_MACTINDX. Log and return -EIO on overrun.
- lan9645x_mact_dsa_dump(): leave automatic ageing enabled during the GET_NEXT walk, as it does not disturb the walk, and toggling ageing resets the timer.
- lan9645x_teardown(): deinit the mac table before fwd_domain_lock.
- Spell the mac argument as mac[ETH_ALEN] and the vid as unsigned int.
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 | 268 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 123 ++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 27 +++ 4 files changed, 419 insertions(+)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -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 +268 -0
268 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +123 -0
147 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +27 -0
@@ -177,6 +177,19 @@ struct lan9645x_vlan { untagged:9 ;/* ports 0-8 */ }; +/* 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;
@@ -192,6 +205,7 @@ struct lan9645x {u16 bridge_mask;/* Mask for bridged ports */ /* lock forwarding configuration and vlan table */ struct mutex fwd_domain_lock; +struct mutex mact_lock;/* serialize mac table register access */ int num_port_dis;
@@ -377,4 +391,17 @@ int lan9645x_vlan_port_add_vlan(struct lan9645x_port *p, u16 vid, bool pvid,int lan9645x_vlan_port_del_vlan (struct lan9645x_port *p,u16 vid);void lan9645x_vlan_set_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 mac[ETH_ALEN ],unsigned int vid, +enum macaccess_entry_type type,bool cpu_copy); +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
PATCH v14 7/9 net: dsa: lan9645x: add mdb management
In reply to Jens Emil Schulz ØstergaardAdd 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 at a PGID, whose destination mask is the port group.
CPU port module membership is carried by the mac table entry's MAC_CPU_COPY bit rather than by the PGID destination mask. This differs from mscc/ocelot, which keeps the CPU port module bit inside the PGID mask, and it lets groups that differ only in host membership share a PGID.
The PGID table is finite, so it is possible to exhaust it and be unable to service an L2 MC mdb request. The two directions then behave differently on purpose.
On add we report the error and leave the group forwarding to the port group it already had, so the caller learns the port was not joined and the existing members are undisturbed.
On delete we always report success. Reporting a failure has negative effects. The switchdev_port_obj_del_deferred() path only logs the error, while br_switchdev_mdb_replay() abandons the remaining entries after the first failure, so failing one delete during a bridge leave would leave the other groups programmed. The group falls back to forwarding according to the flood masks and host membership instead.
A group on the flood masks keeps accepting adds, from front ports and the CPU port module alike, so that the host can still join it. The new members also forward according to the flood masks, until an add or delete finds a PGID for the group again.
IGMP and MLD frames are redirected to the CPU, and IPv4 multicast control frames are copied to it, so that the bridge can snoop them.
---
Changes in v14:
- Keep the PGID reference when a mac table write fails while widening a group, so the index cannot be reused while hardware may point at it.
- Drop the reference a failed narrow write kept when the old and new PGID are the same.
- Keep a CPU port host entry while a host group in another DSA database maps to the same mac table entry. This replaces the dsa_mdb_present_in_other_db() check, which only covered databases of the same type.
Changes in v12:
- Move this patch before bridge support.
- lan9645x_teardown(): deinit the mdb before the mac table, so teardown unwinds in reverse order of init.
- Move the IGMP, MLD and IPMC CPU queue configuration from lan9645x_mdb_init() to lan9645x_setup(), next to the other CPUQ setup.
- __lan9645x_mdb_del(): do not bail out when no PGID is free. If the entry owns its PGID outright, narrow the port mask in place. Otherwise fall back to the L2 MC flood mask.
- Split lan9645x_mdb_update_dest() into lan9645x_mdb_widen_dest() for the add direction and lan9645x_mdb_narrow_dest() for the delete direction. The bridge reads the return value of a .port_mdb_add but not of a .port_mdb_del, so the two need opposite error handling.
- __lan9645x_mdb_add(): let a group already on the flood mask absorb membership changes, so the host can still join it.
- Note that IGMP and MLD are redirected to the CPU and IPv4 multicast control frames copied, so the bridge can snoop them.
- __lan9645x_mdb_del(): log a failing CMD_FORGET but drop the software entry anyway. The bridge never repeats a delete, so a kept entry would be wedged.
- Issue a CMD_FORGET before discarding a freshly allocated mdb entry whose CMD_LEARN reported an error, so a bus failure between the command and the status read cannot leave an unreachable entry behind in hardware.
- Use GPL-2.0+ in the SPDX identifier, matching the rest of the driver.
- Assert mdb_lock in every helper that walks the mdb or pgid lists.
- Replace the PGID_INDEX() macro with lan9645x_pgid_idx().
- Spell the mac argument as mac[ETH_ALEN] and the vid as unsigned int.
- Keep the PGID reference when a mac table write fails, both in lan9645x_mdb_narrow_dest() and when the CMD_FORGET fails for the last port leaving a group, so the index cannot be handed to an unrelated group while hardware may still point at it.
- lan9645x_mdb_deinit(): drain pgid_entries, which can now outlive every mdb entry.
- Note why the delete side reports success. One switchdev path ignores the error and br_switchdev_mdb_replay() truncates on it.
- Classify IPv4 multicast on the 01:00:5E prefix alone rather than with ether_addr_is_ipv4_mcast().
- Name the DSA ops lan9645x_port_mdb_add()/_del() after the .port_mdb_add hooks, rename the lan9645x_mdb.c entry points to lan9645x_mdb_add()/_del(), and fold the mdb_lock wrappers into them. The two files previously defined the same names at different levels of the same call chain.
- lan9645x_mdb_pgid_entry_get(): drop the unreachable !ports test, so a NULL return means an IP entry and nothing else.
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_main.c | 74 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 18 + drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 582 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 8 + 5 files changed, 683 insertions(+)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -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_main.c +74 -0
104 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +18 -0
@@ -207,6 +207,14 @@ struct lan9645x {struct mutex fwd_domain_lock;struct mutex mact_lock;/* serialize mac table register access */ +/* 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;/* VLAN entries */
@@ -404,4 +412,14 @@ 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); +/* Multicast Database lan9645x_mdb.c */ +int lan9645x_mdb_add (struct lan9645x *lan9645x,int port, +const struct switchdev_obj_port_mdb *mdb, +struct net_device *bridge); +int lan9645x_mdb_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 +582 -0
582 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +8 -0
@@ -166,6 +166,14 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)mutex_lock (&lan9645x->fwd_domain_lock);lan9645x_vlan_set_hostmode (p);mutex_unlock (&lan9645x->fwd_domain_lock); + +lan_rmw (ANA_CPU_FWD_CFG_IGMP_REDIR_ENA_SET (1 ) | +ANA_CPU_FWD_CFG_MLD_REDIR_ENA_SET (1 ) | +ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA_SET (1 ), +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
[email protected]
AI reviewRe: [PATCH net-next v14 7/9] net: dsa: lan9645x: add mdb management
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Separate IP multicast groups that map to the same multicast MAC collapse into one per-port bit, so leaving one group removes…
- [Medium] Several error paths deliberately keep a PGID reference, but nothing owns it afterwards and it is only freed in…
- [Low] A comment in lan9645x_setup() (drivers/net/dsa/microchip/lan9645x/lan9645x_main.c, lines 210-214,…
- [Low] PGID destination-mask writes in lan9645x_pgid_entry_alloc() and in the overwrite-in-place branch of __lan9645x_mdb_del() go through…
--
net: dsa: lan9645x: add mdb management
This patch adds .port_mdb_add and .port_mdb_del support to the lan9645x DSA driver. IP multicast entries store the port mask inline in the mac table entry. L2 multicast entries point at a refcounted PGID, and CPU membership is carried by MAC_CPU_COPY. The patch also redirects IGMP and MLD to the CPU and copies IPv4 multicast control frames to it.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0
[ ... ]
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1
-0@@ -253,6 +255,17 @@ static int lan9645x_setup(struct dsa_switch *ds) lan9645x, ANA_CPUQ_8021_CFG(i)); } +/* Use CPU queues to communicate frame classification to the CPU */
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 268
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+lan_rmw (ANA_CPUQ_CFG_CPUQ_MAC_COPY_SET (LAN9645X_CPUQ_DEF ) | +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_MAC_COPY | +ANA_CPUQ_CFG_CPUQ_IGMP | +ANA_CPUQ_CFG_CPUQ_MLD | +ANA_CPUQ_CFG_CPUQ_IPMC_CTRL , + lan9645x,ANA_CPUQ_CFG ); +
[Severity: Low]
Is the comment above the ANA_FLOODING_IPMC write in lan9645x_setup() still accurate after this change?
lan9645x_setup() {
...
/* Setup flooding PGIDs for IPv4/IPv6 multicast. Control and dataplane
* use the same masks. Control frames are redirected to CPU, and
* the network stack is responsible for forwarding these.
...
}This patch copies IPv4 multicast control frames to the CPU instead of redirecting them. lan9645x_port_setup() sets ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA, and IPMC_CTRL is mapped to LAN9645X_CPUQ_COPY here.
lan9645x_offload_fwd_mark() in net/dsa/tag_lan9645x.c only clears skb->offload_fwd_mark for LAN9645X_CPUQ_TRAP:
if (cpuq & BIT(LAN9645X_CPUQ_TRAP)) {
skb->offload_fwd_mark = 0;
return;
}So the hardware forwards these copied frames through FLD_MC4_CTRL=PGID_MC, and the stack does not. Only IGMP and MLD are redirected.
The commit message gets this right. Could the code comment be updated to match?
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0/* Reserve 1664 bytes, 26 buffer cells, per (port, prio) for source * tracking (resource 0, indices 0..95) and destination tracking * (resource 2, indices 512..607). These are access watermarks, not
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0
-0@@ -0,0 +1,582 @@
[ ... ]
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +3
-0+static struct lan9645x_pgid_entry * +lan9645x_pgid_entry_alloc (struct lan9645x *lan9645x,int index,u16 ports) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 186
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +9
-0+dev_dbg (lan9645x->dev,"index=%d ports=0x%x\n" , pgid_entry->index, + pgid_entry->ports); + +lan_rmw (ANA_PGID_PGID_SET (pgid_entry->ports), +ANA_PGID_PGID , lan9645x, +ANA_PGID (pgid_entry->index)); + +return pgid_entry; +}
[Severity: Low]
lan9645x_pgid_entry_put() leaves the old destination mask in hardware on purpose and relies on this write to replace it when the index is reused. lan_rmw() only does WARN_ON_ONCE() when regmap_update_bits() fails, and lan9645x_pgid_entry_alloc() returns success either way.
If this write is lost, would the new group forward to the previous group's ports?
The overwrite in place branch in __lan9645x_mdb_del() has the same shape. It updates mdb_entry->pgid->ports before an unchecked lan_rmw(), so the departing port would keep receiving traffic.
This follows the lan_wr()/lan_rmw() convention used across the driver, and in lan966x and ocelot too. It is also not clear that this regmap can fail at all. So this is more of a hardening question than a defect in the mdb logic.
[ ... ]
Quoted 14 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +14
-0+static int lan9645x_mdb_widen_dest (struct lan9645x *lan9645x, +struct lan9645x_mdb_entry *mdb_entry, +enum macaccess_entry_type type, +struct lan9645x_pgid_entry *new_pgid, +int pgid_index,u16 new_ports) +{ +struct lan9645x_pgid_entry *old_pgid = mdb_entry->pgid; +int err; + +lockdep_assert_held (&lan9645x->mdb_lock); + + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) {
[ ... ]
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5
-0+/* A failed write leaves the hardware state unknown, the mac +* entry may point at old_pgid or new_pgid. Keep the reference +* taken on new_pgid, so its index cannot be handed to an +* unrelated group. If the entry already holds new_pgid, e.g. +* when the CPU port module joins, drop the extra reference.
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 311
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+*/ +if (new_pgid == old_pgid) +lan9645x_pgid_entry_put (lan9645x, new_pgid); +return err; + } + mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports; +lan9645x_pgid_entry_put (lan9645x, old_pgid); +return 0 ; +}
[Severity: Medium]
If lan9645x_mdb_write_dest() fails and new_pgid != old_pgid, the reference on new_pgid is kept but never stored in mdb_entry->pgid. What drops it later?
Later successful updates only put mdb_entry->pgid, so this reference seems to be released only in lan9645x_mdb_deinit().
A few other error paths do the same.
lan9645x_mdb_narrow_dest() switches mdb_entry->pgid to new_pgid before the write. On failure it returns without putting old_pgid:
if (old_pgid != new_pgid) return;
In __lan9645x_mdb_del(), when CMD_FORGET fails for the last port:
mdb_entry->pgid = NULL; } lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);
In __lan9645x_mdb_add(), when both the learn and the cleanup forget fail for a fresh entry, the new_pgid reference is kept and the mdb entry is freed.
Each transient ANA_MACACCESS poll timeout or regmap read error would then use up one index from the PGID_GP_START..PGID_GP_END pool for good. A shared PGID that holds an orphaned reference can also never get back to refcount 1, which disables the overwrite in place branch in __lan9645x_mdb_del().
The v14 changelog explains why the reference is held while the hardware state is uncertain. Is there anything that releases it once a later successful CMD_LEARN or CMD_FORGET for the same (mac, vid) makes the state known again? Without that, could L2 multicast adds eventually fail with -ENOSPC?
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4
-0+static int __lan9645x_mdb_add (struct lan9645x *lan9645x,int chip_port, +const unsigned char addr[ETH_ALEN ],u16 vid, +enum macaccess_entry_type type) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 380
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +9
-0+ mdb_entry =lan9645x_mdb_entry_lookup (lan9645x, addr, vid); +if (!mdb_entry) { + mdb_entry =lan9645x_mdb_entry_alloc (lan9645x, addr, vid); +if (IS_ERR (mdb_entry)) +return PTR_ERR (mdb_entry); + } + +if (mdb_entry->ports &BIT (chip_port)) +return 0 ;
[Severity: Medium]
What happens when two IP groups on the same port map to the same multicast MAC?
br_switchdev_mdb_populate() converts each group with ip_eth_mc_map() or ipv6_eth_mc_map(). For example, 239.1.1.1 and 239.129.1.1 both become 01:00:5e:01:01:01.
For user ports, DSA passes the call straight to the driver without refcounting:
net/dsa/switch.c:dsa_port_do_mdb_add() {
...
/* No need to bother with refcounting for user ports */
if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) {
err = ds->ops->port_mdb_add(ds, port, mdb, db);
...
}The second join returns 0 here and nothing records it. When the first group leaves or expires, __lan9645x_mdb_del() runs:
new_ports = mdb_entry->ports & ~BIT(chip_port);
It then either narrows the destination or forgets the entry. Does the port then stop receiving traffic for the group it is still a member of?
The bridge does not send another add while the remaining group keeps being refreshed. The loss would last until that group expires and is created again. With the bridge support patch later in the series, ordinary IGMP/MLD snooping looks like enough to trigger this.
Does the mdb entry need a per-port membership count here?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 7/9] net: dsa: lan9645x: add mdb management
Quoted 206 lines · On Mon, 2026-10-12 at 11:24 +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 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Separate IP multicast groups that map to the same multicast MAC collapse into one per-port bit, so leaving one group removes…
- [Medium] Several error paths deliberately keep a PGID reference, but nothing owns it afterwards and it is only freed in…
- [Low] A comment inlan9645x_setup()(drivers/net/dsa/microchip/lan9645x/lan9645x_main.c, lines 210-214,…
- [Low] PGID destination-mask writes inlan9645x_pgid_entry_alloc()and in the overwrite-in-place branch of__lan9645x_mdb_del()go through…--
net: dsa: lan9645x: add mdb management
This patch adds .port_mdb_add and .port_mdb_del support to the lan9645x DSA driver. IP multicast entries store the port mask inline in the mac table entry. L2 multicast entries point at a refcounted PGID, and CPU membership is carried by
MAC_CPU_COPY. The patch also redirects IGMP and MLD to the CPU and copies IPv4 multicast control frames to it.Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +1
-0@@ -253,6 +255,17 @@ static int lan9645x_setup(struct dsa_switch *ds) lan9645x, ANA_CPUQ_8021_CFG(i)); } +/* Use CPU queues to communicate frame classification to the CPU */ drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 268
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+lan_rmw (ANA_CPUQ_CFG_CPUQ_MAC_COPY_SET (LAN9645X_CPUQ_DEF ) | +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_MAC_COPY | +ANA_CPUQ_CFG_CPUQ_IGMP | +ANA_CPUQ_CFG_CPUQ_MLD | +ANA_CPUQ_CFG_CPUQ_IPMC_CTRL , + lan9645x,ANA_CPUQ_CFG ); +[Severity: Low]
Is the comment above the
ANA_FLOODING_IPMCwrite inlan9645x_setup()still accurate after this change?lan9645x_setup() { ... /* Setup flooding PGIDs for IPv4/IPv6 multicast. Control and dataplane * use the same masks. Control frames are redirected to CPU, and * the network stack is responsible for forwarding these. ... }This patch copies IPv4 multicast control frames to the CPU instead of redirecting them.
lan9645x_port_setup()setsANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA, andIPMC_CTRLis mapped toLAN9645X_CPUQ_COPYhere.
lan9645x_offload_fwd_mark()innet/dsa/tag_lan9645x.conly clearsskb->offload_fwd_markforLAN9645X_CPUQ_TRAP:if (cpuq & BIT(LAN9645X_CPUQ_TRAP)) { skb->offload_fwd_mark = 0; return; }So the hardware forwards these copied frames through FLD_MC4_CTRL=PGID_MC, and the stack does not. Only IGMP and MLD are redirected.
The commit message gets this right. Could the code comment be updated to match?
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0/* Reserve 1664 bytes, 26 buffer cells, per (port, prio) for source * tracking (resource 0, indices 0..95) and destination tracking * (resource 2, indices 512..607). These are access watermarks, not [ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0
-0@@ -0,0 +1,582 @@[ ... ]
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +3
-0+static struct lan9645x_pgid_entry * +lan9645x_pgid_entry_alloc (struct lan9645x *lan9645x,int index,u16 ports) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 186
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +9
-0+dev_dbg (lan9645x->dev,"index=%d ports=0x%x\n" , pgid_entry->index, + pgid_entry->ports); + +lan_rmw (ANA_PGID_PGID_SET (pgid_entry->ports), +ANA_PGID_PGID , lan9645x, +ANA_PGID (pgid_entry->index)); + +return pgid_entry; +}[Severity: Low]
lan9645x_pgid_entry_put()leaves the old destination mask in hardware on purpose and relies on this write to replace it when the index is reused.lan_rmw()only doesWARN_ON_ONCE()whenregmap_update_bits()fails, andlan9645x_pgid_entry_alloc()returns success either way.If this write is lost, would the new group forward to the previous group's ports?
The overwrite in place branch in
__lan9645x_mdb_del()has the same shape. It updatesmdb_entry->pgid->portsbefore an uncheckedlan_rmw(), so the departing port would keep receiving traffic.This follows the lan_wr()/lan_rmw() convention used across the driver, and in lan966x and ocelot too. It is also not clear that this regmap can fail at all. So this is more of a hardening question than a defect in the mdb logic.
[ ... ]
Quoted 14 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +14
-0+static int lan9645x_mdb_widen_dest (struct lan9645x *lan9645x, +struct lan9645x_mdb_entry *mdb_entry, +enum macaccess_entry_type type, +struct lan9645x_pgid_entry *new_pgid, +int pgid_index,u16 new_ports) +{ +struct lan9645x_pgid_entry *old_pgid = mdb_entry->pgid; +int err; + +lockdep_assert_held (&lan9645x->mdb_lock); + + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) {[ ... ]
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5
-0+/* A failed write leaves the hardware state unknown, the mac +* entry may point at old_pgid or new_pgid. Keep the reference +* taken on new_pgid, so its index cannot be handed to an +* unrelated group. If the entry already holds new_pgid, e.g. +* when the CPU port module joins, drop the extra reference. drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 311
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+*/ +if (new_pgid == old_pgid) +lan9645x_pgid_entry_put (lan9645x, new_pgid); +return err; + } + mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports; +lan9645x_pgid_entry_put (lan9645x, old_pgid); +return 0 ; +}[Severity: Medium]
If
lan9645x_mdb_write_dest()fails andnew_pgid!=old_pgid, the reference onnew_pgidis kept but never stored inmdb_entry->pgid. What drops it later?Later successful updates only put
mdb_entry->pgid, so this reference seems to be released only inlan9645x_mdb_deinit().A few other error paths do the same.
lan9645x_mdb_narrow_dest()switchesmdb_entry->pgidtonew_pgidbefore the write. On failure it returns without puttingold_pgid:if (old_pgid != new_pgid) return;In
__lan9645x_mdb_del(), whenCMD_FORGETfails for the last port:mdb_entry->pgid = NULL; } lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);In
__lan9645x_mdb_add(), when both the learn and the cleanup forget fail for a fresh entry, thenew_pgidreference is kept and the mdb entry is freed.Each transient
ANA_MACACCESSpoll timeout or regmap read error would then use up one index from the PGID_GP_START..PGID_GP_END pool for good. A shared PGID that holds an orphaned reference can also never get back to refcount 1, which disables the overwrite in place branch in__lan9645x_mdb_del().
Quoted 6 lines
The v14 changelog explains why the reference is held while the hardware state is uncertain. Is there anything that releases it once a later successful
CMD_LEARNorCMD_FORGETfor the same (mac, vid) makes the state known again? Without that, could L2 multicast adds eventually fail with-ENOSPC?
Dismissed, intended.
Correct, and intended. These paths are only reached when a MAC table command fails, i.e. a register bus error or a command that never completes. The hardware may then still reference the PGID, and handing its index to another group could forward that group to the wrong ports. Keeping the index reserved until the driver is unbound is the safe outcome, and it costs one of the 48 general purpose PGIDs per failure. When the pool runs out, a new group gets -ENOSPC and is not offloaded, and a group already on the flood mask stays on PGID_MC, so nothing is forwarded incorrectly.
Releasing the reference after a later successful command would need per entry state for a stale PGID, and would still not cover the delete and fresh add paths, where the entry is freed and no later command for it follows. As for the VLAN table, the driver does not attempt runtime recovery after a register bus failure.
Quoted 47 lines
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +4
-0+static int __lan9645x_mdb_add (struct lan9645x *lan9645x,int chip_port, +const unsigned char addr[ETH_ALEN ],u16 vid, +enum macaccess_entry_type type) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 380
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +9
-0+ mdb_entry =lan9645x_mdb_entry_lookup (lan9645x, addr, vid); +if (!mdb_entry) { + mdb_entry =lan9645x_mdb_entry_alloc (lan9645x, addr, vid); +if (IS_ERR (mdb_entry)) +return PTR_ERR (mdb_entry); + } + +if (mdb_entry->ports &BIT (chip_port)) +return 0 ;[Severity: Medium]
What happens when two IP groups on the same port map to the same multicast MAC?
br_switchdev_mdb_populate()converts each group withip_eth_mc_map()oripv6_eth_mc_map(). For example, 239.1.1.1 and 239.129.1.1 both become 01:00:5e:01:01:01.For user ports, DSA passes the call straight to the driver without refcounting:
net/dsa/switch.c:dsa_port_do_mdb_add() { ... /* No need to bother with refcounting for user ports */ if (!(dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp))) { err = ds->ops->port_mdb_add(ds, port, mdb, db); ... }The second join returns 0 here and nothing records it. When the first group leaves or expires,
__lan9645x_mdb_del()runs:new_ports = mdb_entry->ports & ~BIT(chip_port);It then either narrows the destination or forgets the entry. Does the port then stop receiving traffic for the group it is still a member of?
Quoted 7 lines
The bridge does not send another add while the remaining group keeps being refreshed. The loss would last until that group expires and is created again. With the bridge support patch later in the series, ordinary IGMP/MLD snooping looks like enough to trigger this.
Does the mdb entry need a per-port membership count here?
Dismissed, preexisting.
This is an existing issue that can only be fixed in the bridge core. The limitations is shared with ocelot/felix, mv88e6xxx, lan966x and sparx5, which also keep one bit per port. A per port count is not correct either. The bridge sends SWITCHDEV_OBJ_ID_PORT_MDB adds for port groups that already exist without a matching delete, e.g. on mdb replace, on IGMPv3/MLDv2 source list changes, on source timer expiry and on (S, G) blocked flag changes:
bridge mdb add dev br0 port swp1 grp 01:02:03:04:05:06 permanent vid 10 bridge mdb replace dev br0 port swp1 grp 01:02:03:04:05:06 permanent vid 10 bridge mdb del dev br0 port swp1 grp 01:02:03:04:05:06 vid 10
reaches the driver as add, add, del. Counting adds would leave the port in the group after the bridge removed it. Since switchdev_obj_port_mdb only carries (MAC, VID), the driver cannot tell an aliasing group from a re-notification, so neither scheme is right in the driver.
Quoted 4 lines
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
PATCH v14 8/9 net: dsa: lan9645x: add bridge support
In reply to Jens Emil Schulz ØstergaardAdd support for hardware offloading of the bridge. We support a single bridge device.
Mac entry ageing can be configured with a 2s granularity, and a requested time is rounded down. An ANA_AUTOAGE.AGE_PERIOD of 0 stops the analyzer from ageing at all, which is the opposite of what a bridge ageing time of 0 asks for, so ds->ageing_time_min and ds->ageing_time_max let the DSA core reject what the hardware cannot express.
The flood masks are global and not per ingress port. The CPU port module is added to the unicast and multicast flood masks while any port requests host flooding, so unknown unicast and unregistered multicast from every port then reach the CPU. Bridged ports request it under most conditions, which the software bridge relies on for foreign bridge ports and for local delivery of multicast not learned through snooping.
---
Changes in v14:
- Only enable learning on bridged ports, so a port that left a bridge, or failed to join one, does not learn.
- Honour host flood requests from bridged ports. The software bridge needs unknown unicast and unregistered multicast on the CPU for foreign bridge ports and for multicast not learned through snooping.
- Start a joining port in BR_STATE_DISABLED and out of the forwarding mask. DSA applies the inherited BR_LEARNING flag before the STP state, so the standalone FORWARDING state enabled learning on a port the bridge still holds disabled.
Changes in v12:
- Move this patch after vlan, mac table and mdb support, so .port_fast_age exists for the STP state transitions and host address filtering is already advertised.
- Drop the open coded single bridge check now that ds->max_num_bridges makes the core reject a second bridge, and the now unused bridge field.
- Set ds->ageing_time_min and drop the clamp and the msecs == 0 case from lan9645x_set_ageing_time(). An ANA_AUTOAGE.AGE_PERIOD of 0 stops the analyzer from ageing, which is the opposite of what a bridge ageing_time of 0 asks for, so the DSA core now rejects out of range values instead.
- Drop mact_lock from lan9645x_set_ageing_time() after the fdb dump no longer toggles ageing.
- Remove the CPU port module from the unicast and multicast flood masks. Host address filtering covers the known addresses and port_set_host_flood() covers promiscuous and allmulti.
- Move lan9645x_vlan_clear_hostmode() here, with its caller.
- Describe the host flood compromise for offloaded bridged ports.
- lan9645x_port_set_learning() now takes fwd_domain_lock.
- port_set_host_flood(): drop the per port work and ordered workqueue and program the masks inline, since the ndo no longer runs in atomic context.
- Remove unreachable WARN_ON()s and the equally unreachable NPI port check in lan9645x_port_bridge_flags(). DSA does not call the port operations for the CPU port.
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 | 280 ++++++++++++++++++++- drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 7 + drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 9 + 3 files changed, 285 insertions(+), 11 deletions(-)
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +269 -11
@@ -283,19 +283,15 @@ static int lan9645x_setup(struct dsa_switch *ds)lan9645x_port_cpu_init (lan9645x); -/* Multicast to cpu and all front ports */ -lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, -ANA_PGID (PGID_MC )); +/* Multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MC )); -/* IP multicast to cpu and all front ports */ -lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, -ANA_PGID (PGID_MCIPV4 )); -lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, -ANA_PGID (PGID_MCIPV6 )); +/* 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 cpu and all front ports */ -lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, -ANA_PGID (PGID_UC )); +/* Unicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_UC ));/* Broadcast to cpu and all front ports */ lan_wr(BIT(lan9645x->num_phys_ports) | front_ports, lan9645x,
@@ -306,6 +302,19 @@ static int lan9645x_setup(struct dsa_switch *ds) ds->fdb_isolation = true; ds->max_num_bridges =1 ; +/* 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 and 2 seconds of minimum aging. +* +* An AGE_PERIOD of 0 stops the analyzer from aging at all, which is +* the opposite of what a bridge ageing_time of 0 asks for. The bridge +* expires every dynamic entry immediately in that case and floods, so +* reject it rather than keep learned addresses forever. +*/ + ds->ageing_time_min =2U *MSEC_PER_SEC ; + 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);
@@ -324,6 +333,246 @@ 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) +{ +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. +*/ +lan_rmw (ANA_AUTOAGE_AGE_PERIOD_SET (msecs / (2 *MSEC_PER_SEC )), +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; + + 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_apply_learning (struct lan9645x_port *p) +{ +struct lan9645x *lan9645x = p->lan9645x; +bool ena; + +lockdep_assert_held (&lan9645x->fwd_domain_lock); + + ena =lan9645x_port_is_bridged (p) && p->learn_ena && + (p->stp_state ==BR_STATE_LEARNING || + p->stp_state ==BR_STATE_FORWARDING ); + +lan_rmw (ANA_PORT_CFG_LEARN_ENA_SET (ena),ANA_PORT_CFG_LEARN_ENA , + lan9645x,ANA_PORT_CFG (p->chip_port)); +} + +static void lan9645x_port_set_learning (struct lan9645x *lan9645x,int port, +bool enabled) +{ +struct lan9645x_port *p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + p->learn_ena = enabled; +lan9645x_port_apply_learning (p); +mutex_unlock (&lan9645x->fwd_domain_lock); +} + +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; + +/* DSA core does not call this for the CPU port */ +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 (ANA_PGID_PGID_SET (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; + +lockdep_assert_held (&lan9645x->fwd_domain_lock); + + uc_ena = !!lan9645x->host_flood_uc_mask; +lan9645x_port_pgid_set (lan9645x,PGID_UC , lan9645x->num_phys_ports, + uc_ena); + + mc_ena = !!lan9645x->host_flood_mc_mask; +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_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); + +mutex_lock (&lan9645x->fwd_domain_lock); +__lan9645x_port_mark_host_flood (lan9645x, p->chip_port, uc, mc); +__lan9645x_port_set_host_flood (lan9645x); +mutex_unlock (&lan9645x->fwd_domain_lock); +} + +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); + + lan9645x->bridge_mask |=BIT (p->chip_port); +/* DSA sets the bridge port flags before the STP state. Start disabled, +* so the inherited BR_LEARNING does not enable learning in between. +*/ + lan9645x->bridge_fwd_mask &= ~BIT (p->chip_port); + p->stp_state =BR_STATE_DISABLED ; +lan9645x_vlan_clear_hostmode (p); + +mutex_unlock (&lan9645x->fwd_domain_lock); + +/* Forwarding is updated by .port_stp_state_set(), which the core +* invokes after this returns: +* dsa_port_bridge_join() -> dsa_port_switchdev_sync_attrs() -> +* dsa_port_set_state() +*/ + +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; + + 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); + +lan9645x_port_apply_learning (p); +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); + +lan9645x_vlan_set_hostmode (p); +lan9645x_port_apply_learning (p); +lan9645x_update_fwd_mask (lan9645x); + +mutex_unlock (&lan9645x->fwd_domain_lock); +} +static int lan9645x_port_vlan_filtering (struct dsa_switch *ds,int port,bool enabled,struct netlink_ext_ack *extack)
@@ -561,6 +810,15 @@ static const struct dsa_switch_ops lan9645x_switch_ops = { .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, +/* VLAN integration */ .port_vlan_filtering = lan9645x_port_vlan_filtering, .port_vlan_add = lan9645x_port_vlan_add,
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +7 -0
@@ -195,6 +195,9 @@ struct lan9645x {struct dsa_switch *ds;struct regmap *rmap[NUM_TARGETS ]; +u16 host_flood_uc_mask; +u16 host_flood_mc_mask; +/* NPI chip_port */ int npi;
@@ -203,6 +206,7 @@ struct lan9645x {/* Forwarding Database */ u16 bridge_mask;/* Mask for bridged ports */ +u16 bridge_fwd_mask;/* Mask for forwarding bridged ports */ /* lock forwarding configuration and vlan table */ struct mutex fwd_domain_lock;struct mutex mact_lock;/* serialize mac table register access */
@@ -225,6 +229,8 @@ struct lan9645x_port {struct lan9645x *lan9645x;u8 chip_port; +u8 stp_state; +bool learn_ena;bool vlan_aware;u16 pvid;
@@ -398,6 +404,7 @@ int lan9645x_vlan_port_add_vlan(struct lan9645x_port *p, u16 vid, bool pvid, 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);/* MAC table: lan9645x_mac.c */ int lan9645x_mact_flush (struct lan9645x *lan9645x,int port);
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c +9 -0
@@ -347,6 +347,15 @@ void lan9645x_vlan_set_hostmode(struct lan9645x_port *p)lan9645x_vlan_port_apply (p); } +void lan9645x_vlan_clear_hostmode (struct lan9645x_port *p) +{ +lockdep_assert_held (&p->lan9645x->fwd_domain_lock); + + p->lan9645x->vlans[HOST_PVID ].portmask &= ~BIT (p->chip_port); +lan9645x_vlan_hw_wr (p->lan9645x,HOST_PVID ); +lan9645x_vlan_port_apply (p); +} +int lan9645x_vlan_init (struct lan9645x *lan9645x) {u32 all_phys_ports, all_ports;
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v14 8/9] net: dsa: lan9645x: add bridge 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.
Critical: 0 · High: 0 · Medium: 2 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] When the general-purpose PGIDs run out, L2 multicast groups fall back to PGID_MC.
- [Medium] Setting ds->ageing_time_min/max makes a bridge join fail late, and the failed join leaves DSA's dp->vlan_filtering out of step with…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the new lan9645x_set_ageing_time() is affected by it.
--
net: dsa: lan9645x: add bridge support
This adds hardware bridge offload to the lan9645x DSA driver for a single bridge. It adds ageing time configuration with min/max limits enforced by the DSA core, plus bridge port flags and STP state handling. Host flooding is done by adding the CPU port module to the global flood masks.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2
-0@@ -306,6 +302,19 @@ static int lan9645x_setup(struct dsa_switch *ds) ds->fdb_isolation = true; ds->max_num_bridges =1 ; +/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are +* aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 316
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+* maximum aging and 2 seconds of minimum aging. +* +* An AGE_PERIOD of 0 stops the analyzer from aging at all, which is +* the opposite of what a bridge ageing_time of 0 asks for. The bridge +* expires every dynamic entry immediately in that case and floods, so +* reject it rather than keep learned addresses forever. +*/ + ds->ageing_time_min =2U *MSEC_PER_SEC ; + ds->ageing_time_max =2U *MSEC_PER_SEC * +FIELD_MAX (ANA_AUTOAGE_AGE_PERIOD );
[Severity: Medium]
Can a bridge join that fails on these limits leave the port VLAN-unaware in hardware after the next successful join?
With ageing_time_min set, dsa_switch_ageing_time() returns -ERANGE for any bridge ageing_time below 2s, including 0. For example:
ip link add br0 type bridge vlan_filtering 1 ageing_time 0
dsa_port_switchdev_sync_attrs() applies the ageing time last. By then, dsa_port_vlan_filtering(dp, br_vlan_enabled(br)) has already called lan9645x_port_vlan_filtering(true) and set dp->vlan_filtering = true.
The rollback in dsa_port_bridge_join() then does:
net/dsa/port.c:dsa_port_bridge_join() {
...
out_rollback_unoffload:
switchdev_bridge_port_unoffload(...);
dsa_flush_workqueue();
out_rollback_unbridge:
dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info);
out_rollback:
dsa_port_bridge_destroy(dp, br);
...
}This path never calls dsa_port_switchdev_unsync_attrs() or dsa_port_reset_vlan_filtering(), so dp->vlan_filtering stays true.
Meanwhile the BRIDGE_LEAVE notifier reaches lan9645x_port_bridge_leave(). That function calls lan9645x_vlan_set_hostmode(), which sets p->vlan_aware = false.
Now suppose the ageing time is fixed and the port is added to a vlan_filtering=1 bridge again. dsa_port_vlan_filtering() returns early:
if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) return 0;
So .port_vlan_filtering is never called. Neither lan9645x_port_bridge_join() nor lan9645x_vlan_clear_hostmode() restores p->vlan_aware.
Would the port then stay at VLAN_AWARE_ENA=0 in ANA_VLAN_CFG while it is in a VLAN-aware bridge? That would give wrong ingress VLAN classification and filtering.
The incomplete rollback is in the DSA core. This patch makes it reachable through the new ageing limits, and the new bridge_leave creates the mismatch on the driver side. The issue still seems to be there at the end of the series.
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3
-0@@ -324,6 +333,246 @@ 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) +{ +struct lan9645x *lan9645x = ds->priv;
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 348
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +/* Entry must suffer two aging scans before it is removed, so it is +* aged after 2*AGE_PERIOD, and the unit is in seconds. +*/ +lan_rmw (ANA_AUTOAGE_AGE_PERIOD_SET (msecs / (2 *MSEC_PER_SEC )), +ANA_AUTOAGE_AGE_PERIOD , + lan9645x,ANA_AUTOAGE ); + +return 0 ; +}
[Severity: Medium]
This is a pre-existing issue in the DSA core and was not introduced by this patch, but it affects the new lan9645x_set_ageing_time(). Does raising the bridge ageing time ever reach the hardware?
dsa_port_ageing_time() sends the notifier before it updates the cached value:
net/dsa/port.c:dsa_port_ageing_time() {
...
err = dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info);
if (err)
return err;
dp->ageing_time = ageing_time;
...
}dsa_switch_fastest_ageing_time() then takes the minimum over all ports, including the old value of the requesting port:
dsa_switch_for_each_port(dp, ds) if (dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time;
So a change from 300000 ms to 600000 ms programs 300000 ms through lan9645x_set_ageing_time() and returns success. 600000 ms is then cached in dp->ageing_time, with no further hardware write.
The fix probably belongs in the DSA core rather than in this driver: the requester's cached value could be updated, or left out, before the minimum is computed.
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0+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; +
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 419
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7
-0+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); + }
[Severity: Medium]
Does this break the PGID_MC fallback that the mdb code uses when the general-purpose PGIDs run out?
When a group's PGID is shared or no PGID is free, __lan9645x_mdb_del() points the L2 group at PGID_MC:
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_del() {
...
/* Shared PGID or on flood mask. Point the entry at the L2 MC flood mask
* instead. This way our mac table entry survives and MAC_CPU_COPY
* keeps host membership working.
*/
...
lan9645x_mdb_narrow_dest(lan9645x, mdb_entry, type, NULL, PGID_MC,
new_ports);
...
}__lan9645x_mdb_add() also keeps a group that is already on the flood mask pointed at PGID_MC:
/* For a L2 MC group already on the flood mask, we keep it there * so that the host can still join/leave a group we had to give * up offloading. A front port that joins forwards according to * the flood masks, like the other members. */ if (lan9645x_mdb_on_flood_mask(mdb_entry, type)) return lan9645x_mdb_widen_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports);
This fallback depended on PGID_MC holding every front port, as lan9645x_setup() sets it. With this change, a port configured with:
bridge link set dev swpN mcast_flood off
is removed from PGID_MC. If that port is also a registered member of an L2 group in the fallback state, will it stop receiving that group's traffic?
The software bridge still delivers registered groups to their members whatever their mcast_flood setting, so hardware forwarding would no longer match it. Also, when such a port joins through __lan9645x_mdb_add(), the join reports success but the port gets no traffic. The issue still seems to be there at the end of the series.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 8/9] net: dsa: lan9645x: add bridge support
Quoted 231 lines · On Mon, 2026-10-12 at 11:24 +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.
Critical: 0 · High: 0 · Medium: 2 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] When the general-purpose PGIDs run out, L2 multicast groups fall back to
PGID_MC.
- [Medium] Setting ds->ageing_time_min/max makes a bridge join fail late, and the failed join leaves DSA'sdp->vlan_filteringout of step with…Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the newlan9645x_set_ageing_time()is affected by it.--
net: dsa: lan9645x: add bridge support
This adds hardware bridge offload to the lan9645x DSA driver for a single bridge. It adds ageing time configuration with min/max limits enforced by the DSA core, plus bridge port flags and STP state handling. Host flooding is done by adding the CPU port module to the global flood masks.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2
-0@@ -306,6 +302,19 @@ static int lan9645x_setup(struct dsa_switch *ds) ds->fdb_isolation = true; ds->max_num_bridges =1 ; +/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are +* aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 316
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+* maximum aging and 2 seconds of minimum aging. +* +* An AGE_PERIOD of 0 stops the analyzer from aging at all, which is +* the opposite of what a bridge ageing_time of 0 asks for. The bridge +* expires every dynamic entry immediately in that case and floods, so +* reject it rather than keep learned addresses forever. +*/ + ds->ageing_time_min =2U *MSEC_PER_SEC ; + ds->ageing_time_max =2U *MSEC_PER_SEC * +FIELD_MAX (ANA_AUTOAGE_AGE_PERIOD );[Severity: Medium]
Can a bridge join that fails on these limits leave the port VLAN-unaware in hardware after the next successful join?With
ageing_time_minset,dsa_switch_ageing_time()returns-ERANGEfor any bridgeageing_timebelow 2s, including 0. For example:ip link add br0 type bridge
vlan_filtering1ageing_time0
dsa_port_switchdev_sync_attrs()applies the ageing time last. By then,dsa_port_vlan_filtering(dp, br_vlan_enabled(br))has already calledlan9645x_port_vlan_filtering(true)and setdp->vlan_filtering= true.The rollback in
dsa_port_bridge_join()then does:net/dsa/port.c:dsa_port_bridge_join() { ... out_rollback_unoffload: switchdev_bridge_port_unoffload(...); dsa_flush_workqueue(); out_rollback_unbridge: dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); out_rollback: dsa_port_bridge_destroy(dp, br); ... }This path never calls
dsa_port_switchdev_unsync_attrs()ordsa_port_reset_vlan_filtering(), sodp->vlan_filteringstays true.Meanwhile the
BRIDGE_LEAVEnotifier reacheslan9645x_port_bridge_leave(). That function callslan9645x_vlan_set_hostmode(), which setsp->vlan_aware= false.Now suppose the ageing time is fixed and the port is added to a vlan_filtering=1 bridge again.
dsa_port_vlan_filtering()returns early:if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) return 0;So .port_vlan_filtering is never called. Neither
lan9645x_port_bridge_join()norlan9645x_vlan_clear_hostmode()restoresp->vlan_aware.Would the port then stay at VLAN_AWARE_ENA=0 in
ANA_VLAN_CFGwhile it is in a VLAN-aware bridge? That would give wrong ingress VLAN classification and filtering.The incomplete rollback is in the DSA core. This patch makes it reachable through the new ageing limits, and the new
bridge_leavecreates the mismatch on the driver side. The issue still seems to be there at the end of the series.[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3
-0@@ -324,6 +333,246 @@ 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) +{ +struct lan9645x *lan9645x = ds->priv;drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 348
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +/* Entry must suffer two aging scans before it is removed, so it is +* aged after 2*AGE_PERIOD, and the unit is in seconds. +*/ +lan_rmw (ANA_AUTOAGE_AGE_PERIOD_SET (msecs / (2 *MSEC_PER_SEC )), +ANA_AUTOAGE_AGE_PERIOD , + lan9645x,ANA_AUTOAGE ); + +return 0 ; +}[Severity: Medium]
This is a pre-existing issue in the DSA core and was not introduced by this patch, but it affects the newlan9645x_set_ageing_time(). Does raising the bridge ageing time ever reach the hardware?
dsa_port_ageing_time()sends the notifier before it updates the cached value:net/dsa/port.c:dsa_port_ageing_time() { ... err = dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info); if (err) return err; dp->ageing_time = ageing_time; ... }
dsa_switch_fastest_ageing_time()then takes the minimum over all ports, including the old value of the requesting port:dsa_switch_for_each_port(dp, ds) if (dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time;So a change from 300000 ms to 600000 ms programs 300000 ms through
lan9645x_set_ageing_time()and returns success. 600000 ms is then cached indp->ageing_time, with no further hardware write.The fix probably belongs in the DSA core rather than in this driver: the requester's cached value could be updated, or left out, before the minimum is computed.
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0+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; +[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 419
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7
-0+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); + }[Severity: Medium]
Does this break thePGID_MCfallback that the mdb code uses when the general-purpose PGIDs run out?When a group's PGID is shared or no PGID is free,
__lan9645x_mdb_del()points the L2 group atPGID_MC:drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_del() { ... /* Shared PGID or on flood mask. Point the entry at the L2 MC flood mask * instead. This way our mac table entry survives and MAC_CPU_COPY * keeps host membership working. */ ... lan9645x_mdb_narrow_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports); ... }
__lan9645x_mdb_add()also keeps a group that is already on the flood mask pointed atPGID_MC:/* For a L2 MC group already on the flood mask, we keep it there * so that the host can still join/leave a group we had to give * up offloading. A front port that joins forwards according to * the flood masks, like the other members. */ if (lan9645x_mdb_on_flood_mask(mdb_entry, type)) return lan9645x_mdb_widen_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports);This fallback depended on
PGID_MCholding every front port, aslan9645x_setup()sets it. With this change, a port configured with:bridge link set dev swpN
mcast_floodoffis removed from
PGID_MC. If that port is also a registered member of an L2 group in the fallback state, will it stop receiving that group's traffic?The software bridge still delivers registered groups to their members whatever their
mcast_floodsetting, so hardware forwarding would no longer match it. Also, when such a port joins through__lan9645x_mdb_add(), the join reports success but the port gets no traffic. The issue still seems to be there at the end of the series.[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 8/9] net: dsa: lan9645x: add bridge support
In reply to [email protected]Quoted 99 lines · On Mon, 2026-10-12 at 11:24 +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.
Critical: 0 · High: 0 · Medium: 2 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] When the general-purpose PGIDs run out, L2 multicast groups fall back to
PGID_MC.
- [Medium] Setting ds->ageing_time_min/max makes a bridge join fail late, and the failed join leaves DSA'sdp->vlan_filteringout of step with…Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the newlan9645x_set_ageing_time()is affected by it.--
net: dsa: lan9645x: add bridge support
This adds hardware bridge offload to the lan9645x DSA driver for a single bridge. It adds ageing time configuration with min/max limits enforced by the DSA core, plus bridge port flags and STP state handling. Host flooding is done by adding the CPU port module to the global flood masks.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2
-0@@ -306,6 +302,19 @@ static int lan9645x_setup(struct dsa_switch *ds) ds->fdb_isolation = true; ds->max_num_bridges =1 ; +/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are +* aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_setup(struct dsa_switch *ds) · line 316
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+* maximum aging and 2 seconds of minimum aging. +* +* An AGE_PERIOD of 0 stops the analyzer from aging at all, which is +* the opposite of what a bridge ageing_time of 0 asks for. The bridge +* expires every dynamic entry immediately in that case and floods, so +* reject it rather than keep learned addresses forever. +*/ + ds->ageing_time_min =2U *MSEC_PER_SEC ; + ds->ageing_time_max =2U *MSEC_PER_SEC * +FIELD_MAX (ANA_AUTOAGE_AGE_PERIOD );[Severity: Medium]
Can a bridge join that fails on these limits leave the port VLAN-unaware in hardware after the next successful join?With
ageing_time_minset,dsa_switch_ageing_time()returns-ERANGEfor any bridgeageing_timebelow 2s, including 0. For example:ip link add br0 type bridge
vlan_filtering1ageing_time0
dsa_port_switchdev_sync_attrs()applies the ageing time last. By then,dsa_port_vlan_filtering(dp, br_vlan_enabled(br))has already calledlan9645x_port_vlan_filtering(true)and setdp->vlan_filtering= true.The rollback in
dsa_port_bridge_join()then does:net/dsa/port.c:dsa_port_bridge_join() { ... out_rollback_unoffload: switchdev_bridge_port_unoffload(...); dsa_flush_workqueue(); out_rollback_unbridge: dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); out_rollback: dsa_port_bridge_destroy(dp, br); ... }This path never calls
dsa_port_switchdev_unsync_attrs()ordsa_port_reset_vlan_filtering(), sodp->vlan_filteringstays true.Meanwhile the
BRIDGE_LEAVEnotifier reacheslan9645x_port_bridge_leave(). That function callslan9645x_vlan_set_hostmode(), which setsp->vlan_aware= false.Now suppose the ageing time is fixed and the port is added to a vlan_filtering=1 bridge again.
dsa_port_vlan_filtering()returns early:if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) return 0;So .port_vlan_filtering is never called. Neither
lan9645x_port_bridge_join()norlan9645x_vlan_clear_hostmode()restoresp->vlan_aware.
Quoted 9 lines
Would the port then stay at VLAN_AWARE_ENA=0 in
ANA_VLAN_CFGwhile it is in a VLAN-aware bridge? That would give wrong ingress VLAN classification and filtering.The incomplete rollback is in the DSA core. This patch makes it reachable through the new ageing limits, and the new
bridge_leavecreates the mismatch on the driver side. The issue still seems to be there at the end of the series.
Right. As discussed for v14, the missing dsa_port_switchdev_unsync_attrs() in the dsa_port_bridge_join() rollback is a DSA core issue.
But I think I can make sure the driver is not affected by it. The next version keeps p->vlan_aware equal to what DSA last passed to port_vlan_filtering(), so bridge_leave no longer clears it, and derives the hardware VLAN awareness from the port being bridged and p->vlan_aware. A standalone port is VLAN-unaware regardless, and a later join to a VLAN-aware bridge is configured correctly even when DSA skips the port_vlan_filtering() call.
Quoted 45 lines
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3
-0@@ -324,6 +333,246 @@ 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) +{ +struct lan9645x *lan9645x = ds->priv;drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 348
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +/* Entry must suffer two aging scans before it is removed, so it is +* aged after 2*AGE_PERIOD, and the unit is in seconds. +*/ +lan_rmw (ANA_AUTOAGE_AGE_PERIOD_SET (msecs / (2 *MSEC_PER_SEC )), +ANA_AUTOAGE_AGE_PERIOD , + lan9645x,ANA_AUTOAGE ); + +return 0 ; +}[Severity: Medium]
This is a pre-existing issue in the DSA core and was not introduced by this patch, but it affects the newlan9645x_set_ageing_time(). Does raising the bridge ageing time ever reach the hardware?
dsa_port_ageing_time()sends the notifier before it updates the cached value:net/dsa/port.c:dsa_port_ageing_time() { ... err = dsa_port_notify(dp, DSA_NOTIFIER_AGEING_TIME, &info); if (err) return err; dp->ageing_time = ageing_time; ... }
dsa_switch_fastest_ageing_time()then takes the minimum over all ports, including the old value of the requesting port:dsa_switch_for_each_port(dp, ds) if (dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time;
Quoted 8 lines
So a change from 300000 ms to 600000 ms programs 300000 ms through
lan9645x_set_ageing_time()and returns success. 600000 ms is then cached indp->ageing_time, with no further hardware write.The fix probably belongs in the DSA core rather than in this driver: the requester's cached value could be updated, or left out, before the minimum is computed.
Dismissed, preexisting.
The fix belongs in the DSA core.
Quoted 60 lines
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0+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; +[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 419
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +7
-0+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); + }[Severity: Medium]
Does this break thePGID_MCfallback that the mdb code uses when the general-purpose PGIDs run out?When a group's PGID is shared or no PGID is free,
__lan9645x_mdb_del()points the L2 group atPGID_MC:drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_del() { ... /* Shared PGID or on flood mask. Point the entry at the L2 MC flood mask * instead. This way our mac table entry survives and MAC_CPU_COPY * keeps host membership working. */ ... lan9645x_mdb_narrow_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports); ... }
__lan9645x_mdb_add()also keeps a group that is already on the flood mask pointed atPGID_MC:/* For a L2 MC group already on the flood mask, we keep it there * so that the host can still join/leave a group we had to give * up offloading. A front port that joins forwards according to * the flood masks, like the other members. */ if (lan9645x_mdb_on_flood_mask(mdb_entry, type)) return lan9645x_mdb_widen_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports);This fallback depended on
PGID_MCholding every front port, aslan9645x_setup()sets it. With this change, a port configured with:bridge link set dev swpN
mcast_floodoffis removed from
PGID_MC. If that port is also a registered member of an L2 group in the fallback state, will it stop receiving that group's traffic?
Quoted 6 lines
The software bridge still delivers registered groups to their members whatever their
mcast_floodsetting, so hardware forwarding would no longer match it. Also, when such a port joins through__lan9645x_mdb_add(), the join reports success but the port gets no traffic. The issue still seems to be there at the end of the series.
Dismissed, intended.
This is intended, as discussed for v14. Once a group has to fall back to PGID_MC it is forwarded like unregistered multicast, i.e. according to the mcast_flood configuration of the ports, including members that join while it is there. This matches mscc/ocelot, where an mdb add that cannot get a PGID leaves the group without a MAC table entry, so its traffic is flooded as unknown multicast. lan9645x cannot simply forget the entry, since host membership is carried by MAC_CPU_COPY in the entry and not by the flood masks, so it keeps the entry and points it at PGID_MC instead. A PGID with all ports would instead forward the group to non-members where mcast_flood was disabled.
The fallback is limited to non-IP L2 groups. IPv4 and IPv6 groups carry the port mask in the MAC table entry and never use a general purpose PGID, and groups with the same member ports share one, so it takes more than 48 distinct member sets among L2 groups to get here. The mdb patch documents the fallback to the flood masks.
Quoted 4 lines
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
PATCH v14 9/9 net: dsa: lan9645x: add port statistics
In reply to Jens Emil Schulz ØstergaardAdd statistics support for the port counters. Chip registers are 32 bit, so this unit is responsible for maintaining a 64bit software cache, and updating it frequently to handle overflows in hardware.
The pMAC counters are summed into the aggregate source. Reporting the eMAC and pMAC sources separately is not implemented, since MAC merge is not supported yet.
---
Changes in v14:
- Return 0 instead of -EOPNOTSUPP from get_sset_count() for string sets other than ETH_SS_STATS, since the DSA conduit adds the value to its own count.
- Describe in the commit message that the pMAC counters are summed into the aggregate source.
- Leave RMON fragments unset, since only the pMAC counts runts with an invalid CRC and the pMAC receives no traffic without MAC merge.
Changes in v12:
- Clear hardware and software counters lan9645x_stats_init().
- get_stats64: add the missing SCNT_RX_PMAC_LONG to rx_packets.
- get_stats64: move SCNT_DR_TAIL from rx_dropped to rx_missed_errors.
- Drop the unimplemented ISDX, ESDX and SFID counter views, the MAC merge statistics, and the now unused view back pointer, type and name fields.
- Rename lan9645x_stats_add_cnt() to lan9645x_stats_update_counter().
- Move lan9645x_get_vstats() out of lan9645x_stats.h and into lan9645x_stats.c, and replace the STATS_INDEX and STAT_COUNTERS macros with static functions there.
- Drop the NULL return from lan9645x_get_vstats(), and the three guards it forced on its callers.
- Drop the unreachable mac merge related code.
- get_eth_mac_stats: leave InRangeLengthErrors and OutOfRangeLengthField unset. Both describe the 802.3 length/type field, which the MAC does not validate.
- get_eth_mac_stats: leave SingleCollisionFrames unset. SCNT_TX_COL counts collision events, charging 16 to a frame that hits the excessive collision limit, so it cannot express the attribute. It is still reported as rtnl_link_stats64.collisions.
- get_eth_mac_stats: add SCNT_RX_JABBER to FrameTooLongErrors, the too-long-with-bad-CRC half of the event.
- get_stats64: drop SCNT_RX_SYMBOL_ERR from rx_errors, it is a subset of SCNT_RX_CRC which rx_crc_errors already covers. Still reported as SymbolErrorDuringCarrier.
- get_stats64: report rx_length_errors and rx_crc_errors. rx_length_errors carries the FrameTooLongErrors counters, and runts are left out of it since they have no 802.3 length attribute. SCNT_RX_SHORT is reported in rx_errors and rmon undersize_pkts instead.
- Size the bulk read scratch buffer for a single index rather than all of them. hw_lock is held across the read and the transfer into the 64 bit counters, so only one index is ever live.
- Stop the statistics poller in .shutdown. dsa_switch_shutdown() does not call .teardown, so the delayed work stays armed and keeps reading registers after the parent holding the regmaps has been shut down.
- Drop dr_tail from the ethtool -S list. It is reported as rtnl_link_stats64.rx_missed_errors.
- lan9645x_teardown(): stop the counter poller first, so nothing reads registers while the rest unwinds.
- Stop using SCNT_RX_FRAG. It counts frames received after the port is paused rather than undersize frames, so it is dropped from rx_errors, rx_packets and the rmon fragment count.
- get_stats64: drop SCNT_RX_CAT_DROP and SCNT_RX_LONG from rx_dropped. Classifier drops cover ordinary ingress filtering, and an oversized frame is an error rather than a drop, so it is reported in rx_errors and rx_length_errors.
- lan9645x_stats.h: include what it uses, and spell the ethtool statistics argument u64, matching the definition.
- Rate limit the bulk read error. It sits under the three second poller and runs once per port.
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 | 82 +- drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 3 + .../net/dsa/microchip/lan9645x/lan9645x_stats.c | 854 +++++++++++++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.h | 229 ++++++ 5 files changed, 1168 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -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 +81 -1
132 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +3 -0
@@ -219,6 +219,9 @@ struct lan9645x {*/ struct mutex mdb_lock; +/* Statistics */ +struct lan9645x_stats *stats; +int num_port_dis;/* VLAN entries */
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +854 -0
854 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +229 -0
229 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v14 9/9] net: dsa: lan9645x: add port statistics
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: dsa: lan9645x: spin_lock deadlock between process context and ndo_get_stats64 --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: dsa: lan9645x: spin_lock deadlock between process context and ndo_get_stats64 --
commit eaa26add9ac1e5f091f43891f8f2f615b10f01f1
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: lan9645x: add port statistics
This commit adds support for port statistics counters. It handles overflows in 32-bit hardware registers by maintaining a 64-bit software cache.
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c static void __lan9645x_stats_view_idx_update(struct lan9645x *lan9645x, · line 329
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -321,11 +321,11 @@ static void __lan9645x_stats_view_idx_update(struct lan9645x *lan9645x, enum lan9645x_view_stat_type vtype, int idx) {struct lan9645x_stats *s = lan9645x->stats;lockdep_assert_held (&s->hw_lock);if (!__lan9645x_stats_view_idx_hw_read (lan9645x, vtype, idx)) {spin_lock (&s->sw_lock);
[Severity: High]
Can this cause a deadlock? The periodic stats update workqueue and ethtool queries run in process context and acquire s->sw_lock here without disabling softirqs. Process-context lock acquisitions must use spin_lock_bh() to prevent a deadlock if a softirq tries to take the lock on the same CPU.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0__lan9645x_stats_view_idx_transfer (lan9645x, vtype, idx);spin_unlock (&s->sw_lock);}
}
[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -536,11 +536,11 @@ void lan9645x_stats_get_stats64(struct lan9645x *lan9645x, int port, struct rtnl_link_stats64 *stats) {struct lan9645x_stats *s = lan9645x->stats;u64 *c; c =lan9645x_stat_counters (lan9645x,LAN9645X_STAT_PORTS , port);/* ndo_get_stats64 may run in non-sleepable context (under * rcu_read_lock, or with a callers spinlock held as in bonding), so * unlike the ethtool paths we must not take the hw_lock mutex or touch * hardware here.
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0* sw_lock is never taken from softirq/IRQ context by any path, so a * plain spin_lock is sufficient, as in ocelot and ksz. */ spin_lock (&s->sw_lock);
[Severity: High]
Could this lead to a deadlock on s->sw_lock?
The comment indicates the lock is never taken from softirq/IRQ context, but ndo_get_stats64 can be called from atomic/softirq context (for example, when queried by bonding or netfilter).
If a softirq fires on the same CPU while the preempted process-context thread holds the lock (from __lan9645x_stats_view_idx_update), it will spin forever trying to acquire s->sw_lock.
Quoted 2 lines
stats->rx_bytes= c[SCNT_RX_OCT] + c[SCNT_RX_PMAC_OCT];
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213@microchip.com?part=9
[email protected]
AI reviewRe: [PATCH net-next v14 9/9] net: dsa: lan9645x: add port statistics
In reply to Jens Emil Schulz ØstergaardThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] lan9645x_stats_get_stats64() counts bad frames in rtnl_link_stats64.rx_packets.
- [Low] In lan9645x_stats_get_stats64(), rx_errors is the sum c[SCNT_RX_SHORT] + c[SCNT_RX_JABBER] + c[SCNT_RX_CRC] +…
- [Low] __lan9645x_stats_view_idx_hw_read() selects the port with lan_wr(SYS_STAT_CFG_STAT_VIEW_SET(idx), lan9645x, SYS_STAT_CFG).
--
net: dsa: lan9645x: add port statistics
This commit adds port statistics support to the lan9645x DSA driver. A delayed work polls the 32-bit hardware counters every 3 seconds and accumulates them into 64-bit software counters. The counters are exposed through ethtool -S, the standard ethtool stats groups and get_stats64, with the pMAC counters summed into the aggregate source.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -0,0 +1,854 @@
[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +12
-0+static void lan9645x_stats_update_counter (u64 *sw,u32 hw) +{ +if (hw < (*sw &U32_MAX )) + *sw += (u64 )1 <<32 ;/* value has wrapped */ + + *sw = (*sw & ~(u64 )U32_MAX ) + hw; +} + +static int __lan9645x_stats_view_idx_hw_read (struct lan9645x *lan9645x, +enum lan9645x_view_stat_type vtype, +int idx) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 280
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +1
-0+lan_wr (SYS_STAT_CFG_STAT_VIEW_SET (idx), lan9645x,SYS_STAT_CFG );
[Severity: Low]
What happens to the counters if this lan_wr() fails?
lan_wr() returns void and only does WARN_ON_ONCE(regmap_write(...)), so this function never sees a failed STAT_VIEW select. The SYS_CNT window read by the lan_bulk_rd() calls below is the same for every port. If the reads still succeed, buf holds the counters of the previously selected port.
__lan9645x_stats_view_idx_transfer() then passes those values through lan9645x_stats_update_counter() into the requested port's shadow. If the wrong value is larger, the shadow takes it. On the next correct poll, this check:
if (hw < (*sw & U32_MAX)) *sw += (u64)1 << 32; /* value has wrapped */
adds 2^32. That counter then stays about 4G too high until the next setup.
lan9645x_stats_clear_view() has the same unchecked write:
lan_wr(SYS_STAT_CFG_STAT_VIEW_SET(idx) | SYS_STAT_CFG_STAT_CLEAR_SHOT_SET(groups), lan9645x, SYS_STAT_CFG);
If that write is dropped, the poll for !CLEAR_SHOT passes at once and a clear that never happened is reported as success. That case looks harmless, since the shadow later takes the uncleared hardware value.
ocelot_port_update_stats() follows the same pattern, and every other lan_wr() in this driver also ignores write errors. Fixing this would probably mean having the helper return the regmap_write() result.
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +9
-0+ +/* Each region for this index contains counters which are at sequential +* addresses, so we can use bulk reads to ease lock pressure a bit. +*/ +for (int r =0 ; r < vstats->num_regions; r++) { + region = vstats->regions[r]; + err =lan_bulk_rd (&vstats->buf[region.cnts_base_idx], + region.cnt, lan9645x, +SYS_CNT (region.base_offset));
[ ... ]
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 13 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +13
-0+ stats->rx_bytes = c[SCNT_RX_OCT ] + c[SCNT_RX_PMAC_OCT ]; + + stats->rx_packets = c[SCNT_RX_SHORT ] + + 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 ] + + c[SCNT_RX_PMAC_SHORT] +
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 572
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_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 ] + + c[SCNT_RX_PMAC_LONG ];
[Severity: Medium]
Should rx_packets include the error counters?
The rtnl_link_stats64 documentation in include/uapi/linux/if_link.h describes rx_packets as "Number of good packets received by the interface". It describes rx_errors as "Total number of bad packets received on this network device".
SCNT_RX_SHORT, SCNT_RX_JABBER and SCNT_RX_LONG, plus their pMAC versions, are added to both rx_packets and rx_errors. Each runt, jabber and oversize frame is therefore counted as good and as bad.
The SZ_* buckets also seem to include CRC-errored frames. The v5 changelog removed rx_crc from rx_packets "as they are already counted in SZ_* buckets". So rx_packets ends up counting every frame received.
This also does not match FramesReceivedOK in lan9645x_stats_get_eth_mac_stats(), which is UC + MC + BC. The two standard interfaces would report different good RX counts for the same port.
ocelot_port_get_stats64() uses a similar formula. Is that the intended meaning of rx_packets for this new driver?
Separately, c[SCNT_RX_PMAC_FRAG] is added to rx_packets but not to rx_errors, while c[SCNT_RX_PMAC_SHORT] is added to both. The comment in lan9645x_stats_get_rmon_stats() says SCNT_RX_PMAC_FRAG counts runts with an invalid CRC.
Should SCNT_RX_PMAC_FRAG go into rx_errors too, or be removed from rx_packets? This has no effect until MAC merge sends traffic to the pMAC.
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +11
-0+ + stats->multicast = c[SCNT_RX_MC ] + c[SCNT_RX_PMAC_MC ]; + + stats->rx_errors = c[SCNT_RX_SHORT ] + + c[SCNT_RX_JABBER ] + + c[SCNT_RX_CRC ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_SHORT ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_CRC ] + + c[SCNT_RX_PMAC_LONG ];
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 593
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ + stats->rx_length_errors = c[SCNT_RX_JABBER ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_LONG ]; + +/* SCNT_RX_CRC counts CRC errors, alignment errors and RX_ER events at +* any frame size, so a short frame with a bad CRC is counted here. +*/ + stats->rx_crc_errors = c[SCNT_RX_CRC ] + c[SCNT_RX_PMAC_CRC ];
[Severity: Low]
Is a jabber frame counted twice in rx_errors?
This comment says SCNT_RX_CRC counts CRC errors "at any frame size". The v12 changelog describes SCNT_RX_JABBER as "the too-long-with-bad-CRC half of the event".
If both are true, an oversize frame with a bad FCS increments both SCNT_RX_CRC and SCNT_RX_JABBER. rx_errors above adds the two together.
If the hardware keeps these two counters disjoint, is the "any frame size" wording in this comment accurate?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com
Re: [PATCH net-next v14 9/9] net: dsa: lan9645x: add port statistics
Quoted 156 lines · On Mon, 2026-10-12 at 11:24 +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 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium]
lan9645x_stats_get_stats64()counts bad frames in rtnl_link_stats64.rx_packets.
- [Low] Inlan9645x_stats_get_stats64(),rx_errorsis the sum c[SCNT_RX_SHORT] + c[SCNT_RX_JABBER] + c[SCNT_RX_CRC] +…
- [Low]__lan9645x_stats_view_idx_hw_read()selects the port withlan_wr(SYS_STAT_CFG_STAT_VIEW_SET(idx), lan9645x, SYS_STAT_CFG).--
net: dsa: lan9645x: add port statistics
This commit adds port statistics support to the lan9645x DSA driver. A delayed work polls the 32-bit hardware counters every 3 seconds and accumulates them into 64-bit software counters. The counters are exposed through ethtool -S, the standard ethtool stats groups and
get_stats64, with the pMAC counters summed into the aggregate source.Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -0,0 +1,854 @@[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +12
-0+static void lan9645x_stats_update_counter (u64 *sw,u32 hw) +{ +if (hw < (*sw &U32_MAX )) + *sw += (u64 )1 <<32 ;/* value has wrapped */ + + *sw = (*sw & ~(u64 )U32_MAX ) + hw; +} + +static int __lan9645x_stats_view_idx_hw_read (struct lan9645x *lan9645x, +enum lan9645x_view_stat_type vtype, +int idx) +{[ ... ]
Quoted 1 line
+
lan_wr(SYS_STAT_CFG_STAT_VIEW_SET(idx), lan9645x, SYS_STAT_CFG);[Severity: Low]
What happens to the counters if thislan_wr()fails?
lan_wr()returns void and only does WARN_ON_ONCE(regmap_write(...)), so this function never sees a failedSTAT_VIEWselect. TheSYS_CNTwindow read by thelan_bulk_rd()calls below is the same for every port. If the reads still succeed, buf holds the counters of the previously selected port.
__lan9645x_stats_view_idx_transfer()then passes those values throughlan9645x_stats_update_counter()into the requested port's shadow. If the wrong value is larger, the shadow takes it. On the next correct poll, this check:if (hw < (*sw & U32_MAX)) *sw += (u64)1 << 32; /* value has wrapped */adds 2^32. That counter then stays about 4G too high until the next setup.
lan9645x_stats_clear_view()has the same unchecked write:lan_wr(SYS_STAT_CFG_STAT_VIEW_SET(idx) | SYS_STAT_CFG_STAT_CLEAR_SHOT_SET(groups), lan9645x, SYS_STAT_CFG);If that write is dropped, the poll for !CLEAR_SHOT passes at once and a clear that never happened is reported as success. That case looks harmless, since the shadow later takes the uncleared hardware value.
ocelot_port_update_stats()follows the same pattern, and every otherlan_wr()in this driver also ignores write errors. Fixing this would probably mean having the helper return theregmap_write()result.Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +9
-0+ +/* Each region for this index contains counters which are at sequential +* addresses, so we can use bulk reads to ease lock pressure a bit. +*/ +for (int r =0 ; r < vstats->num_regions; r++) { + region = vstats->regions[r]; + err =lan_bulk_rd (&vstats->buf[region.cnts_base_idx], + region.cnt, lan9645x, +SYS_CNT (region.base_offset));[ ... ]
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 13 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +13
-0+ stats->rx_bytes = c[SCNT_RX_OCT ] + c[SCNT_RX_PMAC_OCT ]; + + stats->rx_packets = c[SCNT_RX_SHORT ] + + 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 ] + + c[SCNT_RX_PMAC_SHORT] +drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 572
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_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 ] + + c[SCNT_RX_PMAC_LONG ];[Severity: Medium]
Shouldrx_packetsinclude the error counters?The
rtnl_link_stats64documentation ininclude/uapi/linux/if_link.hdescribesrx_packetsas "Number of good packets received by the interface". It describesrx_errorsas "Total number of bad packets received on this network device".
SCNT_RX_SHORT,SCNT_RX_JABBERandSCNT_RX_LONG, plus their pMAC versions, are added to bothrx_packetsandrx_errors. Each runt, jabber and oversize frame is therefore counted as good and as bad.The SZ_* buckets also seem to include CRC-errored frames. The v5 changelog removed
rx_crcfromrx_packets"as they are already counted in SZ_* buckets". Sorx_packetsends up counting every frame received.This also does not match FramesReceivedOK in
lan9645x_stats_get_eth_mac_stats(), which is UC + MC + BC. The two standard interfaces would report different good RX counts for the same port.
ocelot_port_get_stats64()uses a similar formula. Is that the intended meaning ofrx_packetsfor this new driver?
Quoted 8 lines
Separately, c[SCNT_RX_PMAC_FRAG] is added to
rx_packetsbut not torx_errors, while c[SCNT_RX_PMAC_SHORT] is added to both. The comment inlan9645x_stats_get_rmon_stats()saysSCNT_RX_PMAC_FRAGcounts runts with an invalid CRC.Should
SCNT_RX_PMAC_FRAGgo intorx_errorstoo, or be removed fromrx_packets? This has no effect until MAC merge sends traffic to the pMAC.
Dismissed, intended.
As for v14, this follows mscc/ocelot, which computes rx_packets the same way. The hardware has no good-frames-only octet counter, rx_oct counts octets in good and bad frames, so rx_bytes cannot follow the uapi description either. rx_packets is made to count the same frames rx_bytes counts octets for: the size buckets cover good and bad frames from 64 bytes up to MAXLEN, and short, fragment, jabber and long frames fall outside that range, so every received frame is counted once. Bad frames are also reported in rx_errors.
FramesReceivedOK is the 802.3 good frame count and is meant to differ, as it does in ocelot, where it is the sum of the green counters.
SCNT_RX_PMAC_FRAG is the size class below 64 bytes for pMAC runts with an invalid CRC, so it belongs in rx_packets next to the size buckets. Its frames are already in rx_errors through SCNT_RX_PMAC_CRC, which counts CRC errors at any frame size, in the same way a frame of 64 bytes or more with a bad CRC sits in a size bucket and in SCNT_RX_CRC. Adding it to rx_errors would count those runts twice.
Quoted 37 lines
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +11
-0+ + stats->multicast = c[SCNT_RX_MC ] + c[SCNT_RX_PMAC_MC ]; + + stats->rx_errors = c[SCNT_RX_SHORT ] + + c[SCNT_RX_JABBER ] + + c[SCNT_RX_CRC ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_SHORT ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_CRC ] + + c[SCNT_RX_PMAC_LONG ];drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 593
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ + stats->rx_length_errors = c[SCNT_RX_JABBER ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_LONG ]; + +/* SCNT_RX_CRC counts CRC errors, alignment errors and RX_ER events at +* any frame size, so a short frame with a bad CRC is counted here. +*/ + stats->rx_crc_errors = c[SCNT_RX_CRC ] + c[SCNT_RX_PMAC_CRC ];[Severity: Low]
Is a jabber frame counted twice inrx_errors?This comment says
SCNT_RX_CRCcounts CRC errors "at any frame size". The v12 changelog describesSCNT_RX_JABBERas "the too-long-with-bad-CRC half of the event".If both are true, an oversize frame with a bad FCS increments both
SCNT_RX_CRCandSCNT_RX_JABBER.rx_errorsabove adds the two together.If the hardware keeps these two counters disjoint, is the "any frame size" wording in this comment accurate?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213%40microchip.com