• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define MSGTYPE06_MAX_MSG_SIZE		(12*1024)
23 
24 /**
25  * The type 6 message family is associated with CEXxC/CEXxP cards.
26  *
27  * It contains a message header followed by a CPRB, both of which
28  * are described below.
29  *
30  * Note that all reserved fields must be zeroes.
31  */
32 struct type6_hdr {
33 	unsigned char reserved1;	/* 0x00				*/
34 	unsigned char type;		/* 0x06				*/
35 	unsigned char reserved2[2];	/* 0x0000			*/
36 	unsigned char right[4];		/* 0x00000000			*/
37 	unsigned char reserved3[2];	/* 0x0000			*/
38 	unsigned char reserved4[2];	/* 0x0000			*/
39 	unsigned char apfs[4];		/* 0x00000000			*/
40 	unsigned int  offset1;		/* 0x00000058 (offset to CPRB)	*/
41 	unsigned int  offset2;		/* 0x00000000			*/
42 	unsigned int  offset3;		/* 0x00000000			*/
43 	unsigned int  offset4;		/* 0x00000000			*/
44 	unsigned char agent_id[16];	/* 0x4341000000000000		*/
45 					/* 0x0000000000000000		*/
46 	unsigned char rqid[2];		/* rqid.  internal to 603	*/
47 	unsigned char reserved5[2];	/* 0x0000			*/
48 	unsigned char function_code[2];	/* for PKD, 0x5044 (ascii 'PD')	*/
49 	unsigned char reserved6[2];	/* 0x0000			*/
50 	unsigned int  ToCardLen1;	/* (request CPRB len + 3) & -4	*/
51 	unsigned int  ToCardLen2;	/* db len 0x00000000 for PKD	*/
52 	unsigned int  ToCardLen3;	/* 0x00000000			*/
53 	unsigned int  ToCardLen4;	/* 0x00000000			*/
54 	unsigned int  FromCardLen1;	/* response buffer length	*/
55 	unsigned int  FromCardLen2;	/* db len 0x00000000 for PKD	*/
56 	unsigned int  FromCardLen3;	/* 0x00000000			*/
57 	unsigned int  FromCardLen4;	/* 0x00000000			*/
58 } __packed;
59 
60 /**
61  * The type 86 message family is associated with CEXxC/CEXxP cards.
62  *
63  * It contains a message header followed by a CPRB.  The CPRB is
64  * the same as the request CPRB, which is described above.
65  *
66  * If format is 1, an error condition exists and no data beyond
67  * the 8-byte message header is of interest.
68  *
69  * The non-error message is shown below.
70  *
71  * Note that all reserved fields must be zeroes.
72  */
73 struct type86_hdr {
74 	unsigned char reserved1;	/* 0x00				*/
75 	unsigned char type;		/* 0x86				*/
76 	unsigned char format;		/* 0x01 (error) or 0x02 (ok)	*/
77 	unsigned char reserved2;	/* 0x00				*/
78 	unsigned char reply_code;	/* reply code (see above)	*/
79 	unsigned char reserved3[3];	/* 0x000000			*/
80 } __packed;
81 
82 #define TYPE86_RSP_CODE 0x86
83 #define TYPE87_RSP_CODE 0x87
84 #define TYPE86_FMT2	0x02
85 
86 struct type86_fmt2_ext {
87 	unsigned char	  reserved[4];	/* 0x00000000			*/
88 	unsigned char	  apfs[4];	/* final status			*/
89 	unsigned int	  count1;	/* length of CPRB + parameters	*/
90 	unsigned int	  offset1;	/* offset to CPRB		*/
91 	unsigned int	  count2;	/* 0x00000000			*/
92 	unsigned int	  offset2;	/* db offset 0x00000000 for PKD	*/
93 	unsigned int	  count3;	/* 0x00000000			*/
94 	unsigned int	  offset3;	/* 0x00000000			*/
95 	unsigned int	  count4;	/* 0x00000000			*/
96 	unsigned int	  offset4;	/* 0x00000000			*/
97 } __packed;
98 
99 unsigned int get_cprb_fc(bool userspace, struct ica_xcRB *, struct ap_message *,
100 			 unsigned int *, unsigned short **);
101 unsigned int get_ep11cprb_fc(bool userspace, struct ep11_urb *, struct ap_message *,
102 			     unsigned int *);
103 unsigned int get_rng_fc(struct ap_message *, int *, unsigned int *);
104 
105 #define LOW	10
106 #define MEDIUM	100
107 #define HIGH	500
108 
109 int speed_idx_cca(int);
110 int speed_idx_ep11(int);
111 
112 /**
113  * Prepare a type6 CPRB message for random number generation
114  *
115  * @ap_dev: AP device pointer
116  * @ap_msg: pointer to AP message
117  */
rng_type6CPRB_msgX(struct ap_message * ap_msg,unsigned int random_number_length,unsigned int * domain)118 static inline void rng_type6CPRB_msgX(struct ap_message *ap_msg,
119 				      unsigned int random_number_length,
120 				      unsigned int *domain)
121 {
122 	struct {
123 		struct type6_hdr hdr;
124 		struct CPRBX cprbx;
125 		char function_code[2];
126 		short int rule_length;
127 		char rule[8];
128 		short int verb_length;
129 		short int key_length;
130 	} __packed * msg = ap_msg->msg;
131 	static struct type6_hdr static_type6_hdrX = {
132 		.type		= 0x06,
133 		.offset1	= 0x00000058,
134 		.agent_id	= {'C', 'A'},
135 		.function_code	= {'R', 'L'},
136 		.ToCardLen1	= sizeof(*msg) - sizeof(msg->hdr),
137 		.FromCardLen1	= sizeof(*msg) - sizeof(msg->hdr),
138 	};
139 	static struct CPRBX local_cprbx = {
140 		.cprb_len	= 0x00dc,
141 		.cprb_ver_id	= 0x02,
142 		.func_id	= {0x54, 0x32},
143 		.req_parml	= sizeof(*msg) - sizeof(msg->hdr) -
144 				  sizeof(msg->cprbx),
145 		.rpl_msgbl	= sizeof(*msg) - sizeof(msg->hdr),
146 	};
147 
148 	msg->hdr = static_type6_hdrX;
149 	msg->hdr.FromCardLen2 = random_number_length,
150 	msg->cprbx = local_cprbx;
151 	msg->cprbx.rpl_datal = random_number_length,
152 	memcpy(msg->function_code, msg->hdr.function_code, 0x02);
153 	msg->rule_length = 0x0a;
154 	memcpy(msg->rule, "RANDOM  ", 8);
155 	msg->verb_length = 0x02;
156 	msg->key_length = 0x02;
157 	ap_msg->len = sizeof(*msg);
158 	*domain = (unsigned short)msg->cprbx.domain;
159 }
160 
161 void zcrypt_msgtype6_init(void);
162 void zcrypt_msgtype6_exit(void);
163 
164 #endif /* _ZCRYPT_MSGTYPE6_H_ */
165