From patchwork Wed Jun 29 12:20:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12899899 X-Patchwork-Delegate: geert@linux-m68k.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 85709C43334 for ; Wed, 29 Jun 2022 12:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231552AbiF2MVP (ORCPT ); Wed, 29 Jun 2022 08:21:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbiF2MVO (ORCPT ); Wed, 29 Jun 2022 08:21:14 -0400 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [IPv6:2001:4b98:dc4:8::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24C6C2EA2F; Wed, 29 Jun 2022 05:21:10 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 96B94100002; Wed, 29 Jun 2022 12:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1656505269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=c83soaBUi/uJOyhuJxfgA9+0o0F+wKpVmr2GzEnt4rM=; b=kGcnfWJWZlnAzSbBxJysIe3WGP9752id2n6DN9QVWk/Zpz75XuqU8yvD+dm8TkTwayyZMP NqCADVRu7iKk2knk22U5A5SFZ1yV2FT02jgIDoE7jDXW/PnjO2KizVzlfSOtCPvP9xd88f bUs6oByIwRyh99+jXXBmVtrOU+MpDjlW70b1A4vttUQ0qsZTHGXT1dZjyaJt9ejJJUhH5x 6br3/EuRYFZl6oTRTJkGa3Ngppf0tOf5ewEyCP/mSrZ2YtfheAM5R7Xs2l9J0ic1YIKzsf 2qznzpdihAnfr5SGN4vnrNXQMnwN5pPXFa7MW/K6mvbJtLCij/Y/gESgSgs/Bg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-renesas-soc@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Petazzoni , Herve Codina , =?utf-8?q?Miqu=C3=A8l_Raynal?= , Milan Stevanovic , Jimmy Lalande , Pascal Eberhard Subject: [PATCH net-next] net: pcs: rzn1-miic: update speed only if interface is changed Date: Wed, 29 Jun 2022 14:20:03 +0200 Message-Id: <20220629122003.189397-1-clement.leger@bootlin.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org As stated by Russel King, miic_config() can be called as a result of ethtool setting the configuration while the link is already up. Since the speed is also set in this function, it could potentially modify the current speed that is set. This will only happen if there is no PHY present and we aren't using fixed-link mode. Handle that by storing the current interface mode in the miic_port structure and update the speed only if the interface mode is going to be changed. Signed-off-by: Clément Léger --- drivers/net/pcs/pcs-rzn1-miic.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/net/pcs/pcs-rzn1-miic.c b/drivers/net/pcs/pcs-rzn1-miic.c index 8f5e910f443d..a7dab7b48dda 100644 --- a/drivers/net/pcs/pcs-rzn1-miic.c +++ b/drivers/net/pcs/pcs-rzn1-miic.c @@ -138,11 +138,13 @@ struct miic { * @miic: backiling to MII converter structure * @pcs: PCS structure associated to the port * @port: port number + * @interface: interface mode of the port */ struct miic_port { struct miic *miic; struct phylink_pcs pcs; int port; + phy_interface_t interface; }; static struct miic_port *phylink_pcs_to_miic_port(struct phylink_pcs *pcs) @@ -190,8 +192,8 @@ static int miic_config(struct phylink_pcs *pcs, unsigned int mode, { struct miic_port *miic_port = phylink_pcs_to_miic_port(pcs); struct miic *miic = miic_port->miic; + u32 speed, conv_mode, val, mask; int port = miic_port->port; - u32 speed, conv_mode, val; switch (interface) { case PHY_INTERFACE_MODE_RMII: @@ -216,11 +218,20 @@ static int miic_config(struct phylink_pcs *pcs, unsigned int mode, return -EOPNOTSUPP; } - val = FIELD_PREP(MIIC_CONVCTRL_CONV_MODE, conv_mode) | - FIELD_PREP(MIIC_CONVCTRL_CONV_SPEED, speed); + val = FIELD_PREP(MIIC_CONVCTRL_CONV_MODE, conv_mode); + mask = MIIC_CONVCTRL_CONV_MODE; - miic_reg_rmw(miic, MIIC_CONVCTRL(port), - MIIC_CONVCTRL_CONV_MODE | MIIC_CONVCTRL_CONV_SPEED, val); + /* Update speed only if we are going to change the interface because + * the link might already be up and it would break it if the speed is + * changed. + */ + if (interface != miic_port->interface) { + val |= FIELD_PREP(MIIC_CONVCTRL_CONV_SPEED, speed); + mask |= MIIC_CONVCTRL_CONV_SPEED; + miic_port->interface = interface; + } + + miic_reg_rmw(miic, MIIC_CONVCTRL(port), mask, val); miic_converter_enable(miic_port->miic, miic_port->port, 1); return 0;