WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / wireless / broadcom / brcm80211 / include / brcmu_utils.h
blob9465323286673c6c1f8046bcab9e65833ae507c8
1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2010 Broadcom Corporation
4 */
6 #ifndef _BRCMU_UTILS_H_
7 #define _BRCMU_UTILS_H_
9 #include <linux/skbuff.h>
12 * Spin at most 'us' microseconds while 'exp' is true.
13 * Caller should explicitly test 'exp' when this completes
14 * and take appropriate error action if 'exp' is still true.
16 #define SPINWAIT(exp, us) { \
17 uint countdown = (us) + 9; \
18 while ((exp) && (countdown >= 10)) {\
19 udelay(10); \
20 countdown -= 10; \
21 } \
24 /* osl multi-precedence packet queue */
25 #define PKTQ_LEN_DEFAULT 128 /* Max 128 packets */
26 #define PKTQ_MAX_PREC 16 /* Maximum precedence levels */
28 #define BCME_STRLEN 64 /* Max string length for BCM errors */
30 /* the largest reasonable packet buffer driver uses for ethernet MTU in bytes */
31 #define PKTBUFSZ 2048
33 #ifndef setbit
34 #ifndef NBBY /* the BSD family defines NBBY */
35 #define NBBY 8 /* 8 bits per byte */
36 #endif /* #ifndef NBBY */
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 /* setbit */
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)
49 /* crc defines */
50 #define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
51 #define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
53 /* 18-bytes of Ethernet address buffer length */
54 #define ETHER_ADDR_STR_LEN 18
56 struct pktq_prec {
57 struct sk_buff_head skblist;
58 u16 max; /* maximum number of queued packets */
61 /* multi-priority pkt queue */
62 struct pktq {
63 u16 num_prec; /* number of precedences in use */
64 u16 hi_prec; /* rapid dequeue hint (>= highest non-empty prec) */
65 u16 max; /* total max packets */
66 u16 len; /* total number of packets */
68 * q array must be last since # of elements can be either
69 * PKTQ_MAX_PREC or 1
71 struct pktq_prec q[PKTQ_MAX_PREC];
74 /* operations on a specific precedence in packet queue */
76 static inline int pktq_plen(struct pktq *pq, int prec)
78 return pq->q[prec].skblist.qlen;
81 static inline int pktq_pavail(struct pktq *pq, int prec)
83 return pq->q[prec].max - pq->q[prec].skblist.qlen;
86 static inline bool pktq_pfull(struct pktq *pq, int prec)
88 return pq->q[prec].skblist.qlen >= pq->q[prec].max;
91 static inline bool pktq_pempty(struct pktq *pq, int prec)
93 return skb_queue_empty(&pq->q[prec].skblist);
96 static inline struct sk_buff *pktq_ppeek(struct pktq *pq, int prec)
98 return skb_peek(&pq->q[prec].skblist);
101 static inline struct sk_buff *pktq_ppeek_tail(struct pktq *pq, int prec)
103 return skb_peek_tail(&pq->q[prec].skblist);
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);
116 /* packet primitives */
117 struct sk_buff *brcmu_pkt_buf_get_skb(uint len);
118 void brcmu_pkt_buf_free_skb(struct sk_buff *skb);
120 /* Empty the queue at particular precedence level */
121 /* callback function fn(pkt, arg) returns true if pkt belongs to if */
122 void brcmu_pktq_pflush(struct pktq *pq, int prec, bool dir,
123 bool (*fn)(struct sk_buff *, void *), void *arg);
125 /* operations on a set of precedences in packet queue */
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);
130 /* operations on packet queue as a whole */
132 static inline int pktq_len(struct pktq *pq)
134 return (int)pq->len;
137 static inline int pktq_max(struct pktq *pq)
139 return (int)pq->max;
142 static inline int pktq_avail(struct pktq *pq)
144 return (int)(pq->max - pq->len);
147 static inline bool pktq_full(struct pktq *pq)
149 return pq->len >= pq->max;
152 static inline bool pktq_empty(struct pktq *pq)
154 return pq->len == 0;
157 void brcmu_pktq_init(struct pktq *pq, int num_prec, int max_len);
158 /* prec_out may be NULL if caller is not interested in return value */
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);
163 /* externs */
164 /* ip address */
165 struct ipv4_addr;
168 * bitfield macros using masking and shift
170 * remark: the mask parameter should be a shifted mask.
172 static inline void brcmu_maskset32(u32 *var, u32 mask, u8 shift, u32 value)
174 value = (value << shift) & mask;
175 *var = (*var & ~mask) | value;
177 static inline u32 brcmu_maskget32(u32 var, u32 mask, u8 shift)
179 return (var & mask) >> shift;
181 static inline void brcmu_maskset16(u16 *var, u16 mask, u8 shift, u16 value)
183 value = (value << shift) & mask;
184 *var = (*var & ~mask) | value;
186 static inline u16 brcmu_maskget16(u16 var, u16 mask, u8 shift)
188 return (var & mask) >> shift;
191 /* externs */
192 /* format/print */
193 #ifdef DEBUG
194 void brcmu_prpkt(const char *msg, struct sk_buff *p0);
195 #else
196 #define brcmu_prpkt(a, b)
197 #endif /* DEBUG */
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, ...)
208 #endif
210 #define BRCMU_BOARDREV_LEN 8
211 #define BRCMU_DOTREV_LEN 16
213 char *brcmu_boardrev_str(u32 brev, char *buf);
214 char *brcmu_dotrev_str(u32 dotrev, char *buf);
216 #endif /* _BRCMU_UTILS_H_ */