From patchwork Wed Mar 5 14:19:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 14002815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E56ADC19F32 for ; Wed, 5 Mar 2025 14:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zJgNEItKL9gd+qK8TatNT2syXyozU40dfnTO0unlKEY=; b=r3CUM+qR1EtWf/3NuOfWWs1wml CVxhxr6hgGSPlrv2F+LSxRfIYmTEkfR/qtgG1wDy/fkMM6xR+DbgyT+dACUo+wkgrVwfNIaI8QWl7 r+tOx7zYYSDg6ntN/m4XfB13c6pqckXG3Yf3yY21iYPXu0xfolLJvBwsrDPoLBCrgMkobq573BUkw vmwzH601H0S83tdlNj9SPkIP/seGuFZasQgafqF70lXBQOhD7CNwloMD10wSOjmsozpRDYj2FXkte MJnrs4UwUts5RRz3iZhqyaBbzEfIXX0dDFFnaekLF39oFg/eR7APhZlIlVaccg5+O5Kvo3qlgZJGy nfTXhdYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tpphS-00000008LLo-2mQE; Wed, 05 Mar 2025 14:26:18 +0000 Received: from relay2-d.mail.gandi.net ([217.70.183.194]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tppbA-00000008KIB-0sLs for linux-arm-kernel@lists.infradead.org; Wed, 05 Mar 2025 14:19:49 +0000 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_Maincent?= , 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> MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddutdehtdegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhmvgcuvehhvghvrghllhhivghruceomhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepveegtdffleffleevueellefgjeefvedvjefhheegfefgffdvfeetgeevudetffdtnecukfhppedvrgdtudemtggsudelmeekugegtgemlehftddtmegstgdvudemkeekleelmeehgedttgemvgehlegvnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehinhgvthepvdgrtddumegtsgduleemkegugegtmeelfhdttdemsggtvddumeekkeelleemheegtdgtmegvheelvgdphhgvlhhopehfvgguohhrrgdrhhhomhgvpdhmrghilhhfrhhomhepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvddupdhrtghpthhtohepuggrvhgvmhesuggrvhgvmhhlohhfthdrnhgvthdprhgtphhtthhopegrnhgurhgvfieslhhunhhnrdgthhdprhgtphhtthhopehkuhgsrgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepvgguuhhmr giivghtsehgohhoghhlvgdrtghomhdprhgtphhtthhopehprggsvghnihesrhgvughhrghtrdgtohhmpdhrtghpthhtohephhhkrghllhifvghithdusehgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgrgihimhgvrdgthhgvvhgrlhhlihgvrhessghoohhtlhhinhdrtghomhdprhgtphhtthhopehnvghtuggvvhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250305_061948_377357_14A72852 X-CRM114-Status: GOOD ( 15.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } +/* Specific context for phy-targeting command DUMP operatins. We keep in context + * 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 = kzalloc(sizeof(*dump_ctx), GFP_KERNEL); + if (!dump_ctx) + return -ENOMEM; + + ctx->cmd_ctx = 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 = ctx->cmd_ctx; + struct net_device *dev = ctx->reply_data->dev; + struct phy_device_node *pdn; + int ret = 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 = 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 = 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_device *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; }; +/* 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);