1 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
3 * include/asm-s390/zcrypt.h
5 * zcrypt 2.1.0 (user-visible header)
7 * Copyright IBM Corp. 2001, 2006
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 1
19 #define ZCRYPT_VARIANT 1
21 #include <linux/ioctl.h>
22 #include <linux/compiler.h>
25 * struct ica_rsa_modexpo
28 * - outputdatalength is at least as large as inputdatalength.
29 * - All key parts are right justified in their fields, padded on
30 * the left with zeroes.
31 * - length(b_key) = inputdatalength
32 * - length(n_modulus) = inputdatalength
34 struct ica_rsa_modexpo {
35 char __user *inputdata;
36 unsigned int inputdatalength;
37 char __user *outputdata;
38 unsigned int outputdatalength;
40 char __user *n_modulus;
44 * struct ica_rsa_modexpo_crt
47 * - inputdatalength is even.
48 * - outputdatalength is at least as large as inputdatalength.
49 * - All key parts are right justified in their fields, padded on
50 * the left with zeroes.
51 * - length(bp_key) = inputdatalength/2 + 8
52 * - length(bq_key) = inputdatalength/2
53 * - length(np_key) = inputdatalength/2 + 8
54 * - length(nq_key) = inputdatalength/2
55 * - length(u_mult_inv) = inputdatalength/2 + 8
57 struct ica_rsa_modexpo_crt {
58 char __user *inputdata;
59 unsigned int inputdatalength;
60 char __user *outputdata;
61 unsigned int outputdatalength;
64 char __user *np_prime;
65 char __user *nq_prime;
66 char __user *u_mult_inv;
71 * Note that all shorts and ints are big-endian.
72 * All pointer fields are 16 bytes long, and mean nothing.
74 * A request CPRB is followed by a request_parameter_block.
76 * The request (or reply) parameter block is organized thus:
82 unsigned short cprb_len; /* CPRB length 220 */
83 unsigned char cprb_ver_id; /* CPRB version id. 0x02 */
84 unsigned char pad_000[3]; /* Alignment pad bytes */
85 unsigned char func_id[2]; /* function id 0x5432 */
86 unsigned char cprb_flags[4]; /* Flags */
87 unsigned int req_parml; /* request parameter buffer len */
88 unsigned int req_datal; /* request data buffer */
89 unsigned int rpl_msgbl; /* reply message block length */
90 unsigned int rpld_parml; /* replied parameter block len */
91 unsigned int rpl_datal; /* reply data block len */
92 unsigned int rpld_datal; /* replied data block len */
93 unsigned int req_extbl; /* request extension block len */
94 unsigned char pad_001[4]; /* reserved */
95 unsigned int rpld_extbl; /* replied extension block len */
96 unsigned char padx000[16 - sizeof(char *)];
97 unsigned char *req_parmb; /* request parm block 'address' */
98 unsigned char padx001[16 - sizeof(char *)];
99 unsigned char *req_datab; /* request data block 'address' */
100 unsigned char padx002[16 - sizeof(char *)];
101 unsigned char *rpl_parmb; /* reply parm block 'address' */
102 unsigned char padx003[16 - sizeof(char *)];
103 unsigned char *rpl_datab; /* reply data block 'address' */
104 unsigned char padx004[16 - sizeof(char *)];
105 unsigned char *req_extb; /* request extension block 'addr'*/
106 unsigned char padx005[16 - sizeof(char *)];
107 unsigned char *rpl_extb; /* reply extension block 'address'*/
108 unsigned short ccp_rtcode; /* server return code */
109 unsigned short ccp_rscode; /* server reason code */
110 unsigned int mac_data_len; /* Mac Data Length */
111 unsigned char logon_id[8]; /* Logon Identifier */
112 unsigned char mac_value[8]; /* Mac Value */
113 unsigned char mac_content_flgs;/* Mac content flag byte */
114 unsigned char pad_002; /* Alignment */
115 unsigned short domain; /* Domain */
116 unsigned char usage_domain[4];/* Usage domain */
117 unsigned char cntrl_domain[4];/* Control domain */
118 unsigned char S390enf_mask[4];/* S/390 enforcement mask */
119 unsigned char pad_004[36]; /* reserved */
120 } __attribute__((packed));
126 unsigned short agent_ID;
127 unsigned int user_defined;
128 unsigned short request_ID;
129 unsigned int request_control_blk_length;
130 unsigned char padding1[16 - sizeof(char *)];
131 char __user *request_control_blk_addr;
132 unsigned int request_data_length;
133 char padding2[16 - sizeof(char *)];
134 char __user *request_data_address;
135 unsigned int reply_control_blk_length;
136 char padding3[16 - sizeof(char *)];
137 char __user *reply_control_blk_addr;
138 unsigned int reply_data_length;
139 char padding4[16 - sizeof(char *)];
140 char __user *reply_data_addr;
141 unsigned short priority_window;
143 } __attribute__((packed));
146 * struct ep11_cprb - EP11 connectivity programming request block
147 * @cprb_len: CPRB header length [0x0020]
148 * @cprb_ver_id: CPRB version id. [0x04]
149 * @pad_000: Alignment pad bytes
150 * @flags: Admin bit [0x80], Special bit [0x20]
151 * @func_id: Function id / subtype [0x5434] "T4"
152 * @source_id: Source id [originator id]
153 * @target_id: Target id [usage/ctrl domain id]
154 * @ret_code: Return code
155 * @reserved1: Reserved
156 * @reserved2: Reserved
157 * @payload_len: Payload length
161 unsigned char cprb_ver_id;
162 unsigned char pad_000[2];
164 unsigned char func_id[2];
170 uint32_t payload_len;
171 } __attribute__((packed));
174 * struct ep11_target_dev - EP11 target device list
175 * @ap_id: AP device id
176 * @dom_id: Usage domain id
178 struct ep11_target_dev {
184 * struct ep11_urb - EP11 user request block
185 * @targets_num: Number of target adapters
186 * @targets: Addr to target adapter list
187 * @weight: Level of request priority
188 * @req_no: Request id/number
189 * @req_len: Request length
190 * @req: Addr to request block
191 * @resp_len: Response length
192 * @resp: Addr to response block
195 uint16_t targets_num;
203 } __attribute__((packed));
206 * struct zcrypt_device_status_ext
207 * @hwtype: raw hardware type
208 * @qid: 8 bit device index, 8 bit domain
209 * @functions: AP device function bit field 'abcdef'
211 * d = CCA coprocessor
213 * f = EP11 coprocessor
214 * @online online status
217 struct zcrypt_device_status_ext {
218 unsigned int hwtype:8;
220 unsigned int online:1;
221 unsigned int functions:6;
222 unsigned int reserved:1;
225 #define MAX_ZDEV_CARDIDS_EXT 256
226 #define MAX_ZDEV_DOMAINS_EXT 256
228 /* Maximum number of zcrypt devices */
229 #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
231 /* Device matrix of all zcrypt devices */
232 struct zcrypt_device_matrix_ext {
233 struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
236 #define AUTOSELECT 0xFFFFFFFF
238 #define ZCRYPT_IOCTL_MAGIC 'z'
243 * The ioctl()s which are implemented (along with relevant details)
247 * Perform an RSA operation using a Modulus-Exponent pair
248 * This takes an ica_rsa_modexpo struct as its arg.
250 * NOTE: please refer to the comments preceding this structure
251 * for the implementation details for the contents of the
255 * Perform an RSA operation using a Chinese-Remainder Theorem key
256 * This takes an ica_rsa_modexpo_crt struct as its arg.
258 * NOTE: please refer to the comments preceding this structure
259 * for the implementation details for the contents of the
263 * Send an arbitrary CPRB to a crypto card.
266 * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
268 * ZCRYPT_DEVICE_STATUS
269 * The given struct zcrypt_device_matrix_ext is updated with
270 * status information for each currently known apqn.
273 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
274 * status of all devices.
286 * 0x0d: device is disabled
289 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
290 * queue depth of all devices.
292 * ZCRYPT_PERDEV_REQCNT
293 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for
294 * the number of successfully completed requests per device since the
295 * device was detected and made available.
300 * Supported ioctl calls
302 #define ICARSAMODEXPO _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
303 #define ICARSACRT _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
304 #define ZSECSENDCPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
305 #define ZSENDEP11CPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
307 #define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0)
308 #define ZCRYPT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT])
309 #define ZCRYPT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT])
310 #define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT])
313 * Only deprecated defines, structs and ioctls below this line.
316 /* Deprecated: use MAX_ZDEV_CARDIDS_EXT */
317 #define MAX_ZDEV_CARDIDS 64
318 /* Deprecated: use MAX_ZDEV_DOMAINS_EXT */
319 #define MAX_ZDEV_DOMAINS 256
321 /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
322 #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
324 /* Deprecated: use struct zcrypt_device_status_ext */
325 struct zcrypt_device_status {
326 unsigned int hwtype:8;
328 unsigned int online:1;
329 unsigned int functions:6;
330 unsigned int reserved:3;
333 /* Deprecated: use struct zcrypt_device_matrix_ext */
334 struct zcrypt_device_matrix {
335 struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
338 /* Deprecated: use ZCRYPT_DEVICE_STATUS */
339 #define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
340 /* Deprecated: use ZCRYPT_STATUS_MASK */
341 #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
342 /* Deprecated: use ZCRYPT_QDEPTH_MASK */
343 #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
344 /* Deprecated: use ZCRYPT_PERDEV_REQCNT */
345 #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
347 /* Deprecated: use sysfs to query these values */
348 #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
349 #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
350 #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
351 #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
354 * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
355 * past, don't assign new ioctls for these.
358 #endif /* __ASM_S390_ZCRYPT_H */