2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 /* ctype replacement */
26 #define _BCM_U 0x01 /* upper */
27 #define _BCM_L 0x02 /* lower */
28 #define _BCM_D 0x04 /* digit */
29 #define _BCM_C 0x08 /* cntrl */
30 #define _BCM_P 0x10 /* punct */
31 #define _BCM_S 0x20 /* white space (space/lf/tab) */
32 #define _BCM_X 0x40 /* hex digit */
33 #define _BCM_SP 0x80 /* hard space (0x20) */
35 extern const unsigned char bcm_ctype
[];
36 #define bcm_ismask(x) (bcm_ctype[(int)(unsigned char)(x)])
38 #define bcm_isalnum(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L|_BCM_D)) != 0)
39 #define bcm_isalpha(c) ((bcm_ismask(c)&(_BCM_U|_BCM_L)) != 0)
40 #define bcm_iscntrl(c) ((bcm_ismask(c)&(_BCM_C)) != 0)
41 #define bcm_isdigit(c) ((bcm_ismask(c)&(_BCM_D)) != 0)
42 #define bcm_isgraph(c) ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D)) != 0)
43 #define bcm_islower(c) ((bcm_ismask(c)&(_BCM_L)) != 0)
44 #define bcm_isprint(c) \
45 ((bcm_ismask(c)&(_BCM_P|_BCM_U|_BCM_L|_BCM_D|_BCM_SP)) != 0)
46 #define bcm_ispunct(c) ((bcm_ismask(c)&(_BCM_P)) != 0)
47 #define bcm_isspace(c) ((bcm_ismask(c)&(_BCM_S)) != 0)
48 #define bcm_isupper(c) ((bcm_ismask(c)&(_BCM_U)) != 0)
49 #define bcm_isxdigit(c) ((bcm_ismask(c)&(_BCM_D|_BCM_X)) != 0)
50 #define bcm_tolower(c) (bcm_isupper((c)) ? ((c) + 'a' - 'A') : (c))
51 #define bcm_toupper(c) (bcm_islower((c)) ? ((c) + 'A' - 'a') : (c))
52 #endif /* BRCM_FULLMAC */
54 /* Buffer structure for collecting string-formatted data
55 * using bcm_bprintf() API.
56 * Use bcm_binit() to initialize before use
60 char *buf
; /* pointer to current position in origbuf */
61 unsigned int size
; /* current (residual) size in bytes */
62 char *origbuf
; /* unmodified pointer to orignal buffer */
63 unsigned int origsize
; /* unmodified orignal buffer size in bytes */
66 /* ** driver-only section ** */
69 #define GPIO_PIN_NOTDEFINED 0x20 /* Pin not defined */
72 * Spin at most 'us' microseconds while 'exp' is true.
73 * Caller should explicitly test 'exp' when this completes
74 * and take appropriate error action if 'exp' is still true.
76 #define SPINWAIT(exp, us) { \
77 uint countdown = (us) + 9; \
78 while ((exp) && (countdown >= 10)) {\
84 /* osl multi-precedence packet queue */
85 #ifndef PKTQ_LEN_DEFAULT
86 #define PKTQ_LEN_DEFAULT 128 /* Max 128 packets */
89 #define PKTQ_MAX_PREC 16 /* Maximum precedence levels */
92 typedef struct pktq_prec
{
93 void *head
; /* first packet to dequeue */
94 void *tail
; /* last packet to dequeue */
95 uint16 len
; /* number of queued packets */
96 uint16 max
; /* maximum number of queued packets */
99 /* multi-priority pkt queue */
101 uint16 num_prec
; /* number of precedences in use */
102 uint16 hi_prec
; /* rapid dequeue hint (>= highest non-empty prec) */
103 uint16 max
; /* total max packets */
104 uint16 len
; /* total number of packets */
105 /* q array must be last since # of elements can be either PKTQ_MAX_PREC or 1 */
106 struct pktq_prec q
[PKTQ_MAX_PREC
];
109 /* simple, non-priority pkt queue */
111 uint16 num_prec
; /* number of precedences in use (always 1) */
112 uint16 hi_prec
; /* rapid dequeue hint (>= highest non-empty prec) */
113 uint16 max
; /* total max packets */
114 uint16 len
; /* total number of packets */
115 /* q array must be last since # of elements can be either PKTQ_MAX_PREC or 1 */
116 struct pktq_prec q
[1];
119 #define PKTQ_PREC_ITER(pq, prec) for (prec = (pq)->num_prec - 1; prec >= 0; prec--)
121 /* fn(pkt, arg). return true if pkt belongs to if */
122 typedef bool(*ifpkt_cb_t
) (void *, int);
124 /* forward definition of ether_addr structure used by some function prototypes */
128 extern int ether_isbcast(const void *ea
);
129 extern int ether_isnulladdr(const void *ea
);
131 /* operations on a specific precedence in packet queue */
133 #define pktq_psetmax(pq, prec, _max) ((pq)->q[prec].max = (_max))
134 #define pktq_plen(pq, prec) ((pq)->q[prec].len)
135 #define pktq_pavail(pq, prec) ((pq)->q[prec].max - (pq)->q[prec].len)
136 #define pktq_pfull(pq, prec) ((pq)->q[prec].len >= (pq)->q[prec].max)
137 #define pktq_pempty(pq, prec) ((pq)->q[prec].len == 0)
139 #define pktq_ppeek(pq, prec) ((pq)->q[prec].head)
140 #define pktq_ppeek_tail(pq, prec) ((pq)->q[prec].tail)
142 extern void *pktq_penq(struct pktq
*pq
, int prec
, void *p
);
143 extern void *pktq_penq_head(struct pktq
*pq
, int prec
, void *p
);
144 extern void *pktq_pdeq(struct pktq
*pq
, int prec
);
145 extern void *pktq_pdeq_tail(struct pktq
*pq
, int prec
);
146 /* Empty the queue at particular precedence level */
148 extern void pktq_pflush(osl_t
*osh
, struct pktq
*pq
, int prec
,
151 extern void pktq_pflush(osl_t
*osh
, struct pktq
*pq
, int prec
,
152 bool dir
, ifpkt_cb_t fn
, int arg
);
154 /* Remove a specified packet from its queue */
155 extern bool pktq_pdel(struct pktq
*pq
, void *p
, int prec
);
157 /* operations on a set of precedences in packet queue */
159 extern int pktq_mlen(struct pktq
*pq
, uint prec_bmp
);
160 extern void *pktq_mdeq(struct pktq
*pq
, uint prec_bmp
, int *prec_out
);
162 /* operations on packet queue as a whole */
164 #define pktq_len(pq) ((int)(pq)->len)
165 #define pktq_max(pq) ((int)(pq)->max)
166 #define pktq_avail(pq) ((int)((pq)->max - (pq)->len))
167 #define pktq_full(pq) ((pq)->len >= (pq)->max)
168 #define pktq_empty(pq) ((pq)->len == 0)
170 /* operations for single precedence queues */
171 #define pktenq(pq, p) pktq_penq(((struct pktq *)pq), 0, (p))
172 #define pktenq_head(pq, p) pktq_penq_head(((struct pktq *)pq), 0, (p))
173 #define pktdeq(pq) pktq_pdeq(((struct pktq *)pq), 0)
174 #define pktdeq_tail(pq) pktq_pdeq_tail(((struct pktq *)pq), 0)
175 #define pktqinit(pq, len) pktq_init(((struct pktq *)pq), 1, len)
177 extern void pktq_init(struct pktq
*pq
, int num_prec
, int max_len
);
178 /* prec_out may be NULL if caller is not interested in return value */
179 extern void *pktq_deq(struct pktq
*pq
, int *prec_out
);
180 extern void *pktq_deq_tail(struct pktq
*pq
, int *prec_out
);
181 extern void *pktq_peek(struct pktq
*pq
, int *prec_out
);
182 extern void *pktq_peek_tail(struct pktq
*pq
, int *prec_out
);
184 extern void pktq_flush(osl_t
*osh
, struct pktq
*pq
, bool dir
);
186 extern void pktq_flush(osl_t
*osh
, struct pktq
*pq
, bool dir
,
187 ifpkt_cb_t fn
, int arg
);
192 extern uint
pktcopy(osl_t
*osh
, void *p
, uint offset
, int len
,
194 extern uint
pktfrombuf(osl_t
*osh
, void *p
, uint offset
, int len
,
196 extern uint
pkttotlen(osl_t
*osh
, void *p
);
197 extern void *pktlast(osl_t
*osh
, void *p
);
198 extern uint
pktsegcnt(osl_t
*osh
, void *p
);
200 /* Get priority from a packet and pass it back in scb (or equiv) */
201 extern uint
pktsetprio(void *pkt
, bool update_vtag
);
202 #define PKTPRIO_VDSCP 0x100 /* DSCP prio found after VLAN tag */
203 #define PKTPRIO_VLAN 0x200 /* VLAN prio found */
204 #define PKTPRIO_UPD 0x400 /* DSCP used to update VLAN prio */
205 #define PKTPRIO_DSCP 0x800 /* DSCP prio found */
209 extern int BCMROMFN(bcm_atoi
) (char *s
);
210 extern unsigned long BCMROMFN(bcm_strtoul
) (char *cp
, char **endp
, uint base
);
211 extern char *BCMROMFN(bcmstrstr
) (char *haystack
, char *needle
);
212 extern char *BCMROMFN(bcmstrcat
) (char *dest
, const char *src
);
213 extern char *BCMROMFN(bcmstrncat
) (char *dest
, const char *src
,
215 extern unsigned long wchar2ascii(char *abuf
, unsigned short *wbuf
, unsigned short wbuflen
,
216 unsigned long abuflen
);
217 char *bcmstrtok(char **string
, const char *delimiters
, char *tokdelim
);
218 int bcmstricmp(const char *s1
, const char *s2
);
219 int bcmstrnicmp(const char *s1
, const char *s2
, int cnt
);
221 /* ethernet address */
222 extern char *bcm_ether_ntoa(const struct ether_addr
*ea
, char *buf
);
223 extern int BCMROMFN(bcm_ether_atoe
) (char *p
, struct ether_addr
*ea
);
227 extern char *bcm_ip_ntoa(struct ipv4_addr
*ia
, char *buf
);
230 extern void bcm_mdelay(uint ms
);
231 /* variable access */
232 extern char *getvar(char *vars
, const char *name
);
233 extern int getintvar(char *vars
, const char *name
);
234 extern int getintvararray(char *vars
, const char *name
, u8 index
);
235 extern uint
getgpiopin(char *vars
, char *pin_name
, uint def_pin
);
237 extern void prpkt(const char *msg
, osl_t
*osh
, void *p0
);
239 #define bcm_perf_enable()
240 #define bcmstats(fmt)
241 #define bcmlog(fmt, a1, a2)
242 #define bcmdumplog(buf, size) (*buf = '\0')
243 #define bcmdumplogent(buf, idx) -1
245 #define bcmtslog(tstamp, fmt, a1, a2)
246 #define bcmprinttslogs()
247 #define bcmprinttstamp(us)
249 extern char *bcm_nvram_vars(uint
*length
);
250 extern int bcm_nvram_cache(void *sih
);
252 /* Support for sharing code across in-driver iovar implementations.
253 * The intent is that a driver use this structure to map iovar names
254 * to its (private) iovar identifiers, and the lookup function to
255 * find the entry. Macros are provided to map ids and get/set actions
256 * into a single number space for a switch statement.
259 /* iovar structure */
260 typedef struct bcm_iovar
{
261 const char *name
; /* name for lookup and display */
262 uint16 varid
; /* id for switch */
263 uint16 flags
; /* driver-specific flag bits */
264 uint16 type
; /* base type of argument */
265 uint16 minlen
; /* min length for buffer vars */
268 /* varid definitions are per-driver, may use these get/set bits */
270 /* IOVar action bits for id mapping */
271 #define IOV_GET 0 /* Get an iovar */
272 #define IOV_SET 1 /* Set an iovar */
274 /* Varid to actionid mapping */
275 #define IOV_GVAL(id) ((id)*2)
276 #define IOV_SVAL(id) (((id)*2)+IOV_SET)
277 #define IOV_ISSET(actionid) ((actionid & IOV_SET) == IOV_SET)
278 #define IOV_ID(actionid) (actionid >> 1)
280 /* flags are per-driver based on driver attributes */
282 extern const bcm_iovar_t
*bcm_iovar_lookup(const bcm_iovar_t
*table
,
284 extern int bcm_iovar_lencheck(const bcm_iovar_t
*table
, void *arg
,
287 extern int bcm_format_ssid(char *buf
, const unsigned char ssid
[],
291 /* Base type definitions */
292 #define IOVT_VOID 0 /* no value (implictly set only) */
293 #define IOVT_BOOL 1 /* any value ok (zero/nonzero) */
294 #define IOVT_INT8 2 /* integer values are range-checked */
295 #define IOVT_UINT8 3 /* unsigned int 8 bits */
296 #define IOVT_INT16 4 /* int 16 bits */
297 #define IOVT_UINT16 5 /* unsigned int 16 bits */
298 #define IOVT_INT32 6 /* int 32 bits */
299 #define IOVT_UINT32 7 /* unsigned int 32 bits */
300 #define IOVT_BUFFER 8 /* buffer is size-checked as per minlen */
301 #define BCM_IOVT_VALID(type) (((unsigned int)(type)) <= IOVT_BUFFER)
303 /* Initializer for IOV type strings */
304 #define BCM_IOV_TYPE_INIT { \
316 #define BCM_IOVT_IS_INT(type) (\
317 (type == IOVT_BOOL) || \
318 (type == IOVT_INT8) || \
319 (type == IOVT_UINT8) || \
320 (type == IOVT_INT16) || \
321 (type == IOVT_UINT16) || \
322 (type == IOVT_INT32) || \
323 (type == IOVT_UINT32))
325 /* ** driver/apps-shared section ** */
327 #define BCME_STRLEN 64 /* Max string length for BCM errors */
328 #define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST))
331 * error codes could be added but the defined ones shouldn't be changed/deleted
332 * these error codes are exposed to the user code
333 * when ever a new error code is added to this list
334 * please update errorstring table with the related error string and
335 * update osl files with os specific errorcode map
338 #define BCME_OK 0 /* Success */
339 #define BCME_ERROR -1 /* Error generic */
340 #define BCME_BADARG -2 /* Bad Argument */
341 #define BCME_BADOPTION -3 /* Bad option */
342 #define BCME_NOTUP -4 /* Not up */
343 #define BCME_NOTDOWN -5 /* Not down */
344 #define BCME_NOTAP -6 /* Not AP */
345 #define BCME_NOTSTA -7 /* Not STA */
346 #define BCME_BADKEYIDX -8 /* BAD Key Index */
347 #define BCME_RADIOOFF -9 /* Radio Off */
348 #define BCME_NOTBANDLOCKED -10 /* Not band locked */
349 #define BCME_NOCLK -11 /* No Clock */
350 #define BCME_BADRATESET -12 /* BAD Rate valueset */
351 #define BCME_BADBAND -13 /* BAD Band */
352 #define BCME_BUFTOOSHORT -14 /* Buffer too short */
353 #define BCME_BUFTOOLONG -15 /* Buffer too long */
354 #define BCME_BUSY -16 /* Busy */
355 #define BCME_NOTASSOCIATED -17 /* Not Associated */
356 #define BCME_BADSSIDLEN -18 /* Bad SSID len */
357 #define BCME_OUTOFRANGECHAN -19 /* Out of Range Channel */
358 #define BCME_BADCHAN -20 /* Bad Channel */
359 #define BCME_BADADDR -21 /* Bad Address */
360 #define BCME_NORESOURCE -22 /* Not Enough Resources */
361 #define BCME_UNSUPPORTED -23 /* Unsupported */
362 #define BCME_BADLEN -24 /* Bad length */
363 #define BCME_NOTREADY -25 /* Not Ready */
364 #define BCME_EPERM -26 /* Not Permitted */
365 #define BCME_NOMEM -27 /* No Memory */
366 #define BCME_ASSOCIATED -28 /* Associated */
367 #define BCME_RANGE -29 /* Not In Range */
368 #define BCME_NOTFOUND -30 /* Not Found */
369 #define BCME_WME_NOT_ENABLED -31 /* WME Not Enabled */
370 #define BCME_TSPEC_NOTFOUND -32 /* TSPEC Not Found */
371 #define BCME_ACM_NOTSUPPORTED -33 /* ACM Not Supported */
372 #define BCME_NOT_WME_ASSOCIATION -34 /* Not WME Association */
373 #define BCME_SDIO_ERROR -35 /* SDIO Bus Error */
374 #define BCME_DONGLE_DOWN -36 /* Dongle Not Accessible */
375 #define BCME_VERSION -37 /* Incorrect version */
376 #define BCME_TXFAIL -38 /* TX failure */
377 #define BCME_RXFAIL -39 /* RX failure */
378 #define BCME_NODEVICE -40 /* Device not present */
379 #define BCME_NMODE_DISABLED -41 /* NMODE disabled */
380 #define BCME_NONRESIDENT -42 /* access to nonresident overlay */
381 #define BCME_LAST BCME_NONRESIDENT
383 /* These are collection of BCME Error strings */
384 #define BCMERRSTRINGTABLE { \
397 "Bad Rate valueset", \
399 "Buffer too short", \
404 "Out of Range Channel", \
407 "Not Enough Resources", \
418 "ACM Not Supported", \
419 "Not WME Association", \
421 "Dongle Not Accessible", \
422 "Incorrect version", \
425 "Device Not Present", \
427 "Nonresident overlay access", \
431 #define ABS(a) (((a) < 0) ? -(a) : (a))
435 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
439 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
442 #define CEIL(x, y) (((x) + ((y)-1)) / (y))
443 #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
444 #define ISALIGNED(a, x) (((a) & ((x)-1)) == 0)
445 #define ALIGN_ADDR(addr, boundary) (void *)(((uintptr)(addr) + (boundary) - 1) \
447 #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0)
448 #define VALID_MASK(mask) (!((mask) & ((mask) + 1)))
450 #define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member)
451 #endif /* OFFSETOF */
453 #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
456 /* bit map related macros */
458 #ifndef NBBY /* the BSD family defines NBBY */
459 #define NBBY 8 /* 8 bits per byte */
460 #endif /* #ifndef NBBY */
461 #define setbit(a, i) (((u8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
462 #define clrbit(a, i) (((u8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
463 #define isset(a, i) (((const u8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
464 #define isclr(a, i) ((((const u8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
467 #define NBITS(type) (sizeof(type) * 8)
468 #define NBITVAL(nbits) (1 << (nbits))
469 #define MAXBITVAL(nbits) ((1 << (nbits)) - 1)
470 #define NBITMASK(nbits) MAXBITVAL(nbits)
471 #define MAXNBVAL(nbyte) MAXBITVAL((nbyte) * 8)
473 /* basic mux operation - can be optimized on several architectures */
474 #define MUX(pred, true, false) ((pred) ? (true) : (false))
476 /* modulo inc/dec - assumes x E [0, bound - 1] */
477 #define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1)
478 #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
480 /* modulo inc/dec, bound = 2^k */
481 #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
482 #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
484 /* modulo add/sub - assumes x, y E [0, bound - 1] */
485 #define MODADD(x, y, bound) \
486 MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y))
487 #define MODSUB(x, y, bound) \
488 MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y))
490 /* module add/sub, bound = 2^k */
491 #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
492 #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
495 #define CRC8_INIT_VALUE 0xff /* Initial CRC8 checksum value */
496 #define CRC8_GOOD_VALUE 0x9f /* Good final CRC8 checksum value */
497 #define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
498 #define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
500 /* bcm_format_flags() bit description structure */
501 typedef struct bcm_bit_desc
{
506 /* tag_ID/length/value_buffer tuple */
507 typedef struct bcm_tlv
{
513 /* Check that bcm_tlv_t fits into the given buflen */
514 #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
516 /* buffer length for ethernet address from bcm_ether_ntoa() */
517 #define ETHER_ADDR_STR_LEN 18 /* 18-bytes of Ethernet address buffer length */
519 /* crypto utility function */
520 /* 128-bit xor: *dst = *src1 xor *src2. dst1, src1 and src2 may have any alignment */
522 xor_128bit_block(const u8
*src1
, const u8
*src2
, u8
*dst
) {
527 (((uintptr
) src1
| (uintptr
) src2
| (uintptr
) dst
) &
529 /* ARM CM3 rel time: 1229 (727 if alignment check could be omitted) */
530 /* x86 supports unaligned. This version runs 6x-9x faster on x86. */
531 ((uint32
*) dst
)[0] =
532 ((const uint32
*)src1
)[0] ^ ((const uint32
*)
534 ((uint32
*) dst
)[1] =
535 ((const uint32
*)src1
)[1] ^ ((const uint32
*)
537 ((uint32
*) dst
)[2] =
538 ((const uint32
*)src1
)[2] ^ ((const uint32
*)
540 ((uint32
*) dst
)[3] =
541 ((const uint32
*)src1
)[3] ^ ((const uint32
*)
544 /* ARM CM3 rel time: 4668 (4191 if alignment check could be omitted) */
546 for (k
= 0; k
< 16; k
++)
547 dst
[k
] = src1
[k
] ^ src2
[k
];
553 extern u8
BCMROMFN(hndcrc8
) (u8
*p
, uint nbytes
, u8 crc
);
554 extern uint16
BCMROMFN(hndcrc16
) (u8
*p
, uint nbytes
, uint16 crc
);
557 extern int bcm_format_flags(const bcm_bit_desc_t
*bd
, uint32 flags
,
559 extern int bcm_format_hex(char *str
, const void *bytes
, int len
);
562 extern void deadbeef(void *p
, uint len
);
564 extern const char *bcm_crypto_algo_name(uint algo
);
565 extern char *bcm_chipname(uint chipid
, char *buf
, uint len
);
566 extern char *bcm_brev_str(uint32 brev
, char *buf
);
567 extern void printbig(char *buf
);
568 extern void prhex(const char *msg
, unsigned char *buf
, uint len
);
571 extern bcm_tlv_t
*BCMROMFN(bcm_next_tlv
) (bcm_tlv_t
*elt
, int *buflen
);
572 extern bcm_tlv_t
*BCMROMFN(bcm_parse_tlvs
) (void *buf
, int buflen
,
574 extern bcm_tlv_t
*BCMROMFN(bcm_parse_ordered_tlvs
) (void *buf
,
579 extern const char *bcmerrorstr(int bcmerror
);
581 /* multi-bool data type: set of bools, mbool is true if any is set */
582 typedef uint32 mbool
;
583 #define mboolset(mb, bit) ((mb) |= (bit)) /* set one bool */
584 #define mboolclr(mb, bit) ((mb) &= ~(bit)) /* clear one bool */
585 #define mboolisset(mb, bit) (((mb) & (bit)) != 0) /* TRUE if one bool is set */
586 #define mboolmaskset(mb, mask, val) ((mb) = (((mb) & ~(mask)) | (val)))
588 /* power conversion */
589 extern uint16
BCMROMFN(bcm_qdbm_to_mw
) (u8 qdbm
);
590 extern u8
BCMROMFN(bcm_mw_to_qdbm
) (uint16 mw
);
592 /* generic datastruct to help dump routines */
594 const char *nameandfmt
;
599 extern void bcm_binit(struct bcmstrbuf
*b
, char *buf
, uint size
);
600 extern int bcm_bprintf(struct bcmstrbuf
*b
, const char *fmt
, ...);
601 extern void bcm_inc_bytes(unsigned char *num
, int num_bytes
, u8 amount
);
602 extern int bcm_cmp_bytes(unsigned char *arg1
, unsigned char *arg2
, u8 nbytes
);
603 extern void bcm_print_bytes(char *name
, const unsigned char *cdata
, int len
);
605 typedef uint32(*bcmutl_rdreg_rtn
) (void *arg0
, uint arg1
,
607 extern uint
bcmdumpfields(bcmutl_rdreg_rtn func_ptr
, void *arg0
,
608 uint arg1
, struct fielddesc
*str
, char *buf
,
611 extern uint
bcm_mkiovar(char *name
, char *data
, uint datalen
, char *buf
,
613 extern uint
BCMROMFN(bcm_bitcount
) (u8
*bitmap
, uint bytelength
);
619 #endif /* _bcmutils_h_ */