netmap.h (f9790aeb8869bfcedf111517bace712b390e6cc5) netmap.h (17885a7bfde9d164e45a9833bb172215c55739f9)
1/*
1/*
2 * Copyright (C) 2011-2013 Matteo Landi, Luigi Rizzo. All rights reserved.
2 * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 23 unchanged lines hidden (view full) ---

34 * http://info.iet.unipi.it/~luigi/netmap/
35 *
36 * This API is also used to communicate with the VALE software switch
37 */
38
39#ifndef _NET_NETMAP_H_
40#define _NET_NETMAP_H_
41
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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 23 unchanged lines hidden (view full) ---

34 * http://info.iet.unipi.it/~luigi/netmap/
35 *
36 * This API is also used to communicate with the VALE software switch
37 */
38
39#ifndef _NET_NETMAP_H_
40#define _NET_NETMAP_H_
41
42#define NETMAP_API 10 /* current API version */
43
42/*
44/*
45 * Some fields should be cache-aligned to reduce contention.
46 * The alignment is architecture and OS dependent, but rather than
47 * digging into OS headers to find the exact value we use an estimate
48 * that should cover most architectures.
49 */
50#define NM_CACHE_ALIGN 128
51
52/*
43 * --- Netmap data structures ---
44 *
45 * The userspace data structures used by netmap are shown below.
46 * They are allocated by the kernel and mmap()ed by userspace threads.
47 * Pointers are implemented as memory offsets or indexes,
48 * so that they can be easily dereferenced in kernel and userspace.
49
50 KERNEL (opaque, obviously)
51
52 ====================================================================
53 |
54 USERSPACE | struct netmap_ring
53 * --- Netmap data structures ---
54 *
55 * The userspace data structures used by netmap are shown below.
56 * They are allocated by the kernel and mmap()ed by userspace threads.
57 * Pointers are implemented as memory offsets or indexes,
58 * so that they can be easily dereferenced in kernel and userspace.
59
60 KERNEL (opaque, obviously)
61
62 ====================================================================
63 |
64 USERSPACE | struct netmap_ring
55 +---->+--------------+
56 / | cur |
57 struct netmap_if (nifp, 1 per fd) / | avail |
58 +---------------+ / | buf_ofs |
59 | ni_tx_rings | / +==============+
60 | ni_rx_rings | / | buf_idx, len | slot[0]
61 | | / | flags, ptr |
62 | | / +--------------+
63 +===============+ / | buf_idx, len | slot[1]
64 | txring_ofs[0] | (rel.to nifp)--' | flags, ptr |
65 | txring_ofs[1] | +--------------+
66 (ni_tx_rings+1 entries) (num_slots entries)
67 | txring_ofs[t] | | buf_idx, len | slot[n-1]
68 +---------------+ | flags, ptr |
69 | rxring_ofs[0] | +--------------+
65 +---->+---------------+
66 / | head,cur,tail |
67 struct netmap_if (nifp, 1 per fd) / | buf_ofs |
68 +---------------+ / | other fields |
69 | ni_tx_rings | / +===============+
70 | ni_rx_rings | / | buf_idx, len | slot[0]
71 | | / | flags, ptr |
72 | | / +---------------+
73 +===============+ / | buf_idx, len | slot[1]
74 | txring_ofs[0] | (rel.to nifp)--' | flags, ptr |
75 | txring_ofs[1] | +---------------+
76 (tx+1+extra_tx entries) (num_slots entries)
77 | txring_ofs[t] | | buf_idx, len | slot[n-1]
78 +---------------+ | flags, ptr |
79 | rxring_ofs[0] | +---------------+
70 | rxring_ofs[1] |
80 | rxring_ofs[1] |
71 (ni_rx_rings+1 entries)
81 (rx+1+extra_rx entries)
72 | rxring_ofs[r] |
73 +---------------+
74
75 * For each "interface" (NIC, host stack, VALE switch port) attached to a
76 * file descriptor, the mmap()ed region contains a (logically readonly)
77 * struct netmap_if pointing to struct netmap_ring's.
78 * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
79 * pair attached to the host stack (this pair is unused for VALE ports).

--- 8 unchanged lines hidden (view full) ---

88 * is provided for user-supplied buffers in the tx path.
89 *
90 * In user space, the buffer address is computed as
91 * (char *)ring + buf_ofs + index*NETMAP_BUF_SIZE
92 */
93
94/*
95 * struct netmap_slot is a buffer descriptor
82 | rxring_ofs[r] |
83 +---------------+
84
85 * For each "interface" (NIC, host stack, VALE switch port) attached to a
86 * file descriptor, the mmap()ed region contains a (logically readonly)
87 * struct netmap_if pointing to struct netmap_ring's.
88 * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
89 * pair attached to the host stack (this pair is unused for VALE ports).

--- 8 unchanged lines hidden (view full) ---

98 * is provided for user-supplied buffers in the tx path.
99 *
100 * In user space, the buffer address is computed as
101 * (char *)ring + buf_ofs + index*NETMAP_BUF_SIZE
102 */
103
104/*
105 * struct netmap_slot is a buffer descriptor
96 *
97 * buf_idx the index of the buffer associated to the slot.
98 * len the length of the payload
99 * flags control operation on the slot, as defined below
100 *
101 * NS_BUF_CHANGED must be set whenever userspace wants
102 * to change buf_idx (it might be necessary to
103 * reprogram the NIC)
104 *
105 * NS_REPORT must be set if we want the NIC to generate an interrupt
106 * when this slot is used. Leaving it to 0 improves
107 * performance.
108 *
109 * NS_FORWARD if set on a receive ring, and the device is in
110 * transparent mode, buffers released with the flag set
111 * will be forwarded to the 'other' side (host stack
112 * or NIC, respectively) on the next select() or ioctl()
113 *
114 * NS_NO_LEARN on a VALE switch, do not 'learn' the source port for
115 * this packet.
116 *
117 * NS_INDIRECT (tx rings only) data is in a userspace buffer pointed
118 * by the ptr field in the slot.
119 *
120 * NS_MOREFRAG Part of a multi-segment frame. The last (or only)
121 * segment must not have this flag.
122 * Only supported on VALE ports.
123 *
124 * NS_PORT_MASK the high 8 bits of the flag, if not zero, indicate the
125 * destination port for the VALE switch, overriding
126 * the lookup table.
127 */
106 */
128
129struct netmap_slot {
130 uint32_t buf_idx; /* buffer index */
107struct netmap_slot {
108 uint32_t buf_idx; /* buffer index */
131 uint16_t len; /* packet length */
109 uint16_t len; /* length for this slot */
132 uint16_t flags; /* buf changed, etc. */
110 uint16_t flags; /* buf changed, etc. */
111 uint64_t ptr; /* pointer for indirect buffers */
112};
113
114/*
115 * The following flags control how the slot is used
116 */
117
133#define NS_BUF_CHANGED 0x0001 /* buf_idx changed */
118#define NS_BUF_CHANGED 0x0001 /* buf_idx changed */
134#define NS_REPORT 0x0002 /* ask the hardware to report results
135 * e.g. by generating an interrupt
136 */
137#define NS_FORWARD 0x0004 /* pass packet to the other endpoint
138 * (host stack or device)
139 */
140#define NS_NO_LEARN 0x0008
141#define NS_INDIRECT 0x0010
142#define NS_MOREFRAG 0x0020
119 /*
120 * must be set whenever buf_idx is changed (as it might be
121 * necessary to recompute the physical address and mapping)
122 */
123
124#define NS_REPORT 0x0002 /* ask the hardware to report results */
125 /*
126 * Request notification when slot is used by the hardware.
127 * Normally transmit completions are handled lazily and
128 * may be unreported. This flag lets us know when a slot
129 * has been sent (e.g. to terminate the sender).
130 */
131
132#define NS_FORWARD 0x0004 /* pass packet 'forward' */
133 /*
134 * (Only for physical ports, rx rings with NR_FORWARD set).
135 * Slot released to the kernel (i.e. before ring->head) with
136 * this flag set are passed to the peer ring (host/NIC),
137 * thus restoring the host-NIC connection for these slots.
138 * This supports efficient traffic monitoring or firewalling.
139 */
140
141#define NS_NO_LEARN 0x0008 /* disable bridge learning */
142 /*
143 * On a VALE switch, do not 'learn' the source port for
144 * this buffer.
145 */
146
147#define NS_INDIRECT 0x0010 /* userspace buffer */
148 /*
149 * (VALE tx rings only) data is in a userspace buffer,
150 * whose address is in the 'ptr' field in the slot.
151 */
152
153#define NS_MOREFRAG 0x0020 /* packet has more fragments */
154 /*
155 * (VALE ports only)
156 * Set on all but the last slot of a multi-segment packet.
157 * The 'len' field refers to the individual fragment.
158 */
159
143#define NS_PORT_SHIFT 8
144#define NS_PORT_MASK (0xff << NS_PORT_SHIFT)
160#define NS_PORT_SHIFT 8
161#define NS_PORT_MASK (0xff << NS_PORT_SHIFT)
145 /*
146 * in rx rings, the high 8 bits
147 * are the number of fragments.
148 */
162 /*
163 * The high 8 bits of the flag, if not zero, indicate the
164 * destination port for the VALE switch, overriding
165 * the lookup table.
166 */
167
149#define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff)
168#define NS_RFRAGS(_slot) ( ((_slot)->flags >> 8) & 0xff)
150 uint64_t ptr; /* pointer for indirect buffers */
151};
169 /*
170 * (VALE rx rings only) the high 8 bits
171 * are the number of fragments.
172 */
152
173
174
153/*
154 * struct netmap_ring
155 *
156 * Netmap representation of a TX or RX ring (also known as "queue").
157 * This is a queue implemented as a fixed-size circular array.
175/*
176 * struct netmap_ring
177 *
178 * Netmap representation of a TX or RX ring (also known as "queue").
179 * This is a queue implemented as a fixed-size circular array.
158 * At the software level, two fields are important: avail and cur.
180 * At the software level the important fields are: head, cur, tail.
159 *
160 * In TX rings:
161 *
181 *
182 * In TX rings:
183 *
162 * avail tells how many slots are available for transmission.
163 * It is updated by the kernel in each netmap system call.
164 * It MUST BE decremented by the user when it
165 * adds a new packet to send.
184 * head first slot available for transmission.
185 * cur wakeup point. select() and poll() will unblock
186 * when 'tail' moves past 'cur'
187 * tail (readonly) first slot reserved to the kernel
166 *
188 *
167 * cur indicates the slot to use for the next packet
168 * to send (i.e. the "tail" of the queue).
169 * It MUST BE incremented by the user before
170 * netmap system calls to reflect the number of newly
171 * sent packets.
172 * It is checked by the kernel on netmap system calls
173 * (normally unmodified by the kernel unless invalid).
189 * [head .. tail-1] can be used for new packets to send;
190 * 'head' and 'cur' must be incremented as slots are filled
191 * with new packets to be sent;
192 * 'cur' can be moved further ahead if we need more space
193 * for new transmissions.
174 *
175 * In RX rings:
176 *
194 *
195 * In RX rings:
196 *
177 * avail is the number of packets available (possibly 0).
178 * It is updated by the kernel in each netmap system call.
179 * It MUST BE decremented by the user when it
180 * consumes a packet.
197 * head first valid received packet
198 * cur wakeup point. select() and poll() will unblock
199 * when 'tail' moves past 'cur'
200 * tail (readonly) first slot reserved to the kernel
181 *
201 *
182 * cur indicates the first slot that contains a packet not
183 * yet processed (the "head" of the queue).
184 * It MUST BE incremented by the user when it consumes
185 * a packet.
202 * [head .. tail-1] contain received packets;
203 * 'head' and 'cur' must be incremented as slots are consumed
204 * and can be returned to the kernel;
205 * 'cur' can be moved further ahead if we want to wait for
206 * new packets without returning the previous ones.
186 *
207 *
187 * reserved indicates the number of buffers before 'cur'
188 * that the user has not released yet. Normally 0,
189 * it MUST BE incremented by the user when it
190 * does not return the buffer immediately, and decremented
191 * when the buffer is finally freed.
192 *
193 *
194 * DATA OWNERSHIP/LOCKING:
208 * DATA OWNERSHIP/LOCKING:
195 * The netmap_ring, all slots, and buffers in the range
196 * [reserved-cur , cur+avail[ are owned by the user program,
197 * and the kernel only touches them in the same thread context
198 * during a system call.
199 * Other buffers are reserved for use by the NIC's DMA engines.
209 * The netmap_ring, and all slots and buffers in the range
210 * [head .. tail-1] are owned by the user program;
211 * the kernel only accesses them during a netmap system call
212 * and in the user thread context.
200 *
213 *
201 * FLAGS
202 * NR_TIMESTAMP updates the 'ts' field on each syscall. This is
203 * a global timestamp for all packets.
204 * NR_RX_TSTMP if set, the last 64 byte in each buffer will
205 * contain a timestamp for the frame supplied by
206 * the hardware (if supported)
207 * NR_FORWARD if set, the NS_FORWARD flag in each slot of the
208 * RX ring is checked, and if set the packet is
209 * passed to the other side (host stack or device,
210 * respectively). This permits bpf-like behaviour
211 * or transparency for selected packets.
214 * Other slots and buffers are reserved for use by the kernel
212 */
213struct netmap_ring {
214 /*
215 * buf_ofs is meant to be used through macros.
216 * It contains the offset of the buffer region from this
217 * descriptor.
218 */
215 */
216struct netmap_ring {
217 /*
218 * buf_ofs is meant to be used through macros.
219 * It contains the offset of the buffer region from this
220 * descriptor.
221 */
219 const ssize_t buf_ofs;
222 const int64_t buf_ofs;
220 const uint32_t num_slots; /* number of slots in the ring. */
223 const uint32_t num_slots; /* number of slots in the ring. */
221 uint32_t avail; /* number of usable slots */
222 uint32_t cur; /* 'current' r/w position */
223 uint32_t reserved; /* not refilled before current */
224 const uint32_t nr_buf_size;
225 const uint16_t ringid;
226 const uint16_t dir; /* 0: tx, 1: rx */
224
227
225 const uint16_t nr_buf_size;
226 uint16_t flags;
227#define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */
228#define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */
229#define NR_RX_TSTMP 0x0008 /* set rx timestamp in slots */
228 uint32_t head; /* (u) first user slot */
229 uint32_t cur; /* (u) wakeup point */
230 uint32_t tail; /* (k) first kernel slot */
230
231
231 struct timeval ts; /* time of last *sync() */
232 uint32_t flags;
232
233
234 struct timeval ts; /* (k) time of last *sync() */
235
236 /* opaque room for a mutex or similar object */
237 uint8_t sem[128] __attribute__((__aligned__(NM_CACHE_ALIGN)));
238
233 /* the slots follow. This struct has variable size */
234 struct netmap_slot slot[0]; /* array of slots. */
235};
236
237
238/*
239 /* the slots follow. This struct has variable size */
240 struct netmap_slot slot[0]; /* array of slots. */
241};
242
243
244/*
245 * RING FLAGS
246 */
247#define NR_TIMESTAMP 0x0002 /* set timestamp on *sync() */
248 /*
249 * updates the 'ts' field on each netmap syscall. This saves
250 * saves a separate gettimeofday(), and is not much worse than
251 * software timestamps generated in the interrupt handler.
252 */
253
254#define NR_FORWARD 0x0004 /* enable NS_FORWARD for ring */
255 /*
256 * Enables the NS_FORWARD slot flag for the ring.
257 */
258
259
260/*
239 * Netmap representation of an interface and its queue(s).
240 * This is initialized by the kernel when binding a file
241 * descriptor to a port, and should be considered as readonly
242 * by user programs. The kernel never uses it.
243 *
244 * There is one netmap_if for each file descriptor on which we want
245 * to select/poll.
246 * select/poll operates on one or all pairs depending on the value of
247 * nmr_queueid passed on the ioctl.
248 */
249struct netmap_if {
250 char ni_name[IFNAMSIZ]; /* name of the interface. */
251 const uint32_t ni_version; /* API version, currently unused */
252 const uint32_t ni_flags; /* properties */
253#define NI_PRIV_MEM 0x1 /* private memory region */
254
261 * Netmap representation of an interface and its queue(s).
262 * This is initialized by the kernel when binding a file
263 * descriptor to a port, and should be considered as readonly
264 * by user programs. The kernel never uses it.
265 *
266 * There is one netmap_if for each file descriptor on which we want
267 * to select/poll.
268 * select/poll operates on one or all pairs depending on the value of
269 * nmr_queueid passed on the ioctl.
270 */
271struct netmap_if {
272 char ni_name[IFNAMSIZ]; /* name of the interface. */
273 const uint32_t ni_version; /* API version, currently unused */
274 const uint32_t ni_flags; /* properties */
275#define NI_PRIV_MEM 0x1 /* private memory region */
276
255 const uint32_t ni_rx_rings; /* number of rx rings */
256 const uint32_t ni_tx_rings; /* number of tx rings */
257 /*
277 /*
278 * The number of packet rings available in netmap mode.
279 * Physical NICs can have different numbers of tx and rx rings.
280 * Physical NICs also have a 'host' ring pair.
281 * Additionally, clients can request additional ring pairs to
282 * be used for internal communication.
283 */
284 const uint32_t ni_tx_rings; /* number of HW tx rings */
285 const uint32_t ni_rx_rings; /* number of HW rx rings */
286
287 const uint32_t ni_extra_tx_rings;
288 const uint32_t ni_extra_rx_rings;
289 /*
258 * The following array contains the offset of each netmap ring
290 * The following array contains the offset of each netmap ring
259 * from this structure. The first ni_tx_rings+1 entries refer
260 * to the tx rings, the next ni_rx_rings+1 refer to the rx rings
261 * (the last entry in each block refers to the host stack rings).
291 * from this structure, in the following order:
292 * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings;
293 * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings.
294 *
262 * The area is filled up by the kernel on NIOCREGIF,
263 * and then only read by userspace code.
264 */
265 const ssize_t ring_ofs[0];
266};
267
295 * The area is filled up by the kernel on NIOCREGIF,
296 * and then only read by userspace code.
297 */
298 const ssize_t ring_ofs[0];
299};
300
301
268#ifndef NIOCREGIF
269/*
270 * ioctl names and related fields
271 *
302#ifndef NIOCREGIF
303/*
304 * ioctl names and related fields
305 *
306 * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
307 * whose identity is set in NIOCREGIF through nr_ringid.
308 * These are non blocking and take no argument.
309 *
272 * NIOCGINFO takes a struct ifreq, the interface name is the input,
273 * the outputs are number of queues and number of descriptor
274 * for each queue (useful to set number of threads etc.).
275 * The info returned is only advisory and may change before
276 * the interface is bound to a file descriptor.
277 *
310 * NIOCGINFO takes a struct ifreq, the interface name is the input,
311 * the outputs are number of queues and number of descriptor
312 * for each queue (useful to set number of threads etc.).
313 * The info returned is only advisory and may change before
314 * the interface is bound to a file descriptor.
315 *
278 * NIOCREGIF takes an interface name within a struct ifreq,
316 * NIOCREGIF takes an interface name within a struct nmre,
279 * and activates netmap mode on the interface (if possible).
280 *
317 * and activates netmap mode on the interface (if possible).
318 *
281 * nr_name is the name of the interface
319 * The argument to NIOCGINFO/NIOCREGIF overlays struct ifreq so we
320 * can pass it down to other NIC-related ioctls.
282 *
321 *
283 * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings
284 * indicate the configuration of the port on return.
322 * The actual argument (struct nmreq) has a number of options to request
323 * different functions.
285 *
324 *
286 * On input, non-zero values for nr_tx_rings, nr_tx_slots and the
287 * rx counterparts may be used to reconfigure the port according
288 * to the requested values, but this is not guaranteed.
289 * The actual values are returned on completion of the ioctl().
325 * nr_name (in)
326 * The name of the port (em0, valeXXX:YYY, etc.)
327 * limited to IFNAMSIZ for backward compatibility.
290 *
328 *
291 * nr_ringid
292 * indicates how rings should be bound to the file descriptors.
293 * The default (0) means all physical rings of a NIC are bound.
294 * NETMAP_HW_RING plus a ring number lets you bind just
295 * a single ring pair.
296 * NETMAP_SW_RING binds only the host tx/rx rings
297 * NETMAP_NO_TX_POLL prevents select()/poll() from pushing
298 * out packets on the tx ring unless POLLOUT is specified.
329 * nr_version (in/out)
330 * Must match NETMAP_API as used in the kernel, error otherwise.
331 * Always returns the desired value on output.
299 *
332 *
300 * NETMAP_PRIV_MEM is a return value used to indicate that
301 * this ring is in a private memory region hence buffer
302 * swapping cannot be used
333 * nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out)
334 * On input, non-zero values may be used to reconfigure the port
335 * according to the requested values, but this is not guaranteed.
336 * On output the actual values in use are reported.
303 *
337 *
304 * nr_cmd is used to configure NICs attached to a VALE switch,
305 * or to dump the configuration of a VALE switch.
338 * nr_ringid (in)
339 * Indicates how rings should be bound to the file descriptors.
340 * 0 (default) binds all physical rings
341 * NETMAP_HW_RING | ring number binds a single ring pair
342 * NETMAP_SW_RING binds only the host tx/rx rings
306 *
343 *
307 * nr_cmd = NETMAP_BDG_ATTACH and nr_name = vale*:ifname
308 * attaches the NIC to the switch, with nr_ringid specifying
309 * which rings to use
344 * NETMAP_NO_TX_POLL can be OR-ed to make select()/poll() push
345 * packets on tx rings only if POLLOUT is set.
346 * The default is to push any pending packet.
310 *
347 *
311 * nr_cmd = NETMAP_BDG_DETACH and nr_name = vale*:ifname
312 * disconnects a previously attached NIC
348 * NETMAP_PRIV_MEM is set on return for ports that use private
349 * memory regions and cannot use buffer swapping.
313 *
350 *
314 * nr_cmd = NETMAP_BDG_LIST is used to list the configuration
315 * of VALE switches, with additional arguments.
351 * nr_cmd (in) if non-zero indicates a special command:
352 * NETMAP_BDG_ATTACH and nr_name = vale*:ifname
353 * attaches the NIC to the switch; nr_ringid specifies
354 * which rings to use. Used by vale-ctl -a ...
355 * nr_arg1 = NETMAP_BDG_HOST also attaches the host port
356 * as in vale-ctl -h ...
316 *
357 *
317 * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
318 * whose identity is set in NIOCREGIF through nr_ringid
358 * NETMAP_BDG_DETACH and nr_name = vale*:ifname
359 * disconnects a previously attached NIC.
360 * Used by vale-ctl -d ...
319 *
361 *
320 * NETMAP_API is the API version.
362 * NETMAP_BDG_LIST
363 * list the configuration of VALE switches.
364 *
365 * NETMAP_BDG_OFFSET XXX ?
366 * Set the offset of data in packets. Used with VALE
367 * switches where the clients use the vhost header.
368 *
369 * nr_arg1, nr_arg2 (in/out) command specific
370 *
321 */
322
371 */
372
373
323/*
324 * struct nmreq overlays a struct ifreq
325 */
326struct nmreq {
327 char nr_name[IFNAMSIZ];
328 uint32_t nr_version; /* API version */
374/*
375 * struct nmreq overlays a struct ifreq
376 */
377struct nmreq {
378 char nr_name[IFNAMSIZ];
379 uint32_t nr_version; /* API version */
329#define NETMAP_API 5 /* current version */
330 uint32_t nr_offset; /* nifp offset in the shared region */
331 uint32_t nr_memsize; /* size of the shared region */
332 uint32_t nr_tx_slots; /* slots in tx rings */
333 uint32_t nr_rx_slots; /* slots in rx rings */
334 uint16_t nr_tx_rings; /* number of tx rings */
335 uint16_t nr_rx_rings; /* number of rx rings */
336 uint16_t nr_ringid; /* ring(s) we care about */
337#define NETMAP_PRIV_MEM 0x8000 /* rings use private memory */
338#define NETMAP_HW_RING 0x4000 /* low bits indicate one hw ring */
339#define NETMAP_SW_RING 0x2000 /* process the sw ring */
340#define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */
341#define NETMAP_RING_MASK 0xfff /* the ring number */
380 uint32_t nr_offset; /* nifp offset in the shared region */
381 uint32_t nr_memsize; /* size of the shared region */
382 uint32_t nr_tx_slots; /* slots in tx rings */
383 uint32_t nr_rx_slots; /* slots in rx rings */
384 uint16_t nr_tx_rings; /* number of tx rings */
385 uint16_t nr_rx_rings; /* number of rx rings */
386 uint16_t nr_ringid; /* ring(s) we care about */
387#define NETMAP_PRIV_MEM 0x8000 /* rings use private memory */
388#define NETMAP_HW_RING 0x4000 /* low bits indicate one hw ring */
389#define NETMAP_SW_RING 0x2000 /* process the sw ring */
390#define NETMAP_NO_TX_POLL 0x1000 /* no automatic txsync on poll */
391#define NETMAP_RING_MASK 0xfff /* the ring number */
392
342 uint16_t nr_cmd;
343#define NETMAP_BDG_ATTACH 1 /* attach the NIC */
344#define NETMAP_BDG_DETACH 2 /* detach the NIC */
345#define NETMAP_BDG_LOOKUP_REG 3 /* register lookup function */
346#define NETMAP_BDG_LIST 4 /* get bridge's info */
347#define NETMAP_BDG_OFFSET 5 /* set the port offset */
393 uint16_t nr_cmd;
394#define NETMAP_BDG_ATTACH 1 /* attach the NIC */
395#define NETMAP_BDG_DETACH 2 /* detach the NIC */
396#define NETMAP_BDG_LOOKUP_REG 3 /* register lookup function */
397#define NETMAP_BDG_LIST 4 /* get bridge's info */
398#define NETMAP_BDG_OFFSET 5 /* set the port offset */
399
348 uint16_t nr_arg1;
349#define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */
350#define NETMAP_BDG_MAX_OFFSET 12
400 uint16_t nr_arg1;
401#define NETMAP_BDG_HOST 1 /* attach the host stack on ATTACH */
402#define NETMAP_BDG_MAX_OFFSET 12
403
351 uint16_t nr_arg2;
352 uint32_t spare2[3];
353};
354
404 uint16_t nr_arg2;
405 uint32_t spare2[3];
406};
407
408
355/*
356 * FreeBSD uses the size value embedded in the _IOWR to determine
357 * how much to copy in/out. So we need it to match the actual
358 * data structure we pass. We put some spares in the structure
359 * to ease compatibility with other versions
360 */
361#define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */
362#define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */
409/*
410 * FreeBSD uses the size value embedded in the _IOWR to determine
411 * how much to copy in/out. So we need it to match the actual
412 * data structure we pass. We put some spares in the structure
413 * to ease compatibility with other versions
414 */
415#define NIOCGINFO _IOWR('i', 145, struct nmreq) /* return IF info */
416#define NIOCREGIF _IOWR('i', 146, struct nmreq) /* interface register */
363#define NIOCUNREGIF _IO('i', 147) /* deprecated. Was interface unregister */
364#define NIOCTXSYNC _IO('i', 148) /* sync tx queues */
365#define NIOCRXSYNC _IO('i', 149) /* sync rx queues */
366#endif /* !NIOCREGIF */
367
417#define NIOCTXSYNC _IO('i', 148) /* sync tx queues */
418#define NIOCRXSYNC _IO('i', 149) /* sync rx queues */
419#endif /* !NIOCREGIF */
420
421
422/*
423 * Helper functions for kernel and userspace
424 */
425
426/*
427 * check if space is available in the ring.
428 */
429static inline int
430nm_ring_empty(struct netmap_ring *ring)
431{
432 return (ring->cur == ring->tail);
433}
434
368#endif /* _NET_NETMAP_H_ */
435#endif /* _NET_NETMAP_H_ */