1
0
Fork 0

devlink: Add support for dynamic table size

Up until now the dpipe table's size was static and known at registration
time. The host table does not have constant size and it is resized in
dynamic manner. In order to support this behavior the size is changed
to be obtained dynamically via an op.

This patch also adjust the current dpipe table for the new API.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
hifive-unleashed-5.1
Arkadi Sharshevsky 2017-08-24 08:40:02 +02:00 committed by David S. Miller
parent 23ca5ec3af
commit ffd3cdccf2
3 changed files with 19 additions and 13 deletions

View File

@ -301,24 +301,29 @@ static int mlxsw_sp_dpipe_table_erif_counters_update(void *priv, bool enable)
return 0; return 0;
} }
static u64 mlxsw_sp_dpipe_table_erif_size_get(void *priv)
{
struct mlxsw_sp *mlxsw_sp = priv;
return MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
}
static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = { static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
.matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump, .matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump,
.actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump, .actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump,
.entries_dump = mlxsw_sp_dpipe_table_erif_entries_dump, .entries_dump = mlxsw_sp_dpipe_table_erif_entries_dump,
.counters_set_update = mlxsw_sp_dpipe_table_erif_counters_update, .counters_set_update = mlxsw_sp_dpipe_table_erif_counters_update,
.size_get = mlxsw_sp_dpipe_table_erif_size_get,
}; };
static int mlxsw_sp_dpipe_erif_table_init(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_dpipe_erif_table_init(struct mlxsw_sp *mlxsw_sp)
{ {
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
u64 table_size;
table_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
return devlink_dpipe_table_register(devlink, return devlink_dpipe_table_register(devlink,
MLXSW_SP_DPIPE_TABLE_NAME_ERIF, MLXSW_SP_DPIPE_TABLE_NAME_ERIF,
&mlxsw_sp_erif_ops, &mlxsw_sp_erif_ops,
mlxsw_sp, table_size, mlxsw_sp, false);
false);
} }
static void mlxsw_sp_dpipe_erif_table_fini(struct mlxsw_sp *mlxsw_sp) static void mlxsw_sp_dpipe_erif_table_fini(struct mlxsw_sp *mlxsw_sp)

View File

@ -178,7 +178,6 @@ struct devlink_dpipe_table_ops;
* struct devlink_dpipe_table - table object * struct devlink_dpipe_table - table object
* @priv: private * @priv: private
* @name: table name * @name: table name
* @size: maximum number of entries
* @counters_enabled: indicates if counters are active * @counters_enabled: indicates if counters are active
* @counter_control_extern: indicates if counter control is in dpipe or * @counter_control_extern: indicates if counter control is in dpipe or
* external tool * external tool
@ -189,7 +188,6 @@ struct devlink_dpipe_table {
void *priv; void *priv;
struct list_head list; struct list_head list;
const char *name; const char *name;
u64 size;
bool counters_enabled; bool counters_enabled;
bool counter_control_extern; bool counter_control_extern;
struct devlink_dpipe_table_ops *table_ops; struct devlink_dpipe_table_ops *table_ops;
@ -204,6 +202,7 @@ struct devlink_dpipe_table {
* @counters_set_update - when changing the counter status hardware sync * @counters_set_update - when changing the counter status hardware sync
* maybe needed to allocate/free counter related * maybe needed to allocate/free counter related
* resources * resources
* @size_get - get size
*/ */
struct devlink_dpipe_table_ops { struct devlink_dpipe_table_ops {
int (*actions_dump)(void *priv, struct sk_buff *skb); int (*actions_dump)(void *priv, struct sk_buff *skb);
@ -211,6 +210,7 @@ struct devlink_dpipe_table_ops {
int (*entries_dump)(void *priv, bool counters_enabled, int (*entries_dump)(void *priv, bool counters_enabled,
struct devlink_dpipe_dump_ctx *dump_ctx); struct devlink_dpipe_dump_ctx *dump_ctx);
int (*counters_set_update)(void *priv, bool enable); int (*counters_set_update)(void *priv, bool enable);
u64 (*size_get)(void *priv);
}; };
/** /**
@ -311,8 +311,7 @@ void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
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, u64 size, void *priv, bool counter_control_extern);
bool counter_control_extern);
void devlink_dpipe_table_unregister(struct devlink *devlink, void devlink_dpipe_table_unregister(struct devlink *devlink,
const char *table_name); const char *table_name);
int devlink_dpipe_headers_register(struct devlink *devlink, int devlink_dpipe_headers_register(struct devlink *devlink,

View File

@ -1647,13 +1647,15 @@ static int devlink_dpipe_table_put(struct sk_buff *skb,
struct devlink_dpipe_table *table) struct devlink_dpipe_table *table)
{ {
struct nlattr *table_attr; struct nlattr *table_attr;
u64 table_size;
table_size = table->table_ops->size_get(table->priv);
table_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE); table_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE);
if (!table_attr) if (!table_attr)
return -EMSGSIZE; return -EMSGSIZE;
if (nla_put_string(skb, DEVLINK_ATTR_DPIPE_TABLE_NAME, table->name) || if (nla_put_string(skb, DEVLINK_ATTR_DPIPE_TABLE_NAME, table->name) ||
nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_SIZE, table->size, nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_SIZE, table_size,
DEVLINK_ATTR_PAD)) DEVLINK_ATTR_PAD))
goto nla_put_failure; goto nla_put_failure;
if (nla_put_u8(skb, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED, if (nla_put_u8(skb, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,
@ -2718,20 +2720,21 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
* @table_name: table name * @table_name: table name
* @table_ops: table ops * @table_ops: table ops
* @priv: priv * @priv: priv
* @size: size
* @counter_control_extern: external control for counters * @counter_control_extern: external control for counters
*/ */
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, u64 size, void *priv, bool counter_control_extern)
bool counter_control_extern)
{ {
struct devlink_dpipe_table *table; struct devlink_dpipe_table *table;
if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name)) if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
return -EEXIST; return -EEXIST;
if (WARN_ON(!table_ops->size_get))
return -EINVAL;
table = kzalloc(sizeof(*table), GFP_KERNEL); table = kzalloc(sizeof(*table), GFP_KERNEL);
if (!table) if (!table)
return -ENOMEM; return -ENOMEM;
@ -2739,7 +2742,6 @@ int devlink_dpipe_table_register(struct devlink *devlink,
table->name = table_name; table->name = table_name;
table->table_ops = table_ops; table->table_ops = table_ops;
table->priv = priv; table->priv = priv;
table->size = size;
table->counter_control_extern = counter_control_extern; table->counter_control_extern = counter_control_extern;
mutex_lock(&devlink_mutex); mutex_lock(&devlink_mutex);