diff options
author | Ben Hutchings <bhutchings@solarflare.com> | 2010-06-25 15:46:58 +0100 |
---|---|---|
committer | Jeff Garzik <jgarzik@redhat.com> | 2010-06-25 13:07:48 -0400 |
commit | 18caa78ad1a6b70cce8f3342d547ee70756d91c9 (patch) | |
tree | 912765c85b4f918700395fc2a570c2c202b23469 /ethtool-util.h | |
parent | 2c2ee7ae6117f05fc76741451c5c6e79b31512c3 (diff) | |
download | ethtool-18caa78ad1a6b70cce8f3342d547ee70756d91c9.tar.gz |
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 <bhutchings@solarflare.com>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'ethtool-util.h')
-rw-r--r-- | ethtool-util.h | 29 |
1 files changed, 25 insertions, 4 deletions
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 <sys/types.h> +#include <endian.h> #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); |