forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-02-19 1c055e55a242a33e574e48be530e06770a210dcd
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/include/bcmendian.h
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * Byte order utilities
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,7 +26,7 @@
2526 *
2627 * <<Broadcom-WL-IPTag/Open:>>
2728 *
28
- * $Id: bcmendian.h 514727 2014-11-12 03:02:48Z $
29
+ * $Id: bcmendian.h 633810 2016-04-25 16:46:55Z $
2930 *
3031 * This file by default provides proper behavior on little-endian architectures.
3132 * On big-endian architectures, IL_BIGENDIAN should be defined.
....@@ -69,7 +70,6 @@
6970 ((uint64)((((uint64)(val) & 0x00000000ffffffffULL) << 32) | \
7071 (((uint64)(val) & 0xffffffff00000000ULL) >> 32)))
7172
72
-
7373 /* Byte swapping macros
7474 * Host <=> Network (Big Endian) for 16- and 32-bit values
7575 * Host <=> Little-Endian for 16- and 32-bit values
....@@ -97,17 +97,33 @@
9797
9898 #define ltoh16_buf(buf, i)
9999 #define htol16_buf(buf, i)
100
+#define ltoh32_buf(buf, i)
101
+#define htol32_buf(buf, i)
102
+#define ltoh64_buf(buf, i)
103
+#define htol64_buf(buf, i)
100104
101105 /* Unaligned loads and stores in host byte order */
102106 #define load32_ua(a) ltoh32_ua(a)
103107 #define store32_ua(a, v) htol32_ua_store(v, a)
104108 #define load16_ua(a) ltoh16_ua(a)
105109 #define store16_ua(a, v) htol16_ua_store(v, a)
110
+#define load64_ua(a) ltoh64_ua(a)
111
+#define store64_ua(a, v) htol64_ua_store(v, a)
106112
107
-#define _LTOH16_UA(cp) ((cp)[0] | ((cp)[1] << 8))
108
-#define _LTOH32_UA(cp) ((cp)[0] | ((cp)[1] << 8) | ((cp)[2] << 16) | ((cp)[3] << 24))
109
-#define _NTOH16_UA(cp) (((cp)[0] << 8) | (cp)[1])
110
-#define _NTOH32_UA(cp) (((cp)[0] << 24) | ((cp)[1] << 16) | ((cp)[2] << 8) | (cp)[3])
113
+#define _LTOH16_UA(cp) (uint16)((cp)[0] | ((cp)[1] << 8))
114
+#define _LTOH32_UA(cp) (uint32)((cp)[0] | ((cp)[1] << 8) | ((cp)[2] << 16) | ((cp)[3] << 24))
115
+#define _NTOH16_UA(cp) (uint16)(((cp)[0] << 8) | (cp)[1])
116
+#define _NTOH32_UA(cp) (uint32)(((cp)[0] << 24) | ((cp)[1] << 16) | ((cp)[2] << 8) | (cp)[3])
117
+
118
+#define _LTOH64_UA(cp) ((uint64)(cp)[0] | ((uint64)(cp)[1] << 8) | \
119
+ ((uint64)(cp)[2] << 16) | ((uint64)(cp)[3] << 24) | \
120
+ ((uint64)(cp)[4] << 32) | ((uint64)(cp)[5] << 40) | \
121
+ ((uint64)(cp)[6] << 48) | ((uint64)(cp)[7] << 56))
122
+
123
+#define _NTOH64_UA(cp) ((uint64)(cp)[7] | ((uint64)(cp)[6] << 8) | \
124
+ ((uint64)(cp)[5] << 16) | ((uint64)(cp)[4] << 24) | \
125
+ ((uint64)(cp)[3] << 32) | ((uint64)(cp)[2] << 40) | \
126
+ ((uint64)(cp)[1] << 48) | ((uint64)(cp)[0] << 56))
111127
112128 #define ltoh_ua(ptr) \
113129 (sizeof(*(ptr)) == sizeof(uint8) ? *(const uint8 *)(ptr) : \
....@@ -156,6 +172,24 @@
156172 } \
157173 })
158174
175
+#define bcmswap32_buf(buf, len) ({ \
176
+ uint32 *_buf = (uint32 *)(buf); \
177
+ uint _wds = (len) / 4; \
178
+ while (_wds--) { \
179
+ *_buf = bcmswap32(*_buf); \
180
+ _buf++; \
181
+ } \
182
+})
183
+
184
+#define bcmswap64_buf(buf, len) ({ \
185
+ uint64 *_buf = (uint64 *)(buf); \
186
+ uint _wds = (len) / 8; \
187
+ while (_wds--) { \
188
+ *_buf = bcmswap64(*_buf); \
189
+ _buf++; \
190
+ } \
191
+})
192
+
159193 #define htol16_ua_store(val, bytes) ({ \
160194 uint16 _val = (val); \
161195 uint8 *_bytes = (uint8 *)(bytes); \
....@@ -170,6 +204,16 @@
170204 _bytes[1] = (_val >> 8) & 0xff; \
171205 _bytes[2] = (_val >> 16) & 0xff; \
172206 _bytes[3] = _val >> 24; \
207
+})
208
+
209
+#define htol64_ua_store(val, bytes) ({ \
210
+ uint64 _val = (val); \
211
+ uint8 *_bytes = (uint8 *)(bytes); \
212
+ int i; \
213
+ for (i = 0; i < (int)sizeof(_val); ++i) { \
214
+ *_bytes++ = _val & 0xff; \
215
+ _val >>= 8; \
216
+ } \
173217 })
174218
175219 #define hton16_ua_store(val, bytes) ({ \
....@@ -198,6 +242,11 @@
198242 _LTOH32_UA(_bytes); \
199243 })
200244
245
+#define ltoh64_ua(bytes) ({ \
246
+ const uint8 *_bytes = (const uint8 *)(bytes); \
247
+ _LTOH64_UA(_bytes); \
248
+})
249
+
201250 #define ntoh16_ua(bytes) ({ \
202251 const uint8 *_bytes = (const uint8 *)(bytes); \
203252 _NTOH16_UA(_bytes); \
....@@ -206,6 +255,11 @@
206255 #define ntoh32_ua(bytes) ({ \
207256 const uint8 *_bytes = (const uint8 *)(bytes); \
208257 _NTOH32_UA(_bytes); \
258
+})
259
+
260
+#define ntoh64_ua(bytes) ({ \
261
+ const uint8 *_bytes = (const uint8 *)(bytes); \
262
+ _NTOH64_UA(_bytes); \
209263 })
210264
211265 #else /* !__GNUC__ */
....@@ -272,6 +326,19 @@
272326 }
273327
274328 /*
329
+ * Store 64-bit value to unaligned little-endian byte array.
330
+ */
331
+static INLINE void
332
+htol64_ua_store(uint64 val, uint8 *bytes)
333
+{
334
+ int i;
335
+ for (i = 0; i < sizeof(val); ++i) {
336
+ *bytes++ = (uint8)(val & 0xff);
337
+ val >>= 8;
338
+ }
339
+}
340
+
341
+/*
275342 * Store 16-bit value to unaligned network-(big-)endian byte array.
276343 */
277344 static INLINE void
....@@ -312,6 +379,15 @@
312379 }
313380
314381 /*
382
+ * Load 64-bit value from unaligned little-endian byte array.
383
+ */
384
+static INLINE uint64
385
+ltoh64_ua(const void *bytes)
386
+{
387
+ return _LTOH64_UA((const uint8 *)bytes);
388
+}
389
+
390
+/*
315391 * Load 16-bit value from unaligned big-(network-)endian byte array.
316392 */
317393 static INLINE uint16
....@@ -329,5 +405,14 @@
329405 return _NTOH32_UA((const uint8 *)bytes);
330406 }
331407
408
+/*
409
+ * Load 64-bit value from unaligned big-(network-)endian byte array.
410
+ */
411
+static INLINE uint64
412
+ntoh64_ua(const void *bytes)
413
+{
414
+ return _NTOH64_UA((const uint8 *)bytes);
415
+}
416
+
332417 #endif /* !__GNUC__ */
333418 #endif /* !_BCMENDIAN_H_ */