xref: /dpdk/drivers/net/bnxt/tf_ulp/ulp_mapper.h (revision 68a03efeed657e6e05f281479b33b51102797e15)
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 
18 #define ULP_IDENTS_INVALID ((uint16_t)0xffff)
19 
20 /*
21  * The cache table opcode is used to convey informat from the cache handler
22  * to the tcam handler.  The opcodes do the following:
23  * NORMAL - tcam should process all instructions as normal
24  * SKIP - tcam is using the cached entry and doesn't need to process the
25  *	instruction.
26  * ALLOC - tcam needs to allocate the tcam index and store in the cache entry
27  */
28 enum bnxt_ulp_cache_table_opc {
29 	BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL,
30 	BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP,
31 	BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC
32 };
33 
34 struct bnxt_ulp_mapper_cache_entry {
35 	uint32_t ref_count;
36 	uint16_t tcam_idx;
37 	uint16_t idents[BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM];
38 	uint8_t ident_types[BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM];
39 };
40 
41 struct bnxt_ulp_mapper_glb_resource_entry {
42 	enum bnxt_ulp_resource_func	resource_func;
43 	uint32_t			resource_type; /* TF_ enum type */
44 	uint64_t			resource_hndl;
45 };
46 
47 struct bnxt_ulp_mapper_data {
48 	struct bnxt_ulp_mapper_glb_resource_entry
49 		glb_res_tbl[TF_DIR_MAX][BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ];
50 	struct bnxt_ulp_mapper_cache_entry
51 		*cache_tbl[BNXT_ULP_CACHE_TBL_MAX_SZ];
52 };
53 
54 /* Internal Structure for passing the arguments around */
55 struct bnxt_ulp_mapper_parms {
56 	enum bnxt_ulp_template_type		tmpl_type;
57 	uint32_t				dev_id;
58 	uint32_t				act_tid;
59 	struct bnxt_ulp_mapper_tbl_info		*atbls; /* action table */
60 	uint32_t				num_atbls;
61 	uint32_t				class_tid;
62 	struct bnxt_ulp_mapper_tbl_info		*ctbls; /* class table */
63 	uint32_t				num_ctbls;
64 	struct ulp_rte_act_prop			*act_prop;
65 	struct ulp_rte_act_bitmap		*act_bitmap;
66 	struct ulp_rte_hdr_bitmap		*hdr_bitmap;
67 	struct ulp_rte_hdr_field		*hdr_field;
68 	uint32_t				*comp_fld;
69 	struct ulp_regfile			*regfile;
70 	struct tf				*tfp;
71 	struct bnxt_ulp_context			*ulp_ctx;
72 	uint8_t					encap_byte_swap;
73 	uint32_t				fid;
74 	enum bnxt_ulp_fdb_type			flow_type;
75 	struct bnxt_ulp_mapper_data		*mapper_data;
76 	enum bnxt_ulp_cache_table_opc		tcam_tbl_opc;
77 	struct bnxt_ulp_mapper_cache_entry	*cache_ptr;
78 	struct bnxt_ulp_device_params           *device_params;
79 	uint32_t				parent_fid;
80 	uint32_t				parent_flow;
81 	uint8_t					tun_idx;
82 };
83 
84 struct bnxt_ulp_mapper_create_parms {
85 	uint32_t			app_priority;
86 	struct ulp_rte_hdr_bitmap	*hdr_bitmap;
87 	struct ulp_rte_hdr_field	*hdr_field;
88 	uint32_t			*comp_fld;
89 	struct ulp_rte_act_bitmap	*act;
90 	struct ulp_rte_act_prop		*act_prop;
91 	uint32_t			class_tid;
92 	uint32_t			act_tid;
93 	uint16_t			func_id;
94 	uint32_t			dir_attr;
95 	enum bnxt_ulp_fdb_type		flow_type;
96 
97 	uint32_t			flow_id;
98 	/* if set then create it as a child flow with parent as parent_fid */
99 	uint32_t			parent_fid;
100 	/* if set then create a parent flow */
101 	uint32_t			parent_flow;
102 	uint8_t				tun_idx;
103 };
104 
105 /* Function to initialize any dynamic mapper data. */
106 int32_t
107 ulp_mapper_init(struct bnxt_ulp_context	*ulp_ctx);
108 
109 /* Function to release all dynamic mapper data. */
110 void
111 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx);
112 
113 /*
114  * Function to handle the mapping of the Flow to be compatible
115  * with the underlying hardware.
116  */
117 int32_t
118 ulp_mapper_flow_create(struct bnxt_ulp_context	*ulp_ctx,
119 		       struct bnxt_ulp_mapper_create_parms *parms);
120 
121 /* Function that frees all resources associated with the flow. */
122 int32_t
123 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
124 			enum bnxt_ulp_fdb_type flow_type,
125 			uint32_t fid);
126 
127 /*
128  * Function that frees all resources and can be called on default or regular
129  * flows
130  */
131 int32_t
132 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
133 			  enum bnxt_ulp_fdb_type flow_type,
134 			  uint32_t fid);
135 
136 #endif /* _ULP_MAPPER_H_ */
137