net: dsa: add DSA support for the LAN9645x switch chip family
Subsystems (5)
v17 cover net: dsa: add DSA support for the LAN9645x switch chip family
This series provides the Microchip LAN9645X Switch driver.
The LAN9645x is a family of chips with ethernet switch functionality and multiple peripheral functions. The switch delivers up to 9 ethernet ports and 12 Gbps switching bandwidth.
The switch chip has 5 integrated copper PHYs, support for 2x RGMII interfaces, 2x SGMII and one QSGMII interface.
The switch chip is from the same design architecture family as ocelot and lan966x, and the driver reflects this similarity. However, LAN9645x does not have an internal CPU in any package, and must be driven externally. For register IO it supports interfaces such as SPI, I2C and MDIO.
The chip supports a variety of network features such as
* Mactable for MDB/FDB functionality
* Bridge forwarding offload
* VLAN-aware bridging
* IGMP/MLD snooping
* Link aggregation
* PTP timestamping
* FRER (802.1CB)
* Media Redundancy Protocol
* Parallel Redundancy and High-Availability Seamless Redundancy (HSR/PRP) in DANH/DANP mode
* Per stream filtering and policing
* Shapers such as Credit Based Shaping and Time Aware Shaing
* Frame preemption
* A TCAM (VCAP) for line-rate frame processing
The LAN9645x family consists of the following SKUs:
LAN96455F
LAN96457F
LAN96459F
LAN96455S
LAN96457S
LAN96459S
The difference between the SKUs is the number of supported ports (5, 7 or 9) and features supported. The F subfamily supports HSR/PRP and TSN, while the S subfamily does not.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c, which also resets the chip before it instantiates its children.
This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.c
which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.
The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.
Development is done using the LAN966x as a host CPU, running the lan966x swichdev driver, using the EVB-LAN9668 EDS2 board.
The datasheet is available here:
https://ww1.microchip.com/downloads/aemDocuments/documents/UNG/ProductDocuments/DataSheets/LAN9645xF-Data-Sheet-DS00006065.pdf
This series adds support for standalone ports. Bridges and VLAN uppers on the ports are handled in software.
More support will be added at a later stage. Here is a tentative plan of future patches for this DSA driver:
* Add bridge forwarding and FDB offloading.
* Add multicast forwarding and MDB offloading.
* Add VLAN-aware bridge offloading.
* Add port statistics.
* Add LAG support.
* Add TC matchall mirror support.
* Add TC matchall police support.
* Add DCB/qos support.
* Add simple TC support: mqprio, cbs, tbf, ebf.
* Add TC flower filter support.
* Add HSR/PRP offloading support.
* Add PTP support.
* Add TC taprio support.
For completeness I include tentative plan of planned patches for LAN9645x peripherals:
* Extend pinctrl-ocelot for LAN9645x:
https://lore.kernel.org/linux-gpio/20260119-pinctrl_ocelot_extend_support_for_lan9645x-v1-0-1228155ed0ee@microchip.com/
* Add driver for internal PHY:
https://lore.kernel.org/netdev/20260123-phy_micrel_add_support_for_lan9645x_internal_phy-v1-1-8484b1a5a7fd@microchip.com/
* MFD driver for managing register IO protocol and child device initialization.
* Extend pinctrl-microchip-sgpio for LAN9645x support.
* Extend i2c_designware for LAN9645x support.
* Add driver for outbound interrupt controller.
* Add serdes driver for lan9645x.
---
Changes in v17:
- Individual patches mention specific v17 changes
- tag: set IFH.IPV to the QoS class on injection, so frames from the CPU
are queued by their priority instead of in queue 0.
- basic: reject more than one CPU port on the switch.
- basic: check read error in probe and setup.
- Link to v16: https://lore.kernel.org/r/20261103-dsa_lan9645x_switch_driver_base-v16-0-781c96d735cf@microchip.com
Changes in v16:
- Individual patches mention specific v16 changes
- Reduce the series to standalone ports. The vlan, mac table, mdb,
bridge and port statistics patches are dropped, and will be sent in a
follow-up series.
- tag: restore a popped VLAN tag whenever the IFH reports one, without
depending on dp->vlan_filtering, which DSA updates only after the
hardware VLAN configuration has changed.
- basic: drop the ds flags and defines only used by the dropped patches.
- Link to v15: https://lore.kernel.org/r/20261015-dsa_lan9645x_switch_driver_base-v15-0-562f316f78b9@microchip.com
Changes in v15:
- Individual patches mention specific v15 changes
- basic: on link down, assert MAC_TX_RST and MAC_RX_RST instead of
flushing the queues and asserting PORT_RST, which can hang the port
when the MAC cannot transmit the frames still queued.
- vlan: refuse VLAN filtering on bridges with a vlan_protocol other than
802.1Q, and only apply VLAN awareness while a port is bridged, so a
join after a failed one is configured correctly.
- Link to v14: https://lore.kernel.org/r/20261008-dsa_lan9645x_switch_driver_base-v14-0-3d2a72661213@microchip.com
Changes in v14:
- Individual patches mention specific v14 changes
- tag: classify untagged and priority tagged frames to VID 0 on xmit,
pull the VLAN header before reading it, restore the VLAN tag on rcv
whenever one was popped, and add a .flow_dissect callback that
accounts for popped VLAN tags.
- bindings: use the dt-bindings: net: dsa: subject prefix, and describe
all switch register targets and the analyzer and PTP interrupts.
- vlan: use TAG_NO_UNAWARE on ports with only tagged VLANs.
- mac table: keep a CPU port host entry while another database uses the
same MAC table key.
- mdb: keep the PGID reference when a mac table write fails while
widening a group, drop it on a failed narrow that keeps the same PGID,
and keep a CPU port host entry while another database uses the same
mac table key.
- bridge: only enable learning on bridged ports, start a joining port
disabled so it does not learn before its STP state is applied, and
honour host flood requests from bridged ports.
- stats: return 0 from get_sset_count() for other string sets, leave
RMON fragments unset, and describe the pMAC counters correctly.
- Link to v13: https://lore.kernel.org/r/20260929-dsa_lan9645x_switch_driver_base-v13-0-827c2d3617f2@microchip.com
Changes in v13:
- Individual patches mention specific v13 changes
- bindings: Drop the commit message paragraph citing
Documentation/networking/phy.rst.
- basic: only redirect the CPU extraction queues to the NPI port while
its link is up, and flush the CPU port module on NPI link up.
- Rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 37
- Link to v12: https://lore.kernel.org/r/20260908-dsa_lan9645x_switch_driver_base-v12-0-2d6aa59350cd@microchip.com
Changes in v12:
- reorder the series so bridge support lands after vlan, mac table and
mdb support. port_fast_age() now exists before the STP state handling
that needs it, and host address filtering is in place before bridging.
- include the CPU port module in the flood masks from the start, and
remove it again in the bridge patch where port_set_host_flood() takes
over on demand host flooding. Previously the host could not receive
unicast until the mac table patch.
- vlan: serialize the VLAN table with fwd_domain_lock, and describe the
untagged VLAN, TPID and C-component conformance limitations.
- tag driver: move an out-of-band VLAN tag into the payload before
reading it, instead of relying on the conduit never advertising a VLAN
TX offload.
- tag driver: restore the classified VLAN as a C-tag rather than following
the IFH tag type, so a terminated frame lands on the VID the hardware
forwarded it on.
- basic: drop the tail drop watermark setup, which programmed a
condition that could not trigger.
- mdb: handle PGID exhaustion on both the add and delete paths, rather
than leaving a departed port in the group.
- mdb: classify IPv4 multicast on the 01:00:5E prefix alone. Hardware does
not apply the 23-bit rule, so some groups were programmed as entries it
never matches.
- stats: give the hardware counters and the software shadow a common
baseline, fix some rtnl_link_stats64 fields, and stop reporting the
three eth-mac fields the hardware cannot measure.
- stats: stop the counter poller in .shutdown, which kept reading
registers after the parent had been shut down.
- Link to v11: https://lore.kernel.org/r/20260805-dsa_lan9645x_switch_driver_base-v11-0-007ebc983a0a@microchip.com
Changes in v11:
- Update comment about vlan tag hwaccel use in tag driver.
- Bump DSA_TAG_PROTO value in include/net/dsa.h.
- stats: add comment about calling contexts of sw_lock in
lan9645x_stats_get_stats64
- Link to v10: https://lore.kernel.org/r/20260713-dsa_lan9645x_switch_driver_base-v10-0-a4886a08fb15@microchip.com
Changes in v10:
- Individual patches mention specific v10 changes
- Update tag driver after skb ownership model change in DSA taggers.
- Link to v9: https://lore.kernel.org/r/20260708-dsa_lan9645x_switch_driver_base-v9-0-0d1512a326d7@microchip.com
Changes in v9:
- Individual patches mention specific v9 changes
- Drop RGMII muxing to port 4.
- Link to v8: https://lore.kernel.org/r/20260702-dsa_lan9645x_switch_driver_base-v8-0-90228d8bba58@microchip.com
Changes in v8:
- Individual patches mention specific v8 changes
- Do not use the name CPU_PORT for the chips internal CPU port module,
as it collides with the DSA CPU port (the NPI front port). Drop the
CPU_PORT macro and reference the module as lan9645x->num_phys_ports,
mirroring ocelot/felix.
- Reword the port map and related comments to distinguish the chip CPU
port modules (indices 9-10) from the DSA CPU port.
- Add a port_mux_lock mutex to serialize port mux arbitration in
the phylink mac_prepare path.
- Link to v7: https://lore.kernel.org/r/20260603-dsa_lan9645x_switch_driver_base-v7-0-b2f90e676707@microchip.com
Changes in v7:
- Individual patches mention specific v7 changes
- Do not mark the BPDU range 01:80:C2:00:00:0X as offloaded in the tag driver.
- Refactor cpu queue based frame classification to use categories default, trap
and copy, which mirrors usage instead of being based on frame types.
- Add registers ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.
- Use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames.
- Refactor IGMP/MLD/IPMC_CTRL to use new LAN9645X_CPUQ_DEF,
LAN9645X_CPUQ_TRAP and LAN9645X_CPUQ_COPY queues.
- Add __aligned(2) to mac variable in lan9645x_mdb_update_dest.
- Link to v6: https://lore.kernel.org/r/20260527-dsa_lan9645x_switch_driver_base-v6-0-4d409ae64f3c@microchip.com
Changes in v6:
- Individual patches mention specific v6 changes
- Rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34
- Link to v5: https://lore.kernel.org/r/20260518-dsa_lan9645x_switch_driver_base-v5-0-968fbf34ffa3@microchip.com
Changes in v5:
- Individual patches mention specific v5 changes
- Undo offset fix in postpull_rcsum. The original logic was correct for
CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask
- remove unused fields dd_dis and tsn_dis, and add SKU supported port validation
during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully
dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4
and 7.
- rx/tx-internal-delay-ps checked against supported 2ns value
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit
- use ds->ageing_time_max
- use packed p->host_flood_req for atomic r/w
- fix typo in set_ageing_time comment
- include lan9645x->bridge deref under lock in brige_join
- switch -EBUSY to -EINVAL for vlan add/del in the reserved range.
- remove reserved HSR vlan
- lan9645x_mac_init returns error on table init timeout
- add comment about skipping LOCKED entries on fdb dump
- skip igmp/mld redir for npi port
- make lan9645x_stats_init void
- add SCNT_TX_BUFDROP to tx_dropped
- change rmon range {0,64} -> {64, 64}. Runt frames counted elsewhere.
- remove rx_crc, rx_symbol_err from rx_packets, as they are already
counted in SZ_* buckets.
- add defensive cancel_delayed_work_sync in stats_free
- Link to v4: https://lore.kernel.org/r/20260430-dsa_lan9645x_switch_driver_base-v4-0-f1b6005fa8b7@microchip.com
Changes in v4:
- v3 was deferred, but I made some changes based on the Sashiko review
- Individual patches mention specific v4 changes
- Fix offset in postpull_rcsum so prefix eth header is cleared, not
actual eth header, so tag driver works with CHECKSUM_COMPLETE host
NICs
- Fix untagged rx on vlan aware port with pvid
- Add comment to QSYS_RES_CFG configuration
- Phylink_mac_prepare: fix to make sure we can dynamically change rgmii
on port 4
- Move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- Skip WARN_ON in lan9645x_to_port
- set_host_flood changed to per port work to coalesce values and skip
atomic allocations
- Fix clear HOST_PVID vlan membership when a port joins a bridge.
- Explicit default value write to tag type register for untagged frames
- Use lan_rmw for ANA_DROP_CFG
- Add comment for error path in lan9645x_vlan_hw_wr
- Remove mac_entries list and just do direct IO to mac table from
fdb_add/fdb_del.
- Clean up fresh mdb when hw mac table write fails.
- Remove rx_uc and tx_uc from ethtool stats list, as they are derivable
from the eth-mac group
- Split stats_init into stats_alloc and stats_init, use alloc in probe
and init in dsa_setup
- Link to v3: https://lore.kernel.org/r/20260410-dsa_lan9645x_switch_driver_base-v3-0-aadc8595306d@microchip.com
Changes in v3:
- Individual patches mention specific v3 changes.
- Add guard before vlan_remove_tag on xmit
- Add pskb_may_pull checks on rx
- Remove additionalProperties: true in bindings
- Remove unnecessary | from description in bindings
- Change top level $ref to dsa.yaml#/$defs/ethernet-ports
- Use ethernet-ports and ethernet-port
- Move ethernet-ports under properties instead of patternProperties
- Move unevaluatedProperties: false after $ref
- Update bindings example to use ethernet-ports and ethernet-port
- Move DEV_MAC_TAGS_CFG to port setup, instead of vlan config, so vlan
overhead is always included in port frame maxlen calculation.
- Remove code disabling ipv6 on conduit
- Use of_property_read_u32 for {rx,tx}-internal-delay-ps
- Use dsa_user_ports(ds) instead of
GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- Add comment explaining obey vlan
- Allow disabling aging with explicit zero parameters.
- Fix non-forwarding STP states in bridge fwd calculation.
- Restore host flood state on bridge leave.
- Avoid mac_entry dealloc when mac table writes fail.
- Avoid mdb_entry dealloc when mac table writes fail.
- Dealloc mac_entries on deinit.
- Dealloc mdb_entries on deinit.
- Link to v2: https://lore.kernel.org/r/20260324-dsa_lan9645x_switch_driver_base-v2-0-f7504e3b0681@microchip.com
Changes in v2:
- Individual patches have specific v2 changes.
- Ran DSA, and std counters, selftests, which prompted several changes.
The following selftests pass, except for some expected failures:
- bridge_vlan_aware.sh
- bridge_vlan_unaware.sh
- bridge_vlan_mcast.sh
- no_forwarding.sh
- bridge_mdb.sh
- bridge_mld.sh
- test_fdb_stress_test.sh
- .../drivers/net/hw/ethtool_rmon.sh
- .../drivers/net/hw/ethtool_std_stats.sh (from Ioana's series)
- Added new patch for MDB management, as this was required for selftests.
- Added port_set_host_flood to enable unknown traffic to standalone during
promisc/ALL_MULTI (selftests).
- Remove the dubugfs.
- Link to v1: https://lore.kernel.org/r/20260303-dsa_lan9645x_switch_driver_base-v1-0-bff8ca1396f5@microchip.com
---
Jens Emil Schulz Østergaard (4):
net: dsa: add tag driver for LAN9645X
dt-bindings: net: dsa: add Microchip LAN9645x switch
net: dsa: lan9645x: add autogenerated register macros
net: dsa: lan9645x: add basic dsa driver for LAN9645X
.../net/dsa/microchip,lan96455s-switch.yaml | 208 +++ MAINTAINERS | 10 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 12 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 464 +++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 306 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 116 ++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 315 ++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 166 ++ drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1932 ++++++++++++++++++++ include/linux/dsa/lan9645x.h | 54 + include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 514 ++++++ 17 files changed, 4122 insertions(+)
---
base-commit: 368fbf5d82da9ebce309449c74fc0b128f7d0219
change-id: 20260210-dsa_lan9645x_switch_driver_base-312bbfc37edb
Best regards,
Signature · 1 line
Jens Emil Schulz Østergaard <[email protected]>
PATCH v17 1/4 net: dsa: add tag driver for LAN9645X
Add tag driver for LAN9645x using a front port as CPU port. This mode is called an NPI port in the datasheet.
Use long prefix on extraction (RX) and no prefix on injection (TX). A long prefix on extraction helps get through the conduit port on host side, since it will see a broadcast MAC.
The LAN9645x chip is in the same design architecture family as ocelot and lan966x. The tagging protocol has the same structure as these chips, but the particular fields are different or have different sizes. Therefore, this tag driver is similar to tag_ocelot.c, but the differences in fields makes it hard to reuse.
LAN9645x supports 3 different tag formats for extraction/injection of frames from a CPU port: long prefix, short prefix and no prefix.
The tag is prepended to the frame. The critical data for the chip is contained in an internal frame header (IFH) which is 28 bytes. The prefix formats look like this:
Long prefix (16 bytes) + IFH:
- DMAC = 0xffffffffffff on extraction. - SMAC = 0xfeffffffffff on extraction. - ETYPE = 0x8880
- payload = 0x0011
- IFH
Short prefix (4 bytes) + IFH:
- 0x8880
- 0x0011
- IFH
No prefix:
- IFH
The format can be configured asymmetrically on RX and TX.
The IFH get/set functions are declared as inline. All the field constants are compile-time known, so when these calls are inlined efficient code is generated with branches pruned and loops unrolled. During testing it was observed that without explicit inlining GCC would have trouble inlining the functions, which hurt performance.
A frame extracted from a VLAN-aware port arrives without its VLAN tag. REW_PORT_CFG.NO_REWRITE is clear on the NPI port, so the rewriter applies the classified VLAN_POP_CNT, and the classified VID reaches the CPU only through the IFH. The tagger restores it as a hwaccel tag when the IFH reports that a tag was popped. An untagged frame is classified to the port pvid without a pop and is delivered untagged, which the bridge also classifies to the pvid.
The restored tag is always a C-tag, not the TPID the IFH TAG_TYPE reports. Both TPIDs are recognized as VLAN tags unconditionally, with no per port control to treat one as untagged customer data, so an S-tag is already consumed as the VLAN tag before extraction. Restoring 802.1AD would make the bridge push the tag back into the payload and reclassify the frame to the port pvid, placing it on a different VID than the one the hardware forwarded it on. Normalizing to a C-tag keeps the terminated path consistent with the forwarded path, at the cost of not preserving the S-tag TPID towards the CPU. This assumes a bridge vlan_protocol of 802.1Q, which is the only protocol the driver offloads.
On injection the IFH carries the classified VID used by the rewriter to decide whether to add a port tag. On a VLAN-aware port, a VLAN tag with a non-zero VID is moved from the payload into the IFH. Untagged and priority tagged frames are injected with classified VID 0 and left as they are, so the rewriter adds no tag to them.
---
Changes in v17:
- Set IFH.IPV to the QoS class on injection. With IFH.BYPASS set the egress queue is taken from IPV, so every injected frame was queued in queue 0.
Changes in v16:
- Restore the popped VLAN tag whenever the IFH reports a pop, without checking dsa_port_is_vlan_filtering().
- Mention the real ethernet header in the skb_postpull_rcsum() comment.
Changes in v14:
- Classify untagged and priority tagged frames to VID 0 on xmit instead of the bridge pvid, and leave priority tags in the payload.
- Restore the VLAN tag on rcv whenever the rewriter popped one, instead of only when the VID differs from the port pvid.
- Add a .flow_dissect callback that accounts for the gap left by VLAN tags popped on extraction. The generic dissector assumes the tag length is needed_headroom.
- Pull the VLAN header with pskb_may_pull() before reading it on xmit, so a tag in paged data is handled like a linear one, and drop the frame if the pull fails.
Changes in v12:
- Move an out-of-band VLAN tag into the payload with __vlan_hwaccel_push_inside() before reading it, rather than relying on the conduit never advertising NETIF_F_HW_VLAN_CTAG_TX or NETIF_F_HW_VLAN_STAG_TX in vlan_features.
- Return the skb from lan9645x_xmit_get_vlan_info(), since __vlan_hwaccel_push_inside() may reallocate and frees the skb on failure.
- Annotate the IFH field defines with injection/extraction applicability
- Drop IFH_TIMESTAMP because it is 38 bits wide. Rely on NS/SUB_NS subfields.
- Document how HW derives the DMAC offset from pop_cnt and etype_ofs, and drop frames whose encoding only a tag push could produce.
- Drop unncessary IFH_SRCPORT on injection.
- Drop the WARN_ON_ONCE() when the source port does not resolve to a user port.
- Move the IFH field position and size defines from include/linux/dsa/lan9645x.h into net/dsa/tag_lan9645x.c.
- Rename LAN9645X_IFH_LEN to LAN9645X_IFH_LEN_BYTES, so it does not read as the position of the IFH LEN field.
- Use skb_vlan_eth_hdr() in lan9645x_xmit_get_vlan_info().
- Drop BTM_MSK() TOP_MSK() helpers for GENMASK().
- Rename set_merge_mask() to lan9645x_ifh_merge_byte().
- Name the vendor in the Kconfig prompt, spell the part LAN9645x, and move the entry to its sorted position after NET_DSA_TAG_KSZ.
- Clamp the classified QoS class to the width of IFH_QOS_CLASS. A skb->priority above 7 aliased down onto an unrelated class.
- Comment why needed_headroom covers the extraction prefix.
- Restore the classified VLAN as a C-tag rather than following the IFH TAG_TYPE, so a terminated S-tagged frame lands on the same VID the hardware forwards it on.
Changes in v11:
- Update comment about vlan tag hwaccel use in tag driver.
- Bump DSA_TAG_PROTO value in include/net/dsa.h.
Changes in v10:
- Update tag driver after skb ownership model change in DSA taggers. Explicitly freeing the skb at rcv/xmit return points.
Changes in v8:
- Drop the cpu_port local and use ds->num_ports directly as the IFH source port (the CPU port module index).
- Reword the reflection comment to refer to "the CPU".
Changes in v7:
- Introduce cpu queue based frame classification, and refactor to the categories default, trap and copy, which mirrors usage instead of being based on frame types.
Changes in v6:
- rebased on net-next, bumping DSA_TAG_PROTO_LAN9645X_VALUE to 34
Changes in v5:
- Undo offset fix in postpull_rcsum. The original logic was correct for CHECKSUM_COMPLETE host NICs
- Use __always_inline in lan9645x_ifh_{get,set}
- remove double space after = in set_merge_mask
Changes in v4:
- Fix offset in postpull_rcsum so prefix eth header is cleared, not actual eth header, so tag driver works with CHECKSUM_COMPLETE host NICs
- Fix untagged rx on vlan aware port with pvid
Changes in v3:
- guard vlan_remove_tag behind skb_headlen(skb) >= VLAN_ETH_HLEN on xmit
- add pskb_may_pull checks in rx path
Changes in v2:
- sorting in net/dsa/Kconfig
- sorting in net/dsa/Makefile
- remove default zero promisc_on_conduit
- move functions to to .c file
- add justification for inline usage to commit message
- add __skb_put_padto on xmit path
- fix hwaccel_put_tag
--- MAINTAINERS | 8 + include/linux/dsa/lan9645x.h | 54 +++++ include/net/dsa.h | 2 + net/dsa/Kconfig | 11 + net/dsa/Makefile | 1 + net/dsa/tag_lan9645x.c | 514 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 590 insertions(+)
MAINTAINERS +8 -0
@@ -18319,6 +18319,14 @@ L: [email protected] S: Maintained F: drivers/net/phy/microchip_t1.c +MICROCHIP LAN9645X ETHERNET SWITCH DRIVER +M: Jens Emil Schulz Østergaard <[email protected]> +M: [email protected] +L: [email protected] +S: Maintained +F: include/linux/dsa/lan9645x.h +F: net/dsa/tag_lan9645x.c + MICROCHIP LAN966X ETHERNET DRIVER M: Horatiu Vultur <[email protected]> M: [email protected]
include/linux/dsa/lan9645x.h new file +54 -0
54 lines not on this page · raw message
include/net/dsa.h +2 -0
@@ -62,6 +62,7 @@ struct tc_action;#define DSA_TAG_PROTO_KSZ8463_VALUE 34#define DSA_TAG_PROTO_MT7628_VALUE 35#define DSA_TAG_PROTO_KS8995_VALUE 36 +#define DSA_TAG_PROTO_LAN9645X_VALUE 37enum dsa_tag_protocol {DSA_TAG_PROTO_NONE =DSA_TAG_PROTO_NONE_VALUE ,
@@ -101,6 +102,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ8463 =DSA_TAG_PROTO_KSZ8463_VALUE ,DSA_TAG_PROTO_MT7628 =DSA_TAG_PROTO_MT7628_VALUE ,DSA_TAG_PROTO_KS8995 =DSA_TAG_PROTO_KS8995_VALUE , + DSA_TAG_PROTO_LAN9645X = DSA_TAG_PROTO_LAN9645X_VALUE, };struct dsa_switch ;
net/dsa/Kconfig +11 -0
@@ -137,6 +137,17 @@ config NET_DSA_TAG_KSZ Say Y if you want to enable support for tagging frames for the Microchip 8795/937x/9477/9893 families of switches. +config NET_DSA_TAG_LAN9645X + tristate "Tag driver for Microchip LAN9645x switches" + help + Say Y or M if you want to enable NPI tagging for the Microchip + LAN9645x switches. In this mode, the frames over the Ethernet CPU + port are prepended with a hardware-defined injection/extraction frame + header. On injection a 28 byte internal frame header (IFH) is used. + On extraction a 16 byte prefix is prepended before the internal frame + header. This prefix starts with a broadcast MAC, to ease passage + through the host side RX filter. + config NET_DSA_TAG_NETC tristate "Tag driver for NXP NETC switches" help
net/dsa/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_NET_DSA_TAG_HELLCREEK) += tag_hellcreek.o obj-$(CONFIG_NET_DSA_TAG_KS8995) += tag_ks8995.o obj-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o obj-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o +obj-$(CONFIG_NET_DSA_TAG_LAN9645X) += tag_lan9645x.o obj-$(CONFIG_NET_DSA_TAG_MT7628) += tag_mt7628.o obj-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o obj-$(CONFIG_NET_DSA_TAG_MXL_862XX) += tag_mxl862xx.o
net/dsa/tag_lan9645x.c new file +514 -0
514 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v17 1/4] net: dsa: add tag driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The receive and transmit halves of the LAN9645x tagger disagree about which bridge VLAN protocol they support, and nothing…
--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch, which uses a front port as an NPI CPU port. Extraction uses a 16 byte long prefix plus a 28 byte IFH, and injection uses the IFH only. On receive, VLAN tags popped by the hardware are restored as hwaccel tags; on transmit, VLAN tags are moved into the IFH.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,514 @@
[ ... ]
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+static struct sk_buff *lan9645x_xmit_get_vlan_info (struct sk_buff *skb, +struct net_device *br, +u32 *vlan_tci, +u32 *tag_type) +{
[ ... ]
Quoted 22 lines
net/dsa/tag_lan9645x.c new file +22
-0+br_vlan_get_proto (br, &proto); + + *vlan_tci =0 ; +if (skb->len >=VLAN_ETH_HLEN ) { +if (unlikely (!pskb_may_pull (skb,VLAN_ETH_HLEN ))) { +kfree_skb (skb); +return NULL ; + } + + hdr =skb_vlan_eth_hdr (skb); +if (ntohs (hdr->h_vlan_proto) == proto && +ntohs (hdr->h_vlan_TCI) &VLAN_VID_MASK ) { +vlan_remove_tag (skb, &tci); + *vlan_tci = tci; + } + } + + *tag_type = (proto !=ETH_P_8021Q ) ?LAN9645X_IFH_TAG_TYPE_S : +LAN9645X_IFH_TAG_TYPE_C ; + +return skb; +}
[ ... ]
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) +{
[ ... ]
net/dsa/tag_lan9645x.c line 461
Quoted 11 lines
net/dsa/tag_lan9645x.c new file +11
-0+if (ifh_gap_len) { +/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH +* reports. The classifier recognizes both TPIDs as VLAN tags, +* so an S-tag has already been used for classification by the +* time we get here. Restoring it as 802.1AD would make the +* bridge push it back into the payload and reclassify the frame +* to the port pvid, on a different VID than the one the +* hardware forwarded it on. +*/ +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), vlan_tci); + }
[Severity: Medium]
Do the transmit and receive paths agree on which bridge vlan_protocol is supported?
The commit message says:
This assumes a bridge vlan_protocol of 802.1Q, which is the only protocol the driver offloads.
lan9645x_xmit_get_vlan_info() does three things:
- It reads the bridge protocol with br_vlan_get_proto().
- It strips a payload tag whose TPID matches that protocol, and the protocol can be 0x88a8.
- It sets LAN9645X_IFH_TAG_TYPE_S when the protocol is not ETH_P_8021Q.
So the transmit path looks written for 802.1ad bridges. lan9645x_rcv(), on the other hand, always restores the popped tag as ETH_P_8021Q.
Does anything enforce the 802.1Q-only assumption?
__br_vlan_set_proto() in net/bridge/br_vlan.c sends SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL with SWITCHDEV_F_SKIP_EOPNOTSUPP and ignores -EOPNOTSUPP:
err = switchdev_port_attr_set(br->dev, &attr, extack); if (err && err != -EOPNOTSUPP) return err;
Nothing under net/dsa/ handles that attribute. So it looks like "ip link set br0 type bridge vlan_protocol 802.1ad" cannot be vetoed, even after lan9645x ports have joined the bridge.
Here is what would happen on such a bridge:
- Every popped S-tag reaches the bridge as a 0x8100 hwaccel tag.
- br_allowed_ingress() sees that skb->vlan_proto != br->vlan_proto.
- It pushes the tag back into the payload as a C-tag that was never on the wire.
- It classifies the frame to the port pvid, not the VID the hardware used.
Meanwhile the transmit path treats S-tags as bridge VLAN tags.
At this point in the series the switch driver has no .port_bridge_join and does not program VLAN popping. So dp->bridge is NULL and no tags get popped. The problem would only become reachable once VLAN-aware bridge offload is added.
Would it make sense to use one model in both directions? One option is to drop the LAN9645X_IFH_TAG_TYPE_S handling on xmit and reject 802.1ad. The other is to handle the TPID the same way on transmit and receive.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-dsa_lan9645x_switch_driver_base-v17-0-83a471c5bddb%40microchip.com
Re: [PATCH net-next v17 1/4] net: dsa: add tag driver for LAN9645X
Quoted 127 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The receive and transmit halves of the LAN9645x tagger disagree about which bridge VLAN protocol they support, and nothing…
--
net: dsa: add tag driver for LAN9645X
This adds a DSA tag driver for the Microchip LAN9645x switch, which uses a front port as an NPI CPU port. Extraction uses a 16 byte long prefix plus a 28 byte IFH, and injection uses the IFH only. On receive, VLAN tags popped by the hardware are restored as hwaccel tags; on transmit, VLAN tags are moved into the IFH.
Quoted 6 lines
net/dsa/tag_lan9645x.c new file +0
-0@@ -0,0 +1,514 @@[ ... ]
Quoted 5 lines
net/dsa/tag_lan9645x.c new file +5
-0+static struct sk_buff *lan9645x_xmit_get_vlan_info (struct sk_buff *skb, +struct net_device *br, +u32 *vlan_tci, +u32 *tag_type) +{[ ... ]
Quoted 22 lines
net/dsa/tag_lan9645x.c new file +22
-0+br_vlan_get_proto (br, &proto); + + *vlan_tci =0 ; +if (skb->len >=VLAN_ETH_HLEN ) { +if (unlikely (!pskb_may_pull (skb,VLAN_ETH_HLEN ))) { +kfree_skb (skb); +return NULL ; + } + + hdr =skb_vlan_eth_hdr (skb); +if (ntohs (hdr->h_vlan_proto) == proto && +ntohs (hdr->h_vlan_TCI) &VLAN_VID_MASK ) { +vlan_remove_tag (skb, &tci); + *vlan_tci = tci; + } + } + + *tag_type = (proto !=ETH_P_8021Q ) ?LAN9645X_IFH_TAG_TYPE_S : +LAN9645X_IFH_TAG_TYPE_C ; + +return skb; +}[ ... ]
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) +{[ ... ]
net/dsa/tag_lan9645x.c line 461
Quoted 11 lines
net/dsa/tag_lan9645x.c new file +11
-0+if (ifh_gap_len) { +/* The tag is restored as a C-tag, not as the TAG_TYPE the IFH +* reports. The classifier recognizes both TPIDs as VLAN tags, +* so an S-tag has already been used for classification by the +* time we get here. Restoring it as 802.1AD would make the +* bridge push it back into the payload and reclassify the frame +* to the port pvid, on a different VID than the one the +* hardware forwarded it on. +*/ +__vlan_hwaccel_put_tag (skb,htons (ETH_P_8021Q ), vlan_tci); + }[Severity: Medium]
Do the transmit and receive paths agree on which bridgevlan_protocolis supported?The commit message says:
This assumes a bridge
vlan_protocolof 802.1Q, which is the only protocol the driver offloads.
lan9645x_xmit_get_vlan_info()does three things:- It reads the bridge protocol with
br_vlan_get_proto().
- It strips a payload tag whose TPID matches that protocol, and the protocol can be0x88a8.
- It setsLAN9645X_IFH_TAG_TYPE_Swhen the protocol is notETH_P_8021Q.So the transmit path looks written for 802.1ad bridges.
lan9645x_rcv(), on the other hand, always restores the popped tag asETH_P_8021Q.Does anything enforce the 802.1Q-only assumption?
__br_vlan_set_proto()innet/bridge/br_vlan.csendsSWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOLwithSWITCHDEV_F_SKIP_EOPNOTSUPPand ignores-EOPNOTSUPP:err = switchdev_port_attr_set(br->dev, &attr, extack); if (err && err != -EOPNOTSUPP) return err;Nothing under
net/dsa/handles that attribute. So it looks like "ip link set br0 type bridgevlan_protocol802.1ad" cannot be vetoed, even after lan9645x ports have joined the bridge.Here is what would happen on such a bridge:
- Every popped S-tag reaches the bridge as a
0x8100hwaccel tag.
-br_allowed_ingress()sees thatskb->vlan_proto!=br->vlan_proto.
- It pushes the tag back into the payload as a C-tag that was never on the wire.
- It classifies the frame to the port pvid, not the VID the hardware used.Meanwhile the transmit path treats S-tags as bridge VLAN tags.
Quoted 8 lines
At this point in the series the switch driver has no .port_bridge_join and does not program VLAN popping. So
dp->bridgeis NULL and no tags get popped. The problem would only become reachable once VLAN-aware bridge offload is added.Would it make sense to use one model in both directions? One option is to drop the
LAN9645X_IFH_TAG_TYPE_Shandling on xmit and reject 802.1ad. The other is to handle the TPID the same way on transmit and receive.
This asymmetry is intentional. The driver will not support an 802.1ad bridge, when VLAN and bridge support lands it will reject that procotol to the extend possible.
On RX we have to restore as 802.1Q. The classifier recognizes both TPIDs as VLAN tags on every port, so on an 802.1Q bridge an S-tagged frame is classified to its S-VID before it is extracted. Following the IFH and restoring the tag as 802.1AD would make the bridge push it back into the payload and classify the frame to the port pvid, so it would be terminated on a different VID than the one the hardware forwards it on. Restoring it as a C-tag keeps the two consistent.
On TX the tagger does what the bridge asks for. It moves the tag of the bridge vlan_protocol into the IFH and signals its type, and leaves any other tag in the payload. The rewriter pushes the port tag with the TPID IFH.TAG_TYPE reports, so always signalling a C-tag would send the tags of an 802.1ad bridge out as 802.1Q tags, without making 802.1ad work.
PATCH v17 2/4 dt-bindings: net: dsa: add Microchip LAN9645x switch
In reply to Jens Emil Schulz ØstergaardAdd bindings for LAN9645X switch. We use a fallback compatible for the smallest SKU microchip,lan96455s-switch. The last digit of the part number is the number of usable front ports and the letter is the feature set.
The switch is a child of an externally controlled parent that hands out one regmap per register target, so reg and reg-names describe the target layout the way mscc,vsc7514-switch.yaml does for the equivalent mscc,vsc7512-switch node. That binding, and the mfd parent it hangs off in mscc,ocelot.yaml, is the model this driver and its parent follow.
---
Changes in v14:
- Use the dt-bindings: net: dsa: subject prefix and do not repeat "bindings" in the subject.
- Describe all switch register targets in reg, and the analyzer and PTP interrupts.
Changes in v13:
- Remove section quoting Documentation/networking/phy.rst from commit message.
- Remove rx/tx-internal-delay-ps from example.
Changes in v12:
- Remove Rob's Reviewed-by
- Match both the port@ and ethernet-port@ spellings, so the per port constraints apply. dsa.yaml accepts either, and the local pattern only matched the long form.
- Allow 0 as well as 2000 for rx/tx-internal-delay-ps, matching what the driver accepts, and restrict them to those two values on RGMII ports.
- Constrain the ethernet-ports node the way renesas,rzn1-a5psw.yaml does, with additionalProperties instead of a local dsa-port.yaml $ref.
- Put the example properties in canonical order, so dt-check-style --mode=strict is clean.
- Describe the switch register targets in reg, with a matching reg-names, following mscc,vsc7514-switch.yaml.
- Document the default of rx/tx-internal-delay-ps, as microchip,lan937x.yaml does.
- Describe the SKU naming in the binding description.
Changes in v5:
- No changes.
Changes in v4:
- No changes.
Changes in v3:
- remove additionalProperties: true
- remove unnecessary | from description
- change top level $ref to dsa.yaml#/$defs/ethernet-ports
- use ethernet-ports and ethernet-port
- move ethernet-ports under properties instead of patternProperties
- move unevaluatedProperties: false after $ref
- update example to use ethernet-ports and ethernet-port
Changes in v2:
- rename file to microchip,lan96455s-switch.yaml
- remove led vendor property
- add {rx,tx}-internal-delay-ps for rgmii delay
- remove labels from example
- remove container node from example
--- .../net/dsa/microchip,lan96455s-switch.yaml | 208 +++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 209 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +208 -0
@@ -0,0 +1,208 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/microchip,lan96455s-switch.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microchip LAN9645x Ethernet switch + +maintainers: + - Jens Emil Schulz Østergaard <[email protected]> + +description: | + The LAN9645x switch is a multi-port Gigabit AVB/TSN Ethernet switch with + five integrated 10/100/1000Base-T PHYs. In addition to the integrated PHYs, + it supports up to 2 RGMII/RMII, up to 2 BASE-X/SERDES/2.5GBASE-X and one + Quad-SGMII interfaces. + + The part number encodes the SKU. The last digit is the number of usable + front ports, 5, 7 or 9. The letter is the feature set, f for full and s for + standard, where full adds HSR, PRP, TAS, frame preemption and PSFP. + +properties: + compatible: + oneOf: + - enum: + - microchip,lan96455s-switch + - items: + - enum: + - microchip,lan96455f-switch + - microchip,lan96457f-switch + - microchip,lan96459f-switch + - microchip,lan96457s-switch + - microchip,lan96459s-switch + - const: microchip,lan96455s-switch + + reg: + items: + - description: General configuration block target + - description: + CPU device queue system target, the register based frame injection + and extraction interface + - description: Precision Time Protocol target + - description: Chip top level target + - description: Time aware shaper target + - description: Rewriter target + - description: VCAP ES0 target, egress stage 0 classification + - description: OAM MEP target + - description: VCAP S1 target, ingress stage 1 classification + - description: VCAP S2 target, ingress stage 2 classification + - description: Switching engine target + - description: HSIO target + - description: Port 0 device target + - description: Port 1 device target + - description: Port 2 device target + - description: Port 3 device target + - description: Port 4 device target + - description: Port 5 device target + - description: Port 6 device target + - description: Port 7 device target + - description: Port 8 device target + - description: Queue system target + - description: Automatic frame injector target + - description: Analyzer target + + reg-names: + items: + - const: gcb + - const: qs + - const: ptp + - const: chip_top + - const: tas + - const: rew + - const: vcap0 + - const: mep + - const: vcap1 + - const: vcap2 + - const: sys + - const: hsio + - const: dev0 + - const: dev1 + - const: dev2 + - const: dev3 + - const: dev4 + - const: dev5 + - const: dev6 + - const: dev7 + - const: dev8 + - const: qsys + - const: afi + - const: ana + + interrupts: + items: + - description: PTP timestamp ready interrupt + - description: PTP synchronization interrupt from the PTP pins + - description: Analyzer interrupt + + interrupt-names: + items: + - const: ptp + - const: ptp-ext + - const: ana + + ethernet-ports: + type: object + additionalProperties: true + patternProperties: + "^(ethernet-)?port@[0-8]$": + type: object + description: Ethernet switch ports + additionalProperties: true + + allOf: + - if: + properties: + phy-mode: + contains: + enum: + - rgmii + - rgmii-rxid + - rgmii-txid + - rgmii-id + then: + properties: + rx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + tx-internal-delay-ps: + $ref: "#/$defs/internal-delay-ps" + +$ref: dsa.yaml#/$defs/ethernet-ports + +required: + - compatible + - reg + - reg-names + - ethernet-ports + +unevaluatedProperties: false + +$defs: + internal-delay-ps: + description: + Disable the delay line using 0 ps, or enable the 2000 ps delay. The + delay line is not tunable, so no other phase can be selected. + enum: [0, 2000] + default: 0 + +examples: + - | + ethernet-switch@4000 { + compatible = "microchip,lan96459f-switch", "microchip,lan96455s-switch"; + reg = <0x4000 0x244>, <0x8000 0x4c>, <0xc000 0x1f0>, + <0x10000 0x134>, <0x14000 0x2c8>, <0x18000 0x1910>, + <0x1c000 0x468>, <0x20000 0x1480>, <0x24000 0x468>, + <0x28000 0x468>, <0x2c000 0x12d4>, <0x30000 0xe4>, + <0x38000 0xb8>, <0x3c000 0xb8>, <0x40000 0xb8>, + <0x44000 0xb8>, <0x48000 0xb8>, <0x4c000 0xb8>, + <0x50000 0xb8>, <0x54000 0xb8>, <0x58000 0xb8>, + <0x100000 0xa000>, <0x120000 0x1998>, <0x140000 0x7468>; + reg-names = "gcb", "qs", "ptp", "chip_top", "tas", "rew", "vcap0", + "mep", "vcap1", "vcap2", "sys", "hsio", "dev0", "dev1", + "dev2", "dev3", "dev4", "dev5", "dev6", "dev7", "dev8", + "qsys", "afi", "ana"; + interrupts = <27>, <26>, <17>; + interrupt-names = "ptp", "ptp-ext", "ana"; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + phy-handle = <&cuphy0>; + phy-mode = "gmii"; + }; + + ethernet-port@1 { + reg = <1>; + phy-handle = <&cuphy1>; + phy-mode = "gmii"; + }; + + ethernet-port@2 { + reg = <2>; + phy-handle = <&cuphy2>; + phy-mode = "gmii"; + }; + + ethernet-port@3 { + reg = <3>; + phy-handle = <&cuphy3>; + phy-mode = "gmii"; + }; + + ethernet-port@7 { + reg = <7>; + ethernet = <&cpu_host_port>; + phy-mode = "rgmii"; + + fixed-link { + full-duplex; + pause; + speed = <1000>; + }; + }; + }; + }; +...
MAINTAINERS +1 -0
@@ -18324,6 +18324,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 v17 2/4] dt-bindings: net: dsa: add Microchip LAN9645x switch
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] Rob Herring's Reviewed-by is kept on the binding patch in Documen tation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml,…
- [Low] The schema does not actually limit port indexes to 0-8.
- [Low] The binding seems to leave out the register-based extraction interrupt.
--
dt-bindings: net: dsa: add Microchip LAN9645x switch
This adds a DT binding for the Microchip LAN9645x DSA switch family. The SKU variants fall back to microchip,lan96455s-switch. The binding describes 24 register targets through reg/reg-names, three interrupts and the per-port RGMII internal delay constraints, and adds the file to MAINTAINERS.
Quoted 6 lines
Reviewed-by Steen Hegelund <[email protected]>Signed-off-by Jens Emil Schulz Østergaard <[email protected]>Reviewed-by Rob Herring (Arm) <[email protected]>---
Changes in v14:
[ ... ]
Quoted 2 lines
- Describe all switch register targets in reg, and the analyzer and PTP interrupts.
[ ... ]
Quoted 2 lines
Changes in v12:
- Remove Rob's Reviewed-by
[ ... ]
Quoted 2 lines
- Describe the switch register targets in reg, with a matching reg-names, following mscc,vsc7514-switch.yaml.
[Severity: Low]
Does Rob's Reviewed-by still apply to this version?
In v14, reg/reg-names becomes a fixed, ordered list of 24 targets. v14 also adds new interrupts and interrupt-names properties ("ptp", "ptp-ext", "ana"). All of this is new DT ABI.
The v12 changelog dropped this tag for a similar reg/reg-names change. Here the tag sits after the Signed-off-by, which suggests it was carried over from an earlier posting.
Did Rob review v14? If not, should the tag be dropped so that the new reg-names order and interrupt-names get DT maintainer review?
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +0
-0@@ -0,0 +1,208 @@
[ ... ]
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +6
-0+ reg: + items: + - description: General configuration block target + - description: + CPU device queue system target, the register based frame injection + and extraction interface
[ ... ]
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml line 102
Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +11
-0+ interrupts: + items: + - description: PTP timestamp ready interrupt + - description: PTP synchronization interrupt from the PTP pins + - description: Analyzer interrupt + + interrupt-names: + items: + - const: ptp + - const: ptp-ext + - const: ana
[Severity: Low]
Is an interrupt for register-based extraction missing here?
The qs entry in reg is described as "the register based frame injection and extraction interface". However, interrupts lists only ptp, ptp-ext and ana, and there is no minItems.
The other bindings for this switch IP family all describe an xtr interrupt next to the QS block:
mscc,vsc7514-switch.yaml: ptp_rdy, xtr, fdma
microchip,lan966x-switch.yaml: xtr, fdma, ana, ptp, ptp-ext microchip,sparx5-switch.yaml: xtr, fdma, ptp
The commit message names mscc,vsc7514-switch.yaml as the model. The driver in this series also sets up manual extraction through QS_XTR_GRP_CFG(0) in lan9645x_port_cpu_init().
If LAN9645x routes an xtr interrupt, how would this binding describe it? Since the list is fixed, adding it later would need a fourth item plus
minItems: 3. I could not tell from the tree whether the hardware has a separate xtr line, so this may be fine as it is.
Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml new file +8
-0+ ethernet-ports: + type: object + additionalProperties: true + patternProperties: + "^(ethernet-)?port@[0-8]$": + type: object + description: Ethernet switch ports + additionalProperties: true
[ ... ]
Quoted 1 line
+$ref: dsa.yaml#/$defs/ethernet-ports
[Severity: Low]
Does this actually limit port indexes to 0-8?
ethernet-ports has additionalProperties: true, so the local pattern only constrains nodes that match it. The top-level $ref adds the broader pattern from dsa.yaml:
Documentation/devicetree/bindings/net/dsa/dsa.yaml:
"^(ethernet-)?port@[0-9a-f]+$":
description: Ethernet switch ports $ref: dsa-port.yaml#
unevaluatedProperties: false
So nodes such as ethernet-port@9 or ethernet-port@10 pass dt_binding_check. They also skip the local RGMII rule that limits rx/tx-internal-delay-ps to [0, 2000].
A DT like that only fails at probe time, in dsa_switch_parse_ports_of():
net/dsa/dsa.c:dsa_switch_parse_ports_of() {
...
if (reg >= ds->num_ports) {
dev_err(ds->dev, "port %pOF index %u exceeds num_ports (%u)\n",
port, reg, ds->num_ports);
of_node_put(port);
err = -EINVAL;
goto out_put_node;
...
}renesas,rzn1-a5psw.yaml, which this binding follows, has the same pattern.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-dsa_lan9645x_switch_driver_base-v17-0-83a471c5bddb%40microchip.com
PATCH v17 3/4 net: dsa: lan9645x: add autogenerated register macros
In reply to Jens Emil Schulz ØstergaardAdd autogenerated register macros and update MAINTAINERS file. The register macros are generated using the same tool we use for lan966x, sparx5 and lan969x.
---
Changes in v13:
- Add QS:XTR:XTR_GRP_CFG for extraction mode configuration.
Changes in v12:
- Regenerate without the unused AFI target.
Changes in v7:
- Add ANA:COMMON:CPUQ_8021_CFG for bpdu cpu queue configuration.
Changes in v3:
- No changes
Changes in v2:
- Add cpuq registers
--- MAINTAINERS | 1 + drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h | 1932 ++++++++++++++++++++ 2 files changed, 1933 insertions(+)
MAINTAINERS +1 -0
@@ -18325,6 +18325,7 @@ M: [email protected] L: [email protected] S: Maintained F: Documentation/devicetree/bindings/net/dsa/microchip,lan96455s-switch.yaml +F: drivers/net/dsa/microchip/lan9645x/* F: include/linux/dsa/lan9645x.h F: net/dsa/tag_lan9645x.c
drivers/net/dsa/microchip/lan9645x/lan9645x_regs.h new file +1932 -0
1,932 lines not on this page · raw message
Signature · 1 line
2.52.0
PATCH v17 4/4 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.
The ports operate as standalone ports. Bridges and VLAN uppers on the ports are handled in software.
This patch only wires up the internal CuPHYs (ports 0-4) and the RGMII paths for ports 7 and 8. The supported SerDes-based modes: SGMII, QSGMII, 1000BASE-X and 2500BASE-X on ports 5-8 are deferred, and support will be added in follow-up patches. Port 5-6 have no usable interface mode in this patch, and should not be declared in DT until SerDes support lands.
If port 5 or 6 is declared in DT as a user port, phylink_create() rejects the empty supported_interfaces and dsa_tree_setup_ports() falls back to setting the port up as unused, so the switch still probes. DSA logs an error including the port number. Declared as a CPU port there is no such fallback, and the probe fails, and our driver logs an error including the port number.
The intended way to bind this driver is using a parent MFD driver, responsible for the register IO protocol, and distributing regmaps to child devices. The goal is to use the same approach as the MFD driver in drivers/mfd/ocelot-spi.c, which also resets the chip before it instantiates its children.
This driver expects to request named regmaps from a parent device. This approach is similar to the DSA driver
drivers/net/dsa/ocelot/ocelot_ext.c
which supports being driven by an external CPU via SPI with parent device drivers/mfd/ocelot-spi.c.
The MFD driver will come in a later series, because there are requirements on the number of child devices before a driver qualifies as a MFD device.
---
Changes in v17:
- Check regmap read error in lan9645x_probe() and lan9645x_setup().
- Reject more than one CPU port in lan9645x_tag_npi_setup().
Changes in v16:
- Drop ds->assisted_learning_on_cpu_port, ds->fdb_isolation and ds->max_num_bridges, the reserved VLAN IDs, the general purpose PGID range, PGID_MRP and lan_bulk_rd() which the dropped patches used.
- Describe the standalone port operation in the commit message.
Changes in v15:
- Link down now asserts MAC_TX_RST and MAC_RX_RST instead of flushing the queues and asserting PORT_RST, which can hang the port when the MAC cannot transmit the frames still queued.
Changes in v13:
- Only redirect the CPU extraction queues to the NPI port while the NPI port link is up. This avoids queuing CPU frames to the NPI port while its MAC is held in reset.
- Configure CPU extraction group 0 for manual extraction, instead of the default where the VRAP engine owns it, so QSYS_SW_STATUS.EQ_AVAIL of the CPU port module can be polled when flushing it on NPI link up.
Changes in v12:
- Drop lan9645x_port_set_tail_drop_wm(). This tail dropping config is only active under cut through forwarding, which we never enable.
- lan9645x_reset_switch(): skip the memory init when the switch core is already enabled. We expect parent device to reset before probe, but if it does not, we must skip memory init if switch core is already enabled.
- Drop unused shared_queue_sz field and LAN9645X_BUFFER_MEMORY define.
- Set ds->max_num_bridges = 1 next to ds->fdb_isolation. We support a single offloaded bridge, so let the core enforce it.
- Reject an NPI port with no usable interface mode.
- Kconfig: select REGMAP.
- Include the CPU port module in the unicast and multicast flood masks. Host address filtering needs the fdb and mdb operations, and unknown traffic needs port_set_host_flood(), so until bridge support lands the host depends on flooding to receive anything.
- Describe in the commit what happens if port 5 or 6 is declared in DT.
- Drop unused register writes from lan9645x_port_cpu_init().
- Update PGID table comment.
- Drop the unused PGID_AGGR_NUM, LAN9645X_ISDX_MAX, LAN9645X_ESDX_MAX and LAN9645X_SFID_MAX defines, along with PGID_ENTRIES.
- Follow the LAN9645X_IFH_LEN rename in the tag driver.
- Drop ds->dscp_prio_mapping_is_global. It is only consulted after port_add_dscp_prio() or port_del_dscp_prio() succeeds, neither of which this series implements.
- Program QSYS_RES_CFG through lan9645x_wm_enc().
- Return -ENOMEM directly, not via dev_err_probe(), and add the missing newlines to the remaining probe messages.
- lan9645x_npi_port_deinit(): restore the NPI bit in the CPU port module source PGID that lan9645x_npi_port_init() cleared.
- Spell the part LAN9645x in the Kconfig prompt, the help text and MODULE_DESCRIPTION.
- Drop the unread NULL sentinel from lan9645x_resource_names[].
- Resolve the regmap and the register address once in lan9645x_rd_poll_timeout() and lan9645x_rd_poll_slow().
- lan9645x_get_max_mtu(): drop the NPI case. DSA only asks for the user port limit and adds the tag overhead back itself when it sizes the conduit MTU.
- lan9645x_phylink_mac_prepare(): drop the port range check. Ports 5 and 6 get no phylink instance, and ds->num_ports bounds the rest.
- lan9645x_phylink_mac_link_up(): drop the unreachable SPEED_2500 case, and the DEV_CLOCK_CFG.LINK_SPEED fixup it forced. lan9645x_phylink_get_caps() does not advertise MAC_2500FD.
- Fix DEV_MAC_IFG_CFG.TX_IFG, which had its full and half duplex values swapped.
- Drop the unused afi target regmap request.
- Name the first per port regmap dev0 rather than dev, so the nine read uniformly.
- Bound the ANA_PGID_CFG.OBEY_VLAN loop at PGID_AGGR.
- lan9645x_phylink_mac_prepare(): drop the HSIO_HW_CFG.RGMII_0_CFG write. The field resets to DEV7 and nothing else writes it.
- lan9645x_phylink_port_down(): restore QSYS_SW_PORT_MODE.AGING_MODE to 2 after the flush, which is the reset value, rather than 1. Mode 1 exempts frames from the CPU interface from the transmit ageing that lan9645x_setup() enables, and every port sat in it from probe.
Changes in v9:
- Drop the DEV4 RGMII muxing support.
Changes in v8:
- Remove the CPU_PORT macro, which named the chips internal CPU port module and collided with the DSA CPU port terminology. Reference the module as lan9645x->num_phys_ports.
- Rework the port map comment to distinguish the chip CPU port modules (indices 9-10) from the DSA CPU port (the NPI front port).
- Derive PGID_GP_START from NUM_PHYS_PORTS instead of CPU_PORT.
- Add a port_mux_lock mutex to serialize port mux arbitration in lan9645x_phylink_mac_prepare().
Changes in v7:
- use cpu queue LAN9645X_CPUQ_TRAP for bpdu frames
Changes in v5:
- remove dd_dis and tsn_dis, and add SKU supported port validation during setup
- phylink: remove MAC_2500FD
- phylink: add comment about empty supported_interfaces for port 5-6.
- phylink: fix 2:1 rgmii port muxing for port module 4 and 7 to be fully dynamic and validate requested mux settings.
- phylink: add comment about 2:1 rgmii port muxing for port module 4 and 7.
- rx/tx-internal-delay-ps checked against support 2ns value
- update commit message
- init lan9645x->npi = -1 at probe and check port < 0 in npi_deinit
Changes in v4:
- add comment to QSYS_RES_CFG configuration
- phylink_mac_prepare: fix to make sure we can dynamically change rgmii on port 4
- move ports allocation to probe
- tag_npi_setup: reject cascaded setups
- skip WARN_ON in lan9645x_to_port
Changes in v3:
- move DEV_MAC_TAGS_CFG config to port setup, for vlan overhead in port frame maxlen
- remove code disabling ipv6 on conduit
- use of_property_read_u32 for {rx,tx}-internal-delay-ps
- use dsa_user_ports(ds) instead of GENMASK(lan9645x->num_phys_ports - 1, 0) as base flood mask.
- update obey vlan comment
Changes in v2:
- source Kconfig from drivers/net/dsa/Kconfig
- sorting in Kconfig and Makefiles
- remove unused struct fields
- remote path delays
- use port_setup and dp->dn instead of DTS parsing
- phylink: split rgmii setup into dll and speed config
- phylink: remove pcs/sgmii/qsgmii related code
- phylink: simplify mac_prepare
- phylink: remove phylink_ops wrappers
- phylink: remove unrelated config from link up
- phylink: reorder functions according to phylink call order
--- drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/lan9645x/Kconfig | 12 + drivers/net/dsa/microchip/lan9645x/Makefile | 8 + drivers/net/dsa/microchip/lan9645x/lan9645x_main.c | 464 +++++++++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_main.h | 306 ++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c | 116 ++++++ .../net/dsa/microchip/lan9645x/lan9645x_phylink.c | 315 ++++++++++++++ drivers/net/dsa/microchip/lan9645x/lan9645x_port.c | 166 ++++++++ 9 files changed, 1390 insertions(+)
drivers/net/dsa/Kconfig +2 -0
@@ -82,6 +82,8 @@ config NET_DSA_MV88E6060 source "drivers/net/dsa/microchip/Kconfig" +source "drivers/net/dsa/microchip/lan9645x/Kconfig" + source "drivers/net/dsa/motorcomm/Kconfig" source "drivers/net/dsa/mv88e6xxx/Kconfig"
drivers/net/dsa/microchip/Makefile +1 -0
@@ -12,3 +12,4 @@ endif obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ9477_I2C) += ksz9477_i2c.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_SPI) += ksz_spi.o obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ8863_SMI) += ksz8863_smi.o +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += lan9645x/
drivers/net/dsa/microchip/lan9645x/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +config NET_DSA_MICROCHIP_LAN9645X + tristate "Microchip LAN9645x switch support" + depends on NET_DSA + select NET_DSA_TAG_LAN9645X + select REGMAP + help + This driver adds DSA support for Microchip LAN9645x switch chips. + The lan9645x switch is a multi-port Gigabit AVB/TSN Ethernet Switch + with five integrated 10/100/1000Base-T PHYs. In addition to the + integrated PHYs, it supports up to 2 RGMII/RMII, up to 2 + BASE-X/SERDES/2.5GBASE-X and one Quad-SGMII/Quad-USGMII interfaces.
drivers/net/dsa/microchip/lan9645x/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_NET_DSA_MICROCHIP_LAN9645X) += mchp-lan9645x.o + +mchp-lan9645x-objs := \ + lan9645x_main.o \ + lan9645x_npi.o \ + lan9645x_phylink.o \ + lan9645x_port.o \
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +464 -0
464 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_main.h new file +306 -0
306 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_npi.c new file +116 -0
116 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +315 -0
315 lines not on this page · raw message
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.52.0
[email protected]
AI reviewRe: [PATCH net-next v17 4/4] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The driver never explicitly initializes the analyzer MAC table or VLAN table.
- [Low] Several comments and register writes in this patch describe features the driver does not have.
- [Low] In lan9645x_phylink_mac_link_up() (lan9645x_phylink.c), the comment above the DEV_CLOCK_CFG write gives the…
- [Low] For the NPI port, lan9645x_port_set_maxlen() (lan9645x_port.c) adds both LAN9645X_IFH_LEN_BYTES (28) and LAN9645X_LONG_PREFIX_LEN…
--
net: dsa: lan9645x: add basic dsa driver for LAN9645X
This adds a basic DSA driver for the Microchip LAN9645x switch. The driver gets named regmaps from a parent device. All ports run as standalone ports, with phylink integration for the internal CuPHYs on ports 0-4 and RGMII on ports 7-8. SerDes modes are left for follow-up patches.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,464 @@
[ ... ]
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +9
-0+static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +u32 rst_cfg, val =0 ; +int err; + +/* The parent must reset the whole chip before instantiating its +* children, so the switch core is disabled when we get here. The +* sequence below must not run more than once: initializing the +* memories on a running core corrupts pointers inside the queue
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 114
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+* system, which eventually fills up and stops passing traffic. If the +* core is already enabled the chip was not reset, so skip it. +*/ + err =regmap_read (lan_rmap (lan9645x,SYS_RESET_CFG ), +lan_rel_addr (SYS_RESET_CFG ), &rst_cfg); +if (err) +return err; + +if (SYS_RESET_CFG_CORE_ENA_GET (rst_cfg)) +return 0 ;
[Severity: Medium]
If CORE_ENA is already set, this returns before SYS_RAM_INIT. That is the only memory or table initialization in the driver. On this path, is anything clearing the analyzer MAC table and the VLAN table?
ANA_MACACCESS and ANA_VLANACCESS are defined in lan9645x_regs.h, but no driver file uses them. lan966x runs the same RAM_INIT sequence and then issues MACACCESS_CMD_INIT (lan966x_mac.c) and VLANACCESS_CMD_INIT (lan966x_vlan.c) as separate steps.
This path can be reached after kexec, because lan9645x_shutdown() only calls dsa_switch_shutdown() and leaves the core enabled with the tables populated. It can also be reached with a bootloader that leaves the switch running.
The driver depends on flooding to deliver host traffic: learning is disabled, PGID_SRC + p is 0, and PGID_UC/MC/BC include the CPU port module. Suppose the analyzer behaves like ocelot and lan966x, and a stale unicast entry points at another front port. Would DEST resolve to that port, PGID_SRC then mask it to nothing, and the frame be dropped before the CPU sees it?
Dynamic entries would age out through ANA_AUTOAGE after about 300 seconds. Static entries would never age out.
lan9645x_setup() also sets ANA_PGID_CFG.OBEY_VLAN on every destination PGID. Does the CPU copy then depend on inherited VLAN table contents, such as VLAN_PGID_CPU_DIS, that the driver never programs?
[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +2
-0+static int lan9645x_setup (struct dsa_switch *ds) +{
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+/* 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 );
[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+/* Disable learning for frames discarded by VLAN ingress filtering */ +lan_rmw (ANA_ADVLEARN_VLAN_CHK_SET (1 ), +ANA_ADVLEARN_VLAN_CHK , + lan9645x,ANA_ADVLEARN );
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 204
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +5
-0+/* 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. +*/
[Severity: Low]
This isn't a bug, but this comment says control frames are redirected to the CPU and the dataplane forwards according to offloaded MDB entries. Does the driver set up either of these in this patch?
Nothing sets ANA_CPU_FWD_CFG_IGMP_REDIR_ENA or ANA_CPU_FWD_CFG_MLD_REDIR_ENA. lan9645x_switch_ops also has no port_mdb_add or port_mdb_del.
Some other writes look left over from functionality the v16 changelog says was dropped:
- The ANA_AGGR_CFG write under "Link Aggregation Mode:
NETDEV_LAG_HASH_L2". There are no LAG ops.
- The ANA_ADVLEARN VLAN_CHK write. lan9645x_port_setup() disables learning on every port with ANA_PORT_CFG_LEARN_ENA_SET(0).
- ANA_PGID(PGID_CPU) in lan9645x_port_cpu_init(). It is written once and never used as a destination.
The comment in include/linux/dsa/lan9645x.h, added by the tag driver patch earlier in this series, has the same mismatch:
/* Chip has 8 cpu queues. The cpu queues used by a frame are passed as a mask in
* the IFH on extraction. We use this to avoid classifying BPDU, IGMP and MLD
* frames in the tag driver.
*/
The switch driver only programs LAN9645X_CPUQ_TRAP, for BPDUs through ANA_CPUQ_8021_CFG. LAN9645X_CPUQ_COPY and the IGMP/MLD queues in ANA_CPUQ_CFG are never configured.
Could these comments and writes be dropped or changed to match what the driver does now?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +0
-0@@ -0,0 +1,315 @@
[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +7
-0+static void lan9645x_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev, +unsigned int link_an_mode, +phy_interface_t interface,int speed, +int duplex,bool tx_pause, +bool rx_pause) +{
[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +1
-0+ fc_spd =lan9645x_speed_fc_enc (gspeed);
[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +2
-0+/* Take out the clock from reset. Note this write will set all these +* fields to zero:
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 292
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +11
-0+* This linkspeed field has a slightly different encoding from others: +* +* - 0 is no-link +* - 1 is both 2500/1000 +* - 2 is 100mbit +* - 3 is 10mbit +* +*/ +lan_wr (DEV_CLOCK_CFG_LINK_SPEED_SET (fc_spd), + lan9645x, +DEV_CLOCK_CFG (p->chip_port));
[Severity: Low]
fc_spd comes from lan9645x_speed_fc_enc(). That helper is documented as the PFC_CFG.FC_LINK_SPEED encoding, and it maps 2500 to 0:
lan9645x_main.h:lan9645x_speed_fc_enc() {
...
case LAN9645X_SPEED_2500:
return 0;
...
}The comment just above says this field uses a different encoding, where 0 means no-link. Should DEV_CLOCK_CFG.LINK_SPEED have its own encoding instead of reusing fc_spd?
For 10/100/1000 the two encodings agree. SPEED_2500 cannot reach this code today, because lan9645x_phylink_get_caps() does not advertise MAC_2500FD and the speed switch returns early for anything else.
When 2500BASE-X support is added, would DEV_CLOCK_CFG be programmed as no-link? For reference, lan966x uses one encoding for both registers, with 2500 mapped to 1.
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +0
-0@@ -0,0 +1,166 @@
[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c line 62
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +10
-0+/* VLAN tag overhead is handled by DEV_MAC_TAGS_CFG */ +int lan9645x_port_set_maxlen (struct lan9645x *lan9645x,int port,size_t sdu) +{ +struct lan9645x_port *p =lan9645x_to_port (lan9645x, port); +int maxlen = sdu +ETH_HLEN +ETH_FCS_LEN ; + +if (port == lan9645x->npi) { + maxlen +=LAN9645X_IFH_LEN_BYTES ; + maxlen +=LAN9645X_LONG_PREFIX_LEN ; + }
[Severity: Low]
Is LAN9645X_LONG_PREFIX_LEN needed here? lan9645x_npi_port_init() configures injection with no prefix:
lan_rmw(SYS_PORT_MODE_INCL_XTR_HDR_SET(LAN9645X_TAG_PREFIX_LONG) | SYS_PORT_MODE_INCL_INJ_HDR_SET(LAN9645X_TAG_PREFIX_NONE),
lan9645x_xmit() in the tag driver only pushes the 28-byte IFH. The long prefix is only used on extraction.
ocelot_port_set_maxlen() sizes the NPI MAXLEN from the injection prefix (npi_inj_prefix). If DEV_MAC_MAXLEN_CFG works the same way on this chip, the NPI port accepts frames 16 bytes longer than needed. The pause watermarks derived from 4 * maxlen and 6 * maxlen would also be slightly larger than intended.
If MAXLEN here also limits frames sent with the extraction header, could a comment say why the extraction prefix is counted?
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111-dsa_lan9645x_switch_driver_base-v17-0-83a471c5bddb%40microchip.com
Re: [PATCH net-next v17 4/4] net: dsa: lan9645x: add basic dsa driver for LAN9645X
Quoted 81 lines · netdev-bot+sashiko
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The driver never explicitly initializes the analyzer MAC table or VLAN table.
- [Low] Several comments and register writes in this patch describe features the driver does not have.
- [Low] Inlan9645x_phylink_mac_link_up()(lan9645x_phylink.c), the comment above theDEV_CLOCK_CFGwrite gives the…
- [Low] For the NPI port,lan9645x_port_set_maxlen()(lan9645x_port.c) adds bothLAN9645X_IFH_LEN_BYTES(28) and LAN9645X_LONG_PREFIX_LEN…--
net: dsa: lan9645x: add basic dsa driver for LAN9645X
This adds a basic DSA driver for the Microchip LAN9645x switch. The driver gets named regmaps from a parent device. All ports run as standalone ports, with phylink integration for the internal CuPHYs on ports 0-4 and RGMII on ports 7-8. SerDes modes are left for follow-up patches.
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +0
-0@@ -0,0 +1,464 @@[ ... ]
Quoted 9 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +9
-0+static int lan9645x_reset_switch (struct lan9645x *lan9645x) +{ +u32 rst_cfg, val =0 ; +int err; + +/* The parent must reset the whole chip before instantiating its +* children, so the switch core is disabled when we get here. The +* sequence below must not run more than once: initializing the +* memories on a running core corrupts pointers inside the queue drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 114
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +10
-0+* system, which eventually fills up and stops passing traffic. If the +* core is already enabled the chip was not reset, so skip it. +*/ + err =regmap_read (lan_rmap (lan9645x,SYS_RESET_CFG ), +lan_rel_addr (SYS_RESET_CFG ), &rst_cfg); +if (err) +return err; + +if (SYS_RESET_CFG_CORE_ENA_GET (rst_cfg)) +return 0 ;[Severity: Medium]
If
CORE_ENAis already set, this returns beforeSYS_RAM_INIT. That is the only memory or table initialization in the driver. On this path, is anything clearing the analyzer MAC table and the VLAN table?
ANA_MACACCESSandANA_VLANACCESSare defined inlan9645x_regs.h, but no driver file uses them. lan966x runs the sameRAM_INITsequence and then issuesMACACCESS_CMD_INIT(lan966x_mac.c) andVLANACCESS_CMD_INIT(lan966x_vlan.c) as separate steps.This path can be reached after kexec, because
lan9645x_shutdown()only callsdsa_switch_shutdown()and leaves the core enabled with the tables populated. It can also be reached with a bootloader that leaves the switch running.The driver depends on flooding to deliver host traffic: learning is disabled,
PGID_SRC+ p is 0, and PGID_UC/MC/BC include the CPU port module. Suppose the analyzer behaves like ocelot and lan966x, and a stale unicast entry points at another front port. Would DEST resolve to that port,PGID_SRCthen mask it to nothing, and the frame be dropped before the CPU sees it?
Quoted 7 lines
Dynamic entries would age out through
ANA_AUTOAGEafter about 300 seconds. Static entries would never age out.
lan9645x_setup()also sets ANA_PGID_CFG.OBEY_VLAN on every destination PGID. Does the CPU copy then depend on inherited VLAN table contents, such asVLAN_PGID_CPU_DIS, that the driver never programs?
This is a false positive. These patches only support standalone ports. Nothing writes the MAC table or the VLAN table. Learning is disabled and there are no FDB, MDB or VLAN operations. VLAN_PGID_CPU_DIS has the correct value out of reset.
The later patches that use the tables will initialize them in lan9645x_setup(), whether or not the core was reset.
Quoted 173 lines
[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +2
-0+static int lan9645x_setup (struct dsa_switch *ds) +{[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+/* 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 );[ ... ]
Quoted 4 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +4
-0+/* Disable learning for frames discarded by VLAN ingress filtering */ +lan_rmw (ANA_ADVLEARN_VLAN_CHK_SET (1 ), +ANA_ADVLEARN_VLAN_CHK , + lan9645x,ANA_ADVLEARN );[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c line 204
Quoted 5 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_main.c new file +5
-0+/* 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. +*/ [Severity: Low]
This isn't a bug, but this comment says control frames are redirected to the CPU and the dataplane forwards according to offloaded MDB entries. Does the driver set up either of these in this patch?
Nothing sets
ANA_CPU_FWD_CFG_IGMP_REDIR_ENAorANA_CPU_FWD_CFG_MLD_REDIR_ENA.lan9645x_switch_opsalso has noport_mdb_addorport_mdb_del.Some other writes look left over from functionality the v16 changelog says was dropped:
- The
ANA_AGGR_CFGwrite under "Link Aggregation Mode:
NETDEV_LAG_HASH_L2". There are no LAG ops.- The
ANA_ADVLEARNVLAN_CHKwrite.lan9645x_port_setup()disables learning on every port withANA_PORT_CFG_LEARN_ENA_SET(0).-
ANA_PGID(PGID_CPU)inlan9645x_port_cpu_init(). It is written once and never used as a destination.The comment in
include/linux/dsa/lan9645x.h, added by the tag driver patch earlier in this series, has the same mismatch:/* Chip has 8 cpu queues. The cpu queues used by a frame are passed as a mask in
* the IFH on extraction. We use this to avoid classifying BPDU, IGMP and MLD
* frames in the tag driver.
*/The switch driver only programs
LAN9645X_CPUQ_TRAP, for BPDUs throughANA_CPUQ_8021_CFG.LAN9645X_CPUQ_COPYand the IGMP/MLD queues inANA_CPUQ_CFGare never configured.Could these comments and writes be dropped or changed to match what the driver does now?
[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +0
-0@@ -0,0 +1,315 @@[ ... ]
Quoted 7 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +7
-0+static void lan9645x_phylink_mac_link_up (struct phylink_config *config, +struct phy_device *phydev, +unsigned int link_an_mode, +phy_interface_t interface,int speed, +int duplex,bool tx_pause, +bool rx_pause) +{[ ... ]
Quoted 1 line
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +1
-0+ fc_spd =lan9645x_speed_fc_enc (gspeed);[ ... ]
Quoted 2 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +2
-0+/* Take out the clock from reset. Note this write will set all these +* fields to zero: [ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c line 292
Quoted 11 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_phylink.c new file +11
-0+* This linkspeed field has a slightly different encoding from others: +* +* - 0 is no-link +* - 1 is both 2500/1000 +* - 2 is 100mbit +* - 3 is 10mbit +* +*/ +lan_wr (DEV_CLOCK_CFG_LINK_SPEED_SET (fc_spd), + lan9645x, +DEV_CLOCK_CFG (p->chip_port));[Severity: Low]
fc_spdcomes fromlan9645x_speed_fc_enc(). That helper is documented as the PFC_CFG.FC_LINK_SPEED encoding, and it maps 2500 to 0:lan9645x_main.h:lan9645x_speed_fc_enc() { ... case LAN9645X_SPEED_2500: return 0; ... }The comment just above says this field uses a different encoding, where 0 means no-link. Should DEV_CLOCK_CFG.LINK_SPEED have its own encoding instead of reusing
fc_spd?For 10/100/1000 the two encodings agree.
SPEED_2500cannot reach this code today, becauselan9645x_phylink_get_caps()does not advertiseMAC_2500FDand the speed switch returns early for anything else.When 2500BASE-X support is added, would
DEV_CLOCK_CFGbe programmed as no-link? For reference, lan966x uses one encoding for both registers, with 2500 mapped to 1.[ ... ]
Quoted 6 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +0
-0@@ -0,0 +1,166 @@[ ... ]
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c line 62
Quoted 10 lines
drivers/net/dsa/microchip/lan9645x/lan9645x_port.c new file +10
-0+/* VLAN tag overhead is handled by DEV_MAC_TAGS_CFG */ +int lan9645x_port_set_maxlen (struct lan9645x *lan9645x,int port,size_t sdu) +{ +struct lan9645x_port *p =lan9645x_to_port (lan9645x, port); +int maxlen = sdu +ETH_HLEN +ETH_FCS_LEN ; + +if (port == lan9645x->npi) { + maxlen +=LAN9645X_IFH_LEN_BYTES ; + maxlen +=LAN9645X_LONG_PREFIX_LEN ; + }[Severity: Low]
Is
LAN9645X_LONG_PREFIX_LENneeded here?lan9645x_npi_port_init()configures injection with no prefix:lan_rmw(SYS_PORT_MODE_INCL_XTR_HDR_SET(LAN9645X_TAG_PREFIX_LONG) | SYS_PORT_MODE_INCL_INJ_HDR_SET(LAN9645X_TAG_PREFIX_NONE),
lan9645x_xmit()in the tag driver only pushes the 28-byte IFH. The long prefix is only used on extraction.
ocelot_port_set_maxlen()sizes the NPI MAXLEN from the injection prefix (npi_inj_prefix). IfDEV_MAC_MAXLEN_CFGworks the same way on this chip, the NPI port accepts frames 16 bytes longer than needed. The pause watermarks derived from 4 * maxlen and 6 * maxlen would also be slightly larger than intended.If MAXLEN here also limits frames sent with the extraction header, could a comment say why the extraction prefix is counted?
[ ... ]
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Wed, 11 Nov 2026 16:33:50 +0100 you wrote:
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.
[...]
Here is the summary with links:
- [net-next,v17,1/4] net: dsa: add tag driver for LAN9645X
https://git.kernel.org/netdev/net-next/c/4a7653aee5fd - [net-next,v17,2/4] dt-bindings: net: dsa: add Microchip LAN9645x switch https://git.kernel.org/netdev/net-next/c/4b4e23155b27 - [net-next,v17,3/4] net: dsa: lan9645x: add autogenerated register macros https://git.kernel.org/netdev/net-next/c/12748b403a6a - [net-next,v17,4/4] net: dsa: lan9645x: add basic dsa driver for LAN9645X https://git.kernel.org/netdev/net-next/c/8138a7745064
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html