| .. | .. |
|---|
| 1 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
|---|
| 2 | 2 | /* |
|---|
| 3 | | - * zcrypt 2.1.0 |
|---|
| 4 | | - * |
|---|
| 5 | | - * Copyright IBM Corp. 2001, 2012 |
|---|
| 3 | + * Copyright IBM Corp. 2001, 2019 |
|---|
| 6 | 4 | * Author(s): Robert Burroughs |
|---|
| 7 | 5 | * Eric Rossman (edrossma@us.ibm.com) |
|---|
| 8 | 6 | * Cornelia Huck <cornelia.huck@de.ibm.com> |
|---|
| .. | .. |
|---|
| 22 | 20 | #include "ap_bus.h" |
|---|
| 23 | 21 | |
|---|
| 24 | 22 | /** |
|---|
| 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 |
|---|
| 31 | 24 | */ |
|---|
| 32 | | -#define ZCRYPT_PCICA 1 |
|---|
| 33 | | -#define ZCRYPT_PCICC 2 |
|---|
| 34 | | -#define ZCRYPT_PCIXCC_MCL2 3 |
|---|
| 35 | | -#define ZCRYPT_PCIXCC_MCL3 4 |
|---|
| 36 | 25 | #define ZCRYPT_CEX2C 5 |
|---|
| 37 | 26 | #define ZCRYPT_CEX2A 6 |
|---|
| 38 | 27 | #define ZCRYPT_CEX3C 7 |
|---|
| .. | .. |
|---|
| 40 | 29 | #define ZCRYPT_CEX4 10 |
|---|
| 41 | 30 | #define ZCRYPT_CEX5 11 |
|---|
| 42 | 31 | #define ZCRYPT_CEX6 12 |
|---|
| 32 | +#define ZCRYPT_CEX7 13 |
|---|
| 43 | 33 | |
|---|
| 44 | 34 | /** |
|---|
| 45 | 35 | * Large random numbers are pulled in 4096 byte chunks from the crypto cards |
|---|
| .. | .. |
|---|
| 65 | 55 | |
|---|
| 66 | 56 | struct zcrypt_queue; |
|---|
| 67 | 57 | |
|---|
| 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 | + |
|---|
| 68 | 73 | 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 *); |
|---|
| 70 | 76 | 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 *, |
|---|
| 73 | 80 | 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 *, |
|---|
| 75 | 82 | struct ap_message *); |
|---|
| 76 | 83 | long (*rng)(struct zcrypt_queue *, char *, struct ap_message *); |
|---|
| 77 | 84 | struct list_head list; /* zcrypt ops list. */ |
|---|
| .. | .. |
|---|
| 92 | 99 | int min_mod_size; /* Min number of bits. */ |
|---|
| 93 | 100 | int max_mod_size; /* Max number of bits. */ |
|---|
| 94 | 101 | 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. */ |
|---|
| 96 | 103 | atomic_t load; /* Utilization of the crypto device */ |
|---|
| 97 | 104 | |
|---|
| 98 | 105 | int request_count; /* # current requests. */ |
|---|
| .. | .. |
|---|
| 132 | 139 | int zcrypt_card_put(struct zcrypt_card *); |
|---|
| 133 | 140 | int zcrypt_card_register(struct zcrypt_card *); |
|---|
| 134 | 141 | 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); |
|---|
| 138 | 142 | |
|---|
| 139 | 143 | struct zcrypt_queue *zcrypt_queue_alloc(size_t); |
|---|
| 140 | 144 | void zcrypt_queue_free(struct zcrypt_queue *); |
|---|
| .. | .. |
|---|
| 143 | 147 | int zcrypt_queue_register(struct zcrypt_queue *); |
|---|
| 144 | 148 | void zcrypt_queue_unregister(struct zcrypt_queue *); |
|---|
| 145 | 149 | 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); |
|---|
| 148 | 150 | |
|---|
| 149 | 151 | int zcrypt_rng_device_add(void); |
|---|
| 150 | 152 | void zcrypt_rng_device_remove(void); |
|---|
| .. | .. |
|---|
| 155 | 157 | int zcrypt_api_init(void); |
|---|
| 156 | 158 | void zcrypt_api_exit(void); |
|---|
| 157 | 159 | long zcrypt_send_cprb(struct ica_xcRB *xcRB); |
|---|
| 160 | +long zcrypt_send_ep11_cprb(struct ep11_urb *urb); |
|---|
| 158 | 161 | 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 | +} |
|---|
| 159 | 186 | |
|---|
| 160 | 187 | #endif /* _ZCRYPT_API_H_ */ |
|---|