From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY, URIBL_BLOCKED,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 EA134C282C4 for ; Tue, 22 Jan 2019 15:57:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3FC6217F5 for ; Tue, 22 Jan 2019 15:57:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729344AbfAVP5q (ORCPT ); Tue, 22 Jan 2019 10:57:46 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:35744 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729309AbfAVP5o (ORCPT ); Tue, 22 Jan 2019 10:57:44 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from eranbe@mellanox.com) with ESMTPS (AES256-SHA encrypted); 22 Jan 2019 17:57:35 +0200 Received: from dev-l-vrt-198.mtl.labs.mlnx (dev-l-vrt-198.mtl.labs.mlnx [10.134.198.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x0MFvZq6001815; Tue, 22 Jan 2019 17:57:35 +0200 From: Eran Ben Elisha To: netdev@vger.kernel.org, Jiri Pirko , "David S. Miller" , Saeed Mahameed Cc: Moshe Shemesh , Eran Ben Elisha Subject: [PATCH net-next 3/7] devlink: move devlink health reporter to use devlink msg API Date: Tue, 22 Jan 2019 17:57:20 +0200 Message-Id: <1548172644-30862-4-git-send-email-eranbe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1548172644-30862-1-git-send-email-eranbe@mellanox.com> References: <1548172644-30862-1-git-send-email-eranbe@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move devlink reporter diagnose and dump operations to use the new msg API. Redefine the signature of diagnose and dump operations and move the mlx5e reporter to use it with the new format. Signed-off-by: Eran Ben Elisha Reviewed-by: Moshe Shemesh --- .../mellanox/mlx5/core/en/reporter_tx.c | 1 + include/net/devlink.h | 9 +- net/core/devlink.c | 95 +++++-------------- 3 files changed, 28 insertions(+), 77 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c index fc92850c214a..7238cda670ba 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_tx.c @@ -264,6 +264,7 @@ static int mlx5e_tx_reporter_diagnose(struct devlink_health_reporter *reporter, static const struct devlink_health_reporter_ops mlx5_tx_reporter_ops = { .name = "TX", .recover = mlx5e_tx_reporter_recover, + .diagnose = mlx5e_tx_reporter_diagnose, }; #define MLX5_REPORTER_TX_GRACEFUL_PERIOD 500 diff --git a/include/net/devlink.h b/include/net/devlink.h index fe323e9b14e1..d66de8b80cc2 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -442,17 +442,12 @@ struct devlink_health_reporter; struct devlink_health_reporter_ops { char *name; - unsigned int dump_size; - unsigned int diagnose_size; int (*recover)(struct devlink_health_reporter *reporter, void *priv_ctx); int (*dump)(struct devlink_health_reporter *reporter, - struct devlink_health_buffer **buffers_array, - unsigned int buffer_size, unsigned int num_buffers, - void *priv_ctx); + struct devlink_msg_ctx *msg_ctx, void *priv_ctx); int (*diagnose)(struct devlink_health_reporter *reporter, - struct devlink_health_buffer **buffers_array, - unsigned int buffer_size, unsigned int num_buffers); + struct devlink_msg_ctx *msg_ctx); }; struct devlink_ops { diff --git a/net/core/devlink.c b/net/core/devlink.c index 57ca096849b3..347b638e6f32 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -4555,10 +4555,8 @@ static int devlink_msg_snd(struct genl_info *info, struct devlink_health_reporter { struct list_head list; - struct devlink_health_buffer **dump_buffers_array; + struct devlink_msg_ctx *dump_msg_ctx; struct mutex dump_lock; /* lock parallel read/write from dump buffers */ - struct devlink_health_buffer **diagnose_buffers_array; - struct mutex diagnose_lock; /* lock parallel read/write from diagnose buffers */ void *priv; const struct devlink_health_reporter_ops *ops; struct devlink *devlink; @@ -4619,9 +4617,7 @@ devlink_health_reporter_create(struct devlink *devlink, goto unlock; } - if (WARN_ON(ops->dump && !ops->dump_size) || - WARN_ON(ops->diagnose && !ops->diagnose_size) || - WARN_ON(auto_recover && !ops->recover) || + if (WARN_ON(auto_recover && !ops->recover) || WARN_ON(graceful_period && !ops->recover)) { reporter = ERR_PTR(-EINVAL); goto unlock; @@ -4633,31 +4629,8 @@ devlink_health_reporter_create(struct devlink *devlink, goto unlock; } - if (ops->dump) { - reporter->dump_buffers_array = - devlink_health_buffers_create(ops->dump_size); - if (!reporter->dump_buffers_array) { - kfree(reporter); - reporter = ERR_PTR(-ENOMEM); - goto unlock; - } - } - - if (ops->diagnose) { - reporter->diagnose_buffers_array = - devlink_health_buffers_create(ops->diagnose_size); - if (!reporter->diagnose_buffers_array) { - devlink_health_buffers_destroy(reporter->dump_buffers_array, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(ops->dump_size)); - kfree(reporter); - reporter = ERR_PTR(-ENOMEM); - goto unlock; - } - } - list_add_tail(&reporter->list, &devlink->reporter_list); mutex_init(&reporter->dump_lock); - mutex_init(&reporter->diagnose_lock); reporter->priv = priv; reporter->ops = ops; @@ -4680,10 +4653,8 @@ devlink_health_reporter_destroy(struct devlink_health_reporter *reporter) { mutex_lock(&reporter->devlink->lock); list_del(&reporter->list); - devlink_health_buffers_destroy(reporter->dump_buffers_array, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size)); - devlink_health_buffers_destroy(reporter->diagnose_buffers_array, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->diagnose_size)); + if (reporter->dump_msg_ctx) + devlink_msg_ctx_free(reporter->dump_msg_ctx); kfree(reporter); mutex_unlock(&reporter->devlink->lock); } @@ -4720,12 +4691,15 @@ static int devlink_health_do_dump(struct devlink_health_reporter *reporter, if (reporter->dump_avail) return 0; - devlink_health_buffers_reset(reporter->dump_buffers_array, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size)); - err = reporter->ops->dump(reporter, reporter->dump_buffers_array, - DEVLINK_HEALTH_BUFFER_SIZE, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size), - priv_ctx); + reporter->dump_msg_ctx = devlink_msg_ctx_alloc(); + if (IS_ERR_OR_NULL(reporter->dump_msg_ctx)) { + err = PTR_ERR(reporter->dump_msg_ctx); + reporter->dump_msg_ctx = NULL; + return err; + } + + err = reporter->ops->dump(reporter, reporter->dump_msg_ctx, + priv_ctx); if (!err) { reporter->dump_avail = true; reporter->dump_ts = jiffies; @@ -4960,7 +4934,7 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; struct devlink_health_reporter *reporter; - u64 num_of_buffers; + struct devlink_msg_ctx *msg_ctx; int err; reporter = devlink_health_reporter_get_from_info(devlink, info); @@ -4970,32 +4944,19 @@ static int devlink_nl_cmd_health_reporter_diagnose_doit(struct sk_buff *skb, if (!reporter->ops->diagnose) return -EOPNOTSUPP; - num_of_buffers = - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->diagnose_size); + msg_ctx = devlink_msg_ctx_alloc(); + if (IS_ERR_OR_NULL(msg_ctx)) + return PTR_ERR(msg_ctx); - mutex_lock(&reporter->diagnose_lock); - devlink_health_buffers_reset(reporter->diagnose_buffers_array, - num_of_buffers); - - err = reporter->ops->diagnose(reporter, - reporter->diagnose_buffers_array, - DEVLINK_HEALTH_BUFFER_SIZE, - num_of_buffers); + err = reporter->ops->diagnose(reporter, msg_ctx); if (err) goto out; - err = devlink_health_buffer_snd(info, - DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, - 0, reporter->diagnose_buffers_array, - num_of_buffers); - if (err) - goto out; - - mutex_unlock(&reporter->diagnose_lock); - return 0; + err = devlink_msg_snd(info, DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE, + 0, msg_ctx); out: - mutex_unlock(&reporter->diagnose_lock); + devlink_msg_ctx_free(msg_ctx); return err; } @@ -5004,8 +4965,8 @@ devlink_health_dump_clear(struct devlink_health_reporter *reporter) { reporter->dump_avail = false; reporter->dump_ts = 0; - devlink_health_buffers_reset(reporter->dump_buffers_array, - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size)); + devlink_msg_ctx_free(reporter->dump_msg_ctx); + reporter->dump_msg_ctx = NULL; } static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb, @@ -5013,7 +4974,6 @@ static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb, { struct devlink *devlink = info->user_ptr[0]; struct devlink_health_reporter *reporter; - u64 num_of_buffers; int err; reporter = devlink_health_reporter_get_from_info(devlink, info); @@ -5023,18 +4983,13 @@ static int devlink_nl_cmd_health_reporter_dump_get_doit(struct sk_buff *skb, if (!reporter->ops->dump) return -EOPNOTSUPP; - num_of_buffers = - DEVLINK_HEALTH_SIZE_TO_BUFFERS(reporter->ops->dump_size); - mutex_lock(&reporter->dump_lock); err = devlink_health_do_dump(reporter, NULL); if (err) goto out; - err = devlink_health_buffer_snd(info, - DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, - 0, reporter->dump_buffers_array, - num_of_buffers); + err = devlink_msg_snd(info, DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET, + 0, reporter->dump_msg_ctx); out: mutex_unlock(&reporter->dump_lock); -- 2.17.1