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

Archive Download this file



interactive