net/bnxt: add ULP flow counter manager
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _BNXT_ULP_H_
7 #define _BNXT_ULP_H_
8
9 #include <inttypes.h>
10 #include <stdbool.h>
11 #include <sys/queue.h>
12
13 #include "rte_ethdev.h"
14
15 #include "ulp_template_db_enum.h"
16
17 struct bnxt_ulp_data {
18         uint32_t                        tbl_scope_id;
19         struct bnxt_ulp_mark_tbl        *mark_tbl;
20         uint32_t                        dev_id; /* Hardware device id */
21         uint32_t                        ref_cnt;
22         struct bnxt_ulp_flow_db         *flow_db;
23         void                            *mapper_data;
24         struct bnxt_ulp_port_db         *port_db;
25         struct bnxt_ulp_fc_info         *fc_info;
26         uint32_t                        port_to_app_flow_id;
27         uint32_t                        app_to_port_flow_id;
28         uint32_t                        tx_cfa_action;
29 };
30
31 struct bnxt_ulp_context {
32         struct bnxt_ulp_data    *cfg_data;
33         /* TBD The tfp should be removed once tf_attach is implemented. */
34         struct tf               *g_tfp;
35 };
36
37 struct bnxt_ulp_pci_info {
38         uint32_t        domain;
39         uint8_t         bus;
40 };
41
42 struct bnxt_ulp_session_state {
43         STAILQ_ENTRY(bnxt_ulp_session_state)    next;
44         bool                                    bnxt_ulp_init;
45         pthread_mutex_t                         bnxt_ulp_mutex;
46         struct bnxt_ulp_pci_info                pci_info;
47         struct bnxt_ulp_data                    *cfg_data;
48         /* TBD The tfp should be removed once tf_attach is implemented. */
49         struct tf                               *g_tfp;
50         uint32_t                                session_opened;
51 };
52
53 /* ULP flow id structure */
54 struct rte_tf_flow {
55         uint32_t        flow_id;
56 };
57
58 struct ulp_tlv_param {
59         enum bnxt_ulp_df_param_type type;
60         uint32_t length;
61         uint8_t value[16];
62 };
63
64 /*
65  * Allow the deletion of context only for the bnxt device that
66  * created the session
67  * TBD - The implementation of the function should change to
68  * using the reference count once tf_session_attach functionality
69  * is fixed.
70  */
71 bool
72 ulp_ctx_deinit_allowed(void *bp);
73
74 /* Function to set the device id of the hardware. */
75 int32_t
76 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, uint32_t dev_id);
77
78 /* Function to get the device id of the hardware. */
79 int32_t
80 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, uint32_t *dev_id);
81
82 /* Function to set the table scope id of the EEM table. */
83 int32_t
84 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
85                                 uint32_t tbl_scope_id);
86
87 /* Function to get the table scope id of the EEM table. */
88 int32_t
89 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
90                                 uint32_t *tbl_scope_id);
91
92 /* Function to set the tfp session details in the ulp context. */
93 int32_t
94 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp);
95
96 /* Function to get the tfp session details from ulp context. */
97 struct tf *
98 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp);
99
100 /* Get the device table entry based on the device id. */
101 struct bnxt_ulp_device_params *
102 bnxt_ulp_device_params_get(uint32_t dev_id);
103
104 int32_t
105 bnxt_ulp_ctxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
106                                struct bnxt_ulp_mark_tbl *mark_tbl);
107
108 struct bnxt_ulp_mark_tbl *
109 bnxt_ulp_ctxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx);
110
111 /* Function to set the flow database to the ulp context. */
112 int32_t
113 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
114                                 struct bnxt_ulp_flow_db *flow_db);
115
116 /* Function to get the flow database from the ulp context. */
117 struct bnxt_ulp_flow_db *
118 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx);
119
120 /* Function to get the ulp context from eth device. */
121 struct bnxt_ulp_context *
122 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev);
123
124 /* Function to add the ulp mapper data to the ulp context */
125 int32_t
126 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
127                                     void *mapper_data);
128
129 /* Function to get the ulp mapper data from the ulp context */
130 void *
131 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx);
132
133 /* Function to set the port database to the ulp context. */
134 int32_t
135 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
136                                 struct bnxt_ulp_port_db *port_db);
137
138 /* Function to get the port database from the ulp context. */
139 struct bnxt_ulp_port_db *
140 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx);
141
142 /* Function to create default flows. */
143 int32_t
144 ulp_default_flow_create(struct rte_eth_dev *eth_dev,
145                         struct ulp_tlv_param *param_list,
146                         uint32_t ulp_class_tid,
147                         uint32_t *flow_id);
148
149 /* Function to destroy default flows. */
150 int32_t
151 ulp_default_flow_destroy(struct rte_eth_dev *eth_dev,
152                          uint32_t flow_id);
153
154 int
155 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
156                       struct rte_flow_error *error);
157
158 int32_t
159 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
160                                 struct bnxt_ulp_fc_info *ulp_fc_info);
161
162 struct bnxt_ulp_fc_info *
163 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx);
164
165 #endif /* _BNXT_ULP_H_ */