Merge tag 'vboxsf-v5.14-1' of git://git.kernel.org/pub/scm/linux/kernel/git/hansg...
[linux-2.6-microblaze.git] / drivers / s390 / crypto / zcrypt_msgtype6.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  *  Copyright IBM Corp. 2001, 2012
4  *  Author(s): Robert Burroughs
5  *             Eric Rossman (edrossma@us.ibm.com)
6  *
7  *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
8  *  Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
9  *  MSGTYPE restruct:             Holger Dengler <hd@linux.vnet.ibm.com>
10  */
11
12 #ifndef _ZCRYPT_MSGTYPE6_H_
13 #define _ZCRYPT_MSGTYPE6_H_
14
15 #include <asm/zcrypt.h>
16
17 #define MSGTYPE06_NAME                  "zcrypt_msgtype6"
18 #define MSGTYPE06_VARIANT_DEFAULT       0
19 #define MSGTYPE06_VARIANT_NORNG         1
20 #define MSGTYPE06_VARIANT_EP11          2
21
22 /**
23  * The type 6 message family is associated with CEXxC/CEXxP cards.
24  *
25  * It contains a message header followed by a CPRB, both of which
26  * are described below.
27  *
28  * Note that all reserved fields must be zeroes.
29  */
30 struct type6_hdr {
31         unsigned char reserved1;        /* 0x00                         */
32         unsigned char type;             /* 0x06                         */
33         unsigned char reserved2[2];     /* 0x0000                       */
34         unsigned char right[4];         /* 0x00000000                   */
35         unsigned char reserved3[2];     /* 0x0000                       */
36         unsigned char reserved4[2];     /* 0x0000                       */
37         unsigned char apfs[4];          /* 0x00000000                   */
38         unsigned int  offset1;          /* 0x00000058 (offset to CPRB)  */
39         unsigned int  offset2;          /* 0x00000000                   */
40         unsigned int  offset3;          /* 0x00000000                   */
41         unsigned int  offset4;          /* 0x00000000                   */
42         unsigned char agent_id[16];     /* 0x4341000000000000           */
43                                         /* 0x0000000000000000           */
44         unsigned char rqid[2];          /* rqid.  internal to 603       */
45         unsigned char reserved5[2];     /* 0x0000                       */
46         unsigned char function_code[2]; /* for PKD, 0x5044 (ascii 'PD') */
47         unsigned char reserved6[2];     /* 0x0000                       */
48         unsigned int  ToCardLen1;       /* (request CPRB len + 3) & -4  */
49         unsigned int  ToCardLen2;       /* db len 0x00000000 for PKD    */
50         unsigned int  ToCardLen3;       /* 0x00000000                   */
51         unsigned int  ToCardLen4;       /* 0x00000000                   */
52         unsigned int  FromCardLen1;     /* response buffer length       */
53         unsigned int  FromCardLen2;     /* db len 0x00000000 for PKD    */
54         unsigned int  FromCardLen3;     /* 0x00000000                   */
55         unsigned int  FromCardLen4;     /* 0x00000000                   */
56 } __packed;
57
58 /**
59  * The type 86 message family is associated with CEXxC/CEXxP cards.
60  *
61  * It contains a message header followed by a CPRB.  The CPRB is
62  * the same as the request CPRB, which is described above.
63  *
64  * If format is 1, an error condition exists and no data beyond
65  * the 8-byte message header is of interest.
66  *
67  * The non-error message is shown below.
68  *
69  * Note that all reserved fields must be zeroes.
70  */
71 struct type86_hdr {
72         unsigned char reserved1;        /* 0x00                         */
73         unsigned char type;             /* 0x86                         */
74         unsigned char format;           /* 0x01 (error) or 0x02 (ok)    */
75         unsigned char reserved2;        /* 0x00                         */
76         unsigned char reply_code;       /* reply code (see above)       */
77         unsigned char reserved3[3];     /* 0x000000                     */
78 } __packed;
79
80 #define TYPE86_RSP_CODE 0x86
81 #define TYPE87_RSP_CODE 0x87
82 #define TYPE86_FMT2     0x02
83
84 struct type86_fmt2_ext {
85         unsigned char     reserved[4];  /* 0x00000000                   */
86         unsigned char     apfs[4];      /* final status                 */
87         unsigned int      count1;       /* length of CPRB + parameters  */
88         unsigned int      offset1;      /* offset to CPRB               */
89         unsigned int      count2;       /* 0x00000000                   */
90         unsigned int      offset2;      /* db offset 0x00000000 for PKD */
91         unsigned int      count3;       /* 0x00000000                   */
92         unsigned int      offset3;      /* 0x00000000                   */
93         unsigned int      count4;       /* 0x00000000                   */
94         unsigned int      offset4;      /* 0x00000000                   */
95 } __packed;
96
97 unsigned int get_cprb_fc(bool userspace, struct ica_xcRB *, struct ap_message *,
98                          unsigned int *, unsigned short **);
99 unsigned int get_ep11cprb_fc(bool userspace, struct ep11_urb *, struct ap_message *,
100                              unsigned int *);
101 unsigned int get_rng_fc(struct ap_message *, int *, unsigned int *);
102
103 #define LOW     10
104 #define MEDIUM  100
105 #define HIGH    500
106
107 int speed_idx_cca(int);
108 int speed_idx_ep11(int);
109
110 /**
111  * Prepare a type6 CPRB message for random number generation
112  *
113  * @ap_dev: AP device pointer
114  * @ap_msg: pointer to AP message
115  */
116 static inline void rng_type6CPRB_msgX(struct ap_message *ap_msg,
117                                       unsigned int random_number_length,
118                                       unsigned int *domain)
119 {
120         struct {
121                 struct type6_hdr hdr;
122                 struct CPRBX cprbx;
123                 char function_code[2];
124                 short int rule_length;
125                 char rule[8];
126                 short int verb_length;
127                 short int key_length;
128         } __packed * msg = ap_msg->msg;
129         static struct type6_hdr static_type6_hdrX = {
130                 .type           = 0x06,
131                 .offset1        = 0x00000058,
132                 .agent_id       = {'C', 'A'},
133                 .function_code  = {'R', 'L'},
134                 .ToCardLen1     = sizeof(*msg) - sizeof(msg->hdr),
135                 .FromCardLen1   = sizeof(*msg) - sizeof(msg->hdr),
136         };
137         static struct CPRBX local_cprbx = {
138                 .cprb_len       = 0x00dc,
139                 .cprb_ver_id    = 0x02,
140                 .func_id        = {0x54, 0x32},
141                 .req_parml      = sizeof(*msg) - sizeof(msg->hdr) -
142                                   sizeof(msg->cprbx),
143                 .rpl_msgbl      = sizeof(*msg) - sizeof(msg->hdr),
144         };
145
146         msg->hdr = static_type6_hdrX;
147         msg->hdr.FromCardLen2 = random_number_length,
148         msg->cprbx = local_cprbx;
149         msg->cprbx.rpl_datal = random_number_length,
150         memcpy(msg->function_code, msg->hdr.function_code, 0x02);
151         msg->rule_length = 0x0a;
152         memcpy(msg->rule, "RANDOM  ", 8);
153         msg->verb_length = 0x02;
154         msg->key_length = 0x02;
155         ap_msg->len = sizeof(*msg);
156         *domain = (unsigned short)msg->cprbx.domain;
157 }
158
159 void zcrypt_msgtype6_init(void);
160 void zcrypt_msgtype6_exit(void);
161
162 #endif /* _ZCRYPT_MSGTYPE6_H_ */