1/*
2 * HND RTE packet buffer definitions.
3 *
4 * Copyright (C) 2014, Broadcom Corporation
5 * All Rights Reserved.
6 *
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.
11 *
12 * $Id: bcm_linux_lbuf.h,v 1.4 2009-04-13 16:03:35 $
13 */
14
15#ifndef _bcm_linux_lbuf_h
16#define	_bcm_linux_lbuf_h
17
18#include <bcmdefs.h>
19
20#define OSL_PKTTAG_SZ 32
21
22
23
24struct lbuf {
25	struct lbuf	*next;		/* next lbuf in a chain of lbufs forming one packet */
26	struct lbuf	*link;		/* first lbuf of next packet in a list of packets */
27	uchar		*head;		/* fixed start of buffer */
28	uchar		*end;		/* fixed end of buffer */
29	uchar		*data;		/* variable start of data */
30	uint16		len;		/* nbytes of data */
31	uint16		flags;		/* private flags; don't touch */
32	uint16		dmapad;		/* padding to be added for tx dma */
33	uint32		pkttag[(OSL_PKTTAG_SZ + 3) / 4];  /* 4-byte-aligned packet tag area */
34};
35
36#define	LBUFSZ		sizeof(struct lbuf)
37
38/* Total maximum packet buffer size including lbuf header */
39#define MAXPKTBUFSZ	1920		/* enough to fit a 1500 MTU plus overhead */
40
41/* private flags - don't reference directly */
42#define	LBF_PRI		0x0007		/* priority (low 3 bits of flags) */
43#define LBF_SUM_NEEDED	0x0008
44#define LBF_SUM_GOOD	0x0010
45
46#define LBF_MSGTRACE	0x0020
47#define	LBP(lb)		((struct lbuf *)(lb))
48
49/* prototypes */
50extern void lb_init(void);
51#if defined(BCMDBG_MEMFAIL)
52extern struct lbuf *lb_alloc(uint size, char *file, int line);
53#else
54extern struct lbuf *lb_alloc(uint size);
55#endif
56
57extern struct lbuf *lb_dup(struct lbuf *lb);
58extern void lb_free(struct lbuf *lb);
59extern bool lb_sane(struct lbuf *lb);
60
61static INLINE uchar *
62lb_push(struct lbuf *lb, uint len)
63{
64	ASSERT(lb_sane(lb));
65	ASSERT((lb->data - len) >= lb->head);
66	lb->data -= len;
67	lb->len += len;
68	return (lb->data);
69}
70
71static INLINE uchar *
72lb_pull(struct lbuf *lb, uint len)
73{
74	ASSERT(lb_sane(lb));
75	ASSERT(len <= lb->len);
76	lb->data += len;
77	lb->len -= len;
78	return (lb->data);
79}
80
81static INLINE void
82lb_setlen(struct lbuf *lb, uint len)
83{
84	ASSERT(lb_sane(lb));
85	ASSERT(lb->data + len <= lb->end);
86	lb->len = len;
87}
88
89static INLINE uint
90lb_pri(struct lbuf *lb)
91{
92	ASSERT(lb_sane(lb));
93	return (lb->flags & LBF_PRI);
94}
95
96static INLINE void
97lb_setpri(struct lbuf *lb, uint pri)
98{
99	ASSERT(lb_sane(lb));
100	ASSERT((pri & LBF_PRI) == pri);
101	lb->flags = (lb->flags & ~LBF_PRI) | (pri & LBF_PRI);
102}
103
104static INLINE bool
105lb_sumneeded(struct lbuf *lb)
106{
107	ASSERT(lb_sane(lb));
108	return ((lb->flags & LBF_SUM_NEEDED) != 0);
109}
110
111static INLINE void
112lb_setsumneeded(struct lbuf *lb, bool summed)
113{
114	ASSERT(lb_sane(lb));
115	if (summed)
116		lb->flags |= LBF_SUM_NEEDED;
117	else
118		lb->flags &= ~LBF_SUM_NEEDED;
119}
120
121static INLINE bool
122lb_sumgood(struct lbuf *lb)
123{
124	ASSERT(lb_sane(lb));
125	return ((lb->flags & LBF_SUM_GOOD) != 0);
126}
127
128static INLINE void
129lb_setsumgood(struct lbuf *lb, bool summed)
130{
131	ASSERT(lb_sane(lb));
132	if (summed)
133		lb->flags |= LBF_SUM_GOOD;
134	else
135		lb->flags &= ~LBF_SUM_GOOD;
136}
137
138static INLINE bool
139lb_msgtrace(struct lbuf *lb)
140{
141	ASSERT(lb_sane(lb));
142	return ((lb->flags & LBF_MSGTRACE) != 0);
143}
144
145static INLINE void
146lb_setmsgtrace(struct lbuf *lb, bool set)
147{
148	ASSERT(lb_sane(lb));
149	if (set)
150		lb->flags |= LBF_MSGTRACE;
151	else
152		lb->flags &= ~LBF_MSGTRACE;
153}
154
155#endif	/* _bcm_linux_lbuf_h */
156