[PATCH net v5 4/8] ptp: ocp: handle hardware selectors and combined DPLL input routes

From: Ahmad Byagowi

Date: Mon Nov 23 2026 - 23:43:06 EST


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@xxxxxxxxxx
Link: https://lore.kernel.org/r/179538006772.3135.15875996486888374193@xxxxxxxxxx
Signed-off-by: Ahmad Byagowi <ahmadexp@xxxxxxxxx>
---
Changes in v5:
- Renumbered from v4 patch 2; code and commit message unchanged.

Testing: 4,669 input-route combinations and X1 direction-change recovery.
The boundary test also confirms disabled X1 reads zero Hz and re-enables
PPS at this point in the series, before patches 5 and 6.

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 = {