From patchwork Wed Jun 2 16:20:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295255 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AD83C47083 for ; Wed, 2 Jun 2021 16:21:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12B2B61953 for ; Wed, 2 Jun 2021 16:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbhFBQXS (ORCPT ); Wed, 2 Jun 2021 12:23:18 -0400 Received: from mail-ed1-f49.google.com ([209.85.208.49]:46898 "EHLO mail-ed1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbhFBQXR (ORCPT ); Wed, 2 Jun 2021 12:23:17 -0400 Received: by mail-ed1-f49.google.com with SMTP id r11so3589367edt.13 for ; Wed, 02 Jun 2021 09:21:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=je7P0/kj9dkI/ARzdpLfXpbx3wW6XGZB976ubUlH0yw=; b=uYtgtHqKmYC3Md3nzN9DdbIQy+TVjJt2HANSXW+FAXy+bUGbUOIj08qmZDQRJ6ioxB +e+FOHuZJhwNry2KZgAYBcc5J0YWCrUp341yJVSTnEvxa+qclyhPXk3C9Jk1TgfRb3wC wrs/8gumjcYzTmQp9h5z9fLVj4eb/mOoomQIdlLRfN9TQzGUxkkFsUdkJmMaBA8dkD9J xfEgaJ+El3+VjcfaDGO20mPwOCPMC3jq4/f+NtRUZqVBRrMK2xKyiRZJEff7PVgyCE/u YT2zeVUTUyNcbLb3IInVr/MG58sluDvT6ev9g+BRDQKe3TU83oxNbciZhHtbEuObf7nm a8DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=je7P0/kj9dkI/ARzdpLfXpbx3wW6XGZB976ubUlH0yw=; b=uRDzvi59NM26/0EbjSEqfB3291B50RwVKx+CDa6GII5o1d3EhnEY0bekaxRmBPNfkj DFu9DiZawgYjK0d+PTDU1Xgm90C8hEXD1VilsrVeBFjIBHL/huf2tJerP6XDQp0ENvQF gCQcAaZ4yvu1e7AHeQDJwrhV5Vt7XLtMVrC9twg4QuhrhhS3ip9mZl2tcv5Gygd2b4MT Zq25a1H9ehPZ2UiYC3TuSW+8WIfDqpfP9I1AijiGW80BLo88jKFb/O3KuzmdNowKt9vh jLDhEu5srYr6aBYkJlyrHW5ZoAiE41ChAiNUVOY9NXeCWJVzQpK05Sdwb+mX5I6rVtA1 6h5g== X-Gm-Message-State: AOAM532qI1zvmmFxc0oIks1zDzeN1wkvXe2+0bCOjlAEhgjPCgKrtbR3 5zbbzdIztUc8HhgtyPLXyQIAr3uphoM= X-Google-Smtp-Source: ABdhPJx97gGZMN/nDz742EkP/FnQIPewnJyHPlLjia2AhXU2maHzDZhY5bJ1NOJtDTBXcvtLDsM46w== X-Received: by 2002:a05:6402:2049:: with SMTP id bc9mr19684863edb.298.1622650833111; Wed, 02 Jun 2021 09:20:33 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:32 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 1/9] net: pcs: xpcs: delete shim definition for mdio_xpcs_get_ops() Date: Wed, 2 Jun 2021 19:20:11 +0300 Message-Id: <20210602162019.2201925-2-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean CONFIG_STMMAC_ETH selects CONFIG_PCS_XPCS, so there should be no situation where the shim should be needed. Signed-off-by: Vladimir Oltean --- v1->v2: none v2->v3: none include/linux/pcs/pcs-xpcs.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 5938ced805f4..c4d0a2c469c7 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -36,13 +36,6 @@ struct mdio_xpcs_ops { int enable); }; -#if IS_ENABLED(CONFIG_PCS_XPCS) struct mdio_xpcs_ops *mdio_xpcs_get_ops(void); -#else -static inline struct mdio_xpcs_ops *mdio_xpcs_get_ops(void) -{ - return NULL; -} -#endif #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295257 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85B2FC47083 for ; Wed, 2 Jun 2021 16:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A21A61621 for ; Wed, 2 Jun 2021 16:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbhFBQXc (ORCPT ); Wed, 2 Jun 2021 12:23:32 -0400 Received: from mail-ej1-f50.google.com ([209.85.218.50]:37758 "EHLO mail-ej1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbhFBQXb (ORCPT ); Wed, 2 Jun 2021 12:23:31 -0400 Received: by mail-ej1-f50.google.com with SMTP id ce15so4722875ejb.4 for ; Wed, 02 Jun 2021 09:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6/ymcweiCG9wNftH8hsgp74pwu5eqC/48ceLEiARYPM=; b=tzdXGrsC6odo0fnJCxXY6HVlddqLHTitRdJqqh3yP6HxyiHEbdqrZGrWSWqo1nTIJr q7iR9cdPRBVPAMymJsmg6T77VmMQ4ONJ8qiUakGOOirghh0BFVD5+4hdy7iTESwotNWZ HdNbthCD9486m/59r/aim9CvHA2fKTFDlsf+P4HNci+zc+0qLwtAugI8xK+So5ZJvkvI 5+twkW0ZxJLUUBfHiOM4t35LC/oOB5v0TJa09zlQ5SFlHJeNRjfpyqAQhwpqLnYcCQUb BaNcQsMrvoZKr0Leb9kAr7CqWd+C9BImoVO3FBldNUsk15gqVRN5jzHpCP+66qcxVTu6 mp+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6/ymcweiCG9wNftH8hsgp74pwu5eqC/48ceLEiARYPM=; b=bqOsHiOCyILR+XPdlZOO0ad3o8ib47MxRIcm8wHjd/C8y7oQhX3cGEcCMVxHXGtSCT 3EFzSzm8SXDX6xduHQAeSAm/+5aosCVRb+vjEV8FlRueHzFZag+sX4YVj7j6qBe4CbuW sgsZ5o/qzRCwXTYTw8+NyPHcNh+HtK8kKjCK42+3iooxjn/ARZuGe6v3XT8cqI3OB5QB nsZEcqmd/LQ5jNb0bi5fdAhEg8uG2by8mnFeXbxrnkJVNl9+QnPS8yAV09YFt0qOlFT4 EYFnnsxK5SXPm18fjunwObzBDzdSvefc9LPGgY45rzUaxdP+DJNuZhSKMI8mo4KjCSyC I4sQ== X-Gm-Message-State: AOAM5305JMjTV4wPwsj+TZBgrHQyVZ65gZN4MB2hYmwI4RqieEgTg/ls YEddRWFEBdhRfaiO7rYwwBMTsJw5oys= X-Google-Smtp-Source: ABdhPJwwf970YPDqXsb/s5DWSwR3Tgw5zq9R9OuMungtZVLSqJXQ++3qIxvYpHnfKCp66LqGhnjhgA== X-Received: by 2002:a17:906:b794:: with SMTP id dt20mr34729729ejb.521.1622650834311; Wed, 02 Jun 2021 09:20:34 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:34 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 2/9] net: pcs: xpcs: there is only one PHY ID Date: Wed, 2 Jun 2021 19:20:12 +0300 Message-Id: <20210602162019.2201925-3-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The xpcs driver has an apparently inadequate structure for the actual hardware it drives. These defines and the xpcs_probe() function would suggest that there is one PHY ID per supported PHY interface type, and the driver simply validates whether the mode it should operate in (the argument of xpcs_probe) matches what the hardware is capable of: #define SYNOPSYS_XPCS_USXGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_10GKR_ID 0x7996ced0 #define SYNOPSYS_XPCS_XLGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_SGMII_ID 0x7996ced0 #define SYNOPSYS_XPCS_MASK 0xffffffff but that is not the case, because upon closer inspection, all the above 4 PHY ID definitions are in fact equal. So it is the same XPCS that is compatible with all 4 sets of PHY interface types. This change introduces an array of struct xpcs_compat which is populated by the single struct xpcs_id instance. It also eliminates the bogus defines for multiple Synopsys XPCS PHY IDs and replaces them with a single XPCS_ID, which better reflects the way in which the hardware operates. Because we are touching this area of the code anyway, the new array of struct xpcs_compat, as well as the array of xpcs_id, have been moved towards the end of the file, since they are variable declarations not definitions. If whichever of struct xpcs_compat or struct xpcs_id need to gain a function pointer member in the future, it is easier to reference functions (no forward declarations needed) if we have the const variable declarations at the end of the file. Signed-off-by: Vladimir Oltean --- v1->v2: patch is new v2->v3: move the xpcs_compat and xpcs_id declarations at the end, as well as note this in the commit message (needed for sja1105 support) drivers/net/pcs/pcs-xpcs.c | 129 ++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index aa985a5aae8d..9f2da9e873c4 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -12,10 +12,7 @@ #include #include -#define SYNOPSYS_XPCS_USXGMII_ID 0x7996ced0 -#define SYNOPSYS_XPCS_10GKR_ID 0x7996ced0 -#define SYNOPSYS_XPCS_XLGMII_ID 0x7996ced0 -#define SYNOPSYS_XPCS_SGMII_ID 0x7996ced0 +#define SYNOPSYS_XPCS_ID 0x7996ced0 #define SYNOPSYS_XPCS_MASK 0xffffffff /* Vendor regs access */ @@ -163,56 +160,39 @@ static const int xpcs_sgmii_features[] = { static const phy_interface_t xpcs_usxgmii_interfaces[] = { PHY_INTERFACE_MODE_USXGMII, - PHY_INTERFACE_MODE_MAX, }; static const phy_interface_t xpcs_10gkr_interfaces[] = { PHY_INTERFACE_MODE_10GKR, - PHY_INTERFACE_MODE_MAX, }; static const phy_interface_t xpcs_xlgmii_interfaces[] = { PHY_INTERFACE_MODE_XLGMII, - PHY_INTERFACE_MODE_MAX, }; static const phy_interface_t xpcs_sgmii_interfaces[] = { PHY_INTERFACE_MODE_SGMII, - PHY_INTERFACE_MODE_MAX, }; -static struct xpcs_id { - u32 id; - u32 mask; +enum { + DW_XPCS_USXGMII, + DW_XPCS_10GKR, + DW_XPCS_XLGMII, + DW_XPCS_SGMII, + DW_XPCS_INTERFACE_MAX, +}; + +struct xpcs_compat { const int *supported; const phy_interface_t *interface; + int num_interfaces; int an_mode; -} xpcs_id_list[] = { - { - .id = SYNOPSYS_XPCS_USXGMII_ID, - .mask = SYNOPSYS_XPCS_MASK, - .supported = xpcs_usxgmii_features, - .interface = xpcs_usxgmii_interfaces, - .an_mode = DW_AN_C73, - }, { - .id = SYNOPSYS_XPCS_10GKR_ID, - .mask = SYNOPSYS_XPCS_MASK, - .supported = xpcs_10gkr_features, - .interface = xpcs_10gkr_interfaces, - .an_mode = DW_AN_C73, - }, { - .id = SYNOPSYS_XPCS_XLGMII_ID, - .mask = SYNOPSYS_XPCS_MASK, - .supported = xpcs_xlgmii_features, - .interface = xpcs_xlgmii_interfaces, - .an_mode = DW_AN_C73, - }, { - .id = SYNOPSYS_XPCS_SGMII_ID, - .mask = SYNOPSYS_XPCS_MASK, - .supported = xpcs_sgmii_features, - .interface = xpcs_sgmii_interfaces, - .an_mode = DW_AN_C37_SGMII, - }, +}; + +struct xpcs_id { + u32 id; + u32 mask; + const struct xpcs_compat *compat; }; static int xpcs_read(struct mdio_xpcs_args *xpcs, int dev, u32 reg) @@ -911,35 +891,82 @@ static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs) } static bool xpcs_check_features(struct mdio_xpcs_args *xpcs, - struct xpcs_id *match, + const struct xpcs_id *match, phy_interface_t interface) { - int i; + int i, j; - for (i = 0; match->interface[i] != PHY_INTERFACE_MODE_MAX; i++) { - if (match->interface[i] == interface) - break; - } + for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { + const struct xpcs_compat *compat = &match->compat[i]; + bool supports_interface = false; - if (match->interface[i] == PHY_INTERFACE_MODE_MAX) - return false; + for (j = 0; j < compat->num_interfaces; j++) { + if (compat->interface[j] == interface) { + supports_interface = true; + break; + } + } + + if (!supports_interface) + continue; - for (i = 0; match->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++) - set_bit(match->supported[i], xpcs->supported); + /* Populate the supported link modes for this + * PHY interface type + */ + for (j = 0; compat->supported[j] != __ETHTOOL_LINK_MODE_MASK_NBITS; j++) + set_bit(compat->supported[j], xpcs->supported); - xpcs->an_mode = match->an_mode; + xpcs->an_mode = compat->an_mode; - return true; + return true; + } + + return false; } +static const struct xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { + [DW_XPCS_USXGMII] = { + .supported = xpcs_usxgmii_features, + .interface = xpcs_usxgmii_interfaces, + .num_interfaces = ARRAY_SIZE(xpcs_usxgmii_interfaces), + .an_mode = DW_AN_C73, + }, + [DW_XPCS_10GKR] = { + .supported = xpcs_10gkr_features, + .interface = xpcs_10gkr_interfaces, + .num_interfaces = ARRAY_SIZE(xpcs_10gkr_interfaces), + .an_mode = DW_AN_C73, + }, + [DW_XPCS_XLGMII] = { + .supported = xpcs_xlgmii_features, + .interface = xpcs_xlgmii_interfaces, + .num_interfaces = ARRAY_SIZE(xpcs_xlgmii_interfaces), + .an_mode = DW_AN_C73, + }, + [DW_XPCS_SGMII] = { + .supported = xpcs_sgmii_features, + .interface = xpcs_sgmii_interfaces, + .num_interfaces = ARRAY_SIZE(xpcs_sgmii_interfaces), + .an_mode = DW_AN_C37_SGMII, + }, +}; + +static const struct xpcs_id xpcs_id_list[] = { + { + .id = SYNOPSYS_XPCS_ID, + .mask = SYNOPSYS_XPCS_MASK, + .compat = synopsys_xpcs_compat, + }, +}; + static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) { + const struct xpcs_id *match = NULL; u32 xpcs_id = xpcs_get_id(xpcs); - struct xpcs_id *match = NULL; int i; for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { - struct xpcs_id *entry = &xpcs_id_list[i]; + const struct xpcs_id *entry = &xpcs_id_list[i]; if ((xpcs_id & entry->mask) == entry->id) { match = entry; From patchwork Wed Jun 2 16:20:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295261 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBAE1C4708F for ; Wed, 2 Jun 2021 16:21:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B354961948 for ; Wed, 2 Jun 2021 16:21:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbhFBQXj (ORCPT ); Wed, 2 Jun 2021 12:23:39 -0400 Received: from mail-ej1-f45.google.com ([209.85.218.45]:36585 "EHLO mail-ej1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229607AbhFBQXb (ORCPT ); Wed, 2 Jun 2021 12:23:31 -0400 Received: by mail-ej1-f45.google.com with SMTP id a11so4009380ejf.3 for ; Wed, 02 Jun 2021 09:21:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZwFdxR6KtulZD1ShgkQ7NtR/m6Bt92b8/+4ooloZOFU=; b=exu/496OR9j8PnMpEk4HGzzBZpjN/uUoINeAgpUXtqjKy208dsnZxDyA3y1uarmhO1 OPKfyrkletweqrDRqH3/AzZYSkrWOctLyqrtOuHuuTuiMZYPPqRc/TBiTzCs2edIsmPI vgUgZG8KXiewm01wGNIETiPwECxHcuvTbTlpXZCiSs/DGjvdMK1YK8BD8QEump39SNsR cW/w6uu1SD1qsNuGzX7LSGm3oPTv/GWPBBXQMTKCMWLxbrJJVWrmUC9R197yj8kFiH8x CFgPJSqs5JjAMvUtarrLoTAYRX1r8eLyNuYCeEnqHxBtpVAr2uOyFokCwl8VUq/UGiXR ZDTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZwFdxR6KtulZD1ShgkQ7NtR/m6Bt92b8/+4ooloZOFU=; b=GDx++i9eoSVxKWePo27j+9nAYXEj9wZ39VDNqgzs33Jv51I+StmaV5vZgzw9JAE8EU YfYSmLl9ZgzSNJWKQ5kL5vGWAtBHLNsS53yNjtXR/j/rBPk5xmWHRXVOIvwd+mMNuyeB LNPIQocUOZtrRwFFkYTqVzpH3j3itMhaIBGf7XjrHVdf64eZSoh8oCYJKX0UEGVT/Kcq GeQSqnG4LKum4wHVuoTqa8MMi/ZfXYkHPHKUF3j3yScwMRrX4p9+CxogXdtF37MRgcHk xZb+z9YpHBIzr1z9bHMaZxiUr3127qPT+MuxoOWtl0NrqxRvmSNEhrAQyUgY1N119kCW t7vQ== X-Gm-Message-State: AOAM530XvISahvLYxx55menjPlWQDlv9eFbdmS2HT5XdmEabYFXuGbqU oaJ+yO3uHMswrMB8CRKoeQo= X-Google-Smtp-Source: ABdhPJzBfhVSBXYZ32b/ECDinWWKPsHs3aVhATjzFXwErsxsV7GFrUNdaG4COxUbSBeEtAvZB3WHvg== X-Received: by 2002:a17:906:368e:: with SMTP id a14mr34353506ejc.366.1622650835483; Wed, 02 Jun 2021 09:20:35 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:35 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 3/9] net: pcs: xpcs: make the checks related to the PHY interface mode stateless Date: Wed, 2 Jun 2021 19:20:13 +0300 Message-Id: <20210602162019.2201925-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean The operating mode of the driver is currently to populate its struct mdio_xpcs_args::supported and struct mdio_xpcs_args::an_mode statically in xpcs_probe(), based on the passed phy_interface_t, and work with those. However this is not the operation that phylink expects from a PCS driver, because the port might be attached to an SFP cage that triggers changes of the phy_interface_t dynamically as one SFP module is unpluggged and another is plugged. To migrate towards that model, the struct mdio_xpcs_args should not cache anything related to the phy_interface_t, but just look up the statically defined, const struct xpcs_compat structure corresponding to the detected PCS OUI/model number. So we delete the "supported" and "an_mode" members of struct mdio_xpcs_args, and add the "id" structure there (since the ID is not expected to change at runtime). Since xpcs->supported is used deep in the code in _xpcs_config_aneg_c73(), we need to modify some function headers to pass the xpcs_compat from all callers. In turn, the xpcs_compat is always supplied externally to the xpcs module: - Most of the time by phylink - In xpcs_probe() it is needed because xpcs_soft_reset() writes to MDIO_MMD_PCS or to MDIO_MMD_VEND2 depending on whether an_mode is clause 37 or clause 73. In order to not introduce functional changes related to when the soft reset is issued, we continue to require the initial phy_interface_t argument to be passed to xpcs_probe() so we can pass this on to xpcs_soft_reset(). - stmmac_open() wants to know whether to call stmmac_init_phy() or not, and for that it looks inside xpcs->an_mode, because the clause 73 (backplane) AN modes supposedly do not have a PHY. Because we moved an_mode outside of struct mdio_xpcs_args, this is now no longer directly possible, so we introduce a helper function xpcs_get_an_mode() which protects the data encapsulation of the xpcs module and requires a phy_interface_t to be passed as argument. This function can look up the appropriate compat based on the phy_interface_t. Signed-off-by: Vladimir Oltean --- v1->v2: none v2->v3: none .../net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +- drivers/net/pcs/pcs-xpcs.c | 175 +++++++++++------- include/linux/pcs/pcs-xpcs.h | 6 +- 3 files changed, 120 insertions(+), 65 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9962a1041d35..129b103cd2b5 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3637,6 +3637,7 @@ static int stmmac_request_irq(struct net_device *dev) int stmmac_open(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); + int mode = priv->plat->phy_interface; int bfsize = 0; u32 chan; int ret; @@ -3649,7 +3650,8 @@ int stmmac_open(struct net_device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI && - priv->hw->xpcs_args.an_mode != DW_AN_C73) { + (!priv->hw->xpcs || + xpcs_get_an_mode(&priv->hw->xpcs_args, mode) != DW_AN_C73)) { ret = stmmac_init_phy(dev); if (ret) { netdev_err(priv->dev, diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 9f2da9e873c4..610073cb55d0 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -195,6 +195,49 @@ struct xpcs_id { const struct xpcs_compat *compat; }; +static const struct xpcs_compat *xpcs_find_compat(const struct xpcs_id *id, + phy_interface_t interface) +{ + int i, j; + + for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { + const struct xpcs_compat *compat = &id->compat[i]; + + for (j = 0; j < compat->num_interfaces; j++) + if (compat->interface[j] == interface) + return compat; + } + + return NULL; +} + +int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface) +{ + const struct xpcs_compat *compat; + + compat = xpcs_find_compat(xpcs->id, interface); + if (!compat) + return -ENODEV; + + return compat->an_mode; +} +EXPORT_SYMBOL_GPL(xpcs_get_an_mode); + +static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat, + enum ethtool_link_mode_bit_indices linkmode) +{ + int i; + + for (i = 0; compat->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++) + if (compat->supported[i] == linkmode) + return true; + + return false; +} + +#define xpcs_linkmode_supported(compat, mode) \ + __xpcs_linkmode_supported(compat, ETHTOOL_LINK_MODE_ ## mode ## _BIT) + static int xpcs_read(struct mdio_xpcs_args *xpcs, int dev, u32 reg) { u32 reg_addr = MII_ADDR_C45 | dev << 16 | reg; @@ -246,11 +289,12 @@ static int xpcs_poll_reset(struct mdio_xpcs_args *xpcs, int dev) return (ret & MDIO_CTRL1_RESET) ? -ETIMEDOUT : 0; } -static int xpcs_soft_reset(struct mdio_xpcs_args *xpcs) +static int xpcs_soft_reset(struct mdio_xpcs_args *xpcs, + const struct xpcs_compat *compat) { int ret, dev; - switch (xpcs->an_mode) { + switch (compat->an_mode) { case DW_AN_C73: dev = MDIO_MMD_PCS; break; @@ -419,7 +463,8 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) return xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST); } -static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) +static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs, + const struct xpcs_compat *compat) { int ret, adv; @@ -431,7 +476,7 @@ static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) /* SR_AN_ADV3 */ adv = 0; - if (phylink_test(xpcs->supported, 2500baseX_Full)) + if (xpcs_linkmode_supported(compat, 2500baseX_Full)) adv |= DW_C73_2500KX; /* TODO: 5000baseKR */ @@ -442,11 +487,11 @@ static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) /* SR_AN_ADV2 */ adv = 0; - if (phylink_test(xpcs->supported, 1000baseKX_Full)) + if (xpcs_linkmode_supported(compat, 1000baseKX_Full)) adv |= DW_C73_1000KX; - if (phylink_test(xpcs->supported, 10000baseKX4_Full)) + if (xpcs_linkmode_supported(compat, 10000baseKX4_Full)) adv |= DW_C73_10000KX4; - if (phylink_test(xpcs->supported, 10000baseKR_Full)) + if (xpcs_linkmode_supported(compat, 10000baseKR_Full)) adv |= DW_C73_10000KR; ret = xpcs_write(xpcs, MDIO_MMD_AN, DW_SR_AN_ADV2, adv); @@ -455,19 +500,20 @@ static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) /* SR_AN_ADV1 */ adv = DW_C73_AN_ADV_SF; - if (phylink_test(xpcs->supported, Pause)) + if (xpcs_linkmode_supported(compat, Pause)) adv |= DW_C73_PAUSE; - if (phylink_test(xpcs->supported, Asym_Pause)) + if (xpcs_linkmode_supported(compat, Asym_Pause)) adv |= DW_C73_ASYM_PAUSE; return xpcs_write(xpcs, MDIO_MMD_AN, DW_SR_AN_ADV1, adv); } -static int xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) +static int xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs, + const struct xpcs_compat *compat) { int ret; - ret = _xpcs_config_aneg_c73(xpcs); + ret = _xpcs_config_aneg_c73(xpcs, compat); if (ret < 0) return ret; @@ -481,7 +527,8 @@ static int xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs) } static int xpcs_aneg_done_c73(struct mdio_xpcs_args *xpcs, - struct phylink_link_state *state) + struct phylink_link_state *state, + const struct xpcs_compat *compat) { int ret; @@ -496,7 +543,7 @@ static int xpcs_aneg_done_c73(struct mdio_xpcs_args *xpcs, /* Check if Aneg outcome is valid */ if (!(ret & DW_C73_AN_ADV_SF)) { - xpcs_config_aneg_c73(xpcs); + xpcs_config_aneg_c73(xpcs, compat); return 0; } @@ -642,8 +689,31 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state) { - linkmode_and(supported, supported, xpcs->supported); - linkmode_and(state->advertising, state->advertising, xpcs->supported); + __ETHTOOL_DECLARE_LINK_MODE_MASK(xpcs_supported); + const struct xpcs_compat *compat; + int i; + + /* phylink expects us to report all supported modes with + * PHY_INTERFACE_MODE_NA, just don't limit the supported and + * advertising masks and exit. + */ + if (state->interface == PHY_INTERFACE_MODE_NA) + return 0; + + bitmap_zero(xpcs_supported, __ETHTOOL_LINK_MODE_MASK_NBITS); + + compat = xpcs_find_compat(xpcs->id, state->interface); + + /* Populate the supported link modes for this + * PHY interface type + */ + if (compat) + for (i = 0; compat->supported[i] != __ETHTOOL_LINK_MODE_MASK_NBITS; i++) + set_bit(compat->supported[i], xpcs_supported); + + linkmode_and(supported, supported, xpcs_supported); + linkmode_and(state->advertising, state->advertising, xpcs_supported); + return 0; } @@ -724,12 +794,17 @@ static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs) static int xpcs_config(struct mdio_xpcs_args *xpcs, const struct phylink_link_state *state) { + const struct xpcs_compat *compat; int ret; - switch (xpcs->an_mode) { + compat = xpcs_find_compat(xpcs->id, state->interface); + if (!compat) + return -ENODEV; + + switch (compat->an_mode) { case DW_AN_C73: if (state->an_enabled) { - ret = xpcs_config_aneg_c73(xpcs); + ret = xpcs_config_aneg_c73(xpcs, compat); if (ret) return ret; } @@ -747,7 +822,8 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs, } static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, - struct phylink_link_state *state) + struct phylink_link_state *state, + const struct xpcs_compat *compat) { int ret; @@ -757,7 +833,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, /* ... and then we check the faults. */ ret = xpcs_read_fault_c73(xpcs, state); if (ret) { - ret = xpcs_soft_reset(xpcs); + ret = xpcs_soft_reset(xpcs, compat); if (ret) return ret; @@ -766,7 +842,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, return xpcs_config(xpcs, state); } - if (state->an_enabled && xpcs_aneg_done_c73(xpcs, state)) { + if (state->an_enabled && xpcs_aneg_done_c73(xpcs, state, compat)) { state->an_complete = true; xpcs_read_lpa_c73(xpcs, state); xpcs_resolve_lpa_c73(xpcs, state); @@ -823,11 +899,16 @@ static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs, static int xpcs_get_state(struct mdio_xpcs_args *xpcs, struct phylink_link_state *state) { + const struct xpcs_compat *compat; int ret; - switch (xpcs->an_mode) { + compat = xpcs_find_compat(xpcs->id, state->interface); + if (!compat) + return -ENODEV; + + switch (compat->an_mode) { case DW_AN_C73: - ret = xpcs_get_state_c73(xpcs, state); + ret = xpcs_get_state_c73(xpcs, state, compat); if (ret) return ret; break; @@ -890,40 +971,6 @@ static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs) return 0xffffffff; } -static bool xpcs_check_features(struct mdio_xpcs_args *xpcs, - const struct xpcs_id *match, - phy_interface_t interface) -{ - int i, j; - - for (i = 0; i < DW_XPCS_INTERFACE_MAX; i++) { - const struct xpcs_compat *compat = &match->compat[i]; - bool supports_interface = false; - - for (j = 0; j < compat->num_interfaces; j++) { - if (compat->interface[j] == interface) { - supports_interface = true; - break; - } - } - - if (!supports_interface) - continue; - - /* Populate the supported link modes for this - * PHY interface type - */ - for (j = 0; compat->supported[j] != __ETHTOOL_LINK_MODE_MASK_NBITS; j++) - set_bit(compat->supported[j], xpcs->supported); - - xpcs->an_mode = compat->an_mode; - - return true; - } - - return false; -} - static const struct xpcs_compat synopsys_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { [DW_XPCS_USXGMII] = { .supported = xpcs_usxgmii_features, @@ -961,19 +1008,23 @@ static const struct xpcs_id xpcs_id_list[] = { static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) { - const struct xpcs_id *match = NULL; u32 xpcs_id = xpcs_get_id(xpcs); int i; for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { const struct xpcs_id *entry = &xpcs_id_list[i]; + const struct xpcs_compat *compat; - if ((xpcs_id & entry->mask) == entry->id) { - match = entry; + if ((xpcs_id & entry->mask) != entry->id) + continue; - if (xpcs_check_features(xpcs, match, interface)) - return xpcs_soft_reset(xpcs); - } + xpcs->id = entry; + + compat = xpcs_find_compat(entry, interface); + if (!compat) + return -ENODEV; + + return xpcs_soft_reset(xpcs, compat); } return -ENODEV; diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index c4d0a2c469c7..c2ec440d2c5d 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -14,11 +14,12 @@ #define DW_AN_C73 1 #define DW_AN_C37_SGMII 2 +struct xpcs_id; + struct mdio_xpcs_args { - __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); struct mii_bus *bus; + const struct xpcs_id *id; int addr; - int an_mode; }; struct mdio_xpcs_ops { @@ -36,6 +37,7 @@ struct mdio_xpcs_ops { int enable); }; +int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); struct mdio_xpcs_ops *mdio_xpcs_get_ops(void); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295259 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA79C4708F for ; Wed, 2 Jun 2021 16:21:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA0BC61953 for ; Wed, 2 Jun 2021 16:21:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbhFBQXg (ORCPT ); Wed, 2 Jun 2021 12:23:36 -0400 Received: from mail-ej1-f51.google.com ([209.85.218.51]:34529 "EHLO mail-ej1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229654AbhFBQXb (ORCPT ); Wed, 2 Jun 2021 12:23:31 -0400 Received: by mail-ej1-f51.google.com with SMTP id g8so4762821ejx.1 for ; Wed, 02 Jun 2021 09:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bq4oZb2dKio7jhtcSXyjTHi6FvT3v8gKCUi4OjyUpAI=; b=SmG/q6ZFigw9LUv331lYY33G/RUbSmOSdZR4CqfUz1L85Ij5lNCo1VJ0dJrxdw98ah DankNTWBTBhppN6qHhxv5Jvg5jMxIM5btdBvYalztzI/BlbCNfKpCVBKNkT29xKTQafY aQyd/CR/D8tSWCBFnk1K/fbsh4X0tloeziC0Tv9CZDvAs12k+HmSG1HunP1YozGSniK9 0nIbk5gQYKrhbh5z9k4yyFq6kyFgwIUDRVpDt5aD95ebXTqTyHGp9sB2L7xvjIJC5hdO zRjF/NtxwnNL0Am/qv1QPyIZpHLXipvC43u56rMPJnlDryIUYc9VrnsV4T32inAOkrIu OpDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bq4oZb2dKio7jhtcSXyjTHi6FvT3v8gKCUi4OjyUpAI=; b=daGb+ooJwLzOkcT49Ho18ipoiH3w38hHIZgRvRXXJNL59DF81Y2Z1KsMEpmX3CdeFd AXSnqfOgddaVIWiVNAOnET3EGd5aE/6L+3kgY2NGPJlP2/O603UwOU/C7e8mhtRSZTfX iPf+W+22QJVp7sNFYfqqQQchKLZOcqcoa1NyHExhmhSp3LksrRllPpSRfRRe3Qr5z0n8 FzINexd013rWtWXIDKWW13uSflzkagZT3dH+gLaAUNEIGwJOMyl9V9OthtRyTBNrJqvu PpQhgCRu2+xNFmpCD9+YCRoi4PPXIeiIgw7ac7xQN3WH75wWzxvL5lOzZ59KvI0790ep 54EQ== X-Gm-Message-State: AOAM533BK4AVqVTm6AY4wphp5Mt/GX4A8bo3hKK9Bi0+EOEzs+IK/tkH qXLpnwm8kEgKB+nDjurS4o4Wdy1OggA= X-Google-Smtp-Source: ABdhPJzOZTcycaOCxrWxDDyxXlEJvGgvUmtBpEzsDgKIPKk1HcOmV1Jol4LW1bdLQJYOETAJpzZKKw== X-Received: by 2002:a17:906:d297:: with SMTP id ay23mr27183959ejb.418.1622650836659; Wed, 02 Jun 2021 09:20:36 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:36 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 4/9] net: pcs: xpcs: export xpcs_validate Date: Wed, 2 Jun 2021 19:20:14 +0300 Message-Id: <20210602162019.2201925-5-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Calling a function pointer with a single implementation through struct mdio_xpcs_ops is clunky, and the stmmac_do_callback system forces this to return int, even though it always returns zero. Simply remove the "validate" function pointer from struct mdio_xpcs_ops and replace it with an exported xpcs_validate symbol which is called directly by stmmac. priv->hw->xpcs is of the type "const struct mdio_xpcs_ops *" and is used as a placeholder/synonym for priv->plat->mdio_bus_data->has_xpcs. It is done that way because the mdio_bus_data pointer might or might not be populated in all stmmac instantiations. Signed-off-by: Vladimir Oltean --- v1->v2: guard against potential absence of xpcs on the port v2->v3: none drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 ++- drivers/net/pcs/pcs-xpcs.c | 11 ++++------- include/linux/pcs/pcs-xpcs.h | 5 ++--- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 75a8b90c202a..a86b358feae9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -613,8 +613,6 @@ struct stmmac_mmc_ops { stmmac_do_void_callback(__priv, mmc, read, __args) /* XPCS callbacks */ -#define stmmac_xpcs_validate(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, validate, __args) #define stmmac_xpcs_config(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, config, __args) #define stmmac_xpcs_get_state(__priv, __args...) \ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 129b103cd2b5..9f72e4dd1457 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -996,7 +996,8 @@ static void stmmac_validate(struct phylink_config *config, linkmode_andnot(state->advertising, state->advertising, mask); /* If PCS is supported, check which modes it supports. */ - stmmac_xpcs_validate(priv, &priv->hw->xpcs_args, supported, state); + if (priv->hw->xpcs) + xpcs_validate(&priv->hw->xpcs_args, supported, state); } static void stmmac_mac_pcs_get_state(struct phylink_config *config, diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 610073cb55d0..2f7791bcf07b 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -685,9 +685,8 @@ static void xpcs_resolve_pma(struct mdio_xpcs_args *xpcs, } } -static int xpcs_validate(struct mdio_xpcs_args *xpcs, - unsigned long *supported, - struct phylink_link_state *state) +void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, + struct phylink_link_state *state) { __ETHTOOL_DECLARE_LINK_MODE_MASK(xpcs_supported); const struct xpcs_compat *compat; @@ -698,7 +697,7 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs, * advertising masks and exit. */ if (state->interface == PHY_INTERFACE_MODE_NA) - return 0; + return; bitmap_zero(xpcs_supported, __ETHTOOL_LINK_MODE_MASK_NBITS); @@ -713,9 +712,8 @@ static int xpcs_validate(struct mdio_xpcs_args *xpcs, linkmode_and(supported, supported, xpcs_supported); linkmode_and(state->advertising, state->advertising, xpcs_supported); - - return 0; } +EXPORT_SYMBOL_GPL(xpcs_validate); static int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, int enable) @@ -1031,7 +1029,6 @@ static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) } static struct mdio_xpcs_ops xpcs_ops = { - .validate = xpcs_validate, .config = xpcs_config, .get_state = xpcs_get_state, .link_up = xpcs_link_up, diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index c2ec440d2c5d..5ec9aaca01fe 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -23,9 +23,6 @@ struct mdio_xpcs_args { }; struct mdio_xpcs_ops { - int (*validate)(struct mdio_xpcs_args *xpcs, - unsigned long *supported, - struct phylink_link_state *state); int (*config)(struct mdio_xpcs_args *xpcs, const struct phylink_link_state *state); int (*get_state)(struct mdio_xpcs_args *xpcs, @@ -39,5 +36,7 @@ struct mdio_xpcs_ops { int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); struct mdio_xpcs_ops *mdio_xpcs_get_ops(void); +void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, + struct phylink_link_state *state); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295253 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DE9C47083 for ; Wed, 2 Jun 2021 16:20:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFDC861948 for ; Wed, 2 Jun 2021 16:20:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbhFBQWj (ORCPT ); Wed, 2 Jun 2021 12:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbhFBQWg (ORCPT ); Wed, 2 Jun 2021 12:22:36 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90DD9C061574 for ; Wed, 2 Jun 2021 09:20:39 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id g8so4762929ejx.1 for ; Wed, 02 Jun 2021 09:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2DA9HGV5gAHjmfQUTJ8KwvaU2kjt03us8kFBmkRGg04=; b=hGIhBjM8Huo+Pc1+tWAHnYM82N3c0RGdXEYIztPwsTLgRjTkU3IhqTL9fMVK7DJywM owszF4b0rTuFfUf6KoBTAuNh/9BiYiZEdY61wTlpQieuktOnWZAQP3IIwLbOOySedeqS hkkX/NvIEiGHtQW283a4MxcRzbALOCFFU27Fxe0CFiQxq6ffhFyHNkjyRUTATWAqBnXg noP0QiVTk5QCbQoN2Dv7Nn76lBBFKQTmVscfkNTO6F+FsI6tkZQpk6zfkH5q4AlJcGzR 0ti/lTOxfnjahq3nzS4XymVt2s5+nGh+PaTNtCikNQVY4W9SZ6cr+IFaCDUXVam7r5LF 7XVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2DA9HGV5gAHjmfQUTJ8KwvaU2kjt03us8kFBmkRGg04=; b=Fh87hi9TkvSKZMSbXUUKKUvVdPKayQ7gmuoMxrk3Z6H0pjv7G6ANs3BqTTpIQoiiDa 3PTxmGOnG0Etuj/ZQ/YCeqjaHJnrqXAcxpElVsVLncx3Jbw5Gj8N8KPYkfll0ZgiNjjt kejesD++eGFHi+PCuKirAsaz/P76Kwxnh6RIvodpuUqIPHCl6ID8PJH06GHNOMA1osAN RpEG4PAtUTCXTHwZf9k/Ww5YzsBgi0hwt+zCYvcnS/tZ7+0WYCXICevM5b28L65J3aEl YoOjZ05wfFBDniHv3PkzLGTPZXjX9xcIV8U2KbSHumFNM0zyNwftlXZHsDn+ucYbaSjE +yBw== X-Gm-Message-State: AOAM533rJ6mkYJW7FMqzR5fNjUUFsXdoE2MZ4M8p55s5SDxXd/6U69Xl 0Zu2xQeROstaYAJTaOAHEUc= X-Google-Smtp-Source: ABdhPJw8/VmkzjMsE9GPy3gXpff8sNigFUICRddcGJMMxe9PdtUKytIJ8j4vcZ+eqOv7qP7GC0VNbg== X-Received: by 2002:a17:906:63d2:: with SMTP id u18mr34803214ejk.186.1622650838090; Wed, 02 Jun 2021 09:20:38 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:37 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 5/9] net: pcs: xpcs: export xpcs_config_eee Date: Wed, 2 Jun 2021 19:20:15 +0300 Message-Id: <20210602162019.2201925-6-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean There is no good reason why we need to go through: stmmac_xpcs_config_eee -> stmmac_do_callback -> mdio_xpcs_ops->config_eee -> xpcs_config_eee when we can simply call xpcs_config_eee. priv->hw->xpcs is of the type "const struct mdio_xpcs_ops *" and is used as a placeholder/synonym for priv->plat->mdio_bus_data->has_xpcs. It is done that way because the mdio_bus_data pointer might or might not be populated in all stmmac instantiations. Signed-off-by: Vladimir Oltean --- v1->v2: guard against potential absence of xpcs on the port v2->v3: none drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 12 +++++++----- drivers/net/pcs/pcs-xpcs.c | 6 +++--- include/linux/pcs/pcs-xpcs.h | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index a86b358feae9..2d2843edaf21 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -621,8 +621,6 @@ struct stmmac_mmc_ops { stmmac_do_callback(__priv, xpcs, link_up, __args) #define stmmac_xpcs_probe(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, probe, __args) -#define stmmac_xpcs_config_eee(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, config_eee, __args) struct stmmac_regs_off { u32 ptp_off; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 1f6d749fd9a3..ba7d0f40723a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -720,11 +720,13 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, netdev_warn(priv->dev, "Setting EEE tx-lpi is not supported\n"); - ret = stmmac_xpcs_config_eee(priv, &priv->hw->xpcs_args, - priv->plat->mult_fact_100ns, - edata->eee_enabled); - if (ret) - return ret; + if (priv->hw->xpcs) { + ret = xpcs_config_eee(&priv->hw->xpcs_args, + priv->plat->mult_fact_100ns, + edata->eee_enabled); + if (ret) + return ret; + } if (!edata->eee_enabled) stmmac_disable_eee_mode(priv); diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 2f7791bcf07b..2f2ffab855aa 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -715,8 +715,8 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, } EXPORT_SYMBOL_GPL(xpcs_validate); -static int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, - int enable) +int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, + int enable) { int ret; @@ -747,6 +747,7 @@ static int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, ret |= DW_VR_MII_EEE_TRN_LPI; return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_EEE_MCTRL1, ret); } +EXPORT_SYMBOL_GPL(xpcs_config_eee); static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs) { @@ -1033,7 +1034,6 @@ static struct mdio_xpcs_ops xpcs_ops = { .get_state = xpcs_get_state, .link_up = xpcs_link_up, .probe = xpcs_probe, - .config_eee = xpcs_config_eee, }; struct mdio_xpcs_ops *mdio_xpcs_get_ops(void) diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 5ec9aaca01fe..ae74a336dcb9 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -30,13 +30,13 @@ struct mdio_xpcs_ops { int (*link_up)(struct mdio_xpcs_args *xpcs, int speed, phy_interface_t interface); int (*probe)(struct mdio_xpcs_args *xpcs, phy_interface_t interface); - int (*config_eee)(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, - int enable); }; int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); struct mdio_xpcs_ops *mdio_xpcs_get_ops(void); void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state); +int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, + int enable); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295249 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8518AC4708F for ; Wed, 2 Jun 2021 16:20:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 68E0D61959 for ; Wed, 2 Jun 2021 16:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229886AbhFBQWY (ORCPT ); Wed, 2 Jun 2021 12:22:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbhFBQWX (ORCPT ); Wed, 2 Jun 2021 12:22:23 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A869AC061756 for ; Wed, 2 Jun 2021 09:20:40 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a11so4009624ejf.3 for ; Wed, 02 Jun 2021 09:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LCg9Dutw1JRzfj+NqxI+WdW2d+OdsEcix9C/qdUkoaI=; b=pEqFvvXCO2O1bfnMpxPql0NT9QLMEFzpnwZcmQJEEC/0MCs/Ml+mi2YtpKnlH/+qL9 mrmleUuS3HEoKUf08wzvgm3vH248+boWpu85Npb+egvFIAE+j7YhDHrnh5Ci0QEbfVvE oxV6JtUZU5BbgrfwjsImlnMHrmz/b9yY/uMrNPE/e9w0kwXDEhmqVx3Swd/1eBWR90fR CXsvgvyH61h15YcaiPKAyB/4xS2T3Q05aDVYCN3iutqMzxm9tz3sjtOWb7BTt47w7zEa b4asKoLxFCbKZV4QiWxRq5FwxyPVvkGjhY5bjDGklsIgMz9frZaBotbxUbSKy1LnJXRN 0LSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LCg9Dutw1JRzfj+NqxI+WdW2d+OdsEcix9C/qdUkoaI=; b=hS8GQ71ONSIbShLT7TeYWMmJu3lJtHfaCYh4+/SPkmUrzoASgWFnAzmWk0UBLnti7D aKs16X62P59y6vmRD+jZMw/JEWw8y1egXouzIAU7Z8gvhJlGSWN0qdxfdWzoRz1uc+gX ocYuGvsXNUmSD2bSjlwJn+1Ydhkq1mYyNQWirL6+sldiL6aVlC5jzE85ld7Eo02PGCm8 9aiQVQNGT1RurU/A61Wx1MuIR6P1O7C9BCbmWxspUhMWsdTj8sZyRU7MNOoierpSidXK oaSowlkHuQwebcrXamec2yknjGgRohc8DEvFDlAA5lUcHWfmLjNUv+O9Xa7X4SgIg1Ib BzDA== X-Gm-Message-State: AOAM532i01WTMmXxQpaEjCnUTjupbgBF3Gsi8lvLyHlTjme2FiLCZYx5 EBjKlbmM0Tvm9Ydrf8RlB1UN4UsGslo= X-Google-Smtp-Source: ABdhPJwrO1GqXAqfLADuvwCQUK0lUM2yLkQ82h/YTl+x0RQayK6aV1sp9dz91S9uLSnX6wu/szpTuw== X-Received: by 2002:a17:906:8041:: with SMTP id x1mr13052671ejw.81.1622650839307; Wed, 02 Jun 2021 09:20:39 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:39 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 6/9] net: pcs: xpcs: export xpcs_probe Date: Wed, 2 Jun 2021 19:20:16 +0300 Message-Id: <20210602162019.2201925-7-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Similar to the other recently functions, it is not necessary for xpcs_probe to be a function pointer, so export it so that it can be called directly. Signed-off-by: Vladimir Oltean --- v1->v2: keep passing the phy_interface_t argument to xpcs_probe v2->v3: none drivers/net/ethernet/stmicro/stmmac/hwif.h | 2 -- drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 2 +- drivers/net/pcs/pcs-xpcs.c | 4 ++-- include/linux/pcs/pcs-xpcs.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 2d2843edaf21..5014b260844b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -619,8 +619,6 @@ struct stmmac_mmc_ops { stmmac_do_callback(__priv, xpcs, get_state, __args) #define stmmac_xpcs_link_up(__priv, __args...) \ stmmac_do_callback(__priv, xpcs, link_up, __args) -#define stmmac_xpcs_probe(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, probe, __args) struct stmmac_regs_off { u32 ptp_off; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index e293bf1ce9f3..56deb92a8430 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -521,7 +521,7 @@ int stmmac_mdio_register(struct net_device *ndev) for (addr = 0; addr < max_addr; addr++) { xpcs->addr = addr; - ret = stmmac_xpcs_probe(priv, xpcs, mode); + ret = xpcs_probe(xpcs, mode); if (!ret) { found = 1; break; diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 2f2ffab855aa..7f51eb4bbaa4 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -1005,7 +1005,7 @@ static const struct xpcs_id xpcs_id_list[] = { }, }; -static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) +int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) { u32 xpcs_id = xpcs_get_id(xpcs); int i; @@ -1028,12 +1028,12 @@ static int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) return -ENODEV; } +EXPORT_SYMBOL_GPL(xpcs_probe); static struct mdio_xpcs_ops xpcs_ops = { .config = xpcs_config, .get_state = xpcs_get_state, .link_up = xpcs_link_up, - .probe = xpcs_probe, }; struct mdio_xpcs_ops *mdio_xpcs_get_ops(void) diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index ae74a336dcb9..1d8581b74d81 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -29,7 +29,6 @@ struct mdio_xpcs_ops { struct phylink_link_state *state); int (*link_up)(struct mdio_xpcs_args *xpcs, int speed, phy_interface_t interface); - int (*probe)(struct mdio_xpcs_args *xpcs, phy_interface_t interface); }; int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); @@ -38,5 +37,6 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state); int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, int enable); +int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295267 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 027D2C4708F for ; Wed, 2 Jun 2021 16:22:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3C2D61958 for ; Wed, 2 Jun 2021 16:22:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbhFBQXs (ORCPT ); Wed, 2 Jun 2021 12:23:48 -0400 Received: from mail-ej1-f49.google.com ([209.85.218.49]:44846 "EHLO mail-ej1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbhFBQXk (ORCPT ); Wed, 2 Jun 2021 12:23:40 -0400 Received: by mail-ej1-f49.google.com with SMTP id c10so4662666eja.11 for ; Wed, 02 Jun 2021 09:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=InEy5/81GRSeKeQLmbl3JxFBwNC56Mf2ggNeB4hyCvg=; b=qIlT/RIakNceShPJINUCMN81CDz548JJCWRZItng/Ekm/iEnqnHY8TnX8kP5pj7DXA Go0xpJFP1e4QZcf0QGetwRE2zmpg+LwGnxIoL+hIqOhq7xd/McR5akTtWBFQpVTz6p4E FHI64pZLwYBlzR+qMGGLsnnwgbGRLuPmH3R8SP9KthsmyjmgcWIkqpewYFPchGVX4hDe Mu4KTYxPs+wr1QIMSf1/jz3QrLWklhsMKvu6X9bYyazDv871UqMta4U3xYc9a/Tabwt6 QgNTCIpd2w47I8rGBaGb4nqfaHeFMKwHMLAzoazs7BXW0IxQRiqrlXIw5J3J888hgXq8 CGcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=InEy5/81GRSeKeQLmbl3JxFBwNC56Mf2ggNeB4hyCvg=; b=uPv/g17o1WQMFGHIrJCU7MyE7SUUa7TRM/BN8VA0oFL88WlWekhqkjoI1jjSn7k6fr 1rCZlZB9Mz6GXjsQdFMVPZbWTG3eXwjDW9uLa6jUW4eoL711adKkfMPuEuyoJExWvkbl kdWxea5pnlPZjbstGH53/CxDxYatJmwUGglGcn/Aef6QYa/+hy277ID9p30CBEPzdXSf DI6svrKfFpt2YZm62QaiL2K6BZDPM+DyBrDxorWLv6mAdJX9eEDjQPzH7/uD6LTM0PY4 f6yUNsrlAlPoIhRfTxwrCtoR10o2tnh2Xek39V6ZEiMeD+/LxNJULLTZ/HH5taSHONa1 DpgQ== X-Gm-Message-State: AOAM531/oPPJwnziixGN91h7N052xHphcaRvy9LS4THvALJF4vJP2RLx +H+m0JaI5bOW4UgxHfPfFVY= X-Google-Smtp-Source: ABdhPJyDRFMTham/AX0crT5WaUd9esixo9ZDUjkuycQ0o/p35jj/lO9XKCJEpzi7CW6bl7AFVzhseA== X-Received: by 2002:a17:906:4d04:: with SMTP id r4mr16476496eju.76.1622650840440; Wed, 02 Jun 2021 09:20:40 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:40 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 7/9] net: pcs: xpcs: use mdiobus_c45_addr in xpcs_{read,write} Date: Wed, 2 Jun 2021 19:20:17 +0300 Message-Id: <20210602162019.2201925-8-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Use the dedicated helper for abstracting away how the clause 45 address is packed in reg_addr. Signed-off-by: Vladimir Oltean --- v1->v2: none v2->v3: none drivers/net/pcs/pcs-xpcs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index 7f51eb4bbaa4..afabb9209c52 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -240,14 +240,14 @@ static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat, static int xpcs_read(struct mdio_xpcs_args *xpcs, int dev, u32 reg) { - u32 reg_addr = MII_ADDR_C45 | dev << 16 | reg; + u32 reg_addr = mdiobus_c45_addr(dev, reg); return mdiobus_read(xpcs->bus, xpcs->addr, reg_addr); } static int xpcs_write(struct mdio_xpcs_args *xpcs, int dev, u32 reg, u16 val) { - u32 reg_addr = MII_ADDR_C45 | dev << 16 | reg; + u32 reg_addr = mdiobus_c45_addr(dev, reg); return mdiobus_write(xpcs->bus, xpcs->addr, reg_addr, val); } From patchwork Wed Jun 2 16:20:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295265 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A115C47083 for ; Wed, 2 Jun 2021 16:22:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3605F61953 for ; Wed, 2 Jun 2021 16:22:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbhFBQXn (ORCPT ); Wed, 2 Jun 2021 12:23:43 -0400 Received: from mail-ed1-f52.google.com ([209.85.208.52]:45713 "EHLO mail-ed1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbhFBQXh (ORCPT ); Wed, 2 Jun 2021 12:23:37 -0400 Received: by mail-ed1-f52.google.com with SMTP id dg27so3584659edb.12 for ; Wed, 02 Jun 2021 09:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zODqhf+CDFdGnQOAOvwJ5OGF2rDKwwZmXn4xipM6OwQ=; b=GEdJikQINzr5qIJzL38Ox6xVOHNxghZSAe/dCYarYw5tKbTVfY0MQGYO4iQoPv8o18 N6+/FFtcS3IjLclyeavtYNmUSsmuDym3KxtfaYF2ZhnxW4w1LhUz83wFzAC5IsYN0+lc 1yL833wiExCaNwxW0S7XgDnw8cMnoBbH9XPhPcipV2C7o2GJN23jpnHmZxeR/Ud4awhe jW8Rq8Fy8Zj6N06M6uiEqY/poJYpQteLJ0qFRliaYxn6iqRk9XtcqW7Osxmkv2gEALnJ 7iYO16reImIGR2Q0jhps+hQhPJ5ffaSNGj6f80dezgxz4zXRSqSZwW9QmpoikUFFjXtr 4m5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zODqhf+CDFdGnQOAOvwJ5OGF2rDKwwZmXn4xipM6OwQ=; b=BVd6t+XmCi5oomiEKNkRN0P/pCpSLcIcfhtOThZt/8ba7IsQuVbFZt51hsHrphRT2T YlwfG9yRCyW9zyBk/bBWf6uF8y0aWKYqxGgo/ah9+e0thDw2Y5YJSonOOPI9Y/4t8I5/ Refh/riNKzHwR7nlYO8fRMR8NZfvNRfq+78kkt46Ktm4BmsVzvk64ni2U7O62dpHreO7 fdURcyFqqZjXCMyXEqKacRGzwGKjbmGTnv1FLEZPHDJWJzwTIPtAxPymnF1FpyrhJBTR MOmMInKn1n+VfsL0qI1rRMD3Hcw0gw5BhzpX/0M6D48xKyZ0ay35Oms/gNAAJ+pxmpzw AzSA== X-Gm-Message-State: AOAM530fibJOB1pX30AQzOiCY3TMaZTImC6NL6D9WRG0ooj8bJt9JX7h bC+l7G8Jgo8uN1QfMsp6eK0= X-Google-Smtp-Source: ABdhPJyn0sY0RUMDezmiIkVTqRu8peltFq3Gu9/euSgd6LTf7JjYlQqKMIw/p9Mc8mZpryxQAqFBsA== X-Received: by 2002:aa7:da94:: with SMTP id q20mr2314890eds.310.1622650841601; Wed, 02 Jun 2021 09:20:41 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:41 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 8/9] net: pcs: xpcs: convert to mdio_device Date: Wed, 2 Jun 2021 19:20:18 +0300 Message-Id: <20210602162019.2201925-9-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Unify the 2 existing PCS drivers (lynx and xpcs) by doing a similar thing on probe, which is to have a *_create function that takes a struct mdio_device * given by the caller, and builds a private PCS structure around that. This changes stmmac to hold only a pointer to the xpcs, as opposed to the full structure. This will be used in the next patch when struct mdio_xpcs_ops is removed. Currently a pointer to struct mdio_xpcs_ops is used as a shorthand to determine whether the port has an XPCS or not. We can do the same now with the mdio_xpcs_args pointer. Signed-off-by: Vladimir Oltean --- v1->v2: move this patch in front of the phylink_pcs_ops conversion so that stmmac has a pointer to check against v2->v3: none drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 ++-- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 39 ++++++++------ drivers/net/pcs/pcs-xpcs.c | 53 +++++++++++++++---- include/linux/pcs/pcs-xpcs.h | 7 +-- 6 files changed, 76 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 619e3c0760d6..4bcd1d340766 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -504,7 +504,7 @@ struct mac_device_info { const struct stmmac_tc_ops *tc; const struct stmmac_mmc_ops *mmc; const struct mdio_xpcs_ops *xpcs; - struct mdio_xpcs_args xpcs_args; + struct mdio_xpcs_args *xpcs_args; struct mii_regs mii; /* MII register Addresses */ struct mac_link link; void __iomem *pcsr; /* vpointer to device CSRs */ diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index ba7d0f40723a..050576ee704d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, "Setting EEE tx-lpi is not supported\n"); if (priv->hw->xpcs) { - ret = xpcs_config_eee(&priv->hw->xpcs_args, + ret = xpcs_config_eee(priv->hw->xpcs_args, priv->plat->mult_fact_100ns, edata->eee_enabled); if (ret) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 9f72e4dd1457..426c8f891f5a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -997,7 +997,7 @@ static void stmmac_validate(struct phylink_config *config, /* If PCS is supported, check which modes it supports. */ if (priv->hw->xpcs) - xpcs_validate(&priv->hw->xpcs_args, supported, state); + xpcs_validate(priv->hw->xpcs_args, supported, state); } static void stmmac_mac_pcs_get_state(struct phylink_config *config, @@ -1006,7 +1006,7 @@ static void stmmac_mac_pcs_get_state(struct phylink_config *config, struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); state->link = 0; - stmmac_xpcs_get_state(priv, &priv->hw->xpcs_args, state); + stmmac_xpcs_get_state(priv, priv->hw->xpcs_args, state); } static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, @@ -1014,7 +1014,7 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, { struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); - stmmac_xpcs_config(priv, &priv->hw->xpcs_args, state); + stmmac_xpcs_config(priv, priv->hw->xpcs_args, state); } static void stmmac_mac_an_restart(struct phylink_config *config) @@ -1061,7 +1061,7 @@ static void stmmac_mac_link_up(struct phylink_config *config, struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); u32 ctrl; - stmmac_xpcs_link_up(priv, &priv->hw->xpcs_args, speed, interface); + stmmac_xpcs_link_up(priv, priv->hw->xpcs_args, speed, interface); ctrl = readl(priv->ioaddr + MAC_CTRL_REG); ctrl &= ~priv->hw->link.speed_mask; @@ -3652,7 +3652,7 @@ int stmmac_open(struct net_device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI && (!priv->hw->xpcs || - xpcs_get_an_mode(&priv->hw->xpcs_args, mode) != DW_AN_C73)) { + xpcs_get_an_mode(priv->hw->xpcs_args, mode) != DW_AN_C73)) { ret = stmmac_init_phy(dev); if (ret) { netdev_err(priv->dev, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index 56deb92a8430..9b4bf78d2eaa 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -510,25 +510,27 @@ int stmmac_mdio_register(struct net_device *ndev) } /* Try to probe the XPCS by scanning all addresses. */ - if (priv->hw->xpcs) { - struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args; - int ret, mode = priv->plat->phy_interface; - max_addr = PHY_MAX_ADDR; - - xpcs->bus = new_bus; - - found = 0; - for (addr = 0; addr < max_addr; addr++) { - xpcs->addr = addr; - - ret = xpcs_probe(xpcs, mode); - if (!ret) { - found = 1; - break; + if (mdio_bus_data->has_xpcs) { + int mode = priv->plat->phy_interface; + struct mdio_device *mdiodev; + struct mdio_xpcs_args *xpcs; + + for (addr = 0; addr < PHY_MAX_ADDR; addr++) { + mdiodev = mdio_device_create(new_bus, addr); + if (IS_ERR(mdiodev)) + continue; + + xpcs = xpcs_create(mdiodev, mode); + if (IS_ERR_OR_NULL(xpcs)) { + mdio_device_free(mdiodev); + continue; } + + priv->hw->xpcs_args = xpcs; + break; } - if (!found && !mdio_node) { + if (!priv->hw->xpcs_args) { dev_warn(dev, "No XPCS found\n"); err = -ENODEV; goto no_xpcs_found; @@ -560,6 +562,11 @@ int stmmac_mdio_unregister(struct net_device *ndev) if (!priv->mii) return 0; + if (priv->hw->xpcs) { + mdio_device_free(priv->hw->xpcs_args->mdiodev); + xpcs_destroy(priv->hw->xpcs_args); + } + mdiobus_unregister(priv->mii); priv->mii->priv = NULL; mdiobus_free(priv->mii); diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index afabb9209c52..e17e72175ebb 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -241,15 +241,19 @@ static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat, static int xpcs_read(struct mdio_xpcs_args *xpcs, int dev, u32 reg) { u32 reg_addr = mdiobus_c45_addr(dev, reg); + struct mii_bus *bus = xpcs->mdiodev->bus; + int addr = xpcs->mdiodev->addr; - return mdiobus_read(xpcs->bus, xpcs->addr, reg_addr); + return mdiobus_read(bus, addr, reg_addr); } static int xpcs_write(struct mdio_xpcs_args *xpcs, int dev, u32 reg, u16 val) { u32 reg_addr = mdiobus_c45_addr(dev, reg); + struct mii_bus *bus = xpcs->mdiodev->bus; + int addr = xpcs->mdiodev->addr; - return mdiobus_write(xpcs->bus, xpcs->addr, reg_addr, val); + return mdiobus_write(bus, addr, reg_addr, val); } static int xpcs_read_vendor(struct mdio_xpcs_args *xpcs, int dev, u32 reg) @@ -315,7 +319,7 @@ static int xpcs_soft_reset(struct mdio_xpcs_args *xpcs, #define xpcs_warn(__xpcs, __state, __args...) \ ({ \ if ((__state)->link) \ - dev_warn(&(__xpcs)->bus->dev, ##__args); \ + dev_warn(&(__xpcs)->mdiodev->dev, ##__args); \ }) static int xpcs_read_fault_c73(struct mdio_xpcs_args *xpcs, @@ -1005,10 +1009,20 @@ static const struct xpcs_id xpcs_id_list[] = { }, }; -int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) +struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, + phy_interface_t interface) { - u32 xpcs_id = xpcs_get_id(xpcs); - int i; + struct mdio_xpcs_args *xpcs; + u32 xpcs_id; + int i, ret; + + xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL); + if (!xpcs) + return NULL; + + xpcs->mdiodev = mdiodev; + + xpcs_id = xpcs_get_id(xpcs); for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { const struct xpcs_id *entry = &xpcs_id_list[i]; @@ -1020,15 +1034,32 @@ int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface) xpcs->id = entry; compat = xpcs_find_compat(entry, interface); - if (!compat) - return -ENODEV; + if (!compat) { + ret = -ENODEV; + goto out; + } - return xpcs_soft_reset(xpcs, compat); + ret = xpcs_soft_reset(xpcs, compat); + if (ret) + goto out; + + return xpcs; } - return -ENODEV; + ret = -ENODEV; + +out: + kfree(xpcs); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(xpcs_create); + +void xpcs_destroy(struct mdio_xpcs_args *xpcs) +{ + kfree(xpcs); } -EXPORT_SYMBOL_GPL(xpcs_probe); +EXPORT_SYMBOL_GPL(xpcs_destroy); static struct mdio_xpcs_ops xpcs_ops = { .config = xpcs_config, diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 1d8581b74d81..57a199393d63 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -17,9 +17,8 @@ struct xpcs_id; struct mdio_xpcs_args { - struct mii_bus *bus; + struct mdio_device *mdiodev; const struct xpcs_id *id; - int addr; }; struct mdio_xpcs_ops { @@ -37,6 +36,8 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state); int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, int enable); -int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface); +struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, + phy_interface_t interface); +void xpcs_destroy(struct mdio_xpcs_args *xpcs); #endif /* __LINUX_PCS_XPCS_H */ From patchwork Wed Jun 2 16:20:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12295263 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51175C47092 for ; Wed, 2 Jun 2021 16:21:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3765861953 for ; Wed, 2 Jun 2021 16:21:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbhFBQXl (ORCPT ); Wed, 2 Jun 2021 12:23:41 -0400 Received: from mail-ed1-f46.google.com ([209.85.208.46]:40952 "EHLO mail-ed1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230078AbhFBQXg (ORCPT ); Wed, 2 Jun 2021 12:23:36 -0400 Received: by mail-ed1-f46.google.com with SMTP id t3so3617408edc.7 for ; Wed, 02 Jun 2021 09:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PUPXXtQVaSadA9URtuI7p7qcIAmLchJuS57c7C45SSQ=; b=MKuV6PcM/sPkcWsVsRTpG0zkGxn6J2VYYfDmQJ4pfNcYbyOkeSpXvv7ytrMQmkshiA CwFqIlKaABhfzCBpJ4wrrgLB2cM14vTKWSM3h66y0YHfGl/umPygmrOClaVzBqjIbWGv w8QmazKCp5xOUEj73aS/45/XqqD8ohYcL1N35LBPuj0O/OyRlyhxryVPeZJvd3iQjJDB 7qsmZJCSM5hBo+/MgbDnU6CnkI4D0t+e5lk1dWx2RoeIPRMoVQc9P3jfhH+xzXdjlNCC xduDbbS6g2cox9YnmQmgtihvmJIEpdrE/fT713qfRDt7RgteZiE1wdjtffuODjbUHM+H qgtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PUPXXtQVaSadA9URtuI7p7qcIAmLchJuS57c7C45SSQ=; b=EGHtL2CR4sxS8fLBJvqHDbA8t54u0NGEq81DpsfYTZDUZvRnMD1cHboQYyWCeaa5un 4i5oszLRlzfSLxDUHjRNc+A72loCzvZkeyIEzmQCVlJOBoLDY5rYbPFyS5LcKOH+VPmG +TYPBECBllK6ed9H3CI0t1SC/K96TkKlNdmCFuqg/5jMjCZ84WJpk+zpaXOon9kjN9gm kVEETc04V7+y0S0+bHOlAGxVe9XeaQzwxHXR5YU+Da4+JfVobUJCiWM+YohXrMhlb13F S3ZklpggNFCshvLF5rtowef/60Pngqe5FjZY60zq/Uz6Tw0iO7q7OCTk321UD10C7Dvt T2oA== X-Gm-Message-State: AOAM531erfg3/ul8wQqBa6yycZ2BNC9j+ukiGv3yFWKXCIC6JHBDgaqb OgR7R1vfvDbHCgKkB5wSmv8= X-Google-Smtp-Source: ABdhPJyLzNKg1VoJjgBE0+DxUE9wCJ820RvTLzZvX2CaJJsC/8D2fFubOq+824YBeE9phrdz00H1Dw== X-Received: by 2002:a05:6402:44:: with SMTP id f4mr39780148edu.364.1622650842833; Wed, 02 Jun 2021 09:20:42 -0700 (PDT) Received: from localhost.localdomain ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id m12sm228078edc.40.2021.06.02.09.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 09:20:42 -0700 (PDT) From: Vladimir Oltean To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org Cc: Wong Vee Khee , Ong Boon Leong , Michael Sit Wei Hong , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Coquelin , Heiner Kallweit , Russell King - ARM Linux admin , Florian Fainelli , Andrew Lunn , Vladimir Oltean Subject: [PATCH v3 net-next 9/9] net: pcs: xpcs: convert to phylink_pcs_ops Date: Wed, 2 Jun 2021 19:20:19 +0300 Message-Id: <20210602162019.2201925-10-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210602162019.2201925-1-olteanv@gmail.com> References: <20210602162019.2201925-1-olteanv@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Vladimir Oltean Since all the remaining members of struct mdio_xpcs_ops have direct equivalents in struct phylink_pcs_ops, it is about time we remove it altogether. Since the phylink ops return void, we need to remove the error propagation from the various xpcs methods and simply print an error message where appropriate. Since xpcs_get_state_c73() detects link faults and attempts to reset the link on its own by calling xpcs_config(), but xpcs_config() now has a lot of phylink arguments which are not needed and cannot be simply fabricated by anybody else except phylink, the actual implementation has been moved into a smaller xpcs_do_config(). The const struct mdio_xpcs_ops *priv->hw->xpcs has been removed, so we need to look at the struct mdio_xpcs_args pointer now as an indication whether the port has an XPCS or not. Signed-off-by: Vladimir Oltean --- v1->v2: resolve conflicts after patch reordering v2->v3: leave stmmac_mac_config() in place since it is a required function. drivers/net/ethernet/stmicro/stmmac/common.h | 3 +- drivers/net/ethernet/stmicro/stmmac/hwif.h | 8 -- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 2 +- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 36 +++---- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 16 +-- drivers/net/pcs/pcs-xpcs.c | 99 +++++++++++-------- include/linux/pcs/pcs-xpcs.h | 11 +-- 7 files changed, 78 insertions(+), 97 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/common.h b/drivers/net/ethernet/stmicro/stmmac/common.h index 4bcd1d340766..8a83f9e1e95b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -503,8 +503,7 @@ struct mac_device_info { const struct stmmac_hwtimestamp *ptp; const struct stmmac_tc_ops *tc; const struct stmmac_mmc_ops *mmc; - const struct mdio_xpcs_ops *xpcs; - struct mdio_xpcs_args *xpcs_args; + struct mdio_xpcs_args *xpcs; struct mii_regs mii; /* MII register Addresses */ struct mac_link link; void __iomem *pcsr; /* vpointer to device CSRs */ diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h index 5014b260844b..91f7592a0189 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h @@ -612,14 +612,6 @@ struct stmmac_mmc_ops { #define stmmac_mmc_read(__priv, __args...) \ stmmac_do_void_callback(__priv, mmc, read, __args) -/* XPCS callbacks */ -#define stmmac_xpcs_config(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, config, __args) -#define stmmac_xpcs_get_state(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, get_state, __args) -#define stmmac_xpcs_link_up(__priv, __args...) \ - stmmac_do_callback(__priv, xpcs, link_up, __args) - struct stmmac_regs_off { u32 ptp_off; u32 mmc_off; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 050576ee704d..d0ce608b81c3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, "Setting EEE tx-lpi is not supported\n"); if (priv->hw->xpcs) { - ret = xpcs_config_eee(priv->hw->xpcs_args, + ret = xpcs_config_eee(priv->hw->xpcs, priv->plat->mult_fact_100ns, edata->eee_enabled); if (ret) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 426c8f891f5a..5b5edfdccab3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -997,29 +997,13 @@ static void stmmac_validate(struct phylink_config *config, /* If PCS is supported, check which modes it supports. */ if (priv->hw->xpcs) - xpcs_validate(priv->hw->xpcs_args, supported, state); -} - -static void stmmac_mac_pcs_get_state(struct phylink_config *config, - struct phylink_link_state *state) -{ - struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); - - state->link = 0; - stmmac_xpcs_get_state(priv, priv->hw->xpcs_args, state); + xpcs_validate(priv->hw->xpcs, supported, state); } static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, const struct phylink_link_state *state) { - struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); - - stmmac_xpcs_config(priv, priv->hw->xpcs_args, state); -} - -static void stmmac_mac_an_restart(struct phylink_config *config) -{ - /* Not Supported */ + /* Nothing to do, xpcs_config() handles everything */ } static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up) @@ -1061,8 +1045,6 @@ static void stmmac_mac_link_up(struct phylink_config *config, struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); u32 ctrl; - stmmac_xpcs_link_up(priv, priv->hw->xpcs_args, speed, interface); - ctrl = readl(priv->ioaddr + MAC_CTRL_REG); ctrl &= ~priv->hw->link.speed_mask; @@ -1155,9 +1137,7 @@ static void stmmac_mac_link_up(struct phylink_config *config, static const struct phylink_mac_ops stmmac_phylink_mac_ops = { .validate = stmmac_validate, - .mac_pcs_get_state = stmmac_mac_pcs_get_state, .mac_config = stmmac_mac_config, - .mac_an_restart = stmmac_mac_an_restart, .mac_link_down = stmmac_mac_link_down, .mac_link_up = stmmac_mac_link_up, }; @@ -1234,6 +1214,7 @@ static int stmmac_init_phy(struct net_device *dev) static int stmmac_phy_setup(struct stmmac_priv *priv) { + struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data; struct fwnode_handle *fwnode = of_fwnode_handle(priv->plat->phylink_node); int mode = priv->plat->phy_interface; struct phylink *phylink; @@ -1241,8 +1222,7 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) priv->phylink_config.dev = &priv->dev->dev; priv->phylink_config.type = PHYLINK_NETDEV; priv->phylink_config.pcs_poll = true; - priv->phylink_config.ovr_an_inband = - priv->plat->mdio_bus_data->xpcs_an_inband; + priv->phylink_config.ovr_an_inband = mdio_bus_data->xpcs_an_inband; if (!fwnode) fwnode = dev_fwnode(priv->device); @@ -1252,6 +1232,12 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) if (IS_ERR(phylink)) return PTR_ERR(phylink); + if (mdio_bus_data->has_xpcs) { + struct mdio_xpcs_args *xpcs = priv->hw->xpcs; + + phylink_set_pcs(phylink, &xpcs->pcs); + } + priv->phylink = phylink; return 0; } @@ -3652,7 +3638,7 @@ int stmmac_open(struct net_device *dev) if (priv->hw->pcs != STMMAC_PCS_TBI && priv->hw->pcs != STMMAC_PCS_RTBI && (!priv->hw->xpcs || - xpcs_get_an_mode(priv->hw->xpcs_args, mode) != DW_AN_C73)) { + xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) { ret = stmmac_init_phy(dev); if (ret) { netdev_err(priv->dev, diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index 9b4bf78d2eaa..6312a152c8ad 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -444,14 +444,6 @@ int stmmac_mdio_register(struct net_device *ndev) max_addr = PHY_MAX_ADDR; } - if (mdio_bus_data->has_xpcs) { - priv->hw->xpcs = mdio_xpcs_get_ops(); - if (!priv->hw->xpcs) { - err = -ENODEV; - goto bus_register_fail; - } - } - if (mdio_bus_data->needs_reset) new_bus->reset = &stmmac_mdio_reset; @@ -526,11 +518,11 @@ int stmmac_mdio_register(struct net_device *ndev) continue; } - priv->hw->xpcs_args = xpcs; + priv->hw->xpcs = xpcs; break; } - if (!priv->hw->xpcs_args) { + if (!priv->hw->xpcs) { dev_warn(dev, "No XPCS found\n"); err = -ENODEV; goto no_xpcs_found; @@ -563,8 +555,8 @@ int stmmac_mdio_unregister(struct net_device *ndev) return 0; if (priv->hw->xpcs) { - mdio_device_free(priv->hw->xpcs_args->mdiodev); - xpcs_destroy(priv->hw->xpcs_args); + mdio_device_free(priv->hw->xpcs->mdiodev); + xpcs_destroy(priv->hw->xpcs); } mdiobus_unregister(priv->mii); diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index e17e72175ebb..34164437c135 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -100,6 +100,9 @@ /* VR MII EEE Control 1 defines */ #define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */ +#define phylink_pcs_to_xpcs(pl_pcs) \ + container_of((pl_pcs), struct mdio_xpcs_args, pcs) + static const int xpcs_usxgmii_features[] = { ETHTOOL_LINK_MODE_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT, @@ -413,7 +416,7 @@ static int xpcs_get_max_usxgmii_speed(const unsigned long *supported) return max; } -static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) +static void xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) { int ret, speed_sel; @@ -438,33 +441,40 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) break; default: /* Nothing to do here */ - return -EINVAL; + return; } ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1); if (ret < 0) - return ret; + goto out; ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_EN); if (ret < 0) - return ret; + goto out; ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1); if (ret < 0) - return ret; + goto out; ret &= ~DW_USXGMII_SS_MASK; ret |= speed_sel | DW_USXGMII_FULL; ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, ret); if (ret < 0) - return ret; + goto out; ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1); if (ret < 0) - return ret; + goto out; + + ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST); + if (ret < 0) + goto out; + + return; - return xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST); +out: + pr_err("%s: XPCS access returned %pe\n", __func__, ERR_PTR(ret)); } static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs, @@ -794,19 +804,19 @@ static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs) return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret); } -static int xpcs_config(struct mdio_xpcs_args *xpcs, - const struct phylink_link_state *state) +static int xpcs_do_config(struct mdio_xpcs_args *xpcs, + phy_interface_t interface, unsigned int mode) { const struct xpcs_compat *compat; int ret; - compat = xpcs_find_compat(xpcs->id, state->interface); + compat = xpcs_find_compat(xpcs->id, interface); if (!compat) return -ENODEV; switch (compat->an_mode) { case DW_AN_C73: - if (state->an_enabled) { + if (phylink_autoneg_inband(mode)) { ret = xpcs_config_aneg_c73(xpcs, compat); if (ret) return ret; @@ -824,6 +834,16 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs, return 0; } +static int xpcs_config(struct phylink_pcs *pcs, unsigned int mode, + phy_interface_t interface, + const unsigned long *advertising, + bool permit_pause_to_mac) +{ + struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs); + + return xpcs_do_config(xpcs, interface, mode); +} + static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, struct phylink_link_state *state, const struct xpcs_compat *compat) @@ -842,7 +862,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, state->link = 0; - return xpcs_config(xpcs, state); + return xpcs_do_config(xpcs, state->interface, MLO_AN_INBAND); } if (state->an_enabled && xpcs_aneg_done_c73(xpcs, state, compat)) { @@ -899,41 +919,45 @@ static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs, return 0; } -static int xpcs_get_state(struct mdio_xpcs_args *xpcs, - struct phylink_link_state *state) +static void xpcs_get_state(struct phylink_pcs *pcs, + struct phylink_link_state *state) { + struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs); const struct xpcs_compat *compat; int ret; compat = xpcs_find_compat(xpcs->id, state->interface); if (!compat) - return -ENODEV; + return; switch (compat->an_mode) { case DW_AN_C73: ret = xpcs_get_state_c73(xpcs, state, compat); - if (ret) - return ret; + if (ret) { + pr_err("xpcs_get_state_c73 returned %pe\n", + ERR_PTR(ret)); + return; + } break; case DW_AN_C37_SGMII: ret = xpcs_get_state_c37_sgmii(xpcs, state); - if (ret) - return ret; + if (ret) { + pr_err("xpcs_get_state_c37_sgmii returned %pe\n", + ERR_PTR(ret)); + } break; default: - return -1; + return; } - - return 0; } -static int xpcs_link_up(struct mdio_xpcs_args *xpcs, int speed, - phy_interface_t interface) +static void xpcs_link_up(struct phylink_pcs *pcs, unsigned int mode, + phy_interface_t interface, int speed, int duplex) { + struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs); + if (interface == PHY_INTERFACE_MODE_USXGMII) return xpcs_config_usxgmii(xpcs, speed); - - return 0; } static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs) @@ -1009,6 +1033,12 @@ static const struct xpcs_id xpcs_id_list[] = { }, }; +static const struct phylink_pcs_ops xpcs_phylink_ops = { + .pcs_config = xpcs_config, + .pcs_get_state = xpcs_get_state, + .pcs_link_up = xpcs_link_up, +}; + struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, phy_interface_t interface) { @@ -1039,6 +1069,9 @@ struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, goto out; } + xpcs->pcs.ops = &xpcs_phylink_ops; + xpcs->pcs.poll = true; + ret = xpcs_soft_reset(xpcs, compat); if (ret) goto out; @@ -1061,16 +1094,4 @@ void xpcs_destroy(struct mdio_xpcs_args *xpcs) } EXPORT_SYMBOL_GPL(xpcs_destroy); -static struct mdio_xpcs_ops xpcs_ops = { - .config = xpcs_config, - .get_state = xpcs_get_state, - .link_up = xpcs_link_up, -}; - -struct mdio_xpcs_ops *mdio_xpcs_get_ops(void) -{ - return &xpcs_ops; -} -EXPORT_SYMBOL_GPL(mdio_xpcs_get_ops); - MODULE_LICENSE("GPL v2"); diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h index 57a199393d63..0860a5b59f10 100644 --- a/include/linux/pcs/pcs-xpcs.h +++ b/include/linux/pcs/pcs-xpcs.h @@ -19,19 +19,10 @@ struct xpcs_id; struct mdio_xpcs_args { struct mdio_device *mdiodev; const struct xpcs_id *id; -}; - -struct mdio_xpcs_ops { - int (*config)(struct mdio_xpcs_args *xpcs, - const struct phylink_link_state *state); - int (*get_state)(struct mdio_xpcs_args *xpcs, - struct phylink_link_state *state); - int (*link_up)(struct mdio_xpcs_args *xpcs, int speed, - phy_interface_t interface); + struct phylink_pcs pcs; }; int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); -struct mdio_xpcs_ops *mdio_xpcs_get_ops(void); void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, struct phylink_link_state *state); int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns,