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

net: devlink: add unlocked variants of devlink_resource*() functions

Add unlocked variants of devlink_resource*() functions to be used
in drivers called-in with devlink->lock held.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 852e85a7
...@@ -1608,23 +1608,40 @@ extern struct devlink_dpipe_header devlink_dpipe_header_ethernet; ...@@ -1608,23 +1608,40 @@ extern struct devlink_dpipe_header devlink_dpipe_header_ethernet;
extern struct devlink_dpipe_header devlink_dpipe_header_ipv4; extern struct devlink_dpipe_header devlink_dpipe_header_ipv4;
extern struct devlink_dpipe_header devlink_dpipe_header_ipv6; extern struct devlink_dpipe_header devlink_dpipe_header_ipv6;
int devl_resource_register(struct devlink *devlink,
const char *resource_name,
u64 resource_size,
u64 resource_id,
u64 parent_resource_id,
const struct devlink_resource_size_params *size_params);
int devlink_resource_register(struct devlink *devlink, int devlink_resource_register(struct devlink *devlink,
const char *resource_name, const char *resource_name,
u64 resource_size, u64 resource_size,
u64 resource_id, u64 resource_id,
u64 parent_resource_id, u64 parent_resource_id,
const struct devlink_resource_size_params *size_params); const struct devlink_resource_size_params *size_params);
void devl_resources_unregister(struct devlink *devlink);
void devlink_resources_unregister(struct devlink *devlink); void devlink_resources_unregister(struct devlink *devlink);
int devl_resource_size_get(struct devlink *devlink,
u64 resource_id,
u64 *p_resource_size);
int devlink_resource_size_get(struct devlink *devlink, int devlink_resource_size_get(struct devlink *devlink,
u64 resource_id, u64 resource_id,
u64 *p_resource_size); u64 *p_resource_size);
int devlink_dpipe_table_resource_set(struct devlink *devlink, int devlink_dpipe_table_resource_set(struct devlink *devlink,
const char *table_name, u64 resource_id, const char *table_name, u64 resource_id,
u64 resource_units); u64 resource_units);
void devl_resource_occ_get_register(struct devlink *devlink,
u64 resource_id,
devlink_resource_occ_get_t *occ_get,
void *occ_get_priv);
void devlink_resource_occ_get_register(struct devlink *devlink, void devlink_resource_occ_get_register(struct devlink *devlink,
u64 resource_id, u64 resource_id,
devlink_resource_occ_get_t *occ_get, devlink_resource_occ_get_t *occ_get,
void *occ_get_priv); void *occ_get_priv);
void devl_resource_occ_get_unregister(struct devlink *devlink,
u64 resource_id);
void devlink_resource_occ_get_unregister(struct devlink *devlink, void devlink_resource_occ_get_unregister(struct devlink *devlink,
u64 resource_id); u64 resource_id);
int devlink_params_register(struct devlink *devlink, int devlink_params_register(struct devlink *devlink,
......
...@@ -10555,45 +10555,41 @@ void devlink_dpipe_table_unregister(struct devlink *devlink, ...@@ -10555,45 +10555,41 @@ void devlink_dpipe_table_unregister(struct devlink *devlink,
EXPORT_SYMBOL_GPL(devlink_dpipe_table_unregister); EXPORT_SYMBOL_GPL(devlink_dpipe_table_unregister);
/** /**
* devlink_resource_register - devlink resource register * devl_resource_register - devlink resource register
* *
* @devlink: devlink * @devlink: devlink
* @resource_name: resource's name * @resource_name: resource's name
* @resource_size: resource's size * @resource_size: resource's size
* @resource_id: resource's id * @resource_id: resource's id
* @parent_resource_id: resource's parent id * @parent_resource_id: resource's parent id
* @size_params: size parameters * @size_params: size parameters
* *
* Generic resources should reuse the same names across drivers. * Generic resources should reuse the same names across drivers.
* Please see the generic resources list at: * Please see the generic resources list at:
* Documentation/networking/devlink/devlink-resource.rst * Documentation/networking/devlink/devlink-resource.rst
*/ */
int devlink_resource_register(struct devlink *devlink, int devl_resource_register(struct devlink *devlink,
const char *resource_name, const char *resource_name,
u64 resource_size, u64 resource_size,
u64 resource_id, u64 resource_id,
u64 parent_resource_id, u64 parent_resource_id,
const struct devlink_resource_size_params *size_params) const struct devlink_resource_size_params *size_params)
{ {
struct devlink_resource *resource; struct devlink_resource *resource;
struct list_head *resource_list; struct list_head *resource_list;
bool top_hierarchy; bool top_hierarchy;
int err = 0;
lockdep_assert_held(&devlink->lock);
top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP; top_hierarchy = parent_resource_id == DEVLINK_RESOURCE_ID_PARENT_TOP;
devl_lock(devlink);
resource = devlink_resource_find(devlink, NULL, resource_id); resource = devlink_resource_find(devlink, NULL, resource_id);
if (resource) { if (resource)
err = -EINVAL; return -EINVAL;
goto out;
}
resource = kzalloc(sizeof(*resource), GFP_KERNEL); resource = kzalloc(sizeof(*resource), GFP_KERNEL);
if (!resource) { if (!resource)
err = -ENOMEM; return -ENOMEM;
goto out;
}
if (top_hierarchy) { if (top_hierarchy) {
resource_list = &devlink->resource_list; resource_list = &devlink->resource_list;
...@@ -10607,8 +10603,7 @@ int devlink_resource_register(struct devlink *devlink, ...@@ -10607,8 +10603,7 @@ int devlink_resource_register(struct devlink *devlink,
resource->parent = parent_resource; resource->parent = parent_resource;
} else { } else {
kfree(resource); kfree(resource);
err = -EINVAL; return -EINVAL;
goto out;
} }
} }
...@@ -10621,7 +10616,39 @@ int devlink_resource_register(struct devlink *devlink, ...@@ -10621,7 +10616,39 @@ int devlink_resource_register(struct devlink *devlink,
sizeof(resource->size_params)); sizeof(resource->size_params));
INIT_LIST_HEAD(&resource->resource_list); INIT_LIST_HEAD(&resource->resource_list);
list_add_tail(&resource->list, resource_list); list_add_tail(&resource->list, resource_list);
out:
return 0;
}
EXPORT_SYMBOL_GPL(devl_resource_register);
/**
* devlink_resource_register - devlink resource register
*
* @devlink: devlink
* @resource_name: resource's name
* @resource_size: resource's size
* @resource_id: resource's id
* @parent_resource_id: resource's parent id
* @size_params: size parameters
*
* Generic resources should reuse the same names across drivers.
* Please see the generic resources list at:
* Documentation/networking/devlink/devlink-resource.rst
*
* Context: Takes and release devlink->lock <mutex>.
*/
int devlink_resource_register(struct devlink *devlink,
const char *resource_name,
u64 resource_size,
u64 resource_id,
u64 parent_resource_id,
const struct devlink_resource_size_params *size_params)
{
int err;
devl_lock(devlink);
err = devl_resource_register(devlink, resource_name, resource_size,
resource_id, parent_resource_id, size_params);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
...@@ -10641,15 +10668,15 @@ static void devlink_resource_unregister(struct devlink *devlink, ...@@ -10641,15 +10668,15 @@ static void devlink_resource_unregister(struct devlink *devlink,
} }
/** /**
* devlink_resources_unregister - free all resources * devl_resources_unregister - free all resources
* *
* @devlink: devlink * @devlink: devlink
*/ */
void devlink_resources_unregister(struct devlink *devlink) void devl_resources_unregister(struct devlink *devlink)
{ {
struct devlink_resource *tmp, *child_resource; struct devlink_resource *tmp, *child_resource;
devl_lock(devlink); lockdep_assert_held(&devlink->lock);
list_for_each_entry_safe(child_resource, tmp, &devlink->resource_list, list_for_each_entry_safe(child_resource, tmp, &devlink->resource_list,
list) { list) {
...@@ -10657,34 +10684,65 @@ void devlink_resources_unregister(struct devlink *devlink) ...@@ -10657,34 +10684,65 @@ void devlink_resources_unregister(struct devlink *devlink)
list_del(&child_resource->list); list_del(&child_resource->list);
kfree(child_resource); kfree(child_resource);
} }
}
EXPORT_SYMBOL_GPL(devl_resources_unregister);
/**
* devlink_resources_unregister - free all resources
*
* @devlink: devlink
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_resources_unregister(struct devlink *devlink)
{
devl_lock(devlink);
devl_resources_unregister(devlink);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_resources_unregister); EXPORT_SYMBOL_GPL(devlink_resources_unregister);
/**
* devl_resource_size_get - get and update size
*
* @devlink: devlink
* @resource_id: the requested resource id
* @p_resource_size: ptr to update
*/
int devl_resource_size_get(struct devlink *devlink,
u64 resource_id,
u64 *p_resource_size)
{
struct devlink_resource *resource;
lockdep_assert_held(&devlink->lock);
resource = devlink_resource_find(devlink, NULL, resource_id);
if (!resource)
return -EINVAL;
*p_resource_size = resource->size_new;
resource->size = resource->size_new;
return 0;
}
EXPORT_SYMBOL_GPL(devl_resource_size_get);
/** /**
* devlink_resource_size_get - get and update size * devlink_resource_size_get - get and update size
* *
* @devlink: devlink * @devlink: devlink
* @resource_id: the requested resource id * @resource_id: the requested resource id
* @p_resource_size: ptr to update * @p_resource_size: ptr to update
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
int devlink_resource_size_get(struct devlink *devlink, int devlink_resource_size_get(struct devlink *devlink,
u64 resource_id, u64 resource_id,
u64 *p_resource_size) u64 *p_resource_size)
{ {
struct devlink_resource *resource; int err;
int err = 0;
devl_lock(devlink); devl_lock(devlink);
resource = devlink_resource_find(devlink, NULL, resource_id); err = devl_resource_size_get(devlink, resource_id, p_resource_size);
if (!resource) {
err = -EINVAL;
goto out;
}
*p_resource_size = resource->size_new;
resource->size = resource->size_new;
out:
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
...@@ -10721,6 +10779,33 @@ int devlink_dpipe_table_resource_set(struct devlink *devlink, ...@@ -10721,6 +10779,33 @@ int devlink_dpipe_table_resource_set(struct devlink *devlink,
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_table_resource_set); EXPORT_SYMBOL_GPL(devlink_dpipe_table_resource_set);
/**
* devl_resource_occ_get_register - register occupancy getter
*
* @devlink: devlink
* @resource_id: resource id
* @occ_get: occupancy getter callback
* @occ_get_priv: occupancy getter callback priv
*/
void devl_resource_occ_get_register(struct devlink *devlink,
u64 resource_id,
devlink_resource_occ_get_t *occ_get,
void *occ_get_priv)
{
struct devlink_resource *resource;
lockdep_assert_held(&devlink->lock);
resource = devlink_resource_find(devlink, NULL, resource_id);
if (WARN_ON(!resource))
return;
WARN_ON(resource->occ_get);
resource->occ_get = occ_get;
resource->occ_get_priv = occ_get_priv;
}
EXPORT_SYMBOL_GPL(devl_resource_occ_get_register);
/** /**
* devlink_resource_occ_get_register - register occupancy getter * devlink_resource_occ_get_register - register occupancy getter
* *
...@@ -10728,47 +10813,57 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_resource_set); ...@@ -10728,47 +10813,57 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_resource_set);
* @resource_id: resource id * @resource_id: resource id
* @occ_get: occupancy getter callback * @occ_get: occupancy getter callback
* @occ_get_priv: occupancy getter callback priv * @occ_get_priv: occupancy getter callback priv
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
void devlink_resource_occ_get_register(struct devlink *devlink, void devlink_resource_occ_get_register(struct devlink *devlink,
u64 resource_id, u64 resource_id,
devlink_resource_occ_get_t *occ_get, devlink_resource_occ_get_t *occ_get,
void *occ_get_priv) void *occ_get_priv)
{ {
struct devlink_resource *resource;
devl_lock(devlink); devl_lock(devlink);
resource = devlink_resource_find(devlink, NULL, resource_id); devl_resource_occ_get_register(devlink, resource_id,
if (WARN_ON(!resource)) occ_get, occ_get_priv);
goto out;
WARN_ON(resource->occ_get);
resource->occ_get = occ_get;
resource->occ_get_priv = occ_get_priv;
out:
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_resource_occ_get_register); EXPORT_SYMBOL_GPL(devlink_resource_occ_get_register);
/** /**
* devlink_resource_occ_get_unregister - unregister occupancy getter * devl_resource_occ_get_unregister - unregister occupancy getter
* *
* @devlink: devlink * @devlink: devlink
* @resource_id: resource id * @resource_id: resource id
*/ */
void devlink_resource_occ_get_unregister(struct devlink *devlink, void devl_resource_occ_get_unregister(struct devlink *devlink,
u64 resource_id) u64 resource_id)
{ {
struct devlink_resource *resource; struct devlink_resource *resource;
devl_lock(devlink); lockdep_assert_held(&devlink->lock);
resource = devlink_resource_find(devlink, NULL, resource_id); resource = devlink_resource_find(devlink, NULL, resource_id);
if (WARN_ON(!resource)) if (WARN_ON(!resource))
goto out; return;
WARN_ON(!resource->occ_get); WARN_ON(!resource->occ_get);
resource->occ_get = NULL; resource->occ_get = NULL;
resource->occ_get_priv = NULL; resource->occ_get_priv = NULL;
out: }
EXPORT_SYMBOL_GPL(devl_resource_occ_get_unregister);
/**
* devlink_resource_occ_get_unregister - unregister occupancy getter
*
* @devlink: devlink
* @resource_id: resource id
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_resource_occ_get_unregister(struct devlink *devlink,
u64 resource_id)
{
devl_lock(devlink);
devl_resource_occ_get_unregister(devlink, resource_id);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister); EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister);
......
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