zcrypt_api.h 6.2 KB
Newer Older
1
/*
2
 *  zcrypt 2.1.0
3
 *
4
 *  Copyright IBM Corp. 2001, 2012
5 6 7 8 9 10 11
 *  Author(s): Robert Burroughs
 *	       Eric Rossman (edrossma@us.ibm.com)
 *	       Cornelia Huck <cornelia.huck@de.ibm.com>
 *
 *  Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
 *  Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
 *				  Ralph Wuerthner <rwuerthn@de.ibm.com>
12
 *  MSGTYPE restruct:		  Holger Dengler <hd@linux.vnet.ibm.com>
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _ZCRYPT_API_H_
#define _ZCRYPT_API_H_

32 33
#include <linux/atomic.h>
#include <asm/debug.h>
34
#include <asm/zcrypt.h>
35
#include "ap_bus.h"
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

/* deprecated status calls */
#define ICAZ90STATUS		_IOR(ZCRYPT_IOCTL_MAGIC, 0x10, struct ica_z90_status)
#define Z90STAT_PCIXCCCOUNT	_IOR(ZCRYPT_IOCTL_MAGIC, 0x43, int)

/**
 * This structure is deprecated and the corresponding ioctl() has been
 * replaced with individual ioctl()s for each piece of data!
 */
struct ica_z90_status {
	int totalcount;
	int leedslitecount; // PCICA
	int leeds2count;    // PCICC
	// int PCIXCCCount; is not in struct for backward compatibility
	int requestqWaitCount;
	int pendingqWaitCount;
	int totalOpenCount;
	int cryptoDomain;
	// status: 0=not there, 1=PCICA, 2=PCICC, 3=PCIXCC_MCL2, 4=PCIXCC_MCL3,
	//	   5=CEX2C
	unsigned char status[64];
	// qdepth: # work elements waiting for each device
	unsigned char qdepth[64];
};

/**
 * device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2,
 * PCIXCC_MCL3, CEX2C, or CEX2A
 *
 * NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed
 *	 Internal Code (LIC) (EC J12220 level 29).
 *	 PCIXCC_MCL2 refers to any LIC before this level.
 */
#define ZCRYPT_PCICA		1
#define ZCRYPT_PCICC		2
#define ZCRYPT_PCIXCC_MCL2	3
#define ZCRYPT_PCIXCC_MCL3	4
#define ZCRYPT_CEX2C		5
#define ZCRYPT_CEX2A		6
75 76
#define ZCRYPT_CEX3C		7
#define ZCRYPT_CEX3A		8
77
#define ZCRYPT_CEX4	       10
78
#define ZCRYPT_CEX5	       11
79

80 81
/**
 * Large random numbers are pulled in 4096 byte chunks from the crypto cards
L
Lucas De Marchi 已提交
82
 * and stored in a page. Be careful when increasing this buffer due to size
83 84 85 86
 * limitations for AP requests.
 */
#define ZCRYPT_RNG_BUFFER_SIZE	4096

87 88 89 90
/*
 * Identifier for Crypto Request Performance Index
 */
enum crypto_ops {
91
	MEX_1K,
92 93 94 95 96 97 98 99 100 101
	MEX_2K,
	MEX_4K,
	CRT_1K,
	CRT_2K,
	CRT_4K,
	HWRNG,
	SECKEY,
	NUM_OPS
};

102
struct zcrypt_queue;
103 104

struct zcrypt_ops {
105 106
	long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
	long (*rsa_modexpo_crt)(struct zcrypt_queue *,
107
				struct ica_rsa_modexpo_crt *);
108
	long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
109
			  struct ap_message *);
110
	long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
111
			       struct ap_message *);
112
	long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
113 114 115
	struct list_head list;		/* zcrypt ops list. */
	struct module *owner;
	int variant;
116
	char name[128];
117 118
};

119
struct zcrypt_card {
120
	struct list_head list;		/* Device list. */
121
	struct list_head zqueues;	/* List of zcrypt queues */
122
	struct kref refcount;		/* device refcounting */
123
	struct ap_card *card;		/* The "real" ap card device. */
124 125 126 127 128 129
	int online;			/* User online/offline */

	int user_space_type;		/* User space device id. */
	char *type_string;		/* User space device name. */
	int min_mod_size;		/* Min number of bits. */
	int max_mod_size;		/* Max number of bits. */
130
	int max_exp_bit_length;
131
	int speed_rating[NUM_OPS];	/* Speed idx of crypto ops. */
132 133 134 135 136 137 138 139 140 141 142 143 144 145
	atomic_t load;			/* Utilization of the crypto device */

	int request_count;		/* # current requests. */
};

struct zcrypt_queue {
	struct list_head list;		/* Device list. */
	struct kref refcount;		/* device refcounting */
	struct zcrypt_card *zcard;
	struct zcrypt_ops *ops;		/* Crypto operations. */
	struct ap_queue *queue;		/* The "real" ap queue device. */
	int online;			/* User online/offline */

	atomic_t load;			/* Utilization of the crypto device */
146 147 148 149 150 151

	int request_count;		/* # current requests. */

	struct ap_message reply;	/* Per-device reply structure. */
};

152 153 154
/* transport layer rescanning */
extern atomic_t zcrypt_rescan_req;

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
extern spinlock_t zcrypt_list_lock;
extern int zcrypt_device_count;
extern struct list_head zcrypt_card_list;

#define for_each_zcrypt_card(_zc) \
	list_for_each_entry(_zc, &zcrypt_card_list, list)

#define for_each_zcrypt_queue(_zq, _zc) \
	list_for_each_entry(_zq, &(_zc)->zqueues, list)

struct zcrypt_card *zcrypt_card_alloc(void);
void zcrypt_card_free(struct zcrypt_card *);
void zcrypt_card_get(struct zcrypt_card *);
int zcrypt_card_put(struct zcrypt_card *);
int zcrypt_card_register(struct zcrypt_card *);
void zcrypt_card_unregister(struct zcrypt_card *);
struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
					 unsigned int, unsigned int);
void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);

struct zcrypt_queue *zcrypt_queue_alloc(size_t);
void zcrypt_queue_free(struct zcrypt_queue *);
void zcrypt_queue_get(struct zcrypt_queue *);
int zcrypt_queue_put(struct zcrypt_queue *);
int zcrypt_queue_register(struct zcrypt_queue *);
void zcrypt_queue_unregister(struct zcrypt_queue *);
void zcrypt_queue_force_online(struct zcrypt_queue *, int);
struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
void  zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);

int zcrypt_rng_device_add(void);
void zcrypt_rng_device_remove(void);

188 189
void zcrypt_msgtype_register(struct zcrypt_ops *);
void zcrypt_msgtype_unregister(struct zcrypt_ops *);
190
struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
191 192
int zcrypt_api_init(void);
void zcrypt_api_exit(void);
193 194
long zcrypt_send_cprb(struct ica_xcRB *xcRB);
void zcrypt_device_status_mask(struct zcrypt_device_matrix *devstatus);
195 196

#endif /* _ZCRYPT_API_H_ */