aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/bcmdhd/include/bcmendian.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/bcmdhd/include/bcmendian.h')
-rw-r--r--drivers/net/wireless/bcmdhd/include/bcmendian.h67
1 files changed, 44 insertions, 23 deletions
diff --git a/drivers/net/wireless/bcmdhd/include/bcmendian.h b/drivers/net/wireless/bcmdhd/include/bcmendian.h
index 22eb7db..1545f4e 100644
--- a/drivers/net/wireless/bcmdhd/include/bcmendian.h
+++ b/drivers/net/wireless/bcmdhd/include/bcmendian.h
@@ -1,7 +1,7 @@
/*
* Byte order utilities
*
- * Copyright (C) 1999-2012, Broadcom Corporation
+ * Copyright (C) 1999-2013, Broadcom Corporation
*
* Unless you and Broadcom execute a separate written software license
* agreement governing use of this software, this software is licensed to you
@@ -32,24 +32,27 @@
#include <typedefs.h>
-
+/* Reverse the bytes in a 16-bit value */
#define BCMSWAP16(val) \
((uint16)((((uint16)(val) & (uint16)0x00ffU) << 8) | \
(((uint16)(val) & (uint16)0xff00U) >> 8)))
-
+/* Reverse the bytes in a 32-bit value */
#define BCMSWAP32(val) \
((uint32)((((uint32)(val) & (uint32)0x000000ffU) << 24) | \
(((uint32)(val) & (uint32)0x0000ff00U) << 8) | \
(((uint32)(val) & (uint32)0x00ff0000U) >> 8) | \
(((uint32)(val) & (uint32)0xff000000U) >> 24)))
-
+/* Reverse the two 16-bit halves of a 32-bit value */
#define BCMSWAP32BY16(val) \
((uint32)((((uint32)(val) & (uint32)0x0000ffffU) << 16) | \
(((uint32)(val) & (uint32)0xffff0000U) >> 16)))
-
+/* Byte swapping macros
+ * Host <=> Network (Big Endian) for 16- and 32-bit values
+ * Host <=> Little-Endian for 16- and 32-bit values
+ */
#ifndef hton16
#define HTON16(i) BCMSWAP16(i)
#define hton16(i) bcmswap16(i)
@@ -67,12 +70,12 @@
#define htol16(i) (i)
#define HTOL32(i) (i)
#define htol32(i) (i)
-#endif
+#endif /* hton16 */
#define ltoh16_buf(buf, i)
#define htol16_buf(buf, i)
-
+/* Unaligned loads and stores in host byte order */
#define load32_ua(a) ltoh32_ua(a)
#define store32_ua(a, v) htol32_ua_store(v, a)
#define load16_ua(a) ltoh16_ua(a)
@@ -97,7 +100,9 @@
#ifdef __GNUC__
-
+/* GNU macro versions avoid referencing the argument multiple times, while also
+ * avoiding the -fno-inline used in ROM builds.
+ */
#define bcmswap16(val) ({ \
uint16 _val = (val); \
@@ -175,9 +180,9 @@
_NTOH32_UA(_bytes); \
})
-#else
-
+#else /* !__GNUC__ */
+/* Inline versions avoid referencing the argument multiple times */
static INLINE uint16
bcmswap16(uint16 val)
{
@@ -196,9 +201,9 @@ bcmswap32by16(uint32 val)
return BCMSWAP32BY16(val);
}
-
-
-
+/* Reverse pairs of bytes in a buffer (not for high-performance use) */
+/* buf - start of buffer of shorts to swap */
+/* len - byte length of buffer */
static INLINE void
bcmswap16_buf(uint16 *buf, uint len)
{
@@ -210,7 +215,9 @@ bcmswap16_buf(uint16 *buf, uint len)
}
}
-
+/*
+ * Store 16-bit value to unaligned little-endian byte array.
+ */
static INLINE void
htol16_ua_store(uint16 val, uint8 *bytes)
{
@@ -218,7 +225,9 @@ htol16_ua_store(uint16 val, uint8 *bytes)
bytes[1] = val >> 8;
}
-
+/*
+ * Store 32-bit value to unaligned little-endian byte array.
+ */
static INLINE void
htol32_ua_store(uint32 val, uint8 *bytes)
{
@@ -228,7 +237,9 @@ htol32_ua_store(uint32 val, uint8 *bytes)
bytes[3] = val >> 24;
}
-
+/*
+ * Store 16-bit value to unaligned network-(big-)endian byte array.
+ */
static INLINE void
hton16_ua_store(uint16 val, uint8 *bytes)
{
@@ -236,7 +247,9 @@ hton16_ua_store(uint16 val, uint8 *bytes)
bytes[1] = val & 0xff;
}
-
+/*
+ * Store 32-bit value to unaligned network-(big-)endian byte array.
+ */
static INLINE void
hton32_ua_store(uint32 val, uint8 *bytes)
{
@@ -246,33 +259,41 @@ hton32_ua_store(uint32 val, uint8 *bytes)
bytes[3] = val & 0xff;
}
-
+/*
+ * Load 16-bit value from unaligned little-endian byte array.
+ */
static INLINE uint16
ltoh16_ua(const void *bytes)
{
return _LTOH16_UA((const uint8 *)bytes);
}
-
+/*
+ * Load 32-bit value from unaligned little-endian byte array.
+ */
static INLINE uint32
ltoh32_ua(const void *bytes)
{
return _LTOH32_UA((const uint8 *)bytes);
}
-
+/*
+ * Load 16-bit value from unaligned big-(network-)endian byte array.
+ */
static INLINE uint16
ntoh16_ua(const void *bytes)
{
return _NTOH16_UA((const uint8 *)bytes);
}
-
+/*
+ * Load 32-bit value from unaligned big-(network-)endian byte array.
+ */
static INLINE uint32
ntoh32_ua(const void *bytes)
{
return _NTOH32_UA((const uint8 *)bytes);
}
-#endif
-#endif
+#endif /* !__GNUC__ */
+#endif /* !_BCMENDIAN_H_ */