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