GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / net / net_ebuf.h
blob293dbddb08ab207163e5758dd6577cec0c015510
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 * Network EBUF macros File: net_ebuf.h
5 *
6 * This file contains macros and function prototypes for
7 * messing with "ebuf" buffers. ebufs describe network
8 * packets. They're sort of like poor-man's mbufs :-)
9 *
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
50 /* *********************************************************************
51 * Constants
52 ********************************************************************* */
55 #define ENET_MAX_PKT 1514
56 #define ENET_CRC_SIZE 4
57 #define ENET_ADDR_LEN 6
58 #define ENET_DIX_HEADER 14
60 /* *********************************************************************
61 * Structures
62 ********************************************************************* */
65 typedef struct ebuf_s {
66 queue_t eb_qblock; /* linkage */
67 unsigned int eb_length; /* length of area at eb_ptr */
68 unsigned int eb_status; /* rx/tx status */
69 int eb_port; /* eth port that owns buffer */
70 void *eb_device; /* underlying net device */
71 int eb_usrdata; /* user-defined stuff */
72 uint8_t *eb_usrptr; /* user-defined stuff */
73 uint8_t *eb_ptr; /* current ptr within pkt */
74 uint8_t eb_data[0x5F0]; /* data, must be > ENET_MAX_PKT */
75 /* and divisible by sizeof(uint) */
76 } ebuf_t;
79 * Macros to initialize ebufs
82 #define ebuf_init_rx(eb) (eb)->eb_ptr = (eb)->eb_data; \
83 (eb)->eb_length = 0; \
84 (eb)->eb_status = 0
86 #define ebuf_init_tx(eb) (eb)->eb_ptr = (eb)->eb_data; \
87 (eb)->eb_length = 0; \
88 (eb)->eb_status = 0
91 * Macros to move the currens position within an ebuf
94 #define ebuf_prepend(eb,amt) (eb)->eb_ptr -= amt; (eb)->eb_length += (amt)
95 #define ebuf_adjust(eb,amt) (eb)->eb_ptr += (amt); (eb)->eb_length += (amt)
96 #define ebuf_seek(eb,amt) (eb)->eb_ptr += (amt)
98 #define ebuf_remlen(eb) ((eb)->eb_length)
99 #define ebuf_length(eb) ((eb)->eb_length)
100 #define ebuf_ptr(eb) ((eb)->eb_ptr)
101 #define ebuf_setlength(eb,amt) (eb)->eb_length = (amt)
104 * ebuf_append_xxx macros - these macros add data to the
105 * end of a packet, adjusting the length
108 #define ebuf_append_u8(eb,b) ((eb)->eb_ptr[(eb)->eb_length++]) = (b) ;
109 #define ebuf_append_u16_be(eb,w) ebuf_append_u8(eb,((w) >> 8) & 0xFF) ; \
110 ebuf_append_u8(eb,((w) & 0xFF))
112 #define ebuf_append_u32_be(eb,w) ebuf_append_u8(eb,((w) >> 24) & 0xFF) ; \
113 ebuf_append_u8(eb,((w) >> 16) & 0xFF) ; \
114 ebuf_append_u8(eb,((w) >> 8) & 0xFF) ; \
115 ebuf_append_u8(eb,((w) & 0xFF))
117 #define ebuf_append_bytes(eb,b,l) memcpy(&((eb)->eb_ptr[(eb)->eb_length]),(b),(l)); \
118 (eb)->eb_length += (l)
121 * ebuf_put_xxx macros - these macros modify data in the middle
122 * of a packet, typically in an area already allocated with
123 * ebuf_adjust. The length is not updated, but the pointer is.
126 #define ebuf_put_u8(eb,b) *((eb)->eb_ptr++) = (b)
127 #define ebuf_put_u16_be(eb,w) ebuf_put_u8(eb,((w) >> 8) & 0xFF) ; \
128 ebuf_put_u8(eb,((w) & 0xFF))
130 #define ebuf_put_u32_be(eb,w) ebuf_put_u8(eb,((w) >> 24) & 0xFF) ; \
131 ebuf_put_u8(eb,((w) >> 16) & 0xFF) ; \
132 ebuf_put_u8(eb,((w) >> 8) & 0xFF) ; \
133 ebuf_put_u8(eb,((w) & 0xFF))
135 #define ebuf_put_bytes(eb,b,l) memcpy((buf)->eb_ptr,(b),(l)) ; (buf)->eb_ptr += (l)
137 #define ebuf_srcaddr(eb) &((eb)->eb_data[6])
138 #define ebuf_destaddr(eb) &((eb)->eb_data[0])
140 /* return next byte from the ebuf, and advance pointer */
142 #define ebuf_skip(eb,amt) (eb)->eb_length -= (amt); (eb)->eb_ptr += (amt)
144 #define ebuf_get_u8(eb,v) (eb)->eb_length--; \
145 v = (*((eb)->eb_ptr++))
147 /* return next u16 from the ebuf, big-endian */
149 #define ebuf_get_u16_be(eb,v) (eb)->eb_ptr+=2; \
150 (eb)->eb_length-=2; \
151 v = ( ((uint16_t)*((eb)->eb_ptr-1)) | \
152 (((uint16_t)*((eb)->eb_ptr-2)) << 8) )
154 /* return next u32 from the ebuf, big-endian */
156 #define ebuf_get_u32_be(eb,v) (eb)->eb_ptr+=4; \
157 (eb)->eb_length-=4; \
158 v = ( ((uint32_t)*((eb)->eb_ptr-1)) | \
159 (((uint32_t)*((eb)->eb_ptr-2)) << 8) | \
160 (((uint32_t)*((eb)->eb_ptr-3)) << 16) | \
161 (((uint32_t)*((eb)->eb_ptr-4)) << 24) )
163 #define ebuf_get_bytes(eb,b,l) memcpy((b),(buf)->eb_ptr,(l)) ; (eb)->eb_ptr += (l) ; (eb)->eb_length -= (l)