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, 2022
8 * Author(s): Robert Burroughs
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>
23 #include <linux/types.h>
25 /* Name of the zcrypt device driver. */
26 #define ZCRYPT_NAME "zcrypt"
29 * struct ica_rsa_modexpo
32 * - outputdatalength is at least as large as inputdatalength.
33 * - All key parts are right justified in their fields, padded on
34 * the left with zeroes.
35 * - length(b_key) = inputdatalength
36 * - length(n_modulus) = inputdatalength
38 struct ica_rsa_modexpo {
39 __u8 __user *inputdata;
40 __u32 inputdatalength;
41 __u8 __user *outputdata;
42 __u32 outputdatalength;
44 __u8 __user *n_modulus;
48 * struct ica_rsa_modexpo_crt
51 * - inputdatalength is even.
52 * - outputdatalength is at least as large as inputdatalength.
53 * - All key parts are right justified in their fields, padded on
54 * the left with zeroes.
55 * - length(bp_key) = inputdatalength/2 + 8
56 * - length(bq_key) = inputdatalength/2
57 * - length(np_key) = inputdatalength/2 + 8
58 * - length(nq_key) = inputdatalength/2
59 * - length(u_mult_inv) = inputdatalength/2 + 8
61 struct ica_rsa_modexpo_crt {
62 __u8 __user *inputdata;
63 __u32 inputdatalength;
64 __u8 __user *outputdata;
65 __u32 outputdatalength;
68 __u8 __user *np_prime;
69 __u8 __user *nq_prime;
70 __u8 __user *u_mult_inv;
75 * Note that all shorts and ints are big-endian.
76 * All pointer fields are 16 bytes long, and mean nothing.
78 * A request CPRB is followed by a request_parameter_block.
80 * The request (or reply) parameter block is organized thus:
86 __u16 cprb_len; /* CPRB length 220 */
87 __u8 cprb_ver_id; /* CPRB version id. 0x02 */
88 __u8 _pad_000[3]; /* Alignment pad bytes */
89 __u8 func_id[2]; /* function id 0x5432 */
90 __u8 cprb_flags[4]; /* Flags */
91 __u32 req_parml; /* request parameter buffer len */
92 __u32 req_datal; /* request data buffer */
93 __u32 rpl_msgbl; /* reply message block length */
94 __u32 rpld_parml; /* replied parameter block len */
95 __u32 rpl_datal; /* reply data block len */
96 __u32 rpld_datal; /* replied data block len */
97 __u32 req_extbl; /* request extension block len */
98 __u8 _pad_001[4]; /* reserved */
99 __u32 rpld_extbl; /* replied extension block len */
100 __u8 _pad_002[16 - sizeof(__u8 *)];
101 __u8 __user *req_parmb; /* request parm block 'address' */
102 __u8 _pad_003[16 - sizeof(__u8 *)];
103 __u8 __user *req_datab; /* request data block 'address' */
104 __u8 _pad_004[16 - sizeof(__u8 *)];
105 __u8 __user *rpl_parmb; /* reply parm block 'address' */
106 __u8 _pad_005[16 - sizeof(__u8 *)];
107 __u8 __user *rpl_datab; /* reply data block 'address' */
108 __u8 _pad_006[16 - sizeof(__u8 *)];
109 __u8 __user *req_extb; /* request extension block 'addr'*/
110 __u8 _pad_007[16 - sizeof(__u8 *)];
111 __u8 __user *rpl_extb; /* reply extension block 'address'*/
112 __u16 ccp_rtcode; /* server return code */
113 __u16 ccp_rscode; /* server reason code */
114 __u32 mac_data_len; /* Mac Data Length */
115 __u8 logon_id[8]; /* Logon Identifier */
116 __u8 mac_value[8]; /* Mac Value */
117 __u8 mac_content_flgs; /* Mac content flag byte */
118 __u8 _pad_008; /* Alignment */
119 __u16 domain; /* Domain */
120 __u8 _pad_009[12]; /* reserved, checked for zeros */
121 __u8 _pad_010[36]; /* reserved */
122 } __attribute__((packed));
131 __u32 request_control_blk_length;
132 __u8 _padding1[16 - sizeof(__u8 *)];
133 __u8 __user *request_control_blk_addr;
134 __u32 request_data_length;
135 __u8 _padding2[16 - sizeof(__u8 *)];
136 __u8 __user *request_data_address;
137 __u32 reply_control_blk_length;
138 __u8 _padding3[16 - sizeof(__u8 *)];
139 __u8 __user *reply_control_blk_addr;
140 __u32 reply_data_length;
141 __u8 __padding4[16 - sizeof(__u8 *)];
142 __u8 __user *reply_data_addr;
143 __u16 priority_window;
145 } __attribute__((packed));
148 * struct ep11_cprb - EP11 connectivity programming request block
149 * @cprb_len: CPRB header length [0x0020]
150 * @cprb_ver_id: CPRB version id. [0x04]
151 * @pad_000: Alignment pad bytes
152 * @flags: Admin bit [0x80], Special bit [0x20]
153 * @func_id: Function id / subtype [0x5434] "T4"
154 * @source_id: Source id [originator id]
155 * @target_id: Target id [usage/ctrl domain id]
156 * @ret_code: Return code
157 * @reserved1: Reserved
158 * @reserved2: Reserved
159 * @payload_len: Payload length
173 } __attribute__((packed));
176 * struct ep11_target_dev - EP11 target device list
177 * @ap_id: AP device id
178 * @dom_id: Usage domain id
180 struct ep11_target_dev {
186 * struct ep11_urb - EP11 user request block
187 * @targets_num: Number of target adapters
188 * @targets: Addr to target adapter list
189 * @weight: Level of request priority
190 * @req_no: Request id/number
191 * @req_len: Request length
192 * @req: Addr to request block
193 * @resp_len: Response length
194 * @resp: Addr to response block
198 __u8 __user *targets;
205 } __attribute__((packed));
208 * struct zcrypt_device_status_ext
209 * @hwtype: raw hardware type
210 * @qid: 8 bit device index, 8 bit domain
211 * @functions: AP device function bit field 'abcdef'
213 * d = CCA coprocessor
215 * f = EP11 coprocessor
216 * @online online status
219 struct zcrypt_device_status_ext {
220 unsigned int hwtype:8;
222 unsigned int online:1;
223 unsigned int functions:6;
224 unsigned int reserved:1;
227 #define MAX_ZDEV_CARDIDS_EXT 256
228 #define MAX_ZDEV_DOMAINS_EXT 256
230 /* Maximum number of zcrypt devices */
231 #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
233 /* Device matrix of all zcrypt devices */
234 struct zcrypt_device_matrix_ext {
235 struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
238 #define AUTOSELECT 0xFFFFFFFF
239 #define AUTOSEL_AP ((__u16)0xFFFF)
240 #define AUTOSEL_DOM ((__u16)0xFFFF)
242 #define ZCRYPT_IOCTL_MAGIC 'z'
247 * The ioctl()s which are implemented (along with relevant details)
251 * Perform an RSA operation using a Modulus-Exponent pair
252 * This takes an ica_rsa_modexpo struct as its arg.
254 * NOTE: please refer to the comments preceding this structure
255 * for the implementation details for the contents of the
259 * Perform an RSA operation using a Chinese-Remainder Theorem key
260 * This takes an ica_rsa_modexpo_crt struct as its arg.
262 * NOTE: please refer to the comments preceding this structure
263 * for the implementation details for the contents of the
267 * Send an arbitrary CPRB to a crypto card.
270 * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
272 * ZCRYPT_DEVICE_STATUS
273 * The given struct zcrypt_device_matrix_ext is updated with
274 * status information for each currently known apqn.
277 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
278 * status of all devices.
289 * 0x0c: CEX6, CEX7 or CEX8
290 * 0x0d: device is disabled
293 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
294 * queue depth of all devices.
296 * ZCRYPT_PERDEV_REQCNT
297 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for
298 * the number of successfully completed requests per device since the
299 * device was detected and made available.
304 * Supported ioctl calls
306 #define ICARSAMODEXPO _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
307 #define ICARSACRT _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
308 #define ZSECSENDCPRB _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
309 #define ZSENDEP11CPRB _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
311 #define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0)
312 #define ZCRYPT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT])
313 #define ZCRYPT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT])
314 #define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT])
317 * Support for multiple zcrypt device nodes.
320 /* Nr of minor device node numbers to allocate. */
321 #define ZCRYPT_MAX_MINOR_NODES 256
323 /* Max amount of possible ioctls */
324 #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS)
327 * Only deprecated defines, structs and ioctls below this line.
330 /* Deprecated: use MAX_ZDEV_CARDIDS_EXT */
331 #define MAX_ZDEV_CARDIDS 64
332 /* Deprecated: use MAX_ZDEV_DOMAINS_EXT */
333 #define MAX_ZDEV_DOMAINS 256
335 /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
336 #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
338 /* Deprecated: use struct zcrypt_device_status_ext */
339 struct zcrypt_device_status {
340 unsigned int hwtype:8;
342 unsigned int online:1;
343 unsigned int functions:6;
344 unsigned int reserved:3;
347 /* Deprecated: use struct zcrypt_device_matrix_ext */
348 struct zcrypt_device_matrix {
349 struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
352 /* Deprecated: use ZCRYPT_DEVICE_STATUS */
353 #define ZDEVICESTATUS _IOC(_IOC_READ | _IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
354 /* Deprecated: use ZCRYPT_STATUS_MASK */
355 #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
356 /* Deprecated: use ZCRYPT_QDEPTH_MASK */
357 #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
358 /* Deprecated: use ZCRYPT_PERDEV_REQCNT */
359 #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
361 /* Deprecated: use sysfs to query these values */
362 #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
363 #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
364 #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
365 #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
368 * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
369 * past, don't assign new ioctls for these.
372 #endif /* __ASM_S390_ZCRYPT_H */