blob: caa95443b0a803485392617ddcc0ead96128a1ed [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
Florin Corasca031862018-09-24 13:58:05 -070031#define FIFO_SEGMENT_MAX_FIFO_SIZE (2 << 30) /* 2GB max fifo size */
Florin Corasc87c91d2017-08-16 19:55:49 -070032#define FIFO_SEGMENT_ALLOC_CHUNK_SIZE 32 /* Allocation quantum */
33
Florin Corasf8f516a2018-02-08 15:10:09 -080034#define FIFO_SEGMENT_F_IS_PREALLOCATED (1 << 0)
35#define FIFO_SEGMENT_F_WILL_DELETE (1 << 1)
Dave Barach818eb542017-08-02 13:56:13 -040036
Dave Barach68b0fb02017-02-28 15:15:56 -050037typedef struct
38{
Dave Barach10d8cc62017-05-30 09:30:07 -040039 svm_fifo_t *fifos; /**< Linked list of active RX fifos */
Dave Barach818eb542017-08-02 13:56:13 -040040 svm_fifo_t **free_fifos; /**< Freelists, by fifo size */
Florin Corasc87c91d2017-08-16 19:55:49 -070041 u32 n_active_fifos; /**< Number of active fifos */
42 u8 flags; /**< Segment flags */
Dave Barach68b0fb02017-02-28 15:15:56 -050043} svm_fifo_segment_header_t;
44
45typedef struct
46{
47 ssvm_private_t ssvm;
48 svm_fifo_segment_header_t *h;
49} svm_fifo_segment_private_t;
50
51typedef struct
52{
Florin Corasa5464812017-04-19 13:00:05 -070053 volatile u32 lock;
54
Dave Barach68b0fb02017-02-28 15:15:56 -050055 /** pool of segments */
56 svm_fifo_segment_private_t *segments;
57 /* Where to put the next one */
58 u64 next_baseva;
59 u32 timeout_in_seconds;
60} svm_fifo_segment_main_t;
61
Dave Barach68b0fb02017-02-28 15:15:56 -050062typedef struct
63{
Florin Corasb384b542018-01-15 01:08:33 -080064 ssvm_segment_type_t segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -050065 char *segment_name;
66 u32 segment_size;
Dave Barach2c25a622017-06-26 11:35:07 -040067 u32 *new_segment_indices;
Florin Corasb384b542018-01-15 01:08:33 -080068 int memfd_fd;
Dave Barach68b0fb02017-02-28 15:15:56 -050069} svm_fifo_segment_create_args_t;
70
Florin Corasa332c462018-01-31 06:52:17 -080071#define svm_fifo_segment_flags(_seg) _seg->h->flags
72
Dave Barach68b0fb02017-02-28 15:15:56 -050073static inline svm_fifo_segment_private_t *
Florin Corasadc74d72018-12-02 13:36:00 -080074svm_fifo_segment_get_segment (svm_fifo_segment_main_t * sm, u32 segment_index)
Dave Barach68b0fb02017-02-28 15:15:56 -050075{
Florin Corasadc74d72018-12-02 13:36:00 -080076 return pool_elt_at_index (sm->segments, segment_index);
Dave Barach68b0fb02017-02-28 15:15:56 -050077}
78
Florin Coras6cf30ad2017-04-04 23:08:23 -070079static inline u8
80svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment)
81{
Dave Barach10d8cc62017-05-30 09:30:07 -040082 return fifo_segment->h->fifos != 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -070083}
84
Dave Barach10d8cc62017-05-30 09:30:07 -040085static inline svm_fifo_t *
86svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment)
Florin Coras6cf30ad2017-04-04 23:08:23 -070087{
Dave Barach10d8cc62017-05-30 09:30:07 -040088 return fifo_segment->h->fifos;
Florin Coras6cf30ad2017-04-04 23:08:23 -070089}
90
Florin Corasa332c462018-01-31 06:52:17 -080091int svm_fifo_segment_init (svm_fifo_segment_private_t * s);
Florin Corasadc74d72018-12-02 13:36:00 -080092int svm_fifo_segment_create (svm_fifo_segment_main_t * sm,
93 svm_fifo_segment_create_args_t * a);
94int svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
95 svm_fifo_segment_create_args_t
96 *);
Florin Corasa332c462018-01-31 06:52:17 -080097void svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
98 u32 rx_fifo_size,
99 u32 tx_fifo_size,
100 u32 * n_fifo_pairs);
Florin Corasadc74d72018-12-02 13:36:00 -0800101int svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
102 svm_fifo_segment_create_args_t * a);
103void svm_fifo_segment_delete (svm_fifo_segment_main_t * sm,
104 svm_fifo_segment_private_t * s);
Dave Barach68b0fb02017-02-28 15:15:56 -0500105
106svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400107 u32 data_size_in_bytes,
108 svm_fifo_segment_freelist_t index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500109void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400110 svm_fifo_t * f,
111 svm_fifo_segment_freelist_t index);
Florin Corasadc74d72018-12-02 13:36:00 -0800112void svm_fifo_segment_main_init (svm_fifo_segment_main_t * sm, u64 baseva,
113 u32 timeout_in_seconds);
114u32 svm_fifo_segment_index (svm_fifo_segment_main_t * sm,
115 svm_fifo_segment_private_t * s);
Florin Corasc87c91d2017-08-16 19:55:49 -0700116u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
Dave Barach91f3e742017-09-01 19:12:11 -0400117u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
118 fifo_segment, u32 fifo_size_in_bytes);
David Johnsond9818dd2018-12-14 14:53:41 -0500119void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, char **address,
120 size_t * size);
Dave Barach91f3e742017-09-01 19:12:11 -0400121
Florin Corasadc74d72018-12-02 13:36:00 -0800122svm_fifo_segment_private_t
123 * svm_fifo_segment_segments_pool (svm_fifo_segment_main_t * sm);
Florin Corasb384b542018-01-15 01:08:33 -0800124
Dave Barach91f3e742017-09-01 19:12:11 -0400125format_function_t format_svm_fifo_segment;
Florin Corasb384b542018-01-15 01:08:33 -0800126format_function_t format_svm_fifo_segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -0500127
128#endif /* __included_ssvm_fifo_segment_h__ */
129
130/*
131 * fd.io coding-style-patch-verification: ON
132 *
133 * Local Variables:
134 * eval: (c-set-style "gnu")
135 * End:
136 */