Skip to content

Commit d5665a2

Browse files
Mark Zhangjgunthorpe
authored andcommitted
RDMA/core: Add hash functions to calculate RoCEv2 flowlabel and UDP source port
Add two hash functions to distribute RoCE v2 UDP source and Flowlabel symmetrically. These are user visible API and any change in the implementation needs to be tested for inter-operability between old and new variant. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Zhang <[email protected]> Reviewed-by: Maor Gottlieb <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 11a0ae4 commit d5665a2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

include/rdma/ib_verbs.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4709,4 +4709,48 @@ static inline struct ib_device *rdma_device_to_ibdev(struct device *device)
47094709

47104710
bool rdma_dev_access_netns(const struct ib_device *device,
47114711
const struct net *net);
4712+
4713+
#define IB_ROCE_UDP_ENCAP_VALID_PORT_MIN (0xC000)
4714+
#define IB_GRH_FLOWLABEL_MASK (0x000FFFFF)
4715+
4716+
/**
4717+
* rdma_flow_label_to_udp_sport - generate a RoCE v2 UDP src port value based
4718+
* on the flow_label
4719+
*
4720+
* This function will convert the 20 bit flow_label input to a valid RoCE v2
4721+
* UDP src port 14 bit value. All RoCE V2 drivers should use this same
4722+
* convention.
4723+
*/
4724+
static inline u16 rdma_flow_label_to_udp_sport(u32 fl)
4725+
{
4726+
u32 fl_low = fl & 0x03fff, fl_high = fl & 0xFC000;
4727+
4728+
fl_low ^= fl_high >> 14;
4729+
return (u16)(fl_low | IB_ROCE_UDP_ENCAP_VALID_PORT_MIN);
4730+
}
4731+
4732+
/**
4733+
* rdma_calc_flow_label - generate a RDMA symmetric flow label value based on
4734+
* local and remote qpn values
4735+
*
4736+
* This function folded the multiplication results of two qpns, 24 bit each,
4737+
* fields, and converts it to a 20 bit results.
4738+
*
4739+
* This function will create symmetric flow_label value based on the local
4740+
* and remote qpn values. this will allow both the requester and responder
4741+
* to calculate the same flow_label for a given connection.
4742+
*
4743+
* This helper function should be used by driver in case the upper layer
4744+
* provide a zero flow_label value. This is to improve entropy of RDMA
4745+
* traffic in the network.
4746+
*/
4747+
static inline u32 rdma_calc_flow_label(u32 lqpn, u32 rqpn)
4748+
{
4749+
u64 v = (u64)lqpn * rqpn;
4750+
4751+
v ^= v >> 20;
4752+
v ^= v >> 40;
4753+
4754+
return (u32)(v & IB_GRH_FLOWLABEL_MASK);
4755+
}
47124756
#endif /* IB_VERBS_H */

0 commit comments

Comments
 (0)