From patchwork Wed Dec 14 23:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mogilappagari, Sudheer" X-Patchwork-Id: 13073811 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 B105DC4332F for ; Thu, 15 Dec 2022 00:05:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbiLOAFa (ORCPT ); Wed, 14 Dec 2022 19:05:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229876AbiLOAFE (ORCPT ); Wed, 14 Dec 2022 19:05:04 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D15A59158 for ; Wed, 14 Dec 2022 15:58:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671062285; x=1702598285; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OUm3It5eiUx+fCL6aKNRKthVKH9aGmPJxRhFZgF06UU=; b=RkWLwDX6jMxtrb2Nt6mx/CGQ68T/LMJGxKz1czoz7MBvQk/hHut3Gml8 vnYdAa7cglDTJxLWvqOGwNOFqwNiAQgd3dlu8dqGO+7bdW07L2s1tdFDE dmAGUUpE1j/8icRTDmKevmb7NhARGu9dIX8xhwNwb7uetAuT60yRvR359 ZvLw3ZsE94fz3au7dMAPsNAu0ZE9bC8kLk3z4Qb+2HhWbA+L8CjGpSFlj J+wG6TmOFy1PHUMV4DCHBVl57FJ3HS9LRsdXvCebeCkeb8aNnhEcQGmjH yEuO1otlyRYL7tMxkcx2w1idfVBYpGPH456Ba0BOMbBvVY83OcnmAQJfY w==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="301951802" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="301951802" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 15:57:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="773503924" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="773503924" Received: from msu-dell.jf.intel.com ([10.166.233.5]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2022 15:57:25 -0800 From: Sudheer Mogilappagari To: netdev@vger.kernel.org Cc: mkubecek@suse.cz, kuba@kernel.org, sridhar.samudrala@intel.com, anthony.l.nguyen@intel.com Subject: [PATCH ethtool-next v1 1/3] update UAPI header copies for RSS_GET support Date: Wed, 14 Dec 2022 15:54:16 -0800 Message-Id: <20221214235418.1033834-2-sudheer.mogilappagari@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> References: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Update to kernel 'commit 7112a04664bf ("ethtool:add netlink based get rss support")' Signed-off-by: Sudheer Mogilappagari --- uapi/linux/ethtool_netlink.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h index d581c43..0d553ec 100644 --- a/uapi/linux/ethtool_netlink.h +++ b/uapi/linux/ethtool_netlink.h @@ -51,6 +51,7 @@ enum { ETHTOOL_MSG_MODULE_SET, ETHTOOL_MSG_PSE_GET, ETHTOOL_MSG_PSE_SET, + ETHTOOL_MSG_RSS_GET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -97,6 +98,7 @@ enum { ETHTOOL_MSG_MODULE_GET_REPLY, ETHTOOL_MSG_MODULE_NTF, ETHTOOL_MSG_PSE_GET_REPLY, + ETHTOOL_MSG_RSS_GET_REPLY, /* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT, @@ -880,6 +882,18 @@ enum { ETHTOOL_A_PSE_MAX = (__ETHTOOL_A_PSE_CNT - 1) }; +enum { + ETHTOOL_A_RSS_UNSPEC, + ETHTOOL_A_RSS_HEADER, + ETHTOOL_A_RSS_CONTEXT, /* u32 */ + ETHTOOL_A_RSS_HFUNC, /* u32 */ + ETHTOOL_A_RSS_INDIR, /* binary */ + ETHTOOL_A_RSS_HKEY, /* binary */ + + __ETHTOOL_A_RSS_CNT, + ETHTOOL_A_RSS_MAX = (__ETHTOOL_A_RSS_CNT - 1), +}; + /* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool" #define ETHTOOL_GENL_VERSION 1 From patchwork Wed Dec 14 23:54:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mogilappagari, Sudheer" X-Patchwork-Id: 13073814 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 C086AC4332F for ; Thu, 15 Dec 2022 00:06:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229527AbiLOAGa (ORCPT ); Wed, 14 Dec 2022 19:06:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbiLOAFp (ORCPT ); Wed, 14 Dec 2022 19:05:45 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56E0756D73 for ; Wed, 14 Dec 2022 15:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671062310; x=1702598310; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nXQAflAxrY/Ib1yP4tv5u4ncYn2ew+J63x7ANDQR2Ag=; b=mOwp8BIhAel25OWPaIxh/o96GizJmZMUezKcooShpD1wPi0y/HgfkxC3 Jzrd59oWFn5tHYslAIm5nimaba4+7WR6PEyotWdjrcC/PALOmxQGKXiu7 lgLxtnM62v5a0rE/4yXXhTpblQ4NFPLTirPYlT6ai9pSeaB77hVxHYXfG L31uGW4onLvlJSRgmOdzmlfGcNDBcfOUqaoxF+K5q6Tp4hZ+G0g8BH3HR w2tZ2COSUk1NvENr5nJHQetnP5yueU42QezXiy6IxA/iODk/AKIrMkwxA QHuFfTqlLHyoOtC7bYqkXU7lUHXky8FH79VSjpmdLQZ+E8KxVUITr6S2X Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="301951806" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="301951806" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 15:57:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="773503927" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="773503927" Received: from msu-dell.jf.intel.com ([10.166.233.5]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2022 15:57:25 -0800 From: Sudheer Mogilappagari To: netdev@vger.kernel.org Cc: mkubecek@suse.cz, kuba@kernel.org, sridhar.samudrala@intel.com, anthony.l.nguyen@intel.com Subject: [PATCH ethtool-next v1 2/3] Move code that print rss info into common file Date: Wed, 14 Dec 2022 15:54:17 -0800 Message-Id: <20221214235418.1033834-3-sudheer.mogilappagari@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> References: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Move functions that print rss indirection table and hash key into common file for use by both netlink and ioctl interface. Changed function argument to be ring count instead of structure. Signed-off-by: Sudheer Mogilappagari --- common.c | 43 +++++++++++++++++++++++++++++++++++++++++++ common.h | 7 +++++++ ethtool.c | 44 ++++---------------------------------------- 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/common.c b/common.c index 2630e73..0f2d8c0 100644 --- a/common.c +++ b/common.c @@ -173,3 +173,46 @@ void dump_mdix(u8 mdix, u8 mdix_ctrl) fprintf(stdout, "\n"); } } + +void print_indir_table(struct cmd_context *ctx, u64 ring_count, + u32 indir_size, u32 *indir) +{ + u32 i; + + printf("RX flow hash indirection table for %s with %llu RX ring(s):\n", + ctx->devname, ring_count); + + if (!indir_size) + printf("Operation not supported\n"); + + for (i = 0; i < indir_size; i++) { + if (i % 8 == 0) + printf("%5u: ", i); + printf(" %5u", indir[i]); + if (i % 8 == 7 || i == indir_size - 1) + fputc('\n', stdout); + } +} + +void print_rss_info(struct cmd_context *ctx, u64 ring_count, + struct ethtool_rxfh *rss) +{ + u32 i, indir_bytes; + char *hkey; + + print_indir_table(ctx, ring_count, rss->indir_size, rss->rss_config); + + indir_bytes = rss->indir_size * sizeof(rss->rss_config[0]); + hkey = ((char *)rss->rss_config + indir_bytes); + + printf("RSS hash key:\n"); + if (!rss->key_size) + printf("Operation not supported\n"); + + for (i = 0; i < rss->key_size; i++) { + if (i == (rss->key_size - 1)) + printf("%02x\n", (u8)hkey[i]); + else + printf("%02x:", (u8)hkey[i]); + } +} diff --git a/common.h b/common.h index b74fdfa..8589714 100644 --- a/common.h +++ b/common.h @@ -8,6 +8,8 @@ #define ETHTOOL_COMMON_H__ #include "internal.h" +#include +#include #define KERNEL_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) @@ -41,5 +43,10 @@ extern const struct off_flag_def off_flag_def[OFF_FLAG_DEF_SIZE]; void print_flags(const struct flag_info *info, unsigned int n_info, u32 value); int dump_wol(struct ethtool_wolinfo *wol); void dump_mdix(u8 mdix, u8 mdix_ctrl); +void print_indir_table(struct cmd_context *ctx, u64 ring_count, + u32 indir_size, u32 *indir); + +void print_rss_info(struct cmd_context *ctx, u64 ring_count, + struct ethtool_rxfh *rss); #endif /* ETHTOOL_COMMON_H__ */ diff --git a/ethtool.c b/ethtool.c index 3207e49..0971074 100644 --- a/ethtool.c +++ b/ethtool.c @@ -3880,27 +3880,6 @@ static int do_grxclass(struct cmd_context *ctx) return err ? 1 : 0; } -static void print_indir_table(struct cmd_context *ctx, - struct ethtool_rxnfc *ring_count, - u32 indir_size, u32 *indir) -{ - u32 i; - - printf("RX flow hash indirection table for %s with %llu RX ring(s):\n", - ctx->devname, ring_count->data); - - if (!indir_size) - printf("Operation not supported\n"); - - for (i = 0; i < indir_size; i++) { - if (i % 8 == 0) - printf("%5u: ", i); - printf(" %5u", indir[i]); - if (i % 8 == 7 || i == indir_size - 1) - fputc('\n', stdout); - } -} - static int do_grxfhindir(struct cmd_context *ctx, struct ethtool_rxnfc *ring_count) { @@ -3932,7 +3911,8 @@ static int do_grxfhindir(struct cmd_context *ctx, return 1; } - print_indir_table(ctx, ring_count, indir->size, indir->ring_index); + print_indir_table(ctx, ring_count->data, indir->size, + indir->ring_index); free(indir); return 0; @@ -3945,9 +3925,7 @@ static int do_grxfh(struct cmd_context *ctx) struct ethtool_rxnfc ring_count; struct ethtool_rxfh *rss; u32 rss_context = 0; - u32 i, indir_bytes; - unsigned int arg_num = 0; - char *hkey; + unsigned int arg_num = 0, i; int err; while (arg_num < ctx->argc) { @@ -3997,21 +3975,7 @@ static int do_grxfh(struct cmd_context *ctx) return 1; } - print_indir_table(ctx, &ring_count, rss->indir_size, rss->rss_config); - - indir_bytes = rss->indir_size * sizeof(rss->rss_config[0]); - hkey = ((char *)rss->rss_config + indir_bytes); - - printf("RSS hash key:\n"); - if (!rss->key_size) - printf("Operation not supported\n"); - - for (i = 0; i < rss->key_size; i++) { - if (i == (rss->key_size - 1)) - printf("%02x\n", (u8) hkey[i]); - else - printf("%02x:", (u8) hkey[i]); - } + print_rss_info(ctx, ring_count.data, rss); printf("RSS hash function:\n"); if (!rss->hfunc) { From patchwork Wed Dec 14 23:54:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mogilappagari, Sudheer" X-Patchwork-Id: 13073813 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 CAFA1C4332F for ; Thu, 15 Dec 2022 00:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbiLOAGK (ORCPT ); Wed, 14 Dec 2022 19:06:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiLOAFb (ORCPT ); Wed, 14 Dec 2022 19:05:31 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B19F36B991 for ; Wed, 14 Dec 2022 15:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1671062297; x=1702598297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NqUcjvoPCz7Brbj36DpxXqGQWysHjoz5KI1pG/OJr3g=; b=dtoziMyh6nt0yPEAypcBqC2oExCcNu8aF9mRB8jE/XjPnUugQe/hP9fx /MHXEESJeQmTlHBa6dTewOIE9IZoki0mYkl8+h3qC3FME1bhuje8pYphh 4AVItf6/f651GFl2bAuQ+kmxymUmd30lPi7QTbYOm7alZpVlOuNVjTNmF raUxjhXWx1y9ctsngYm1xRA/0cIQ6HVEpFqRJeTYDxlVXKprNbCGZHpeL rEIqzDdaqqQnRl2FXxhSZSPurOhntWdzB+G75JCIS12o6J2cS/flSE7Ou yMQpLcwH2OWR5mOXjr3SLbbSf/Txb/Y4vhqwHkwKiz12Frj7tlvczCWUL Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="301951809" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="301951809" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2022 15:57:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10561"; a="773503930" X-IronPort-AV: E=Sophos;i="5.96,245,1665471600"; d="scan'208";a="773503930" Received: from msu-dell.jf.intel.com ([10.166.233.5]) by orsmga004.jf.intel.com with ESMTP; 14 Dec 2022 15:57:25 -0800 From: Sudheer Mogilappagari To: netdev@vger.kernel.org Cc: mkubecek@suse.cz, kuba@kernel.org, sridhar.samudrala@intel.com, anthony.l.nguyen@intel.com Subject: [PATCH ethtool-next v1 3/3] netlink: add netlink handler for get rss (-x) Date: Wed, 14 Dec 2022 15:54:18 -0800 Message-Id: <20221214235418.1033834-4-sudheer.mogilappagari@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> References: <20221214235418.1033834-1-sudheer.mogilappagari@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: mkubecek+ethtool@suse.cz Add support for netlink based "ethtool -x " command using ETHTOOL_MSG_RSS_GET netlink message. It implements same functionality provided by traditional ETHTOOL_GRSSH subcommand. This displays RSS table, hash key and hash function. Signed-off-by: Sudheer Mogilappagari --- Makefile.am | 2 +- ethtool.c | 1 + netlink/desc-ethtool.c | 11 +++ netlink/extapi.h | 2 + netlink/rss.c | 197 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 netlink/rss.c diff --git a/Makefile.am b/Makefile.am index fcc912e..4765c3f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,7 +39,7 @@ ethtool_SOURCES += \ netlink/eee.c netlink/tsinfo.c netlink/fec.c \ netlink/stats.c \ netlink/desc-ethtool.c netlink/desc-genlctrl.c \ - netlink/module-eeprom.c netlink/module.c \ + netlink/module-eeprom.c netlink/module.c netlink/rss.c \ netlink/desc-rtnl.c netlink/cable_test.c netlink/tunnels.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ diff --git a/ethtool.c b/ethtool.c index 0971074..af57807 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5830,6 +5830,7 @@ static const struct option args[] = { { .opts = "-x|--show-rxfh-indir|--show-rxfh", .func = do_grxfh, + .nlfunc = nl_grss, .help = "Show Rx flow hash indirection table and/or RSS hash key", .xhelp = " [ context %d ]\n" }, diff --git a/netlink/desc-ethtool.c b/netlink/desc-ethtool.c index 9a6651e..8783afc 100644 --- a/netlink/desc-ethtool.c +++ b/netlink/desc-ethtool.c @@ -409,6 +409,15 @@ static const struct pretty_nla_desc __module_desc[] = { NLATTR_DESC_U8(ETHTOOL_A_MODULE_POWER_MODE), }; +static const struct pretty_nla_desc __rss_desc[] = { + NLATTR_DESC_INVALID(ETHTOOL_A_MODULE_UNSPEC), + NLATTR_DESC_NESTED(ETHTOOL_A_MODULE_HEADER, header), + NLATTR_DESC_U32(ETHTOOL_A_RSS_CONTEXT), + NLATTR_DESC_U32(ETHTOOL_A_RSS_HFUNC), + NLATTR_DESC_BINARY(ETHTOOL_A_RSS_INDIR), + NLATTR_DESC_BINARY(ETHTOOL_A_RSS_HKEY), +}; + const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { NLMSG_DESC_INVALID(ETHTOOL_MSG_USER_NONE), NLMSG_DESC(ETHTOOL_MSG_STRSET_GET, strset), @@ -446,6 +455,7 @@ const struct pretty_nlmsg_desc ethnl_umsg_desc[] = { NLMSG_DESC(ETHTOOL_MSG_PHC_VCLOCKS_GET, phc_vclocks), NLMSG_DESC(ETHTOOL_MSG_MODULE_GET, module), NLMSG_DESC(ETHTOOL_MSG_MODULE_SET, module), + NLMSG_DESC(ETHTOOL_MSG_RSS_GET, rss), }; const unsigned int ethnl_umsg_n_desc = ARRAY_SIZE(ethnl_umsg_desc); @@ -488,6 +498,7 @@ const struct pretty_nlmsg_desc ethnl_kmsg_desc[] = { NLMSG_DESC(ETHTOOL_MSG_PHC_VCLOCKS_GET_REPLY, phc_vclocks), NLMSG_DESC(ETHTOOL_MSG_MODULE_GET_REPLY, module), NLMSG_DESC(ETHTOOL_MSG_MODULE_NTF, module), + NLMSG_DESC(ETHTOOL_MSG_RSS_GET_REPLY, rss), }; const unsigned int ethnl_kmsg_n_desc = ARRAY_SIZE(ethnl_kmsg_desc); diff --git a/netlink/extapi.h b/netlink/extapi.h index 1bb580a..9b6dd1a 100644 --- a/netlink/extapi.h +++ b/netlink/extapi.h @@ -47,6 +47,7 @@ int nl_gmodule(struct cmd_context *ctx); int nl_smodule(struct cmd_context *ctx); int nl_monitor(struct cmd_context *ctx); int nl_getmodule(struct cmd_context *ctx); +int nl_grss(struct cmd_context *ctx); void nl_monitor_usage(void); @@ -114,6 +115,7 @@ nl_get_eeprom_page(struct cmd_context *ctx __maybe_unused, #define nl_getmodule NULL #define nl_gmodule NULL #define nl_smodule NULL +#define nl_grss NULL #endif /* ETHTOOL_ENABLE_NETLINK */ diff --git a/netlink/rss.c b/netlink/rss.c new file mode 100644 index 0000000..256f688 --- /dev/null +++ b/netlink/rss.c @@ -0,0 +1,197 @@ +/* + * rss.c - netlink implementation of RSS context commands + * + * Implementation of "ethtool -x " + */ + +#include +#include +#include + +#include "../internal.h" +#include "../common.h" +#include "netlink.h" +#include "strset.h" +#include "parser.h" + +struct cb_args { + struct nl_context *nlctx; + u32 num_rings; +}; + +int rss_reply_cb(const struct nlmsghdr *nlhdr, void *data) +{ + const struct nlattr *tb[ETHTOOL_A_RSS_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + struct cb_args *args = data; + struct nl_context *nlctx = args->nlctx; + const struct stringset *hash_funcs; + u32 rss_config_size, rss_hfunc; + const char *rss_config, *hkey; + int indir_sz = 0, hkey_sz = 0; + struct ethtool_rxfh *rss; + bool silent; + int err_ret; + int ret; + + silent = nlctx->is_dump || nlctx->is_monitor; + err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR; + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return err_ret; + nlctx->devname = get_dev_name(tb[ETHTOOL_A_RSS_HEADER]); + if (!dev_ok(nlctx)) + return err_ret; + + if (silent) + putchar('\n'); + + rss_hfunc = mnl_attr_get_u32(tb[ETHTOOL_A_RSS_HFUNC]); + + indir_sz = mnl_attr_get_payload_len(tb[ETHTOOL_A_RSS_INDIR]); + rss_config = mnl_attr_get_str(tb[ETHTOOL_A_RSS_INDIR]); + + hkey_sz = mnl_attr_get_payload_len(tb[ETHTOOL_A_RSS_HKEY]); + hkey = mnl_attr_get_str(tb[ETHTOOL_A_RSS_HKEY]); + + rss_config_size = indir_sz + hkey_sz; + + rss = calloc(1, sizeof(*rss) + rss_config_size); + if (!rss) { + perror("Cannot allocate memory for RX flow hash config"); + return 1; + } + + rss->indir_size = indir_sz / sizeof(u32); + rss->key_size = hkey_sz; + + memcpy(rss->rss_config, rss_config, indir_sz); + memcpy(rss->rss_config + rss->indir_size, hkey, hkey_sz); + + print_rss_info(nlctx->ctx, args->num_rings, rss); + + /* Fetch RSS hash functions and their status and print */ + printf("RSS hash function:\n"); + if (!rss_hfunc) { + printf(" Operation not supported\n"); + return 0; + } + + if (!nlctx->is_monitor) { + ret = netlink_init_ethnl2_socket(nlctx); + if (ret < 0) + return MNL_CB_ERROR; + } + hash_funcs = global_stringset(ETH_SS_RSS_HASH_FUNCS, + nlctx->ethnl2_socket); + + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return silent ? MNL_CB_OK : MNL_CB_ERROR; + nlctx->devname = get_dev_name(tb[ETHTOOL_A_RSS_HEADER]); + if (!dev_ok(nlctx)) + return MNL_CB_OK; + + for (unsigned int i = 0; i < get_count(hash_funcs); i++) + printf(" %s: %s\n", get_string(hash_funcs, i), + (rss_hfunc & (1 << i)) ? "on" : "off"); + + free(rss); + return MNL_CB_OK; +} + +/* RSS_GET */ +static const struct param_parser grss_params[] = { + { + .arg = "context", + .type = ETHTOOL_A_RSS_CONTEXT, + .handler = nl_parse_direct_u32, + .min_argc = 1, + }, + {} +}; + +int get_channels_cb(const struct nlmsghdr *nlhdr, void *data) +{ + const struct nlattr *tb[ETHTOOL_A_CHANNELS_MAX + 1] = {}; + DECLARE_ATTR_TB_INFO(tb); + struct cb_args *args = data; + struct nl_context *nlctx = args->nlctx; + bool silent; + int err_ret; + int ret; + + silent = nlctx->is_dump || nlctx->is_monitor; + err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR; + ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info); + if (ret < 0) + return err_ret; + nlctx->devname = get_dev_name(tb[ETHTOOL_A_CHANNELS_HEADER]); + if (!dev_ok(nlctx)) + return err_ret; + + args->num_rings = mnl_attr_get_u8(tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT]); + return MNL_CB_OK; +} + +int nl_grss(struct cmd_context *ctx) +{ + struct nl_context *nlctx = ctx->nlctx; + struct nl_socket *nlsk = nlctx->ethnl_socket; + struct nl_msg_buff *msgbuff; + struct cb_args args; + int ret; + + nlctx->cmd = "-x"; + nlctx->argp = ctx->argp; + nlctx->argc = ctx->argc; + nlctx->devname = ctx->devname; + nlsk = nlctx->ethnl_socket; + msgbuff = &nlsk->msgbuff; + + if (netlink_cmd_check(ctx, ETHTOOL_MSG_RSS_GET, true)) + return -EOPNOTSUPP; + + /* save rings information into args.num_rings */ + if (netlink_cmd_check(ctx, ETHTOOL_MSG_CHANNELS_GET, true)) + return -EOPNOTSUPP; + + ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_CHANNELS_GET, + ETHTOOL_A_CHANNELS_HEADER, 0); + if (ret < 0) + goto err; + + ret = nlsock_sendmsg(nlsk, NULL); + if (ret < 0) + goto err; + + args.nlctx = nlsk->nlctx; + ret = nlsock_process_reply(nlsk, get_channels_cb, &args); + if (ret < 0) + goto err; + + ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_RSS_GET, + NLM_F_REQUEST | NLM_F_ACK); + if (ret < 0) + return 1; + if (ethnla_fill_header(msgbuff, ETHTOOL_A_RSS_HEADER, + ctx->devname, 0)) + return -EMSGSIZE; + + ret = nl_parser(nlctx, grss_params, NULL, PARSER_GROUP_NONE, NULL); + if (ret < 0) + goto err; + + ret = nlsock_sendmsg(nlsk, NULL); + if (ret < 0) + goto err; + + args.nlctx = nlctx; + ret = nlsock_process_reply(nlsk, rss_reply_cb, &args); + if (ret == 0) + return 0; + +err: + return nlctx->exit_code ?: 1; +} +