xref: /freebsd/sys/net/netmap.h (revision f0cfa1b168014f56c02b83e5f28412cc5f78d117)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  *   1. Redistributions of source code must retain the above copyright
11  *      notice, this list of conditions and the following disclaimer.
12  *   2. Redistributions in binary form must reproduce the above copyright
13  *      notice, this list of conditions and the following disclaimer in the
14  *      documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 /*
30  * $FreeBSD$
31  *
32  * Definitions of constants and the structures used by the netmap
33  * framework, for the part visible to both kernel and userspace.
34  * Detailed info on netmap is available with "man netmap" or at
35  *
36  *	http://info.iet.unipi.it/~luigi/netmap/
37  *
38  * This API is also used to communicate with the VALE software switch
39  */
40 
41 #ifndef _NET_NETMAP_H_
42 #define _NET_NETMAP_H_
43 
44 #define	NETMAP_API	11		/* current API version */
45 
46 #define	NETMAP_MIN_API	11		/* min and max versions accepted */
47 #define	NETMAP_MAX_API	15
48 /*
49  * Some fields should be cache-aligned to reduce contention.
50  * The alignment is architecture and OS dependent, but rather than
51  * digging into OS headers to find the exact value we use an estimate
52  * that should cover most architectures.
53  */
54 #define NM_CACHE_ALIGN	128
55 
56 /*
57  * --- Netmap data structures ---
58  *
59  * The userspace data structures used by netmap are shown below.
60  * They are allocated by the kernel and mmap()ed by userspace threads.
61  * Pointers are implemented as memory offsets or indexes,
62  * so that they can be easily dereferenced in kernel and userspace.
63 
64    KERNEL (opaque, obviously)
65 
66   ====================================================================
67                                          |
68    USERSPACE                             |      struct netmap_ring
69                                          +---->+---------------+
70                                              / | head,cur,tail |
71    struct netmap_if (nifp, 1 per fd)        /  | buf_ofs       |
72     +---------------+                      /   | other fields  |
73     | ni_tx_rings   |                     /    +===============+
74     | ni_rx_rings   |                    /     | buf_idx, len  | slot[0]
75     |               |                   /      | flags, ptr    |
76     |               |                  /       +---------------+
77     +===============+                 /        | buf_idx, len  | slot[1]
78     | txring_ofs[0] | (rel.to nifp)--'         | flags, ptr    |
79     | txring_ofs[1] |                          +---------------+
80      (tx+1 entries)                           (num_slots entries)
81     | txring_ofs[t] |                          | buf_idx, len  | slot[n-1]
82     +---------------+                          | flags, ptr    |
83     | rxring_ofs[0] |                          +---------------+
84     | rxring_ofs[1] |
85      (rx+1 entries)
86     | rxring_ofs[r] |
87     +---------------+
88 
89  * For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to
90  * a file descriptor, the mmap()ed region contains a (logically readonly)
91  * struct netmap_if pointing to struct netmap_ring's.
92  *
93  * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
94  * pair attached to the host stack (this pair is unused for non-NIC ports).
95  *
96  * All physical/host stack ports share the same memory region,
97  * so that zero-copy can be implemented between them.
98  * VALE switch ports instead have separate memory regions.
99  *
100  * The netmap_ring is the userspace-visible replica of the NIC ring.
101  * Each slot has the index of a buffer (MTU-sized and residing in the
102  * mmapped region), its length and some flags. An extra 64-bit pointer
103  * is provided for user-supplied buffers in the tx path.
104  *
105  * In user space, the buffer address is computed as
106  *	(char *)ring + buf_ofs + index * NETMAP_BUF_SIZE
107  *
108  * Added in NETMAP_API 11:
109  *
110  * + NIOCREGIF can request the allocation of extra spare buffers from
111  *   the same memory pool. The desired number of buffers must be in
112  *   nr_arg3. The ioctl may return fewer buffers, depending on memory
113  *   availability. nr_arg3 will return the actual value, and, once
114  *   mapped, nifp->ni_bufs_head will be the index of the first buffer.
115  *
116  *   The buffers are linked to each other using the first uint32_t
117  *   as the index. On close, ni_bufs_head must point to the list of
118  *   buffers to be released.
119  *
120  * + NIOCREGIF can request space for extra rings (and buffers)
121  *   allocated in the same memory space. The number of extra rings
122  *   is in nr_arg1, and is advisory. This is a no-op on NICs where
123  *   the size of the memory space is fixed.
124  *
125  * + NIOCREGIF can attach to PIPE rings sharing the same memory
126  *   space with a parent device. The ifname indicates the parent device,
127  *   which must already exist. Flags in nr_flags indicate if we want to
128  *   bind the master or slave side, the index (from nr_ringid)
129  *   is just a cookie and does not need to be sequential.
130  *
131  * + NIOCREGIF can also attach to 'monitor' rings that replicate
132  *   the content of specific rings, also from the same memory space.
133  *
134  *   Extra flags in nr_flags support the above functions.
135  *   Application libraries may use the following naming scheme:
136  *	netmap:foo			all NIC ring pairs
137  *	netmap:foo^			only host ring pair
138  *	netmap:foo+			all NIC ring + host ring pairs
139  *	netmap:foo-k			the k-th NIC ring pair
140  *	netmap:foo{k			PIPE ring pair k, master side
141  *	netmap:foo}k			PIPE ring pair k, slave side
142  *
143  * Some notes about host rings:
144  *
145  * + The RX host ring is used to store those packets that the host network
146  *   stack is trying to transmit through a NIC queue, but only if that queue
147  *   is currently in netmap mode. Netmap will not intercept host stack mbufs
148  *   designated to NIC queues that are not in netmap mode. As a consequence,
149  *   registering a netmap port with netmap:foo^ is not enough to intercept
150  *   mbufs in the RX host ring; the netmap port should be registered with
151  *   netmap:foo*, or another registration should be done to open at least a
152  *   NIC TX queue in netmap mode.
153  *
154  * + Netmap is not currently able to deal with intercepted trasmit mbufs which
155  *   require offloadings like TSO, UFO, checksumming offloadings, etc. It is
156  *   responsibility of the user to disable those offloadings (e.g. using
157  *   ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being
158  *   used in netmap mode. If the offloadings are not disabled, GSO and/or
159  *   unchecksummed packets may be dropped immediately or end up in the host RX
160  *   ring, and will be dropped as soon as the packet reaches another netmap
161  *   adapter.
162  */
163 
164 /*
165  * struct netmap_slot is a buffer descriptor
166  */
167 struct netmap_slot {
168 	uint32_t buf_idx;	/* buffer index */
169 	uint16_t len;		/* length for this slot */
170 	uint16_t flags;		/* buf changed, etc. */
171 	uint64_t ptr;		/* pointer for indirect buffers */
172 };
173 
174 /*
175  * The following flags control how the slot is used
176  */
177 
178 #define	NS_BUF_CHANGED	0x0001	/* buf_idx changed */
179 	/*
180 	 * must be set whenever buf_idx is changed (as it might be
181 	 * necessary to recompute the physical address and mapping)
182 	 *
183 	 * It is also set by the kernel whenever the buf_idx is
184 	 * changed internally (e.g., by pipes). Applications may
185 	 * use this information to know when they can reuse the
186 	 * contents of previously prepared buffers.
187 	 */
188 
189 #define	NS_REPORT	0x0002	/* ask the hardware to report results */
190 	/*
191 	 * Request notification when slot is used by the hardware.
192 	 * Normally transmit completions are handled lazily and
193 	 * may be unreported. This flag lets us know when a slot
194 	 * has been sent (e.g. to terminate the sender).
195 	 */
196 
197 #define	NS_FORWARD	0x0004	/* pass packet 'forward' */
198 	/*
199 	 * (Only for physical ports, rx rings with NR_FORWARD set).
200 	 * Slot released to the kernel (i.e. before ring->head) with
201 	 * this flag set are passed to the peer ring (host/NIC),
202 	 * thus restoring the host-NIC connection for these slots.
203 	 * This supports efficient traffic monitoring or firewalling.
204 	 */
205 
206 #define	NS_NO_LEARN	0x0008	/* disable bridge learning */
207  	/*
208 	 * On a VALE switch, do not 'learn' the source port for
209  	 * this buffer.
210 	 */
211 
212 #define	NS_INDIRECT	0x0010	/* userspace buffer */
213  	/*
214 	 * (VALE tx rings only) data is in a userspace buffer,
215 	 * whose address is in the 'ptr' field in the slot.
216 	 */
217 
218 #define	NS_MOREFRAG	0x0020	/* packet has more fragments */
219  	/*
220 	 * (VALE ports only)
221 	 * Set on all but the last slot of a multi-segment packet.
222 	 * The 'len' field refers to the individual fragment.
223 	 */
224 
225 #define	NS_PORT_SHIFT	8
226 #define	NS_PORT_MASK	(0xff << NS_PORT_SHIFT)
227 	/*
228  	 * The high 8 bits of the flag, if not zero, indicate the
229 	 * destination port for the VALE switch, overriding
230  	 * the lookup table.
231  	 */
232 
233 #define	NS_RFRAGS(_slot)	( ((_slot)->flags >> 8) & 0xff)
234 	/*
235 	 * (VALE rx rings only) the high 8 bits
236 	 *  are the number of fragments.
237 	 */
238 
239 
240 /*
241  * struct netmap_ring
242  *
243  * Netmap representation of a TX or RX ring (also known as "queue").
244  * This is a queue implemented as a fixed-size circular array.
245  * At the software level the important fields are: head, cur, tail.
246  *
247  * In TX rings:
248  *
249  *	head	first slot available for transmission.
250  *	cur	wakeup point. select() and poll() will unblock
251  *		when 'tail' moves past 'cur'
252  *	tail	(readonly) first slot reserved to the kernel
253  *
254  *	[head .. tail-1] can be used for new packets to send;
255  *	'head' and 'cur' must be incremented as slots are filled
256  *	    with new packets to be sent;
257  *	'cur' can be moved further ahead if we need more space
258  *	for new transmissions. XXX todo (2014-03-12)
259  *
260  * In RX rings:
261  *
262  *	head	first valid received packet
263  *	cur	wakeup point. select() and poll() will unblock
264  *		when 'tail' moves past 'cur'
265  *	tail	(readonly) first slot reserved to the kernel
266  *
267  *	[head .. tail-1] contain received packets;
268  *	'head' and 'cur' must be incremented as slots are consumed
269  *		and can be returned to the kernel;
270  *	'cur' can be moved further ahead if we want to wait for
271  *		new packets without returning the previous ones.
272  *
273  * DATA OWNERSHIP/LOCKING:
274  *	The netmap_ring, and all slots and buffers in the range
275  *	[head .. tail-1] are owned by the user program;
276  *	the kernel only accesses them during a netmap system call
277  *	and in the user thread context.
278  *
279  *	Other slots and buffers are reserved for use by the kernel
280  */
281 struct netmap_ring {
282 	/*
283 	 * buf_ofs is meant to be used through macros.
284 	 * It contains the offset of the buffer region from this
285 	 * descriptor.
286 	 */
287 	const int64_t	buf_ofs;
288 	const uint32_t	num_slots;	/* number of slots in the ring. */
289 	const uint32_t	nr_buf_size;
290 	const uint16_t	ringid;
291 	const uint16_t	dir;		/* 0: tx, 1: rx */
292 
293 	uint32_t        head;		/* (u) first user slot */
294 	uint32_t        cur;		/* (u) wakeup point */
295 	uint32_t	tail;		/* (k) first kernel slot */
296 
297 	uint32_t	flags;
298 
299 	struct timeval	ts;		/* (k) time of last *sync() */
300 
301 	/* opaque room for a mutex or similar object */
302 #if !defined(_WIN32) || defined(__CYGWIN__)
303 	uint8_t	__attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128];
304 #else
305 	uint8_t	__declspec(align(NM_CACHE_ALIGN)) sem[128];
306 #endif
307 
308 	/* the slots follow. This struct has variable size */
309 	struct netmap_slot slot[0];	/* array of slots. */
310 };
311 
312 
313 /*
314  * RING FLAGS
315  */
316 #define	NR_TIMESTAMP	0x0002		/* set timestamp on *sync() */
317 	/*
318 	 * updates the 'ts' field on each netmap syscall. This saves
319 	 * saves a separate gettimeofday(), and is not much worse than
320 	 * software timestamps generated in the interrupt handler.
321 	 */
322 
323 #define	NR_FORWARD	0x0004		/* enable NS_FORWARD for ring */
324  	/*
325 	 * Enables the NS_FORWARD slot flag for the ring.
326 	 */
327 
328 
329 /*
330  * Netmap representation of an interface and its queue(s).
331  * This is initialized by the kernel when binding a file
332  * descriptor to a port, and should be considered as readonly
333  * by user programs. The kernel never uses it.
334  *
335  * There is one netmap_if for each file descriptor on which we want
336  * to select/poll.
337  * select/poll operates on one or all pairs depending on the value of
338  * nmr_queueid passed on the ioctl.
339  */
340 struct netmap_if {
341 	char		ni_name[IFNAMSIZ]; /* name of the interface. */
342 	const uint32_t	ni_version;	/* API version, currently unused */
343 	const uint32_t	ni_flags;	/* properties */
344 #define	NI_PRIV_MEM	0x1		/* private memory region */
345 
346 	/*
347 	 * The number of packet rings available in netmap mode.
348 	 * Physical NICs can have different numbers of tx and rx rings.
349 	 * Physical NICs also have a 'host' ring pair.
350 	 * Additionally, clients can request additional ring pairs to
351 	 * be used for internal communication.
352 	 */
353 	const uint32_t	ni_tx_rings;	/* number of HW tx rings */
354 	const uint32_t	ni_rx_rings;	/* number of HW rx rings */
355 
356 	uint32_t	ni_bufs_head;	/* head index for extra bufs */
357 	uint32_t	ni_spare1[5];
358 	/*
359 	 * The following array contains the offset of each netmap ring
360 	 * from this structure, in the following order:
361 	 * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings;
362 	 * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings.
363 	 *
364 	 * The area is filled up by the kernel on NIOCREGIF,
365 	 * and then only read by userspace code.
366 	 */
367 	const ssize_t	ring_ofs[0];
368 };
369 
370 
371 #ifndef NIOCREGIF
372 /*
373  * ioctl names and related fields
374  *
375  * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
376  *	whose identity is set in NIOCREGIF through nr_ringid.
377  *	These are non blocking and take no argument.
378  *
379  * NIOCGINFO takes a struct ifreq, the interface name is the input,
380  *	the outputs are number of queues and number of descriptor
381  *	for each queue (useful to set number of threads etc.).
382  *	The info returned is only advisory and may change before
383  *	the interface is bound to a file descriptor.
384  *
385  * NIOCREGIF takes an interface name within a struct nmre,
386  *	and activates netmap mode on the interface (if possible).
387  *
388  * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we
389  * can pass it down to other NIC-related ioctls.
390  *
391  * The actual argument (struct nmreq) has a number of options to request
392  * different functions.
393  * The following are used in NIOCREGIF when nr_cmd == 0:
394  *
395  * nr_name	(in)
396  *	The name of the port (em0, valeXXX:YYY, etc.)
397  *	limited to IFNAMSIZ for backward compatibility.
398  *
399  * nr_version	(in/out)
400  *	Must match NETMAP_API as used in the kernel, error otherwise.
401  *	Always returns the desired value on output.
402  *
403  * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out)
404  *	On input, non-zero values may be used to reconfigure the port
405  *	according to the requested values, but this is not guaranteed.
406  *	On output the actual values in use are reported.
407  *
408  * nr_ringid (in)
409  *	Indicates how rings should be bound to the file descriptors.
410  *	If nr_flags != 0, then the low bits (in NETMAP_RING_MASK)
411  *	are used to indicate the ring number, and nr_flags specifies
412  *	the actual rings to bind. NETMAP_NO_TX_POLL is unaffected.
413  *
414  *	NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED:
415  *	If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control
416  *	the binding as follows:
417  *	0 (default)			binds all physical rings
418  *	NETMAP_HW_RING | ring number	binds a single ring pair
419  *	NETMAP_SW_RING			binds only the host tx/rx rings
420  *
421  *	NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push
422  *		packets on tx rings only if POLLOUT is set.
423  *		The default is to push any pending packet.
424  *
425  *	NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release
426  *		packets on rx rings also when POLLIN is NOT set.
427  *		The default is to touch the rx ring only with POLLIN.
428  *		Note that this is the opposite of TX because it
429  *		reflects the common usage.
430  *
431  *	NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead.
432  *	NETMAP_PRIV_MEM is set on return for ports that do not use
433  *		the global memory allocator.
434  *		This information is not significant and applications
435  *		should look at the region id in nr_arg2
436  *
437  * nr_flags	is the recommended mode to indicate which rings should
438  *		be bound to a file descriptor. Values are NR_REG_*
439  *
440  * nr_arg1 (in)	The number of extra rings to be reserved.
441  *		Especially when allocating a VALE port the system only
442  *		allocates the amount of memory needed for the port.
443  *		If more shared memory rings are desired (e.g. for pipes),
444  *		the first invocation for the same basename/allocator
445  *		should specify a suitable number. Memory cannot be
446  *		extended after the first allocation without closing
447  *		all ports on the same region.
448  *
449  * nr_arg2 (in/out) The identity of the memory region used.
450  *		On input, 0 means the system decides autonomously,
451  *		other values may try to select a specific region.
452  *		On return the actual value is reported.
453  *		Region '1' is the global allocator, normally shared
454  *		by all interfaces. Other values are private regions.
455  *		If two ports the same region zero-copy is possible.
456  *
457  * nr_arg3 (in/out)	number of extra buffers to be allocated.
458  *
459  *
460  *
461  * nr_cmd (in)	if non-zero indicates a special command:
462  *	NETMAP_BDG_ATTACH	 and nr_name = vale*:ifname
463  *		attaches the NIC to the switch; nr_ringid specifies
464  *		which rings to use. Used by vale-ctl -a ...
465  *	    nr_arg1 = NETMAP_BDG_HOST also attaches the host port
466  *		as in vale-ctl -h ...
467  *
468  *	NETMAP_BDG_DETACH	and nr_name = vale*:ifname
469  *		disconnects a previously attached NIC.
470  *		Used by vale-ctl -d ...
471  *
472  *	NETMAP_BDG_LIST
473  *		list the configuration of VALE switches.
474  *
475  *	NETMAP_BDG_VNET_HDR
476  *		Set the virtio-net header length used by the client
477  *		of a VALE switch port.
478  *
479  *	NETMAP_BDG_NEWIF
480  *		create a persistent VALE port with name nr_name.
481  *		Used by vale-ctl -n ...
482  *
483  *	NETMAP_BDG_DELIF
484  *		delete a persistent VALE port. Used by vale-ctl -d ...
485  *
486  * nr_arg1, nr_arg2, nr_arg3  (in/out)		command specific
487  *
488  *
489  *
490  */
491 
492 
493 /*
494  * struct nmreq overlays a struct ifreq (just the name)
495  */
496 struct nmreq {
497 	char		nr_name[IFNAMSIZ];
498 	uint32_t	nr_version;	/* API version */
499 	uint32_t	nr_offset;	/* nifp offset in the shared region */
500 	uint32_t	nr_memsize;	/* size of the shared region */
501 	uint32_t	nr_tx_slots;	/* slots in tx rings */
502 	uint32_t	nr_rx_slots;	/* slots in rx rings */
503 	uint16_t	nr_tx_rings;	/* number of tx rings */
504 	uint16_t	nr_rx_rings;	/* number of rx rings */
505 
506 	uint16_t	nr_ringid;	/* ring(s) we care about */
507 #define NETMAP_HW_RING		0x4000	/* single NIC ring pair */
508 #define NETMAP_SW_RING		0x2000	/* only host ring pair */
509 
510 #define NETMAP_RING_MASK	0x0fff	/* the ring number */
511 
512 #define NETMAP_NO_TX_POLL	0x1000	/* no automatic txsync on poll */
513 
514 #define NETMAP_DO_RX_POLL	0x8000	/* DO automatic rxsync on poll */
515 
516 	uint16_t	nr_cmd;
517 #define NETMAP_BDG_ATTACH	1	/* attach the NIC */
518 #define NETMAP_BDG_DETACH	2	/* detach the NIC */
519 #define NETMAP_BDG_REGOPS	3	/* register bridge callbacks */
520 #define NETMAP_BDG_LIST		4	/* get bridge's info */
521 #define NETMAP_BDG_VNET_HDR     5       /* set the port virtio-net-hdr length */
522 #define NETMAP_BDG_OFFSET	NETMAP_BDG_VNET_HDR	/* deprecated alias */
523 #define NETMAP_BDG_NEWIF	6	/* create a virtual port */
524 #define NETMAP_BDG_DELIF	7	/* destroy a virtual port */
525 #define NETMAP_PT_HOST_CREATE	8	/* create ptnetmap kthreads */
526 #define NETMAP_PT_HOST_DELETE	9	/* delete ptnetmap kthreads */
527 #define NETMAP_BDG_POLLING_ON	10	/* delete polling kthread */
528 #define NETMAP_BDG_POLLING_OFF	11	/* delete polling kthread */
529 #define NETMAP_VNET_HDR_GET	12      /* get the port virtio-net-hdr length */
530 #define NETMAP_POOLS_INFO_GET	13	/* get memory allocator pools info */
531 	uint16_t	nr_arg1;	/* reserve extra rings in NIOCREGIF */
532 #define NETMAP_BDG_HOST		1	/* attach the host stack on ATTACH */
533 
534 	uint16_t	nr_arg2;
535 	uint32_t	nr_arg3;	/* req. extra buffers in NIOCREGIF */
536 	uint32_t	nr_flags;
537 	/* various modes, extends nr_ringid */
538 	uint32_t	spare2[1];
539 };
540 
541 #define NR_REG_MASK		0xf /* values for nr_flags */
542 enum {	NR_REG_DEFAULT	= 0,	/* backward compat, should not be used. */
543 	NR_REG_ALL_NIC	= 1,
544 	NR_REG_SW	= 2,
545 	NR_REG_NIC_SW	= 3,
546 	NR_REG_ONE_NIC	= 4,
547 	NR_REG_PIPE_MASTER = 5,
548 	NR_REG_PIPE_SLAVE = 6,
549 };
550 /* monitor uses the NR_REG to select the rings to monitor */
551 #define NR_MONITOR_TX	0x100
552 #define NR_MONITOR_RX	0x200
553 #define NR_ZCOPY_MON	0x400
554 /* request exclusive access to the selected rings */
555 #define NR_EXCLUSIVE	0x800
556 /* request ptnetmap host support */
557 #define NR_PASSTHROUGH_HOST	NR_PTNETMAP_HOST /* deprecated */
558 #define NR_PTNETMAP_HOST	0x1000
559 #define NR_RX_RINGS_ONLY	0x2000
560 #define NR_TX_RINGS_ONLY	0x4000
561 /* Applications set this flag if they are able to deal with virtio-net headers,
562  * that is send/receive frames that start with a virtio-net header.
563  * If not set, NIOCREGIF will fail with netmap ports that require applications
564  * to use those headers. If the flag is set, the application can use the
565  * NETMAP_VNET_HDR_GET command to figure out the header length. */
566 #define NR_ACCEPT_VNET_HDR	0x8000
567 
568 #define	NM_BDG_NAME		"vale"	/* prefix for bridge port name */
569 
570 /*
571  * Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined
572  * in ws2def.h but not sure if they are in the form we need.
573  * XXX so we redefine them
574  * in a convenient way to use for DeviceIoControl signatures
575  */
576 #ifdef _WIN32
577 #undef _IO	// ws2def.h
578 #define _WIN_NM_IOCTL_TYPE 40000
579 #define _IO(_c, _n)	CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
580 		METHOD_BUFFERED, FILE_ANY_ACCESS  )
581 #define _IO_direct(_c, _n)	CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
582 		METHOD_OUT_DIRECT, FILE_ANY_ACCESS  )
583 
584 #define _IOWR(_c, _n, _s)	_IO(_c, _n)
585 
586 /* We havesome internal sysctl in addition to the externally visible ones */
587 #define NETMAP_MMAP _IO_direct('i', 160)	// note METHOD_OUT_DIRECT
588 #define NETMAP_POLL _IO('i', 162)
589 
590 /* and also two setsockopt for sysctl emulation */
591 #define NETMAP_SETSOCKOPT _IO('i', 140)
592 #define NETMAP_GETSOCKOPT _IO('i', 141)
593 
594 
595 //These linknames are for the Netmap Core Driver
596 #define NETMAP_NT_DEVICE_NAME			L"\\Device\\NETMAP"
597 #define NETMAP_DOS_DEVICE_NAME			L"\\DosDevices\\netmap"
598 
599 //Definition of a structure used to pass a virtual address within an IOCTL
600 typedef struct _MEMORY_ENTRY {
601 	PVOID       pUsermodeVirtualAddress;
602 } MEMORY_ENTRY, *PMEMORY_ENTRY;
603 
604 typedef struct _POLL_REQUEST_DATA {
605 	int events;
606 	int timeout;
607 	int revents;
608 } POLL_REQUEST_DATA;
609 
610 #endif /* _WIN32 */
611 
612 /*
613  * FreeBSD uses the size value embedded in the _IOWR to determine
614  * how much to copy in/out. So we need it to match the actual
615  * data structure we pass. We put some spares in the structure
616  * to ease compatibility with other versions
617  */
618 #define NIOCGINFO	_IOWR('i', 145, struct nmreq) /* return IF info */
619 #define NIOCREGIF	_IOWR('i', 146, struct nmreq) /* interface register */
620 #define NIOCTXSYNC	_IO('i', 148) /* sync tx queues */
621 #define NIOCRXSYNC	_IO('i', 149) /* sync rx queues */
622 #define NIOCCONFIG	_IOWR('i',150, struct nm_ifreq) /* for ext. modules */
623 #endif /* !NIOCREGIF */
624 
625 
626 /*
627  * Helper functions for kernel and userspace
628  */
629 
630 /*
631  * check if space is available in the ring.
632  */
633 static inline int
634 nm_ring_empty(struct netmap_ring *ring)
635 {
636 	return (ring->cur == ring->tail);
637 }
638 
639 /*
640  * Opaque structure that is passed to an external kernel
641  * module via ioctl(fd, NIOCCONFIG, req) for a user-owned
642  * bridge port (at this point ephemeral VALE interface).
643  */
644 #define NM_IFRDATA_LEN 256
645 struct nm_ifreq {
646 	char nifr_name[IFNAMSIZ];
647 	char data[NM_IFRDATA_LEN];
648 };
649 
650 #endif /* _NET_NETMAP_H_ */
651