LCOV - code coverage report
Current view: top level - drivers/compress/zlib - zlib_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 254 0.8 %
Date: 2025-12-01 19:08:10 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                 :          0 :         free(dictionary);
     130                 :            : }
     131                 :            : 
     132                 :            : static void
     133                 :          0 : process_zlib_deflate(struct rte_comp_op *op, z_stream *strm)
     134                 :            : {
     135                 :            :         int ret, flush, fin_flush;
     136                 :            :         unsigned long total_in_at_start, total_out_at_start;
     137                 :          0 :         struct rte_mbuf *mbuf_src = op->m_src;
     138                 :          0 :         struct rte_mbuf *mbuf_dst = op->m_dst;
     139                 :            : 
     140      [ #  #  # ]:          0 :         switch (op->flush_flag) {
     141                 :            :         case RTE_COMP_FLUSH_FULL:
     142                 :            :         case RTE_COMP_FLUSH_FINAL:
     143                 :            :                 fin_flush = Z_FINISH;
     144                 :            :                 break;
     145                 :          0 :         case RTE_COMP_FLUSH_SYNC:
     146                 :            :                 fin_flush = Z_SYNC_FLUSH;
     147                 :          0 :                 break;
     148                 :          0 :         default:
     149                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     150                 :          0 :                 ZLIB_PMD_ERR("Invalid flush value");
     151                 :          0 :                 return;
     152                 :            :         }
     153                 :            : 
     154         [ #  # ]:          0 :         if (unlikely(!strm)) {
     155                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     156                 :          0 :                 ZLIB_PMD_ERR("Invalid z_stream");
     157                 :          0 :                 return;
     158                 :            :         }
     159                 :            :         /* Update z_stream with the inputs provided by application */
     160                 :          0 :         strm->next_in = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
     161                 :            :                         op->src.offset);
     162                 :            : 
     163                 :          0 :         strm->avail_in = rte_pktmbuf_data_len(mbuf_src) - op->src.offset;
     164                 :            : 
     165                 :          0 :         strm->next_out = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
     166                 :            :                         op->dst.offset);
     167                 :            : 
     168                 :          0 :         strm->avail_out = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset;
     169                 :            : 
     170                 :          0 :         total_in_at_start = strm->total_in;
     171                 :          0 :         total_out_at_start = strm->total_out;
     172                 :            : 
     173                 :            :         /* Set flush value to NO_FLUSH unless it is last mbuf */
     174                 :            :         flush = Z_NO_FLUSH;
     175                 :            :         /* Initialize status to SUCCESS */
     176                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
     177                 :            : 
     178                 :            :         do {
     179                 :            :                 /* Set flush value to Z_FINISH for last block */
     180         [ #  # ]:          0 :                 if ((op->src.length - (strm->total_in - total_in_at_start)) <= strm->avail_in) {
     181                 :          0 :                         strm->avail_in = (op->src.length - (strm->total_in - total_in_at_start));
     182                 :            :                         flush = fin_flush;
     183                 :            :                 }
     184                 :            :                 do {
     185                 :          0 :                         ret = deflate(strm, flush);
     186         [ #  # ]:          0 :                         if (unlikely(ret == Z_STREAM_ERROR)) {
     187                 :            :                                 /* error return, do not process further */
     188                 :          0 :                                 op->status =  RTE_COMP_OP_STATUS_ERROR;
     189                 :          0 :                                 goto def_end;
     190                 :            :                         }
     191                 :            :                         /* Break if Z_STREAM_END is encountered */
     192         [ #  # ]:          0 :                         if (ret == Z_STREAM_END)
     193                 :          0 :                                 goto def_end;
     194                 :            : 
     195                 :            :                 /* Keep looping until input mbuf is consumed.
     196                 :            :                  * Exit if destination mbuf gets exhausted.
     197                 :            :                  */
     198         [ #  # ]:          0 :                 } while ((strm->avail_out == 0) &&
     199   [ #  #  #  # ]:          0 :                         COMPUTE_BUF(mbuf_dst, strm->next_out, strm->avail_out));
     200                 :            : 
     201         [ #  # ]:          0 :                 if (!strm->avail_out) {
     202                 :            :                         /* there is no space for compressed output */
     203                 :          0 :                         op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
     204                 :          0 :                         break;
     205                 :            :                 }
     206                 :            : 
     207                 :            :         /* Update source buffer to next mbuf
     208                 :            :          * Exit if input buffers are fully consumed
     209                 :            :          */
     210   [ #  #  #  # ]:          0 :         } while (COMPUTE_BUF(mbuf_src, strm->next_in, strm->avail_in));
     211                 :            : 
     212                 :          0 : def_end:
     213                 :            :         /* Update op stats */
     214      [ #  #  # ]:          0 :         switch (op->status) {
     215                 :          0 :         case RTE_COMP_OP_STATUS_SUCCESS:
     216                 :          0 :                 op->consumed += strm->total_in - total_in_at_start;
     217                 :            :         /* Fall-through */
     218                 :          0 :         case RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED:
     219                 :          0 :                 op->produced += strm->total_out - total_out_at_start;
     220                 :          0 :                 break;
     221                 :          0 :         default:
     222                 :          0 :                 ZLIB_PMD_ERR("stats not updated for status:%d",
     223                 :            :                                 op->status);
     224                 :            :         }
     225                 :            : 
     226         [ #  # ]:          0 :         if (op->flush_flag != RTE_COMP_FLUSH_SYNC)
     227                 :          0 :                 deflateReset(strm);
     228                 :            : }
     229                 :            : 
     230                 :            : static void
     231                 :          0 : process_zlib_inflate(struct rte_comp_op *op, z_stream *strm)
     232                 :            : {
     233                 :            :         int ret, flush;
     234                 :            :         unsigned long total_in_at_start, total_out_at_start;
     235                 :          0 :         struct rte_mbuf *mbuf_src = op->m_src;
     236                 :          0 :         struct rte_mbuf *mbuf_dst = op->m_dst;
     237                 :            : 
     238         [ #  # ]:          0 :         if (unlikely(!strm)) {
     239                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     240                 :          0 :                 ZLIB_PMD_ERR("Invalid z_stream");
     241                 :          0 :                 return;
     242                 :            :         }
     243                 :          0 :         strm->next_in = rte_pktmbuf_mtod_offset(mbuf_src, uint8_t *,
     244                 :            :                         op->src.offset);
     245                 :            : 
     246                 :          0 :         strm->avail_in = rte_pktmbuf_data_len(mbuf_src) - op->src.offset;
     247                 :            : 
     248                 :          0 :         strm->next_out = rte_pktmbuf_mtod_offset(mbuf_dst, uint8_t *,
     249                 :            :                         op->dst.offset);
     250                 :            : 
     251                 :          0 :         strm->avail_out = rte_pktmbuf_data_len(mbuf_dst) - op->dst.offset;
     252                 :            : 
     253                 :          0 :         total_in_at_start = strm->total_in;
     254                 :          0 :         total_out_at_start = strm->total_out;
     255                 :            : 
     256                 :            :         /** Ignoring flush value provided from application for decompression */
     257                 :            :         flush = Z_NO_FLUSH;
     258                 :            :         /* initialize status to SUCCESS */
     259                 :          0 :         op->status = RTE_COMP_OP_STATUS_SUCCESS;
     260                 :            : 
     261                 :            :         do {
     262                 :            :                 do {
     263                 :          0 :                         ret = inflate(strm, flush);
     264                 :            : 
     265      [ #  #  # ]:          0 :                         switch (ret) {
     266                 :            :                         /* Fall-through */
     267                 :            :                         case Z_NEED_DICT:
     268                 :            :                                 ret = Z_DATA_ERROR;
     269                 :            :                         /* Fall-through */
     270                 :          0 :                         case Z_DATA_ERROR:
     271                 :            :                         /* Fall-through */
     272                 :            :                         case Z_MEM_ERROR:
     273                 :            :                         /* Fall-through */
     274                 :            :                         case Z_STREAM_ERROR:
     275                 :          0 :                                 op->status = RTE_COMP_OP_STATUS_ERROR;
     276                 :            :                         /* Fall-through */
     277                 :          0 :                         case Z_STREAM_END:
     278                 :            :                                 /* no further computation needed if
     279                 :            :                                  * Z_STREAM_END is encountered
     280                 :            :                                  */
     281                 :          0 :                                 goto inf_end;
     282                 :            :                         default:
     283                 :            :                                 /* success */
     284                 :            :                                 break;
     285                 :            : 
     286                 :            :                         }
     287                 :            :                 /* Keep looping until input mbuf is consumed.
     288                 :            :                  * Exit if destination mbuf gets exhausted.
     289                 :            :                  */
     290         [ #  # ]:          0 :                 } while ((strm->avail_out == 0) &&
     291   [ #  #  #  # ]:          0 :                         COMPUTE_BUF(mbuf_dst, strm->next_out, strm->avail_out));
     292                 :            : 
     293         [ #  # ]:          0 :                 if (!strm->avail_out) {
     294                 :            :                         /* there is no more space for decompressed output */
     295                 :          0 :                         op->status = RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED;
     296                 :          0 :                         break;
     297                 :            :                 }
     298                 :            :         /* Read next input buffer to be processed, exit if compressed
     299                 :            :          * blocks are fully read
     300                 :            :          */
     301   [ #  #  #  # ]:          0 :         } while (COMPUTE_BUF(mbuf_src, strm->next_in, strm->avail_in));
     302                 :            : 
     303                 :          0 : inf_end:
     304                 :            :         /* Update op stats */
     305      [ #  #  # ]:          0 :         switch (op->status) {
     306                 :          0 :         case RTE_COMP_OP_STATUS_SUCCESS:
     307                 :          0 :                 op->consumed += strm->total_in - total_in_at_start;
     308                 :            :         /* Fall-through */
     309                 :          0 :         case RTE_COMP_OP_STATUS_OUT_OF_SPACE_TERMINATED:
     310                 :          0 :                 op->produced += strm->total_out - total_out_at_start;
     311                 :          0 :                 break;
     312                 :          0 :         default:
     313                 :          0 :                 ZLIB_PMD_ERR("stats not produced for status:%d",
     314                 :            :                                 op->status);
     315                 :            :         }
     316                 :            : 
     317         [ #  # ]:          0 :         if (op->flush_flag != RTE_COMP_FLUSH_SYNC)
     318                 :          0 :                 inflateReset(strm);
     319                 :            : }
     320                 :            : 
     321                 :            : /** Process comp operation for mbuf */
     322                 :            : static inline int
     323                 :          0 : process_zlib_op(struct zlib_qp *qp, struct rte_comp_op *op)
     324                 :            : {
     325                 :            :         struct zlib_stream *stream;
     326                 :            :         struct zlib_priv_xform *private_xform;
     327                 :            : 
     328         [ #  # ]:          0 :         if ((op->op_type == RTE_COMP_OP_STATEFUL) ||
     329         [ #  # ]:          0 :                         (op->src.offset > rte_pktmbuf_data_len(op->m_src)) ||
     330         [ #  # ]:          0 :                         (op->dst.offset > rte_pktmbuf_data_len(op->m_dst))) {
     331                 :          0 :                 op->status = RTE_COMP_OP_STATUS_INVALID_ARGS;
     332                 :          0 :                 ZLIB_PMD_ERR("Invalid source or destination buffers or "
     333                 :            :                                   "invalid Operation requested");
     334                 :            :         } else {
     335                 :          0 :                 private_xform = (struct zlib_priv_xform *)op->private_xform;
     336                 :            :                 stream = &private_xform->stream;
     337                 :          0 :                 stream->chksum(op, &stream->strm, stream->chksum_type);
     338         [ #  # ]:          0 :                 if (op->status != RTE_COMP_OP_STATUS_SUCCESS)
     339                 :            :                         return -1;
     340                 :            : 
     341                 :          0 :                 stream->comp(op, &stream->strm);
     342                 :            :         }
     343                 :            :         /* whatever is out of op, put it into completion queue with
     344                 :            :          * its status
     345                 :            :          */
     346   [ #  #  #  #  :          0 :         return rte_ring_enqueue(qp->processed_pkts, (void *)op);
                      # ]
     347                 :            : }
     348                 :            : 
     349                 :            : /** Parse comp xform and set private xform/Stream parameters */
     350                 :            : int
     351                 :          0 : zlib_set_stream_parameters(const struct rte_comp_xform *xform,
     352                 :            :                 struct zlib_stream *stream)
     353                 :            : {
     354                 :            :         int strategy, level, wbits;
     355                 :          0 :         z_stream *strm = &stream->strm;
     356                 :            : 
     357                 :            :         /* allocate deflate state */
     358                 :          0 :         strm->zalloc = Z_NULL;
     359                 :          0 :         strm->zfree = Z_NULL;
     360                 :          0 :         strm->opaque = Z_NULL;
     361                 :            : 
     362      [ #  #  # ]:          0 :         switch (xform->type) {
     363                 :          0 :         case RTE_COMP_COMPRESS:
     364                 :          0 :                 stream->comp = process_zlib_deflate;
     365                 :          0 :                 stream->free = deflateEnd;
     366                 :          0 :                 stream->chksum = process_zlib_deflate_chksum;
     367                 :            :                 /** Compression window bits */
     368         [ #  # ]:          0 :                 switch (xform->compress.algo) {
     369                 :          0 :                 case RTE_COMP_ALGO_DEFLATE:
     370                 :          0 :                         wbits = -(xform->compress.window_size);
     371                 :            :                         break;
     372                 :          0 :                 default:
     373                 :          0 :                         ZLIB_PMD_ERR("Compression algorithm not supported");
     374                 :          0 :                         return -1;
     375                 :            :                 }
     376                 :            :                 /** Compression Level */
     377   [ #  #  #  #  :          0 :                 switch (xform->compress.level) {
                      # ]
     378                 :            :                 case RTE_COMP_LEVEL_PMD_DEFAULT:
     379                 :            :                         level = Z_DEFAULT_COMPRESSION;
     380                 :            :                         break;
     381                 :          0 :                 case RTE_COMP_LEVEL_NONE:
     382                 :            :                         level = Z_NO_COMPRESSION;
     383                 :          0 :                         break;
     384                 :          0 :                 case RTE_COMP_LEVEL_MIN:
     385                 :            :                         level = Z_BEST_SPEED;
     386                 :          0 :                         break;
     387                 :          0 :                 case RTE_COMP_LEVEL_MAX:
     388                 :            :                         level = Z_BEST_COMPRESSION;
     389                 :          0 :                         break;
     390                 :          0 :                 default:
     391                 :            :                         level = xform->compress.level;
     392         [ #  # ]:          0 :                         if (level < RTE_COMP_LEVEL_MIN ||
     393                 :            :                                         level > RTE_COMP_LEVEL_MAX) {
     394                 :          0 :                                 ZLIB_PMD_ERR("Compression level %d "
     395                 :            :                                                 "not supported",
     396                 :            :                                                 level);
     397                 :          0 :                                 return -1;
     398                 :            :                         }
     399                 :            :                         break;
     400                 :            :                 }
     401                 :            :                 /** Compression strategy */
     402      [ #  #  # ]:          0 :                 switch (xform->compress.deflate.huffman) {
     403                 :            :                 case RTE_COMP_HUFFMAN_DEFAULT:
     404                 :            :                         strategy = Z_DEFAULT_STRATEGY;
     405                 :            :                         break;
     406                 :          0 :                 case RTE_COMP_HUFFMAN_FIXED:
     407                 :            :                         strategy = Z_FIXED;
     408                 :          0 :                         break;
     409                 :            :                 case RTE_COMP_HUFFMAN_DYNAMIC:
     410                 :            :                         strategy = Z_DEFAULT_STRATEGY;
     411                 :            :                         break;
     412                 :          0 :                 default:
     413                 :          0 :                         ZLIB_PMD_ERR("Compression strategy not supported");
     414                 :          0 :                         return -1;
     415                 :            :                 }
     416                 :            : 
     417                 :            :                 /** Checksum used */
     418                 :          0 :                 stream->chksum_type = xform->compress.chksum;
     419                 :            : 
     420         [ #  # ]:          0 :                 if (deflateInit2(strm, level,
     421                 :            :                                         Z_DEFLATED, wbits,
     422                 :            :                                         DEF_MEM_LEVEL, strategy) != Z_OK) {
     423                 :          0 :                         ZLIB_PMD_ERR("Deflate init failed");
     424                 :          0 :                         return -1;
     425                 :            :                 }
     426                 :            : 
     427         [ #  # ]:          0 :                 if (xform->compress.deflate.dictionary) {
     428         [ #  # ]:          0 :                         if (deflateSetDictionary(strm, xform->compress.deflate.dictionary,
     429                 :          0 :                                         xform->compress.deflate.dictionary_len)) {
     430                 :          0 :                                 ZLIB_PMD_ERR("Deflate set dictionary failed");
     431                 :          0 :                                 return -1;
     432                 :            :                         }
     433                 :            :                 }
     434                 :            :                 break;
     435                 :            : 
     436                 :          0 :         case RTE_COMP_DECOMPRESS:
     437                 :          0 :                 stream->comp = process_zlib_inflate;
     438                 :          0 :                 stream->free = inflateEnd;
     439                 :          0 :                 stream->chksum = process_zlib_inflate_chksum;
     440                 :            :                 /** window bits */
     441         [ #  # ]:          0 :                 switch (xform->decompress.algo) {
     442                 :          0 :                 case RTE_COMP_ALGO_DEFLATE:
     443                 :          0 :                         wbits = -(xform->decompress.window_size);
     444                 :            :                         break;
     445                 :          0 :                 default:
     446                 :          0 :                         ZLIB_PMD_ERR("Compression algorithm not supported");
     447                 :          0 :                         return -1;
     448                 :            :                 }
     449                 :            : 
     450                 :            :                 /** Checksum used */
     451                 :          0 :                 stream->chksum_type = xform->decompress.chksum;
     452                 :            : 
     453         [ #  # ]:          0 :                 if (inflateInit2(strm, wbits) != Z_OK) {
     454                 :          0 :                         ZLIB_PMD_ERR("Inflate init failed");
     455                 :          0 :                         return -1;
     456                 :            :                 }
     457                 :            : 
     458         [ #  # ]:          0 :                 if (xform->decompress.inflate.dictionary) {
     459         [ #  # ]:          0 :                         if (inflateSetDictionary(strm, xform->decompress.inflate.dictionary,
     460                 :          0 :                                         xform->decompress.inflate.dictionary_len)) {
     461                 :          0 :                                 ZLIB_PMD_ERR("inflate set dictionary failed");
     462                 :          0 :                                 return -1;
     463                 :            :                         }
     464                 :            :                 }
     465                 :            :                 break;
     466                 :            :         default:
     467                 :            :                 return -1;
     468                 :            :         }
     469                 :            :         return 0;
     470                 :            : }
     471                 :            : 
     472                 :            : static uint16_t
     473                 :          0 : zlib_pmd_enqueue_burst(void *queue_pair,
     474                 :            :                         struct rte_comp_op **ops, uint16_t nb_ops)
     475                 :            : {
     476                 :            :         struct zlib_qp *qp = queue_pair;
     477                 :            :         int ret;
     478                 :            :         uint16_t i;
     479                 :            :         uint16_t enqd = 0;
     480         [ #  # ]:          0 :         for (i = 0; i < nb_ops; i++) {
     481                 :          0 :                 ret = process_zlib_op(qp, ops[i]);
     482         [ #  # ]:          0 :                 if (unlikely(ret < 0)) {
     483                 :            :                         /* increment count if failed to push to completion
     484                 :            :                          * queue
     485                 :            :                          */
     486                 :          0 :                         qp->qp_stats.enqueue_err_count++;
     487                 :            :                 } else {
     488                 :          0 :                         qp->qp_stats.enqueued_count++;
     489                 :          0 :                         enqd++;
     490                 :            :                 }
     491                 :            :         }
     492                 :          0 :         return enqd;
     493                 :            : }
     494                 :            : 
     495                 :            : static uint16_t
     496                 :          0 : zlib_pmd_dequeue_burst(void *queue_pair,
     497                 :            :                         struct rte_comp_op **ops, uint16_t nb_ops)
     498                 :            : {
     499                 :            :         struct zlib_qp *qp = queue_pair;
     500                 :            : 
     501                 :            :         unsigned int nb_dequeued = 0;
     502                 :            : 
     503   [ #  #  #  #  :          0 :         nb_dequeued = rte_ring_dequeue_burst(qp->processed_pkts,
                      # ]
     504                 :            :                         (void **)ops, nb_ops, NULL);
     505                 :          0 :         qp->qp_stats.dequeued_count += nb_dequeued;
     506                 :            : 
     507                 :          0 :         return nb_dequeued;
     508                 :            : }
     509                 :            : 
     510                 :            : static int
     511                 :          0 : zlib_create(const char *name,
     512                 :            :                 struct rte_vdev_device *vdev,
     513                 :            :                 struct rte_compressdev_pmd_init_params *init_params)
     514                 :            : {
     515                 :            :         struct rte_compressdev *dev;
     516                 :            : 
     517                 :          0 :         dev = rte_compressdev_pmd_create(name, &vdev->device,
     518                 :            :                         sizeof(struct zlib_private), init_params);
     519         [ #  # ]:          0 :         if (dev == NULL) {
     520                 :          0 :                 ZLIB_PMD_ERR("driver %s: create failed", init_params->name);
     521                 :          0 :                 return -ENODEV;
     522                 :            :         }
     523                 :            : 
     524                 :          0 :         dev->dev_ops = rte_zlib_pmd_ops;
     525                 :            : 
     526                 :            :         /* register rx/tx burst functions for data path */
     527                 :          0 :         dev->dequeue_burst = zlib_pmd_dequeue_burst;
     528                 :          0 :         dev->enqueue_burst = zlib_pmd_enqueue_burst;
     529                 :            : 
     530                 :          0 :         return 0;
     531                 :            : }
     532                 :            : 
     533                 :            : static int
     534                 :          0 : zlib_probe(struct rte_vdev_device *vdev)
     535                 :            : {
     536                 :          0 :         struct rte_compressdev_pmd_init_params init_params = {
     537                 :            :                 "",
     538         [ #  # ]:          0 :                 rte_socket_id()
     539                 :            :         };
     540                 :            :         const char *name;
     541                 :            :         const char *input_args;
     542                 :            :         int retval;
     543                 :            : 
     544                 :            :         name = rte_vdev_device_name(vdev);
     545                 :            : 
     546                 :            :         if (name == NULL)
     547                 :            :                 return -EINVAL;
     548                 :            : 
     549                 :            :         input_args = rte_vdev_device_args(vdev);
     550                 :            : 
     551                 :          0 :         retval = rte_compressdev_pmd_parse_input_args(&init_params, input_args);
     552         [ #  # ]:          0 :         if (retval < 0) {
     553                 :          0 :                 ZLIB_PMD_LOG(ERR,
     554                 :            :                         "Failed to parse initialisation arguments[%s]",
     555                 :            :                         input_args);
     556                 :          0 :                 return -EINVAL;
     557                 :            :         }
     558                 :            : 
     559                 :          0 :         return zlib_create(name, vdev, &init_params);
     560                 :            : }
     561                 :            : 
     562                 :            : static int
     563         [ #  # ]:          0 : zlib_remove(struct rte_vdev_device *vdev)
     564                 :            : {
     565                 :            :         struct rte_compressdev *compressdev;
     566                 :            :         const char *name;
     567                 :            : 
     568                 :            :         name = rte_vdev_device_name(vdev);
     569                 :            :         if (name == NULL)
     570                 :            :                 return -EINVAL;
     571                 :            : 
     572                 :          0 :         compressdev = rte_compressdev_pmd_get_named_dev(name);
     573         [ #  # ]:          0 :         if (compressdev == NULL)
     574                 :            :                 return -ENODEV;
     575                 :            : 
     576                 :          0 :         return rte_compressdev_pmd_destroy(compressdev);
     577                 :            : }
     578                 :            : 
     579                 :            : static struct rte_vdev_driver zlib_pmd_drv = {
     580                 :            :         .probe = zlib_probe,
     581                 :            :         .remove = zlib_remove
     582                 :            : };
     583                 :            : 
     584                 :        254 : RTE_PMD_REGISTER_VDEV(COMPRESSDEV_NAME_ZLIB_PMD, zlib_pmd_drv);
     585         [ -  + ]:        254 : RTE_LOG_REGISTER_DEFAULT(zlib_logtype_driver, INFO);

Generated by: LCOV version 1.14