All callers build xfrm attributes with help of mlx5e_ipsec_build_accel_xfrm_attrs() function that ensure validity of attributes. There is no need to recheck them again.
Unified · Split
| @@ -62,55 +62,11 @@ u32 mlx5_ipsec_device_caps(struct mlx5_core_dev *mdev) · 61 unmodified lines | |||
| 62 | } | 62 | } |
| 63 | EXPORT_SYMBOL_GPL(mlx5_ipsec_device_caps); | 63 | EXPORT_SYMBOL_GPL(mlx5_ipsec_device_caps); |
| 64 | 64 | ||
| 65 | static int | ||
| 66 | mlx5_ipsec_offload_esp_validate_xfrm_attrs(struct mlx5_core_dev *mdev, | ||
| 67 | const struct mlx5_accel_esp_xfrm_attrs *attrs) | ||
| 68 | { | ||
| 69 | if (attrs->replay_type != MLX5_ACCEL_ESP_REPLAY_NONE) { | ||
| 70 | mlx5_core_err(mdev, "Cannot offload xfrm states with anti replay (replay_type = %d)\n", | ||
| 71 | attrs->replay_type); | ||
| 72 | return -EOPNOTSUPP; | ||
| 73 | } | ||
| 74 | |||
| 75 | if (attrs->keymat_type != MLX5_ACCEL_ESP_KEYMAT_AES_GCM) { | ||
| 76 | mlx5_core_err(mdev, "Only aes gcm keymat is supported (keymat_type = %d)\n", | ||
| 77 | attrs->keymat_type); | ||
| 78 | return -EOPNOTSUPP; | ||
| 79 | } | ||
| 80 | |||
| 81 | if (attrs->keymat.aes_gcm.iv_algo != | ||
| 82 | MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ) { | ||
| 83 | mlx5_core_err(mdev, "Only iv sequence algo is supported (iv_algo = %d)\n", | ||
| 84 | attrs->keymat.aes_gcm.iv_algo); | ||
| 85 | return -EOPNOTSUPP; | ||
| 86 | } | ||
| 87 | |||
| 88 | if (attrs->keymat.aes_gcm.key_len != 128 && | ||
| 89 | attrs->keymat.aes_gcm.key_len != 256) { | ||
| 90 | mlx5_core_err(mdev, "Cannot offload xfrm states with key length other than 128/256 bit (key length = %d)\n", | ||
| 91 | attrs->keymat.aes_gcm.key_len); | ||
| 92 | return -EOPNOTSUPP; | ||
| 93 | } | ||
| 94 | |||
| 95 | if ((attrs->flags & MLX5_ACCEL_ESP_FLAGS_ESN_TRIGGERED) && | ||
| 96 | !MLX5_CAP_IPSEC(mdev, ipsec_esn)) { | ||
| 97 | mlx5_core_err(mdev, "Cannot offload xfrm states with ESN triggered\n"); | ||
| 98 | return -EOPNOTSUPP; | ||
| 99 | } | ||
| 100 | |||
| 101 | return 0; | ||
| 102 | } | ||
| 103 | |||
| 104 | static struct mlx5_accel_esp_xfrm * | 65 | static struct mlx5_accel_esp_xfrm * |
| 105 | mlx5_ipsec_offload_esp_create_xfrm(struct mlx5_core_dev *mdev, | 66 | mlx5_ipsec_offload_esp_create_xfrm(struct mlx5_core_dev *mdev, |
| 106 | const struct mlx5_accel_esp_xfrm_attrs *attrs) | 67 | const struct mlx5_accel_esp_xfrm_attrs *attrs) |
| 107 | { | 68 | { |
| 108 | struct mlx5_ipsec_esp_xfrm *mxfrm; | 69 | struct mlx5_ipsec_esp_xfrm *mxfrm; |
| 109 | int err = 0; | ||
| 110 | |||
| 111 | err = mlx5_ipsec_offload_esp_validate_xfrm_attrs(mdev, attrs); | ||
| 112 | if (err) | ||
| 113 | return ERR_PTR(err); | ||
| 114 | 70 | ||
| 115 | mxfrm = kzalloc(sizeof(*mxfrm), GFP_KERNEL); | 71 | mxfrm = kzalloc(sizeof(*mxfrm), GFP_KERNEL); |
| 116 | if (!mxfrm) | 72 | if (!mxfrm) |
| @@ -36,10 +36,6 @@ · 35 unmodified lines | |||
| 36 | 36 | ||
| 37 | #include <linux/mlx5/driver.h> | 37 | #include <linux/mlx5/driver.h> |
| 38 | 38 | ||
| 39 | enum mlx5_accel_esp_aes_gcm_keymat_iv_algo { | ||
| 40 | MLX5_ACCEL_ESP_AES_GCM_IV_ALGO_SEQ, | ||
| 41 | }; | ||
| 42 | |||
| 43 | enum mlx5_accel_esp_flags { | 39 | enum mlx5_accel_esp_flags { |
| 44 | MLX5_ACCEL_ESP_FLAGS_TUNNEL = 0, /* Default */ | 40 | MLX5_ACCEL_ESP_FLAGS_TUNNEL = 0, /* Default */ |
| 45 | MLX5_ACCEL_ESP_FLAGS_TRANSPORT = 1UL << 0, | 41 | MLX5_ACCEL_ESP_FLAGS_TRANSPORT = 1UL << 0, |
| @@ -57,14 +53,9 @@ enum mlx5_accel_esp_keymats { · 11 unmodified lines | |||
| 57 | MLX5_ACCEL_ESP_KEYMAT_AES_GCM, | 53 | MLX5_ACCEL_ESP_KEYMAT_AES_GCM, |
| 58 | }; | 54 | }; |
| 59 | 55 | ||
| 60 | enum mlx5_accel_esp_replay { | ||
| 61 | MLX5_ACCEL_ESP_REPLAY_NONE, | ||
| 62 | MLX5_ACCEL_ESP_REPLAY_BMP, | ||
| 63 | }; | ||
| 64 | 56 | ||
| 65 | struct aes_gcm_keymat { | 57 | struct aes_gcm_keymat { |
| 66 | u64 seq_iv; | 58 | u64 seq_iv; |
| 67 | enum mlx5_accel_esp_aes_gcm_keymat_iv_algo iv_algo; | ||
| 68 | 59 | ||
| 69 | u32 salt; | 60 | u32 salt; |
| 70 | u32 icv_len; | 61 | u32 icv_len; |
| @@ -81,7 +72,6 @@ struct mlx5_accel_esp_xfrm_attrs { · 10 unmodified lines | |||
| 81 | u32 tfc_pad; | 72 | u32 tfc_pad; |
| 82 | u32 flags; | 73 | u32 flags; |
| 83 | u32 sa_handle; | 74 | u32 sa_handle; |
| 84 | enum mlx5_accel_esp_replay replay_type; | ||
| 85 | union { | 75 | union { |
| 86 | struct { | 76 | struct { |
| 87 | u32 size; | 77 | u32 size; |