mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ali Rouhi <arouhi@sitime.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: "jiri@resnulli.us" <jiri@resnulli.us>,
	"vadim.fedorenko@linux.dev" <vadim.fedorenko@linux.dev>,
	"arkadiusz.kubalewski@intel.com" <arkadiusz.kubalewski@intel.com>,
	"ivecera@redhat.com" <ivecera@redhat.com>,
	"pabeni@redhat.com" <pabeni@redhat.com>,
	"robh@kernel.org" <robh@kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"cjubran@nvidia.com" <cjubran@nvidia.com>,
	"Oleg.Zadorozhnyi@devoxsoftware.com"
	<Oleg.Zadorozhnyi@devoxsoftware.com>,
	"prabhakar.mahadev-lad.rj@bp.renesas.com"
	<prabhakar.mahadev-lad.rj@bp.renesas.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next v15 09/13] dpll: sit9531x: add support to get and set frequency on pins
Date: Thu, 19 Nov 2026 21:20:18 +0000	[thread overview]
Message-ID: <20261119212014.13180-6-arouhi@sitime.com> (raw)
In-Reply-To: <20261117021818.2220307-1-kuba@kernel.org>

On Mon, 16 Nov 2026 18:18:18 -0800, Jakub Kicinski wrote:

> > +		if (rc)
> > +			goto unpark;
> > +		rc = sit9531x_pll_small_update(sitdev, i);
> > +		if (rc)
> > +			goto unpark;
> > +	}
>
> [Severity: Medium]
> Is a full PLL restart meant to be a side effect of setting one output's
> frequency? regs.h describes the bit as "the restart bit restarts the PLL".
> When PHFL_EN is clear in the profile, the call chain
> sit9531x_output_freq_set() -> sit9531x_output_phase_flush() would glitch
> every output on this PLL and drop its lock. Any PLL cascaded from it would
> also lose its reference.
>
> Nothing marks the channel stale or refreshes the lock state after the
> restart. Would userspace keep seeing the old lock status until the next
> poll?
>
> When PHFL_EN is set, the loop above clears ON_DEMAND_EN and issues
> SMALL_UPDATE on every other armed PLL, then restores them. A request on one
> DPLL device therefore writes registers that belong to the other DPLL
> devices.
>
> The commit message only says:
>
>   The phase flush after it is enabled per PLL, so it realigns every
>   output the PLL drives.
>
> Could it also mention the PLL restart and the writes to other PLLs? The
> later "dpll: sit9531x: add support to adjust output phase" patch also only
> describes a divider-phase restart.

Both are intended and the commit message will say so: a PLL whose
configuration has the flush off is restarted to realign its dividers, as
the documented delay sequence does, and the on-demand enable of the
other PLLs is cleared for the pulse and written back after it, so only
this PLL is armed when the trigger fires. The lock status after a
restart comes from the next poll, at most 500 ms later, as for any other
loss of lock.

> > +	slot = info->clkout_map[out_idx];
> > +
> > +	if (slot > SIT9531X_PAGE_OUTSYS0_SLOT_MAX)
> > +		page = SIT9531X_PAGE_OUTSYS1;
> > +	else
> > +		page = SIT9531X_PAGE_OUTSYS0;
>
> [Severity: Medium]
> For slots above SIT9531X_PAGE_OUTSYS0_SLOT_MAX, the DIVO bytes go to page
> 4. However, sit9531x_prg_enter() only unlocks the key on page 3:
>
>     #define SIT9531X_REG_OUTSYS_DEBUG		SIT9531X_REG(0x03, 0xBD)
>
> regs.h describes this register as "Debug register (same offset,
> per-page)". The comment in sit9531x_prg_commit() says "The debug key
> register unlocks every debug register". Which of these is right?
>
> If page 4 has its own key at 0xBD, would the DIVO writes for slots 6-11 be
> ACKed but dropped? sit9531x_output_freq_set() would then still cache
> fvco / divo as the new rate and return success.

Page 4 is a sub-page of page 3, and the key on page 3 covers it, as it
covers every sub-page. The comment above sit9531x_outsys_debug_open()
states that scope.

> > +	if (rc)
> > +		return rc;
> > +
> > +	rc = sit9531x_output_divo_write(sitdev, out_idx, divo, &back);
> > +	/* NVM update and loop lock */
> > +	ret = sit9531x_prg_commit(sitdev);
>
> [Severity: Medium]
> Suppose sit9531x_output_divo_write() fails partway and its rollback also
> fails. It logs "the divider is part old and part new" and returns an error.
> Is it intended that sit9531x_prg_commit() then writes SIT9531X_UPDATE_NVM
> over that torn 34-bit divider anyway?
>
> The back result is not checked here. sit9531x_prg_abort(), which does
> LOOP_LOCK without UPDATE_NVM, is not used on this path either.
>
> Later in the series prg_abort() is removed, and freq_set() always commits
> ("Always leave PRG_CMD so the loops re-lock"). The torn divider is still
> committed there; the only change is that chan->flush_pending gets set.

Deliberate. That path takes a failed write and a failed rollback, after
which the divider registers hold a value that is neither rate. The
driver banks what the registers hold so the rate read back afterwards is
the rate on the pin, returns the error and notifies the read-back rate.

> > +	if (ret && !rc)
> > +		rc = ret;
> > +	if (rc)
> > +		return rc;
>
> [Severity: Medium]
> What happens if the divider write succeeds, but the UPDATE_NVM write in
> sit9531x_prg_commit() fails while LOOP_LOCK succeeds? loops_open stays
> false, so the background retry never runs. The new DIVO bytes are neither
> rolled back nor committed.
>
> sit9531x_dpll_output_pin_frequency_set() then does:
>
> 	if (rc) {
> 		if (!sit9531x_output_freq_get(sitdev, dpin->id, &hz))
> 			moved |= hz != was;
> 	}
>
> This reads the uncommitted DIVO, caches Fvco / DIVO in out.freq, and calls
> __dpll_pin_change_ntf() as if the rate had changed.
>
> If the divider only takes effect after UPDATE_NVM, could the reported and
> cached rate differ from what the part produces, with nothing correcting it
> later? Later in the series this path also sets chan->flush_pending, but
> UPDATE_NVM is still not retried.

Correct. It takes a failed write of the bank update followed by a
successful loop lock; the request returns the error, but the readback
then shows the new divider. Recording the bank update as pending and
repeating the sequence from the poll is the fix, and I would like to do
it as a follow-up with the other error-path work.

> > +			sitdev->out[out_idx].freq = 0;
> > +		return rc;
> > +	}
> > +
> > +	*frequency = div64_u64(fvco, divo);
> > +	sitdev->out[out_idx].freq = *frequency;
>
> [Severity: Medium]
> sit9531x_get_fvco() returns success when Fref * DIVN is outside the PLL's
> VCO band. Its own comment says such a value "is usually not the rate the
> PLL runs at, as for a PLL fed from another PLL". For that reason,
> sit9531x_output_divo_calc() and sit9531x_output_phase_adjust_set() both
> refuse an out-of-band Fvco.
>
> Should this path also check sit9531x_fvco_in_band()? Without the check, a
> pin get or dump on an output of a cascaded PLL reports and caches
> Fvco / DIVO from the same untrusted Fvco. sit9531x_pin_props_get() also
> seeds the cache through this function at registration.

Intended for now. The band check tells the driver that Fref * DIVN is
suspect, as for a PLL fed from another PLL, but not what the right rate
is, and it cannot tell that case from a configuration that runs the VCO
outside the nominal band, where the value is correct. So the read paths
report the computed value and the log names the PLL once, while the
write paths refuse because they would program from it. Deriving the
reference of a PLL fed from another PLL removes the case and is planned
as a follow-up.

> >  	bool answered = false;
> >  	int i, rc;
> >  
> > +	/* Retry pending writes first so the reads below see their result */
> > +	if (sitdev->loops_open)
> > +		sit9531x_prg_commit(sitdev);
>
> [Severity: Medium]
> sit9531x_prg_commit() is documented to run after sit9531x_prg_enter(). By
> the time loops_open is set, the failed attempt has already re-locked the
> page 3 debug key at the end of prg_commit():
>
> 	rc3 = sit9531x_write_close(sitdev, SIT9531X_REG_OUTSYS_DEBUG,
> 				   SIT9531X_DEBUG_LOCK_VAL);
>
> This retry therefore writes UPDATE_NVM and LOOP_LOCK to
> SIT9531X_REG_PRG_DIR_GEN while the key is locked and outside PRG_CMD.
> prg_enter() unlocks the key before it writes PRG_DIR_GEN, which suggests
> the key is needed.
>
> If the part ignores the write while the key is locked, the I2C write is
> still ACKed, and this line clears the flag:
>
> 	sitdev->loops_open = !!rc2;
>
> Could the loops then stay unlocked with no further retry? The same applies
> to the retry in sit9531x_dev_stop(), which would also skip its "output
> loops left unlocked at removal" warning. Both retry sites are unchanged at
> the end of the series.

The retry follows the documented frequency-change procedure, which
writes PRG_CMD, the divider, UPDATE_NVM and LOOP_LOCK without opening
the key. No change.

> > +	int rc;
> > +
> > +	mutex_lock(&sitdev->multiop_lock);
> > +	rc = sit9531x_output_freq_get(sitdev, dpin->id, frequency);
> > +	if (rc == -ENODATA)
> > +		*frequency = sit9531x_out_state_get(sitdev, dpin->id)->freq;
>
> [Severity: Low]
> Can this fallback ever return a cached rate? Both -ENODATA paths in
> sit9531x_output_freq_get() set sitdev->out[out_idx].freq = 0 before they
> return. This line therefore always reads 0 and reports success.
>
> For an unrouted or unprogrammed output, the result is
> DPLL_A_PIN_FREQUENCY = 0. That is outside the 1 Hz to 1 GHz range the
> driver advertises for outputs.
>
> Should the comment and the fallback be updated? Alternatively, should the
> cache be left alone on -ENODATA?

Right, the cached read was dead. The callback now reports 0 Hz directly
for an output whose divider chain does not resolve; an error from the
callback would fail the whole pin dump.

> > +	if (rc) {
> > +		struct dpll_pin *dpll_pin;
> > +
> > +		NL_SET_ERR_MSG(extack, "Output frequency set failed");
>
> [Severity: Low]
> Does this message ever reach userspace? dpll_pin_freq_set() in
> dpll_netlink.c overwrites the extack whenever ops->frequency_set() fails:
>
> 	NL_SET_ERR_MSG_FMT(extack, "frequency set failed for dpll_id:%u", dpll->id);
>
> The actual rejection reasons in sit9531x_output_divo_calc() only go to
> dev_dbg. These are: the rate is not exactly Fvco/N, the VCO is out of
> band, the divider is too large, or the output is unrouted. Userspace gets a
> bare -EINVAL with generic text.

True for every driver: the core sets its own message after the callback
returns. The driver keeps the reasons in dev_dbg with the output and the
PLL named; keeping a driver's message in the core is a core change
outside this series.

> > +		mutex_lock(&sitdev->multiop_lock);
> > +		rc = sit9531x_output_freq_get(sitdev, index, &hw_freq);
> > +		mutex_unlock(&sitdev->multiop_lock);
> > +		if (rc && rc != -ENODATA)
> > +			goto err_alloc_ranges;
> > +	}
>
> [Severity: Low]
> Is this comment accurate? Phase adjust does not read sitdev->out[].freq,
> either here or later in the series. sit9531x_output_phase_adjust_set()
> reads DIVO directly ("Take the period from the divider; the cached rate is
> whole hertz"). The only readers are the frequency_get fallback and the was
> value in frequency_set.
>
> A non-ENODATA I2C error here fails pin registration. Is this readback
> needed at probe at all?

The comment was wrong and is corrected: phase adjust takes the period
from the divider. The read at probe stays; it fails the probe on a bus
fault and gives the cached rate, which a failed set is compared against,
its starting value.

  reply	other threads:[~2026-11-19 21:20 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 20:26 [PATCH net-next v15 00/13] dpll: add SiTime SiT9531x DPLL clock driver Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 01/13] dpll: omit pin phase attributes the driver has no value for Ali Rouhi
2026-11-11 15:35   ` Ivan Vecera
2026-11-10 20:26 ` [PATCH net-next v15 02/13] dt-bindings: vendor-prefixes: add SiTime Corporation Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 04/13] dpll: add basic SiTime SiT9531x support Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 06/13] dpll: sit9531x: register DPLL devices and pins Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 07/13] dpll: sit9531x: implement input pin state on a DPLL Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 08/13] dpll: sit9531x: add support to get and set priority on input pins Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 09/13] dpll: sit9531x: add support to get and set frequency on pins Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi [this message]
2026-11-10 20:26 ` [PATCH net-next v15 10/13] dpll: sit9531x: implement output pin state on a DPLL Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 11/13] dpll: sit9531x: add support to adjust output phase Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 12/13] dpll: sit9531x: add support to get phase offset on the connected input pin Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-10 20:26 ` [PATCH net-next v15 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins Ali Rouhi
2026-11-17  2:18   ` Jakub Kicinski
2026-11-19 21:20     ` Ali Rouhi
2026-11-17  9:27 ` [PATCH net-next v15 00/13] dpll: add SiTime SiT9531x DPLL clock driver Paolo Abeni

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=20261119212014.13180-6-arouhi@sitime.com \
    --to=arouhi@sitime.com \
    --cc=Oleg.Zadorozhnyi@devoxsoftware.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=cjubran@nvidia.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ivecera@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=robh@kernel.org \
    --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

all inboxes | Powered by JetHome®