From 18caa78ad1a6b70cce8f3342d547ee70756d91c9 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Fri, 25 Jun 2010 15:46:58 +0100 Subject: ethtool: Parse integers into variables of different sizes and byte orders The arguments for RX n-tuple traffic direction are filled into structure fields of varying size, some of which are in big-endian rather than native byte order. Currently parse_generic_cmdline() only supports 32-bit integers in native byte order, so this does not work correctly. Replace CMDL_INT and CMDL_UINT with the more explicit CMDL_S32 and CMDL_U32. Add CMDL_U16 and CMDL_U64 for narrower and wider integers, and CMDL_BE16 and CMDL_BE32 for big-endian unsigned integers. Use them for RX n-tuple argument parsing. Signed-off-by: Ben Hutchings Signed-off-by: Jeff Garzik --- ethtool-util.h | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'ethtool-util.h') diff --git a/ethtool-util.h b/ethtool-util.h index e9a998a..01b1d03 100644 --- a/ethtool-util.h +++ b/ethtool-util.h @@ -4,14 +4,35 @@ #define ETHTOOL_UTIL_H__ #include +#include #include "ethtool-copy.h" -/* historical: we used to use kernel-like types; remove these once cleaned */ typedef unsigned long long u64; -typedef __uint32_t u32; /* ditto */ -typedef __uint16_t u16; /* ditto */ -typedef __uint8_t u8; /* ditto */ +typedef __uint32_t u32; +typedef __uint16_t u16; +typedef __uint8_t u8; +typedef __int32_t s32; + +#if __BYTE_ORDER == __BIG_ENDIAN +static inline u16 cpu_to_be16(u16 value) +{ + return value; +} +static inline u32 cpu_to_be32(u32 value) +{ + return value; +} +#else +static inline u16 cpu_to_be16(u16 value) +{ + return (value >> 8) | (value << 8); +} +static inline u32 cpu_to_be32(u32 value) +{ + return cpu_to_be16(value >> 16) | (cpu_to_be16(value) << 16); +} +#endif /* National Semiconductor DP83815, DP83816 */ int natsemi_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs); -- cgit v1.2.1