aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/devices/ssvm/ssvm_eth.h
blob: 7f9aaad3e827573833e0dd1d0565bc64ec4ed1f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (c) 2015 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __included_ssvm_eth_h__
#define __included_ssvm_eth_h__

#include <vnet/vnet.h>

#include <vppinfra/elog.h>
#include <vppinfra/error.h>
#include <vppinfra/format.h>
#include <vppinfra/hash.h>
#include <vppinfra/vec.h>
#include <vppinfra/elog.h>
#include <vlib/vlib.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/devices/devices.h>
#include <vnet/ip/ip.h>
#include <vnet/pg/pg.h>
#include <vlibmemory/unix_shared_memory_queue.h>

#include <svm/ssvm.h>

extern vnet_device_class_t ssvm_eth_device_class;
extern vlib_node_registration_t ssvm_eth_input_node;

#define SSVM_BUFFER_SIZE  \
  (VLIB_BUFFER_DATA_SIZE + VLIB_BUFFER_PRE_DATA_SIZE)
#define SSVM_PACKET_TYPE 1

typedef struct
{
  /* Type of queue element */
  u8 type;
  u8 flags;
#define SSVM_BUFFER_NEXT_PRESENT (1<<0)
  u8 owner;
  u8 tag;
  i16 current_data_hint;
  u16 length_this_buffer;
  u16 total_length_not_including_first_buffer;
  u16 pad;
  u32 next_index;
  /* offset 16 */
  u8 data[SSVM_BUFFER_SIZE];
  /* pad to an even multiple of 64 octets */
  u8 pad2[CLIB_CACHE_LINE_BYTES - 16];
} ssvm_eth_queue_elt_t;

typedef struct
{
  /* vector of point-to-point connections */
  ssvm_private_t *intfcs;

  u32 *buffer_cache;
  u32 *chunk_cache;

  /* Configurable parameters */
  /* base address for next placement */
  u64 next_base_va;
  u64 segment_size;
  u64 nbuffers;
  u64 queue_elts;

  /* Segment names */
  u8 **names;

  /* convenience */
  vlib_main_t *vlib_main;
  vnet_main_t *vnet_main;
  elog_main_t *elog_main;
} ssvm_eth_main_t;

extern ssvm_eth_main_t ssvm_eth_main;

typedef enum
{
  CHUNK_POOL_FREELIST_INDEX = 0,
  CHUNK_POOL_INDEX,
  CHUNK_POOL_NFREE,
  TO_MASTER_Q_INDEX,
  TO_SLAVE_Q_INDEX,
  MASTER_ADMIN_STATE_INDEX,
  SLAVE_ADMIN_STATE_INDEX,
} ssvm_eth_opaque_index_t;

/*
 * debug scaffolding.
 */
static inline void
ssvm_eth_validate_freelists (int need_lock)
{
#if CLIB_DEBUG > 0
  ssvm_eth_main_t *em = &ssvm_eth_main;
  ssvm_private_t *intfc;
  ssvm_shared_header_t *sh;
  u32 *elt_indices;
  u32 n_available;
  int i;

  for (i = 0; i < vec_len (em->intfcs); i++)
    {
      intfc = em->intfcs + i;
      sh = intfc->sh;
      u32 my_pid = intfc->my_pid;

      if (need_lock)
	ssvm_lock (sh, my_pid, 15);

      elt_indices = (u32 *) (sh->opaque[CHUNK_POOL_FREELIST_INDEX]);
      n_available = (u32) (uword) (sh->opaque[CHUNK_POOL_NFREE]);

      for (i = 0; i < n_available; i++)
	ASSERT (elt_indices[i] < 2048);

      if (need_lock)
	ssvm_unlock (sh);
    }
#endif
}

#endif /* __included_ssvm_eth_h__ */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */