From patchwork Thu Feb 8 19:06:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 198541 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp391985dyd; Thu, 8 Feb 2024 11:09:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFbRCwLmDsM4QUrBMVv0YEkV46RljrcUqJ5O60Z39QeFeEcBVc1rwF/SzlpMGuDhnjUz1QT X-Received: by 2002:ad4:5dec:0:b0:681:7242:784 with SMTP id jn12-20020ad45dec000000b0068172420784mr143721qvb.45.1707419367203; Thu, 08 Feb 2024 11:09:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707419367; cv=pass; d=google.com; s=arc-20160816; b=hzy9i6IVhoFc61/fD0gXk71kWrmcERjEpf2TSlw/EdOmmd9JCzvSXdYkSnWNyZHXUc cHVDBdM9voHEykrySDxoPjihti+MTPvVkG1e1uLUeLMJs3QgQXJgeAvcnySRRE6R2JQR vVlcJbysR/CuX+PZg7XUDqgAzOih8ZAz3NncwxeHATuYmHyn7I40mu0msaSjGVXhUT+c NbEMaRwunYMyuaNPZwbXUwZ3OSO0qkjpLWvZeeiiWd5+9VQFqiL+IKsLVSX7KZj6jqIm ASxYbyL1dK1vD8RFL8/CERAuoR09QsMX3ZkXUMllPKRUhuBboBR4pE7J0VtqiTKlyddS TEhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=CoKMYJJHifYrItGeT9N7qx5/iRM+pnpQKwxxqyzyd7o=; fh=NaJm0zhIi0Axu9NjOSwqSMawrt3odkcuj2kjqxrGQ1U=; b=QppuHgLkbrmn29Tyl8a90QMCYMtckR3EdGv4F2wF3TlTuQS/Noy1Syph7JxyQqCFCv d4itsqm/Uj2E8Zqd7lL4XZJKTRBDyQBJBnCFBkntnVWWGNGzhA9hfTNQj9h7LNs9B3B2 Wm32ODVui7u0tIxsc8rR7WaTyLhrn+cexvzjDhXV0ghQt2A9gKZO0PKo7gaWZyUOJ2qi OGrf69rcUDb52D3UxoD6UsKzODhosfA1OqeLYmHLqLuAu2rs42cBUG6BNpxvsNp/Clf7 vGcU/alk3cXEhNNTX2KOvSyGFIzF6qnIsT1VFS7YRJ+J1Rzlg71mrzzJjKYgp6+0mfy+ bB/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=OeX9dN8p; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58597-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58597-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCVjJZx3FyTlNjYbJRlk3Svi7USb/Z1nsK1uwfjY8jY5FU8cXl76ZXP4/JxrvhQiZq34Ag8dsF4DqT7chnrWiRGFav+BaA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gy6-20020a056214242600b0068c7a23fd81si153415qvb.489.2024.02.08.11.09.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 11:09:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58597-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=OeX9dN8p; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58597-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58597-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1E9681C28501 for ; Thu, 8 Feb 2024 19:07:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2FB9A2E3E8; Thu, 8 Feb 2024 19:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="OeX9dN8p" Received: from relay.smtp-ext.broadcom.com (unknown [192.19.166.231]) (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 6CA7725601; Thu, 8 Feb 2024 19:06:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.166.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707419171; cv=none; b=AZRNKJGrTRkADU3QGsJi6VlnoaolYwnz3+7lCXtwQjU4N0XRhq7W4UjQfThoiKbjK+Zv5drDM4bdvO7RVT6xcT8p03Kksd0Cb3k3YAMXA7pv11kQXVaxQkpWeOwLh4FnxBNC8k73Uhe4g/Z5arjnq4jyuu3rUcASkpyUodTh2+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707419171; c=relaxed/simple; bh=pyH+Ue54Wg/q6X3n+rbfohcY/QkgjD9zNm2XlWtPMdQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kDnfp6/uKe0rtmq6vpk5yolOPrbEIQzCxzJpMsbXdaUk/HZApA4u/3Zqv72DGSXHtYYDBb+sXKligw8RFzlsPAydvY+wp0qCCIG/yilALjM29Lvi/hPj1fZu8dGmXsEGVjxANKhH/PtGvGZ6z4Ga5/ZcIxP7EM9axtYlqdY/JYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=OeX9dN8p; arc=none smtp.client-ip=192.19.166.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: from mail-lvn-it-01.lvn.broadcom.net (mail-lvn-it-01.lvn.broadcom.net [10.36.132.253]) by relay.smtp-ext.broadcom.com (Postfix) with ESMTP id 9FA97C001CAD; Thu, 8 Feb 2024 11:06:08 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 9FA97C001CAD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707419168; bh=pyH+Ue54Wg/q6X3n+rbfohcY/QkgjD9zNm2XlWtPMdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OeX9dN8pKGCF8ytWIGGd88VHSocOFcVKIRUqTrA7UjTLXtlOOC0xpldeiWbsOYznB rohTCl1F3LmGoT7quZb4COL3x6uoUBxd9gyUaPZ8cat3WOWJYN/qREOBvvwSz2U8qi pa+To89xhUqa0JrIUOi3fWHn/fWdYNrp69tOayHA= Received: from stbirv-lnx-1.igp.broadcom.net (stbirv-lnx-1.igp.broadcom.net [10.67.48.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail-lvn-it-01.lvn.broadcom.net (Postfix) with ESMTPSA id 1E08918041CAC4; Thu, 8 Feb 2024 11:06:07 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org Cc: Florian Fainelli , Russell King , Jakub Kicinski , Sasha Levin , Doug Berger , Florian Fainelli , "David S. Miller" , bcm-kernel-feedback-list@broadcom.com (open list:BROADCOM GENET ETHERNET DRIVER), netdev@vger.kernel.org (open list:BROADCOM GENET ETHERNET DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH stable 5.15 v2] net: bcmgenet: Fix EEE implementation Date: Thu, 8 Feb 2024 11:06:05 -0800 Message-Id: <20240208190605.3341379-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208190605.3341379-1-florian.fainelli@broadcom.com> References: <20240208190605.3341379-1-florian.fainelli@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790358970562915928 X-GMAIL-MSGID: 1790358970562915928 [ Upstream commit a9f31047baca57d47440c879cf259b86f900260c ] We had a number of short comings: - EEE must be re-evaluated whenever the state machine detects a link change as wight be switching from a link partner with EEE enabled/disabled - tx_lpi_enabled controls whether EEE should be enabled/disabled for the transmit path, which applies to the TBUF block - We do not need to forcibly enable EEE upon system resume, as the PHY state machine will trigger a link event that will do that, too Fixes: 6ef398ea60d9 ("net: bcmgenet: add EEE support") Signed-off-by: Florian Fainelli Reviewed-by: Russell King (Oracle) Link: https://lore.kernel.org/r/20230606214348.2408018-1-florian.fainelli@broadcom.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin Signed-off-by: Florian Fainelli --- Changes in v2: - none .../net/ethernet/broadcom/genet/bcmgenet.c | 22 +++++++------------ .../net/ethernet/broadcom/genet/bcmgenet.h | 3 +++ drivers/net/ethernet/broadcom/genet/bcmmii.c | 5 +++++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index 66f0c28298bf..7327a8d5dc75 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1318,7 +1318,8 @@ static void bcmgenet_get_ethtool_stats(struct net_device *dev, } } -static void bcmgenet_eee_enable_set(struct net_device *dev, bool enable) +void bcmgenet_eee_enable_set(struct net_device *dev, bool enable, + bool tx_lpi_enabled) { struct bcmgenet_priv *priv = netdev_priv(dev); u32 off = priv->hw_params->tbuf_offset + TBUF_ENERGY_CTRL; @@ -1338,7 +1339,7 @@ static void bcmgenet_eee_enable_set(struct net_device *dev, bool enable) /* Enable EEE and switch to a 27Mhz clock automatically */ reg = bcmgenet_readl(priv->base + off); - if (enable) + if (tx_lpi_enabled) reg |= TBUF_EEE_EN | TBUF_PM_EN; else reg &= ~(TBUF_EEE_EN | TBUF_PM_EN); @@ -1359,6 +1360,7 @@ static void bcmgenet_eee_enable_set(struct net_device *dev, bool enable) priv->eee.eee_enabled = enable; priv->eee.eee_active = enable; + priv->eee.tx_lpi_enabled = tx_lpi_enabled; } static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_eee *e) @@ -1374,6 +1376,7 @@ static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_eee *e) e->eee_enabled = p->eee_enabled; e->eee_active = p->eee_active; + e->tx_lpi_enabled = p->tx_lpi_enabled; e->tx_lpi_timer = bcmgenet_umac_readl(priv, UMAC_EEE_LPI_TIMER); return phy_ethtool_get_eee(dev->phydev, e); @@ -1383,7 +1386,6 @@ static int bcmgenet_set_eee(struct net_device *dev, struct ethtool_eee *e) { struct bcmgenet_priv *priv = netdev_priv(dev); struct ethtool_eee *p = &priv->eee; - int ret = 0; if (GENET_IS_V1(priv)) return -EOPNOTSUPP; @@ -1394,16 +1396,11 @@ static int bcmgenet_set_eee(struct net_device *dev, struct ethtool_eee *e) p->eee_enabled = e->eee_enabled; if (!p->eee_enabled) { - bcmgenet_eee_enable_set(dev, false); + bcmgenet_eee_enable_set(dev, false, false); } else { - ret = phy_init_eee(dev->phydev, 0); - if (ret) { - netif_err(priv, hw, dev, "EEE initialization failed\n"); - return ret; - } - + p->eee_active = phy_init_eee(dev->phydev, false) >= 0; bcmgenet_umac_writel(priv, e->tx_lpi_timer, UMAC_EEE_LPI_TIMER); - bcmgenet_eee_enable_set(dev, true); + bcmgenet_eee_enable_set(dev, p->eee_active, e->tx_lpi_enabled); } return phy_ethtool_set_eee(dev->phydev, e); @@ -4219,9 +4216,6 @@ static int bcmgenet_resume(struct device *d) if (!device_may_wakeup(d)) phy_resume(dev->phydev); - if (priv->eee.eee_enabled) - bcmgenet_eee_enable_set(dev, true); - bcmgenet_netif_start(dev); netif_device_attach(dev); diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h index d111af605c44..95b3db100af6 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -735,4 +735,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, int bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv, enum bcmgenet_power_mode mode); +void bcmgenet_eee_enable_set(struct net_device *dev, bool enable, + bool tx_lpi_enabled); + #endif /* __BCMGENET_H__ */ diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c index 32fc845ade9e..72bb9364a471 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -87,6 +87,11 @@ static void bcmgenet_mac_config(struct net_device *dev) reg |= CMD_TX_EN | CMD_RX_EN; } bcmgenet_umac_writel(priv, reg, UMAC_CMD); + + priv->eee.eee_active = phy_init_eee(phydev, 0) >= 0; + bcmgenet_eee_enable_set(dev, + priv->eee.eee_enabled && priv->eee.eee_active, + priv->eee.tx_lpi_enabled); } /* setup netdev link state when PHY link status change and