diff options
author | Roland Dreier <rolandd@cisco.com> | 2005-09-07 20:01:31 +0000 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-11-09 11:35:57 -0800 |
commit | 15ba0b1eab8c7276dabbe53a542488d77f7d8114 (patch) | |
tree | 6826d1d0bafd3e65c44d8dddfdadf77cd44d1e2c | |
parent | 7a126170e8a1c579564b64be9892cbe106a86463 (diff) | |
download | libibverbs-15ba0b1eab8c7276dabbe53a542488d77f7d8114.tar.gz |
Include htonll() and nothll() in <infiniband/arch.h>
Move htonll() and ntohll() from libmthca into libibverb's
<infiniband/arch.h>, and use them in ibv_get_device_guid() to
avoid pointer aliasing (which some versions of gcc miscompile).
Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | include/infiniband/arch.h | 11 | ||||
-rw-r--r-- | src/device.c | 11 |
3 files changed, 26 insertions, 4 deletions
@@ -1,3 +1,11 @@ +2005-09-07 Roland Dreier <roland@cisco.com> + + * src/device.c (ibv_get_device_guid): Use htonll() instead of + relying on pointer aliasing (which seems to break for some gcc + versions). + + * include/infiniband/arch.h: Add htonll() and ntohll() functions. + 2005-09-06 Roland Dreier <roland@cisco.com> * include/infiniband/kern-abi.h, include/infiniband/verbs.h, diff --git a/include/infiniband/arch.h b/include/infiniband/arch.h index b582d18..e6eb8c8 100644 --- a/include/infiniband/arch.h +++ b/include/infiniband/arch.h @@ -35,6 +35,17 @@ #ifndef INFINIBAND_ARCH_H #define INFINIBAND_ARCH_H +#include <endian.h> +#include <byteswap.h> + +#if __BYTE_ORDER == __LITTLE_ENDIAN +static inline uint64_t htonll(uint64_t x) { return bswap_64(x); } +static inline uint64_t ntohll(uint64_t x) { return bswap_64(x); } +#elif __BYTE_ORDER == __BIG_ENDIAN +static inline uint64_t htonll(uint64_t x) { return x; } +static inline uint64_t ntohll(uint64_t x) { return x; } +#endif + /* * Architecture-specific defines. Currently, an architecture is * required to implement the following operations: diff --git a/src/device.c b/src/device.c index 19a8c98..82afcdd 100644 --- a/src/device.c +++ b/src/device.c @@ -44,6 +44,8 @@ #include <unistd.h> #include <alloca.h> +#include <infiniband/arch.h> + #include "ibverbs.h" static struct dlist *device_list; @@ -63,7 +65,8 @@ const char *ibv_get_device_name(struct ibv_device *device) uint64_t ibv_get_device_guid(struct ibv_device *device) { struct sysfs_attribute *attr; - uint16_t guid[4]; + uint64_t guid = 0; + uint16_t parts[4]; int i; attr = sysfs_get_classdev_attr(device->ibdev, "node_guid"); @@ -71,13 +74,13 @@ uint64_t ibv_get_device_guid(struct ibv_device *device) return 0; if (sscanf(attr->value, "%hx:%hx:%hx:%hx", - guid, guid + 1, guid + 2, guid + 3) != 4) + parts, parts + 1, parts + 2, parts + 3) != 4) return 0; for (i = 0; i < 4; ++i) - guid[i] = htons(guid[i]); + guid = (guid << 16) | parts[i]; - return *(uint64_t *) guid; + return htonll(guid); } struct ibv_context *ibv_open_device(struct ibv_device *device) |