From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25FC13F8714 for ; Thu, 18 Jun 2026 12:58:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781787507; cv=none; b=Thf6J5OTkqNFwPGnMeLlpF1by5CQfolQmSNncDJ0f38HmcI4QtoTPAcdrtRygIYyO914YsYuLwTznKjNvJuPHjkkgS2oGVkVP/Op9q2Nw/+0TwUEpVWvmBNr8WOjke94bwOcnZ7oCddHmJDDeHoIJqSGJ87xD5Q8Y09ePVUwy/g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781787507; c=relaxed/simple; bh=G2FXsp8rc8X6cn3GN9/7ENRjhOMTdXRbI6ic9QN690w=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nDuYYJLbYWjd2AhdtjnVVOxsl5jRusNUK9uKRhG0aKMPbhJJXVwZST8F0kC5lQUhk9N0LM+32pvtJbQQzQpMfZ+xp5C/FST7w1mPhi8mjemEqPtYG8A9xSdFNQf7W8Wl4VUhemcyLNrqE1u6egZ6vdiq/Yhq/8YSY27AdFjXFYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GEOAo713; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GEOAo713" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4923139e940so5105855e9.3 for ; Thu, 18 Jun 2026 05:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781787503; x=1782392303; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=aWBKkXCPnVX9y0NE85TytOyaJugeSr3Fnil+IDh5DbM=; b=GEOAo7131sDtv8MB5R7pFEt4F0tEJ9VhP15kq7pCqnG49pnivs83LHLaU6379iQ3Xf uFHIWSy0RuhokpEC6KYjn5v0MshGNvZLNwpFyFIHckHM8US23mDN+hauTx5h3KusohVS QvlUE/nG35giy0aVu7v0p9Xxl4+rKOwnE2FxHhx9cNRAwH0kY8ZlJZ9701IuG9IUWLLz tj39hOlora3lJ5Aq4c7+6Ig2Is1ydPTus3ImYRYi3rCfsRnBtznb1PjnxnHZ4+hgwVxu MkFXZI44ozZWl60VaM98QbCjUkxfXBIY/Whewg0KJnMoylZdzu1jfZVKF5h6xP3BIdau kaTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781787503; x=1782392303; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aWBKkXCPnVX9y0NE85TytOyaJugeSr3Fnil+IDh5DbM=; b=dWUy9LWCmmgma0sHRLeBREc97WhSY4H1LgDzhANY/1fVmabDZabIPaWYDddtHHbAIt 7d1siQCYAvDKDUkAdeerj/4Bc8GJhW0f9kiUOwH3MUtigj6j0EPWA9wj5KYyAajMCxrt d61RluQpm4i+SNP38cPXibGbKrG1HPX8gGnOMN+DRWc8ZO9SRR+dQXvDG7gVP+nlhAb5 b27yls+N5hGo7w23khIp44T5ZvF1Y+oHnDkSQwp7xllDlV3JWvz5JKZg+qDUVuWdso15 1BrQs10tWdmTtTsPORIfwQ//cUUFsdwi6gua6BeG/OIJFaC4krKLq5NG8ubiNpZgnaKJ kBFw== X-Forwarded-Encrypted: i=1; AFNElJ9Lg6iJQmL1rFR1gmj4f91bkUgy5Co1FdQ6m1tAbiD1KzvKIg8aneMsHi/4ZxwQR9xo3ywmZI7ifB70@vger.kernel.org X-Gm-Message-State: AOJu0YwlDTGBDfYthk3q55OqSXqBb+/25zAeLW8KUTQFbVqMtoDd08/U +Gh64p0eoYOT3gqa5g+FqWUFojWe7VEYRlkJl4GNC7yOWEcW7aaQBJOe X-Gm-Gg: AfdE7clDLRFHngv4LCjeatwSmv45dWvdba4zLBXN10NqtpQbbGxPZvgaQKDWf107Juq qgIsmTpX22gEbz6fEiYxFM5Io8p1fQMRwvkUlGqekIHd4XjUoMK3FltlXSyyEmgN3puo3rxqY3X 9Jx8bOwQ+Dlcf/FW37dSBIY9YNPhOXtTXy6wY7jm2DBjb1x+E3mo0IPhzslr1H3snygOdCEr8dc lLLiSk4l7yL7zDiiYJGNxK+FcGN+hKtqTLgM1c9gIvH5KM06Jghm4bOTBe1t6Z2esiiP9cnn6R0 Bk1dW8B3y54ZoJgrqB0Eil91Ur6pVfwKmvp6/7JjTHqoMvEwB+JbU3Q6BXSVqEl98LLqYS9jOxl v1/v1FZVxMaPOCWHOm/YdlTF6tSSpI2DCxprI4oSxYYgeyTgD+z/XmnyJrEeLl6lQPzXzArZAdn lpMQ6ivoiqqDAlyP302rQ0kYoK3+TGoD5GgHjLBeGuSPFsGnUZkSyPIqXsYCuFdA== X-Received: by 2002:a05:600c:3b9b:b0:492:3445:ecf8 with SMTP id 5b1f17b1804b1-4923445efbdmr126249705e9.3.1781787503384; Thu, 18 Jun 2026 05:58:23 -0700 (PDT) Received: from Ansuel-XPS24.localdomain (93-34-88-103.ip49.fastwebnet.it. [93.34.88.103]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-49230a458f2sm241451585e9.3.2026.06.18.05.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 05:58:22 -0700 (PDT) From: Christian Marangi To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Simon Horman , Jonathan Corbet , Shuah Khan , Christian Marangi , Lorenzo Bianconi , Heiner Kallweit , Russell King , Saravana Kannan , Philipp Zabel , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, llvm@lists.linux.dev, Maxime Chevallier Subject: [RFC PATCH net-next v8 06/12] net: Document PCS subsystem Date: Thu, 18 Jun 2026 14:57:14 +0200 Message-ID: <20260618125752.1223-7-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260618125752.1223-1-ansuelsmth@gmail.com> References: <20260618125752.1223-1-ansuelsmth@gmail.com> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add extensive documentation of the new PCS subsystem and the fwnode implementation with producer/consumer API. Signed-off-by: Christian Marangi --- Documentation/networking/index.rst | 1 + Documentation/networking/pcs.rst | 229 +++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 Documentation/networking/pcs.rst diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst index 44a422ad3b05..3fce8f6ac089 100644 --- a/Documentation/networking/index.rst +++ b/Documentation/networking/index.rst @@ -28,6 +28,7 @@ Contents: net_failover page_pool phy + pcs sfp-phylink alias bridge diff --git a/Documentation/networking/pcs.rst b/Documentation/networking/pcs.rst new file mode 100644 index 000000000000..98592cdee3ef --- /dev/null +++ b/Documentation/networking/pcs.rst @@ -0,0 +1,229 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============= +PCS Subsystem +============= + +The PCS (Physical Coding Sublayer) subsystem handles the registration and lookup +of PCS devices. These devices contain the upper sublayers of the Ethernet +physical layer, generally handling framing, scrambling, and encoding tasks. PCS +devices may also include PMA (Physical Medium Attachment) components. PCS +devices transfer data between the Link-layer MAC device, and the rest of the +physical layer, typically via a serdes. The output of the serdes may be +connected more-or-less directly to the medium when using fiber-optic or +backplane connections (1000BASE-SX, 1000BASE-KX, etc). It may also communicate +with a separate PHY (such as over SGMII) which handles the connection to the +medium (such as 1000BASE-T). + +Remark on usage of .mac_select_pcs and fw_node PCS +-------------------------------------------------- + +There are generally two ways to look up a PCS device. + +1. MAC OP struct .mac_select_pcs (considered legacy) +2. firmware node (fwnode) PCS entirely handled by phylink + +Implementation 1 leaves the entire handling of the PCS to the MAC +driver with the selection of the PCS driven by .mac_select_pcs. +Custom implementations are required if the PCS is external to the MAC +and needs to be handled by a separate driver. + +This implementation is considered legacy and it's suggested to +switch to the new fwnode PCS. + +Looking up PCS Devices (fwnode implementation) +----------------------------------------------- + +The lookup of a PCS device follows the common producer/consumer implementation +used by similar subsystems with a ``#pcs-cells`` on the producer and a +``pcs-handle`` property on the consumer:: + + pcs: pcs { + // ... + #pcs-cells = <0>; + }; + + ethernet-controller { + // ... + pcs-handle = <&pcs>; + }; + +On :c:func:`phylink_create`, phylink will use the ``num_possible_pcs`` +value and ``fill_available_pcs`` helper function in +:c:struct:`phylink_config` to compose the list of available PCS that can be +used for the phylink instance. + +Phylink will then internally handle the selection of the correct PCS for +the requested interface mode based on the interface modes configured in +``pcs_interfaces`` in :c:struct:`phylink_config` struct and +``supported_interfaces`` in :c:struct:`phylink_pcs` struct. + +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. + +``supported_interfaces`` describes all interface modes supported by the MAC, +whereas ``pcs_interfaces`` identifies the subset that require PCS selection. + +For the special implementation where the PCS is internal or part of the MAC +and a dedicated driver is not needed, it's possible to leave the implementation +of the PCS to the MAC driver and just implement the ``num_possible_pcs`` +value and ``fill_available_pcs`` helper function in +:c:struct:`phylink_config` referencing the local :c:struct:`phylink_pcs` +struct allocated from the MAC driver. + +Using PCS Devices +----------------- + +It's mandatory to either implement the ``mac_select_pcs`` callback +of :c:struct:`phylink_mac_ops` or ``num_possible_pcs`` and ``fill_available_pcs`` +of :c:struct:`phylink_config` to use a PCS for a MAC. + +The fwnode implementation exposes simple helpers to parse the PCS from +the fwnode :c:func:`fwnode_phylink_pcs_count` and +:c:func:`fwnode_phylink_pcs_parse`. The :c:func:`fwnode_phylink_pcs_count` helper +takes the fwnode where the ``pcs-handle`` should be parsed and return the +number of PCS entries described in the fwnode. +The :c:func:`fwnode_phylink_pcs_parse` helper takes three arguments, +the fwnode where the ``pcs-handle`` should be parsed, an allocated array +of :c:struct:`phylink_pcs` pointer where to put the parsed PCS from the fwnode +and the maximum number of PCS to parse. +Contrary to :c:func:`fwnode_phylink_pcs_count`, :c:func:`fwnode_phylink_pcs_parse` +helper fills the allocated array with ONLY the available PCS and return the +number of available PCS found. PCS that returns -ENODEV will be skipped and +won't be inserted in the allocated array. + +A phylink instance may use multiple PCS devices. The maximum number is reported +through ``num_possible_pcs``. + +It's mandatory to specify for what interface a PCS is needed. This can be done +by filling the ``pcs_interfaces`` in :c:struct:`phylink_config` struct. +If the requested interface mode is not present in this bitmask, phylink does +not search for a PCS for that specific mode. (example MAC doesn't need a PCS +for SGMII but require one for USXGMII) + +With the use of the :c:func:`fwnode_phylink_pcs_parse` a common implementation +is the following:: + + static int mac_fill_available_pcs(struct phylink_config *config, + struct phylink_pcs **available_pcs, + unsigned int num_possible_pcs) + { + struct device *dev = config->dev; + + return fwnode_phylink_pcs_parse(dev_fwnode(dev), available_pcs, + num_possible_pcs); + } + + 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; + + __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, //... + +It's worth to mention that it's phylink code that takes care of allocating +the array of :c:struct:`phylink_pcs` pointer for ``fill_available_pcs`` +callback based on the value set in ``num_possible_pcs`` for +:c:struct:`phylink_config` struct. + +The ``fill_available_pcs`` callback must not write more than +``num_possible_pcs`` entries. The third argument may be used to validate +that there is enough space to fill all the available PCS in the passed array +of :c:struct:`phylink_pcs` pointer. + +The ``fill_available_pcs`` callback is called only on :c:func:`phylink_create` +and is used only to compose the initial available PCS list. Ownership of PCS +is held by phylink and :c:func:`phylink_release_pcs` should be used to release +them. + +Writing PCS Drivers +------------------- + +To write a PCS driver, first implement :c:struct:`phylink_pcs_ops`. Then, +register your PCS in your probe function using :c:func:`fwnode_pcs_add_provider`. +The :c:func:`fwnode_pcs_add_provider` takes three arguments, the fwnode where +the PCS provider should be registered to, a get function to return the requested +PCS based on ``#pcs-cells`` and a pointer to reference private data for the get +function. + +The PCS will then be registered to a global list of PCS provider that the +PCS fwnode implementation will use to parse it. + +For the simple case where the PCS driver expose a single PCS, +:c:func:`fwnode_pcs_simple_get` can be used as the get function. + +You must call :c:func:`fwnode_pcs_del_provider` from your remove function and +release the PCS from any phylink instance under RTNL lock with +:c:func:`phylink_release_pcs`:: + + fwnode_pcs_del_provider(dev_fwnode(&pdev->dev)); + + rtnl_lock(); + + for (i = 0; i < data->num_port; i++) { + struct pcs_port *port = &priv->ports[i]; + + phylink_release_pcs(&port->pcs); + } + + rtnl_unlock(); + +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``. + +This is to prevent race condition with particular devices that register +MAC and PCS with USB or PCIe and require the MAC to be registered before +the PCS. + +The phylink logic correctly handle this special case and keep the phylink +instance in a fail condition. + +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. + +Function :c:func:`pcs_provider_notify` will check if the just added PCS +should be used by the phylink instance. If it should be used then, +it's added to the internal list of available PCS and a phylink major +config is forced. + +If a phylink instance was in a failure state, with the just added PCS +now part of the available PCS internal phylink list, provided all other +conditions are satisfied, the configuration is retried and the failure +condition is cleared. + +API Reference +------------- + +.. kernel-doc:: include/linux/phylink.h + :identifiers: phylink_pcs + +.. kernel-doc:: include/linux/pcs/pcs.h + :internal: + +.. kernel-doc:: include/linux/pcs/pcs-provider.h + :internal: -- 2.53.0