aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/caam_jr/caam_jr_desc.h
blob: 6683ea83509a551346449a777bb9939f7cce21b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright 2017-2018 NXP
 */

#ifndef CAAM_JR_DESC_H
#define CAAM_JR_DESC_H

#define CMD_HDR_CTYPE_SD		0x16
#define CMD_HDR_CTYPE_JD		0x17

/* The maximum size of a SEC descriptor, in WORDs (32 bits). */
#define MAX_DESC_SIZE_WORDS                     64

/*
 * Macros manipulating descriptors
 */
/* Macro for setting the SD pointer in a JD. Common for all protocols
 * supported by the SEC driver.
 */
#define SEC_JD_SET_SD(descriptor, ptr, len)	   {	  \
	(descriptor)->sd_ptr = (ptr);			       \
	(descriptor)->deschdr.command.jd.shr_desc_len = (len);      \
}

/* Macro for setting a pointer to the job which this descriptor processes.
 * It eases the lookup procedure for identifying the descriptor that has
 * completed.
 */
#define SEC_JD_SET_JOB_PTR(descriptor, ptr) \
	((descriptor)->job_ptr = (ptr))

/* Macro for setting up a JD. The structure of the JD is common across all
 * supported protocols, thus its structure is identical.
 */
#define SEC_JD_INIT(descriptor)	      ({ \
	/* CTYPE = job descriptor			       \
	 * RSMS, DNR = 0
	 * ONE = 1
	 * Start Index = 0
	 * ZRO,TD, MTD = 0
	 * SHR = 1 (there's a shared descriptor referenced
	 *	  by this job descriptor,pointer in next word)
	 * REO = 1 (execute job descr. first, shared descriptor
	 *	  after)
	 * SHARE = DEFER
	 * Descriptor Length = 0 ( to be completed @ runtime ) */ \
	(descriptor)->deschdr.command.word = 0xB0801C0D;	\
	/*
	 * CTYPE = SEQ OUT command * Scater Gather Flag = 0
	 * (can be updated @ runtime) PRE = 0 * EXT = 1
	 * (data length is in next word, following the * command)
	 * RTO = 0 */						\
	(descriptor)->seq_out.command.word = 0xF8400000; /**/	\
	/*
	 * CTYPE = SEQ IN command
	 * Scater Gather Flag = 0 (can be updated @ runtime)
	 * PRE = 0
	 * EXT = 1 ( data length is in next word, following the
	 *	   command)
	 * RTO = 0 */						\
	(descriptor)->seq_in.command.word  = 0xF0400000; /**/	\
	/*
	 * In order to be compatible with QI scenarios, the DPOVRD value
	 * loaded must be formated like this:
	 * DPOVRD_EN (1b) | Res| DPOVRD Value (right aligned). */ \
	(descriptor)->load_dpovrd.command.word = 0x16870004;	\
	/* By default, DPOVRD mechanism is disabled, thus the value to be
	 * LOAD-ed through the above descriptor command will be
	 * 0x0000_0000. */					\
	(descriptor)->dpovrd = 0x00000000;			\
})

/* Macro for setting the pointer to the input buffer in the JD, according to
 * the parameters set by the user in the ::sec_packet_t structure.
 */
#define SEC_JD_SET_IN_PTR(descriptor, phys_addr, offset, length) {     \
	(descriptor)->seq_in_ptr = (phys_addr) + (offset);	      \
	(descriptor)->in_ext_length = (length);			 \
}

/* Macro for setting the pointer to the output buffer in the JD, according to
 * the parameters set by the user in the ::sec_packet_t structure.
 */
#define SEC_JD_SET_OUT_PTR(descriptor, phys_addr, offset, length) {    \
	(descriptor)->seq_out_ptr = (phys_addr) + (offset);	     \
	(descriptor)->out_ext_length = (length);			\
}

/* Macro for setting the Scatter-Gather flag in the SEQ IN command. Used in
 * case the input buffer is split in multiple buffers, according to the user
 * specification.
 */
#define SEC_JD_SET_SG_IN(descriptor) \
	((descriptor)->seq_in.command.field.sgf =  1)

/* Macro for setting the Scatter-Gather flag in the SEQ OUT command. Used in
 * case the output buffer is split in multiple buffers, according to the user
 * specification.
 */
#define SEC_JD_SET_SG_OUT(descriptor) \
	((descriptor)->seq_out.command.field.sgf = 1)

#define SEC_JD_SET_DPOVRD(descriptor) \

/* Macro for retrieving a descriptor's length. Works for both SD and JD. */
#define SEC_GET_DESC_LEN(descriptor)					\
	(((struct descriptor_header_s *)(descriptor))->command.sd.ctype == \
	CMD_HDR_CTYPE_SD ? ((struct descriptor_header_s *) \
	(descriptor))->command.sd.desclen :	\
	((struct descriptor_header_s *)(descriptor))->command.jd.desclen)

/* Helper macro for dumping the hex representation of a descriptor */
#define SEC_DUMP_DESC(descriptor) {					\
	int __i;							\
	CAAM_JR_INFO("Des@ 0x%08x\n", (uint32_t)((uint32_t *)(descriptor)));\
	for (__i = 0;						\
		__i < SEC_GET_DESC_LEN(descriptor);			\
		__i++) {						\
		printf("0x%08x: 0x%08x\n",			\
			(uint32_t)(((uint32_t *)(descriptor)) + __i),	\
			*(((uint32_t *)(descriptor)) + __i));		\
	}								\
}
/* Union describing a descriptor header.
 */
struct descriptor_header_s {
	union {
		uint32_t word;
		struct {
			/* 4  */ unsigned int ctype:5;
			/* 5  */ unsigned int res1:2;
			/* 7  */ unsigned int dnr:1;
			/* 8  */ unsigned int one:1;
			/* 9  */ unsigned int res2:1;
			/* 10 */ unsigned int start_idx:6;
			/* 16 */ unsigned int res3:2;
			/* 18 */ unsigned int cif:1;
			/* 19 */ unsigned int sc:1;
			/* 20 */ unsigned int pd:1;
			/* 21 */ unsigned int res4:1;
			/* 22 */ unsigned int share:2;
			/* 24 */ unsigned int res5:2;
			/* 26 */ unsigned int desclen:6;
		} sd;
		struct {
			/* TODO only below struct members are corrected,
			 * all others also need to be reversed please verify it
			 */
			/* 0 */ unsigned int desclen:7;
			/* 7 */ unsigned int res4:1;
			/* 8 */ unsigned int share:3;
			/* 11 */ unsigned int reo:1;
			/* 12 */ unsigned int shr:1;
			/* 13 */ unsigned int mtd:1;
			/* 14 */ unsigned int td:1;
			/* 15 */ unsigned int zero:1;
			/* 16 */ unsigned int shr_desc_len:6;
			/* 22  */ unsigned int res2:1;
			/* 23  */ unsigned int one:1;
			/* 24  */ unsigned int dnr:1;
			/* 25  */ unsigned int rsms:1;
			/* 26  */ unsigned int res1:1;
			/* 27  */ unsigned int ctype:5;
		} jd;
	} __rte_packed command;
} __rte_packed;

/* Union describing a KEY command in a descriptor.
 */
struct key_command_s {
	union {
		uint32_t word;
		struct {
			unsigned int ctype:5;
			unsigned int cls:2;
			unsigned int sgf:1;
			unsigned int imm:1;
			unsigned int enc:1;
			unsigned int nwb:1;
			unsigned int ekt:1;
			unsigned int kdest:4;
			unsigned int tk:1;
			unsigned int rsvd1:5;
			unsigned int length:10;
		} __rte_packed field;
	} __rte_packed command;
} __rte_packed;

/* Union describing a PROTOCOL command
 * in a descriptor.
 */
struct protocol_operation_command_s {
	union {
		uint32_t word;
		struct {
			unsigned int ctype:5;
			unsigned int optype:3;
			unsigned char protid;
			unsigned short protinfo;
		} __rte_packed field;
	} __rte_packed command;
} __rte_packed;

/* Union describing a SEQIN command in a
 * descriptor.
 */
struct seq_in_command_s {
	union {
		uint32_t word;
		struct {
			unsigned int ctype:5;
			unsigned int res1:1;
			unsigned int inl:1;
			unsigned int sgf:1;
			unsigned int pre:1;
			unsigned int ext:1;
			unsigned int rto:1;
			unsigned int rjd:1;
			unsigned int res2:4;
			unsigned int length:16;
		} field;
	} __rte_packed command;
} __rte_packed;

/* Union describing a SEQOUT command in a
 * descriptor.
 */
struct seq_out_command_s {
	union {
		uint32_t word;
		struct {
			unsigned int ctype:5;
			unsigned int res1:2;
			unsigned int sgf:1;
			unsigned int pre:1;
			unsigned int ext:1;
			unsigned int rto:1;
			unsigned int res2:5;
			unsigned int length:16;
		} field;
	} __rte_packed command;
} __rte_packed;

struct load_command_s {
	union {
		uint32_t word;
		struct {
			unsigned int ctype:5;
			unsigned int class:2;
			unsigned int sgf:1;
			unsigned int imm:1;
			unsigned int dst:7;
			unsigned char offset;
			unsigned char length;
		} fields;
	} __rte_packed command;
} __rte_packed;

/* Structure encompassing a general shared descriptor of maximum
 * size (64 WORDs). Usually, other specific shared descriptor structures
 * will be type-casted to this one
 * this one.
 */
struct sec_sd_t {
	uint32_t rsvd[MAX_DESC_SIZE_WORDS];
} __attribute__((packed, aligned(64)));

/* Structure encompassing a job descriptor which processes
 * a single packet from a context. The job descriptor references
 * a shared descriptor from a SEC context.
 */
struct sec_job_descriptor_t {
	struct descriptor_header_s deschdr;
	dma_addr_t sd_ptr;
	struct seq_out_command_s seq_out;
	dma_addr_t seq_out_ptr;
	uint32_t out_ext_length;
	struct seq_in_command_s seq_in;
	dma_addr_t seq_in_ptr;
	uint32_t in_ext_length;
	struct load_command_s load_dpovrd;
	uint32_t dpovrd;
} __attribute__((packed, aligned(64)));

#endif