From nobody Mon Feb 9 10:28:24 2026 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (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 815C524CEE1; Wed, 5 Mar 2025 14:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741184390; cv=none; b=JHyMhYaY5/1iofK8GLh65A7mHUKta/73DN5VQghqTfyT07IG2DX2AOWsxO++g2aJMVg50EYDXvOylFffp4Ofpau032VqB6wwf04M6ay+r9aIyqw5QWpQm5d1LxW09i/D5anO42c+pwu6cZBtltbsfKZHdPbmnlyhrQjAvf9TPeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741184390; c=relaxed/simple; bh=+vhGDgKV4lHQXIyeNh5cRqs9PsvTrwokDExGfcxFPes=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FOYeCbXEpGtWkro1TGoNH52JhRiOfZlujEfry4xis9gP8S65gOPGp560BR4kK9X7W0LIIunXP0xoNcAV7vN4a6PyW0LiyKOGbvNORt2yAENvSncNpMgQoO1TUK1aDspZI/rNVBPPSB8UdKVaQdmKDq8Ij6vzFZDFDpf4m3xpFnA= 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=PUl5UzEO; arc=none smtp.client-ip=217.70.183.194 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="PUl5UzEO" Received: by mail.gandi.net (Postfix) with ESMTPSA id DE8C0430B7; Wed, 5 Mar 2025 14:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1741184386; 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=zJgNEItKL9gd+qK8TatNT2syXyozU40dfnTO0unlKEY=; b=PUl5UzEO8dOz/sIqp5xFVmMCLIrOAcnXM6lu94YWybX96zzbqH5Km0mbjwLEmixA13ENjc y28QojU/ClX+E9qbDkOBim0bHGJSHiWQboAfhwqZ3LHuG+vMy1A6ec9wILqxN/2a7HYxVc 7iSQBaFPFUDuy584j6swxPc2vOMgToKsN3SFjDc3os6eWio/xFPD/GEN7eJ16+OFIqKY7z TfqpmK1gaxyS93o1OsPEZ61+4gi9yYcWgJMr4NwDtdtVIc/lisyeCUavzz1Op2Wo46FMjR DA08uSLgzmveGRwVRvaA+WPMe2d6uQuuXBlJ/EISP/mmfvdXucQsKW+l1VgqZA== From: Maxime Chevallier To: davem@davemloft.net, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Heiner Kallweit Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Russell King , Vladimir Oltean , =?UTF-8?q?K=C3=B6ry=20Maincent?= , Oleksij Rempel , Simon Horman , Romain Gantois , Piergiorgio Beruto Subject: [PATCH net-next 4/7] net: ethtool: netlink: Introduce per-phy DUMP helpers Date: Wed, 5 Mar 2025 15:19:34 +0100 Message-ID: <20250305141938.319282-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250305141938.319282-1-maxime.chevallier@bootlin.com> References: <20250305141938.319282-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-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdehtdegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhmvgcuvehhvghvrghllhhivghruceomhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepveegtdffleffleevueellefgjeefvedvjefhheegfefgffdvfeetgeevudetffdtnecukfhppedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehinhgvthepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgdphhgvlhhopehfvgguohhrrgdrhhhomhgvpdhmrghilhhfrhhomhepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvddupdhrtghpthhtohepuggrvhgvmhesuggrvhgvmhhlohhfthdrnhgvthdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmr giivghtsehgohhoghhlvgdrtghomhdprhgtphhtthhopehprggsvghnihesrhgvughhrghtrdgtohhmpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdprhgtphhtthhopehnvghtuggvvhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" As there are multiple ethnl commands that report messages based on phy_device information, let's introduce a set of ethnl generic dump helpers to allow DUMP support for each PHY on a given netdev. This logic iterates over the phy_link_topology of each netdev (or a single netdev for filtered DUMP), and call ethnl_default_dump_one() with the req_info populated with ifindex + phyindex. This allows re-using all the existing infra for phy-targetting commands that already use ethnl generic helpers. Signed-off-by: Maxime Chevallier --- net/ethtool/netlink.c | 53 +++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.h | 6 +++++ 2 files changed, 59 insertions(+) diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index c0215f4acc05..474362af1aea 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -551,6 +551,59 @@ static int ethnl_default_dump_one(struct sk_buff *skb, return ret; } =20 +/* Specific context for phy-targeting command DUMP operatins. We keep in c= ontext + * the latest phy_index we dumped, in case of an interrupted DUMP. + */ +struct ethnl_dump_ctx_perphy { + unsigned long phy_index; +}; + +int ethnl_dump_start_perphy(struct ethnl_dump_ctx *ctx) +{ + struct ethnl_dump_ctx_perphy *dump_ctx; + + dump_ctx =3D kzalloc(sizeof(*dump_ctx), GFP_KERNEL); + if (!dump_ctx) + return -ENOMEM; + + ctx->cmd_ctx =3D dump_ctx; + + return 0; +} + +void ethnl_dump_done_perphy(struct ethnl_dump_ctx *ctx) +{ + kfree(ctx->cmd_ctx); +} + +int ethnl_dump_one_dev_perphy(struct sk_buff *skb, + struct ethnl_dump_ctx *ctx, + const struct genl_info *info) +{ + struct ethnl_dump_ctx_perphy *dump_ctx =3D ctx->cmd_ctx; + struct net_device *dev =3D ctx->reply_data->dev; + struct phy_device_node *pdn; + int ret =3D 0; + + if (!dev->link_topo) + return 0; + + xa_for_each_start(&dev->link_topo->phys, dump_ctx->phy_index, + pdn, dump_ctx->phy_index) { + ctx->req_info->phy_index =3D dump_ctx->phy_index; + + /* We can re-use the original dump_one as ->prepare_data in + * commands use ethnl_req_get_phydev(), which gets the PHY from + * what's in req_info + */ + ret =3D ethnl_default_dump_one(skb, ctx, info); + if (ret) + break; + } + + return ret; +} + static int ethnl_default_dump_one_dev(struct sk_buff *skb, struct net_devi= ce *dev, struct ethnl_dump_ctx *ctx, const struct genl_info *info) diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index d7506b08e5d6..835376a9c84c 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -327,6 +327,12 @@ struct ethnl_dump_ctx { void *cmd_ctx; }; =20 +/* Generic callbacks to be used by PHY targeting commands */ +int ethnl_dump_start_perphy(struct ethnl_dump_ctx *ctx); +int ethnl_dump_one_dev_perphy(struct sk_buff *skb, struct ethnl_dump_ctx *= ctx, + const struct genl_info *info); +void ethnl_dump_done_perphy(struct ethnl_dump_ctx *ctx); + int ethnl_ops_begin(struct net_device *dev); void ethnl_ops_complete(struct net_device *dev); =20 --=20 2.48.1