Linux Audio

Check our new training course

Loading...
  1/*
  2 *  include/asm-s390/zcrypt.h
  3 *
  4 *  zcrypt 2.1.0 (user-visible header)
  5 *
  6 *  Copyright IBM Corp. 2001, 2006
  7 *  Author(s): Robert Burroughs
  8 *	       Eric Rossman (edrossma@us.ibm.com)
  9 *
 10 *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.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 __ASM_S390_ZCRYPT_H
 28#define __ASM_S390_ZCRYPT_H
 29
 30#define ZCRYPT_VERSION 2
 31#define ZCRYPT_RELEASE 1
 32#define ZCRYPT_VARIANT 1
 33
 34#include <linux/ioctl.h>
 35#include <linux/compiler.h>
 36
 37/**
 38 * struct ica_rsa_modexpo
 39 *
 40 * Requirements:
 41 * - outputdatalength is at least as large as inputdatalength.
 42 * - All key parts are right justified in their fields, padded on
 43 *   the left with zeroes.
 44 * - length(b_key) = inputdatalength
 45 * - length(n_modulus) = inputdatalength
 46 */
 47struct ica_rsa_modexpo {
 48	char __user *	inputdata;
 49	unsigned int	inputdatalength;
 50	char __user *	outputdata;
 51	unsigned int	outputdatalength;
 52	char __user *	b_key;
 53	char __user *	n_modulus;
 54};
 55
 56/**
 57 * struct ica_rsa_modexpo_crt
 58 *
 59 * Requirements:
 60 * - inputdatalength is even.
 61 * - outputdatalength is at least as large as inputdatalength.
 62 * - All key parts are right justified in their fields, padded on
 63 *   the left with zeroes.
 64 * - length(bp_key)	= inputdatalength/2 + 8
 65 * - length(bq_key)	= inputdatalength/2
 66 * - length(np_key)	= inputdatalength/2 + 8
 67 * - length(nq_key)	= inputdatalength/2
 68 * - length(u_mult_inv) = inputdatalength/2 + 8
 69 */
 70struct ica_rsa_modexpo_crt {
 71	char __user *	inputdata;
 72	unsigned int	inputdatalength;
 73	char __user *	outputdata;
 74	unsigned int	outputdatalength;
 75	char __user *	bp_key;
 76	char __user *	bq_key;
 77	char __user *	np_prime;
 78	char __user *	nq_prime;
 79	char __user *	u_mult_inv;
 80};
 81
 82/**
 83 * CPRBX
 84 *	  Note that all shorts and ints are big-endian.
 85 *	  All pointer fields are 16 bytes long, and mean nothing.
 86 *
 87 *	  A request CPRB is followed by a request_parameter_block.
 88 *
 89 *	  The request (or reply) parameter block is organized thus:
 90 *	    function code
 91 *	    VUD block
 92 *	    key block
 93 */
 94struct CPRBX {
 95	unsigned short	cprb_len;	/* CPRB length	      220	 */
 96	unsigned char	cprb_ver_id;	/* CPRB version id.   0x02	 */
 97	unsigned char	pad_000[3];	/* Alignment pad bytes		 */
 98	unsigned char	func_id[2];	/* function id	      0x5432	 */
 99	unsigned char	cprb_flags[4];	/* Flags			 */
100	unsigned int	req_parml;	/* request parameter buffer len	 */
101	unsigned int	req_datal;	/* request data buffer		 */
102	unsigned int	rpl_msgbl;	/* reply  message block length	 */
103	unsigned int	rpld_parml;	/* replied parameter block len	 */
104	unsigned int	rpl_datal;	/* reply data block len		 */
105	unsigned int	rpld_datal;	/* replied data block len	 */
106	unsigned int	req_extbl;	/* request extension block len	 */
107	unsigned char	pad_001[4];	/* reserved			 */
108	unsigned int	rpld_extbl;	/* replied extension block len	 */
109	unsigned char	padx000[16 - sizeof (char *)];
110	unsigned char *	req_parmb;	/* request parm block 'address'	 */
111	unsigned char	padx001[16 - sizeof (char *)];
112	unsigned char *	req_datab;	/* request data block 'address'	 */
113	unsigned char	padx002[16 - sizeof (char *)];
114	unsigned char *	rpl_parmb;	/* reply parm block 'address'	 */
115	unsigned char	padx003[16 - sizeof (char *)];
116	unsigned char *	rpl_datab;	/* reply data block 'address'	 */
117	unsigned char	padx004[16 - sizeof (char *)];
118	unsigned char *	req_extb;	/* request extension block 'addr'*/
119	unsigned char	padx005[16 - sizeof (char *)];
120	unsigned char *	rpl_extb;	/* reply extension block 'address'*/
121	unsigned short	ccp_rtcode;	/* server return code		 */
122	unsigned short	ccp_rscode;	/* server reason code		 */
123	unsigned int	mac_data_len;	/* Mac Data Length		 */
124	unsigned char	logon_id[8];	/* Logon Identifier		 */
125	unsigned char	mac_value[8];	/* Mac Value			 */
126	unsigned char	mac_content_flgs;/* Mac content flag byte	 */
127	unsigned char	pad_002;	/* Alignment			 */
128	unsigned short	domain;		/* Domain			 */
129	unsigned char	usage_domain[4];/* Usage domain			 */
130	unsigned char	cntrl_domain[4];/* Control domain		 */
131	unsigned char	S390enf_mask[4];/* S/390 enforcement mask	 */
132	unsigned char	pad_004[36];	/* reserved			 */
133} __attribute__((packed));
134
135/**
136 * xcRB
137 */
138struct ica_xcRB {
139	unsigned short	agent_ID;
140	unsigned int	user_defined;
141	unsigned short	request_ID;
142	unsigned int	request_control_blk_length;
143	unsigned char	padding1[16 - sizeof (char *)];
144	char __user *	request_control_blk_addr;
145	unsigned int	request_data_length;
146	char		padding2[16 - sizeof (char *)];
147	char __user *	request_data_address;
148	unsigned int	reply_control_blk_length;
149	char		padding3[16 - sizeof (char *)];
150	char __user *	reply_control_blk_addr;
151	unsigned int	reply_data_length;
152	char		padding4[16 - sizeof (char *)];
153	char __user *	reply_data_addr;
154	unsigned short	priority_window;
155	unsigned int	status;
156} __attribute__((packed));
157
158/**
159 * struct ep11_cprb - EP11 connectivity programming request block
160 * @cprb_len:		CPRB header length [0x0020]
161 * @cprb_ver_id:	CPRB version id.   [0x04]
162 * @pad_000:		Alignment pad bytes
163 * @flags:		Admin cmd [0x80] or functional cmd [0x00]
164 * @func_id:		Function id / subtype [0x5434]
165 * @source_id:		Source id [originator id]
166 * @target_id:		Target id [usage/ctrl domain id]
167 * @ret_code:		Return code
168 * @reserved1:		Reserved
169 * @reserved2:		Reserved
170 * @payload_len:	Payload length
171 */
172struct ep11_cprb {
173	uint16_t	cprb_len;
174	unsigned char	cprb_ver_id;
175	unsigned char	pad_000[2];
176	unsigned char	flags;
177	unsigned char	func_id[2];
178	uint32_t	source_id;
179	uint32_t	target_id;
180	uint32_t	ret_code;
181	uint32_t	reserved1;
182	uint32_t	reserved2;
183	uint32_t	payload_len;
184} __attribute__((packed));
185
186/**
187 * struct ep11_target_dev - EP11 target device list
188 * @ap_id:	AP device id
189 * @dom_id:	Usage domain id
190 */
191struct ep11_target_dev {
192	uint16_t ap_id;
193	uint16_t dom_id;
194};
195
196/**
197 * struct ep11_urb - EP11 user request block
198 * @targets_num:	Number of target adapters
199 * @targets:		Addr to target adapter list
200 * @weight:		Level of request priority
201 * @req_no:		Request id/number
202 * @req_len:		Request length
203 * @req:		Addr to request block
204 * @resp_len:		Response length
205 * @resp:		Addr to response block
206 */
207struct ep11_urb {
208	uint16_t		targets_num;
209	uint64_t		targets;
210	uint64_t		weight;
211	uint64_t		req_no;
212	uint64_t		req_len;
213	uint64_t		req;
214	uint64_t		resp_len;
215	uint64_t		resp;
216} __attribute__((packed));
217
218/**
219 * struct zcrypt_device_status
220 * @hwtype:		raw hardware type
221 * @qid:		6 bit device index, 8 bit domain
222 * @functions:		AP device function bit field 'abcdef'
223 *			a, b, c = reserved
224 *			d = CCA coprocessor
225 *			e = Accelerator
226 *			f = EP11 coprocessor
227 * @online		online status
228 * @reserved		reserved
229 */
230struct zcrypt_device_status {
231	unsigned int hwtype:8;
232	unsigned int qid:14;
233	unsigned int online:1;
234	unsigned int functions:6;
235	unsigned int reserved:3;
236};
237
238#define MAX_ZDEV_CARDIDS 64
239#define MAX_ZDEV_DOMAINS 256
240
241/**
242 * Maximum number of zcrypt devices
243 */
244#define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
245
246/**
247 * zcrypt_device_matrix
248 * Device matrix of all zcrypt devices
249 */
250struct zcrypt_device_matrix {
251	struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
252};
253
254#define AUTOSELECT ((unsigned int)0xFFFFFFFF)
255
256#define ZCRYPT_IOCTL_MAGIC 'z'
257
258/**
259 * Interface notes:
260 *
261 * The ioctl()s which are implemented (along with relevant details)
262 * are:
263 *
264 *   ICARSAMODEXPO
265 *     Perform an RSA operation using a Modulus-Exponent pair
266 *     This takes an ica_rsa_modexpo struct as its arg.
267 *
268 *     NOTE: please refer to the comments preceding this structure
269 *	     for the implementation details for the contents of the
270 *	     block
271 *
272 *   ICARSACRT
273 *     Perform an RSA operation using a Chinese-Remainder Theorem key
274 *     This takes an ica_rsa_modexpo_crt struct as its arg.
275 *
276 *     NOTE: please refer to the comments preceding this structure
277 *	     for the implementation details for the contents of the
278 *	     block
279 *
280 *   ZSECSENDCPRB
281 *     Send an arbitrary CPRB to a crypto card.
282 *
283 *   ZSENDEP11CPRB
284 *     Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
285 *
286 *   Z90STAT_STATUS_MASK
287 *     Return an 64 element array of unsigned chars for the status of
288 *     all devices.
289 *	 0x01: PCICA
290 *	 0x02: PCICC
291 *	 0x03: PCIXCC_MCL2
292 *	 0x04: PCIXCC_MCL3
293 *	 0x05: CEX2C
294 *	 0x06: CEX2A
295 *	 0x0d: device is disabled via the proc filesystem
296 *
297 *   Z90STAT_QDEPTH_MASK
298 *     Return an 64 element array of unsigned chars for the queue
299 *     depth of all devices.
300 *
301 *   Z90STAT_PERDEV_REQCNT
302 *     Return an 64 element array of unsigned integers for the number
303 *     of successfully completed requests per device since the device
304 *     was detected and made available.
305 *
306 *   Z90STAT_REQUESTQ_COUNT
307 *     Return an integer count of the number of entries waiting to be
308 *     sent to a device.
309 *
310 *   Z90STAT_PENDINGQ_COUNT
311 *     Return an integer count of the number of entries sent to all
312 *     devices awaiting the reply.
313 *
314 *   Z90STAT_TOTALOPEN_COUNT
315 *     Return an integer count of the number of open file handles.
316 *
317 *   Z90STAT_DOMAIN_INDEX
318 *     Return the integer value of the Cryptographic Domain.
319 *
320 *   The following ioctls are deprecated and should be no longer used:
321 *
322 *   Z90STAT_TOTALCOUNT
323 *     Return an integer count of all device types together.
324 *
325 *   Z90STAT_PCICACOUNT
326 *     Return an integer count of all PCICAs.
327 *
328 *   Z90STAT_PCICCCOUNT
329 *     Return an integer count of all PCICCs.
330 *
331 *   Z90STAT_PCIXCCMCL2COUNT
332 *     Return an integer count of all MCL2 PCIXCCs.
333 *
334 *   Z90STAT_PCIXCCMCL3COUNT
335 *     Return an integer count of all MCL3 PCIXCCs.
336 *
337 *   Z90STAT_CEX2CCOUNT
338 *     Return an integer count of all CEX2Cs.
339 *
340 *   Z90STAT_CEX2ACOUNT
341 *     Return an integer count of all CEX2As.
342 *
343 *   ICAZ90STATUS
344 *     Return some device driver status in a ica_z90_status struct
345 *     This takes an ica_z90_status struct as its arg.
346 *
347 *   Z90STAT_PCIXCCCOUNT
348 *     Return an integer count of all PCIXCCs (MCL2 + MCL3).
349 *     This is DEPRECATED now that MCL3 PCIXCCs are treated differently from
350 *     MCL2 PCIXCCs.
351 */
352
353/**
354 * Supported ioctl calls
355 */
356#define ICARSAMODEXPO	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x05, 0)
357#define ICARSACRT	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
358#define ZSECSENDCPRB	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
359#define ZSENDEP11CPRB	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
360#define ZDEVICESTATUS	_IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
361
362/* New status calls */
363#define Z90STAT_TOTALCOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x40, int)
364#define Z90STAT_PCICACOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x41, int)
365#define Z90STAT_PCICCCOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x42, int)
366#define Z90STAT_PCIXCCMCL2COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x4b, int)
367#define Z90STAT_PCIXCCMCL3COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x4c, int)
368#define Z90STAT_CEX2CCOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x4d, int)
369#define Z90STAT_CEX2ACOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x4e, int)
370#define Z90STAT_REQUESTQ_COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
371#define Z90STAT_PENDINGQ_COUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
372#define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
373#define Z90STAT_DOMAIN_INDEX	_IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
374#define Z90STAT_STATUS_MASK	_IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
375#define Z90STAT_QDEPTH_MASK	_IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
376#define Z90STAT_PERDEV_REQCNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
377
378#endif /* __ASM_S390_ZCRYPT_H */