Commit c18c1e18 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

mlxsw: core: Make counter index allocated inside the action append

So far, the caller of mlxsw_afa_block_append_counter needed to allocate
counter index by hand. Benefit from the previously introduced resource
infra and counter_index_get/put callbacks, and allocate the counter
index in place where it is needed, inside the action append function.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 140ce421
...@@ -559,6 +559,53 @@ mlxsw_afa_fwd_entry_ref_create(struct mlxsw_afa_block *block, u8 local_port) ...@@ -559,6 +559,53 @@ mlxsw_afa_fwd_entry_ref_create(struct mlxsw_afa_block *block, u8 local_port)
return ERR_PTR(err); return ERR_PTR(err);
} }
struct mlxsw_afa_counter {
struct mlxsw_afa_resource resource;
u32 counter_index;
};
static void
mlxsw_afa_counter_destroy(struct mlxsw_afa_block *block,
struct mlxsw_afa_counter *counter)
{
block->afa->ops->counter_index_put(block->afa->ops_priv,
counter->counter_index);
kfree(counter);
}
static void
mlxsw_afa_counter_destructor(struct mlxsw_afa_block *block,
struct mlxsw_afa_resource *resource)
{
struct mlxsw_afa_counter *counter;
counter = container_of(resource, struct mlxsw_afa_counter, resource);
mlxsw_afa_counter_destroy(block, counter);
}
static struct mlxsw_afa_counter *
mlxsw_afa_counter_create(struct mlxsw_afa_block *block)
{
struct mlxsw_afa_counter *counter;
int err;
counter = kzalloc(sizeof(*counter), GFP_KERNEL);
if (!counter)
return ERR_PTR(-ENOMEM);
err = block->afa->ops->counter_index_get(block->afa->ops_priv,
&counter->counter_index);
if (err)
goto err_counter_index_get;
counter->resource.destructor = mlxsw_afa_counter_destructor;
mlxsw_afa_resource_add(block, &counter->resource);
return counter;
err_counter_index_get:
kfree(counter);
return ERR_PTR(err);
}
#define MLXSW_AFA_ONE_ACTION_LEN 32 #define MLXSW_AFA_ONE_ACTION_LEN 32
#define MLXSW_AFA_PAYLOAD_OFFSET 4 #define MLXSW_AFA_PAYLOAD_OFFSET 4
...@@ -876,11 +923,10 @@ mlxsw_afa_polcnt_pack(char *payload, ...@@ -876,11 +923,10 @@ mlxsw_afa_polcnt_pack(char *payload,
mlxsw_afa_polcnt_counter_index_set(payload, counter_index); mlxsw_afa_polcnt_counter_index_set(payload, counter_index);
} }
int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, int mlxsw_afa_block_append_allocated_counter(struct mlxsw_afa_block *block,
u32 counter_index) u32 counter_index)
{ {
char *act = mlxsw_afa_block_append_action(block, char *act = mlxsw_afa_block_append_action(block, MLXSW_AFA_POLCNT_CODE,
MLXSW_AFA_POLCNT_CODE,
MLXSW_AFA_POLCNT_SIZE); MLXSW_AFA_POLCNT_SIZE);
if (!act) if (!act)
return -ENOBUFS; return -ENOBUFS;
...@@ -888,6 +934,32 @@ int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, ...@@ -888,6 +934,32 @@ int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block,
counter_index); counter_index);
return 0; return 0;
} }
EXPORT_SYMBOL(mlxsw_afa_block_append_allocated_counter);
int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block,
u32 *p_counter_index)
{
struct mlxsw_afa_counter *counter;
u32 counter_index;
int err;
counter = mlxsw_afa_counter_create(block);
if (IS_ERR(counter))
return PTR_ERR(counter);
counter_index = counter->counter_index;
err = mlxsw_afa_block_append_allocated_counter(block, counter_index);
if (err)
goto err_append_allocated_counter;
if (p_counter_index)
*p_counter_index = counter_index;
return 0;
err_append_allocated_counter:
mlxsw_afa_counter_destroy(block, counter);
return err;
}
EXPORT_SYMBOL(mlxsw_afa_block_append_counter); EXPORT_SYMBOL(mlxsw_afa_block_append_counter);
/* Virtual Router and Forwarding Domain Action /* Virtual Router and Forwarding Domain Action
......
...@@ -69,8 +69,10 @@ int mlxsw_afa_block_append_fwd(struct mlxsw_afa_block *block, ...@@ -69,8 +69,10 @@ int mlxsw_afa_block_append_fwd(struct mlxsw_afa_block *block,
u8 local_port, bool in_port); u8 local_port, bool in_port);
int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block, int mlxsw_afa_block_append_vlan_modify(struct mlxsw_afa_block *block,
u16 vid, u8 pcp, u8 et); u16 vid, u8 pcp, u8 et);
int mlxsw_afa_block_append_allocated_counter(struct mlxsw_afa_block *block,
u32 counter_index);
int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block, int mlxsw_afa_block_append_counter(struct mlxsw_afa_block *block,
u32 counter_index); u32 *p_counter_index);
int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid); int mlxsw_afa_block_append_fid_set(struct mlxsw_afa_block *block, u16 fid);
int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block, int mlxsw_afa_block_append_mcrouter(struct mlxsw_afa_block *block,
u16 expected_irif, u16 min_mtu, u16 expected_irif, u16 min_mtu,
......
...@@ -457,7 +457,6 @@ struct mlxsw_sp_acl_rule_info { ...@@ -457,7 +457,6 @@ struct mlxsw_sp_acl_rule_info {
struct mlxsw_afk_element_values values; struct mlxsw_afk_element_values values;
struct mlxsw_afa_block *act_block; struct mlxsw_afa_block *act_block;
unsigned int counter_index; unsigned int counter_index;
bool counter_valid;
}; };
enum mlxsw_sp_acl_profile { enum mlxsw_sp_acl_profile {
......
...@@ -462,27 +462,6 @@ u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset) ...@@ -462,27 +462,6 @@ u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset)
return ops->ruleset_group_id(ruleset->priv); return ops->ruleset_group_id(ruleset->priv);
} }
static int
mlxsw_sp_acl_rulei_counter_alloc(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei)
{
int err;
err = mlxsw_sp_flow_counter_alloc(mlxsw_sp, &rulei->counter_index);
if (err)
return err;
rulei->counter_valid = true;
return 0;
}
static void
mlxsw_sp_acl_rulei_counter_free(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei)
{
rulei->counter_valid = false;
mlxsw_sp_flow_counter_free(mlxsw_sp, rulei->counter_index);
}
struct mlxsw_sp_acl_rule_info * struct mlxsw_sp_acl_rule_info *
mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl) mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl)
{ {
...@@ -619,7 +598,7 @@ int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp, ...@@ -619,7 +598,7 @@ int mlxsw_sp_acl_rulei_act_count(struct mlxsw_sp *mlxsw_sp,
struct mlxsw_sp_acl_rule_info *rulei) struct mlxsw_sp_acl_rule_info *rulei)
{ {
return mlxsw_afa_block_append_counter(rulei->act_block, return mlxsw_afa_block_append_counter(rulei->act_block,
rulei->counter_index); &rulei->counter_index);
} }
int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp, int mlxsw_sp_acl_rulei_act_fid_set(struct mlxsw_sp *mlxsw_sp,
...@@ -653,13 +632,8 @@ mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp, ...@@ -653,13 +632,8 @@ mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,
goto err_rulei_create; goto err_rulei_create;
} }
err = mlxsw_sp_acl_rulei_counter_alloc(mlxsw_sp, rule->rulei);
if (err)
goto err_counter_alloc;
return rule; return rule;
err_counter_alloc:
mlxsw_sp_acl_rulei_destroy(rule->rulei);
err_rulei_create: err_rulei_create:
kfree(rule); kfree(rule);
err_alloc: err_alloc:
...@@ -672,7 +646,6 @@ void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp, ...@@ -672,7 +646,6 @@ void mlxsw_sp_acl_rule_destroy(struct mlxsw_sp *mlxsw_sp,
{ {
struct mlxsw_sp_acl_ruleset *ruleset = rule->ruleset; struct mlxsw_sp_acl_ruleset *ruleset = rule->ruleset;
mlxsw_sp_acl_rulei_counter_free(mlxsw_sp, rule->rulei);
mlxsw_sp_acl_rulei_destroy(rule->rulei); mlxsw_sp_acl_rulei_destroy(rule->rulei);
kfree(rule); kfree(rule);
mlxsw_sp_acl_ruleset_ref_dec(mlxsw_sp, ruleset); mlxsw_sp_acl_ruleset_ref_dec(mlxsw_sp, ruleset);
......
...@@ -243,7 +243,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp, ...@@ -243,7 +243,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp,
if (!afa_block) if (!afa_block)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
err = mlxsw_afa_block_append_counter(afa_block, counter_index); err = mlxsw_afa_block_append_allocated_counter(afa_block,
counter_index);
if (err) if (err)
goto err; goto 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