xref: /openbmc/linux/arch/s390/include/uapi/asm/zcrypt.h (revision 3213486f)
1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2 /*
3  *  include/asm-s390/zcrypt.h
4  *
5  *  zcrypt 2.2.1 (user-visible header)
6  *
7  *  Copyright IBM Corp. 2001, 2018
8  *  Author(s): Robert Burroughs
9  *	       Eric Rossman (edrossma@us.ibm.com)
10  *
11  *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
12  */
13 
14 #ifndef __ASM_S390_ZCRYPT_H
15 #define __ASM_S390_ZCRYPT_H
16 
17 #define ZCRYPT_VERSION 2
18 #define ZCRYPT_RELEASE 2
19 #define ZCRYPT_VARIANT 1
20 
21 #include <linux/ioctl.h>
22 #include <linux/compiler.h>
23 
24 /* Name of the zcrypt device driver. */
25 #define ZCRYPT_NAME "zcrypt"
26 
27 /**
28  * struct ica_rsa_modexpo
29  *
30  * Requirements:
31  * - outputdatalength is at least as large as inputdatalength.
32  * - All key parts are right justified in their fields, padded on
33  *   the left with zeroes.
34  * - length(b_key) = inputdatalength
35  * - length(n_modulus) = inputdatalength
36  */
37 struct ica_rsa_modexpo {
38 	char __user  *inputdata;
39 	unsigned int  inputdatalength;
40 	char __user  *outputdata;
41 	unsigned int  outputdatalength;
42 	char __user  *b_key;
43 	char __user  *n_modulus;
44 };
45 
46 /**
47  * struct ica_rsa_modexpo_crt
48  *
49  * Requirements:
50  * - inputdatalength is even.
51  * - outputdatalength is at least as large as inputdatalength.
52  * - All key parts are right justified in their fields, padded on
53  *   the left with zeroes.
54  * - length(bp_key)	= inputdatalength/2 + 8
55  * - length(bq_key)	= inputdatalength/2
56  * - length(np_key)	= inputdatalength/2 + 8
57  * - length(nq_key)	= inputdatalength/2
58  * - length(u_mult_inv) = inputdatalength/2 + 8
59  */
60 struct ica_rsa_modexpo_crt {
61 	char __user  *inputdata;
62 	unsigned int  inputdatalength;
63 	char __user  *outputdata;
64 	unsigned int  outputdatalength;
65 	char __user  *bp_key;
66 	char __user  *bq_key;
67 	char __user  *np_prime;
68 	char __user  *nq_prime;
69 	char __user  *u_mult_inv;
70 };
71 
72 /**
73  * CPRBX
74  *	  Note that all shorts and ints are big-endian.
75  *	  All pointer fields are 16 bytes long, and mean nothing.
76  *
77  *	  A request CPRB is followed by a request_parameter_block.
78  *
79  *	  The request (or reply) parameter block is organized thus:
80  *	    function code
81  *	    VUD block
82  *	    key block
83  */
84 struct CPRBX {
85 	unsigned short	cprb_len;	/* CPRB length	      220	 */
86 	unsigned char	cprb_ver_id;	/* CPRB version id.   0x02	 */
87 	unsigned char	pad_000[3];	/* Alignment pad bytes		 */
88 	unsigned char	func_id[2];	/* function id	      0x5432	 */
89 	unsigned char	cprb_flags[4];	/* Flags			 */
90 	unsigned int	req_parml;	/* request parameter buffer len	 */
91 	unsigned int	req_datal;	/* request data buffer		 */
92 	unsigned int	rpl_msgbl;	/* reply  message block length	 */
93 	unsigned int	rpld_parml;	/* replied parameter block len	 */
94 	unsigned int	rpl_datal;	/* reply data block len		 */
95 	unsigned int	rpld_datal;	/* replied data block len	 */
96 	unsigned int	req_extbl;	/* request extension block len	 */
97 	unsigned char	pad_001[4];	/* reserved			 */
98 	unsigned int	rpld_extbl;	/* replied extension block len	 */
99 	unsigned char	padx000[16 - sizeof(char *)];
100 	unsigned char  *req_parmb;	/* request parm block 'address'	 */
101 	unsigned char	padx001[16 - sizeof(char *)];
102 	unsigned char  *req_datab;	/* request data block 'address'	 */
103 	unsigned char	padx002[16 - sizeof(char *)];
104 	unsigned char  *rpl_parmb;	/* reply parm block 'address'	 */
105 	unsigned char	padx003[16 - sizeof(char *)];
106 	unsigned char  *rpl_datab;	/* reply data block 'address'	 */
107 	unsigned char	padx004[16 - sizeof(char *)];
108 	unsigned char  *req_extb;	/* request extension block 'addr'*/
109 	unsigned char	padx005[16 - sizeof(char *)];
110 	unsigned char  *rpl_extb;	/* reply extension block 'address'*/
111 	unsigned short	ccp_rtcode;	/* server return code		 */
112 	unsigned short	ccp_rscode;	/* server reason code		 */
113 	unsigned int	mac_data_len;	/* Mac Data Length		 */
114 	unsigned char	logon_id[8];	/* Logon Identifier		 */
115 	unsigned char	mac_value[8];	/* Mac Value			 */
116 	unsigned char	mac_content_flgs;/* Mac content flag byte	 */
117 	unsigned char	pad_002;	/* Alignment			 */
118 	unsigned short	domain;		/* Domain			 */
119 	unsigned char	usage_domain[4];/* Usage domain			 */
120 	unsigned char	cntrl_domain[4];/* Control domain		 */
121 	unsigned char	S390enf_mask[4];/* S/390 enforcement mask	 */
122 	unsigned char	pad_004[36];	/* reserved			 */
123 } __attribute__((packed));
124 
125 /**
126  * xcRB
127  */
128 struct ica_xcRB {
129 	unsigned short	agent_ID;
130 	unsigned int	user_defined;
131 	unsigned short	request_ID;
132 	unsigned int	request_control_blk_length;
133 	unsigned char	padding1[16 - sizeof(char *)];
134 	char __user    *request_control_blk_addr;
135 	unsigned int	request_data_length;
136 	char		padding2[16 - sizeof(char *)];
137 	char __user    *request_data_address;
138 	unsigned int	reply_control_blk_length;
139 	char		padding3[16 - sizeof(char *)];
140 	char __user    *reply_control_blk_addr;
141 	unsigned int	reply_data_length;
142 	char		padding4[16 - sizeof(char *)];
143 	char __user    *reply_data_addr;
144 	unsigned short	priority_window;
145 	unsigned int	status;
146 } __attribute__((packed));
147 
148 /**
149  * struct ep11_cprb - EP11 connectivity programming request block
150  * @cprb_len:		CPRB header length [0x0020]
151  * @cprb_ver_id:	CPRB version id.   [0x04]
152  * @pad_000:		Alignment pad bytes
153  * @flags:		Admin bit [0x80], Special bit [0x20]
154  * @func_id:		Function id / subtype [0x5434] "T4"
155  * @source_id:		Source id [originator id]
156  * @target_id:		Target id [usage/ctrl domain id]
157  * @ret_code:		Return code
158  * @reserved1:		Reserved
159  * @reserved2:		Reserved
160  * @payload_len:	Payload length
161  */
162 struct ep11_cprb {
163 	uint16_t	cprb_len;
164 	unsigned char	cprb_ver_id;
165 	unsigned char	pad_000[2];
166 	unsigned char	flags;
167 	unsigned char	func_id[2];
168 	uint32_t	source_id;
169 	uint32_t	target_id;
170 	uint32_t	ret_code;
171 	uint32_t	reserved1;
172 	uint32_t	reserved2;
173 	uint32_t	payload_len;
174 } __attribute__((packed));
175 
176 /**
177  * struct ep11_target_dev - EP11 target device list
178  * @ap_id:	AP device id
179  * @dom_id:	Usage domain id
180  */
181 struct ep11_target_dev {
182 	uint16_t ap_id;
183 	uint16_t dom_id;
184 };
185 
186 /**
187  * struct ep11_urb - EP11 user request block
188  * @targets_num:	Number of target adapters
189  * @targets:		Addr to target adapter list
190  * @weight:		Level of request priority
191  * @req_no:		Request id/number
192  * @req_len:		Request length
193  * @req:		Addr to request block
194  * @resp_len:		Response length
195  * @resp:		Addr to response block
196  */
197 struct ep11_urb {
198 	uint16_t		targets_num;
199 	uint64_t		targets;
200 	uint64_t		weight;
201 	uint64_t		req_no;
202 	uint64_t		req_len;
203 	uint64_t		req;
204 	uint64_t		resp_len;
205 	uint64_t		resp;
206 } __attribute__((packed));
207 
208 /**
209  * struct zcrypt_device_status_ext
210  * @hwtype:		raw hardware type
211  * @qid:		8 bit device index, 8 bit domain
212  * @functions:		AP device function bit field 'abcdef'
213  *			a, b, c = reserved
214  *			d = CCA coprocessor
215  *			e = Accelerator
216  *			f = EP11 coprocessor
217  * @online		online status
218  * @reserved		reserved
219  */
220 struct zcrypt_device_status_ext {
221 	unsigned int hwtype:8;
222 	unsigned int qid:16;
223 	unsigned int online:1;
224 	unsigned int functions:6;
225 	unsigned int reserved:1;
226 };
227 
228 #define MAX_ZDEV_CARDIDS_EXT 256
229 #define MAX_ZDEV_DOMAINS_EXT 256
230 
231 /* Maximum number of zcrypt devices */
232 #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
233 
234 /* Device matrix of all zcrypt devices */
235 struct zcrypt_device_matrix_ext {
236 	struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
237 };
238 
239 #define AUTOSELECT 0xFFFFFFFF
240 
241 #define ZCRYPT_IOCTL_MAGIC 'z'
242 
243 /**
244  * Interface notes:
245  *
246  * The ioctl()s which are implemented (along with relevant details)
247  * are:
248  *
249  *   ICARSAMODEXPO
250  *     Perform an RSA operation using a Modulus-Exponent pair
251  *     This takes an ica_rsa_modexpo struct as its arg.
252  *
253  *     NOTE: please refer to the comments preceding this structure
254  *	     for the implementation details for the contents of the
255  *	     block
256  *
257  *   ICARSACRT
258  *     Perform an RSA operation using a Chinese-Remainder Theorem key
259  *     This takes an ica_rsa_modexpo_crt struct as its arg.
260  *
261  *     NOTE: please refer to the comments preceding this structure
262  *	     for the implementation details for the contents of the
263  *	     block
264  *
265  *   ZSECSENDCPRB
266  *     Send an arbitrary CPRB to a crypto card.
267  *
268  *   ZSENDEP11CPRB
269  *     Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
270  *
271  *   ZCRYPT_DEVICE_STATUS
272  *     The given struct zcrypt_device_matrix_ext is updated with
273  *     status information for each currently known apqn.
274  *
275  *   ZCRYPT_STATUS_MASK
276  *     Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
277  *     status of all devices.
278  *	 0x01: PCICA
279  *	 0x02: PCICC
280  *	 0x03: PCIXCC_MCL2
281  *	 0x04: PCIXCC_MCL3
282  *	 0x05: CEX2C
283  *	 0x06: CEX2A
284  *	 0x07: CEX3C
285  *	 0x08: CEX3A
286  *	 0x0a: CEX4
287  *	 0x0b: CEX5
288  *	 0x0c: CEX6
289  *	 0x0d: device is disabled
290  *
291  *   ZCRYPT_QDEPTH_MASK
292  *     Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
293  *     queue depth of all devices.
294  *
295  *   ZCRYPT_PERDEV_REQCNT
296  *     Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for
297  *     the number of successfully completed requests per device since the
298  *     device was detected and made available.
299  *
300  */
301 
302 /**
303  * Supported ioctl calls
304  */
305 #define ICARSAMODEXPO	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
306 #define ICARSACRT	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
307 #define ZSECSENDCPRB	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
308 #define ZSENDEP11CPRB	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
309 
310 #define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0)
311 #define ZCRYPT_STATUS_MASK   _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT])
312 #define ZCRYPT_QDEPTH_MASK   _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT])
313 #define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT])
314 
315 /*
316  * Support for multiple zcrypt device nodes.
317  */
318 
319 /* Nr of minor device node numbers to allocate. */
320 #define ZCRYPT_MAX_MINOR_NODES 256
321 
322 /* Max amount of possible ioctls */
323 #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS)
324 
325 /*
326  * Only deprecated defines, structs and ioctls below this line.
327  */
328 
329 /* Deprecated: use MAX_ZDEV_CARDIDS_EXT */
330 #define MAX_ZDEV_CARDIDS 64
331 /* Deprecated: use MAX_ZDEV_DOMAINS_EXT */
332 #define MAX_ZDEV_DOMAINS 256
333 
334 /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
335 #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
336 
337 /* Deprecated: use struct zcrypt_device_status_ext */
338 struct zcrypt_device_status {
339 	unsigned int hwtype:8;
340 	unsigned int qid:14;
341 	unsigned int online:1;
342 	unsigned int functions:6;
343 	unsigned int reserved:3;
344 };
345 
346 /* Deprecated: use struct zcrypt_device_matrix_ext */
347 struct zcrypt_device_matrix {
348 	struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
349 };
350 
351 /* Deprecated: use ZCRYPT_DEVICE_STATUS */
352 #define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
353 /* Deprecated: use ZCRYPT_STATUS_MASK */
354 #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
355 /* Deprecated: use ZCRYPT_QDEPTH_MASK */
356 #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
357 /* Deprecated: use ZCRYPT_PERDEV_REQCNT */
358 #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
359 
360 /* Deprecated: use sysfs to query these values */
361 #define Z90STAT_REQUESTQ_COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
362 #define Z90STAT_PENDINGQ_COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
363 #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
364 #define Z90STAT_DOMAIN_INDEX	_IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
365 
366 /*
367  * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
368  * past, don't assign new ioctls for these.
369  */
370 
371 #endif /* __ASM_S390_ZCRYPT_H */
372