From patchwork Fri Jun 16 22:14:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 109379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1653415vqr; Fri, 16 Jun 2023 15:33:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eaTCXhGuDjI758mK5pyWAkky1tgsENYMX55jwjILsyiOiCKN7WJg+Vw2wKexugrmJ2L95 X-Received: by 2002:a17:902:e807:b0:1b3:d33f:917 with SMTP id u7-20020a170902e80700b001b3d33f0917mr2455204plg.49.1686954820651; Fri, 16 Jun 2023 15:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686954820; cv=none; d=google.com; s=arc-20160816; b=CmfAWl11427DokOz/+6zY+8hfenEHruexM9M2biPjN1jwgPhRlWe85b8PJQxaRp1bf wndpes3zSXr9G2x6od38k3yv81HuphmDRPUKGUMspSuUVdu3WucPDGyLu3JFutLiZjKu 6T2jCHNRV49TCRvC0njJJy+D8GjN4P6/X5lLePROBVNjRznX7e0MH3M22lOaXeXzUrWE GBOS51M8iw7cOcmr88KvNCUZwJbJxUhOvPWuKlewA0VSh9Xl74wkSxmB4kx+6ZFq7DE4 AauNLV+JjLlcqnlQxope0qY652UHweF7w9FGap5WMUzI5KHzxa1uc7qSB0oOBwz28A2y V4wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=JGI36TfAMbHppwGcmyn/F9ivlJvVAyDDQcZEGdAG8EA=; b=iWNp3JtAlIDecMH6qDcHJCiP680yIJTy6YJNhEXBIYtxE+2cM6Pehy4NIRI+uRPIKI zmdzxc9aGK14pfhxvr7ht7wpvg5rFTRgW6ke5yTprnde7uAUoZgE6wGPNuPHebD60iUM V4FgCddV4wq81GUcnLqY1bXuDRQUVJik/Owqkv7rIEq+XgF4wlmR+j0DRVb6J6FePDNB 6kbKkYF7ts1wdKoFXz/TbcYrucJEVD4n2JmoYAx9tOO1AUaiHmyf6wCJsmClAkPEqQuZ vP0Xn7taxCqM9/q9AIeGFG2OPvqRvhCxx1O6c6gVcj3U/53AURBUxXCzhtY6BfG08Zh5 stvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=FhPhOF3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a170902f54900b001b3e1afe77fsi1694509plf.103.2023.06.16.15.33.26; Fri, 16 Jun 2023 15:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=FhPhOF3H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345914AbjFPWPb (ORCPT + 99 others); Fri, 16 Jun 2023 18:15:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345668AbjFPWPC (ORCPT ); Fri, 16 Jun 2023 18:15:02 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58FB23C22 for ; Fri, 16 Jun 2023 15:14:44 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b517ee9157so8654055ad.3 for ; Fri, 16 Jun 2023 15:14:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686953683; x=1689545683; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=JGI36TfAMbHppwGcmyn/F9ivlJvVAyDDQcZEGdAG8EA=; b=FhPhOF3H0OdGveTnzdZOBU9eRuh40fYlkE147Bs41PXA0b23nZUMCohxKOUUx+1T9Q evaX+OGoz3piNRL10iRRC/sAx4pTWKHaRYyM2FY1qAMlKvTM5FVG7/1Oc/9qWks8aAF6 x3Dm7ygTtprCwSTHmnPy7ixsMwkJv0cUhHIl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686953683; x=1689545683; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JGI36TfAMbHppwGcmyn/F9ivlJvVAyDDQcZEGdAG8EA=; b=TvAYfTSmFaZToqcim0OZYU6IodkYIjIQORcLViOjwuEBNbNc/iq5nP4Y8xVGSTs5vB OSJIDHlaUiH2TLaZY0ooS7RoJDHGwz3xyiaNBzVekdvR3lnASelRktfOKb/UOXXEe8zR ZQHc9E3Fo169ODm7Cp/0NYZRnFEtdOxHHOcwoWGB74JpsVRxihio0weqRvokAsTA9A+H Up0CiXDt/5gOeNJrCNq+gfz7QShV2UayNDJ/6ES96CghuBQMQ4AyFLND+fvh28umPPRV 1A1UG69QbuEujQrqr+IrMAFOR11cVuN4PaDjImbVznXXYmpN+zseXOMLdD2tnb6KhDmm OPHg== X-Gm-Message-State: AC+VfDyM4/c9l4CM30coSxHELiuqYu1ZTi/iAQxkaxvWrUZzYYh8M/Id 6SjvbE97yt5+pYGNKW9oCooaQw== X-Received: by 2002:a17:903:442:b0:1b1:d39e:28bb with SMTP id iw2-20020a170903044200b001b1d39e28bbmr2426746plb.34.1686953683626; Fri, 16 Jun 2023 15:14:43 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id f12-20020a170902ab8c00b001aaed524541sm16220860plr.227.2023.06.16.15.14.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2023 15:14:43 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, bcm-kernel-feedback-list@broadcom.com Cc: florian.fainelli@broadcom.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, opendmb@gmail.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, richardcochran@gmail.com, sumit.semwal@linaro.org, christian.koenig@amd.com, simon.horman@corigine.com, Justin Chen Subject: [PATCH net-next v8 06/11] net: bcmasp: Add support for eee mode Date: Fri, 16 Jun 2023 15:14:19 -0700 Message-Id: <1686953664-17498-7-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1686953664-17498-1-git-send-email-justin.chen@broadcom.com> References: <1686953664-17498-1-git-send-email-justin.chen@broadcom.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, MIME_HEADER_CTYPE_ONLY,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768900338118317658?= X-GMAIL-MSGID: =?utf-8?q?1768900338118317658?= Add support for eee mode. Signed-off-by: Justin Chen --- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ++ .../net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 61 ++++++++++++++++++++++ drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 6 +++ 3 files changed, 71 insertions(+) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.h b/drivers/net/ethernet/broadcom/asp2/bcmasp.h index e791b869006e..d6740077877a 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h @@ -313,6 +313,8 @@ struct bcmasp_intf { /* Used if per intf wol irq */ int wol_irq; unsigned int wol_irq_enabled:1; + + struct ethtool_eee eee; }; #define NUM_NET_FILTERS 32 @@ -559,4 +561,6 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, u32 *rule_cnt); void bcmasp_netfilt_suspend(struct bcmasp_intf *intf); + +void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable); #endif diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c index eddd1c43f00e..1e96a69043f3 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c @@ -191,6 +191,65 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, return err; } +void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable) +{ + u32 reg; + + reg = umac_rl(intf, UMC_EEE_CTRL); + if (enable) + reg |= EEE_EN; + else + reg &= ~EEE_EN; + umac_wl(intf, reg, UMC_EEE_CTRL); + + intf->eee.eee_enabled = enable; + intf->eee.eee_active = enable; +} + +static int bcmasp_get_eee(struct net_device *dev, struct ethtool_eee *e) +{ + struct bcmasp_intf *intf = netdev_priv(dev); + struct ethtool_eee *p = &intf->eee; + + if (!dev->phydev) + return -ENODEV; + + e->eee_enabled = p->eee_enabled; + e->eee_active = p->eee_active; + e->tx_lpi_enabled = p->tx_lpi_enabled; + e->tx_lpi_timer = umac_rl(intf, UMC_EEE_LPI_TIMER); + + return phy_ethtool_get_eee(dev->phydev, e); +} + +static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e) +{ + struct bcmasp_intf *intf = netdev_priv(dev); + struct ethtool_eee *p = &intf->eee; + int ret; + + if (!dev->phydev) + return -ENODEV; + + if (!p->eee_enabled) { + bcmasp_eee_enable_set(intf, false); + } else { + ret = phy_init_eee(dev->phydev, 0); + if (ret) { + netif_err(intf, hw, dev, + "EEE initialization failed: %d\n", ret); + return ret; + } + + umac_wl(intf, e->tx_lpi_timer, UMC_EEE_LPI_TIMER); + intf->eee.eee_active = ret >= 0; + intf->eee.tx_lpi_enabled = e->tx_lpi_enabled; + bcmasp_eee_enable_set(intf, true); + } + + return phy_ethtool_set_eee(dev->phydev, e); +} + const struct ethtool_ops bcmasp_ethtool_ops = { .get_drvinfo = bcmasp_get_drvinfo, .get_link = ethtool_op_get_link, @@ -202,4 +261,6 @@ const struct ethtool_ops bcmasp_ethtool_ops = { .set_wol = bcmasp_set_wol, .get_rxnfc = bcmasp_get_rxnfc, .set_rxnfc = bcmasp_set_rxnfc, + .set_eee = bcmasp_set_eee, + .get_eee = bcmasp_get_eee, }; diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index e221f07bf743..2c8a9d5711de 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -653,6 +653,9 @@ static void bcmasp_adj_link(struct net_device *dev) UMC_CMD_TX_PAUSE_IGNORE); reg |= cmd_bits; umac_wl(intf, reg, UMC_CMD); + + intf->eee.eee_active = phy_init_eee(phydev, 0) >= 0; + bcmasp_eee_enable_set(intf, intf->eee.eee_active); } reg = rgmii_rl(intf, RGMII_OOB_CNTRL); @@ -1403,6 +1406,9 @@ int bcmasp_interface_resume(struct bcmasp_intf *intf) bcmasp_resume_from_wol(intf); + if (intf->eee.eee_enabled) + bcmasp_eee_enable_set(intf, true); + netif_device_attach(dev); return 0;