]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: phylink: add support for PCS supported_interfaces bitmap
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Fri, 3 Jan 2025 11:16:31 +0000 (11:16 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Jan 2025 00:26:12 +0000 (16:26 -0800)
Add support for the PCS to specify which interfaces it supports, which
can be used by MAC drivers to build the main supported_interfaces
bitmap. Phylink also validates that the PCS returned by the MAC driver
supports the interface that the MAC was asked for.

An empty supported_interfaces bitmap from the PCS indicates that it
does not provide this information, and we handle that appropriately.

Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1tTffL-007RoD-1Y@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/phy/phylink.c
include/linux/phylink.h

index 6d50c2fdb190ef18384eabd2c7b2fb8dbb2ccd36..31754d5fd6590372d36f2daf35735c494608c88d 100644 (file)
@@ -691,6 +691,17 @@ static int phylink_validate_mac_and_pcs(struct phylink *pl,
                        return -EINVAL;
                }
 
+               /* Ensure that this PCS supports the interface which the MAC
+                * returned it for. It is an error for the MAC to return a PCS
+                * that does not support the interface mode.
+                */
+               if (!phy_interface_empty(pcs->supported_interfaces) &&
+                   !test_bit(state->interface, pcs->supported_interfaces)) {
+                       phylink_err(pl, "MAC returned PCS which does not support %s\n",
+                                   phy_modes(state->interface));
+                       return -EINVAL;
+               }
+
                /* Validate the link parameters with the PCS */
                if (pcs->ops->pcs_validate) {
                        ret = pcs->ops->pcs_validate(pcs, supported, state);
index 5462cc6a37dc21c47f0e4e1147cdb4cc829f5c00..4b7a20620b496f0de5618b671af9e4deae93142f 100644 (file)
@@ -393,6 +393,8 @@ struct phylink_pcs_ops;
 
 /**
  * struct phylink_pcs - PHYLINK PCS instance
+ * @supported_interfaces: describing which PHY_INTERFACE_MODE_xxx
+ *                        are supported by this PCS.
  * @ops: a pointer to the &struct phylink_pcs_ops structure
  * @phylink: pointer to &struct phylink_config
  * @neg_mode: provide PCS neg mode via "mode" argument
@@ -409,6 +411,7 @@ struct phylink_pcs_ops;
  * the PCS driver.
  */
 struct phylink_pcs {
+       DECLARE_PHY_INTERFACE_MASK(supported_interfaces);
        const struct phylink_pcs_ops *ops;
        struct phylink *phylink;
        bool neg_mode;