[Pkg-ofed-commits] [libibverbs] 03/24: Imported Upstream version 1.0.3

Ana Beatriz Guerrero López ana at moszumanska.debian.org
Wed Jul 2 13:16:46 UTC 2014


This is an automated email from the git hooks/post-receive script.

ana pushed a commit to branch master
in repository libibverbs.

commit 3ff8458ba8a14cc54b190b5db40b72943bf8815e
Author: Ana Guerrero López <ana at ekaia.org>
Date:   Wed Jul 2 15:15:06 2014 +0200

    Imported Upstream version 1.0.3
---
 ChangeLog                            | 62 +++++++++++++++++++++++++
 Makefile.am                          |  4 +-
 Makefile.in                          | 14 ++++--
 configure                            | 20 ++++----
 configure.in                         |  4 +-
 examples/asyncwatch.c                | 39 ++++++++++++++--
 include/infiniband/arch.h            |  8 +++-
 include/infiniband/driver.h          | 10 +++-
 include/infiniband/marshall.h        | 27 +++++++++--
 include/infiniband/sa-kern-abi.h     | 13 ++++--
 include/infiniband/sa.h              | 45 +++++-------------
 include/infiniband/verbs.h           | 32 ++++++++++++-
 libibverbs.spec                      | 14 +++---
 libibverbs.spec.in                   | 12 ++---
 src/cmd.c                            |  3 +-
 src/device.c                         | 11 +++--
 src/init.c                           | 48 ++++++++------------
 src/libibverbs.map                   |  8 ++++
 src/marshall.c                       | 38 ++++++++++++----
 src/memory.c                         |  3 +-
 examples/asyncwatch.c => src/sysfs.c | 88 ++++++++++++++++++++++--------------
 src/verbs.c                          | 85 ++++++++++++++++++++--------------
 22 files changed, 395 insertions(+), 193 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 28e1839..6f67a01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,65 @@
+2006-05-02  Roland Dreier  <rdreier at cisco.com>
+
+	* Release version 1.0.3.
+
+2006-05-01  Roland Dreier  <rdreier at cisco.com>
+
+	* include/infiniband/arch.h: Only SPARC V9 ISA supports membar.
+	So just use generic memory barrier for older sparc archs.
+
+2006-04-11  Roland Dreier  <rdreier at cisco.com>
+
+	* src/sysfs.c (ibv_read_sysfs_file): Fix memory leak if open fails.
+
+	* src/device.c (ibv_get_device_guid), src/verbs.c (ibv_query_gid,
+	ibv_query_pkey), src/init.c (init_drivers, check_abi_version): Use
+	libibverbs functions instead of libsysfs functions to get to sysfs.
+
+	* src/sysfs.c (ibv_get_sysfs_path, ibv_read_sysfs_file): Add some
+	simple functions for accessing sysfs without using libsysfs.
+
+	* include/infiniband/sa-kern-abi.h: Deprecate struct
+	ib_kern_path_rec name; struct ibv_kern_path_rec is now preferred.
+
+	* include/infiniband/sa.h: Deprecate struct ib_sa_XXX names;
+	struct ibv_sa_XXX is now preferred.
+
+	* src/marshall.c, include/infiniband/marshall.h: Deprecate
+	ib_copy_XXX() names; ibv_copy_XXX() is preferred.  Add stub
+	wrappers with the old names so old binaries still work.
+
+2006-04-11  Hoang-Nam Nguyen  <HNGUYEN at de.ibm.com>
+
+	* src/verbs.c (ibv_rate_to_mult, mult_to_ibv_rate): Add new
+	functions to convert between IB rate enums and multiples of the
+	base 2.5 Gb/sec rate.
+
+2006-04-11  Roland Dreier  <rdreier at cisco.com>
+
+	* include/infiniband/verbs.h: Add __attribute_const macro to
+	portably mark functions as __attribute__((const))
+
+2006-03-28  Roland Dreier  <rdreier at cisco.com>
+
+	* src/init.c (load_driver): Print warning if dlopen() of a driver
+	plugin fails.
+
+2006-03-22  Dotan Barak  <dotanb at mellanox.co.il>
+
+	* examples/asyncwatch.c: Print asynchronous event name as well as
+	raw integer value.
+	
+2006-03-22  Roland Dreier  <rdreier at cisco.com>
+
+	* include/infiniband/verbs.h (ibv_req_notify_cq): Document
+	parameters better.
+
+2006-03-16  Roland Dreier  <rdreier at cisco.com>
+
+	* src/cmd.c, src/device.c, src/memory.c, src/verbs.c: Add include
+	of <stdlib.h> to get a declaration of free() and avoid compile
+	warnings.
+
 2006-03-14  Roland Dreier  <rdreier at cisco.com>
 
 	* Release version 1.0.2.
diff --git a/Makefile.am b/Makefile.am
index 8f1d0e9..c27c356 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# $Id: Makefile.am 5827 2006-03-15 00:45:55Z roland $
+# $Id: Makefile.am 6432 2006-04-11 23:27:38Z roland $
 
 INCLUDES = -I$(srcdir)/include
 
@@ -15,7 +15,7 @@ else
 endif
 
 src_libibverbs_la_SOURCES = src/cmd.c src/device.c src/init.c src/marshall.c \
-			    src/memory.c src/verbs.c
+			    src/memory.c src/sysfs.c src/verbs.c
 src_libibverbs_la_LDFLAGS = -version-info 1 -export-dynamic \
     $(libibverbs_version_script)
 src_libibverbs_la_DEPENDENCIES = $(srcdir)/src/libibverbs.map
diff --git a/Makefile.in b/Makefile.in
index efb10b6..b315f94 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -14,7 +14,7 @@
 
 @SET_MAKE@
 
-# $Id: Makefile.am 5827 2006-03-15 00:45:55Z roland $
+# $Id: Makefile.am 6432 2006-04-11 23:27:38Z roland $
 
 
 
@@ -79,7 +79,7 @@ src_libibverbs_la_LIBADD =
 am_src_libibverbs_la_OBJECTS = src_libibverbs_la-cmd.lo \
 	src_libibverbs_la-device.lo src_libibverbs_la-init.lo \
 	src_libibverbs_la-marshall.lo src_libibverbs_la-memory.lo \
-	src_libibverbs_la-verbs.lo
+	src_libibverbs_la-sysfs.lo src_libibverbs_la-verbs.lo
 src_libibverbs_la_OBJECTS = $(am_src_libibverbs_la_OBJECTS)
 am__dirstamp = $(am__leading_dot)dirstamp
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
@@ -269,7 +269,7 @@ src_libibverbs_la_CFLAGS = -g -Wall -D_GNU_SOURCE -DDRIVER_PATH=\"$(libdir)/infi
 @HAVE_LD_VERSION_SCRIPT_FALSE at libibverbs_version_script = 
 @HAVE_LD_VERSION_SCRIPT_TRUE at libibverbs_version_script = -Wl,--version-script=$(srcdir)/src/libibverbs.map
 src_libibverbs_la_SOURCES = src/cmd.c src/device.c src/init.c src/marshall.c \
-			    src/memory.c src/verbs.c
+			    src/memory.c src/sysfs.c src/verbs.c
 
 src_libibverbs_la_LDFLAGS = -version-info 1 -export-dynamic \
     $(libibverbs_version_script)
@@ -467,6 +467,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/src_libibverbs_la-init.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/src_libibverbs_la-marshall.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/src_libibverbs_la-memory.Plo at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/src_libibverbs_la-sysfs.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/src_libibverbs_la-verbs.Plo at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/srq_pingpong.Po at am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/uc_pingpong.Po at am__quote@
@@ -528,6 +529,13 @@ src_libibverbs_la-memory.lo: src/memory.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_libibverbs_la_CFLAGS) $(CFLAGS) -c -o src_libibverbs_la-memory.lo `test -f 'src/memory.c' || echo '$(srcdir)/'`src/memory.c
 
+src_libibverbs_la-sysfs.lo: src/sysfs.c
+ at am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_libibverbs_la_CFLAGS) $(CFLAGS) -MT src_libibverbs_la-sysfs.lo -MD -MP -MF "$(DEPDIR)/src_libibverbs_la-sysfs.Tpo" -c -o src_libibverbs_la-sysfs.lo `test -f 'src/sysfs.c' || echo '$(srcdir)/'`src/sysfs.c; \
+ at am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/src_libibverbs_la-sysfs.Tpo" "$(DEPDIR)/src_libibverbs_la-sysfs.Plo"; else rm -f "$(DEPDIR)/src_libibverbs_la-sysfs.Tpo"; exit 1; fi
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	source='src/sysfs.c' object='src_libibverbs_la-sysfs.lo' libtool=yes @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_libibverbs_la_CFLAGS) $(CFLAGS) -c -o src_libibverbs_la-sysfs.lo `test -f 'src/sysfs.c' || echo '$(srcdir)/'`src/sysfs.c
+
 src_libibverbs_la-verbs.lo: src/verbs.c
 @am__fastdepCC_TRUE@	if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(src_libibverbs_la_CFLAGS) $(CFLAGS) -MT src_libibverbs_la-verbs.lo -MD -MP -MF "$(DEPDIR)/src_libibverbs_la-verbs.Tpo" -c -o src_libibverbs_la-verbs.lo `test -f 'src/verbs.c' || echo '$(srcdir)/'`src/verbs.c; \
 @am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/src_libibverbs_la-verbs.Tpo" "$(DEPDIR)/src_libibverbs_la-verbs.Plo"; else rm -f "$(DEPDIR)/src_libibverbs_la-verbs.Tpo"; exit 1; fi
diff --git a/configure b/configure
index 753d672..28aaa2d 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for libibverbs 1.0.2.
+# Generated by GNU Autoconf 2.59 for libibverbs 1.0.3.
 #
 # Report bugs to <openib-general at openib.org>.
 #
@@ -423,8 +423,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='libibverbs'
 PACKAGE_TARNAME='libibverbs'
-PACKAGE_VERSION='1.0.2'
-PACKAGE_STRING='libibverbs 1.0.2'
+PACKAGE_VERSION='1.0.3'
+PACKAGE_STRING='libibverbs 1.0.3'
 PACKAGE_BUGREPORT='openib-general at openib.org'
 
 ac_unique_file="src/ibverbs.h"
@@ -954,7 +954,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures libibverbs 1.0.2 to adapt to many kinds of systems.
+\`configure' configures libibverbs 1.0.3 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1020,7 +1020,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of libibverbs 1.0.2:";;
+     short | recursive ) echo "Configuration of libibverbs 1.0.3:";;
    esac
   cat <<\_ACEOF
 
@@ -1159,7 +1159,7 @@ fi
 test -n "$ac_init_help" && exit 0
 if $ac_init_version; then
   cat <<\_ACEOF
-libibverbs configure 1.0.2
+libibverbs configure 1.0.3
 generated by GNU Autoconf 2.59
 
 Copyright (C) 2003 Free Software Foundation, Inc.
@@ -1173,7 +1173,7 @@ cat >&5 <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by libibverbs $as_me 1.0.2, which was
+It was created by libibverbs $as_me 1.0.3, which was
 generated by GNU Autoconf 2.59.  Invocation command line was
 
   $ $0 $@
@@ -1819,7 +1819,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE=libibverbs
- VERSION=1.0.2
+ VERSION=1.0.3
 
 
 cat >>confdefs.h <<_ACEOF
@@ -21542,7 +21542,7 @@ _ASBOX
 } >&5
 cat >&5 <<_CSEOF
 
-This file was extended by libibverbs $as_me 1.0.2, which was
+This file was extended by libibverbs $as_me 1.0.3, which was
 generated by GNU Autoconf 2.59.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -21605,7 +21605,7 @@ _ACEOF
 
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-libibverbs config.status 1.0.2
+libibverbs config.status 1.0.3
 configured by $0, generated by GNU Autoconf 2.59,
   with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/configure.in b/configure.in
index 6530d52..d86f5e4 100644
--- a/configure.in
+++ b/configure.in
@@ -1,11 +1,11 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.57)
-AC_INIT(libibverbs, 1.0.2, openib-general at openib.org)
+AC_INIT(libibverbs, 1.0.3, openib-general at openib.org)
 AC_CONFIG_SRCDIR([src/ibverbs.h])
 AC_CONFIG_AUX_DIR(config)
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(libibverbs, 1.0.2)
+AM_INIT_AUTOMAKE(libibverbs, 1.0.3)
 
 AM_PROG_LIBTOOL
 
diff --git a/examples/asyncwatch.c b/examples/asyncwatch.c
index 3c8351d..792da48 100644
--- a/examples/asyncwatch.c
+++ b/examples/asyncwatch.c
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: asyncwatch.c 5401 2006-02-14 03:38:30Z roland $
+ * $Id: asyncwatch.c 5971 2006-03-23 00:48:03Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -42,6 +42,38 @@
 
 #include <infiniband/verbs.h>
 
+static const char *event_name_str(enum ibv_event_type event_type)
+{
+	switch (event_type) {
+	case IBV_EVENT_DEVICE_FATAL:
+		return "IBV_EVENT_DEVICE_FATAL";
+	case IBV_EVENT_PORT_ACTIVE:
+		return "IBV_EVENT_PORT_ACTIVE";
+	case IBV_EVENT_PORT_ERR:
+		return "IBV_EVENT_PORT_ERR";
+	case IBV_EVENT_LID_CHANGE:
+		return "IBV_EVENT_LID_CHANGE";
+	case IBV_EVENT_PKEY_CHANGE:
+		return "IBV_EVENT_PKEY_CHANGE";
+	case IBV_EVENT_SM_CHANGE:
+		return "IBV_EVENT_SM_CHANGE";
+
+	case IBV_EVENT_CQ_ERR:
+	case IBV_EVENT_QP_FATAL:
+	case IBV_EVENT_QP_REQ_ERR:
+	case IBV_EVENT_QP_ACCESS_ERR:
+	case IBV_EVENT_COMM_EST:
+	case IBV_EVENT_SQ_DRAINED:
+	case IBV_EVENT_PATH_MIG:
+	case IBV_EVENT_PATH_MIG_ERR:
+	case IBV_EVENT_SRQ_ERR:
+	case IBV_EVENT_SRQ_LIMIT_REACHED:
+	case IBV_EVENT_QP_LAST_WQE_REACHED:
+	default:
+		return "unexpected";
+	}
+}
+
 int main(int argc, char *argv[])
 {
 	struct ibv_device **dev_list;
@@ -73,8 +105,9 @@ int main(int argc, char *argv[])
 		if (ibv_get_async_event(context, &event))
 			return 1;
 
-		printf("  event_type %d, port %d\n", event.event_type,
-		       event.element.port_num);
+		printf("  event_type %s (%d), port %d\n",
+		       event_name_str(event.event_type),
+		       event.event_type, event.element.port_num);
 
 		ibv_ack_async_event(&event);
 	}
diff --git a/include/infiniband/arch.h b/include/infiniband/arch.h
index 95669bd..35c50ae 100644
--- a/include/infiniband/arch.h
+++ b/include/infiniband/arch.h
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: arch.h 3340 2005-09-07 22:17:35Z roland $
+ * $Id: arch.h 6849 2006-05-01 23:10:33Z roland $
  */
 
 #ifndef INFINIBAND_ARCH_H
@@ -76,10 +76,14 @@ static inline uint64_t ntohll(uint64_t x) { return x; }
 
 #define mb()	asm volatile("sync" ::: "memory")
 
-#elif defined(__sparc__)
+#elif defined(__sparc_v9__)
 
 #define mb()	asm volatile("membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad" ::: "memory")
 
+#elif defined(__sparc__)
+
+#define mb()	asm volatile("sync" ::: "memory")
+
 #else
 
 #warning No architecture specific defines found.  Using generic implementation.
diff --git a/include/infiniband/driver.h b/include/infiniband/driver.h
index 579ccb3..3b53551 100644
--- a/include/infiniband/driver.h
+++ b/include/infiniband/driver.h
@@ -31,7 +31,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: driver.h 5424 2006-02-15 22:48:01Z roland $
+ * $Id: driver.h 6432 2006-04-11 23:27:38Z roland $
  */
 
 #ifndef INFINIBAND_DRIVER_H
@@ -136,4 +136,12 @@ int ibv_cmd_destroy_ah(struct ibv_ah *ah);
 int ibv_cmd_attach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
 int ibv_cmd_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
 
+/*
+ * sysfs helper functions
+ */
+const char *ibv_get_sysfs_path(void);
+
+int ibv_read_sysfs_file(const char *dir, const char *file,
+			char *buf, size_t size);
+
 #endif /* INFINIBAND_DRIVER_H */
diff --git a/include/infiniband/marshall.h b/include/infiniband/marshall.h
index d6bd38f..fe2bb1e 100644
--- a/include/infiniband/marshall.h
+++ b/include/infiniband/marshall.h
@@ -46,17 +46,38 @@
 #  define END_C_DECLS
 #endif /* __cplusplus */
 
+#if __GNUC__ >= 3
+#  define __attribute_deprecated	__attribute__((deprecated))
+#else
+#  define __attribute_deprecated
+#endif
+
 BEGIN_C_DECLS
 
+void ibv_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
+				struct ibv_kern_qp_attr *src);
+
+void ibv_copy_path_rec_from_kern(struct ibv_sa_path_rec *dst,
+				 struct ibv_kern_path_rec *src);
+
+void ibv_copy_path_rec_to_kern(struct ibv_kern_path_rec *dst,
+			       struct ibv_sa_path_rec *src);
+
+/*
+ * Obsolete, deprecated names.  Will be removed in libibverbs 1.1.
+ */
+
 void ib_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
-			       struct ibv_kern_qp_attr *src);
+			       struct ibv_kern_qp_attr *src) __attribute_deprecated;
 
 void ib_copy_path_rec_from_kern(struct ib_sa_path_rec *dst,
-				struct ib_kern_path_rec *src);
+				struct ib_kern_path_rec *src) __attribute_deprecated;
 
 void ib_copy_path_rec_to_kern(struct ib_kern_path_rec *dst,
-			      struct ib_sa_path_rec *src);
+			      struct ib_sa_path_rec *src) __attribute_deprecated;
 
 END_C_DECLS
 
+#undef __attribute_deprecated
+
 #endif /* INFINIBAND_MARSHALL_H */
diff --git a/include/infiniband/sa-kern-abi.h b/include/infiniband/sa-kern-abi.h
index fe1155e..4927d11 100644
--- a/include/infiniband/sa-kern-abi.h
+++ b/include/infiniband/sa-kern-abi.h
@@ -30,12 +30,17 @@
  * SOFTWARE.
  */
 
-#ifndef SA_KERN_ABI_H
-#define SA_KERN_ABI_H
+#ifndef INFINIBAND_SA_KERN_ABI_H
+#define INFINIBAND_SA_KERN_ABI_H
 
 #include <linux/types.h>
 
-struct ib_kern_path_rec {
+/*
+ * Obsolete, deprecated names.  Will be removed in libibverbs 1.1.
+ */
+#define ib_kern_path_rec	ibv_kern_path_rec
+
+struct ibv_kern_path_rec {
 	__u8  dgid[16];
 	__u8  sgid[16];
 	__u16 dlid;
@@ -57,4 +62,4 @@ struct ib_kern_path_rec {
 	__u8  preference;
 };
 
-#endif /* SA_KERN_ABI_H */
+#endif /* INFINIBAND_SA_KERN_ABI_H */
diff --git a/include/infiniband/sa.h b/include/infiniband/sa.h
index 951da37..dc2f3b5 100644
--- a/include/infiniband/sa.h
+++ b/include/infiniband/sa.h
@@ -33,40 +33,19 @@
  * $Id: sa.h 2616 2005-06-15 15:22:39Z halr $
  */
 
-#ifndef IB_SA_H
-#define IB_SA_H
+#ifndef INFINIBAND_SA_H
+#define INFINIBAND_SA_H
 
 #include <infiniband/verbs.h>
 
-enum ib_sa_rate {
-	IB_SA_RATE_2_5_GBPS = 2,
-	IB_SA_RATE_5_GBPS   = 5,
-	IB_SA_RATE_10_GBPS  = 3,
-	IB_SA_RATE_20_GBPS  = 6,
-	IB_SA_RATE_30_GBPS  = 4,
-	IB_SA_RATE_40_GBPS  = 7,
-	IB_SA_RATE_60_GBPS  = 8,
-	IB_SA_RATE_80_GBPS  = 9,
-	IB_SA_RATE_120_GBPS = 10
-};
-
-static inline int ib_sa_rate_enum_to_int(enum ib_sa_rate rate)
-{
-	switch (rate) {
-	case IB_SA_RATE_2_5_GBPS: return  1;
-	case IB_SA_RATE_5_GBPS:   return  2;
-	case IB_SA_RATE_10_GBPS:  return  4;
-	case IB_SA_RATE_20_GBPS:  return  8;
-	case IB_SA_RATE_30_GBPS:  return 12;
-	case IB_SA_RATE_40_GBPS:  return 16;
-	case IB_SA_RATE_60_GBPS:  return 24;
-	case IB_SA_RATE_80_GBPS:  return 32;
-	case IB_SA_RATE_120_GBPS: return 48;
-	default: 	          return -1;
-	}
-}
+/*
+ * Obsolete, deprecated names.  Will be removed in libibverbs 1.1.
+ */
+#define ib_sa_path_rec		ibv_sa_path_rec
+#define ib_sa_mcmember_rec	ibv_sa_mcmember_rec
+#define ib_sa_service_rec	ibv_sa_service_rec
 
-struct ib_sa_path_rec {
+struct ibv_sa_path_rec {
 	/* reserved */
 	/* reserved */
 	union ibv_gid dgid;
@@ -92,7 +71,7 @@ struct ib_sa_path_rec {
 	uint8_t       preference;
 };
 
-struct ib_sa_mcmember_rec {
+struct ibv_sa_mcmember_rec {
 	union ibv_gid mgid;
 	union ibv_gid port_gid;
 	uint32_t      qkey;
@@ -113,7 +92,7 @@ struct ib_sa_mcmember_rec {
 	int           proxy_join;
 };
 
-struct ib_sa_service_rec {
+struct ibv_sa_service_rec {
 	uint64_t      id;
 	union ibv_gid gid;
 	uint16_t      pkey;
@@ -127,4 +106,4 @@ struct ib_sa_service_rec {
 	uint64_t      data64[2];
 };
 
-#endif /* IB_SA_H */
+#endif /* INFINIBAND_SA_H */
diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h
index f566b65..b0f4f33 100644
--- a/include/infiniband/verbs.h
+++ b/include/infiniband/verbs.h
@@ -32,7 +32,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: verbs.h 5642 2006-03-06 22:28:21Z roland $
+ * $Id: verbs.h 6428 2006-04-11 20:40:26Z roland $
  */
 
 #ifndef INFINIBAND_VERBS_H
@@ -51,6 +51,12 @@
 #  define END_C_DECLS
 #endif /* __cplusplus */
 
+#if __GNUC__ >= 3
+#  define __attribute_const __attribute__((const))
+#else
+#  define __attribute_const
+#endif
+
 BEGIN_C_DECLS
 
 union ibv_gid {
@@ -306,6 +312,20 @@ enum ibv_rate {
 	IBV_RATE_120_GBPS = 10
 };
 
+/**
+ * ibv_rate_to_mult - Convert the IB rate enum to a multiple of the
+ * base rate of 2.5 Gbit/sec.  For example, IBV_RATE_5_GBPS will be
+ * converted to 2, since 5 Gbit/sec is 2 * 2.5 Gbit/sec.
+ * @rate: rate to convert.
+ */
+int ibv_rate_to_mult(enum ibv_rate rate) __attribute_const;
+
+/**
+ * mult_to_ibv_rate - Convert a multiple of 2.5 Gbit/sec to an IB rate enum.
+ * @mult: multiple to convert.
+ */
+enum ibv_rate mult_to_ibv_rate(int mult) __attribute_const;
+
 struct ibv_ah_attr {
 	struct ibv_global_route	grh;
 	uint16_t		dlid;
@@ -795,7 +815,13 @@ static inline int ibv_poll_cq(struct ibv_cq *cq, int num_entries, struct ibv_wc
 }
 
 /**
- * ibv_req_notify_cq - Request completion notification on a CQ.
+ * ibv_req_notify_cq - Request completion notification on a CQ.  An
+ *   event will be added to the completion channel associated with the
+ *   CQ when an entry is added to the CQ.
+ * @cq: The completion queue to request notification for.
+ * @solicited_only: If non-zero, an event will be generated only for
+ *   the next solicited CQ entry.  If zero, any CQ entry, solicited or
+ *   not, will generate an event.
  */
 static inline int ibv_req_notify_cq(struct ibv_cq *cq, int solicited_only)
 {
@@ -943,4 +969,6 @@ int ibv_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
 
 END_C_DECLS
 
+#  undef __attribute_const
+
 #endif /* INFINIBAND_VERBS_H */
diff --git a/libibverbs.spec b/libibverbs.spec
index 26ed10a..2ab18e9 100644
--- a/libibverbs.spec
+++ b/libibverbs.spec
@@ -1,19 +1,19 @@
-# $Id: libibverbs.spec.in 5805 2006-03-14 07:33:42Z roland $
+# $Id: libibverbs.spec.in 6354 2006-04-10 04:57:58Z roland $
 
-%define ver      1.0.2
+%define ver      1.0.3
 
 Name: libibverbs
-Version: 1.0.2
+Version: 1.0.3
 Release: 1%{?dist}
 Summary: A library for direct userspace use of InfiniBand
 
 Group: System Environment/Libraries
 License: GPL/BSD
 Url: http://openib.org/
-Source: http://openib.org/downloads/libibverbs-1.0.2.tar.gz
+Source: http://openib.org/downloads/libibverbs-1.0.3.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
-BuildRequires: sysfsutils-devel
+BuildRequires: %{_includedir}/sysfs/libsysfs.h
 
 %description
 libibverbs is a library that allows userspace processes to use
@@ -27,7 +27,7 @@ also be installed.
 %package devel
 Summary: Development files for the libibverbs library
 Group: System Environment/Libraries
-Requires: %{name} = %{version}-%{release} sysfsutils-devel
+Requires: %{name} = %{version}-%{release} %{_includedir}/sysfs/libsysfs.h
 
 %description devel
 Static libraries and header files for the libibverbs verbs library.
@@ -77,7 +77,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/*
 
 %changelog
-* Mon Mar 13 2006 Roland Dreier <rdreier at cisco.com> - 1.0.2-1
+* Mon Mar 14 2006 Roland Dreier <rdreier at cisco.com> - 1.0.3-1
 - New upstream release
 
 * Mon Mar 13 2006 Roland Dreier <rdreier at cisco.com> - 1.0.1-1
diff --git a/libibverbs.spec.in b/libibverbs.spec.in
index 33d089a..6ba49d0 100644
--- a/libibverbs.spec.in
+++ b/libibverbs.spec.in
@@ -1,19 +1,19 @@
-# $Id: libibverbs.spec.in 5805 2006-03-14 07:33:42Z roland $
+# $Id: libibverbs.spec.in 6354 2006-04-10 04:57:58Z roland $
 
 %define ver      @VERSION@
 
 Name: libibverbs
-Version: 1.0.2
+Version: 1.0.3
 Release: 1%{?dist}
 Summary: A library for direct userspace use of InfiniBand
 
 Group: System Environment/Libraries
 License: GPL/BSD
 Url: http://openib.org/
-Source: http://openib.org/downloads/libibverbs-1.0.2.tar.gz
+Source: http://openib.org/downloads/libibverbs-1.0.3.tar.gz
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
-BuildRequires: sysfsutils-devel
+BuildRequires: %{_includedir}/sysfs/libsysfs.h
 
 %description
 libibverbs is a library that allows userspace processes to use
@@ -27,7 +27,7 @@ also be installed.
 %package devel
 Summary: Development files for the libibverbs library
 Group: System Environment/Libraries
-Requires: %{name} = %{version}-%{release} sysfsutils-devel
+Requires: %{name} = %{version}-%{release} %{_includedir}/sysfs/libsysfs.h
 
 %description devel
 Static libraries and header files for the libibverbs verbs library.
@@ -77,7 +77,7 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/*
 
 %changelog
-* Mon Mar 13 2006 Roland Dreier <rdreier at cisco.com> - 1.0.2-1
+* Mon Mar 14 2006 Roland Dreier <rdreier at cisco.com> - 1.0.3-1
 - New upstream release
 
 * Mon Mar 13 2006 Roland Dreier <rdreier at cisco.com> - 1.0.1-1
diff --git a/src/cmd.c b/src/cmd.c
index 64bb5f7..4839183 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -31,7 +31,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: cmd.c 5478 2006-02-23 20:41:50Z roland $
+ * $Id: cmd.c 5882 2006-03-17 23:55:09Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -40,6 +40,7 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <alloca.h>
 
diff --git a/src/device.c b/src/device.c
index 92d79bd..0285d20 100644
--- a/src/device.c
+++ b/src/device.c
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: device.c 4466 2005-12-14 20:44:36Z roland $
+ * $Id: device.c 6432 2006-04-11 23:27:38Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -42,6 +42,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <alloca.h>
 
 #include <infiniband/arch.h>
@@ -86,16 +87,16 @@ const char *ibv_get_device_name(struct ibv_device *device)
 
 uint64_t ibv_get_device_guid(struct ibv_device *device)
 {
-	struct sysfs_attribute *attr;
+	char attr[24];
 	uint64_t guid = 0;
 	uint16_t parts[4];
 	int i;
 
-	attr = sysfs_get_classdev_attr(device->ibdev, "node_guid");
-	if (!attr)
+	if (ibv_read_sysfs_file(device->ibdev->path, "node_guid",
+				attr, sizeof attr) < 0)
 		return 0;
 
-	if (sscanf(attr->value, "%hx:%hx:%hx:%hx",
+	if (sscanf(attr, "%hx:%hx:%hx:%hx",
 		   parts, parts + 1, parts + 2, parts + 3) != 4)
 		return 0;
 
diff --git a/src/init.c b/src/init.c
index 6acaf75..7dbcede 100644
--- a/src/init.c
+++ b/src/init.c
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: init.c 5801 2006-03-14 00:24:55Z roland $
+ * $Id: init.c 6432 2006-04-11 23:27:38Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -64,8 +64,11 @@ static void load_driver(char *so_path)
 	struct ibv_driver *driver;
 
 	dlhandle = dlopen(so_path, RTLD_NOW);
-	if (!dlhandle)
+	if (!dlhandle) {
+		fprintf(stderr, PFX "Warning: couldn't load driver %s: %s\n",
+			so_path, dlerror());
 		return;
+	}
 
 	dlerror();
 	init_func = dlsym(dlhandle, "openib_driver_init");
@@ -118,24 +121,21 @@ static void find_drivers(char *dir)
 static struct ibv_device *init_drivers(struct sysfs_class_device *verbs_dev)
 {
 	struct sysfs_class_device *ib_dev;
-	struct sysfs_attribute *attr;
 	struct ibv_driver *driver;
 	struct ibv_device *dev;
 	char ibdev_name[64];
 
-	attr = sysfs_get_classdev_attr(verbs_dev, "ibdev");
-	if (!attr) {
+	if (ibv_read_sysfs_file(verbs_dev->path, "ibdev",
+				ibdev_name, sizeof ibdev_name) < 0) {
 		fprintf(stderr, PFX "Warning: no ibdev class attr for %s\n",
 			verbs_dev->name);
 		return NULL;
 	}
 
-	sscanf(attr->value, "%63s", ibdev_name);
-
 	ib_dev = sysfs_open_class_device("infiniband", ibdev_name);
 	if (!ib_dev) {
 		fprintf(stderr, PFX "Warning: no infiniband class device %s for %s\n",
-			attr->value, verbs_dev->name);
+			ibdev_name, verbs_dev->name);
 		return NULL;
 	}
 
@@ -161,44 +161,34 @@ static struct ibv_device *init_drivers(struct sysfs_class_device *verbs_dev)
 
 static int check_abi_version(void)
 {
-	char path[256];
-	struct sysfs_attribute *attr;
-	int ret = -1;
+	const char *path;
+	char value[8];
 
-	if (sysfs_get_mnt_path(path, sizeof path)) {
+	path = ibv_get_sysfs_path();
+	if (!path) {
 		fprintf(stderr, PFX "Fatal: couldn't find sysfs mount.\n");
 		return -1;
 	}
 
-	strncat(path, "/class/infiniband_verbs/abi_version", sizeof path);
-
-	attr = sysfs_open_attribute(path);
-	if (!attr)
-		return -1;
-
-	if (sysfs_read_attribute(attr)) {
+	if (ibv_read_sysfs_file(path, "class/infiniband_verbs/abi_version",
+				value, sizeof value) < 0) {
 		fprintf(stderr, PFX "Fatal: couldn't read uverbs ABI version.\n");
-		goto out;
+		return -1;
 	}
 
-	abi_ver = strtol(attr->value, NULL, 10);
+	abi_ver = strtol(value, NULL, 10);
 
 	if (abi_ver < IB_USER_VERBS_MIN_ABI_VERSION ||
 	    abi_ver > IB_USER_VERBS_MAX_ABI_VERSION) {
 		fprintf(stderr, PFX "Fatal: kernel ABI version %d "
 			"doesn't match library version %d.\n",
 			abi_ver, IB_USER_VERBS_MAX_ABI_VERSION);
-		goto out;
+		return -1;
 	}
 
-	ret = 0;
-
-out:
-	sysfs_close_attribute(attr);
-	return ret;
+	return 0;
 }
 
-
 HIDDEN int ibverbs_init(struct ibv_device ***list)
 {
 	char *wr_path, *dir;
@@ -218,7 +208,7 @@ HIDDEN int ibverbs_init(struct ibv_device ***list)
 	find_drivers(default_path);
 
 	/*
-	 * Only follow the path passed in through the calling user's
+	 * Only follow use path passed in through the calling user's
 	 * environment if we're not running SUID.
 	 */
 	if (getuid() == geteuid()) {
diff --git a/src/libibverbs.map b/src/libibverbs.map
index 2bebc5d..fba7026 100644
--- a/src/libibverbs.map
+++ b/src/libibverbs.map
@@ -64,6 +64,14 @@ IBVERBS_1.0 {
 		ibv_cmd_destroy_ah;
 		ibv_cmd_attach_mcast;
 		ibv_cmd_detach_mcast;
+		ibv_copy_qp_attr_from_kern;
+		ibv_copy_path_rec_from_kern;
+		ibv_copy_path_rec_to_kern;
+		ibv_rate_to_mult;
+		mult_to_ibv_rate;
+		ibv_get_sysfs_path;
+		ibv_read_sysfs_file;
+
 		ib_copy_qp_attr_from_kern;
 		ib_copy_path_rec_from_kern;
 		ib_copy_path_rec_to_kern;
diff --git a/src/marshall.c b/src/marshall.c
index 6f6c387..1284f64 100644
--- a/src/marshall.c
+++ b/src/marshall.c
@@ -36,8 +36,8 @@
 
 #include <infiniband/marshall.h>
 
-static void ib_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
-				      struct ibv_kern_ah_attr *src)
+static void ibv_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
+				       struct ibv_kern_ah_attr *src)
 {
 	memcpy(dst->grh.dgid.raw, src->grh.dgid, sizeof dst->grh.dgid);
 	dst->grh.flow_label = src->grh.flow_label;
@@ -53,8 +53,8 @@ static void ib_copy_ah_attr_from_kern(struct ibv_ah_attr *dst,
 	dst->port_num = src->port_num;
 }
 
-void ib_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
-			       struct ibv_kern_qp_attr *src)
+void ibv_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
+				struct ibv_kern_qp_attr *src)
 {
 	dst->cur_qp_state = src->cur_qp_state;
 	dst->path_mtu = src->path_mtu;
@@ -71,8 +71,8 @@ void ib_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
 	dst->cap.max_recv_sge = src->max_recv_sge;
 	dst->cap.max_inline_data = src->max_inline_data;
 
-	ib_copy_ah_attr_from_kern(&dst->ah_attr, &src->ah_attr);
-	ib_copy_ah_attr_from_kern(&dst->alt_ah_attr, &src->alt_ah_attr);
+	ibv_copy_ah_attr_from_kern(&dst->ah_attr, &src->ah_attr);
+	ibv_copy_ah_attr_from_kern(&dst->alt_ah_attr, &src->alt_ah_attr);
 
 	dst->pkey_index = src->pkey_index;
 	dst->alt_pkey_index = src->alt_pkey_index;
@@ -89,8 +89,8 @@ void ib_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
 	dst->alt_timeout = src->alt_timeout;
 }
 
-void ib_copy_path_rec_from_kern(struct ib_sa_path_rec *dst,
-				struct ib_kern_path_rec *src)
+void ibv_copy_path_rec_from_kern(struct ibv_sa_path_rec *dst,
+				 struct ibv_kern_path_rec *src)
 {
 	memcpy(dst->dgid.raw, src->dgid, sizeof dst->dgid);
 	memcpy(dst->sgid.raw, src->sgid, sizeof dst->sgid);
@@ -114,8 +114,8 @@ void ib_copy_path_rec_from_kern(struct ib_sa_path_rec *dst,
 	dst->packet_life_time_selector = src->packet_life_time_selector;
 }
 
-void ib_copy_path_rec_to_kern(struct ib_kern_path_rec *dst,
-			      struct ib_sa_path_rec *src)
+void ibv_copy_path_rec_to_kern(struct ibv_kern_path_rec *dst,
+			       struct ibv_sa_path_rec *src)
 {
 	memcpy(dst->dgid, src->dgid.raw, sizeof src->dgid);
 	memcpy(dst->sgid, src->sgid.raw, sizeof src->sgid);
@@ -138,3 +138,21 @@ void ib_copy_path_rec_to_kern(struct ib_kern_path_rec *dst,
 	dst->preference		= src->preference;
 	dst->packet_life_time_selector = src->packet_life_time_selector;
 }
+
+void ib_copy_qp_attr_from_kern(struct ibv_qp_attr *dst,
+			       struct ibv_kern_qp_attr *src)
+{
+	return ibv_copy_qp_attr_from_kern(dst, src);
+}
+
+void ib_copy_path_rec_from_kern(struct ib_sa_path_rec *dst,
+				struct ib_kern_path_rec *src)
+{
+	return ibv_copy_path_rec_from_kern(dst, src);
+}
+
+void ib_copy_path_rec_to_kern(struct ib_kern_path_rec *dst,
+			      struct ib_sa_path_rec *src)
+{
+	return ibv_copy_path_rec_to_kern(dst, src);
+}
diff --git a/src/memory.c b/src/memory.c
index f2afbb5..83842e5 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: memory.c 1505 2005-01-10 23:47:29Z roland $
+ * $Id: memory.c 5882 2006-03-17 23:55:09Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -38,6 +38,7 @@
 
 #include <sys/mman.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <stdint.h>
 
 #include "ibverbs.h"
diff --git a/examples/asyncwatch.c b/src/sysfs.c
similarity index 57%
copy from examples/asyncwatch.c
copy to src/sysfs.c
index 3c8351d..52fbd5a 100644
--- a/examples/asyncwatch.c
+++ b/src/sysfs.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005 Topspin Communications.  All rights reserved.
+ * Copyright (c) 2006 Cisco Systems.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -29,7 +29,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: asyncwatch.c 5401 2006-02-14 03:38:30Z roland $
+ * $Id$
  */
 
 #if HAVE_CONFIG_H
@@ -37,47 +37,67 @@
 #endif /* HAVE_CONFIG_H */
 
 #include <stdio.h>
-#include <endian.h>
-#include <byteswap.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
-#include <infiniband/verbs.h>
+#include "ibverbs.h"
 
-int main(int argc, char *argv[])
+static char *sysfs_path;
+
+const char *ibv_get_sysfs_path(void)
 {
-	struct ibv_device **dev_list;
-	struct ibv_context *context;
-	struct ibv_async_event event;
-
-	dev_list = ibv_get_device_list(NULL);
-	if (!dev_list) {
-		fprintf(stderr, "No IB devices found\n");
-		return 1;
-	}
+	char *env = NULL;
 
-	if (!*dev_list) {
-		fprintf(stderr, "No IB devices found\n");
-		return 1;
-	}
+	if (sysfs_path)
+		return sysfs_path;
 
-	context = ibv_open_device(*dev_list);
-	if (!context) {
-		fprintf(stderr, "Couldn't get context for %s\n",
-			ibv_get_device_name(*dev_list));
-		return 1;
-	}
+	/*
+	 * Only follow use path passed in through the calling user's
+	 * environment if we're not running SUID.
+	 */
+	if (getuid() == geteuid())
+		env = getenv("SYSFS_PATH");
 
-	printf("%s: async event FD %d\n",
-	       ibv_get_device_name(*dev_list), context->async_fd);
+	if (env) {
+		int len;
 
-	while (1) {
-		if (ibv_get_async_event(context, &event))
-			return 1;
+		sysfs_path = strndup(env, 256);
+		len = strlen(sysfs_path);
+		while (len > 0 && sysfs_path[len - 1] == '/') {
+			--len;
+			sysfs_path[len] = '\0';
+		}
+	} else
+		sysfs_path = "/sys";
 
-		printf("  event_type %d, port %d\n", event.event_type,
-		       event.element.port_num);
+	return sysfs_path;
+}
 
-		ibv_ack_async_event(&event);
+int ibv_read_sysfs_file(const char *dir, const char *file,
+			char *buf, size_t size)
+{
+	char *path;
+	int fd;
+	int len;
+
+	asprintf(&path, "%s/%s", dir, file);
+
+	fd = open(path, O_RDONLY);
+	if (fd < 0) {
+		free(path);
+		return -1;
 	}
 
-	return 0;
+	len = read(fd, buf, size);
+
+	close(fd);
+	free(path);
+
+	if (len > 0 && buf[len - 1] == '\n')
+		buf[--len] = '\0';
+
+	return len;
 }
diff --git a/src/verbs.c b/src/verbs.c
index 2e6cb9a..9348a49 100644
--- a/src/verbs.c
+++ b/src/verbs.c
@@ -30,7 +30,7 @@
  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  *
- * $Id: verbs.c 5801 2006-03-14 00:24:55Z roland $
+ * $Id: verbs.c 6432 2006-04-11 23:27:38Z roland $
  */
 
 #if HAVE_CONFIG_H
@@ -40,10 +40,43 @@
 #include <stdio.h>
 #include <netinet/in.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <errno.h>
 
 #include "ibverbs.h"
 
+int ibv_rate_to_mult(enum ibv_rate rate)
+{
+	switch (rate) {
+	case IBV_RATE_2_5_GBPS: return  1;
+	case IBV_RATE_5_GBPS:   return  2;
+	case IBV_RATE_10_GBPS:  return  4;
+	case IBV_RATE_20_GBPS:  return  8;
+	case IBV_RATE_30_GBPS:  return 12;
+	case IBV_RATE_40_GBPS:  return 16;
+	case IBV_RATE_60_GBPS:  return 24;
+	case IBV_RATE_80_GBPS:  return 32;
+	case IBV_RATE_120_GBPS: return 48;
+	default:           return -1;
+	}
+}
+
+enum ibv_rate mult_to_ibv_rate(int mult)
+{
+	switch (mult) {
+	case 1:  return IBV_RATE_2_5_GBPS;
+	case 2:  return IBV_RATE_5_GBPS;
+	case 4:  return IBV_RATE_10_GBPS;
+	case 8:  return IBV_RATE_20_GBPS;
+	case 12: return IBV_RATE_30_GBPS;
+	case 16: return IBV_RATE_40_GBPS;
+	case 24: return IBV_RATE_60_GBPS;
+	case 32: return IBV_RATE_80_GBPS;
+	case 48: return IBV_RATE_120_GBPS;
+	default: return IBV_RATE_MAX;
+	}
+}
+
 int ibv_query_device(struct ibv_context *context,
 		     struct ibv_device_attr *device_attr)
 {
@@ -59,63 +92,45 @@ int ibv_query_port(struct ibv_context *context, uint8_t port_num,
 int ibv_query_gid(struct ibv_context *context, uint8_t port_num,
 		  int index, union ibv_gid *gid)
 {
-	char *attr_name;
-	struct sysfs_attribute *attr;
+	char name[24];
+	char attr[41];
 	uint16_t val;
 	int i;
-	int ret = -1;
 
-	asprintf(&attr_name, "%s/ports/%d/gids/%d",
-		 context->device->ibdev->path, port_num, index);
+	snprintf(name, sizeof name, "ports/%d/gids/%d", port_num, index);
 
-	attr = sysfs_open_attribute(attr_name);
-	if (!attr)
+	if (ibv_read_sysfs_file(context->device->ibdev->path, name,
+				attr, sizeof attr) < 0)
 		return -1;
 
-	if (sysfs_read_attribute(attr))
-		goto out;
-
 	for (i = 0; i < 8; ++i) {
-		if (sscanf(attr->value + i * 5, "%hx", &val) != 1)
-			goto out;
+		if (sscanf(attr + i * 5, "%hx", &val) != 1)
+			return -1;
 		gid->raw[i * 2    ] = val >> 8;
 		gid->raw[i * 2 + 1] = val & 0xff;
 	}
 
-	ret = 0;
-
-out:
-	sysfs_close_attribute(attr);
-	return ret;
+	return 0;
 }
 
 int ibv_query_pkey(struct ibv_context *context, uint8_t port_num,
 		   int index, uint16_t *pkey)
 {
-	char *attr_name;
-	struct sysfs_attribute *attr;
+	char name[24];
+	char attr[8];
 	uint16_t val;
-	int ret = -1;
 
-	asprintf(&attr_name, "%s/ports/%d/pkeys/%d",
-		 context->device->ibdev->path, port_num, index);
+	snprintf(name, sizeof name, "ports/%d/pkeys/%d", port_num, index);
 
-	attr = sysfs_open_attribute(attr_name);
-	if (!attr)
+	if (ibv_read_sysfs_file(context->device->ibdev->path, name,
+				attr, sizeof attr) < 0)
 		return -1;
 
-	if (sysfs_read_attribute(attr))
-		goto out;
-
-	if (sscanf(attr->value, "%hx", &val) != 1)
-		goto out;
+	if (sscanf(attr, "%hx", &val) != 1)
+		return -1;
 
 	*pkey = htons(val);
-	ret = 0;
-
-out:
-	sysfs_close_attribute(attr);
-	return ret;
+	return 0;
 }
 
 struct ibv_pd *ibv_alloc_pd(struct ibv_context *context)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ofed/libibverbs.git



More information about the Pkg-ofed-commits mailing list