[kernel] 2.6.31: update generic config
[openwrt.git] / package / broadcom-wl / src / driver / bcmutils.h
1 /*
2 * Misc useful os-independent macros and functions.
3 *
4 * Copyright 2007, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
11 */
12
13 #ifndef _bcmutils_h_
14 #define _bcmutils_h_
15 #include "linux_osl.h"
16
17 /* ctype replacement */
18 #define _BCM_U 0x01 /* upper */
19 #define _BCM_L 0x02 /* lower */
20 #define _BCM_D 0x04 /* digit */
21 #define _BCM_C 0x08 /* cntrl */
22 #define _BCM_P 0x10 /* punct */
23 #define _BCM_S 0x20 /* white space (space/lf/tab) */
24 #define _BCM_X 0x40 /* hex digit */
25 #define _BCM_SP 0x80 /* hard space (0x20) */
26
27 extern const unsigned char bcm_ctype[];
28 #define bcm_ismask(x) (bcm_ctype[(int)(unsigned char)(x)])
29
30 #define bcm_isalnum(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L|_BCM_D)) != 0)
31 #define bcm_isalpha(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L)) != 0)
32 #define bcm_iscntrl(c) ((bcm_ismask(c)&(_BCM_C)) != 0)
33 #define bcm_isdigit(c) ((bcm_ismask(c)&(_BCM_D)) != 0)
34 #define bcm_isgraph(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D)) != 0)
35 #define bcm_islower(c) ((bcm_ismask(c)&(_BCM_L)) != 0)
36 #define bcm_isprint(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D|_BCM_SP)) != 0)
37 #define bcm_ispunct(c) ((bcm_ismask(c)&(_BCM_P)) != 0)
38 #define bcm_isspace(c) ((bcm_ismask(c)&(_BCM_S)) != 0)
39 #define bcm_isupper(c) ((bcm_ismask(c)&(_BCM_U)) != 0)
40 #define bcm_isxdigit(c) ((bcm_ismask(c)&(_BCM_D|_BCM_X)) != 0)
41 #define bcm_tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
42 #define bcm_toupper(c) (bcm_islower((c)) ? ((c) + 'A' - 'a') : (c))
43
44 /* Buffer structure for collecting string-formatted data
45 * using bcm_bprintf() API.
46 * Use bcm_binit() to initialize before use
47 */
48
49 struct bcmstrbuf {
50 char *buf; /* pointer to current position in origbuf */
51 unsigned int size; /* current (residual) size in bytes */
52 char *origbuf; /* unmodified pointer to orignal buffer */
53 unsigned int origsize; /* unmodified orignal buffer size in bytes */
54 };
55
56 /* ** driver-only section ** */
57 #include <osl.h>
58
59 #define GPIO_PIN_NOTDEFINED 0x20 /* Pin not defined */
60
61
62 /* osl multi-precedence packet queue */
63 #ifndef PKTQ_LEN_DEFAULT
64 #define PKTQ_LEN_DEFAULT 128 /* Max 128 packets */
65 #endif
66 #ifndef PKTQ_MAX_PREC
67 #define PKTQ_MAX_PREC 16 /* Maximum precedence levels */
68 #endif
69
70 typedef struct pktq_prec {
71 void *head; /* first packet to dequeue */
72 void *tail; /* last packet to dequeue */
73 uint16 len; /* number of queued packets */
74 uint16 max; /* maximum number of queued packets */
75 } pktq_prec_t;
76
77
78 /* multi-priority pkt queue */
79 struct pktq {
80 uint16 num_prec; /* number of precedences in use */
81 uint16 hi_prec; /* rapid dequeue hint (>= highest non-empty prec) */
82 uint16 max; /* total max packets */
83 uint16 len; /* total number of packets */
84 /* q array must be last since # of elements can be either PKTQ_MAX_PREC or 1 */
85 struct pktq_prec q[PKTQ_MAX_PREC];
86 };
87
88 /* simple, non-priority pkt queue */
89 struct spktq {
90 uint16 num_prec; /* number of precedences in use (always 1) */
91 uint16 hi_prec; /* rapid dequeue hint (>= highest non-empty prec) */
92 uint16 max; /* total max packets */
93 uint16 len; /* total number of packets */
94 /* q array must be last since # of elements can be either PKTQ_MAX_PREC or 1 */
95 struct pktq_prec q[1];
96 };
97
98 #define PKTQ_PREC_ITER(pq, prec) for (prec = (pq)->num_prec - 1; prec >= 0; prec--)
99
100 /* forward definition of ether_addr structure used by some function prototypes */
101 struct ether_addr;
102
103 /* operations on a specific precedence in packet queue */
104
105 #define pktq_psetmax(pq, prec, _max) ((pq)->q[prec].max = (_max))
106 #define pktq_plen(pq, prec) ((pq)->q[prec].len)
107 #define pktq_pavail(pq, prec) ((pq)->q[prec].max - (pq)->q[prec].len)
108 #define pktq_pfull(pq, prec) ((pq)->q[prec].len >= (pq)->q[prec].max)
109 #define pktq_pempty(pq, prec) ((pq)->q[prec].len == 0)
110
111 #define pktq_ppeek(pq, prec) ((pq)->q[prec].head)
112 #define pktq_ppeek_tail(pq, prec) ((pq)->q[prec].tail)
113
114 extern void *pktq_penq(struct pktq *pq, int prec, void *p);
115 extern void *pktq_penq_head(struct pktq *pq, int prec, void *p);
116 extern void *pktq_pdeq(struct pktq *pq, int prec);
117 extern void *pktq_pdeq_tail(struct pktq *pq, int prec);
118 /* Empty the queue at particular precedence level */
119 extern void pktq_pflush(osl_t *osh, struct pktq *pq, int prec, bool dir);
120 /* Remove a specified packet from its queue */
121 extern bool pktq_pdel(struct pktq *pq, void *p, int prec);
122
123 /* operations on a set of precedences in packet queue */
124
125 extern int pktq_mlen(struct pktq *pq, uint prec_bmp);
126 extern void *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out);
127
128 /* operations on packet queue as a whole */
129
130 #define pktq_len(pq) ((int)(pq)->len)
131 #define pktq_max(pq) ((int)(pq)->max)
132 #define pktq_avail(pq) ((int)((pq)->max - (pq)->len))
133 #define pktq_full(pq) ((pq)->len >= (pq)->max)
134 #define pktq_empty(pq) ((pq)->len == 0)
135
136 /* operations for single precedence queues */
137 #define pktenq(pq, p) pktq_penq(((struct pktq *)pq), 0, (p))
138 #define pktenq_head(pq, p) pktq_penq_head(((struct pktq *)pq), 0, (p))
139 #define pktdeq(pq) pktq_pdeq(((struct pktq *)pq), 0)
140 #define pktdeq_tail(pq) pktq_pdeq_tail(((struct pktq *)pq), 0)
141 #define pktqinit(pq, len) pktq_init(((struct pktq *)pq), 1, len)
142
143 extern void pktq_init(struct pktq *pq, int num_prec, int max_len);
144 /* prec_out may be NULL if caller is not interested in return value */
145 extern void *pktq_deq(struct pktq *pq, int *prec_out);
146 extern void *pktq_deq_tail(struct pktq *pq, int *prec_out);
147 extern void *pktq_peek(struct pktq *pq, int *prec_out);
148 extern void *pktq_peek_tail(struct pktq *pq, int *prec_out);
149 extern void pktq_flush(osl_t *osh, struct pktq *pq, bool dir); /* Empty the entire queue */
150 extern int pktq_setmax(struct pktq *pq, int max_len);
151
152 /* externs */
153 /* packet */
154 extern uint pktcopy(osl_t *osh, void *p, uint offset, int len, uchar *buf);
155 extern uint pkttotlen(osl_t *osh, void *p);
156 extern void *pktlast(osl_t *osh, void *p);
157
158 /* Get priority from a packet and pass it back in scb (or equiv) */
159 extern uint pktsetprio(void *pkt, bool update_vtag);
160 #define PKTPRIO_VDSCP 0x100 /* DSCP prio found after VLAN tag */
161 #define PKTPRIO_VLAN 0x200 /* VLAN prio found */
162 #define PKTPRIO_UPD 0x400 /* DSCP used to update VLAN prio */
163 #define PKTPRIO_DSCP 0x800 /* DSCP prio found */
164
165 /* string */
166 extern int BCMROMFN(bcm_atoi)(char *s);
167 extern ulong BCMROMFN(bcm_strtoul)(char *cp, char **endp, uint base);
168 extern char *BCMROMFN(bcmstrstr)(char *haystack, char *needle);
169 extern char *BCMROMFN(bcmstrcat)(char *dest, const char *src);
170 extern char *BCMROMFN(bcmstrncat)(char *dest, const char *src, uint size);
171 extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen);
172 /* ethernet address */
173 extern char *bcm_ether_ntoa(struct ether_addr *ea, char *buf);
174 extern int BCMROMFN(bcm_ether_atoe)(char *p, struct ether_addr *ea);
175
176 /* ip address */
177 struct ipv4_addr;
178 extern char *bcm_ip_ntoa(struct ipv4_addr *ia, char *buf);
179
180 /* delay */
181 extern void bcm_mdelay(uint ms);
182 /* variable access */
183 extern char *getvar(char *vars, const char *name);
184 extern int getintvar(char *vars, const char *name);
185 extern uint getgpiopin(char *vars, char *pin_name, uint def_pin);
186 #ifdef BCMDBG
187 extern void prpkt(const char *msg, osl_t *osh, void *p0);
188 #endif /* BCMDBG */
189 #ifdef BCMPERFSTATS
190 extern void bcm_perf_enable(void);
191 extern void bcmstats(char *fmt);
192 extern void bcmlog(char *fmt, uint a1, uint a2);
193 extern void bcmdumplog(char *buf, int size);
194 extern int bcmdumplogent(char *buf, uint idx);
195 #else
196 #define bcm_perf_enable()
197 #define bcmstats(fmt)
198 #define bcmlog(fmt, a1, a2)
199 #define bcmdumplog(buf, size) *buf = '\0'
200 #define bcmdumplogent(buf, idx) -1
201 #endif /* BCMPERFSTATS */
202 extern char *bcm_nvram_vars(uint *length);
203 extern int bcm_nvram_cache(void *sbh);
204
205 /* Support for sharing code across in-driver iovar implementations.
206 * The intent is that a driver use this structure to map iovar names
207 * to its (private) iovar identifiers, and the lookup function to
208 * find the entry. Macros are provided to map ids and get/set actions
209 * into a single number space for a switch statement.
210 */
211
212 /* iovar structure */
213 typedef struct bcm_iovar {
214 const char *name; /* name for lookup and display */
215 uint16 varid; /* id for switch */
216 uint16 flags; /* driver-specific flag bits */
217 uint16 type; /* base type of argument */
218 uint16 minlen; /* min length for buffer vars */
219 } bcm_iovar_t;
220
221 /* varid definitions are per-driver, may use these get/set bits */
222
223 /* IOVar action bits for id mapping */
224 #define IOV_GET 0 /* Get an iovar */
225 #define IOV_SET 1 /* Set an iovar */
226
227 /* Varid to actionid mapping */
228 #define IOV_GVAL(id) ((id)*2)
229 #define IOV_SVAL(id) (((id)*2)+IOV_SET)
230 #define IOV_ISSET(actionid) ((actionid & IOV_SET) == IOV_SET)
231
232 /* flags are per-driver based on driver attributes */
233
234 extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name);
235 extern int bcm_iovar_lencheck(const bcm_iovar_t *table, void *arg, int len, bool set);
236
237 /* Base type definitions */
238 #define IOVT_VOID 0 /* no value (implictly set only) */
239 #define IOVT_BOOL 1 /* any value ok (zero/nonzero) */
240 #define IOVT_INT8 2 /* integer values are range-checked */
241 #define IOVT_UINT8 3 /* unsigned int 8 bits */
242 #define IOVT_INT16 4 /* int 16 bits */
243 #define IOVT_UINT16 5 /* unsigned int 16 bits */
244 #define IOVT_INT32 6 /* int 32 bits */
245 #define IOVT_UINT32 7 /* unsigned int 32 bits */
246 #define IOVT_BUFFER 8 /* buffer is size-checked as per minlen */
247 #define BCM_IOVT_VALID(type) (((unsigned int)(type)) <= IOVT_BUFFER)
248
249 /* Initializer for IOV type strings */
250 #define BCM_IOV_TYPE_INIT { \
251 "void", \
252 "bool", \
253 "int8", \
254 "uint8", \
255 "int16", \
256 "uint16", \
257 "int32", \
258 "uint32", \
259 "buffer", \
260 "" }
261
262 #define BCM_IOVT_IS_INT(type) (\
263 (type == IOVT_BOOL) || \
264 (type == IOVT_INT8) || \
265 (type == IOVT_UINT8) || \
266 (type == IOVT_INT16) || \
267 (type == IOVT_UINT16) || \
268 (type == IOVT_INT32) || \
269 (type == IOVT_UINT32))
270
271 /* ** driver/apps-shared section ** */
272
273 #define BCME_STRLEN 64 /* Max string length for BCM errors */
274 #define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST))
275
276
277 /*
278 * error codes could be added but the defined ones shouldn't be changed/deleted
279 * these error codes are exposed to the user code
280 * when ever a new error code is added to this list
281 * please update errorstring table with the related error string and
282 * update osl files with os specific errorcode map
283 */
284
285 #define BCME_OK 0 /* Success */
286 #define BCME_ERROR -1 /* Error generic */
287 #define BCME_BADARG -2 /* Bad Argument */
288 #define BCME_BADOPTION -3 /* Bad option */
289 #define BCME_NOTUP -4 /* Not up */
290 #define BCME_NOTDOWN -5 /* Not down */
291 #define BCME_NOTAP -6 /* Not AP */
292 #define BCME_NOTSTA -7 /* Not STA */
293 #define BCME_BADKEYIDX -8 /* BAD Key Index */
294 #define BCME_RADIOOFF -9 /* Radio Off */
295 #define BCME_NOTBANDLOCKED -10 /* Not band locked */
296 #define BCME_NOCLK -11 /* No Clock */
297 #define BCME_BADRATESET -12 /* BAD Rate valueset */
298 #define BCME_BADBAND -13 /* BAD Band */
299 #define BCME_BUFTOOSHORT -14 /* Buffer too short */
300 #define BCME_BUFTOOLONG -15 /* Buffer too long */
301 #define BCME_BUSY -16 /* Busy */
302 #define BCME_NOTASSOCIATED -17 /* Not Associated */
303 #define BCME_BADSSIDLEN -18 /* Bad SSID len */
304 #define BCME_OUTOFRANGECHAN -19 /* Out of Range Channel */
305 #define BCME_BADCHAN -20 /* Bad Channel */
306 #define BCME_BADADDR -21 /* Bad Address */
307 #define BCME_NORESOURCE -22 /* Not Enough Resources */
308 #define BCME_UNSUPPORTED -23 /* Unsupported */
309 #define BCME_BADLEN -24 /* Bad length */
310 #define BCME_NOTREADY -25 /* Not Ready */
311 #define BCME_EPERM -26 /* Not Permitted */
312 #define BCME_NOMEM -27 /* No Memory */
313 #define BCME_ASSOCIATED -28 /* Associated */
314 #define BCME_RANGE -29 /* Not In Range */
315 #define BCME_NOTFOUND -30 /* Not Found */
316 #define BCME_WME_NOT_ENABLED -31 /* WME Not Enabled */
317 #define BCME_TSPEC_NOTFOUND -32 /* TSPEC Not Found */
318 #define BCME_ACM_NOTSUPPORTED -33 /* ACM Not Supported */
319 #define BCME_NOT_WME_ASSOCIATION -34 /* Not WME Association */
320 #define BCME_SDIO_ERROR -35 /* SDIO Bus Error */
321 #define BCME_DONGLE_DOWN -36 /* Dongle Not Accessible */
322 #define BCME_VERSION -37 /* Incorrect version */
323 #define BCME_LAST BCME_VERSION
324
325 /* These are collection of BCME Error strings */
326 #define BCMERRSTRINGTABLE { \
327 "OK", \
328 "Undefined error", \
329 "Bad Argument", \
330 "Bad Option", \
331 "Not up", \
332 "Not down", \
333 "Not AP", \
334 "Not STA", \
335 "Bad Key Index", \
336 "Radio Off", \
337 "Not band locked", \
338 "No clock", \
339 "Bad Rate valueset", \
340 "Bad Band", \
341 "Buffer too short", \
342 "Buffer too long", \
343 "Busy", \
344 "Not Associated", \
345 "Bad SSID len", \
346 "Out of Range Channel", \
347 "Bad Channel", \
348 "Bad Address", \
349 "Not Enough Resources", \
350 "Unsupported", \
351 "Bad length", \
352 "Not Ready", \
353 "Not Permitted", \
354 "No Memory", \
355 "Associated", \
356 "Not In Range", \
357 "Not Found", \
358 "WME Not Enabled", \
359 "TSPEC Not Found", \
360 "ACM Not Supported", \
361 "Not WME Association", \
362 "SDIO Bus Error", \
363 "Dongle Not Accessible", \
364 "Incorrect version" \
365 }
366
367 #ifndef ABS
368 #define ABS(a) (((a) < 0)?-(a):(a))
369 #endif /* ABS */
370
371 #ifndef MIN
372 #define MIN(a, b) (((a) < (b))?(a):(b))
373 #endif /* MIN */
374
375 #ifndef MAX
376 #define MAX(a, b) (((a) > (b))?(a):(b))
377 #endif /* MAX */
378
379 #define CEIL(x, y) (((x) + ((y)-1)) / (y))
380 #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
381 #define ISALIGNED(a, x) (((a) & ((x)-1)) == 0)
382 #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0)
383 #define VALID_MASK(mask) !((mask) & ((mask) + 1))
384 #ifndef OFFSETOF
385 #define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member)
386 #endif /* OFFSETOF */
387 #ifndef ARRAYSIZE
388 #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
389 #endif
390
391 /* bit map related macros */
392 #ifndef setbit
393 #ifndef NBBY /* the BSD family defines NBBY */
394 #define NBBY 8 /* 8 bits per byte */
395 #endif /* #ifndef NBBY */
396 #define setbit(a, i) (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
397 #define clrbit(a, i) (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
398 #define isset(a, i) (((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
399 #define isclr(a, i) ((((const uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
400 #endif /* setbit */
401
402 #define NBITS(type) (sizeof(type) * 8)
403 #define NBITVAL(nbits) (1 << (nbits))
404 #define MAXBITVAL(nbits) ((1 << (nbits)) - 1)
405 #define NBITMASK(nbits) MAXBITVAL(nbits)
406 #define MAXNBVAL(nbyte) MAXBITVAL((nbyte) * 8)
407
408 /* basic mux operation - can be optimized on several architectures */
409 #define MUX(pred, true, false) ((pred) ? (true) : (false))
410
411 /* modulo inc/dec - assumes x E [0, bound - 1] */
412 #define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1)
413 #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
414
415 /* modulo inc/dec, bound = 2^k */
416 #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
417 #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
418
419 /* modulo add/sub - assumes x, y E [0, bound - 1] */
420 #define MODADD(x, y, bound) \
421 MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y))
422 #define MODSUB(x, y, bound) \
423 MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y))
424
425 /* module add/sub, bound = 2^k */
426 #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
427 #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
428
429 /* crc defines */
430 #define CRC8_INIT_VALUE 0xff /* Initial CRC8 checksum value */
431 #define CRC8_GOOD_VALUE 0x9f /* Good final CRC8 checksum value */
432 #define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
433 #define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
434 #define CRC32_INIT_VALUE 0xffffffff /* Initial CRC32 checksum value */
435 #define CRC32_GOOD_VALUE 0xdebb20e3 /* Good final CRC32 checksum value */
436
437 /* bcm_format_flags() bit description structure */
438 typedef struct bcm_bit_desc {
439 uint32 bit;
440 const char* name;
441 } bcm_bit_desc_t;
442
443 /* tag_ID/length/value_buffer tuple */
444 typedef struct bcm_tlv {
445 uint8 id;
446 uint8 len;
447 uint8 data[1];
448 } bcm_tlv_t;
449
450 /* Check that bcm_tlv_t fits into the given buflen */
451 #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
452
453 /* buffer length for ethernet address from bcm_ether_ntoa() */
454 #define ETHER_ADDR_STR_LEN 18 /* 18-bytes of Ethernet address buffer length */
455
456 /* unaligned load and store macros */
457 #ifdef IL_BIGENDIAN
458 static INLINE uint32
459 load32_ua(uint8 *a)
460 {
461 return ((a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3]);
462 }
463
464 static INLINE void
465 store32_ua(uint8 *a, uint32 v)
466 {
467 a[0] = (v >> 24) & 0xff;
468 a[1] = (v >> 16) & 0xff;
469 a[2] = (v >> 8) & 0xff;
470 a[3] = v & 0xff;
471 }
472
473 static INLINE uint16
474 load16_ua(uint8 *a)
475 {
476 return ((a[0] << 8) | a[1]);
477 }
478
479 static INLINE void
480 store16_ua(uint8 *a, uint16 v)
481 {
482 a[0] = (v >> 8) & 0xff;
483 a[1] = v & 0xff;
484 }
485
486 #else /* IL_BIGENDIAN */
487
488 static INLINE uint32
489 load32_ua(uint8 *a)
490 {
491 return ((a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0]);
492 }
493
494 static INLINE void
495 store32_ua(uint8 *a, uint32 v)
496 {
497 a[3] = (v >> 24) & 0xff;
498 a[2] = (v >> 16) & 0xff;
499 a[1] = (v >> 8) & 0xff;
500 a[0] = v & 0xff;
501 }
502
503 static INLINE uint16
504 load16_ua(uint8 *a)
505 {
506 return ((a[1] << 8) | a[0]);
507 }
508
509 static INLINE void
510 store16_ua(uint8 *a, uint16 v)
511 {
512 a[1] = (v >> 8) & 0xff;
513 a[0] = v & 0xff;
514 }
515
516 #endif /* IL_BIGENDIAN */
517
518 /* externs */
519 /* crc */
520 extern uint8 BCMROMFN(hndcrc8)(uint8 *p, uint nbytes, uint8 crc);
521 extern uint16 BCMROMFN(hndcrc16)(uint8 *p, uint nbytes, uint16 crc);
522 extern uint32 BCMROMFN(hndcrc32)(uint8 *p, uint nbytes, uint32 crc);
523 /* format/print */
524 #ifdef BCMDBG
525 extern int bcm_format_flags(const bcm_bit_desc_t *bd, uint32 flags, char* buf, int len);
526 extern int bcm_format_hex(char *str, const void *bytes, int len);
527 extern void deadbeef(void *p, uint len);
528 extern void prhex(const char *msg, uchar *buf, uint len);
529 #endif /* BCMDBG */
530 extern char *bcm_brev_str(uint16 brev, char *buf);
531 extern void printfbig(char *buf);
532
533 /* IE parsing */
534 extern bcm_tlv_t *BCMROMFN(bcm_next_tlv)(bcm_tlv_t *elt, int *buflen);
535 extern bcm_tlv_t *BCMROMFN(bcm_parse_tlvs)(void *buf, int buflen, uint key);
536 extern bcm_tlv_t *BCMROMFN(bcm_parse_ordered_tlvs)(void *buf, int buflen, uint key);
537
538 /* bcmerror */
539 extern const char *bcmerrorstr(int bcmerror);
540
541 /* multi-bool data type: set of bools, mbool is true if any is set */
542 typedef uint32 mbool;
543 #define mboolset(mb, bit) ((mb) |= (bit)) /* set one bool */
544 #define mboolclr(mb, bit) ((mb) &= ~(bit)) /* clear one bool */
545 #define mboolisset(mb, bit) (((mb) & (bit)) != 0) /* TRUE if one bool is set */
546 #define mboolmaskset(mb, mask, val) ((mb) = (((mb) & ~(mask)) | (val)))
547
548 /* power conversion */
549 extern uint16 BCMROMFN(bcm_qdbm_to_mw)(uint8 qdbm);
550 extern uint8 BCMROMFN(bcm_mw_to_qdbm)(uint16 mw);
551
552 /* generic datastruct to help dump routines */
553 struct fielddesc {
554 const char *nameandfmt;
555 uint32 offset;
556 uint32 len;
557 };
558
559 extern void bcm_binit(struct bcmstrbuf *b, char *buf, uint size);
560 extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...);
561
562 typedef uint32 (*readreg_rtn)(void *arg0, void *arg1, uint32 offset);
563 extern uint bcmdumpfields(readreg_rtn func_ptr, void *arg0, void *arg1, struct fielddesc *str,
564 char *buf, uint32 bufsize);
565
566 extern uint bcm_mkiovar(char *name, char *data, uint datalen, char *buf, uint len);
567 extern uint BCMROMFN(bcm_bitcount)(uint8 *bitmap, uint bytelength);
568
569 #ifdef BCMDBG_PKT /* pkt logging for debugging */
570 #define PKTLIST_SIZE 1000
571 typedef struct {
572 void *list[PKTLIST_SIZE]; /* List of pointers to packets */
573 uint count; /* Total count of the packets */
574 } pktlist_info_t;
575
576 extern void pktlist_add(pktlist_info_t *pktlist, void *p);
577 extern void pktlist_remove(pktlist_info_t *pktlist, void *p);
578 extern char* pktlist_dump(pktlist_info_t *pktlist, char *buf);
579 #endif /* BCMDBG_PKT */
580
581 #endif /* _bcmutils_h_ */
This page took 0.102237 seconds and 5 git commands to generate.