net/bnxt: modify TRUFLOW HWRM messages
[dpdk.git] / drivers / net / bnxt / tf_core / tf_session.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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 #include "ll.h"
20
21 /**
22  * The Session module provides session control support. A session is
23  * to the ULP layer known as a session_info instance. The session
24  * private data is the actual session.
25  *
26  * Session manages:
27  *   - The device and all the resources related to the device.
28  *   - Any session sharing between ULP applications
29  */
30
31 /** Session defines
32  */
33 #define TF_SESSION_ID_INVALID     0xFFFFFFFF /** Invalid Session ID define */
34
35 /**
36  * At this stage we are using fixed size entries so that each
37  * stack entry represents either 2 or 4 RT (f/n)blocks. So we
38  * take the total block allocation for truflow and divide that
39  * by either 2 or 4.
40  */
41 #ifdef TF_EM_ENTRY_IPV4_ONLY
42 #define TF_SESSION_EM_ENTRY_SIZE 2 /* 2 blocks per entry */
43 #else
44 #define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
45 #endif
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. It also holds info about Session Clients.
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         /**
69          * Session ID, allocated by FW on tf_open_session()
70          */
71         union tf_session_id session_id;
72
73         /**
74          * Boolean controlling the use and availability of shadow
75          * copy. Shadow copy will allow the TruFlow Core to keep track
76          * of resource content on the firmware side without having to
77          * query firmware. Additional private session core_data will
78          * be allocated if this boolean is set to 'true', default
79          * 'false'.
80          *
81          * Size of memory depends on the NVM Resource settings for the
82          * control channel.
83          */
84         bool shadow_copy;
85
86         /**
87          * Session Reference Count. To keep track of functions per
88          * session the ref_count is updated. There is also a
89          * parallel TruFlow Firmware ref_count in case the TruFlow
90          * Core goes away without informing the Firmware.
91          */
92         uint8_t ref_count;
93
94         /**
95          * Session Reference Count for attached sessions. To keep
96          * track of application sharing of a session the
97          * ref_count_attach is updated.
98          */
99         uint8_t ref_count_attach;
100
101         /**
102          * Device handle
103          */
104         struct tf_dev_info dev;
105         /**
106          * Device init flag. False if Device is not fully initialized,
107          * else true.
108          */
109         bool dev_init;
110
111         /**
112          * Linked list of clients registered for this session
113          */
114         struct ll client_ll;
115
116         /**
117          * em ext db reference for the session
118          */
119         void *em_ext_db_handle;
120
121         /**
122          * tcam db reference for the session
123          */
124         void *tcam_db_handle;
125
126         /**
127          * table db reference for the session
128          */
129         void *tbl_db_handle;
130
131         /**
132          * identifier db reference for the session
133          */
134         void *id_db_handle;
135
136         /**
137          * em db reference for the session
138          */
139         void *em_db_handle;
140 };
141
142 /**
143  * Session Client
144  *
145  * Shared memory for each of the Session Clients. A session can have
146  * one or more clients.
147  */
148 struct tf_session_client {
149         /**
150          * Linked list of clients
151          */
152         struct ll_entry ll_entry; /* For inserting in link list, must be
153                                    * first field of struct.
154                                    */
155
156         /**
157          * String containing name of control channel interface to be
158          * used for this session to communicate with firmware.
159          *
160          * ctrl_chan_name will be used as part of a name for any
161          * shared memory allocation.
162          */
163         char ctrl_chan_name[TF_SESSION_NAME_MAX];
164
165         /**
166          * Firmware FID, learned at time of Session Client create.
167          */
168         uint16_t fw_fid;
169
170         /**
171          * Session Client ID, allocated by FW on tf_register_session()
172          */
173         union tf_session_client_id session_client_id;
174 };
175
176 /**
177  * Session open parameter definition
178  */
179 struct tf_session_open_session_parms {
180         /**
181          * [in] Pointer to the TF open session configuration
182          */
183         struct tf_open_session_parms *open_cfg;
184 };
185
186 /**
187  * Session attach parameter definition
188  */
189 struct tf_session_attach_session_parms {
190         /**
191          * [in] Pointer to the TF attach session configuration
192          */
193         struct tf_attach_session_parms *attach_cfg;
194 };
195
196 /**
197  * Session close parameter definition
198  */
199 struct tf_session_close_session_parms {
200         /**
201          * []
202          */
203         uint8_t *ref_count;
204         /**
205          * []
206          */
207         union tf_session_id *session_id;
208 };
209
210 /**
211  * @page session Session Management
212  *
213  * @ref tf_session_open_session
214  *
215  * @ref tf_session_attach_session
216  *
217  * @ref tf_session_close_session
218  *
219  * @ref tf_session_is_fid_supported
220  *
221  * @ref tf_session_get_session_internal
222  *
223  * @ref tf_session_get_session
224  *
225  * @ref tf_session_get_session_client
226  *
227  * @ref tf_session_find_session_client_by_name
228  *
229  * @ref tf_session_find_session_client_by_fid
230  *
231  * @ref tf_session_get_device
232  *
233  * @ref tf_session_get_fw_session_id
234  *
235  * @ref tf_session_get_session_id
236  */
237
238 /**
239  * Creates a host session with a corresponding firmware session.
240  *
241  * [in] tfp
242  *   Pointer to TF handle
243  *
244  * [in] parms
245  *   Pointer to the session open parameters
246  *
247  * Returns
248  *   - (0) if successful.
249  *   - (-EINVAL) on failure.
250  */
251 int tf_session_open_session(struct tf *tfp,
252                             struct tf_session_open_session_parms *parms);
253
254 /**
255  * Attaches a previous created session.
256  *
257  * [in] tfp
258  *   Pointer to TF handle
259  *
260  * [in] parms
261  *   Pointer to the session attach parameters
262  *
263  * Returns
264  *   - (0) if successful.
265  *   - (-EINVAL) on failure.
266  */
267 int tf_session_attach_session(struct tf *tfp,
268                               struct tf_session_attach_session_parms *parms);
269
270 /**
271  * Closes a previous created session. Only possible if previous
272  * registered Clients had been unregistered first.
273  *
274  * [in] tfp
275  *   Pointer to TF handle
276  *
277  * [in/out] parms
278  *   Pointer to the session close parameters.
279  *
280  * Returns
281  *   - (0) if successful.
282  *   - (-EUSERS) if clients are still registered with the session.
283  *   - (-EINVAL) on failure.
284  */
285 int tf_session_close_session(struct tf *tfp,
286                              struct tf_session_close_session_parms *parms);
287
288 /**
289  * Verifies that the fid is supported by the session. Used to assure
290  * that a function i.e. client/control channel is registered with the
291  * session.
292  *
293  * [in] tfs
294  *   Pointer to TF Session handle
295  *
296  * [in] fid
297  *   FID value to check
298  *
299  * Returns
300  *   - (true) if successful, else false
301  *   - (-EINVAL) on failure.
302  */
303 bool
304 tf_session_is_fid_supported(struct tf_session *tfs,
305                             uint16_t fid);
306
307 /**
308  * Looks up the private session information from the TF session
309  * info. Does not perform a fid check against the registered
310  * clients. Should be used if tf_session_get_session() was used
311  * previously i.e. at the TF API boundary.
312  *
313  * [in] tfp
314  *   Pointer to TF handle
315  *
316  * [out] tfs
317  *   Pointer pointer to the session
318  *
319  * Returns
320  *   - (0) if successful.
321  *   - (-EINVAL) on failure.
322  */
323 int tf_session_get_session_internal(struct tf *tfp,
324                                     struct tf_session **tfs);
325
326 /**
327  * Looks up the private session information from the TF session
328  * info. Performs a fid check against the clients on the session.
329  *
330  * [in] tfp
331  *   Pointer to TF handle
332  *
333  * [out] tfs
334  *   Pointer pointer to the session
335  *
336  * Returns
337  *   - (0) if successful.
338  *   - (-EINVAL) on failure.
339  */
340 int tf_session_get_session(struct tf *tfp,
341                            struct tf_session **tfs);
342
343 /**
344  * Looks up client within the session.
345  *
346  * [in] tfs
347  *   Pointer pointer to the session
348  *
349  * [in] session_client_id
350  *   Client id to look for within the session
351  *
352  * Returns
353  *   client if successful.
354  *   - (NULL) on failure, client not found.
355  */
356 struct tf_session_client *
357 tf_session_get_session_client(struct tf_session *tfs,
358                               union tf_session_client_id session_client_id);
359
360 /**
361  * Looks up client using name within the session.
362  *
363  * [in] session, pointer to the session
364  *
365  * [in] session_client_name, name of the client to lookup in the session
366  *
367  * Returns:
368  *   - Pointer to the session, if found.
369  *   - (NULL) on failure, client not found.
370  */
371 struct tf_session_client *
372 tf_session_find_session_client_by_name(struct tf_session *tfs,
373                                        const char *ctrl_chan_name);
374
375 /**
376  * Looks up client using the fid.
377  *
378  * [in] session, pointer to the session
379  *
380  * [in] fid, fid of the client to find
381  *
382  * Returns:
383  *   - Pointer to the session, if found.
384  *   - (NULL) on failure, client not found.
385  */
386 struct tf_session_client *
387 tf_session_find_session_client_by_fid(struct tf_session *tfs,
388                                       uint16_t fid);
389
390 /**
391  * Looks up the device information from the TF Session.
392  *
393  * [in] tfp
394  *   Pointer to TF handle
395  *
396  * [out] tfd
397  *   Pointer pointer to the device
398  *
399  * Returns
400  *   - (0) if successful.
401  *   - (-EINVAL) on failure.
402  */
403 int tf_session_get_device(struct tf_session *tfs,
404                           struct tf_dev_info **tfd);
405
406 /**
407  * Looks up the FW Session id the requested TF handle.
408  *
409  * [in] tfp
410  *   Pointer to TF handle
411  *
412  * [out] session_id
413  *   Pointer to the session_id
414  *
415  * Returns
416  *   - (0) if successful.
417  *   - (-EINVAL) on failure.
418  */
419 int tf_session_get_fw_session_id(struct tf *tfp,
420                                  uint8_t *fw_session_id);
421
422 /**
423  * Looks up the Session id the requested TF handle.
424  *
425  * [in] tfp
426  *   Pointer to TF handle
427  *
428  * [out] session_id
429  *   Pointer to the session_id
430  *
431  * Returns
432  *   - (0) if successful.
433  *   - (-EINVAL) on failure.
434  */
435 int tf_session_get_session_id(struct tf *tfp,
436                               union tf_session_id *session_id);
437
438 /**
439  * API to get the em_ext_db from tf_session.
440  *
441  * [in] tfp
442  *   Pointer to TF handle
443  *
444  * [out] em_ext_db_handle, pointer to eem handle
445  *
446  * Returns:
447  *   - (0) if successful.
448  *   - (-EINVAL) on failure.
449  */
450 int
451 tf_session_get_em_ext_db(struct tf *tfp,
452                         void **em_ext_db_handle);
453
454 /**
455  * API to set the em_ext_db in tf_session.
456  *
457  * [in] tfp
458  *   Pointer to TF handle
459  *
460  * [in] em_ext_db_handle, pointer to eem handle
461  *
462  * Returns:
463  *   - (0) if successful.
464  *   - (-EINVAL) on failure.
465  */
466 int
467 tf_session_set_em_ext_db(struct tf *tfp,
468                         void *em_ext_db_handle);
469
470 /**
471  * API to get the db from tf_session.
472  *
473  * [in] tfp
474  *   Pointer to TF handle
475  *
476  * [out] db_handle, pointer to db handle
477  *
478  * Returns:
479  *   - (0) if successful.
480  *   - (-EINVAL) on failure.
481  */
482 int
483 tf_session_get_db(struct tf *tfp,
484                    enum tf_module_type type,
485                   void **db_handle);
486
487 /**
488  * API to set the db in tf_session.
489  *
490  * [in] tfp
491  *   Pointer to TF handle
492  *
493  * [in] db_handle, pointer to db handle
494  *
495  * Returns:
496  *   - (0) if successful.
497  *   - (-EINVAL) on failure.
498  */
499 int
500 tf_session_set_db(struct tf *tfp,
501                    enum tf_module_type type,
502                   void *db_handle);
503 #endif /* _TF_SESSION_H_ */