From patchwork Tue Sep 15 23:52:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 260821 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 A8546C433E2 for ; Tue, 15 Sep 2020 23:54:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 695D120739 for ; Tue, 15 Sep 2020 23:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600214048; bh=Z6lv7rGj6RRAUhAA0eR8FrsBXGgpmjKJA4K97EO5Ue0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zRJHisGwKqm8XjVw/GvO/G4mB8alF0Y69NUU8BwToiE0/mhLt5NtypY82eEk1q7P8 wvIDw5WT6B2onXs9HkCTMQDewS9fS2eHbbIrQUkr+BcHt/ltC5dHxyBCC3Ik3HKk0q 960ReNwXjZ2s3V409EDYjeIrGCPGjBazXt2s2ITI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727258AbgIOXyD (ORCPT ); Tue, 15 Sep 2020 19:54:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:49618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727141AbgIOXxB (ORCPT ); Tue, 15 Sep 2020 19:53:01 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E348A20809; Tue, 15 Sep 2020 23:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600213981; bh=Z6lv7rGj6RRAUhAA0eR8FrsBXGgpmjKJA4K97EO5Ue0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J+Q/oX/7WD3qoRlXOh1E5784umDwhoDxlAYDD9T8NI4RpbkObJomzxGwj8Itu9pjO bobzSYUEKUBCOAdXf3c4ZDkKpUJCEujr/9jtES06b1qRo4P3FtC9C9RwPfImJrAO7a GAPvS5QFT9TLPSQJvok3CE4MmkQS0ktlzQI0BSec= From: Jakub Kicinski To: mkubecek@suse.cz Cc: netdev@vger.kernel.org, Jakub Kicinski Subject: [PATCH ethtool-next 1/5] update UAPI header copies Date: Tue, 15 Sep 2020 16:52:55 -0700 Message-Id: <20200915235259.457050-2-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200915235259.457050-1-kuba@kernel.org> References: <20200915235259.457050-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Update to kernel commit 945c5704887e. Signed-off-by: Jakub Kicinski --- uapi/linux/ethtool_netlink.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h index cebdb52e6a05..8d3926c56769 100644 --- a/uapi/linux/ethtool_netlink.h +++ b/uapi/linux/ethtool_netlink.h @@ -91,9 +91,12 @@ enum { #define ETHTOOL_FLAG_COMPACT_BITSETS (1 << 0) /* provide optional reply for SET or ACT requests */ #define ETHTOOL_FLAG_OMIT_REPLY (1 << 1) +/* request statistics, if supported by the driver */ +#define ETHTOOL_FLAG_STATS (1 << 2) #define ETHTOOL_FLAG_ALL (ETHTOOL_FLAG_COMPACT_BITSETS | \ - ETHTOOL_FLAG_OMIT_REPLY) + ETHTOOL_FLAG_OMIT_REPLY | \ + ETHTOOL_FLAG_STATS) enum { ETHTOOL_A_HEADER_UNSPEC, @@ -376,12 +379,25 @@ enum { ETHTOOL_A_PAUSE_AUTONEG, /* u8 */ ETHTOOL_A_PAUSE_RX, /* u8 */ ETHTOOL_A_PAUSE_TX, /* u8 */ + ETHTOOL_A_PAUSE_STATS, /* nest - _PAUSE_STAT_* */ /* add new constants above here */ __ETHTOOL_A_PAUSE_CNT, ETHTOOL_A_PAUSE_MAX = (__ETHTOOL_A_PAUSE_CNT - 1) }; +enum { + ETHTOOL_A_PAUSE_STAT_UNSPEC, + ETHTOOL_A_PAUSE_STAT_PAD, + + ETHTOOL_A_PAUSE_STAT_TX_FRAMES, + ETHTOOL_A_PAUSE_STAT_RX_FRAMES, + + /* add new constants above here */ + __ETHTOOL_A_PAUSE_STAT_CNT, + ETHTOOL_A_PAUSE_STAT_MAX = (__ETHTOOL_A_PAUSE_STAT_CNT - 1) +}; + /* EEE */ enum { From patchwork Tue Sep 15 23:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 260822 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 1EDB2C43461 for ; Tue, 15 Sep 2020 23:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB53B20739 for ; Tue, 15 Sep 2020 23:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600214018; bh=XhGWjT6nRhPQqolWFAg+Saen05pdEeNWpwZQvjsqhgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=QSt+GocKlt4zUs7K4EJg4pcHrFtZXkbNvyNmDMXbqO5IiNvXPtVWursSsQapJVL3p yXLugOpZ+mlEmTM58x3BGPlKlpG2fGKMRgr/0b+yse60+yKhMTB7Y3xQkxFRXQAW3V djV0CrEts7Pq9lBgO/7+1uKlMI/0IjoKQX6KCx6s= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727146AbgIOXxZ (ORCPT ); Tue, 15 Sep 2020 19:53:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:49624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727144AbgIOXxC (ORCPT ); Tue, 15 Sep 2020 19:53:02 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 366BC21D24; Tue, 15 Sep 2020 23:53:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600213981; bh=XhGWjT6nRhPQqolWFAg+Saen05pdEeNWpwZQvjsqhgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=06yjZuSyHG49OAjB3AmVu9ZcBSReo+/43MiZtvStADC3Xh/3/vz7Oyxc8GuJR3pxO Ian/BVXe8OXE8Dn5aQUZP1zZLHBQoOrv8bXlxI6D7BnXyyp2Xw8qODdVwjflccR036 ULdEJifelvNtNY0fzHooLvR/Xg1BmY+8Mp+Y/lCM= From: Jakub Kicinski To: mkubecek@suse.cz Cc: netdev@vger.kernel.org, Jakub Kicinski Subject: [PATCH ethtool-next 2/5] pause: add --json support Date: Tue, 15 Sep 2020 16:52:56 -0700 Message-Id: <20200915235259.457050-3-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200915235259.457050-1-kuba@kernel.org> References: <20200915235259.457050-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org No change in normal text output: # ./ethtool -a eth0 Pause parameters for eth0: Autonegotiate: on RX: on TX: on RX negotiated: on TX negotiated: on JSON: # ./ethtool --json -a eth0 [ { "ifname": "eth0", "autonegotiate": true, "rx": true, "tx": true, "negotiated": { "rx": true, "tx": true } } ] Signed-off-by: Jakub Kicinski Reviewed-by: Jacob Keller --- netlink/netlink.h | 12 ++++++++++-- netlink/pause.c | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/netlink/netlink.h b/netlink/netlink.h index dd4a02bcc916..4916d25ed5c0 100644 --- a/netlink/netlink.h +++ b/netlink/netlink.h @@ -106,9 +106,17 @@ static inline const char *u8_to_bool(const struct nlattr *attr) return "n/a"; } -static inline void show_bool(const struct nlattr *attr, const char *label) +static inline void show_bool(const char *key, const char *fmt, + const struct nlattr *attr) { - printf("%s%s\n", label, u8_to_bool(attr)); + if (is_json_context()) { + if (attr) { + print_bool(PRINT_JSON, key, NULL, + mnl_attr_get_u8(attr)); + } + } else { + print_string(PRINT_FP, NULL, fmt, u8_to_bool(attr)); + } } /* misc */ diff --git a/netlink/pause.c b/netlink/pause.c index 7b6b3a1d2c10..30ecdccb15eb 100644 --- a/netlink/pause.c +++ b/netlink/pause.c @@ -72,8 +72,16 @@ static int pause_autoneg_cb(const struct nlmsghdr *nlhdr, void *data) else if (peer.pause) tx_status = true; } - printf("RX negotiated: %s\nTX negotiated: %s\n", - rx_status ? "on" : "off", tx_status ? "on" : "off"); + + if (is_json_context()) { + open_json_object("negotiated"); + print_bool(PRINT_JSON, "rx", NULL, rx_status); + print_bool(PRINT_JSON, "tx", NULL, tx_status); + close_json_object(); + } else { + printf("RX negotiated: %s\nTX negotiated: %s\n", + rx_status ? "on" : "off", tx_status ? "on" : "off"); + } return MNL_CB_OK; } @@ -121,21 +129,34 @@ int pause_reply_cb(const struct nlmsghdr *nlhdr, void *data) return err_ret; if (silent) - putchar('\n'); - printf("Pause parameters for %s:\n", nlctx->devname); - show_bool(tb[ETHTOOL_A_PAUSE_AUTONEG], "Autonegotiate:\t"); - show_bool(tb[ETHTOOL_A_PAUSE_RX], "RX:\t\t"); - show_bool(tb[ETHTOOL_A_PAUSE_TX], "TX:\t\t"); + print_nl(); + + open_json_object(NULL); + + print_string(PRINT_ANY, "ifname", "Pause parameters for %s:\n", + nlctx->devname); + + show_bool("autonegotiate", "Autonegotiate:\t%s\n", + tb[ETHTOOL_A_PAUSE_AUTONEG]); + show_bool("rx", "RX:\t\t%s\n", tb[ETHTOOL_A_PAUSE_RX]); + show_bool("tx", "TX:\t\t%s\n", tb[ETHTOOL_A_PAUSE_TX]); + if (!nlctx->is_monitor && tb[ETHTOOL_A_PAUSE_AUTONEG] && mnl_attr_get_u8(tb[ETHTOOL_A_PAUSE_AUTONEG])) { ret = show_pause_autoneg_status(nlctx); if (ret < 0) - return err_ret; + goto err_close_dev; } if (!silent) - putchar('\n'); + print_nl(); + + close_json_object(); return MNL_CB_OK; + +err_close_dev: + close_json_object(); + return err_ret; } int nl_gpause(struct cmd_context *ctx) @@ -156,7 +177,11 @@ int nl_gpause(struct cmd_context *ctx) ETHTOOL_A_PAUSE_HEADER, 0); if (ret < 0) return ret; - return nlsock_send_get_request(nlsk, pause_reply_cb); + + new_json_obj(ctx->json); + ret = nlsock_send_get_request(nlsk, pause_reply_cb); + delete_json_obj(); + return ret; } /* PAUSE_SET */ From patchwork Tue Sep 15 23:52:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 260823 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,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 2638BC43461 for ; Tue, 15 Sep 2020 23:53:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E278C20720 for ; Tue, 15 Sep 2020 23:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600214000; bh=yLS1vq20W6tTyAkcxNKspYRmP2DcQhY1lsr6EZbvcKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Tv1uQ49utDTUNdz7qU3Zskk9GQpZ3QJhA7IMQlAIalMC8Krf5bXYCgtC4RkpaE3Cm bl96FqEHucBKPMjyElWKAjI3vrymGvHIldU+IdVO4x+4EkxuzXr+zZ/VJLR4We0LQR fwrVlTnY60WQ5FH3mpskVWpJJi0JJErY07qYsKGI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbgIOXxO (ORCPT ); Tue, 15 Sep 2020 19:53:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:49662 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727154AbgIOXxE (ORCPT ); Tue, 15 Sep 2020 19:53:04 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 15FFB221E3; Tue, 15 Sep 2020 23:53:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600213982; bh=yLS1vq20W6tTyAkcxNKspYRmP2DcQhY1lsr6EZbvcKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0+qlgY53MhuKmu5X3NmnsrslOJ785fzVLnTd2zR7daRnXi6W9T0lamsN66zTfqe8 p9laMseVPAhoxmZTQrQtKAzbmnu/hcm/m8/woIwjtYEgfEobC0ktaQZEtvWUZBg9Sg 6x4B+eTk3WiIJDoLHgnmoG7Kyu9q9HIJAwi/bd3c= From: Jakub Kicinski To: mkubecek@suse.cz Cc: netdev@vger.kernel.org, Jakub Kicinski Subject: [PATCH ethtool-next 5/5] pause: add support for dumping statistics Date: Tue, 15 Sep 2020 16:52:59 -0700 Message-Id: <20200915235259.457050-6-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200915235259.457050-1-kuba@kernel.org> References: <20200915235259.457050-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add support for requesting pause frame stats from the kernel. # ./ethtool -I -a eth0 Pause parameters for eth0: Autonegotiate: on RX: on TX: on Statistics: tx_pause_frames: 1 rx_pause_frames: 1 # ./ethtool -I --json -a eth0 [ { "ifname": "eth0", "autonegotiate": true, "rx": true, "tx": true, "statistics": { "tx_pause_frames": 1, "rx_pause_frames": 1 } } ] Signed-off-by: Jakub Kicinski --- netlink/pause.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/netlink/pause.c b/netlink/pause.c index 30ecdccb15eb..f9dec9fe887a 100644 --- a/netlink/pause.c +++ b/netlink/pause.c @@ -5,6 +5,7 @@ */ #include +#include #include #include @@ -110,6 +111,62 @@ static int show_pause_autoneg_status(struct nl_context *nlctx) return ret; } +static int show_pause_stats(const struct nlattr *nest) +{ + const struct nlattr *tb[ETHTOOL_A_PAUSE_STAT_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + static const struct { + unsigned int attr; + char *name; + } stats[] = { + { ETHTOOL_A_PAUSE_STAT_TX_FRAMES, "tx_pause_frames" }, + { ETHTOOL_A_PAUSE_STAT_RX_FRAMES, "rx_pause_frames" }, + }; + bool header = false; + unsigned int i; + size_t n; + int ret; + + ret = mnl_attr_parse_nested(nest, attr_cb, &tb_info); + if (ret < 0) + return ret; + + open_json_object("statistics"); + for (i = 0; i < ARRAY_SIZE(stats); i++) { + char fmt[32]; + + if (!tb[stats[i].attr]) + continue; + + if (!header && !is_json_context()) { + printf("Statistics:\n"); + header = true; + } + + if (mnl_attr_validate(tb[stats[i].attr], MNL_TYPE_U64)) { + fprintf(stderr, "malformed netlink message (statistic)\n"); + goto err_close_stats; + } + + n = snprintf(fmt, sizeof(fmt), " %s: %%" PRId64 "\n", + stats[i].name); + if (n >= sizeof(fmt)) { + fprintf(stderr, "internal error - malformed label\n"); + goto err_close_stats; + } + + print_u64(PRINT_ANY, stats[i].name, fmt, + mnl_attr_get_u64(tb[stats[i].attr])); + } + close_json_object(); + + return 0; + +err_close_stats: + close_json_object(); + return -1; +} + int pause_reply_cb(const struct nlmsghdr *nlhdr, void *data) { const struct nlattr *tb[ETHTOOL_A_PAUSE_MAX + 1] = {}; @@ -147,6 +204,11 @@ int pause_reply_cb(const struct nlmsghdr *nlhdr, void *data) if (ret < 0) goto err_close_dev; } + if (tb[ETHTOOL_A_PAUSE_STATS]) { + ret = show_pause_stats(tb[ETHTOOL_A_PAUSE_STATS]); + if (ret < 0) + goto err_close_dev; + } if (!silent) print_nl(); @@ -163,6 +225,7 @@ int nl_gpause(struct cmd_context *ctx) { struct nl_context *nlctx = ctx->nlctx; struct nl_socket *nlsk = nlctx->ethnl_socket; + u32 flags; int ret; if (netlink_cmd_check(ctx, ETHTOOL_MSG_PAUSE_GET, true)) @@ -173,8 +236,9 @@ int nl_gpause(struct cmd_context *ctx) return 1; } + flags = nlctx->ctx->show_stats ? ETHTOOL_FLAG_STATS : 0; ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_PAUSE_GET, - ETHTOOL_A_PAUSE_HEADER, 0); + ETHTOOL_A_PAUSE_HEADER, flags); if (ret < 0) return ret;