Commit 70a2ff89 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

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

Add unlocked variants of devlink_dpipe*() 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 755cfa69
...@@ -1589,14 +1589,23 @@ int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, ...@@ -1589,14 +1589,23 @@ int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
u16 egress_tc_count); u16 egress_tc_count);
void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index); void devl_sb_unregister(struct devlink *devlink, unsigned int sb_index);
void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index); void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
int devl_dpipe_table_register(struct devlink *devlink,
const char *table_name,
struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern);
int devlink_dpipe_table_register(struct devlink *devlink, int devlink_dpipe_table_register(struct devlink *devlink,
const char *table_name, const char *table_name,
struct devlink_dpipe_table_ops *table_ops, struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern); void *priv, bool counter_control_extern);
void devl_dpipe_table_unregister(struct devlink *devlink,
const char *table_name);
void devlink_dpipe_table_unregister(struct devlink *devlink, void devlink_dpipe_table_unregister(struct devlink *devlink,
const char *table_name); const char *table_name);
void devl_dpipe_headers_register(struct devlink *devlink,
struct devlink_dpipe_headers *dpipe_headers);
void devlink_dpipe_headers_register(struct devlink *devlink, void devlink_dpipe_headers_register(struct devlink *devlink,
struct devlink_dpipe_headers *dpipe_headers); struct devlink_dpipe_headers *dpipe_headers);
void devl_dpipe_headers_unregister(struct devlink *devlink);
void devlink_dpipe_headers_unregister(struct devlink *devlink); void devlink_dpipe_headers_unregister(struct devlink *devlink);
bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
const char *table_name); const char *table_name);
...@@ -1633,6 +1642,9 @@ int devl_resource_size_get(struct devlink *devlink, ...@@ -1633,6 +1642,9 @@ int devl_resource_size_get(struct devlink *devlink,
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 devl_dpipe_table_resource_set(struct devlink *devlink,
const char *table_name, u64 resource_id,
u64 resource_units);
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);
......
...@@ -10438,6 +10438,23 @@ void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index) ...@@ -10438,6 +10438,23 @@ void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index)
} }
EXPORT_SYMBOL_GPL(devlink_sb_unregister); EXPORT_SYMBOL_GPL(devlink_sb_unregister);
/**
* devl_dpipe_headers_register - register dpipe headers
*
* @devlink: devlink
* @dpipe_headers: dpipe header array
*
* Register the headers supported by hardware.
*/
void devl_dpipe_headers_register(struct devlink *devlink,
struct devlink_dpipe_headers *dpipe_headers)
{
lockdep_assert_held(&devlink->lock);
devlink->dpipe_headers = dpipe_headers;
}
EXPORT_SYMBOL_GPL(devl_dpipe_headers_register);
/** /**
* devlink_dpipe_headers_register - register dpipe headers * devlink_dpipe_headers_register - register dpipe headers
* *
...@@ -10445,27 +10462,46 @@ EXPORT_SYMBOL_GPL(devlink_sb_unregister); ...@@ -10445,27 +10462,46 @@ EXPORT_SYMBOL_GPL(devlink_sb_unregister);
* @dpipe_headers: dpipe header array * @dpipe_headers: dpipe header array
* *
* Register the headers supported by hardware. * Register the headers supported by hardware.
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
void devlink_dpipe_headers_register(struct devlink *devlink, void devlink_dpipe_headers_register(struct devlink *devlink,
struct devlink_dpipe_headers *dpipe_headers) struct devlink_dpipe_headers *dpipe_headers)
{ {
devl_lock(devlink); devl_lock(devlink);
devlink->dpipe_headers = dpipe_headers; devl_dpipe_headers_register(devlink, dpipe_headers);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_headers_register); EXPORT_SYMBOL_GPL(devlink_dpipe_headers_register);
/**
* devl_dpipe_headers_unregister - unregister dpipe headers
*
* @devlink: devlink
*
* Unregister the headers supported by hardware.
*/
void devl_dpipe_headers_unregister(struct devlink *devlink)
{
lockdep_assert_held(&devlink->lock);
devlink->dpipe_headers = NULL;
}
EXPORT_SYMBOL_GPL(devl_dpipe_headers_unregister);
/** /**
* devlink_dpipe_headers_unregister - unregister dpipe headers * devlink_dpipe_headers_unregister - unregister dpipe headers
* *
* @devlink: devlink * @devlink: devlink
* *
* Unregister the headers supported by hardware. * Unregister the headers supported by hardware.
*
* Context: Takes and release devlink->lock <mutex>.
*/ */
void devlink_dpipe_headers_unregister(struct devlink *devlink) void devlink_dpipe_headers_unregister(struct devlink *devlink)
{ {
devl_lock(devlink); devl_lock(devlink);
devlink->dpipe_headers = NULL; devl_dpipe_headers_unregister(devlink);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_headers_unregister); EXPORT_SYMBOL_GPL(devlink_dpipe_headers_unregister);
...@@ -10502,7 +10538,7 @@ bool devlink_dpipe_table_counter_enabled(struct devlink *devlink, ...@@ -10502,7 +10538,7 @@ bool devlink_dpipe_table_counter_enabled(struct devlink *devlink,
EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled); EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
/** /**
* devlink_dpipe_table_register - register dpipe table * devl_dpipe_table_register - register dpipe table
* *
* @devlink: devlink * @devlink: devlink
* @table_name: table name * @table_name: table name
...@@ -10510,30 +10546,25 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled); ...@@ -10510,30 +10546,25 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
* @priv: priv * @priv: priv
* @counter_control_extern: external control for counters * @counter_control_extern: external control for counters
*/ */
int devlink_dpipe_table_register(struct devlink *devlink, int devl_dpipe_table_register(struct devlink *devlink,
const char *table_name, const char *table_name,
struct devlink_dpipe_table_ops *table_ops, struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern) void *priv, bool counter_control_extern)
{ {
struct devlink_dpipe_table *table; struct devlink_dpipe_table *table;
int err = 0;
lockdep_assert_held(&devlink->lock);
if (WARN_ON(!table_ops->size_get)) if (WARN_ON(!table_ops->size_get))
return -EINVAL; return -EINVAL;
devl_lock(devlink);
if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name, if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name,
devlink)) { devlink))
err = -EEXIST; return -EEXIST;
goto unlock;
}
table = kzalloc(sizeof(*table), GFP_KERNEL); table = kzalloc(sizeof(*table), GFP_KERNEL);
if (!table) { if (!table)
err = -ENOMEM; return -ENOMEM;
goto unlock;
}
table->name = table_name; table->name = table_name;
table->table_ops = table_ops; table->table_ops = table_ops;
...@@ -10541,33 +10572,72 @@ int devlink_dpipe_table_register(struct devlink *devlink, ...@@ -10541,33 +10572,72 @@ int devlink_dpipe_table_register(struct devlink *devlink,
table->counter_control_extern = counter_control_extern; table->counter_control_extern = counter_control_extern;
list_add_tail_rcu(&table->list, &devlink->dpipe_table_list); list_add_tail_rcu(&table->list, &devlink->dpipe_table_list);
unlock:
return 0;
}
EXPORT_SYMBOL_GPL(devl_dpipe_table_register);
/**
* devlink_dpipe_table_register - register dpipe table
*
* @devlink: devlink
* @table_name: table name
* @table_ops: table ops
* @priv: priv
* @counter_control_extern: external control for counters
*
* Context: Takes and release devlink->lock <mutex>.
*/
int devlink_dpipe_table_register(struct devlink *devlink,
const char *table_name,
struct devlink_dpipe_table_ops *table_ops,
void *priv, bool counter_control_extern)
{
int err;
devl_lock(devlink);
err = devl_dpipe_table_register(devlink, table_name, table_ops, priv,
counter_control_extern);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_table_register); EXPORT_SYMBOL_GPL(devlink_dpipe_table_register);
/** /**
* devlink_dpipe_table_unregister - unregister dpipe table * devl_dpipe_table_unregister - unregister dpipe table
* *
* @devlink: devlink * @devlink: devlink
* @table_name: table name * @table_name: table name
*/ */
void devlink_dpipe_table_unregister(struct devlink *devlink, void devl_dpipe_table_unregister(struct devlink *devlink,
const char *table_name) const char *table_name)
{ {
struct devlink_dpipe_table *table; struct devlink_dpipe_table *table;
devl_lock(devlink); lockdep_assert_held(&devlink->lock);
table = devlink_dpipe_table_find(&devlink->dpipe_table_list, table = devlink_dpipe_table_find(&devlink->dpipe_table_list,
table_name, devlink); table_name, devlink);
if (!table) if (!table)
goto unlock; return;
list_del_rcu(&table->list); list_del_rcu(&table->list);
devl_unlock(devlink);
kfree_rcu(table, rcu); kfree_rcu(table, rcu);
return; }
unlock: EXPORT_SYMBOL_GPL(devl_dpipe_table_unregister);
/**
* devlink_dpipe_table_unregister - unregister dpipe table
*
* @devlink: devlink
* @table_name: table name
*
* Context: Takes and release devlink->lock <mutex>.
*/
void devlink_dpipe_table_unregister(struct devlink *devlink,
const char *table_name)
{
devl_lock(devlink);
devl_dpipe_table_unregister(devlink, table_name);
devl_unlock(devlink); devl_unlock(devlink);
} }
EXPORT_SYMBOL_GPL(devlink_dpipe_table_unregister); EXPORT_SYMBOL_GPL(devlink_dpipe_table_unregister);
...@@ -10767,31 +10837,50 @@ int devlink_resource_size_get(struct devlink *devlink, ...@@ -10767,31 +10837,50 @@ int devlink_resource_size_get(struct devlink *devlink,
EXPORT_SYMBOL_GPL(devlink_resource_size_get); EXPORT_SYMBOL_GPL(devlink_resource_size_get);
/** /**
* devlink_dpipe_table_resource_set - set the resource id * devl_dpipe_table_resource_set - set the resource id
* *
* @devlink: devlink * @devlink: devlink
* @table_name: table name * @table_name: table name
* @resource_id: resource id * @resource_id: resource id
* @resource_units: number of resource's units consumed per table's entry * @resource_units: number of resource's units consumed per table's entry
*/ */
int devlink_dpipe_table_resource_set(struct devlink *devlink, int devl_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)
{ {
struct devlink_dpipe_table *table; struct devlink_dpipe_table *table;
int err = 0;
devl_lock(devlink);
table = devlink_dpipe_table_find(&devlink->dpipe_table_list, table = devlink_dpipe_table_find(&devlink->dpipe_table_list,
table_name, devlink); table_name, devlink);
if (!table) { if (!table)
err = -EINVAL; return -EINVAL;
goto out;
}
table->resource_id = resource_id; table->resource_id = resource_id;
table->resource_units = resource_units; table->resource_units = resource_units;
table->resource_valid = true; table->resource_valid = true;
out: return 0;
}
EXPORT_SYMBOL_GPL(devl_dpipe_table_resource_set);
/**
* devlink_dpipe_table_resource_set - set the resource id
*
* @devlink: devlink
* @table_name: table name
* @resource_id: resource id
* @resource_units: number of resource's units consumed per table's entry
*
* Context: Takes and release devlink->lock <mutex>.
*/
int devlink_dpipe_table_resource_set(struct devlink *devlink,
const char *table_name, u64 resource_id,
u64 resource_units)
{
int err;
devl_lock(devlink);
err = devl_dpipe_table_resource_set(devlink, table_name,
resource_id, resource_units);
devl_unlock(devlink); devl_unlock(devlink);
return err; return err;
} }
......
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