[openib-general] [PATCH v2 1/2] iWARP changes to libibverbs.

Steve Wise swise at opengridcomputing.com
Tue Jun 20 13:03:08 PDT 2006


Cache the node type (iWARP vs IB) in the ib_device struct to enable
transport-dependent logic.
---

 libibverbs/include/infiniband/verbs.h |   44 ++++++++++++++++++++++++++++++++-
 libibverbs/src/device.c               |   16 ++++++++++++
 2 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/libibverbs/include/infiniband/verbs.h b/libibverbs/include/infiniband/verbs.h
index 7679436..0ff97e9 100644
--- a/libibverbs/include/infiniband/verbs.h
+++ b/libibverbs/include/infiniband/verbs.h
@@ -66,9 +66,17 @@ union ibv_gid {
 };
 
 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 {
@@ -574,6 +582,7 @@ enum {
 
 struct ibv_device {
 	struct ibv_driver      *driver;
+	enum ibv_node_type	node_type;
 	struct ibv_device_ops	ops;
 	/* Name of underlying kernel IB device, eg "mthca0" */
 	char			name[IBV_SYSFS_NAME_MAX];
@@ -673,6 +682,39 @@ const char *ibv_get_device_name(struct i
 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)
+{
+	if (!context->device)
+		return IBV_TRANSPORT_UNKNOWN;
+
+	switch (context->device->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)
+{
+	if (!context->device)
+		return IBV_NODE_UNKNOWN;
+
+	return context->device->node_type;
+}
+
+/**
  * ibv_open_device - Initialize device for use
  */
 struct ibv_context *ibv_open_device(struct ibv_device *device);
diff --git a/libibverbs/src/device.c b/libibverbs/src/device.c
index de97d4d..f08059e 100644
--- a/libibverbs/src/device.c
+++ b/libibverbs/src/device.c
@@ -107,6 +107,20 @@ uint64_t ibv_get_device_guid(struct ibv_
 	return htonll(guid);
 }
 
+static enum ibv_node_type query_node_type(struct ibv_device *device)
+{
+	char node_desc[24];
+	char node_str[24];
+	int node_type;
+
+	if (ibv_read_sysfs_file(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;
@@ -125,6 +139,8 @@ struct ibv_context *ibv_open_device(stru
 	if (cmd_fd < 0)
 		return NULL;
 
+	device->node_type = query_node_type(device);
+
 	context = device->ops.alloc_context(device, cmd_fd);
 	if (!context)
 		goto err;




More information about the general mailing list