-
Notifications
You must be signed in to change notification settings - Fork 4
/
ulp_mark_mgr.c
271 lines (227 loc) · 5.91 KB
/
ulp_mark_mgr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2014-2020 Broadcom
* All rights reserved.
*/
#include <rte_common.h>
#include <rte_malloc.h>
#include <rte_log.h>
#include "bnxt.h"
#include "bnxt_ulp.h"
#include "tf_ext_flow_handle.h"
#include "ulp_mark_mgr.h"
#include "bnxt_tf_common.h"
#include "ulp_template_db.h"
#include "ulp_template_struct.h"
static inline uint32_t
ulp_mark_db_idx_get(bool is_gfid, uint32_t fid, struct bnxt_ulp_mark_tbl *mtbl)
{
uint32_t idx = 0, hashtype = 0;
if (is_gfid) {
TF_GET_HASH_TYPE_FROM_GFID(fid, hashtype);
TF_GET_HASH_INDEX_FROM_GFID(fid, idx);
/* Need to truncate anything beyond supported flows */
idx &= mtbl->gfid_mask;
if (hashtype)
idx |= mtbl->gfid_type_bit;
} else {
idx = fid;
}
return idx;
}
static int32_t
ulp_mark_db_mark_set(struct bnxt_ulp_context *ctxt,
bool is_gfid,
uint32_t fid,
uint32_t mark)
{
struct bnxt_ulp_mark_tbl *mtbl;
uint32_t idx = 0;
if (!ctxt) {
BNXT_TF_DBG(ERR, "Invalid ulp context\n");
return -EINVAL;
}
mtbl = bnxt_ulp_cntxt_ptr2_mark_db_get(ctxt);
if (!mtbl) {
BNXT_TF_DBG(ERR, "Unable to get Mark DB\n");
return -EINVAL;
}
idx = ulp_mark_db_idx_get(is_gfid, fid, mtbl);
if (is_gfid) {
BNXT_TF_DBG(DEBUG, "Set GFID[0x%0x] = 0x%0x\n", idx, mark);
mtbl->gfid_tbl[idx].mark_id = mark;
mtbl->gfid_tbl[idx].valid = true;
} else {
/* For the LFID, the FID is used as the index */
mtbl->lfid_tbl[fid].mark_id = mark;
mtbl->lfid_tbl[fid].valid = true;
}
return 0;
}
/*
* Allocate and Initialize all Mark Manager resources for this ulp context.
*
* ctxt [in] The ulp context for the mark manager.
*
*/
int32_t
ulp_mark_db_init(struct bnxt_ulp_context *ctxt)
{
struct bnxt_ulp_device_params *dparms;
struct bnxt_ulp_mark_tbl *mark_tbl = NULL;
uint32_t dev_id;
if (!ctxt) {
BNXT_TF_DBG(DEBUG, "Invalid ULP CTXT\n");
return -EINVAL;
}
if (bnxt_ulp_cntxt_dev_id_get(ctxt, &dev_id)) {
BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
return -EINVAL;
}
dparms = bnxt_ulp_device_params_get(dev_id);
if (!dparms) {
BNXT_TF_DBG(DEBUG, "Failed to device parms\n");
return -EINVAL;
}
mark_tbl = rte_zmalloc("ulp_rx_mark_tbl_ptr",
sizeof(struct bnxt_ulp_mark_tbl), 0);
if (!mark_tbl)
goto mem_error;
/* Need to allocate 2 * Num flows to account for hash type bit. */
mark_tbl->lfid_tbl = rte_zmalloc("ulp_rx_em_flow_mark_table",
dparms->lfid_entries *
sizeof(struct bnxt_lfid_mark_info),
0);
if (!mark_tbl->lfid_tbl)
goto mem_error;
/* Need to allocate 2 * Num flows to account for hash type bit. */
mark_tbl->gfid_tbl = rte_zmalloc("ulp_rx_eem_flow_mark_table",
2 * dparms->num_flows *
sizeof(struct bnxt_gfid_mark_info),
0);
if (!mark_tbl->gfid_tbl)
goto mem_error;
/*
* TBD: This needs to be generalized for better mark handling
* These values are used to compress the FID to the allowable index
* space. The FID from hw may be the full hash.
*/
mark_tbl->gfid_max = dparms->gfid_entries - 1;
mark_tbl->gfid_mask = (dparms->gfid_entries / 2) - 1;
mark_tbl->gfid_type_bit = (dparms->gfid_entries / 2);
BNXT_TF_DBG(DEBUG, "GFID Max = 0x%08x\nGFID MASK = 0x%08x\n",
mark_tbl->gfid_max,
mark_tbl->gfid_mask);
/* Add the mark tbl to the ulp context. */
bnxt_ulp_cntxt_ptr2_mark_db_set(ctxt, mark_tbl);
return 0;
mem_error:
rte_free(mark_tbl->gfid_tbl);
rte_free(mark_tbl->lfid_tbl);
rte_free(mark_tbl);
BNXT_TF_DBG(DEBUG,
"Failed to allocate memory for mark mgr\n");
return -ENOMEM;
}
/*
* Release all resources in the Mark Manager for this ulp context
*
* ctxt [in] The ulp context for the mark manager
*
*/
int32_t
ulp_mark_db_deinit(struct bnxt_ulp_context *ctxt)
{
struct bnxt_ulp_mark_tbl *mtbl;
mtbl = bnxt_ulp_cntxt_ptr2_mark_db_get(ctxt);
if (mtbl) {
rte_free(mtbl->gfid_tbl);
rte_free(mtbl->lfid_tbl);
rte_free(mtbl);
/* Safe to ignore on deinit */
(void)bnxt_ulp_cntxt_ptr2_mark_db_set(ctxt, NULL);
}
return 0;
}
/*
* Get a Mark from the Mark Manager
*
* ctxt [in] The ulp context for the mark manager
*
* is_gfid [in] The type of fid (GFID or LFID)
*
* fid [in] The flow id that is returned by HW in BD
*
* mark [out] The mark that is associated with the FID
*
*/
int32_t
ulp_mark_db_mark_get(struct bnxt_ulp_context *ctxt,
bool is_gfid,
uint32_t fid,
uint32_t *mark)
{
struct bnxt_ulp_mark_tbl *mtbl;
uint32_t idx = 0;
if (!ctxt || !mark)
return -EINVAL;
mtbl = bnxt_ulp_cntxt_ptr2_mark_db_get(ctxt);
if (!mtbl) {
BNXT_TF_DBG(ERR, "Unable to get Mark Table\n");
return -EINVAL;
}
idx = ulp_mark_db_idx_get(is_gfid, fid, mtbl);
if (is_gfid) {
if (!mtbl->gfid_tbl[idx].valid)
return -EINVAL;
BNXT_TF_DBG(DEBUG, "Get GFID[0x%0x] = 0x%0x\n",
idx, mtbl->gfid_tbl[idx].mark_id);
*mark = mtbl->gfid_tbl[idx].mark_id;
} else {
if (!mtbl->gfid_tbl[idx].valid)
return -EINVAL;
BNXT_TF_DBG(DEBUG, "Get LFID[0x%0x] = 0x%0x\n",
idx, mtbl->lfid_tbl[idx].mark_id);
*mark = mtbl->lfid_tbl[idx].mark_id;
}
return 0;
}
/*
* Adds a Mark to the Mark Manager
*
* ctxt [in] The ulp context for the mark manager
*
* is_gfid [in] The type of fid (GFID or LFID)
*
* fid [in] The flow id that is returned by HW in BD
*
* mark [in] The mark to be associated with the FID
*
*/
int32_t
ulp_mark_db_mark_add(struct bnxt_ulp_context *ctxt,
bool is_gfid,
uint32_t gfid,
uint32_t mark)
{
return ulp_mark_db_mark_set(ctxt, is_gfid, gfid, mark);
}
/*
* Removes a Mark from the Mark Manager
*
* ctxt [in] The ulp context for the mark manager
*
* is_gfid [in] The type of fid (GFID or LFID)
*
* fid [in] The flow id that is returned by HW in BD
*
* mark [in] The mark to be associated with the FID
*
*/
int32_t
ulp_mark_db_mark_del(struct bnxt_ulp_context *ctxt,
bool is_gfid,
uint32_t gfid,
uint32_t mark __rte_unused)
{
return ulp_mark_db_mark_set(ctxt, is_gfid, gfid, ULP_MARK_INVALID);
}