LCOV - code coverage report
Current view: top level - lib/compressdev - rte_comp.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 95 0.0 %
Date: 2025-05-01 17:49:45 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 54 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2017-2018 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <eal_export.h>
       6                 :            : #include "rte_comp.h"
       7                 :            : #include "rte_compressdev_internal.h"
       8                 :            : 
       9                 :            : RTE_EXPORT_SYMBOL(rte_comp_get_feature_name)
      10                 :            : const char *
      11                 :          0 : rte_comp_get_feature_name(uint64_t flag)
      12                 :            : {
      13   [ #  #  #  #  :          0 :         switch (flag) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
      14                 :            :         case RTE_COMP_FF_STATEFUL_COMPRESSION:
      15                 :            :                 return "STATEFUL_COMPRESSION";
      16                 :          0 :         case RTE_COMP_FF_STATEFUL_DECOMPRESSION:
      17                 :          0 :                 return "STATEFUL_DECOMPRESSION";
      18                 :          0 :         case RTE_COMP_FF_OOP_SGL_IN_SGL_OUT:
      19                 :          0 :                 return "OOP_SGL_IN_SGL_OUT";
      20                 :          0 :         case RTE_COMP_FF_OOP_SGL_IN_LB_OUT:
      21                 :          0 :                 return "OOP_SGL_IN_LB_OUT";
      22                 :          0 :         case RTE_COMP_FF_OOP_LB_IN_SGL_OUT:
      23                 :          0 :                 return "OOP_LB_IN_SGL_OUT";
      24                 :          0 :         case RTE_COMP_FF_MULTI_PKT_CHECKSUM:
      25                 :          0 :                 return "MULTI_PKT_CHECKSUM";
      26                 :          0 :         case RTE_COMP_FF_ADLER32_CHECKSUM:
      27                 :          0 :                 return "ADLER32_CHECKSUM";
      28                 :          0 :         case RTE_COMP_FF_CRC32_CHECKSUM:
      29                 :          0 :                 return "CRC32_CHECKSUM";
      30                 :          0 :         case RTE_COMP_FF_CRC32_ADLER32_CHECKSUM:
      31                 :          0 :                 return "CRC32_ADLER32_CHECKSUM";
      32                 :          0 :         case RTE_COMP_FF_NONCOMPRESSED_BLOCKS:
      33                 :          0 :                 return "NONCOMPRESSED_BLOCKS";
      34                 :          0 :         case RTE_COMP_FF_SHA1_HASH:
      35                 :          0 :                 return "SHA1_HASH";
      36                 :          0 :         case RTE_COMP_FF_SHA2_SHA256_HASH:
      37                 :          0 :                 return "SHA2_SHA256_HASH";
      38                 :          0 :         case RTE_COMP_FF_SHAREABLE_PRIV_XFORM:
      39                 :          0 :                 return "SHAREABLE_PRIV_XFORM";
      40                 :          0 :         case RTE_COMP_FF_HUFFMAN_FIXED:
      41                 :          0 :                 return "HUFFMAN_FIXED";
      42                 :          0 :         case RTE_COMP_FF_HUFFMAN_DYNAMIC:
      43                 :          0 :                 return "HUFFMAN_DYNAMIC";
      44                 :          0 :         case RTE_COMP_FF_XXHASH32_CHECKSUM:
      45                 :          0 :                 return "XXHASH32_CHECKSUM";
      46                 :          0 :         case RTE_COMP_FF_LZ4_DICT_ID:
      47                 :          0 :                 return "LZ4_DICT_ID";
      48                 :          0 :         case RTE_COMP_FF_LZ4_CONTENT_WITH_CHECKSUM:
      49                 :          0 :                 return "LZ4_CONTENT_WITH_CHECKSUM";
      50                 :          0 :         case RTE_COMP_FF_LZ4_CONTENT_SIZE:
      51                 :          0 :                 return "LZ4_CONTENT_SIZE";
      52                 :          0 :         case RTE_COMP_FF_LZ4_BLOCK_INDEPENDENCE:
      53                 :          0 :                 return "LZ4_BLOCK_INDEPENDENCE";
      54                 :          0 :         case RTE_COMP_FF_LZ4_BLOCK_WITH_CHECKSUM:
      55                 :          0 :                 return "LZ4_BLOCK_WITH_CHECKSUM";
      56                 :          0 :         default:
      57                 :          0 :                 return NULL;
      58                 :            :         }
      59                 :            : }
      60                 :            : 
      61                 :            : /**
      62                 :            :  * Reset the fields of an operation to their default values.
      63                 :            :  *
      64                 :            :  * @note The private data associated with the operation is not zeroed.
      65                 :            :  *
      66                 :            :  * @param op
      67                 :            :  *   The operation to be reset
      68                 :            :  */
      69                 :            : static inline void
      70                 :            : rte_comp_op_reset(struct rte_comp_op *op)
      71                 :            : {
      72                 :          0 :         struct rte_mempool *tmp_mp = op->mempool;
      73                 :          0 :         rte_iova_t tmp_iova_addr = op->iova_addr;
      74                 :            : 
      75                 :            :         memset(op, 0, sizeof(struct rte_comp_op));
      76                 :          0 :         op->status = RTE_COMP_OP_STATUS_NOT_PROCESSED;
      77                 :          0 :         op->iova_addr = tmp_iova_addr;
      78                 :          0 :         op->mempool = tmp_mp;
      79                 :            : }
      80                 :            : 
      81                 :            : /**
      82                 :            :  * Private data structure belonging to an operation pool.
      83                 :            :  */
      84                 :            : struct rte_comp_op_pool_private {
      85                 :            :         uint16_t user_size;
      86                 :            :         /**< Size of private user data with each operation. */
      87                 :            : };
      88                 :            : 
      89                 :            : /**
      90                 :            :  * Bulk allocate raw element from mempool and return as comp operations
      91                 :            :  *
      92                 :            :  * @param mempool
      93                 :            :  *   Compress operation mempool
      94                 :            :  * @param ops
      95                 :            :  *   Array to place allocated operations
      96                 :            :  * @param nb_ops
      97                 :            :  *   Number of operations to allocate
      98                 :            :  * @return
      99                 :            :  *   - nb_ops: Success, the nb_ops requested was allocated
     100                 :            :  *   - 0: Not enough entries in the mempool; no ops are retrieved.
     101                 :            :  */
     102                 :            : static inline int
     103                 :          0 : rte_comp_op_raw_bulk_alloc(struct rte_mempool *mempool,
     104                 :            :                 struct rte_comp_op **ops, uint16_t nb_ops)
     105                 :            : {
     106   [ #  #  #  # ]:          0 :         if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
     107                 :          0 :                 return nb_ops;
     108                 :            : 
     109                 :            :         return 0;
     110                 :            : }
     111                 :            : 
     112                 :            : /** Initialise rte_comp_op mempool element */
     113                 :            : static void
     114                 :          0 : rte_comp_op_init(struct rte_mempool *mempool,
     115                 :            :                 __rte_unused void *opaque_arg,
     116                 :            :                 void *_op_data,
     117                 :            :                 __rte_unused unsigned int i)
     118                 :            : {
     119                 :            :         struct rte_comp_op *op = _op_data;
     120                 :            : 
     121                 :          0 :         memset(_op_data, 0, mempool->elt_size);
     122                 :            : 
     123                 :          0 :         op->status = RTE_COMP_OP_STATUS_NOT_PROCESSED;
     124                 :          0 :         op->iova_addr = rte_mem_virt2iova(_op_data);
     125                 :          0 :         op->mempool = mempool;
     126                 :          0 : }
     127                 :            : 
     128                 :            : RTE_EXPORT_SYMBOL(rte_comp_op_pool_create)
     129                 :            : struct rte_mempool *
     130                 :          0 : rte_comp_op_pool_create(const char *name,
     131                 :            :                 unsigned int nb_elts, unsigned int cache_size,
     132                 :            :                 uint16_t user_size, int socket_id)
     133                 :            : {
     134                 :            :         struct rte_comp_op_pool_private *priv;
     135                 :            : 
     136                 :          0 :         unsigned int elt_size = sizeof(struct rte_comp_op) + user_size;
     137                 :            : 
     138                 :            :         /* lookup mempool in case already allocated */
     139                 :          0 :         struct rte_mempool *mp = rte_mempool_lookup(name);
     140                 :            : 
     141         [ #  # ]:          0 :         if (mp != NULL) {
     142                 :            :                 priv = (struct rte_comp_op_pool_private *)
     143                 :            :                                 rte_mempool_get_priv(mp);
     144                 :            : 
     145   [ #  #  #  # ]:          0 :                 if (mp->elt_size != elt_size ||
     146                 :          0 :                                 mp->cache_size < cache_size ||
     147         [ #  # ]:          0 :                                 mp->size < nb_elts ||
     148         [ #  # ]:          0 :                                 priv->user_size <  user_size) {
     149                 :            :                         mp = NULL;
     150                 :          0 :                         COMPRESSDEV_LOG(ERR,
     151                 :            :                 "Mempool %s already exists but with incompatible parameters",
     152                 :            :                                         name);
     153                 :          0 :                         return NULL;
     154                 :            :                 }
     155                 :            :                 return mp;
     156                 :            :         }
     157                 :            : 
     158                 :          0 :         mp = rte_mempool_create(
     159                 :            :                         name,
     160                 :            :                         nb_elts,
     161                 :            :                         elt_size,
     162                 :            :                         cache_size,
     163                 :            :                         sizeof(struct rte_comp_op_pool_private),
     164                 :            :                         NULL,
     165                 :            :                         NULL,
     166                 :            :                         rte_comp_op_init,
     167                 :            :                         NULL,
     168                 :            :                         socket_id,
     169                 :            :                         0);
     170                 :            : 
     171         [ #  # ]:          0 :         if (mp == NULL) {
     172                 :          0 :                 COMPRESSDEV_LOG(ERR, "Failed to create mempool %s", name);
     173                 :          0 :                 return NULL;
     174                 :            :         }
     175                 :            : 
     176                 :            :         priv = (struct rte_comp_op_pool_private *)
     177                 :            :                         rte_mempool_get_priv(mp);
     178                 :            : 
     179                 :          0 :         priv->user_size = user_size;
     180                 :            : 
     181                 :          0 :         return mp;
     182                 :            : }
     183                 :            : 
     184                 :            : RTE_EXPORT_SYMBOL(rte_comp_op_alloc)
     185                 :            : struct rte_comp_op *
     186                 :          0 : rte_comp_op_alloc(struct rte_mempool *mempool)
     187                 :            : {
     188                 :          0 :         struct rte_comp_op *op = NULL;
     189                 :            :         int retval;
     190                 :            : 
     191                 :          0 :         retval = rte_comp_op_raw_bulk_alloc(mempool, &op, 1);
     192         [ #  # ]:          0 :         if (unlikely(retval != 1))
     193                 :            :                 return NULL;
     194                 :            : 
     195                 :          0 :         rte_comp_op_reset(op);
     196                 :            : 
     197                 :          0 :         return op;
     198                 :            : }
     199                 :            : 
     200                 :            : RTE_EXPORT_SYMBOL(rte_comp_op_bulk_alloc)
     201                 :            : int
     202                 :          0 : rte_comp_op_bulk_alloc(struct rte_mempool *mempool,
     203                 :            :                 struct rte_comp_op **ops, uint16_t nb_ops)
     204                 :            : {
     205                 :            :         int retval;
     206                 :            :         uint16_t i;
     207                 :            : 
     208                 :          0 :         retval = rte_comp_op_raw_bulk_alloc(mempool, ops, nb_ops);
     209         [ #  # ]:          0 :         if (unlikely(retval != nb_ops))
     210                 :            :                 return 0;
     211                 :            : 
     212         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++)
     213                 :          0 :                 rte_comp_op_reset(ops[i]);
     214                 :            : 
     215                 :            :         return nb_ops;
     216                 :            : }
     217                 :            : 
     218                 :            : /**
     219                 :            :  * free operation structure
     220                 :            :  * If operation has been allocate from a rte_mempool, then the operation will
     221                 :            :  * be returned to the mempool.
     222                 :            :  *
     223                 :            :  * @param op
     224                 :            :  *   Compress operation
     225                 :            :  */
     226                 :            : RTE_EXPORT_SYMBOL(rte_comp_op_free)
     227                 :            : void
     228                 :          0 : rte_comp_op_free(struct rte_comp_op *op)
     229                 :            : {
     230   [ #  #  #  # ]:          0 :         if (op != NULL && op->mempool != NULL)
     231                 :          0 :                 rte_mempool_put(op->mempool, op);
     232                 :          0 : }
     233                 :            : 
     234                 :            : RTE_EXPORT_SYMBOL(rte_comp_op_bulk_free)
     235                 :            : void
     236                 :          0 : rte_comp_op_bulk_free(struct rte_comp_op **ops, uint16_t nb_ops)
     237                 :            : {
     238                 :            :         uint16_t i;
     239                 :            : 
     240         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
     241   [ #  #  #  # ]:          0 :                 if (ops[i] != NULL && ops[i]->mempool != NULL)
     242                 :          0 :                         rte_mempool_put(ops[i]->mempool, ops[i]);
     243                 :          0 :                 ops[i] = NULL;
     244                 :            :         }
     245                 :          0 : }

Generated by: LCOV version 1.14