patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / s390 / crypto / z90crypt.h
1 /*
2  *  linux/drivers/s390/misc/z90crypt.h
3  *
4  *  z90crypt 1.3.1
5  *
6  *  Copyright (C)  2001, 2004 IBM Corporation
7  *  Author(s): Robert Burroughs (burrough@us.ibm.com)
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 _LINUX_Z90CRYPT_H_
28 #define _LINUX_Z90CRYPT_H_
29
30 #include <linux/ioctl.h>
31
32 #define VERSION_Z90CRYPT_H "$Revision: 1.2 $"
33
34 #define z90crypt_VERSION 1
35 #define z90crypt_RELEASE 3      // 2 = PCIXCC, 3 = rewrite for coding standards
36 #define z90crypt_VARIANT 1
37
38 /**
39  * struct ica_rsa_modexpo
40  *
41  * Requirements:
42  * - outputdatalength is at least as large as inputdatalength.
43  * - All key parts are right justified in their fields, padded on
44  *   the left with zeroes.
45  * - length(b_key) = inputdatalength
46  * - length(n_modulus) = inputdatalength
47  */
48 struct ica_rsa_modexpo {
49         char __user *   inputdata;
50         unsigned int    inputdatalength;
51         char __user *   outputdata;
52         unsigned int    outputdatalength;
53         char __user *   b_key;
54         char __user *   n_modulus;
55 };
56
57 /**
58  * struct ica_rsa_modexpo_crt
59  *
60  * Requirements:
61  * - inputdatalength is even.
62  * - outputdatalength is at least as large as inputdatalength.
63  * - All key parts are right justified in their fields, padded on
64  *   the left with zeroes.
65  * - length(bp_key)     = inputdatalength/2 + 8
66  * - length(bq_key)     = inputdatalength/2
67  * - length(np_key)     = inputdatalength/2 + 8
68  * - length(nq_key)     = inputdatalength/2
69  * - length(u_mult_inv) = inputdatalength/2 + 8
70  */
71 struct ica_rsa_modexpo_crt {
72         char __user *   inputdata;
73         unsigned int    inputdatalength;
74         char __user *   outputdata;
75         unsigned int    outputdatalength;
76         char __user *   bp_key;
77         char __user *   bq_key;
78         char __user *   np_prime;
79         char __user *   nq_prime;
80         char __user *   u_mult_inv;
81 };
82
83 #define Z90_IOCTL_MAGIC 'z'  // NOTE:  Need to allocate from linux folks
84
85 /**
86  * Interface notes:
87  *
88  * The ioctl()s which are implemented (along with relevant details)
89  * are:
90  *
91  *   ICARSAMODEXPO
92  *     Perform an RSA operation using a Modulus-Exponent pair
93  *     This takes an ica_rsa_modexpo struct as its arg.
94  *
95  *     NOTE: please refer to the comments preceding this structure
96  *           for the implementation details for the contents of the
97  *           block
98  *
99  *   ICARSACRT
100  *     Perform an RSA operation using a Chinese-Remainder Theorem key
101  *     This takes an ica_rsa_modexpo_crt struct as its arg.
102  *
103  *     NOTE: please refer to the comments preceding this structure
104  *           for the implementation details for the contents of the
105  *           block
106  *
107  *   Z90STAT_TOTALCOUNT
108  *     Return an integer count of all device types together.
109  *
110  *   Z90STAT_PCICACOUNT
111  *     Return an integer count of all PCICAs.
112  *
113  *   Z90STAT_PCICCCOUNT
114  *     Return an integer count of all PCICCs.
115  *
116  *   Z90STAT_PCIXCCCOUNT
117  *     Return an integer count of all PCIXCCs.
118  *
119  *   Z90STAT_REQUESTQ_COUNT
120  *     Return an integer count of the number of entries waiting to be
121  *     sent to a device.
122  *
123  *   Z90STAT_PENDINGQ_COUNT
124  *     Return an integer count of the number of entries sent to a
125  *     device awaiting the reply.
126  *
127  *   Z90STAT_TOTALOPEN_COUNT
128  *     Return an integer count of the number of open file handles.
129  *
130  *   Z90STAT_DOMAIN_INDEX
131  *     Return the integer value of the Cryptographic Domain.
132  *
133  *   Z90STAT_STATUS_MASK
134  *     Return an 64 element array of unsigned chars for the status of
135  *     all devices.
136  *       0x01: PCICA
137  *       0x02: PCICC
138  *       0x03: PCIXCC
139  *       0x0d: device is disabled via the proc filesystem
140  *
141  *   Z90STAT_QDEPTH_MASK
142  *     Return an 64 element array of unsigned chars for the queue
143  *     depth of all devices.
144  *
145  *   Z90STAT_PERDEV_REQCNT
146  *     Return an 64 element array of unsigned integers for the number
147  *     of successfully completed requests per device since the device
148  *     was detected and made available.
149  *
150  *   ICAZ90STATUS (deprecated)
151  *     Return some device driver status in a ica_z90_status struct
152  *     This takes an ica_z90_status struct as its arg.
153  *
154  *     NOTE: this ioctl() is deprecated, and has been replaced with
155  *           single ioctl()s for each type of status being requested
156  *
157  *   Z90QUIESCE (not recommended)
158  *     Quiesce the driver.  This is intended to stop all new
159  *     requests from being processed.  Its use is not recommended,
160  *     except in circumstances where there is no other way to stop
161  *     callers from accessing the driver.  Its original use was to
162  *     allow the driver to be "drained" of work in preparation for
163  *     a system shutdown.
164  *
165  *     NOTE: once issued, this ban on new work cannot be undone
166  *           except by unloading and reloading the driver.
167  */
168
169 /**
170  * Supported ioctl calls
171  */
172 #define ICARSAMODEXPO   _IOC(_IOC_READ|_IOC_WRITE, Z90_IOCTL_MAGIC, 0x05, 0)
173 #define ICARSACRT       _IOC(_IOC_READ|_IOC_WRITE, Z90_IOCTL_MAGIC, 0x06, 0)
174
175 /* DEPRECATED status call (bound for removal SOON) */
176 #define ICAZ90STATUS    _IOR(Z90_IOCTL_MAGIC, 0x10, struct ica_z90_status)
177
178 /* unrelated to ICA callers */
179 #define Z90QUIESCE      _IO(Z90_IOCTL_MAGIC, 0x11)
180
181 /* New status calls */
182 #define Z90STAT_TOTALCOUNT      _IOR(Z90_IOCTL_MAGIC, 0x40, int)
183 #define Z90STAT_PCICACOUNT      _IOR(Z90_IOCTL_MAGIC, 0x41, int)
184 #define Z90STAT_PCICCCOUNT      _IOR(Z90_IOCTL_MAGIC, 0x42, int)
185 #define Z90STAT_PCIXCCCOUNT     _IOR(Z90_IOCTL_MAGIC, 0x43, int)
186 #define Z90STAT_REQUESTQ_COUNT  _IOR(Z90_IOCTL_MAGIC, 0x44, int)
187 #define Z90STAT_PENDINGQ_COUNT  _IOR(Z90_IOCTL_MAGIC, 0x45, int)
188 #define Z90STAT_TOTALOPEN_COUNT _IOR(Z90_IOCTL_MAGIC, 0x46, int)
189 #define Z90STAT_DOMAIN_INDEX    _IOR(Z90_IOCTL_MAGIC, 0x47, int)
190 #define Z90STAT_STATUS_MASK     _IOR(Z90_IOCTL_MAGIC, 0x48, char[64])
191 #define Z90STAT_QDEPTH_MASK     _IOR(Z90_IOCTL_MAGIC, 0x49, char[64])
192 #define Z90STAT_PERDEV_REQCNT   _IOR(Z90_IOCTL_MAGIC, 0x4a, int[64])
193
194 /**
195  * local errno definitions
196  */
197 #define ENOBUFF   129   // filp->private_data->...>work_elem_p->buffer is NULL
198 #define EWORKPEND 130   // user issues ioctl while another pending
199 #define ERELEASED 131   // user released while ioctl pending
200 #define EQUIESCE  132   // z90crypt quiescing (no more work allowed)
201 #define ETIMEOUT  133   // request timed out
202 #define EUNKNOWN  134   // some unrecognized error occured
203 #define EGETBUFF  135   // Error getting buffer
204
205 /**
206  * DEPRECATED STRUCTURES
207  */
208
209 /**
210  * This structure is DEPRECATED and the corresponding ioctl() has been
211  * replaced with individual ioctl()s for each piece of data!
212  * This structure will NOT survive past version 1.3.1, so switch to the
213  * new ioctl()s.
214  */
215 #define MASK_LENGTH 64 // mask length
216 struct ica_z90_status {
217         int totalcount;
218         int leedslitecount; // PCICA
219         int leeds2count;    // PCICC
220         // int PCIXCCCount; is not in struct for backward compatibility
221         int requestqWaitCount;
222         int pendingqWaitCount;
223         int totalOpenCount;
224         int cryptoDomain;
225         // status: 0=not there. 1=PCICA. 2=PCICC. 3=PCIXCC
226         unsigned char status[MASK_LENGTH];
227         // qdepth: # work elements waiting for each device
228         unsigned char qdepth[MASK_LENGTH];
229 };
230
231 #endif /* _LINUX_Z90CRYPT_H_ */