1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef _ZCRYPT_API_H_
17#define _ZCRYPT_API_H_
18
19#include <linux/atomic.h>
20#include <asm/debug.h>
21#include <asm/zcrypt.h>
22#include "ap_bus.h"
23
24
25
26
27
28
29
30
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
38#define ZCRYPT_CEX3C 7
39#define ZCRYPT_CEX3A 8
40#define ZCRYPT_CEX4 10
41#define ZCRYPT_CEX5 11
42#define ZCRYPT_CEX6 12
43
44
45
46
47
48
49#define ZCRYPT_RNG_BUFFER_SIZE 4096
50
51
52
53
54enum crypto_ops {
55 MEX_1K,
56 MEX_2K,
57 MEX_4K,
58 CRT_1K,
59 CRT_2K,
60 CRT_4K,
61 HWRNG,
62 SECKEY,
63 NUM_OPS
64};
65
66struct zcrypt_queue;
67
68struct zcrypt_ops {
69 long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
70 long (*rsa_modexpo_crt)(struct zcrypt_queue *,
71 struct ica_rsa_modexpo_crt *);
72 long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
73 struct ap_message *);
74 long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
75 struct ap_message *);
76 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
77 struct list_head list;
78 struct module *owner;
79 int variant;
80 char name[128];
81};
82
83struct zcrypt_card {
84 struct list_head list;
85 struct list_head zqueues;
86 struct kref refcount;
87 struct ap_card *card;
88 int online;
89
90 int user_space_type;
91 char *type_string;
92 int min_mod_size;
93 int max_mod_size;
94 int max_exp_bit_length;
95 int speed_rating[NUM_OPS];
96 atomic_t load;
97
98 int request_count;
99};
100
101struct zcrypt_queue {
102 struct list_head list;
103 struct kref refcount;
104 struct zcrypt_card *zcard;
105 struct zcrypt_ops *ops;
106 struct ap_queue *queue;
107 int online;
108
109 atomic_t load;
110
111 int request_count;
112
113 struct ap_message reply;
114};
115
116
117extern atomic_t zcrypt_rescan_req;
118
119extern spinlock_t zcrypt_list_lock;
120extern int zcrypt_device_count;
121extern struct list_head zcrypt_card_list;
122
123#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
152void zcrypt_msgtype_register(struct zcrypt_ops *);
153void zcrypt_msgtype_unregister(struct zcrypt_ops *);
154struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
155int zcrypt_api_init(void);
156void zcrypt_api_exit(void);
157long zcrypt_send_cprb(struct ica_xcRB *xcRB);
158void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
159
160#endif
161