The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: arouhi@sitime.com
Cc: jiri@resnulli.us, ivecera@redhat.com, vadim.fedorenko@linux.dev,
	arkadiusz.kubalewski@intel.com, kuba@kernel.org,
	pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, prabhakar.mahadev-lad.rj@bp.renesas.com,
	cjubran@nvidia.com, Oleg.Zadorozhnyi@devoxsoftware.com,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v17 09/13] dpll: sit9531x: add support to get and set frequency on pins
Date: Thu, 03 Dec 2026 00:39:12 +0000	[thread overview]
Message-ID: <179625835286.3146.13064702356278777587@kernel.org> (raw)
In-Reply-To: <20261201235202.97645-10-arouhi@sitime.com>

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

Critical: 0 · High: 0 · Medium: 1 · Low: 4

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] A torn output divider (part old bytes, part new) gets
  committed to the active NVM bank.
- [Low] For every output, sit9531x_pin_props_get() in
  drivers/dpll/sit9531x/prop.c (lines 319-330) advertises…
- [Low] sit9531x_dpll_output_pin_frequency_get()
  (drivers/dpll/sit9531x/dpll.c:630) calls sit9531x_output_freq_get() on…
- [Low] When an output's divider chain does not resolve (-ENODATA from
  sit9531x_output_freq_get()), sit9531x_dpll_output_pin_frequency_get()…
- [Low] The comment on sit9531x_dpll_input_pin_frequency_get()
  (drivers/dpll/sit9531x/dpll.c:308) reads "Report the first supported-…

--

dpll: sit9531x: add support to get and set frequency on pins

This adds frequency_get for input and XO pins, taken from the firmware
description. It also adds frequency_get and frequency_set for output pins,
computed as Fvco / DIVO and programmed by writing a new DIVO inside the
PRG_CMD state. A phase flush follows each write, and the poll and removal
paths retry a failed bank update.

> diff --git a/drivers/dpll/sit9531x/core.c b/drivers/dpll/sit9531x/core.c
> index 6e06e99e5ff82..bce58b3371130 100644
> --- a/drivers/dpll/sit9531x/core.c
> +++ b/drivers/dpll/sit9531x/core.c
> @@ -463,6 +463,153 @@ static int sit9531x_output_forced_hiz(struct sit9531x_dev *sitdev,

[ ... ]

> +/* Update the NVM bank and leave PRG_CMD */
> +static int sit9531x_prg_commit(struct sit9531x_dev *sitdev)
> +{
> +	int rc, rc2;
> +
> +	rc = sit9531x_write_u8(sitdev, SIT9531X_REG_PRG_DIR_GEN,
> +			       SIT9531X_UPDATE_NVM_BANK);
> +	sitdev->bank_pending = !!rc;
> +	rc2 = sit9531x_prg_relock(sitdev);
> +
> +	return rc ? rc : rc2;
> +}

[ ... ]

> @@ -1199,6 +1346,525 @@ int sit9531x_input_prio_add(struct sit9531x_dev *sitdev, u8 pll_idx,

[ ... ]

> +rollback:
> +	/* The byte whose write failed may have reached the part */
> +	*back = true;
> +	for (j = 0; j <= written && j < 5; j++) {
> +		rb_rc = sit9531x_write_u8(sitdev,
> +					  SIT9531X_REG(page, base_reg - j),
> +					  old_bytes[j]);
> +		if (rb_rc) {
> +			*back = false;
> +			dev_err(sitdev->dev,
> +				"out%u: DIVO rollback failed (%d), the divider is part old and part new\n",
> +				out_idx, rb_rc);
> +			if (!rc)
> +				rc = rb_rc;
> +		}
> +	}
> +
> +	return rc;
> +}

[ ... ]

> +int sit9531x_output_freq_set(struct sit9531x_dev *sitdev, u8 out_idx,
> +			     u8 pll_idx, u64 frequency)
> +{

[ ... ]

> +	rc = sit9531x_prg_enter(sitdev);
> +	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]
Can this commit a torn DIVO to the running configuration?

The rollback in sit9531x_output_divo_write() can fail partway. When it
does, it logs "the divider is part old and part new" and leaves back set
to false. sit9531x_output_freq_set() never looks at back, and
sit9531x_prg_commit() always issues SIT9531X_UPDATE_NVM_BANK. The mixed
divider is then loaded.

If the bank write fails as well, bank_pending is set. Then
sit9531x_dev_chan_states_update() and sit9531x_dev_stop() reissue the bank
update through sit9531x_prg_retry() as soon as the bus answers. Neither
rewrites the old or intended divider first.

For example, take an old DIVO of 0x31 and a new DIVO with a low byte of
0x00. Byte 0 is written, the byte 1 write fails, and the byte 0 rollback
fails. The registers now hold DIVO = 0, and that is what gets committed. A
small torn divider could also push an LVCMOS output past the 250 MHz limit
that sit9531x_dpll_output_pin_frequency_set() enforces.

Later in the series, "dpll: sit9531x: model the inter-PLL sync line as a
pair of pins" consumes back as landed = !back:

    ret = landed ? sit9531x_prg_commit(sitdev) : sit9531x_prg_relock(sitdev);

A failed rollback still gives back == false and so landed == true. The
torn value is still committed, and there is no pending flag to retry the
rollback.

Should a failed rollback skip the bank update and record something the
poll can use to rewrite a consistent divider?

> +	if (ret && !rc)
> +		rc = ret;
> +	if (rc)
> +		return rc;

[ ... ]

> diff --git a/drivers/dpll/sit9531x/dpll.c b/drivers/dpll/sit9531x/dpll.c
> index 3a31d0707127a..25bee483bb5a7 100644
> --- a/drivers/dpll/sit9531x/dpll.c
> +++ b/drivers/dpll/sit9531x/dpll.c
> @@ -305,6 +305,24 @@ sit9531x_dpll_input_pin_direction_get(const struct dpll_pin *pin,
>  	return 0;
>  }
>  
> +/* Report the first supported-frequencies-hz entry */
> +static int
> +sit9531x_dpll_input_pin_frequency_get(const struct dpll_pin *pin,
> +				      void *pin_priv,
> +				      const struct dpll_device *dpll,
> +				      void *dpll_priv, u64 *frequency,
> +				      struct netlink_ext_ack *extack)
> +{
> +	struct sit9531x_dpll_pin *dpin = pin_priv;
> +	struct sit9531x_dpll *sitdpll = dpll_priv;
> +	const struct sit9531x_ref *ref;
> +
> +	ref = sit9531x_ref_state_get(sitdpll->dev, dpin->id);
> +	*frequency = ref->freq;
> +
> +	return 0;
> +}

[Severity: Low]
This isn't a bug, but the comment does not cover every user of this
callback. It is also installed in sit9531x_dpll_xo_pin_ops and
sit9531x_dpll_xo_pin_manual_ops. For the XO, sit9531x_pin_props_get()
takes curr_freq from sitdev->xtal_freq and skips the firmware properties,
so the value is not a supported-frequencies-hz entry.

The XO ops also have no norate variant. If xtal_freq were 0, the XO would
report 0 Hz, while other inputs with no rate leave the attribute out.

[ ... ]

> @@ -567,8 +609,84 @@ sit9531x_dpll_output_pin_direction_get(const struct dpll_pin *pin,

[ ... ]

> +static int
> +sit9531x_dpll_output_pin_frequency_get(const struct dpll_pin *pin,
> +				       void *pin_priv,
> +				       const struct dpll_device *dpll,
> +				       void *dpll_priv, u64 *frequency,
> +				       struct netlink_ext_ack *extack)
> +{
> +	struct sit9531x_dpll_pin *dpin = pin_priv;
> +	struct sit9531x_dpll *sitdpll = dpll_priv;
> +	struct sit9531x_dev *sitdev = sitdpll->dev;
> +	int rc;
> +
> +	mutex_lock(&sitdev->multiop_lock);
> +	rc = sit9531x_output_freq_get(sitdev, dpin->id, frequency);

[Severity: Low]
Is a live hardware read intended on every get and dump here?

sit9531x_output_freq_get() reads the following through sit9531x_get_fvco():

  - the DIVN integer byte
  - 4 numerator bytes
  - 4 denominator bytes
  - the XO doubler register

It then reads 5 DIVO bytes through sit9531x_output_divo_read(). That is
about 15 paged I2C reads per output pin, plus page selects. They all run
under multiop_lock and the core's dpll_lock. With up to 12 outputs, one
pin dump becomes a few hundred I2C transfers.

The earlier commit "dpll: sit9531x: register DPLL devices and pins"
describes the poll as filling "a cache the callbacks answer from, so a
netlink call does not become a burst of I2C transfers".

This patch keeps sitdev->out[].freq up to date but only uses it as was in
the set path. Could the get answer from the cached value? If not, could
the commit message mention the departure?

> +	if (rc == -ENODATA)
> +		*frequency = 0;
> +	mutex_unlock(&sitdev->multiop_lock);
> +
> +	return rc == -ENODATA ? 0 : rc;
> +}

[Severity: Low]
When the divider chain does not resolve, this emits DPLL_A_PIN_FREQUENCY
= 0. That is below the 1 Hz minimum that sit9531x_pin_props_get()
advertises for the pin, and userspace cannot tell it from a real reading.
For inputs with no rate, the same patch adds
sit9531x_dpll_input_pin_norate_ops and
sit9531x_dpll_input_pin_norate_manual_ops so the attribute is left out
instead.

Both approaches work around dpll_msg_add_pin_freq() in dpll_netlink.c,
which fails the whole pin dump on any error:

	ret = ops->frequency_get(pin, dpll_pin_on_dpll_priv(dpll, pin), dpll,
				 dpll_priv(dpll), &freq, extack);
	if (ret)
		return ret;

The phase_adjust, phase_offset and ffo helpers already treat -ENODATA as
an absent attribute. The first patch of this series, "dpll: omit pin phase
attributes the driver has no value for", added that handling because "a
zero cannot be told from a measurement". The same reasoning applies here.

Would it be better to give dpll_msg_add_pin_freq() the same -ENODATA
handling and return -ENODATA from here? That would avoid making 0 Hz part
of the uAPI, and it would also remove the need for the separate norate
input ops.

> +
> +static int
> +sit9531x_dpll_output_pin_frequency_set(const struct dpll_pin *pin,

[ ... ]

> +	mutex_lock(&sitdev->multiop_lock);
> +	/* The advertised range is the same for every output mode */
> +	if (sitdev->out[dpin->id].cmos &&
> +	    frequency > SIT9531X_OUT_FREQ_CMOS_MAX_HZ) {
> +		mutex_unlock(&sitdev->multiop_lock);
> +		NL_SET_ERR_MSG(extack,
> +			       "Frequency above the 250 MHz limit of an LVCMOS output");
> +		return -EINVAL;
> +	}

[Severity: Low]
Should the supported set advertised for an LVCMOS output stop at 250 MHz?

sit9531x_pin_props_get() advertises the same rates for every output: 1 Hz
to 800 MHz, plus 61.44 MHz times {15, 20, 24, 30, 32, 40, 48}, up to about
2.949 GHz. It does not check sitdev->out[index].cmos. That flag is already
known at probe, because sit9531x_output_mode_fetch() runs in
sit9531x_dev_state_fetch() before the pins are registered.

dpll_pin_freq_set() in the core checks the request only against
freq_supported. When the driver then fails, the core overwrites the
message set here:

	NL_SET_ERR_MSG_FMT(extack,
			   "frequency set failed for dpll_id:%u",
			   dpll->id);

So a user who picks an advertised rate above 250 MHz on a CMOS output gets
-EINVAL with only the generic message.

The continuous 1 Hz to 800 MHz range has a milder form of the same gap.
sit9531x_output_divo_calc() accepts only exact Fvco/N values, and it
reports the reason only through dev_dbg().

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201235202.97645-1-arouhi%40sitime.com

  reply	other threads:[~2026-12-03  0:39 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 23:52 [PATCH net-next v17 00/13] dpll: add SiTime SiT9531x DPLL clock driver Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 02/13] dt-bindings: vendor-prefixes: add SiTime Corporation Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 01/13] dpll: omit pin phase attributes the driver has no value for Ali Rouhi
2026-12-01 23:52 ` [PATCH net-next v17 04/13] dpll: add basic SiTime SiT9531x support Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 03/13] dt-bindings: dpll: add SiTime SiT95316 clock generator Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 05/13] dpll: sit9531x: read DPLL types and pin properties from system firmware Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 06/13] dpll: sit9531x: register DPLL devices and pins Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 08/13] dpll: sit9531x: add support to get and set priority on input pins Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 07/13] dpll: sit9531x: implement input pin state on a DPLL Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 09/13] dpll: sit9531x: add support to get and set frequency on pins Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko [this message]
2026-12-01 23:52 ` [PATCH net-next v17 10/13] dpll: sit9531x: implement output pin state on a DPLL Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 11/13] dpll: sit9531x: add support to adjust output phase Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 12/13] dpll: sit9531x: add support to get phase offset on the connected input Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko
2026-12-01 23:52 ` [PATCH net-next v17 13/13] dpll: sit9531x: model the inter-PLL sync line as a pair of pins Ali Rouhi
2026-12-03  0:39   ` netdev-bot+sashiko

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=179625835286.3146.13064702356278777587@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=Oleg.Zadorozhnyi@devoxsoftware.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=arouhi@sitime.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