From patchwork Thu Jul 13 22:19:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 120130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2125926vqm; Thu, 13 Jul 2023 15:26:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlEUasV+laDNDSCyaMeWye2IJ+xE5gylpyDwXrsHmi1luH0gH+yFpRfQM/LfX4Toi1fH8TIs X-Received: by 2002:a05:6512:210f:b0:4f9:8c08:57db with SMTP id q15-20020a056512210f00b004f98c0857dbmr2365376lfr.58.1689287199722; Thu, 13 Jul 2023 15:26:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689287199; cv=none; d=google.com; s=arc-20160816; b=B2n+PRo/eT88QM5XhjsptAXFwU5pvBytcn6V07Lc9ERUqNnx6HIKt68ONFYDxJdG3Y LArqCKtGOAbscQ7vJlbJEyE04LqhEFLV8qXNDDkAOnCWdlMox5Fw1EzQ4pDyeIHnFIOl ydZ6W6ZT4X1x85/ymKQg2r24fmEHjvpLGJKApYI3HmYDX7bmlLxjPF8v5SsFd+e2cZDy UZzR4utNGiUvkjRcR/wIrELRN0gFhFNS6B+g0Tpgl4O+3vjKuSZCiAWFtgBjiW+VBjZd txZGtEa1A4Qykae2VpAeoarJ/zgsG61g58PuiNovWEIoVL2UV1213AUt2B2jzSQrSc1S IgfQ== 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=6il9Bf6X04K4XYhxvSsbkJIi2bojbSPSBB2Yiiz7Zjw=; fh=auIu3uj+2hbF0lD5w/46TjOR2iYLfsn3CHYsSny1RMQ=; b=Eeud9Z2xZ5iqaZ4i3qpWHtunoG0JE/DE/bEU9BcpCyJEQALWTjia8WAlpQDxS02yLz mioJ4YCoUWcSG5vTGcfjMfvb0dU62i8VMf3CD4hACyogdEW/x26NkefaGoGzu3WP4irE Ir9zHiILEARrrHZoo53lC40Amy6hDvuDHInoCzU2bV8oQVhAunE9JRvhnPEzA3A+u8Mf rrZCeTIZyePUfkRwJJTsm4aasSkQPG3qmYTPpLs/logySaY1O7kc4+RO4iLcl3xOSgQ0 1CuL7XS3WhqjgrARRTh3FWvRQjx614IVilS3LrtRLx/lMQJLm80ljnufLAM+i06pQrGF Ze+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ZjNSLo5x; 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 a22-20020aa7cf16000000b0051bf8f889dbsi7598799edy.448.2023.07.13.15.26.15; Thu, 13 Jul 2023 15:26:39 -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=ZjNSLo5x; 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 S233676AbjGMWT7 (ORCPT + 99 others); Thu, 13 Jul 2023 18:19:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233832AbjGMWTt (ORCPT ); Thu, 13 Jul 2023 18:19:49 -0400 Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64FFD30F2 for ; Thu, 13 Jul 2023 15:19:30 -0700 (PDT) Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-7659cb9c42aso110178285a.3 for ; Thu, 13 Jul 2023 15:19:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1689286769; x=1691878769; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=6il9Bf6X04K4XYhxvSsbkJIi2bojbSPSBB2Yiiz7Zjw=; b=ZjNSLo5xDnLlTzteuY4IKZzKyFRJWH8R7Vn1/4/eWZOZgxbU7nhlNpqU9j43NIKiq+ l1Gy4IuGX4LUrTCGRWjrrWTUhREJcNEEtVlBr3Rqulif/3X4atHbBUVdHdQ6ZimMXWEp Wy9qh7Jh8ANKYka0j6k7+U1xd2MHgnJgZQpjU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689286769; x=1691878769; 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=6il9Bf6X04K4XYhxvSsbkJIi2bojbSPSBB2Yiiz7Zjw=; b=d20couDj8Wm7fdjivRnh8fHMVOX6grKD0/jrADPvC0AL0GthoJYAlrgHefIN1o/FIF fPGf5yknVoLuF1/kBGSneag+PJTfOcaeRsGzFGg3WZoHs1Ax2khnDuVloJRiuRotsodv U4bZnQQMNHKsyH2WwHMyEIgYZdPP4cUknquZBVl67YLkEc/qi6OTze5pAU812NMILSoJ QPUlSP0XVRpIRWCrYLLcdeaxVkh53GXQ01jncPIpQYZ40hZba0KU8NBJgwqxTbLGelHV McL2DALNE74syJ6qlUOzLG1raWXDsuvV+BNo92sCmjwxZ+EwiDKPiR0LEHBu6zRbLN3X HeSA== X-Gm-Message-State: ABy/qLbPR3Xx5PZOrlbPw5sZrufL41wabdp4Hzm055/bDcSWs3AOI1eB 1jDAScDTQtJ7GOgonxnCHN7gww== X-Received: by 2002:a0c:f0d2:0:b0:636:2fa5:fd78 with SMTP id d18-20020a0cf0d2000000b006362fa5fd78mr2619548qvl.30.1689286768888; Thu, 13 Jul 2023 15:19:28 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id i14-20020a0cf38e000000b006262de12a8csm427623qvk.65.2023.07.13.15.19.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2023 15:19:28 -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, simon.horman@corigine.com, christian.koenig@amd.com, Justin Chen Subject: [net-next v9 06/11] net: bcmasp: Add support for eee mode Date: Thu, 13 Jul 2023 15:19:01 -0700 Message-Id: <1689286746-43609-7-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1689286746-43609-1-git-send-email-justin.chen@broadcom.com> References: <1689286746-43609-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 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: INBOX X-GMAIL-THRID: 1771346014520744715 X-GMAIL-MSGID: 1771346014520744715 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 fbbde04a0eab..18a44044ad93 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.h +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.h @@ -315,6 +315,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 @@ -558,4 +560,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 ad8422334f38..051f882b2766 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -646,6 +646,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); @@ -1387,6 +1390,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;