From patchwork Thu Feb 8 18:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 198649 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp515005dyd; Thu, 8 Feb 2024 15:27:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+x57ZhYp0IKfhfSlwvfD+XLEZRgg+nmjRDkK4+GoOG6PFMlXwSoTUk0qKy6KPRUOO1lO5 X-Received: by 2002:a17:906:fcb6:b0:a38:757:fee with SMTP id qw22-20020a170906fcb600b00a3807570feemr882707ejb.8.1707434855533; Thu, 08 Feb 2024 15:27:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434855; cv=pass; d=google.com; s=arc-20160816; b=GhcsuWAxdMbVwJOyCdA1o9nDw9gT4iRzF1ewVTEDUiFVYm9wnr3M24WOhuTbzY+MTc YPPP6NOBbJT9ogFgAzBVcvkk11OEBg0S2vI+SlKYvCx+yLD6dCX/IpaNVuUYp6O3MmUv KxAy2noLGoNKtliZgSw0X1mmHnMq7pfeUnDtk9Y14s87j913busV3pO8jTjPt+hGjLxz YC3RrcEXO7T5WloIkwNhJMF2/dCuO8tlvUw4ypaHwSIwtIW80z+i02cOmRsZxlFjTs7T ZAur75nh0EU6mDIOiS7KzSuriUy1T5lg8MN7KvVXx3cOErGLk4eSTo3OsURvd4nBEKZx tsKw== 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=DQ3Yo6hpSEVN9rwF1JL5EZf+DGeDg25u35/uX4RjowU=; fh=mJnfwxknXZISKDBNbLL9snwJ/T86B/zCPNo42LB5cyE=; b=CLay+zofZzvqQpLoRD6DiB52sv/rRSW2UAdZR/uHkONsSBev61WRayjLUxujmbpwXm 4rM3JQnWvJBjfQDk9IsI+uUP0CcgvVD8v7zEqdzm+tLq6EZIwMw4YKsIfvBcgpX5MXdJ MAwBOOPeWSTUkmsGyLgotlByaPvuNK8JS+ODrhT4RMnOjfY4PFGxk5e/H0v0ljM8QVUP OXwU/2ZwplCqA/7DSNQtSg4Avlq/VE3/zDBvQqxl+ra46bzzTGTrIqCK2o2Lk9hESJVq 08LV2O1HzoUrUwOrPUj5GK9OZKn0T0nEjeb8dYLQ+nJprp6+pnZYq34oKe4zluZD5M+T 4O/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=pg7JONnp; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58524-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58524-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCXja5WdRSU+ovWpneFzzZ/sf9hXp7Zmx0XurY0ShsKDz5eCuXy1oKDnQhPRNso0as4DmS8uTGhfheGVeem9Bz6MVVvSbg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p26-20020a1709060e9a00b00a38020c1999si162634ejf.204.2024.02.08.15.27.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:27:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58524-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=pg7JONnp; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58524-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58524-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 55EF01F28E12 for ; Thu, 8 Feb 2024 18:21:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA3281272D0; Thu, 8 Feb 2024 18:20:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="pg7JONnp" 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 E89DC823C2; Thu, 8 Feb 2024 18:20:50 +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=1707416452; cv=none; b=JK/GtQ+MrbmdEIqpl3KjH16WYIDSzU3Qoh/16zSnZGFsrGTZcuLa8zxCAFXmJi1JZ78iC35Mly5R+kkrba5mfYmqA7VBuxgnziOe98D6QAWbwGJKCmnKYJKt1i/F+hXdaXZtCpGw1IF6XoDS+yam/yjLYtkN/yMEjVHKH4+t7xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707416452; c=relaxed/simple; bh=oSNraDIjNZgqeOB4YZoeNAkbN+8dHm4kET6YmMe3Bl8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fFTzUt22xlKM5WlXiNzQaefobO4J6hSZngRLYbPnKLJJMdLQpdvWB7jpyOqNumkKroazO/bZBlJSxP5715Pdk9Dl4R1DQ7fQGMo/dWNrQgt4JRWIkNc++0D9+xrkvHBXXjsNG8E76EQpxj21Cf4MPFYmZQPuR6u0Q0moLwpBn8A= 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=pg7JONnp; 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 1F7ABC00167E; Thu, 8 Feb 2024 10:20:50 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com 1F7ABC00167E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707416450; bh=oSNraDIjNZgqeOB4YZoeNAkbN+8dHm4kET6YmMe3Bl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pg7JONnp28Gi/i148JjkxuqoXC9IcR0ehy0tZrOjiCFxQTQe//qZH4JQolvvCwca3 Ia/t3vrWxeJEyDHwYl7jLfjlVVmkdK+HJzLOaRPr19grj6KYAvRgL4Q4t0XI9ixNyr iCDG3sFIXNZym9pcQnIGQQKeDkG0SK6W7mQWjC9g= 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 7A72B18041CAC4; Thu, 8 Feb 2024 10:20:48 -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] net: bcmgenet: Fix EEE implementation Date: Thu, 8 Feb 2024 10:20:41 -0800 Message-Id: <20240208182041.3228898-2-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240208182041.3228898-1-florian.fainelli@broadcom.com> References: <20240208182041.3228898-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: 1790359334874435664 X-GMAIL-MSGID: 1790375211065750107 [ 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 --- .../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