From patchwork Thu Feb 8 18:20:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 198626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp496314dyd; Thu, 8 Feb 2024 14:44:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOfRJUcxAPpZvWloqfSswv4/vU9HIQCoZkMHl+x6bNQFOG4l546aKnGon7HkFGwK1YE1iC X-Received: by 2002:a05:6a20:6a0e:b0:19e:99be:c53a with SMTP id p14-20020a056a206a0e00b0019e99bec53amr1502918pzk.4.1707432258447; Thu, 08 Feb 2024 14:44:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707432258; cv=pass; d=google.com; s=arc-20160816; b=INKoN0qUbWkbd0J/E0Kd3p2kj6OmfjAIqL/0I5JX7xy2MiDS/U8xTVWZz0FXoVzdkB xMWi8KAEJ9LqQc3aTdkFvRtWwpYJ66QwG2J3//qhlt2Dvo9/s8MQkb33ks7l0rQD2Hfv 1nnfDsduVzcrxOHmT/4t0+6WtB0t9UAug4lD7EL14tFEPUp6eXKiM6qseCyaWaezUIon ykpLRiDH0i3bRKR64RRbdS5ByanKSVhetFDOvT+hhGIkzDcN/g0BTzdSAh7A3opyOXsU 0prhmscFKSQbQT5MORWi4vwzikOZdQBv8+cexIt9BwYUZs+be0h+ADqfzS8Y1wMFk4Yv XiVg== 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=yk1F0X361HAh1pQ+XGKBAr9kSuT3CJyD3kAJzlY3TqM=; fh=/ZVXcw4k4t0y4alSxxc7CC3YoWkfxdvaI/ghdqMxmxA=; b=qqXwhJYBSWoorfjgxMKw9xHqVjM4vJsUqHAjh8fs4MzrSeYzHok/4pHvwmPAzIj5Dr JRKY57oRPQA7EZq+hv837z6lwLJFnbmaQmsnPlxrKJigmFxIqgPwIQJsobb5Rn5Igv3p ID2GIRmgy873+WmjCZZ7JeG1AedieQWpIXX5Q2lwrJ+iT/ww7LS7klLKNyrIh6EdvwS/ iwVP8tZrQv2lm4GhgReMOHTQL25XBfoOWoXnCk6CpBxDqxdBmV/GBTukl7sgUAFYFb3u x14g7JDJblHg/6MnQE9Jw8E/jN/OMc5Kvk4c45Pe+wFfbFvj8dBB/QbPf/gmsk/jvwjY ir8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=P6cJ9wjF; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58523-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com X-Forwarded-Encrypted: i=2; AJvYcCU1E6ANx5B+tsvIu2KyuAal34mZQL3320hfT1B0A67rUpFCXJOPKhXGgik0kBCWdMuuANXctAi6gASzJq2Bfhzcxhhtxg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n68-20020a632747000000b005dc41265c15si546132pgn.658.2024.02.08.14.44.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 14:44:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=dkimrelay header.b=P6cJ9wjF; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-58523-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58523-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id DDD29B25932 for ; Thu, 8 Feb 2024 18:21:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 813DD1272B5; Thu, 8 Feb 2024 18:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="P6cJ9wjF" Received: from relay.smtp-ext.broadcom.com (unknown [192.19.166.228]) (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 97A6983CD5; Thu, 8 Feb 2024 18:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.19.166.228 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707416451; cv=none; b=B+0qIT+vlnb42eqXhJcgGKon6I8vMZFR+yhX/bZoOmEAQiuA3mze+uzMV/VBZTbAfueDpxffpVbM35WsqKSsR7daLh8XkCe6nbnOPMlGJl2zd9rHSXNm9X2Ee394sklOlCFeXH8sI1OQDslA0C5DyO32D6DRWdpKwRrdoWf+U34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707416451; c=relaxed/simple; bh=3DhEN22lmOWhxC+qxvJ3t5FlzdbECygh0mh33F0j8to=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Kc/JKngr3wF0hXbE1d3eBEuX1Slzmz4QOj+s1N3b2+vVVpjpA7A2Ky98sEhSjaCg7XrCjQniBe8OY0FCY61qHKov/mguBKdzavgss0XW3ppcuoHsLJJHKMqxYozc7ILfeBKLmq/oIs87hFnsb5nnBS3QjMa46A30NUi9SiZvbDs= 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=P6cJ9wjF; arc=none smtp.client-ip=192.19.166.228 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 B6FFCC002E47; Thu, 8 Feb 2024 10:20:48 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 relay.smtp-ext.broadcom.com B6FFCC002E47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=broadcom.com; s=dkimrelay; t=1707416448; bh=3DhEN22lmOWhxC+qxvJ3t5FlzdbECygh0mh33F0j8to=; h=From:To:Cc:Subject:Date:From; b=P6cJ9wjF3OdWzzOTxverzTBk09CfD3FgoPi8ETN0iIrHZStgdPnmvPqUvzC1koaw4 fQmg3aRNeS6jenN28xePfqLLEAPd+DcpMVHeKBMemb1VC7nywMBf7qxJ3bFsMJJP82 Sz03//zB2cltCGN3AuA9Oc2Xv+vWdNTO7Jm0RBYE= 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 31D3518041CAC4; Thu, 8 Feb 2024 10:20:47 -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] net: bcmgenet: Fix EEE implementation Date: Thu, 8 Feb 2024 10:20:40 -0800 Message-Id: <20240208182041.3228898-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: 1790359334874435664 X-GMAIL-MSGID: 1790372487842974363 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 Signed-off-by: Florian Fainelli Change-Id: I9e9d9d9e10817c7fcf3d9cde2389a1f6fe42a2ba --- .../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)