Devicetree
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: ansuelsmth@gmail.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, robh@kernel.org,
	krzk+dt@kernel.org, conor+dt@kernel.org, willemb@google.com,
	horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
	rdunlap@infradead.org, lorenzo@kernel.org, hkallweit1@gmail.com,
	linux@armlinux.org.uk, maxime.chevallier@bootlin.com,
	p.zabel@pengutronix.de, nathan@kernel.org,
	ndesaulniers@google.com, morbo@google.com,
	justinstitt@google.com, rmk+kernel@armlinux.org.uk,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, llvm@lists.linux.dev,
	zhengping.zhang@airoha.com
Subject: Re: [PATCH net-next v23 10/15] net: Document PCS subsystem
Date: Mon, 30 Nov 2026 23:47:51 +0000	[thread overview]
Message-ID: <179608247135.3146.5515172354102212593@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-11-ansuelsmth@gmail.com>

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

Critical: 0 · High: 0 · Medium: 2 · Low: 3

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 consumer example in Documentation/networking/pcs.rst
  (mac_setup_phylink, lines ~137-147) sets config->num_possible_pcs =…
- [Medium] pcs.rst (lines 72-73) says ``supported_interfaces`` "describes
  all interface modes supported by the MAC, whereas ``pcs_interfaces``…
- [Low] pcs.rst (lines 68-70) says "A PCS is considered eligible when the
  requested interface mode is present in both ``pcs_interfaces`` in…
- [Low] The 'Late PCS registration handling' section of pcs.rst
  misdescribes the implementation in several places, and some cross-…
- [Low] pcs.rst line 165 says "Ownership of PCS is held by phylink." Read
  as a lifetime statement, this contradicts the implementation and the…

--

net: Document PCS subsystem

This commit adds Documentation/networking/pcs.rst. It documents the new
PCS subsystem, the fwnode producer/consumer API and how phylink handles
late PCS registration. It also updates the sfp-phylink migration guide to
use num_possible_pcs and fill_available_pcs instead of mac_select_pcs.

> diff --git a/Documentation/networking/pcs.rst b/Documentation/networking/pcs.rst
> new file mode 100644
> index 0000000000000..03b7de73a1065
> --- /dev/null
> +++ b/Documentation/networking/pcs.rst
> @@ -0,0 +1,257 @@

[ ... ]

> +A PCS is considered eligible when the requested interface mode is present
> +in both ``pcs_interfaces`` in :c:struct:`phylink_config` struct and
> +``supported_interfaces`` in :c:struct:`phylink_pcs` struct.

[Severity: Low]
Is this eligibility rule complete? phylink_validate_pcs_interface() in
drivers/net/phy/phylink.c treats an empty PCS mask as a wildcard:

    if (phy_interface_empty(pcs->supported_interfaces))
        return 0;

phylink_parse_supported_interfaces() also skips the AND in that case:

    if (!phy_interface_empty(pcs->supported_interfaces))
        phy_interface_and(pcs_interfaces, pcs_interfaces,
                          pcs->supported_interfaces);

So a provider that leaves supported_interfaces empty gets selected for every
mode in pcs_interfaces, not for none of them.

Could this paragraph, and maybe the struct phylink_pcs kernel-doc, mention
the empty-mask behaviour?

> +``supported_interfaces`` describes all interface modes supported by the MAC,
> +whereas ``pcs_interfaces`` identifies the subset that require PCS selection.

[Severity: Medium]
Does this match how phylink builds pl->supported_interfaces?

The previous paragraph names supported_interfaces in struct phylink_pcs. The
kernel-doc in include/linux/phylink.h describes that field as the modes
"supported by this PCS", not by the MAC.

The model also seems to be the opposite of what the code expects.
phylink_parse_supported_interfaces() assumes PCS-only modes are absent from
config->supported_interfaces:

    phy_interface_copy(pl->supported_interfaces,
                       pl->config->supported_interfaces);

    /*
     * Only add PCS-supported modes that phylink will select a PCS for.
     * Otherwise, phylink may accept a PCS-only mode and configure it without
     * a PCS.
     */

phylink_sfp_module_insert() only defers when the module's interfaces miss
pl->supported_interfaces:

    if (!caps->may_have_phy &&
        !bitmap_intersects(caps->interfaces, pl->supported_interfaces,
                           PHY_INTERFACE_MODE_MAX) &&
        bitmap_intersects(caps->interfaces, pl->config->pcs_interfaces,
                          PHY_INTERFACE_MODE_MAX))
        return -EAGAIN;

This paragraph makes pcs_interfaces a subset of config->supported_interfaces,
and the mac_setup_phylink() example below sets USXGMII in both masks. In
that case USXGMII is always in pl->supported_interfaces.

Wouldn't that mean three things?

- The -EAGAIN deferral and the sfp_upstream_retry_module() retry described
  in the late registration section can never trigger.
- phylink_validate_mac_and_pcs() accepts USXGMII without a PCS.
- phylink_major_config() then fails with "couldn't find a PCS".

Step 13 of sfp-phylink.rst still tells readers to fill supported_interfaces
with what "your MAC and all PCS associated with this MAC are capable of",
which points the same way.

[ ... ]

> +      // Parse possible PCS and fill num_possible_pcs
> +      config->num_possible_pcs = fwnode_phylink_pcs_count(dev_fwnode(&netdev->dev));
> +      config->fill_available_pcs = mac_fill_available_pcs;
> +
> +      __set_bit(PHY_INTERFACE_MODE_INTERNAL, config->supported_interfaces);
> +      __set_bit(PHY_INTERFACE_MODE_SGMII, config->supported_interfaces);
> +      __set_bit(PHY_INTERFACE_MODE_1000BASEX, config->supported_interfaces);
> +      __set_bit(PHY_INTERFACE_MODE_USXGMII, config->supported_interfaces);
> +
> +      // PCS required only for USXGMII
> +      __set_bit(PHY_INTERFACE_MODE_USXGMII, config->pcs_interfaces);
> +
> +      phylink = phylink_create(config, //...

[Severity: Medium]
What happens with this example when fwnode_phylink_pcs_count() returns 0?
That happens when the node has no pcs-handle. It also always happens with
CONFIG_FWNODE_PCS=n, where the stub is:

    static inline unsigned int fwnode_phylink_pcs_count(struct fwnode_handle *fwnode)
    {
        return 0;
    }

fill_available_pcs and pcs_interfaces are still set unconditionally, so
phylink_create() rejects the configuration:

    if (has_pcs_interfaces != has_pcs_callback ||
        has_pcs_interfaces != has_pcs_count) {
        dev_err(config->dev,
                "phylink: error: pcs_interfaces, num_possible_pcs and fill_available_pcs must be set together\n");
        return ERR_PTR(-EINVAL);
    }

A driver that copies this example would then fail to probe, even for SGMII,
1000BASE-X and INTERNAL, which the example says need no PCS. PHYLINK does
not select FWNODE_PCS.

Should the example set the PCS fields only when the count is non-zero? Should
the text say that all three fields must be left unset when no PCS is
described?

The example also takes the fwnode from &netdev->dev. It doesn't say that the
netdev needs an fwnode assigned, so a count of 0 is more likely.

Step 12 in sfp-phylink.rst only asks for num_possible_pcs and
fill_available_pcs. Could it also mention pcs_interfaces? Following that
step alone hits the same -EINVAL.

[ ... ]

> +The ``fill_available_pcs`` callback is called on :c:func:`phylink_create`
> +and on provider notification and can be called multiple times.
> +It's used to compose the available PCS list at the time of calling and
> +will be called again when a PCS provider is released or a new one is attached.
> +Ownership of PCS is held by phylink.

[Severity: Low]
Is the last sentence accurate? The fwnode_pcs_add_provider() kernel-doc in
include/linux/pcs/pcs-provider.h, which this page renders in its API
Reference, says the opposite:

    * A PCS object belongs to one provider and must remain valid until that
    * provider is removed.

phylink never allocates, refcounts or frees struct phylink_pcs.
phylink_add_pcs() only links the PCS into pl->pcs_list and sets
pcs->phylink. fwnode_pcs_free_provider() only unlinks provider_list.

If the intent is that phylink tracks which instance a PCS is attached to,
could the sentence say that? As written, a provider author could free the PCS
before fwnode_pcs_del_provider() runs, which would leave a dangling pointer
in pl->pcs_list.

[ ... ]

> +Late PCS registration handling
> +------------------------------
> +
> +It's possible that a PCS becomes available after the MAC finished probing.
> +Contrary to the usual producer/consumer implementation, when a PCS is not
> +registered and can't be found, the fwnode parser helper returns ``-ENODEV``
> +instead of ``-EPROBE_DEFER``.

[ ... ]

> +The PCS fwnode implementation provides a notifier to which each phylink
> +instance with a non-empty ``pcs_interfaces`` in :c:type:`phylink_config`
> +registers. When a new PCS provider is registered, the notifier is called
> +triggering the :c:func:`pcs_provider_notify` function.
> +
> +On receiving a PCS provider event, :c:func:`pcs_provider_notify` will
> +reprase the available PCS by calling the ``fill_available_pcs`` callback
> +and update the internal PCS list for the phylink instance with both the
> +removed and the newly available PCS and a phylink major config is forced.

[ ... ]

> +In an SFP scenario, with no currently usable interface, phylink defers module
> +insertion with ``-EAGAIN`` if the module supports an interface listed in
> +``pcs_interfaces`` and the SFP socket waits with its transmitter disabled.
> +After phylink adds a PCS to its list and refreshes its interface mask, it
> +calls ``sfp_upstream_retry_module()`` and if there is usable interface,
> +the SFP the module insertion is retried.

[Severity: Low]
A few statements in this section don't seem to match the implementation.

fwnode_phylink_pcs_parse() doesn't return -ENODEV for an unregistered PCS.
It skips those references and returns the number it found. It returns
-ENODEV only when pcs-handle is absent, and the !CONFIG_FWNODE_PCS stub
returns -EOPNOTSUPP. Was fwnode_pcs_get() the helper meant here?

A major config isn't forced on every provider event. phylink_pcs_changed()
only forces one when a major config was already pending or had failed:

    if (!test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state) &&
        (pl->force_major_config || pl->major_config_failed)) {
        pl->force_major_config = true;
        pl->link_failed = true;
    }

During init it only marks PCS_STATE_INIT_PENDING, so adding a PCS to a
working link doesn't trigger a reconfiguration.

The SFP deferral in phylink_sfp_module_insert() also requires
!caps->may_have_phy, so modules that may carry a PHY are never deferred.
Should that condition be mentioned here?

Some cross-references won't resolve:

- pcs_provider_notify() is a static function in phylink.c, and no kernel-doc
  directive pulls it in.
- In step 12 of sfp-phylink.rst, num_possible_pcs and fill_available_pcs are
  members of struct phylink_config, so the :c:var: and :c:func: roles won't
  resolve them.

There are also some typos:

- "reprase" should be "reparse".
- "the SFP the module insertion is retried" has a doubled "the".
- There are doubled spaces in "helper  function" and "for  that".

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129230558.612526-1-ansuelsmth%40gmail.com

  parent reply	other threads:[~2026-11-30 23:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 23:05 [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 01/15] net: phylink: make PCS phylink instance access RCU protected Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 02/15] net: phylink: keep and use MAC supported_interfaces in phylink struct Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 03/15] net: phylink: introduce internal phylink PCS handling Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 04/15] net: pcs: implement Firmware node support for PCS driver Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 05/15] net: phylink: make phylink_validate state locked Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 06/15] net: phylink: add capabilities helpers and track modified advertising Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 07/15] net: sfp: support deferred module insertion Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 08/15] net: phylink: support PCS provider release Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 09/15] net: phylink: support late PCS provider attach Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 10/15] net: Document PCS subsystem Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko [this message]
2026-11-29 23:05 ` [PATCH net-next v23 11/15] MAINTAINERS: add myself as PCS subsystem maintainer Christian Marangi
2026-11-29 23:05 ` [PATCH net-next v23 12/15] net: phylink: add .pcs_link_down PCS OP Christian Marangi
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 13/15] dt-bindings: net: pcs: Document support for Airoha Ethernet PCS Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 14/15] net: pcs: airoha: add PCS driver for Airoha AN7581 SoC Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:47   ` netdev-bot+sashiko
2026-11-29 23:05 ` [PATCH net-next v23 15/15] net: airoha: add phylink support Christian Marangi
2026-11-30 23:25   ` sashiko-bot
2026-11-30 23:48   ` netdev-bot+sashiko
2026-11-29 23:09 ` [PATCH net-next v23 00/15] net: pcs: Introduce support for fwnode PCS netdev-bot+sinfo

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=179608247135.3146.5515172354102212593@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=ansuelsmth@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=justinstitt@google.com \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=llvm@lists.linux.dev \
    --cc=lorenzo@kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=willemb@google.com \
    --cc=zhengping.zhang@airoha.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