NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
compress_common.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <string.h>
30 #include <time.h>
31 
32 #include <doca_buf.h>
33 #include <doca_ctx.h>
34 #include <doca_log.h>
35 #include <doca_error.h>
36 #include <doca_pe.h>
37 #include <doca_argp.h>
38 #include <doca_compress.h>
39 
40 #include "../common.h"
41 #include "compress_common.h"
42 
43 DOCA_LOG_REGISTER(COMPRESS::COMMON);
44 
45 /*
46  * Compression Method and Flags (CMF) defines for the Zlib header
47  */
48 #define ZLIB_CMF_CM 8 /* Compression Method - DEFLATE compression */
49 #define ZLIB_CMF_CINFO \
50  7 /* For DEFLATE compression (CM=8), CINFO is the base-2 logarithm of the LZ77 \
51  * window size, minus eight. CINFO=7 indicates a 32K window size \
52  */
53 #define ZLIB_CMF_CM_MASK 0x0F /* Mask for Compression Method bits in the CMF byte */
54 #define ZLIB_CMF_CINFO_MASK 0xF0 /* Mask for Compression Info bits in the CMF byte */
55 #define ZLIB_CMF_CINFO_SHIFT 4 /* Shift for Compression Info bits in the CMF byte */
56 
57 /*
58  * Flags (FLG) defines for the Zlib header
59  */
60 #define ZLIB_FLG_FLEVEL 2 /* Use the default algorithm for the DEFLATE compression method (CM=8) */
61 #define ZLIB_FLG_FDICT \
62  0 /* Represents whether the DICT dictionary identifier is present immediately \
63  * after the FLG byte. It indicates that no preset dictionary is used \
64  */
65 #define ZLIB_FLG_FCHECK_MASK 0x1F /* Mask for FCHECK bits in the FLG byte */
66 #define ZLIB_FLG_FDICT_MASK 0x20 /* Mask for FDICT flag in the FLG byte */
67 #define ZLIB_FLG_FDICT_SHIFT 5 /* Shift for FDICT flag in the FLG byte */
68 #define ZLIB_FLG_FLEVEL_MASK 0xC0 /* Mask for FLEVEL bits in the FLG byte */
69 #define ZLIB_FLG_FLEVEL_SHIFT 6 /* Shift for FLEVEL bits in the FLG byte */
70 
71 /*
72  * LZ4 frame format defines
73  */
74 #define LZ4_MAGIC_NUMBER 0x184D2204 /* Magic number for LZ4 files */
75 #define LZ4_VERSION_NUMER 0x01 /* The LZ4 frame format version */
76 
77 #define LZ4_FLAGS_DICT_ID_MASK 0x1 /* Mask for dictionary ID bits in the FLG byte */
78 #define LZ4_FLAGS_CONTENT_CHECKSUM_SHIFT 2 /* Shift for content checksum flag bit in the FLG byte */
79 #define LZ4_FLAGS_CONTENT_CHECKSUM_MASK 0x4 /* Mask for content checksum flag bit in the FLG byte */
80 #define LZ4_FLAGS_CONTENT_SIZE_SHIFT 3 /* Shift for content size flag bit in the FLG byte */
81 #define LZ4_FLAGS_CONTENT_SIZE_MASK 0x8 /* Mask for content size flag bit in the FLG byte */
82 #define LZ4_FLAGS_BLOCK_CHECKSUM_SHIFT 4 /* Shift for block checksum flag bit in the FLG byte */
83 #define LZ4_FLAGS_BLOCK_CHECKSUM_MASK 0x10 /* Mask for block checksum flag bit in the FLG byte */
84 #define LZ4_FLAGS_BLOCK_INDEPENDENT_SHIFT 5 /* Shift for block independent flag bit in the FLG byte */
85 #define LZ4_FLAGS_BLOCK_INDEPENDENT_MASK 0x20 /* Mask for block independent flag bit in the FLG byte */
86 #define LZ4_FLAGS_VERSION_NUMBER_SHIFT 6 /* Shift for version number bits in the FLG byte */
87 #define LZ4_FLAGS_VERSION_NUMBER_MASK 0xC0 /* Mask for version number bits in the FLG byte */
88 
89 #define LZ4_END_MARK_LEN 4 /* The length of the end mark */
90 
91 /* Describes result of a compress/decompress deflate task */
94  uint32_t crc_cs;
95  uint32_t adler_cs;
96 };
97 
98 /* Describes result of a decompress lz4 tasks */
99 struct compress_lz4_result {
101  uint32_t crc_cs;
102  uint32_t xxh_cs;
103 };
104 
105 /*
106  * ARGP Callback - Handle PCI device address parameter
107  *
108  * @param [in]: Input parameter
109  * @config [in/out]: Program configuration context
110  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
111  */
112 static doca_error_t pci_address_callback(void *param, void *config)
113 {
114  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
115  char *pci_address = (char *)param;
116  int len;
117 
120  DOCA_LOG_ERR("Entered device PCI address exceeding the maximum size of %d",
123  }
124  strncpy(compress_cfg->pci_address, pci_address, len + 1);
125  return DOCA_SUCCESS;
126 }
127 
128 /*
129  * ARGP Callback - Handle user file parameter
130  *
131  * @param [in]: Input parameter
132  * @config [in/out]: Program configuration context
133  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
134  */
135 static doca_error_t file_callback(void *param, void *config)
136 {
137  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
138  char *file = (char *)param;
139  int len;
140 
141  len = strnlen(file, MAX_FILE_NAME);
142  if (len == MAX_FILE_NAME) {
143  DOCA_LOG_ERR("Invalid file name length, max %d", USER_MAX_FILE_NAME);
145  }
146  strcpy(compress_cfg->file_path, file);
147  return DOCA_SUCCESS;
148 }
149 
150 /*
151  * ARGP Callback - Handle output file parameter
152  *
153  * @param [in]: Input parameter
154  * @config [in/out]: Program configuration context
155  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
156  */
157 static doca_error_t output_callback(void *param, void *config)
158 {
159  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
160  char *file = (char *)param;
161  int len;
162 
163  len = strnlen(file, MAX_FILE_NAME);
164  if (len == MAX_FILE_NAME) {
165  DOCA_LOG_ERR("Invalid file name length, max %d", USER_MAX_FILE_NAME);
167  }
168  strcpy(compress_cfg->output_path, file);
169  return DOCA_SUCCESS;
170 }
171 
172 /*
173  * ARGP Callback - Handle output checksum parameter
174  *
175  * @param [in]: Input parameter
176  * @config [in/out]: Program configuration context
177  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
178  */
179 static doca_error_t output_checksum_callback(void *param, void *config)
180 {
181  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
182  bool output_checksum = *((bool *)param);
183 
185 
186  return DOCA_SUCCESS;
187 }
188 
189 /*
190  * Register the command line parameters for the sample.
191  *
192  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
193  */
195 {
197  struct doca_argp_param *pci_param, *file_param, *output_param, *output_checksum_param;
198 
199  result = doca_argp_param_create(&pci_param);
200  if (result != DOCA_SUCCESS) {
201  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
202  return result;
203  }
204  doca_argp_param_set_short_name(pci_param, "p");
205  doca_argp_param_set_long_name(pci_param, "pci-addr");
206  doca_argp_param_set_description(pci_param, "DOCA device PCI device address");
209  result = doca_argp_register_param(pci_param);
210  if (result != DOCA_SUCCESS) {
211  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
212  return result;
213  }
214 
215  result = doca_argp_param_create(&file_param);
216  if (result != DOCA_SUCCESS) {
217  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
218  return result;
219  }
220  doca_argp_param_set_short_name(file_param, "f");
221  doca_argp_param_set_long_name(file_param, "file");
222  doca_argp_param_set_description(file_param, "Input file to compress/decompress");
225  result = doca_argp_register_param(file_param);
226  if (result != DOCA_SUCCESS) {
227  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
228  return result;
229  }
230 
231  result = doca_argp_param_create(&output_param);
232  if (result != DOCA_SUCCESS) {
233  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
234  return result;
235  }
236  doca_argp_param_set_short_name(output_param, "o");
237  doca_argp_param_set_long_name(output_param, "output");
238  doca_argp_param_set_description(output_param, "Output file");
241  result = doca_argp_register_param(output_param);
242  if (result != DOCA_SUCCESS) {
243  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
244  return result;
245  }
246 
247  result = doca_argp_param_create(&output_checksum_param);
248  if (result != DOCA_SUCCESS) {
249  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
250  return result;
251  }
252  doca_argp_param_set_short_name(output_checksum_param, "c");
253  doca_argp_param_set_long_name(output_checksum_param, "output-checksum");
254  doca_argp_param_set_description(output_checksum_param, "Output checksum");
256  doca_argp_param_set_type(output_checksum_param, DOCA_ARGP_TYPE_BOOLEAN);
257  result = doca_argp_register_param(output_checksum_param);
258  if (result != DOCA_SUCCESS) {
259  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
260  return result;
261  }
262 
263  return DOCA_SUCCESS;
264 }
265 
266 /*
267  * ARGP Callback - Handle with-frame parameter
268  *
269  * @param [in]: Input parameter
270  * @config [in/out]: Program configuration context
271  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
272  */
273 static doca_error_t is_with_frame_callback(void *param, void *config)
274 {
275  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
276  bool is_with_frame = *((bool *)param);
277 
279 
280  return DOCA_SUCCESS;
281 }
282 
283 /*
284  * Register the command line parameters for the sample.
285  *
286  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
287  */
289 {
291  struct doca_argp_param *is_with_frame;
292 
293  result = doca_argp_param_create(&is_with_frame);
294  if (result != DOCA_SUCCESS) {
295  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
296  return result;
297  }
298  doca_argp_param_set_short_name(is_with_frame, "wf");
299  doca_argp_param_set_long_name(is_with_frame, "with-frame");
300  doca_argp_param_set_description(is_with_frame,
301  "Write/read a file with a frame, compatible with default zlib settings");
304  result = doca_argp_register_param(is_with_frame);
305  if (result != DOCA_SUCCESS) {
306  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
307  return result;
308  }
309 
310  return DOCA_SUCCESS;
311 }
312 
313 /*
314  * ARGP Callback - Handle has_block_checksum parameter
315  *
316  * @param [in]: Input parameter
317  * @config [in/out]: Program configuration context
318  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
319  */
320 static doca_error_t has_block_checksum_callback(void *param, void *config)
321 {
322  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
323  bool has_block_checksum = *((bool *)param);
324 
326 
327  return DOCA_SUCCESS;
328 }
329 
330 /*
331  * ARGP Callback - Handle are_blocks_independent parameter
332  *
333  * @param [in]: Input parameter
334  * @config [in/out]: Program configuration context
335  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
336  */
337 static doca_error_t are_blocks_independent_callback(void *param, void *config)
338 {
339  struct compress_cfg *compress_cfg = (struct compress_cfg *)config;
340  bool are_blocks_independent = *((bool *)param);
341 
343 
344  return DOCA_SUCCESS;
345 }
346 
347 /*
348  * Register the command line parameters for the sample.
349  *
350  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
351  */
353 {
355  struct doca_argp_param *is_with_frame;
356  struct doca_argp_param *has_block_checksum;
357  struct doca_argp_param *are_blocks_independent;
358 
359  result = doca_argp_param_create(&is_with_frame);
360  if (result != DOCA_SUCCESS) {
361  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
362  return result;
363  }
364  doca_argp_param_set_short_name(is_with_frame, "wf");
365  doca_argp_param_set_long_name(is_with_frame, "with-frame");
366  doca_argp_param_set_description(is_with_frame, "Read a file compatible with an LZ4 frame");
369  result = doca_argp_register_param(is_with_frame);
370  if (result != DOCA_SUCCESS) {
371  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
372  return result;
373  }
374 
375  result = doca_argp_param_create(&has_block_checksum);
376  if (result != DOCA_SUCCESS) {
377  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
378  return result;
379  }
380  doca_argp_param_set_short_name(has_block_checksum, "bc");
381  doca_argp_param_set_long_name(has_block_checksum, "has-block-checksum");
383  has_block_checksum,
384  "Flag to indicate if blocks have a checksum. Valid only when the sample is run without the with-frame(wf) flag");
387  result = doca_argp_register_param(has_block_checksum);
388  if (result != DOCA_SUCCESS) {
389  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
390  return result;
391  }
392 
393  result = doca_argp_param_create(&are_blocks_independent);
394  if (result != DOCA_SUCCESS) {
395  DOCA_LOG_ERR("Failed to create ARGP param: %s", doca_error_get_descr(result));
396  return result;
397  }
398  doca_argp_param_set_short_name(are_blocks_independent, "bi");
399  doca_argp_param_set_long_name(are_blocks_independent, "are-blocks-independent");
401  are_blocks_independent,
402  "Flag to indicate if blocks are independent. Valid only when the sample is run without the with-frame(wf) flag");
404  doca_argp_param_set_type(are_blocks_independent, DOCA_ARGP_TYPE_BOOLEAN);
405  result = doca_argp_register_param(are_blocks_independent);
406  if (result != DOCA_SUCCESS) {
407  DOCA_LOG_ERR("Failed to register program param: %s", doca_error_get_descr(result));
408  return result;
409  }
410 
411  return DOCA_SUCCESS;
412 }
413 
414 /*
415  * Compute the FCHECK value for the filled zlib header.
416  * The FCHECK value must be such that CMF and FLG, when viewed as a 16-bit unsigned integer stored in MSB order
417  * (CMF*256 + FLG), is a multiple of 31
418  *
419  * @zlib_header [in]: A Zlib header to initiate with DOCA Compress default settings
420  * @return: The FCHECK value of a given zlib header
421  */
422 static inline uint8_t compute_zlib_header_fcheck(struct compress_zlib_header *zlib_header)
423 {
424  uint16_t sum = htobe16(*(uint16_t *)zlib_header) & ~ZLIB_FLG_FCHECK_MASK;
425  uint8_t fcheck = (31 - (sum % 31));
426 
427  return fcheck;
428 }
429 
430 /*
431  * Initiate the fields of the zlib header with default values
432  */
433 void init_compress_zlib_header(struct compress_zlib_header *zlib_header)
434 {
435  zlib_header->cmf = (ZLIB_CMF_CINFO << ZLIB_CMF_CINFO_SHIFT);
436  zlib_header->cmf |= ZLIB_CMF_CM;
437 
438  zlib_header->flg = (ZLIB_FLG_FLEVEL << ZLIB_FLG_FLEVEL_SHIFT);
439  zlib_header->flg |= (ZLIB_FLG_FDICT << ZLIB_FLG_FDICT_SHIFT);
440  zlib_header->flg |= compute_zlib_header_fcheck(zlib_header);
441 }
442 
443 /*
444  * Verify the header values are valid and compatible with DOCA compress
445  *
446  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
447  */
449 {
450  uint8_t computed_fcheck = compute_zlib_header_fcheck(zlib_header);
451 
452  if ((zlib_header->flg & ZLIB_FLG_FCHECK_MASK) != computed_fcheck) {
453  DOCA_LOG_ERR("Invalid header: header FCHECK=%u doesn't match expected FCHECK=%u",
454  (zlib_header->flg & ZLIB_FLG_FCHECK_MASK),
455  computed_fcheck);
457  }
458 
459  if (((zlib_header->flg & ZLIB_FLG_FDICT_MASK) >> ZLIB_FLG_FDICT_SHIFT) != ZLIB_FLG_FDICT) {
460  DOCA_LOG_ERR("Invalid header: DOCA compress doesn't support the use of dictionary identifiers");
462  }
463 
464  if (((zlib_header->flg & ZLIB_FLG_FLEVEL_MASK) >> ZLIB_FLG_FLEVEL_SHIFT) != ZLIB_FLG_FLEVEL) {
465  DOCA_LOG_ERR(
466  "Invalid header: DOCA compress supports only a default algorithm (FLEVEL=%u) yet FLEVEL=%u was given",
468  ((zlib_header->flg & ZLIB_FLG_FLEVEL_MASK) >> ZLIB_FLG_FLEVEL_SHIFT));
470  }
471 
472  if ((zlib_header->cmf & ZLIB_CMF_CM_MASK) != ZLIB_CMF_CM) {
473  DOCA_LOG_ERR(
474  "Invalid header: DOCA compress supports only DEFLATE compress method (CM=%u) yet CM=%u was given",
475  ZLIB_CMF_CM,
476  (zlib_header->cmf & ZLIB_CMF_CM_MASK));
478  }
479 
480  if (((zlib_header->cmf & ZLIB_CMF_CINFO_MASK) >> ZLIB_CMF_CINFO_SHIFT) > ZLIB_CMF_CINFO) {
481  DOCA_LOG_ERR(
482  "Invalid header: the given window size (CINFO=%u) may not be smaller than the window size used to compress with DOCA (CINFO=%u)",
483  ((zlib_header->cmf & ZLIB_CMF_CINFO_MASK) >> ZLIB_CMF_CINFO_SHIFT),
486  }
487 
488  return DOCA_SUCCESS;
489 }
490 
491 doca_error_t parse_lz4_frame(struct doca_buf *src_buf,
492  struct compress_cfg *cfg,
493  bool *has_content_checksum,
494  uint32_t *content_checksum)
495 {
497  bool has_content_size = false;
498  bool has_content_checksum_flag = false;
499  bool has_dict_id = false;
500  uint8_t flags = 0;
501  uint8_t version_number = 0;
502  uint32_t magic_number = 0;
503  uint64_t content_size = 0;
504  size_t src_buf_len = 0;
505  size_t total_frame_length = 0;
506  void *src_buf_addr = NULL;
507  uint8_t *start_addr = NULL;
508 
509  uint32_t frame_header_length = 0;
510  uint32_t frame_footer_length = 0;
511 
512  result = doca_buf_get_head(src_buf, &src_buf_addr);
513  if (result != DOCA_SUCCESS) {
514  DOCA_LOG_ERR("Failed to get buffer's address: %s", doca_error_get_descr(result));
515  return result;
516  }
517 
518  result = doca_buf_get_len(src_buf, &src_buf_len);
519  if (result != DOCA_SUCCESS) {
520  DOCA_LOG_ERR("Failed to get buffer's length: %s", doca_error_get_descr(result));
521  return result;
522  }
523 
524  start_addr = (uint8_t *)src_buf_addr;
525 
526  magic_number = (*(uint32_t *)start_addr);
527  frame_header_length += sizeof(uint32_t);
528  if (le32toh(magic_number) != LZ4_MAGIC_NUMBER) {
529  DOCA_LOG_ERR("Invalid header: magic number=%x doesn't match the expected LZ4 magic number=%x",
530  le32toh(magic_number),
533  }
534 
535  flags = *(start_addr + frame_header_length);
536  frame_header_length += sizeof(uint8_t);
537 
539  if (version_number != LZ4_VERSION_NUMER) {
540  DOCA_LOG_ERR("Invalid header: version=%x doesn't match the expected LZ4 version=%x",
541  version_number,
544  }
545 
546  cfg->are_blocks_independent = (flags & LZ4_FLAGS_BLOCK_INDEPENDENT_MASK) >> LZ4_FLAGS_BLOCK_INDEPENDENT_SHIFT;
547  cfg->has_block_checksum = (flags & LZ4_FLAGS_BLOCK_CHECKSUM_MASK) >> LZ4_FLAGS_BLOCK_CHECKSUM_SHIFT;
548 
549  has_content_size = (flags & LZ4_FLAGS_CONTENT_SIZE_MASK) >> LZ4_FLAGS_CONTENT_SIZE_SHIFT;
550  has_content_checksum_flag = (flags & LZ4_FLAGS_CONTENT_CHECKSUM_MASK) >> LZ4_FLAGS_CONTENT_CHECKSUM_SHIFT;
551  if (has_content_checksum != NULL)
552  *has_content_checksum = has_content_checksum_flag;
553 
554  has_dict_id = flags & LZ4_FLAGS_DICT_ID_MASK;
555  if (has_dict_id) {
556  DOCA_LOG_ERR("Data compressed using a dictionary is not supported");
558  }
559 
560  frame_header_length += sizeof(uint8_t); // BD byte - value is not utilized by DOCA Compress
561 
562  if (has_content_size) {
563  content_size = *((uint64_t *)(start_addr + frame_header_length));
564  frame_header_length += sizeof(uint64_t);
565  }
566 
567  // Header checksum - For the simplicity of this sample, the value is not checked
568  frame_header_length += sizeof(uint8_t);
569 
570  frame_footer_length += LZ4_END_MARK_LEN;
571  if (has_content_checksum_flag) {
572  if (content_checksum != NULL)
573  *content_checksum = htobe32(*((uint32_t *)(start_addr + src_buf_len - frame_footer_length)));
574 
575  frame_footer_length += has_content_checksum_flag * sizeof(uint32_t);
576  }
577 
578  src_buf_addr = (void *)(start_addr + frame_header_length);
579 
580  total_frame_length = (frame_header_length + frame_footer_length);
581  if (total_frame_length > src_buf_len) { // Check file includes content Frame
582  DOCA_LOG_ERR("Invalid header: Frame expected size=%lu is longer than file size =%lu",
583  total_frame_length,
584  src_buf_len);
586  }
587  src_buf_len -= total_frame_length;
588  // Check file includes at least 1 block frame
589  if ((sizeof(uint32_t) * (1 + cfg->has_block_checksum)) > src_buf_len) {
590  DOCA_LOG_ERR("File size=%lu is smaller than the minimum expected size =%lu",
591  src_buf_len + total_frame_length,
592  (sizeof(uint32_t) * (1 + cfg->has_block_checksum)) + total_frame_length);
594  }
595 
596  // Check content file is as expected
597  if (has_content_size && (src_buf_len != content_size)) {
598  DOCA_LOG_ERR("Invalid header: content size=%lu doesn't match the expected=%lu",
599  content_size,
600  src_buf_len);
602  }
603 
604  // Set buffer data section to include only the content, without the frame
605  result = doca_buf_set_data(src_buf, src_buf_addr, src_buf_len);
606  if (result != DOCA_SUCCESS) {
607  DOCA_LOG_ERR("Failed to set buffer's data address and length: %s", doca_error_get_descr(result));
608  return result;
609  }
610 
611  return DOCA_SUCCESS;
612 }
613 
622 static void compress_state_changed_callback(const union doca_data user_data,
623  struct doca_ctx *ctx,
624  enum doca_ctx_states prev_state,
625  enum doca_ctx_states next_state)
626 {
627  (void)ctx;
628  (void)prev_state;
629 
630  struct compress_resources *resources = (struct compress_resources *)user_data.ptr;
631 
632  switch (next_state) {
633  case DOCA_CTX_STATE_IDLE:
634  DOCA_LOG_INFO("Compress context has been stopped");
635  /* We can stop progressing the PE */
636  resources->run_pe_progress = false;
637  break;
642  DOCA_LOG_ERR("Compress context entered into starting state. Unexpected transition");
643  break;
645  DOCA_LOG_INFO("Compress context is running");
646  break;
655  DOCA_LOG_INFO("Compress context entered into stopping state. Any inflight tasks will be flushed");
656 
657  break;
658  default:
659  break;
660  }
661 }
662 
663 doca_error_t allocate_compress_resources(const char *pci_addr, uint32_t max_bufs, struct compress_resources *resources)
664 {
665  struct program_core_objects *state = NULL;
666  union doca_data ctx_user_data = {0};
667  doca_error_t result, tmp_result;
668  tasks_check supported_check_func;
669 
670  resources->state = malloc(sizeof(*resources->state));
671  if (resources->state == NULL) {
673  DOCA_LOG_ERR("Failed to allocate DOCA program core objects: %s", doca_error_get_descr(result));
674  return result;
675  }
677 
678  state = resources->state;
679 
680  switch (resources->mode) {
682  supported_check_func = compress_task_compress_deflate_is_supported;
683  break;
685  supported_check_func = compress_task_decompress_deflate_is_supported;
686  break;
689  break;
690  default:
691  DOCA_LOG_ERR("Unknown compress mode: %d", resources->mode);
693  goto free_state;
694  }
695 
696  /* Open DOCA device */
697  if (pci_addr != NULL) {
698  /* If pci_addr was provided then open using it */
699  result = open_doca_device_with_pci(pci_addr, supported_check_func, &state->dev);
700  } else {
701  /* If pci_addr was not provided then look for DOCA device */
702  result = open_doca_device_with_capabilities(supported_check_func, &state->dev);
703  }
704 
705  if (result != DOCA_SUCCESS) {
706  DOCA_LOG_ERR("Failed to open DOCA device for DOCA compress: %s", doca_error_get_descr(result));
707  goto free_state;
708  }
709 
710  result = doca_compress_create(state->dev, &resources->compress);
711  if (result != DOCA_SUCCESS) {
712  DOCA_LOG_ERR("Unable to create compress engine: %s", doca_error_get_descr(result));
713  goto close_device;
714  }
715 
716  state->ctx = doca_compress_as_ctx(resources->compress);
717 
718  result = create_core_objects(state, max_bufs);
719  if (result != DOCA_SUCCESS) {
720  DOCA_LOG_ERR("Unable to create DOCA core objects: %s", doca_error_get_descr(result));
721  goto destroy_compress;
722  }
723 
724  result = doca_pe_connect_ctx(state->pe, state->ctx);
725  if (result != DOCA_SUCCESS) {
726  DOCA_LOG_ERR("Unable to set progress engine for PE: %s", doca_error_get_descr(result));
728  }
729 
731  if (result != DOCA_SUCCESS) {
732  DOCA_LOG_ERR("Unable to set Compress state change callback: %s", doca_error_get_descr(result));
734  }
735 
736  switch (resources->mode) {
742  break;
748  break;
754  break;
755  default:
756  DOCA_LOG_ERR("Unknown compress mode: %d", resources->mode);
758  goto free_state;
759  }
760 
761  if (result != DOCA_SUCCESS) {
762  DOCA_LOG_ERR("Unable to set configurations for compress task: %s", doca_error_get_descr(result));
764  }
765 
766  /* Include resources in user data of context to be used in callbacks */
767  ctx_user_data.ptr = resources;
768  doca_ctx_set_user_data(state->ctx, ctx_user_data);
769 
770  return result;
771 
773  tmp_result = destroy_core_objects(state);
774  if (tmp_result != DOCA_SUCCESS) {
775  DOCA_LOG_ERR("Failed to destroy DOCA core objects: %s", doca_error_get_descr(tmp_result));
776  DOCA_ERROR_PROPAGATE(result, tmp_result);
777  }
778 destroy_compress:
779  tmp_result = doca_compress_destroy(resources->compress);
780  if (tmp_result != DOCA_SUCCESS) {
781  DOCA_LOG_ERR("Failed to destroy DOCA compress: %s", doca_error_get_descr(tmp_result));
782  DOCA_ERROR_PROPAGATE(result, tmp_result);
783  }
784 close_device:
785  tmp_result = doca_dev_close(state->dev);
786  if (tmp_result != DOCA_SUCCESS) {
787  DOCA_ERROR_PROPAGATE(result, tmp_result);
788  DOCA_LOG_ERR("Failed to close device: %s", doca_error_get_descr(tmp_result));
789  }
790 
791 free_state:
792  free(resources->state);
793  resources->state = NULL;
794  return result;
795 }
796 
798 {
799  struct program_core_objects *state = resources->state;
800  doca_error_t result = DOCA_SUCCESS, tmp_result;
801 
802  if (resources->compress != NULL) {
803  result = doca_ctx_stop(state->ctx);
804  if (result != DOCA_SUCCESS)
805  DOCA_LOG_ERR("Unable to stop context: %s", doca_error_get_descr(result));
806  state->ctx = NULL;
807 
808  tmp_result = doca_compress_destroy(resources->compress);
809  if (tmp_result != DOCA_SUCCESS) {
810  DOCA_LOG_ERR("Failed to destroy DOCA compress: %s", doca_error_get_descr(tmp_result));
811  DOCA_ERROR_PROPAGATE(result, tmp_result);
812  }
813  }
814 
815  if (resources->state != NULL) {
816  tmp_result = destroy_core_objects(state);
817  if (tmp_result != DOCA_SUCCESS) {
818  DOCA_LOG_ERR("Failed to destroy DOCA core objects: %s", doca_error_get_descr(tmp_result));
819  DOCA_ERROR_PROPAGATE(result, tmp_result);
820  }
821  free(state);
822  resources->state = NULL;
823  }
824 
825  return result;
826 }
827 
828 /*
829  * Calculate the checksum where the lower 32 bits contain the CRC checksum result
830  * and the upper 32 bits contain the Adler checksum result.
831  *
832  * @crc_checksum [in]: DOCA compress resources
833  * @adler_checksum [in]: Source buffer
834  * @return: The calculated checksum
835  */
836 static uint64_t calculate_checksum(uint32_t crc_checksum, uint32_t adler_checksum)
837 {
838  uint64_t checksum;
839 
840  checksum = (uint64_t)adler_checksum;
841  checksum <<= ADLER_CHECKSUM_SHIFT;
842  checksum += (uint64_t)crc_checksum;
843 
844  return checksum;
845 }
846 
848  struct doca_buf *src_buf,
849  struct doca_buf *dst_buf,
850  uint64_t *output_checksum)
851 {
852  struct doca_compress_task_compress_deflate *compress_task;
853  struct program_core_objects *state = resources->state;
854  struct doca_task *task;
855  union doca_data task_user_data = {0};
856  struct compress_deflate_result task_result = {0};
857  struct timespec ts = {
858  .tv_sec = 0,
859  .tv_nsec = SLEEP_IN_NANOS,
860  };
862 
863  /* Include result in user data of task to be used in the callbacks */
864  task_user_data.ptr = &task_result;
865  /* Allocate and construct compress task */
867  src_buf,
868  dst_buf,
869  task_user_data,
870  &compress_task);
871  if (result != DOCA_SUCCESS) {
872  DOCA_LOG_ERR("Failed to allocate compress task: %s", doca_error_get_descr(result));
873  return result;
874  }
875 
876  task = doca_compress_task_compress_deflate_as_task(compress_task);
877 
878  /* Submit compress task */
880  result = doca_task_submit(task);
881  if (result != DOCA_SUCCESS) {
882  DOCA_LOG_ERR("Failed to submit compress task: %s", doca_error_get_descr(result));
883  doca_task_free(task);
884  return result;
885  }
886 
887  resources->run_pe_progress = true;
888 
889  /* Wait for all tasks to be completed */
890  while (resources->run_pe_progress) {
891  if (doca_pe_progress(state->pe) == 0)
892  nanosleep(&ts, &ts);
893  }
894 
895  /* Check result of task according to the result we update in the callbacks */
896  if (task_result.status != DOCA_SUCCESS)
897  return task_result.status;
898 
899  /* Calculate checksum if needed */
900  if (output_checksum != NULL)
901  *output_checksum = calculate_checksum(task_result.crc_cs, task_result.adler_cs);
902 
903  return result;
904 }
905 
907  struct doca_buf *src_buf,
908  struct doca_buf *dst_buf,
909  uint64_t *output_checksum)
910 {
911  struct doca_compress_task_decompress_deflate *decompress_task;
912  struct program_core_objects *state = resources->state;
913  struct doca_task *task;
914  union doca_data task_user_data = {0};
915  struct compress_deflate_result task_result = {0};
916  struct timespec ts = {
917  .tv_sec = 0,
918  .tv_nsec = SLEEP_IN_NANOS,
919  };
921 
922  /* Include result in user data of task to be used in the callbacks */
923  task_user_data.ptr = &task_result;
924  /* Allocate and construct decompress task */
926  src_buf,
927  dst_buf,
928  task_user_data,
929  &decompress_task);
930  if (result != DOCA_SUCCESS) {
931  DOCA_LOG_ERR("Failed to allocate decompress task: %s", doca_error_get_descr(result));
932  return result;
933  }
934 
935  task = doca_compress_task_decompress_deflate_as_task(decompress_task);
936 
937  /* Submit decompress task */
939  result = doca_task_submit(task);
940  if (result != DOCA_SUCCESS) {
941  DOCA_LOG_ERR("Failed to submit decompress task: %s", doca_error_get_descr(result));
942  doca_task_free(task);
943  return result;
944  }
945 
946  resources->run_pe_progress = true;
947 
948  /* Wait for all tasks to be completed */
949  while (resources->run_pe_progress) {
950  if (doca_pe_progress(state->pe) == 0)
951  nanosleep(&ts, &ts);
952  }
953 
954  /* Check result of task according to the result we update in the callbacks */
955  if (task_result.status != DOCA_SUCCESS)
956  return task_result.status;
957 
958  /* Calculate checksum if needed */
959  if (output_checksum != NULL)
960  *output_checksum = calculate_checksum(task_result.crc_cs, task_result.adler_cs);
961 
962  return result;
963 }
964 
966  uint8_t has_block_checksum,
967  uint8_t are_blocks_independent,
968  struct doca_buf *src_buf,
969  struct doca_buf *dst_buf,
970  uint32_t *output_crc_checksum,
971  uint32_t *output_xxh_checksum)
972 {
973  struct doca_compress_task_decompress_lz4_stream *decompress_task;
974  struct program_core_objects *state = resources->state;
975  struct doca_task *task;
976  union doca_data task_user_data = {0};
977  struct compress_lz4_result task_result = {0};
978  struct timespec ts = {
979  .tv_sec = 0,
980  .tv_nsec = SLEEP_IN_NANOS,
981  };
983 
984  /* Include result in user data of task to be used in the callbacks */
985  task_user_data.ptr = &task_result;
986  /* Allocate and construct decompress task */
988  has_block_checksum,
989  are_blocks_independent,
990  src_buf,
991  dst_buf,
992  task_user_data,
993  &decompress_task);
994  if (result != DOCA_SUCCESS) {
995  DOCA_LOG_ERR("Failed to allocate decompress task: %s", doca_error_get_descr(result));
996  return result;
997  }
998 
999  task = doca_compress_task_decompress_lz4_stream_as_task(decompress_task);
1000 
1001  /* Submit decompress task */
1003  result = doca_task_submit(task);
1004  if (result != DOCA_SUCCESS) {
1005  DOCA_LOG_ERR("Failed to submit decompress task: %s", doca_error_get_descr(result));
1006  doca_task_free(task);
1007  return result;
1008  }
1009 
1010  resources->run_pe_progress = true;
1011 
1012  /* Wait for all tasks to be completed */
1013  while (resources->run_pe_progress) {
1014  if (doca_pe_progress(state->pe) == 0)
1015  nanosleep(&ts, &ts);
1016  }
1017 
1018  /* Check result of task according to the result we update in the callbacks */
1019  if (task_result.status != DOCA_SUCCESS)
1020  return task_result.status;
1021 
1022  /* Calculate checksum if needed */
1023  if (output_crc_checksum != NULL)
1024  *output_crc_checksum = task_result.crc_cs;
1025 
1026  if (output_xxh_checksum != NULL)
1027  *output_xxh_checksum = task_result.xxh_cs;
1029  return result;
1030 }
1031 
1032 doca_error_t compress_task_compress_deflate_is_supported(struct doca_devinfo *devinfo)
1035 }
1036 
1037 doca_error_t compress_task_decompress_deflate_is_supported(struct doca_devinfo *devinfo)
1040 }
1041 
1045 }
1046 
1047 void compress_completed_callback(struct doca_compress_task_compress_deflate *compress_task,
1048  union doca_data task_user_data,
1049  union doca_data ctx_user_data)
1050 {
1051  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1052  struct compress_deflate_result *result = (struct compress_deflate_result *)task_user_data.ptr;
1053 
1054  DOCA_LOG_INFO("Compress task was done successfully");
1055 
1056  /* Prepare task result */
1057  result->crc_cs = doca_compress_task_compress_deflate_get_crc_cs(compress_task);
1058  result->adler_cs = doca_compress_task_compress_deflate_get_adler_cs(compress_task);
1059  result->status = DOCA_SUCCESS;
1060 
1061  /* Free task */
1063  /* Decrement number of remaining tasks */
1065  /* Stop context once all tasks are completed */
1067  (void)doca_ctx_stop(resources->state->ctx);
1068 }
1069 
1070 void compress_error_callback(struct doca_compress_task_compress_deflate *compress_task,
1071  union doca_data task_user_data,
1072  union doca_data ctx_user_data)
1073 {
1074  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1075  struct doca_task *task = doca_compress_task_compress_deflate_as_task(compress_task);
1076  struct compress_deflate_result *result = (struct compress_deflate_result *)task_user_data.ptr;
1077 
1078  /* Get the result of the task */
1079  result->status = doca_task_get_status(task);
1080  DOCA_LOG_ERR("Compress task failed: %s", doca_error_get_descr(result->status));
1081  /* Free task */
1082  doca_task_free(task);
1083  /* Decrement number of remaining tasks */
1085  /* Stop context once all tasks are completed */
1087  (void)doca_ctx_stop(resources->state->ctx);
1088 }
1089 
1090 void decompress_deflate_completed_callback(struct doca_compress_task_decompress_deflate *decompress_task,
1091  union doca_data task_user_data,
1092  union doca_data ctx_user_data)
1093 {
1094  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1095  struct compress_deflate_result *result = (struct compress_deflate_result *)task_user_data.ptr;
1096 
1097  DOCA_LOG_INFO("Decompress task was done successfully");
1098 
1099  /* Prepare task result */
1100  result->crc_cs = doca_compress_task_decompress_deflate_get_crc_cs(decompress_task);
1101  result->adler_cs = doca_compress_task_decompress_deflate_get_adler_cs(decompress_task);
1102  result->status = DOCA_SUCCESS;
1103 
1104  /* Free task */
1106  /* Decrement number of remaining tasks */
1108  /* Stop context once all tasks are completed */
1110  (void)doca_ctx_stop(resources->state->ctx);
1111 }
1112 
1113 void decompress_deflate_error_callback(struct doca_compress_task_decompress_deflate *decompress_task,
1114  union doca_data task_user_data,
1115  union doca_data ctx_user_data)
1116 {
1117  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1118  struct doca_task *task = doca_compress_task_decompress_deflate_as_task(decompress_task);
1119  struct compress_deflate_result *result = (struct compress_deflate_result *)task_user_data.ptr;
1120 
1121  /* Get the result of the task */
1122  result->status = doca_task_get_status(task);
1123  DOCA_LOG_ERR("Decompress task failed: %s", doca_error_get_descr(result->status));
1124  /* Free task */
1125  doca_task_free(task);
1126  /* Decrement number of remaining tasks */
1128  /* Stop context once all tasks are completed */
1130  (void)doca_ctx_stop(resources->state->ctx);
1131 }
1132 
1133 void decompress_lz4_stream_completed_callback(struct doca_compress_task_decompress_lz4_stream *decompress_task,
1134  union doca_data task_user_data,
1135  union doca_data ctx_user_data)
1136 {
1137  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1138  struct compress_lz4_result *result = (struct compress_lz4_result *)task_user_data.ptr;
1139 
1140  DOCA_LOG_INFO("Decompress task was done successfully");
1141 
1142  /* Prepare task result */
1145  result->status = DOCA_SUCCESS;
1146 
1147  /* Free task */
1149  /* Decrement number of remaining tasks */
1151  /* Stop context once all tasks are completed */
1153  (void)doca_ctx_stop(resources->state->ctx);
1154 }
1155 
1156 void decompress_lz4_stream_error_callback(struct doca_compress_task_decompress_lz4_stream *decompress_task,
1157  union doca_data task_user_data,
1158  union doca_data ctx_user_data)
1159 {
1160  struct compress_resources *resources = (struct compress_resources *)ctx_user_data.ptr;
1161  struct doca_task *task = doca_compress_task_decompress_lz4_stream_as_task(decompress_task);
1162  struct compress_lz4_result *result = (struct compress_lz4_result *)task_user_data.ptr;
1163 
1164  /* Get the result of the task */
1165  result->status = doca_task_get_status(task);
1166  DOCA_LOG_ERR("Decompress task failed: %s", doca_error_get_descr(result->status));
1167  /* Free task */
1168  doca_task_free(task);
1169  /* Decrement number of remaining tasks */
1171  /* Stop context once all tasks are completed */
1172  if (resources->num_remaining_tasks == 0)
1173  (void)doca_ctx_stop(resources->state->ctx);
1174 }
#define NULL
Definition: __stddef_null.h:26
#define USER_MAX_FILE_NAME
int32_t result
#define SLEEP_IN_NANOS
Definition: comch_utils.c:40
doca_error_t destroy_core_objects(struct program_core_objects *state)
Definition: common.c:392
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
Definition: common.c:302
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
Definition: common.c:188
static void compress_state_changed_callback(const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state)
#define LZ4_VERSION_NUMER
#define LZ4_FLAGS_CONTENT_CHECKSUM_SHIFT
#define ZLIB_FLG_FDICT
doca_error_t register_compress_params(void)
doca_error_t register_lz4_stream_params(void)
doca_error_t register_deflate_params(void)
doca_error_t destroy_compress_resources(struct compress_resources *resources)
#define ZLIB_CMF_CINFO_SHIFT
doca_error_t compress_task_compress_deflate_is_supported(struct doca_devinfo *devinfo)
#define LZ4_FLAGS_BLOCK_CHECKSUM_MASK
#define ZLIB_FLG_FLEVEL_SHIFT
#define LZ4_FLAGS_CONTENT_SIZE_MASK
static doca_error_t has_block_checksum_callback(void *param, void *config)
#define LZ4_FLAGS_CONTENT_SIZE_SHIFT
#define ZLIB_FLG_FLEVEL
void init_compress_zlib_header(struct compress_zlib_header *zlib_header)
void compress_error_callback(struct doca_compress_task_compress_deflate *compress_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t pci_address_callback(void *param, void *config)
void decompress_deflate_completed_callback(struct doca_compress_task_decompress_deflate *decompress_task, union doca_data task_user_data, union doca_data ctx_user_data)
doca_error_t compress_task_decompress_lz4_stream_is_supported(struct doca_devinfo *devinfo)
void decompress_deflate_error_callback(struct doca_compress_task_decompress_deflate *decompress_task, union doca_data task_user_data, union doca_data ctx_user_data)
#define LZ4_FLAGS_VERSION_NUMBER_MASK
#define LZ4_END_MARK_LEN
#define ZLIB_CMF_CINFO
static doca_error_t is_with_frame_callback(void *param, void *config)
#define ZLIB_FLG_FCHECK_MASK
#define ZLIB_FLG_FDICT_MASK
#define ZLIB_CMF_CM_MASK
doca_error_t parse_lz4_frame(struct doca_buf *src_buf, struct compress_cfg *cfg, bool *has_content_checksum, uint32_t *content_checksum)
static uint8_t compute_zlib_header_fcheck(struct compress_zlib_header *zlib_header)
#define LZ4_FLAGS_BLOCK_CHECKSUM_SHIFT
static uint64_t calculate_checksum(uint32_t crc_checksum, uint32_t adler_checksum)
static doca_error_t are_blocks_independent_callback(void *param, void *config)
#define ZLIB_FLG_FDICT_SHIFT
#define LZ4_FLAGS_BLOCK_INDEPENDENT_SHIFT
doca_error_t submit_decompress_lz4_stream_task(struct compress_resources *resources, uint8_t has_block_checksum, uint8_t are_blocks_independent, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint32_t *output_crc_checksum, uint32_t *output_xxh_checksum)
#define ZLIB_CMF_CM
#define LZ4_FLAGS_BLOCK_INDEPENDENT_MASK
void compress_completed_callback(struct doca_compress_task_compress_deflate *compress_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t output_checksum_callback(void *param, void *config)
DOCA_LOG_REGISTER(COMPRESS::COMMON)
void decompress_lz4_stream_completed_callback(struct doca_compress_task_decompress_lz4_stream *decompress_task, union doca_data task_user_data, union doca_data ctx_user_data)
#define LZ4_FLAGS_DICT_ID_MASK
#define LZ4_MAGIC_NUMBER
doca_error_t compress_task_decompress_deflate_is_supported(struct doca_devinfo *devinfo)
void decompress_lz4_stream_error_callback(struct doca_compress_task_decompress_lz4_stream *decompress_task, union doca_data task_user_data, union doca_data ctx_user_data)
#define ZLIB_CMF_CINFO_MASK
doca_error_t allocate_compress_resources(const char *pci_addr, uint32_t max_bufs, struct compress_resources *resources)
static doca_error_t output_callback(void *param, void *config)
doca_error_t submit_decompress_deflate_task(struct compress_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint64_t *output_checksum)
#define LZ4_FLAGS_VERSION_NUMBER_SHIFT
#define LZ4_FLAGS_CONTENT_CHECKSUM_MASK
static doca_error_t file_callback(void *param, void *config)
#define ZLIB_FLG_FLEVEL_MASK
doca_error_t verify_compress_zlib_header(struct compress_zlib_header *zlib_header)
doca_error_t submit_compress_deflate_task(struct compress_resources *resources, struct doca_buf *src_buf, struct doca_buf *dst_buf, uint64_t *output_checksum)
@ COMPRESS_MODE_DECOMPRESS_LZ4_STREAM
@ COMPRESS_MODE_COMPRESS_DEFLATE
@ COMPRESS_MODE_DECOMPRESS_DEFLATE
#define NUM_COMPRESS_TASKS
#define ADLER_CHECKSUM_SHIFT
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
Definition: device.c:43
uint64_t len
#define MAX_FILE_NAME
struct rdma_resources resources
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
@ DOCA_ARGP_TYPE_STRING
Definition: doca_argp.h:56
@ DOCA_ARGP_TYPE_BOOLEAN
Definition: doca_argp.h:58
DOCA_STABLE doca_error_t doca_buf_get_len(const struct doca_buf *buf, size_t *len)
Get the buffer's length.
DOCA_STABLE doca_error_t doca_buf_get_head(const struct doca_buf *buf, void **head)
Get the buffer's head.
DOCA_STABLE doca_error_t doca_buf_set_data(struct doca_buf *buf, void *data, size_t data_len)
DOCA_EXPERIMENTAL uint32_t doca_compress_task_decompress_lz4_stream_get_xxh_cs(const struct doca_compress_task_decompress_lz4_stream *task)
get decompress LZ4 stream task xxHash-32 checksum
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_compress_deflate_set_conf(struct doca_compress *compress, doca_compress_task_compress_deflate_completion_cb_t task_completion_cb, doca_compress_task_compress_deflate_completion_cb_t task_error_cb, uint32_t num_tasks)
This method sets the compress deflate task configuration.
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_decompress_lz4_stream_alloc_init(struct doca_compress *compress, uint8_t has_block_checksum, uint8_t are_blocks_independent, struct doca_buf const *src_buff, struct doca_buf *dst_buff, union doca_data user_data, struct doca_compress_task_decompress_lz4_stream **task)
Allocate decompress LZ4 stream task.
DOCA_EXPERIMENTAL doca_error_t doca_compress_destroy(struct doca_compress *compress)
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_decompress_deflate_set_conf(struct doca_compress *compress, doca_compress_task_decompress_deflate_completion_cb_t task_completion_cb, doca_compress_task_decompress_deflate_completion_cb_t task_error_cb, uint32_t num_tasks)
This method sets the decompress deflate task configuration.
DOCA_EXPERIMENTAL uint32_t doca_compress_task_compress_deflate_get_crc_cs(const struct doca_compress_task_compress_deflate *task)
get compress deflate task CRC checksum
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_compress_deflate_is_supported(const struct doca_devinfo *devinfo)
Check if a compress deflate task is supported by a device.
DOCA_EXPERIMENTAL struct doca_task * doca_compress_task_decompress_deflate_as_task(struct doca_compress_task_decompress_deflate *task)
convert decompress deflate task to doca_task
DOCA_EXPERIMENTAL uint32_t doca_compress_task_decompress_deflate_get_adler_cs(const struct doca_compress_task_decompress_deflate *task)
get decompress deflate task adler checksum
DOCA_EXPERIMENTAL doca_error_t doca_compress_create(struct doca_dev *dev, struct doca_compress **compress)
DOCA_EXPERIMENTAL uint32_t doca_compress_task_decompress_deflate_get_crc_cs(const struct doca_compress_task_decompress_deflate *task)
get decompress deflate task CRC checksum
DOCA_EXPERIMENTAL struct doca_ctx * doca_compress_as_ctx(struct doca_compress *compress)
DOCA_EXPERIMENTAL struct doca_task * doca_compress_task_compress_deflate_as_task(struct doca_compress_task_compress_deflate *task)
convert compress deflate task to doca_task
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_decompress_lz4_stream_is_supported(const struct doca_devinfo *devinfo)
Check if a decompress LZ4 stream task is supported by a device.
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_decompress_lz4_stream_set_conf(struct doca_compress *compress, doca_compress_task_decompress_lz4_stream_completion_cb_t task_completion_cb, doca_compress_task_decompress_lz4_stream_completion_cb_t task_error_cb, uint32_t num_tasks)
This method sets the decompress LZ4 stream task configuration.
DOCA_EXPERIMENTAL uint32_t doca_compress_task_decompress_lz4_stream_get_crc_cs(const struct doca_compress_task_decompress_lz4_stream *task)
get decompress LZ4 stream task CRC checksum
DOCA_EXPERIMENTAL struct doca_task * doca_compress_task_decompress_lz4_stream_as_task(struct doca_compress_task_decompress_lz4_stream *task)
convert decompress LZ4 stream task to doca_task
DOCA_EXPERIMENTAL uint32_t doca_compress_task_compress_deflate_get_adler_cs(const struct doca_compress_task_compress_deflate *task)
get compress deflate task adler checksum
DOCA_EXPERIMENTAL doca_error_t doca_compress_cap_task_decompress_deflate_is_supported(const struct doca_devinfo *devinfo)
Check if a decompress deflate task is supported by a device.
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_compress_deflate_alloc_init(struct doca_compress *compress, struct doca_buf const *src_buff, struct doca_buf *dst_buff, union doca_data user_data, struct doca_compress_task_compress_deflate **task)
Allocate compress deflate task.
DOCA_EXPERIMENTAL doca_error_t doca_compress_task_decompress_deflate_alloc_init(struct doca_compress *compress, struct doca_buf const *src_buff, struct doca_buf *dst_buff, union doca_data user_data, struct doca_compress_task_decompress_deflate **task)
Allocate decompress deflate task.
DOCA_STABLE doca_error_t doca_ctx_set_state_changed_cb(struct doca_ctx *ctx, doca_ctx_state_changed_callback_t cb)
Set state changed callback.
DOCA_STABLE doca_error_t doca_ctx_set_user_data(struct doca_ctx *ctx, union doca_data user_data)
set user data to context
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
doca_ctx_states
This enum defines the states of a context.
Definition: doca_ctx.h:83
@ DOCA_CTX_STATE_STARTING
Definition: doca_ctx.h:93
@ DOCA_CTX_STATE_STOPPING
Definition: doca_ctx.h:106
@ DOCA_CTX_STATE_IDLE
Definition: doca_ctx.h:88
@ DOCA_CTX_STATE_RUNNING
Definition: doca_ctx.h:98
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
Definition: doca_error.h:44
@ DOCA_ERROR_NOT_SUPPORTED
Definition: doca_error.h:42
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE uint8_t doca_pe_progress(struct doca_pe *pe)
Run the progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
#define htobe32
Definition: os_utils.hpp:40
#define htobe16
Definition: os_utils.hpp:39
doca_error_t(* tasks_check)(struct doca_devinfo *)
Definition: common.h:42
char file_path[MAX_FILE_NAME]
bool are_blocks_independent
bool has_block_checksum
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
char output_path[MAX_FILE_NAME]
struct doca_pe * pe
Definition: common.h:51
struct doca_dev * dev
Definition: common.h:46
struct doca_ctx * ctx
Definition: common.h:50
size_t num_remaining_tasks
Definition: rdma_common.h:134
bool run_pe_progress
Definition: rdma_common.h:133
Convenience type for representing opaque data.
Definition: doca_types.h:56
void * ptr
Definition: doca_types.h:57
struct upf_accel_ctx * ctx