diff mbox series

[for-next,02/13] RDMA/hns: Optimized the verb of creating ah

Message ID 1532503781-45205-3-git-send-email-oulijun@huawei.com (mailing list archive)
State Changes Requested
Headers show
Series Updates hns for v4.19 | expand

Commit Message

Lijun Ou July 25, 2018, 7:29 a.m. UTC
This patch mainly improves the create ah verb, includes add
IB_AH_GRH enable bit and assign the value for hoplimit of
address vector.

Signed-off-by: Lijun Ou <oulijun@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_ah.c | 72 +++++++++++++++++++++------------
 1 file changed, 46 insertions(+), 26 deletions(-)

Comments

Jason Gunthorpe July 26, 2018, 10:46 p.m. UTC | #1
On Wed, Jul 25, 2018 at 03:29:30PM +0800, Lijun Ou wrote:
> This patch mainly improves the create ah verb, includes add
> IB_AH_GRH enable bit and assign the value for hoplimit of
> address vector.
> 
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>  drivers/infiniband/hw/hns/hns_roce_ah.c | 72 +++++++++++++++++++++------------
>  1 file changed, 46 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c
> index 14efa3b..3e20a45 100644
> +++ b/drivers/infiniband/hw/hns/hns_roce_ah.c
> @@ -48,38 +48,58 @@ struct ib_ah *hns_roce_create_ah(struct ib_pd *ibpd,
>  	struct device *dev = hr_dev->dev;
>  	struct hns_roce_ah *ah;
>  	u16 vlan_tag = 0xffff;
> +	struct in6_addr in6;
>  	const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
>  
>  	ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
>  	if (!ah)
>  		return ERR_PTR(-ENOMEM);
>  
> -	/* Get mac address */
> -	memcpy(ah->av.mac, ah_attr->roce.dmac, ETH_ALEN);
> -
> -	gid_attr = ah_attr->grh.sgid_attr;
> -	if (is_vlan_dev(gid_attr->ndev))
> -		vlan_tag = vlan_dev_vlan_id(gid_attr->ndev);
> -
> -	if (vlan_tag < 0x1000)
> -		vlan_tag |= (rdma_ah_get_sl(ah_attr) &
> -			     HNS_ROCE_VLAN_SL_BIT_MASK) <<
> -			     HNS_ROCE_VLAN_SL_SHIFT;
> -
> -	ah->av.port_pd = cpu_to_be32(to_hr_pd(ibpd)->pdn |
> -				     (rdma_ah_get_port_num(ah_attr) <<
> -				     HNS_ROCE_PORT_NUM_SHIFT));
> -	ah->av.gid_index = grh->sgid_index;
> -	ah->av.vlan = cpu_to_le16(vlan_tag);
> -	dev_dbg(dev, "gid_index = 0x%x,vlan = 0x%x\n", ah->av.gid_index,
> -		ah->av.vlan);
> -
> -	if (rdma_ah_get_static_rate(ah_attr))
> -		ah->av.stat_rate = IB_RATE_10_GBPS;
> -
> -	memcpy(ah->av.dgid, grh->dgid.raw, HNS_ROCE_GID_SIZE);
> -	ah->av.sl_tclass_flowlabel = cpu_to_le32(rdma_ah_get_sl(ah_attr) <<
> -						 HNS_ROCE_SL_SHIFT);
> +	if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {

hns is a roce only driver, right?

roce driver's create_ah is never called with no GRH, the core code
guarentees this.

So, I'm not sure what this patch is doing?

Jason
--
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
Lijun Ou July 28, 2018, 3:37 a.m. UTC | #2
在 2018/7/27 6:46, Jason Gunthorpe 写道:
> On Wed, Jul 25, 2018 at 03:29:30PM +0800, Lijun Ou wrote:
>> This patch mainly improves the create ah verb, includes add
>> IB_AH_GRH enable bit and assign the value for hoplimit of
>> address vector.
>>
>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>  drivers/infiniband/hw/hns/hns_roce_ah.c | 72 +++++++++++++++++++++------------
>>  1 file changed, 46 insertions(+), 26 deletions(-)
>>
>> diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c
>> index 14efa3b..3e20a45 100644
>> +++ b/drivers/infiniband/hw/hns/hns_roce_ah.c
>> @@ -48,38 +48,58 @@ struct ib_ah *hns_roce_create_ah(struct ib_pd *ibpd,
>>  	struct device *dev = hr_dev->dev;
>>  	struct hns_roce_ah *ah;
>>  	u16 vlan_tag = 0xffff;
>> +	struct in6_addr in6;
>>  	const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
>>  
>>  	ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
>>  	if (!ah)
>>  		return ERR_PTR(-ENOMEM);
>>  
>> -	/* Get mac address */
>> -	memcpy(ah->av.mac, ah_attr->roce.dmac, ETH_ALEN);
>> -
>> -	gid_attr = ah_attr->grh.sgid_attr;
>> -	if (is_vlan_dev(gid_attr->ndev))
>> -		vlan_tag = vlan_dev_vlan_id(gid_attr->ndev);
>> -
>> -	if (vlan_tag < 0x1000)
>> -		vlan_tag |= (rdma_ah_get_sl(ah_attr) &
>> -			     HNS_ROCE_VLAN_SL_BIT_MASK) <<
>> -			     HNS_ROCE_VLAN_SL_SHIFT;
>> -
>> -	ah->av.port_pd = cpu_to_be32(to_hr_pd(ibpd)->pdn |
>> -				     (rdma_ah_get_port_num(ah_attr) <<
>> -				     HNS_ROCE_PORT_NUM_SHIFT));
>> -	ah->av.gid_index = grh->sgid_index;
>> -	ah->av.vlan = cpu_to_le16(vlan_tag);
>> -	dev_dbg(dev, "gid_index = 0x%x,vlan = 0x%x\n", ah->av.gid_index,
>> -		ah->av.vlan);
>> -
>> -	if (rdma_ah_get_static_rate(ah_attr))
>> -		ah->av.stat_rate = IB_RATE_10_GBPS;
>> -
>> -	memcpy(ah->av.dgid, grh->dgid.raw, HNS_ROCE_GID_SIZE);
>> -	ah->av.sl_tclass_flowlabel = cpu_to_le32(rdma_ah_get_sl(ah_attr) <<
>> -						 HNS_ROCE_SL_SHIFT);
>> +	if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
> 
> hns is a roce only driver, right?
> 
Yes
> roce driver's create_ah is never called with no GRH, the core code
> guarentees this.
> 
> So, I'm not sure what this patch is doing?
> 
ok, I will anlaysis with the new core code before decide to modifying it.

thanks
> Jason
> 
> .
> 


--
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 series

Patch

diff --git a/drivers/infiniband/hw/hns/hns_roce_ah.c b/drivers/infiniband/hw/hns/hns_roce_ah.c
index 14efa3b..3e20a45 100644
--- a/drivers/infiniband/hw/hns/hns_roce_ah.c
+++ b/drivers/infiniband/hw/hns/hns_roce_ah.c
@@ -48,38 +48,58 @@  struct ib_ah *hns_roce_create_ah(struct ib_pd *ibpd,
 	struct device *dev = hr_dev->dev;
 	struct hns_roce_ah *ah;
 	u16 vlan_tag = 0xffff;
+	struct in6_addr in6;
 	const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
 
 	ah = kzalloc(sizeof(*ah), GFP_ATOMIC);
 	if (!ah)
 		return ERR_PTR(-ENOMEM);
 
-	/* Get mac address */
-	memcpy(ah->av.mac, ah_attr->roce.dmac, ETH_ALEN);
-
-	gid_attr = ah_attr->grh.sgid_attr;
-	if (is_vlan_dev(gid_attr->ndev))
-		vlan_tag = vlan_dev_vlan_id(gid_attr->ndev);
-
-	if (vlan_tag < 0x1000)
-		vlan_tag |= (rdma_ah_get_sl(ah_attr) &
-			     HNS_ROCE_VLAN_SL_BIT_MASK) <<
-			     HNS_ROCE_VLAN_SL_SHIFT;
-
-	ah->av.port_pd = cpu_to_be32(to_hr_pd(ibpd)->pdn |
-				     (rdma_ah_get_port_num(ah_attr) <<
-				     HNS_ROCE_PORT_NUM_SHIFT));
-	ah->av.gid_index = grh->sgid_index;
-	ah->av.vlan = cpu_to_le16(vlan_tag);
-	dev_dbg(dev, "gid_index = 0x%x,vlan = 0x%x\n", ah->av.gid_index,
-		ah->av.vlan);
-
-	if (rdma_ah_get_static_rate(ah_attr))
-		ah->av.stat_rate = IB_RATE_10_GBPS;
-
-	memcpy(ah->av.dgid, grh->dgid.raw, HNS_ROCE_GID_SIZE);
-	ah->av.sl_tclass_flowlabel = cpu_to_le32(rdma_ah_get_sl(ah_attr) <<
-						 HNS_ROCE_SL_SHIFT);
+	if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
+		/* Get mac address */
+		memcpy(&in6, grh->dgid.raw, sizeof(grh->dgid.raw));
+		if (rdma_is_multicast_addr(&in6)) {
+			rdma_get_mcast_mac(&in6, ah->av.mac);
+		} else {
+			u8 *dmac = rdma_ah_retrieve_dmac(ah_attr);
+
+			if (!dmac) {
+				kfree(ah);
+				return ERR_PTR(-EINVAL);
+			}
+			memcpy(ah->av.mac, dmac, ETH_ALEN);
+		}
+
+		gid_attr = ah_attr->grh.sgid_attr;
+		if (is_vlan_dev(gid_attr->ndev))
+			vlan_tag = vlan_dev_vlan_id(gid_attr->ndev);
+
+		if (vlan_tag < 0x1000)
+			vlan_tag |= (rdma_ah_get_sl(ah_attr) &
+				     HNS_ROCE_VLAN_SL_BIT_MASK) <<
+				     HNS_ROCE_VLAN_SL_SHIFT;
+
+		ah->av.port_pd = cpu_to_be32(to_hr_pd(ibpd)->pdn |
+					    (rdma_ah_get_port_num(ah_attr) <<
+					     HNS_ROCE_PORT_NUM_SHIFT));
+		ah->av.gid_index = grh->sgid_index;
+		ah->av.vlan = cpu_to_le16(vlan_tag);
+		dev_dbg(dev, "gid_index = 0x%x,vlan = 0x%x\n", ah->av.gid_index,
+			ah->av.vlan);
+
+		if (rdma_ah_get_static_rate(ah_attr))
+			ah->av.stat_rate = IB_RATE_10_GBPS;
+
+		memcpy(ah->av.dgid, grh->dgid.raw, HNS_ROCE_GID_SIZE);
+		ah->av.sl_tclass_flowlabel =
+				cpu_to_le32(rdma_ah_get_sl(ah_attr) <<
+					    HNS_ROCE_SL_SHIFT);
+		ah->av.sl_tclass_flowlabel |=
+				cpu_to_le32((grh->traffic_class <<
+					    HNS_ROCE_TCLASS_SHIFT) |
+					    grh->flow_label);
+		ah->av.hop_limit = grh->hop_limit;
+	}
 
 	return &ah->ibah;
 }