aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/dpaa2_sec/hw/rta/header_cmd.h
blob: 0c7ea9387c368cc974fbe4fdff519cd4268f784d (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
/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
 *
 * Copyright 2008-2016 Freescale Semiconductor Inc.
 * Copyright 2016 NXP
 *
 */

#ifndef __RTA_HEADER_CMD_H__
#define __RTA_HEADER_CMD_H__

extern enum rta_sec_era rta_sec_era;

/* Allowed job header flags for each SEC Era. */
static const uint32_t job_header_flags[] = {
	DNR | TD | MTD | SHR | REO,
	DNR | TD | MTD | SHR | REO | RSMS,
	DNR | TD | MTD | SHR | REO | RSMS,
	DNR | TD | MTD | SHR | REO | RSMS,
	DNR | TD | MTD | SHR | REO | RSMS | EXT,
	DNR | TD | MTD | SHR | REO | RSMS | EXT,
	DNR | TD | MTD | SHR | REO | RSMS | EXT,
	DNR | TD | MTD | SHR | REO | EXT
};

/* Allowed shared header flags for each SEC Era. */
static const uint32_t shr_header_flags[] = {
	DNR | SC | PD,
	DNR | SC | PD | CIF,
	DNR | SC | PD | CIF,
	DNR | SC | PD | CIF | RIF,
	DNR | SC | PD | CIF | RIF,
	DNR | SC | PD | CIF | RIF,
	DNR | SC | PD | CIF | RIF,
	DNR | SC | PD | CIF | RIF
};

static inline int
rta_shr_header(struct program *program,
	       enum rta_share_type share,
	       unsigned int start_idx,
	       uint32_t flags)
{
	uint32_t opcode = CMD_SHARED_DESC_HDR;
	unsigned int start_pc = program->current_pc;

	if (flags & ~shr_header_flags[rta_sec_era]) {
		pr_err("SHR_DESC: Flag(s) not supported by SEC Era %d\n",
		       USER_SEC_ERA(rta_sec_era));
		goto err;
	}

	switch (share) {
	case SHR_ALWAYS:
		opcode |= HDR_SHARE_ALWAYS;
		break;
	case SHR_SERIAL:
		opcode |= HDR_SHARE_SERIAL;
		break;
	case SHR_NEVER:
		/*
		 * opcode |= HDR_SHARE_NEVER;
		 * HDR_SHARE_NEVER is 0
		 */
		break;
	case SHR_WAIT:
		opcode |= HDR_SHARE_WAIT;
		break;
	default:
		pr_err("SHR_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
		       program->current_pc);
		goto err;
	}

	opcode |= HDR_ONE;
	opcode |= (start_idx << HDR_START_IDX_SHIFT) & HDR_START_IDX_MASK;

	if (flags & DNR)
		opcode |= HDR_DNR;
	if (flags & CIF)
		opcode |= HDR_CLEAR_IFIFO;
	if (flags & SC)
		opcode |= HDR_SAVECTX;
	if (flags & PD)
		opcode |= HDR_PROP_DNR;
	if (flags & RIF)
		opcode |= HDR_RIF;

	__rta_out32(program, opcode);
	program->current_instruction++;

	if (program->current_instruction == 1)
		program->shrhdr = program->buffer;

	return (int)start_pc;

 err:
	program->first_error_pc = start_pc;
	program->current_instruction++;
	return -EINVAL;
}

static inline int
rta_job_header(struct program *program,
	       enum rta_share_type share,
	       unsigned int start_idx,
	       uint64_t shr_desc, uint32_t flags,
	       uint32_t ext_flags)
{
	uint32_t opcode = CMD_DESC_HDR;
	uint32_t hdr_ext = 0;
	unsigned int start_pc = program->current_pc;

	if (flags & ~job_header_flags[rta_sec_era]) {
		pr_err("JOB_DESC: Flag(s) not supported by SEC Era %d\n",
		       USER_SEC_ERA(rta_sec_era));
		goto err;
	}

	switch (share) {
	case SHR_ALWAYS:
		opcode |= HDR_SHARE_ALWAYS;
		break;
	case SHR_SERIAL:
		opcode |= HDR_SHARE_SERIAL;
		break;
	case SHR_NEVER:
		/*
		 * opcode |= HDR_SHARE_NEVER;
		 * HDR_SHARE_NEVER is 0
		 */
		break;
	case SHR_WAIT:
		opcode |= HDR_SHARE_WAIT;
		break;
	case SHR_DEFER:
		opcode |= HDR_SHARE_DEFER;
		break;
	default:
		pr_err("JOB_DESC: SHARE VALUE is not supported. SEC Program Line: %d\n",
		       program->current_pc);
		goto err;
	}

	if ((flags & TD) && (flags & REO)) {
		pr_err("JOB_DESC: REO flag not supported for trusted descriptors. SEC Program Line: %d\n",
		       program->current_pc);
		goto err;
	}

	if ((rta_sec_era < RTA_SEC_ERA_7) && (flags & MTD) && !(flags & TD)) {
		pr_err("JOB_DESC: Trying to MTD a descriptor that is not a TD. SEC Program Line: %d\n",
		       program->current_pc);
		goto err;
	}

	if ((flags & EXT) && !(flags & SHR) && (start_idx < 2)) {
		pr_err("JOB_DESC: Start index must be >= 2 in case of no SHR and EXT. SEC Program Line: %d\n",
		       program->current_pc);
		goto err;
	}

	opcode |= HDR_ONE;
	opcode |= ((start_idx << HDR_START_IDX_SHIFT) & HDR_START_IDX_MASK);

	if (flags & EXT) {
		opcode |= HDR_EXT;

		if (ext_flags & DSV) {
			hdr_ext |= HDR_EXT_DSEL_VALID;
			hdr_ext |= ext_flags & DSEL_MASK;
		}

		if (ext_flags & FTD) {
			if (rta_sec_era <= RTA_SEC_ERA_5) {
				pr_err("JOB_DESC: Fake trusted descriptor not supported by SEC Era %d\n",
				       USER_SEC_ERA(rta_sec_era));
				goto err;
			}

			hdr_ext |= HDR_EXT_FTD;
		}
	}
	if (flags & RSMS)
		opcode |= HDR_RSLS;
	if (flags & DNR)
		opcode |= HDR_DNR;
	if (flags & TD)
		opcode |= HDR_TRUSTED;
	if (flags & MTD)
		opcode |= HDR_MAKE_TRUSTED;
	if (flags & REO)
		opcode |= HDR_REVERSE;
	if (flags & SHR)
		opcode |= HDR_SHARED;

	__rta_out32(program, opcode);
	program->current_instruction++;

	if (program->current_instruction == 1) {
		program->jobhdr = program->buffer;

		if (opcode & HDR_SHARED)
			__rta_out64(program, program->ps, shr_desc);
	}

	if (flags & EXT)
		__rta_out32(program, hdr_ext);

	/* Note: descriptor length is set in program_finalize routine */
	return (int)start_pc;

 err:
	program->first_error_pc = start_pc;
	program->current_instruction++;
	return -EINVAL;
}

#endif /* __RTA_HEADER_CMD_H__ */