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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2019 Vincenzo Maffione <vmaffione@FreeBSD.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __NET_BACKENDS_PRIV_H__
#define __NET_BACKENDS_PRIV_H__
#include <sys/linker_set.h>
/*
* Each network backend registers a set of function pointers that are
* used to implement the net backends API.
* This might need to be exposed if we implement backends in separate files.
*/
struct net_backend {
const char *prefix; /* prefix matching this backend */
/*
* Routines used to initialize and cleanup the resources needed
* by a backend. The cleanup function is used internally,
* and should not be called by the frontend.
*/
int (*init)(struct net_backend *be, const char *devname,
nvlist_t *nvl, net_be_rxeof_t cb, void *param);
void (*cleanup)(struct net_backend *be);
/*
* Called to serve a guest transmit request. The scatter-gather
* vector provided by the caller has 'iovcnt' elements and contains
* the packet to send.
*/
ssize_t (*send)(struct net_backend *be, const struct iovec *iov,
int iovcnt);
/*
* Get the length of the next packet that can be received from
* the backend. If no packets are currently available, this
* function returns 0.
*/
ssize_t (*peek_recvlen)(struct net_backend *be);
/*
* Called to receive a packet from the backend. When the function
* returns a positive value 'len', the scatter-gather vector
* provided by the caller contains a packet with such length.
* The function returns 0 if the backend doesn't have a new packet to
* receive.
*/
ssize_t (*recv)(struct net_backend *be, const struct iovec *iov,
int iovcnt);
/*
* Ask the backend to enable or disable receive operation in the
* backend. On return from a disable operation, it is guaranteed
* that the receive callback won't be called until receive is
* enabled again. Note however that it is up to the caller to make
* sure that netbe_recv() is not currently being executed by another
* thread.
*/
void (*recv_enable)(struct net_backend *be);
void (*recv_disable)(struct net_backend *be);
/*
* Ask the backend for the virtio-net features it is able to
* support. Possible features are TSO, UFO and checksum offloading
* in both rx and tx direction and for both IPv4 and IPv6.
*/
uint64_t (*get_cap)(struct net_backend *be);
/*
* Tell the backend to enable/disable the specified virtio-net
* features (capabilities).
*/
int (*set_cap)(struct net_backend *be, uint64_t features,
unsigned int vnet_hdr_len);
#ifndef __FreeBSD__
int (*get_mac)(struct net_backend *be, void *, size_t *);
#endif
struct pci_vtnet_softc *sc;
int fd;
/*
* Length of the virtio-net header used by the backend and the
* frontend, respectively. A zero value means that the header
* is not used.
*/
unsigned int be_vnet_hdr_len;
unsigned int fe_vnet_hdr_len;
/* Size of backend-specific private data. */
size_t priv_size;
/* Backend-specific private data follows. */
};
#define NET_BE_PRIV(be) ((void *)((be) + 1))
SET_DECLARE(net_backend_set, struct net_backend);
#define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)
#ifdef __FreeBSD__
/*
* Export the tap backend routines for the benefit of other backends which have
* a similar interface to the kernel, i.e., they send and receive data using
* standard I/O system calls with a single file descriptor.
*/
struct tap_priv {
struct mevent *mevp;
/*
* A bounce buffer that allows us to implement the peek_recvlen
* callback. In the future we may get the same information from
* the kevent data.
*/
char bbuf[1 << 16];
ssize_t bbuflen;
};
void tap_cleanup(struct net_backend *be);
ssize_t tap_send(struct net_backend *be, const struct iovec *iov, int io
vcnt);
ssize_t tap_recv(struct net_backend *be, const struct iovec *iov, int io
vcnt);
ssize_t tap_peek_recvlen(struct net_backend *be);
void tap_recv_enable(struct net_backend *be);
ssize_t tap_recv(struct net_backend *be, const struct iovec *iov, int io
vcnt);
void tap_recv_disable(struct net_backend *be);
uint64_t tap_get_cap(struct net_backend *be);
int tap_set_cap(struct net_backend *be, uint64_t features,
unsigned vnet_hdr_len);
#endif /* __FreeBSD__ */
#endif /* !__NET_BACKENDS_PRIV_H__ */
|