Fix PTP teardown and Time Card DPLL operations
v4 cover Fix PTP teardown and Time Card DPLL operations
This series fixes timestamp teardown and existing ptp_ocp DPLL behavior. It contains no WiWi board support and targets net.
Changes since v3:
- Follow Vadim's channel/pin distinction explicitly: send PTP_CLK_REQ_EXTTS disable requests for timestamp channels directly, without using ptp_disable_pinfunc(). Keep that helper for actual pin configuration. Preserve cleanup after user-interface removal, shared PPS handling, and final IRQ draining without a new driver lock.
- Handle combined input destinations in the DPLL frequency getter. Report a known frequency only when the frequency-bearing destinations agree; report zero for unconstrained, conflicting or unknown routes. Output selectors still require an exact match.
- Recover disconnected SMA state from mux enable bits at initialization. Neither buffer enabled is represented as IN: None, since hardware does not retain a direction for that state. Do not write the mux or change fixed-direction firmware behavior. Explain the ADVA X1 failure too.
- Add a separate fifth patch for the ART 10 MHz input table typo.
- Keep patch-specific explanations and brief validation statements in the changelogs; move detailed testing/revision notes below the separator. Keep the trailer blocks contiguous.
Patch 4's DCF correction is unchanged and retains Vadim's Reviewed-by. Patches 2 and 3 changed substantially, so their earlier review tags are not carried forward. They need fresh review.
Validation:
- Reproduced combined-input, ART-frequency and rebind failures against the previous candidate using source-derived ASan/UBSan tests.
- Repeated teardown/shared-PPS tests 100 times; checked all six channels, unassigned/zero pins, concurrent requests and active IRQ draining.
- Tested 4,669 input masks and 243 four-connector rebind configurations, plus actual DPLL core get-before-set and supported-frequency checks.
- Rejected 16 deliberate regressions with runtime assertions.
- Built the PTP subtree for x86_64/i386, allmodconfig and allyesconfig, with W=1 KCFLAGS=-Werror.
- Ran five PTP cleanup KUnit cases using real core register/unregister in QEMU with KASAN and lockdep. No physical-card test is claimed.
This replaces the previous four-patch common-driver series. The separate WiWi support series will follow for net-next after these fixes are in.
Previous series:
https://lore.kernel.org/r/[email protected]
Review prompting the explicit timestamp requests:
https://lore.kernel.org/r/[email protected]
Additional DPLL, rebind and ART reports:
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
As required by generated-content.rst, Codex assisted with the code, tests and changelogs in response to review. This does not replace personal DCO certification or hardware validation.
Ahmad Byagowi (5):
ptp: disable all timestamp channels after removing the user interfaces
ptp: ocp: handle hardware selectors and combined DPLL input routes
ptp: ocp: preserve disabled SMA inputs across driver rebind
ptp: ocp: correct the DCF output frequency
ptp: ocp: correct the ART 10 MHz input frequency
drivers/ptp/ptp_chardev.c | 14 ++++++---- drivers/ptp/ptp_ocp.c | 58 ++++++++++++++++++++++++++------------- 2 files changed, 48 insertions(+), 24 deletions(-)
base-commit: af6737b9066832a2017c281159950ba92385ce00
PATCH v4 1/5 ptp: disable all timestamp channels after removing the user interfaces
PTP_EXTTS_REQUEST and extts_enable can enable channels without assigning a PTP_PF_EXTTS pin. ptp_disable_all_events() only visits assigned pins, so those channels can still generate events after the clock is released. ptp_ocp exposes six timestamp channels but only four SMA pin descriptors; the internal GNSS and PHC timestamp sources do not need an SMA assignment.
Disable each advertised external timestamp channel, followed by the existing PPS disable, after posix_clock_unregister() has removed sysfs and drained active ioctls. Keep the pin configuration unchanged.
Remove ptp_ocp's preliminary timestamp-disable loop. It runs before the user interfaces are removed and can race with an enable: the enable sets pps_req_map, detach clears it and disables the source, then the enable rearms the source. Both later subscription disables can consequently see an empty map and skip the hardware shutdown. With shutdown delegated to the core, requests finish before the final disables and IRQ drains. Keep the existing resource cleanup for probe failures without a clock.
Do not skip the shared PPS source's register disable when the final subscription map is empty. An overlapping extts_enable sysfs request and ioctl can leave an empty map with the source enabled. Once both interfaces are drained, the core's final disables must still mask and drain the IRQ. Preserve the shortcut while another PPS or EXTTS subscription remains.
Issue PTP_CLK_REQ_EXTTS requests directly for timestamp channel indices. Do not use the pin-function helper or require a pin assignment. Keep the pin-function helper for changes to actual pin configuration.
Source-derived tests with stubbed MMIO and IRQ operations reproduce the early-disable/map race and pass with this fix. Core unregister tests also pass in QEMU with KASAN and lockdep. No physical card was tested.
The issue was reported by the Sashiko review. Codex assisted with the code, tests and changelog in response to that report and Vadim's review.
---
Changes in v4:
- Issue timestamp disable requests directly, as requested by Vadim; leave ptp_disable_pinfunc() for pin configuration.
- Move review-only testing details out of the commit message.
Testing: 100 ASan/UBSan teardown/shared-PPS suite runs, including late and in-flight enables, concurrent sysfs/ioctl requests, all six channels, zero/unassigned pins, absent channels and active IRQ draining. Seven deliberate cleanup regressions were rejected. Five core register/unregister KUnit cases ran in QEMU with KASAN and lockdep. No physical card was used.
drivers/ptp/ptp_chardev.c | 14 +++++++++----- drivers/ptp/ptp_ocp.c | 17 ++--------------- 2 files changed, 11 insertions(+), 20 deletions(-)
drivers/ptp/ptp_chardev.c +9 -5
@@ -53,11 +53,15 @@ void ptp_disable_all_events(struct ptp_clock *ptp)unsigned int i;mutex_lock (&ptp->pincfg_mux); -/* Disable any pins that may raise EXTTS events */ -for (i =0 ; i < info->n_pins; i++) -if (info->pin_config[i].func ==PTP_PF_EXTTS ) -ptp_disable_pinfunc (info, info->pin_config[i].func, - info->pin_config[i].chan); +/* EXTTS requests do not require a pin assignment. */ +for (i =0 ; i < info->n_ext_ts; i++) { +struct ptp_clock_request req = { + .type =PTP_CLK_REQ_EXTTS , + .extts.index = i, + }; + + info->enable (info, &req,0 ); + }/* Disable the PPS event if the driver has PPS support */ if (info->pps) {
drivers/ptp/ptp_ocp.c +2 -15
@@ -2559,8 +2559,8 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)else bp->pps_req_map &= ~req; -/* if no state change, just return */ -if ((!!old_map ^ !!bp->pps_req_map) ==0 ) +/* Skip the register update while a subscription remains. */ +if (old_map && bp->pps_req_map)return 0 ; }
@@ -5755,19 +5755,6 @@ ptp_ocp_detach(struct ptp_ocp *bp)ptp_ocp_detach_sysfs (bp);ptp_ocp_attr_group_del (bp);timer_delete_sync (&bp->watchdog); -/* Disable interrupts on all timestampers */ -if (bp->ts0) -ptp_ocp_ts_enable (bp->ts0,0 , false); -if (bp->ts1) -ptp_ocp_ts_enable (bp->ts1,0 , false); -if (bp->ts2) -ptp_ocp_ts_enable (bp->ts2,0 , false); -if (bp->ts3) -ptp_ocp_ts_enable (bp->ts3,0 , false); -if (bp->ts4) -ptp_ocp_ts_enable (bp->ts4,0 , false); -if (bp->pps) -ptp_ocp_ts_enable (bp->pps, ~0 , false);if (bp->ptp)ptp_clock_unregister (bp->ptp);kfree (bp->ptp_info.pin_config);
[email protected]
AI reviewRe: [PATCH net v4 1/5] ptp: disable all timestamp channels after removing the user interfaces
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Nothing serializes the two callers of ptp_ocp_ts_enable() (drivers/ptp/ptp_ocp.c).
- [Low] ptp_disable_all_events() (drivers/ptp/ptp_chardev.c) now sends PTP_CLK_REQ_EXTTS with on=0 to every channel below info->n_ext_ts,…
--
I found two possible regressions in commit 9b634abf9770 (ptp: disable all timestamp channels after removing the user interfaces). One is a runtime race on the shared PPS source in ptp_ocp_ts_enable() that the narrowed shortcut opens up. The other is a teardown side effect on sja1105, where the new blanket EXTTS disable changes the pin direction.
ptp: disable all timestamp channels after removing the user interfaces
This patch changes ptp_disable_all_events() to send an EXTTS disable to every channel below n_ext_ts, not only to pins assigned to PTP_PF_EXTTS. It removes the early timestamper disable loop from ptp_ocp_detach(). It also narrows the pps_req_map shortcut in ptp_ocp_ts_enable() so that a disable with an empty map still reaches the registers.
Quoted 12 lines
drivers/ptp/ptp_chardev.c +0
-4@@ -53,11 +53,15 @@ void ptp_disable_all_events(struct ptp_clock *ptp)unsigned int i;mutex_lock (&ptp->pincfg_mux); -/* Disable any pins that may raise EXTTS events */ -for (i =0 ; i < info->n_pins; i++) -if (info->pin_config[i].func ==PTP_PF_EXTTS ) - ptp_disable_pinfunc(info, info->pin_config[i].func,
drivers/ptp/ptp_chardev.c void ptp_disable_all_events(struct ptp_clock *ptp) · line 64
Quoted 10 lines
drivers/ptp/ptp_chardev.c +9
-1- info->pin_config[i].chan); +/* EXTTS requests do not require a pin assignment. */ +for (i =0 ; i < info->n_ext_ts; i++) { +struct ptp_clock_request req = { + .type =PTP_CLK_REQ_EXTTS , + .extts.index = i, + }; + + info->enable (info, &req,0 ); + }
[Severity: Low]
Can this loop change the hardware pin direction on sja1105 during teardown?
The commit message says "Keep the pin configuration unchanged". However, sja1105 registers n_pins=1, n_ext_ts=1 and n_per_out=1, and EXTTS and PEROUT share the single PTP_CLK pin. Its EXTTS handler switches the pin function whatever the value of on:
drivers/net/dsa/sja1105/sja1105_ptp.c:sja1105_extts_enable() {
...
rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
if (rc)
return rc;
priv->ptp_data.extts_enabled = on;
...
}When the old function differs, sja1105_change_ptp_clk_pin_func() does:
avb->cas_master = (func == PTP_PF_PEROUT); return sja1105_dynamic_config_write(priv, BLK_IDX_AVB_PARAMS, 0, avb, true);
On SJA1105P/Q/R/S and SJA1110, suppose PEROUT was the last function used on the pin (through PTP_PEROUT_REQUEST or PTP_PIN_SETFUNC). Teardown then takes this path:
sja1105_teardown()
sja1105_ptp_clock_unregister()
ptp_clock_unregister()
ptp_disable_all_events()
sja1105_extts_enable(on=0)That path now clears cas_master and writes AVB_PARAMS over SPI. PTP_CLK becomes an input and the periodic output stops, while pin_config[0].func still reads PTP_PF_PEROUT.
Before this patch the pin's func was not PTP_PF_EXTTS, so no EXTTS disable was sent and the output kept running.
On SJA1105E/T the helper always sees old_func as PEROUT. Every unregister now calls sja1105_dynamic_config_write(BLK_IDX_AVB_PARAMS), which returns -ERANGE before any SPI transfer, so it has no effect there.
Is this teardown side effect intended? If so, should the commit message mention it?
[ ... ]
Quoted 5 lines
drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c ptp_ocp_ts_enable(void *priv, u32 req, bool enable) · line 2565
Quoted 9 lines
drivers/ptp/ptp_ocp.c +2
-2@@ -2559,8 +2559,8 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)else bp->pps_req_map &= ~req; -/* if no state change, just return */ -if ((!!old_map ^ !!bp->pps_req_map) ==0 ) +/* Skip the register update while a subscription remains. */ +if (old_map && bp->pps_req_map)return 0 ; }
[Severity: Medium]
Can a disable that finds the map already empty now undo a concurrent enable at runtime?
Nothing serializes the callers of ptp_ocp_ts_enable():
- extts_enable_store() in drivers/ptp/ptp_sysfs.c calls ops->enable()
without taking ptp->pincfg_mux.
- ptp_extts_request() and ptp_enable_pps() in ptp_chardev.c call it
under pincfg_mux.
- ptp_ocp_enable() sends both PTP_CLK_REQ_PPS and PTP_CLK_REQ_EXTTS
index 5 to bp->pps, and takes no driver lock.Before this patch, a disable with old_map == 0 and a new map of 0 returned early. Now it goes on to the register disable. Suppose the map is 0 and the source is disabled:
CPU A (sysfs: echo "5 0" > extts_enable) ptp_ocp_ts_enable(bp->pps, OCP_REQ_TIMESTAMP, false)
old_map = 0, pps_req_map = 0
shortcut not taken, enters the disable branch
CPU B (PTP_ENABLE_PPS ioctl, enable=1)ptp_ocp_ts_enable(bp->pps, OCP_REQ_PPS, true)
old_map = 0, pps_req_map = OCP_REQ_PPS
iowrite32(1, ®->enable);
iowrite32(1, ®->intr_mask);
returns success
CPU A
iowrite32(0, ®->intr_mask);
iowrite32(0, ®->enable);
synchronize_irq(irq_vec);
The result is pps_req_map == OCP_REQ_PPS with the source hardware disabled. No PPS events reach the pps device, even though the ioctl returned success. The state stays inconsistent until userspace disables and re-enables PPS.
Older interleavings of the same kind also remain. Examples are an ioctl disable racing a sysfs enable, or a lost |= or &= update on pps_req_map.
The commit message acknowledges that "An overlapping extts_enable sysfs request and ioctl can leave an empty map with the source enabled", but this patch only handles that at teardown.
Could the pps_req_map update and the register writes be serialized instead? Two options:
- Use a driver mutex. A spinlock won't work, because synchronize_irq() can sleep.
- Make extts_enable_store() take pincfg_mux, as the ioctl paths do.
With either one in place, the original shortcut would still be correct and this change would not be needed.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-timecard-common-v4-e0db4ab1aa-0-ahmadexp%40gmail.com
Re: [PATCH net v4 1/5] ptp: disable all timestamp channels after removing the user interfaces
Quoted 4 lines · On Tue, 24 Nov 2026 at 01:58:32 +0000, [email protected] wrote:
[Severity: Medium]
Can a disable that finds the map already empty now undo a concurrent enable at runtime?
Quoted 8 lines
Nothing serializes the callers of
ptp_ocp_ts_enable():-
extts_enable_store()indrivers/ptp/ptp_sysfs.ccallsops->enable()without taking ptp->pincfg_mux. - ptp_extts_request() and ptp_enable_pps() in ptp_chardev.c call it under pincfg_mux. - ptp_ocp_enable() sends both PTP_CLK_REQ_PPS and PTP_CLK_REQ_EXTTS index 5 to bp->pps, and takes no driver lock.
You're right. V4 addressed final shutdown but left the runtime callers unserialized. The reported schedule reproduces with the actual v4 functions and stubbed registers: the map ends at OCP_REQ_PPS while both enable and intr_mask are zero.
The v5 series adds a prerequisite taking pincfg_mux around the enable callback in extts_enable_store(), pps_enable_store() and period_store(). The latter two also lacked the lock. This uses the same mutex as the ioctl paths and permits synchronize_irq() to sleep. Permission and parse checks remain outside the critical section; callback errors and an interrupted lock acquisition are propagated.
Four controlled sysfs/ioctl interleavings passed in 100 ASan/UBSan runs. The final map and hardware enable/mask agree. Three additional local KUnit cases call the real sysfs stores against a registered test clock while pincfg_mux is held, then verify completion after release. All eight KUnit cases passed in QEMU with KASAN, lockdep and DEBUG_ATOMIC_SLEEP. No physical OCP card was used.
Quoted 2 lines
With either one in place, the original shortcut would still be correct and this change would not be needed.
That removes the runtime-race justification for changing the shortcut. I corrected the message accordingly. The series retains the final empty-map disable for a separate reason: ptp_ocp_register_ext() requests the IRQ without resetting the timestamp source, so an empty software subscription map is not proof that the initial hardware state is idle. The final disable still masks and drains that source before releasing the clock. The test explicitly models a prearmed source with map == 0; it no longer simulates a sysfs callback bypassing the now-held mutex. This is a modeled state, not an observation on physical hardware.
Quoted 8 lines
[Severity: Low]
Can this loop change the hardware pin direction on sja1105 during teardown?The commit message says "Keep the pin configuration unchanged". However, sja1105 registers n_pins=1, n_ext_ts=1 and n_per_out=1, and EXTTS and PEROUT share the single
PTP_CLKpin. Its EXTTS handler switches the pin function whatever the value of on:
Yes, and that side effect was not intended. A second prerequisite makes sja1105_extts_enable() select EXTTS only when enabling capture. Disable clears extts_enabled and synchronously deletes the timer without changing cas_master or attempting the AVB_PARAMS write. Repeated disable is safe, and the enable/error paths are retained.
The actual-function test reproduces the output-to-input change on v4. The correction passes 14 modeled chip/direction cases per run, repeated 100 times, including repeated disable and enable/error paths. The writes are stubbed: this is not an SJA1105/SJA1110 hardware test. All four x86_64/i386 allmodconfig/allyesconfig builds passed for PTP and the SJA1105 PTP object with W=1 and KCFLAGS=-Werror.
Vadim's teardown approach remains unchanged: remove the user interfaces, then directly disable every advertised EXTTS channel followed by PPS. No pin assignment, pin-function helper misuse, new stopping flag or spinlock is introduced. The removal/shared-PPS suite passed 100 runs, and all seven deliberately broken cleanup variants failed at runtime.
I have sent v5 for review. The v4 series should not be applied as-is. Thank you for identifying both gaps.
Series:
https://lore.kernel.org/r/[email protected]
Patch 1:
https://lore.kernel.org/r/[email protected]
Patch 2:
https://lore.kernel.org/r/[email protected]
Patch 3:
https://lore.kernel.org/r/[email protected]
Ahmad
pw-bot: cr
PATCH v4 2/5 ptp: ocp: handle hardware selectors and combined DPLL input routes
In reply to Ahmad ByagowiThe selector table index is not the hardware selector value. Passing the index to the SMA setter can select unrelated signals. Use the table value, as the sysfs path already does, and mask the direction enable bit before looking up the frequency.
Inputs can feed several destinations. For example, IN: TS1 TS2 produces selector 0x000c, which is not an individual table entry. An exact-match frequency lookup fails with -EINVAL, preventing the DPLL core from reading the old frequency before a later frequency change. The error also propagates through the DPLL pin dump.
For input combinations, report a known frequency only when the selected frequency-bearing destinations agree. Timestamp and counter destinations do not constrain it. Report zero when there is no known frequency, when destinations disagree, or when unknown selector bits remain. This uses the same zero-frequency representation as individual timestamp routes. Keep the exact-match requirement for output selectors.
Source-derived tests reproduce the selector and combined-input failures using stubbed MMIO and the DPLL core get-before-set function. They pass with the fix under ASan/UBSan. No physical card was tested.
The issues were reported by the Sashiko review. Codex assisted with the code, tests and changelog in response to those reports.
---
Changes in v4:
- Handle input masks with multiple destinations and make ambiguous frequencies explicit as zero. Keep exact output matching.
- Drop the earlier review tag because this expands the implementation.
Testing: 4,669 input masks across FB/ADVA/ADVA X1 tables, timestamp-only and mixed-frequency routes, unknown bits, strict output matching and recovery through the actual DPLL core get-before-set function. The old source fails the combined-input test. Selector, mask, combined-route and conflicting-frequency negative variants fail at runtime under ASan/UBSan.
drivers/ptp/ptp_ocp.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/ptp/ptp_ocp.c +25 -2
@@ -5869,7 +5869,8 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin, tbl = bp->sma_op->tbl[sma->mode];for (i =0 ; tbl[i].name; i++)if (tbl[i].frequency == frequency) -return ptp_ocp_sma_store_val (bp, i, sma->mode, sma_nr +1 ); +return ptp_ocp_sma_store_val (bp, tbl[i].value, + sma->mode, sma_nr +1 );return -EINVAL ; }
@@ -5887,6 +5888,7 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,int i; val = bp->sma_op->get (bp, sma_nr +1 ); + val &=SMA_SELECT_MASK ; tbl = bp->sma_op->tbl[sma->mode];for (i =0 ; tbl[i].name; i++)if (val == tbl[i].value) {
@@ -5894,7 +5896,28 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,return 0 ; } -return -EINVAL ; +if (sma->mode ==SMA_MODE_OUT ) +return -EINVAL ; + +/* Inputs can feed several destinations, including timestampers. */ + *frequency =0 ; +for (i =0 ; tbl[i].name; i++) { +if (!(val & tbl[i].value)) +continue ; + val &= ~tbl[i].value; +if (!tbl[i].frequency) +continue ; +if (*frequency && *frequency != tbl[i].frequency) { + *frequency =0 ; +return 0 ; + } + *frequency = tbl[i].frequency; + } +/* Unknown destinations do not establish a frequency either. */ +if (val) + *frequency =0 ; + +return 0 ; }static const struct dpll_device_ops dpll_ops = {
PATCH v4 3/5 ptp: ocp: preserve disabled SMA inputs across driver rebind
In reply to Ahmad ByagowiDisabling an SMA input clears its mux field. Zero is also the selector for 10 MHz on FB and ADVA, so a DPLL read reports 10 MHz while sysfs reports None. The DPLL core then skips a 10 MHz request as unchanged, leaving the input disabled. ADVA X1 has no zero selector; its disabled input instead fails the frequency lookup, blocking DPLL reads and later frequency changes.
Substitute SMA_DISABLE for disabled inputs before the frequency lookup, as the sysfs path already does, so the None entry reports zero Hz.
The software flag alone is insufficient after a rebind. Recover it from the mux enable bits when initializing direction-configurable FB-style connectors. The existing direction selection picks an enabled side if either side is enabled. If the selected side is also disabled, neither buffer is enabled: represent this as an input with the None function. The mux does not preserve a direction for that disconnected state. Do not write the mux or change the interpretation of fixed-direction firmware, which does not provide these enable bits.
Source-derived tests reproduce the lost disabled state using retained mux values and a fresh driver instance with stubbed MMIO. The corrected rebind and DPLL re-enable cases pass under ASan/UBSan. No physical rebind or card test was performed.
The issues were reported by the Sashiko review. Codex assisted with the code, tests and changelog using the report and public SMA-selector RTL.
---
Changes in v4:
- Recover the disconnected state from mux enable bits at initialization.
- Explain the original ADVA X1 error, not only the false 10 MHz case.
- Drop the earlier review tag because initialization behavior changed.
Testing: 243 configurations across FB/ADVA/ADVA X1, covering all four connectors, enabled inputs, outputs and disconnected states. Initialization performs zero writes; fixed-direction behavior remains unchanged. Re-enable uses the actual DPLL core get-before-set function. The old source fails the rebind case. Three disabled-state negative variants fail at runtime. These are source-derived tests with stubbed MMIO, not a physical rebind.
drivers/ptp/ptp_ocp.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/ptp/ptp_ocp.c +10 -0
@@ -2932,6 +2932,14 @@ ptp_ocp_sma_fb_init(struct ptp_ocp *bp) reg =ioread32 (&bp->sma_map1->gpio2); bp->sma[2 ].mode = reg &BIT (15 ) ?SMA_MODE_OUT :SMA_MODE_IN ; bp->sma[3 ].mode = reg &BIT (31 ) ?SMA_MODE_OUT :SMA_MODE_IN ; + +for (i =0 ; i <OCP_SMA_NUM ; i++) { + reg =ptp_ocp_sma_fb_get (bp, i +1 ); + bp->sma[i].disabled = !(reg &SMA_ENABLE ); +/* Both buffers disabled: report None. */ +if (bp->sma[i].disabled) + bp->sma[i].mode =SMA_MODE_IN ; + } } }
@@ -5889,6 +5897,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, val = bp->sma_op->get (bp, sma_nr +1 ); val &=SMA_SELECT_MASK ; +if (sma->mode ==SMA_MODE_IN && sma->disabled) + val =SMA_DISABLE ; tbl = bp->sma_op->tbl[sma->mode];for (i =0 ; tbl[i].name; i++)if (val == tbl[i].value) {
[email protected]
AI reviewRe: [PATCH net v4 3/5] ptp: ocp: preserve disabled SMA inputs across driver rebind
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] The commit message describes an ADVA X1 failure that no longer exists in the tree this patch applies to.
- [Low] The Fixes: tag is incomplete.
--
ptp: ocp: preserve disabled SMA inputs across driver rebind
This patch makes ptp_ocp_dpll_frequency_get() substitute SMA_DISABLE for disabled inputs, so the None entry reports zero Hz. It also recovers the disabled flag from the mux enable bits in ptp_ocp_sma_fb_init() for direction-configurable connectors, so a disabled input stays disabled across a driver rebind.
Quoted 6 lines
Disabling an SMA input clears its mux field. Zero is also the selector for 10 MHz on FB and ADVA, so a DPLL read reports 10 MHz while sysfs reports None. The DPLL core then skips a 10 MHz request as unchanged, leaving the input disabled. ADVA X1 has no zero selector; its disabled input instead fails the frequency lookup, blocking DPLL reads and later frequency changes.
[Severity: Low]
Does the ADVA X1 part of this description still hold for the tree this patch applies to?
The previous patch in this series, "ptp: ocp: handle hardware selectors and combined DPLL input routes", changed ptp_ocp_dpll_frequency_get(). An input that fails the exact match now falls through to the combined-destination loop instead of returning -EINVAL:
drivers/ptp/ptp_ocp.c:ptp_ocp_dpll_frequency_get() {
...
if (sma->mode == SMA_MODE_OUT)
return -EINVAL;
/* Inputs can feed several destinations, including timestampers. */
*frequency = 0;
for (i = 0; tbl[i].name; i++) {
if (!(val & tbl[i].value))
continue;
...
return 0;
}For a disabled ADVA X1 input, ptp_ocp_sma_store_val() has written 0 to the mux, so val == 0. No entry in ptp_ocp_adva_x1_sma_in has value 0, so the exact match fails. The loop then matches no bits, and the function returns 0 with *frequency = 0. So the DPLL read succeeds, and dpll_pin_freq_set() is not blocked.
With this patch, val = SMA_DISABLE matches the None entry, which gives the same 0 Hz result. On ADVA X1, the new frequency_get hunk does not appear to change anything visible. Only the rebind recovery in ptp_ocp_sma_fb_init() has an effect there, since ocp_adva_x1_sma_op also uses ptp_ocp_sma_fb_init.
The description matches the original 09eeb3aecc6c code. Could the changelog say what this patch changes on top of the previous patch in the series?
Quoted 1 line
Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
[Severity: Low]
Should this also have a Fixes: tag for b2c4f0ac53f3 ("ptp: ocp: Add ability to disable input selectors.")?
The init-time recovery in ptp_ocp_sma_fb_init() fixes a lost disabled state that goes back to that commit. It added the software-only sma->disabled flag and the SMA_DISABLE substitution in ptp_ocp_sma_show(). It also added this write in ptp_ocp_sma_store_val(), which clears the SMA_ENABLE bit:
if (sma->disabled) val = 0;
After a rebind with an input set to "IN: None", bp is freshly zeroed, so disabled is false. For SMA1, for example, ptp_ocp_sma_fb_init() sees BIT(15) of sma_map1->gpio1 clear and sets mode = SMA_MODE_OUT. Sysfs then reports an output function for a connector with neither buffer enabled. This happens without any DPLL involvement.
With only Fixes: 09eeb3aecc6c, stable trees that have b2c4f0ac53f3 but not the DPLL ops commit would not be offered the rebind part of this fix.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-timecard-common-v4-e0db4ab1aa-0-ahmadexp%40gmail.com
Re: [PATCH net v4 3/5] ptp: ocp: preserve disabled SMA inputs across driver rebind
Quoted 8 lines · On Tue, 24 Nov 2026 at 01:58:34 +0000, [email protected] wrote:
[Severity: Low]
Does the ADVA X1 part of this description still hold for the tree this patch applies to?The previous patch in this series, "ptp: ocp: handle hardware selectors and combined DPLL input routes", changed
ptp_ocp_dpll_frequency_get(). An input that fails the exact match now falls through to the combined-destination loop instead of returning-EINVAL:
No. Thank you for catching the inaccurate incremental description. After the combined-input patch, a disabled X1 input with raw selector zero already reads as zero Hz and can be re-enabled through the DPLL core. The explicit SMA_DISABLE substitution has no additional visible effect for that X1 case. Its effect is on FB/ADVA, where zero otherwise matches 10 MHz. X1 separately benefits from recovering disabled state on rebind.
The v5 series says this explicitly. A boundary test runs the actual X1 getter and DPLL core get-before-set path after the combined-input patch but before either disabled-state patch. It passes disabled-to-PPS re-enable and output-to-input direction-change recovery on all four pins. These are source-derived tests with stubbed MMIO, not hardware observations.
Quoted 9 lines
[Severity: Low]
Should this also have a Fixes: tag forb2c4f0ac53f3("ptp: ocp: Add ability to disable input selectors.")?The init-time recovery in
ptp_ocp_sma_fb_init()fixes a lost disabled state that goes back to that commit. It added the software-onlysma->disabledflag and theSMA_DISABLEsubstitution inptp_ocp_sma_show(). It also added this write inptp_ocp_sma_store_val(), which clears theSMA_ENABLEbit:
Yes. I split the old patch into two independently described changes:
v5 patch 5: recover disabled state at bind, with
v5 patch 6: report disabled inputs as zero Hz through DPLL, with
Patch 5 contains only the initialization hunk, with no DPLL dependency. It applies independently to the current net base. The base reproduces the lost state, and that patch alone passes 243 modeled FB/ADVA/X1 initialization states without calling DPLL or writing the mux. Backports to older trees may still need context/name adjustments.
The complete series also passes the rebind plus DPLL re-enable tests, 4,669 input-route combinations, ART and DCF frequency tests, and nine deliberately broken routing variants are rejected by runtime assertions. No physical rebind was performed. Vadim's Reviewed-by remains only on the unchanged DCF correction; I have not carried it onto changed patches.
I have sent the eight-patch v5 series to net for review.
Series:
https://lore.kernel.org/r/[email protected]
Patch 4:
https://lore.kernel.org/r/[email protected]
Patch 5:
https://lore.kernel.org/r/[email protected]
Patch 6:
https://lore.kernel.org/r/[email protected]
Ahmad
PATCH v4 4/5 ptp: ocp: correct the DCF output frequency
In reply to Ahmad ByagowiThe output selector table uses 77000 Hz for DCF, whereas the input table and the DPLL supported frequency list use 77500 Hz. A request for the advertised DCF77 frequency consequently fails on an output, and reading that output reports a frequency outside its advertised set.
Use 77500 Hz for the DCF output selector as well.
Source-derived set/readback tests with stubbed MMIO fail at 77500 Hz with the old entry and pass with the correction under ASan/UBSan. No physical card was tested.
The issue was reported by the Sashiko review. Codex assisted with this table correction, its regression test and the changelog.
---
Changes in v4: no code change; trim the changelog to this correction and retain Vadim's Reviewed-by. The ART input typo is a separate fifth patch.
Testing: DCF output set/readback at 77500 Hz in the source-derived ASan/UBSan fixture. Restoring 77000 fails the runtime assertion.
drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -1373,7 +1373,7 @@ static const struct ocp_selector ptp_ocp_sma_out[] = { { .name = "GNSS1", .value = 0x0004, .frequency = 1 }, { .name = "GNSS2", .value = 0x0008, .frequency = 1 }, { .name = "IRIG", .value = 0x0010, .frequency = 10000 }, - { .name = "DCF", .value = 0x0020, .frequency = 77000 }, + { .name = "DCF", .value = 0x0020, .frequency = 77500 }, { .name = "GEN1", .value = 0x0040 }, { .name = "GEN2", .value = 0x0080 }, { .name = "GEN3", .value = 0x0100 },
PATCH v4 5/5 ptp: ocp: correct the ART 10 MHz input frequency
In reply to Ahmad ByagowiThe ART input selector named 10Mhz has a frequency of 1000000 Hz instead of 10000000 Hz. ART pins advertise 10 MHz, not 1 MHz. A request for the advertised value passes the DPLL core's supported-frequency check but matches no input selector, so frequency_set returns -EINVAL. Reading the default ART input selector 0x08 reports the unadvertised 1 MHz value.
Use 10000000 Hz for the ART input selector, matching the advertised frequency and the corresponding ART output entry.
Tests using the actual ART accessors, stubbed registers and DPLL core frequency validation reproduce both failures and pass with the fix under ASan/UBSan. No physical ART card was tested.
The issue was reported by the Sashiko review. Codex assisted with the table correction, actual-accessor regression tests and the changelog.
---
New in v4, kept separate from the unchanged DCF correction.
Testing: actual ART init/set/get functions plus the actual DPLL core frequency validation and get-before-set functions. A literal 10000000 Hz request succeeds; 1000000 is rejected; the fixed 0x08 default reports 10000000. The old source and the one-MHz mutation fail runtime assertions. The test uses stubbed registers, not an ART card.
drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -1385,7 +1385,7 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {static const struct ocp_selector ptp_ocp_art_sma_in[] = { { .name ="PPS1" , .value =0x0001 , .frequency =1 }, - { .name ="10Mhz" , .value =0x0008 , .frequency =1000000 }, + { .name ="10Mhz" , .value =0x0008 , .frequency =10000000 }, { } };