LCOV - code coverage report
Current view: top level - drivers/compress/zlib - zlib_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 253 0.8 %
Date: 2025-11-01 17:50:34 Functions: 2 13 15.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 129 0.8 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Cavium Networks
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <bus_vdev_driver.h>
       6                 :            : #include <rte_common.h>
       7                 :            : #include <stdlib.h>
       8                 :            : 
       9                 :            : #include "zlib_pmd_private.h"
      10                 :            : 
      11                 :            : /** Compute next mbuf in the list, assign data buffer and length,
      12                 :            :  *  returns 0 if mbuf is NULL
      13                 :            :  */
      14                 :            : #define COMPUTE_BUF(mbuf, data, len)            \
      15                 :            :                 ((mbuf = mbuf->next) ?               \
      16                 :            :                 (data = rte_pktmbuf_mtod(mbuf, uint8_t *)),     \
      17                 :            :                 (len = rte_pktmbuf_data_len(mbuf)) : 0)
      18                 :            : 
      19                 :            : #define BOTTOM_NIBBLE_OF_BYTE 0xf
      20                 :            : #define TOP_NIBBLE_OF_BYTE 0xf0
      21                 :            : #define BOTTOM_NIBBLE_OF_BYTES_IN_DOUBLE_WORD 0x0f0f0f0f
      22                 :            : #define TOP_NIBBLE_OF_BYTE_IN_DOUBLE_WORD 0xf0f0f0f0
      23                 :            : #define ZLIB_MAX_DICT_SIZE (1ULL << 15)
      24                 :            : 
      25                 :            : static void
      26                 :          0 : process_zlib_deflate_chksum(struct rte_comp_op *op,
      27                 :            :                 z_stream *strm, enum rte_comp_checksum_type chksum)
      28                 :            : {
      29                 :          0 :         uint32_t dictionary_len = 0;
      30                 :          0 :         uint8_t *dictionary = malloc(ZLIB_MAX_DICT_SIZE);
      31                 :            :         uint32_t dictionary_start, dictionary_end, sum;
      32                 :            :         uint8_t *sum_bytes = (uint8_t *)&sum;
      33                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
      34                 :            : 
      35      [ #  #  # ]:          0 :         switch (chksum) {
      36                 :          0 :         case RTE_COMP_CHECKSUM_3GPP_PDCP_UDC:
      37                 :            : 
      38         [ #  # ]:          0 :                 if (!dictionary) {
      39                 :          0 :                         ZLIB_PMD_ERR("Unable to fetch dictionary");
      40                 :          0 :                         op->status = RTE_COMP_OP_STATUS_ERROR;
      41                 :          0 :                         return;
      42                 :            :                 }
      43                 :            : 
      44         [ #  # ]:          0 :                 if (deflateGetDictionary(strm, dictionary, &dictionary_len)) {
      45                 :          0 :                         ZLIB_PMD_ERR("Unable to fetch dictionary");
      46                 :          0 :                         op->status = RTE_COMP_OP_STATUS_CHECKSUM_VALIDATION_FAILED;
      47                 :          0 :                         free(dictionary);
      48                 :          0 :                         return;
      49                 :            :                 }
      50                 :            : 
      51                 :          0 :                 dictionary_start = (uint32_t)(*dictionary);
      52                 :          0 :                 dictionary_end = (uint32_t)(*(dictionary + dictionary_len - 4));
      53                 :          0 :                 sum = (dictionary_start & BOTTOM_NIBBLE_OF_BYTES_IN_DOUBLE_WORD)
      54                 :          0 :                         + (dictionary_start & (TOP_NIBBLE_OF_BYTE_IN_DOUBLE_WORD >> 4))
      55                 :          0 :                         + (dictionary_end & BOTTOM_NIBBLE_OF_BYTES_IN_DOUBLE_WORD)
      56                 :          0 :                         + (dictionary_end & (TOP_NIBBLE_OF_BYTE_IN_DOUBLE_WORD >> 4));
      57                 :            : 
      58                 :          0 :                 op->output_chksum = ~(sum_bytes[0] + sum_bytes[1] + sum_bytes[2] + sum_bytes[3])
      59                 :          0 :                          & BOTTOM_NIBBLE_OF_BYTE;
      60                 :          0 :                 break;
      61                 :            :         case RTE_COMP_CHECKSUM_NONE:
      62                 :            :                 break;
      63                 :          0 :         case RTE_COMP_CHECKSUM_CRC32:
      64                 :            :         case RTE_COMP_CHECKSUM_ADLER32:
      65                 :            :         case RTE_COMP_CHECKSUM_CRC32_ADLER32:
      66                 :            :         default:
      67                 :          0 :                 ZLIB_PMD_ERR("Checksum not supported");
      68                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
      69                 :          0 :                 free(dictionary);
      70                 :          0 :                 return;
      71                 :            :         }
      72                 :          0 :         free(dictionary);
      73                 :            : }
      74                 :            : 
      75                 :            : static void
      76                 :          0 : process_zlib_inflate_chksum(struct rte_comp_op *op,
      77                 :            :                 z_stream *strm,
      78                 :            :                 enum rte_comp_checksum_type chksum)
      79                 :            : {
      80                 :          0 :         uint32_t dictionary_len = 0;
      81                 :          0 :         uint8_t *dictionary = malloc(ZLIB_MAX_DICT_SIZE);
      82                 :            :         uint32_t dictionary_start, dictionary_end, sum;
      83                 :            :         uint8_t *sum_bytes = (uint8_t *)&sum;
      84                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
      85                 :            : 
      86      [ #  #  # ]:          0 :         switch (chksum) {
      87                 :          0 :         case RTE_COMP_CHECKSUM_3GPP_PDCP_UDC:
      88         [ #  # ]:          0 :                 if (!dictionary) {
      89                 :          0 :                         ZLIB_PMD_ERR("Unable to malloc dictionary");
      90                 :          0 :                         op->status = RTE_COMP_OP_STATUS_ERROR;
      91                 :          0 :                         return;
      92                 :            :                 }
      93                 :            : 
      94         [ #  # ]:          0 :                 if (inflateGetDictionary(strm, dictionary, &dictionary_len)) {
      95                 :          0 :                         ZLIB_PMD_ERR("Unable to fetch dictionary");
      96                 :          0 :                         op->status = RTE_COMP_OP_STATUS_CHECKSUM_VALIDATION_FAILED;
      97                 :          0 :                         free(dictionary);
      98                 :          0 :                         return;
      99                 :            :                 }
     100                 :            : 
     101                 :          0 :                 dictionary_start = (uint32_t)(*dictionary);
     102                 :          0 :                 dictionary_end = (uint32_t)(*(dictionary + dictionary_len - 4));
     103                 :          0 :                 sum = (dictionary_start & BOTTOM_NIBBLE_OF_BYTES_IN_DOUBLE_WORD)
     104                 :          0 :                         + (dictionary_start & (TOP_NIBBLE_OF_BYTE_IN_DOUBLE_WORD >> 4))
     105                 :          0 :                         + (dictionary_end & BOTTOM_NIBBLE_OF_BYTES_IN_DOUBLE_WORD)
     106                 :          0 :                         + (dictionary_end & (TOP_NIBBLE_OF_BYTE_IN_DOUBLE_WORD >> 4));
     107                 :            : 
     108                 :          0 :                 op->output_chksum = ~(sum_bytes[0] + sum_bytes[1] + sum_bytes[2] + sum_bytes[3])
     109                 :          0 :                          & BOTTOM_NIBBLE_OF_BYTE;
     110                 :            : 
     111         [ #  # ]:          0 :                 if (op->input_chksum != op->output_chksum) {
     112                 :          0 :                         ZLIB_PMD_ERR("Checksum does not match");
     113                 :          0 :                         op->status = RTE_COMP_OP_STATUS_CHECKSUM_VALIDATION_FAILED;
     114                 :          0 :                         free(dictionary);
     115                 :          0 :                         return;
     116                 :            :                 }
     117                 :            :                 break;
     118                 :            :         case RTE_COMP_CHECKSUM_NONE:
     119                 :            :                 break;
     120                 :          0 :         case RTE_COMP_CHECKSUM_CRC32:
     121                 :            :         case RTE_COMP_CHECKSUM_ADLER32:
     122                 :            :         case RTE_COMP_CHECKSUM_CRC32_ADLER32:
     123                 :            :         default:
     124                 :          0 :                 ZLIB_PMD_ERR("Checksum not supported");
     125                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     126                 :          0 :                 free(dictionary);
     127                 :          0 :                 return;
     128                 :            :         }
     129                 :            : }
     130                 :            : 
     131                 :            : static void
     132                 :          0 : process_zlib_deflate(struct rte_comp_op *op, z_stream *strm)
     133                 :            : {
     134                 :            :         int ret, flush, fin_flush;
     135                 :            :         unsigned long total_in_at_start, total_out_at_start;
     136                 :          0 :         struct rte_mbuf *mbuf_src = op->m_src;
     137                 :          0 :         struct rte_mbuf *mbuf_dst = op->m_dst;
     138                 :            : 
     139      [ #  #  # ]:          0 :         switch (op->flush_flag) {
     140                 :            :         case RTE_COMP_FLUSH_FULL:
     141                 :            :         case RTE_COMP_FLUSH_FINAL:
     142                 :            :                 fin_flush = Z_FINISH;
     143                 :            :                 break;
     144                 :          0 :         case RTE_COMP_FLUSH_SYNC:
     145                 :            :                 fin_flush = Z_SYNC_FLUSH;
     146                 :          0 :                 break;
     147                 :          0 :         default:
     148                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     149                 :          0 :                 ZLIB_PMD_ERR("Invalid flush value");
     150                 :          0 :                 return;
     151                 :            :         }
     152                 :            : 
     153         [ #  # ]:          0 :         if (unlikely(!strm)) {
     154                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     155                 :          0 :                 ZLIB_PMD_ERR("Invalid z_stream");
     156                 :          0 :                 return;
     157                 :            :         }
     158                 :            :         /* Update z_stream with the inputs provided by application */
     159                 :          0 :         strm->next_in = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
     160                 :            :                         op->src.offset);
     161                 :            : 
     162                 :          0 :         strm->avail_in = rte_pktmbuf_data_len(mbuf_src) - op->src.offset;
     163                 :            : 
     164                 :          0 :         strm->next_out = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
     165                 :            :                         op->dst.offset);
     166                 :            : 
     167                 :          0 :         strm->avail_out = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset;
     168                 :            : 
     169                 :          0 :         total_in_at_start = strm->total_in;
     170                 :          0 :         total_out_at_start = strm->total_out;
     171                 :            : 
     172                 :            :         /* Set flush value to NO_FLUSH unless it is last mbuf */
     173                 :            :         flush = Z_NO_FLUSH;
     174                 :            :         /* Initialize status to SUCCESS */
     175                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
     176                 :            : 
     177                 :            :         do {
     178                 :            :                 /* Set flush value to Z_FINISH for last block */
     179         [ #  # ]:          0 :                 if ((op->src.length - (strm->total_in - total_in_at_start)) <= strm->avail_in) {
     180                 :          0 :                         strm->avail_in = (op->src.length - (strm->total_in - total_in_at_start));
     181                 :            :                         flush = fin_flush;
     182                 :            :                 }
     183                 :            :                 do {
     184                 :          0 :                         ret = deflate(strm, flush);
     185         [ #  # ]:          0 :                         if (unlikely(ret == Z_STREAM_ERROR)) {
     186                 :            :                                 /* error return, do not process further */
     187                 :          0 :                                 op->status =  RTE_COMP_OP_STATUS_ERROR;
     188                 :          0 :                                 goto def_end;
     189                 :            :                         }
     190                 :            :                         /* Break if Z_STREAM_END is encountered */
     191         [ #  # ]:          0 :                         if (ret == Z_STREAM_END)
     192                 :          0 :                                 goto def_end;
     193                 :            : 
     194                 :            :                 /* Keep looping until input mbuf is consumed.
     195                 :            :                  * Exit if destination mbuf gets exhausted.
     196                 :            :                  */
     197         [ #  # ]:          0 :                 } while ((strm->avail_out == 0) &&
     198   [ #  #  #  # ]:          0 :                         COMPUTE_BUF(mbuf_dst, strm->next_out, strm->avail_out));
     199                 :            : 
     200         [ #  # ]:          0 :                 if (!strm->avail_out) {
     201                 :            :                         /* there is no space for compressed output */
     202                 :          0 :                         op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
     203                 :          0 :                         break;
     204                 :            :                 }
     205                 :            : 
     206                 :            :         /* Update source buffer to next mbuf
     207                 :            :          * Exit if input buffers are fully consumed
     208                 :            :          */
     209   [ #  #  #  # ]:          0 :         } while (COMPUTE_BUF(mbuf_src, strm->next_in, strm->avail_in));
     210                 :            : 
     211                 :          0 : def_end:
     212                 :            :         /* Update op stats */
     213      [ #  #  # ]:          0 :         switch (op->status) {
     214                 :          0 :         case RTE_COMP_OP_STATUS_SUCCESS:
     215                 :          0 :                 op->consumed += strm->total_in - total_in_at_start;
     216                 :            :         /* Fall-through */
     217                 :          0 :         case RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED:
     218                 :          0 :                 op->produced += strm->total_out - total_out_at_start;
     219                 :          0 :                 break;
     220                 :          0 :         default:
     221                 :          0 :                 ZLIB_PMD_ERR("stats not updated for status:%d",
     222                 :            :                                 op->status);
     223                 :            :         }
     224                 :            : 
     225         [ #  # ]:          0 :         if (op->flush_flag != RTE_COMP_FLUSH_SYNC)
     226                 :          0 :                 deflateReset(strm);
     227                 :            : }
     228                 :            : 
     229                 :            : static void
     230                 :          0 : process_zlib_inflate(struct rte_comp_op *op, z_stream *strm)
     231                 :            : {
     232                 :            :         int ret, flush;
     233                 :            :         unsigned long total_in_at_start, total_out_at_start;
     234                 :          0 :         struct rte_mbuf *mbuf_src = op->m_src;
     235                 :          0 :         struct rte_mbuf *mbuf_dst = op->m_dst;
     236                 :            : 
     237         [ #  # ]:          0 :         if (unlikely(!strm)) {
     238                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     239                 :          0 :                 ZLIB_PMD_ERR("Invalid z_stream");
     240                 :          0 :                 return;
     241                 :            :         }
     242                 :          0 :         strm->next_in = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
     243                 :            :                         op->src.offset);
     244                 :            : 
     245                 :          0 :         strm->avail_in = rte_pktmbuf_data_len(mbuf_src) - op->src.offset;
     246                 :            : 
     247                 :          0 :         strm->next_out = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
     248                 :            :                         op->dst.offset);
     249                 :            : 
     250                 :          0 :         strm->avail_out = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset;
     251                 :            : 
     252                 :          0 :         total_in_at_start = strm->total_in;
     253                 :          0 :         total_out_at_start = strm->total_out;
     254                 :            : 
     255                 :            :         /** Ignoring flush value provided from application for decompression */
     256                 :            :         flush = Z_NO_FLUSH;
     257                 :            :         /* initialize status to SUCCESS */
     258                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
     259                 :            : 
     260                 :            :         do {
     261                 :            :                 do {
     262                 :          0 :                         ret = inflate(strm, flush);
     263                 :            : 
     264      [ #  #  # ]:          0 :                         switch (ret) {
     265                 :            :                         /* Fall-through */
     266                 :            :                         case Z_NEED_DICT:
     267                 :            :                                 ret = Z_DATA_ERROR;
     268                 :            :                         /* Fall-through */
     269                 :          0 :                         case Z_DATA_ERROR:
     270                 :            :                         /* Fall-through */
     271                 :            :                         case Z_MEM_ERROR:
     272                 :            :                         /* Fall-through */
     273                 :            :                         case Z_STREAM_ERROR:
     274                 :          0 :                                 op->status = RTE_COMP_OP_STATUS_ERROR;
     275                 :            :                         /* Fall-through */
     276                 :          0 :                         case Z_STREAM_END:
     277                 :            :                                 /* no further computation needed if
     278                 :            :                                  * Z_STREAM_END is encountered
     279                 :            :                                  */
     280                 :          0 :                                 goto inf_end;
     281                 :            :                         default:
     282                 :            :                                 /* success */
     283                 :            :                                 break;
     284                 :            : 
     285                 :            :                         }
     286                 :            :                 /* Keep looping until input mbuf is consumed.
     287                 :            :                  * Exit if destination mbuf gets exhausted.
     288                 :            :                  */
     289         [ #  # ]:          0 :                 } while ((strm->avail_out == 0) &&
     290   [ #  #  #  # ]:          0 :                         COMPUTE_BUF(mbuf_dst, strm->next_out, strm->avail_out));
     291                 :            : 
     292         [ #  # ]:          0 :                 if (!strm->avail_out) {
     293                 :            :                         /* there is no more space for decompressed output */
     294                 :          0 :                         op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
     295                 :          0 :                         break;
     296                 :            :                 }
     297                 :            :         /* Read next input buffer to be processed, exit if compressed
     298                 :            :          * blocks are fully read
     299                 :            :          */
     300   [ #  #  #  # ]:          0 :         } while (COMPUTE_BUF(mbuf_src, strm->next_in, strm->avail_in));
     301                 :            : 
     302                 :          0 : inf_end:
     303                 :            :         /* Update op stats */
     304      [ #  #  # ]:          0 :         switch (op->status) {
     305                 :          0 :         case RTE_COMP_OP_STATUS_SUCCESS:
     306                 :          0 :                 op->consumed += strm->total_in - total_in_at_start;
     307                 :            :         /* Fall-through */
     308                 :          0 :         case RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED:
     309                 :          0 :                 op->produced += strm->total_out - total_out_at_start;
     310                 :          0 :                 break;
     311                 :          0 :         default:
     312                 :          0 :                 ZLIB_PMD_ERR("stats not produced for status:%d",
     313                 :            :                                 op->status);
     314                 :            :         }
     315                 :            : 
     316         [ #  # ]:          0 :         if (op->flush_flag != RTE_COMP_FLUSH_SYNC)
     317                 :          0 :                 inflateReset(strm);
     318                 :            : }
     319                 :            : 
     320                 :            : /** Process comp operation for mbuf */
     321                 :            : static inline int
     322                 :          0 : process_zlib_op(struct zlib_qp *qp, struct rte_comp_op *op)
     323                 :            : {
     324                 :            :         struct zlib_stream *stream;
     325                 :            :         struct zlib_priv_xform *private_xform;
     326                 :            : 
     327         [ #  # ]:          0 :         if ((op->op_type == RTE_COMP_OP_STATEFUL) ||
     328         [ #  # ]:          0 :                         (op->src.offset > rte_pktmbuf_data_len(op->m_src)) ||
     329         [ #  # ]:          0 :                         (op->dst.offset > rte_pktmbuf_data_len(op->m_dst))) {
     330                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     331                 :          0 :                 ZLIB_PMD_ERR("Invalid source or destination buffers or "
     332                 :            :                                   "invalid Operation requested");
     333                 :            :         } else {
     334                 :          0 :                 private_xform = (struct zlib_priv_xform *)op->private_xform;
     335                 :            :                 stream = &private_xform->stream;
     336                 :          0 :                 stream->chksum(op, &stream->strm, stream->chksum_type);
     337         [ #  # ]:          0 :                 if (op->status != RTE_COMP_OP_STATUS_SUCCESS)
     338                 :            :                         return -1;
     339                 :            : 
     340                 :          0 :                 stream->comp(op, &stream->strm);
     341                 :            :         }
     342                 :            :         /* whatever is out of op, put it into completion queue with
     343                 :            :          * its status
     344                 :            :          */
     345   [ #  #  #  #  :          0 :         return rte_ring_enqueue(qp->processed_pkts, (void *)op);
                      # ]
     346                 :            : }
     347                 :            : 
     348                 :            : /** Parse comp xform and set private xform/Stream parameters */
     349                 :            : int
     350                 :          0 : zlib_set_stream_parameters(const struct rte_comp_xform *xform,
     351                 :            :                 struct zlib_stream *stream)
     352                 :            : {
     353                 :            :         int strategy, level, wbits;
     354                 :          0 :         z_stream *strm = &stream->strm;
     355                 :            : 
     356                 :            :         /* allocate deflate state */
     357                 :          0 :         strm->zalloc = Z_NULL;
     358                 :          0 :         strm->zfree = Z_NULL;
     359                 :          0 :         strm->opaque = Z_NULL;
     360                 :            : 
     361      [ #  #  # ]:          0 :         switch (xform->type) {
     362                 :          0 :         case RTE_COMP_COMPRESS:
     363                 :          0 :                 stream->comp = process_zlib_deflate;
     364                 :          0 :                 stream->free = deflateEnd;
     365                 :          0 :                 stream->chksum = process_zlib_deflate_chksum;
     366                 :            :                 /** Compression window bits */
     367         [ #  # ]:          0 :                 switch (xform->compress.algo) {
     368                 :          0 :                 case RTE_COMP_ALGO_DEFLATE:
     369                 :          0 :                         wbits = -(xform->compress.window_size);
     370                 :            :                         break;
     371                 :          0 :                 default:
     372                 :          0 :                         ZLIB_PMD_ERR("Compression algorithm not supported");
     373                 :          0 :                         return -1;
     374                 :            :                 }
     375                 :            :                 /** Compression Level */
     376   [ #  #  #  #  :          0 :                 switch (xform->compress.level) {
                      # ]
     377                 :            :                 case RTE_COMP_LEVEL_PMD_DEFAULT:
     378                 :            :                         level = Z_DEFAULT_COMPRESSION;
     379                 :            :                         break;
     380                 :          0 :                 case RTE_COMP_LEVEL_NONE:
     381                 :            :                         level = Z_NO_COMPRESSION;
     382                 :          0 :                         break;
     383                 :          0 :                 case RTE_COMP_LEVEL_MIN:
     384                 :            :                         level = Z_BEST_SPEED;
     385                 :          0 :                         break;
     386                 :          0 :                 case RTE_COMP_LEVEL_MAX:
     387                 :            :                         level = Z_BEST_COMPRESSION;
     388                 :          0 :                         break;
     389                 :          0 :                 default:
     390                 :            :                         level = xform->compress.level;
     391         [ #  # ]:          0 :                         if (level < RTE_COMP_LEVEL_MIN ||
     392                 :            :                                         level > RTE_COMP_LEVEL_MAX) {
     393                 :          0 :                                 ZLIB_PMD_ERR("Compression level %d "
     394                 :            :                                                 "not supported",
     395                 :            :                                                 level);
     396                 :          0 :                                 return -1;
     397                 :            :                         }
     398                 :            :                         break;
     399                 :            :                 }
     400                 :            :                 /** Compression strategy */
     401      [ #  #  # ]:          0 :                 switch (xform->compress.deflate.huffman) {
     402                 :            :                 case RTE_COMP_HUFFMAN_DEFAULT:
     403                 :            :                         strategy = Z_DEFAULT_STRATEGY;
     404                 :            :                         break;
     405                 :          0 :                 case RTE_COMP_HUFFMAN_FIXED:
     406                 :            :                         strategy = Z_FIXED;
     407                 :          0 :                         break;
     408                 :            :                 case RTE_COMP_HUFFMAN_DYNAMIC:
     409                 :            :                         strategy = Z_DEFAULT_STRATEGY;
     410                 :            :                         break;
     411                 :          0 :                 default:
     412                 :          0 :                         ZLIB_PMD_ERR("Compression strategy not supported");
     413                 :          0 :                         return -1;
     414                 :            :                 }
     415                 :            : 
     416                 :            :                 /** Checksum used */
     417                 :          0 :                 stream->chksum_type = xform->compress.chksum;
     418                 :            : 
     419         [ #  # ]:          0 :                 if (deflateInit2(strm, level,
     420                 :            :                                         Z_DEFLATED, wbits,
     421                 :            :                                         DEF_MEM_LEVEL, strategy) != Z_OK) {
     422                 :          0 :                         ZLIB_PMD_ERR("Deflate init failed");
     423                 :          0 :                         return -1;
     424                 :            :                 }
     425                 :            : 
     426         [ #  # ]:          0 :                 if (xform->compress.deflate.dictionary) {
     427         [ #  # ]:          0 :                         if (deflateSetDictionary(strm, xform->compress.deflate.dictionary,
     428                 :          0 :                                         xform->compress.deflate.dictionary_len)) {
     429                 :          0 :                                 ZLIB_PMD_ERR("Deflate set dictionary failed");
     430                 :          0 :                                 return -1;
     431                 :            :                         }
     432                 :            :                 }
     433                 :            :                 break;
     434                 :            : 
     435                 :          0 :         case RTE_COMP_DECOMPRESS:
     436                 :          0 :                 stream->comp = process_zlib_inflate;
     437                 :          0 :                 stream->free = inflateEnd;
     438                 :          0 :                 stream->chksum = process_zlib_inflate_chksum;
     439                 :            :                 /** window bits */
     440         [ #  # ]:          0 :                 switch (xform->decompress.algo) {
     441                 :          0 :                 case RTE_COMP_ALGO_DEFLATE:
     442                 :          0 :                         wbits = -(xform->decompress.window_size);
     443                 :            :                         break;
     444                 :          0 :                 default:
     445                 :          0 :                         ZLIB_PMD_ERR("Compression algorithm not supported");
     446                 :          0 :                         return -1;
     447                 :            :                 }
     448                 :            : 
     449                 :            :                 /** Checksum used */
     450                 :          0 :                 stream->chksum_type = xform->decompress.chksum;
     451                 :            : 
     452         [ #  # ]:          0 :                 if (inflateInit2(strm, wbits) != Z_OK) {
     453                 :          0 :                         ZLIB_PMD_ERR("Inflate init failed");
     454                 :          0 :                         return -1;
     455                 :            :                 }
     456                 :            : 
     457         [ #  # ]:          0 :                 if (xform->decompress.inflate.dictionary) {
     458         [ #  # ]:          0 :                         if (inflateSetDictionary(strm, xform->decompress.inflate.dictionary,
     459                 :          0 :                                         xform->decompress.inflate.dictionary_len)) {
     460                 :          0 :                                 ZLIB_PMD_ERR("inflate set dictionary failed");
     461                 :          0 :                                 return -1;
     462                 :            :                         }
     463                 :            :                 }
     464                 :            :                 break;
     465                 :            :         default:
     466                 :            :                 return -1;
     467                 :            :         }
     468                 :            :         return 0;
     469                 :            : }
     470                 :            : 
     471                 :            : static uint16_t
     472                 :          0 : zlib_pmd_enqueue_burst(void *queue_pair,
     473                 :            :                         struct rte_comp_op **ops, uint16_t nb_ops)
     474                 :            : {
     475                 :            :         struct zlib_qp *qp = queue_pair;
     476                 :            :         int ret;
     477                 :            :         uint16_t i;
     478                 :            :         uint16_t enqd = 0;
     479         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
     480                 :          0 :                 ret = process_zlib_op(qp, ops[i]);
     481         [ #  # ]:          0 :                 if (unlikely(ret < 0)) {
     482                 :            :                         /* increment count if failed to push to completion
     483                 :            :                          * queue
     484                 :            :                          */
     485                 :          0 :                         qp->qp_stats.enqueue_err_count++;
     486                 :            :                 } else {
     487                 :          0 :                         qp->qp_stats.enqueued_count++;
     488                 :          0 :                         enqd++;
     489                 :            :                 }
     490                 :            :         }
     491                 :          0 :         return enqd;
     492                 :            : }
     493                 :            : 
     494                 :            : static uint16_t
     495                 :          0 : zlib_pmd_dequeue_burst(void *queue_pair,
     496                 :            :                         struct rte_comp_op **ops, uint16_t nb_ops)
     497                 :            : {
     498                 :            :         struct zlib_qp *qp = queue_pair;
     499                 :            : 
     500                 :            :         unsigned int nb_dequeued = 0;
     501                 :            : 
     502   [ #  #  #  #  :          0 :         nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
                      # ]
     503                 :            :                         (void **)ops, nb_ops, NULL);
     504                 :          0 :         qp->qp_stats.dequeued_count += nb_dequeued;
     505                 :            : 
     506                 :          0 :         return nb_dequeued;
     507                 :            : }
     508                 :            : 
     509                 :            : static int
     510                 :          0 : zlib_create(const char *name,
     511                 :            :                 struct rte_vdev_device *vdev,
     512                 :            :                 struct rte_compressdev_pmd_init_params *init_params)
     513                 :            : {
     514                 :            :         struct rte_compressdev *dev;
     515                 :            : 
     516                 :          0 :         dev = rte_compressdev_pmd_create(name, &vdev->device,
     517                 :            :                         sizeof(struct zlib_private), init_params);
     518         [ #  # ]:          0 :         if (dev == NULL) {
     519                 :          0 :                 ZLIB_PMD_ERR("driver %s: create failed", init_params->name);
     520                 :          0 :                 return -ENODEV;
     521                 :            :         }
     522                 :            : 
     523                 :          0 :         dev->dev_ops = rte_zlib_pmd_ops;
     524                 :            : 
     525                 :            :         /* register rx/tx burst functions for data path */
     526                 :          0 :         dev->dequeue_burst = zlib_pmd_dequeue_burst;
     527                 :          0 :         dev->enqueue_burst = zlib_pmd_enqueue_burst;
     528                 :            : 
     529                 :          0 :         return 0;
     530                 :            : }
     531                 :            : 
     532                 :            : static int
     533                 :          0 : zlib_probe(struct rte_vdev_device *vdev)
     534                 :            : {
     535                 :          0 :         struct rte_compressdev_pmd_init_params init_params = {
     536                 :            :                 "",
     537         [ #  # ]:          0 :                 rte_socket_id()
     538                 :            :         };
     539                 :            :         const char *name;
     540                 :            :         const char *input_args;
     541                 :            :         int retval;
     542                 :            : 
     543                 :            :         name = rte_vdev_device_name(vdev);
     544                 :            : 
     545                 :            :         if (name == NULL)
     546                 :            :                 return -EINVAL;
     547                 :            : 
     548                 :            :         input_args = rte_vdev_device_args(vdev);
     549                 :            : 
     550                 :          0 :         retval = rte_compressdev_pmd_parse_input_args(&init_params, input_args);
     551         [ #  # ]:          0 :         if (retval < 0) {
     552                 :          0 :                 ZLIB_PMD_LOG(ERR,
     553                 :            :                         "Failed to parse initialisation arguments[%s]",
     554                 :            :                         input_args);
     555                 :          0 :                 return -EINVAL;
     556                 :            :         }
     557                 :            : 
     558                 :          0 :         return zlib_create(name, vdev, &init_params);
     559                 :            : }
     560                 :            : 
     561                 :            : static int
     562         [ #  # ]:          0 : zlib_remove(struct rte_vdev_device *vdev)
     563                 :            : {
     564                 :            :         struct rte_compressdev *compressdev;
     565                 :            :         const char *name;
     566                 :            : 
     567                 :            :         name = rte_vdev_device_name(vdev);
     568                 :            :         if (name == NULL)
     569                 :            :                 return -EINVAL;
     570                 :            : 
     571                 :          0 :         compressdev = rte_compressdev_pmd_get_named_dev(name);
     572         [ #  # ]:          0 :         if (compressdev == NULL)
     573                 :            :                 return -ENODEV;
     574                 :            : 
     575                 :          0 :         return rte_compressdev_pmd_destroy(compressdev);
     576                 :            : }
     577                 :            : 
     578                 :            : static struct rte_vdev_driver zlib_pmd_drv = {
     579                 :            :         .probe = zlib_probe,
     580                 :            :         .remove = zlib_remove
     581                 :            : };
     582                 :            : 
     583                 :        253 : RTE_PMD_REGISTER_VDEV(COMPRESSDEV_NAME_ZLIB_PMD, zlib_pmd_drv);
     584         [ -  + ]:        253 : RTE_LOG_REGISTER_DEFAULT(zlib_logtype_driver, INFO);

Generated by: LCOV version 1.14