Skip to contentSkip to conversation

Generate UDP src port with flow label or lqpn/rqpn

PATCH Applied [email protected] 3 participants 7 messages Jan 6, 2022 – Jan 7, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover Generate UDP src port with flow label or lqpn/rqpn

From: Zhu Yanjun <[email protected]>

Follow the advice from Leon Romanovsky, rdma_get_udp_sport is moved to ib_verbs.h. several drivers generate udp source port with this function.

---
v2->v3:Because in-subnet communications, GRH is optional. Without thei
randomization for src_port done in rxe_qp_init_req, udp source port will be 0xC000 in that case.
v1->v2:Remove the local variables in commits "RDMA/irdma: Make the source
udp port vary" and "RDMA/rxe: Use the standard method to produce udp source port". A new commit is added to remove the redundant randomization for UDP source port in RXE.
---

Zhu Yanjun (4):
RDMA/core: Calculate UDP source port based on flow label or lqpn/rqpn RDMA/hns: Replace get_udp_sport with rdma_get_udp_sport RDMA/irdma: Make the source udp port vary
RDMA/rxe: Use the standard method to produce udp source port

 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 12 ++----------
 drivers/infiniband/hw/irdma/verbs.c        |  4 ++++
 drivers/infiniband/sw/rxe/rxe_verbs.c      |  6 ++++++
 include/rdma/ib_verbs.h                    | 17 +++++++++++++++++
 4 files changed, 29 insertions(+), 10 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v3 1/4 RDMA/core: Calculate UDP source port based on flow label or lqpn/rqpn

From: Zhu Yanjun <[email protected]>

Calculate and set UDP source port based on the flow label. If flow label is not defined in GRH then calculate it based on lqpn/rqpn.

---
 include/rdma/ib_verbs.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/rdma/ib_verbs.h +17 -0
index 6e9ad656ecb7..69d883f7fb41 100644
@@ -4749,6 +4749,23 @@ static inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
 	return (u32)(v & IB_GRH_FLOWLABEL_MASK);
 }
 
+/**
+ * rdma_get_udp_sport - Calculate and set UDP source port based on the flow
+ *                      label. If flow label is not defined in GRH then
+ *                      calculate it based on lqpn/rqpn.
+ *
+ * @fl:                 flow label from GRH
+ * @lqpn:               local qp number
+ * @rqpn:               remote qp number
+ */
+static inline u16 rdma_get_udp_sport(u32 fl, u32 lqpn, u32 rqpn)
+{
+	if (!fl)
+		fl = rdma_calc_flow_label(lqpn, rqpn);
+
+	return rdma_flow_label_to_udp_sport(fl);
+}
+
 const struct ib_port_immutable*
 ib_port_immutable_read(struct ib_device *dev, unsigned int port);
 #endif /* IB_VERBS_H */
Signature · 1 line
2.27.0
#2 lore raw

PATCH v3 2/4 RDMA/hns: Replace get_udp_sport with rdma_get_udp_sport

In reply to [email protected]

From: Zhu Yanjun <[email protected]>

Several drivers have the same function xxx_get_udp_sport. So this function is moved to ib_verbs.h.

---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/infiniband/hw/hns/hns_roce_hw_v2.c +2 -10
index eb0defa80d0d..cb795663b813 100644
@@ -4488,14 +4488,6 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
 	return 0;
 }
 
-static inline u16 get_udp_sport(u32 fl, u32 lqpn, u32 rqpn)
-{
-	if (!fl)
-		fl = rdma_calc_flow_label(lqpn, rqpn);
-
-	return rdma_flow_label_to_udp_sport(fl);
-}
-
 static int get_dip_ctx_idx(struct ib_qp *ibqp, const struct ib_qp_attr *attr,
 			   u32 *dip_idx)
 {
@@ -4712,8 +4704,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp,
 	}
 
 	hr_reg_write(context, QPC_UDPSPN,
-		     is_udp ? get_udp_sport(grh->flow_label, ibqp->qp_num,
-					    attr->dest_qp_num) : 0);
+		     is_udp ? rdma_get_udp_sport(grh->flow_label, ibqp->qp_num,
+						 attr->dest_qp_num) : 0);
 
 	hr_reg_clear(qpc_mask, QPC_UDPSPN);
 
Signature · 1 line
2.27.0
Acked-by on v3 2/4
#3 lore raw

Re: [PATCH v3 2/4] RDMA/hns: Replace get_udp_sport with rdma_get_udp_sport

Quoted 10 lines · On 2022/1/7 2:03, [email protected] wrote:

From: Zhu Yanjun <[email protected]>

Several drivers have the same function xxx_get_udp_sport. So this function is moved to ib_verbs.h.

---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

Thanks

#4 lore raw

PATCH v3 3/4 RDMA/irdma: Make the source udp port vary

In reply to [email protected]

From: Zhu Yanjun <[email protected]>

Get the source udp port number for a QP based on the grh.flow_label or lqpn/rqrpn. This provides a better spread of traffic across NIC RX queues.

---
 drivers/infiniband/hw/irdma/verbs.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/infiniband/hw/irdma/verbs.c +4 -0
index 8cd5f9261692..8234a101e752 100644
@@ -1170,6 +1170,10 @@ int irdma_modify_qp_roce(struct ib_qp *ibqp, struct ib_qp_attr *attr,
 			udp_info->ttl = attr->ah_attr.grh.hop_limit;
 			udp_info->flow_label = attr->ah_attr.grh.flow_label;
 			udp_info->tos = attr->ah_attr.grh.traffic_class;
+			udp_info->src_port = rdma_get_udp_sport(
+						udp_info->flow_label,
+						ibqp->qp_num,
+						roce_info->dest_qp);
 			irdma_qp_rem_qos(&iwqp->sc_qp);
 			dev->ws_remove(iwqp->sc_qp.vsi, ctx_info->user_pri);
 			ctx_info->user_pri = rt_tos2priority(udp_info->tos);
Signature · 1 line
2.27.0
#5 lore raw

PATCH v3 4/4 RDMA/rxe: Use the standard method to produce udp source port

In reply to [email protected]

From: Zhu Yanjun <[email protected]>

Use the standard method to produce udp source port.

---
 drivers/infiniband/sw/rxe/rxe_verbs.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/infiniband/sw/rxe/rxe_verbs.c +6 -0
index 0aa0d7e52773..42fa81b455de 100644
@@ -469,6 +469,12 @@ static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
 	if (err)
 		goto err1;
 
+	if ((mask & IB_QP_AV) && (attr->ah_attr.ah_flags & IB_AH_GRH))
+		qp->src_port = rdma_get_udp_sport(attr->ah_attr.grh.flow_label,
+						  qp->ibqp.qp_num,
+						  qp->attr.dest_qp_num);
+
+
 	return 0;
 
 err1:
Signature · 1 line
2.27.0
maintainer Applied
#6 lore raw
In reply to [email protected]
Quoted 17 lines · On Thu, Jan 06, 2022 at 01:03:55PM -0500, [email protected] wrote:

From: Zhu Yanjun <[email protected]>

Follow the advice from Leon Romanovsky, rdma_get_udp_sport is moved to ib_verbs.h. several drivers generate udp source port with this function.

---
v2->v3:Because in-subnet communications, GRH is optional. Without thei
randomization for src_port done in rxe_qp_init_req, udp source port will be 0xC000 in that case.
v1->v2:Remove the local variables in commits "RDMA/irdma: Make the source
udp port vary" and "RDMA/rxe: Use the standard method to produce udp source port". A new commit is added to remove the redundant randomization for UDP source port in RXE.
---

Quoted 5 lines

Zhu Yanjun (4):
RDMA/core: Calculate UDP source port based on flow label or lqpn/rqpn RDMA/hns: Replace get_udp_sport with rdma_get_udp_sport RDMA/irdma: Make the source udp port vary
RDMA/rxe: Use the standard method to produce udp source port

Applied to for-next, thanks

Jason