1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
3 * include/asm-s390/zcrypt.h
5 * zcrypt 2.2.1 (user-visible header)
7 * Copyright IBM Corp. 2001, 2018
8 * Author(s): Robert Burroughs
9 * Eric Rossman (edrossma@us.ibm.com)
11 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
14 #ifndef __ASM_S390_ZCRYPT_H
15 #define __ASM_S390_ZCRYPT_H
17 #define ZCRYPT_VERSION 2
18 #define ZCRYPT_RELEASE 2
19 #define ZCRYPT_VARIANT 1
21 #include <linux/ioctl.h>
22 #include <linux/compiler.h>
24 /* Name of the zcrypt device driver. */
25 #define ZCRYPT_NAME "zcrypt"
28 * struct ica_rsa_modexpo
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
37 struct ica_rsa_modexpo {
38 char __user *inputdata;
39 unsigned int inputdatalength;
40 char __user *outputdata;
41 unsigned int outputdatalength;
43 char __user *n_modulus;
47 * struct ica_rsa_modexpo_crt
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
60 struct ica_rsa_modexpo_crt {
61 char __user *inputdata;
62 unsigned int inputdatalength;
63 char __user *outputdata;
64 unsigned int outputdatalength;
67 char __user *np_prime;
68 char __user *nq_prime;
69 char __user *u_mult_inv;
74 * Note that all shorts and ints are big-endian.
75 * All pointer fields are 16 bytes long, and mean nothing.
77 * A request CPRB is followed by a request_parameter_block.
79 * The request (or reply) parameter block is organized thus:
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));
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;
146 } __attribute__((packed));
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
164 unsigned char cprb_ver_id;
165 unsigned char pad_000[2];
167 unsigned char func_id[2];
173 uint32_t payload_len;
174 } __attribute__((packed));
177 * struct ep11_target_dev - EP11 target device list
178 * @ap_id: AP device id
179 * @dom_id: Usage domain id
181 struct ep11_target_dev {
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
198 uint16_t targets_num;
206 } __attribute__((packed));
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'
214 * d = CCA coprocessor
216 * f = EP11 coprocessor
217 * @online online status
220 struct zcrypt_device_status_ext {
221 unsigned int hwtype:8;
223 unsigned int online:1;
224 unsigned int functions:6;
225 unsigned int reserved:1;
228 #define MAX_ZDEV_CARDIDS_EXT 256
229 #define MAX_ZDEV_DOMAINS_EXT 256
231 /* Maximum number of zcrypt devices */
232 #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
234 /* Device matrix of all zcrypt devices */
235 struct zcrypt_device_matrix_ext {
236 struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
239 #define AUTOSELECT 0xFFFFFFFF
241 #define ZCRYPT_IOCTL_MAGIC 'z'
246 * The ioctl()s which are implemented (along with relevant details)
250 * Perform an RSA operation using a Modulus-Exponent pair
251 * This takes an ica_rsa_modexpo struct as its arg.
253 * NOTE: please refer to the comments preceding this structure
254 * for the implementation details for the contents of the
258 * Perform an RSA operation using a Chinese-Remainder Theorem key
259 * This takes an ica_rsa_modexpo_crt struct as its arg.
261 * NOTE: please refer to the comments preceding this structure
262 * for the implementation details for the contents of the
266 * Send an arbitrary CPRB to a crypto card.
269 * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
271 * ZCRYPT_DEVICE_STATUS
272 * The given struct zcrypt_device_matrix_ext is updated with
273 * status information for each currently known apqn.
276 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
277 * status of all devices.
289 * 0x0d: device is disabled
292 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
293 * queue depth of all devices.
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.
303 * Supported ioctl calls
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)
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])
316 * Support for multiple zcrypt device nodes.
319 /* Nr of minor device node numbers to allocate. */
320 #define ZCRYPT_MAX_MINOR_NODES 256
322 /* Max amount of possible ioctls */
323 #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS)
326 * Only deprecated defines, structs and ioctls below this line.
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
334 /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
335 #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
337 /* Deprecated: use struct zcrypt_device_status_ext */
338 struct zcrypt_device_status {
339 unsigned int hwtype:8;
341 unsigned int online:1;
342 unsigned int functions:6;
343 unsigned int reserved:3;
346 /* Deprecated: use struct zcrypt_device_matrix_ext */
347 struct zcrypt_device_matrix {
348 struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
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])
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)
367 * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
368 * past, don't assign new ioctls for these.
371 #endif /* __ASM_S390_ZCRYPT_H */