All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv10 02/12] ib_core: IBoE CMA device binding
@ 2010-08-26 14:17 Eli Cohen
  2010-08-26 20:11 ` Hefty, Sean
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Cohen @ 2010-08-26 14:17 UTC (permalink / raw)
  To: Roland Dreier; +Cc: RDMA list

Add support for IBoE device binding and IP --> GID resolution. Path resolving
and multicast joining are implemented within cma.c by filling the responses and
pushing the callbacks to the cma work queue. IP->GID resolution always yields
IPv6 link local addresses - remote GIDs are derived from the destination MAC
address of the remote port. Multicast GIDs are always mapped to multicast MACs
as is done in IPv6. Some helper functions are added to ib_addr.h.  IPv4
multicast is enabled by translating IPv4 multicast addresses to IPv6 multicast
as described in
http://www.mail-archive.com/ipng-Va8kgSFw1KyzQ7sTrsxvMkEOCMrvLtNR@public.gmane.org/msg02134.html.

Signed-off-by: Eli Cohen <eli-VPRAkNaXOzVS1MOuV/RT9w@public.gmane.org>
---
Changes from v9:
return -ENODEV instead of -EINVAL when net device is not found.

 drivers/infiniband/core/cma.c      |  278 +++++++++++++++++++++++++++++++++--
 drivers/infiniband/core/sa_query.c |    5 +-
 drivers/infiniband/core/ucma.c     |   45 +++++-
 include/rdma/ib_addr.h             |   98 +++++++++++++-
 4 files changed, 402 insertions(+), 24 deletions(-)

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index b930b81..a90511b 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -59,6 +59,7 @@ MODULE_LICENSE("Dual BSD/GPL");
 #define CMA_CM_RESPONSE_TIMEOUT 20
 #define CMA_MAX_CM_RETRIES 15
 #define CMA_CM_MRA_SETTING (IB_CM_MRA_FLAG_DELAY | 24)
+#define IBOE_PACKET_LIFETIME 18
 
 static void cma_add_one(struct ib_device *device);
 static void cma_remove_one(struct ib_device *device);
@@ -157,6 +158,7 @@ struct cma_multicast {
 	struct list_head	list;
 	void			*context;
 	struct sockaddr_storage	addr;
+	struct kref		mcref;
 };
 
 struct cma_work {
@@ -173,6 +175,12 @@ struct cma_ndev_work {
 	struct rdma_cm_event	event;
 };
 
+struct iboe_mcast_work {
+	struct work_struct	 work;
+	struct rdma_id_private	*id;
+	struct cma_multicast	*mc;
+};
+
 union cma_ip_addr {
 	struct in6_addr ip6;
 	struct {
@@ -281,6 +289,8 @@ static void cma_attach_to_dev(struct rdma_id_private *id_priv,
 	atomic_inc(&cma_dev->refcount);
 	id_priv->cma_dev = cma_dev;
 	id_priv->id.device = cma_dev->device;
+	id_priv->id.route.addr.dev_addr.transport =
+		rdma_node_get_transport(cma_dev->device->node_type);
 	list_add_tail(&id_priv->list, &cma_dev->id_list);
 }
 
@@ -290,6 +300,14 @@ static inline void cma_deref_dev(struct cma_device *cma_dev)
 		complete(&cma_dev->comp);
 }
 
+static inline void release_mc(struct kref *kref)
+{
+	struct cma_multicast *mc = container_of(kref, struct cma_multicast, mcref);
+
+	kfree(mc->multicast.ib);
+	kfree(mc);
+}
+
 static void cma_detach_from_dev(struct rdma_id_private *id_priv)
 {
 	list_del(&id_priv->list);
@@ -330,15 +348,29 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
 	union ib_gid gid;
 	int ret = -ENODEV;
 
-	rdma_addr_get_sgid(dev_addr, &gid);
+	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
+		iboe_addr_get_sgid(dev_addr, &gid);
+		list_for_each_entry(cma_dev, &dev_list, list) {
+			ret = ib_find_cached_gid(cma_dev->device, &gid,
+						 &id_priv->id.port_num, NULL);
+			if (!ret)
+				goto out;
+		}
+	}
+
+	memcpy(&gid, dev_addr->src_dev_addr +
+	       rdma_addr_gid_offset(dev_addr), sizeof gid);
 	list_for_each_entry(cma_dev, &dev_list, list) {
 		ret = ib_find_cached_gid(cma_dev->device, &gid,
 					 &id_priv->id.port_num, NULL);
-		if (!ret) {
-			cma_attach_to_dev(id_priv, cma_dev);
+		if (!ret)
 			break;
-		}
 	}
+
+out:
+	if (!ret)
+		cma_attach_to_dev(id_priv, cma_dev);
+
 	return ret;
 }
 
@@ -556,10 +588,16 @@ static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
 {
 	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
 	int ret;
+	u16 pkey;
+
+	if (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num) ==
+	    IB_LINK_LAYER_INFINIBAND)
+		pkey = ib_addr_get_pkey(dev_addr);
+	else
+		pkey = 0xffff;
 
 	ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num,
-				  ib_addr_get_pkey(dev_addr),
-				  &qp_attr->pkey_index);
+				  pkey, &qp_attr->pkey_index);
 	if (ret)
 		return ret;
 
@@ -737,8 +775,8 @@ static inline int cma_user_data_offset(enum rdma_port_space ps)
 
 static void cma_cancel_route(struct rdma_id_private *id_priv)
 {
-	switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
-	case RDMA_TRANSPORT_IB:
+	switch (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num)) {
+	case IB_LINK_LAYER_INFINIBAND:
 		if (id_priv->query)
 			ib_sa_cancel_query(id_priv->query_id, id_priv->query);
 		break;
@@ -816,8 +854,17 @@ static void cma_leave_mc_groups(struct rdma_id_private *id_priv)
 		mc = container_of(id_priv->mc_list.next,
 				  struct cma_multicast, list);
 		list_del(&mc->list);
-		ib_sa_free_multicast(mc->multicast.ib);
-		kfree(mc);
+		switch (rdma_port_get_link_layer(id_priv->cma_dev->device, id_priv->id.port_num)) {
+		case IB_LINK_LAYER_INFINIBAND:
+			ib_sa_free_multicast(mc->multicast.ib);
+			kfree(mc);
+			break;
+		case IB_LINK_LAYER_ETHERNET:
+			kref_put(&mc->mcref, release_mc);
+			break;
+		default:
+			break;
+		}
 	}
 }
 
@@ -833,7 +880,7 @@ void rdma_destroy_id(struct rdma_cm_id *id)
 	mutex_lock(&lock);
 	if (id_priv->cma_dev) {
 		mutex_unlock(&lock);
-		switch (rdma_node_get_transport(id->device->node_type)) {
+		switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
 		case RDMA_TRANSPORT_IB:
 			if (id_priv->cm_id.ib && !IS_ERR(id_priv->cm_id.ib))
 				ib_destroy_cm_id(id_priv->cm_id.ib);
@@ -1708,6 +1755,77 @@ static int cma_resolve_iw_route(struct rdma_id_private *id_priv, int timeout_ms)
 	return 0;
 }
 
+static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
+{
+	struct rdma_route *route = &id_priv->id.route;
+	struct rdma_addr *addr = &route->addr;
+	struct cma_work *work;
+	int ret;
+	struct sockaddr_in *src_addr = (struct sockaddr_in *)&route->addr.src_addr;
+	struct sockaddr_in *dst_addr = (struct sockaddr_in *)&route->addr.dst_addr;
+	struct net_device *ndev = NULL;
+
+	if (src_addr->sin_family != dst_addr->sin_family)
+		return -EINVAL;
+
+	work = kzalloc(sizeof *work, GFP_KERNEL);
+	if (!work)
+		return -ENOMEM;
+
+	work->id = id_priv;
+	INIT_WORK(&work->work, cma_work_handler);
+
+	route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL);
+	if (!route->path_rec) {
+		ret = -ENOMEM;
+		goto err1;
+	}
+
+	route->num_paths = 1;
+
+	iboe_mac_to_ll(&route->path_rec->sgid, addr->dev_addr.src_dev_addr);
+	iboe_mac_to_ll(&route->path_rec->dgid, addr->dev_addr.dst_dev_addr);
+
+	route->path_rec->hop_limit = 1;
+	route->path_rec->reversible = 1;
+	route->path_rec->pkey = cpu_to_be16(0xffff);
+	route->path_rec->mtu_selector = IB_SA_EQ;
+
+	if (addr->dev_addr.bound_dev_if)
+		ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if);
+	if (!ndev) {
+		ret = -ENODEV;
+		goto err2;
+	}
+
+	route->path_rec->mtu = iboe_get_mtu(ndev->mtu);
+	route->path_rec->rate_selector = IB_SA_EQ;
+	route->path_rec->rate = iboe_get_rate(ndev);
+	dev_put(ndev);
+	route->path_rec->packet_life_time_selector = IB_SA_EQ;
+	route->path_rec->packet_life_time = IBOE_PACKET_LIFETIME;
+	if (!route->path_rec->mtu) {
+		ret = -EINVAL;
+		goto err2;
+	}
+
+	work->old_state = CMA_ROUTE_QUERY;
+	work->new_state = CMA_ROUTE_RESOLVED;
+	work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED;
+	work->event.status = 0;
+
+	queue_work(cma_wq, &work->work);
+
+	return 0;
+
+err2:
+	kfree(route->path_rec);
+	route->path_rec = NULL;
+err1:
+	kfree(work);
+	return ret;
+}
+
 int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms)
 {
 	struct rdma_id_private *id_priv;
@@ -1720,7 +1838,16 @@ int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms)
 	atomic_inc(&id_priv->refcount);
 	switch (rdma_node_get_transport(id->device->node_type)) {
 	case RDMA_TRANSPORT_IB:
-		ret = cma_resolve_ib_route(id_priv, timeout_ms);
+		switch (rdma_port_get_link_layer(id->device, id->port_num)) {
+		case IB_LINK_LAYER_INFINIBAND:
+			ret = cma_resolve_ib_route(id_priv, timeout_ms);
+			break;
+		case IB_LINK_LAYER_ETHERNET:
+			ret = cma_resolve_iboe_route(id_priv);
+			break;
+		default:
+			ret = -ENOSYS;
+		}
 		break;
 	case RDMA_TRANSPORT_IWARP:
 		ret = cma_resolve_iw_route(id_priv, timeout_ms);
@@ -1773,7 +1900,7 @@ port_found:
 		goto out;
 
 	id_priv->id.route.addr.dev_addr.dev_type =
-		(rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB) ?
+		(rdma_port_get_link_layer(cma_dev->device, p) == IB_LINK_LAYER_INFINIBAND) ?
 		ARPHRD_INFINIBAND : ARPHRD_ETHER;
 
 	rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid);
@@ -2758,6 +2885,103 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
 	return 0;
 }
 
+
+static void iboe_mcast_work_handler(struct work_struct *work)
+{
+	struct iboe_mcast_work *mw = container_of(work, struct iboe_mcast_work, work);
+	struct cma_multicast *mc = mw->mc;
+	struct ib_sa_multicast *m = mc->multicast.ib;
+
+	mc->multicast.ib->context = mc;
+	cma_ib_mc_handler(0, m);
+	kref_put(&mc->mcref, release_mc);
+	kfree(mw);
+}
+
+static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid)
+{
+	struct sockaddr_in *sin = (struct sockaddr_in *)addr;
+	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
+
+	if (cma_any_addr(addr)) {
+		memset(mgid, 0, sizeof *mgid);
+	} else if (addr->sa_family == AF_INET6)
+		memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
+	else {
+		mgid->raw[0] = 0xff;
+		mgid->raw[1] = 0x0e;
+		mgid->raw[2] = 0;
+		mgid->raw[3] = 0;
+		mgid->raw[4] = 0;
+		mgid->raw[5] = 0;
+		mgid->raw[6] = 0;
+		mgid->raw[7] = 0;
+		mgid->raw[8] = 0;
+		mgid->raw[9] = 0;
+		mgid->raw[10] = 0xff;
+		mgid->raw[11] = 0xff;
+		*(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr;
+	}
+}
+
+static int cma_iboe_join_multicast(struct rdma_id_private *id_priv,
+				   struct cma_multicast *mc)
+{
+	struct iboe_mcast_work *work;
+	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
+	int err;
+	struct sockaddr *addr = (struct sockaddr *)&mc->addr;
+	struct net_device *ndev = NULL;
+
+	if (cma_zero_addr((struct sockaddr *)&mc->addr))
+		return -EINVAL;
+
+	work = kzalloc(sizeof *work, GFP_KERNEL);
+	if (!work)
+		return -ENOMEM;
+
+	mc->multicast.ib = kzalloc(sizeof(struct ib_sa_multicast), GFP_KERNEL);
+	if (!mc->multicast.ib) {
+		err = -ENOMEM;
+		goto out1;
+	}
+
+	cma_iboe_set_mgid(addr, &mc->multicast.ib->rec.mgid);
+
+	mc->multicast.ib->rec.pkey = cpu_to_be16(0xffff);
+	if (id_priv->id.ps == RDMA_PS_UDP)
+		mc->multicast.ib->rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
+
+	if (dev_addr->bound_dev_if)
+		ndev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
+	if (!ndev) {
+		err = -ENODEV;
+		goto out2;
+	}
+	mc->multicast.ib->rec.rate = iboe_get_rate(ndev);
+	mc->multicast.ib->rec.hop_limit = 1;
+	mc->multicast.ib->rec.mtu = iboe_get_mtu(ndev->mtu);
+	dev_put(ndev);
+	if (!mc->multicast.ib->rec.mtu) {
+		err = -EINVAL;
+		goto out2;
+	}
+	iboe_addr_get_sgid(dev_addr, &mc->multicast.ib->rec.port_gid);
+	work->id = id_priv;
+	work->mc = mc;
+	INIT_WORK(&work->work, iboe_mcast_work_handler);
+	kref_get(&mc->mcref);
+	queue_work(cma_wq, &work->work);
+
+	return 0;
+
+out2:
+	kfree(mc->multicast.ib);
+out1:
+	kfree(work);
+	return err;
+}
+
 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
 			void *context)
 {
@@ -2784,7 +3008,17 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
 
 	switch (rdma_node_get_transport(id->device->node_type)) {
 	case RDMA_TRANSPORT_IB:
-		ret = cma_join_ib_multicast(id_priv, mc);
+		switch (rdma_port_get_link_layer(id->device, id->port_num)) {
+		case IB_LINK_LAYER_INFINIBAND:
+			ret = cma_join_ib_multicast(id_priv, mc);
+			break;
+		case IB_LINK_LAYER_ETHERNET:
+			kref_init(&mc->mcref);
+			ret = cma_iboe_join_multicast(id_priv, mc);
+			break;
+		default:
+			ret = -EINVAL;
+		}
 		break;
 	default:
 		ret = -ENOSYS;
@@ -2797,6 +3031,7 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
 		spin_unlock_irq(&id_priv->lock);
 		kfree(mc);
 	}
+
 	return ret;
 }
 EXPORT_SYMBOL(rdma_join_multicast);
@@ -2817,8 +3052,19 @@ void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
 				ib_detach_mcast(id->qp,
 						&mc->multicast.ib->rec.mgid,
 						mc->multicast.ib->rec.mlid);
-			ib_sa_free_multicast(mc->multicast.ib);
-			kfree(mc);
+			if (rdma_node_get_transport(id_priv->cma_dev->device->node_type) == RDMA_TRANSPORT_IB) {
+				switch (rdma_port_get_link_layer(id->device, id->port_num)) {
+				case IB_LINK_LAYER_INFINIBAND:
+					ib_sa_free_multicast(mc->multicast.ib);
+					kfree(mc);
+					break;
+				case IB_LINK_LAYER_ETHERNET:
+					kref_put(&mc->mcref, release_mc);
+					break;
+				default:
+					break;
+				}
+			}
 			return;
 		}
 	}
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 27674c7..91a6603 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -496,6 +496,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
 {
 	int ret;
 	u16 gid_index;
+	int force_grh;
 
 	memset(ah_attr, 0, sizeof *ah_attr);
 	ah_attr->dlid = be16_to_cpu(rec->dlid);
@@ -505,7 +506,9 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
 	ah_attr->port_num = port_num;
 	ah_attr->static_rate = rec->rate;
 
-	if (rec->hop_limit > 1) {
+	force_grh = rdma_port_get_link_layer(device, port_num) == IB_LINK_LAYER_ETHERNET;
+
+	if (rec->hop_limit > 1 || force_grh) {
 		ah_attr->ah_flags = IB_AH_GRH;
 		ah_attr->grh.dgid = rec->dgid;
 
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index ac7edc2..3d3c926 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -583,6 +583,34 @@ static void ucma_copy_ib_route(struct rdma_ucm_query_route_resp *resp,
 	}
 }
 
+static void ucma_copy_iboe_route(struct rdma_ucm_query_route_resp *resp,
+				 struct rdma_route *route)
+{
+	struct rdma_dev_addr *dev_addr;
+
+	resp->num_paths = route->num_paths;
+	switch (route->num_paths) {
+	case 0:
+		dev_addr = &route->addr.dev_addr;
+		iboe_mac_to_ll((union ib_gid *) &resp->ib_route[0].dgid,
+			       dev_addr->dst_dev_addr);
+		iboe_addr_get_sgid(dev_addr,
+				   (union ib_gid *) &resp->ib_route[0].sgid);
+		resp->ib_route[0].pkey = cpu_to_be16(0xffff);
+		break;
+	case 2:
+		ib_copy_path_rec_to_user(&resp->ib_route[1],
+					 &route->path_rec[1]);
+		/* fall through */
+	case 1:
+		ib_copy_path_rec_to_user(&resp->ib_route[0],
+					 &route->path_rec[0]);
+		break;
+	default:
+		break;
+	}
+}
+
 static ssize_t ucma_query_route(struct ucma_file *file,
 				const char __user *inbuf,
 				int in_len, int out_len)
@@ -617,12 +645,17 @@ static ssize_t ucma_query_route(struct ucma_file *file,
 
 	resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid;
 	resp.port_num = ctx->cm_id->port_num;
-	switch (rdma_node_get_transport(ctx->cm_id->device->node_type)) {
-	case RDMA_TRANSPORT_IB:
-		ucma_copy_ib_route(&resp, &ctx->cm_id->route);
-		break;
-	default:
-		break;
+	if (rdma_node_get_transport(ctx->cm_id->device->node_type) == RDMA_TRANSPORT_IB) {
+		switch (rdma_port_get_link_layer(ctx->cm_id->device, ctx->cm_id->port_num)) {
+		case IB_LINK_LAYER_INFINIBAND:
+			ucma_copy_ib_route(&resp, &ctx->cm_id->route);
+			break;
+		case IB_LINK_LAYER_ETHERNET:
+			ucma_copy_iboe_route(&resp, &ctx->cm_id->route);
+			break;
+		default:
+			break;
+		}
 	}
 
 out:
diff --git a/include/rdma/ib_addr.h b/include/rdma/ib_addr.h
index fa0d52b..fb5707c 100644
--- a/include/rdma/ib_addr.h
+++ b/include/rdma/ib_addr.h
@@ -40,6 +40,7 @@
 #include <linux/netdevice.h>
 #include <linux/socket.h>
 #include <rdma/ib_verbs.h>
+#include <rdma/ib_pack.h>
 
 struct rdma_addr_client {
 	atomic_t refcount;
@@ -63,6 +64,7 @@ struct rdma_dev_addr {
 	unsigned char broadcast[MAX_ADDR_LEN];
 	unsigned short dev_type;
 	int bound_dev_if;
+	enum rdma_transport_type transport;
 };
 
 /**
@@ -127,9 +129,31 @@ static inline int rdma_addr_gid_offset(struct rdma_dev_addr *dev_addr)
 	return dev_addr->dev_type == ARPHRD_INFINIBAND ? 4 : 0;
 }
 
+static inline void iboe_mac_to_ll(union ib_gid *gid, u8 *mac)
+{
+	memset(gid->raw, 0, 16);
+	*((u32 *)gid->raw) = cpu_to_be32(0xfe800000);
+	gid->raw[12] = 0xfe;
+	gid->raw[11] = 0xff;
+	memcpy(gid->raw + 13, mac + 3, 3);
+	memcpy(gid->raw + 8, mac, 3);
+	gid->raw[8] ^= 2;
+}
+
+static inline void iboe_addr_get_sgid(struct rdma_dev_addr *dev_addr,
+				      union ib_gid *gid)
+{
+	iboe_mac_to_ll(gid, dev_addr->src_dev_addr);
+}
+
 static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
 {
-	memcpy(gid, dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid);
+	if (dev_addr->transport == RDMA_TRANSPORT_IB &&
+	    dev_addr->dev_type != ARPHRD_INFINIBAND)
+		iboe_addr_get_sgid(dev_addr, gid);
+	else
+		memcpy(gid, dev_addr->src_dev_addr +
+		       rdma_addr_gid_offset(dev_addr), sizeof *gid);
 }
 
 static inline void rdma_addr_set_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
@@ -147,4 +171,76 @@ static inline void rdma_addr_set_dgid(struct rdma_dev_addr *dev_addr, union ib_g
 	memcpy(dev_addr->dst_dev_addr + rdma_addr_gid_offset(dev_addr), gid, sizeof *gid);
 }
 
+static inline enum ib_mtu iboe_get_mtu(int mtu)
+{
+	/*
+	 * reduce IB headers from effective IBoE MTU. 28 stands for
+	 * atomic header which is the biggest possible header after BTH
+	 */
+	mtu = mtu - IB_GRH_BYTES - IB_BTH_BYTES - 28;
+
+	if (mtu >= ib_mtu_enum_to_int(IB_MTU_4096))
+		return IB_MTU_4096;
+	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_2048))
+		return IB_MTU_2048;
+	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_1024))
+		return IB_MTU_1024;
+	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_512))
+		return IB_MTU_512;
+	else if (mtu >= ib_mtu_enum_to_int(IB_MTU_256))
+		return IB_MTU_256;
+	else
+		return 0;
+}
+
+static inline int iboe_get_rate(struct net_device *dev)
+{
+	struct ethtool_cmd cmd;
+
+	if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings ||
+	    dev->ethtool_ops->get_settings(dev, &cmd))
+		return IB_RATE_PORT_CURRENT;
+
+	if (cmd.speed >= 40000)
+		return IB_RATE_40_GBPS;
+	else if (cmd.speed >= 30000)
+		return IB_RATE_30_GBPS;
+	else if (cmd.speed >= 20000)
+		return IB_RATE_20_GBPS;
+	else if (cmd.speed >= 10000)
+		return IB_RATE_10_GBPS;
+	else
+		return IB_RATE_PORT_CURRENT;
+}
+
+static inline int rdma_link_local_addr(struct in6_addr *addr)
+{
+	if (addr->s6_addr32[0] == cpu_to_be32(0xfe800000) &&
+	    addr->s6_addr32[1] == 0)
+		return 1;
+
+	return 0;
+}
+
+static inline void rdma_get_ll_mac(struct in6_addr *addr, u8 *mac)
+{
+	memcpy(mac, &addr->s6_addr[8], 3);
+	memcpy(mac + 3, &addr->s6_addr[13], 3);
+	mac[0] ^= 2;
+}
+
+static inline int rdma_is_multicast_addr(struct in6_addr *addr)
+{
+	return addr->s6_addr[0] == 0xff;
+}
+
+static inline void rdma_get_mcast_mac(struct in6_addr *addr, u8 *mac)
+{
+	int i;
+
+	mac[0] = 0x33;
+	mac[1] = 0x33;
+	for (i = 2; i < 6; ++i)
+		mac[i] = addr->s6_addr[i + 10];
+}
 #endif /* IB_ADDR_H */
-- 
1.7.2.2

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* RE: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-08-26 14:17 [PATCHv10 02/12] ib_core: IBoE CMA device binding Eli Cohen
@ 2010-08-26 20:11 ` Hefty, Sean
       [not found]   ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB26491D-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Hefty, Sean @ 2010-08-26 20:11 UTC (permalink / raw)
  To: Eli Cohen, Roland Dreier; +Cc: RDMA list

> @@ -330,15 +348,29 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
>  	union ib_gid gid;
>  	int ret = -ENODEV;
> 
> -	rdma_addr_get_sgid(dev_addr, &gid);
> +	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
> +		iboe_addr_get_sgid(dev_addr, &gid);

How does this work with iwarp?

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
       [not found]   ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB26491D-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2010-08-27  5:42     ` Eli Cohen
  2010-08-27  6:14       ` Roland Dreier
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Cohen @ 2010-08-27  5:42 UTC (permalink / raw)
  To: Hefty, Sean; +Cc: Roland Dreier, RDMA list

On Thu, Aug 26, 2010 at 01:11:56PM -0700, Hefty, Sean wrote:
> > @@ -330,15 +348,29 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
> >  	union ib_gid gid;
> >  	int ret = -ENODEV;
> > 
> > -	rdma_addr_get_sgid(dev_addr, &gid);
> > +	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
> > +		iboe_addr_get_sgid(dev_addr, &gid);
> 
> How does this work with iwarp?
> 

Referring to the entire function:
 
static int cma_acquire_dev(struct rdma_id_private *id_priv)
{
	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
	struct cma_device *cma_dev;
	union ib_gid gid;
	int ret = -ENODEV;

	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
		iboe_addr_get_sgid(dev_addr, &gid);
		list_for_each_entry(cma_dev, &dev_list, list) {
			ret = ib_find_cached_gid(cma_dev->device, &gid,
						 &id_priv->id.port_num, NULL);
			if (!ret)
				goto out;
		}
	}

	memcpy(&gid, dev_addr->src_dev_addr +
	       rdma_addr_gid_offset(dev_addr), sizeof gid);
	list_for_each_entry(cma_dev, &dev_list, list) {
		ret = ib_find_cached_gid(cma_dev->device, &gid,
					 &id_priv->id.port_num, NULL);
		if (!ret)
			break;
	}

out:
	if (!ret)
		cma_attach_to_dev(id_priv, cma_dev);

	return ret;
}

The idea is that if it is not infiniband then it is either iwarp or iboe.
So we first build a gid assuming it is the iboe case and search it the
devices' gid tables. If it was not found then we proceed with the
regular flow.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-08-27  5:42     ` Eli Cohen
@ 2010-08-27  6:14       ` Roland Dreier
       [not found]         ` <adavd6w37lp.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Roland Dreier @ 2010-08-27  6:14 UTC (permalink / raw)
  To: Eli Cohen; +Cc: Hefty, Sean, RDMA list

 > 	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
 > 		iboe_addr_get_sgid(dev_addr, &gid);
 > 		list_for_each_entry(cma_dev, &dev_list, list) {
 > 			ret = ib_find_cached_gid(cma_dev->device, &gid,
 > 						 &id_priv->id.port_num, NULL);
 > 			if (!ret)
 > 				goto out;
 > 		}
 > 	}
 > 
 > 	memcpy(&gid, dev_addr->src_dev_addr +
 > 	       rdma_addr_gid_offset(dev_addr), sizeof gid);
 > 	list_for_each_entry(cma_dev, &dev_list, list) {
 > 		ret = ib_find_cached_gid(cma_dev->device, &gid,
 > 					 &id_priv->id.port_num, NULL);
 > 		if (!ret)
 > 			break;
 > 	}
 > 
 > out:

This duplication of the code in the loop ends up looking pretty bad, and
indeed the change to the function doesn't make much sense to me:

 > @@ -330,15 +348,29 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv)
 >  	union ib_gid gid;
 >  	int ret = -ENODEV;
 >  
 > -	rdma_addr_get_sgid(dev_addr, &gid);
 > +	if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
 > +		iboe_addr_get_sgid(dev_addr, &gid);
 > +		list_for_each_entry(cma_dev, &dev_list, list) {
 > +			ret = ib_find_cached_gid(cma_dev->device, &gid,
 > +						 &id_priv->id.port_num, NULL);
 > +			if (!ret)
 > +				goto out;
 > +		}
 > +	}
 > +
 > +	memcpy(&gid, dev_addr->src_dev_addr +
 > +	       rdma_addr_gid_offset(dev_addr), sizeof gid);

I thought the whole point of this change:

 >  static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
 >  {
 > -	memcpy(gid, dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid);
 > +	if (dev_addr->transport == RDMA_TRANSPORT_IB &&
 > +	    dev_addr->dev_type != ARPHRD_INFINIBAND)
 > +		iboe_addr_get_sgid(dev_addr, gid);
 > +	else
 > +		memcpy(gid, dev_addr->src_dev_addr +
 > +		       rdma_addr_gid_offset(dev_addr), sizeof *gid);
 >  }

is that rdma_addr_get_sgid() now calls iboe_addr_get_sgid for IBoE
devices, and does the original thing in the other case.  So I don't see
why any change to cma_acquire_dev() is needed at all?

 - R.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
       [not found]         ` <adavd6w37lp.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
@ 2010-08-29 14:39           ` Eli Cohen
  2010-09-01 20:05             ` Hefty, Sean
  2010-09-02 17:46             ` Roland Dreier
  0 siblings, 2 replies; 12+ messages in thread
From: Eli Cohen @ 2010-08-29 14:39 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Hefty, Sean, RDMA list

On Thu, Aug 26, 2010 at 11:14:26PM -0700, Roland Dreier wrote:
> 
> I thought the whole point of this change:
> 
>  >  static inline void rdma_addr_get_sgid(struct rdma_dev_addr *dev_addr, union ib_gid *gid)
>  >  {
>  > -	memcpy(gid, dev_addr->src_dev_addr + rdma_addr_gid_offset(dev_addr), sizeof *gid);
>  > +	if (dev_addr->transport == RDMA_TRANSPORT_IB &&
>  > +	    dev_addr->dev_type != ARPHRD_INFINIBAND)
>  > +		iboe_addr_get_sgid(dev_addr, gid);
>  > +	else
>  > +		memcpy(gid, dev_addr->src_dev_addr +
>  > +		       rdma_addr_gid_offset(dev_addr), sizeof *gid);
>  >  }
> 
> is that rdma_addr_get_sgid() now calls iboe_addr_get_sgid for IBoE
> devices, and does the original thing in the other case.  So I don't see
> why any change to cma_acquire_dev() is needed at all?
> 

The point is it cma_acquire_dev() may get called when
dev_addr->transport has not yet been set so we can't rely on its value
to retrieve the correct GID; for example when it gets called by
rdma_bind_addr() it will only set the transport a few lines down the
function when calling cma_attach_to_dev(). That's why I may have to
look for the GID in the IBoE case.
I agree that traversing the list twice does not look so good so how
about this:

static int cma_acquire_dev(struct rdma_id_private *id_priv)
{
	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
	struct cma_device *cma_dev;
	union ib_gid gid, iboe_gid;
	int ret = -ENODEV;

	iboe_addr_get_sgid(dev_addr, &iboe_gid);
	memcpy(&gid, dev_addr->src_dev_addr +
	       rdma_addr_gid_offset(dev_addr), sizeof gid);
	list_for_each_entry(cma_dev, &dev_list, list) {
		ret = ib_find_cached_gid(cma_dev->device, &gid,
					 &id_priv->id.port_num, NULL);
		if (!ret)
			break;
		if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
			ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
						 &id_priv->id.port_num, NULL);
			if (!ret)
				break;
		}
	}

	if (!ret)
		cma_attach_to_dev(id_priv, cma_dev);

	return ret;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-08-29 14:39           ` Eli Cohen
@ 2010-09-01 20:05             ` Hefty, Sean
  2010-09-02 17:46             ` Roland Dreier
  1 sibling, 0 replies; 12+ messages in thread
From: Hefty, Sean @ 2010-09-01 20:05 UTC (permalink / raw)
  To: Eli Cohen, Roland Dreier; +Cc: RDMA list

> The point is it cma_acquire_dev() may get called when
> dev_addr->transport has not yet been set so we can't rely on its value
> to retrieve the correct GID; for example when it gets called by
> rdma_bind_addr() it will only set the transport a few lines down the
> function when calling cma_attach_to_dev(). That's why I may have to
> look for the GID in the IBoE case.
> I agree that traversing the list twice does not look so good so how
> about this:

I dislike the idea of guessing where the GID is when trying to perform these matches.  Is there any chance of getting a false match?

Is there some other approach that anyone can think of for handling this?  Maybe register the netdev HW address with ib_addr or rdma_cm?
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-08-29 14:39           ` Eli Cohen
  2010-09-01 20:05             ` Hefty, Sean
@ 2010-09-02 17:46             ` Roland Dreier
       [not found]               ` <adaeidcnin1.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Roland Dreier @ 2010-09-02 17:46 UTC (permalink / raw)
  To: Eli Cohen; +Cc: Hefty, Sean, RDMA list

 > The point is it cma_acquire_dev() may get called when
 > dev_addr->transport has not yet been set so we can't rely on its value
 > to retrieve the correct GID; for example when it gets called by
 > rdma_bind_addr() it will only set the transport a few lines down the
 > function when calling cma_attach_to_dev(). That's why I may have to
 > look for the GID in the IBoE case.

I see.  We just have the address but the RDMA CM API doesn't give us the
type exactly (we just know the ARPHRD type).

 > I agree that traversing the list twice does not look so good so how
 > about this:

 > static int cma_acquire_dev(struct rdma_id_private *id_priv)
 > {
 > 	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
 > 	struct cma_device *cma_dev;
 > 	union ib_gid gid, iboe_gid;
 > 	int ret = -ENODEV;
 > 
 > 	iboe_addr_get_sgid(dev_addr, &iboe_gid);
 > 	memcpy(&gid, dev_addr->src_dev_addr +
 > 	       rdma_addr_gid_offset(dev_addr), sizeof gid);

I wish there were a cleaner way to write all this...

 > 	list_for_each_entry(cma_dev, &dev_list, list) {
 > 		ret = ib_find_cached_gid(cma_dev->device, &gid,
 > 					 &id_priv->id.port_num, NULL);
 > 		if (!ret)
 > 			break;
 > 		if (dev_addr->dev_type != ARPHRD_INFINIBAND) {
 > 			ret = ib_find_cached_gid(cma_dev->device, &iboe_gid,
 > 						 &id_priv->id.port_num, NULL);
 > 			if (!ret)
 > 				break;
 > 		}

looks better but since we know everything about the device we're
comparing to, can't we do something like:

		if (addr and dev ARPHRD agree)
			if (dev is IBoE)
				ret = ib_find_gid(iboe_gid);
			else
				ret = ib_find_gid(gid);

		if (!ret)
			break;

(by the way, it seems we can use ib_find_gid() here since we are in a
sleepable context -- no need to rely on the cached_gid stuff, which I
would like to phase out someday)

 > 	}
 > 
 > 	if (!ret)
 > 		cma_attach_to_dev(id_priv, cma_dev);
 > 
 > 	return ret;
 > }
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
       [not found]               ` <adaeidcnin1.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
@ 2010-09-02 19:27                 ` Eli Cohen
  2010-09-02 20:10                   ` Roland Dreier
  2010-09-02 20:30                   ` Hefty, Sean
  0 siblings, 2 replies; 12+ messages in thread
From: Eli Cohen @ 2010-09-02 19:27 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Hefty, Sean, RDMA list

On Thu, Sep 02, 2010 at 10:46:10AM -0700, Roland Dreier wrote:
> 
> looks better but since we know everything about the device we're
> comparing to, can't we do something like:
> 
> 		if (addr and dev ARPHRD agree)
> 			if (dev is IBoE)
> 				ret = ib_find_gid(iboe_gid);
> 			else
> 				ret = ib_find_gid(gid);
> 
> 		if (!ret)
> 			break;

This looks even better with no duplicate checks.

> 
> (by the way, it seems we can use ib_find_gid() here since we are in a
> sleepable context -- no need to rely on the cached_gid stuff, which I
> would like to phase out someday)
> 

Sure, I can change that too.
Please let me know if you'd like me to send a new series or just send
this patch again.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-09-02 19:27                 ` Eli Cohen
@ 2010-09-02 20:10                   ` Roland Dreier
       [not found]                     ` <aday6bjnbyu.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
  2010-09-02 20:30                   ` Hefty, Sean
  1 sibling, 1 reply; 12+ messages in thread
From: Roland Dreier @ 2010-09-02 20:10 UTC (permalink / raw)
  To: Eli Cohen; +Cc: Hefty, Sean, RDMA list

 > Please let me know if you'd like me to send a new series or just send
 > this patch again.

Please just resend this, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCHv10 02/12] ib_core: IBoE CMA device binding
  2010-09-02 19:27                 ` Eli Cohen
  2010-09-02 20:10                   ` Roland Dreier
@ 2010-09-02 20:30                   ` Hefty, Sean
       [not found]                     ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB44BA6F-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Hefty, Sean @ 2010-09-02 20:30 UTC (permalink / raw)
  To: Eli Cohen, Roland Dreier; +Cc: RDMA list

> > looks better but since we know everything about the device we're
> > comparing to, can't we do something like:
> >
> > 		if (addr and dev ARPHRD agree)
> > 			if (dev is IBoE)
> > 				ret = ib_find_gid(iboe_gid);
> > 			else
> > 				ret = ib_find_gid(gid);
> >
> > 		if (!ret)
> > 			break;
> 
> This looks even better with no duplicate checks.

In cma_acquire_dev, we try to match up a portion of the dev_addr with a GID.  The current code does this by checking the dev_type to determine if the GID would start at offset 0 or 4 in the dev_addr.  With IBoE, this check is no longer possible, so we select the offset based on the rdma device that we're trying to compare against, rather than using data stored with the net_device.

Maybe it's just so unlikely that we don't care, but can this lead to a false match?  (and maybe the current code can have a false match..)
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
       [not found]                     ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB44BA6F-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2010-09-02 21:57                       ` Roland Dreier
  0 siblings, 0 replies; 12+ messages in thread
From: Roland Dreier @ 2010-09-02 21:57 UTC (permalink / raw)
  To: Hefty, Sean; +Cc: Eli Cohen, RDMA list

 > In cma_acquire_dev, we try to match up a portion of the dev_addr with
 > a GID.  The current code does this by checking the dev_type to
 > determine if the GID would start at offset 0 or 4 in the dev_addr.
 > With IBoE, this check is no longer possible, so we select the offset
 > based on the rdma device that we're trying to compare against, rather
 > than using data stored with the net_device.
 > 
 > Maybe it's just so unlikely that we don't care, but can this lead to
 > a false match?  (and maybe the current code can have a false match..)

I don't think there's any chance of a false positive.  We can tell if
the GID offset is 0 or 4 based on the ARPHRD type of the address we're
comparing, so that should always be correct.  The only difference with
between IBoE and iWARP GIDs is that the IBoE GIDs are actually IPv6
link-local addresses, so they need some munging to convert back to
ethernet hardware addresses.  But in any case there shouldn't be a
collision unless there are duplicate ethernet addresses.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCHv10 02/12] ib_core: IBoE CMA device binding
       [not found]                     ` <aday6bjnbyu.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
@ 2010-09-07 15:18                       ` Eli Cohen
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Cohen @ 2010-09-07 15:18 UTC (permalink / raw)
  To: Roland Dreier; +Cc: Hefty, Sean, RDMA list

On Thu, Sep 02, 2010 at 01:10:17PM -0700, Roland Dreier wrote:
> Please just resend this, thanks.

Here's the new code. I added a function that tries to find a match for
a given port, istead of ib_find_cached_gid() which searches all the
ports.
I tested this on a machine with two cards with different
configurations and it works fine.

static int find_gid_port(struct ib_device *device, union ib_gid	*gid, u8 port_num)
{
	int i;
	int err;
	struct ib_port_attr props;
	union ib_gid tmp;

	err = ib_query_port(device, port_num, &props);
	if (err)
		return 1;

	for (i = 0; i < props.gid_tbl_len; ++i) {
		err = ib_query_gid(device, port_num, i, &tmp);
		if (err)
			return 1;
		if (!memcmp(&tmp, gid, sizeof tmp))
			return 0;
	}

	return -EAGAIN;
}

static int cma_acquire_dev(struct rdma_id_private *id_priv)
{
	struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
	struct cma_device *cma_dev;
	union ib_gid gid, iboe_gid;
	int ret = -ENODEV;
	u8 port;
	enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
		IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;

	iboe_addr_get_sgid(dev_addr, &iboe_gid);
	memcpy(&gid, dev_addr->src_dev_addr +
	       rdma_addr_gid_offset(dev_addr), sizeof gid);
	list_for_each_entry(cma_dev, &dev_list, list) {
		for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
			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 &&
				    rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
					ret = find_gid_port(cma_dev->device, &iboe_gid, port);
				else
					ret = find_gid_port(cma_dev->device, &gid, port);

				if (!ret) {
					id_priv->id.port_num = port;
					goto out;
				} else if (ret == 1)
					break;
			}
		}
	}

out:
	if (!ret)
		cma_attach_to_dev(id_priv, cma_dev);

	return ret;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2010-09-07 15:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-26 14:17 [PATCHv10 02/12] ib_core: IBoE CMA device binding Eli Cohen
2010-08-26 20:11 ` Hefty, Sean
     [not found]   ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB26491D-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2010-08-27  5:42     ` Eli Cohen
2010-08-27  6:14       ` Roland Dreier
     [not found]         ` <adavd6w37lp.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2010-08-29 14:39           ` Eli Cohen
2010-09-01 20:05             ` Hefty, Sean
2010-09-02 17:46             ` Roland Dreier
     [not found]               ` <adaeidcnin1.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2010-09-02 19:27                 ` Eli Cohen
2010-09-02 20:10                   ` Roland Dreier
     [not found]                     ` <aday6bjnbyu.fsf-FYB4Gu1CFyUAvxtiuMwx3w@public.gmane.org>
2010-09-07 15:18                       ` Eli Cohen
2010-09-02 20:30                   ` Hefty, Sean
     [not found]                     ` <CF9C39F99A89134C9CF9C4CCB68B8DDF25AB44BA6F-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2010-09-02 21:57                       ` Roland Dreier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.