mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ahmadexp@gmail.com
Cc: netdev@vger.kernel.org, richardcochran@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, vladimir.oltean@nxp.com,
	vadim.fedorenko@linux.dev, andrew@lunn.ch,
	linux-kernel@vger.kernel.org, arkadiusz.kubalewski@intel.com,
	jiri@resnulli.us, jonathan.lemon@gmail.com
Subject: Re: [PATCH net v6 4/8] ptp: ocp: restore disabled SMA inputs when binding
Date: Fri, 27 Nov 2026 16:48:02 +0000	[thread overview]
Message-ID: <179579808276.3135.5382400825629748441@kernel.org> (raw)
In-Reply-To: <20261126-timecard-driver-v6-4-ahmadexp@gmail.com>

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

  reply	other threads:[~2026-11-27 16:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=179579808276.3135.5382400825629748441@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ahmadexp@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=jonathan.lemon@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@nxp.com \
    /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®