DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2019-2021 Broadcom
 * All rights reserved.
 */

#ifndef _TF_SESSION_H_
#define _TF_SESSION_H_

#include <stdint.h>
#include <stdlib.h>

#include "bitalloc.h"
#include "tf_core.h"
#include "tf_device.h"
#include "tf_rm.h"
#include "tf_resources.h"
#include "stack.h"
#include "ll.h"

/**
 * The Session module provides session control support. A session is
 * to the ULP layer known as a session_info instance. The session
 * private data is the actual session.
 *
 * Session manages:
 *   - The device and all the resources related to the device.
 *   - Any session sharing between ULP applications
 */

/** Session defines
 */
#define TF_SESSION_ID_INVALID     0xFFFFFFFF /** Invalid Session ID define */

/**
 * At this stage we are using fixed size entries so that each
 * stack entry represents either 2 or 4 RT (f/n)blocks. So we
 * take the total block allocation for truflow and divide that
 * by either 2 or 4.
 */
#ifdef TF_EM_ENTRY_IPV4_ONLY
#define TF_SESSION_EM_ENTRY_SIZE 2 /* 2 blocks per entry */
#else
#define TF_SESSION_EM_ENTRY_SIZE 4 /* 4 blocks per entry */
#endif

/**
 * Session
 *
 * Shared memory containing private TruFlow session information.
 * Through this structure the session can keep track of resource
 * allocations and (if so configured) any shadow copy of flow
 * information. It also holds info about Session Clients.
 *
 * Memory is assigned to the Truflow instance by way of
 * tf_open_session. Memory is allocated and owned by i.e. ULP.
 *
 * Access control to this shared memory is handled by the spin_lock in
 * tf_session_info.
 */
struct tf_session {
	/** TruFlow Version. Used to control the structure layout
	 * when sharing sessions. No guarantee that a secondary
	 * process would come from the same version of an executable.
	 */
	struct tf_session_version ver;

	/**
	 * Session ID, allocated by FW on tf_open_session()
	 */
	union tf_session_id session_id;

	/**
	 * Boolean controlling the use and availability of shared session.
	 * Shared session will allow the application to share resources
	 * on the firmware side without having to allocate them on firmware.
	 * Additional private session core_data will be allocated if this
	 * boolean is set to 'true', default 'false'.
	 *
	 */
	bool shared_session;

	/**
	 * This flag indicates the shared session on firmware side is created
	 * by this session. Some privileges may be assigned to this session.
	 *
	 */
	bool shared_session_creator;

	/**
	 * Boolean controlling the use and availability of shadow
	 * copy. Shadow copy will allow the TruFlow Core to keep track
	 * of resource content on the firmware side without having to
	 * query firmware. Additional private session core_data will
	 * be allocated if this boolean is set to 'true', default
	 * 'false'.
	 *
	 * Size of memory depends on the NVM Resource settings for the
	 * control channel.
	 */
	bool shadow_copy;

	/**
	 * Session Reference Count. To keep track of functions per
	 * session the ref_count is updated. There is also a
	 * parallel TruFlow Firmware ref_count in case the TruFlow
	 * Core goes away without informing the Firmware.
	 */
	uint8_t ref_count;

	/**
	 * Session Reference Count for attached sessions. To keep
	 * track of application sharing of a session the
	 * ref_count_attach is updated.
	 */
	uint8_t ref_count_attach;

	/**
	 * Device handle
	 */
	struct tf_dev_info dev;
	/**
	 * Device init flag. False if Device is not fully initialized,
	 * else true.
	 */
	bool dev_init;

	/**
	 * Linked list of clients registered for this session
	 */
	struct ll client_ll;

	/**
	 * em ext db reference for the session
	 */
	void *em_ext_db_handle;

	/**
	 * tcam db reference for the session
	 */
	void *tcam_db_handle;

	/**
	 * table db reference for the session
	 */
	void *tbl_db_handle;

	/**
	 * identifier db reference for the session
	 */
	void *id_db_handle;

	/**
	 * em db reference for the session
	 */
	void *em_db_handle;

	/**
	 * EM allocator for session
	 */
	void *em_pool[TF_DIR_MAX];

#ifdef TF_TCAM_SHARED
	/**
	 * tcam db reference for the session
	 */
	void *tcam_shared_db_handle;
#endif /* TF_TCAM_SHARED */

	/**
	 * SRAM db reference for the session
	 */
	void *sram_handle;

	/**
	 * if table db reference for the session
	 */
	void *if_tbl_db_handle;

	/**
	 * global db reference for the session
	 */
	void *global_db_handle;

	/**
	 * Number of slices per row for WC TCAM
	 */
	uint16_t wc_num_slices_per_row;
};

/**
 * Session Client
 *
 * Shared memory for each of the Session Clients. A session can have
 * one or more clients.
 */
struct tf_session_client {
	/**
	 * Linked list of clients
	 */
	struct ll_entry ll_entry; /* For inserting in link list, must be
				   * first field of struct.
				   */

	/**
	 * String containing name of control channel interface to be
	 * used for this session to communicate with firmware.
	 *
	 * ctrl_chan_name will be used as part of a name for any
	 * shared memory allocation.
	 */
	char ctrl_chan_name[TF_SESSION_NAME_MAX];

	/**
	 * Firmware FID, learned at time of Session Client create.
	 */
	uint16_t fw_fid;

	/**
	 * Session Client ID, allocated by FW on tf_register_session()
	 */
	union tf_session_client_id session_client_id;
};

/**
 * Session open parameter definition
 */
struct tf_session_open_session_parms {
	/**
	 * [in] Pointer to the TF open session configuration
	 */
	struct tf_open_session_parms *open_cfg;
};

/**
 * Session attach parameter definition
 */
struct tf_session_attach_session_parms {
	/**
	 * [in] Pointer to the TF attach session configuration
	 */
	struct tf_attach_session_parms *attach_cfg;
};

/**
 * Session close parameter definition
 */
struct tf_session_close_session_parms {
	/**
	 * []
	 */
	uint8_t *ref_count;
	/**
	 * []
	 */
	union tf_session_id *session_id;
};

/**
 * @page session Session Management
 *
 * @ref tf_session_open_session
 *
 * @ref tf_session_attach_session
 *
 * @ref tf_session_close_session
 *
 * @ref tf_session_is_fid_supported
 *
 * @ref tf_session_get_session_internal
 *
 * @ref tf_session_get_session
 *
 * @ref tf_session_get_session_client
 *
 * @ref tf_session_find_session_client_by_name
 *
 * @ref tf_session_find_session_client_by_fid
 *
 * @ref tf_session_get_device
 *
 * @ref tf_session_get_fw_session_id
 *
 * @ref tf_session_get_session_id
 *
 * @ref tf_session_is_shared_session_creator
 *
 * @ref tf_session_get_db
 *
 * @ref tf_session_set_db
 *
 * @ref tf_session_get_bp
 *
 * @ref tf_session_is_shared_session
 *
 * #define TF_SHARED
 * @ref tf_session_get_tcam_shared_db
 *
 * @ref tf_session_set_tcam_shared_db
 * #endif
 *
 * @ref tf_session_get_sram_db
 *
 * @ref tf_session_set_sram_db
 */

/**
 * Creates a host session with a corresponding firmware session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [in] parms
 *   Pointer to the session open parameters
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_open_session(struct tf *tfp,
			    struct tf_session_open_session_parms *parms);

/**
 * Attaches a previous created session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [in] parms
 *   Pointer to the session attach parameters
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_attach_session(struct tf *tfp,
			      struct tf_session_attach_session_parms *parms);

/**
 * Closes a previous created session. Only possible if previous
 * registered Clients had been unregistered first.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [in/out] parms
 *   Pointer to the session close parameters.
 *
 * Returns
 *   - (0) if successful.
 *   - (-EUSERS) if clients are still registered with the session.
 *   - (-EINVAL) on failure.
 */
int tf_session_close_session(struct tf *tfp,
			     struct tf_session_close_session_parms *parms);

/**
 * Verifies that the fid is supported by the session. Used to assure
 * that a function i.e. client/control channel is registered with the
 * session.
 *
 * [in] tfs
 *   Pointer to TF Session handle
 *
 * [in] fid
 *   FID value to check
 *
 * Returns
 *   - (true) if successful, else false
 *   - (-EINVAL) on failure.
 */
bool
tf_session_is_fid_supported(struct tf_session *tfs,
			    uint16_t fid);

/**
 * Looks up the private session information from the TF session
 * info. Does not perform a fid check against the registered
 * clients. Should be used if tf_session_get_session() was used
 * previously i.e. at the TF API boundary.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] tfs
 *   Pointer pointer to the session
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get_session_internal(struct tf *tfp,
				    struct tf_session **tfs);

/**
 * Looks up the private session information from the TF session
 * info. Performs a fid check against the clients on the session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] tfs
 *   Pointer pointer to the session
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get_session(struct tf *tfp,
			   struct tf_session **tfs);

/**
 * Looks up client within the session.
 *
 * [in] tfs
 *   Pointer pointer to the session
 *
 * [in] session_client_id
 *   Client id to look for within the session
 *
 * Returns
 *   client if successful.
 *   - (NULL) on failure, client not found.
 */
struct tf_session_client *
tf_session_get_session_client(struct tf_session *tfs,
			      union tf_session_client_id session_client_id);

/**
 * Looks up client using name within the session.
 *
 * [in] session, pointer to the session
 *
 * [in] session_client_name, name of the client to lookup in the session
 *
 * Returns:
 *   - Pointer to the session, if found.
 *   - (NULL) on failure, client not found.
 */
struct tf_session_client *
tf_session_find_session_client_by_name(struct tf_session *tfs,
				       const char *ctrl_chan_name);

/**
 * Looks up client using the fid.
 *
 * [in] session, pointer to the session
 *
 * [in] fid, fid of the client to find
 *
 * Returns:
 *   - Pointer to the session, if found.
 *   - (NULL) on failure, client not found.
 */
struct tf_session_client *
tf_session_find_session_client_by_fid(struct tf_session *tfs,
				      uint16_t fid);

/**
 * Looks up the device information from the TF Session.
 *
 * [in] tfs
 *   Pointer to session handle
 *
 * [out] tfd
 *   Pointer to the device
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get_device(struct tf_session *tfs,
			  struct tf_dev_info **tfd);

/**
 * Returns the session and the device from the tfp.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] tfs
 *   Pointer to the session
 *
 * [out] tfd
 *   Pointer to the device

 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get(struct tf *tfp,
		   struct tf_session **tfs,
		   struct tf_dev_info **tfd);

/**
 * Looks up the FW Session id the requested TF handle.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] session_id
 *   Pointer to the session_id
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get_fw_session_id(struct tf *tfp,
				 uint8_t *fw_session_id);

/**
 * Looks up the Session id the requested TF handle.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] session_id
 *   Pointer to the session_id
 *
 * Returns
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int tf_session_get_session_id(struct tf *tfp,
			      union tf_session_id *session_id);

/**
 * API to get the em_ext_db from tf_session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] em_ext_db_handle, pointer to eem handle
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_get_em_ext_db(struct tf *tfp,
			void **em_ext_db_handle);

/**
 * API to set the em_ext_db in tf_session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [in] em_ext_db_handle, pointer to eem handle
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_set_em_ext_db(struct tf *tfp,
			void *em_ext_db_handle);

/**
 * API to get the db from tf_session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [out] db_handle, pointer to db handle
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_get_db(struct tf *tfp,
		   enum tf_module_type type,
		  void **db_handle);

/**
 * API to set the db in tf_session.
 *
 * [in] tfp
 *   Pointer to TF handle
 *
 * [in] db_handle, pointer to db handle
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_set_db(struct tf *tfp,
		   enum tf_module_type type,
		  void *db_handle);

/**
 * Check if the session is shared session.
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - true if it is shared session
 *   - false if it is not shared session
 */
static inline bool
tf_session_is_shared_session(struct tf_session *tfs)
{
	return tfs->shared_session;
}

/**
 * Check if the session is the shared session creator
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - true if it is the shared session creator
 *   - false if it is not the shared session creator
 */
static inline bool
tf_session_is_shared_session_creator(struct tf_session *tfs)
{
	return tfs->shared_session_creator;
}

/**
 * Get the pointer to the parent bnxt struct
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - the pointer to the parent bnxt struct
 */
static inline struct bnxt*
tf_session_get_bp(struct tf *tfp)
{
	return tfp->bp;
}

/**
 * Set the pointer to the tcam shared database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - the pointer to the parent bnxt struct
 */
int
tf_session_set_tcam_shared_db(struct tf *tfp,
			      void *tcam_shared_db_handle);

/**
 * Get the pointer to the tcam shared database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - the pointer to the parent bnxt struct
 */
int
tf_session_get_tcam_shared_db(struct tf *tfp,
			      void **tcam_shared_db_handle);

/**
 * Set the pointer to the SRAM database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - the pointer to the parent bnxt struct
 */
int
tf_session_set_sram_db(struct tf *tfp,
		       void *sram_handle);

/**
 * Get the pointer to the SRAM database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - the pointer to the parent bnxt struct
 */
int
tf_session_get_sram_db(struct tf *tfp,
		       void **sram_handle);

/**
 * Set the pointer to the global cfg database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_set_global_db(struct tf *tfp,
			 void *global_handle);

/**
 * Get the pointer to the global cfg database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_get_global_db(struct tf *tfp,
			 void **global_handle);

/**
 * Set the pointer to the if table cfg database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_set_if_tbl_db(struct tf *tfp,
			 void *if_tbl_handle);

/**
 * Get the pointer to the if table cfg database
 *
 * [in] session, pointer to the session
 *
 * Returns:
 *   - (0) if successful.
 *   - (-EINVAL) on failure.
 */
int
tf_session_get_if_tbl_db(struct tf *tfp,
			 void **if_tbl_handle);

#endif /* _TF_SESSION_H_ */