ptp: ocp: fix timestamp teardown and DPLL routing
v2 cover ptp: ocp: fix timestamp teardown and DPLL routing
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/[email protected]
Review:
https://lore.kernel.org/r/[email protected]
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(-)
PATCH v2 1/4 ptp: ocp: prevent timestamp rearming during detach
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.
--- drivers/ptp/ptp_ocp.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)
drivers/ptp/ptp_ocp.c +28 -7
@@ -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 , ®->intr_mask);iowrite32 (1 , ®->intr); }else { -int irq_vec =pci_irq_vector (bp->pdev, ext->irq_vec); -iowrite32 (0 , ®->intr_mask);iowrite32 (0 , ®->enable);ioread32 (®->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);
Vadim Fedorenko
maintainerRe: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
Quoted 5 lines · Ahmad Byagowi
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_EXTTSpin 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.
Quoted 67 lines
Use the existing device spinlock to serialize the stopping check, PPS subscription updates and timestamp MMIO. Set
ts_stoppingunder 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, andsynchronize_irq(), which may sleep. During teardown, bypass the PPS no-state-change shortcut: a concurrent disable
may have clearedpps_req_mapand dropped the lock without yet draining its IRQ. Detach must still disable and drain that channel beforeptp_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 <[email protected]>Signed-off-by Ahmad Byagowi <[email protected]>--- drivers/ptp/ptp_ocp.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-)drivers/ptp/ptp_ocp.c +11
-0@@ -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;
drivers/ptp/ptp_ocp.c ptp_ocp_ts_enable(void *priv, u32 req, bool enable) · line 2573
Quoted 7 lines
drivers/ptp/ptp_ocp.c +1
-3@@ -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?
Quoted 49 lines
drivers/ptp/ptp_ocp.c +16
-4+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 , ®->intr_mask);iowrite32 (1 , ®->intr); }else { -int irq_vec =pci_irq_vector (bp->pdev, ext->irq_vec); -iowrite32 (0 , ®->intr_mask);iowrite32 (0 , ®->enable);ioread32 (®->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);
Re: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
Quoted 1 line · Vadim Fedorenko
enable()callback has to setPTP_PF_EXTTSfunction
Thanks. I tested the cleanup path. Recording an assignment makes the core disable that channel, but ptp_ocp exposes six timestamp channels and only four SMA descriptors. TS0 is the internal GNSS source and TS5 is the PHC source. All six can be enabled without pin assignments. Four descriptors cannot record that state without rejecting requests or changing the pin interface. extts_enable sysfs also reaches enable() without an assignment.
Would you and Richard prefer disabling all n_ext_ts channels in ptp_disable_all_events(), followed by the existing PPS disable? That keeps cleanup after posix_clock_unregister(), without inventing pin assignments. I have prepared and tested that alternative locally, not posted it yet.
I also removed ptp_ocp's preliminary disable loop. Otherwise it can clear pps_req_map while an in-flight enable subsequently rearms the hardware. An overlapping sysfs/ioctl request can likewise leave an empty map with the source enabled, so the final disable now always masks and drains an empty PPS map. The shortcut remains while another subscription is active.
Quoted 1 line
why do we need it now?
The v2 teardown exception covered a disable that had cleared the map and dropped the spinlock but had not yet completed synchronize_irq(). The previous mutex version held its lock through the IRQ drain. This local revision removes the stopping flag and its special-case condition: core cleanup runs after active requests finish, and an empty map is disabled and drained regardless of its prior value.
The source-derived ASan/UBSan removal/shared-PPS tests pass 100 runs, and seven deliberate regressions fail assertions. Five KUnit cases using real PTP register/unregister pass in QEMU with KASAN and lockdep; the old core fails all five. The KUnit callback models events, and the source-derived tests model MMIO/IRQs. Neither is a physical Time Card removal test.
I have preserved your Reviewed-by tags on the other three unchanged fixes. Thank you for reviewing them.
Ahmad
Vadim Fedorenko
maintainerRe: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
Quoted 9 lines · Ahmad Byagowi
Quoted 1 line · Vadim Fedorenko
enable()callback has to setPTP_PF_EXTTSfunctionThanks. I tested the cleanup path. Recording an assignment makes the core disable that channel, but
ptp_ocpexposes six timestamp channels and only four SMA descriptors. TS0 is the internal GNSS source and TS5 is the PHC source. All six can be enabled without pin assignments. Four descriptors cannot record that state without rejecting requests or changing the pin interface.extts_enablesysfs also reachesenable()without an assignment.
Fair point. Pins are pins, time stampers are time stampers. We have to disable things which may trigger interrupts, the time stampers.
Quoted 4 lines
Would you and Richard prefer disabling all
n_ext_tschannels inptp_disable_all_events(), followed by the existing PPS disable? That keeps cleanup afterposix_clock_unregister(), without inventing pin assignments. I have prepared and tested that alternative locally, not posted it yet.
Yes, it's better to make correct core PTP cleanup function.
Quoted 7 lines
I also removed ptp_ocp's preliminary disable loop. Otherwise it can clear
pps_req_mapwhile an in-flight enable subsequently rearms the hardware. An overlapping sysfs/ioctl request can likewise leave an empty map with the source enabled, so the final disable now always masks and drains an empty PPS map. The shortcut remains while another subscription is active.
Quoted 8 lines
Quoted 1 line
why do we need it now?
The v2 teardown exception covered a disable that had cleared the map and dropped the spinlock but had not yet completed
synchronize_irq(). The previous mutex version held its lock through the IRQ drain. This local revision removes the stopping flag and its special-case condition: core cleanup runs after active requests finish, and an empty map is disabled and drained regardless of its prior value.
Could you please keep more context while quoting? It's really hard to follow the conversation otherwise
Re: [PATCH net v2 1/4] ptp: ocp: prevent timestamp rearming during detach
Quoted 14 lines · Vadim Fedorenko
Quoted 9 lines · Ahmad Byagowi
Quoted 1 line · Vadim Fedorenko
enable()callback has to setPTP_PF_EXTTSfunctionThanks. I tested the cleanup path. Recording an assignment makes the core disable that channel, but
ptp_ocpexposes six timestamp channels and only four SMA descriptors. TS0 is the internal GNSS source and TS5 is the PHC source. All six can be enabled without pin assignments. Four descriptors cannot record that state without rejecting requests or changing the pin interface.extts_enablesysfs also reachesenable()without an assignment.Fair point. Pins are pins, time stampers are time stampers. We have to disable things which may trigger interrupts, the time stampers.
Quoted 6 lines
Quoted 4 lines
Would you and Richard prefer disabling all
n_ext_tschannels inptp_disable_all_events(), followed by the existing PPS disable? That keeps cleanup afterposix_clock_unregister(), without inventing pin assignments. I have prepared and tested that alternative locally, not posted it yet.Yes, it's better to make correct core PTP cleanup function.
Thanks. V3 follows that direction: disable all n_ext_ts channels in ptp_disable_all_events(), followed by the existing PPS disable. Pin descriptors and SMA routing stay unchanged. The driver's preliminary timestamp-disable loop is removed, so final shutdown runs after sysfs callbacks and active ioctls have finished, while the clock is still alive.
Quoted 15 lines · You also
Quoted 6 lines
I also removed ptp_ocp's preliminary disable loop. Otherwise it can clear
pps_req_mapwhile an in-flight enable subsequently rearms the hardware. An overlapping sysfs/ioctl request can likewise leave an empty map with the source enabled, so the final disable now always masks and drains an empty PPS map. The shortcut remains while another subscription is active.Quoted 8 lines
Quoted 1 line
why do we need it now?
The v2 teardown exception covered a disable that had cleared the map and dropped the spinlock but had not yet completed
synchronize_irq(). The previous mutex version held its lock through the IRQ drain. This local revision removes the stopping flag and its special-case condition: core cleanup runs after active requests finish, and an empty map is disabled and drained regardless of its prior value.
Quoted 2 lines
Could you please keep more context while quoting? It's really hard to follow the conversation otherwise
Sorry, I trimmed the original question too far. Here is the code and the full question from your 19 November review:
Quoted 9 lines
drivers/ptp/ptp_ocp.c ptp_ocp_ts_enable(void *priv, u32 req, bool enable) · line 2573
Quoted 4 lines
drivers/ptp/ptp_ocp.c +1
-3-/* 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?
drivers/ptp/ptp_ocp.c ptp_ocp_ts_enable(void *priv, u32 req, bool enable) · line 2575
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+if ((!!old_map ^ !!bp->pps_req_map) ==0 && !bp->ts_stopping) + goto out;
In v1, the mutex stayed held through synchronize_irq(). In v2, the spinlock had to be released before that sleeping operation. Another disable could therefore observe an empty subscription map while the first disable still had an IRQ to drain. The ts_stopping exception made detach drain it too, instead of returning solely because the map was unchanged.
V3 removes that flag and the added spinlock section. After user interfaces are removed and their active operations have drained, core cleanup disables each channel. In ptp_ocp_ts_enable(), the shortcut becomes:
if (old_map && bp->pps_req_map)
return 0;This retains the shared source while a PPS or EXTTS subscriber remains. An empty map always takes the mask/disable/readback/synchronize_irq path. That also handles an earlier overlapping sysfs enable and ioctl disable which left the map empty but the hardware enabled. This final shutdown change is not a claim to serialize every normal-operation sysfs/ioctl race.
The refreshed source-derived removal/shared-PPS tests pass 100 runs and reject all seven deliberate regressions. The routing fixes are unchanged and retain your Reviewed-by tags. I have posted the signed four-patch v3 series to net in a separate thread:
https://lore.kernel.org/r/[email protected]
The cover links this discussion and explains replacement of the older pending series. Thank you for reviewing the changes.
Ahmad
PATCH v2 2/4 ptp: ocp: use hardware selectors in DPLL frequency operations
In reply to Ahmad ByagowiThe selector table index is not the hardware selector value. Passing the index to the SMA setter can select unrelated signals, 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.
--- drivers/ptp/ptp_ocp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +3 -1
@@ -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) {
Re: [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
Quoted 41 lines · Ahmad Byagowi
The selector table index is not the hardware selector value. Passing the index to the SMA setter can select unrelated signals, or fail on ART. Use the table value, as the sysfs path already does.
Mask the direction enable bit before the frequency lookup. Otherwise an enabled, direction-configurable pin has no matching table entry and its DPLL get or dump fails. Apply both corrections to all board variants.
Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. The driver object builds on current net with W=1 and KCFLAGS=-Werror. No physical card was tested.
Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.
Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")Signed-off-by Ahmad Byagowi <[email protected]>--- drivers/ptp/ptp_ocp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/ptp/ptp_ocp.c +2
-1@@ -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 ; }
drivers/ptp/ptp_ocp.c static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, · line 5928
Quoted 7 lines
drivers/ptp/ptp_ocp.c +1
-0@@ -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) {
[email protected]
AI reviewRe: [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
In reply to Ahmad ByagowiThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] On ADVA TimeCard X1 boards (PCI_DEVICE_DATA(ADVA, TIMECARD_X1) -> ocp_adva_x1_sma_op), DPLL get and dump can still fail for an…
--
ptp: ocp: use hardware selectors in DPLL frequency operations
The DPLL frequency_set op now passes the selector table value to ptp_ocp_sma_store_val() instead of the table index. The frequency_get op now masks the readback with SMA_SELECT_MASK before the table lookup, so the direction enable bit does not prevent a match.
Quoted 4 lines
drivers/ptp/ptp_ocp.c +0
-0
[ ... ]
drivers/ptp/ptp_ocp.c static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, · line 5928
Quoted 8 lines
drivers/ptp/ptp_ocp.c +1
-0@@ -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) {
[Severity: High]
Does this fully fix the get/dump failure on ADVA TimeCard X1 boards? The commit message says:
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.
ptp_ocp_dpll_direction_set() switches a pin to input with selector 0:
return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr + 1);
When the direction is not fixed, ptp_ocp_sma_store_val() adds the enable bit:
if (!sma->fixed_dir)
val |= SMA_ENABLE;The hardware therefore holds 0x8000. With the new mask, the readback in ptp_ocp_dpll_frequency_get() becomes 0. However, ptp_ocp_adva_x1_sma_in[] has no 0x0000 entry:
static const struct ocp_selector ptp_ocp_adva_x1_sma_in[] = {
{ .name = "PPS1", .value = 0x0001, .frequency = 1 },
...
{ .name = "None", .value = SMA_DISABLE, .frequency = 0 },The "None" entry is BIT(16), and SMA_SELECT_MASK clears that bit. The lookup finds no entry and returns -EINVAL.
On X1 the direction is configurable (sma_map2->gpio2 != 0xffffffff in ptp_ocp_sma_fb_init()). In that case, does a direction change to input through DPLL leave the pin in a state that frequency_get cannot decode?
If so, the error has three effects:
dpll_msg_add_pin_freq() passes the error up, so DPLL_CMD_PIN_GET fails for that pin.
dpll_nl_pin_get_dumpit() only skips -ENODEV, so a system-wide pin dump also stops with -EINVAL.
dpll_pin_freq_set() calls frequency_get() before frequency_set(). It fails with "unable to get old frequency value", so the pin cannot be moved to a valid frequency through DPLL either. The only way to recover is through sysfs.
A later commit in the series, "ptp: ocp: report disabled SMA inputs consistently over DPLL", maps disabled inputs to SMA_DISABLE ("None"). That handles the disabled-input case. The override only applies when sma->disabled is set, though, and direction_set leaves disabled false. So the direction_set case still appears to fail at the end of the series (d6d7d7a64ee6).
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119-timecard-common-v2-078fe69f33-0-ahmadexp%40gmail.com
Re: [PATCH net v2 2/4] ptp: ocp: use hardware selectors in DPLL frequency operations
Quoted 7 lines · On Mon, 23 Nov 2026 at 21:49:50 +0000, [email protected] wrote:
ptp_ocp_dpll_direction_set()switches a pin to input with selector 0:return ptp_ocp_sma_store_val(bp, 0, mode, sma_nr + 1);When the direction is not fixed,
ptp_ocp_sma_store_val()adds the enable bit:
Quoted 6 lines
if (!sma->fixed_dir) val |= SMA_ENABLE;The hardware therefore holds
0x8000. With the new mask, the readback inptp_ocp_dpll_frequency_get()becomes 0. However, ptp_ocp_adva_x1_sma_in[] has no0x0000entry:
Thank you. This is a valid failure in v2, and I reproduced the exact direction-change case. It is already addressed by the posted v4 patch 2:
https://lore.kernel.org/r/[email protected]
After the exact-match lookup, v4 handles unmatched input selectors without returning -EINVAL. For this X1 zero selector, no destination establishes a frequency, so the getter returns success with frequency zero (unknown), not a claim that the signal is absent or measured at zero Hz. The DPLL core can then perform a subsequent frequency update. Output selectors still require an exact match.
Quoted 6 lines
A later commit in the series, "ptp: ocp: report disabled SMA inputs consistently over DPLL", maps disabled inputs to
SMA_DISABLE("None"). That handles the disabled-input case. The override only applies whensma->disabledis set, though, anddirection_setleaves disabled false. So thedirection_setcase still appears to fail at the end of the series (d6d7d7a64ee6).
Agreed. This case is distinct from a disabled input. The v4 result does not depend on the disabled-input override: the test asserts that the input is enabled, sma->disabled is false, and readback is exactly 0x8000.
I reran a focused source-derived ASan/UBSan test using the actual driver direction callback, SMA accessors and DPLL core get-before-set function. The v2 getter returns -EINVAL. With the unchanged submitted v4 code, all four X1 connectors pass this sequence:
output -> direction_set(INPUT) -> raw 0x8000, disabled=false frequency_get -> success, frequency=0
DPLL core frequency_set(1) -> success, raw 0x8001, frequency_get=1
This is software validation with stubbed MMIO, not a physical X1 test or an end-to-end netlink dump. No new driver change or respin was needed.
Ahmad
PATCH v2 3/4 ptp: ocp: report disabled SMA inputs consistently over DPLL
In reply to Ahmad ByagowiDisabling 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.
--- drivers/ptp/ptp_ocp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/ptp/ptp_ocp.c +2 -0
@@ -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) {
Re: [PATCH net v2 3/4] ptp: ocp: report disabled SMA inputs consistently over DPLL
Quoted 32 lines · Ahmad Byagowi
Disabling an SMA input clears its mux field. Zero is also the selector for 10 MHz, so a DPLL read reports 10 MHz while sysfs reports None. The DPLL core then treats a request to enable 10 MHz as unchanged and skips the setter, leaving the input disabled.
Substitute
SMA_DISABLEfor 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")Signed-off-by Ahmad Byagowi <[email protected]>--- drivers/ptp/ptp_ocp.c | 2 ++ 1 file changed, 2 insertions(+)drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin, · line 5930
Quoted 8 lines
drivers/ptp/ptp_ocp.c +2
-0@@ -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) {
PATCH v2 4/4 ptp: ocp: correct the DCF output frequency
In reply to Ahmad ByagowiThe output selector table uses 77000 Hz for DCF, whereas the input table and the DPLL supported frequency list use 77500 Hz. A request for the advertised DCF77 frequency consequently fails on an output, and reading that output reports a frequency outside its advertised set.
Use 77500 Hz for the DCF output selector as well.
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.
--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ptp/ptp_ocp.c +1 -1
@@ -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 },
Re: [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency
Quoted 30 lines · Ahmad Byagowi
The output selector table uses 77000 Hz for DCF, whereas the input table and the DPLL supported frequency list use 77500 Hz. A request for the advertised DCF77 frequency consequently fails on an output, and reading that output reports a frequency outside its advertised set.
Use 77500 Hz for the DCF output selector as well.
Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. The driver object builds on current net with W=1 and KCFLAGS=-Werror. No physical card was tested.
Codex prepared the fix, tests and changelog from the review and upstream source, at the request to separate common-driver fixes from WiWi support and validate removal ordering.
Fixes 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")Signed-off-by Ahmad Byagowi <[email protected]>--- drivers/ptp/ptp_ocp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/ptp/ptp_ocp.c +0
-0
drivers/ptp/ptp_ocp.c static const struct ocp_selector ptp_ocp_sma_out[] = { · line 1381
Quoted 8 lines
drivers/ptp/ptp_ocp.c +1
-1@@ -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 },
[email protected]
AI reviewRe: [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency
In reply to Ahmad ByagowiThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] This patch fixes one bad frequency in a selector table, but an identical bug from the same Fixes commit (09eeb3aecc6c) is left in…
- [Low] The commit message describes testing and process for changes this patch does not contain.
--
ptp: ocp: correct the DCF output frequency
This commit changes the DCF entry in the ptp_ocp_sma_out selector table from 77000 Hz to 77500 Hz. That makes it match the input table and the advertised DPLL_PIN_FREQUENCY_DCF77 value.
Quoted 10 lines
Reported by the netdev Sashiko AI review and confirmed by code inspection. Source-derived C regression tests pass with ASan/UBSan; restoring the faulty selector, mask, disabled-state or DCF value makes the corresponding regression fail. Tests use stubbed MMIO, not hardware. 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.
[Severity: Low]
This isn't a bug, but do these paragraphs describe this commit?
The diff only changes the DCF .frequency value in ptp_ocp_sma_out. The selector, mask, disabled-state and removal ordering work mentioned here is not part of this patch. Someone reading this commit by itself, such as a stable backporter, will see validation claims for code it does not touch.
Could the series-level testing notes and the description of tool assistance go in the cover letter or below the '---' separator instead?
The "Reported by the netdev Sashiko AI review" sentence could also become a proper tag, or be dropped since the Link: tag is already there.
drivers/ptp/ptp_ocp.c static const struct ocp_selector ptp_ocp_sma_out[] = { · line 1378
Quoted 10 lines
drivers/ptp/ptp_ocp.c +1
-1@@ -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 },
[Severity: Medium]
Should the "10Mhz" entry in ptp_ocp_art_sma_in be fixed the same way? It comes from the same commit, 09eeb3aecc6c, and looks like the same kind of typo:
drivers/ptp/ptp_ocp.c:
static const struct ocp_selector ptp_ocp_art_sma_in[] = {
{ .name = "PPS1", .value = 0x0001, .frequency = 1 },
{ .name = "10Mhz", .value = 0x0008, .frequency = 1000000 },
{ }
};That value is 1 MHz. The matching "10Mhz" entry in ptp_ocp_art_sma_out uses 10000000, and ptp_ocp_art_sma_init() labels 0x08 as the 10 MHz input:
bp->sma[0].default_fcn = 0x08; /* IN: 10Mhz */
The ART pins advertise ptp_ocp_sma_freq. That list has DPLL_PIN_FREQUENCY_10MHZ and no 1 MHz entry.
This produces the same two symptoms the commit message describes for DCF.
On read, ptp_ocp_dpll_frequency_get()->ptp_ocp_art_sma_get() returns 0x08 for sma[0] in its default mode. The driver then reports 1000000 Hz, which is outside the advertised set.
On write, take a non-fixed ART pin. A request for the advertised 10000000 Hz passes dpll_pin_is_freq_supported() in the DPLL core. The exact match in ptp_ocp_dpll_frequency_set() then finds no entry:
if (tbl[i].frequency == frequency)
so the request fails with -EINVAL. The core rejects a 1 MHz request, so the ART 10 MHz input cannot be selected through the DPLL frequency interface at all.
Could this be fixed in this patch, or in a companion patch with the same Fixes: tag?
Quoted 3 lines
drivers/ptp/ptp_ocp.c +0
-0{ .name = "GEN1", .value = 0x0040 }, { .name = "GEN2", .value = 0x0080 }, { .name = "GEN3", .value = 0x0100 },
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119-timecard-common-v2-078fe69f33-0-ahmadexp%40gmail.com
Re: [PATCH net v2 4/4] ptp: ocp: correct the DCF output frequency
Quoted 11 lines · On Mon, 23 Nov 2026 at 21:49:51 +0000, [email protected] wrote:
Should the "10Mhz" entry in
ptp_ocp_art_sma_inbe fixed the same way? It comes from the same commit,09eeb3aecc6c, and looks like the same kind of typo:
drivers/ptp/ptp_ocp.c:static const struct ocp_selector ptp_ocp_art_sma_in[] = { { .name = "PPS1", .value = 0x0001, .frequency = 1 }, { .name = "10Mhz", .value = 0x0008, .frequency = 1000000 }, { } };
Quoted 5 lines
That value is 1 MHz. The matching "10Mhz" entry in
ptp_ocp_art_sma_outuses 10000000, andptp_ocp_art_sma_init()labels0x08as the 10 MHz input:bp->sma[0].default_fcn = 0x08; /* IN: 10Mhz */
Yes, thank you. This is a real defect in v2. The posted v4 series already includes the separate companion patch 5, with the same Fixes commit:
https://lore.kernel.org/r/[email protected]
It changes the ART input entry to 10000000 Hz. Keeping this separate leaves the DCF correction narrowly scoped and preserves its review tag.
I reran the source-derived ASan/UBSan regression on the unchanged submitted v4 source. It uses the actual ART init/set/get functions and the DPLL core supported-frequency and get-before-set functions:
- A literal 10000000 Hz request succeeds and selects 0x08.
- A 1000000 Hz request is rejected by core validation.
- The fixed-pin default 0x08 reads back as 10000000 Hz.
The pre-fix source failed the ART regression during v4 preparation; the submitted v4 code passes. These tests use stubbed registers, not a physical ART card or an end-to-end netlink session.
Quoted 8 lines
The diff only changes the DCF .frequency value in
ptp_ocp_sma_out. The selector, mask, disabled-state and removal ordering work mentioned here is not part of this patch. Someone reading this commit by itself, such as a stable backporter, will see validation claims for code it does not touch.Could the series-level testing notes and the description of tool assistance go in the cover letter or below the '---' separator instead?
Agreed about the cross-patch claims. The posted v4 DCF patch now describes only the DCF set/readback regression and its software-only validation:
https://lore.kernel.org/r/[email protected]
Detailed test and revision notes are below the separator. Brief discovery, validation and provenance statements remain in the commit message as required by maintainer-netdev.rst and generated-content.rst. The repeated selector, disabled-state and teardown testing claims are removed, and the original report link is retained. No new revision is needed for either of these v2 findings.
Ahmad
Quoted 2 lines · Ahmad Byagowi
These fixes address existing Time Card teardown and routing issues and are independent of the WiWi board support series.
Please treat this four-patch v2 series as withdrawn in favor of the five-patch v4 series posted on November 22. V2 still has all four patches marked New in Patchwork and its implementation remains in the CI pending tree, where it conflicts with the replacement v4 teardown patch.
The replacement series is:
https://lore.kernel.org/r/[email protected]
https://patchwork.kernel.org/series/1219090/
V4 follows Vadim's requested teardown approach: the PTP core disables all timestamp channels after removing the user interfaces, rather than adding the v2 stopping flag and driver locking. It also addresses the selector, combined-route and disabled-input review points, and includes a separate ART 10 MHz frequency correction. Thank you for the review and for pointing out the shortcomings in the earlier revisions.
Current validation:
- All five signed v4 patches apply cleanly to net/main 639a75a3539f and net-next/main 57f165ff2f30. The resulting affected files match their previously tested common-v4 integrations on those respective trees.
- The ptp_ocp.c blob in the reported CI branch, net-next-2026-11-23--03-00, is the same blob used in the local conflict reproduction. Reversing only the four posted v2 patches from that file and applying v4 succeeds and reproduces the tested v4 dependency file. This is an affected-file application check, not a full pending-tree build or a claim that public CI has already passed.
- V4's public 32-bit, allmodconfig-warning, Clang and checkpatch checks report success. The contest check fails on the pending-tree conflict at ptp_ocp.c:2559; contest-hw is blocked by that check.
- The focused source-derived X1 test reproduces v2's -EINVAL after an input-direction change. V4 passes for all four connectors, including the DPLL get-before-set path. The ART tests accept 10 MHz, reject 1 MHz and read back 10 MHz for the fixed default. These use stubbed registers, not physical X1 or ART hardware.
The focused results and relevant v4 patch links are also in these replies:
https://lore.kernel.org/r/[email protected]
https://lore.kernel.org/r/[email protected]
Please remove v2 from the active queue so CI can test v4 without stacking it on this obsolete revision. This status request applies only to v2; v4 remains the series for review. WiWi board support remains separate.
pw-bot: changes-requested
Thanks,
Ahmad