168b8534bSLuigi Rizzo /* 2f18be576SLuigi Rizzo * Copyright (C) 2011-2013 Matteo Landi, Luigi Rizzo. All rights reserved. 368b8534bSLuigi Rizzo * 468b8534bSLuigi Rizzo * Redistribution and use in source and binary forms, with or without 5*f9790aebSLuigi Rizzo * modification, are permitted provided that the following conditions 6*f9790aebSLuigi 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 12*f9790aebSLuigi Rizzo * documentation and/or other materials provided with the distribution. 1368b8534bSLuigi Rizzo * 14*f9790aebSLuigi 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 16*f9790aebSLuigi Rizzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*f9790aebSLuigi Rizzo * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*f9790aebSLuigi Rizzo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*f9790aebSLuigi Rizzo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*f9790aebSLuigi Rizzo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*f9790aebSLuigi Rizzo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*f9790aebSLuigi Rizzo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*f9790aebSLuigi Rizzo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*f9790aebSLuigi 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 4268b8534bSLuigi Rizzo /* 4368b8534bSLuigi Rizzo * --- Netmap data structures --- 4468b8534bSLuigi Rizzo * 45ce3ee1e7SLuigi Rizzo * The userspace data structures used by netmap are shown below. 46ce3ee1e7SLuigi Rizzo * They are allocated by the kernel and mmap()ed by userspace threads. 47ce3ee1e7SLuigi Rizzo * Pointers are implemented as memory offsets or indexes, 48ce3ee1e7SLuigi Rizzo * so that they can be easily dereferenced in kernel and userspace. 4968b8534bSLuigi Rizzo 50ce3ee1e7SLuigi Rizzo KERNEL (opaque, obviously) 5168b8534bSLuigi Rizzo 5264ae02c3SLuigi Rizzo ==================================================================== 5364ae02c3SLuigi Rizzo | 54ce3ee1e7SLuigi Rizzo USERSPACE | struct netmap_ring 55ce3ee1e7SLuigi Rizzo +---->+--------------+ 5668b8534bSLuigi Rizzo / | cur | 57ce3ee1e7SLuigi Rizzo struct netmap_if (nifp, 1 per fd) / | avail | 5868b8534bSLuigi Rizzo +---------------+ / | buf_ofs | 59ce3ee1e7SLuigi Rizzo | ni_tx_rings | / +==============+ 60ce3ee1e7SLuigi Rizzo | ni_rx_rings | / | buf_idx, len | slot[0] 61ce3ee1e7SLuigi Rizzo | | / | flags, ptr | 62ce3ee1e7SLuigi Rizzo | | / +--------------+ 63ce3ee1e7SLuigi Rizzo +===============+ / | buf_idx, len | slot[1] 64ce3ee1e7SLuigi Rizzo | txring_ofs[0] | (rel.to nifp)--' | flags, ptr | 65ce3ee1e7SLuigi Rizzo | txring_ofs[1] | +--------------+ 66ce3ee1e7SLuigi Rizzo (ni_tx_rings+1 entries) (num_slots entries) 67ce3ee1e7SLuigi Rizzo | txring_ofs[t] | | buf_idx, len | slot[n-1] 68ce3ee1e7SLuigi Rizzo +---------------+ | flags, ptr | 69ce3ee1e7SLuigi Rizzo | rxring_ofs[0] | +--------------+ 7068b8534bSLuigi Rizzo | rxring_ofs[1] | 71ce3ee1e7SLuigi Rizzo (ni_rx_rings+1 entries) 72ce3ee1e7SLuigi Rizzo | rxring_ofs[r] | 7368b8534bSLuigi Rizzo +---------------+ 7468b8534bSLuigi Rizzo 75ce3ee1e7SLuigi Rizzo * For each "interface" (NIC, host stack, VALE switch port) attached to a 76ce3ee1e7SLuigi Rizzo * file descriptor, the mmap()ed region contains a (logically readonly) 77ce3ee1e7SLuigi Rizzo * struct netmap_if pointing to struct netmap_ring's. 78ce3ee1e7SLuigi Rizzo * There is one netmap_ring per physical NIC ring, plus one tx/rx ring 79ce3ee1e7SLuigi Rizzo * pair attached to the host stack (this pair is unused for VALE ports). 80ce3ee1e7SLuigi Rizzo * 81ce3ee1e7SLuigi Rizzo * All physical/host stack ports share the same memory region, 82ce3ee1e7SLuigi Rizzo * so that zero-copy can be implemented between them. 83ce3ee1e7SLuigi Rizzo * VALE switch ports instead have separate memory regions. 84ce3ee1e7SLuigi Rizzo * 85ce3ee1e7SLuigi Rizzo * The netmap_ring is the userspace-visible replica of the NIC ring. 86ce3ee1e7SLuigi Rizzo * Each slot has the index of a buffer (MTU-sized and residing in the 87ce3ee1e7SLuigi Rizzo * mmapped region), its length and some flags. An extra 64-bit pointer 88ce3ee1e7SLuigi Rizzo * is provided for user-supplied buffers in the tx path. 89ce3ee1e7SLuigi Rizzo * 9068b8534bSLuigi Rizzo * In user space, the buffer address is computed as 9164ae02c3SLuigi Rizzo * (char *)ring + buf_ofs + index*NETMAP_BUF_SIZE 92ce3ee1e7SLuigi Rizzo */ 93ce3ee1e7SLuigi Rizzo 94ce3ee1e7SLuigi Rizzo /* 95ce3ee1e7SLuigi Rizzo * struct netmap_slot is a buffer descriptor 9668b8534bSLuigi Rizzo * 97ce3ee1e7SLuigi Rizzo * buf_idx the index of the buffer associated to the slot. 98ce3ee1e7SLuigi Rizzo * len the length of the payload 99ce3ee1e7SLuigi Rizzo * flags control operation on the slot, as defined below 10001c039a1SLuigi Rizzo * 10101c039a1SLuigi Rizzo * NS_BUF_CHANGED must be set whenever userspace wants 10201c039a1SLuigi Rizzo * to change buf_idx (it might be necessary to 103ce3ee1e7SLuigi Rizzo * reprogram the NIC) 104ce3ee1e7SLuigi Rizzo * 10501c039a1SLuigi Rizzo * NS_REPORT must be set if we want the NIC to generate an interrupt 10601c039a1SLuigi Rizzo * when this slot is used. Leaving it to 0 improves 10701c039a1SLuigi Rizzo * performance. 108ce3ee1e7SLuigi Rizzo * 10901c039a1SLuigi Rizzo * NS_FORWARD if set on a receive ring, and the device is in 11001c039a1SLuigi Rizzo * transparent mode, buffers released with the flag set 11101c039a1SLuigi Rizzo * will be forwarded to the 'other' side (host stack 11201c039a1SLuigi Rizzo * or NIC, respectively) on the next select() or ioctl() 113f18be576SLuigi Rizzo * 11401c039a1SLuigi Rizzo * NS_NO_LEARN on a VALE switch, do not 'learn' the source port for 11501c039a1SLuigi Rizzo * this packet. 116ce3ee1e7SLuigi Rizzo * 117ce3ee1e7SLuigi Rizzo * NS_INDIRECT (tx rings only) data is in a userspace buffer pointed 118ce3ee1e7SLuigi Rizzo * by the ptr field in the slot. 119ce3ee1e7SLuigi Rizzo * 120f18be576SLuigi Rizzo * NS_MOREFRAG Part of a multi-segment frame. The last (or only) 121f18be576SLuigi Rizzo * segment must not have this flag. 122ce3ee1e7SLuigi Rizzo * Only supported on VALE ports. 123ce3ee1e7SLuigi Rizzo * 12401c039a1SLuigi Rizzo * NS_PORT_MASK the high 8 bits of the flag, if not zero, indicate the 12501c039a1SLuigi Rizzo * destination port for the VALE switch, overriding 12601c039a1SLuigi Rizzo * the lookup table. 12768b8534bSLuigi Rizzo */ 12801c039a1SLuigi Rizzo 12968b8534bSLuigi Rizzo struct netmap_slot { 13068b8534bSLuigi Rizzo uint32_t buf_idx; /* buffer index */ 131ce3ee1e7SLuigi Rizzo uint16_t len; /* packet length */ 13268b8534bSLuigi Rizzo uint16_t flags; /* buf changed, etc. */ 133ce3ee1e7SLuigi Rizzo #define NS_BUF_CHANGED 0x0001 /* buf_idx changed */ 13468b8534bSLuigi Rizzo #define NS_REPORT 0x0002 /* ask the hardware to report results 13568b8534bSLuigi Rizzo * e.g. by generating an interrupt 13668b8534bSLuigi Rizzo */ 13701c039a1SLuigi Rizzo #define NS_FORWARD 0x0004 /* pass packet to the other endpoint 13801c039a1SLuigi Rizzo * (host stack or device) 13901c039a1SLuigi Rizzo */ 14001c039a1SLuigi Rizzo #define NS_NO_LEARN 0x0008 141f18be576SLuigi Rizzo #define NS_INDIRECT 0x0010 142f18be576SLuigi Rizzo #define NS_MOREFRAG 0x0020 14301c039a1SLuigi Rizzo #define NS_PORT_SHIFT 8 14401c039a1SLuigi Rizzo #define NS_PORT_MASK (0xff << NS_PORT_SHIFT) 145ce3ee1e7SLuigi Rizzo /* 146ce3ee1e7SLuigi Rizzo * in rx rings, the high 8 bits 147ce3ee1e7SLuigi Rizzo * are the number of fragments. 148ce3ee1e7SLuigi Rizzo */ 149ce3ee1e7SLuigi Rizzo #define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff) 150ce3ee1e7SLuigi Rizzo uint64_t ptr; /* pointer for indirect buffers */ 15168b8534bSLuigi Rizzo }; 15268b8534bSLuigi Rizzo 15368b8534bSLuigi Rizzo /* 154ce3ee1e7SLuigi Rizzo * struct netmap_ring 155ce3ee1e7SLuigi Rizzo * 15668b8534bSLuigi Rizzo * Netmap representation of a TX or RX ring (also known as "queue"). 15768b8534bSLuigi Rizzo * This is a queue implemented as a fixed-size circular array. 15868b8534bSLuigi Rizzo * At the software level, two fields are important: avail and cur. 15968b8534bSLuigi Rizzo * 16068b8534bSLuigi Rizzo * In TX rings: 161ce3ee1e7SLuigi Rizzo * 162ce3ee1e7SLuigi Rizzo * avail tells how many slots are available for transmission. 163ce3ee1e7SLuigi Rizzo * It is updated by the kernel in each netmap system call. 164ce3ee1e7SLuigi Rizzo * It MUST BE decremented by the user when it 165ce3ee1e7SLuigi Rizzo * adds a new packet to send. 166ce3ee1e7SLuigi Rizzo * 16764ae02c3SLuigi Rizzo * cur indicates the slot to use for the next packet 16868b8534bSLuigi Rizzo * to send (i.e. the "tail" of the queue). 169ce3ee1e7SLuigi Rizzo * It MUST BE incremented by the user before 17064ae02c3SLuigi Rizzo * netmap system calls to reflect the number of newly 17164ae02c3SLuigi Rizzo * sent packets. 17264ae02c3SLuigi Rizzo * It is checked by the kernel on netmap system calls 17364ae02c3SLuigi Rizzo * (normally unmodified by the kernel unless invalid). 17468b8534bSLuigi Rizzo * 17568b8534bSLuigi Rizzo * In RX rings: 176ce3ee1e7SLuigi Rizzo * 17768b8534bSLuigi Rizzo * avail is the number of packets available (possibly 0). 178ce3ee1e7SLuigi Rizzo * It is updated by the kernel in each netmap system call. 179ce3ee1e7SLuigi Rizzo * It MUST BE decremented by the user when it 180ce3ee1e7SLuigi Rizzo * consumes a packet. 181ce3ee1e7SLuigi Rizzo * 18264ae02c3SLuigi Rizzo * cur indicates the first slot that contains a packet not 183ce3ee1e7SLuigi Rizzo * yet processed (the "head" of the queue). 184ce3ee1e7SLuigi Rizzo * It MUST BE incremented by the user when it consumes 18568b8534bSLuigi Rizzo * a packet. 186ce3ee1e7SLuigi Rizzo * 18764ae02c3SLuigi Rizzo * reserved indicates the number of buffers before 'cur' 188ce3ee1e7SLuigi Rizzo * that the user has not released yet. Normally 0, 189ce3ee1e7SLuigi Rizzo * it MUST BE incremented by the user when it 19064ae02c3SLuigi Rizzo * does not return the buffer immediately, and decremented 19164ae02c3SLuigi Rizzo * when the buffer is finally freed. 19268b8534bSLuigi Rizzo * 19368b8534bSLuigi Rizzo * 19468b8534bSLuigi Rizzo * DATA OWNERSHIP/LOCKING: 195ce3ee1e7SLuigi Rizzo * The netmap_ring, all slots, and buffers in the range 196ce3ee1e7SLuigi Rizzo * [reserved-cur , cur+avail[ are owned by the user program, 197ce3ee1e7SLuigi Rizzo * and the kernel only touches them in the same thread context 198ce3ee1e7SLuigi Rizzo * during a system call. 199ce3ee1e7SLuigi Rizzo * Other buffers are reserved for use by the NIC's DMA engines. 20001c039a1SLuigi Rizzo * 20101c039a1SLuigi Rizzo * FLAGS 20201c039a1SLuigi Rizzo * NR_TIMESTAMP updates the 'ts' field on each syscall. This is 20301c039a1SLuigi Rizzo * a global timestamp for all packets. 20401c039a1SLuigi Rizzo * NR_RX_TSTMP if set, the last 64 byte in each buffer will 20501c039a1SLuigi Rizzo * contain a timestamp for the frame supplied by 20601c039a1SLuigi Rizzo * the hardware (if supported) 20701c039a1SLuigi Rizzo * NR_FORWARD if set, the NS_FORWARD flag in each slot of the 20801c039a1SLuigi Rizzo * RX ring is checked, and if set the packet is 20901c039a1SLuigi Rizzo * passed to the other side (host stack or device, 21001c039a1SLuigi Rizzo * respectively). This permits bpf-like behaviour 21101c039a1SLuigi Rizzo * or transparency for selected packets. 21268b8534bSLuigi Rizzo */ 21368b8534bSLuigi Rizzo struct netmap_ring { 21468b8534bSLuigi Rizzo /* 215ce3ee1e7SLuigi Rizzo * buf_ofs is meant to be used through macros. 21668b8534bSLuigi Rizzo * It contains the offset of the buffer region from this 21768b8534bSLuigi Rizzo * descriptor. 21868b8534bSLuigi Rizzo */ 21968b8534bSLuigi Rizzo const ssize_t buf_ofs; 22068b8534bSLuigi Rizzo const uint32_t num_slots; /* number of slots in the ring. */ 22168b8534bSLuigi Rizzo uint32_t avail; /* number of usable slots */ 22268b8534bSLuigi Rizzo uint32_t cur; /* 'current' r/w position */ 22364ae02c3SLuigi Rizzo uint32_t reserved; /* not refilled before current */ 22468b8534bSLuigi Rizzo 22568b8534bSLuigi Rizzo const uint16_t nr_buf_size; 22668b8534bSLuigi Rizzo uint16_t flags; 22768b8534bSLuigi Rizzo #define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */ 22801c039a1SLuigi Rizzo #define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */ 22901c039a1SLuigi Rizzo #define NR_RX_TSTMP 0x0008 /* set rx timestamp in slots */ 23068b8534bSLuigi Rizzo 23168b8534bSLuigi Rizzo struct timeval ts; /* time of last *sync() */ 23268b8534bSLuigi Rizzo 23368b8534bSLuigi Rizzo /* the slots follow. This struct has variable size */ 23468b8534bSLuigi Rizzo struct netmap_slot slot[0]; /* array of slots. */ 23568b8534bSLuigi Rizzo }; 23668b8534bSLuigi Rizzo 23768b8534bSLuigi Rizzo 23868b8534bSLuigi Rizzo /* 23968b8534bSLuigi Rizzo * Netmap representation of an interface and its queue(s). 240ce3ee1e7SLuigi Rizzo * This is initialized by the kernel when binding a file 241ce3ee1e7SLuigi Rizzo * descriptor to a port, and should be considered as readonly 242ce3ee1e7SLuigi Rizzo * by user programs. The kernel never uses it. 243ce3ee1e7SLuigi Rizzo * 24468b8534bSLuigi Rizzo * There is one netmap_if for each file descriptor on which we want 245ce3ee1e7SLuigi Rizzo * to select/poll. 24668b8534bSLuigi Rizzo * select/poll operates on one or all pairs depending on the value of 24768b8534bSLuigi Rizzo * nmr_queueid passed on the ioctl. 24868b8534bSLuigi Rizzo */ 24968b8534bSLuigi Rizzo struct netmap_if { 25068b8534bSLuigi Rizzo char ni_name[IFNAMSIZ]; /* name of the interface. */ 251ce3ee1e7SLuigi Rizzo const uint32_t ni_version; /* API version, currently unused */ 252ce3ee1e7SLuigi Rizzo const uint32_t ni_flags; /* properties */ 253ce3ee1e7SLuigi Rizzo #define NI_PRIV_MEM 0x1 /* private memory region */ 254ce3ee1e7SLuigi Rizzo 255ce3ee1e7SLuigi Rizzo const uint32_t ni_rx_rings; /* number of rx rings */ 256ce3ee1e7SLuigi Rizzo const uint32_t ni_tx_rings; /* number of tx rings */ 25768b8534bSLuigi Rizzo /* 25864ae02c3SLuigi Rizzo * The following array contains the offset of each netmap ring 259ce3ee1e7SLuigi Rizzo * from this structure. The first ni_tx_rings+1 entries refer 260ce3ee1e7SLuigi Rizzo * to the tx rings, the next ni_rx_rings+1 refer to the rx rings 26164ae02c3SLuigi Rizzo * (the last entry in each block refers to the host stack rings). 262ce3ee1e7SLuigi Rizzo * The area is filled up by the kernel on NIOCREGIF, 26368b8534bSLuigi Rizzo * and then only read by userspace code. 26468b8534bSLuigi Rizzo */ 26568b8534bSLuigi Rizzo const ssize_t ring_ofs[0]; 26668b8534bSLuigi Rizzo }; 26768b8534bSLuigi Rizzo 26868b8534bSLuigi Rizzo #ifndef NIOCREGIF 26968b8534bSLuigi Rizzo /* 27068b8534bSLuigi Rizzo * ioctl names and related fields 27168b8534bSLuigi Rizzo * 27268b8534bSLuigi Rizzo * NIOCGINFO takes a struct ifreq, the interface name is the input, 27368b8534bSLuigi Rizzo * the outputs are number of queues and number of descriptor 27468b8534bSLuigi Rizzo * for each queue (useful to set number of threads etc.). 275ce3ee1e7SLuigi Rizzo * The info returned is only advisory and may change before 276ce3ee1e7SLuigi Rizzo * the interface is bound to a file descriptor. 27768b8534bSLuigi Rizzo * 27868b8534bSLuigi Rizzo * NIOCREGIF takes an interface name within a struct ifreq, 27968b8534bSLuigi Rizzo * and activates netmap mode on the interface (if possible). 28068b8534bSLuigi Rizzo * 281ce3ee1e7SLuigi Rizzo * nr_name is the name of the interface 282f18be576SLuigi Rizzo * 283ce3ee1e7SLuigi Rizzo * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings 284ce3ee1e7SLuigi Rizzo * indicate the configuration of the port on return. 285f18be576SLuigi Rizzo * 286ce3ee1e7SLuigi Rizzo * On input, non-zero values for nr_tx_rings, nr_tx_slots and the 287ce3ee1e7SLuigi Rizzo * rx counterparts may be used to reconfigure the port according 288ce3ee1e7SLuigi Rizzo * to the requested values, but this is not guaranteed. 289ce3ee1e7SLuigi Rizzo * The actual values are returned on completion of the ioctl(). 290ce3ee1e7SLuigi Rizzo * 291ce3ee1e7SLuigi Rizzo * nr_ringid 292ce3ee1e7SLuigi Rizzo * indicates how rings should be bound to the file descriptors. 293ce3ee1e7SLuigi Rizzo * The default (0) means all physical rings of a NIC are bound. 294ce3ee1e7SLuigi Rizzo * NETMAP_HW_RING plus a ring number lets you bind just 295ce3ee1e7SLuigi Rizzo * a single ring pair. 296ce3ee1e7SLuigi Rizzo * NETMAP_SW_RING binds only the host tx/rx rings 297ce3ee1e7SLuigi Rizzo * NETMAP_NO_TX_POLL prevents select()/poll() from pushing 298ce3ee1e7SLuigi Rizzo * out packets on the tx ring unless POLLOUT is specified. 299ce3ee1e7SLuigi Rizzo * 300ce3ee1e7SLuigi Rizzo * NETMAP_PRIV_MEM is a return value used to indicate that 301ce3ee1e7SLuigi Rizzo * this ring is in a private memory region hence buffer 302ce3ee1e7SLuigi Rizzo * swapping cannot be used 303ce3ee1e7SLuigi Rizzo * 304ce3ee1e7SLuigi Rizzo * nr_cmd is used to configure NICs attached to a VALE switch, 305ce3ee1e7SLuigi Rizzo * or to dump the configuration of a VALE switch. 306ce3ee1e7SLuigi Rizzo * 307ce3ee1e7SLuigi Rizzo * nr_cmd = NETMAP_BDG_ATTACH and nr_name = vale*:ifname 308ce3ee1e7SLuigi Rizzo * attaches the NIC to the switch, with nr_ringid specifying 309ce3ee1e7SLuigi Rizzo * which rings to use 310ce3ee1e7SLuigi Rizzo * 311ce3ee1e7SLuigi Rizzo * nr_cmd = NETMAP_BDG_DETACH and nr_name = vale*:ifname 312ce3ee1e7SLuigi Rizzo * disconnects a previously attached NIC 313ce3ee1e7SLuigi Rizzo * 314ce3ee1e7SLuigi Rizzo * nr_cmd = NETMAP_BDG_LIST is used to list the configuration 315ce3ee1e7SLuigi Rizzo * of VALE switches, with additional arguments. 31668b8534bSLuigi Rizzo * 31768b8534bSLuigi Rizzo * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues, 31868b8534bSLuigi Rizzo * whose identity is set in NIOCREGIF through nr_ringid 319f18be576SLuigi Rizzo * 320f18be576SLuigi Rizzo * NETMAP_API is the API version. 32168b8534bSLuigi Rizzo */ 32268b8534bSLuigi Rizzo 32368b8534bSLuigi Rizzo /* 32468b8534bSLuigi Rizzo * struct nmreq overlays a struct ifreq 32568b8534bSLuigi Rizzo */ 32668b8534bSLuigi Rizzo struct nmreq { 32768b8534bSLuigi Rizzo char nr_name[IFNAMSIZ]; 32864ae02c3SLuigi Rizzo uint32_t nr_version; /* API version */ 329ce3ee1e7SLuigi Rizzo #define NETMAP_API 5 /* current version */ 33068b8534bSLuigi Rizzo uint32_t nr_offset; /* nifp offset in the shared region */ 33168b8534bSLuigi Rizzo uint32_t nr_memsize; /* size of the shared region */ 33264ae02c3SLuigi Rizzo uint32_t nr_tx_slots; /* slots in tx rings */ 33364ae02c3SLuigi Rizzo uint32_t nr_rx_slots; /* slots in rx rings */ 33464ae02c3SLuigi Rizzo uint16_t nr_tx_rings; /* number of tx rings */ 33564ae02c3SLuigi Rizzo uint16_t nr_rx_rings; /* number of rx rings */ 33668b8534bSLuigi Rizzo uint16_t nr_ringid; /* ring(s) we care about */ 337ce3ee1e7SLuigi Rizzo #define NETMAP_PRIV_MEM 0x8000 /* rings use private memory */ 33868b8534bSLuigi Rizzo #define NETMAP_HW_RING 0x4000 /* low bits indicate one hw ring */ 33964ae02c3SLuigi Rizzo #define NETMAP_SW_RING 0x2000 /* process the sw ring */ 34064ae02c3SLuigi Rizzo #define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */ 34168b8534bSLuigi Rizzo #define NETMAP_RING_MASK 0xfff /* the ring number */ 342f18be576SLuigi Rizzo uint16_t nr_cmd; 343f18be576SLuigi Rizzo #define NETMAP_BDG_ATTACH 1 /* attach the NIC */ 344f18be576SLuigi Rizzo #define NETMAP_BDG_DETACH 2 /* detach the NIC */ 345f18be576SLuigi Rizzo #define NETMAP_BDG_LOOKUP_REG 3 /* register lookup function */ 346f18be576SLuigi Rizzo #define NETMAP_BDG_LIST 4 /* get bridge's info */ 347*f9790aebSLuigi Rizzo #define NETMAP_BDG_OFFSET 5 /* set the port offset */ 348f18be576SLuigi Rizzo uint16_t nr_arg1; 349f18be576SLuigi Rizzo #define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */ 350*f9790aebSLuigi Rizzo #define NETMAP_BDG_MAX_OFFSET 12 351f18be576SLuigi Rizzo uint16_t nr_arg2; 352f18be576SLuigi Rizzo uint32_t spare2[3]; 35368b8534bSLuigi Rizzo }; 35468b8534bSLuigi Rizzo 35564ae02c3SLuigi Rizzo /* 35664ae02c3SLuigi Rizzo * FreeBSD uses the size value embedded in the _IOWR to determine 35764ae02c3SLuigi Rizzo * how much to copy in/out. So we need it to match the actual 35864ae02c3SLuigi Rizzo * data structure we pass. We put some spares in the structure 35964ae02c3SLuigi Rizzo * to ease compatibility with other versions 36064ae02c3SLuigi Rizzo */ 36168b8534bSLuigi Rizzo #define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */ 36268b8534bSLuigi Rizzo #define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */ 363ce3ee1e7SLuigi Rizzo #define NIOCUNREGIF _IO('i', 147) /* deprecated. Was interface unregister */ 36468b8534bSLuigi Rizzo #define NIOCTXSYNC _IO('i', 148) /* sync tx queues */ 36568b8534bSLuigi Rizzo #define NIOCRXSYNC _IO('i', 149) /* sync rx queues */ 36668b8534bSLuigi Rizzo #endif /* !NIOCREGIF */ 36768b8534bSLuigi Rizzo 36868b8534bSLuigi Rizzo #endif /* _NET_NETMAP_H_ */ 369