168b8534bSLuigi Rizzo /* 217885a7bSLuigi Rizzo * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved. 368b8534bSLuigi Rizzo * 468b8534bSLuigi Rizzo * Redistribution and use in source and binary forms, with or without 5f9790aebSLuigi Rizzo * modification, are permitted provided that the following conditions 6f9790aebSLuigi Rizzo * are met: 768b8534bSLuigi Rizzo * 868b8534bSLuigi Rizzo * 1. Redistributions of source code must retain the above copyright 968b8534bSLuigi Rizzo * notice, this list of conditions and the following disclaimer. 1068b8534bSLuigi Rizzo * 2. Redistributions in binary form must reproduce the above copyright 1168b8534bSLuigi Rizzo * notice, this list of conditions and the following disclaimer in the 12f9790aebSLuigi Rizzo * documentation and/or other materials provided with the distribution. 1368b8534bSLuigi Rizzo * 14f9790aebSLuigi Rizzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND 1568b8534bSLuigi Rizzo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16f9790aebSLuigi Rizzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17f9790aebSLuigi Rizzo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18f9790aebSLuigi Rizzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19f9790aebSLuigi Rizzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20f9790aebSLuigi Rizzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21f9790aebSLuigi Rizzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22f9790aebSLuigi Rizzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23f9790aebSLuigi Rizzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24f9790aebSLuigi Rizzo * SUCH DAMAGE. 2568b8534bSLuigi Rizzo */ 2668b8534bSLuigi Rizzo 2768b8534bSLuigi Rizzo /* 2868b8534bSLuigi Rizzo * $FreeBSD$ 2968b8534bSLuigi Rizzo * 3064ae02c3SLuigi Rizzo * Definitions of constants and the structures used by the netmap 3164ae02c3SLuigi Rizzo * framework, for the part visible to both kernel and userspace. 3264ae02c3SLuigi Rizzo * Detailed info on netmap is available with "man netmap" or at 3364ae02c3SLuigi Rizzo * 3464ae02c3SLuigi Rizzo * http://info.iet.unipi.it/~luigi/netmap/ 35ce3ee1e7SLuigi Rizzo * 36ce3ee1e7SLuigi Rizzo * This API is also used to communicate with the VALE software switch 3768b8534bSLuigi Rizzo */ 3868b8534bSLuigi Rizzo 3968b8534bSLuigi Rizzo #ifndef _NET_NETMAP_H_ 4068b8534bSLuigi Rizzo #define _NET_NETMAP_H_ 4168b8534bSLuigi Rizzo 42f0ea3689SLuigi Rizzo #define NETMAP_API 11 /* current API version */ 4317885a7bSLuigi Rizzo 44f0ea3689SLuigi Rizzo #define NETMAP_MIN_API 11 /* min and max versions accepted */ 45f0ea3689SLuigi Rizzo #define NETMAP_MAX_API 15 4617885a7bSLuigi Rizzo /* 4717885a7bSLuigi Rizzo * Some fields should be cache-aligned to reduce contention. 4817885a7bSLuigi Rizzo * The alignment is architecture and OS dependent, but rather than 4917885a7bSLuigi Rizzo * digging into OS headers to find the exact value we use an estimate 5017885a7bSLuigi Rizzo * that should cover most architectures. 5117885a7bSLuigi Rizzo */ 5217885a7bSLuigi Rizzo #define NM_CACHE_ALIGN 128 5317885a7bSLuigi Rizzo 5468b8534bSLuigi Rizzo /* 5568b8534bSLuigi Rizzo * --- Netmap data structures --- 5668b8534bSLuigi Rizzo * 57ce3ee1e7SLuigi Rizzo * The userspace data structures used by netmap are shown below. 58ce3ee1e7SLuigi Rizzo * They are allocated by the kernel and mmap()ed by userspace threads. 59ce3ee1e7SLuigi Rizzo * Pointers are implemented as memory offsets or indexes, 60ce3ee1e7SLuigi Rizzo * so that they can be easily dereferenced in kernel and userspace. 6168b8534bSLuigi Rizzo 62ce3ee1e7SLuigi Rizzo KERNEL (opaque, obviously) 6368b8534bSLuigi Rizzo 6464ae02c3SLuigi Rizzo ==================================================================== 6564ae02c3SLuigi Rizzo | 66ce3ee1e7SLuigi Rizzo USERSPACE | struct netmap_ring 6717885a7bSLuigi Rizzo +---->+---------------+ 6817885a7bSLuigi Rizzo / | head,cur,tail | 6917885a7bSLuigi Rizzo struct netmap_if (nifp, 1 per fd) / | buf_ofs | 7017885a7bSLuigi Rizzo +---------------+ / | other fields | 7117885a7bSLuigi Rizzo | ni_tx_rings | / +===============+ 72ce3ee1e7SLuigi Rizzo | ni_rx_rings | / | buf_idx, len | slot[0] 73ce3ee1e7SLuigi Rizzo | | / | flags, ptr | 7417885a7bSLuigi Rizzo | | / +---------------+ 75ce3ee1e7SLuigi Rizzo +===============+ / | buf_idx, len | slot[1] 76ce3ee1e7SLuigi Rizzo | txring_ofs[0] | (rel.to nifp)--' | flags, ptr | 7717885a7bSLuigi Rizzo | txring_ofs[1] | +---------------+ 78f0ea3689SLuigi Rizzo (tx+1 entries) (num_slots entries) 79ce3ee1e7SLuigi Rizzo | txring_ofs[t] | | buf_idx, len | slot[n-1] 80ce3ee1e7SLuigi Rizzo +---------------+ | flags, ptr | 8117885a7bSLuigi Rizzo | rxring_ofs[0] | +---------------+ 8268b8534bSLuigi Rizzo | rxring_ofs[1] | 83f0ea3689SLuigi Rizzo (rx+1 entries) 84ce3ee1e7SLuigi Rizzo | rxring_ofs[r] | 8568b8534bSLuigi Rizzo +---------------+ 8668b8534bSLuigi Rizzo 87f0ea3689SLuigi Rizzo * For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to 88f0ea3689SLuigi Rizzo * a file descriptor, the mmap()ed region contains a (logically readonly) 89ce3ee1e7SLuigi Rizzo * struct netmap_if pointing to struct netmap_ring's. 90f0ea3689SLuigi Rizzo * 91ce3ee1e7SLuigi Rizzo * There is one netmap_ring per physical NIC ring, plus one tx/rx ring 92f0ea3689SLuigi Rizzo * pair attached to the host stack (this pair is unused for non-NIC ports). 93ce3ee1e7SLuigi Rizzo * 94ce3ee1e7SLuigi Rizzo * All physical/host stack ports share the same memory region, 95ce3ee1e7SLuigi Rizzo * so that zero-copy can be implemented between them. 96ce3ee1e7SLuigi Rizzo * VALE switch ports instead have separate memory regions. 97ce3ee1e7SLuigi Rizzo * 98ce3ee1e7SLuigi Rizzo * The netmap_ring is the userspace-visible replica of the NIC ring. 99ce3ee1e7SLuigi Rizzo * Each slot has the index of a buffer (MTU-sized and residing in the 100ce3ee1e7SLuigi Rizzo * mmapped region), its length and some flags. An extra 64-bit pointer 101ce3ee1e7SLuigi Rizzo * is provided for user-supplied buffers in the tx path. 102ce3ee1e7SLuigi Rizzo * 10368b8534bSLuigi Rizzo * In user space, the buffer address is computed as 10464ae02c3SLuigi Rizzo * (char *)ring + buf_ofs + index * NETMAP_BUF_SIZE 105f0ea3689SLuigi Rizzo * 106f0ea3689SLuigi Rizzo * Added in NETMAP_API 11: 107f0ea3689SLuigi Rizzo * 108f0ea3689SLuigi Rizzo * + NIOCREGIF can request the allocation of extra spare buffers from 109f0ea3689SLuigi Rizzo * the same memory pool. The desired number of buffers must be in 110f0ea3689SLuigi Rizzo * nr_arg3. The ioctl may return fewer buffers, depending on memory 111f0ea3689SLuigi Rizzo * availability. nr_arg3 will return the actual value, and, once 112f0ea3689SLuigi Rizzo * mapped, nifp->ni_bufs_head will be the index of the first buffer. 113f0ea3689SLuigi Rizzo * 114f0ea3689SLuigi Rizzo * The buffers are linked to each other using the first uint32_t 115f0ea3689SLuigi Rizzo * as the index. On close, ni_bufs_head must point to the list of 116f0ea3689SLuigi Rizzo * buffers to be released. 117f0ea3689SLuigi Rizzo * 118f0ea3689SLuigi Rizzo * + NIOCREGIF can request space for extra rings (and buffers) 119f0ea3689SLuigi Rizzo * allocated in the same memory space. The number of extra rings 120f0ea3689SLuigi Rizzo * is in nr_arg1, and is advisory. This is a no-op on NICs where 121f0ea3689SLuigi Rizzo * the size of the memory space is fixed. 122f0ea3689SLuigi Rizzo * 123f0ea3689SLuigi Rizzo * + NIOCREGIF can attach to PIPE rings sharing the same memory 124f0ea3689SLuigi Rizzo * space with a parent device. The ifname indicates the parent device, 125f0ea3689SLuigi Rizzo * which must already exist. Flags in nr_flags indicate if we want to 126f0ea3689SLuigi Rizzo * bind the master or slave side, the index (from nr_ringid) 1275c8c1004SLuigi Rizzo * is just a cookie and does not need to be sequential. 128f0ea3689SLuigi Rizzo * 129f0ea3689SLuigi Rizzo * + NIOCREGIF can also attach to 'monitor' rings that replicate 130f0ea3689SLuigi Rizzo * the content of specific rings, also from the same memory space. 131f0ea3689SLuigi Rizzo * 132f0ea3689SLuigi Rizzo * Extra flags in nr_flags support the above functions. 133f0ea3689SLuigi Rizzo * Application libraries may use the following naming scheme: 134f0ea3689SLuigi Rizzo * netmap:foo all NIC ring pairs 135f0ea3689SLuigi Rizzo * netmap:foo^ only host ring pair 136f0ea3689SLuigi Rizzo * netmap:foo+ all NIC ring + host ring pairs 137f0ea3689SLuigi Rizzo * netmap:foo-k the k-th NIC ring pair 138f0ea3689SLuigi Rizzo * netmap:foo{k PIPE ring pair k, master side 139f0ea3689SLuigi Rizzo * netmap:foo}k PIPE ring pair k, slave side 140*37e3a6d3SLuigi Rizzo * 141*37e3a6d3SLuigi Rizzo * Some notes about host rings: 142*37e3a6d3SLuigi Rizzo * 143*37e3a6d3SLuigi Rizzo * + The RX host ring is used to store those packets that the host network 144*37e3a6d3SLuigi Rizzo * stack is trying to transmit through a NIC queue, but only if that queue 145*37e3a6d3SLuigi Rizzo * is currently in netmap mode. Netmap will not intercept host stack mbufs 146*37e3a6d3SLuigi Rizzo * designated to NIC queues that are not in netmap mode. As a consequence, 147*37e3a6d3SLuigi Rizzo * registering a netmap port with netmap:foo^ is not enough to intercept 148*37e3a6d3SLuigi Rizzo * mbufs in the RX host ring; the netmap port should be registered with 149*37e3a6d3SLuigi Rizzo * netmap:foo*, or another registration should be done to open at least a 150*37e3a6d3SLuigi Rizzo * NIC TX queue in netmap mode. 151*37e3a6d3SLuigi Rizzo * 152*37e3a6d3SLuigi Rizzo * + Netmap is not currently able to deal with intercepted trasmit mbufs which 153*37e3a6d3SLuigi Rizzo * require offloadings like TSO, UFO, checksumming offloadings, etc. It is 154*37e3a6d3SLuigi Rizzo * responsibility of the user to disable those offloadings (e.g. using 155*37e3a6d3SLuigi Rizzo * ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being 156*37e3a6d3SLuigi Rizzo * used in netmap mode. If the offloadings are not disabled, GSO and/or 157*37e3a6d3SLuigi Rizzo * unchecksummed packets may be dropped immediately or end up in the host RX 158*37e3a6d3SLuigi Rizzo * ring, and will be dropped as soon as the packet reaches another netmap 159*37e3a6d3SLuigi Rizzo * adapter. 160ce3ee1e7SLuigi Rizzo */ 161ce3ee1e7SLuigi Rizzo 162ce3ee1e7SLuigi Rizzo /* 163ce3ee1e7SLuigi Rizzo * struct netmap_slot is a buffer descriptor 16417885a7bSLuigi Rizzo */ 16517885a7bSLuigi Rizzo struct netmap_slot { 16617885a7bSLuigi Rizzo uint32_t buf_idx; /* buffer index */ 16717885a7bSLuigi Rizzo uint16_t len; /* length for this slot */ 16817885a7bSLuigi Rizzo uint16_t flags; /* buf changed, etc. */ 16917885a7bSLuigi Rizzo uint64_t ptr; /* pointer for indirect buffers */ 17017885a7bSLuigi Rizzo }; 17117885a7bSLuigi Rizzo 17217885a7bSLuigi Rizzo /* 17317885a7bSLuigi Rizzo * The following flags control how the slot is used 17417885a7bSLuigi Rizzo */ 17517885a7bSLuigi Rizzo 17617885a7bSLuigi Rizzo #define NS_BUF_CHANGED 0x0001 /* buf_idx changed */ 17717885a7bSLuigi Rizzo /* 17817885a7bSLuigi Rizzo * must be set whenever buf_idx is changed (as it might be 17917885a7bSLuigi Rizzo * necessary to recompute the physical address and mapping) 180847bf383SLuigi Rizzo * 181847bf383SLuigi Rizzo * It is also set by the kernel whenever the buf_idx is 182847bf383SLuigi Rizzo * changed internally (e.g., by pipes). Applications may 183847bf383SLuigi Rizzo * use this information to know when they can reuse the 184847bf383SLuigi Rizzo * contents of previously prepared buffers. 18517885a7bSLuigi Rizzo */ 18617885a7bSLuigi Rizzo 18717885a7bSLuigi Rizzo #define NS_REPORT 0x0002 /* ask the hardware to report results */ 18817885a7bSLuigi Rizzo /* 18917885a7bSLuigi Rizzo * Request notification when slot is used by the hardware. 19017885a7bSLuigi Rizzo * Normally transmit completions are handled lazily and 19117885a7bSLuigi Rizzo * may be unreported. This flag lets us know when a slot 19217885a7bSLuigi Rizzo * has been sent (e.g. to terminate the sender). 19317885a7bSLuigi Rizzo */ 19417885a7bSLuigi Rizzo 19517885a7bSLuigi Rizzo #define NS_FORWARD 0x0004 /* pass packet 'forward' */ 19617885a7bSLuigi Rizzo /* 19717885a7bSLuigi Rizzo * (Only for physical ports, rx rings with NR_FORWARD set). 19817885a7bSLuigi Rizzo * Slot released to the kernel (i.e. before ring->head) with 19917885a7bSLuigi Rizzo * this flag set are passed to the peer ring (host/NIC), 20017885a7bSLuigi Rizzo * thus restoring the host-NIC connection for these slots. 20117885a7bSLuigi Rizzo * This supports efficient traffic monitoring or firewalling. 20217885a7bSLuigi Rizzo */ 20317885a7bSLuigi Rizzo 20417885a7bSLuigi Rizzo #define NS_NO_LEARN 0x0008 /* disable bridge learning */ 20517885a7bSLuigi Rizzo /* 20617885a7bSLuigi Rizzo * On a VALE switch, do not 'learn' the source port for 20717885a7bSLuigi Rizzo * this buffer. 20817885a7bSLuigi Rizzo */ 20917885a7bSLuigi Rizzo 21017885a7bSLuigi Rizzo #define NS_INDIRECT 0x0010 /* userspace buffer */ 21117885a7bSLuigi Rizzo /* 21217885a7bSLuigi Rizzo * (VALE tx rings only) data is in a userspace buffer, 21317885a7bSLuigi Rizzo * whose address is in the 'ptr' field in the slot. 21417885a7bSLuigi Rizzo */ 21517885a7bSLuigi Rizzo 21617885a7bSLuigi Rizzo #define NS_MOREFRAG 0x0020 /* packet has more fragments */ 21717885a7bSLuigi Rizzo /* 21817885a7bSLuigi Rizzo * (VALE ports only) 21917885a7bSLuigi Rizzo * Set on all but the last slot of a multi-segment packet. 22017885a7bSLuigi Rizzo * The 'len' field refers to the individual fragment. 22117885a7bSLuigi Rizzo */ 22217885a7bSLuigi Rizzo 22317885a7bSLuigi Rizzo #define NS_PORT_SHIFT 8 22417885a7bSLuigi Rizzo #define NS_PORT_MASK (0xff << NS_PORT_SHIFT) 22517885a7bSLuigi Rizzo /* 22617885a7bSLuigi Rizzo * The high 8 bits of the flag, if not zero, indicate the 22701c039a1SLuigi Rizzo * destination port for the VALE switch, overriding 22801c039a1SLuigi Rizzo * the lookup table. 22968b8534bSLuigi Rizzo */ 23001c039a1SLuigi Rizzo 23117885a7bSLuigi Rizzo #define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff) 232ce3ee1e7SLuigi Rizzo /* 23317885a7bSLuigi Rizzo * (VALE rx rings only) the high 8 bits 234ce3ee1e7SLuigi Rizzo * are the number of fragments. 235ce3ee1e7SLuigi Rizzo */ 23617885a7bSLuigi Rizzo 23768b8534bSLuigi Rizzo 23868b8534bSLuigi Rizzo /* 239ce3ee1e7SLuigi Rizzo * struct netmap_ring 240ce3ee1e7SLuigi Rizzo * 24168b8534bSLuigi Rizzo * Netmap representation of a TX or RX ring (also known as "queue"). 24268b8534bSLuigi Rizzo * This is a queue implemented as a fixed-size circular array. 24317885a7bSLuigi Rizzo * At the software level the important fields are: head, cur, tail. 24468b8534bSLuigi Rizzo * 24568b8534bSLuigi Rizzo * In TX rings: 246ce3ee1e7SLuigi Rizzo * 24717885a7bSLuigi Rizzo * head first slot available for transmission. 24817885a7bSLuigi Rizzo * cur wakeup point. select() and poll() will unblock 24917885a7bSLuigi Rizzo * when 'tail' moves past 'cur' 25017885a7bSLuigi Rizzo * tail (readonly) first slot reserved to the kernel 251ce3ee1e7SLuigi Rizzo * 25217885a7bSLuigi Rizzo * [head .. tail-1] can be used for new packets to send; 25317885a7bSLuigi Rizzo * 'head' and 'cur' must be incremented as slots are filled 25417885a7bSLuigi Rizzo * with new packets to be sent; 25517885a7bSLuigi Rizzo * 'cur' can be moved further ahead if we need more space 2565c8c1004SLuigi Rizzo * for new transmissions. XXX todo (2014-03-12) 25768b8534bSLuigi Rizzo * 25868b8534bSLuigi Rizzo * In RX rings: 259ce3ee1e7SLuigi Rizzo * 26017885a7bSLuigi Rizzo * head first valid received packet 26117885a7bSLuigi Rizzo * cur wakeup point. select() and poll() will unblock 26217885a7bSLuigi Rizzo * when 'tail' moves past 'cur' 26317885a7bSLuigi Rizzo * tail (readonly) first slot reserved to the kernel 264ce3ee1e7SLuigi Rizzo * 26517885a7bSLuigi Rizzo * [head .. tail-1] contain received packets; 26617885a7bSLuigi Rizzo * 'head' and 'cur' must be incremented as slots are consumed 26717885a7bSLuigi Rizzo * and can be returned to the kernel; 26817885a7bSLuigi Rizzo * 'cur' can be moved further ahead if we want to wait for 26917885a7bSLuigi Rizzo * new packets without returning the previous ones. 27068b8534bSLuigi Rizzo * 27168b8534bSLuigi Rizzo * DATA OWNERSHIP/LOCKING: 27217885a7bSLuigi Rizzo * The netmap_ring, and all slots and buffers in the range 27317885a7bSLuigi Rizzo * [head .. tail-1] are owned by the user program; 27417885a7bSLuigi Rizzo * the kernel only accesses them during a netmap system call 27517885a7bSLuigi Rizzo * and in the user thread context. 27601c039a1SLuigi Rizzo * 27717885a7bSLuigi Rizzo * Other slots and buffers are reserved for use by the kernel 27868b8534bSLuigi Rizzo */ 27968b8534bSLuigi Rizzo struct netmap_ring { 28068b8534bSLuigi Rizzo /* 281ce3ee1e7SLuigi Rizzo * buf_ofs is meant to be used through macros. 28268b8534bSLuigi Rizzo * It contains the offset of the buffer region from this 28368b8534bSLuigi Rizzo * descriptor. 28468b8534bSLuigi Rizzo */ 28517885a7bSLuigi Rizzo const int64_t buf_ofs; 28668b8534bSLuigi Rizzo const uint32_t num_slots; /* number of slots in the ring. */ 28717885a7bSLuigi Rizzo const uint32_t nr_buf_size; 28817885a7bSLuigi Rizzo const uint16_t ringid; 28917885a7bSLuigi Rizzo const uint16_t dir; /* 0: tx, 1: rx */ 29068b8534bSLuigi Rizzo 29117885a7bSLuigi Rizzo uint32_t head; /* (u) first user slot */ 29217885a7bSLuigi Rizzo uint32_t cur; /* (u) wakeup point */ 29317885a7bSLuigi Rizzo uint32_t tail; /* (k) first kernel slot */ 29468b8534bSLuigi Rizzo 29517885a7bSLuigi Rizzo uint32_t flags; 29617885a7bSLuigi Rizzo 29717885a7bSLuigi Rizzo struct timeval ts; /* (k) time of last *sync() */ 29817885a7bSLuigi Rizzo 29917885a7bSLuigi Rizzo /* opaque room for a mutex or similar object */ 300*37e3a6d3SLuigi Rizzo #if !defined(_WIN32) || defined(__CYGWIN__) 301*37e3a6d3SLuigi Rizzo uint8_t __attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128]; 302*37e3a6d3SLuigi Rizzo #else 303*37e3a6d3SLuigi Rizzo uint8_t __declspec(align(NM_CACHE_ALIGN)) sem[128]; 304*37e3a6d3SLuigi Rizzo #endif 30568b8534bSLuigi Rizzo 30668b8534bSLuigi Rizzo /* the slots follow. This struct has variable size */ 30768b8534bSLuigi Rizzo struct netmap_slot slot[0]; /* array of slots. */ 30868b8534bSLuigi Rizzo }; 30968b8534bSLuigi Rizzo 31068b8534bSLuigi Rizzo 31168b8534bSLuigi Rizzo /* 31217885a7bSLuigi Rizzo * RING FLAGS 31317885a7bSLuigi Rizzo */ 31417885a7bSLuigi Rizzo #define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */ 31517885a7bSLuigi Rizzo /* 31617885a7bSLuigi Rizzo * updates the 'ts' field on each netmap syscall. This saves 31717885a7bSLuigi Rizzo * saves a separate gettimeofday(), and is not much worse than 31817885a7bSLuigi Rizzo * software timestamps generated in the interrupt handler. 31917885a7bSLuigi Rizzo */ 32017885a7bSLuigi Rizzo 32117885a7bSLuigi Rizzo #define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */ 32217885a7bSLuigi Rizzo /* 32317885a7bSLuigi Rizzo * Enables the NS_FORWARD slot flag for the ring. 32417885a7bSLuigi Rizzo */ 32517885a7bSLuigi Rizzo 32617885a7bSLuigi Rizzo 32717885a7bSLuigi Rizzo /* 32868b8534bSLuigi Rizzo * Netmap representation of an interface and its queue(s). 329ce3ee1e7SLuigi Rizzo * This is initialized by the kernel when binding a file 330ce3ee1e7SLuigi Rizzo * descriptor to a port, and should be considered as readonly 331ce3ee1e7SLuigi Rizzo * by user programs. The kernel never uses it. 332ce3ee1e7SLuigi Rizzo * 33368b8534bSLuigi Rizzo * There is one netmap_if for each file descriptor on which we want 334ce3ee1e7SLuigi Rizzo * to select/poll. 33568b8534bSLuigi Rizzo * select/poll operates on one or all pairs depending on the value of 33668b8534bSLuigi Rizzo * nmr_queueid passed on the ioctl. 33768b8534bSLuigi Rizzo */ 33868b8534bSLuigi Rizzo struct netmap_if { 33968b8534bSLuigi Rizzo char ni_name[IFNAMSIZ]; /* name of the interface. */ 340ce3ee1e7SLuigi Rizzo const uint32_t ni_version; /* API version, currently unused */ 341ce3ee1e7SLuigi Rizzo const uint32_t ni_flags; /* properties */ 342ce3ee1e7SLuigi Rizzo #define NI_PRIV_MEM 0x1 /* private memory region */ 343ce3ee1e7SLuigi Rizzo 34417885a7bSLuigi Rizzo /* 34517885a7bSLuigi Rizzo * The number of packet rings available in netmap mode. 34617885a7bSLuigi Rizzo * Physical NICs can have different numbers of tx and rx rings. 34717885a7bSLuigi Rizzo * Physical NICs also have a 'host' ring pair. 34817885a7bSLuigi Rizzo * Additionally, clients can request additional ring pairs to 34917885a7bSLuigi Rizzo * be used for internal communication. 35017885a7bSLuigi Rizzo */ 35117885a7bSLuigi Rizzo const uint32_t ni_tx_rings; /* number of HW tx rings */ 35217885a7bSLuigi Rizzo const uint32_t ni_rx_rings; /* number of HW rx rings */ 35317885a7bSLuigi Rizzo 354f0ea3689SLuigi Rizzo uint32_t ni_bufs_head; /* head index for extra bufs */ 355f0ea3689SLuigi Rizzo uint32_t ni_spare1[5]; 35668b8534bSLuigi Rizzo /* 35764ae02c3SLuigi Rizzo * The following array contains the offset of each netmap ring 35817885a7bSLuigi Rizzo * from this structure, in the following order: 35917885a7bSLuigi Rizzo * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings; 36017885a7bSLuigi Rizzo * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings. 36117885a7bSLuigi Rizzo * 362ce3ee1e7SLuigi Rizzo * The area is filled up by the kernel on NIOCREGIF, 36368b8534bSLuigi Rizzo * and then only read by userspace code. 36468b8534bSLuigi Rizzo */ 36568b8534bSLuigi Rizzo const ssize_t ring_ofs[0]; 36668b8534bSLuigi Rizzo }; 36768b8534bSLuigi Rizzo 36817885a7bSLuigi Rizzo 36968b8534bSLuigi Rizzo #ifndef NIOCREGIF 37068b8534bSLuigi Rizzo /* 37168b8534bSLuigi Rizzo * ioctl names and related fields 37268b8534bSLuigi Rizzo * 37317885a7bSLuigi Rizzo * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues, 37417885a7bSLuigi Rizzo * whose identity is set in NIOCREGIF through nr_ringid. 37517885a7bSLuigi Rizzo * These are non blocking and take no argument. 37617885a7bSLuigi Rizzo * 37768b8534bSLuigi Rizzo * NIOCGINFO takes a struct ifreq, the interface name is the input, 37868b8534bSLuigi Rizzo * the outputs are number of queues and number of descriptor 37968b8534bSLuigi Rizzo * for each queue (useful to set number of threads etc.). 380ce3ee1e7SLuigi Rizzo * The info returned is only advisory and may change before 381ce3ee1e7SLuigi Rizzo * the interface is bound to a file descriptor. 38268b8534bSLuigi Rizzo * 38317885a7bSLuigi Rizzo * NIOCREGIF takes an interface name within a struct nmre, 38468b8534bSLuigi Rizzo * and activates netmap mode on the interface (if possible). 38568b8534bSLuigi Rizzo * 38617885a7bSLuigi Rizzo * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we 38717885a7bSLuigi Rizzo * can pass it down to other NIC-related ioctls. 388f18be576SLuigi Rizzo * 38917885a7bSLuigi Rizzo * The actual argument (struct nmreq) has a number of options to request 39017885a7bSLuigi Rizzo * different functions. 391f0ea3689SLuigi Rizzo * The following are used in NIOCREGIF when nr_cmd == 0: 392f18be576SLuigi Rizzo * 39317885a7bSLuigi Rizzo * nr_name (in) 39417885a7bSLuigi Rizzo * The name of the port (em0, valeXXX:YYY, etc.) 39517885a7bSLuigi Rizzo * limited to IFNAMSIZ for backward compatibility. 396ce3ee1e7SLuigi Rizzo * 39717885a7bSLuigi Rizzo * nr_version (in/out) 39817885a7bSLuigi Rizzo * Must match NETMAP_API as used in the kernel, error otherwise. 39917885a7bSLuigi Rizzo * Always returns the desired value on output. 40017885a7bSLuigi Rizzo * 40117885a7bSLuigi Rizzo * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out) 40217885a7bSLuigi Rizzo * On input, non-zero values may be used to reconfigure the port 40317885a7bSLuigi Rizzo * according to the requested values, but this is not guaranteed. 40417885a7bSLuigi Rizzo * On output the actual values in use are reported. 40517885a7bSLuigi Rizzo * 40617885a7bSLuigi Rizzo * nr_ringid (in) 40717885a7bSLuigi Rizzo * Indicates how rings should be bound to the file descriptors. 408f0ea3689SLuigi Rizzo * If nr_flags != 0, then the low bits (in NETMAP_RING_MASK) 409f0ea3689SLuigi Rizzo * are used to indicate the ring number, and nr_flags specifies 410f0ea3689SLuigi Rizzo * the actual rings to bind. NETMAP_NO_TX_POLL is unaffected. 411f0ea3689SLuigi Rizzo * 412f0ea3689SLuigi Rizzo * NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED: 413f0ea3689SLuigi Rizzo * If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control 414f0ea3689SLuigi Rizzo * the binding as follows: 41517885a7bSLuigi Rizzo * 0 (default) binds all physical rings 41617885a7bSLuigi Rizzo * NETMAP_HW_RING | ring number binds a single ring pair 417ce3ee1e7SLuigi Rizzo * NETMAP_SW_RING binds only the host tx/rx rings 418ce3ee1e7SLuigi Rizzo * 41917885a7bSLuigi Rizzo * NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push 42017885a7bSLuigi Rizzo * packets on tx rings only if POLLOUT is set. 42117885a7bSLuigi Rizzo * The default is to push any pending packet. 422ce3ee1e7SLuigi Rizzo * 423f0ea3689SLuigi Rizzo * NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release 424f0ea3689SLuigi Rizzo * packets on rx rings also when POLLIN is NOT set. 425f0ea3689SLuigi Rizzo * The default is to touch the rx ring only with POLLIN. 426f0ea3689SLuigi Rizzo * Note that this is the opposite of TX because it 427f0ea3689SLuigi Rizzo * reflects the common usage. 428f0ea3689SLuigi Rizzo * 429f0ea3689SLuigi Rizzo * NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead. 430f0ea3689SLuigi Rizzo * NETMAP_PRIV_MEM is set on return for ports that do not use 431f0ea3689SLuigi Rizzo * the global memory allocator. 432f0ea3689SLuigi Rizzo * This information is not significant and applications 433f0ea3689SLuigi Rizzo * should look at the region id in nr_arg2 434f0ea3689SLuigi Rizzo * 435f0ea3689SLuigi Rizzo * nr_flags is the recommended mode to indicate which rings should 436f0ea3689SLuigi Rizzo * be bound to a file descriptor. Values are NR_REG_* 437f0ea3689SLuigi Rizzo * 438f0ea3689SLuigi Rizzo * nr_arg1 (in) The number of extra rings to be reserved. 439f0ea3689SLuigi Rizzo * Especially when allocating a VALE port the system only 440f0ea3689SLuigi Rizzo * allocates the amount of memory needed for the port. 441f0ea3689SLuigi Rizzo * If more shared memory rings are desired (e.g. for pipes), 442f0ea3689SLuigi Rizzo * the first invocation for the same basename/allocator 443f0ea3689SLuigi Rizzo * should specify a suitable number. Memory cannot be 444f0ea3689SLuigi Rizzo * extended after the first allocation without closing 445f0ea3689SLuigi Rizzo * all ports on the same region. 446f0ea3689SLuigi Rizzo * 447f0ea3689SLuigi Rizzo * nr_arg2 (in/out) The identity of the memory region used. 448f0ea3689SLuigi Rizzo * On input, 0 means the system decides autonomously, 449f0ea3689SLuigi Rizzo * other values may try to select a specific region. 450f0ea3689SLuigi Rizzo * On return the actual value is reported. 451f0ea3689SLuigi Rizzo * Region '1' is the global allocator, normally shared 452f0ea3689SLuigi Rizzo * by all interfaces. Other values are private regions. 453f0ea3689SLuigi Rizzo * If two ports the same region zero-copy is possible. 454f0ea3689SLuigi Rizzo * 455f0ea3689SLuigi Rizzo * nr_arg3 (in/out) number of extra buffers to be allocated. 456f0ea3689SLuigi Rizzo * 457f0ea3689SLuigi Rizzo * 458ce3ee1e7SLuigi Rizzo * 45917885a7bSLuigi Rizzo * nr_cmd (in) if non-zero indicates a special command: 46017885a7bSLuigi Rizzo * NETMAP_BDG_ATTACH and nr_name = vale*:ifname 46117885a7bSLuigi Rizzo * attaches the NIC to the switch; nr_ringid specifies 46217885a7bSLuigi Rizzo * which rings to use. Used by vale-ctl -a ... 46317885a7bSLuigi Rizzo * nr_arg1 = NETMAP_BDG_HOST also attaches the host port 46417885a7bSLuigi Rizzo * as in vale-ctl -h ... 465ce3ee1e7SLuigi Rizzo * 46617885a7bSLuigi Rizzo * NETMAP_BDG_DETACH and nr_name = vale*:ifname 46717885a7bSLuigi Rizzo * disconnects a previously attached NIC. 46817885a7bSLuigi Rizzo * Used by vale-ctl -d ... 469ce3ee1e7SLuigi Rizzo * 47017885a7bSLuigi Rizzo * NETMAP_BDG_LIST 47117885a7bSLuigi Rizzo * list the configuration of VALE switches. 47268b8534bSLuigi Rizzo * 473f0ea3689SLuigi Rizzo * NETMAP_BDG_VNET_HDR 474f0ea3689SLuigi Rizzo * Set the virtio-net header length used by the client 475f0ea3689SLuigi Rizzo * of a VALE switch port. 476f18be576SLuigi Rizzo * 4774bf50f18SLuigi Rizzo * NETMAP_BDG_NEWIF 4784bf50f18SLuigi Rizzo * create a persistent VALE port with name nr_name. 4794bf50f18SLuigi Rizzo * Used by vale-ctl -n ... 4804bf50f18SLuigi Rizzo * 4814bf50f18SLuigi Rizzo * NETMAP_BDG_DELIF 4824bf50f18SLuigi Rizzo * delete a persistent VALE port. Used by vale-ctl -d ... 4834bf50f18SLuigi Rizzo * 484f0ea3689SLuigi Rizzo * nr_arg1, nr_arg2, nr_arg3 (in/out) command specific 485f0ea3689SLuigi Rizzo * 486f0ea3689SLuigi Rizzo * 48717885a7bSLuigi Rizzo * 48868b8534bSLuigi Rizzo */ 48968b8534bSLuigi Rizzo 49017885a7bSLuigi Rizzo 49168b8534bSLuigi Rizzo /* 492f0ea3689SLuigi Rizzo * struct nmreq overlays a struct ifreq (just the name) 49368b8534bSLuigi Rizzo */ 49468b8534bSLuigi Rizzo struct nmreq { 49568b8534bSLuigi Rizzo char nr_name[IFNAMSIZ]; 49664ae02c3SLuigi Rizzo uint32_t nr_version; /* API version */ 49768b8534bSLuigi Rizzo uint32_t nr_offset; /* nifp offset in the shared region */ 49868b8534bSLuigi Rizzo uint32_t nr_memsize; /* size of the shared region */ 49964ae02c3SLuigi Rizzo uint32_t nr_tx_slots; /* slots in tx rings */ 50064ae02c3SLuigi Rizzo uint32_t nr_rx_slots; /* slots in rx rings */ 50164ae02c3SLuigi Rizzo uint16_t nr_tx_rings; /* number of tx rings */ 50264ae02c3SLuigi Rizzo uint16_t nr_rx_rings; /* number of rx rings */ 503f0ea3689SLuigi Rizzo 50468b8534bSLuigi Rizzo uint16_t nr_ringid; /* ring(s) we care about */ 505f0ea3689SLuigi Rizzo #define NETMAP_HW_RING 0x4000 /* single NIC ring pair */ 506f0ea3689SLuigi Rizzo #define NETMAP_SW_RING 0x2000 /* only host ring pair */ 507f0ea3689SLuigi Rizzo 508f0ea3689SLuigi Rizzo #define NETMAP_RING_MASK 0x0fff /* the ring number */ 509f0ea3689SLuigi Rizzo 51064ae02c3SLuigi Rizzo #define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */ 511f0ea3689SLuigi Rizzo 512f0ea3689SLuigi Rizzo #define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */ 51317885a7bSLuigi Rizzo 514f18be576SLuigi Rizzo uint16_t nr_cmd; 515f18be576SLuigi Rizzo #define NETMAP_BDG_ATTACH 1 /* attach the NIC */ 516f18be576SLuigi Rizzo #define NETMAP_BDG_DETACH 2 /* detach the NIC */ 5174bf50f18SLuigi Rizzo #define NETMAP_BDG_REGOPS 3 /* register bridge callbacks */ 518f18be576SLuigi Rizzo #define NETMAP_BDG_LIST 4 /* get bridge's info */ 519f0ea3689SLuigi Rizzo #define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */ 520f0ea3689SLuigi Rizzo #define NETMAP_BDG_OFFSET NETMAP_BDG_VNET_HDR /* deprecated alias */ 5214bf50f18SLuigi Rizzo #define NETMAP_BDG_NEWIF 6 /* create a virtual port */ 5224bf50f18SLuigi Rizzo #define NETMAP_BDG_DELIF 7 /* destroy a virtual port */ 523*37e3a6d3SLuigi Rizzo #define NETMAP_PT_HOST_CREATE 8 /* create ptnetmap kthreads */ 524*37e3a6d3SLuigi Rizzo #define NETMAP_PT_HOST_DELETE 9 /* delete ptnetmap kthreads */ 525*37e3a6d3SLuigi Rizzo #define NETMAP_BDG_POLLING_ON 10 /* delete polling kthread */ 526*37e3a6d3SLuigi Rizzo #define NETMAP_BDG_POLLING_OFF 11 /* delete polling kthread */ 527*37e3a6d3SLuigi Rizzo #define NETMAP_VNET_HDR_GET 12 /* get the port virtio-net-hdr length */ 528f0ea3689SLuigi Rizzo uint16_t nr_arg1; /* reserve extra rings in NIOCREGIF */ 529f18be576SLuigi Rizzo #define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */ 53017885a7bSLuigi Rizzo 531f18be576SLuigi Rizzo uint16_t nr_arg2; 532f0ea3689SLuigi Rizzo uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */ 533f0ea3689SLuigi Rizzo uint32_t nr_flags; 534f0ea3689SLuigi Rizzo /* various modes, extends nr_ringid */ 535f0ea3689SLuigi Rizzo uint32_t spare2[1]; 53668b8534bSLuigi Rizzo }; 53768b8534bSLuigi Rizzo 538f0ea3689SLuigi Rizzo #define NR_REG_MASK 0xf /* values for nr_flags */ 539f0ea3689SLuigi Rizzo enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */ 540f0ea3689SLuigi Rizzo NR_REG_ALL_NIC = 1, 541f0ea3689SLuigi Rizzo NR_REG_SW = 2, 542f0ea3689SLuigi Rizzo NR_REG_NIC_SW = 3, 543f0ea3689SLuigi Rizzo NR_REG_ONE_NIC = 4, 544f0ea3689SLuigi Rizzo NR_REG_PIPE_MASTER = 5, 545f0ea3689SLuigi Rizzo NR_REG_PIPE_SLAVE = 6, 546f0ea3689SLuigi Rizzo }; 547f0ea3689SLuigi Rizzo /* monitor uses the NR_REG to select the rings to monitor */ 548f0ea3689SLuigi Rizzo #define NR_MONITOR_TX 0x100 549f0ea3689SLuigi Rizzo #define NR_MONITOR_RX 0x200 550847bf383SLuigi Rizzo #define NR_ZCOPY_MON 0x400 551847bf383SLuigi Rizzo /* request exclusive access to the selected rings */ 552847bf383SLuigi Rizzo #define NR_EXCLUSIVE 0x800 553*37e3a6d3SLuigi Rizzo /* request ptnetmap host support */ 554*37e3a6d3SLuigi Rizzo #define NR_PASSTHROUGH_HOST NR_PTNETMAP_HOST /* deprecated */ 555*37e3a6d3SLuigi Rizzo #define NR_PTNETMAP_HOST 0x1000 556*37e3a6d3SLuigi Rizzo #define NR_RX_RINGS_ONLY 0x2000 557*37e3a6d3SLuigi Rizzo #define NR_TX_RINGS_ONLY 0x4000 558*37e3a6d3SLuigi Rizzo /* Applications set this flag if they are able to deal with virtio-net headers, 559*37e3a6d3SLuigi Rizzo * that is send/receive frames that start with a virtio-net header. 560*37e3a6d3SLuigi Rizzo * If not set, NIOCREGIF will fail with netmap ports that require applications 561*37e3a6d3SLuigi Rizzo * to use those headers. If the flag is set, the application can use the 562*37e3a6d3SLuigi Rizzo * NETMAP_VNET_HDR_GET command to figure out the header length. */ 563*37e3a6d3SLuigi Rizzo #define NR_ACCEPT_VNET_HDR 0x8000 564f0ea3689SLuigi Rizzo 565*37e3a6d3SLuigi Rizzo #define NM_BDG_NAME "vale" /* prefix for bridge port name */ 566*37e3a6d3SLuigi Rizzo 567*37e3a6d3SLuigi Rizzo /* 568*37e3a6d3SLuigi Rizzo * Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined 569*37e3a6d3SLuigi Rizzo * in ws2def.h but not sure if they are in the form we need. 570*37e3a6d3SLuigi Rizzo * XXX so we redefine them 571*37e3a6d3SLuigi Rizzo * in a convenient way to use for DeviceIoControl signatures 572*37e3a6d3SLuigi Rizzo */ 573*37e3a6d3SLuigi Rizzo #ifdef _WIN32 574*37e3a6d3SLuigi Rizzo #undef _IO // ws2def.h 575*37e3a6d3SLuigi Rizzo #define _WIN_NM_IOCTL_TYPE 40000 576*37e3a6d3SLuigi Rizzo #define _IO(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \ 577*37e3a6d3SLuigi Rizzo METHOD_BUFFERED, FILE_ANY_ACCESS ) 578*37e3a6d3SLuigi Rizzo #define _IO_direct(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \ 579*37e3a6d3SLuigi Rizzo METHOD_OUT_DIRECT, FILE_ANY_ACCESS ) 580*37e3a6d3SLuigi Rizzo 581*37e3a6d3SLuigi Rizzo #define _IOWR(_c, _n, _s) _IO(_c, _n) 582*37e3a6d3SLuigi Rizzo 583*37e3a6d3SLuigi Rizzo /* We havesome internal sysctl in addition to the externally visible ones */ 584*37e3a6d3SLuigi Rizzo #define NETMAP_MMAP _IO_direct('i', 160) // note METHOD_OUT_DIRECT 585*37e3a6d3SLuigi Rizzo #define NETMAP_POLL _IO('i', 162) 586*37e3a6d3SLuigi Rizzo 587*37e3a6d3SLuigi Rizzo /* and also two setsockopt for sysctl emulation */ 588*37e3a6d3SLuigi Rizzo #define NETMAP_SETSOCKOPT _IO('i', 140) 589*37e3a6d3SLuigi Rizzo #define NETMAP_GETSOCKOPT _IO('i', 141) 590*37e3a6d3SLuigi Rizzo 591*37e3a6d3SLuigi Rizzo 592*37e3a6d3SLuigi Rizzo //These linknames are for the Netmap Core Driver 593*37e3a6d3SLuigi Rizzo #define NETMAP_NT_DEVICE_NAME L"\\Device\\NETMAP" 594*37e3a6d3SLuigi Rizzo #define NETMAP_DOS_DEVICE_NAME L"\\DosDevices\\netmap" 595*37e3a6d3SLuigi Rizzo 596*37e3a6d3SLuigi Rizzo //Definition of a structure used to pass a virtual address within an IOCTL 597*37e3a6d3SLuigi Rizzo typedef struct _MEMORY_ENTRY { 598*37e3a6d3SLuigi Rizzo PVOID pUsermodeVirtualAddress; 599*37e3a6d3SLuigi Rizzo } MEMORY_ENTRY, *PMEMORY_ENTRY; 600*37e3a6d3SLuigi Rizzo 601*37e3a6d3SLuigi Rizzo typedef struct _POLL_REQUEST_DATA { 602*37e3a6d3SLuigi Rizzo int events; 603*37e3a6d3SLuigi Rizzo int timeout; 604*37e3a6d3SLuigi Rizzo int revents; 605*37e3a6d3SLuigi Rizzo } POLL_REQUEST_DATA; 606*37e3a6d3SLuigi Rizzo 607*37e3a6d3SLuigi Rizzo #endif /* _WIN32 */ 60817885a7bSLuigi Rizzo 60964ae02c3SLuigi Rizzo /* 61064ae02c3SLuigi Rizzo * FreeBSD uses the size value embedded in the _IOWR to determine 61164ae02c3SLuigi Rizzo * how much to copy in/out. So we need it to match the actual 61264ae02c3SLuigi Rizzo * data structure we pass. We put some spares in the structure 61364ae02c3SLuigi Rizzo * to ease compatibility with other versions 61464ae02c3SLuigi Rizzo */ 61568b8534bSLuigi Rizzo #define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */ 61668b8534bSLuigi Rizzo #define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */ 61768b8534bSLuigi Rizzo #define NIOCTXSYNC _IO('i', 148) /* sync tx queues */ 61868b8534bSLuigi Rizzo #define NIOCRXSYNC _IO('i', 149) /* sync rx queues */ 6194bf50f18SLuigi Rizzo #define NIOCCONFIG _IOWR('i',150, struct nm_ifreq) /* for ext. modules */ 62068b8534bSLuigi Rizzo #endif /* !NIOCREGIF */ 62168b8534bSLuigi Rizzo 62217885a7bSLuigi Rizzo 62317885a7bSLuigi Rizzo /* 62417885a7bSLuigi Rizzo * Helper functions for kernel and userspace 62517885a7bSLuigi Rizzo */ 62617885a7bSLuigi Rizzo 62717885a7bSLuigi Rizzo /* 62817885a7bSLuigi Rizzo * check if space is available in the ring. 62917885a7bSLuigi Rizzo */ 63017885a7bSLuigi Rizzo static inline int 63117885a7bSLuigi Rizzo nm_ring_empty(struct netmap_ring *ring) 63217885a7bSLuigi Rizzo { 63317885a7bSLuigi Rizzo return (ring->cur == ring->tail); 63417885a7bSLuigi Rizzo } 63517885a7bSLuigi Rizzo 6364bf50f18SLuigi Rizzo /* 6374bf50f18SLuigi Rizzo * Opaque structure that is passed to an external kernel 6384bf50f18SLuigi Rizzo * module via ioctl(fd, NIOCCONFIG, req) for a user-owned 6394bf50f18SLuigi Rizzo * bridge port (at this point ephemeral VALE interface). 6404bf50f18SLuigi Rizzo */ 6414bf50f18SLuigi Rizzo #define NM_IFRDATA_LEN 256 6424bf50f18SLuigi Rizzo struct nm_ifreq { 6434bf50f18SLuigi Rizzo char nifr_name[IFNAMSIZ]; 6444bf50f18SLuigi Rizzo char data[NM_IFRDATA_LEN]; 6454bf50f18SLuigi Rizzo }; 6464bf50f18SLuigi Rizzo 647*37e3a6d3SLuigi Rizzo /* 648*37e3a6d3SLuigi Rizzo * netmap kernel thread configuration 649*37e3a6d3SLuigi Rizzo */ 650*37e3a6d3SLuigi Rizzo /* bhyve/vmm.ko MSIX parameters for IOCTL */ 651*37e3a6d3SLuigi Rizzo struct ptn_vmm_ioctl_msix { 652*37e3a6d3SLuigi Rizzo uint64_t msg; 653*37e3a6d3SLuigi Rizzo uint64_t addr; 654*37e3a6d3SLuigi Rizzo }; 655*37e3a6d3SLuigi Rizzo 656*37e3a6d3SLuigi Rizzo /* IOCTL parameters */ 657*37e3a6d3SLuigi Rizzo struct nm_kth_ioctl { 658*37e3a6d3SLuigi Rizzo u_long com; 659*37e3a6d3SLuigi Rizzo /* TODO: use union */ 660*37e3a6d3SLuigi Rizzo union { 661*37e3a6d3SLuigi Rizzo struct ptn_vmm_ioctl_msix msix; 662*37e3a6d3SLuigi Rizzo } data; 663*37e3a6d3SLuigi Rizzo }; 664*37e3a6d3SLuigi Rizzo 665*37e3a6d3SLuigi Rizzo /* Configuration of a ptnetmap ring */ 666*37e3a6d3SLuigi Rizzo struct ptnet_ring_cfg { 667*37e3a6d3SLuigi Rizzo uint64_t ioeventfd; /* eventfd in linux, tsleep() parameter in FreeBSD */ 668*37e3a6d3SLuigi Rizzo uint64_t irqfd; /* eventfd in linux, ioctl fd in FreeBSD */ 669*37e3a6d3SLuigi Rizzo struct nm_kth_ioctl ioctl; /* ioctl parameter to send irq (only used in bhyve/FreeBSD) */ 670*37e3a6d3SLuigi Rizzo }; 67168b8534bSLuigi Rizzo #endif /* _NET_NETMAP_H_ */ 672