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, 2019
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>
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 char __user *inputdata;
40 unsigned int inputdatalength;
41 char __user *outputdata;
42 unsigned int outputdatalength;
44 char __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 char __user *inputdata;
63 unsigned int inputdatalength;
64 char __user *outputdata;
65 unsigned int outputdatalength;
68 char __user *np_prime;
69 char __user *nq_prime;
70 char __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 unsigned short cprb_len; /* CPRB length 220 */
87 unsigned char cprb_ver_id; /* CPRB version id. 0x02 */
88 unsigned char pad_000[3]; /* Alignment pad bytes */
89 unsigned char func_id[2]; /* function id 0x5432 */
90 unsigned char cprb_flags[4]; /* Flags */
91 unsigned int req_parml; /* request parameter buffer len */
92 unsigned int req_datal; /* request data buffer */
93 unsigned int rpl_msgbl; /* reply message block length */
94 unsigned int rpld_parml; /* replied parameter block len */
95 unsigned int rpl_datal; /* reply data block len */
96 unsigned int rpld_datal; /* replied data block len */
97 unsigned int req_extbl; /* request extension block len */
98 unsigned char pad_001[4]; /* reserved */
99 unsigned int rpld_extbl; /* replied extension block len */
100 unsigned char padx000[16 - sizeof(char *)];
101 unsigned char *req_parmb; /* request parm block 'address' */
102 unsigned char padx001[16 - sizeof(char *)];
103 unsigned char *req_datab; /* request data block 'address' */
104 unsigned char padx002[16 - sizeof(char *)];
105 unsigned char *rpl_parmb; /* reply parm block 'address' */
106 unsigned char padx003[16 - sizeof(char *)];
107 unsigned char *rpl_datab; /* reply data block 'address' */
108 unsigned char padx004[16 - sizeof(char *)];
109 unsigned char *req_extb; /* request extension block 'addr'*/
110 unsigned char padx005[16 - sizeof(char *)];
111 unsigned char *rpl_extb; /* reply extension block 'address'*/
112 unsigned short ccp_rtcode; /* server return code */
113 unsigned short ccp_rscode; /* server reason code */
114 unsigned int mac_data_len; /* Mac Data Length */
115 unsigned char logon_id[8]; /* Logon Identifier */
116 unsigned char mac_value[8]; /* Mac Value */
117 unsigned char mac_content_flgs;/* Mac content flag byte */
118 unsigned char pad_002; /* Alignment */
119 unsigned short domain; /* Domain */
120 unsigned char usage_domain[4];/* Usage domain */
121 unsigned char cntrl_domain[4];/* Control domain */
122 unsigned char S390enf_mask[4];/* S/390 enforcement mask */
123 unsigned char pad_004[36]; /* reserved */
124 } __attribute__((packed));
130 unsigned short agent_ID;
131 unsigned int user_defined;
132 unsigned short request_ID;
133 unsigned int request_control_blk_length;
134 unsigned char padding1[16 - sizeof(char *)];
135 char __user *request_control_blk_addr;
136 unsigned int request_data_length;
137 char padding2[16 - sizeof(char *)];
138 char __user *request_data_address;
139 unsigned int reply_control_blk_length;
140 char padding3[16 - sizeof(char *)];
141 char __user *reply_control_blk_addr;
142 unsigned int reply_data_length;
143 char padding4[16 - sizeof(char *)];
144 char __user *reply_data_addr;
145 unsigned short priority_window;
147 } __attribute__((packed));
150 * struct ep11_cprb - EP11 connectivity programming request block
151 * @cprb_len: CPRB header length [0x0020]
152 * @cprb_ver_id: CPRB version id. [0x04]
153 * @pad_000: Alignment pad bytes
154 * @flags: Admin bit [0x80], Special bit [0x20]
155 * @func_id: Function id / subtype [0x5434] "T4"
156 * @source_id: Source id [originator id]
157 * @target_id: Target id [usage/ctrl domain id]
158 * @ret_code: Return code
159 * @reserved1: Reserved
160 * @reserved2: Reserved
161 * @payload_len: Payload length
165 unsigned char cprb_ver_id;
166 unsigned char pad_000[2];
168 unsigned char func_id[2];
175 } __attribute__((packed));
178 * struct ep11_target_dev - EP11 target device list
179 * @ap_id: AP device id
180 * @dom_id: Usage domain id
182 struct ep11_target_dev {
188 * struct ep11_urb - EP11 user request block
189 * @targets_num: Number of target adapters
190 * @targets: Addr to target adapter list
191 * @weight: Level of request priority
192 * @req_no: Request id/number
193 * @req_len: Request length
194 * @req: Addr to request block
195 * @resp_len: Response length
196 * @resp: Addr to response block
207 } __attribute__((packed));
210 * struct zcrypt_device_status_ext
211 * @hwtype: raw hardware type
212 * @qid: 8 bit device index, 8 bit domain
213 * @functions: AP device function bit field 'abcdef'
215 * d = CCA coprocessor
217 * f = EP11 coprocessor
218 * @online online status
221 struct zcrypt_device_status_ext {
222 unsigned int hwtype:8;
224 unsigned int online:1;
225 unsigned int functions:6;
226 unsigned int reserved:1;
229 #define MAX_ZDEV_CARDIDS_EXT 256
230 #define MAX_ZDEV_DOMAINS_EXT 256
232 /* Maximum number of zcrypt devices */
233 #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
235 /* Device matrix of all zcrypt devices */
236 struct zcrypt_device_matrix_ext {
237 struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
240 #define AUTOSELECT 0xFFFFFFFF
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 and CEX7
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 */