From patchwork Wed Jun 14 22:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13280507 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 98F8F22D7E for ; Wed, 14 Jun 2023 22:30:53 +0000 (UTC) Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF10C271C for ; Wed, 14 Jun 2023 15:30:44 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-3f9b7345fb1so24009751cf.1 for ; Wed, 14 Jun 2023 15:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686781844; x=1689373844; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=uR/uJ0WR6HE3cx4VxS9ApSAuwM+2CPIMoEtzSjwc3G4=; b=ckP+Q6+Hj9cbI5n5ooce+ePhYy+XB7MnsDXfRG04Fmu8FCQ7KZCElehX0DRkSARUQj B4ZWopfpmKE9plchIaizdfJxVGgYd87IUyGmnstf3xFWWJMGUe4Nv0YWUBSqViUACQ0G /6mn0Vf538wt5zP6co9EkUElChO5VWZjd8ktQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686781844; x=1689373844; 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=uR/uJ0WR6HE3cx4VxS9ApSAuwM+2CPIMoEtzSjwc3G4=; b=Vn3IUPXfK623fymL9KKJft2hePz3sXMgfnhGj4RRnK0dYwBwI2cDbN9tUB/wBzDs2N mTgBpEF8TIQoOGzoTFYUUrsBi8HKYLmnzxaDVw64aGRoAX9eOXlWz7rHS9SR/VEQFWLW sTlTtFPO00pQC085UPh7c16U6LUR7NeVclrhGGk5UPkqmFQnP4QD0nLgeR9abAQREtjK l3ppFjjx/pnqaDWqQBH+OifwpCDrZurgGqofhGDBgdxIgO/HpXCIqO27Ww2ImijRmIt9 whz4MBC5y0o22xjXDU8LA+NRdSHG/C+VJbf1DvMpXhTagJ1ALTAyEy6DeMjx8y6aknxz v62g== X-Gm-Message-State: AC+VfDyNbiMezxV9EycJrsn5o0IkwbdBmREev8OaZGk0naKfva9ps1bW 0TAZAfob9sntvnzeY7YjXnQTCbwyV6WrytPhkNUekd7193EnUonFib34yYH6UTa4qKvzFp8YrIg ds4k6l8hniMNaCee0kVBnyU9YOl0VFEo+tra38jBPo2/pOjDglv1LvPbrJ31qloRWUfoUUK3PmL Fq/TKXqw== X-Google-Smtp-Source: ACHHUZ7SV75GkLw3wtTEZBl/RZmbx73Xslg4Ndnbxmq0XugPQHqeKusZWpsY7uDrLA0odOe4MP80OQ== X-Received: by 2002:a05:622a:289:b0:3dc:fa58:97fd with SMTP id z9-20020a05622a028900b003dcfa5897fdmr4198619qtw.25.1686781843770; Wed, 14 Jun 2023 15:30:43 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id d3-20020ac85443000000b003ef2db16e72sm5419360qtq.94.2023.06.14.15.30.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jun 2023 15:30: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 v7 06/11] net: bcmasp: Add support for eee mode Date: Wed, 14 Jun 2023 15:30:15 -0700 Message-Id: <1686781820-832-7-git-send-email-justin.chen@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1686781820-832-1-git-send-email-justin.chen@broadcom.com> References: <1686781820-832-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 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-Patchwork-Delegate: kuba@kernel.org 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 521c9b4b7288..7dc597658ed7 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 0c59f4025965..899cb06a3fde 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -656,6 +656,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); @@ -1407,6 +1410,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;