LCOV - code coverage report
Current view: top level - lib/cryptodev - rte_cryptodev.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 15 32 46.9 %
Date: 2025-02-01 18:54:23 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 24 12.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2015-2020 Intel Corporation.
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef _RTE_CRYPTODEV_H_
       6                 :            : #define _RTE_CRYPTODEV_H_
       7                 :            : 
       8                 :            : /**
       9                 :            :  * @file rte_cryptodev.h
      10                 :            :  *
      11                 :            :  * RTE Cryptographic Device APIs
      12                 :            :  *
      13                 :            :  * Defines RTE Crypto Device APIs for the provisioning of cipher and
      14                 :            :  * authentication operations.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include <rte_compat.h>
      18                 :            : #include "rte_kvargs.h"
      19                 :            : #include "rte_crypto.h"
      20                 :            : #include <rte_common.h>
      21                 :            : #include <rte_rcu_qsbr.h>
      22                 :            : 
      23                 :            : #include "rte_cryptodev_trace_fp.h"
      24                 :            : 
      25                 :            : #ifdef __cplusplus
      26                 :            : extern "C" {
      27                 :            : #endif
      28                 :            : 
      29                 :            : /**
      30                 :            :  * @internal Logtype used for cryptodev related messages.
      31                 :            :  */
      32                 :            : extern int rte_cryptodev_logtype;
      33                 :            : #define RTE_LOGTYPE_CRYPTODEV rte_cryptodev_logtype
      34                 :            : 
      35                 :            : /* Logging Macros */
      36                 :            : #define CDEV_LOG_ERR(...) \
      37                 :            :         RTE_LOG_LINE_PREFIX(ERR, CRYPTODEV, \
      38                 :            :                 "%s() line %u: ", __func__ RTE_LOG_COMMA __LINE__, __VA_ARGS__)
      39                 :            : 
      40                 :            : #define CDEV_LOG_INFO(...) \
      41                 :            :         RTE_LOG_LINE(INFO, CRYPTODEV, "" __VA_ARGS__)
      42                 :            : 
      43                 :            : #define CDEV_LOG_DEBUG(...) \
      44                 :            :         RTE_LOG_LINE_PREFIX(DEBUG, CRYPTODEV, \
      45                 :            :                 "%s() line %u: ", __func__ RTE_LOG_COMMA __LINE__, __VA_ARGS__)
      46                 :            : 
      47                 :            : #define CDEV_PMD_TRACE(...) \
      48                 :            :         RTE_LOG_LINE_PREFIX(DEBUG, CRYPTODEV, \
      49                 :            :                 "[%s] %s: ", dev RTE_LOG_COMMA __func__, __VA_ARGS__)
      50                 :            : 
      51                 :            : /**
      52                 :            :  * A macro that points to an offset from the start
      53                 :            :  * of the crypto operation structure (rte_crypto_op)
      54                 :            :  *
      55                 :            :  * The returned pointer is cast to type t.
      56                 :            :  *
      57                 :            :  * @param c
      58                 :            :  *   The crypto operation.
      59                 :            :  * @param o
      60                 :            :  *   The offset from the start of the crypto operation.
      61                 :            :  * @param t
      62                 :            :  *   The type to cast the result into.
      63                 :            :  */
      64                 :            : #define rte_crypto_op_ctod_offset(c, t, o)      \
      65                 :            :         ((t)((char *)(c) + (o)))
      66                 :            : 
      67                 :            : /**
      68                 :            :  * A macro that returns the physical address that points
      69                 :            :  * to an offset from the start of the crypto operation
      70                 :            :  * (rte_crypto_op)
      71                 :            :  *
      72                 :            :  * @param c
      73                 :            :  *   The crypto operation.
      74                 :            :  * @param o
      75                 :            :  *   The offset from the start of the crypto operation
      76                 :            :  *   to calculate address from.
      77                 :            :  */
      78                 :            : #define rte_crypto_op_ctophys_offset(c, o)      \
      79                 :            :         (rte_iova_t)((c)->phys_addr + (o))
      80                 :            : 
      81                 :            : /**
      82                 :            :  * Crypto parameters range description
      83                 :            :  */
      84                 :            : struct rte_crypto_param_range {
      85                 :            :         uint16_t min;   /**< minimum size */
      86                 :            :         uint16_t max;   /**< maximum size */
      87                 :            :         uint16_t increment;
      88                 :            :         /**< if a range of sizes are supported,
      89                 :            :          * this parameter is used to indicate
      90                 :            :          * increments in byte size that are supported
      91                 :            :          * between the minimum and maximum
      92                 :            :          */
      93                 :            : };
      94                 :            : 
      95                 :            : /**
      96                 :            :  * Data-unit supported lengths of cipher algorithms.
      97                 :            :  * A bit can represent any set of data-unit sizes
      98                 :            :  * (single size, multiple size, range, etc).
      99                 :            :  */
     100                 :            : #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_512_BYTES             RTE_BIT32(0)
     101                 :            : #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_4096_BYTES            RTE_BIT32(1)
     102                 :            : #define RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_1_MEGABYTES           RTE_BIT32(2)
     103                 :            : 
     104                 :            : /**
     105                 :            :  * Symmetric Crypto Capability
     106                 :            :  */
     107                 :            : struct rte_cryptodev_symmetric_capability {
     108                 :            :         enum rte_crypto_sym_xform_type xform_type;
     109                 :            :         /**< Transform type : Authentication / Cipher / AEAD */
     110                 :            :         union {
     111                 :            :                 struct {
     112                 :            :                         enum rte_crypto_auth_algorithm algo;
     113                 :            :                         /**< authentication algorithm */
     114                 :            :                         uint16_t block_size;
     115                 :            :                         /**< algorithm block size */
     116                 :            :                         struct rte_crypto_param_range key_size;
     117                 :            :                         /**< auth key size range */
     118                 :            :                         struct rte_crypto_param_range digest_size;
     119                 :            :                         /**< digest size range */
     120                 :            :                         struct rte_crypto_param_range aad_size;
     121                 :            :                         /**< Additional authentication data size range */
     122                 :            :                         struct rte_crypto_param_range iv_size;
     123                 :            :                         /**< Initialisation vector data size range */
     124                 :            :                 } auth;
     125                 :            :                 /**< Symmetric Authentication transform capabilities */
     126                 :            :                 struct {
     127                 :            :                         enum rte_crypto_cipher_algorithm algo;
     128                 :            :                         /**< cipher algorithm */
     129                 :            :                         uint16_t block_size;
     130                 :            :                         /**< algorithm block size */
     131                 :            :                         struct rte_crypto_param_range key_size;
     132                 :            :                         /**< cipher key size range */
     133                 :            :                         struct rte_crypto_param_range iv_size;
     134                 :            :                         /**< Initialisation vector data size range */
     135                 :            :                         uint32_t dataunit_set;
     136                 :            :                         /**<
     137                 :            :                          * Supported data-unit lengths:
     138                 :            :                          * RTE_CRYPTO_CIPHER_DATA_UNIT_LEN_* bits
     139                 :            :                          * or 0 for lengths defined in the algorithm standard.
     140                 :            :                          */
     141                 :            :                 } cipher;
     142                 :            :                 /**< Symmetric Cipher transform capabilities */
     143                 :            :                 struct {
     144                 :            :                         enum rte_crypto_aead_algorithm algo;
     145                 :            :                         /**< AEAD algorithm */
     146                 :            :                         uint16_t block_size;
     147                 :            :                         /**< algorithm block size */
     148                 :            :                         struct rte_crypto_param_range key_size;
     149                 :            :                         /**< AEAD key size range */
     150                 :            :                         struct rte_crypto_param_range digest_size;
     151                 :            :                         /**< digest size range */
     152                 :            :                         struct rte_crypto_param_range aad_size;
     153                 :            :                         /**< Additional authentication data size range */
     154                 :            :                         struct rte_crypto_param_range iv_size;
     155                 :            :                         /**< Initialisation vector data size range */
     156                 :            :                 } aead;
     157                 :            :         };
     158                 :            : };
     159                 :            : 
     160                 :            : /**
     161                 :            :  * Asymmetric Xform Crypto Capability
     162                 :            :  */
     163                 :            : struct rte_cryptodev_asymmetric_xform_capability {
     164                 :            :         enum rte_crypto_asym_xform_type xform_type;
     165                 :            :         /**< Transform type: RSA/MODEXP/DH/DSA/MODINV */
     166                 :            : 
     167                 :            :         uint32_t op_types;
     168                 :            :         /**<
     169                 :            :          * Bitmask for supported rte_crypto_asym_op_type or
     170                 :            :          * rte_crypto_asym_ke_type. Which enum is used is determined
     171                 :            :          * by the rte_crypto_asym_xform_type. For key exchange algorithms
     172                 :            :          * like Diffie-Hellman it is rte_crypto_asym_ke_type, for others
     173                 :            :          * it is rte_crypto_asym_op_type.
     174                 :            :          */
     175                 :            : 
     176                 :            :         __extension__
     177                 :            :         union {
     178                 :            :                 struct rte_crypto_param_range modlen;
     179                 :            :                 /**< Range of modulus length supported by modulus based xform.
     180                 :            :                  * Value 0 mean implementation default
     181                 :            :                  */
     182                 :            : 
     183                 :            :                 uint8_t internal_rng;
     184                 :            :                 /**< Availability of random number generator for Elliptic curve based xform.
     185                 :            :                  * Value 0 means unavailable, and application should pass the required
     186                 :            :                  * random value. Otherwise, PMD would internally compute the random number.
     187                 :            :                  */
     188                 :            : 
     189                 :            :                 uint32_t op_capa[RTE_CRYPTO_ASYM_OP_LIST_END];
     190                 :            :                 /**< Operation specific capabilities. */
     191                 :            :         };
     192                 :            : 
     193                 :            :         uint64_t hash_algos;
     194                 :            :         /**< Bitmask of hash algorithms supported for op_type. */
     195                 :            : };
     196                 :            : 
     197                 :            : /**
     198                 :            :  * Asymmetric Crypto Capability
     199                 :            :  */
     200                 :            : struct rte_cryptodev_asymmetric_capability {
     201                 :            :         struct rte_cryptodev_asymmetric_xform_capability xform_capa;
     202                 :            : };
     203                 :            : 
     204                 :            : 
     205                 :            : /** Structure used to capture a capability of a crypto device */
     206                 :            : struct rte_cryptodev_capabilities {
     207                 :            :         enum rte_crypto_op_type op;
     208                 :            :         /**< Operation type */
     209                 :            : 
     210                 :            :         union {
     211                 :            :                 struct rte_cryptodev_symmetric_capability sym;
     212                 :            :                 /**< Symmetric operation capability parameters */
     213                 :            :                 struct rte_cryptodev_asymmetric_capability asym;
     214                 :            :                 /**< Asymmetric operation capability parameters */
     215                 :            :         };
     216                 :            : };
     217                 :            : 
     218                 :            : /** Structure used to describe crypto algorithms */
     219                 :            : struct rte_cryptodev_sym_capability_idx {
     220                 :            :         enum rte_crypto_sym_xform_type type;
     221                 :            :         union {
     222                 :            :                 enum rte_crypto_cipher_algorithm cipher;
     223                 :            :                 enum rte_crypto_auth_algorithm auth;
     224                 :            :                 enum rte_crypto_aead_algorithm aead;
     225                 :            :         } algo;
     226                 :            : };
     227                 :            : 
     228                 :            : /**
     229                 :            :  * Structure used to describe asymmetric crypto xforms
     230                 :            :  * Each xform maps to one asym algorithm.
     231                 :            :  */
     232                 :            : struct rte_cryptodev_asym_capability_idx {
     233                 :            :         enum rte_crypto_asym_xform_type type;
     234                 :            :         /**< Asymmetric xform (algo) type */
     235                 :            : };
     236                 :            : 
     237                 :            : /**
     238                 :            :  * Provide capabilities available for defined device and algorithm
     239                 :            :  *
     240                 :            :  * @param       dev_id          The identifier of the device.
     241                 :            :  * @param       idx             Description of crypto algorithms.
     242                 :            :  *
     243                 :            :  * @return
     244                 :            :  *   - Return description of the symmetric crypto capability if exist.
     245                 :            :  *   - Return NULL if the capability not exist.
     246                 :            :  */
     247                 :            : const struct rte_cryptodev_symmetric_capability *
     248                 :            : rte_cryptodev_sym_capability_get(uint8_t dev_id,
     249                 :            :                 const struct rte_cryptodev_sym_capability_idx *idx);
     250                 :            : 
     251                 :            : /**
     252                 :            :  *  Provide capabilities available for defined device and xform
     253                 :            :  *
     254                 :            :  * @param       dev_id          The identifier of the device.
     255                 :            :  * @param       idx             Description of asym crypto xform.
     256                 :            :  *
     257                 :            :  * @return
     258                 :            :  *   - Return description of the asymmetric crypto capability if exist.
     259                 :            :  *   - Return NULL if the capability not exist.
     260                 :            :  */
     261                 :            : const struct rte_cryptodev_asymmetric_xform_capability *
     262                 :            : rte_cryptodev_asym_capability_get(uint8_t dev_id,
     263                 :            :                 const struct rte_cryptodev_asym_capability_idx *idx);
     264                 :            : 
     265                 :            : /**
     266                 :            :  * Check if key size and initial vector are supported
     267                 :            :  * in crypto cipher capability
     268                 :            :  *
     269                 :            :  * @param       capability      Description of the symmetric crypto capability.
     270                 :            :  * @param       key_size        Cipher key size.
     271                 :            :  * @param       iv_size         Cipher initial vector size.
     272                 :            :  *
     273                 :            :  * @return
     274                 :            :  *   - Return 0 if the parameters are in range of the capability.
     275                 :            :  *   - Return -1 if the parameters are out of range of the capability.
     276                 :            :  */
     277                 :            : int
     278                 :            : rte_cryptodev_sym_capability_check_cipher(
     279                 :            :                 const struct rte_cryptodev_symmetric_capability *capability,
     280                 :            :                 uint16_t key_size, uint16_t iv_size);
     281                 :            : 
     282                 :            : /**
     283                 :            :  * Check if key size and initial vector are supported
     284                 :            :  * in crypto auth capability
     285                 :            :  *
     286                 :            :  * @param       capability      Description of the symmetric crypto capability.
     287                 :            :  * @param       key_size        Auth key size.
     288                 :            :  * @param       digest_size     Auth digest size.
     289                 :            :  * @param       iv_size         Auth initial vector size.
     290                 :            :  *
     291                 :            :  * @return
     292                 :            :  *   - Return 0 if the parameters are in range of the capability.
     293                 :            :  *   - Return -1 if the parameters are out of range of the capability.
     294                 :            :  */
     295                 :            : int
     296                 :            : rte_cryptodev_sym_capability_check_auth(
     297                 :            :                 const struct rte_cryptodev_symmetric_capability *capability,
     298                 :            :                 uint16_t key_size, uint16_t digest_size, uint16_t iv_size);
     299                 :            : 
     300                 :            : /**
     301                 :            :  * Check if key, digest, AAD and initial vector sizes are supported
     302                 :            :  * in crypto AEAD capability
     303                 :            :  *
     304                 :            :  * @param       capability      Description of the symmetric crypto capability.
     305                 :            :  * @param       key_size        AEAD key size.
     306                 :            :  * @param       digest_size     AEAD digest size.
     307                 :            :  * @param       aad_size        AEAD AAD size.
     308                 :            :  * @param       iv_size         AEAD IV size.
     309                 :            :  *
     310                 :            :  * @return
     311                 :            :  *   - Return 0 if the parameters are in range of the capability.
     312                 :            :  *   - Return -1 if the parameters are out of range of the capability.
     313                 :            :  */
     314                 :            : int
     315                 :            : rte_cryptodev_sym_capability_check_aead(
     316                 :            :                 const struct rte_cryptodev_symmetric_capability *capability,
     317                 :            :                 uint16_t key_size, uint16_t digest_size, uint16_t aad_size,
     318                 :            :                 uint16_t iv_size);
     319                 :            : 
     320                 :            : /**
     321                 :            :  * Check if op type is supported
     322                 :            :  *
     323                 :            :  * @param       capability      Description of the asymmetric crypto capability.
     324                 :            :  * @param       op_type         op type
     325                 :            :  *
     326                 :            :  * @return
     327                 :            :  *   - Return 1 if the op type is supported
     328                 :            :  *   - Return 0 if unsupported
     329                 :            :  */
     330                 :            : int
     331                 :            : rte_cryptodev_asym_xform_capability_check_optype(
     332                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability,
     333                 :            :                 enum rte_crypto_asym_op_type op_type);
     334                 :            : 
     335                 :            : /**
     336                 :            :  * Check if modulus length is in supported range
     337                 :            :  *
     338                 :            :  * @param       capability      Description of the asymmetric crypto capability.
     339                 :            :  * @param       modlen          modulus length.
     340                 :            :  *
     341                 :            :  * @return
     342                 :            :  *   - Return 0 if the parameters are in range of the capability.
     343                 :            :  *   - Return -1 if the parameters are out of range of the capability.
     344                 :            :  */
     345                 :            : int
     346                 :            : rte_cryptodev_asym_xform_capability_check_modlen(
     347                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability,
     348                 :            :                 uint16_t modlen);
     349                 :            : 
     350                 :            : /**
     351                 :            :  * Check if hash algorithm is supported.
     352                 :            :  *
     353                 :            :  * @param       capability      Asymmetric crypto capability.
     354                 :            :  * @param       hash            Hash algorithm.
     355                 :            :  *
     356                 :            :  * @return
     357                 :            :  *   - Return true if the hash algorithm is supported.
     358                 :            :  *   - Return false if the hash algorithm is not supported.
     359                 :            :  */
     360                 :            : bool
     361                 :            : rte_cryptodev_asym_xform_capability_check_hash(
     362                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability,
     363                 :            :         enum rte_crypto_auth_algorithm hash);
     364                 :            : 
     365                 :            : /**
     366                 :            :  * @warning
     367                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     368                 :            :  *
     369                 :            :  * Check if op capability is supported
     370                 :            :  *
     371                 :            :  * @param       capability      Description of the asymmetric crypto capability.
     372                 :            :  * @param       op_type         op type
     373                 :            :  * @param       cap             op capability
     374                 :            :  *
     375                 :            :  * @return
     376                 :            :  *   - Return 1 if the op capability is supported
     377                 :            :  *   - Return 0 if unsupported
     378                 :            :  */
     379                 :            : __rte_experimental
     380                 :            : int
     381                 :            : rte_cryptodev_asym_xform_capability_check_opcap(
     382                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability,
     383                 :            :         enum rte_crypto_asym_op_type op_type, uint8_t cap);
     384                 :            : 
     385                 :            : /**
     386                 :            :  * Provide the cipher algorithm enum, given an algorithm string
     387                 :            :  *
     388                 :            :  * @param       algo_enum       A pointer to the cipher algorithm
     389                 :            :  *                              enum to be filled
     390                 :            :  * @param       algo_string     Authentication algo string
     391                 :            :  *
     392                 :            :  * @return
     393                 :            :  * - Return -1 if string is not valid
     394                 :            :  * - Return 0 is the string is valid
     395                 :            :  */
     396                 :            : int
     397                 :            : rte_cryptodev_get_cipher_algo_enum(enum rte_crypto_cipher_algorithm *algo_enum,
     398                 :            :                 const char *algo_string);
     399                 :            : 
     400                 :            : /**
     401                 :            :  * Provide the authentication algorithm enum, given an algorithm string
     402                 :            :  *
     403                 :            :  * @param       algo_enum       A pointer to the authentication algorithm
     404                 :            :  *                              enum to be filled
     405                 :            :  * @param       algo_string     Authentication algo string
     406                 :            :  *
     407                 :            :  * @return
     408                 :            :  * - Return -1 if string is not valid
     409                 :            :  * - Return 0 is the string is valid
     410                 :            :  */
     411                 :            : int
     412                 :            : rte_cryptodev_get_auth_algo_enum(enum rte_crypto_auth_algorithm *algo_enum,
     413                 :            :                 const char *algo_string);
     414                 :            : 
     415                 :            : /**
     416                 :            :  * Provide the AEAD algorithm enum, given an algorithm string
     417                 :            :  *
     418                 :            :  * @param       algo_enum       A pointer to the AEAD algorithm
     419                 :            :  *                              enum to be filled
     420                 :            :  * @param       algo_string     AEAD algorithm string
     421                 :            :  *
     422                 :            :  * @return
     423                 :            :  * - Return -1 if string is not valid
     424                 :            :  * - Return 0 is the string is valid
     425                 :            :  */
     426                 :            : int
     427                 :            : rte_cryptodev_get_aead_algo_enum(enum rte_crypto_aead_algorithm *algo_enum,
     428                 :            :                 const char *algo_string);
     429                 :            : 
     430                 :            : /**
     431                 :            :  * Provide the Asymmetric xform enum, given an xform string
     432                 :            :  *
     433                 :            :  * @param       xform_enum      A pointer to the xform type
     434                 :            :  *                              enum to be filled
     435                 :            :  * @param       xform_string    xform string
     436                 :            :  *
     437                 :            :  * @return
     438                 :            :  * - Return -1 if string is not valid
     439                 :            :  * - Return 0 if the string is valid
     440                 :            :  */
     441                 :            : int
     442                 :            : rte_cryptodev_asym_get_xform_enum(enum rte_crypto_asym_xform_type *xform_enum,
     443                 :            :                 const char *xform_string);
     444                 :            : 
     445                 :            : /**
     446                 :            :  * Provide the cipher algorithm string, given an algorithm enum.
     447                 :            :  *
     448                 :            :  * @param       algo_enum       cipher algorithm enum
     449                 :            :  *
     450                 :            :  * @return
     451                 :            :  * - Return NULL if enum is not valid
     452                 :            :  * - Return algo_string corresponding to enum
     453                 :            :  */
     454                 :            : __rte_experimental
     455                 :            : const char *
     456                 :            : rte_cryptodev_get_cipher_algo_string(enum rte_crypto_cipher_algorithm algo_enum);
     457                 :            : 
     458                 :            : /**
     459                 :            :  * Provide the authentication algorithm string, given an algorithm enum.
     460                 :            :  *
     461                 :            :  * @param       algo_enum       auth algorithm enum
     462                 :            :  *
     463                 :            :  * @return
     464                 :            :  * - Return NULL if enum is not valid
     465                 :            :  * - Return algo_string corresponding to enum
     466                 :            :  */
     467                 :            : __rte_experimental
     468                 :            : const char *
     469                 :            : rte_cryptodev_get_auth_algo_string(enum rte_crypto_auth_algorithm algo_enum);
     470                 :            : 
     471                 :            : /**
     472                 :            :  * Provide the AEAD algorithm string, given an algorithm enum.
     473                 :            :  *
     474                 :            :  * @param       algo_enum       AEAD algorithm enum
     475                 :            :  *
     476                 :            :  * @return
     477                 :            :  * - Return NULL if enum is not valid
     478                 :            :  * - Return algo_string corresponding to enum
     479                 :            :  */
     480                 :            : __rte_experimental
     481                 :            : const char *
     482                 :            : rte_cryptodev_get_aead_algo_string(enum rte_crypto_aead_algorithm algo_enum);
     483                 :            : 
     484                 :            : /**
     485                 :            :  * Provide the Asymmetric xform string, given an xform enum.
     486                 :            :  *
     487                 :            :  * @param       xform_enum      xform type enum
     488                 :            :  *
     489                 :            :  * @return
     490                 :            :  * - Return NULL, if enum is not valid.
     491                 :            :  * - Return xform string, for valid enum.
     492                 :            :  */
     493                 :            : __rte_experimental
     494                 :            : const char *
     495                 :            : rte_cryptodev_asym_get_xform_string(enum rte_crypto_asym_xform_type xform_enum);
     496                 :            : 
     497                 :            : 
     498                 :            : /** Macro used at end of crypto PMD list */
     499                 :            : #define RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() \
     500                 :            :         { RTE_CRYPTO_OP_TYPE_UNDEFINED }
     501                 :            : 
     502                 :            : 
     503                 :            : /**
     504                 :            :  * Crypto device supported feature flags
     505                 :            :  *
     506                 :            :  * Note:
     507                 :            :  * New features flags should be added to the end of the list
     508                 :            :  *
     509                 :            :  * Keep these flags synchronised with rte_cryptodev_get_feature_name()
     510                 :            :  */
     511                 :            : #define RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO               (1ULL << 0)
     512                 :            : /**< Symmetric crypto operations are supported */
     513                 :            : #define RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO              (1ULL << 1)
     514                 :            : /**< Asymmetric crypto operations are supported */
     515                 :            : #define RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING         (1ULL << 2)
     516                 :            : /**< Chaining symmetric crypto operations are supported */
     517                 :            : #define RTE_CRYPTODEV_FF_CPU_SSE                        (1ULL << 3)
     518                 :            : /**< Utilises CPU SIMD SSE instructions */
     519                 :            : #define RTE_CRYPTODEV_FF_CPU_AVX                        (1ULL << 4)
     520                 :            : /**< Utilises CPU SIMD AVX instructions */
     521                 :            : #define RTE_CRYPTODEV_FF_CPU_AVX2                       (1ULL << 5)
     522                 :            : /**< Utilises CPU SIMD AVX2 instructions */
     523                 :            : #define RTE_CRYPTODEV_FF_CPU_AESNI                      (1ULL << 6)
     524                 :            : /**< Utilises CPU AES-NI instructions */
     525                 :            : #define RTE_CRYPTODEV_FF_HW_ACCELERATED                 (1ULL << 7)
     526                 :            : /**< Operations are off-loaded to an
     527                 :            :  * external hardware accelerator
     528                 :            :  */
     529                 :            : #define RTE_CRYPTODEV_FF_CPU_AVX512                     (1ULL << 8)
     530                 :            : /**< Utilises CPU SIMD AVX512 instructions */
     531                 :            : #define RTE_CRYPTODEV_FF_IN_PLACE_SGL                   (1ULL << 9)
     532                 :            : /**< In-place Scatter-gather (SGL) buffers, with multiple segments,
     533                 :            :  * are supported
     534                 :            :  */
     535                 :            : #define RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT             (1ULL << 10)
     536                 :            : /**< Out-of-place Scatter-gather (SGL) buffers are
     537                 :            :  * supported in input and output
     538                 :            :  */
     539                 :            : #define RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT              (1ULL << 11)
     540                 :            : /**< Out-of-place Scatter-gather (SGL) buffers are supported
     541                 :            :  * in input, combined with linear buffers (LB), with a
     542                 :            :  * single segment in output
     543                 :            :  */
     544                 :            : #define RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT              (1ULL << 12)
     545                 :            : /**< Out-of-place Scatter-gather (SGL) buffers are supported
     546                 :            :  * in output, combined with linear buffers (LB) in input
     547                 :            :  */
     548                 :            : #define RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT               (1ULL << 13)
     549                 :            : /**< Out-of-place linear buffers (LB) are supported in input and output */
     550                 :            : #define RTE_CRYPTODEV_FF_CPU_NEON                       (1ULL << 14)
     551                 :            : /**< Utilises CPU NEON instructions */
     552                 :            : #define RTE_CRYPTODEV_FF_CPU_ARM_CE                     (1ULL << 15)
     553                 :            : /**< Utilises ARM CPU Cryptographic Extensions */
     554                 :            : #define RTE_CRYPTODEV_FF_SECURITY                       (1ULL << 16)
     555                 :            : /**< Support Security Protocol Processing */
     556                 :            : #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP            (1ULL << 17)
     557                 :            : /**< Support RSA Private Key OP with exponent */
     558                 :            : #define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT             (1ULL << 18)
     559                 :            : /**< Support RSA Private Key OP with CRT (quintuple) Keys */
     560                 :            : #define RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED               (1ULL << 19)
     561                 :            : /**< Support encrypted-digest operations where digest is appended to data */
     562                 :            : #define RTE_CRYPTODEV_FF_ASYM_SESSIONLESS               (1ULL << 20)
     563                 :            : /**< Support asymmetric session-less operations */
     564                 :            : #define RTE_CRYPTODEV_FF_SYM_CPU_CRYPTO                 (1ULL << 21)
     565                 :            : /**< Support symmetric cpu-crypto processing */
     566                 :            : #define RTE_CRYPTODEV_FF_SYM_SESSIONLESS                (1ULL << 22)
     567                 :            : /**< Support symmetric session-less operations */
     568                 :            : #define RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA          (1ULL << 23)
     569                 :            : /**< Support operations on data which is not byte aligned */
     570                 :            : #define RTE_CRYPTODEV_FF_SYM_RAW_DP                     (1ULL << 24)
     571                 :            : /**< Support accelerator specific symmetric raw data-path APIs */
     572                 :            : #define RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS     (1ULL << 25)
     573                 :            : /**< Support operations on multiple data-units message */
     574                 :            : #define RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY             (1ULL << 26)
     575                 :            : /**< Support wrapped key in cipher xform  */
     576                 :            : #define RTE_CRYPTODEV_FF_SECURITY_INNER_CSUM            (1ULL << 27)
     577                 :            : /**< Support inner checksum computation/verification */
     578                 :            : #define RTE_CRYPTODEV_FF_SECURITY_RX_INJECT             (1ULL << 28)
     579                 :            : /**< Support Rx injection after security processing */
     580                 :            : 
     581                 :            : /**
     582                 :            :  * Get the name of a crypto device feature flag
     583                 :            :  *
     584                 :            :  * @param       flag    The mask describing the flag.
     585                 :            :  *
     586                 :            :  * @return
     587                 :            :  *   The name of this flag, or NULL if it's not a valid feature flag.
     588                 :            :  */
     589                 :            : const char *
     590                 :            : rte_cryptodev_get_feature_name(uint64_t flag);
     591                 :            : 
     592                 :            : /**  Crypto device information */
     593                 :            : /* Structure rte_cryptodev_info 8< */
     594                 :            : struct rte_cryptodev_info {
     595                 :            :         const char *driver_name;        /**< Driver name. */
     596                 :            :         uint8_t driver_id;              /**< Driver identifier */
     597                 :            :         struct rte_device *device;      /**< Generic device information. */
     598                 :            : 
     599                 :            :         uint64_t feature_flags;
     600                 :            :         /**< Feature flags exposes HW/SW features for the given device */
     601                 :            : 
     602                 :            :         const struct rte_cryptodev_capabilities *capabilities;
     603                 :            :         /**< Array of devices supported capabilities */
     604                 :            : 
     605                 :            :         unsigned max_nb_queue_pairs;
     606                 :            :         /**< Maximum number of queues pairs supported by device. */
     607                 :            : 
     608                 :            :         uint16_t min_mbuf_headroom_req;
     609                 :            :         /**< Minimum mbuf headroom required by device */
     610                 :            : 
     611                 :            :         uint16_t min_mbuf_tailroom_req;
     612                 :            :         /**< Minimum mbuf tailroom required by device */
     613                 :            : 
     614                 :            :         struct {
     615                 :            :                 unsigned max_nb_sessions;
     616                 :            :                 /**< Maximum number of sessions supported by device.
     617                 :            :                  * If 0, the device does not have any limitation in
     618                 :            :                  * number of sessions that can be used.
     619                 :            :                  */
     620                 :            :         } sym;
     621                 :            : };
     622                 :            : /* >8 End of structure rte_cryptodev_info. */
     623                 :            : 
     624                 :            : #define RTE_CRYPTODEV_DETACHED  (0)
     625                 :            : #define RTE_CRYPTODEV_ATTACHED  (1)
     626                 :            : 
     627                 :            : /** Definitions of Crypto device event types */
     628                 :            : enum rte_cryptodev_event_type {
     629                 :            :         RTE_CRYPTODEV_EVENT_UNKNOWN,    /**< unknown event type */
     630                 :            :         RTE_CRYPTODEV_EVENT_ERROR,      /**< error interrupt event */
     631                 :            :         RTE_CRYPTODEV_EVENT_MAX         /**< max value of this enum */
     632                 :            : };
     633                 :            : 
     634                 :            : /* Crypto queue pair priority levels */
     635                 :            : #define RTE_CRYPTODEV_QP_PRIORITY_HIGHEST   0
     636                 :            : /**< Highest priority of a cryptodev queue pair
     637                 :            :  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
     638                 :            :  */
     639                 :            : #define RTE_CRYPTODEV_QP_PRIORITY_NORMAL    128
     640                 :            : /**< Normal priority of a cryptodev queue pair
     641                 :            :  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
     642                 :            :  */
     643                 :            : #define RTE_CRYPTODEV_QP_PRIORITY_LOWEST    255
     644                 :            : /**< Lowest priority of a cryptodev queue pair
     645                 :            :  * @see rte_cryptodev_queue_pair_setup(), rte_cryptodev_enqueue_burst()
     646                 :            :  */
     647                 :            : 
     648                 :            : /** Crypto device queue pair configuration structure. */
     649                 :            : /* Structure rte_cryptodev_qp_conf 8<*/
     650                 :            : struct rte_cryptodev_qp_conf {
     651                 :            :         uint32_t nb_descriptors; /**< Number of descriptors per queue pair */
     652                 :            :         struct rte_mempool *mp_session;
     653                 :            :         /**< The mempool for creating session in sessionless mode */
     654                 :            :         uint8_t priority;
     655                 :            :         /**< Priority for this queue pair relative to other queue pairs.
     656                 :            :          *
     657                 :            :          * The requested priority should in the range of
     658                 :            :          * [@ref RTE_CRYPTODEV_QP_PRIORITY_HIGHEST, @ref RTE_CRYPTODEV_QP_PRIORITY_LOWEST].
     659                 :            :          * The implementation may normalize the requested priority to
     660                 :            :          * device supported priority value.
     661                 :            :          */
     662                 :            : };
     663                 :            : /* >8 End of structure rte_cryptodev_qp_conf. */
     664                 :            : 
     665                 :            : /**
     666                 :            :  * Function type used for processing crypto ops when enqueue/dequeue burst is
     667                 :            :  * called.
     668                 :            :  *
     669                 :            :  * The callback function is called on enqueue/dequeue burst immediately.
     670                 :            :  *
     671                 :            :  * @param       dev_id          The identifier of the device.
     672                 :            :  * @param       qp_id           The index of the queue pair on which ops are
     673                 :            :  *                              enqueued/dequeued. The value must be in the
     674                 :            :  *                              range [0, nb_queue_pairs - 1] previously
     675                 :            :  *                              supplied to *rte_cryptodev_configure*.
     676                 :            :  * @param       ops             The address of an array of *nb_ops* pointers
     677                 :            :  *                              to *rte_crypto_op* structures which contain
     678                 :            :  *                              the crypto operations to be processed.
     679                 :            :  * @param       nb_ops          The number of operations to process.
     680                 :            :  * @param       user_param      The arbitrary user parameter passed in by the
     681                 :            :  *                              application when the callback was originally
     682                 :            :  *                              registered.
     683                 :            :  * @return                      The number of ops to be enqueued to the
     684                 :            :  *                              crypto device.
     685                 :            :  */
     686                 :            : typedef uint16_t (*rte_cryptodev_callback_fn)(uint16_t dev_id, uint16_t qp_id,
     687                 :            :                 struct rte_crypto_op **ops, uint16_t nb_ops, void *user_param);
     688                 :            : 
     689                 :            : /**
     690                 :            :  * Typedef for application callback function to be registered by application
     691                 :            :  * software for notification of device events
     692                 :            :  *
     693                 :            :  * @param       dev_id  Crypto device identifier
     694                 :            :  * @param       event   Crypto device event to register for notification of.
     695                 :            :  * @param       cb_arg  User specified parameter to be passed as to passed to
     696                 :            :  *                      users callback function.
     697                 :            :  */
     698                 :            : typedef void (*rte_cryptodev_cb_fn)(uint8_t dev_id,
     699                 :            :                 enum rte_cryptodev_event_type event, void *cb_arg);
     700                 :            : 
     701                 :            : 
     702                 :            : /** Crypto Device statistics */
     703                 :            : struct rte_cryptodev_stats {
     704                 :            :         uint64_t enqueued_count;
     705                 :            :         /**< Count of all operations enqueued */
     706                 :            :         uint64_t dequeued_count;
     707                 :            :         /**< Count of all operations dequeued */
     708                 :            : 
     709                 :            :         uint64_t enqueue_err_count;
     710                 :            :         /**< Total error count on operations enqueued */
     711                 :            :         uint64_t dequeue_err_count;
     712                 :            :         /**< Total error count on operations dequeued */
     713                 :            : };
     714                 :            : 
     715                 :            : #define RTE_CRYPTODEV_NAME_MAX_LEN      (64)
     716                 :            : /**< Max length of name of crypto PMD */
     717                 :            : 
     718                 :            : /**
     719                 :            :  * Get the device identifier for the named crypto device.
     720                 :            :  *
     721                 :            :  * @param       name    device name to select the device structure.
     722                 :            :  *
     723                 :            :  * @return
     724                 :            :  *   - Returns crypto device identifier on success.
     725                 :            :  *   - Return -1 on failure to find named crypto device.
     726                 :            :  */
     727                 :            : int
     728                 :            : rte_cryptodev_get_dev_id(const char *name);
     729                 :            : 
     730                 :            : /**
     731                 :            :  * Get the crypto device name given a device identifier.
     732                 :            :  *
     733                 :            :  * @param dev_id
     734                 :            :  *   The identifier of the device
     735                 :            :  *
     736                 :            :  * @return
     737                 :            :  *   - Returns crypto device name.
     738                 :            :  *   - Returns NULL if crypto device is not present.
     739                 :            :  */
     740                 :            : const char *
     741                 :            : rte_cryptodev_name_get(uint8_t dev_id);
     742                 :            : 
     743                 :            : /**
     744                 :            :  * Get the total number of crypto devices that have been successfully
     745                 :            :  * initialised.
     746                 :            :  *
     747                 :            :  * @return
     748                 :            :  *   - The total number of usable crypto devices.
     749                 :            :  */
     750                 :            : uint8_t
     751                 :            : rte_cryptodev_count(void);
     752                 :            : 
     753                 :            : /**
     754                 :            :  * Get number of crypto device defined type.
     755                 :            :  *
     756                 :            :  * @param       driver_id       driver identifier.
     757                 :            :  *
     758                 :            :  * @return
     759                 :            :  *   Returns number of crypto device.
     760                 :            :  */
     761                 :            : uint8_t
     762                 :            : rte_cryptodev_device_count_by_driver(uint8_t driver_id);
     763                 :            : 
     764                 :            : /**
     765                 :            :  * Get number and identifiers of attached crypto devices that
     766                 :            :  * use the same crypto driver.
     767                 :            :  *
     768                 :            :  * @param       driver_name     driver name.
     769                 :            :  * @param       devices         output devices identifiers.
     770                 :            :  * @param       nb_devices      maximal number of devices.
     771                 :            :  *
     772                 :            :  * @return
     773                 :            :  *   Returns number of attached crypto device.
     774                 :            :  */
     775                 :            : uint8_t
     776                 :            : rte_cryptodev_devices_get(const char *driver_name, uint8_t *devices,
     777                 :            :                 uint8_t nb_devices);
     778                 :            : /*
     779                 :            :  * Return the NUMA socket to which a device is connected
     780                 :            :  *
     781                 :            :  * @param dev_id
     782                 :            :  *   The identifier of the device
     783                 :            :  * @return
     784                 :            :  *   The NUMA socket id to which the device is connected or
     785                 :            :  *   a default of zero if the socket could not be determined.
     786                 :            :  *   -1 if returned is the dev_id value is out of range.
     787                 :            :  */
     788                 :            : int
     789                 :            : rte_cryptodev_socket_id(uint8_t dev_id);
     790                 :            : 
     791                 :            : /** Crypto device configuration structure */
     792                 :            : /* Structure rte_cryptodev_config 8< */
     793                 :            : struct rte_cryptodev_config {
     794                 :            :         int socket_id;                  /**< Socket to allocate resources on */
     795                 :            :         uint16_t nb_queue_pairs;
     796                 :            :         /**< Number of queue pairs to configure on device */
     797                 :            :         uint64_t ff_disable;
     798                 :            :         /**< Feature flags to be disabled. Only the following features are
     799                 :            :          * allowed to be disabled,
     800                 :            :          *  - RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO
     801                 :            :          *  - RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO
     802                 :            :          *  - RTE_CRYTPODEV_FF_SECURITY
     803                 :            :          */
     804                 :            : };
     805                 :            : /* >8 End of structure rte_cryptodev_config. */
     806                 :            : 
     807                 :            : /**
     808                 :            :  * Configure a device.
     809                 :            :  *
     810                 :            :  * This function must be invoked first before any other function in the
     811                 :            :  * API. This function can also be re-invoked when a device is in the
     812                 :            :  * stopped state.
     813                 :            :  *
     814                 :            :  * @param       dev_id          The identifier of the device to configure.
     815                 :            :  * @param       config          The crypto device configuration structure.
     816                 :            :  *
     817                 :            :  * @return
     818                 :            :  *   - 0: Success, device configured.
     819                 :            :  *   - <0: Error code returned by the driver configuration function.
     820                 :            :  */
     821                 :            : int
     822                 :            : rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config);
     823                 :            : 
     824                 :            : /**
     825                 :            :  * Start an device.
     826                 :            :  *
     827                 :            :  * The device start step is the last one and consists of setting the configured
     828                 :            :  * offload features and in starting the transmit and the receive units of the
     829                 :            :  * device.
     830                 :            :  * On success, all basic functions exported by the API (link status,
     831                 :            :  * receive/transmit, and so on) can be invoked.
     832                 :            :  *
     833                 :            :  * @param dev_id
     834                 :            :  *   The identifier of the device.
     835                 :            :  * @return
     836                 :            :  *   - 0: Success, device started.
     837                 :            :  *   - <0: Error code of the driver device start function.
     838                 :            :  */
     839                 :            : int
     840                 :            : rte_cryptodev_start(uint8_t dev_id);
     841                 :            : 
     842                 :            : /**
     843                 :            :  * Stop an device. The device can be restarted with a call to
     844                 :            :  * rte_cryptodev_start()
     845                 :            :  *
     846                 :            :  * @param       dev_id          The identifier of the device.
     847                 :            :  */
     848                 :            : void
     849                 :            : rte_cryptodev_stop(uint8_t dev_id);
     850                 :            : 
     851                 :            : /**
     852                 :            :  * Close an device. The device cannot be restarted!
     853                 :            :  *
     854                 :            :  * @param       dev_id          The identifier of the device.
     855                 :            :  *
     856                 :            :  * @return
     857                 :            :  *  - 0 on successfully closing device
     858                 :            :  *  - <0 on failure to close device
     859                 :            :  */
     860                 :            : int
     861                 :            : rte_cryptodev_close(uint8_t dev_id);
     862                 :            : 
     863                 :            : /**
     864                 :            :  * Allocate and set up a receive queue pair for a device.
     865                 :            :  *
     866                 :            :  *
     867                 :            :  * @param       dev_id          The identifier of the device.
     868                 :            :  * @param       queue_pair_id   The index of the queue pairs to set up. The
     869                 :            :  *                              value must be in the range [0, nb_queue_pair
     870                 :            :  *                              - 1] previously supplied to
     871                 :            :  *                              rte_cryptodev_configure().
     872                 :            :  * @param       qp_conf         The pointer to the configuration data to be
     873                 :            :  *                              used for the queue pair.
     874                 :            :  * @param       socket_id       The *socket_id* argument is the socket
     875                 :            :  *                              identifier in case of NUMA. The value can be
     876                 :            :  *                              *SOCKET_ID_ANY* if there is no NUMA constraint
     877                 :            :  *                              for the DMA memory allocated for the receive
     878                 :            :  *                              queue pair.
     879                 :            :  *
     880                 :            :  * @return
     881                 :            :  *   - 0: Success, queue pair correctly set up.
     882                 :            :  *   - <0: Queue pair configuration failed
     883                 :            :  */
     884                 :            : int
     885                 :            : rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id,
     886                 :            :                 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
     887                 :            : 
     888                 :            : /**
     889                 :            :  * @warning
     890                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
     891                 :            :  *
     892                 :            :  * Reset a queue pair for a device.
     893                 :            :  * The caller of this API must ensure that, there are no enqueues to the queue and there are no
     894                 :            :  * pending/inflight packets in the queue when the API is called.
     895                 :            :  * The API can reconfigure the queue pair when the queue pair configuration data is provided.
     896                 :            :  *
     897                 :            :  * @param       dev_id          The identifier of the device.
     898                 :            :  * @param       queue_pair_id   The index of the queue pairs to set up. The value must be in the
     899                 :            :  *                              range [0, nb_queue_pair - 1] previously supplied to
     900                 :            :  *                              rte_cryptodev_configure().
     901                 :            :  * @param       qp_conf         The pointer to configuration data to be used for the queue pair.
     902                 :            :  *                              It should be NULL, if the API is called from an interrupt context.
     903                 :            :  * @param       socket_id       The *socket_id* argument is the socket identifier in case of NUMA.
     904                 :            :  *                              The value can be *SOCKET_ID_ANY* if there is no NUMA constraint
     905                 :            :  *                              for the DMA memory allocated for the queue pair.
     906                 :            :  *
     907                 :            :  * @return
     908                 :            :  *   - 0:  Queue pair is reset successfully.
     909                 :            :  *   - ENOTSUP: If the operation is not supported by the PMD.
     910                 :            :  *   - <0: Queue pair reset failed
     911                 :            :  */
     912                 :            : __rte_experimental
     913                 :            : int
     914                 :            : rte_cryptodev_queue_pair_reset(uint8_t dev_id, uint16_t queue_pair_id,
     915                 :            :                 const struct rte_cryptodev_qp_conf *qp_conf, int socket_id);
     916                 :            : 
     917                 :            : /**
     918                 :            :  * Get the status of queue pairs setup on a specific crypto device
     919                 :            :  *
     920                 :            :  * @param       dev_id          Crypto device identifier.
     921                 :            :  * @param       queue_pair_id   The index of the queue pairs to set up. The
     922                 :            :  *                              value must be in the range [0, nb_queue_pair
     923                 :            :  *                              - 1] previously supplied to
     924                 :            :  *                              rte_cryptodev_configure().
     925                 :            :  * @return
     926                 :            :  *   - 0: qp was not configured
     927                 :            :  *       - 1: qp was configured
     928                 :            :  *       - -EINVAL: device was not configured
     929                 :            :  */
     930                 :            : int
     931                 :            : rte_cryptodev_get_qp_status(uint8_t dev_id, uint16_t queue_pair_id);
     932                 :            : 
     933                 :            : /**
     934                 :            :  * Get the number of queue pairs on a specific crypto device
     935                 :            :  *
     936                 :            :  * @param       dev_id          Crypto device identifier.
     937                 :            :  * @return
     938                 :            :  *   - The number of configured queue pairs.
     939                 :            :  */
     940                 :            : uint16_t
     941                 :            : rte_cryptodev_queue_pair_count(uint8_t dev_id);
     942                 :            : 
     943                 :            : 
     944                 :            : /**
     945                 :            :  * Retrieve the general I/O statistics of a device.
     946                 :            :  *
     947                 :            :  * @param       dev_id          The identifier of the device.
     948                 :            :  * @param       stats           A pointer to a structure of type
     949                 :            :  *                              *rte_cryptodev_stats* to be filled with the
     950                 :            :  *                              values of device counters.
     951                 :            :  * @return
     952                 :            :  *   - Zero if successful.
     953                 :            :  *   - Non-zero otherwise.
     954                 :            :  */
     955                 :            : int
     956                 :            : rte_cryptodev_stats_get(uint8_t dev_id, struct rte_cryptodev_stats *stats);
     957                 :            : 
     958                 :            : /**
     959                 :            :  * Reset the general I/O statistics of a device.
     960                 :            :  *
     961                 :            :  * @param       dev_id          The identifier of the device.
     962                 :            :  */
     963                 :            : void
     964                 :            : rte_cryptodev_stats_reset(uint8_t dev_id);
     965                 :            : 
     966                 :            : /**
     967                 :            :  * Retrieve the contextual information of a device.
     968                 :            :  *
     969                 :            :  * @param       dev_id          The identifier of the device.
     970                 :            :  * @param       dev_info        A pointer to a structure of type
     971                 :            :  *                              *rte_cryptodev_info* to be filled with the
     972                 :            :  *                              contextual information of the device.
     973                 :            :  *
     974                 :            :  * @note The capabilities field of dev_info is set to point to the first
     975                 :            :  * element of an array of struct rte_cryptodev_capabilities. The element after
     976                 :            :  * the last valid element has it's op field set to
     977                 :            :  * RTE_CRYPTO_OP_TYPE_UNDEFINED.
     978                 :            :  */
     979                 :            : void
     980                 :            : rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info);
     981                 :            : 
     982                 :            : 
     983                 :            : /**
     984                 :            :  * Register a callback function for specific device id.
     985                 :            :  *
     986                 :            :  * @param       dev_id          Device id.
     987                 :            :  * @param       event           Event interested.
     988                 :            :  * @param       cb_fn           User supplied callback function to be called.
     989                 :            :  * @param       cb_arg          Pointer to the parameters for the registered
     990                 :            :  *                              callback.
     991                 :            :  *
     992                 :            :  * @return
     993                 :            :  *  - On success, zero.
     994                 :            :  *  - On failure, a negative value.
     995                 :            :  */
     996                 :            : int
     997                 :            : rte_cryptodev_callback_register(uint8_t dev_id,
     998                 :            :                 enum rte_cryptodev_event_type event,
     999                 :            :                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
    1000                 :            : 
    1001                 :            : /**
    1002                 :            :  * Unregister a callback function for specific device id.
    1003                 :            :  *
    1004                 :            :  * @param       dev_id          The device identifier.
    1005                 :            :  * @param       event           Event interested.
    1006                 :            :  * @param       cb_fn           User supplied callback function to be called.
    1007                 :            :  * @param       cb_arg          Pointer to the parameters for the registered
    1008                 :            :  *                              callback.
    1009                 :            :  *
    1010                 :            :  * @return
    1011                 :            :  *  - On success, zero.
    1012                 :            :  *  - On failure, a negative value.
    1013                 :            :  */
    1014                 :            : int
    1015                 :            : rte_cryptodev_callback_unregister(uint8_t dev_id,
    1016                 :            :                 enum rte_cryptodev_event_type event,
    1017                 :            :                 rte_cryptodev_cb_fn cb_fn, void *cb_arg);
    1018                 :            : 
    1019                 :            : /**
    1020                 :            :  * @warning
    1021                 :            :  * @b EXPERIMENTAL: this API may change without prior notice.
    1022                 :            :  *
    1023                 :            :  * Query a cryptodev queue pair if there are pending RTE_CRYPTODEV_EVENT_ERROR
    1024                 :            :  * events.
    1025                 :            :  *
    1026                 :            :  * @param          dev_id       The device identifier.
    1027                 :            :  * @param          qp_id        Queue pair index to be queried.
    1028                 :            :  *
    1029                 :            :  * @return
    1030                 :            :  *   - 1 if requested queue has a pending event.
    1031                 :            :  *   - 0 if no pending event is found.
    1032                 :            :  *   - a negative value on failure
    1033                 :            :  */
    1034                 :            : __rte_experimental
    1035                 :            : int
    1036                 :            : rte_cryptodev_queue_pair_event_error_query(uint8_t dev_id, uint16_t qp_id);
    1037                 :            : 
    1038                 :            : struct rte_cryptodev_callback;
    1039                 :            : 
    1040                 :            : /** Structure to keep track of registered callbacks */
    1041                 :            : RTE_TAILQ_HEAD(rte_cryptodev_cb_list, rte_cryptodev_callback);
    1042                 :            : 
    1043                 :            : /**
    1044                 :            :  * Structure used to hold information about the callbacks to be called for a
    1045                 :            :  * queue pair on enqueue/dequeue.
    1046                 :            :  */
    1047                 :            : struct rte_cryptodev_cb {
    1048                 :            :         RTE_ATOMIC(struct rte_cryptodev_cb *) next;
    1049                 :            :         /**< Pointer to next callback */
    1050                 :            :         rte_cryptodev_callback_fn fn;
    1051                 :            :         /**< Pointer to callback function */
    1052                 :            :         void *arg;
    1053                 :            :         /**< Pointer to argument */
    1054                 :            : };
    1055                 :            : 
    1056                 :            : /**
    1057                 :            :  * @internal
    1058                 :            :  * Structure used to hold information about the RCU for a queue pair.
    1059                 :            :  */
    1060                 :            : struct rte_cryptodev_cb_rcu {
    1061                 :            :         RTE_ATOMIC(struct rte_cryptodev_cb *) next;
    1062                 :            :         /**< Pointer to next callback */
    1063                 :            :         struct rte_rcu_qsbr *qsbr;
    1064                 :            :         /**< RCU QSBR variable per queue pair */
    1065                 :            : };
    1066                 :            : 
    1067                 :            : /**
    1068                 :            :  * Get the security context for the cryptodev.
    1069                 :            :  *
    1070                 :            :  * @param dev_id
    1071                 :            :  *   The device identifier.
    1072                 :            :  * @return
    1073                 :            :  *   - NULL on error.
    1074                 :            :  *   - Pointer to security context on success.
    1075                 :            :  */
    1076                 :            : void *
    1077                 :            : rte_cryptodev_get_sec_ctx(uint8_t dev_id);
    1078                 :            : 
    1079                 :            : /**
    1080                 :            :  * Create a symmetric session mempool.
    1081                 :            :  *
    1082                 :            :  * @param name
    1083                 :            :  *   The unique mempool name.
    1084                 :            :  * @param nb_elts
    1085                 :            :  *   The number of elements in the mempool.
    1086                 :            :  * @param elt_size
    1087                 :            :  *   The size of the element. This should be the size of the cryptodev PMD
    1088                 :            :  *   session private data obtained through
    1089                 :            :  *   rte_cryptodev_sym_get_private_session_size() function call.
    1090                 :            :  *   For the user who wants to use the same mempool for heterogeneous PMDs
    1091                 :            :  *   this value should be the maximum value of their private session sizes.
    1092                 :            :  *   Please note the created mempool will have bigger elt size than this
    1093                 :            :  *   value as necessary session header and the possible padding are filled
    1094                 :            :  *   into each elt.
    1095                 :            :  * @param cache_size
    1096                 :            :  *   The number of per-lcore cache elements
    1097                 :            :  * @param priv_size
    1098                 :            :  *   The private data size of each session.
    1099                 :            :  * @param socket_id
    1100                 :            :  *   The *socket_id* argument is the socket identifier in the case of
    1101                 :            :  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
    1102                 :            :  *   constraint for the reserved zone.
    1103                 :            :  *
    1104                 :            :  * @return
    1105                 :            :  *  - On success returns the created session mempool pointer
    1106                 :            :  *  - On failure returns NULL
    1107                 :            :  */
    1108                 :            : struct rte_mempool *
    1109                 :            : rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts,
    1110                 :            :         uint32_t elt_size, uint32_t cache_size, uint16_t priv_size,
    1111                 :            :         int socket_id);
    1112                 :            : 
    1113                 :            : 
    1114                 :            : /**
    1115                 :            :  * Create an asymmetric session mempool.
    1116                 :            :  *
    1117                 :            :  * @param name
    1118                 :            :  *   The unique mempool name.
    1119                 :            :  * @param nb_elts
    1120                 :            :  *   The number of elements in the mempool.
    1121                 :            :  * @param cache_size
    1122                 :            :  *   The number of per-lcore cache elements
    1123                 :            :  * @param user_data_size
    1124                 :            :  *   The size of user data to be placed after session private data.
    1125                 :            :  * @param socket_id
    1126                 :            :  *   The *socket_id* argument is the socket identifier in the case of
    1127                 :            :  *   NUMA. The value can be *SOCKET_ID_ANY* if there is no NUMA
    1128                 :            :  *   constraint for the reserved zone.
    1129                 :            :  *
    1130                 :            :  * @return
    1131                 :            :  *  - On success return mempool
    1132                 :            :  *  - On failure returns NULL
    1133                 :            :  */
    1134                 :            : struct rte_mempool *
    1135                 :            : rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts,
    1136                 :            :         uint32_t cache_size, uint16_t user_data_size, int socket_id);
    1137                 :            : 
    1138                 :            : /**
    1139                 :            :  * Create symmetric crypto session and fill out private data for the device id,
    1140                 :            :  * based on its device type.
    1141                 :            :  *
    1142                 :            :  * @param   dev_id   ID of device that we want the session to be used on
    1143                 :            :  * @param   xforms   Symmetric crypto transform operations to apply on flow
    1144                 :            :  *                   processed with this session
    1145                 :            :  * @param   mp       Mempool to allocate symmetric session objects from
    1146                 :            :  *
    1147                 :            :  * @return
    1148                 :            :  *  - On success return pointer to sym-session.
    1149                 :            :  *  - On failure returns NULL and rte_errno is set to the error code:
    1150                 :            :  *    - EINVAL on invalid arguments.
    1151                 :            :  *    - ENOMEM on memory error for session allocation.
    1152                 :            :  *    - ENOTSUP if device doesn't support session configuration.
    1153                 :            :  */
    1154                 :            : void *
    1155                 :            : rte_cryptodev_sym_session_create(uint8_t dev_id,
    1156                 :            :                 struct rte_crypto_sym_xform *xforms,
    1157                 :            :                 struct rte_mempool *mp);
    1158                 :            : /**
    1159                 :            :  * Create and initialise an asymmetric crypto session structure.
    1160                 :            :  * Calls the PMD to configure the private session data.
    1161                 :            :  *
    1162                 :            :  * @param   dev_id   ID of device that we want the session to be used on
    1163                 :            :  * @param   xforms   Asymmetric crypto transform operations to apply on flow
    1164                 :            :  *                   processed with this session
    1165                 :            :  * @param   mp       mempool to allocate asymmetric session
    1166                 :            :  *                   objects from
    1167                 :            :  * @param   session  void ** for session to be used
    1168                 :            :  *
    1169                 :            :  * @return
    1170                 :            :  *  - 0 on success.
    1171                 :            :  *  - -EINVAL on invalid arguments.
    1172                 :            :  *  - -ENOMEM on memory error for session allocation.
    1173                 :            :  *  - -ENOTSUP if device doesn't support session configuration.
    1174                 :            :  */
    1175                 :            : int
    1176                 :            : rte_cryptodev_asym_session_create(uint8_t dev_id,
    1177                 :            :                 struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp,
    1178                 :            :                 void **session);
    1179                 :            : 
    1180                 :            : /**
    1181                 :            :  * Frees session for the device id and returning it to its mempool.
    1182                 :            :  * It is the application's responsibility to ensure that the session
    1183                 :            :  * is not still in-flight operations using it.
    1184                 :            :  *
    1185                 :            :  * @param   dev_id   ID of device that uses the session.
    1186                 :            :  * @param   sess     Session header to be freed.
    1187                 :            :  *
    1188                 :            :  * @return
    1189                 :            :  *  - 0 if successful.
    1190                 :            :  *  - -EINVAL if session is NULL or the mismatched device ids.
    1191                 :            :  */
    1192                 :            : int
    1193                 :            : rte_cryptodev_sym_session_free(uint8_t dev_id,
    1194                 :            :         void *sess);
    1195                 :            : 
    1196                 :            : /**
    1197                 :            :  * Clears and frees asymmetric crypto session header and private data,
    1198                 :            :  * returning it to its original mempool.
    1199                 :            :  *
    1200                 :            :  * @param   dev_id   ID of device that uses the asymmetric session.
    1201                 :            :  * @param   sess     Session header to be freed.
    1202                 :            :  *
    1203                 :            :  * @return
    1204                 :            :  *  - 0 if successful.
    1205                 :            :  *  - -EINVAL if device is invalid or session is NULL.
    1206                 :            :  */
    1207                 :            : int
    1208                 :            : rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess);
    1209                 :            : 
    1210                 :            : /**
    1211                 :            :  * Get the size of the asymmetric session header.
    1212                 :            :  *
    1213                 :            :  * @return
    1214                 :            :  *   Size of the asymmetric header session.
    1215                 :            :  */
    1216                 :            : unsigned int
    1217                 :            : rte_cryptodev_asym_get_header_session_size(void);
    1218                 :            : 
    1219                 :            : /**
    1220                 :            :  * Get the size of the private symmetric session data
    1221                 :            :  * for a device.
    1222                 :            :  *
    1223                 :            :  * @param       dev_id          The device identifier.
    1224                 :            :  *
    1225                 :            :  * @return
    1226                 :            :  *   - Size of the private data, if successful
    1227                 :            :  *   - 0 if device is invalid or does not have private
    1228                 :            :  *   symmetric session
    1229                 :            :  */
    1230                 :            : unsigned int
    1231                 :            : rte_cryptodev_sym_get_private_session_size(uint8_t dev_id);
    1232                 :            : 
    1233                 :            : /**
    1234                 :            :  * Get the size of the private data for asymmetric session
    1235                 :            :  * on device
    1236                 :            :  *
    1237                 :            :  * @param       dev_id          The device identifier.
    1238                 :            :  *
    1239                 :            :  * @return
    1240                 :            :  *   - Size of the asymmetric private data, if successful
    1241                 :            :  *   - 0 if device is invalid or does not have private session
    1242                 :            :  */
    1243                 :            : unsigned int
    1244                 :            : rte_cryptodev_asym_get_private_session_size(uint8_t dev_id);
    1245                 :            : 
    1246                 :            : /**
    1247                 :            :  * Validate if the crypto device index is valid attached crypto device.
    1248                 :            :  *
    1249                 :            :  * @param       dev_id  Crypto device index.
    1250                 :            :  *
    1251                 :            :  * @return
    1252                 :            :  *   - If the device index is valid (1) or not (0).
    1253                 :            :  */
    1254                 :            : unsigned int
    1255                 :            : rte_cryptodev_is_valid_dev(uint8_t dev_id);
    1256                 :            : 
    1257                 :            : /**
    1258                 :            :  * Provide driver identifier.
    1259                 :            :  *
    1260                 :            :  * @param name
    1261                 :            :  *   The pointer to a driver name.
    1262                 :            :  * @return
    1263                 :            :  *  The driver type identifier or -1 if no driver found
    1264                 :            :  */
    1265                 :            : int rte_cryptodev_driver_id_get(const char *name);
    1266                 :            : 
    1267                 :            : /**
    1268                 :            :  * Provide driver name.
    1269                 :            :  *
    1270                 :            :  * @param driver_id
    1271                 :            :  *   The driver identifier.
    1272                 :            :  * @return
    1273                 :            :  *  The driver name or null if no driver found
    1274                 :            :  */
    1275                 :            : const char *rte_cryptodev_driver_name_get(uint8_t driver_id);
    1276                 :            : 
    1277                 :            : /**
    1278                 :            :  * Store user data in a session.
    1279                 :            :  *
    1280                 :            :  * @param       sess            Session pointer allocated by
    1281                 :            :  *                              *rte_cryptodev_sym_session_create*.
    1282                 :            :  * @param       data            Pointer to the user data.
    1283                 :            :  * @param       size            Size of the user data.
    1284                 :            :  *
    1285                 :            :  * @return
    1286                 :            :  *  - On success, zero.
    1287                 :            :  *  - On failure, a negative value.
    1288                 :            :  */
    1289                 :            : int
    1290                 :            : rte_cryptodev_sym_session_set_user_data(void *sess,
    1291                 :            :                                         void *data,
    1292                 :            :                                         uint16_t size);
    1293                 :            : 
    1294                 :            : #define CRYPTO_SESS_OPAQUE_DATA_OFF 0
    1295                 :            : /**
    1296                 :            :  * Get opaque data from session handle
    1297                 :            :  */
    1298                 :            : static inline uint64_t
    1299                 :            : rte_cryptodev_sym_session_opaque_data_get(void *sess)
    1300                 :            : {
    1301                 :          0 :         return *((uint64_t *)sess + CRYPTO_SESS_OPAQUE_DATA_OFF);
    1302                 :            : }
    1303                 :            : 
    1304                 :            : /**
    1305                 :            :  * Set opaque data in session handle
    1306                 :            :  */
    1307                 :            : static inline void
    1308                 :            : rte_cryptodev_sym_session_opaque_data_set(void *sess, uint64_t opaque)
    1309                 :            : {
    1310                 :            :         uint64_t *data;
    1311                 :            :         data = (((uint64_t *)sess) + CRYPTO_SESS_OPAQUE_DATA_OFF);
    1312                 :          0 :         *data = opaque;
    1313                 :          0 : }
    1314                 :            : 
    1315                 :            : /**
    1316                 :            :  * Get user data stored in a session.
    1317                 :            :  *
    1318                 :            :  * @param       sess            Session pointer allocated by
    1319                 :            :  *                              *rte_cryptodev_sym_session_create*.
    1320                 :            :  *
    1321                 :            :  * @return
    1322                 :            :  *  - On success return pointer to user data.
    1323                 :            :  *  - On failure returns NULL.
    1324                 :            :  */
    1325                 :            : void *
    1326                 :            : rte_cryptodev_sym_session_get_user_data(void *sess);
    1327                 :            : 
    1328                 :            : /**
    1329                 :            :  * Store user data in an asymmetric session.
    1330                 :            :  *
    1331                 :            :  * @param       sess            Session pointer allocated by
    1332                 :            :  *                              *rte_cryptodev_asym_session_create*.
    1333                 :            :  * @param       data            Pointer to the user data.
    1334                 :            :  * @param       size            Size of the user data.
    1335                 :            :  *
    1336                 :            :  * @return
    1337                 :            :  *  - On success, zero.
    1338                 :            :  *  - -EINVAL if the session pointer is invalid.
    1339                 :            :  *  - -ENOMEM if the available user data size is smaller than the size parameter.
    1340                 :            :  */
    1341                 :            : int
    1342                 :            : rte_cryptodev_asym_session_set_user_data(void *sess, void *data, uint16_t size);
    1343                 :            : 
    1344                 :            : /**
    1345                 :            :  * Get user data stored in an asymmetric session.
    1346                 :            :  *
    1347                 :            :  * @param       sess            Session pointer allocated by
    1348                 :            :  *                              *rte_cryptodev_asym_session_create*.
    1349                 :            :  *
    1350                 :            :  * @return
    1351                 :            :  *  - On success return pointer to user data.
    1352                 :            :  *  - On failure returns NULL.
    1353                 :            :  */
    1354                 :            : void *
    1355                 :            : rte_cryptodev_asym_session_get_user_data(void *sess);
    1356                 :            : 
    1357                 :            : /**
    1358                 :            :  * Perform actual crypto processing (encrypt/digest or auth/decrypt)
    1359                 :            :  * on user provided data.
    1360                 :            :  *
    1361                 :            :  * @param       dev_id  The device identifier.
    1362                 :            :  * @param       sess    Cryptodev session structure
    1363                 :            :  * @param       ofs     Start and stop offsets for auth and cipher operations
    1364                 :            :  * @param       vec     Vectorized operation descriptor
    1365                 :            :  *
    1366                 :            :  * @return
    1367                 :            :  *  - Returns number of successfully processed packets.
    1368                 :            :  */
    1369                 :            : uint32_t
    1370                 :            : rte_cryptodev_sym_cpu_crypto_process(uint8_t dev_id,
    1371                 :            :         void *sess, union rte_crypto_sym_ofs ofs,
    1372                 :            :         struct rte_crypto_sym_vec *vec);
    1373                 :            : 
    1374                 :            : /**
    1375                 :            :  * Get the size of the raw data-path context buffer.
    1376                 :            :  *
    1377                 :            :  * @param       dev_id          The device identifier.
    1378                 :            :  *
    1379                 :            :  * @return
    1380                 :            :  *   - If the device supports raw data-path APIs, return the context size.
    1381                 :            :  *   - If the device does not support the APIs, return -1.
    1382                 :            :  */
    1383                 :            : int
    1384                 :            : rte_cryptodev_get_raw_dp_ctx_size(uint8_t dev_id);
    1385                 :            : 
    1386                 :            : /**
    1387                 :            :  * Set session event meta data
    1388                 :            :  *
    1389                 :            :  * @param       dev_id          The device identifier.
    1390                 :            :  * @param       sess            Crypto or security session.
    1391                 :            :  * @param       op_type         Operation type.
    1392                 :            :  * @param       sess_type       Session type.
    1393                 :            :  * @param       ev_mdata        Pointer to the event crypto meta data
    1394                 :            :  *                              (aka *union rte_event_crypto_metadata*)
    1395                 :            :  * @param       size            Size of ev_mdata.
    1396                 :            :  *
    1397                 :            :  * @return
    1398                 :            :  *  - On success, zero.
    1399                 :            :  *  - On failure, a negative value.
    1400                 :            :  */
    1401                 :            : int
    1402                 :            : rte_cryptodev_session_event_mdata_set(uint8_t dev_id, void *sess,
    1403                 :            :         enum rte_crypto_op_type op_type,
    1404                 :            :         enum rte_crypto_op_sess_type sess_type,
    1405                 :            :         void *ev_mdata, uint16_t size);
    1406                 :            : 
    1407                 :            : /**
    1408                 :            :  * Union of different crypto session types, including session-less xform
    1409                 :            :  * pointer.
    1410                 :            :  */
    1411                 :            : union rte_cryptodev_session_ctx {void *crypto_sess;
    1412                 :            :         struct rte_crypto_sym_xform *xform;
    1413                 :            :         struct rte_security_session *sec_sess;
    1414                 :            : };
    1415                 :            : 
    1416                 :            : /**
    1417                 :            :  * Enqueue a vectorized operation descriptor into the device queue but the
    1418                 :            :  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
    1419                 :            :  * is called.
    1420                 :            :  *
    1421                 :            :  * @param       qp              Driver specific queue pair data.
    1422                 :            :  * @param       drv_ctx         Driver specific context data.
    1423                 :            :  * @param       vec             Vectorized operation descriptor.
    1424                 :            :  * @param       ofs             Start and stop offsets for auth and cipher
    1425                 :            :  *                              operations.
    1426                 :            :  * @param       user_data       The array of user data for dequeue later.
    1427                 :            :  * @param       enqueue_status  Driver written value to specify the
    1428                 :            :  *                              enqueue status. Possible values:
    1429                 :            :  *                              - 1: The number of operations returned are
    1430                 :            :  *                                   enqueued successfully.
    1431                 :            :  *                              - 0: The number of operations returned are
    1432                 :            :  *                                   cached into the queue but are not processed
    1433                 :            :  *                                   until rte_cryptodev_raw_enqueue_done() is
    1434                 :            :  *                                   called.
    1435                 :            :  *                              - negative integer: Error occurred.
    1436                 :            :  * @return
    1437                 :            :  *   - The number of operations in the descriptor successfully enqueued or
    1438                 :            :  *     cached into the queue but not enqueued yet, depends on the
    1439                 :            :  *     "enqueue_status" value.
    1440                 :            :  */
    1441                 :            : typedef uint32_t (*cryptodev_sym_raw_enqueue_burst_t)(
    1442                 :            :         void *qp, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
    1443                 :            :         union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status);
    1444                 :            : 
    1445                 :            : /**
    1446                 :            :  * Enqueue single raw data vector into the device queue but the driver may or
    1447                 :            :  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
    1448                 :            :  *
    1449                 :            :  * @param       qp              Driver specific queue pair data.
    1450                 :            :  * @param       drv_ctx         Driver specific context data.
    1451                 :            :  * @param       data_vec        The buffer data vector.
    1452                 :            :  * @param       n_data_vecs     Number of buffer data vectors.
    1453                 :            :  * @param       ofs             Start and stop offsets for auth and cipher
    1454                 :            :  *                              operations.
    1455                 :            :  * @param       iv              IV virtual and IOVA addresses
    1456                 :            :  * @param       digest          digest virtual and IOVA addresses
    1457                 :            :  * @param       aad_or_auth_iv  AAD or auth IV virtual and IOVA addresses,
    1458                 :            :  *                              depends on the algorithm used.
    1459                 :            :  * @param       user_data       The user data.
    1460                 :            :  * @return
    1461                 :            :  *   - 1: The data vector is enqueued successfully.
    1462                 :            :  *   - 0: The data vector is cached into the queue but is not processed
    1463                 :            :  *        until rte_cryptodev_raw_enqueue_done() is called.
    1464                 :            :  *   - negative integer: failure.
    1465                 :            :  */
    1466                 :            : typedef int (*cryptodev_sym_raw_enqueue_t)(
    1467                 :            :         void *qp, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
    1468                 :            :         uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
    1469                 :            :         struct rte_crypto_va_iova_ptr *iv,
    1470                 :            :         struct rte_crypto_va_iova_ptr *digest,
    1471                 :            :         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
    1472                 :            :         void *user_data);
    1473                 :            : 
    1474                 :            : /**
    1475                 :            :  * Inform the cryptodev queue pair to start processing or finish dequeuing all
    1476                 :            :  * enqueued/dequeued operations.
    1477                 :            :  *
    1478                 :            :  * @param       qp              Driver specific queue pair data.
    1479                 :            :  * @param       drv_ctx         Driver specific context data.
    1480                 :            :  * @param       n               The total number of processed operations.
    1481                 :            :  * @return
    1482                 :            :  *   - On success return 0.
    1483                 :            :  *   - On failure return negative integer.
    1484                 :            :  */
    1485                 :            : typedef int (*cryptodev_sym_raw_operation_done_t)(void *qp, uint8_t *drv_ctx,
    1486                 :            :         uint32_t n);
    1487                 :            : 
    1488                 :            : /**
    1489                 :            :  * Typedef that the user provided for the driver to get the dequeue count.
    1490                 :            :  * The function may return a fixed number or the number parsed from the user
    1491                 :            :  * data stored in the first processed operation.
    1492                 :            :  *
    1493                 :            :  * @param       user_data       Dequeued user data.
    1494                 :            :  * @return
    1495                 :            :  *  - The number of operations to be dequeued.
    1496                 :            :  */
    1497                 :            : typedef uint32_t (*rte_cryptodev_raw_get_dequeue_count_t)(void *user_data);
    1498                 :            : 
    1499                 :            : /**
    1500                 :            :  * Typedef that the user provided to deal with post dequeue operation, such
    1501                 :            :  * as filling status.
    1502                 :            :  *
    1503                 :            :  * @param       user_data       Dequeued user data.
    1504                 :            :  * @param       index           Index number of the processed descriptor.
    1505                 :            :  * @param       is_op_success   Operation status provided by the driver.
    1506                 :            :  */
    1507                 :            : typedef void (*rte_cryptodev_raw_post_dequeue_t)(void *user_data,
    1508                 :            :         uint32_t index, uint8_t is_op_success);
    1509                 :            : 
    1510                 :            : /**
    1511                 :            :  * Dequeue a burst of symmetric crypto processing.
    1512                 :            :  *
    1513                 :            :  * @param       qp                      Driver specific queue pair data.
    1514                 :            :  * @param       drv_ctx                 Driver specific context data.
    1515                 :            :  * @param       get_dequeue_count       User provided callback function to
    1516                 :            :  *                                      obtain dequeue operation count.
    1517                 :            :  * @param       max_nb_to_dequeue       When get_dequeue_count is NULL this
    1518                 :            :  *                                      value is used to pass the maximum
    1519                 :            :  *                                      number of operations to be dequeued.
    1520                 :            :  * @param       post_dequeue            User provided callback function to
    1521                 :            :  *                                      post-process a dequeued operation.
    1522                 :            :  * @param       out_user_data           User data pointer array to be retrieve
    1523                 :            :  *                                      from device queue. In case of
    1524                 :            :  *                                      *is_user_data_array* is set there
    1525                 :            :  *                                      should be enough room to store all
    1526                 :            :  *                                      user data.
    1527                 :            :  * @param       is_user_data_array      Set 1 if every dequeued user data will
    1528                 :            :  *                                      be written into out_user_data array.
    1529                 :            :  *                                      Set 0 if only the first user data will
    1530                 :            :  *                                      be written into out_user_data array.
    1531                 :            :  * @param       n_success               Driver written value to specific the
    1532                 :            :  *                                      total successful operations count.
    1533                 :            :  * @param       dequeue_status          Driver written value to specify the
    1534                 :            :  *                                      dequeue status. Possible values:
    1535                 :            :  *                                      - 1: Successfully dequeued the number
    1536                 :            :  *                                           of operations returned. The user
    1537                 :            :  *                                           data previously set during enqueue
    1538                 :            :  *                                           is stored in the "out_user_data".
    1539                 :            :  *                                      - 0: The number of operations returned
    1540                 :            :  *                                           are completed and the user data is
    1541                 :            :  *                                           stored in the "out_user_data", but
    1542                 :            :  *                                           they are not freed from the queue
    1543                 :            :  *                                           until
    1544                 :            :  *                                           rte_cryptodev_raw_dequeue_done()
    1545                 :            :  *                                           is called.
    1546                 :            :  *                                      - negative integer: Error occurred.
    1547                 :            :  * @return
    1548                 :            :  *   - The number of operations dequeued or completed but not freed from the
    1549                 :            :  *     queue, depends on "dequeue_status" value.
    1550                 :            :  */
    1551                 :            : typedef uint32_t (*cryptodev_sym_raw_dequeue_burst_t)(void *qp,
    1552                 :            :         uint8_t *drv_ctx,
    1553                 :            :         rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
    1554                 :            :         uint32_t max_nb_to_dequeue,
    1555                 :            :         rte_cryptodev_raw_post_dequeue_t post_dequeue,
    1556                 :            :         void **out_user_data, uint8_t is_user_data_array,
    1557                 :            :         uint32_t *n_success, int *dequeue_status);
    1558                 :            : 
    1559                 :            : /**
    1560                 :            :  * Dequeue a symmetric crypto processing.
    1561                 :            :  *
    1562                 :            :  * @param       qp                      Driver specific queue pair data.
    1563                 :            :  * @param       drv_ctx                 Driver specific context data.
    1564                 :            :  * @param       dequeue_status          Driver written value to specify the
    1565                 :            :  *                                      dequeue status. Possible values:
    1566                 :            :  *                                      - 1: Successfully dequeued a operation.
    1567                 :            :  *                                           The user data is returned.
    1568                 :            :  *                                      - 0: The first operation in the queue
    1569                 :            :  *                                           is completed and the user data
    1570                 :            :  *                                           previously set during enqueue is
    1571                 :            :  *                                           returned, but it is not freed from
    1572                 :            :  *                                           the queue until
    1573                 :            :  *                                           rte_cryptodev_raw_dequeue_done() is
    1574                 :            :  *                                           called.
    1575                 :            :  *                                      - negative integer: Error occurred.
    1576                 :            :  * @param       op_status               Driver written value to specify
    1577                 :            :  *                                      operation status.
    1578                 :            :  * @return
    1579                 :            :  *   - The user data pointer retrieved from device queue or NULL if no
    1580                 :            :  *     operation is ready for dequeue.
    1581                 :            :  */
    1582                 :            : typedef void * (*cryptodev_sym_raw_dequeue_t)(
    1583                 :            :                 void *qp, uint8_t *drv_ctx, int *dequeue_status,
    1584                 :            :                 enum rte_crypto_op_status *op_status);
    1585                 :            : 
    1586                 :            : /**
    1587                 :            :  * Context data for raw data-path API crypto process. The buffer of this
    1588                 :            :  * structure is to be allocated by the user application with the size equal
    1589                 :            :  * or bigger than rte_cryptodev_get_raw_dp_ctx_size() returned value.
    1590                 :            :  */
    1591                 :            : struct rte_crypto_raw_dp_ctx {
    1592                 :            :         void *qp_data;
    1593                 :            : 
    1594                 :            :         cryptodev_sym_raw_enqueue_t enqueue;
    1595                 :            :         cryptodev_sym_raw_enqueue_burst_t enqueue_burst;
    1596                 :            :         cryptodev_sym_raw_operation_done_t enqueue_done;
    1597                 :            :         cryptodev_sym_raw_dequeue_t dequeue;
    1598                 :            :         cryptodev_sym_raw_dequeue_burst_t dequeue_burst;
    1599                 :            :         cryptodev_sym_raw_operation_done_t dequeue_done;
    1600                 :            : 
    1601                 :            :         /* Driver specific context data */
    1602                 :            :         uint8_t drv_ctx_data[];
    1603                 :            : };
    1604                 :            : 
    1605                 :            : /**
    1606                 :            :  * Configure raw data-path context data.
    1607                 :            :  *
    1608                 :            :  * @param       dev_id          The device identifier.
    1609                 :            :  * @param       qp_id           The index of the queue pair from which to
    1610                 :            :  *                              retrieve processed packets. The value must be
    1611                 :            :  *                              in the range [0, nb_queue_pair - 1] previously
    1612                 :            :  *                              supplied to rte_cryptodev_configure().
    1613                 :            :  * @param       ctx             The raw data-path context data.
    1614                 :            :  * @param       sess_type       Session type.
    1615                 :            :  * @param       session_ctx     Session context data.
    1616                 :            :  * @param       is_update       Set 0 if it is to initialize the ctx.
    1617                 :            :  *                              Set 1 if ctx is initialized and only to update
    1618                 :            :  *                              session context data.
    1619                 :            :  * @return
    1620                 :            :  *   - On success return 0.
    1621                 :            :  *   - On failure return negative integer.
    1622                 :            :  *     - -EINVAL if input parameters are invalid.
    1623                 :            :  *     - -ENOTSUP if crypto device does not support raw DP operations with the
    1624                 :            :  *        provided session.
    1625                 :            :  */
    1626                 :            : int
    1627                 :            : rte_cryptodev_configure_raw_dp_ctx(uint8_t dev_id, uint16_t qp_id,
    1628                 :            :         struct rte_crypto_raw_dp_ctx *ctx,
    1629                 :            :         enum rte_crypto_op_sess_type sess_type,
    1630                 :            :         union rte_cryptodev_session_ctx session_ctx,
    1631                 :            :         uint8_t is_update);
    1632                 :            : 
    1633                 :            : /**
    1634                 :            :  * Enqueue a vectorized operation descriptor into the device queue but the
    1635                 :            :  * driver may or may not start processing until rte_cryptodev_raw_enqueue_done()
    1636                 :            :  * is called.
    1637                 :            :  *
    1638                 :            :  * @param       ctx             The initialized raw data-path context data.
    1639                 :            :  * @param       vec             Vectorized operation descriptor.
    1640                 :            :  * @param       ofs             Start and stop offsets for auth and cipher
    1641                 :            :  *                              operations.
    1642                 :            :  * @param       user_data       The array of user data for dequeue later.
    1643                 :            :  * @param       enqueue_status  Driver written value to specify the
    1644                 :            :  *                              enqueue status. Possible values:
    1645                 :            :  *                              - 1: The number of operations returned are
    1646                 :            :  *                                   enqueued successfully.
    1647                 :            :  *                              - 0: The number of operations returned are
    1648                 :            :  *                                   cached into the queue but are not processed
    1649                 :            :  *                                   until rte_cryptodev_raw_enqueue_done() is
    1650                 :            :  *                                   called.
    1651                 :            :  *                              - negative integer: Error occurred.
    1652                 :            :  * @return
    1653                 :            :  *   - The number of operations in the descriptor successfully enqueued or
    1654                 :            :  *     cached into the queue but not enqueued yet, depends on the
    1655                 :            :  *     "enqueue_status" value.
    1656                 :            :  */
    1657                 :            : uint32_t
    1658                 :            : rte_cryptodev_raw_enqueue_burst(struct rte_crypto_raw_dp_ctx *ctx,
    1659                 :            :         struct rte_crypto_sym_vec *vec, union rte_crypto_sym_ofs ofs,
    1660                 :            :         void **user_data, int *enqueue_status);
    1661                 :            : 
    1662                 :            : /**
    1663                 :            :  * Enqueue single raw data vector into the device queue but the driver may or
    1664                 :            :  * may not start processing until rte_cryptodev_raw_enqueue_done() is called.
    1665                 :            :  *
    1666                 :            :  * @param       ctx             The initialized raw data-path context data.
    1667                 :            :  * @param       data_vec        The buffer data vector.
    1668                 :            :  * @param       n_data_vecs     Number of buffer data vectors.
    1669                 :            :  * @param       ofs             Start and stop offsets for auth and cipher
    1670                 :            :  *                              operations.
    1671                 :            :  * @param       iv              IV virtual and IOVA addresses
    1672                 :            :  * @param       digest          digest virtual and IOVA addresses
    1673                 :            :  * @param       aad_or_auth_iv  AAD or auth IV virtual and IOVA addresses,
    1674                 :            :  *                              depends on the algorithm used.
    1675                 :            :  * @param       user_data       The user data.
    1676                 :            :  * @return
    1677                 :            :  *   - 1: The data vector is enqueued successfully.
    1678                 :            :  *   - 0: The data vector is cached into the queue but is not processed
    1679                 :            :  *        until rte_cryptodev_raw_enqueue_done() is called.
    1680                 :            :  *   - negative integer: failure.
    1681                 :            :  */
    1682                 :            : __rte_experimental
    1683                 :            : static __rte_always_inline int
    1684                 :            : rte_cryptodev_raw_enqueue(struct rte_crypto_raw_dp_ctx *ctx,
    1685                 :            :         struct rte_crypto_vec *data_vec, uint16_t n_data_vecs,
    1686                 :            :         union rte_crypto_sym_ofs ofs,
    1687                 :            :         struct rte_crypto_va_iova_ptr *iv,
    1688                 :            :         struct rte_crypto_va_iova_ptr *digest,
    1689                 :            :         struct rte_crypto_va_iova_ptr *aad_or_auth_iv,
    1690                 :            :         void *user_data)
    1691                 :            : {
    1692                 :            :         return (*ctx->enqueue)(ctx->qp_data, ctx->drv_ctx_data, data_vec,
    1693                 :            :                 n_data_vecs, ofs, iv, digest, aad_or_auth_iv, user_data);
    1694                 :            : }
    1695                 :            : 
    1696                 :            : /**
    1697                 :            :  * Start processing all enqueued operations from last
    1698                 :            :  * rte_cryptodev_configure_raw_dp_ctx() call.
    1699                 :            :  *
    1700                 :            :  * @param       ctx     The initialized raw data-path context data.
    1701                 :            :  * @param       n       The number of operations cached.
    1702                 :            :  * @return
    1703                 :            :  *   - On success return 0.
    1704                 :            :  *   - On failure return negative integer.
    1705                 :            :  */
    1706                 :            : int
    1707                 :            : rte_cryptodev_raw_enqueue_done(struct rte_crypto_raw_dp_ctx *ctx,
    1708                 :            :                 uint32_t n);
    1709                 :            : 
    1710                 :            : /**
    1711                 :            :  * Dequeue a burst of symmetric crypto processing.
    1712                 :            :  *
    1713                 :            :  * @param       ctx                     The initialized raw data-path context
    1714                 :            :  *                                      data.
    1715                 :            :  * @param       get_dequeue_count       User provided callback function to
    1716                 :            :  *                                      obtain dequeue operation count.
    1717                 :            :  * @param       max_nb_to_dequeue       When get_dequeue_count is NULL this
    1718                 :            :  *                                      value is used to pass the maximum
    1719                 :            :  *                                      number of operations to be dequeued.
    1720                 :            :  * @param       post_dequeue            User provided callback function to
    1721                 :            :  *                                      post-process a dequeued operation.
    1722                 :            :  * @param       out_user_data           User data pointer array to be retrieve
    1723                 :            :  *                                      from device queue. In case of
    1724                 :            :  *                                      *is_user_data_array* is set there
    1725                 :            :  *                                      should be enough room to store all
    1726                 :            :  *                                      user data.
    1727                 :            :  * @param       is_user_data_array      Set 1 if every dequeued user data will
    1728                 :            :  *                                      be written into out_user_data array.
    1729                 :            :  *                                      Set 0 if only the first user data will
    1730                 :            :  *                                      be written into out_user_data array.
    1731                 :            :  * @param       n_success               Driver written value to specific the
    1732                 :            :  *                                      total successful operations count.
    1733                 :            :  * @param       dequeue_status          Driver written value to specify the
    1734                 :            :  *                                      dequeue status. Possible values:
    1735                 :            :  *                                      - 1: Successfully dequeued the number
    1736                 :            :  *                                           of operations returned. The user
    1737                 :            :  *                                           data previously set during enqueue
    1738                 :            :  *                                           is stored in the "out_user_data".
    1739                 :            :  *                                      - 0: The number of operations returned
    1740                 :            :  *                                           are completed and the user data is
    1741                 :            :  *                                           stored in the "out_user_data", but
    1742                 :            :  *                                           they are not freed from the queue
    1743                 :            :  *                                           until
    1744                 :            :  *                                           rte_cryptodev_raw_dequeue_done()
    1745                 :            :  *                                           is called.
    1746                 :            :  *                                      - negative integer: Error occurred.
    1747                 :            :  * @return
    1748                 :            :  *   - The number of operations dequeued or completed but not freed from the
    1749                 :            :  *     queue, depends on "dequeue_status" value.
    1750                 :            :  */
    1751                 :            : uint32_t
    1752                 :            : rte_cryptodev_raw_dequeue_burst(struct rte_crypto_raw_dp_ctx *ctx,
    1753                 :            :         rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
    1754                 :            :         uint32_t max_nb_to_dequeue,
    1755                 :            :         rte_cryptodev_raw_post_dequeue_t post_dequeue,
    1756                 :            :         void **out_user_data, uint8_t is_user_data_array,
    1757                 :            :         uint32_t *n_success, int *dequeue_status);
    1758                 :            : 
    1759                 :            : /**
    1760                 :            :  * Dequeue a symmetric crypto processing.
    1761                 :            :  *
    1762                 :            :  * @param       ctx                     The initialized raw data-path context
    1763                 :            :  *                                      data.
    1764                 :            :  * @param       dequeue_status          Driver written value to specify the
    1765                 :            :  *                                      dequeue status. Possible values:
    1766                 :            :  *                                      - 1: Successfully dequeued a operation.
    1767                 :            :  *                                           The user data is returned.
    1768                 :            :  *                                      - 0: The first operation in the queue
    1769                 :            :  *                                           is completed and the user data
    1770                 :            :  *                                           previously set during enqueue is
    1771                 :            :  *                                           returned, but it is not freed from
    1772                 :            :  *                                           the queue until
    1773                 :            :  *                                           rte_cryptodev_raw_dequeue_done() is
    1774                 :            :  *                                           called.
    1775                 :            :  *                                      - negative integer: Error occurred.
    1776                 :            :  * @param       op_status               Driver written value to specify
    1777                 :            :  *                                      operation status.
    1778                 :            :  * @return
    1779                 :            :  *   - The user data pointer retrieved from device queue or NULL if no
    1780                 :            :  *     operation is ready for dequeue.
    1781                 :            :  */
    1782                 :            : __rte_experimental
    1783                 :            : static __rte_always_inline void *
    1784                 :            : rte_cryptodev_raw_dequeue(struct rte_crypto_raw_dp_ctx *ctx,
    1785                 :            :                 int *dequeue_status, enum rte_crypto_op_status *op_status)
    1786                 :            : {
    1787                 :            :         return (*ctx->dequeue)(ctx->qp_data, ctx->drv_ctx_data, dequeue_status,
    1788                 :            :                         op_status);
    1789                 :            : }
    1790                 :            : 
    1791                 :            : /**
    1792                 :            :  * Inform the queue pair dequeue operations is finished.
    1793                 :            :  *
    1794                 :            :  * @param       ctx     The initialized raw data-path context data.
    1795                 :            :  * @param       n       The number of operations.
    1796                 :            :  * @return
    1797                 :            :  *   - On success return 0.
    1798                 :            :  *   - On failure return negative integer.
    1799                 :            :  */
    1800                 :            : int
    1801                 :            : rte_cryptodev_raw_dequeue_done(struct rte_crypto_raw_dp_ctx *ctx,
    1802                 :            :                 uint32_t n);
    1803                 :            : 
    1804                 :            : /**
    1805                 :            :  * Add a user callback for a given crypto device and queue pair which will be
    1806                 :            :  * called on crypto ops enqueue.
    1807                 :            :  *
    1808                 :            :  * This API configures a function to be called for each burst of crypto ops
    1809                 :            :  * received on a given crypto device queue pair. The return value is a pointer
    1810                 :            :  * that can be used later to remove the callback using
    1811                 :            :  * rte_cryptodev_remove_enq_callback().
    1812                 :            :  *
    1813                 :            :  * Callbacks registered by application would not survive
    1814                 :            :  * rte_cryptodev_configure() as it reinitializes the callback list.
    1815                 :            :  * It is user responsibility to remove all installed callbacks before
    1816                 :            :  * calling rte_cryptodev_configure() to avoid possible memory leakage.
    1817                 :            :  * Application is expected to call add API after rte_cryptodev_configure().
    1818                 :            :  *
    1819                 :            :  * Multiple functions can be registered per queue pair & they are called
    1820                 :            :  * in the order they were added. The API does not restrict on maximum number
    1821                 :            :  * of callbacks.
    1822                 :            :  *
    1823                 :            :  * @param       dev_id          The identifier of the device.
    1824                 :            :  * @param       qp_id           The index of the queue pair on which ops are
    1825                 :            :  *                              to be enqueued for processing. The value
    1826                 :            :  *                              must be in the range [0, nb_queue_pairs - 1]
    1827                 :            :  *                              previously supplied to
    1828                 :            :  *                              *rte_cryptodev_configure*.
    1829                 :            :  * @param       cb_fn           The callback function
    1830                 :            :  * @param       cb_arg          A generic pointer parameter which will be passed
    1831                 :            :  *                              to each invocation of the callback function on
    1832                 :            :  *                              this crypto device and queue pair.
    1833                 :            :  *
    1834                 :            :  * @return
    1835                 :            :  *  - NULL on error & rte_errno will contain the error code.
    1836                 :            :  *  - On success, a pointer value which can later be used to remove the
    1837                 :            :  *    callback.
    1838                 :            :  */
    1839                 :            : struct rte_cryptodev_cb *
    1840                 :            : rte_cryptodev_add_enq_callback(uint8_t dev_id,
    1841                 :            :                                uint16_t qp_id,
    1842                 :            :                                rte_cryptodev_callback_fn cb_fn,
    1843                 :            :                                void *cb_arg);
    1844                 :            : 
    1845                 :            : /**
    1846                 :            :  * Remove a user callback function for given crypto device and queue pair.
    1847                 :            :  *
    1848                 :            :  * This function is used to remove enqueue callbacks that were added to a
    1849                 :            :  * crypto device queue pair using rte_cryptodev_add_enq_callback().
    1850                 :            :  *
    1851                 :            :  *
    1852                 :            :  *
    1853                 :            :  * @param       dev_id          The identifier of the device.
    1854                 :            :  * @param       qp_id           The index of the queue pair on which ops are
    1855                 :            :  *                              to be enqueued. The value must be in the
    1856                 :            :  *                              range [0, nb_queue_pairs - 1] previously
    1857                 :            :  *                              supplied to *rte_cryptodev_configure*.
    1858                 :            :  * @param       cb              Pointer to user supplied callback created via
    1859                 :            :  *                              rte_cryptodev_add_enq_callback().
    1860                 :            :  *
    1861                 :            :  * @return
    1862                 :            :  *   -  0: Success. Callback was removed.
    1863                 :            :  *   - <0: The dev_id or the qp_id is out of range, or the callback
    1864                 :            :  *         is NULL or not found for the crypto device queue pair.
    1865                 :            :  */
    1866                 :            : int rte_cryptodev_remove_enq_callback(uint8_t dev_id,
    1867                 :            :                                       uint16_t qp_id,
    1868                 :            :                                       struct rte_cryptodev_cb *cb);
    1869                 :            : 
    1870                 :            : /**
    1871                 :            :  * Add a user callback for a given crypto device and queue pair which will be
    1872                 :            :  * called on crypto ops dequeue.
    1873                 :            :  *
    1874                 :            :  * This API configures a function to be called for each burst of crypto ops
    1875                 :            :  * received on a given crypto device queue pair. The return value is a pointer
    1876                 :            :  * that can be used later to remove the callback using
    1877                 :            :  * rte_cryptodev_remove_deq_callback().
    1878                 :            :  *
    1879                 :            :  * Callbacks registered by application would not survive
    1880                 :            :  * rte_cryptodev_configure() as it reinitializes the callback list.
    1881                 :            :  * It is user responsibility to remove all installed callbacks before
    1882                 :            :  * calling rte_cryptodev_configure() to avoid possible memory leakage.
    1883                 :            :  * Application is expected to call add API after rte_cryptodev_configure().
    1884                 :            :  *
    1885                 :            :  * Multiple functions can be registered per queue pair & they are called
    1886                 :            :  * in the order they were added. The API does not restrict on maximum number
    1887                 :            :  * of callbacks.
    1888                 :            :  *
    1889                 :            :  * @param       dev_id          The identifier of the device.
    1890                 :            :  * @param       qp_id           The index of the queue pair on which ops are
    1891                 :            :  *                              to be dequeued. The value must be in the
    1892                 :            :  *                              range [0, nb_queue_pairs - 1] previously
    1893                 :            :  *                              supplied to *rte_cryptodev_configure*.
    1894                 :            :  * @param       cb_fn           The callback function
    1895                 :            :  * @param       cb_arg          A generic pointer parameter which will be passed
    1896                 :            :  *                              to each invocation of the callback function on
    1897                 :            :  *                              this crypto device and queue pair.
    1898                 :            :  *
    1899                 :            :  * @return
    1900                 :            :  *   - NULL on error & rte_errno will contain the error code.
    1901                 :            :  *   - On success, a pointer value which can later be used to remove the
    1902                 :            :  *     callback.
    1903                 :            :  */
    1904                 :            : struct rte_cryptodev_cb *
    1905                 :            : rte_cryptodev_add_deq_callback(uint8_t dev_id,
    1906                 :            :                                uint16_t qp_id,
    1907                 :            :                                rte_cryptodev_callback_fn cb_fn,
    1908                 :            :                                void *cb_arg);
    1909                 :            : 
    1910                 :            : /**
    1911                 :            :  * Remove a user callback function for given crypto device and queue pair.
    1912                 :            :  *
    1913                 :            :  * This function is used to remove dequeue callbacks that were added to a
    1914                 :            :  * crypto device queue pair using rte_cryptodev_add_deq_callback().
    1915                 :            :  *
    1916                 :            :  *
    1917                 :            :  *
    1918                 :            :  * @param       dev_id          The identifier of the device.
    1919                 :            :  * @param       qp_id           The index of the queue pair on which ops are
    1920                 :            :  *                              to be dequeued. The value must be in the
    1921                 :            :  *                              range [0, nb_queue_pairs - 1] previously
    1922                 :            :  *                              supplied to *rte_cryptodev_configure*.
    1923                 :            :  * @param       cb              Pointer to user supplied callback created via
    1924                 :            :  *                              rte_cryptodev_add_deq_callback().
    1925                 :            :  *
    1926                 :            :  * @return
    1927                 :            :  *   -  0: Success. Callback was removed.
    1928                 :            :  *   - <0: The dev_id or the qp_id is out of range, or the callback
    1929                 :            :  *         is NULL or not found for the crypto device queue pair.
    1930                 :            :  */
    1931                 :            : int rte_cryptodev_remove_deq_callback(uint8_t dev_id,
    1932                 :            :                                       uint16_t qp_id,
    1933                 :            :                                       struct rte_cryptodev_cb *cb);
    1934                 :            : 
    1935                 :            : #ifdef __cplusplus
    1936                 :            : }
    1937                 :            : #endif
    1938                 :            : 
    1939                 :            : #include "rte_cryptodev_core.h"
    1940                 :            : 
    1941                 :            : #ifdef __cplusplus
    1942                 :            : extern "C" {
    1943                 :            : #endif
    1944                 :            : 
    1945                 :            : /**
    1946                 :            :  *
    1947                 :            :  * Dequeue a burst of processed crypto operations from a queue on the crypto
    1948                 :            :  * device. The dequeued operation are stored in *rte_crypto_op* structures
    1949                 :            :  * whose pointers are supplied in the *ops* array.
    1950                 :            :  *
    1951                 :            :  * The rte_cryptodev_dequeue_burst() function returns the number of ops
    1952                 :            :  * actually dequeued, which is the number of *rte_crypto_op* data structures
    1953                 :            :  * effectively supplied into the *ops* array.
    1954                 :            :  *
    1955                 :            :  * A return value equal to *nb_ops* indicates that the queue contained
    1956                 :            :  * at least *nb_ops* operations, and this is likely to signify that other
    1957                 :            :  * processed operations remain in the devices output queue. Applications
    1958                 :            :  * implementing a "retrieve as many processed operations as possible" policy
    1959                 :            :  * can check this specific case and keep invoking the
    1960                 :            :  * rte_cryptodev_dequeue_burst() function until a value less than
    1961                 :            :  * *nb_ops* is returned.
    1962                 :            :  *
    1963                 :            :  * The rte_cryptodev_dequeue_burst() function does not provide any error
    1964                 :            :  * notification to avoid the corresponding overhead.
    1965                 :            :  *
    1966                 :            :  * @param       dev_id          The symmetric crypto device identifier
    1967                 :            :  * @param       qp_id           The index of the queue pair from which to
    1968                 :            :  *                              retrieve processed packets. The value must be
    1969                 :            :  *                              in the range [0, nb_queue_pair - 1] previously
    1970                 :            :  *                              supplied to rte_cryptodev_configure().
    1971                 :            :  * @param       ops             The address of an array of pointers to
    1972                 :            :  *                              *rte_crypto_op* structures that must be
    1973                 :            :  *                              large enough to store *nb_ops* pointers in it.
    1974                 :            :  * @param       nb_ops          The maximum number of operations to dequeue.
    1975                 :            :  *
    1976                 :            :  * @return
    1977                 :            :  *   - The number of operations actually dequeued, which is the number
    1978                 :            :  *   of pointers to *rte_crypto_op* structures effectively supplied to the
    1979                 :            :  *   *ops* array.
    1980                 :            :  */
    1981                 :            : static inline uint16_t
    1982                 :        294 : rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id,
    1983                 :            :                 struct rte_crypto_op **ops, uint16_t nb_ops)
    1984                 :            : {
    1985                 :            :         const struct rte_crypto_fp_ops *fp_ops;
    1986                 :            :         void *qp;
    1987                 :            : 
    1988                 :        294 :         rte_cryptodev_trace_dequeue_burst(dev_id, qp_id, (void **)ops, nb_ops);
    1989                 :            : 
    1990                 :            :         fp_ops = &rte_crypto_fp_ops[dev_id];
    1991                 :        294 :         qp = fp_ops->qp.data[qp_id];
    1992                 :            : 
    1993                 :        294 :         nb_ops = fp_ops->dequeue_burst(qp, ops, nb_ops);
    1994                 :            : 
    1995                 :            : #ifdef RTE_CRYPTO_CALLBACKS
    1996         [ -  + ]:        294 :         if (unlikely(fp_ops->qp.deq_cb[qp_id].next != NULL)) {
    1997                 :            :                 struct rte_cryptodev_cb_rcu *list;
    1998                 :            :                 struct rte_cryptodev_cb *cb;
    1999                 :            : 
    2000                 :            :                 /* rte_memory_order_release memory order was used when the
    2001                 :            :                  * call back was inserted into the list.
    2002                 :            :                  * Since there is a clear dependency between loading
    2003                 :            :                  * cb and cb->fn/cb->next, rte_memory_order_acquire memory order is
    2004                 :            :                  * not required.
    2005                 :            :                  */
    2006                 :            :                 list = &fp_ops->qp.deq_cb[qp_id];
    2007                 :          0 :                 rte_rcu_qsbr_thread_online(list->qsbr, 0);
    2008                 :          0 :                 cb = rte_atomic_load_explicit(&list->next, rte_memory_order_relaxed);
    2009                 :            : 
    2010         [ #  # ]:          0 :                 while (cb != NULL) {
    2011                 :          0 :                         nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
    2012                 :            :                                         cb->arg);
    2013                 :          0 :                         cb = cb->next;
    2014                 :            :                 };
    2015                 :            : 
    2016                 :          0 :                 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
    2017                 :            :         }
    2018                 :            : #endif
    2019                 :        294 :         return nb_ops;
    2020                 :            : }
    2021                 :            : 
    2022                 :            : /**
    2023                 :            :  * Enqueue a burst of operations for processing on a crypto device.
    2024                 :            :  *
    2025                 :            :  * The rte_cryptodev_enqueue_burst() function is invoked to place
    2026                 :            :  * crypto operations on the queue *qp_id* of the device designated by
    2027                 :            :  * its *dev_id*.
    2028                 :            :  *
    2029                 :            :  * The *nb_ops* parameter is the number of operations to process which are
    2030                 :            :  * supplied in the *ops* array of *rte_crypto_op* structures.
    2031                 :            :  *
    2032                 :            :  * The rte_cryptodev_enqueue_burst() function returns the number of
    2033                 :            :  * operations it actually enqueued for processing. A return value equal to
    2034                 :            :  * *nb_ops* means that all packets have been enqueued.
    2035                 :            :  *
    2036                 :            :  * @param       dev_id          The identifier of the device.
    2037                 :            :  * @param       qp_id           The index of the queue pair which packets are
    2038                 :            :  *                              to be enqueued for processing. The value
    2039                 :            :  *                              must be in the range [0, nb_queue_pairs - 1]
    2040                 :            :  *                              previously supplied to
    2041                 :            :  *                               *rte_cryptodev_configure*.
    2042                 :            :  * @param       ops             The address of an array of *nb_ops* pointers
    2043                 :            :  *                              to *rte_crypto_op* structures which contain
    2044                 :            :  *                              the crypto operations to be processed.
    2045                 :            :  * @param       nb_ops          The number of operations to process.
    2046                 :            :  *
    2047                 :            :  * @return
    2048                 :            :  * The number of operations actually enqueued on the crypto device. The return
    2049                 :            :  * value can be less than the value of the *nb_ops* parameter when the
    2050                 :            :  * crypto devices queue is full or if invalid parameters are specified in
    2051                 :            :  * a *rte_crypto_op*.
    2052                 :            :  */
    2053                 :            : static inline uint16_t
    2054                 :        294 : rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id,
    2055                 :            :                 struct rte_crypto_op **ops, uint16_t nb_ops)
    2056                 :            : {
    2057                 :            :         const struct rte_crypto_fp_ops *fp_ops;
    2058                 :            :         void *qp;
    2059                 :            : 
    2060                 :        294 :         fp_ops = &rte_crypto_fp_ops[dev_id];
    2061                 :        294 :         qp = fp_ops->qp.data[qp_id];
    2062                 :            : #ifdef RTE_CRYPTO_CALLBACKS
    2063         [ -  + ]:        294 :         if (unlikely(fp_ops->qp.enq_cb[qp_id].next != NULL)) {
    2064                 :            :                 struct rte_cryptodev_cb_rcu *list;
    2065                 :            :                 struct rte_cryptodev_cb *cb;
    2066                 :            : 
    2067                 :            :                 /* rte_memory_order_release memory order was used when the
    2068                 :            :                  * call back was inserted into the list.
    2069                 :            :                  * Since there is a clear dependency between loading
    2070                 :            :                  * cb and cb->fn/cb->next, rte_memory_order_acquire memory order is
    2071                 :            :                  * not required.
    2072                 :            :                  */
    2073                 :            :                 list = &fp_ops->qp.enq_cb[qp_id];
    2074                 :          0 :                 rte_rcu_qsbr_thread_online(list->qsbr, 0);
    2075                 :          0 :                 cb = rte_atomic_load_explicit(&list->next, rte_memory_order_relaxed);
    2076                 :            : 
    2077         [ #  # ]:          0 :                 while (cb != NULL) {
    2078                 :          0 :                         nb_ops = cb->fn(dev_id, qp_id, ops, nb_ops,
    2079                 :            :                                         cb->arg);
    2080                 :          0 :                         cb = cb->next;
    2081                 :            :                 };
    2082                 :            : 
    2083                 :          0 :                 rte_rcu_qsbr_thread_offline(list->qsbr, 0);
    2084                 :            :         }
    2085                 :            : #endif
    2086                 :            : 
    2087                 :        294 :         rte_cryptodev_trace_enqueue_burst(dev_id, qp_id, (void **)ops, nb_ops);
    2088                 :        294 :         return fp_ops->enqueue_burst(qp, ops, nb_ops);
    2089                 :            : }
    2090                 :            : 
    2091                 :            : /**
    2092                 :            :  * @warning
    2093                 :            :  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
    2094                 :            :  *
    2095                 :            :  * Get the number of used descriptors or depth of a cryptodev queue pair.
    2096                 :            :  *
    2097                 :            :  * This function retrieves the number of used descriptors in a crypto queue.
    2098                 :            :  * Applications can use this API in the fast path to inspect QP occupancy and
    2099                 :            :  * take appropriate action.
    2100                 :            :  *
    2101                 :            :  * Since it is a fast-path function, no check is performed on dev_id and qp_id.
    2102                 :            :  * Caller must therefore ensure that the device is enabled and queue pair is setup.
    2103                 :            :  *
    2104                 :            :  * @param       dev_id          The identifier of the device.
    2105                 :            :  * @param       qp_id           The index of the queue pair for which used descriptor
    2106                 :            :  *                              count is to be retrieved. The value
    2107                 :            :  *                              must be in the range [0, nb_queue_pairs - 1]
    2108                 :            :  *                              previously supplied to *rte_cryptodev_configure*.
    2109                 :            :  *
    2110                 :            :  * @return
    2111                 :            :  *  The number of used descriptors on the specified queue pair, or:
    2112                 :            :  *   - (-ENOTSUP) if the device does not support this function.
    2113                 :            :  */
    2114                 :            : 
    2115                 :            : __rte_experimental
    2116                 :            : static inline int
    2117                 :            : rte_cryptodev_qp_depth_used(uint8_t dev_id, uint16_t qp_id)
    2118                 :            : {
    2119                 :            :         const struct rte_crypto_fp_ops *fp_ops;
    2120                 :            :         void *qp;
    2121                 :            :         int rc;
    2122                 :            : 
    2123                 :            :         fp_ops = &rte_crypto_fp_ops[dev_id];
    2124                 :          1 :         qp = fp_ops->qp.data[qp_id];
    2125                 :            : 
    2126   [ -  -  +  -  :          1 :         if (fp_ops->qp_depth_used == NULL) {
             -  -  -  - ]
    2127                 :            :                 rc = -ENOTSUP;
    2128                 :          1 :                 goto out;
    2129                 :            :         }
    2130                 :            : 
    2131   [ #  #  #  #  :          0 :         rc = fp_ops->qp_depth_used(qp);
                   #  # ]
    2132         [ #  # ]:          0 : out:
    2133                 :            :         rte_cryptodev_trace_qp_depth_used(dev_id, qp_id);
    2134                 :            :         return rc;
    2135                 :            : }
    2136                 :            : 
    2137                 :            : #ifdef __cplusplus
    2138                 :            : }
    2139                 :            : #endif
    2140                 :            : 
    2141                 :            : #endif /* _RTE_CRYPTODEV_H_ */

Generated by: LCOV version 1.14