1*22ce4affSfengbojiang /*- 2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*22ce4affSfengbojiang * 4*22ce4affSfengbojiang * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved. 5*22ce4affSfengbojiang * 6*22ce4affSfengbojiang * Redistribution and use in source and binary forms, with or without 7*22ce4affSfengbojiang * modification, are permitted provided that the following conditions 8*22ce4affSfengbojiang * are met: 9*22ce4affSfengbojiang * 10*22ce4affSfengbojiang * 1. Redistributions of source code must retain the above copyright 11*22ce4affSfengbojiang * notice, this list of conditions and the following disclaimer. 12*22ce4affSfengbojiang * 2. Redistributions in binary form must reproduce the above copyright 13*22ce4affSfengbojiang * notice, this list of conditions and the following disclaimer in the 14*22ce4affSfengbojiang * documentation and/or other materials provided with the distribution. 15*22ce4affSfengbojiang * 16*22ce4affSfengbojiang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND 17*22ce4affSfengbojiang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*22ce4affSfengbojiang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*22ce4affSfengbojiang * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*22ce4affSfengbojiang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*22ce4affSfengbojiang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*22ce4affSfengbojiang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*22ce4affSfengbojiang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*22ce4affSfengbojiang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*22ce4affSfengbojiang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*22ce4affSfengbojiang * SUCH DAMAGE. 27*22ce4affSfengbojiang */ 28*22ce4affSfengbojiang 29*22ce4affSfengbojiang #ifndef _NET_NETMAP_LEGACY_H_ 30*22ce4affSfengbojiang #define _NET_NETMAP_LEGACY_H_ 31*22ce4affSfengbojiang 32*22ce4affSfengbojiang /* 33*22ce4affSfengbojiang * $FreeBSD$ 34*22ce4affSfengbojiang * 35*22ce4affSfengbojiang * ioctl names and related fields 36*22ce4affSfengbojiang * 37*22ce4affSfengbojiang * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues, 38*22ce4affSfengbojiang * whose identity is set in NIOCREGIF through nr_ringid. 39*22ce4affSfengbojiang * These are non blocking and take no argument. 40*22ce4affSfengbojiang * 41*22ce4affSfengbojiang * NIOCGINFO takes a struct ifreq, the interface name is the input, 42*22ce4affSfengbojiang * the outputs are number of queues and number of descriptor 43*22ce4affSfengbojiang * for each queue (useful to set number of threads etc.). 44*22ce4affSfengbojiang * The info returned is only advisory and may change before 45*22ce4affSfengbojiang * the interface is bound to a file descriptor. 46*22ce4affSfengbojiang * 47*22ce4affSfengbojiang * NIOCREGIF takes an interface name within a struct nmre, 48*22ce4affSfengbojiang * and activates netmap mode on the interface (if possible). 49*22ce4affSfengbojiang * 50*22ce4affSfengbojiang * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we 51*22ce4affSfengbojiang * can pass it down to other NIC-related ioctls. 52*22ce4affSfengbojiang * 53*22ce4affSfengbojiang * The actual argument (struct nmreq) has a number of options to request 54*22ce4affSfengbojiang * different functions. 55*22ce4affSfengbojiang * The following are used in NIOCREGIF when nr_cmd == 0: 56*22ce4affSfengbojiang * 57*22ce4affSfengbojiang * nr_name (in) 58*22ce4affSfengbojiang * The name of the port (em0, valeXXX:YYY, etc.) 59*22ce4affSfengbojiang * limited to IFNAMSIZ for backward compatibility. 60*22ce4affSfengbojiang * 61*22ce4affSfengbojiang * nr_version (in/out) 62*22ce4affSfengbojiang * Must match NETMAP_API as used in the kernel, error otherwise. 63*22ce4affSfengbojiang * Always returns the desired value on output. 64*22ce4affSfengbojiang * 65*22ce4affSfengbojiang * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out) 66*22ce4affSfengbojiang * On input, non-zero values may be used to reconfigure the port 67*22ce4affSfengbojiang * according to the requested values, but this is not guaranteed. 68*22ce4affSfengbojiang * On output the actual values in use are reported. 69*22ce4affSfengbojiang * 70*22ce4affSfengbojiang * nr_ringid (in) 71*22ce4affSfengbojiang * Indicates how rings should be bound to the file descriptors. 72*22ce4affSfengbojiang * If nr_flags != 0, then the low bits (in NETMAP_RING_MASK) 73*22ce4affSfengbojiang * are used to indicate the ring number, and nr_flags specifies 74*22ce4affSfengbojiang * the actual rings to bind. NETMAP_NO_TX_POLL is unaffected. 75*22ce4affSfengbojiang * 76*22ce4affSfengbojiang * NOTE: THE FOLLOWING (nr_flags == 0) IS DEPRECATED: 77*22ce4affSfengbojiang * If nr_flags == 0, NETMAP_HW_RING and NETMAP_SW_RING control 78*22ce4affSfengbojiang * the binding as follows: 79*22ce4affSfengbojiang * 0 (default) binds all physical rings 80*22ce4affSfengbojiang * NETMAP_HW_RING | ring number binds a single ring pair 81*22ce4affSfengbojiang * NETMAP_SW_RING binds only the host tx/rx rings 82*22ce4affSfengbojiang * 83*22ce4affSfengbojiang * NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push 84*22ce4affSfengbojiang * packets on tx rings only if POLLOUT is set. 85*22ce4affSfengbojiang * The default is to push any pending packet. 86*22ce4affSfengbojiang * 87*22ce4affSfengbojiang * NETMAP_DO_RX_POLL can be OR-ed to make select()/poll() release 88*22ce4affSfengbojiang * packets on rx rings also when POLLIN is NOT set. 89*22ce4affSfengbojiang * The default is to touch the rx ring only with POLLIN. 90*22ce4affSfengbojiang * Note that this is the opposite of TX because it 91*22ce4affSfengbojiang * reflects the common usage. 92*22ce4affSfengbojiang * 93*22ce4affSfengbojiang * NOTE: NETMAP_PRIV_MEM IS DEPRECATED, use nr_arg2 instead. 94*22ce4affSfengbojiang * NETMAP_PRIV_MEM is set on return for ports that do not use 95*22ce4affSfengbojiang * the global memory allocator. 96*22ce4affSfengbojiang * This information is not significant and applications 97*22ce4affSfengbojiang * should look at the region id in nr_arg2 98*22ce4affSfengbojiang * 99*22ce4affSfengbojiang * nr_flags is the recommended mode to indicate which rings should 100*22ce4affSfengbojiang * be bound to a file descriptor. Values are NR_REG_* 101*22ce4affSfengbojiang * 102*22ce4affSfengbojiang * nr_arg1 (in) Reserved. 103*22ce4affSfengbojiang * 104*22ce4affSfengbojiang * nr_arg2 (in/out) The identity of the memory region used. 105*22ce4affSfengbojiang * On input, 0 means the system decides autonomously, 106*22ce4affSfengbojiang * other values may try to select a specific region. 107*22ce4affSfengbojiang * On return the actual value is reported. 108*22ce4affSfengbojiang * Region '1' is the global allocator, normally shared 109*22ce4affSfengbojiang * by all interfaces. Other values are private regions. 110*22ce4affSfengbojiang * If two ports the same region zero-copy is possible. 111*22ce4affSfengbojiang * 112*22ce4affSfengbojiang * nr_arg3 (in/out) number of extra buffers to be allocated. 113*22ce4affSfengbojiang * 114*22ce4affSfengbojiang * 115*22ce4affSfengbojiang * 116*22ce4affSfengbojiang * nr_cmd (in) if non-zero indicates a special command: 117*22ce4affSfengbojiang * NETMAP_BDG_ATTACH and nr_name = vale*:ifname 118*22ce4affSfengbojiang * attaches the NIC to the switch; nr_ringid specifies 119*22ce4affSfengbojiang * which rings to use. Used by valectl -a ... 120*22ce4affSfengbojiang * nr_arg1 = NETMAP_BDG_HOST also attaches the host port 121*22ce4affSfengbojiang * as in valectl -h ... 122*22ce4affSfengbojiang * 123*22ce4affSfengbojiang * NETMAP_BDG_DETACH and nr_name = vale*:ifname 124*22ce4affSfengbojiang * disconnects a previously attached NIC. 125*22ce4affSfengbojiang * Used by valectl -d ... 126*22ce4affSfengbojiang * 127*22ce4affSfengbojiang * NETMAP_BDG_LIST 128*22ce4affSfengbojiang * list the configuration of VALE switches. 129*22ce4affSfengbojiang * 130*22ce4affSfengbojiang * NETMAP_BDG_VNET_HDR 131*22ce4affSfengbojiang * Set the virtio-net header length used by the client 132*22ce4affSfengbojiang * of a VALE switch port. 133*22ce4affSfengbojiang * 134*22ce4affSfengbojiang * NETMAP_BDG_NEWIF 135*22ce4affSfengbojiang * create a persistent VALE port with name nr_name. 136*22ce4affSfengbojiang * Used by valectl -n ... 137*22ce4affSfengbojiang * 138*22ce4affSfengbojiang * NETMAP_BDG_DELIF 139*22ce4affSfengbojiang * delete a persistent VALE port. Used by valectl -d ... 140*22ce4affSfengbojiang * 141*22ce4affSfengbojiang * nr_arg1, nr_arg2, nr_arg3 (in/out) command specific 142*22ce4affSfengbojiang * 143*22ce4affSfengbojiang * 144*22ce4affSfengbojiang * 145*22ce4affSfengbojiang */ 146*22ce4affSfengbojiang 147*22ce4affSfengbojiang /* 148*22ce4affSfengbojiang * struct nmreq overlays a struct ifreq (just the name) 149*22ce4affSfengbojiang */ 150*22ce4affSfengbojiang struct nmreq { 151*22ce4affSfengbojiang char nr_name[IFNAMSIZ]; 152*22ce4affSfengbojiang uint32_t nr_version; /* API version */ 153*22ce4affSfengbojiang uint32_t nr_offset; /* nifp offset in the shared region */ 154*22ce4affSfengbojiang uint32_t nr_memsize; /* size of the shared region */ 155*22ce4affSfengbojiang uint32_t nr_tx_slots; /* slots in tx rings */ 156*22ce4affSfengbojiang uint32_t nr_rx_slots; /* slots in rx rings */ 157*22ce4affSfengbojiang uint16_t nr_tx_rings; /* number of tx rings */ 158*22ce4affSfengbojiang uint16_t nr_rx_rings; /* number of rx rings */ 159*22ce4affSfengbojiang 160*22ce4affSfengbojiang uint16_t nr_ringid; /* ring(s) we care about */ 161*22ce4affSfengbojiang #define NETMAP_HW_RING 0x4000 /* single NIC ring pair */ 162*22ce4affSfengbojiang #define NETMAP_SW_RING 0x2000 /* only host ring pair */ 163*22ce4affSfengbojiang 164*22ce4affSfengbojiang #define NETMAP_RING_MASK 0x0fff /* the ring number */ 165*22ce4affSfengbojiang 166*22ce4affSfengbojiang #define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */ 167*22ce4affSfengbojiang 168*22ce4affSfengbojiang #define NETMAP_DO_RX_POLL 0x8000 /* DO automatic rxsync on poll */ 169*22ce4affSfengbojiang 170*22ce4affSfengbojiang uint16_t nr_cmd; 171*22ce4affSfengbojiang #define NETMAP_BDG_ATTACH 1 /* attach the NIC */ 172*22ce4affSfengbojiang #define NETMAP_BDG_DETACH 2 /* detach the NIC */ 173*22ce4affSfengbojiang #define NETMAP_BDG_REGOPS 3 /* register bridge callbacks */ 174*22ce4affSfengbojiang #define NETMAP_BDG_LIST 4 /* get bridge's info */ 175*22ce4affSfengbojiang #define NETMAP_BDG_VNET_HDR 5 /* set the port virtio-net-hdr length */ 176*22ce4affSfengbojiang #define NETMAP_BDG_NEWIF 6 /* create a virtual port */ 177*22ce4affSfengbojiang #define NETMAP_BDG_DELIF 7 /* destroy a virtual port */ 178*22ce4affSfengbojiang #define NETMAP_PT_HOST_CREATE 8 /* create ptnetmap kthreads */ 179*22ce4affSfengbojiang #define NETMAP_PT_HOST_DELETE 9 /* delete ptnetmap kthreads */ 180*22ce4affSfengbojiang #define NETMAP_BDG_POLLING_ON 10 /* delete polling kthread */ 181*22ce4affSfengbojiang #define NETMAP_BDG_POLLING_OFF 11 /* delete polling kthread */ 182*22ce4affSfengbojiang #define NETMAP_VNET_HDR_GET 12 /* get the port virtio-net-hdr length */ 183*22ce4affSfengbojiang uint16_t nr_arg1; /* extra arguments */ 184*22ce4affSfengbojiang #define NETMAP_BDG_HOST 1 /* nr_arg1 value for NETMAP_BDG_ATTACH */ 185*22ce4affSfengbojiang 186*22ce4affSfengbojiang uint16_t nr_arg2; /* id of the memory allocator */ 187*22ce4affSfengbojiang uint32_t nr_arg3; /* req. extra buffers in NIOCREGIF */ 188*22ce4affSfengbojiang uint32_t nr_flags; /* specify NR_REG_* mode and other flags */ 189*22ce4affSfengbojiang #define NR_REG_MASK 0xf /* to extract NR_REG_* mode from nr_flags */ 190*22ce4affSfengbojiang /* various modes, extends nr_ringid */ 191*22ce4affSfengbojiang uint32_t spare2[1]; 192*22ce4affSfengbojiang }; 193*22ce4affSfengbojiang 194*22ce4affSfengbojiang #ifdef _WIN32 195*22ce4affSfengbojiang /* 196*22ce4affSfengbojiang * Windows does not have _IOWR(). _IO(), _IOW() and _IOR() are defined 197*22ce4affSfengbojiang * in ws2def.h but not sure if they are in the form we need. 198*22ce4affSfengbojiang * We therefore redefine them in a convenient way to use for DeviceIoControl 199*22ce4affSfengbojiang * signatures. 200*22ce4affSfengbojiang */ 201*22ce4affSfengbojiang #undef _IO // ws2def.h 202*22ce4affSfengbojiang #define _WIN_NM_IOCTL_TYPE 40000 203*22ce4affSfengbojiang #define _IO(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \ 204*22ce4affSfengbojiang METHOD_BUFFERED, FILE_ANY_ACCESS ) 205*22ce4affSfengbojiang #define _IO_direct(_c, _n) CTL_CODE(_WIN_NM_IOCTL_TYPE, ((_n) + 0x800) , \ 206*22ce4affSfengbojiang METHOD_OUT_DIRECT, FILE_ANY_ACCESS ) 207*22ce4affSfengbojiang 208*22ce4affSfengbojiang #define _IOWR(_c, _n, _s) _IO(_c, _n) 209*22ce4affSfengbojiang 210*22ce4affSfengbojiang /* We havesome internal sysctl in addition to the externally visible ones */ 211*22ce4affSfengbojiang #define NETMAP_MMAP _IO_direct('i', 160) // note METHOD_OUT_DIRECT 212*22ce4affSfengbojiang #define NETMAP_POLL _IO('i', 162) 213*22ce4affSfengbojiang 214*22ce4affSfengbojiang /* and also two setsockopt for sysctl emulation */ 215*22ce4affSfengbojiang #define NETMAP_SETSOCKOPT _IO('i', 140) 216*22ce4affSfengbojiang #define NETMAP_GETSOCKOPT _IO('i', 141) 217*22ce4affSfengbojiang 218*22ce4affSfengbojiang /* These linknames are for the Netmap Core Driver */ 219*22ce4affSfengbojiang #define NETMAP_NT_DEVICE_NAME L"\\Device\\NETMAP" 220*22ce4affSfengbojiang #define NETMAP_DOS_DEVICE_NAME L"\\DosDevices\\netmap" 221*22ce4affSfengbojiang 222*22ce4affSfengbojiang /* Definition of a structure used to pass a virtual address within an IOCTL */ 223*22ce4affSfengbojiang typedef struct _MEMORY_ENTRY { 224*22ce4affSfengbojiang PVOID pUsermodeVirtualAddress; 225*22ce4affSfengbojiang } MEMORY_ENTRY, *PMEMORY_ENTRY; 226*22ce4affSfengbojiang 227*22ce4affSfengbojiang typedef struct _POLL_REQUEST_DATA { 228*22ce4affSfengbojiang int events; 229*22ce4affSfengbojiang int timeout; 230*22ce4affSfengbojiang int revents; 231*22ce4affSfengbojiang } POLL_REQUEST_DATA; 232*22ce4affSfengbojiang #endif /* _WIN32 */ 233*22ce4affSfengbojiang 234*22ce4affSfengbojiang /* 235*22ce4affSfengbojiang * Opaque structure that is passed to an external kernel 236*22ce4affSfengbojiang * module via ioctl(fd, NIOCCONFIG, req) for a user-owned 237*22ce4affSfengbojiang * bridge port (at this point ephemeral VALE interface). 238*22ce4affSfengbojiang */ 239*22ce4affSfengbojiang #define NM_IFRDATA_LEN 256 240*22ce4affSfengbojiang struct nm_ifreq { 241*22ce4affSfengbojiang char nifr_name[IFNAMSIZ]; 242*22ce4affSfengbojiang char data[NM_IFRDATA_LEN]; 243*22ce4affSfengbojiang }; 244*22ce4affSfengbojiang 245*22ce4affSfengbojiang /* 246*22ce4affSfengbojiang * FreeBSD uses the size value embedded in the _IOWR to determine 247*22ce4affSfengbojiang * how much to copy in/out. So we need it to match the actual 248*22ce4affSfengbojiang * data structure we pass. We put some spares in the structure 249*22ce4affSfengbojiang * to ease compatibility with other versions 250*22ce4affSfengbojiang */ 251*22ce4affSfengbojiang #define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */ 252*22ce4affSfengbojiang #define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */ 253*22ce4affSfengbojiang #define NIOCCONFIG _IOWR('i',150, struct nm_ifreq) /* for ext. modules */ 254*22ce4affSfengbojiang 255*22ce4affSfengbojiang #endif /* _NET_NETMAP_LEGACY_H_ */ 256