diff --git a/simulation/fw/wb_cfggen.c b/simulation/fw/wb_cfggen.c index 597c63911dc741bd193116790135ad99884185e0..958f3153e36c7b22b4e59957811ce71089e658e3 100644 --- a/simulation/fw/wb_cfggen.c +++ b/simulation/fw/wb_cfggen.c @@ -74,7 +74,7 @@ struct sdwb_wbid *sdwb_create_id() if (!id) return NULL; - id->bstream_type = htobe64(0xdeadbeefdeadbeef); + id->bstream_type = htonll(0xdeadbeefdeadbeefLL); return id; } diff --git a/simulation/include/linux/sdwb.h b/simulation/include/linux/sdwb.h index 1552d1b1c96b55dd439612d7925c50ff07abe07b..9e7848a757ffa693f6421b130f1f7a29c10f00c3 100644 --- a/simulation/include/linux/sdwb.h +++ b/simulation/include/linux/sdwb.h @@ -23,13 +23,39 @@ #ifndef _SDWB_H #define _SDWB_H -/* SDWB magic numbers */ +/* + * SDWB magic numbers. They are all big-endian. We use be**_to_cpu in + * kernel space, and network order in user space. Please note that + * we define the internal values as constants, but help users by + * also defining the host-order values (without leading underscores) + */ +#define __SDWB_HEAD_MAGIC 0x5344574248454144LL /* "SDWBHEAD" */ +#define __SDWB_WBD_MAGIC 0x5742 /* "WB" */ + +#define SDWB_HEAD_MAGIC ntohll(__SDWB_HEAD_MAGIC) +#define SDWB_WBD_MAGIC ntohs(__SDWB_WBD_MAGIC) -/* 'SDWBHEAD' (big endian). Used in SDWB Header */ -#define SDWB_HEAD_MAGIC 0x5344574248454144LL +/* The following comes from arch/um/drivers/cow.h -- factorazing anyone? */ +#if !defined(ntohll) && defined(__KERNEL__) +# include <asm/byteorder.h> +# define ntohll(x) be64_to_cpu(x) +# define htonll(x) cpu_to_be64(x) +#elif !defined(ntohll) && !defined(__KERNEL__) +# include <endian.h> +# include <netinet/in.h> +# if defined(__BYTE_ORDER) +# if __BYTE_ORDER == __BIG_ENDIAN +# define ntohll(x) (x) +# define htonll(x) (x) +# else +# define ntohll(x) __bswap_64(x) +# define htonll(x) __bswap_64(x) +# endif +# else +# error "Could not determine byte order: __BYTE_ORDER undefined" +# endif +#endif /* __KERNEL__ */ -/* 'WB' (big endian, 16 bits). Used in SDWB device descriptors */ -#define SDWB_WBD_MAGIC 0x5742 /* * SDWB - Header structure