summaryrefslogtreecommitdiff
path: root/net/core
diff options
context:
space:
mode:
authorLeon Romanovsky <leonro@nvidia.com>2021-10-12 16:15:24 +0300
committerJakub Kicinski <kuba@kernel.org>2021-10-12 16:29:17 -0700
commitbd032e35c568ff7cfa347aa4ddd6491e2453f00c (patch)
treeb9a808354fc8d0554fb51a658c3e6adaac07ecb6 /net/core
parentb88f7b1203bf481af58291c28957aaab09503f43 (diff)
devlink: Allow control devlink ops behavior through feature mask
Introduce new devlink call to set feature mask to control devlink behavior during device initialization phase after devlink_alloc() is already called. This allows us to set reload ops based on device property which is not known at the beginning of driver initialization. For the sake of simplicity, this API lacks any type of locking and needs to be called before devlink_register() to make sure that no parallel access to the ops is possible at this stage. Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/devlink.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 276e1e421eb4..1931caa0ce1e 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -54,6 +54,7 @@ struct devlink {
struct list_head trap_group_list;
struct list_head trap_policer_list;
const struct devlink_ops *ops;
+ u64 features;
struct xarray snapshot_ids;
struct devlink_dev_stats stats;
struct device *dev;
@@ -4032,7 +4033,7 @@ static int devlink_reload(struct devlink *devlink, struct net *dest_net,
struct net *curr_net;
int err;
- if (!devlink->reload_enabled)
+ if (!devlink->reload_enabled || !(devlink->features & DEVLINK_F_RELOAD))
return -EOPNOTSUPP;
memcpy(remote_reload_stats, devlink->stats.remote_reload_stats,
@@ -8986,6 +8987,25 @@ static bool devlink_reload_actions_valid(const struct devlink_ops *ops)
}
/**
+ * devlink_set_features - Set devlink supported features
+ *
+ * @devlink: devlink
+ * @features: devlink support features
+ *
+ * This interface allows us to set reload ops separatelly from
+ * the devlink_alloc.
+ */
+void devlink_set_features(struct devlink *devlink, u64 features)
+{
+ ASSERT_DEVLINK_NOT_REGISTERED(devlink);
+
+ WARN_ON(features & DEVLINK_F_RELOAD &&
+ !devlink_reload_supported(devlink->ops));
+ devlink->features = features;
+}
+EXPORT_SYMBOL_GPL(devlink_set_features);
+
+/**
* devlink_alloc_ns - Allocate new devlink instance resources
* in specific namespace
*
@@ -9155,7 +9175,7 @@ void devlink_unregister(struct devlink *devlink)
wait_for_completion(&devlink->comp);
mutex_lock(&devlink_mutex);
- WARN_ON(devlink_reload_supported(devlink->ops) &&
+ WARN_ON(devlink->features & DEVLINK_F_RELOAD &&
devlink->reload_enabled);
devlink_notify_unregister(devlink);
xa_clear_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);