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, vadim.fedorenko@linux.dev,
	andi.shyti@kernel.org, andrew+netdev@lunn.ch, corbet@lwn.net,
	davem@davemloft.net, edumazet@kernel.org, horms@kernel.org,
	jiri@resnulli.us, kuba@kernel.org, linux-doc@vger.kernel.org,
	linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org,
	pabeni@redhat.com, rdunlap@infradead.org,
	richardcochran@gmail.com, skhan@linuxfoundation.org
Subject: Re: [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card
Date: Wed, 18 Nov 2026 18:22:58 +0000	[thread overview]
Message-ID: <179502617840.3136.12704245716223038161@kernel.org> (raw)
In-Reply-To: <20261116-wiwi-v3-87afa10a8-3-ahmadexp@gmail.com>

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

Critical: 0 · High: 1 (1) · Medium: 3 · 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).

- [High] The patch fixes the DPLL selector bugs for WiWi only.
- [Medium] The new ptp_ocp_wiwi_sma_out table gives DCF a frequency of
  77000.
- [Medium] On WiWi the patch removes GNSS2 (0x0008) from the SMA output
  table but never clears that selection in the output mux.
- [Medium] ptp: ocp: disabled WiWi SMA input reported as 10 MHz in
  ptp_ocp_dpll_frequency_get()
- [Low] On WiWi, ptp_ocp_sma_show() prints "OUT: unavailable\n" when the
  output selector holds a value missing from ptp_ocp_wiwi_sma_out, such…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but there is a
  remove-vs-ioctl race in ptp_ocp_detach() that can lead to a use-after-…

--

ptp: ocp: support the WiWi revision 02 Time Card

This adds support for the WiWi revision 02 Time Card (2163:1008, subsystem
10ee:0007). It reuses the FB resource table with WiWi-specific MMIO and
MSI-X offsets, adds a WiWi SMA output table without GNSS2, and drives an
MSI enable gate at BAR0 0x1800. On WiWi it also rejects devlink flash,
skips the SPI flash and GNSS2 UART, and blocks timestamper and generator
arming until probe has opened the interrupt gate.

> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index decc56892059b..df40dac982213 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c

[ ... ]

> @@ -1384,6 +1421,23 @@ static const struct ocp_selector ptp_ocp_sma_out[] = {
>  	{ }
>  };
>  
> +/* No validated second receiver on the supported WiWi board. */
> +static const struct ocp_selector ptp_ocp_wiwi_sma_out[] = {
> +	{ .name = "10Mhz", .value = 0x0000, .frequency = 10000000 },
> +	{ .name = "PHC",   .value = 0x0001, .frequency = 1 },
> +	{ .name = "MAC",   .value = 0x0002, .frequency = 1 },
> +	{ .name = "GNSS1", .value = 0x0004, .frequency = 1 },
> +	{ .name = "IRIG",  .value = 0x0010, .frequency = 10000 },
> +	{ .name = "DCF",   .value = 0x0020, .frequency = 77000 },

[Severity: Medium]
Should this be 77500? The SMA DPLL pins advertise DPLL_PIN_FREQUENCY_DCF77
(77.5 kHz) in ptp_ocp_sma_freq[], and ptp_ocp_sma_in already uses 77500
for DCF.

For WiWi, ptp_ocp_dpll_frequency_set() now picks the hardware value with
tbl[i].frequency == frequency. A 77500 Hz request on an output SMA matches
nothing in ptp_ocp_wiwi_sma_out, so it returns -EINVAL.

In the other direction, ptp_ocp_dpll_frequency_get() would report 77000 Hz
for a DCF-routed output, and that frequency is not in the pin's supported
list.

The value was copied from ptp_ocp_sma_out, but this table and its
value-based DPLL path are new in this patch.

[ ... ]

> @@ -2944,6 +3019,14 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
>  	.set_output	= ptp_ocp_sma_fb_set_output,
>  };
>  
> +static const struct ocp_sma_op ocp_wiwi_sma_op = {
> +	.tbl		= { ptp_ocp_sma_in, ptp_ocp_wiwi_sma_out },
> +	.init		= ptp_ocp_sma_fb_init,
> +	.get		= ptp_ocp_sma_fb_get,
> +	.set_inputs	= ptp_ocp_sma_fb_set_inputs,
> +	.set_output	= ptp_ocp_sma_fb_set_output,
> +};

[Severity: Medium]
GNSS2 (0x0008) is dropped from ptp_ocp_wiwi_sma_out, but the output mux is
never reprogrammed. ocp_wiwi_sma_op reuses ptp_ocp_sma_fb_init(), which
only reads sma_map1/sma_map2 to work out the pin direction:

    reg = ioread32(&bp->sma_map1->gpio2);
    bp->sma[2].mode = reg & BIT(15) ? SMA_MODE_OUT : SMA_MODE_IN;

Suppose an output selector already holds GNSS2 at bind time. That could
come from the FPGA default or from a previous kernel. It could also come
from the earlier driver build mentioned in the commit message, which used
the FB table with GNSS2. The CSR is not reset on driver reload. In that
case, will the SMA keep driving the GNSS2 PPS net?

In that state ptp_ocp_sma_show() prints "OUT: unavailable".
ptp_ocp_dpll_frequency_get() finds no match and returns -EINVAL, which
makes the DPLL pin dump fail.

The commit message says:

  "Do not expose an unvalidated second GNSS UART or PPS output source."

Should the WiWi SMA init replace any output selection that is missing
from ptp_ocp_wiwi_sma_out with the pin's default_fcn?

[ ... ]

> @@ -3394,6 +3506,8 @@ ptp_ocp_sma_show(struct ptp_ocp *bp, int sma_nr, char *buf,
>  		return ptp_ocp_show_inputs(tbl[0], val, buf, default_in_val);
>  	}
>  
> +	if (bp->wiwi && !ptp_ocp_select_name_from_val(tbl[1], val))
> +		return sysfs_emit(buf, "OUT: unavailable\n");
>  	return ptp_ocp_show_output(tbl[1], val, buf, default_out_val);
>  }

[Severity: Low]
Is "OUT: unavailable" meant to be part of the sysfs ABI?
Documentation/ABI/testing/sysfs-timecard describes the smaN read format
this way:

    The display format of the attribute is a space separated
    list of signals, prefixed by the input/output direction.

It also says output values come from available_sma_outputs, and
"unavailable" is not one of them. Writing the displayed value back fails
with -EINVAL, because sma_parse_inputs()->ptp_ocp_select_val_from_name()
finds no match.

Should the sysfs ABI document be updated along with the devlink rst?

[ ... ]

> @@ -5787,6 +5901,12 @@ ptp_ocp_detach(struct ptp_ocp *bp)
>  	platform_device_unregister(bp->i2c_ctrl);
>  	if (bp->i2c_clk)
>  		clk_hw_unregister_fixed_rate(bp->i2c_clk);
> +	/* Keep child interrupts available until the children are gone. */
> +	if (bp->wiwi_msi) {
> +		iowrite32(0, bp->wiwi_msi);
> +		iowrite32(0, bp->wiwi_msi + 4);
> +		ioread32(bp->wiwi_msi);
> +	}
>  	if (bp->n_irqs)
>  		pci_free_irq_vectors(bp->pdev);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch, but the
new wiwi_timing_ready flag looks like it could close it.

ptp_ocp_detach() disables the timestampers before it unregisters the
clock:

    if (bp->pps)
        ptp_ocp_ts_enable(bp->pps, ~0, false);
    if (bp->ptp)
        ptp_clock_unregister(bp->ptp);

Until posix_clock_unregister() runs, can userspace still issue
PTP_EXTTS_REQUEST and reach ptp_ocp_enable()->ptp_ocp_ts_enable() with
enable=true, which re-arms the timestamper? On WiWi, ptp_ocp_timing_ready()
still returns true at this point, because wiwi_timing_ready is never
cleared.

ptp_disable_all_events() only disables EXTTS on pins whose func is
PTP_PF_EXTTS. ptp_ocp_set_pins() leaves func at PTP_PF_NONE, so a
re-armed channel stays enabled.

The MSI vector stays requested until ptp_ocp_unregister_ext() runs. The
WiWi gate at 0x1800 also stays open until the children have been freed.

If the fd that armed EXTTS has been closed, put_device() in
ptp_clock_unregister() frees the ptp_clock. An external edge would then
run this on freed memory:

ptp_ocp_ts_irq()
  ptp_clock_event(ext->bp->ptp, &ev)
    spin_lock_irqsave(&ptp->tsevqs_lock, ...)

Would it help to clear wiwi_timing_ready with smp_store_release(..., false)
or to mask OCP_WIWI_TIMING_IRQS before the disable loop?

[ ... ]

> @@ -5881,9 +6001,14 @@ static int ptp_ocp_dpll_frequency_set(const struct dpll_pin *pin,
>  		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) {
> +			int val = bp->wiwi ? tbl[i].value : i;
> +
> +			return ptp_ocp_sma_store_val(bp, val, sma->mode,
> +						     sma_nr + 1);
> +		}
> +	}
>  	return -EINVAL;
>  }
>  
> @@ -5901,6 +6026,8 @@ static int ptp_ocp_dpll_frequency_get(const struct dpll_pin *pin,
>  	int i;
>  
>  	val = bp->sma_op->get(bp, sma_nr + 1);
> +	if (bp->wiwi)
> +		val &= SMA_SELECT_MASK;
>  	tbl = bp->sma_op->tbl[sma->mode];

[Severity: Medium]
When an SMA input is disabled, ptp_ocp_sma_store_val() sets
sma->disabled and writes 0 to the mux field, which also clears
SMA_ENABLE. With the new masking, ptp_ocp_dpll_frequency_get() then
looks up 0x0000 in ptp_ocp_sma_in and matches the 10Mhz entry.
Doesn't that make a disabled WiWi input report 10 MHz over DPLL
netlink?

ptp_ocp_sma_show() avoids this collision by substituting SMA_DISABLE
before the table lookup:

    if (sma->disabled)
        val = SMA_DISABLE;

So sysfs shows "IN: None" for a pin that DPLL reports as 10 MHz.

The wrong readback also gets in the way of re-enabling the pin.
dpll_pin_freq_set() calls frequency_get first. If the requested
frequency matches the current one, it returns 0 without calling
frequency_set. A 10 MHz request on the disabled input is therefore a
silent no-op. ptp_ocp_dpll_frequency_set() never runs and
sma->disabled stays set, yet the request still reports success.

Should ptp_ocp_dpll_frequency_get() check sma->disabled the same way,
so the lookup hits the "None" entry and reports 0 Hz? Or is there a
better way to report a disabled pin here? A disabled pin also reads
back 0 on the other boards that use ptp_ocp_sma_fb_get(), so the
check may belong in the common path rather than only under bp->wiwi.

[Severity: High]
WiWi now uses the hardware selector value here. Non-WiWi boards still pass
the table index i to ptp_ocp_sma_store_val(), so don't they keep the same
bug?

ptp_ocp_sma_store_val() expects a selector bitmask. The sysfs path
ptp_ocp_sma_store() passes it the value from sma_parse_inputs(), and
ptp_ocp_sma_store_val() ORs in SMA_ENABLE before writing the mux.

With ptp_ocp_sma_out (Meta, Celestica, ADVA), a 10 kHz request on an
output SMA matches IRIG at index 5. It writes 0x5 | SMA_ENABLE, which
selects PHC|GNSS1 instead of 0x10.

With ptp_ocp_sma_in, a 10 kHz request writes 0x5 (PPS1|TS1) instead of
IRIG (0x10). A 77500 Hz request writes 0x6 (PPS2|TS1) instead of DCF
(0x20).

On ART, a 1 Hz request writes 0, which ptp_ocp_art_sma_set() rejects.

ptp_ocp_dpll_frequency_get() has the same split. ptp_ocp_sma_fb_get()
returns the raw 16-bit field:

    return (ioread32(gpio) >> shift) & 0xffff;

On FB/ADVA pins whose direction can change, SMA_ENABLE (BIT(15)) is set,
so no table entry matches and the callback returns -EINVAL.
dpll_msg_add_pin_freq() in drivers/dpll/dpll_netlink.c passes that error
on, so the DPLL pin get/dump fails for that pin. By comparison,
ptp_ocp_sma_show() masks with SMA_SELECT_MASK on every board.

The commit message says:

  "Use hardware selector values for WiWi DPLL routing; preserve the
  existing behavior on other boards."

Could tbl[i].value and the SMA_SELECT_MASK masking be applied on every
board instead, as a separate fix with Fixes: 09eeb3aecc6c ("ptp_ocp:
implement DPLL ops"), rather than only for WiWi?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-wiwi-v3-87afa10a8-0-ahmadexp%40gmail.com

  reply	other threads:[~2026-11-18 18:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 18:20 [PATCH net-next v3 0/3] ptp: ocp: support the WiWi production " Ahmad Byagowi
2026-11-16 18:20 ` [PATCH net-next v3 1/3] i2c: xiic: allow platforms to require 32-bit register accesses Ahmad Byagowi
2026-11-18 18:22   ` netdev-bot+sashiko
2026-11-18 20:05     ` Ahmad Byagowi
2026-11-16 18:20 ` [PATCH net-next v3 2/3] i2c: xiic: add KUnit coverage for register access modes Ahmad Byagowi
2026-11-18 18:22   ` netdev-bot+sashiko
2026-11-18 20:05     ` Ahmad Byagowi
2026-11-16 18:20 ` [PATCH net-next v3 3/3] ptp: ocp: support the WiWi revision 02 Time Card Ahmad Byagowi
2026-11-18 18:22   ` netdev-bot+sashiko [this message]
2026-11-18 20:05     ` 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=179502617840.3136.12704245716223038161@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=ahmadexp@gmail.com \
    --cc=andi.shyti@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=skhan@linuxfoundation.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®