From mboxrd@z Thu Jan 1 00:00:00 1970 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 7672ECD4857 for ; Wed, 4 Sep 2024 17:46:24 +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: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VR+gSSCn3dh6Z4eIR/edtipFavfpSPefYQsgu2j7UZY=; b=ij9r8TNk6U6eIHioO0P0k0q9Ls xLmdBP6ZJ5kblNj9w4C/clp4ebb1ubHOfTt3rnmAnCka6ijMXpgMxSDW1uiRcpTr6ef3QqPk80Zoe zQ/sd+l+mzayda48pA+z11fF4BA8npiC6RZ+1WpDenl29gE0n6u6/RujjAGw1FiXx62glYnvPcbwu cRnWVWa/SJ9QHgf01M7TmlqurDA91lOlt3suyvfrTyWGDmoFx9T29H+fOMb7klMTFPEgc1xKEPLc1 lMf0eehPNFzu7ggIjOFf7ghYCPbJQS8cAK+hPW0wC8BTXHaDfryzoeZAn2bwDlRP4so/YHQghGTte 2ZWw6mjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slu56-00000005VQK-0Ffx; Wed, 04 Sep 2024 17:46:12 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slu48-00000005VG1-2CiT for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 17:45:14 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id D1CA360006; Wed, 4 Sep 2024 17:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1725471907; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VR+gSSCn3dh6Z4eIR/edtipFavfpSPefYQsgu2j7UZY=; b=iS+NWWZ/SZprfKVKBgY2M02Zhh59DjlhlAmWMUvyq0NF0NJkMe6NDx7sxUNHP+dqvdHegm eAqK3Qhz4Jxc5JPKRMU50I59tybX9l6M8lZ3JQsnhTGq5ogfRQWh7QNMnVoWjtUpR4mBlq 8Y+xBGOQJCV/fdEuJJxiJwJPB08tR3efumrAgrzSTX6bJemTsg0SGuDlMzXX+4ESgWOkCq 3SLOuPMzzQ0aCM5vLjC1cHjFrxNVDdQcQ1nCWwi4LH5DP+ZBRHFVLIP2yvGiyzrWhe0hlg Zq2DYkhjJAuz7Yr2ssOD0YfYHW/1V6sPoYyO591j7gsPNzY4TRZB7G3KwlLCwA== Date: Wed, 4 Sep 2024 19:45:04 +0200 From: Maxime Chevallier To: Michal Kubecek Cc: davem@davemloft.net, 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?B?S8O2cnk=?= Maincent , Jonathan Corbet , Marek =?UTF-8?B?QmVow7pu?= , Piergiorgio Beruto , Oleksij Rempel , =?UTF-8?B?Tmljb2zDsg==?= Veronese , Simon Horman Subject: Re: [PATCH ethtool-next v2 2/3] ethtool: Allow passing a PHY index for phy-targetting commands Message-ID: <20240904194504.44071f11@fedora.home> In-Reply-To: References: <20240828152511.194453-1-maxime.chevallier@bootlin.com> <20240828152511.194453-3-maxime.chevallier@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.3.0 (GTK 3.24.43; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_104512_873009_ADCDD634 X-CRM114-Status: GOOD ( 30.05 ) 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 Hello Michal, On Mon, 2 Sep 2024 00:04:39 +0200 Michal Kubecek wrote: > On Wed, Aug 28, 2024 at 05:25:09PM +0200, Maxime Chevallier wrote: > > With the introduction of PHY topology and the ability to list PHYs, we > > can now target some netlink commands to specific PHYs. This is done by > > passing a PHY index as a request parameter in the netlink GET command. > > > > This is useful for PSE-PD, PLCA and Cable-testing operations when > > multiple PHYs are on the link (e.g. when a PHY is used as an SFP > > upstream controller, and when there's another PHY within the SFP > > module). > > > > Introduce a new, generic, option "--phy N" that can be used in > > conjunction with PHY-targetting commands to pass the PHY index for the > > targetted PHY. > > > > Signed-off-by: Maxime Chevallier > > --- > > ethtool.8.in | 20 +++++++++++++++++ > > ethtool.c | 25 ++++++++++++++++++++- > > internal.h | 1 + > > netlink/cable_test.c | 4 ++-- > > netlink/msgbuff.c | 52 ++++++++++++++++++++++++++++++++++---------- > > netlink/msgbuff.h | 3 +++ > > netlink/nlsock.c | 3 ++- > > netlink/plca.c | 4 ++-- > > netlink/pse-pd.c | 4 ++-- > > 9 files changed, 96 insertions(+), 20 deletions(-) > > > [...] > > @@ -6550,6 +6559,16 @@ int main(int argc, char **argp) > > argc -= 1; > > continue; > > } > > + if (*argp && !strcmp(*argp, "--phy")) { > > + char *eptr; > > + > > + ctx.phy_index = strtoul(argp[1], &eptr, 0); > > + if (!argp[1][0] || *eptr) > > + exit_bad_args(); > > + argp += 2; > > + argc -= 2; > > + continue; > > + } > > break; > > } > > if (*argp && !strcmp(*argp, "--monitor")) { > > Could we have a meaningful error message that would tell user what was > wrong instead? Good point, I'll add one. > > > @@ -6585,6 +6604,10 @@ int main(int argc, char **argp) > > } > > if (ctx.json && !args[k].json) > > exit_bad_args_info("JSON output not available for this subcommand"); > > + > > + if (!args[k].targets_phy && ctx.phy_index) > > + exit_bad_args(); > > + > > ctx.argc = argc; > > ctx.argp = argp; > > netlink_run_handler(&ctx, args[k].nlchk, args[k].nlfunc, !args[k].func); > > Same here. Indeed, I'll update accordingly. [...] > > @@ -159,7 +151,9 @@ bool ethnla_fill_header(struct nl_msg_buff *msgbuff, uint16_t type, > > if ((devname && > > ethnla_put_strz(msgbuff, ETHTOOL_A_HEADER_DEV_NAME, devname)) || > > (flags && > > - ethnla_put_u32(msgbuff, ETHTOOL_A_HEADER_FLAGS, flags))) > > + ethnla_put_u32(msgbuff, ETHTOOL_A_HEADER_FLAGS, flags)) || > > + (phy_index && > > + ethnla_put_u32(msgbuff, ETHTOOL_A_HEADER_PHY_INDEX, phy_index))) > > goto err; > > > > ethnla_nest_end(msgbuff, nest); > > Just to be sure: are we sure the PHY index cannot ever be zero (or that > we won't need to pass 0 index to kernel)? I should better document that, sorry... The phy index assigned starts at 1 at wraps-around back to 1 when we exhausted the indices, so it can't ever be 0. The netlink code in the kernel side interprets the fact that userspace passes 0 as "use the default PHY", as if you didn't pass the parameter : net/ethtool/netlink.c: if (!req_info->phy_index) return req_info->dev->phydev; I'll send a patch to document that behaviour, thanks for pointing this out. Maxime