|
4 | 4 | #include "fs_core.h" |
5 | 5 | #include "lib/ipsec_fs_roce.h" |
6 | 6 | #include "mlx5_core.h" |
| 7 | +#include <linux/random.h> |
7 | 8 |
|
8 | 9 | struct mlx5_ipsec_miss { |
9 | 10 | struct mlx5_flow_group *group; |
@@ -44,6 +45,71 @@ static void ipsec_fs_roce_setup_udp_dport(struct mlx5_flow_spec *spec, |
44 | 45 | MLX5_SET(fte_match_param, spec->match_value, outer_headers.udp_dport, dport); |
45 | 46 | } |
46 | 47 |
|
| 48 | +static bool ipsec_fs_create_alias_supported(struct mlx5_core_dev *mdev, |
| 49 | + struct mlx5_core_dev *master_mdev) |
| 50 | +{ |
| 51 | + u64 obj_allowed_m = MLX5_CAP_GEN_2_64(master_mdev, allowed_object_for_other_vhca_access); |
| 52 | + u32 obj_supp_m = MLX5_CAP_GEN_2(master_mdev, cross_vhca_object_to_object_supported); |
| 53 | + u64 obj_allowed = MLX5_CAP_GEN_2_64(mdev, allowed_object_for_other_vhca_access); |
| 54 | + u32 obj_supp = MLX5_CAP_GEN_2(mdev, cross_vhca_object_to_object_supported); |
| 55 | + |
| 56 | + if (!(obj_supp & |
| 57 | + MLX5_CROSS_VHCA_OBJ_TO_OBJ_SUPPORTED_LOCAL_FLOW_TABLE_TO_REMOTE_FLOW_TABLE_MISS) || |
| 58 | + !(obj_supp_m & |
| 59 | + MLX5_CROSS_VHCA_OBJ_TO_OBJ_SUPPORTED_LOCAL_FLOW_TABLE_TO_REMOTE_FLOW_TABLE_MISS)) |
| 60 | + return false; |
| 61 | + |
| 62 | + if (!(obj_allowed & MLX5_ALLOWED_OBJ_FOR_OTHER_VHCA_ACCESS_FLOW_TABLE) || |
| 63 | + !(obj_allowed_m & MLX5_ALLOWED_OBJ_FOR_OTHER_VHCA_ACCESS_FLOW_TABLE)) |
| 64 | + return false; |
| 65 | + |
| 66 | + return true; |
| 67 | +} |
| 68 | + |
| 69 | +static int ipsec_fs_create_aliased_ft(struct mlx5_core_dev *ibv_owner, |
| 70 | + struct mlx5_core_dev *ibv_allowed, |
| 71 | + struct mlx5_flow_table *ft, |
| 72 | + u32 *obj_id) |
| 73 | +{ |
| 74 | + u32 aliased_object_id = (ft->type << FT_ID_FT_TYPE_OFFSET) | ft->id; |
| 75 | + u16 vhca_id_to_be_accessed = MLX5_CAP_GEN(ibv_owner, vhca_id); |
| 76 | + struct mlx5_cmd_allow_other_vhca_access_attr allow_attr = {}; |
| 77 | + struct mlx5_cmd_alias_obj_create_attr alias_attr = {}; |
| 78 | + char key[ACCESS_KEY_LEN]; |
| 79 | + int ret; |
| 80 | + int i; |
| 81 | + |
| 82 | + if (!ipsec_fs_create_alias_supported(ibv_owner, ibv_allowed)) |
| 83 | + return -EOPNOTSUPP; |
| 84 | + |
| 85 | + for (i = 0; i < ACCESS_KEY_LEN; i++) |
| 86 | + key[i] = get_random_u64() & 0xFF; |
| 87 | + |
| 88 | + memcpy(allow_attr.access_key, key, ACCESS_KEY_LEN); |
| 89 | + allow_attr.obj_type = MLX5_GENERAL_OBJECT_TYPES_FLOW_TABLE_ALIAS; |
| 90 | + allow_attr.obj_id = aliased_object_id; |
| 91 | + |
| 92 | + ret = mlx5_cmd_allow_other_vhca_access(ibv_owner, &allow_attr); |
| 93 | + if (ret) { |
| 94 | + mlx5_core_err(ibv_owner, "Failed to allow other vhca access err=%d\n", |
| 95 | + ret); |
| 96 | + return ret; |
| 97 | + } |
| 98 | + |
| 99 | + memcpy(alias_attr.access_key, key, ACCESS_KEY_LEN); |
| 100 | + alias_attr.obj_id = aliased_object_id; |
| 101 | + alias_attr.obj_type = MLX5_GENERAL_OBJECT_TYPES_FLOW_TABLE_ALIAS; |
| 102 | + alias_attr.vhca_id = vhca_id_to_be_accessed; |
| 103 | + ret = mlx5_cmd_alias_obj_create(ibv_allowed, &alias_attr, obj_id); |
| 104 | + if (ret) { |
| 105 | + mlx5_core_err(ibv_allowed, "Failed to create alias object err=%d\n", |
| 106 | + ret); |
| 107 | + return ret; |
| 108 | + } |
| 109 | + |
| 110 | + return 0; |
| 111 | +} |
| 112 | + |
47 | 113 | static int |
48 | 114 | ipsec_fs_roce_rx_rule_setup(struct mlx5_core_dev *mdev, |
49 | 115 | struct mlx5_flow_destination *default_dst, |
|
0 commit comments