net: dsa: add DSA support for the LAN9645x switch chip family
Subsystems (5)
v13 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 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: lan9645x: add LAN9645X switch bindings
net: dsa: lan9645x: add autogenerated register macros
net: dsa: lan9645x: add basic dsa driver for LAN9645X
net: dsa: lan9645x: add 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 | 177 ++ 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 | 1031 +++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 435 +++++ drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 569 ++++++ 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 | 856 +++++++++ .../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 | 474 +++++ 22 files changed, 7154 insertions(+)
---
base-commit: 014d795c73837ea2339a4ea8e8f82c6e959b845d
change-id: 20260210-dsa_lan9645x_switch_driver_base-312bbfc37edb
Best regards,
Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
PATCH v13 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, except when it equals the port pvid, where a frame tagged with the pvid is indistinguishable from an untagged one.
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.
---
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 | 474 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 550 insertions(+)
MAINTAINERS +8 -0
@@ -17800,6 +17800,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 +474 -0
474 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v13 1/9] net: dsa: add tag driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] net: dsa: lan9645x: VLAN hopping via fragmented in-band VLAN tags --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] net: dsa: lan9645x: VLAN hopping via fragmented in-band VLAN tags --
commit f7552b4bce99ac2975ea8145332463c0a3772965
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: add tag driver for LAN9645X
This commit adds a DSA tag driver for LAN9645x switches using an NPI port. It implements asymmetric prefix configurations, using a long prefix for extraction and an internal frame header (IFH) for both extraction and injection.
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0
-0
[ ... ]
Quoted 7 lines
net/dsa/tag_lan9645x.c new file +7
-0+static struct sk_buff *lan9645x_xmit_get_vlan_info (struct sk_buff *skb, +struct net_device *br, +u32 *vlan_tci, +u32 *tag_type) +{ +struct vlan_ethhdr *hdr; +u16 proto, tci;
[ ... ]
net/dsa/tag_lan9645x.c line 266
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+if (skb_headlen (skb) >=VLAN_ETH_HLEN && +ntohs (hdr->h_vlan_proto) == proto) { +vlan_remove_tag (skb, &tci); + *vlan_tci = tci; + }else {
[Severity: Critical]
Does this logic allow VLAN isolation bypass for fragmented in-band VLAN tags?
If a user with raw socket access constructs a frame where the 14-byte MAC header is linear, but the in-band 802.1Q VLAN tag is placed in paged fragments, skb_headlen(skb) >= VLAN_ETH_HLEN will evaluate to false.
Instead of linearizing the header to securely process the VLAN tag using pskb_may_pull(), the code takes this else branch. This misclassifies the packet as untagged and assigns it the bridge's PVID, leaving the original spoofed 802.1Q tag untouched in the payload.
When the frame is later injected into the switch, the hardware rewriter won't pop the payload tag since the switch believes the frame is untagged. The packet would then be transmitted on the wire retaining the user's spoofed 802.1Q tag, completely bypassing the bridge's VLAN filtering and isolation.
Quoted 11 lines
net/dsa/tag_lan9645x.c new file +11
-0+rcu_read_lock (); +br_vlan_get_pvid_rcu (br, &tci); +rcu_read_unlock (); + *vlan_tci = tci; + } + + *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/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2@microchip.com?part=1
[email protected]
AI reviewRe: [PATCH net-next v13 1/9] net: dsa: add tag driver for LAN9645X
In reply to Jens Emil Schulz ØstergaardThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 2 · 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).
- [High] In lan9645x_xmit_get_vlan_info() (net/dsa/tag_lan9645x.c), any frame with no in-band tag matching the bridge protocol gets IFH_TCI…
- [Medium] lan9645x_netdev_ops sets no .flow_dissect, so __skb_flow_dissect() (net/core/flow_dissector.c:1083-1098) falls back…
- [Medium] When the IFH-classified VID equals the port pvid, lan9645x_rcv() skips restoring the tag (tag_lan9645x.c:451-453).
- [Low] In lan9645x_xmit_get_vlan_info(), the condition `skb_headlen(skb)
Quoted 1 line
=
VLAN_ETH_HLEN&&ntohs(hdr->h_vlan_proto)== proto` treats a VLAN…
- [Low] In lan9645x_xmit_get_vlan_info(), the guard skb_headlen(skb) >= VLAN_ETH_HLEN in front of vlan_remove_tag() does not cover every byte…
- [Low] lan9645x_rcv() always restores the classified VLAN as ETH_P_8021Q.
Pre-existing issues:
- [High] lan9645x_xmit() calls dsa_port_bridge_dev_get(dp) (include/net/dsa.h:774-778, `dp->bridge ?
--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch, which uses a front port as the NPI CPU port. On extraction, frames carry a 16 byte long prefix plus a 28 byte IFH. On injection, frames carry only the IFH. On receive, the classified VLAN is restored as a hwaccel C-tag unless it equals the port pvid.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,474 @@
[ ... ]
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 264
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +6
-0+ hdr =skb_vlan_eth_hdr (skb); +br_vlan_get_proto (br, &proto); + +if (skb_headlen (skb) >=VLAN_ETH_HLEN && +ntohs (hdr->h_vlan_proto) == proto) { +vlan_remove_tag (skb, &tci);
[Severity: Low]
What happens when the VLAN header is not fully in the linear area?
Because of the skb_headlen() check, a tagged frame with a short linear head goes to the else branch. The original 802.1Q tag then stays in the payload, and IFH_TCI is set to br0's pvid.
dsa_user_xmit() does not linearize the skb here. The user netdev inherits NETIF_F_SG from conduit->vlan_features in dsa_user_setup_tagger(). The AF_PACKET PACKET_TX_RING path, tpacket_snd()->tpacket_fill_skb(), copies only hard_header_len (14) bytes into the linear area.
Could the rewriter then push a second tag, so the frame goes out double-tagged or in the wrong VLAN? Would a pskb_may_pull() of VLAN_ETH_HLEN before this check avoid that?
[Severity: Low]
Is the VLAN_ETH_HLEN check enough for vlan_remove_tag()?
When h_vlan_encapsulated_proto is an 802.3 length, vlan_set_encap_proto() also reads the two bytes after the VLAN header:
include/linux/if_vlan.h:vlan_set_encap_proto() {
...
rawp = (unsigned short *)(vhdr + 1);
if (*rawp == 0xFFFF)
...
}lan9645x has no needed_tailroom, so dsa_user_xmit() does not pad the frame. skb_put_padto() in lan9645x_xmit() only runs after this function returns.
Take an 18 or 19 byte frame such as DA SA 8100 TCI <len>. Can this read uninitialized tailroom past skb_tail_pointer()? The only effect is whether skb->protocol becomes ETH_P_802_3 or ETH_P_802_2, but KMSAN would likely report an uninit-value.
net/dsa/tag_lan9645x.c line 269
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+ *vlan_tci = tci; + }else { +rcu_read_lock (); +br_vlan_get_pvid_rcu (br, &tci); +rcu_read_unlock ();
[Severity: High]
Is br_vlan_get_pvid_rcu() being passed the right device here?
br comes from dsa_port_bridge_dev_get(), so it is the bridge master. This call returns the pvid of br0's own VLAN group. That VID is unrelated to the egress port and to the VLAN the bridge forwarded the frame in, because br_handle_vlan() already cleared the tag for an egress-untagged VLAN.
lan9645x_xmit() then writes that VID into IFH_TCI with IFH_BYPASS set, so the rewriter uses it as the classified VID:
lan9645x_ifh_set(ifh, 1, IFH_BYPASS, IFH_BYPASS_SZ); ... lan9645x_ifh_set(ifh, vlan_tci, IFH_TCI, IFH_TCI_SZ);
The later "net: dsa: lan9645x: add vlan support" patch changes lan9645x_vlan_port_apply_egress(). It programs a hybrid port (one untagged VLAN plus tagged VLANs) as LAN9645X_TAG_NO_PVID_NO_UNAWARE, with PORT_VID set to the untagged VID. In that mode every frame is tagged unless VID == PORT_VID or VID == 0.
For example, say br0 has pvid 1 (the default), and swp1 has VLAN 10 as pvid/untagged plus VLAN 20 tagged. A frame sent by the host in VLAN 10 (from br0.10, or ARP flooded by the bridge) reaches this code untagged and gets VID 1. So does a frame forwarded in software in VLAN 10.
Would the switch then send it on the wire tagged with VLAN 1 instead of untagged in VLAN 10?
Quoted 2 lines
net/dsa/tag_lan9645x.c new file +2
-0+ *vlan_tci = tci; + }
[ ... ]
net/dsa/tag_lan9645x.c line 299
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: High]
This isn't a bug introduced by this patch. The racy pattern is in the DSA core and is already used by tag_ocelot, tag_sja1105, tag_dsa and others; this tagger adds another user of it.
dsa_port_bridge_dev_get() reads dp->bridge twice on the TX path. It holds no lock and uses neither READ_ONCE() nor RCU:
return dp->bridge ? dp->bridge->dev : NULL;
The following path runs under rtnl:
del_nbp()
netdev_upper_dev_unlink()
dsa_port_bridge_leave()
dsa_port_bridge_destroy()
It clears dp->bridge and, on the last reference, frees the dsa_bridge without waiting for a grace period:
net/dsa/port.c:dsa_port_bridge_destroy() {
...
dp->bridge = NULL;
if (!refcount_dec_and_test(&bridge->refcount))
return;
...
kfree(bridge);
}TX on the user port (AF_PACKET or locally generated traffic) is not quiesced at that point.
Can a concurrent lan9645x_xmit() read ->dev from freed memory, or reload dp->bridge after it became NULL? The result is then passed to br_vlan_enabled(), br_vlan_get_proto() and br_vlan_get_pvid_rcu().
[ ... ]
Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3
-0+static struct sk_buff *lan9645x_rcv (struct sk_buff *skb, +struct net_device *ndev) +{
[ ... ]
Quoted 8 lines
net/dsa/tag_lan9645x.c new file +8
-0+ dp =dsa_user_to_port (skb->dev); + +if (dsa_port_is_vlan_filtering (dp) && vlan_tci) { +u16 port_pvid =0 ; + +br_vlan_get_pvid_rcu (skb->dev, &port_pvid); + +/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH
net/dsa/tag_lan9645x.c line 453
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+* 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. +*/ +if ((vlan_tci &VLAN_VID_MASK ) != port_pvid) +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), + vlan_tci);
[Severity: Medium]
What happens to a double-tagged frame whose outer VID equals the pvid?
The later "net: dsa: lan9645x: add vlan support" patch sets ANA_VLAN_CFG_VLAN_POP_CNT=1 without VLAN_INNER_TAG_ENA, so VLAN-aware ports pop exactly one tag.
Take outer VID 100 (the pvid) with an inner C-tag 200. The frame is extracted with popcnt == 3, the inner tag is still in the payload, and IFH_TCI reports VID 100.
No tag is restored here in that case. eth_type_trans() in dsa_switch_rcv() then sets skb->protocol to 0x8100, and __netif_receive_skb_core() turns the inner tag into hwaccel VID 200 via skb_vlan_untag().
Would the software bridge then classify the frame to VLAN 200, while the hardware forwarded it in VLAN 100?
[Severity: Low]
The commit message says this assumes an 802.1Q bridge:
This assumes a bridge vlan_protocol of 802.1Q, which is the only protocol the driver offloads.
The later "net: dsa: lan9645x: add vlan support" patch documents the same limitation. Is anything enforcing it?
DSA does not handle SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL, and __br_vlan_set_proto() sends it with SWITCHDEV_F_SKIP_EOPNOTSUPP. So an 802.1ad bridge cannot be refused that way.
On such a bridge, __allowed_ingress() sees skb->vlan_proto != br->vlan_proto. It pushes the tag back into the payload and classifies the frame to the pvid. Terminated frames on non-pvid VLANs would then land on the pvid, or be dropped if the port has no pvid.
lan9645x_xmit_get_vlan_info(), on the other hand, handles 802.1ad explicitly:
*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S : LAN9645X_IFH_TAG_TYPE_C;
Should 802.1ad bridges be refused in port_bridge_join? Should xmit and rcv also handle an 802.1ad bridge the same way?
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+ } + +return skb; +} +
net/dsa/tag_lan9645x.c line 468
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+static const struct dsa_device_ops lan9645x_netdev_ops = { + .name =LAN9645X_NAME , + .proto =DSA_TAG_PROTO_LAN9645X , + .xmit = lan9645x_xmit, + .rcv = lan9645x_rcv, +/* Covers the extraction prefix too, since dsa_tag_protocol_overhead() +* sizes the conduit MTU from this. +*/ + .needed_headroom =LAN9645X_TOTAL_TAG_LEN , +};
[Severity: Medium]
There is no .flow_dissect callback here, so __skb_flow_dissect() falls back to dsa_tag_generic_flow_dissect(). That helper assumes the tag overhead is exactly needed_headroom:
include/net/dsa.h:dsa_tag_generic_flow_dissect() {
...
*offset = tag_len;
*proto = ((__be16 *)skb->data)[(tag_len / 2) - 1];
}Does that hold for this tagger? Whenever the rewriter popped tags, lan9645x_rcv() skips a 4 or 8 byte ifh_gap_len between the IFH and the real DMAC.
The later "net: dsa: lan9645x: add vlan support" patch sets ANA_VLAN_CFG_VLAN_POP_CNT=1 on VLAN-aware ports. So every tagged frame received on those ports has a 4 byte gap.
For those frames, would the generic dissector take SMAC or gap bytes as the EtherType and use the wrong network header offset? That would misdirect RPS and skb_get_hash() on the conduit.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 1/9] net: dsa: add tag driver for LAN9645X
Quoted 128 lines · On Fri, 2026-10-02 at 21:14 +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 6 potential issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 2 · 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).
- [High] In
lan9645x_xmit_get_vlan_info()(net/dsa/tag_lan9645x.c), any frame with no in-band tag matching the bridge protocol gets IFH_TCI…
- [Medium]lan9645x_netdev_opssets no .flow_dissect, so__skb_flow_dissect()(net/core/flow_dissector.c:1083-1098) falls back…
- [Medium] When the IFH-classified VID equals the port pvid,lan9645x_rcv()skips restoring the tag (tag_lan9645x.c:451-453).
- [Low] Inlan9645x_xmit_get_vlan_info(), the condition `skb_headlen(skb)Quoted 1 line
=
VLAN_ETH_HLEN&&ntohs(hdr->h_vlan_proto)== proto` treats a VLAN…- [Low] In
lan9645x_xmit_get_vlan_info(), the guardskb_headlen(skb) >= VLAN_ETH_HLENin front ofvlan_remove_tag()does not cover every byte…
- [Low]lan9645x_rcv()always restores the classified VLAN asETH_P_8021Q.Pre-existing issues:
- [High]lan9645x_xmit()callsdsa_port_bridge_dev_get(dp)(include/net/dsa.h:774-778, `dp->bridge ?--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch, which uses a front port as the NPI CPU port. On extraction, frames carry a 16 byte long prefix plus a 28 byte IFH. On injection, frames carry only the IFH. On receive, the classified VLAN is restored as a hwaccel C-tag unless it equals the port pvid.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,474 @@[ ... ]
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 264
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +6
-0+ hdr =skb_vlan_eth_hdr (skb); +br_vlan_get_proto (br, &proto); + +if (skb_headlen (skb) >=VLAN_ETH_HLEN && +ntohs (hdr->h_vlan_proto) == proto) { +vlan_remove_tag (skb, &tci);[Severity: Low]
What happens when the VLAN header is not fully in the linear area?Because of the
skb_headlen()check, a tagged frame with a short linear head goes to the else branch. The original 802.1Q tag then stays in the payload, andIFH_TCIis set to br0's pvid.
dsa_user_xmit()does not linearize the skb here. The user netdev inheritsNETIF_F_SGfromconduit->vlan_featuresindsa_user_setup_tagger(). TheAF_PACKETPACKET_TX_RINGpath, tpacket_snd()->tpacket_fill_skb(), copies onlyhard_header_len(14) bytes into the linear area.Could the rewriter then push a second tag, so the frame goes out double-tagged or in the wrong VLAN? Would a
pskb_may_pull()ofVLAN_ETH_HLENbefore this check avoid that?[Severity: Low]
Is theVLAN_ETH_HLENcheck enough forvlan_remove_tag()?When
h_vlan_encapsulated_protois an 802.3 length,vlan_set_encap_proto()also reads the two bytes after the VLAN header:include/linux/if_vlan.h:vlan_set_encap_proto() { ... rawp = (unsigned short *)(vhdr + 1); if (*rawp == 0xFFFF) ... }lan9645x has no
needed_tailroom, sodsa_user_xmit()does not pad the frame.skb_put_padto()inlan9645x_xmit()only runs after this function returns.Take an 18 or 19 byte frame such as DA SA 8100 TCI <len>. Can this read uninitialized tailroom past
skb_tail_pointer()? The only effect is whetherskb->protocolbecomesETH_P_802_3orETH_P_802_2, but KMSAN would likely report an uninit-value.net/dsa/tag_lan9645x.c line 269
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+ *vlan_tci = tci; + }else { +rcu_read_lock (); +br_vlan_get_pvid_rcu (br, &tci); +rcu_read_unlock ();[Severity: High]
Isbr_vlan_get_pvid_rcu()being passed the right device here?br comes from
dsa_port_bridge_dev_get(), so it is the bridge master. This call returns the pvid of br0's own VLAN group. That VID is unrelated to the egress port and to the VLAN the bridge forwarded the frame in, becausebr_handle_vlan()already cleared the tag for an egress-untagged VLAN.
lan9645x_xmit()then writes that VID intoIFH_TCIwithIFH_BYPASSset, so the rewriter uses it as the classified VID:lan9645x_ifh_set(ifh, 1, IFH_BYPASS, IFH_BYPASS_SZ); ... lan9645x_ifh_set(ifh, vlan_tci, IFH_TCI, IFH_TCI_SZ);The later "net: dsa: lan9645x: add vlan support" patch changes
lan9645x_vlan_port_apply_egress(). It programs a hybrid port (one untagged VLAN plus tagged VLANs) asLAN9645X_TAG_NO_PVID_NO_UNAWARE, withPORT_VIDset to the untagged VID. In that mode every frame is tagged unless VID ==PORT_VIDor VID == 0.
Quoted 7 lines
For example, say br0 has pvid 1 (the default), and swp1 has VLAN 10 as pvid/untagged plus VLAN 20 tagged. A frame sent by the host in VLAN 10 (from br0.10, or ARP flooded by the bridge) reaches this code untagged and gets VID 1. So does a frame forwarded in software in VLAN 10.
Would the switch then send it on the wire tagged with VLAN 1 instead of untagged in VLAN 10?
This is legitimate. I will fix this.
Quoted 47 lines
Quoted 3 lines
net/dsa/tag_lan9645x.c new file +2
-0+ *vlan_tci = tci; + }[ ... ]
net/dsa/tag_lan9645x.c line 299
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: High]
This isn't a bug introduced by this patch. The racy pattern is in the DSA core and is already used bytag_ocelot,tag_sja1105,tag_dsaand others; this tagger adds another user of it.
dsa_port_bridge_dev_get()readsdp->bridgetwice on the TX path. It holds no lock and uses neitherREAD_ONCE()nor RCU:return dp->bridge ? dp->bridge->dev : NULL;The following path runs under rtnl:
del_nbp()
netdev_upper_dev_unlink()
dsa_port_bridge_leave()
dsa_port_bridge_destroy()It clears
dp->bridgeand, on the last reference, frees thedsa_bridgewithout waiting for a grace period:net/dsa/port.c:dsa_port_bridge_destroy() { ... dp->bridge = NULL; if (!refcount_dec_and_test(&bridge->refcount)) return; ... kfree(bridge); }
Quoted 9 lines
TX on the user port (
AF_PACKETor locally generated traffic) is not quiesced at that point.Can a concurrent
lan9645x_xmit()read ->dev from freed memory, or reloaddp->bridgeafter it became NULL? The result is then passed tobr_vlan_enabled(),br_vlan_get_proto()andbr_vlan_get_pvid_rcu().[ ... ]
Dismissed.
This is preexisting and a DSA core pattern shared with tag_ocelot, tag_dsa, tag_sja1105, tag_vsc73xx_8021q and dsa_software_vlan_untag(). dsa_bridge is freed in dsa_port_bridge_destroy() without a grace period, so no tagger can fix it locally.
Quoted 36 lines
Quoted 3 lines
net/dsa/tag_lan9645x.c new file +3
-0+static struct sk_buff *lan9645x_rcv (struct sk_buff *skb, +struct net_device *ndev) +{[ ... ]
Quoted 8 lines
net/dsa/tag_lan9645x.c new file +8
-0+ dp =dsa_user_to_port (skb->dev); + +if (dsa_port_is_vlan_filtering (dp) && vlan_tci) { +u16 port_pvid =0 ; + +br_vlan_get_pvid_rcu (skb->dev, &port_pvid); + +/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH net/dsa/tag_lan9645x.c line 453
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+* 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. +*/ +if ((vlan_tci &VLAN_VID_MASK ) != port_pvid) +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), + vlan_tci);[Severity: Medium]
What happens to a double-tagged frame whose outer VID equals the pvid?The later "net: dsa: lan9645x: add vlan support" patch sets ANA_VLAN_CFG_VLAN_POP_CNT=1 without
VLAN_INNER_TAG_ENA, so VLAN-aware ports pop exactly one tag.Take outer VID 100 (the pvid) with an inner C-tag 200. The frame is extracted with popcnt == 3, the inner tag is still in the payload, and
IFH_TCIreports VID 100.
Quoted 7 lines
No tag is restored here in that case.
eth_type_trans()indsa_switch_rcv()then setsskb->protocolto0x8100, and__netif_receive_skb_core()turns the inner tag into hwaccel VID 200 viaskb_vlan_untag().Would the software bridge then classify the frame to VLAN 200, while the hardware forwarded it in VLAN 100?
Correct. The pvid comparison in lan9645x_rcv() assumed a frame tagged with the pvid cannot be told apart from an untagged one, but the IFH reports whether the rewriter popped a tag. v14 restores the classified VID as a hwaccel tag whenever a tag was popped.
Quoted 58 lines
[Severity: Low]
The commit message says this assumes an 802.1Q bridge:This assumes a bridge
vlan_protocolof 802.1Q, which is the only protocol the driver offloads.The later "net: dsa: lan9645x: add vlan support" patch documents the same limitation. Is anything enforcing it?
DSA does not handle
SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL, and__br_vlan_set_proto()sends it withSWITCHDEV_F_SKIP_EOPNOTSUPP. So an 802.1ad bridge cannot be refused that way.On such a bridge,
__allowed_ingress()seesskb->vlan_proto!=br->vlan_proto. It pushes the tag back into the payload and classifies the frame to the pvid. Terminated frames on non-pvid VLANs would then land on the pvid, or be dropped if the port has no pvid.
lan9645x_xmit_get_vlan_info(), on the other hand, handles 802.1ad explicitly:*tag_type = (proto != ETH_P_8021Q) ? LAN9645X_IFH_TAG_TYPE_S : LAN9645X_IFH_TAG_TYPE_C;Should 802.1ad bridges be refused in
port_bridge_join? Should xmit and rcv also handle an 802.1ad bridge the same way?Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+ } + +return skb; +} +net/dsa/tag_lan9645x.c line 468
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+static const struct dsa_device_ops lan9645x_netdev_ops = { + .name =LAN9645X_NAME , + .proto =DSA_TAG_PROTO_LAN9645X , + .xmit = lan9645x_xmit, + .rcv = lan9645x_rcv, +/* Covers the extraction prefix too, since dsa_tag_protocol_overhead() +* sizes the conduit MTU from this. +*/ + .needed_headroom =LAN9645X_TOTAL_TAG_LEN , +};[Severity: Medium]
There is no .flow_dissect callback here, so__skb_flow_dissect()falls back todsa_tag_generic_flow_dissect(). That helper assumes the tag overhead is exactlyneeded_headroom:include/net/dsa.h:dsa_tag_generic_flow_dissect() { ... *offset = tag_len; *proto = ((__be16 *)skb->data)[(tag_len / 2) - 1]; }Does that hold for this tagger? Whenever the rewriter popped tags,
lan9645x_rcv()skips a 4 or 8 byteifh_gap_lenbetween the IFH and the real DMAC.
Quoted 8 lines
The later "net: dsa: lan9645x: add vlan support" patch sets ANA_VLAN_CFG_VLAN_POP_CNT=1 on VLAN-aware ports. So every tagged frame received on those ports has a 4 byte gap.
For those frames, would the generic dissector take SMAC or gap bytes as the EtherType and use the wrong network header offset? That would misdirect RPS and
skb_get_hash()on the conduit.
Correct, the generic dissector takes needed_headroom as the rx tag length, which only holds when the rewriter did not pop a tag on extraction. v14 adds a .flow_dissect callback.
Quoted 2 lines
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
pw-bot: cr
PATCH v13 2/9 dt-bindings: net: lan9645x: add LAN9645X switch bindings
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 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 | 177 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +177 -0
@@ -0,0 +1,177 @@ +# 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: Chip top level target + - description: Rewriter target + - 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: Analyzer target + + reg-names: + items: + - const: gcb + - const: qs + - const: chip_top + - const: rew + - 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: 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>, <0x10000 0x134>, + <0x18000 0x1910>, <0x2c000 0x12d4>, <0x30000 0xe4>, + <0x38000 0xb8>, <0x3c000 0xb8>, <0x40000 0xb8>, + <0x44000 0xb8>, <0x48000 0xb8>, <0x4c000 0xb8>, + <0x50000 0xb8>, <0x54000 0xb8>, <0x58000 0xb8>, + <0x100000 0xa000>, <0x140000 0x7468>; + reg-names = "gcb", "qs", "chip_top", "rew", "sys", "hsio", "dev0", + "dev1", "dev2", "dev3", "dev4", "dev5", "dev6", "dev7", + "dev8", "qsys", "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
@@ -17805,6 +17805,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
[email protected]
AI reviewRe: [PATCH net-next v13 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: strict property validation disabled by additionalProperties: true --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: strict property validation disabled by additionalProperties: true --
commit 37a55f2415392987ad4b328233f6c32282b21103
Author: Jens Emil Schulz Østergaard <[email protected]>
dt-bindings: net: lan9645x: add LAN9645X switch bindings
This commit adds bindings for the LAN9645X switch, which uses a fallback compatible for the smallest SKU microchip,lan96455s-switch. The switch is a child of an externally controlled parent that hands out one regmap per register target.
Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 90
Quoted 13 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +13
-0+ ethernet-ports: + type: object + additionalProperties: true + patternProperties: + "^(ethernet-)?port@[0-8]$": + type: object + description: Ethernet switch ports + additionalProperties: true + + allOf: + - if: + properties: + phy-mode:
[Severity: Low]
Does setting additionalProperties: true here introduce a validation regression by unintentionally defeating the unevaluatedProperties: false strictness checks inherited from dsa.yaml?
Because additionalProperties: true causes dt-schema to mark all unknown properties as evaluated, it allows any undefined or misspelled properties inside the child port nodes to silently pass validation.
Could this also cause a regression in the conditional if-then logic below? If restricted properties like rx-internal-delay-ps are specified on non-RGMII ports, the if condition fails and the constraint is skipped, but instead of being rejected, the property is silently allowed unrestricted by
additionalProperties: true.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2@microchip.com?part=2
[email protected]
AI reviewRe: [PATCH net-next v13 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings
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] The binding makes rx/tx-internal-delay-ps on the MAC-side switch port nodes an on/off switch for the full 2 ns RGMII delay…
- [Low] The per-port pattern "^(ethernet-)?port@[0-8]$" in properties/ethernet-ports does not actually limit ports to the 9…
- [Low] The subject "dt-bindings: net: lan9645x: add LAN9645X switch bindings" does not follow…
--
dt-bindings: net: lan9645x: add LAN9645X switch bindings
This commit adds a DT binding for the Microchip LAN9645x DSA switch. The smallest SKU, microchip,lan96455s-switch, is the fallback compatible. The switch register targets are described through reg and reg-names, following mscc,vsc7514-switch.yaml.
Quoted 1 line
dt-bindings: net: lan9645x: add LAN9645X switch bindings
[Severity: Low]
This isn't a bug, but the subject doesn't match what Documentation/devicetree/bindings/submitting-patches.rst asks for. That file says "Repeating "binding" again should also be avoided". Its example form is "dt-bindings: iio: adc: Add ROHM BD79100G".
The file lives under net/dsa/, so the usual prefix is "dt-bindings: net: dsa:". Something like "dt-bindings: net: dsa: Add Microchip LAN9645x switch" would fit better.
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 82
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]
Does this pattern actually restrict port nodes to the 9 hardware ports (dev0..dev8)?
ethernet-ports has additionalProperties: true, so nodes that don't match "^(ethernet-)?port@[0-8]$" are not rejected here. The inherited dsa.yaml#/$defs/ethernet-ports and ethernet-switch.yaml both accept any "^(ethernet-)?port@[0-9a-f]+$" node through dsa-port.yaml.
So a node like ethernet-port@9 { reg = <9>; ... } or ethernet-port@a passes dt_binding_check and dtbs_check. It also skips the local RGMII delay constraints. The problem only shows up at probe time:
net/dsa/dsa.c: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);
...
}Should the 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 120
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: Medium]
Is it intended that rx/tx-internal-delay-ps on the MAC side port nodes turns the full 2 ns RGMII delay on and off, for all four rgmii phy-modes?
Documentation/devicetree/bindings/net/ethernet-controller.yaml says these MAC node properties "should 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 same document says that when the MAC adds the delay, 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."
This schema accepts phy-mode = "rgmii-id" together with rx-internal-delay-ps = <2000>. In the driver later in this series, lan9645x_parse_mac_delay() in lan9645x_port.c only checks for 0 or 2000. lan9645x_rgmii_dll_config() in lan9645x_phylink.c then enables the delay line directly from the parsed value:
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c:lan9645x_rgmii_dll_config() {
...
HSIO_DLL_CFG_DLL_ENA_SET(p->rx_internal_delay) |
HSIO_DLL_CFG_DELAY_ENA_SET(p->rx_internal_delay),
...
}Nothing there checks phy-mode or removes the delay from the interface that phylink passes to the PHY.
Take port 7 or 8 with a phy-handle, phy-mode "rgmii-id" and rx-internal-delay-ps = <2000>. Wouldn't the MAC and the PHY each add 2 ns, leaving a DT that passes validation with a link that doesn't work?
The example also uses phy-mode = "rgmii" on the CPU port. For any RGMII mode other than 'rgmii-id', ethernet-controller.yaml says it "is probably wrong" unless justified.
Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +2
-0+ +examples:
[ ... ]
Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +4
-0+ ethernet-port@7 { + reg = <7>; + ethernet = <&cpu_host_port>; + phy-mode = "rgmii";
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings
Quoted 37 lines · On Fri, 2026-10-02 at 21:14 +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 binding makes rx/tx-internal-delay-ps on the MAC-side switch port nodes an on/off switch for the full 2 ns RGMII delay…
- [Low] The per-port pattern "^(ethernet-)?port@[0-8]$" in properties/ethernet-ports does not actually limit ports to the 9…
- [Low] The subject "dt-bindings: net: lan9645x: add LAN9645X switch bindings" does not follow…--
dt-bindings: net: lan9645x: add LAN9645X switch bindings
This commit adds a DT binding for the Microchip LAN9645x DSA switch. The smallest SKU, microchip,lan96455s-switch, is the fallback compatible. The switch register targets are described through reg and reg-names, following mscc,vsc7514-switch.yaml.
Quoted 1 line
dt-bindings: net: lan9645x: add LAN9645X switch bindings
[Severity: Low]
This isn't a bug, but the subject doesn't match whatDocumentation/devicetree/bindings/submitting-patches.rstasks for. That file says "Repeating "binding" again should also be avoided". Its example form is "dt-bindings: iio: adc: Add ROHM BD79100G".
Quoted 4 lines
The file lives under
net/dsa/, so the usual prefix is "dt-bindings: net: dsa:". Something like "dt-bindings: net: dsa: Add Microchip LAN9645x switch" would fit better.
I will retitle.
Quoted 97 lines
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0
-0[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 82
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]
Does this pattern actually restrict port nodes to the 9 hardware ports (dev0..dev8)?ethernet-ports has additionalProperties: true, so nodes that don't match "^(ethernet-)?port@[0-8]$" are not rejected here. The inherited dsa.yaml#/$defs/ethernet-ports and
ethernet-switch.yamlboth accept any "^(ethernet-)?port@[0-9a-f]+$" node throughdsa-port.yaml.So a node like ethernet-port@9 { reg = <9>; ... } or ethernet-port@a passes
dt_binding_checkanddtbs_check. It also skips the local RGMII delay constraints. The problem only shows up at probe time:net/dsa/dsa.c: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); ... }Should the 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 120
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: Medium]
Is it intended that rx/tx-internal-delay-ps on the MAC side port nodes turns the full 2 ns RGMII delay on and off, for all four rgmii phy-modes?
Documentation/devicetree/bindings/net/ethernet-controller.yamlsays these MAC node properties "should 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 same document says that when the MAC adds the delay, 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."
This schema accepts phy-mode = "rgmii-id" together with rx-internal-delay-ps = <2000>. In the driver later in this series,
lan9645x_parse_mac_delay()inlan9645x_port.conly checks for 0 or 2000.lan9645x_rgmii_dll_config()inlan9645x_phylink.cthen enables the delay line directly from the parsed value:drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c:lan9645x_rgmii_dll_config() { ... HSIO_DLL_CFG_DLL_ENA_SET(p->rx_internal_delay) | HSIO_DLL_CFG_DELAY_ENA_SET(p->rx_internal_delay), ... }Nothing there checks phy-mode or removes the delay from the interface that phylink passes to the PHY.
Quoted 8 lines
Take port 7 or 8 with a phy-handle, phy-mode "rgmii-id" and rx-internal-delay-ps = <2000>. Wouldn't the MAC and the PHY each add 2 ns, leaving a DT that passes validation with a link that doesn't work?
The example also uses phy-mode = "rgmii" on the CPU port. For any RGMII mode other than 'rgmii-id',
ethernet-controller.yamlsays it "is probably wrong" unless justified.
Dismissed. This follows the binding model introduced for sja1105 in commit ac41ac81e331 ("dt-bindings: net: dsa: sja1105: add {rx,tx}-internal-delay-ps") and used by microchip,lan937x.yaml since commit 8926d94e5c50, which also restricts the values to 0 and 2000 ps. The MAC delay lines are configured only from rx/tx-internal-delay-ps, independently of phy-mode and of whether the port uses a PHY or a fixed-link, and phy-mode is passed unmodified to the PHY. The hardware has a fixed 2 ns delay line, 0 and 2000 are the only values it can express. For the CPU port, phy-mode "rgmii" with a fixed-link matches the sja1105 and lan937x examples.
Quoted 14 lines
Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +2
-0+ +examples:[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 167
Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +4
-0+ ethernet-port@7 { + reg = <7>; + ethernet = <&cpu_host_port>; + phy-mode = "rgmii";[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings
In reply to Jens Emil Schulz ØstergaardQuoted 56 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 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 | 177 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 178 insertions(+)
PATCH v13 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
@@ -17806,6 +17806,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 v13 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 v13 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
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…
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] lan9645x_probe() gets every register target (gcb, qs, chip_top, rew, sys, hsio, dev0..dev8, qsys, ana) through…
- [Low] The binding microchip,lan96455s-switch.yaml requires reg and reg- names (17 windows) on the switch node, but the driver never reads its…
- [Low] The v4 changelog says lan9645x_tag_npi_setup() rejects cascaded setups, but it only catches a LAN9645x that sits downstream.
- [Low] In lan9645x_reset_switch(), the decision to skip memory init depends on lan_rd(lan9645x, SYS_RESET_CFG).
--
net: dsa: lan9645x: add basic dsa driver for LAN9645X
This adds a basic DSA driver for the Microchip LAN9645x switch. It covers switch init, NPI and CPU port module setup, front port setup, and phylink MAC configuration for the internal CuPHYs and the RGMII ports 7-8. Register targets come from a parent device as named regmaps, and the parent MFD driver is planned for a later series.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,456 @@
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 40
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +12
-0+static int lan9645x_tag_npi_setup (struct dsa_switch *ds) +{ +struct dsa_port *dp, *first_cpu_dp =NULL ; +struct lan9645x *lan9645x = ds->priv; +struct phylink_config c = {}; + +dsa_switch_for_each_user_port (dp, ds) { +if (dp->cpu_dp->ds != ds) { +dev_err (ds->dev, +"NPI port on a remote switch is not supported\n" ); +return -EINVAL ; + }
[Severity: Low]
Does this check catch every cascaded setup? The v4 changelog says "tag_npi_setup: reject cascaded setups". The loop only looks at this switch's user ports and only rejects when their cpu_dp is on another switch, so it only covers a LAN9645x that sits downstream.
Take a LAN9645x at the top of a dsa,member cluster that owns the NPI port and has a link port to a switch from another family. Every local user port then has a local cpu_dp, so the check passes. The DSA link port and the remote user ports behind it are never checked.
The DSA core doesn't seem to reject the mixed tree either. dsa_switch_setup_tag_protocol() in net/dsa/dsa.c goes straight to connect when the protocol matches the tree default:
if (tag_ops->proto == dst->default_proto) goto connect;
lan9645x_port_setup() then sets up the link port like a normal front port. lan9645x_setup() zeroes the source mask for every port:
for (int p = 0; p < lan9645x->num_phys_ports; p++) {
lan_wr(0, lan9645x, ANA_PGID(PGID_SRC + p));so frames arriving on the link port are not forwarded. On transmit, lan9645x_xmit() sets IFH_DSTS = BIT(dp->index) for a remote user port, which selects the local port with the same index.
The tree would probe successfully, but cascaded traffic would be dropped or misdirected with nothing logged. Could setup fail instead when a dsa_switch_for_each_port() loop finds a port where dsa_port_is_dsa(dp) is true?
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +7
-0+static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +u32 val =0 ; +int err; + +/* The parent must reset the whole chip before instantiating its +* children, so the switch core is disabled when we get here. The
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 115
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+* 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 ; + +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 );
[Severity: Low]
What happens here if the SYS_RESET_CFG read fails? After the WARN_ON_ONCE, lan_rd() in lan9645x_main.h returns 0:
u32 addr, val = 0; ... WARN_ON_ONCE(regmap_read(lan_tgt2rmap(lan9645x, t, tinst), addr, &val)); return val;
That reads the same as CORE_ENA=0, so the RAM_INIT sequence could run on a core that is already running. The comment above says that corrupts the queue system.
In the same way, lan_wr() returns void, so a failed SYS_RAM_INIT write is ignored. CORE_ENA could then be set on memories that were never initialized.
This needs both a chip the parent did not reset and a bus error on exactly this access. There is no in-tree regmap provider yet, so it is unclear whether these regmap calls can fail in practice.
Should the regmap_read() result be checked before deciding whether to skip or run the memory 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]
Is there any in-tree configuration where this lookup can succeed? Nothing under drivers/mfd registers regmaps with these names (gcb, qs, chip_top, rew, sys, hsio, dev0..dev8, qsys, ana) for a lan9645x or lan96455 parent.
That means lan9645x_probe() returns -ENODEV every time, including for a DT node placed under simple-bus. None of the setup, NPI, phylink or port code in this patch can run in-tree until the MFD parent lands.
The commit message does say "The MFD driver will come in a later series", so this is mostly a question for the maintainers: should the driver be merged before anything in-tree can bind it?
[Severity: Low]
Should the driver also be able to use the switch node's own register windows?
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml requires reg and reg-names on the switch node, with 17 windows. The driver never reads those resources itself, and only asks dev->parent for named regmaps.
For comparison, ocelot_regmap_from_resource() tries the device's own IORESOURCE_MEM first and only then falls back to the parent.
If the plan is for the future MFD parent to build the named regmaps from the child's reg and reg-names, as with VSC7512, then this matches, since the binding's reg-names match lan9645x_resource_names[]. Otherwise, would a fallback to the node's own resources be useful here?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
PATCH v13 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 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 v13 5/9] net: dsa: lan9645x: add vlan support
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] On a VLAN-aware bridged port, frames the host sends without a tag can leave the switch tagged, sometimes with the wrong VID.
- [Medium] On VLAN-aware ports, lan9645x_vlan_port_apply_ingress() sets ANA_VLAN_CFG_VLAN_POP_CNT=1, so the hardware removes the outer VLAN…
- [Low] The commit message says the patch adds "VLAN support for VLAN- aware and VLAN-unaware bridges", but none of the bridged code paths…
- [Low] Errors from VLAN table programming are not passed back to callers.
--
net: dsa: lan9645x: add vlan support
This commit adds VLAN table management to the lan9645x DSA driver. It configures ports for VLAN-aware and VLAN-unaware bridges, and reserves HOST_PVID (4095) for standalone ports. It also registers the port_vlan_filtering, port_vlan_add and port_vlan_del ops, all serialized by a new fwd_domain_lock.
Quoted 1 line
Add VLAN support for VLAN-aware and VLAN-unaware bridges.
[Severity: Low]
Does this description match what the commit does on its own?
At this point in the series nothing writes lan9645x->bridge_mask, and lan9645x_switch_ops has no .port_bridge_join. That means lan9645x_port_is_bridged() always returns false:
static inline bool lan9645x_port_is_bridged(struct lan9645x_port *p)
{
return p->lan9645x->bridge_mask & BIT(p->chip_port);
}It also means DSA never offloads a bridge, so .port_vlan_filtering, .port_vlan_add and .port_vlan_del are never called for user ports. The only thing that takes effect here is the standalone HOST_PVID setup done from .port_setup.
Bridge offload, and clearing HOST_PVID membership on bridge join, arrive with the later "net: dsa: lan9645x: add bridge support" patch. That ordering is only explained in the v12 changelog below the "---", and git am drops that part.
Could the commit message say that the bridged paths only become reachable once the bridge support patch is applied?
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0
-0@@ -0,0 +1,402 @@
[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +12
-0+static void +lan9645x_vlan_port_apply_egress (struct lan9645x_port *p, +struct lan9645x_vlan_port_info *info) +{ +struct lan9645x *lan9645x = p->lan9645x; +enum lan9645x_vlan_port_tag tag_cfg; +u16 port_vid =UNAWARE_PVID ; + +if (!lan9645x_port_is_bridged (p)) { + tag_cfg =LAN9645X_TAG_NO_PVID_NO_UNAWARE ; + port_vid =HOST_PVID ; + }else if (p->vlan_aware) {
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 144
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8
-0+if (info->untagged ==1 && info->tagged) { + tag_cfg =LAN9645X_TAG_NO_PVID_NO_UNAWARE ; + port_vid = info->untagged_vid; + }else if (info->untagged) { + tag_cfg =LAN9645X_TAG_DISABLED ; + }else { + tag_cfg =LAN9645X_TAG_ALL ; + }
[Severity: Medium]
Can untagged frames from the host leave a VLAN-aware bridged port tagged, and with the wrong VID?
For an untagged host frame on a VLAN-filtering bridge, lan9645x_xmit_get_vlan_info() in net/dsa/tag_lan9645x.c puts the bridge device's pvid into the IFH:
} else {
rcu_read_lock();
br_vlan_get_pvid_rcu(br, &tci);
rcu_read_unlock();
*vlan_tci = tci;
}The rewriter mode here, however, is chosen from the port's own untagged VID:
- With one untagged VLAN X plus tagged VLANs, TAG_NO_PVID_NO_UNAWARE with PORT_VID=X leaves only VID X or VID 0 untagged.
- With no untagged VLANs, TAG_ALL tags every frame, including VID 0.
The two sides only agree when br0's pvid equals the port's untagged VID. Two examples where they don't:
(a) swp0 has "vid 10 pvid untagged" plus tagged vid 20, and br0 self pvid is 1. br_handle_vlan() strips host traffic on br0.10 for egress on swp0, and the same happens to VLAN 10 traffic forwarded in software from a foreign bridge port. The tagger then puts VID 1 in the IFH, so the frame goes out tagged with VID 1 instead of untagged in VLAN 10.
(b) On a trunk port with no untagged VLANs, untagged frames go out tagged with br0's pvid. If br0 has no pvid, they go out priority-tagged with VID 0. STP BPDUs from br_send_bpdu() and LLDP sent on swp0 are examples.
This depends on the rewriter using IFH.TCI as the classified VID when BYPASS=1, and on the TAG_CFG semantics described in the lan9645x_vlan_port_tag comment. I could not check either against the datasheet. ocelot and tag_ocelot use a similar pairing, so this may be a known limitation.
The code becomes reachable once the bridge support patch lands, and it is unchanged at the end of the series. Also, LAN9645X_TAG_NO_UNAWARE is defined but never used.
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3
-0+ }else { + tag_cfg =LAN9645X_TAG_DISABLED ; + }
[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +2
-0+static void lan9645x_vlan_port_apply_ingress (struct lan9645x_port *p) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 188
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +5
-0+ val =ANA_VLAN_CFG_VLAN_VID_SET (pvid) | +ANA_VLAN_CFG_VLAN_TAG_TYPE_SET (0 ); +if (p->vlan_aware) + val |=ANA_VLAN_CFG_VLAN_AWARE_ENA_SET (1 ) | +ANA_VLAN_CFG_VLAN_POP_CNT_SET (1 );
[Severity: Medium]
Does popping the outer tag here conflict with the pvid check in lan9645x_rcv()?
With VLAN_POP_CNT=1 on VLAN-aware ports, the classified VID survives only in the IFH. lan9645x_rcv() in net/dsa/tag_lan9645x.c skips restoring it when it equals the port pvid:
if ((vlan_tci & VLAN_VID_MASK) != port_pvid) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);
That is fine for untagged frames. Consider a double-tagged frame [0x8100 VID 100][0x8100 VID 200] that arrives on a VLAN-aware port with pvid 100 and is sent to the CPU (broadcast, host flood or trap). The hardware classifies it to VID 100 and pops the outer tag. IFH TCI is 100, which equals the pvid, so no hwaccel tag is set.
The software bridge then finds the inner tag 200 in the payload and puts the frame in VLAN 200, while the hardware forwarded it in VLAN 100.
Could this cause local delivery (for example to br0.200), or software forwarding in a different VLAN than the hardware used? br_allowed_ingress() still restricts this to VIDs the port is a member of.
[ ... ]
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3
-0+int lan9645x_vlan_port_add_vlan (struct lan9645x_port *p,u16 vid,bool pvid, +bool untagged,struct netlink_ext_ack *extack) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 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]
Should the return value of lan9645x_vlan_hw_wr() be checked here, before the software state is committed?
This path updates lan9645x->vlans[] and p->pvid, reprograms the port ingress and egress configuration, and returns 0 even when the table write failed. lan9645x_vlan_port_del_vlan(), lan9645x_vlan_cpu_add(), lan9645x_vlan_cpu_del() and lan9645x_vlan_set_hostmode() do the same.
Inside lan9645x_vlan_hw_wr(), the ANA_VLANTIDX, ANA_VLAN_PORT_MASK and ANA_VLANACCESS writes go through lan_wr(), which only does WARN_ON_ONCE() on a regmap error. The engine is also not checked for IDLE before a new command is issued.
When this fails, the shadow table and the hardware can diverge while switchdev believes the change succeeded. For the CPU port, DSA caches the VID as installed, so later adds of the same VID only bump a refcount and never restore the missing membership.
The comment in lan9645x_vlan_hw_wr() says a timeout most likely means the register bus is dead, which limits the practical impact. lan_wr() swallowing errors also predates this patch.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 5/9] net: dsa: lan9645x: add vlan support
Quoted 133 lines · On Fri, 2026-10-02 at 21:14 +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] On a VLAN-aware bridged port, frames the host sends without a tag can leave the switch tagged, sometimes with the wrong VID.
- [Medium] On VLAN-aware ports,lan9645x_vlan_port_apply_ingress()sets ANA_VLAN_CFG_VLAN_POP_CNT=1, so the hardware removes the outer VLAN…
- [Low] The commit message says the patch adds "VLAN support for VLAN- aware and VLAN-unaware bridges", but none of the bridged code paths…
- [Low] Errors from VLAN table programming are not passed back to callers.--
net: dsa: lan9645x: add vlan support
This commit adds VLAN table management to the lan9645x DSA driver. It configures ports for VLAN-aware and VLAN-unaware bridges, and reserves
HOST_PVID(4095) for standalone ports. It also registers theport_vlan_filtering,port_vlan_addandport_vlan_delops, all serialized by a newfwd_domain_lock.Quoted 1 line
Add VLAN support for VLAN-aware and VLAN-unaware bridges.
[Severity: Low]
Does this description match what the commit does on its own?At this point in the series nothing writes
lan9645x->bridge_mask, andlan9645x_switch_opshas no .port_bridge_join. That meanslan9645x_port_is_bridged()always returns false:static inline bool
lan9645x_port_is_bridged(struct lan9645x_port *p){ return p->lan9645x->bridge_mask & BIT(p->chip_port); }It also means DSA never offloads a bridge, so .port_vlan_filtering, .port_vlan_add and .port_vlan_del are never called for user ports. The only thing that takes effect here is the standalone
HOST_PVIDsetup done from .port_setup.Bridge offload, and clearing
HOST_PVIDmembership on bridge join, arrive with the later "net: dsa: lan9645x: add bridge support" patch. That ordering is only explained in the v12 changelog below the "---", and git am drops that part.Could the commit message say that the bridged paths only become reachable once the bridge support patch is applied?
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +0
-0@@ -0,0 +1,402 @@[ ... ]
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +12
-0+static void +lan9645x_vlan_port_apply_egress (struct lan9645x_port *p, +struct lan9645x_vlan_port_info *info) +{ +struct lan9645x *lan9645x = p->lan9645x; +enum lan9645x_vlan_port_tag tag_cfg; +u16 port_vid =UNAWARE_PVID ; + +if (!lan9645x_port_is_bridged (p)) { + tag_cfg =LAN9645X_TAG_NO_PVID_NO_UNAWARE ; + port_vid =HOST_PVID ; + }else if (p->vlan_aware) {[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 144
Quoted 8 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +8
-0+if (info->untagged ==1 && info->tagged) { + tag_cfg =LAN9645X_TAG_NO_PVID_NO_UNAWARE ; + port_vid = info->untagged_vid; + }else if (info->untagged) { + tag_cfg =LAN9645X_TAG_DISABLED ; + }else { + tag_cfg =LAN9645X_TAG_ALL ; + }[Severity: Medium]
Can untagged frames from the host leave a VLAN-aware bridged port tagged, and with the wrong VID?For an untagged host frame on a VLAN-filtering bridge,
lan9645x_xmit_get_vlan_info()innet/dsa/tag_lan9645x.cputs the bridge device's pvid into the IFH:} else { rcu_read_lock(); br_vlan_get_pvid_rcu(br, &tci); rcu_read_unlock(); *vlan_tci = tci; }The rewriter mode here, however, is chosen from the port's own untagged VID:
- With one untagged VLAN X plus tagged VLANs,
TAG_NO_PVID_NO_UNAWAREwith PORT_VID=X leaves only VID X or VID 0 untagged.
- With no untagged VLANs,TAG_ALLtags every frame, including VID 0.The two sides only agree when br0's pvid equals the port's untagged VID. Two examples where they don't:
(a) swp0 has "vid 10 pvid untagged" plus tagged vid 20, and br0 self pvid is 1.
br_handle_vlan()strips host traffic on br0.10 for egress on swp0, and the same happens to VLAN 10 traffic forwarded in software from a foreign bridge port. The tagger then puts VID 1 in the IFH, so the frame goes out tagged with VID 1 instead of untagged in VLAN 10.(b) On a trunk port with no untagged VLANs, untagged frames go out tagged with br0's pvid. If br0 has no pvid, they go out priority-tagged with VID 0. STP BPDUs from
br_send_bpdu()and LLDP sent on swp0 are examples.This depends on the rewriter using IFH.TCI as the classified VID when BYPASS=1, and on the
TAG_CFGsemantics described in thelan9645x_vlan_port_tagcomment. I could not check either against the datasheet. ocelot andtag_ocelotuse a similar pairing, so this may be a known limitation.
Quoted 4 lines
The code becomes reachable once the bridge support patch lands, and it is unchanged at the end of the series. Also,
LAN9645X_TAG_NO_UNAWAREis defined but never used.
Correct, this is the same issue as the one raised on the tag driver patch, and the rewriter does use IFH.TCI as the classified VID with BYPASS set. v14 fixes both sides: the tag driver no longer uses the bridge pvid, and ports with only tagged VLANs use TAG_NO_UNAWARE instead of TAG_ALL.
Quoted 35 lines
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3
-0+ }else { + tag_cfg =LAN9645X_TAG_DISABLED ; + }[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +2
-0+static void lan9645x_vlan_port_apply_ingress (struct lan9645x_port *p) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 188
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +5
-0+ val =ANA_VLAN_CFG_VLAN_VID_SET (pvid) | +ANA_VLAN_CFG_VLAN_TAG_TYPE_SET (0 ); +if (p->vlan_aware) + val |=ANA_VLAN_CFG_VLAN_AWARE_ENA_SET (1 ) | +ANA_VLAN_CFG_VLAN_POP_CNT_SET (1 );[Severity: Medium]
Does popping the outer tag here conflict with the pvid check inlan9645x_rcv()?With VLAN_POP_CNT=1 on VLAN-aware ports, the classified VID survives only in the IFH.
lan9645x_rcv()innet/dsa/tag_lan9645x.cskips restoring it when it equals the port pvid:if ((vlan_tci & VLAN_VID_MASK) != port_pvid) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vlan_tci);That is fine for untagged frames. Consider a double-tagged frame [
0x8100VID 100][0x8100 VID 200] that arrives on a VLAN-aware port with pvid 100 and is sent to the CPU (broadcast, host flood or trap). The hardware classifies it to VID 100 and pops the outer tag. IFH TCI is 100, which equals the pvid, so no hwaccel tag is set.
Quoted 8 lines
The software bridge then finds the inner tag 200 in the payload and puts the frame in VLAN 200, while the hardware forwarded it in VLAN 100.
Could this cause local delivery (for example to br0.200), or software forwarding in a different VLAN than the hardware used?
br_allowed_ingress()still restricts this to VIDs the port is a member of.
Correct, same issue as on the tag driver patch. v14 restores the classified VID as a hwaccel tag whenever a tag was popped, so in the example the inner tag 200 stays in the payload and the bridge classifies the frame to VLAN 100, as the hardware did. This also preserves the PCP of priority tagged frames and of frames tagged with the pvid.
Quoted 42 lines
[ ... ]
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +3
-0+int lan9645x_vlan_port_add_vlan (struct lan9645x_port *p,u16 vid,bool pvid, +bool untagged,struct netlink_ext_ack *extack) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c line 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]
Should the return value oflan9645x_vlan_hw_wr()be checked here, before the software state is committed?This path updates lan9645x->vlans[] and
p->pvid, reprograms the port ingress and egress configuration, and returns 0 even when the table write failed.lan9645x_vlan_port_del_vlan(),lan9645x_vlan_cpu_add(),lan9645x_vlan_cpu_del()andlan9645x_vlan_set_hostmode()do the same.Inside
lan9645x_vlan_hw_wr(), theANA_VLANTIDX,ANA_VLAN_PORT_MASKandANA_VLANACCESSwrites go throughlan_wr(), which only doesWARN_ON_ONCE()on a regmap error. The engine is also not checked for IDLE before a new command is issued.When this fails, the shadow table and the hardware can diverge while switchdev believes the change succeeded. For the CPU port, DSA caches the VID as installed, so later adds of the same VID only bump a refcount and never restore the missing membership.
The comment in
lan9645x_vlan_hw_wr()says a timeout most likely means the register bus is dead, which limits the practical impact.lan_wr()swallowing errors also predates this patch.[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
PATCH v13 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 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 | 85 +++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 27 +++ 4 files changed, 381 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 +85 -0
109 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
[email protected]
AI reviewRe: [PATCH net-next v13 6/9] net: dsa: lan9645x: add mac table integration
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: 1 · Low: 1
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] For a non-zero VID, lan9645x_fdb_add() and lan9645x_fdb_del() map DSA_DB_PORT and DSA_DB_BRIDGE host entries to the same hardware…
- [Low] Each new MAC table sequence writes the key, the filter and the command through lan_wr().
--
net: dsa: lan9645x: add mac table integration
This commit adds MAC table support to the lan9645x DSA driver. It adds learn, forget, flush and GET_NEXT based dump helpers keyed on (vid, mac). These are wired into the port_fast_age, port_fdb_dump, port_fdb_add and port_fdb_del DSA callbacks.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +0
-0@@ -0,0 +1,268 @@
[ ... ]
Quoted 17 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +17
-0+static void lan9645x_mac_select (struct lan9645x *lan9645x, +const unsigned char mac[ETH_ALEN ], +unsigned int vid) +{ +u64 maddr =ether_addr_to_u64 (mac); + +lockdep_assert_held (&lan9645x->mact_lock); + +lan_wr (ANA_MACHDATA_VID_SET (vid) | +ANA_MACHDATA_MACHDATA_SET (upper_32_bits (maddr)), + lan9645x, +ANA_MACHDATA ); + +lan_wr (lower_32_bits (maddr), + lan9645x, +ANA_MACLDATA ); +}
[ ... ]
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +9
-0+static 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) +{ +lockdep_assert_held (&lan9645x->mact_lock); + +lan9645x_mac_select (lan9645x, mac, vid);
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c line 109
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +10
-0+ +lan_wr (ANA_MACACCESS_VALID_SET (1 ) | +ANA_MACACCESS_DEST_IDX_SET (port) | +ANA_MACACCESS_MAC_CPU_COPY_SET (cpu_copy) | +ANA_MACACCESS_ENTRYTYPE_SET (type) | +ANA_MACACCESS_MAC_TABLE_CMD_SET (CMD_LEARN ), + lan9645x,ANA_MACACCESS ); + +return lan9645x_mac_wait_for_completion (lan9645x,NULL ); +}
[Severity: Low]
Can a failed register write here be reported to DSA as a successful learn?
lan_wr() returns void and only calls WARN_ON_ONCE() when regmap_write() fails. Suppose the ANA_MACACCESS command write is lost but the reads that follow still work. Then lan9645x_mac_wait_for_completion() sees CMD_IDLE immediately and returns 0:
err = lan9645x_rd_poll_timeout(lan9645x, ANA_MACACCESS, val, ANA_MACACCESS_MAC_TABLE_CMD_GET(val) == CMD_IDLE);
In that case lan9645x_fdb_add() returns success and the bridge marks the entry as offloaded, but the table was never changed. The same applies to CMD_FORGET in __lan9645x_mact_forget().
What happens if only the ANA_MACHDATA or ANA_MACLDATA write in lan9645x_mac_select() fails? Would CMD_LEARN or CMD_FORGET then act on a stale key? That could be the previous operation's key, or whatever the last GET_NEXT walk in lan9645x_mact_dsa_dump() left in the registers.
lan9645x_mact_flush() has the same problem with its ANA_ANAGEFIL write:
lan_wr(ANA_ANAGEFIL_PID_EN_SET(1) | ANA_ANAGEFIL_PID_VAL_SET(port), lan9645x, ANA_ANAGEFIL);
If that write fails, both CMD_AGE scans would run without the port filter. Would that flush dynamic entries from every port instead of only the requested one?
This only happens if the parent MFD bus can fail a write while later reads succeed. The parent driver is not in the tree, so that could not be confirmed. The ocelot-family drivers follow the same lan_wr() convention.
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0@@ -360,6 +364,81 @@ static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port,
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static int lan9645x_fdb_add (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db) +{
[ ... ]
Quoted 23 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +23
-0+if (dsa_port_is_cpu (dp) && !br && +dsa_fdb_present_in_other_db (ds, port, addr, vid, db)) +return 0 ; + +if (!vid) + vid =lan9645x_vlan_unaware_pvid (!!br); + + dest =dsa_port_is_cpu (dp) ?PGID_CPU : port; + +return lan9645x_mact_learn (lan9645x, dest, addr, vid,ENTRYTYPE_LOCKED , + false); +} + +static int lan9645x_fdb_del (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db) +{ +struct net_device *br =lan9645x_db2bridge (db); +struct dsa_port *dp =dsa_to_port (ds, port); +struct lan9645x *lan9645x = ds->priv; + +if (IS_ERR (br)) +return PTR_ERR (br);
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port, · line 440
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +if (dsa_port_is_cpu (dp) && !br && +dsa_fdb_present_in_other_db (ds, port, addr, vid, db)) +return 0 ; + +if (!vid) + vid =lan9645x_vlan_unaware_pvid (!!br); + +return lan9645x_mact_forget (lan9645x, addr, vid,ENTRYTYPE_LOCKED ); +}
[Severity: Medium]
Could this forget a CPU port entry that another database still needs?
For a non-zero vid, lan9645x_fdb_add() and lan9645x_fdb_del() map two host entries with the same (vid, mac) to one hardware key pointing atPGID_CPU: the DSA_DB_PORT one and the DSA_DB_BRIDGE one. Only vid 0 is split, into HOST_PVID and UNAWARE_PVID by lan9645x_vlan_unaware_pvid().
DSA refcounts the two entries separately on the CPU port, because dsa_mac_addr_find() includes the db in its key. The shared-key guard only matches entries of the same db type:
net/dsa/dsa.c:dsa_fdb_present_in_other_db() {
...
if (a->db.type == db.type && !dsa_db_equal(&a->db, &db))
return true;
...
}So when a DSA_DB_PORT entry is deleted, the guard never sees a DSA_DB_BRIDGE entry with the same key. For DSA_DB_BRIDGE deletions, the !br check skips the guard entirely.
One way to hit this:
- swp1 is in a VLAN-aware bridge.
- swp1.100 is a VLAN upper whose MAC M differs from swp1's.
- dsa_user_vlan_rx_add_vid()->dsa_user_schedule_standalone_work(DSA_UC_ADD) installs a DSA_DB_PORT host entry (M, 100).
- M is also a bridge host address in VID 100, which adds a DSA_DB_BRIDGE host entry (M, 100). This happens, for example, with br0 using vid 100 self and the same MAC, or with a local entry of another port in VID 100.
Removing either entry, for example by taking swp1.100 down or deleting the bridge VLAN, goes through:
dsa_switch_host_fdb_del()
dsa_port_do_fdb_del()
lan9645x_fdb_del()
dsa_fdb_present_in_other_db() /* false, db types differ */
lan9645x_mact_forget() /* CMD_FORGET on (M, 100) */Wouldn't the hardware then lose the entry for the host address that is still wanted?
__lan9645x_port_set_host_flood() leaves the CPU out of PGID_UC when only bridged ports request host flooding. Unicast to M in VID 100 could then be dropped instead of reaching the host. The felix driver uses the same pattern.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 6/9] net: dsa: lan9645x: add mac table integration
Quoted 207 lines · On Fri, 2026-10-02 at 21:14 +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: 1 · Low: 1
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] For a non-zero VID,
lan9645x_fdb_add()andlan9645x_fdb_del()mapDSA_DB_PORTandDSA_DB_BRIDGEhost entries to the same hardware…
- [Low] Each new MAC table sequence writes the key, the filter and the command throughlan_wr().--
net: dsa: lan9645x: add mac table integration
This commit adds MAC table support to the lan9645x DSA driver. It adds learn, forget, flush and
GET_NEXTbased dump helpers keyed on (vid, mac). These are wired into theport_fast_age,port_fdb_dump,port_fdb_addandport_fdb_delDSA callbacks.Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +0
-0@@ -0,0 +1,268 @@[ ... ]
Quoted 17 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +17
-0+static void lan9645x_mac_select (struct lan9645x *lan9645x, +const unsigned char mac[ETH_ALEN ], +unsigned int vid) +{ +u64 maddr =ether_addr_to_u64 (mac); + +lockdep_assert_held (&lan9645x->mact_lock); + +lan_wr (ANA_MACHDATA_VID_SET (vid) | +ANA_MACHDATA_MACHDATA_SET (upper_32_bits (maddr)), + lan9645x, +ANA_MACHDATA ); + +lan_wr (lower_32_bits (maddr), + lan9645x, +ANA_MACLDATA ); +}[ ... ]
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +9
-0+static 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) +{ +lockdep_assert_held (&lan9645x->mact_lock); + +lan9645x_mac_select (lan9645x, mac, vid);drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c line 109
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +10
-0+ +lan_wr (ANA_MACACCESS_VALID_SET (1 ) | +ANA_MACACCESS_DEST_IDX_SET (port) | +ANA_MACACCESS_MAC_CPU_COPY_SET (cpu_copy) | +ANA_MACACCESS_ENTRYTYPE_SET (type) | +ANA_MACACCESS_MAC_TABLE_CMD_SET (CMD_LEARN ), + lan9645x,ANA_MACACCESS ); + +return lan9645x_mac_wait_for_completion (lan9645x,NULL ); +}[Severity: Low]
Can a failed register write here be reported to DSA as a successful learn?
lan_wr()returns void and only callsWARN_ON_ONCE()whenregmap_write()fails. Suppose theANA_MACACCESScommand write is lost but the reads that follow still work. Thenlan9645x_mac_wait_for_completion()seesCMD_IDLEimmediately and returns 0:err = lan9645x_rd_poll_timeout(lan9645x, ANA_MACACCESS, val, ANA_MACACCESS_MAC_TABLE_CMD_GET(val) == CMD_IDLE);In that case
lan9645x_fdb_add()returns success and the bridge marks the entry as offloaded, but the table was never changed. The same applies toCMD_FORGETin__lan9645x_mact_forget().What happens if only the
ANA_MACHDATAorANA_MACLDATAwrite inlan9645x_mac_select()fails? WouldCMD_LEARNorCMD_FORGETthen act on a stale key? That could be the previous operation's key, or whatever the lastGET_NEXTwalk inlan9645x_mact_dsa_dump()left in the registers.
lan9645x_mact_flush()has the same problem with itsANA_ANAGEFILwrite:lan_wr(ANA_ANAGEFIL_PID_EN_SET(1) | ANA_ANAGEFIL_PID_VAL_SET(port), lan9645x, ANA_ANAGEFIL);If that write fails, both
CMD_AGEscans would run without the port filter. Would that flush dynamic entries from every port instead of only the requested one?This only happens if the parent MFD bus can fail a write while later reads succeed. The parent driver is not in the tree, so that could not be confirmed. The ocelot-family drivers follow the same
lan_wr()convention.[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0@@ -360,6 +364,81 @@ static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port,[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static int lan9645x_fdb_add (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db) +{[ ... ]
Quoted 23 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +23
-0+if (dsa_port_is_cpu (dp) && !br && +dsa_fdb_present_in_other_db (ds, port, addr, vid, db)) +return 0 ; + +if (!vid) + vid =lan9645x_vlan_unaware_pvid (!!br); + + dest =dsa_port_is_cpu (dp) ?PGID_CPU : port; + +return lan9645x_mact_learn (lan9645x, dest, addr, vid,ENTRYTYPE_LOCKED , + false); +} + +static int lan9645x_fdb_del (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid, +struct dsa_db db) +{ +struct net_device *br =lan9645x_db2bridge (db); +struct dsa_port *dp =dsa_to_port (ds, port); +struct lan9645x *lan9645x = ds->priv; + +if (IS_ERR (br)) +return PTR_ERR (br);drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static int lan9645x_port_vlan_del(struct dsa_switch *ds, int port, · line 440
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+ +if (dsa_port_is_cpu (dp) && !br && +dsa_fdb_present_in_other_db (ds, port, addr, vid, db)) +return 0 ; + +if (!vid) + vid =lan9645x_vlan_unaware_pvid (!!br); + +return lan9645x_mact_forget (lan9645x, addr, vid,ENTRYTYPE_LOCKED ); +}[Severity: Medium]
Could this forget a CPU port entry that another database still needs?For a non-zero vid,
lan9645x_fdb_add()andlan9645x_fdb_del()map two host entries with the same (vid, mac) to one hardware key pointing atPGID_CPU: theDSA_DB_PORTone and theDSA_DB_BRIDGEone. Only vid 0 is split, intoHOST_PVIDandUNAWARE_PVIDbylan9645x_vlan_unaware_pvid().DSA refcounts the two entries separately on the CPU port, because
dsa_mac_addr_find()includes the db in its key. The shared-key guard only matches entries of the same db type:net/dsa/dsa.c:dsa_fdb_present_in_other_db() { ... if (a->db.type == db.type && !dsa_db_equal(&a->db, &db)) return true; ... }So when a
DSA_DB_PORTentry is deleted, the guard never sees aDSA_DB_BRIDGEentry with the same key. ForDSA_DB_BRIDGEdeletions, the !br check skips the guard entirely.One way to hit this:
- swp1 is in a VLAN-aware bridge.
- swp1.100 is a VLAN upper whose MAC M differs from swp1's.
- dsa_user_vlan_rx_add_vid()->dsa_user_schedule_standalone_work(DSA_UC_ADD) installs aDSA_DB_PORThost entry (M, 100).
- M is also a bridge host address in VID 100, which adds aDSA_DB_BRIDGEhost entry (M, 100). This happens, for example, with br0 using vid 100 self and the same MAC, or with a local entry of another port in VID 100.Removing either entry, for example by taking swp1.100 down or deleting the bridge VLAN, goes through:
dsa_switch_host_fdb_del()
dsa_port_do_fdb_del()lan9645x_fdb_del() dsa_fdb_present_in_other_db() /* false, db types differ */ lan9645x_mact_forget() /* CMD_FORGET on (M, 100) */
Quoted 8 lines
Wouldn't the hardware then lose the entry for the host address that is still wanted?
__lan9645x_port_set_host_flood()leaves the CPU out ofPGID_UCwhen only bridged ports request host flooding. Unicast to M in VID 100 could then be dropped instead of reaching the host. The felix driver uses the same pattern.
Correct, a DSA_DB_PORT and a DSA_DB_BRIDGE host entry with the same address and a non-zero VID map to one MAC table entry, and dsa_fdb_present_in_other_db() only considers databases of the same type. v14 replaces the check with one that walks the CPU port address list and compares the MAC table key each entry maps to, so the entry is only learned or forgotten when no other database uses that key.
Quoted 4 lines
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
PATCH v13 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.
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 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 | 72 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 18 + drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 569 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 8 + 5 files changed, 668 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 +72 -0
102 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 +569 -0
569 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 v13 7/9] net: dsa: lan9645x: add mdb management
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] On a failed MAC table write, lan9645x_mdb_widen_dest() drops the reference on new_pgid right away…
- [Low] lan9645x_mdb_narrow_dest() commits mdb_entry->pgid = new_pgid and mdb_entry->ports = new_ports before calling lan9645x_mdb_write_dest().
- [Low] A failed CPU-only membership delete leaks a PGID reference because old_pgid and new_pgid are the same object.
--
net: dsa: lan9645x: add mdb management
This adds the DSA mdb callbacks to the lan9645x driver. IP multicast stores the port group mask inline in the mac table entry. L2 multicast points at a refcounted PGID whose destination mask is the port group. CPU membership is carried by the MAC_CPU_COPY bit, and when the PGIDs run out, add and delete handle it differently.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0
-0@@ -0,0 +1,569 @@
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +7
-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;
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 295
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+int err; + +lockdep_assert_held (&lan9645x->mdb_lock); + + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) { +lan9645x_pgid_entry_put (lan9645x, new_pgid); +return err; + }
[Severity: Medium]
Can this hand a PGID index to an unrelated group while hardware still points at it?
__lan9645x_mact_learn() issues the command before it polls for completion:
lan_wr(ANA_MACACCESS_VALID_SET(1) |
ANA_MACACCESS_DEST_IDX_SET(port) |
...
ANA_MACACCESS_MAC_TABLE_CMD_SET(CMD_LEARN),
lan9645x, ANA_MACACCESS);
return lan9645x_mac_wait_for_completion(lan9645x, NULL);That means an error from lan9645x_mdb_write_dest() only tells us the outcome is unknown, for example after a failed poll read or a timeout. The entry may already point at pgid_index.
If new_pgid was just created, this put frees its index. A later add with a different port mask can get the same index back from lan9645x_mdb_pgid_entry_create(). lan9645x_pgid_entry_alloc() then rewrites ANA_PGID for that group, so an entry that may have been written would forward this group to the other group's ports.
When the entry already existed (ports != 0), __lan9645x_mdb_add() does no further cleanup. For a fresh entry it issues the forget only after the PGID has been released, and it ignores the result:
lan9645x_mact_forget(lan9645x, mdb_entry->mac,
mdb_entry->vid, type);
lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);The comment there says the forget "fails harmlessly if the bus is still down". Isn't that the case where an entry pointing at a freed PGID is left in hardware?
The delete side handles the same uncertainty by keeping the reference. lan9645x_mdb_narrow_dest() keeps old_pgid on failure, and __lan9645x_mdb_del() sets mdb_entry->pgid = NULL when CMD_FORGET fails. The v12 changelog gives the reason: "so the index cannot be handed to an unrelated group while hardware may still point at it".
Should the add path also keep the new_pgid reference when the write fails?
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5
-0+ mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports; +lan9645x_pgid_entry_put (lan9645x, old_pgid); +return 0 ; +}
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 334
Quoted 13 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +13
-0+static void lan9645x_mdb_narrow_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); + + mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports;
[Severity: Low]mdb_entry->pgid is switched to new_pgid before the hardware write. If that write fails, which PGID does the entry use afterwards? Hardware would still use old_pgid, while software records new_pgid.
The in-place branch in __lan9645x_mdb_del() assumes hardware points at mdb_entry->pgid, so it only rewrites ANA_PGID:
if (mdb_entry->pgid && refcount_read(&mdb_entry->pgid->refcount) == 1) {
mdb_entry->pgid->ports = new_ports &
~BIT(lan9645x->num_phys_ports);
...
lan_rmw(ANA_PGID_PGID_SET(mdb_entry->pgid->ports), ...);
return 0;
}For example, take a group {A,B,C} on PGID P:
1. Deleting C creates Q={A,B} with the last free index, and the MAC write fails.
2. Deleting B finds no PGID for {A}, so creation returns -ENOSPC.
3. Q has refcount 1, so it is narrowed in place.
Hardware still forwards through P, so B and C keep receiving the group, and nothing further is logged.
Should the in-place branch, or a later narrowing, rewrite the MAC entry after an earlier failed write?
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 344
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+ + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) { +dev_err (lan9645x->dev, +"Narrowing %pM vid %u to mask 0x%x returned %pe\n" , + mdb_entry->mac, mdb_entry->vid, new_ports, +ERR_PTR (err)); +return ; + }
[Severity: Low]
Does this early return leak a PGID reference when old_pgid and new_pgid are the same object?
Take a group {A, CPU} on PGID P, whose ports are {A}. When only the CPU port module leaves, lan9645x_mdb_pgid_entry_get() strips the CPU bit. lan9645x_mdb_pgid_entry_lookup() then returns P after refcount_inc(). Now new_pgid == old_pgid == P, and P holds two references for a single mdb entry.
If lan9645x_mdb_write_dest() fails here, the put below is skipped. When the group is removed later, lan9645x_mdb_entry_dealloc() drops only one reference. P and its index then stay reserved until lan9645x_mdb_deinit().
Keeping old_pgid makes sense when it differs from new_pgid. Here, though, mdb_entry->pgid already holds P. Should the put still run when old_pgid == new_pgid?
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +3
-0+ +lan9645x_pgid_entry_put (lan9645x, old_pgid); +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 7/9] net: dsa: lan9645x: add mdb management
Quoted 94 lines · On Fri, 2026-10-02 at 21:14 +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] On a failed MAC table write,
lan9645x_mdb_widen_dest()drops the reference onnew_pgidright away…
- [Low]lan9645x_mdb_narrow_dest()commitsmdb_entry->pgid=new_pgidandmdb_entry->ports=new_portsbefore callinglan9645x_mdb_write_dest().
- [Low] A failed CPU-only membership delete leaks a PGID reference becauseold_pgidandnew_pgidare the same object.--
net: dsa: lan9645x: add mdb management
This adds the DSA mdb callbacks to the lan9645x driver. IP multicast stores the port group mask inline in the mac table entry. L2 multicast points at a refcounted PGID whose destination mask is the port group. CPU membership is carried by the
MAC_CPU_COPYbit, and when the PGIDs run out, add and delete handle it differently.Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +0
-0@@ -0,0 +1,569 @@[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +7
-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;drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 295
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+int err; + +lockdep_assert_held (&lan9645x->mdb_lock); + + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) { +lan9645x_pgid_entry_put (lan9645x, new_pgid); +return err; + }[Severity: Medium]
Can this hand a PGID index to an unrelated group while hardware still points at it?
__lan9645x_mact_learn()issues the command before it polls for completion:lan_wr(ANA_MACACCESS_VALID_SET(1) | ANA_MACACCESS_DEST_IDX_SET(port) | ... ANA_MACACCESS_MAC_TABLE_CMD_SET(CMD_LEARN), lan9645x, ANA_MACACCESS); return lan9645x_mac_wait_for_completion(lan9645x, NULL);That means an error from
lan9645x_mdb_write_dest()only tells us the outcome is unknown, for example after a failed poll read or a timeout. The entry may already point atpgid_index.If
new_pgidwas just created, this put frees its index. A later add with a different port mask can get the same index back fromlan9645x_mdb_pgid_entry_create().lan9645x_pgid_entry_alloc()then rewritesANA_PGIDfor that group, so an entry that may have been written would forward this group to the other group's ports.When the entry already existed (ports != 0),
__lan9645x_mdb_add()does no further cleanup. For a fresh entry it issues the forget only after the PGID has been released, and it ignores the result:lan9645x_mact_forget(lan9645x, mdb_entry->mac, mdb_entry->vid, type); lan9645x_mdb_entry_dealloc(lan9645x, mdb_entry);The comment there says the forget "fails harmlessly if the bus is still down". Isn't that the case where an entry pointing at a freed PGID is left in hardware?
Quoted 9 lines
The delete side handles the same uncertainty by keeping the reference.
lan9645x_mdb_narrow_dest()keepsold_pgidon failure, and__lan9645x_mdb_del()setsmdb_entry->pgid= NULL whenCMD_FORGETfails. The v12 changelog gives the reason: "so the index cannot be handed to an unrelated group while hardware may still point at it".Should the add path also keep the
new_pgidreference when the write fails?
Correct, an error from the learn command leaves the hardware state unknown, and the add path dropped the PGID reference anyway. v14 keeps the reference on a failed write, as the delete path does, so the index cannot be reused while hardware may point at it.
Quoted 91 lines
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +5
-0+ mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports; +lan9645x_pgid_entry_put (lan9645x, old_pgid); +return 0 ; +}[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 334
Quoted 13 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +13
-0+static void lan9645x_mdb_narrow_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); + + mdb_entry->pgid = new_pgid; + mdb_entry->ports = new_ports;[Severity: Low]
mdb_entry->pgidis switched tonew_pgidbefore the hardware write. If that write fails, which PGID does the entry use afterwards? Hardware would still useold_pgid, while software recordsnew_pgid.The in-place branch in
__lan9645x_mdb_del()assumes hardware points atmdb_entry->pgid, so it only rewritesANA_PGID:if (mdb_entry->pgid && refcount_read(&mdb_entry->pgid->refcount) == 1) { mdb_entry->pgid->ports = new_ports & ~BIT(lan9645x->num_phys_ports); ... lan_rmw(ANA_PGID_PGID_SET(mdb_entry->pgid->ports), ...); return 0; }For example, take a group {A,B,C} on PGID P:
1. Deleting C creates Q={A,B} with the last free index, and the MAC write fails.
2. Deleting B finds no PGID for {A}, so creation returns
-ENOSPC.3. Q has refcount 1, so it is narrowed in place.
Hardware still forwards through P, so B and C keep receiving the group, and nothing further is logged.
Should the in-place branch, or a later narrowing, rewrite the MAC entry after an earlier failed write?
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 344
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +10
-0+ + err =lan9645x_mdb_write_dest (lan9645x, mdb_entry, type, pgid_index, + new_ports); +if (err) { +dev_err (lan9645x->dev, +"Narrowing %pM vid %u to mask 0x%x returned %pe\n" , + mdb_entry->mac, mdb_entry->vid, new_ports, +ERR_PTR (err)); +return ; + }[Severity: Low]
Does this early return leak a PGID reference whenold_pgidandnew_pgidare the same object?Take a group {A, CPU} on PGID P, whose ports are {A}. When only the CPU port module leaves,
lan9645x_mdb_pgid_entry_get()strips the CPU bit.lan9645x_mdb_pgid_entry_lookup()then returns P afterrefcount_inc(). Nownew_pgid==old_pgid== P, and P holds two references for a single mdb entry.If
lan9645x_mdb_write_dest()fails here, the put below is skipped. When the group is removed later,lan9645x_mdb_entry_dealloc()drops only one reference. P and its index then stay reserved untillan9645x_mdb_deinit().Keeping
old_pgidmakes sense when it differs fromnew_pgid. Here, though,mdb_entry->pgidalready holds P. Should the put still run whenold_pgid==new_pgid?drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c line 300
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +3
-0+ +lan9645x_pgid_entry_put (lan9645x, old_pgid); +}[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
PATCH v13 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, so a host flood request from one port causes unknown unicast or multicast from every port to be forwarded to the CPU.
The bridge applies promiscuous mode to enslaved ports under most conditions even when VLAN filtering is enabled. To protect a weak external CPU, port_set_host_flood requests for offloaded bridged ports are recorded, but not programmed until the port leaves the bridge. Standalone ports get programmed, so software bridging works.
---
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 | 291 ++++++++++++++++++++- drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 7 + drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 9 + 3 files changed, 296 insertions(+), 11 deletions(-)
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +280 -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,257 @@ 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_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; + + enabled = enabled && (p->stp_state ==BR_STATE_LEARNING || + p->stp_state ==BR_STATE_FORWARDING ); + +lan_rmw (ANA_PORT_CFG_LEARN_ENA_SET (enabled),ANA_PORT_CFG_LEARN_ENA , + lan9645x,ANA_PORT_CFG (p->chip_port)); +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; +u16 unbridged; + +lockdep_assert_held (&lan9645x->fwd_domain_lock); + +/* We want promiscuous and all_multi to affect standalone ports, for +* software bridging, debug and test purposes. +* +* However, the linux bridge is incredibly eager to put bridged ports in +* promiscuous mode. +* +* This is unfortunate since lan9645x flood masks are global and not per +* ingress port. When some port triggers unknown uc/mc to the CPU, the +* traffic from any port is forwarded to the CPU. +* +* If the host CPU is weak, this can cause tremendous stress. Therefore, +* we compromise by ignoring this host flood request for offloaded +* bridged ports. +*/ + unbridged = ~lan9645x->bridge_mask & +GENMASK (lan9645x->num_phys_ports -1 ,0 ); + + uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged); +lan9645x_port_pgid_set (lan9645x,PGID_UC , lan9645x->num_phys_ports, + uc_ena); + + mc_ena = !!(lan9645x->host_flood_mc_mask & unbridged); +lan9645x_port_pgid_set (lan9645x,PGID_MC , lan9645x->num_phys_ports, + mc_ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV4 , lan9645x->num_phys_ports, + mc_ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV6 , lan9645x->num_phys_ports, + mc_ena); +} + +static void lan9645x_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); +__lan9645x_port_set_host_flood (lan9645x); +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; +bool learn_ena; + + lan9645x = ds->priv; + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + p->stp_state = state; + +if (state ==BR_STATE_FORWARDING ) + lan9645x->bridge_fwd_mask |=BIT (p->chip_port); +else + lan9645x->bridge_fwd_mask &= ~BIT (p->chip_port); + + learn_ena = (state ==BR_STATE_LEARNING || + state ==BR_STATE_FORWARDING ) && p->learn_ena; + +lan_rmw (ANA_PORT_CFG_LEARN_ENA_SET (learn_ena), +ANA_PORT_CFG_LEARN_ENA , lan9645x, +ANA_PORT_CFG (p->chip_port)); + +lan9645x_update_fwd_mask (lan9645x); +mutex_unlock (&lan9645x->fwd_domain_lock); +} + +static void lan9645x_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge) +{ +struct lan9645x *lan9645x = ds->priv; +struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + lan9645x->bridge_mask &= ~BIT (p->chip_port); + +__lan9645x_port_set_host_flood (lan9645x); +lan9645x_vlan_set_hostmode (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)
@@ -521,6 +781,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 v13 8/9] net: dsa: lan9645x: add bridge 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: 3 · 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] __lan9645x_port_set_host_flood() computes uc_ena/mc_ena from host_flood_*_mask & ~bridge_mask, so it drops every host flood request…
- [Medium] The MDB code falls back to the L2 multicast flood PGID (PGID_MC) when it runs out of general-purpose PGIDs.
- [Medium] The patch sets ds->ageing_time_min = 2000 ms, so enslaving a lan9645x port to a bridge with ageing_time below 2 s (for example 0,…
--
net: dsa: lan9645x: add bridge support
This adds hardware bridge offload to the lan9645x DSA driver for a single bridge. It covers ageing time, bridge port flags, STP state and host flood. The CPU port module is taken out of the default UC/MC flood PGIDs. Host flood requests from offloaded bridged ports are recorded, but they are not programmed until the port leaves the bridge.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0@@ -324,6 +333,257 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static int lan9645x_port_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags f, +struct netlink_ext_ack *extack) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 406
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+if (f.mask &BR_MCAST_FLOOD ) { +bool ena = !!(f.val &BR_MCAST_FLOOD ); + +lan9645x_port_pgid_set (lan9645x,PGID_MC , port, ena);
[Severity: Medium]
Does this work with the MDB fallback to PGID_MC?
When the general-purpose PGIDs run out, __lan9645x_mdb_add() and __lan9645x_mdb_del() in lan9645x_mdb.c point a group at PGID_MC:
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_add() {
...
if (lan9645x_mdb_on_flood_mask(mdb_entry, type))
return lan9645x_mdb_widen_dest(lan9645x, mdb_entry,
type, NULL, PGID_MC,
new_ports);
...
}drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_del() {
...
lan9645x_mdb_narrow_dest(lan9645x, mdb_entry, type, NULL, PGID_MC,
new_ports);
...
}After the fallback, the MAC table entry forwards to whatever PGID_MC holds, not to the member mask that the MDB code computed. That worked when PGID_MC was fixed to all front ports.
With this change, "bridge link set dev swpN mcast_flood off" clears swpN from PGID_MC. In the software bridge, mcast_flood only affects unregistered multicast. Here, though, it looks like a registered member port with mcast_flood off would stop getting any group that has fallen back to PGID_MC.
One way to reach this is more than 48 distinct front port subsets among non-IP L2 MDB groups, for example static "bridge mdb add" entries on a switch with 6 or more user ports. That would use up PGID_GP_START to PGID_GP_END. IP multicast should not be affected because the MAC entry encodes the port mask. CPU membership comes from MAC_CPU_COPY.
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3
-0+lan9645x_port_pgid_set (lan9645x,PGID_MCIPV4 , port, ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV6 , port, ena); + }
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0+static void __lan9645x_port_set_host_flood (struct lan9645x *lan9645x) +{ +bool mc_ena, uc_ena; +u16 unbridged; + +lockdep_assert_held (&lan9645x->fwd_domain_lock);
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 484
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+ unbridged = ~lan9645x->bridge_mask & +GENMASK (lan9645x->num_phys_ports -1 ,0 ); + + uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged);
[Severity: Medium]lan9645x_setup() no longer puts the CPU port module in PGID_UC, PGID_MC, PGID_MCIPV4 or PGID_MCIPV6. That leaves the host flood bit as the only path for unknown unicast and unregistered multicast to reach the CPU. With the unbridged filter here, can the CPU ever get that traffic when only bridged ports ask for host flooding?
The bridge calls dev_set_allmulti(dev, 1) on every port in br_add_if(). br_manage_promisc() sets promisc when vlan_filtering=0, and also when there is more than one auto port. dsa_user_manage_host_flood() passes the flags through unchanged:
net/dsa/user.c:dsa_user_manage_host_flood() {
bool mc = dev->flags & (IFF_PROMISC | IFF_ALLMULTI);
...
bool uc = dev->flags & IFF_PROMISC;
dsa_port_set_host_flood(dp, uc, mc);
}Here, however, ~bridge_mask filters those requests out.
A few cases seem to be affected:
- Take a bridge with a lan9645x port and a foreign port such as wlan, veth or tap. The software bridge can't flood FDB misses or unregistered multicast to the foreign port. Assisted learning only covers addresses it has already learned. DSA returns -EOPNOTSUPP for MDB entries whose orig_dev is a foreign port, so the hardware would drop a multicast stream going to a wifi client.
- With multicast snooping disabled, br0 receives no non-link-local multicast.
- Setting promisc or allmulti explicitly on br0 or on a bridged port does nothing.
Documentation/networking/switchdev.rst asks for unknown unicast to be flooded to every port in the domain. It also asks for flooding to the CPU when IFF_PROMISC or IFF_ALLMULTI is set. I'd also expect the promisc and allmulti cases of test_bridge in tools/testing/selftests/net/forwarding/local_termination.sh to fail.
felix has the same global flood mask limitation, but it honours host flood for bridged ports. The commit message only presents this as protection for a weak CPU and doesn't mention these consequences.
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2
-0+lan9645x_port_pgid_set (lan9645x,PGID_UC , lan9645x->num_phys_ports, + uc_ena);
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static void lan9645x_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge) +{ +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 581
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + lan9645x->bridge_mask &= ~BIT (p->chip_port); + +__lan9645x_port_set_host_flood (lan9645x); +lan9645x_vlan_set_hostmode (p);
[Severity: Medium]
Can the new ds->ageing_time_min = 2U * MSEC_PER_SEC in lan9645x_setup() leave the driver and the DSA core disagreeing when a bridge join fails partway through?
Suppose a port joins a bridge whose ageing_time is below 2 s, for example 0. dsa_port_switchdev_sync_attrs() applies the brport flags, STP state and VLAN filtering first. Only after that does dsa_port_ageing_time() fail with -ERANGE:
dsa_port_bridge_join()
DSA_NOTIFIER_BRIDGE_JOIN -> lan9645x_port_bridge_join() dsa_port_switchdev_sync_attrs()
dsa_port_inherit_brport_flags() p->learn_ena = true, dp->learning = true
dsa_port_set_state()
dsa_port_vlan_filtering(true) p->vlan_aware = true, dp->vlan_filtering = true
dsa_port_ageing_time() -ERANGE
out_rollback_unoffload / out_rollback_unbridge
DSA_NOTIFIER_BRIDGE_LEAVE -> lan9645x_port_bridge_leave()The rollback never calls dsa_port_switchdev_unsync_attrs(). Here, lan9645x_vlan_set_hostmode() sets p->vlan_aware = false while dp->vlan_filtering stays true. p->learn_ena stays true as well.
If the port later joins a vlan_filtering=1 bridge, dsa_port_vlan_filtering() returns early:
if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) return 0;
As a result, lan9645x_port_vlan_filtering() is never called. Would the port then run VLAN-unaware (UNAWARE_PVID, no VLAN_AWARE_ENA) inside a VLAN-aware bridge?
If the port stays standalone and is brought down and up again, this path runs:
dsa_port_enable_rt()
dsa_port_set_state_now(BR_STATE_FORWARDING)
lan9645x_port_bridge_stp_state_set()
learn_ena is computed from the stale p->learn_ena, and ANA_PORT_CFG_LEARN_ENA gets set on a standalone port in HOST_PVID. Is that intended?
The missing unsync in the DSA core rollback is older than this patch. However, ageing_time_min is what makes it reachable for lan9645x. On top of that, bridge_leave resets vlan_aware without DSA knowing.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+lan9645x_update_fwd_mask (lan9645x); + +mutex_unlock (&lan9645x->fwd_domain_lock); +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 8/9] net: dsa: lan9645x: add bridge support
Quoted 85 lines · On Fri, 2026-10-02 at 21:14 +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: 3 · 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]
__lan9645x_port_set_host_flood()computes uc_ena/mc_ena from host_flood_*_mask & ~bridge_mask, so it drops every host flood request…
- [Medium] The MDB code falls back to the L2 multicast flood PGID (PGID_MC) when it runs out of general-purpose PGIDs.
- [Medium] The patch setsds->ageing_time_min= 2000 ms, so enslaving a lan9645x port to a bridge withageing_timebelow 2 s (for example 0,…--
net: dsa: lan9645x: add bridge support
This adds hardware bridge offload to the lan9645x DSA driver for a single bridge. It covers ageing time, bridge port flags, STP state and host flood. The CPU port module is taken out of the default UC/MC flood PGIDs. Host flood requests from offloaded bridged ports are recorded, but they are not programmed until the port leaves the bridge.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +0
-0@@ -324,6 +333,257 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static int lan9645x_port_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags f, +struct netlink_ext_ack *extack) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 406
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+if (f.mask &BR_MCAST_FLOOD ) { +bool ena = !!(f.val &BR_MCAST_FLOOD ); + +lan9645x_port_pgid_set (lan9645x,PGID_MC , port, ena);[Severity: Medium]
Does this work with the MDB fallback toPGID_MC?When the general-purpose PGIDs run out,
__lan9645x_mdb_add()and__lan9645x_mdb_del()inlan9645x_mdb.cpoint a group atPGID_MC:drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_add() { ... if (lan9645x_mdb_on_flood_mask(mdb_entry, type)) return lan9645x_mdb_widen_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports); ... }drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c:__lan9645x_mdb_del() { ... lan9645x_mdb_narrow_dest(lan9645x, mdb_entry, type, NULL, PGID_MC, new_ports); ... }After the fallback, the MAC table entry forwards to whatever
PGID_MCholds, not to the member mask that the MDB code computed. That worked whenPGID_MCwas fixed to all front ports.With this change, "bridge link set dev swpN
mcast_floodoff" clears swpN fromPGID_MC. In the software bridge,mcast_floodonly affects unregistered multicast. Here, though, it looks like a registered member port withmcast_floodoff would stop getting any group that has fallen back toPGID_MC.
Quoted 5 lines
One way to reach this is more than 48 distinct front port subsets among non-IP L2 MDB groups, for example static "bridge mdb add" entries on a switch with 6 or more user ports. That would use up
PGID_GP_STARTtoPGID_GP_END. IP multicast should not be affected because the MAC entry encodes the port mask. CPU membership comes fromMAC_CPU_COPY.
Dismissed. This is intended. Once a group has to fall back to PGID_MC, it is forwarded like unregistered multicast, i.e. according to the user's mcast_flood configuration. 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 forward the group to ports where mcast_flood was disabled.
Quoted 64 lines
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +3
-0+lan9645x_port_pgid_set (lan9645x,PGID_MCIPV4 , port, ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV6 , port, ena); + }[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +6
-0+static void __lan9645x_port_set_host_flood (struct lan9645x *lan9645x) +{ +bool mc_ena, uc_ena; +u16 unbridged; + +lockdep_assert_held (&lan9645x->fwd_domain_lock);[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 484
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+ unbridged = ~lan9645x->bridge_mask & +GENMASK (lan9645x->num_phys_ports -1 ,0 ); + + uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged);[Severity: Medium]
lan9645x_setup()no longer puts the CPU port module inPGID_UC,PGID_MC,PGID_MCIPV4orPGID_MCIPV6. That leaves the host flood bit as the only path for unknown unicast and unregistered multicast to reach the CPU. With the unbridged filter here, can the CPU ever get that traffic when only bridged ports ask for host flooding?The bridge calls
dev_set_allmulti(dev, 1)on every port inbr_add_if().br_manage_promisc()sets promisc when vlan_filtering=0, and also when there is more than one auto port.dsa_user_manage_host_flood()passes the flags through unchanged:net/dsa/user.c:dsa_user_manage_host_flood() { bool mc = dev->flags & (IFF_PROMISC | IFF_ALLMULTI); ... bool uc = dev->flags & IFF_PROMISC; dsa_port_set_host_flood(dp, uc, mc); }Here, however, ~bridge_mask filters those requests out.
A few cases seem to be affected:
- Take a bridge with a lan9645x port and a foreign port such as wlan, veth or tap. The software bridge can't flood FDB misses or unregistered multicast to the foreign port. Assisted learning only covers addresses it has already learned. DSA returns
-EOPNOTSUPPfor MDB entries whoseorig_devis a foreign port, so the hardware would drop a multicast stream going to a wifi client.- With multicast snooping disabled, br0 receives no non-link-local multicast.
- Setting promisc or allmulti explicitly on br0 or on a bridged port does nothing.
Documentation/networking/switchdev.rstasks for unknown unicast to be flooded to every port in the domain. It also asks for flooding to the CPU whenIFF_PROMISCorIFF_ALLMULTIis set. I'd also expect the promisc and allmulti cases oftest_bridgeintools/testing/selftests/net/forwarding/local_termination.shto fail.
Quoted 4 lines
felix has the same global flood mask limitation, but it honours host flood for bridged ports. The commit message only presents this as protection for a weak CPU and doesn't mention these consequences.
Correct. This was intentional, as described in the comment and commit message. I was aware of cases 1 and 3, but was willing to accept that in the name of comfortably running a weak host CPU. I was not aware of 2 though, and I would not accept that. I was also not aware of switchdev.rst specifically asking not to do this. Therefore, I change v14 to honours host flood requests from bridged ports as well, as felix does, so the CPU port module is in the unicast and multicast flood masks while any port requests it.
Quoted 61 lines
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +2
-0+lan9645x_port_pgid_set (lan9645x,PGID_UC , lan9645x->num_phys_ports, + uc_ena);[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+static void lan9645x_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge) +{ +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 581
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +10
-0+struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + lan9645x->bridge_mask &= ~BIT (p->chip_port); + +__lan9645x_port_set_host_flood (lan9645x); +lan9645x_vlan_set_hostmode (p);[Severity: Medium]
Can the newds->ageing_time_min= 2U *MSEC_PER_SECinlan9645x_setup()leave the driver and the DSA core disagreeing when a bridge join fails partway through?Suppose a port joins a bridge whose
ageing_timeis below 2 s, for example 0.dsa_port_switchdev_sync_attrs()applies the brport flags, STP state and VLAN filtering first. Only after that doesdsa_port_ageing_time()fail with-ERANGE:
dsa_port_bridge_join()
DSA_NOTIFIER_BRIDGE_JOIN->lan9645x_port_bridge_join()dsa_port_switchdev_sync_attrs()dsa_port_inherit_brport_flags() p->learn_ena = true, dp->learning = true dsa_port_set_state() dsa_port_vlan_filtering(true) p->vlan_aware = true, dp->vlan_filtering = true dsa_port_ageing_time() -ERANGE out_rollback_unoffload / out_rollback_unbridge DSA_NOTIFIER_BRIDGE_LEAVE -> lan9645x_port_bridge_leave()The rollback never calls
dsa_port_switchdev_unsync_attrs(). Here,lan9645x_vlan_set_hostmode()setsp->vlan_aware= false whiledp->vlan_filteringstays true.p->learn_enastays true as well.If the port later joins a vlan_filtering=1 bridge,
dsa_port_vlan_filtering()returns early:if (dsa_port_is_vlan_filtering(dp) == vlan_filtering) return 0;As a result,
lan9645x_port_vlan_filtering()is never called. Would the port then run VLAN-unaware (UNAWARE_PVID, noVLAN_AWARE_ENA) inside a VLAN-aware bridge?If the port stays standalone and is brought down and up again, this path runs:
dsa_port_enable_rt()
dsa_port_set_state_now(BR_STATE_FORWARDING)lan9645x_port_bridge_stp_state_set()
Quoted 8 lines
learn_enais computed from the stalep->learn_ena, andANA_PORT_CFG_LEARN_ENAgets set on a standalone port inHOST_PVID. Is that intended?The missing unsync in the DSA core rollback is older than this patch. However,
ageing_time_minis what makes it reachable for lan9645x. On top of that,bridge_leaveresetsvlan_awarewithout DSA knowing.
Dismissed, preexisting. As is mentioned the missing dsa_port_switchdev_unsync attrs() in the dsa_port_bridge_join() rollback predates this patch. I think it affects every driver for which a step of dsa_port_switchdev_sync_attrs() can fail after VLAN filtering was applied, including all users of ageing_time_min. Only the core can reset the cached dp->vlan_filtering and dp->learning, so that is better fixed in DSA. In v14 I can make the driver independent of this for the learning part though, so I can add that.
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port, · line 585
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +4
-0+lan9645x_update_fwd_mask (lan9645x); + +mutex_unlock (&lan9645x->fwd_domain_lock); +}[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
PATCH v13 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 maintaining a 64bit software cache, and updating it frequently to handle overflows in hardware.
The eMAC and pMAC counter sources are decoded, but only the aggregate source is reachable for now, until MAC merge support is added.
---
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 | 856 +++++++++++++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.h | 229 ++++++ 5 files changed, 1170 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 +856 -0
856 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 v13 9/9] net: dsa: lan9645x: add port statistics
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] net: dsa: lan9645x: deadlock due to sw_lock taken in process and softirq contexts - [Medium] net…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] net: dsa: lan9645x: deadlock due to sw_lock taken in process and softirq contexts
- [Medium] net: dsa: lan9645x: duplication of queue and standard stats in private ethtool -S --
commit 49afb622c4cdbf51f9a151db3a2117596b256a9a
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: lan9645x: add port statistics
This commit adds port statistics support for the LAN9645x switch. It introduces a 64-bit software cache to handle 32-bit hardware counter overflows via a periodic polling workqueue. It also implements callbacks for ethtool and netdev statistics to expose these counters to userspace.
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 166
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +5
-0+static const struct lan9645x_ethtool_stat lan9645x_port_ethtool_stats[] = { + {"rx_cat_drop" ,SCNT_RX_CAT_DROP }, + {"rx_red_prio_0" ,SCNT_RX_RED_PRIO_0 }, + {"rx_red_prio_1" ,SCNT_RX_RED_PRIO_1 }, + {"rx_red_prio_2" ,SCNT_RX_RED_PRIO_2 },
[Severity: Medium]
Should these priority queue counters be exposed through the standard netdev per-queue statistics interface instead?
Adding hardware counters to the private ethtool -S list when a standard uAPI already exists (like struct netdev_queue_stats_rx and netdev_queue_stats_tx) duplicates effort and creates confusion. The tx_drop counter listed further down in this array also appears to map directly to the standard rtnl_link_stats64.tx_dropped counter.
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +4
-0+static void __lan9645x_stats_view_idx_update (struct lan9645x *lan9645x, +enum lan9645x_view_stat_type vtype, +int idx) +{
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 335
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+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); +__lan9645x_stats_view_idx_transfer (lan9645x, vtype, idx); +spin_unlock (&s->sw_lock); + } +}
[Severity: High]
Since __lan9645x_stats_view_idx_update is called from a workqueue running in process context, can this cause a deadlock?
If a softirq interrupts the CPU while this lock is held, and the softirq attempts to read network statistics via dev_get_stats() to ndo_get_stats64(), it will attempt to acquire sw_lock in lan9645x_stats_get_stats64() and spin forever. Do these process-context paths need to use spin_lock_bh() instead?
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +4
-0+void lan9645x_stats_get_ethtool_stats (struct lan9645x *lan9645x,int port, +u64 *data) +{ +struct lan9645x_stats *stats = lan9645x->stats;
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 413
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+u64 *c; +int i; + + c =lan9645x_stats_view_idx_update (lan9645x,LAN9645X_STAT_PORTS , port); + +spin_lock (&stats->sw_lock); +for (i =0 ; i <ARRAY_SIZE (lan9645x_port_ethtool_stats); i++) + *data++ = c[lan9645x_port_ethtool_stats[i].idx]; +spin_unlock (&stats->sw_lock); +}
[Severity: High]
Similarly, since ethtool queries run in process context, does this need to be spin_lock_bh() to protect against preemption by softirqs that call lan9645x_stats_get_stats64()?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +6
-0+void lan9645x_stats_get_stats64 (struct lan9645x *lan9645x,int port, +struct rtnl_link_stats64 *stats) +{ +struct lan9645x_stats *s = lan9645x->stats; +u64 *c; +
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 550
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ 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. +* 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]
The comment notes that sw_lock is never taken from softirq/IRQ context, but lan9645x_stats_get_stats64() itself can be called from softirq context. For example, when traffic control qdiscs or bonding query network statistics.
Is it possible for this to deadlock against the plain spin_lock() calls in the ethtool and workqueue paths mentioned above?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2@microchip.com?part=9
[email protected]
AI reviewRe: [PATCH net-next v13 9/9] net: dsa: lan9645x: add port statistics
In reply to Jens Emil Schulz ØstergaardThank 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: 3 · Low: 1
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_sset_count() returns -EOPNOTSUPP (-95) for every string set other than ETH_SS_STATS.
- [Medium] lan9645x_stats_get_stats64() counts bad frames in rx_packets.
- [Medium] The eMAC and pMAC FRAG counters are handled inconsistently.
- [Low] The commit message says 'The eMAC and pMAC counter sources are decoded, but only the aggregate source is reachable for now'.
--
net: dsa: lan9645x: add port statistics
This adds port counter support to the lan9645x DSA driver. The 32 bit hardware counters are copied into 64 bit software counters by a poller that runs every three seconds. They are reported through ethtool -S, the standard ethtool statistics groups and ndo_get_stats64.
Quoted 2 lines
The eMAC and pMAC counter sources are decoded, but only the aggregate source is reachable for now, until MAC merge support is added.
[Severity: Low]
Is this sentence still accurate? None of these read the ->src field of the structure they fill in:
lan9645x_stats_get_eth_mac_stats()
lan9645x_stats_get_rmon_stats()
lan9645x_stats_get_pause_stats()
lan9645x_stats_get_eth_phy_stats()
lan9645x_stats_get_eth_ctrl_stats()
All of them always return the eMAC plus pMAC sum.
The v12 changelog says "Drop the unreachable mac merge related code", so the per-source decoding seems to have been removed. This has no runtime effect today, because without .get_mm ethtool only allows the aggregate source.
Could the message say instead that the pMAC counters are summed into the aggregate, and that per-source reporting is not implemented yet?
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -0,0 +1,856 @@
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 395
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +4
-0+int lan9645x_stats_get_sset_count (struct lan9645x *lan9645x,int port,int sset) +{ +if (sset !=ETH_SS_STATS ) +return -EOPNOTSUPP ;
[Severity: Medium]
Can this negative return value corrupt the sset counts that the conduit netdev reports? DSA replaces the conduit's get_sset_count with dsa_conduit_get_sset_count(). For every sset, that function calls:
net/dsa/conduit.c:dsa_conduit_append_port_sset_count() {
if (ds->ops->get_sset_count)
*count += ds->ops->get_sset_count(ds, port, sset);
}Nothing checks for a negative value. For ETH_SS_TEST, ETH_SS_PRIV_FLAGS and ETH_SS_PHY_STATS, the conduit therefore reports its own count minus 95.
If the conduit has fewer than 95 entries, the count is negative. Then ethtool -t, the netlink priv-flags path and ETHTOOL_GSTRINGS on the conduit fail with a bogus errno. The conduit's self-tests and private flags also drop out of ethtool -i and the netlink strset reply.
If the conduit has 95 or more entries, the result is zero or a smaller positive value. ethtool_self_test(), ethtool_get_phy_stats_ethtool() and strset_prepare_set() size their buffers from that value, but the conduit's own callbacks still write their full number of entries. No real NIC has that many entries, so this part is theoretical.
Most other DSA drivers (hellcreek, lan9303, gswip, mt7530, qca8k, a5psw, vsc73xx, and others) return 0 for unsupported ssets. Should this return 0 as well?
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +3
-0+ +return ARRAY_SIZE (lan9645x_port_ethtool_stats); +}
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 498
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +11
-0+ r->undersize_pkts = c[SCNT_RX_SHORT ] + + c[SCNT_RX_PMAC_SHORT ]; + r->oversize_pkts = c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_LONG ]; +/* SCNT_RX_FRAG counts frames received after the port is paused, and +* increments when pause frames arrive from the link partner. +* It counts neither undersize frames nor errors, so it is left out here +* and out of rx_packets, unlike lan966x which adds it to rx_errors. +* SCNT_RX_PMAC_FRAG does count number of runt frames with invalid CRC. +*/ + r->fragments = c[SCNT_RX_PMAC_FRAG ];
[Severity: Medium]
Can fragments be non-zero without MAC merge support? The pMAC receives no traffic until MAC merge is supported, so RMON fragments always reads 0 in lan9645x_stats_get_rmon_stats(). That includes the case where runts with a bad CRC arrive on the eMAC.
Documentation/networking/statistics.rst says drivers should leave fields they do not report at ETHTOOL_STAT_NOT_SET, not overwrite them with 0. If no accurate eMAC fragment count exists, would it be better to leave fragments unset?
The two MACs are also treated differently in lan9645x_stats_get_stats64(). rx_packets includes c[SCNT_RX_PMAC_FRAG] but not c[SCNT_RX_FRAG]. As a result, a bad-CRC runt is counted in rx_packets only when the pMAC receives it.
Does the hardware really use different meanings for the counters at offset 0x5 and offset 0x35, which is the same position in the pMAC block? If not, could both MACs be handled the same way?
[ ... ]
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) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 563
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ 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] +
[Severity: Medium]
Should rx_packets include SCNT_RX_SHORT, SCNT_RX_JABBER and SCNT_RX_LONG, and their pMAC equivalents? The same function counts all of them in rx_errors below, and counts JABBER and LONG in rx_length_errors too.
include/uapi/linux/if_link.h describes rx_packets as "Number of good packets received by the interface".
The SZ_* buckets also include frames with a bad FCS. The v5 changelog
says: "remove rx_crc, rx_symbol_err from rx_packets, as they are already counted in SZ_* buckets".
So when a link partner sends a runt, jabber, oversized or bad-FCS frame, it shows up in both rx_packets and rx_errors. ocelot and lan966x use a similar formula.
Would the RX_UC, RX_MC and RX_BC good frame counters, which already feed FramesReceivedOK, be a better source here?
Quoted 27 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +27
-0+ c[SCNT_RX_PMAC_SHORT ] + + c[SCNT_RX_PMAC_FRAG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_SZ_64 ] + + c[SCNT_RX_PMAC_SZ_65_127 ] + + c[SCNT_RX_PMAC_SZ_128_255 ] + + c[SCNT_RX_PMAC_SZ_256_511 ] + + c[SCNT_RX_PMAC_SZ_512_1023 ] + + c[SCNT_RX_PMAC_SZ_1024_1526 ] + + c[SCNT_RX_PMAC_SZ_JUMBO ] + + c[SCNT_RX_PMAC_LONG ]; + + 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 ]; + + stats->rx_length_errors = c[SCNT_RX_JABBER ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_LONG ];
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com
Re: [PATCH net-next v13 9/9] net: dsa: lan9645x: add port statistics
Quoted 44 lines · On Fri, 2026-10-02 at 21:14 +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: 3 · Low: 1
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_sset_count()returns-EOPNOTSUPP(-95) for every string set other thanETH_SS_STATS.
- [Medium]lan9645x_stats_get_stats64()counts bad frames inrx_packets.
- [Medium] The eMAC and pMAC FRAG counters are handled inconsistently.
- [Low] The commit message says 'The eMAC and pMAC counter sources are decoded, but only the aggregate source is reachable for now'.--
net: dsa: lan9645x: add port statistics
This adds port counter support to the lan9645x DSA driver. The 32 bit hardware counters are copied into 64 bit software counters by a poller that runs every three seconds. They are reported through ethtool -S, the standard ethtool statistics groups and
ndo_get_stats64.Quoted 2 lines
The eMAC and pMAC counter sources are decoded, but only the aggregate source is reachable for now, until MAC merge support is added.
[Severity: Low]
Is this sentence still accurate? None of these read the ->src field of the structure they fill in:
lan9645x_stats_get_eth_mac_stats()
lan9645x_stats_get_rmon_stats()
lan9645x_stats_get_pause_stats()
lan9645x_stats_get_eth_phy_stats()
lan9645x_stats_get_eth_ctrl_stats()All of them always return the eMAC plus pMAC sum.
Quoted 8 lines
The v12 changelog says "Drop the unreachable mac merge related code", so the per-source decoding seems to have been removed. This has no runtime effect today, because without .get_mm ethtool only allows the aggregate source.
Could the message say instead that the pMAC counters are summed into the aggregate, and that per-source reporting is not implemented yet?
Correct, the sentence was left over from before the per-source code was dropped. v14 says that the pMAC counters are summed into the aggregate source, and that per-source reporting is not implemented yet.
Quoted 39 lines
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0@@ -0,0 +1,856 @@[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 395
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +4
-0+int lan9645x_stats_get_sset_count (struct lan9645x *lan9645x,int port,int sset) +{ +if (sset !=ETH_SS_STATS ) +return -EOPNOTSUPP ;[Severity: Medium]
Can this negative return value corrupt the sset counts that the conduit netdev reports? DSA replaces the conduit'sget_sset_countwithdsa_conduit_get_sset_count(). For every sset, that function calls:net/dsa/conduit.c:dsa_conduit_append_port_sset_count() { if (ds->ops->get_sset_count) *count += ds->ops->get_sset_count(ds, port, sset); }Nothing checks for a negative value. For
ETH_SS_TEST,ETH_SS_PRIV_FLAGSandETH_SS_PHY_STATS, the conduit therefore reports its own count minus 95.If the conduit has fewer than 95 entries, the count is negative. Then ethtool -t, the netlink priv-flags path and
ETHTOOL_GSTRINGSon the conduit fail with a bogus errno. The conduit's self-tests and private flags also drop out of ethtool -i and the netlink strset reply.If the conduit has 95 or more entries, the result is zero or a smaller positive value.
ethtool_self_test(),ethtool_get_phy_stats_ethtool()andstrset_prepare_set()size their buffers from that value, but the conduit's own callbacks still write their full number of entries. No real NIC has that many entries, so this part is theoretical.
Quoted 4 lines
Most other DSA drivers (hellcreek, lan9303, gswip, mt7530, qca8k, a5psw, vsc73xx, and others) return 0 for unsupported ssets. Should this return 0 as well?
Correct, v14 returns 0 for the other string sets, as other DSA drivers do.
Quoted 29 lines
Quoted 3 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +3
-0+ +return ARRAY_SIZE (lan9645x_port_ethtool_stats); +}[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 498
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +11
-0+ r->undersize_pkts = c[SCNT_RX_SHORT ] + + c[SCNT_RX_PMAC_SHORT ]; + r->oversize_pkts = c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_LONG ]; +/* SCNT_RX_FRAG counts frames received after the port is paused, and +* increments when pause frames arrive from the link partner. +* It counts neither undersize frames nor errors, so it is left out here +* and out of rx_packets, unlike lan966x which adds it to rx_errors. +* SCNT_RX_PMAC_FRAG does count number of runt frames with invalid CRC. +*/ + r->fragments = c[SCNT_RX_PMAC_FRAG ];[Severity: Medium]
Can fragments be non-zero without MAC merge support? The pMAC receives no traffic until MAC merge is supported, so RMON fragments always reads 0 inlan9645x_stats_get_rmon_stats(). That includes the case where runts with a bad CRC arrive on the eMAC.
Documentation/networking/statistics.rstsays drivers should leave fields they do not report atETHTOOL_STAT_NOT_SET, not overwrite them with 0. If no accurate eMAC fragment count exists, would it be better to leave fragments unset?
Quoted 9 lines
The two MACs are also treated differently in
lan9645x_stats_get_stats64().rx_packetsincludes c[SCNT_RX_PMAC_FRAG] but not c[SCNT_RX_FRAG]. As a result, a bad-CRC runt is counted inrx_packetsonly when the pMAC receives it.Does the hardware really use different meanings for the counters at offset
0x5and offset0x35, which is the same position in the pMAC block? If not, could both MACs be handled the same way?
The two counters do differ in hardware. c_rx_frag (0x05) counts runts with an invalid CRC only on half-duplex links, on full-duplex links it counts frames received after the port is paused and increments on received pause frames. c_rx_pmac_frag (0x35) always counts runts with an invalid CRC. That is also why only the pMAC counter is part of rx_packets. I will leave RMON fragments unset, since reporting fragments from the pMAC alone is misleading
Quoted 31 lines
[ ... ]
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) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 563
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ 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] +[Severity: Medium]
Shouldrx_packetsincludeSCNT_RX_SHORT,SCNT_RX_JABBERandSCNT_RX_LONG, and their pMAC equivalents? The same function counts all of them inrx_errorsbelow, and counts JABBER and LONG inrx_length_errorstoo.
include/uapi/linux/if_link.hdescribesrx_packetsas "Number of good packets received by the interface".The SZ_* buckets also include frames with a bad FCS. The v5 changelog
says: "removerx_crc,rx_symbol_errfromrx_packets, as they are already counted in SZ_* buckets".
Quoted 6 lines
So when a link partner sends a runt, jabber, oversized or bad-FCS frame, it shows up in both
rx_packetsandrx_errors. ocelot and lan966x use a similar formula.Would the
RX_UC,RX_MCandRX_BCgood frame counters, which already feed FramesReceivedOK, be a better source here?
Dismissed, intentional. This follows mscc/ocelot, which computes rx_packets the same way. The hardware has no good-frames-only octet counter, c_rx_oct counts octets in good and bad frames, so rx_bytes cannot follow the uapi description either. rx_packets is therefore 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, jabber and long frames fall outside that range, so every received frame is counted exactly once. Bad frames are also reported in rx_errors.
Quoted 33 lines
Quoted 18 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +17
-0+ c[SCNT_RX_PMAC_SHORT ] + + c[SCNT_RX_PMAC_FRAG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_SZ_64 ] + + c[SCNT_RX_PMAC_SZ_65_127 ] + + c[SCNT_RX_PMAC_SZ_128_255 ] + + c[SCNT_RX_PMAC_SZ_256_511 ] + + c[SCNT_RX_PMAC_SZ_512_1023 ] + + c[SCNT_RX_PMAC_SZ_1024_1526 ] + + c[SCNT_RX_PMAC_SZ_JUMBO ] + + c[SCNT_RX_PMAC_LONG ]; + + 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] +drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 590
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+ c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_SHORT ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_CRC ] + + c[SCNT_RX_PMAC_LONG ]; + + stats->rx_length_errors = c[SCNT_RX_JABBER ] + + c[SCNT_RX_LONG ] + + c[SCNT_RX_PMAC_JABBER ] + + c[SCNT_RX_PMAC_LONG ];[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2%40microchip.com