Skip to content

Commit 5ac55df

Browse files
Mark Zhangjgunthorpe
authored andcommitted
RDMA/mlx5: Set UDP source port based on the grh.flow_label
Calculate UDP source port based on the grh.flow_label. If grh.flow_label is not valid, we will use minimal supported UDP source port. 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 f665340 commit 5ac55df

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

drivers/infiniband/hw/mlx5/ah.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,24 @@
3232

3333
#include "mlx5_ib.h"
3434

35+
static __be16 mlx5_ah_get_udp_sport(const struct mlx5_ib_dev *dev,
36+
const struct rdma_ah_attr *ah_attr)
37+
{
38+
enum ib_gid_type gid_type = ah_attr->grh.sgid_attr->gid_type;
39+
__be16 sport;
40+
41+
if ((gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) &&
42+
(rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) &&
43+
(ah_attr->grh.flow_label & IB_GRH_FLOWLABEL_MASK))
44+
sport = cpu_to_be16(
45+
rdma_flow_label_to_udp_sport(ah_attr->grh.flow_label));
46+
else
47+
sport = mlx5_get_roce_udp_sport_min(dev,
48+
ah_attr->grh.sgid_attr);
49+
50+
return sport;
51+
}
52+
3553
static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
3654
struct rdma_ah_init_attr *init_attr)
3755
{
@@ -60,8 +78,7 @@ static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
6078

6179
memcpy(ah->av.rmac, ah_attr->roce.dmac,
6280
sizeof(ah_attr->roce.dmac));
63-
ah->av.udp_sport =
64-
mlx5_get_roce_udp_sport(dev, ah_attr->grh.sgid_attr);
81+
ah->av.udp_sport = mlx5_ah_get_udp_sport(dev, ah_attr);
6582
ah->av.stat_rate_sl |= (rdma_ah_get_sl(ah_attr) & 0x7) << 1;
6683
if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP)
6784
#define MLX5_ECN_ENABLED BIT(1)

drivers/infiniband/hw/mlx5/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ static int mlx5_ib_del_gid(const struct ib_gid_attr *attr,
629629
attr->index, NULL, NULL);
630630
}
631631

632-
__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev,
633-
const struct ib_gid_attr *attr)
632+
__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev,
633+
const struct ib_gid_attr *attr)
634634
{
635635
if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP)
636636
return 0;

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,8 @@ int mlx5_ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
13561356
int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
13571357
u64 guid, int type);
13581358

1359-
__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev,
1360-
const struct ib_gid_attr *attr);
1359+
__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev,
1360+
const struct ib_gid_attr *attr);
13611361

13621362
void mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
13631363
void mlx5_ib_init_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);

0 commit comments

Comments
 (0)