]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: pcs: keep track of number of links per SerDes
authorJonas Jelonek <jelonek.jonas@gmail.com>
Wed, 24 Dec 2025 10:28:36 +0000 (10:28 +0000)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 3 Jan 2026 15:59:48 +0000 (16:59 +0100)
Add a field to the rtpcs_serdes structure to keep track of how many
links (aka ports) are used on a single SerDes. This is needed to be
known to map kernel interface modes to SerDes hardware modes properly
(e.g. USXGMII --> USXGMII/10G-QXGMII/XSGMII).

While working in rtpcs_create, optimize referencing the SerDes instance
for cleaner code.

Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/21365
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/realtek/files-6.12/drivers/net/pcs/pcs-rtl-otto.c

index 2953c5c5f57c6b29c5bc4c7ef9075858818f62c5..da11b7bafe326d7c92fdb8379d032487bf2f5636 100644 (file)
@@ -12,6 +12,7 @@
 
 #define RTPCS_SDS_CNT                          14
 #define RTPCS_PORT_CNT                         57
+#define RTPCS_MAX_LINKS_PER_SDS                        8
 
 #define RTPCS_SPEED_10                         0
 #define RTPCS_SPEED_100                                1
@@ -134,8 +135,9 @@ struct rtpcs_ctrl;
 
 struct rtpcs_serdes {
        struct rtpcs_ctrl *ctrl;
-       u8 id;
        enum rtpcs_sds_mode hw_mode;
+       u8 id;
+       u8 num_of_links;
 
        bool rx_pol_inv;
        bool tx_pol_inv;
@@ -3090,6 +3092,7 @@ struct phylink_pcs *rtpcs_create(struct device *dev, struct device_node *np, int
 {
        struct platform_device *pdev;
        struct device_node *pcs_np;
+       struct rtpcs_serdes *sds;
        struct rtpcs_ctrl *ctrl;
        struct rtpcs_link *link;
        u32 sds_id;
@@ -3124,8 +3127,12 @@ struct phylink_pcs *rtpcs_create(struct device *dev, struct device_node *np, int
                return ERR_PTR(-EINVAL);
        if (sds_id >= ctrl->cfg->serdes_count)
                return ERR_PTR(-EINVAL);
-       if (rtpcs_sds_read(&ctrl->serdes[sds_id], 0, 0) < 0)
+
+       sds = &ctrl->serdes[sds_id];
+       if (rtpcs_sds_read(sds, 0, 0) < 0)
                return ERR_PTR(-EINVAL);
+       if (sds->num_of_links >= RTPCS_MAX_LINKS_PER_SDS)
+               return ERR_PTR(-ERANGE);
 
        link = kzalloc(sizeof(*link), GFP_KERNEL);
        if (!link) {
@@ -3135,9 +3142,10 @@ struct phylink_pcs *rtpcs_create(struct device *dev, struct device_node *np, int
 
        device_link_add(dev, ctrl->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
 
+       sds->num_of_links++;
        link->ctrl = ctrl;
        link->port = port;
-       link->sds = &ctrl->serdes[sds_id];
+       link->sds = sds;
        link->pcs.ops = ctrl->cfg->pcs_ops;
        link->pcs.neg_mode = true;