xref: /dflybsd-src/sys/net/netmap/netmap.h (revision f933b737dabc806a2f1680f0afea2fb42a345b92)
1*f933b737SSascha Wildner /*
2*f933b737SSascha Wildner  * Copyright (C) 2011-2013 Matteo Landi, Luigi Rizzo. All rights reserved.
3*f933b737SSascha Wildner  *
4*f933b737SSascha Wildner  * Redistribution and use in source and binary forms, with or without
5*f933b737SSascha Wildner  * modification, are permitted provided that the following conditions
6*f933b737SSascha Wildner  * are met:
7*f933b737SSascha Wildner  *
8*f933b737SSascha Wildner  *   1. Redistributions of source code must retain the above copyright
9*f933b737SSascha Wildner  *      notice, this list of conditions and the following disclaimer.
10*f933b737SSascha Wildner  *   2. Redistributions in binary form must reproduce the above copyright
11*f933b737SSascha Wildner  *      notice, this list of conditions and the following disclaimer in the
12*f933b737SSascha Wildner  *      documentation and/or other materials provided with the distribution.
13*f933b737SSascha Wildner  *
14*f933b737SSascha Wildner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND
15*f933b737SSascha Wildner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*f933b737SSascha Wildner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*f933b737SSascha Wildner  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*f933b737SSascha Wildner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*f933b737SSascha Wildner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*f933b737SSascha Wildner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*f933b737SSascha Wildner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*f933b737SSascha Wildner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*f933b737SSascha Wildner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*f933b737SSascha Wildner  * SUCH DAMAGE.
25*f933b737SSascha Wildner  */
26*f933b737SSascha Wildner 
27*f933b737SSascha Wildner /*
28*f933b737SSascha Wildner  * $FreeBSD: head/sys/net/netmap.h 251139 2013-05-30 14:07:14Z luigi $
29*f933b737SSascha Wildner  *
30*f933b737SSascha Wildner  * Definitions of constants and the structures used by the netmap
31*f933b737SSascha Wildner  * framework, for the part visible to both kernel and userspace.
32*f933b737SSascha Wildner  * Detailed info on netmap is available with "man netmap" or at
33*f933b737SSascha Wildner  *
34*f933b737SSascha Wildner  *	http://info.iet.unipi.it/~luigi/netmap/
35*f933b737SSascha Wildner  *
36*f933b737SSascha Wildner  * This API is also used to communicate with the VALE software switch
37*f933b737SSascha Wildner  */
38*f933b737SSascha Wildner 
39*f933b737SSascha Wildner #ifndef _NET_NETMAP_H_
40*f933b737SSascha Wildner #define _NET_NETMAP_H_
41*f933b737SSascha Wildner 
42*f933b737SSascha Wildner /*
43*f933b737SSascha Wildner  * --- Netmap data structures ---
44*f933b737SSascha Wildner  *
45*f933b737SSascha Wildner  * The userspace data structures used by netmap are shown below.
46*f933b737SSascha Wildner  * They are allocated by the kernel and mmap()ed by userspace threads.
47*f933b737SSascha Wildner  * Pointers are implemented as memory offsets or indexes,
48*f933b737SSascha Wildner  * so that they can be easily dereferenced in kernel and userspace.
49*f933b737SSascha Wildner 
50*f933b737SSascha Wildner    KERNEL (opaque, obviously)
51*f933b737SSascha Wildner 
52*f933b737SSascha Wildner   ====================================================================
53*f933b737SSascha Wildner                                          |
54*f933b737SSascha Wildner    USERSPACE                             |      struct netmap_ring
55*f933b737SSascha Wildner                                          +---->+--------------+
56*f933b737SSascha Wildner                                              / | cur          |
57*f933b737SSascha Wildner    struct netmap_if (nifp, 1 per fd)        /  | avail        |
58*f933b737SSascha Wildner     +---------------+                      /   | buf_ofs      |
59*f933b737SSascha Wildner     | ni_tx_rings   |                     /    +==============+
60*f933b737SSascha Wildner     | ni_rx_rings   |                    /     | buf_idx, len | slot[0]
61*f933b737SSascha Wildner     |               |                   /      | flags, ptr   |
62*f933b737SSascha Wildner     |               |                  /       +--------------+
63*f933b737SSascha Wildner     +===============+                 /        | buf_idx, len | slot[1]
64*f933b737SSascha Wildner     | txring_ofs[0] | (rel.to nifp)--'         | flags, ptr   |
65*f933b737SSascha Wildner     | txring_ofs[1] |                          +--------------+
66*f933b737SSascha Wildner   (ni_tx_rings+1 entries)                     (num_slots entries)
67*f933b737SSascha Wildner     | txring_ofs[t] |                          | buf_idx, len | slot[n-1]
68*f933b737SSascha Wildner     +---------------+                          | flags, ptr   |
69*f933b737SSascha Wildner     | rxring_ofs[0] |                          +--------------+
70*f933b737SSascha Wildner     | rxring_ofs[1] |
71*f933b737SSascha Wildner   (ni_rx_rings+1 entries)
72*f933b737SSascha Wildner     | rxring_ofs[r] |
73*f933b737SSascha Wildner     +---------------+
74*f933b737SSascha Wildner 
75*f933b737SSascha Wildner  * For each "interface" (NIC, host stack, VALE switch port) attached to a
76*f933b737SSascha Wildner  * file descriptor, the mmap()ed region contains a (logically readonly)
77*f933b737SSascha Wildner  * struct netmap_if pointing to struct netmap_ring's.
78*f933b737SSascha Wildner  * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
79*f933b737SSascha Wildner  * pair attached to the host stack (this pair is unused for VALE ports).
80*f933b737SSascha Wildner  *
81*f933b737SSascha Wildner  * All physical/host stack ports share the same memory region,
82*f933b737SSascha Wildner  * so that zero-copy can be implemented between them.
83*f933b737SSascha Wildner  * VALE switch ports instead have separate memory regions.
84*f933b737SSascha Wildner  *
85*f933b737SSascha Wildner  * The netmap_ring is the userspace-visible replica of the NIC ring.
86*f933b737SSascha Wildner  * Each slot has the index of a buffer (MTU-sized and residing in the
87*f933b737SSascha Wildner  * mmapped region), its length and some flags. An extra 64-bit pointer
88*f933b737SSascha Wildner  * is provided for user-supplied buffers in the tx path.
89*f933b737SSascha Wildner  *
90*f933b737SSascha Wildner  * In user space, the buffer address is computed as
91*f933b737SSascha Wildner  *	(char *)ring + buf_ofs + index*NETMAP_BUF_SIZE
92*f933b737SSascha Wildner  */
93*f933b737SSascha Wildner 
94*f933b737SSascha Wildner /*
95*f933b737SSascha Wildner  * struct netmap_slot is a buffer descriptor
96*f933b737SSascha Wildner  *
97*f933b737SSascha Wildner  * buf_idx	the index of the buffer associated to the slot.
98*f933b737SSascha Wildner  * len		the length of the payload
99*f933b737SSascha Wildner  * flags	control operation on the slot, as defined below
100*f933b737SSascha Wildner  *
101*f933b737SSascha Wildner  * NS_BUF_CHANGED	must be set whenever userspace wants
102*f933b737SSascha Wildner  *		to change buf_idx (it might be necessary to
103*f933b737SSascha Wildner  *		reprogram the NIC)
104*f933b737SSascha Wildner  *
105*f933b737SSascha Wildner  * NS_REPORT	must be set if we want the NIC to generate an interrupt
106*f933b737SSascha Wildner  *		when this slot is used. Leaving it to 0 improves
107*f933b737SSascha Wildner  *		performance.
108*f933b737SSascha Wildner  *
109*f933b737SSascha Wildner  * NS_FORWARD	if set on a receive ring, and the device is in
110*f933b737SSascha Wildner  *		transparent mode, buffers released with the flag set
111*f933b737SSascha Wildner  *		will be forwarded to the 'other' side (host stack
112*f933b737SSascha Wildner  *		or NIC, respectively) on the next select() or ioctl()
113*f933b737SSascha Wildner  *
114*f933b737SSascha Wildner  * NS_NO_LEARN	on a VALE switch, do not 'learn' the source port for
115*f933b737SSascha Wildner  *		this packet.
116*f933b737SSascha Wildner  *
117*f933b737SSascha Wildner  * NS_INDIRECT	(tx rings only) data is in a userspace buffer pointed
118*f933b737SSascha Wildner  *		by the ptr field in the slot.
119*f933b737SSascha Wildner  *
120*f933b737SSascha Wildner  * NS_MOREFRAG	Part of a multi-segment frame. The last (or only)
121*f933b737SSascha Wildner  *		segment must not have this flag.
122*f933b737SSascha Wildner  *		Only supported on VALE ports.
123*f933b737SSascha Wildner  *
124*f933b737SSascha Wildner  * NS_PORT_MASK	the high 8 bits of the flag, if not zero, indicate the
125*f933b737SSascha Wildner  *		destination port for the VALE switch, overriding
126*f933b737SSascha Wildner  *		the lookup table.
127*f933b737SSascha Wildner  */
128*f933b737SSascha Wildner 
129*f933b737SSascha Wildner struct netmap_slot {
130*f933b737SSascha Wildner 	uint32_t buf_idx;	/* buffer index */
131*f933b737SSascha Wildner 	uint16_t len;		/* packet length */
132*f933b737SSascha Wildner 	uint16_t flags;		/* buf changed, etc. */
133*f933b737SSascha Wildner #define	NS_BUF_CHANGED	0x0001	/* buf_idx changed */
134*f933b737SSascha Wildner #define	NS_REPORT	0x0002	/* ask the hardware to report results
135*f933b737SSascha Wildner 				 * e.g. by generating an interrupt
136*f933b737SSascha Wildner 				 */
137*f933b737SSascha Wildner #define	NS_FORWARD	0x0004	/* pass packet to the other endpoint
138*f933b737SSascha Wildner 				 * (host stack or device)
139*f933b737SSascha Wildner 				 */
140*f933b737SSascha Wildner #define	NS_NO_LEARN	0x0008
141*f933b737SSascha Wildner #define	NS_INDIRECT	0x0010
142*f933b737SSascha Wildner #define	NS_MOREFRAG	0x0020
143*f933b737SSascha Wildner #define	NS_PORT_SHIFT	8
144*f933b737SSascha Wildner #define	NS_PORT_MASK	(0xff << NS_PORT_SHIFT)
145*f933b737SSascha Wildner 				/*
146*f933b737SSascha Wildner 				 * in rx rings, the high 8 bits
147*f933b737SSascha Wildner 				 *  are the number of fragments.
148*f933b737SSascha Wildner 				 */
149*f933b737SSascha Wildner #define	NS_RFRAGS(_slot)	( ((_slot)->flags >> 8) & 0xff)
150*f933b737SSascha Wildner 	uint64_t	ptr;	/* pointer for indirect buffers */
151*f933b737SSascha Wildner };
152*f933b737SSascha Wildner 
153*f933b737SSascha Wildner /*
154*f933b737SSascha Wildner  * struct netmap_ring
155*f933b737SSascha Wildner  *
156*f933b737SSascha Wildner  * Netmap representation of a TX or RX ring (also known as "queue").
157*f933b737SSascha Wildner  * This is a queue implemented as a fixed-size circular array.
158*f933b737SSascha Wildner  * At the software level, two fields are important: avail and cur.
159*f933b737SSascha Wildner  *
160*f933b737SSascha Wildner  * In TX rings:
161*f933b737SSascha Wildner  *
162*f933b737SSascha Wildner  *	avail	tells how many slots are available for transmission.
163*f933b737SSascha Wildner  *		It is updated by the kernel in each netmap system call.
164*f933b737SSascha Wildner  *		It MUST BE decremented by the user when it
165*f933b737SSascha Wildner  *		adds a new packet to send.
166*f933b737SSascha Wildner  *
167*f933b737SSascha Wildner  *	cur	indicates the slot to use for the next packet
168*f933b737SSascha Wildner  *		to send (i.e. the "tail" of the queue).
169*f933b737SSascha Wildner  *		It MUST BE incremented by the user before
170*f933b737SSascha Wildner  *		netmap system calls to reflect the number of newly
171*f933b737SSascha Wildner  *		sent packets.
172*f933b737SSascha Wildner  *		It is checked by the kernel on netmap system calls
173*f933b737SSascha Wildner  *		(normally unmodified by the kernel unless invalid).
174*f933b737SSascha Wildner  *
175*f933b737SSascha Wildner  * In RX rings:
176*f933b737SSascha Wildner  *
177*f933b737SSascha Wildner  *	avail	is the number of packets available (possibly 0).
178*f933b737SSascha Wildner  *		It is updated by the kernel in each netmap system call.
179*f933b737SSascha Wildner  *		It MUST BE decremented by the user when it
180*f933b737SSascha Wildner  *		consumes a packet.
181*f933b737SSascha Wildner  *
182*f933b737SSascha Wildner  *	cur	indicates the first slot that contains a packet not
183*f933b737SSascha Wildner  *		yet processed (the "head" of the queue).
184*f933b737SSascha Wildner  *		It MUST BE incremented by the user when it consumes
185*f933b737SSascha Wildner  *		a packet.
186*f933b737SSascha Wildner  *
187*f933b737SSascha Wildner  *	reserved	indicates the number of buffers before 'cur'
188*f933b737SSascha Wildner  *		that the user has not released yet. Normally 0,
189*f933b737SSascha Wildner  *		it MUST BE incremented by the user when it
190*f933b737SSascha Wildner  *		does not return the buffer immediately, and decremented
191*f933b737SSascha Wildner  *		when the buffer is finally freed.
192*f933b737SSascha Wildner  *
193*f933b737SSascha Wildner  *
194*f933b737SSascha Wildner  * DATA OWNERSHIP/LOCKING:
195*f933b737SSascha Wildner  *	The netmap_ring, all slots, and buffers in the range
196*f933b737SSascha Wildner  *	[reserved-cur , cur+avail[ are owned by the user program,
197*f933b737SSascha Wildner  *	and the kernel only touches them in the same thread context
198*f933b737SSascha Wildner  *	during a system call.
199*f933b737SSascha Wildner  *	Other buffers are reserved for use by the NIC's DMA engines.
200*f933b737SSascha Wildner  *
201*f933b737SSascha Wildner  * FLAGS
202*f933b737SSascha Wildner  *	NR_TIMESTAMP	updates the 'ts' field on each syscall. This is
203*f933b737SSascha Wildner  *			a global timestamp for all packets.
204*f933b737SSascha Wildner  *	NR_RX_TSTMP	if set, the last 64 byte in each buffer will
205*f933b737SSascha Wildner  *			contain a timestamp for the frame supplied by
206*f933b737SSascha Wildner  *			the hardware (if supported)
207*f933b737SSascha Wildner  *	NR_FORWARD	if set, the NS_FORWARD flag in each slot of the
208*f933b737SSascha Wildner  *			RX ring is checked, and if set the packet is
209*f933b737SSascha Wildner  *			passed to the other side (host stack or device,
210*f933b737SSascha Wildner  *			respectively). This permits bpf-like behaviour
211*f933b737SSascha Wildner  *			or transparency for selected packets.
212*f933b737SSascha Wildner  */
213*f933b737SSascha Wildner struct netmap_ring {
214*f933b737SSascha Wildner 	/*
215*f933b737SSascha Wildner 	 * buf_ofs is meant to be used through macros.
216*f933b737SSascha Wildner 	 * It contains the offset of the buffer region from this
217*f933b737SSascha Wildner 	 * descriptor.
218*f933b737SSascha Wildner 	 */
219*f933b737SSascha Wildner 	const ssize_t	buf_ofs;
220*f933b737SSascha Wildner 	const uint32_t	num_slots;	/* number of slots in the ring. */
221*f933b737SSascha Wildner 	uint32_t	avail;		/* number of usable slots */
222*f933b737SSascha Wildner 	uint32_t        cur;		/* 'current' r/w position */
223*f933b737SSascha Wildner 	uint32_t	reserved;	/* not refilled before current */
224*f933b737SSascha Wildner 
225*f933b737SSascha Wildner 	const uint16_t	nr_buf_size;
226*f933b737SSascha Wildner 	uint16_t	flags;
227*f933b737SSascha Wildner #define	NR_TIMESTAMP	0x0002		/* set timestamp on *sync() */
228*f933b737SSascha Wildner #define	NR_FORWARD	0x0004		/* enable NS_FORWARD for ring */
229*f933b737SSascha Wildner #define	NR_RX_TSTMP	0x0008		/* set rx timestamp in slots */
230*f933b737SSascha Wildner 
231*f933b737SSascha Wildner 	struct timeval	ts;		/* time of last *sync() */
232*f933b737SSascha Wildner 
233*f933b737SSascha Wildner 	/* the slots follow. This struct has variable size */
234*f933b737SSascha Wildner 	struct netmap_slot slot[0];	/* array of slots. */
235*f933b737SSascha Wildner };
236*f933b737SSascha Wildner 
237*f933b737SSascha Wildner 
238*f933b737SSascha Wildner /*
239*f933b737SSascha Wildner  * Netmap representation of an interface and its queue(s).
240*f933b737SSascha Wildner  * This is initialized by the kernel when binding a file
241*f933b737SSascha Wildner  * descriptor to a port, and should be considered as readonly
242*f933b737SSascha Wildner  * by user programs. The kernel never uses it.
243*f933b737SSascha Wildner  *
244*f933b737SSascha Wildner  * There is one netmap_if for each file descriptor on which we want
245*f933b737SSascha Wildner  * to select/poll.
246*f933b737SSascha Wildner  * select/poll operates on one or all pairs depending on the value of
247*f933b737SSascha Wildner  * nmr_queueid passed on the ioctl.
248*f933b737SSascha Wildner  */
249*f933b737SSascha Wildner struct netmap_if {
250*f933b737SSascha Wildner 	char		ni_name[IFNAMSIZ]; /* name of the interface. */
251*f933b737SSascha Wildner 	const uint32_t	ni_version;	/* API version, currently unused */
252*f933b737SSascha Wildner 	const uint32_t	ni_flags;	/* properties */
253*f933b737SSascha Wildner #define	NI_PRIV_MEM	0x1		/* private memory region */
254*f933b737SSascha Wildner 
255*f933b737SSascha Wildner 	const uint32_t	ni_rx_rings;	/* number of rx rings */
256*f933b737SSascha Wildner 	const uint32_t	ni_tx_rings;	/* number of tx rings */
257*f933b737SSascha Wildner 	/*
258*f933b737SSascha Wildner 	 * The following array contains the offset of each netmap ring
259*f933b737SSascha Wildner 	 * from this structure. The first ni_tx_rings+1 entries refer
260*f933b737SSascha Wildner 	 * to the tx rings, the next ni_rx_rings+1 refer to the rx rings
261*f933b737SSascha Wildner 	 * (the last entry in each block refers to the host stack rings).
262*f933b737SSascha Wildner 	 * The area is filled up by the kernel on NIOCREGIF,
263*f933b737SSascha Wildner 	 * and then only read by userspace code.
264*f933b737SSascha Wildner 	 */
265*f933b737SSascha Wildner 	const ssize_t	ring_ofs[0];
266*f933b737SSascha Wildner };
267*f933b737SSascha Wildner 
268*f933b737SSascha Wildner #ifndef NIOCREGIF
269*f933b737SSascha Wildner /*
270*f933b737SSascha Wildner  * ioctl names and related fields
271*f933b737SSascha Wildner  *
272*f933b737SSascha Wildner  * NIOCGINFO takes a struct ifreq, the interface name is the input,
273*f933b737SSascha Wildner  *	the outputs are number of queues and number of descriptor
274*f933b737SSascha Wildner  *	for each queue (useful to set number of threads etc.).
275*f933b737SSascha Wildner  *	The info returned is only advisory and may change before
276*f933b737SSascha Wildner  *	the interface is bound to a file descriptor.
277*f933b737SSascha Wildner  *
278*f933b737SSascha Wildner  * NIOCREGIF takes an interface name within a struct ifreq,
279*f933b737SSascha Wildner  *	and activates netmap mode on the interface (if possible).
280*f933b737SSascha Wildner  *
281*f933b737SSascha Wildner  *   nr_name	is the name of the interface
282*f933b737SSascha Wildner  *
283*f933b737SSascha Wildner  *   nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings
284*f933b737SSascha Wildner  *	indicate the configuration of the port on return.
285*f933b737SSascha Wildner  *
286*f933b737SSascha Wildner  *	On input, non-zero values for nr_tx_rings, nr_tx_slots and the
287*f933b737SSascha Wildner  *	rx counterparts may be used to reconfigure the port according
288*f933b737SSascha Wildner  *	to the requested values, but this is not guaranteed.
289*f933b737SSascha Wildner  *	The actual values are returned on completion of the ioctl().
290*f933b737SSascha Wildner  *
291*f933b737SSascha Wildner  *   nr_ringid
292*f933b737SSascha Wildner  *	indicates how rings should be bound to the file descriptors.
293*f933b737SSascha Wildner  *	The default (0) means all physical rings of a NIC are bound.
294*f933b737SSascha Wildner  *	NETMAP_HW_RING plus a ring number lets you bind just
295*f933b737SSascha Wildner  *	a single ring pair.
296*f933b737SSascha Wildner  *	NETMAP_SW_RING binds only the host tx/rx rings
297*f933b737SSascha Wildner  *	NETMAP_NO_TX_POLL prevents select()/poll() from pushing
298*f933b737SSascha Wildner  *	out packets on the tx ring unless POLLOUT is specified.
299*f933b737SSascha Wildner  *
300*f933b737SSascha Wildner  *	NETMAP_PRIV_MEM is a return value used to indicate that
301*f933b737SSascha Wildner  *	this ring is in a private memory region hence buffer
302*f933b737SSascha Wildner  *	swapping cannot be used
303*f933b737SSascha Wildner  *
304*f933b737SSascha Wildner  *   nr_cmd	is used to configure NICs attached to a VALE switch,
305*f933b737SSascha Wildner  *	or to dump the configuration of a VALE switch.
306*f933b737SSascha Wildner  *
307*f933b737SSascha Wildner  *	nr_cmd = NETMAP_BDG_ATTACH and nr_name = vale*:ifname
308*f933b737SSascha Wildner  *	attaches the NIC to the switch, with nr_ringid specifying
309*f933b737SSascha Wildner  *	which rings to use
310*f933b737SSascha Wildner  *
311*f933b737SSascha Wildner  *	nr_cmd = NETMAP_BDG_DETACH and nr_name = vale*:ifname
312*f933b737SSascha Wildner  *	disconnects a previously attached NIC
313*f933b737SSascha Wildner  *
314*f933b737SSascha Wildner  *	nr_cmd = NETMAP_BDG_LIST is used to list the configuration
315*f933b737SSascha Wildner  *	of VALE switches, with additional arguments.
316*f933b737SSascha Wildner  *
317*f933b737SSascha Wildner  * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
318*f933b737SSascha Wildner  *	whose identity is set in NIOCREGIF through nr_ringid
319*f933b737SSascha Wildner  *
320*f933b737SSascha Wildner  * NETMAP_API is the API version.
321*f933b737SSascha Wildner  */
322*f933b737SSascha Wildner 
323*f933b737SSascha Wildner /*
324*f933b737SSascha Wildner  * struct nmreq overlays a struct ifreq
325*f933b737SSascha Wildner  */
326*f933b737SSascha Wildner struct nmreq {
327*f933b737SSascha Wildner 	char		nr_name[IFNAMSIZ];
328*f933b737SSascha Wildner 	uint32_t	nr_version;	/* API version */
329*f933b737SSascha Wildner #define	NETMAP_API	5		/* current version */
330*f933b737SSascha Wildner 	uint32_t	nr_offset;	/* nifp offset in the shared region */
331*f933b737SSascha Wildner 	uint32_t	nr_memsize;	/* size of the shared region */
332*f933b737SSascha Wildner 	uint32_t	nr_tx_slots;	/* slots in tx rings */
333*f933b737SSascha Wildner 	uint32_t	nr_rx_slots;	/* slots in rx rings */
334*f933b737SSascha Wildner 	uint16_t	nr_tx_rings;	/* number of tx rings */
335*f933b737SSascha Wildner 	uint16_t	nr_rx_rings;	/* number of rx rings */
336*f933b737SSascha Wildner 	uint16_t	nr_ringid;	/* ring(s) we care about */
337*f933b737SSascha Wildner #define NETMAP_PRIV_MEM	0x8000		/* rings use private memory */
338*f933b737SSascha Wildner #define NETMAP_HW_RING	0x4000		/* low bits indicate one hw ring */
339*f933b737SSascha Wildner #define NETMAP_SW_RING	0x2000		/* process the sw ring */
340*f933b737SSascha Wildner #define NETMAP_NO_TX_POLL	0x1000	/* no automatic txsync on poll */
341*f933b737SSascha Wildner #define NETMAP_RING_MASK 0xfff		/* the ring number */
342*f933b737SSascha Wildner 	uint16_t	nr_cmd;
343*f933b737SSascha Wildner #define NETMAP_BDG_ATTACH	1	/* attach the NIC */
344*f933b737SSascha Wildner #define NETMAP_BDG_DETACH	2	/* detach the NIC */
345*f933b737SSascha Wildner #define NETMAP_BDG_LOOKUP_REG	3	/* register lookup function */
346*f933b737SSascha Wildner #define NETMAP_BDG_LIST		4	/* get bridge's info */
347*f933b737SSascha Wildner 	uint16_t	nr_arg1;
348*f933b737SSascha Wildner #define NETMAP_BDG_HOST		1	/* attach the host stack on ATTACH */
349*f933b737SSascha Wildner 	uint16_t	nr_arg2;
350*f933b737SSascha Wildner 	uint32_t	spare2[3];
351*f933b737SSascha Wildner };
352*f933b737SSascha Wildner 
353*f933b737SSascha Wildner /*
354*f933b737SSascha Wildner  * FreeBSD uses the size value embedded in the _IOWR to determine
355*f933b737SSascha Wildner  * how much to copy in/out. So we need it to match the actual
356*f933b737SSascha Wildner  * data structure we pass. We put some spares in the structure
357*f933b737SSascha Wildner  * to ease compatibility with other versions
358*f933b737SSascha Wildner  */
359*f933b737SSascha Wildner #define NIOCGINFO	_IOWR('i', 145, struct nmreq) /* return IF info */
360*f933b737SSascha Wildner #define NIOCREGIF	_IOWR('i', 146, struct nmreq) /* interface register */
361*f933b737SSascha Wildner #define NIOCUNREGIF	_IO('i', 147) /* deprecated. Was interface unregister */
362*f933b737SSascha Wildner #define NIOCTXSYNC	_IO('i', 148) /* sync tx queues */
363*f933b737SSascha Wildner #define NIOCRXSYNC	_IO('i', 149) /* sync rx queues */
364*f933b737SSascha Wildner #endif /* !NIOCREGIF */
365*f933b737SSascha Wildner 
366*f933b737SSascha Wildner #endif /* _NET_NETMAP_H_ */
367