From patchwork Tue Mar 15 03:18:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "wangjie (L)" X-Patchwork-Id: 12780986 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0D53C433F5 for ; Tue, 15 Mar 2022 03:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344520AbiCODZX (ORCPT ); Mon, 14 Mar 2022 23:25:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbiCODZV (ORCPT ); Mon, 14 Mar 2022 23:25:21 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974B435862 for ; Mon, 14 Mar 2022 20:24:10 -0700 (PDT) Received: from kwepemi500015.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KHdyB02gMzfYq0; Tue, 15 Mar 2022 11:22:41 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500015.china.huawei.com (7.221.188.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 15 Mar 2022 11:24:08 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 15 Mar 2022 11:24:08 +0800 From: Jie Wang To: , , , CC: , , , , , , , , Subject: [RFC ethtool 1/2] ethtool: add has_input in struct cmdline_info to record cmdline params Date: Tue, 15 Mar 2022 11:18:33 +0800 Message-ID: <20220315031834.56676-2-wangjie125@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220315031834.56676-1-wangjie125@huawei.com> References: <20220315031834.56676-1-wangjie125@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz X-Patchwork-State: RFC In driver feature configuration scene, ethtool need to record the config combination. So this patch add has_input to mark the features to be configured. Signed-off-by: Jie Wang --- ethtool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ethtool.c b/ethtool.c index 5d718a2..e2b4e17 100644 --- a/ethtool.c +++ b/ethtool.c @@ -111,6 +111,8 @@ struct cmdline_info { * For anything else, points to int and is set if the option is * seen. */ void *seen_val; + /* indicate current input has this item */ + u32 has_input; }; struct feature_def { @@ -244,6 +246,7 @@ static void parse_generic_cmdline(struct cmd_context *ctx, if (!strcmp(info[idx].name, argp[i])) { found = 1; *changed = 1; + info[idx].has_input = 1; if (info[idx].type != CMDL_FLAG && info[idx].seen_val) *(int *)info[idx].seen_val = 1; From patchwork Tue Mar 15 03:18:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "wangjie (L)" X-Patchwork-Id: 12780987 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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0AD7C433EF for ; Tue, 15 Mar 2022 03:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230445AbiCODZY (ORCPT ); Mon, 14 Mar 2022 23:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244124AbiCODZW (ORCPT ); Mon, 14 Mar 2022 23:25:22 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDCF035876 for ; Mon, 14 Mar 2022 20:24:10 -0700 (PDT) Received: from kwepemi500013.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KHdt86bt6z1GCMt; Tue, 15 Mar 2022 11:19:12 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500013.china.huawei.com (7.221.188.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 15 Mar 2022 11:24:09 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 15 Mar 2022 11:24:08 +0800 From: Jie Wang To: , , , CC: , , , , , , , , Subject: [RFC ethtool 2/2] ethtool: add support to get/set device features Date: Tue, 15 Mar 2022 11:18:34 +0800 Message-ID: <20220315031834.56676-3-wangjie125@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220315031834.56676-1-wangjie125@huawei.com> References: <20220315031834.56676-1-wangjie125@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz X-Patchwork-State: RFC Currently tx push is a standard feature for NICs such as Mellanox, nVidia and Broadcom. But there is no cmd for features contained entirely to the driver. So this patch add cmd "ethtool --set-dev-features tx-push [on |off]" and "ethtool --get-dev-features " to set/get features contained entirely to the driver. Signed-off-by: Jie Wang --- ethtool.c | 113 +++++++++++++++++++++++++++++++++++++++++++ uapi/linux/ethtool.h | 27 +++++++++++ 2 files changed, 140 insertions(+) diff --git a/ethtool.c b/ethtool.c index e2b4e17..3f28782 100644 --- a/ethtool.c +++ b/ethtool.c @@ -1956,6 +1956,108 @@ static int do_spause(struct cmd_context *ctx) return 0; } +static void show_tx_push_mode(struct ethtool_dev_features *dev_features) +{ + fprintf(stdout, "tx push mode: %s\n", + dev_features->data ? "on" : "off"); +} + +static void dump_devfeatures(struct ethtool_dev_features *dev_feat, u32 i) +{ + struct dump_proto { + __u64 features_bit; + void (*show_func)(struct ethtool_dev_features *dev_feat); + } show_features[] = { + { ETHTOOL_DEV_TX_PUSH, show_tx_push_mode } + }; + + if (i < ARRAY_SIZE(show_features) && show_features[i].show_func) + show_features[i].show_func(dev_feat); +} + +const enum ethtool_dev_features_type dev_feature_type[] = { + ETHTOOL_DEV_TX_PUSH, +}; + +static int do_gdevfeatures(struct cmd_context *ctx) +{ + struct ethtool_dev_features dev_features; + u32 i, failed_cnt = 0; + int ret; + + for (i = 0; i < ARRAY_SIZE(dev_feature_type); ++i) { + dev_features.cmd = ETHTOOL_GDEVFEAT; + dev_features.type = dev_feature_type[i]; + ret = send_ioctl(ctx, &dev_features); + if (ret) { + ++failed_cnt; + continue; + } + + dump_devfeatures(&dev_features, i); + } + + if (failed_cnt == ARRAY_SIZE(dev_feature_type)) { + perror("Cannot get any device features"); + return 75; + } + + return 0; +} + +static int do_sdevfeatures(struct cmd_context *ctx) +{ + u32 i, unchanged_num = 0, set_value = 1; + struct ethtool_dev_features dev_feat; + struct cmdline_info feat_line[] = { + { + .name = "tx-push", + .type = CMDL_BOOL, + .wanted_val = &set_value, + .ioctl_val = &dev_feat.data, + } + }; + int err, changed; + + parse_generic_cmdline(ctx, &changed, feat_line, ARRAY_SIZE(feat_line)); + + for (i = 0; i < ARRAY_SIZE(feat_line); i++) { + if (!feat_line[i].has_input) { + ++unchanged_num; + continue; + } + + dev_feat.cmd = ETHTOOL_GDEVFEAT; + dev_feat.type = dev_feature_type[i]; + err = send_ioctl(ctx, &dev_feat); + if (err) { + perror("Cannot get device features"); + return err; + } + + changed = false; + do_generic_set1(&feat_line[i], &changed); + if (!changed) { + ++unchanged_num; + continue; + } + + dev_feat.cmd = ETHTOOL_SDEVFEAT; + err = send_ioctl(ctx, &dev_feat); + if (err) { + perror("Cannot set device parameters"); + return err; + } + } + + if (unchanged_num == ARRAY_SIZE(feat_line)) { + fprintf(stderr, "no device feature parameters changed, aborting\n"); + return 75; + } + + return 0; +} + static int do_sring(struct cmd_context *ctx) { struct ethtool_ringparam ering; @@ -6062,6 +6164,17 @@ static const struct option args[] = { .help = "Set transceiver module settings", .xhelp = " [ power-mode-policy high|auto ]\n" }, + { + .opts = "--show-dev-features", + .func = do_gdevfeatures, + .help = "Get device driver features", + }, + { + .opts = "--set-dev-features", + .func = do_sdevfeatures, + .help = "Set device driver features", + .xhelp = " [ tx-push on|off ]\n" + }, { .opts = "-h|--help", .no_dev = true, diff --git a/uapi/linux/ethtool.h b/uapi/linux/ethtool.h index 85548f9..4e3ccee 100644 --- a/uapi/linux/ethtool.h +++ b/uapi/linux/ethtool.h @@ -221,6 +221,31 @@ struct ethtool_value { __u32 data; }; +/** + * struct ethtool_dev_features - device feature configurations + * @cmd: Command number = %ETHTOOL_GDEVFEAT or %ETHTOOL_SDEVFEAT + * @type: feature configuration type. + * @data: feature configuration value. + */ +struct ethtool_dev_features { + __u32 cmd; + __u32 type; + __u32 data; +}; + +/** + * enum ethtool_dev_features_type - flags definition of ethtool_dev_features + * @ETHTOOL_DEV_TX_PUSH: nic tx push mode set bit. + */ +enum ethtool_dev_features_type { + ETHTOOL_DEV_TX_PUSH, + /* + * Add your fresh feature type above and remember to update + * feat_line[] in ethtool.c + */ + ETHTOOL_DEV_FEATURE_COUNT, +}; + #define PFC_STORM_PREVENTION_AUTO 0xffff #define PFC_STORM_PREVENTION_DISABLE 0 @@ -1582,6 +1607,8 @@ enum ethtool_fec_config_bits { #define ETHTOOL_PHY_STUNABLE 0x0000004f /* Set PHY tunable configuration */ #define ETHTOOL_GFECPARAM 0x00000050 /* Get FEC settings */ #define ETHTOOL_SFECPARAM 0x00000051 /* Set FEC settings */ +#define ETHTOOL_GDEVFEAT 0x00000052 /* Get device features */ +#define ETHTOOL_SDEVFEAT 0x00000053 /* Set device features */ /* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET