Skip to content

Commit

Permalink
net/mlx5: Add support SYNC_CRYPTO command
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jianbo Liu authored and Saeed Mahameed committed Jan 31, 2023
1 parent 204369e commit 7a5b72c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
}
}
Expand Down
36 changes: 36 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/lib/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}

0 comments on commit 7a5b72c

Please sign in to comment.