From nobody Mon Feb 9 02:13:18 2026 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 5E7341468F6; Tue, 20 Feb 2024 18:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454553; cv=none; b=CEUTiabGGBt6XQRokH8wprzMIt2ubHFrqJpQmEHd9a4dTHI2BhHbiomu1xpLODMlhlz9rbCDrFd9kgx/21FxZmKtd1vMVq0v23rlPPDmRw/rwMl8S3WHU0T1se5JZxuCe5C6R/rKcAXy6DLJIIb+QzlYYrmj8ykjHM3QC2QCT6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708454553; c=relaxed/simple; bh=rujjtNcSPg7Ek/BmCmnyg0LsGshClWOmSaCsRf+8L6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZBGdgk37Yn3xne/bHS2lUsBYLs1Pw1oKsYN+4UA9IcHHojoNQ1kKqbcGXJCiALa+xeF+rFlafZdbAhxoaEOWKbIrA43PCn8Wev+v4UqmSCez49YajwvlbUe8bCOf2KuCYNG61mB42ORACgqWhY67yZIyG2QvD6TF0u6V4eSjeZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=QjNurYbt; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="QjNurYbt" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1639A6000D; Tue, 20 Feb 2024 18:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708454549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P8IuwAuTUhXFrJO3/E30Av0QTrxdWPt1nWTG7/ulps4=; b=QjNurYbtVYakfZbS0Z9TvyekstAsW14LtY2d06n4xpHcRxQHWAyRRwKt/PvcHntu1Syb9D cWPIbKuxSCtnwDojLQSHHPMKfgFHPbUcsk3ew+u8ngMwGbgyOXJfYfNltIMF6bsv5lxufj tqAiUpnYZKl8OFUhGLKrwi/YxPsQcP2bbNnZcv/nbgpkBTeTCYkoe1vaEcdChVaviJaoBJ ecrr9M1+1y1hoKKBkdsJeR7oOfqSDIJH1azi2W/Q2TrdZFkgjRq/tq1oDEyxsa0iG7spVv vPhfhwJwV93b8daGfTT3CUFyfXt5pkXWiFwXdN9FpZvA8DB4i1NR461mGFnW2w== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Jesse Brandeburg , Jonathan Corbet , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?q?Nicol=C3=B2=20Veronese?= , Simon Horman , mwojtas@chromium.org Subject: [PATCH net-next v8 05/13] net: ethtool: Allow passing a phy index for some commands Date: Tue, 20 Feb 2024 19:42:08 +0100 Message-ID: <20240220184217.3689988-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220184217.3689988-1-maxime.chevallier@bootlin.com> References: <20240220184217.3689988-1-maxime.chevallier@bootlin.com> 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-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" Some netlink commands are target towards ethernet PHYs, to control some of their features. As there's several such commands, add the ability to pass a PHY index in the ethnl request, which will populate the generic ethnl_req_info with the relevant phydev when the command targets a PHY. Signed-off-by: Maxime Chevallier Reviewed-by: Andrew Lunn --- V8: - No changes V7: - No changes V6: - Added dedicated policies when passing a PHY index - Dropped Andrew's R-b as there were changes V5: - Added Andrew's R-b - Fix a typo reported by Simon V4: - No Changes V3: - Fixed the documentation V2: - New patch Documentation/networking/ethtool-netlink.rst | 7 ++++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/netlink.c | 44 +++++++++++++++++++- net/ethtool/netlink.h | 5 +++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/n= etworking/ethtool-netlink.rst index d583d9abf2f8..3ca6c21e74af 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -57,6 +57,7 @@ Structure of this header is ``ETHTOOL_A_HEADER_DEV_INDEX`` u32 device ifindex ``ETHTOOL_A_HEADER_DEV_NAME`` string device name ``ETHTOOL_A_HEADER_FLAGS`` u32 flags common for all requests + ``ETHTOOL_A_HEADER_PHY_INDEX`` u32 phy device index =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 ``ETHTOOL_A_HEADER_DEV_INDEX`` and ``ETHTOOL_A_HEADER_DEV_NAME`` identify = the @@ -81,6 +82,12 @@ the behaviour is backward compatible, i.e. requests from= old clients not aware of the flag should be interpreted the way the client expects. A client must not set flags it does not understand. =20 +``ETHTOOL_A_HEADER_PHY_INDEX`` identify the ethernet PHY the message relat= es to. +As there are numerous commands that are related to PHY configuration, and = because +we can have more than one PHY on the link, the PHY index can be passed in = the +request for the commands that needs it. It is however not mandatory, and i= f it +is not passed for commands that target a PHY, the net_device.phydev pointer +is used, as a fallback that keeps the legacy behaviour. =20 Bit sets =3D=3D=3D=3D=3D=3D=3D=3D diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/etht= ool_netlink.h index 3f89074aa06c..422e8cfdd98c 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -133,6 +133,7 @@ enum { ETHTOOL_A_HEADER_DEV_INDEX, /* u32 */ ETHTOOL_A_HEADER_DEV_NAME, /* string */ ETHTOOL_A_HEADER_FLAGS, /* u32 - ETHTOOL_FLAG_* */ + ETHTOOL_A_HEADER_PHY_INDEX, /* u32 */ =20 /* add new constants above here */ __ETHTOOL_A_HEADER_CNT, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index bd04f28d5cf4..b8f16398ea9d 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -4,6 +4,7 @@ #include #include #include "netlink.h" +#include =20 static struct genl_family ethtool_genl_family; =20 @@ -30,6 +31,24 @@ const struct nla_policy ethnl_header_policy_stats[] =3D { ETHTOOL_FLAGS_STATS), }; =20 +const struct nla_policy ethnl_header_policy_phy[] =3D { + [ETHTOOL_A_HEADER_DEV_INDEX] =3D { .type =3D NLA_U32 }, + [ETHTOOL_A_HEADER_DEV_NAME] =3D { .type =3D NLA_NUL_STRING, + .len =3D ALTIFNAMSIZ - 1 }, + [ETHTOOL_A_HEADER_FLAGS] =3D NLA_POLICY_MASK(NLA_U32, + ETHTOOL_FLAGS_BASIC), + [ETHTOOL_A_HEADER_PHY_INDEX] =3D NLA_POLICY_MIN(NLA_U32, 1), +}; + +const struct nla_policy ethnl_header_policy_phy_stats[] =3D { + [ETHTOOL_A_HEADER_DEV_INDEX] =3D { .type =3D NLA_U32 }, + [ETHTOOL_A_HEADER_DEV_NAME] =3D { .type =3D NLA_NUL_STRING, + .len =3D ALTIFNAMSIZ - 1 }, + [ETHTOOL_A_HEADER_FLAGS] =3D NLA_POLICY_MASK(NLA_U32, + ETHTOOL_FLAGS_STATS), + [ETHTOOL_A_HEADER_PHY_INDEX] =3D NLA_POLICY_MIN(NLA_U32, 1), +}; + int ethnl_ops_begin(struct net_device *dev) { int ret; @@ -89,8 +108,9 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *re= q_info, const struct nlattr *header, struct net *net, struct netlink_ext_ack *extack, bool require_dev) { - struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy)]; + struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy_phy)]; const struct nlattr *devname_attr; + struct phy_device *phydev =3D NULL; struct net_device *dev =3D NULL; u32 flags =3D 0; int ret; @@ -104,7 +124,7 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *r= eq_info, /* No validation here, command policy should have a nested policy set * for the header, therefore validation should have already been done. */ - ret =3D nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy) - 1, header, + ret =3D nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy_phy) - 1, hea= der, NULL, extack); if (ret < 0) return ret; @@ -145,6 +165,26 @@ int ethnl_parse_header_dev_get(struct ethnl_req_info *= req_info, return -EINVAL; } =20 + if (dev) { + if (tb[ETHTOOL_A_HEADER_PHY_INDEX]) { + u32 phy_index =3D nla_get_u32(tb[ETHTOOL_A_HEADER_PHY_INDEX]); + + phydev =3D phy_link_topo_get_phy(dev->link_topo, + phy_index); + if (!phydev) { + NL_SET_ERR_MSG_ATTR(extack, header, + "no phy matches phy index"); + return -EINVAL; + } + } else { + /* If we need a PHY but no phy index is specified, fallback + * to dev->phydev + */ + phydev =3D dev->phydev; + } + } + + req_info->phydev =3D phydev; req_info->dev =3D dev; req_info->flags =3D flags; return 0; diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 9a333a8d04c1..d57a890b5d9e 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -250,6 +250,7 @@ static inline unsigned int ethnl_reply_header_size(void) * @dev: network device the request is for (may be null) * @dev_tracker: refcount tracker for @dev reference * @flags: request flags common for all request types + * @phydev: phy_device connected to @dev this request is for (may be null) * * This is a common base for request specific structures holding data from * parsed userspace request. These always embed struct ethnl_req_info at @@ -259,6 +260,7 @@ struct ethnl_req_info { struct net_device *dev; netdevice_tracker dev_tracker; u32 flags; + struct phy_device *phydev; }; =20 static inline void ethnl_parse_header_dev_put(struct ethnl_req_info *req_i= nfo) @@ -395,9 +397,12 @@ extern const struct ethnl_request_ops ethnl_rss_reques= t_ops; extern const struct ethnl_request_ops ethnl_plca_cfg_request_ops; extern const struct ethnl_request_ops ethnl_plca_status_request_ops; extern const struct ethnl_request_ops ethnl_mm_request_ops; +extern const struct ethnl_request_ops ethnl_phy_request_ops; =20 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS = + 1]; extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_= FLAGS + 1]; +extern const struct nla_policy ethnl_header_policy_phy[ETHTOOL_A_HEADER_PH= Y_INDEX + 1]; +extern const struct nla_policy ethnl_header_policy_phy_stats[ETHTOOL_A_HEA= DER_PHY_INDEX + 1]; extern const struct nla_policy ethnl_strset_get_policy[ETHTOOL_A_STRSET_CO= UNTS_ONLY + 1]; extern const struct nla_policy ethnl_linkinfo_get_policy[ETHTOOL_A_LINKINF= O_HEADER + 1]; extern const struct nla_policy ethnl_linkinfo_set_policy[ETHTOOL_A_LINKINF= O_TP_MDIX_CTRL + 1]; --=20 2.43.2