xref: /freebsd/sys/net/netmap.h (revision fe267a559009cbf34f9341666fe4d88a92c02d5e)
1*fe267a55SPedro F. Giffuni /*-
2*fe267a55SPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*fe267a55SPedro F. Giffuni  *
417885a7bSLuigi Rizzo  * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
568b8534bSLuigi Rizzo  *
668b8534bSLuigi Rizzo  * Redistribution and use in source and binary forms, with or without
7f9790aebSLuigi Rizzo  * modification, are permitted provided that the following conditions
8f9790aebSLuigi Rizzo  * are met:
968b8534bSLuigi Rizzo  *
1068b8534bSLuigi Rizzo  *   1. Redistributions of source code must retain the above copyright
1168b8534bSLuigi Rizzo  *      notice, this list of conditions and the following disclaimer.
1268b8534bSLuigi Rizzo  *   2. Redistributions in binary form must reproduce the above copyright
1368b8534bSLuigi Rizzo  *      notice, this list of conditions and the following disclaimer in the
14f9790aebSLuigi Rizzo  *      documentation and/or other materials provided with the distribution.
1568b8534bSLuigi Rizzo  *
16f9790aebSLuigi Rizzo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND
1768b8534bSLuigi Rizzo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f9790aebSLuigi Rizzo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f9790aebSLuigi Rizzo  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20f9790aebSLuigi Rizzo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f9790aebSLuigi Rizzo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f9790aebSLuigi Rizzo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f9790aebSLuigi Rizzo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f9790aebSLuigi Rizzo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f9790aebSLuigi Rizzo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f9790aebSLuigi Rizzo  * SUCH DAMAGE.
2768b8534bSLuigi Rizzo  */
2868b8534bSLuigi Rizzo 
2968b8534bSLuigi Rizzo /*
3068b8534bSLuigi Rizzo  * $FreeBSD$
3168b8534bSLuigi Rizzo  *
3264ae02c3SLuigi Rizzo  * Definitions of constants and the structures used by the netmap
3364ae02c3SLuigi Rizzo  * framework, for the part visible to both kernel and userspace.
3464ae02c3SLuigi Rizzo  * Detailed info on netmap is available with "man netmap" or at
3564ae02c3SLuigi Rizzo  *
3664ae02c3SLuigi Rizzo  *	http://info.iet.unipi.it/~luigi/netmap/
37ce3ee1e7SLuigi Rizzo  *
38ce3ee1e7SLuigi Rizzo  * This API is also used to communicate with the VALE software switch
3968b8534bSLuigi Rizzo  */
4068b8534bSLuigi Rizzo 
4168b8534bSLuigi Rizzo #ifndef _NET_NETMAP_H_
4268b8534bSLuigi Rizzo #define _NET_NETMAP_H_
4368b8534bSLuigi Rizzo 
44f0ea3689SLuigi Rizzo #define	NETMAP_API	11		/* current API version */
4517885a7bSLuigi Rizzo 
46f0ea3689SLuigi Rizzo #define	NETMAP_MIN_API	11		/* min and max versions accepted */
47f0ea3689SLuigi Rizzo #define	NETMAP_MAX_API	15
4817885a7bSLuigi Rizzo /*
4917885a7bSLuigi Rizzo  * Some fields should be cache-aligned to reduce contention.
5017885a7bSLuigi Rizzo  * The alignment is architecture and OS dependent, but rather than
5117885a7bSLuigi Rizzo  * digging into OS headers to find the exact value we use an estimate
5217885a7bSLuigi Rizzo  * that should cover most architectures.
5317885a7bSLuigi Rizzo  */
5417885a7bSLuigi Rizzo #define NM_CACHE_ALIGN	128
5517885a7bSLuigi Rizzo 
5668b8534bSLuigi Rizzo /*
5768b8534bSLuigi Rizzo  * --- Netmap data structures ---
5868b8534bSLuigi Rizzo  *
59ce3ee1e7SLuigi Rizzo  * The userspace data structures used by netmap are shown below.
60ce3ee1e7SLuigi Rizzo  * They are allocated by the kernel and mmap()ed by userspace threads.
61ce3ee1e7SLuigi Rizzo  * Pointers are implemented as memory offsets or indexes,
62ce3ee1e7SLuigi Rizzo  * so that they can be easily dereferenced in kernel and userspace.
6368b8534bSLuigi Rizzo 
64ce3ee1e7SLuigi Rizzo    KERNEL (opaque, obviously)
6568b8534bSLuigi Rizzo 
6664ae02c3SLuigi Rizzo   ====================================================================
6764ae02c3SLuigi Rizzo                                          |
68ce3ee1e7SLuigi Rizzo    USERSPACE                             |      struct netmap_ring
6917885a7bSLuigi Rizzo                                          +---->+---------------+
7017885a7bSLuigi Rizzo                                              / | head,cur,tail |
7117885a7bSLuigi Rizzo    struct netmap_if (nifp, 1 per fd)        /  | buf_ofs       |
7217885a7bSLuigi Rizzo     +---------------+                      /   | other fields  |
7317885a7bSLuigi Rizzo     | ni_tx_rings   |                     /    +===============+
74ce3ee1e7SLuigi Rizzo     | ni_rx_rings   |                    /     | buf_idx, len  | slot[0]
75ce3ee1e7SLuigi Rizzo     |               |                   /      | flags, ptr    |
7617885a7bSLuigi Rizzo     |               |                  /       +---------------+
77ce3ee1e7SLuigi Rizzo     +===============+                 /        | buf_idx, len  | slot[1]
78ce3ee1e7SLuigi Rizzo     | txring_ofs[0] | (rel.to nifp)--'         | flags, ptr    |
7917885a7bSLuigi Rizzo     | txring_ofs[1] |                          +---------------+
80f0ea3689SLuigi Rizzo      (tx+1 entries)                           (num_slots entries)
81ce3ee1e7SLuigi Rizzo     | txring_ofs[t] |                          | buf_idx, len  | slot[n-1]
82ce3ee1e7SLuigi Rizzo     +---------------+                          | flags, ptr    |
8317885a7bSLuigi Rizzo     | rxring_ofs[0] |                          +---------------+
8468b8534bSLuigi Rizzo     | rxring_ofs[1] |
85f0ea3689SLuigi Rizzo      (rx+1 entries)
86ce3ee1e7SLuigi Rizzo     | rxring_ofs[r] |
8768b8534bSLuigi Rizzo     +---------------+
8868b8534bSLuigi Rizzo 
89f0ea3689SLuigi Rizzo  * For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to
90f0ea3689SLuigi Rizzo  * a file descriptor, the mmap()ed region contains a (logically readonly)
91ce3ee1e7SLuigi Rizzo  * struct netmap_if pointing to struct netmap_ring's.
92f0ea3689SLuigi Rizzo  *
93ce3ee1e7SLuigi Rizzo  * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
94f0ea3689SLuigi Rizzo  * pair attached to the host stack (this pair is unused for non-NIC ports).
95ce3ee1e7SLuigi Rizzo  *
96ce3ee1e7SLuigi Rizzo  * All physical/host stack ports share the same memory region,
97ce3ee1e7SLuigi Rizzo  * so that zero-copy can be implemented between them.
98ce3ee1e7SLuigi Rizzo  * VALE switch ports instead have separate memory regions.
99ce3ee1e7SLuigi Rizzo  *
100ce3ee1e7SLuigi Rizzo  * The netmap_ring is the userspace-visible replica of the NIC ring.
101ce3ee1e7SLuigi Rizzo  * Each slot has the index of a buffer (MTU-sized and residing in the
102ce3ee1e7SLuigi Rizzo  * mmapped region), its length and some flags. An extra 64-bit pointer
103ce3ee1e7SLuigi Rizzo  * is provided for user-supplied buffers in the tx path.
104ce3ee1e7SLuigi Rizzo  *
10568b8534bSLuigi Rizzo  * In user space, the buffer address is computed as
10664ae02c3SLuigi Rizzo  *	(char *)ring + buf_ofs + index * NETMAP_BUF_SIZE
107f0ea3689SLuigi Rizzo  *
108f0ea3689SLuigi Rizzo  * Added in NETMAP_API 11:
109f0ea3689SLuigi Rizzo  *
110f0ea3689SLuigi Rizzo  * + NIOCREGIF can request the allocation of extra spare buffers from
111f0ea3689SLuigi Rizzo  *   the same memory pool. The desired number of buffers must be in
112f0ea3689SLuigi Rizzo  *   nr_arg3. The ioctl may return fewer buffers, depending on memory
113f0ea3689SLuigi Rizzo  *   availability. nr_arg3 will return the actual value, and, once
114f0ea3689SLuigi Rizzo  *   mapped, nifp->ni_bufs_head will be the index of the first buffer.
115f0ea3689SLuigi Rizzo  *
116f0ea3689SLuigi Rizzo  *   The buffers are linked to each other using the first uint32_t
117f0ea3689SLuigi Rizzo  *   as the index. On close, ni_bufs_head must point to the list of
118f0ea3689SLuigi Rizzo  *   buffers to be released.
119f0ea3689SLuigi Rizzo  *
120f0ea3689SLuigi Rizzo  * + NIOCREGIF can request space for extra rings (and buffers)
121f0ea3689SLuigi Rizzo  *   allocated in the same memory space. The number of extra rings
122f0ea3689SLuigi Rizzo  *   is in nr_arg1, and is advisory. This is a no-op on NICs where
123f0ea3689SLuigi Rizzo  *   the size of the memory space is fixed.
124f0ea3689SLuigi Rizzo  *
125f0ea3689SLuigi Rizzo  * + NIOCREGIF can attach to PIPE rings sharing the same memory
126f0ea3689SLuigi Rizzo  *   space with a parent device. The ifname indicates the parent device,
127f0ea3689SLuigi Rizzo  *   which must already exist. Flags in nr_flags indicate if we want to
128f0ea3689SLuigi Rizzo  *   bind the master or slave side, the index (from nr_ringid)
1295c8c1004SLuigi Rizzo  *   is just a cookie and does not need to be sequential.
130f0ea3689SLuigi Rizzo  *
131f0ea3689SLuigi Rizzo  * + NIOCREGIF can also attach to 'monitor' rings that replicate
132f0ea3689SLuigi Rizzo  *   the content of specific rings, also from the same memory space.
133f0ea3689SLuigi Rizzo  *
134f0ea3689SLuigi Rizzo  *   Extra flags in nr_flags support the above functions.
135f0ea3689SLuigi Rizzo  *   Application libraries may use the following naming scheme:
136f0ea3689SLuigi Rizzo  *	netmap:foo			all NIC ring pairs
137f0ea3689SLuigi Rizzo  *	netmap:foo^			only host ring pair
138f0ea3689SLuigi Rizzo  *	netmap:foo+			all NIC ring + host ring pairs
139f0ea3689SLuigi Rizzo  *	netmap:foo-k			the k-th NIC ring pair
140f0ea3689SLuigi Rizzo  *	netmap:foo{k			PIPE ring pair k, master side
141f0ea3689SLuigi Rizzo  *	netmap:foo}k			PIPE ring pair k, slave side
14237e3a6d3SLuigi Rizzo  *
14337e3a6d3SLuigi Rizzo  * Some notes about host rings:
14437e3a6d3SLuigi Rizzo  *
14537e3a6d3SLuigi Rizzo  * + The RX host ring is used to store those packets that the host network
14637e3a6d3SLuigi Rizzo  *   stack is trying to transmit through a NIC queue, but only if that queue
14737e3a6d3SLuigi Rizzo  *   is currently in netmap mode. Netmap will not intercept host stack mbufs
14837e3a6d3SLuigi Rizzo  *   designated to NIC queues that are not in netmap mode. As a consequence,
14937e3a6d3SLuigi Rizzo  *   registering a netmap port with netmap:foo^ is not enough to intercept
15037e3a6d3SLuigi Rizzo  *   mbufs in the RX host ring; the netmap port should be registered with
15137e3a6d3SLuigi Rizzo  *   netmap:foo*, or another registration should be done to open at least a
15237e3a6d3SLuigi Rizzo  *   NIC TX queue in netmap mode.
15337e3a6d3SLuigi Rizzo  *
15437e3a6d3SLuigi Rizzo  * + Netmap is not currently able to deal with intercepted trasmit mbufs which
15537e3a6d3SLuigi Rizzo  *   require offloadings like TSO, UFO, checksumming offloadings, etc. It is
15637e3a6d3SLuigi Rizzo  *   responsibility of the user to disable those offloadings (e.g. using
15737e3a6d3SLuigi Rizzo  *   ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being
15837e3a6d3SLuigi Rizzo  *   used in netmap mode. If the offloadings are not disabled, GSO and/or
15937e3a6d3SLuigi Rizzo  *   unchecksummed packets may be dropped immediately or end up in the host RX
16037e3a6d3SLuigi Rizzo  *   ring, and will be dropped as soon as the packet reaches another netmap
16137e3a6d3SLuigi Rizzo  *   adapter.
162ce3ee1e7SLuigi Rizzo  */
163ce3ee1e7SLuigi Rizzo 
164ce3ee1e7SLuigi Rizzo /*
165ce3ee1e7SLuigi Rizzo  * struct netmap_slot is a buffer descriptor
16617885a7bSLuigi Rizzo  */
16717885a7bSLuigi Rizzo struct netmap_slot {
16817885a7bSLuigi Rizzo 	uint32_t buf_idx;	/* buffer index */
16917885a7bSLuigi Rizzo 	uint16_t len;		/* length for this slot */
17017885a7bSLuigi Rizzo 	uint16_t flags;		/* buf changed, etc. */
17117885a7bSLuigi Rizzo 	uint64_t ptr;		/* pointer for indirect buffers */
17217885a7bSLuigi Rizzo };
17317885a7bSLuigi Rizzo 
17417885a7bSLuigi Rizzo /*
17517885a7bSLuigi Rizzo  * The following flags control how the slot is used
17617885a7bSLuigi Rizzo  */
17717885a7bSLuigi Rizzo 
17817885a7bSLuigi Rizzo #define	NS_BUF_CHANGED	0x0001	/* buf_idx changed */
17917885a7bSLuigi Rizzo 	/*
18017885a7bSLuigi Rizzo 	 * must be set whenever buf_idx is changed (as it might be
18117885a7bSLuigi Rizzo 	 * necessary to recompute the physical address and mapping)
182847bf383SLuigi Rizzo 	 *
183847bf383SLuigi Rizzo 	 * It is also set by the kernel whenever the buf_idx is
184847bf383SLuigi Rizzo 	 * changed internally (e.g., by pipes). Applications may
185847bf383SLuigi Rizzo 	 * use this information to know when they can reuse the
186847bf383SLuigi Rizzo 	 * contents of previously prepared buffers.
18717885a7bSLuigi Rizzo 	 */
18817885a7bSLuigi Rizzo 
18917885a7bSLuigi Rizzo #define	NS_REPORT	0x0002	/* ask the hardware to report results */
19017885a7bSLuigi Rizzo 	/*
19117885a7bSLuigi Rizzo 	 * Request notification when slot is used by the hardware.
19217885a7bSLuigi Rizzo 	 * Normally transmit completions are handled lazily and
19317885a7bSLuigi Rizzo 	 * may be unreported. This flag lets us know when a slot
19417885a7bSLuigi Rizzo 	 * has been sent (e.g. to terminate the sender).
19517885a7bSLuigi Rizzo 	 */
19617885a7bSLuigi Rizzo 
19717885a7bSLuigi Rizzo #define	NS_FORWARD	0x0004	/* pass packet 'forward' */
19817885a7bSLuigi Rizzo 	/*
19917885a7bSLuigi Rizzo 	 * (Only for physical ports, rx rings with NR_FORWARD set).
20017885a7bSLuigi Rizzo 	 * Slot released to the kernel (i.e. before ring->head) with
20117885a7bSLuigi Rizzo 	 * this flag set are passed to the peer ring (host/NIC),
20217885a7bSLuigi Rizzo 	 * thus restoring the host-NIC connection for these slots.
20317885a7bSLuigi Rizzo 	 * This supports efficient traffic monitoring or firewalling.
20417885a7bSLuigi Rizzo 	 */
20517885a7bSLuigi Rizzo 
20617885a7bSLuigi Rizzo #define	NS_NO_LEARN	0x0008	/* disable bridge learning */
20717885a7bSLuigi Rizzo  	/*
20817885a7bSLuigi Rizzo 	 * On a VALE switch, do not 'learn' the source port for
20917885a7bSLuigi Rizzo  	 * this buffer.
21017885a7bSLuigi Rizzo 	 */
21117885a7bSLuigi Rizzo 
21217885a7bSLuigi Rizzo #define	NS_INDIRECT	0x0010	/* userspace buffer */
21317885a7bSLuigi Rizzo  	/*
21417885a7bSLuigi Rizzo 	 * (VALE tx rings only) data is in a userspace buffer,
21517885a7bSLuigi Rizzo 	 * whose address is in the 'ptr' field in the slot.
21617885a7bSLuigi Rizzo 	 */
21717885a7bSLuigi Rizzo 
21817885a7bSLuigi Rizzo #define	NS_MOREFRAG	0x0020	/* packet has more fragments */
21917885a7bSLuigi Rizzo  	/*
22017885a7bSLuigi Rizzo 	 * (VALE ports only)
22117885a7bSLuigi Rizzo 	 * Set on all but the last slot of a multi-segment packet.
22217885a7bSLuigi Rizzo 	 * The 'len' field refers to the individual fragment.
22317885a7bSLuigi Rizzo 	 */
22417885a7bSLuigi Rizzo 
22517885a7bSLuigi Rizzo #define	NS_PORT_SHIFT	8
22617885a7bSLuigi Rizzo #define	NS_PORT_MASK	(0xff << NS_PORT_SHIFT)
22717885a7bSLuigi Rizzo 	/*
22817885a7bSLuigi Rizzo  	 * The high 8 bits of the flag, if not zero, indicate the
22901c039a1SLuigi Rizzo 	 * destination port for the VALE switch, overriding
23001c039a1SLuigi Rizzo  	 * the lookup table.
23168b8534bSLuigi Rizzo  	 */
23201c039a1SLuigi Rizzo 
23317885a7bSLuigi Rizzo #define	NS_RFRAGS(_slot)	( ((_slot)->flags >> 8) & 0xff)
234ce3ee1e7SLuigi Rizzo 	/*
23517885a7bSLuigi Rizzo 	 * (VALE rx rings only) the high 8 bits
236ce3ee1e7SLuigi Rizzo 	 *  are the number of fragments.
237ce3ee1e7SLuigi Rizzo 	 */
23817885a7bSLuigi Rizzo 
23968b8534bSLuigi Rizzo 
24068b8534bSLuigi Rizzo /*
241ce3ee1e7SLuigi Rizzo  * struct netmap_ring
242ce3ee1e7SLuigi Rizzo  *
24368b8534bSLuigi Rizzo  * Netmap representation of a TX or RX ring (also known as "queue").
24468b8534bSLuigi Rizzo  * This is a queue implemented as a fixed-size circular array.
24517885a7bSLuigi Rizzo  * At the software level the important fields are: head, cur, tail.
24668b8534bSLuigi Rizzo  *
24768b8534bSLuigi Rizzo  * In TX rings:
248ce3ee1e7SLuigi Rizzo  *
24917885a7bSLuigi Rizzo  *	head	first slot available for transmission.
25017885a7bSLuigi Rizzo  *	cur	wakeup point. select() and poll() will unblock
25117885a7bSLuigi Rizzo  *		when 'tail' moves past 'cur'
25217885a7bSLuigi Rizzo  *	tail	(readonly) first slot reserved to the kernel
253ce3ee1e7SLuigi Rizzo  *
25417885a7bSLuigi Rizzo  *	[head .. tail-1] can be used for new packets to send;
25517885a7bSLuigi Rizzo  *	'head' and 'cur' must be incremented as slots are filled
25617885a7bSLuigi Rizzo  *	    with new packets to be sent;
25717885a7bSLuigi Rizzo  *	'cur' can be moved further ahead if we need more space
2585c8c1004SLuigi Rizzo  *	for new transmissions. XXX todo (2014-03-12)
25968b8534bSLuigi Rizzo  *
26068b8534bSLuigi Rizzo  * In RX rings:
261ce3ee1e7SLuigi Rizzo  *
26217885a7bSLuigi Rizzo  *	head	first valid received packet
26317885a7bSLuigi Rizzo  *	cur	wakeup point. select() and poll() will unblock
26417885a7bSLuigi Rizzo  *		when 'tail' moves past 'cur'
26517885a7bSLuigi Rizzo  *	tail	(readonly) first slot reserved to the kernel
266ce3ee1e7SLuigi Rizzo  *
26717885a7bSLuigi Rizzo  *	[head .. tail-1] contain received packets;
26817885a7bSLuigi Rizzo  *	'head' and 'cur' must be incremented as slots are consumed
26917885a7bSLuigi Rizzo  *		and can be returned to the kernel;
27017885a7bSLuigi Rizzo  *	'cur' can be moved further ahead if we want to wait for
27117885a7bSLuigi Rizzo  *		new packets without returning the previous ones.
27268b8534bSLuigi Rizzo  *
27368b8534bSLuigi Rizzo  * DATA OWNERSHIP/LOCKING:
27417885a7bSLuigi Rizzo  *	The netmap_ring, and all slots and buffers in the range
27517885a7bSLuigi Rizzo  *	[head .. tail-1] are owned by the user program;
27617885a7bSLuigi Rizzo  *	the kernel only accesses them during a netmap system call
27717885a7bSLuigi Rizzo  *	and in the user thread context.
27801c039a1SLuigi Rizzo  *
27917885a7bSLuigi Rizzo  *	Other slots and buffers are reserved for use by the kernel
28068b8534bSLuigi Rizzo  */
28168b8534bSLuigi Rizzo struct netmap_ring {
28268b8534bSLuigi Rizzo 	/*
283ce3ee1e7SLuigi Rizzo 	 * buf_ofs is meant to be used through macros.
28468b8534bSLuigi Rizzo 	 * It contains the offset of the buffer region from this
28568b8534bSLuigi Rizzo 	 * descriptor.
28668b8534bSLuigi Rizzo 	 */
28717885a7bSLuigi Rizzo 	const int64_t	buf_ofs;
28868b8534bSLuigi Rizzo 	const uint32_t	num_slots;	/* number of slots in the ring. */
28917885a7bSLuigi Rizzo 	const uint32_t	nr_buf_size;
29017885a7bSLuigi Rizzo 	const uint16_t	ringid;
29117885a7bSLuigi Rizzo 	const uint16_t	dir;		/* 0: tx, 1: rx */
29268b8534bSLuigi Rizzo 
29317885a7bSLuigi Rizzo 	uint32_t        head;		/* (u) first user slot */
29417885a7bSLuigi Rizzo 	uint32_t        cur;		/* (u) wakeup point */
29517885a7bSLuigi Rizzo 	uint32_t	tail;		/* (k) first kernel slot */
29668b8534bSLuigi Rizzo 
29717885a7bSLuigi Rizzo 	uint32_t	flags;
29817885a7bSLuigi Rizzo 
29917885a7bSLuigi Rizzo 	struct timeval	ts;		/* (k) time of last *sync() */
30017885a7bSLuigi Rizzo 
30117885a7bSLuigi Rizzo 	/* opaque room for a mutex or similar object */
30237e3a6d3SLuigi Rizzo #if !defined(_WIN32) || defined(__CYGWIN__)
30337e3a6d3SLuigi Rizzo 	uint8_t	__attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128];
30437e3a6d3SLuigi Rizzo #else
30537e3a6d3SLuigi Rizzo 	uint8_t	__declspec(align(NM_CACHE_ALIGN)) sem[128];
30637e3a6d3SLuigi Rizzo #endif
30768b8534bSLuigi Rizzo 
30868b8534bSLuigi Rizzo 	/* the slots follow. This struct has variable size */
30968b8534bSLuigi Rizzo 	struct netmap_slot slot[0];	/* array of slots. */
31068b8534bSLuigi Rizzo };
31168b8534bSLuigi Rizzo 
31268b8534bSLuigi Rizzo 
31368b8534bSLuigi Rizzo /*
31417885a7bSLuigi Rizzo  * RING FLAGS
31517885a7bSLuigi Rizzo  */
31617885a7bSLuigi Rizzo #define	NR_TIMESTAMP	0x0002		/* set timestamp on *sync() */
31717885a7bSLuigi Rizzo 	/*
31817885a7bSLuigi Rizzo 	 * updates the 'ts' field on each netmap syscall. This saves
31917885a7bSLuigi Rizzo 	 * saves a separate gettimeofday(), and is not much worse than
32017885a7bSLuigi Rizzo 	 * software timestamps generated in the interrupt handler.
32117885a7bSLuigi Rizzo 	 */
32217885a7bSLuigi Rizzo 
32317885a7bSLuigi Rizzo #define	NR_FORWARD	0x0004		/* enable NS_FORWARD for ring */
32417885a7bSLuigi Rizzo  	/*
32517885a7bSLuigi Rizzo 	 * Enables the NS_FORWARD slot flag for the ring.
32617885a7bSLuigi Rizzo 	 */
32717885a7bSLuigi Rizzo 
32817885a7bSLuigi Rizzo 
32917885a7bSLuigi Rizzo /*
33068b8534bSLuigi Rizzo  * Netmap representation of an interface and its queue(s).
331ce3ee1e7SLuigi Rizzo  * This is initialized by the kernel when binding a file
332ce3ee1e7SLuigi Rizzo  * descriptor to a port, and should be considered as readonly
333ce3ee1e7SLuigi Rizzo  * by user programs. The kernel never uses it.
334ce3ee1e7SLuigi Rizzo  *
33568b8534bSLuigi Rizzo  * There is one netmap_if for each file descriptor on which we want
336ce3ee1e7SLuigi Rizzo  * to select/poll.
33768b8534bSLuigi Rizzo  * select/poll operates on one or all pairs depending on the value of
33868b8534bSLuigi Rizzo  * nmr_queueid passed on the ioctl.
33968b8534bSLuigi Rizzo  */
34068b8534bSLuigi Rizzo struct netmap_if {
34168b8534bSLuigi Rizzo 	char		ni_name[IFNAMSIZ]; /* name of the interface. */
342ce3ee1e7SLuigi Rizzo 	const uint32_t	ni_version;	/* API version, currently unused */
343ce3ee1e7SLuigi Rizzo 	const uint32_t	ni_flags;	/* properties */
344ce3ee1e7SLuigi Rizzo #define	NI_PRIV_MEM	0x1		/* private memory region */
345ce3ee1e7SLuigi Rizzo 
34617885a7bSLuigi Rizzo 	/*
34717885a7bSLuigi Rizzo 	 * The number of packet rings available in netmap mode.
34817885a7bSLuigi Rizzo 	 * Physical NICs can have different numbers of tx and rx rings.
34917885a7bSLuigi Rizzo 	 * Physical NICs also have a 'host' ring pair.
35017885a7bSLuigi Rizzo 	 * Additionally, clients can request additional ring pairs to
35117885a7bSLuigi Rizzo 	 * be used for internal communication.
35217885a7bSLuigi Rizzo 	 */
35317885a7bSLuigi Rizzo 	const uint32_t	ni_tx_rings;	/* number of HW tx rings */
35417885a7bSLuigi Rizzo 	const uint32_t	ni_rx_rings;	/* number of HW rx rings */
35517885a7bSLuigi Rizzo 
356f0ea3689SLuigi Rizzo 	uint32_t	ni_bufs_head;	/* head index for extra bufs */
357f0ea3689SLuigi Rizzo 	uint32_t	ni_spare1[5];
35868b8534bSLuigi Rizzo 	/*
35964ae02c3SLuigi Rizzo 	 * The following array contains the offset of each netmap ring
36017885a7bSLuigi Rizzo 	 * from this structure, in the following order:
36117885a7bSLuigi Rizzo 	 * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings;
36217885a7bSLuigi Rizzo 	 * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings.
36317885a7bSLuigi Rizzo 	 *
364ce3ee1e7SLuigi Rizzo 	 * The area is filled up by the kernel on NIOCREGIF,
36568b8534bSLuigi Rizzo 	 * and then only read by userspace code.
36668b8534bSLuigi Rizzo 	 */
36768b8534bSLuigi Rizzo 	const ssize_t	ring_ofs[0];
36868b8534bSLuigi Rizzo };
36968b8534bSLuigi Rizzo 
37017885a7bSLuigi Rizzo 
37168b8534bSLuigi Rizzo #ifndef NIOCREGIF
37268b8534bSLuigi Rizzo /*
37368b8534bSLuigi Rizzo  * ioctl names and related fields
37468b8534bSLuigi Rizzo  *
37517885a7bSLuigi Rizzo  * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
37617885a7bSLuigi Rizzo  *	whose identity is set in NIOCREGIF through nr_ringid.
37717885a7bSLuigi Rizzo  *	These are non blocking and take no argument.
37817885a7bSLuigi Rizzo  *
37968b8534bSLuigi Rizzo  * NIOCGINFO takes a struct ifreq, the interface name is the input,
38068b8534bSLuigi Rizzo  *	the outputs are number of queues and number of descriptor
38168b8534bSLuigi Rizzo  *	for each queue (useful to set number of threads etc.).
382ce3ee1e7SLuigi Rizzo  *	The info returned is only advisory and may change before
383ce3ee1e7SLuigi Rizzo  *	the interface is bound to a file descriptor.
38468b8534bSLuigi Rizzo  *
38517885a7bSLuigi Rizzo  * NIOCREGIF takes an interface name within a struct nmre,
38668b8534bSLuigi Rizzo  *	and activates netmap mode on the interface (if possible).
38768b8534bSLuigi Rizzo  *
38817885a7bSLuigi Rizzo  * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we
38917885a7bSLuigi Rizzo  * can pass it down to other NIC-related ioctls.
390f18be576SLuigi Rizzo  *
39117885a7bSLuigi Rizzo  * The actual argument (struct nmreq) has a number of options to request
39217885a7bSLuigi Rizzo  * different functions.
393f0ea3689SLuigi Rizzo  * The following are used in NIOCREGIF when nr_cmd == 0:
394f18be576SLuigi Rizzo  *
39517885a7bSLuigi Rizzo  * nr_name	(in)
39617885a7bSLuigi Rizzo  *	The name of the port (em0, valeXXX:YYY, etc.)
39717885a7bSLuigi Rizzo  *	limited to IFNAMSIZ for backward compatibility.
398ce3ee1e7SLuigi Rizzo  *
39917885a7bSLuigi Rizzo  * nr_version	(in/out)
40017885a7bSLuigi Rizzo  *	Must match NETMAP_API as used in the kernel, error otherwise.
40117885a7bSLuigi Rizzo  *	Always returns the desired value on output.
40217885a7bSLuigi Rizzo  *
40317885a7bSLuigi Rizzo  * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out)
40417885a7bSLuigi Rizzo  *	On input, non-zero values may be used to reconfigure the port
40517885a7bSLuigi Rizzo  *	according to the requested values, but this is not guaranteed.
40617885a7bSLuigi Rizzo  *	On output the actual values in use are reported.
40717885a7bSLuigi Rizzo  *
40817885a7bSLuigi Rizzo  * nr_ringid (in)
40917885a7bSLuigi Rizzo  *	Indicates how rings should be bound to the file descriptors.
410f0ea3689SLuigi Rizzo  *	If nr_flags != 0, then the low bits (in NETMAP_RING_MASK)
411f0ea3689SLuigi Rizzo  *	are used to indicate the ring number, and nr_flags specifies
412f0ea3689SLuigi Rizzo  *	the actual rings to bind. NETMAP_NO_TX_POLL is unaffected.
413f0ea3689SLuigi Rizzo  *
414f0ea3689SLuigi Rizzo  *	NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED:
415f0ea3689SLuigi Rizzo  *	If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control
416f0ea3689SLuigi Rizzo  *	the binding as follows:
41717885a7bSLuigi Rizzo  *	0 (default)			binds all physical rings
41817885a7bSLuigi Rizzo  *	NETMAP_HW_RING | ring number	binds a single ring pair
419ce3ee1e7SLuigi Rizzo  *	NETMAP_SW_RING			binds only the host tx/rx rings
420ce3ee1e7SLuigi Rizzo  *
42117885a7bSLuigi Rizzo  *	NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push
42217885a7bSLuigi Rizzo  *		packets on tx rings only if POLLOUT is set.
42317885a7bSLuigi Rizzo  *		The default is to push any pending packet.
424ce3ee1e7SLuigi Rizzo  *
425f0ea3689SLuigi Rizzo  *	NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release
426f0ea3689SLuigi Rizzo  *		packets on rx rings also when POLLIN is NOT set.
427f0ea3689SLuigi Rizzo  *		The default is to touch the rx ring only with POLLIN.
428f0ea3689SLuigi Rizzo  *		Note that this is the opposite of TX because it
429f0ea3689SLuigi Rizzo  *		reflects the common usage.
430f0ea3689SLuigi Rizzo  *
431f0ea3689SLuigi Rizzo  *	NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead.
432f0ea3689SLuigi Rizzo  *	NETMAP_PRIV_MEM is set on return for ports that do not use
433f0ea3689SLuigi Rizzo  *		the global memory allocator.
434f0ea3689SLuigi Rizzo  *		This information is not significant and applications
435f0ea3689SLuigi Rizzo  *		should look at the region id in nr_arg2
436f0ea3689SLuigi Rizzo  *
437f0ea3689SLuigi Rizzo  * nr_flags	is the recommended mode to indicate which rings should
438f0ea3689SLuigi Rizzo  *		be bound to a file descriptor. Values are NR_REG_*
439f0ea3689SLuigi Rizzo  *
440f0ea3689SLuigi Rizzo  * nr_arg1 (in)	The number of extra rings to be reserved.
441f0ea3689SLuigi Rizzo  *		Especially when allocating a VALE port the system only
442f0ea3689SLuigi Rizzo  *		allocates the amount of memory needed for the port.
443f0ea3689SLuigi Rizzo  *		If more shared memory rings are desired (e.g. for pipes),
444f0ea3689SLuigi Rizzo  *		the first invocation for the same basename/allocator
445f0ea3689SLuigi Rizzo  *		should specify a suitable number. Memory cannot be
446f0ea3689SLuigi Rizzo  *		extended after the first allocation without closing
447f0ea3689SLuigi Rizzo  *		all ports on the same region.
448f0ea3689SLuigi Rizzo  *
449f0ea3689SLuigi Rizzo  * nr_arg2 (in/out) The identity of the memory region used.
450f0ea3689SLuigi Rizzo  *		On input, 0 means the system decides autonomously,
451f0ea3689SLuigi Rizzo  *		other values may try to select a specific region.
452f0ea3689SLuigi Rizzo  *		On return the actual value is reported.
453f0ea3689SLuigi Rizzo  *		Region '1' is the global allocator, normally shared
454f0ea3689SLuigi Rizzo  *		by all interfaces. Other values are private regions.
455f0ea3689SLuigi Rizzo  *		If two ports the same region zero-copy is possible.
456f0ea3689SLuigi Rizzo  *
457f0ea3689SLuigi Rizzo  * nr_arg3 (in/out)	number of extra buffers to be allocated.
458f0ea3689SLuigi Rizzo  *
459f0ea3689SLuigi Rizzo  *
460ce3ee1e7SLuigi Rizzo  *
46117885a7bSLuigi Rizzo  * nr_cmd (in)	if non-zero indicates a special command:
46217885a7bSLuigi Rizzo  *	NETMAP_BDG_ATTACH	 and nr_name = vale*:ifname
46317885a7bSLuigi Rizzo  *		attaches the NIC to the switch; nr_ringid specifies
46417885a7bSLuigi Rizzo  *		which rings to use. Used by vale-ctl -a ...
46517885a7bSLuigi Rizzo  *	    nr_arg1 = NETMAP_BDG_HOST also attaches the host port
46617885a7bSLuigi Rizzo  *		as in vale-ctl -h ...
467ce3ee1e7SLuigi Rizzo  *
46817885a7bSLuigi Rizzo  *	NETMAP_BDG_DETACH	and nr_name = vale*:ifname
46917885a7bSLuigi Rizzo  *		disconnects a previously attached NIC.
47017885a7bSLuigi Rizzo  *		Used by vale-ctl -d ...
471ce3ee1e7SLuigi Rizzo  *
47217885a7bSLuigi Rizzo  *	NETMAP_BDG_LIST
47317885a7bSLuigi Rizzo  *		list the configuration of VALE switches.
47468b8534bSLuigi Rizzo  *
475f0ea3689SLuigi Rizzo  *	NETMAP_BDG_VNET_HDR
476f0ea3689SLuigi Rizzo  *		Set the virtio-net header length used by the client
477f0ea3689SLuigi Rizzo  *		of a VALE switch port.
478f18be576SLuigi Rizzo  *
4794bf50f18SLuigi Rizzo  *	NETMAP_BDG_NEWIF
4804bf50f18SLuigi Rizzo  *		create a persistent VALE port with name nr_name.
4814bf50f18SLuigi Rizzo  *		Used by vale-ctl -n ...
4824bf50f18SLuigi Rizzo  *
4834bf50f18SLuigi Rizzo  *	NETMAP_BDG_DELIF
4844bf50f18SLuigi Rizzo  *		delete a persistent VALE port. Used by vale-ctl -d ...
4854bf50f18SLuigi Rizzo  *
486f0ea3689SLuigi Rizzo  * nr_arg1, nr_arg2, nr_arg3  (in/out)		command specific
487f0ea3689SLuigi Rizzo  *
488f0ea3689SLuigi Rizzo  *
48917885a7bSLuigi Rizzo  *
49068b8534bSLuigi Rizzo  */
49168b8534bSLuigi Rizzo 
49217885a7bSLuigi Rizzo 
49368b8534bSLuigi Rizzo /*
494f0ea3689SLuigi Rizzo  * struct nmreq overlays a struct ifreq (just the name)
49568b8534bSLuigi Rizzo  */
49668b8534bSLuigi Rizzo struct nmreq {
49768b8534bSLuigi Rizzo 	char		nr_name[IFNAMSIZ];
49864ae02c3SLuigi Rizzo 	uint32_t	nr_version;	/* API version */
49968b8534bSLuigi Rizzo 	uint32_t	nr_offset;	/* nifp offset in the shared region */
50068b8534bSLuigi Rizzo 	uint32_t	nr_memsize;	/* size of the shared region */
50164ae02c3SLuigi Rizzo 	uint32_t	nr_tx_slots;	/* slots in tx rings */
50264ae02c3SLuigi Rizzo 	uint32_t	nr_rx_slots;	/* slots in rx rings */
50364ae02c3SLuigi Rizzo 	uint16_t	nr_tx_rings;	/* number of tx rings */
50464ae02c3SLuigi Rizzo 	uint16_t	nr_rx_rings;	/* number of rx rings */
505f0ea3689SLuigi Rizzo 
50668b8534bSLuigi Rizzo 	uint16_t	nr_ringid;	/* ring(s) we care about */
507f0ea3689SLuigi Rizzo #define NETMAP_HW_RING		0x4000	/* single NIC ring pair */
508f0ea3689SLuigi Rizzo #define NETMAP_SW_RING		0x2000	/* only host ring pair */
509f0ea3689SLuigi Rizzo 
510f0ea3689SLuigi Rizzo #define NETMAP_RING_MASK	0x0fff	/* the ring number */
511f0ea3689SLuigi Rizzo 
51264ae02c3SLuigi Rizzo #define NETMAP_NO_TX_POLL	0x1000	/* no automatic txsync on poll */
513f0ea3689SLuigi Rizzo 
514f0ea3689SLuigi Rizzo #define NETMAP_DO_RX_POLL	0x8000	/* DO automatic rxsync on poll */
51517885a7bSLuigi Rizzo 
516f18be576SLuigi Rizzo 	uint16_t	nr_cmd;
517f18be576SLuigi Rizzo #define NETMAP_BDG_ATTACH	1	/* attach the NIC */
518f18be576SLuigi Rizzo #define NETMAP_BDG_DETACH	2	/* detach the NIC */
5194bf50f18SLuigi Rizzo #define NETMAP_BDG_REGOPS	3	/* register bridge callbacks */
520f18be576SLuigi Rizzo #define NETMAP_BDG_LIST		4	/* get bridge's info */
521f0ea3689SLuigi Rizzo #define NETMAP_BDG_VNET_HDR     5       /* set the port virtio-net-hdr length */
522f0ea3689SLuigi Rizzo #define NETMAP_BDG_OFFSET	NETMAP_BDG_VNET_HDR	/* deprecated alias */
5234bf50f18SLuigi Rizzo #define NETMAP_BDG_NEWIF	6	/* create a virtual port */
5244bf50f18SLuigi Rizzo #define NETMAP_BDG_DELIF	7	/* destroy a virtual port */
52537e3a6d3SLuigi Rizzo #define NETMAP_PT_HOST_CREATE	8	/* create ptnetmap kthreads */
52637e3a6d3SLuigi Rizzo #define NETMAP_PT_HOST_DELETE	9	/* delete ptnetmap kthreads */
52737e3a6d3SLuigi Rizzo #define NETMAP_BDG_POLLING_ON	10	/* delete polling kthread */
52837e3a6d3SLuigi Rizzo #define NETMAP_BDG_POLLING_OFF	11	/* delete polling kthread */
52937e3a6d3SLuigi Rizzo #define NETMAP_VNET_HDR_GET	12      /* get the port virtio-net-hdr length */
530844a6f0cSLuigi Rizzo #define NETMAP_POOLS_INFO_GET	13	/* get memory allocator pools info */
531f0ea3689SLuigi Rizzo 	uint16_t	nr_arg1;	/* reserve extra rings in NIOCREGIF */
532f18be576SLuigi Rizzo #define NETMAP_BDG_HOST		1	/* attach the host stack on ATTACH */
53317885a7bSLuigi Rizzo 
534f18be576SLuigi Rizzo 	uint16_t	nr_arg2;
535f0ea3689SLuigi Rizzo 	uint32_t	nr_arg3;	/* req. extra buffers in NIOCREGIF */
536f0ea3689SLuigi Rizzo 	uint32_t	nr_flags;
537f0ea3689SLuigi Rizzo 	/* various modes, extends nr_ringid */
538f0ea3689SLuigi Rizzo 	uint32_t	spare2[1];
53968b8534bSLuigi Rizzo };
54068b8534bSLuigi Rizzo 
541f0ea3689SLuigi Rizzo #define NR_REG_MASK		0xf /* values for nr_flags */
542f0ea3689SLuigi Rizzo enum {	NR_REG_DEFAULT	= 0,	/* backward compat, should not be used. */
543f0ea3689SLuigi Rizzo 	NR_REG_ALL_NIC	= 1,
544f0ea3689SLuigi Rizzo 	NR_REG_SW	= 2,
545f0ea3689SLuigi Rizzo 	NR_REG_NIC_SW	= 3,
546f0ea3689SLuigi Rizzo 	NR_REG_ONE_NIC	= 4,
547f0ea3689SLuigi Rizzo 	NR_REG_PIPE_MASTER = 5,
548f0ea3689SLuigi Rizzo 	NR_REG_PIPE_SLAVE = 6,
549f0ea3689SLuigi Rizzo };
550f0ea3689SLuigi Rizzo /* monitor uses the NR_REG to select the rings to monitor */
551f0ea3689SLuigi Rizzo #define NR_MONITOR_TX	0x100
552f0ea3689SLuigi Rizzo #define NR_MONITOR_RX	0x200
553847bf383SLuigi Rizzo #define NR_ZCOPY_MON	0x400
554847bf383SLuigi Rizzo /* request exclusive access to the selected rings */
555847bf383SLuigi Rizzo #define NR_EXCLUSIVE	0x800
55637e3a6d3SLuigi Rizzo /* request ptnetmap host support */
55737e3a6d3SLuigi Rizzo #define NR_PASSTHROUGH_HOST	NR_PTNETMAP_HOST /* deprecated */
55837e3a6d3SLuigi Rizzo #define NR_PTNETMAP_HOST	0x1000
55937e3a6d3SLuigi Rizzo #define NR_RX_RINGS_ONLY	0x2000
56037e3a6d3SLuigi Rizzo #define NR_TX_RINGS_ONLY	0x4000
56137e3a6d3SLuigi Rizzo /* Applications set this flag if they are able to deal with virtio-net headers,
56237e3a6d3SLuigi Rizzo  * that is send/receive frames that start with a virtio-net header.
56337e3a6d3SLuigi Rizzo  * If not set, NIOCREGIF will fail with netmap ports that require applications
56437e3a6d3SLuigi Rizzo  * to use those headers. If the flag is set, the application can use the
56537e3a6d3SLuigi Rizzo  * NETMAP_VNET_HDR_GET command to figure out the header length. */
56637e3a6d3SLuigi Rizzo #define NR_ACCEPT_VNET_HDR	0x8000
567f0ea3689SLuigi Rizzo 
56837e3a6d3SLuigi Rizzo #define	NM_BDG_NAME		"vale"	/* prefix for bridge port name */
56937e3a6d3SLuigi Rizzo 
57037e3a6d3SLuigi Rizzo /*
57137e3a6d3SLuigi Rizzo  * Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined
57237e3a6d3SLuigi Rizzo  * in ws2def.h but not sure if they are in the form we need.
57337e3a6d3SLuigi Rizzo  * XXX so we redefine them
57437e3a6d3SLuigi Rizzo  * in a convenient way to use for DeviceIoControl signatures
57537e3a6d3SLuigi Rizzo  */
57637e3a6d3SLuigi Rizzo #ifdef _WIN32
57737e3a6d3SLuigi Rizzo #undef _IO	// ws2def.h
57837e3a6d3SLuigi Rizzo #define _WIN_NM_IOCTL_TYPE 40000
57937e3a6d3SLuigi Rizzo #define _IO(_c, _n)	CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
58037e3a6d3SLuigi Rizzo 		METHOD_BUFFERED, FILE_ANY_ACCESS  )
58137e3a6d3SLuigi Rizzo #define _IO_direct(_c, _n)	CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \
58237e3a6d3SLuigi Rizzo 		METHOD_OUT_DIRECT, FILE_ANY_ACCESS  )
58337e3a6d3SLuigi Rizzo 
58437e3a6d3SLuigi Rizzo #define _IOWR(_c, _n, _s)	_IO(_c, _n)
58537e3a6d3SLuigi Rizzo 
58637e3a6d3SLuigi Rizzo /* We havesome internal sysctl in addition to the externally visible ones */
58737e3a6d3SLuigi Rizzo #define NETMAP_MMAP _IO_direct('i', 160)	// note METHOD_OUT_DIRECT
58837e3a6d3SLuigi Rizzo #define NETMAP_POLL _IO('i', 162)
58937e3a6d3SLuigi Rizzo 
59037e3a6d3SLuigi Rizzo /* and also two setsockopt for sysctl emulation */
59137e3a6d3SLuigi Rizzo #define NETMAP_SETSOCKOPT _IO('i', 140)
59237e3a6d3SLuigi Rizzo #define NETMAP_GETSOCKOPT _IO('i', 141)
59337e3a6d3SLuigi Rizzo 
59437e3a6d3SLuigi Rizzo 
59537e3a6d3SLuigi Rizzo //These linknames are for the Netmap Core Driver
59637e3a6d3SLuigi Rizzo #define NETMAP_NT_DEVICE_NAME			L"\\Device\\NETMAP"
59737e3a6d3SLuigi Rizzo #define NETMAP_DOS_DEVICE_NAME			L"\\DosDevices\\netmap"
59837e3a6d3SLuigi Rizzo 
59937e3a6d3SLuigi Rizzo //Definition of a structure used to pass a virtual address within an IOCTL
60037e3a6d3SLuigi Rizzo typedef struct _MEMORY_ENTRY {
60137e3a6d3SLuigi Rizzo 	PVOID       pUsermodeVirtualAddress;
60237e3a6d3SLuigi Rizzo } MEMORY_ENTRY, *PMEMORY_ENTRY;
60337e3a6d3SLuigi Rizzo 
60437e3a6d3SLuigi Rizzo typedef struct _POLL_REQUEST_DATA {
60537e3a6d3SLuigi Rizzo 	int events;
60637e3a6d3SLuigi Rizzo 	int timeout;
60737e3a6d3SLuigi Rizzo 	int revents;
60837e3a6d3SLuigi Rizzo } POLL_REQUEST_DATA;
60937e3a6d3SLuigi Rizzo 
61037e3a6d3SLuigi Rizzo #endif /* _WIN32 */
61117885a7bSLuigi Rizzo 
61264ae02c3SLuigi Rizzo /*
61364ae02c3SLuigi Rizzo  * FreeBSD uses the size value embedded in the _IOWR to determine
61464ae02c3SLuigi Rizzo  * how much to copy in/out. So we need it to match the actual
61564ae02c3SLuigi Rizzo  * data structure we pass. We put some spares in the structure
61664ae02c3SLuigi Rizzo  * to ease compatibility with other versions
61764ae02c3SLuigi Rizzo  */
61868b8534bSLuigi Rizzo #define NIOCGINFO	_IOWR('i', 145, struct nmreq) /* return IF info */
61968b8534bSLuigi Rizzo #define NIOCREGIF	_IOWR('i', 146, struct nmreq) /* interface register */
62068b8534bSLuigi Rizzo #define NIOCTXSYNC	_IO('i', 148) /* sync tx queues */
62168b8534bSLuigi Rizzo #define NIOCRXSYNC	_IO('i', 149) /* sync rx queues */
6224bf50f18SLuigi Rizzo #define NIOCCONFIG	_IOWR('i',150, struct nm_ifreq) /* for ext. modules */
62368b8534bSLuigi Rizzo #endif /* !NIOCREGIF */
62468b8534bSLuigi Rizzo 
62517885a7bSLuigi Rizzo 
62617885a7bSLuigi Rizzo /*
62717885a7bSLuigi Rizzo  * Helper functions for kernel and userspace
62817885a7bSLuigi Rizzo  */
62917885a7bSLuigi Rizzo 
63017885a7bSLuigi Rizzo /*
63117885a7bSLuigi Rizzo  * check if space is available in the ring.
63217885a7bSLuigi Rizzo  */
63317885a7bSLuigi Rizzo static inline int
63417885a7bSLuigi Rizzo nm_ring_empty(struct netmap_ring *ring)
63517885a7bSLuigi Rizzo {
63617885a7bSLuigi Rizzo 	return (ring->cur == ring->tail);
63717885a7bSLuigi Rizzo }
63817885a7bSLuigi Rizzo 
6394bf50f18SLuigi Rizzo /*
6404bf50f18SLuigi Rizzo  * Opaque structure that is passed to an external kernel
6414bf50f18SLuigi Rizzo  * module via ioctl(fd, NIOCCONFIG, req) for a user-owned
6424bf50f18SLuigi Rizzo  * bridge port (at this point ephemeral VALE interface).
6434bf50f18SLuigi Rizzo  */
6444bf50f18SLuigi Rizzo #define NM_IFRDATA_LEN 256
6454bf50f18SLuigi Rizzo struct nm_ifreq {
6464bf50f18SLuigi Rizzo 	char nifr_name[IFNAMSIZ];
6474bf50f18SLuigi Rizzo 	char data[NM_IFRDATA_LEN];
6484bf50f18SLuigi Rizzo };
6494bf50f18SLuigi Rizzo 
65068b8534bSLuigi Rizzo #endif /* _NET_NETMAP_H_ */
651