blob: d4b73208257244d75c1b682bebc1264b620235cc [file] [log] [blame]
Florin Coras6cf30ad2017-04-04 23:08:23 -07001/*
2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef SRC_VNET_SESSION_SEGMENT_MANAGER_H_
16#define SRC_VNET_SESSION_SEGMENT_MANAGER_H_
17
18#include <vnet/vnet.h>
19#include <svm/svm_fifo_segment.h>
20
Florin Corasa5464812017-04-19 13:00:05 -070021#include <vlibmemory/unix_shared_memory_queue.h>
22#include <vlibmemory/api.h>
23#include <vppinfra/lock.h>
24
Florin Coras6cf30ad2017-04-04 23:08:23 -070025typedef struct _segment_manager_properties
26{
27 /** Session fifo sizes. */
28 u32 rx_fifo_size;
29 u32 tx_fifo_size;
30
Dave Barach10d8cc62017-05-30 09:30:07 -040031 /** Preallocated pool sizes */
32 u32 preallocated_fifo_pairs;
33
Florin Coras6cf30ad2017-04-04 23:08:23 -070034 /** Configured additional segment size */
35 u32 add_segment_size;
36
37 /** Flag that indicates if additional segments should be created */
38 u8 add_segment;
39
Florin Corasa5464812017-04-19 13:00:05 -070040 /** Use private memory segment instead of shared memory */
41 u8 use_private_segment;
Florin Coras6cf30ad2017-04-04 23:08:23 -070042} segment_manager_properties_t;
43
44typedef struct _segment_manager
45{
Florin Corasa5464812017-04-19 13:00:05 -070046 clib_spinlock_t lockp;
47
Florin Coras6cf30ad2017-04-04 23:08:23 -070048 /** segments mapped by this manager */
49 u32 *segment_indices;
50
51 /** Owner app index */
52 u32 app_index;
53
54 /** Pointer to manager properties. Could be shared among all of
55 * an app's segment managers s*/
56 segment_manager_properties_t *properties;
57} segment_manager_t;
58
59/** Pool of segment managers */
60extern segment_manager_t *segment_managers;
61
62always_inline segment_manager_t *
63segment_manager_new ()
64{
65 segment_manager_t *sm;
66 pool_get (segment_managers, sm);
67 memset (sm, 0, sizeof (*sm));
68 return sm;
69}
70
71always_inline segment_manager_t *
72segment_manager_get (u32 index)
73{
74 return pool_elt_at_index (segment_managers, index);
75}
76
77always_inline segment_manager_t *
78segment_manager_get_if_valid (u32 index)
79{
80 if (pool_is_free_index (segment_managers, index))
81 return 0;
82 return pool_elt_at_index (segment_managers, index);
83}
84
85always_inline u32
86segment_manager_index (segment_manager_t * sm)
87{
88 return sm - segment_managers;
89}
90
91int
92segment_manager_init (segment_manager_t * sm,
93 segment_manager_properties_t * properties,
94 u32 seg_size);
95
96void segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size);
97int
98session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size);
99int session_manager_add_segment (segment_manager_t * sm);
100void segment_manager_del (segment_manager_t * sm);
101int
102segment_manager_alloc_session_fifos (segment_manager_t * sm,
103 svm_fifo_t ** server_rx_fifo,
104 svm_fifo_t ** server_tx_fifo,
105 u32 * fifo_segment_index);
106void
107segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo,
108 svm_fifo_t * tx_fifo);
Florin Corasa5464812017-04-19 13:00:05 -0700109unix_shared_memory_queue_t *segment_manager_alloc_queue (segment_manager_t *
110 sm, u32 queue_size);
111void segment_manager_dealloc_queue (segment_manager_t * sm,
112 unix_shared_memory_queue_t * q);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700113
114#endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
115/*
116 * fd.io coding-style-patch-verification: ON
117 *
118 * Local Variables:
119 * eval: (c-set-style "gnu")
120 * End:
121 */