From patchwork Tue Feb 14 09:03:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139712 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 037A0C64EC7 for ; Tue, 14 Feb 2023 09:03:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231961AbjBNJDj (ORCPT ); Tue, 14 Feb 2023 04:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BACE1CDE8 for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004UF-JK; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDl-Em; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V5e-G2; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 1/7] net: phy: add driver specific get/set_eee support Date: Tue, 14 Feb 2023 10:03:08 +0100 Message-Id: <20230214090314.2026067-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Not all PHYs can be handled by generic phy_ethtool_get/set_eee() functions. So, add driver specific get/set_eee support. Signed-off-by: Oleksij Rempel --- drivers/net/phy/phy.c | 6 ++++++ include/linux/phy.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 2f1041a7211e..c42df62df302 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1520,6 +1520,9 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data) if (!phydev->drv) return -EIO; + if (phydev->drv->get_eee) + return phydev->drv->get_eee(phydev, data); + return genphy_c45_ethtool_get_eee(phydev, data); } EXPORT_SYMBOL(phy_ethtool_get_eee); @@ -1536,6 +1539,9 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) if (!phydev->drv) return -EIO; + if (phydev->drv->set_eee) + return phydev->drv->set_eee(phydev, data); + return genphy_c45_ethtool_set_eee(phydev, data); } EXPORT_SYMBOL(phy_ethtool_set_eee); diff --git a/include/linux/phy.h b/include/linux/phy.h index 727bff531a14..6709fbd72e10 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1052,6 +1052,11 @@ struct phy_driver { /** @get_plca_status: Return the current PLCA status info */ int (*get_plca_status)(struct phy_device *dev, struct phy_plca_status *plca_st); + + /** @get_eee: Return the current EEE configuration */ + int (*get_eee)(struct phy_device *phydev, struct ethtool_eee *e); + /** @set_eee: Set the EEE configuration */ + int (*set_eee)(struct phy_device *phydev, struct ethtool_eee *e); }; #define to_phy_driver(d) container_of(to_mdio_common_driver(d), \ struct phy_driver, mdiodrv) From patchwork Tue Feb 14 09:03:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139713 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C630C05027 for ; Tue, 14 Feb 2023 09:03:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231722AbjBNJDj (ORCPT ); Tue, 14 Feb 2023 04:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231714AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE7E768B for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004U4-JS; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDX-004qDW-Oe; Tue, 14 Feb 2023 10:03:16 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V5n-Gq; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 2/7] net: phy: at803x: implement ethtool access to SmartEEE functionality Date: Tue, 14 Feb 2023 10:03:09 +0100 Message-Id: <20230214090314.2026067-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If AR8035 PHY is used with a MAC without EEE support (iMX6, etc), then we need to process ethtool_eee::tx_lpi_timer and tx_lpi_enabled by the PHY driver. So, add get/set_eee support for this functionality. Signed-off-by: Oleksij Rempel --- drivers/net/phy/at803x.c | 109 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 22f4458274aa..9eb4439b0afc 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -166,8 +166,18 @@ #define AT803X_MMD3_SMARTEEE_CTL1 0x805b #define AT803X_MMD3_SMARTEEE_CTL2 0x805c +#define AT803X_MMD3_SMARTEEE_LPI_TIME_LOW GENMASK(15, 0) +#define AT803X_MMD3_SMARTEEE_LPI_TIME_15_0 GENMASK(15, 0) #define AT803X_MMD3_SMARTEEE_CTL3 0x805d #define AT803X_MMD3_SMARTEEE_CTL3_LPI_EN BIT(8) +#define AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH GENMASK(7, 0) +#define AT803X_MMD3_SMARTEEE_LPI_TIME_23_16 GENMASK(23, 16) +/* Tx LPI timer resolution */ +#define AT803X_MMD3_SMARTEEE_LPI_TIME_RESOL_NS 163840 +#define AT803X_MMD3_SMARTEEE_LPI_TIME_MAX_US \ + ((GENMASK(23, 0) * AT803X_MMD3_SMARTEEE_LPI_TIME_RESOL_NS) / \ + NSEC_PER_USEC) +#define AT803X_MMD3_SMARTEEE_LPI_TIME_DEF_US 335544 #define ATH9331_PHY_ID 0x004dd041 #define ATH8030_PHY_ID 0x004dd076 @@ -951,17 +961,26 @@ static int at803x_get_features(struct phy_device *phydev) return 0; } -static int at803x_smarteee_config(struct phy_device *phydev) +static int at803x_smarteee_config(struct phy_device *phydev, bool enable, + u32 tx_lpi_timer_us) { struct at803x_priv *priv = phydev->priv; + u64 tx_lpi_timer_raw; + u64 tx_lpi_timer_ns; u16 mask = 0, val = 0; int ret; - if (priv->flags & AT803X_DISABLE_SMARTEEE) + if (priv->flags & AT803X_DISABLE_SMARTEEE || !enable) return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, 0); + if (tx_lpi_timer_us > AT803X_MMD3_SMARTEEE_LPI_TIME_MAX_US) { + phydev_err(phydev, "Max LPI timer is %lu microsecs\n", + AT803X_MMD3_SMARTEEE_LPI_TIME_MAX_US); + return -EINVAL; + } + if (priv->smarteee_lpi_tw_1g) { mask |= 0xff00; val |= priv->smarteee_lpi_tw_1g << 8; @@ -978,9 +997,27 @@ static int at803x_smarteee_config(struct phy_device *phydev) if (ret) return ret; + tx_lpi_timer_ns = tx_lpi_timer_us * NSEC_PER_USEC; + tx_lpi_timer_raw = + DIV_ROUND_CLOSEST_ULL(tx_lpi_timer_ns, + AT803X_MMD3_SMARTEEE_LPI_TIME_RESOL_NS); + val = FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_LOW, + FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_15_0, + tx_lpi_timer_raw)); + + ret = phy_write_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL2, + val); + if (ret) + return ret; + + val = AT803X_MMD3_SMARTEEE_CTL3_LPI_EN | + FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH, + FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_23_16, + tx_lpi_timer_raw)); + return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, - AT803X_MMD3_SMARTEEE_CTL3_LPI_EN, - AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); + AT803X_MMD3_SMARTEEE_CTL3_LPI_EN | + AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH, val); } static int at803x_clk_out_config(struct phy_device *phydev) @@ -1067,7 +1104,8 @@ static int at803x_config_init(struct phy_device *phydev) if (ret < 0) return ret; - ret = at803x_smarteee_config(phydev); + ret = at803x_smarteee_config(phydev, true, + AT803X_MMD3_SMARTEEE_LPI_TIME_DEF_US); if (ret < 0) return ret; @@ -1612,6 +1650,65 @@ static int at803x_cable_test_start(struct phy_device *phydev) return 0; } +static int at803x_get_eee(struct phy_device *phydev, struct ethtool_eee *data) +{ + struct at803x_priv *priv = phydev->priv; + u32 tx_timer_raw; + u64 tx_timer_ns; + int ret; + + /* If SmartEEE is not enabled, it is expected that tx_lpi_* fields + * are processed by the MAC driver. + */ + if (priv->flags & AT803X_DISABLE_SMARTEEE) + return genphy_c45_ethtool_get_eee(phydev, data); + + ret = phy_read_mmd(phydev, MDIO_MMD_PCS, + AT803X_MMD3_SMARTEEE_CTL2); + tx_timer_raw = FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_15_0, + FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_LOW, + ret)); + if (ret < 0) + return ret; + + ret = phy_read_mmd(phydev, MDIO_MMD_PCS, + AT803X_MMD3_SMARTEEE_CTL3); + if (ret < 0) + return ret; + + tx_timer_raw |= FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_23_16, + FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH, + ret)); + tx_timer_ns = tx_timer_raw * AT803X_MMD3_SMARTEEE_LPI_TIME_RESOL_NS; + data->tx_lpi_timer = DIV_ROUND_CLOSEST_ULL(tx_timer_ns, NSEC_PER_USEC); + + data->tx_lpi_enabled = !!(ret & AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); + + return genphy_c45_ethtool_get_eee(phydev, data); +} + +static int at803x_set_eee(struct phy_device *phydev, struct ethtool_eee *data) +{ + struct at803x_priv *priv = phydev->priv; + int ret; + + /* If SmartEEE is not enabled, it is expected that tx_lpi_* fields + * are processed by the MAC driver. + */ + if (priv->flags & AT803X_DISABLE_SMARTEEE) + return genphy_c45_ethtool_set_eee(phydev, data); + + /* Changing Tx LPI on/off or Tx LPI timer settings + * do not require link reset. + */ + ret = at803x_smarteee_config(phydev, data->tx_lpi_enabled, + data->tx_lpi_timer); + if (ret) + return ret; + + return genphy_c45_ethtool_set_eee(phydev, data); +} + static int qca83xx_config_init(struct phy_device *phydev) { u8 switch_revision; @@ -2038,6 +2135,8 @@ static struct phy_driver at803x_driver[] = { .set_tunable = at803x_set_tunable, .cable_test_start = at803x_cable_test_start, .cable_test_get_status = at803x_cable_test_get_status, + .get_eee = at803x_get_eee, + .set_eee = at803x_set_eee, }, { /* Qualcomm Atheros AR8030 */ .phy_id = ATH8030_PHY_ID, From patchwork Tue Feb 14 09:03:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139714 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85FAEC61DA4 for ; Tue, 14 Feb 2023 09:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232207AbjBNJDm (ORCPT ); Tue, 14 Feb 2023 04:03:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231745AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6DE0CDDF for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004UJ-JU; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDr-Ki; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V5w-HY; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 3/7] net: phy: at803x: ar8035: fix EEE support for half duplex links Date: Tue, 14 Feb 2023 10:03:10 +0100 Message-Id: <20230214090314.2026067-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org If AR8035 is running with enabled EEE and LPI, it will not be able to establish an 100BaseTX/Half or 1000BaseT/Half link. Similar issue we will have with 100BaseTX/Full and LPI TX timer configured to less then 80msec. To avoid this issue, we need to keep LPI disabled before link is establish and enable it only we detected supported link configuration. Signed-off-by: Oleksij Rempel --- drivers/net/phy/at803x.c | 41 +++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 9eb4439b0afc..5ab43eb63581 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -313,6 +313,7 @@ struct at803x_priv { u8 smarteee_lpi_tw_100m; bool is_fiber; bool is_1000basex; + bool tx_lpi_on; struct regulator_dev *vddio_rdev; struct regulator_dev *vddh_rdev; struct regulator *vddio; @@ -970,6 +971,8 @@ static int at803x_smarteee_config(struct phy_device *phydev, bool enable, u16 mask = 0, val = 0; int ret; + priv->tx_lpi_on = enable; + if (priv->flags & AT803X_DISABLE_SMARTEEE || !enable) return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, @@ -1010,10 +1013,15 @@ static int at803x_smarteee_config(struct phy_device *phydev, bool enable, if (ret) return ret; - val = AT803X_MMD3_SMARTEEE_CTL3_LPI_EN | - FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH, - FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_23_16, - tx_lpi_timer_raw)); + val = FIELD_PREP(AT803X_MMD3_SMARTEEE_LPI_TIME_HIGH, + FIELD_GET(AT803X_MMD3_SMARTEEE_LPI_TIME_23_16, + tx_lpi_timer_raw)); + + if (phydev->state == PHY_RUNNING && + phy_check_valid(phydev->speed, phydev->duplex, + phydev->supported_eee)) { + val |= AT803X_MMD3_SMARTEEE_CTL3_LPI_EN; + } return phy_modify_mmd(phydev, MDIO_MMD_PCS, AT803X_MMD3_SMARTEEE_CTL3, AT803X_MMD3_SMARTEEE_CTL3_LPI_EN | @@ -1682,7 +1690,7 @@ static int at803x_get_eee(struct phy_device *phydev, struct ethtool_eee *data) tx_timer_ns = tx_timer_raw * AT803X_MMD3_SMARTEEE_LPI_TIME_RESOL_NS; data->tx_lpi_timer = DIV_ROUND_CLOSEST_ULL(tx_timer_ns, NSEC_PER_USEC); - data->tx_lpi_enabled = !!(ret & AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); + data->tx_lpi_enabled = priv->tx_lpi_on; return genphy_c45_ethtool_get_eee(phydev, data); } @@ -1709,6 +1717,28 @@ static int at803x_set_eee(struct phy_device *phydev, struct ethtool_eee *data) return genphy_c45_ethtool_set_eee(phydev, data); } +static void at8035_link_change_notify(struct phy_device *phydev) +{ + struct at803x_priv *priv = phydev->priv; + + if (priv->flags & AT803X_DISABLE_SMARTEEE) + return; + + if (phydev->state == PHY_RUNNING) { + if (priv->tx_lpi_on && phy_check_valid(phydev->speed, + phydev->duplex, + phydev->supported_eee)) + phy_set_bits_mmd(phydev, MDIO_MMD_PCS, + AT803X_MMD3_SMARTEEE_CTL3, + AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); + } else { + if (priv->tx_lpi_on) + phy_clear_bits_mmd(phydev, MDIO_MMD_PCS, + AT803X_MMD3_SMARTEEE_CTL3, + AT803X_MMD3_SMARTEEE_CTL3_LPI_EN); + } +} + static int qca83xx_config_init(struct phy_device *phydev) { u8 switch_revision; @@ -2137,6 +2167,7 @@ static struct phy_driver at803x_driver[] = { .cable_test_get_status = at803x_cable_test_get_status, .get_eee = at803x_get_eee, .set_eee = at803x_set_eee, + .link_change_notify = at8035_link_change_notify, }, { /* Qualcomm Atheros AR8030 */ .phy_id = ATH8030_PHY_ID, From patchwork Tue Feb 14 09:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139710 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEBF3C61DA4 for ; Tue, 14 Feb 2023 09:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231919AbjBNJDe (ORCPT ); Tue, 14 Feb 2023 04:03:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231599AbjBNJDb (ORCPT ); Tue, 14 Feb 2023 04:03:31 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DA9B469D for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004UA-JP; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDa-4d; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V65-IB; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 4/7] net: phy: add PHY specifica flag to signal SmartEEE support Date: Tue, 14 Feb 2023 10:03:11 +0100 Message-Id: <20230214090314.2026067-5-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Typical EEE support need cooperation of MAC and PHY, so both parts should be able to do EEE. But, there also PHYs compatible with normal 802.3az standard working with legacy MAC without EEE ability, acting as a complete EEE power saving system. To identify this PHYs we need a PHY specific flag. Since the PHY specification implementing this functionality calls it SmartEEE, use the same flag name - PHY_SMART_EEE. Signed-off-by: Oleksij Rempel --- include/linux/phy.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index 6709fbd72e10..e6b12653c655 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -85,6 +85,7 @@ extern const int phy_10gbit_features_array[1]; #define PHY_IS_INTERNAL 0x00000001 #define PHY_RST_AFTER_CLK_EN 0x00000002 #define PHY_POLL_CABLE_TEST 0x00000004 +#define PHY_SMART_EEE 0x00000008 /* EEE done by PHY without MAC */ #define MDIO_DEVICE_IS_PHY 0x80000000 /** From patchwork Tue Feb 14 09:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139715 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 003C4C6379F for ; Tue, 14 Feb 2023 09:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232004AbjBNJDo (ORCPT ); Tue, 14 Feb 2023 04:03:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231715AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5450CDDE for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004U8-JR; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDZ-3Y; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V6E-Ik; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 5/7] net: phy: at803x: add PHY_SMART_EEE flag to AR8035 Date: Tue, 14 Feb 2023 10:03:12 +0100 Message-Id: <20230214090314.2026067-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org AR8035 is one of the PHYs with SmartEEE functionality. This flag will be used by one of next patches on the i.MX FEC driver. Signed-off-by: Oleksij Rempel --- drivers/net/phy/at803x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/at803x.c b/drivers/net/phy/at803x.c index 5ab43eb63581..94dbec0a992c 100644 --- a/drivers/net/phy/at803x.c +++ b/drivers/net/phy/at803x.c @@ -2147,7 +2147,7 @@ static struct phy_driver at803x_driver[] = { /* Qualcomm Atheros AR8035 */ PHY_ID_MATCH_EXACT(ATH8035_PHY_ID), .name = "Qualcomm Atheros AR8035", - .flags = PHY_POLL_CABLE_TEST, + .flags = PHY_POLL_CABLE_TEST | PHY_SMART_EEE, .probe = at803x_probe, .remove = at803x_remove, .config_aneg = at803x_config_aneg, From patchwork Tue Feb 14 09:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139716 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAED3C05027 for ; Tue, 14 Feb 2023 09:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbjBNJDp (ORCPT ); Tue, 14 Feb 2023 04:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31E4ADBD1 for ; Tue, 14 Feb 2023 01:03:31 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004UD-JO; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDh-CX; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V6N-JJ; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 6/7] net: phy: add phy_has_smarteee() helper Date: Tue, 14 Feb 2023 10:03:13 +0100 Message-Id: <20230214090314.2026067-7-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add helper to identify PHYs with SmartEEE support. Signed-off-by: Oleksij Rempel --- include/linux/phy.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/phy.h b/include/linux/phy.h index e6b12653c655..2e726450d3c3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1408,6 +1408,15 @@ static inline bool phy_polling_mode(struct phy_device *phydev) return phydev->irq == PHY_POLL; } +/** + * phy_has_smarteee - Tests whether a PHY supports SmartEEE. + * @phydev: the phy_device struct + */ +static inline bool phy_has_smarteee(struct phy_device *phydev) +{ + return phydev && phydev->drv && !!(phydev->drv->flags & PHY_SMART_EEE); +} + /** * phy_has_hwtstamp - Tests whether a PHY time stamp configuration. * @phydev: the phy_device struct From patchwork Tue Feb 14 09:03:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 13139711 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E81FC6379F for ; Tue, 14 Feb 2023 09:03:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230193AbjBNJDh (ORCPT ); Tue, 14 Feb 2023 04:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231697AbjBNJDc (ORCPT ); Tue, 14 Feb 2023 04:03:32 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14D0CDCD for ; Tue, 14 Feb 2023 01:03:30 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pRrDa-0004UG-JN; Tue, 14 Feb 2023 10:03:18 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1pRrDY-004qDm-G1; Tue, 14 Feb 2023 10:03:17 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1pRrDX-008V6W-Js; Tue, 14 Feb 2023 10:03:15 +0100 From: Oleksij Rempel To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Wei Fang , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v1 7/7] net: fec: add support for PHYs with SmartEEE support Date: Tue, 14 Feb 2023 10:03:14 +0100 Message-Id: <20230214090314.2026067-8-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230214090314.2026067-1-o.rempel@pengutronix.de> References: <20230214090314.2026067-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Ethernet controller in i.MX6*/i.MX7* series do not provide EEE support. But this chips are used sometimes in combinations with SmartEEE capable PHYs. So, instead of aborting get/set_eee access on MACs without EEE support, ask PHY if it is able to do the EEE job by using SmartEEE. Signed-off-by: Oleksij Rempel --- drivers/net/ethernet/freescale/fec_main.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index c73e25f8995e..00f3703db69d 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3102,8 +3102,15 @@ fec_enet_get_eee(struct net_device *ndev, struct ethtool_eee *edata) struct fec_enet_private *fep = netdev_priv(ndev); struct ethtool_eee *p = &fep->eee; - if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) - return -EOPNOTSUPP; + if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) { + if (!netif_running(ndev)) + return -ENETDOWN; + + if (!phy_has_smarteee(ndev->phydev)) + return -EOPNOTSUPP; + + return phy_ethtool_get_eee(ndev->phydev, edata); + } if (!netif_running(ndev)) return -ENETDOWN; @@ -3123,8 +3130,15 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_eee *edata) struct ethtool_eee *p = &fep->eee; int ret = 0; - if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) - return -EOPNOTSUPP; + if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) { + if (!netif_running(ndev)) + return -ENETDOWN; + + if (!phy_has_smarteee(ndev->phydev)) + return -EOPNOTSUPP; + + return phy_ethtool_set_eee(ndev->phydev, edata); + } if (!netif_running(ndev)) return -ENETDOWN;