| .. | .. |
|---|
| 36 | 36 | #include "accel/ipsec.h" |
|---|
| 37 | 37 | #include "mlx5_core.h" |
|---|
| 38 | 38 | #include "fpga/ipsec.h" |
|---|
| 39 | +#include "accel/ipsec_offload.h" |
|---|
| 40 | + |
|---|
| 41 | +void mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev) |
|---|
| 42 | +{ |
|---|
| 43 | + const struct mlx5_accel_ipsec_ops *ipsec_ops; |
|---|
| 44 | + int err = 0; |
|---|
| 45 | + |
|---|
| 46 | + ipsec_ops = (mlx5_ipsec_offload_ops(mdev)) ? |
|---|
| 47 | + mlx5_ipsec_offload_ops(mdev) : |
|---|
| 48 | + mlx5_fpga_ipsec_ops(mdev); |
|---|
| 49 | + |
|---|
| 50 | + if (!ipsec_ops || !ipsec_ops->init) { |
|---|
| 51 | + mlx5_core_dbg(mdev, "IPsec ops is not supported\n"); |
|---|
| 52 | + return; |
|---|
| 53 | + } |
|---|
| 54 | + |
|---|
| 55 | + err = ipsec_ops->init(mdev); |
|---|
| 56 | + if (err) { |
|---|
| 57 | + mlx5_core_warn_once(mdev, "Failed to start IPsec device, err = %d\n", err); |
|---|
| 58 | + return; |
|---|
| 59 | + } |
|---|
| 60 | + |
|---|
| 61 | + mdev->ipsec_ops = ipsec_ops; |
|---|
| 62 | +} |
|---|
| 63 | + |
|---|
| 64 | +void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev) |
|---|
| 65 | +{ |
|---|
| 66 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 67 | + |
|---|
| 68 | + if (!ipsec_ops || !ipsec_ops->cleanup) |
|---|
| 69 | + return; |
|---|
| 70 | + |
|---|
| 71 | + ipsec_ops->cleanup(mdev); |
|---|
| 72 | +} |
|---|
| 39 | 73 | |
|---|
| 40 | 74 | u32 mlx5_accel_ipsec_device_caps(struct mlx5_core_dev *mdev) |
|---|
| 41 | 75 | { |
|---|
| 42 | | - return mlx5_fpga_ipsec_device_caps(mdev); |
|---|
| 76 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 77 | + |
|---|
| 78 | + if (!ipsec_ops || !ipsec_ops->device_caps) |
|---|
| 79 | + return 0; |
|---|
| 80 | + |
|---|
| 81 | + return ipsec_ops->device_caps(mdev); |
|---|
| 43 | 82 | } |
|---|
| 44 | 83 | EXPORT_SYMBOL_GPL(mlx5_accel_ipsec_device_caps); |
|---|
| 45 | 84 | |
|---|
| 46 | 85 | unsigned int mlx5_accel_ipsec_counters_count(struct mlx5_core_dev *mdev) |
|---|
| 47 | 86 | { |
|---|
| 48 | | - return mlx5_fpga_ipsec_counters_count(mdev); |
|---|
| 87 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 88 | + |
|---|
| 89 | + if (!ipsec_ops || !ipsec_ops->counters_count) |
|---|
| 90 | + return -EOPNOTSUPP; |
|---|
| 91 | + |
|---|
| 92 | + return ipsec_ops->counters_count(mdev); |
|---|
| 49 | 93 | } |
|---|
| 50 | 94 | |
|---|
| 51 | 95 | int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters, |
|---|
| 52 | 96 | unsigned int count) |
|---|
| 53 | 97 | { |
|---|
| 54 | | - return mlx5_fpga_ipsec_counters_read(mdev, counters, count); |
|---|
| 98 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 99 | + |
|---|
| 100 | + if (!ipsec_ops || !ipsec_ops->counters_read) |
|---|
| 101 | + return -EOPNOTSUPP; |
|---|
| 102 | + |
|---|
| 103 | + return ipsec_ops->counters_read(mdev, counters, count); |
|---|
| 55 | 104 | } |
|---|
| 56 | 105 | |
|---|
| 57 | 106 | void *mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev, |
|---|
| 58 | 107 | struct mlx5_accel_esp_xfrm *xfrm, |
|---|
| 59 | | - const __be32 saddr[4], |
|---|
| 60 | | - const __be32 daddr[4], |
|---|
| 61 | | - const __be32 spi, bool is_ipv6) |
|---|
| 108 | + u32 *sa_handle) |
|---|
| 62 | 109 | { |
|---|
| 63 | | - return mlx5_fpga_ipsec_create_sa_ctx(mdev, xfrm, saddr, daddr, |
|---|
| 64 | | - spi, is_ipv6); |
|---|
| 110 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 111 | + __be32 saddr[4] = {}, daddr[4] = {}; |
|---|
| 112 | + |
|---|
| 113 | + if (!ipsec_ops || !ipsec_ops->create_hw_context) |
|---|
| 114 | + return ERR_PTR(-EOPNOTSUPP); |
|---|
| 115 | + |
|---|
| 116 | + if (!xfrm->attrs.is_ipv6) { |
|---|
| 117 | + saddr[3] = xfrm->attrs.saddr.a4; |
|---|
| 118 | + daddr[3] = xfrm->attrs.daddr.a4; |
|---|
| 119 | + } else { |
|---|
| 120 | + memcpy(saddr, xfrm->attrs.saddr.a6, sizeof(saddr)); |
|---|
| 121 | + memcpy(daddr, xfrm->attrs.daddr.a6, sizeof(daddr)); |
|---|
| 122 | + } |
|---|
| 123 | + |
|---|
| 124 | + return ipsec_ops->create_hw_context(mdev, xfrm, saddr, daddr, xfrm->attrs.spi, |
|---|
| 125 | + xfrm->attrs.is_ipv6, sa_handle); |
|---|
| 65 | 126 | } |
|---|
| 66 | 127 | |
|---|
| 67 | | -void mlx5_accel_esp_free_hw_context(void *context) |
|---|
| 128 | +void mlx5_accel_esp_free_hw_context(struct mlx5_core_dev *mdev, void *context) |
|---|
| 68 | 129 | { |
|---|
| 69 | | - mlx5_fpga_ipsec_delete_sa_ctx(context); |
|---|
| 70 | | -} |
|---|
| 130 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 71 | 131 | |
|---|
| 72 | | -int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev) |
|---|
| 73 | | -{ |
|---|
| 74 | | - return mlx5_fpga_ipsec_init(mdev); |
|---|
| 75 | | -} |
|---|
| 132 | + if (!ipsec_ops || !ipsec_ops->free_hw_context) |
|---|
| 133 | + return; |
|---|
| 76 | 134 | |
|---|
| 77 | | -void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev) |
|---|
| 78 | | -{ |
|---|
| 79 | | - mlx5_fpga_ipsec_cleanup(mdev); |
|---|
| 135 | + ipsec_ops->free_hw_context(context); |
|---|
| 80 | 136 | } |
|---|
| 81 | 137 | |
|---|
| 82 | 138 | struct mlx5_accel_esp_xfrm * |
|---|
| .. | .. |
|---|
| 84 | 140 | const struct mlx5_accel_esp_xfrm_attrs *attrs, |
|---|
| 85 | 141 | u32 flags) |
|---|
| 86 | 142 | { |
|---|
| 143 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = mdev->ipsec_ops; |
|---|
| 87 | 144 | struct mlx5_accel_esp_xfrm *xfrm; |
|---|
| 88 | 145 | |
|---|
| 89 | | - xfrm = mlx5_fpga_esp_create_xfrm(mdev, attrs, flags); |
|---|
| 146 | + if (!ipsec_ops || !ipsec_ops->esp_create_xfrm) |
|---|
| 147 | + return ERR_PTR(-EOPNOTSUPP); |
|---|
| 148 | + |
|---|
| 149 | + xfrm = ipsec_ops->esp_create_xfrm(mdev, attrs, flags); |
|---|
| 90 | 150 | if (IS_ERR(xfrm)) |
|---|
| 91 | 151 | return xfrm; |
|---|
| 92 | 152 | |
|---|
| .. | .. |
|---|
| 97 | 157 | |
|---|
| 98 | 158 | void mlx5_accel_esp_destroy_xfrm(struct mlx5_accel_esp_xfrm *xfrm) |
|---|
| 99 | 159 | { |
|---|
| 100 | | - mlx5_fpga_esp_destroy_xfrm(xfrm); |
|---|
| 160 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = xfrm->mdev->ipsec_ops; |
|---|
| 161 | + |
|---|
| 162 | + if (!ipsec_ops || !ipsec_ops->esp_destroy_xfrm) |
|---|
| 163 | + return; |
|---|
| 164 | + |
|---|
| 165 | + ipsec_ops->esp_destroy_xfrm(xfrm); |
|---|
| 101 | 166 | } |
|---|
| 102 | 167 | EXPORT_SYMBOL_GPL(mlx5_accel_esp_destroy_xfrm); |
|---|
| 103 | 168 | |
|---|
| 104 | 169 | int mlx5_accel_esp_modify_xfrm(struct mlx5_accel_esp_xfrm *xfrm, |
|---|
| 105 | 170 | const struct mlx5_accel_esp_xfrm_attrs *attrs) |
|---|
| 106 | 171 | { |
|---|
| 107 | | - return mlx5_fpga_esp_modify_xfrm(xfrm, attrs); |
|---|
| 172 | + const struct mlx5_accel_ipsec_ops *ipsec_ops = xfrm->mdev->ipsec_ops; |
|---|
| 173 | + |
|---|
| 174 | + if (!ipsec_ops || !ipsec_ops->esp_modify_xfrm) |
|---|
| 175 | + return -EOPNOTSUPP; |
|---|
| 176 | + |
|---|
| 177 | + return ipsec_ops->esp_modify_xfrm(xfrm, attrs); |
|---|
| 108 | 178 | } |
|---|
| 109 | 179 | EXPORT_SYMBOL_GPL(mlx5_accel_esp_modify_xfrm); |
|---|