mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction
@ 2026-11-26 16:42 Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
                   ` (7 more replies)
  0 siblings, 8 replies; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

This driver series contains the SJA1105 pin-direction fixes and OCP SMA/DPLL
corrections. It is separate from the PTP core series as requested in review.
The PTP core v6 series is a prerequisite; apply this series only after those
core changes. This series contains no ptp_chardev.c or ptp_sysfs.c changes.

Prerequisite PTP core series:
https://lore.kernel.org/r/20261126-timecard-core-v6-0-ahmadexp@gmail.com/

The teardown follow-up removes ptp_ocp's early timestamp-disable loop so the
new core unregister cleanup disables channels after user operations drain.
The existing shared-PPS map shortcut is unchanged. The DCF correction is
unchanged and retains Vadim's Reviewed-by tag; tags were not carried onto
patches changed in this revision.

Validation: strict x86_64 object build for the PTP core, OCP driver and
SJA1105 PTP object with W=1 KCFLAGS=-Werror; source-derived teardown and
sysfs/ioctl race tests; SMA routing, DPLL get/set and ART capability tests;
runtime mutations reject missing sysfs locks. Hardware register and IRQ
operations were stubbed. No physical card or switch was tested.

A coding assistant helped identify the issues, develop the fixes and
regression tests, and prepare changelog text.

Ahmad Byagowi (8):
  net: dsa: sja1105: keep pin function on EXTTS disable
  net: dsa: sja1105: keep pin function on PEROUT disable
  ptp: ocp: preserve timestamp routes on DPLL frequency changes
  ptp: ocp: restore disabled SMA inputs when binding
  ptp: ocp: report disabled SMA inputs as zero Hz
  ptp: ocp: correct the DCF output frequency
  ptp: ocp: match ART DPLL frequencies to selectors
  ptp: ocp: defer timestamp shutdown to clock unregister

 drivers/net/dsa/sja1105/sja1105_ptp.c | 16 ++++--
 drivers/ptp/ptp_ocp.c                 | 83 ++++++++++++++++++++-------
 2 files changed, 71 insertions(+), 28 deletions(-)


base-commit: 4392bb809812ac79449cd0cf1f5e00469ee102d1
prerequisite-patch-id: 6bad78c955ada1724510b31a0276a3208ce76a5c
prerequisite-patch-id: dc638755165b24f907f718a498e20d4aa1c6190a
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:47   ` netdev-bot+sashiko
  2026-11-26 16:42 ` [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

Disabling EXTTS currently selects PTP_PF_EXTTS, changing the shared PTP_CLK pin from periodic output to timestamp input. Only select the EXTTS function while enabling capture; disable continues to clear the state and synchronously stop the timer.

A coding assistant helped analyze the teardown side effect, develop the correction and source-derived regression test, and prepare this changelog. The test exercises the actual function with configuration writes stubbed.

Fixes: 747e5eb31d59 ("net: dsa: sja1105: configure the PTP_CLK pin as EXT_TS or PER_OUT")
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105_ptp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
index 350f958dcb2a..da35805152e0 100644
--- a/drivers/net/dsa/sja1105/sja1105_ptp.c
+++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
@@ -816,9 +816,11 @@ static int sja1105_extts_enable(struct sja1105_private *priv,
 	    (extts->flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
 		return -EOPNOTSUPP;
 
-	rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
-	if (rc)
-		return rc;
+	if (on) {
+		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
+		if (rc)
+			return rc;
+	}
 
 	priv->ptp_data.extts_enabled = on;
 
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:47   ` netdev-bot+sashiko
  2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

Disabling periodic output currently selects PTP_PF_PEROUT even when the shared PTP_CLK pin is configured for external timestamping. Only select the PEROUT function when enabling the output; disable should stop the generator without reprogramming the pin.

A coding assistant helped identify this related pin-direction side effect, develop the correction and regression test, and prepare this changelog. The source-derived test checks the actual callback behavior with configuration writes stubbed.

Fixes: 747e5eb31d59 ("net: dsa: sja1105: configure the PTP_CLK pin as EXT_TS or PER_OUT")
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/net/dsa/sja1105/sja1105_ptp.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
index da35805152e0..7c07f76caccf 100644
--- a/drivers/net/dsa/sja1105/sja1105_ptp.c
+++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
@@ -733,9 +733,11 @@ static int sja1105_per_out_enable(struct sja1105_private *priv,
 
 	mutex_lock(&ptp_data->lock);
 
-	rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
-	if (rc)
-		goto out;
+	if (on) {
+		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
+		if (rc)
+			goto out;
+	}
 
 	if (on) {
 		struct timespec64 pin_duration_ts = {
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
  2026-11-27 16:53   ` Olech, Milena
  2026-11-26 16:42 ` [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding Ahmad Byagowi
                   ` (4 subsequent siblings)
  7 siblings, 2 replies; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

DPLL frequency changes on a combined SMA input currently replace its complete selector value. This silently removes timestamp or counter destinations configured through the SMA sysfs interface.

When changing an input frequency, retain selector bits for destinations that do not define a frequency. Preserve the existing output path and continue to clear disabled inputs. This keeps the timestamp route while changing the frequency-bearing source.

A coding assistant helped identify the route-loss issue, develop the fix and regression test, and prepare this changelog. The test uses the actual selector and DPLL functions with instrumented register access.

Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 47 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 625a85b2dc7e..284908c6abc2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5873,16 +5873,31 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
 	struct ptp_ocp_sma_connector *sma = pin_priv;
 	struct ptp_ocp *bp = dpll_priv;
 	const struct ocp_selector *tbl;
+	u32 val, aux = 0;
 	int sma_nr = (sma - bp->sma);
-	int i;
+	int i, j;
 
 	if (sma->fixed_fcn)
 		return -EOPNOTSUPP;
 
 	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);
+	for (i = 0; tbl[i].name; i++) {
+		if (tbl[i].frequency != frequency)
+			continue;
+
+		if (sma->mode == SMA_MODE_IN) {
+			val = bp->sma_op->get(bp, sma_nr + 1) & SMA_SELECT_MASK;
+			if (sma->disabled)
+				val = 0;
+
+			for (j = 0; tbl[j].name; j++) {
+				if (!tbl[j].frequency && (val & tbl[j].value))
+					aux |= tbl[j].value;
+			}
+		}
+		return ptp_ocp_sma_store_val(bp, tbl[i].value | aux,
+					     sma->mode, sma_nr + 1);
+	}
 	return -EINVAL;
 }
 
@@ -5900,6 +5915,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) {
@@ -5907,7 +5923,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 = {
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
                   ` (2 preceding siblings ...)
  2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
  2026-11-26 16:42 ` [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

The SMA disable state is stored in software and is lost when the driver is unbound. The hardware selector may therefore route an input after a rebind even though userspace had disabled it.

Apply the disabled state during SMA initialization so the hardware mux and software state agree after binding. This fix is independent of DPLL reporting.

A coding assistant helped validate the rebind behavior and prepare the source-derived regression test and changelog.

Fixes: b2c4f0ac53f3 ("ptp: ocp: Add ability to disable input selectors.")
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 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 284908c6abc2..aa18c5e5eba4 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;
+		}
 	}
 }
 
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
                   ` (3 preceding siblings ...)
  2026-11-26 16:42 ` [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
  2026-11-26 16:42 ` [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

A disabled SMA input has no active signal and should report zero frequency through DPLL. The DPLL core reads the current frequency before applying a new value, so reporting the stale selector frequency can prevent a disabled input from being re-enabled.

Report zero for disabled input pins while leaving output and enabled-input reporting unchanged. This complements the separate initialization fix for preserving disabled state across rebind.

A coding assistant helped check the DPLL get-before-set behavior, develop the regression test and prepare this changelog.

Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
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 aa18c5e5eba4..3457c351958d 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5924,6 +5924,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) {
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
                   ` (4 preceding siblings ...)
  2026-11-26 16:42 ` [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
  2026-11-26 16:42 ` [PATCH net v6 7/8] ptp: ocp: match ART DPLL frequencies to selectors Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister Ahmad Byagowi
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

The output selector table uses 77000 Hz for DCF, while the input table and DPLL frequency list use 77500 Hz. Requests for the advertised DCF77 output frequency consequently fail, and reading the output reports an unsupported frequency.

Use 77500 Hz for the DCF output selector.

A coding assistant helped identify and verify the selector mismatch and prepare the regression test and changelog.

Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")

Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
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 3457c351958d..6bfd5792768e 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 },
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 7/8] ptp: ocp: match ART DPLL frequencies to selectors
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
                   ` (5 preceding siblings ...)
  2026-11-26 16:42 ` [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-26 16:42 ` [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister Ahmad Byagowi
  7 siblings, 0 replies; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

The ART input selector named 10Mhz is recorded as 1 MHz, although the pin advertises 10 MHz. In addition, ART pins share a generic capability list that advertises IRIG-B and DCF77 frequencies which the ART selector tables cannot select.

Record the ART input as 10 MHz and give ART pins a supported-frequency list containing only 1 PPS and 10 MHz. This makes DPLL capability validation agree with the available selectors.

A coding assistant helped identify both capability mismatches, develop the source-derived regression tests and prepare this changelog. The tests use the actual ART accessors and DPLL validation with stubbed registers; no physical card was used.

Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 6bfd5792768e..040518895176 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -299,6 +299,11 @@ static struct dpll_pin_frequency ptp_ocp_sma_freq[] = {
 	DPLL_PIN_FREQUENCY_DCF77,
 };
 
+static struct dpll_pin_frequency ptp_ocp_art_sma_freq[] = {
+	DPLL_PIN_FREQUENCY_1PPS,
+	DPLL_PIN_FREQUENCY_10MHZ,
+};
+
 struct ptp_ocp_sma_connector {
 	enum	ptp_ocp_sma_mode mode;
 	bool	fixed_fcn;
@@ -1385,7 +1390,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 },
 	{ }
 };
 
@@ -3138,8 +3143,8 @@ ptp_ocp_art_sma_init(struct ptp_ocp *bp)
 		.board_label = NULL,
 		.type = DPLL_PIN_TYPE_EXT,
 		.capabilities = 0,
-		.freq_supported_num = ARRAY_SIZE(ptp_ocp_sma_freq),
-		.freq_supported = ptp_ocp_sma_freq,
+		.freq_supported_num = ARRAY_SIZE(ptp_ocp_art_sma_freq),
+		.freq_supported = ptp_ocp_art_sma_freq,
 
 	};
 	u32 reg;
-- 
2.54.0 (Apple Git-157)


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

* [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister
  2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
                   ` (6 preceding siblings ...)
  2026-11-26 16:42 ` [PATCH net v6 7/8] ptp: ocp: match ART DPLL frequencies to selectors Ahmad Byagowi
@ 2026-11-26 16:42 ` Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
  7 siblings, 1 reply; 17+ messages in thread
From: Ahmad Byagowi @ 2026-11-26 16:42 UTC (permalink / raw)
  To: netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, arkadiusz.kubalewski,
	jiri, jonathan.lemon

From: ahmadexp <ahmadexp@gmail.com>

ptp_ocp_detach() disables timestamp sources before ptp_clock_unregister() removes the user interfaces. An in-flight request can rearm a source after that early disable.

Rely on the PTP core unregister cleanup to disable timestamp channels after userspace operations have been removed and drained. Keep the shared PPS subscription-map shortcut unchanged. This driver patch depends on the separate PTP core teardown series.

A coding assistant helped trace the detach race, prepare this driver-side change and develop the combined teardown regression test. The test uses the actual callback and cleanup functions with register and IRQ operations stubbed.

Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")

Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
 drivers/ptp/ptp_ocp.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 040518895176..27cf3ab3327c 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -5768,19 +5768,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);
-- 
2.54.0 (Apple Git-157)


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

* Re: [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable
  2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
@ 2026-11-27 16:47   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:47 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The changelog says the coding assistant helped 'develop the
  correction and source-derived regression test' and that 'The test…
- [Low] The commit author is 'ahmadexp <ahmadexp@gmail.com>' but the
  trailer is 'Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>'.

Pre-existing issues:
- [High] Pre-existing teardown race, not introduced by this patch: the
  EXTTS poll timer can be re-armed after it is cancelled in…
- [High] Pre-existing init-order race, not introduced by this patch:
  sja1105_ptp_clock_register() makes the PHC (and its .enable callback)…

--

net: dsa: sja1105: keep pin function on EXTTS disable

This patch changes sja1105_extts_enable() so that the PTP_CLK pin is only
switched to PTP_PF_EXTTS when capture is being enabled. Disabling EXTTS
now only clears the enabled state and stops the poll timer. The pin is no
longer moved away from periodic output.

> A coding assistant helped analyze the teardown side effect, develop the correction and source-derived regression test, and prepare this changelog. The test exercises the actual function with configuration writes stubbed.

[Severity: Low]
The changelog mentions a regression test. The patch only touches
drivers/net/dsa/sja1105/sja1105_ptp.c, and the test is neither included
nor linked. Could the test be included, or the reference dropped?

With sja1105_dynamic_config_write() stubbed, can the test see whether
PTP_CLK keeps driving the periodic output after an EXTTS disable?

Was this change run on SJA1105 hardware? If not, could the changelog say
so, as Documentation/process/coding-assistants.rst asks? Another patch in
the series, "ptp: ocp: match ART DPLL frequencies to selectors", states
that no physical card was used.

> Author: ahmadexp <ahmadexp@gmail.com>
> [ ... ]
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

[Severity: Low]
The email addresses match, but the author name differs from the
Signed-off-by name. checkpatch reports this as FROM_SIGN_OFF_MISMATCH.
Could the git author be set to the name used in the sign-off before
resending? The same mismatch appears on every patch in the series.

> diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
> index 350f958dcb2af..da35805152e05 100644
> --- a/drivers/net/dsa/sja1105/sja1105_ptp.c
> +++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
> @@ -816,9 +816,11 @@ static int sja1105_extts_enable(struct sja1105_private *priv,
>  	    (extts->flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES)
>  		return -EOPNOTSUPP;
>  
> -	rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
> -	if (rc)
> -		return rc;
> +	if (on) {
> +		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
> +		if (rc)
> +			return rc;
> +	}
>  
>  	priv->ptp_data.extts_enabled = on;
>  

[Severity: High]
This isn't a bug introduced by this patch, but the enable path just below
this hunk can re-arm the EXTTS poll timer after teardown has cancelled it:

drivers/net/dsa/sja1105/sja1105_ptp.c:sja1105_extts_enable() {
    ...
	if (on)
		sja1105_ptp_extts_setup_timer(&priv->ptp_data);
    ...
}

sja1105_ptp_clock_unregister() stops the timer before the PHC is
unregistered:

drivers/net/dsa/sja1105/sja1105_ptp.c:sja1105_ptp_clock_unregister() {
    ...
	timer_delete_sync(&ptp_data->extts_timer);
	ptp_cancel_worker_sync(ptp_data->clock);
	...
	ptp_clock_unregister(ptp_data->clock);
	ptp_data->clock = NULL;
}

Userspace can still reach sja1105_extts_enable() with on=1 until
posix_clock_unregister() marks the clock as a zombie inside
ptp_clock_unregister(). Two ways in are a PTP_EXTTS_REQUEST ioctl on an
already open /dev/ptpN and a write to the extts_enable sysfs file:

ptp_extts_request()
  ops->enable(ops, &req, 1)
    sja1105_ptp_enable()
      sja1105_extts_enable()
        sja1105_ptp_extts_setup_timer()
          mod_timer()

ptp_disable_all_events() doesn't undo this. It only disables EXTTS
channels whose pin is set to PTP_PF_EXTTS:

drivers/ptp/ptp_chardev.c:ptp_disable_all_events() {
    ...
		if (info->pin_config[i].func == PTP_PF_EXTTS)
			ptp_disable_pinfunc(info, info->pin_config[i].func,
					    info->pin_config[i].chan);
    ...
}

sja1105_ptp_pin defaults to .func = PTP_PF_NONE, and ptp_extts_request()
doesn't require a pin assignment. The re-armed timer would therefore stay
pending.

sja1105_ptp_extts_timer() re-arms itself and calls
ptp_schedule_worker(ptp_data->clock, 0). Can this touch a freed ptp_clock
after kthread_destroy_worker() or put_device()? Or a NULL clock once
ptp_data->clock is cleared?

And once the devm allocated priv is freed, wouldn't a pending timer_list
be left behind in freed memory?

[Severity: High]
This is also a pre-existing issue, not introduced by this patch.
sja1105_ptp_clock_register() makes the PHC, and its .enable callback,
visible to userspace before the EXTTS timer is set up:

drivers/net/dsa/sja1105/sja1105_ptp.c:sja1105_ptp_clock_register() {
    ...
	ptp_data->clock = ptp_clock_register(&ptp_data->caps, ds->dev);
	...
	timer_setup(&ptp_data->extts_timer, sja1105_ptp_extts_timer, 0);
    ...
}

On the first setup, priv comes from devm_kzalloc_obj(), so timer->function
is NULL and __mod_timer() returns early. An EXTTS enable that lands in this
window is silently dropped. EXTTS then reports as enabled but never polls.

The later setup of a live priv looks more serious. In a multi-switch tree,
removing and re-probing another switch goes through
dsa_switch_remove()->dsa_tree_teardown(). That runs sja1105_teardown() and
then sja1105_setup() on the surviving sja1105.

sja1105_ptp_clock_unregister() uses timer_delete_sync() rather than
timer_shutdown_sync(), so timer->function still points at
sja1105_ptp_extts_timer. An EXTTS enable on the newly registered /dev/ptpN
could then enqueue the timer before timer_setup() runs:

sja1105_setup()
  sja1105_ptp_clock_register()
    ptp_clock_register()        /dev/ptpN is now live
                                  PTP_EXTTS_REQUEST
                                    sja1105_extts_enable(on=1)
                                      mod_timer()
    timer_setup()

Can timer_setup() then reset entry.pprev and timer->flags while the timer
is still linked in the timer wheel?

If so, expiry would seem to reach __hlist_del() with a NULL pprev. Another
outcome is a later timer_delete_sync() that sees the timer as not pending
and leaves it in the wheel.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable
  2026-11-26 16:42 ` [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
@ 2026-11-27 16:47   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:47 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The changelog does not match what was submitted, and it leaves
  out the trigger and the impact.
- [Low] The author identity 'ahmadexp <ahmadexp@gmail.com>' does not
  match the Signed-off-by 'Ahmad Byagowi <ahmadexp@gmail.com>'.
- [Low] In sja1105_per_out_enable()
  (drivers/net/dsa/sja1105/sja1105_ptp.c), the patch wraps the…

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
  sja1105_per_out_enable() still switches the shared PTP_CLK pin to…
- [Medium] This problem wasn't introduced by this patch, but the PTP_CLK
  pin-function state avb->cas_master, kept in the shared in-memory…
- [Medium] This problem wasn't introduced by this patch, but
  sja1105_per_out_enable() copies ptp_data->cmd into a local cmd at line…
- [Medium] This problem wasn't introduced by this patch, but on P/Q/R/S
  parts sja1105_per_out_enable(on=true) switches the PTP_CLK pin to…

--

net: dsa: sja1105: keep pin function on PEROUT disable

This patch changes sja1105_per_out_enable() so that it moves the shared
PTP_CLK pin to the PEROUT function only when the periodic output is being
enabled. Disabling now stops the generator without reprogramming the pin.
Before this, the pin could be switched away from EXTTS by a disable request.

> Disabling periodic output currently selects PTP_PF_PEROUT even when the shared PTP_CLK pin is configured for external timestamping. Only select the PEROUT function when enabling the output; disable should stop the generator without reprogramming the pin.
>
> A coding assistant helped identify this related pin-direction side effect, develop the correction and regression test, and prepare this changelog. The source-derived test checks the actual callback behavior with configuration writes stubbed.

[Severity: Low]
Is the regression test mentioned here included in the submission? The patch
only touches drivers/net/dsa/sja1105/sja1105_ptp.c. Reviewers have nothing
to read or run for "the source-derived test".

The phrase "this related pin-direction side effect" seems to point at the
sibling patch "net: dsa: sja1105: keep pin function on EXTTS disable". If
this commit is read on its own, for example by a stable backporter, what is
it related to?

Could the changelog also say how the bug is triggered and what users see?
On P/Q/R/S parts, userspace can send PTP_PEROUT_REQUEST(2) with a zero
period, or write a zero period to the sysfs period file, while EXTTS is
armed. Before this fix that path was:

ptp_perout_request()
  ops->enable(ops, &req, perout->period.sec || perout->period.nsec)
    sja1105_per_out_enable(on = false)
      sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT)
        avb->cas_master = 1

The pin then became an output. extts_enabled stayed true and the poll timer
kept running, but external edges were no longer captured. The switch could
also drive the pin against an external PPS source.

Both body paragraphs are single lines well over 75 columns, which checkpatch
flags as COMMIT_LOG_LONG_LINE. Documentation/process/coding-assistants.rst
asks for checkpatch-clean submissions and for a statement of what could not
be tested. Was this fix tried on real hardware?

> Fixes: 747e5eb31d59 ("net: dsa: sja1105: configure the PTP_CLK pin as EXT_TS or PER_OUT")
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

[Severity: Low]
The commit author is "ahmadexp <ahmadexp@gmail.com>", but the sign-off is
"Ahmad Byagowi <ahmadexp@gmail.com>". For this case checkpatch warns:

  From:/Signed-off-by: email name mismatch

Could the From: name be changed to match the sign-off? Netdev usually asks
for a resend so the DCO identity is clear. The sibling patches in the series
seem to have the same mismatch.

> diff --git a/drivers/net/dsa/sja1105/sja1105_ptp.c b/drivers/net/dsa/sja1105/sja1105_ptp.c
> index da35805152e05..7c07f76caccf4 100644
> --- a/drivers/net/dsa/sja1105/sja1105_ptp.c
> +++ b/drivers/net/dsa/sja1105/sja1105_ptp.c
> @@ -733,9 +733,11 @@ static int sja1105_per_out_enable(struct sja1105_private *priv,
>  
>  	mutex_lock(&ptp_data->lock);

[Severity: Medium]
This isn't a bug introduced by this patch, but the local cmd is copied from
ptp_data->cmd before this mutex_lock():

sja1105_per_out_enable() {
	...
	struct sja1105_ptp_cmd cmd = ptp_data->cmd;
	...
	mutex_lock(&ptp_data->lock);
	...
}

sja1105_ptp_commit() later writes the whole copy, ptpclkadd included. If
adjtime or settime runs while this caller is waiting on the mutex, can a
stale ptpclkadd be written back to the hardware?

For example, with the cached mode at SET:

perout                          adjtime
cmd = ptp_data->cmd (SET)
mutex_lock() blocks
                                mutex_lock()
                                sja1105_ptp_mode_set(ADD)
                                write delta
                                mutex_unlock()
sja1105_ptp_commit(&cmd)
  hardware back in SET mode

The cache now says ADD, so the next adjtime skips the mode switch in
sja1105_ptp_mode_set():

	if (ptp_data->cmd.ptpclkadd == mode)
		return 0;

Its delta is then written in SET mode, and the PHC is set to roughly the
delta value. In the mirrored case, the next settime is applied as an add.

sja1105_ptp_reset() makes the same unlocked copy. Should both copies be
taken after mutex_lock()?

>  
> -	rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
> -	if (rc)
> -		goto out;
> +	if (on) {
> +		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_PEROUT);
> +		if (rc)
> +			goto out;
> +	}

[Severity: Medium]
This is a pre-existing issue, but the enable path still switches the shared
PTP_CLK pin to output without checking the function the PTP core records in
sja1105_ptp_pin.func. ptp_perout_request() and ptp_extts_request() only
check the index and flags before they call ops->enable(). That leaves the
driver as the only place this could be enforced.

If EXTTS is armed and a PEROUT request with a non-zero period arrives on
index 0, avb->cas_master becomes 1. PTP_PIN_GETFUNC still reports EXTTS and
extts_enabled stays true. Does EXTTS then stop capturing without any error
while its poll keeps running?

The reverse case looks possible too. sja1105_extts_enable(on) sets
cas_master to 0 while the PEROUT generator started by startptpcp may still
be running.

This is how 747e5eb31d59 was designed, with the request choosing the pin
direction, and the changelog keeps that on purpose ("Only select the PEROUT
function when enabling the output"). Should these requests be checked
against the pin assignment?

[Severity: Medium]
This isn't a bug introduced by this patch either. On P/Q/R/S parts the pin
is switched to output here before the request has been checked. Later
failures jump to out, and out only drops the mutex:

		if (pin_duration > U32_MAX) {
			rc = -ERANGE;
			goto out;
		}

Failures from __sja1105_ptp_gettimex() and from the PTPPINST and PTPPINDUR
SPI writes take the same exit.

With a period above about 68.7 seconds, the caller gets -ERANGE. Does the
pin stay driven as an output even though startptpcp was never issued? That
would break an armed EXTTS. It would also undo the safe input default that
sja1105_init_avb_params() sets:

	avb->cas_master = false;

Could the period check, and ideally the register programming, move before
the pin direction change? Restoring the old direction on error would also
work.

[Severity: Medium]
This is a pre-existing issue, but sja1105_change_ptp_clk_pin_func() is
called here with ptp_data->lock held, while sja1105_extts_enable() calls it
with no driver lock at all:

sja1105_extts_enable() {
	...
	if (on) {
		rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS);
		if (rc)
			return rc;
	}

	priv->ptp_data.extts_enabled = on;
	...
}

The PTP core's pincfg_mux does not help here. The sysfs handlers
extts_enable_store() and period_store() call ops->enable() directly.

Can the read-modify-write of avb->cas_master in
sja1105_change_ptp_clk_pin_func() then overlap with a PEROUT enable running
at the same time?

It also looks like this can run during sja1105_static_config_reload(),
which relies on ptp_data.lock:

	/* No PTP operations can run right now */
	mutex_lock(&priv->ptp_data.lock);

If so, a dynamic AVB_PARAMS write could land in the middle of the switch
reset. The uploaded static config could also pick up a half-updated pin
direction.

extts_enabled is written here without ptp_data->lock as well, while
sja1105_rxtstamp_work() reads it under that lock.

>  
>  	if (on) {

[Severity: Low]
This isn't a bug, but the new if (on) block is followed right away by this
existing if (on) block. Could the sja1105_change_ptp_clk_pin_func() call go
inside the existing block, after its local declarations?

>  		struct timespec64 pin_duration_ts = {

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes
  2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
@ 2026-11-27 16:48   ` netdev-bot+sashiko
  2026-11-27 16:53   ` Olech, Milena
  1 sibling, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:48 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 4 · 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] In ptp_ocp_dpll_frequency_set() (drivers/ptp/ptp_ocp.c), the
  value passed to ptp_ocp_sma_store_val() changes from the table index…
- [Medium] The patch makes two user-visible changes to
  ptp_ocp_dpll_frequency_get() that the commit message never mentions.
- [Medium] On SMA inputs, ptp_ocp_dpll_frequency_set() can report success
  for a 10 MHz request without selecting 10 MHz.
- [Medium] ptp_ocp_dpll_frequency_set() now does an unlocked read-modify-
  write of the SMA input selector.
- [Low] The From:/author identity on the commit ("ahmadexp
  <ahmadexp@gmail.com>") does not match the Signed-off-by: name ("Ahmad…

--

ptp: ocp: preserve timestamp routes on DPLL frequency changes

This patch changes ptp_ocp_dpll_frequency_set() so that a DPLL frequency
change on an SMA input keeps the timestamp and counter selector bits, and
so that it programs the selector value instead of the table index. It also
masks the value read in ptp_ocp_dpll_frequency_get() with SMA_SELECT_MASK.
Input pins with combined routes now report a frequency of 0 instead of
failing.

> A coding assistant helped identify the route-loss issue, develop the fix and regression test, and prepare this changelog. The test uses the actual selector and DPLL functions with instrumented register access.
>
> Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

[Severity: Low]
This isn't a bug, but the commit author ("ahmadexp <ahmadexp@gmail.com>")
does not match the Signed-off-by name ("Ahmad Byagowi
<ahmadexp@gmail.com>"). checkpatch reports this as FROM_SIGN_OFF_MISMATCH.
Could the author be set to the real name?

The changelog also mentions a regression test that uses instrumented
register access. The patch only touches drivers/ptp/ptp_ocp.c, though.

Will the test be posted? If it is an out-of-tree harness, should that
description go below the --- line?

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 625a85b2dc7e5..284908c6abc22 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -5873,16 +5873,31 @@ 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);
> +	for (i = 0; tbl[i].name; i++) {
> +		if (tbl[i].frequency != frequency)
> +			continue;
> +
> +		if (sma->mode == SMA_MODE_IN) {
> +			val = bp->sma_op->get(bp, sma_nr + 1) & SMA_SELECT_MASK;
> +			if (sma->disabled)
> +				val = 0;

[Severity: Medium]
Is this read-modify-write of the selector serialized against the other
writers? The DPLL path holds only dpll_lock here. bp->lock is taken only
inside ptp_ocp_sma_fb_set_inputs() and ptp_ocp_sma_adva_set_inputs(),
around the final register merge.

The other writers of the same selector do not take dpll_lock:

- The sysfs path sma1..4_store()->ptp_ocp_sma_store()->
  ptp_ocp_sma_store_val() holds no driver lock.
- The PTP_PIN_SETFUNC path ptp_ocp_verify()->ptp_ocp_sma_store() holds
  only the PTP core pincfg_mux.

Consider this sequence:

CPU0 (DPLL frequency set)
ptp_ocp_dpll_frequency_set()
   val = bp->sma_op->get(...);    /* no TS bits, aux = 0 */

CPU1 (sysfs "IN: PPS1 TS1", or PTP verify "IN: None")
ptp_ocp_sma_store()
   ptp_ocp_sma_store_val()        /* writes the new selector */

CPU0
   ptp_ocp_sma_store_val(bp, tbl[i].value | 0, ...)
      sma->disabled = false;      /* overwrites the selector */

Wouldn't CPU1's TS1 route, or its disable, be lost while both callers
report success? That is the same route loss the commit message describes.

Would one driver mutex held across the read, the aux computation and the
store close this? It would need to cover sysfs, PTP verify and the DPLL
ops. Merging the preserved bits inside the bp->lock section is another
option.

> +
> +			for (j = 0; tbl[j].name; j++) {
> +				if (!tbl[j].frequency && (val & tbl[j].value))
> +					aux |= tbl[j].value;
> +			}
> +		}
> +		return ptp_ocp_sma_store_val(bp, tbl[i].value | aux,
> +					     sma->mode, sma_nr + 1);

[Severity: Medium]
What happens here when 10 MHz is requested on an input that already has a
timestamp route? In ptp_ocp_sma_in and ptp_ocp_adva_sma_in, the 10 MHz
selector is encoded as zero:

    { .name = "10Mhz",  .value = 0x0000,      .frequency = 10000000 },

So tbl[i].value | aux is just aux.

Take an input configured through sysfs as "IN: PPS1 TS1" (0x5):

- frequency_get reports 1 Hz, so dpll_pin_freq_set() calls frequency_set.
- aux becomes 0x4, and ptp_ocp_sma_store_val() writes 0x4. That clears
  PPS1 and leaves only TS1.
- The op returns 0, and dpll_pin_freq_set() sends
  __dpll_pin_change_ntf().

In this driver's encoding, 10 MHz means no selector bits are set. The
readback is therefore TS1 (frequency 0), or 0 Hz through the new combining
loop when several aux bits are set.

Repeating the request is another no-op that succeeds and sends a
notification, because old_freq stays 0.

Doesn't this contradict "This keeps the timestamp route while changing
the frequency-bearing source"? Should this combination be rejected, for
example with -EINVAL or -EBUSY and an extack message? Or is there a defined
way for the zero-valued 10 MHz selector to coexist with the aux
destinations?

[Severity: Medium]
This also changes what gets programmed for both inputs and outputs. The
old code passed the table index i to ptp_ocp_sma_store_val(), and the new
code passes tbl[i].value. The two only agree for the first two entries of
the fb tables (10Mhz = 0, PPS1 = 1).

Inputs (ptp_ocp_sma_in): IRIG is index 5 / value 0x10, and DCF is index 6
/ value 0x20. Before this patch, an IRIG-B (10000 Hz) request programmed
0x5 (PPS1|TS1), and a DCF77 request programmed 0x6 (PPS2|TS1).

Outputs (ptp_ocp_sma_out): an IRIG request used to program 0x5 (PHC|GNSS1)
and now programs 0x10.

The ART tables also differ between index and value: ART PPS1 is index 0
but value 0x1.

The changelog says "Preserve the existing output path", but output
programming changes here. Could the commit message describe this
index-to-value fix? It might also be worth splitting into its own patch,
so maintainers and stable backporters know the IRIG/DCF behavior changes.

[ ... ]

> @@ -5900,6 +5915,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) {
> @@ -5907,7 +5923,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;

[Severity: Medium]
Both of these changes affect what DPLL netlink reports, and the commit
message does not mention either one.

The first is the new mask. ptp_ocp_sma_fb_get() returns the 16-bit field,
which includes SMA_ENABLE (bit 15):

    return (ioread32(gpio) >> shift) & 0xffff;

ptp_ocp_sma_store_val() also ORs SMA_ENABLE into every value on !fixed_dir
boards. On configurable fb and ADVA boards, the old exact match
val == tbl[i].value could therefore never succeed, and frequency_get
returned -EINVAL.

dpll_msg_add_pin_freq() passes that error on, so pin GET and dump failed
for those pins. dpll_pin_freq_set() also failed before it could reach
frequency_set.

With the mask, pin GET succeeds on those boards, and DPLL frequency set
can be reached there for the first time.

The second is the new fallback. Inputs with no exact match now report
DPLL_A_PIN_FREQUENCY = 0. That covers timestamp-only routes,
mixed-frequency routes and unknown bits.

0 Hz is not in the pin's advertised ptp_ocp_sma_freq list (1PPS, 10MHz,
IRIG-B, DCF77). Userspace has never received it from this driver before.

Could the commit message describe these user-visible changes?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding
  2026-11-26 16:42 ` [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding Ahmad Byagowi
@ 2026-11-27 16:48   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:48 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · 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] The commit message describes a hardware bug that does not
  exist.
- [Medium] The code that disables an SMA input and the new restore code
  in ptp_ocp_sma_fb_init() read the hardware state differently for…
- [Low] There are three submission metadata problems.

--

ptp: ocp: restore disabled SMA inputs when binding

This commit adds a loop to ptp_ocp_sma_fb_init(). At probe time the loop
reads each SMA selector through ptp_ocp_sma_fb_get() and sets
bp->sma[i].disabled when SMA_ENABLE is clear. It also forces disabled
pins to SMA_MODE_IN, so they show as "IN: None" after a rebind.

> The SMA disable state is stored in software and is lost when the driver is unbound. The hardware selector may therefore route an input after a rebind even though userspace had disabled it.
>
> Apply the disabled state during SMA initialization so the hardware mux and software state agree after binding. This fix is independent of DPLL reporting.

[Severity: Medium]
Is this description accurate? The disable path already writes the
disabled state into the hardware input selector:

drivers/ptp/ptp_ocp.c:ptp_ocp_sma_store_val() {
    ...
	if (sma->disabled)
		val = 0;

	if (mode == SMA_MODE_IN)
		val = ptp_ocp_sma_set_inputs(bp, sma_nr, val);
    ...
}

Neither ptp_ocp_detach() nor the probe path writes sma_map1 or
sma_map2. The probe path goes through
ptp_ocp_sma_init()->ptp_ocp_sma_fb_init(). So the cleared input selector
should survive an unbind and rebind. The new loop also only reads
hardware, through ptp_ocp_sma_fb_get(). It updates bp->sma[i].disabled
and bp->sma[i].mode but writes nothing to the mux.

Before the patch, the user-visible problem looks like a reporting one. A
disabled SMA1/SMA2 has its input field cleared, so BIT(15)/BIT(31) of
sma_map1->gpio1 is clear and the pin is detected as an output:

	bp->sma[0].mode = reg & BIT(15) ? SMA_MODE_IN : SMA_MODE_OUT;
	bp->sma[1].mode = reg & BIT(31) ? SMA_MODE_IN : SMA_MODE_OUT;

sysfs then reports it as an output. A disabled SMA3/SMA4 is reported as
an input without "None".

On "independent of DPLL reporting": ptp_ocp_dpll_direction_get() takes
the direction from sma->mode:

	*direction = sma->mode == SMA_MODE_IN ?
				  DPLL_PIN_DIRECTION_INPUT :
				  DPLL_PIN_DIRECTION_OUTPUT;

The patch forces SMA_MODE_IN for disabled pins. After a rebind, the DPLL
netlink direction for a disabled SMA1/SMA2 therefore changes from OUTPUT
to INPUT.

Could the commit message describe the reporting fix and this change to
the DPLL-reported direction instead?

> A coding assistant helped validate the rebind behavior and prepare the source-derived regression test and changelog.

[Severity: Low]
The patch only touches drivers/ptp/ptp_ocp.c, so the regression test
mentioned here isn't included. Can it be posted for reviewers?

This isn't a bug, but the From: name (ahmadexp) doesn't match the
Signed-off-by: name (Ahmad Byagowi), and checkpatch will flag that. The
body paragraphs are also not wrapped at 75 columns.

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 284908c6abc22..aa18c5e5eba45 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);

[Severity: Medium]
For SMA1/SMA2, can this miss a pin that was disabled while it was
already in input mode?

If the pin is already SMA_MODE_IN, ptp_ocp_sma_store_val() skips the
direction switch, so only the input selector is cleared:

	if (mode != sma->mode) {
		if (mode == SMA_MODE_IN)
			ptp_ocp_sma_set_output(bp, sma_nr, 0);
		...
	}
	...
	if (sma->disabled)
		val = 0;

On rebind, the SMA1/SMA2 direction comes only from the input-enable bit
in sma_map1->gpio1, so the disabled pin is first classified as
SMA_MODE_OUT. Because of that mode, ptp_ocp_sma_fb_get() then reads the
output register:

	else
		gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2;

disabled is set only if SMA_ENABLE is also clear in sma_map2->gpio2.

Suppose the output half has SMA_ENABLE set while the pin is in input
mode. Then the "IN: None" setting is not restored, and the pin comes
back as an enabled output, the same as before the patch.

Every direction switch in the driver clears the other half, so this
state would have to come from the firmware power-on defaults for
sma_map2->gpio2. I couldn't verify those defaults. SMA3/SMA4 don't seem
affected, because their direction comes from the output-enable bit.

Should the restore check the input selector for these pins? Or should
the disable path also clear the output half?

> +			/* Both buffers disabled: report None. */
> +			if (bp->sma[i].disabled)
> +				bp->sma[i].mode = SMA_MODE_IN;
> +		}
>  	}
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz
  2026-11-26 16:42 ` [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
@ 2026-11-27 16:48   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:48 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The changelog blames a 'stale selector frequency', but that is
  not what happens on the normal disable path.
- [Low] Two submission-hygiene problems.

--

ptp: ocp: report disabled SMA inputs as zero Hz

This commit makes ptp_ocp_dpll_frequency_get() report zero frequency for
disabled SMA input pins by forcing the selector value to SMA_DISABLE. The
goal is to let a DPLL frequency set re-enable a disabled input, since the
DPLL core compares the request against the current frequency first.

> A disabled SMA input has no active signal and should report zero frequency through DPLL. The DPLL core reads the current frequency before applying a new value, so reporting the stale selector frequency can prevent a disabled input from being re-enabled.

[Severity: Low]
Does "stale selector frequency" accurately describe what happens here?

When an input is disabled through sysfs, ptp_ocp_sma_store_val() writes 0
to the selector instead of leaving the old value in place:

drivers/ptp/ptp_ocp.c:ptp_ocp_sma_store_val() {
    ...
	if (sma->disabled)
		val = 0;
    ...
}

In ptp_ocp_sma_in[] and ptp_ocp_adva_sma_in[], selector 0x0000 is the
10 MHz entry:

	{ .name = "10Mhz",  .value = 0x0000,      .frequency = 10000000 },

So before this patch, a disabled input always read back as 10 MHz. It did
not read back as the previously configured source. For example, an input
set to PPS1 and then disabled would report 10 MHz, not 1 Hz.

The result is that only a 10 MHz re-enable request was silently dropped,
by this check in dpll_pin_freq_set():

	if (freq == old_freq)
		return 0;

On adva_x1 boards, ptp_ocp_adva_x1_sma_in[] has no 0x0000 entry. A
disabled input there already reported 0, so those boards were not
affected.

The code change itself looks correct. Could the changelog describe the
clash between the disabled value and the 0x0000 / 10 MHz encoding? It
would also help to name the affected frequency and boards, so backporters
can judge which boards and requests were affected.

> A coding assistant helped check the DPLL get-before-set behavior, develop the regression test and prepare this changelog.

[Severity: Low]
This isn't a bug, but which regression test does this refer to? The commit
only adds two lines to drivers/ptp/ptp_ocp.c and includes no selftest or
KUnit change, so the test can't be reviewed or run.

> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

The author line is "ahmadexp <ahmadexp@gmail.com>", but the Signed-off-by
is "Ahmad Byagowi <ahmadexp@gmail.com>". The email matches and the name
does not, which checkpatch reports as a From/Signed-off-by name mismatch.

If applied as is, the commit would be credited to "ahmadexp". The other
patches in the series have the same metadata.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency
  2026-11-26 16:42 ` [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
@ 2026-11-27 16:48   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:48 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message says "A coding assistant helped identify and
  verify the selector mismatch and prepare the regression test and…
- [Low] The commit author is "ahmadexp <ahmadexp@gmail.com>" but the
  Signed-off-by is "Ahmad Byagowi <ahmadexp@gmail.com>".

--

ptp: ocp: correct the DCF output frequency

This commit changes the DCF entry in the ptp_ocp_sma_out[] selector table
in drivers/ptp/ptp_ocp.c from 77000 Hz to 77500 Hz. The output table then
matches the input table and the DPLL frequency list, so requests for the
DCF77 output frequency no longer fail.

> A coding assistant helped identify and verify the selector mismatch and
> prepare the regression test and changelog.

[Severity: Low]
This isn't a bug, but which regression test does this sentence refer to?

The patch only changes one line in drivers/ptp/ptp_ocp.c. No selftest or
KUnit test is added here or elsewhere in the series.

Should the sentence say that the test was only used for out-of-tree
verification? The other option is to submit the test with the series.

> Author: ahmadexp <ahmadexp@gmail.com>
[ ... ]
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>

[Severity: Low]
This isn't a bug, but the author name ("ahmadexp") does not match the name
in the Signed-off-by ("Ahmad Byagowi"). The email address is the same in
both.

scripts/checkpatch.pl warns about exactly this case:

    WARN("FROM_SIGN_OFF_MISMATCH",
         "From:/Signed-off-by: email name mismatch: $sob_msg\n");

Could the author identity be updated to match the sign-off? The same
mismatch seems to be present on the other commits in the series.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* Re: [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister
  2026-11-26 16:42 ` [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister Ahmad Byagowi
@ 2026-11-27 16:48   ` netdev-bot+sashiko
  0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 16:48 UTC (permalink / raw)
  To: ahmadexp
  Cc: netdev, richardcochran, davem, edumazet, kuba, pabeni,
	vladimir.oltean, vadim.fedorenko, andrew, linux-kernel,
	arkadiusz.kubalewski, jiri, jonathan.lemon

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 1 · High: 1 · Medium: 1 · 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).

- [Critical] In ptp_ocp_detach() (drivers/ptp/ptp_ocp.c), the patch
  removes the explicit ptp_ocp_ts_enable(bp->ts0..ts4, 0, false) and…
- [High] Removing ptp_ocp_ts_enable(bp->pps, ~0, false) from
  ptp_ocp_detach() leaves the core's PTP_CLK_REQ_PPS request as the only…
- [Medium] The commit is not self-contained but has a Fixes: tag for
  627366c51145 ("ptp: ocp: fix resource freeing order").

--

ptp: ocp: defer timestamp shutdown to clock unregister

This patch removes the explicit ptp_ocp_ts_enable() calls for ts0..ts4 and
pps from ptp_ocp_detach(). It relies on the PTP core unregister path to
disable the timestamp channels once the user interfaces are gone. The
commit message says it depends on a separate PTP core teardown series.

Link: https://lore.kernel.org/r/179548551283.3135.17206659598806657887@kernel.org

> This driver patch depends on the separate PTP core teardown series.

[ ... ]

> Fixes: 627366c51145 ("ptp: ocp: fix resource freeing order")

[Severity: Medium]
Which series does this refer to? The only Link: tag points to a single
lore message, not a patch series. There is also no commit ID or stable
dependency note for the prerequisite.

In this tree, ptp_disable_all_events() and ptp_clock_unregister() do not
seem to contain the core change this patch relies on.

The Fixes: target 627366c51145 is the commit that added the early-disable
block being removed here. Because of the Fixes: tag, could stable tooling
pick up this patch without the core series? That would bring the
timestamp IRQ regression described below into stable kernels.

Could the prerequisite be named explicitly, or this patch be sent as part
of the core series?

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 0405188951768..27cf3ab3327c4 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -5768,19 +5768,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);

[Severity: Critical]
Does ptp_disable_all_events() in this tree actually disable these
channels? It only handles pins whose function is PTP_PF_EXTTS, plus one
PPS request:

drivers/ptp/ptp_chardev.c:ptp_disable_all_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);

	/* Disable the PPS event if the driver has PPS support */
	if (info->pps) {
		struct ptp_clock_request req = { .type = PTP_CLK_REQ_PPS };
		info->enable(info, &req, 0);
	}
    ...
}

ptp_ocp has n_ext_ts = 6 but only 4 pins. ptp_ocp_set_pins() allocates
the pins zeroed, so by default they are all PTP_PF_NONE.

EXTTS channels can be enabled by index with no pin assigned. Both
ptp_extts_request() (PTP_EXTTS_REQUEST) and extts_enable_store() do this,
and nothing disables the channel when the fd is closed.

For bp->pps, the core request becomes
ptp_ocp_ts_enable(bp->pps, OCP_REQ_PPS, false). If OCP_REQ_TIMESTAMP
(EXTTS index 5) is also set, pps_req_map stays non-zero. The "no state
change" shortcut then returns early and the PPS/TS5 timestamper stays
armed.

In all of these cases the interrupt is still unmasked and requested when
ptp_clock_unregister() does its final put_device(). That put runs
ptp_clock_release():

drivers/ptp/ptp_clock.c:ptp_clock_release() {
    ...
	bitmap_free(tsevq->mask);
	kfree(tsevq);
	debugfs_remove(ptp->debugfs_root);
	xa_erase(&ptp_clocks_map, ptp->index);
	kfree(ptp);
}

bp->ptp is not cleared. The IRQ is only disabled and freed later, one
source at a time, in ptp_ocp_unregister_ext():

	ext->info->enable(ext, ~0, false);
	pci_free_irq(ext->bp->pdev, ext->irq_vec, ext);

Can a timestamp interrupt in that window write to freed memory?

ptp_ocp_ts_irq()
    ptp_clock_event(ext->bp->ptp, &ev)     /* PTP_CLOCK_EXTTS */
        spin_lock_irqsave(&ptp->tsevqs_lock, flags);
        list_for_each_entry(tsevq, &ptp->tsevqs, qlist)
            enqueue_external_timestamp(tsevq, event);

One way to hit this: enable a channel with "echo '0 1' > extts_enable",
feed a 1PPS signal on the input, then unbind or remove the device.

This seems to reopen the use-after-free that 627366c51145 ("ptp: ocp: fix
resource freeing order") closed.

> -	if (bp->pps)
> -		ptp_ocp_ts_enable(bp->pps, ~0, false);
>  	if (bp->ptp)
>  		ptp_clock_unregister(bp->ptp);

[Severity: High]
With this call gone, is an in-flight PPS interrupt still drained before
pps_unregister_source()?

The only teardown disable left for the PPS event is the core's
PTP_CLK_REQ_PPS request. It goes through
ptp_ocp_enable()->ptp_ocp_ts_enable(bp->pps, OCP_REQ_PPS, false).

If OCP_REQ_TIMESTAMP is also set in pps_req_map, the map stays non-zero.
The function then returns before the intr_mask write and before
synchronize_irq():

drivers/ptp/ptp_ocp.c:ptp_ocp_ts_enable() {
    ...
		/* if no state change, just return */
		if ((!!old_map ^ !!bp->pps_req_map) == 0)
			return 0;
    ...
}

A ptp_ocp_ts_irq() already running on another CPU may have seen
OCP_REQ_PPS set. pps_req_map is a plain field, written under pincfg_mux
and read without a lock in hardirq context:

drivers/ptp/ptp_ocp.c:ptp_ocp_ts_irq() {
    ...
		if (ext->bp->pps_req_map & OCP_REQ_PPS) {
			ev.type = PTP_CLOCK_PPS;
			ptp_clock_event(ext->bp->ptp, &ev);
		}
    ...
}

Meanwhile ptp_clock_unregister() continues:

	ptp_disable_all_events(ptp);
	...
	if (ptp->pps_source)
		pps_unregister_source(ptp->pps_source);

Could pps_event(ptp->pps_source, ...) still be running in that handler
when pps_unregister_source() tears down and frees the pps_device?

Before this patch, the req = ~0 call always set pps_req_map to 0. The
source was masked and synchronize_irq() ran before ptp_clock_unregister().

>  	kfree(bp->ptp_info.pin_config);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126-timecard-driver-v6-0-ahmadexp%40gmail.com

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

* RE: [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes
  2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
  2026-11-27 16:48   ` netdev-bot+sashiko
@ 2026-11-27 16:53   ` Olech, Milena
  1 sibling, 0 replies; 17+ messages in thread
From: Olech, Milena @ 2026-11-27 16:53 UTC (permalink / raw)
  To: Ahmad Byagowi, netdev
  Cc: richardcochran, davem, edumazet, kuba, pabeni, vladimir.oltean,
	vadim.fedorenko, andrew, linux-kernel, Kubalewski, Arkadiusz,
	jiri, jonathan.lemon

On 11/26/26 5:43 PM, Ahmad Byagowi wrote:

>
>DPLL frequency changes on a combined SMA input currently replace its complete selector value. This silently removes timestamp or counter destinations configured through the SMA sysfs interface.
>
>When changing an input frequency, retain selector bits for destinations that do not define a frequency. Preserve the existing output path and continue to clear disabled inputs. This keeps the timestamp route while changing the frequency-bearing source.
>
>A coding assistant helped identify the route-loss issue, develop the fix and regression test, and prepare this changelog. The test uses the actual selector and DPLL functions with instrumented register access.
>
>Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
>Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
>---
> drivers/ptp/ptp_ocp.c | 47 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 42 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
>index 625a85b2dc7e..284908c6abc2 100644
>--- a/drivers/ptp/ptp_ocp.c
>+++ b/drivers/ptp/ptp_ocp.c
>@@ -5873,16 +5873,31 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
> 	struct ptp_ocp_sma_connector *sma = pin_priv;
> 	struct ptp_ocp *bp = dpll_priv;
> 	const struct ocp_selector *tbl;
>+	u32 val, aux = 0;
> 	int sma_nr = (sma - bp->sma);
>-	int i;
>+	int i, j;
> 
> 	if (sma->fixed_fcn)
> 		return -EOPNOTSUPP;
> 
> 	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);
>+	for (i = 0; tbl[i].name; i++) {
>+		if (tbl[i].frequency != frequency)
>+			continue;
>+
>+		if (sma->mode == SMA_MODE_IN) {
>+			val = bp->sma_op->get(bp, sma_nr + 1) & SMA_SELECT_MASK;
>+			if (sma->disabled)
>+				val = 0;
>+
>+			for (j = 0; tbl[j].name; j++) {
>+				if (!tbl[j].frequency && (val & tbl[j].value))
>+					aux |= tbl[j].value;
>+			}
>+		}
>+		return ptp_ocp_sma_store_val(bp, tbl[i].value | aux,
>+					     sma->mode, sma_nr + 1);

One observation on the tables that these functions rely on:

ptp_ocp_art_sma_in has the entry "10Mhz" with .frequency = 1000000, while
ptp_ocp_sma_freq has 10 MHz. So with these tables frequency_set(10 MHz)
finds no entry and returns -EINVAL, and 1 MHz cannot be requested
through the DPLL. Is 1000000 a typo...?

The old code stored the table index , so this patch also changes the
behavior of the devices that use ocp_art_sma_op. Maybe it's worth
mentioning it in the commit message?

BR,
Milena

>+	}
> 	return -EINVAL;
> }
> 
>@@ -5900,6 +5915,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) {
>@@ -5907,7 +5923,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 = {
>-- 
>2.54.0 (Apple Git-157)

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

end of thread, other threads:[~2026-11-27 16:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26 16:42 [PATCH net v6 0/8] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
2026-11-26 16:42 ` [PATCH net v6 1/8] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
2026-11-27 16:47   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 2/8] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
2026-11-27 16:47   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 3/8] ptp: ocp: preserve timestamp routes on DPLL frequency changes Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-27 16:53   ` Olech, Milena
2026-11-26 16:42 ` [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 5/8] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 6/8] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko
2026-11-26 16:42 ` [PATCH net v6 7/8] ptp: ocp: match ART DPLL frequencies to selectors Ahmad Byagowi
2026-11-26 16:42 ` [PATCH net v6 8/8] ptp: ocp: defer timestamp shutdown to clock unregister Ahmad Byagowi
2026-11-27 16:48   ` netdev-bot+sashiko

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

all inboxes | Powered by JetHome®