From patchwork Thu Sep 21 12:19:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Choong Yong Liang X-Patchwork-Id: 13393906 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDC6BE71060 for ; Thu, 21 Sep 2023 12:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7MHBf8iGUcCKBPNASMOaIGZliMaudVgFLwteMV5ndk4=; b=H0PM+X+SSo5fLF JSoA84Ka5n9hEwhKe1/2RDY7e9MEKMYtd5y683TfIknYyqpSpxtnzU1IXcVe4eV9qP15FxCiHyG81 Kx3oSWyAevcax63IyBT1Bz+XZgol9hh+006kU0CnPLxpbSOXF37hNw/ENl4uJysBrbMO+Z3bKqmWl Y04XmM0D3O/m7G1Jenal8hS5UWLo8SiS3SYhdge/+lRewo+aqwq+S0NhO8oysE5ToozplIEow7l4b puuNN3YwaA4m1es0K/ojr/ZHlFF8hXMzdEdsAQVQsFJBj1tua1O5LsXG1x++uXtnYbUwwRrAKPBCx HU8gZdrjwAn9uC62sqbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qjIg3-00604l-1c; Thu, 21 Sep 2023 12:21:03 +0000 Received: from mgamail.intel.com ([134.134.136.31]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qjIg0-00602t-1c for linux-arm-kernel@lists.infradead.org; Thu, 21 Sep 2023 12:21:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695298860; x=1726834860; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lTXXgtikZK8fOV2paXgb9h3Lt1o9zA5yS/eHowFJJOE=; b=QVKkvLJuTl45+O8kNdMC/arOwZgNXhYWM3JNLL2ZQkbylItsfm2e6MpW b6BPgLf1HAF1VjMWRO3XtRUBIsLp+7kvTQVGyF74F72ONpEOHIpQJ6b5L UNhWac36Y/zHGgPw9Sdx2mIwXoxzwN088xyfi6gy2UyekgoRLGeHjouSy s18KFh5Mqjs68TnBY9v4t3g1hjPU1oRhsfnf43Y1xaGN3qTM0MmKQVgFr QJxHyNvI2a8RSdO4Sr63MeZovVVIt+C8djFpv0NrjNC2VpoLGtMz6ZCMH L8JaPBIqKb0BtfUMEffKiKxpI5sOTi7F5eFyL+bYM1sDhYljGBUivHK99 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="444608260" X-IronPort-AV: E=Sophos;i="6.03,165,1694761200"; d="scan'208";a="444608260" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Sep 2023 05:20:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10839"; a="862441935" X-IronPort-AV: E=Sophos;i="6.03,165,1694761200"; d="scan'208";a="862441935" Received: from yongliang-ubuntu20-ilbpg12.png.intel.com ([10.88.229.33]) by fmsmga002.fm.intel.com with ESMTP; 21 Sep 2023 05:20:48 -0700 From: Choong Yong Liang To: Rajneesh Bhardwaj , David E Box , Hans de Goede , Mark Gross , Jose Abreu , Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?q?Marek_Beh=C3=BAn?= , Jean Delvare , Guenter Roeck , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Richard Cochran , Philipp Zabel , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Wong Vee Khee , Jon Hunter , Jesse Brandeburg , Revanth Kumar Uppala , Shenwei Wang , Andrey Konovalov , Jochen Henneberg Cc: David E Box , Andrew Halaney , Simon Horman , Bartosz Golaszewski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, bpf@vger.kernel.org, Voon Wei Feng , Tan Tee Min , Michael Sit Wei Hong , Lai Peter Jun Ann Subject: [PATCH net-next v3 3/5] net: phy: update in-band AN mode when changing interface by PHY driver Date: Thu, 21 Sep 2023 20:19:44 +0800 Message-Id: <20230921121946.3025771-4-yong.liang.choong@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230921121946.3025771-1-yong.liang.choong@linux.intel.com> References: <20230921121946.3025771-1-yong.liang.choong@linux.intel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230921_052100_680613_BF7FF890 X-CRM114-Status: GOOD ( 16.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As there is a mechanism in PHY drivers to switch the PHY interface between SGMII and 2500BaseX according to link speed. In this case, the in-band AN mode should be switching based on the PHY interface as well, if the PHY interface has been changed/updated by PHY driver. For e.g., disable in-band AN in 2500BaseX mode, or enable in-band AN back for SGMII mode (10/100/1000Mbps). Signed-off-by: Choong Yong Liang --- drivers/net/phy/phylink.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 0d7354955d62..5811c8086149 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1723,6 +1723,34 @@ bool phylink_expects_phy(struct phylink *pl) } EXPORT_SYMBOL_GPL(phylink_expects_phy); +/** + * phylink_interface_change() - update both cfg_link_an_mode and + * cur_link_an_mode when there is a change in the interface. + * @phydev: pointer to &struct phy_device + * + * When the PHY interface switches between SGMII and 2500BaseX in + * accordance with the link speed, the in-band AN mode should also switch + * based on the PHY interface + */ +static void phylink_interface_change(struct phy_device *phydev) +{ + struct phylink *pl = phydev->phylink; + + if (pl->phy_state.interface != phydev->interface) { + /* Fallback to the correct AN mode. */ + if (phy_interface_mode_is_8023z(phydev->interface) && + pl->cfg_link_an_mode == MLO_AN_INBAND) { + pl->cfg_link_an_mode = MLO_AN_PHY; + pl->cur_link_an_mode = MLO_AN_PHY; + } else if (pl->config->ovr_an_inband) { + pl->cfg_link_an_mode = MLO_AN_INBAND; + pl->cur_link_an_mode = MLO_AN_INBAND; + } + + pl->phy_state.interface = phydev->interface; + } +} + static void phylink_phy_change(struct phy_device *phydev, bool up) { struct phylink *pl = phydev->phylink; @@ -1739,7 +1767,7 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) pl->phy_state.pause |= MLO_PAUSE_TX; if (rx_pause) pl->phy_state.pause |= MLO_PAUSE_RX; - pl->phy_state.interface = phydev->interface; + phylink_interface_change(phydev); pl->phy_state.link = up; mutex_unlock(&pl->state_mutex);