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_user.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  * Copyright (C) 2011 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 are
    6  * met:
    7  * 
    8  *   1. Redistributions of source code must retain the above copyright
    9  *      notice, this list of conditions and the following disclaimer.
   10  * 
   11  *   2. Redistributions in binary form must reproduce the above copyright
   12  *      notice, this list of conditions and the following disclaimer in the
   13  *      documentation and/or other materials provided with the
   14  *      distribution.
   15  * 
   16  *   3. Neither the name of the authors nor the names of their contributors
   17  *      may be used to endorse or promote products derived from this
   18  *      software without specific prior written permission.
   19  * 
   20  * THIS SOFTWARE IS PROVIDED BY MATTEO LANDI AND CONTRIBUTORS "AS IS" AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTEO LANDI OR CONTRIBUTORS
   24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
   30  * THE POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 /*
   34  * $FreeBSD: releng/8.4/sys/net/netmap_user.h 231717 2012-02-14 22:49:34Z luigi $
   35  * $Id: netmap_user.h 9495 2011-10-18 15:28:23Z luigi $
   36  *
   37  * This header contains the macros used to manipulate netmap structures
   38  * and packets in userspace. See netmap(4) for more information.
   39  *
   40  * The address of the struct netmap_if, say nifp, is determined
   41  * by the value returned from ioctl(.., NIOCREG, ...) and the mmap
   42  * region:
   43  *      ioctl(fd, NIOCREG, &req);
   44  *      mem = mmap(0, ... );
   45  *      nifp = NETMAP_IF(mem, req.nr_nifp);
   46  *              (so simple, we could just do it manually)
   47  *
   48  * From there:
   49  *      struct netmap_ring *NETMAP_TXRING(nifp, index)
   50  *      struct netmap_ring *NETMAP_RXRING(nifp, index)
   51  *              we can access ring->nr_cur, ring->nr_avail, ring->nr_flags
   52  *
   53  *      ring->slot[i] gives us the i-th slot (we can access
   54  *              directly plen, flags, bufindex)
   55  *
   56  *      char *buf = NETMAP_BUF(ring, index) returns a pointer to
   57  *              the i-th buffer
   58  *
   59  * Since rings are circular, we have macros to compute the next index
   60  *      i = NETMAP_RING_NEXT(ring, i);
   61  */
   62 
   63 #ifndef _NET_NETMAP_USER_H_
   64 #define _NET_NETMAP_USER_H_
   65 
   66 #define NETMAP_IF(b, o) (struct netmap_if *)((char *)(b) + (o))
   67 
   68 #define NETMAP_TXRING(nifp, index)                      \
   69         ((struct netmap_ring *)((char *)(nifp) +        \
   70                 (nifp)->ring_ofs[index] ) )
   71 
   72 #define NETMAP_RXRING(nifp, index)                      \
   73         ((struct netmap_ring *)((char *)(nifp) +        \
   74             (nifp)->ring_ofs[index + (nifp)->ni_num_queues+1] ) )
   75 
   76 #define NETMAP_BUF(ring, index)                         \
   77         ((char *)(ring) + (ring)->buf_ofs + ((index)*(ring)->nr_buf_size))
   78 
   79 #define NETMAP_RING_NEXT(r, i)                          \
   80         ((i)+1 == (r)->num_slots ? 0 : (i) + 1 )
   81 
   82 /*
   83  * Return 1 if the given tx ring is empty.
   84  *
   85  * @r netmap_ring descriptor pointer.
   86  * Special case, a negative value in hwavail indicates that the
   87  * transmit queue is idle.
   88  * XXX revise
   89  */
   90 #define NETMAP_TX_RING_EMPTY(r) ((r)->avail >= (r)->num_slots - 1)
   91 
   92 #endif /* _NET_NETMAP_USER_H_ */

Cache object: 4f2530dde1c4c5abd94eb4bdd48a746f


[ 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.