From nobody Sat Jan 4 23:08:10 2025 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 C9E46282EE for ; Sat, 21 Dec 2024 08:15:49 +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=1734768951; cv=none; b=oD2HXRORH+rhZe89SsgLRom+dz6wRZJ5FA8tMjf7lY2Ox8M8AOp/nJ9A/nufU+SOh7l9IShkgwJswPeS/HSnJ0NvodA2C4k9Bian3BxdXxSRKHzDKDUlKAwA+n/lhnaj4VShZYEAbgaWdQm6bbM35uFcJvLWdIpBNuoVLIFQFQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734768951; c=relaxed/simple; bh=IezSPtzCA+GIk5IpkRFZvleekPS1quzOod7dsNbrjWo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y6ACu5Xl64Fwq+d6vfXQHKFydMzLKEMakpzZQqAuVFsJtMSP3+AnW1sSEHagNxzbbLYwBJI8VaSUDxU8jqXKPTcUdMQ7q/RHAssbMEdb7fgrhYuSe/Afa5KElSlbCAlJK8R2AliApq39L/0ygYEKi2SlVLgpFqVbrpAebbr+xCs= 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 1tOue8-0000Qm-3p; Sat, 21 Dec 2024 09:15:36 +0100 Received: from dude04.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::ac]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tOue2-004Vdo-2p; Sat, 21 Dec 2024 09:15:31 +0100 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1tOue3-00CbSj-1r; Sat, 21 Dec 2024 09:15:31 +0100 From: Oleksij Rempel To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Heiner Kallweit , Jonathan Corbet Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Simon Horman , Russell King , Maxime Chevallier , linux-doc@vger.kernel.org Subject: [PATCH net-next v4 1/8] ethtool: linkstate: migrate linkstate functions to support multi-PHY setups Date: Sat, 21 Dec 2024 09:15:23 +0100 Message-Id: <20241221081530.3003900-2-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241221081530.3003900-1-o.rempel@pengutronix.de> References: <20241221081530.3003900-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: quoted-printable 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 Content-Type: text/plain; charset="utf-8" Adapt linkstate_get_sqi() and linkstate_get_sqi_max() to take a phy_device argument directly, enabling support for setups with multiple PHYs. The previous assumption of a single PHY attached to a net_device no longer holds. Use ethnl_req_get_phydev() to identify the appropriate PHY device for the operation. Update linkstate_prepare_data() and related logic to accommodate this change, ensuring compatibility with multi-PHY configurations. Signed-off-by: Oleksij Rempel --- changes v3: - s/ETHTOOL_A_PLCA_HEADER/ETHTOOL_A_LINKSTATE_HEADER --- net/ethtool/linkstate.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c index 34d76e87847d..459cfea7652d 100644 --- a/net/ethtool/linkstate.c +++ b/net/ethtool/linkstate.c @@ -26,9 +26,8 @@ const struct nla_policy ethnl_linkstate_get_policy[] =3D { NLA_POLICY_NESTED(ethnl_header_policy_stats), }; =20 -static int linkstate_get_sqi(struct net_device *dev) +static int linkstate_get_sqi(struct phy_device *phydev) { - struct phy_device *phydev =3D dev->phydev; int ret; =20 if (!phydev) @@ -46,9 +45,8 @@ static int linkstate_get_sqi(struct net_device *dev) return ret; } =20 -static int linkstate_get_sqi_max(struct net_device *dev) +static int linkstate_get_sqi_max(struct phy_device *phydev) { - struct phy_device *phydev =3D dev->phydev; int ret; =20 if (!phydev) @@ -100,19 +98,28 @@ static int linkstate_prepare_data(const struct ethnl_r= eq_info *req_base, { struct linkstate_reply_data *data =3D LINKSTATE_REPDATA(reply_base); struct net_device *dev =3D reply_base->dev; + struct nlattr **tb =3D info->attrs; + struct phy_device *phydev; int ret; =20 + phydev =3D ethnl_req_get_phydev(req_base, tb[ETHTOOL_A_LINKSTATE_HEADER], + info->extack); + if (IS_ERR(phydev)) { + ret =3D PTR_ERR(phydev); + goto out; + } + ret =3D ethnl_ops_begin(dev); if (ret < 0) return ret; data->link =3D __ethtool_get_link(dev); =20 - ret =3D linkstate_get_sqi(dev); + ret =3D linkstate_get_sqi(phydev); if (linkstate_sqi_critical_error(ret)) goto out; data->sqi =3D ret; =20 - ret =3D linkstate_get_sqi_max(dev); + ret =3D linkstate_get_sqi_max(phydev); if (linkstate_sqi_critical_error(ret)) goto out; data->sqi_max =3D ret; @@ -127,9 +134,9 @@ static int linkstate_prepare_data(const struct ethnl_re= q_info *req_base, sizeof(data->link_stats) / 8); =20 if (req_base->flags & ETHTOOL_FLAG_STATS) { - if (dev->phydev) + if (phydev) data->link_stats.link_down_events =3D - READ_ONCE(dev->phydev->link_down_events); + READ_ONCE(phydev->link_down_events); =20 if (dev->ethtool_ops->get_link_ext_stats) dev->ethtool_ops->get_link_ext_stats(dev, --=20 2.39.5