The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Moshe Shemesh <moshe@mellanox.com>
To: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>
Cc: Jiri Pirko <jiri@mellanox.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Moshe Shemesh <moshe@mellanox.com>
Subject: [PATCH net-next RFC v3 03/14] devlink: Add reload actions counters to dev get
Date: Sun, 30 Aug 2020 18:27:23 +0300	[thread overview]
Message-ID: <1598801254-27764-4-git-send-email-moshe@mellanox.com> (raw)
In-Reply-To: <1598801254-27764-1-git-send-email-moshe@mellanox.com>

Expose devlink reload actions counters to the user through devlink dev
get command.

Examples:
$ devlink dev show
pci/0000:82:00.0:
  reload_actions_stats:
    driver_reinit 2
    fw_activate 1
    fw_activate_no_reset 0
pci/0000:82:00.1:
  reload_actions_stats:
    driver_reinit 1
    fw_activate 1
    fw_activate_no_reset 0

$ devlink dev show -jp
{
    "dev": {
        "pci/0000:82:00.0": {
            "reload_actions_stats": [ {
                    "driver_reinit": 2
                },{
                    "fw_activate": 1
                },{
                    "fw_activate_no_reset": 0
                } ]
        },
        "pci/0000:82:00.1": {
            "reload_actions_stats": [ {
                    "driver_reinit": 1
                },{
                    "fw_activate": 1
                },{
                    "fw_activate_no_reset": 0
                } ]
        }
    }
}

Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
---
v2 -> v3:
- Add reload actions counters instead of supported reload actions
  (reload actions counters are only for supported action so no need for
   both)
v1 -> v2:
- Removed DEVLINK_ATTR_RELOAD_DEFAULT_LEVEL
- Removed DEVLINK_ATTR_RELOAD_LEVELS_INFO
- Have actions instead of levels
---
 include/uapi/linux/devlink.h |  3 +++
 net/core/devlink.c           | 37 +++++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 0a438135c3cf..fd7667c78417 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -478,6 +478,9 @@ enum devlink_attr {
 
 	DEVLINK_ATTR_RELOAD_ACTION,		/* u8 */
 	DEVLINK_ATTR_RELOAD_ACTIONS_DONE,	/* nested */
+	DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE,	/* u32 */
+	DEVLINK_ATTR_RELOAD_ACTION_CNT,		/* nested */
+	DEVLINK_ATTR_RELOAD_ACTIONS_CNTS,	/* nested */
 
 	/* add new attributes above here, update the policy in devlink.c */
 
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 20a29c34ff71..962b14295380 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -462,6 +462,11 @@ static int devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
 	return 0;
 }
 
+static bool devlink_reload_supported(struct devlink *devlink)
+{
+	return devlink->ops->reload_down && devlink->ops->reload_up;
+}
+
 static bool
 devlink_reload_action_is_supported(struct devlink *devlink, enum devlink_reload_action action)
 {
@@ -472,7 +477,9 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
 			   enum devlink_command cmd, u32 portid,
 			   u32 seq, int flags)
 {
+	struct nlattr *reload_actions_cnts, *reload_action_cnt;
 	void *hdr;
+	int i;
 
 	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
 	if (!hdr)
@@ -483,9 +490,34 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
 	if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_FAILED, devlink->reload_failed))
 		goto nla_put_failure;
 
+	if (devlink_reload_supported(devlink)) {
+		reload_actions_cnts = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTIONS_CNTS);
+		if (!reload_actions_cnts)
+			goto nla_put_failure;
+
+		for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) {
+			if (!devlink_reload_action_is_supported(devlink, i))
+				continue;
+			reload_action_cnt = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_CNT);
+			if (!reload_action_cnt)
+				goto reload_actions_cnts_nest_cancel;
+			if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, i))
+				goto reload_action_cnt_nest_cancel;
+			if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION_CNT_VALUE,
+				       devlink->reload_actions_cnts[i]))
+				goto reload_action_cnt_nest_cancel;
+			nla_nest_end(msg, reload_action_cnt);
+		}
+		nla_nest_end(msg, reload_actions_cnts);
+	}
+
 	genlmsg_end(msg, hdr);
 	return 0;
 
+reload_action_cnt_nest_cancel:
+	nla_nest_cancel(msg, reload_action_cnt);
+reload_actions_cnts_nest_cancel:
+	nla_nest_cancel(msg, reload_actions_cnts);
 nla_put_failure:
 	genlmsg_cancel(msg, hdr);
 	return -EMSGSIZE;
@@ -2949,11 +2981,6 @@ static void devlink_reload_netns_change(struct devlink *devlink,
 				     DEVLINK_CMD_PARAM_NEW);
 }
 
-static bool devlink_reload_supported(const struct devlink *devlink)
-{
-	return devlink->ops->reload_down && devlink->ops->reload_up;
-}
-
 static void devlink_reload_failed_set(struct devlink *devlink,
 				      bool reload_failed)
 {
-- 
2.17.1


  parent reply	other threads:[~2020-08-30 15:28 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-30 15:27 [PATCH net-next RFC v3 00/14] Add devlink reload action option Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 01/14] devlink: Add reload action option to devlink reload command Moshe Shemesh
2020-08-31 12:15   ` Jiri Pirko
2020-09-01 19:43     ` Moshe Shemesh
2020-09-02  9:46       ` Jiri Pirko
2020-09-02 15:30         ` Jakub Kicinski
2020-09-03  5:57           ` Jiri Pirko
2020-09-03 19:47             ` Jakub Kicinski
2020-09-04  9:04               ` Jiri Pirko
2020-09-04 19:56                 ` Jakub Kicinski
2020-09-07 13:46                   ` Moshe Shemesh
2020-09-07 17:58                     ` Jakub Kicinski
2020-09-09 13:27                       ` Moshe Shemesh
2020-09-09 19:24                         ` Jakub Kicinski
2020-09-10  5:16                         ` Vasundhara Volam
2020-09-10  6:51                         ` Jiri Pirko
2020-08-30 15:27 ` [PATCH net-next RFC v3 02/14] devlink: Add reload actions counters Moshe Shemesh
2020-08-31 10:48   ` Jiri Pirko
2020-09-01 19:05     ` Moshe Shemesh
2020-09-02  0:01       ` Jakub Kicinski
2020-09-04  5:03         ` Moshe Shemesh
2020-08-30 15:27 ` Moshe Shemesh [this message]
2020-08-31 10:44   ` [PATCH net-next RFC v3 03/14] devlink: Add reload actions counters to dev get Jiri Pirko
2020-09-01 19:00     ` Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 04/14] net/mlx5: Add functions to set/query MFRL register Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 05/14] net/mlx5: Set cap for pci sync for fw update event Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 06/14] net/mlx5: Handle sync reset request event Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 07/14] net/mlx5: Handle sync reset now event Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 08/14] net/mlx5: Handle sync reset abort event Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 09/14] net/mlx5: Add support for devlink reload action fw activate Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 10/14] devlink: Add enable_remote_dev_reset generic parameter Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 11/14] net/mlx5: Add devlink param enable_remote_dev_reset support Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 12/14] net/mlx5: Add support for fw live patch event Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 13/14] net/mlx5: Add support for devlink reload action fw activate no reset Moshe Shemesh
2020-08-30 15:27 ` [PATCH net-next RFC v3 14/14] devlink: Add Documentation/networking/devlink/devlink-reload.rst Moshe Shemesh
2020-08-31 10:49 ` [PATCH net-next RFC v3 00/14] Add devlink reload action option Jiri Pirko
2020-09-01 20:05   ` Moshe Shemesh
     [not found]   ` <36e30108-26e3-44ae-e133-48d412f7efe6@nvidia.com>
2020-09-02  7:55     ` Jiri Pirko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1598801254-27764-4-git-send-email-moshe@mellanox.com \
    --to=moshe@mellanox.com \
    --cc=davem@davemloft.net \
    --cc=jiri@mellanox.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox