1
2
3
4
5#ifndef CAAM_JR_PVT_H
6#define CAAM_JR_PVT_H
7
8#include <desc/ipsec.h>
9#include <dpaax_iova_table.h>
10
11
12
13#define CAAM_JR_ALG_UNSUPPORT (-1)
14
15
16
17
18#define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
19#define CAAM_JOB_DESC_SIZE 13
20
21
22#define CTX_POOL_NUM_BUFS 32000
23#define CTX_POOL_CACHE_SIZE 512
24
25#define DIR_ENC 1
26#define DIR_DEC 0
27
28#define JR_MAX_NB_MAX_DIGEST 32
29
30#define RTE_CAAM_JR_PMD_MAX_NB_SESSIONS 2048
31
32
33
34enum sec_return_code_e {
35 SEC_SUCCESS = 0,
36 SEC_INVALID_INPUT_PARAM,
37
38
39 SEC_OUT_OF_MEMORY,
40 SEC_DESCRIPTOR_IN_FLIGHT,
41
42
43
44 SEC_LAST_DESCRIPTOR_IN_FLIGHT,
45
46
47
48 SEC_PROCESSING_ERROR,
49
50
51
52
53
54
55
56 SEC_DESC_PROCESSING_ERROR,
57
58
59
60
61
62
63 SEC_JR_IS_FULL,
64
65
66
67
68 SEC_DRIVER_RELEASE_IN_PROGRESS,
69
70
71
72 SEC_DRIVER_ALREADY_INITIALIZED,
73 SEC_DRIVER_NOT_INITIALIZED,
74 SEC_JOB_RING_RESET_IN_PROGRESS,
75
76
77
78
79
80
81 SEC_RESET_ENGINE_FAILED,
82
83
84 SEC_ENABLE_IRQS_FAILED,
85
86
87 SEC_DISABLE_IRQS_FAILED,
88
89
90
91
92 SEC_RETURN_CODE_MAX_VALUE,
93
94
95
96
97
98};
99
100enum caam_jr_op_type {
101 CAAM_JR_NONE,
102 CAAM_JR_CIPHER,
103 CAAM_JR_AUTH,
104 CAAM_JR_AEAD,
105 CAAM_JR_IPSEC,
106 CAAM_JR_PDCP,
107 CAAM_JR_PKC,
108 CAAM_JR_MAX
109};
110
111struct caam_jr_session {
112 uint8_t dir;
113 enum rte_crypto_cipher_algorithm cipher_alg;
114 enum rte_crypto_auth_algorithm auth_alg;
115 enum rte_crypto_aead_algorithm aead_alg;
116 enum rte_security_session_protocol proto_alg;
117 union {
118 struct {
119 uint8_t *data;
120 size_t length;
121 } aead_key;
122 struct {
123 struct {
124 uint8_t *data;
125 size_t length;
126 } cipher_key;
127 struct {
128 uint8_t *data;
129 size_t length;
130 } auth_key;
131 };
132 };
133 struct {
134 uint16_t length;
135 uint16_t offset;
136 } iv;
137 uint16_t auth_only_len;
138 uint32_t digest_length;
139 struct ipsec_encap_pdb encap_pdb;
140 struct ip ip4_hdr;
141 struct ipsec_decap_pdb decap_pdb;
142 struct caam_jr_qp *qp;
143 struct sec_cdb *cdb;
144 struct rte_mempool *ctx_pool;
145};
146
147
148
149
150
151#define SEC4_SG_LEN_EXT 0x80000000
152#define SEC4_SG_LEN_FIN 0x40000000
153#define SEC4_SG_BPID_MASK 0x000000ff
154#define SEC4_SG_BPID_SHIFT 16
155#define SEC4_SG_LEN_MASK 0x3fffffff
156#define SEC4_SG_OFFSET_MASK 0x00001fff
157
158struct sec4_sg_entry {
159 uint64_t ptr;
160 uint32_t len;
161 uint32_t bpid_offset;
162};
163
164#define MAX_SG_ENTRIES 16
165#define SG_CACHELINE_0 0
166#define SG_CACHELINE_1 4
167#define SG_CACHELINE_2 8
168#define SG_CACHELINE_3 12
169
170
171
172
173
174
175
176struct job_descriptor {
177 uint32_t desc[CAAM_JOB_DESC_SIZE];
178};
179
180struct caam_jr_op_ctx {
181 struct job_descriptor jobdes;
182
183 struct sec4_sg_entry sg[MAX_SG_ENTRIES];
184 struct rte_crypto_op *op;
185 struct rte_mempool *ctx_pool;
186 int64_t vtop_offset;
187 uint8_t digest[JR_MAX_NB_MAX_DIGEST];
188};
189
190
191
192
193
194
195
196
197
198static inline uint16_t
199calc_chksum(void *buffer, int len)
200{
201 uint16_t *buf = (uint16_t *)buffer;
202 uint32_t sum = 0;
203 uint16_t result;
204
205 for (sum = 0; len > 1; len -= 2)
206 sum += *buf++;
207
208 if (len == 1)
209 sum += *(unsigned char *)buf;
210
211 sum = (sum >> 16) + (sum & 0xFFFF);
212 sum += (sum >> 16);
213 result = ~sum;
214
215 return result;
216}
217struct uio_job_ring {
218 uint32_t jr_id;
219 int uio_fd;
220 void *register_base_addr;
221 int map_size;
222 int uio_minor_number;
223};
224
225int sec_cleanup(void);
226int sec_configure(void);
227void sec_uio_job_rings_init(void);
228struct uio_job_ring *config_job_ring(void);
229void free_job_ring(int uio_fd);
230
231
232static inline void *
233caam_jr_dma_mem_alloc(size_t align, size_t len)
234{
235 return rte_malloc("mem_alloc", len, align);
236}
237
238
239static inline void
240caam_jr_dma_free(void *ptr)
241{
242 rte_free(ptr);
243}
244
245static inline rte_iova_t
246caam_jr_mem_vtop(void *vaddr)
247{
248 const struct rte_memseg *ms;
249
250 ms = rte_mem_virt2memseg(vaddr, NULL);
251 if (ms)
252 return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
253 return (size_t)NULL;
254}
255
256static inline void *
257caam_jr_dma_ptov(rte_iova_t paddr)
258{
259 void *va;
260 va = dpaax_iova_table_get_va(paddr);
261 if (likely(va != NULL))
262 return va;
263
264 return rte_mem_iova2virt(paddr);
265}
266
267
268static inline rte_iova_t caam_jr_dma_vtop(void *ptr)
269{
270 return caam_jr_mem_vtop(ptr);
271}
272
273
274
275
276
277
278
279
280
281
282
283int caam_jr_enable_irqs(int uio_fd);
284
285
286
287
288
289
290
291
292
293
294
295
296int caam_jr_disable_irqs(int uio_fd);
297
298#endif
299