From patchwork Sat Apr 6 20:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619926 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9E474EB44; Sat, 6 Apr 2024 20:16:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434605; cv=none; b=i03Usj4Y14BwnNoUVjYs5gguMsu3PdB2XAGpdS1c2GjoXB68xXtp8ZP00NhXSLwx2lnr+JAWvsFVYxuK8cSjf24IWOwl4v3jwZLfmYJ1SYG2G40rtfar1giz6wIFmqLu8ht7hfluKsew9h1NmH6BPBCgFB+CJiVueftpoXheobs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434605; c=relaxed/simple; bh=LzDrLCIRFXbyHZJ7V8iUoMb0IOYOM06aLEPPPW/2fc8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZKXAY1UnWa7KmaR6G8ooLacMV2g9Uncif5FmR7VAHUejYMAPt2u/1RNLTndVDs7da2meAmBZkqLUAlTYQBTYNi0WgUpTR4oSlT0uyVHN3hdPmv/apiXaRk23OAiQ4q+EfkGbtRd9FnTd2JO/ToPIF7iZgW3djB42HcZBAG25ztQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=5dPGXmlh; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="5dPGXmlh" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=oh/cxGf6fDe2mzBzmglfTGPPEIubaDYcE+unOBbBPYA=; b=5d PGXmlhhfz0eNFM4TpJBJNpHoU2cbum1Yj099C6Yq3cvAGk22k7DOV+YLIfD9OkwBXjMzy3BZLPZZ+ 7x/SLhIY3K/j784g9JHmx+STUqHCs0YwO/uRERXV1RQnUzHY3vKbC3GxqFUHNAHx/nd0kAuS7fAUM euMDXF6P/u9m/FM=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCSf-00COEr-O9; Sat, 06 Apr 2024 22:16:25 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:15:59 -0500 Subject: [PATCH net-next 1/2] net: usb: lan78xx: Fixup EEE Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-lan78xx-eee-v1-1-2993b14b849c@lunn.ch> References: <20240406-lan78xx-eee-v1-0-2993b14b849c@lunn.ch> In-Reply-To: <20240406-lan78xx-eee-v1-0-2993b14b849c@lunn.ch> To: Woojung Huh , UNGLinuxDriver@microchip.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bryan Whitehead Cc: Heiner Kallweit , Oleksij Rempel , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3169; i=andrew@lunn.ch; h=from:subject:message-id; bh=LzDrLCIRFXbyHZJ7V8iUoMb0IOYOM06aLEPPPW/2fc8=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa2SM4dz9/cnfzH353SiCIjg46UrI7GaUvSDF N6epE9u//KJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtkgAKCRDmvw3LpmlM hCnpEACpXk8zD6qZi8SrkrKffHDURQkfjWhmy85crP14/mSfuFjPdtwBWu/byuJ7FvdlqVSvx62 tgZf9ekXxb6a+cTJDvpOZ1wbtwbAAfsdCb7MkqUA4KVQ5uMlkYW9GWgcghnGuEO7fGY4ueEaT2q isJGVRs58HymoYOyOQXeuIt3fYnDBsfazxElMdelK6qdO7sCcUSxDBg03KfU3qYFsJQGjznO+hn csxpM5ziEJdn9/VjWXoCNdkVnL+oirwIuP7fvzncgPFVBEgU2RyFl/e3TdpFdi4jO50ql/znWW7 xidgoYQK+haRu0FrJAo6enUE5PgDuQQZcLzxy1s9MEt8iD+/3ne9MA98+16VrEqK+/sBH0mE/RW 0RFpCANmqYtvs1kZjrDDRudkT3OTFnF8VdzNEBiIhW+f7xdBpP7xDX6ne4ArMhe5QnvxM5dKBUL pdCNsHrEds0u/N9+IJRGUiMEKLbMjnQP9e/UxTj0dNERIqLNqPaVPr/Ul5iW5pZ5LWsQM3hFZNl Igig2WSUx2b7P4ZiaBCwrMH+f2R9HxwwQI3OlWDwXHhn7kS5Yrh1VmDA3EICENkoyHQ9tWhgNci mUrAhfomfu4Zoe4z7bGr4b/SMEmW/WNEpf+ZFr6NwKfql68oRmwpN2Xov0G3AbF4vAT9R1J3BWS Kqde8dAOo8BXxdw== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into lan783xx_phy_link_status_change() which gets called by phylib when there is a change in link status. lan78xx_set_eee() now just programs the hardware with the LPI timer value, and passed everything else to phylib, so it can correctly setup the PHY. lan743x_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LPI timer value. Call phy_support_eee() to indicate the MAC does actually support EEE. Signed-off-by: Andrew Lunn Reviewed-by: Oleksij Rempel --- drivers/net/usb/lan78xx.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 80ee4fcdfb36..0030be502daa 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1692,15 +1692,10 @@ static int lan78xx_get_eee(struct net_device *net, struct ethtool_keee *edata) ret = lan78xx_read_reg(dev, MAC_CR, &buf); if (buf & MAC_CR_EEE_EN_) { - edata->eee_enabled = true; - edata->tx_lpi_enabled = true; /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */ ret = lan78xx_read_reg(dev, EEE_TX_LPI_REQ_DLY, &buf); edata->tx_lpi_timer = buf; } else { - edata->eee_enabled = false; - edata->eee_active = false; - edata->tx_lpi_enabled = false; edata->tx_lpi_timer = 0; } @@ -1721,24 +1716,16 @@ static int lan78xx_set_eee(struct net_device *net, struct ethtool_keee *edata) if (ret < 0) return ret; - if (edata->eee_enabled) { - ret = lan78xx_read_reg(dev, MAC_CR, &buf); - buf |= MAC_CR_EEE_EN_; - ret = lan78xx_write_reg(dev, MAC_CR, buf); - - phy_ethtool_set_eee(net->phydev, edata); - - buf = (u32)edata->tx_lpi_timer; - ret = lan78xx_write_reg(dev, EEE_TX_LPI_REQ_DLY, buf); - } else { - ret = lan78xx_read_reg(dev, MAC_CR, &buf); - buf &= ~MAC_CR_EEE_EN_; - ret = lan78xx_write_reg(dev, MAC_CR, buf); - } + ret = phy_ethtool_set_eee(net->phydev, edata); + if (ret < 0) + goto out; + buf = (u32)edata->tx_lpi_timer; + ret = lan78xx_write_reg(dev, EEE_TX_LPI_REQ_DLY, buf); +out: usb_autopm_put_interface(dev->intf); - return 0; + return ret; } static u32 lan78xx_get_link(struct net_device *net) @@ -2114,7 +2101,20 @@ static void lan78xx_remove_mdio(struct lan78xx_net *dev) static void lan78xx_link_status_change(struct net_device *net) { + struct lan78xx_net *dev = netdev_priv(net); struct phy_device *phydev = net->phydev; + u32 data; + int ret; + + ret = lan78xx_read_reg(dev, MAC_CR, &data); + if (ret < 0) + return; + + if (phydev->enable_tx_lpi) + data |= MAC_CR_EEE_EN_; + else + data &= ~MAC_CR_EEE_EN_; + lan78xx_write_reg(dev, MAC_CR, data); phy_print_status(phydev); } @@ -2408,6 +2408,8 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) mii_adv_to_linkmode_adv_t(fc, mii_adv); linkmode_or(phydev->advertising, fc, phydev->advertising); + phy_support_eee(phydev); + if (phydev->mdio.dev.of_node) { u32 reg; int len; From patchwork Sat Apr 6 20:16:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13619927 X-Patchwork-Delegate: kuba@kernel.org Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 365824F885; Sat, 6 Apr 2024 20:16:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=156.67.10.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434615; cv=none; b=Ohpy8K31ejQv4SdVzuQ0uBOldpFkCjGcJ2tbGAMmqUMY3RQBNpjecn02N6SVh5Qv29QC+mA3yHvonX5MwD0Mmco9EVhG0kmxlu09goGLMrSwwkEQ9kLhcBo5y3XN6aImw60SwhPADuAzPYs3KclyxD7iJP6z0nuKr4AiKbcX5Lo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712434615; c=relaxed/simple; bh=F0GHo7WXtaoyoLfifO6y6BpGbziO0HDIfRr+QScR4TM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gONHfhmyBgvF9kInkaBeEhrkITr0SeGjRKyPHHoFKXL6FrkwK868wTVAn88tfPvuo9/p4dLdV82hhdqNdo0wGIKN0yr41jKHM3m7CjAZM+WEOtu0hargliaefweaT0t94ZUXc3r1rpOCCEMSHoLgDtS0HP7QnBE9gY8kTWXslYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch; spf=pass smtp.mailfrom=lunn.ch; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b=MdWAiPMC; arc=none smtp.client-ip=156.67.10.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lunn.ch Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lunn.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=lunn.ch header.i=@lunn.ch header.b="MdWAiPMC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:From: Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Content-Disposition: In-Reply-To:References; bh=FPkrENK0Zuf73NwhJFCeyNLXWQmepl+j0ukaA706qw8=; b=Md WAiPMCnkR1I7PIpmceno0aJHibn36/FJyE0DUINa8S4VxS2SlnOXTPZUvduJHbQlV8+/WsBPtouE6 Ly05LTzJ0SF8/NqgSm7RjU16xjSKXDPT3QILZ4kZmXGqZg0q27ctXP0t+npoXOPoxalT+4QR0Qs/K 2JQdQDcj4M5tpuA=; Received: from c-76-156-36-110.hsd1.mn.comcast.net ([76.156.36.110] helo=thinkpad.home.lunn.ch) by vps0.lunn.ch with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtCSj-00COEr-0v; Sat, 06 Apr 2024 22:16:29 +0200 From: Andrew Lunn Date: Sat, 06 Apr 2024 15:16:00 -0500 Subject: [PATCH net-next 2/2] net: lan743x: Fixup EEE Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240406-lan78xx-eee-v1-2-2993b14b849c@lunn.ch> References: <20240406-lan78xx-eee-v1-0-2993b14b849c@lunn.ch> In-Reply-To: <20240406-lan78xx-eee-v1-0-2993b14b849c@lunn.ch> To: Woojung Huh , UNGLinuxDriver@microchip.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bryan Whitehead Cc: Heiner Kallweit , Oleksij Rempel , "Russell King (Oracle)" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3176; i=andrew@lunn.ch; h=from:subject:message-id; bh=F0GHo7WXtaoyoLfifO6y6BpGbziO0HDIfRr+QScR4TM=; b=owEBbQKS/ZANAwAKAea/DcumaUyEAcsmYgBmEa2Sz6vE6PjAi9vSIfixJjbNP3YTwsv2Nyrsv Pe7Hx/H66KJAjMEAAEKAB0WIQRh+xAly1MmORb54bfmvw3LpmlMhAUCZhGtkgAKCRDmvw3LpmlM hKRjD/9rLDVillq8rLS8CWq8BUAjaXqGjtXTOq7Oc97Ha8XKmdLAHv+kXJJXhJRcTlhJKx9I/aT bTzr7eFHzNeiD62qQp45Hed5ya99JYTIE7JuzbQtvnyGN8JMjssrJtLJx9D5rZFYYRPcr/N0G6d Sga5V7zEsfDMGjg7UaDTAvpPBqoPt8lGAple+6SSqHs0EIOjFTfwOv5a7DSHA/wXQRdZylI8+1J aULM9e7BungSnJWsaRfx3jalmiWngpGTh74Fk28HdHjmn5FkhW4eroepCuhYKeflQ6fAbsAhPy4 NVFMa1ab/rOdXV2yHywYQ3p7Olq2+z9OfPT/ZfXuCa3JgQn3iBujnUDF1VRp9UtklHc2GiOIatS cnJakX1SANOexVM7ZXja7i/u1pest+V+WeFORipl/SJI5Sco8cyKfyX6z8XqC+HU1M8LyIZjZqR UHT1fn04WI62rCLIKWDw5nhlZ5ImSobmiM6IrBNMnE6mnHC58EYvjiq6wD0j2KVGySMmaSCWZyl Z32mkjtReKolYEfO1P9jeWjDiWGgljBE6J8vhHXTMTAnIc8Pfk/6KC1FSyb1fwOeISm2K6pVx/w XVL/Hbhm+qLLJWnkq7R8uyVlqZNgVs4mY6llq4DW4fnreOGcQQ6pjHWklc6s//nop4taqAwl4b8 +TXgOJdIUhTKb6g== X-Developer-Key: i=andrew@lunn.ch; a=openpgp; fpr=61FB1025CB53263916F9E1B7E6BF0DCBA6694C84 X-Patchwork-Delegate: kuba@kernel.org The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into lan743x_phy_link_status_change() which gets called by phylib when there is a change in link status. lan743x_ethtool_set_eee() now just programs the hardware with the LTI timer value, and passed everything else to phylib, so it can correctly setup the PHY. lan743x_ethtool_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value. Signed-off-by: Andrew Lunn Reviewed-by: Oleksij Rempel --- drivers/net/ethernet/microchip/lan743x_ethtool.c | 21 --------------------- drivers/net/ethernet/microchip/lan743x_main.c | 7 +++++++ 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c index 8a6ae171e375..d0f4ff4ee075 100644 --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c @@ -1076,15 +1076,10 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev, buf = lan743x_csr_read(adapter, MAC_CR); if (buf & MAC_CR_EEE_EN_) { - eee->eee_enabled = true; - eee->tx_lpi_enabled = true; /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */ buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT); eee->tx_lpi_timer = buf; } else { - eee->eee_enabled = false; - eee->eee_active = false; - eee->tx_lpi_enabled = false; eee->tx_lpi_timer = 0; } @@ -1097,7 +1092,6 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, struct lan743x_adapter *adapter; struct phy_device *phydev; u32 buf = 0; - int ret = 0; if (!netdev) return -EINVAL; @@ -1114,23 +1108,8 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, } if (eee->eee_enabled) { - ret = phy_init_eee(phydev, false); - if (ret) { - netif_err(adapter, drv, adapter->netdev, - "EEE initialization failed\n"); - return ret; - } - buf = (u32)eee->tx_lpi_timer; lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf); - - buf = lan743x_csr_read(adapter, MAC_CR); - buf |= MAC_CR_EEE_EN_; - lan743x_csr_write(adapter, MAC_CR, buf); - } else { - buf = lan743x_csr_read(adapter, MAC_CR); - buf &= ~MAC_CR_EEE_EN_; - lan743x_csr_write(adapter, MAC_CR, buf); } return phy_ethtool_set_eee(phydev, eee); diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 75a988c0bd79..d37a49cd5c69 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1462,6 +1462,13 @@ static void lan743x_phy_link_status_change(struct net_device *netdev) phydev->interface == PHY_INTERFACE_MODE_1000BASEX || phydev->interface == PHY_INTERFACE_MODE_2500BASEX) lan743x_sgmii_config(adapter); + + data = lan743x_csr_read(adapter, MAC_CR); + if (phydev->enable_tx_lpi) + data |= MAC_CR_EEE_EN_; + else + data &= ~MAC_CR_EEE_EN_; + lan743x_csr_write(adapter, MAC_CR, data); } }