Commit c5e1bf8a authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

devlink: introduce possibility to expose info about nested devlinks

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: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9473bc01
...@@ -1921,6 +1921,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter, ...@@ -1921,6 +1921,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
void void
devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter); 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); bool devlink_is_reload_failed(const struct devlink *devlink);
void devlink_remote_reload_actions_performed(struct devlink *devlink, void devlink_remote_reload_actions_performed(struct devlink *devlink,
enum devlink_reload_limit limit, enum devlink_reload_limit limit,
......
...@@ -430,6 +430,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, ...@@ -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->ports, XA_FLAGS_ALLOC);
xa_init_flags(&devlink->params, XA_FLAGS_ALLOC); xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
xa_init_flags(&devlink->snapshot_ids, 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); write_pnet(&devlink->_net, net);
INIT_LIST_HEAD(&devlink->rate_list); INIT_LIST_HEAD(&devlink->rate_list);
INIT_LIST_HEAD(&devlink->linecard_list); INIT_LIST_HEAD(&devlink->linecard_list);
...@@ -476,6 +477,7 @@ void devlink_free(struct devlink *devlink) ...@@ -476,6 +477,7 @@ void devlink_free(struct devlink *devlink)
WARN_ON(!list_empty(&devlink->linecard_list)); WARN_ON(!list_empty(&devlink->linecard_list));
WARN_ON(!xa_empty(&devlink->ports)); WARN_ON(!xa_empty(&devlink->ports));
xa_destroy(&devlink->nested_rels);
xa_destroy(&devlink->snapshot_ids); xa_destroy(&devlink->snapshot_ids);
xa_destroy(&devlink->params); xa_destroy(&devlink->params);
xa_destroy(&devlink->ports); xa_destroy(&devlink->ports);
......
...@@ -138,6 +138,23 @@ devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_r ...@@ -138,6 +138,23 @@ devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_r
return -EMSGSIZE; 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, static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
enum devlink_command cmd, u32 portid, enum devlink_command cmd, u32 portid,
u32 seq, int flags) u32 seq, int flags)
...@@ -164,6 +181,10 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink, ...@@ -164,6 +181,10 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
goto dev_stats_nest_cancel; goto dev_stats_nest_cancel;
nla_nest_end(msg, dev_stats); nla_nest_end(msg, dev_stats);
if (devlink_nl_nested_fill(msg, devlink))
goto nla_put_failure;
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
return 0; return 0;
...@@ -230,6 +251,34 @@ int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb) ...@@ -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); 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) void devlink_notify_register(struct devlink *devlink)
{ {
devlink_notify(devlink, DEVLINK_CMD_NEW); devlink_notify(devlink, DEVLINK_CMD_NEW);
......
...@@ -58,6 +58,7 @@ struct devlink { ...@@ -58,6 +58,7 @@ struct devlink {
refcount_t refcount; refcount_t refcount;
struct rcu_work rwork; struct rcu_work rwork;
struct devlink_rel *rel; struct devlink_rel *rel;
struct xarray nested_rels;
char priv[] __aligned(NETDEV_ALIGN); char priv[] __aligned(NETDEV_ALIGN);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment