From: Ahmad Byagowi <ahmadexp@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew+netdev@lunn.ch, arkadiusz.kubalewski@intel.com,
davem@davemloft.net, edumazet@kernel.org, jiri@resnulli.us,
kuba@kernel.org, milena.olech@intel.com, pabeni@redhat.com,
richardcochran@gmail.com, vadim.fedorenko@linux.dev
Subject: [PATCH net v7 3/7] ptp: ocp: preserve timestamp routes on DPLL frequency changes
Date: Fri, 27 Nov 2026 11:22:58 -0800 [thread overview]
Message-ID: <20261127-timecard-driver-v7-3-ahmadexp@gmail.com> (raw)
In-Reply-To: <20261127-timecard-driver-v7-0-ahmadexp@gmail.com>
DPLL frequency set uses a table index as a hardware selector and can
replace timestamp or counter destinations selected through sysfs.
Use the encoded selector on inputs and outputs, including ART. Keep
auxiliary input routes while replacing the frequency-bearing source.
Reject a zero-encoded 10 MHz selection when auxiliary routes make it
unrepresentable, without changing the register or connector state.
Serialize the read and write against sysfs, PTP pin assignments and
DPLL direction changes. Keep the existing MMIO spinlock inside the
register accessors.
For readback, mask out the enable bit and report the configured nominal
frequency when combined input routes agree. Report zero when there is
no unambiguous frequency. This does not measure the input signal.
Developed with coding-assistant support using v6 review feedback.
Fixes: 09eeb3aecc6c ("ptp_ocp: implement DPLL ops")
Link: https://lore.kernel.org/r/179579808134.3135.14342336954222031404@kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 64 +++++++++++++++++++++++++++++++++++++++----
1 file changed, 59 insertions(+), 5 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 625a85b2dc7e..3781f6582b7b 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -417,6 +417,7 @@ struct ptp_ocp {
u32 ts_window_adjust;
u64 fw_cap;
struct ptp_ocp_signal signal[OCP_SIGNAL_NUM];
+ struct mutex sma_lock; /* serializes routing and connector state */
struct ptp_ocp_sma_connector sma[OCP_SMA_NUM];
const struct ocp_sma_op *sma_op;
struct dpll_device *dpll;
@@ -3384,6 +3385,7 @@ ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf,
const struct ocp_selector * const *tbl;
u32 val;
+ guard(mutex)(&bp->sma_lock);
tbl = bp->sma_op->tbl;
val = ptp_ocp_sma_get(bp, sma_nr) & SMA_SELECT_MASK;
@@ -3433,6 +3435,7 @@ ptp_ocp_sma_store_val(struct ptp_ocp *bp, int val, enum ptp_ocp_sma_mode mode, i
{
struct ptp_ocp_sma_connector *sma = &bp->sma[sma_nr - 1];
+ lockdep_assert_held(&bp->sma_lock);
if (sma->fixed_dir && (mode != sma->mode || val & SMA_DISABLE))
return -EOPNOTSUPP;
@@ -3473,6 +3476,7 @@ ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr)
enum ptp_ocp_sma_mode mode;
int val;
+ guard(mutex)(&bp->sma_lock);
mode = sma->mode;
val = sma_parse_inputs(bp->sma_op->tbl, buf, &mode);
if (val < 0)
@@ -5838,7 +5842,9 @@ static int ptp_ocp_dpll_direction_get(const struct dpll_pin *pin,
struct netlink_ext_ack *extack)
{
struct ptp_ocp_sma_connector *sma = pin_priv;
+ struct ptp_ocp *bp = priv;
+ guard(mutex)(&bp->sma_lock);
*direction = sma->mode == SMA_MODE_IN ?
DPLL_PIN_DIRECTION_INPUT :
DPLL_PIN_DIRECTION_OUTPUT;
@@ -5857,6 +5863,7 @@ static int ptp_ocp_dpll_direction_set(const struct dpll_pin *pin,
enum ptp_ocp_sma_mode mode;
int sma_nr = (sma - bp->sma);
+ guard(mutex)(&bp->sma_lock);
if (sma->fixed_dir)
return -EOPNOTSUPP;
mode = direction == DPLL_PIN_DIRECTION_INPUT ?
@@ -5873,16 +5880,39 @@ 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;
+ guard(mutex)(&bp->sma_lock);
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;
+ }
+
+ /* Some boards encode 10 MHz as an empty selector. */
+ if (!tbl[i].value && aux) {
+ NL_SET_ERR_MSG(extack,
+ "10 MHz cannot coexist with the current SMA routes");
+ return -EBUSY;
+ }
+ }
+ return ptp_ocp_sma_store_val(bp, tbl[i].value | aux,
+ sma->mode, sma_nr + 1);
+ }
return -EINVAL;
}
@@ -5899,7 +5929,9 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
u32 val;
int i;
+ guard(mutex)(&bp->sma_lock);
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 +5939,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 = {
@@ -5981,6 +6034,7 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
* ptp_ocp_register_resources(), so this sentinel cannot overwrite an
* adapter number the i2c notifier stores during registration.
*/
+ mutex_init(&bp->sma_lock);
mutex_init(&bp->cpld_lock);
spin_lock_init(&bp->cpld_adap_lock);
bp->cpld_i2c_adap_nr = -1;
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-27 19:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 19:22 [PATCH net v7 0/7] ptp: fix OCP routes and SJA1105 pin direction Ahmad Byagowi
2026-11-27 19:22 ` [PATCH net v7 1/7] net: dsa: sja1105: keep pin function on EXTTS disable Ahmad Byagowi
2026-11-27 19:22 ` [PATCH net v7 2/7] net: dsa: sja1105: keep pin function on PEROUT disable Ahmad Byagowi
2026-11-27 19:22 ` Ahmad Byagowi [this message]
2026-11-27 19:22 ` [PATCH net v7 4/7] ptp: ocp: recover SMA direction from both enable bits on bind Ahmad Byagowi
2026-11-27 19:23 ` [PATCH net v7 5/7] ptp: ocp: report disabled SMA inputs as zero Hz Ahmad Byagowi
2026-11-27 19:23 ` [PATCH net v7 6/7] ptp: ocp: correct the DCF output frequency Ahmad Byagowi
2026-11-27 19:23 ` [PATCH net v7 7/7] ptp: ocp: match ART DPLL frequencies to selectors Ahmad Byagowi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127-timecard-driver-v7-3-ahmadexp@gmail.com \
--to=ahmadexp@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=arkadiusz.kubalewski@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=milena.olech@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox