---
title: COMP算法类相关接口
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_17_0046.html
sourcePath: /source/zh/kunpengboostkithistory/251RC1/accel/kunpengaccel_17_0046.html
indexId: 16fc4ee371373597a0ceed1fe9a39df61546541d4312114b1b62e723c434878272
---
# COMP算法类相关接口

```
enum wcrypto_comp_flush_type {
WCRYPTO_INVALID_FLUSH,

/* output as much data as we can to improve performance */
WCRYPTO_NO_FLUSH,

/* output as bytes aligning or some other conditions satisfied */
WCRYPTO_SYNC_FLUSH,

/* indicates the end of the file/data */
WCRYPTO_FINISH,
};
enum wcrypto_comp_level {
WCRYPTO_COMP_L1 = 1,/* Compression level 1 */
WCRYPTO_COMP_L2,    /* Compression level 2 */
WCRYPTO_COMP_L3,    /* Compression level 3 */
WCRYPTO_COMP_L4, /* Compression level 4 */
WCRYPTO_COMP_L5, /* Compression level 5 */
WCRYPTO_COMP_L6, /* Compression level 6 */
WCRYPTO_COMP_L7, /* Compression level 7 */
WCRYPTO_COMP_L8, /* Compression level 8 */
WCRYPTO_COMP_L9 /* Compression level 9 */
};

enum wcrypto_comp_win_type {
WCRYPTO_COMP_WS_4K, /* 4k bytes window size */
WCRYPTO_COMP_WS_8K, /* 8k bytes window size */
WCRYPTO_COMP_WS_16K, /* 16k bytes window size */
WCRYPTO_COMP_WS_32K, /* 32k bytes window size */
};
/* Comp message format of Warpdrive */
struct wcrypto_comp_msg {
__u8 alg_type;/* Denoted by enum wcrypto_comp_alg_type */
__u8 op_type;/* Denoted by enum wcrypto_comp_op_type */
__u8 flush_type;/* indicates the output mode, from enum wcrypto_comp_flush_type */
__u8 stream_mode;/* Denoted by enum wcrypto_comp_state */
__u8 stream_pos;/* Denoted by enum wcrypto_stream_status */
__u8 comp_lv;/* Denoted by enum wcrypto_comp_level */
__u8 data_fmt;/* Data format, denoted by enum wd_buff_type */
__u8 win_sz;/* Denoted by enum wcrypto_comp_win_type */
__u32 in_size;    /* Input data bytes */
__u32 avail_out;/* Output buffer size */
__u32 in_cons;/* consumed bytes of input data */
__u32 produced;/* produced bytes of current operation */
__u8 *src;/* Input data VA, buf should be DMA-able. */
__u8 *dst;/* Output data VA pointer */
__u32 tag;       /* User-defined request identifier */
__u32 win_size;/* Denoted by enum wcrypto_comp_win_type */
__u32 status;/* Data format, denoted by WD error code and enum wcrypto_op_result */
__u32 isize;/* Denoted by gzip isize */
__u32 checksum;/* Denoted by zlib/gzip CRC */
__u32 ctx_priv0;/* Denoted HW priv */
__u32 ctx_priv1;/* Denoted HW priv */
__u32 ctx_priv2;/* Denoted HW priv */
void *ctx_buf;/* Denoted HW ctx cache */
__u64 udata;/* Input user tag, used for indentify data stream/user: struct wcrypto_cb_tag */
};

enum wcrypto_comp_alg_type {
WCRYPTO_ZLIB,
WCRYPTO_GZIP,
};

/* Compression operational types */
enum wcrypto_comp_op_type {
WCRYPTO_DEFLATE,/* Data Compression */
WCRYPTO_INFLATE, /* Data Decompression */
};

enum wcrypto_comp_state {
WCRYPTO_COMP_STATELESS,
WCRYPTO_COMP_STATEFUL,
};

enum wcrypto_stream_status {
WCRYPTO_COMP_STREAM_OLD,
WCRYPTO_COMP_STREAM_NEW,  /* indicates the first packet */
};

/* context setup parameters */
struct wcrypto_comp_ctx_setup {
wcrypto_cb cb;/* User call back */
__u8 alg_type; /* wcrypto_comp_alg_type */
__u8 op_type; /* wcrypto_comp_op_type */
__u8 stream_mode; /* wcrypto_comp_state */
__u8 comp_lv; /* compression level */
__u16 win_size; /* window size */
__u16 data_fmt;/* buffer format */
struct wd_mm_br br;  /* memory operations from user */
};

struct wcrypto_comp_op_data {
__u8 alg_type;/* Denoted by enum wcrypto_comp_alg_type */
__u8 flush; /* indicates from enum wcrypto_comp_flush_type */
__u8 stream_pos;  /* Denoted by enum wcrypto_stream_status */
__u8 status;/* Denoted by WD error code and enum wcrypto_op_result */
__u8 *in; /* Input VA, buffer should be DMA buffer. */
__u8 *out;/* Output data VA pointer, buffer should be DMA-able */
__u32 in_len;/* input data bytes */
__u32 avail_out; /* output buffer size */
__u32 consumed;  /* bytes consumed by the operation */
__u32 produced; /* bytes output by the operation */
__u32 isize;/* gzip isize */
__u32 checksum; /* Will be updated to the checksum of data produced by the operation */
void *priv;       /* private field for extend */
};
```

| 函数原型 | void \* wcrypto\_create\_comp\_ctx (struct wd\_queue \*q, struct wcrypto\_comp\_ctx\_setup \*setup); |
| --- | --- |
| 函数功能 | 基于Warpdrive queue创建COMP算法context |
| 输入说明 | q：Warpdrive queue setup：用户对于context的创建输入参数 |
| 输出说明 | 无 |
| 返回值说明 | Context地址 NULL：失败 非NULL：成功 |
| 使用说明 | 支持多线程 |
| 注意事项 | 无 |


| 函数原型 | int wcrypto\_do\_comp(void \*ctx, struct wcrypto\_comp\_op\_data \*opdata, void \*tag); |
| --- | --- |
| 函数功能 | 基于COMP context的COMP算法操作 |
| 输入说明 | ctx：COMP context opdata：COMP操作参数，包括输入输出以及操作类型等 tag：用户回调标识，为NULL时，为同步接口，否则为异步接口 |
| 输出说明 | 无 |
| 返回值说明 | 0：成功 否则失败（错误码含义请参考WD消息错误码接口定义） |
| 使用说明 | 同一个ctx仅支持单线程 |
| 注意事项 | 无 |


| 函数原型 | int wcrypto\_comp\_poll(struct wd\_queue \*q, unsigned int num); |
| --- | --- |
| 函数功能 | 基于warpdrive queue的COMP算法poll操作 |
| 输入说明 | q：Warpdrive COMP queue num：0\-\-\-表示将队列q中所有回应消息全部收上来，非0\-\-\-表示将队列中num个回应消息收上来 |
| 输出说明 | 无 |
| 返回值说明 | 大于0：成功收到对应个数的回应消息 0：没有收到任何回应 负值：poll发生错误 |
| 使用说明 | 同一个q仅支持单线程 |
| 注意事项 | 无 |


| 函数原型 | void wcrypto\_del\_comp\_ctx (void \*ctx); |
| --- | --- |
| 函数功能 | 删除一个COMP的context |
| 输入说明 | ctx：需要删除的COMP context |
| 输出说明 | 无 |
| 返回值说明 | 无 |
| 使用说明 | 无 |
| 注意事项 | 无 |
