Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "bnxt_tf_common.h"
7 : : #include "ulp_template_struct.h"
8 : : #include "ulp_template_db_enum.h"
9 : : #include "ulp_template_db_field.h"
10 : : #include "ulp_utils.h"
11 : : #include "ulp_port_db.h"
12 : : #include "ulp_flow_db.h"
13 : : #include "ulp_mapper.h"
14 : :
15 : : struct bnxt_ulp_def_param_handler {
16 : : int32_t (*vfr_func)(struct bnxt_ulp_context *ulp_ctx,
17 : : struct ulp_tlv_param *param,
18 : : struct bnxt_ulp_mapper_create_parms *mapper_params);
19 : : };
20 : :
21 : : static int32_t
22 : 0 : ulp_set_svif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
23 : : uint32_t ifindex, uint8_t svif_type,
24 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
25 : : {
26 : : uint16_t svif;
27 : : uint8_t idx;
28 : : int rc;
29 : :
30 : 0 : rc = ulp_port_db_svif_get(ulp_ctx, ifindex, svif_type, &svif);
31 [ # # ]: 0 : if (rc)
32 : : return rc;
33 : :
34 [ # # ]: 0 : if (svif_type == BNXT_ULP_PHY_PORT_SVIF)
35 : : idx = BNXT_ULP_CF_IDX_PHY_PORT_SVIF;
36 [ # # ]: 0 : else if (svif_type == BNXT_ULP_DRV_FUNC_SVIF)
37 : : idx = BNXT_ULP_CF_IDX_DRV_FUNC_SVIF;
38 : : else
39 : : idx = BNXT_ULP_CF_IDX_VF_FUNC_SVIF;
40 : :
41 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, idx, svif);
42 : :
43 : 0 : return 0;
44 : : }
45 : :
46 : : static int32_t
47 : 0 : ulp_set_spif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
48 : : uint32_t ifindex, uint8_t spif_type,
49 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
50 : : {
51 : : uint16_t spif;
52 : : uint8_t idx;
53 : : int rc;
54 : :
55 : 0 : rc = ulp_port_db_spif_get(ulp_ctx, ifindex, spif_type, &spif);
56 [ # # ]: 0 : if (rc)
57 : : return rc;
58 : :
59 [ # # ]: 0 : if (spif_type == BNXT_ULP_PHY_PORT_SPIF)
60 : : idx = BNXT_ULP_CF_IDX_PHY_PORT_SPIF;
61 [ # # ]: 0 : else if (spif_type == BNXT_ULP_DRV_FUNC_SPIF)
62 : : idx = BNXT_ULP_CF_IDX_DRV_FUNC_SPIF;
63 : : else
64 : : idx = BNXT_ULP_CF_IDX_VF_FUNC_SPIF;
65 : :
66 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, idx, spif);
67 : :
68 : 0 : return 0;
69 : : }
70 : :
71 : : static int32_t
72 : 0 : ulp_set_parif_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
73 : : uint32_t ifindex, uint8_t parif_type,
74 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
75 : : {
76 : : uint16_t parif;
77 : : uint8_t idx;
78 : : int rc;
79 : :
80 : 0 : rc = ulp_port_db_parif_get(ulp_ctx, ifindex, parif_type, &parif);
81 [ # # ]: 0 : if (rc)
82 : : return rc;
83 : :
84 [ # # ]: 0 : if (parif_type == BNXT_ULP_PHY_PORT_PARIF)
85 : : idx = BNXT_ULP_CF_IDX_PHY_PORT_PARIF;
86 [ # # ]: 0 : else if (parif_type == BNXT_ULP_DRV_FUNC_PARIF)
87 : : idx = BNXT_ULP_CF_IDX_DRV_FUNC_PARIF;
88 : : else
89 : : idx = BNXT_ULP_CF_IDX_VF_FUNC_PARIF;
90 : :
91 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, idx, parif);
92 : :
93 : 0 : return 0;
94 : : }
95 : :
96 : : static int32_t
97 : 0 : ulp_set_vport_in_comp_fld(struct bnxt_ulp_context *ulp_ctx, uint32_t ifindex,
98 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
99 : : {
100 : : uint16_t vport;
101 : : int rc;
102 : :
103 : 0 : rc = ulp_port_db_vport_get(ulp_ctx, ifindex, &vport);
104 [ # # ]: 0 : if (rc)
105 : : return rc;
106 : :
107 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, BNXT_ULP_CF_IDX_PHY_PORT_VPORT,
108 : : vport);
109 : 0 : return 0;
110 : : }
111 : :
112 : : static int32_t
113 : 0 : ulp_set_vnic_in_comp_fld(struct bnxt_ulp_context *ulp_ctx,
114 : : uint32_t ifindex, uint8_t vnic_type,
115 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
116 : : {
117 : : uint16_t vnic;
118 : : uint8_t idx;
119 : : int rc;
120 : :
121 : 0 : rc = ulp_port_db_default_vnic_get(ulp_ctx, ifindex, vnic_type, &vnic);
122 [ # # ]: 0 : if (rc)
123 : : return rc;
124 : :
125 [ # # ]: 0 : if (vnic_type == BNXT_ULP_DRV_FUNC_VNIC)
126 : : idx = BNXT_ULP_CF_IDX_DRV_FUNC_VNIC;
127 : : else
128 : : idx = BNXT_ULP_CF_IDX_VF_FUNC_VNIC;
129 : :
130 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, idx, vnic);
131 : :
132 : 0 : return 0;
133 : : }
134 : :
135 : : static int32_t
136 : 0 : ulp_set_vlan_in_act_prop(uint16_t port_id,
137 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
138 : : {
139 : 0 : struct ulp_rte_act_prop *act_prop = mapper_params->act_prop;
140 : :
141 [ # # ]: 0 : if (ULP_BITMAP_ISSET(mapper_params->act->bits,
142 : : BNXT_ULP_ACT_BIT_SET_VLAN_VID)) {
143 : 0 : BNXT_TF_DBG(ERR,
144 : : "VLAN already set, multiple VLANs unsupported\n");
145 : 0 : return BNXT_TF_RC_ERROR;
146 : : }
147 : :
148 [ # # ]: 0 : port_id = rte_cpu_to_be_16(port_id);
149 : :
150 : 0 : ULP_BITMAP_SET(mapper_params->act->bits,
151 : : BNXT_ULP_ACT_BIT_SET_VLAN_VID);
152 : :
153 : 0 : memcpy(&act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_ENCAP_VTAG],
154 : : &port_id, sizeof(port_id));
155 : :
156 : 0 : return 0;
157 : : }
158 : :
159 : : static int32_t
160 : 0 : ulp_set_mark_in_act_prop(uint16_t port_id,
161 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
162 : : {
163 [ # # ]: 0 : if (ULP_BITMAP_ISSET(mapper_params->act->bits,
164 : : BNXT_ULP_ACT_BIT_MARK)) {
165 : 0 : BNXT_TF_DBG(ERR,
166 : : "MARK already set, multiple MARKs unsupported\n");
167 : 0 : return BNXT_TF_RC_ERROR;
168 : : }
169 : :
170 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(mapper_params, BNXT_ULP_CF_IDX_DEV_PORT_ID,
171 : : port_id);
172 : :
173 : 0 : return 0;
174 : : }
175 : :
176 : : static int32_t
177 : 0 : ulp_df_dev_port_handler(struct bnxt_ulp_context *ulp_ctx,
178 : : struct ulp_tlv_param *param,
179 : : struct bnxt_ulp_mapper_create_parms *mapper_params)
180 : : {
181 : : uint16_t port_id;
182 : : uint32_t ifindex;
183 : : int rc;
184 : :
185 : 0 : port_id = param->value[0] | param->value[1];
186 : :
187 : 0 : rc = ulp_port_db_dev_port_to_ulp_index(ulp_ctx, port_id, &ifindex);
188 [ # # ]: 0 : if (rc) {
189 : 0 : BNXT_TF_DBG(ERR,
190 : : "Invalid port id\n");
191 : 0 : return BNXT_TF_RC_ERROR;
192 : : }
193 : :
194 : : /* Set port SVIF */
195 : 0 : rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_PHY_PORT_SVIF,
196 : : mapper_params);
197 [ # # ]: 0 : if (rc)
198 : : return rc;
199 : :
200 : : /* Set DRV Func SVIF */
201 : 0 : rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SVIF,
202 : : mapper_params);
203 [ # # ]: 0 : if (rc)
204 : : return rc;
205 : :
206 : : /* Set VF Func SVIF */
207 : 0 : rc = ulp_set_svif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_VF_FUNC_SVIF,
208 : : mapper_params);
209 [ # # ]: 0 : if (rc)
210 : : return rc;
211 : :
212 : : /* Set port SPIF */
213 : 0 : rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_PHY_PORT_SPIF,
214 : : mapper_params);
215 [ # # ]: 0 : if (rc)
216 : : return rc;
217 : :
218 : : /* Set DRV Func SPIF */
219 : 0 : rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SPIF,
220 : : mapper_params);
221 [ # # ]: 0 : if (rc)
222 : : return rc;
223 : :
224 : : /* Set VF Func SPIF */
225 : 0 : rc = ulp_set_spif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_DRV_FUNC_SPIF,
226 : : mapper_params);
227 [ # # ]: 0 : if (rc)
228 : : return rc;
229 : :
230 : : /* Set port PARIF */
231 : 0 : rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex,
232 : : BNXT_ULP_PHY_PORT_PARIF, mapper_params);
233 [ # # ]: 0 : if (rc)
234 : : return rc;
235 : :
236 : : /* Set DRV Func PARIF */
237 : 0 : rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex,
238 : : BNXT_ULP_DRV_FUNC_PARIF, mapper_params);
239 [ # # ]: 0 : if (rc)
240 : : return rc;
241 : :
242 : : /* Set VF Func PARIF */
243 : 0 : rc = ulp_set_parif_in_comp_fld(ulp_ctx, ifindex, BNXT_ULP_VF_FUNC_PARIF,
244 : : mapper_params);
245 [ # # ]: 0 : if (rc)
246 : : return rc;
247 : :
248 : : /* Set uplink VNIC */
249 : 0 : rc = ulp_set_vnic_in_comp_fld(ulp_ctx, ifindex, true, mapper_params);
250 [ # # ]: 0 : if (rc)
251 : : return rc;
252 : :
253 : : /* Set VF VNIC */
254 : 0 : rc = ulp_set_vnic_in_comp_fld(ulp_ctx, ifindex, false, mapper_params);
255 [ # # ]: 0 : if (rc)
256 : : return rc;
257 : :
258 : : /* Set VPORT */
259 : 0 : rc = ulp_set_vport_in_comp_fld(ulp_ctx, ifindex, mapper_params);
260 [ # # ]: 0 : if (rc)
261 : : return rc;
262 : :
263 : : /* Set VLAN */
264 : 0 : rc = ulp_set_vlan_in_act_prop(port_id, mapper_params);
265 [ # # ]: 0 : if (rc)
266 : : return rc;
267 : :
268 : : /* Set MARK */
269 : 0 : rc = ulp_set_mark_in_act_prop(port_id, mapper_params);
270 [ # # ]: 0 : if (rc)
271 : 0 : return rc;
272 : :
273 : : return 0;
274 : : }
275 : :
276 : : struct bnxt_ulp_def_param_handler ulp_def_handler_tbl[] = {
277 : : [BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID] = {
278 : : .vfr_func = ulp_df_dev_port_handler }
279 : : };
280 : :
281 : : /*
282 : : * Function to create default rules for the following paths
283 : : * 1) Device PORT to DPDK App
284 : : * 2) DPDK App to Device PORT
285 : : * 3) VF Representor to VF
286 : : * 4) VF to VF Representor
287 : : *
288 : : * eth_dev [in] Ptr to rte eth device.
289 : : * param_list [in] Ptr to a list of parameters (Currently, only DPDK port_id).
290 : : * ulp_class_tid [in] Class template ID number.
291 : : * flow_id [out] Ptr to flow identifier.
292 : : *
293 : : * Returns 0 on success or negative number on failure.
294 : : */
295 : : int32_t
296 : 0 : ulp_default_flow_create(struct rte_eth_dev *eth_dev,
297 : : struct ulp_tlv_param *param_list,
298 : : uint32_t ulp_class_tid,
299 : : uint16_t port_id,
300 : : uint32_t *flow_id)
301 : : {
302 : : struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
303 : : uint64_t comp_fld[BNXT_ULP_CF_IDX_LAST];
304 : : struct bnxt_ulp_mapper_create_parms mapper_params = { 0 };
305 : : struct ulp_rte_act_prop act_prop;
306 : 0 : struct ulp_rte_act_bitmap act = { 0 };
307 : : struct bnxt_ulp_context *ulp_ctx;
308 : 0 : uint32_t type, ulp_flags = 0, fid;
309 : : int rc = 0;
310 : :
311 : : memset(&mapper_params, 0, sizeof(mapper_params));
312 : : memset(hdr_field, 0, sizeof(hdr_field));
313 : : memset(comp_fld, 0, sizeof(comp_fld));
314 : : memset(&act_prop, 0, sizeof(act_prop));
315 : :
316 : 0 : mapper_params.hdr_field = hdr_field;
317 : 0 : mapper_params.act = &act;
318 : 0 : mapper_params.act_prop = &act_prop;
319 : 0 : mapper_params.comp_fld = comp_fld;
320 : 0 : mapper_params.class_tid = ulp_class_tid;
321 : 0 : mapper_params.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT;
322 : 0 : mapper_params.port_id = eth_dev->data->port_id;
323 : :
324 : 0 : ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
325 [ # # ]: 0 : if (!ulp_ctx) {
326 : 0 : BNXT_TF_DBG(ERR,
327 : : "ULP is not init'ed. Fail to create dflt flow.\n");
328 : 0 : return -EINVAL;
329 : : }
330 : :
331 : : /* update the vf rep flag */
332 [ # # ]: 0 : if (bnxt_ulp_cntxt_ptr2_ulp_flags_get(ulp_ctx, &ulp_flags)) {
333 : 0 : BNXT_TF_DBG(ERR, "Error in getting ULP context flags\n");
334 : 0 : return -EINVAL;
335 : : }
336 [ # # ]: 0 : if (ULP_VF_REP_IS_ENABLED(ulp_flags))
337 : 0 : ULP_COMP_FLD_IDX_WR(&mapper_params,
338 : : BNXT_ULP_CF_IDX_VFR_MODE, 1);
339 : :
340 : 0 : type = param_list->type;
341 [ # # ]: 0 : while (type != BNXT_ULP_DF_PARAM_TYPE_LAST) {
342 [ # # ]: 0 : if (ulp_def_handler_tbl[type].vfr_func) {
343 : 0 : rc = ulp_def_handler_tbl[type].vfr_func(ulp_ctx,
344 : : param_list,
345 : : &mapper_params);
346 [ # # ]: 0 : if (rc) {
347 : 0 : BNXT_TF_DBG(ERR,
348 : : "Failed to create default flow.\n");
349 : 0 : return rc;
350 : : }
351 : : }
352 : :
353 : 0 : param_list++;
354 : 0 : type = param_list->type;
355 : : }
356 : :
357 : : /* Get the function id */
358 [ # # ]: 0 : if (ulp_port_db_port_func_id_get(ulp_ctx,
359 : : port_id,
360 : : &mapper_params.func_id)) {
361 : 0 : BNXT_TF_DBG(ERR, "conversion of port to func id failed\n");
362 : 0 : goto err1;
363 : : }
364 : :
365 : : /* update the VF meta function id */
366 [ # # ]: 0 : ULP_COMP_FLD_IDX_WR(&mapper_params, BNXT_ULP_CF_IDX_VF_META_FID,
367 : : BNXT_ULP_META_VF_FLAG | mapper_params.func_id);
368 : :
369 : 0 : BNXT_TF_DBG(DEBUG, "Creating default flow with template id: %u\n",
370 : : ulp_class_tid);
371 : :
372 : : /* Protect flow creation */
373 [ # # ]: 0 : if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
374 : 0 : BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
375 : 0 : goto err1;
376 : : }
377 : :
378 : 0 : rc = ulp_flow_db_fid_alloc(ulp_ctx, mapper_params.flow_type,
379 : 0 : mapper_params.func_id, &fid);
380 [ # # ]: 0 : if (rc) {
381 : 0 : BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
382 : 0 : goto err2;
383 : : }
384 : :
385 : 0 : mapper_params.flow_id = fid;
386 : 0 : rc = ulp_mapper_flow_create(ulp_ctx, &mapper_params);
387 [ # # ]: 0 : if (rc)
388 : 0 : goto err3;
389 : :
390 : 0 : bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
391 : 0 : *flow_id = fid;
392 : 0 : return 0;
393 : :
394 : : err3:
395 : 0 : ulp_flow_db_fid_free(ulp_ctx, mapper_params.flow_type, fid);
396 : 0 : err2:
397 : 0 : bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
398 : 0 : err1:
399 : 0 : BNXT_TF_DBG(ERR, "Failed to create default flow.\n");
400 : 0 : return rc;
401 : : }
402 : :
403 : : /*
404 : : * Function to destroy default rules for the following paths
405 : : * 1) Device PORT to DPDK App
406 : : * 2) DPDK App to Device PORT
407 : : * 3) VF Representor to VF
408 : : * 4) VF to VF Representor
409 : : *
410 : : * eth_dev [in] Ptr to rte eth device.
411 : : * flow_id [in] Flow identifier.
412 : : *
413 : : * Returns 0 on success or negative number on failure.
414 : : */
415 : : int32_t
416 : 0 : ulp_default_flow_destroy(struct rte_eth_dev *eth_dev, uint32_t flow_id)
417 : : {
418 : : struct bnxt_ulp_context *ulp_ctx;
419 : : int rc = 0;
420 : :
421 : 0 : ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
422 [ # # ]: 0 : if (!ulp_ctx) {
423 : 0 : BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
424 : 0 : return -EINVAL;
425 : : }
426 : :
427 [ # # ]: 0 : if (!flow_id) {
428 : 0 : BNXT_TF_DBG(DEBUG, "invalid flow id zero\n");
429 : 0 : return rc;
430 : : }
431 : :
432 [ # # ]: 0 : if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
433 : 0 : BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
434 : 0 : return -EINVAL;
435 : : }
436 : 0 : rc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_DEFAULT,
437 : : flow_id);
438 [ # # ]: 0 : if (rc)
439 : 0 : BNXT_TF_DBG(ERR, "Failed to destroy flow.\n");
440 : 0 : bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
441 : :
442 : 0 : return rc;
443 : : }
444 : :
445 : : void
446 : 0 : bnxt_ulp_destroy_df_rules(struct bnxt *bp, bool global)
447 : : {
448 : : struct bnxt_ulp_df_rule_info *info;
449 : : uint16_t port_id;
450 : :
451 [ # # # # : 0 : if (!BNXT_TRUFLOW_EN(bp) ||
# # ]
452 [ # # ]: 0 : rte_eth_dev_is_repr(bp->eth_dev))
453 : : return;
454 : :
455 [ # # # # ]: 0 : if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
456 : : return;
457 : :
458 : : /* Delete default rules per port */
459 [ # # ]: 0 : if (!global) {
460 : 0 : port_id = bp->eth_dev->data->port_id;
461 : 0 : info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
462 [ # # ]: 0 : if (!info->valid)
463 : : return;
464 : :
465 : 0 : ulp_default_flow_destroy(bp->eth_dev,
466 : : info->def_port_flow_id);
467 : : memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
468 : 0 : return;
469 : : }
470 : :
471 : : /* Delete default rules for all ports */
472 [ # # ]: 0 : for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
473 : 0 : info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
474 [ # # ]: 0 : if (!info->valid)
475 : 0 : continue;
476 : :
477 : 0 : ulp_default_flow_destroy(bp->eth_dev,
478 : : info->def_port_flow_id);
479 : : memset(info, 0, sizeof(struct bnxt_ulp_df_rule_info));
480 : : }
481 : : }
482 : :
483 : : static int32_t
484 : 0 : bnxt_create_port_app_df_rule(struct bnxt *bp, uint8_t flow_type,
485 : : uint32_t *flow_id)
486 : : {
487 : 0 : uint16_t port_id = bp->eth_dev->data->port_id;
488 : 0 : struct ulp_tlv_param param_list[] = {
489 : : {
490 : : .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
491 : : .length = 2,
492 : : .value = {(port_id >> 8) & 0xff, port_id & 0xff}
493 : : },
494 : : {
495 : : .type = BNXT_ULP_DF_PARAM_TYPE_LAST,
496 : : .length = 0,
497 : : .value = {0}
498 : : }
499 : : };
500 : :
501 [ # # ]: 0 : if (!flow_type) {
502 : 0 : *flow_id = 0;
503 : 0 : return 0;
504 : : }
505 : 0 : return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
506 : : port_id, flow_id);
507 : : }
508 : :
509 : : int32_t
510 : 0 : bnxt_ulp_create_df_rules(struct bnxt *bp)
511 : : {
512 : : struct bnxt_ulp_df_rule_info *info;
513 : : uint16_t port_id;
514 : : int rc = 0;
515 : :
516 [ # # # # : 0 : if (!BNXT_TRUFLOW_EN(bp) ||
# # ]
517 [ # # # # ]: 0 : rte_eth_dev_is_repr(bp->eth_dev) || !bp->ulp_ctx)
518 : : return 0;
519 : :
520 : 0 : port_id = bp->eth_dev->data->port_id;
521 : 0 : info = &bp->ulp_ctx->cfg_data->df_rule_info[port_id];
522 : 0 : rc = bnxt_create_port_app_df_rule(bp,
523 : : BNXT_ULP_DF_TPL_DEFAULT_UPLINK_PORT,
524 : : &info->def_port_flow_id);
525 [ # # ]: 0 : if (rc) {
526 : 0 : BNXT_TF_DBG(ERR,
527 : : "Failed to create port to app default rule\n");
528 : 0 : return rc;
529 : : }
530 : :
531 : 0 : rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
532 : : info->def_port_flow_id,
533 : : &bp->tx_cfa_action);
534 : :
535 [ # # # # ]: 0 : if (rc || BNXT_TESTPMD_EN(bp))
536 : 0 : bp->tx_cfa_action = 0;
537 : :
538 : 0 : info->valid = true;
539 : 0 : return 0;
540 : : }
541 : :
542 : : static int32_t
543 : 0 : bnxt_create_port_vfr_default_rule(struct bnxt *bp,
544 : : uint8_t flow_type,
545 : : uint16_t vfr_port_id,
546 : : uint32_t *flow_id)
547 : : {
548 : 0 : struct ulp_tlv_param param_list[] = {
549 : : {
550 : : .type = BNXT_ULP_DF_PARAM_TYPE_DEV_PORT_ID,
551 : : .length = 2,
552 : : .value = {(vfr_port_id >> 8) & 0xff, vfr_port_id & 0xff}
553 : : },
554 : : {
555 : : .type = BNXT_ULP_DF_PARAM_TYPE_LAST,
556 : : .length = 0,
557 : : .value = {0}
558 : : }
559 : : };
560 : 0 : return ulp_default_flow_create(bp->eth_dev, param_list, flow_type,
561 : : vfr_port_id,
562 : : flow_id);
563 : : }
564 : :
565 : : int32_t
566 : 0 : bnxt_ulp_create_vfr_default_rules(struct rte_eth_dev *vfr_ethdev)
567 : : {
568 : : struct bnxt_ulp_vfr_rule_info *info;
569 : 0 : struct bnxt_representor *vfr = vfr_ethdev->data->dev_private;
570 : 0 : struct rte_eth_dev *parent_dev = vfr->parent_dev;
571 : 0 : struct bnxt *bp = parent_dev->data->dev_private;
572 : 0 : uint16_t vfr_port_id = vfr_ethdev->data->port_id;
573 : : uint16_t port_id;
574 : : int rc;
575 : :
576 [ # # # # : 0 : if (!bp || !BNXT_TRUFLOW_EN(bp))
# # ]
577 : : return 0;
578 : :
579 : : port_id = vfr_ethdev->data->port_id;
580 : 0 : info = bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(bp->ulp_ctx, port_id);
581 : :
582 [ # # ]: 0 : if (!info) {
583 : 0 : BNXT_TF_DBG(ERR, "Failed to get vfr ulp context\n");
584 : 0 : return -EINVAL;
585 : : }
586 : :
587 [ # # ]: 0 : if (info->valid) {
588 : 0 : BNXT_TF_DBG(ERR, "VFR already allocated\n");
589 : 0 : return -EINVAL;
590 : : }
591 : :
592 : : memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
593 : 0 : rc = bnxt_create_port_vfr_default_rule(bp, BNXT_ULP_DF_TPL_DEFAULT_VFR,
594 : : vfr_port_id,
595 : : &info->vfr_flow_id);
596 [ # # ]: 0 : if (rc) {
597 : 0 : BNXT_TF_DBG(ERR, "Failed to create VFR default rule\n");
598 : 0 : goto error;
599 : : }
600 : 0 : rc = ulp_default_flow_db_cfa_action_get(bp->ulp_ctx,
601 : : info->vfr_flow_id,
602 : : &vfr->vfr_tx_cfa_action);
603 [ # # ]: 0 : if (rc) {
604 : 0 : BNXT_TF_DBG(ERR, "Failed to get the tx cfa action\n");
605 : 0 : goto error;
606 : : }
607 : :
608 : : /* Update the other details */
609 : 0 : info->valid = true;
610 : 0 : info->parent_port_id = bp->eth_dev->data->port_id;
611 : 0 : return 0;
612 : :
613 : 0 : error:
614 [ # # ]: 0 : if (info->vfr_flow_id)
615 : 0 : ulp_default_flow_destroy(bp->eth_dev, info->vfr_flow_id);
616 : : return rc;
617 : : }
618 : :
619 : : int32_t
620 : 0 : bnxt_ulp_delete_vfr_default_rules(struct bnxt_representor *vfr)
621 : : {
622 : : struct bnxt_ulp_vfr_rule_info *info;
623 : 0 : struct rte_eth_dev *parent_dev = vfr->parent_dev;
624 : 0 : struct bnxt *bp = parent_dev->data->dev_private;
625 : :
626 [ # # # # : 0 : if (!bp || !BNXT_TRUFLOW_EN(bp))
# # ]
627 : : return 0;
628 : 0 : info = bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(bp->ulp_ctx,
629 : : vfr->dpdk_port_id);
630 [ # # ]: 0 : if (!info) {
631 : 0 : BNXT_TF_DBG(ERR, "Failed to get vfr ulp context\n");
632 : 0 : return -EINVAL;
633 : : }
634 : :
635 [ # # ]: 0 : if (!info->valid) {
636 : 0 : BNXT_TF_DBG(ERR, "VFR already freed\n");
637 : 0 : return -EINVAL;
638 : : }
639 : 0 : ulp_default_flow_destroy(bp->eth_dev, info->vfr_flow_id);
640 : 0 : vfr->vfr_tx_cfa_action = 0;
641 : : memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
642 : 0 : return 0;
643 : : }
|