The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net/netmap.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
    3  *
    4  * Copyright (C) 2011-2014 Matteo Landi, Luigi Rizzo. All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  *
   10  *   1. Redistributions of source code must retain the above copyright
   11  *      notice, this list of conditions and the following disclaimer.
   12  *   2. Redistributions in binary form must reproduce the above copyright
   13  *      notice, this list of conditions and the following disclaimer in the
   14  *      documentation and/or other materials provided with the distribution.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``S IS''AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  */
   28 
   29 /*
   30  * $FreeBSD: releng/12.0/sys/net/netmap.h 339906 2018-10-30 08:36:36Z vmaffione $
   31  *
   32  * Definitions of constants and the structures used by the netmap
   33  * framework, for the part visible to both kernel and userspace.
   34  * Detailed info on netmap is available with "man netmap" or at
   35  *
   36  *      http://info.iet.unipi.it/~luigi/netmap/
   37  *
   38  * This API is also used to communicate with the VALE software switch
   39  */
   40 
   41 #ifndef _NET_NETMAP_H_
   42 #define _NET_NETMAP_H_
   43 
   44 #define NETMAP_API      12              /* current API version */
   45 
   46 #define NETMAP_MIN_API  11              /* min and max versions accepted */
   47 #define NETMAP_MAX_API  15
   48 /*
   49  * Some fields should be cache-aligned to reduce contention.
   50  * The alignment is architecture and OS dependent, but rather than
   51  * digging into OS headers to find the exact value we use an estimate
   52  * that should cover most architectures.
   53  */
   54 #define NM_CACHE_ALIGN  128
   55 
   56 /*
   57  * --- Netmap data structures ---
   58  *
   59  * The userspace data structures used by netmap are shown below.
   60  * They are allocated by the kernel and mmap()ed by userspace threads.
   61  * Pointers are implemented as memory offsets or indexes,
   62  * so that they can be easily dereferenced in kernel and userspace.
   63 
   64    KERNEL (opaque, obviously)
   65 
   66   ====================================================================
   67                                          |
   68    USERSPACE                             |      struct netmap_ring
   69                                          +---->+---------------+
   70                                              / | head,cur,tail |
   71    struct netmap_if (nifp, 1 per fd)        /  | buf_ofs       |
   72     +---------------+                      /   | other fields  |
   73     | ni_tx_rings   |                     /    +===============+
   74     | ni_rx_rings   |                    /     | buf_idx, len  | slot[0]
   75     |               |                   /      | flags, ptr    |
   76     |               |                  /       +---------------+
   77     +===============+                 /        | buf_idx, len  | slot[1]
   78     | txring_ofs[0] | (rel.to nifp)--'         | flags, ptr    |
   79     | txring_ofs[1] |                          +---------------+
   80      (tx+1 entries)                           (num_slots entries)
   81     | txring_ofs[t] |                          | buf_idx, len  | slot[n-1]
   82     +---------------+                          | flags, ptr    |
   83     | rxring_ofs[0] |                          +---------------+
   84     | rxring_ofs[1] |
   85      (rx+1 entries)
   86     | rxring_ofs[r] |
   87     +---------------+
   88 
   89  * For each "interface" (NIC, host stack, PIPE, VALE switch port) bound to
   90  * a file descriptor, the mmap()ed region contains a (logically readonly)
   91  * struct netmap_if pointing to struct netmap_ring's.
   92  *
   93  * There is one netmap_ring per physical NIC ring, plus one tx/rx ring
   94  * pair attached to the host stack (this pair is unused for non-NIC ports).
   95  *
   96  * All physical/host stack ports share the same memory region,
   97  * so that zero-copy can be implemented between them.
   98  * VALE switch ports instead have separate memory regions.
   99  *
  100  * The netmap_ring is the userspace-visible replica of the NIC ring.
  101  * Each slot has the index of a buffer (MTU-sized and residing in the
  102  * mmapped region), its length and some flags. An extra 64-bit pointer
  103  * is provided for user-supplied buffers in the tx path.
  104  *
  105  * In user space, the buffer address is computed as
  106  *      (char *)ring + buf_ofs + index * NETMAP_BUF_SIZE
  107  *
  108  * Added in NETMAP_API 11:
  109  *
  110  * + NIOCREGIF can request the allocation of extra spare buffers from
  111  *   the same memory pool. The desired number of buffers must be in
  112  *   nr_arg3. The ioctl may return fewer buffers, depending on memory
  113  *   availability. nr_arg3 will return the actual value, and, once
  114  *   mapped, nifp->ni_bufs_head will be the index of the first buffer.
  115  *
  116  *   The buffers are linked to each other using the first uint32_t
  117  *   as the index. On close, ni_bufs_head must point to the list of
  118  *   buffers to be released.
  119  *
  120  * + NIOCREGIF can request space for extra rings (and buffers)
  121  *   allocated in the same memory space. The number of extra rings
  122  *   is in nr_arg1, and is advisory. This is a no-op on NICs where
  123  *   the size of the memory space is fixed.
  124  *
  125  * + NIOCREGIF can attach to PIPE rings sharing the same memory
  126  *   space with a parent device. The ifname indicates the parent device,
  127  *   which must already exist. Flags in nr_flags indicate if we want to
  128  *   bind the master or slave side, the index (from nr_ringid)
  129  *   is just a cookie and does not need to be sequential.
  130  *
  131  * + NIOCREGIF can also attach to 'monitor' rings that replicate
  132  *   the content of specific rings, also from the same memory space.
  133  *
  134  *   Extra flags in nr_flags support the above functions.
  135  *   Application libraries may use the following naming scheme:
  136  *      netmap:foo                      all NIC ring pairs
  137  *      netmap:foo^                     only host ring pair
  138  *      netmap:foo+                     all NIC ring + host ring pairs
  139  *      netmap:foo-k                    the k-th NIC ring pair
  140  *      netmap:foo{k                    PIPE ring pair k, master side
  141  *      netmap:foo}k                    PIPE ring pair k, slave side
  142  *
  143  * Some notes about host rings:
  144  *
  145  * + The RX host ring is used to store those packets that the host network
  146  *   stack is trying to transmit through a NIC queue, but only if that queue
  147  *   is currently in netmap mode. Netmap will not intercept host stack mbufs
  148  *   designated to NIC queues that are not in netmap mode. As a consequence,
  149  *   registering a netmap port with netmap:foo^ is not enough to intercept
  150  *   mbufs in the RX host ring; the netmap port should be registered with
  151  *   netmap:foo*, or another registration should be done to open at least a
  152  *   NIC TX queue in netmap mode.
  153  *
  154  * + Netmap is not currently able to deal with intercepted trasmit mbufs which
  155  *   require offloadings like TSO, UFO, checksumming offloadings, etc. It is
  156  *   responsibility of the user to disable those offloadings (e.g. using
  157  *   ifconfig on FreeBSD or ethtool -K on Linux) for an interface that is being
  158  *   used in netmap mode. If the offloadings are not disabled, GSO and/or
  159  *   unchecksummed packets may be dropped immediately or end up in the host RX
  160  *   ring, and will be dropped as soon as the packet reaches another netmap
  161  *   adapter.
  162  */
  163 
  164 /*
  165  * struct netmap_slot is a buffer descriptor
  166  */
  167 struct netmap_slot {
  168         uint32_t buf_idx;       /* buffer index */
  169         uint16_t len;           /* length for this slot */
  170         uint16_t flags;         /* buf changed, etc. */
  171         uint64_t ptr;           /* pointer for indirect buffers */
  172 };
  173 
  174 /*
  175  * The following flags control how the slot is used
  176  */
  177 
  178 #define NS_BUF_CHANGED  0x0001  /* buf_idx changed */
  179         /*
  180          * must be set whenever buf_idx is changed (as it might be
  181          * necessary to recompute the physical address and mapping)
  182          *
  183          * It is also set by the kernel whenever the buf_idx is
  184          * changed internally (e.g., by pipes). Applications may
  185          * use this information to know when they can reuse the
  186          * contents of previously prepared buffers.
  187          */
  188 
  189 #define NS_REPORT       0x0002  /* ask the hardware to report results */
  190         /*
  191          * Request notification when slot is used by the hardware.
  192          * Normally transmit completions are handled lazily and
  193          * may be unreported. This flag lets us know when a slot
  194          * has been sent (e.g. to terminate the sender).
  195          */
  196 
  197 #define NS_FORWARD      0x0004  /* pass packet 'forward' */
  198         /*
  199          * (Only for physical ports, rx rings with NR_FORWARD set).
  200          * Slot released to the kernel (i.e. before ring->head) with
  201          * this flag set are passed to the peer ring (host/NIC),
  202          * thus restoring the host-NIC connection for these slots.
  203          * This supports efficient traffic monitoring or firewalling.
  204          */
  205 
  206 #define NS_NO_LEARN     0x0008  /* disable bridge learning */
  207         /*
  208          * On a VALE switch, do not 'learn' the source port for
  209          * this buffer.
  210          */
  211 
  212 #define NS_INDIRECT     0x0010  /* userspace buffer */
  213         /*
  214          * (VALE tx rings only) data is in a userspace buffer,
  215          * whose address is in the 'ptr' field in the slot.
  216          */
  217 
  218 #define NS_MOREFRAG     0x0020  /* packet has more fragments */
  219         /*
  220          * (VALE ports, ptnetmap ports and some NIC ports, e.g.
  221          * ixgbe and i40e on Linux)
  222          * Set on all but the last slot of a multi-segment packet.
  223          * The 'len' field refers to the individual fragment.
  224          */
  225 
  226 #define NS_PORT_SHIFT   8
  227 #define NS_PORT_MASK    (0xff << NS_PORT_SHIFT)
  228         /*
  229          * The high 8 bits of the flag, if not zero, indicate the
  230          * destination port for the VALE switch, overriding
  231          * the lookup table.
  232          */
  233 
  234 #define NS_RFRAGS(_slot)        ( ((_slot)->flags >> 8) & 0xff)
  235         /*
  236          * (VALE rx rings only) the high 8 bits
  237          *  are the number of fragments.
  238          */
  239 
  240 #define NETMAP_MAX_FRAGS        64      /* max number of fragments */
  241 
  242 
  243 /*
  244  * struct netmap_ring
  245  *
  246  * Netmap representation of a TX or RX ring (also known as "queue").
  247  * This is a queue implemented as a fixed-size circular array.
  248  * At the software level the important fields are: head, cur, tail.
  249  *
  250  * In TX rings:
  251  *
  252  *      head    first slot available for transmission.
  253  *      cur     wakeup point. select() and poll() will unblock
  254  *              when 'tail' moves past 'cur'
  255  *      tail    (readonly) first slot reserved to the kernel
  256  *
  257  *      [head .. tail-1] can be used for new packets to send;
  258  *      'head' and 'cur' must be incremented as slots are filled
  259  *          with new packets to be sent;
  260  *      'cur' can be moved further ahead if we need more space
  261  *      for new transmissions. XXX todo (2014-03-12)
  262  *
  263  * In RX rings:
  264  *
  265  *      head    first valid received packet
  266  *      cur     wakeup point. select() and poll() will unblock
  267  *              when 'tail' moves past 'cur'
  268  *      tail    (readonly) first slot reserved to the kernel
  269  *
  270  *      [head .. tail-1] contain received packets;
  271  *      'head' and 'cur' must be incremented as slots are consumed
  272  *              and can be returned to the kernel;
  273  *      'cur' can be moved further ahead if we want to wait for
  274  *              new packets without returning the previous ones.
  275  *
  276  * DATA OWNERSHIP/LOCKING:
  277  *      The netmap_ring, and all slots and buffers in the range
  278  *      [head .. tail-1] are owned by the user program;
  279  *      the kernel only accesses them during a netmap system call
  280  *      and in the user thread context.
  281  *
  282  *      Other slots and buffers are reserved for use by the kernel
  283  */
  284 struct netmap_ring {
  285         /*
  286          * buf_ofs is meant to be used through macros.
  287          * It contains the offset of the buffer region from this
  288          * descriptor.
  289          */
  290         const int64_t   buf_ofs;
  291         const uint32_t  num_slots;      /* number of slots in the ring. */
  292         const uint32_t  nr_buf_size;
  293         const uint16_t  ringid;
  294         const uint16_t  dir;            /* 0: tx, 1: rx */
  295 
  296         uint32_t        head;           /* (u) first user slot */
  297         uint32_t        cur;            /* (u) wakeup point */
  298         uint32_t        tail;           /* (k) first kernel slot */
  299 
  300         uint32_t        flags;
  301 
  302         struct timeval  ts;             /* (k) time of last *sync() */
  303 
  304         /* opaque room for a mutex or similar object */
  305 #if !defined(_WIN32) || defined(__CYGWIN__)
  306         uint8_t __attribute__((__aligned__(NM_CACHE_ALIGN))) sem[128];
  307 #else
  308         uint8_t __declspec(align(NM_CACHE_ALIGN)) sem[128];
  309 #endif
  310 
  311         /* the slots follow. This struct has variable size */
  312         struct netmap_slot slot[0];     /* array of slots. */
  313 };
  314 
  315 
  316 /*
  317  * RING FLAGS
  318  */
  319 #define NR_TIMESTAMP    0x0002          /* set timestamp on *sync() */
  320         /*
  321          * updates the 'ts' field on each netmap syscall. This saves
  322          * saves a separate gettimeofday(), and is not much worse than
  323          * software timestamps generated in the interrupt handler.
  324          */
  325 
  326 #define NR_FORWARD      0x0004          /* enable NS_FORWARD for ring */
  327         /*
  328          * Enables the NS_FORWARD slot flag for the ring.
  329          */
  330 
  331 /*
  332  * Helper functions for kernel and userspace
  333  */
  334 
  335 /*
  336  * check if space is available in the ring.
  337  */
  338 static inline int
  339 nm_ring_empty(struct netmap_ring *ring)
  340 {
  341         return (ring->cur == ring->tail);
  342 }
  343 
  344 /*
  345  * Netmap representation of an interface and its queue(s).
  346  * This is initialized by the kernel when binding a file
  347  * descriptor to a port, and should be considered as readonly
  348  * by user programs. The kernel never uses it.
  349  *
  350  * There is one netmap_if for each file descriptor on which we want
  351  * to select/poll.
  352  * select/poll operates on one or all pairs depending on the value of
  353  * nmr_queueid passed on the ioctl.
  354  */
  355 struct netmap_if {
  356         char            ni_name[IFNAMSIZ]; /* name of the interface. */
  357         const uint32_t  ni_version;     /* API version, currently unused */
  358         const uint32_t  ni_flags;       /* properties */
  359 #define NI_PRIV_MEM     0x1             /* private memory region */
  360 
  361         /*
  362          * The number of packet rings available in netmap mode.
  363          * Physical NICs can have different numbers of tx and rx rings.
  364          * Physical NICs also have a 'host' ring pair.
  365          * Additionally, clients can request additional ring pairs to
  366          * be used for internal communication.
  367          */
  368         const uint32_t  ni_tx_rings;    /* number of HW tx rings */
  369         const uint32_t  ni_rx_rings;    /* number of HW rx rings */
  370 
  371         uint32_t        ni_bufs_head;   /* head index for extra bufs */
  372         uint32_t        ni_spare1[5];
  373         /*
  374          * The following array contains the offset of each netmap ring
  375          * from this structure, in the following order:
  376          * NIC tx rings (ni_tx_rings); host tx ring (1); extra tx rings;
  377          * NIC rx rings (ni_rx_rings); host tx ring (1); extra rx rings.
  378          *
  379          * The area is filled up by the kernel on NIOCREGIF,
  380          * and then only read by userspace code.
  381          */
  382         const ssize_t   ring_ofs[0];
  383 };
  384 
  385 /* Legacy interface to interact with a netmap control device.
  386  * Included for backward compatibility. The user should not include this
  387  * file directly. */
  388 #include "netmap_legacy.h"
  389 
  390 /*
  391  * New API to control netmap control devices. New applications should only use
  392  * nmreq_xyz structs with the NIOCCTRL ioctl() command.
  393  *
  394  * NIOCCTRL takes a nmreq_header struct, which contains the required
  395  * API version, the name of a netmap port, a command type, and pointers
  396  * to request body and options.
  397  *
  398  *      nr_name (in)
  399  *              The name of the port (em0, valeXXX:YYY, eth0{pn1 etc.)
  400  *
  401  *      nr_version (in/out)
  402  *              Must match NETMAP_API as used in the kernel, error otherwise.
  403  *              Always returns the desired value on output.
  404  *
  405  *      nr_reqtype (in)
  406  *              One of the NETMAP_REQ_* command types below
  407  *
  408  *      nr_body (in)
  409  *              Pointer to a command-specific struct, described by one
  410  *              of the struct nmreq_xyz below.
  411  *
  412  *      nr_options (in)
  413  *              Command specific options, if any.
  414  *
  415  * A NETMAP_REQ_REGISTER command activates netmap mode on the netmap
  416  * port (e.g. physical interface) specified by nmreq_header.nr_name.
  417  * The request body (struct nmreq_register) has several arguments to
  418  * specify how the port is to be registered.
  419  *
  420  *      nr_tx_slots, nr_tx_slots, nr_tx_rings, nr_rx_rings (in/out)
  421  *              On input, non-zero values may be used to reconfigure the port
  422  *              according to the requested values, but this is not guaranteed.
  423  *              On output the actual values in use are reported.
  424  *
  425  *      nr_mode (in)
  426  *              Indicate what set of rings must be bound to the netmap
  427  *              device (e.g. all NIC rings, host rings only, NIC and
  428  *              host rings, ...). Values are in NR_REG_*.
  429  *
  430  *      nr_ringid (in)
  431  *              If nr_mode == NR_REG_ONE_NIC (only a single couple of TX/RX
  432  *              rings), indicate which NIC TX and/or RX ring is to be bound
  433  *              (0..nr_*x_rings-1).
  434  *
  435  *      nr_flags (in)
  436  *              Indicate special options for how to open the port.
  437  *
  438  *              NR_NO_TX_POLL can be OR-ed to make select()/poll() push
  439  *                      packets on tx rings only if POLLOUT is set.
  440  *                      The default is to push any pending packet.
  441  *
  442  *              NR_DO_RX_POLL can be OR-ed to make select()/poll() release
  443  *                      packets on rx rings also when POLLIN is NOT set.
  444  *                      The default is to touch the rx ring only with POLLIN.
  445  *                      Note that this is the opposite of TX because it
  446  *                      reflects the common usage.
  447  *
  448  *              Other options are NR_MONITOR_TX, NR_MONITOR_RX, NR_ZCOPY_MON,
  449  *              NR_EXCLUSIVE, NR_RX_RINGS_ONLY, NR_TX_RINGS_ONLY and
  450  *              NR_ACCEPT_VNET_HDR.
  451  *
  452  *      nr_mem_id (in/out)
  453  *              The identity of the memory region used.
  454  *              On input, 0 means the system decides autonomously,
  455  *              other values may try to select a specific region.
  456  *              On return the actual value is reported.
  457  *              Region '1' is the global allocator, normally shared
  458  *              by all interfaces. Other values are private regions.
  459  *              If two ports the same region zero-copy is possible.
  460  *
  461  *      nr_extra_bufs (in/out)
  462  *              Number of extra buffers to be allocated.
  463  *
  464  * The other NETMAP_REQ_* commands are described below.
  465  *
  466  */
  467 
  468 /* maximum size of a request, including all options */
  469 #define NETMAP_REQ_MAXSIZE      4096
  470 
  471 /* Header common to all request options. */
  472 struct nmreq_option {
  473         /* Pointer ot the next option. */
  474         uint64_t                nro_next;
  475         /* Option type. */
  476         uint32_t                nro_reqtype;
  477         /* (out) status of the option:
  478          * 0: recognized and processed
  479          * !=0: errno value
  480          */
  481         uint32_t                nro_status;
  482 };
  483 
  484 /* Header common to all requests. Do not reorder these fields, as we need
  485  * the second one (nr_reqtype) to know how much to copy from/to userspace. */
  486 struct nmreq_header {
  487         uint16_t                nr_version;     /* API version */
  488         uint16_t                nr_reqtype;     /* nmreq type (NETMAP_REQ_*) */
  489         uint32_t                nr_reserved;    /* must be zero */
  490 #define NETMAP_REQ_IFNAMSIZ     64
  491         char                    nr_name[NETMAP_REQ_IFNAMSIZ]; /* port name */
  492         uint64_t                nr_options;     /* command-specific options */
  493         uint64_t                nr_body;        /* ptr to nmreq_xyz struct */
  494 };
  495 
  496 enum {
  497         /* Register a netmap port with the device. */
  498         NETMAP_REQ_REGISTER = 1,
  499         /* Get information from a netmap port. */
  500         NETMAP_REQ_PORT_INFO_GET,
  501         /* Attach a netmap port to a VALE switch. */
  502         NETMAP_REQ_VALE_ATTACH,
  503         /* Detach a netmap port from a VALE switch. */
  504         NETMAP_REQ_VALE_DETACH,
  505         /* List the ports attached to a VALE switch. */
  506         NETMAP_REQ_VALE_LIST,
  507         /* Set the port header length (was virtio-net header length). */
  508         NETMAP_REQ_PORT_HDR_SET,
  509         /* Get the port header length (was virtio-net header length). */
  510         NETMAP_REQ_PORT_HDR_GET,
  511         /* Create a new persistent VALE port. */
  512         NETMAP_REQ_VALE_NEWIF,
  513         /* Delete a persistent VALE port. */
  514         NETMAP_REQ_VALE_DELIF,
  515         /* Enable polling kernel thread(s) on an attached VALE port. */
  516         NETMAP_REQ_VALE_POLLING_ENABLE,
  517         /* Disable polling kernel thread(s) on an attached VALE port. */
  518         NETMAP_REQ_VALE_POLLING_DISABLE,
  519         /* Get info about the pools of a memory allocator. */
  520         NETMAP_REQ_POOLS_INFO_GET,
  521 };
  522 
  523 enum {
  524         /* On NETMAP_REQ_REGISTER, ask netmap to use memory allocated
  525          * from user-space allocated memory pools (e.g. hugepages). */
  526         NETMAP_REQ_OPT_EXTMEM = 1,
  527 };
  528 
  529 /*
  530  * nr_reqtype: NETMAP_REQ_REGISTER
  531  * Bind (register) a netmap port to this control device.
  532  */
  533 struct nmreq_register {
  534         uint64_t        nr_offset;      /* nifp offset in the shared region */
  535         uint64_t        nr_memsize;     /* size of the shared region */
  536         uint32_t        nr_tx_slots;    /* slots in tx rings */
  537         uint32_t        nr_rx_slots;    /* slots in rx rings */
  538         uint16_t        nr_tx_rings;    /* number of tx rings */
  539         uint16_t        nr_rx_rings;    /* number of rx rings */
  540 
  541         uint16_t        nr_mem_id;      /* id of the memory allocator */
  542         uint16_t        nr_ringid;      /* ring(s) we care about */
  543         uint32_t        nr_mode;        /* specify NR_REG_* modes */
  544 
  545         uint64_t        nr_flags;       /* additional flags (see below) */
  546 /* monitors use nr_ringid and nr_mode to select the rings to monitor */
  547 #define NR_MONITOR_TX   0x100
  548 #define NR_MONITOR_RX   0x200
  549 #define NR_ZCOPY_MON    0x400
  550 /* request exclusive access to the selected rings */
  551 #define NR_EXCLUSIVE    0x800
  552 /* request ptnetmap host support */
  553 #define NR_PASSTHROUGH_HOST     NR_PTNETMAP_HOST /* deprecated */
  554 #define NR_PTNETMAP_HOST        0x1000
  555 #define NR_RX_RINGS_ONLY        0x2000
  556 #define NR_TX_RINGS_ONLY        0x4000
  557 /* Applications set this flag if they are able to deal with virtio-net headers,
  558  * that is send/receive frames that start with a virtio-net header.
  559  * If not set, NIOCREGIF will fail with netmap ports that require applications
  560  * to use those headers. If the flag is set, the application can use the
  561  * NETMAP_VNET_HDR_GET command to figure out the header length. */
  562 #define NR_ACCEPT_VNET_HDR      0x8000
  563 /* The following two have the same meaning of NETMAP_NO_TX_POLL and
  564  * NETMAP_DO_RX_POLL. */
  565 #define NR_DO_RX_POLL           0x10000
  566 #define NR_NO_TX_POLL           0x20000
  567 
  568         uint32_t        nr_extra_bufs;  /* number of requested extra buffers */
  569 };
  570 
  571 /* Valid values for nmreq_register.nr_mode (see above). */
  572 enum {  NR_REG_DEFAULT  = 0,    /* backward compat, should not be used. */
  573         NR_REG_ALL_NIC  = 1,
  574         NR_REG_SW       = 2,
  575         NR_REG_NIC_SW   = 3,
  576         NR_REG_ONE_NIC  = 4,
  577         NR_REG_PIPE_MASTER = 5, /* deprecated, use "x{y" port name syntax */
  578         NR_REG_PIPE_SLAVE = 6,  /* deprecated, use "x}y" port name syntax */
  579 };
  580 
  581 /* A single ioctl number is shared by all the new API command.
  582  * Demultiplexing is done using the nr_hdr.nr_reqtype field.
  583  * FreeBSD uses the size value embedded in the _IOWR to determine
  584  * how much to copy in/out, so we define the ioctl() command
  585  * specifying only nmreq_header, and copyin/copyout the rest. */
  586 #define NIOCCTRL        _IOWR('i', 151, struct nmreq_header)
  587 
  588 /* The ioctl commands to sync TX/RX netmap rings.
  589  * NIOCTXSYNC, NIOCRXSYNC synchronize tx or rx queues,
  590  *      whose identity is set in NIOCREGIF through nr_ringid.
  591  *      These are non blocking and take no argument. */
  592 #define NIOCTXSYNC      _IO('i', 148) /* sync tx queues */
  593 #define NIOCRXSYNC      _IO('i', 149) /* sync rx queues */
  594 
  595 /*
  596  * nr_reqtype: NETMAP_REQ_PORT_INFO_GET
  597  * Get information about a netmap port, including number of rings.
  598  * slots per ring, id of the memory allocator, etc.
  599  */
  600 struct nmreq_port_info_get {
  601         uint64_t        nr_offset;      /* nifp offset in the shared region */
  602         uint64_t        nr_memsize;     /* size of the shared region */
  603         uint32_t        nr_tx_slots;    /* slots in tx rings */
  604         uint32_t        nr_rx_slots;    /* slots in rx rings */
  605         uint16_t        nr_tx_rings;    /* number of tx rings */
  606         uint16_t        nr_rx_rings;    /* number of rx rings */
  607         uint16_t        nr_mem_id;      /* id of the memory allocator */
  608 };
  609 
  610 #define NM_BDG_NAME             "vale"  /* prefix for bridge port name */
  611 
  612 /*
  613  * nr_reqtype: NETMAP_REQ_VALE_ATTACH
  614  * Attach a netmap port to a VALE switch. Both the name of the netmap
  615  * port and the VALE switch are specified through the nr_name argument.
  616  * The attach operation could need to register a port, so at least
  617  * the same arguments are available.
  618  * port_index will contain the index where the port has been attached.
  619  */
  620 struct nmreq_vale_attach {
  621         struct nmreq_register reg;
  622         uint32_t port_index;
  623 };
  624 
  625 /*
  626  * nr_reqtype: NETMAP_REQ_VALE_DETACH
  627  * Detach a netmap port from a VALE switch. Both the name of the netmap
  628  * port and the VALE switch are specified through the nr_name argument.
  629  * port_index will contain the index where the port was attached.
  630  */
  631 struct nmreq_vale_detach {
  632         uint32_t port_index;
  633 };
  634 
  635 /*
  636  * nr_reqtype: NETMAP_REQ_VALE_LIST
  637  * List the ports of a VALE switch.
  638  */
  639 struct nmreq_vale_list {
  640         /* Name of the VALE port (valeXXX:YYY) or empty. */
  641         uint16_t        nr_bridge_idx;
  642         uint32_t        nr_port_idx;
  643 };
  644 
  645 /*
  646  * nr_reqtype: NETMAP_REQ_PORT_HDR_SET or NETMAP_REQ_PORT_HDR_GET
  647  * Set the port header length.
  648  */
  649 struct nmreq_port_hdr {
  650         uint32_t        nr_hdr_len;
  651 };
  652 
  653 /*
  654  * nr_reqtype: NETMAP_REQ_VALE_NEWIF
  655  * Create a new persistent VALE port.
  656  */
  657 struct nmreq_vale_newif {
  658         uint32_t        nr_tx_slots;    /* slots in tx rings */
  659         uint32_t        nr_rx_slots;    /* slots in rx rings */
  660         uint16_t        nr_tx_rings;    /* number of tx rings */
  661         uint16_t        nr_rx_rings;    /* number of rx rings */
  662         uint16_t        nr_mem_id;      /* id of the memory allocator */
  663 };
  664 
  665 /*
  666  * nr_reqtype: NETMAP_REQ_VALE_POLLING_ENABLE or NETMAP_REQ_VALE_POLLING_DISABLE
  667  * Enable or disable polling kthreads on a VALE port.
  668  */
  669 struct nmreq_vale_polling {
  670         uint32_t        nr_mode;
  671 #define NETMAP_POLLING_MODE_SINGLE_CPU 1
  672 #define NETMAP_POLLING_MODE_MULTI_CPU 2
  673         uint32_t        nr_first_cpu_id;
  674         uint32_t        nr_num_polling_cpus;
  675 };
  676 
  677 /*
  678  * nr_reqtype: NETMAP_REQ_POOLS_INFO_GET
  679  * Get info about the pools of the memory allocator of the port bound
  680  * to a given netmap control device (used i.e. by a ptnetmap-enabled
  681  * hypervisor). The nr_hdr.nr_name field is ignored.
  682  */
  683 struct nmreq_pools_info {
  684         uint64_t        nr_memsize;
  685         uint16_t        nr_mem_id;
  686         uint64_t        nr_if_pool_offset;
  687         uint32_t        nr_if_pool_objtotal;
  688         uint32_t        nr_if_pool_objsize;
  689         uint64_t        nr_ring_pool_offset;
  690         uint32_t        nr_ring_pool_objtotal;
  691         uint32_t        nr_ring_pool_objsize;
  692         uint64_t        nr_buf_pool_offset;
  693         uint32_t        nr_buf_pool_objtotal;
  694         uint32_t        nr_buf_pool_objsize;
  695 };
  696 
  697 /*
  698  * data for NETMAP_REQ_OPT_* options
  699  */
  700 
  701 struct nmreq_opt_extmem {
  702         struct nmreq_option     nro_opt;        /* common header */
  703         uint64_t                nro_usrptr;     /* (in) ptr to usr memory */
  704         struct nmreq_pools_info nro_info;       /* (in/out) */
  705 };
  706 
  707 #endif /* _NET_NETMAP_H_ */

Cache object: 93fc91e4642b79684973b36e577e8fef


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.