Skip to contentSkip to conversation

ptp: fix timestamp teardown and OCP DPLL routing

PATCH Superseded Ahmad Byagowi 3 participants 13 messages Nov 20 – Nov 24

Subsystems (4)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover ptp: fix timestamp teardown and OCP DPLL routing

This revision keeps timestamp shutdown in PTP core, after removal of the user interfaces, instead of adding a driver-specific stopping flag.

Patch 1 changes ptp_disable_all_events() to disable all advertised EXTTS channels, not just channels recorded in pin descriptors. ptp_ocp has six channels and four SMA descriptors; assigning artificial pins would change the existing interface and cannot represent all enabled channels at once. The patch removes ptp_ocp's early disable loop and ensures that an empty shared PPS map still causes hardware disable and IRQ draining. The latter also covers overlapping sysfs and ioctl requests before unregister.

This follows Vadim's agreement to fix PTP core cleanup in the discussion linked below. It does not add pins or change normal SMA routing. The existing PPS/EXTTS shortcut remains while another subscription is active. Patch 1 does not claim a formal Reviewed-by or Acked-by for the new code.

Patches 2-4 are unchanged in code and carry Vadim's Reviewed-by tags.

Validation:
- 100 source-derived ASan/UBSan removal/shared-PPS runs, including the empty-map race, six timestamp channels and IRQ-drain ordering.
- Seven deliberate regressions rejected by runtime assertions.
- Five KUnit cases pass using real PTP register/unregister in QEMU with KASAN, lockdep and DEBUG_ATOMIC_SLEEP. All five fail on the old core. The test callback models event state; no physical IRQ source is used.
- DPLL/SMA source-derived tests pass.
- Complete drivers/ptp/ subtree builds pass for x86-64 and i386 with allmodconfig and allyesconfig, W=1 and KCFLAGS=-Werror.

No physical card was removed or tested. Other PTP hardware drivers have not received runtime coverage from these tests.

Changes from v2:
- Replace the timestamp stopping flag and spinlock solution with core channel cleanup after the user interfaces are drained.
- Remove the preliminary OCP disable loop and drain an empty PPS map.
- Preserve the three review tags and keep the other code fixes unchanged.
- Refresh on current net; the PTP sources are unchanged by the rebase.
- The v2 80-column warning is gone with the removed spinlock code. Keep the replacement shared-PPS comment within 80 columns as well.

v2: https://lore.kernel.org/r/[email protected]
Cleanup discussion: https://lore.kernel.org/r/[email protected]

This series replaces the earlier common fixes, rather than stacking on them. The CI pending tree net-next-2026-11-20--00-00 still contains v1's mutex implementation and the three routing fixes. That explains v2's pending-tree apply conflict; those four old patches must be replaced.

The original common-driver issues were reported by the netdev Sashiko AI review. Codex revised patch 1, its tests and the explanatory text from the request to test Vadim's approach and preserve shared PPS behavior. The unchanged patches retain their original provenance statements.

Ahmad Byagowi (4):
ptp: disable all timestamp channels after removing the user interfaces
ptp: ocp: use hardware selectors in DPLL frequency operations
ptp: ocp: report disabled SMA inputs consistently over DPLL
ptp: ocp: correct the DCF output frequency

 drivers/ptp/ptp_chardev.c |  8 +++-----
 drivers/ptp/ptp_ocp.c     | 25 ++++++++-----------------
 2 files changed, 11 insertions(+), 22 deletions(-)

base-commit: d7f2d9b6c7d0ff0af7d19d889810d35dfe07da90

#1 lore raw

PATCH v3 1/4 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.

The source-derived ASan/UBSan tests exercise late and in-flight enables, the early-disable/map race, concurrent sysfs/ioctl requests, active IRQ draining and shared PPS users.
KUnit tests exercise real PTP registration and unregistration in QEMU with KASAN and lockdep, using a test callback without physical hardware.

The original teardown issue was reported by the netdev Sashiko AI review. Codex revised the code, tests and changelog when asked to test Vadim's cleanup approach, including unassigned channels and shared PPS behavior.

Fixes a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
Fixes 627366c51145 ("ptp: ocp: fix resource freeing order")
---
 drivers/ptp/ptp_chardev.c |  8 +++-----
 drivers/ptp/ptp_ocp.c     | 17 ++---------------
 2 files changed, 5 insertions(+), 20 deletions(-)
drivers/ptp/ptp_chardev.c +3 -5
index f63b45f5ee6a..193e6baf2b47 100644
@@ -53,11 +53,9 @@ 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++)
+		ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);
 
 	/* Disable the PPS event if the driver has PPS support */
 	if (info->pps) {
drivers/ptp/ptp_ocp.c +2 -15
index 625a85b2dc7e..b16d36c3305f 100644
@@ -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);

base-commit: d7f2d9b6c7d0ff0af7d19d889810d35dfe07da90

maintainer
#2 lore raw

Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces

Quoted 50 lines · Ahmad Byagowi

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.

The source-derived ASan/UBSan tests exercise late and in-flight enables, the early-disable/map race, concurrent sysfs/ioctl requests, active IRQ draining and shared PPS users.
KUnit tests exercise real PTP registration and unregistration in QEMU with KASAN and lockdep, using a test callback without physical hardware.

The original teardown issue was reported by the netdev Sashiko AI review. Codex revised the code, tests and changelog when asked to test Vadim's cleanup approach, including unassigned channels and shared PPS behavior.

Fixes a60fc3294a37 ("ptp: rework ptp_clock_unregister() to disable events")
Fixes 627366c51145 ("ptp: ocp: fix resource freeing order")
---
  drivers/ptp/ptp_chardev.c |  8 +++-----
  drivers/ptp/ptp_ocp.c     | 17 ++---------------
  2 files changed, 5 insertions(+), 20 deletions(-)
drivers/ptp/ptp_chardev.c +0 -0
index f63b45f5ee6a..193e6baf2b47 100644
@@ -53,11 +53,9 @@ void ptp_disable_all_events(struct ptp_clock *ptp)
  	unsigned int i;

drivers/ptp/ptp_chardev.c void ptp_disable_all_events(struct ptp_clock *ptp) · line 58

Quoted 10 lines
drivers/ptp/ptp_chardev.c +3 -5
 
  	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++)
+		ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);

I thought we have agreed that time stampers and pins are different beasties. Still you provide time stamper index to pin function...

--
pw-bot: cr

#3 lore raw

Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces

Quoted 5 lines · Vadim Fedorenko

drivers/ptp/ptp_chardev.c void ptp_disable_all_events(struct ptp_clock *ptp) · line 58

Quoted 3 lines
drivers/ptp/ptp_chardev.c +3 -0
+	/* EXTTS requests do not require a pin assignment. */
+	for (i = 0; i < info->n_ext_ts; i++)
+		ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);

I thought we have agreed that time stampers and pins are different beasties. Still you provide time stamper index to pin function...

You're right. We agreed to keep timestamp channels separate from pin configuration, and v3 still blurred that distinction by using the pin helper. Sorry for not carrying that through consistently.

In the v4 revision, the loop issues a timestamp-channel disable request directly:

	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);
	}

ptp_disable_pinfunc() is unchanged and stays in the pin-configuration path. Teardown neither reads nor changes pin assignments. It disables every advertised timestamp channel, including unassigned channels and clocks with no pins, then disables the PPS subscription. It retains the existing core ordering after the user interfaces have been removed and active operations drained, with no new driver stopping flag or lock. The shared-PPS final disable still masks, flushes and drains the IRQ.

I reran the source-derived removal/shared-PPS suite 100 times, covering six channels, zero/unassigned pins, absent channels, late and in-flight requests, both subscription orders and active IRQ draining. The five core registration/unregistration KUnit cases also pass in QEMU with KASAN and lockdep. These are software tests, not a new physical-card run.

Thank you for insisting on the distinction. The revised code now makes it explicit rather than relying on a pin-named helper for channel work.

The five-patch v4 series is posted separately to net:
https://lore.kernel.org/r/[email protected]

Ahmad

#4 lore raw

Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces

In reply to Ahmad Byagowi
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

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 new skip condition in ptp_ocp_ts_enable(), if (old_map && bp->pps_req_map) return 0;, lets a redundant disable on the shared…
- [Low] The commit message's testing statement describes private, out-of- tree test harnesses and leaves out the information netdev requires.
- [Low] After this patch, ptp_disable_all_events() calls the driver's EXTTS disable for every channel below n_ext_ts, whatever the pin…

--

ptp: disable all timestamp channels after removing the user interfaces

This patch changes ptp_disable_all_events() to disable every EXTTS channel below n_ext_ts, not just the channels that have a PTP_PF_EXTTS pin assigned. It removes the timestamp-disable loop that ptp_ocp_detach() ran before unregistering and leaves the final shutdown to the core. It also changes ptp_ocp_ts_enable() so that a disable on an empty PPS subscription map still reaches the register-disable path.

Quoted 5 lines

The source-derived ASan/UBSan tests exercise late and in-flight enables, the early-disable/map race, concurrent sysfs/ioctl requests, active IRQ draining and shared PPS users.
KUnit tests exercise real PTP registration and unregistration in QEMU with KASAN and lockdep, using a test callback without physical hardware.

[Severity: Low]
Where can these tests be found? They are not part of this patch or the series, and drivers/ptp/ has no KUnit infrastructure.

The patch also changes how ptp_ocp programs its registers: the shared PPS shortcut in ptp_ocp_ts_enable() and the removed disable loop in ptp_ocp_detach(). Was this tested on TimeCard hardware?

Documentation/process/maintainer-netdev.rst says:

If the bug is in a hardware driver, the testing statement must include information about the HW on which the fix was tested.

The changelog says Codex revised the code and tests. Documentation/process/coding-assistants.rst asks that the changelog say so explicitly when a fix could not be tested.

Could the changelog name the hardware that was used, or state that ptp_ocp was not tested on hardware?

Quoted 6 lines
drivers/ptp/ptp_chardev.c +0 -0
index f63b45f5ee6ae..193e6baf2b475 100644
@@ -53,11 +53,9 @@ void ptp_disable_all_events(struct ptp_clock *ptp)
 	unsigned int i;

drivers/ptp/ptp_chardev.c void ptp_disable_all_events(struct ptp_clock *ptp) · line 58

Quoted 10 lines
drivers/ptp/ptp_chardev.c +3 -5
 
 	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++)
+		ptp_disable_pinfunc(info, PTP_PF_EXTTS, i);

[Severity: Low]
Can this reconfigure hardware on drivers whose EXTTS disable callback has side effects? ptp_disable_all_events() now calls the EXTTS disable for every channel. It does this whether or not a pin is assigned to EXTTS, and whether or not the channel was ever enabled.

sja1105 sets n_pins = 1 and n_ext_ts = 1. Its single PTP_CLK pin is shared between EXTTS and PEROUT. sja1105_extts_enable() switches the pin function before it checks 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;
    ...
}

sja1105_change_ptp_clk_pin_func() treats the pin as PEROUT when cas_master is set, and always does so on E/T parts:

drivers/net/dsa/sja1105/sja1105_ptp.c:sja1105_change_ptp_clk_pin_func() {
    ...
	if (priv->info->device_id == SJA1105E_DEVICE_ID ||
	    priv->info->device_id == SJA1105T_DEVICE_ID ||
	    avb->cas_master)
		old_func = PTP_PF_PEROUT;
    ...
	avb->cas_master = (func == PTP_PF_PEROUT);

	return sja1105_dynamic_config_write(priv, BLK_IDX_AVB_PARAMS, 0, avb,
					    true);
}

On teardown the call chain is now:

sja1105_teardown()
sja1105_ptp_clock_unregister()

    ptp_clock_unregister()
      ptp_disable_all_events()
        ptp_disable_pinfunc(info, PTP_PF_EXTTS, 0)
          sja1105_extts_enable(on=false)
            sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS)
              sja1105_dynamic_config_write(BLK_IDX_AVB_PARAMS)

This switches a pin that is running PEROUT into EXTTS input mode, and rewrites the AVB params table over SPI.

On SJA1105E/T this happens on every teardown, even though sja1105_ptp_verify_pin() rejects PTP_PF_EXTTS on those parts. Before this patch, the path ran only when pin_config[0].func was PTP_PF_EXTTS.

The core also ignores the return value, so an SPI failure here goes unreported.

Is this reconfiguration intended?

[ ... ]

Quoted 5 lines
drivers/ptp/ptp_ocp.c +0 -0
index 625a85b2dc7e5..b16d36c3305f9 100644

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]
Does this widen the race on pps_req_map at runtime? Before this patch, a disable on an already empty map returned early. Now it falls through to the register disable:

	iowrite32(0, &reg->intr_mask);
	iowrite32(0, &reg->enable);
	...
		synchronize_irq(irq_vec);

The pps_req_map read-modify-write is not serialized against the register writes:

- extts_enable_store() and pps_enable_store() in ptp_sysfs.c call

    ops->enable() without any lock.

- ptp_extts_request() and ptp_enable_pps() hold only ptp->pincfg_mux, which the sysfs paths never take.
- ptp_ocp_enable() takes no driver lock.

One possible interleaving, with TS5 never enabled:

CPU A (echo '5 0' > extts_enable) CPU B (PTP_ENABLE_PPS, 1)
ptp_ocp_ts_enable(enable=false)
old_map = 0, map = 0
0 && 0 is false, continue

                                      ptp_ocp_ts_enable(enable=true)
                                        old_map = 0, map = OCP_REQ_PPS
                                        iowrite32(1, &reg->enable)
                                        iowrite32(1, &reg->intr_mask)

iowrite32(0, &reg->intr_mask)
iowrite32(0, &reg->enable)
synchronize_irq()

The result is pps_req_map == OCP_REQ_PPS with the source masked and disabled. PPS and EXTTS index 5 events would stop with no error. The debugfs summary would show the source as off while the map still shows a subscription.

The commit message acknowledges this race:

An overlapping extts_enable sysfs request and ioctl can leave an empty map with the source enabled.

However, only teardown is made to tolerate it. Would a driver mutex held across the pps_req_map update and the register programming be more robust? It would need to be a mutex rather than a spinlock because of synchronize_irq(). With that lock in place, the original transition-based shortcut would also be correct again.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-timecard-common-v3-33316bf475-0-ahmadexp%40gmail.com
#5 lore raw

Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces

Thank you for the detailed review. These are valid concerns with v3. The current eight-patch v5 series includes the runtime and SJA1105 prerequisites, and I have now published the test fixtures and results.

Quoted 4 lines

Does this widen the race on pps_req_map at runtime? Before this patch, a disable on an already empty map returned early. Now it falls through to the register disable:

Quoted 8 lines

The pps_req_map read-modify-write is not serialized against the register writes:

- extts_enable_store() and pps_enable_store() in ptp_sysfs.c call

    ops->enable() without any lock.

- ptp_extts_request() and ptp_enable_pps() hold only ptp->pincfg_mux, which the sysfs paths never take.
- ptp_ocp_enable() takes no driver lock.

Agreed. Fixing only teardown did not serialize those runtime callers. V5 patch 1 takes the existing pincfg_mux around the EXTTS, PPS and PEROUT sysfs enable callbacks, matching the ioctl paths. That mutex covers the driver's subscription update, register programming and sleeping IRQ drain. It avoids adding a second driver lock or a spinlock.

Four controlled interleavings pass in 100 source-derived runtime runs with ASan/UBSan. Three KUnit cases call the actual sysfs stores under mutex contention in QEMU with KASAN and lockdep. Removing each store's lock makes its negative test fail at a runtime assertion.

V5 patch 3 retains Vadim's direct-channel teardown: remove the user interfaces and drain active ioctls, then issue EXTTS disables for each advertised channel followed by PPS. The final empty-map drain has a separate reason: an empty software subscription map does not establish that the source was initially idle, since IRQ registration does not reset it. The prearmed state is injected in the model, not an observation of a physical card.

Quoted 4 lines

This switches a pin that is running PEROUT into EXTTS input mode, and rewrites the AVB params table over SPI.

Is this reconfiguration intended?

No. V5 patch 2 makes sja1105_extts_enable() select the pin function only when enabling EXTTS. Disable still clears extts_enabled and synchronously deletes the polling timer, but does not reconfigure the pin. The fixture executes the actual functions with stubbed configuration writes: 14 chip/direction cases, repeated disable, enable and error paths pass in 100 runs. Restoring the unconditional pin change fails the negative test.

Quoted 5 lines

Where can these tests be found? They are not part of this patch or the series, and drivers/ptp/ has no KUnit infrastructure.

Could the changelog name the hardware that was used, or state that ptp_ocp was not tested on hardware?

The public package, pinned to a Git commit, is here:
https://github.com/Time-Appliances-Project/Time-Card/tree/c889b25e9ea175f64dd811457f8f2c3d29512e45/DRV/Linux/tests/common-v5

It contains the source-extraction runners, complete C fixtures, KUnit source, Makefile integration patch, KUnit configuration, build commands, the submitted v5 patches, checksum manifest and result logs. These are out-of-tree review fixtures; the integration patch supplies the missing PTP KUnit build entry. The documented source preparation checks the complete resulting tree against the exact submitted v5 tree.

The original run passed all eight QEMU KUnit cases, four targeted x86_64/i386 allmodconfig/allyesconfig PTP/SJA1105 builds with W=1 KCFLAGS=-Werror, and 100 cleanup/shared-PPS model runs. I also reran the published model runners and all 20 negative variants on macOS and Linux. A fresh checkout of the pinned public net base plus the supplied v5 patches reproduces the tested source tree, and all eight QEMU KUnit cases pass there too. No physical OCP/Time Card or SJA1105 hardware was tested for these fixes. The userspace models stub MMIO, IRQ and timer behavior; KUnit uses a synthetic clock. No physical unbind/rebind, PCIe interrupt timing or SPI validation is claimed. V5's messages state the software-only testing limits explicitly.

V5 series:
https://lore.kernel.org/r/[email protected]
Patch 1, runtime serialization:
https://lore.kernel.org/r/[email protected]
Patch 2, SJA1105 prerequisite:
https://lore.kernel.org/r/[email protected]
Patch 3, timestamp teardown:
https://lore.kernel.org/r/[email protected]

I have kept [email protected] copied here. The v5 series used [email protected]; sorry for missing the netdev alias in that posting.

Ahmad

#6 lore raw

PATCH v3 2/4 ptp: ocp: use hardware selectors in DPLL frequency operations

In reply to Ahmad Byagowi

The selector table index is not the hardware selector value. Passing the index to the SMA setter can select unrelated signals, or fail on ART. Use the table value, as the sysfs path already does.

Mask the direction enable bit before the frequency lookup. Otherwise an enabled, direction-configurable pin has no matching table entry and its DPLL get or dump fails. Apply both corrections to all board variants.

Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. The driver object builds on current net with W=1 and KCFLAGS=-Werror. No physical card was tested.

Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.

Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
---
 drivers/ptp/ptp_ocp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +3 -1
index b16d36c3305f..95a4df468e79 100644
@@ -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) {
#7 lore raw

Re: [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations

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: 1 · Medium: 0 · 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).

- [High] The mask fix does not cover adva_x1 after a DPLL direction change to input.

--

ptp: ocp: use hardware selectors in DPLL frequency operations

This commit makes ptp_ocp_dpll_frequency_set() pass the selector table value to ptp_ocp_sma_store_val(). Before, it passed the table index. It also masks the direction enable bit in ptp_ocp_dpll_frequency_get() before the table lookup, so that enabled, direction-configurable pins resolve to a table entry.

Quoted 4 lines
drivers/ptp/ptp_ocp.c +0 -0
index b16d36c3305f9..95a4df468e793 100644

[ ... ]

drivers/ptp/ptp_ocp.c static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, · line 5894

Quoted 8 lines
drivers/ptp/ptp_ocp.c +1 -0
@@ -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) {

[Severity: High]
Does this mask fix the get/dump failure on adva_x1 after a DPLL direction change to input?

ptp_ocp_dpll_direction_set() always writes selector 0, whatever the board:

drivers/ptp/ptp_ocp.c:ptp_ocp_dpll_direction_set() {
    ...
	return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr + 1);
}

On a direction-configurable pin (fixed_dir is false), the call path is ptp_ocp_sma_store_val() -> ptp_ocp_sma_adva_set_inputs(). Along the way SMA_ENABLE is ORed in, so 0x8000 is written to the input mux. Once the new mask is applied in ptp_ocp_dpll_frequency_get(), that leaves 0.

On fb and adva, 0 matches the "10Mhz" entry. The adva_x1 input table has no 0x0000 entry:

static const struct ocp_selector ptp_ocp_adva_x1_sma_in[] = {
	{ .name = "PPS1",	.value = 0x0001,      .frequency = 1 },
	{ .name = "TS1",	.value = 0x0004,      .frequency = 0 },
	...

So the lookup loop finds nothing and returns -EINVAL.

ocp_adva_x1_sma_op uses ptp_ocp_sma_fb_init(). When sma_map2->gpio2 is not 0xffffffff, the adva_x1 pins keep fixed_dir false and DIRECTION_CAN_CHANGE, so a DPLL pin-set with direction=input reaches this path.

After that:

- dpll_cmd_pin_get_one() fails, so PIN_GET and the change notification fail for that pin.
- dpll_nl_pin_get_dumpit() breaks out on any error other than -ENODEV, so the whole pin dump fails, not just this pin's entry.
- dpll_pin_freq_set() calls frequency_get first and stops with "unable to get old frequency value", so the pin cannot be recovered through DPLL.

The commit message says the corrections apply "to all board variants". Would adva_x1 need a board-specific default selector in ptp_ocp_dpll_direction_set(), or a matching entry in ptp_ocp_adva_x1_sma_in[]?

Later patches in this series do not change this path either. Those are "ptp: ocp: report disabled SMA inputs consistently over DPLL" and "ptp:
ocp: correct the DCF output frequency".

ptp_ocp_dpll_direction_set() clears sma->disabled, so the disabled-state substitution added later does not trigger here. The adva_x1 input table is unchanged at the end of the series.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-timecard-common-v3-33316bf475-0-ahmadexp%40gmail.com
#8 lore raw

Re: [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations

Thank you. This is a valid gap in v3's mask-only correction.

Quoted 9 lines

Does this mask fix the get/dump failure on adva_x1 after a DPLL direction change to input?

On fb and adva, 0 matches the "10Mhz" entry. The adva_x1 input table has no 0x0000 entry:

ptp_ocp_dpll_direction_set() clears sma->disabled, so the disabled-state substitution added later does not trigger here. The adva_x1 input table is unchanged at the end of the series.

Agreed: the disabled flag alone does not address the direction-change case. V5 patch 4 handles input selector combinations instead of failing every non-exact lookup. An X1 zero input selector reports 0 Hz (no known frequency), which permits the DPLL core's get-before-set path to proceed. It does not invent a 10 MHz X1 route or change the selector table. Output selectors still require exact matches.

The published x1-direction test executes the actual direction callback for all four pins: raw 0x8000, disabled=false, a successful 0 Hz read, then successful PPS recovery through the actual DPLL get-before-set function. The boundary test passes immediately after v5 patch 4, before patches 5 and 6. This is not an additional fix attributed to patch 6.

The ASan/UBSan routing tests also pass 4,669 FB/ADVA/X1 input masks, including combined destinations, conflicting frequencies, unknown bits and strict output lookup. These are source-derived tests with stubbed MMIO, not observations on physical ADVA X1 hardware.

Public test fixtures, reproduction instructions and logs:
https://github.com/Time-Appliances-Project/Time-Card/tree/c889b25e9ea175f64dd811457f8f2c3d29512e45/DRV/Linux/tests/common-v5
See tests/run-routing-tests.py (x1-direction), tests/run-boundary-tests.py, results/original/fixed-x1.log and results/original/boundary-tests.log. The published runners and negative variants were rerun before publication.

V5 series:
https://lore.kernel.org/r/[email protected]
Patch 4, hardware selectors and combined DPLL input routes:
https://lore.kernel.org/r/[email protected]

Ahmad

#9 lore raw

PATCH v3 3/4 ptp: ocp: report disabled SMA inputs consistently over DPLL

In reply to Ahmad Byagowi

Disabling an SMA input clears its mux field. Zero is also the selector for 10 MHz, so a DPLL read reports 10 MHz while sysfs reports None. The DPLL core then treats a request to enable 10 MHz as unchanged and skips the setter, leaving the input disabled.

Substitute SMA_DISABLE for disabled inputs before looking up the frequency, as the sysfs path already does. The None entry reports zero Hz and a subsequent 10 MHz request reaches the setter.

Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. The driver object builds on current net with W=1 and KCFLAGS=-Werror. No physical card was tested.

Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.

Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
---
 drivers/ptp/ptp_ocp.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/ptp/ptp_ocp.c +2 -0
index 95a4df468e79..653c3b1ca066 100644
@@ -5889,6 +5889,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) {
#10 lore raw

Re: [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL

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] The fix keys only on the software flag sma->disabled, and nothing rebuilds that flag from hardware at probe.
- [Low] The testing and provenance paragraphs of the changelog are the same text used in the other patches of the series.

--

ptp: ocp: report disabled SMA inputs consistently over DPLL

This commit changes ptp_ocp_dpll_frequency_get() so that a disabled SMA input uses SMA_DISABLE before the selector table lookup, which is what the sysfs show path already does. Before this, a disabled input read back as 10 MHz, and the DPLL core skipped a later 10 MHz set as unchanged.

Quoted 4 lines

Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware.

[ ... ]

Quoted 3 lines

Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.

[Severity: Low]
Do these paragraphs describe this commit? They look like the same testing and provenance text used in the other patches of the series.

This patch only adds the disabled-state substitution in ptp_ocp_dpll_frequency_get().

It doesn't change the selector handling or SMA_SELECT_MASK. That work is in the earlier patch "ptp: ocp: use hardware selectors in DPLL frequency operations".

It also has nothing to do with removal ordering. That is in "ptp:
disable all timestamp channels after removing the user interfaces".

At this commit the DCF output entry still has the old value:

drivers/ptp/ptp_ocp.c:ptp_ocp_sma_out[] {
    ...
	{ .name = "DCF",	.value = 0x0020,  .frequency = 77000 },
    ...
}

The following patch, "ptp: ocp: correct the DCF output frequency", fixes that value. So a DCF regression test would fail on this tree by itself.

Could the changelog describe only the testing that applies to this change?

drivers/ptp/ptp_ocp.c static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, · line 5893

Quoted 10 lines
drivers/ptp/ptp_ocp.c +2 -0
index 95a4df468e793..653c3b1ca0668 100644
@@ -5889,6 +5889,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;

[Severity: Medium]
Can a disabled input still be reported as 10 MHz after the driver is unbound and rebound?

The new check looks only at the software flag sma->disabled. Disabling an input in ptp_ocp_sma_store_val() writes 0 to the whole input field, and that also clears SMA_ENABLE:

drivers/ptp/ptp_ocp.c:ptp_ocp_sma_store_val() {
    ...
	if (!sma->fixed_dir)
		val |= SMA_ENABLE;		/* add enable bit */

	if (sma->disabled)
		val = 0;
    ...
}

On rebind, bp is allocated zeroed, so disabled starts out false. ptp_ocp_sma_fb_init() uses bit 15 of the gpio registers only to pick the direction:

drivers/ptp/ptp_ocp.c:ptp_ocp_sma_fb_init() {
    ...
		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;
    ...
}

Take SMA3 or SMA4 on a board where the direction can be changed. Switch it to input, disable it, then rebind the driver. The pin comes back as SMA_MODE_IN with disabled == false.

In ptp_ocp_dpll_frequency_get(), the line "val &= SMA_SELECT_MASK" drops bit 15. In hardware, that bit is the only thing that tells disabled (0x0000) apart from enabled 10 MHz (0x8000).

The new check doesn't fire, and the lookup matches the "10Mhz" entry. A DPLL request for 10 MHz then returns early here:

drivers/dpll/dpll_netlink.c:dpll_pin_freq_set() {
    ...
	if (freq == old_freq)
		return 0;
    ...
}

The input stays disabled, which is the failure the changelog says this patch fixes.

This assumes the FPGA mux registers keep their value across unbind/rebind. Probe doesn't seem to reset them, but this hasn't been confirmed on hardware.

Would it work to check the raw SMA_ENABLE bit for !sma->fixed_dir pins before masking? Another option is to set sma->disabled from that bit in ptp_ocp_sma_fb_init().

Quoted 3 lines
drivers/ptp/ptp_ocp.c +0 -0
 	tbl = bp->sma_op->tbl[sma->mode];
 	for (i = 0; tbl[i].name; i++)
 		if (val == tbl[i].value) {
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-timecard-common-v3-33316bf475-0-ahmadexp%40gmail.com
#11 lore raw

Re: [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL

Thank you. Both points are valid for v3 and are addressed in v5.

Quoted 10 lines

Can a disabled input still be reported as 10 MHz after the driver is unbound and rebound?

The new check looks only at the software flag sma->disabled. Disabling an input in ptp_ocp_sma_store_val() writes 0 to the whole input field, and that also clears SMA_ENABLE:

Would it work to check the raw SMA_ENABLE bit for !sma->fixed_dir pins before masking? Another option is to set sma->disabled from that bit in ptp_ocp_sma_fb_init().

V5 patch 5 takes the initialization approach. For direction-configurable FB-style connectors, including ADVA and ADVA X1, it recovers disabled state from the mux enable bits. If neither buffer is enabled, it reports input/None without writing the mux. It leaves legacy fixed-direction firmware's interpretation unchanged. This fixes the pre-DPLL bind-state bug separately, with Fixes: b2c4f0ac53f3.

V5 patch 6 then makes DPLL use the disabled state consistently with sysfs and report 0 Hz, permitting a subsequent 10 MHz request on FB/ADVA to re-enable the input. Its Fixes tag remains 09eeb3aecc6c.

The ASan/UBSan tests pass 243 modeled FB/ADVA/X1 rebind states with fresh driver state and retained mux values, all four connectors, zero MMIO writes and legacy fixed-direction checks. The boundary test also applies patch 5 alone to the net base and verifies the initialization correction without any DPLL test calls. Retained mux state is a model assumption; no physical unbind/rebind or retained-register experiment was performed.

Quoted 2 lines

Could the changelog describe only the testing that applies to this change?

Agreed. The v5 messages now describe each change's own test coverage and limits. Patch 5 describes initialization/rebind tests; patch 6 describes disabled-input reporting and recovery. Neither borrows the DCF77 or teardown result. Patch 6 also explains that X1 zero-selector recovery already works after patch 4, rather than claiming a second X1 -EINVAL fix.

Public test fixtures, reproduction instructions and logs:
https://github.com/Time-Appliances-Project/Time-Card/tree/c889b25e9ea175f64dd811457f8f2c3d29512e45/DRV/Linux/tests/common-v5
See tests/run-boundary-tests.py, results/original/fixed-rebind.log and results/original/boundary-tests.log. The published model runners and all 20 negative variants passed again before publication.

V5 series:
https://lore.kernel.org/r/[email protected]
Patch 5, recover disabled SMA inputs when binding:
https://lore.kernel.org/r/[email protected]
Patch 6, report zero frequency for disabled SMA inputs:
https://lore.kernel.org/r/[email protected]

Ahmad

#12 lore raw

PATCH v3 4/4 ptp: ocp: correct the DCF output frequency

In reply to Ahmad Byagowi

The 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.

Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. The driver object builds on current net with W=1 and KCFLAGS=-Werror. No physical card was tested.

Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.

Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
---
 drivers/ptp/ptp_ocp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
index 653c3b1ca066..f4896f980ef5 100644
@@ -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 },