Skip to content

ramips: mt7620: add upstream MediaTek Ethernet support - #24557

Open
dormancygrace wants to merge 8 commits into
openwrt:mainfrom
dormancygrace:mt7620-upstream-ethernet
Open

dormancygrace wants to merge 8 commits into
openwrt:mainfrom
dormancygrace:mt7620-upstream-ethernet

Conversation

@dormancygrace

@dormancygrace dormancygrace commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Use the generic MediaTek Ethernet driver for the optional MT7620 DSA path. Existing swconfig profiles keep the Ralink driver. This builds on #24493; board migrations and PPE support (#24515) remain separate.

Changes

  • Add MT7620 probe, legacy PDMA descriptor translation, DSA metadata, reset/clock support and switch-child/IRQ teardown.
  • Share SoC identification through a built-in SoC-bus provider and soc_device_match(). Report MT7620A/N and decimal version/ECO, retaining the existing MT7628/MT7688 registration.
  • Enable RX checksum offload on all MT7620 revisions. Gate IPv4/IPv6 TX checksum, SG, TSO and TSO6 on ECO >= 5; honor the RX-checksum feature when accepting parsed checksums.
  • Program GDMA jumbo fields from the MTU; retain integrated-switch PHY interrupts and hardware mirroring.
  • Enable PDMA CTAG insertion through the Ralink tagger. Reserve slot 0 for VID 0 and pin other CDMA slots until driver removal. Colliding VIDs and DEI=1 use software insertion.
  • Expose twelve CPU GDM1 hardware counters with 64-bit accumulation and one-second polling. Keep rtnetlink skb counts separate from hardware packet counts, which can include TSO segments; preserve totals across close/open.
  • Allocate legacy-NETSYS DSA metadata before PHY/DMA startup. If MT7620 DMA remains busy after the stop timeout, reset FE before freeing rings. Restore RX/TX interrupt moderation, CDMA assignments and checksum parsing before DMA is enabled.
  • Make kmod-dsa-mt7620 select the modular FE and required PCS support.

The corresponding net-next preparation includes the VLAN port and switch-counter cadence. Its new TX registration API requires subsystem review; Linux v7 hardware validation remains pending.

Validation

After rebasing on current OpenWrt main, the series passes a fresh ramips/mt7620 kernel/module build against Linux 6.18.54, native prepare and two refresh runs without patch changes. The changed SoC, FE, DSA and tagger objects pass W=1 and Werror; the generic and legacy FE paths also compile at every commit in the series. Sparse comparison found no new warning classes or affected driver functions; existing baseline warnings remain.

The delay-interrupt recovery change passes the fresh kernel/module build and W=1/Werror FE compilation. An ASan/UBSan fixture extracts the real stop/start and DIM helpers, models FE reset, and checks 25 RX/TX profile pairs, ordinary close, DMA initialization failure and non-MT7620 controls. MMIO and reset APIs are mocked; this is not hardware failure injection. Sparse warnings match the preceding source under identical commands. Embedded patch sign-offs now match their owning commits.

The hardware tests below were performed before this rebase on WE826-T2, MT7620A version 2 / ECO 6, Linux 6.18.44, with FE and DSA loaded as modules. Those runtime tests have not been repeated on 6.18.54 or with the later delay-interrupt recovery fix.

  • 50 IPv4/IPv6 ICMP and bidirectional TCP/UDP checks for VID 0, 400, 401, 417 and 402, with wire VID/PCP verification and registered CDMA slots 401/402.
  • 256 captured frames covering mapped and colliding VIDs, all PCP values and both DEI values, with TX insertion enabled and disabled; no tag mismatch.
  • Eight VLAN deletion/recreation cycles under traffic and conduit close/open with DSA user ports restored; the pinned map remained intact.
  • Hardware/rtnetlink counter growth, TSO and RX-checksum toggles, stable cached totals while down and monotonic totals across close/open.

The author also hardware-tested D-Link DWR-921 C3 (MT7620N), confirming operation comparable to MT7620A. The detailed test counts above are from WE826-T2.

These are short correctness tests. Older ECO-specific coverage, external Realtek switches, forced busy-DMA failure, sustained line rate and QinQ remain untested. Earlier jumbo/mirroring/performance results are recorded in the historical comments; this update does not add runtime coverage for them or PPE.

Prior work: 2021 MT7620 DSA/PPE discussion, 2025 MediaTek Ethernet cleanup series.

@openwrt openwrt Bot added kernel pull request/issue with Linux kernel related changes target/ipq40xx pull request/issue for ipq40xx target target/qualcommax pull request/issue for qualcommax target target/ramips pull request/issue for ramips target target/realtek pull request/issue for realtek target labels Aug 3, 2026
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch 3 times, most recently from 958ede4 to 03ee341 Compare August 5, 2026 10:22

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • 03ee3414 "ramips: mt7620: add upstream MediaTek Ethernet support" — the message says "Keep the legacy Ralink Ethernet path available for swconfig profiles. The optional kmod-dsa-mt7620 package selects the generic MediaTek driver", but the diff sets CONFIG_NET_MEDIATEK_SOC=y in target/linux/ramips/mt7620/config-6.18, which builds the generic driver into every mt7620 image regardless of whether the package is selected, and prevents mtk_eth.ko from ever being built as a module. Details inline.
  • 03ee3414 — the message does not mention that the patch renames the generic MediaTek platform driver from mtk_soc_eth to mtk_eth_upstream. That is a cross-target change (the patch lives in target/linux/ramips/patches-6.18/, so it also hits mt7621) with a user-visible side effect outside this SoC; it deserves a line in the message even if the inline concern is resolved differently.

Note on scope: 5 of the 6 commits here are the stacked series from #24493, and this PR carries no prior review, so the whole branch was in scope. The inline comments are all on 03ee3414, this PR's own contribution; the earlier commits' messages match their diffs (including the deliberately-scoped patch-offset refreshes in 7c086e6f and 976de981).

CI on 03ee34147ea9a8cef0f06662d62518c82c5328ef reports no completed checks, so nothing was grounded in build logs.


Generated by Claude Code

Comment thread target/linux/ramips/mt7620/config-6.18 Resolved
Comment thread target/linux/ramips/modules.mk Resolved
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch 2 times, most recently from 4a0241d to 3d2e6aa Compare August 5, 2026 23:17

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 3d2e6aa1. The five earlier commits are byte-identical to the previously reviewed revision (same git patch-id), so only 3d2e6aa1 was in scope. The four points from the last round are addressed: CONFIG_NET_MEDIATEK_SOC is now is not set in the target config, CONFIG_PCS_MTK_LYNXI is listed explicitly in KernelPackage/dsa-mt7620, patches 337–339 are folded into 336, and the generic driver keeps its upstream mtk_soc_eth platform-driver name.

I checked the packaging consequence of NET_MEDIATEK_SOC=m on mt7620: PHYLINK is covered by kmod-dsa's +kmod-phylink, DIMLIB is already =y from target/linux/generic/config-6.18:1483, and PAGE_POOL_STATS/GENERIC_ALLOCATOR are bool, so no unshipped .ko results. I also confirmed the legacy-driver rename does not affect packet-steering.uc: that driver adds NAPI directly on the netdev (netif_napi_add_weight(netdev, &priv->rx_napi, ...)), so the napi/mtk_eth- branch never applied to it, and the generic napi/<netdev>-N branch still matches.

Commit checks

  • 3d2e6aa1 "ramips: mt7620: add upstream MediaTek Ethernet support" — the message says "Give only its MT7620 build a distinct platform-driver name", but the guard added to the legacy driver is #ifdef CONFIG_SOC_MT7620, which is also =y on the mt76x8 subtarget. As written the rename applies to MT7628/MT7688 builds too. Details inline.

CI on 3d2e6aa17e7cef147209905f49fc10d16e240d75 is green across all three workflow runs (Build PR Profile, Build Kernel, Build all core packages), so nothing here is grounded in build logs.


Generated by Claude Code

@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch 3 times, most recently from c366f45 to b40b2f1 Compare August 7, 2026 20:25
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Synced this series onto the current #24493 head and restored the offloads provided by the legacy MT7620 Ethernet driver. IPv4 TX/RX checksum is enabled on all revisions; ECO 5 and newer additionally advertise SG, TSO, TSO6 and IPv6 TX checksum. Hardware VLAN insertion remains disabled pending separate validation. The combined Ethernet + DSA + PPE tree applies with zero fuzz and completes a clean ramips/mt7620 kernel build. The PR description now includes the live feature verification and IPv4/IPv6 throughput results.

@namiltd

namiltd commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

I noticed the commit: "ramips: mt7620: restore Ethernet offloads". I'm curious what performance impact this has on routers with an external switch via RGMII. Are there any throughput/CPU-load numbers before and after this change?

Edit: if the downstream chip is a Realtek switch attached via DSA, this patch changes nothing for that traffic. RTL8_4 disables the offload path via mtk_features_check() clearing NETIF_F_CSUM_MASK/NETIF_F_GSO_MASK, and RTL8_4T disables it because the tagger already checksums in software before this driver sees the frame (ip_summed is no longer CHECKSUM_PARTIAL). Either way, SG/TSO/TSO6/IPv6-checksum never engage regardless of the ECO ≥5 gate added here.

@dormancygrace

Copy link
Copy Markdown
Contributor Author

@namiltd Your edit matches my reading. I am not claiming a benefit for traffic traversing an external Realtek DSA switch with RTL8_4 or RTL8_4T: the tagger path removes or consumes the relevant checksum/GSO state before the MT7620 driver can use these features.

The measurements in the PR are from the native integrated MT7620 switch path only. On that path, a local-originating IPv4 TCP test at about 93--94 Mbit/s reduced router CPU busy from 64.7% with SG/TSO disabled to 45.0% with them enabled. For IPv6, TSO6 reduced CPU busy from 56.8% to 48.1% at 92--93 Mbit/s. RX checksum was exercised without errors, although the receive-side test saturated the CPU in both modes and did not provide a useful performance delta.

I will keep the external RGMII/Realtek limitation explicit in the PR description. Supporting that path would require tagger-specific work and hardware validation rather than another MT7620 feature bit. The new GDMA jumbo change I am validating is likewise for the integrated-switch path; I will not present it as external-switch coverage.

@dormancygrace

Copy link
Copy Markdown
Contributor Author

Added 13bc77d82a to fix the remaining integrated-switch jumbo receive limit. MT7620 GDMA1 now follows ndo_change_mtu: GDM1_FWD_CFG changes from 0x20710000 at MTU 1500 to 0x20790000 at MTU 2026 and returns when the MTU is lowered.

This is the same code already exercised in the flashed WE826 integration image. Untagged IPv4 and IPv6 passed bidirectionally at IP MTU 2026; tagged VLAN 400 passed bidirectionally at IP MTU 2024, which is the MikroTik peers fixed limit. The new patch was normalized by two consecutive target/linux/refresh runs, strict checkpatch reports no findings, and a clean ramips/mt7620 Linux 6.18.41 build completed with GCC 14.4.

The PR body now also makes the external RGMII/Realtek limitation explicit, as discussed above.

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 13bc77d8, against my last review at 3d2e6aa1. The first five commits are byte-identical to the previously reviewed revision (same git patch-id), so the scope was: the reworked 2e86ff85 ("add upstream MediaTek Ethernet support"), plus the two new commits b40b2f19 and 13bc77d8.

The only change inside 2e86ff85 versus 3d2e6aa1 is the added eth->netdev[0] NULL guard before netif_keep_dst() / mtk_dsa_metadata_init() — good, and it does not invalidate the previous round's conclusions. The CONFIG_SOC_MT7620-vs-mt76x8 rename concern I raised last time is gone with the rename itself.

I checked b40b2f19 against the legacy driver it restores: NETIF_F_IP_CSUM | NETIF_F_RXCSUM plus the mt7620_get_eco() >= 5 gate for SG/TSO/TSO6/IPV6_CSUM matches mt7620_init_data() exactly, minus the deliberately-omitted `NETIF_F_HW_VLAN_CTAG_TX`, and the `vlan_features`/`features` derivation matches [the legacy probe](https://github.com/openwrt/openwrt/blob/13bc77d82a4fc1ccb73502b540116397a416e605/target/linux/ramips/files/drivers/net/ethernet/ralink/mtk_eth_soc.c#L1635-L1638).`` The descriptor bits line up too: TX_DMA_CHKSUM (0x7 << 29) / TX_DMA_TSO BIT(28) are identical in both drivers and do not collide with MT7620_TX_DMA_FP_BMAP (27:20), and MT7620_RX_DMA_L4_VALID BIT(23) matches the legacy MT7620_L4_VALID. mt7620_get_eco() is a static inline in asm/mach-ralink/mt7620.h, so the new include adds no link dependency for the other ramips subtargets that build this driver. No findings there.

For 13bc77d8 I also checked the RX-buffer side: mtk_max_frag_size() floors at MTK_MAX_RX_LENGTH_2K, so ring->buf_size >= 2048 regardless of MTU and raising the GDMA limit cannot overrun the RX buffers. The one issue I found is that the jumbo programming is not re-applied after a frame-engine reset — details inline.

Commit checks

  • 13bc77d8 "ramips: mt7620: enable GDMA jumbo frames" — the message says the "jumbo enable and length fields" are updated "from ndo_change_mtu", but only the enable bit is derived from the MTU; MT7620_GDMA_JMB_LEN is written as a constant 2 (2 KB) irrespective of new_mtu. The legacy driver did derive it, DIV_ROUND_UP(frag_size, 1024) (mtk_eth_soc.c:1614-1624).`` A constant 2 is defensible since max_mtu is `MTK_MAX_RX_LENGTH_2K - MTK_RX_ETH_HLEN` = 2030, but the message overstates what the code does. Minor, in the same commit: the body is written one sentence per paragraph, unlike the other seven commits in the series.

CI on 13bc77d82a4fc1ccb73502b540116397a416e605 was still running at review time (no failed check runs), so nothing here is grounded in build logs.


Generated by Claude Code

@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 13bc77d to abbf92f Compare August 8, 2026 04:17
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Added 136ca5dc85 with the remaining hardware features validated on the flashed WE826: aggregate switch PHY IRQ (irq=MAC), DSA ingress/egress mirroring, and MT7620 PDMA TX VLAN insertion with safe software fallback on a CDMA slot collision. The ported Linux 6.18.41 tree completes a clean ramips/mt7620 build; the raw driver diff passes strict checkpatch with no findings. No generic netfilter/flowtable patch is included, so stacked flow offload keeps the existing two-VLAN limit.

@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch 2 times, most recently from 7bf89c8 to b5329cb Compare August 8, 2026 16:29
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Rebased to b5329cbe80 to correct the jumbo commit evidence and make the VLAN-TX header hunk independent of the optional PPE reset field. The 0x20710000 value was from the integration tree retaining the legacy residual length; the submitted code clears both jumbo fields at MTU 1500. The corrected Ethernet tree prepares cleanly on Linux 6.18.41.

@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from b5329cb to 8302148 Compare August 8, 2026 21:56
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Refreshed the MT7620 VLAN-TX kernel patch against the current series and force-updated the branch to 8302148f39.

Validation:

  • make target/linux/compile -j12 V=s: pass for ramips/mt7620;
  • a second make target/linux/refresh V=s: clean tree;
  • FormalityCheck: all three jobs pass.

The ramips/mt7620 upstream kernel jobs are now queued on the refreshed head.

@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 8302148 to ff10d56 Compare August 8, 2026 22:32
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Rebased onto the refreshed DSA head/current main. This incorporates the exact Realtek rtl838x context correction identified by the previous kernel-matrix failure. Validation on the resulting stack: target/linux/clean, target/linux/refresh, a clean git diff after refresh, and full ramips/mt7620 target/linux/compile all passed.

dormancygrace added a commit to dormancygrace/openwrt that referenced this pull request Sep 8, 2026
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 39356b8 to 7ff466b Compare September 8, 2026 16:27

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 amended commit; no new issues found.


Generated by Claude Code

@dormancygrace

dormancygrace commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

VLAN hardware validation for revision 7ff466bb3927 on 2026-10-01: WE826-T2, MT7620A version 2 / ECO 6, Linux 6.18.44, modular FE and DSA.

  • VID 0, 400, 401, 417 and 402 at PCP 5 passed 50 IPv4/IPv6 ICMP and bidirectional TCP/UDP checks. Captures verified VID/PCP/TPID. Standalone DSA VLAN uppers left nonzero CDMA slots empty, so those nonzero VIDs exercised software fallback.
  • DSA bridge host VLAN membership registered CDMA slots 401/402. Colliding VID 417 did not replace 401. Concurrent UDP on 401/417 survived eight remove/re-add cycles of host VID 401 with zero reported packet loss and no captured tag mismatch.
  • Conduit close/open preserved the CDMA map; both VLANs passed ping after restoring the DSA user ports. DSA closes those ports when the conduit goes down, so raising only the conduit is insufficient.
  • After bridge membership removal, the pinned 401/402 entries remained. A further 30 IPv4/IPv6 ICMP and bidirectional TCP/UDP checks on 401/417/402 passed, including wire-tag checks.

All 80 functional checks passed. These short paced tests do not establish line-rate performance or coverage of MT7620N, older ECOs, forced hardware reset, all PCP values or QinQ. TX descriptors were not instrumented; path selection was checked from source, feature state and the registered map.

Testing/report preparation assisted by Codex (OpenAI GPT-6).

dormancygrace added a commit to dormancygrace/openwrt that referenced this pull request Oct 1, 2026
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

Use the shared mt7620a/mt7620n identity for package-specific embedded-PHY
tuning in both legacy and upstream paths. Propagate missing-identity errors
and release the switch-device reference. Remove the unused revision offset;
the actual PHY tuning values and mode-control syscon accesses are unchanged.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.
Register only 802.1Q VIDs, and use software insertion for DEI=1 because the
descriptor has no DEI bit. Preserve PCP, VID and DEI in software fallback.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 7ff466b to ea67885 Compare October 1, 2026 20:56
@openwrt openwrt Bot added the not following guidelines Pull request does not follow formatting guidelines label Oct 1, 2026
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from ea67885 to 7d21f55 Compare October 1, 2026 21:01
@openwrt openwrt Bot removed the not following guidelines Pull request does not follow formatting guidelines label Oct 1, 2026
dormancygrace added a commit to dormancygrace/openwrt that referenced this pull request Oct 1, 2026
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

Use the shared mt7620a/mt7620n identity for package-specific embedded-PHY
tuning in both legacy and upstream paths. Propagate missing-identity errors
and release the switch-device reference. Remove the unused revision offset;
the actual PHY tuning values and mode-control syscon accesses are unchanged.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.
Register only 802.1Q VIDs, and use software insertion for DEI=1 because the
descriptor has no DEI bit. Preserve PCP, VID and DEI in software fallback.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 7d21f55 to 4017ad9 Compare October 1, 2026 21:23
@dormancygrace

Copy link
Copy Markdown
Contributor Author

@dangowrt Following your recommendation to send the Ethernet changes to net-next, could you review the current series in this PR and the MT7620 integration v7 before I submit the Ethernet patches to netdev? The latest changes cover VLAN TX, checksum handling, shared SoC/ECO identification and counters.

Integration and validation notes. Linux v7 hardware validation is still pending.

dormancygrace referenced this pull request in dormancygrace/net-next Oct 1, 2026
The early metadata allocation used by MT7620 also ran for newer NETSYS
devices, although their original open path returned before allocation.
Retain the original NETSYS generation condition while allocating metadata
before PHY connection and DMA startup on the legacy path. An allocation
failure must not prevent a newer NETSYS device from opening when those
metadata destinations are unused.

The extracted open function reproduces an unexpected -ENOMEM with a
newer NETSYS configuration and forced metadata allocation failure. The
guard preserves the MT7620 error unwind and restores the newer behavior.

Fixes: cb00ac4 ("net: ethernet: mediatek: carry MT7620 DSA ports in DMA metadata")
Assisted-by: LLM [sparse]
dormancygrace added a commit to dormancygrace/openwrt that referenced this pull request Oct 1, 2026
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

Use the shared mt7620a/mt7620n identity for package-specific embedded-PHY
tuning in both legacy and upstream paths. Propagate missing-identity errors
and release the switch-device reference. Remove the unused revision offset;
the actual PHY tuning values and mode-control syscon accesses are unchanged.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.
Register only 802.1Q VIDs, and use software insertion for DEI=1 because the
descriptor has no DEI bit. Preserve PCP, VID and DEI in software fallback.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from 4017ad9 to f50f591 Compare October 1, 2026 23:42

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit checks

  • 68fbd142 "ramips: mt7620: expose frame-engine traffic counters": the message says it will "drain counters before DMA stops", but the final mt7620_stats_read() in mtk_stop() runs after mtk_stop_dma(). Only the polling cancel happens before. The patch body ("drain remaining counters on close") gets this right.

Generated by Claude Code

dormancygrace added a commit to dormancygrace/openwrt that referenced this pull request Oct 2, 2026
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

Use the shared mt7620a/mt7620n identity for package-specific embedded-PHY
tuning in both legacy and upstream paths. Propagate missing-identity errors
and release the switch-device reference. Remove the unused revision offset;
the actual PHY tuning values and mode-control syscon accesses are unchanged.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.
Register only 802.1Q VIDs, and use software insertion for DEI=1 because the
descriptor has no DEI bit. Preserve PCP, VID and DEI in software fallback.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
@dormancygrace
dormancygrace force-pushed the mt7620-upstream-ethernet branch from f50f591 to fc5f4ef Compare October 2, 2026 07:59
The generic MediaTek Ethernet driver describes MT7620, but cannot probe the
current ramips device tree and lacks the legacy PDMA handling required by the
Ralink DSA metadata tagger.

Add MT7620 probe, reset, clock, DMA and integrated-switch handoff support.
Copy DSA TXD4 metadata into the descriptor consumed by legacy PDMA and keep
RX switch source-port metadata on GMAC0 as the conduit.

Reset the software TX producer cursor when PDMA restarts. Initialize DSA RX
metadata before registering the conduit and order probe, remove and IRQ
handling so repeated close/open cycles and modular teardown remain safe.
Keep these corrections in the initial MT7620 kernel patch instead of adding
introduce-then-fix patches in the same Git commit.

Add a built-in SoC bus provider sharing the MTMIPS clock/reset syscon regmap.
Publish mt7620a/mt7620n and decimal silicon version.ECO before driver probes,
and require an identified model in the generic FE probe. Skip the duplicate
architecture registration only on MT7620A/N, preserving MT7628/MT7688.
Select the provider for SOC_MT7620 and retain the existing legacy helpers.

Keep the legacy Ralink Ethernet path available for swconfig profiles during
the staged migration. Give only its MT7620 build a distinct platform-driver
name, preserving the generic driver's upstream mtk_soc_eth name and existing
packet-steering behaviour on MT7621. Retain an opt-in MT7620 compatible for
the generic path because the built-in legacy and modular generic drivers must
coexist until individual boards migrate; sharing a compatible would let the
legacy driver claim the node first.

Leave NET_MEDIATEK_SOC disabled in the target config so the optional
kmod-dsa-mt7620 package can select it as a module. Explicitly select and ship
the LynxI PCS module required by the generic driver's Kconfig dependencies.
Declare the conduit pointer with the initial switch lifecycle support,
so cleanup builds before the later switch offload additions.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
Keep receive checksum offload on all MT7620 revisions, but restrict IPv4
and IPv6 transmit checksums, scatter-gather, TSO and TSO6 to ECO 5 or later.
The early-ECO workaround applies to IPv4 TX checksums as well as the other
transmit offloads; the legacy driver's broader IPv4 advertisement should
not be copied into the generic driver.

Match the model and decimal version.ECO published by the preceding shared
SoC provider, including both one-digit ECOs 5--9 and two-digit ECOs 10--15.
Do not read architecture-specific registers in the network driver.

The generic MediaTek paths already program and parse the corresponding
legacy PDMA descriptor bits. VLAN insertion is enabled separately by the
later switch-feature commit.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
The integrated switch accepts frames up to 2048 bytes, but GDMA1 remains
limited to 1518 bytes unless its jumbo fields are programmed.

Update the jumbo enable and length fields from ndo_change_mtu. This lets DSA
user ports use the advertised maximum MTU and returns GDMA1 to standard mode
when the MTU is lowered. This revision only refreshes the patch coordinates
after the preceding SoC and offload changes; jumbo behavior is unchanged.

Earlier integration tests on a ZBT-WE826 passed bidirectional IPv4 and IPv6
at IP MTU 2026 with GDM1_FWD_CFG 0x20790000. Those measurements predate this
SoC-provider revision. At standard MTU, both jumbo fields are cleared;
the length field is irrelevant while jumbo mode is disabled.

Signed-off-by: Gleb Pesin <[email protected]>
Complete the upstream Ethernet conversion with PHY link interrupts,
DSA hardware mirroring and PDMA VLAN insertion.

Let embedded PHY user ports take negotiated link, speed, duplex and pause
from PPSC. Clear PMCR_FORCE in the link callbacks and remove software
programming of those parameters, including the obsolete speed helper.

Select MAC-managed PHY interrupts before DSA registration and program the
switch PHY polling range for the embedded PHYs. Enable link interrupts
after user PHY attachment. Resynchronize already-up and reopened PHYs with
delayed work, restarting autonegotiation where enabled. Quiesce the IRQ
before cancelling that work and restore PHY polling on teardown.

Support ingress and egress mirroring with a single shared destination,
and disable the mirror engine when its last source is removed.

Use the shared mt7620a/mt7620n identity for package-specific embedded-PHY
tuning in both legacy and upstream paths. Propagate missing-identity errors
and release the switch-device reference. Remove the unused revision offset;
the actual PHY tuning values and mode-control syscon accesses are unchanged.

MT7620 TX descriptors encode a VLAN table index rather than a full VID.
Keep each assigned mapping until device removal so table updates cannot
retag an skb already past the feature check or a descriptor owned by DMA.
Reserve slot 0 for priority-tagged VID 0. Other slots retain their first
VID; aliases use software insertion even after that VID is removed.
Restore the same table on FE reset. Use ordered MMIO and a readback before
publishing a newly assigned slot to the lockless feature check.
Register only 802.1Q VIDs, and use software insertion for DEI=1 because the
descriptor has no DEI bit. Preserve PCP, VID and DEI in software fallback.

Extend the ramips-local Ralink metadata tagger so DSA user ports inherit
VLAN TX offload from capable conduits. Keep the generic flowtable and its
two-VLAN limit unchanged. Publish the conduit only after MDIO succeeds,
and keep registration failure cleanup in one block.

Pass the shared switch pointer to the DSA child as copied platform data
and validate it in both probe and remove. Propagate IRQ lookup failures.

The conduit VLAN references added here rely on the teardown order
established by the earlier Ethernet-support commit: the DSA child is
unregistered before the conduit is cleared, so port_vlan_del() can call
vlan_vid_del().

Link: openwrt#24557 (comment)
Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
The MT7620 FE statistics path currently returns zero. Backport the
twelve CPU GDM1 clear-on-read registers and protected 64-bit totals from
the Linux integration, with one-second polling while open and cached
queries while down. Cancel polling before DMA stops and drain the final
counters on close.

Keep rtnetlink RX and completed-TX skb counts separate from hardware
counts, which include segmentation and parser errors. Report twelve
MT7620 ethtool counters; existing switch port MIBs stay independent.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
The receive parser can remain enabled after ethtool disables RX checksum
offload. Require NETIF_F_RXCSUM before trusting its result and marking
an skb CHECKSUM_UNNECESSARY. Backport the Linux integration condition so
disabling this feature lets the network stack verify checksums.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
RX metadata allocation can fail after DMA, NAPI and queues have started.
Backport allocation before PHY connection and DMA startup so an error
leaves the conduit closed. Preserve the original legacy NETSYS guard;
newer NETSYS devices do not use these destinations and must not depend
on their allocation.

Extracted open-function checks cover metadata, PHY and DMA failures and
verify that a newer NETSYS open ignores forced metadata ENOMEM. Resource
APIs are mocked; this is not hardware allocation-failure injection.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
Backport the Linux integration FE-reset fallback when MT7620 DMA stays
busy after the bounded stop wait. Drain clear-on-read statistics before
resetting FE and freeing descriptor rings.

Restore RX/TX interrupt moderation, pinned CDMA VLAN assignments and
the checksum parser before every DMA start. FE reset clears registers
while software assignments and accumulated statistics survive. GDMA setup then restores
MTU and forwarding before queues start.

Assisted-by: Codex (OpenAI GPT-6)
Signed-off-by: Gleb Pesin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel pull request/issue with Linux kernel related changes target/ipq40xx pull request/issue for ipq40xx target target/qualcommax pull request/issue for qualcommax target target/ramips pull request/issue for ramips target target/realtek pull request/issue for realtek target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants