forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/s390/crypto/zcrypt_api.h
....@@ -1,8 +1,6 @@
11 /* SPDX-License-Identifier: GPL-2.0+ */
22 /*
3
- * zcrypt 2.1.0
4
- *
5
- * Copyright IBM Corp. 2001, 2012
3
+ * Copyright IBM Corp. 2001, 2019
64 * Author(s): Robert Burroughs
75 * Eric Rossman (edrossma@us.ibm.com)
86 * Cornelia Huck <cornelia.huck@de.ibm.com>
....@@ -22,17 +20,8 @@
2220 #include "ap_bus.h"
2321
2422 /**
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.
23
+ * Supported device types
3124 */
32
-#define ZCRYPT_PCICA 1
33
-#define ZCRYPT_PCICC 2
34
-#define ZCRYPT_PCIXCC_MCL2 3
35
-#define ZCRYPT_PCIXCC_MCL3 4
3625 #define ZCRYPT_CEX2C 5
3726 #define ZCRYPT_CEX2A 6
3827 #define ZCRYPT_CEX3C 7
....@@ -40,6 +29,7 @@
4029 #define ZCRYPT_CEX4 10
4130 #define ZCRYPT_CEX5 11
4231 #define ZCRYPT_CEX6 12
32
+#define ZCRYPT_CEX7 13
4333
4434 /**
4535 * Large random numbers are pulled in 4096 byte chunks from the crypto cards
....@@ -65,13 +55,30 @@
6555
6656 struct zcrypt_queue;
6757
58
+/* struct to hold tracking information for a userspace request/response */
59
+struct zcrypt_track {
60
+ int again_counter; /* retry attempts counter */
61
+ int last_qid; /* last qid used */
62
+ int last_rc; /* last return code */
63
+#ifdef CONFIG_ZCRYPT_DEBUG
64
+ struct ap_fi fi; /* failure injection cmd */
65
+#endif
66
+};
67
+
68
+/* defines related to message tracking */
69
+#define TRACK_AGAIN_MAX 10
70
+#define TRACK_AGAIN_CARD_WEIGHT_PENALTY 1000
71
+#define TRACK_AGAIN_QUEUE_WEIGHT_PENALTY 10000
72
+
6873 struct zcrypt_ops {
69
- long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
74
+ long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *,
75
+ struct ap_message *);
7076 long (*rsa_modexpo_crt)(struct zcrypt_queue *,
71
- struct ica_rsa_modexpo_crt *);
72
- long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
77
+ struct ica_rsa_modexpo_crt *,
78
+ struct ap_message *);
79
+ long (*send_cprb)(bool userspace, struct zcrypt_queue *, struct ica_xcRB *,
7380 struct ap_message *);
74
- long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
81
+ long (*send_ep11_cprb)(bool userspace, struct zcrypt_queue *, struct ep11_urb *,
7582 struct ap_message *);
7683 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
7784 struct list_head list; /* zcrypt ops list. */
....@@ -92,7 +99,7 @@
9299 int min_mod_size; /* Min number of bits. */
93100 int max_mod_size; /* Max number of bits. */
94101 int max_exp_bit_length;
95
- int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
102
+ const int *speed_rating; /* Speed idx of crypto ops. */
96103 atomic_t load; /* Utilization of the crypto device */
97104
98105 int request_count; /* # current requests. */
....@@ -132,9 +139,6 @@
132139 int zcrypt_card_put(struct zcrypt_card *);
133140 int zcrypt_card_register(struct zcrypt_card *);
134141 void zcrypt_card_unregister(struct zcrypt_card *);
135
-struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
136
- unsigned int, unsigned int);
137
-void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
138142
139143 struct zcrypt_queue *zcrypt_queue_alloc(size_t);
140144 void zcrypt_queue_free(struct zcrypt_queue *);
....@@ -143,8 +147,6 @@
143147 int zcrypt_queue_register(struct zcrypt_queue *);
144148 void zcrypt_queue_unregister(struct zcrypt_queue *);
145149 void zcrypt_queue_force_online(struct zcrypt_queue *, int);
146
-struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
147
-void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
148150
149151 int zcrypt_rng_device_add(void);
150152 void zcrypt_rng_device_remove(void);
....@@ -155,6 +157,31 @@
155157 int zcrypt_api_init(void);
156158 void zcrypt_api_exit(void);
157159 long zcrypt_send_cprb(struct ica_xcRB *xcRB);
160
+long zcrypt_send_ep11_cprb(struct ep11_urb *urb);
158161 void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
162
+int zcrypt_device_status_ext(int card, int queue,
163
+ struct zcrypt_device_status_ext *devstatus);
164
+
165
+static inline unsigned long z_copy_from_user(bool userspace,
166
+ void *to,
167
+ const void __user *from,
168
+ unsigned long n)
169
+{
170
+ if (likely(userspace))
171
+ return copy_from_user(to, from, n);
172
+ memcpy(to, (void __force *) from, n);
173
+ return 0;
174
+}
175
+
176
+static inline unsigned long z_copy_to_user(bool userspace,
177
+ void __user *to,
178
+ const void *from,
179
+ unsigned long n)
180
+{
181
+ if (likely(userspace))
182
+ return copy_to_user(to, from, n);
183
+ memcpy((void __force *) to, from, n);
184
+ return 0;
185
+}
159186
160187 #endif /* _ZCRYPT_API_H_ */