From patchwork Fri Feb 23 09:44:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 205272 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp482156dyb; Fri, 23 Feb 2024 01:56:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXGVQW+0PNi6FAVcJWAh57+mU8xwF1HEzH8R/xOnkkyzDeyysoELwpMq2RAwwGXSVTySI4iJBcROrVBpeWlQfRPNcWNbA== X-Google-Smtp-Source: AGHT+IH6G7ME5RmSIiy35QUyoQ3JRqOopdpNwJFcvAC4QOitALlCfutI1GauSZUb8/ntQ0Fk9ACu X-Received: by 2002:a17:902:6f08:b0:1dc:2120:2467 with SMTP id w8-20020a1709026f0800b001dc21202467mr1142030plk.44.1708682191727; Fri, 23 Feb 2024 01:56:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708682191; cv=pass; d=google.com; s=arc-20160816; b=vT45KkgX0hKhXPX603uwaq/EzrmC3QQX6x1dhRVP4bWJl//de0Zwq+zzmBtvLdX5Th /FTpStr2KqIW00Md+h8K8ezE8h8cIUkqZ5C7usgWrsYAuPHFObuK1aOssvCsa2hM6QlE L5eRgTYPqoGcC1tl2jJ805dxWOITOnjhIMs8guGQom+spF6ViCfY+FHSewvHBCg/2XR1 mXIr3OE1DQkREPKMwJxG5OKXUdWXJsOwVfm9LKYCGUTtSF7VnC/9XkvEia+spv1rS0xk Uq5Ka02qFlzXWwkSM3ccNO8NnmVmGlclTFFah08NjXssM+1hMXKPnxF8Cw4nVK2u/1Iy 3gKw== 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=uMZz3Rym5sPkSk5AavCCPES8XuvGaOlsetdtNgLDqX4=; fh=/mFbHcqW6l4fLIJBfKVNbHEV0oGb2iio8Q6EPf9P78A=; b=RVI+MkF1iM/BDKPLnkfd0wgSMp5Ib2fWi3cZLha2Y8Q8YPebYcdHjhxMDSOxeZ8KaY yRebEiFuikgN1mLL+4lcBuU0mSqhlCl+GNskdW2B7TgpeSV6z2lXWg227tJndAFZlK89 /TSpTcWdaCBQRzbiUwt5OZR7GspeBFVj1hWBii9XiNxpHrhMLKUHGj7UeGdJ3KxvPESt bx1bDhkK6FlyU+yjP46J4PoPpfEAMl/1cL4Wu7mFff9URKUe5CIb7wqvBSojPMeSrt6i O6JOwjquKmhNML8q9NK2VtoE7x1LNwUW6j9djaE3lO/Nwzfdnwe0Ng89oVxdIfcq0iOM XP5A==; 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-78062-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78062-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id a10-20020a170902ee8a00b001da2c896119si11592516pld.432.2024.02.23.01.56.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 01:56:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78062-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=pengutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-78062-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78062-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id BB0A7B26C5A for ; Fri, 23 Feb 2024 09:48:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D968D5FDCD; Fri, 23 Feb 2024 09:45:01 +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 D08175EE71 for ; Fri, 23 Feb 2024 09:44:42 +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=1708681491; cv=none; b=iIpWLO8So57ergRLeRJkF4IGiD/MzYdLy5NbQclxuEMylMURPhE+Uh9DqWLHOE9fs46ABEogaTxKrRMxHp+iEBDddeyNWgpr4tqwd0VFoSWMhBCZwZcoXp4LQn6KHKmSJanS81klx1T6mihKuAYJpOiWe3F6EcEBSCaAIGQoTAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681491; c=relaxed/simple; bh=JmFgZtEJFcZh4DjZNnu6vM0KJrQ9j13y+0zGMDqBKA4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N2UPUoH+GEH8mEhiHAsXfypKoPg8Cr0kFLd00yiv0mB0W40QgbVkJlcF1QNJkz2yQQaU41IHceJfgkTj/a6JinimdxnLAEitenxjvLFw//120I0eFgDNk7eVX4GVI84kuUa3td5/ML1ftWLDlCSnIE7oHVYgX+VnFm8uUQ0/RzM= 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 1rdS6W-00080m-LP; Fri, 23 Feb 2024 10:44:28 +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 1rdS6V-002OkT-Aq; Fri, 23 Feb 2024 10:44:27 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rdS6V-002tpb-0o; Fri, 23 Feb 2024 10:44:27 +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 v6 2/8] net: phy: Add phydev->enable_tx_lpi to simplify adjust link callbacks Date: Fri, 23 Feb 2024 10:44:19 +0100 Message-Id: <20240223094425.691209-3-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223094425.691209-1-o.rempel@pengutronix.de> References: <20240223094425.691209-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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791683137840965727 X-GMAIL-MSGID: 1791683137840965727 From: Andrew Lunn 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->enable_tx_lpi 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. If enable_tx_lpi is true, the MAC should send low power indications and does not need to consider anything else with respect to EEE. Reviewed-by: Florian Fainelli Signed-off-by: Andrew Lunn Signed-off-by: Oleksij Rempel --- v2: Check for errors from genphy_c45_eee_is_active v5: Rename to enable_tx_lpi to fit better with phylink changes v6: enable_tx_lpi = !!err --- drivers/net/phy/phy.c | 7 +++++++ include/linux/phy.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 14224e06d69f..2bc0a7d51c63 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -983,9 +983,16 @@ 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; + err = genphy_c45_eee_is_active(phydev, + NULL, NULL, NULL); + if (err < 0) + phydev->enable_tx_lpi = false; + else + phydev->enable_tx_lpi = !!err; phy_link_up(phydev); } else if (!phydev->link && phydev->state != PHY_NOLINK) { phydev->state = PHY_NOLINK; + phydev->enable_tx_lpi = false; phy_link_down(phydev); } diff --git a/include/linux/phy.h b/include/linux/phy.h index e3ab2c347a59..a880f6d7170e 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -594,6 +594,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 + * @enable_tx_lpi: When True, MAC should transmit LPI to PHY * @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 @@ -713,6 +714,7 @@ struct phy_device { /* Energy efficient ethernet modes which should be prohibited */ u32 eee_broken_modes; + bool enable_tx_lpi; #ifdef CONFIG_LED_TRIGGER_PHY struct phy_led_trigger *phy_led_triggers;