All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
	jiri@nvidia.com, petrm@nvidia.com, dsahern@gmail.com,
	andrew@lunn.ch, mlxsw@nvidia.com,
	Ido Schimmel <idosch@nvidia.com>
Subject: [PATCH net-next 02/11] devlink: introduce line card info get message
Date: Mon, 25 Apr 2022 06:44:22 +0300	[thread overview]
Message-ID: <20220425034431.3161260-3-idosch@nvidia.com> (raw)
In-Reply-To: <20220425034431.3161260-1-idosch@nvidia.com>

From: Jiri Pirko <jiri@nvidia.com>

Allow the driver to provide per line card info get op to fill-up info,
similar to the "devlink dev info".

Example:

$ devlink lc info pci/0000:01:00.0 lc 8
pci/0000:01:00.0:
  lc 8
    versions:
        fixed:
          hw.revision 0
        running:
          ini.version 4

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 .../networking/devlink/devlink-linecard.rst   |   4 +
 include/net/devlink.h                         |   7 +-
 include/uapi/linux/devlink.h                  |   2 +
 net/core/devlink.c                            | 130 +++++++++++++++++-
 4 files changed, 138 insertions(+), 5 deletions(-)

diff --git a/Documentation/networking/devlink/devlink-linecard.rst b/Documentation/networking/devlink/devlink-linecard.rst
index 6c0b8928bc13..5a8d5989702a 100644
--- a/Documentation/networking/devlink/devlink-linecard.rst
+++ b/Documentation/networking/devlink/devlink-linecard.rst
@@ -14,6 +14,7 @@ system. Following operations are provided:
   * Get a list of supported line card types.
   * Provision of a slot with specific line card type.
   * Get and monitor of line card state and its change.
+  * Get information about line card versions.
 
 Line card according to the type may contain one or more gearboxes
 to mux the lanes with certain speed to multiple ports with lanes
@@ -120,3 +121,6 @@ Example usage
 
     # Set slot 8 to be unprovisioned:
     $ devlink lc set pci/0000:01:00.0 lc 8 notype
+
+    # Set info for slot 8:
+    $ devlink lc info pci/0000:01:00.0 lc 8
diff --git a/include/net/devlink.h b/include/net/devlink.h
index c84b52fb9ff0..f96dcb376630 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -150,6 +150,8 @@ struct devlink_port_new_attrs {
 	   sfnum_valid:1;
 };
 
+struct devlink_info_req;
+
 /**
  * struct devlink_linecard_ops - Linecard operations
  * @provision: callback to provision the linecard slot with certain
@@ -168,6 +170,7 @@ struct devlink_port_new_attrs {
  *                  provisioned.
  * @types_count: callback to get number of supported types
  * @types_get: callback to get next type in list
+ * @info_get: callback to get linecard info
  */
 struct devlink_linecard_ops {
 	int (*provision)(struct devlink_linecard *linecard, void *priv,
@@ -182,6 +185,9 @@ struct devlink_linecard_ops {
 	void (*types_get)(struct devlink_linecard *linecard,
 			  void *priv, unsigned int index, const char **type,
 			  const void **type_priv);
+	int (*info_get)(struct devlink_linecard *linecard, void *priv,
+			struct devlink_info_req *req,
+			struct netlink_ext_ack *extack);
 };
 
 struct devlink_sb_pool_info {
@@ -628,7 +634,6 @@ struct devlink_flash_update_params {
 #define DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK	BIT(1)
 
 struct devlink_region;
-struct devlink_info_req;
 
 /**
  * struct devlink_region_ops - Region operations
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index cd578645f94f..fb8c3864457f 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -136,6 +136,8 @@ enum devlink_command {
 	DEVLINK_CMD_LINECARD_NEW,
 	DEVLINK_CMD_LINECARD_DEL,
 
+	DEVLINK_CMD_LINECARD_INFO_GET,		/* can dump */
+
 	/* add new commands above here */
 	__DEVLINK_CMD_MAX,
 	DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 41d9631ceada..5facd10de64a 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -2424,6 +2424,125 @@ static int devlink_nl_cmd_linecard_set_doit(struct sk_buff *skb,
 	return 0;
 }
 
+struct devlink_info_req {
+	struct sk_buff *msg;
+};
+
+static int
+devlink_nl_linecard_info_fill(struct sk_buff *msg, struct devlink *devlink,
+			      struct devlink_linecard *linecard,
+			      enum devlink_command cmd, u32 portid,
+			      u32 seq, int flags, struct netlink_ext_ack *extack)
+{
+	struct devlink_info_req req;
+	void *hdr;
+	int err;
+
+	hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
+	if (!hdr)
+		return -EMSGSIZE;
+
+	err = -EMSGSIZE;
+	if (devlink_nl_put_handle(msg, devlink))
+		goto nla_put_failure;
+	if (nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, linecard->index))
+		goto nla_put_failure;
+
+	req.msg = msg;
+	err = linecard->ops->info_get(linecard, linecard->priv, &req, extack);
+	if (err)
+		goto nla_put_failure;
+
+	genlmsg_end(msg, hdr);
+	return 0;
+
+nla_put_failure:
+	genlmsg_cancel(msg, hdr);
+	return err;
+}
+
+static int devlink_nl_cmd_linecard_info_get_doit(struct sk_buff *skb,
+						 struct genl_info *info)
+{
+	struct devlink_linecard *linecard = info->user_ptr[1];
+	struct devlink *devlink = linecard->devlink;
+	struct sk_buff *msg;
+	int err;
+
+	if (!linecard->ops->info_get)
+		return -EOPNOTSUPP;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	mutex_lock(&linecard->state_lock);
+	err = devlink_nl_linecard_info_fill(msg, devlink, linecard,
+					    DEVLINK_CMD_LINECARD_INFO_GET,
+					    info->snd_portid, info->snd_seq, 0,
+					    info->extack);
+	mutex_unlock(&linecard->state_lock);
+	if (err) {
+		nlmsg_free(msg);
+		return err;
+	}
+
+	return genlmsg_reply(msg, info);
+}
+
+static int devlink_nl_cmd_linecard_info_get_dumpit(struct sk_buff *msg,
+						   struct netlink_callback *cb)
+{
+	struct devlink_linecard *linecard;
+	struct devlink *devlink;
+	int start = cb->args[0];
+	unsigned long index;
+	int idx = 0;
+	int err = 0;
+
+	mutex_lock(&devlink_mutex);
+	xa_for_each_marked(&devlinks, index, devlink, DEVLINK_REGISTERED) {
+		if (!devlink_try_get(devlink))
+			continue;
+
+		if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
+			goto retry;
+
+		mutex_lock(&devlink->linecards_lock);
+		list_for_each_entry(linecard, &devlink->linecard_list, list) {
+			if (idx < start || !linecard->ops->info_get) {
+				idx++;
+				continue;
+			}
+			mutex_lock(&linecard->state_lock);
+			err = devlink_nl_linecard_info_fill(msg, devlink, linecard,
+							    DEVLINK_CMD_LINECARD_INFO_GET,
+							    NETLINK_CB(cb->skb).portid,
+							    cb->nlh->nlmsg_seq,
+							    NLM_F_MULTI,
+							    cb->extack);
+			mutex_unlock(&linecard->state_lock);
+			if (err) {
+				mutex_unlock(&devlink->linecards_lock);
+				devlink_put(devlink);
+				goto out;
+			}
+			idx++;
+		}
+		mutex_unlock(&devlink->linecards_lock);
+retry:
+		devlink_put(devlink);
+	}
+out:
+	mutex_unlock(&devlink_mutex);
+
+	if (err != -EMSGSIZE)
+		return err;
+
+	cb->args[0] = idx;
+	return msg->len;
+}
+
 static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink,
 			      struct devlink_sb *devlink_sb,
 			      enum devlink_command cmd, u32 portid,
@@ -6416,10 +6535,6 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	return err;
 }
 
-struct devlink_info_req {
-	struct sk_buff *msg;
-};
-
 int devlink_info_driver_name_put(struct devlink_info_req *req, const char *name)
 {
 	return nla_put_string(req->msg, DEVLINK_ATTR_INFO_DRIVER_NAME, name);
@@ -9139,6 +9254,13 @@ static const struct genl_small_ops devlink_nl_ops[] = {
 		.flags = GENL_ADMIN_PERM,
 		.internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
 	},
+	{
+		.cmd = DEVLINK_CMD_LINECARD_INFO_GET,
+		.doit = devlink_nl_cmd_linecard_info_get_doit,
+		.dumpit = devlink_nl_cmd_linecard_info_get_dumpit,
+		.internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
+		/* can be retrieved by unprivileged users */
+	},
 	{
 		.cmd = DEVLINK_CMD_SB_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-- 
2.33.1


  parent reply	other threads:[~2022-04-25  3:46 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25  3:44 [PATCH net-next 00/11] mlxsw: extend line card model by devices and info Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 01/11] devlink: introduce line card devices support Ido Schimmel
2022-04-25  3:44 ` Ido Schimmel [this message]
2022-04-25  3:44 ` [PATCH net-next 03/11] devlink: introduce line card device info infrastructure Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 04/11] mlxsw: reg: Extend MDDQ by device_info Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 05/11] mlxsw: core_linecards: Probe provisioned line cards for devices and attach them Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 06/11] selftests: mlxsw: Check devices on provisioned line card Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 07/11] mlxsw: core_linecards: Expose HW revision and INI version Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 08/11] selftests: mlxsw: Check line card info on provisioned line card Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 09/11] mlxsw: reg: Extend MDDQ device_info by FW version fields Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 10/11] mlxsw: core_linecards: Expose device FW version over device info Ido Schimmel
2022-04-25  3:44 ` [PATCH net-next 11/11] selftests: mlxsw: Check device info on activated line card Ido Schimmel
2022-04-25  9:50 ` [PATCH net-next 00/11] mlxsw: extend line card model by devices and info patchwork-bot+netdevbpf
2022-04-25 16:00 ` Jakub Kicinski
2022-04-25 19:39   ` Ido Schimmel
2022-04-25 19:52     ` Jakub Kicinski
2022-04-26  6:57       ` Jiri Pirko
2022-04-26 12:11         ` Andrew Lunn
2022-04-26 12:36           ` Jiri Pirko
2022-04-26 12:41         ` Jakub Kicinski
2022-04-26 14:00           ` Jiri Pirko
2022-04-26 14:51             ` Jakub Kicinski
2022-04-27  7:35               ` Jiri Pirko
2022-04-27 14:14                 ` Jakub Kicinski
2022-04-29 11:51                   ` Jiri Pirko
2022-04-29 18:45                     ` Jakub Kicinski
2022-04-29 19:29                       ` Jiri Pirko
2022-04-29 22:38                         ` Jakub Kicinski
2022-04-30  6:27                           ` Jiri Pirko
2022-05-02 14:39                             ` Jakub Kicinski
2022-05-23  9:42                               ` Jiri Pirko
2022-05-23 17:56                                 ` Jakub Kicinski
2022-05-24  6:46                                   ` Jiri Pirko
2022-05-24 14:31                                     ` Jiri Pirko
2022-05-24 18:00                                       ` Jakub Kicinski
2022-05-25  6:20                                         ` Jiri Pirko
2022-05-25 15:50                                           ` Jakub Kicinski
2022-05-26  9:05                                             ` Jiri Pirko
2022-05-26 10:47                                               ` Jiri Pirko
2022-05-26 11:45                                             ` Jiri Pirko
2022-05-26 17:35                                               ` Jakub Kicinski
2022-05-27  7:27                                                 ` Jiri Pirko
2022-05-28  0:10                                                   ` Jakub Kicinski
2022-05-28  9:09                                                     ` Jiri Pirko
2022-05-28 19:02                                                       ` Jakub Kicinski
2022-05-29  9:23                                                         ` Jiri Pirko
2022-05-30 19:54                                                           ` Jakub Kicinski
2022-05-31  7:11                                                             ` Jiri Pirko
2022-05-31 15:05                                                               ` Jakub Kicinski
2022-05-31 15:51                                                                 ` Jiri Pirko
2022-05-31 16:08                                                                   ` Jakub Kicinski
2022-05-31 19:34                                                                     ` Jiri Pirko
2022-05-31 22:41                                                                       ` Jakub Kicinski
2022-06-01  7:35                                                                         ` Jiri Pirko
2022-05-28 15:58                                       ` David Ahern
2022-05-29  9:24                                         ` Jiri Pirko
2022-05-31  2:11                                           ` David Ahern
2022-05-31  7:05                                             ` Jiri Pirko
2022-04-26 15:24             ` Andrew Lunn
2022-04-27  7:37               ` Jiri Pirko
2022-04-26  6:47     ` Jiri Pirko
2022-04-26 12:27       ` Andrew Lunn
2022-04-26 12:41         ` Jiri Pirko
2022-04-26 13:45           ` Andrew Lunn
2022-04-26 14:05             ` Jiri Pirko
2022-04-26 15:36               ` Andrew Lunn

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=20220425034431.3161260-3-idosch@nvidia.com \
    --to=idosch@nvidia.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=jiri@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.