Skip to contentSkip to conversation

devlink: expose nested devlink for a line card object

PATCH Applied Jiri Pirko 3 participants 3 messages Aug 9, 2022 – Aug 14, 2022

Subsystems (2)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 devlink: expose nested devlink for a line card object

From: Jiri Pirko <[email protected]>

If line card object contains a nested devlink, expose it.

Example:

$ devlink lc show pci/0000:01:00.0 lc 1
pci/0000:01:00.0:
  lc 1 state active type 16x100G nested_devlink auxiliary/mlxsw_core.lc.0
    supported_types:
      16x100G
$ devlink dev show auxiliary/mlxsw_core.lc.0
auxiliary/mlxsw_core.lc.0
---
 devlink/devlink.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
devlink/devlink.c +23 -0
index 21f26246f91b..1ccb669c423b 100644
@@ -703,6 +703,7 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
 	[DEVLINK_ATTR_LINECARD_STATE] = MNL_TYPE_U8,
 	[DEVLINK_ATTR_LINECARD_TYPE] = MNL_TYPE_STRING,
 	[DEVLINK_ATTR_LINECARD_SUPPORTED_TYPES] = MNL_TYPE_NESTED,
+	[DEVLINK_ATTR_NESTED_DEVLINK] = MNL_TYPE_NESTED,
 	[DEVLINK_ATTR_SELFTESTS] = MNL_TYPE_NESTED,
 };
 
@@ -2423,6 +2424,25 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name,
 	       !cmp_arr_last_handle(dl, bus_name, dev_name);
 }
 
+static void pr_out_nested_handle(struct nlattr *nla_nested_dl)
+{
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+	char buf[64];
+	int err;
+
+	err = mnl_attr_parse_nested(nla_nested_dl, attr_cb, tb);
+	if (err != MNL_CB_OK)
+		return;
+
+	if (!tb[DEVLINK_ATTR_BUS_NAME] ||
+	    !tb[DEVLINK_ATTR_DEV_NAME])
+		return;
+
+	sprintf(buf, "%s/%s", mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]),
+		mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]));
+	print_string(PRINT_ANY, "nested_devlink", " nested_devlink %s", buf);
+}
+
 static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb,
 				  bool content, bool array)
 {
@@ -5278,6 +5298,9 @@ static void pr_out_linecard(struct dl *dl, struct nlattr **tb)
 	if (tb[DEVLINK_ATTR_LINECARD_TYPE])
 		print_string(PRINT_ANY, "type", " type %s",
 			     mnl_attr_get_str(tb[DEVLINK_ATTR_LINECARD_TYPE]));
+	if (tb[DEVLINK_ATTR_NESTED_DEVLINK])
+		pr_out_nested_handle(tb[DEVLINK_ATTR_NESTED_DEVLINK]);
+
 	pr_out_linecard_supported_types(dl, tb);
 	pr_out_handle_end(dl);
 }
Signature · 1 line
2.35.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

If line card object contains a nested devlink, expose it.

Example:

$ devlink lc show pci/0000:01:00.0 lc 1
pci/0000:01:00.0:
  lc 1 state active type 16x100G nested_devlink auxiliary/mlxsw_core.lc.0
    supported_types:
      16x100G
$ devlink dev show auxiliary/mlxsw_core.lc.0
auxiliary/mlxsw_core.lc.0
Quoted 1 line
#2 lore raw
In reply to Jiri Pirko
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 14 lines · On Tue, 9 Aug 2022 15:17:30 +0200 you wrote:

From: Jiri Pirko <[email protected]>

If line card object contains a nested devlink, expose it.

Example:

$ devlink lc show pci/0000:01:00.0 lc 1
pci/0000:01:00.0:
  lc 1 state active type 16x100G nested_devlink auxiliary/mlxsw_core.lc.0
    supported_types:
      16x100G
$ devlink dev show auxiliary/mlxsw_core.lc.0
auxiliary/mlxsw_core.lc.0
Quoted 1 line

[...]

Here is the summary with links:
- [iproute2-next] devlink: expose nested devlink for a line card object

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=700a8991f05e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html