1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2020 Broadcom
7 #include "bnxt_tf_common.h"
8 #include "ulp_rte_parser.h"
9 #include "ulp_matcher.h"
10 #include "ulp_flow_db.h"
11 #include "ulp_mapper.h"
12 #include <rte_malloc.h>
15 bnxt_ulp_flow_validate_args(const struct rte_flow_attr *attr,
16 const struct rte_flow_item pattern[],
17 const struct rte_flow_action actions[],
18 struct rte_flow_error *error)
20 /* Perform the validation of the arguments for null */
22 return BNXT_TF_RC_ERROR;
25 rte_flow_error_set(error,
27 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
30 return BNXT_TF_RC_ERROR;
34 rte_flow_error_set(error,
36 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
39 return BNXT_TF_RC_ERROR;
43 rte_flow_error_set(error,
45 RTE_FLOW_ERROR_TYPE_ATTR,
48 return BNXT_TF_RC_ERROR;
51 if (attr->egress && attr->ingress) {
52 rte_flow_error_set(error,
54 RTE_FLOW_ERROR_TYPE_ATTR,
56 "EGRESS AND INGRESS UNSUPPORTED");
57 return BNXT_TF_RC_ERROR;
59 return BNXT_TF_RC_SUCCESS;
62 /* Function to create the rte flow. */
63 static struct rte_flow *
64 bnxt_ulp_flow_create(struct rte_eth_dev *dev,
65 const struct rte_flow_attr *attr,
66 const struct rte_flow_item pattern[],
67 const struct rte_flow_action actions[],
68 struct rte_flow_error *error)
70 struct ulp_rte_hdr_bitmap hdr_bitmap;
71 struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
72 struct ulp_rte_act_bitmap act_bitmap;
73 struct ulp_rte_act_prop act_prop;
74 enum ulp_direction_type dir = ULP_DIR_INGRESS;
75 uint32_t class_id, act_tmpl;
76 uint32_t app_priority;
78 struct bnxt_ulp_context *ulp_ctx = NULL;
81 struct rte_flow *flow_id;
84 if (bnxt_ulp_flow_validate_args(attr,
86 error) == BNXT_TF_RC_ERROR) {
87 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
91 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
93 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
97 /* clear the header bitmap and field structure */
98 memset(&hdr_bitmap, 0, sizeof(struct ulp_rte_hdr_bitmap));
99 memset(hdr_field, 0, sizeof(hdr_field));
100 memset(&act_bitmap, 0, sizeof(act_bitmap));
101 memset(&act_prop, 0, sizeof(act_prop));
103 svif = bnxt_get_svif(dev->data->port_id, false);
104 BNXT_TF_DBG(ERR, "SVIF for port[%d][port]=0x%08x\n",
105 dev->data->port_id, svif);
107 hdr_field[BNXT_ULP_HDR_FIELD_SVIF_INDEX].size = sizeof(svif);
108 hdr_field[BNXT_ULP_HDR_FIELD_SVIF_INDEX].spec[0] = svif;
109 hdr_field[BNXT_ULP_HDR_FIELD_SVIF_INDEX].mask[0] = -1;
110 ULP_BITMAP_SET(hdr_bitmap.bits, BNXT_ULP_HDR_BIT_SVIF);
113 * VNIC is being pushed as 32bit and the pop will take care of
116 vnic = (uint32_t)bnxt_get_vnic_id(dev->data->port_id);
118 rte_memcpy(&act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
119 &vnic, BNXT_ULP_ACT_PROP_SZ_VNIC);
121 /* Parse the rte flow pattern */
122 ret = bnxt_ulp_rte_parser_hdr_parse(pattern,
125 if (ret != BNXT_TF_RC_SUCCESS)
128 /* Parse the rte flow action */
129 ret = bnxt_ulp_rte_parser_act_parse(actions,
132 if (ret != BNXT_TF_RC_SUCCESS)
136 dir = ULP_DIR_EGRESS;
138 ret = ulp_matcher_pattern_match(dir, &hdr_bitmap, hdr_field,
139 &act_bitmap, &class_id);
141 if (ret != BNXT_TF_RC_SUCCESS)
144 ret = ulp_matcher_action_match(dir, &act_bitmap, &act_tmpl);
145 if (ret != BNXT_TF_RC_SUCCESS)
148 app_priority = attr->priority;
149 /* call the ulp mapper to create the flow in the hardware */
150 ret = ulp_mapper_flow_create(ulp_ctx,
160 flow_id = (struct rte_flow *)((uintptr_t)fid);
165 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
166 "Failed to create flow.");
170 /* Function to validate the rte flow. */
172 bnxt_ulp_flow_validate(struct rte_eth_dev *dev __rte_unused,
173 const struct rte_flow_attr *attr,
174 const struct rte_flow_item pattern[],
175 const struct rte_flow_action actions[],
176 struct rte_flow_error *error)
178 struct ulp_rte_hdr_bitmap hdr_bitmap;
179 struct ulp_rte_hdr_field hdr_field[BNXT_ULP_PROTO_HDR_MAX];
180 struct ulp_rte_act_bitmap act_bitmap;
181 struct ulp_rte_act_prop act_prop;
182 enum ulp_direction_type dir = ULP_DIR_INGRESS;
183 uint32_t class_id, act_tmpl;
186 if (bnxt_ulp_flow_validate_args(attr,
188 error) == BNXT_TF_RC_ERROR) {
189 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
193 /* clear the header bitmap and field structure */
194 memset(&hdr_bitmap, 0, sizeof(struct ulp_rte_hdr_bitmap));
195 memset(hdr_field, 0, sizeof(hdr_field));
196 memset(&act_bitmap, 0, sizeof(act_bitmap));
197 memset(&act_prop, 0, sizeof(act_prop));
199 /* Parse the rte flow pattern */
200 ret = bnxt_ulp_rte_parser_hdr_parse(pattern,
203 if (ret != BNXT_TF_RC_SUCCESS)
206 /* Parse the rte flow action */
207 ret = bnxt_ulp_rte_parser_act_parse(actions,
210 if (ret != BNXT_TF_RC_SUCCESS)
214 dir = ULP_DIR_EGRESS;
216 ret = ulp_matcher_pattern_match(dir, &hdr_bitmap, hdr_field,
217 &act_bitmap, &class_id);
219 if (ret != BNXT_TF_RC_SUCCESS)
222 ret = ulp_matcher_action_match(dir, &act_bitmap, &act_tmpl);
223 if (ret != BNXT_TF_RC_SUCCESS)
226 /* all good return success */
230 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
231 "Failed to validate flow.");
235 /* Function to destroy the rte flow. */
237 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
238 struct rte_flow *flow,
239 struct rte_flow_error *error)
242 struct bnxt_ulp_context *ulp_ctx;
245 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
247 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
248 rte_flow_error_set(error, EINVAL,
249 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
250 "Failed to destroy flow.");
254 fid = (uint32_t)(uintptr_t)flow;
256 ret = ulp_mapper_flow_destroy(ulp_ctx, fid);
258 rte_flow_error_set(error, -ret,
259 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
260 "Failed to destroy flow.");
265 /* Function to destroy the rte flows. */
267 bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
268 struct rte_flow_error *error)
270 struct bnxt_ulp_context *ulp_ctx;
274 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
276 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
277 rte_flow_error_set(error, EINVAL,
278 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
279 "Failed to flush flow.");
282 bp = eth_dev->data->dev_private;
284 /* Free the resources for the last device */
285 if (!ulp_ctx_deinit_allowed(bp))
288 ret = ulp_flow_db_flush_flows(ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
290 rte_flow_error_set(error, ret,
291 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
292 "Failed to flush flow.");
296 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
297 .validate = bnxt_ulp_flow_validate,
298 .create = bnxt_ulp_flow_create,
299 .destroy = bnxt_ulp_flow_destroy,
300 .flush = bnxt_ulp_flow_flush,