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