|
60 | 60 | #include "ib_rep.h" |
61 | 61 | #include "cmd.h" |
62 | 62 | #include <linux/mlx5/fs_helpers.h> |
| 63 | +#include <linux/mlx5/accel.h> |
63 | 64 | #include <rdma/uverbs_std_types.h> |
| 65 | +#include <rdma/mlx5_user_ioctl_verbs.h> |
| 66 | +#include <rdma/mlx5_user_ioctl_cmds.h> |
64 | 67 |
|
65 | 68 | #define UVERBS_MODULE_NAME mlx5_ib |
66 | 69 | #include <rdma/uverbs_named_ioctl.h> |
@@ -3103,6 +3106,122 @@ static struct ib_flow *mlx5_ib_create_flow(struct ib_qp *qp, |
3103 | 3106 | return ERR_PTR(err); |
3104 | 3107 | } |
3105 | 3108 |
|
| 3109 | +static u32 mlx5_ib_flow_action_flags_to_accel_xfrm_flags(u32 mlx5_flags) |
| 3110 | +{ |
| 3111 | + u32 flags = 0; |
| 3112 | + |
| 3113 | + if (mlx5_flags & MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA) |
| 3114 | + flags |= MLX5_ACCEL_XFRM_FLAG_REQUIRE_METADATA; |
| 3115 | + |
| 3116 | + return flags; |
| 3117 | +} |
| 3118 | + |
| 3119 | +#define MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA |
| 3120 | +static struct ib_flow_action * |
| 3121 | +mlx5_ib_create_flow_action_esp(struct ib_device *device, |
| 3122 | + const struct ib_flow_action_attrs_esp *attr, |
| 3123 | + struct uverbs_attr_bundle *attrs) |
| 3124 | +{ |
| 3125 | + struct mlx5_ib_dev *mdev = to_mdev(device); |
| 3126 | + struct ib_uverbs_flow_action_esp_keymat_aes_gcm *aes_gcm; |
| 3127 | + struct mlx5_accel_esp_xfrm_attrs accel_attrs = {}; |
| 3128 | + struct mlx5_ib_flow_action *action; |
| 3129 | + u64 action_flags; |
| 3130 | + u64 flags; |
| 3131 | + int err = 0; |
| 3132 | + |
| 3133 | + if (IS_UVERBS_COPY_ERR(uverbs_copy_from(&action_flags, attrs, |
| 3134 | + MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS))) |
| 3135 | + return ERR_PTR(-EFAULT); |
| 3136 | + |
| 3137 | + if (action_flags >= (MLX5_FLOW_ACTION_ESP_CREATE_LAST_SUPPORTED << 1)) |
| 3138 | + return ERR_PTR(-EOPNOTSUPP); |
| 3139 | + |
| 3140 | + flags = mlx5_ib_flow_action_flags_to_accel_xfrm_flags(action_flags); |
| 3141 | + |
| 3142 | + /* We current only support a subset of the standard features. Only a |
| 3143 | + * keymat of type AES_GCM, with icv_len == 16, iv_algo == SEQ and esn |
| 3144 | + * (with overlap). Full offload mode isn't supported. |
| 3145 | + */ |
| 3146 | + if (!attr->keymat || attr->replay || attr->encap || |
| 3147 | + attr->spi || attr->seq || attr->tfc_pad || |
| 3148 | + attr->hard_limit_pkts || |
| 3149 | + (attr->flags & ~(IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED | |
| 3150 | + IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT))) |
| 3151 | + return ERR_PTR(-EOPNOTSUPP); |
| 3152 | + |
| 3153 | + if (attr->keymat->protocol != |
| 3154 | + IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM) |
| 3155 | + return ERR_PTR(-EOPNOTSUPP); |
| 3156 | + |
| 3157 | + aes_gcm = &attr->keymat->keymat.aes_gcm; |
| 3158 | + |
| 3159 | + if (aes_gcm->icv_len != 16 || |
| 3160 | + aes_gcm->iv_algo != IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ) |
| 3161 | + return ERR_PTR(-EOPNOTSUPP); |
| 3162 | + |
| 3163 | + action = kmalloc(sizeof(*action), GFP_KERNEL); |
| 3164 | + if (!action) |
| 3165 | + return ERR_PTR(-ENOMEM); |
| 3166 | + |
| 3167 | + action->esp_aes_gcm.ib_flags = attr->flags; |
| 3168 | + memcpy(&accel_attrs.keymat.aes_gcm.aes_key, &aes_gcm->aes_key, |
| 3169 | + sizeof(accel_attrs.keymat.aes_gcm.aes_key)); |
| 3170 | + accel_attrs.keymat.aes_gcm.key_len = aes_gcm->key_len * 8; |
| 3171 | + memcpy(&accel_attrs.keymat.aes_gcm.salt, &aes_gcm->salt, |
| 3172 | + sizeof(accel_attrs.keymat.aes_gcm.salt)); |
| 3173 | + memcpy(&accel_attrs.keymat.aes_gcm.seq_iv, &aes_gcm->iv, |
| 3174 | + sizeof(accel_attrs.keymat.aes_gcm.seq_iv)); |
| 3175 | + accel_attrs.keymat.aes_gcm.icv_len = aes_gcm->icv_len * 8; |
| 3176 | + accel_attrs.keymat.aes_gcm.iv_algo = MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ; |
| 3177 | + accel_attrs.keymat_type = MLX5_ACCEL_ESP_KEYMAT_AES_GCM; |
| 3178 | + |
| 3179 | + accel_attrs.esn = attr->esn; |
| 3180 | + if (attr->flags & IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED) |
| 3181 | + accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED; |
| 3182 | + if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW) |
| 3183 | + accel_attrs.flags |= MLX5_ACCEL_ESP_FLAGS_ESN_STATE_OVERLAP; |
| 3184 | + |
| 3185 | + if (attr->flags & IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT) |
| 3186 | + accel_attrs.action |= MLX5_ACCEL_ESP_ACTION_ENCRYPT; |
| 3187 | + |
| 3188 | + action->esp_aes_gcm.ctx = |
| 3189 | + mlx5_accel_esp_create_xfrm(mdev->mdev, &accel_attrs, flags); |
| 3190 | + if (IS_ERR(action->esp_aes_gcm.ctx)) { |
| 3191 | + err = PTR_ERR(action->esp_aes_gcm.ctx); |
| 3192 | + goto err_parse; |
| 3193 | + } |
| 3194 | + |
| 3195 | + action->esp_aes_gcm.ib_flags = attr->flags; |
| 3196 | + |
| 3197 | + return &action->ib_action; |
| 3198 | + |
| 3199 | +err_parse: |
| 3200 | + kfree(action); |
| 3201 | + return ERR_PTR(err); |
| 3202 | +} |
| 3203 | + |
| 3204 | +static int mlx5_ib_destroy_flow_action(struct ib_flow_action *action) |
| 3205 | +{ |
| 3206 | + struct mlx5_ib_flow_action *maction = to_mflow_act(action); |
| 3207 | + |
| 3208 | + switch (action->type) { |
| 3209 | + case IB_FLOW_ACTION_ESP: |
| 3210 | + /* |
| 3211 | + * We only support aes_gcm by now, so we implicitly know this is |
| 3212 | + * the underline crypto. |
| 3213 | + */ |
| 3214 | + mlx5_accel_esp_destroy_xfrm(maction->esp_aes_gcm.ctx); |
| 3215 | + break; |
| 3216 | + default: |
| 3217 | + WARN_ON(true); |
| 3218 | + break; |
| 3219 | + } |
| 3220 | + |
| 3221 | + kfree(maction); |
| 3222 | + return 0; |
| 3223 | +} |
| 3224 | + |
3106 | 3225 | static int mlx5_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
3107 | 3226 | { |
3108 | 3227 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
@@ -4548,13 +4667,23 @@ static void mlx5_ib_cleanup_multiport_master(struct mlx5_ib_dev *dev) |
4548 | 4667 | mlx5_nic_vport_disable_roce(dev->mdev); |
4549 | 4668 | } |
4550 | 4669 |
|
4551 | | -#define NUM_TREES 0 |
| 4670 | +ADD_UVERBS_ATTRIBUTES_SIMPLE(mlx5_ib_flow_action, UVERBS_OBJECT_FLOW_ACTION, |
| 4671 | + UVERBS_METHOD_FLOW_ACTION_ESP_CREATE, |
| 4672 | + &UVERBS_ATTR_PTR_IN(MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS, |
| 4673 | + UVERBS_ATTR_TYPE(u64), |
| 4674 | + UA_FLAGS(UVERBS_ATTR_SPEC_F_MANDATORY))); |
| 4675 | + |
| 4676 | +#define NUM_TREES 1 |
4552 | 4677 | static int populate_specs_root(struct mlx5_ib_dev *dev) |
4553 | 4678 | { |
4554 | 4679 | const struct uverbs_object_tree_def *default_root[NUM_TREES + 1] = { |
4555 | 4680 | uverbs_default_get_objects()}; |
4556 | 4681 | size_t num_trees = 1; |
4557 | 4682 |
|
| 4683 | + if (mlx5_accel_ipsec_device_caps(dev->mdev) & MLX5_ACCEL_IPSEC_CAP_DEVICE && |
| 4684 | + !WARN_ON(num_trees >= ARRAY_SIZE(default_root))) |
| 4685 | + default_root[num_trees++] = &mlx5_ib_flow_action; |
| 4686 | + |
4558 | 4687 | dev->ib_dev.specs_root = |
4559 | 4688 | uverbs_alloc_spec_tree(num_trees, default_root); |
4560 | 4689 |
|
@@ -4796,6 +4925,8 @@ int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev) |
4796 | 4925 | dev->ib_dev.uverbs_ex_cmd_mask |= |
4797 | 4926 | (1ull << IB_USER_VERBS_EX_CMD_CREATE_FLOW) | |
4798 | 4927 | (1ull << IB_USER_VERBS_EX_CMD_DESTROY_FLOW); |
| 4928 | + dev->ib_dev.create_flow_action_esp = mlx5_ib_create_flow_action_esp; |
| 4929 | + dev->ib_dev.destroy_flow_action = mlx5_ib_destroy_flow_action; |
4799 | 4930 | dev->ib_dev.driver_id = RDMA_DRIVER_MLX5; |
4800 | 4931 |
|
4801 | 4932 | err = init_node_data(dev); |
|
0 commit comments