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