Messages in this thread Patch in this message | | | From | Michal Kubecek <> | Subject | [RFC PATCH ethtool v2 12/23] netlink: add netlink handler for gcoalesce (-c) | Date | Mon, 30 Jul 2018 14:56:44 +0200 (CEST) |
| |
Implement "ethtool -c <dev>" subcommand using netlink interface command ETHNL_CMD_GET_PARAMS with ETH_PARAMS_IM_COALESCE mask.
Signed-off-by: Michal Kubecek <mkubecek@suse.cz> --- Makefile.am | 2 +- ethtool.c | 3 +- netlink/extapi.h | 1 + netlink/monitor.c | 10 +++++ netlink/params.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 netlink/params.c
diff --git a/Makefile.am b/Makefile.am index 7cc4adc53c59..bedf9edaac47 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,7 +24,7 @@ ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ netlink/strset.c netlink/strset.h netlink/monitor.c \ netlink/parser.c netlink/parser.h \ - netlink/drvinfo.c netlink/settings.c \ + netlink/drvinfo.c netlink/settings.c netlink/params.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h ethtool_CFLAGS += @MNL_CFLAGS@ diff --git a/ethtool.c b/ethtool.c index b2f93a331098..24c70c372914 100644 --- a/ethtool.c +++ b/ethtool.c @@ -4879,6 +4879,7 @@ static int show_usage(struct cmd_context *ctx); #define nl_sset NULL #define nl_gfeatures NULL #define nl_sfeatures NULL +#define nl_gcoalesce NULL #endif static const struct option { @@ -4909,7 +4910,7 @@ static const struct option { " [ autoneg on|off ]\n" " [ rx on|off ]\n" " [ tx on|off ]\n" }, - { "-c|--show-coalesce", 1, do_gcoalesce, NULL, + { "-c|--show-coalesce", 1, do_gcoalesce, nl_gcoalesce, "Show coalesce options" }, { "-C|--coalesce", 1, do_scoalesce, NULL, "Set coalesce options", diff --git a/netlink/extapi.h b/netlink/extapi.h index ad67e81449ba..8030bda4cbc9 100644 --- a/netlink/extapi.h +++ b/netlink/extapi.h @@ -18,6 +18,7 @@ int nl_gset(struct cmd_context *ctx); int nl_sset(struct cmd_context *ctx); int nl_gfeatures(struct cmd_context *ctx); int nl_sfeatures(struct cmd_context *ctx); +int nl_gcoalesce(struct cmd_context *ctx); int nl_monitor(struct cmd_context *ctx); void monitor_usage(); diff --git a/netlink/monitor.c b/netlink/monitor.c index e3b8bb46f561..5d494ba43923 100644 --- a/netlink/monitor.c +++ b/netlink/monitor.c @@ -68,6 +68,7 @@ static int monitor_event_cb(const struct nlmsghdr *nlhdr, void *data) int drvinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data); int settings_reply_cb(const struct nlmsghdr *nlhdr, void *data); +int params_reply_cb(const struct nlmsghdr *nlhdr, void *data); static struct { uint8_t cmd; @@ -85,6 +86,10 @@ static struct { .cmd = ETHNL_CMD_SET_SETTINGS, .cb = settings_reply_cb, }, + { + .cmd = ETHNL_CMD_SET_PARAMS, + .cb = params_reply_cb, + }, }; static int monitor_any_cb(const struct nlmsghdr *nlhdr, void *data) @@ -133,6 +138,11 @@ static struct monitor_option monitor_opts[] = { .cmd = ETHNL_CMD_SET_SETTINGS, .info_mask = ETH_SETTINGS_IM_FEATURES, }, + { + .pattern = "-c|--show-coalesce|-C|--coalesce", + .cmd = ETHNL_CMD_SET_PARAMS, + .info_mask = ETH_PARAMS_IM_COALESCE, + }, }; static bool pattern_match(const char *s, const char *pattern) diff --git a/netlink/params.c b/netlink/params.c new file mode 100644 index 000000000000..30aee5758c42 --- /dev/null +++ b/netlink/params.c @@ -0,0 +1,101 @@ +#include <errno.h> +#include <string.h> +#include <stdio.h> + +#include "../internal.h" +#include "../common.h" +#include "netlink.h" +#include "strset.h" +#include "parser.h" + +/* GET_PARAMS */ + +static int show_coalesce(struct nl_context *nlctx, const struct nlattr *nest) +{ + const struct nlattr *tb[ETHA_COALESCE_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + int ret; + + if (!nest) + return -EOPNOTSUPP; + ret = mnl_attr_parse_nested(nest, attr_cb, &tb_info); + if (ret < 0) + return ret; + + printf("Coalesce parameters for %s:\n", nlctx->devname); + printf("Adaptive RX: %s TX: %s\n", + u8_to_bool(tb[ETHA_COALESCE_RX_USE_ADAPTIVE]), + u8_to_bool(tb[ETHA_COALESCE_TX_USE_ADAPTIVE])); + show_u32(tb[ETHA_COALESCE_STATS_BLOCK_USECS], "stats-block-usecs: "); + show_u32(tb[ETHA_COALESCE_RATE_SAMPLE_INTERVAL], "sample-interval: "); + show_u32(tb[ETHA_COALESCE_PKT_RATE_LOW], "pkt-rate-low: "); + show_u32(tb[ETHA_COALESCE_PKT_RATE_HIGH], "pkt-rate-high: "); + putchar('\n'); + show_u32(tb[ETHA_COALESCE_RX_USECS], "rx-usecs: "); + show_u32(tb[ETHA_COALESCE_RX_MAXFRM], "rx-frames: "); + show_u32(tb[ETHA_COALESCE_RX_USECS_IRQ], "rx-usecs-irq: "); + show_u32(tb[ETHA_COALESCE_RX_MAXFRM_IRQ], "rx-frames-irq: "); + putchar('\n'); + show_u32(tb[ETHA_COALESCE_TX_USECS], "tx-usecs: "); + show_u32(tb[ETHA_COALESCE_TX_MAXFRM], "tx-frames: "); + show_u32(tb[ETHA_COALESCE_TX_USECS_IRQ], "tx-usecs-irq: "); + show_u32(tb[ETHA_COALESCE_TX_MAXFRM_IRQ], "tx-frames-irq: "); + putchar('\n'); + show_u32(tb[ETHA_COALESCE_RX_USECS_LOW], "rx-usecs-low: "); + show_u32(tb[ETHA_COALESCE_RX_MAXFRM_LOW], "rx-frame-low: "); + show_u32(tb[ETHA_COALESCE_TX_USECS_LOW], "tx-usecs-low: "); + show_u32(tb[ETHA_COALESCE_TX_MAXFRM_LOW], "tx-frame-low: "); + putchar('\n'); + show_u32(tb[ETHA_COALESCE_RX_USECS_HIGH], "rx-usecs-high: "); + show_u32(tb[ETHA_COALESCE_RX_MAXFRM_HIGH], "rx-frame-high: "); + show_u32(tb[ETHA_COALESCE_TX_USECS_HIGH], "tx-usecs-high: "); + show_u32(tb[ETHA_COALESCE_TX_MAXFRM_HIGH], "tx-frame-high: "); + putchar('\n'); + + return 0; +} + +int params_reply_cb(const struct nlmsghdr *nlhdr, void *data) +{ + const struct nlattr *tb[ETHA_PARAMS_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + struct nl_context *nlctx = data; + int ret; + + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return ret; + nlctx->devname = get_dev_name(tb[ETHA_PARAMS_DEV]); + if (!dev_ok(nlctx)) + return MNL_CB_OK; + + if (mask_ok(nlctx, ETH_PARAMS_IM_COALESCE)) { + ret = show_coalesce(nlctx, tb[ETHA_PARAMS_COALESCE]); + if ((ret < 0) && show_only(nlctx, ETH_PARAMS_IM_COALESCE)) { + nlctx->exit_code = 82; + errno = -ret; + perror("Cannot get device coalesce settings"); + return MNL_CB_ERROR; + } + } + + return MNL_CB_OK; +} + +static int params_request(struct cmd_context *ctx, uint32_t info_mask) +{ + int ret; + + ret = ethnl_prep_get_request(ctx, ETHNL_CMD_GET_PARAMS, + ETHA_PARAMS_DEV); + if (ret < 0) + return ret; + if (ethnla_put_u32(ctx->nlctx, ETHA_PARAMS_INFOMASK, info_mask)) + return -EMSGSIZE; + return ethnl_send_get_request(ctx->nlctx, params_reply_cb); +} + +int nl_gcoalesce(struct cmd_context *ctx) +{ + return params_request(ctx, ETH_PARAMS_IM_COALESCE); +} -- 2.18.0
| |