RDMA/mlx5: Set UDP source port based on the grh.flow_label
authorMark Zhang <markz@mellanox.com>
Mon, 4 May 2020 05:19:35 +0000 (08:19 +0300)
committerJason Gunthorpe <jgg@mellanox.com>
Wed, 6 May 2020 19:51:44 +0000 (16:51 -0300)
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/20200504051935.269708-6-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>
drivers/infiniband/hw/mlx5/ah.c
drivers/infiniband/hw/mlx5/main.c
drivers/infiniband/hw/mlx5/mlx5_ib.h

index cc858f658567c6cc6ea92fe8a0aef0222903bccd..59e5ec39b447b9e0c199b49d5f45b4cb19d9a5a4 100644 (file)
 
 #include "mlx5_ib.h"
 
+static __be16 mlx5_ah_get_udp_sport(const struct mlx5_ib_dev *dev,
+                                 const struct rdma_ah_attr *ah_attr)
+{
+       enum ib_gid_type gid_type = ah_attr->grh.sgid_attr->gid_type;
+       __be16 sport;
+
+       if ((gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) &&
+           (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) &&
+           (ah_attr->grh.flow_label & IB_GRH_FLOWLABEL_MASK))
+               sport = cpu_to_be16(
+                       rdma_flow_label_to_udp_sport(ah_attr->grh.flow_label));
+       else
+               sport = mlx5_get_roce_udp_sport_min(dev,
+                                                   ah_attr->grh.sgid_attr);
+
+       return sport;
+}
+
 static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
                         struct rdma_ah_init_attr *init_attr)
 {
@@ -60,8 +78,7 @@ static void create_ib_ah(struct mlx5_ib_dev *dev, struct mlx5_ib_ah *ah,
 
                memcpy(ah->av.rmac, ah_attr->roce.dmac,
                       sizeof(ah_attr->roce.dmac));
-               ah->av.udp_sport =
-                       mlx5_get_roce_udp_sport(dev, ah_attr->grh.sgid_attr);
+               ah->av.udp_sport = mlx5_ah_get_udp_sport(dev, ah_attr);
                ah->av.stat_rate_sl |= (rdma_ah_get_sl(ah_attr) & 0x7) << 1;
                if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP)
 #define MLX5_ECN_ENABLED BIT(1)
index e7fb290c9d8dc8a08a7220c1ab9e89b6495258d4..0b8cc219e085ab173f8437ad5aef79de6c5a8fd6 100644 (file)
@@ -629,8 +629,8 @@ static int mlx5_ib_del_gid(const struct ib_gid_attr *attr,
                             attr->index, NULL, NULL);
 }
 
-__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev,
-                              const struct ib_gid_attr *attr)
+__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev,
+                                  const struct ib_gid_attr *attr)
 {
        if (attr->gid_type != IB_GID_TYPE_ROCE_UDP_ENCAP)
                return 0;
index f250753319d0cc4fbaa2cd4c0a4223b6edf79930..3041808773e62c1caf3a69cd591ba7b18c614eb9 100644 (file)
@@ -1356,8 +1356,8 @@ int mlx5_ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
 int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
                        u64 guid, int type);
 
-__be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev,
-                              const struct ib_gid_attr *attr);
+__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev,
+                                  const struct ib_gid_attr *attr);
 
 void mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
 void mlx5_ib_init_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);