net/bnxt: support bulk table get and mirror
[dpdk.git] / drivers / net / bnxt / tf_core / tf_session.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_SESSION_H_
7 #define _TF_SESSION_H_
8
9 #include <stdint.h>
10 #include <stdlib.h>
11
12 #include "bitalloc.h"
13 #include "tf_core.h"
14 #include "tf_device.h"
15 #include "tf_rm.h"
16 #include "tf_tbl.h"
17 #include "stack.h"
18
19 /**
20  * The Session module provides session control support. A session is
21  * to the ULP layer known as a session_info instance. The session
22  * private data is the actual session.
23  *
24  * Session manages:
25  *   - The device and all the resources related to the device.
26  *   - Any session sharing between ULP applications
27  */
28
29 /** Session defines
30  */
31 #define TF_SESSIONS_MAX           1          /** max # sessions */
32 #define TF_SESSION_ID_INVALID     0xFFFFFFFF /** Invalid Session ID define */
33
34 /**
35  * Number of EM entries. Static for now will be removed
36  * when parameter added at a later date. At this stage we
37  * are using fixed size entries so that each stack entry
38  * represents 4 RT (f/n)blocks. So we take the total block
39  * allocation for truflow and divide that by 4.
40  */
41 #define TF_SESSION_TOTAL_FN_BLOCKS (1024 * 8) /* 8K blocks */
42 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
43 #define TF_SESSION_EM_POOL_SIZE \
44         (TF_SESSION_TOTAL_FN_BLOCKS / TF_SESSION_EM_ENTRY_SIZE)
45
46 /** Session
47  *
48  * Shared memory containing private TruFlow session information.
49  * Through this structure the session can keep track of resource
50  * allocations and (if so configured) any shadow copy of flow
51  * information.
52  *
53  * Memory is assigned to the Truflow instance by way of
54  * tf_open_session. Memory is allocated and owned by i.e. ULP.
55  *
56  * Access control to this shared memory is handled by the spin_lock in
57  * tf_session_info.
58  */
59 struct tf_session {
60         /** TrueFlow Version. Used to control the structure layout
61          * when sharing sessions. No guarantee that a secondary
62          * process would come from the same version of an executable.
63          */
64         struct tf_session_version ver;
65
66         /** Device type, provided by tf_open_session().
67          */
68         enum tf_device_type device_type;
69
70         /** Session ID, allocated by FW on tf_open_session().
71          */
72         union tf_session_id session_id;
73
74         /**
75          * String containing name of control channel interface to be
76          * used for this session to communicate with firmware.
77          *
78          * ctrl_chan_name will be used as part of a name for any
79          * shared memory allocation.
80          */
81         char ctrl_chan_name[TF_SESSION_NAME_MAX];
82
83         /**
84          * Boolean controlling the use and availability of shadow
85          * copy. Shadow copy will allow the TruFlow Core to keep track
86          * of resource content on the firmware side without having to
87          * query firmware. Additional private session core_data will
88          * be allocated if this boolean is set to 'true', default
89          * 'false'.
90          *
91          * Size of memory depends on the NVM Resource settings for the
92          * control channel.
93          */
94         bool shadow_copy;
95
96         /**
97          * Session Reference Count. To keep track of functions per
98          * session the ref_count is incremented. There is also a
99          * parallel TruFlow Firmware ref_count in case the TruFlow
100          * Core goes away without informing the Firmware.
101          */
102         uint8_t ref_count;
103
104         /** Device */
105         struct tf_dev_info *dev;
106
107         /** Session HW and SRAM resources */
108         struct tf_rm_db resc;
109
110         /* Session HW resource pools */
111
112         /** RX L2 CTXT TCAM Pool */
113         BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
114         /** TX L2 CTXT TCAM Pool */
115         BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
116
117         /** RX Profile Func Pool */
118         BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_RX, TF_NUM_PROF_FUNC);
119         /** TX Profile Func Pool */
120         BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_TX, TF_NUM_PROF_FUNC);
121
122         /** RX Profile TCAM Pool */
123         BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_RX, TF_NUM_PROF_TCAM);
124         /** TX Profile TCAM Pool */
125         BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_TX, TF_NUM_PROF_TCAM);
126
127         /** RX EM Profile ID Pool */
128         BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_RX, TF_NUM_EM_PROF_ID);
129         /** TX EM Key Pool */
130         BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_TX, TF_NUM_EM_PROF_ID);
131
132         /** RX WC Profile Pool */
133         BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_RX, TF_NUM_WC_PROF_ID);
134         /** TX WC Profile Pool */
135         BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_TX, TF_NUM_WC_PROF_ID);
136
137         /* TBD, how do we want to handle EM records ?*/
138         /* EM Records are not controlled by way of a pool */
139
140         /** RX WC TCAM Pool */
141         BITALLOC_INST(TF_WC_TCAM_POOL_NAME_RX, TF_NUM_WC_TCAM_ROW);
142         /** TX WC TCAM Pool */
143         BITALLOC_INST(TF_WC_TCAM_POOL_NAME_TX, TF_NUM_WC_TCAM_ROW);
144
145         /** RX Meter Profile Pool */
146         BITALLOC_INST(TF_METER_PROF_POOL_NAME_RX, TF_NUM_METER_PROF);
147         /** TX Meter Profile Pool */
148         BITALLOC_INST(TF_METER_PROF_POOL_NAME_TX, TF_NUM_METER_PROF);
149
150         /** RX Meter Instance Pool */
151         BITALLOC_INST(TF_METER_INST_POOL_NAME_RX, TF_NUM_METER);
152         /** TX Meter Pool */
153         BITALLOC_INST(TF_METER_INST_POOL_NAME_TX, TF_NUM_METER);
154
155         /** RX Mirror Configuration Pool*/
156         BITALLOC_INST(TF_MIRROR_POOL_NAME_RX, TF_NUM_MIRROR);
157         /** RX Mirror Configuration Pool */
158         BITALLOC_INST(TF_MIRROR_POOL_NAME_TX, TF_NUM_MIRROR);
159
160         /** RX UPAR Pool */
161         BITALLOC_INST(TF_UPAR_POOL_NAME_RX, TF_NUM_UPAR);
162         /** TX UPAR Pool */
163         BITALLOC_INST(TF_UPAR_POOL_NAME_TX, TF_NUM_UPAR);
164
165         /** RX SP TCAM Pool */
166         BITALLOC_INST(TF_SP_TCAM_POOL_NAME_RX, TF_NUM_SP_TCAM);
167         /** TX SP TCAM Pool */
168         BITALLOC_INST(TF_SP_TCAM_POOL_NAME_TX, TF_NUM_SP_TCAM);
169
170         /** RX FKB Pool */
171         BITALLOC_INST(TF_FKB_POOL_NAME_RX, TF_NUM_FKB);
172         /** TX FKB Pool */
173         BITALLOC_INST(TF_FKB_POOL_NAME_TX, TF_NUM_FKB);
174
175         /** RX Table Scope Pool */
176         BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_RX, TF_NUM_TBL_SCOPE);
177         /** TX Table Scope Pool */
178         BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_TX, TF_NUM_TBL_SCOPE);
179
180         /** RX L2 Func Pool */
181         BITALLOC_INST(TF_L2_FUNC_POOL_NAME_RX, TF_NUM_L2_FUNC);
182         /** TX L2 Func Pool */
183         BITALLOC_INST(TF_L2_FUNC_POOL_NAME_TX, TF_NUM_L2_FUNC);
184
185         /** RX Epoch0 Pool */
186         BITALLOC_INST(TF_EPOCH0_POOL_NAME_RX, TF_NUM_EPOCH0);
187         /** TX Epoch0 Pool */
188         BITALLOC_INST(TF_EPOCH0_POOL_NAME_TX, TF_NUM_EPOCH0);
189
190         /** TX Epoch1 Pool */
191         BITALLOC_INST(TF_EPOCH1_POOL_NAME_RX, TF_NUM_EPOCH1);
192         /** TX Epoch1 Pool */
193         BITALLOC_INST(TF_EPOCH1_POOL_NAME_TX, TF_NUM_EPOCH1);
194
195         /** RX MetaData Profile Pool */
196         BITALLOC_INST(TF_METADATA_POOL_NAME_RX, TF_NUM_METADATA);
197         /** TX MetaData Profile Pool */
198         BITALLOC_INST(TF_METADATA_POOL_NAME_TX, TF_NUM_METADATA);
199
200         /** RX Connection Tracking State Pool */
201         BITALLOC_INST(TF_CT_STATE_POOL_NAME_RX, TF_NUM_CT_STATE);
202         /** TX Connection Tracking State Pool */
203         BITALLOC_INST(TF_CT_STATE_POOL_NAME_TX, TF_NUM_CT_STATE);
204
205         /** RX Range Profile Pool */
206         BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_RX, TF_NUM_RANGE_PROF);
207         /** TX Range Profile Pool */
208         BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_TX, TF_NUM_RANGE_PROF);
209
210         /** RX Range Pool */
211         BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_RX, TF_NUM_RANGE_ENTRY);
212         /** TX Range Pool */
213         BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_TX, TF_NUM_RANGE_ENTRY);
214
215         /** RX LAG Pool */
216         BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_RX, TF_NUM_LAG_ENTRY);
217         /** TX LAG Pool */
218         BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_TX, TF_NUM_LAG_ENTRY);
219
220         /* Session SRAM pools */
221
222         /** RX Full Action Record Pool */
223         BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_RX,
224                       TF_RSVD_SRAM_FULL_ACTION_RX);
225         /** TX Full Action Record Pool */
226         BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_TX,
227                       TF_RSVD_SRAM_FULL_ACTION_TX);
228
229         /** RX Multicast Group Pool, only RX is supported */
230         BITALLOC_INST(TF_SRAM_MCG_POOL_NAME_RX,
231                       TF_RSVD_SRAM_MCG_RX);
232
233         /** RX Encap 8B Pool*/
234         BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_RX,
235                       TF_RSVD_SRAM_ENCAP_8B_RX);
236         /** TX Encap 8B Pool*/
237         BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_TX,
238                       TF_RSVD_SRAM_ENCAP_8B_TX);
239
240         /** RX Encap 16B Pool */
241         BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_RX,
242                       TF_RSVD_SRAM_ENCAP_16B_RX);
243         /** TX Encap 16B Pool */
244         BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_TX,
245                       TF_RSVD_SRAM_ENCAP_16B_TX);
246
247         /** TX Encap 64B Pool, only TX is supported */
248         BITALLOC_INST(TF_SRAM_ENCAP_64B_POOL_NAME_TX,
249                       TF_RSVD_SRAM_ENCAP_64B_TX);
250
251         /** RX Source Properties SMAC Pool */
252         BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_RX,
253                       TF_RSVD_SRAM_SP_SMAC_RX);
254         /** TX Source Properties SMAC Pool */
255         BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_TX,
256                       TF_RSVD_SRAM_SP_SMAC_TX);
257
258         /** TX Source Properties SMAC IPv4 Pool, only TX is supported */
259         BITALLOC_INST(TF_SRAM_SP_SMAC_IPV4_POOL_NAME_TX,
260                       TF_RSVD_SRAM_SP_SMAC_IPV4_TX);
261
262         /** TX Source Properties SMAC IPv6 Pool, only TX is supported */
263         BITALLOC_INST(TF_SRAM_SP_SMAC_IPV6_POOL_NAME_TX,
264                       TF_RSVD_SRAM_SP_SMAC_IPV6_TX);
265
266         /** RX Counter 64B Pool */
267         BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_RX,
268                       TF_RSVD_SRAM_COUNTER_64B_RX);
269         /** TX Counter 64B Pool */
270         BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_TX,
271                       TF_RSVD_SRAM_COUNTER_64B_TX);
272
273         /** RX NAT Source Port Pool */
274         BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_RX,
275                       TF_RSVD_SRAM_NAT_SPORT_RX);
276         /** TX NAT Source Port Pool */
277         BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_TX,
278                       TF_RSVD_SRAM_NAT_SPORT_TX);
279
280         /** RX NAT Destination Port Pool */
281         BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_RX,
282                       TF_RSVD_SRAM_NAT_DPORT_RX);
283         /** TX NAT Destination Port Pool */
284         BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_TX,
285                       TF_RSVD_SRAM_NAT_DPORT_TX);
286
287         /** RX NAT Source IPv4 Pool */
288         BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_RX,
289                       TF_RSVD_SRAM_NAT_S_IPV4_RX);
290         /** TX NAT Source IPv4 Pool */
291         BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_TX,
292                       TF_RSVD_SRAM_NAT_S_IPV4_TX);
293
294         /** RX NAT Destination IPv4 Pool */
295         BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_RX,
296                       TF_RSVD_SRAM_NAT_D_IPV4_RX);
297         /** TX NAT IPv4 Destination Pool */
298         BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_TX,
299                       TF_RSVD_SRAM_NAT_D_IPV4_TX);
300
301         /**
302          * Pools not allocated from HCAPI RM
303          */
304
305         /** RX L2 Ctx Remap ID  Pool */
306         BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
307         /** TX L2 Ctx Remap ID Pool */
308         BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
309
310         /** CRC32 seed table */
311 #define TF_LKUP_SEED_MEM_SIZE 512
312         uint32_t lkup_em_seed_mem[TF_DIR_MAX][TF_LKUP_SEED_MEM_SIZE];
313
314         /** Lookup3 init values */
315         uint32_t lkup_lkup3_init_cfg[TF_DIR_MAX];
316
317         /** Table scope array */
318         struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE];
319
320         /**
321          * EM Pools
322          */
323         struct stack em_pool[TF_DIR_MAX];
324 };
325
326 /**
327  * @page session Session Management
328  *
329  * @ref tf_session_get_session
330  *
331  * @ref tf_session_get_device
332  */
333
334 /**
335  * Looks up the private session information from the TF session info.
336  *
337  * [in] tfp
338  *   Pointer to TF handle
339  *
340  * [out] tfs
341  *   Pointer to the session
342  *
343  * Returns
344  *   - (0) if successful.
345  *   - (-EINVAL) on failure.
346  */
347 int tf_session_get_session(struct tf *tfp,
348                            struct tf_session *tfs);
349
350 /**
351  * Looks up the device information from the TF Session.
352  *
353  * [in] tfp
354  *   Pointer to TF handle
355  *
356  * [out] tfd
357  *   Pointer to the device
358  *
359  * Returns
360  *   - (0) if successful.
361  *   - (-EINVAL) on failure.
362  */
363 int tf_session_get_device(struct tf_session *tfs,
364                           struct tf_dev_info *tfd);
365
366 #endif /* _TF_SESSION_H_ */