2 * HND RTE packet buffer definitions.
4 * Copyright (C) 2010, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: hndrte_lbuf.h,v 13.38 2009-11-08 21:00:48 Exp $
15 #ifndef _hndrte_lbuf_h_
16 #define _hndrte_lbuf_h_
21 struct lbuf
*next
; /* next lbuf in a chain of lbufs forming one packet */
22 struct lbuf
*link
; /* first lbuf of next packet in a list of packets */
23 uchar
*head
; /* fixed start of buffer */
24 uchar
*end
; /* fixed end of buffer */
25 uchar
*data
; /* variable start of data */
26 uint16 len
; /* nbytes of data */
27 uint16 flags
; /* private flags; don't touch */
28 uint16 dmapad
; /* padding to be added for tx dma */
29 uint8 dataOff
; /* offset to beginning of data in 4-byte words */
30 uint8 refcnt
; /* external references to this lbuf */
31 void *pool
; /* BCMPKTPOOL */
32 uint32 pkttag
[(OSL_PKTTAG_SZ
+ 3) / 4]; /* 4-byte-aligned packet tag area */
35 #define LBUFSZ sizeof(struct lbuf)
37 /* Total maximum packet buffer size including lbuf header */
38 #define MAXPKTBUFSZ 1920 /* enough to fit a 1500 MTU plus overhead */
40 /* private flags - don't reference directly */
41 #define LBF_PRI 0x0007 /* priority (low 3 bits of flags) */
42 #define LBF_SUM_NEEDED 0x0008
43 #define LBF_SUM_GOOD 0x0010
44 #define LBF_MSGTRACE 0x0020
45 #define LBF_CLONE 0x0040
46 #define LBF_PTBLK 0x0100 /* came from fixed block in a partition, not main malloc */
47 #define LBF_POOL 0x0200
48 #define LBF_POOLSTATE_MASK 0xF000
49 #define LBF_POOLSTATE_SHIFT 12
52 #define LBP(lb) ((struct lbuf *)(lb))
54 /* lbuf clone structure
55 * if lbuf->flags LBF_CLONE bit is set, the lbuf can be cast to an lbuf_clone
59 struct lbuf
*orig
; /* original non-clone lbuf providing the buffer space */
63 extern void lb_init(void);
64 #if defined(BCMDBG_MEM) || defined(BCMDBG_MEMFAIL)
65 extern struct lbuf
*lb_alloc(uint size
, const char *file
, int line
);
66 extern struct lbuf
*lb_clone(struct lbuf
*lb
, int offset
, int len
, const char *file
, int line
);
68 extern struct lbuf
*lb_alloc(uint size
);
69 extern struct lbuf
*lb_clone(struct lbuf
*lb
, int offset
, int len
);
70 #endif /* BCMDBG_MEM || BCMDBG_MEMFAIL */
72 extern struct lbuf
*lb_dup(struct lbuf
*lb
);
73 extern void lb_free(struct lbuf
*lb
);
74 extern bool lb_sane(struct lbuf
*lb
);
75 extern void lb_resetpool(struct lbuf
*lb
, uint16 len
);
77 extern void lb_dump(void);
82 /* GNU macro versions avoid the -fno-inline used in ROM builds. */
84 #define lb_push(lb, _len) ({ \
85 uint __len = (_len); \
86 ASSERT(lb_sane(lb)); \
87 ASSERT(((lb)->data - __len) >= (lb)->head); \
88 (lb)->data -= __len; \
93 #define lb_pull(lb, _len) ({ \
94 uint __len = (_len); \
95 ASSERT(lb_sane(lb)); \
96 ASSERT(__len <= (lb)->len); \
97 (lb)->data += __len; \
102 #define lb_setlen(lb, _len) ({ \
103 uint __len = (_len); \
104 ASSERT(lb_sane(lb)); \
105 ASSERT((lb)->data + __len <= (lb)->end); \
106 (lb)->len = (__len); \
109 #define lb_pri(lb) ({ \
110 ASSERT(lb_sane(lb)); \
111 ((lb)->flags & LBF_PRI); \
114 #define lb_setpri(lb, pri) ({ \
116 ASSERT(lb_sane(lb)); \
117 ASSERT((_pri & LBF_PRI) == _pri); \
118 (lb)->flags = ((lb)->flags & ~LBF_PRI) | (_pri & LBF_PRI); \
121 #define lb_sumneeded(lb) ({ \
122 ASSERT(lb_sane(lb)); \
123 (((lb)->flags & LBF_SUM_NEEDED) != 0); \
126 #define lb_setsumneeded(lb, summed) ({ \
127 ASSERT(lb_sane(lb)); \
129 (lb)->flags |= LBF_SUM_NEEDED; \
131 (lb)->flags &= ~LBF_SUM_NEEDED; \
134 #define lb_sumgood(lb) ({ \
135 ASSERT(lb_sane(lb)); \
136 (((lb)->flags & LBF_SUM_GOOD) != 0); \
139 #define lb_setsumgood(lb, summed) ({ \
140 ASSERT(lb_sane(lb)); \
142 (lb)->flags |= LBF_SUM_GOOD; \
144 (lb)->flags &= ~LBF_SUM_GOOD; \
147 #define lb_msgtrace(lb) ({ \
148 ASSERT(lb_sane(lb)); \
149 (((lb)->flags & LBF_MSGTRACE) != 0); \
152 #define lb_setmsgtrace(lb, set) ({ \
153 ASSERT(lb_sane(lb)); \
155 (lb)->flags |= LBF_MSGTRACE; \
157 (lb)->flags &= ~LBF_MSGTRACE; \
160 #define lb_dataoff(lb) ({ \
161 ASSERT(lb_sane(lb)); \
165 #define lb_setdataoff(lb, _dataOff) ({ \
166 ASSERT(lb_sane(lb)); \
167 (lb)->dataOff = _dataOff; \
170 #define lb_isclone(lb) ({ \
171 ASSERT(lb_sane(lb)); \
172 (((lb)->flags & LBF_CLONE) != 0); \
175 #define lb_isptblk(lb) ({ \
176 ASSERT(lb_sane(lb)); \
177 (((lb)->flags & LBF_PTBLK) != 0); \
180 #define lb_setpool(lb, set, _pool) ({ \
181 ASSERT(lb_sane(lb)); \
183 (lb)->flags |= LBF_POOL; \
185 (lb)->flags &= ~LBF_POOL; \
186 (lb)->pool = (_pool); \
189 #define lb_getpool(lb) ({ \
190 ASSERT(lb_sane(lb)); \
194 #define lb_pool(lb) ({ \
195 ASSERT(lb_sane(lb)); \
196 (((lb)->flags & LBF_POOL) != 0); \
199 #define lb_poolstate(lb) ({ \
200 ASSERT(lb_sane(lb)); \
201 (((lb)->flags & LBF_POOLSTATE_MASK) >> LBF_POOLSTATE_SHIFT); \
204 #define lb_setpoolstate(lb, state) ({ \
205 ASSERT(lb_sane(lb)); \
206 (lb)->flags &= ~LBF_POOLSTATE_MASK; \
207 (lb)->flags |= (state) << LBF_POOLSTATE_SHIFT; \
210 #else /* !__GNUC__ */
212 static INLINE uchar
*
213 lb_push(struct lbuf
*lb
, uint len
)
216 ASSERT((lb
->data
- len
) >= lb
->head
);
222 static INLINE uchar
*
223 lb_pull(struct lbuf
*lb
, uint len
)
226 ASSERT(len
<= lb
->len
);
233 lb_setlen(struct lbuf
*lb
, uint len
)
236 ASSERT(lb
->data
+ len
<= lb
->end
);
241 lb_pri(struct lbuf
*lb
)
244 return (lb
->flags
& LBF_PRI
);
248 lb_setpri(struct lbuf
*lb
, uint pri
)
251 ASSERT((pri
& LBF_PRI
) == pri
);
252 lb
->flags
= (lb
->flags
& ~LBF_PRI
) | (pri
& LBF_PRI
);
256 lb_sumneeded(struct lbuf
*lb
)
259 return ((lb
->flags
& LBF_SUM_NEEDED
) != 0);
263 lb_setsumneeded(struct lbuf
*lb
, bool summed
)
267 lb
->flags
|= LBF_SUM_NEEDED
;
269 lb
->flags
&= ~LBF_SUM_NEEDED
;
273 lb_sumgood(struct lbuf
*lb
)
276 return ((lb
->flags
& LBF_SUM_GOOD
) != 0);
280 lb_setsumgood(struct lbuf
*lb
, bool summed
)
284 lb
->flags
|= LBF_SUM_GOOD
;
286 lb
->flags
&= ~LBF_SUM_GOOD
;
290 lb_msgtrace(struct lbuf
*lb
)
293 return ((lb
->flags
& LBF_MSGTRACE
) != 0);
297 lb_setmsgtrace(struct lbuf
*lb
, bool set
)
301 lb
->flags
|= LBF_MSGTRACE
;
303 lb
->flags
&= ~LBF_MSGTRACE
;
306 /* get Data Offset */
308 lb_dataoff(struct lbuf
*lb
)
311 return (lb
->dataOff
);
314 /* set Data Offset */
316 lb_setdataoff(struct lbuf
*lb
, uint8 dataOff
)
319 lb
->dataOff
= dataOff
;
323 lb_isclone(struct lbuf
*lb
)
326 return ((lb
->flags
& LBF_CLONE
) != 0);
330 lb_isptblk(struct lbuf
*lb
)
333 return ((lb
->flags
& LBF_PTBLK
) != 0);
336 /* if set, lb_free() skips de-alloc */
338 lb_setpool(struct lbuf
*lb
, int8 set
, void *pool
)
343 lb
->flags
|= LBF_POOL
;
345 lb
->flags
&= ~LBF_POOL
;
351 lb_getpool(struct lbuf
*lb
)
359 lb_pool(struct lbuf
*lb
)
362 return ((lb
->flags
& LBF_POOL
) != 0);
366 lb_poolstate(struct lbuf
*lb
)
369 return ((lb
->flags
& LBF_POOLSTATE_MASK
) >> LBF_POOLSTATE_SHIFT
);
373 lb_setpoolstate(struct lbuf
*lb
, int8 state
)
376 lb
->flags
&= ~LBF_POOLSTATE_MASK
;
377 lb
->flags
|= state
<< LBF_POOLSTATE_SHIFT
;
380 #endif /* !__GNUC__ */
381 #endif /* !_hndrte_lbuf_h_ */