1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * zcrypt 2.1.0 4 * 5 * Copyright IBM Corp. 2001, 2012 6 * 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> 13 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com> 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 /* deprecated status calls */ 25 #define ICAZ90STATUS _IOR(ZCRYPT_IOCTL_MAGIC, 0x10, struct ica_z90_status) 26 #define Z90STAT_PCIXCCCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x43, int) 27 28 /** 29 * This structure is deprecated and the corresponding ioctl() has been 30 * replaced with individual ioctl()s for each piece of data! 31 */ 32 struct ica_z90_status { 33 int totalcount; 34 int leedslitecount; // PCICA 35 int leeds2count; // PCICC 36 // int PCIXCCCount; is not in struct for backward compatibility 37 int requestqWaitCount; 38 int pendingqWaitCount; 39 int totalOpenCount; 40 int cryptoDomain; 41 // status: 0=not there, 1=PCICA, 2=PCICC, 3=PCIXCC_MCL2, 4=PCIXCC_MCL3, 42 // 5=CEX2C 43 unsigned char status[64]; 44 // qdepth: # work elements waiting for each device 45 unsigned char qdepth[64]; 46 }; 47 48 /** 49 * device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2, 50 * PCIXCC_MCL3, CEX2C, or CEX2A 51 * 52 * NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed 53 * Internal Code (LIC) (EC J12220 level 29). 54 * PCIXCC_MCL2 refers to any LIC before this level. 55 */ 56 #define ZCRYPT_PCICA 1 57 #define ZCRYPT_PCICC 2 58 #define ZCRYPT_PCIXCC_MCL2 3 59 #define ZCRYPT_PCIXCC_MCL3 4 60 #define ZCRYPT_CEX2C 5 61 #define ZCRYPT_CEX2A 6 62 #define ZCRYPT_CEX3C 7 63 #define ZCRYPT_CEX3A 8 64 #define ZCRYPT_CEX4 10 65 #define ZCRYPT_CEX5 11 66 #define ZCRYPT_CEX6 12 67 68 /** 69 * Large random numbers are pulled in 4096 byte chunks from the crypto cards 70 * and stored in a page. Be careful when increasing this buffer due to size 71 * limitations for AP requests. 72 */ 73 #define ZCRYPT_RNG_BUFFER_SIZE 4096 74 75 /* 76 * Identifier for Crypto Request Performance Index 77 */ 78 enum crypto_ops { 79 MEX_1K, 80 MEX_2K, 81 MEX_4K, 82 CRT_1K, 83 CRT_2K, 84 CRT_4K, 85 HWRNG, 86 SECKEY, 87 NUM_OPS 88 }; 89 90 struct zcrypt_queue; 91 92 struct zcrypt_ops { 93 long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *); 94 long (*rsa_modexpo_crt)(struct zcrypt_queue *, 95 struct ica_rsa_modexpo_crt *); 96 long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *, 97 struct ap_message *); 98 long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *, 99 struct ap_message *); 100 long (*rng)(struct zcrypt_queue *, char *, struct ap_message *); 101 struct list_head list; /* zcrypt ops list. */ 102 struct module *owner; 103 int variant; 104 char name[128]; 105 }; 106 107 struct zcrypt_card { 108 struct list_head list; /* Device list. */ 109 struct list_head zqueues; /* List of zcrypt queues */ 110 struct kref refcount; /* device refcounting */ 111 struct ap_card *card; /* The "real" ap card device. */ 112 int online; /* User online/offline */ 113 114 int user_space_type; /* User space device id. */ 115 char *type_string; /* User space device name. */ 116 int min_mod_size; /* Min number of bits. */ 117 int max_mod_size; /* Max number of bits. */ 118 int max_exp_bit_length; 119 int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */ 120 atomic_t load; /* Utilization of the crypto device */ 121 122 int request_count; /* # current requests. */ 123 }; 124 125 struct zcrypt_queue { 126 struct list_head list; /* Device list. */ 127 struct kref refcount; /* device refcounting */ 128 struct zcrypt_card *zcard; 129 struct zcrypt_ops *ops; /* Crypto operations. */ 130 struct ap_queue *queue; /* The "real" ap queue device. */ 131 int online; /* User online/offline */ 132 133 atomic_t load; /* Utilization of the crypto device */ 134 135 int request_count; /* # current requests. */ 136 137 struct ap_message reply; /* Per-device reply structure. */ 138 }; 139 140 /* transport layer rescanning */ 141 extern atomic_t zcrypt_rescan_req; 142 143 extern spinlock_t zcrypt_list_lock; 144 extern int zcrypt_device_count; 145 extern struct list_head zcrypt_card_list; 146 147 #define for_each_zcrypt_card(_zc) \ 148 list_for_each_entry(_zc, &zcrypt_card_list, list) 149 150 #define for_each_zcrypt_queue(_zq, _zc) \ 151 list_for_each_entry(_zq, &(_zc)->zqueues, list) 152 153 struct zcrypt_card *zcrypt_card_alloc(void); 154 void zcrypt_card_free(struct zcrypt_card *); 155 void zcrypt_card_get(struct zcrypt_card *); 156 int zcrypt_card_put(struct zcrypt_card *); 157 int zcrypt_card_register(struct zcrypt_card *); 158 void zcrypt_card_unregister(struct zcrypt_card *); 159 struct zcrypt_card *zcrypt_card_get_best(unsigned int *, 160 unsigned int, unsigned int); 161 void zcrypt_card_put_best(struct zcrypt_card *, unsigned int); 162 163 struct zcrypt_queue *zcrypt_queue_alloc(size_t); 164 void zcrypt_queue_free(struct zcrypt_queue *); 165 void zcrypt_queue_get(struct zcrypt_queue *); 166 int zcrypt_queue_put(struct zcrypt_queue *); 167 int zcrypt_queue_register(struct zcrypt_queue *); 168 void zcrypt_queue_unregister(struct zcrypt_queue *); 169 void zcrypt_queue_force_online(struct zcrypt_queue *, int); 170 struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int); 171 void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int); 172 173 int zcrypt_rng_device_add(void); 174 void zcrypt_rng_device_remove(void); 175 176 void zcrypt_msgtype_register(struct zcrypt_ops *); 177 void zcrypt_msgtype_unregister(struct zcrypt_ops *); 178 struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int); 179 int zcrypt_api_init(void); 180 void zcrypt_api_exit(void); 181 long zcrypt_send_cprb(struct ica_xcRB *xcRB); 182 void zcrypt_device_status_mask(struct zcrypt_device_matrix *devstatus); 183 184 #endif /* _ZCRYPT_API_H_ */ 185