devlink: introduce possibility to expose info about nested devlinks
authorJiri Pirko <jiri@nvidia.com>
Wed, 13 Sep 2023 07:12:42 +0000 (09:12 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 17 Sep 2023 13:01:47 +0000 (14:01 +0100)
In mlx5, there is a devlink instance created for PCI device. Also, one
separate devlink instance is created for auxiliary device that
represents the netdev of uplink port. This relation is currently
invisible to the devlink user.

Benefit from the rel infrastructure and allow for nested devlink
instance to set the relationship for the nested-in devlink instance.
Note that there may be many nested instances, therefore use xarray to
hold the list of rel_indexes for individual nested instances.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/devlink.h
net/devlink/core.c
net/devlink/dev.c
net/devlink/devl_internal.h

index 0dfcd7d..fad8e36 100644 (file)
@@ -1921,6 +1921,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
 void
 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
 
+int devl_nested_devlink_set(struct devlink *devlink,
+                           struct devlink *nested_devlink);
 bool devlink_is_reload_failed(const struct devlink *devlink);
 void devlink_remote_reload_actions_performed(struct devlink *devlink,
                                             enum devlink_reload_limit limit,
index 2a98ff9..bcbbb95 100644 (file)
@@ -430,6 +430,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
        xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC);
        xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
        xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC);
+       xa_init_flags(&devlink->nested_rels, XA_FLAGS_ALLOC);
        write_pnet(&devlink->_net, net);
        INIT_LIST_HEAD(&devlink->rate_list);
        INIT_LIST_HEAD(&devlink->linecard_list);
@@ -476,6 +477,7 @@ void devlink_free(struct devlink *devlink)
        WARN_ON(!list_empty(&devlink->linecard_list));
        WARN_ON(!xa_empty(&devlink->ports));
 
+       xa_destroy(&devlink->nested_rels);
        xa_destroy(&devlink->snapshot_ids);
        xa_destroy(&devlink->params);
        xa_destroy(&devlink->ports);
index 3ae26d9..dc8039c 100644 (file)
@@ -138,6 +138,23 @@ nla_put_failure:
        return -EMSGSIZE;
 }
 
+static int devlink_nl_nested_fill(struct sk_buff *msg, struct devlink *devlink)
+{
+       unsigned long rel_index;
+       void *unused;
+       int err;
+
+       xa_for_each(&devlink->nested_rels, rel_index, unused) {
+               err = devlink_rel_devlink_handle_put(msg, devlink,
+                                                    rel_index,
+                                                    DEVLINK_ATTR_NESTED_DEVLINK,
+                                                    NULL);
+               if (err)
+                       return err;
+       }
+       return 0;
+}
+
 static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
                           enum devlink_command cmd, u32 portid,
                           u32 seq, int flags)
@@ -164,6 +181,10 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
                goto dev_stats_nest_cancel;
 
        nla_nest_end(msg, dev_stats);
+
+       if (devlink_nl_nested_fill(msg, devlink))
+               goto nla_put_failure;
+
        genlmsg_end(msg, hdr);
        return 0;
 
@@ -230,6 +251,34 @@ int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
        return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one);
 }
 
+static void devlink_rel_notify_cb(struct devlink *devlink, u32 obj_index)
+{
+       devlink_notify(devlink, DEVLINK_CMD_NEW);
+}
+
+static void devlink_rel_cleanup_cb(struct devlink *devlink, u32 obj_index,
+                                  u32 rel_index)
+{
+       xa_erase(&devlink->nested_rels, rel_index);
+}
+
+int devl_nested_devlink_set(struct devlink *devlink,
+                           struct devlink *nested_devlink)
+{
+       u32 rel_index;
+       int err;
+
+       err = devlink_rel_nested_in_add(&rel_index, devlink->index, 0,
+                                       devlink_rel_notify_cb,
+                                       devlink_rel_cleanup_cb,
+                                       nested_devlink);
+       if (err)
+               return err;
+       return xa_insert(&devlink->nested_rels, rel_index,
+                        xa_mk_value(0), GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(devl_nested_devlink_set);
+
 void devlink_notify_register(struct devlink *devlink)
 {
        devlink_notify(devlink, DEVLINK_CMD_NEW);
index 4cb534a..741d1bf 100644 (file)
@@ -58,6 +58,7 @@ struct devlink {
        refcount_t refcount;
        struct rcu_work rwork;
        struct devlink_rel *rel;
+       struct xarray nested_rels;
        char priv[] __aligned(NETDEV_ALIGN);
 };