blob: 0e86c25deabda826b796a496bd546f5362858536 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
2 * Copyright (c) 2016 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 __included_ssvm_fifo_segment_h__
16#define __included_ssvm_fifo_segment_h__
17
Florin Coras6792ec02017-03-13 03:49:51 -070018#include <svm/ssvm.h>
Florin Corasd3e83a92018-01-16 02:40:18 -080019#include <svm/svm_fifo.h>
Florin Corasa5464812017-04-19 13:00:05 -070020#include <vppinfra/lock.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050021
Dave Barach10d8cc62017-05-30 09:30:07 -040022typedef enum
23{
24 FIFO_SEGMENT_FREELIST_NONE = -1,
25 FIFO_SEGMENT_RX_FREELIST = 0,
26 FIFO_SEGMENT_TX_FREELIST,
27 FIFO_SEGMENT_N_FREELISTS
28} svm_fifo_segment_freelist_t;
29
Florin Corasc87c91d2017-08-16 19:55:49 -070030#define FIFO_SEGMENT_MIN_FIFO_SIZE 4096
Dave Barach818eb542017-08-02 13:56:13 -040031#define FIFO_SEGMENT_MAX_FIFO_SIZE (8<<20) /* 8mb max fifo size */
Florin Corasc87c91d2017-08-16 19:55:49 -070032#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE 32 /* Allocation quantum */
33
34#define FIFO_SEGMENT_F_IS_PRIVATE 1 << 0 /* Private segment */
35#define FIFO_SEGMENT_F_IS_MAIN_HEAP 1 << 1 /* Segment is main heap */
Florin Coras9d063042017-09-14 03:08:00 -040036#define FIFO_SEGMENT_F_IS_PREALLOCATED 1 << 2 /* Segment is preallocated */
Florin Corasb384b542018-01-15 01:08:33 -080037#define FIFO_SEGMENT_F_WILL_DELETE 1 << 3 /* Segment will be removed */
Dave Barach818eb542017-08-02 13:56:13 -040038
Dave Barach68b0fb02017-02-28 15:15:56 -050039typedef struct
40{
Dave Barach10d8cc62017-05-30 09:30:07 -040041 svm_fifo_t *fifos; /**< Linked list of active RX fifos */
Dave Barach818eb542017-08-02 13:56:13 -040042 svm_fifo_t **free_fifos; /**< Freelists, by fifo size */
Florin Corasc87c91d2017-08-16 19:55:49 -070043 u32 n_active_fifos; /**< Number of active fifos */
44 u8 flags; /**< Segment flags */
Dave Barach68b0fb02017-02-28 15:15:56 -050045} svm_fifo_segment_header_t;
46
47typedef struct
48{
49 ssvm_private_t ssvm;
50 svm_fifo_segment_header_t *h;
51} svm_fifo_segment_private_t;
52
53typedef struct
54{
Florin Corasa5464812017-04-19 13:00:05 -070055 volatile u32 lock;
56
Dave Barach68b0fb02017-02-28 15:15:56 -050057 /** pool of segments */
58 svm_fifo_segment_private_t *segments;
59 /* Where to put the next one */
60 u64 next_baseva;
61 u32 timeout_in_seconds;
62} svm_fifo_segment_main_t;
63
64extern svm_fifo_segment_main_t svm_fifo_segment_main;
65
66typedef struct
67{
Florin Corasb384b542018-01-15 01:08:33 -080068 ssvm_segment_type_t segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -050069 char *segment_name;
70 u32 segment_size;
Dave Barach2c25a622017-06-26 11:35:07 -040071 u32 *new_segment_indices;
Dave Barach10d8cc62017-05-30 09:30:07 -040072 u32 rx_fifo_size;
73 u32 tx_fifo_size;
74 u32 preallocated_fifo_pairs;
Dave Barach2c25a622017-06-26 11:35:07 -040075 u32 private_segment_count;
Florin Corasb384b542018-01-15 01:08:33 -080076 u32 seg_protected_space;
77 int memfd_fd;
Dave Barach68b0fb02017-02-28 15:15:56 -050078} svm_fifo_segment_create_args_t;
79
80static inline svm_fifo_segment_private_t *
Florin Corasc87c91d2017-08-16 19:55:49 -070081svm_fifo_segment_get_segment (u32 segment_index)
Dave Barach68b0fb02017-02-28 15:15:56 -050082{
83 svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main;
Florin Corasb384b542018-01-15 01:08:33 -080084 return pool_elt_at_index (ssm->segments, segment_index);
Dave Barach68b0fb02017-02-28 15:15:56 -050085}
86
Florin Coras6cf30ad2017-04-04 23:08:23 -070087static inline u8
88svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment)
89{
Dave Barach10d8cc62017-05-30 09:30:07 -040090 return fifo_segment->h->fifos != 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -070091}
92
Dave Barach10d8cc62017-05-30 09:30:07 -040093static inline svm_fifo_t *
94svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment)
Florin Coras6cf30ad2017-04-04 23:08:23 -070095{
Dave Barach10d8cc62017-05-30 09:30:07 -040096 return fifo_segment->h->fifos;
Florin Coras6cf30ad2017-04-04 23:08:23 -070097}
98
Dave Barach68b0fb02017-02-28 15:15:56 -050099#define foreach_ssvm_fifo_segment_api_error \
100_(OUT_OF_SPACE, "Out of space in segment", -200)
101
102typedef enum
103{
104#define _(n,s,c) SSVM_FIFO_SEGMENT_API_ERROR_##n = c,
105 foreach_ssvm_fifo_segment_api_error
106#undef _
107} ssvm_fifo_segment_api_error_enum_t;
108
109int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a);
Florin Corasa5464812017-04-19 13:00:05 -0700110int svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t
111 * a);
Dave Barach68b0fb02017-02-28 15:15:56 -0500112int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a);
113void svm_fifo_segment_delete (svm_fifo_segment_private_t * s);
114
115svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400116 u32 data_size_in_bytes,
117 svm_fifo_segment_freelist_t index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500118void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400119 svm_fifo_t * f,
120 svm_fifo_segment_freelist_t index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500121void svm_fifo_segment_init (u64 baseva, u32 timeout_in_seconds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500122u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s);
Florin Corasc87c91d2017-08-16 19:55:49 -0700123u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
Dave Barach91f3e742017-09-01 19:12:11 -0400124u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
125 fifo_segment, u32 fifo_size_in_bytes);
Florin Corasb384b542018-01-15 01:08:33 -0800126void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
127 u64 * size);
Dave Barach91f3e742017-09-01 19:12:11 -0400128
Florin Corasc87c91d2017-08-16 19:55:49 -0700129svm_fifo_segment_private_t *svm_fifo_segment_segments_pool (void);
Florin Corasb384b542018-01-15 01:08:33 -0800130
Dave Barach91f3e742017-09-01 19:12:11 -0400131format_function_t format_svm_fifo_segment;
Florin Corasb384b542018-01-15 01:08:33 -0800132format_function_t format_svm_fifo_segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -0500133
134#endif /* __included_ssvm_fifo_segment_h__ */
135
136/*
137 * fd.io coding-style-patch-verification: ON
138 *
139 * Local Variables:
140 * eval: (c-set-style "gnu")
141 * End:
142 */