[PATCH rdma-core 2/2] umad: Do not check for umad sysfs files in umad_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jason Gunthorpe <jgg@xxxxxxxxxxxx>

Now that we don't load the umad module if the HW doesn't use it (eg
for roce only hardware) umad_init is failing to read the ABI version
from the kernel.

Applications still want to use some libibumad services that are not
related to the char device, so move the version check to umad_open_port
instead.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxxxx>
---
 libibumad/man/umad_init.3.md | 22 +++++++++----------
 libibumad/umad.c             | 41 ++++++++++++++++++++++++------------
 2 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/libibumad/man/umad_init.3.md b/libibumad/man/umad_init.3.md
index b55676d5f96908..68fff5d053d452 100644
--- a/libibumad/man/umad_init.3.md
+++ b/libibumad/man/umad_init.3.md
@@ -24,22 +24,22 @@ int umad_done(void);
 
 # DESCRIPTION
 
-**umad_init()** initializes the umad library for use. Must be called before
-any other call to this library.
-
-**umad_done()** finalizes the use of the umad library.
+**umad_init()** and **umad_done()** do nothing.
 
 # RETURN VALUE
 
-**umad_init()** and **umad_done()** return 0 on success, and -1 on error.
-Error is returned from **umad_init()** if infiniband umad can't be opened, or
-the abi version doesn't match. There are no errors currently returned by
-**umad_done().**
+Always 0.
+
+# COMPATABILITY
 
-# NOTES
+Versions prior to releaes 18 of the library require **umad_init()** to be
+called prior to using any other library functions. Old versions could return a
+failure code of -1 from **umad_init()**.
 
-If an error occurs during the library initialization, no further use of the
-umad library should be attempted.
+For compatibility applications should continue to cal **umad_init()**, and
+check the return code, prior to calling other **umad_** functions.  If
+**umad_init()** returns an error then, no further use of the umad library
+should be attempted.
 
 # AUTHORS
 
diff --git a/libibumad/umad.c b/libibumad/umad.c
index dcb2c6809eb12c..08efb089d990cc 100644
--- a/libibumad/umad.c
+++ b/libibumad/umad.c
@@ -90,9 +90,31 @@ static int umaddebug = 0;
 static const char *def_ca_name = "mthca0";
 static int def_ca_port = 1;
 
-static unsigned abi_version;
 static unsigned new_user_mad_api;
 
+static unsigned int get_abi_version(void)
+{
+	static unsigned int abi_version;
+
+	if (abi_version != 0)
+		return abi_version & 0x7FFFFFFF;
+
+	if (sys_read_uint(IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, &abi_version) <
+	    0) {
+		IBWARN("can't read ABI version from %s/%s (%m): is ib_umad module loaded?",
+		       IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE);
+		abi_version = 1 << 31;
+		return 0;
+	}
+
+	if (abi_version < IB_UMAD_ABI_VERSION) {
+		abi_version = 1 << 31;
+		return 0;
+	}
+
+	return abi_version;
+}
+
 /*************************************
  * Port
  */
@@ -502,19 +524,6 @@ static int dev_to_umad_id(const char *dev, unsigned port)
 int umad_init(void)
 {
 	TRACE("umad_init");
-	if (sys_read_uint(IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, &abi_version) < 0) {
-		IBWARN
-		    ("can't read ABI version from %s/%s (%m): is ib_umad module loaded?",
-		     IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE);
-		return -1;
-	}
-	if (abi_version < IB_UMAD_ABI_VERSION) {
-		IBWARN
-		    ("wrong ABI version: %s/%s is %d but library minimal ABI is %d",
-		     IB_UMAD_ABI_DIR, IB_UMAD_ABI_FILE, abi_version,
-		     IB_UMAD_ABI_VERSION);
-		return -1;
-	}
 	return 0;
 }
 
@@ -618,9 +627,13 @@ int umad_open_port(const char *ca_name, int portnum)
 {
 	char dev_file[UMAD_DEV_FILE_SZ];
 	int umad_id, fd;
+	unsigned int abi_version = get_abi_version();
 
 	TRACE("ca %s port %d", ca_name, portnum);
 
+	if (!abi_version)
+		return -EOPNOTSUPP;
+
 	if (!(ca_name = resolve_ca_name(ca_name, &portnum)))
 		return -ENODEV;
 
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux