]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net/mlx5: Refactor mlx5_accel_esp_create_hw_context parameter list
authorRaed Salem <raeds@mellanox.com>
Tue, 10 Dec 2019 11:20:55 +0000 (13:20 +0200)
committerSaeed Mahameed <saeedm@mellanox.com>
Mon, 20 Apr 2020 21:20:19 +0000 (14:20 -0700)
Currently the FPGA IPsec is the only hw implementation of the IPsec
acceleration api, and so the mlx5_accel_esp_create_hw_context was
wrongly made to suit this HW api, among other in its parameter list
and some of its parameter endianness.

This implementation might not be suitable for different HW.

Refactor by group and pass all function arguments of
mlx5_accel_esp_create_hw_context in common mlx5_accel_esp_xfrm_attrs
struct field of mlx5_accel_esp_xfrm struct and correct the endianness
according to the HW being called.

Signed-off-by: Raed Salem <raeds@mellanox.com>
Reviewed-by: Boris Pismenny <borisp@mellanox.com>
Reviewed-by: Huy Nguyen <huyn@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/accel/ipsec.c
drivers/net/ethernet/mellanox/mlx5/core/accel/ipsec.h
drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c
include/linux/mlx5/accel.h

index eddc34e4a7625000103dc37f6bb4442a82362306..a92cd88d369cedcfc2142a8b394715a2010fcf16 100644 (file)
@@ -57,13 +57,21 @@ int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
 }
 
 void *mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
-                                      struct mlx5_accel_esp_xfrm *xfrm,
-                                      const __be32 saddr[4],
-                                      const __be32 daddr[4],
-                                      const __be32 spi, bool is_ipv6)
+                                      struct mlx5_accel_esp_xfrm *xfrm)
 {
-       return mlx5_fpga_ipsec_create_sa_ctx(mdev, xfrm, saddr, daddr,
-                                            spi, is_ipv6);
+       __be32 saddr[4] = {}, daddr[4] = {};
+
+       if (!xfrm->attrs.is_ipv6) {
+               saddr[3] = xfrm->attrs.saddr.a4;
+               daddr[3] = xfrm->attrs.daddr.a4;
+       } else {
+               memcpy(saddr, xfrm->attrs.saddr.a6, sizeof(saddr));
+               memcpy(daddr, xfrm->attrs.daddr.a6, sizeof(daddr));
+       }
+
+       return mlx5_fpga_ipsec_create_sa_ctx(mdev, xfrm, saddr,
+                                            daddr, xfrm->attrs.spi,
+                                            xfrm->attrs.is_ipv6);
 }
 
 void mlx5_accel_esp_free_hw_context(void *context)
index 530e428d46ab7288f0cb744561c66caed03535fd..f9b8e2a041c1eb0779b61f525459ec0b6fe33087 100644 (file)
@@ -47,10 +47,7 @@ int mlx5_accel_ipsec_counters_read(struct mlx5_core_dev *mdev, u64 *counters,
                                   unsigned int count);
 
 void *mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
-                                      struct mlx5_accel_esp_xfrm *xfrm,
-                                      const __be32 saddr[4],
-                                      const __be32 daddr[4],
-                                      const __be32 spi, bool is_ipv6);
+                                      struct mlx5_accel_esp_xfrm *xfrm);
 void mlx5_accel_esp_free_hw_context(void *context);
 
 int mlx5_accel_ipsec_init(struct mlx5_core_dev *mdev);
@@ -63,10 +60,7 @@ void mlx5_accel_ipsec_cleanup(struct mlx5_core_dev *mdev);
 
 static inline void *
 mlx5_accel_esp_create_hw_context(struct mlx5_core_dev *mdev,
-                                struct mlx5_accel_esp_xfrm *xfrm,
-                                const __be32 saddr[4],
-                                const __be32 daddr[4],
-                                const __be32 spi, bool is_ipv6)
+                                struct mlx5_accel_esp_xfrm *xfrm)
 {
        return NULL;
 }
index 29626c6c9c25cc0eacd20a3b1bbde073c43098c0..9e6c2216c93ecbe1272955e2b89dff1c068fc254 100644 (file)
@@ -199,6 +199,14 @@ mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
        attrs->flags |= (x->props.mode == XFRM_MODE_TRANSPORT) ?
                        MLX5_ACCEL_ESP_FLAGS_TRANSPORT :
                        MLX5_ACCEL_ESP_FLAGS_TUNNEL;
+
+       /* spi */
+       attrs->spi = x->id.spi;
+
+       /* source , destination ips */
+       memcpy(&attrs->saddr, x->props.saddr.a6, sizeof(attrs->saddr));
+       memcpy(&attrs->daddr, x->id.daddr.a6, sizeof(attrs->daddr));
+       attrs->is_ipv6 = (x->props.family != AF_INET);
 }
 
 static inline int mlx5e_xfrm_validate_state(struct xfrm_state *x)
@@ -284,8 +292,6 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x)
        struct net_device *netdev = x->xso.dev;
        struct mlx5_accel_esp_xfrm_attrs attrs;
        struct mlx5e_priv *priv;
-       __be32 saddr[4] = {0}, daddr[4] = {0}, spi;
-       bool is_ipv6 = false;
        int err;
 
        priv = netdev_priv(netdev);
@@ -331,20 +337,9 @@ static int mlx5e_xfrm_add_state(struct xfrm_state *x)
        }
 
        /* create hw context */
-       if (x->props.family == AF_INET) {
-               saddr[3] = x->props.saddr.a4;
-               daddr[3] = x->id.daddr.a4;
-       } else {
-               memcpy(saddr, x->props.saddr.a6, sizeof(saddr));
-               memcpy(daddr, x->id.daddr.a6, sizeof(daddr));
-               is_ipv6 = true;
-       }
-       spi = x->id.spi;
        sa_entry->hw_context =
                        mlx5_accel_esp_create_hw_context(priv->mdev,
-                                                        sa_entry->xfrm,
-                                                        saddr, daddr, spi,
-                                                        is_ipv6);
+                                                        sa_entry->xfrm);
        if (IS_ERR(sa_entry->hw_context)) {
                err = PTR_ERR(sa_entry->hw_context);
                goto err_xfrm;
index 5613e677a5f93b9f0cc945b0e13e0038bfccb763..b919d143a9a6e9e4e94854a67e8473c8dea9b042 100644 (file)
@@ -92,6 +92,18 @@ struct mlx5_accel_esp_xfrm_attrs {
        union {
                struct aes_gcm_keymat aes_gcm;
        } keymat;
+
+       union {
+               __be32 a4;
+               __be32 a6[4];
+       } saddr;
+
+       union {
+               __be32 a4;
+               __be32 a6[4];
+       } daddr;
+
+       u8 is_ipv6;
 };
 
 struct mlx5_accel_esp_xfrm {