Netdev List
 help / color / mirror / Atom feed
* [PATCH ethtool-next 0/2] ethtool: Introduce the --show-ports command
@ 2026-11-18 15:05 Maxime Chevallier
  2026-11-18 15:05 ` [PATCH ethtool-next 1/2] update UAPI header copies Maxime Chevallier
  2026-11-18 15:05 ` [PATCH ethtool-next 2/2] ethtool: Introduce a command to list an interface's ports Maxime Chevallier
  0 siblings, 2 replies; 3+ messages in thread
From: Maxime Chevallier @ 2026-11-18 15:05 UTC (permalink / raw)
  To: Michal Kubecek, Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet,
	Paolo Abeni, Simon Horman
  Cc: Maxime Chevallier, netdev, Christophe Leroy, thomas.petazzoni

Hi everyone,

Following the merge of the phy_port GET ethnl command into net-next,
here's the ethtool counterpart that uses that commande to enumerate the
ports and their capabilities. This is queued for v7.4.

The output looks like this:

# ethtool --show-ports *

Port for eth0:
        Port id: 1
        Port type: mdi
        Supported link modes:  10baseT/Half 10baseT/Full
                               100baseT/Half 100baseT/Full
                               1000baseT/Full
                               10000baseT/Full
                               2500baseT/Full
                               5000baseT/Full

Port for eth0:
        Port id: 2
        Port type: sfp
        Supported MII interfaces: 10gbase-r

Port for eth2:
        Port id: 1
        Port type: mdi
        Supported link modes:  10baseT/Half 10baseT/Full
                               100baseT/Half 100baseT/Full
                               1000baseT/Half 1000baseT/Full

Port for eth3:
        Port id: 1
        Port type: sfp
        Supported MII interfaces: sgmii 1000base-x 2500base-x

Port for eth3:
        Port id: 2
        Port type: mdi
        Supported link modes:  10baseT/Half 10baseT/Full
                               100baseT/Half 100baseT/Full
                               1000baseT/Half 1000baseT/Full
                               1000baseX/Full
        Upstream port id: 1

Patch 1 syncs the kernel headers, and patch 2 implements the
--show-ports command.

Thanks,

Maxime

Maxime Chevallier (2):
  update UAPI header copies
  ethtool: Introduce a command to list an interface's ports

 Makefile.am                            |   1 +
 ethtool.8.in                           |  30 ++++++
 ethtool.c                              |   6 ++
 netlink/extapi.h                       |   2 +
 netlink/port.c                         | 134 +++++++++++++++++++++++++
 uapi/linux/ethtool.h                   |   2 +
 uapi/linux/ethtool_netlink_generated.h |  22 ++++
 uapi/linux/if_addr.h                   |   1 +
 uapi/linux/if_link.h                   |   1 +
 uapi/linux/netlink.h                   |  14 +++
 10 files changed, 213 insertions(+)
 create mode 100644 netlink/port.c

-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH ethtool-next 1/2] update UAPI header copies
  2026-11-18 15:05 [PATCH ethtool-next 0/2] ethtool: Introduce the --show-ports command Maxime Chevallier
@ 2026-11-18 15:05 ` Maxime Chevallier
  2026-11-18 15:05 ` [PATCH ethtool-next 2/2] ethtool: Introduce a command to list an interface's ports Maxime Chevallier
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Chevallier @ 2026-11-18 15:05 UTC (permalink / raw)
  To: Michal Kubecek, Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet,
	Paolo Abeni, Simon Horman
  Cc: Maxime Chevallier, netdev, Christophe Leroy, thomas.petazzoni

Update to kernel commit d6816d9a93b6.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 uapi/linux/ethtool.h                   |  2 ++
 uapi/linux/ethtool_netlink_generated.h | 22 ++++++++++++++++++++++
 uapi/linux/if_addr.h                   |  1 +
 uapi/linux/if_link.h                   |  1 +
 uapi/linux/netlink.h                   | 14 ++++++++++++++
 5 files changed, 40 insertions(+)

diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h
index c2afca5..2f8f90a 100644
--- a/uapi/linux/ethtool.h
+++ b/uapi/linux/ethtool.h
@@ -685,6 +685,7 @@ enum ethtool_link_ext_substate_module {
  * @ETH_SS_STATS_RMON: names of RMON statistics
  * @ETH_SS_STATS_PHY: names of PHY(dev) statistics
  * @ETH_SS_TS_FLAGS: hardware timestamping flags
+ * @ETH_SS_PHY_INTERFACES: names of MAC to PHY interfaces
  *
  * @ETH_SS_COUNT: number of defined string sets
  */
@@ -712,6 +713,7 @@ enum ethtool_stringset {
 	ETH_SS_STATS_RMON,
 	ETH_SS_STATS_PHY,
 	ETH_SS_TS_FLAGS,
+	ETH_SS_PHY_INTERFACES,
 
 	/* add new constants above here */
 	ETH_SS_COUNT
diff --git a/uapi/linux/ethtool_netlink_generated.h b/uapi/linux/ethtool_netlink_generated.h
index 572c5f9..dff1741 100644
--- a/uapi/linux/ethtool_netlink_generated.h
+++ b/uapi/linux/ethtool_netlink_generated.h
@@ -78,6 +78,14 @@ enum ethtool_pse_event {
 	ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64,
 };
 
+/*
+ * type of physical connector
+ */
+enum ethtool_port_type {
+	ETHTOOL_PORT_TYPE_MDI,
+	ETHTOOL_PORT_TYPE_SFP,
+};
+
 enum {
 	ETHTOOL_A_HEADER_UNSPEC,
 	ETHTOOL_A_HEADER_DEV_INDEX,
@@ -840,6 +848,18 @@ enum {
 	ETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1)
 };
 
+enum {
+	ETHTOOL_A_PORT_HEADER = 1,
+	ETHTOOL_A_PORT_ID,
+	ETHTOOL_A_PORT_SUPPORTED_MODES,
+	ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+	ETHTOOL_A_PORT_TYPE,
+	ETHTOOL_A_PORT_UPSTREAM_PORT,
+
+	__ETHTOOL_A_PORT_CNT,
+	ETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1)
+};
+
 enum {
 	ETHTOOL_MSG_USER_NONE = 0,
 	ETHTOOL_MSG_STRSET_GET = 1,
@@ -893,6 +913,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_ACT,
 	ETHTOOL_MSG_RSS_DELETE_ACT,
 	ETHTOOL_MSG_MSE_GET,
+	ETHTOOL_MSG_PORT_GET,
 
 	__ETHTOOL_MSG_USER_CNT,
 	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -954,6 +975,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_NTF,
 	ETHTOOL_MSG_RSS_DELETE_NTF,
 	ETHTOOL_MSG_MSE_GET_REPLY,
+	ETHTOOL_MSG_PORT_GET_REPLY,
 
 	__ETHTOOL_MSG_KERNEL_CNT,
 	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
diff --git a/uapi/linux/if_addr.h b/uapi/linux/if_addr.h
index 5a28b95..aa30ef5 100644
--- a/uapi/linux/if_addr.h
+++ b/uapi/linux/if_addr.h
@@ -57,6 +57,7 @@ enum {
 #define IFA_F_NOPREFIXROUTE	0x200
 #define IFA_F_MCAUTOJOIN	0x400
 #define IFA_F_STABLE_PRIVACY	0x800
+#define IFA_F_GLOBAL		0x1000
 
 struct ifa_cacheinfo {
 	__u32	ifa_prefered;
diff --git a/uapi/linux/if_link.h b/uapi/linux/if_link.h
index d3a21fb..7ce01d8 100644
--- a/uapi/linux/if_link.h
+++ b/uapi/linux/if_link.h
@@ -381,6 +381,7 @@ enum {
 	IFLA_NETNS_IMMUTABLE,
 	IFLA_HEADROOM,
 	IFLA_TAILROOM,
+	IFLA_PACING_OFFLOAD,
 	__IFLA_MAX
 };
 
diff --git a/uapi/linux/netlink.h b/uapi/linux/netlink.h
index ff64eb1..792a915 100644
--- a/uapi/linux/netlink.h
+++ b/uapi/linux/netlink.h
@@ -325,6 +325,17 @@ enum netlink_attribute_type {
 	NL_ATTR_TYPE_UINT,
 };
 
+/**
+ * enum netlink_policy_byte_order - byte order of an integer attribute
+ * @NL_POLICY_BYTE_ORDER_BIG_ENDIAN: big endian (network byte order)
+ *
+ * Zero is left unassigned so that it keeps meaning host byte order,
+ * which is also what a missing byte order means.
+ */
+enum netlink_policy_byte_order {
+	NL_POLICY_BYTE_ORDER_BIG_ENDIAN = 1,
+};
+
 /**
  * enum netlink_policy_type_attr - policy type attributes
  * @NL_POLICY_TYPE_ATTR_UNSPEC: unused
@@ -352,6 +363,8 @@ enum netlink_attribute_type {
  *	bitfield32 type (U32)
  * @NL_POLICY_TYPE_ATTR_MASK: mask of valid bits for unsigned integers (U64)
  * @NL_POLICY_TYPE_ATTR_PAD: pad attribute for 64-bit alignment
+ * @NL_POLICY_TYPE_ATTR_BYTE_ORDER: byte order of an integer attribute,
+ *	&enum netlink_policy_byte_order, absent if host byte order (U32)
  *
  * @__NL_POLICY_TYPE_ATTR_MAX: number of attributes
  * @NL_POLICY_TYPE_ATTR_MAX: highest attribute number
@@ -370,6 +383,7 @@ enum netlink_policy_type_attr {
 	NL_POLICY_TYPE_ATTR_BITFIELD32_MASK,
 	NL_POLICY_TYPE_ATTR_PAD,
 	NL_POLICY_TYPE_ATTR_MASK,
+	NL_POLICY_TYPE_ATTR_BYTE_ORDER,
 
 	/* keep last */
 	__NL_POLICY_TYPE_ATTR_MAX,
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH ethtool-next 2/2] ethtool: Introduce a command to list an interface's ports
  2026-11-18 15:05 [PATCH ethtool-next 0/2] ethtool: Introduce the --show-ports command Maxime Chevallier
  2026-11-18 15:05 ` [PATCH ethtool-next 1/2] update UAPI header copies Maxime Chevallier
@ 2026-11-18 15:05 ` Maxime Chevallier
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Chevallier @ 2026-11-18 15:05 UTC (permalink / raw)
  To: Michal Kubecek, Andrew Lunn, Jakub Kicinski, davem, Eric Dumazet,
	Paolo Abeni, Simon Horman
  Cc: Maxime Chevallier, netdev, Christophe Leroy, thomas.petazzoni

Introduce the "--show-ports <dev>" command to list an interface's ports
using the ETHTOOL_MSG_PORT_GET netlink command.

It shows the supported linkmodes, interfaces, type and upstream info,
using either plain text or JSON mode.

Add a small manpage alongside it.

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 Makefile.am      |   1 +
 ethtool.8.in     |  30 +++++++++++
 ethtool.c        |   6 +++
 netlink/extapi.h |   2 +
 netlink/port.c   | 134 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 173 insertions(+)
 create mode 100644 netlink/port.c

diff --git a/Makefile.am b/Makefile.am
index db22be4..f253ba0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -56,6 +56,7 @@ ethtool_SOURCES += \
 		  netlink/phy.c \
 		  netlink/tsconfig.c \
 		  netlink/mse.c \
+		  netlink/port.c \
 		  uapi/linux/const.h uapi/linux/ethtool.h \
 		  uapi/linux/ethtool_netlink.h \
 		  uapi/linux/ethtool_netlink_generated.h \
diff --git a/ethtool.8.in b/ethtool.8.in
index b404b93..d8ce895 100644
--- a/ethtool.8.in
+++ b/ethtool.8.in
@@ -594,6 +594,9 @@ ethtool \- query or control network driver and hardware settings
 .HP
 .B ethtool \-\-show\-phys
 .I devname
+.HP
+.B ethtool \-\-show\-ports
+.I devname
 .
 .\" Adjust lines (i.e. full justification) and hyphenate.
 .ad
@@ -2149,6 +2152,33 @@ If the PHY's upstream_type is
 .B upstream_sfp_name
 If the PHY is within an SFP/SFF module, this field contains the name of the
 upstream SFP bus.
+.RE
+.TP
+.B \-\-show\-ports
+Show the ports of an interface, that is the physical connection points through
+which it can be linked to a medium, such as an RJ45 connector or an SFP cage.
+.RS 4
+.TP
+.B port\-id
+The port's identifier, unique within the network interface.
+.TP
+.B type \ mdi | sfp
+The nature of the port.
+.B mdi
+ports connect directly to a medium.
+.B sfp
+ports are either an SFP cage, or a port provided by the module sitting in a
+cage.
+.TP
+.B supported\-link\-modes
+The link modes this port can operate at. Not reported for SFP cages.
+.TP
+.B supported\-interfaces
+For SFP cages, the MII interfaces that can be used towards the module.
+.TP
+.B upstream\-port
+If any, the port\-id of the port that feeds into this one, such as the cage a
+module sits in.
 
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
diff --git a/ethtool.c b/ethtool.c
index 30a1d97..8482a10 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6514,6 +6514,12 @@ static const struct option args[] = {
 		.nlfunc	= nl_gmse,
 		.help	= "Show Mean Square Error (MSE) diagnostics",
 	},
+	{
+		.opts	= "--show-ports",
+		.json	= true,
+		.nlfunc	= nl_get_port,
+		.help	= "List ports"
+	},
 	{
 		.opts	= "-h|--help",
 		.no_dev	= true,
diff --git a/netlink/extapi.h b/netlink/extapi.h
index e10af62..e7b6140 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -61,6 +61,7 @@ int nl_spse(struct cmd_context *ctx);
 int nl_flash_module_fw(struct cmd_context *ctx);
 int nl_get_phy(struct cmd_context *ctx);
 int nl_gmse(struct cmd_context *ctx);
+int nl_get_port(struct cmd_context *ctx);
 
 void nl_monitor_usage(void);
 
@@ -142,6 +143,7 @@ nl_get_eeprom_page(struct cmd_context *ctx __maybe_unused,
 #define nl_flash_module_fw	NULL
 #define nl_get_phy		NULL
 #define nl_gmse			NULL
+#define nl_get_port		NULL
 
 #endif /* ETHTOOL_ENABLE_NETLINK */
 
diff --git a/netlink/port.c b/netlink/port.c
new file mode 100644
index 0000000..b845d01
--- /dev/null
+++ b/netlink/port.c
@@ -0,0 +1,134 @@
+/*
+ * port.c - List the ports of an interface and their parameters
+ *
+ * Implementation of "ethtool --show-ports <dev>"
+ */
+
+#include <errno.h>
+#include <inttypes.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../internal.h"
+#include "../common.h"
+#include "netlink.h"
+#include "bitset.h"
+
+/* PORT_GET */
+
+static const char *port_type_str(uint32_t port_type)
+{
+	switch (port_type) {
+	case ETHTOOL_PORT_TYPE_MDI: return "mdi";
+	case ETHTOOL_PORT_TYPE_SFP: return "sfp";
+	default: return "unknown";
+	}
+}
+
+static void port_interfaces_walk_cb(unsigned int idx __maybe_unused,
+				    const char *name, bool val, void *data)
+{
+	bool *first = data;
+
+	if (!val)
+		return;
+
+	if (!is_json_context() && !*first)
+		putchar(' ');
+	*first = false;
+
+	print_string(PRINT_ANY, NULL, "%s", name);
+}
+
+static int port_dump_interfaces(const struct nlattr *bitset)
+{
+	bool first = true;
+	int ret;
+
+	open_json_array("supported-interfaces", "");
+	if (!is_json_context())
+		printf("\tSupported MII interfaces: ");
+	ret = walk_bitset(bitset, NULL, port_interfaces_walk_cb, &first);
+	close_json_array("\n");
+
+	return ret;
+}
+
+static int port_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+	const struct nlattr *tb[ETHTOOL_A_PORT_MAX + 1] = {};
+	struct nl_context *nlctx = data;
+	DECLARE_ATTR_TB_INFO(tb);
+	uint32_t port_type;
+	int ret;
+
+	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+	if (ret < 0)
+		return MNL_CB_OK;
+	nlctx->devname = get_dev_name(tb[ETHTOOL_A_PORT_HEADER]);
+	if (!dev_ok(nlctx))
+		return MNL_CB_OK;
+
+	print_nl();
+
+	open_json_object(NULL);
+
+	print_string(PRINT_ANY, "ifname", "Port for %s:\n", nlctx->devname);
+
+	show_u32("port-id", "\tPort id: ", tb[ETHTOOL_A_PORT_ID]);
+
+	if (tb[ETHTOOL_A_PORT_TYPE]) {
+		port_type = mnl_attr_get_u32(tb[ETHTOOL_A_PORT_TYPE]);
+		print_string(PRINT_ANY, "type", "\tPort type: %s\n",
+			     port_type_str(port_type));
+	}
+
+	if (tb[ETHTOOL_A_PORT_SUPPORTED_MODES]) {
+		ret = dump_link_modes(nlctx, tb[ETHTOOL_A_PORT_SUPPORTED_MODES],
+				      false, LM_CLASS_REAL,
+				      "Supported link modes:  ", NULL, "\n",
+				      "Not reported", "supported-link-modes");
+		if (ret < 0)
+			goto out;
+	}
+
+	if (tb[ETHTOOL_A_PORT_SUPPORTED_INTERFACES]) {
+		ret = port_dump_interfaces(tb[ETHTOOL_A_PORT_SUPPORTED_INTERFACES]);
+		if (ret < 0)
+			goto out;
+	}
+
+	if (tb[ETHTOOL_A_PORT_UPSTREAM_PORT])
+		show_u32("upstream-port", "\tUpstream port id: ",
+			 tb[ETHTOOL_A_PORT_UPSTREAM_PORT]);
+
+out:
+	close_json_object();
+
+	return MNL_CB_OK;
+}
+
+int nl_get_port(struct cmd_context *ctx)
+{
+	struct nl_context *nlctx = ctx->nlctx;
+	struct nl_socket *nlsk = nlctx->ethnl_socket;
+	int ret;
+
+	if (netlink_cmd_check(ctx, ETHTOOL_MSG_PORT_GET, true))
+		return -EOPNOTSUPP;
+	if (ctx->argc > 0) {
+		fprintf(stderr, "ethtool: unexpected parameter '%s'\n",
+			*ctx->argp);
+		return 1;
+	}
+
+	ret = nlsock_prep_filtered_dump_request(nlsk, ETHTOOL_MSG_PORT_GET,
+						ETHTOOL_A_PORT_HEADER, 0);
+	if (ret)
+		return ret;
+
+	new_json_obj(ctx->json);
+	ret = nlsock_send_get_request(nlsk, port_reply_cb);
+	delete_json_obj();
+	return ret;
+}
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18 15:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 15:05 [PATCH ethtool-next 0/2] ethtool: Introduce the --show-ports command Maxime Chevallier
2026-11-18 15:05 ` [PATCH ethtool-next 1/2] update UAPI header copies Maxime Chevallier
2026-11-18 15:05 ` [PATCH ethtool-next 2/2] ethtool: Introduce a command to list an interface's ports Maxime Chevallier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox