net/bnxt: add capability option for socket redirect
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp_flow.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #include "bnxt.h"
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 "ulp_fc_mgr.h"
13 #include "ulp_port_db.h"
14 #include "ulp_ha_mgr.h"
15 #include "ulp_tun.h"
16 #include <rte_malloc.h>
17
18 static int32_t
19 bnxt_ulp_flow_validate_args(const struct rte_flow_attr *attr,
20                             const struct rte_flow_item pattern[],
21                             const struct rte_flow_action actions[],
22                             struct rte_flow_error *error)
23 {
24         /* Perform the validation of the arguments for null */
25         if (!error)
26                 return BNXT_TF_RC_ERROR;
27
28         if (!pattern) {
29                 rte_flow_error_set(error,
30                                    EINVAL,
31                                    RTE_FLOW_ERROR_TYPE_ITEM_NUM,
32                                    NULL,
33                                    "NULL pattern.");
34                 return BNXT_TF_RC_ERROR;
35         }
36
37         if (!actions) {
38                 rte_flow_error_set(error,
39                                    EINVAL,
40                                    RTE_FLOW_ERROR_TYPE_ACTION_NUM,
41                                    NULL,
42                                    "NULL action.");
43                 return BNXT_TF_RC_ERROR;
44         }
45
46         if (!attr) {
47                 rte_flow_error_set(error,
48                                    EINVAL,
49                                    RTE_FLOW_ERROR_TYPE_ATTR,
50                                    NULL,
51                                    "NULL attribute.");
52                 return BNXT_TF_RC_ERROR;
53         }
54
55         if (attr->egress && attr->ingress) {
56                 rte_flow_error_set(error,
57                                    EINVAL,
58                                    RTE_FLOW_ERROR_TYPE_ATTR,
59                                    attr,
60                                    "EGRESS AND INGRESS UNSUPPORTED");
61                 return BNXT_TF_RC_ERROR;
62         }
63         return BNXT_TF_RC_SUCCESS;
64 }
65
66 static inline void
67 bnxt_ulp_set_dir_attributes(struct ulp_rte_parser_params *params,
68                             const struct rte_flow_attr *attr)
69 {
70         /* Set the flow attributes */
71         if (attr->egress)
72                 params->dir_attr |= BNXT_ULP_FLOW_ATTR_EGRESS;
73         if (attr->ingress)
74                 params->dir_attr |= BNXT_ULP_FLOW_ATTR_INGRESS;
75 #if RTE_VERSION_NUM(17, 11, 10, 16) < RTE_VERSION
76         if (attr->transfer)
77                 params->dir_attr |= BNXT_ULP_FLOW_ATTR_TRANSFER;
78 #endif
79 }
80
81 void
82 bnxt_ulp_init_mapper_params(struct bnxt_ulp_mapper_create_parms *mapper_cparms,
83                             struct ulp_rte_parser_params *params,
84                             enum bnxt_ulp_fdb_type flow_type)
85 {
86         uint32_t ulp_flags = 0;
87
88         memset(mapper_cparms, 0, sizeof(*mapper_cparms));
89         mapper_cparms->flow_type = flow_type;
90         mapper_cparms->app_priority = params->priority;
91         mapper_cparms->dir_attr = params->dir_attr;
92         mapper_cparms->class_tid = params->class_id;
93         mapper_cparms->act_tid = params->act_tmpl;
94         mapper_cparms->func_id = params->func_id;
95         mapper_cparms->hdr_bitmap = &params->hdr_bitmap;
96         mapper_cparms->enc_hdr_bitmap = &params->enc_hdr_bitmap;
97         mapper_cparms->hdr_field = params->hdr_field;
98         mapper_cparms->enc_field = params->enc_field;
99         mapper_cparms->comp_fld = params->comp_fld;
100         mapper_cparms->act = &params->act_bitmap;
101         mapper_cparms->act_prop = &params->act_prop;
102         mapper_cparms->flow_id = params->fid;
103         mapper_cparms->parent_flow = params->parent_flow;
104         mapper_cparms->child_flow = params->child_flow;
105         mapper_cparms->fld_bitmap = &params->fld_bitmap;
106         mapper_cparms->flow_pattern_id = params->flow_pattern_id;
107         mapper_cparms->act_pattern_id = params->act_pattern_id;
108         mapper_cparms->app_id = params->app_id;
109         mapper_cparms->port_id = params->port_id;
110         mapper_cparms->tun_idx = params->tun_idx;
111
112         /* update the signature fields into the computed field list */
113         ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_HDR_SIG_ID,
114                             params->hdr_sig_id);
115         ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_FLOW_SIG_ID,
116                             params->flow_sig_id);
117
118         if (bnxt_ulp_cntxt_ptr2_ulp_flags_get(params->ulp_ctx, &ulp_flags))
119                 return;
120
121         /* update the WC Priority flag */
122         if (ULP_HIGH_AVAIL_IS_ENABLED(ulp_flags)) {
123                 enum ulp_ha_mgr_region region = ULP_HA_REGION_LOW;
124                 int32_t rc;
125
126                 rc = ulp_ha_mgr_region_get(params->ulp_ctx, &region);
127                 if (rc)
128                         BNXT_TF_DBG(ERR, "Unable to get WC region\n");
129                 if (region == ULP_HA_REGION_HI)
130                         ULP_COMP_FLD_IDX_WR(params,
131                                             BNXT_ULP_CF_IDX_WC_IS_HA_HIGH_REG,
132                                             1);
133         }
134
135         /* Update the socket direct flag */
136         if (ULP_SOCKET_DIRECT_IS_ENABLED(ulp_flags))
137                 ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_SOCKET_DIRECT, 1);
138 }
139
140 /* Function to create the rte flow. */
141 static struct rte_flow *
142 bnxt_ulp_flow_create(struct rte_eth_dev *dev,
143                      const struct rte_flow_attr *attr,
144                      const struct rte_flow_item pattern[],
145                      const struct rte_flow_action actions[],
146                      struct rte_flow_error *error)
147 {
148         struct bnxt_ulp_mapper_create_parms mapper_cparms = { 0 };
149         struct ulp_rte_parser_params params;
150         struct bnxt_ulp_context *ulp_ctx;
151         int rc, ret = BNXT_TF_RC_ERROR;
152         struct rte_flow *flow_id;
153         uint16_t func_id;
154         uint32_t fid;
155
156         if (bnxt_ulp_flow_validate_args(attr,
157                                         pattern, actions,
158                                         error) == BNXT_TF_RC_ERROR) {
159                 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
160                 goto flow_error;
161         }
162
163         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
164         if (!ulp_ctx) {
165                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
166                 goto flow_error;
167         }
168
169         /* Initialize the parser params */
170         memset(&params, 0, sizeof(struct ulp_rte_parser_params));
171         params.ulp_ctx = ulp_ctx;
172
173         if (bnxt_ulp_cntxt_app_id_get(params.ulp_ctx, &params.app_id)) {
174                 BNXT_TF_DBG(ERR, "failed to get the app id\n");
175                 goto flow_error;
176         }
177
178         /* Set the flow attributes */
179         bnxt_ulp_set_dir_attributes(&params, attr);
180
181         /* copy the device port id and direction for further processing */
182         ULP_COMP_FLD_IDX_WR(&params, BNXT_ULP_CF_IDX_INCOMING_IF,
183                             dev->data->port_id);
184         ULP_COMP_FLD_IDX_WR(&params, BNXT_ULP_CF_IDX_DEV_PORT_ID,
185                             dev->data->port_id);
186         ULP_COMP_FLD_IDX_WR(&params, BNXT_ULP_CF_IDX_SVIF_FLAG,
187                             BNXT_ULP_INVALID_SVIF_VAL);
188
189         /* Get the function id */
190         if (ulp_port_db_port_func_id_get(ulp_ctx,
191                                          dev->data->port_id,
192                                          &func_id)) {
193                 BNXT_TF_DBG(ERR, "conversion of port to func id failed\n");
194                 goto flow_error;
195         }
196
197         /* Protect flow creation */
198         if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
199                 BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
200                 goto flow_error;
201         }
202
203         /* Allocate a Flow ID for attaching all resources for the flow to.
204          * Once allocated, all errors have to walk the list of resources and
205          * free each of them.
206          */
207         rc = ulp_flow_db_fid_alloc(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
208                                    func_id, &fid);
209         if (rc) {
210                 BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
211                 goto release_lock;
212         }
213
214         /* Parse the rte flow pattern */
215         ret = bnxt_ulp_rte_parser_hdr_parse(pattern, &params);
216         if (ret != BNXT_TF_RC_SUCCESS)
217                 goto free_fid;
218
219         /* Parse the rte flow action */
220         ret = bnxt_ulp_rte_parser_act_parse(actions, &params);
221         if (ret != BNXT_TF_RC_SUCCESS)
222                 goto free_fid;
223
224         params.fid = fid;
225         params.func_id = func_id;
226         params.priority = attr->priority;
227         params.port_id = dev->data->port_id;
228
229         /* Perform the rte flow post process */
230         bnxt_ulp_rte_parser_post_process(&params);
231
232         /* do the tunnel offload process if any */
233         ret = ulp_tunnel_offload_process(&params);
234         if (ret == BNXT_TF_RC_ERROR)
235                 goto free_fid;
236
237         ret = ulp_matcher_pattern_match(&params, &params.class_id);
238         if (ret != BNXT_TF_RC_SUCCESS)
239                 goto free_fid;
240
241         ret = ulp_matcher_action_match(&params, &params.act_tmpl);
242         if (ret != BNXT_TF_RC_SUCCESS)
243                 goto free_fid;
244
245         bnxt_ulp_init_mapper_params(&mapper_cparms, &params,
246                                     BNXT_ULP_FDB_TYPE_REGULAR);
247         /* Call the ulp mapper to create the flow in the hardware. */
248         ret = ulp_mapper_flow_create(ulp_ctx, &mapper_cparms);
249         if (ret)
250                 goto free_fid;
251
252         bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
253
254         flow_id = (struct rte_flow *)((uintptr_t)fid);
255         return flow_id;
256
257 free_fid:
258         ulp_flow_db_fid_free(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR, fid);
259 release_lock:
260         bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
261 flow_error:
262         rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
263                            "Failed to create flow.");
264         return NULL;
265 }
266
267 /* Function to validate the rte flow. */
268 static int
269 bnxt_ulp_flow_validate(struct rte_eth_dev *dev,
270                        const struct rte_flow_attr *attr,
271                        const struct rte_flow_item pattern[],
272                        const struct rte_flow_action actions[],
273                        struct rte_flow_error *error)
274 {
275         struct ulp_rte_parser_params params;
276         struct bnxt_ulp_context *ulp_ctx;
277         uint32_t class_id, act_tmpl;
278         int ret = BNXT_TF_RC_ERROR;
279
280         if (bnxt_ulp_flow_validate_args(attr,
281                                         pattern, actions,
282                                         error) == BNXT_TF_RC_ERROR) {
283                 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n");
284                 goto parse_error;
285         }
286
287         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
288         if (!ulp_ctx) {
289                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
290                 goto parse_error;
291         }
292
293         /* Initialize the parser params */
294         memset(&params, 0, sizeof(struct ulp_rte_parser_params));
295         params.ulp_ctx = ulp_ctx;
296
297         if (bnxt_ulp_cntxt_app_id_get(params.ulp_ctx, &params.app_id)) {
298                 BNXT_TF_DBG(ERR, "failed to get the app id\n");
299                 goto parse_error;
300         }
301
302         /* Set the flow attributes */
303         bnxt_ulp_set_dir_attributes(&params, attr);
304
305         /* Parse the rte flow pattern */
306         ret = bnxt_ulp_rte_parser_hdr_parse(pattern, &params);
307         if (ret != BNXT_TF_RC_SUCCESS)
308                 goto parse_error;
309
310         /* Parse the rte flow action */
311         ret = bnxt_ulp_rte_parser_act_parse(actions, &params);
312         if (ret != BNXT_TF_RC_SUCCESS)
313                 goto parse_error;
314
315         /* Perform the rte flow post process */
316         bnxt_ulp_rte_parser_post_process(&params);
317
318         /* do the tunnel offload process if any */
319         ret = ulp_tunnel_offload_process(&params);
320         if (ret == BNXT_TF_RC_ERROR)
321                 goto parse_error;
322
323         ret = ulp_matcher_pattern_match(&params, &class_id);
324
325         if (ret != BNXT_TF_RC_SUCCESS)
326                 goto parse_error;
327
328         ret = ulp_matcher_action_match(&params, &act_tmpl);
329         if (ret != BNXT_TF_RC_SUCCESS)
330                 goto parse_error;
331
332         /* all good return success */
333         return ret;
334
335 parse_error:
336         rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
337                            "Failed to validate flow.");
338         return -EINVAL;
339 }
340
341 /* Function to destroy the rte flow. */
342 int
343 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev,
344                       struct rte_flow *flow,
345                       struct rte_flow_error *error)
346 {
347         struct bnxt_ulp_context *ulp_ctx;
348         uint32_t flow_id;
349         uint16_t func_id;
350         int ret;
351
352         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev);
353         if (!ulp_ctx) {
354                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
355                 if (error)
356                         rte_flow_error_set(error, EINVAL,
357                                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
358                                            "Failed to destroy flow.");
359                 return -EINVAL;
360         }
361
362         flow_id = (uint32_t)(uintptr_t)flow;
363
364         if (ulp_port_db_port_func_id_get(ulp_ctx,
365                                          dev->data->port_id,
366                                          &func_id)) {
367                 BNXT_TF_DBG(ERR, "conversion of port to func id failed\n");
368                 if (error)
369                         rte_flow_error_set(error, EINVAL,
370                                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
371                                            "Failed to destroy flow.");
372                 return -EINVAL;
373         }
374
375         if (ulp_flow_db_validate_flow_func(ulp_ctx, flow_id, func_id) ==
376             false) {
377                 BNXT_TF_DBG(ERR, "Incorrect device params\n");
378                 if (error)
379                         rte_flow_error_set(error, EINVAL,
380                                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
381                                            "Failed to destroy flow.");
382                 return -EINVAL;
383         }
384
385         if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) {
386                 BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n");
387                 return -EINVAL;
388         }
389         ret = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
390                                       flow_id);
391         if (ret) {
392                 BNXT_TF_DBG(ERR, "Failed to destroy flow.\n");
393                 if (error)
394                         rte_flow_error_set(error, -ret,
395                                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
396                                            "Failed to destroy flow.");
397         }
398         bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx);
399
400         return ret;
401 }
402
403 /* Function to destroy the rte flows. */
404 static int32_t
405 bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev,
406                     struct rte_flow_error *error)
407 {
408         struct bnxt_ulp_context *ulp_ctx;
409         int32_t ret = 0;
410         uint16_t func_id;
411
412         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
413         if (!ulp_ctx) {
414                 return ret;
415         }
416
417         /* Free the resources for the last device */
418         if (ulp_ctx_deinit_allowed(ulp_ctx)) {
419                 ret = ulp_flow_db_session_flow_flush(ulp_ctx);
420         } else if (bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctx)) {
421                 ret = ulp_port_db_port_func_id_get(ulp_ctx,
422                                                    eth_dev->data->port_id,
423                                                    &func_id);
424                 if (!ret)
425                         ret = ulp_flow_db_function_flow_flush(ulp_ctx, func_id);
426                 else
427                         BNXT_TF_DBG(ERR, "convert port to func id failed\n");
428         }
429         if (ret)
430                 rte_flow_error_set(error, ret,
431                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
432                                    "Failed to flush flow.");
433         return ret;
434 }
435
436 /* Function to query the rte flows. */
437 static int32_t
438 bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev,
439                     struct rte_flow *flow,
440                     const struct rte_flow_action *action,
441                     void *data,
442                     struct rte_flow_error *error)
443 {
444         int rc = 0;
445         struct bnxt_ulp_context *ulp_ctx;
446         struct rte_flow_query_count *count;
447         uint32_t flow_id;
448
449         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
450         if (!ulp_ctx) {
451                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
452                 rte_flow_error_set(error, EINVAL,
453                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
454                                    "Failed to query flow.");
455                 return -EINVAL;
456         }
457
458         flow_id = (uint32_t)(uintptr_t)flow;
459
460         switch (action->type) {
461         case RTE_FLOW_ACTION_TYPE_COUNT:
462                 count = data;
463                 rc = ulp_fc_mgr_query_count_get(ulp_ctx, flow_id, count);
464                 if (rc) {
465                         rte_flow_error_set(error, EINVAL,
466                                            RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
467                                            "Failed to query flow.");
468                 }
469                 break;
470         default:
471                 rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM,
472                                    NULL, "Unsupported action item");
473         }
474
475         return rc;
476 }
477
478 /* Tunnel offload Apis */
479 #define BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS       1
480
481 static int
482 bnxt_ulp_tunnel_decap_set(struct rte_eth_dev *eth_dev,
483                           struct rte_flow_tunnel *tunnel,
484                           struct rte_flow_action **pmd_actions,
485                           uint32_t *num_of_actions,
486                           struct rte_flow_error *error)
487 {
488         struct bnxt_ulp_context *ulp_ctx;
489         struct bnxt_flow_app_tun_ent *tun_entry;
490         int32_t rc = 0;
491
492         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
493         if (ulp_ctx == NULL) {
494                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
495                 rte_flow_error_set(error, EINVAL,
496                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
497                                    "ULP context uninitialized");
498                 return -EINVAL;
499         }
500
501         if (tunnel == NULL) {
502                 BNXT_TF_DBG(ERR, "No tunnel specified\n");
503                 rte_flow_error_set(error, EINVAL,
504                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
505                                    "no tunnel specified");
506                 return -EINVAL;
507         }
508
509         if (tunnel->type != RTE_FLOW_ITEM_TYPE_VXLAN) {
510                 BNXT_TF_DBG(ERR, "Tunnel type unsupported\n");
511                 rte_flow_error_set(error, EINVAL,
512                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
513                                    "tunnel type unsupported");
514                 return -EINVAL;
515         }
516
517         rc = ulp_app_tun_search_entry(ulp_ctx, tunnel, &tun_entry);
518         if (rc < 0) {
519                 rte_flow_error_set(error, EINVAL,
520                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
521                                    "tunnel decap set failed");
522                 return -EINVAL;
523         }
524
525         rc = ulp_app_tun_entry_set_decap_action(tun_entry);
526         if (rc < 0) {
527                 rte_flow_error_set(error, EINVAL,
528                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
529                                    "tunnel decap set failed");
530                 return -EINVAL;
531         }
532
533         *pmd_actions = &tun_entry->action;
534         *num_of_actions = BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS;
535         return 0;
536 }
537
538 static int
539 bnxt_ulp_tunnel_match(struct rte_eth_dev *eth_dev,
540                       struct rte_flow_tunnel *tunnel,
541                       struct rte_flow_item **pmd_items,
542                       uint32_t *num_of_items,
543                       struct rte_flow_error *error)
544 {
545         struct bnxt_ulp_context *ulp_ctx;
546         struct bnxt_flow_app_tun_ent *tun_entry;
547         int32_t rc = 0;
548
549         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
550         if (ulp_ctx == NULL) {
551                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
552                 rte_flow_error_set(error, EINVAL,
553                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
554                                    "ULP context uninitialized");
555                 return -EINVAL;
556         }
557
558         if (tunnel == NULL) {
559                 BNXT_TF_DBG(ERR, "No tunnel specified\n");
560                 rte_flow_error_set(error, EINVAL,
561                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
562                                    "no tunnel specified");
563                 return -EINVAL;
564         }
565
566         if (tunnel->type != RTE_FLOW_ITEM_TYPE_VXLAN) {
567                 BNXT_TF_DBG(ERR, "Tunnel type unsupported\n");
568                 rte_flow_error_set(error, EINVAL,
569                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
570                                    "tunnel type unsupported");
571                 return -EINVAL;
572         }
573
574         rc = ulp_app_tun_search_entry(ulp_ctx, tunnel, &tun_entry);
575         if (rc < 0) {
576                 rte_flow_error_set(error, EINVAL,
577                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
578                                    "tunnel match set failed");
579                 return -EINVAL;
580         }
581
582         rc = ulp_app_tun_entry_set_decap_item(tun_entry);
583         if (rc < 0) {
584                 rte_flow_error_set(error, EINVAL,
585                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
586                                    "tunnel match set failed");
587                 return -EINVAL;
588         }
589
590         *pmd_items = &tun_entry->item;
591         *num_of_items = BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS;
592         return 0;
593 }
594
595 static int
596 bnxt_ulp_tunnel_decap_release(struct rte_eth_dev *eth_dev,
597                               struct rte_flow_action *pmd_actions,
598                               uint32_t num_actions,
599                               struct rte_flow_error *error)
600 {
601         struct bnxt_ulp_context *ulp_ctx;
602         struct bnxt_flow_app_tun_ent *tun_entry;
603         const struct rte_flow_action *action_item = pmd_actions;
604
605         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
606         if (ulp_ctx == NULL) {
607                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
608                 rte_flow_error_set(error, EINVAL,
609                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
610                                    "ULP context uninitialized");
611                 return -EINVAL;
612         }
613         if (num_actions != BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS) {
614                 BNXT_TF_DBG(ERR, "num actions is invalid\n");
615                 rte_flow_error_set(error, EINVAL,
616                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
617                                    "num actions is invalid");
618                 return -EINVAL;
619         }
620         while (action_item && action_item->type != RTE_FLOW_ACTION_TYPE_END) {
621                 if (action_item->type == (typeof(tun_entry->action.type))
622                     BNXT_RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) {
623                         tun_entry = ulp_app_tun_match_entry(ulp_ctx,
624                                                             action_item->conf);
625                         ulp_app_tun_entry_delete(tun_entry);
626                 }
627                 action_item++;
628         }
629         return 0;
630 }
631
632 static int
633 bnxt_ulp_tunnel_item_release(struct rte_eth_dev *eth_dev,
634                              struct rte_flow_item *pmd_items,
635                              uint32_t num_items,
636                              struct rte_flow_error *error)
637 {
638         struct bnxt_ulp_context *ulp_ctx;
639         struct bnxt_flow_app_tun_ent *tun_entry;
640
641         ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev);
642         if (ulp_ctx == NULL) {
643                 BNXT_TF_DBG(ERR, "ULP context is not initialized\n");
644                 rte_flow_error_set(error, EINVAL,
645                                    RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
646                                    "ULP context uninitialized");
647                 return -EINVAL;
648         }
649         if (num_items != BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS) {
650                 BNXT_TF_DBG(ERR, "num items is invalid\n");
651                 rte_flow_error_set(error, EINVAL,
652                                    RTE_FLOW_ERROR_TYPE_ATTR, NULL,
653                                    "num items is invalid");
654                 return -EINVAL;
655         }
656
657         tun_entry = ulp_app_tun_match_entry(ulp_ctx, pmd_items->spec);
658         ulp_app_tun_entry_delete(tun_entry);
659         return 0;
660 }
661
662 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = {
663         .validate = bnxt_ulp_flow_validate,
664         .create = bnxt_ulp_flow_create,
665         .destroy = bnxt_ulp_flow_destroy,
666         .flush = bnxt_ulp_flow_flush,
667         .query = bnxt_ulp_flow_query,
668         .isolate = NULL,
669         /* Tunnel offload callbacks */
670         .tunnel_decap_set = bnxt_ulp_tunnel_decap_set,
671         .tunnel_match = bnxt_ulp_tunnel_match,
672         .tunnel_action_decap_release = bnxt_ulp_tunnel_decap_release,
673         .tunnel_item_release = bnxt_ulp_tunnel_item_release,
674         .get_restore_info = NULL
675 };