ethtool: Introduce the --show-ports command
Subsystems (3)
cover ethtool: Introduce the --show-ports command
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/FullPort 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
Signature · 1 line
2.56.1
PATCH 1/2 update UAPI header copies
Update to kernel commit d6816d9a93b6.
--- 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(+)
uapi/linux/ethtool.h +2 -0
@@ -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
uapi/linux/ethtool_netlink_generated.h +22 -0
@@ -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 )
uapi/linux/if_addr.h +1 -0
@@ -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 0x1000struct ifa_cacheinfo {__u32 ifa_prefered;
uapi/linux/if_link.h +1 -0
@@ -381,6 +381,7 @@ enum {IFLA_NETNS_IMMUTABLE ,IFLA_HEADROOM ,IFLA_TAILROOM , +IFLA_PACING_OFFLOAD , __IFLA_MAX };
uapi/linux/netlink.h +14 -0
@@ -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,
Signature · 1 line
2.56.1
PATCH 2/2 ethtool: Introduce a command to list an interface's ports
In reply to Maxime ChevallierIntroduce 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.
--- 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
Makefile.am +1 -0
@@ -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 \
ethtool.8.in +30 -0
@@ -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.
ethtool.c +6 -0
@@ -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,
netlink/extapi.h +2 -0
@@ -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 */
netlink/port.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.56.1