zcrypt_api.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * zcrypt 2.1.0
  3. *
  4. * Copyright IBM Corp. 2001, 2012
  5. * Author(s): Robert Burroughs
  6. * Eric Rossman (edrossma@us.ibm.com)
  7. * Cornelia Huck <cornelia.huck@de.ibm.com>
  8. *
  9. * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
  10. * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
  11. * Ralph Wuerthner <rwuerthn@de.ibm.com>
  12. * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #ifndef _ZCRYPT_API_H_
  29. #define _ZCRYPT_API_H_
  30. #include <linux/atomic.h>
  31. #include <asm/debug.h>
  32. #include <asm/zcrypt.h>
  33. #include "ap_bus.h"
  34. /* deprecated status calls */
  35. #define ICAZ90STATUS _IOR(ZCRYPT_IOCTL_MAGIC, 0x10, struct ica_z90_status)
  36. #define Z90STAT_PCIXCCCOUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x43, int)
  37. /**
  38. * This structure is deprecated and the corresponding ioctl() has been
  39. * replaced with individual ioctl()s for each piece of data!
  40. */
  41. struct ica_z90_status {
  42. int totalcount;
  43. int leedslitecount; // PCICA
  44. int leeds2count; // PCICC
  45. // int PCIXCCCount; is not in struct for backward compatibility
  46. int requestqWaitCount;
  47. int pendingqWaitCount;
  48. int totalOpenCount;
  49. int cryptoDomain;
  50. // status: 0=not there, 1=PCICA, 2=PCICC, 3=PCIXCC_MCL2, 4=PCIXCC_MCL3,
  51. // 5=CEX2C
  52. unsigned char status[64];
  53. // qdepth: # work elements waiting for each device
  54. unsigned char qdepth[64];
  55. };
  56. /**
  57. * device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2,
  58. * PCIXCC_MCL3, CEX2C, or CEX2A
  59. *
  60. * NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed
  61. * Internal Code (LIC) (EC J12220 level 29).
  62. * PCIXCC_MCL2 refers to any LIC before this level.
  63. */
  64. #define ZCRYPT_PCICA 1
  65. #define ZCRYPT_PCICC 2
  66. #define ZCRYPT_PCIXCC_MCL2 3
  67. #define ZCRYPT_PCIXCC_MCL3 4
  68. #define ZCRYPT_CEX2C 5
  69. #define ZCRYPT_CEX2A 6
  70. #define ZCRYPT_CEX3C 7
  71. #define ZCRYPT_CEX3A 8
  72. #define ZCRYPT_CEX4 10
  73. #define ZCRYPT_CEX5 11
  74. /**
  75. * Large random numbers are pulled in 4096 byte chunks from the crypto cards
  76. * and stored in a page. Be careful when increasing this buffer due to size
  77. * limitations for AP requests.
  78. */
  79. #define ZCRYPT_RNG_BUFFER_SIZE 4096
  80. /*
  81. * Identifier for Crypto Request Performance Index
  82. */
  83. enum crypto_ops {
  84. MEX_1K,
  85. MEX_2K,
  86. MEX_4K,
  87. CRT_1K,
  88. CRT_2K,
  89. CRT_4K,
  90. HWRNG,
  91. SECKEY,
  92. NUM_OPS
  93. };
  94. struct zcrypt_queue;
  95. struct zcrypt_ops {
  96. long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
  97. long (*rsa_modexpo_crt)(struct zcrypt_queue *,
  98. struct ica_rsa_modexpo_crt *);
  99. long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
  100. struct ap_message *);
  101. long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
  102. struct ap_message *);
  103. long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
  104. struct list_head list; /* zcrypt ops list. */
  105. struct module *owner;
  106. int variant;
  107. char name[128];
  108. };
  109. struct zcrypt_card {
  110. struct list_head list; /* Device list. */
  111. struct list_head zqueues; /* List of zcrypt queues */
  112. struct kref refcount; /* device refcounting */
  113. struct ap_card *card; /* The "real" ap card device. */
  114. int online; /* User online/offline */
  115. int user_space_type; /* User space device id. */
  116. char *type_string; /* User space device name. */
  117. int min_mod_size; /* Min number of bits. */
  118. int max_mod_size; /* Max number of bits. */
  119. int max_exp_bit_length;
  120. int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
  121. atomic_t load; /* Utilization of the crypto device */
  122. int request_count; /* # current requests. */
  123. };
  124. struct zcrypt_queue {
  125. struct list_head list; /* Device list. */
  126. struct kref refcount; /* device refcounting */
  127. struct zcrypt_card *zcard;
  128. struct zcrypt_ops *ops; /* Crypto operations. */
  129. struct ap_queue *queue; /* The "real" ap queue device. */
  130. int online; /* User online/offline */
  131. atomic_t load; /* Utilization of the crypto device */
  132. int request_count; /* # current requests. */
  133. struct ap_message reply; /* Per-device reply structure. */
  134. };
  135. /* transport layer rescanning */
  136. extern atomic_t zcrypt_rescan_req;
  137. extern spinlock_t zcrypt_list_lock;
  138. extern int zcrypt_device_count;
  139. extern struct list_head zcrypt_card_list;
  140. #define for_each_zcrypt_card(_zc) \
  141. list_for_each_entry(_zc, &zcrypt_card_list, list)
  142. #define for_each_zcrypt_queue(_zq, _zc) \
  143. list_for_each_entry(_zq, &(_zc)->zqueues, list)
  144. struct zcrypt_card *zcrypt_card_alloc(void);
  145. void zcrypt_card_free(struct zcrypt_card *);
  146. void zcrypt_card_get(struct zcrypt_card *);
  147. int zcrypt_card_put(struct zcrypt_card *);
  148. int zcrypt_card_register(struct zcrypt_card *);
  149. void zcrypt_card_unregister(struct zcrypt_card *);
  150. struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
  151. unsigned int, unsigned int);
  152. void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
  153. struct zcrypt_queue *zcrypt_queue_alloc(size_t);
  154. void zcrypt_queue_free(struct zcrypt_queue *);
  155. void zcrypt_queue_get(struct zcrypt_queue *);
  156. int zcrypt_queue_put(struct zcrypt_queue *);
  157. int zcrypt_queue_register(struct zcrypt_queue *);
  158. void zcrypt_queue_unregister(struct zcrypt_queue *);
  159. void zcrypt_queue_force_online(struct zcrypt_queue *, int);
  160. struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
  161. void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
  162. int zcrypt_rng_device_add(void);
  163. void zcrypt_rng_device_remove(void);
  164. void zcrypt_msgtype_register(struct zcrypt_ops *);
  165. void zcrypt_msgtype_unregister(struct zcrypt_ops *);
  166. struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
  167. int zcrypt_api_init(void);
  168. void zcrypt_api_exit(void);
  169. #endif /* _ZCRYPT_API_H_ */