b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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, 2019 |
| 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 | #include <linux/types.h> |
| 24 | |
| 25 | /* Name of the zcrypt device driver. */ |
| 26 | #define ZCRYPT_NAME "zcrypt" |
| 27 | |
| 28 | /** |
| 29 | * struct ica_rsa_modexpo |
| 30 | * |
| 31 | * Requirements: |
| 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 |
| 37 | */ |
| 38 | struct ica_rsa_modexpo { |
| 39 | char __user *inputdata; |
| 40 | unsigned int inputdatalength; |
| 41 | char __user *outputdata; |
| 42 | unsigned int outputdatalength; |
| 43 | char __user *b_key; |
| 44 | char __user *n_modulus; |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * struct ica_rsa_modexpo_crt |
| 49 | * |
| 50 | * Requirements: |
| 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 |
| 60 | */ |
| 61 | struct ica_rsa_modexpo_crt { |
| 62 | char __user *inputdata; |
| 63 | unsigned int inputdatalength; |
| 64 | char __user *outputdata; |
| 65 | unsigned int outputdatalength; |
| 66 | char __user *bp_key; |
| 67 | char __user *bq_key; |
| 68 | char __user *np_prime; |
| 69 | char __user *nq_prime; |
| 70 | char __user *u_mult_inv; |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * CPRBX |
| 75 | * Note that all shorts and ints are big-endian. |
| 76 | * All pointer fields are 16 bytes long, and mean nothing. |
| 77 | * |
| 78 | * A request CPRB is followed by a request_parameter_block. |
| 79 | * |
| 80 | * The request (or reply) parameter block is organized thus: |
| 81 | * function code |
| 82 | * VUD block |
| 83 | * key block |
| 84 | */ |
| 85 | struct CPRBX { |
| 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)); |
| 125 | |
| 126 | /** |
| 127 | * xcRB |
| 128 | */ |
| 129 | struct ica_xcRB { |
| 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; |
| 146 | unsigned int status; |
| 147 | } __attribute__((packed)); |
| 148 | |
| 149 | /** |
| 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 |
| 162 | */ |
| 163 | struct ep11_cprb { |
| 164 | __u16 cprb_len; |
| 165 | unsigned char cprb_ver_id; |
| 166 | unsigned char pad_000[2]; |
| 167 | unsigned char flags; |
| 168 | unsigned char func_id[2]; |
| 169 | __u32 source_id; |
| 170 | __u32 target_id; |
| 171 | __u32 ret_code; |
| 172 | __u32 reserved1; |
| 173 | __u32 reserved2; |
| 174 | __u32 payload_len; |
| 175 | } __attribute__((packed)); |
| 176 | |
| 177 | /** |
| 178 | * struct ep11_target_dev - EP11 target device list |
| 179 | * @ap_id: AP device id |
| 180 | * @dom_id: Usage domain id |
| 181 | */ |
| 182 | struct ep11_target_dev { |
| 183 | __u16 ap_id; |
| 184 | __u16 dom_id; |
| 185 | }; |
| 186 | |
| 187 | /** |
| 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 |
| 197 | */ |
| 198 | struct ep11_urb { |
| 199 | __u16 targets_num; |
| 200 | __u64 targets; |
| 201 | __u64 weight; |
| 202 | __u64 req_no; |
| 203 | __u64 req_len; |
| 204 | __u64 req; |
| 205 | __u64 resp_len; |
| 206 | __u64 resp; |
| 207 | } __attribute__((packed)); |
| 208 | |
| 209 | /** |
| 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' |
| 214 | * a, b, c = reserved |
| 215 | * d = CCA coprocessor |
| 216 | * e = Accelerator |
| 217 | * f = EP11 coprocessor |
| 218 | * @online online status |
| 219 | * @reserved reserved |
| 220 | */ |
| 221 | struct zcrypt_device_status_ext { |
| 222 | unsigned int hwtype:8; |
| 223 | unsigned int qid:16; |
| 224 | unsigned int online:1; |
| 225 | unsigned int functions:6; |
| 226 | unsigned int reserved:1; |
| 227 | }; |
| 228 | |
| 229 | #define MAX_ZDEV_CARDIDS_EXT 256 |
| 230 | #define MAX_ZDEV_DOMAINS_EXT 256 |
| 231 | |
| 232 | /* Maximum number of zcrypt devices */ |
| 233 | #define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT) |
| 234 | |
| 235 | /* Device matrix of all zcrypt devices */ |
| 236 | struct zcrypt_device_matrix_ext { |
| 237 | struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT]; |
| 238 | }; |
| 239 | |
| 240 | #define AUTOSELECT 0xFFFFFFFF |
| 241 | |
| 242 | #define ZCRYPT_IOCTL_MAGIC 'z' |
| 243 | |
| 244 | /** |
| 245 | * Interface notes: |
| 246 | * |
| 247 | * The ioctl()s which are implemented (along with relevant details) |
| 248 | * are: |
| 249 | * |
| 250 | * ICARSAMODEXPO |
| 251 | * Perform an RSA operation using a Modulus-Exponent pair |
| 252 | * This takes an ica_rsa_modexpo struct as its arg. |
| 253 | * |
| 254 | * NOTE: please refer to the comments preceding this structure |
| 255 | * for the implementation details for the contents of the |
| 256 | * block |
| 257 | * |
| 258 | * ICARSACRT |
| 259 | * Perform an RSA operation using a Chinese-Remainder Theorem key |
| 260 | * This takes an ica_rsa_modexpo_crt struct as its arg. |
| 261 | * |
| 262 | * NOTE: please refer to the comments preceding this structure |
| 263 | * for the implementation details for the contents of the |
| 264 | * block |
| 265 | * |
| 266 | * ZSECSENDCPRB |
| 267 | * Send an arbitrary CPRB to a crypto card. |
| 268 | * |
| 269 | * ZSENDEP11CPRB |
| 270 | * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card. |
| 271 | * |
| 272 | * ZCRYPT_DEVICE_STATUS |
| 273 | * The given struct zcrypt_device_matrix_ext is updated with |
| 274 | * status information for each currently known apqn. |
| 275 | * |
| 276 | * ZCRYPT_STATUS_MASK |
| 277 | * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the |
| 278 | * status of all devices. |
| 279 | * 0x01: PCICA |
| 280 | * 0x02: PCICC |
| 281 | * 0x03: PCIXCC_MCL2 |
| 282 | * 0x04: PCIXCC_MCL3 |
| 283 | * 0x05: CEX2C |
| 284 | * 0x06: CEX2A |
| 285 | * 0x07: CEX3C |
| 286 | * 0x08: CEX3A |
| 287 | * 0x0a: CEX4 |
| 288 | * 0x0b: CEX5 |
| 289 | * 0x0c: CEX6 and CEX7 |
| 290 | * 0x0d: device is disabled |
| 291 | * |
| 292 | * ZCRYPT_QDEPTH_MASK |
| 293 | * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the |
| 294 | * queue depth of all devices. |
| 295 | * |
| 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. |
| 300 | * |
| 301 | */ |
| 302 | |
| 303 | /** |
| 304 | * Supported ioctl calls |
| 305 | */ |
| 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) |
| 310 | |
| 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]) |
| 315 | |
| 316 | /* |
| 317 | * Support for multiple zcrypt device nodes. |
| 318 | */ |
| 319 | |
| 320 | /* Nr of minor device node numbers to allocate. */ |
| 321 | #define ZCRYPT_MAX_MINOR_NODES 256 |
| 322 | |
| 323 | /* Max amount of possible ioctls */ |
| 324 | #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS) |
| 325 | |
| 326 | /* |
| 327 | * Only deprecated defines, structs and ioctls below this line. |
| 328 | */ |
| 329 | |
| 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 |
| 334 | |
| 335 | /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */ |
| 336 | #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS) |
| 337 | |
| 338 | /* Deprecated: use struct zcrypt_device_status_ext */ |
| 339 | struct zcrypt_device_status { |
| 340 | unsigned int hwtype:8; |
| 341 | unsigned int qid:14; |
| 342 | unsigned int online:1; |
| 343 | unsigned int functions:6; |
| 344 | unsigned int reserved:3; |
| 345 | }; |
| 346 | |
| 347 | /* Deprecated: use struct zcrypt_device_matrix_ext */ |
| 348 | struct zcrypt_device_matrix { |
| 349 | struct zcrypt_device_status device[MAX_ZDEV_ENTRIES]; |
| 350 | }; |
| 351 | |
| 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]) |
| 360 | |
| 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) |
| 366 | |
| 367 | /* |
| 368 | * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the |
| 369 | * past, don't assign new ioctls for these. |
| 370 | */ |
| 371 | |
| 372 | #endif /* __ASM_S390_ZCRYPT_H */ |