net/bnxt: identify duplicate flows
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_gen_tbl.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _ULP_GEN_TBL_H_
7 #define _ULP_GEN_TBL_H_
8
9 /* Macros for reference count manipulation */
10 #define ULP_GEN_TBL_REF_CNT_INC(entry) {*(entry)->ref_count += 1; }
11 #define ULP_GEN_TBL_REF_CNT_DEC(entry) {*(entry)->ref_count -= 1; }
12 #define ULP_GEN_TBL_REF_CNT(entry) (*(entry)->ref_count)
13
14 #define ULP_GEN_TBL_FID_OFFSET          0
15 #define ULP_GEN_TBL_FID_SIZE_BITS       32
16
17 /* Structure to pass the generic table values across APIs */
18 struct ulp_mapper_gen_tbl_entry {
19         uint32_t                *ref_count;
20         uint32_t                byte_data_size;
21         uint8_t                 *byte_data;
22         enum bnxt_ulp_byte_order        byte_order;
23 };
24
25 /*
26  * Structure to store the generic tbl container
27  * The ref count and byte data contain list of "num_elem" elements.
28  * The size of each entry in byte_data is of size byte_data_size.
29  */
30 struct ulp_mapper_gen_tbl_cont {
31         uint32_t                        num_elem;
32         uint32_t                        byte_data_size;
33         enum bnxt_ulp_byte_order        byte_order;
34         /* Reference count to track number of users*/
35         uint32_t                        *ref_count;
36         /* First 4 bytes is either tcam_idx or fid and rest are identities */
37         uint8_t                         *byte_data;
38 };
39
40 /* Structure to store the generic tbl container */
41 struct ulp_mapper_gen_tbl_list {
42         struct ulp_mapper_gen_tbl_cont  container;
43         uint32_t                        mem_data_size;
44         uint8_t                         *mem_data;
45 };
46
47 /* Forward declaration */
48 struct bnxt_ulp_mapper_data;
49 struct ulp_flow_db_res_params;
50
51 /*
52  * Initialize the generic table list
53  *
54  * mapper_data [in] Pointer to the mapper data and the generic table is
55  * part of it
56  *
57  * returns 0 on success
58  */
59 int32_t
60 ulp_mapper_generic_tbl_list_init(struct bnxt_ulp_mapper_data *mapper_data);
61
62 /*
63  * Free the generic table list
64  *
65  * mapper_data [in] Pointer to the mapper data and the generic table is
66  * part of it
67  *
68  * returns 0 on success
69  */
70 int32_t
71 ulp_mapper_generic_tbl_list_deinit(struct bnxt_ulp_mapper_data *mapper_data);
72
73 /*
74  * Get the generic table list entry
75  *
76  * ulp_ctxt [in] - Ptr to ulp_context
77  * tbl_idx [in] -  Table index to the generic table list
78  * key [in] - Key index to the table
79  * entry [out] - output will include the entry if found
80  *
81  * returns 0 on success.
82  */
83 int32_t
84 ulp_mapper_gen_tbl_entry_get(struct bnxt_ulp_context *ulp,
85                              uint32_t tbl_idx,
86                              uint32_t key,
87                              struct ulp_mapper_gen_tbl_entry *entry);
88
89 /*
90  * utility function to calculate the table idx
91  *
92  * res_sub_type [in] - Resource sub type
93  * dir [in] - direction
94  *
95  * returns None
96  */
97 int32_t
98 ulp_mapper_gen_tbl_idx_calculate(uint32_t res_sub_type, uint32_t dir);
99
100 /*
101  * Set the data in the generic table entry
102  *
103  * entry [in] - generic table entry
104  * len [in] - The length of the data in bits to be set
105  * data [in] - pointer to the data to be used for setting the value.
106  * data_size [in] - length of the data pointer in bytes.
107  *
108  * returns 0 on success
109  */
110 int32_t
111 ulp_mapper_gen_tbl_entry_data_set(struct ulp_mapper_gen_tbl_entry *entry,
112                                   uint32_t len, uint8_t *data,
113                                   uint32_t data_size);
114
115 /*
116  * Get the data in the generic table entry
117  *
118  * entry [in] - generic table entry
119  * offset [in] - The offset in bits where the data has to get
120  * len [in] - The length of the data in bits to be get
121  * data [out] - pointer to the data to be used for setting the value.
122  * data_size [in] - The size of data in bytes
123  *
124  * returns 0 on success
125  */
126 int32_t
127 ulp_mapper_gen_tbl_entry_data_get(struct ulp_mapper_gen_tbl_entry *entry,
128                                   uint32_t offset, uint32_t len, uint8_t *data,
129                                   uint32_t data_size);
130
131 /*
132  * Free the generic table list entry
133  *
134  * ulp_ctx [in] - Pointer to the ulp context
135  * res [in] - Pointer to flow db resource entry
136  *
137  * returns 0 on success
138  */
139 int32_t
140 ulp_mapper_gen_tbl_res_free(struct bnxt_ulp_context *ulp_ctx,
141                             struct ulp_flow_db_res_params *res);
142
143 #endif /* _ULP_EN_TBL_H_ */