net/bnxt: update multi device design
[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         /** Session ID, allocated by FW on tf_open_session() */
67         union tf_session_id session_id;
68
69         /**
70          * String containing name of control channel interface to be
71          * used for this session to communicate with firmware.
72          *
73          * ctrl_chan_name will be used as part of a name for any
74          * shared memory allocation.
75          */
76         char ctrl_chan_name[TF_SESSION_NAME_MAX];
77
78         /**
79          * Boolean controlling the use and availability of shadow
80          * copy. Shadow copy will allow the TruFlow Core to keep track
81          * of resource content on the firmware side without having to
82          * query firmware. Additional private session core_data will
83          * be allocated if this boolean is set to 'true', default
84          * 'false'.
85          *
86          * Size of memory depends on the NVM Resource settings for the
87          * control channel.
88          */
89         bool shadow_copy;
90
91         /**
92          * Session Reference Count. To keep track of functions per
93          * session the ref_count is incremented. There is also a
94          * parallel TruFlow Firmware ref_count in case the TruFlow
95          * Core goes away without informing the Firmware.
96          */
97         uint8_t ref_count;
98
99         /** Device handle */
100         struct tf_dev_info *dev;
101
102         /** Session HW and SRAM resources */
103         struct tf_rm_db resc;
104
105         /* Session HW resource pools */
106
107         /** RX L2 CTXT TCAM Pool */
108         BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
109         /** TX L2 CTXT TCAM Pool */
110         BITALLOC_INST(TF_L2_CTXT_TCAM_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
111
112         /** RX Profile Func Pool */
113         BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_RX, TF_NUM_PROF_FUNC);
114         /** TX Profile Func Pool */
115         BITALLOC_INST(TF_PROF_FUNC_POOL_NAME_TX, TF_NUM_PROF_FUNC);
116
117         /** RX Profile TCAM Pool */
118         BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_RX, TF_NUM_PROF_TCAM);
119         /** TX Profile TCAM Pool */
120         BITALLOC_INST(TF_PROF_TCAM_POOL_NAME_TX, TF_NUM_PROF_TCAM);
121
122         /** RX EM Profile ID Pool */
123         BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_RX, TF_NUM_EM_PROF_ID);
124         /** TX EM Key Pool */
125         BITALLOC_INST(TF_EM_PROF_ID_POOL_NAME_TX, TF_NUM_EM_PROF_ID);
126
127         /** RX WC Profile Pool */
128         BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_RX, TF_NUM_WC_PROF_ID);
129         /** TX WC Profile Pool */
130         BITALLOC_INST(TF_WC_TCAM_PROF_ID_POOL_NAME_TX, TF_NUM_WC_PROF_ID);
131
132         /* TBD, how do we want to handle EM records ?*/
133         /* EM Records are not controlled by way of a pool */
134
135         /** RX WC TCAM Pool */
136         BITALLOC_INST(TF_WC_TCAM_POOL_NAME_RX, TF_NUM_WC_TCAM_ROW);
137         /** TX WC TCAM Pool */
138         BITALLOC_INST(TF_WC_TCAM_POOL_NAME_TX, TF_NUM_WC_TCAM_ROW);
139
140         /** RX Meter Profile Pool */
141         BITALLOC_INST(TF_METER_PROF_POOL_NAME_RX, TF_NUM_METER_PROF);
142         /** TX Meter Profile Pool */
143         BITALLOC_INST(TF_METER_PROF_POOL_NAME_TX, TF_NUM_METER_PROF);
144
145         /** RX Meter Instance Pool */
146         BITALLOC_INST(TF_METER_INST_POOL_NAME_RX, TF_NUM_METER);
147         /** TX Meter Pool */
148         BITALLOC_INST(TF_METER_INST_POOL_NAME_TX, TF_NUM_METER);
149
150         /** RX Mirror Configuration Pool*/
151         BITALLOC_INST(TF_MIRROR_POOL_NAME_RX, TF_NUM_MIRROR);
152         /** RX Mirror Configuration Pool */
153         BITALLOC_INST(TF_MIRROR_POOL_NAME_TX, TF_NUM_MIRROR);
154
155         /** RX UPAR Pool */
156         BITALLOC_INST(TF_UPAR_POOL_NAME_RX, TF_NUM_UPAR);
157         /** TX UPAR Pool */
158         BITALLOC_INST(TF_UPAR_POOL_NAME_TX, TF_NUM_UPAR);
159
160         /** RX SP TCAM Pool */
161         BITALLOC_INST(TF_SP_TCAM_POOL_NAME_RX, TF_NUM_SP_TCAM);
162         /** TX SP TCAM Pool */
163         BITALLOC_INST(TF_SP_TCAM_POOL_NAME_TX, TF_NUM_SP_TCAM);
164
165         /** RX FKB Pool */
166         BITALLOC_INST(TF_FKB_POOL_NAME_RX, TF_NUM_FKB);
167         /** TX FKB Pool */
168         BITALLOC_INST(TF_FKB_POOL_NAME_TX, TF_NUM_FKB);
169
170         /** RX Table Scope Pool */
171         BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_RX, TF_NUM_TBL_SCOPE);
172         /** TX Table Scope Pool */
173         BITALLOC_INST(TF_TBL_SCOPE_POOL_NAME_TX, TF_NUM_TBL_SCOPE);
174
175         /** RX L2 Func Pool */
176         BITALLOC_INST(TF_L2_FUNC_POOL_NAME_RX, TF_NUM_L2_FUNC);
177         /** TX L2 Func Pool */
178         BITALLOC_INST(TF_L2_FUNC_POOL_NAME_TX, TF_NUM_L2_FUNC);
179
180         /** RX Epoch0 Pool */
181         BITALLOC_INST(TF_EPOCH0_POOL_NAME_RX, TF_NUM_EPOCH0);
182         /** TX Epoch0 Pool */
183         BITALLOC_INST(TF_EPOCH0_POOL_NAME_TX, TF_NUM_EPOCH0);
184
185         /** TX Epoch1 Pool */
186         BITALLOC_INST(TF_EPOCH1_POOL_NAME_RX, TF_NUM_EPOCH1);
187         /** TX Epoch1 Pool */
188         BITALLOC_INST(TF_EPOCH1_POOL_NAME_TX, TF_NUM_EPOCH1);
189
190         /** RX MetaData Profile Pool */
191         BITALLOC_INST(TF_METADATA_POOL_NAME_RX, TF_NUM_METADATA);
192         /** TX MetaData Profile Pool */
193         BITALLOC_INST(TF_METADATA_POOL_NAME_TX, TF_NUM_METADATA);
194
195         /** RX Connection Tracking State Pool */
196         BITALLOC_INST(TF_CT_STATE_POOL_NAME_RX, TF_NUM_CT_STATE);
197         /** TX Connection Tracking State Pool */
198         BITALLOC_INST(TF_CT_STATE_POOL_NAME_TX, TF_NUM_CT_STATE);
199
200         /** RX Range Profile Pool */
201         BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_RX, TF_NUM_RANGE_PROF);
202         /** TX Range Profile Pool */
203         BITALLOC_INST(TF_RANGE_PROF_POOL_NAME_TX, TF_NUM_RANGE_PROF);
204
205         /** RX Range Pool */
206         BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_RX, TF_NUM_RANGE_ENTRY);
207         /** TX Range Pool */
208         BITALLOC_INST(TF_RANGE_ENTRY_POOL_NAME_TX, TF_NUM_RANGE_ENTRY);
209
210         /** RX LAG Pool */
211         BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_RX, TF_NUM_LAG_ENTRY);
212         /** TX LAG Pool */
213         BITALLOC_INST(TF_LAG_ENTRY_POOL_NAME_TX, TF_NUM_LAG_ENTRY);
214
215         /* Session SRAM pools */
216
217         /** RX Full Action Record Pool */
218         BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_RX,
219                       TF_RSVD_SRAM_FULL_ACTION_RX);
220         /** TX Full Action Record Pool */
221         BITALLOC_INST(TF_SRAM_FULL_ACTION_POOL_NAME_TX,
222                       TF_RSVD_SRAM_FULL_ACTION_TX);
223
224         /** RX Multicast Group Pool, only RX is supported */
225         BITALLOC_INST(TF_SRAM_MCG_POOL_NAME_RX,
226                       TF_RSVD_SRAM_MCG_RX);
227
228         /** RX Encap 8B Pool*/
229         BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_RX,
230                       TF_RSVD_SRAM_ENCAP_8B_RX);
231         /** TX Encap 8B Pool*/
232         BITALLOC_INST(TF_SRAM_ENCAP_8B_POOL_NAME_TX,
233                       TF_RSVD_SRAM_ENCAP_8B_TX);
234
235         /** RX Encap 16B Pool */
236         BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_RX,
237                       TF_RSVD_SRAM_ENCAP_16B_RX);
238         /** TX Encap 16B Pool */
239         BITALLOC_INST(TF_SRAM_ENCAP_16B_POOL_NAME_TX,
240                       TF_RSVD_SRAM_ENCAP_16B_TX);
241
242         /** TX Encap 64B Pool, only TX is supported */
243         BITALLOC_INST(TF_SRAM_ENCAP_64B_POOL_NAME_TX,
244                       TF_RSVD_SRAM_ENCAP_64B_TX);
245
246         /** RX Source Properties SMAC Pool */
247         BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_RX,
248                       TF_RSVD_SRAM_SP_SMAC_RX);
249         /** TX Source Properties SMAC Pool */
250         BITALLOC_INST(TF_SRAM_SP_SMAC_POOL_NAME_TX,
251                       TF_RSVD_SRAM_SP_SMAC_TX);
252
253         /** TX Source Properties SMAC IPv4 Pool, only TX is supported */
254         BITALLOC_INST(TF_SRAM_SP_SMAC_IPV4_POOL_NAME_TX,
255                       TF_RSVD_SRAM_SP_SMAC_IPV4_TX);
256
257         /** TX Source Properties SMAC IPv6 Pool, only TX is supported */
258         BITALLOC_INST(TF_SRAM_SP_SMAC_IPV6_POOL_NAME_TX,
259                       TF_RSVD_SRAM_SP_SMAC_IPV6_TX);
260
261         /** RX Counter 64B Pool */
262         BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_RX,
263                       TF_RSVD_SRAM_COUNTER_64B_RX);
264         /** TX Counter 64B Pool */
265         BITALLOC_INST(TF_SRAM_STATS_64B_POOL_NAME_TX,
266                       TF_RSVD_SRAM_COUNTER_64B_TX);
267
268         /** RX NAT Source Port Pool */
269         BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_RX,
270                       TF_RSVD_SRAM_NAT_SPORT_RX);
271         /** TX NAT Source Port Pool */
272         BITALLOC_INST(TF_SRAM_NAT_SPORT_POOL_NAME_TX,
273                       TF_RSVD_SRAM_NAT_SPORT_TX);
274
275         /** RX NAT Destination Port Pool */
276         BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_RX,
277                       TF_RSVD_SRAM_NAT_DPORT_RX);
278         /** TX NAT Destination Port Pool */
279         BITALLOC_INST(TF_SRAM_NAT_DPORT_POOL_NAME_TX,
280                       TF_RSVD_SRAM_NAT_DPORT_TX);
281
282         /** RX NAT Source IPv4 Pool */
283         BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_RX,
284                       TF_RSVD_SRAM_NAT_S_IPV4_RX);
285         /** TX NAT Source IPv4 Pool */
286         BITALLOC_INST(TF_SRAM_NAT_S_IPV4_POOL_NAME_TX,
287                       TF_RSVD_SRAM_NAT_S_IPV4_TX);
288
289         /** RX NAT Destination IPv4 Pool */
290         BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_RX,
291                       TF_RSVD_SRAM_NAT_D_IPV4_RX);
292         /** TX NAT IPv4 Destination Pool */
293         BITALLOC_INST(TF_SRAM_NAT_D_IPV4_POOL_NAME_TX,
294                       TF_RSVD_SRAM_NAT_D_IPV4_TX);
295
296         /**
297          * Pools not allocated from HCAPI RM
298          */
299
300         /** RX L2 Ctx Remap ID  Pool */
301         BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_RX, TF_NUM_L2_CTXT_TCAM);
302         /** TX L2 Ctx Remap ID Pool */
303         BITALLOC_INST(TF_L2_CTXT_REMAP_POOL_NAME_TX, TF_NUM_L2_CTXT_TCAM);
304
305         /** CRC32 seed table */
306 #define TF_LKUP_SEED_MEM_SIZE 512
307         uint32_t lkup_em_seed_mem[TF_DIR_MAX][TF_LKUP_SEED_MEM_SIZE];
308
309         /** Lookup3 init values */
310         uint32_t lkup_lkup3_init_cfg[TF_DIR_MAX];
311
312         /** Table scope array */
313         struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE];
314
315         /**
316          * EM Pools
317          */
318         struct stack em_pool[TF_DIR_MAX];
319 };
320
321 /**
322  * Session open parameter definition
323  */
324 struct tf_session_open_session_parms {
325         /**
326          * [in] Pointer to the TF open session configuration
327          */
328         struct tf_open_session_parms *open_cfg;
329 };
330
331 /**
332  * Session attach parameter definition
333  */
334 struct tf_session_attach_session_parms {
335         /**
336          * [in] Pointer to the TF attach session configuration
337          */
338         struct tf_attach_session_parms *attach_cfg;
339 };
340
341 /**
342  * Session close parameter definition
343  */
344 struct tf_session_close_session_parms {
345         uint8_t *ref_count;
346         union tf_session_id *session_id;
347 };
348
349 /**
350  * @page session Session Management
351  *
352  * @ref tf_session_open_session
353  *
354  * @ref tf_session_attach_session
355  *
356  * @ref tf_session_close_session
357  *
358  * @ref tf_session_get_session
359  *
360  * @ref tf_session_get_device
361  *
362  * @ref tf_session_get_fw_session_id
363  */
364
365 /**
366  * Creates a host session with a corresponding firmware session.
367  *
368  * [in] tfp
369  *   Pointer to TF handle
370  *
371  * [in] parms
372  *   Pointer to the session open parameters
373  *
374  * Returns
375  *   - (0) if successful.
376  *   - (-EINVAL) on failure.
377  */
378 int tf_session_open_session(struct tf *tfp,
379                             struct tf_session_open_session_parms *parms);
380
381 /**
382  * Attaches a previous created session.
383  *
384  * [in] tfp
385  *   Pointer to TF handle
386  *
387  * [in] parms
388  *   Pointer to the session attach parameters
389  *
390  * Returns
391  *   - (0) if successful.
392  *   - (-EINVAL) on failure.
393  */
394 int tf_session_attach_session(struct tf *tfp,
395                               struct tf_session_attach_session_parms *parms);
396
397 /**
398  * Closes a previous created session.
399  *
400  * [in] tfp
401  *   Pointer to TF handle
402  *
403  * [in/out] parms
404  *   Pointer to the session close parameters.
405  *
406  * Returns
407  *   - (0) if successful.
408  *   - (-EINVAL) on failure.
409  */
410 int tf_session_close_session(struct tf *tfp,
411                              struct tf_session_close_session_parms *parms);
412
413 /**
414  * Looks up the private session information from the TF session info.
415  *
416  * [in] tfp
417  *   Pointer to TF handle
418  *
419  * [out] tfs
420  *   Pointer pointer to the session
421  *
422  * Returns
423  *   - (0) if successful.
424  *   - (-EINVAL) on failure.
425  */
426 int tf_session_get_session(struct tf *tfp,
427                            struct tf_session **tfs);
428
429 /**
430  * Looks up the device information from the TF Session.
431  *
432  * [in] tfp
433  *   Pointer to TF handle
434  *
435  * [out] tfd
436  *   Pointer pointer to the device
437  *
438  * Returns
439  *   - (0) if successful.
440  *   - (-EINVAL) on failure.
441  */
442 int tf_session_get_device(struct tf_session *tfs,
443                           struct tf_dev_info **tfd);
444
445 /**
446  * Looks up the FW session id of the firmware connection for the
447  * requested TF handle.
448  *
449  * [in] tfp
450  *   Pointer to TF handle
451  *
452  * [out] session_id
453  *   Pointer to the session_id
454  *
455  * Returns
456  *   - (0) if successful.
457  *   - (-EINVAL) on failure.
458  */
459 int tf_session_get_fw_session_id(struct tf *tfp,
460                                  uint8_t *fw_session_id);
461
462 #endif /* _TF_SESSION_H_ */