From f4626313eea2c78a8fac4b007b08533371ce1501 Mon Sep 17 00:00:00 2001
From: Guofeng Yue <yueguofeng@hisilicon.com>
Date: Tue, 13 Sep 2022 20:09:27 +0800
Subject: libhns: Add the parsing of mac type in RoH mode

After parsing the mac type as RoH mode, the user driver
needs to set the dmac field of ud wqe to 0xFF, the hardware
will recognize this field, and increase the recognition of
the IP field in RoH mode, which is used for the CM link
building function in user mode.

Signed-off-by: Yangyang Li <liyangyang20@huawei.com>
Signed-off-by: Guofeng Yue <yueguofeng@hisilicon.com>
---
 providers/hns/hns_roce_u.c       | 2 ++
 providers/hns/hns_roce_u.h       | 6 ++++++
 providers/hns/hns_roce_u_hw_v2.c | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/providers/hns/hns_roce_u.c b/providers/hns/hns_roce_u.c
index 60b3fe1..20e3698 100644
--- a/providers/hns/hns_roce_u.c
+++ b/providers/hns/hns_roce_u.c
@@ -121,6 +121,8 @@ static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,
 				&resp.ibv_resp, sizeof(resp)))
 		goto err_free;
 
+	hr_dev->mac_type = resp.mac_type;
+
 	if (!resp.cqe_size)
 		context->cqe_size = HNS_ROCE_CQE_SIZE;
 	else if (resp.cqe_size <= HNS_ROCE_V3_CQE_SIZE)
diff --git a/providers/hns/hns_roce_u.h b/providers/hns/hns_roce_u.h
index 8c1cb1e..623be79 100644
--- a/providers/hns/hns_roce_u.h
+++ b/providers/hns/hns_roce_u.h
@@ -153,11 +153,17 @@
 #define HNS_ROCE_SRQ_TABLE_BITS 8
 #define HNS_ROCE_SRQ_TABLE_SIZE BIT(HNS_ROCE_SRQ_TABLE_BITS)
 
+enum {
+	HNAE3_MAC_ETH,
+	HNAE3_MAC_ROH,
+};
+
 struct hns_roce_device {
 	struct verbs_device		ibv_dev;
 	int				page_size;
 	const struct hns_roce_u_hw	*u_hw;
 	int				hw_version;
+	uint8_t				mac_type;
 };
 
 struct hns_roce_buf {
diff --git a/providers/hns/hns_roce_u_hw_v2.c b/providers/hns/hns_roce_u_hw_v2.c
index c652eea..b0c3109 100644
--- a/providers/hns/hns_roce_u_hw_v2.c
+++ b/providers/hns/hns_roce_u_hw_v2.c
@@ -1068,6 +1068,7 @@ static inline void enable_wqe(struct hns_roce_qp *qp, void *sq_wqe,
 static int set_ud_wqe(void *wqe, struct hns_roce_qp *qp, struct ibv_send_wr *wr,
 		      unsigned int nreq, struct hns_roce_sge_info *sge_info)
 {
+	struct hns_roce_device *hr_dev = to_hr_dev(qp->verbs_qp.qp.context->device);
 	struct hns_roce_ah *ah = to_hr_ah(wr->wr.ud.ah);
 	struct hns_roce_ud_sq_wqe *ud_sq_wqe = wqe;
 	int ret = 0;
@@ -1092,6 +1093,9 @@ static int set_ud_wqe(void *wqe, struct hns_roce_qp *qp, struct ibv_send_wr *wr,
 	if (ret)
 		return ret;
 
+	if (hr_dev->mac_type == HNAE3_MAC_ROH)
+		ud_sq_wqe->dmac[0] = 0xFF;
+
 	ret = fill_ud_data_seg(ud_sq_wqe, qp, wr, sge_info);
 	if (ret)
 		return ret;
-- 
2.30.0

