Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing
@ 2026-11-19 21:19 Ahmad Byagowi
  2026-11-19 21:19 ` [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach Ahmad Byagowi
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Ahmad Byagowi @ 2026-11-19 21:19 UTC (permalink / raw)
  To: netdev, vadim.fedorenko, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

These fixes address existing Time Card teardown and routing issues and
are independent of the WiWi board support series.

Changes since v1:
- Patch 1 uses the existing device spinlock instead of a new mutex, as
  suggested by Vadim Fedorenko. It covers the stopping check, PPS map
  changes and MMIO, but releases the lock before pci_irq_vector() and
  synchronize_irq(). The vector lookup takes the MSI descriptor mutex.
- During teardown, the PPS no-state-change shortcut is bypassed so a
  concurrent disable which has cleared the map cannot cause detach to
  skip its own IRQ drain.
- The source-derived removal harness now checks that MMIO remains locked,
  vector lookup and IRQ synchronization are unlocked, and an in-flight
  disable cannot skip teardown synchronization. Six intentional
  regressions are rejected.
- Code changes in patches 2-4 are unchanged. Group Fixes, Link and
  Signed-off-by trailers without intervening blank lines, addressing
  the v1 verify_fixes CI finding.

The common and WiWi-integration PTP objects compile for x86-64 with W=1
and KCFLAGS=-Werror. Source-derived ASan/UBSan removal and routing checks
pass. The old-source control still reproduces rearming. These are mocked
MMIO/IRQ interleaving tests, not kernel lockdep, KASAN or physical unbind
tests. No production machine, card firmware or Windows HLK host was used.

The issues were reported in the netdev Sashiko AI review and checked
against the upstream source. Codex prepared the code, changelogs and
software tests at the request to separate common fixes from WiWi support;
this revision checks Vadim's spinlock suggestion and extends the removal
tests. The patch changelogs describe the discovery and testing details.

Previous series:
https://lore.kernel.org/r/20261118-timecard-common-301f823ddd-0-ahmadexp@gmail.com
Review:
https://lore.kernel.org/r/ad6883e5-c103-4f82-8040-e5463477ca10@linux.dev

Base: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5 (same net base as v1).
WiWi v4 remains separate and unsent.

Ahmad Byagowi (4):
  ptp: ocp: prevent timestamp rearming during detach
  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_ocp.c | 43 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 34 insertions(+), 9 deletions(-)


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

* [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
  2026-11-19 21:19 [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing Ahmad Byagowi
@ 2026-11-19 21:19 ` Ahmad Byagowi
  2026-11-19 22:23   ` Vadim Fedorenko
  2026-11-19 21:19 ` [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Ahmad Byagowi @ 2026-11-19 21:19 UTC (permalink / raw)
  To: netdev, vadim.fedorenko, richardcochran
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni

Detach disables timestamp interrupts before unregistering the PTP clock.
Until the POSIX clock is unregistered, an ioctl can rearm a channel
after that disable. The clock can then be released while the timestamp
IRQ is still registered. The core cleanup does not necessarily disable
the channel: EXTTS requests do not require a PTP_PF_EXTTS pin assignment.

Use the existing device spinlock to serialize the stopping check, PPS
subscription updates and timestamp MMIO. Set ts_stopping under that lock
before detach disables the channels, so an enable already in progress
finishes first and later enables fail with -ENODEV. Keep disables
available for PTP core cleanup.

Flush the interrupt mask writes under the lock, then drop the lock and
restore IRQ flags before pci_irq_vector(), which takes the MSI descriptor
mutex, and synchronize_irq(), which may sleep. During teardown, bypass
the PPS no-state-change shortcut: a concurrent disable
may have cleared pps_req_map and dropped the lock without yet draining
its IRQ. Detach must still disable and drain that channel before
ptp_clock_unregister().

Reported by the netdev Sashiko AI review, then checked against the PTP
and POSIX-clock paths. The source-derived userspace harness reproduces
rearming with the old source. With this fix it rejects late enables,
serializes in-flight enables, drains a mocked active IRQ and covers a
disable paused after unlock but before IRQ synchronization. It checks
that MMIO is locked and vector lookup and IRQ synchronization run unlocked
with IRQ flags restored. Shared PPS/EXTTS subscriptions and all six
channels pass with ASan/UBSan. This is not an in-kernel UAF, lockdep or
physical-card test.

Codex revised the code, tests and changelog from Vadim's review, at the
request to check the spinlock approach and rerun the removal-race tests.

Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")
Suggested-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/ad6883e5-c103-4f82-8040-e5463477ca10@linux.dev
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 625a85b2dc..4c98558e96 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -367,6 +367,8 @@ struct ptp_ocp {
 	struct pci_dev		*pdev;
 	struct device		dev;
 	spinlock_t		lock;
+	/* Protected by lock; blocks timestamp arming during teardown. */
+	bool			ts_stopping;
 	struct ocp_reg __iomem	*reg;
 	struct tod_reg __iomem	*tod;
 	struct pps_reg __iomem	*pps_to_ext;
@@ -2550,6 +2552,15 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
 	struct ptp_ocp_ext_src *ext = priv;
 	struct ts_reg __iomem *reg = ext->mem;
 	struct ptp_ocp *bp = ext->bp;
+	unsigned long flags;
+	bool need_sync = false;
+	int err = 0;
+
+	spin_lock_irqsave(&bp->lock, flags);
+	if (enable && bp->ts_stopping) {
+		err = -ENODEV;
+		goto out;
+	}
 
 	if (ext == bp->pps) {
 		u32 old_map = bp->pps_req_map;
@@ -2559,9 +2570,9 @@ 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)
-			return 0;
+		/* Teardown must drain IRQs even if another disable cleared the map. */
+		if ((!!old_map ^ !!bp->pps_req_map) == 0 && !bp->ts_stopping)
+			goto out;
 	}
 
 	if (enable) {
@@ -2569,16 +2580,21 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
 		iowrite32(1, &reg->intr_mask);
 		iowrite32(1, &reg->intr);
 	} else {
-		int irq_vec = pci_irq_vector(bp->pdev, ext->irq_vec);
-
 		iowrite32(0, &reg->intr_mask);
 		iowrite32(0, &reg->enable);
 		ioread32(&reg->intr_mask);
+		need_sync = true;
+	}
+
+out:
+	spin_unlock_irqrestore(&bp->lock, flags);
+	if (need_sync) {
+		int irq_vec = pci_irq_vector(bp->pdev, ext->irq_vec);
+
 		if (irq_vec > 0)
 			synchronize_irq(irq_vec);
 	}
-
-	return 0;
+	return err;
 }
 
 static void
@@ -5749,12 +5765,17 @@ ptp_ocp_detach_sysfs(struct ptp_ocp *bp)
 static void
 ptp_ocp_detach(struct ptp_ocp *bp)
 {
+	unsigned long flags;
 	int i;
 
 	ptp_ocp_debugfs_remove_device(bp);
 	ptp_ocp_detach_sysfs(bp);
 	ptp_ocp_attr_group_del(bp);
 	timer_delete_sync(&bp->watchdog);
+	/* Drain in-flight enables and prevent rearming before unregister. */
+	spin_lock_irqsave(&bp->lock, flags);
+	bp->ts_stopping = true;
+	spin_unlock_irqrestore(&bp->lock, flags);
 	/* Disable interrupts on all timestampers */
 	if (bp->ts0)
 		ptp_ocp_ts_enable(bp->ts0, 0, false);

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

* [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
  2026-11-19 21:19 [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing Ahmad Byagowi
  2026-11-19 21:19 ` [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach Ahmad Byagowi
@ 2026-11-19 21:19 ` Ahmad Byagowi
  2026-11-19 22:23   ` Vadim Fedorenko
  2026-11-19 21:19 ` [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
  2026-11-19 21:19 ` [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
  3 siblings, 1 reply; 9+ messages in thread
From: Ahmad Byagowi @ 2026-11-19 21:19 UTC (permalink / raw)
  To: netdev, vadim.fedorenko, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

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
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 4c98558e96..f1f97c1fa0 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5903,7 +5903,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;
 }
 
@@ -5921,6 +5922,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] 9+ messages in thread

* [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
  2026-11-19 21:19 [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing Ahmad Byagowi
  2026-11-19 21:19 ` [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach Ahmad Byagowi
  2026-11-19 21:19 ` [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
@ 2026-11-19 21:19 ` Ahmad Byagowi
  2026-11-19 22:24   ` Vadim Fedorenko
  2026-11-19 21:19 ` [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
  3 siblings, 1 reply; 9+ messages in thread
From: Ahmad Byagowi @ 2026-11-19 21:19 UTC (permalink / raw)
  To: netdev, vadim.fedorenko, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

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
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 f1f97c1fa0..06d05fac6e 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5923,6 +5923,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] 9+ messages in thread

* [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency
  2026-11-19 21:19 [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing Ahmad Byagowi
                   ` (2 preceding siblings ...)
  2026-11-19 21:19 ` [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
@ 2026-11-19 21:19 ` Ahmad Byagowi
  2026-11-19 22:24   ` Vadim Fedorenko
  3 siblings, 1 reply; 9+ messages in thread
From: Ahmad Byagowi @ 2026-11-19 21:19 UTC (permalink / raw)
  To: netdev, vadim.fedorenko, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

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
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 06d05fac6e..0d3d9ffd1f 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1375,7 +1375,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] 9+ messages in thread

* Re: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
  2026-11-19 21:19 ` [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach Ahmad Byagowi
@ 2026-11-19 22:23   ` Vadim Fedorenko
  0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2026-11-19 22:23 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev, richardcochran
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni

On 19/11/2026 21:19, Ahmad Byagowi wrote:
> Detach disables timestamp interrupts before unregistering the PTP clock.
> Until the POSIX clock is unregistered, an ioctl can rearm a channel
> after that disable. The clock can then be released while the timestamp
> IRQ is still registered. The core cleanup does not necessarily disable
> the channel: EXTTS requests do not require a PTP_PF_EXTTS pin assignment.

I think we have to fix it other way. Basically, there are several ways
to enable EXTTS in ptp_ocp:
1. Via sma* attributes in ptp_ocp sysfs entry
2. Via pin name sysfs entry under ptp device
3. Via PTP_PIN_SETFUNC ioctl
4. Via PTP_EXTTS_REQUEST ioctl

On teardown, sma* attributes (1) are removed before disabling
interrupts. Options 2 and 3 set PTP_PF_EXTTS function and reverted
during ptp_clock_unregister(). Only option 4 does not set PTP_PF_EXTTS
function to pin, because it calls ops->enable() callback directly.
To fix it properly enable() callback has to set PTP_PF_EXTTS function
if it's requested. That will make ptp_disable_all_events() do exactly
what is has to do - clear all events generators of ptp device after
removing ioctl interface.


> 
> Use the existing device spinlock to serialize the stopping check, PPS
> subscription updates and timestamp MMIO. Set ts_stopping under that lock
> before detach disables the channels, so an enable already in progress
> finishes first and later enables fail with -ENODEV. Keep disables
> available for PTP core cleanup.
> 
> Flush the interrupt mask writes under the lock, then drop the lock and
> restore IRQ flags before pci_irq_vector(), which takes the MSI descriptor
> mutex, and synchronize_irq(), which may sleep. During teardown, bypass
> the PPS no-state-change shortcut: a concurrent disable
> may have cleared pps_req_map and dropped the lock without yet draining
> its IRQ. Detach must still disable and drain that channel before
> ptp_clock_unregister().
> 
> Reported by the netdev Sashiko AI review, then checked against the PTP
> and POSIX-clock paths. The source-derived userspace harness reproduces
> rearming with the old source. With this fix it rejects late enables,
> serializes in-flight enables, drains a mocked active IRQ and covers a
> disable paused after unlock but before IRQ synchronization. It checks
> that MMIO is locked and vector lookup and IRQ synchronization run unlocked
> with IRQ flags restored. Shared PPS/EXTTS subscriptions and all six
> channels pass with ASan/UBSan. This is not an in-kernel UAF, lockdep or
> physical-card test.
> 
> Codex revised the code, tests and changelog from Vadim's review, at the
> request to check the spinlock approach and rerun the removal-race tests.
> 
> Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")
> Suggested-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
> Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
> Link: https://lore.kernel.org/r/ad6883e5-c103-4f82-8040-e5463477ca10@linux.dev
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
>   drivers/ptp/ptp_ocp.c | 35 ++++++++++++++++++++++++++++-------
>   1 file changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 625a85b2dc..4c98558e96 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -367,6 +367,8 @@ struct ptp_ocp {
>   	struct pci_dev		*pdev;
>   	struct device		dev;
>   	spinlock_t		lock;
> +	/* Protected by lock; blocks timestamp arming during teardown. */
> +	bool			ts_stopping;
>   	struct ocp_reg __iomem	*reg;
>   	struct tod_reg __iomem	*tod;
>   	struct pps_reg __iomem	*pps_to_ext;
> @@ -2550,6 +2552,15 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
>   	struct ptp_ocp_ext_src *ext = priv;
>   	struct ts_reg __iomem *reg = ext->mem;
>   	struct ptp_ocp *bp = ext->bp;
> +	unsigned long flags;
> +	bool need_sync = false;
> +	int err = 0;
> +
> +	spin_lock_irqsave(&bp->lock, flags);
> +	if (enable && bp->ts_stopping) {
> +		err = -ENODEV;
> +		goto out;
> +	}
>   
>   	if (ext == bp->pps) {
>   		u32 old_map = bp->pps_req_map;
> @@ -2559,9 +2570,9 @@ 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)
> -			return 0;
> +		/* Teardown must drain IRQs even if another disable cleared the map. */

there was no need of this in the previous patch, why do we need it now?

> +		if ((!!old_map ^ !!bp->pps_req_map) == 0 && !bp->ts_stopping)
> +			goto out;
>   	}
>   
>   	if (enable) {
> @@ -2569,16 +2580,21 @@ ptp_ocp_ts_enable(void *priv, u32 req, bool enable)
>   		iowrite32(1, &reg->intr_mask);
>   		iowrite32(1, &reg->intr);
>   	} else {
> -		int irq_vec = pci_irq_vector(bp->pdev, ext->irq_vec);
> -
>   		iowrite32(0, &reg->intr_mask);
>   		iowrite32(0, &reg->enable);
>   		ioread32(&reg->intr_mask);
> +		need_sync = true;
> +	}
> +
> +out:
> +	spin_unlock_irqrestore(&bp->lock, flags);
> +	if (need_sync) {
> +		int irq_vec = pci_irq_vector(bp->pdev, ext->irq_vec);
> +
>   		if (irq_vec > 0)
>   			synchronize_irq(irq_vec);
>   	}
> -
> -	return 0;
> +	return err;
>   }
>   
>   static void
> @@ -5749,12 +5765,17 @@ ptp_ocp_detach_sysfs(struct ptp_ocp *bp)
>   static void
>   ptp_ocp_detach(struct ptp_ocp *bp)
>   {
> +	unsigned long flags;
>   	int i;
>   
>   	ptp_ocp_debugfs_remove_device(bp);
>   	ptp_ocp_detach_sysfs(bp);
>   	ptp_ocp_attr_group_del(bp);
>   	timer_delete_sync(&bp->watchdog);
> +	/* Drain in-flight enables and prevent rearming before unregister. */
> +	spin_lock_irqsave(&bp->lock, flags);
> +	bp->ts_stopping = true;
> +	spin_unlock_irqrestore(&bp->lock, flags);
>   	/* Disable interrupts on all timestampers */
>   	if (bp->ts0)
>   		ptp_ocp_ts_enable(bp->ts0, 0, false);


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

* Re: [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
  2026-11-19 21:19 ` [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
@ 2026-11-19 22:23   ` Vadim Fedorenko
  0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2026-11-19 22:23 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

On 19/11/2026 21:19, Ahmad Byagowi wrote:
> 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
> 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 4c98558e96..f1f97c1fa0 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -5903,7 +5903,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;
>   }
>   
> @@ -5921,6 +5922,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) {

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
  2026-11-19 21:19 ` [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
@ 2026-11-19 22:24   ` Vadim Fedorenko
  0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2026-11-19 22:24 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

On 19/11/2026 21:19, Ahmad Byagowi wrote:
> 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
> 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 f1f97c1fa0..06d05fac6e 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -5923,6 +5923,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) {

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

* Re: [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency
  2026-11-19 21:19 ` [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
@ 2026-11-19 22:24   ` Vadim Fedorenko
  0 siblings, 0 replies; 9+ messages in thread
From: Vadim Fedorenko @ 2026-11-19 22:24 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev, richardcochran
  Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
	pabeni

On 19/11/2026 21:19, Ahmad Byagowi wrote:
> 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
> 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 06d05fac6e..0d3d9ffd1f 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -1375,7 +1375,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 },

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>

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

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 21:19 [PATCH net v2 0/4] ptp: ocp: fix timestamp teardown and DPLL routing Ahmad Byagowi
2026-11-19 21:19 ` [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach Ahmad Byagowi
2026-11-19 22:23   ` Vadim Fedorenko
2026-11-19 21:19 ` [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations Ahmad Byagowi
2026-11-19 22:23   ` Vadim Fedorenko
2026-11-19 21:19 ` [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL Ahmad Byagowi
2026-11-19 22:24   ` Vadim Fedorenko
2026-11-19 21:19 ` [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-19 22:24   ` Vadim Fedorenko

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