<br><font size=2 face="sans-serif">Hello Roland,</font>
<br>
<br><font size=2 face="sans-serif">does OpenIB 1.0 RC2 (RC3, ...) still
uses libsysfs or is it only change for subversion head (trunk)?</font>
<br><font size=2 face="sans-serif"><br>
Mit freundlichen Gruessen / Kind Regards<br>
Heiko Joerg Schick<br>
</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Roland Dreier <rdreier@cisco.com></b>
</font>
<p><font size=1 face="sans-serif">04/20/2006 09:13 PM</font>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">Christoph Raisch/Germany/IBM@IBMDE,
Heiko J Schick/Germany/IBM@IBMDE, Hoang-Nam Nguyen/Germany/IBM@IBMDE</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top><font size=1 face="sans-serif">openib-general@openib.org</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">[openib-general] [PATCH 2/2]
Wean libehca off of libsysfs</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2><tt>As discussed in <http://thread.gmane.org/gmane.linux.drivers.openib/24250><br>
I would like to start moving the libibverbs interface to lower-level<br>
drivers away from using libsysfs data structures.<br>
<br>
This patch implements that scheme for libehca, and adds an<br>
ibv_driver_init() entry point in a backwards compatible way: it will<br>
work with existing releases of libibverbs 1.0, and should be source<br>
compatible with libibverbs 1.1.<br>
<br>
Compile tested only, as I don't have ehca hardware (yet...). Please<br>
test and apply if it looks good to you.<br>
<br>
Signed-off-by: Roland Dreier <rolandd@cisco.com><br>
<br>
--- src/userspace/libehca/configure.in
(revision 6541)<br>
+++ src/userspace/libehca/configure.in
(working copy)<br>
@@ -16,6 +16,9 @@ AC_CHECK_LIB(ibverbs, <br>
[], <br>
AC_MSG_ERROR([libibverbs
not installed]))<br>
<br>
+dnl Checks for library functions<br>
+AC_CHECK_FUNCS(ibv_read_sysfs_file)<br>
+<br>
dnl Checks for programs.<br>
AC_PROG_CC<br>
AC_OUTPUT([Makefile])<br>
--- src/userspace/libehca/src/ehca_uinit.c
(revision 6541)<br>
+++ src/userspace/libehca/src/ehca_uinit.c
(working copy)<br>
@@ -38,12 +38,19 @@<br>
* $Id: ehca_uinit.c,v 1.6 2006/04/11 13:45:31 nguyen Exp $<br>
*/<br>
<br>
+#if HAVE_CONFIG_H<br>
+# include <config.h><br>
+#endif /* HAVE_CONFIG_H */<br>
+<br>
#include <infiniband/driver.h><br>
#include <stdlib.h><br>
#include <unistd.h><br>
#include <errno.h><br>
#include <sys/mman.h><br>
#include <pthread.h><br>
+#include <sys/types.h><br>
+#include <sys/stat.h><br>
+#include <fcntl.h><br>
<br>
#include "ehca_uclasses.h"<br>
<br>
@@ -144,42 +151,58 @@ static struct ibv_device_ops ehcau_dev_o<br>
.free_context
= ehcau_free_context<br>
};<br>
<br>
-struct ibv_device *openib_driver_init(struct sysfs_class_device *sysdev)<br>
+/*<br>
+ * Keep a private implementation of HAVE_IBV_READ_SYSFS_FILE to handle<br>
+ * old versions of libibverbs that didn't implement it. This can
be<br>
+ * removed when libibverbs 1.0.3 or newer is available "everywhere."<br>
+ */<br>
+#ifndef HAVE_IBV_READ_SYSFS_FILE<br>
+static int ibv_read_sysfs_file(const char *dir, const char *file,<br>
+
char *buf, size_t size)<br>
+{<br>
+
char path[256];<br>
+
int fd;<br>
+
int len;<br>
+<br>
+
snprintf(path, sizeof path, "%s/%s", dir, file);<br>
+<br>
+
fd = open(path, O_RDONLY);<br>
+
if (fd < 0)<br>
+
return
-1;<br>
+<br>
+
len = read(fd, buf, size);<br>
+<br>
+
close(fd);<br>
+<br>
+
if (len > 0 && buf[len - 1] == '\n')<br>
+
buf[--len]
= '\0';<br>
+<br>
+
return len;<br>
+}<br>
+#endif /* HAVE_IBV_READ_SYSFS_FILE */<br>
+<br>
+struct ibv_device *ibv_driver_init(const char *uverbs_sys_path,<br>
+
int abi_version)<br>
{<br>
struct
ehcau_device *my_dev = NULL;<br>
-
struct sysfs_device *sysfs_dev = NULL;<br>
-
struct sysfs_attribute *sysfs_attr = NULL;<br>
-
char *dev_name = NULL;<br>
+
char value[64];<br>
int
num_ports = 0;<br>
<br>
EDEB_EN(7,
"");<br>
<br>
-
/* check devices existence */<br>
-
sysfs_dev = sysfs_get_classdev_device(sysdev);<br>
-
if (sysfs_dev == NULL) {<br>
-
return
NULL;<br>
-
}<br>
<br>
-
sysfs_attr = sysfs_get_device_attr(sysfs_dev, "name");<br>
-
if (sysfs_attr == NULL) {<br>
+
if (ibv_read_sysfs_file(uverbs_sys_path, "device/vendor",<br>
+
value,
sizeof value) < 0)<br>
return NULL;<br>
-
}<br>
-
if (asprintf(&dev_name, "%s", sysfs_attr->value)<0)
{<br>
-
return
NULL;<br>
-
}<br>
-
sysfs_close_attribute(sysfs_attr);<br>
-
if (strcmp("lhca", str_strip(dev_name)) != 0) {<br>
-
free(dev_name);<br>
+<br>
+
if (strcmp("lhca", str_strip(value)) != 0)<br>
return NULL;<br>
-
}<br>
-
free(dev_name);<br>
<br>
-
sysfs_attr = sysfs_get_device_attr(sysfs_dev, "num_ports");<br>
-
if (sysfs_attr == NULL) {<br>
+
if (ibv_read_sysfs_file(uverbs_sys_path, "device/num_ports",<br>
+
value,
sizeof value) < 0)<br>
return NULL;<br>
-
}<br>
-
sscanf(sysfs_attr->value, "%i", &num_ports);<br>
-
sysfs_close_attribute(sysfs_attr);<br>
+<br>
+
sscanf(value, "%i", &num_ports);<br>
if
(num_ports<1) {<br>
return NULL;<br>
}<br>
@@ -188,7 +211,7 @@ struct ibv_device *openib_driver_init(st<br>
my_dev
= malloc(sizeof *my_dev);<br>
if
(!my_dev) {<br>
fprintf(stderr, "Fatal: couldn't allocate device for %s\n",<br>
-
sysdev->name);<br>
+
uverbs_sys_path);<br>
abort();<br>
}<br>
<br>
@@ -198,6 +221,18 @@ struct ibv_device *openib_driver_init(st<br>
return
&my_dev->ibv_dev;<br>
}<br>
<br>
+struct ibv_device *openib_driver_init(struct sysfs_class_device *sysdev)<br>
+{<br>
+
int abi_ver = 0;<br>
+
char value[8];<br>
+<br>
+
if (ibv_read_sysfs_file(sysdev->path, "abi_version",<br>
+
value,
sizeof value) > 0)<br>
+
abi_ver
= strtol(value, NULL, 10);<br>
+<br>
+
return ibv_driver_init(sysdev->path, abi_ver);<br>
+}<br>
+<br>
/** @brief module initialization<br>
*/<br>
int libehca_trlevel = 5;<br>
--- src/userspace/libehca/src/libehca.map
(revision 6541)<br>
+++ src/userspace/libehca/src/libehca.map
(working copy)<br>
@@ -1,5 +1,6 @@<br>
LIBEHCA_1.0 {<br>
global:<br>
+
ibv_driver_init;<br>
openib_driver_init;<br>
ehcau_query_qp;
<br>
ehcau_send_wr_trigger;<br>
</tt></font>
<br>