xref: /linux/arch/s390/include/asm/cpacf.h (revision 66e72a01b60ae6950ddbb3585fdc1424d303e14b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * CP Assist for Cryptographic Functions (CPACF)
4  *
5  * Copyright IBM Corp. 2003, 2023
6  * Author(s): Thomas Spatzier
7  *	      Jan Glauber
8  *	      Harald Freudenberger (freude@de.ibm.com)
9  *	      Martin Schwidefsky <schwidefsky@de.ibm.com>
10  */
11 #ifndef _ASM_S390_CPACF_H
12 #define _ASM_S390_CPACF_H
13 
14 #include <asm/facility.h>
15 #include <linux/kmsan-checks.h>
16 
17 /*
18  * Instruction opcodes for the CPACF instructions
19  */
20 #define CPACF_KMAC		0xb91e		/* MSA	*/
21 #define CPACF_KM		0xb92e		/* MSA	*/
22 #define CPACF_KMC		0xb92f		/* MSA	*/
23 #define CPACF_KIMD		0xb93e		/* MSA	*/
24 #define CPACF_KLMD		0xb93f		/* MSA	*/
25 #define CPACF_PCKMO		0xb928		/* MSA3 */
26 #define CPACF_KMF		0xb92a		/* MSA4 */
27 #define CPACF_KMO		0xb92b		/* MSA4 */
28 #define CPACF_PCC		0xb92c		/* MSA4 */
29 #define CPACF_KMCTR		0xb92d		/* MSA4 */
30 #define CPACF_PRNO		0xb93c		/* MSA5 */
31 #define CPACF_KMA		0xb929		/* MSA8 */
32 #define CPACF_KDSA		0xb93a		/* MSA9 */
33 
34 /*
35  * En/decryption modifier bits
36  */
37 #define CPACF_ENCRYPT		0x00
38 #define CPACF_DECRYPT		0x80
39 
40 /*
41  * Function codes for the KM (CIPHER MESSAGE) instruction
42  */
43 #define CPACF_KM_QUERY		0x00
44 #define CPACF_KM_DEA		0x01
45 #define CPACF_KM_TDEA_128	0x02
46 #define CPACF_KM_TDEA_192	0x03
47 #define CPACF_KM_AES_128	0x12
48 #define CPACF_KM_AES_192	0x13
49 #define CPACF_KM_AES_256	0x14
50 #define CPACF_KM_PAES_128	0x1a
51 #define CPACF_KM_PAES_192	0x1b
52 #define CPACF_KM_PAES_256	0x1c
53 #define CPACF_KM_XTS_128	0x32
54 #define CPACF_KM_XTS_256	0x34
55 #define CPACF_KM_PXTS_128	0x3a
56 #define CPACF_KM_PXTS_256	0x3c
57 
58 /*
59  * Function codes for the KMC (CIPHER MESSAGE WITH CHAINING)
60  * instruction
61  */
62 #define CPACF_KMC_QUERY		0x00
63 #define CPACF_KMC_DEA		0x01
64 #define CPACF_KMC_TDEA_128	0x02
65 #define CPACF_KMC_TDEA_192	0x03
66 #define CPACF_KMC_AES_128	0x12
67 #define CPACF_KMC_AES_192	0x13
68 #define CPACF_KMC_AES_256	0x14
69 #define CPACF_KMC_PAES_128	0x1a
70 #define CPACF_KMC_PAES_192	0x1b
71 #define CPACF_KMC_PAES_256	0x1c
72 #define CPACF_KMC_PRNG		0x43
73 
74 /*
75  * Function codes for the KMCTR (CIPHER MESSAGE WITH COUNTER)
76  * instruction
77  */
78 #define CPACF_KMCTR_QUERY	0x00
79 #define CPACF_KMCTR_DEA		0x01
80 #define CPACF_KMCTR_TDEA_128	0x02
81 #define CPACF_KMCTR_TDEA_192	0x03
82 #define CPACF_KMCTR_AES_128	0x12
83 #define CPACF_KMCTR_AES_192	0x13
84 #define CPACF_KMCTR_AES_256	0x14
85 #define CPACF_KMCTR_PAES_128	0x1a
86 #define CPACF_KMCTR_PAES_192	0x1b
87 #define CPACF_KMCTR_PAES_256	0x1c
88 
89 /*
90  * Function codes for the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
91  * instruction
92  */
93 #define CPACF_KIMD_QUERY	0x00
94 #define CPACF_KIMD_SHA_1	0x01
95 #define CPACF_KIMD_SHA_256	0x02
96 #define CPACF_KIMD_SHA_512	0x03
97 #define CPACF_KIMD_SHA3_224	0x20
98 #define CPACF_KIMD_SHA3_256	0x21
99 #define CPACF_KIMD_SHA3_384	0x22
100 #define CPACF_KIMD_SHA3_512	0x23
101 #define CPACF_KIMD_GHASH	0x41
102 
103 /*
104  * Function codes for the KLMD (COMPUTE LAST MESSAGE DIGEST)
105  * instruction
106  */
107 #define CPACF_KLMD_QUERY	0x00
108 #define CPACF_KLMD_SHA_1	0x01
109 #define CPACF_KLMD_SHA_256	0x02
110 #define CPACF_KLMD_SHA_512	0x03
111 #define CPACF_KLMD_SHA3_224	0x20
112 #define CPACF_KLMD_SHA3_256	0x21
113 #define CPACF_KLMD_SHA3_384	0x22
114 #define CPACF_KLMD_SHA3_512	0x23
115 
116 /*
117  * function codes for the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
118  * instruction
119  */
120 #define CPACF_KMAC_QUERY	0x00
121 #define CPACF_KMAC_DEA		0x01
122 #define CPACF_KMAC_TDEA_128	0x02
123 #define CPACF_KMAC_TDEA_192	0x03
124 
125 /*
126  * Function codes for the PCKMO (PERFORM CRYPTOGRAPHIC KEY MANAGEMENT)
127  * instruction
128  */
129 #define CPACF_PCKMO_QUERY		0x00
130 #define CPACF_PCKMO_ENC_DES_KEY		0x01
131 #define CPACF_PCKMO_ENC_TDES_128_KEY	0x02
132 #define CPACF_PCKMO_ENC_TDES_192_KEY	0x03
133 #define CPACF_PCKMO_ENC_AES_128_KEY	0x12
134 #define CPACF_PCKMO_ENC_AES_192_KEY	0x13
135 #define CPACF_PCKMO_ENC_AES_256_KEY	0x14
136 #define CPACF_PCKMO_ENC_ECC_P256_KEY	0x20
137 #define CPACF_PCKMO_ENC_ECC_P384_KEY	0x21
138 #define CPACF_PCKMO_ENC_ECC_P521_KEY	0x22
139 #define CPACF_PCKMO_ENC_ECC_ED25519_KEY	0x28
140 #define CPACF_PCKMO_ENC_ECC_ED448_KEY	0x29
141 
142 /*
143  * Function codes for the PRNO (PERFORM RANDOM NUMBER OPERATION)
144  * instruction
145  */
146 #define CPACF_PRNO_QUERY		0x00
147 #define CPACF_PRNO_SHA512_DRNG_GEN	0x03
148 #define CPACF_PRNO_SHA512_DRNG_SEED	0x83
149 #define CPACF_PRNO_TRNG_Q_R2C_RATIO	0x70
150 #define CPACF_PRNO_TRNG			0x72
151 
152 /*
153  * Function codes for the KMA (CIPHER MESSAGE WITH AUTHENTICATION)
154  * instruction
155  */
156 #define CPACF_KMA_QUERY		0x00
157 #define CPACF_KMA_GCM_AES_128	0x12
158 #define CPACF_KMA_GCM_AES_192	0x13
159 #define CPACF_KMA_GCM_AES_256	0x14
160 
161 /*
162  * Flags for the KMA (CIPHER MESSAGE WITH AUTHENTICATION) instruction
163  */
164 #define CPACF_KMA_LPC	0x100	/* Last-Plaintext/Ciphertext */
165 #define CPACF_KMA_LAAD	0x200	/* Last-AAD */
166 #define CPACF_KMA_HS	0x400	/* Hash-subkey Supplied */
167 
168 typedef struct { unsigned char bytes[16]; } cpacf_mask_t;
169 
170 /*
171  * Prototype for a not existing function to produce a link
172  * error if __cpacf_query() or __cpacf_check_opcode() is used
173  * with an invalid compile time const opcode.
174  */
175 void __cpacf_bad_opcode(void);
176 
177 static __always_inline void __cpacf_query_rre(u32 opc, u8 r1, u8 r2,
178 					      cpacf_mask_t *mask)
179 {
180 	asm volatile(
181 		"	la	%%r1,%[mask]\n"
182 		"	xgr	%%r0,%%r0\n"
183 		"	.insn	rre,%[opc] << 16,%[r1],%[r2]\n"
184 		: [mask] "=R" (*mask)
185 		: [opc] "i" (opc),
186 		  [r1] "i" (r1), [r2] "i" (r2)
187 		: "cc", "r0", "r1");
188 }
189 
190 static __always_inline void __cpacf_query_rrf(u32 opc,
191 					      u8 r1, u8 r2, u8 r3, u8 m4,
192 					      cpacf_mask_t *mask)
193 {
194 	asm volatile(
195 		"	la	%%r1,%[mask]\n"
196 		"	xgr	%%r0,%%r0\n"
197 		"	.insn	rrf,%[opc] << 16,%[r1],%[r2],%[r3],%[m4]\n"
198 		: [mask] "=R" (*mask)
199 		: [opc] "i" (opc), [r1] "i" (r1), [r2] "i" (r2),
200 		  [r3] "i" (r3), [m4] "i" (m4)
201 		: "cc", "r0", "r1");
202 }
203 
204 static __always_inline void __cpacf_query(unsigned int opcode,
205 					  cpacf_mask_t *mask)
206 {
207 	switch (opcode) {
208 	case CPACF_KDSA:
209 		__cpacf_query_rre(CPACF_KDSA, 0, 2, mask);
210 		break;
211 	case CPACF_KIMD:
212 		__cpacf_query_rre(CPACF_KIMD, 0, 2, mask);
213 		break;
214 	case CPACF_KLMD:
215 		__cpacf_query_rre(CPACF_KLMD, 0, 2, mask);
216 		break;
217 	case CPACF_KM:
218 		__cpacf_query_rre(CPACF_KM, 2, 4, mask);
219 		break;
220 	case CPACF_KMA:
221 		__cpacf_query_rrf(CPACF_KMA, 2, 4, 6, 0, mask);
222 		break;
223 	case CPACF_KMAC:
224 		__cpacf_query_rre(CPACF_KMAC, 0, 2, mask);
225 		break;
226 	case CPACF_KMC:
227 		__cpacf_query_rre(CPACF_KMC, 2, 4, mask);
228 		break;
229 	case CPACF_KMCTR:
230 		__cpacf_query_rrf(CPACF_KMCTR, 2, 4, 6, 0, mask);
231 		break;
232 	case CPACF_KMF:
233 		__cpacf_query_rre(CPACF_KMF, 2, 4, mask);
234 		break;
235 	case CPACF_KMO:
236 		__cpacf_query_rre(CPACF_KMO, 2, 4, mask);
237 		break;
238 	case CPACF_PCC:
239 		__cpacf_query_rre(CPACF_PCC, 0, 0, mask);
240 		break;
241 	case CPACF_PCKMO:
242 		__cpacf_query_rre(CPACF_PCKMO, 0, 0, mask);
243 		break;
244 	case CPACF_PRNO:
245 		__cpacf_query_rre(CPACF_PRNO, 2, 4, mask);
246 		break;
247 	default:
248 		__cpacf_bad_opcode();
249 	}
250 }
251 
252 static __always_inline int __cpacf_check_opcode(unsigned int opcode)
253 {
254 	switch (opcode) {
255 	case CPACF_KMAC:
256 	case CPACF_KM:
257 	case CPACF_KMC:
258 	case CPACF_KIMD:
259 	case CPACF_KLMD:
260 		return test_facility(17);	/* check for MSA */
261 	case CPACF_PCKMO:
262 		return test_facility(76);	/* check for MSA3 */
263 	case CPACF_KMF:
264 	case CPACF_KMO:
265 	case CPACF_PCC:
266 	case CPACF_KMCTR:
267 		return test_facility(77);	/* check for MSA4 */
268 	case CPACF_PRNO:
269 		return test_facility(57);	/* check for MSA5 */
270 	case CPACF_KMA:
271 		return test_facility(146);	/* check for MSA8 */
272 	default:
273 		__cpacf_bad_opcode();
274 		return 0;
275 	}
276 }
277 
278 /**
279  * cpacf_query() - check if a specific CPACF function is available
280  * @opcode: the opcode of the crypto instruction
281  * @func: the function code to test for
282  *
283  * Executes the query function for the given crypto instruction @opcode
284  * and checks if @func is available
285  *
286  * Returns 1 if @func is available for @opcode, 0 otherwise
287  */
288 static __always_inline int cpacf_query(unsigned int opcode, cpacf_mask_t *mask)
289 {
290 	if (__cpacf_check_opcode(opcode)) {
291 		__cpacf_query(opcode, mask);
292 		return 1;
293 	}
294 	memset(mask, 0, sizeof(*mask));
295 	return 0;
296 }
297 
298 static inline int cpacf_test_func(cpacf_mask_t *mask, unsigned int func)
299 {
300 	return (mask->bytes[func >> 3] & (0x80 >> (func & 7))) != 0;
301 }
302 
303 static __always_inline int cpacf_query_func(unsigned int opcode, unsigned int func)
304 {
305 	cpacf_mask_t mask;
306 
307 	if (cpacf_query(opcode, &mask))
308 		return cpacf_test_func(&mask, func);
309 	return 0;
310 }
311 
312 /**
313  * cpacf_km() - executes the KM (CIPHER MESSAGE) instruction
314  * @func: the function code passed to KM; see CPACF_KM_xxx defines
315  * @param: address of parameter block; see POP for details on each func
316  * @dest: address of destination memory area
317  * @src: address of source memory area
318  * @src_len: length of src operand in bytes
319  *
320  * Returns 0 for the query func, number of processed bytes for
321  * encryption/decryption funcs
322  */
323 static inline int cpacf_km(unsigned long func, void *param,
324 			   u8 *dest, const u8 *src, long src_len)
325 {
326 	union register_pair d, s;
327 
328 	d.even = (unsigned long)dest;
329 	s.even = (unsigned long)src;
330 	s.odd  = (unsigned long)src_len;
331 	asm volatile(
332 		"	lgr	0,%[fc]\n"
333 		"	lgr	1,%[pba]\n"
334 		"0:	.insn	rre,%[opc] << 16,%[dst],%[src]\n"
335 		"	brc	1,0b\n" /* handle partial completion */
336 		: [src] "+&d" (s.pair), [dst] "+&d" (d.pair)
337 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
338 		  [opc] "i" (CPACF_KM)
339 		: "cc", "memory", "0", "1");
340 
341 	return src_len - s.odd;
342 }
343 
344 /**
345  * cpacf_kmc() - executes the KMC (CIPHER MESSAGE WITH CHAINING) instruction
346  * @func: the function code passed to KM; see CPACF_KMC_xxx defines
347  * @param: address of parameter block; see POP for details on each func
348  * @dest: address of destination memory area
349  * @src: address of source memory area
350  * @src_len: length of src operand in bytes
351  *
352  * Returns 0 for the query func, number of processed bytes for
353  * encryption/decryption funcs
354  */
355 static inline int cpacf_kmc(unsigned long func, void *param,
356 			    u8 *dest, const u8 *src, long src_len)
357 {
358 	union register_pair d, s;
359 
360 	d.even = (unsigned long)dest;
361 	s.even = (unsigned long)src;
362 	s.odd  = (unsigned long)src_len;
363 	asm volatile(
364 		"	lgr	0,%[fc]\n"
365 		"	lgr	1,%[pba]\n"
366 		"0:	.insn	rre,%[opc] << 16,%[dst],%[src]\n"
367 		"	brc	1,0b\n" /* handle partial completion */
368 		: [src] "+&d" (s.pair), [dst] "+&d" (d.pair)
369 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
370 		  [opc] "i" (CPACF_KMC)
371 		: "cc", "memory", "0", "1");
372 
373 	return src_len - s.odd;
374 }
375 
376 /**
377  * cpacf_kimd() - executes the KIMD (COMPUTE INTERMEDIATE MESSAGE DIGEST)
378  *		  instruction
379  * @func: the function code passed to KM; see CPACF_KIMD_xxx defines
380  * @param: address of parameter block; see POP for details on each func
381  * @src: address of source memory area
382  * @src_len: length of src operand in bytes
383  */
384 static inline void cpacf_kimd(unsigned long func, void *param,
385 			      const u8 *src, long src_len)
386 {
387 	union register_pair s;
388 
389 	s.even = (unsigned long)src;
390 	s.odd  = (unsigned long)src_len;
391 	asm volatile(
392 		"	lgr	0,%[fc]\n"
393 		"	lgr	1,%[pba]\n"
394 		"0:	.insn	rre,%[opc] << 16,0,%[src]\n"
395 		"	brc	1,0b\n" /* handle partial completion */
396 		: [src] "+&d" (s.pair)
397 		: [fc] "d" (func), [pba] "d" ((unsigned long)(param)),
398 		  [opc] "i" (CPACF_KIMD)
399 		: "cc", "memory", "0", "1");
400 }
401 
402 /**
403  * cpacf_klmd() - executes the KLMD (COMPUTE LAST MESSAGE DIGEST) instruction
404  * @func: the function code passed to KM; see CPACF_KLMD_xxx defines
405  * @param: address of parameter block; see POP for details on each func
406  * @src: address of source memory area
407  * @src_len: length of src operand in bytes
408  */
409 static inline void cpacf_klmd(unsigned long func, void *param,
410 			      const u8 *src, long src_len)
411 {
412 	union register_pair s;
413 
414 	s.even = (unsigned long)src;
415 	s.odd  = (unsigned long)src_len;
416 	asm volatile(
417 		"	lgr	0,%[fc]\n"
418 		"	lgr	1,%[pba]\n"
419 		"0:	.insn	rre,%[opc] << 16,0,%[src]\n"
420 		"	brc	1,0b\n" /* handle partial completion */
421 		: [src] "+&d" (s.pair)
422 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
423 		  [opc] "i" (CPACF_KLMD)
424 		: "cc", "memory", "0", "1");
425 }
426 
427 /**
428  * cpacf_kmac() - executes the KMAC (COMPUTE MESSAGE AUTHENTICATION CODE)
429  *		  instruction
430  * @func: the function code passed to KM; see CPACF_KMAC_xxx defines
431  * @param: address of parameter block; see POP for details on each func
432  * @src: address of source memory area
433  * @src_len: length of src operand in bytes
434  *
435  * Returns 0 for the query func, number of processed bytes for digest funcs
436  */
437 static inline int cpacf_kmac(unsigned long func, void *param,
438 			     const u8 *src, long src_len)
439 {
440 	union register_pair s;
441 
442 	s.even = (unsigned long)src;
443 	s.odd  = (unsigned long)src_len;
444 	asm volatile(
445 		"	lgr	0,%[fc]\n"
446 		"	lgr	1,%[pba]\n"
447 		"0:	.insn	rre,%[opc] << 16,0,%[src]\n"
448 		"	brc	1,0b\n" /* handle partial completion */
449 		: [src] "+&d" (s.pair)
450 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
451 		  [opc] "i" (CPACF_KMAC)
452 		: "cc", "memory", "0", "1");
453 
454 	return src_len - s.odd;
455 }
456 
457 /**
458  * cpacf_kmctr() - executes the KMCTR (CIPHER MESSAGE WITH COUNTER) instruction
459  * @func: the function code passed to KMCTR; see CPACF_KMCTR_xxx defines
460  * @param: address of parameter block; see POP for details on each func
461  * @dest: address of destination memory area
462  * @src: address of source memory area
463  * @src_len: length of src operand in bytes
464  * @counter: address of counter value
465  *
466  * Returns 0 for the query func, number of processed bytes for
467  * encryption/decryption funcs
468  */
469 static inline int cpacf_kmctr(unsigned long func, void *param, u8 *dest,
470 			      const u8 *src, long src_len, u8 *counter)
471 {
472 	union register_pair d, s, c;
473 
474 	d.even = (unsigned long)dest;
475 	s.even = (unsigned long)src;
476 	s.odd  = (unsigned long)src_len;
477 	c.even = (unsigned long)counter;
478 	asm volatile(
479 		"	lgr	0,%[fc]\n"
480 		"	lgr	1,%[pba]\n"
481 		"0:	.insn	rrf,%[opc] << 16,%[dst],%[src],%[ctr],0\n"
482 		"	brc	1,0b\n" /* handle partial completion */
483 		: [src] "+&d" (s.pair), [dst] "+&d" (d.pair),
484 		  [ctr] "+&d" (c.pair)
485 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
486 		  [opc] "i" (CPACF_KMCTR)
487 		: "cc", "memory", "0", "1");
488 
489 	return src_len - s.odd;
490 }
491 
492 /**
493  * cpacf_prno() - executes the PRNO (PERFORM RANDOM NUMBER OPERATION)
494  *		  instruction
495  * @func: the function code passed to PRNO; see CPACF_PRNO_xxx defines
496  * @param: address of parameter block; see POP for details on each func
497  * @dest: address of destination memory area
498  * @dest_len: size of destination memory area in bytes
499  * @seed: address of seed data
500  * @seed_len: size of seed data in bytes
501  */
502 static inline void cpacf_prno(unsigned long func, void *param,
503 			      u8 *dest, unsigned long dest_len,
504 			      const u8 *seed, unsigned long seed_len)
505 {
506 	union register_pair d, s;
507 
508 	d.even = (unsigned long)dest;
509 	d.odd  = (unsigned long)dest_len;
510 	s.even = (unsigned long)seed;
511 	s.odd  = (unsigned long)seed_len;
512 	asm volatile (
513 		"	lgr	0,%[fc]\n"
514 		"	lgr	1,%[pba]\n"
515 		"0:	.insn	rre,%[opc] << 16,%[dst],%[seed]\n"
516 		"	brc	1,0b\n"	  /* handle partial completion */
517 		: [dst] "+&d" (d.pair)
518 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
519 		  [seed] "d" (s.pair), [opc] "i" (CPACF_PRNO)
520 		: "cc", "memory", "0", "1");
521 }
522 
523 /**
524  * cpacf_trng() - executes the TRNG subfunction of the PRNO instruction
525  * @ucbuf: buffer for unconditioned data
526  * @ucbuf_len: amount of unconditioned data to fetch in bytes
527  * @cbuf: buffer for conditioned data
528  * @cbuf_len: amount of conditioned data to fetch in bytes
529  */
530 static inline void cpacf_trng(u8 *ucbuf, unsigned long ucbuf_len,
531 			      u8 *cbuf, unsigned long cbuf_len)
532 {
533 	union register_pair u, c;
534 
535 	u.even = (unsigned long)ucbuf;
536 	u.odd  = (unsigned long)ucbuf_len;
537 	c.even = (unsigned long)cbuf;
538 	c.odd  = (unsigned long)cbuf_len;
539 	asm volatile (
540 		"	lghi	0,%[fc]\n"
541 		"0:	.insn	rre,%[opc] << 16,%[ucbuf],%[cbuf]\n"
542 		"	brc	1,0b\n"	  /* handle partial completion */
543 		: [ucbuf] "+&d" (u.pair), [cbuf] "+&d" (c.pair)
544 		: [fc] "K" (CPACF_PRNO_TRNG), [opc] "i" (CPACF_PRNO)
545 		: "cc", "memory", "0");
546 	kmsan_unpoison_memory(ucbuf, ucbuf_len);
547 	kmsan_unpoison_memory(cbuf, cbuf_len);
548 }
549 
550 /**
551  * cpacf_pcc() - executes the PCC (PERFORM CRYPTOGRAPHIC COMPUTATION)
552  *		 instruction
553  * @func: the function code passed to PCC; see CPACF_KM_xxx defines
554  * @param: address of parameter block; see POP for details on each func
555  */
556 static inline void cpacf_pcc(unsigned long func, void *param)
557 {
558 	asm volatile(
559 		"	lgr	0,%[fc]\n"
560 		"	lgr	1,%[pba]\n"
561 		"0:	.insn	rre,%[opc] << 16,0,0\n" /* PCC opcode */
562 		"	brc	1,0b\n" /* handle partial completion */
563 		:
564 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
565 		  [opc] "i" (CPACF_PCC)
566 		: "cc", "memory", "0", "1");
567 }
568 
569 /**
570  * cpacf_pckmo() - executes the PCKMO (PERFORM CRYPTOGRAPHIC KEY
571  *		  MANAGEMENT) instruction
572  * @func: the function code passed to PCKMO; see CPACF_PCKMO_xxx defines
573  * @param: address of parameter block; see POP for details on each func
574  *
575  * Returns 0.
576  */
577 static inline void cpacf_pckmo(long func, void *param)
578 {
579 	asm volatile(
580 		"	lgr	0,%[fc]\n"
581 		"	lgr	1,%[pba]\n"
582 		"       .insn   rre,%[opc] << 16,0,0\n" /* PCKMO opcode */
583 		:
584 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
585 		  [opc] "i" (CPACF_PCKMO)
586 		: "cc", "memory", "0", "1");
587 }
588 
589 /**
590  * cpacf_kma() - executes the KMA (CIPHER MESSAGE WITH AUTHENTICATION)
591  *		 instruction
592  * @func: the function code passed to KMA; see CPACF_KMA_xxx defines
593  * @param: address of parameter block; see POP for details on each func
594  * @dest: address of destination memory area
595  * @src: address of source memory area
596  * @src_len: length of src operand in bytes
597  * @aad: address of additional authenticated data memory area
598  * @aad_len: length of aad operand in bytes
599  */
600 static inline void cpacf_kma(unsigned long func, void *param, u8 *dest,
601 			     const u8 *src, unsigned long src_len,
602 			     const u8 *aad, unsigned long aad_len)
603 {
604 	union register_pair d, s, a;
605 
606 	d.even = (unsigned long)dest;
607 	s.even = (unsigned long)src;
608 	s.odd  = (unsigned long)src_len;
609 	a.even = (unsigned long)aad;
610 	a.odd  = (unsigned long)aad_len;
611 	asm volatile(
612 		"	lgr	0,%[fc]\n"
613 		"	lgr	1,%[pba]\n"
614 		"0:	.insn	rrf,%[opc] << 16,%[dst],%[src],%[aad],0\n"
615 		"	brc	1,0b\n"	/* handle partial completion */
616 		: [dst] "+&d" (d.pair), [src] "+&d" (s.pair),
617 		  [aad] "+&d" (a.pair)
618 		: [fc] "d" (func), [pba] "d" ((unsigned long)param),
619 		  [opc] "i" (CPACF_KMA)
620 		: "cc", "memory", "0", "1");
621 }
622 
623 #endif	/* _ASM_S390_CPACF_H */
624