blob: 1872da169f9180c461486ee9c0d1ea3193f21893 [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
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
62extern svm_fifo_segment_main_t svm_fifo_segment_main;
63
64typedef struct
65{
Florin Corasb384b542018-01-15 01:08:33 -080066 ssvm_segment_type_t segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -050067 char *segment_name;
68 u32 segment_size;
Dave Barach2c25a622017-06-26 11:35:07 -040069 u32 *new_segment_indices;
Florin Corasb384b542018-01-15 01:08:33 -080070 int memfd_fd;
Dave Barach68b0fb02017-02-28 15:15:56 -050071} svm_fifo_segment_create_args_t;
72
Florin Corasa332c462018-01-31 06:52:17 -080073#define svm_fifo_segment_flags(_seg) _seg->h->flags
74
Dave Barach68b0fb02017-02-28 15:15:56 -050075static inline svm_fifo_segment_private_t *
Florin Corasc87c91d2017-08-16 19:55:49 -070076svm_fifo_segment_get_segment (u32 segment_index)
Dave Barach68b0fb02017-02-28 15:15:56 -050077{
78 svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main;
Florin Corasb384b542018-01-15 01:08:33 -080079 return pool_elt_at_index (ssm->segments, segment_index);
Dave Barach68b0fb02017-02-28 15:15:56 -050080}
81
Florin Coras6cf30ad2017-04-04 23:08:23 -070082static inline u8
83svm_fifo_segment_has_fifos (svm_fifo_segment_private_t * fifo_segment)
84{
Dave Barach10d8cc62017-05-30 09:30:07 -040085 return fifo_segment->h->fifos != 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -070086}
87
Dave Barach10d8cc62017-05-30 09:30:07 -040088static inline svm_fifo_t *
89svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment)
Florin Coras6cf30ad2017-04-04 23:08:23 -070090{
Dave Barach10d8cc62017-05-30 09:30:07 -040091 return fifo_segment->h->fifos;
Florin Coras6cf30ad2017-04-04 23:08:23 -070092}
93
Florin Corasa332c462018-01-31 06:52:17 -080094int svm_fifo_segment_init (svm_fifo_segment_private_t * s);
Dave Barach68b0fb02017-02-28 15:15:56 -050095int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a);
Florin Corasa5464812017-04-19 13:00:05 -070096int svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t
97 * a);
Florin Corasa332c462018-01-31 06:52:17 -080098void svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
99 u32 rx_fifo_size,
100 u32 tx_fifo_size,
101 u32 * n_fifo_pairs);
Dave Barach68b0fb02017-02-28 15:15:56 -0500102int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a);
103void svm_fifo_segment_delete (svm_fifo_segment_private_t * s);
104
105svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400106 u32 data_size_in_bytes,
107 svm_fifo_segment_freelist_t index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500108void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s,
Dave Barach10d8cc62017-05-30 09:30:07 -0400109 svm_fifo_t * f,
110 svm_fifo_segment_freelist_t index);
Florin Corasa332c462018-01-31 06:52:17 -0800111void svm_fifo_segment_main_init (u64 baseva, u32 timeout_in_seconds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500112u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s);
Florin Corasc87c91d2017-08-16 19:55:49 -0700113u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
Dave Barach91f3e742017-09-01 19:12:11 -0400114u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
115 fifo_segment, u32 fifo_size_in_bytes);
Florin Corasb384b542018-01-15 01:08:33 -0800116void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
117 u64 * size);
Dave Barach91f3e742017-09-01 19:12:11 -0400118
Florin Corasc87c91d2017-08-16 19:55:49 -0700119svm_fifo_segment_private_t *svm_fifo_segment_segments_pool (void);
Florin Corasb384b542018-01-15 01:08:33 -0800120
Dave Barach91f3e742017-09-01 19:12:11 -0400121format_function_t format_svm_fifo_segment;
Florin Corasb384b542018-01-15 01:08:33 -0800122format_function_t format_svm_fifo_segment_type;
Dave Barach68b0fb02017-02-28 15:15:56 -0500123
124#endif /* __included_ssvm_fifo_segment_h__ */
125
126/*
127 * fd.io coding-style-patch-verification: ON
128 *
129 * Local Variables:
130 * eval: (c-set-style "gnu")
131 * End:
132 */