/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */1/*2* include/asm-s390/zcrypt.h3*4* zcrypt 2.2.1 (user-visible header)5*6* Copyright IBM Corp. 2001, 20227* Author(s): Robert Burroughs8* Eric Rossman ([email protected])9*10* Hotplug & misc device support: Jochen Roehrig ([email protected])11*/1213#ifndef __ASM_S390_ZCRYPT_H14#define __ASM_S390_ZCRYPT_H1516#define ZCRYPT_VERSION 217#define ZCRYPT_RELEASE 218#define ZCRYPT_VARIANT 11920#include <linux/ioctl.h>21#include <linux/compiler.h>22#include <linux/types.h>2324/* Name of the zcrypt device driver. */25#define ZCRYPT_NAME "zcrypt"2627/**28* struct ica_rsa_modexpo29*30* Requirements:31* - outputdatalength is at least as large as inputdatalength.32* - All key parts are right justified in their fields, padded on33* the left with zeroes.34* - length(b_key) = inputdatalength35* - length(n_modulus) = inputdatalength36*/37struct ica_rsa_modexpo {38__u8 __user *inputdata;39__u32 inputdatalength;40__u8 __user *outputdata;41__u32 outputdatalength;42__u8 __user *b_key;43__u8 __user *n_modulus;44};4546/**47* struct ica_rsa_modexpo_crt48*49* Requirements:50* - inputdatalength is even.51* - outputdatalength is at least as large as inputdatalength.52* - All key parts are right justified in their fields, padded on53* the left with zeroes.54* - length(bp_key) = inputdatalength/2 + 855* - length(bq_key) = inputdatalength/256* - length(np_key) = inputdatalength/2 + 857* - length(nq_key) = inputdatalength/258* - length(u_mult_inv) = inputdatalength/2 + 859*/60struct ica_rsa_modexpo_crt {61__u8 __user *inputdata;62__u32 inputdatalength;63__u8 __user *outputdata;64__u32 outputdatalength;65__u8 __user *bp_key;66__u8 __user *bq_key;67__u8 __user *np_prime;68__u8 __user *nq_prime;69__u8 __user *u_mult_inv;70};7172/**73* CPRBX74* Note that all shorts and ints are big-endian.75* All pointer fields are 16 bytes long, and mean nothing.76*77* A request CPRB is followed by a request_parameter_block.78*79* The request (or reply) parameter block is organized thus:80* function code81* VUD block82* key block83*/84struct CPRBX {85__u16 cprb_len; /* CPRB length 220 */86__u8 cprb_ver_id; /* CPRB version id. 0x02 */87__u8 ctfm; /* Command Type Filtering Mask */88__u8 pad_000[2]; /* 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));123124/**125* xcRB126*/127struct ica_xcRB {128__u16 agent_ID;129__u32 user_defined;130__u16 request_ID;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;144__u32 status;145} __attribute__((packed));146147/**148* struct ep11_cprb - EP11 connectivity programming request block149* @cprb_len: CPRB header length [0x0020]150* @cprb_ver_id: CPRB version id. [0x04]151* @pad_000: Alignment pad bytes152* @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 code157* @reserved1: Reserved158* @reserved2: Reserved159* @payload_len: Payload length160*/161struct ep11_cprb {162__u16 cprb_len;163__u8 cprb_ver_id;164__u8 pad_000[2];165__u8 flags;166__u8 func_id[2];167__u32 source_id;168__u32 target_id;169__u32 ret_code;170__u32 reserved1;171__u32 reserved2;172__u32 payload_len;173} __attribute__((packed));174175/**176* struct ep11_target_dev - EP11 target device list177* @ap_id: AP device id178* @dom_id: Usage domain id179*/180struct ep11_target_dev {181__u16 ap_id;182__u16 dom_id;183};184185/**186* struct ep11_urb - EP11 user request block187* @targets_num: Number of target adapters188* @targets: Addr to target adapter list189* @weight: Level of request priority190* @req_no: Request id/number191* @req_len: Request length192* @req: Addr to request block193* @resp_len: Response length194* @resp: Addr to response block195*/196struct ep11_urb {197__u16 targets_num;198__u8 __user *targets;199__u64 weight;200__u64 req_no;201__u64 req_len;202__u8 __user *req;203__u64 resp_len;204__u8 __user *resp;205} __attribute__((packed));206207/**208* struct zcrypt_device_status_ext209* @hwtype: raw hardware type210* @qid: 8 bit device index, 8 bit domain211* @functions: AP device function bit field 'abcdef'212* a, b, c = reserved213* d = CCA coprocessor214* e = Accelerator215* f = EP11 coprocessor216* @online online status217* @reserved reserved218*/219struct zcrypt_device_status_ext {220unsigned int hwtype:8;221unsigned int qid:16;222unsigned int online:1;223unsigned int functions:6;224unsigned int reserved:1;225};226227#define MAX_ZDEV_CARDIDS_EXT 256228#define MAX_ZDEV_DOMAINS_EXT 256229230/* Maximum number of zcrypt devices */231#define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)232233/* Device matrix of all zcrypt devices */234struct zcrypt_device_matrix_ext {235struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];236};237238#define AUTOSELECT 0xFFFFFFFF239#define AUTOSEL_AP ((__u16)0xFFFF)240#define AUTOSEL_DOM ((__u16)0xFFFF)241242#define ZCRYPT_IOCTL_MAGIC 'z'243244/**245* Interface notes:246*247* The ioctl()s which are implemented (along with relevant details)248* are:249*250* ICARSAMODEXPO251* Perform an RSA operation using a Modulus-Exponent pair252* This takes an ica_rsa_modexpo struct as its arg.253*254* NOTE: please refer to the comments preceding this structure255* for the implementation details for the contents of the256* block257*258* ICARSACRT259* Perform an RSA operation using a Chinese-Remainder Theorem key260* This takes an ica_rsa_modexpo_crt struct as its arg.261*262* NOTE: please refer to the comments preceding this structure263* for the implementation details for the contents of the264* block265*266* ZSECSENDCPRB267* Send an arbitrary CPRB to a crypto card.268*269* ZSENDEP11CPRB270* Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.271*272* ZCRYPT_DEVICE_STATUS273* The given struct zcrypt_device_matrix_ext is updated with274* status information for each currently known apqn.275*276* ZCRYPT_STATUS_MASK277* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the278* status of all devices.279* 0x01: PCICA280* 0x02: PCICC281* 0x03: PCIXCC_MCL2282* 0x04: PCIXCC_MCL3283* 0x05: CEX2C284* 0x06: CEX2A285* 0x07: CEX3C286* 0x08: CEX3A287* 0x0a: CEX4288* 0x0b: CEX5289* 0x0c: CEX6, CEX7 or CEX8290* 0x0d: device is disabled291*292* ZCRYPT_QDEPTH_MASK293* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the294* queue depth of all devices.295*296* ZCRYPT_PERDEV_REQCNT297* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for298* the number of successfully completed requests per device since the299* device was detected and made available.300*301*/302303/**304* Supported ioctl calls305*/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)310311#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])315316/*317* Support for multiple zcrypt device nodes.318*/319320/* Nr of minor device node numbers to allocate. */321#define ZCRYPT_MAX_MINOR_NODES 256322323/* Max amount of possible ioctls */324#define MAX_ZDEV_IOCTLS (1 << _IOC_NRBITS)325326/*327* Only deprecated defines, structs and ioctls below this line.328*/329330/* Deprecated: use MAX_ZDEV_CARDIDS_EXT */331#define MAX_ZDEV_CARDIDS 64332/* Deprecated: use MAX_ZDEV_DOMAINS_EXT */333#define MAX_ZDEV_DOMAINS 256334335/* Deprecated: use MAX_ZDEV_ENTRIES_EXT */336#define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)337338/* Deprecated: use struct zcrypt_device_status_ext */339struct zcrypt_device_status {340unsigned int hwtype:8;341unsigned int qid:14;342unsigned int online:1;343unsigned int functions:6;344unsigned int reserved:3;345};346347/* Deprecated: use struct zcrypt_device_matrix_ext */348struct zcrypt_device_matrix {349struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];350};351352/* 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])360361/* 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)366367/*368* The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the369* past, don't assign new ioctls for these.370*/371372#endif /* __ASM_S390_ZCRYPT_H */373374375