| .. | .. |
|---|
| 1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
|---|
| 2 | 1 | /* |
|---|
| 3 | 2 | * Misc useful os-independent macros and functions. |
|---|
| 4 | 3 | * |
|---|
| 5 | | - * Copyright (C) 1999-2019, Broadcom Corporation |
|---|
| 6 | | - * |
|---|
| 4 | + * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation |
|---|
| 5 | + * |
|---|
| 6 | + * Copyright (C) 1999-2017, Broadcom Corporation |
|---|
| 7 | + * |
|---|
| 7 | 8 | * Unless you and Broadcom execute a separate written software license |
|---|
| 8 | 9 | * agreement governing use of this software, this software is licensed to you |
|---|
| 9 | 10 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
|---|
| 10 | 11 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
|---|
| 11 | 12 | * following added to such license: |
|---|
| 12 | | - * |
|---|
| 13 | + * |
|---|
| 13 | 14 | * As a special exception, the copyright holders of this software give you |
|---|
| 14 | 15 | * permission to link this software with independent modules, and to copy and |
|---|
| 15 | 16 | * distribute the resulting executable under terms of your choice, provided that |
|---|
| .. | .. |
|---|
| 17 | 18 | * the license of that module. An independent module is a module which is not |
|---|
| 18 | 19 | * derived from this software. The special exception does not apply to any |
|---|
| 19 | 20 | * modifications of the software. |
|---|
| 20 | | - * |
|---|
| 21 | + * |
|---|
| 21 | 22 | * Notwithstanding the above, under no circumstances may you combine this |
|---|
| 22 | 23 | * software in any way with any other Broadcom software provided under a license |
|---|
| 23 | 24 | * other than the GPL, without Broadcom's express prior written consent. |
|---|
| .. | .. |
|---|
| 25 | 26 | * |
|---|
| 26 | 27 | * <<Broadcom-WL-IPTag/Open:>> |
|---|
| 27 | 28 | * |
|---|
| 28 | | - * $Id: bcmutils.h 696078 2018-08-15 09:24:11Z $ |
|---|
| 29 | + * $Id: bcmutils.h 700843 2017-05-22 15:56:44Z $ |
|---|
| 29 | 30 | */ |
|---|
| 30 | 31 | |
|---|
| 31 | 32 | #ifndef _bcmutils_h_ |
|---|
| 32 | 33 | #define _bcmutils_h_ |
|---|
| 33 | 34 | |
|---|
| 35 | +#include <bcmtlv.h> |
|---|
| 34 | 36 | |
|---|
| 35 | 37 | #ifdef __cplusplus |
|---|
| 36 | 38 | extern "C" { |
|---|
| 37 | | -#endif |
|---|
| 38 | | - |
|---|
| 39 | +#endif // endif |
|---|
| 39 | 40 | |
|---|
| 40 | 41 | #define bcm_strncpy_s(dst, noOfElements, src, count) strncpy((dst), (src), (count)) |
|---|
| 42 | +#ifdef FREEBSD |
|---|
| 43 | +#define bcm_strncat_s(dst, noOfElements, src, count) strcat((dst), (src)) |
|---|
| 44 | +#else |
|---|
| 41 | 45 | #define bcm_strncat_s(dst, noOfElements, src, count) strncat((dst), (src), (count)) |
|---|
| 46 | +#endif /* FREEBSD */ |
|---|
| 42 | 47 | #define bcm_snprintf_s snprintf |
|---|
| 43 | 48 | #define bcm_sprintf_s snprintf |
|---|
| 44 | 49 | |
|---|
| .. | .. |
|---|
| 48 | 53 | * bcm_strcat_s: Use bcm_strncat_s as a safer option |
|---|
| 49 | 54 | * |
|---|
| 50 | 55 | */ |
|---|
| 56 | + |
|---|
| 57 | +#define BCM_BIT(x) (1 << (x)) |
|---|
| 51 | 58 | |
|---|
| 52 | 59 | /* ctype replacement */ |
|---|
| 53 | 60 | #define _BCM_U 0x01 /* upper */ |
|---|
| .. | .. |
|---|
| 109 | 116 | * and take appropriate error action if 'exp' is still true. |
|---|
| 110 | 117 | */ |
|---|
| 111 | 118 | #ifndef SPINWAIT_POLL_PERIOD |
|---|
| 112 | | -#define SPINWAIT_POLL_PERIOD 10 |
|---|
| 113 | | -#endif |
|---|
| 119 | +#define SPINWAIT_POLL_PERIOD 10U |
|---|
| 120 | +#endif // endif |
|---|
| 114 | 121 | |
|---|
| 115 | 122 | #define SPINWAIT(exp, us) { \ |
|---|
| 116 | | - uint countdown = (us) + (SPINWAIT_POLL_PERIOD - 1); \ |
|---|
| 117 | | - while ((exp) && (countdown >= SPINWAIT_POLL_PERIOD)) { \ |
|---|
| 123 | + uint countdown = (us) + (SPINWAIT_POLL_PERIOD - 1U); \ |
|---|
| 124 | + while (((exp) != 0) && (uint)(countdown >= SPINWAIT_POLL_PERIOD)) { \ |
|---|
| 118 | 125 | OSL_DELAY(SPINWAIT_POLL_PERIOD); \ |
|---|
| 119 | 126 | countdown -= SPINWAIT_POLL_PERIOD; \ |
|---|
| 120 | 127 | } \ |
|---|
| .. | .. |
|---|
| 127 | 134 | extern int ether_isbcast(const void *ea); |
|---|
| 128 | 135 | extern int ether_isnulladdr(const void *ea); |
|---|
| 129 | 136 | |
|---|
| 130 | | -#define BCM_MAC_RXCPL_IDX_BITS 12 |
|---|
| 131 | | -#define BCM_MAX_RXCPL_IDX_INVALID 0 |
|---|
| 132 | | -#define BCM_MAC_RXCPL_IFIDX_BITS 3 |
|---|
| 133 | | -#define BCM_MAC_RXCPL_DOT11_BITS 1 |
|---|
| 134 | | -#define BCM_MAX_RXCPL_IFIDX ((1 << BCM_MAC_RXCPL_IFIDX_BITS) - 1) |
|---|
| 135 | | -#define BCM_MAC_RXCPL_FLAG_BITS 4 |
|---|
| 136 | | -#define BCM_RXCPL_FLAGS_IN_TRANSIT 0x1 |
|---|
| 137 | | -#define BCM_RXCPL_FLAGS_FIRST_IN_FLUSHLIST 0x2 |
|---|
| 138 | | -#define BCM_RXCPL_FLAGS_RXCPLVALID 0x4 |
|---|
| 139 | | -#define BCM_RXCPL_FLAGS_RSVD 0x8 |
|---|
| 140 | | - |
|---|
| 141 | | -#define BCM_RXCPL_SET_IN_TRANSIT(a) ((a)->rxcpl_id.flags |= BCM_RXCPL_FLAGS_IN_TRANSIT) |
|---|
| 142 | | -#define BCM_RXCPL_CLR_IN_TRANSIT(a) ((a)->rxcpl_id.flags &= ~BCM_RXCPL_FLAGS_IN_TRANSIT) |
|---|
| 143 | | -#define BCM_RXCPL_IN_TRANSIT(a) ((a)->rxcpl_id.flags & BCM_RXCPL_FLAGS_IN_TRANSIT) |
|---|
| 144 | | - |
|---|
| 145 | | -#define BCM_RXCPL_SET_FRST_IN_FLUSH(a) ((a)->rxcpl_id.flags |= BCM_RXCPL_FLAGS_FIRST_IN_FLUSHLIST) |
|---|
| 146 | | -#define BCM_RXCPL_CLR_FRST_IN_FLUSH(a) ((a)->rxcpl_id.flags &= ~BCM_RXCPL_FLAGS_FIRST_IN_FLUSHLIST) |
|---|
| 147 | | -#define BCM_RXCPL_FRST_IN_FLUSH(a) ((a)->rxcpl_id.flags & BCM_RXCPL_FLAGS_FIRST_IN_FLUSHLIST) |
|---|
| 148 | | - |
|---|
| 149 | | -#define BCM_RXCPL_SET_VALID_INFO(a) ((a)->rxcpl_id.flags |= BCM_RXCPL_FLAGS_RXCPLVALID) |
|---|
| 150 | | -#define BCM_RXCPL_CLR_VALID_INFO(a) ((a)->rxcpl_id.flags &= ~BCM_RXCPL_FLAGS_RXCPLVALID) |
|---|
| 151 | | -#define BCM_RXCPL_VALID_INFO(a) (((a)->rxcpl_id.flags & BCM_RXCPL_FLAGS_RXCPLVALID) ? TRUE : FALSE) |
|---|
| 152 | | - |
|---|
| 153 | 137 | #define UP_TABLE_MAX ((IPV4_TOS_DSCP_MASK >> IPV4_TOS_DSCP_SHIFT) + 1) /* 64 max */ |
|---|
| 154 | | - |
|---|
| 155 | | -struct reorder_rxcpl_id_list { |
|---|
| 156 | | - uint16 head; |
|---|
| 157 | | - uint16 tail; |
|---|
| 158 | | - uint32 cnt; |
|---|
| 159 | | -}; |
|---|
| 160 | | - |
|---|
| 161 | | -typedef struct rxcpl_id { |
|---|
| 162 | | - uint32 idx : BCM_MAC_RXCPL_IDX_BITS; |
|---|
| 163 | | - uint32 next_idx : BCM_MAC_RXCPL_IDX_BITS; |
|---|
| 164 | | - uint32 ifidx : BCM_MAC_RXCPL_IFIDX_BITS; |
|---|
| 165 | | - uint32 dot11 : BCM_MAC_RXCPL_DOT11_BITS; |
|---|
| 166 | | - uint32 flags : BCM_MAC_RXCPL_FLAG_BITS; |
|---|
| 167 | | -} rxcpl_idx_id_t; |
|---|
| 168 | | - |
|---|
| 169 | | -typedef struct rxcpl_data_len { |
|---|
| 170 | | - uint32 metadata_len_w : 6; |
|---|
| 171 | | - uint32 dataoffset: 10; |
|---|
| 172 | | - uint32 datalen : 16; |
|---|
| 173 | | -} rxcpl_data_len_t; |
|---|
| 174 | | - |
|---|
| 175 | | -typedef struct rxcpl_info { |
|---|
| 176 | | - rxcpl_idx_id_t rxcpl_id; |
|---|
| 177 | | - uint32 host_pktref; |
|---|
| 178 | | - union { |
|---|
| 179 | | - rxcpl_data_len_t rxcpl_len; |
|---|
| 180 | | - struct rxcpl_info *free_next; |
|---|
| 181 | | - }; |
|---|
| 182 | | -} rxcpl_info_t; |
|---|
| 183 | | - |
|---|
| 184 | | -/* rx completion list */ |
|---|
| 185 | | -typedef struct bcm_rxcplid_list { |
|---|
| 186 | | - uint32 max; |
|---|
| 187 | | - uint32 avail; |
|---|
| 188 | | - rxcpl_info_t *rxcpl_ptr; |
|---|
| 189 | | - rxcpl_info_t *free_list; |
|---|
| 190 | | -} bcm_rxcplid_list_t; |
|---|
| 191 | | - |
|---|
| 192 | | -extern bool bcm_alloc_rxcplid_list(osl_t *osh, uint32 max); |
|---|
| 193 | | -extern rxcpl_info_t * bcm_alloc_rxcplinfo(void); |
|---|
| 194 | | -extern void bcm_free_rxcplinfo(rxcpl_info_t *ptr); |
|---|
| 195 | | -extern void bcm_chain_rxcplid(uint16 first, uint16 next); |
|---|
| 196 | | -extern rxcpl_info_t *bcm_id2rxcplinfo(uint16 id); |
|---|
| 197 | | -extern uint16 bcm_rxcplinfo2id(rxcpl_info_t *ptr); |
|---|
| 198 | | -extern rxcpl_info_t *bcm_rxcpllist_end(rxcpl_info_t *ptr, uint32 *count); |
|---|
| 138 | +#define CORE_SLAVE_PORT_0 0 |
|---|
| 139 | +#define CORE_SLAVE_PORT_1 1 |
|---|
| 140 | +#define CORE_BASE_ADDR_0 0 |
|---|
| 141 | +#define CORE_BASE_ADDR_1 1 |
|---|
| 199 | 142 | |
|---|
| 200 | 143 | /* externs */ |
|---|
| 201 | 144 | /* packet */ |
|---|
| .. | .. |
|---|
| 204 | 147 | extern uint pkttotlen(osl_t *osh, void *p); |
|---|
| 205 | 148 | extern void *pktlast(osl_t *osh, void *p); |
|---|
| 206 | 149 | extern uint pktsegcnt(osl_t *osh, void *p); |
|---|
| 207 | | -extern uint pktsegcnt_war(osl_t *osh, void *p); |
|---|
| 208 | 150 | extern uint8 *pktdataoffset(osl_t *osh, void *p, uint offset); |
|---|
| 209 | 151 | extern void *pktoffset(osl_t *osh, void *p, uint offset); |
|---|
| 210 | 152 | |
|---|
| .. | .. |
|---|
| 223 | 165 | #define DSCP_AF21 0x12 |
|---|
| 224 | 166 | #define DSCP_AF22 0x14 |
|---|
| 225 | 167 | #define DSCP_AF23 0x16 |
|---|
| 168 | +/* CS2: OAM (RFC2474) */ |
|---|
| 169 | +#define DSCP_CS2 0x10 |
|---|
| 226 | 170 | /* AF3x: Multimedia Streaming (RFC2597) */ |
|---|
| 227 | 171 | #define DSCP_AF31 0x1A |
|---|
| 228 | 172 | #define DSCP_AF32 0x1C |
|---|
| 229 | 173 | #define DSCP_AF33 0x1E |
|---|
| 174 | +/* CS3: Broadcast Video (RFC2474) */ |
|---|
| 175 | +#define DSCP_CS3 0x18 |
|---|
| 176 | +/* VA: VOCIE-ADMIT (RFC5865) */ |
|---|
| 177 | +#define DSCP_VA 0x2C |
|---|
| 230 | 178 | /* EF: Telephony (RFC3246) */ |
|---|
| 231 | 179 | #define DSCP_EF 0x2E |
|---|
| 180 | +/* CS6: Network Control (RFC2474) */ |
|---|
| 181 | +#define DSCP_CS6 0x30 |
|---|
| 182 | +/* CS7: Network Control (RFC2474) */ |
|---|
| 183 | +#define DSCP_CS7 0x38 |
|---|
| 232 | 184 | |
|---|
| 233 | 185 | extern uint pktsetprio(void *pkt, bool update_vtag); |
|---|
| 234 | 186 | extern uint pktsetprio_qms(void *pkt, uint8* up_table, bool update_vtag); |
|---|
| 235 | 187 | extern bool pktgetdscp(uint8 *pktdata, uint pktlen, uint8 *dscp); |
|---|
| 236 | | - |
|---|
| 237 | | -/* string */ |
|---|
| 238 | | -extern int bcm_atoi(const char *s); |
|---|
| 239 | | -extern ulong bcm_strtoul(const char *cp, char **endp, uint base); |
|---|
| 240 | | -extern char *bcmstrstr(const char *haystack, const char *needle); |
|---|
| 241 | | -extern char *bcmstrnstr(const char *s, uint s_len, const char *substr, uint substr_len); |
|---|
| 242 | | -extern char *bcmstrcat(char *dest, const char *src); |
|---|
| 243 | | -extern char *bcmstrncat(char *dest, const char *src, uint size); |
|---|
| 244 | | -extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen); |
|---|
| 245 | | -char* bcmstrtok(char **string, const char *delimiters, char *tokdelim); |
|---|
| 246 | | -int bcmstricmp(const char *s1, const char *s2); |
|---|
| 247 | | -int bcmstrnicmp(const char* s1, const char* s2, int cnt); |
|---|
| 248 | | - |
|---|
| 249 | 188 | |
|---|
| 250 | 189 | /* ethernet address */ |
|---|
| 251 | 190 | extern char *bcm_ether_ntoa(const struct ether_addr *ea, char *buf); |
|---|
| .. | .. |
|---|
| 260 | 199 | /* delay */ |
|---|
| 261 | 200 | extern void bcm_mdelay(uint ms); |
|---|
| 262 | 201 | /* variable access */ |
|---|
| 202 | +#if defined(BCM_RECLAIM) |
|---|
| 203 | +extern bool _nvram_reclaim_enb; |
|---|
| 204 | +#define NVRAM_RECLAIM_ENAB() (_nvram_reclaim_enb) |
|---|
| 205 | +#define NVRAM_RECLAIM_CHECK(name) \ |
|---|
| 206 | + if (NVRAM_RECLAIM_ENAB() && (bcm_attach_part_reclaimed == TRUE)) { \ |
|---|
| 207 | + *(char*) 0 = 0; /* TRAP */ \ |
|---|
| 208 | + return NULL; \ |
|---|
| 209 | + } |
|---|
| 210 | +#else /* BCM_RECLAIM */ |
|---|
| 263 | 211 | #define NVRAM_RECLAIM_CHECK(name) |
|---|
| 212 | +#endif /* BCM_RECLAIM */ |
|---|
| 264 | 213 | |
|---|
| 265 | 214 | extern char *getvar(char *vars, const char *name); |
|---|
| 266 | 215 | extern int getintvar(char *vars, const char *name); |
|---|
| 267 | 216 | extern int getintvararray(char *vars, const char *name, int index); |
|---|
| 268 | 217 | extern int getintvararraysize(char *vars, const char *name); |
|---|
| 218 | + |
|---|
| 219 | +/* Read an array of values from a possibly slice-specific nvram string */ |
|---|
| 220 | +extern int get_uint8_vararray_slicespecific(osl_t *osh, char *vars, char *vars_table_accessor, |
|---|
| 221 | + const char* name, uint8* dest_array, uint dest_size); |
|---|
| 222 | +extern int get_int16_vararray_slicespecific(osl_t *osh, char *vars, char *vars_table_accessor, |
|---|
| 223 | + const char* name, int16* dest_array, uint dest_size); |
|---|
| 224 | +/* Prepend a slice-specific accessor to an nvram string name */ |
|---|
| 225 | +extern int get_slicespecific_var_name(osl_t *osh, char *vars_table_accessor, |
|---|
| 226 | + const char *name, char **name_out); |
|---|
| 227 | + |
|---|
| 269 | 228 | extern uint getgpiopin(char *vars, char *pin_name, uint def_pin); |
|---|
| 270 | 229 | #define bcm_perf_enable() |
|---|
| 271 | 230 | #define bcmstats(fmt) |
|---|
| .. | .. |
|---|
| 297 | 256 | const char *name; /* name for lookup and display */ |
|---|
| 298 | 257 | uint16 varid; /* id for switch */ |
|---|
| 299 | 258 | uint16 flags; /* driver-specific flag bits */ |
|---|
| 300 | | - uint16 type; /* base type of argument */ |
|---|
| 259 | + uint8 flags2; /* driver-specific flag bits */ |
|---|
| 260 | + uint8 type; /* base type of argument */ |
|---|
| 301 | 261 | uint16 minlen; /* min length for buffer vars */ |
|---|
| 302 | 262 | } bcm_iovar_t; |
|---|
| 303 | 263 | |
|---|
| .. | .. |
|---|
| 317 | 277 | |
|---|
| 318 | 278 | extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name); |
|---|
| 319 | 279 | extern int bcm_iovar_lencheck(const bcm_iovar_t *table, void *arg, int len, bool set); |
|---|
| 280 | + |
|---|
| 281 | +/* ioctl structure */ |
|---|
| 282 | +typedef struct wlc_ioctl_cmd { |
|---|
| 283 | + uint16 cmd; /**< IOCTL command */ |
|---|
| 284 | + uint16 flags; /**< IOCTL command flags */ |
|---|
| 285 | + int16 min_len; /**< IOCTL command minimum argument len (in bytes) */ |
|---|
| 286 | +} wlc_ioctl_cmd_t; |
|---|
| 287 | + |
|---|
| 320 | 288 | #if defined(WLTINYDUMP) || defined(WLMSG_INFORM) || defined(WLMSG_ASSOC) || \ |
|---|
| 321 | 289 | defined(WLMSG_PRPKT) || defined(WLMSG_WSEC) |
|---|
| 322 | 290 | extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len); |
|---|
| 323 | | -#endif |
|---|
| 291 | +#endif // endif |
|---|
| 324 | 292 | #endif /* BCMDRIVER */ |
|---|
| 293 | + |
|---|
| 294 | +/* string */ |
|---|
| 295 | +extern int bcm_atoi(const char *s); |
|---|
| 296 | +extern ulong bcm_strtoul(const char *cp, char **endp, uint base); |
|---|
| 297 | +extern uint64 bcm_strtoull(const char *cp, char **endp, uint base); |
|---|
| 298 | +extern char *bcmstrstr(const char *haystack, const char *needle); |
|---|
| 299 | +extern char *bcmstrnstr(const char *s, uint s_len, const char *substr, uint substr_len); |
|---|
| 300 | +extern char *bcmstrcat(char *dest, const char *src); |
|---|
| 301 | +extern char *bcmstrncat(char *dest, const char *src, uint size); |
|---|
| 302 | +extern ulong wchar2ascii(char *abuf, ushort *wbuf, ushort wbuflen, ulong abuflen); |
|---|
| 303 | +char* bcmstrtok(char **string, const char *delimiters, char *tokdelim); |
|---|
| 304 | +int bcmstricmp(const char *s1, const char *s2); |
|---|
| 305 | +int bcmstrnicmp(const char* s1, const char* s2, int cnt); |
|---|
| 325 | 306 | |
|---|
| 326 | 307 | /* Base type definitions */ |
|---|
| 327 | 308 | #define IOVT_VOID 0 /* no value (implictly set only) */ |
|---|
| .. | .. |
|---|
| 359 | 340 | |
|---|
| 360 | 341 | /* ** driver/apps-shared section ** */ |
|---|
| 361 | 342 | |
|---|
| 362 | | -#define BCME_STRLEN 64 /* Max string length for BCM errors */ |
|---|
| 363 | | -#define VALID_BCMERROR(e) ((e <= 0) && (e >= BCME_LAST)) |
|---|
| 343 | +#define BCME_STRLEN 64 /* Max string length for BCM errors */ |
|---|
| 344 | +#define VALID_BCMERROR(e) valid_bcmerror(e) |
|---|
| 364 | 345 | |
|---|
| 346 | +#ifdef DBG_BUS |
|---|
| 347 | +/** tracks non typical execution paths, use gdb with arm sim + firmware dump to read counters */ |
|---|
| 348 | +#define DBG_BUS_INC(s, cnt) ((s)->dbg_bus->cnt++) |
|---|
| 349 | +#else |
|---|
| 350 | +#define DBG_BUS_INC(s, cnt) |
|---|
| 351 | +#endif /* DBG_BUS */ |
|---|
| 365 | 352 | |
|---|
| 366 | 353 | /* |
|---|
| 367 | 354 | * error codes could be added but the defined ones shouldn't be changed/deleted |
|---|
| .. | .. |
|---|
| 413 | 400 | #define BCME_RXFAIL -39 /* RX failure */ |
|---|
| 414 | 401 | #define BCME_NODEVICE -40 /* Device not present */ |
|---|
| 415 | 402 | #define BCME_NMODE_DISABLED -41 /* NMODE disabled */ |
|---|
| 416 | | -#define BCME_NONRESIDENT -42 /* access to nonresident overlay */ |
|---|
| 403 | +#define BCME_HOFFLOAD_RESIDENT -42 /* offload resident */ |
|---|
| 417 | 404 | #define BCME_SCANREJECT -43 /* reject scan request */ |
|---|
| 418 | 405 | #define BCME_USAGE_ERROR -44 /* WLCMD usage error */ |
|---|
| 419 | 406 | #define BCME_IOCTL_ERROR -45 /* WLCMD ioctl error */ |
|---|
| .. | .. |
|---|
| 425 | 412 | #define BCME_REPLAY -51 /* Replay */ |
|---|
| 426 | 413 | #define BCME_IE_NOTFOUND -52 /* IE not found */ |
|---|
| 427 | 414 | #define BCME_DATA_NOTFOUND -53 /* Complete data not found in buffer */ |
|---|
| 428 | | -#define BCME_LAST BCME_DATA_NOTFOUND |
|---|
| 415 | +#define BCME_NOT_GC -54 /* expecting a group client */ |
|---|
| 416 | +#define BCME_PRS_REQ_FAILED -55 /* GC presence req failed to sent */ |
|---|
| 417 | +#define BCME_NO_P2P_SE -56 /* Could not find P2P-Subelement */ |
|---|
| 418 | +#define BCME_NOA_PND -57 /* NoA pending, CB shuld be NULL */ |
|---|
| 419 | +#define BCME_FRAG_Q_FAILED -58 /* queueing 80211 frag failedi */ |
|---|
| 420 | +#define BCME_GET_AF_FAILED -59 /* Get p2p AF pkt failed */ |
|---|
| 421 | +#define BCME_MSCH_NOTREADY -60 /* scheduler not ready */ |
|---|
| 422 | +#define BCME_IOV_LAST_CMD -61 /* last batched iov sub-command */ |
|---|
| 423 | +#define BCME_MINIPMU_CAL_FAIL -62 /* MiniPMU cal failed */ |
|---|
| 424 | +#define BCME_RCAL_FAIL -63 /* Rcal failed */ |
|---|
| 425 | +#define BCME_LPF_RCCAL_FAIL -64 /* RCCAL failed */ |
|---|
| 426 | +#define BCME_DACBUF_RCCAL_FAIL -65 /* RCCAL failed */ |
|---|
| 427 | +#define BCME_VCOCAL_FAIL -66 /* VCOCAL failed */ |
|---|
| 428 | +#define BCME_BANDLOCKED -67 /* interface is restricted to a band */ |
|---|
| 429 | +#define BCME_DNGL_DEVRESET -68 /* dongle re-attach during DEVRESET */ |
|---|
| 430 | +#define BCME_LAST BCME_DNGL_DEVRESET |
|---|
| 429 | 431 | |
|---|
| 430 | 432 | #define BCME_NOTENABLED BCME_DISABLED |
|---|
| 433 | + |
|---|
| 434 | +/* This error code is *internal* to the driver, and is not propogated to users. It should |
|---|
| 435 | + * only be used by IOCTL patch handlers as an indication that it did not handle the IOCTL. |
|---|
| 436 | + * (Since the error code is internal, an entry in 'BCMERRSTRINGTABLE' is not required, |
|---|
| 437 | + * nor does it need to be part of any OSL driver-to-OS error code mapping). |
|---|
| 438 | + */ |
|---|
| 439 | +#define BCME_IOCTL_PATCH_UNSUPPORTED -9999 |
|---|
| 440 | +#if (BCME_LAST <= BCME_IOCTL_PATCH_UNSUPPORTED) |
|---|
| 441 | + #error "BCME_LAST <= BCME_IOCTL_PATCH_UNSUPPORTED" |
|---|
| 442 | +#endif // endif |
|---|
| 431 | 443 | |
|---|
| 432 | 444 | /* These are collection of BCME Error strings */ |
|---|
| 433 | 445 | #define BCMERRSTRINGTABLE { \ |
|---|
| .. | .. |
|---|
| 473 | 485 | "RX Failure", \ |
|---|
| 474 | 486 | "Device Not Present", \ |
|---|
| 475 | 487 | "NMODE Disabled", \ |
|---|
| 476 | | - "Nonresident overlay access", \ |
|---|
| 488 | + "Host Offload in device", \ |
|---|
| 477 | 489 | "Scan Rejected", \ |
|---|
| 478 | 490 | "WLCMD usage error", \ |
|---|
| 479 | 491 | "WLCMD ioctl error", \ |
|---|
| .. | .. |
|---|
| 485 | 497 | "Replay", \ |
|---|
| 486 | 498 | "IE not found", \ |
|---|
| 487 | 499 | "Data not found", \ |
|---|
| 500 | + "NOT GC", \ |
|---|
| 501 | + "PRS REQ FAILED", \ |
|---|
| 502 | + "NO P2P SubElement", \ |
|---|
| 503 | + "NOA Pending", \ |
|---|
| 504 | + "FRAG Q FAILED", \ |
|---|
| 505 | + "GET ActionFrame failed", \ |
|---|
| 506 | + "scheduler not ready", \ |
|---|
| 507 | + "Last IOV batched sub-cmd", \ |
|---|
| 508 | + "Mini PMU Cal failed", \ |
|---|
| 509 | + "R-cal failed", \ |
|---|
| 510 | + "LPF RC Cal failed", \ |
|---|
| 511 | + "DAC buf RC Cal failed", \ |
|---|
| 512 | + "VCO Cal failed", \ |
|---|
| 513 | + "band locked", \ |
|---|
| 514 | + "Dongle Devreset", \ |
|---|
| 488 | 515 | } |
|---|
| 489 | 516 | |
|---|
| 490 | 517 | #ifndef ABS |
|---|
| .. | .. |
|---|
| 549 | 576 | #endif /* __ARMCC_VERSION */ |
|---|
| 550 | 577 | #endif /* OFFSETOF */ |
|---|
| 551 | 578 | |
|---|
| 579 | +#ifndef CONTAINEROF |
|---|
| 580 | +#define CONTAINEROF(ptr, type, member) ((type *)((char *)(ptr) - OFFSETOF(type, member))) |
|---|
| 581 | +#endif /* CONTAINEROF */ |
|---|
| 582 | + |
|---|
| 583 | +/* substruct size up to and including a member of the struct */ |
|---|
| 584 | +#ifndef STRUCT_SIZE_THROUGH |
|---|
| 585 | +#define STRUCT_SIZE_THROUGH(sptr, fname) \ |
|---|
| 586 | + (((uint8*)&((sptr)->fname) - (uint8*)(sptr)) + sizeof((sptr)->fname)) |
|---|
| 587 | +#endif // endif |
|---|
| 588 | + |
|---|
| 589 | +/* Extracting the size of element in a structure */ |
|---|
| 590 | +#define SIZE_OF(type, field) sizeof(((type *)0)->field) |
|---|
| 591 | + |
|---|
| 552 | 592 | #ifndef ARRAYSIZE |
|---|
| 553 | | -#define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0])) |
|---|
| 554 | | -#endif |
|---|
| 593 | +#define ARRAYSIZE(a) (uint32)(sizeof(a) / sizeof(a[0])) |
|---|
| 594 | +#endif // endif |
|---|
| 555 | 595 | |
|---|
| 556 | 596 | #ifndef ARRAYLAST /* returns pointer to last array element */ |
|---|
| 557 | 597 | #define ARRAYLAST(a) (&a[ARRAYSIZE(a)-1]) |
|---|
| 558 | | -#endif |
|---|
| 598 | +#endif // endif |
|---|
| 599 | + |
|---|
| 600 | +/* Calculates the required pad size. This is mainly used in register structures */ |
|---|
| 601 | +#define PADSZ(start, end) ((((end) - (start)) / 4) + 1) |
|---|
| 559 | 602 | |
|---|
| 560 | 603 | /* Reference a function; used to prevent a static function from being optimized out */ |
|---|
| 561 | 604 | extern void *_bcmutils_dummy_fn; |
|---|
| .. | .. |
|---|
| 576 | 619 | #define clrbit(a, i) (((uint8 *)a)[(i) / NBBY] &= ~(1 << ((i) % NBBY))) |
|---|
| 577 | 620 | #define isset(a, i) (((const uint8 *)a)[(i) / NBBY] & (1 << ((i) % NBBY))) |
|---|
| 578 | 621 | #define isclr(a, i) ((((const uint8 *)a)[(i) / NBBY] & (1 << ((i) % NBBY))) == 0) |
|---|
| 579 | | -#endif |
|---|
| 622 | +#endif // endif |
|---|
| 580 | 623 | #endif /* setbit */ |
|---|
| 624 | + |
|---|
| 625 | +/* read/write/clear field in a consecutive bits in an octet array. |
|---|
| 626 | + * 'addr' is the octet array's start byte address |
|---|
| 627 | + * 'size' is the octet array's byte size |
|---|
| 628 | + * 'stbit' is the value's start bit offset |
|---|
| 629 | + * 'nbits' is the value's bit size |
|---|
| 630 | + * This set of utilities are for convenience. Don't use them |
|---|
| 631 | + * in time critical/data path as there's a great overhead in them. |
|---|
| 632 | + */ |
|---|
| 633 | +void setbits(uint8 *addr, uint size, uint stbit, uint nbits, uint32 val); |
|---|
| 634 | +uint32 getbits(const uint8 *addr, uint size, uint stbit, uint nbits); |
|---|
| 635 | +#define clrbits(addr, size, stbit, nbits) setbits(addr, size, stbit, nbits, 0) |
|---|
| 636 | + |
|---|
| 581 | 637 | extern void set_bitrange(void *array, uint start, uint end, uint maxbit); |
|---|
| 638 | +extern int bcm_find_fsb(uint32 num); |
|---|
| 582 | 639 | |
|---|
| 583 | 640 | #define isbitset(a, i) (((a) & (1 << (i))) != 0) |
|---|
| 584 | 641 | |
|---|
| .. | .. |
|---|
| 616 | 673 | return ((*a >> pos) & MSK); \ |
|---|
| 617 | 674 | } |
|---|
| 618 | 675 | |
|---|
| 619 | | -DECLARE_MAP_API(2, 4, 1, 15U, 0x0003) /* setbit2() and getbit2() */ |
|---|
| 620 | | -DECLARE_MAP_API(4, 3, 2, 7U, 0x000F) /* setbit4() and getbit4() */ |
|---|
| 621 | | -DECLARE_MAP_API(8, 2, 3, 3U, 0x00FF) /* setbit8() and getbit8() */ |
|---|
| 676 | +DECLARE_MAP_API(2, 4, 1, 15U, 0x0003U) /* setbit2() and getbit2() */ |
|---|
| 677 | +DECLARE_MAP_API(4, 3, 2, 7U, 0x000FU) /* setbit4() and getbit4() */ |
|---|
| 678 | +DECLARE_MAP_API(8, 2, 3, 3U, 0x00FFU) /* setbit8() and getbit8() */ |
|---|
| 622 | 679 | |
|---|
| 623 | 680 | /* basic mux operation - can be optimized on several architectures */ |
|---|
| 624 | 681 | #define MUX(pred, true, false) ((pred) ? (true) : (false)) |
|---|
| .. | .. |
|---|
| 658 | 715 | ((struct ether_addr *) (ea))->octet[4], \ |
|---|
| 659 | 716 | ((struct ether_addr *) (ea))->octet[5] |
|---|
| 660 | 717 | |
|---|
| 661 | | -#define ETHER_TO_MACF(ea) (ea).octet[0], \ |
|---|
| 718 | +#define CONST_ETHERP_TO_MACF(ea) ((const struct ether_addr *) (ea))->octet[0], \ |
|---|
| 719 | + ((const struct ether_addr *) (ea))->octet[1], \ |
|---|
| 720 | + ((const struct ether_addr *) (ea))->octet[2], \ |
|---|
| 721 | + ((const struct ether_addr *) (ea))->octet[3], \ |
|---|
| 722 | + ((const struct ether_addr *) (ea))->octet[4], \ |
|---|
| 723 | + ((const struct ether_addr *) (ea))->octet[5] |
|---|
| 724 | +#define ETHER_TO_MACF(ea) (ea).octet[0], \ |
|---|
| 662 | 725 | (ea).octet[1], \ |
|---|
| 663 | 726 | (ea).octet[2], \ |
|---|
| 664 | 727 | (ea).octet[3], \ |
|---|
| .. | .. |
|---|
| 666 | 729 | (ea).octet[5] |
|---|
| 667 | 730 | #if !defined(SIMPLE_MAC_PRINT) |
|---|
| 668 | 731 | #define MACDBG "%02x:%02x:%02x:%02x:%02x:%02x" |
|---|
| 669 | | -#define MAC2STRDBG(ea) (ea)[0], (ea)[1], (ea)[2], (ea)[3], (ea)[4], (ea)[5] |
|---|
| 732 | +#define MAC2STRDBG(ea) CONST_ETHERP_TO_MACF(ea) |
|---|
| 670 | 733 | #else |
|---|
| 671 | | -#define MACDBG "%02x:%02x:%02x" |
|---|
| 672 | | -#define MAC2STRDBG(ea) (ea)[0], (ea)[4], (ea)[5] |
|---|
| 734 | +#define MACDBG "%02x:xx:xx:xx:x%x:%02x" |
|---|
| 735 | +#define MAC2STRDBG(ea) ((uint8*)(ea))[0], (((uint8*)(ea))[4] & 0xf), ((uint8*)(ea))[5] |
|---|
| 673 | 736 | #endif /* SIMPLE_MAC_PRINT */ |
|---|
| 737 | + |
|---|
| 738 | +#define MACOUIDBG "%02x:%x:%02x" |
|---|
| 739 | +#define MACOUI2STRDBG(ea) ((uint8*)(ea))[0], ((uint8*)(ea))[1] & 0xf, ((uint8*)(ea))[2] |
|---|
| 740 | + |
|---|
| 741 | +#define MACOUI "%02x:%02x:%02x" |
|---|
| 742 | +#define MACOUI2STR(ea) ((uint8*)(ea))[0], ((uint8*)(ea))[1], ((uint8*)(ea))[2] |
|---|
| 674 | 743 | |
|---|
| 675 | 744 | /* bcm_format_flags() bit description structure */ |
|---|
| 676 | 745 | typedef struct bcm_bit_desc { |
|---|
| .. | .. |
|---|
| 705 | 774 | if ( |
|---|
| 706 | 775 | #ifdef __i386__ |
|---|
| 707 | 776 | 1 || |
|---|
| 708 | | -#endif |
|---|
| 777 | +#endif // endif |
|---|
| 709 | 778 | (((uintptr)src1 | (uintptr)src2 | (uintptr)dst) & 3) == 0) { |
|---|
| 710 | 779 | /* ARM CM3 rel time: 1229 (727 if alignment check could be omitted) */ |
|---|
| 711 | 780 | /* x86 supports unaligned. This version runs 6x-9x faster on x86. */ |
|---|
| .. | .. |
|---|
| 723 | 792 | |
|---|
| 724 | 793 | /* externs */ |
|---|
| 725 | 794 | /* crc */ |
|---|
| 726 | | -extern uint8 hndcrc8(uint8 *p, uint nbytes, uint8 crc); |
|---|
| 727 | | -extern uint16 hndcrc16(uint8 *p, uint nbytes, uint16 crc); |
|---|
| 728 | | -extern uint32 hndcrc32(uint8 *p, uint nbytes, uint32 crc); |
|---|
| 795 | +uint8 hndcrc8(const uint8 *p, uint nbytes, uint8 crc); |
|---|
| 796 | +uint16 hndcrc16(const uint8 *p, uint nbytes, uint16 crc); |
|---|
| 797 | +uint32 hndcrc32(const uint8 *p, uint nbytes, uint32 crc); |
|---|
| 729 | 798 | |
|---|
| 730 | 799 | /* format/print */ |
|---|
| 731 | 800 | #if defined(DHD_DEBUG) || defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || \ |
|---|
| .. | .. |
|---|
| 734 | 803 | extern int bcm_format_field(const bcm_bit_desc_ex_t *bd, uint32 field, char* buf, int len); |
|---|
| 735 | 804 | /* print out which bits in flags are set */ |
|---|
| 736 | 805 | extern int bcm_format_flags(const bcm_bit_desc_t *bd, uint32 flags, char* buf, int len); |
|---|
| 737 | | -#endif |
|---|
| 806 | +/* print out whcih bits in octet array 'addr' are set. bcm_bit_desc_t:bit is a bit offset. */ |
|---|
| 807 | +int bcm_format_octets(const bcm_bit_desc_t *bd, uint bdsz, |
|---|
| 808 | + const uint8 *addr, uint size, char *buf, int len); |
|---|
| 809 | +#endif // endif |
|---|
| 738 | 810 | |
|---|
| 739 | 811 | extern int bcm_format_hex(char *str, const void *bytes, int len); |
|---|
| 740 | 812 | |
|---|
| .. | .. |
|---|
| 742 | 814 | extern char *bcm_chipname(uint chipid, char *buf, uint len); |
|---|
| 743 | 815 | extern char *bcm_brev_str(uint32 brev, char *buf); |
|---|
| 744 | 816 | extern void printbig(char *buf); |
|---|
| 745 | | -extern void prhex(const char *msg, uchar *buf, uint len); |
|---|
| 746 | | - |
|---|
| 747 | | -/* IE parsing */ |
|---|
| 748 | | - |
|---|
| 749 | | -/* packing is required if struct is passed across the bus */ |
|---|
| 750 | | -#include <packed_section_start.h> |
|---|
| 751 | | -/* tag_ID/length/value_buffer tuple */ |
|---|
| 752 | | -typedef struct bcm_tlv { |
|---|
| 753 | | - uint8 id; |
|---|
| 754 | | - uint8 len; |
|---|
| 755 | | - uint8 data[1]; |
|---|
| 756 | | -} bcm_tlv_t; |
|---|
| 757 | | - |
|---|
| 758 | | -/* bcm tlv w/ 16 bit id/len */ |
|---|
| 759 | | -typedef BWL_PRE_PACKED_STRUCT struct bcm_xtlv { |
|---|
| 760 | | - uint16 id; |
|---|
| 761 | | - uint16 len; |
|---|
| 762 | | - uint8 data[1]; |
|---|
| 763 | | -} BWL_POST_PACKED_STRUCT bcm_xtlv_t; |
|---|
| 764 | | -#include <packed_section_end.h> |
|---|
| 765 | | - |
|---|
| 766 | | - |
|---|
| 767 | | -/* descriptor of xtlv data src or dst */ |
|---|
| 768 | | -typedef struct { |
|---|
| 769 | | - uint16 type; |
|---|
| 770 | | - uint16 len; |
|---|
| 771 | | - void *ptr; /* ptr to memory location */ |
|---|
| 772 | | -} xtlv_desc_t; |
|---|
| 773 | | - |
|---|
| 774 | | -/* xtlv options */ |
|---|
| 775 | | -#define BCM_XTLV_OPTION_NONE 0x0000 |
|---|
| 776 | | -#define BCM_XTLV_OPTION_ALIGN32 0x0001 |
|---|
| 777 | | - |
|---|
| 778 | | -typedef uint16 bcm_xtlv_opts_t; |
|---|
| 779 | | -struct bcm_xtlvbuf { |
|---|
| 780 | | - bcm_xtlv_opts_t opts; |
|---|
| 781 | | - uint16 size; |
|---|
| 782 | | - uint8 *head; /* point to head of buffer */ |
|---|
| 783 | | - uint8 *buf; /* current position of buffer */ |
|---|
| 784 | | - /* allocated buffer may follow, but not necessarily */ |
|---|
| 785 | | -}; |
|---|
| 786 | | -typedef struct bcm_xtlvbuf bcm_xtlvbuf_t; |
|---|
| 787 | | - |
|---|
| 788 | | -#define BCM_TLV_MAX_DATA_SIZE (255) |
|---|
| 789 | | -#define BCM_XTLV_MAX_DATA_SIZE (65535) |
|---|
| 790 | | -#define BCM_TLV_HDR_SIZE (OFFSETOF(bcm_tlv_t, data)) |
|---|
| 791 | | - |
|---|
| 792 | | -#define BCM_XTLV_HDR_SIZE (OFFSETOF(bcm_xtlv_t, data)) |
|---|
| 793 | | -/* LEN only stores the value's length without padding */ |
|---|
| 794 | | -#define BCM_XTLV_LEN(elt) ltoh16_ua(&(elt->len)) |
|---|
| 795 | | -#define BCM_XTLV_ID(elt) ltoh16_ua(&(elt->id)) |
|---|
| 796 | | -/* entire size of the XTLV including header, data, and optional padding */ |
|---|
| 797 | | -#define BCM_XTLV_SIZE(elt, opts) bcm_xtlv_size(elt, opts) |
|---|
| 798 | | -#define bcm_valid_xtlv(elt, buflen, opts) (elt && ((int)(buflen) >= (int)BCM_XTLV_SIZE(elt, opts))) |
|---|
| 799 | | - |
|---|
| 800 | | -/* Check that bcm_tlv_t fits into the given buflen */ |
|---|
| 801 | | -#define bcm_valid_tlv(elt, buflen) (\ |
|---|
| 802 | | - ((int)(buflen) >= (int)BCM_TLV_HDR_SIZE) && \ |
|---|
| 803 | | - ((int)(buflen) >= (int)(BCM_TLV_HDR_SIZE + (elt)->len))) |
|---|
| 804 | | - |
|---|
| 805 | | - |
|---|
| 806 | | -extern bcm_tlv_t *bcm_next_tlv(bcm_tlv_t *elt, int *buflen); |
|---|
| 807 | | -extern bcm_tlv_t *bcm_parse_tlvs(void *buf, int buflen, uint key); |
|---|
| 808 | | -extern bcm_tlv_t *bcm_parse_tlvs_min_bodylen(void *buf, int buflen, uint key, int min_bodylen); |
|---|
| 809 | | - |
|---|
| 810 | | -extern bcm_tlv_t *bcm_parse_ordered_tlvs(void *buf, int buflen, uint key); |
|---|
| 811 | | - |
|---|
| 812 | | -extern bcm_tlv_t *bcm_find_vendor_ie(void *tlvs, int tlvs_len, const char *voui, uint8 *type, |
|---|
| 813 | | - int type_len); |
|---|
| 814 | | - |
|---|
| 815 | | -extern uint8 *bcm_write_tlv(int type, const void *data, int datalen, uint8 *dst); |
|---|
| 816 | | -extern uint8 *bcm_write_tlv_safe(int type, const void *data, int datalen, uint8 *dst, |
|---|
| 817 | | - int dst_maxlen); |
|---|
| 818 | | - |
|---|
| 819 | | -extern uint8 *bcm_copy_tlv(const void *src, uint8 *dst); |
|---|
| 820 | | -extern uint8 *bcm_copy_tlv_safe(const void *src, uint8 *dst, int dst_maxlen); |
|---|
| 821 | | - |
|---|
| 822 | | -/* xtlv */ |
|---|
| 823 | | - |
|---|
| 824 | | -/* return the next xtlv element, and update buffer len (remaining). Buffer length |
|---|
| 825 | | - * updated includes padding as specified by options |
|---|
| 826 | | - */ |
|---|
| 827 | | -extern bcm_xtlv_t *bcm_next_xtlv(bcm_xtlv_t *elt, int *buflen, bcm_xtlv_opts_t opts); |
|---|
| 828 | | - |
|---|
| 829 | | -/* initialize an xtlv buffer. Use options specified for packing/unpacking using |
|---|
| 830 | | - * the buffer. Caller is responsible for allocating both buffers. |
|---|
| 831 | | - */ |
|---|
| 832 | | -extern int bcm_xtlv_buf_init(bcm_xtlvbuf_t *tlv_buf, uint8 *buf, uint16 len, |
|---|
| 833 | | - bcm_xtlv_opts_t opts); |
|---|
| 834 | | - |
|---|
| 835 | | -extern uint16 bcm_xtlv_buf_len(struct bcm_xtlvbuf *tbuf); |
|---|
| 836 | | -extern uint16 bcm_xtlv_buf_rlen(struct bcm_xtlvbuf *tbuf); |
|---|
| 837 | | -extern uint8 *bcm_xtlv_buf(struct bcm_xtlvbuf *tbuf); |
|---|
| 838 | | -extern uint8 *bcm_xtlv_head(struct bcm_xtlvbuf *tbuf); |
|---|
| 839 | | -extern int bcm_xtlv_put_data(bcm_xtlvbuf_t *tbuf, uint16 type, const void *data, uint16 dlen); |
|---|
| 840 | | -extern int bcm_xtlv_put_8(bcm_xtlvbuf_t *tbuf, uint16 type, const int8 data); |
|---|
| 841 | | -extern int bcm_xtlv_put_16(bcm_xtlvbuf_t *tbuf, uint16 type, const int16 data); |
|---|
| 842 | | -extern int bcm_xtlv_put_32(bcm_xtlvbuf_t *tbuf, uint16 type, const int32 data); |
|---|
| 843 | | -extern int bcm_unpack_xtlv_entry(uint8 **buf, uint16 xpct_type, uint16 xpct_len, |
|---|
| 844 | | - void *dst, bcm_xtlv_opts_t opts); |
|---|
| 845 | | -extern int bcm_pack_xtlv_entry(uint8 **buf, uint16 *buflen, uint16 type, uint16 len, |
|---|
| 846 | | - void *src, bcm_xtlv_opts_t opts); |
|---|
| 847 | | -extern int bcm_xtlv_size(const bcm_xtlv_t *elt, bcm_xtlv_opts_t opts); |
|---|
| 848 | | - |
|---|
| 849 | | -/* callback for unpacking xtlv from a buffer into context. */ |
|---|
| 850 | | -typedef int (bcm_xtlv_unpack_cbfn_t)(void *ctx, uint8 *buf, uint16 type, uint16 len); |
|---|
| 851 | | - |
|---|
| 852 | | -/* unpack a tlv buffer using buffer, options, and callback */ |
|---|
| 853 | | -extern int bcm_unpack_xtlv_buf(void *ctx, uint8 *buf, uint16 buflen, |
|---|
| 854 | | - bcm_xtlv_opts_t opts, bcm_xtlv_unpack_cbfn_t *cbfn); |
|---|
| 855 | | - |
|---|
| 856 | | -/* unpack a set of tlvs from the buffer using provided xtlv desc */ |
|---|
| 857 | | -extern int bcm_unpack_xtlv_buf_to_mem(void *buf, int *buflen, xtlv_desc_t *items, |
|---|
| 858 | | - bcm_xtlv_opts_t opts); |
|---|
| 859 | | - |
|---|
| 860 | | -/* pack a set of tlvs into buffer using provided xtlv desc */ |
|---|
| 861 | | -extern int bcm_pack_xtlv_buf_from_mem(void **buf, uint16 *buflen, xtlv_desc_t *items, |
|---|
| 862 | | - bcm_xtlv_opts_t opts); |
|---|
| 863 | | - |
|---|
| 864 | | -/* return data pointer of a given ID from xtlv buffer |
|---|
| 865 | | - * xtlv data length is given to *datalen_out, if the pointer is valid |
|---|
| 866 | | - */ |
|---|
| 867 | | -extern void *bcm_get_data_from_xtlv_buf(uint8 *tlv_buf, uint16 buflen, uint16 id, |
|---|
| 868 | | - uint16 *datalen_out, bcm_xtlv_opts_t opts); |
|---|
| 869 | | - |
|---|
| 870 | | -/* callback to return next tlv id and len to pack, if there is more tlvs to come and |
|---|
| 871 | | - * options e.g. alignment |
|---|
| 872 | | - */ |
|---|
| 873 | | -typedef bool (*bcm_pack_xtlv_next_info_cbfn_t)(void *ctx, uint16 *tlv_id, uint16 *tlv_len); |
|---|
| 874 | | - |
|---|
| 875 | | -/* callback to pack the tlv into length validated buffer */ |
|---|
| 876 | | -typedef void (*bcm_pack_xtlv_pack_next_cbfn_t)(void *ctx, |
|---|
| 877 | | - uint16 tlv_id, uint16 tlv_len, uint8* buf); |
|---|
| 878 | | - |
|---|
| 879 | | -/* pack a set of tlvs into buffer using get_next to interate */ |
|---|
| 880 | | -int bcm_pack_xtlv_buf(void *ctx, void *tlv_buf, uint16 buflen, |
|---|
| 881 | | - bcm_xtlv_opts_t opts, bcm_pack_xtlv_next_info_cbfn_t get_next, |
|---|
| 882 | | - bcm_pack_xtlv_pack_next_cbfn_t pack_next, int *outlen); |
|---|
| 817 | +extern void prhex(const char *msg, const uchar *buf, uint len); |
|---|
| 883 | 818 | |
|---|
| 884 | 819 | /* bcmerror */ |
|---|
| 885 | 820 | extern const char *bcmerrorstr(int bcmerror); |
|---|
| .. | .. |
|---|
| 913 | 848 | char *buf, uint32 bufsize); |
|---|
| 914 | 849 | extern uint bcm_bitcount(uint8 *bitmap, uint bytelength); |
|---|
| 915 | 850 | |
|---|
| 916 | | -extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...); |
|---|
| 851 | +extern int bcm_bprintf(struct bcmstrbuf *b, const char *fmt, ...) |
|---|
| 852 | + __attribute__ ((format (__printf__, 2, 0))); |
|---|
| 917 | 853 | |
|---|
| 918 | 854 | /* power conversion */ |
|---|
| 919 | 855 | extern uint16 bcm_qdbm_to_mw(uint8 qdbm); |
|---|
| 920 | 856 | extern uint8 bcm_mw_to_qdbm(uint16 mw); |
|---|
| 921 | | -extern uint bcm_mkiovar(const char *name, char *data, uint datalen, char *buf, uint len); |
|---|
| 857 | +extern uint bcm_mkiovar(const char *name, const char *data, uint datalen, char *buf, uint len); |
|---|
| 922 | 858 | |
|---|
| 923 | 859 | unsigned int process_nvram_vars(char *varbuf, unsigned int len); |
|---|
| 860 | +extern bool replace_nvram_variable(char *varbuf, unsigned int buflen, const char *variable, |
|---|
| 861 | + unsigned int *datalen); |
|---|
| 924 | 862 | |
|---|
| 925 | 863 | /* trace any object allocation / free, with / without features (flags) set to the object */ |
|---|
| 926 | 864 | |
|---|
| .. | .. |
|---|
| 966 | 904 | #define bcm_object_trace_deinit() |
|---|
| 967 | 905 | #endif /* BCM_OBJECT_TRACE */ |
|---|
| 968 | 906 | |
|---|
| 969 | | -/* calculate a * b + c */ |
|---|
| 970 | | -extern void bcm_uint64_multiple_add(uint32* r_high, uint32* r_low, uint32 a, uint32 b, uint32 c); |
|---|
| 971 | | -/* calculate a / b */ |
|---|
| 972 | | -extern void bcm_uint64_divide(uint32* r, uint32 a_high, uint32 a_low, uint32 b); |
|---|
| 973 | | - |
|---|
| 974 | | - |
|---|
| 975 | 907 | /* Public domain bit twiddling hacks/utilities: Sean Eron Anderson */ |
|---|
| 976 | 908 | |
|---|
| 977 | 909 | /* Table driven count set bits. */ |
|---|
| .. | .. |
|---|
| 992 | 924 | return (_CSBTBL[p[0]] + _CSBTBL[p[1]] + _CSBTBL[p[2]] + _CSBTBL[p[3]]); |
|---|
| 993 | 925 | } |
|---|
| 994 | 926 | |
|---|
| 995 | | - |
|---|
| 996 | 927 | static INLINE int /* C equivalent count of leading 0's in a u32 */ |
|---|
| 997 | 928 | C_bcm_count_leading_zeros(uint32 u32arg) |
|---|
| 998 | 929 | { |
|---|
| .. | .. |
|---|
| 1000 | 931 | while (u32arg) { |
|---|
| 1001 | 932 | shifts++; u32arg >>= 1; |
|---|
| 1002 | 933 | } |
|---|
| 1003 | | - return (32U - shifts); |
|---|
| 934 | + return (32 - shifts); |
|---|
| 1004 | 935 | } |
|---|
| 936 | + |
|---|
| 937 | +/* the format of current TCM layout during boot |
|---|
| 938 | + * |
|---|
| 939 | + * Code Unused memory Random numbers Random number Magic number NVRAM NVRAM |
|---|
| 940 | + * byte Count 0xFEEDC0DE Size |
|---|
| 941 | + * |<-----Variable---->|<---Variable--->|<-----4 bytes-->|<---4 bytes---->|<---V--->|<--4B--->| |
|---|
| 942 | + * |<------------- BCM_ENTROPY_HOST_MAXSIZE --------->| |
|---|
| 943 | + */ |
|---|
| 944 | + |
|---|
| 945 | +/* The HOST need to provided 64 bytes (512 bits) entropy for the bcm SW RNG */ |
|---|
| 946 | +#define BCM_ENTROPY_MAGIC_SIZE 4u |
|---|
| 947 | +#define BCM_ENTROPY_COUNT_SIZE 4u |
|---|
| 948 | +#define BCM_ENTROPY_MIN_NBYTES 64u |
|---|
| 949 | +#define BCM_ENTROPY_MAX_NBYTES 512u |
|---|
| 950 | +#define BCM_ENTROPY_HOST_NBYTES 128u |
|---|
| 951 | +#define BCM_ENTROPY_HOST_MAXSIZE \ |
|---|
| 952 | + (BCM_ENTROPY_MAGIC_SIZE + BCM_ENTROPY_COUNT_SIZE + BCM_ENTROPY_MAX_NBYTES) |
|---|
| 953 | + |
|---|
| 954 | +/* Keep BCM MAX_RAND NUMBERS definition for the current dongle image. It will be |
|---|
| 955 | + * removed after the dongle image is updated to use the bcm RNG. |
|---|
| 956 | + */ |
|---|
| 957 | +#define BCM_MAX_RAND_NUMBERS 2u |
|---|
| 958 | + |
|---|
| 959 | +/* Constant for calculate the location of host entropy input */ |
|---|
| 960 | +#define BCM_NVRAM_OFFSET_TCM 4u |
|---|
| 961 | +#define BCM_NVRAM_IMG_COMPRS_FACTOR 4u |
|---|
| 962 | +#define BCM_NVRAM_RNG_SIGNATURE 0xFEEDC0DEu |
|---|
| 963 | + |
|---|
| 964 | +typedef struct bcm_rand_metadata { |
|---|
| 965 | + uint32 count; /* number of random numbers in bytes */ |
|---|
| 966 | + uint32 signature; /* host fills it in, FW verfies before reading rand */ |
|---|
| 967 | +} bcm_rand_metadata_t; |
|---|
| 1005 | 968 | |
|---|
| 1006 | 969 | #ifdef BCMDRIVER |
|---|
| 1007 | 970 | /* |
|---|
| .. | .. |
|---|
| 1078 | 1041 | extern void bcm_mwbmap_audit(struct bcm_mwbmap * mwbmap_hdl); |
|---|
| 1079 | 1042 | /* End - Multiword bitmap based small Id allocator. */ |
|---|
| 1080 | 1043 | |
|---|
| 1081 | | - |
|---|
| 1082 | 1044 | /* INTERFACE: Simple unique 16bit Id Allocator using a stack implementation. */ |
|---|
| 1083 | 1045 | |
|---|
| 1084 | | -#define ID16_INVALID ((uint16)(~0)) |
|---|
| 1085 | | -#define ID16_UNDEFINED (ID16_INVALID) |
|---|
| 1046 | +#define ID8_INVALID 0xFFu |
|---|
| 1047 | +#define ID16_INVALID 0xFFFFu |
|---|
| 1048 | +#define ID32_INVALID 0xFFFFFFFFu |
|---|
| 1049 | +#define ID16_UNDEFINED ID16_INVALID |
|---|
| 1086 | 1050 | |
|---|
| 1087 | 1051 | /* |
|---|
| 1088 | 1052 | * Construct a 16bit id allocator, managing 16bit ids in the range: |
|---|
| .. | .. |
|---|
| 1108 | 1072 | /* End - Simple 16bit Id Allocator. */ |
|---|
| 1109 | 1073 | #endif /* BCMDRIVER */ |
|---|
| 1110 | 1074 | |
|---|
| 1111 | | -extern void bcm_uint64_right_shift(uint32* r, uint32 a_high, uint32 a_low, uint32 b); |
|---|
| 1075 | +#define MASK_32_BITS (~0) |
|---|
| 1076 | +#define MASK_8_BITS ((1 << 8) - 1) |
|---|
| 1112 | 1077 | |
|---|
| 1113 | | -void bcm_add_64(uint32* r_hi, uint32* r_lo, uint32 offset); |
|---|
| 1114 | | -void bcm_sub_64(uint32* r_hi, uint32* r_lo, uint32 offset); |
|---|
| 1115 | | -uint16 ipv4_hdr_cksum(uint8 *ip, int ip_len); |
|---|
| 1078 | +#define EXTRACT_LOW32(num) (uint32)(num & MASK_32_BITS) |
|---|
| 1079 | +#define EXTRACT_HIGH32(num) (uint32)(((uint64)num >> 32) & MASK_32_BITS) |
|---|
| 1080 | + |
|---|
| 1081 | +#define MAXIMUM(a, b) ((a > b) ? a : b) |
|---|
| 1082 | +#define MINIMUM(a, b) ((a < b) ? a : b) |
|---|
| 1083 | +#define LIMIT(x, min, max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x))) |
|---|
| 1116 | 1084 | |
|---|
| 1117 | 1085 | /* calculate checksum for ip header, tcp / udp header / data */ |
|---|
| 1118 | 1086 | uint16 bcm_ip_cksum(uint8 *buf, uint32 len, uint32 sum); |
|---|
| .. | .. |
|---|
| 1186 | 1154 | return list_p->next_p; |
|---|
| 1187 | 1155 | } |
|---|
| 1188 | 1156 | |
|---|
| 1189 | | - |
|---|
| 1190 | 1157 | static INLINE dll_t * |
|---|
| 1191 | 1158 | dll_tail_p(dll_t *list_p) |
|---|
| 1192 | 1159 | { |
|---|
| 1193 | 1160 | return (list_p)->prev_p; |
|---|
| 1194 | 1161 | } |
|---|
| 1195 | | - |
|---|
| 1196 | 1162 | |
|---|
| 1197 | 1163 | static INLINE dll_t * |
|---|
| 1198 | 1164 | dll_next_p(dll_t *node_p) |
|---|
| .. | .. |
|---|
| 1200 | 1166 | return (node_p)->next_p; |
|---|
| 1201 | 1167 | } |
|---|
| 1202 | 1168 | |
|---|
| 1203 | | - |
|---|
| 1204 | 1169 | static INLINE dll_t * |
|---|
| 1205 | 1170 | dll_prev_p(dll_t *node_p) |
|---|
| 1206 | 1171 | { |
|---|
| 1207 | 1172 | return (node_p)->prev_p; |
|---|
| 1208 | 1173 | } |
|---|
| 1209 | | - |
|---|
| 1210 | 1174 | |
|---|
| 1211 | 1175 | static INLINE bool |
|---|
| 1212 | 1176 | dll_empty(dll_t *list_p) |
|---|
| .. | .. |
|---|
| 1214 | 1178 | return ((list_p)->next_p == (list_p)); |
|---|
| 1215 | 1179 | } |
|---|
| 1216 | 1180 | |
|---|
| 1217 | | - |
|---|
| 1218 | 1181 | static INLINE bool |
|---|
| 1219 | 1182 | dll_end(dll_t *list_p, dll_t * node_p) |
|---|
| 1220 | 1183 | { |
|---|
| 1221 | 1184 | return (list_p == node_p); |
|---|
| 1222 | 1185 | } |
|---|
| 1223 | | - |
|---|
| 1224 | 1186 | |
|---|
| 1225 | 1187 | /* inserts the node new_p "after" the node at_p */ |
|---|
| 1226 | 1188 | static INLINE void |
|---|
| .. | .. |
|---|
| 1243 | 1205 | { |
|---|
| 1244 | 1206 | dll_insert(node_p, list_p); |
|---|
| 1245 | 1207 | } |
|---|
| 1246 | | - |
|---|
| 1247 | 1208 | |
|---|
| 1248 | 1209 | /* deletes a node from any list that it "may" be in, if at all. */ |
|---|
| 1249 | 1210 | static INLINE void |
|---|
| .. | .. |
|---|
| 1271 | 1232 | typedef void (* dll_elem_dump)(void * elem_p); |
|---|
| 1272 | 1233 | void dll_pool_detach(void * osh, dll_pool_t * pool, uint16 elems_max, uint16 elem_size); |
|---|
| 1273 | 1234 | |
|---|
| 1235 | +int valid_bcmerror(int e); |
|---|
| 1236 | + |
|---|
| 1237 | +/* calculate IPv4 header checksum |
|---|
| 1238 | + * - input ip points to IP header in network order |
|---|
| 1239 | + * - output cksum is in network order |
|---|
| 1240 | + */ |
|---|
| 1241 | +uint16 ipv4_hdr_cksum(uint8 *ip, int ip_len); |
|---|
| 1242 | + |
|---|
| 1243 | +/* calculate IPv4 TCP header checksum |
|---|
| 1244 | + * - input ip and tcp points to IP and TCP header in network order |
|---|
| 1245 | + * - output cksum is in network order |
|---|
| 1246 | + */ |
|---|
| 1247 | +uint16 ipv4_tcp_hdr_cksum(uint8 *ip, uint8 *tcp, uint16 tcp_len); |
|---|
| 1248 | + |
|---|
| 1249 | +/* calculate IPv6 TCP header checksum |
|---|
| 1250 | + * - input ipv6 and tcp points to IPv6 and TCP header in network order |
|---|
| 1251 | + * - output cksum is in network order |
|---|
| 1252 | + */ |
|---|
| 1253 | +uint16 ipv6_tcp_hdr_cksum(uint8 *ipv6, uint8 *tcp, uint16 tcp_len); |
|---|
| 1254 | + |
|---|
| 1274 | 1255 | #ifdef __cplusplus |
|---|
| 1275 | 1256 | } |
|---|
| 1276 | | -#endif |
|---|
| 1257 | +#endif // endif |
|---|
| 1277 | 1258 | |
|---|
| 1278 | 1259 | /* #define DEBUG_COUNTER */ |
|---|
| 1279 | 1260 | #ifdef DEBUG_COUNTER |
|---|
| .. | .. |
|---|
| 1287 | 1268 | bool enabled; /* Whether to enable printing log */ |
|---|
| 1288 | 1269 | } counter_tbl_t; |
|---|
| 1289 | 1270 | |
|---|
| 1290 | | - |
|---|
| 1291 | 1271 | void counter_printlog(counter_tbl_t *ctr_tbl); |
|---|
| 1292 | 1272 | #endif /* DEBUG_COUNTER */ |
|---|
| 1293 | 1273 | |
|---|
| 1294 | | -/* Given a number 'n' returns 'm' that is next larger power of 2 after n */ |
|---|
| 1295 | | -static INLINE uint32 next_larger_power2(uint32 num) |
|---|
| 1296 | | -{ |
|---|
| 1297 | | - num--; |
|---|
| 1298 | | - num |= (num >> 1); |
|---|
| 1299 | | - num |= (num >> 2); |
|---|
| 1300 | | - num |= (num >> 4); |
|---|
| 1301 | | - num |= (num >> 8); |
|---|
| 1302 | | - num |= (num >> 16); |
|---|
| 1303 | | - return (num + 1); |
|---|
| 1304 | | -} |
|---|
| 1274 | +#if defined(__GNUC__) |
|---|
| 1275 | +#define CALL_SITE __builtin_return_address(0) |
|---|
| 1276 | +#else |
|---|
| 1277 | +#define CALL_SITE ((void*) 0) |
|---|
| 1278 | +#endif // endif |
|---|
| 1279 | +#ifdef SHOW_LOGTRACE |
|---|
| 1280 | +#define TRACE_LOG_BUF_MAX_SIZE 1700 |
|---|
| 1281 | +#define RTT_LOG_BUF_MAX_SIZE 1700 |
|---|
| 1282 | +#define BUF_NOT_AVAILABLE 0 |
|---|
| 1283 | +#define NEXT_BUF_NOT_AVAIL 1 |
|---|
| 1284 | +#define NEXT_BUF_AVAIL 2 |
|---|
| 1285 | + |
|---|
| 1286 | +typedef struct trace_buf_info { |
|---|
| 1287 | + int availability; |
|---|
| 1288 | + int size; |
|---|
| 1289 | + char buf[TRACE_LOG_BUF_MAX_SIZE]; |
|---|
| 1290 | +} trace_buf_info_t; |
|---|
| 1291 | +#endif /* SHOW_LOGTRACE */ |
|---|
| 1292 | + |
|---|
| 1293 | +enum dump_dongle_e { |
|---|
| 1294 | + DUMP_DONGLE_COREREG = 0, |
|---|
| 1295 | + DUMP_DONGLE_D11MEM |
|---|
| 1296 | +}; |
|---|
| 1297 | + |
|---|
| 1298 | +typedef struct { |
|---|
| 1299 | + uint32 type; /**< specifies e.g dump of d11 memory, use enum dump_dongle_e */ |
|---|
| 1300 | + uint32 index; /**< iterator1, specifies core index or d11 memory index */ |
|---|
| 1301 | + uint32 offset; /**< iterator2, byte offset within register set or memory */ |
|---|
| 1302 | +} dump_dongle_in_t; |
|---|
| 1303 | + |
|---|
| 1304 | +typedef struct { |
|---|
| 1305 | + uint32 address; /**< e.g. backplane address of register */ |
|---|
| 1306 | + uint32 id; /**< id, e.g. core id */ |
|---|
| 1307 | + uint32 rev; /**< rev, e.g. core rev */ |
|---|
| 1308 | + uint32 n_bytes; /**< nbytes in array val[] */ |
|---|
| 1309 | + uint32 val[1]; /**< out: values that were read out of registers or memory */ |
|---|
| 1310 | +} dump_dongle_out_t; |
|---|
| 1311 | + |
|---|
| 1312 | +extern uint32 sqrt_int(uint32 value); |
|---|
| 1313 | + |
|---|
| 1314 | +#ifdef BCMDRIVER |
|---|
| 1315 | +/* structures and routines to process variable sized data */ |
|---|
| 1316 | +typedef struct var_len_data { |
|---|
| 1317 | + uint32 vlen; |
|---|
| 1318 | + uint8 *vdata; |
|---|
| 1319 | +} var_len_data_t; |
|---|
| 1320 | + |
|---|
| 1321 | +int bcm_vdata_alloc(osl_t *osh, var_len_data_t *vld, uint32 size); |
|---|
| 1322 | +int bcm_vdata_free(osl_t *osh, var_len_data_t *vld); |
|---|
| 1323 | +#endif /* BCMDRIVER */ |
|---|
| 1324 | + |
|---|
| 1325 | +/* Count the number of elements in an array that do not match the given value */ |
|---|
| 1326 | +extern int array_value_mismatch_count(uint8 value, uint8 *array, int array_size); |
|---|
| 1327 | +/* Count the number of non-zero elements in an uint8 array */ |
|---|
| 1328 | +extern int array_nonzero_count(uint8 *array, int array_size); |
|---|
| 1329 | +/* Count the number of non-zero elements in an int16 array */ |
|---|
| 1330 | +extern int array_nonzero_count_int16(int16 *array, int array_size); |
|---|
| 1331 | +/* Count the number of zero elements in an uint8 array */ |
|---|
| 1332 | +extern int array_zero_count(uint8 *array, int array_size); |
|---|
| 1333 | +/* Validate a uint8 ordered array. Assert if invalid. */ |
|---|
| 1334 | +extern int verify_ordered_array_uint8(uint8 *array, int array_size, uint8 range_lo, uint8 range_hi); |
|---|
| 1335 | +/* Validate a int16 configuration array that need not be zero-terminated. Assert if invalid. */ |
|---|
| 1336 | +extern int verify_ordered_array_int16(int16 *array, int array_size, int16 range_lo, int16 range_hi); |
|---|
| 1337 | +/* Validate all values in an array are in range */ |
|---|
| 1338 | +extern int verify_array_values(uint8 *array, int array_size, |
|---|
| 1339 | + int range_lo, int range_hi, bool zero_terminated); |
|---|
| 1305 | 1340 | |
|---|
| 1306 | 1341 | #endif /* _bcmutils_h_ */ |
|---|