Initial commit of vpp code.
[vpp.git] / vnet / vnet / devices / ssvm / ssvm_eth.h
1 /*
2  * Copyright (c) 2015 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_eth_h__
16 #define __included_ssvm_eth_h__
17
18 #include <vnet/vnet.h>
19
20 #include <vppinfra/elog.h>
21 #include <vppinfra/error.h>
22 #include <vppinfra/format.h>
23 #include <vppinfra/hash.h>
24 #include <vppinfra/vec.h>
25 #include <vppinfra/elog.h>
26 #include <vlib/vlib.h>
27 #include <vnet/ethernet/ethernet.h>
28 #include <vnet/ip/ip.h>
29 #include <vnet/pg/pg.h>
30 #include <vlibmemory/unix_shared_memory_queue.h>
31
32 #include <ssvm.h>
33
34 vnet_device_class_t ssvm_eth_device_class;
35 vlib_node_registration_t ssvm_eth_input_node;
36
37 #define SSVM_BUFFER_SIZE  \
38   (VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES + VLIB_BUFFER_PRE_DATA_SIZE)
39 #define SSVM_PACKET_TYPE 1
40
41 typedef struct {
42   /* Type of queue element */
43   u8 type;
44   u8 flags;
45 #define SSVM_BUFFER_NEXT_PRESENT (1<<0)
46   u8 owner;
47   u8 tag;
48   i16 current_data_hint;
49   u16 length_this_buffer;
50   u16 total_length_not_including_first_buffer;
51   u16 pad;
52   u32 next_index;
53   /* offset 16 */
54   u8 data [SSVM_BUFFER_SIZE];
55   /* pad to an even multiple of 64 octets */
56   u8 pad2[CLIB_CACHE_LINE_BYTES - 16];
57 } ssvm_eth_queue_elt_t;
58
59 typedef struct {
60   /* vector of point-to-point connections */
61   ssvm_private_t * intfcs;
62
63   u32 * buffer_cache;
64   u32 * chunk_cache;
65
66   /* Configurable parameters */
67   /* base address for next placement */
68   u64 next_base_va;
69   u64 segment_size;
70   u64 nbuffers;
71   u64 queue_elts;
72
73   /* Segment names */
74   u8 ** names;
75
76   /* convenience */
77   vlib_main_t * vlib_main;
78   vnet_main_t * vnet_main;
79   elog_main_t * elog_main;
80 } ssvm_eth_main_t;
81
82 ssvm_eth_main_t ssvm_eth_main;
83
84 typedef enum {
85   CHUNK_POOL_FREELIST_INDEX = 0,
86   CHUNK_POOL_INDEX, 
87   CHUNK_POOL_NFREE,
88   TO_MASTER_Q_INDEX,
89   TO_SLAVE_Q_INDEX,
90   MASTER_ADMIN_STATE_INDEX,
91   SLAVE_ADMIN_STATE_INDEX,
92 } ssvm_eth_opaque_index_t;
93
94 /*
95  * debug scaffolding.
96  */
97 static inline void ssvm_eth_validate_freelists (int need_lock)
98 {
99 #if CLIB_DEBUG > 0
100   ssvm_eth_main_t * em = &ssvm_eth_main;
101   ssvm_private_t * intfc;
102   ssvm_shared_header_t * sh;
103   u32 * elt_indices;
104   u32 n_available;
105   int i;
106
107   for (i = 0; i < vec_len (em->intfcs); i++)
108     {
109       intfc = em->intfcs + i;
110       sh = intfc->sh;
111       u32 my_pid = intfc->my_pid;
112   
113       if (need_lock)
114         ssvm_lock (sh, my_pid, 15);
115
116       elt_indices = (u32 *) (sh->opaque [CHUNK_POOL_FREELIST_INDEX]);
117       n_available = (u32) (u64) (sh->opaque [CHUNK_POOL_NFREE]);
118
119       for (i = 0; i < n_available; i++)
120         ASSERT (elt_indices[i] < 2048);
121
122       if (need_lock)
123         ssvm_unlock (sh);
124     }
125 #endif
126 }
127
128 #endif /* __included_ssvm_eth_h__ */