Skip to content

Commit 074bf2c

Browse files
Weihang Lijgunthorpe
authored andcommitted
RDMA/hns: Get udp sport num dynamically instead of using a fixed value
The UDP source port number in RoCE v2 is used to create entropy for network routers (ECMP), load balancers and 802.3ad link aggregation switching that are not aware of RoCE IB headers. Considering that the IB core has achieved a new interface to get a hashed value of it, the fixed value of it in QPC and UD WQE in hns driver could be fixed and the port number is to be set dynamically now. For QPC of RC, the value could be hashed from flow_lable if the user pass it in or from remote qpn and local qpn. For WQE of UD, it is set according to fl or as a random value. Link: https://lore.kernel.org/r/1598002289-8611-1-git-send-email-liweihang@huawei.com Signed-off-by: Weihang Li <liweihang@huawei.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 5f9e282 commit 074bf2c

4 files changed

Lines changed: 42 additions & 13 deletions

File tree

‎drivers/infiniband/hw/hns/hns_roce_ah.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
#define HNS_ROCE_VLAN_SL_BIT_MASK 7
4040
#define HNS_ROCE_VLAN_SL_SHIFT 13
4141

42+
static inline u16 get_ah_udp_sport(const struct rdma_ah_attr *ah_attr)
43+
{
44+
u32 fl = ah_attr->grh.flow_label;
45+
u16 sport;
46+
47+
if (!fl)
48+
sport = get_random_u32() %
49+
(IB_ROCE_UDP_ENCAP_VALID_PORT_MAX + 1 -
50+
IB_ROCE_UDP_ENCAP_VALID_PORT_MIN) +
51+
IB_ROCE_UDP_ENCAP_VALID_PORT_MIN;
52+
else
53+
sport = rdma_flow_label_to_udp_sport(fl);
54+
55+
return sport;
56+
}
57+
4258
int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
4359
struct ib_udata *udata)
4460
{
@@ -79,6 +95,8 @@ int hns_roce_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr,
7995

8096
memcpy(ah->av.dgid, grh->dgid.raw, HNS_ROCE_GID_SIZE);
8197
ah->av.sl = rdma_ah_get_sl(ah_attr);
98+
ah->av.flowlabel = grh->flow_label;
99+
ah->av.udp_sport = get_ah_udp_sport(ah_attr);
82100

83101
return 0;
84102
}

‎drivers/infiniband/hw/hns/hns_roce_device.h‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,18 @@ struct hns_roce_raq_table {
537537
};
538538

539539
struct hns_roce_av {
540-
u8 port;
541-
u8 gid_index;
542-
u8 stat_rate;
543-
u8 hop_limit;
544-
u32 flowlabel;
545-
u8 sl;
546-
u8 tclass;
547-
u8 dgid[HNS_ROCE_GID_SIZE];
548-
u8 mac[ETH_ALEN];
549-
u16 vlan_id;
550-
bool vlan_en;
540+
u8 port;
541+
u8 gid_index;
542+
u8 stat_rate;
543+
u8 hop_limit;
544+
u32 flowlabel;
545+
u16 udp_sport;
546+
u8 sl;
547+
u8 tclass;
548+
u8 dgid[HNS_ROCE_GID_SIZE];
549+
u8 mac[ETH_ALEN];
550+
u16 vlan_id;
551+
bool vlan_en;
551552
};
552553

553554
struct hns_roce_ah {

‎drivers/infiniband/hw/hns/hns_roce_hw_v2.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static inline int set_ud_wqe(struct hns_roce_qp *qp,
369369
curr_idx & (qp->sge.sge_cnt - 1));
370370

371371
roce_set_field(ud_sq_wqe->byte_24, V2_UD_SEND_WQE_BYTE_24_UDPSPN_M,
372-
V2_UD_SEND_WQE_BYTE_24_UDPSPN_S, 0);
372+
V2_UD_SEND_WQE_BYTE_24_UDPSPN_S, ah->av.udp_sport);
373373
ud_sq_wqe->qkey = cpu_to_le32(ud_wr(wr)->remote_qkey & 0x80000000 ?
374374
qp->qkey : ud_wr(wr)->remote_qkey);
375375
roce_set_field(ud_sq_wqe->byte_32, V2_UD_SEND_WQE_BYTE_32_DQPN_M,
@@ -4165,6 +4165,14 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
41654165
return 0;
41664166
}
41674167

4168+
static inline u16 get_udp_sport(u32 fl, u32 lqpn, u32 rqpn)
4169+
{
4170+
if (!fl)
4171+
fl = rdma_calc_flow_label(lqpn, rqpn);
4172+
4173+
return rdma_flow_label_to_udp_sport(fl);
4174+
}
4175+
41684176
static int hns_roce_v2_set_path(struct ib_qp *ibqp,
41694177
const struct ib_qp_attr *attr,
41704178
int attr_mask,
@@ -4228,7 +4236,8 @@ static int hns_roce_v2_set_path(struct ib_qp *ibqp,
42284236

42294237
roce_set_field(context->byte_52_udpspn_dmac, V2_QPC_BYTE_52_UDPSPN_M,
42304238
V2_QPC_BYTE_52_UDPSPN_S,
4231-
is_udp ? 0x12b7 : 0);
4239+
is_udp ? get_udp_sport(grh->flow_label, ibqp->qp_num,
4240+
attr->dest_qp_num) : 0);
42324241

42334242
roce_set_field(qpc_mask->byte_52_udpspn_dmac, V2_QPC_BYTE_52_UDPSPN_M,
42344243
V2_QPC_BYTE_52_UDPSPN_S, 0);

‎include/rdma/ib_verbs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,6 +4706,7 @@ bool rdma_dev_access_netns(const struct ib_device *device,
47064706
const struct net *net);
47074707

47084708
#define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
4709+
#define IB_ROCE_UDP_ENCAP_VALID_PORT_MAX (0xFFFF)
47094710
#define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
47104711

47114712
/**

0 commit comments

Comments
 (0)