40 #include "../common.h"
49 #define ZLIB_CMF_CINFO \
53 #define ZLIB_CMF_CM_MASK 0x0F
54 #define ZLIB_CMF_CINFO_MASK 0xF0
55 #define ZLIB_CMF_CINFO_SHIFT 4
60 #define ZLIB_FLG_FLEVEL 2
61 #define ZLIB_FLG_FDICT \
65 #define ZLIB_FLG_FCHECK_MASK 0x1F
66 #define ZLIB_FLG_FDICT_MASK 0x20
67 #define ZLIB_FLG_FDICT_SHIFT 5
68 #define ZLIB_FLG_FLEVEL_MASK 0xC0
69 #define ZLIB_FLG_FLEVEL_SHIFT 6
74 #define LZ4_MAGIC_NUMBER 0x184D2204
75 #define LZ4_VERSION_NUMER 0x01
77 #define LZ4_FLAGS_DICT_ID_MASK 0x1
78 #define LZ4_FLAGS_CONTENT_CHECKSUM_SHIFT 2
79 #define LZ4_FLAGS_CONTENT_CHECKSUM_MASK 0x4
80 #define LZ4_FLAGS_CONTENT_SIZE_SHIFT 3
81 #define LZ4_FLAGS_CONTENT_SIZE_MASK 0x8
82 #define LZ4_FLAGS_BLOCK_CHECKSUM_SHIFT 4
83 #define LZ4_FLAGS_BLOCK_CHECKSUM_MASK 0x10
84 #define LZ4_FLAGS_BLOCK_INDEPENDENT_SHIFT 5
85 #define LZ4_FLAGS_BLOCK_INDEPENDENT_MASK 0x20
86 #define LZ4_FLAGS_VERSION_NUMBER_SHIFT 6
87 #define LZ4_FLAGS_VERSION_NUMBER_MASK 0xC0
89 #define LZ4_END_MARK_LEN 4
120 DOCA_LOG_ERR(
"Entered device PCI address exceeding the maximum size of %d",
138 char *file = (
char *)param;
160 char *file = (
char *)param;
197 struct doca_argp_param *pci_param, *file_param, *output_param, *output_checksum_param;
291 struct doca_argp_param *is_with_frame;
301 "Write/read a file with a frame, compatible with default zlib settings");
355 struct doca_argp_param *is_with_frame;
356 struct doca_argp_param *has_block_checksum;
357 struct doca_argp_param *are_blocks_independent;
384 "Flag to indicate if blocks have a checksum. Valid only when the sample is run without the with-frame(wf) flag");
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");
425 uint8_t fcheck = (31 - (sum % 31));
453 DOCA_LOG_ERR(
"Invalid header: header FCHECK=%u doesn't match expected FCHECK=%u",
460 DOCA_LOG_ERR(
"Invalid header: DOCA compress doesn't support the use of dictionary identifiers");
466 "Invalid header: DOCA compress supports only a default algorithm (FLEVEL=%u) yet FLEVEL=%u was given",
474 "Invalid header: DOCA compress supports only DEFLATE compress method (CM=%u) yet CM=%u was given",
482 "Invalid header: the given window size (CINFO=%u) may not be smaller than the window size used to compress with DOCA (CINFO=%u)",
493 bool *has_content_checksum,
494 uint32_t *content_checksum)
497 bool has_content_size =
false;
498 bool has_content_checksum_flag =
false;
499 bool has_dict_id =
false;
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;
509 uint32_t frame_header_length = 0;
510 uint32_t frame_footer_length = 0;
524 start_addr = (uint8_t *)src_buf_addr;
526 magic_number = (*(uint32_t *)start_addr);
527 frame_header_length +=
sizeof(uint32_t);
529 DOCA_LOG_ERR(
"Invalid header: magic number=%x doesn't match the expected LZ4 magic number=%x",
530 le32toh(magic_number),
535 flags = *(start_addr + frame_header_length);
536 frame_header_length +=
sizeof(uint8_t);
540 DOCA_LOG_ERR(
"Invalid header: version=%x doesn't match the expected LZ4 version=%x",
551 if (has_content_checksum !=
NULL)
552 *has_content_checksum = has_content_checksum_flag;
556 DOCA_LOG_ERR(
"Data compressed using a dictionary is not supported");
560 frame_header_length +=
sizeof(uint8_t);
562 if (has_content_size) {
563 content_size = *((uint64_t *)(start_addr + frame_header_length));
564 frame_header_length +=
sizeof(uint64_t);
568 frame_header_length +=
sizeof(uint8_t);
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)));
575 frame_footer_length += has_content_checksum_flag *
sizeof(uint32_t);
578 src_buf_addr = (
void *)(start_addr + frame_header_length);
580 total_frame_length = (frame_header_length + frame_footer_length);
581 if (total_frame_length > src_buf_len) {
582 DOCA_LOG_ERR(
"Invalid header: Frame expected size=%lu is longer than file size =%lu",
587 src_buf_len -= total_frame_length;
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);
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",
623 struct doca_ctx *
ctx,
632 switch (next_state) {
642 DOCA_LOG_ERR(
"Compress context entered into starting state. Unexpected transition");
655 DOCA_LOG_INFO(
"Compress context entered into stopping state. Any inflight tasks will be flushed");
697 if (pci_addr !=
NULL) {
721 goto destroy_compress;
840 checksum = (uint64_t)adler_checksum;
842 checksum += (uint64_t)crc_checksum;
848 struct doca_buf *src_buf,
849 struct doca_buf *dst_buf,
850 uint64_t *output_checksum)
852 struct doca_compress_task_compress_deflate *compress_task;
854 struct doca_task *task;
857 struct timespec ts = {
864 task_user_data.
ptr = &task_result;
897 return task_result.
status;
900 if (output_checksum !=
NULL)
907 struct doca_buf *src_buf,
908 struct doca_buf *dst_buf,
909 uint64_t *output_checksum)
911 struct doca_compress_task_decompress_deflate *decompress_task;
913 struct doca_task *task;
916 struct timespec ts = {
923 task_user_data.
ptr = &task_result;
956 return task_result.
status;
959 if (output_checksum !=
NULL)
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)
973 struct doca_compress_task_decompress_lz4_stream *decompress_task;
975 struct doca_task *task;
978 struct timespec ts = {
985 task_user_data.
ptr = &task_result;
989 are_blocks_independent,
1015 nanosleep(&ts, &ts);
1020 return task_result.
status;
1023 if (output_crc_checksum !=
NULL)
1024 *output_crc_checksum = task_result.
crc_cs;
1026 if (output_xxh_checksum !=
NULL)
1027 *output_xxh_checksum = task_result.
xxh_cs;
#define USER_MAX_FILE_NAME
doca_error_t destroy_core_objects(struct program_core_objects *state)
doca_error_t create_core_objects(struct program_core_objects *state, uint32_t max_bufs)
doca_error_t open_doca_device_with_capabilities(tasks_check func, struct doca_dev **retval)
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
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
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
static doca_error_t is_with_frame_callback(void *param, void *config)
#define ZLIB_FLG_FCHECK_MASK
#define ZLIB_FLG_FDICT_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 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
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)
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_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.
@ DOCA_CTX_STATE_STARTING
@ DOCA_CTX_STATE_STOPPING
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
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.
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
@ DOCA_ERROR_NOT_SUPPORTED
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
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
doca_error_t(* tasks_check)(struct doca_devinfo *)
char file_path[MAX_FILE_NAME]
bool are_blocks_independent
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
char output_path[MAX_FILE_NAME]
size_t num_remaining_tasks
Convenience type for representing opaque data.
struct upf_accel_ctx * ctx