Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp674715img; Thu, 21 Mar 2019 06:44:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxf4X26nPqrirWtvm3gLh3TO6B0H9eBOhrHoDM5aCIGLpz+fS+dTFpOw+rjiA1ez18cpnav X-Received: by 2002:aa7:8299:: with SMTP id s25mr3435105pfm.56.1553175847161; Thu, 21 Mar 2019 06:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553175847; cv=none; d=google.com; s=arc-20160816; b=FRZUKzvpf4Lrlmll61VT1yltS2RtuU9T9rlk0btVUrD+zarMPaU1sEBQUITOkQfMkp maNWnblYVRwDSYfgilKEEZd2PDp7Jf4dFFi6qItvD692XeqmvAJVw+MSm0OW2gXyu1Xt 4Iif7N/CJAWvKYM397nHgJ04PdL9MyzvwIVa+0izc2curJW+fxK8ZSCdg/HF7vWCeqIA Mau7dOtsafaWWe3yQL8kRfqqW0FMYymRKFAgem34h5l5bB12NEtzoYDyuxgG1bH64I+m bY084UxgtZNdHchq295LXoVbErwlDvefXS7mmOFAeoNT6iqIn3lHG1siUtDvGa/SurH3 82tw== 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=efclk19ic3WpbrZQXEWBDE3iXU7IJKEbH3YCVg1XGa0=; b=KnVTxfnuPMuO1phNzIWd+2eSWyvUp+NsD0ZWyc52gAi3TMq6uorxVgawotoE3jqovp Tom+mKYzg8ZtG91AcuA8991Cd/GzvB4oUq+HAhLX978R1hUQBDouDdbKK0u4o572x4Vw 8NdJKRT2xtJ81BAFAFzOeb0V1PuhqdL0DEuIeQx3+BBK9BmbqCijW3mXEE1wMiLUmp1/ jzdhwhPD196EWpCAGX2T8uNE3bmTlER6FnqoiXMXLoCqGGl6447tQUmGKji+E4E+0F8P 5/eCXotr6okKsUQQgvbnzpb//POip02zlgciRScVwu2GdAz3ei8qo423WdmjyG/cwcnt yahQ== 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 t15si4352862pgr.522.2019.03.21.06.43.52; Thu, 21 Mar 2019 06:44:07 -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 S1728600AbfCUNlI (ORCPT + 99 others); Thu, 21 Mar 2019 09:41:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:36490 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728579AbfCUNlF (ORCPT ); Thu, 21 Mar 2019 09:41:05 -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 BC194AFAF; Thu, 21 Mar 2019 13:41:03 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 692DBE00BF; Thu, 21 Mar 2019 14:41:03 +0100 (CET) Message-Id: <3af2ddbb88c7f91e6783177bfd0f0cb47223b957.1553170807.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH net-next v4 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 , linux-kernel@vger.kernel.org Date: Thu, 21 Mar 2019 14:41:03 +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 ab30f77eda25..521b139f46b6 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -6,6 +6,84 @@ u32 ethnl_bcast_seq; +#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 }, @@ -596,6 +674,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 (ret < 0) panic("ethtool: could not register genetlink family\n"); 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