Skip to content

Commit ffd3cdc

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 23ca5ec commit ffd3cdc

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,29 @@ static int mlxsw_sp_dpipe_table_erif_counters_update(void *priv, bool enable)
301301
return 0;
302302
}
303303

304+
static u64 mlxsw_sp_dpipe_table_erif_size_get(void *priv)
305+
{
306+
struct mlxsw_sp *mlxsw_sp = priv;
307+
308+
return MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
309+
}
310+
304311
static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
305312
.matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump,
306313
.actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump,
307314
.entries_dump = mlxsw_sp_dpipe_table_erif_entries_dump,
308315
.counters_set_update = mlxsw_sp_dpipe_table_erif_counters_update,
316+
.size_get = mlxsw_sp_dpipe_table_erif_size_get,
309317
};
310318

311319
static int mlxsw_sp_dpipe_erif_table_init(struct mlxsw_sp *mlxsw_sp)
312320
{
313321
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
314-
u64 table_size;
315322

316-
table_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
317323
return devlink_dpipe_table_register(devlink,
318324
MLXSW_SP_DPIPE_TABLE_NAME_ERIF,
319325
&mlxsw_sp_erif_ops,
320-
mlxsw_sp, table_size,
321-
false);
326+
mlxsw_sp, false);
322327
}
323328

324329
static void mlxsw_sp_dpipe_erif_table_fini(struct mlxsw_sp *mlxsw_sp)

include/net/devlink.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ struct devlink_dpipe_table_ops;
178178
* struct devlink_dpipe_table - table object
179179
* @priv: private
180180
* @name: table name
181-
* @size: maximum number of entries
182181
* @counters_enabled: indicates if counters are active
183182
* @counter_control_extern: indicates if counter control is in dpipe or
184183
* external tool
@@ -189,7 +188,6 @@ struct devlink_dpipe_table {
189188
void *priv;
190189
struct list_head list;
191190
const char *name;
192-
u64 size;
193191
bool counters_enabled;
194192
bool counter_control_extern;
195193
struct devlink_dpipe_table_ops *table_ops;
@@ -204,13 +202,15 @@ struct devlink_dpipe_table {
204202
* @counters_set_update - when changing the counter status hardware sync
205203
* maybe needed to allocate/free counter related
206204
* resources
205+
* @size_get - get size
207206
*/
208207
struct devlink_dpipe_table_ops {
209208
int (*actions_dump)(void *priv, struct sk_buff *skb);
210209
int (*matches_dump)(void *priv, struct sk_buff *skb);
211210
int (*entries_dump)(void *priv, bool counters_enabled,
212211
struct devlink_dpipe_dump_ctx *dump_ctx);
213212
int (*counters_set_update)(void *priv, bool enable);
213+
u64 (*size_get)(void *priv);
214214
};
215215

216216
/**
@@ -311,8 +311,7 @@ void devlink_sb_unregister(struct devlink *devlink, unsigned int sb_index);
311311
int devlink_dpipe_table_register(struct devlink *devlink,
312312
const char *table_name,
313313
struct devlink_dpipe_table_ops *table_ops,
314-
void *priv, u64 size,
315-
bool counter_control_extern);
314+
void *priv, bool counter_control_extern);
316315
void devlink_dpipe_table_unregister(struct devlink *devlink,
317316
const char *table_name);
318317
int devlink_dpipe_headers_register(struct devlink *devlink,

net/core/devlink.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,13 +1647,15 @@ static int devlink_dpipe_table_put(struct sk_buff *skb,
16471647
struct devlink_dpipe_table *table)
16481648
{
16491649
struct nlattr *table_attr;
1650+
u64 table_size;
16501651

1652+
table_size = table->table_ops->size_get(table->priv);
16511653
table_attr = nla_nest_start(skb, DEVLINK_ATTR_DPIPE_TABLE);
16521654
if (!table_attr)
16531655
return -EMSGSIZE;
16541656

16551657
if (nla_put_string(skb, DEVLINK_ATTR_DPIPE_TABLE_NAME, table->name) ||
1656-
nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_SIZE, table->size,
1658+
nla_put_u64_64bit(skb, DEVLINK_ATTR_DPIPE_TABLE_SIZE, table_size,
16571659
DEVLINK_ATTR_PAD))
16581660
goto nla_put_failure;
16591661
if (nla_put_u8(skb, DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED,
@@ -2718,28 +2720,28 @@ EXPORT_SYMBOL_GPL(devlink_dpipe_table_counter_enabled);
27182720
* @table_name: table name
27192721
* @table_ops: table ops
27202722
* @priv: priv
2721-
* @size: size
27222723
* @counter_control_extern: external control for counters
27232724
*/
27242725
int devlink_dpipe_table_register(struct devlink *devlink,
27252726
const char *table_name,
27262727
struct devlink_dpipe_table_ops *table_ops,
2727-
void *priv, u64 size,
2728-
bool counter_control_extern)
2728+
void *priv, bool counter_control_extern)
27292729
{
27302730
struct devlink_dpipe_table *table;
27312731

27322732
if (devlink_dpipe_table_find(&devlink->dpipe_table_list, table_name))
27332733
return -EEXIST;
27342734

2735+
if (WARN_ON(!table_ops->size_get))
2736+
return -EINVAL;
2737+
27352738
table = kzalloc(sizeof(*table), GFP_KERNEL);
27362739
if (!table)
27372740
return -ENOMEM;
27382741

27392742
table->name = table_name;
27402743
table->table_ops = table_ops;
27412744
table->priv = priv;
2742-
table->size = size;
27432745
table->counter_control_extern = counter_control_extern;
27442746

27452747
mutex_lock(&devlink_mutex);

0 commit comments

Comments
 (0)