diff mbox

[V1,1/7] libibverbs: Add link layer field port attribute

Message ID alpine.LRH.2.00.1107202235510.12424@ogerlitz.voltaire.com (mailing list archive)
State New, archived
Headers show

Commit Message

Or Gerlitz July 20, 2011, 7:37 p.m. UTC
The new field has one of three values - IBV_LINK_LAYER_UNSPECIFIED,
IBV_LINK_LAYER_INFINIBAND, IBV_LINK_LAYER_ETHERNET. It can be used
by applications to know the link layer used by the port, which
can be either Infiniband or Ethernet.

The addition of the new field does not change the size of struct
ibv_port_attr due to alignment of the preceding fields. As such
binary compatibility between the library to applications is kept,
since old apps running over new library do not read this field,
and new apps running over old library will determine the link
layer as unspecified and hence take their IB code path.

The solution was suggested by: Roland Dreier <roland@purestorage.com>
and Jason Gunthorpe <jgunthorpe@obsidianresearch.com>

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.co.il>
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
---
changes from V0:

- applied feedback from Jason, made the ___ibv_query_port trick
  clearer to header file readers

 include/infiniband/verbs.h |   23 +++++++++++++++++++++++
 man/ibv_query_port.3       |    4 ++++
 2 files changed, 27 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h
index 0f1cb2e..d1a3e47 100644
--- a/include/infiniband/verbs.h
+++ b/include/infiniband/verbs.h
@@ -161,6 +161,12 @@  enum ibv_port_state {
 	IBV_PORT_ACTIVE_DEFER	= 5
 };

+enum {
+	IBV_LINK_LAYER_UNSPECIFIED,
+	IBV_LINK_LAYER_INFINIBAND,
+	IBV_LINK_LAYER_ETHERNET,
+};
+
 struct ibv_port_attr {
 	enum ibv_port_state	state;
 	enum ibv_mtu		max_mtu;
@@ -181,6 +187,8 @@  struct ibv_port_attr {
 	uint8_t			active_width;
 	uint8_t			active_speed;
 	uint8_t			phys_state;
+	uint8_t			link_layer;
+	uint8_t			pad;
 };

 enum ibv_event_type {
@@ -767,6 +775,20 @@  int ibv_query_device(struct ibv_context *context,
 int ibv_query_port(struct ibv_context *context, uint8_t port_num,
 		   struct ibv_port_attr *port_attr);

+static inline int ___ibv_query_port(struct ibv_context *context,
+				    uint8_t port_num,
+				    struct ibv_port_attr *port_attr)
+{
+	/* For compatability linking with old libibverbs */
+	port_attr->link_layer = IBV_LINK_LAYER_UNSPECIFIED;
+	port_attr->pad = 0;
+
+	return ibv_query_port(context, port_num, port_attr);
+}
+
+#define ibv_query_port(context, port_num, port_attr) \
+	___ibv_query_port(context, port_num, port_attr)
+
 /**
  * ibv_query_gid - Get a GID table entry
  */
@@ -1097,4 +1119,5 @@  END_C_DECLS

 #  undef __attribute_const

+
 #endif /* INFINIBAND_VERBS_H */
diff --git a/man/ibv_query_port.3 b/man/ibv_query_port.3
index 882470d..9bedd90 100644
--- a/man/ibv_query_port.3
+++ b/man/ibv_query_port.3
@@ -44,9 +44,13 @@  uint8_t                 init_type_reply;/* Type of initialization performed by S
 uint8_t                 active_width;   /* Currently active link width */
 uint8_t                 active_speed;   /* Currently active link speed */
 uint8_t                 phys_state;     /* Physical port state */
+uint8_t                 link_layer;     /* link layer protocol of the port */
 .in -8
 };
 .sp
+possible values for the link layer field are IBV_LINK_LAYER_INFINIBAND,
+IBV_LINK_LAYER_ETHERNET, or IBV_LINK_LAYER_UNSPECIFIED.
+.sp
 .fi
 .SH "RETURN VALUE"
 .B ibv_query_port()