From: Or Har-Toov <[email protected]>

When the kernel returns port-level resource messages during a
DEVLINK_CMD_RESOURCE_DUMP, display them alongside device-level
resources.

For example:

$ devlink resource show
pci/0000:03:00.0:
  name max_local_SFs size 32 unit entry dpipe_tables none
  name max_external_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.0/196608:
  name max_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.1:
  name max_local_SFs size 32 unit entry dpipe_tables none
  name max_external_SFs size 32 unit entry dpipe_tables none
pci/0000:03:00.1/262144:
  name max_SFs size 32 unit entry dpipe_tables none

Signed-off-by: Or Har-Toov <[email protected]>
Signed-off-by: Tariq Toukan <[email protected]>
---
 devlink/devlink.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 0962ffd861ad..737cfc7437f9 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -8954,18 +8954,23 @@ static void resources_dpipe_tables_fini(struct 
dpipe_ctx *dpipe_ctx,
 static void
 resources_show(struct resource_ctx *ctx, struct nlattr **tb)
 {
-       struct resources *resources = ctx->resources;
+       bool is_port = !!tb[DEVLINK_ATTR_PORT_INDEX];
        struct dpipe_ctx dpipe_ctx = {};
        struct resource *resource;
+       struct dl *dl = ctx->dl;
 
        resources_dpipe_tables_init(&dpipe_ctx, ctx, tb);
-
-       list_for_each_entry(resource, &resources->resource_list, list) {
-               pr_out_handle_start_arr(ctx->dl, tb);
+       list_for_each_entry(resource, &ctx->resources->resource_list, list) {
+               if (is_port)
+                       pr_out_port_handle_start_arr(dl, tb, false);
+               else
+                       pr_out_handle_start_arr(dl, tb);
                resource_show(resource, ctx);
-               pr_out_handle_end(ctx->dl);
+               if (is_port)
+                       pr_out_port_handle_end(dl);
+               else
+                       pr_out_handle_end(dl);
        }
-
        resources_dpipe_tables_fini(&dpipe_ctx, ctx);
 }
 
-- 
2.44.0


Reply via email to