net/mlx5: Add support SYNC_CRYPTO command
authorJianbo Liu <jianbol@nvidia.com>
Wed, 20 Jul 2022 02:43:40 +0000 (02:43 +0000)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 31 Jan 2023 03:10:05 +0000 (19:10 -0800)
Add support for SYNC_CRYPTO command. For now, it is executed only when
initializing DEK, but needed when reusing keys in later patch.

Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c
drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.c

index 382d02f6619c7b85fb17a059388872ba2efd9d2a..b00e33ed05e9177460260436c560bd37f3817fe8 100644 (file)
@@ -104,6 +104,7 @@ static bool mlx5_cmd_is_throttle_opcode(u16 op)
        case MLX5_CMD_OP_DESTROY_GENERAL_OBJECT:
        case MLX5_CMD_OP_MODIFY_GENERAL_OBJECT:
        case MLX5_CMD_OP_QUERY_GENERAL_OBJECT:
+       case MLX5_CMD_OP_SYNC_CRYPTO:
                return true;
        }
        return false;
@@ -523,6 +524,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
        case MLX5_CMD_OP_QUERY_VHCA_MIGRATION_STATE:
        case MLX5_CMD_OP_SAVE_VHCA_STATE:
        case MLX5_CMD_OP_LOAD_VHCA_STATE:
+       case MLX5_CMD_OP_SYNC_CRYPTO:
                *status = MLX5_DRIVER_STATUS_ABORTED;
                *synd = MLX5_DRIVER_SYND;
                return -ENOLINK;
@@ -725,6 +727,7 @@ const char *mlx5_command_str(int command)
        MLX5_COMMAND_STR_CASE(QUERY_VHCA_MIGRATION_STATE);
        MLX5_COMMAND_STR_CASE(SAVE_VHCA_STATE);
        MLX5_COMMAND_STR_CASE(LOAD_VHCA_STATE);
+       MLX5_COMMAND_STR_CASE(SYNC_CRYPTO);
        default: return "unknown command opcode";
        }
 }
index d1b4cc99075679f310a732bd1743d65b8cf9a459..ce29251484c048a19eac89c241964bb36a85d899 100644 (file)
@@ -7,6 +7,10 @@
 #define MLX5_CRYPTO_DEK_POOLS_NUM (MLX5_ACCEL_OBJ_TYPE_KEY_NUM - 1)
 #define type2idx(type) ((type) - 1)
 
+enum {
+       MLX5_CRYPTO_DEK_ALL_TYPE = BIT(0),
+};
+
 struct mlx5_crypto_dek_pool {
        struct mlx5_core_dev *mdev;
        u32 key_purpose;
@@ -71,6 +75,28 @@ static int mlx5_crypto_dek_fill_key(struct mlx5_core_dev *mdev, u8 *key_obj,
        return 0;
 }
 
+static int mlx5_crypto_cmd_sync_crypto(struct mlx5_core_dev *mdev,
+                                      int crypto_type)
+{
+       u32 in[MLX5_ST_SZ_DW(sync_crypto_in)] = {};
+       int err;
+
+       mlx5_core_dbg(mdev,
+                     "Execute SYNC_CRYPTO command with crypto_type(0x%x)\n",
+                     crypto_type);
+
+       MLX5_SET(sync_crypto_in, in, opcode, MLX5_CMD_OP_SYNC_CRYPTO);
+       MLX5_SET(sync_crypto_in, in, crypto_type, crypto_type);
+
+       err = mlx5_cmd_exec_in(mdev, sync_crypto, in);
+       if (err)
+               mlx5_core_err(mdev,
+                             "Failed to exec sync crypto, type=%d, err=%d\n",
+                             crypto_type, err);
+
+       return err;
+}
+
 static int mlx5_crypto_create_dek_key(struct mlx5_core_dev *mdev,
                                      const void *key, u32 sz_bytes,
                                      u32 key_purpose, u32 *p_key_id)
@@ -197,6 +223,7 @@ void mlx5_crypto_dek_cleanup(struct mlx5_crypto_dek_priv *dek_priv)
 struct mlx5_crypto_dek_priv *mlx5_crypto_dek_init(struct mlx5_core_dev *mdev)
 {
        struct mlx5_crypto_dek_priv *dek_priv;
+       int err;
 
        if (!MLX5_CAP_CRYPTO(mdev, log_dek_max_alloc))
                return NULL;
@@ -209,10 +236,19 @@ struct mlx5_crypto_dek_priv *mlx5_crypto_dek_init(struct mlx5_core_dev *mdev)
        dek_priv->log_dek_obj_range = min_t(int, 12,
                                            MLX5_CAP_CRYPTO(mdev, log_dek_max_alloc));
 
+       /* sync all types of objects */
+       err = mlx5_crypto_cmd_sync_crypto(mdev, MLX5_CRYPTO_DEK_ALL_TYPE);
+       if (err)
+               goto err_sync_crypto;
+
        mlx5_core_dbg(mdev, "Crypto DEK enabled, %d deks per alloc (max %d), total %d\n",
                      1 << dek_priv->log_dek_obj_range,
                      1 << MLX5_CAP_CRYPTO(mdev, log_dek_max_alloc),
                      1 << MLX5_CAP_CRYPTO(mdev, log_max_num_deks));
 
        return dek_priv;
+
+err_sync_crypto:
+       kfree(dek_priv);
+       return ERR_PTR(err);
 }