From 40e7e1643cd67bbdd0865372c4ff64d42d1aaf0b Mon Sep 17 00:00:00 2001
From: Luoyouming <luoyouming@huawei.com>
Date: Mon, 29 Jan 2024 15:38:18 +0800
Subject: [PATCH 1/4] libhns: Fix overwritten SL in DSCP mode

After configuring the DSCP mode, the driver needs to use the
priority as the SL instead of the user-configured SL.
Adjusting the assignment order ensures that the priority is
used as the SL in DSCP mode.

Fixes: 6ec5d1f3f04c ("libhns: Support DSCP")
Signed-off-by: Luoyouming <luoyouming@huawei.com>
---
 providers/hns/hns_roce_u_hw_v2.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c
index 8f071e1..42b4f32 100644
--- a/providers/hns/hns_roce_u_hw_v2.c
+++ b/providers/hns/hns_roce_u_hw_v2.c
@@ -1896,7 +1896,9 @@ static void record_qp_attr(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 	if (attr_mask & IBV_QP_PORT)
 		hr_qp->port_num = attr->port_num;
 
-	if (attr_mask & IBV_QP_AV)
+	if (hr_qp->tc_mode == HNS_ROCE_TC_MAP_MODE_DSCP)
+		hr_qp->sl = hr_qp->priority;
+	else if (attr_mask & IBV_QP_AV)
 		hr_qp->sl = attr->ah_attr.sl;
 
 	if (attr_mask & IBV_QP_QKEY)
@@ -1959,9 +1961,6 @@ static int hns_roce_u_v2_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
 		hns_roce_init_qp_indices(to_hr_qp(qp));
 	}
 
-	if (hr_qp->tc_mode == HNS_ROCE_TC_MAP_MODE_DSCP)
-		hr_qp->sl = hr_qp->priority;
-
 	/* Try to shrink the DCA mem */
 	if (ctx->dca_ctx.mem_cnt > 0)
 		hns_roce_shrink_dca_mem(ctx);
-- 
2.33.0

