Netdev List
 help / color / mirror / Atom feed
* [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing
@ 2026-11-20 21:21 Ahmad Byagowi
  2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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/20261119-timecard-common-v2-078fe69f33-0-ahmadexp@gmail.com
Cleanup discussion: https://lore.kernel.org/r/75abd6c6-f0ee-4665-9451-05e0e1a7a3d7@linux.dev

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
  2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
  2026-11-22 20:10   ` Vadim Fedorenko
  2026-11-24 22:10   ` netdev-bot+sashiko
  2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/4e42134b-b017-4836-9772-9c1915b16e77@linux.dev
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_chardev.c |  8 +++-----
 drivers/ptp/ptp_ocp.c     | 17 ++---------------
 2 files changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f63b45f5ee6a..193e6baf2b47 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -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) {
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 625a85b2dc7e..b16d36c3305f 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
  2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
  2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
  2026-11-24 22:10   ` netdev-bot+sashiko
  2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
  2026-11-20 21:21 ` [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
  3 siblings, 1 reply; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index b16d36c3305f..95a4df468e79 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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) {

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
  2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
  2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
  2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
  2026-11-24 22:10   ` netdev-bot+sashiko
  2026-11-20 21:21 ` [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
  3 siblings, 1 reply; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 95a4df468e79..653c3b1ca066 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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) {

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency
  2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
                   ` (2 preceding siblings ...)
  2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
@ 2026-11-20 21:21 ` Ahmad Byagowi
  3 siblings, 0 replies; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-20 21:21 UTC (permalink / raw)
  To: netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 653c3b1ca066..f4896f980ef5 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -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 },

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
  2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
@ 2026-11-22 20:10   ` Vadim Fedorenko
  2026-11-23  1:57     ` Ahmad Byagowi
  2026-11-24 22:10   ` netdev-bot+sashiko
  1 sibling, 1 reply; 10+ messages in thread
From: Vadim Fedorenko @ 2026-11-22 20:10 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni, richardcochran, rmk+kernel, vladimir.oltean

On 20.11.2026 21:21, Ahmad Byagowi wrote:
> 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")
> Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
> Link: https://lore.kernel.org/r/4e42134b-b017-4836-9772-9c1915b16e77@linux.dev
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
>   drivers/ptp/ptp_chardev.c |  8 +++-----
>   drivers/ptp/ptp_ocp.c     | 17 ++---------------
>   2 files changed, 5 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index f63b45f5ee6a..193e6baf2b47 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -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);
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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
  2026-11-22 20:10   ` Vadim Fedorenko
@ 2026-11-23  1:57     ` Ahmad Byagowi
  0 siblings, 0 replies; 10+ messages in thread
From: Ahmad Byagowi @ 2026-11-23  1:57 UTC (permalink / raw)
  To: Vadim Fedorenko
  Cc: netdev, andrew+netdev, arkadiusz.kubalewski, davem, edumazet,
	jiri, kuba, pabeni, richardcochran, rmk+kernel, vladimir.oltean

On Sun, 22 Nov 2026 at 20:10:55 +0000, Vadim Fedorenko wrote:
> > +	/* 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/20261122-timecard-common-v4-e0db4ab1aa-0-ahmadexp@gmail.com

Ahmad

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces
  2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
  2026-11-22 20:10   ` Vadim Fedorenko
@ 2026-11-24 22:10   ` netdev-bot+sashiko
  1 sibling, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 22:10 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, andrew+netdev, arkadiusz.kubalewski, davem, edumazet,
	jiri, kuba, pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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.

Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/4e42134b-b017-4836-9772-9c1915b16e77@linux.dev

> 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?

> diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
> index f63b45f5ee6ae..193e6baf2b475 100644
> --- a/drivers/ptp/ptp_chardev.c
> +++ b/drivers/ptp/ptp_chardev.c
> @@ -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);

[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?

[ ... ]

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 625a85b2dc7e5..b16d36c3305f9 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -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.

[ ... ]

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
  2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
@ 2026-11-24 22:10   ` netdev-bot+sashiko
  0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 22:10 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, andrew+netdev, arkadiusz.kubalewski, davem, edumazet,
	jiri, kuba, pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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.

Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index b16d36c3305f9..95a4df468e793 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c

[ ... ]

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

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
  2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
@ 2026-11-24 22:10   ` netdev-bot+sashiko
  0 siblings, 0 replies; 10+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 22:10 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, andrew+netdev, arkadiusz.kubalewski, davem, edumazet,
	jiri, kuba, pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
	vladimir.oltean

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.

Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org

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

[ ... ]

> 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?

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 95a4df468e793..653c3b1ca0668 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -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().

>  	tbl = bp->sma_op->tbl[sma->mode];
>  	for (i = 0; tbl[i].name; i++)
>  		if (val == tbl[i].value) {

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-24 22:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 21:21 [PATCH net v3 0/4] ptp: fix timestamp teardown and OCP DPLL routing Ahmad Byagowi
2026-11-20 21:21 ` [PATCH net v3 1/4] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
2026-11-22 20:10   ` Vadim Fedorenko
2026-11-23  1:57     ` Ahmad Byagowi
2026-11-24 22:10   ` netdev-bot+sashiko
2026-11-20 21:21 ` [PATCH net v3 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
2026-11-24 22:10   ` netdev-bot+sashiko
2026-11-20 21:21 ` [PATCH net v3 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
2026-11-24 22:10   ` netdev-bot+sashiko
2026-11-20 21:21 ` [PATCH net v3 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox