Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3433991img; Mon, 25 Mar 2019 10:11:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTHcCv+0EgTRyMWAMgD+lCvnIGJwqlWg1LIAtio2skcvJBMmY2wPJrOJSiiDrGDEsZTdKC X-Received: by 2002:a17:902:3f83:: with SMTP id a3mr24948494pld.6.1553533886523; Mon, 25 Mar 2019 10:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553533886; cv=none; d=google.com; s=arc-20160816; b=s2Um6HfoVcymuQn3MsmwuF+WqYYEAFE4p0dJk/gx3IOPYW948EjsWAF8Rvh25h5pC/ DOOXsGGo90BihRosuAvOZb7PkrlNzBis2YaLnQkZxH3LGQ59431HgeeSjElR894VwtXc 7cY+Nh8Jx036anYesk7L62OoQ0GsjNybm3PQOcIPEq/yVJ5pxE31Dwyd9vkcvEpxVSdl kq4Vdp1Ywr0ceqD9rc+4b3g+2Qq3ynniEYxgqI7jzhdeE1HSKq+GDyuokAq2bZKKYxWN fWPMwgOtswCdYlRRDTF5fVstOGBEkjCcXBl1pVLkEHGzQc83oLZA9Urxfrx0boBhSKZV OEfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id; bh=N0E2zID9PFuGLQBQXydraqJHD38kPeFe//Gnukiia08=; b=LS6pdio6husDpS7A6UFnqvXKHa69KAlBiwXjr/NYosDJ8VRvLD9QA1RW8jg1AlsG7/ XuEDutaEr1QGRpbCvLkn7xDokkY3aiKSfsDrrIlwkMkwfiWYzaSwC4oiVHMXhutZlgwO 3pf/rjdRwUN/A4XMQ0blPG1QmRH/F/ku1EcZDLdSsOVPMQ3IxdvvIqLjLLW16bh9FLNz /mYM2a5Axk8/TjdbmEpZukdt14nHcZVBMNj5H1Q0sL86lw8tybwmL62Amm3Z/1/py5v9 PSqaCQ0/Z4vdSTY8L0wcum29KzHfAArDg1vONtFsHnT8tAY1iSXh85BHCk47gJWE6OLK xLoA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si11643661plt.418.2019.03.25.10.11.11; Mon, 25 Mar 2019 10:11:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730368AbfCYRIp (ORCPT + 99 others); Mon, 25 Mar 2019 13:08:45 -0400 Received: from mx2.suse.de ([195.135.220.15]:51244 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730326AbfCYRIm (ORCPT ); Mon, 25 Mar 2019 13:08:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 48CBBB018; Mon, 25 Mar 2019 17:08:40 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id E95D6E1404; Mon, 25 Mar 2019 18:08:39 +0100 (CET) Message-Id: <823fb9fb5d2055836719962d30befbc5da8e9310.1553532199.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v5 15/22] ethtool: provide link mode names as a string set To: David Miller , netdev@vger.kernel.org Cc: Jakub Kicinski , Jiri Pirko , Andrew Lunn , Florian Fainelli , John Linville , Stephen Hemminger , linux-kernel@vger.kernel.org Date: Mon, 25 Mar 2019 18:08:39 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add table of ethernet link mode names and make it available as a string set to userspace GET_STRSET requests. Signed-off-by: Michal Kubecek --- include/linux/ethtool.h | 4 ++ include/uapi/linux/ethtool.h | 2 + net/ethtool/netlink.c | 81 ++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.h | 1 + net/ethtool/strset.c | 6 +++ 5 files changed, 94 insertions(+) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index e6ebc9761822..ac3612599450 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -102,6 +102,10 @@ static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) +/* compose link mode index from speed, type and duplex */ +#define ETHTOOL_LINK_MODE(speed, type, duplex) \ + ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT + /* drivers must ignore base.cmd and base.link_mode_masks_nwords * fields, but they are allowed to overwrite them (will be ignored). */ diff --git a/include/uapi/linux/ethtool.h b/include/uapi/linux/ethtool.h index 882a542eaaa9..ef1288eb737c 100644 --- a/include/uapi/linux/ethtool.h +++ b/include/uapi/linux/ethtool.h @@ -566,6 +566,7 @@ struct ethtool_pauseparam { * @ETH_SS_TSTAMP_SOF: timestamping flag names * @ETH_SS_TSTAMP_TX_TYPE: timestamping Tx type names * @ETH_SS_TSTAMP_RX_FILTER: timestamping Rx filter names + * @ETH_SS_LINK_MODES: link mode names */ enum ethtool_stringset { ETH_SS_TEST = 0, @@ -580,6 +581,7 @@ enum ethtool_stringset { ETH_SS_TSTAMP_SOF, ETH_SS_TSTAMP_TX_TYPE, ETH_SS_TSTAMP_RX_FILTER, + ETH_SS_LINK_MODES, ETH_SS_COUNT }; diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index 7f9597c0c7a7..f0385c30169b 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -8,6 +8,84 @@ u32 ethnl_bcast_seq; static bool ethnl_ok __read_mostly; +#define __LINK_MODE_NAME(speed, type, duplex) \ + #speed "base" #type "/" #duplex +#define __DEFINE_LINK_MODE_NAME(speed, type, duplex) \ + [ETHTOOL_LINK_MODE(speed, type, duplex)] = \ + __LINK_MODE_NAME(speed, type, duplex) +#define __DEFINE_SPECIAL_MODE_NAME(_mode, _name) \ + [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = _name + +const char *const link_mode_names[] = { + __DEFINE_LINK_MODE_NAME(10, T, Half), + __DEFINE_LINK_MODE_NAME(10, T, Full), + __DEFINE_LINK_MODE_NAME(100, T, Half), + __DEFINE_LINK_MODE_NAME(100, T, Full), + __DEFINE_LINK_MODE_NAME(1000, T, Half), + __DEFINE_LINK_MODE_NAME(1000, T, Full), + __DEFINE_SPECIAL_MODE_NAME(Autoneg, "Autoneg"), + __DEFINE_SPECIAL_MODE_NAME(TP, "TP"), + __DEFINE_SPECIAL_MODE_NAME(AUI, "AUI"), + __DEFINE_SPECIAL_MODE_NAME(MII, "MII"), + __DEFINE_SPECIAL_MODE_NAME(FIBRE, "FIBRE"), + __DEFINE_SPECIAL_MODE_NAME(BNC, "BNC"), + __DEFINE_LINK_MODE_NAME(10000, T, Full), + __DEFINE_SPECIAL_MODE_NAME(Pause, "Pause"), + __DEFINE_SPECIAL_MODE_NAME(Asym_Pause, "Asym_Pause"), + __DEFINE_LINK_MODE_NAME(2500, X, Full), + __DEFINE_SPECIAL_MODE_NAME(Backplane, "Backplane"), + __DEFINE_LINK_MODE_NAME(1000, KX, Full), + __DEFINE_LINK_MODE_NAME(10000, KX4, Full), + __DEFINE_LINK_MODE_NAME(10000, KR, Full), + [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = "10000baseR_FEC", + __DEFINE_LINK_MODE_NAME(20000, MLD2, Full), + __DEFINE_LINK_MODE_NAME(20000, KR2, Full), + __DEFINE_LINK_MODE_NAME(40000, KR4, Full), + __DEFINE_LINK_MODE_NAME(40000, CR4, Full), + __DEFINE_LINK_MODE_NAME(40000, SR4, Full), + __DEFINE_LINK_MODE_NAME(40000, LR4, Full), + __DEFINE_LINK_MODE_NAME(56000, KR4, Full), + __DEFINE_LINK_MODE_NAME(56000, CR4, Full), + __DEFINE_LINK_MODE_NAME(56000, SR4, Full), + __DEFINE_LINK_MODE_NAME(56000, LR4, Full), + __DEFINE_LINK_MODE_NAME(25000, CR, Full), + __DEFINE_LINK_MODE_NAME(25000, KR, Full), + __DEFINE_LINK_MODE_NAME(25000, SR, Full), + __DEFINE_LINK_MODE_NAME(50000, CR2, Full), + __DEFINE_LINK_MODE_NAME(50000, KR2, Full), + __DEFINE_LINK_MODE_NAME(100000, KR4, Full), + __DEFINE_LINK_MODE_NAME(100000, SR4, Full), + __DEFINE_LINK_MODE_NAME(100000, CR4, Full), + __DEFINE_LINK_MODE_NAME(100000, LR4_ER4, Full), + __DEFINE_LINK_MODE_NAME(50000, SR2, Full), + __DEFINE_LINK_MODE_NAME(1000, X, Full), + __DEFINE_LINK_MODE_NAME(10000, CR, Full), + __DEFINE_LINK_MODE_NAME(10000, SR, Full), + __DEFINE_LINK_MODE_NAME(10000, LR, Full), + __DEFINE_LINK_MODE_NAME(10000, LRM, Full), + __DEFINE_LINK_MODE_NAME(10000, ER, Full), + __DEFINE_LINK_MODE_NAME(2500, T, Full), + __DEFINE_LINK_MODE_NAME(5000, T, Full), + __DEFINE_SPECIAL_MODE_NAME(FEC_NONE, "None"), + __DEFINE_SPECIAL_MODE_NAME(FEC_RS, "RS"), + __DEFINE_SPECIAL_MODE_NAME(FEC_BASER, "BASER"), + __DEFINE_LINK_MODE_NAME(50000, KR, Full), + __DEFINE_LINK_MODE_NAME(50000, SR, Full), + __DEFINE_LINK_MODE_NAME(50000, CR, Full), + __DEFINE_LINK_MODE_NAME(50000, LR_ER_FR, Full), + __DEFINE_LINK_MODE_NAME(50000, DR, Full), + __DEFINE_LINK_MODE_NAME(100000, KR2, Full), + __DEFINE_LINK_MODE_NAME(100000, SR2, Full), + __DEFINE_LINK_MODE_NAME(100000, CR2, Full), + __DEFINE_LINK_MODE_NAME(100000, LR2_ER2_FR2, Full), + __DEFINE_LINK_MODE_NAME(100000, DR2, Full), + __DEFINE_LINK_MODE_NAME(200000, KR4, Full), + __DEFINE_LINK_MODE_NAME(200000, SR4, Full), + __DEFINE_LINK_MODE_NAME(200000, LR4_ER4_FR4, Full), + __DEFINE_LINK_MODE_NAME(200000, DR4, Full), + __DEFINE_LINK_MODE_NAME(200000, CR4, Full), +}; + static const struct nla_policy dev_policy[ETHA_DEV_MAX + 1] = { [ETHA_DEV_UNSPEC] = { .type = NLA_REJECT }, [ETHA_DEV_INDEX] = { .type = NLA_U32 }, @@ -600,6 +678,9 @@ static int __init ethnl_init(void) { int ret; + BUILD_BUG_ON(ARRAY_SIZE(link_mode_names) < + __ETHTOOL_LINK_MODE_MASK_NBITS); + ret = genl_register_family(ðtool_genl_family); if (WARN(ret < 0, "ethtool: genetlink family registration failed")) return ret; diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 4ad9a3eee3e5..ce60d7e18651 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -23,6 +23,7 @@ extern struct genl_family ethtool_genl_family; extern const char *const so_timestamping_labels[]; extern const char *const tstamp_tx_type_labels[]; extern const char *const tstamp_rx_filter_labels[]; +extern const char *const link_mode_names[]; struct net_device *ethnl_dev_get(struct genl_info *info, struct nlattr *nest); int ethnl_fill_dev(struct sk_buff *msg, struct net_device *dev, u16 attrtype); diff --git a/net/ethtool/strset.c b/net/ethtool/strset.c index e1b831097ca7..577d1309ba6f 100644 --- a/net/ethtool/strset.c +++ b/net/ethtool/strset.c @@ -85,6 +85,12 @@ static const struct strset_info info_template[] = { .count = __HWTSTAMP_FILTER_COUNT, .data = { .simple = tstamp_rx_filter_labels }, }, + [ETH_SS_LINK_MODES] = { + .type = ETH_SS_TYPE_SIMPLE, + .per_dev = false, + .count = __ETHTOOL_LINK_MODE_MASK_NBITS, + .data = { .simple = link_mode_names }, + }, }; struct strset_data { -- 2.21.0