Skip to content

Commit 0487cfb

Browse files
nirdotandavem330
authored andcommitted
mlxsw: spectrum_acl: Introduce Bloom filter
Lay the foundations for Bloom filter handling. Introduce a new file for Bloom filter actions. Add struct mlxsw_sp_acl_bf to struct mlxsw_sp_acl_erp_core and initialize the Bloom filter data structure. Also take care of proper destruction when terminating. Signed-off-by: Nir Dotan <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9440685 commit 0487cfb

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

drivers/net/ethernet/mellanox/mlxsw/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mlxsw_spectrum-objs := spectrum.o spectrum_buffers.o \
2020
spectrum_acl_tcam.o spectrum_acl_ctcam.o \
2121
spectrum_acl_atcam.o spectrum_acl_erp.o \
2222
spectrum1_acl_tcam.o spectrum2_acl_tcam.o \
23-
spectrum_acl.o \
23+
spectrum_acl_bloom_filter.o spectrum_acl.o \
2424
spectrum_flower.o spectrum_cnt.o \
2525
spectrum_fid.o spectrum_ipip.o \
2626
spectrum_acl_flex_actions.o \
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2+
/* Copyright (c) 2018 Mellanox Technologies. All rights reserved */
3+
4+
#include <linux/errno.h>
5+
#include <linux/gfp.h>
6+
#include <linux/kernel.h>
7+
#include <linux/refcount.h>
8+
9+
#include "spectrum.h"
10+
#include "spectrum_acl_tcam.h"
11+
12+
struct mlxsw_sp_acl_bf {
13+
unsigned int bank_size;
14+
refcount_t refcnt[0];
15+
};
16+
17+
struct mlxsw_sp_acl_bf *
18+
mlxsw_sp_acl_bf_init(struct mlxsw_sp *mlxsw_sp, unsigned int num_erp_banks)
19+
{
20+
struct mlxsw_sp_acl_bf *bf;
21+
unsigned int bf_bank_size;
22+
23+
if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, ACL_MAX_BF_LOG))
24+
return ERR_PTR(-EIO);
25+
26+
/* Bloom filter size per erp_table_bank
27+
* is 2^ACL_MAX_BF_LOG
28+
*/
29+
bf_bank_size = 1 << MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_BF_LOG);
30+
bf = kzalloc(sizeof(*bf) + bf_bank_size * num_erp_banks *
31+
sizeof(*bf->refcnt), GFP_KERNEL);
32+
if (!bf)
33+
return ERR_PTR(-ENOMEM);
34+
35+
bf->bank_size = bf_bank_size;
36+
return bf;
37+
}
38+
39+
void mlxsw_sp_acl_bf_fini(struct mlxsw_sp_acl_bf *bf)
40+
{
41+
kfree(bf);
42+
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct mlxsw_sp_acl_erp_core {
2424
unsigned int erpt_entries_size[MLXSW_SP_ACL_ATCAM_REGION_TYPE_MAX + 1];
2525
struct gen_pool *erp_tables;
2626
struct mlxsw_sp *mlxsw_sp;
27+
struct mlxsw_sp_acl_bf *bf;
2728
unsigned int num_erp_banks;
2829
};
2930

@@ -1320,6 +1321,12 @@ static int mlxsw_sp_acl_erp_tables_init(struct mlxsw_sp *mlxsw_sp,
13201321
if (err)
13211322
goto err_gen_pool_add;
13221323

1324+
erp_core->bf = mlxsw_sp_acl_bf_init(mlxsw_sp, erp_core->num_erp_banks);
1325+
if (IS_ERR(erp_core->bf)) {
1326+
err = PTR_ERR(erp_core->bf);
1327+
goto err_bf_init;
1328+
}
1329+
13231330
/* Different regions require masks of different sizes */
13241331
err = mlxsw_sp_acl_erp_tables_sizes_query(mlxsw_sp, erp_core);
13251332
if (err)
@@ -1328,6 +1335,8 @@ static int mlxsw_sp_acl_erp_tables_init(struct mlxsw_sp *mlxsw_sp,
13281335
return 0;
13291336

13301337
err_erp_tables_sizes_query:
1338+
mlxsw_sp_acl_bf_fini(erp_core->bf);
1339+
err_bf_init:
13311340
err_gen_pool_add:
13321341
gen_pool_destroy(erp_core->erp_tables);
13331342
return err;
@@ -1336,6 +1345,7 @@ static int mlxsw_sp_acl_erp_tables_init(struct mlxsw_sp *mlxsw_sp,
13361345
static void mlxsw_sp_acl_erp_tables_fini(struct mlxsw_sp *mlxsw_sp,
13371346
struct mlxsw_sp_acl_erp_core *erp_core)
13381347
{
1348+
mlxsw_sp_acl_bf_fini(erp_core->bf);
13391349
gen_pool_destroy(erp_core->erp_tables);
13401350
}
13411351

drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,10 @@ int mlxsw_sp_acl_erps_init(struct mlxsw_sp *mlxsw_sp,
258258
void mlxsw_sp_acl_erps_fini(struct mlxsw_sp *mlxsw_sp,
259259
struct mlxsw_sp_acl_atcam *atcam);
260260

261+
struct mlxsw_sp_acl_bf;
262+
263+
struct mlxsw_sp_acl_bf *
264+
mlxsw_sp_acl_bf_init(struct mlxsw_sp *mlxsw_sp, unsigned int num_erp_banks);
265+
void mlxsw_sp_acl_bf_fini(struct mlxsw_sp_acl_bf *bf);
266+
261267
#endif

0 commit comments

Comments
 (0)