[PATCH net v5 5/8] ptp: ocp: recover disabled SMA inputs when binding the driver

From: Ahmad Byagowi

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


Disabling an SMA input clears its mux field and sets the software-only
disabled flag. After unbind and rebind, the hardware retains the cleared
field but the newly allocated driver state loses the flag. Direction
initialization can then report an output function for a connector with
neither buffer enabled. This happens independently of DPLL support.

Recover the disabled state from the mux enable bits when initializing
direction-configurable FB-style connectors, including ADVA and ADVA X1.
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 fixed-direction firmware's interpretation,
since it does not provide these enable bits. Keep this initialization
fix separate from the DPLL frequency-reporting correction so it can be
backported to kernels predating DPLL support.

Source-derived tests reproduce the lost state with retained mux values
and fresh driver state. The corrected initialization passes 243 modeled
FB/ADVA/X1 rebind states with stubbed MMIO under ASan/UBSan, without mux
writes. No physical rebind was performed.

The issue and missing earlier Fixes tag were reported by Sashiko review.
Codex assisted with the tests, correction and changelog.

Fixes: b2c4f0ac53f3 ("ptp: ocp: Add ability to disable input selectors.")
Link: https://lore.kernel.org/r/179538006912.3135.16971430532149423594@xxxxxxxxxx
Link: https://lore.kernel.org/r/179548551472.3135.11972018356692852897@xxxxxxxxxx
Signed-off-by: Ahmad Byagowi <ahmadexp@xxxxxxxxx>
---
Changes in v5:
- Split initialization from v4 patch 3's DPLL frequency substitution.
- Use b2c4f0ac53f3 as the earlier Fixes tag for the lost rebind state.
- Describe the DPLL-independent behavior and backport scope.

Testing: this patch alone applies to the net base and passes 243 modeled
initialization states, without DPLL calls or mux writes. The unmodified
base reproduces the lost state. Older trees may need context adjustments.

drivers/ptp/ptp_ocp.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index df1a428eb2fe..c4c9d3501edf 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;
+ }
}
}