blob: a848625c1a5a370ff8d175555b1e499c2f1448f1 [file] [log] [blame]
Harald Freudenbergerac2b96f2018-08-17 12:36:01 +02001/* SPDX-License-Identifier: GPL-2.0+ */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +02002/*
Ralph Wuerthner54321142006-09-20 15:58:36 +02003 * zcrypt 2.1.0
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +02004 *
Holger Dengler5e55a482012-08-28 16:45:36 +02005 * Copyright IBM Corp. 2001, 2012
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +02006 * Author(s): Robert Burroughs
7 * Eric Rossman (edrossma@us.ibm.com)
8 * Cornelia Huck <cornelia.huck@de.ibm.com>
9 *
10 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
11 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
12 * Ralph Wuerthner <rwuerthn@de.ibm.com>
Holger Dengler5e55a482012-08-28 16:45:36 +020013 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020014 */
15
16#ifndef _ZCRYPT_API_H_
17#define _ZCRYPT_API_H_
18
Holger Denglerdabecb22012-09-10 21:34:26 +020019#include <linux/atomic.h>
20#include <asm/debug.h>
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020021#include <asm/zcrypt.h>
Holger Denglerdabecb22012-09-10 21:34:26 +020022#include "ap_bus.h"
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020023
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020024/**
25 * device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2,
26 * PCIXCC_MCL3, CEX2C, or CEX2A
27 *
28 * NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed
29 * Internal Code (LIC) (EC J12220 level 29).
30 * PCIXCC_MCL2 refers to any LIC before this level.
31 */
32#define ZCRYPT_PCICA 1
33#define ZCRYPT_PCICC 2
34#define ZCRYPT_PCIXCC_MCL2 3
35#define ZCRYPT_PCIXCC_MCL3 4
36#define ZCRYPT_CEX2C 5
37#define ZCRYPT_CEX2A 6
Felix Beck8e89b6b2009-12-07 12:51:57 +010038#define ZCRYPT_CEX3C 7
39#define ZCRYPT_CEX3A 8
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +010040#define ZCRYPT_CEX4 10
Ingo Tuchschererbdea1f1b2015-01-23 14:56:25 +010041#define ZCRYPT_CEX5 11
Harald Freudenberger21214b02017-10-10 11:25:06 +020042#define ZCRYPT_CEX6 12
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020043
Ralph Wuerthner2f7c8bd2008-04-17 07:46:15 +020044/**
45 * Large random numbers are pulled in 4096 byte chunks from the crypto cards
Lucas De Marchi25985ed2011-03-30 22:57:33 -030046 * and stored in a page. Be careful when increasing this buffer due to size
Ralph Wuerthner2f7c8bd2008-04-17 07:46:15 +020047 * limitations for AP requests.
48 */
49#define ZCRYPT_RNG_BUFFER_SIZE 4096
50
Ingo Tuchscherer34a15162016-08-25 11:14:15 +020051/*
52 * Identifier for Crypto Request Performance Index
53 */
54enum crypto_ops {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020055 MEX_1K,
Ingo Tuchscherer34a15162016-08-25 11:14:15 +020056 MEX_2K,
57 MEX_4K,
58 CRT_1K,
59 CRT_2K,
60 CRT_4K,
61 HWRNG,
62 SECKEY,
63 NUM_OPS
64};
65
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020066struct zcrypt_queue;
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020067
68struct zcrypt_ops {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020069 long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
70 long (*rsa_modexpo_crt)(struct zcrypt_queue *,
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020071 struct ica_rsa_modexpo_crt *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020072 long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
Ingo Tuchscherer34a15162016-08-25 11:14:15 +020073 struct ap_message *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020074 long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
Ingo Tuchscherer34a15162016-08-25 11:14:15 +020075 struct ap_message *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020076 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
Holger Dengler5e55a482012-08-28 16:45:36 +020077 struct list_head list; /* zcrypt ops list. */
78 struct module *owner;
79 int variant;
Sascha Silbe121a8682015-10-28 11:06:08 +010080 char name[128];
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020081};
82
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020083struct zcrypt_card {
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020084 struct list_head list; /* Device list. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020085 struct list_head zqueues; /* List of zcrypt queues */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020086 struct kref refcount; /* device refcounting */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020087 struct ap_card *card; /* The "real" ap card device. */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020088 int online; /* User online/offline */
89
90 int user_space_type; /* User space device id. */
91 char *type_string; /* User space device name. */
92 int min_mod_size; /* Min number of bits. */
93 int max_mod_size; /* Max number of bits. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020094 int max_exp_bit_length;
Ingo Tuchscherer34a15162016-08-25 11:14:15 +020095 int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020096 atomic_t load; /* Utilization of the crypto device */
97
98 int request_count; /* # current requests. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020099};
100
101struct zcrypt_queue {
102 struct list_head list; /* Device list. */
103 struct kref refcount; /* device refcounting */
104 struct zcrypt_card *zcard;
105 struct zcrypt_ops *ops; /* Crypto operations. */
106 struct ap_queue *queue; /* The "real" ap queue device. */
107 int online; /* User online/offline */
108
109 atomic_t load; /* Utilization of the crypto device */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200110
111 int request_count; /* # current requests. */
112
113 struct ap_message reply; /* Per-device reply structure. */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200114};
115
Holger Denglerdabecb22012-09-10 21:34:26 +0200116/* transport layer rescanning */
117extern atomic_t zcrypt_rescan_req;
118
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200119extern spinlock_t zcrypt_list_lock;
120extern int zcrypt_device_count;
121extern struct list_head zcrypt_card_list;
122
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200123#define for_each_zcrypt_card(_zc) \
124 list_for_each_entry(_zc, &zcrypt_card_list, list)
125
126#define for_each_zcrypt_queue(_zq, _zc) \
127 list_for_each_entry(_zq, &(_zc)->zqueues, list)
128
129struct zcrypt_card *zcrypt_card_alloc(void);
130void zcrypt_card_free(struct zcrypt_card *);
131void zcrypt_card_get(struct zcrypt_card *);
132int zcrypt_card_put(struct zcrypt_card *);
133int zcrypt_card_register(struct zcrypt_card *);
134void zcrypt_card_unregister(struct zcrypt_card *);
135struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
136 unsigned int, unsigned int);
137void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
138
139struct zcrypt_queue *zcrypt_queue_alloc(size_t);
140void zcrypt_queue_free(struct zcrypt_queue *);
141void zcrypt_queue_get(struct zcrypt_queue *);
142int zcrypt_queue_put(struct zcrypt_queue *);
143int zcrypt_queue_register(struct zcrypt_queue *);
144void zcrypt_queue_unregister(struct zcrypt_queue *);
145void zcrypt_queue_force_online(struct zcrypt_queue *, int);
146struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
147void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
148
149int zcrypt_rng_device_add(void);
150void zcrypt_rng_device_remove(void);
151
Holger Dengler5e55a482012-08-28 16:45:36 +0200152void zcrypt_msgtype_register(struct zcrypt_ops *);
153void zcrypt_msgtype_unregister(struct zcrypt_ops *);
Martin Schwidefsky236fb2a2016-09-02 15:21:45 +0200154struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200155int zcrypt_api_init(void);
156void zcrypt_api_exit(void);
Harald Freudenbergera1d001e2016-11-02 14:32:32 +0100157long zcrypt_send_cprb(struct ica_xcRB *xcRB);
Harald Freudenbergeraf4a7222018-04-09 16:18:37 +0200158void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200159
160#endif /* _ZCRYPT_API_H_ */