blob: af67a768a3fc1de855797211903bb4d3ee5c3af1 [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/*
Harald Freudenbergeree410de2018-10-04 15:30:24 +02003 * Copyright IBM Corp. 2001, 2018
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +02004 * Author(s): Robert Burroughs
5 * Eric Rossman (edrossma@us.ibm.com)
6 * Cornelia Huck <cornelia.huck@de.ibm.com>
7 *
8 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
9 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
10 * Ralph Wuerthner <rwuerthn@de.ibm.com>
Holger Dengler5e55a482012-08-28 16:45:36 +020011 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020012 */
13
14#ifndef _ZCRYPT_API_H_
15#define _ZCRYPT_API_H_
16
Holger Denglerdabecb22012-09-10 21:34:26 +020017#include <linux/atomic.h>
18#include <asm/debug.h>
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020019#include <asm/zcrypt.h>
Holger Denglerdabecb22012-09-10 21:34:26 +020020#include "ap_bus.h"
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020021
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020022/**
Harald Freudenbergeree410de2018-10-04 15:30:24 +020023 * Supported device types
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020024 */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020025#define ZCRYPT_CEX2C 5
26#define ZCRYPT_CEX2A 6
Felix Beck8e89b6b2009-12-07 12:51:57 +010027#define ZCRYPT_CEX3C 7
28#define ZCRYPT_CEX3A 8
Ingo Tuchscherer91f3e3ea2013-11-20 10:47:13 +010029#define ZCRYPT_CEX4 10
Ingo Tuchschererbdea1f1b2015-01-23 14:56:25 +010030#define ZCRYPT_CEX5 11
Harald Freudenberger21214b02017-10-10 11:25:06 +020031#define ZCRYPT_CEX6 12
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020032
Ralph Wuerthner2f7c8bd2008-04-17 07:46:15 +020033/**
34 * Large random numbers are pulled in 4096 byte chunks from the crypto cards
Lucas De Marchi25985ed2011-03-30 22:57:33 -030035 * and stored in a page. Be careful when increasing this buffer due to size
Ralph Wuerthner2f7c8bd2008-04-17 07:46:15 +020036 * limitations for AP requests.
37 */
38#define ZCRYPT_RNG_BUFFER_SIZE 4096
39
Ingo Tuchscherer34a151672016-08-25 11:14:15 +020040/*
41 * Identifier for Crypto Request Performance Index
42 */
43enum crypto_ops {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020044 MEX_1K,
Ingo Tuchscherer34a151672016-08-25 11:14:15 +020045 MEX_2K,
46 MEX_4K,
47 CRT_1K,
48 CRT_2K,
49 CRT_4K,
50 HWRNG,
51 SECKEY,
52 NUM_OPS
53};
54
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020055struct zcrypt_queue;
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020056
57struct zcrypt_ops {
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020058 long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
59 long (*rsa_modexpo_crt)(struct zcrypt_queue *,
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020060 struct ica_rsa_modexpo_crt *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020061 long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
Ingo Tuchscherer34a151672016-08-25 11:14:15 +020062 struct ap_message *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020063 long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
Ingo Tuchscherer34a151672016-08-25 11:14:15 +020064 struct ap_message *);
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020065 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
Holger Dengler5e55a482012-08-28 16:45:36 +020066 struct list_head list; /* zcrypt ops list. */
67 struct module *owner;
68 int variant;
Sascha Silbe121a8682015-10-28 11:06:08 +010069 char name[128];
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020070};
71
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020072struct zcrypt_card {
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020073 struct list_head list; /* Device list. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020074 struct list_head zqueues; /* List of zcrypt queues */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020075 struct kref refcount; /* device refcounting */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020076 struct ap_card *card; /* The "real" ap card device. */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020077 int online; /* User online/offline */
78
79 int user_space_type; /* User space device id. */
80 char *type_string; /* User space device name. */
81 int min_mod_size; /* Min number of bits. */
82 int max_mod_size; /* Max number of bits. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020083 int max_exp_bit_length;
Ingo Tuchscherer34a151672016-08-25 11:14:15 +020084 int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020085 atomic_t load; /* Utilization of the crypto device */
86
87 int request_count; /* # current requests. */
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +020088};
89
90struct zcrypt_queue {
91 struct list_head list; /* Device list. */
92 struct kref refcount; /* device refcounting */
93 struct zcrypt_card *zcard;
94 struct zcrypt_ops *ops; /* Crypto operations. */
95 struct ap_queue *queue; /* The "real" ap queue device. */
96 int online; /* User online/offline */
97
98 atomic_t load; /* Utilization of the crypto device */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +020099
100 int request_count; /* # current requests. */
101
102 struct ap_message reply; /* Per-device reply structure. */
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200103};
104
Holger Denglerdabecb22012-09-10 21:34:26 +0200105/* transport layer rescanning */
106extern atomic_t zcrypt_rescan_req;
107
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200108extern spinlock_t zcrypt_list_lock;
109extern int zcrypt_device_count;
110extern struct list_head zcrypt_card_list;
111
Ingo Tuchscherere28d2af2016-08-25 11:16:03 +0200112#define for_each_zcrypt_card(_zc) \
113 list_for_each_entry(_zc, &zcrypt_card_list, list)
114
115#define for_each_zcrypt_queue(_zq, _zc) \
116 list_for_each_entry(_zq, &(_zc)->zqueues, list)
117
118struct zcrypt_card *zcrypt_card_alloc(void);
119void zcrypt_card_free(struct zcrypt_card *);
120void zcrypt_card_get(struct zcrypt_card *);
121int zcrypt_card_put(struct zcrypt_card *);
122int zcrypt_card_register(struct zcrypt_card *);
123void zcrypt_card_unregister(struct zcrypt_card *);
124struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
125 unsigned int, unsigned int);
126void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
127
128struct zcrypt_queue *zcrypt_queue_alloc(size_t);
129void zcrypt_queue_free(struct zcrypt_queue *);
130void zcrypt_queue_get(struct zcrypt_queue *);
131int zcrypt_queue_put(struct zcrypt_queue *);
132int zcrypt_queue_register(struct zcrypt_queue *);
133void zcrypt_queue_unregister(struct zcrypt_queue *);
134void zcrypt_queue_force_online(struct zcrypt_queue *, int);
135struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
136void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
137
138int zcrypt_rng_device_add(void);
139void zcrypt_rng_device_remove(void);
140
Holger Dengler5e55a482012-08-28 16:45:36 +0200141void zcrypt_msgtype_register(struct zcrypt_ops *);
142void zcrypt_msgtype_unregister(struct zcrypt_ops *);
Martin Schwidefsky236fb2a2016-09-02 15:21:45 +0200143struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200144int zcrypt_api_init(void);
145void zcrypt_api_exit(void);
Harald Freudenbergera1d001e2016-11-02 14:32:32 +0100146long zcrypt_send_cprb(struct ica_xcRB *xcRB);
Harald Freudenbergeraf4a7222018-04-09 16:18:37 +0200147void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
Martin Schwidefsky2dbc2412006-09-20 15:58:27 +0200148
149#endif /* _ZCRYPT_API_H_ */