Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp458606lqb; Thu, 29 Feb 2024 06:09:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVa1lilOGFygMDw8xGNg1Esh/nqkB45sU8CZY58tAQT22wGU9jURvkb+/hs1RqRqyPJtYxBFpdaHCQhISm1bl2A1bO91glWnQmEME4LEQ== X-Google-Smtp-Source: AGHT+IEH8YdQaEhWChpjV7fzfZgAw5hNXqNLQUUlg4E2IgGpJNbZq3Hwh7/PaC8I6mrX/h1zDEvr X-Received: by 2002:a92:dccd:0:b0:365:55fb:9944 with SMTP id b13-20020a92dccd000000b0036555fb9944mr2302182ilr.4.1709215746069; Thu, 29 Feb 2024 06:09:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709215746; cv=pass; d=google.com; s=arc-20160816; b=zjPxviPDd9mdhEHe559lCNMzvYvRYQsYMEblvj2hUIdxrcs4DVG0Emmamtg+P5J8js /GcGh1CQnd2+0QimqppdiO5n7/26XJU2xrczkHPlmOOgLvnJzX6/B5nDJfV7aoHjvNpH XdQOLe4dd5oMolEbF1rHP5go5M9ehaUds9ND2A3f+0bMnVrGJjwVGqDlp4oEDAGREsaK S6up9A0V6LB3z3tufeSqDd64uNjfSkJkcvUo/MDgmnnSrI4L7lYAJz7s/444BZziOL5F 79ufp8rPVdRVXZ5UKfUXSxRyvNzZypAl1EMSrfgKTvBmgvNNchXSqljA5jZekCuxa7Vn IuXA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=4bULncGuAiU59VwkZcHHG9hU4TEDsp1GWopva5HUlwU=; fh=/mFbHcqW6l4fLIJBfKVNbHEV0oGb2iio8Q6EPf9P78A=; b=wKryiD0bUaAesG5fcO3Yrl68eybj73DvzkEnOI/QiW33+HOBWblkHnifTl4jSH85Tu Qypjn1W07gjeRXPWb6ZFV+yOqUJ7uckdwsMUSdjr8FZAjeDMjMW9Dp3Dvl7ewqkPWJ3H xAVVWa/lcltdqVtPpoy1kDmPI7Fb67gmycsBl/EA8GlkXDmJYks8TMT4DwCRrioK1zi1 Ph+3sSq84S0u+m8L9y/QPdYSWtS0K84Mb/07eUbavRL63tn0epShCuOaomBbyyVMtkwA c5w9vu0NY2Q8VSKaaiBMJuQFKznF0ZWjy7snPa/AtNfK7rJSmlIsC08i2pBuAmNKUKVp t+ng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-86800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86800-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a16-20020a92c710000000b00365037a3c68si479221ilp.158.2024.02.29.06.09.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 06:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-86800-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86800-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B9D1B28650C for ; Thu, 29 Feb 2024 14:09:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9384D137750; Thu, 29 Feb 2024 14:08:24 +0000 (UTC) Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C94E712F368 for ; Thu, 29 Feb 2024 14:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709215703; cv=none; b=PDsq5fU/eDJJMcgnRnThrmSu9uyhksaYLP9fC5Z9zTR26/5c1m3orgaU3S5T4kKJmx8cr2z2VECS05GNvuAKXRt2gFtu+mX17IIjtNLsalu5jQQPgngo87Dg+GAFa+GuIyZEA16WdpBpihFYfjiJvwM++jmpz52O2A7X/ELsThQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709215703; c=relaxed/simple; bh=EjUlI4B+nyCavzxwMEbYsYK3pVkIBH0qY41+5ui6lDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QRit6Lliyfh3fTZ53goPz1hlKMh3aOltcJ1QlEZdJ+Jq4QEiFWqv1vl65N97Z5+E6uoa+8obGUe5vATMFakj9lVyjYZTuBF5a5CjX75lWT3V9kc3IjT5Hr9iG+6ekO04wqZMUpoJirEjOFavquY2glu+Pi41rThZ6hH+mJUv+G4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rfh4t-0000Sw-MV; Thu, 29 Feb 2024 15:08:03 +0100 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfh4s-003ba0-0Q; Thu, 29 Feb 2024 15:08:02 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rfh4r-00ELmj-2a; Thu, 29 Feb 2024 15:08:01 +0100 From: Oleksij Rempel To: Wei Fang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Russell King Cc: Florian Fainelli , Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Shenwei Wang , Clark Wang , NXP Linux Team Subject: [PATCH net-next v7 5/8] net: phy: Immediately call adjust_link if only tx_lpi_enabled changes Date: Thu, 29 Feb 2024 15:07:57 +0100 Message-Id: <20240229140800.3420180-6-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240229140800.3420180-1-o.rempel@pengutronix.de> References: <20240229140800.3420180-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org From: Andrew Lunn The MAC driver changes its EEE hardware configuration in its adjust_link callback. This is called when auto-neg completes. Disabling EEE via eee_enabled false will trigger an autoneg, and as a result the adjust_link callback will be called with phydev->enable_tx_lpi set to false. Similarly, eee_enabled set to true and with a change of advertised link modes will result in a new autoneg, and a call the adjust_link call. If set_eee is called with only 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->enable_tx_lpi, take both eee_enabled and tx_lpi_enabled into account, so the MAC drivers just needs to act on phydev->enable_tx_lpi and not the whole EEE configuration. The same check should be done for tx_lpi_timer too. Signed-off-by: Andrew Lunn Reviewed-by: Florian Fainelli Signed-off-by: Oleksij Rempel --- v7: remove ' comment and parenthesis or return v8: - add phy_link_down() before phy_link_up() - rewrite comment for phy_ethtool_set_eee_noneg() - add check for changed tx_lpi_timer --- drivers/net/phy/phy-c45.c | 14 ++++++++++++-- drivers/net/phy/phy.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index 3e95b8a15f442..5695935fdce97 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -1550,6 +1550,8 @@ EXPORT_SYMBOL(genphy_c45_ethtool_get_eee); * advertised, but the previously advertised link modes are * retained. This allows EEE to be enabled/disabled in a * non-destructive way. + * Returns either error code, 0 if there was no change, or positive + * value if there was a change which triggered auto-neg. */ int genphy_c45_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data) @@ -1576,8 +1578,16 @@ int genphy_c45_ethtool_set_eee(struct phy_device *phydev, phydev->eee_enabled = data->eee_enabled; ret = genphy_c45_an_config_eee_aneg(phydev); - if (ret > 0) - return phy_restart_aneg(phydev); + if (ret > 0) { + ret = phy_restart_aneg(phydev); + if (ret < 0) + return ret; + + /* explicitly return 1, otherwise (ret > 0) value will be + * overwritten by phy_restart_aneg(). + */ + return 1; + } return ret; } diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index f0ed07c74a36e..8216061ff0e34 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -988,7 +988,8 @@ static int phy_check_link_status(struct phy_device *phydev) if (err < 0) phydev->enable_tx_lpi = false; else - phydev->enable_tx_lpi = !!err; + phydev->enable_tx_lpi = (err & phydev->eee_cfg.tx_lpi_enabled); + phy_link_up(phydev); } else if (!phydev->link && phydev->state != PHY_NOLINK) { phydev->state = PHY_NOLINK; @@ -1679,6 +1680,34 @@ int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_keee *data) } EXPORT_SYMBOL(phy_ethtool_get_eee); +/** + * phy_ethtool_set_eee_noneg - Adjusts MAC LPI configuration without PHY + * renegotiation + * @phydev: pointer to the target PHY device structure + * @data: pointer to the ethtool_keee structure containing the new EEE settings + * + * This function updates the Energy Efficient Ethernet (EEE) configuration + * for cases where only the MAC's Low Power Idle (LPI) configuration changes, + * without triggering PHY renegotiation. It ensures that the MAC is properly + * informed of the new LPI settings by cycling the link down and up, which + * is necessary for the MAC to adopt the new configuration. This adjustment + * is done only if there is a change in the tx_lpi_enabled or tx_lpi_timer + * configuration. + */ +static void phy_ethtool_set_eee_noneg(struct phy_device *phydev, + struct ethtool_keee *data) +{ + if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled || + phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) { + eee_to_eeecfg(data, &phydev->eee_cfg); + phydev->enable_tx_lpi = eeecfg_mac_can_tx_lpi(&phydev->eee_cfg); + if (phydev->link) { + phy_link_down(phydev); + phy_link_up(phydev); + } + } +} + /** * phy_ethtool_set_eee - set EEE supported and status * @phydev: target phy_device struct @@ -1695,11 +1724,14 @@ int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data) mutex_lock(&phydev->lock); ret = genphy_c45_ethtool_set_eee(phydev, data); - if (!ret) + if (ret >= 0) { + if (ret == 0) + phy_ethtool_set_eee_noneg(phydev, data); eee_to_eeecfg(data, &phydev->eee_cfg); + } mutex_unlock(&phydev->lock); - return ret; + return ret < 0 ? ret : 0; } EXPORT_SYMBOL(phy_ethtool_set_eee); -- 2.39.2