e794795c4be298f6413c07a1ab90c8e1e5aa9f79
[dpdk.git] / drivers / net / bnxt / tf_ulp / ulp_mapper.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2019 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.h"
14 #include "ulp_template_struct.h"
15 #include "bnxt_ulp.h"
16 #include "ulp_utils.h"
17
18 #define ULP_SZ_BITS2BYTES(x) (((x) + 7) / 8)
19 #define ULP_IDENTS_INVALID ((uint16_t)0xffff)
20 #define ULP_MAPPER_CACHE_RES_TBL_ID_SHFT 16
21 #define ULP_MAPPER_CACHE_RES_TBL_TYPE_SHFT 0
22 #define ULP_MAPPER_CACHE_RES_TBL_MASK ((uint32_t)0x0000ffff)
23
24 /*
25  * The cache table opcode is used to convey informat from the cache handler
26  * to the tcam handler.  The opcodes do the following:
27  * NORMAL - tcam should process all instructions as normal
28  * SKIP - tcam is using the cached entry and doesn't need to process the
29  *      instruction.
30  * ALLOC - tcam needs to allocate the tcam index and store in the cache entry
31  */
32 enum bnxt_ulp_cache_table_opc {
33         BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL,
34         BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP,
35         BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC
36 };
37
38 struct bnxt_ulp_mapper_cache_entry {
39         uint32_t ref_count;
40         uint16_t tcam_idx;
41         uint16_t idents[BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM];
42         uint8_t ident_types[BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM];
43 };
44
45 struct bnxt_ulp_mapper_def_id_entry {
46         enum tf_identifier_type ident_type;
47         uint64_t ident;
48 };
49
50 struct bnxt_ulp_mapper_data {
51         struct bnxt_ulp_mapper_def_id_entry
52                 dflt_ids[TF_DIR_MAX][BNXT_ULP_DEF_IDENT_INFO_TBL_MAX_SZ];
53         struct bnxt_ulp_mapper_cache_entry
54                 *cache_tbl[BNXT_ULP_CACHE_TBL_MAX_SZ];
55 };
56
57 /* Internal Structure for passing the arguments around */
58 struct bnxt_ulp_mapper_parms {
59         uint32_t                                dev_id;
60         enum bnxt_ulp_byte_order                order;
61         uint32_t                                act_tid;
62         struct bnxt_ulp_mapper_act_tbl_info     *atbls;
63         uint32_t                                num_atbls;
64         uint32_t                                class_tid;
65         struct bnxt_ulp_mapper_class_tbl_info   *ctbls;
66         uint32_t                                num_ctbls;
67         struct ulp_rte_act_prop                 *act_prop;
68         struct ulp_rte_act_bitmap               *act_bitmap;
69         struct ulp_rte_hdr_field                *hdr_field;
70         uint32_t                                *comp_fld;
71         struct ulp_regfile                      *regfile;
72         struct tf                               *tfp;
73         struct bnxt_ulp_context                 *ulp_ctx;
74         uint8_t                                 encap_byte_swap;
75         uint32_t                                fid;
76         enum bnxt_ulp_flow_db_tables            tbl_idx;
77         struct bnxt_ulp_mapper_data             *mapper_data;
78         enum bnxt_ulp_cache_table_opc           tcam_tbl_opc;
79         struct bnxt_ulp_mapper_cache_entry      *cache_ptr;
80 };
81
82 struct bnxt_ulp_mapper_create_parms {
83         uint32_t                        app_priority;
84         struct ulp_rte_hdr_bitmap       *hdr_bitmap;
85         struct ulp_rte_hdr_field        *hdr_field;
86         uint32_t                        *comp_fld;
87         struct ulp_rte_act_bitmap       *act;
88         struct ulp_rte_act_prop         *act_prop;
89         uint32_t                        class_tid;
90         uint32_t                        act_tid;
91         uint16_t                        func_id;
92         enum ulp_direction_type         dir;
93 };
94
95 /* Function to initialize any dynamic mapper data. */
96 int32_t
97 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx);
98
99 /* Function to release all dynamic mapper data. */
100 void
101 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx);
102
103 /*
104  * Function to handle the mapping of the Flow to be compatible
105  * with the underlying hardware.
106  */
107 int32_t
108 ulp_mapper_flow_create(struct bnxt_ulp_context  *ulp_ctx,
109                        struct bnxt_ulp_mapper_create_parms *parms,
110                        uint32_t *flowid);
111
112 /* Function that frees all resources associated with the flow. */
113 int32_t
114 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid);
115
116 /*
117  * Function that frees all resources and can be called on default or regular
118  * flows
119  */
120 int32_t
121 ulp_mapper_resources_free(struct bnxt_ulp_context       *ulp_ctx,
122                           uint32_t fid,
123                           enum bnxt_ulp_flow_db_tables  tbl_type);
124
125 #endif /* _ULP_MAPPER_H_ */