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 __u8 cprb_ver_id; 166 __u8 pad_000[2]; 167 __u8 flags; 168 __u8 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 __u8 __user *targets; 201 __u64 weight; 202 __u64 req_no; 203 __u64 req_len; 204 __u8 __user *req; 205 __u64 resp_len; 206 __u8 __user *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 #define AUTOSEL_AP ((__u16) 0xFFFF) 242 #define AUTOSEL_DOM ((__u16) 0xFFFF) 243 244 #define ZCRYPT_IOCTL_MAGIC 'z' 245 246 /** 247 * Interface notes: 248 * 249 * The ioctl()s which are implemented (along with relevant details) 250 * are: 251 * 252 * ICARSAMODEXPO 253 * Perform an RSA operation using a Modulus-Exponent pair 254 * This takes an ica_rsa_modexpo struct as its arg. 255 * 256 * NOTE: please refer to the comments preceding this structure 257 * for the implementation details for the contents of the 258 * block 259 * 260 * ICARSACRT 261 * Perform an RSA operation using a Chinese-Remainder Theorem key 262 * This takes an ica_rsa_modexpo_crt struct as its arg. 263 * 264 * NOTE: please refer to the comments preceding this structure 265 * for the implementation details for the contents of the 266 * block 267 * 268 * ZSECSENDCPRB 269 * Send an arbitrary CPRB to a crypto card. 270 * 271 * ZSENDEP11CPRB 272 * Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card. 273 * 274 * ZCRYPT_DEVICE_STATUS 275 * The given struct zcrypt_device_matrix_ext is updated with 276 * status information for each currently known apqn. 277 * 278 * ZCRYPT_STATUS_MASK 279 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the 280 * status of all devices. 281 * 0x01: PCICA 282 * 0x02: PCICC 283 * 0x03: PCIXCC_MCL2 284 * 0x04: PCIXCC_MCL3 285 * 0x05: CEX2C 286 * 0x06: CEX2A 287 * 0x07: CEX3C 288 * 0x08: CEX3A 289 * 0x0a: CEX4 290 * 0x0b: CEX5 291 * 0x0c: CEX6 and CEX7 292 * 0x0d: device is disabled 293 * 294 * ZCRYPT_QDEPTH_MASK 295 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the 296 * queue depth of all devices. 297 * 298 * ZCRYPT_PERDEV_REQCNT 299 * Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for 300 * the number of successfully completed requests per device since the 301 * device was detected and made available. 302 * 303 */ 304 305 /** 306 * Supported ioctl calls 307 */ 308 #define ICARSAMODEXPO _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0) 309 #define ICARSACRT _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0) 310 #define ZSECSENDCPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0) 311 #define ZSENDEP11CPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0) 312 313 #define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0) 314 #define ZCRYPT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT]) 315 #define ZCRYPT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT]) 316 #define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT]) 317 318 /* 319 * Support for multiple zcrypt device nodes. 320 */ 321 322 /* Nr of minor device node numbers to allocate. */ 323 #define ZCRYPT_MAX_MINOR_NODES 256 324 325 /* Max amount of possible ioctls */ 326 #define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS) 327 328 /* 329 * Only deprecated defines, structs and ioctls below this line. 330 */ 331 332 /* Deprecated: use MAX_ZDEV_CARDIDS_EXT */ 333 #define MAX_ZDEV_CARDIDS 64 334 /* Deprecated: use MAX_ZDEV_DOMAINS_EXT */ 335 #define MAX_ZDEV_DOMAINS 256 336 337 /* Deprecated: use MAX_ZDEV_ENTRIES_EXT */ 338 #define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS) 339 340 /* Deprecated: use struct zcrypt_device_status_ext */ 341 struct zcrypt_device_status { 342 unsigned int hwtype:8; 343 unsigned int qid:14; 344 unsigned int online:1; 345 unsigned int functions:6; 346 unsigned int reserved:3; 347 }; 348 349 /* Deprecated: use struct zcrypt_device_matrix_ext */ 350 struct zcrypt_device_matrix { 351 struct zcrypt_device_status device[MAX_ZDEV_ENTRIES]; 352 }; 353 354 /* Deprecated: use ZCRYPT_DEVICE_STATUS */ 355 #define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0) 356 /* Deprecated: use ZCRYPT_STATUS_MASK */ 357 #define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64]) 358 /* Deprecated: use ZCRYPT_QDEPTH_MASK */ 359 #define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64]) 360 /* Deprecated: use ZCRYPT_PERDEV_REQCNT */ 361 #define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64]) 362 363 /* Deprecated: use sysfs to query these values */ 364 #define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int) 365 #define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int) 366 #define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int) 367 #define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int) 368 369 /* 370 * The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the 371 * past, don't assign new ioctls for these. 372 */ 373 374 #endif /* __ASM_S390_ZCRYPT_H */ 375