From: sashiko-bot@kernel.org
To: "Ali Rouhi" <arouhi@sitime.com>
Cc: "devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v16 11/13] dpll: sit9531x: add support to adjust output phase
Date: Fri, 20 Nov 2026 22:58:33 +0000 [thread overview]
Message-ID: <sashiko-outbox-226327@kernel.org> (raw)
In-Reply-To: <20261119225752.41846-12-arouhi@sitime.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] dpll: sit9531x: stale phase_adj cached when retime_pending is
set on error
- [Medium] dpll: sit9531x: spurious pin notifications while
retime_pending is set
- [Medium] dpll: sit9531x: phase flush marked fired before trigger is
cleared low
- [Low] dpll: sit9531x: unsigned underflow in
sit9531x_output_phase_read()
--
commit 143a1b7f99e490d4972a0786a10e854c727940fb
Author: Oleg Zadorozhnyi <Oleg.Zadorozhnyi@devoxsoftware.com>
dpll: sit9531x: add support to adjust output phase
This commit adds output phase-adjust support to the sit9531x DPLL driver,
including register encoding/decoding, re-timing on output frequency changes,
and deferred retries for failed phase flushes and re-time writes.
> diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c
> index eb1d10e1fde2e..fd8f0df9116d6 100644
> --- a/drivers/dpll/sit9531x/core.c
> +++ b/drivers/dpll/sit9531x/core.c
[ ... ]
> @@ -1559,6 +1576,65 @@ static int sit9531x_pll_small_update(struct sit9531x_dev *sitdev, u8 pll_idx)
> SIT9531X_SMALL_UPDATE_CMD);
> }
>
> +static int sit9531x_pll_small_update_close(struct sit9531x_dev *sitdev,
> + u8 pll_idx)
> +{
> + return sit9531x_write_pll_close(sitdev, pll_idx,
> + SIT9531X_PLL_REG_SMALL_UPDATE,
> + SIT9531X_SMALL_UPDATE_CMD);
> +}
> +
> +/*
> + * Undo a phase flush: restore the trigger select and the flush enable of @plls
> + * from @armed.
> + */
> +static int sit9531x_phase_flush_undo(struct sit9531x_dev *sitdev,
> + bool ctrl_back, u8 ctrl, u8 plls, u8 armed)
> +{
> + const u8 en = SIT9531X_PLL_PHFL_ON_DEMAND_EN;
> + int rc = 0, ret;
> + u8 i;
> +
> + if (ctrl_back) {
> + rc = sit9531x_write_close(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,
> + ctrl);
> + sitdev->flush_ctrl_pending = !!rc;
> + sitdev->flush_ctrl = ctrl;
> + }
[ ... ]
> @@ -1638,40 +1725,19 @@ static int sit9531x_output_phase_flush(struct sit9531x_dev *sitdev, u8 pll_idx)
> */
> rc = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1,
> ctrl | SIT9531X_DIVO_PHASE_TRIG);
> -
> -restore:
> - ret = sit9531x_write_u8(sitdev, SIT9531X_REG_GPIO_FUNC_CTRL1, orig);
> + fired = !rc;
> +
> +undo:
> + touched = parked;
> + if (armed_here && !(armed_mask & BIT(pll_idx)))
> + touched |= BIT(pll_idx);
> + ret = sit9531x_phase_flush_undo(sitdev, ctrl_back, orig, touched,
> + armed_mask);
> if (ret && !rc)
> rc = ret;
>
> -disarm:
[ ... ]
> +out:
> + sitdev->chan[pll_idx].flush_pending = !fired;
>
> return rc;
> }
[Severity: Medium]
As reported by Jakub Kicinski on v15 [1], if the write in
sit9531x_phase_flush_undo() to restore SIT9531X_REG_GPIO_FUNC_CTRL1 fails,
does sit9531x_phase_flush_undo() disarm the target PLL and re-arm the
parked sibling PLLs while SIT9531X_DIVO_PHASE_TRIG is still asserted high?
Because fired is already true, sitdev->chan[pll_idx].flush_pending is also
cleared, so when sit9531x_phase_flush_undo_retry() later writes
SIT9531X_REG_GPIO_FUNC_CTRL1 low, the pulse can complete with the sibling
PLLs armed instead of the target PLL and the target PLL's flush is not
retried.
[ ... ]
> @@ -1837,12 +1904,361 @@ static int sit9531x_output_divo_read(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
> +int sit9531x_output_phase_read(struct sit9531x_dev *sitdev, u8 out_idx,
> + s64 *phase_ps, bool *beyond)
> +{
> + const struct sit9531x_chip_info *info = sitdev->info;
> + u8 bytes[SIT9531X_OUT_PRG_BYTES], fine;
> + u64 coarse = 0, fvco, ps, divo;
> + int rc;
> +
> + lockdep_assert_held(&sitdev->multiop_lock);
> +
> + if (out_idx >= info->num_outputs)
> + return -EINVAL;
> +
> + *beyond = false;
> +
> + if (!sitdev->out[out_idx].routed)
> + return -ENODATA;
> +
> + rc = sit9531x_get_fvco(sitdev, sitdev->out[out_idx].pll_idx, &fvco);
> + if (rc)
> + return rc;
[ ... ]
> + if (!rc) {
> + u64 t_out_ps = mul_u64_u64_div_u64(divo, 1000000000000ULL,
> + fvco);
> +
> + if (ps >= t_out_ps)
> + ps -= t_out_ps;
> + if (ps > t_out_ps - ps &&
> + t_out_ps - ps <= SIT9531X_OUT_PHASE_ADJ_MAX_PS) {
> + *phase_ps = -(s64)(t_out_ps - ps);
> + return 0;
> + }
> + }
[Severity: Low]
Can t_out_ps - ps underflow when sit9531x_get_fvco() returns an out-of-band
VCO frequency above SIT9531X_FVCO_HIGHBAND_MAX?
sit9531x_get_fvco() only rejects fvco < SIT9531X_FVCO_LOWBAND_MIN and warns
without returning an error when fvco is above the PLL's VCO band. If fvco
is high enough that t_out_ps is less than half of the 210 ps maximum fine
delay (for example, divo == 1 and fine == 7 with fvco > 9.53 GHz), a single
ps -= t_out_ps leaves ps > t_out_ps, wrapping the unsigned subtraction
t_out_ps - ps and returning an unfolded *phase_ps larger than the output
period.
[ ... ]
> @@ -1915,20 +2421,138 @@ int sit9531x_output_freq_get(struct sit9531x_dev *sitdev, u8 out_idx,
[ ... ]
> + if (!same) {
> + /*
> + * The delay bytes take effect on a small-change update, as in
> + * Dely_program_output.py; only a divider rewrite needs the
> + * programming state.
> + */
> + rc = sit9531x_outsys_debug_open(sitdev);
> + if (rc)
> + return rc;
> +
> + rc = sit9531x_output_phase_bytes_write(sitdev, out_idx,
> + new_bytes, old_bytes,
> + &bytes_back);
> + bytes_in = !rc;
> + if (!rc)
> + rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
> + SIT9531X_SMALL_UPDATE_CMD);
> + sit9531x_outsys_debug_close(sitdev);
> + if (rc) {
> + if (bytes_in) {
> + out->phase_stale = true;
> + out->retime_ps = phase_ps;
> + out->retime_pending = true;
> + } else if (!bytes_back) {
> + out->phase_stale = true;
> + chan->flush_pending = true;
> + }
> + return rc;
> + }
> + }
[Severity: Medium]
As reported by Jakub Kicinski on v15 [2], when arming out->retime_pending
on error here (and in the `retime && landed` error branch of
sit9531x_output_freq_set()), does leaving out->phase_adj at its previous
value cause sit9531x_dpll_output_pin_phase_adjust_get() to report the old
delay while a re-time to out->retime_ps is queued?
Because sit9531x_dpll_output_pin_phase_adjust_get() skips
sit9531x_output_phase_read() while out->retime_pending is set, userspace
reads the old out->phase_adj; if userspace then requests that reported
value before the next poll, dpll_pin_phase_adj_set() treats the request as
a no-op and sit9531x_retime_retry() overwrites the pin delay with
out->retime_ps on the next poll tick.
[ ... ]
> @@ -2559,6 +3203,25 @@ static void sit9531x_ho_release_retry(struct sit9531x_dev *sitdev, u8 pll_idx)
> 'A' + pll_idx);
> }
>
> +/*
> + * Re-time the output delay after a failed rate change. Caller must hold
> + * sitdev->multiop_lock.
> + */
> +static void sit9531x_retime_retry(struct sit9531x_dev *sitdev, u8 out_idx)
> +{
> + struct sit9531x_out *out = &sitdev->out[out_idx];
> + s64 was;
> +
> + if (!out->retime_pending)
> + return;
> +
> + was = out->phase_adj;
> + if (!sit9531x_output_phase_adjust_set(sitdev, out_idx, out->retime_ps))
> + dev_info(sitdev->dev, "out%u: delay re-timed\n", out_idx);
> + if (out->phase_adj != was || out->phase_stale)
> + out->ntf_pending = true;
> +}
[Severity: Medium]
Does checking out->phase_stale without `!out->retime_pending` here (and in
sit9531x_dpll_output_pin_phase_adjust_set() and
sit9531x_dpll_output_pin_frequency_set()) emit a pin change notification on
every failed retry while a re-time is pending?
Whenever out->retime_pending is set, out->phase_stale is also true. If
sit9531x_output_phase_adjust_set() fails during sit9531x_retime_retry(),
out->phase_stale sets out->ntf_pending = true, and
sit9531x_dpll_output_ntf_pending() skips hardware readback because
out->retime_pending is true and returns true, sending a notification with
unchanged attributes on every failed poll tick.
[1] https://lore.kernel.org/r/20261117021822.2220376-1-kuba@kernel.org
[2] https://lore.kernel.org/r/20261117021822.2220376-1-kuba@kernel.org
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119225752.41846-1-arouhi@sitime.com?part=11
next prev parent reply other threads:[~2026-11-20 22:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 22:57 [PATCH net-next v16 00/13] dpll: add SiTime SiT9531x DPLL clock driver Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 02/13] dt-bindings: vendor-prefixes: add SiTime Corporation Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 01/13] dpll: omit pin phase attributes the driver has no value for Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 04/13] dpll: add basic SiTime SiT9531x support Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:57 ` [PATCH net-next v16 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 06/13] dpll: sit9531x: register DPLL devices and pins Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:57 ` [PATCH net-next v16 07/13] dpll: sit9531x: implement input pin state on a DPLL Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:57 ` [PATCH net-next v16 08/13] dpll: sit9531x: add support to get and set priority on input pins Ali Rouhi
2026-11-19 22:57 ` [PATCH net-next v16 09/13] dpll: sit9531x: add support to get and set frequency on pins Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:57 ` [PATCH net-next v16 10/13] dpll: sit9531x: implement output pin state on a DPLL Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:58 ` [PATCH net-next v16 11/13] dpll: sit9531x: add support to adjust output phase Ali Rouhi
2026-11-20 22:58 ` sashiko-bot [this message]
2026-11-19 22:58 ` [PATCH net-next v16 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins Ali Rouhi
2026-11-20 22:58 ` sashiko-bot
2026-11-19 22:58 ` [PATCH net-next v16 12/13] dpll: sit9531x: add support to get phase offset on the connected input Ali Rouhi
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=sashiko-outbox-226327@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=arouhi@sitime.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.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