From patchwork Tue Mar 30 04:01:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12171581 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3C46C433C1 for ; Tue, 30 Mar 2021 04:02:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B162B6195D for ; Tue, 30 Mar 2021 04:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbhC3ECN (ORCPT ); Tue, 30 Mar 2021 00:02:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:46752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231139AbhC3EB5 (ORCPT ); Tue, 30 Mar 2021 00:01:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8AC6A61929; Tue, 30 Mar 2021 04:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617076916; bh=jj4zDSRwz1/y4OPeWNllNF02JTrbayMEHydg7F7ohJo=; h=From:To:Cc:Subject:Date:From; b=DOTqgkTi5aN2q+5vEEZspUyqPx33gSIuQYmCUhDplh0jasLqpTtolJkb1mXLiKvu2 Rqk3b6TwhXvBb7JtDYryWfx951bJDRwvVqL2nNDzEJ/VMhLpscWzk2HPI/B3OxlrLr CDV9SIRSdum384EJdbLLycMtOZHgU9+CoEJbjWRUWQFfym071Koap8LnbZTAxAyT6X Sp3s1iGmLA2RiCJxuWYgYiJg9hW+5cIyj3ctsMlo9FeMkhKRT/2H2Rz8G5mf1i4m5o xWUJvof0fCW0BITvFuMJO/NT+AqdOHWJS1pL+ighxOhH7tfZ6WDXDKBuSk5sfc5Wti J3CxUUVbYQ5jg== From: Jakub Kicinski To: mkubecek@suse.cz, andrew@lunn.ch Cc: netdev@vger.kernel.org, ecree.xilinx@gmail.com, Jakub Kicinski Subject: [RFC ethtool-next 1/3] update UAPI header copies Date: Mon, 29 Mar 2021 21:01:52 -0700 Message-Id: <20210330040154.1218028-1-kuba@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz X-Patchwork-State: RFC Update to kernel commit 6917719f1b85. Signed-off-by: Jakub Kicinski --- uapi/linux/ethtool.h | 47 +++++++++++++++++++++++++++--------- uapi/linux/ethtool_netlink.h | 18 ++++++++++++++ uapi/linux/if_link.h | 9 +++++-- uapi/linux/netlink.h | 2 +- uapi/linux/rtnetlink.h | 33 +++++++++++++++++++++---- 5 files changed, 89 insertions(+), 20 deletions(-) diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h index 052689bcc90c..ceb34faa1b16 100644 --- a/uapi/linux/ethtool.h +++ b/uapi/linux/ethtool.h @@ -14,7 +14,7 @@ #ifndef _LINUX_ETHTOOL_H #define _LINUX_ETHTOOL_H -#include +#include #include #include @@ -1374,15 +1374,33 @@ struct ethtool_per_queue_op { }; /** - * struct ethtool_fecparam - Ethernet forward error correction(fec) parameters + * struct ethtool_fecparam - Ethernet Forward Error Correction parameters * @cmd: Command number = %ETHTOOL_GFECPARAM or %ETHTOOL_SFECPARAM - * @active_fec: FEC mode which is active on porte - * @fec: Bitmask of supported/configured FEC modes - * @rsvd: Reserved for future extensions. i.e FEC bypass feature. + * @active_fec: FEC mode which is active on the port, single bit set, GET only. + * @fec: Bitmask of configured FEC modes. + * @reserved: Reserved for future extensions, ignore on GET, write 0 for SET. * - * Drivers should reject a non-zero setting of @autoneg when - * autoneogotiation is disabled (or not supported) for the link. + * Note that @reserved was never validated on input and ethtool user space + * left it uninitialized when calling SET. Hence going forward it can only be + * used to return a value to userspace with GET. + * + * FEC modes supported by the device can be read via %ETHTOOL_GLINKSETTINGS. + * FEC settings are configured by link autonegotiation whenever it's enabled. + * With autoneg on %ETHTOOL_GFECPARAM can be used to read the current mode. + * + * When autoneg is disabled %ETHTOOL_SFECPARAM controls the FEC settings. + * It is recommended that drivers only accept a single bit set in @fec. + * When multiple bits are set in @fec drivers may pick mode in an implementation + * dependent way. Drivers should reject mixing %ETHTOOL_FEC_AUTO_BIT with other + * FEC modes, because it's unclear whether in this case other modes constrain + * AUTO or are independent choices. + * Drivers must reject SET requests if they support none of the requested modes. + * + * If device does not support FEC drivers may use %ETHTOOL_FEC_NONE instead + * of returning %EOPNOTSUPP from %ETHTOOL_GFECPARAM. * + * See enum ethtool_fec_config_bits for definition of valid bits for both + * @fec and @active_fec. */ struct ethtool_fecparam { __u32 cmd; @@ -1394,11 +1412,16 @@ struct ethtool_fecparam { /** * enum ethtool_fec_config_bits - flags definition of ethtool_fec_configuration - * @ETHTOOL_FEC_NONE: FEC mode configuration is not supported - * @ETHTOOL_FEC_AUTO: Default/Best FEC mode provided by driver - * @ETHTOOL_FEC_OFF: No FEC Mode - * @ETHTOOL_FEC_RS: Reed-Solomon Forward Error Detection mode - * @ETHTOOL_FEC_BASER: Base-R/Reed-Solomon Forward Error Detection mode + * @ETHTOOL_FEC_NONE_BIT: FEC mode configuration is not supported. Should not + * be used together with other bits. GET only. + * @ETHTOOL_FEC_AUTO_BIT: Select default/best FEC mode automatically, usually + * based link mode and SFP parameters read from module's + * EEPROM. This bit does _not_ mean autonegotiation. + * @ETHTOOL_FEC_OFF_BIT: No FEC Mode + * @ETHTOOL_FEC_RS_BIT: Reed-Solomon FEC Mode + * @ETHTOOL_FEC_BASER_BIT: Base-R/Reed-Solomon FEC Mode + * @ETHTOOL_FEC_LLRS_BIT: Low Latency Reed Solomon FEC Mode (25G/50G Ethernet + * Consortium) */ enum ethtool_fec_config_bits { ETHTOOL_FEC_NONE_BIT, diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h index c022883cdb22..737b1a4b342c 100644 --- a/uapi/linux/ethtool_netlink.h +++ b/uapi/linux/ethtool_netlink.h @@ -42,6 +42,8 @@ enum { ETHTOOL_MSG_CABLE_TEST_ACT, ETHTOOL_MSG_CABLE_TEST_TDR_ACT, ETHTOOL_MSG_TUNNEL_INFO_GET, + ETHTOOL_MSG_FEC_GET, + ETHTOOL_MSG_FEC_SET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -80,6 +82,8 @@ enum { ETHTOOL_MSG_CABLE_TEST_NTF, ETHTOOL_MSG_CABLE_TEST_TDR_NTF, ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, + ETHTOOL_MSG_FEC_GET_REPLY, + ETHTOOL_MSG_FEC_NTF, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -227,6 +231,7 @@ enum { ETHTOOL_A_LINKMODES_DUPLEX, /* u8 */ ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG, /* u8 */ ETHTOOL_A_LINKMODES_MASTER_SLAVE_STATE, /* u8 */ + ETHTOOL_A_LINKMODES_LANES, /* u32 */ /* add new constants above here */ __ETHTOOL_A_LINKMODES_CNT, @@ -628,6 +633,19 @@ enum { ETHTOOL_A_TUNNEL_INFO_MAX = (__ETHTOOL_A_TUNNEL_INFO_CNT - 1) }; +/* FEC */ + +enum { + ETHTOOL_A_FEC_UNSPEC, + ETHTOOL_A_FEC_HEADER, /* nest - _A_HEADER_* */ + ETHTOOL_A_FEC_MODES, /* bitset */ + ETHTOOL_A_FEC_AUTO, /* u8 */ + ETHTOOL_A_FEC_ACTIVE, /* u32 */ + + __ETHTOOL_A_FEC_CNT, + ETHTOOL_A_FEC_MAX = (__ETHTOOL_A_FEC_CNT - 1) +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 diff --git a/uapi/linux/if_link.h b/uapi/linux/if_link.h index 307e5c245e9f..50193377e5e4 100644 --- a/uapi/linux/if_link.h +++ b/uapi/linux/if_link.h @@ -75,8 +75,9 @@ struct rtnl_link_stats { * * @rx_dropped: Number of packets received but not processed, * e.g. due to lack of resources or unsupported protocol. - * For hardware interfaces this counter should not include packets - * dropped by the device which are counted separately in + * For hardware interfaces this counter may include packets discarded + * due to L2 address filtering but should not include packets dropped + * by the device due to buffer exhaustion which are counted separately in * @rx_missed_errors (since procfs folds those two counters together). * * @tx_dropped: Number of packets dropped on their way to transmission, @@ -522,6 +523,8 @@ enum { IFLA_BRPORT_BACKUP_PORT, IFLA_BRPORT_MRP_RING_OPEN, IFLA_BRPORT_MRP_IN_OPEN, + IFLA_BRPORT_MCAST_EHT_HOSTS_LIMIT, + IFLA_BRPORT_MCAST_EHT_HOSTS_CNT, __IFLA_BRPORT_MAX }; #define IFLA_BRPORT_MAX (__IFLA_BRPORT_MAX - 1) @@ -586,6 +589,8 @@ enum { IFLA_MACVLAN_MACADDR, IFLA_MACVLAN_MACADDR_DATA, IFLA_MACVLAN_MACADDR_COUNT, + IFLA_MACVLAN_BC_QUEUE_LEN, + IFLA_MACVLAN_BC_QUEUE_LEN_USED, __IFLA_MACVLAN_MAX, }; diff --git a/uapi/linux/netlink.h b/uapi/linux/netlink.h index dfef006be9f9..5024c5435749 100644 --- a/uapi/linux/netlink.h +++ b/uapi/linux/netlink.h @@ -2,7 +2,7 @@ #ifndef __LINUX_NETLINK_H #define __LINUX_NETLINK_H -#include +#include #include /* for __kernel_sa_family_t */ #include diff --git a/uapi/linux/rtnetlink.h b/uapi/linux/rtnetlink.h index 5ad84e663d01..e01efa281bdc 100644 --- a/uapi/linux/rtnetlink.h +++ b/uapi/linux/rtnetlink.h @@ -178,6 +178,13 @@ enum { RTM_GETVLAN, #define RTM_GETVLAN RTM_GETVLAN + RTM_NEWNEXTHOPBUCKET = 116, +#define RTM_NEWNEXTHOPBUCKET RTM_NEWNEXTHOPBUCKET + RTM_DELNEXTHOPBUCKET, +#define RTM_DELNEXTHOPBUCKET RTM_DELNEXTHOPBUCKET + RTM_GETNEXTHOPBUCKET, +#define RTM_GETNEXTHOPBUCKET RTM_GETNEXTHOPBUCKET + __RTM_MAX, #define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) }; @@ -283,6 +290,7 @@ enum { #define RTPROT_MROUTED 17 /* Multicast daemon */ #define RTPROT_KEEPALIVED 18 /* Keepalived daemon */ #define RTPROT_BABEL 42 /* Babel daemon */ +#define RTPROT_OPENR 99 /* Open Routing (Open/R) Routes */ #define RTPROT_BGP 186 /* BGP Routes */ #define RTPROT_ISIS 187 /* ISIS Routes */ #define RTPROT_OSPF 188 /* OSPF Routes */ @@ -319,6 +327,11 @@ enum rt_scope_t { #define RTM_F_FIB_MATCH 0x2000 /* return full fib lookup match */ #define RTM_F_OFFLOAD 0x4000 /* route is offloaded */ #define RTM_F_TRAP 0x8000 /* route is trapping packets */ +#define RTM_F_OFFLOAD_FAILED 0x20000000 /* route offload failed, this value + * is chosen to avoid conflicts with + * other flags defined in + * include/uapi/linux/ipv6_route.h + */ /* Reserved table identifiers */ @@ -396,11 +409,13 @@ struct rtnexthop { #define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */ #define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */ #define RTNH_F_ONLINK 4 /* Gateway is forced on link */ -#define RTNH_F_OFFLOAD 8 /* offloaded route */ +#define RTNH_F_OFFLOAD 8 /* Nexthop is offloaded */ #define RTNH_F_LINKDOWN 16 /* carrier-down on nexthop */ #define RTNH_F_UNRESOLVED 32 /* The entry is unresolved (ipmr) */ +#define RTNH_F_TRAP 64 /* Nexthop is trapping packets */ -#define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | RTNH_F_OFFLOAD) +#define RTNH_COMPARE_MASK (RTNH_F_DEAD | RTNH_F_LINKDOWN | \ + RTNH_F_OFFLOAD | RTNH_F_TRAP) /* Macros to handle hexthops */ @@ -764,12 +779,18 @@ enum { #define TA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcamsg)) /* tcamsg flags stored in attribute TCA_ROOT_FLAGS * - * TCA_FLAG_LARGE_DUMP_ON user->kernel to request for larger than TCA_ACT_MAX_PRIO - * actions in a dump. All dump responses will contain the number of actions - * being dumped stored in for user app's consumption in TCA_ROOT_COUNT + * TCA_ACT_FLAG_LARGE_DUMP_ON user->kernel to request for larger than + * TCA_ACT_MAX_PRIO actions in a dump. All dump responses will contain the + * number of actions being dumped stored in for user app's consumption in + * TCA_ROOT_COUNT + * + * TCA_ACT_FLAG_TERSE_DUMP user->kernel to request terse (brief) dump that only + * includes essential action info (kind, index, etc.) * */ #define TCA_FLAG_LARGE_DUMP_ON (1 << 0) +#define TCA_ACT_FLAG_LARGE_DUMP_ON TCA_FLAG_LARGE_DUMP_ON +#define TCA_ACT_FLAG_TERSE_DUMP (1 << 1) /* New extended info filters for IFLA_EXT_MASK */ #define RTEXT_FILTER_VF (1 << 0) @@ -777,6 +798,8 @@ enum { #define RTEXT_FILTER_BRVLAN_COMPRESSED (1 << 2) #define RTEXT_FILTER_SKIP_STATS (1 << 3) #define RTEXT_FILTER_MRP (1 << 4) +#define RTEXT_FILTER_CFM_CONFIG (1 << 5) +#define RTEXT_FILTER_CFM_STATUS (1 << 6) /* End of information exported to user level */ From patchwork Tue Mar 30 04:01:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12171579 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BD4CC433E0 for ; Tue, 30 Mar 2021 04:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C482461959 for ; Tue, 30 Mar 2021 04:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231219AbhC3ECM (ORCPT ); Tue, 30 Mar 2021 00:02:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:46768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbhC3EB5 (ORCPT ); Tue, 30 Mar 2021 00:01:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F087E6196C; Tue, 30 Mar 2021 04:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617076917; bh=n4sEnSDmhYKsaExK7os5FLh2G6mjLQTpU3+v8OcDH4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=luZbY140k9rPB9hgobmXyzOaDrR/L1AVWyB2bNvQHzNwHPQMaMOLXMcSeEN/xEN/+ PdS0uS4nz3FnxXhOkEqu7iHagS2SHgYo4AciEB8Ll0DRB+QEO5XHIbIOttfXIdKB/p Z38UxnAmefVXdcyDgCeM/kIFc65IXku/SNuS2JhSVcTCfi8p9KklGoZ0JuLueu1eRE jQpahMDnOSjNWSsKXyZPY6iyeTSvpFiSBFOcwL62EIyZPIpOQDeuKzEzKsLVsHkAW8 Vsgdj90/YtCbX8Gbaqik9zV1mpbnzwsO/sMDF6I/4RSRKTKqkX1JBtaGQRaUA5sXWd PNxBWv7O5h2Zw== From: Jakub Kicinski To: mkubecek@suse.cz, andrew@lunn.ch Cc: netdev@vger.kernel.org, ecree.xilinx@gmail.com, Jakub Kicinski Subject: [RFC ethtool-next 2/3] json: simplify array print API Date: Mon, 29 Mar 2021 21:01:53 -0700 Message-Id: <20210330040154.1218028-2-kuba@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330040154.1218028-1-kuba@kernel.org> References: <20210330040154.1218028-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz X-Patchwork-State: RFC In ethtool when we print an array we usually have a label (non-JSON) and a key (JSON), because arrays are most often printed on a single line (unlike iproute2 where the output has multiple params on a line to cater to multi-interface dumps well). Build this into the json array API. Signed-off-by: Jakub Kicinski --- json_print.c | 20 ++++++++++---------- json_print.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/json_print.c b/json_print.c index 56d5b4337e49..4f62767bdbc9 100644 --- a/json_print.c +++ b/json_print.c @@ -73,15 +73,15 @@ void close_json_object(void) /* * Start json array or string array using * the provided string as json key (if not null) - * or as array delimiter in non-json context. + * or array delimiter in non-json context. */ -void open_json_array(enum output_type type, const char *str) +void open_json_array(const char *key, const char *str) { - if (_IS_JSON_CONTEXT(type)) { - if (str) - jsonw_name(_jw, str); + if (is_json_context()) { + if (key) + jsonw_name(_jw, key); jsonw_start_array(_jw); - } else if (_IS_FP_CONTEXT(type)) { + } else { printf("%s", str); } } @@ -89,12 +89,12 @@ void open_json_array(enum output_type type, const char *str) /* * End json array or string array */ -void close_json_array(enum output_type type, const char *str) +void close_json_array(const char *delim) { - if (_IS_JSON_CONTEXT(type)) + if (is_json_context()) jsonw_end_array(_jw); - else if (_IS_FP_CONTEXT(type)) - printf("%s", str); + else + printf("%s", delim); } /* diff --git a/json_print.h b/json_print.h index cc0c2ea19b59..df15314bafe2 100644 --- a/json_print.h +++ b/json_print.h @@ -37,8 +37,8 @@ void fflush_fp(void); void open_json_object(const char *str); void close_json_object(void); -void open_json_array(enum output_type type, const char *delim); -void close_json_array(enum output_type type, const char *delim); +void open_json_array(const char *key, const char *str); +void close_json_array(const char *delim); void print_nl(void); From patchwork Tue Mar 30 04:01:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 12171583 X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28881C433DB for ; Tue, 30 Mar 2021 04:02:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E88106198A for ; Tue, 30 Mar 2021 04:02:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230247AbhC3ECO (ORCPT ); Tue, 30 Mar 2021 00:02:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:46772 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbhC3EB5 (ORCPT ); Tue, 30 Mar 2021 00:01:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5FCD161988; Tue, 30 Mar 2021 04:01:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617076917; bh=iIPPKGY4sqkL6OlRUL9tOodRurxYcrbsY6xdumUhmmk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwNQb8kcbGQ0xVEZ6F5RBmpgr19NZRMrIdovYzKFife5lXbH8NGPiTu+ZfuiVtZW9 dyyv7Hpw1CRTfdC72wB6Ed/38uDvvJE/4YKtQgUBvem54PhLe5RK7j/pggRJAWWWmn JOFZytnwKo+H9F0sJ8BRU0TsHjC9iGx08E4jy38O4TnXG6km7ptA5bqa3shaafW/D9 jxeIVKEhtJhKxnxjx4yemB6mqkfzNRniQIPdy9jUB2knob29Cz2vdjUkuR4+qI6Mnf dsyANdQV6MAXMX7PwNz6BU94A1h2aR6tU2OFuNdyMvRS0Ps4czQACgSJt+yo9BRWDz Cttaxhb5OFGQA== From: Jakub Kicinski To: mkubecek@suse.cz, andrew@lunn.ch Cc: netdev@vger.kernel.org, ecree.xilinx@gmail.com, Jakub Kicinski Subject: [RFC ethtool-next 3/3] netlink: add FEC support Date: Mon, 29 Mar 2021 21:01:54 -0700 Message-Id: <20210330040154.1218028-3-kuba@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210330040154.1218028-1-kuba@kernel.org> References: <20210330040154.1218028-1-kuba@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz X-Patchwork-State: RFC Add support for FEC get/set over netlink. Output should be identical but for ordering of RS vs BaseR. Since the new output is based on link modes RS comes before BaseR in "Configured FEC encodings". Seems pretty unlikely someone depends on the ordering there. Since old API was case insensitive we need to carefully manage the bit names. Luckily for now most of the modes are all uppercase. Beyond that we need to cover up the discrepancy between the meanings of None and Off. Kernel API uses the link mode definition, but ethtool needs to maintain the old interpretation of None meaning "not supported". Because of those deviations existing link mode parsers can't be directly reused. Allocate error code 83 for FEC errors. JSON support included. Signed-off-by: Jakub Kicinski --- Makefile.am | 2 +- ethtool.c | 2 + netlink/desc-ethtool.c | 12 ++ netlink/extapi.h | 4 + netlink/fec.c | 273 +++++++++++++++++++++++++++++++++++++++++ netlink/monitor.c | 4 + netlink/netlink.h | 1 + 7 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 netlink/fec.c diff --git a/Makefile.am b/Makefile.am index e3e311d4b274..f643a24af97a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,7 +35,7 @@ ethtool_SOURCES += \ netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \ netlink/features.c netlink/privflags.c netlink/rings.c \ netlink/channels.c netlink/coalesce.c netlink/pause.c \ - netlink/eee.c netlink/tsinfo.c \ + netlink/eee.c netlink/tsinfo.c netlink/fec.c \ netlink/desc-ethtool.c netlink/desc-genlctrl.c \ netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \ uapi/linux/ethtool_netlink.h \ diff --git a/ethtool.c b/ethtool.c index fb90e9e456b9..0933bc02ce5e 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5963,11 +5963,13 @@ static const struct option args[] = { { .opts = "--show-fec", .func = do_gfec, + .nlfunc = nl_gfec, .help = "Show FEC settings", }, { .opts = "--set-fec", .func = do_sfec, + .nlfunc = nl_sfec, .help = "Set FEC settings", .xhelp = " [ encoding auto|off|rs|baser|llrs [...]]\n" }, diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c index 96291b9bdd3b..9da052a5b8aa 100644 --- a/netlink/desc-ethtool.c +++ b/netlink/desc-ethtool.c @@ -317,6 +317,14 @@ const struct pretty_nla_desc __tunnel_info_desc[] = { NLATTR_DESC_NESTED(ETHTOOL_A_TUNNEL_INFO_UDP_PORTS, tunnel_udp), }; +static const struct pretty_nla_desc __fec_desc[] = { + NLATTR_DESC_INVALID(ETHTOOL_A_FEC_UNSPEC), + NLATTR_DESC_NESTED(ETHTOOL_A_FEC_HEADER, header), + NLATTR_DESC_NESTED(ETHTOOL_A_FEC_MODES, bitset), + NLATTR_DESC_BOOL(ETHTOOL_A_FEC_AUTO), + NLATTR_DESC_U32(ETHTOOL_A_FEC_ACTIVE), +}; + const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE), NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset), @@ -347,6 +355,8 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_ACT, cable_test), NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_TDR_ACT, cable_test_tdr), NLMSG_DESC(ETHTOOL_MSG_TUNNEL_INFO_GET, tunnel_info), + NLMSG_DESC(ETHTOOL_MSG_FEC_GET, fec), + NLMSG_DESC(ETHTOOL_MSG_FEC_SET, fec), }; const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc); @@ -382,6 +392,8 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = { NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_NTF, cable_test_ntf), NLMSG_DESC(ETHTOOL_MSG_CABLE_TEST_TDR_NTF, cable_test_tdr_ntf), NLMSG_DESC(ETHTOOL_MSG_TUNNEL_INFO_GET_REPLY, tunnel_info), + NLMSG_DESC(ETHTOOL_MSG_FEC_GET_REPLY, fec), + NLMSG_DESC(ETHTOOL_MSG_FEC_NTF, fec), }; const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc); diff --git a/netlink/extapi.h b/netlink/extapi.h index 761cafb97855..5cadacce08e8 100644 --- a/netlink/extapi.h +++ b/netlink/extapi.h @@ -38,6 +38,8 @@ int nl_tsinfo(struct cmd_context *ctx); int nl_cable_test(struct cmd_context *ctx); int nl_cable_test_tdr(struct cmd_context *ctx); int nl_gtunnels(struct cmd_context *ctx); +int nl_gfec(struct cmd_context *ctx); +int nl_sfec(struct cmd_context *ctx); int nl_monitor(struct cmd_context *ctx); void nl_monitor_usage(void); @@ -87,6 +89,8 @@ static inline void nl_monitor_usage(void) #define nl_cable_test NULL #define nl_cable_test_tdr NULL #define nl_gtunnels NULL +#define nl_gfec NULL +#define nl_sfec NULL #endif /* ETHTOOL_ENABLE_NETLINK */ diff --git a/netlink/fec.c b/netlink/fec.c new file mode 100644 index 000000000000..9d15832db98a --- /dev/null +++ b/netlink/fec.c @@ -0,0 +1,273 @@ +/* + * fec.c - netlink implementation of FEC commands + * + * Implementation of "ethtool --show-fec " and + * "ethtool --set-fec ..." + */ + +#include +#include +#include +#include + +#include "../internal.h" +#include "../common.h" +#include "netlink.h" +#include "bitset.h" +#include "parser.h" + +/* FEC_GET */ + +static void +fec_mode_walk(unsigned int idx, const char *name, bool val, void *data) +{ + bool *empty = data; + + if (!val) + return; + if (empty) + *empty = false; + + /* Rename None to Off - in legacy ioctl None means "not supported" + * rather than supported but disabled. + */ + if (idx == ETHTOOL_LINK_MODE_FEC_NONE_BIT) + name = "Off"; + /* Rename to match the ioctl letter case */ + else if (idx == ETHTOOL_LINK_MODE_FEC_BASER_BIT) + name = "BaseR"; + + print_string(PRINT_ANY, NULL, " %s", name); +} + +int fec_reply_cb(const struct nlmsghdr *nlhdr, void *data) +{ + const struct nlattr *tb[ETHTOOL_A_FEC_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + struct nl_context *nlctx = data; + const struct stringset *lm_strings; + const char *name; + bool fa, empty; + bool silent; + int err_ret; + u32 active; + int ret; + + silent = nlctx->is_dump || nlctx->is_monitor; + err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR; + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return err_ret; + nlctx->devname = get_dev_name(tb[ETHTOOL_A_FEC_HEADER]); + if (!dev_ok(nlctx)) + return err_ret; + + ret = netlink_init_ethnl2_socket(nlctx); + if (ret < 0) + return err_ret; + lm_strings = global_stringset(ETH_SS_LINK_MODES, nlctx->ethnl2_socket); + + active = 0; + if (tb[ETHTOOL_A_FEC_ACTIVE]) + active = mnl_attr_get_u32(tb[ETHTOOL_A_FEC_ACTIVE]); + + if (silent) + print_nl(); + + open_json_object(NULL); + + print_string(PRINT_ANY, "ifname", "FEC parameters for %s:\n", + nlctx->devname); + + open_json_array("config", "Configured FEC encodings:"); + fa = tb[ETHTOOL_A_FEC_AUTO] && mnl_attr_get_u8(tb[ETHTOOL_A_FEC_AUTO]); + if (fa) + print_string(PRINT_ANY, NULL, " %s", "Auto"); + empty = !fa; + + ret = walk_bitset(tb[ETHTOOL_A_FEC_MODES], lm_strings, fec_mode_walk, + &empty); + if (ret < 0) + goto err_close_dev; + if (empty) + print_string(PRINT_ANY, NULL, " %s", "None"); + close_json_array("\n"); + + open_json_array("active", "Active FEC encoding:"); + if (active) { + name = get_string(lm_strings, active); + if (name) + /* Take care of renames */ + fec_mode_walk(active, name, true, NULL); + else + print_uint(PRINT_ANY, NULL, " BIT%u", active); + } else { + print_string(PRINT_ANY, NULL, " %s", "None"); + } + close_json_array("\n"); + + close_json_object(); + + return MNL_CB_OK; + +err_close_dev: + close_json_object(); + return err_ret; +} + +int nl_gfec(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_FEC_GET, true)) + return -EOPNOTSUPP; + if (ctx->argc > 0) { + fprintf(stderr, "ethtool: unexpected parameter '%s'\n", + *ctx->argp); + return 1; + } + + ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_FEC_GET, + ETHTOOL_A_FEC_HEADER, 0); + if (ret < 0) + return ret; + + new_json_obj(ctx->json); + ret = nlsock_send_get_request(nlsk, fec_reply_cb); + delete_json_obj(); + return ret; +} + +/* FEC_SET */ + +static void strupc(char *dst, const char *src) +{ + while (*src) + *dst++ = toupper(*src++); + *dst = '\0'; +} + +static int fec_parse_bitset(struct nl_context *nlctx, uint16_t type, + const void *data __maybe_unused, + struct nl_msg_buff *msgbuff, void *dest) +{ + struct nlattr *bitset_attr; + struct nlattr *bits_attr; + struct nlattr *bit_attr; + char upper[ETH_GSTRING_LEN]; + bool fec_auto = false; + int ret; + + if (!type || dest) { + fprintf(stderr, "ethtool (%s): internal error parsing '%s'\n", + nlctx->cmd, nlctx->param); + return -EFAULT; + } + + bitset_attr = ethnla_nest_start(msgbuff, type); + if (!bitset_attr) + return -EMSGSIZE; + ret = -EMSGSIZE; + if (ethnla_put_flag(msgbuff, ETHTOOL_A_BITSET_NOMASK, true)) + goto err; + bits_attr = ethnla_nest_start(msgbuff, ETHTOOL_A_BITSET_BITS); + if (!bits_attr) + goto err; + + while (nlctx->argc > 0) { + const char *name = *nlctx->argp; + + if (!strcmp(name, "--")) + goto next; + + if (!strcasecmp(name, "auto")) { + fec_auto = true; + goto next; + } + if (!strcasecmp(name, "off")) { + name = "None"; + } else { + strupc(upper, name); + name = upper; + } + + ret = -EMSGSIZE; + bit_attr = ethnla_nest_start(msgbuff, + ETHTOOL_A_BITSET_BITS_BIT); + if (!bit_attr) + goto err; + if (ethnla_put_strz(msgbuff, ETHTOOL_A_BITSET_BIT_NAME, name)) + goto err; + ethnla_nest_end(msgbuff, bit_attr); + +next: + nlctx->argp++; + nlctx->argc--; + } + + ethnla_nest_end(msgbuff, bits_attr); + ethnla_nest_end(msgbuff, bitset_attr); + + if (ethnla_put_u8(msgbuff, ETHTOOL_A_FEC_AUTO, fec_auto)) + goto err; + + return 0; +err: + ethnla_nest_cancel(msgbuff, bitset_attr); + return ret; +} + +static const struct param_parser sfec_params[] = { + { + .arg = "encoding", + .type = ETHTOOL_A_FEC_MODES, + .handler = fec_parse_bitset, + .min_argc = 1, + }, + {} +}; + +int nl_sfec(struct cmd_context *ctx) +{ + struct nl_context *nlctx = ctx->nlctx; + struct nl_msg_buff *msgbuff; + struct nl_socket *nlsk; + int ret; + + if (netlink_cmd_check(ctx, ETHTOOL_MSG_FEC_SET, false)) + return -EOPNOTSUPP; + if (!ctx->argc) { + fprintf(stderr, "ethtool (--set-fec): parameters missing\n"); + return 1; + } + + nlctx->cmd = "--set-fec"; + nlctx->argp = ctx->argp; + nlctx->argc = ctx->argc; + nlctx->devname = ctx->devname; + nlsk = nlctx->ethnl_socket; + msgbuff = &nlsk->msgbuff; + + ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_FEC_SET, + NLM_F_REQUEST | NLM_F_ACK); + if (ret < 0) + return 2; + if (ethnla_fill_header(msgbuff, ETHTOOL_A_FEC_HEADER, + ctx->devname, 0)) + return -EMSGSIZE; + + ret = nl_parser(nlctx, sfec_params, NULL, PARSER_GROUP_NONE, NULL); + if (ret < 0) + return 1; + + ret = nlsock_sendmsg(nlsk, NULL); + if (ret < 0) + return 83; + ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx); + if (ret == 0) + return 0; + else + return nlctx->exit_code ?: 83; +} diff --git a/netlink/monitor.c b/netlink/monitor.c index 19f991fce3e4..0c4df9e78ee3 100644 --- a/netlink/monitor.c +++ b/netlink/monitor.c @@ -67,6 +67,10 @@ static struct { .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_NTF, .cb = cable_test_tdr_ntf_cb, }, + { + .cmd = ETHTOOL_MSG_FEC_NTF, + .cb = fec_reply_cb, + }, }; static void clear_filter(struct nl_context *nlctx) diff --git a/netlink/netlink.h b/netlink/netlink.h index c02558540218..70fa666b20e5 100644 --- a/netlink/netlink.h +++ b/netlink/netlink.h @@ -90,6 +90,7 @@ int cable_test_reply_cb(const struct nlmsghdr *nlhdr, void *data); int cable_test_ntf_cb(const struct nlmsghdr *nlhdr, void *data); int cable_test_tdr_reply_cb(const struct nlmsghdr *nlhdr, void *data); int cable_test_tdr_ntf_cb(const struct nlmsghdr *nlhdr, void *data); +int fec_reply_cb(const struct nlmsghdr *nlhdr, void *data); /* dump helpers */