---
title: EC存储算法类相关接口
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/252RC1/accel/kunpengaccel_17_0050.html
sourcePath: /source/zh/kunpengboostkithistory/252RC1/accel/kunpengaccel_17_0050.html
indexId: fde59ec2e72f7628188e7f79d03e13fbac7489003cec807cdcbb95e20bc25d2c72
---
# EC存储算法类相关接口

```
/* EC message format of Warpdrive */
struct wcrypto_ec_msg {
__u8 alg_type;/* Denoted by enum wcrypto_alg_type */
__u8 ec_type; /* Denoted by enum wcrypto_ec_type */
__u8 op_type; /* Denoted by enum wcrypto_ec_op_type */
__u8 data_fmt; /* Data format, denoted by enum wd_buff_type */
__u8 result;/* Data format, denoted by WD error code */
__u8 *coef_matrix; /* Coefficient matrix */
__u8 coef_matrix_load; /* coef_matrix reload control, 0: do not load, 1: load */
__u8 coef_matrix_len;  /* length of loaded coe_matrix, equal to src_num*/
__u8 alg_blk_size; /* algorithm granularity, 0: 512 gran, 1: 4096 gran*/
__u16 block_size;/* support 512,520,4096,4104,4160 */
__u16 block_num;/*number of sector*/
__u8 *in; /* Input address, should be dma buffer */
__u8 in_disk_num;/* number of source disks */
__u8 *out; /* Result address should be dma buffer */
__u8 out_disk_num; /* number of destination disks */
__u64 usr_data; /* user identifier: for example: struct wcrypto_cb_tag */
};
enum wcrypto_ec_type {
WCRYPTO_EC_FLEXEC,
WCRYPTO_EC_MPCC,
};

enum wcrypto_ec_op_type {
WCRYPTO_EC_GENERATE,
WCRYPTO_EC_VALIDATE,
WCRYPTO_EC_UPDATE,
WCRYPTO_EC_RECONSTRUCT,
};

struct wcrypto_ec_ctx_setup {
enum wcrypto_ec_type ec_type;
wcrypto_cb cb;
__u16 data_fmt;
struct wd_mm_br br;
};

struct wcrypto_ec_op_data {
enum wcrypto_ec_op_type op_type;
int status;
__u8 *coef_matrix; /* Coefficient matrix */
__u8 coef_matrix_load; /* coef_matrix reload control, 0: do not load, 1: load */
__u8 coef_matrix_len; /* length of loaded coe_matrix, equal to src_num*/
__u8 alg_blk_size; /* algorithm granularity, 0: 512 gran, 1: 4096 gran*/
__u16 block_size;/*support 512,520,4096,4104,4160*/
__u16 block_num;/*number of sector*/
void *in; /* Input address */
__u8 in_disk_num;/* number of source disks */
void *out; /* Result address */
__u8 out_disk_num; /* number of destination disks */
void *priv;
};
```

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


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


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


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