net/bnxt: add conditional processing of templates
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_mapper.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _ULP_MAPPER_H_
7 #define _ULP_MAPPER_H_
8
9 #include <rte_log.h>
10 #include <rte_flow.h>
11 #include <rte_flow_driver.h>
12 #include "tf_core.h"
13 #include "ulp_template_db_enum.h"
14 #include "ulp_template_struct.h"
15 #include "bnxt_ulp.h"
16 #include "ulp_utils.h"
17 #include "ulp_gen_tbl.h"
18
19 #define ULP_IDENTS_INVALID ((uint16_t)0xffff)
20
21 /*
22  * The cache table opcode is used to convey informat from the cache handler
23  * to the tcam handler.  The opcodes do the following:
24  * NORMAL - tcam should process all instructions as normal
25  * SKIP - tcam is using the cached entry and doesn't need to process the
26  *      instruction.
27  * ALLOC - tcam needs to allocate the tcam index and store in the cache entry
28  */
29 enum bnxt_ulp_cache_table_opc {
30         BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL,
31         BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP,
32         BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC
33 };
34
35 struct bnxt_ulp_mapper_glb_resource_entry {
36         enum bnxt_ulp_resource_func     resource_func;
37         uint32_t                        resource_type; /* TF_ enum type */
38         uint64_t                        resource_hndl;
39 };
40
41 struct bnxt_ulp_mapper_data {
42         struct bnxt_ulp_mapper_glb_resource_entry
43                 glb_res_tbl[TF_DIR_MAX][BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ];
44         struct ulp_mapper_gen_tbl_list gen_tbl_list[BNXT_ULP_GEN_TBL_MAX_SZ];
45 };
46
47 /* Internal Structure for passing the arguments around */
48 struct bnxt_ulp_mapper_parms {
49         enum bnxt_ulp_template_type             tmpl_type;
50         uint32_t                                dev_id;
51         uint32_t                                act_tid;
52         struct bnxt_ulp_mapper_tbl_info         *atbls; /* action table */
53         uint32_t                                num_atbls;
54         uint32_t                                class_tid;
55         struct bnxt_ulp_mapper_tbl_info         *ctbls; /* class table */
56         uint32_t                                num_ctbls;
57         struct ulp_rte_act_prop                 *act_prop;
58         struct ulp_rte_act_bitmap               *act_bitmap;
59         struct ulp_rte_hdr_bitmap               *hdr_bitmap;
60         struct ulp_rte_hdr_field                *hdr_field;
61         struct ulp_rte_field_bitmap             *fld_bitmap;
62         uint32_t                                *comp_fld;
63         struct ulp_regfile                      *regfile;
64         struct tf                               *tfp;
65         struct bnxt_ulp_context                 *ulp_ctx;
66         uint32_t                                fid;
67         enum bnxt_ulp_fdb_type                  flow_type;
68         struct bnxt_ulp_mapper_data             *mapper_data;
69         enum bnxt_ulp_cache_table_opc           tcam_tbl_opc;
70         struct bnxt_ulp_device_params           *device_params;
71         uint32_t                                parent_fid;
72         uint32_t                                parent_flow;
73         uint8_t                                 tun_idx;
74 };
75
76 struct bnxt_ulp_mapper_create_parms {
77         uint32_t                        app_priority;
78         struct ulp_rte_hdr_bitmap       *hdr_bitmap;
79         struct ulp_rte_hdr_field        *hdr_field;
80         uint32_t                        *comp_fld;
81         struct ulp_rte_act_bitmap       *act;
82         struct ulp_rte_act_prop         *act_prop;
83         struct ulp_rte_field_bitmap     *fld_bitmap;
84         uint32_t                        class_tid;
85         uint32_t                        act_tid;
86         uint16_t                        func_id;
87         uint32_t                        dir_attr;
88         enum bnxt_ulp_fdb_type          flow_type;
89
90         uint32_t                        flow_id;
91         /* if set then create it as a child flow with parent as parent_fid */
92         uint32_t                        parent_fid;
93         /* if set then create a parent flow */
94         uint32_t                        parent_flow;
95         uint8_t                         tun_idx;
96 };
97
98 /* Function to initialize any dynamic mapper data. */
99 int32_t
100 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx);
101
102 /* Function to release all dynamic mapper data. */
103 void
104 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx);
105
106 /*
107  * Function to handle the mapping of the Flow to be compatible
108  * with the underlying hardware.
109  */
110 int32_t
111 ulp_mapper_flow_create(struct bnxt_ulp_context  *ulp_ctx,
112                        struct bnxt_ulp_mapper_create_parms *parms);
113
114 /* Function that frees all resources associated with the flow. */
115 int32_t
116 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
117                         enum bnxt_ulp_fdb_type flow_type,
118                         uint32_t fid);
119
120 /*
121  * Function that frees all resources and can be called on default or regular
122  * flows
123  */
124 int32_t
125 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
126                           enum bnxt_ulp_fdb_type flow_type,
127                           uint32_t fid);
128
129 #endif /* _ULP_MAPPER_H_ */