blob: 2710bb544d7a376d1cb532477e823006dd270b4d [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
31 /** Configured additional segment size */
32 u32 add_segment_size;
33
34 /** Flag that indicates if additional segments should be created */
35 u8 add_segment;
36
Florin Corasa5464812017-04-19 13:00:05 -070037 /** Use private memory segment instead of shared memory */
38 u8 use_private_segment;
Florin Coras6cf30ad2017-04-04 23:08:23 -070039} segment_manager_properties_t;
40
41typedef struct _segment_manager
42{
Florin Corasa5464812017-04-19 13:00:05 -070043 clib_spinlock_t lockp;
44
Florin Coras6cf30ad2017-04-04 23:08:23 -070045 /** segments mapped by this manager */
46 u32 *segment_indices;
47
48 /** Owner app index */
49 u32 app_index;
50
51 /** Pointer to manager properties. Could be shared among all of
52 * an app's segment managers s*/
53 segment_manager_properties_t *properties;
54} segment_manager_t;
55
56/** Pool of segment managers */
57extern segment_manager_t *segment_managers;
58
59always_inline segment_manager_t *
60segment_manager_new ()
61{
62 segment_manager_t *sm;
63 pool_get (segment_managers, sm);
64 memset (sm, 0, sizeof (*sm));
65 return sm;
66}
67
68always_inline segment_manager_t *
69segment_manager_get (u32 index)
70{
71 return pool_elt_at_index (segment_managers, index);
72}
73
74always_inline segment_manager_t *
75segment_manager_get_if_valid (u32 index)
76{
77 if (pool_is_free_index (segment_managers, index))
78 return 0;
79 return pool_elt_at_index (segment_managers, index);
80}
81
82always_inline u32
83segment_manager_index (segment_manager_t * sm)
84{
85 return sm - segment_managers;
86}
87
88int
89segment_manager_init (segment_manager_t * sm,
90 segment_manager_properties_t * properties,
91 u32 seg_size);
92
93void segment_manager_get_segment_info (u32 index, u8 ** name, u32 * size);
94int
95session_manager_add_first_segment (segment_manager_t * sm, u32 segment_size);
96int session_manager_add_segment (segment_manager_t * sm);
97void segment_manager_del (segment_manager_t * sm);
98int
99segment_manager_alloc_session_fifos (segment_manager_t * sm,
100 svm_fifo_t ** server_rx_fifo,
101 svm_fifo_t ** server_tx_fifo,
102 u32 * fifo_segment_index);
103void
104segment_manager_dealloc_fifos (u32 svm_segment_index, svm_fifo_t * rx_fifo,
105 svm_fifo_t * tx_fifo);
Florin Corasa5464812017-04-19 13:00:05 -0700106unix_shared_memory_queue_t *segment_manager_alloc_queue (segment_manager_t *
107 sm, u32 queue_size);
108void segment_manager_dealloc_queue (segment_manager_t * sm,
109 unix_shared_memory_queue_t * q);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700110
111#endif /* SRC_VNET_SESSION_SEGMENT_MANAGER_H_ */
112/*
113 * fd.io coding-style-patch-verification: ON
114 *
115 * Local Variables:
116 * eval: (c-set-style "gnu")
117 * End:
118 */