* [PATCH net v4 1/5] ptp: disable all timestamp channels after removing the user interfaces
2026-11-23 1:57 [PATCH net v4 0/5] Fix PTP teardown and Time Card DPLL operations Ahmad Byagowi
@ 2026-11-23 1:57 ` Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 2/5] ptp: ocp: handle hardware selectors and combined DPLL input routes Ahmad Byagowi
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-23 1:57 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.
Issue PTP_CLK_REQ_EXTTS requests directly for timestamp channel indices.
Do not use the pin-function helper or require a pin assignment. Keep the
pin-function helper for changes to actual pin configuration.
Source-derived tests with stubbed MMIO and IRQ operations reproduce the
early-disable/map race and pass with this fix. Core unregister tests also
pass in QEMU with KASAN and lockdep. No physical card was tested.
The issue was reported by the Sashiko review. Codex assisted with the
code, tests and changelog in response to that report and Vadim's review.
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
Link: https://lore.kernel.org/r/08537eb6-3f85-4a46-b3be-46796998eda4@linux.dev
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
Changes in v4:
- Issue timestamp disable requests directly, as requested by Vadim;
leave ptp_disable_pinfunc() for pin configuration.
- Move review-only testing details out of the commit message.
Testing: 100 ASan/UBSan teardown/shared-PPS suite runs, including late and
in-flight enables, concurrent sysfs/ioctl requests, all six channels,
zero/unassigned pins, absent channels and active IRQ draining. Seven
deliberate cleanup regressions were rejected. Five core register/unregister
KUnit cases ran in QEMU with KASAN and lockdep. No physical card was used.
drivers/ptp/ptp_chardev.c | 14 +++++++++-----
drivers/ptp/ptp_ocp.c | 17 ++---------------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index f63b45f5ee6a..5835c01cddb4 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -53,11 +53,15 @@ void ptp_disable_all_events(struct ptp_clock *ptp)
unsigned int i;
mutex_lock(&ptp->pincfg_mux);
- /* Disable any pins that may raise EXTTS events */
- for (i = 0; i < info->n_pins; i++)
- if (info->pin_config[i].func == PTP_PF_EXTTS)
- ptp_disable_pinfunc(info, info->pin_config[i].func,
- info->pin_config[i].chan);
+ /* EXTTS requests do not require a pin assignment. */
+ for (i = 0; i < info->n_ext_ts; i++) {
+ struct ptp_clock_request req = {
+ .type = PTP_CLK_REQ_EXTTS,
+ .extts.index = i,
+ };
+
+ info->enable(info, &req, 0);
+ }
/* Disable the PPS event if the driver has PPS support */
if (info->pps) {
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);
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v4 2/5] ptp: ocp: handle hardware selectors and combined DPLL input routes
2026-11-23 1:57 [PATCH net v4 0/5] Fix PTP teardown and Time Card DPLL operations Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 1/5] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
@ 2026-11-23 1:57 ` Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 3/5] ptp: ocp: preserve disabled SMA inputs across driver rebind Ahmad Byagowi
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-23 1:57 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. Use the table
value, as the sysfs path already does, and mask the direction enable bit
before looking up the frequency.
Inputs can feed several destinations. For example, IN: TS1 TS2 produces
selector 0x000c, which is not an individual table entry. An exact-match
frequency lookup fails with -EINVAL, preventing the DPLL core from
reading the old frequency before a later frequency change. The error
also propagates through the DPLL pin dump.
For input combinations, report a known frequency only when the selected
frequency-bearing destinations agree. Timestamp and counter destinations
do not constrain it. Report zero when there is no known frequency, when
destinations disagree, or when unknown selector bits remain. This uses
the same zero-frequency representation as individual timestamp routes.
Keep the exact-match requirement for output selectors.
Source-derived tests reproduce the selector and combined-input failures
using stubbed MMIO and the DPLL core get-before-set function. They pass
with the fix under ASan/UBSan. No physical card was tested.
The issues were reported by the Sashiko review. Codex assisted with the
code, tests and changelog in response to those reports.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/179538006772.3135.15875996486888374193@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
Changes in v4:
- Handle input masks with multiple destinations and make ambiguous
frequencies explicit as zero. Keep exact output matching.
- Drop the earlier review tag because this expands the implementation.
Testing: 4,669 input masks across FB/ADVA/ADVA X1 tables, timestamp-only
and mixed-frequency routes, unknown bits, strict output matching and
recovery through the actual DPLL core get-before-set function. The old
source fails the combined-input test. Selector, mask, combined-route and
conflicting-frequency negative variants fail at runtime under ASan/UBSan.
drivers/ptp/ptp_ocp.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index b16d36c3305f..df1a428eb2fe 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) {
@@ -5894,7 +5896,28 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
return 0;
}
- return -EINVAL;
+ if (sma->mode == SMA_MODE_OUT)
+ return -EINVAL;
+
+ /* Inputs can feed several destinations, including timestampers. */
+ *frequency = 0;
+ for (i = 0; tbl[i].name; i++) {
+ if (!(val & tbl[i].value))
+ continue;
+ val &= ~tbl[i].value;
+ if (!tbl[i].frequency)
+ continue;
+ if (*frequency && *frequency != tbl[i].frequency) {
+ *frequency = 0;
+ return 0;
+ }
+ *frequency = tbl[i].frequency;
+ }
+ /* Unknown destinations do not establish a frequency either. */
+ if (val)
+ *frequency = 0;
+
+ return 0;
}
static const struct dpll_device_ops dpll_ops = {
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v4 3/5] ptp: ocp: preserve disabled SMA inputs across driver rebind
2026-11-23 1:57 [PATCH net v4 0/5] Fix PTP teardown and Time Card DPLL operations Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 1/5] ptp: disable all timestamp channels after removing the user interfaces Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 2/5] ptp: ocp: handle hardware selectors and combined DPLL input routes Ahmad Byagowi
@ 2026-11-23 1:57 ` Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 4/5] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 5/5] ptp: ocp: correct the ART 10 MHz input frequency Ahmad Byagowi
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-23 1:57 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 on FB and ADVA, so a DPLL read reports 10 MHz while sysfs
reports None. The DPLL core then skips a 10 MHz request as unchanged,
leaving the input disabled. ADVA X1 has no zero selector; its disabled
input instead fails the frequency lookup, blocking DPLL reads and later
frequency changes.
Substitute SMA_DISABLE for disabled inputs before the frequency lookup,
as the sysfs path already does, so the None entry reports zero Hz.
The software flag alone is insufficient after a rebind. Recover it from
the mux enable bits when initializing direction-configurable FB-style
connectors. The existing direction selection picks an enabled side if
either side is enabled. If the selected side is also disabled, neither
buffer is enabled: represent this as an input with the None function.
The mux does not preserve a direction for that disconnected state.
Do not write the mux or change the interpretation of fixed-direction
firmware, which does not provide these enable bits.
Source-derived tests reproduce the lost disabled state using retained
mux values and a fresh driver instance with stubbed MMIO. The corrected
rebind and DPLL re-enable cases pass under ASan/UBSan. No physical rebind
or card test was performed.
The issues were reported by the Sashiko review. Codex assisted with the
code, tests and changelog using the report and public SMA-selector RTL.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179502617840.3136.12704245716223038161@kernel.org
Link: https://lore.kernel.org/r/179538006912.3135.16971430532149423594@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
Changes in v4:
- Recover the disconnected state from mux enable bits at initialization.
- Explain the original ADVA X1 error, not only the false 10 MHz case.
- Drop the earlier review tag because initialization behavior changed.
Testing: 243 configurations across FB/ADVA/ADVA X1, covering all four
connectors, enabled inputs, outputs and disconnected states. Initialization
performs zero writes; fixed-direction behavior remains unchanged. Re-enable
uses the actual DPLL core get-before-set function. The old source fails
the rebind case. Three disabled-state negative variants fail at runtime.
These are source-derived tests with stubbed MMIO, not a physical rebind.
drivers/ptp/ptp_ocp.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index df1a428eb2fe..e27abe2c24c7 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2932,6 +2932,14 @@ ptp_ocp_sma_fb_init(struct ptp_ocp *bp)
reg = ioread32(&bp->sma_map1->gpio2);
bp->sma[2].mode = reg & BIT(15) ? SMA_MODE_OUT : SMA_MODE_IN;
bp->sma[3].mode = reg & BIT(31) ? SMA_MODE_OUT : SMA_MODE_IN;
+
+ for (i = 0; i < OCP_SMA_NUM; i++) {
+ reg = ptp_ocp_sma_fb_get(bp, i + 1);
+ bp->sma[i].disabled = !(reg & SMA_ENABLE);
+ /* Both buffers disabled: report None. */
+ if (bp->sma[i].disabled)
+ bp->sma[i].mode = SMA_MODE_IN;
+ }
}
}
@@ -5889,6 +5897,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
val = bp->sma_op->get(bp, sma_nr + 1);
val &= SMA_SELECT_MASK;
+ if (sma->mode == SMA_MODE_IN && sma->disabled)
+ val = SMA_DISABLE;
tbl = bp->sma_op->tbl[sma->mode];
for (i = 0; tbl[i].name; i++)
if (val == tbl[i].value) {
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v4 4/5] ptp: ocp: correct the DCF output frequency
2026-11-23 1:57 [PATCH net v4 0/5] Fix PTP teardown and Time Card DPLL operations Ahmad Byagowi
` (2 preceding siblings ...)
2026-11-23 1:57 ` [PATCH net v4 3/5] ptp: ocp: preserve disabled SMA inputs across driver rebind Ahmad Byagowi
@ 2026-11-23 1:57 ` Ahmad Byagowi
2026-11-23 1:57 ` [PATCH net v4 5/5] ptp: ocp: correct the ART 10 MHz input frequency Ahmad Byagowi
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-23 1:57 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.
Source-derived set/readback tests with stubbed MMIO fail at 77500 Hz
with the old entry and pass with the correction under ASan/UBSan.
No physical card was tested.
The issue was reported by the Sashiko review. Codex assisted with this
table correction, its regression test and the changelog.
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>
---
Changes in v4: no code change; trim the changelog to this correction and
retain Vadim's Reviewed-by. The ART input typo is a separate fifth patch.
Testing: DCF output set/readback at 77500 Hz in the source-derived
ASan/UBSan fixture. Restoring 77000 fails the runtime assertion.
drivers/ptp/ptp_ocp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index e27abe2c24c7..821ecd1a13c8 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] 6+ messages in thread* [PATCH net v4 5/5] ptp: ocp: correct the ART 10 MHz input frequency
2026-11-23 1:57 [PATCH net v4 0/5] Fix PTP teardown and Time Card DPLL operations Ahmad Byagowi
` (3 preceding siblings ...)
2026-11-23 1:57 ` [PATCH net v4 4/5] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
@ 2026-11-23 1:57 ` Ahmad Byagowi
4 siblings, 0 replies; 6+ messages in thread
From: Ahmad Byagowi @ 2026-11-23 1:57 UTC (permalink / raw)
To: netdev
Cc: andrew+netdev, arkadiusz.kubalewski, davem, edumazet, jiri, kuba,
pabeni, richardcochran, rmk+kernel, vadim.fedorenko,
vladimir.oltean
The ART input selector named 10Mhz has a frequency of 1000000 Hz instead
of 10000000 Hz. ART pins advertise 10 MHz, not 1 MHz. A request for the
advertised value passes the DPLL core's supported-frequency check but
matches no input selector, so frequency_set returns -EINVAL. Reading
the default ART input selector 0x08 reports the unadvertised 1 MHz value.
Use 10000000 Hz for the ART input selector, matching the advertised
frequency and the corresponding ART output entry.
Tests using the actual ART accessors, stubbed registers and DPLL core
frequency validation reproduce both failures and pass with the fix
under ASan/UBSan. No physical ART card was tested.
The issue was reported by the Sashiko review. Codex assisted with the
table correction, actual-accessor regression tests and the changelog.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179538006772.3135.15875996486888374193@kernel.org
Link: https://lore.kernel.org/r/179538007070.3135.8275620503580456948@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
New in v4, kept separate from the unchanged DCF correction.
Testing: actual ART init/set/get functions plus the actual DPLL core
frequency validation and get-before-set functions. A literal 10000000 Hz
request succeeds; 1000000 is rejected; the fixed 0x08 default reports
10000000. The old source and the one-MHz mutation fail runtime assertions.
The test uses stubbed registers, not an ART card.
drivers/ptp/ptp_ocp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 821ecd1a13c8..93923d5a2992 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -1385,7 +1385,7 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
static const struct ocp_selector ptp_ocp_art_sma_in[] = {
{ .name = "PPS1", .value = 0x0001, .frequency = 1 },
- { .name = "10Mhz", .value = 0x0008, .frequency = 1000000 },
+ { .name = "10Mhz", .value = 0x0008, .frequency = 10000000 },
{ }
};
^ permalink raw reply related [flat|nested] 6+ messages in thread