forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/include/bcmutils.h
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * Misc useful os-independent macros and functions.
43 *
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
+ *
78 * Unless you and Broadcom execute a separate written software license
89 * agreement governing use of this software, this software is licensed to you
910 * under the terms of the GNU General Public License version 2 (the "GPL"),
1011 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
1112 * following added to such license:
12
- *
13
+ *
1314 * As a special exception, the copyright holders of this software give you
1415 * permission to link this software with independent modules, and to copy and
1516 * distribute the resulting executable under terms of your choice, provided that
....@@ -17,7 +18,7 @@
1718 * the license of that module. An independent module is a module which is not
1819 * derived from this software. The special exception does not apply to any
1920 * modifications of the software.
20
- *
21
+ *
2122 * Notwithstanding the above, under no circumstances may you combine this
2223 * software in any way with any other Broadcom software provided under a license
2324 * other than the GPL, without Broadcom's express prior written consent.
....@@ -25,20 +26,24 @@
2526 *
2627 * <<Broadcom-WL-IPTag/Open:>>
2728 *
28
- * $Id: bcmutils.h 696078 2018-08-15 09:24:11Z $
29
+ * $Id: bcmutils.h 700843 2017-05-22 15:56:44Z $
2930 */
3031
3132 #ifndef _bcmutils_h_
3233 #define _bcmutils_h_
3334
35
+#include <bcmtlv.h>
3436
3537 #ifdef __cplusplus
3638 extern "C" {
37
-#endif
38
-
39
+#endif // endif
3940
4041 #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
4145 #define bcm_strncat_s(dst, noOfElements, src, count) strncat((dst), (src), (count))
46
+#endif /* FREEBSD */
4247 #define bcm_snprintf_s snprintf
4348 #define bcm_sprintf_s snprintf
4449
....@@ -48,6 +53,8 @@
4853 * bcm_strcat_s: Use bcm_strncat_s as a safer option
4954 *
5055 */
56
+
57
+#define BCM_BIT(x) (1 << (x))
5158
5259 /* ctype replacement */
5360 #define _BCM_U 0x01 /* upper */
....@@ -109,12 +116,12 @@
109116 * and take appropriate error action if 'exp' is still true.
110117 */
111118 #ifndef SPINWAIT_POLL_PERIOD
112
-#define SPINWAIT_POLL_PERIOD 10
113
-#endif
119
+#define SPINWAIT_POLL_PERIOD 10U
120
+#endif // endif
114121
115122 #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)) { \
118125 OSL_DELAY(SPINWAIT_POLL_PERIOD); \
119126 countdown -= SPINWAIT_POLL_PERIOD; \
120127 } \
....@@ -127,75 +134,11 @@
127134 extern int ether_isbcast(const void *ea);
128135 extern int ether_isnulladdr(const void *ea);
129136
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
-
153137 #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
199142
200143 /* externs */
201144 /* packet */
....@@ -204,7 +147,6 @@
204147 extern uint pkttotlen(osl_t *osh, void *p);
205148 extern void *pktlast(osl_t *osh, void *p);
206149 extern uint pktsegcnt(osl_t *osh, void *p);
207
-extern uint pktsegcnt_war(osl_t *osh, void *p);
208150 extern uint8 *pktdataoffset(osl_t *osh, void *p, uint offset);
209151 extern void *pktoffset(osl_t *osh, void *p, uint offset);
210152
....@@ -223,29 +165,26 @@
223165 #define DSCP_AF21 0x12
224166 #define DSCP_AF22 0x14
225167 #define DSCP_AF23 0x16
168
+/* CS2: OAM (RFC2474) */
169
+#define DSCP_CS2 0x10
226170 /* AF3x: Multimedia Streaming (RFC2597) */
227171 #define DSCP_AF31 0x1A
228172 #define DSCP_AF32 0x1C
229173 #define DSCP_AF33 0x1E
174
+/* CS3: Broadcast Video (RFC2474) */
175
+#define DSCP_CS3 0x18
176
+/* VA: VOCIE-ADMIT (RFC5865) */
177
+#define DSCP_VA 0x2C
230178 /* EF: Telephony (RFC3246) */
231179 #define DSCP_EF 0x2E
180
+/* CS6: Network Control (RFC2474) */
181
+#define DSCP_CS6 0x30
182
+/* CS7: Network Control (RFC2474) */
183
+#define DSCP_CS7 0x38
232184
233185 extern uint pktsetprio(void *pkt, bool update_vtag);
234186 extern uint pktsetprio_qms(void *pkt, uint8* up_table, bool update_vtag);
235187 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
-
249188
250189 /* ethernet address */
251190 extern char *bcm_ether_ntoa(const struct ether_addr *ea, char *buf);
....@@ -260,12 +199,32 @@
260199 /* delay */
261200 extern void bcm_mdelay(uint ms);
262201 /* 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 */
263211 #define NVRAM_RECLAIM_CHECK(name)
212
+#endif /* BCM_RECLAIM */
264213
265214 extern char *getvar(char *vars, const char *name);
266215 extern int getintvar(char *vars, const char *name);
267216 extern int getintvararray(char *vars, const char *name, int index);
268217 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
+
269228 extern uint getgpiopin(char *vars, char *pin_name, uint def_pin);
270229 #define bcm_perf_enable()
271230 #define bcmstats(fmt)
....@@ -297,7 +256,8 @@
297256 const char *name; /* name for lookup and display */
298257 uint16 varid; /* id for switch */
299258 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 */
301261 uint16 minlen; /* min length for buffer vars */
302262 } bcm_iovar_t;
303263
....@@ -317,11 +277,32 @@
317277
318278 extern const bcm_iovar_t *bcm_iovar_lookup(const bcm_iovar_t *table, const char *name);
319279 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
+
320288 #if defined(WLTINYDUMP) || defined(WLMSG_INFORM) || defined(WLMSG_ASSOC) || \
321289 defined(WLMSG_PRPKT) || defined(WLMSG_WSEC)
322290 extern int bcm_format_ssid(char* buf, const uchar ssid[], uint ssid_len);
323
-#endif
291
+#endif // endif
324292 #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);
325306
326307 /* Base type definitions */
327308 #define IOVT_VOID 0 /* no value (implictly set only) */
....@@ -359,9 +340,15 @@
359340
360341 /* ** driver/apps-shared section ** */
361342
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)
364345
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 */
365352
366353 /*
367354 * error codes could be added but the defined ones shouldn't be changed/deleted
....@@ -413,7 +400,7 @@
413400 #define BCME_RXFAIL -39 /* RX failure */
414401 #define BCME_NODEVICE -40 /* Device not present */
415402 #define BCME_NMODE_DISABLED -41 /* NMODE disabled */
416
-#define BCME_NONRESIDENT -42 /* access to nonresident overlay */
403
+#define BCME_HOFFLOAD_RESIDENT -42 /* offload resident */
417404 #define BCME_SCANREJECT -43 /* reject scan request */
418405 #define BCME_USAGE_ERROR -44 /* WLCMD usage error */
419406 #define BCME_IOCTL_ERROR -45 /* WLCMD ioctl error */
....@@ -425,9 +412,34 @@
425412 #define BCME_REPLAY -51 /* Replay */
426413 #define BCME_IE_NOTFOUND -52 /* IE not found */
427414 #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
429431
430432 #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
431443
432444 /* These are collection of BCME Error strings */
433445 #define BCMERRSTRINGTABLE { \
....@@ -473,7 +485,7 @@
473485 "RX Failure", \
474486 "Device Not Present", \
475487 "NMODE Disabled", \
476
- "Nonresident overlay access", \
488
+ "Host Offload in device", \
477489 "Scan Rejected", \
478490 "WLCMD usage error", \
479491 "WLCMD ioctl error", \
....@@ -485,6 +497,21 @@
485497 "Replay", \
486498 "IE not found", \
487499 "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", \
488515 }
489516
490517 #ifndef ABS
....@@ -549,13 +576,29 @@
549576 #endif /* __ARMCC_VERSION */
550577 #endif /* OFFSETOF */
551578
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
+
552592 #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
555595
556596 #ifndef ARRAYLAST /* returns pointer to last array element */
557597 #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)
559602
560603 /* Reference a function; used to prevent a static function from being optimized out */
561604 extern void *_bcmutils_dummy_fn;
....@@ -576,9 +619,23 @@
576619 #define clrbit(a, i) (((uint8 *)a)[(i) / NBBY] &= ~(1 << ((i) % NBBY)))
577620 #define isset(a, i) (((const uint8 *)a)[(i) / NBBY] & (1 << ((i) % NBBY)))
578621 #define isclr(a, i) ((((const uint8 *)a)[(i) / NBBY] & (1 << ((i) % NBBY))) == 0)
579
-#endif
622
+#endif // endif
580623 #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
+
581637 extern void set_bitrange(void *array, uint start, uint end, uint maxbit);
638
+extern int bcm_find_fsb(uint32 num);
582639
583640 #define isbitset(a, i) (((a) & (1 << (i))) != 0)
584641
....@@ -616,9 +673,9 @@
616673 return ((*a >> pos) & MSK); \
617674 }
618675
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() */
622679
623680 /* basic mux operation - can be optimized on several architectures */
624681 #define MUX(pred, true, false) ((pred) ? (true) : (false))
....@@ -658,7 +715,13 @@
658715 ((struct ether_addr *) (ea))->octet[4], \
659716 ((struct ether_addr *) (ea))->octet[5]
660717
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], \
662725 (ea).octet[1], \
663726 (ea).octet[2], \
664727 (ea).octet[3], \
....@@ -666,11 +729,17 @@
666729 (ea).octet[5]
667730 #if !defined(SIMPLE_MAC_PRINT)
668731 #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)
670733 #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]
673736 #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]
674743
675744 /* bcm_format_flags() bit description structure */
676745 typedef struct bcm_bit_desc {
....@@ -705,7 +774,7 @@
705774 if (
706775 #ifdef __i386__
707776 1 ||
708
-#endif
777
+#endif // endif
709778 (((uintptr)src1 | (uintptr)src2 | (uintptr)dst) & 3) == 0) {
710779 /* ARM CM3 rel time: 1229 (727 if alignment check could be omitted) */
711780 /* x86 supports unaligned. This version runs 6x-9x faster on x86. */
....@@ -723,9 +792,9 @@
723792
724793 /* externs */
725794 /* 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);
729798
730799 /* format/print */
731800 #if defined(DHD_DEBUG) || defined(WLMSG_PRHDRS) || defined(WLMSG_PRPKT) || \
....@@ -734,7 +803,10 @@
734803 extern int bcm_format_field(const bcm_bit_desc_ex_t *bd, uint32 field, char* buf, int len);
735804 /* print out which bits in flags are set */
736805 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
738810
739811 extern int bcm_format_hex(char *str, const void *bytes, int len);
740812
....@@ -742,144 +814,7 @@
742814 extern char *bcm_chipname(uint chipid, char *buf, uint len);
743815 extern char *bcm_brev_str(uint32 brev, char *buf);
744816 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);
883818
884819 /* bcmerror */
885820 extern const char *bcmerrorstr(int bcmerror);
....@@ -913,14 +848,17 @@
913848 char *buf, uint32 bufsize);
914849 extern uint bcm_bitcount(uint8 *bitmap, uint bytelength);
915850
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)));
917853
918854 /* power conversion */
919855 extern uint16 bcm_qdbm_to_mw(uint8 qdbm);
920856 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);
922858
923859 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);
924862
925863 /* trace any object allocation / free, with / without features (flags) set to the object */
926864
....@@ -966,12 +904,6 @@
966904 #define bcm_object_trace_deinit()
967905 #endif /* BCM_OBJECT_TRACE */
968906
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
-
975907 /* Public domain bit twiddling hacks/utilities: Sean Eron Anderson */
976908
977909 /* Table driven count set bits. */
....@@ -992,7 +924,6 @@
992924 return (_CSBTBL[p[0]] + _CSBTBL[p[1]] + _CSBTBL[p[2]] + _CSBTBL[p[3]]);
993925 }
994926
995
-
996927 static INLINE int /* C equivalent count of leading 0's in a u32 */
997928 C_bcm_count_leading_zeros(uint32 u32arg)
998929 {
....@@ -1000,8 +931,40 @@
1000931 while (u32arg) {
1001932 shifts++; u32arg >>= 1;
1002933 }
1003
- return (32U - shifts);
934
+ return (32 - shifts);
1004935 }
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;
1005968
1006969 #ifdef BCMDRIVER
1007970 /*
....@@ -1078,11 +1041,12 @@
10781041 extern void bcm_mwbmap_audit(struct bcm_mwbmap * mwbmap_hdl);
10791042 /* End - Multiword bitmap based small Id allocator. */
10801043
1081
-
10821044 /* INTERFACE: Simple unique 16bit Id Allocator using a stack implementation. */
10831045
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
10861050
10871051 /*
10881052 * Construct a 16bit id allocator, managing 16bit ids in the range:
....@@ -1108,11 +1072,15 @@
11081072 /* End - Simple 16bit Id Allocator. */
11091073 #endif /* BCMDRIVER */
11101074
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)
11121077
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)))
11161084
11171085 /* calculate checksum for ip header, tcp / udp header / data */
11181086 uint16 bcm_ip_cksum(uint8 *buf, uint32 len, uint32 sum);
....@@ -1186,13 +1154,11 @@
11861154 return list_p->next_p;
11871155 }
11881156
1189
-
11901157 static INLINE dll_t *
11911158 dll_tail_p(dll_t *list_p)
11921159 {
11931160 return (list_p)->prev_p;
11941161 }
1195
-
11961162
11971163 static INLINE dll_t *
11981164 dll_next_p(dll_t *node_p)
....@@ -1200,13 +1166,11 @@
12001166 return (node_p)->next_p;
12011167 }
12021168
1203
-
12041169 static INLINE dll_t *
12051170 dll_prev_p(dll_t *node_p)
12061171 {
12071172 return (node_p)->prev_p;
12081173 }
1209
-
12101174
12111175 static INLINE bool
12121176 dll_empty(dll_t *list_p)
....@@ -1214,13 +1178,11 @@
12141178 return ((list_p)->next_p == (list_p));
12151179 }
12161180
1217
-
12181181 static INLINE bool
12191182 dll_end(dll_t *list_p, dll_t * node_p)
12201183 {
12211184 return (list_p == node_p);
12221185 }
1223
-
12241186
12251187 /* inserts the node new_p "after" the node at_p */
12261188 static INLINE void
....@@ -1243,7 +1205,6 @@
12431205 {
12441206 dll_insert(node_p, list_p);
12451207 }
1246
-
12471208
12481209 /* deletes a node from any list that it "may" be in, if at all. */
12491210 static INLINE void
....@@ -1271,9 +1232,29 @@
12711232 typedef void (* dll_elem_dump)(void * elem_p);
12721233 void dll_pool_detach(void * osh, dll_pool_t * pool, uint16 elems_max, uint16 elem_size);
12731234
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
+
12741255 #ifdef __cplusplus
12751256 }
1276
-#endif
1257
+#endif // endif
12771258
12781259 /* #define DEBUG_COUNTER */
12791260 #ifdef DEBUG_COUNTER
....@@ -1287,20 +1268,74 @@
12871268 bool enabled; /* Whether to enable printing log */
12881269 } counter_tbl_t;
12891270
1290
-
12911271 void counter_printlog(counter_tbl_t *ctr_tbl);
12921272 #endif /* DEBUG_COUNTER */
12931273
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);
13051340
13061341 #endif /* _bcmutils_h_ */