2 * Misc useful os-independent macros and functions.
4 * Copyright 2006, Broadcom Corporation
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.
17 /* ** driver/apps-shared section ** */
19 #define BCME_STRLEN 64 /* Max string length for BCM errors */
20 #define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST))
24 * error codes could be added but the defined ones shouldn't be changed/deleted
25 * these error codes are exposed to the user code
26 * when ever a new error code is added to this list
27 * please update errorstring table with the related error string and
28 * update osl files with os specific errorcode map
31 #define BCME_OK 0 /* Success */
32 #define BCME_ERROR -1 /* Error generic */
33 #define BCME_BADARG -2 /* Bad Argument */
34 #define BCME_BADOPTION -3 /* Bad option */
35 #define BCME_NOTUP -4 /* Not up */
36 #define BCME_NOTDOWN -5 /* Not down */
37 #define BCME_NOTAP -6 /* Not AP */
38 #define BCME_NOTSTA -7 /* Not STA */
39 #define BCME_BADKEYIDX -8 /* BAD Key Index */
40 #define BCME_RADIOOFF -9 /* Radio Off */
41 #define BCME_NOTBANDLOCKED -10 /* Not band locked */
42 #define BCME_NOCLK -11 /* No Clock */
43 #define BCME_BADRATESET -12 /* BAD Rate valueset */
44 #define BCME_BADBAND -13 /* BAD Band */
45 #define BCME_BUFTOOSHORT -14 /* Buffer too short */
46 #define BCME_BUFTOOLONG -15 /* Buffer too long */
47 #define BCME_BUSY -16 /* Busy */
48 #define BCME_NOTASSOCIATED -17 /* Not Associated */
49 #define BCME_BADSSIDLEN -18 /* Bad SSID len */
50 #define BCME_OUTOFRANGECHAN -19 /* Out of Range Channel */
51 #define BCME_BADCHAN -20 /* Bad Channel */
52 #define BCME_BADADDR -21 /* Bad Address */
53 #define BCME_NORESOURCE -22 /* Not Enough Resources */
54 #define BCME_UNSUPPORTED -23 /* Unsupported */
55 #define BCME_BADLEN -24 /* Bad length */
56 #define BCME_NOTREADY -25 /* Not Ready */
57 #define BCME_EPERM -26 /* Not Permitted */
58 #define BCME_NOMEM -27 /* No Memory */
59 #define BCME_ASSOCIATED -28 /* Associated */
60 #define BCME_RANGE -29 /* Not In Range */
61 #define BCME_NOTFOUND -30 /* Not Found */
62 #define BCME_WME_NOT_ENABLED -31 /* WME Not Enabled */
63 #define BCME_TSPEC_NOTFOUND -32 /* TSPEC Not Found */
64 #define BCME_ACM_NOTSUPPORTED -33 /* ACM Not Supported */
65 #define BCME_NOT_WME_ASSOCIATION -34 /* Not WME Association */
66 #define BCME_SDIO_ERROR -35 /* SDIO Bus Error */
67 #define BCME_DONGLE_DOWN -36 /* Dongle Not Accessible */
68 #define BCME_LAST BCME_DONGLE_DOWN
70 /* These are collection of BCME Error strings */
71 #define BCMERRSTRINGTABLE { \
84 "Bad Rate valueset", \
91 "Out of Range Channel", \
94 "Not Enough Resources", \
105 "ACM Not Supported", \
106 "Not WME Association", \
108 "Dongle Not Accessible" \
112 #define ABS(a) (((a) < 0)?-(a):(a))
116 #define MIN(a, b) (((a) < (b))?(a):(b))
120 #define MAX(a, b) (((a) > (b))?(a):(b))
123 #define CEIL(x, y) (((x) + ((y)-1)) / (y))
124 #define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
125 #define ISALIGNED(a, x) (((a) & ((x)-1)) == 0)
126 #define ISPOWEROF2(x) ((((x)-1)&(x)) == 0)
127 #define VALID_MASK(mask) !((mask) & ((mask) + 1))
128 #define OFFSETOF(type, member) ((uint)(uintptr)&((type *)0)->member)
129 #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
131 /* bit map related macros */
133 #ifndef NBBY /* the BSD family defines NBBY */
134 #define NBBY 8 /* 8 bits per byte */
135 #endif /* #ifndef NBBY */
136 #define setbit(a, i) (((uint8 *)a)[(i)/NBBY] |= 1<<((i)%NBBY))
137 #define clrbit(a, i) (((uint8 *)a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
138 #define isset(a, i) (((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY)))
139 #define isclr(a, i) ((((uint8 *)a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
142 #define NBITS(type) (sizeof(type) * 8)
143 #define NBITVAL(nbits) (1 << (nbits))
144 #define MAXBITVAL(nbits) ((1 << (nbits)) - 1)
145 #define NBITMASK(nbits) MAXBITVAL(nbits)
146 #define MAXNBVAL(nbyte) MAXBITVAL((nbyte) * 8)
148 /* basic mux operation - can be optimized on several architectures */
149 #define MUX(pred, true, false) ((pred) ? (true) : (false))
151 /* modulo inc/dec - assumes x E [0, bound - 1] */
152 #define MODDEC(x, bound) MUX((x) == 0, (bound) - 1, (x) - 1)
153 #define MODINC(x, bound) MUX((x) == (bound) - 1, 0, (x) + 1)
155 /* modulo inc/dec, bound = 2^k */
156 #define MODDEC_POW2(x, bound) (((x) - 1) & ((bound) - 1))
157 #define MODINC_POW2(x, bound) (((x) + 1) & ((bound) - 1))
159 /* modulo add/sub - assumes x, y E [0, bound - 1] */
160 #define MODADD(x, y, bound) \
161 MUX((x) + (y) >= (bound), (x) + (y) - (bound), (x) + (y))
162 #define MODSUB(x, y, bound) \
163 MUX(((int)(x)) - ((int)(y)) < 0, (x) - (y) + (bound), (x) - (y))
165 /* module add/sub, bound = 2^k */
166 #define MODADD_POW2(x, y, bound) (((x) + (y)) & ((bound) - 1))
167 #define MODSUB_POW2(x, y, bound) (((x) - (y)) & ((bound) - 1))
170 #define CRC8_INIT_VALUE 0xff /* Initial CRC8 checksum value */
171 #define CRC8_GOOD_VALUE 0x9f /* Good final CRC8 checksum value */
172 #define CRC16_INIT_VALUE 0xffff /* Initial CRC16 checksum value */
173 #define CRC16_GOOD_VALUE 0xf0b8 /* Good final CRC16 checksum value */
174 #define CRC32_INIT_VALUE 0xffffffff /* Initial CRC32 checksum value */
175 #define CRC32_GOOD_VALUE 0xdebb20e3 /* Good final CRC32 checksum value */
177 /* bcm_format_flags() bit description structure */
178 typedef struct bcm_bit_desc
{
183 /* tag_ID/length/value_buffer tuple */
184 typedef struct bcm_tlv
{
190 /* Check that bcm_tlv_t fits into the given buflen */
191 #define bcm_valid_tlv(elt, buflen) ((buflen) >= 2 && (int)(buflen) >= (int)(2 + (elt)->len))
193 /* buffer length for ethernet address from bcm_ether_ntoa() */
194 #define ETHER_ADDR_STR_LEN 18 /* 18-bytes of Ethernet address buffer length */
196 /* unaligned load and store macros */
201 return ((a
[0] << 24) | (a
[1] << 16) | (a
[2] << 8) | a
[3]);
205 store32_ua(uint8
*a
, uint32 v
)
207 a
[0] = (v
>> 24) & 0xff;
208 a
[1] = (v
>> 16) & 0xff;
209 a
[2] = (v
>> 8) & 0xff;
216 return ((a
[0] << 8) | a
[1]);
220 store16_ua(uint8
*a
, uint16 v
)
222 a
[0] = (v
>> 8) & 0xff;
231 return ((a
[3] << 24) | (a
[2] << 16) | (a
[1] << 8) | a
[0]);
235 store32_ua(uint8
*a
, uint32 v
)
237 a
[3] = (v
>> 24) & 0xff;
238 a
[2] = (v
>> 16) & 0xff;
239 a
[1] = (v
>> 8) & 0xff;
246 return ((a
[1] << 8) | a
[0]);
250 store16_ua(uint8
*a
, uint16 v
)
252 a
[1] = (v
>> 8) & 0xff;
256 #endif /* IL_BIGENDIAN */
258 #endif /* _bcmutils_h_ */
This page took 0.061377 seconds and 5 git commands to generate.