From patchwork Tue Nov 23 16:40:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634655 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86112C43217 for ; Tue, 23 Nov 2021 16:40:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbhKWQnm (ORCPT ); Tue, 23 Nov 2021 11:43:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:47602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229719AbhKWQnm (ORCPT ); Tue, 23 Nov 2021 11:43:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B23860FC3; Tue, 23 Nov 2021 16:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685634; bh=L48kIXjuaTs/4FTXMYKR2SMr9wsO+2Q7RveVzlbgxUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ARyB35ZhiB99NdgF4lRr8UNgsMqwXcCNFOAVvnEcFEa3D33Xu1I6xhEhLjJOtAZrY 2Y6iVnh5f/ShTkouSszXZ0bJq9fCpZ1tEW1/66BcrzBjpqUiO3vDtg547WgjZXmvw/ k9MgMhT3yQiqGjccIlutPHgAlfYoUtUj0JGo4uUlXMCec1izmeIsAkylntGgJq89vX +o9Byyl727QhUdJ0f4hOJTwQCv4i5HYSH4ddBFI7UmlCbc61otyNSwhzQXInMLEqOB /1qAzaIl6CT7ZXbQP1diHTYycNs9ZjiJCbIwO+++G0oYwOjh/q6DwrfCJnGQyHsu06 D5JX31YkjdMmA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 1/8] dt-bindings: ethernet-controller: support multiple PHY connection types Date: Tue, 23 Nov 2021 17:40:20 +0100 Message-Id: <20211123164027.15618-2-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Sometimes, an ethernet PHY may communicate with ethernet controller with multiple different PHY connection types, and the software should be able to choose between them. Russell King says: conventionally phy-mode has meant "this is the mode we want to operate the PHY interface in" which was fine when PHYs didn't change their mode depending on the media speed This is no longer the case, since we have PHYs that can change PHY mode. Existing example is the Marvell 88X3310 PHY, which supports connecting the MAC with the PHY with `xaui` and `rxaui`. The MAC may also support both modes, but it is possible that a particular board doesn't have these modes wired (since they use multiple SerDes lanes). Another example is one SerDes lane capable of `1000base-x`, `2500base-x` and `sgmii` when connecting Marvell switches with Marvell ethernet controller. Currently we mention only one of these modes in device-tree, and software assumes the other modes are also supported, since they use the same SerDes lanes. But a board may be able to support `1000base-x` and not support `2500base-x`, for example due to the higher frequency not working correctly on a particular board. In order for the kernel to know which modes are supported on the board, we need to be able to specify them all in the device-tree. Change the type of property `phy-connection-type` of an ethernet controller to be an array of the enumerated strings, instead of just one string. Require at least one item defined. Signed-off-by: Marek Behún Reviewed-by: Andrew Lunn Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring --- .../bindings/net/ethernet-controller.yaml | 94 ++++++++++--------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/Documentation/devicetree/bindings/net/ethernet-controller.yaml b/Documentation/devicetree/bindings/net/ethernet-controller.yaml index b0933a8c295a..1fd27d45d136 100644 --- a/Documentation/devicetree/bindings/net/ethernet-controller.yaml +++ b/Documentation/devicetree/bindings/net/ethernet-controller.yaml @@ -54,51 +54,55 @@ properties: phy-connection-type: description: - Specifies interface type between the Ethernet device and a physical - layer (PHY) device. - enum: - # There is not a standard bus between the MAC and the PHY, - # something proprietary is being used to embed the PHY in the - # MAC. - - internal - - mii - - gmii - - sgmii - - qsgmii - - tbi - - rev-mii - - rmii - - rev-rmii - - # RX and TX delays are added by the MAC when required - - rgmii - - # RGMII with internal RX and TX delays provided by the PHY, - # the MAC should not add the RX or TX delays in this case - - rgmii-id - - # RGMII with internal RX delay provided by the PHY, the MAC - # should not add an RX delay in this case - - rgmii-rxid - - # RGMII with internal TX delay provided by the PHY, the MAC - # should not add an TX delay in this case - - rgmii-txid - - rtbi - - smii - - xgmii - - trgmii - - 1000base-x - - 2500base-x - - 5gbase-r - - rxaui - - xaui - - # 10GBASE-KR, XFI, SFI - - 10gbase-kr - - usxgmii - - 10gbase-r - - 25gbase-r + Specifies interface types between the Ethernet device and a physical + layer (PHY) device. Since more interface types can be wired between + the MAC and the PHY, this property should list all that are supported + by the board. + minItems: 1 + items: + enum: + # There is not a standard bus between the MAC and the PHY, + # something proprietary is being used to embed the PHY in the + # MAC. + - internal + - mii + - gmii + - sgmii + - qsgmii + - tbi + - rev-mii + - rmii + - rev-rmii + + # RX and TX delays are added by the MAC when required + - rgmii + + # RGMII with internal RX and TX delays provided by the PHY, + # the MAC should not add the RX or TX delays in this case + - rgmii-id + + # RGMII with internal RX delay provided by the PHY, the MAC + # should not add an RX delay in this case + - rgmii-rxid + + # RGMII with internal TX delay provided by the PHY, the MAC + # should not add an TX delay in this case + - rgmii-txid + - rtbi + - smii + - xgmii + - trgmii + - 1000base-x + - 2500base-x + - 5gbase-r + - rxaui + - xaui + + # 10GBASE-KR, XFI, SFI + - 10gbase-kr + - usxgmii + - 10gbase-r + - 25gbase-r phy-mode: $ref: "#/properties/phy-connection-type" From patchwork Tue Nov 23 16:40:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634657 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E12C5C433FE for ; Tue, 23 Nov 2021 16:40:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232807AbhKWQnr (ORCPT ); Tue, 23 Nov 2021 11:43:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:47632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232252AbhKWQno (ORCPT ); Tue, 23 Nov 2021 11:43:44 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9B11360F9D; Tue, 23 Nov 2021 16:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685636; bh=yhEHz9JVknjMUJ/knQ9hcoYufuSNDgBuNPUmMLAzHlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iC2PzEq0YJ2pnQclk0dVVpo0ReZare75YROyKTZ+lVbkfu5oI24aDKTLvNQ9aZMSF 8mfcPGb8MpOXlt7RVQP6yNhZcGOQtSDdY0ZdE12eR7J40dDe0mpm0CAnOc3Mz19mVc HgPIQz6kDNVMV4EKnyOAiYKpWfIKFyT5SH5BhpWtc3DsjOk5KuN1OuVOjTeDQhalGV UbKNkZ5Z5k6bAjqjbJv3L8NPKzCQACQU4+5n+tb9EcVg+BhuNtOOdVJTeCzNupGZKs uVCXvYRUeLQjeGoT94IATBuQynaztvkRN8z3lWB5jfi72Xu79a7b1H2ykl/ib4WKLw PpbMtvvAZ8koA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 2/8] net: Update documentation for *_get_phy_mode() functions Date: Tue, 23 Nov 2021 17:40:21 +0100 Message-Id: <20211123164027.15618-3-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Now that the `phy-mode` DT property can be an array of strings instead of just one string, update the documentation for of_get_phy_mode(), fwnode_get_phy_mode() and device_get_phy_mode() saying that if multiple strings are present, the first one is returned. Conventionally the property was used to represent the mode we want the PHY to operate in, but we extended this to mean the list of all supported modes by that PHY on that particular board. Signed-off-by: Marek Behún Reviewed-by: Andrew Lunn --- drivers/base/property.c | 14 ++++++++------ net/core/of_net.c | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index f1f35b48ab8b..e12aef10f7fd 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -893,12 +893,13 @@ enum dev_dma_attr device_get_dma_attr(struct device *dev) EXPORT_SYMBOL_GPL(device_get_dma_attr); /** - * fwnode_get_phy_mode - Get phy mode for given firmware node + * fwnode_get_phy_mode - Get first phy mode for given firmware node * @fwnode: Pointer to the given node * * The function gets phy interface string from property 'phy-mode' or - * 'phy-connection-type', and return its index in phy_modes table, or errno in - * error case. + * 'phy-connection-type', and returns its index in phy_modes table, or errno in + * error case. If there are multiple strings in the property, the first one is + * used. */ int fwnode_get_phy_mode(struct fwnode_handle *fwnode) { @@ -921,12 +922,13 @@ int fwnode_get_phy_mode(struct fwnode_handle *fwnode) EXPORT_SYMBOL_GPL(fwnode_get_phy_mode); /** - * device_get_phy_mode - Get phy mode for given device + * device_get_phy_mode - Get first phy mode for given device * @dev: Pointer to the given device * * The function gets phy interface string from property 'phy-mode' or - * 'phy-connection-type', and return its index in phy_modes table, or errno in - * error case. + * 'phy-connection-type', and returns its index in phy_modes table, or errno in + * error case. If there are multiple strings in the property, the first one is + * used. */ int device_get_phy_mode(struct device *dev) { diff --git a/net/core/of_net.c b/net/core/of_net.c index f1a9bf7578e7..7cd10f0ef679 100644 --- a/net/core/of_net.c +++ b/net/core/of_net.c @@ -14,14 +14,15 @@ #include /** - * of_get_phy_mode - Get phy mode for given device_node + * of_get_phy_mode - Get first phy mode for given device_node * @np: Pointer to the given device_node * @interface: Pointer to the result * * The function gets phy interface string from property 'phy-mode' or - * 'phy-connection-type'. The index in phy_modes table is set in - * interface and 0 returned. In case of error interface is set to - * PHY_INTERFACE_MODE_NA and an errno is returned, e.g. -ENODEV. + * 'phy-connection-type'. If there are more string in the property, the first + * one is used. The index in phy_modes table is set in interface and 0 returned. + * In case of error interface is set to PHY_INTERFACE_MODE_NA and an errno is + * returned, e.g. -ENODEV. */ int of_get_phy_mode(struct device_node *np, phy_interface_t *interface) { From patchwork Tue Nov 23 16:40:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634659 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 868F0C4332F for ; Tue, 23 Nov 2021 16:40:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbhKWQnr (ORCPT ); Tue, 23 Nov 2021 11:43:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:47652 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbhKWQnq (ORCPT ); Tue, 23 Nov 2021 11:43:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BC06060F90; Tue, 23 Nov 2021 16:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685638; bh=LI6uHS/wP+avmLAUWSW6X7r65Xj3azfYhtW66M34qvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=teftqRymS3caKyn8wpTtAPB4pfIbSdGIZLfsAbRx7iXbtBtBaDG4BOXo7zBj/bbXQ hUpO9+C6U3DT7NLBksFt0PTHanlexQ56lmiJWVU5IwgLRefS+Xlov5lAXfTxr4D1LQ axXrAQdSqA27dyhUSZdgEyUYcsP31hdP3sn+sAAyjPZ/l39JwO+mfC3tOV6abtJUXN vV4NVqcw+DFNXjk2hMi+y4niN91tk8LstwFKm9eihOgk25UY2DksOS+AmZPiEwg0WC JyK3tavZnxsrYVA7jKkk/YfhbsdHdHY9oFEZHBs68B1tsTmsVQiTVy7U42j85Yjq0s pbDN1vT0U9N2Q== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 3/8] device property: add helper function for getting phy mode bitmap Date: Tue, 23 Nov 2021 17:40:22 +0100 Message-Id: <20211123164027.15618-4-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Now that the 'phy-mode' property can be a string array containing more PHY modes, add helper function fwnode_get_phy_modes() that reads this property and fills in PHY interfaces bitmap. Signed-off-by: Marek Behún Reviewed-by: Andrew Lunn --- drivers/base/property.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/property.h | 3 +++ 2 files changed, 37 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index e12aef10f7fd..9f9dbc2ae386 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -921,6 +921,40 @@ int fwnode_get_phy_mode(struct fwnode_handle *fwnode) } EXPORT_SYMBOL_GPL(fwnode_get_phy_mode); +/** + * fwnode_get_phy_modes - Fill in phy modes bitmap for given firmware node + * @fwnode: Pointer to the given node + * @interfaces: Phy modes bitmask, as declared by DECLARE_PHY_INTERFACE_MASK() + * + * Reads the strings from property 'phy-mode' or 'phy-connection-type' and fills + * interfaces bitmask. Returns 0 on success, or errno on error. + */ +int fwnode_get_phy_modes(struct fwnode_handle *fwnode, + unsigned long *interfaces) +{ + const char *modes[PHY_INTERFACE_MODE_MAX]; + int len, i, j; + + len = fwnode_property_read_string_array(fwnode, "phy-mode", modes, + ARRAY_SIZE(modes)); + if (len < 0) + len = fwnode_property_read_string_array(fwnode, + "phy-connection-type", + modes, + ARRAY_SIZE(modes)); + if (len < 0) + return len; + + phy_interface_zero(interfaces); + for (i = 0; i < len; ++i) + for (j = 0; j < PHY_INTERFACE_MODE_MAX; j++) + if (!strcasecmp(modes[i], phy_modes(j))) + __set_bit(j, interfaces); + + return 0; +} +EXPORT_SYMBOL_GPL(fwnode_get_phy_modes); + /** * device_get_phy_mode - Get first phy mode for given device * @dev: Pointer to the given device diff --git a/include/linux/property.h b/include/linux/property.h index 88fa726a76df..99a74d524b2b 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -391,6 +391,9 @@ const void *device_get_match_data(struct device *dev); int device_get_phy_mode(struct device *dev); int fwnode_get_phy_mode(struct fwnode_handle *fwnode); +int fwnode_get_phy_modes(struct fwnode_handle *fwnode, + unsigned long *interfaces); + struct fwnode_handle *fwnode_graph_get_next_endpoint( const struct fwnode_handle *fwnode, struct fwnode_handle *prev); struct fwnode_handle * From patchwork Tue Nov 23 16:40:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634661 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F138DC433EF for ; Tue, 23 Nov 2021 16:40:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233389AbhKWQnu (ORCPT ); Tue, 23 Nov 2021 11:43:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:47698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233113AbhKWQns (ORCPT ); Tue, 23 Nov 2021 11:43:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC87860FE8; Tue, 23 Nov 2021 16:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685640; bh=qjerIt6Uvl7jcepztOSIvq+5+1RCG0nkPZxqbSX3UGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwPS5/d6lbogtOn6swqGp/P/4+bsjFAW690Gix5Ob/fhfYwJ5LRhuA4OzRpDKLHHR LT9YzJmNiijOo1+IJ12WaXrEJG8ohcoE4BKcaDRVuBNXYTd18fFBfP1VvaJmSudDn2 1R4i1hkvagMDMIvBz4wUlzKt7PNcHo6ymjcPVmuPZo/AzWsvwv7cIlsqSoKz8mSwoo M1bEq6ja5uTyQU6kBUTQThdIgDDo2W0YNyOvahss+tEta/ryde/Wry8hfJ0jvbyoCO POIUNsCGLLSo+wRSwZDJTfzsuFIpzW6+cU8VLq/vbMUumEBLwSMHhsBeet3IsNo0A9 UmdDbnuOnqgSA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 4/8] net: phylink: update supported_interfaces with modes from fwnode Date: Tue, 23 Nov 2021 17:40:23 +0100 Message-Id: <20211123164027.15618-5-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Now that the 'phy-mode' property can be a string array containing more PHY modes (all that are supported by the board), update the bitmap of interfaces supported by the MAC with this property. Normally this would be a simple intersection (of interfaces supported by the current implementation of the driver and interfaces supported by the board), but we need to keep being backwards compatible with older DTs, which may only define one mode, since, as Russell King says, conventionally phy-mode has meant "this is the mode we want to operate the PHY interface in" which was fine when PHYs didn't change their mode depending on the media speed An example is DT defining phy-mode = "sgmii"; but the board supporting also 1000base-x and 2500base-x. Add the following logic to keep this backwards compatiblity: - if more PHY modes are defined, do a simple intersection - if one PHY mode is defined: - if it is sgmii, 1000base-x or 2500base-x, add all three and then do the intersection - if it is 10gbase-r or usxgmii, add both, and also 5gbase-r, 2500base-x, 1000base-x and sgmii, and then do the intersection This is simple enough and should work for all boards. Nonetheless it is possible (although extremely unlikely, in my opinion) that a board will be found that (for example) defines phy-mode = "sgmii"; and the MAC drivers supports sgmii, 1000base-x and 2500base-x, but the board DOESN'T support 2500base-x, because of electrical reasons (since the frequency is 2.5x of sgmii). Our code will in this case incorrectly infer also support for 2500base-x. To avoid this, the board maintainer should either change DTS to phy-mode = "sgmii", "1000base-x"; and update device tree on all boards, or, if that is impossible, add a fix into the function we are introducing in this commit. Another example would be a board with device-tree defining phy-mode = "10gbase-r"; We infer from this all other modes (sgmii, 1000base-x, 2500base-x, 5gbase-r, usxgmii), and these then get filtered by those supported by the driver. But it is possible that a driver supports all of these modes, and yet not all are supported because the board has an older version of the TF-A firmware, which implements changing of PHY modes via SMC calls. For this case, the board maintainer should either provide all supported modes in the phy-mode property, or add a fix into this function that somehow checks for this situation. But this is a really unprobable scenario, in my opinion. Signed-off-by: Marek Behún --- Changes since v1: - added 10gbase-r example scenario to commit message - changed phylink_update_phy_modes() so that if supported_interfaces is empty (an unconverted driver that doesn't fill up this member), we leave it empty - rewritten phylink_update_phy_modes() according to Sean Anderson's comment: use phy_interface_and/or() instead of several if (test_bit) set_bit --- drivers/net/phy/phylink.c | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 3603c024109a..d2300a3a60ec 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -564,6 +564,74 @@ static int phylink_parse_fixedlink(struct phylink *pl, return 0; } +static void phylink_update_phy_modes(struct phylink *pl, + struct fwnode_handle *fwnode) +{ + unsigned long *supported = pl->config->supported_interfaces; + DECLARE_PHY_INTERFACE_MASK(modes); + + /* FIXME: If supported is empty, leave it as it is. This happens for + * unconverted drivers that don't fill up supported_interfaces. Once all + * such drivers are converted, we can drop this. + */ + if (phy_interface_empty(supported)) + return; + + if (fwnode_get_phy_modes(fwnode, modes) < 0) + return; + + /* If no modes are defined in fwnode, interpret it as all modes + * supported by the MAC are supported by the board. + */ + if (phy_interface_empty(modes)) + return; + + /* We want the intersection of given supported modes with those defined + * in DT. + * + * Some older device-trees mention only one of `sgmii`, `1000base-x` or + * `2500base-x`, while supporting all three. Other mention `10gbase-r` + * or `usxgmii`, while supporting both, and also `sgmii`, `1000base-x`, + * `2500base-x` and `5gbase-r`. + * For backwards compatibility with these older DTs, make it so that if + * one of these modes is mentioned in DT and MAC supports more of them, + * keep all that are supported according to the logic above. + * + * Nonetheless it is possible that a device may support only one mode, + * for example 1000base-x, due to strapping pins or some other reasons. + * If a specific device supports only the mode mentioned in DT, the + * exception should be made here with of_machine_is_compatible(). + */ + if (bitmap_weight(modes, PHY_INTERFACE_MODE_MAX) == 1) { + DECLARE_PHY_INTERFACE_MASK(mask); + bool lower = false; + + if (test_bit(PHY_INTERFACE_MODE_10GBASER, modes) || + test_bit(PHY_INTERFACE_MODE_USXGMII, modes)) { + phy_interface_zero(mask); + __set_bit(PHY_INTERFACE_MODE_5GBASER, mask); + __set_bit(PHY_INTERFACE_MODE_10GBASER, mask); + __set_bit(PHY_INTERFACE_MODE_USXGMII, mask); + phy_interface_and(mask, supported, mask); + phy_interface_or(modes, modes, mask); + lower = true; + } + + if (lower || (test_bit(PHY_INTERFACE_MODE_SGMII, modes) || + test_bit(PHY_INTERFACE_MODE_1000BASEX, modes) || + test_bit(PHY_INTERFACE_MODE_2500BASEX, modes))) { + phy_interface_zero(mask); + __set_bit(PHY_INTERFACE_MODE_SGMII, mask); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, mask); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, mask); + phy_interface_and(mask, supported, mask); + phy_interface_or(modes, modes, mask); + } + } + + phy_interface_and(supported, supported, modes); +} + static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) { struct fwnode_handle *dn; @@ -1157,6 +1225,8 @@ struct phylink *phylink_create(struct phylink_config *config, __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); timer_setup(&pl->link_poll, phylink_fixed_poll, 0); + phylink_update_phy_modes(pl, fwnode); + bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS); linkmode_copy(pl->link_config.advertising, pl->supported); phylink_validate(pl, pl->supported, &pl->link_config); From patchwork Tue Nov 23 16:40:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634663 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2F14C433F5 for ; Tue, 23 Nov 2021 16:40:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232918AbhKWQn5 (ORCPT ); Tue, 23 Nov 2021 11:43:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:47716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233400AbhKWQnv (ORCPT ); Tue, 23 Nov 2021 11:43:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0859060FC1; Tue, 23 Nov 2021 16:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685642; bh=893w7YK58a16FrgQv1BBeT0NVXWeeILmCnh28eXL+pQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qr2PoHJSTxk4Z2B3WetdsTu2xCC1vrnu0gOsSIMOm8L++63YyUrLwBxhf0t1Icl6q 1DUhO2zfjlwocsP69vIJQIxOkjACB1XVi7afJh3Ay2awCWR/5LXl9bqRSZVjnj5k4G 3vtiyascAOmFu2IERX1PFdLSLwtosFzxeYJpFsUp6UOUUnGfxT1dhjD4fvx/uCCvGO /DUi0jJqhkDRbkUWkQ6ZcSX7tOACt/lp2ZEm2q/dbmK5JH/9LdUgXfGxD/D6Ak6Qx+ R7sq2KYlBRBRRDMoiIzZOWittZMoJXR7xFULbSDqwK5npWJ/oryN5ofoVOVAi2i8fr d6qIbOKHcs34g== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 5/8] net: phylink: pass supported PHY interface modes to phylib Date: Tue, 23 Nov 2021 17:40:24 +0100 Message-Id: <20211123164027.15618-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Pass the supported PHY interface types to phylib so that PHY drivers can select an appropriate host configuration mode for their interface according to the host capabilities. Signed-off-by: Marek Behún Reviewed-by: Russell King (Oracle) --- drivers/net/phy/phylink.c | 28 ++++++++++++++++++++++++++++ include/linux/phy.h | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index d2300a3a60ec..0dcf94170d06 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1439,6 +1439,10 @@ int phylink_connect_phy(struct phylink *pl, struct phy_device *phy) { int ret; + /* Set the PHY's host supported interfaces */ + phy_interface_copy(phy->host_interfaces, + pl->config->supported_interfaces); + /* Use PHY device/driver interface */ if (pl->link_interface == PHY_INTERFACE_MODE_NA) { pl->link_interface = phy->interface; @@ -1514,6 +1518,10 @@ int phylink_fwnode_phy_connect(struct phylink *pl, if (!phy_dev) return -ENODEV; + /* Set the PHY's host supported interfaces */ + phy_interface_copy(phy_dev->host_interfaces, + pl->config->supported_interfaces); + /* Use PHY device/driver interface */ if (pl->link_interface == PHY_INTERFACE_MODE_NA) { pl->link_interface = phy_dev->interface; @@ -2704,6 +2712,8 @@ static bool phylink_phy_no_inband(struct phy_device *phy) (phy->c45_ids.device_ids[1] & 0xfffffff0) == 0xae025150; } +static DECLARE_PHY_INTERFACE_MASK(phylink_sfp_interfaces); + static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) { struct phylink *pl = upstream; @@ -2725,6 +2735,10 @@ static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) else mode = MLO_AN_INBAND; + /* Set the PHY's host supported interfaces */ + phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces, + pl->config->supported_interfaces); + /* Do the initial configuration */ ret = phylink_sfp_config(pl, mode, phy->supported, phy->advertising); if (ret < 0) @@ -3102,4 +3116,18 @@ void phylink_mii_c45_pcs_get_state(struct mdio_device *pcs, } EXPORT_SYMBOL_GPL(phylink_mii_c45_pcs_get_state); +static int __init phylink_init(void) +{ + __set_bit(PHY_INTERFACE_MODE_USXGMII, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_10GBASER, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_5GBASER, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_2500BASEX, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_SGMII, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_1000BASEX, phylink_sfp_interfaces); + __set_bit(PHY_INTERFACE_MODE_100BASEX, phylink_sfp_interfaces); + + return 0; +} +module_init(phylink_init); + MODULE_LICENSE("GPL v2"); diff --git a/include/linux/phy.h b/include/linux/phy.h index 1e57cdd95da3..11f3b5b7d7b1 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -169,6 +169,12 @@ static inline bool phy_interface_empty(const unsigned long *intf) return bitmap_empty(intf, PHY_INTERFACE_MODE_MAX); } +static inline void phy_interface_copy(unsigned long *dst, + const unsigned long *src) +{ + bitmap_copy(dst, src, PHY_INTERFACE_MODE_MAX); +} + static inline void phy_interface_and(unsigned long *dst, const unsigned long *a, const unsigned long *b) { @@ -563,6 +569,7 @@ struct macsec_ops; * @advertising: Currently advertised linkmodes * @adv_old: Saved advertised while power saving for WoL * @lp_advertising: Current link partner advertised linkmodes + * @host_interfaces: PHY interface modes supported by host * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited * @autoneg: Flag autoneg being used * @link: Current link state @@ -652,6 +659,9 @@ struct phy_device { /* used with phy_speed_down */ __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old); + /* host supported PHY interface types */ + DECLARE_PHY_INTERFACE_MASK(host_interfaces); + /* Energy efficient ethernet modes which should be prohibited */ u32 eee_broken_modes; From patchwork Tue Nov 23 16:40:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634665 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D74BC433FE for ; Tue, 23 Nov 2021 16:40:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234748AbhKWQoE (ORCPT ); Tue, 23 Nov 2021 11:44:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:47752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233715AbhKWQnx (ORCPT ); Tue, 23 Nov 2021 11:43:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 289DC60F90; Tue, 23 Nov 2021 16:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685644; bh=1g0Fb2Uk/jOxx7QzT7TJ5TjvwLuxkudnvVugm9DJ5aU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKbC+NeayyQznFDs30JjAr248TMNCtrwI9prQDFJzEgerx9KH8ooEjAOw9LixrJBM NVTp38vxWp3sRpeeZ0IQcfEzCURULRQbkTqNQE53v72LFwyNcj4gCAP1x2HhmniEXB 5h+S97G3gV4vn2KS5fDpWmsmH0qKYlOyL5XUmEhbTcaMoyrZSpQUc/etHe9DhIkRR+ bJvrzzQ/C4jVvf1YVtgMXoCbYuIURAOkiqbfgG3fmBH27rJhrV+fJGBukGNlFdLOC7 dsIJ9YDe8S+r17avzCYlyWLy/aYg2gatdaM5tAYxTF0DAnmiSbmX1W6shkgT/10OqK WDiZwfvoIGoXQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 6/8] net: phy: marvell10g: Use generic macro for supported interfaces Date: Tue, 23 Nov 2021 17:40:25 +0100 Message-Id: <20211123164027.15618-7-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Now that phy.h defines macro DECLARE_PHY_INTERFACE_MASK(), use it instead of DECLARE_BITMAP(). Signed-off-by: Marek Behún Reviewed-by: Russell King (Oracle) Reviewed-by: Andrew Lunn --- drivers/net/phy/marvell10g.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index b6fea119fe13..d289641190db 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -148,7 +148,7 @@ struct mv3310_chip { }; struct mv3310_priv { - DECLARE_BITMAP(supported_interfaces, PHY_INTERFACE_MODE_MAX); + DECLARE_PHY_INTERFACE_MASK(supported_interfaces); u32 firmware_ver; bool has_downshift; From patchwork Tue Nov 23 16:40:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634667 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBDC2C433EF for ; Tue, 23 Nov 2021 16:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231267AbhKWQoK (ORCPT ); Tue, 23 Nov 2021 11:44:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:47782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234047AbhKWQnz (ORCPT ); Tue, 23 Nov 2021 11:43:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A84160FD7; Tue, 23 Nov 2021 16:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685647; bh=pm89O6T7XMf9GJsbHn268oS26nRGu8hdc24kbn90W60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXvHnhYpvwplB5lJVRuvsgaxhHNY4sMyyQds1zIulvjOyGcjjdtCofVLCEaLjonZO yv9YqYYLZ+peecPR0YqksABX16JYAc11QG9wuUGMJ2qI8h1flL9RCyNakjSlC813SX dHQNlK0S7/KE66GKkog6vFm6rhg7DHQxPgmrckStZjwp3MtRWI6VOjnxicUG7Mr9aS 6DQTh4Ga3u+soadoNliq6e6i4jMWvxy1jkx8P4Beu7vf9hdngr1E2KMTm+AZm5oEM/ Zxx6FCl9jaTmsbS7xe+LDbfMOqIcJ4W2dtxEdHJVbb3rtlSp1GvSqpzG9jn22PPnX5 xI20xkF76RTrw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 7/8] net: phy: marvell10g: Use tabs instead of spaces for indentation Date: Tue, 23 Nov 2021 17:40:26 +0100 Message-Id: <20211123164027.15618-8-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Some register definitions were defined with spaces used for indentation. Change them to tabs. Signed-off-by: Marek Behún Reviewed-by: Russell King (Oracle) --- drivers/net/phy/marvell10g.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index d289641190db..0cb9b4ef09c7 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -117,16 +117,16 @@ enum { MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_NO_SGMII_AN = 0x5, MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH = 0x6, MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII = 0x7, - MV_V2_PORT_INTR_STS = 0xf040, - MV_V2_PORT_INTR_MASK = 0xf043, - MV_V2_PORT_INTR_STS_WOL_EN = BIT(8), - MV_V2_MAGIC_PKT_WORD0 = 0xf06b, - MV_V2_MAGIC_PKT_WORD1 = 0xf06c, - MV_V2_MAGIC_PKT_WORD2 = 0xf06d, + MV_V2_PORT_INTR_STS = 0xf040, + MV_V2_PORT_INTR_MASK = 0xf043, + MV_V2_PORT_INTR_STS_WOL_EN = BIT(8), + MV_V2_MAGIC_PKT_WORD0 = 0xf06b, + MV_V2_MAGIC_PKT_WORD1 = 0xf06c, + MV_V2_MAGIC_PKT_WORD2 = 0xf06d, /* Wake on LAN registers */ - MV_V2_WOL_CTRL = 0xf06e, - MV_V2_WOL_CTRL_CLEAR_STS = BIT(15), - MV_V2_WOL_CTRL_MAGIC_PKT_EN = BIT(0), + MV_V2_WOL_CTRL = 0xf06e, + MV_V2_WOL_CTRL_CLEAR_STS = BIT(15), + MV_V2_WOL_CTRL_MAGIC_PKT_EN = BIT(0), /* Temperature control/read registers (88X3310 only) */ MV_V2_TEMP_CTRL = 0xf08a, MV_V2_TEMP_CTRL_MASK = 0xc000, From patchwork Tue Nov 23 16:40:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 12634669 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B855C433FE for ; Tue, 23 Nov 2021 16:41:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233207AbhKWQoL (ORCPT ); Tue, 23 Nov 2021 11:44:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:47800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234388AbhKWQn5 (ORCPT ); Tue, 23 Nov 2021 11:43:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 68C9B60FC3; Tue, 23 Nov 2021 16:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637685649; bh=yeXIxIeywEh1WCGyS0+ZYNprOIvFWZLdVHE/fFNgcyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ewOOqvWzFvQ6/ZbIavCOZzGkYDOVBoLw9ypqCsfvu4vuXlf14aukRxyQsJXZxfcGj ug/NBtPJb0r8ty8fOOFhOGHy+nMdBCaq/j7My7Yp+msqwE0hzg0u+kgQKR26gn0+E3 SBYedDvRHCpU72x03tl+PNMgfzKYUq4ql6R1sESxrFLTwICNmku4UIZe0p8rXSVweI NFSSgoyYEsLw5u6kogViTWhsR8wZKda7j0gKT3F//jHfaE0d1TuylQHqQcKBiZHF9U 2OfUSQxdlPkJj0GO9okiX5zYexbtUdhBSDcBEM4dSCePpESmN8+Adm1AZOBhSPPyH2 E5PzOmaAc9jpA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Rob Herring , devicetree@vger.kernel.org, Russell King , Jakub Kicinski , Vladimir Oltean , Sean Anderson , davem@davemloft.net, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next v2 8/8] net: phy: marvell10g: select host interface configuration Date: Tue, 23 Nov 2021 17:40:27 +0100 Message-Id: <20211123164027.15618-9-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211123164027.15618-1-kabel@kernel.org> References: <20211123164027.15618-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Russell King Select the host interface configuration according to the capabilities of the host. The PHY supports several configurations of host communication: - always communicate with host in 10gbase-r, even if copper speed is lower (rate matching mode), - the same as above but use xaui/rxaui instead of 10gbase-r, - switch host SerDes mode between 10gbase-r, 5gbase-r, 2500base-x and sgmii according to copper speed, - the same as above but use xaui/rxaui instead of 10gbase-r. This mode of host communication, called MACTYPE, is by default selected by strapping pins, but it can be changed in software. This adds support for selecting this mode according to which modes are supported by the host. This allows the kernel to: - support SFP modules with 88X33X0 or 88E21X0 inside them - switch interface modes when the PHY is used with the mvpp2 MAC (e.g. on MacchiatoBIN) Note: we use mv3310_select_mactype() for both 88X3310 and 88X3340, although 88X3340 does not support XAUI. This is not a problem because 88X3340 does not declare XAUI in it's supported_interfaces, and so this function will never choose that MACTYPE. Signed-off-by: Russell King [ rebase, updated, also added support for 88E21X0 ] Signed-off-by: Marek Behún --- Changes since v1: - added more explanation to commit message, as per Vladimir Oltean's suggestion --- drivers/net/phy/marvell10g.c | 120 +++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 0cb9b4ef09c7..94bea1bade6f 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -96,6 +96,11 @@ enum { MV_PCS_PORT_INFO_NPORTS_MASK = 0x0380, MV_PCS_PORT_INFO_NPORTS_SHIFT = 7, + /* SerDes reinitialization 88E21X0 */ + MV_AN_21X0_SERDES_CTRL2 = 0x800f, + MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS = BIT(13), + MV_AN_21X0_SERDES_CTRL2_RUN_INIT = BIT(15), + /* These registers appear at 0x800X and 0xa00X - the 0xa00X control * registers appear to set themselves to the 0x800X when AN is * restarted, but status registers appear readable from either. @@ -140,6 +145,8 @@ struct mv3310_chip { bool (*has_downshift)(struct phy_device *phydev); void (*init_supported_interfaces)(unsigned long *mask); int (*get_mactype)(struct phy_device *phydev); + int (*set_mactype)(struct phy_device *phydev, int mactype); + int (*select_mactype)(unsigned long *interfaces); int (*init_interface)(struct phy_device *phydev, int mactype); #ifdef CONFIG_HWMON @@ -593,6 +600,49 @@ static int mv2110_get_mactype(struct phy_device *phydev) return mactype & MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK; } +static int mv2110_set_mactype(struct phy_device *phydev, int mactype) +{ + int err, val; + + mactype &= MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK; + err = phy_modify_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_21X0_PORT_CTRL, + MV_PMA_21X0_PORT_CTRL_SWRST | + MV_PMA_21X0_PORT_CTRL_MACTYPE_MASK, + MV_PMA_21X0_PORT_CTRL_SWRST | mactype); + if (err) + return err; + + err = phy_set_bits_mmd(phydev, MDIO_MMD_AN, MV_AN_21X0_SERDES_CTRL2, + MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS | + MV_AN_21X0_SERDES_CTRL2_RUN_INIT); + if (err) + return err; + + err = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_AN, + MV_AN_21X0_SERDES_CTRL2, val, + !(val & + MV_AN_21X0_SERDES_CTRL2_RUN_INIT), + 5000, 100000, true); + if (err) + return err; + + return phy_clear_bits_mmd(phydev, MDIO_MMD_AN, MV_AN_21X0_SERDES_CTRL2, + MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS); +} + +static int mv2110_select_mactype(unsigned long *interfaces) +{ + if (test_bit(PHY_INTERFACE_MODE_USXGMII, interfaces)) + return MV_PMA_21X0_PORT_CTRL_MACTYPE_USXGMII; + else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) && + !test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces)) + return MV_PMA_21X0_PORT_CTRL_MACTYPE_5GBASER; + else if (test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces)) + return MV_PMA_21X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH; + else + return -1; +} + static int mv3310_get_mactype(struct phy_device *phydev) { int mactype; @@ -604,6 +654,46 @@ static int mv3310_get_mactype(struct phy_device *phydev) return mactype & MV_V2_33X0_PORT_CTRL_MACTYPE_MASK; } +static int mv3310_set_mactype(struct phy_device *phydev, int mactype) +{ + int ret; + + mactype &= MV_V2_33X0_PORT_CTRL_MACTYPE_MASK; + ret = phy_modify_mmd_changed(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, + MV_V2_33X0_PORT_CTRL_MACTYPE_MASK, + mactype); + if (ret <= 0) + return ret; + + return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL, + MV_V2_33X0_PORT_CTRL_SWRST); +} + +static int mv3310_select_mactype(unsigned long *interfaces) +{ + if (test_bit(PHY_INTERFACE_MODE_USXGMII, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_USXGMII; + else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) && + test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER; + else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) && + test_bit(PHY_INTERFACE_MODE_RXAUI, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI; + else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces) && + test_bit(PHY_INTERFACE_MODE_XAUI, interfaces)) + return MV_V2_3310_PORT_CTRL_MACTYPE_XAUI; + else if (test_bit(PHY_INTERFACE_MODE_10GBASER, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER_RATE_MATCH; + else if (test_bit(PHY_INTERFACE_MODE_RXAUI, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_RXAUI_RATE_MATCH; + else if (test_bit(PHY_INTERFACE_MODE_XAUI, interfaces)) + return MV_V2_3310_PORT_CTRL_MACTYPE_XAUI_RATE_MATCH; + else if (test_bit(PHY_INTERFACE_MODE_SGMII, interfaces)) + return MV_V2_33X0_PORT_CTRL_MACTYPE_10GBASER; + else + return -1; +} + static int mv2110_init_interface(struct phy_device *phydev, int mactype) { struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); @@ -674,10 +764,16 @@ static int mv3310_config_init(struct phy_device *phydev) { struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev); const struct mv3310_chip *chip = to_mv3310_chip(phydev); + DECLARE_PHY_INTERFACE_MASK(interfaces); int err, mactype; - /* Check that the PHY interface type is compatible */ - if (!test_bit(phydev->interface, priv->supported_interfaces)) + /* In case host didn't provide supported interfaces */ + __set_bit(phydev->interface, phydev->host_interfaces); + + /* Check that there is at least one compatible PHY interface type */ + phy_interface_and(interfaces, phydev->host_interfaces, + priv->supported_interfaces); + if (phy_interface_empty(interfaces)) return -ENODEV; phydev->mdix_ctrl = ETH_TP_MDI_AUTO; @@ -687,9 +783,15 @@ static int mv3310_config_init(struct phy_device *phydev) if (err) return err; - mactype = chip->get_mactype(phydev); - if (mactype < 0) - return mactype; + mactype = chip->select_mactype(interfaces); + if (mactype < 0) { + mactype = chip->get_mactype(phydev); + } else { + phydev_info(phydev, "Changing MACTYPE to %i\n", mactype); + err = chip->set_mactype(phydev, mactype); + if (err) + return err; + } err = chip->init_interface(phydev, mactype); if (err) { @@ -1049,6 +1151,8 @@ static const struct mv3310_chip mv3310_type = { .has_downshift = mv3310_has_downshift, .init_supported_interfaces = mv3310_init_supported_interfaces, .get_mactype = mv3310_get_mactype, + .set_mactype = mv3310_set_mactype, + .select_mactype = mv3310_select_mactype, .init_interface = mv3310_init_interface, #ifdef CONFIG_HWMON @@ -1060,6 +1164,8 @@ static const struct mv3310_chip mv3340_type = { .has_downshift = mv3310_has_downshift, .init_supported_interfaces = mv3340_init_supported_interfaces, .get_mactype = mv3310_get_mactype, + .set_mactype = mv3310_set_mactype, + .select_mactype = mv3310_select_mactype, .init_interface = mv3340_init_interface, #ifdef CONFIG_HWMON @@ -1070,6 +1176,8 @@ static const struct mv3310_chip mv3340_type = { static const struct mv3310_chip mv2110_type = { .init_supported_interfaces = mv2110_init_supported_interfaces, .get_mactype = mv2110_get_mactype, + .set_mactype = mv2110_set_mactype, + .select_mactype = mv2110_select_mactype, .init_interface = mv2110_init_interface, #ifdef CONFIG_HWMON @@ -1080,6 +1188,8 @@ static const struct mv3310_chip mv2110_type = { static const struct mv3310_chip mv2111_type = { .init_supported_interfaces = mv2111_init_supported_interfaces, .get_mactype = mv2110_get_mactype, + .set_mactype = mv2110_set_mactype, + .select_mactype = mv2110_select_mactype, .init_interface = mv2110_init_interface, #ifdef CONFIG_HWMON