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/netatm/port.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  *
    3  * ===================================
    4  * HARP  |  Host ATM Research Platform
    5  * ===================================
    6  *
    7  *
    8  * This Host ATM Research Platform ("HARP") file (the "Software") is
    9  * made available by Network Computing Services, Inc. ("NetworkCS")
   10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
   11  * support of any kind.
   12  *
   13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
   14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
   15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
   16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
   17  * In no event shall NetworkCS be responsible for any damages, including
   18  * but not limited to consequential damages, arising from or relating to
   19  * any use of the Software or related support.
   20  *
   21  * Copyright 1994-1998 Network Computing Services, Inc.
   22  *
   23  * Copies of this Software may be made, however, the above copyright
   24  * notice must be reproduced on all copies.
   25  *
   26  *      @(#) $FreeBSD$
   27  *
   28  */
   29 
   30 /*
   31  * System Configuration
   32  * --------------------
   33  *
   34  * Porting aides
   35  *
   36  */
   37 
   38 #ifndef _NETATM_PORT_H
   39 #define _NETATM_PORT_H
   40 
   41 
   42 #ifdef _KERNEL
   43 /*
   44  * Kernel buffers
   45  *
   46  * KBuffer              Typedef for a kernel buffer.
   47  *
   48  * KB_NEXT(bfr)         Access next buffer in chain (r/w).
   49  * KB_LEN(bfr)          Access length of data in this buffer (r/w).
   50  * KB_QNEXT(bfr)        Access next buffer in queue (r/w).
   51  *
   52  * KB_ALLOC(bfr, size, flags, type)
   53  *                      Allocates a new kernel buffer of at least size bytes.
   54  * KB_ALLOCPKT(bfr, size, flags, type)
   55  *                      Allocates a new kernel packet header buffer of at
   56  *                      least size bytes.
   57  * KB_ALLOCEXT(bfr, size, flags, type)
   58  *                      Allocates a new kernel buffer with external storage
   59  *                      of at least size bytes.
   60  * KB_FREEONE(bfr, nxt) Free buffer bfr and set next buffer in chain in nxt.
   61  * KB_FREEALL(bfr)      Free bfr's entire buffer chain.
   62  * KB_COPY(bfr, off, len, new, flags)
   63  *                      Copy len bytes of user data from buffer bfr starting at
   64  *                      byte offset off and return new buffer chain in new.
   65  *                      If len is KB_COPYALL, copy until end of chain.
   66  * KB_COPYDATA(bfr, off, len, datap)
   67  *                      Copy data from buffer bfr starting at byte offset off
   68  *                      for len bytes into the data area pointed to by datap.
   69  *                      Returns the number of bytes not copied to datap.
   70  * KB_PULLUP(bfr, n, new)
   71  *                      Get at least the first n bytes of data in the buffer 
   72  *                      chain headed by bfr contiguous in the first buffer.
   73  *                      Returns the (potentially new) head of the chain in new.
   74  *                      On failure the chain is freed and NULL is returned.
   75  * KB_LINKHEAD(new, head)
   76  *                      Link the kernel buffer new at the head of the buffer
   77  *                      chain headed by head.  If both new and head are
   78  *                      packet header buffers, new will become the packet
   79  *                      header for the chain.
   80  * KB_LINK(new, prev)
   81  *                      Link the kernel buffer new into the buffer chain
   82  *                      after the buffer prev.
   83  * KB_UNLINKHEAD(head, next)
   84  *                      Unlink the kernel buffer from the head of the buffer
   85  *                      chain headed by head.  The buffer head will be freed
   86  *                      and the new chain head will be placed in next.
   87  * KB_UNLINK(old, prev, next)
   88  *                      Unlink the kernel buffer old with previous buffer prev
   89  *                      from its buffer chain.  The following buffer in the
   90  *                      chain will be placed in next and the buffer old will
   91  *                      be freed.
   92  * KB_ISPKT(bfr)        Tests whether bfr is a packet header buffer.
   93  * KB_ISEXT(bfr)        Tests whether bfr has external storage.
   94  * KB_BFRSTART(bfr, x, t)
   95  *                      Sets x (cast to type t) to point to the start of the
   96  *                      buffer space in bfr.
   97  * KB_BFREND(bfr, x, t)
   98  *                      Sets x (cast to type t) to point one byte past the end
   99  *                      of the buffer space in bfr.
  100  * KB_BFRLEN(bfr)       Returns length of buffer space in bfr.
  101  * KB_DATASTART(bfr, x, t)
  102  *                      Sets x (cast to type t) to point to the start of the
  103  *                      buffer data contained in bfr.
  104  * KB_DATAEND(bfr, x, t)
  105  *                      Sets x (cast to type t) to point one byte past the end
  106  *                      of the buffer data contained in bfr.
  107  * KB_HEADSET(bfr, n)   Sets the start address for buffer data in buffer bfr to
  108  *                      n bytes from the beginning of the buffer space.
  109  * KB_HEADMOVE(bfr, n)  Adjust buffer data controls to move data down (n > 0) 
  110  *                      or up (n < 0) n bytes in the buffer bfr.
  111  * KB_HEADADJ(bfr, n)   Adjust buffer data controls to add (n > 0) or subtract
  112  *                      (n < 0) n bytes of data to/from the beginning of bfr.
  113  * KB_TAILADJ(bfr, n)   Adjust buffer data controls to add (n > 0) or subtract
  114  *                      (n < 0) n bytes of data to/from the end of bfr.
  115  * KB_TAILALIGN(bfr, n) Set buffer data controls to place an object of size n
  116  *                      at the end of bfr, longword aligned.
  117  * KB_HEADROOM(bfr, n)  Set n to the amount of buffer space available before
  118  *                      the start of data in bfr.
  119  * KB_TAILROOM(bfr, n)  Set n to the amount of buffer space available after
  120  *                      the end of data in bfr.
  121  * KB_PLENGET(bfr, n)   Set n to bfr's packet length.
  122  * KB_PLENSET(bfr, n)   Set bfr's packet length to n.
  123  * KB_PLENADJ(bfr, n)   Adjust total packet length by n bytes.
  124  *
  125  */
  126 #include <sys/mbuf.h>
  127 typedef struct mbuf     KBuffer;
  128 
  129 #define KB_F_WAIT       M_TRYWAIT
  130 #define KB_F_NOWAIT     M_DONTWAIT
  131 
  132 #define KB_T_HEADER     MT_HEADER
  133 #define KB_T_DATA       MT_DATA
  134 
  135 #define KB_COPYALL      M_COPYALL
  136 
  137 #define KB_NEXT(bfr)            (bfr)->m_next
  138 #define KB_LEN(bfr)             (bfr)->m_len
  139 #define KB_QNEXT(bfr)           (bfr)->m_nextpkt
  140 #define KB_ALLOC(bfr, size, flags, type) {              \
  141         if ((size) <= MLEN) {                           \
  142                 MGET((bfr), (flags), (type));           \
  143         } else                                          \
  144                 (bfr) = NULL;                           \
  145 }
  146 #define KB_ALLOCPKT(bfr, size, flags, type) {           \
  147         if ((size) <= MHLEN) {                          \
  148                 MGETHDR((bfr), (flags), (type));        \
  149         } else                                          \
  150                 (bfr) = NULL;                           \
  151 }
  152 #define KB_ALLOCEXT(bfr, size, flags, type) {           \
  153         if ((size) <= MCLBYTES) {                       \
  154                 MGET((bfr), (flags), (type));           \
  155                 if ((bfr) != NULL) {                    \
  156                         MCLGET((bfr), (flags));         \
  157                         if (((bfr)->m_flags & M_EXT) == 0) {    \
  158                                 m_freem((bfr));         \
  159                                 (bfr) = NULL;           \
  160                         }                               \
  161                 }                                       \
  162         } else                                          \
  163                 (bfr) = NULL;                           \
  164 }
  165 #define KB_FREEONE(bfr, nxt) {                          \
  166         (nxt) = m_free(bfr);                            \
  167 }
  168 #define KB_FREEALL(bfr) {                               \
  169         m_freem(bfr);                                   \
  170 }
  171 #define KB_COPY(bfr, off, len, new, flags) {            \
  172         (new) = m_copym((bfr), (off), (len), (flags));  \
  173 }
  174 #define KB_COPYDATA(bfr, off, len, datap)               \
  175         (m_copydata((bfr), (off), (len), (datap)), 0)
  176 #define KB_PULLUP(bfr, n, new) {                        \
  177         (new) = m_pullup((bfr), (n));                   \
  178 }
  179 #define KB_LINKHEAD(new, head) {                        \
  180         if ((head) && KB_ISPKT(new) && KB_ISPKT(head)) {\
  181                 M_MOVE_PKTHDR((new), (head));           \
  182         }                                               \
  183         (new)->m_next = (head);                         \
  184 }
  185 #define KB_LINK(new, prev) {                            \
  186         (new)->m_next = (prev)->m_next;                 \
  187         (prev)->m_next = (new);                         \
  188 }
  189 #define KB_UNLINKHEAD(head, next) {                     \
  190         (next) = m_free((head));                        \
  191         (head) = NULL;                                  \
  192 }
  193 #define KB_UNLINK(old, prev, next) {                    \
  194         (next) = m_free((old));                         \
  195         (old) = NULL;                                   \
  196         (prev)->m_next = (next);                        \
  197 }
  198 #define KB_ISPKT(bfr)           (((bfr)->m_flags & M_PKTHDR) != 0)
  199 #define KB_ISEXT(bfr)           (((bfr)->m_flags & M_EXT) != 0)
  200 #define KB_BFRSTART(bfr, x, t) {                        \
  201         if ((bfr)->m_flags & M_EXT)                     \
  202                 (x) = (t)((bfr)->m_ext.ext_buf);        \
  203         else if ((bfr)->m_flags & M_PKTHDR)             \
  204                 (x) = (t)(&(bfr)->m_pktdat);            \
  205         else                                            \
  206                 (x) = (t)((bfr)->m_dat);                \
  207 }
  208 #define KB_BFREND(bfr, x, t) {                          \
  209         if ((bfr)->m_flags & M_EXT)                     \
  210                 (x) = (t)((bfr)->m_ext.ext_buf + (bfr)->m_ext.ext_size);\
  211         else if ((bfr)->m_flags & M_PKTHDR)             \
  212                 (x) = (t)(&(bfr)->m_pktdat + MHLEN);    \
  213         else                                            \
  214                 (x) = (t)((bfr)->m_dat + MLEN);         \
  215 }
  216 #define KB_BFRLEN(bfr)                                  \
  217         (((bfr)->m_flags & M_EXT) ? (bfr)->m_ext.ext_size :     \
  218                 (((bfr)->m_flags & M_PKTHDR) ? MHLEN : MLEN))
  219 #define KB_DATASTART(bfr, x, t) {                       \
  220         (x) = mtod((bfr), t);                           \
  221 }
  222 #define KB_DATAEND(bfr, x, t) {                         \
  223         (x) = (t)(mtod((bfr), caddr_t) + (bfr)->m_len); \
  224 }
  225 #define KB_HEADSET(bfr, n) {                            \
  226         if ((bfr)->m_flags & M_EXT)                     \
  227                 (bfr)->m_data = (bfr)->m_ext.ext_buf + (n);     \
  228         else if ((bfr)->m_flags & M_PKTHDR)             \
  229                 (bfr)->m_data = (bfr)->m_pktdat + (n);  \
  230         else                                            \
  231                 (bfr)->m_data = (bfr)->m_dat + (n);     \
  232 }
  233 #define KB_HEADMOVE(bfr, n) {                           \
  234         (bfr)->m_data += (n);                           \
  235 }
  236 #define KB_HEADADJ(bfr, n) {                            \
  237         (bfr)->m_len += (n);                            \
  238         (bfr)->m_data -= (n);                           \
  239 }
  240 #define KB_TAILADJ(bfr, n) {                            \
  241         (bfr)->m_len += (n);                            \
  242 }
  243 #define KB_TAILALIGN(bfr, n) {                          \
  244         (bfr)->m_len = (n);                             \
  245         if ((bfr)->m_flags & M_EXT)                     \
  246                 (bfr)->m_data = (caddr_t)(((uintptr_t)(bfr)->m_ext.ext_buf \
  247                         + (bfr)->m_ext.ext_size - (n)) & ~(sizeof(long) - 1));\
  248         else                                            \
  249                 (bfr)->m_data = (caddr_t)(((uintptr_t)(bfr)->m_dat + MLEN - (n)) \
  250                         & ~(sizeof(long) - 1));         \
  251 }
  252 #define KB_HEADROOM(bfr, n) {                           \
  253         /* N = m_leadingspace(BFR) XXX */               \
  254         (n) = ((bfr)->m_flags & M_EXT ? (bfr)->m_data - (bfr)->m_ext.ext_buf : \
  255                 (bfr)->m_flags & M_PKTHDR ? (bfr)->m_data - (bfr)->m_pktdat : \
  256                         (bfr)->m_data - (bfr)->m_dat);  \
  257 }
  258 #define KB_TAILROOM(bfr, n) {                           \
  259         (n) = M_TRAILINGSPACE(bfr);                     \
  260 }
  261 #define KB_PLENGET(bfr, n) {                            \
  262         (n) = (bfr)->m_pkthdr.len;                      \
  263 }
  264 #define KB_PLENSET(bfr, n) {                            \
  265         (bfr)->m_pkthdr.len = (n);                      \
  266 }
  267 #define KB_PLENADJ(bfr, n) {                            \
  268         (bfr)->m_pkthdr.len += (n);                     \
  269 }
  270 
  271 
  272 /*
  273  * Kernel time
  274  *
  275  * KTimeout_ret         Typedef for timeout() function return
  276  *
  277  * KT_TIME(t)           Sets t to the current time.
  278  *
  279  */
  280 typedef void    KTimeout_ret;
  281 #define KT_TIME(t)      microtime(&t)
  282 
  283 #endif  /* _KERNEL */
  284 
  285 #ifndef MAX
  286 #define MAX(a,b)        max((a),(b))
  287 #endif
  288 #ifndef MIN
  289 #define MIN(a,b)        min((a),(b))
  290 #endif
  291 
  292 #endif  /* _NETATM_PORT_H */

Cache object: d7ca219b56182de8b8866726b73ff2b6


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