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 bnxt_ulp_mapper_create_parms mapper_cparms = { 0 };
71 struct ulp_rte_parser_params params;
72 struct bnxt_ulp_context *ulp_ctx;
73 uint32_t class_id, act_tmpl;
74 struct rte_flow *flow_id;
78 if (bnxt_ulp_flow_validate_args(attr,
80 error) == BNXT_TF_RC_ERROR) {
81 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
85 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
87 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
91 /* Initialize the parser params */
92 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
93 params.ulp_ctx = ulp_ctx;
96 params.dir = ULP_DIR_EGRESS;
98 /* copy the device port id and direction for further processing */
99 ULP_UTIL_CHF_IDX_WR(¶ms, BNXT_ULP_CHF_IDX_INCOMING_IF,
101 ULP_UTIL_CHF_IDX_WR(¶ms, BNXT_ULP_CHF_IDX_DIRECTION, params.dir);
103 /* Parse the rte flow pattern */
104 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms);
105 if (ret != BNXT_TF_RC_SUCCESS)
108 /* Parse the rte flow action */
109 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
110 if (ret != BNXT_TF_RC_SUCCESS)
113 ret = ulp_matcher_pattern_match(¶ms, &class_id);
114 if (ret != BNXT_TF_RC_SUCCESS)
117 ret = ulp_matcher_action_match(¶ms, &act_tmpl);
118 if (ret != BNXT_TF_RC_SUCCESS)
121 mapper_cparms.app_priority = attr->priority;
122 mapper_cparms.hdr_bitmap = ¶ms.hdr_bitmap;
123 mapper_cparms.hdr_field = params.hdr_field;
124 mapper_cparms.act = ¶ms.act_bitmap;
125 mapper_cparms.act_prop = ¶ms.act_prop;
126 mapper_cparms.class_tid = class_id;
127 mapper_cparms.act_tid = act_tmpl;
128 mapper_cparms.func_id = bnxt_get_fw_func_id(dev->data->port_id);
129 mapper_cparms.dir = params.dir;
131 /* Call the ulp mapper to create the flow in the hardware. */
132 ret = ulp_mapper_flow_create(ulp_ctx, &mapper_cparms, &fid);
134 flow_id = (struct rte_flow *)((uintptr_t)fid);
139 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
140 "Failed to create flow.");
144 /* Function to validate the rte flow. */
146 bnxt_ulp_flow_validate(struct rte_eth_dev *dev,
147 const struct rte_flow_attr *attr,
148 const struct rte_flow_item pattern[],
149 const struct rte_flow_action actions[],
150 struct rte_flow_error *error)
152 struct ulp_rte_parser_params params;
153 uint32_t class_id, act_tmpl;
155 struct bnxt_ulp_context *ulp_ctx;
157 if (bnxt_ulp_flow_validate_args(attr,
159 error) == BNXT_TF_RC_ERROR) {
160 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
164 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
166 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
170 /* Initialize the parser params */
171 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
172 params.ulp_ctx = ulp_ctx;
175 params.dir = ULP_DIR_EGRESS;
177 /* Parse the rte flow pattern */
178 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms);
179 if (ret != BNXT_TF_RC_SUCCESS)
182 /* Parse the rte flow action */
183 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
184 if (ret != BNXT_TF_RC_SUCCESS)
187 ret = ulp_matcher_pattern_match(¶ms, &class_id);
189 if (ret != BNXT_TF_RC_SUCCESS)
192 ret = ulp_matcher_action_match(¶ms, &act_tmpl);
193 if (ret != BNXT_TF_RC_SUCCESS)
196 /* all good return success */
200 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
201 "Failed to validate flow.");
205 /* Function to destroy the rte flow. */
207 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
208 struct rte_flow *flow,
209 struct rte_flow_error *error)
212 struct bnxt_ulp_context *ulp_ctx;
216 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
218 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
219 rte_flow_error_set(error, EINVAL,
220 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
221 "Failed to destroy flow.");
225 flow_id = (uint32_t)(uintptr_t)flow;
226 func_id = bnxt_get_fw_func_id(dev->data->port_id);
228 if (ulp_flow_db_validate_flow_func(ulp_ctx, flow_id, func_id) ==
230 BNXT_TF_DBG(ERR, "Incorrect device params\n");
231 rte_flow_error_set(error, EINVAL,
232 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
233 "Failed to destroy flow.");
237 ret = ulp_mapper_flow_destroy(ulp_ctx, flow_id);
239 rte_flow_error_set(error, -ret,
240 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
241 "Failed to destroy flow.");
246 /* Function to destroy the rte flows. */
248 bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
249 struct rte_flow_error *error)
251 struct bnxt_ulp_context *ulp_ctx;
256 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
258 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
259 rte_flow_error_set(error, EINVAL,
260 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
261 "Failed to flush flow.");
264 bp = eth_dev->data->dev_private;
266 /* Free the resources for the last device */
267 if (ulp_ctx_deinit_allowed(bp)) {
268 ret = ulp_flow_db_session_flow_flush(ulp_ctx);
269 } else if (bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctx)) {
270 func_id = bnxt_get_fw_func_id(eth_dev->data->port_id);
271 ret = ulp_flow_db_function_flow_flush(ulp_ctx, func_id);
274 rte_flow_error_set(error, ret,
275 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
276 "Failed to flush flow.");
280 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
281 .validate = bnxt_ulp_flow_validate,
282 .create = bnxt_ulp_flow_create,
283 .destroy = bnxt_ulp_flow_destroy,
284 .flush = bnxt_ulp_flow_flush,