From patchwork Sun Aug 23 19:40:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kubecek X-Patchwork-Id: 262034 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=-9.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UPPERCASE_50_75 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 8B50AC433E1 for ; Sun, 23 Aug 2020 19:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6440E20720 for ; Sun, 23 Aug 2020 19:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726884AbgHWTkn (ORCPT ); Sun, 23 Aug 2020 15:40:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:50814 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726803AbgHWTkj (ORCPT ); Sun, 23 Aug 2020 15:40:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id D36EFAEC4; Sun, 23 Aug 2020 19:41:05 +0000 (UTC) Received: by lion.mk-sys.cz (Postfix, from userid 1000) id 3E43E6030D; Sun, 23 Aug 2020 21:40:36 +0200 (CEST) Message-Id: <562b9a44ae5c6af4c801d8abf3a7cf318d2bfd32.1598210544.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [PATCH ethtool v2 7/9] settings: simplify link_mode_info[] initializers To: netdev@vger.kernel.org Cc: Andrew Lunn Date: Sun, 23 Aug 2020 21:40:36 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use macro helpers to make link_mode_info[] initializers easier to read and less prone to mistakes. As a bonus, this gets rid of "missing field initializer" warnings in netlink/settings.c This commit should have no effect on resulting code (checked with gcc-11 and -O2). Signed-off-by: Michal Kubecek Reviewed-by: Andrew Lunn --- netlink/settings.c | 236 +++++++++++++++++---------------------------- 1 file changed, 86 insertions(+), 150 deletions(-) diff --git a/netlink/settings.c b/netlink/settings.c index 99d047a3e497..935724e799da 100644 --- a/netlink/settings.c +++ b/netlink/settings.c @@ -64,160 +64,96 @@ static const char *const names_transceiver[] = { * there is little chance of getting them separated any time soon so let's * sort them out ourselves */ +#define __REAL(_speed) \ + { .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_FULL } +#define __HALF_DUPLEX(_speed) \ + { .class = LM_CLASS_REAL, .speed = _speed, .duplex = DUPLEX_HALF } +#define __SPECIAL(_class) \ + { .class = LM_CLASS_ ## _class } + static const struct link_mode_info link_modes[] = { - [ETHTOOL_LINK_MODE_10baseT_Half_BIT] = - { LM_CLASS_REAL, 10, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_10baseT_Full_BIT] = - { LM_CLASS_REAL, 10, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100baseT_Half_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_100baseT_Full_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_HALF }, - [ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Autoneg_BIT] = - { LM_CLASS_AUTONEG }, - [ETHTOOL_LINK_MODE_TP_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_AUI_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_MII_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_FIBRE_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_BNC_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Pause_BIT] = - { LM_CLASS_PAUSE }, - [ETHTOOL_LINK_MODE_Asym_Pause_BIT] = - { LM_CLASS_PAUSE }, - [ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = - { LM_CLASS_REAL, 2500, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_Backplane_BIT] = - { LM_CLASS_PORT }, - [ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = - { LM_CLASS_REAL, 20000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 20000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = - { LM_CLASS_REAL, 40000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = - { LM_CLASS_REAL, 56000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = - { LM_CLASS_REAL, 25000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = - { LM_CLASS_REAL, 10000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = - { LM_CLASS_REAL, 2500, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = - { LM_CLASS_REAL, 5000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_FEC_NONE_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_FEC_RS_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_FEC_BASER_BIT] = - { LM_CLASS_FEC }, - [ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] = - { LM_CLASS_REAL, 50000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] = - { LM_CLASS_REAL, 100000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] = - { LM_CLASS_REAL, 200000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_100baseT1_Full_BIT] = - { LM_CLASS_REAL, 100, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_1000baseT1_Full_BIT] = - { LM_CLASS_REAL, 1000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT] = - { LM_CLASS_REAL, 400000, DUPLEX_FULL }, - [ETHTOOL_LINK_MODE_FEC_LLRS_BIT] = - { LM_CLASS_FEC }, + [ETHTOOL_LINK_MODE_10baseT_Half_BIT] = __HALF_DUPLEX(10), + [ETHTOOL_LINK_MODE_10baseT_Full_BIT] = __REAL(10), + [ETHTOOL_LINK_MODE_100baseT_Half_BIT] = __HALF_DUPLEX(100), + [ETHTOOL_LINK_MODE_100baseT_Full_BIT] = __REAL(100), + [ETHTOOL_LINK_MODE_1000baseT_Half_BIT] = __HALF_DUPLEX(1000), + [ETHTOOL_LINK_MODE_1000baseT_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_Autoneg_BIT] = __SPECIAL(AUTONEG), + [ETHTOOL_LINK_MODE_TP_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_AUI_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_MII_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_FIBRE_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_BNC_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_10000baseT_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_Pause_BIT] = __SPECIAL(PAUSE), + [ETHTOOL_LINK_MODE_Asym_Pause_BIT] = __SPECIAL(PAUSE), + [ETHTOOL_LINK_MODE_2500baseX_Full_BIT] = __REAL(2500), + [ETHTOOL_LINK_MODE_Backplane_BIT] = __SPECIAL(PORT), + [ETHTOOL_LINK_MODE_1000baseKX_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseKR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseR_FEC_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT] = __REAL(20000), + [ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT] = __REAL(20000), + [ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT] = __REAL(40000), + [ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT] = __REAL(56000), + [ETHTOOL_LINK_MODE_25000baseCR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_25000baseKR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_25000baseSR_Full_BIT] = __REAL(25000), + [ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_1000baseX_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_10000baseCR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseSR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseLR_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_10000baseER_Full_BIT] = __REAL(10000), + [ETHTOOL_LINK_MODE_2500baseT_Full_BIT] = __REAL(2500), + [ETHTOOL_LINK_MODE_5000baseT_Full_BIT] = __REAL(5000), + [ETHTOOL_LINK_MODE_FEC_NONE_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_FEC_RS_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_FEC_BASER_BIT] = __SPECIAL(FEC), + [ETHTOOL_LINK_MODE_50000baseKR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseSR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseCR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_50000baseDR_Full_BIT] = __REAL(50000), + [ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT] = __REAL(100000), + [ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT] = __REAL(200000), + [ETHTOOL_LINK_MODE_100baseT1_Full_BIT] = __REAL(100), + [ETHTOOL_LINK_MODE_1000baseT1_Full_BIT] = __REAL(1000), + [ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT] = __REAL(400000), + [ETHTOOL_LINK_MODE_FEC_LLRS_BIT] = __SPECIAL(FEC), }; const unsigned int link_modes_count = ARRAY_SIZE(link_modes); +#undef __REAL +#undef __HALF_DUPLEX +#undef __SPECIAL + static bool lm_class_match(unsigned int mode, enum link_mode_class class) { unsigned int mode_class = (mode < link_modes_count) ?