1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef _BRCMU_UTILS_H_
18#define _BRCMU_UTILS_H_
19
20#include <linux/skbuff.h>
21
22
23
24
25
26
27#define SPINWAIT(exp, us) { \
28 uint countdown = (us) + 9; \
29 while ((exp) && (countdown >= 10)) {\
30 udelay(10); \
31 countdown -= 10; \
32 } \
33}
34
35
36#define PKTQ_LEN_DEFAULT 128
37#define PKTQ_MAX_PREC 16
38
39#define BCME_STRLEN 64
40
41
42#define PKTBUFSZ 2048
43
44#ifndef setbit
45#ifndef NBBY
46#define NBBY 8
47#endif
48#define setbit(a, i) (((u8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
49#define clrbit(a, i) (((u8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
50#define isset(a, i) (((const u8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
51#define isclr(a, i) ((((const u8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
52#endif
53
54#define NBITS(type) (sizeof(type) * 8)
55#define NBITVAL(nbits) (1 << (nbits))
56#define MAXBITVAL(nbits) ((1 << (nbits)) - 1)
57#define NBITMASK(nbits) MAXBITVAL(nbits)
58#define MAXNBVAL(nbyte) MAXBITVAL((nbyte) * 8)
59
60
61#define CRC16_INIT_VALUE 0xffff
62#define CRC16_GOOD_VALUE 0xf0b8
63
64
65#define ETHER_ADDR_STR_LEN 18
66
67struct pktq_prec {
68 struct sk_buff_head skblist;
69 u16 max;
70};
71
72
73struct pktq {
74 u16 num_prec;
75 u16 hi_prec;
76 u16 max;
77 u16 len;
78
79
80
81
82 struct pktq_prec q[PKTQ_MAX_PREC];
83};
84
85
86
87static inline int pktq_plen(struct pktq *pq, int prec)
88{
89 return pq->q[prec].skblist.qlen;
90}
91
92static inline int pktq_pavail(struct pktq *pq, int prec)
93{
94 return pq->q[prec].max - pq->q[prec].skblist.qlen;
95}
96
97static inline bool pktq_pfull(struct pktq *pq, int prec)
98{
99 return pq->q[prec].skblist.qlen >= pq->q[prec].max;
100}
101
102static inline bool pktq_pempty(struct pktq *pq, int prec)
103{
104 return skb_queue_empty(&pq->q[prec].skblist);
105}
106
107static inline struct sk_buff *pktq_ppeek(struct pktq *pq, int prec)
108{
109 return skb_peek(&pq->q[prec].skblist);
110}
111
112static inline struct sk_buff *pktq_ppeek_tail(struct pktq *pq, int prec)
113{
114 return skb_peek_tail(&pq->q[prec].skblist);
115}
116
117extern struct sk_buff *brcmu_pktq_penq(struct pktq *pq, int prec,
118 struct sk_buff *p);
119extern struct sk_buff *brcmu_pktq_penq_head(struct pktq *pq, int prec,
120 struct sk_buff *p);
121extern struct sk_buff *brcmu_pktq_pdeq(struct pktq *pq, int prec);
122extern struct sk_buff *brcmu_pktq_pdeq_tail(struct pktq *pq, int prec);
123
124
125extern struct sk_buff *brcmu_pkt_buf_get_skb(uint len);
126extern void brcmu_pkt_buf_free_skb(struct sk_buff *skb);
127
128
129
130extern void brcmu_pktq_pflush(struct pktq *pq, int prec,
131 bool dir, bool (*fn)(struct sk_buff *, void *), void *arg);
132
133
134
135extern int brcmu_pktq_mlen(struct pktq *pq, uint prec_bmp);
136extern struct sk_buff *brcmu_pktq_mdeq(struct pktq *pq, uint prec_bmp,
137 int *prec_out);
138
139
140
141static inline int pktq_len(struct pktq *pq)
142{
143 return (int)pq->len;
144}
145
146static inline int pktq_max(struct pktq *pq)
147{
148 return (int)pq->max;
149}
150
151static inline int pktq_avail(struct pktq *pq)
152{
153 return (int)(pq->max - pq->len);
154}
155
156static inline bool pktq_full(struct pktq *pq)
157{
158 return pq->len >= pq->max;
159}
160
161static inline bool pktq_empty(struct pktq *pq)
162{
163 return pq->len == 0;
164}
165
166extern void brcmu_pktq_init(struct pktq *pq, int num_prec, int max_len);
167
168extern struct sk_buff *brcmu_pktq_peek_tail(struct pktq *pq, int *prec_out);
169extern void brcmu_pktq_flush(struct pktq *pq, bool dir,
170 bool (*fn)(struct sk_buff *, void *), void *arg);
171
172
173
174struct ipv4_addr;
175
176
177
178
179#ifdef BCMDBG
180extern void brcmu_prpkt(const char *msg, struct sk_buff *p0);
181#else
182#define brcmu_prpkt(a, b)
183#endif
184
185#endif
186