xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/bcmbloom.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Bloom filter support
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 1999-2017, Broadcom Corporation
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      Unless you and Broadcom execute a separate written software license
9*4882a593Smuzhiyun  * agreement governing use of this software, this software is licensed to you
10*4882a593Smuzhiyun  * under the terms of the GNU General Public License version 2 (the "GPL"),
11*4882a593Smuzhiyun  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12*4882a593Smuzhiyun  * following added to such license:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *      As a special exception, the copyright holders of this software give you
15*4882a593Smuzhiyun  * permission to link this software with independent modules, and to copy and
16*4882a593Smuzhiyun  * distribute the resulting executable under terms of your choice, provided that
17*4882a593Smuzhiyun  * you also meet, for each linked independent module, the terms and conditions of
18*4882a593Smuzhiyun  * the license of that module.  An independent module is a module which is not
19*4882a593Smuzhiyun  * derived from this software.  The special exception does not apply to any
20*4882a593Smuzhiyun  * modifications of the software.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  *      Notwithstanding the above, under no circumstances may you combine this
23*4882a593Smuzhiyun  * software in any way with any other Broadcom software provided under a license
24*4882a593Smuzhiyun  * other than the GPL, without Broadcom's express prior written consent.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * <<Broadcom-WL-IPTag/Open:>>
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * $Id$
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifndef _bcmbloom_h_
33*4882a593Smuzhiyun #define _bcmbloom_h_
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <typedefs.h>
36*4882a593Smuzhiyun #ifdef BCMDRIVER
37*4882a593Smuzhiyun #include <osl.h>
38*4882a593Smuzhiyun #else
39*4882a593Smuzhiyun #include <stddef.h>  /* For size_t */
40*4882a593Smuzhiyun #endif // endif
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun struct bcm_bloom_filter;
43*4882a593Smuzhiyun typedef struct bcm_bloom_filter bcm_bloom_filter_t;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun typedef void* (*bcm_bloom_alloc_t)(void *ctx, uint size);
46*4882a593Smuzhiyun typedef void (*bcm_bloom_free_t)(void *ctx, void *buf, uint size);
47*4882a593Smuzhiyun typedef uint (*bcm_bloom_hash_t)(void* ctx, uint idx, const uint8 *tag, uint len);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /* create/allocate a bloom filter. filter size can be 0 for validate only filters */
50*4882a593Smuzhiyun int bcm_bloom_create(bcm_bloom_alloc_t alloc_cb,
51*4882a593Smuzhiyun 	bcm_bloom_free_t free_cb, void *callback_ctx, uint max_hash,
52*4882a593Smuzhiyun 	uint filter_size /* bytes */, bcm_bloom_filter_t **bloom);
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /* destroy bloom filter */
55*4882a593Smuzhiyun int bcm_bloom_destroy(bcm_bloom_filter_t **bloom, bcm_bloom_free_t free_cb);
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* add a hash function to filter, return an index */
58*4882a593Smuzhiyun int bcm_bloom_add_hash(bcm_bloom_filter_t *filter, bcm_bloom_hash_t hash, uint *idx);
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* remove the hash function at index from filter */
61*4882a593Smuzhiyun int bcm_bloom_remove_hash(bcm_bloom_filter_t *filter, uint idx);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* check if given tag is member of the filter. If buf is NULL and/or buf_len is 0
64*4882a593Smuzhiyun  * then use the internal state. BCME_OK if member, BCME_NOTFOUND if not,
65*4882a593Smuzhiyun  * or other error (e.g. BADARG)
66*4882a593Smuzhiyun  */
67*4882a593Smuzhiyun bool bcm_bloom_is_member(bcm_bloom_filter_t *filter,
68*4882a593Smuzhiyun 	const uint8 *tag, uint tag_len, const uint8 *buf, uint buf_len);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /* add a member to the filter. invalid for validate_only filters */
71*4882a593Smuzhiyun int bcm_bloom_add_member(bcm_bloom_filter_t *filter, const uint8 *tag, uint tag_len);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /* no support for remove member */
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /* get the filter data from state. BCME_BUFTOOSHORT w/ required length in buf_len
76*4882a593Smuzhiyun  * if supplied size is insufficient
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun int bcm_bloom_get_filter_data(bcm_bloom_filter_t *filter,
79*4882a593Smuzhiyun 	uint buf_size, uint8 *buf, uint *buf_len);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun #endif /* _bcmbloom_h_ */
82