diff options
Diffstat (limited to 'drivers/net/wireless/bcmdhd/include/bcmendian.h')
-rw-r--r-- | drivers/net/wireless/bcmdhd/include/bcmendian.h | 279 |
1 files changed, 279 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcmdhd/include/bcmendian.h b/drivers/net/wireless/bcmdhd/include/bcmendian.h new file mode 100644 index 00000000000..04b07ecb804 --- /dev/null +++ b/drivers/net/wireless/bcmdhd/include/bcmendian.h | |||
@@ -0,0 +1,279 @@ | |||
1 | /* | ||
2 | * Byte order utilities | ||
3 | * | ||
4 | * Copyright (C) 1999-2011, Broadcom Corporation | ||
5 | * | ||
6 | * Unless you and Broadcom execute a separate written software license | ||
7 | * agreement governing use of this software, this software is licensed to you | ||
8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | ||
9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | ||
10 | * following added to such license: | ||
11 | * | ||
12 | * As a special exception, the copyright holders of this software give you | ||
13 | * permission to link this software with independent modules, and to copy and | ||
14 | * distribute the resulting executable under terms of your choice, provided that | ||
15 | * you also meet, for each linked independent module, the terms and conditions of | ||
16 | * the license of that module. An independent module is a module which is not | ||
17 | * derived from this software. The special exception does not apply to any | ||
18 | * modifications of the software. | ||
19 | * | ||
20 | * Notwithstanding the above, under no circumstances may you combine this | ||
21 | * software in any way with any other Broadcom software provided under a license | ||
22 | * other than the GPL, without Broadcom's express prior written consent. | ||
23 | * | ||
24 | * $Id: bcmendian.h,v 1.36 2009-11-09 05:29:43 Exp $ | ||
25 | * | ||
26 | * This file by default provides proper behavior on little-endian architectures. | ||
27 | * On big-endian architectures, IL_BIGENDIAN should be defined. | ||
28 | */ | ||
29 | |||
30 | |||
31 | #ifndef _BCMENDIAN_H_ | ||
32 | #define _BCMENDIAN_H_ | ||
33 | |||
34 | #include <typedefs.h> | ||
35 | |||
36 | |||
37 | #define BCMSWAP16(val) \ | ||
38 | ((uint16)((((uint16)(val) & (uint16)0x00ffU) << 8) | \ | ||
39 | (((uint16)(val) & (uint16)0xff00U) >> 8))) | ||
40 | |||
41 | |||
42 | #define BCMSWAP32(val) \ | ||
43 | ((uint32)((((uint32)(val) & (uint32)0x000000ffU) << 24) | \ | ||
44 | (((uint32)(val) & (uint32)0x0000ff00U) << 8) | \ | ||
45 | (((uint32)(val) & (uint32)0x00ff0000U) >> 8) | \ | ||
46 | (((uint32)(val) & (uint32)0xff000000U) >> 24))) | ||
47 | |||
48 | |||
49 | #define BCMSWAP32BY16(val) \ | ||
50 | ((uint32)((((uint32)(val) & (uint32)0x0000ffffU) << 16) | \ | ||
51 | (((uint32)(val) & (uint32)0xffff0000U) >> 16))) | ||
52 | |||
53 | |||
54 | #ifndef hton16 | ||
55 | #define HTON16(i) BCMSWAP16(i) | ||
56 | #define hton16(i) bcmswap16(i) | ||
57 | #define HTON32(i) BCMSWAP32(i) | ||
58 | #define hton32(i) bcmswap32(i) | ||
59 | #define NTOH16(i) BCMSWAP16(i) | ||
60 | #define ntoh16(i) bcmswap16(i) | ||
61 | #define NTOH32(i) BCMSWAP32(i) | ||
62 | #define ntoh32(i) bcmswap32(i) | ||
63 | #define LTOH16(i) (i) | ||
64 | #define ltoh16(i) (i) | ||
65 | #define LTOH32(i) (i) | ||
66 | #define ltoh32(i) (i) | ||
67 | #define HTOL16(i) (i) | ||
68 | #define htol16(i) (i) | ||
69 | #define HTOL32(i) (i) | ||
70 | #define htol32(i) (i) | ||
71 | #endif | ||
72 | |||
73 | #define ltoh16_buf(buf, i) | ||
74 | #define htol16_buf(buf, i) | ||
75 | |||
76 | |||
77 | #define load32_ua(a) ltoh32_ua(a) | ||
78 | #define store32_ua(a, v) htol32_ua_store(v, a) | ||
79 | #define load16_ua(a) ltoh16_ua(a) | ||
80 | #define store16_ua(a, v) htol16_ua_store(v, a) | ||
81 | |||
82 | #define _LTOH16_UA(cp) ((cp)[0] | ((cp)[1] << 8)) | ||
83 | #define _LTOH32_UA(cp) ((cp)[0] | ((cp)[1] << 8) | ((cp)[2] << 16) | ((cp)[3] << 24)) | ||
84 | #define _NTOH16_UA(cp) (((cp)[0] << 8) | (cp)[1]) | ||
85 | #define _NTOH32_UA(cp) (((cp)[0] << 24) | ((cp)[1] << 16) | ((cp)[2] << 8) | (cp)[3]) | ||
86 | |||
87 | #define ltoh_ua(ptr) \ | ||
88 | (sizeof(*(ptr)) == sizeof(uint8) ? *(const uint8 *)(ptr) : \ | ||
89 | sizeof(*(ptr)) == sizeof(uint16) ? _LTOH16_UA((const uint8 *)(ptr)) : \ | ||
90 | sizeof(*(ptr)) == sizeof(uint32) ? _LTOH32_UA((const uint8 *)(ptr)) : \ | ||
91 | *(uint8 *)0) | ||
92 | |||
93 | #define ntoh_ua(ptr) \ | ||
94 | (sizeof(*(ptr)) == sizeof(uint8) ? *(const uint8 *)(ptr) : \ | ||
95 | sizeof(*(ptr)) == sizeof(uint16) ? _NTOH16_UA((const uint8 *)(ptr)) : \ | ||
96 | sizeof(*(ptr)) == sizeof(uint32) ? _NTOH32_UA((const uint8 *)(ptr)) : \ | ||
97 | *(uint8 *)0) | ||
98 | |||
99 | #ifdef __GNUC__ | ||
100 | |||
101 | |||
102 | |||
103 | #define bcmswap16(val) ({ \ | ||
104 | uint16 _val = (val); \ | ||
105 | BCMSWAP16(_val); \ | ||
106 | }) | ||
107 | |||
108 | #define bcmswap32(val) ({ \ | ||
109 | uint32 _val = (val); \ | ||
110 | BCMSWAP32(_val); \ | ||
111 | }) | ||
112 | |||
113 | #define bcmswap32by16(val) ({ \ | ||
114 | uint32 _val = (val); \ | ||
115 | BCMSWAP32BY16(_val); \ | ||
116 | }) | ||
117 | |||
118 | #define bcmswap16_buf(buf, len) ({ \ | ||
119 | uint16 *_buf = (uint16 *)(buf); \ | ||
120 | uint _wds = (len) / 2; \ | ||
121 | while (_wds--) { \ | ||
122 | *_buf = bcmswap16(*_buf); \ | ||
123 | _buf++; \ | ||
124 | } \ | ||
125 | }) | ||
126 | |||
127 | #define htol16_ua_store(val, bytes) ({ \ | ||
128 | uint16 _val = (val); \ | ||
129 | uint8 *_bytes = (uint8 *)(bytes); \ | ||
130 | _bytes[0] = _val & 0xff; \ | ||
131 | _bytes[1] = _val >> 8; \ | ||
132 | }) | ||
133 | |||
134 | #define htol32_ua_store(val, bytes) ({ \ | ||
135 | uint32 _val = (val); \ | ||
136 | uint8 *_bytes = (uint8 *)(bytes); \ | ||
137 | _bytes[0] = _val & 0xff; \ | ||
138 | _bytes[1] = (_val >> 8) & 0xff; \ | ||
139 | _bytes[2] = (_val >> 16) & 0xff; \ | ||
140 | _bytes[3] = _val >> 24; \ | ||
141 | }) | ||
142 | |||
143 | #define hton16_ua_store(val, bytes) ({ \ | ||
144 | uint16 _val = (val); \ | ||
145 | uint8 *_bytes = (uint8 *)(bytes); \ | ||
146 | _bytes[0] = _val >> 8; \ | ||
147 | _bytes[1] = _val & 0xff; \ | ||
148 | }) | ||
149 | |||
150 | #define hton32_ua_store(val, bytes) ({ \ | ||
151 | uint32 _val = (val); \ | ||
152 | uint8 *_bytes = (uint8 *)(bytes); \ | ||
153 | _bytes[0] = _val >> 24; \ | ||
154 | _bytes[1] = (_val >> 16) & 0xff; \ | ||
155 | _bytes[2] = (_val >> 8) & 0xff; \ | ||
156 | _bytes[3] = _val & 0xff; \ | ||
157 | }) | ||
158 | |||
159 | #define ltoh16_ua(bytes) ({ \ | ||
160 | const uint8 *_bytes = (const uint8 *)(bytes); \ | ||
161 | _LTOH16_UA(_bytes); \ | ||
162 | }) | ||
163 | |||
164 | #define ltoh32_ua(bytes) ({ \ | ||
165 | const uint8 *_bytes = (const uint8 *)(bytes); \ | ||
166 | _LTOH32_UA(_bytes); \ | ||
167 | }) | ||
168 | |||
169 | #define ntoh16_ua(bytes) ({ \ | ||
170 | const uint8 *_bytes = (const uint8 *)(bytes); \ | ||
171 | _NTOH16_UA(_bytes); \ | ||
172 | }) | ||
173 | |||
174 | #define ntoh32_ua(bytes) ({ \ | ||
175 | const uint8 *_bytes = (const uint8 *)(bytes); \ | ||
176 | _NTOH32_UA(_bytes); \ | ||
177 | }) | ||
178 | |||
179 | #else | ||
180 | |||
181 | |||
182 | static INLINE uint16 | ||
183 | bcmswap16(uint16 val) | ||
184 | { | ||
185 | return BCMSWAP16(val); | ||
186 | } | ||
187 | |||
188 | static INLINE uint32 | ||
189 | bcmswap32(uint32 val) | ||
190 | { | ||
191 | return BCMSWAP32(val); | ||
192 | } | ||
193 | |||
194 | static INLINE uint32 | ||
195 | bcmswap32by16(uint32 val) | ||
196 | { | ||
197 | return BCMSWAP32BY16(val); | ||
198 | } | ||
199 | |||
200 | |||
201 | |||
202 | |||
203 | static INLINE void | ||
204 | bcmswap16_buf(uint16 *buf, uint len) | ||
205 | { | ||
206 | len = len / 2; | ||
207 | |||
208 | while (len--) { | ||
209 | *buf = bcmswap16(*buf); | ||
210 | buf++; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | |||
215 | static INLINE void | ||
216 | htol16_ua_store(uint16 val, uint8 *bytes) | ||
217 | { | ||
218 | bytes[0] = val & 0xff; | ||
219 | bytes[1] = val >> 8; | ||
220 | } | ||
221 | |||
222 | |||
223 | static INLINE void | ||
224 | htol32_ua_store(uint32 val, uint8 *bytes) | ||
225 | { | ||
226 | bytes[0] = val & 0xff; | ||
227 | bytes[1] = (val >> 8) & 0xff; | ||
228 | bytes[2] = (val >> 16) & 0xff; | ||
229 | bytes[3] = val >> 24; | ||
230 | } | ||
231 | |||
232 | |||
233 | static INLINE void | ||
234 | hton16_ua_store(uint16 val, uint8 *bytes) | ||
235 | { | ||
236 | bytes[0] = val >> 8; | ||
237 | bytes[1] = val & 0xff; | ||
238 | } | ||
239 | |||
240 | |||
241 | static INLINE void | ||
242 | hton32_ua_store(uint32 val, uint8 *bytes) | ||
243 | { | ||
244 | bytes[0] = val >> 24; | ||
245 | bytes[1] = (val >> 16) & 0xff; | ||
246 | bytes[2] = (val >> 8) & 0xff; | ||
247 | bytes[3] = val & 0xff; | ||
248 | } | ||
249 | |||
250 | |||
251 | static INLINE uint16 | ||
252 | ltoh16_ua(const void *bytes) | ||
253 | { | ||
254 | return _LTOH16_UA((const uint8 *)bytes); | ||
255 | } | ||
256 | |||
257 | |||
258 | static INLINE uint32 | ||
259 | ltoh32_ua(const void *bytes) | ||
260 | { | ||
261 | return _LTOH32_UA((const uint8 *)bytes); | ||
262 | } | ||
263 | |||
264 | |||
265 | static INLINE uint16 | ||
266 | ntoh16_ua(const void *bytes) | ||
267 | { | ||
268 | return _NTOH16_UA((const uint8 *)bytes); | ||
269 | } | ||
270 | |||
271 | |||
272 | static INLINE uint32 | ||
273 | ntoh32_ua(const void *bytes) | ||
274 | { | ||
275 | return _NTOH32_UA((const uint8 *)bytes); | ||
276 | } | ||
277 | |||
278 | #endif | ||
279 | #endif | ||