FD.io VPP
v17.01.1-3-gc6833f8
Vector Packet Processing
Main Page
Related Pages
Data Structures
Source
Files
Symbols
netmap.h
Go to the documentation of this file.
1
/*
2
*------------------------------------------------------------------
3
* Copyright (c) 2016 Cisco and/or its affiliates.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at:
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*------------------------------------------------------------------
16
*/
17
/*
18
* Copyright (C) 2011-2014 Universita` di Pisa. All rights reserved.
19
*
20
* Redistribution and use in source and binary forms, with or without
21
* modification, are permitted provided that the following conditions
22
* are met:
23
*
24
* 1. Redistributions of source code must retain the above copyright
25
* notice, this list of conditions and the following disclaimer.
26
* 2. Redistributions in binary form must reproduce the above copyright
27
* notice, this list of conditions and the following disclaimer in the
28
* documentation and/or other materials provided with the distribution.
29
*
30
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40
* SUCH DAMAGE.
41
*/
42
43
typedef
struct
44
{
45
CLIB_CACHE_LINE_ALIGN_MARK
(cacheline0);
46
volatile
u32
*
lockp
;
47
u8
*
host_if_name
;
48
uword
if_index
;
49
u32
hw_if_index
;
50
u32
sw_if_index
;
51
u32
unix_file_index
;
52
53
u32
per_interface_next_index
;
54
u8
is_admin_up
;
55
56
/* netmap */
57
struct
nmreq
*
req
;
58
u16
mem_region
;
59
int
fd
;
60
struct
netmap_if
*
nifp
;
61
u16
first_tx_ring
;
62
u16
last_tx_ring
;
63
u16
first_rx_ring
;
64
u16
last_rx_ring
;
65
66
}
netmap_if_t
;
67
68
typedef
struct
69
{
70
char
*
mem
;
71
u32
region_size
;
72
int
refcnt
;
73
}
netmap_mem_region_t
;
74
75
typedef
struct
76
{
77
CLIB_CACHE_LINE_ALIGN_MARK
(cacheline0);
78
netmap_if_t
*
interfaces
;
79
80
/* bitmap of pending rx interfaces */
81
uword
*
pending_input_bitmap
;
82
83
/* rx buffer cache */
84
u32
**
rx_buffers
;
85
86
/* hash of host interface names */
87
mhash_t
if_index_by_host_if_name
;
88
89
/* vector of memory regions */
90
netmap_mem_region_t
*
mem_regions
;
91
92
/* first cpu index */
93
u32
input_cpu_first_index
;
94
95
/* total cpu count */
96
u32
input_cpu_count
;
97
}
netmap_main_t
;
98
99
netmap_main_t
netmap_main
;
100
extern
vnet_device_class_t
netmap_device_class
;
101
extern
vlib_node_registration_t
netmap_input_node
;
102
103
int
netmap_create_if
(
vlib_main_t
* vm,
u8
* host_if_name,
u8
* hw_addr_set,
104
u8
is_pipe,
u8
is_master,
u32
* sw_if_index);
105
int
netmap_delete_if
(
vlib_main_t
* vm,
u8
* host_if_name);
106
107
108
/* Macros and helper functions from sys/net/netmap_user.h */
109
110
#ifdef _NET_NETMAP_H_
111
112
#define _NETMAP_OFFSET(type, ptr, offset) \
113
((type)(void *)((char *)(ptr) + (offset)))
114
115
#define NETMAP_IF(_base, _ofs) _NETMAP_OFFSET(struct netmap_if *, _base, _ofs)
116
117
#define NETMAP_TXRING(nifp, index) _NETMAP_OFFSET(struct netmap_ring *, \
118
nifp, (nifp)->ring_ofs[index] )
119
120
#define NETMAP_RXRING(nifp, index) _NETMAP_OFFSET(struct netmap_ring *, \
121
nifp, (nifp)->ring_ofs[index + (nifp)->ni_tx_rings + 1] )
122
123
#define NETMAP_BUF(ring, index) \
124
((char *)(ring) + (ring)->buf_ofs + ((index)*(ring)->nr_buf_size))
125
126
#define NETMAP_BUF_IDX(ring, buf) \
127
( ((char *)(buf) - ((char *)(ring) + (ring)->buf_ofs) ) / \
128
(ring)->nr_buf_size )
129
130
static
inline
uint32_t
131
nm_ring_next (
struct
netmap_ring
*ring, uint32_t i)
132
{
133
return
(
PREDICT_FALSE
(i + 1 == ring->
num_slots
) ? 0 : i + 1);
134
}
135
136
137
/*
138
* Return 1 if we have pending transmissions in the tx ring.
139
* When everything is complete ring->head = ring->tail + 1 (modulo ring size)
140
*/
141
static
inline
int
142
nm_tx_pending (
struct
netmap_ring
*ring)
143
{
144
return
nm_ring_next (ring, ring->
tail
) != ring->
head
;
145
}
146
147
static
inline
uint32_t
148
nm_ring_space (
struct
netmap_ring
*ring)
149
{
150
int
ret = ring->
tail
- ring->
cur
;
151
if
(ret < 0)
152
ret += ring->
num_slots
;
153
return
ret;
154
}
155
#endif
156
157
158
/*
159
* fd.io coding-style-patch-verification: ON
160
*
161
* Local Variables:
162
* eval: (c-set-style "gnu")
163
* End:
164
*/
netmap_ring::num_slots
const uint32_t num_slots
Definition:
net_netmap.h:266
mhash_t
Definition:
mhash.h:46
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition:
cache.h:68
netmap_main_t::interfaces
netmap_if_t * interfaces
Definition:
netmap.h:78
netmap_if_t::lockp
volatile u32 * lockp
Definition:
netmap.h:46
netmap_ring::cur
uint32_t cur
Definition:
net_netmap.h:272
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
netmap_delete_if
int netmap_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition:
netmap.c:248
vnet_device_class_t
struct _vnet_device_class vnet_device_class_t
nmreq
Definition:
net_netmap.h:474
netmap_if_t::sw_if_index
u32 sw_if_index
Definition:
netmap.h:50
netmap_mem_region_t::refcnt
int refcnt
Definition:
netmap.h:72
netmap_if
Definition:
net_netmap.h:318
netmap_main_t
Definition:
netmap.h:75
netmap_create_if
int netmap_create_if(vlib_main_t *vm, u8 *host_if_name, u8 *hw_addr_set, u8 is_pipe, u8 is_master, u32 *sw_if_index)
Definition:
netmap.c:113
netmap_if_t::per_interface_next_index
u32 per_interface_next_index
Definition:
netmap.h:53
netmap_main_t::input_cpu_count
u32 input_cpu_count
Definition:
netmap.h:96
netmap_if_t::nifp
struct netmap_if * nifp
Definition:
netmap.h:60
netmap_if_t::req
struct nmreq * req
Definition:
netmap.h:57
netmap_main_t::mem_regions
netmap_mem_region_t * mem_regions
Definition:
netmap.h:90
netmap_mem_region_t
Definition:
netmap.h:68
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition:
clib.h:97
netmap_if_t::first_rx_ring
u16 first_rx_ring
Definition:
netmap.h:63
netmap_mem_region_t::region_size
u32 region_size
Definition:
netmap.h:71
netmap_main_t::if_index_by_host_if_name
mhash_t if_index_by_host_if_name
Definition:
netmap.h:87
netmap_if_t::fd
int fd
Definition:
netmap.h:59
netmap_ring::head
uint32_t head
Definition:
net_netmap.h:271
netmap_if_t::first_tx_ring
u16 first_tx_ring
Definition:
netmap.h:61
netmap_if_t::hw_if_index
u32 hw_if_index
Definition:
netmap.h:49
netmap_if_t::last_rx_ring
u16 last_rx_ring
Definition:
netmap.h:64
netmap_ring::tail
uint32_t tail
Definition:
net_netmap.h:273
netmap_if_t::last_tx_ring
u16 last_tx_ring
Definition:
netmap.h:62
netmap_if_t::if_index
uword if_index
Definition:
netmap.h:48
netmap_main
netmap_main_t netmap_main
Definition:
netmap.h:99
netmap_input_node
vlib_node_registration_t netmap_input_node
(constructor) VLIB_REGISTER_NODE (netmap_input_node)
Definition:
node.c:278
u32
unsigned int u32
Definition:
types.h:88
netmap_ring
Definition:
net_netmap.h:259
netmap_if_t::mem_region
u16 mem_region
Definition:
netmap.h:58
netmap_if_t
Definition:
netmap.h:43
netmap_if_t::host_if_name
u8 * host_if_name
Definition:
netmap.h:47
uword
u64 uword
Definition:
types.h:112
netmap_if_t::unix_file_index
u32 unix_file_index
Definition:
netmap.h:51
netmap_main_t::input_cpu_first_index
u32 input_cpu_first_index
Definition:
netmap.h:93
u16
unsigned short u16
Definition:
types.h:57
netmap_mem_region_t::mem
char * mem
Definition:
netmap.h:70
netmap_if_t::is_admin_up
u8 is_admin_up
Definition:
netmap.h:54
u8
unsigned char u8
Definition:
types.h:56
netmap_device_class
vnet_device_class_t netmap_device_class
vlib_main_t
Definition:
main.h:59
netmap_main_t::pending_input_bitmap
uword * pending_input_bitmap
Definition:
netmap.h:81
netmap_main_t::rx_buffers
u32 ** rx_buffers
Definition:
netmap.h:84
vnet
vnet
devices
netmap
netmap.h
Generated on Mon May 15 2017 22:01:56 for FD.io VPP by
1.8.11