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