701a8d10e5083ca25f7730a09af2f09fb3481a59
[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  * offset [in] - The offset in bits where the data has to be set
105  * len [in] - The length of the data in bits to be set
106  * data [in] - pointer to the data to be used for setting the value.
107  * data_size [in] - length of the data pointer in bytes.
108  *
109  * returns 0 on success
110  */
111 int32_t
112 ulp_mapper_gen_tbl_entry_data_set(struct ulp_mapper_gen_tbl_entry *entry,
113                                   uint32_t offset, uint32_t len, uint8_t *data,
114                                   uint32_t data_size);
115
116 /*
117  * Get the data in the generic table entry
118  *
119  * entry [in] - generic table entry
120  * offset [in] - The offset in bits where the data has to get
121  * len [in] - The length of the data in bits to be get
122  * data [out] - pointer to the data to be used for setting the value.
123  * data_size [in] - The size of data in bytes
124  *
125  * returns 0 on success
126  */
127 int32_t
128 ulp_mapper_gen_tbl_entry_data_get(struct ulp_mapper_gen_tbl_entry *entry,
129                                   uint32_t offset, uint32_t len, uint8_t *data,
130                                   uint32_t data_size);
131
132 /*
133  * Free the generic table list entry
134  *
135  * ulp_ctx [in] - Pointer to the ulp context
136  * res [in] - Pointer to flow db resource entry
137  *
138  * returns 0 on success
139  */
140 int32_t
141 ulp_mapper_gen_tbl_res_free(struct bnxt_ulp_context *ulp_ctx,
142                             struct ulp_flow_db_res_params *res);
143
144 #endif /* _ULP_EN_TBL_H_ */