diff mbox

[v4,14/27] IB/Verbs: Reform cma_acquire_dev()

Message ID 552F6E43.2070700@profitbricks.com (mailing list archive)
State Rejected
Headers show

Commit Message

Michael Wang April 16, 2015, 8:09 a.m. UTC
Reform cma_acquire_dev() with management helpers, introduce
cma_validate_port() to make the code more clean.

Cc: Steve Wise <swise@opengridcomputing.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Doug Ledford <dledford@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Michael Wang <yun.wang@profitbricks.com>
---
 drivers/infiniband/core/cma.c | 69 +++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 28 deletions(-)

Comments

Hal Rosenstock April 16, 2015, 1:19 p.m. UTC | #1
On 4/16/2015 4:09 AM, Michael Wang wrote:
> 
> Reform cma_acquire_dev() with management helpers, introduce
> cma_validate_port() to make the code more clean.
> 
> Cc: Steve Wise <swise@opengridcomputing.com>
> Cc: Tom Talpey <tom@talpey.com>
> Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
> Cc: Doug Ledford <dledford@redhat.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: Sean Hefty <sean.hefty@intel.com>
> Signed-off-by: Michael Wang <yun.wang@profitbricks.com>
> ---
>  drivers/infiniband/core/cma.c | 69 +++++++++++++++++++++++++------------------
>  1 file changed, 41 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index b520882..902cc1a 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -370,18 +370,36 @@ static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_a
>  	return ret;
>  }
>  
> +static inline int cma_validate_port(struct ib_device *device, u8 port,
> +				      union ib_gid *gid, int dev_type)
> +{
> +	u8 found_port;
> +	int ret = -ENODEV;
> +
> +	if ((dev_type == ARPHRD_INFINIBAND) && !rdma_tech_ib(device, port))
> +		return ret;
> +
> +	if ((dev_type != ARPHRD_INFINIBAND) && rdma_tech_ib(device, port))
> +		return ret;
> +
> +	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
> +
> +	if (!ret && (port == found_port))
> +		return 0;
> +
> +	return ret;

Should the case where ret = 0 and port != found_port need to be handled
the same as currently ? It looks different to me since in this case the
port will be saved into id_priv->id.port_num whereas currently it isn't.

-- Hal

> +}
> +
>  static int cma_acquire_dev(struct rdma_id_private *id_priv,
>  			   struct rdma_id_private *listen_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;
> +	union ib_gid gid, iboe_gid, *gidp;
>  	int ret = -ENODEV;
> -	u8 port, found_port;
> -	enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
> -		IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
> +	u8 port;
>  
> -	if (dev_ll != IB_LINK_LAYER_INFINIBAND &&
> +	if (dev_addr->dev_type != ARPHRD_INFINIBAND &&
>  	    id_priv->id.ps == RDMA_PS_IPOIB)
>  		return -EINVAL;
>  
> @@ -391,41 +409,36 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
>  
>  	memcpy(&gid, dev_addr->src_dev_addr +
>  	       rdma_addr_gid_offset(dev_addr), sizeof gid);
> -	if (listen_id_priv &&
> -	    rdma_port_get_link_layer(listen_id_priv->id.device,
> -				     listen_id_priv->id.port_num) == dev_ll) {
> +
> +	if (listen_id_priv) {
>  		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 &&
> -		    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
> -			ret = ib_find_cached_gid(cma_dev->device, &gid,
> -						 &found_port, NULL);
> +		gidp = rdma_tech_iboe(cma_dev->device, port) ?
> +		       &iboe_gid : &gid;
>  
> -		if (!ret && (port  == found_port)) {
> -			id_priv->id.port_num = found_port;
> +		ret = cma_validate_port(cma_dev->device, port, gidp,
> +					dev_addr->dev_type);
> +		if (!ret) {
> +			id_priv->id.port_num = port;
>  			goto out;
>  		}
>  	}
> +
>  	list_for_each_entry(cma_dev, &dev_list, list) {
>  		for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
>  			if (listen_id_priv &&
>  			    listen_id_priv->cma_dev == cma_dev &&
>  			    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 &&
> -				    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
> -					ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
> -
> -				if (!ret && (port == found_port)) {
> -					id_priv->id.port_num = found_port;
> -					goto out;
> -				}
> +
> +			gidp = rdma_tech_iboe(cma_dev->device, port) ?
> +			       &iboe_gid : &gid;
> +
> +			ret = cma_validate_port(cma_dev->device, port, gidp,
> +						dev_addr->dev_type);
> +			if (!ret) {
> +				id_priv->id.port_num = port;
> +				goto out;
>  			}
>  		}
>  	}

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael Wang April 16, 2015, 1:35 p.m. UTC | #2
On 04/16/2015 03:19 PM, Hal Rosenstock wrote:
[snip]
>>  
>> +static inline int cma_validate_port(struct ib_device *device, u8 port,
>> +				      union ib_gid *gid, int dev_type)
>> +{
>> +	u8 found_port;
>> +	int ret = -ENODEV;
>> +
>> +	if ((dev_type == ARPHRD_INFINIBAND) && !rdma_tech_ib(device, port))
>> +		return ret;
>> +
>> +	if ((dev_type != ARPHRD_INFINIBAND) && rdma_tech_ib(device, port))
>> +		return ret;
>> +
>> +	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
>> +
>> +	if (!ret && (port == found_port))
>> +		return 0;
>> +
>> +	return ret;
> 
> Should the case where ret = 0 and port != found_port need to be handled
> the same as currently ? It looks different to me since in this case the
> port will be saved into id_priv->id.port_num whereas currently it isn't.

I get your point :-) what about:

	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
	if (port != found_port)
		return -ENODEV;

	return ret

Regards,
Michael Wang

> 
> -- Hal
> 
>> +}
>> +
>>  static int cma_acquire_dev(struct rdma_id_private *id_priv,
>>  			   struct rdma_id_private *listen_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;
>> +	union ib_gid gid, iboe_gid, *gidp;
>>  	int ret = -ENODEV;
>> -	u8 port, found_port;
>> -	enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
>> -		IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
>> +	u8 port;
>>  
>> -	if (dev_ll != IB_LINK_LAYER_INFINIBAND &&
>> +	if (dev_addr->dev_type != ARPHRD_INFINIBAND &&
>>  	    id_priv->id.ps == RDMA_PS_IPOIB)
>>  		return -EINVAL;
>>  
>> @@ -391,41 +409,36 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
>>  
>>  	memcpy(&gid, dev_addr->src_dev_addr +
>>  	       rdma_addr_gid_offset(dev_addr), sizeof gid);
>> -	if (listen_id_priv &&
>> -	    rdma_port_get_link_layer(listen_id_priv->id.device,
>> -				     listen_id_priv->id.port_num) == dev_ll) {
>> +
>> +	if (listen_id_priv) {
>>  		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 &&
>> -		    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
>> -			ret = ib_find_cached_gid(cma_dev->device, &gid,
>> -						 &found_port, NULL);
>> +		gidp = rdma_tech_iboe(cma_dev->device, port) ?
>> +		       &iboe_gid : &gid;
>>  
>> -		if (!ret && (port  == found_port)) {
>> -			id_priv->id.port_num = found_port;
>> +		ret = cma_validate_port(cma_dev->device, port, gidp,
>> +					dev_addr->dev_type);
>> +		if (!ret) {
>> +			id_priv->id.port_num = port;
>>  			goto out;
>>  		}
>>  	}
>> +
>>  	list_for_each_entry(cma_dev, &dev_list, list) {
>>  		for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
>>  			if (listen_id_priv &&
>>  			    listen_id_priv->cma_dev == cma_dev &&
>>  			    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 &&
>> -				    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
>> -					ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
>> -
>> -				if (!ret && (port == found_port)) {
>> -					id_priv->id.port_num = found_port;
>> -					goto out;
>> -				}
>> +
>> +			gidp = rdma_tech_iboe(cma_dev->device, port) ?
>> +			       &iboe_gid : &gid;
>> +
>> +			ret = cma_validate_port(cma_dev->device, port, gidp,
>> +						dev_addr->dev_type);
>> +			if (!ret) {
>> +				id_priv->id.port_num = port;
>> +				goto out;
>>  			}
>>  		}
>>  	}
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Hal Rosenstock April 16, 2015, 1:41 p.m. UTC | #3
On 4/16/2015 9:35 AM, Michael Wang wrote:
> 
> 
> On 04/16/2015 03:19 PM, Hal Rosenstock wrote:
> [snip]
>>>  
>>> +static inline int cma_validate_port(struct ib_device *device, u8 port,
>>> +				      union ib_gid *gid, int dev_type)
>>> +{
>>> +	u8 found_port;
>>> +	int ret = -ENODEV;
>>> +
>>> +	if ((dev_type == ARPHRD_INFINIBAND) && !rdma_tech_ib(device, port))
>>> +		return ret;
>>> +
>>> +	if ((dev_type != ARPHRD_INFINIBAND) && rdma_tech_ib(device, port))
>>> +		return ret;
>>> +
>>> +	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
>>> +
>>> +	if (!ret && (port == found_port))
>>> +		return 0;
>>> +
>>> +	return ret;
>>
>> Should the case where ret = 0 and port != found_port need to be handled
>> the same as currently ? It looks different to me since in this case the
>> port will be saved into id_priv->id.port_num whereas currently it isn't.
> 
> I get your point :-) what about:
> 
> 	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
> 	if (port != found_port)
> 		return -ENODEV;
> 
> 	return ret;

Yes, that looks to me to be consistent with the current implementation.

-- Hal

> Regards,
> Michael Wang
> 
>>
>> -- Hal
>>
>>> +}
>>> +
>>>  static int cma_acquire_dev(struct rdma_id_private *id_priv,
>>>  			   struct rdma_id_private *listen_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;
>>> +	union ib_gid gid, iboe_gid, *gidp;
>>>  	int ret = -ENODEV;
>>> -	u8 port, found_port;
>>> -	enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
>>> -		IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
>>> +	u8 port;
>>>  
>>> -	if (dev_ll != IB_LINK_LAYER_INFINIBAND &&
>>> +	if (dev_addr->dev_type != ARPHRD_INFINIBAND &&
>>>  	    id_priv->id.ps == RDMA_PS_IPOIB)
>>>  		return -EINVAL;
>>>  
>>> @@ -391,41 +409,36 @@ static int cma_acquire_dev(struct rdma_id_private *id_priv,
>>>  
>>>  	memcpy(&gid, dev_addr->src_dev_addr +
>>>  	       rdma_addr_gid_offset(dev_addr), sizeof gid);
>>> -	if (listen_id_priv &&
>>> -	    rdma_port_get_link_layer(listen_id_priv->id.device,
>>> -				     listen_id_priv->id.port_num) == dev_ll) {
>>> +
>>> +	if (listen_id_priv) {
>>>  		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 &&
>>> -		    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
>>> -			ret = ib_find_cached_gid(cma_dev->device, &gid,
>>> -						 &found_port, NULL);
>>> +		gidp = rdma_tech_iboe(cma_dev->device, port) ?
>>> +		       &iboe_gid : &gid;
>>>  
>>> -		if (!ret && (port  == found_port)) {
>>> -			id_priv->id.port_num = found_port;
>>> +		ret = cma_validate_port(cma_dev->device, port, gidp,
>>> +					dev_addr->dev_type);
>>> +		if (!ret) {
>>> +			id_priv->id.port_num = port;
>>>  			goto out;
>>>  		}
>>>  	}
>>> +
>>>  	list_for_each_entry(cma_dev, &dev_list, list) {
>>>  		for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
>>>  			if (listen_id_priv &&
>>>  			    listen_id_priv->cma_dev == cma_dev &&
>>>  			    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 &&
>>> -				    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
>>> -					ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
>>> -
>>> -				if (!ret && (port == found_port)) {
>>> -					id_priv->id.port_num = found_port;
>>> -					goto out;
>>> -				}
>>> +
>>> +			gidp = rdma_tech_iboe(cma_dev->device, port) ?
>>> +			       &iboe_gid : &gid;
>>> +
>>> +			ret = cma_validate_port(cma_dev->device, port, gidp,
>>> +						dev_addr->dev_type);
>>> +			if (!ret) {
>>> +				id_priv->id.port_num = port;
>>> +				goto out;
>>>  			}
>>>  		}
>>>  	}
>>
> 

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

Patch

diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index b520882..902cc1a 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -370,18 +370,36 @@  static int cma_translate_addr(struct sockaddr *addr, struct rdma_dev_addr *dev_a
 	return ret;
 }
 
+static inline int cma_validate_port(struct ib_device *device, u8 port,
+				      union ib_gid *gid, int dev_type)
+{
+	u8 found_port;
+	int ret = -ENODEV;
+
+	if ((dev_type == ARPHRD_INFINIBAND) && !rdma_tech_ib(device, port))
+		return ret;
+
+	if ((dev_type != ARPHRD_INFINIBAND) && rdma_tech_ib(device, port))
+		return ret;
+
+	ret = ib_find_cached_gid(device, gid, &found_port, NULL);
+
+	if (!ret && (port == found_port))
+		return 0;
+
+	return ret;
+}
+
 static int cma_acquire_dev(struct rdma_id_private *id_priv,
 			   struct rdma_id_private *listen_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;
+	union ib_gid gid, iboe_gid, *gidp;
 	int ret = -ENODEV;
-	u8 port, found_port;
-	enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
-		IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
+	u8 port;
 
-	if (dev_ll != IB_LINK_LAYER_INFINIBAND &&
+	if (dev_addr->dev_type != ARPHRD_INFINIBAND &&
 	    id_priv->id.ps == RDMA_PS_IPOIB)
 		return -EINVAL;
 
@@ -391,41 +409,36 @@  static int cma_acquire_dev(struct rdma_id_private *id_priv,
 
 	memcpy(&gid, dev_addr->src_dev_addr +
 	       rdma_addr_gid_offset(dev_addr), sizeof gid);
-	if (listen_id_priv &&
-	    rdma_port_get_link_layer(listen_id_priv->id.device,
-				     listen_id_priv->id.port_num) == dev_ll) {
+
+	if (listen_id_priv) {
 		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 &&
-		    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
-			ret = ib_find_cached_gid(cma_dev->device, &gid,
-						 &found_port, NULL);
+		gidp = rdma_tech_iboe(cma_dev->device, port) ?
+		       &iboe_gid : &gid;
 
-		if (!ret && (port  == found_port)) {
-			id_priv->id.port_num = found_port;
+		ret = cma_validate_port(cma_dev->device, port, gidp,
+					dev_addr->dev_type);
+		if (!ret) {
+			id_priv->id.port_num = port;
 			goto out;
 		}
 	}
+
 	list_for_each_entry(cma_dev, &dev_list, list) {
 		for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
 			if (listen_id_priv &&
 			    listen_id_priv->cma_dev == cma_dev &&
 			    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 &&
-				    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
-					ret = ib_find_cached_gid(cma_dev->device, &gid, &found_port, NULL);
-
-				if (!ret && (port == found_port)) {
-					id_priv->id.port_num = found_port;
-					goto out;
-				}
+
+			gidp = rdma_tech_iboe(cma_dev->device, port) ?
+			       &iboe_gid : &gid;
+
+			ret = cma_validate_port(cma_dev->device, port, gidp,
+						dev_addr->dev_type);
+			if (!ret) {
+				id_priv->id.port_num = port;
+				goto out;
 			}
 		}
 	}