1fe267a55SPedro F. Giffuni /*- 2fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3fe267a55SPedro 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 44d12354a5SVincenzo Maffione #define NETMAP_API 14 /* current API version */ 4517885a7bSLuigi Rizzo 46d12354a5SVincenzo Maffione #define NETMAP_MIN_API 14 /* 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 | 72d12354a5SVincenzo Maffione +----------------+ / | other fields | 7317885a7bSLuigi Rizzo | ni_tx_rings | / +===============+ 74ce3ee1e7SLuigi Rizzo | ni_rx_rings | / | buf_idx, len | slot[0] 75ce3ee1e7SLuigi Rizzo | | / | flags, ptr | 7617885a7bSLuigi Rizzo | | / +---------------+ 77d12354a5SVincenzo Maffione +================+ / | buf_idx, len | slot[1] 78ce3ee1e7SLuigi Rizzo | txring_ofs[0] | (rel.to nifp)--' | flags, ptr | 7917885a7bSLuigi Rizzo | txring_ofs[1] | +---------------+ 80d12354a5SVincenzo Maffione (tx+htx entries) (num_slots entries) 81ce3ee1e7SLuigi Rizzo | txring_ofs[t] | | buf_idx, len | slot[n-1] 82d12354a5SVincenzo Maffione +----------------+ | flags, ptr | 8317885a7bSLuigi Rizzo | rxring_ofs[0] | +---------------+ 8468b8534bSLuigi Rizzo | rxring_ofs[1] | 85d12354a5SVincenzo Maffione (rx+hrx entries) 86ce3ee1e7SLuigi Rizzo | rxring_ofs[r] | 87d12354a5SVincenzo Maffione +----------------+ 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 * 93d12354a5SVincenzo Maffione * There is one netmap_ring per physical NIC ring, plus at least one tx/rx ring 94d12354a5SVincenzo Maffione * pair attached to the host stack (these pairs are 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 attach to PIPE rings sharing the same memory 121f0ea3689SLuigi Rizzo * space with a parent device. The ifname indicates the parent device, 122f0ea3689SLuigi Rizzo * which must already exist. Flags in nr_flags indicate if we want to 123f0ea3689SLuigi Rizzo * bind the master or slave side, the index (from nr_ringid) 1245c8c1004SLuigi Rizzo * is just a cookie and does not need to be sequential. 125f0ea3689SLuigi Rizzo * 126f0ea3689SLuigi Rizzo * + NIOCREGIF can also attach to 'monitor' rings that replicate 127f0ea3689SLuigi Rizzo * the content of specific rings, also from the same memory space. 128f0ea3689SLuigi Rizzo * 129f0ea3689SLuigi Rizzo * Extra flags in nr_flags support the above functions. 130f0ea3689SLuigi Rizzo * Application libraries may use the following naming scheme: 131d12354a5SVincenzo Maffione * netmap:foo all NIC rings pairs 132d12354a5SVincenzo Maffione * netmap:foo^ only host rings pairs 133d12354a5SVincenzo Maffione * netmap:foo^k the k-th host rings pair 134d12354a5SVincenzo Maffione * netmap:foo+ all NIC rings + host rings pairs 135d12354a5SVincenzo Maffione * netmap:foo-k the k-th NIC rings pair 136d12354a5SVincenzo Maffione * netmap:foo{k PIPE rings pair k, master side 137d12354a5SVincenzo Maffione * netmap:foo}k PIPE rings pair k, slave side 13837e3a6d3SLuigi Rizzo * 13937e3a6d3SLuigi Rizzo * Some notes about host rings: 14037e3a6d3SLuigi Rizzo * 141d12354a5SVincenzo Maffione * + The RX host rings are used to store those packets that the host network 14237e3a6d3SLuigi Rizzo * stack is trying to transmit through a NIC queue, but only if that queue 14337e3a6d3SLuigi Rizzo * is currently in netmap mode. Netmap will not intercept host stack mbufs 14437e3a6d3SLuigi Rizzo * designated to NIC queues that are not in netmap mode. As a consequence, 14537e3a6d3SLuigi Rizzo * registering a netmap port with netmap:foo^ is not enough to intercept 146d12354a5SVincenzo Maffione * mbufs in the RX host rings; the netmap port should be registered with 14737e3a6d3SLuigi Rizzo * netmap:foo*, or another registration should be done to open at least a 14837e3a6d3SLuigi Rizzo * NIC TX queue in netmap mode. 14937e3a6d3SLuigi Rizzo * 15037e3a6d3SLuigi Rizzo * + Netmap is not currently able to deal with intercepted trasmit mbufs which 15137e3a6d3SLuigi Rizzo * require offloadings like TSO, UFO, checksumming offloadings, etc. It is 15237e3a6d3SLuigi Rizzo * responsibility of the user to disable those offloadings (e.g. using 15337e3a6d3SLuigi Rizzo * ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being 15437e3a6d3SLuigi Rizzo * used in netmap mode. If the offloadings are not disabled, GSO and/or 15537e3a6d3SLuigi Rizzo * unchecksummed packets may be dropped immediately or end up in the host RX 156d12354a5SVincenzo Maffione * rings, and will be dropped as soon as the packet reaches another netmap 15737e3a6d3SLuigi Rizzo * adapter. 158ce3ee1e7SLuigi Rizzo */ 159ce3ee1e7SLuigi Rizzo 160ce3ee1e7SLuigi Rizzo /* 161ce3ee1e7SLuigi Rizzo * struct netmap_slot is a buffer descriptor 16217885a7bSLuigi Rizzo */ 16317885a7bSLuigi Rizzo struct netmap_slot { 16417885a7bSLuigi Rizzo uint32_t buf_idx; /* buffer index */ 16517885a7bSLuigi Rizzo uint16_t len; /* length for this slot */ 16617885a7bSLuigi Rizzo uint16_t flags; /* buf changed, etc. */ 16717885a7bSLuigi Rizzo uint64_t ptr; /* pointer for indirect buffers */ 16817885a7bSLuigi Rizzo }; 16917885a7bSLuigi Rizzo 17017885a7bSLuigi Rizzo /* 17117885a7bSLuigi Rizzo * The following flags control how the slot is used 17217885a7bSLuigi Rizzo */ 17317885a7bSLuigi Rizzo 17417885a7bSLuigi Rizzo #define NS_BUF_CHANGED 0x0001 /* buf_idx changed */ 17517885a7bSLuigi Rizzo /* 17617885a7bSLuigi Rizzo * must be set whenever buf_idx is changed (as it might be 17717885a7bSLuigi Rizzo * necessary to recompute the physical address and mapping) 178847bf383SLuigi Rizzo * 179847bf383SLuigi Rizzo * It is also set by the kernel whenever the buf_idx is 180847bf383SLuigi Rizzo * changed internally (e.g., by pipes). Applications may 181847bf383SLuigi Rizzo * use this information to know when they can reuse the 182847bf383SLuigi Rizzo * contents of previously prepared buffers. 18317885a7bSLuigi Rizzo */ 18417885a7bSLuigi Rizzo 18517885a7bSLuigi Rizzo #define NS_REPORT 0x0002 /* ask the hardware to report results */ 18617885a7bSLuigi Rizzo /* 18717885a7bSLuigi Rizzo * Request notification when slot is used by the hardware. 18817885a7bSLuigi Rizzo * Normally transmit completions are handled lazily and 18917885a7bSLuigi Rizzo * may be unreported. This flag lets us know when a slot 19017885a7bSLuigi Rizzo * has been sent (e.g. to terminate the sender). 19117885a7bSLuigi Rizzo */ 19217885a7bSLuigi Rizzo 19317885a7bSLuigi Rizzo #define NS_FORWARD 0x0004 /* pass packet 'forward' */ 19417885a7bSLuigi Rizzo /* 19517885a7bSLuigi Rizzo * (Only for physical ports, rx rings with NR_FORWARD set). 19617885a7bSLuigi Rizzo * Slot released to the kernel (i.e. before ring->head) with 19717885a7bSLuigi Rizzo * this flag set are passed to the peer ring (host/NIC), 19817885a7bSLuigi Rizzo * thus restoring the host-NIC connection for these slots. 19917885a7bSLuigi Rizzo * This supports efficient traffic monitoring or firewalling. 20017885a7bSLuigi Rizzo */ 20117885a7bSLuigi Rizzo 20217885a7bSLuigi Rizzo #define NS_NO_LEARN 0x0008 /* disable bridge learning */ 20317885a7bSLuigi Rizzo /* 20417885a7bSLuigi Rizzo * On a VALE switch, do not 'learn' the source port for 20517885a7bSLuigi Rizzo * this buffer. 20617885a7bSLuigi Rizzo */ 20717885a7bSLuigi Rizzo 20817885a7bSLuigi Rizzo #define NS_INDIRECT 0x0010 /* userspace buffer */ 20917885a7bSLuigi Rizzo /* 21017885a7bSLuigi Rizzo * (VALE tx rings only) data is in a userspace buffer, 21117885a7bSLuigi Rizzo * whose address is in the 'ptr' field in the slot. 21217885a7bSLuigi Rizzo */ 21317885a7bSLuigi Rizzo 21417885a7bSLuigi Rizzo #define NS_MOREFRAG 0x0020 /* packet has more fragments */ 21517885a7bSLuigi Rizzo /* 2164f80b14cSVincenzo Maffione * (VALE ports, ptnetmap ports and some NIC ports, e.g. 2174f80b14cSVincenzo Maffione * ixgbe and i40e on Linux) 21817885a7bSLuigi Rizzo * Set on all but the last slot of a multi-segment packet. 21917885a7bSLuigi Rizzo * The 'len' field refers to the individual fragment. 22017885a7bSLuigi Rizzo */ 22117885a7bSLuigi Rizzo 22217885a7bSLuigi Rizzo #define NS_PORT_SHIFT 8 22317885a7bSLuigi Rizzo #define NS_PORT_MASK (0xff << NS_PORT_SHIFT) 22417885a7bSLuigi Rizzo /* 22517885a7bSLuigi Rizzo * The high 8 bits of the flag, if not zero, indicate the 22601c039a1SLuigi Rizzo * destination port for the VALE switch, overriding 22701c039a1SLuigi Rizzo * the lookup table. 22868b8534bSLuigi Rizzo */ 22901c039a1SLuigi Rizzo 23017885a7bSLuigi Rizzo #define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff) 231ce3ee1e7SLuigi Rizzo /* 23217885a7bSLuigi Rizzo * (VALE rx rings only) the high 8 bits 233ce3ee1e7SLuigi Rizzo * are the number of fragments. 234ce3ee1e7SLuigi Rizzo */ 23517885a7bSLuigi Rizzo 2362a7db7a6SVincenzo Maffione #define NETMAP_MAX_FRAGS 64 /* max number of fragments */ 2372a7db7a6SVincenzo Maffione 238*a6d768d8SVincenzo Maffione 23968b8534bSLuigi Rizzo /* 240ce3ee1e7SLuigi Rizzo * struct netmap_ring 241ce3ee1e7SLuigi Rizzo * 24268b8534bSLuigi Rizzo * Netmap representation of a TX or RX ring (also known as "queue"). 24368b8534bSLuigi Rizzo * This is a queue implemented as a fixed-size circular array. 24417885a7bSLuigi Rizzo * At the software level the important fields are: head, cur, tail. 24568b8534bSLuigi Rizzo * 24668b8534bSLuigi Rizzo * In TX rings: 247ce3ee1e7SLuigi Rizzo * 24817885a7bSLuigi Rizzo * head first slot available for transmission. 24917885a7bSLuigi Rizzo * cur wakeup point. select() and poll() will unblock 25017885a7bSLuigi Rizzo * when 'tail' moves past 'cur' 25117885a7bSLuigi Rizzo * tail (readonly) first slot reserved to the kernel 252ce3ee1e7SLuigi Rizzo * 25317885a7bSLuigi Rizzo * [head .. tail-1] can be used for new packets to send; 25417885a7bSLuigi Rizzo * 'head' and 'cur' must be incremented as slots are filled 25517885a7bSLuigi Rizzo * with new packets to be sent; 25617885a7bSLuigi Rizzo * 'cur' can be moved further ahead if we need more space 2575c8c1004SLuigi Rizzo * for new transmissions. XXX todo (2014-03-12) 25868b8534bSLuigi Rizzo * 25968b8534bSLuigi Rizzo * In RX rings: 260ce3ee1e7SLuigi Rizzo * 26117885a7bSLuigi Rizzo * head first valid received packet 26217885a7bSLuigi Rizzo * cur wakeup point. select() and poll() will unblock 26317885a7bSLuigi Rizzo * when 'tail' moves past 'cur' 26417885a7bSLuigi Rizzo * tail (readonly) first slot reserved to the kernel 265ce3ee1e7SLuigi Rizzo * 26617885a7bSLuigi Rizzo * [head .. tail-1] contain received packets; 26717885a7bSLuigi Rizzo * 'head' and 'cur' must be incremented as slots are consumed 26817885a7bSLuigi Rizzo * and can be returned to the kernel; 26917885a7bSLuigi Rizzo * 'cur' can be moved further ahead if we want to wait for 27017885a7bSLuigi Rizzo * new packets without returning the previous ones. 27168b8534bSLuigi Rizzo * 27268b8534bSLuigi Rizzo * DATA OWNERSHIP/LOCKING: 27317885a7bSLuigi Rizzo * The netmap_ring, and all slots and buffers in the range 27417885a7bSLuigi Rizzo * [head .. tail-1] are owned by the user program; 27517885a7bSLuigi Rizzo * the kernel only accesses them during a netmap system call 27617885a7bSLuigi Rizzo * and in the user thread context. 27701c039a1SLuigi Rizzo * 27817885a7bSLuigi Rizzo * Other slots and buffers are reserved for use by the kernel 27968b8534bSLuigi Rizzo */ 28068b8534bSLuigi Rizzo struct netmap_ring { 28168b8534bSLuigi Rizzo /* 282ce3ee1e7SLuigi Rizzo * buf_ofs is meant to be used through macros. 28368b8534bSLuigi Rizzo * It contains the offset of the buffer region from this 28468b8534bSLuigi Rizzo * descriptor. 28568b8534bSLuigi Rizzo */ 28617885a7bSLuigi Rizzo const int64_t buf_ofs; 28768b8534bSLuigi Rizzo const uint32_t num_slots; /* number of slots in the ring. */ 28817885a7bSLuigi Rizzo const uint32_t nr_buf_size; 28917885a7bSLuigi Rizzo const uint16_t ringid; 29017885a7bSLuigi Rizzo const uint16_t dir; /* 0: tx, 1: rx */ 29168b8534bSLuigi Rizzo 29217885a7bSLuigi Rizzo uint32_t head; /* (u) first user slot */ 29317885a7bSLuigi Rizzo uint32_t cur; /* (u) wakeup point */ 29417885a7bSLuigi Rizzo uint32_t tail; /* (k) first kernel slot */ 29568b8534bSLuigi Rizzo 29617885a7bSLuigi Rizzo uint32_t flags; 29717885a7bSLuigi Rizzo 29817885a7bSLuigi Rizzo struct timeval ts; /* (k) time of last *sync() */ 29917885a7bSLuigi Rizzo 300*a6d768d8SVincenzo Maffione /* offset_mask is used to isolate the part of the ptr field 301*a6d768d8SVincenzo Maffione * in the slots used to contain an offset in the buffer. 302*a6d768d8SVincenzo Maffione * It is zero if the ring has not be opened using the 303*a6d768d8SVincenzo Maffione * NETMAP_REQ_OPT_OFFSETS option. 304*a6d768d8SVincenzo Maffione */ 305*a6d768d8SVincenzo Maffione const uint64_t offset_mask; 306*a6d768d8SVincenzo Maffione /* the alignment requirement, in bytes, for the start 307*a6d768d8SVincenzo Maffione * of the packets inside the buffers. 308*a6d768d8SVincenzo Maffione * User programs should take this alignment into 309*a6d768d8SVincenzo Maffione * account when specifing buffer-offsets in TX slots. 310*a6d768d8SVincenzo Maffione */ 311*a6d768d8SVincenzo Maffione const uint64_t buf_align; 312*a6d768d8SVincenzo Maffione 31317885a7bSLuigi Rizzo /* opaque room for a mutex or similar object */ 31437e3a6d3SLuigi Rizzo #if !defined(_WIN32) || defined(__CYGWIN__) 31537e3a6d3SLuigi Rizzo uint8_t __attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128]; 31637e3a6d3SLuigi Rizzo #else 31737e3a6d3SLuigi Rizzo uint8_t __declspec(align(NM_CACHE_ALIGN)) sem[128]; 31837e3a6d3SLuigi Rizzo #endif 31968b8534bSLuigi Rizzo 32068b8534bSLuigi Rizzo /* the slots follow. This struct has variable size */ 32168b8534bSLuigi Rizzo struct netmap_slot slot[0]; /* array of slots. */ 32268b8534bSLuigi Rizzo }; 32368b8534bSLuigi Rizzo 324*a6d768d8SVincenzo Maffione 32568b8534bSLuigi Rizzo /* 32617885a7bSLuigi Rizzo * RING FLAGS 32717885a7bSLuigi Rizzo */ 32817885a7bSLuigi Rizzo #define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */ 32917885a7bSLuigi Rizzo /* 33017885a7bSLuigi Rizzo * updates the 'ts' field on each netmap syscall. This saves 33117885a7bSLuigi Rizzo * saves a separate gettimeofday(), and is not much worse than 33217885a7bSLuigi Rizzo * software timestamps generated in the interrupt handler. 33317885a7bSLuigi Rizzo */ 33417885a7bSLuigi Rizzo 33517885a7bSLuigi Rizzo #define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */ 33617885a7bSLuigi Rizzo /* 33717885a7bSLuigi Rizzo * Enables the NS_FORWARD slot flag for the ring. 33817885a7bSLuigi Rizzo */ 33917885a7bSLuigi Rizzo 3402ff91c17SVincenzo Maffione /* 3412ff91c17SVincenzo Maffione * Helper functions for kernel and userspace 3422ff91c17SVincenzo Maffione */ 3432ff91c17SVincenzo Maffione 3442ff91c17SVincenzo Maffione /* 345b6e66be2SVincenzo Maffione * Check if space is available in the ring. We use ring->head, which 346b6e66be2SVincenzo Maffione * points to the next netmap slot to be published to netmap. It is 347b6e66be2SVincenzo Maffione * possible that the applications moves ring->cur ahead of ring->tail 348b6e66be2SVincenzo Maffione * (e.g., by setting ring->cur <== ring->tail), if it wants more slots 349b6e66be2SVincenzo Maffione * than the ones currently available, and it wants to be notified when 350b6e66be2SVincenzo Maffione * more arrive. See netmap(4) for more details and examples. 3512ff91c17SVincenzo Maffione */ 3522ff91c17SVincenzo Maffione static inline int 3532ff91c17SVincenzo Maffione nm_ring_empty(struct netmap_ring *ring) 3542ff91c17SVincenzo Maffione { 355b6e66be2SVincenzo Maffione return (ring->head == ring->tail); 3562ff91c17SVincenzo Maffione } 35717885a7bSLuigi Rizzo 35817885a7bSLuigi Rizzo /* 35968b8534bSLuigi Rizzo * Netmap representation of an interface and its queue(s). 360ce3ee1e7SLuigi Rizzo * This is initialized by the kernel when binding a file 361ce3ee1e7SLuigi Rizzo * descriptor to a port, and should be considered as readonly 362ce3ee1e7SLuigi Rizzo * by user programs. The kernel never uses it. 363ce3ee1e7SLuigi Rizzo * 36468b8534bSLuigi Rizzo * There is one netmap_if for each file descriptor on which we want 365ce3ee1e7SLuigi Rizzo * to select/poll. 36668b8534bSLuigi Rizzo * select/poll operates on one or all pairs depending on the value of 36768b8534bSLuigi Rizzo * nmr_queueid passed on the ioctl. 36868b8534bSLuigi Rizzo */ 36968b8534bSLuigi Rizzo struct netmap_if { 37068b8534bSLuigi Rizzo char ni_name[IFNAMSIZ]; /* name of the interface. */ 371ce3ee1e7SLuigi Rizzo const uint32_t ni_version; /* API version, currently unused */ 372ce3ee1e7SLuigi Rizzo const uint32_t ni_flags; /* properties */ 373ce3ee1e7SLuigi Rizzo #define NI_PRIV_MEM 0x1 /* private memory region */ 374ce3ee1e7SLuigi Rizzo 37517885a7bSLuigi Rizzo /* 37617885a7bSLuigi Rizzo * The number of packet rings available in netmap mode. 37717885a7bSLuigi Rizzo * Physical NICs can have different numbers of tx and rx rings. 378d12354a5SVincenzo Maffione * Physical NICs also have at least a 'host' rings pair. 37917885a7bSLuigi Rizzo * Additionally, clients can request additional ring pairs to 38017885a7bSLuigi Rizzo * be used for internal communication. 38117885a7bSLuigi Rizzo */ 38217885a7bSLuigi Rizzo const uint32_t ni_tx_rings; /* number of HW tx rings */ 38317885a7bSLuigi Rizzo const uint32_t ni_rx_rings; /* number of HW rx rings */ 38417885a7bSLuigi Rizzo 385f0ea3689SLuigi Rizzo uint32_t ni_bufs_head; /* head index for extra bufs */ 386d12354a5SVincenzo Maffione const uint32_t ni_host_tx_rings; /* number of SW tx rings */ 387d12354a5SVincenzo Maffione const uint32_t ni_host_rx_rings; /* number of SW rx rings */ 388d12354a5SVincenzo Maffione uint32_t ni_spare1[3]; 38968b8534bSLuigi Rizzo /* 39064ae02c3SLuigi Rizzo * The following array contains the offset of each netmap ring 39117885a7bSLuigi Rizzo * from this structure, in the following order: 392d12354a5SVincenzo Maffione * - NIC tx rings (ni_tx_rings); 393d12354a5SVincenzo Maffione * - host tx rings (ni_host_tx_rings); 394d12354a5SVincenzo Maffione * - NIC rx rings (ni_rx_rings); 395d12354a5SVincenzo Maffione * - host rx ring (ni_host_rx_rings); 39617885a7bSLuigi Rizzo * 397d12354a5SVincenzo Maffione * The area is filled up by the kernel on NETMAP_REQ_REGISTER, 39868b8534bSLuigi Rizzo * and then only read by userspace code. 39968b8534bSLuigi Rizzo */ 40068b8534bSLuigi Rizzo const ssize_t ring_ofs[0]; 40168b8534bSLuigi Rizzo }; 40268b8534bSLuigi Rizzo 4032ff91c17SVincenzo Maffione /* Legacy interface to interact with a netmap control device. 4042ff91c17SVincenzo Maffione * Included for backward compatibility. The user should not include this 4052ff91c17SVincenzo Maffione * file directly. */ 4062ff91c17SVincenzo Maffione #include "netmap_legacy.h" 40717885a7bSLuigi Rizzo 40868b8534bSLuigi Rizzo /* 4092ff91c17SVincenzo Maffione * New API to control netmap control devices. New applications should only use 4102ff91c17SVincenzo Maffione * nmreq_xyz structs with the NIOCCTRL ioctl() command. 41168b8534bSLuigi Rizzo * 4122ff91c17SVincenzo Maffione * NIOCCTRL takes a nmreq_header struct, which contains the required 4132ff91c17SVincenzo Maffione * API version, the name of a netmap port, a command type, and pointers 4142ff91c17SVincenzo Maffione * to request body and options. 415f18be576SLuigi Rizzo * 41617885a7bSLuigi Rizzo * nr_name (in) 4172ff91c17SVincenzo Maffione * The name of the port (em0, valeXXX:YYY, eth0{pn1 etc.) 418ce3ee1e7SLuigi Rizzo * 41917885a7bSLuigi Rizzo * nr_version (in/out) 42017885a7bSLuigi Rizzo * Must match NETMAP_API as used in the kernel, error otherwise. 42117885a7bSLuigi Rizzo * Always returns the desired value on output. 42217885a7bSLuigi Rizzo * 4232ff91c17SVincenzo Maffione * nr_reqtype (in) 4242ff91c17SVincenzo Maffione * One of the NETMAP_REQ_* command types below 4252ff91c17SVincenzo Maffione * 4262ff91c17SVincenzo Maffione * nr_body (in) 4272ff91c17SVincenzo Maffione * Pointer to a command-specific struct, described by one 4282ff91c17SVincenzo Maffione * of the struct nmreq_xyz below. 4292ff91c17SVincenzo Maffione * 4302ff91c17SVincenzo Maffione * nr_options (in) 4312ff91c17SVincenzo Maffione * Command specific options, if any. 4322ff91c17SVincenzo Maffione * 4332ff91c17SVincenzo Maffione * A NETMAP_REQ_REGISTER command activates netmap mode on the netmap 4342ff91c17SVincenzo Maffione * port (e.g. physical interface) specified by nmreq_header.nr_name. 4352ff91c17SVincenzo Maffione * The request body (struct nmreq_register) has several arguments to 4362ff91c17SVincenzo Maffione * specify how the port is to be registered. 4372ff91c17SVincenzo Maffione * 438d12354a5SVincenzo Maffione * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings, 439d12354a5SVincenzo Maffione * nr_host_tx_rings, nr_host_rx_rings (in/out) 44017885a7bSLuigi Rizzo * On input, non-zero values may be used to reconfigure the port 44117885a7bSLuigi Rizzo * according to the requested values, but this is not guaranteed. 44217885a7bSLuigi Rizzo * On output the actual values in use are reported. 44317885a7bSLuigi Rizzo * 4442ff91c17SVincenzo Maffione * nr_mode (in) 4452ff91c17SVincenzo Maffione * Indicate what set of rings must be bound to the netmap 4462ff91c17SVincenzo Maffione * device (e.g. all NIC rings, host rings only, NIC and 4472ff91c17SVincenzo Maffione * host rings, ...). Values are in NR_REG_*. 4482ff91c17SVincenzo Maffione * 44917885a7bSLuigi Rizzo * nr_ringid (in) 4502ff91c17SVincenzo Maffione * If nr_mode == NR_REG_ONE_NIC (only a single couple of TX/RX 4512ff91c17SVincenzo Maffione * rings), indicate which NIC TX and/or RX ring is to be bound 4522ff91c17SVincenzo Maffione * (0..nr_*x_rings-1). 453f0ea3689SLuigi Rizzo * 4542ff91c17SVincenzo Maffione * nr_flags (in) 4552ff91c17SVincenzo Maffione * Indicate special options for how to open the port. 456ce3ee1e7SLuigi Rizzo * 4572ff91c17SVincenzo Maffione * NR_NO_TX_POLL can be OR-ed to make select()/poll() push 45817885a7bSLuigi Rizzo * packets on tx rings only if POLLOUT is set. 45917885a7bSLuigi Rizzo * The default is to push any pending packet. 460ce3ee1e7SLuigi Rizzo * 4612ff91c17SVincenzo Maffione * NR_DO_RX_POLL can be OR-ed to make select()/poll() release 462f0ea3689SLuigi Rizzo * packets on rx rings also when POLLIN is NOT set. 463f0ea3689SLuigi Rizzo * The default is to touch the rx ring only with POLLIN. 464f0ea3689SLuigi Rizzo * Note that this is the opposite of TX because it 465f0ea3689SLuigi Rizzo * reflects the common usage. 466f0ea3689SLuigi Rizzo * 4672ff91c17SVincenzo Maffione * Other options are NR_MONITOR_TX, NR_MONITOR_RX, NR_ZCOPY_MON, 4682ff91c17SVincenzo Maffione * NR_EXCLUSIVE, NR_RX_RINGS_ONLY, NR_TX_RINGS_ONLY and 4692ff91c17SVincenzo Maffione * NR_ACCEPT_VNET_HDR. 470f0ea3689SLuigi Rizzo * 4712ff91c17SVincenzo Maffione * nr_mem_id (in/out) 4722ff91c17SVincenzo Maffione * The identity of the memory region used. 473f0ea3689SLuigi Rizzo * On input, 0 means the system decides autonomously, 474f0ea3689SLuigi Rizzo * other values may try to select a specific region. 475f0ea3689SLuigi Rizzo * On return the actual value is reported. 476f0ea3689SLuigi Rizzo * Region '1' is the global allocator, normally shared 477f0ea3689SLuigi Rizzo * by all interfaces. Other values are private regions. 478f0ea3689SLuigi Rizzo * If two ports the same region zero-copy is possible. 479f0ea3689SLuigi Rizzo * 4802ff91c17SVincenzo Maffione * nr_extra_bufs (in/out) 4812ff91c17SVincenzo Maffione * Number of extra buffers to be allocated. 482f0ea3689SLuigi Rizzo * 4832ff91c17SVincenzo Maffione * The other NETMAP_REQ_* commands are described below. 48417885a7bSLuigi Rizzo * 48568b8534bSLuigi Rizzo */ 48668b8534bSLuigi Rizzo 4872ff91c17SVincenzo Maffione /* maximum size of a request, including all options */ 4882ff91c17SVincenzo Maffione #define NETMAP_REQ_MAXSIZE 4096 4892ff91c17SVincenzo Maffione 4902ff91c17SVincenzo Maffione /* Header common to all request options. */ 4912ff91c17SVincenzo Maffione struct nmreq_option { 4922ff91c17SVincenzo Maffione /* Pointer ot the next option. */ 4932ff91c17SVincenzo Maffione uint64_t nro_next; 4942ff91c17SVincenzo Maffione /* Option type. */ 4952ff91c17SVincenzo Maffione uint32_t nro_reqtype; 4962ff91c17SVincenzo Maffione /* (out) status of the option: 4972ff91c17SVincenzo Maffione * 0: recognized and processed 4982ff91c17SVincenzo Maffione * !=0: errno value 4992ff91c17SVincenzo Maffione */ 5002ff91c17SVincenzo Maffione uint32_t nro_status; 501b6e66be2SVincenzo Maffione /* Option size, used only for options that can have variable size 502b6e66be2SVincenzo Maffione * (e.g. because they contain arrays). For fixed-size options this 503b6e66be2SVincenzo Maffione * field should be set to zero. */ 504b6e66be2SVincenzo Maffione uint64_t nro_size; 5052ff91c17SVincenzo Maffione }; 5062ff91c17SVincenzo Maffione 5072ff91c17SVincenzo Maffione /* Header common to all requests. Do not reorder these fields, as we need 5082ff91c17SVincenzo Maffione * the second one (nr_reqtype) to know how much to copy from/to userspace. */ 5092ff91c17SVincenzo Maffione struct nmreq_header { 5102ff91c17SVincenzo Maffione uint16_t nr_version; /* API version */ 5112ff91c17SVincenzo Maffione uint16_t nr_reqtype; /* nmreq type (NETMAP_REQ_*) */ 5122ff91c17SVincenzo Maffione uint32_t nr_reserved; /* must be zero */ 5132ff91c17SVincenzo Maffione #define NETMAP_REQ_IFNAMSIZ 64 5142ff91c17SVincenzo Maffione char nr_name[NETMAP_REQ_IFNAMSIZ]; /* port name */ 5152ff91c17SVincenzo Maffione uint64_t nr_options; /* command-specific options */ 5162ff91c17SVincenzo Maffione uint64_t nr_body; /* ptr to nmreq_xyz struct */ 5172ff91c17SVincenzo Maffione }; 5182ff91c17SVincenzo Maffione 5192ff91c17SVincenzo Maffione enum { 5202ff91c17SVincenzo Maffione /* Register a netmap port with the device. */ 5212ff91c17SVincenzo Maffione NETMAP_REQ_REGISTER = 1, 5222ff91c17SVincenzo Maffione /* Get information from a netmap port. */ 5232ff91c17SVincenzo Maffione NETMAP_REQ_PORT_INFO_GET, 5242ff91c17SVincenzo Maffione /* Attach a netmap port to a VALE switch. */ 5252ff91c17SVincenzo Maffione NETMAP_REQ_VALE_ATTACH, 5262ff91c17SVincenzo Maffione /* Detach a netmap port from a VALE switch. */ 5272ff91c17SVincenzo Maffione NETMAP_REQ_VALE_DETACH, 5282ff91c17SVincenzo Maffione /* List the ports attached to a VALE switch. */ 5292ff91c17SVincenzo Maffione NETMAP_REQ_VALE_LIST, 5302ff91c17SVincenzo Maffione /* Set the port header length (was virtio-net header length). */ 5312ff91c17SVincenzo Maffione NETMAP_REQ_PORT_HDR_SET, 5322ff91c17SVincenzo Maffione /* Get the port header length (was virtio-net header length). */ 5332ff91c17SVincenzo Maffione NETMAP_REQ_PORT_HDR_GET, 5342ff91c17SVincenzo Maffione /* Create a new persistent VALE port. */ 5352ff91c17SVincenzo Maffione NETMAP_REQ_VALE_NEWIF, 5362ff91c17SVincenzo Maffione /* Delete a persistent VALE port. */ 5372ff91c17SVincenzo Maffione NETMAP_REQ_VALE_DELIF, 5382ff91c17SVincenzo Maffione /* Enable polling kernel thread(s) on an attached VALE port. */ 5392ff91c17SVincenzo Maffione NETMAP_REQ_VALE_POLLING_ENABLE, 5402ff91c17SVincenzo Maffione /* Disable polling kernel thread(s) on an attached VALE port. */ 5412ff91c17SVincenzo Maffione NETMAP_REQ_VALE_POLLING_DISABLE, 5422ff91c17SVincenzo Maffione /* Get info about the pools of a memory allocator. */ 5432ff91c17SVincenzo Maffione NETMAP_REQ_POOLS_INFO_GET, 544b6e66be2SVincenzo Maffione /* Start an in-kernel loop that syncs the rings periodically or 545b6e66be2SVincenzo Maffione * on notifications. The loop runs in the context of the ioctl 546b6e66be2SVincenzo Maffione * syscall, and only stops on NETMAP_REQ_SYNC_KLOOP_STOP. */ 547b6e66be2SVincenzo Maffione NETMAP_REQ_SYNC_KLOOP_START, 548b6e66be2SVincenzo Maffione /* Stops the thread executing the in-kernel loop. The thread 549b6e66be2SVincenzo Maffione * returns from the ioctl syscall. */ 550b6e66be2SVincenzo Maffione NETMAP_REQ_SYNC_KLOOP_STOP, 551b6e66be2SVincenzo Maffione /* Enable CSB mode on a registered netmap control device. */ 552b6e66be2SVincenzo Maffione NETMAP_REQ_CSB_ENABLE, 5532ff91c17SVincenzo Maffione }; 5542ff91c17SVincenzo Maffione 5552ff91c17SVincenzo Maffione enum { 5562ff91c17SVincenzo Maffione /* On NETMAP_REQ_REGISTER, ask netmap to use memory allocated 5575faab778SVincenzo Maffione * from user-space allocated memory pools (e.g. hugepages). 5585faab778SVincenzo Maffione */ 5592ff91c17SVincenzo Maffione NETMAP_REQ_OPT_EXTMEM = 1, 560b6e66be2SVincenzo Maffione 561b6e66be2SVincenzo Maffione /* ON NETMAP_REQ_SYNC_KLOOP_START, ask netmap to use eventfd-based 562b6e66be2SVincenzo Maffione * notifications to synchronize the kernel loop with the application. 563b6e66be2SVincenzo Maffione */ 564b6e66be2SVincenzo Maffione NETMAP_REQ_OPT_SYNC_KLOOP_EVENTFDS, 565b6e66be2SVincenzo Maffione 566b6e66be2SVincenzo Maffione /* On NETMAP_REQ_REGISTER, ask netmap to work in CSB mode, where 567b6e66be2SVincenzo Maffione * head, cur and tail pointers are not exchanged through the 568b6e66be2SVincenzo Maffione * struct netmap_ring header, but rather using an user-provided 5695faab778SVincenzo Maffione * memory area (see struct nm_csb_atok and struct nm_csb_ktoa). 5705faab778SVincenzo Maffione */ 571b6e66be2SVincenzo Maffione NETMAP_REQ_OPT_CSB, 5725faab778SVincenzo Maffione 5735faab778SVincenzo Maffione /* An extension to NETMAP_REQ_OPT_SYNC_KLOOP_EVENTFDS, which specifies 5745faab778SVincenzo Maffione * if the TX and/or RX rings are synced in the context of the VM exit. 5755faab778SVincenzo Maffione * This requires the 'ioeventfd' fields to be valid (cannot be < 0). 5765faab778SVincenzo Maffione */ 5775faab778SVincenzo Maffione NETMAP_REQ_OPT_SYNC_KLOOP_MODE, 578253b2ec1SVincenzo Maffione 579*a6d768d8SVincenzo Maffione /* On NETMAP_REQ_REGISTER, ask for (part of) the ptr field in the 580*a6d768d8SVincenzo Maffione * slots of the registered rings to be used as an offset field 581*a6d768d8SVincenzo Maffione * for the start of the packets inside the netmap buffer. 582*a6d768d8SVincenzo Maffione */ 583*a6d768d8SVincenzo Maffione NETMAP_REQ_OPT_OFFSETS, 584*a6d768d8SVincenzo Maffione 585253b2ec1SVincenzo Maffione /* This is a marker to count the number of available options. 586253b2ec1SVincenzo Maffione * New options must be added above it. */ 587253b2ec1SVincenzo Maffione NETMAP_REQ_OPT_MAX, 5882ff91c17SVincenzo Maffione }; 58917885a7bSLuigi Rizzo 59068b8534bSLuigi Rizzo /* 5912ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_REGISTER 5922ff91c17SVincenzo Maffione * Bind (register) a netmap port to this control device. 59368b8534bSLuigi Rizzo */ 5942ff91c17SVincenzo Maffione struct nmreq_register { 5952ff91c17SVincenzo Maffione uint64_t nr_offset; /* nifp offset in the shared region */ 5962ff91c17SVincenzo Maffione uint64_t nr_memsize; /* size of the shared region */ 59764ae02c3SLuigi Rizzo uint32_t nr_tx_slots; /* slots in tx rings */ 59864ae02c3SLuigi Rizzo uint32_t nr_rx_slots; /* slots in rx rings */ 59964ae02c3SLuigi Rizzo uint16_t nr_tx_rings; /* number of tx rings */ 60064ae02c3SLuigi Rizzo uint16_t nr_rx_rings; /* number of rx rings */ 601d12354a5SVincenzo Maffione uint16_t nr_host_tx_rings; /* number of host tx rings */ 602d12354a5SVincenzo Maffione uint16_t nr_host_rx_rings; /* number of host rx rings */ 603f0ea3689SLuigi Rizzo 6042ff91c17SVincenzo Maffione uint16_t nr_mem_id; /* id of the memory allocator */ 60568b8534bSLuigi Rizzo uint16_t nr_ringid; /* ring(s) we care about */ 6062ff91c17SVincenzo Maffione uint32_t nr_mode; /* specify NR_REG_* modes */ 607b6e66be2SVincenzo Maffione uint32_t nr_extra_bufs; /* number of requested extra buffers */ 608f0ea3689SLuigi Rizzo 6092ff91c17SVincenzo Maffione uint64_t nr_flags; /* additional flags (see below) */ 6102ff91c17SVincenzo Maffione /* monitors use nr_ringid and nr_mode to select the rings to monitor */ 611f0ea3689SLuigi Rizzo #define NR_MONITOR_TX 0x100 612f0ea3689SLuigi Rizzo #define NR_MONITOR_RX 0x200 613847bf383SLuigi Rizzo #define NR_ZCOPY_MON 0x400 614847bf383SLuigi Rizzo /* request exclusive access to the selected rings */ 615847bf383SLuigi Rizzo #define NR_EXCLUSIVE 0x800 616b6e66be2SVincenzo Maffione /* 0x1000 unused */ 61737e3a6d3SLuigi Rizzo #define NR_RX_RINGS_ONLY 0x2000 61837e3a6d3SLuigi Rizzo #define NR_TX_RINGS_ONLY 0x4000 61937e3a6d3SLuigi Rizzo /* Applications set this flag if they are able to deal with virtio-net headers, 62037e3a6d3SLuigi Rizzo * that is send/receive frames that start with a virtio-net header. 621d12354a5SVincenzo Maffione * If not set, NETMAP_REQ_REGISTER will fail with netmap ports that require 622d12354a5SVincenzo Maffione * applications to use those headers. If the flag is set, the application can 623d12354a5SVincenzo Maffione * use the NETMAP_VNET_HDR_GET command to figure out the header length. */ 62437e3a6d3SLuigi Rizzo #define NR_ACCEPT_VNET_HDR 0x8000 6252ff91c17SVincenzo Maffione /* The following two have the same meaning of NETMAP_NO_TX_POLL and 6262ff91c17SVincenzo Maffione * NETMAP_DO_RX_POLL. */ 6272ff91c17SVincenzo Maffione #define NR_DO_RX_POLL 0x10000 6282ff91c17SVincenzo Maffione #define NR_NO_TX_POLL 0x20000 6292ff91c17SVincenzo Maffione }; 6302ff91c17SVincenzo Maffione 6312ff91c17SVincenzo Maffione /* Valid values for nmreq_register.nr_mode (see above). */ 6322ff91c17SVincenzo Maffione enum { NR_REG_DEFAULT = 0, /* backward compat, should not be used. */ 6332ff91c17SVincenzo Maffione NR_REG_ALL_NIC = 1, 6342ff91c17SVincenzo Maffione NR_REG_SW = 2, 6352ff91c17SVincenzo Maffione NR_REG_NIC_SW = 3, 6362ff91c17SVincenzo Maffione NR_REG_ONE_NIC = 4, 6372ff91c17SVincenzo Maffione NR_REG_PIPE_MASTER = 5, /* deprecated, use "x{y" port name syntax */ 6382ff91c17SVincenzo Maffione NR_REG_PIPE_SLAVE = 6, /* deprecated, use "x}y" port name syntax */ 639b6e66be2SVincenzo Maffione NR_REG_NULL = 7, 640d12354a5SVincenzo Maffione NR_REG_ONE_SW = 8, 6412ff91c17SVincenzo Maffione }; 6422ff91c17SVincenzo Maffione 6432ff91c17SVincenzo Maffione /* A single ioctl number is shared by all the new API command. 644b6e66be2SVincenzo Maffione * Demultiplexing is done using the hdr.nr_reqtype field. 6452ff91c17SVincenzo Maffione * FreeBSD uses the size value embedded in the _IOWR to determine 6462ff91c17SVincenzo Maffione * how much to copy in/out, so we define the ioctl() command 6472ff91c17SVincenzo Maffione * specifying only nmreq_header, and copyin/copyout the rest. */ 6482ff91c17SVincenzo Maffione #define NIOCCTRL _IOWR('i', 151, struct nmreq_header) 6492ff91c17SVincenzo Maffione 6502ff91c17SVincenzo Maffione /* The ioctl commands to sync TX/RX netmap rings. 6512ff91c17SVincenzo Maffione * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues, 652d12354a5SVincenzo Maffione * whose identity is set in NETMAP_REQ_REGISTER through nr_ringid. 6532ff91c17SVincenzo Maffione * These are non blocking and take no argument. */ 6542ff91c17SVincenzo Maffione #define NIOCTXSYNC _IO('i', 148) /* sync tx queues */ 6552ff91c17SVincenzo Maffione #define NIOCRXSYNC _IO('i', 149) /* sync rx queues */ 6562ff91c17SVincenzo Maffione 6572ff91c17SVincenzo Maffione /* 6582ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_PORT_INFO_GET 6592ff91c17SVincenzo Maffione * Get information about a netmap port, including number of rings. 660b6e66be2SVincenzo Maffione * slots per ring, id of the memory allocator, etc. The netmap 661b6e66be2SVincenzo Maffione * control device used for this operation does not need to be bound 662b6e66be2SVincenzo Maffione * to a netmap port. 6632ff91c17SVincenzo Maffione */ 6642ff91c17SVincenzo Maffione struct nmreq_port_info_get { 6652ff91c17SVincenzo Maffione uint64_t nr_memsize; /* size of the shared region */ 6662ff91c17SVincenzo Maffione uint32_t nr_tx_slots; /* slots in tx rings */ 6672ff91c17SVincenzo Maffione uint32_t nr_rx_slots; /* slots in rx rings */ 6682ff91c17SVincenzo Maffione uint16_t nr_tx_rings; /* number of tx rings */ 6692ff91c17SVincenzo Maffione uint16_t nr_rx_rings; /* number of rx rings */ 670d12354a5SVincenzo Maffione uint16_t nr_host_tx_rings; /* number of host tx rings */ 671d12354a5SVincenzo Maffione uint16_t nr_host_rx_rings; /* number of host rx rings */ 672b6e66be2SVincenzo Maffione uint16_t nr_mem_id; /* memory allocator id (in/out) */ 673d12354a5SVincenzo Maffione uint16_t pad[3]; 6742ff91c17SVincenzo Maffione }; 675f0ea3689SLuigi Rizzo 67637e3a6d3SLuigi Rizzo #define NM_BDG_NAME "vale" /* prefix for bridge port name */ 67737e3a6d3SLuigi Rizzo 67837e3a6d3SLuigi Rizzo /* 6792ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_VALE_ATTACH 6802ff91c17SVincenzo Maffione * Attach a netmap port to a VALE switch. Both the name of the netmap 6812ff91c17SVincenzo Maffione * port and the VALE switch are specified through the nr_name argument. 6822ff91c17SVincenzo Maffione * The attach operation could need to register a port, so at least 6832ff91c17SVincenzo Maffione * the same arguments are available. 6842ff91c17SVincenzo Maffione * port_index will contain the index where the port has been attached. 68537e3a6d3SLuigi Rizzo */ 6862ff91c17SVincenzo Maffione struct nmreq_vale_attach { 6872ff91c17SVincenzo Maffione struct nmreq_register reg; 6882ff91c17SVincenzo Maffione uint32_t port_index; 689b6e66be2SVincenzo Maffione uint32_t pad1; 6902ff91c17SVincenzo Maffione }; 69117885a7bSLuigi Rizzo 69264ae02c3SLuigi Rizzo /* 6932ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_VALE_DETACH 6942ff91c17SVincenzo Maffione * Detach a netmap port from a VALE switch. Both the name of the netmap 6952ff91c17SVincenzo Maffione * port and the VALE switch are specified through the nr_name argument. 6962ff91c17SVincenzo Maffione * port_index will contain the index where the port was attached. 69764ae02c3SLuigi Rizzo */ 6982ff91c17SVincenzo Maffione struct nmreq_vale_detach { 6992ff91c17SVincenzo Maffione uint32_t port_index; 700b6e66be2SVincenzo Maffione uint32_t pad1; 7012ff91c17SVincenzo Maffione }; 70217885a7bSLuigi Rizzo 70317885a7bSLuigi Rizzo /* 7042ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_VALE_LIST 7052ff91c17SVincenzo Maffione * List the ports of a VALE switch. 70617885a7bSLuigi Rizzo */ 7072ff91c17SVincenzo Maffione struct nmreq_vale_list { 7082ff91c17SVincenzo Maffione /* Name of the VALE port (valeXXX:YYY) or empty. */ 7092ff91c17SVincenzo Maffione uint16_t nr_bridge_idx; 710b6e66be2SVincenzo Maffione uint16_t pad1; 7112ff91c17SVincenzo Maffione uint32_t nr_port_idx; 7122ff91c17SVincenzo Maffione }; 71317885a7bSLuigi Rizzo 71417885a7bSLuigi Rizzo /* 7152ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_PORT_HDR_SET or NETMAP_REQ_PORT_HDR_GET 716b6e66be2SVincenzo Maffione * Set or get the port header length of the port identified by hdr.nr_name. 717b6e66be2SVincenzo Maffione * The control device does not need to be bound to a netmap port. 71817885a7bSLuigi Rizzo */ 7192ff91c17SVincenzo Maffione struct nmreq_port_hdr { 7202ff91c17SVincenzo Maffione uint32_t nr_hdr_len; 721b6e66be2SVincenzo Maffione uint32_t pad1; 7222ff91c17SVincenzo Maffione }; 72317885a7bSLuigi Rizzo 7244bf50f18SLuigi Rizzo /* 7252ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_VALE_NEWIF 7262ff91c17SVincenzo Maffione * Create a new persistent VALE port. 7274bf50f18SLuigi Rizzo */ 7282ff91c17SVincenzo Maffione struct nmreq_vale_newif { 7292ff91c17SVincenzo Maffione uint32_t nr_tx_slots; /* slots in tx rings */ 7302ff91c17SVincenzo Maffione uint32_t nr_rx_slots; /* slots in rx rings */ 7312ff91c17SVincenzo Maffione uint16_t nr_tx_rings; /* number of tx rings */ 7322ff91c17SVincenzo Maffione uint16_t nr_rx_rings; /* number of rx rings */ 7332ff91c17SVincenzo Maffione uint16_t nr_mem_id; /* id of the memory allocator */ 734b6e66be2SVincenzo Maffione uint16_t pad1; 7352ff91c17SVincenzo Maffione }; 7362ff91c17SVincenzo Maffione 7372ff91c17SVincenzo Maffione /* 7382ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_VALE_POLLING_ENABLE or NETMAP_REQ_VALE_POLLING_DISABLE 7392ff91c17SVincenzo Maffione * Enable or disable polling kthreads on a VALE port. 7402ff91c17SVincenzo Maffione */ 7412ff91c17SVincenzo Maffione struct nmreq_vale_polling { 7422ff91c17SVincenzo Maffione uint32_t nr_mode; 7432ff91c17SVincenzo Maffione #define NETMAP_POLLING_MODE_SINGLE_CPU 1 7442ff91c17SVincenzo Maffione #define NETMAP_POLLING_MODE_MULTI_CPU 2 7452ff91c17SVincenzo Maffione uint32_t nr_first_cpu_id; 7462ff91c17SVincenzo Maffione uint32_t nr_num_polling_cpus; 747b6e66be2SVincenzo Maffione uint32_t pad1; 7482ff91c17SVincenzo Maffione }; 7492ff91c17SVincenzo Maffione 7502ff91c17SVincenzo Maffione /* 7512ff91c17SVincenzo Maffione * nr_reqtype: NETMAP_REQ_POOLS_INFO_GET 752b6e66be2SVincenzo Maffione * Get info about the pools of the memory allocator of the netmap 753b6e66be2SVincenzo Maffione * port specified by hdr.nr_name and nr_mem_id. The netmap control 754b6e66be2SVincenzo Maffione * device used for this operation does not need to be bound to a netmap 755b6e66be2SVincenzo Maffione * port. 7562ff91c17SVincenzo Maffione */ 7572ff91c17SVincenzo Maffione struct nmreq_pools_info { 7582ff91c17SVincenzo Maffione uint64_t nr_memsize; 759b6e66be2SVincenzo Maffione uint16_t nr_mem_id; /* in/out argument */ 760b6e66be2SVincenzo Maffione uint16_t pad1[3]; 7612ff91c17SVincenzo Maffione uint64_t nr_if_pool_offset; 7622ff91c17SVincenzo Maffione uint32_t nr_if_pool_objtotal; 7632ff91c17SVincenzo Maffione uint32_t nr_if_pool_objsize; 7642ff91c17SVincenzo Maffione uint64_t nr_ring_pool_offset; 7652ff91c17SVincenzo Maffione uint32_t nr_ring_pool_objtotal; 7662ff91c17SVincenzo Maffione uint32_t nr_ring_pool_objsize; 7672ff91c17SVincenzo Maffione uint64_t nr_buf_pool_offset; 7682ff91c17SVincenzo Maffione uint32_t nr_buf_pool_objtotal; 7692ff91c17SVincenzo Maffione uint32_t nr_buf_pool_objsize; 7702ff91c17SVincenzo Maffione }; 7712ff91c17SVincenzo Maffione 7722ff91c17SVincenzo Maffione /* 773b6e66be2SVincenzo Maffione * nr_reqtype: NETMAP_REQ_SYNC_KLOOP_START 774b6e66be2SVincenzo Maffione * Start an in-kernel loop that syncs the rings periodically or on 775b6e66be2SVincenzo Maffione * notifications. The loop runs in the context of the ioctl syscall, 776b6e66be2SVincenzo Maffione * and only stops on NETMAP_REQ_SYNC_KLOOP_STOP. 777b6e66be2SVincenzo Maffione * The registered netmap port must be open in CSB mode. 778b6e66be2SVincenzo Maffione */ 779b6e66be2SVincenzo Maffione struct nmreq_sync_kloop_start { 780b6e66be2SVincenzo Maffione /* Sleeping is the default synchronization method for the kloop. 781b6e66be2SVincenzo Maffione * The 'sleep_us' field specifies how many microsconds to sleep for 782b6e66be2SVincenzo Maffione * when there is no work to do, before doing another kloop iteration. 783b6e66be2SVincenzo Maffione */ 784b6e66be2SVincenzo Maffione uint32_t sleep_us; 785b6e66be2SVincenzo Maffione uint32_t pad1; 786b6e66be2SVincenzo Maffione }; 787b6e66be2SVincenzo Maffione 788b6e66be2SVincenzo Maffione /* A CSB entry for the application --> kernel direction. */ 789b6e66be2SVincenzo Maffione struct nm_csb_atok { 790b6e66be2SVincenzo Maffione uint32_t head; /* AW+ KR+ the head of the appl netmap_ring */ 791b6e66be2SVincenzo Maffione uint32_t cur; /* AW+ KR+ the cur of the appl netmap_ring */ 792b6e66be2SVincenzo Maffione uint32_t appl_need_kick; /* AW+ KR+ kern --> appl notification enable */ 793b6e66be2SVincenzo Maffione uint32_t sync_flags; /* AW+ KR+ the flags of the appl [tx|rx]sync() */ 794b6e66be2SVincenzo Maffione uint32_t pad[12]; /* pad to a 64 bytes cacheline */ 795b6e66be2SVincenzo Maffione }; 796b6e66be2SVincenzo Maffione 797b6e66be2SVincenzo Maffione /* A CSB entry for the application <-- kernel direction. */ 798b6e66be2SVincenzo Maffione struct nm_csb_ktoa { 799b6e66be2SVincenzo Maffione uint32_t hwcur; /* AR+ KW+ the hwcur of the kern netmap_kring */ 800b6e66be2SVincenzo Maffione uint32_t hwtail; /* AR+ KW+ the hwtail of the kern netmap_kring */ 801b6e66be2SVincenzo Maffione uint32_t kern_need_kick; /* AR+ KW+ appl-->kern notification enable */ 802b6e66be2SVincenzo Maffione uint32_t pad[13]; 803b6e66be2SVincenzo Maffione }; 804b6e66be2SVincenzo Maffione 805b6e66be2SVincenzo Maffione #ifdef __linux__ 806b6e66be2SVincenzo Maffione 807b6e66be2SVincenzo Maffione #ifdef __KERNEL__ 808b6e66be2SVincenzo Maffione #define nm_stst_barrier smp_wmb 809f79ba6d7SVincenzo Maffione #define nm_ldld_barrier smp_rmb 810f79ba6d7SVincenzo Maffione #define nm_stld_barrier smp_mb 811b6e66be2SVincenzo Maffione #else /* !__KERNEL__ */ 812b6e66be2SVincenzo Maffione static inline void nm_stst_barrier(void) 813b6e66be2SVincenzo Maffione { 814b6e66be2SVincenzo Maffione /* A memory barrier with release semantic has the combined 815b6e66be2SVincenzo Maffione * effect of a store-store barrier and a load-store barrier, 816b6e66be2SVincenzo Maffione * which is fine for us. */ 817b6e66be2SVincenzo Maffione __atomic_thread_fence(__ATOMIC_RELEASE); 818b6e66be2SVincenzo Maffione } 819f79ba6d7SVincenzo Maffione static inline void nm_ldld_barrier(void) 820f79ba6d7SVincenzo Maffione { 821f79ba6d7SVincenzo Maffione /* A memory barrier with acquire semantic has the combined 822f79ba6d7SVincenzo Maffione * effect of a load-load barrier and a store-load barrier, 823f79ba6d7SVincenzo Maffione * which is fine for us. */ 824f79ba6d7SVincenzo Maffione __atomic_thread_fence(__ATOMIC_ACQUIRE); 825f79ba6d7SVincenzo Maffione } 826b6e66be2SVincenzo Maffione #endif /* !__KERNEL__ */ 827b6e66be2SVincenzo Maffione 828b6e66be2SVincenzo Maffione #elif defined(__FreeBSD__) 829b6e66be2SVincenzo Maffione 830b6e66be2SVincenzo Maffione #ifdef _KERNEL 831b6e66be2SVincenzo Maffione #define nm_stst_barrier atomic_thread_fence_rel 832f79ba6d7SVincenzo Maffione #define nm_ldld_barrier atomic_thread_fence_acq 833f79ba6d7SVincenzo Maffione #define nm_stld_barrier atomic_thread_fence_seq_cst 834b6e66be2SVincenzo Maffione #else /* !_KERNEL */ 835*a6d768d8SVincenzo Maffione 836*a6d768d8SVincenzo Maffione #ifdef __cplusplus 837*a6d768d8SVincenzo Maffione #include <atomic> 838*a6d768d8SVincenzo Maffione using std::memory_order_release; 839*a6d768d8SVincenzo Maffione using std::memory_order_acquire; 840*a6d768d8SVincenzo Maffione 841*a6d768d8SVincenzo Maffione #else /* __cplusplus */ 8421d9ec3eeSVincenzo Maffione #include <stdatomic.h> 843*a6d768d8SVincenzo Maffione #endif /* __cplusplus */ 844*a6d768d8SVincenzo Maffione 845b6e66be2SVincenzo Maffione static inline void nm_stst_barrier(void) 846b6e66be2SVincenzo Maffione { 8471d9ec3eeSVincenzo Maffione atomic_thread_fence(memory_order_release); 848b6e66be2SVincenzo Maffione } 849f79ba6d7SVincenzo Maffione static inline void nm_ldld_barrier(void) 850f79ba6d7SVincenzo Maffione { 851f79ba6d7SVincenzo Maffione atomic_thread_fence(memory_order_acquire); 852f79ba6d7SVincenzo Maffione } 853b6e66be2SVincenzo Maffione #endif /* !_KERNEL */ 854b6e66be2SVincenzo Maffione 855b6e66be2SVincenzo Maffione #else /* !__linux__ && !__FreeBSD__ */ 856b6e66be2SVincenzo Maffione #error "OS not supported" 857b6e66be2SVincenzo Maffione #endif /* !__linux__ && !__FreeBSD__ */ 858b6e66be2SVincenzo Maffione 859b6e66be2SVincenzo Maffione /* Application side of sync-kloop: Write ring pointers (cur, head) to the CSB. 860b6e66be2SVincenzo Maffione * This routine is coupled with sync_kloop_kernel_read(). */ 861b6e66be2SVincenzo Maffione static inline void 862b6e66be2SVincenzo Maffione nm_sync_kloop_appl_write(struct nm_csb_atok *atok, uint32_t cur, 863b6e66be2SVincenzo Maffione uint32_t head) 864b6e66be2SVincenzo Maffione { 865f79ba6d7SVincenzo Maffione /* Issue a first store-store barrier to make sure writes to the 866f79ba6d7SVincenzo Maffione * netmap ring do not overcome updates on atok->cur and atok->head. */ 867f79ba6d7SVincenzo Maffione nm_stst_barrier(); 868f79ba6d7SVincenzo Maffione 869b6e66be2SVincenzo Maffione /* 870b6e66be2SVincenzo Maffione * We need to write cur and head to the CSB but we cannot do it atomically. 871b6e66be2SVincenzo Maffione * There is no way we can prevent the host from reading the updated value 872b6e66be2SVincenzo Maffione * of one of the two and the old value of the other. However, if we make 873b6e66be2SVincenzo Maffione * sure that the host never reads a value of head more recent than the 874b6e66be2SVincenzo Maffione * value of cur we are safe. We can allow the host to read a value of cur 875b6e66be2SVincenzo Maffione * more recent than the value of head, since in the netmap ring cur can be 876b6e66be2SVincenzo Maffione * ahead of head and cur cannot wrap around head because it must be behind 877b6e66be2SVincenzo Maffione * tail. Inverting the order of writes below could instead result into the 878b6e66be2SVincenzo Maffione * host to think head went ahead of cur, which would cause the sync 879b6e66be2SVincenzo Maffione * prologue to fail. 880b6e66be2SVincenzo Maffione * 881b6e66be2SVincenzo Maffione * The following memory barrier scheme is used to make this happen: 882b6e66be2SVincenzo Maffione * 883b6e66be2SVincenzo Maffione * Guest Host 884b6e66be2SVincenzo Maffione * 885b6e66be2SVincenzo Maffione * STORE(cur) LOAD(head) 886f79ba6d7SVincenzo Maffione * wmb() <-----------> rmb() 887b6e66be2SVincenzo Maffione * STORE(head) LOAD(cur) 888b6e66be2SVincenzo Maffione * 889b6e66be2SVincenzo Maffione */ 890b6e66be2SVincenzo Maffione atok->cur = cur; 891b6e66be2SVincenzo Maffione nm_stst_barrier(); 892b6e66be2SVincenzo Maffione atok->head = head; 893b6e66be2SVincenzo Maffione } 894b6e66be2SVincenzo Maffione 895b6e66be2SVincenzo Maffione /* Application side of sync-kloop: Read kring pointers (hwcur, hwtail) from 896b6e66be2SVincenzo Maffione * the CSB. This routine is coupled with sync_kloop_kernel_write(). */ 897b6e66be2SVincenzo Maffione static inline void 898b6e66be2SVincenzo Maffione nm_sync_kloop_appl_read(struct nm_csb_ktoa *ktoa, uint32_t *hwtail, 899b6e66be2SVincenzo Maffione uint32_t *hwcur) 900b6e66be2SVincenzo Maffione { 901b6e66be2SVincenzo Maffione /* 902b6e66be2SVincenzo Maffione * We place a memory barrier to make sure that the update of hwtail never 903b6e66be2SVincenzo Maffione * overtakes the update of hwcur. 904b6e66be2SVincenzo Maffione * (see explanation in sync_kloop_kernel_write). 905b6e66be2SVincenzo Maffione */ 906b6e66be2SVincenzo Maffione *hwtail = ktoa->hwtail; 907f79ba6d7SVincenzo Maffione nm_ldld_barrier(); 908b6e66be2SVincenzo Maffione *hwcur = ktoa->hwcur; 909f79ba6d7SVincenzo Maffione 910f79ba6d7SVincenzo Maffione /* Make sure that loads from ktoa->hwtail and ktoa->hwcur are not delayed 911f79ba6d7SVincenzo Maffione * after the loads from the netmap ring. */ 912f79ba6d7SVincenzo Maffione nm_ldld_barrier(); 913b6e66be2SVincenzo Maffione } 914b6e66be2SVincenzo Maffione 915b6e66be2SVincenzo Maffione /* 9162ff91c17SVincenzo Maffione * data for NETMAP_REQ_OPT_* options 9172ff91c17SVincenzo Maffione */ 9182ff91c17SVincenzo Maffione 919b6e66be2SVincenzo Maffione struct nmreq_opt_sync_kloop_eventfds { 920b6e66be2SVincenzo Maffione struct nmreq_option nro_opt; /* common header */ 921b6e66be2SVincenzo Maffione /* An array of N entries for bidirectional notifications between 922b6e66be2SVincenzo Maffione * the kernel loop and the application. The number of entries and 923b6e66be2SVincenzo Maffione * their order must agree with the CSB arrays passed in the 924b6e66be2SVincenzo Maffione * NETMAP_REQ_OPT_CSB option. Each entry contains a file descriptor 925b6e66be2SVincenzo Maffione * backed by an eventfd. 9265faab778SVincenzo Maffione * 9275faab778SVincenzo Maffione * If any of the 'ioeventfd' entries is < 0, the event loop uses 9285faab778SVincenzo Maffione * the sleeping synchronization strategy (according to sleep_us), 9295faab778SVincenzo Maffione * and keeps kern_need_kick always disabled. 9305faab778SVincenzo Maffione * Each 'irqfd' can be < 0, and in that case the corresponding queue 9315faab778SVincenzo Maffione * is never notified. 932b6e66be2SVincenzo Maffione */ 933b6e66be2SVincenzo Maffione struct { 934b6e66be2SVincenzo Maffione /* Notifier for the application --> kernel loop direction. */ 935b6e66be2SVincenzo Maffione int32_t ioeventfd; 936b6e66be2SVincenzo Maffione /* Notifier for the kernel loop --> application direction. */ 937b6e66be2SVincenzo Maffione int32_t irqfd; 938b6e66be2SVincenzo Maffione } eventfds[0]; 939b6e66be2SVincenzo Maffione }; 940b6e66be2SVincenzo Maffione 9415faab778SVincenzo Maffione struct nmreq_opt_sync_kloop_mode { 9425faab778SVincenzo Maffione struct nmreq_option nro_opt; /* common header */ 9435faab778SVincenzo Maffione #define NM_OPT_SYNC_KLOOP_DIRECT_TX (1 << 0) 9445faab778SVincenzo Maffione #define NM_OPT_SYNC_KLOOP_DIRECT_RX (1 << 1) 9455faab778SVincenzo Maffione uint32_t mode; 9465faab778SVincenzo Maffione }; 9475faab778SVincenzo Maffione 9482ff91c17SVincenzo Maffione struct nmreq_opt_extmem { 9492ff91c17SVincenzo Maffione struct nmreq_option nro_opt; /* common header */ 9502ff91c17SVincenzo Maffione uint64_t nro_usrptr; /* (in) ptr to usr memory */ 9512ff91c17SVincenzo Maffione struct nmreq_pools_info nro_info; /* (in/out) */ 9524bf50f18SLuigi Rizzo }; 9534bf50f18SLuigi Rizzo 954b6e66be2SVincenzo Maffione struct nmreq_opt_csb { 955b6e66be2SVincenzo Maffione struct nmreq_option nro_opt; 956b6e66be2SVincenzo Maffione 957b6e66be2SVincenzo Maffione /* Array of CSB entries for application --> kernel communication 958b6e66be2SVincenzo Maffione * (N entries). */ 959b6e66be2SVincenzo Maffione uint64_t csb_atok; 960b6e66be2SVincenzo Maffione 961b6e66be2SVincenzo Maffione /* Array of CSB entries for kernel --> application communication 962b6e66be2SVincenzo Maffione * (N entries). */ 963b6e66be2SVincenzo Maffione uint64_t csb_ktoa; 964b6e66be2SVincenzo Maffione }; 965b6e66be2SVincenzo Maffione 966*a6d768d8SVincenzo Maffione /* option NETMAP_REQ_OPT_OFFSETS */ 967*a6d768d8SVincenzo Maffione struct nmreq_opt_offsets { 968*a6d768d8SVincenzo Maffione struct nmreq_option nro_opt; 969*a6d768d8SVincenzo Maffione /* the user must declare the maximum offset value that she is 970*a6d768d8SVincenzo Maffione * going to put into the offset slot-fields. Any larger value 971*a6d768d8SVincenzo Maffione * found at runtime will be cropped. On output the (possibly 972*a6d768d8SVincenzo Maffione * higher) effective max value is returned. 973*a6d768d8SVincenzo Maffione */ 974*a6d768d8SVincenzo Maffione uint64_t nro_max_offset; 975*a6d768d8SVincenzo Maffione /* optional initial offset value, to be set in all slots. */ 976*a6d768d8SVincenzo Maffione uint64_t nro_initial_offset; 977*a6d768d8SVincenzo Maffione /* number of bits in the lower part of the 'ptr' field to be 978*a6d768d8SVincenzo Maffione * used as the offset field. On output the (possibily larger) 979*a6d768d8SVincenzo Maffione * effective number of bits is returned. 980*a6d768d8SVincenzo Maffione * 0 means: use the whole ptr field. 981*a6d768d8SVincenzo Maffione */ 982*a6d768d8SVincenzo Maffione uint32_t nro_offset_bits; 983*a6d768d8SVincenzo Maffione /* required alignment for the beginning of the packets 984*a6d768d8SVincenzo Maffione * (base of the buffer plus offset) in the TX slots. 985*a6d768d8SVincenzo Maffione */ 986*a6d768d8SVincenzo Maffione uint32_t nro_tx_align; 987*a6d768d8SVincenzo Maffione /* Reserved: set to zero. */ 988*a6d768d8SVincenzo Maffione uint64_t nro_min_gap; 989*a6d768d8SVincenzo Maffione }; 990*a6d768d8SVincenzo Maffione 99168b8534bSLuigi Rizzo #endif /* _NET_NETMAP_H_ */ 992