From patchwork Wed Oct 19 08:50:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 13011746 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 3F196C433FE for ; Wed, 19 Oct 2022 13:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231324AbiJSNWJ (ORCPT ); Wed, 19 Oct 2022 09:22:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232504AbiJSNVe (ORCPT ); Wed, 19 Oct 2022 09:21:34 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 583201DDC37; Wed, 19 Oct 2022 06:06:50 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.95,195,1661785200"; d="scan'208";a="137159774" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 19 Oct 2022 17:51:10 +0900 Received: from localhost.localdomain (unknown [10.166.15.32]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 79CEF400BC18; Wed, 19 Oct 2022 17:51:10 +0900 (JST) From: Yoshihiro Shimoda To: linux@armlinux.org.uk, kabel@kernel.org, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH RFC 1/3] net: mdio: Add of_phy_connect_with_host_param() Date: Wed, 19 Oct 2022 17:50:50 +0900 Message-Id: <20221019085052.933385-2-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> References: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC To set host parameters from an ethernet driver, add a new function of_phy_connect_with_host_param(). Signed-off-by: Yoshihiro Shimoda --- drivers/net/mdio/of_mdio.c | 42 ++++++++++++++++++++++++++++++++++++++ include/linux/of_mdio.h | 7 +++++++ include/linux/phy.h | 8 ++++++++ 3 files changed, 57 insertions(+) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 796e9c7857d0..a2b0c3f84eea 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -298,6 +298,48 @@ struct phy_device *of_phy_connect(struct net_device *dev, } EXPORT_SYMBOL(of_phy_connect); +/** + * of_phy_connect_with_host_params + * - Connect to the phy described in the device tree with host parameters + * @dev: pointer to net_device claiming the phy + * @phy_np: Pointer to device tree node for the PHY + * @hndlr: Link state callback for the network device + * @flags: flags to pass to the PHY + * @iface: PHY data interface type + * @host_interfaces: PHY data interface type by host + * @host_speed: PHY data interface speed by host + * + * If successful, returns a pointer to the phy_device with the embedded + * struct device refcount incremented by one, or NULL on failure. The + * refcount must be dropped by calling phy_disconnect() or phy_detach(). + */ +struct phy_device * +of_phy_connect_with_host_params(struct net_device *dev, + struct device_node *phy_np, + void (*hndlr)(struct net_device *), u32 flags, + phy_interface_t iface, + unsigned long *host_interfaces, + int host_speed) +{ + struct phy_device *phy = of_phy_find_device(phy_np); + int ret; + + if (!phy) + return NULL; + + phy->dev_flags |= flags; + phy_interface_copy(phy->host_interfaces, host_interfaces); + phy->host_speed = host_speed; + + ret = phy_connect_direct(dev, phy, hndlr, iface); + + /* refcount is held by phy_connect_direct() on success */ + put_device(&phy->mdio.dev); + + return ret ? NULL : phy; +} +EXPORT_SYMBOL(of_phy_connect_with_host_params); + /** * of_phy_get_and_connect * - Get phy node and connect to the phy described in the device tree diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h index da633d34ab86..1df6edca7578 100644 --- a/include/linux/of_mdio.h +++ b/include/linux/of_mdio.h @@ -24,6 +24,13 @@ of_phy_connect(struct net_device *dev, struct device_node *phy_np, void (*hndlr)(struct net_device *), u32 flags, phy_interface_t iface); struct phy_device * +of_phy_connect_with_host_params(struct net_device *dev, + struct device_node *phy_np, + void (*hndlr)(struct net_device *), u32 flags, + phy_interface_t iface, + unsigned long *host_interfaces, + int host_speed); +struct phy_device * of_phy_get_and_connect(struct net_device *dev, struct device_node *np, void (*hndlr)(struct net_device *)); diff --git a/include/linux/phy.h b/include/linux/phy.h index ddf66198f751..000df47f8ae6 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -185,6 +185,12 @@ static inline void phy_interface_or(unsigned long *dst, const unsigned long *a, bitmap_or(dst, a, b, 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_set_rgmii(unsigned long *intf) { __set_bit(PHY_INTERFACE_MODE_RGMII, intf); @@ -675,6 +681,8 @@ struct phy_device { /* Host supported PHY interface types. Should be ignored if empty. */ DECLARE_PHY_INTERFACE_MASK(host_interfaces); + int host_speed; + /* Energy efficient ethernet modes which should be prohibited */ u32 eee_broken_modes; From patchwork Wed Oct 19 08:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 13011685 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 8637CC4332F for ; Wed, 19 Oct 2022 12:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbiJSMWb (ORCPT ); Wed, 19 Oct 2022 08:22:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233054AbiJSMWR (ORCPT ); Wed, 19 Oct 2022 08:22:17 -0400 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E8D431C3E5F; Wed, 19 Oct 2022 04:56:39 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.95,195,1661785200"; d="scan'208";a="139552393" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 19 Oct 2022 17:51:10 +0900 Received: from localhost.localdomain (unknown [10.166.15.32]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 9388A400BC17; Wed, 19 Oct 2022 17:51:10 +0900 (JST) From: Yoshihiro Shimoda To: linux@armlinux.org.uk, kabel@kernel.org, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH RFC 2/3] net: phy: marvell10g: Add host interface speed configuration Date: Wed, 19 Oct 2022 17:50:51 +0900 Message-Id: <20221019085052.933385-3-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> References: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add support for selecting host speed mode. For now, only support 1000M bps. Signed-off-by: Yoshihiro Shimoda --- drivers/net/phy/marvell10g.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 383a9c9f36e5..daf3242c6078 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -101,6 +101,10 @@ enum { MV_AN_21X0_SERDES_CTRL2_AUTO_INIT_DIS = BIT(13), MV_AN_21X0_SERDES_CTRL2_RUN_INIT = BIT(15), + MV_MOD_CONF = 0xf000, + MV_MOD_CONF_SPEED_MASK = 0x00c0, + MV_MOD_CONF_SPEED_1000 = BIT(7), + /* 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. @@ -147,6 +151,7 @@ struct mv3310_chip { int (*get_mactype)(struct phy_device *phydev); int (*set_mactype)(struct phy_device *phydev, int mactype); int (*select_mactype)(unsigned long *interfaces); + int (*set_macspeed)(struct phy_device *phydev, int macspeed); int (*init_interface)(struct phy_device *phydev, int mactype); #ifdef CONFIG_HWMON @@ -644,6 +649,16 @@ static int mv2110_select_mactype(unsigned long *interfaces) return -1; } +static int mv2110_set_macspeed(struct phy_device *phydev, int macspeed) +{ + if (macspeed != SPEED_1000) + return -EOPNOTSUPP; + + return phy_modify_mmd(phydev, MDIO_MMD_VEND2, MV_MOD_CONF, + MV_MOD_CONF_SPEED_MASK, + MV_MOD_CONF_SPEED_1000); +} + static int mv3310_get_mactype(struct phy_device *phydev) { int mactype; @@ -778,6 +793,13 @@ static int mv3310_config_init(struct phy_device *phydev) if (err) return err; + /* If host provided host mac speed, try to set the mac speed */ + if (phydev->host_speed && chip->set_macspeed) { + err = chip->set_macspeed(phydev, phydev->host_speed); + if (err) + return err; + } + /* If host provided host supported interface modes, try to select the * best one */ @@ -1181,6 +1203,7 @@ static const struct mv3310_chip mv2110_type = { .get_mactype = mv2110_get_mactype, .set_mactype = mv2110_set_mactype, .select_mactype = mv2110_select_mactype, + .set_macspeed = mv2110_set_macspeed, .init_interface = mv2110_init_interface, #ifdef CONFIG_HWMON From patchwork Wed Oct 19 08:50:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 13011747 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 57FAAC43217 for ; Wed, 19 Oct 2022 13:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229976AbiJSNWY (ORCPT ); Wed, 19 Oct 2022 09:22:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231833AbiJSNVz (ORCPT ); Wed, 19 Oct 2022 09:21:55 -0400 Received: from relmlie5.idc.renesas.com (relmlor1.renesas.com [210.160.252.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8DAEF9A9D0; Wed, 19 Oct 2022 06:07:04 -0700 (PDT) X-IronPort-AV: E=Sophos;i="5.95,195,1661785200"; d="scan'208";a="137159777" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie5.idc.renesas.com with ESMTP; 19 Oct 2022 17:51:10 +0900 Received: from localhost.localdomain (unknown [10.166.15.32]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id AD56F400BC17; Wed, 19 Oct 2022 17:51:10 +0900 (JST) From: Yoshihiro Shimoda To: linux@armlinux.org.uk, kabel@kernel.org, andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH RFC 3/3] net: renesas: rswitch: Pass host parameters to phydev Date: Wed, 19 Oct 2022 17:50:52 +0900 Message-Id: <20221019085052.933385-4-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> References: <20221019085052.933385-1-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use of_phy_connect_with_host_params() to pass host parameters to phydev. Otherwise, connected PHY cannot work correctly. Signed-off-by: Yoshihiro Shimoda --- drivers/net/ethernet/renesas/rswitch.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c index c604331bfd88..bb2f1e667210 100644 --- a/drivers/net/ethernet/renesas/rswitch.c +++ b/drivers/net/ethernet/renesas/rswitch.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1234,11 +1235,19 @@ static void rswitch_phy_remove_link_mode(struct rswitch_device *rdev, static int rswitch_phy_init(struct rswitch_device *rdev, struct device_node *phy) { + DECLARE_PHY_INTERFACE_MASK(host_interfaces); struct phy_device *phydev; int err = 0; - phydev = of_phy_connect(rdev->ndev, phy, rswitch_adjust_link, 0, - rdev->etha->phy_interface); + phy_interface_zero(host_interfaces); + if (rdev->etha->phy_interface == PHY_INTERFACE_MODE_SGMII) + __set_bit(PHY_INTERFACE_MODE_SGMII, host_interfaces); + + phydev = of_phy_connect_with_host_params(rdev->ndev, phy, + rswitch_adjust_link, 0, + rdev->etha->phy_interface, + host_interfaces, + rdev->etha->speed); if (!phydev) { err = -ENOENT; goto out;