In AES-XTS the data to be encrypted\decrypted does not have to be
in multiples of 16B size, the unit of data is called data-unit.

As a result of patch [1] a new field is added to the cipher capability,
called dataunit_set, where the devices can report the range of
supported data-unit sizes.

The new field enables saving the data-unit size in the session
structure to the block size pointer variable in order to support
several data-unit sizes.

[1] https://www.mail-archive.com/dev@dpdk.org/msg203590.html

Signed-off-by: Shiri Kuzin <shi...@nvidia.com>
---
 drivers/crypto/mlx5/mlx5_crypto.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/crypto/mlx5/mlx5_crypto.c 
b/drivers/crypto/mlx5/mlx5_crypto.c
index 25a435a999..8810872aff 100644
--- a/drivers/crypto/mlx5/mlx5_crypto.c
+++ b/drivers/crypto/mlx5/mlx5_crypto.c
@@ -48,6 +48,11 @@ struct mlx5_crypto_session {
         * bsf_size, bsf_p_type, encryption_order and encryption standard,
         * saved in big endian format.
         */
+       uint32_t bsp_res;
+       /*
+        * crypto_block_size_pointer and reserved 24 bits saved in big endian
+        * format.
+        */
        uint32_t iv_offset:16;
        /* Starting point for Initialisation Vector. */
        struct mlx5_crypto_dek *dek; /* Pointer to dek struct. */
@@ -170,6 +175,26 @@ mlx5_crypto_sym_session_configure(struct rte_cryptodev 
*dev,
                         MLX5_BSF_P_TYPE_CRYPTO << MLX5_BSF_P_TYPE_OFFSET |
                         encryption_order << MLX5_ENCRYPTION_ORDER_OFFSET |
                         MLX5_ENCRYPTION_STANDARD_AES_XTS);
+       switch (xform->cipher.dataunit_len) {
+       case RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES:
+               sess_private_data->bsp_res = rte_cpu_to_be_32
+                                            ((uint32_t)MLX5_BLOCK_SIZE_512B <<
+                                            MLX5_BLOCK_SIZE_OFFSET);
+               break;
+       case RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES:
+               sess_private_data->bsp_res = rte_cpu_to_be_32
+                                            ((uint32_t)MLX5_BLOCK_SIZE_4096B <<
+                                            MLX5_BLOCK_SIZE_OFFSET);
+               break;
+       case RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1M_BYTES:
+               sess_private_data->bsp_res = rte_cpu_to_be_32
+                                            ((uint32_t)MLX5_BLOCK_SIZE_1MB <<
+                                            MLX5_BLOCK_SIZE_OFFSET);
+               break;
+       default:
+               DRV_LOG(ERR, "Cipher data unit length is not supported.");
+               return -ENOTSUP;
+       }
        sess_private_data->iv_offset = cipher->iv.offset;
        set_sym_session_private_data(session, dev->driver_id,
                                     sess_private_data);
-- 
2.21.0

Reply via email to