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