From patchwork Mon Aug 17 12:50:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 262416 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 26483C433DF for ; Mon, 17 Aug 2020 12:52:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9F9A2078D for ; Mon, 17 Aug 2020 12:52:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Hu/TDNFO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728505AbgHQMwl (ORCPT ); Mon, 17 Aug 2020 08:52:41 -0400 Received: from wnew3-smtp.messagingengine.com ([64.147.123.17]:55175 "EHLO wnew3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728452AbgHQMwa (ORCPT ); Mon, 17 Aug 2020 08:52:30 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id C89B391A; Mon, 17 Aug 2020 08:52:28 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 17 Aug 2020 08:52:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=RZNNt95zD5BPj7e1BZG4LoynU6kgWATDWqYasbxe7es=; b=Hu/TDNFO s1bhBCLIol4zj8RhHk1V78AJnumcUzsrYdrbvCf1cF/MlRc36+O7d5uSUKeKzfGp tYm++DqWtbu6UM8AFQwti34OKgukfu9qUxKCVLmo6orJ7Yfwi43OnI6TlksfbixR LxU2Meao2qj0rzw1DvRdW2y4TvxyhNnyaQJ+3ervbdKC+R9UoClszyRKlpERYsTq P071ermpA3EaiixJmxzezIrf+27xNk49TtBiWklWTJVD0zeflY/WLFaTpM6HVqkt /bd1IXLf3g3H3UTusrPRvZkk9BRZwEfqTS81RFxjkoMYgyJwRUdOsmp2i6ezxm7G 0hiVt14jIRrV8Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtfedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecuggftrfgrthhtvghrnhepudetieevffffveelkeeljeffkefhke ehgfdtffethfelvdejgffghefgveejkefhnecukfhppeejledrudekvddrieefrdegvden ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehiughosh gthhesihguohhstghhrdhorhhg X-ME-Proxy: Received: from localhost.localdomain (bzq-79-182-63-42.red.bezeqint.net [79.182.63.42]) by mail.messagingengine.com (Postfix) with ESMTPA id 64F9D306005F; Mon, 17 Aug 2020 08:52:16 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com, amcohen@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com, roopa@nvidia.com, dsahern@gmail.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, saeedm@nvidia.com, tariqt@nvidia.com, ayal@nvidia.com, eranbe@nvidia.com, mkubecek@suse.cz, Ido Schimmel Subject: [RFC PATCH net-next 2/6] netdevsim: Add devlink metric support Date: Mon, 17 Aug 2020 15:50:55 +0300 Message-Id: <20200817125059.193242-3-idosch@idosch.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200817125059.193242-1-idosch@idosch.org> References: <20200817125059.193242-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel Register a dummy counter with devlink that is incremented by one whenever queried. Allow the query to fail by writing to a file in debugfs so that error paths in the core infrastructure could be exercised. Signed-off-by: Amit Cohen Signed-off-by: Danielle Ratson Signed-off-by: Ido Schimmel --- drivers/net/netdevsim/dev.c | 92 ++++++++++++++++++++++++++++++- drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 32f339fedb21..075d2d4e22a5 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -692,6 +692,81 @@ static void nsim_dev_traps_exit(struct devlink *devlink) kfree(nsim_dev->trap_data); } +struct nsim_metric_data { + struct devlink_metric *dummy_counter; + struct dentry *ddir; + u64 dummy_counter_value; + bool fail_counter_get; +}; + +static int nsim_dev_dummy_counter_get(struct devlink_metric *metric, u64 *p_val) +{ + struct nsim_dev *nsim_dev = devlink_metric_priv(metric); + u64 *cnt; + + if (nsim_dev->metric_data->fail_counter_get) + return -EINVAL; + + cnt = &nsim_dev->metric_data->dummy_counter_value; + *p_val = (*cnt)++; + + return 0; +} + +static const struct devlink_metric_ops nsim_dev_dummy_counter_ops = { + .counter_get = nsim_dev_dummy_counter_get, +}; + +static int nsim_dev_metric_init(struct nsim_dev *nsim_dev) +{ + struct devlink *devlink = priv_to_devlink(nsim_dev); + struct nsim_metric_data *nsim_metric_data; + struct devlink_metric *dummy_counter; + int err; + + nsim_metric_data = kzalloc(sizeof(*nsim_metric_data), GFP_KERNEL); + if (!nsim_metric_data) + return -ENOMEM; + nsim_dev->metric_data = nsim_metric_data; + + dummy_counter = devlink_metric_counter_create(devlink, "dummy_counter", + &nsim_dev_dummy_counter_ops, + nsim_dev); + if (IS_ERR(dummy_counter)) { + err = PTR_ERR(dummy_counter); + goto err_free_metric_data; + } + nsim_metric_data->dummy_counter = dummy_counter; + + nsim_metric_data->ddir = debugfs_create_dir("metric", nsim_dev->ddir); + if (IS_ERR(nsim_metric_data->ddir)) { + err = PTR_ERR(nsim_metric_data->ddir); + goto err_dummy_counter_destroy; + } + + nsim_metric_data->fail_counter_get = false; + debugfs_create_bool("fail_counter_get", 0600, nsim_metric_data->ddir, + &nsim_metric_data->fail_counter_get); + + return 0; + +err_dummy_counter_destroy: + devlink_metric_destroy(devlink, dummy_counter); +err_free_metric_data: + kfree(nsim_metric_data); + return err; +} + +static void nsim_dev_metric_exit(struct nsim_dev *nsim_dev) +{ + struct nsim_metric_data *nsim_metric_data = nsim_dev->metric_data; + struct devlink *devlink = priv_to_devlink(nsim_dev); + + debugfs_remove_recursive(nsim_metric_data->ddir); + devlink_metric_destroy(devlink, nsim_metric_data->dummy_counter); + kfree(nsim_metric_data); +} + static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack); static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev); @@ -1008,10 +1083,14 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, if (err) goto err_traps_exit; - err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + err = nsim_dev_metric_init(nsim_dev); if (err) goto err_health_exit; + err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); + if (err) + goto err_metric_exit; + nsim_dev->take_snapshot = debugfs_create_file("take_snapshot", 0200, nsim_dev->ddir, @@ -1019,6 +1098,8 @@ static int nsim_dev_reload_create(struct nsim_dev *nsim_dev, &nsim_dev_take_snapshot_fops); return 0; +err_metric_exit: + nsim_dev_metric_exit(nsim_dev); err_health_exit: nsim_dev_health_exit(nsim_dev); err_traps_exit: @@ -1089,10 +1170,14 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) if (err) goto err_debugfs_exit; - err = nsim_bpf_dev_init(nsim_dev); + err = nsim_dev_metric_init(nsim_dev); if (err) goto err_health_exit; + err = nsim_bpf_dev_init(nsim_dev); + if (err) + goto err_metric_exit; + err = nsim_dev_port_add_all(nsim_dev, nsim_bus_dev->port_count); if (err) goto err_bpf_dev_exit; @@ -1103,6 +1188,8 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) err_bpf_dev_exit: nsim_bpf_dev_exit(nsim_dev); +err_metric_exit: + nsim_dev_metric_exit(nsim_dev); err_health_exit: nsim_dev_health_exit(nsim_dev); err_debugfs_exit: @@ -1133,6 +1220,7 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) return; debugfs_remove(nsim_dev->take_snapshot); nsim_dev_port_del_all(nsim_dev); + nsim_dev_metric_exit(nsim_dev); nsim_dev_health_exit(nsim_dev); nsim_dev_traps_exit(devlink); nsim_dev_dummy_region_exit(nsim_dev); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 284f7092241d..5f9a99bc4022 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -171,6 +171,7 @@ struct nsim_dev { struct nsim_bus_dev *nsim_bus_dev; struct nsim_fib_data *fib_data; struct nsim_trap_data *trap_data; + struct nsim_metric_data *metric_data; struct dentry *ddir; struct dentry *ports_ddir; struct dentry *take_snapshot; From patchwork Mon Aug 17 12:50:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 262415 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 3F164C433E1 for ; Mon, 17 Aug 2020 12:52:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12ABD20789 for ; Mon, 17 Aug 2020 12:52:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="awfjKvdn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728540AbgHQMwz (ORCPT ); Mon, 17 Aug 2020 08:52:55 -0400 Received: from wnew3-smtp.messagingengine.com ([64.147.123.17]:53713 "EHLO wnew3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728460AbgHQMwy (ORCPT ); Mon, 17 Aug 2020 08:52:54 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id BA6493CA; Mon, 17 Aug 2020 08:52:52 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 17 Aug 2020 08:52:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=9Yq33ndBPm2JTNKrE2BgBjBPYn1WEP/sFtVlS8Smhq0=; b=awfjKvdn sNkYpmmEApkoGjgvhXKuaDhZN06jPiCQR0mdqqvxEltVmlZ8/7tFurk2exhYBPCL UobOcGIs/117RuVLM64BsGdKVmp4v5R3c1QfjC9+vfGsaSe2VroRuiJJFqssAe+Z tV+D1f3vLf6Zsk9mZE9n08BJEzgBy3g6+svQKyGszqKnGPild73no9SHflhA42IU BqJMbPZ+lmiZLJ6KeI3VeIbMh9yJ7oXwoCdLUBaV7AVdPlV3/9OSHvqMclhOdxr4 lWkabrYjjlv/L123/3ri7l+Nvt3UvQVDR936aFVBbkv6GhHuOerq+hmuoc2h+WOt KF68sMCjmNQlWw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtfedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecuggftrfgrthhtvghrnhepudetieevffffveelkeeljeffkefhke ehgfdtffethfelvdejgffghefgveejkefhnecukfhppeejledrudekvddrieefrdegvden ucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmhgrihhlfhhrohhmpehiughosh gthhesihguohhstghhrdhorhhg X-ME-Proxy: Received: from localhost.localdomain (bzq-79-182-63-42.red.bezeqint.net [79.182.63.42]) by mail.messagingengine.com (Postfix) with ESMTPA id CD2C03060067; Mon, 17 Aug 2020 08:52:41 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com, amcohen@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com, roopa@nvidia.com, dsahern@gmail.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, saeedm@nvidia.com, tariqt@nvidia.com, ayal@nvidia.com, eranbe@nvidia.com, mkubecek@suse.cz, Ido Schimmel Subject: [RFC PATCH net-next 4/6] mlxsw: reg: Add Tunneling NVE Counters Register Date: Mon, 17 Aug 2020 15:50:57 +0300 Message-Id: <20200817125059.193242-5-idosch@idosch.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200817125059.193242-1-idosch@idosch.org> References: <20200817125059.193242-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel The TNCR register exposes counters of NVE encapsulation and decapsulation on Spectrum-1. Signed-off-by: Amit Cohen Signed-off-by: Danielle Ratson Signed-off-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/reg.h | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h index 079b080de7f7..9f19127caf83 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/reg.h +++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h @@ -10070,6 +10070,56 @@ static inline void mlxsw_reg_tngcr_pack(char *payload, mlxsw_reg_tngcr_nve_group_size_flood_set(payload, 1); } +/* TNCR - Tunneling NVE Counters Register + * -------------------------------------- + * The TNCR register exposes counters of NVE encapsulation and decapsulation. + * + * Note: Not supported by Spectrum-2 onwards. + */ +#define MLXSW_REG_TNCR_ID 0xA002 +#define MLXSW_REG_TNCR_LEN 0x30 + +MLXSW_REG_DEFINE(tncr, MLXSW_REG_TNCR_ID, MLXSW_REG_TNCR_LEN); + +/* reg_tncr_clear_counters + * Clear counters. + * Access: OP + */ +MLXSW_ITEM32(reg, tncr, clear_counters, 0x00, 31, 1); + +/* reg_tncr_count_encap + * Count number of packets which did encapsulation to an NVE tunnel. + * Access: RO + * + * Note: Multicast packets which are encapsulated multiple times are counted + * multiple times. + */ +MLXSW_ITEM64(reg, tncr, count_encap, 0x10, 0, 64); + +/* reg_tncr_count_decap + * Count number of packets which did decapsulation from an NVE tunnel. + * Access: RO + */ +MLXSW_ITEM64(reg, tncr, count_decap, 0x18, 0, 64); + +/* reg_tncr_count_decap_errors + * Count number of packets which had decapsulation errors from an NVE tunnel. + * Access: RO + */ +MLXSW_ITEM64(reg, tncr, count_decap_errors, 0x20, 0, 64); + +/* reg_tncr_count_decap_discards + * Count number of packets which had decapsulation discards from an NVE tunnel. + * Access: RO + */ +MLXSW_ITEM64(reg, tncr, count_decap_discards, 0x28, 0, 64); + +static inline void mlxsw_reg_tncr_pack(char *payload, bool clear_counters) +{ + MLXSW_REG_ZERO(tncr, payload); + mlxsw_reg_tncr_clear_counters_set(payload, clear_counters); +} + /* TNUMT - Tunneling NVE Underlay Multicast Table Register * ------------------------------------------------------- * The TNUMT register is for building the underlay MC table. It is used @@ -11001,6 +11051,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = { MLXSW_REG(mtptpt), MLXSW_REG(mgpir), MLXSW_REG(tngcr), + MLXSW_REG(tncr), MLXSW_REG(tnumt), MLXSW_REG(tnqcr), MLXSW_REG(tnqdr), From patchwork Mon Aug 17 12:50:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 262414 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, 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 6DA60C433DF for ; Mon, 17 Aug 2020 12:53:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24EDB2078D for ; Mon, 17 Aug 2020 12:53:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="AgjKSaC7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728576AbgHQMxX (ORCPT ); Mon, 17 Aug 2020 08:53:23 -0400 Received: from wnew3-smtp.messagingengine.com ([64.147.123.17]:60951 "EHLO wnew3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728563AbgHQMxW (ORCPT ); Mon, 17 Aug 2020 08:53:22 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id A6150714; Mon, 17 Aug 2020 08:53:20 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 17 Aug 2020 08:53:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=aVE32PImCPZl/J7SliC3bPsJtAIgs+EOzRaZs/BOa5Y=; b=AgjKSaC7 UeGqop4sA56GAB/7Ee/13ZxsoJRxaSjL2F0IBw3IVVwc291FtOjngnS9vTPjB/IL mROTSIvbqTy6VjmQcO2LLzYMqKh/62Pljvz8Xh0x1v/L5Z0/3HJvaTMuaq2dJMbi as6+8UmjQZUX+Ag67UL736M/0TmJO0RJn2oEBem/KR9dkdXu9umMaZyx4jG49Wpo jTu7MPIDBLZ/72JxeUvVX+a5fU/OrrUbLQWvHeHJKShj8KGpYeYio9NQZ2RyKige rk5O9PuNa11BWVHzz6bnY329XttEdn6J+KOuGtBviOH0+vehsex1ni0GiUJ+ahCT MFpN69jtM92rRg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedruddtfedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepkfguohcuufgthhhimhhmvghluceoihguohhstghhsehiugho shgthhdrohhrgheqnecuggftrfgrthhtvghrnhepudetieevffffveelkeeljeffkefhke ehgfdtffethfelvdejgffghefgveejkefhnecukfhppeejledrudekvddrieefrdegvden ucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepmhgrihhlfhhrohhmpehiughosh gthhesihguohhstghhrdhorhhg X-ME-Proxy: Received: from localhost.localdomain (bzq-79-182-63-42.red.bezeqint.net [79.182.63.42]) by mail.messagingengine.com (Postfix) with ESMTPA id 0DACA30600B1; Mon, 17 Aug 2020 08:53:04 -0400 (EDT) From: Ido Schimmel To: netdev@vger.kernel.org Cc: davem@davemloft.net, kuba@kernel.org, jiri@nvidia.com, amcohen@nvidia.com, danieller@nvidia.com, mlxsw@nvidia.com, roopa@nvidia.com, dsahern@gmail.com, andrew@lunn.ch, f.fainelli@gmail.com, vivien.didelot@gmail.com, saeedm@nvidia.com, tariqt@nvidia.com, ayal@nvidia.com, eranbe@nvidia.com, mkubecek@suse.cz, Ido Schimmel Subject: [RFC PATCH net-next 6/6] mlxsw: spectrum_nve: Expose VXLAN counters via devlink-metric Date: Mon, 17 Aug 2020 15:50:59 +0300 Message-Id: <20200817125059.193242-7-idosch@idosch.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200817125059.193242-1-idosch@idosch.org> References: <20200817125059.193242-1-idosch@idosch.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel The Spectrum ASICs have a single hardware VTEP that is able to perform VXLAN encapsulation and decapsulation. The VTEP is logically mapped by mlxsw to the multiple VXLAN netdevs that are using it. Exposing the counters of this VTEP via the multiple VXLAN netdevs that are using it would be both inaccurate and confusing for users. Instead, expose the counters of the VTEP via devlink-metric. Note that Spectrum-1 supports a different set of counters compared to newer ASICs in the Spectrum family. Signed-off-by: Amit Cohen Signed-off-by: Danielle Ratson Signed-off-by: Ido Schimmel --- Documentation/networking/devlink/mlxsw.rst | 36 +++ .../ethernet/mellanox/mlxsw/spectrum_nve.h | 10 + .../mellanox/mlxsw/spectrum_nve_vxlan.c | 285 ++++++++++++++++++ 3 files changed, 331 insertions(+) diff --git a/Documentation/networking/devlink/mlxsw.rst b/Documentation/networking/devlink/mlxsw.rst index cf857cb4ba8f..5d95056a571a 100644 --- a/Documentation/networking/devlink/mlxsw.rst +++ b/Documentation/networking/devlink/mlxsw.rst @@ -79,3 +79,39 @@ Driver-specific Traps routed through a disabled router interface (RIF). This can happen during RIF dismantle, when the RIF is first disabled before being removed completely + +Metrics +======= + +.. list-table:: List of metrics registered by ``mlxsw`` + :widths: 5 5 20 70 + + * - Name + - Type + - Supported platforms + - Description + * - ``nve_vxlan_encap`` + - ``counter`` + - Spectrum-1 only + - Counts number of packets that were VXLAN encapsulated by the device. A + packet sent to multiple VTEPs is counted multiple times + * - ``nve_vxlan_decap`` + - ``counter`` + - Spectrum-1 only + - Counts number of VXLAN packets that were decapsulated (successfully or + otherwise) by the device + * - ``nve_vxlan_decap_errors`` + - ``counter`` + - Spectrum-1 only + - Counts number of VXLAN packets that encountered decapsulation errors. + This includes overlay packets with a VLAN tag, ECN mismatch between + overlay and underlay, multicast overlay source MAC, overlay source MAC + equals overlay destination MAC and packets too short to decapsulate + * - ``nve_vxlan_decap_discards`` + - ``counter`` + - All + - Counts number of VXLAN packets that were discarded during decapsulation. + In Spectrum-1 this includes packets that had to be VXLAN decapsulated + when VXLAN decapsulation is disabled and fragmented overlay packets. In + Spectrum-2 this includes ``nve_vxlan_decap_errors`` errors and a missing + mapping between VNI and filtering identifier (FID) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.h index 12f664f42f21..249adea4d547 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.h @@ -6,6 +6,7 @@ #include #include +#include #include "spectrum.h" @@ -20,10 +21,19 @@ struct mlxsw_sp_nve_config { union mlxsw_sp_l3addr ul_sip; }; +struct mlxsw_sp_nve_metrics { + struct devlink_metric *counter_encap; + struct devlink_metric *counter_decap; + struct devlink_metric *counter_decap_errors; + struct devlink_metric *counter_decap_discards; + struct devlink_metric *counter_encap_discards; +}; + struct mlxsw_sp_nve { struct mlxsw_sp_nve_config config; struct rhashtable mc_list_ht; struct mlxsw_sp *mlxsw_sp; + struct mlxsw_sp_nve_metrics metrics; const struct mlxsw_sp_nve_ops **nve_ops_arr; unsigned int num_nve_tunnels; /* Protected by RTNL */ unsigned int num_max_mc_entries[MLXSW_SP_L3_PROTO_MAX]; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c index 05517c7feaa5..7b71fecb3b96 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_nve_vxlan.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "reg.h" @@ -220,6 +221,173 @@ static int mlxsw_sp1_nve_vxlan_rtdp_set(struct mlxsw_sp *mlxsw_sp, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rtdp), rtdp_pl); } +static int +mlxsw_sp1_nve_vxlan_common_counter_get(struct devlink_metric *metric, + char *tncr_pl) +{ + struct mlxsw_sp *mlxsw_sp = devlink_metric_priv(metric); + + mlxsw_reg_tncr_pack(tncr_pl, false); + + return mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(tncr), tncr_pl); +} + +static int +mlxsw_sp1_nve_vxlan_encap_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr_pl[MLXSW_REG_TNCR_LEN]; + int err; + + err = mlxsw_sp1_nve_vxlan_common_counter_get(metric, tncr_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr_count_encap_get(tncr_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp1_nve_vxlan_encap_ops = { + .counter_get = mlxsw_sp1_nve_vxlan_encap_counter_get, +}; + +static int +mlxsw_sp1_nve_vxlan_decap_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr_pl[MLXSW_REG_TNCR_LEN]; + int err; + + err = mlxsw_sp1_nve_vxlan_common_counter_get(metric, tncr_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr_count_decap_get(tncr_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp1_nve_vxlan_decap_ops = { + .counter_get = mlxsw_sp1_nve_vxlan_decap_counter_get, +}; + +static int +mlxsw_sp1_nve_vxlan_decap_errors_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr_pl[MLXSW_REG_TNCR_LEN]; + int err; + + err = mlxsw_sp1_nve_vxlan_common_counter_get(metric, tncr_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr_count_decap_errors_get(tncr_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp1_nve_vxlan_decap_errors_ops = { + .counter_get = mlxsw_sp1_nve_vxlan_decap_errors_counter_get, +}; + +static int +mlxsw_sp1_nve_vxlan_decap_discards_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr_pl[MLXSW_REG_TNCR_LEN]; + int err; + + err = mlxsw_sp1_nve_vxlan_common_counter_get(metric, tncr_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr_count_decap_discards_get(tncr_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp1_nve_vxlan_decap_discards_ops = { + .counter_get = mlxsw_sp1_nve_vxlan_decap_discards_counter_get, +}; + +static int mlxsw_sp1_nve_vxlan_counters_clear(struct mlxsw_sp *mlxsw_sp) +{ + char tncr_pl[MLXSW_REG_TNCR_LEN]; + + mlxsw_reg_tncr_pack(tncr_pl, true); + + /* Clear operation is implemented on query. */ + return mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(tncr), tncr_pl); +} + +static int mlxsw_sp1_nve_vxlan_metrics_init(struct mlxsw_sp *mlxsw_sp) +{ + struct mlxsw_sp_nve_metrics *metrics = &mlxsw_sp->nve->metrics; + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); + int err; + + err = mlxsw_sp1_nve_vxlan_counters_clear(mlxsw_sp); + if (err) + return err; + + metrics->counter_encap = + devlink_metric_counter_create(devlink, "nve_vxlan_encap", + &mlxsw_sp1_nve_vxlan_encap_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_encap)) + return PTR_ERR(metrics->counter_encap); + + metrics->counter_decap = + devlink_metric_counter_create(devlink, "nve_vxlan_decap", + &mlxsw_sp1_nve_vxlan_decap_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_decap)) { + err = PTR_ERR(metrics->counter_decap); + goto err_counter_decap; + } + + metrics->counter_decap_errors = + devlink_metric_counter_create(devlink, "nve_vxlan_decap_errors", + &mlxsw_sp1_nve_vxlan_decap_errors_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_decap_errors)) { + err = PTR_ERR(metrics->counter_decap_errors); + goto err_counter_decap_errors; + } + + metrics->counter_decap_discards = + devlink_metric_counter_create(devlink, "nve_vxlan_decap_discards", + &mlxsw_sp1_nve_vxlan_decap_discards_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_decap_discards)) { + err = PTR_ERR(metrics->counter_decap_discards); + goto err_counter_decap_discards; + } + + return 0; + +err_counter_decap_discards: + devlink_metric_destroy(devlink, metrics->counter_decap_errors); +err_counter_decap_errors: + devlink_metric_destroy(devlink, metrics->counter_decap); +err_counter_decap: + devlink_metric_destroy(devlink, metrics->counter_encap); + return err; +} + +static void mlxsw_sp1_nve_vxlan_metrics_fini(struct mlxsw_sp *mlxsw_sp) +{ + struct mlxsw_sp_nve_metrics *metrics = &mlxsw_sp->nve->metrics; + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); + + devlink_metric_destroy(devlink, metrics->counter_decap_discards); + devlink_metric_destroy(devlink, metrics->counter_decap_errors); + devlink_metric_destroy(devlink, metrics->counter_decap); + devlink_metric_destroy(devlink, metrics->counter_encap); +} + static int mlxsw_sp1_nve_vxlan_init(struct mlxsw_sp_nve *nve, const struct mlxsw_sp_nve_config *config) { @@ -238,6 +406,10 @@ static int mlxsw_sp1_nve_vxlan_init(struct mlxsw_sp_nve *nve, if (err) goto err_rtdp_set; + err = mlxsw_sp1_nve_vxlan_metrics_init(mlxsw_sp); + if (err) + goto err_metrics_init; + err = mlxsw_sp_router_nve_promote_decap(mlxsw_sp, config->ul_tb_id, config->ul_proto, &config->ul_sip, @@ -248,6 +420,8 @@ static int mlxsw_sp1_nve_vxlan_init(struct mlxsw_sp_nve *nve, return 0; err_promote_decap: + mlxsw_sp1_nve_vxlan_metrics_fini(mlxsw_sp); +err_metrics_init: err_rtdp_set: mlxsw_sp1_nve_vxlan_config_clear(mlxsw_sp); err_config_set: @@ -262,6 +436,7 @@ static void mlxsw_sp1_nve_vxlan_fini(struct mlxsw_sp_nve *nve) mlxsw_sp_router_nve_demote_decap(mlxsw_sp, config->ul_tb_id, config->ul_proto, &config->ul_sip); + mlxsw_sp1_nve_vxlan_metrics_fini(mlxsw_sp); mlxsw_sp1_nve_vxlan_config_clear(mlxsw_sp); __mlxsw_sp_nve_inc_parsing_depth_put(mlxsw_sp, 0); } @@ -360,6 +535,109 @@ static int mlxsw_sp2_nve_vxlan_rtdp_set(struct mlxsw_sp *mlxsw_sp, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(rtdp), rtdp_pl); } +static int +mlxsw_sp2_nve_vxlan_common_counter_get(struct devlink_metric *metric, + char *tncr2_pl) +{ + struct mlxsw_sp *mlxsw_sp = devlink_metric_priv(metric); + + mlxsw_reg_tncr2_pack(tncr2_pl, MLXSW_REG_TNCR2_TUNNEL_PORT_NVE, false); + + return mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(tncr2), tncr2_pl); +} + +static int +mlxsw_sp2_nve_vxlan_decap_discards_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr2_pl[MLXSW_REG_TNCR2_LEN]; + int err; + + err = mlxsw_sp2_nve_vxlan_common_counter_get(metric, tncr2_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr2_count_decap_discards_get(tncr2_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp2_nve_vxlan_decap_discards_ops = { + .counter_get = mlxsw_sp2_nve_vxlan_decap_discards_counter_get, +}; + +static int +mlxsw_sp2_nve_vxlan_encap_discards_counter_get(struct devlink_metric *metric, + u64 *p_val) +{ + char tncr2_pl[MLXSW_REG_TNCR2_LEN]; + int err; + + err = mlxsw_sp2_nve_vxlan_common_counter_get(metric, tncr2_pl); + if (err) + return err; + + *p_val = mlxsw_reg_tncr2_count_encap_discards_get(tncr2_pl); + + return 0; +} + +static const struct devlink_metric_ops mlxsw_sp2_nve_vxlan_encap_discards_ops = { + .counter_get = mlxsw_sp2_nve_vxlan_encap_discards_counter_get, +}; + +static int mlxsw_sp2_nve_vxlan_counters_clear(struct mlxsw_sp *mlxsw_sp) +{ + char tncr2_pl[MLXSW_REG_TNCR2_LEN]; + + mlxsw_reg_tncr2_pack(tncr2_pl, MLXSW_REG_TNCR2_TUNNEL_PORT_NVE, true); + + /* Clear operation is implemented on query. */ + return mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(tncr2), tncr2_pl); +} + +static int mlxsw_sp2_nve_vxlan_metrics_init(struct mlxsw_sp *mlxsw_sp) +{ + struct mlxsw_sp_nve_metrics *metrics = &mlxsw_sp->nve->metrics; + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); + int err; + + err = mlxsw_sp2_nve_vxlan_counters_clear(mlxsw_sp); + if (err) + return err; + + metrics->counter_decap_discards = + devlink_metric_counter_create(devlink, "nve_vxlan_decap_discards", + &mlxsw_sp2_nve_vxlan_decap_discards_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_decap_discards)) + return PTR_ERR(metrics->counter_decap_discards); + + metrics->counter_encap_discards = + devlink_metric_counter_create(devlink, "nve_vxlan_encap_discards", + &mlxsw_sp2_nve_vxlan_encap_discards_ops, + mlxsw_sp); + if (IS_ERR(metrics->counter_encap_discards)) { + err = PTR_ERR(metrics->counter_encap_discards); + goto err_counter_encap_discards; + } + + return 0; + +err_counter_encap_discards: + devlink_metric_destroy(devlink, metrics->counter_decap_discards); + return err; +} + +static void mlxsw_sp2_nve_vxlan_metrics_fini(struct mlxsw_sp *mlxsw_sp) +{ + struct mlxsw_sp_nve_metrics *metrics = &mlxsw_sp->nve->metrics; + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); + + devlink_metric_destroy(devlink, metrics->counter_encap_discards); + devlink_metric_destroy(devlink, metrics->counter_decap_discards); +} + static int mlxsw_sp2_nve_vxlan_init(struct mlxsw_sp_nve *nve, const struct mlxsw_sp_nve_config *config) { @@ -379,6 +657,10 @@ static int mlxsw_sp2_nve_vxlan_init(struct mlxsw_sp_nve *nve, if (err) goto err_rtdp_set; + err = mlxsw_sp2_nve_vxlan_metrics_init(mlxsw_sp); + if (err) + goto err_metrics_init; + err = mlxsw_sp_router_nve_promote_decap(mlxsw_sp, config->ul_tb_id, config->ul_proto, &config->ul_sip, @@ -389,6 +671,8 @@ static int mlxsw_sp2_nve_vxlan_init(struct mlxsw_sp_nve *nve, return 0; err_promote_decap: + mlxsw_sp2_nve_vxlan_metrics_fini(mlxsw_sp); +err_metrics_init: err_rtdp_set: mlxsw_sp2_nve_vxlan_config_clear(mlxsw_sp); err_config_set: @@ -403,6 +687,7 @@ static void mlxsw_sp2_nve_vxlan_fini(struct mlxsw_sp_nve *nve) mlxsw_sp_router_nve_demote_decap(mlxsw_sp, config->ul_tb_id, config->ul_proto, &config->ul_sip); + mlxsw_sp2_nve_vxlan_metrics_fini(mlxsw_sp); mlxsw_sp2_nve_vxlan_config_clear(mlxsw_sp); __mlxsw_sp_nve_inc_parsing_depth_put(mlxsw_sp, 0); }