mbuf.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:12k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* mbuf.h - mbuf header file */
  2. /* Copyright 1984 - 2002 Wind River Systems, Inc. */
  3. /*
  4.  * Copyright (c) 1982, 1986, 1988, 1993
  5.  * The Regents of the University of California.  All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  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.  * 3. All advertising materials mentioning features or use of this software
  16.  *    must display the following acknowledgement:
  17.  * This product includes software developed by the University of
  18.  * California, Berkeley and its contributors.
  19.  * 4. Neither the name of the University nor the names of its contributors
  20.  *    may be used to endorse or promote products derived from this software
  21.  *    without specific prior written permission.
  22.  *
  23.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33.  * SUCH DAMAGE.
  34.  *
  35.  * @(#)mbuf.h 8.3 (Berkeley) 1/21/94
  36.  */
  37. /*
  38. modification history
  39. --------------------
  40. 01n,21mar02,vvv  updated doc for copy_from_mbufs (SPR #20787)
  41. 01m,10oct01,rae  merge from truestack (VIRTUAL_STACK)
  42. 01l,30oct00,ijm  changed M_TRAILINGSPACE from + to - (m)->m_len (SPR# 30996)
  43. 01k,11dec97,vin  made m_free and m_freem as macros calling netMblkClFree
  44.  and netMblkClChainFree functions.
  45. 01j,08dec97,vin  changed m_copym to netMblkChainDup macro SPR 9966.
  46. 01i,30nov97,vin  added extern declarations _pNetSysPool & relevant stuff.
  47. 01h,19sep97,vin  changes to fit in clBlk logic
  48. 01g,14aug97,vin  changed MBUF_CONFIG to MBLK_CONFIG moved generic stuff to
  49.  netBufLib.h
  50. 01f,02jul97,vin  moved clIncr in clPool to the end. optimized mbuf structure
  51.  for long word accesses.
  52. 01e,15may97,vin  reworked macro copy_from_mbufs, and bcopy_from_mbufs,
  53.  cleanup.
  54. 01d,31jan96,vin  added default cluster configurations.
  55. 01c,03dec96,vin  changed declaration for m_getclr(). 
  56. 01b,17nov96,vin  removed mbufs, code works with (mbuf, cluster) pair.
  57. 01a,03mar96,vin  created from BSD4.4 stuff,integrated with 02u of mbuf.h
  58. */
  59. #ifndef __INCmbufh
  60. #define __INCmbufh
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. #include "vxWorks.h"
  65. #include "sys/types.h"
  66. #include "net/unixLib.h"
  67. #include "semLib.h"
  68. #include "memLib.h"
  69. #include "string.h"
  70. #include "netBufLib.h"
  71. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  72. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  73. #endif /* CPU_FAMILY==I960 */
  74. /* Constants */
  75. #define MCLBYTES         2048 /* default cluster size */
  76. #define USE_CLUSTER(size)       ((size) >= 512 ? TRUE : FALSE)
  77. #define M_MAXCOMPRESS (CL_SIZE_128/2) /* max amount to copy for compression */
  78. #define mbuf mBlk
  79. #define m_next mBlkHdr.mNext
  80. #define m_len mBlkHdr.mLen
  81. #define m_data mBlkHdr.mData
  82. #define m_type mBlkHdr.mType
  83. #define m_flags mBlkHdr.mFlags
  84. #define m_nextpkt mBlkHdr.mNextPkt
  85. #define m_act m_nextpkt
  86. #define m_pkthdr mBlkPktHdr
  87. #define m_ext pClBlk
  88. #define m_extBuf m_ext->clNode.pClBuf
  89. #define m_extFreeRtn m_ext->pClFreeRtn
  90. #define m_extSize m_ext->clSize
  91. #define m_extRefCnt m_ext->clRefCnt
  92. #define m_extArg1 m_ext->clFreeArg1
  93. #define m_extArg2 m_ext->clFreeArg2
  94. #define m_extArg3 m_ext->clFreeArg3
  95. /* flags copied when copying m_pkthdr */
  96. #define M_COPYFLAGS (M_PKTHDR|M_EOR|M_BCAST|M_MCAST)
  97. /* flags to mBufClGet/mHdrClGet/mBlkGet */
  98. /*
  99.  * Macros for type conversion
  100.  * mtod(m,t) - convert mbuf pointer to data pointer of correct type
  101.  */
  102. #define mtod(m,t) ((t)((m)->m_data))
  103. #define MC_NO_CLUSTER ((u_char) 0)
  104. #define MC_CLUSTER ((u_char) 1)
  105. #define MC_LANCE ((u_char) 2) /* 0x02 - 0x80 for netif */
  106. #define MC_BACKPLANE ((u_char) 3)
  107. #define MC_EI ((u_char) 4)
  108. #define MC_UCLUSTER ((u_char) 0x80) /* 0x80 - 0xff for network code */
  109. /* m_pullup will pull up additional length if convenient;
  110.  * should be enough to hold headers of second-level and higher protocols.
  111.  */
  112. #define MPULL_EXTRA 32
  113. /*
  114.  * Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place
  115.  * an object of the specified size at the end of the mbuf, longword aligned.
  116.  */
  117. #define M_ALIGN(m, len) 
  118.     { (m)->m_data += (m->m_extSize - (len)) &~ (sizeof(long) - 1); }
  119. /*
  120.  * As above, for mbufs allocated with m_gethdr/MGETHDR
  121.  * or initialized by M_COPY_PKTHDR.
  122.  */
  123. #define MH_ALIGN(m, len) M_ALIGN((m),(len))
  124. /*
  125.  * Compute the amount of space available
  126.  * before the current start of data in a cluster.
  127.  */
  128. #define M_LEADINGSPACE(m) ((m)->m_data - (m)->m_extBuf) 
  129. /*
  130.  * Compute the amount of space available
  131.  * after the end of data in a cluster.
  132.  */
  133. #define M_TRAILINGSPACE(m) ((m)->m_extBuf + (m)->m_extSize - 
  134.     (m)->m_data - (m)->m_len)
  135. /*
  136.  * Arrange to prepend space of size plen to mbuf m.
  137.  * If a new mbuf must be allocated, how specifies whether to wait.
  138.  * If how is M_DONTWAIT and allocation fails, the original mbuf chain
  139.  * is freed and m is set to NULL.
  140.  */
  141. #ifndef STANDALONE_AGENT
  142. #define M_PREPEND(m, plen, how)
  143.     { 
  144. if (M_LEADINGSPACE(m) >= (plen)) { 
  145. (m)->m_data -= (plen); 
  146. (m)->m_len += (plen); 
  147. } else 
  148. (m) = m_prepend((m), (plen), (how)); 
  149. if ((m) && (m)->m_flags & M_PKTHDR) 
  150. (m)->m_pkthdr.len += (plen); 
  151.     }
  152. #else /* STANDALONE_AGENT */
  153. /*
  154.  * for standalone agent, the M_PREPEND routine does no try to allocate
  155.  * a new buffer (there is no available). Anyway, this is not needed since
  156.  * all the WDB packets can be stored in one buffer.
  157.  */
  158. #define M_PREPEND(m, plen, how)
  159.     { 
  160. if (M_LEADINGSPACE(m) >= (plen)) { 
  161. (m)->m_data -= (plen); 
  162. (m)->m_len += (plen); 
  163. } else 
  164. (m) = NULL;  
  165. if ((m) && (m)->m_flags & M_PKTHDR) 
  166. (m)->m_pkthdr.len += (plen); 
  167.     }
  168. #endif /* STANDALONE_AGENT */
  169. /* change mbuf to new type */
  170. #define MCHTYPE(m, t)
  171.     {
  172.     int ms = splimp(); 
  173.     mbstat.m_mtypes[(m)->m_type]--; 
  174.     mbstat.m_mtypes[t]++;
  175.     (m)->m_type = t;                                            
  176.     splx(ms); 
  177.     }
  178. /*
  179.  * We have to do this locally so that we don't have circular
  180.  * include dependencies.
  181.  */
  182. #ifdef VIRTUAL_STACK
  183. #define _pNetDpool vsTbl[myStackNum]->pNetDPool
  184. #endif
  185. /* compatiblity with 4.3 */
  186. #define  m_copy(m, o, l)        m_copym((m), (o), (l), M_DONTWAIT)
  187. #define  m_copym(m, o, l, w)  netMblkChainDup(_pNetDpool, (m), (o), (l), (w))
  188. #define  m_freem(m) netMblkClChainFree(m)
  189. #define  m_free(m) netMblkClFree(m)    
  190. #ifdef VIRTUAL_STACK
  191. #undef _pNetDpool  /* prevents conflicts with vsData.h definition */
  192. #endif
  193. #define m_mbufs mNum
  194. #define m_drops mDrops
  195. #define m_wait mWait
  196. #define m_drain mDrain
  197. #define m_mtypes  mTypes
  198. /* SunOS compatible macros to be used in network interface drivers */
  199. /* copy_from_mbufs copies data from mbuf chain to user supplied buffer area.
  200.  *
  201.  * N.B.: This macro takes an extra argument 'len' which is used to return
  202.  * the number of bytes actually transferred.  SunOS routine copy_from_mbufs
  203.  * returns this value; VxWorks macro copy_from_mbufs "returns" the same
  204.  * value in 'len'.
  205.  *
  206.  * This macro should not be used since bcopy_from_mbufs is now obsolete.
  207.  */
  208. #define copy_from_mbufs(buf0, m, len) 
  209.     bcopy_from_mbufs (buf0, m, len, NONE)
  210. /* bcopy_from_mbufs copies dat from mbuf chain to user supplied buffer area
  211.  * by transferring bytes by unit 'width' indicated by the user.
  212.  * This macro is similiar to copy_from_mbufs; the only difference is the
  213.  * extra argument 'width' which is used to accommodate certain hardware
  214.  * restrictions that require copying of data to only occur at certain byte size
  215.  * boundaries.  Calling this macro with 'width' value set to NONE is equivalent
  216.  * to calling copy_from_mbufs macro.
  217.  *
  218.  * This macro should not be used since it calls copyFromMbufs which may cause
  219.  * unaligned memory accesses resulting in target failure. The routine
  220.  * netMblkToBufCopy can be used instead. However, netMblkToBufCopy does not
  221.  * free the mbuf chain after copying.
  222.  *
  223.  * Instead of 
  224.  *    bcopy_from_mbufs (pBuf, pMblk, len, width);
  225.  * we can have
  226.  *    len = netMblkToBufCopy (pMblk, pBuf, NULL);
  227.  *    netMblkClChainFree (pMblk);
  228.  *
  229.  * There is no width argument but the last argument to netMblkToBufCopy 
  230.  * specifies which routine will be used to copy the data. If NULL, bcopy is
  231.  * used.
  232.  */
  233.         
  234. #define bcopy_from_mbufs(buf0, m, len, width)
  235.     {
  236.     (len) = copyFromMbufs (buf0, m, width);
  237.     }
  238.     
  239. /* copy_to_mbufs copies data into mbuf chain and returns the pointer to
  240.  * the first mbuf.
  241.  *
  242.  * N.B.: This macro calls a routine bcopy_to_mbufs with width value set
  243.  * to NONE.  VxWorks routine bcopy_to_mbufs is provided to accommodate
  244.  * hardware restrictions that require copying of data to only
  245.  * occur at certain byte size boundaries.
  246.  */
  247. #define copy_to_mbufs(buf, totlen, off, ifp) 
  248.     bcopy_to_mbufs (buf, totlen, off, ifp, NONE)
  249. #if ((CPU_FAMILY==I960) && (defined __GNUC__))
  250. #pragma align 0                 /* turn off alignment requirement */
  251. #endif  /* CPU_FAMILY==I960 */
  252. /* imported stuff */
  253. IMPORT struct mbstat  mbstat; /* mBlk statistics */
  254. IMPORT M_CL_CONFIG mClBlkConfig; /* mBlk, clBlk configuration */
  255. IMPORT CL_DESC  clDescTbl []; /* cluster configuration */
  256. IMPORT int clDescTblNumEnt;  /* no. elements in the table */
  257. IMPORT M_CL_CONFIG sysMclBlkConfig; /* mBlk, clBlk configuration */
  258. IMPORT CL_DESC  sysClDescTbl []; /* cluster configuration */
  259. IMPORT int sysClDescTblNumEnt;  /* no. elements in the table */
  260. #ifndef VIRTUAL_STACK
  261. IMPORT NET_POOL_ID _pNetDpool; /* network data pool */
  262. IMPORT NET_POOL_ID _pNetSysPool; /* network data pool */
  263. #endif
  264. /* These variables are initialized when individual protocols are initialized */
  265. extern int max_linkhdr; /* largest link-level header */
  266. extern int max_protohdr; /* largest protocol header */
  267. extern int max_hdr; /* largest link+protocol header */
  268. extern int max_datalen; /* CL_SIZE_128 - max_hdr */
  269. extern struct mbuf *m_free (struct mbuf *);
  270. extern struct mbuf *m_getclr (int, UCHAR, int, BOOL);
  271. extern struct mbuf *m_prepend (struct mbuf *, int, int);
  272. extern struct mbuf *m_pullup (struct mbuf *, int);
  273. extern void m_adj (struct mbuf *, int);
  274. extern void m_freem (struct mbuf *);
  275. extern void  m_cat (struct mbuf *, struct mbuf *);
  276. extern struct  mbuf *m_devget (char *, int, int, struct ifnet *,
  277. void (*copy)());
  278. struct mbuf * mBufClGet (int, UCHAR, FAST int, BOOL); 
  279. struct mbuf *  mHdrClGet (int, UCHAR, FAST int, BOOL); 
  280. IMPORT struct mbuf * bcopy_to_mbufs (u_char * buf, int totlen, int off0,
  281.                                      struct ifnet * ifp, int width);
  282. IMPORT struct mbuf * build_cluster (u_char * buf, int totlen,
  283.                                     struct ifnet * ifp, u_char ctype,
  284.                                     u_char * pRefcnt, FUNCPTR freeRtn,
  285.                                     int arg1, int arg2, int arg3);
  286. IMPORT int copyFromMbufs (char * pIobuf, struct mbuf * pMbuf, int width);
  287. #ifdef __cplusplus
  288. }
  289. #endif
  290. #endif /* __INCmbufh */