@@ -38,6 +38,7 @@
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/mutex.h>
+#include <linux/netdevice.h>
#include <rdma/rdma_netlink.h>
#include "core_priv.h"
@@ -733,6 +734,62 @@ int ib_find_pkey(struct ib_device *device,
}
EXPORT_SYMBOL(ib_find_pkey);
+static struct net_device *ib_get_net_dev_by_port_pkey_ip(struct ib_device *dev,
+ u8 port,
+ u16 pkey,
+ struct sockaddr *addr)
+{
+ struct net_device *ret = NULL;
+ struct ib_client *client;
+
+ mutex_lock(&device_mutex);
+ list_for_each_entry(client, &client_list, list)
+ if (client->get_net_device_by_port_pkey_ip) {
+ ret = client->get_net_device_by_port_pkey_ip(dev, port,
+ pkey,
+ addr);
+ if (ret)
+ break;
+ }
+
+ mutex_unlock(&device_mutex);
+ return ret;
+}
+
+struct net *ib_get_net_ns_by_port_pkey_ip(struct ib_device *dev,
+ u8 port,
+ u16 pkey,
+ struct sockaddr *addr)
+{
+ struct net_device *ndev = NULL;
+ struct net *ns;
+
+ switch (rdma_port_get_link_layer(dev, port)) {
+ case IB_LINK_LAYER_INFINIBAND:
+ if (!addr)
+ goto not_found;
+ ndev = ib_get_net_dev_by_port_pkey_ip(dev, port, pkey, addr);
+ break;
+ default:
+ goto not_found;
+ }
+
+ if (!ndev)
+ goto not_found;
+
+ rcu_read_lock();
+ ns = maybe_get_net(dev_net(ndev));
+ dev_put(ndev);
+ rcu_read_unlock();
+ if (!ns)
+ goto not_found;
+ return ns;
+
+not_found:
+ return get_net(&init_net);
+}
+EXPORT_SYMBOL(ib_get_net_ns_by_port_pkey_ip);
+
static int __init ib_core_init(void)
{
int ret;
@@ -1683,6 +1683,21 @@ struct ib_client {
void (*add) (struct ib_device *);
void (*remove)(struct ib_device *);
+ /* Returns the net_dev belonging to this ib_client and matching the
+ * given parameters.
+ * @dev: An RDMA device that the net_dev use for communication.
+ * @port: A physical port number on the RDMA device.
+ * @pkey: P_Key that the net_dev uses if applicable.
+ * @addr: An IP address the net_dev is configured with.
+ *
+ * An ib_client that implements a net_dev on top of RDMA devices
+ * (such as IP over IB) should implement this callback, allowing the
+ * rdma_cm module to find the right net_dev for a given request. */
+ struct net_device *(*get_net_device_by_port_pkey_ip)(
+ struct ib_device *dev,
+ u8 port,
+ u16 pkey,
+ struct sockaddr *addr);
struct list_head list;
};
@@ -2682,4 +2697,18 @@ static inline int ib_check_mr_access(int flags)
int ib_check_mr_status(struct ib_mr *mr, u32 check_mask,
struct ib_mr_status *mr_status);
+/**
+ * ib_get_net_ns_by_port_pkey_ip() - Return the appropriate net namespace
+ * for a received CM request
+ * @dev: An RDMA device on which the request has been received.
+ * @port: Port number on the RDMA device.
+ * @pkey: The Pkey the request came on.
+ * @addr: Contains the IP address that the request specified as its
+ * destination.
+ */
+struct net *ib_get_net_ns_by_port_pkey_ip(struct ib_device *dev,
+ u8 port,
+ u16 pkey,
+ struct sockaddr *addr);
+
#endif /* IB_VERBS_H */