Linux Audio

Check our new training course

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