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_parser_params params;
71 struct bnxt_ulp_context *ulp_ctx = NULL;
72 uint32_t class_id, act_tmpl;
73 struct rte_flow *flow_id;
74 uint32_t app_priority;
80 if (bnxt_ulp_flow_validate_args(attr,
82 error) == BNXT_TF_RC_ERROR) {
83 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
87 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
89 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
93 /* Initialize the parser params */
94 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
97 params.dir = ULP_DIR_EGRESS;
99 /* copy the device port id and direction for further processing */
100 buffer = params.hdr_field[BNXT_ULP_HDR_FIELD_SVIF_INDEX].spec;
101 rte_memcpy(buffer, &dev->data->port_id, sizeof(uint16_t));
103 /* Set the implicit vnic in the action property */
104 vnic = (uint32_t)bnxt_get_vnic_id(dev->data->port_id);
106 rte_memcpy(¶ms.act_prop.act_details[BNXT_ULP_ACT_PROP_IDX_VNIC],
107 &vnic, BNXT_ULP_ACT_PROP_SZ_VNIC);
109 /* Parse the rte flow pattern */
110 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms);
111 if (ret != BNXT_TF_RC_SUCCESS)
114 /* Parse the rte flow action */
115 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
116 if (ret != BNXT_TF_RC_SUCCESS)
119 ret = ulp_matcher_pattern_match(¶ms, &class_id);
121 if (ret != BNXT_TF_RC_SUCCESS)
124 ret = ulp_matcher_action_match(¶ms, &act_tmpl);
125 if (ret != BNXT_TF_RC_SUCCESS)
128 app_priority = attr->priority;
129 /* call the ulp mapper to create the flow in the hardware */
130 ret = ulp_mapper_flow_create(ulp_ctx,
140 flow_id = (struct rte_flow *)((uintptr_t)fid);
145 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
146 "Failed to create flow.");
150 /* Function to validate the rte flow. */
152 bnxt_ulp_flow_validate(struct rte_eth_dev *dev __rte_unused,
153 const struct rte_flow_attr *attr,
154 const struct rte_flow_item pattern[],
155 const struct rte_flow_action actions[],
156 struct rte_flow_error *error)
158 struct ulp_rte_parser_params params;
159 uint32_t class_id, act_tmpl;
162 if (bnxt_ulp_flow_validate_args(attr,
164 error) == BNXT_TF_RC_ERROR) {
165 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
169 /* Initialize the parser params */
170 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params));
173 params.dir = ULP_DIR_EGRESS;
175 /* Parse the rte flow pattern */
176 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms);
177 if (ret != BNXT_TF_RC_SUCCESS)
180 /* Parse the rte flow action */
181 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms);
182 if (ret != BNXT_TF_RC_SUCCESS)
185 ret = ulp_matcher_pattern_match(¶ms, &class_id);
187 if (ret != BNXT_TF_RC_SUCCESS)
190 ret = ulp_matcher_action_match(¶ms, &act_tmpl);
191 if (ret != BNXT_TF_RC_SUCCESS)
194 /* all good return success */
198 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
199 "Failed to validate flow.");
203 /* Function to destroy the rte flow. */
205 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
206 struct rte_flow *flow,
207 struct rte_flow_error *error)
210 struct bnxt_ulp_context *ulp_ctx;
213 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
215 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
216 rte_flow_error_set(error, EINVAL,
217 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
218 "Failed to destroy flow.");
222 fid = (uint32_t)(uintptr_t)flow;
224 ret = ulp_mapper_flow_destroy(ulp_ctx, fid);
226 rte_flow_error_set(error, -ret,
227 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
228 "Failed to destroy flow.");
233 /* Function to destroy the rte flows. */
235 bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
236 struct rte_flow_error *error)
238 struct bnxt_ulp_context *ulp_ctx;
242 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
244 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
245 rte_flow_error_set(error, EINVAL,
246 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
247 "Failed to flush flow.");
250 bp = eth_dev->data->dev_private;
252 /* Free the resources for the last device */
253 if (!ulp_ctx_deinit_allowed(bp))
256 ret = ulp_flow_db_flush_flows(ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
258 rte_flow_error_set(error, ret,
259 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
260 "Failed to flush flow.");
264 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
265 .validate = bnxt_ulp_flow_validate,
266 .create = bnxt_ulp_flow_create,
267 .destroy = bnxt_ulp_flow_destroy,
268 .flush = bnxt_ulp_flow_flush,