netmap_kern.h (239140) | netmap_kern.h (241719) |
---|---|
1/* 2 * Copyright (C) 2011-2012 Matteo Landi, Luigi Rizzo. All rights reserved. | 1/* 2 * Copyright (C) 2011-2012 Matteo Landi, Luigi Rizzo. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. | 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26/* | 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26/* |
27 * $FreeBSD: head/sys/dev/netmap/netmap_kern.h 239140 2012-08-08 15:27:01Z emaste $ 28 * $Id: netmap_kern.h 11343 2012-07-03 09:08:38Z luigi $ | 27 * $FreeBSD: head/sys/dev/netmap/netmap_kern.h 241719 2012-10-19 04:13:12Z luigi $ 28 * $Id: netmap_kern.h 11829 2012-09-26 04:06:34Z luigi $ |
29 * 30 * The header contains the definitions of constants and function 31 * prototypes used only in kernelspace. 32 */ 33 34#ifndef _NET_NETMAP_KERN_H_ 35#define _NET_NETMAP_KERN_H_ 36 --- 13 unchanged lines hidden (view full) --- 50#define MBUF_LEN(m) ((m)->len) 51#define NM_SEND_UP(ifp, m) netif_rx(m) 52 53#ifndef DEV_NETMAP 54#define DEV_NETMAP 55#endif 56 57/* | 29 * 30 * The header contains the definitions of constants and function 31 * prototypes used only in kernelspace. 32 */ 33 34#ifndef _NET_NETMAP_KERN_H_ 35#define _NET_NETMAP_KERN_H_ 36 --- 13 unchanged lines hidden (view full) --- 50#define MBUF_LEN(m) ((m)->len) 51#define NM_SEND_UP(ifp, m) netif_rx(m) 52 53#ifndef DEV_NETMAP 54#define DEV_NETMAP 55#endif 56 57/* |
58 * IFCAP_NETMAP goes into net_device's flags (if_capabilities) 59 * and priv_flags (if_capenable). The latter used to be 16 bits 60 * up to linux 2.6.36, so we need to use a 16 bit value on older | 58 * IFCAP_NETMAP goes into net_device's priv_flags (if_capenable). 59 * This was 16 bits up to linux 2.6.36, so we need a 16 bit value on older |
61 * platforms and tolerate the clash with IFF_DYNAMIC and IFF_BRIDGE_PORT. | 60 * platforms and tolerate the clash with IFF_DYNAMIC and IFF_BRIDGE_PORT. |
62 * For the 32-bit value, 0x100000 (bit 20) has no clashes up to 3.3.1 | 61 * For the 32-bit value, 0x100000 has no clashes until at least 3.5.1 |
63 */ 64#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) 65#define IFCAP_NETMAP 0x8000 66#else 67#define IFCAP_NETMAP 0x100000 68#endif 69 70#elif defined (__APPLE__) | 62 */ 63#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) 64#define IFCAP_NETMAP 0x8000 65#else 66#define IFCAP_NETMAP 0x100000 67#endif 68 69#elif defined (__APPLE__) |
71#warning apple support is experimental | 70#warning apple support is incomplete. |
72#define likely(x) __builtin_expect(!!(x), 1) 73#define unlikely(x) __builtin_expect(!!(x), 0) 74#define NM_LOCK_T IOLock * 75#define NM_SELINFO_T struct selinfo 76#define MBUF_LEN(m) ((m)->m_pkthdr.len) 77#define NM_SEND_UP(ifp, m) ((ifp)->if_input)(ifp, m) 78 79#else --- 4 unchanged lines hidden (view full) --- 84#define D(format, ...) \ 85 do { \ 86 struct timeval __xxts; \ 87 microtime(&__xxts); \ 88 printf("%03d.%06d %s [%d] " format "\n", \ 89 (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \ 90 __FUNCTION__, __LINE__, ##__VA_ARGS__); \ 91 } while (0) | 71#define likely(x) __builtin_expect(!!(x), 1) 72#define unlikely(x) __builtin_expect(!!(x), 0) 73#define NM_LOCK_T IOLock * 74#define NM_SELINFO_T struct selinfo 75#define MBUF_LEN(m) ((m)->m_pkthdr.len) 76#define NM_SEND_UP(ifp, m) ((ifp)->if_input)(ifp, m) 77 78#else --- 4 unchanged lines hidden (view full) --- 83#define D(format, ...) \ 84 do { \ 85 struct timeval __xxts; \ 86 microtime(&__xxts); \ 87 printf("%03d.%06d %s [%d] " format "\n", \ 88 (int)__xxts.tv_sec % 1000, (int)__xxts.tv_usec, \ 89 __FUNCTION__, __LINE__, ##__VA_ARGS__); \ 90 } while (0) |
92 | 91 92/* rate limited, lps indicates how many per second */ 93#define RD(lps, format, ...) \ 94 do { \ 95 static int t0, __cnt; \ 96 if (t0 != time_second) { \ 97 t0 = time_second; \ 98 __cnt = 0; \ 99 } \ 100 if (__cnt++ < lps) \ 101 D(format, ##__VA_ARGS__); \ 102 } while (0) 103 |
93struct netmap_adapter; 94 95/* 96 * private, kernel view of a ring. Keeps track of the status of 97 * a ring across system calls. 98 * 99 * nr_hwcur index of the next buffer to refill. 100 * It corresponds to ring->cur - ring->reserved --- 23 unchanged lines hidden (view full) --- 124} __attribute__((__aligned__(64))); 125 126/* 127 * This struct extends the 'struct adapter' (or 128 * equivalent) device descriptor. It contains all fields needed to 129 * support netmap operation. 130 */ 131struct netmap_adapter { | 104struct netmap_adapter; 105 106/* 107 * private, kernel view of a ring. Keeps track of the status of 108 * a ring across system calls. 109 * 110 * nr_hwcur index of the next buffer to refill. 111 * It corresponds to ring->cur - ring->reserved --- 23 unchanged lines hidden (view full) --- 135} __attribute__((__aligned__(64))); 136 137/* 138 * This struct extends the 'struct adapter' (or 139 * equivalent) device descriptor. It contains all fields needed to 140 * support netmap operation. 141 */ 142struct netmap_adapter { |
143 /* 144 * On linux we do not have a good way to tell if an interface 145 * is netmap-capable. So we use the following trick: 146 * NA(ifp) points here, and the first entry (which hopefully 147 * always exists and is at least 32 bits) contains a magic 148 * value which we can use to detect that the interface is good. 149 */ 150 uint32_t magic; 151 uint32_t na_flags; /* future place for IFCAP_NETMAP */ 152#define NAF_SKIP_INTR 1 /* use the regular interrupt handler. 153 * useful during initialization 154 */ |
|
132 int refcount; /* number of user-space descriptors using this 133 interface, which is equal to the number of 134 struct netmap_if objs in the mapped region. */ 135 /* 136 * The selwakeup in the interrupt thread can use per-ring 137 * and/or global wait queues. We track how many clients 138 * of each type we have so we can optimize the drivers, 139 * and especially avoid huge contention on the locks. --- 4 unchanged lines hidden (view full) --- 144 int separate_locks; /* set if the interface suports different 145 locks for rx, tx and core. */ 146 147 u_int num_rx_rings; /* number of adapter receive rings */ 148 u_int num_tx_rings; /* number of adapter transmit rings */ 149 150 u_int num_tx_desc; /* number of descriptor in each queue */ 151 u_int num_rx_desc; | 155 int refcount; /* number of user-space descriptors using this 156 interface, which is equal to the number of 157 struct netmap_if objs in the mapped region. */ 158 /* 159 * The selwakeup in the interrupt thread can use per-ring 160 * and/or global wait queues. We track how many clients 161 * of each type we have so we can optimize the drivers, 162 * and especially avoid huge contention on the locks. --- 4 unchanged lines hidden (view full) --- 167 int separate_locks; /* set if the interface suports different 168 locks for rx, tx and core. */ 169 170 u_int num_rx_rings; /* number of adapter receive rings */ 171 u_int num_tx_rings; /* number of adapter transmit rings */ 172 173 u_int num_tx_desc; /* number of descriptor in each queue */ 174 u_int num_rx_desc; |
152 //u_int buff_size; // XXX deprecate, use NETMAP_BUF_SIZE | |
153 154 /* tx_rings and rx_rings are private but allocated 155 * as a contiguous chunk of memory. Each array has 156 * N+1 entries, for the adapter queues and for the host queue. 157 */ 158 struct netmap_kring *tx_rings; /* array of TX rings. */ 159 struct netmap_kring *rx_rings; /* array of RX rings. */ 160 --- 19 unchanged lines hidden (view full) --- 180 int bdg_port; 181#ifdef linux 182 struct net_device_ops nm_ndo; 183 int if_refcount; // XXX additions for bridge 184#endif /* linux */ 185}; 186 187/* | 175 176 /* tx_rings and rx_rings are private but allocated 177 * as a contiguous chunk of memory. Each array has 178 * N+1 entries, for the adapter queues and for the host queue. 179 */ 180 struct netmap_kring *tx_rings; /* array of TX rings. */ 181 struct netmap_kring *rx_rings; /* array of RX rings. */ 182 --- 19 unchanged lines hidden (view full) --- 202 int bdg_port; 203#ifdef linux 204 struct net_device_ops nm_ndo; 205 int if_refcount; // XXX additions for bridge 206#endif /* linux */ 207}; 208 209/* |
188 * The combination of "enable" (ifp->if_capabilities &IFCAP_NETMAP) | 210 * The combination of "enable" (ifp->if_capenable & IFCAP_NETMAP) |
189 * and refcount gives the status of the interface, namely: 190 * 191 * enable refcount Status 192 * 193 * FALSE 0 normal operation 194 * FALSE != 0 -- (impossible) 195 * TRUE 1 netmap mode 196 * TRUE 0 being deleted. --- 66 unchanged lines hidden (view full) --- 263 * NA returns a pointer to the struct netmap adapter from the ifp, 264 * WNA is used to write it. 265 */ 266#ifndef WNA 267#define WNA(_ifp) (_ifp)->if_pspare[0] 268#endif 269#define NA(_ifp) ((struct netmap_adapter *)WNA(_ifp)) 270 | 211 * and refcount gives the status of the interface, namely: 212 * 213 * enable refcount Status 214 * 215 * FALSE 0 normal operation 216 * FALSE != 0 -- (impossible) 217 * TRUE 1 netmap mode 218 * TRUE 0 being deleted. --- 66 unchanged lines hidden (view full) --- 285 * NA returns a pointer to the struct netmap adapter from the ifp, 286 * WNA is used to write it. 287 */ 288#ifndef WNA 289#define WNA(_ifp) (_ifp)->if_pspare[0] 290#endif 291#define NA(_ifp) ((struct netmap_adapter *)WNA(_ifp)) 292 |
293/* 294 * Macros to determine if an interface is netmap capable or netmap enabled. 295 * See the magic field in struct netmap_adapter. 296 */ 297#ifdef __FreeBSD__ 298/* 299 * on FreeBSD just use if_capabilities and if_capenable. 300 */ 301#define NETMAP_CAPABLE(ifp) (NA(ifp) && \ 302 (ifp)->if_capabilities & IFCAP_NETMAP ) |
|
271 | 303 |
304#define NETMAP_SET_CAPABLE(ifp) \ 305 (ifp)->if_capabilities |= IFCAP_NETMAP 306 307#else /* linux */ 308 309/* 310 * on linux: 311 * we check if NA(ifp) is set and its first element has a related 312 * magic value. The capenable is within the struct netmap_adapter. 313 */ 314#define NETMAP_MAGIC 0x52697a7a 315 316#define NETMAP_CAPABLE(ifp) (NA(ifp) && \ 317 ((uint32_t)(uintptr_t)NA(ifp) ^ NA(ifp)->magic) == NETMAP_MAGIC ) 318 319#define NETMAP_SET_CAPABLE(ifp) \ 320 NA(ifp)->magic = ((uint32_t)(uintptr_t)NA(ifp)) ^ NETMAP_MAGIC 321 322#endif /* linux */ 323 |
|
272#ifdef __FreeBSD__ 273/* Callback invoked by the dma machinery after a successfull dmamap_load */ 274static void netmap_dmamap_cb(__unused void *arg, 275 __unused bus_dma_segment_t * segs, __unused int nseg, __unused int error) 276{ 277} 278 279/* bus_dmamap_load wrapper: call aforementioned function if map != NULL. --- 139 unchanged lines hidden --- | 324#ifdef __FreeBSD__ 325/* Callback invoked by the dma machinery after a successfull dmamap_load */ 326static void netmap_dmamap_cb(__unused void *arg, 327 __unused bus_dma_segment_t * segs, __unused int nseg, __unused int error) 328{ 329} 330 331/* bus_dmamap_load wrapper: call aforementioned function if map != NULL. --- 139 unchanged lines hidden --- |