All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian Marangi" <ansuelsmth@gmail.com>, devicetree@vger.kernel.org
Cc: robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v23 10/15] net: Document PCS subsystem
Date: Mon, 30 Nov 2026 23:25:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-242234@kernel.org> (raw)
In-Reply-To: <20261129230558.612526-11-ansuelsmth@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] net: doc: pcs: setting pcs_interfaces modes in
  supported_interfaces breaks gating
- [Low] net: doc: pcs: unconditional PCS config in mac_setup_phylink()
  fails when count is 0
- [Low] net: doc: pcs: inaccurate ownership, notifier semantics, and
  Sphinx C references
--

commit 90c76f7838a6fb884106472bf5d9e3dc365a66ee
Author: Christian Marangi <ansuelsmth@gmail.com>

net: Document PCS subsystem

This commit adds documentation for the PCS subsystem and its fwnode
producer/consumer API, and updates the sfp-phylink porting 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 @@
[ ... ]
> +``supported_interfaces`` describes all interface modes supported by the MAC,
> +whereas ``pcs_interfaces`` identifies the subset that require PCS selection.
[ ... ]
> +   static int mac_setup_phylink(struct net_device *netdev)
> +   {
> +      struct phylink_config *config;
> +
> +      // ...
> +
> +      config->dev = &netdev->dev;
> +
> +      // ...
> +
> +      // 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;

[Severity: Low]
Will phylink_create() fail with -EINVAL in this example whenever
fwnode_phylink_pcs_count() returns 0?

phylink_create() requires pcs_interfaces, fill_available_pcs, and
num_possible_pcs > 0 to either all be set or all be empty:

drivers/net/phy/phylink.c:phylink_create() {
    ...
	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);
	}
    ...
}

In a MAC that supports modes such as SGMII without an external PCS and
only requires a PCS for USXGMII, a board without a pcs-handle property
(or a kernel built with CONFIG_FWNODE_PCS disabled) gets
num_possible_pcs == 0 while fill_available_pcs and pcs_interfaces are
still populated, causing phylink_create() to fail.  Step 12 in
Documentation/networking/sfp-phylink.rst also tells drivers to populate
num_possible_pcs and fill_available_pcs without mentioning that
pcs_interfaces must be populated together with them when num_possible_pcs
is non-zero.

> +
> +      __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);

[Severity: Medium]
Does setting PHY_INTERFACE_MODE_USXGMII in both
config->supported_interfaces and config->pcs_interfaces (as also stated
earlier where pcs_interfaces is described as a subset of
supported_interfaces) prevent phylink from gating PCS-dependent modes on
PCS availability?

phylink_parse_supported_interfaces() copies config->supported_interfaces
directly into pl->supported_interfaces without masking out
config->pcs_interfaces before ORing in the interfaces supported by the
currently registered PCS providers:

drivers/net/phy/phylink.c:phylink_parse_supported_interfaces() {
	phy_interface_copy(pl->supported_interfaces,
			   pl->config->supported_interfaces);

	list_for_each_entry(pcs, &pl->pcs_list, list) {
		phy_interface_and(interfaces, pl->config->pcs_interfaces,
				  pcs->supported_interfaces);
		phy_interface_or(pl->supported_interfaces,
				 pl->supported_interfaces,
				 interfaces);
	}
}

If a driver sets a PCS-dependent mode in config->supported_interfaces,
that mode remains present in pl->supported_interfaces even when no PCS is
registered.  As a result, phylink_validate_mac_and_pcs() validates the
mode against MAC capabilities alone with no PCS attached, and
phylink_sfp_module_insert() sees a non-empty intersection with
pl->supported_interfaces and never defers optical SFP module insertion
with -EAGAIN while waiting for a late PCS provider.

[ ... ]
> +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.
[ ... ]
> +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.
[ ... ]
> diff --git a/Documentation/networking/sfp-phylink.rst b/Documentation/networking/sfp-phylink.rst
> index 5bf285d73e8a1..306505118eba9 100644
> --- a/Documentation/networking/sfp-phylink.rst
> +++ b/Documentation/networking/sfp-phylink.rst
> @@ -311,33 +311,20 @@ this documentation.
[ ... ]
> +12. Populate the :c:var:`num_possible_pcs` value and
> +    :c:func:`fill_available_pcs` callback and add it to your
> +    :c:type:`struct phylink_config <phylink_config>`.

[Severity: Low]
As reported by Jakub Kicinski on v22 [1], is "Ownership of PCS is held by
phylink" accurate?  phylink_add_pcs() and phylink_del_pcs() only link the
struct phylink_pcs pointer into pl->pcs_list without taking a reference or
freeing it, so the PCS provider or MAC driver retains ownership of the
memory (and each struct phylink_pcs instance can only be attached to one
phylink instance at a time via pcs->phylink).

A few other details in these sections also do not match the code or
Sphinx C domain markup:

- In pcs_provider_notify() ("reprase" -> "reparse"), a major config is not
  always forced on provider events; phylink_del_pcs() and
  phylink_pcs_changed() only set pl->force_major_config when the currently
  active pl->pcs is removed or when pl->major_config_failed is set while
  phylink is not stopped.
- The description of fwnode_phylink_pcs_parse() notes that missing PCS
  providers returning -ENODEV are skipped, but omits that
  fwnode_phylink_pcs_parse() itself returns -ENODEV when the pcs-handle
  property is absent on the fwnode.
- In the "Looking up PCS Devices" section, the paragraph beginning
  "supported_interfaces describes all interface modes supported by the
  MAC" switches from struct phylink_pcs to struct phylink_config without
  naming struct phylink_config.
- pcs_provider_notify is a static function in drivers/net/phy/phylink.c
  with no kernel-doc entry, and num_possible_pcs and fill_available_pcs in
  sfp-phylink.rst are struct phylink_config members rather than a global
  :c:var: and :c:func:.

[1] https://lore.kernel.org/r/20261121232652.1365578-1-kuba@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129230558.612526-1-ansuelsmth@gmail.com?part=10

  reply	other threads:[~2026-11-30 23:25 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 [this message]
2026-11-30 23:47   ` netdev-bot+sashiko
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=sashiko-outbox-242234@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ansuelsmth@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.