Skip to content

Commit f0ae287

Browse files
lin755herbertx
authored andcommitted
crypto: hisilicon/sec2 - implement full backlog mode for sec
This patch introduces a hierarchical backlog mechanism to cache user data in high-throughput encryption/decryption scenarios, the implementation addresses packet loss issues when hardware queues overflow during peak loads. First, we use sec_alloc_req_id to obtain an exclusive resource from the pre-allocated resource pool of each queue, if no resource is allocated, perform the DMA map operation on the request memory. When the task is ready, we will attempt to send it to the hardware, if the hardware queue is already full, we cache the request into the backlog list, then return an EBUSY status to the upper layer and instruct the packet-sending thread to pause transmission. Simultaneously, when the hardware completes a task, it triggers the sec callback function, within this function, reattempt to send the requests from the backlog list and wake up the sending thread until the hardware queue becomes fully occupied again. In addition, it handles such exceptions like the hardware is reset when packets are sent, it will switch to the software computing and release occupied resources. Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent f9c4923 commit f0ae287

2 files changed

Lines changed: 457 additions & 180 deletions

File tree

drivers/crypto/hisilicon/sec2/sec.h

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#include <linux/hisi_acc_qm.h>
88
#include "sec_crypto.h"
99

10+
#define SEC_PBUF_SZ 512
11+
#define SEC_MAX_MAC_LEN 64
12+
#define SEC_IV_SIZE 24
13+
#define SEC_SGE_NR_NUM 4
14+
#define SEC_SGL_ALIGN_SIZE 64
15+
1016
/* Algorithm resource per hardware SEC queue */
1117
struct sec_alg_res {
1218
u8 *pbuf;
@@ -20,6 +26,40 @@ struct sec_alg_res {
2026
u16 depth;
2127
};
2228

29+
struct sec_hw_sge {
30+
dma_addr_t buf;
31+
void *page_ctrl;
32+
__le32 len;
33+
__le32 pad;
34+
__le32 pad0;
35+
__le32 pad1;
36+
};
37+
38+
struct sec_hw_sgl {
39+
dma_addr_t next_dma;
40+
__le16 entry_sum_in_chain;
41+
__le16 entry_sum_in_sgl;
42+
__le16 entry_length_in_sgl;
43+
__le16 pad0;
44+
__le64 pad1[5];
45+
struct sec_hw_sgl *next;
46+
struct sec_hw_sge sge_entries[SEC_SGE_NR_NUM];
47+
} __aligned(SEC_SGL_ALIGN_SIZE);
48+
49+
struct sec_src_dst_buf {
50+
struct sec_hw_sgl in;
51+
struct sec_hw_sgl out;
52+
};
53+
54+
struct sec_request_buf {
55+
union {
56+
struct sec_src_dst_buf data_buf;
57+
__u8 pbuf[SEC_PBUF_SZ];
58+
};
59+
dma_addr_t in_dma;
60+
dma_addr_t out_dma;
61+
};
62+
2363
/* Cipher request of SEC private */
2464
struct sec_cipher_req {
2565
struct hisi_acc_hw_sgl *c_out;
@@ -29,6 +69,7 @@ struct sec_cipher_req {
2969
struct skcipher_request *sk_req;
3070
u32 c_len;
3171
bool encrypt;
72+
__u8 c_ivin_buf[SEC_IV_SIZE];
3273
};
3374

3475
struct sec_aead_req {
@@ -37,6 +78,13 @@ struct sec_aead_req {
3778
u8 *a_ivin;
3879
dma_addr_t a_ivin_dma;
3980
struct aead_request *aead_req;
81+
__u8 a_ivin_buf[SEC_IV_SIZE];
82+
__u8 out_mac_buf[SEC_MAX_MAC_LEN];
83+
};
84+
85+
struct sec_instance_backlog {
86+
struct list_head list;
87+
spinlock_t lock;
4088
};
4189

4290
/* SEC request of Crypto */
@@ -55,15 +103,17 @@ struct sec_req {
55103
dma_addr_t in_dma;
56104
struct sec_cipher_req c_req;
57105
struct sec_aead_req aead_req;
58-
struct list_head backlog_head;
106+
struct crypto_async_request *base;
59107

60108
int err_type;
61109
int req_id;
62110
u32 flag;
63111

64-
/* Status of the SEC request */
65-
bool fake_busy;
66112
bool use_pbuf;
113+
114+
struct list_head list;
115+
struct sec_instance_backlog *backlog;
116+
struct sec_request_buf buf;
67117
};
68118

69119
/**
@@ -119,9 +169,11 @@ struct sec_qp_ctx {
119169
struct sec_alg_res *res;
120170
struct sec_ctx *ctx;
121171
spinlock_t req_lock;
122-
struct list_head backlog;
172+
spinlock_t id_lock;
123173
struct hisi_acc_sgl_pool *c_in_pool;
124174
struct hisi_acc_sgl_pool *c_out_pool;
175+
struct sec_instance_backlog backlog;
176+
u16 send_head;
125177
};
126178

127179
enum sec_alg_type {
@@ -139,9 +191,6 @@ struct sec_ctx {
139191
/* Half queues for encipher, and half for decipher */
140192
u32 hlf_q_num;
141193

142-
/* Threshold for fake busy, trigger to return -EBUSY to user */
143-
u32 fake_req_limit;
144-
145194
/* Current cyclic index to select a queue for encipher */
146195
atomic_t enc_qcyclic;
147196

0 commit comments

Comments
 (0)