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