Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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/20200504051935.269708-2-leon@kernel.org
Signed-off-by: Mark Zhang <markz@mellanox.com>
Reviewed-by: Maor Gottlieb <maorg@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>

authored by

Mark Zhang and committed by
Jason Gunthorpe
d5665a21 11a0ae4c

+44
+44
include/rdma/ib_verbs.h
··· 4709 4709 4710 4710 bool rdma_dev_access_netns(const struct ib_device *device, 4711 4711 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 + } 4712 4756 #endif /* IB_VERBS_H */