Commit eb0e9fa2 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

net: devlink: add unlocked variants of devlink_region_create/destroy() functions

Add unlocked variants of devlink_region_create/destroy() functions
to be used in drivers called-in with devlink->lock held.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Reviewed-by: default avatarMoshe Shemesh <moshe@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 72a4c8c9
...@@ -1676,6 +1676,10 @@ int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, ...@@ -1676,6 +1676,10 @@ int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
union devlink_param_value init_val); union devlink_param_value init_val);
void devlink_param_value_changed(struct devlink *devlink, u32 param_id); void devlink_param_value_changed(struct devlink *devlink, u32 param_id);
struct devlink_region *devl_region_create(struct devlink *devlink,
const struct devlink_region_ops *ops,
u32 region_max_snapshots,
u64 region_size);
struct devlink_region * struct devlink_region *
devlink_region_create(struct devlink *devlink, devlink_region_create(struct devlink *devlink,
const struct devlink_region_ops *ops, const struct devlink_region_ops *ops,
...@@ -1684,6 +1688,7 @@ struct devlink_region * ...@@ -1684,6 +1688,7 @@ struct devlink_region *
devlink_port_region_create(struct devlink_port *port, devlink_port_region_create(struct devlink_port *port,
const struct devlink_port_region_ops *ops, const struct devlink_port_region_ops *ops,
u32 region_max_snapshots, u64 region_size); u32 region_max_snapshots, u64 region_size);
void devl_region_destroy(struct devlink_region *region);
void devlink_region_destroy(struct devlink_region *region); void devlink_region_destroy(struct devlink_region *region);
void devlink_port_region_destroy(struct devlink_region *region); void devlink_port_region_destroy(struct devlink_region *region);
......
...@@ -11192,36 +11192,31 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id) ...@@ -11192,36 +11192,31 @@ void devlink_param_value_changed(struct devlink *devlink, u32 param_id)
EXPORT_SYMBOL_GPL(devlink_param_value_changed); EXPORT_SYMBOL_GPL(devlink_param_value_changed);
/** /**
* devlink_region_create - create a new address region * devl_region_create - create a new address region
* *
* @devlink: devlink * @devlink: devlink
* @ops: region operations and name * @ops: region operations and name
* @region_max_snapshots: Maximum supported number of snapshots for region * @region_max_snapshots: Maximum supported number of snapshots for region
* @region_size: size of region * @region_size: size of region
*/ */
struct devlink_region * struct devlink_region *devl_region_create(struct devlink *devlink,
devlink_region_create(struct devlink *devlink, const struct devlink_region_ops *ops,
const struct devlink_region_ops *ops, u32 region_max_snapshots,
u32 region_max_snapshots, u64 region_size) u64 region_size)
{ {
struct devlink_region *region; struct devlink_region *region;
int err = 0;
devl_assert_locked(devlink);
if (WARN_ON(!ops) || WARN_ON(!ops->destructor)) if (WARN_ON(!ops) || WARN_ON(!ops->destructor))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
devl_lock(devlink); if (devlink_region_get_by_name(devlink, ops->name))
return ERR_PTR(-EEXIST);
if (devlink_region_get_by_name(devlink, ops->name)) {
err = -EEXIST;
goto unlock;
}
region = kzalloc(sizeof(*region), GFP_KERNEL); region = kzalloc(sizeof(*region), GFP_KERNEL);
if (!region) { if (!region)
err = -ENOMEM; return ERR_PTR(-ENOMEM);
goto unlock;
}
region->devlink = devlink; region->devlink = devlink;
region->max_snapshots = region_max_snapshots; region->max_snapshots = region_max_snapshots;
...@@ -11231,12 +11226,32 @@ devlink_region_create(struct devlink *devlink, ...@@ -11231,12 +11226,32 @@ devlink_region_create(struct devlink *devlink,
list_add_tail(&region->list, &devlink->region_list); list_add_tail(&region->list, &devlink->region_list);
devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW); devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_NEW);
devl_unlock(devlink);
return region; return region;
}
EXPORT_SYMBOL_GPL(devl_region_create);
unlock: /**
* devlink_region_create - create a new address region
*
* @devlink: devlink
* @ops: region operations and name
* @region_max_snapshots: Maximum supported number of snapshots for region
* @region_size: size of region
*
* Context: Takes and release devlink->lock <mutex>.
*/
struct devlink_region *
devlink_region_create(struct devlink *devlink,
const struct devlink_region_ops *ops,
u32 region_max_snapshots, u64 region_size)
{
struct devlink_region *region;
devl_lock(devlink);
region = devl_region_create(devlink, ops, region_max_snapshots,
region_size);
devl_unlock(devlink); devl_unlock(devlink);
return ERR_PTR(err); return region;
} }
EXPORT_SYMBOL_GPL(devlink_region_create); EXPORT_SYMBOL_GPL(devlink_region_create);
...@@ -11247,6 +11262,8 @@ EXPORT_SYMBOL_GPL(devlink_region_create); ...@@ -11247,6 +11262,8 @@ EXPORT_SYMBOL_GPL(devlink_region_create);
* @ops: region operations and name * @ops: region operations and name
* @region_max_snapshots: Maximum supported number of snapshots for region * @region_max_snapshots: Maximum supported number of snapshots for region
* @region_size: size of region * @region_size: size of region
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
struct devlink_region * struct devlink_region *
devlink_port_region_create(struct devlink_port *port, devlink_port_region_create(struct devlink_port *port,
...@@ -11292,16 +11309,16 @@ devlink_port_region_create(struct devlink_port *port, ...@@ -11292,16 +11309,16 @@ devlink_port_region_create(struct devlink_port *port,
EXPORT_SYMBOL_GPL(devlink_port_region_create); EXPORT_SYMBOL_GPL(devlink_port_region_create);
/** /**
* devlink_region_destroy - destroy address region * devl_region_destroy - destroy address region
* *
* @region: devlink region to destroy * @region: devlink region to destroy
*/ */
void devlink_region_destroy(struct devlink_region *region) void devl_region_destroy(struct devlink_region *region)
{ {
struct devlink *devlink = region->devlink; struct devlink *devlink = region->devlink;
struct devlink_snapshot *snapshot, *ts; struct devlink_snapshot *snapshot, *ts;
devl_lock(devlink); devl_assert_locked(devlink);
/* Free all snapshots of region */ /* Free all snapshots of region */
list_for_each_entry_safe(snapshot, ts, &region->snapshot_list, list) list_for_each_entry_safe(snapshot, ts, &region->snapshot_list, list)
...@@ -11310,9 +11327,25 @@ void devlink_region_destroy(struct devlink_region *region) ...@@ -11310,9 +11327,25 @@ void devlink_region_destroy(struct devlink_region *region)
list_del(&region->list); list_del(&region->list);
devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_DEL); devlink_nl_region_notify(region, NULL, DEVLINK_CMD_REGION_DEL);
devl_unlock(devlink);
kfree(region); kfree(region);
} }
EXPORT_SYMBOL_GPL(devl_region_destroy);
/**
* devlink_region_destroy - destroy address region
*
* @region: devlink region to destroy
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_region_destroy(struct devlink_region *region)
{
struct devlink *devlink = region->devlink;
devl_lock(devlink);
devl_region_destroy(region);
devl_unlock(devlink);
}
EXPORT_SYMBOL_GPL(devlink_region_destroy); EXPORT_SYMBOL_GPL(devlink_region_destroy);
/** /**
......
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