From patchwork Fri Mar 31 00:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195121 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 64844C7619A for ; Fri, 31 Mar 2023 00:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229897AbjCaAz4 (ORCPT ); Thu, 30 Mar 2023 20:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA5AC1041F for ; Thu, 30 Mar 2023 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=ywMkoH6yiyWWuEZTTgl8DXNHkG9cJErCqcID5K7/eHA=; b=EsDnkXOMeTKF4Xhf08ngMmK3D3 bagmmT3RL3bqVOcq2OmmLFW6TNQ83MS13bENwkY6kc4fL9O6woKHy4gCNHicd72MbKfqG00Q03VR1 4NxRZOrERCFegJW6kZSszd7xfNGZrYpXJUgNcFu6lTxWi8c+PYcNe1nIeKsFahL0G6R4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xK9-As; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 01/24] net: phy: Add phydev->eee_active to simplify adjust link callbacks Date: Fri, 31 Mar 2023 02:54:55 +0200 Message-Id: <20230331005518.2134652-2-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC MAC drivers which support EEE need to know the results of the EEE auto-neg in order to program the hardware to perform EEE or not. The oddly named phy_init_eee() can be used to determine this, it returns 0 if EEE should be used, or a negative error code, e.g. -EOPPROTONOTSUPPORT if the PHY does not support EEE or negotiate resulted in it not being used. However, many MAC drivers get this wrong. Add phydev->eee_active which indicates the result of the autoneg for EEE, including if EEE is administratively disabled with ethtool. The MAC driver can then access this in the same way as link speed and duplex in the adjust link callback. Reviewed-by: Russell King (Oracle) Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- v2 Check for errors from genphy_c45_eee_is_active v3 Refactor into helper which can be used in a later patch --- drivers/net/phy/phy.c | 21 +++++++++++++++++++++ include/linux/phy.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 0c0df38cd1ab..150df69d9e08 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -902,6 +902,25 @@ int phy_config_aneg(struct phy_device *phydev) } EXPORT_SYMBOL(phy_config_aneg); +/** + * phy_update_eee_active - Update phydev->eee_active statue + * @phydev: the phy_device struct + * + * Description: Read from the PHY is EEE is active. Use the + * information to set eee_active in phydev, which the MAC can then use + * to enable EEE in the MAC. + */ +static void phy_update_eee_active(struct phy_device *phydev) +{ + int err; + + err = genphy_c45_eee_is_active(phydev, NULL, NULL, NULL); + if (err < 0) + phydev->eee_active = false; + else + phydev->eee_active = err; +} + /** * phy_check_link_status - check link status and set state accordingly * @phydev: the phy_device struct @@ -928,9 +947,11 @@ static int phy_check_link_status(struct phy_device *phydev) if (phydev->link && phydev->state != PHY_RUNNING) { phy_check_downshift(phydev); phydev->state = PHY_RUNNING; + phy_update_eee_active(phydev); phy_link_up(phydev); } else if (!phydev->link && phydev->state != PHY_NOLINK) { phydev->state = PHY_NOLINK; + phydev->eee_active = false; phy_link_down(phydev); } diff --git a/include/linux/phy.h b/include/linux/phy.h index fefd5091bc24..5cc2dcb17eb0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -577,6 +577,7 @@ struct macsec_ops; * @supported_eee: supported PHY EEE linkmodes * @advertising_eee: Currently advertised EEE linkmodes * @eee_enabled: Flag indicating whether the EEE feature is enabled + * @eee_active: EEE is active for the current link mode * @lp_advertising: Current link partner advertised linkmodes * @host_interfaces: PHY interface modes supported by host * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited @@ -691,6 +692,7 @@ struct phy_device { /* Energy efficient ethernet modes which should be prohibited */ u32 eee_broken_modes; + bool eee_active; #ifdef CONFIG_LED_TRIGGER_PHY struct phy_led_trigger *phy_led_triggers; From patchwork Fri Mar 31 00:54:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195138 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 D24BAC7619A for ; Fri, 31 Mar 2023 00:56:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229889AbjCaA4U (ORCPT ); Thu, 30 Mar 2023 20:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbjCaAzt (ORCPT ); Thu, 30 Mar 2023 20:55:49 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36208EFAC for ; Thu, 30 Mar 2023 17:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=5ELgqnZXVrcsJD/qHvyCDs5uJ943tNeY5adKWh8hAjA=; b=tRnldfm5if9cdraXV98qQaUeBr ILFaCnIwWZB8+OcE9pUqKqzg0dkMPk51ZjFLdLsqLzspWBG/YdyvEZX7G28c42dRJNihk6R0eW75D aJUPykLXBq2WBdb1N739dJHvGJRF941DoURL7EJK8p4ow8t231U0LiN8DgWcICsg0A3M=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKD-Bv; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 02/24] net: phylink: Add mac_set_eee() callback Date: Fri, 31 Mar 2023 02:54:56 +0200 Message-Id: <20230331005518.2134652-3-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC MAC drivers need to know the result of the auto negotiation of Energy Efficient Ethernet. This is a simple boolean, it should be active or not in the MAC. Add an additional callback to pass this information to the MAC. Currently the correct value should be passed, however no MAC drivers have been modified to actually use it. Yet. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy-core.c | 11 +++++++++++ drivers/net/phy/phylink.c | 16 ++++++++++++++-- include/linux/phy.h | 1 + include/linux/phylink.h | 22 +++++++++++++++++++--- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index a64186dc53f8..666b3b9b6f4d 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -76,6 +76,17 @@ const char *phy_duplex_to_str(unsigned int duplex) } EXPORT_SYMBOL_GPL(phy_duplex_to_str); +/** + * phy_eee_active_to_str - Return string describing eee_active + * + * @eee_active: EEE active setting to describe + */ +const char *phy_eee_active_to_str(bool eee_active) +{ + return eee_active ? "EEE Active" : "EEE Inactive"; +} +EXPORT_SYMBOL_GPL(phy_eee_active_to_str); + /** * phy_rate_matching_to_str - Return a string describing the rate matching * diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index f7da96f0c75b..453f80544792 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1142,6 +1142,7 @@ static void phylink_mac_pcs_get_state(struct phylink *pl, state->speed = SPEED_UNKNOWN; state->duplex = DUPLEX_UNKNOWN; state->pause = MLO_PAUSE_NONE; + state->eee_active = false; } else { state->speed = pl->link_config.speed; state->duplex = pl->link_config.duplex; @@ -1223,10 +1224,12 @@ static void phylink_link_up(struct phylink *pl, struct net_device *ndev = pl->netdev; int speed, duplex; bool rx_pause; + bool eee_active; speed = link_state.speed; duplex = link_state.duplex; rx_pause = !!(link_state.pause & MLO_PAUSE_RX); + eee_active = link_state.eee_active; switch (link_state.rate_matching) { case RATE_MATCH_PAUSE: @@ -1259,6 +1262,9 @@ static void phylink_link_up(struct phylink *pl, pl->cur_interface, speed, duplex, !!(link_state.pause & MLO_PAUSE_TX), rx_pause); + if (pl->phydev && pl->mac_ops->mac_set_eee) + pl->mac_ops->mac_set_eee(pl->config, eee_active); + if (ndev) netif_carrier_on(ndev); @@ -1529,6 +1535,7 @@ struct phylink *phylink_create(struct phylink_config *config, pl->link_config.pause = MLO_PAUSE_AN; pl->link_config.speed = SPEED_UNKNOWN; pl->link_config.duplex = DUPLEX_UNKNOWN; + pl->link_config.eee_active = false; pl->mac_ops = mac_ops; __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); timer_setup(&pl->link_poll, phylink_fixed_poll, 0); @@ -1593,6 +1600,7 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) mutex_lock(&pl->state_mutex); pl->phy_state.speed = phydev->speed; pl->phy_state.duplex = phydev->duplex; + pl->phy_state.eee_active = phydev->eee_active; pl->phy_state.rate_matching = phydev->rate_matching; pl->phy_state.pause = MLO_PAUSE_NONE; if (tx_pause) @@ -1605,12 +1613,13 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) phylink_run_resolve(pl); - phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s\n", up ? "up" : "down", + phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s/%s\n", up ? "up" : "down", phy_modes(phydev->interface), phy_speed_to_str(phydev->speed), phy_duplex_to_str(phydev->duplex), phy_rate_matching_to_str(phydev->rate_matching), - phylink_pause_to_str(pl->phy_state.pause)); + phylink_pause_to_str(pl->phy_state.pause), + phy_eee_active_to_str(phydev->eee_active)); } static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, @@ -1684,6 +1693,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, pl->phy_state.pause = MLO_PAUSE_NONE; pl->phy_state.speed = SPEED_UNKNOWN; pl->phy_state.duplex = DUPLEX_UNKNOWN; + pl->phy_state.eee_active = false; pl->phy_state.rate_matching = RATE_MATCH_NONE; linkmode_copy(pl->supported, supported); linkmode_copy(pl->link_config.advertising, config.advertising); @@ -2929,6 +2939,7 @@ static int phylink_sfp_config_phy(struct phylink *pl, u8 mode, config.interface = PHY_INTERFACE_MODE_NA; config.speed = SPEED_UNKNOWN; config.duplex = DUPLEX_UNKNOWN; + config.eee_active = false; config.pause = MLO_PAUSE_AN; /* Ignore errors if we're expecting a PHY to attach later */ @@ -2997,6 +3008,7 @@ static int phylink_sfp_config_optical(struct phylink *pl) linkmode_copy(config.advertising, pl->sfp_support); config.speed = SPEED_UNKNOWN; config.duplex = DUPLEX_UNKNOWN; + config.eee_active = false; config.pause = MLO_PAUSE_AN; /* For all the interfaces that are supported, reduce the sfp_support diff --git a/include/linux/phy.h b/include/linux/phy.h index 5cc2dcb17eb0..2508f1d99777 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1080,6 +1080,7 @@ struct phy_fixup { const char *phy_speed_to_str(int speed); const char *phy_duplex_to_str(unsigned int duplex); +const char *phy_eee_active_to_str(bool eee_active); const char *phy_rate_matching_to_str(int rate_matching); int phy_interface_num_ports(phy_interface_t interface); diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 9ff56b050584..7b5df55e2467 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -88,6 +88,7 @@ static inline bool phylink_autoneg_inband(unsigned int mode) * @speed: link speed, one of the SPEED_* constants. * @duplex: link duplex mode, one of DUPLEX_* constants. * @pause: link pause state, described by MLO_PAUSE_* constants. + * @eee_active: true if EEE should be active * @rate_matching: rate matching being performed, one of the RATE_MATCH_* * constants. If rate matching is taking place, then the speed/duplex of * the medium link mode (@speed and @duplex) and the speed/duplex of the phy @@ -105,6 +106,7 @@ struct phylink_link_state { int rate_matching; unsigned int link:1; unsigned int an_complete:1; + unsigned int eee_active:1; }; enum phylink_op_type { @@ -152,6 +154,7 @@ struct phylink_config { * @mac_an_restart: restart 802.3z BaseX autonegotiation. * @mac_link_down: take the link down. * @mac_link_up: allow the link to come up. + * @mac_set_eee: enable/disable EEE in the MAC * * The individual methods are described more fully below. */ @@ -176,6 +179,7 @@ struct phylink_mac_ops { struct phy_device *phy, unsigned int mode, phy_interface_t interface, int speed, int duplex, bool tx_pause, bool rx_pause); + void (*mac_set_eee)(struct phylink_config *config, bool eee_active); }; #if 0 /* For kernel-doc purposes only. */ @@ -408,6 +412,7 @@ void mac_link_down(struct phylink_config *config, unsigned int mode, * @duplex: link duplex * @tx_pause: link transmit pause enablement status * @rx_pause: link receive pause enablement status + * @eee_active: EEE should be enabled * * Configure the MAC for an established link. * @@ -421,14 +426,25 @@ void mac_link_down(struct phylink_config *config, unsigned int mode, * that the user wishes to override the pause settings, and this should * be allowed when considering the implementation of this method. * - * If in-band negotiation mode is disabled, allow the link to come up. If - * @phy is non-%NULL, configure Energy Efficient Ethernet by calling - * phy_init_eee() and perform appropriate MAC configuration for EEE. + * If in-band negotiation mode is disabled, allow the link to come up. * Interface type selection must be done in mac_config(). */ void mac_link_up(struct phylink_config *config, struct phy_device *phy, unsigned int mode, phy_interface_t interface, int speed, int duplex, bool tx_pause, bool rx_pause); +/** + * mac_set_eee() - enable/disable EEE in the MAC + * @config: a pointer to a &struct phylink_config. + * + * Enable or disable the MAC performing EEE. + * + * @eee_active indicates if the MAC should enable EEE. This callback + * can be called without the link going down, e.g after calls to + * ethtool_set_eee() which don't require a new auto-negotiation. + * + * This callback is optional. + */ +void mac_set_eee(struct phylink_config *config, bool eee_active); #endif struct phylink_pcs_ops; From patchwork Fri Mar 31 00:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195120 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 9CAC4C6FD1D for ; Fri, 31 Mar 2023 00:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229835AbjCaAzz (ORCPT ); Thu, 30 Mar 2023 20:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229848AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 724521024E for ; Thu, 30 Mar 2023 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=K1Z6RXGT7Cy75Vw4xUJqWStadQH/2oFQYxnNkmPVn5E=; b=14mTYhtJ5v3lGUgn5QOA7xXcRA JdORX9vl0fDOkfaaWylqWhVqEnzR0gU9raqaHN2B1JREXKqxFI65I10eAqRuRiSs/UVK45Hs0Z1I0 8oaKWdczXOk3PzmXLz/ve0S4TGFnB9EGrCfz7JG1K6D6HFhQyBkzsBLKKx0yOUgpvtY8=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKH-DQ; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 03/24] net: phy: Add helper to set EEE Clock stop enable bit Date: Fri, 31 Mar 2023 02:54:57 +0200 Message-Id: <20230331005518.2134652-4-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The MAC driver can request that the PHY stops the clock during EEE LPI. This has normally been does as part of phy_init_eee(), however that function is overly complex and often wrongly used. Add a standalone helper, to aid removing phy_init_eee(). The helper currently calls generic code, but it could in the future call a PHY specific op if a PHY exports different registers to 802.3. Signed-off-by: Andrew Lunn --- v2: Add missing EXPORT_SYMBOL_GPL v3: Move register access into phy-c45.c --- drivers/net/phy/phy-c45.c | 24 ++++++++++++++++++++++++ drivers/net/phy/phy.c | 19 +++++++++++++++++++ include/linux/phy.h | 2 ++ include/uapi/linux/mdio.h | 1 + 4 files changed, 46 insertions(+) diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index fee514b96ab1..29479e142826 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -1386,6 +1386,30 @@ int genphy_c45_eee_is_active(struct phy_device *phydev, unsigned long *adv, } EXPORT_SYMBOL(genphy_c45_eee_is_active); +/** + * genphy_c45_eee_clk_stop_enable - Clock should stop during LPI signalling + * @phydev: target phy_device struct + * + * Description: Program the MMD register 3.0 setting the "Clock stop enable" + * bit. + */ +int genphy_c45_eee_clk_stop_enable(struct phy_device *phydev) +{ + int ret; + + /* IEEE 802.3:2018 - 45.2.3.2.6 Clock stop capable (3.1.6) */ + ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_STAT1); + if (ret < 0) + return ret; + + if (ret & MDIO_STAT1_CLKSTOP_CAPABLE) + /* IEEE 802.3-2018 45.2.3.1.4 Clock stop enable (3.0.10) */ + return phy_set_bits_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, + MDIO_PCS_CTRL1_CLKSTOP_EN); + return 0; +} +EXPORT_SYMBOL_GPL(genphy_c45_eee_clk_stop_enable); + /** * genphy_c45_ethtool_get_eee - get EEE supported and status * @phydev: target phy_device struct diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 150df69d9e08..6fc6a59d2f56 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1573,6 +1573,25 @@ int phy_get_eee_err(struct phy_device *phydev) } EXPORT_SYMBOL(phy_get_eee_err); +/** + * phy_eee_clk_stop_enable - Clock should stop during LIP + * @phydev: target phy_device struct + * + * Description: Program the PHY to stop the clock when EEE is + * signalling LPI + */ +int phy_eee_clk_stop_enable(struct phy_device *phydev) +{ + int ret; + + mutex_lock(&phydev->lock); + ret = genphy_c45_eee_clk_stop_enable(phydev); + mutex_unlock(&phydev->lock); + + return ret; +} +EXPORT_SYMBOL_GPL(phy_eee_clk_stop_enable); + /** * phy_ethtool_get_eee - get EEE supported and status * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index 2508f1d99777..dea707b3189b 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1773,6 +1773,7 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev, int genphy_c45_write_eee_adv(struct phy_device *phydev, unsigned long *adv); int genphy_c45_an_config_eee_aneg(struct phy_device *phydev); int genphy_c45_read_eee_adv(struct phy_device *phydev, unsigned long *adv); +int genphy_c45_eee_clk_stop_enable(struct phy_device *phydev); /* Generic C45 PHY driver */ extern struct phy_driver genphy_c45_driver; @@ -1847,6 +1848,7 @@ int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask); int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable); int phy_get_eee_err(struct phy_device *phydev); +int phy_eee_clk_stop_enable(struct phy_device *phydev); int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data); int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data); int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol); diff --git a/include/uapi/linux/mdio.h b/include/uapi/linux/mdio.h index 256b463e47a6..e810abb1a4d3 100644 --- a/include/uapi/linux/mdio.h +++ b/include/uapi/linux/mdio.h @@ -121,6 +121,7 @@ /* Status register 1. */ #define MDIO_STAT1_LPOWERABLE 0x0002 /* Low-power ability */ #define MDIO_STAT1_LSTATUS BMSR_LSTATUS +#define MDIO_STAT1_CLKSTOP_CAPABLE 0x0040 /* Clock stop capable */ #define MDIO_STAT1_FAULT 0x0080 /* Fault */ #define MDIO_AN_STAT1_LPABLE 0x0001 /* Link partner AN ability */ #define MDIO_AN_STAT1_ABLE BMSR_ANEGCAPABLE From patchwork Fri Mar 31 00:54:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195122 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 6836BC761AF for ; Fri, 31 Mar 2023 00:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbjCaAz5 (ORCPT ); Thu, 30 Mar 2023 20:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B0A310273 for ; Thu, 30 Mar 2023 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=9pL9WRWZ5caPjAv55S5XbcHL/wDTIdZMTxFn18EmnkI=; b=O46YuCX37eXA7p3/xnzUFykoar 50d1aUYR49zVzM5WykvpVhoECzwxibFgItJsZ5tjosXYnwVJI9/mu5tEnVf3UHzU1zvB0aO445u0O cGYoBRbeUsYZam6/0Oa5IUMWm8KNXu9TLj5EcRWSsFQwSo2G9CLJQkpLtVaeTs2xGSsc=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKL-Ep; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 04/24] net: phy: Keep track of EEE tx_lpi_enabled Date: Fri, 31 Mar 2023 02:54:58 +0200 Message-Id: <20230331005518.2134652-5-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Have phylib keep track of the EEE tx_lpi_enabled configuration. This simplifies the MAC drivers, in that they don't need to store it. Future patches to phylib will also make use of this information to further simplify the MAC drivers. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- drivers/net/phy/phy.c | 5 ++++- include/linux/phy.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 6fc6a59d2f56..c7a5d0240211 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1598,7 +1598,7 @@ EXPORT_SYMBOL_GPL(phy_eee_clk_stop_enable); * @data: ethtool_eee data * * Description: it reportes the Supported/Advertisement/LP Advertisement - * capabilities. + * capabilities, etc. */ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data) { @@ -1609,6 +1609,7 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_eee *data) mutex_lock(&phydev->lock); ret = genphy_c45_ethtool_get_eee(phydev, data); + data->tx_lpi_enabled = phydev->tx_lpi_enabled; mutex_unlock(&phydev->lock); return ret; @@ -1631,6 +1632,8 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) mutex_lock(&phydev->lock); ret = genphy_c45_ethtool_set_eee(phydev, data); + if (!ret) + phydev->tx_lpi_enabled = data->tx_lpi_enabled; mutex_unlock(&phydev->lock); return ret; diff --git a/include/linux/phy.h b/include/linux/phy.h index dea707b3189b..4c3d80311c04 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -578,6 +578,7 @@ struct macsec_ops; * @advertising_eee: Currently advertised EEE linkmodes * @eee_enabled: Flag indicating whether the EEE feature is enabled * @eee_active: EEE is active for the current link mode + * @tx_lpi_enabled: EEE should send LPI * @lp_advertising: Current link partner advertised linkmodes * @host_interfaces: PHY interface modes supported by host * @eee_broken_modes: Energy efficient ethernet modes which should be prohibited @@ -693,6 +694,7 @@ struct phy_device { /* Energy efficient ethernet modes which should be prohibited */ u32 eee_broken_modes; bool eee_active; + bool tx_lpi_enabled; #ifdef CONFIG_LED_TRIGGER_PHY struct phy_led_trigger *phy_led_triggers; From patchwork Fri Mar 31 00:54:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195127 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 82134C6FD1D for ; Fri, 31 Mar 2023 00:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjCaA4E (ORCPT ); Thu, 30 Mar 2023 20:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229874AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C941B11144 for ; Thu, 30 Mar 2023 17:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=+533Q/Qe8nG30r/6OVIf8aM4XBgMlYrLzDC4nqWSFLw=; b=id96lhJQ/7IgBbx3a2zfJnZZ1g kXo3OVSKSIXDrIglmggmvhBYTPt/1alWivk2bb3On4Sb3w/89LY/MK+izsc/9ou7rhrKesUJ6Jhuq xyV8LFFbGxIWdtKTsa3xj1ewP50aQH3ReUV2BDNtkGJS+/JEylxFNmtFxdNs+JcLaRek=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKP-Fl; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 05/24] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Date: Fri, 31 Mar 2023 02:54:59 +0200 Message-Id: <20230331005518.2134652-6-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The MAC driver changes its EEE hardware configuration in its adjust_link callback. This is called when auto-neg completes. If set_eee is called with a change to tx_lpi_enabled which does not trigger an auto-neg, it is necessary to call the adjust_link callback so that the MAC is reconfigured to take this change into account. When setting phydev->eee_active, take tx_lpi_enabled into account, so the MAC drivers don't need to consider tx_lpi_enabled. Signed-off-by: Andrew Lunn --- v3: Update phydev->eee_active --- drivers/net/phy/phy-c45.c | 11 ++++++++--- drivers/net/phy/phy.c | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index 29479e142826..a16124668e1d 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -1455,6 +1455,8 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee); * * Description: it reportes the Supported/Advertisement/LP Advertisement * capabilities. + * Returns either error code, 0 if there was no change, or positive if + * there was a change which triggered auto-neg. */ int genphy_c45_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) @@ -1488,9 +1490,12 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev, ret = genphy_c45_an_config_eee_aneg(phydev); if (ret < 0) return ret; - if (ret > 0) - return phy_restart_aneg(phydev); - + if (ret > 0) { + ret = phy_restart_aneg(phydev); + if (ret < 0) + return ret; + return 1; + } return 0; } EXPORT_SYMBOL(genphy_c45_ethtool_set_eee); diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c7a5d0240211..f4da7a5440e3 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -918,7 +918,7 @@ static void phy_update_eee_active(struct phy_device *phydev) if (err < 0) phydev->eee_active = false; else - phydev->eee_active = err; + phydev->eee_active = (err & phydev->tx_lpi_enabled); } /** @@ -1632,11 +1632,21 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data) mutex_lock(&phydev->lock); ret = genphy_c45_ethtool_set_eee(phydev, data); - if (!ret) + if (ret >= 0) { + if (ret == 0) { + /* auto-neg not triggered */ + if (phydev->tx_lpi_enabled != data->tx_lpi_enabled) { + phydev->tx_lpi_enabled = data->tx_lpi_enabled; + phy_update_eee_active(phydev); + if (phydev->link) + phy_link_up(phydev); + } + } phydev->tx_lpi_enabled = data->tx_lpi_enabled; + } mutex_unlock(&phydev->lock); - return ret; + return (ret < 0 ? ret : 0); } EXPORT_SYMBOL(phy_ethtool_set_eee); From patchwork Fri Mar 31 00:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195116 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 04E67C6FD1D for ; Fri, 31 Mar 2023 00:55:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbjCaAzt (ORCPT ); Thu, 30 Mar 2023 20:55:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3901D322 for ; Thu, 30 Mar 2023 17:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=w0Zqeh2lsTq+b7kVuSkMzxzALPtz+WvJtFj2bjWgq38=; b=v0D8COP9DEHFoHWl3EbQ9qiqUX 2I+YfeQj64xRJ9UADj2rzyzKvNjXKoTffW2Ny6Gz0EeEQ/RoMXMOIyW/wF+qNnRqy0C8C1+jef1zn n2eDHqAakdtkxrAg4nKeI4Jfe5r1Ttl+WVIAK98IrTm29R1A5tHuVXx1Clv7olBDeRrU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKT-Gi; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 06/24] net: phylink: Handle change in EEE from phylib Date: Fri, 31 Mar 2023 02:55:00 +0200 Message-Id: <20230331005518.2134652-7-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC phylib can indicate a change in EEE outside of the link coming up. When it does this, the link will already be up and remain up. Detect this in the phylink adjust_link callback, and call the mac_set_eee() callback, rather than running the resolver. This then avoids violating phylinks guarantee of not calling mac_link_up() without a corresponding mac_link_down(). Signed-off-by: Andrew Lunn --- drivers/net/phy/phylink.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 453f80544792..cf26acc920bd 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1594,10 +1594,13 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) { struct phylink *pl = phydev->phylink; bool tx_pause, rx_pause; + bool eee_changed; phy_get_pause(phydev, &tx_pause, &rx_pause); mutex_lock(&pl->state_mutex); + eee_changed = (pl->phy_state.link == up); + pl->phy_state.speed = phydev->speed; pl->phy_state.duplex = phydev->duplex; pl->phy_state.eee_active = phydev->eee_active; @@ -1609,9 +1612,14 @@ static void phylink_phy_change(struct phy_device *phydev, bool up) pl->phy_state.pause |= MLO_PAUSE_RX; pl->phy_state.interface = phydev->interface; pl->phy_state.link = up; + + if (eee_changed && pl->mac_ops->mac_set_eee) + pl->mac_ops->mac_set_eee(pl->config, pl->phy_state.eee_active); + mutex_unlock(&pl->state_mutex); - phylink_run_resolve(pl); + if (!eee_changed) + phylink_run_resolve(pl); phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s/%s\n", up ? "up" : "down", phy_modes(phydev->interface), From patchwork Fri Mar 31 00:55:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195128 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 ED65DC761AF for ; Fri, 31 Mar 2023 00:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjCaA4G (ORCPT ); Thu, 30 Mar 2023 20:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38EAC10A82 for ; Thu, 30 Mar 2023 17:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=jrn6cGCEToVRuwA/NoEFJON5CK6kATc25/oMJqS+RlM=; b=Xxqbnik4JcB1sE05tDaqZgydab Jd/IhZs1pJ/2MmDDgyRtdGdjbMH3XoVjbFAIJ7CpBVA78ysSTr+M8BQfybdKb7qDDqokmI3Drn9yQ OPbZUAnK/jjmHkAYWqqiKNvHYORSkiBQZ1vloqBhwO7skSOFhCED2Y0khKtxf4rx1kgQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKX-Hf; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 07/24] net: marvell: mvneta: Simplify EEE configuration Date: Fri, 31 Mar 2023 02:55:01 +0200 Message-Id: <20230331005518.2134652-8-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC phylib already does most of the work. It will track eee_enabled, eee_active and tx_lpi_enabled and correctly set them in the ethtool_get_eee callback. Replace the call to phy_init_eee() by looking at the value of eee_active passed to the mac_set_eee callback. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- v2: Use eee_active parameter, which is race free. Remove handling of tx_lpi_enabled, leave it to phylib. v3: Add mac_set_eee() callback. --- drivers/net/ethernet/marvell/mvneta.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index 0e39d199ff06..fba9edad9e37 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -536,10 +536,6 @@ struct mvneta_port { struct mvneta_bm_pool *pool_short; int bm_win_id; - bool eee_enabled; - bool eee_active; - bool tx_lpi_enabled; - u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)]; u32 indir[MVNETA_RSS_LU_TABLE_SIZE]; @@ -4170,7 +4166,6 @@ static void mvneta_mac_link_down(struct phylink_config *config, mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val); } - pp->eee_active = false; mvneta_set_eee(pp, false); } @@ -4220,11 +4215,15 @@ static void mvneta_mac_link_up(struct phylink_config *config, } mvneta_port_up(pp); +} - if (phy && pp->eee_enabled) { - pp->eee_active = phy_init_eee(phy, false) >= 0; - mvneta_set_eee(pp, pp->eee_active && pp->tx_lpi_enabled); - } +static void mvneta_mac_set_eee(struct phylink_config *config, + bool eee_active) +{ + struct net_device *ndev = to_net_dev(config->dev); + struct mvneta_port *pp = netdev_priv(ndev); + + mvneta_set_eee(pp, eee_active); } static const struct phylink_mac_ops mvneta_phylink_ops = { @@ -4234,6 +4233,7 @@ static const struct phylink_mac_ops mvneta_phylink_ops = { .mac_finish = mvneta_mac_finish, .mac_link_down = mvneta_mac_link_down, .mac_link_up = mvneta_mac_link_up, + .mac_set_eee = mvneta_mac_set_eee, }; static int mvneta_mdio_probe(struct mvneta_port *pp) @@ -5028,9 +5028,6 @@ static int mvneta_ethtool_get_eee(struct net_device *dev, lpi_ctl0 = mvreg_read(pp, MVNETA_LPI_CTRL_0); - eee->eee_enabled = pp->eee_enabled; - eee->eee_active = pp->eee_active; - eee->tx_lpi_enabled = pp->tx_lpi_enabled; eee->tx_lpi_timer = (lpi_ctl0) >> 8; // * scale; return phylink_ethtool_get_eee(pp->phylink, eee); @@ -5053,11 +5050,6 @@ static int mvneta_ethtool_set_eee(struct net_device *dev, lpi_ctl0 |= eee->tx_lpi_timer << 8; mvreg_write(pp, MVNETA_LPI_CTRL_0, lpi_ctl0); - pp->eee_enabled = eee->eee_enabled; - pp->tx_lpi_enabled = eee->tx_lpi_enabled; - - mvneta_set_eee(pp, eee->tx_lpi_enabled && eee->eee_enabled); - return phylink_ethtool_set_eee(pp->phylink, eee); } From patchwork Fri Mar 31 00:55:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195114 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 72B0EC6FD1D for ; Fri, 31 Mar 2023 00:55:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A93BDCA30 for ; Thu, 30 Mar 2023 17:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=3Lfh0ktoZwzqctBPTUWSfpvQ3j4ygku2HRMWE6CjmkQ=; b=J9QC4AdvRQPSMhsbdANdBcYhGt X2y/co/eXAXIbvPtviVPSm6GQm13A+rPpgW5TSp8UJIe23cpe7y4fGnll/C+T69gIf6nIfWmvose0 /ZT3xdHNAyNzIglNL38Xod1QJkwjG89MXPSeicyZ02SLzS7x+dz/jepiZMeTWPreTSyo=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKb-Iw; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 08/24] net: stmmac: Drop usage of phy_init_eee() Date: Fri, 31 Mar 2023 02:55:02 +0200 Message-Id: <20230331005518.2134652-9-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Replace this method by looking at the eee_active member of the phydev structure. Additionally, call the phy_eee_clk_stop_enable() if the platform indicates the clock should be stopped while LPI is active. Signed-off-by: Andrew Lunn --- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 17310ade88dd..dd2488998993 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1080,8 +1080,9 @@ static void stmmac_mac_link_up(struct phylink_config *config, stmmac_mac_set(priv, priv->ioaddr, true); if (phy && priv->dma_cap.eee) { - priv->eee_active = - phy_init_eee(phy, !priv->plat->rx_clk_runs_in_lpi) >= 0; + priv->eee_active = phy->eee_active; + if (!priv->plat->rx_clk_runs_in_lpi) + phy_eee_clk_stop_enable(phy); priv->eee_enabled = stmmac_eee_init(priv); priv->tx_lpi_enabled = priv->eee_enabled; stmmac_set_eee_pls(priv, priv->hw, true); From patchwork Fri Mar 31 00:55:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195123 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 AA829C6FD1D for ; Fri, 31 Mar 2023 00:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229925AbjCaAz6 (ORCPT ); Thu, 30 Mar 2023 20:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229869AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9590110AAB for ; Thu, 30 Mar 2023 17:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=Jb35pzQSEqazBycU9msxB2jI7yLeWnGVR6T0TrQvFT8=; b=glQuBkTBT0ZUROdTbMFBgqaJ9W gaBe3Z1BDXDCNRrfalgwxPWNTspRe8fL61U175zLsxd5LLFOy3D9K8gSJucSBO0KEPGVoFbGs7Py7 XUEXIF40Dzyau2sZTuAWe1/aVMThlXMwvIzStP5mkKd5Hb+OKeHiBc4TokQzNLCAoY3I=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKf-Jz; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 09/24] net: stmmac: Simplify ethtool get eee Date: Fri, 31 Mar 2023 02:55:03 +0200 Message-Id: <20230331005518.2134652-10-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC phylink_ethtool_get_eee() fills in eee_enabled, eee_active and tx_lpi_enabled. So there is no need for the MAC driver to do it as well. Signed-off-by: Andrew Lunn Tested-by: Oleksij Rempel --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 - drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 7 ------- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 -- 3 files changed, 10 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 3d15e1e92e18..a0f6e58fc622 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -253,7 +253,6 @@ struct stmmac_priv { int eee_enabled; int eee_active; int tx_lpi_timer; - int tx_lpi_enabled; int eee_tw_timer; bool eee_sw_timer_en; unsigned int mode; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 35c8dd92d369..fd97cdbb6797 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -782,10 +782,7 @@ static int stmmac_ethtool_op_get_eee(struct net_device *dev, if (!priv->dma_cap.eee) return -EOPNOTSUPP; - edata->eee_enabled = priv->eee_enabled; - edata->eee_active = priv->eee_active; edata->tx_lpi_timer = priv->tx_lpi_timer; - edata->tx_lpi_enabled = priv->tx_lpi_enabled; return phylink_ethtool_get_eee(priv->phylink, edata); } @@ -799,10 +796,6 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, if (!priv->dma_cap.eee) return -EOPNOTSUPP; - if (priv->tx_lpi_enabled != edata->tx_lpi_enabled) - netdev_warn(priv->dev, - "Setting EEE tx-lpi is not supported\n"); - if (!edata->eee_enabled) stmmac_disable_eee_mode(priv); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index dd2488998993..190b74d7f4e7 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -971,7 +971,6 @@ static void stmmac_mac_link_down(struct phylink_config *config, stmmac_mac_set(priv, priv->ioaddr, false); priv->eee_active = false; - priv->tx_lpi_enabled = false; priv->eee_enabled = stmmac_eee_init(priv); stmmac_set_eee_pls(priv, priv->hw, false); @@ -1084,7 +1083,6 @@ static void stmmac_mac_link_up(struct phylink_config *config, if (!priv->plat->rx_clk_runs_in_lpi) phy_eee_clk_stop_enable(phy); priv->eee_enabled = stmmac_eee_init(priv); - priv->tx_lpi_enabled = priv->eee_enabled; stmmac_set_eee_pls(priv, priv->hw, true); } From patchwork Fri Mar 31 00:55:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195136 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 249C6C6FD1D for ; Fri, 31 Mar 2023 00:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229913AbjCaA4S (ORCPT ); Thu, 30 Mar 2023 20:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjCaAzt (ORCPT ); Thu, 30 Mar 2023 20:55:49 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB37FF2F for ; Thu, 30 Mar 2023 17:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=SYQ2diBX2UCAJOq4OlK7YCoqtn/xB/rDinj8IG/rv3w=; b=oZTPxgyNatX0+/g2WhIeevOp+B JKTavtcmTk48cL9TmS8uqfXCEc5Dx1SsFAq0+jGIrwv+S/YlQ0Cd9xYaEBz7tBI5EoT8l/10lMaI+ FZGxHB5lWvEJqzoztyf493z+7RK/IxOfYXQoCg9AOcare6IoNPXls66uihlz5zB9aCwA=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKj-LD; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 10/24] net: lan743x: Fixup EEE Date: Fri, 31 Mar 2023 02:55:04 +0200 Message-Id: <20230331005518.2134652-11-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into lan743x_phy_link_status_change() which gets called by phylib when there is a change in link status. lan743x_ethtool_set_eee() now just programs the hardware with the LTI timer value, and passed everything else to phylib, so it can correctly setup the PHY. lan743x_ethtool_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- .../net/ethernet/microchip/lan743x_ethtool.c | 22 ------------------- drivers/net/ethernet/microchip/lan743x_main.c | 7 ++++++ 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c index 2db5949b4c7e..da2f1110e0db 100644 --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c @@ -1073,16 +1073,10 @@ static int lan743x_ethtool_get_eee(struct net_device *netdev, buf = lan743x_csr_read(adapter, MAC_CR); if (buf & MAC_CR_EEE_EN_) { - eee->eee_enabled = true; - eee->eee_active = !!(eee->advertised & eee->lp_advertised); - eee->tx_lpi_enabled = true; /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */ buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT); eee->tx_lpi_timer = buf; } else { - eee->eee_enabled = false; - eee->eee_active = false; - eee->tx_lpi_enabled = false; eee->tx_lpi_timer = 0; } @@ -1095,7 +1089,6 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, struct lan743x_adapter *adapter; struct phy_device *phydev; u32 buf = 0; - int ret = 0; if (!netdev) return -EINVAL; @@ -1112,23 +1105,8 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev, } if (eee->eee_enabled) { - ret = phy_init_eee(phydev, false); - if (ret) { - netif_err(adapter, drv, adapter->netdev, - "EEE initialization failed\n"); - return ret; - } - buf = (u32)eee->tx_lpi_timer; lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf); - - buf = lan743x_csr_read(adapter, MAC_CR); - buf |= MAC_CR_EEE_EN_; - lan743x_csr_write(adapter, MAC_CR, buf); - } else { - buf = lan743x_csr_read(adapter, MAC_CR); - buf &= ~MAC_CR_EEE_EN_; - lan743x_csr_write(adapter, MAC_CR, buf); } return phy_ethtool_set_eee(phydev, eee); diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 957d96a91a8a..7986f8fcf7d3 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1457,6 +1457,13 @@ static void lan743x_phy_link_status_change(struct net_device *netdev) phydev->interface == PHY_INTERFACE_MODE_1000BASEX || phydev->interface == PHY_INTERFACE_MODE_2500BASEX) lan743x_sgmii_config(adapter); + + data = lan743x_csr_read(adapter, MAC_CR); + if (phydev->eee_active) + data |= MAC_CR_EEE_EN_; + else + data &= ~MAC_CR_EEE_EN_; + lan743x_csr_write(adapter, MAC_CR, data); } } From patchwork Fri Mar 31 00:55:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195134 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 DF993C6FD1D for ; Fri, 31 Mar 2023 00:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbjCaA4P (ORCPT ); Thu, 30 Mar 2023 20:56:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbjCaAzs (ORCPT ); Thu, 30 Mar 2023 20:55:48 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD619CA0F for ; Thu, 30 Mar 2023 17:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=lxqd3Qo6earaNp+DfYY477P8FY5Hm7FmGB1HdaqqIAM=; b=uAgO5c/xfVo3KhrHLjfr4WIzc1 YIqDijmsBklIIWmIP+9iGHsqDQBgoaR+pFu5nFzqw0yJPE8NAZuGG/YbSAqZfrxHVb9iUEuvofmeJ sBeZqgjYEJ3GS3C/WtIAC4SCgQUD/h0xSVYfdjDg30dMOISSckTDNb6dA83x7xOWzEIQ=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKn-MH; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 11/24] net: fec: Move fec_enet_eee_mode_set() and helper earlier Date: Fri, 31 Mar 2023 02:55:05 +0200 Message-Id: <20230331005518.2134652-12-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC FEC is about to get its EEE code re-written. To allow this, move fec_enet_eee_mode_set() before fec_enet_adjust_link() which will need to call it. Signed-off-by: Andrew Lunn --- drivers/net/ethernet/freescale/fec_main.c | 79 ++++++++++++----------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index f3b16a6673e2..462755f5d33e 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1919,6 +1919,46 @@ static int fec_get_mac(struct net_device *ndev) /* * Phy section */ + +/* LPI Sleep Ts count base on tx clk (clk_ref). + * The lpi sleep cnt value = X us / (cycle_ns). + */ +static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + + return us * (fep->clk_ref_rate / 1000) / 1000; +} + +static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable) +{ + struct fec_enet_private *fep = netdev_priv(ndev); + struct ethtool_eee *p = &fep->eee; + unsigned int sleep_cycle, wake_cycle; + int ret = 0; + + if (enable) { + ret = phy_init_eee(ndev->phydev, false); + if (ret) + return ret; + + sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer); + wake_cycle = sleep_cycle; + } else { + sleep_cycle = 0; + wake_cycle = 0; + } + + p->tx_lpi_enabled = enable; + p->eee_enabled = enable; + p->eee_active = enable; + + writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP); + writel(wake_cycle, fep->hwp + FEC_LPI_WAKE); + + return 0; +} + static void fec_enet_adjust_link(struct net_device *ndev) { struct fec_enet_private *fep = netdev_priv(ndev); @@ -3057,45 +3097,6 @@ static int fec_enet_set_tunable(struct net_device *netdev, return ret; } -/* LPI Sleep Ts count base on tx clk (clk_ref). - * The lpi sleep cnt value = X us / (cycle_ns). - */ -static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us) -{ - struct fec_enet_private *fep = netdev_priv(ndev); - - return us * (fep->clk_ref_rate / 1000) / 1000; -} - -static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable) -{ - struct fec_enet_private *fep = netdev_priv(ndev); - struct ethtool_eee *p = &fep->eee; - unsigned int sleep_cycle, wake_cycle; - int ret = 0; - - if (enable) { - ret = phy_init_eee(ndev->phydev, false); - if (ret) - return ret; - - sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer); - wake_cycle = sleep_cycle; - } else { - sleep_cycle = 0; - wake_cycle = 0; - } - - p->tx_lpi_enabled = enable; - p->eee_enabled = enable; - p->eee_active = enable; - - writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP); - writel(wake_cycle, fep->hwp + FEC_LPI_WAKE); - - return 0; -} - static int fec_enet_get_eee(struct net_device *ndev, struct ethtool_eee *edata) { From patchwork Fri Mar 31 00:55:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195117 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 55E6FC7619A for ; Fri, 31 Mar 2023 00:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjCaAzu (ORCPT ); Thu, 30 Mar 2023 20:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77DFCA0F for ; Thu, 30 Mar 2023 17:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=HohKRu7DmOMqIPqlD5JGST8gaDMwRol7D8yS78TxAT0=; b=jyld5eYOdeKAfluR8FZARQhSN4 dgr05Y++GW+OO1ahctkN8RXwO0SKHsBGo7pFcHFrz52G3C6WJgOvbDlSyrOVega33taopWAqIK8Xc kjQywDB6d5+U5NJGaK+UGYSY0dTqunW+AJ3hPLc72WauevpHkHCK/doKPXVXawjqwBbs=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKr-NK; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 12/24] net: FEC: Fixup EEE Date: Fri, 31 Mar 2023 02:55:06 +0200 Message-Id: <20230331005518.2134652-13-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into fec_enet_adjust_link() which gets called by phylib when there is a change in link status. fec_enet_set_eee() now just stores away the LTI timer value. Everything else is passed to phylib, so it can correctly setup the PHY. fec_enet_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value. Signed-off-by: Andrew Lunn Tested-by: Oleksij Rempel --- v2: Only call fec_enet_eee_mode_set for those that support EEE --- drivers/net/ethernet/freescale/fec_main.c | 28 ++++------------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 462755f5d33e..fda1f9ff32b9 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1930,18 +1930,13 @@ static int fec_enet_us_to_tx_cycle(struct net_device *ndev, int us) return us * (fep->clk_ref_rate / 1000) / 1000; } -static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable) +static int fec_enet_eee_mode_set(struct net_device *ndev, bool eee_active) { struct fec_enet_private *fep = netdev_priv(ndev); struct ethtool_eee *p = &fep->eee; unsigned int sleep_cycle, wake_cycle; - int ret = 0; - - if (enable) { - ret = phy_init_eee(ndev->phydev, false); - if (ret) - return ret; + if (eee_active) { sleep_cycle = fec_enet_us_to_tx_cycle(ndev, p->tx_lpi_timer); wake_cycle = sleep_cycle; } else { @@ -1949,10 +1944,6 @@ static int fec_enet_eee_mode_set(struct net_device *ndev, bool enable) wake_cycle = 0; } - p->tx_lpi_enabled = enable; - p->eee_enabled = enable; - p->eee_active = enable; - writel(sleep_cycle, fep->hwp + FEC_LPI_SLEEP); writel(wake_cycle, fep->hwp + FEC_LPI_WAKE); @@ -1997,6 +1988,8 @@ static void fec_enet_adjust_link(struct net_device *ndev) netif_tx_unlock_bh(ndev); napi_enable(&fep->napi); } + if (fep->quirks & FEC_QUIRK_HAS_EEE) + fec_enet_eee_mode_set(ndev, phy_dev->eee_active); } else { if (fep->link) { napi_disable(&fep->napi); @@ -3109,10 +3102,7 @@ fec_enet_get_eee(struct net_device *ndev, struct ethtool_eee *edata) if (!netif_running(ndev)) return -ENETDOWN; - edata->eee_enabled = p->eee_enabled; - edata->eee_active = p->eee_active; edata->tx_lpi_timer = p->tx_lpi_timer; - edata->tx_lpi_enabled = p->tx_lpi_enabled; return phy_ethtool_get_eee(ndev->phydev, edata); } @@ -3122,7 +3112,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_eee *edata) { struct fec_enet_private *fep = netdev_priv(ndev); struct ethtool_eee *p = &fep->eee; - int ret = 0; if (!(fep->quirks & FEC_QUIRK_HAS_EEE)) return -EOPNOTSUPP; @@ -3132,15 +3121,6 @@ fec_enet_set_eee(struct net_device *ndev, struct ethtool_eee *edata) p->tx_lpi_timer = edata->tx_lpi_timer; - if (!edata->eee_enabled || !edata->tx_lpi_enabled || - !edata->tx_lpi_timer) - ret = fec_enet_eee_mode_set(ndev, false); - else - ret = fec_enet_eee_mode_set(ndev, true); - - if (ret) - return ret; - return phy_ethtool_set_eee(ndev->phydev, edata); } From patchwork Fri Mar 31 00:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195129 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 19130C6FD1D for ; Fri, 31 Mar 2023 00:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229941AbjCaA4H (ORCPT ); Thu, 30 Mar 2023 20:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26676C67E for ; Thu, 30 Mar 2023 17:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=3oqIOsKued46J4FItnxZj5LSJdU4+2L8Wb6tyVTV4FQ=; b=s+CcrWBV+d88+pWQ2rN0Mef14z lEBsDUgva4UVsVlQs5NuLbxGQD87cg3dGCKBCLNxF+4GnikQz3/v1TEuEKg6BrwHIx+3nT7KWR3QV luHmQY+Pul8S8hqsKWMO4ae1YayE8+QphvlaPSLUwTtoJsTt3d3oRY+opGvpySKTZTrI=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKv-OV; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 13/24] net: genet: Fixup EEE Date: Fri, 31 Mar 2023 02:55:07 +0200 Message-Id: <20230331005518.2134652-14-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into bcmgenet_mii_setup() which gets called by phylib when there is a change in link status. bcmgenet_set_eee() now just writes the LTI timer value to the hardware. Everything else is passed to phylib, so it can correctly setup the PHY. bcmgenet_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value from hardware. The call to bcmgenet_eee_enable_set() in the resume function has been removed. There is both unconditional calls to phy_init_hw() and genphy_config_aneg, and a call to phy_resume(). As a result, the PHY is going to perform auto-neg, and then it completes bcmgenet_mii_setup() will be called, which will set the hardware to the correct EEE mode. Signed-off-by: Andrew Lunn --- .../net/ethernet/broadcom/genet/bcmgenet.c | 42 +++++-------------- .../net/ethernet/broadcom/genet/bcmgenet.h | 3 +- drivers/net/ethernet/broadcom/genet/bcmmii.c | 1 + 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c index d937daa8ee88..035486304e31 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c @@ -1272,19 +1272,21 @@ 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 eee_active) { struct bcmgenet_priv *priv = netdev_priv(dev); - u32 off = priv->hw_params->tbuf_offset + TBUF_ENERGY_CTRL; + u32 off; u32 reg; - if (enable && !priv->clk_eee_enabled) { + off = priv->hw_params->tbuf_offset + TBUF_ENERGY_CTRL; + + if (eee_active && !priv->clk_eee_enabled) { clk_prepare_enable(priv->clk_eee); priv->clk_eee_enabled = true; } reg = bcmgenet_umac_readl(priv, UMAC_EEE_CTRL); - if (enable) + if (eee_active) reg |= EEE_EN; else reg &= ~EEE_EN; @@ -1292,7 +1294,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 (eee_active) reg |= TBUF_EEE_EN | TBUF_PM_EN; else reg &= ~(TBUF_EEE_EN | TBUF_PM_EN); @@ -1300,25 +1302,21 @@ static void bcmgenet_eee_enable_set(struct net_device *dev, bool enable) /* Do the same for thing for RBUF */ reg = bcmgenet_rbuf_readl(priv, RBUF_ENERGY_CTRL); - if (enable) + if (eee_active) reg |= RBUF_EEE_EN | RBUF_PM_EN; else reg &= ~(RBUF_EEE_EN | RBUF_PM_EN); bcmgenet_rbuf_writel(priv, reg, RBUF_ENERGY_CTRL); - if (!enable && priv->clk_eee_enabled) { + if (!eee_active && priv->clk_eee_enabled) { clk_disable_unprepare(priv->clk_eee); priv->clk_eee_enabled = false; } - - priv->eee.eee_enabled = enable; - priv->eee.eee_active = enable; } static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_eee *e) { struct bcmgenet_priv *priv = netdev_priv(dev); - struct ethtool_eee *p = &priv->eee; if (GENET_IS_V1(priv)) return -EOPNOTSUPP; @@ -1326,8 +1324,6 @@ static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_eee *e) if (!dev->phydev) return -ENODEV; - e->eee_enabled = p->eee_enabled; - e->eee_active = p->eee_active; e->tx_lpi_timer = bcmgenet_umac_readl(priv, UMAC_EEE_LPI_TIMER); return phy_ethtool_get_eee(dev->phydev, e); @@ -1336,8 +1332,6 @@ static int bcmgenet_get_eee(struct net_device *dev, struct ethtool_eee *e) 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; @@ -1345,20 +1339,7 @@ static int bcmgenet_set_eee(struct net_device *dev, struct ethtool_eee *e) if (!dev->phydev) return -ENODEV; - p->eee_enabled = e->eee_enabled; - - if (!p->eee_enabled) { - bcmgenet_eee_enable_set(dev, false); - } else { - ret = phy_init_eee(dev->phydev, false); - if (ret) { - netif_err(priv, hw, dev, "EEE initialization failed\n"); - return ret; - } - - bcmgenet_umac_writel(priv, e->tx_lpi_timer, UMAC_EEE_LPI_TIMER); - bcmgenet_eee_enable_set(dev, true); - } + bcmgenet_umac_writel(priv, e->tx_lpi_timer, UMAC_EEE_LPI_TIMER); return phy_ethtool_set_eee(dev->phydev, e); } @@ -4278,9 +4259,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 946f6e283c4e..8c9643ec738c 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h @@ -644,8 +644,6 @@ struct bcmgenet_priv { bool wol_active; struct bcmgenet_mib_counters mib; - - struct ethtool_eee eee; }; #define GENET_IO_MACRO(name, offset) \ @@ -703,4 +701,5 @@ 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 eee_active); #endif /* __BCMGENET_H__ */ diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c index be042905ada2..6c39839762a7 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -100,6 +100,7 @@ void bcmgenet_mii_setup(struct net_device *dev) if (phydev->link) { bcmgenet_mac_config(dev); + bcmgenet_eee_enable_set(dev, phydev->eee_active); } else { reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL); reg &= ~RGMII_LINK; From patchwork Fri Mar 31 00:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195118 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 05841C6FD1D for ; Fri, 31 Mar 2023 00:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229903AbjCaAzw (ORCPT ); Thu, 30 Mar 2023 20:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229841AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319B4FF2F for ; Thu, 30 Mar 2023 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=zMnNz2bNP9Kii6W3Q1KSVFWIPvSi1Jj5giEJItJf5cM=; b=xTLXvTMB6MiIzX1h89ZjXjnMZ/ JXSMHQgXsIf6SimXzuHZXRn4dMZFrF2/wfSSO4eLrIBYZeDc5fsIHdYMMHkXWphxgY7YfC/Gbd+5x 0dJgWuVpmEAu0ZiXIoE6rcYfWTDWjXvKToiWwq/7gALMnn87NVRDt97O/w68feGMggGM=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xKz-Pf; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 14/24] net: sxgdb: Fixup EEE Date: Fri, 31 Mar 2023 02:55:08 +0200 Message-Id: <20230331005518.2134652-15-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So rework sxgbe_eee_adjust() to take the result of negotiation into account. sxgbe_set_eee() now just stores LTI timer value. Everything else is passed to phylib, so it can correctly setup the PHY. sxgbe_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value. The hw_cap.eee is now used to control timers, rather than eee_enabled, which was wrongly being set based on the value of phy_init_eee() before auto-neg even completed. Signed-off-by: Andrew Lunn --- .../net/ethernet/samsung/sxgbe/sxgbe_common.h | 3 -- .../ethernet/samsung/sxgbe/sxgbe_ethtool.c | 21 ++--------- .../net/ethernet/samsung/sxgbe/sxgbe_main.c | 36 ++++++------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h index 0f45107db8dd..c25588b90a13 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_common.h @@ -502,8 +502,6 @@ struct sxgbe_priv_data { struct timer_list eee_ctrl_timer; bool tx_path_in_lpi_mode; int lpi_irq; - int eee_enabled; - int eee_active; int tx_lpi_timer; }; @@ -528,5 +526,4 @@ int sxgbe_restore(struct net_device *ndev); const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void); void sxgbe_disable_eee_mode(struct sxgbe_priv_data * const priv); -bool sxgbe_eee_init(struct sxgbe_priv_data * const priv); #endif /* __SXGBE_COMMON_H__ */ diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c index 8ba017ec9849..e7128864a3ef 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_ethtool.c @@ -140,8 +140,6 @@ static int sxgbe_get_eee(struct net_device *dev, if (!priv->hw_cap.eee) return -EOPNOTSUPP; - edata->eee_enabled = priv->eee_enabled; - edata->eee_active = priv->eee_active; edata->tx_lpi_timer = priv->tx_lpi_timer; return phy_ethtool_get_eee(dev->phydev, edata); @@ -152,22 +150,7 @@ static int sxgbe_set_eee(struct net_device *dev, { struct sxgbe_priv_data *priv = netdev_priv(dev); - priv->eee_enabled = edata->eee_enabled; - - if (!priv->eee_enabled) { - sxgbe_disable_eee_mode(priv); - } else { - /* We are asking for enabling the EEE but it is safe - * to verify all by invoking the eee_init function. - * In case of failure it will return an error. - */ - priv->eee_enabled = sxgbe_eee_init(priv); - if (!priv->eee_enabled) - return -EOPNOTSUPP; - - /* Do not change tx_lpi_timer in case of failure */ - priv->tx_lpi_timer = edata->tx_lpi_timer; - } + priv->tx_lpi_timer = edata->tx_lpi_timer; return phy_ethtool_set_eee(dev->phydev, edata); } @@ -230,7 +213,7 @@ static void sxgbe_get_ethtool_stats(struct net_device *dev, int i; char *p; - if (priv->eee_enabled) { + if (dev->phydev->eee_active) { int val = phy_get_eee_err(dev->phydev); if (val) diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c index 9664f029fa16..cf549a524674 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c @@ -119,18 +119,10 @@ static void sxgbe_eee_ctrl_timer(struct timer_list *t) * phy can also manage EEE, so enable the LPI state and start the timer * to verify if the tx path can enter in LPI state. */ -bool sxgbe_eee_init(struct sxgbe_priv_data * const priv) +static void sxgbe_eee_init(struct sxgbe_priv_data * const priv) { - struct net_device *ndev = priv->dev; - bool ret = false; - /* MAC core supports the EEE feature. */ if (priv->hw_cap.eee) { - /* Check if the PHY supports EEE */ - if (phy_init_eee(ndev->phydev, true)) - return false; - - priv->eee_active = 1; timer_setup(&priv->eee_ctrl_timer, sxgbe_eee_ctrl_timer, 0); priv->eee_ctrl_timer.expires = SXGBE_LPI_TIMER(eee_timer); add_timer(&priv->eee_ctrl_timer); @@ -140,23 +132,15 @@ bool sxgbe_eee_init(struct sxgbe_priv_data * const priv) priv->tx_lpi_timer); pr_info("Energy-Efficient Ethernet initialized\n"); - - ret = true; } - - return ret; } -static void sxgbe_eee_adjust(const struct sxgbe_priv_data *priv) +static void sxgbe_eee_adjust(const struct sxgbe_priv_data *priv, + bool eee_active) { - struct net_device *ndev = priv->dev; - - /* When the EEE has been already initialised we have to - * modify the PLS bit in the LPI ctrl & status reg according - * to the PHY link status. For this reason. - */ - if (priv->eee_enabled) - priv->hw->mac->set_eee_pls(priv->ioaddr, ndev->phydev->link); + if (priv->hw_cap.eee) + priv->hw->mac->set_eee_pls(priv->ioaddr, eee_active); + phy_eee_clk_stop_enable(priv->dev->phydev); } /** @@ -250,7 +234,7 @@ static void sxgbe_adjust_link(struct net_device *dev) phy_print_status(phydev); /* Alter the MAC settings for EEE */ - sxgbe_eee_adjust(priv); + sxgbe_eee_adjust(priv, phydev->eee_active); } /** @@ -803,7 +787,7 @@ static void sxgbe_tx_all_clean(struct sxgbe_priv_data * const priv) sxgbe_tx_queue_clean(tqueue); } - if ((priv->eee_enabled) && (!priv->tx_path_in_lpi_mode)) { + if (priv->hw_cap.eee && !priv->tx_path_in_lpi_mode) { sxgbe_enable_eee_mode(priv); mod_timer(&priv->eee_ctrl_timer, SXGBE_LPI_TIMER(eee_timer)); } @@ -1181,7 +1165,7 @@ static int sxgbe_open(struct net_device *dev) } priv->tx_lpi_timer = SXGBE_DEFAULT_LPI_TIMER; - priv->eee_enabled = sxgbe_eee_init(priv); + sxgbe_eee_init(priv); napi_enable(&priv->napi); netif_start_queue(dev); @@ -1208,7 +1192,7 @@ static int sxgbe_release(struct net_device *dev) { struct sxgbe_priv_data *priv = netdev_priv(dev); - if (priv->eee_enabled) + if (priv->hw_cap.eee) del_timer_sync(&priv->eee_ctrl_timer); /* Stop and disconnect the PHY */ From patchwork Fri Mar 31 00:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195130 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 47692C77B6C for ; Fri, 31 Mar 2023 00:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbjCaA4I (ORCPT ); Thu, 30 Mar 2023 20:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46DD9113D3 for ; Thu, 30 Mar 2023 17:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=PR4xrm8c68/VGo9jp6k6Bup9hDdIAvVszf2q+o3lSgQ=; b=JRdZ5knePZzDYc/RtkberWlWK7 pvMcmJ2sTfD2sjymxf5NNLpyZt0fIj47TClN7bPxVt1YvMrzuTVn4BPG3lh1t0GVzQAcqiQznfv6z ZETjG1HEAZaTxhtPsyi+Ggu4ahlf8hMPLxNHIlKpuiaL//+kAbKyflsPCQrqvtE0Bso4=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xL3-Qo; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 15/24] net: dsa: mt7530: Swap to using phydev->eee_active Date: Fri, 31 Mar 2023 02:55:09 +0200 Message-Id: <20230331005518.2134652-16-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Rather than calling phy_init_eee() retrieve the same information from within the phydev structure. Signed-off-by: Andrew Lunn --- drivers/net/dsa/mt7530.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index a0d99af897ac..19d089eadcd0 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -2753,7 +2753,7 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, mcr |= PMCR_RX_FC_EN; } - if (mode == MLO_AN_PHY && phydev && phy_init_eee(phydev, false) >= 0) { + if (mode == MLO_AN_PHY && phydev && phydev->eee_active) { switch (speed) { case SPEED_1000: mcr |= PMCR_FORCE_EEE1G; From patchwork Fri Mar 31 00:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195126 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 19485C7619A for ; Fri, 31 Mar 2023 00:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbjCaA4D (ORCPT ); Thu, 30 Mar 2023 20:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B37A510402 for ; Thu, 30 Mar 2023 17:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=YL6xhcBVXuty3K6N6oEf9aHPNv9O56x7qsv4scpFW3s=; b=s6fOmYUnX9SlbAcrc9aYDf3QI9 QzUtRqnFtOriJtfnhcPDqcbtay68iSksvtWZCU5qsNLsEuO9dFe/pdF9lRdTXcZLnNrL+nAvlO6Hi IEK4OD4FqpgV1m0oIhf+xfZeMx7p1wG5/cZyNoFh/GlUjf2qCG2XG8fMsYNnaexe0QTY=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xL7-Ru; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 16/24] net: dsa: b53: Swap to using phydev->eee_active Date: Fri, 31 Mar 2023 02:55:10 +0200 Message-Id: <20230331005518.2134652-17-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Rather than calling phy_init_eee() retrieve the same information from within the phydev structure. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- drivers/net/dsa/b53/b53_common.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index 3464ce5e7470..5984733e4d0d 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2218,10 +2218,7 @@ EXPORT_SYMBOL(b53_eee_enable_set); */ int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy) { - int ret; - - ret = phy_init_eee(phy, false); - if (ret) + if (!phy->eee_active) return 0; b53_eee_enable_set(ds, port, true); From patchwork Fri Mar 31 00:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195137 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 DD406C761AF for ; Fri, 31 Mar 2023 00:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbjCaA4T (ORCPT ); Thu, 30 Mar 2023 20:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbjCaAzt (ORCPT ); Thu, 30 Mar 2023 20:55:49 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD76CCA17 for ; Thu, 30 Mar 2023 17:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=9UYj/8esH2X02G+vWdHOQRTG8LwFe54E3WD49rcXs7Q=; b=SRRnBHAYKZ5CrZnZ3vYUHxOFp5 r75aoN5mT3BUxTqX527iy41rGeVJ1ak1uXiWu5cb1uguignuchSwr9dSMQl38q+ITZuov71HbCvrD MHKChkZgigFZMAkmp0SBwiBgPwwLCxmECJGxoiivo33wmNjNh274olCZlWmZjLRD7Gxs=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xLB-St; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 17/24] net: phylink: Remove unused phylink_init_eee() Date: Fri, 31 Mar 2023 02:55:11 +0200 Message-Id: <20230331005518.2134652-18-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This is not used in tree, and the phylib equivalent phy_init_eee() is about to be removed. Reviewed-by: Russell King (Oracle) Signed-off-by: Andrew Lunn --- drivers/net/phy/phylink.c | 18 ------------------ include/linux/phylink.h | 1 - 2 files changed, 19 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index cf26acc920bd..61e4502086c3 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -2517,24 +2517,6 @@ int phylink_get_eee_err(struct phylink *pl) } EXPORT_SYMBOL_GPL(phylink_get_eee_err); -/** - * phylink_init_eee() - init and check the EEE features - * @pl: a pointer to a &struct phylink returned from phylink_create() - * @clk_stop_enable: allow PHY to stop receive clock - * - * Must be called either with RTNL held or within mac_link_up() - */ -int phylink_init_eee(struct phylink *pl, bool clk_stop_enable) -{ - int ret = -EOPNOTSUPP; - - if (pl->phydev) - ret = phy_init_eee(pl->phydev, clk_stop_enable); - - return ret; -} -EXPORT_SYMBOL_GPL(phylink_init_eee); - /** * phylink_ethtool_get_eee() - read the energy efficient ethernet parameters * @pl: a pointer to a &struct phylink returned from phylink_create() diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 7b5df55e2467..52f29b648853 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -617,7 +617,6 @@ void phylink_ethtool_get_pauseparam(struct phylink *, int phylink_ethtool_set_pauseparam(struct phylink *, struct ethtool_pauseparam *); int phylink_get_eee_err(struct phylink *); -int phylink_init_eee(struct phylink *, bool); int phylink_ethtool_get_eee(struct phylink *, struct ethtool_eee *); int phylink_ethtool_set_eee(struct phylink *, struct ethtool_eee *); int phylink_mii_ioctl(struct phylink *, struct ifreq *, int); From patchwork Fri Mar 31 00:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195115 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 BAC7DC7619A for ; Fri, 31 Mar 2023 00:55:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229871AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229733AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A925BCA17 for ; Thu, 30 Mar 2023 17:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=8WDLBBqJq5l0AmISc/9zZPZwrAzUFEnsfM0T9gAF5Vk=; b=uzOnVaECDzYTODSq9+Wd8g+j0d P+ymUBsCiEHmdHoc8PenQ9h8LrcIDywEb3HRDdfI0fWGKTjRpIxPwAFLLIjxfc3wTzvZhHGgwjRdo o120ezkAun+GcCzXDD49NTCQc20B8Au9FcRm5rXpuhcjt7Auf5gMpLltXrVkunYZVqvU=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xLF-Tz; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 18/24] net: phy: remove unused phy_init_eee() Date: Fri, 31 Mar 2023 02:55:12 +0200 Message-Id: <20230331005518.2134652-19-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC There are no users left of phy_init_eee(), and it is often wrongly used. So remove it. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy.c | 34 ---------------------------------- include/linux/phy.h | 1 - 2 files changed, 35 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index f4da7a5440e3..a70de8dbe6b6 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1517,40 +1517,6 @@ void phy_mac_interrupt(struct phy_device *phydev) } EXPORT_SYMBOL(phy_mac_interrupt); -/** - * phy_init_eee - init and check the EEE feature - * @phydev: target phy_device struct - * @clk_stop_enable: PHY may stop the clock during LPI - * - * Description: it checks if the Energy-Efficient Ethernet (EEE) - * is supported by looking at the MMD registers 3.20 and 7.60/61 - * and it programs the MMD register 3.0 setting the "Clock stop enable" - * bit if required. - */ -int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) -{ - int ret; - - if (!phydev->drv) - return -EIO; - - ret = genphy_c45_eee_is_active(phydev, NULL, NULL, NULL); - if (ret < 0) - return ret; - if (!ret) - return -EPROTONOSUPPORT; - - if (clk_stop_enable) - /* Configure the PHY to stop receiving xMII - * clock while it is signaling LPI. - */ - ret = phy_set_bits_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, - MDIO_PCS_CTRL1_CLKSTOP_EN); - - return ret < 0 ? ret : 0; -} -EXPORT_SYMBOL(phy_init_eee); - /** * phy_get_eee_err - report the EEE wake error count * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index 4c3d80311c04..af199fcc52b2 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1848,7 +1848,6 @@ int phy_unregister_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask); int phy_unregister_fixup_for_id(const char *bus_id); int phy_unregister_fixup_for_uid(u32 phy_uid, u32 phy_uid_mask); -int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable); int phy_get_eee_err(struct phy_device *phydev); int phy_eee_clk_stop_enable(struct phy_device *phydev); int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_eee *data); From patchwork Fri Mar 31 00:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195125 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 A987BC6FD1D for ; Fri, 31 Mar 2023 00:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbjCaA4B (ORCPT ); Thu, 30 Mar 2023 20:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229867AbjCaAzr (ORCPT ); Thu, 30 Mar 2023 20:55:47 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3623F1043E for ; Thu, 30 Mar 2023 17:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=1/dbEsXqGx48zAli55PJOIiTxiYPYrEPuTGpZjjHHLI=; b=OjNq+Iv8jJis45LH3HPNEs3D3w iNPv+Dnw7OyUMU643v/u0bwSCIA5ro8o8QOu1Phk8YoaAPSSZme1+eO1Q/6JZppG3XnBHLxy4+g6L IV95vUWrC3qPeH1Ei4DAJUvrpr8K2TtuMBDI/ejKigyj/Vi4i/W7oVJvkSe0npC2svmc=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xLJ-V1; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 19/24] net: usb: lan78xx: Fixup EEE Date: Fri, 31 Mar 2023 02:55:13 +0200 Message-Id: <20230331005518.2134652-20-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The enabling/disabling of EEE in the MAC should happen as a result of auto negotiation. So move the enable/disable into lan783xx_phy_link_status_change() which gets called by phylib when there is a change in link status. lan78xx_set_eee() now just programs the hardware with the LTI timer value, and passed everything else to phylib, so it can correctly setup the PHY. lan743x_get_eee() relies on phylib doing most of the work, the MAC driver just adds the LTI timer value. Signed-off-by: Andrew Lunn --- v3: Fixup compiler error, missing read in read/modify/write. --- drivers/net/usb/lan78xx.c | 42 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index c458c030fadf..729183e57080 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -1690,17 +1690,10 @@ static int lan78xx_get_eee(struct net_device *net, struct ethtool_eee *edata) ret = lan78xx_read_reg(dev, MAC_CR, &buf); if (buf & MAC_CR_EEE_EN_) { - edata->eee_enabled = true; - edata->eee_active = !!(edata->advertised & - edata->lp_advertised); - edata->tx_lpi_enabled = true; /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */ ret = lan78xx_read_reg(dev, EEE_TX_LPI_REQ_DLY, &buf); edata->tx_lpi_timer = buf; } else { - edata->eee_enabled = false; - edata->eee_active = false; - edata->tx_lpi_enabled = false; edata->tx_lpi_timer = 0; } @@ -1721,24 +1714,16 @@ static int lan78xx_set_eee(struct net_device *net, struct ethtool_eee *edata) if (ret < 0) return ret; - if (edata->eee_enabled) { - ret = lan78xx_read_reg(dev, MAC_CR, &buf); - buf |= MAC_CR_EEE_EN_; - ret = lan78xx_write_reg(dev, MAC_CR, buf); - - phy_ethtool_set_eee(net->phydev, edata); - - buf = (u32)edata->tx_lpi_timer; - ret = lan78xx_write_reg(dev, EEE_TX_LPI_REQ_DLY, buf); - } else { - ret = lan78xx_read_reg(dev, MAC_CR, &buf); - buf &= ~MAC_CR_EEE_EN_; - ret = lan78xx_write_reg(dev, MAC_CR, buf); - } + ret = phy_ethtool_set_eee(net->phydev, edata); + if (ret < 0) + goto out; + buf = (u32)edata->tx_lpi_timer; + ret = lan78xx_write_reg(dev, EEE_TX_LPI_REQ_DLY, buf); +out: usb_autopm_put_interface(dev->intf); - return 0; + return ret; } static u32 lan78xx_get_link(struct net_device *net) @@ -2114,7 +2099,20 @@ static void lan78xx_remove_mdio(struct lan78xx_net *dev) static void lan78xx_link_status_change(struct net_device *net) { + struct lan78xx_net *dev = netdev_priv(net); struct phy_device *phydev = net->phydev; + u32 data; + int ret; + + ret = lan78xx_read_reg(dev, MAC_CR, &data); + if (ret < 0) + return; + + if (phydev->eee_active) + data |= MAC_CR_EEE_EN_; + else + data &= ~MAC_CR_EEE_EN_; + lan78xx_write_reg(dev, MAC_CR, data); phy_print_status(phydev); } From patchwork Fri Mar 31 00:55:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195119 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 330F2C761AF for ; Fri, 31 Mar 2023 00:55:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbjCaAzx (ORCPT ); Thu, 30 Mar 2023 20:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbjCaAzp (ORCPT ); Thu, 30 Mar 2023 20:55:45 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04194EFAC for ; Thu, 30 Mar 2023 17:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=SUC3bTy6Yk5Z8jpuY5i1NZkacvWXZt5TkotdG1rBY0A=; b=eOe+xm5ppWFV2WHcjOAVtsgcuD N1DTm3Yuch79tC+zlx5j2KRdVDiGswDeW38Sy/Yi0PJl/tNkIdghE52IIvEZgj+0NXif2TXa5+8Aa 6B9NKlnCYexdMN+PJAS6Xg36HCwgNeN/RDEDumgYsUMjaajxSp2TizU/eaVUapK3FVPw=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33L-008xLN-W3; Fri, 31 Mar 2023 02:55:39 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 20/24] net: phy: Add phy_support_eee() indicating MAC support EEE Date: Fri, 31 Mar 2023 02:55:14 +0200 Message-Id: <20230331005518.2134652-21-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC In order for EEE to operate, both the MAC and the PHY need to support it, similar to how pause works. Copy the pause concept and add the call phy_support_eee() which the MAC makes after connecting the PHY to indicate it supports EEE. phylib will then advertise EEE when auto-neg is performed. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- drivers/net/phy/phy_device.c | 16 ++++++++++++++++ include/linux/phy.h | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c0760cbf534b..30f07623637b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2760,6 +2760,22 @@ void phy_advertise_supported(struct phy_device *phydev) } EXPORT_SYMBOL(phy_advertise_supported); +/** + * phy_support_eee - Enable support of EEE + * @phydev: target phy_device struct + * + * Description: Called by the MAC to indicate is supports Energy + * Efficient Ethernet. This should be called before phy_start() in + * order that EEE is negotiated when the link comes up as part of + * phy_start(). + */ +void phy_support_eee(struct phy_device *phydev) +{ + linkmode_copy(phydev->advertising_eee, phydev->supported_eee); + phydev->tx_lpi_enabled = true; +} +EXPORT_SYMBOL(phy_support_eee); + /** * phy_support_sym_pause - Enable support of symmetrical pause * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index af199fcc52b2..85f66c905fef 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -683,7 +683,7 @@ struct phy_device { __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); /* used with phy_speed_down */ __ETHTOOL_DECLARE_LINK_MODE_MASK(adv_old); - /* used for eee validation */ + /* used for eee validation and configuration*/ __ETHTOOL_DECLARE_LINK_MODE_MASK(supported_eee); __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising_eee); bool eee_enabled; @@ -1824,6 +1824,7 @@ void phy_remove_link_mode(struct phy_device *phydev, u32 link_mode); void phy_advertise_supported(struct phy_device *phydev); void phy_support_sym_pause(struct phy_device *phydev); void phy_support_asym_pause(struct phy_device *phydev); +void phy_support_eee(struct phy_device *phydev); void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx, bool autoneg); void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx); From patchwork Fri Mar 31 00:55:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195124 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 656EFC761AF for ; Fri, 31 Mar 2023 00:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbjCaA4A (ORCPT ); Thu, 30 Mar 2023 20:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229851AbjCaAzq (ORCPT ); Thu, 30 Mar 2023 20:55:46 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA6E1042E for ; Thu, 30 Mar 2023 17:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=Yg/2dJzWMvYIFv1CqxSeP+R8BAfCeyF2/k8+iXX0Xzg=; b=k9WOhifDdsk5zoDJokWjX09M/y J6sS0DY9nUqqFPhwAKQIix3nn+k1QhbEg8IhFI8c27KAPOrLOHgkJKlXzF2UPJAYiXdxnVzXwAVTP ZA4SbsobLAANORX9UX7oBzsN10DSixJW2HZtqj16vISkGVlLcd/oG1oAAEsE3aAoX848=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33M-008xLR-0y; Fri, 31 Mar 2023 02:55:40 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 21/24] net: phylink: Add MAC_EEE to mac_capabilites Date: Fri, 31 Mar 2023 02:55:15 +0200 Message-Id: <20230331005518.2134652-22-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC If the MAC supports Energy Efficient Ethernet, it should indicate this by setting the MAC_EEE bit in the config.mac_capabilities bitmap. phylink will then enable EEE in the PHY, if it supports it. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli --- v3: Move MAC_EEE to BIT(2) and renumber link modes. --- drivers/net/phy/phylink.c | 3 +++ include/linux/phylink.h | 39 ++++++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 61e4502086c3..191cafd37e62 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1647,6 +1647,9 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, */ phy_support_asym_pause(phy); + if (pl->config->mac_capabilities & MAC_EEE) + phy_support_eee(phy); + memset(&config, 0, sizeof(config)); linkmode_copy(supported, phy->supported); linkmode_copy(config.advertising, phy->advertising); diff --git a/include/linux/phylink.h b/include/linux/phylink.h index 52f29b648853..cb5204fb9106 100644 --- a/include/linux/phylink.h +++ b/include/linux/phylink.h @@ -52,26 +52,31 @@ enum { */ MAC_SYM_PAUSE = BIT(0), MAC_ASYM_PAUSE = BIT(1), - MAC_10HD = BIT(2), - MAC_10FD = BIT(3), + + /* MAC_EEE indicates that the MAC is Energy Efficient capable + * and that the PHY should negotiate its use, if possible + */ + MAC_EEE = BIT(2), + MAC_10HD = BIT(3), + MAC_10FD = BIT(4), MAC_10 = MAC_10HD | MAC_10FD, - MAC_100HD = BIT(4), - MAC_100FD = BIT(5), + MAC_100HD = BIT(5), + MAC_100FD = BIT(6), MAC_100 = MAC_100HD | MAC_100FD, - MAC_1000HD = BIT(6), - MAC_1000FD = BIT(7), + MAC_1000HD = BIT(7), + MAC_1000FD = BIT(8), MAC_1000 = MAC_1000HD | MAC_1000FD, - MAC_2500FD = BIT(8), - MAC_5000FD = BIT(9), - MAC_10000FD = BIT(10), - MAC_20000FD = BIT(11), - MAC_25000FD = BIT(12), - MAC_40000FD = BIT(13), - MAC_50000FD = BIT(14), - MAC_56000FD = BIT(15), - MAC_100000FD = BIT(16), - MAC_200000FD = BIT(17), - MAC_400000FD = BIT(18), + MAC_2500FD = BIT(9), + MAC_5000FD = BIT(10), + MAC_10000FD = BIT(11), + MAC_20000FD = BIT(12), + MAC_25000FD = BIT(13), + MAC_40000FD = BIT(14), + MAC_50000FD = BIT(15), + MAC_56000FD = BIT(16), + MAC_100000FD = BIT(17), + MAC_200000FD = BIT(18), + MAC_400000FD = BIT(19), }; static inline bool phylink_autoneg_inband(unsigned int mode) From patchwork Fri Mar 31 00:55:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195132 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 58A77C761AF for ; Fri, 31 Mar 2023 00:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjCaA4L (ORCPT ); Thu, 30 Mar 2023 20:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjCaAzs (ORCPT ); Thu, 30 Mar 2023 20:55:48 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E022CA30 for ; Thu, 30 Mar 2023 17:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=RCuP5Gl3E6IZNAqlJ2JcW/mqur+qGEdqu2d0PBfr/04=; b=XmkvxQ7MEPBk2yXhtnxBl/E/U9 RqhqUVcd5PL9jMS6G48jHvakuSLpLrpVaQOSKBJ28klirbRbnqM/X6RulD85Vetb4/+jV9AWjnzH+ O+A94i5ClAH4Iwmu7oc7to3JwLzxkym/2zJ4n99hX5T3XcPHWP9odVK1dDeNqIEsh0uY=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33M-008xLV-24; Fri, 31 Mar 2023 02:55:40 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 22/24] net: phylink: Extend mac_capabilities in MAC drivers which support EEE Date: Fri, 31 Mar 2023 02:55:16 +0200 Message-Id: <20230331005518.2134652-23-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC For MAC drivers making use of phylink, and which support EEE, set the MAC_EEE bit in the mac_capabilities. Signed-off-by: Andrew Lunn --- drivers/net/ethernet/marvell/mvneta.c | 2 +- drivers/net/ethernet/microchip/lan743x_main.c | 2 ++ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 3 +++ net/dsa/port.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c index fba9edad9e37..efe751da899b 100644 --- a/drivers/net/ethernet/marvell/mvneta.c +++ b/drivers/net/ethernet/marvell/mvneta.c @@ -5450,7 +5450,7 @@ static int mvneta_probe(struct platform_device *pdev) pp->phylink_config.dev = &dev->dev; pp->phylink_config.type = PHYLINK_NETDEV; - pp->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_10 | + pp->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_EEE | MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD; phy_interface_set_rgmii(pp->phylink_config.supported_interfaces); diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c index 7986f8fcf7d3..ad76be484536 100644 --- a/drivers/net/ethernet/microchip/lan743x_main.c +++ b/drivers/net/ethernet/microchip/lan743x_main.c @@ -1543,6 +1543,8 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter) phy->fc_request_control = (FLOW_CTRL_RX | FLOW_CTRL_TX); phy->fc_autoneg = phydev->autoneg; + phy_support_eee(phydev); + phy_start(phydev); phy_start_aneg(phydev); phy_attached_info(phydev); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 190b74d7f4e7..522e6bb9e1fd 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1232,6 +1232,9 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) ~(MAC_10HD | MAC_100HD | MAC_1000HD); priv->phylink_config.mac_managed_pm = true; + if (priv->dma_cap.eee) + priv->phylink_config.mac_capabilities |= MAC_EEE; + phylink = phylink_create(&priv->phylink_config, fwnode, mode, &stmmac_phylink_mac_ops); if (IS_ERR(phylink)) diff --git a/net/dsa/port.c b/net/dsa/port.c index 67ad1adec2a2..68e52abadd7e 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -1696,6 +1696,9 @@ int dsa_port_phylink_create(struct dsa_port *dp) if (ds->ops->phylink_get_caps) ds->ops->phylink_get_caps(ds, dp->index, &dp->pl_config); + if (ds->ops->set_mac_eee && ds->ops->get_mac_eee) + dp->pl_config.mac_capabilities |= MAC_EEE; + pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), mode, &dsa_port_phylink_mac_ops); if (IS_ERR(pl)) { From patchwork Fri Mar 31 00:55:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195133 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 42CF5C7619A for ; Fri, 31 Mar 2023 00:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229933AbjCaA4N (ORCPT ); Thu, 30 Mar 2023 20:56:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229883AbjCaAzs (ORCPT ); Thu, 30 Mar 2023 20:55:48 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8C23113E0 for ; Thu, 30 Mar 2023 17:55:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=fbsSXkNq5cmT+UK/tIKyVFcwVlSNPkI0gdM8ysWtF6k=; b=wHWcb1xVAE18CIV3HAc0rg8OVp vBFIIYaeHd9W7z9gmB1Zl+Q1HqTUnuD/Lw0iXA65GtVwvkYzv0W+SI/rVzfXJ9wWdss12KaJIsSUN qjuKt2y83lrqPVaIc5AiaTXSfnNwjDOmI7Lx10Zwc1ufeWLXIig24pKgQsVxjFN5Wjmk=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33M-008xLZ-3J; Fri, 31 Mar 2023 02:55:40 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 23/24] net: phylib: call phy_support_eee() in MAC drivers which support EEE Date: Fri, 31 Mar 2023 02:55:17 +0200 Message-Id: <20230331005518.2134652-24-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC For MAC drivers making use of phylib, and which support EEE, call phy_support_eee() before starting the PHY. Signed-off-by: Andrew Lunn --- drivers/net/ethernet/broadcom/genet/bcmmii.c | 2 ++ drivers/net/ethernet/freescale/fec_main.c | 3 +++ drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 3 +++ drivers/net/usb/lan78xx.c | 2 ++ 4 files changed, 10 insertions(+) diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c index 6c39839762a7..4175042865ec 100644 --- a/drivers/net/ethernet/broadcom/genet/bcmmii.c +++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c @@ -376,6 +376,8 @@ int bcmgenet_mii_probe(struct net_device *dev) } } + phy_support_eee(dev->phydev); + /* Configure port multiplexer based on what the probed PHY device since * reading the 'max-speed' property determines the maximum supported * PHY speed which is needed for bcmgenet_mii_config() to configure diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index fda1f9ff32b9..09c55430c614 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -2348,6 +2348,9 @@ static int fec_enet_mii_probe(struct net_device *ndev) else phy_set_max_speed(phy_dev, 100); + if (fep->quirks & FEC_QUIRK_HAS_EEE) + phy_support_eee(phy_dev); + fep->link = 0; fep->full_duplex = 0; diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c index cf549a524674..060280c4bc0a 100644 --- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c +++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c @@ -286,6 +286,9 @@ static int sxgbe_init_phy(struct net_device *ndev) return -ENODEV; } + if (priv->hw_cap.eee) + phy_support_eee(phydev); + netdev_dbg(ndev, "%s: attached to PHY (UID 0x%x) Link = %d\n", __func__, phydev->phy_id, phydev->link); diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 729183e57080..fcf367ad9b0b 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -2406,6 +2406,8 @@ static int lan78xx_phy_init(struct lan78xx_net *dev) mii_adv_to_linkmode_adv_t(fc, mii_adv); linkmode_or(phydev->advertising, fc, phydev->advertising); + phy_support_eee(phydev); + if (phydev->mdio.dev.of_node) { u32 reg; int len; From patchwork Fri Mar 31 00:55:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Lunn X-Patchwork-Id: 13195135 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 CB56BC761AF for ; Fri, 31 Mar 2023 00:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229943AbjCaA4Q (ORCPT ); Thu, 30 Mar 2023 20:56:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbjCaAzs (ORCPT ); Thu, 30 Mar 2023 20:55:48 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6A35D322 for ; Thu, 30 Mar 2023 17:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:From:Sender:Reply-To:Subject:Date: Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=cfp1FqY7Y8E92284N8DFBdTLetOjaw0pAoiT5v+E6D8=; b=Z+Z8vF87nB19u46tqStAFy4Ome ETzpMW6tX4MPVtpBG+TjQnGW/O8bg2B5O3EA3t00WEfcHulfgj0KpVpN7ZCOrkNkd7wOYgeNz2ZCR Q30jKeZgrgOusKhFXvtv4QJIrEYUvQYbcUS7dVT5c+yEYgX1C1ws5i0dPk2mlk3XK0L8=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1pi33M-008xLd-8G; Fri, 31 Mar 2023 02:55:40 +0200 From: Andrew Lunn To: netdev Cc: Florian Fainelli , Heiner Kallweit , Russell King , Oleksij Rempel , Andrew Lunn Subject: [RFC/RFTv3 24/24] net: phy: Disable EEE advertisement by default Date: Fri, 31 Mar 2023 02:55:18 +0200 Message-Id: <20230331005518.2134652-25-andrew@lunn.ch> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230331005518.2134652-1-andrew@lunn.ch> References: <20230331005518.2134652-1-andrew@lunn.ch> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC EEE should only be advertised if the MAC supports it. Clear advertising_eee by default. If the MAC indicates it supports EEE by calling phy_support_eee() advertising_eee will be set to supported_eee. When the PHY is started, EEE registers will then be configured. Signed-off-by: Andrew Lunn --- drivers/net/phy/phy_device.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 30f07623637b..0a5936a81ee6 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3153,24 +3153,11 @@ static int phy_probe(struct device *dev) of_set_phy_supported(phydev); phy_advertise_supported(phydev); - /* Get PHY default EEE advertising modes and handle them as potentially - * safe initial configuration. + /* Clear EEE advertising until the MAC indicates it also + * supports EEE. */ - err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee); - if (err) - goto out; - - /* There is no "enabled" flag. If PHY is advertising, assume it is - * kind of enabled. - */ - phydev->eee_enabled = !linkmode_empty(phydev->advertising_eee); - - /* Some PHYs may advertise, by default, not support EEE modes. So, - * we need to clean them. - */ - if (phydev->eee_enabled) - linkmode_and(phydev->advertising_eee, phydev->supported_eee, - phydev->advertising_eee); + linkmode_zero(phydev->advertising_eee); + phydev->eee_enabled = false; /* Get the EEE modes we want to prohibit. We will ask * the PHY stop advertising these mode later on