net: dsa: add DSA support for the LAN9645x switch chip family
Subsystems (5)
v10 cover net: dsa: add DSA support for the LAN9645x switch chip family
This series provides the Microchip LAN9645X Switch driver.
The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.
The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.
The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.
The chip supports a variety of network features such as
* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing
The LAN9645x family consists of the following SKUs:
LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S
The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.
This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.c
which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.
The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.
Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.
The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf
This series will deliver the following features:
* Standalone ports
* Bridge forwarding and FDB offloading
* VLAN-aware bridge
* Stats integration
More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:
* Add LAG support.
* Add MDB support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.
For completeness I include tentative plan of planned patches for LAN9645x peripherals:
* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.
---
Changes in v10:
- Individual patches mention specific v10 changes
- Update tag driver after skb ownership model change in DSA taggers.
- Link to v9: https://lore.kernel.org/r/20260708-dsa_lan9645x_switch_driver_base-v9-0-0d1512a326d7@microchip.com
Changes in v9:
- Individual patches mention specific v9 changes
- Drop RGMII muxing to port 4.
- Link to v8: https://lore.kernel.org/r/20260702-dsa_lan9645x_switch_driver_base-v8-0-90228d8bba58@microchip.com
Changes in v8:
- Individual patches mention specific v8 changes
- Do not use the name CPU_PORT for the chips internal CPU port module,
as it collides with the DSA CPU port (the NPI front port). Drop the
CPU_PORT macro and reference the module as lan9645x->num_phys_ports,
mirroring ocelot/felix.
- Reword the port map and related comments to distinguish the chip CPU
port modules (indices 9-10) from the DSA CPU port.
- Add a port_mux_lock mutex to serialize port mux arbitration in
the phylink mac_prepare path.
- Link to v7: https://lore.kernel.org/r/20260603-dsa_lan9645x_switch_driver_base-v7-0-b2f90e676707@microchip.com
Changes in v7:
- Individual patches mention specific v7 changes
- Do not mark the BPDU range 01:80:C2:00:00:0X as offloaded in the tag driver.
- Refactor cpu queue based frame classification to use categories default, trap
and copy, which mirrors usage instead of being based on frame types.
- Add registers ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.
- Use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames.
- Refactor IGMP/MLD/IPMC_CTRL to use new LAN9645X_CPUQ_DEF,
LAN9645X_CPUQ_TRAP and LAN9645X_CPUQ_COPY queues.
- Add __aligned(2) to mac variable in lan9645x_mdb_update_dest.
- Link to v6: https://lore.kernel.org/r/20260527-dsa_lan9645x_switch_driver_base-v6-0-4d409ae64f3c@microchip.com
Changes in v6:
- Individual patches mention specific v6 changes
- Rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34
- Link to v5: https://lore.kernel.org/r/20260518-dsa_lan9645x_switch_driver_base-v5-0-968fbf34ffa3@microchip.com
Changes in v5:
- Individual patches mention specific v5 changes
- Undo offset fix in postpull_rcsum. The original logic was correct for
CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask
- remove unused fields dd_dis and tsn_dis, and add SKU supported port validation
during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully
dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4
and 7.
- rx/tx-internal-delay-ps checked against supported 2ns value
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit
- use ds->ageing_time_max
- use packed p->host_flood_req for atomic r/w
- fix typo in set_ageing_time comment
- include lan9645x->bridge deref under lock in brige_join
- switch -EBUSY to -EINVAL for vlan add/del in the reserved range.
- remove reserved HSR vlan
- lan9645x_mac_init returns error on table init timeout
- add comment about skipping LOCKED entries on fdb dump
- skip igmp/mld redir for npi port
- make lan9645x_stats_init void
- add SCNT_TX_BUFDROP to tx_dropped
- change rmon range {0,64} -> {64, 64}. Runt frames counted elsewhere.
- remove rx_crc, rx_symbol_err from rx_packets, as they are already
counted in SZ_* buckets.
- add defensive cancel_delayed_work_sync in stats_free
- Link to v4: https://lore.kernel.org/r/20260430-dsa_lan9645x_switch_driver_base-v4-0-f1b6005fa8b7@microchip.com
Changes in v4:
- v3 was deferred, but I made some changes based on the Sashiko review
- Individual patches mention specific v4 changes
- Fix offset in postpull_rcsum so prefix eth header is cleared, not
actual eth header, so tag driver works with CHECKSUM_COMPLETE host
NICs
- Fix untagged rx on vlan aware port with pvid
- Add comment to QSYS_RES_CFG configuration
- Phylink_mac_prepare: fix to make sure we can dynamically change rgmii
on port 4
- Move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- Skip WARN_ON in lan9645x_to_port
- set_host_flood changed to per port work to coalesce values and skip
atomic allocations
- Fix clear HOST_PVID vlan membership when a port joins a bridge.
- Explicit default value write to tag type register for untagged frames
- Use lan_rmw for ANA_DROP_CFG
- Add comment for error path in lan9645x_vlan_hw_wr
- Remove mac_entries list and just do direct IO to mac table from
fdb_add/fdb_del.
- Clean up fresh mdb when hw mac table write fails.
- Remove rx_uc and tx_uc from ethtool stats list, as they are derivable
from the eth-mac group
- Split stats_init into stats_alloc and stats_init, use alloc in probe
and init in dsa_setup
- Link to v3: https://lore.kernel.org/r/20260410-dsa_lan9645x_switch_driver_base-v3-0-aadc8595306d@microchip.com
Changes in v3:
- Individual patches mention specific v3 changes.
- Add guard before vlan_remove_tag on xmit
- Add pskb_may_pull checks on rx
- Remove additionalProperties: true in bindings
- Remove unnecessary | from description in bindings
- Change top level $ref to dsa.yaml#/$defs/ethernet-ports
- Use ethernet-ports and ethernet-port
- Move ethernet-ports under properties instead of patternProperties
- Move unevaluatedProperties: false after $ref
- Update bindings example to use ethernet-ports and ethernet-port
- Move DEV_MAC_TAGS_CFG to port setup, instead of vlan config, so vlan
overhead is always included in port frame maxlen calculation.
- Remove code disabling ipv6 on conduit
- Use of_property_read_u32 for {rx,tx}-internal-delay-ps
- Use dsa_user_ports(ds) instead of
GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- Add comment explaining obey vlan
- Allow disabling aging with explicit zero parameters.
- Fix non-forwarding STP states in bridge fwd calculation.
- Restore host flood state on bridge leave.
- Avoid mac_entry dealloc when mac table writes fail.
- Avoid mdb_entry dealloc when mac table writes fail.
- Dealloc mac_entries on deinit.
- Dealloc mdb_entries on deinit.
- Link to v2: https://lore.kernel.org/r/20260324-dsa_lan9645x_switch_driver_base-v2-0-f7504e3b0681@microchip.com
Changes in v2:
- Individual patches have specific v2 changes.
- Ran DSA, and std counters, selftests, which prompted several changes.
The following selftests pass, except for some expected failures:
- bridge_vlan_aware.sh
- bridge_vlan_unaware.sh
- bridge_vlan_mcast.sh
- no_forwarding.sh
- bridge_mdb.sh
- bridge_mld.sh
- test_fdb_stress_test.sh
- .../drivers/net/hw/ethtool_rmon.sh
- .../drivers/net/hw/ethtool_std_stats.sh (from Ioana's series)
- Added new patch for MDB management, as this was required for selftests.
- Added port_set_host_flood to enable unknown traffic to standalone during
promisc/ALL_MULTI (selftests).
- Remove the dubugfs.
- Link to v1: https://lore.kernel.org/r/20260303-dsa_lan9645x_switch_driver_base-v1-0-bff8ca1396f5@microchip.com
---
Jens Emil Schulz Østergaard (9):
net: dsa: add tag driver for LAN9645X
dt-bindings: net: lan9645x: add LAN9645X switch bindings
net: dsa: lan9645x: add autogenerated register macros
net: dsa: lan9645x: add basic dsa driver for LAN9645X
net: dsa: lan9645x: add bridge support
net: dsa: lan9645x: add vlan support
net: dsa: lan9645x: add mac table integration
net: dsa: lan9645x: add mdb management
net: dsa: lan9645x: add port statistics
.../net/dsa/microchip,lan96455s-switch.yaml | 111 ++ MAINTAINERS | 10 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 11 + drivers/net/dsa/microchip/lan9645x/Makefile | 12 + drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c | 307 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 1038 +++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 439 +++++ drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 398 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 85 + .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 382 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 226 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1937 ++++++++++++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.c | 929 ++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.h | 279 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 403 ++++ include/linux/dsa/lan9645x.h | 144 ++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 316 ++++ 22 files changed, 7044 insertions(+)
---
base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e
change-id: 20260210-dsa_lan9645x_switch_driver_base-312bbfc37edb
Best regards,
Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
PATCH v10 1/9 net: dsa: add tag driver for LAN9645X
Add tag driver for LAN9645x using a front port as CPU port. This mode is called an NPI port in the datasheet.
Use long prefix on extraction (RX) and no prefix on injection (TX). A long prefix on extraction helps get through the conduit port on host side, since it will see a broadcast MAC.
The LAN9645x chip is in the same design architecture family as ocelot and lan966x. The tagging protocol has the same structure as these chips, but the particular fields are different or have different sizes. Therefore, this tag driver is similar to tag_ocelot.c, but the differences in fields makes it hard to reuse.
LAN9645x supports 3 different tag formats for extraction/injection of frames from a CPU port: long prefix, short prefix and no prefix.
The tag is prepended to the frame. The critical data for the chip is contained in an internal frame header (IFH) which is 28 bytes. The prefix formats look like this:
Long prefix (16 bytes) + IFH:
- DMAC = 0xffffffffffff on extraction. - SMAC = 0xfeffffffffff on extraction. - ETYPE = 0x8880
- payload = 0x0011
- IFH
Short prefix (4 bytes) + IFH:
- 0x8880
- 0x0011
- IFH
No prefix:
- IFH
The format can be configured asymmetrically on RX and TX.
The IFH get/set functions are declared as inline. All the field constants are compile-time known, so when these calls are inlined efficient code is generated with branches pruned and loops unrolled. During testing it was observed that without explicit inlining GCC would have trouble inlining the functions, which hurt performance.
---
Changes in v10:
- Update tag driver after skb ownership model change in DSA taggers. Explicitly freeing the skb at rcv/xmit return points.
Changes in v8:
- Drop the cpu_port local and use ds->num_ports directly as the IFH source port (the CPU port module index).
- Reword the reflection comment to refer to "the CPU".
Changes in v7:
- Introduce cpu queue based frame classification, and refactor to the categories default, trap and copy, which mirrors usage instead of being based on frame types.
Changes in v6:
- rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34
Changes in v5:
- Undo offset fix in postpull_rcsum. The original logic was correct for CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask
Changes in v4:
- Fix offset in postpull_rcsum so prefix eth header is cleared, not actual eth header, so tag driver works with CHECKSUM_COMPLETE host NICs
- Fix untagged rx on vlan aware port with pvid
Changes in v3:
- guard vlan_remove_tag behind skb_headlen(skb) >= VLAN_ETH_HLEN on xmit
- add pskb_may_pull checks in rx path
Changes in v2:
- sorting in net/dsa/Kconfig
- sorting in net/dsa/Makefile
- remove default zero promisc_on_conduit
- move functions to to .c file
- add justification for inline usage to commit message
- add __skb_put_padto on xmit path
- fix hwaccel_put_tag
--- MAINTAINERS | 8 ++ include/linux/dsa/lan9645x.h | 144 ++++++++++++++++++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 ++ net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 316 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 482 insertions(+)
MAINTAINERS +8 -0
@@ -17622,6 +17622,14 @@ L: [email protected] S: Maintained F: drivers/net/phy/microchip_t1.c +MICROCHIP LAN9645X ETHERNET SWITCH DRIVER +M: Jens Emil Schulz Østergaard <[email protected]> +M: [email protected] +L: [email protected] +S: Maintained +F: include/linux/dsa/lan9645x.h +F: net/dsa/tag_lan9645x.c + MICROCHIP LAN966X ETHERNET DRIVER M: Horatiu Vultur <[email protected]> M: [email protected]
include/linux/dsa/lan9645x.h new file +144 -0
144 lines not on this page · raw message
include/net/dsa.h +2 -0
@@ -59,6 +59,7 @@ struct tc_action;#define DSA_TAG_PROTO_MXL_GSW1XX_VALUE 31#define DSA_TAG_PROTO_MXL862_VALUE 32#define DSA_TAG_PROTO_NETC_VALUE 33 +#define DSA_TAG_PROTO_LAN9645X_VALUE 34enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -95,6 +96,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_MXL_GSW1XX =DSA_TAG_PROTO_MXL_GSW1XX_VALUE ,DSA_TAG_PROTO_MXL862 =DSA_TAG_PROTO_MXL862_VALUE ,DSA_TAG_PROTO_NETC =DSA_TAG_PROTO_NETC_VALUE , + DSA_TAG_PROTO_LAN9645X = DSA_TAG_PROTO_LAN9645X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +11 -0
@@ -75,6 +75,17 @@ config NET_DSA_TAG_HELLCREEK Say Y or M if you want to enable support for tagging frames for the Hirschmann Hellcreek TSN switches. +config NET_DSA_TAG_LAN9645X + tristate "Tag driver for Lan9645x switches" + help + Say Y or M if you want to enable NPI tagging for the Lan9645x switches. + In this mode, the frames over the Ethernet CPU port are prepended with + a hardware-defined injection/extraction frame header. + On injection a 28 byte internal frame header (IFH) is used. On + extraction a 16 byte prefix is prepended before the internal frame + header. This prefix starts with a broadcast MAC, to ease passage + through the host side RX filter. + config NET_DSA_TAG_GSWIP tristate "Tag driver for Lantiq / Intel GSWIP switches" help
net/dsa/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_NET_DSA_TAG_GSWIP) += tag_gswip.o obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o +obj-$(CONFIG_NET_DSA_TAG_LAN9645X) += tag_lan9645x.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o obj-$(CONFIG_NET_DSA_TAG_MXL_GSW1XX) += tag_mxl-gsw1xx.o
net/dsa/tag_lan9645x.c new file +316 -0
316 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v10 1/9] net: dsa: add tag driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Adding an out-of-band VLAN tag without checking for and popping an existing payload tag results in…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Adding an out-of-band VLAN tag without checking for and popping an existing payload tag results in double-tagged frames. --
--- Patch [1]: [PATCH net-next v10 1/9] net: dsa: add tag driver for LAN9645X --- commit 3fca3b09e95a3eeee247c89f8ecdf602074e9506
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: add tag driver for LAN9645X
This commit adds a DSA tag driver for the LAN9645x family of switches. It configures an NPI port to use a 16-byte long prefix on extraction and no prefix on injection, prepending an internal frame header (IFH) to transmit critical data.
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0
-0
[ ... ]
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 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+/* While we have REW_PORT_NO_REWRITE=0 on the NPI port, we still disable +* port VLAN tagging with REW_TAG_CFG. Any classified VID, different +* from a VID in the frame, will not be written to the frame, but is +* only communicated via the IFH. So for VLAN-aware ports we add the IFH +* vlan to the skb.
net/dsa/tag_lan9645x.c line 297
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+*/ + dp =dsa_user_to_port (skb->dev); + vlan_tpid = tag_type ?ETH_P_8021AD :ETH_P_8021Q ; + +if (dsa_port_is_vlan_filtering (dp) && vlan_tci) { +u16 port_pvid =0 ; + +br_vlan_get_pvid_rcu (skb->dev, &port_pvid); + +if ((vlan_tci &VLAN_VID_MASK ) != port_pvid)
[Severity: High]
Does this code result in double-tagged frames?
If the hardware delivers the frame without stripping the in-band tag because port VLAN rewrite is disabled, calling __vlan_hwaccel_put_tag() here adds an out-of-band tag while leaving the original in-band tag intact in the payload. This would cause the network stack to process a single 802.1Q tagged frame from the wire as a Q-in-Q double-tagged frame.
Should lan9645x_rcv() pop the existing payload tag (for example, using __skb_vlan_pop()) before adding the out-of-band tag to avoid duplicating it?
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+__vlan_hwaccel_put_tag (skb,htons (vlan_tpid), vlan_tci); + } + +return skb; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=1
Re: [PATCH net-next v10 1/9] net: dsa: add tag driver for LAN9645X
Quoted 46 lines · On Tue, 2026-07-14 at 14:43 +0000, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Adding an out-of-band VLAN tag without checking for and popping an existing payload tag results in double-tagged frames. ----- Patch [1]: [PATCH net-next v10 1/9] net: dsa: add tag driver for LAN9645X --- commit
3fca3b09e95a3eeee247c89f8ecdf602074e9506
Author: Jens Emil Schulz Østergaard <[email protected]>net: dsa: add tag driver for LAN9645X
This commit adds a DSA tag driver for the LAN9645x family of switches. It configures an NPI port to use a 16-byte long prefix on extraction and no prefix on injection, prepending an internal frame header (IFH) to transmit critical data.
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +0
-0[ ... ]
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 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+/* While we have REW_PORT_NO_REWRITE=0 on the NPI port, we still disable +* port VLAN tagging with REW_TAG_CFG. Any classified VID, different +* from a VID in the frame, will not be written to the frame, but is +* only communicated via the IFH. So for VLAN-aware ports we add the IFH +* vlan to the skb. net/dsa/tag_lan9645x.c line 297
Quoted 10 lines
net/dsa/tag_lan9645x.c new file +10
-0+*/ + dp =dsa_user_to_port (skb->dev); + vlan_tpid = tag_type ?ETH_P_8021AD :ETH_P_8021Q ; + +if (dsa_port_is_vlan_filtering (dp) && vlan_tci) { +u16 port_pvid =0 ; + +br_vlan_get_pvid_rcu (skb->dev, &port_pvid); + +if ((vlan_tci &VLAN_VID_MASK ) != port_pvid)[Severity: High]
Does this code result in double-tagged frames?
Quoted 9 lines
If the hardware delivers the frame without stripping the in-band tag because port VLAN rewrite is disabled, calling
__vlan_hwaccel_put_tag()here adds an out-of-band tag while leaving the original in-band tag intact in the payload. This would cause the network stack to process a single 802.1Q tagged frame from the wire as a Q-in-Q double-tagged frame.Should
lan9645x_rcv()pop the existing payload tag (for example, using__skb_vlan_pop()) before adding the out-of-band tag to avoid duplicating it?
This is a false positive. On a vlan aware port, the vlan tag is popped and all vlan info is stored in the IFH. The tag will not egress in the frame data unless the rewriter pushes it, and we disable this toward the cpu via REW_TAG_CFG.
There is no in-band vlan tag in the frame in this scenario. Only the IFH contains the classified vlan info, so we add it to the skb. Using __skb_vlan_pop would corrupt the frame, and we avoid it on purpose. I will update the comment to be more clear about this.
Quoted 8 lines
net/dsa/tag_lan9645x.c line 302
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+__vlan_hwaccel_put_tag (skb,htons (vlan_tpid), vlan_tci); + } + +return skb; +}--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=1
PATCH v10 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.
---
Changes in v5:
- No changes.
Changes in v4:
- No changes.
Changes in v3:
- remove additionalProperties: true
- remove unnecessary | from description
- change top level $ref to dsa.yaml#/$defs/ethernet-ports
- use ethernet-ports and ethernet-port
- move ethernet-ports under properties instead of patternProperties
- move unevaluatedProperties: false after $ref
- update example to use ethernet-ports and ethernet-port
Changes in v2:
- rename file to microchip,lan96455s-switch.yaml
- remove led vendor property
- add {rx,tx}-internal-delay-ps for rgmii delay
- remove labels from example
- remove container node from example
--- .../net/dsa/microchip,lan96455s-switch.yaml | 111 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 112 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +111 -0
@@ -0,0 +1,111 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/microchip,lan96455s-switch.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip LAN9645x Ethernet switch + +maintainers: + - Jens Emil Schulz Østergaard <[email protected]> + +description: + The LAN9645x switch is a multi-port Gigabit AVB/TSN Ethernet switch with + five integrated 10/100/1000Base-T PHYs. In addition to the integrated PHYs, + it supports up to 2 RGMII/RMII, up to 2 BASE-X/SERDES/2.5GBASE-X and one + Quad-SGMII interfaces. + +properties: + compatible: + oneOf: + - enum: + - microchip,lan96455s-switch + - items: + - enum: + - microchip,lan96455f-switch + - microchip,lan96457f-switch + - microchip,lan96459f-switch + - microchip,lan96457s-switch + - microchip,lan96459s-switch + - const: microchip,lan96455s-switch + + reg: + maxItems: 1 + + ethernet-ports: + type: object + patternProperties: + "^ethernet-port@[0-8]$": + type: object + description: Ethernet switch ports + + $ref: dsa-port.yaml# + unevaluatedProperties: false + + properties: + rx-internal-delay-ps: + const: 2000 + + tx-internal-delay-ps: + const: 2000 + +$ref: dsa.yaml#/$defs/ethernet-ports + +required: + - compatible + - reg + - ethernet-ports + +unevaluatedProperties: false + +examples: + - | + ethernet-switch@4000 { + compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch"; + reg = <0x4000 0x244>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + phy-mode = "gmii"; + phy-handle = <&cuphy0>; + }; + + ethernet-port@1 { + reg = <1>; + phy-mode = "gmii"; + phy-handle = <&cuphy1>; + }; + + ethernet-port@2 { + reg = <2>; + phy-mode = "gmii"; + phy-handle = <&cuphy2>; + }; + + ethernet-port@3 { + reg = <3>; + phy-mode = "gmii"; + phy-handle = <&cuphy3>; + }; + + ethernet-port@7 { + reg = <7>; + phy-mode = "rgmii"; + ethernet = <&cpu_host_port>; + rx-internal-delay-ps = <2000>; + tx-internal-delay-ps = <2000>; + + fixed-link { + speed = <1000>; + full-duplex; + pause; + }; + }; + }; + }; +... +
MAINTAINERS +1 -0
@@ -17627,6 +17627,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 v10 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: - [Medium] DT binding schema strictly prohibits `mdio` bus nodes, breaking the ability to define integrated…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] DT binding schema strictly prohibits mdio bus nodes, breaking the ability to define integrated PHYs. --
--- Patch [2]: [PATCH net-next v10 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings --- commit d0ca8cd625881ac3b8529fd977bdb0c8a0c3b129
Author: Jens Emil Schulz Østergaard <[email protected]>
dt-bindings: net: lan9645x: add LAN9645X switch bindings
Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch.
Quoted 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 59
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6
-0+required: + - compatible + - reg + - ethernet-ports + +unevaluatedProperties: false
[Severity: Medium]
Will this schema reject valid hardware descriptions that include an mdio child node for the integrated PHYs?
Since the schema sets unevaluatedProperties: false without defining or referencing an mdio property, any mdio node defined in a device tree will be rejected as an illegal property.
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +5
-0+ +examples: + - | + ethernet-switch@4000 { + compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch";
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 74
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +10
-0+ reg = <0x4000 0x244>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + phy-mode = "gmii"; + phy-handle = <&cuphy0>;
[Severity: Medium]
Does the schema allow defining the integrated PHY nodes referenced here?
The example demonstrates the necessity of phy-handle pointers to integrated PHY nodes (such as &cuphy0), yet the schema's constraints make it structurally impossible to validly define the MDIO bus for those PHYs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=2
Re: [PATCH net-next v10 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings
Quoted 57 lines · On Tue, 2026-07-14 at 14:43 +0000, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] DT binding schema strictly prohibitsmdiobus nodes, breaking the ability to define integrated PHYs. ----- Patch [2]: [PATCH net-next v10 2/9] dt-bindings: net: lan9645x: add LAN9645X switch bindings --- commit
d0ca8cd625881ac3b8529fd977bdb0c8a0c3b129
Author: Jens Emil Schulz Østergaard <[email protected]>dt-bindings: net: lan9645x: add LAN9645X switch bindings
Add bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch.
Quoted 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 59
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6
-0+required: + - compatible + - reg + - ethernet-ports + +unevaluatedProperties: false[Severity: Medium]
Will this schema reject valid hardware descriptions that include an mdio child node for the integrated PHYs?Since the schema sets unevaluatedProperties: false without defining or referencing an mdio property, any mdio node defined in a device tree will be rejected as an illegal property.
Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +5
-0+ +examples: + - | + ethernet-switch@4000 { + compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch";Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 74
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +10
-0+ reg = <0x4000 0x244>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + phy-mode = "gmii"; + phy-handle = <&cuphy0>;[Severity: Medium]
Does the schema allow defining the integrated PHY nodes referenced here?
Quoted 4 lines
The example demonstrates the necessity of phy-handle pointers to integrated PHY nodes (such as &cuphy0), yet the schema's constraints make it structurally impossible to validly define the MDIO bus for those PHYs.
I think this is a false positive. Any peripherals such as MDIO controllers are meant to be child nodes of an MFD device, as siblings of this switch node. The MDIO bus devices will not be subnodes of this switch node, so they are not meant to be accomodated by this schema.
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=2
PATCH v10 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 v7:
- Add ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.
Changes in v3:
- No changes
Changes in v2:
- Add cpuq registers
--- MAINTAINERS | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1937 ++++++++++++++++++++ 2 files changed, 1938 insertions(+)
MAINTAINERS +1 -0
@@ -17628,6 +17628,7 @@ M: [email protected] L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml +F: drivers/net/dsa/microchip/lan9645x/* F: include/linux/dsa/lan9645x.h F: net/dsa/tag_lan9645x.c
drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h new file +1937 -0
1,937 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v10 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.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c.
This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.c
which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.
The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.
---
Changes in v9:
- Drop the DEV4 RGMII muxing support.
Changes in v8:
- Remove the CPU_PORT macro, which named the chips internal CPU port module and collided with the DSA CPU port terminology. Reference the module as lan9645x->num_phys_ports.
- Rework the port map comment to distinguish the chip CPU port modules (indices 9-10) from the DSA CPU port (the NPI front port).
- Derive PGID_GP_START from NUM_PHYS_PORTS instead of CPU_PORT.
- Add a port_mux_lock mutex to serialize port mux arbitration in lan9645x_phylink_mac_prepare().
Changes in v7:
- use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames
Changes in v5:
- remove dd_dis and tsn_dis, and add SKU supported port validation during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4 and 7.
- rx/tx-internal-delay-ps checked against support 2ns value
- update commit message
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit
Changes in v4:
- add comment to QSYS_RES_CFG configuration
- phylink_mac_prepare: fix to make sure we can dynamically change rgmii on port 4
- move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- skip WARN_ON in lan9645x_to_port
Changes in v3:
- move DEV_MAC_TAGS_CFG config to port setup, for vlan overhead in port frame maxlen
- remove code disabling ipv6 on conduit
- use of_property_read_u32 for {rx,tx}-internal-delay-ps
- use dsa_user_ports(ds) instead of GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- update obey vlan comment
Changes in v2:
- source Kconfig from drivers/net/dsa/Kconfig
- sorting in Kconfig and Makefiles
- remove unused struct fields
- remote path delays
- use port_setup and dp->dn instead of DTS parsing
- phylink: split rgmii setup into dll and speed config
- phylink: remove pcs/sgmii/qsgmii related code
- phylink: simplify mac_prepare
- phylink: remove phylink_ops wrappers
- phylink: remove unrelated config from link up
- phylink: reorder functions according to phylink call order
--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 11 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 447 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 332 +++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 85 ++++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 382 ++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 214 ++++++++++ 9 files changed, 1482 insertions(+)
drivers/net/dsa/Kconfig +2 -0
@@ -72,6 +72,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/microchip/lan9645x/Kconfig" + source "drivers/net/dsa/mv88e6xxx/Kconfig" source "drivers/net/dsa/mxl862xx/Kconfig"
drivers/net/dsa/microchip/Makefile +1 -0
@@ -12,3 +12,4 @@ endif obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += lan9645x/
drivers/net/dsa/microchip/lan9645x/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MICROCHIP_LAN9645X + tristate "Microchip Lan9645x switch support" + depends on NET_DSA + select NET_DSA_TAG_LAN9645X + help + This driver adds DSA support for Microchip Lan9645x switch chips. + The lan9645x switch is a multi-port Gigabit AVB/TSN Ethernet Switch + with five integrated 10/100/1000Base-T PHYs. In addition to the + integrated PHYs, it supports up to 2 RGMII/RMII, up to 2 + BASE-X/SERDES/2.5GBASE-X and one Quad-SGMII/Quad-USGMII interfaces.
drivers/net/dsa/microchip/lan9645x/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o + +mchp-lan9645x-objs := \ + lan9645x_main.o \ + lan9645x_npi.o \ + lan9645x_phylink.o \ + lan9645x_port.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +447 -0
447 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +332 -0
332 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c new file +85 -0
85 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +382 -0
382 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +214 -0
214 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing FDB operations and omission of the CPU port in PGID_UC breaks unicast IP traffic to the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing FDB operations and omission of the CPU port in PGID_UC breaks unicast IP traffic to the CPU. --
--- Patch [4]: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X --- commit 996cf37c0fe28c352442c3b82c0b401974b8f66a
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: lan9645x: add basic dsa driver for LAN9645X
Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0
[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,447 @@
[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +2
-0+static int lan9645x_setup (struct dsa_switch *ds) +{
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +9
-0+/* Multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MC )); + +/* IP multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV4 )); +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV6 )); + +/* Unicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_UC ));
[Severity: High]
Does omitting the CPU port module (BIT(lan9645x->num_phys_ports)) from the unknown unicast flooding mask (PGID_UC) prevent unicast traffic from reaching the CPU?
Since hardware learning is disabled in lan9645x_port_setup() via ANA_PORT_CFG_LEARN_ENA_SET(0), and the lan9645x_switch_ops struct lacks a port_fdb_add callback to statically program the CPU's MAC address, unicast frames destined for the CPU will be treated as unknown unicast.
Because PGID_UC only includes front_ports, it appears these unknown unicast frames will be flooded to the front ports but not to the CPU, effectively breaking unicast IP connectivity (such as ARP replies) to the host.
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+ +/* Broadcast to cpu and all front ports */ +lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, +ANA_PGID (PGID_BC ));
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=4
Re: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Quoted 48 lines · On Tue, 2026-07-14 at 14:43 +0000, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing FDB operations and omission of the CPU port inPGID_UCbreaks unicast IP traffic to the CPU. ----- Patch [4]: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X --- commit
996cf37c0fe28c352442c3b82c0b401974b8f66a
Author: Jens Emil Schulz Østergaard <[email protected]>net: dsa: lan9645x: add basic dsa driver for LAN9645X
Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,447 @@[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +2
-0+static int lan9645x_setup (struct dsa_switch *ds) +{[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +9
-0+/* Multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MC )); + +/* IP multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV4 )); +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV6 )); + +/* Unicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_UC ));[Severity: High]
Does omitting the CPU port module (BIT(lan9645x->num_phys_ports)) from the unknown unicast flooding mask (PGID_UC) prevent unicast traffic from reaching the CPU?
Quoted 9 lines
Since hardware learning is disabled in
lan9645x_port_setup()viaANA_PORT_CFG_LEARN_ENA_SET(0), and thelan9645x_switch_opsstruct lacks aport_fdb_addcallback to statically program the CPU's MAC address, unicast frames destined for the CPU will be treated as unknown unicast.Because
PGID_UConly includesfront_ports, it appears these unknown unicast frames will be flooded to the front ports but not to the CPU, effectively breaking unicast IP connectivity (such as ARP replies) to the host.
I think this is a false positive. I have split the patches to make review easier. The callbacks
port_fdb_addport_mdb_addport_set_host_flood
are added in later patches in the same series. These handle unknown and known traffic toward the CPU. For standalone ports flooding of unknown traffic to the cpu can be configured with promiscuous mode and all_multi.
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 264
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+ +/* Broadcast to cpu and all front ports */ +lan_wr (BIT (lan9645x->num_phys_ports) | front_ports, lan9645x, +ANA_PGID (PGID_BC ));[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=4
Paolo Abeni
maintainerRe: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
In reply to Jens Emil Schulz ØstergaardQuoted 410 lines · Jens Emil Schulz Østergaard
Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.
This patch only wires up the internal CuPHYs (ports 0-4) and the RGMII paths for ports 7 and 8. The supported SerDes-based modes: SGMII, QSGMII, 1000BASE-X and 2500BASE-X on ports 5-8 are deferred, and support will be added in follow-up patches. Port 5-6 have no usable interface mode in this patch, and should not be declared in DT until SerDes support lands.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in
drivers/mfd/ocelot-spi.c.This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.cwhich 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.
Reviewed-by Steen Hegelund <[email protected]>Signed-off-by Jens Emil Schulz Østergaard <[email protected]>---
Changes in v9:
- Drop the DEV4 RGMII muxing support.Changes in v8:
- Remove theCPU_PORTmacro, which named the chips internal CPU port module and collided with the DSA CPU port terminology. Reference the module aslan9645x->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).
- DerivePGID_GP_STARTfromNUM_PHYS_PORTSinstead ofCPU_PORT.
- Add aport_mux_lockmutex to serialize port mux arbitration inlan9645x_phylink_mac_prepare().Changes in v7:
- use cpu queueLAN9645X_CPUQ_TRAPfor bpdu framesChanges in v5:
- removedd_disandtsn_dis, and add SKU supported port validation during setup
- phylink: removeMAC_2500FD
- phylink: add comment about emptysupported_interfacesfor 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
- initlan9645x->npi= -1 at probe and check port < 0 innpi_deinitChanges in v4:
- add comment toQSYS_RES_CFGconfiguration
-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
- skipWARN_ONinlan9645x_to_portChanges in v3:
- moveDEV_MAC_TAGS_CFGconfig to port setup, for vlan overhead in port frame maxlen
- remove code disabling ipv6 on conduit
- useof_property_read_u32for {rx,tx}-internal-delay-ps
- usedsa_user_ports(ds)instead ofGENMASK(lan9645x->num_phys_ports - 1, 0)as base flood mask.
- update obey vlan commentChanges in v2:
- sourceKconfigfromdrivers/net/dsa/Kconfig
- sorting inKconfigand Makefiles
- remove unused struct fields
- remote path delays
- useport_setupanddp->dninstead of DTS parsing
- phylink: split rgmii setup into dll and speed config
- phylink: remove pcs/sgmii/qsgmii related code
- phylink: simplifymac_prepare
- phylink: removephylink_opswrappers
- phylink: remove unrelated config from link up
- phylink: reorder functions according to phylink call order--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 11 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 447 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 332 +++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 85 ++++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 382 ++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 214 ++++++++++ 9 files changed, 1482 insertions(+)drivers/net/dsa/Kconfig +2
-0@@ -72,6 +72,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/microchip/lan9645x/Kconfig" + source "drivers/net/dsa/mv88e6xxx/Kconfig" source "drivers/net/dsa/mxl862xx/Kconfig"drivers/net/dsa/microchip/Makefile +1
-0@@ -12,3 +12,4 @@ endif obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += lan9645x/drivers/net/dsa/microchip/lan9645x/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MICROCHIP_LAN9645X + tristate "Microchip Lan9645x switch support" + depends on NET_DSA + select NET_DSA_TAG_LAN9645X + help + This driver adds DSA support for Microchip Lan9645x switch chips. + The lan9645x switch is a multi-port Gigabit AVB/TSN Ethernet Switch + with five integrated 10/100/1000Base-T PHYs. In addition to the + integrated PHYs, it supports up to 2 RGMII/RMII, up to 2 + BASE-X/SERDES/2.5GBASE-X and one Quad-SGMII/Quad-USGMII interfaces.drivers/net/dsa/microchip/lan9645x/Makefile new file +8
-0@@ -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 +250
-0@@ -0,0 +1,447 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2026 Microchip Technology Inc. +*/ + +#include <linux/platform_device.h> + +#include "lan9645x_main.h" + +static const char *lan9645x_resource_names[NUM_TARGETS +1 ] = { + [TARGET_GCB ] ="gcb" , + [TARGET_QS ] ="qs" , + [TARGET_CHIP_TOP ] ="chip_top" , + [TARGET_REW ] ="rew" , + [TARGET_SYS ] ="sys" , + [TARGET_HSIO ] ="hsio" , + [TARGET_DEV ] ="dev" , + [TARGET_DEV +1 ] ="dev1" , + [TARGET_DEV +2 ] ="dev2" , + [TARGET_DEV +3 ] ="dev3" , + [TARGET_DEV +4 ] ="dev4" , + [TARGET_DEV +5 ] ="dev5" , + [TARGET_DEV +6 ] ="dev6" , + [TARGET_DEV +7 ] ="dev7" , + [TARGET_DEV +8 ] ="dev8" , + [TARGET_QSYS ] ="qsys" , + [TARGET_AFI ] ="afi" , + [TARGET_ANA ] ="ana" , + [NUM_TARGETS ] =NULL , +}; + +static int lan9645x_tag_npi_setup (struct dsa_switch *ds) +{ +struct dsa_port *dp, *first_cpu_dp =NULL ; +struct lan9645x *lan9645x = ds->priv; + +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 ; + } + +if (first_cpu_dp && dp->cpu_dp != first_cpu_dp) { +dev_err (ds->dev,"Multiple NPI ports not supported\n" ); +return -EINVAL ; + } + + first_cpu_dp = dp->cpu_dp; + } + +if (!first_cpu_dp) +return -EINVAL ; + +lan9645x_npi_port_init (lan9645x, first_cpu_dp); + +return 0 ; +} + +static enum dsa_tag_protocol lan9645x_get_tag_protocol (struct dsa_switch *ds, +int port, +enum dsa_tag_protocol tp) +{ +return DSA_TAG_PROTO_LAN9645X ; +} + +static void lan9645x_teardown (struct dsa_switch *ds) +{ +struct lan9645x *lan9645x = ds->priv; + +lan9645x_npi_port_deinit (lan9645x, lan9645x->npi); +} + +static int lan9645x_change_mtu (struct dsa_switch *ds,int port,int new_mtu) +{ +return lan9645x_port_set_maxlen (ds->priv, port, new_mtu); +} + +static int lan9645x_get_max_mtu (struct dsa_switch *ds,int port) +{ +struct lan9645x *lan9645x = ds->priv; +int max_mtu; + +/* Actual MAC max MTU is around 16KB. We set 10000 - overhead which +* should be sufficient for all jumbo frames. Larger frames can cause +* problems especially with flow control, since we only have 160K queue +* buffer. +*/ + max_mtu =10000 -ETH_HLEN -ETH_FCS_LEN ; + +if (port == lan9645x->npi) { + max_mtu -=LAN9645X_IFH_LEN ; + max_mtu -=LAN9645X_LONG_PREFIX_LEN ; + } + +return max_mtu; +} + +static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +int val =0 ; +int err; + +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 ); + err =lan9645x_rd_poll_timeout (lan9645x,SYS_RAM_INIT , val, +SYS_RAM_INIT_RAM_INIT_GET (val) ==0 ); +if (err) { +dev_err (lan9645x->dev,"Failed to init chip RAM.\n" ); +return err; + } +lan_wr (SYS_RESET_CFG_CORE_ENA_SET (1 ), lan9645x,SYS_RESET_CFG ); + +return 0 ; +} + +static int lan9645x_setup (struct dsa_switch *ds) +{ +struct lan9645x *lan9645x = ds->priv; +struct device *dev = lan9645x->dev; +int supported, used =0 ; +struct dsa_port *dp; +u32 front_ports; +int err; + + lan9645x->num_phys_ports = ds->num_ports; + front_ports =dsa_user_ports (ds); + supported = lan9645x->num_phys_ports - lan9645x->num_port_dis; + +dsa_switch_for_each_available_port (dp, ds) + used++; + +if (used > supported) { +dev_err (ds->dev, +"%d physical ports in use in DT, SKU supports at most %d\n" , + used, supported); +return -EINVAL ; + } + + err =lan9645x_reset_switch (lan9645x); +if (err) +return err; + + err =lan9645x_tag_npi_setup (ds); +if (err) { +dev_err (dev,"Failed to setup NPI port.\n" ); +return err; + } + +/* Link Aggregation Mode: NETDEV_LAG_HASH_L2 */ +lan_wr (ANA_AGGR_CFG_AC_SMAC_ENA | +ANA_AGGR_CFG_AC_DMAC_ENA , + lan9645x,ANA_AGGR_CFG ); + +/* Flush queues */ +lan_wr (GENMASK (1 ,0 ), lan9645x,QS_XTR_FLUSH ); + +/* Allow to drain */ +usleep_range (1000 ,2000 ); + +/* All Queues normal */ +lan_wr (0x0 , lan9645x,QS_XTR_FLUSH ); + +/* Set MAC age time to default value, the entry is aged after +* 2 * AGE_PERIOD +*/ +lan_wr (ANA_AUTOAGE_AGE_PERIOD_SET (BR_DEFAULT_AGEING_TIME /2 /HZ ), + lan9645x,ANA_AUTOAGE ); + +/* Disable learning for frames discarded by VLAN ingress filtering */ +lan_rmw (ANA_ADVLEARN_VLAN_CHK_SET (1 ), +ANA_ADVLEARN_VLAN_CHK , + lan9645x,ANA_ADVLEARN ); + +/* Queue system frame ageing. We target 2s ageing. +* +* Register unit is 1024 cycles. +* +* ASIC: 165.625 Mhz ~ 6.0377 ns period +* +* 1024 * 6.0377 ns =~ 6182 ns +* val = 2000000000ns / 6182ns +*/ +lan_wr (SYS_FRM_AGING_AGE_TX_ENA_SET (1 ) | +SYS_FRM_AGING_MAX_AGE_SET ((2000000000 /6182 )), + lan9645x,SYS_FRM_AGING ); + +/* Setup flooding PGIDs for IPv4/IPv6 multicast. Control and dataplane +* use the same masks. Control frames are redirected to CPU, and +* the network stack is responsible for forwarding these. +* The dataplane is forwarding according to the offloaded MDB entries. +*/ +lan_wr (ANA_FLOODING_IPMC_FLD_MC4_DATA_SET (PGID_MCIPV4 ) | +ANA_FLOODING_IPMC_FLD_MC4_CTRL_SET (PGID_MC ) | +ANA_FLOODING_IPMC_FLD_MC6_DATA_SET (PGID_MCIPV6 ) | +ANA_FLOODING_IPMC_FLD_MC6_CTRL_SET (PGID_MC ), + lan9645x,ANA_FLOODING_IPMC ); + +/* There are 8 priorities */ +for (int prio =0 ; prio <8 ; ++prio) +lan_wr (ANA_FLOODING_FLD_MULTICAST_SET (PGID_MC ) | +ANA_FLOODING_FLD_UNICAST_SET (PGID_UC ) | +ANA_FLOODING_FLD_BROADCAST_SET (PGID_BC ), + lan9645x,ANA_FLOODING (prio)); + +/* Allow VLAN table to control whether cpu copy from the pgid table is +* enabled. Index PGID_ENTRIES is CPU src pgid, so we skip it as the +* configuration makes little sense here. +*/ +for (int i =0 ; i <PGID_ENTRIES ; ++i) +lan_wr (ANA_PGID_CFG_OBEY_VLAN_SET (1 ), + lan9645x,ANA_PGID_CFG (i)); + +/* Disable bridging by default */ +for (int p =0 ; p < lan9645x->num_phys_ports; p++) { +lan_wr (0 , lan9645x,ANA_PGID (PGID_SRC + p)); + +/* Do not forward BPDU frames to the front ports and copy them +* to CPU +*/ +lan_wr (ANA_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA , + lan9645x,ANA_CPU_FWD_BPDU_CFG (p)); + } + +for (int i =0 ; i <16 ; i++) { +/* The register instance number corresponds to the +* address of the extracted frame. For instance: +* CPUQ_8021_CFG[4].CPUQ_BPDU_VAL +* is the cpu extraction queue used for BPDU frames +* with address 01-80-C2-00-00-04 +*/ +lan_rmw (ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL_SET (LAN9645X_CPUQ_TRAP ), +ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL , + lan9645x,ANA_CPUQ_8021_CFG (i)); + } + +/* Reserve ~1700 bytes of buffer memory per (port, prio) for source +* tracking (resource 0, indices 0..95) and destination tracking +* (resource 2, indices 512..607). These are access watermarks, not +* pre-allocations: a flow draws from its reservation first, then +* from the shared pool. Keeping the reservation above a max-size +* Ethernet frame prevents a single frame from spilling into the +* shared pool, and cause pause frames to be emitted without actual +* congestion. +*/ +for (int i =0 ; i <=QSYS_Q_RSRV ; ++i) { +lan_wr (QS_SRC_BUF_RSV /64 , lan9645x,QSYS_RES_CFG (i)); +lan_wr (QS_SRC_BUF_RSV /64 , lan9645x,QSYS_RES_CFG (512 + i)); + } + +lan9645x_port_cpu_init (lan9645x);
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ +/* Multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MC )); + +/* IP multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV4 )); +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV6 )); + +/* Unicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_UC ));
Sashiko noted that the port mask here should likely include the CPU port, to allow correct handling of unknown unicast.
For the same reason I think even multicast should be forwarded to the CPU port.
There are a couple of other reports, but I think they are false positives.
Note that is expected that you replies to sashiko reports on the ML.
/P
Re: [PATCH net-next v10 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Quoted 429 lines · Paolo Abeni
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 410 lines · Jens Emil Schulz Østergaard
Add the LAN9645X basic DSA driver with initialization, parent regmap requests, port module initialization for NPI, CPU ports and front ports, and phylink integration for MAC side configuration.
This patch only wires up the internal CuPHYs (ports 0-4) and the RGMII paths for ports 7 and 8. The supported SerDes-based modes: SGMII, QSGMII, 1000BASE-X and 2500BASE-X on ports 5-8 are deferred, and support will be added in follow-up patches. Port 5-6 have no usable interface mode in this patch, and should not be declared in DT until SerDes support lands.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in
drivers/mfd/ocelot-spi.c.This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.cwhich 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.
Reviewed-by Steen Hegelund <[email protected]>Signed-off-by Jens Emil Schulz Østergaard <[email protected]>---
Changes in v9:
- Drop the DEV4 RGMII muxing support.Changes in v8:
- Remove theCPU_PORTmacro, which named the chips internal CPU port module and collided with the DSA CPU port terminology. Reference the module aslan9645x->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).
- DerivePGID_GP_STARTfromNUM_PHYS_PORTSinstead ofCPU_PORT.
- Add aport_mux_lockmutex to serialize port mux arbitration inlan9645x_phylink_mac_prepare().Changes in v7:
- use cpu queueLAN9645X_CPUQ_TRAPfor bpdu framesChanges in v5:
- removedd_disandtsn_dis, and add SKU supported port validation during setup
- phylink: removeMAC_2500FD
- phylink: add comment about emptysupported_interfacesfor 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
- initlan9645x->npi= -1 at probe and check port < 0 innpi_deinitChanges in v4:
- add comment toQSYS_RES_CFGconfiguration
-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
- skipWARN_ONinlan9645x_to_portChanges in v3:
- moveDEV_MAC_TAGS_CFGconfig to port setup, for vlan overhead in port frame maxlen
- remove code disabling ipv6 on conduit
- useof_property_read_u32for {rx,tx}-internal-delay-ps
- usedsa_user_ports(ds)instead ofGENMASK(lan9645x->num_phys_ports - 1, 0)as base flood mask.
- update obey vlan commentChanges in v2:
- sourceKconfigfromdrivers/net/dsa/Kconfig
- sorting inKconfigand Makefiles
- remove unused struct fields
- remote path delays
- useport_setupanddp->dninstead of DTS parsing
- phylink: split rgmii setup into dll and speed config
- phylink: remove pcs/sgmii/qsgmii related code
- phylink: simplifymac_prepare
- phylink: removephylink_opswrappers
- phylink: remove unrelated config from link up
- phylink: reorder functions according to phylink call order--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 11 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 447 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 332 +++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 85 ++++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 382 ++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 214 ++++++++++ 9 files changed, 1482 insertions(+)drivers/net/dsa/Kconfig +2
-0@@ -72,6 +72,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/microchip/lan9645x/Kconfig" + source "drivers/net/dsa/mv88e6xxx/Kconfig" source "drivers/net/dsa/mxl862xx/Kconfig"drivers/net/dsa/microchip/Makefile +1
-0@@ -12,3 +12,4 @@ endif obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += lan9645x/drivers/net/dsa/microchip/lan9645x/Kconfig new file +11
-0@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MICROCHIP_LAN9645X + tristate "Microchip Lan9645x switch support" + depends on NET_DSA + select NET_DSA_TAG_LAN9645X + help + This driver adds DSA support for Microchip Lan9645x switch chips. + The lan9645x switch is a multi-port Gigabit AVB/TSN Ethernet Switch + with five integrated 10/100/1000Base-T PHYs. In addition to the + integrated PHYs, it supports up to 2 RGMII/RMII, up to 2 + BASE-X/SERDES/2.5GBASE-X and one Quad-SGMII/Quad-USGMII interfaces.drivers/net/dsa/microchip/lan9645x/Makefile new file +8
-0@@ -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 +250
-0@@ -0,0 +1,447 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2026 Microchip Technology Inc. +*/ + +#include <linux/platform_device.h> + +#include "lan9645x_main.h" + +static const char *lan9645x_resource_names[NUM_TARGETS +1 ] = { + [TARGET_GCB ] ="gcb" , + [TARGET_QS ] ="qs" , + [TARGET_CHIP_TOP ] ="chip_top" , + [TARGET_REW ] ="rew" , + [TARGET_SYS ] ="sys" , + [TARGET_HSIO ] ="hsio" , + [TARGET_DEV ] ="dev" , + [TARGET_DEV +1 ] ="dev1" , + [TARGET_DEV +2 ] ="dev2" , + [TARGET_DEV +3 ] ="dev3" , + [TARGET_DEV +4 ] ="dev4" , + [TARGET_DEV +5 ] ="dev5" , + [TARGET_DEV +6 ] ="dev6" , + [TARGET_DEV +7 ] ="dev7" , + [TARGET_DEV +8 ] ="dev8" , + [TARGET_QSYS ] ="qsys" , + [TARGET_AFI ] ="afi" , + [TARGET_ANA ] ="ana" , + [NUM_TARGETS ] =NULL , +}; + +static int lan9645x_tag_npi_setup (struct dsa_switch *ds) +{ +struct dsa_port *dp, *first_cpu_dp =NULL ; +struct lan9645x *lan9645x = ds->priv; + +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 ; + } + +if (first_cpu_dp && dp->cpu_dp != first_cpu_dp) { +dev_err (ds->dev,"Multiple NPI ports not supported\n" ); +return -EINVAL ; + } + + first_cpu_dp = dp->cpu_dp; + } + +if (!first_cpu_dp) +return -EINVAL ; + +lan9645x_npi_port_init (lan9645x, first_cpu_dp); + +return 0 ; +} + +static enum dsa_tag_protocol lan9645x_get_tag_protocol (struct dsa_switch *ds, +int port, +enum dsa_tag_protocol tp) +{ +return DSA_TAG_PROTO_LAN9645X ; +} + +static void lan9645x_teardown (struct dsa_switch *ds) +{ +struct lan9645x *lan9645x = ds->priv; + +lan9645x_npi_port_deinit (lan9645x, lan9645x->npi); +} + +static int lan9645x_change_mtu (struct dsa_switch *ds,int port,int new_mtu) +{ +return lan9645x_port_set_maxlen (ds->priv, port, new_mtu); +} + +static int lan9645x_get_max_mtu (struct dsa_switch *ds,int port) +{ +struct lan9645x *lan9645x = ds->priv; +int max_mtu; + +/* Actual MAC max MTU is around 16KB. We set 10000 - overhead which +* should be sufficient for all jumbo frames. Larger frames can cause +* problems especially with flow control, since we only have 160K queue +* buffer. +*/ + max_mtu =10000 -ETH_HLEN -ETH_FCS_LEN ; + +if (port == lan9645x->npi) { + max_mtu -=LAN9645X_IFH_LEN ; + max_mtu -=LAN9645X_LONG_PREFIX_LEN ; + } + +return max_mtu; +} + +static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +int val =0 ; +int err; + +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 ); + err =lan9645x_rd_poll_timeout (lan9645x,SYS_RAM_INIT , val, +SYS_RAM_INIT_RAM_INIT_GET (val) ==0 ); +if (err) { +dev_err (lan9645x->dev,"Failed to init chip RAM.\n" ); +return err; + } +lan_wr (SYS_RESET_CFG_CORE_ENA_SET (1 ), lan9645x,SYS_RESET_CFG ); + +return 0 ; +} + +static int lan9645x_setup (struct dsa_switch *ds) +{ +struct lan9645x *lan9645x = ds->priv; +struct device *dev = lan9645x->dev; +int supported, used =0 ; +struct dsa_port *dp; +u32 front_ports; +int err; + + lan9645x->num_phys_ports = ds->num_ports; + front_ports =dsa_user_ports (ds); + supported = lan9645x->num_phys_ports - lan9645x->num_port_dis; + +dsa_switch_for_each_available_port (dp, ds) + used++; + +if (used > supported) { +dev_err (ds->dev, +"%d physical ports in use in DT, SKU supports at most %d\n" , + used, supported); +return -EINVAL ; + } + + err =lan9645x_reset_switch (lan9645x); +if (err) +return err; + + err =lan9645x_tag_npi_setup (ds); +if (err) { +dev_err (dev,"Failed to setup NPI port.\n" ); +return err; + } + +/* Link Aggregation Mode: NETDEV_LAG_HASH_L2 */ +lan_wr (ANA_AGGR_CFG_AC_SMAC_ENA | +ANA_AGGR_CFG_AC_DMAC_ENA , + lan9645x,ANA_AGGR_CFG ); + +/* Flush queues */ +lan_wr (GENMASK (1 ,0 ), lan9645x,QS_XTR_FLUSH ); + +/* Allow to drain */ +usleep_range (1000 ,2000 ); + +/* All Queues normal */ +lan_wr (0x0 , lan9645x,QS_XTR_FLUSH ); + +/* Set MAC age time to default value, the entry is aged after +* 2 * AGE_PERIOD +*/ +lan_wr (ANA_AUTOAGE_AGE_PERIOD_SET (BR_DEFAULT_AGEING_TIME /2 /HZ ), + lan9645x,ANA_AUTOAGE ); + +/* Disable learning for frames discarded by VLAN ingress filtering */ +lan_rmw (ANA_ADVLEARN_VLAN_CHK_SET (1 ), +ANA_ADVLEARN_VLAN_CHK , + lan9645x,ANA_ADVLEARN ); + +/* Queue system frame ageing. We target 2s ageing. +* +* Register unit is 1024 cycles. +* +* ASIC: 165.625 Mhz ~ 6.0377 ns period +* +* 1024 * 6.0377 ns =~ 6182 ns +* val = 2000000000ns / 6182ns +*/ +lan_wr (SYS_FRM_AGING_AGE_TX_ENA_SET (1 ) | +SYS_FRM_AGING_MAX_AGE_SET ((2000000000 /6182 )), + lan9645x,SYS_FRM_AGING ); + +/* Setup flooding PGIDs for IPv4/IPv6 multicast. Control and dataplane +* use the same masks. Control frames are redirected to CPU, and +* the network stack is responsible for forwarding these. +* The dataplane is forwarding according to the offloaded MDB entries. +*/ +lan_wr (ANA_FLOODING_IPMC_FLD_MC4_DATA_SET (PGID_MCIPV4 ) | +ANA_FLOODING_IPMC_FLD_MC4_CTRL_SET (PGID_MC ) | +ANA_FLOODING_IPMC_FLD_MC6_DATA_SET (PGID_MCIPV6 ) | +ANA_FLOODING_IPMC_FLD_MC6_CTRL_SET (PGID_MC ), + lan9645x,ANA_FLOODING_IPMC ); + +/* There are 8 priorities */ +for (int prio =0 ; prio <8 ; ++prio) +lan_wr (ANA_FLOODING_FLD_MULTICAST_SET (PGID_MC ) | +ANA_FLOODING_FLD_UNICAST_SET (PGID_UC ) | +ANA_FLOODING_FLD_BROADCAST_SET (PGID_BC ), + lan9645x,ANA_FLOODING (prio)); + +/* Allow VLAN table to control whether cpu copy from the pgid table is +* enabled. Index PGID_ENTRIES is CPU src pgid, so we skip it as the +* configuration makes little sense here. +*/ +for (int i =0 ; i <PGID_ENTRIES ; ++i) +lan_wr (ANA_PGID_CFG_OBEY_VLAN_SET (1 ), + lan9645x,ANA_PGID_CFG (i)); + +/* Disable bridging by default */ +for (int p =0 ; p < lan9645x->num_phys_ports; p++) { +lan_wr (0 , lan9645x,ANA_PGID (PGID_SRC + p)); + +/* Do not forward BPDU frames to the front ports and copy them +* to CPU +*/ +lan_wr (ANA_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA , + lan9645x,ANA_CPU_FWD_BPDU_CFG (p)); + } + +for (int i =0 ; i <16 ; i++) { +/* The register instance number corresponds to the +* address of the extracted frame. For instance: +* CPUQ_8021_CFG[4].CPUQ_BPDU_VAL +* is the cpu extraction queue used for BPDU frames +* with address 01-80-C2-00-00-04 +*/ +lan_rmw (ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL_SET (LAN9645X_CPUQ_TRAP ), +ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL , + lan9645x,ANA_CPUQ_8021_CFG (i)); + } + +/* Reserve ~1700 bytes of buffer memory per (port, prio) for source +* tracking (resource 0, indices 0..95) and destination tracking +* (resource 2, indices 512..607). These are access watermarks, not +* pre-allocations: a flow draws from its reservation first, then +* from the shared pool. Keeping the reservation above a max-size +* Ethernet frame prevents a single frame from spilling into the +* shared pool, and cause pause frames to be emitted without actual +* congestion. +*/ +for (int i =0 ; i <=QSYS_Q_RSRV ; ++i) { +lan_wr (QS_SRC_BUF_RSV /64 , lan9645x,QSYS_RES_CFG (i)); +lan_wr (QS_SRC_BUF_RSV /64 , lan9645x,QSYS_RES_CFG (512 + i)); + } + +lan9645x_port_cpu_init (lan9645x);drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 260
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+ +/* Multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MC )); + +/* IP multicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV4 )); +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_MCIPV6 )); + +/* Unicast to all front ports */ +lan_wr (front_ports, lan9645x,ANA_PGID (PGID_UC ));Sashiko noted that the port mask here should likely include the CPU port, to allow correct handling of unknown unicast.
Quoted 9 lines
For the same reason I think even multicast should be forwarded to the CPU port.
There are a couple of other reports, but I think they are false positives.
Note that is expected that you replies to sashiko reports on the ML.
/P
Ok understood. I have been unsure what to do with the sashiko-dev mails, since they are not responding to the series thread. I will reply to the mails on the sashiko-reviews list. I do think all 4 are false positives.
For the one you mention here, I have split the patches to make it easier to review. The callbacks port_fdb_add and port_mdb_add are implemented in later patches in the same series, along with port_set_host_flood for controlling forwarding of unknown traffic to the CPU.
After those patches I do not think there are issues with unknown traffic to the CPU.
Thanks,
Emil
PATCH v10 5/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.
---
Changes in v9:
- Drop the port_mux_lock teardown from the setup error path, as the mutex has been removed.
Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module in the port pgid and host flood helpers.
Changes in v5:
- use ds->ageing_time_max
- use packed p->host_flood_req for atomic r/w
- fix typo in set_ageing_time comment
- include lan9645x->bridge deref under lock in brige_join
Changes in v4:
- set_host_flood changed to per port work to coalesce values and skip atomic allocations
Changes in v3:
- allow disabling aging with explicit zero parameters.
- fix non-forwarding stp states
- fix restore host_flood requests on bridge leave
- destroy fwd_domain_lock mutex on setup err path
Changes in v2:
- variable name consistency
- port_set_learning use stp_state before writing to hw
- add set_host_flood for selftests, which need promic/all_multi on standalone interfaces
--- drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 309 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 27 ++ 2 files changed, 336 insertions(+)
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +309 -0
@@ -67,7 +67,9 @@ static void lan9645x_teardown(struct dsa_switch *ds) {struct lan9645x *lan9645x = ds->priv; +destroy_workqueue (lan9645x->owq);lan9645x_npi_port_deinit (lan9645x, lan9645x->npi); +mutex_destroy (&lan9645x->fwd_domain_lock); }static int lan9645x_change_mtu (struct dsa_switch *ds,int port,int new_mtu)
@@ -146,6 +148,8 @@ static int lan9645x_setup(struct dsa_switch *ds)return err; } +mutex_init (&lan9645x->fwd_domain_lock); +/* Link Aggregation Mode: NETDEV_LAG_HASH_L2 */ lan_wr(ANA_AGGR_CFG_AC_SMAC_ENA | ANA_AGGR_CFG_AC_DMAC_ENA,
@@ -265,15 +269,34 @@ static int lan9645x_setup(struct dsa_switch *ds)lan9645x_port_set_tail_drop_wm (lan9645x); + lan9645x->owq =alloc_ordered_workqueue ("%s-owq" ,0 , +dev_name (lan9645x->dev)); +if (!lan9645x->owq) { + err = -ENOMEM ; + goto err_mutex; + } + ds->mtu_enforcement_ingress = true; ds->assisted_learning_on_cpu_port = true; ds->fdb_isolation = true; +/* ANA_AUTOAGE_AGE_PERIOD is a seconds-based field and entries are +* aged after 2 * AGE_PERIOD, giving (2 * FIELD_MAX) seconds of +* maximum aging. +*/ + ds->ageing_time_max =2U *MSEC_PER_SEC * +FIELD_MAX (ANA_AUTOAGE_AGE_PERIOD ); +dev_info (lan9645x->dev,"SKU features: max_ports=%d\n" , lan9645x->num_phys_ports - lan9645x->num_port_dis);return 0 ; + +err_mutex: +mutex_destroy (&lan9645x->fwd_domain_lock); +lan9645x_npi_port_deinit (lan9645x, lan9645x->npi); +return err; } static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,
@@ -282,6 +305,282 @@ static void lan9645x_port_phylink_get_caps(struct dsa_switch *ds, int port,lan9645x_phylink_get_caps (ds->priv, port, config); } +static int lan9645x_set_ageing_time (struct dsa_switch *ds,unsigned int msecs) +{ +u32 age_secs =max (1 , msecs /MSEC_PER_SEC /2 ); +struct lan9645x *lan9645x = ds->priv; + +/* Entry must suffer two aging scans before it is removed, so it is +* aged after 2*AGE_PERIOD, and the unit is in seconds. +* An age period of 0 disables automatic aging. +*/ +lan_rmw (ANA_AUTOAGE_AGE_PERIOD_SET (msecs ? age_secs :0 ), +ANA_AUTOAGE_AGE_PERIOD , + lan9645x,ANA_AUTOAGE ); +return 0 ; +} + +static int lan9645x_port_pre_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags flags, +struct netlink_ext_ack *extack) +{ +if (flags.mask & + ~(BR_LEARNING |BR_FLOOD |BR_MCAST_FLOOD |BR_BCAST_FLOOD )) +return -EINVAL ; + +return 0 ; +} + +static void lan9645x_port_pgid_set (struct lan9645x *lan9645x,u16 pgid, +int chip_port,bool enabled) +{ +u32 reg_msk, port_msk; + +WARN_ON (chip_port > lan9645x->num_phys_ports); + + port_msk =ANA_PGID_PGID_SET (enabled ?BIT (chip_port) :0 ); + reg_msk =ANA_PGID_PGID_SET (BIT (chip_port)); + +lan_rmw (port_msk, reg_msk, lan9645x,ANA_PGID (pgid)); +} + +static void lan9645x_port_set_learning (struct lan9645x *lan9645x,int port, +bool enabled) +{ +struct lan9645x_port *p =lan9645x_to_port (lan9645x, port); + + p->learn_ena = enabled; + + enabled = enabled && (p->stp_state ==BR_STATE_LEARNING || + p->stp_state ==BR_STATE_FORWARDING ); + +lan_rmw (ANA_PORT_CFG_LEARN_ENA_SET (enabled),ANA_PORT_CFG_LEARN_ENA , + lan9645x,ANA_PORT_CFG (port)); +} + +static int lan9645x_port_bridge_flags (struct dsa_switch *ds,int port, +struct switchdev_brport_flags f, +struct netlink_ext_ack *extack) +{ +struct lan9645x *lan9645x = ds->priv; + +if (WARN_ON (port == lan9645x->npi)) +return -EINVAL ; + +if (f.mask &BR_LEARNING ) +lan9645x_port_set_learning (lan9645x, port, + !!(f.val &BR_LEARNING )); + +if (f.mask &BR_FLOOD ) +lan9645x_port_pgid_set (lan9645x,PGID_UC , port, + !!(f.val &BR_FLOOD )); + +if (f.mask &BR_MCAST_FLOOD ) { +bool ena = !!(f.val &BR_MCAST_FLOOD ); + +lan9645x_port_pgid_set (lan9645x,PGID_MC , port, ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV4 , port, ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV6 , port, ena); + } + +if (f.mask &BR_BCAST_FLOOD ) +lan9645x_port_pgid_set (lan9645x,PGID_BC , port, + !!(f.val &BR_BCAST_FLOOD )); + +return 0 ; +} + +static void lan9645x_update_fwd_mask (struct lan9645x *lan9645x) +{ +struct lan9645x_port *p; +struct dsa_port *dp; + +lockdep_assert_held (&lan9645x->fwd_domain_lock); + +/* Updates the source port PGIDs, making sure frames from p +* are only forwarded to ports q != p, where q is relevant to forward +*/ +dsa_switch_for_each_available_port (dp, lan9645x->ds) { +u32 mask =0 ; + + p =lan9645x_to_port (lan9645x, dp->index); + +if (lan9645x_port_is_bridged (p) && + (lan9645x->bridge_fwd_mask &BIT (dp->index))) { + mask = lan9645x->bridge_mask & + lan9645x->bridge_fwd_mask & ~BIT (dp->index); + } + +lan_wr (mask, lan9645x,ANA_PGID (PGID_SRC + dp->index)); + } +} + +static void __lan9645x_port_mark_host_flood (struct lan9645x *lan9645x,int port, +bool uc,bool mc) +{ +lockdep_assert_held (&lan9645x->fwd_domain_lock); + +if (uc) + lan9645x->host_flood_uc_mask |=BIT (port); +else + lan9645x->host_flood_uc_mask &= ~BIT (port); + +if (mc) + lan9645x->host_flood_mc_mask |=BIT (port); +else + lan9645x->host_flood_mc_mask &= ~BIT (port); +} + +static void __lan9645x_port_set_host_flood (struct lan9645x *lan9645x) +{ +bool mc_ena, uc_ena; +u16 unbridged; + +lockdep_assert_held (&lan9645x->fwd_domain_lock); + +/* We want promiscuous and all_multi to affect standalone ports, for +* debug and test purposes. +* +* However, the linux bridge is incredibly eager to put bridged ports in +* promiscuous mode. +* +* This is unfortunate since lan9645x flood masks are global and not per +* ingress port. When some port triggers unknown uc/mc to the CPU, the +* traffic from any port is forwarded to the CPU. +* +* If the host CPU is weak, this can cause tremendous stress. Therefore, +* we compromise by ignoring this host flood request for bridged ports. +*/ + unbridged = ~lan9645x->bridge_mask &GENMASK (NUM_PHYS_PORTS -1 ,0 ); + + uc_ena = !!(lan9645x->host_flood_uc_mask & unbridged); +lan9645x_port_pgid_set (lan9645x,PGID_UC , lan9645x->num_phys_ports, + uc_ena); + + mc_ena = !!(lan9645x->host_flood_mc_mask & unbridged); +lan9645x_port_pgid_set (lan9645x,PGID_MC , lan9645x->num_phys_ports, + mc_ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV4 , lan9645x->num_phys_ports, + mc_ena); +lan9645x_port_pgid_set (lan9645x,PGID_MCIPV6 , lan9645x->num_phys_ports, + mc_ena); +} + +static void lan9645x_host_flood_work_fn (struct work_struct *work) +{ + struct lan9645x_port *p = container_of(work, struct lan9645x_port, + host_flood_work); +struct lan9645x *lan9645x = p->lan9645x; +u8 req; + + req =READ_ONCE (p->host_flood_req); + +mutex_lock (&lan9645x->fwd_domain_lock); +__lan9645x_port_mark_host_flood (lan9645x, p->chip_port, + req &LAN9645X_HOST_FLOOD_UC , + req &LAN9645X_HOST_FLOOD_MC ); +__lan9645x_port_set_host_flood (lan9645x); +mutex_unlock (&lan9645x->fwd_domain_lock); +} + +/* Called in atomic context. */ +static void lan9645x_port_set_host_flood (struct dsa_switch *ds,int port, +bool uc,bool mc) +{ +struct lan9645x *lan9645x = ds->priv; +struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +WRITE_ONCE (p->host_flood_req, + (uc ?LAN9645X_HOST_FLOOD_UC :0 ) | + (mc ?LAN9645X_HOST_FLOOD_MC :0 )); +queue_work (lan9645x->owq, &p->host_flood_work); +} + +static int lan9645x_port_bridge_join (struct dsa_switch *ds,int port, +struct dsa_bridge bridge, +bool *tx_fwd_offload, +struct netlink_ext_ack *extack) +{ +struct lan9645x *lan9645x = ds->priv; +struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); +if (lan9645x->bridge && lan9645x->bridge != bridge.dev) { +mutex_unlock (&lan9645x->fwd_domain_lock); +NL_SET_ERR_MSG_MOD (extack,"Only one bridge supported" ); +return -EBUSY ; + } + +/* First bridged port sets bridge dev */ +if (!lan9645x->bridge_mask) + lan9645x->bridge = bridge.dev; + + lan9645x->bridge_mask |=BIT (p->chip_port); +__lan9645x_port_set_host_flood (lan9645x); + +mutex_unlock (&lan9645x->fwd_domain_lock); + +/* Later: stp_state_set updates forwarding */ + +return 0 ; +} + +static void lan9645x_port_bridge_stp_state_set (struct dsa_switch *ds,int port, +u8 state) +{ +struct lan9645x *lan9645x; +struct lan9645x_port *p; +bool learn_ena; + + lan9645x = ds->priv; + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + p->stp_state = state; + +if (state ==BR_STATE_FORWARDING ) + lan9645x->bridge_fwd_mask |=BIT (p->chip_port); +else + lan9645x->bridge_fwd_mask &= ~BIT (p->chip_port); + + learn_ena = (state ==BR_STATE_LEARNING || + state ==BR_STATE_FORWARDING ) && p->learn_ena; + +lan_rmw (ANA_PORT_CFG_LEARN_ENA_SET (learn_ena), +ANA_PORT_CFG_LEARN_ENA , lan9645x, +ANA_PORT_CFG (p->chip_port)); + +lan9645x_update_fwd_mask (lan9645x); +mutex_unlock (&lan9645x->fwd_domain_lock); +} + +static void lan9645x_port_bridge_leave (struct dsa_switch *ds,int port, +struct dsa_bridge bridge) +{ +struct lan9645x *lan9645x = ds->priv; +struct lan9645x_port *p; + + p =lan9645x_to_port (lan9645x, port); + +mutex_lock (&lan9645x->fwd_domain_lock); + + lan9645x->bridge_mask &= ~BIT (p->chip_port); + +/* Last port leaving clears bridge dev */ +if (!lan9645x->bridge_mask) + lan9645x->bridge =NULL ; + +__lan9645x_port_set_host_flood (lan9645x); +lan9645x_update_fwd_mask (lan9645x); + +mutex_unlock (&lan9645x->fwd_domain_lock); +} +static const struct dsa_switch_ops lan9645x_switch_ops = { .get_tag_protocol = lan9645x_get_tag_protocol,
@@ -295,6 +594,15 @@ static const struct dsa_switch_ops lan9645x_switch_ops = {/* MTU */ .port_change_mtu = lan9645x_change_mtu, .port_max_mtu = lan9645x_get_max_mtu, + +/* Bridge integration */ + .set_ageing_time = lan9645x_set_ageing_time, + .port_pre_bridge_flags = lan9645x_port_pre_bridge_flags, + .port_bridge_flags = lan9645x_port_bridge_flags, + .port_bridge_join = lan9645x_port_bridge_join, + .port_bridge_leave = lan9645x_port_bridge_leave, + .port_stp_state_set = lan9645x_port_bridge_stp_state_set, + .port_set_host_flood = lan9645x_port_set_host_flood, };static int lan9645x_request_target_regmaps (struct lan9645x *lan9645x)
@@ -376,6 +684,7 @@ static int lan9645x_probe(struct platform_device *pdev) p->lan9645x = lan9645x; p->chip_port = port; +INIT_WORK (&p->host_flood_work, lan9645x_host_flood_work_fn); lan9645x->ports[port] = p; }
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +27 -0
@@ -117,6 +117,9 @@ (_cond), SLOW_RD_SLEEP_US, \ SLOW_RD_SLEEPTIMEOUT_US) +#define LAN9645X_HOST_FLOOD_UC BIT(0) +#define LAN9645X_HOST_FLOOD_MC BIT(1) +/* NPI port prefix config encoding * * 0: No CPU extraction header (normal frames)
@@ -158,6 +161,11 @@ struct lan9645x {struct dsa_switch *ds;struct regmap *rmap[NUM_TARGETS ]; +u16 host_flood_uc_mask; +u16 host_flood_mc_mask; + +struct workqueue_struct *owq; +int shared_queue_sz;/* NPI chip_port */
@@ -166,6 +174,12 @@ struct lan9645x {u8 num_phys_ports;struct lan9645x_port **ports; +/* Forwarding Database */ +struct net_device *bridge;/* Only support single bridge */ +u16 bridge_mask;/* Mask for bridged ports */ +u16 bridge_fwd_mask;/* Mask for forwarding bridged ports */ +struct mutex fwd_domain_lock;/* lock forwarding configuration */ +int num_port_dis; };
@@ -173,9 +187,17 @@ struct lan9645x_port {struct lan9645x *lan9645x;u8 chip_port; +u8 stp_state; +bool learn_ena;bool rx_internal_delay;bool tx_internal_delay; + +struct work_struct host_flood_work; +/* Packed host flood request deposited by port_set_host_flood (atomic +* context) and consumed by host_flood_work_fn. +*/ +u8 host_flood_req; };extern const struct phylink_mac_ops lan9645x_phylink_mac_ops;
@@ -222,6 +244,11 @@ static inline struct lan9645x_port *lan9645x_to_port(struct lan9645x *lan9645x,return lan9645x->ports[port]; } +static inline bool lan9645x_port_is_bridged (struct lan9645x_port *p) +{ +return p && (p->lan9645x->bridge_mask &BIT (p->chip_port)); +} +static inline struct regmap *lan_tgt2rmap (struct lan9645x *lan9645x,enum lan9645x_target t,int tinst) {
Signature · 1 line
2.52.0
PATCH v10 6/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).
---
Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module, and reword the portmask comment.
Changes in v5:
- switch -EBUSY to -EINVAL for vlan add/del in the reserved range.
- remove reserved HSR vlan
- update commit message
Changes in v4:
- fix clear HOST_PVID vlan membership when a port joins a bridge
- explicit default value write to tag type register for untagged frames
- use lan_rmw for ANA_DROP_CFG
- add comment for error path in lan9645x_vlan_hw_wr
- use dsa_switch_for_each_user_port to iterate ports
Changes in v3:
- use SET register macros in vlan_hw_wr
- add vlan id bounds check to vlan_del
- return vlan_hw_wr timeout err on init
- move cpu vlan action after bounds check
Changes in v2:
- redesign based on selftests which rely on changing vlan_default_pvid. Our HW limitations were too forward. Following Vladimirs changes to ocelot VLAN implementation, we now dynamically change egress tag configuration, allowing more states.
- selftests are passing, except an expected failure w.r.t ctag/stag conformance, which is a hw limitation.
--- drivers/net/dsa/microchip/lan9645x/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 50 +++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 29 ++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 3 + drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c | 403 +++++++++++++++++++++ 5 files changed, 486 insertions(+)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -6,3 +6,4 @@ mchp-lan9645x-objs := \ lan9645x_npi.o \ lan9645x_phylink.o \ lan9645x_port.o \ + lan9645x_vlan.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +50 -0
79 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +29 -0
@@ -7,6 +7,7 @@#include <linux/dsa/lan9645x.h> #include <linux/if_bridge.h> +#include <linux/if_vlan.h> #include <linux/regmap.h> #include <net/dsa.h>
@@ -156,6 +157,17 @@ enum lan9645x_vlan_port_tag { LAN9645X_TAG_ALL = 3, }; +struct lan9645x_vlan { +u32 portmask:10 ,/* ports 0-8 + CPU port module */ + untagged:9 ,/* ports 0-8 */ + src_chk:1 , + mir:1 , + lrn_dis:1 , + prv_vlan:1 , + fld_dis:1 , + s_fwd_ena:1 ; +}; +struct lan9645x {struct device *dev;struct dsa_switch *ds;
@@ -180,6 +192,9 @@ struct lan9645x {u16 bridge_fwd_mask;/* Mask for forwarding bridged ports */ struct mutex fwd_domain_lock;/* lock forwarding configuration */ +/* VLAN entries */ +struct lan9645x_vlan vlans[VLAN_N_VID ]; +int num_port_dis; };
@@ -190,6 +205,9 @@ struct lan9645x_port {u8 stp_state;bool learn_ena; +bool vlan_aware; +u16 pvid; +bool rx_internal_delay;bool tx_internal_delay;
@@ -356,4 +374,15 @@ void lan9645x_phylink_get_caps(struct lan9645x *lan9645x, int port, struct phylink_config *c);void lan9645x_phylink_port_down (struct lan9645x *lan9645x,int port); +/* VLAN lan9645x_vlan.c */ +int lan9645x_vlan_init (struct lan9645x *lan9645x); +u16 lan9645x_vlan_unaware_pvid (bool is_bridged); +void lan9645x_vlan_port_apply (struct lan9645x_port *p); +int lan9645x_vlan_port_add_vlan (struct lan9645x_port *p,u16 vid,bool pvid, +bool untagged, +struct netlink_ext_ack *extack); +int lan9645x_vlan_port_del_vlan (struct lan9645x_port *p,u16 vid); +void lan9645x_vlan_set_hostmode (struct lan9645x_port *p); +void lan9645x_vlan_clear_hostmode (struct lan9645x_port *p); +#endif /* __LAN9645X_MAIN_H__ */
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +3 -0
@@ -210,5 +210,8 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)ANA_PORT_CFG_PORTID_VAL , lan9645x, ANA_PORT_CFG(p->chip_port)); +if (p->chip_port != lan9645x->npi) +lan9645x_vlan_set_hostmode (p); +return 0 ; }
drivers/net/dsa/microchip/lan9645x/lan9645x_vlan.c new file +403 -0
403 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v10 7/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 bucket has 4 slots. A mac table entry typically points to a PGID index, the first 9 of which represent a front port.
Mac table entries for L2 multicast will use a PGID containing a group port mask. For IP multicast entries in the mac table a trick us used, where the group port mask is packed into the MAC data, exploiting the fact that the top bits are fixed, and that the number of switch ports is small enough to fit in the redundant bits.
Therefore, we can avoid using sparse PGID resources for IP multicast entries in the mac table.
---
Changes in v8:
- Pass lan9645x into lan9645x_mac_ports_use_cpu() and reference the CPU port module as lan9645x->num_phys_ports instead of CPU_PORT.
Changes in v5:
- lan9645x_mac_init returns error on table init timeout
- add comment about skipping LOCKED entries on fdb dump
Changes in v4:
- remove mac_entries list and just do direct IO to mac table from fdb_add/fdb_del
Changes in v3:
- avoid mac add/del dealloc when mac table writes fail
- add mact_lock to change ageing time
- dealloc all mac_entries on deinit
- dsa_dump returns mac table timeout error
Changes in v2:
- use a single lock for hw and sw
- remove unused row struct field and define
- remove list element INIT_LIST_HEAD
- consistent use of err vs ret
- remove mutex_lock in init
- use empty initializer { 0 } -> {}
- do not move fwd_domain_lock init to this unit
- add newline to dev_* log statements
--- drivers/net/dsa/microchip/lan9645x/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c | 293 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 87 +++++- drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 27 ++ 4 files changed, 407 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -2,6 +2,7 @@ obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o mchp-lan9645x-objs := \ + lan9645x_mac.o \ lan9645x_main.o \ lan9645x_npi.o \ lan9645x_phylink.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c new file +293 -0
293 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +86 -1
135 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +27 -0
@@ -168,6 +168,19 @@ struct lan9645x_vlan { s_fwd_ena:1 ; }; +/* MAC table entry types. +* ENTRYTYPE_NORMAL is subject to aging. +* ENTRYTYPE_LOCKED is not subject to aging. +* ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast. +* ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast. +*/ +enum macaccess_entry_type { +ENTRYTYPE_NORMAL =0 , +ENTRYTYPE_LOCKED , +ENTRYTYPE_MACV4 , +ENTRYTYPE_MACV6 , +}; +struct lan9645x {struct device *dev;struct dsa_switch *ds;
@@ -191,6 +204,7 @@ struct lan9645x {u16 bridge_mask;/* Mask for bridged ports */ u16 bridge_fwd_mask;/* Mask for forwarding bridged ports */ struct mutex fwd_domain_lock;/* lock forwarding configuration */ +struct mutex mact_lock;/* serialize mac table register access */ /* VLAN entries */ struct lan9645x_vlan vlans[VLAN_N_VID ];
@@ -385,4 +399,17 @@ int lan9645x_vlan_port_del_vlan(struct lan9645x_port *p, u16 vid);void lan9645x_vlan_set_hostmode (struct lan9645x_port *p);void lan9645x_vlan_clear_hostmode (struct lan9645x_port *p); +/* MAC table: lan9645x_mac.c */ +int lan9645x_mact_flush (struct lan9645x *lan9645x,int port); +int lan9645x_mact_learn (struct lan9645x *lan9645x,int port, +const unsigned char *addr,u16 vid, +enum macaccess_entry_type type); +int lan9645x_mact_forget (struct lan9645x *lan9645x, +const unsigned char mac[ETH_ALEN ],unsigned int vid, +enum macaccess_entry_type type); +int lan9645x_mac_init (struct lan9645x *lan9645x); +void lan9645x_mac_deinit (struct lan9645x *lan9645x); +int lan9645x_mact_dsa_dump (struct lan9645x *lan9645x,int port, +dsa_fdb_dump_cb_t *cb,void *data); +#endif /* __LAN9645X_MAIN_H__ */
Signature · 1 line
2.52.0
PATCH v10 8/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 to a PGID index, which encodes the port group mask.
---
Changes in v8:
- Use lan9645x->num_phys_ports instead of CPU_PORT for the CPU port module, and reword the related comments.
Changes in v7:
- refactor IGMP/MLD/IPMC_CTRL to use new LAN9645X_CPUQ_DEF, LAN9645X_CPUQ_TRAP and LAN9645X_CPUQ_COPY queues
- add __aligned(2) to mac variable in lan9645x_mdb_update_dest
Changes in v5:
- skip igmp/mld redir for npi port
Changes in v4:
- clean up fresh mdb when hw mac table write fails.
- avoid void return in lan9645x_offload_fwd_mark
Changes in v3:
- avoid mdb add/del dealloc when mac table writes fail
- dealloc mdb entries on deinit
Changes in v2:
- New file: selftests required implementation of the mdb callbacks.
--- drivers/net/dsa/microchip/lan9645x/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c | 14 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 62 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 21 ++ drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c | 398 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 11 +- 6 files changed, 506 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/lan9645x/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o mchp-lan9645x-objs := \ lan9645x_mac.o \ lan9645x_main.o \ + lan9645x_mdb.o \ lan9645x_npi.o \ lan9645x_phylink.o \ lan9645x_port.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_mac.c +14 -0
@@ -143,6 +143,20 @@ int lan9645x_mact_learn(struct lan9645x *lan9645x, int port,return err; } +int lan9645x_mact_learn_cpu_copy (struct lan9645x *lan9645x,int port, +const unsigned char *addr,u16 vid, +enum macaccess_entry_type type,bool cpu_copy) +{ +int err; + +mutex_lock (&lan9645x->mact_lock); + err =__lan9645x_mact_learn_cpu_copy (lan9645x, port, addr, vid, type, + cpu_copy); +mutex_unlock (&lan9645x->mact_lock); + +return err; +} +int lan9645x_mact_flush (struct lan9645x *lan9645x,int port) {int err;
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c +62 -0
92 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +21 -0
@@ -209,6 +209,14 @@ struct lan9645x {/* VLAN entries */ struct lan9645x_vlan vlans[VLAN_N_VID ]; +/* Multicast Forwarding Database */ +struct list_head mdb_entries; +struct list_head pgid_entries; +/* lock for mdb_entries and pgid_entries. Must be taken before mact_lock +* if both are taken. +*/ +struct mutex mdb_lock; +int num_port_dis; };
@@ -411,5 +419,18 @@ int lan9645x_mac_init(struct lan9645x *lan9645x);void lan9645x_mac_deinit (struct lan9645x *lan9645x);int lan9645x_mact_dsa_dump (struct lan9645x *lan9645x,int port,dsa_fdb_dump_cb_t *cb,void *data); +int lan9645x_mact_learn_cpu_copy (struct lan9645x *lan9645x,int port, +const unsigned char *addr,u16 vid, +enum macaccess_entry_type type,bool cpu_copy); + +/* Multicast Database lan9645x_mdb.c */ +int lan9645x_mdb_port_add (struct lan9645x *lan9645x,int port, +const struct switchdev_obj_port_mdb *mdb, +struct net_device *bridge); +int lan9645x_mdb_port_del (struct lan9645x *lan9645x,int port, +const struct switchdev_obj_port_mdb *mdb, +struct net_device *bridge); +void lan9645x_mdb_init (struct lan9645x *lan9645x); +void lan9645x_mdb_deinit (struct lan9645x *lan9645x);#endif /* __LAN9645X_MAIN_H__ */
drivers/net/dsa/microchip/lan9645x/lan9645x_mdb.c new file +398 -0
398 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c +10 -1
@@ -210,8 +210,17 @@ int lan9645x_port_setup(struct dsa_switch *ds, int port)ANA_PORT_CFG_PORTID_VAL , lan9645x, ANA_PORT_CFG(p->chip_port)); -if (p->chip_port != lan9645x->npi) +if (p->chip_port != lan9645x->npi) {lan9645x_vlan_set_hostmode (p); +lan_rmw (ANA_CPU_FWD_CFG_IGMP_REDIR_ENA_SET (true) | +ANA_CPU_FWD_CFG_MLD_REDIR_ENA_SET (true) | +ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA_SET (true), +ANA_CPU_FWD_CFG_IGMP_REDIR_ENA | +ANA_CPU_FWD_CFG_MLD_REDIR_ENA | +ANA_CPU_FWD_CFG_IPMC_CTRL_COPY_ENA , + lan9645x,ANA_CPU_FWD_CFG (p->chip_port)); + } +return 0 ; }
Signature · 1 line
2.52.0
PATCH v10 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.
---
Changes in v5:
- make lan9645x_stats_init void
- add SCNT_TX_BUFDROP to tx_dropped
- change rmon range {0,64} -> {64, 64}. Runt frames counted elsewhere.
- remove rx_crc, rx_symbol_err from rx_packets, as they are already counted in SZ_* buckets.
- add defensive cancel_delayed_work_sync in stats_free
Changes in v4:
- remove rx_uc and tx_uc from ethtool stats list, as they are derivable from the eth-mac group
- split stats_init into stats_alloc and stats_init, use alloc in probe and init in dsa_setup
Changes in v3:
- No changes
Changes in v2:
- introduce spinlock sw_lock protecting software counters and region buffer.
- ran Ioana's selftest for standard counters drivers/net/hw/ethtool_std_stats.sh
along with
selftests/drivers/net/hw/ethtool_rmon.sh
they pass except for software injected pause frames.
- remove strings/counters covered by standard counters from get_strings/get_ethtool_stats.
- fix proper use of 'src' in standard counters
- remove static region table, and use stats_prepare_regions for dynamic region calculation inspired by ocelot.
- fix queue leak in error path.
--- drivers/net/dsa/microchip/lan9645x/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 87 +- drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 3 + .../net/dsa/microchip/lan9645x/lan9645x_stats.c | 929 +++++++++++++++++++++ .../net/dsa/microchip/lan9645x/lan9645x_stats.h | 279 +++++++ 5 files changed, 1298 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 +86 -1
131 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h +3 -0
@@ -217,6 +217,9 @@ struct lan9645x {*/ struct mutex mdb_lock; +/* Statistics */ +struct lan9645x_stats *stats; +int num_port_dis; };
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +929 -0
929 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.h new file +279 -0
279 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Process-context functions acquire `sw_lock` using `spin_lock()` instead of `spin_lock_bh()`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Process-context functions acquire sw_lock using spin_lock() instead of spin_lock_bh(), risking a deadlock with softirq contexts. --
--- Patch [9]: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics --- commit e9223f3e66d6e1a49c762c181b787e9d1d5b11fa
Author: Jens Emil Schulz Østergaard <[email protected]>
net: dsa: lan9645x: add port statistics
This commit adds support for port statistics counters. It introduces a 64-bit software cache to handle 32-bit hardware register overflows and exposes standard as well as private ethtool statistics.
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 297
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+static void __lan9645x_stats_view_idx_update (struct lan9645x *lan9645x, +enum lan9645x_view_stat_type vtype, +int idx) +{ +struct lan9645x_stats *s = lan9645x->stats; + +lockdep_assert_held (&s->hw_lock); + +if (!__lan9645x_stats_view_idx_hw_read (lan9645x, vtype, idx)) { +spin_lock (&s->sw_lock);
[Severity: High]
Can a softirq preempt this process context and cause a deadlock?
Since this is called from a delayed workqueue context, it runs with softirqs enabled. If a network receive softirq fires on the same CPU while this lock is held, it will call lan9645x_stats_get_stats64(), which attempts to acquire this same spin_lock, leading to a permanent hang.
Should this and other process-context lock acquisitions use spin_lock_bh() to prevent softirq preemption?
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 378
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+void lan9645x_stats_get_ethtool_stats (struct lan9645x *lan9645x,int port, +u64 *data) +{ +struct lan9645x_stats *stats = lan9645x->stats; +u64 *c; +int i; + + c =lan9645x_stats_view_idx_update (lan9645x,LAN9645X_STAT_PORTS , port); + +spin_lock (&stats->sw_lock);
[Severity: High]
Is this another location where the lock should be taken with spin_lock_bh()?
Ethtool callbacks run in process context and are also vulnerable to the same softirq preemption race as the workqueue.
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 610
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +12
-0+/* Called in atomic context */ +void lan9645x_stats_get_stats64 (struct lan9645x *lan9645x,int port, +struct rtnl_link_stats64 *stats) +{ +struct lan9645x_stats *s = lan9645x->stats; +u64 *c; + + c =STAT_COUNTERS (lan9645x,LAN9645X_STAT_PORTS , port); + +spin_lock (&s->sw_lock); + + stats->rx_bytes = c[SCNT_RX_OCT ] + c[SCNT_RX_PMAC_OCT ];
[Severity: High]
This is the softirq-callable path mentioned above that completes the deadlock scenario if it preempts the workqueue or ethtool operations holding sw_lock.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=9
Re: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics
Quoted 67 lines · On Tue, 2026-07-14 at 14:43 +0000, [email protected] wrote:
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Process-context functions acquiresw_lockusingspin_lock()instead ofspin_lock_bh(), risking a deadlock with softirq contexts. ----- Patch [9]: [PATCH net-next v10 9/9] net: dsa: lan9645x: add port statistics --- commit
e9223f3e66d6e1a49c762c181b787e9d1d5b11fa
Author: Jens Emil Schulz Østergaard <[email protected]>net: dsa: lan9645x: add port statistics
This commit adds support for port statistics counters. It introduces a 64-bit software cache to handle 32-bit hardware register overflows and exposes standard as well as private ethtool statistics.
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +0
-0[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 297
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+static void __lan9645x_stats_view_idx_update (struct lan9645x *lan9645x, +enum lan9645x_view_stat_type vtype, +int idx) +{ +struct lan9645x_stats *s = lan9645x->stats; + +lockdep_assert_held (&s->hw_lock); + +if (!__lan9645x_stats_view_idx_hw_read (lan9645x, vtype, idx)) { +spin_lock (&s->sw_lock);[Severity: High]
Can a softirq preempt this process context and cause a deadlock?Since this is called from a delayed workqueue context, it runs with softirqs enabled. If a network receive softirq fires on the same CPU while this lock is held, it will call
lan9645x_stats_get_stats64(), which attempts to acquire this samespin_lock, leading to a permanent hang.Should this and other process-context lock acquisitions use
spin_lock_bh()to prevent softirq preemption?[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 378
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +10
-0+void lan9645x_stats_get_ethtool_stats (struct lan9645x *lan9645x,int port, +u64 *data) +{ +struct lan9645x_stats *stats = lan9645x->stats; +u64 *c; +int i; + + c =lan9645x_stats_view_idx_update (lan9645x,LAN9645X_STAT_PORTS , port); + +spin_lock (&stats->sw_lock);[Severity: High]
Is this another location where the lock should be taken withspin_lock_bh()?Ethtool callbacks run in process context and are also vulnerable to the same softirq preemption race as the workqueue.
[ ... ]
Quoted 17 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c line 610
Quoted 12 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c new file +12
-0+/* Called in atomic context */ +void lan9645x_stats_get_stats64 (struct lan9645x *lan9645x,int port, +struct rtnl_link_stats64 *stats) +{ +struct lan9645x_stats *s = lan9645x->stats; +u64 *c; + + c =STAT_COUNTERS (lan9645x,LAN9645X_STAT_PORTS , port); + +spin_lock (&s->sw_lock); + + stats->rx_bytes = c[SCNT_RX_OCT ] + c[SCNT_RX_PMAC_OCT ];[Severity: High]
This is the softirq-callable path mentioned above that completes the deadlock scenario if it preempts the workqueue or ethtool operations holdingsw_lock.
I think this is a false positive, since .ndo_get_stats64 is not called from softirq context, so the deadlock can not occur. Ocelot and ksz also use a straight spin_lock for the same purpose here.
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com?part=9