mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, "Andrew Lunn" <andrew@lunn.ch>,
	"Eric Dumazet" <edumazet@google.com>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	thomas.petazzoni@bootlin.com,
	"Christophe Leroy" <christophe.leroy@csgroup.eu>,
	"Herve Codina" <herve.codina@bootlin.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Vladimir Oltean" <vladimir.oltean@nxp.com>,
	"Köry Maincent" <kory.maincent@bootlin.com>,
	"Marek Behún" <kabel@kernel.org>,
	"Oleksij Rempel" <o.rempel@pengutronix.de>,
	"Nicolò Veronese" <nicveronese@gmail.com>,
	"Simon Horman" <horms@kernel.org>,
	mwojtas@chromium.org,
	"Romain Gantois" <romain.gantois@bootlin.com>,
	"Daniel Golle" <daniel@makrotopia.org>,
	"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>,
	"Frank Wunderlich" <frank.wunderlich@linux.dev>,
	"Pietro Ameruoso" <p.ameruoso@live.it>,
	"Aleksei Sviridkin" <f@lex.la>
Subject: Re: [PATCH net-next v18 09/10] net: ethtool: Introduce ethtool command to list ports
Date: Thu, 1 Oct 2026 08:49:05 +0200	[thread overview]
Message-ID: <5e5fc716-3be9-40f5-a74b-9d2eae478194@bootlin.com> (raw)
In-Reply-To: <20260930155310.775843d4@kernel.org>



On 10/1/26 00:53, Jakub Kicinski wrote:
> On Sun, 27 Sep 2026 15:36:18 +0200 Maxime Chevallier wrote:
>> Expose the phy_port information to userspace, so that we can know how
>> many ports are available on a given interface, as well as their
>> capabilities. For MDI ports, we report the list of supported linkmodes
>> based on what the PHY that drives this port says.
>> For MII ports, i.e. empty SFP cages, we report the MII linkmodes that we
>> can output on this port.
>>
>> Tested-by: Aleksei Sviridkin <f@lex.la>
>> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
> 
>> +static void __init ethnl_phy_names_populate(void)
>> +{
>> +	const char *name;
>> +	int i;
>> +
>> +	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
>> +		name = phy_modes(i);
>> +		strscpy(phy_interface_names[i], name, ETH_GSTRING_LEN);
> 
> Feels a bit backward, we run thru a switch statement to dump it down
> to an array.. Why not convert to an array and then make phy_modes()
> also use it?

From my memories on early tries to get it done another way, this was
tricky as I was struggling to find the correct place to put the array
in question.

phy_names() is required even when CONFIG_NET=n as it's used for devicetree
parsing, so we can't put that in phylib nor in any networking code without
doing some trickery to get some of it to build inconditionally. I'll try
harder :)

> 
>> +	}
>> +}
> 
>> +static int port_fill_reply(struct sk_buff *skb,
>> +			   const struct ethnl_req_info *req_info,
>> +			   const struct ethnl_reply_data *reply_data)
>> +{
>> +	bool compact = req_info->flags & ETHTOOL_FLAG_COMPACT_BITSETS;
>> +	struct port_reply_data *reply = PORT_REPDATA(reply_data);
>> +	int ret, port_type = ETHTOOL_PORT_TYPE_MDI;
>> +
>> +	if (nla_put_u32(skb, ETHTOOL_A_PORT_ID, reply->port_id))
>> +		return -EMSGSIZE;
>> +
>> +	if (!reply->mii) {
>> +		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_MODES,
>> +				       reply->supported, NULL,
>> +				       __ETHTOOL_LINK_MODE_MASK_NBITS,
>> +				       link_mode_names, compact);
>> +		if (ret < 0)
>> +			return ret;
>> +	} else {
>> +		ret = ethnl_put_bitset(skb, ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
>> +				       reply->interfaces, NULL,
>> +				       PHY_INTERFACE_MODE_MAX,
>> +				       phy_interface_names, compact);
>> +		if (ret < 0)
>> +			return ret;
>> +	}
>> +
> 
> please move the port_type init from inline up to to here.
> initializing things inline often lowers readability

Ack, will do

> 
>> +	if (reply->mii || reply->sfp)
>> +		port_type = ETHTOOL_PORT_TYPE_SFP;
>> +
>> +	if (nla_put_u32(skb, ETHTOOL_A_PORT_TYPE, port_type))
>> +		return -EMSGSIZE;
>> +
>> +	if (reply->upstream_port &&
>> +	    nla_put_u32(skb, ETHTOOL_A_PORT_UPSTREAM_PORT,
>> +			reply->upstream_port))
>> +		return -EMSGSIZE;
>> +
>> +	return 0;
>> +}
> 
>> +static int port_dump_all_dev(struct sk_buff *skb, struct netlink_callback *cb)
>> +{
>> +	struct port_dump_ctx *ctx = port_dump_ctx_get(cb);
>> +	struct net *net = sock_net(skb->sk);
>> +	netdevice_tracker dev_tracker;
>> +	struct net_device *dev;
>> +	int ret = 0;
>> +
>> +	rcu_read_lock();
>> +	for_each_netdev_dump(net, dev, ctx->pos_ifindex) {
>> +		netdev_hold(dev, &dev_tracker, GFP_ATOMIC);
>> +		rcu_read_unlock();
>> +
>> +		ctx->req_info->base.dev = dev;
>> +		ret = port_dump_one_dev(skb, cb);
>> +
>> +		rcu_read_lock();
>> +		netdev_put(dev, &dev_tracker);
>> +		ctx->req_info->base.dev = NULL;
>> +
>> +		if (ret < 0 && ret != -EOPNOTSUPP) {
>> +			if (likely(skb->len))
>> +				ret = skb->len;
> 
> smells of pre-commit b5a899154 netlink
> Can we delete the skb->len check and override here?
> There's one more such construct below

ah indeed yes :(

Thanks for reviewing,

Maxime


  reply	other threads:[~2026-10-01  6:49 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 13:36 [PATCH net-next v18 00/10] net: phy_port: SFP modules representation and phy_port listing Maxime Chevallier
2026-09-27 13:36 ` [PATCH net-next v18 01/10] net: phy: phy_link_topology: Add a helper for opportunistic alloc Maxime Chevallier
2026-09-28  9:36   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 02/10] net: phy: phy_link_topology: Track ports in phy_link_topology Maxime Chevallier
2026-09-28  9:37   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-30 13:02     ` Maxime Chevallier
2026-09-27 13:36 ` [PATCH net-next v18 03/10] net: phylink: Register a phy_port for MAC-driven SFP cages Maxime Chevallier
2026-09-28  9:38   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 04/10] net: phy: Create SFP phy_port before registering upstream Maxime Chevallier
2026-09-28  9:40   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 05/10] net: phy: Represent PHY-less SFP modules with phy_port Maxime Chevallier
2026-09-28  9:42   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 06/10] net: phy: phy_port: Store information about a port's upstream Maxime Chevallier
2026-09-28  9:43   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 07/10] net: phy: phy_link_topology: Add a helper to retrieve ports Maxime Chevallier
2026-09-28  9:43   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-30 13:09     ` Maxime Chevallier
2026-09-27 13:36 ` [PATCH net-next v18 08/10] netlink: specs: Add ethernet port listing with ethtool Maxime Chevallier
2026-09-28  9:47   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-27 13:36 ` [PATCH net-next v18 09/10] net: ethtool: Introduce ethtool command to list ports Maxime Chevallier
2026-09-28  9:48   ` Christophe Leroy (CS GROUP)
2026-09-29  0:38   ` netdev-bot+sashiko
2026-09-30 22:40     ` Jakub Kicinski
2026-10-01  6:51       ` Maxime Chevallier
2026-09-30 22:53   ` Jakub Kicinski
2026-10-01  6:49     ` Maxime Chevallier [this message]
2026-09-27 13:36 ` [PATCH net-next v18 10/10] Documentation: networking: Update the phy_port infrastructure description Maxime Chevallier
2026-09-28 10:07   ` Christophe Leroy (CS GROUP)
2026-09-28 17:31 ` [PATCH net-next v18 00/10] net: phy_port: SFP modules representation and phy_port listing Christophe Leroy (CS GROUP)
2026-09-30 22:56 ` Jakub Kicinski
2026-10-01  6:57   ` Maxime Chevallier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e5fc716-3be9-40f5-a74b-9d2eae478194@bootlin.com \
    --to=maxime.chevallier@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=christophe.leroy@csgroup.eu \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=dimitri.fedrau@liebherr.com \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=f@lex.la \
    --cc=frank.wunderlich@linux.dev \
    --cc=herve.codina@bootlin.com \
    --cc=hkallweit1@gmail.com \
    --cc=horms@kernel.org \
    --cc=kabel@kernel.org \
    --cc=kory.maincent@bootlin.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mwojtas@chromium.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicveronese@gmail.com \
    --cc=o.rempel@pengutronix.de \
    --cc=p.ameruoso@live.it \
    --cc=pabeni@redhat.com \
    --cc=romain.gantois@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vladimir.oltean@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®