[openib-general] [PATCH][UVERBS][RFC] node type in ibv_context

Tom Tucker tom at opengridcomputing.com
Mon Apr 24 13:41:07 PDT 2006


Here's a patch that puts a node_type in the ibv_context. 

Signed-off-by: Tom Tucker <tom at opengridcomputing.com>

Index: libibverbs/include/infiniband/verbs.h
===================================================================
--- libibverbs/include/infiniband/verbs.h	(revision 6570)
+++ libibverbs/include/infiniband/verbs.h	(working copy)
@@ -68,11 +68,19 @@
 };
 
 enum ibv_node_type {
+	IBV_NODE_UNKNOWN=-1,
 	IBV_NODE_CA 	= 1,
 	IBV_NODE_SWITCH,
-	IBV_NODE_ROUTER
+	IBV_NODE_ROUTER,
+	IBV_NODE_RNIC
 };
 
+enum ibv_transport_type {
+	IBV_TRANSPORT_UNKNOWN=0,
+	IBV_TRANSPORT_IB=1,
+	IBV_TRANSPORT_IWARP=2
+};
+
 enum ibv_device_cap_flags {
 	IBV_DEVICE_RESIZE_MAX_WR	= 1,
 	IBV_DEVICE_BAD_PKEY_CNTR	= 1 <<  1,
@@ -615,6 +623,7 @@
 };
 
 struct ibv_context {
+	enum ibv_node_type         node_type;
 	struct ibv_device         *device;
 	struct ibv_context_ops	   ops;
 	int                        cmd_fd;
@@ -654,6 +663,33 @@
 uint64_t ibv_get_device_guid(struct ibv_device *device);
 
 /**
+ * ibv_get_transport_type - Return device's network transport type
+ */
+static inline enum ibv_transport_type
+ibv_get_transport_type(struct ibv_context *context)
+{
+	switch (context->node_type) {
+	case IBV_NODE_CA:
+	case IBV_NODE_SWITCH:
+	case IBV_NODE_ROUTER:
+		return IBV_TRANSPORT_IB;
+	case IBV_NODE_RNIC:
+		return IBV_TRANSPORT_IWARP;
+	default:
+		return IBV_TRANSPORT_UNKNOWN;
+	}
+}
+
+/**
+ * ibv_get_node_type - Return device's node type
+ */
+static inline enum ibv_node_type
+ibv_get_node_type(struct ibv_context *context)
+{
+	return context->node_type;
+}
+
+/**
  * ibv_open_device - Initialize device for use
  */
 struct ibv_context *ibv_open_device(struct ibv_device *device);
Index: libibverbs/src/device.c
===================================================================
--- libibverbs/src/device.c	(revision 6570)
+++ libibverbs/src/device.c	(working copy)
@@ -106,6 +106,23 @@
 	return htonll(guid);
 }
 
+static enum ibv_node_type query_node_type(struct ibv_context *context)
+{
+	char node_desc[24];
+	char node_str[24];
+	int node_type;
+
+	if (!context)
+		return IBV_NODE_UNKNOWN;
+
+	if (ibv_read_sysfs_file(context->device->ibdev->path, "node_type",
+				node_desc, sizeof(node_desc)) < 0)
+		return IBV_NODE_UNKNOWN;
+
+	sscanf(node_desc, "%d: %s\n", (int*)&node_type, node_str);
+	return (enum ibv_node_type) node_type;
+}
+
 struct ibv_context *ibv_open_device(struct ibv_device *device)
 {
 	char *devpath;
@@ -128,7 +145,7 @@
 
 	context->device = device;
 	context->cmd_fd = cmd_fd;
-
+	context->node_type = query_node_type(context);
 	return context;
 
 err:





More information about the general mailing list