e4472ed7f523b76ebc1ca1af0e254841a6678ba9
[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 "tf_resources.h"
18 #include "stack.h"
19
20 /**
21  * The Session module provides session control support. A session is
22  * to the ULP layer known as a session_info instance. The session
23  * private data is the actual session.
24  *
25  * Session manages:
26  *   - The device and all the resources related to the device.
27  *   - Any session sharing between ULP applications
28  */
29
30 /** Session defines
31  */
32 #define TF_SESSIONS_MAX           1          /** max # sessions */
33 #define TF_SESSION_ID_INVALID     0xFFFFFFFF /** Invalid Session ID define */
34
35 /**
36  * Number of EM entries. Static for now will be removed
37  * when parameter added at a later date. At this stage we
38  * are using fixed size entries so that each stack entry
39  * represents 4 RT (f/n)blocks. So we take the total block
40  * allocation for truflow and divide that by 4.
41  */
42 #define TF_SESSION_TOTAL_FN_BLOCKS (1024 * 8) /* 8K blocks */
43 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
44 #define TF_SESSION_EM_POOL_SIZE \
45         (TF_SESSION_TOTAL_FN_BLOCKS / TF_SESSION_EM_ENTRY_SIZE)
46
47 /**
48  * Session
49  *
50  * Shared memory containing private TruFlow session information.
51  * Through this structure the session can keep track of resource
52  * allocations and (if so configured) any shadow copy of flow
53  * information.
54  *
55  * Memory is assigned to the Truflow instance by way of
56  * tf_open_session. Memory is allocated and owned by i.e. ULP.
57  *
58  * Access control to this shared memory is handled by the spin_lock in
59  * tf_session_info.
60  */
61 struct tf_session {
62         /** TrueFlow Version. Used to control the structure layout
63          * when sharing sessions. No guarantee that a secondary
64          * process would come from the same version of an executable.
65          */
66         struct tf_session_version ver;
67
68         /** Session ID, allocated by FW on tf_open_session() */
69         union tf_session_id session_id;
70
71         /**
72          * String containing name of control channel interface to be
73          * used for this session to communicate with firmware.
74          *
75          * ctrl_chan_name will be used as part of a name for any
76          * shared memory allocation.
77          */
78         char ctrl_chan_name[TF_SESSION_NAME_MAX];
79
80         /**
81          * Boolean controlling the use and availability of shadow
82          * copy. Shadow copy will allow the TruFlow Core to keep track
83          * of resource content on the firmware side without having to
84          * query firmware. Additional private session core_data will
85          * be allocated if this boolean is set to 'true', default
86          * 'false'.
87          *
88          * Size of memory depends on the NVM Resource settings for the
89          * control channel.
90          */
91         bool shadow_copy;
92
93         /**
94          * Session Reference Count. To keep track of functions per
95          * session the ref_count is incremented. There is also a
96          * parallel TruFlow Firmware ref_count in case the TruFlow
97          * Core goes away without informing the Firmware.
98          */
99         uint8_t ref_count;
100
101         /** Device handle */
102         struct tf_dev_info dev;
103
104         /** Table scope array */
105         struct tf_tbl_scope_cb tbl_scopes[TF_NUM_TBL_SCOPE];
106
107         /**
108          * EM Pools
109          */
110         struct stack em_pool[TF_DIR_MAX];
111 };
112
113 /**
114  * Session open parameter definition
115  */
116 struct tf_session_open_session_parms {
117         /**
118          * [in] Pointer to the TF open session configuration
119          */
120         struct tf_open_session_parms *open_cfg;
121 };
122
123 /**
124  * Session attach parameter definition
125  */
126 struct tf_session_attach_session_parms {
127         /**
128          * [in] Pointer to the TF attach session configuration
129          */
130         struct tf_attach_session_parms *attach_cfg;
131 };
132
133 /**
134  * Session close parameter definition
135  */
136 struct tf_session_close_session_parms {
137         uint8_t *ref_count;
138         union tf_session_id *session_id;
139 };
140
141 /**
142  * @page session Session Management
143  *
144  * @ref tf_session_open_session
145  *
146  * @ref tf_session_attach_session
147  *
148  * @ref tf_session_close_session
149  *
150  * @ref tf_session_get_session
151  *
152  * @ref tf_session_get_device
153  *
154  * @ref tf_session_get_fw_session_id
155  */
156
157 /**
158  * Creates a host session with a corresponding firmware session.
159  *
160  * [in] tfp
161  *   Pointer to TF handle
162  *
163  * [in] parms
164  *   Pointer to the session open parameters
165  *
166  * Returns
167  *   - (0) if successful.
168  *   - (-EINVAL) on failure.
169  */
170 int tf_session_open_session(struct tf *tfp,
171                             struct tf_session_open_session_parms *parms);
172
173 /**
174  * Attaches a previous created session.
175  *
176  * [in] tfp
177  *   Pointer to TF handle
178  *
179  * [in] parms
180  *   Pointer to the session attach parameters
181  *
182  * Returns
183  *   - (0) if successful.
184  *   - (-EINVAL) on failure.
185  */
186 int tf_session_attach_session(struct tf *tfp,
187                               struct tf_session_attach_session_parms *parms);
188
189 /**
190  * Closes a previous created session.
191  *
192  * [in] tfp
193  *   Pointer to TF handle
194  *
195  * [in/out] parms
196  *   Pointer to the session close parameters.
197  *
198  * Returns
199  *   - (0) if successful.
200  *   - (-EINVAL) on failure.
201  */
202 int tf_session_close_session(struct tf *tfp,
203                              struct tf_session_close_session_parms *parms);
204
205 /**
206  * Looks up the private session information from the TF session info.
207  *
208  * [in] tfp
209  *   Pointer to TF handle
210  *
211  * [out] tfs
212  *   Pointer pointer to the session
213  *
214  * Returns
215  *   - (0) if successful.
216  *   - (-EINVAL) on failure.
217  */
218 int tf_session_get_session(struct tf *tfp,
219                            struct tf_session **tfs);
220
221 /**
222  * Looks up the device information from the TF Session.
223  *
224  * [in] tfp
225  *   Pointer to TF handle
226  *
227  * [out] tfd
228  *   Pointer pointer to the device
229  *
230  * Returns
231  *   - (0) if successful.
232  *   - (-EINVAL) on failure.
233  */
234 int tf_session_get_device(struct tf_session *tfs,
235                           struct tf_dev_info **tfd);
236
237 /**
238  * Looks up the FW session id of the firmware connection for the
239  * requested TF handle.
240  *
241  * [in] tfp
242  *   Pointer to TF handle
243  *
244  * [out] session_id
245  *   Pointer to the session_id
246  *
247  * Returns
248  *   - (0) if successful.
249  *   - (-EINVAL) on failure.
250  */
251 int tf_session_get_fw_session_id(struct tf *tfp,
252                                  uint8_t *fw_session_id);
253
254 #endif /* _TF_SESSION_H_ */