This repository contains the source code provided by Realtek for the RTL8127 10GbE PCIe controllers.
The source code is provided by Realtek as-is, without any kind of changelog. Git is only used for tracking down the changes introduced between versions.
You can find the original files provided by Realtek here.
The same files from Realtek are provided as release assets.
Bug reports or issues should be reported directly to Realtek.
This repository is used for OpenWrt development because the files provided by Realtek are protected with CAPTCHAs and can't be used for creating OpenWrt packages.
The following patches are applied on top of the upstream Realtek source to fix PTP hardware timestamping on the RTL8127A. They were developed and validated on a Qualcomm DragonWing IQ-9075 running Linux 6.18.12 (aarch64).
Files: r8127.h, r8127_n.c, r8127_ptp.c, r8127_ptp.h
Hardware timestamping produced zero timestamps on every TX and RX packet despite
ptp4l successfully writing PTP_CTL = 0x103F via SIOCSHWTSTAMP.
PTP_INSR read back 0x0000 at every TX timeout, confirming the PHY capture
pipeline was never generating timestamp-ready interrupts.
The upstream driver wrote register 0xA640 BIT_15 (the PHY timestamp capture
engine arm bit) from within rtl8127_ptp_enable_config(), which is called from
the hwtstamp_enable(true) path that ptp4l triggers via SIOCSHWTSTAMP.
This caused two separate bugs:
-
Infinite link-drop loop. Writing
0xA640 BIT_15triggers a PHY autoneg restart, which drops the link. ptp4l monitors the link and callsSIOCSHWTSTAMPagain on each link-up event, which writes0xA640again, which drops the link again — repeating indefinitely. -
Capture engine never armed. The PHY only activates its internal timestamp pipeline when
0xA640 BIT_15is written whilePTP_CTLis already non-zero. When the link-drop loop was broken by removing0xA640from the enable path and moving it to the probe-timertl8127_ptp_reset(), the probe code calledhwtstamp_enable(false)first (leavingPTP_CTL = 0x0000), then wrote0xA640. The register write was accepted but the pipeline never activated (PTP_INSRremained0x0000).
rtl8127_ptp_reset() (called once at probe / hardware reset) now:
- Calls
hwtstamp_enable(false)to reach a clean state. - Calls
rtl8127_ptp_enable_config()underphy_lockto setPTP_CTL = 0x103F. - Writes
0xA640 BIT_15whilePTP_CTLis non-zero — the PHY arms the capture pipeline and then triggers an autoneg restart that resets all OCP registers (includingPTP_CTL) back to zero. - Sets
RTL_FLAG_PTP_ENGINE_ARMEDsohwtstamp_enable()never writes0xA640again after the engine has been primed.
When ptp4l calls SIOCSHWTSTAMP after the link comes back up, hwtstamp_enable(true)
re-writes PTP_CTL = 0x103F. Because the capture pipeline was already armed during
probe, PTP_INSR now correctly signals TX_TX_INTR on every egress PTP packet.
| Change | Reason |
|---|---|
hwtstamp_enable(disable) writes PTP_CTL = 0x0000 instead of clearing BIT_0 only |
Clearing only BIT_0 leaves the PHY in a partial PTP mode that causes the link partner to timeout and drop the link |
New rtl8127_ptp_link_up_init(), called from rtl8127_link_on_patch |
Re-writes PTP_CTL and PTP_INER after any link recovery while hwtstamp is enabled; the upstream code only called rtl8127_set_local_time() on link-up, which did not restore the PTP capture configuration |
hrtimer_init() + manual .function assignment → hrtimer_setup() |
hrtimer_setup() is the preferred API from kernel 6.15 onward |
Debug logging: INSR/TRX_STA/PTP_CTL readbacks on TX timeout and ingress path; all PTP log messages rate-limited with net_ratelimit() |
Aids diagnosis; netdev_warn_ratelimited() / netdev_info_ratelimited() are not present in all 6.x kernel builds |
0xA640 BIT_15must only be written at module probe or hardware reset — never fromhwtstamp_enable(). Writing it while a link partner is connected drops the link. If the write is repeated (e.g. from a link-up → SIOCSHWTSTAMP loop) the switch port can accumulate flap state and stay down for 120+ seconds.PTP_CTLmust be non-zero when0xA640 BIT_15is written — otherwise the PHY timestamp capture pipeline does not activate.
Validated on Qualcomm DragonWing IQ-9075, RTL8127A, kernel 6.18.12-aarch64:
ptp4l -i enP1p1s0 --step_threshold 1.0 --tx_timestamp_timeout 100 -m
ptp4ltransitions to MASTER and holds the role without TX timestamp timeouts.dmesgshowsPTP: TX_TX_INTR seenon every Sync/Announce egress (~1 Hz).- No link drops after
SIOCSHWTSTAMP;PTP_CTL readback = 0x103fconfirmed.