RDMA: Add and use rdma_for_each_port
[linux-2.6-block.git] / include / rdma / ib_verbs.h
index 2a17c2b3007389d142689c556df347a92d9e4fbc..fa0edd6ae33ca8c16e2883e6ed9b092b410b91ec 100644 (file)
@@ -2827,6 +2827,16 @@ static inline u8 rdma_start_port(const struct ib_device *device)
        return rdma_cap_ib_switch(device) ? 0 : 1;
 }
 
+/**
+ * rdma_for_each_port - Iterate over all valid port numbers of the IB device
+ * @device - The struct ib_device * to iterate over
+ * @iter - The unsigned int to store the port number
+ */
+#define rdma_for_each_port(device, iter)                                       \
+       for (iter = rdma_start_port(device + BUILD_BUG_ON_ZERO(!__same_type(   \
+                                                    unsigned int, iter)));    \
+            iter <= rdma_end_port(device); (iter)++)
+
 /**
  * rdma_end_port - Return the last valid port number for the device
  * specified