Skip to contentSkip to conversation

IB/verbs: introduce rdma_transport_is_ib() to check transport type

RFC PATCH In review Michael Wang 2 participants 3 messages Mar 19, 2015 InfiniBand

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 IB/verbs: introduce rdma_transport_is_ib() to check transport type

We have plenty of places where we don't care what exactly the transport type is, but only care if it's IB type.

This patch introduce rdma_transport_is_ib() as shortcuts to check whether an 'ib_device' is infiniband transport type, which help us to save some code.

---
 drivers/infiniband/core/cm.c              |  2 +-
 drivers/infiniband/core/cma.c             | 15 +++++++--------
 drivers/infiniband/core/mad.c             |  4 ++--
 drivers/infiniband/core/multicast.c       |  2 +-
 drivers/infiniband/core/sa_query.c        |  2 +-
 drivers/infiniband/core/ucm.c             |  3 +--
 drivers/infiniband/core/user_mad.c        |  2 +-
 drivers/infiniband/ulp/ipoib/ipoib_main.c |  4 ++--
 include/rdma/ib_verbs.h                   |  5 +++++
 9 files changed, 21 insertions(+), 18 deletions(-)
drivers/infiniband/core/cm.c +1 -1
index e28a494..2c72e9e 100644
@@ -3762,7 +3762,7 @@ static void cm_add_one(struct ib_device *ib_device)
     int ret;
     u8 i;
 
-    if (rdma_node_get_transport(ib_device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(ib_device))
         return;
 
     cm_dev = kzalloc(sizeof(*cm_dev) + sizeof(*port) *
drivers/infiniband/core/cma.c +1 -1
index d570030..cc2b261 100644
@@ -375,7 +375,7 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
                      listen_id_priv->id.port_num) == dev_ll) {
         cma_dev = listen_id_priv->cma_dev;
         port = listen_id_priv->id.port_num;
-        if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
+        if (rdma_transport_is_ib(cma_dev->device) &&
             rdma_port_get_link_layer(cma_dev->device, port) == 

IB_LINK_LAYER_ETHERNET)

             ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
                          &found_port, NULL);
@@ -395,7 +395,7 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
                 listen_id_priv->id.port_num == port)
                 continue;
             if (rdma_port_get_link_layer(cma_dev->device, port) == 
dev_ll) {
-                if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
+                if (rdma_transport_is_ib(cma_dev->device) &&
                     rdma_port_get_link_layer(cma_dev->device, port) == 
IB_LINK_LAYER_ETHERNET)
                     ret = ib_find_cached_gid(cma_dev->device, 
&iboe_gid, &found_port, NULL);
                 else
@@ -435,7 +435,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
     pkey = ntohs(addr->sib_pkey);

     list_for_each_entry(cur_dev, &dev_list, list) {
-        if (rdma_node_get_transport(cur_dev->device->node_type) != RDMA_TRANSPORT_IB)
+        if (!rdma_transport_is_ib(cur_dev->device))
             continue;

         for (p = 1; p <= cur_dev->device->phys_port_cnt; ++p) {
@@ -633,8 +633,7 @@ static int cma_modify_qp_rtr(struct rdma_id_private *id_priv,
     if (ret)
         goto out;

- if (rdma_node_get_transport(id_priv->cma_dev->device->node_type)
- == RDMA_TRANSPORT_IB &&
+ if (rdma_transport_is_ib(id_priv->cma_dev->device) &&

         rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num)
         == IB_LINK_LAYER_ETHERNET) {
         ret = rdma_addr_find_smac_by_sgid(&sgid, qp_attr.smac, NULL);
@@ -1626,7 +1625,7 @@ static void cma_listen_on_dev(struct rdma_id_private *id_priv,
     int ret;

     if (cma_family(id_priv) == AF_IB &&
-        rdma_node_get_transport(cma_dev->device->node_type) != RDMA_TRANSPORT_IB)
+        !rdma_transport_is_ib(cma_dev->device))
         return;

     id = rdma_create_id(cma_listen_handler, id_priv, id_priv->id.ps,
@@ -2028,7 +2027,7 @@ static int cma_bind_loopback(struct rdma_id_private *id_priv)
     mutex_lock(&lock);
     list_for_each_entry(cur_dev, &dev_list, list) {
         if (cma_family(id_priv) == AF_IB &&
- rdma_node_get_transport(cur_dev->device->node_type) != RDMA_TRANSPORT_IB)
+            !rdma_transport_is_ib(cur_dev->device))
             continue;

         if (!cma_dev)
@@ -3405,7 +3404,7 @@ void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
                 ib_detach_mcast(id->qp,
                         &mc->multicast.ib->rec.mgid,
 be16_to_cpu(mc->multicast.ib->rec.mlid));
-            if (rdma_node_get_transport(id_priv->cma_dev->device->node_type) == RDMA_TRANSPORT_IB) {
+            if (rdma_transport_is_ib(id_priv->cma_dev->device)) {
                 switch (rdma_port_get_link_layer(id->device, 
id->port_num)) {
                 case IB_LINK_LAYER_INFINIBAND:
                     ib_sa_free_multicast(mc->multicast.ib);
drivers/infiniband/core/mad.c +2 -2
index 74c30f4..dd51b37 100644
@@ -3057,7 +3057,7 @@ static void ib_mad_init_device(struct ib_device *device)
 {
     int start, end, i;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     if (device->node_type == RDMA_NODE_IB_SWITCH) {
@@ -3102,7 +3102,7 @@ static void ib_mad_remove_device(struct ib_device *device)
 {
     int i, num_ports, cur_port;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     if (device->node_type == RDMA_NODE_IB_SWITCH) {
drivers/infiniband/core/multicast.c +1 -1
index fa17b55..bdda79f 100644
@@ -808,7 +808,7 @@ static void mcast_add_one(struct ib_device *device)
     int i;
     int count = 0;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     dev = kmalloc(sizeof *dev + device->phys_port_cnt * sizeof *port,
drivers/infiniband/core/sa_query.c +1 -1
index c38f030..ce82861 100644
@@ -1154,7 +1154,7 @@ static void ib_sa_add_one(struct ib_device *device)
     struct ib_sa_device *sa_dev;
     int s, e, i;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     if (device->node_type == RDMA_NODE_IB_SWITCH)
drivers/infiniband/core/ucm.c +1 -2
index f2f6393..ddbe0b4 100644
@@ -1253,8 +1253,7 @@ static void ib_ucm_add_one(struct ib_device *device)
     dev_t base;
     struct ib_ucm_device *ucm_dev;
 
-    if (!device->alloc_ucontext ||
-        rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!device->alloc_ucontext || !rdma_transport_is_ib(device))
         return;
 
     ucm_dev = kzalloc(sizeof *ucm_dev, GFP_KERNEL);
drivers/infiniband/core/user_mad.c +1 -1
index 928cdd2..28a8b30 100644
@@ -1274,7 +1274,7 @@ static void ib_umad_add_one(struct ib_device *device)
     struct ib_umad_device *umad_dev;
     int s, e, i;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     if (device->node_type == RDMA_NODE_IB_SWITCH)
drivers/infiniband/ulp/ipoib/ipoib_main.c +2 -2
index 58b5aa3..6afb30f 100644
@@ -1655,7 +1655,7 @@ static void ipoib_add_one(struct ib_device *device)
     struct ipoib_dev_priv *priv;
     int s, e, p;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     dev_list = kmalloc(sizeof *dev_list, GFP_KERNEL);
@@ -1690,7 +1690,7 @@ static void ipoib_remove_one(struct ib_device *device)
     struct ipoib_dev_priv *priv, *tmp;
     struct list_head *dev_list;
 
-    if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
+    if (!rdma_transport_is_ib(device))
         return;
 
     dev_list = ib_get_client_data(device, &ipoib_client);
include/rdma/ib_verbs.h +5 -0
index 65994a1..f6a04b5 100644
@@ -1743,6 +1743,11 @@ int ib_query_port(struct ib_device *device,
 enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device,
                            u8 port_num);
 
+static inline int rdma_transport_is_ib(struct ib_device *device)
+{
+    return rdma_node_get_transport(device->node_type) == RDMA_TRANSPORT_IB;
+}
+
 int ib_query_gid(struct ib_device *device,
          u8 port_num, int index, union ib_gid *gid);
 
Signature · 6 lines
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw
Quoted 6 lines

We have plenty of places where we don't care what exactly the transport type is, but only care if it's IB type.

This patch introduce rdma_transport_is_ib() as shortcuts to check whether an 'ib_device' is infiniband transport type, which help us to save some code.

In most of these places, the check that we want is whether IB management is used. The transport check is an indirect way of checking for that, and I believe we should use a more direct method of checking for the functionality that's actually desired.

Please see the following thread that is related to these changes:

http://www.spinics.net/lists/linux-rdma/msg23484.html

- Sean

#2 lore raw

Hi, Sean

Thanks for point it out for me :-)

I'll try to follow the conversation to understand what really needs to be done, see if I could do some contribution on it.

Regards,
Michael Wang

Quoted 13 lines · Sean
Quoted 6 lines

We have plenty of places where we don't care what exactly the transport type is, but only care if it's IB type.

This patch introduce rdma_transport_is_ib() as shortcuts to check whether an 'ib_device' is infiniband transport type, which help us to save some code.

In most of these places, the check that we want is whether IB management is used. The transport check is an indirect way of checking for that, and I believe we should use a more direct method of checking for the functionality that's actually desired.

Please see the following thread that is related to these changes:

http://www.spinics.net/lists/linux-rdma/msg23484.html

- Sean