From patchwork Wed Nov 17 22:50:43 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: 12625681 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA690C4332F for ; Wed, 17 Nov 2021 22:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAE4861B93 for ; Wed, 17 Nov 2021 22:51:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241472AbhKQWyA (ORCPT ); Wed, 17 Nov 2021 17:54:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:51202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241454AbhKQWx4 (ORCPT ); Wed, 17 Nov 2021 17:53:56 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0CAB661BA1; Wed, 17 Nov 2021 22:50:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189457; bh=Sh+21fQkevzKHY6BMtF9nXk+QCIMlzBA3QMW2tZNoew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+RNA5N5BALCG9un3QWwIhvRu9rtxwgiu+aEAqipXwPSQa/Zh7o/J/zQKC5Sich1L eGc1HvmTyOep0GXJC/KS5GQ8/CDmZeH8gAdzJzVEKKHwD20vA86iz3JQB8dkJe9ona e2Af5JMP96MxOrpxUk0K1ZUM0lLNp49lDQhH997c7YaqwEQbEh0i9y5DyrFoegOTu8 EnU7+2XkeDlCmi9AVVeoq2o584kFgZtW0yfoZXxvQ1tt4FooqMjWBkw+50i/0lYWRr P6YcYy5u6CLs/Cg2xFIKtrRRkLwEuxIGRR7wJQsZCAPpvQOqVUKOcSGDTppJYOysPs 8c8rH41m3z81g== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 1/8] dt-bindings: ethernet-controller: support multiple PHY connection types Date: Wed, 17 Nov 2021 23:50:43 +0100 Message-Id: <20211117225050.18395-2-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 Cc: devicetree@vger.kernel.org Reviewed-by: Andrew Lunn --- Changes since RFC: - update also description of the `phy-connection-type` property --- .../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 Wed Nov 17 22:50:44 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: 12625683 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30332C433EF for ; Wed, 17 Nov 2021 22:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1940661B9F for ; Wed, 17 Nov 2021 22:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241479AbhKQWyC (ORCPT ); Wed, 17 Nov 2021 17:54:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:51234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241452AbhKQWx6 (ORCPT ); Wed, 17 Nov 2021 17:53:58 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D102361B93; Wed, 17 Nov 2021 22:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189459; bh=8QI5zgNX6FAyW+1FqIk7tgJ+sJMwphnuLdkZC0QM4Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GG2ipseL/uFWU2Qo6JZvtYZcNJA7FJWUJqGCiANSjSgUpyeRQ3gpb5JX9IqoqN05M g21wyLNpPA+5ux8Kt7Op3BVIe6BcbQ5Ij1LXe1KKb2clYUrjAI+j/MWE1mb+Fw+KfS VvuJSLIQopbNyuAtUWh2jRRIuJ+cyy65oKRvKWaPQg2Zz1pZIQZuOaROzHDXezDpfr iX/oiswVWfB+k2d4YgmJjYwLXyFyNvVWTQGT8STyyGSpMXRpgyGWn/Z69jaa5rPlvJ KblvGjvl4lQk62uoeI38Z6d6q/KOvO0/KK41lOGXJXkceLlxwA+IiawvCnH8RkeXPs dM3Fn1uRps4kQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 2/8] net: Update documentation for *_get_phy_mode() functions Date: Wed, 17 Nov 2021 23:50:44 +0100 Message-Id: <20211117225050.18395-3-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 Wed Nov 17 22:50:45 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: 12625685 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81F2AC433EF for ; Wed, 17 Nov 2021 22:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6783561BD3 for ; Wed, 17 Nov 2021 22:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241482AbhKQWyE (ORCPT ); Wed, 17 Nov 2021 17:54:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:51286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241468AbhKQWyA (ORCPT ); Wed, 17 Nov 2021 17:54:00 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A06E261B9F; Wed, 17 Nov 2021 22:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189461; bh=a9yOpygQWOFXF/Zv6Qdc+lw/irBC0JDiccS+/FN/lho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6hst4PRWIrFqRwOLaVLaEfz6CLxs+PJuOSc7cItRRCLS47hHiGADhNaTlbDtvFbH +UD/aU9CWwSLgtom4cWUWtQaXwoA2+DZzwKhJzybCDyi33heoGOSbkR40WzsquerR3 CvZYQwQqdfGKdWFcaF6B5+kZQjVl/I2S29GBcBRU4xG43Zna9OG4OjW8pLsDQe/9TW npNvSZQiEGyZBAZGWzirmjeEF9SqWcmp3Q9oNE8QqcHZtJqjNsHa87cuhssbqevr0V bteDvUTFrxkC61IgK537KXVDvkDQO/MxgrwSqp+Mn7/S025saZ1cPDNw789ixQizPp M2TFNVyldmMFg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 3/8] device property: add helper function for getting phy mode bitmap Date: Wed, 17 Nov 2021 23:50:45 +0100 Message-Id: <20211117225050.18395-4-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 Wed Nov 17 22:50:46 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: 12625687 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E80EC433FE for ; Wed, 17 Nov 2021 22:51:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B6E1613D0 for ; Wed, 17 Nov 2021 22:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241495AbhKQWyL (ORCPT ); Wed, 17 Nov 2021 17:54:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:51338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241475AbhKQWyB (ORCPT ); Wed, 17 Nov 2021 17:54:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6FB3961BA1; Wed, 17 Nov 2021 22:51:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189462; bh=6TQslwpbQgCRCGvOuUjPr6Nry14AkQU6Zx3A5C+Qx5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kXsyMFnx1XTebq0Qa4yd3/+F51JpGBNrTZZuOA9p7M5Onu2+2RkIRsJ7SI+ge3HRb M0iTyEwR8WY7RC8JowgtgW6M76YPyQnquHCLKZ9asfvGZiv9pKzfCy+gxdxUFMZFI5 x8q+4nehRvsEJ7s2oerqOBDQkqMta/oqjZlMHDqyx5GYRK5r2JLQxlFLi2a5NUUlpB +931qp4mcCux5xHTkGm2w/ef0xTJzPRLZfnYrnKtIxzuXRLYBOt4O0f9U5QagfbAgB /TlYfZO7MsXZ1OWsMX3if4KUBqH5hkJ5Xe/mBsRG8E1PS67SxLPjOJA0VAx+J+S8rI V7IGvQ1gSl4kw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 4/8] net: phylink: update supported_interfaces with modes from fwnode Date: Wed, 17 Nov 2021 23:50:46 +0100 Message-Id: <20211117225050.18395-5-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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. Signed-off-by: Marek Behún --- drivers/net/phy/phylink.c | 63 +++++++++++++++++++++++++++++++++++++++ include/linux/phy.h | 6 ++++ 2 files changed, 69 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index f7156b6868e7..6d7c216a5dea 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -563,6 +563,67 @@ 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); + + if (fwnode_get_phy_modes(fwnode, modes) < 0) + return; + + if (phy_interface_empty(modes)) + return; + + /* If supported is empty, just copy modes defined in fwnode. */ + if (phy_interface_empty(supported)) + return phy_interface_copy(supported, modes); + + /* 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) { + bool lower = false; + + if (test_bit(PHY_INTERFACE_MODE_10GBASER, modes) || + test_bit(PHY_INTERFACE_MODE_USXGMII, modes)) { + if (test_bit(PHY_INTERFACE_MODE_5GBASER, supported)) + __set_bit(PHY_INTERFACE_MODE_5GBASER, modes); + if (test_bit(PHY_INTERFACE_MODE_10GBASER, supported)) + __set_bit(PHY_INTERFACE_MODE_10GBASER, modes); + if (test_bit(PHY_INTERFACE_MODE_USXGMII, supported)) + __set_bit(PHY_INTERFACE_MODE_USXGMII, modes); + 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))) { + if (test_bit(PHY_INTERFACE_MODE_SGMII, supported)) + __set_bit(PHY_INTERFACE_MODE_SGMII, modes); + if (test_bit(PHY_INTERFACE_MODE_1000BASEX, supported)) + __set_bit(PHY_INTERFACE_MODE_1000BASEX, modes); + if (test_bit(PHY_INTERFACE_MODE_2500BASEX, supported)) + __set_bit(PHY_INTERFACE_MODE_2500BASEX, modes); + } + } + + phy_interface_and(supported, supported, modes); +} + static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) { struct fwnode_handle *dn; @@ -1156,6 +1217,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); diff --git a/include/linux/phy.h b/include/linux/phy.h index 1e57cdd95da3..83ae15ab1676 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) { From patchwork Wed Nov 17 22:50:47 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: 12625689 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F32E2C433EF for ; Wed, 17 Nov 2021 22:51:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD43F61B7D for ; Wed, 17 Nov 2021 22:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241503AbhKQWyQ (ORCPT ); Wed, 17 Nov 2021 17:54:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:51388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241452AbhKQWyD (ORCPT ); Wed, 17 Nov 2021 17:54:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3F4E961B7D; Wed, 17 Nov 2021 22:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189464; bh=wtPo9eEOU3l9X4mBTIoDho9DYbbysz2q0qlt7yuHE5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uD6YFjiZY5VTzs2pj3jvEWlR5gaGNTPs4mudvzaiR5jGoQKf1WjFI5V4QJYoieSkf GRMbD5lt45fdxjeg+RgNymjZjRU7FcOD92ptP4B5d/U5ekzKYJaI8VkM8I6I8Ay+sQ xkJ34nQc2txOCzBvQWzcYacGQFsrVzQnl/z5BqhcOckMI4q1KPEYWy1sBr+YabJo1S /bHy0R9kEq7jX476JFlFB353dX38PR26BtqjFJPqIWqINpdlXh3AJWbd3SuOG51UCS dhXassnXw1s75OimsP5LQo6YxFavir9mqu2RkgfHdHdP835f82YyFauAu7HihocsXe gQQgxAOsdaryQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 5/8] net: phylink: pass supported PHY interface modes to phylib Date: Wed, 17 Nov 2021 23:50:47 +0100 Message-Id: <20211117225050.18395-6-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 6d7c216a5dea..20403b9676e1 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1430,6 +1430,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; @@ -1505,6 +1509,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); + ret = phy_attach_direct(pl->netdev, phy_dev, flags, pl->link_interface); if (ret) { @@ -2689,6 +2697,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; @@ -2710,6 +2720,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) @@ -3071,4 +3085,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_10GKR, 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); + + return 0; +} +module_init(phylink_init); + MODULE_LICENSE("GPL v2"); diff --git a/include/linux/phy.h b/include/linux/phy.h index 83ae15ab1676..11f3b5b7d7b1 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -569,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 @@ -658,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 Wed Nov 17 22:50:48 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: 12625691 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE269C433F5 for ; Wed, 17 Nov 2021 22:51:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B4F2761B7D for ; Wed, 17 Nov 2021 22:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241468AbhKQWyR (ORCPT ); Wed, 17 Nov 2021 17:54:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:51448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241484AbhKQWyF (ORCPT ); Wed, 17 Nov 2021 17:54:05 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0EC726101C; Wed, 17 Nov 2021 22:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189466; bh=w8cQj8Xef1Oh87M1Z22c1qsxYss2IbmH3JBYGxMtkMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IZImEU3InvHwzczuJnkExTBECRvl+PtQxlBd9KnSHZWBTGusVj8Tw2NxG367P9kHe 3+2+FxqwZfK5S/hVwyQHEClQ5BVpgFAG1jwr5NDTnF/hVN8X/AnwzSSBBMYrguSaZX 7MRC0cccVWrisHxucuHQDZAMSzvmBhUmDjIRdYbJEzNXkJIgF230ZbZhrvtvJmFMXp /SUwB8nwug1924uICC0H1SoO6JGrLkQ2PmORK+9U9LqKAXHgygdP0bAhO5KNHeezlc ldb9pVN+BpnrQTjbv7bgQKn+nC6hZDCWIP+yQthcE1/2pJdNhF410JUIudCSjHGOb8 Aife3Sehr+0xg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 6/8] net: phy: marvell10g: Use generic macro for supported interfaces Date: Wed, 17 Nov 2021 23:50:48 +0100 Message-Id: <20211117225050.18395-7-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 Wed Nov 17 22:50:49 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: 12625693 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B734C433EF for ; Wed, 17 Nov 2021 22:51:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C68D613D0 for ; Wed, 17 Nov 2021 22:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241518AbhKQWyX (ORCPT ); Wed, 17 Nov 2021 17:54:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:51466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241485AbhKQWyH (ORCPT ); Wed, 17 Nov 2021 17:54:07 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DC3EC61B93; Wed, 17 Nov 2021 22:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189468; bh=whK1wt/Uk1I5jN9W5WcTntaGF28yC0dQ4k4Bl9OH6Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HFp5m/6XDpAtwkB0LJGKP1K6DenAvmzOsA2suEq1VhwaKd9g9Bj3hERW8tWCBTC57 by8kdLhLPbGsZrJOxQ4gXSooZdZkRhm3KcoHfZVoeN7iCbekZHNZmUON8njCpzf2lS Yr0lD2UWxxKSgpkfP442R9bCrHk1CaePUEf4geRRWyOQsX0br1Yh8w6FEY7OVe9MmO InmMAIN3sDQnOqBvM301gqgF3Gn/bP5XI3RTUNn6RNJpgXhyX65Mb8gPWKxM0g8lR2 i/AeSR+hQUcbBs93P03hq+Hb/udcYwmc80vtvEaasAl7yDrcw4Aidefk+F6QwdLYz1 0bXO6GJc1L/zg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 7/8] net: phy: marvell10g: Use tabs instead of spaces for indentation Date: Wed, 17 Nov 2021 23:50:49 +0100 Message-Id: <20211117225050.18395-8-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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 Wed Nov 17 22:50:50 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: 12625695 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30FBBC433F5 for ; Wed, 17 Nov 2021 22:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 165FC613D0 for ; Wed, 17 Nov 2021 22:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241532AbhKQWy2 (ORCPT ); Wed, 17 Nov 2021 17:54:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:51504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241488AbhKQWyJ (ORCPT ); Wed, 17 Nov 2021 17:54:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC3C461BCF; Wed, 17 Nov 2021 22:51:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637189470; bh=GyCY08s0Brp5i/xVSdvC3xXsX4BvDeO4gHsWneeh5cM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m5bsagck3HXz6EptfxjY6t13DRb0ZLML5sNtFHersJoYS8nWQ/BUlVGPIThie7Xkr WoR+UnATcmu6sTJBVN/c4mlop6adUQ+etdgH50ldmKG2Qf5VUCUM+2Z5EzeO+Jc4lL EJLALjm2gNvB8y2x0vNXeNFby/7u1abx3rnHs+ioJbucKOhAEEM6PF95egEg2ao0Hz g+5/0Mkn/Nqa2SnN64Q3z9kz4R48px3aG3JKTywNhmSwEGcMI0RfOvkxOun0jGr52h NKnchGqSBoqM6vbcYws0Tmwl+7VpDbiPZXjs9qZuLyJzM5puwRmoCb49g3tzQ+kXXl TbR14HsR+4HQg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: netdev@vger.kernel.org, Andrew Lunn Cc: Jakub Kicinski , David Miller , Russell King , Rob Herring , devicetree@vger.kernel.org, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH net-next 8/8] net: phy: marvell10g: select host interface configuration Date: Wed, 17 Nov 2021 23:50:50 +0100 Message-Id: <20211117225050.18395-9-kabel@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117225050.18395-1-kabel@kernel.org> References: <20211117225050.18395-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. 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) Signed-off-by: Russell King [ rebase, updated, also added support for 88E21X0 ] Signed-off-by: Marek Behún --- 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