From patchwork Mon Feb 12 01:48:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 199588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2251159dyd; Sun, 11 Feb 2024 21:50:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfPRIrPjF2Sh+o1TmPL6Cwzn7kOF+8hMXzfj3QFEXGqSAqkWsYnR5xW9w4SPtqQoTxlcGDrtU1IxpAYlkGvAZaeeDmeQ== X-Google-Smtp-Source: AGHT+IECDcY90tHXBi9Ixjn3B84k4SvU/2qHxJgTGRlKC8Kn7SslCtBJSbvTlccWG3RQtklM9qeK X-Received: by 2002:a05:620a:4490:b0:785:cc83:500d with SMTP id x16-20020a05620a449000b00785cc83500dmr6320920qkp.15.1707717012920; Sun, 11 Feb 2024 21:50:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707717012; cv=pass; d=google.com; s=arc-20160816; b=AL40IsYKkK4/k4e4hSZ4kWQxAxHpD/EVxHtK/jPlkdhl2V/AUd9KCSUYSJXNwJZ/yx WZvTXmupl1wwA+LsxESUClTz10+VS3uB6QliPB2J+y4N31+pjHaIPWTLFIsOev3b/Yjn FwgQWU9oaka2YgkXp292Xk4w80Y1IyAHsgCJjJsDvSMG0vxKIiFs865ZJihh6TAMcx3J 0kBmr7pXek/yfB7nOcOuOH+Z0BWvCFjPCo2i6rcLqRIfHm0uGDCNyIumaKs0m8SVyGdC HVaiDX3mLyidG/PRW0R6mN5LQ3siRx4ZY8GROgRZYGflMYi7u9QaLYok9Nob0HGkvC9T wlRw== 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:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=naqGt+FZUOWlrrPaNnENwBHBxmR4wCE3B1vDr7AjnLE=; fh=YuI8em1+QIpz2b63QT4tzS4os3cbqJuRW9FW/GtnulE=; b=TrsUFR+K4s2Hsxlc3oyOoM88VpMJ6smjylDbAQ3UExZ0k97hv4YURONMwSCrwBXeXd XTDIEH0+5DkFqE2Yr6Y3LsZ9SIy3+6jK6OS8XXSvqT7QRAFRBj2B0pOLvDh5/11JaR5B eh6yDW8yALajNLT7toVP31Jc52qramEHAQ3j4UNoS+Mozk5syz22l5Y7uJY72BBiEy7G rs7bROByPNQfDf8qWO2Pgrgpfu39A1CmLBcYe8ml6QTEPtHQP+4actJE46mcxfDvVaMz t9nim49PK3ruYQ5llAsAYzZ5vr/FmMTqfYzkp7rgyAMydML1XagGBGPf9bPbW+6wxVnT uW0g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=EHE+okVh; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-61059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61059-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCVubXZRGnjsGNJYx/Yhq46e+aKncu8IUMcf6GonVGBNnLMW4Q0Goc4LYEEzJ1mucCM6rHmWt+/Oum0ZbwegY93vpkyVuA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x18-20020a05620a14b200b007840499694csi5095483qkj.206.2024.02.11.21.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 21:50:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=EHE+okVh; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-61059-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61059-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 5BDB61C23DEC for ; Mon, 12 Feb 2024 01:50:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF54579D0; Mon, 12 Feb 2024 01:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="EHE+okVh" 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 E494C5396; Mon, 12 Feb 2024 01:50:02 +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=1707702604; cv=none; b=oNb8ipIopPOBeqeR3V3BcBBbP68wfsjXPeXhHCdxUTlJJZ3+DGnK3ZE3KBMATaaNQP2MVJU5MKjzYzUNFvRL7EjAOuNZ0rY1n8Q2OZnEuDo/Rg0cncn/jihD2RDu4YQ01p5eFwM5G9qK82HkF8t6/jChql8P48w6VY+PRPlGSvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707702604; c=relaxed/simple; bh=nQMrCX2Nlpz0PywRuI79FOgJ46w8SfapQjiAlTEBxF0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dlSMsvbHl0tYBMF3uoSnrgZzk2SdOK3YD+IH7aexaK6+51jZv4++nKRnAwxa5rTeoZs1sTNGncNdcKs6HjjYt6C/sjn9okj55UlYMbkU65CS/L6nxM0SpaIThg+OVLARFMUH9mYIgq5vb9drrzJtvYUpiVehw2+u4WT5ipiAHsU= 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=EHE+okVh; 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 CAABFC003C2E; Sun, 11 Feb 2024 17:49:55 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com CAABFC003C2E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707702595; bh=nQMrCX2Nlpz0PywRuI79FOgJ46w8SfapQjiAlTEBxF0=; h=From:To:Cc:Subject:Date:From; b=EHE+okVh4xvSGKWjUqg2ziKCj2Yu1t0JZectVSsIkVuas46O23atr8K7jgfKZrw05 UJUk7KPgyfQShk/V3mUKNlMrHicEtMAqAqKwFnYLhMsJxZSKp7+uaV0MRaejndGRof ZZ75eAvIzCngm7kxkMe/LhXJdgK/MwdLXctanj/s= 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 3F51C18041CAC4; Sun, 11 Feb 2024 17:49:54 -0800 (PST) From: Florian Fainelli To: stable@vger.kernel.org Cc: Florian Fainelli , Russell King , Jakub Kicinski , 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.4 v3] net: bcmgenet: Fix EEE implementation Date: Sun, 11 Feb 2024 17:48:57 -0800 Message-Id: <20240212014859.3860032-1-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 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: 1790665384548419141 X-GMAIL-MSGID: 1790671074401128903 commit a9f31047baca57d47440c879cf259b86f900260c upstream 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 Reviewed-by: Jacob Keller --- Changes in v2: - removed Changed-id .../net/ethernet/broadcom/genet/bcmgenet.c | 22 +++++++------------ .../net/ethernet/broadcom/genet/bcmgenet.h | 3 +++ drivers/net/ethernet/broadcom/genet/bcmmii.c | 6 +++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index eeadeeec17ba..380bf7a328ba 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1018,7 +1018,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; @@ -1038,7 +1039,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); @@ -1059,6 +1060,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) @@ -1074,6 +1076,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); @@ -1083,7 +1086,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; @@ -1094,16 +1096,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); @@ -3688,9 +3685,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 5b7c2f9241d0..29bf256d13f6 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -736,4 +736,7 @@ int bcmgenet_wol_power_down_cfg(struct bcmgenet_priv *priv, void 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 2fbec2acb606..026f00ccaa0c 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -25,6 +25,7 @@ #include "bcmgenet.h" + /* setup netdev link state when PHY link status change and * update UMAC and RGMII block when link up */ @@ -96,6 +97,11 @@ void bcmgenet_mii_setup(struct net_device *dev) CMD_RX_PAUSE_IGNORE | CMD_TX_PAUSE_IGNORE); reg |= cmd_bits; 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); } else { /* done if nothing has changed */ if (!status_changed)