zcrypt_api.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #ifndef _ZCRYPT_API_H_
  16. #define _ZCRYPT_API_H_
  17. #include <linux/atomic.h>
  18. #include <asm/debug.h>
  19. #include <asm/zcrypt.h>
  20. #include "ap_bus.h"
  21. /**
  22. * device type for an actual device is either PCICA, PCICC, PCIXCC_MCL2,
  23. * PCIXCC_MCL3, CEX2C, or CEX2A
  24. *
  25. * NOTE: PCIXCC_MCL3 refers to a PCIXCC with May 2004 version of Licensed
  26. * Internal Code (LIC) (EC J12220 level 29).
  27. * PCIXCC_MCL2 refers to any LIC before this level.
  28. */
  29. #define ZCRYPT_PCICA 1
  30. #define ZCRYPT_PCICC 2
  31. #define ZCRYPT_PCIXCC_MCL2 3
  32. #define ZCRYPT_PCIXCC_MCL3 4
  33. #define ZCRYPT_CEX2C 5
  34. #define ZCRYPT_CEX2A 6
  35. #define ZCRYPT_CEX3C 7
  36. #define ZCRYPT_CEX3A 8
  37. #define ZCRYPT_CEX4 10
  38. #define ZCRYPT_CEX5 11
  39. #define ZCRYPT_CEX6 12
  40. /**
  41. * Large random numbers are pulled in 4096 byte chunks from the crypto cards
  42. * and stored in a page. Be careful when increasing this buffer due to size
  43. * limitations for AP requests.
  44. */
  45. #define ZCRYPT_RNG_BUFFER_SIZE 4096
  46. /*
  47. * Identifier for Crypto Request Performance Index
  48. */
  49. enum crypto_ops {
  50. MEX_1K,
  51. MEX_2K,
  52. MEX_4K,
  53. CRT_1K,
  54. CRT_2K,
  55. CRT_4K,
  56. HWRNG,
  57. SECKEY,
  58. NUM_OPS
  59. };
  60. struct zcrypt_queue;
  61. struct zcrypt_ops {
  62. long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
  63. long (*rsa_modexpo_crt)(struct zcrypt_queue *,
  64. struct ica_rsa_modexpo_crt *);
  65. long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
  66. struct ap_message *);
  67. long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
  68. struct ap_message *);
  69. long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
  70. struct list_head list; /* zcrypt ops list. */
  71. struct module *owner;
  72. int variant;
  73. char name[128];
  74. };
  75. struct zcrypt_card {
  76. struct list_head list; /* Device list. */
  77. struct list_head zqueues; /* List of zcrypt queues */
  78. struct kref refcount; /* device refcounting */
  79. struct ap_card *card; /* The "real" ap card device. */
  80. int online; /* User online/offline */
  81. int user_space_type; /* User space device id. */
  82. char *type_string; /* User space device name. */
  83. int min_mod_size; /* Min number of bits. */
  84. int max_mod_size; /* Max number of bits. */
  85. int max_exp_bit_length;
  86. int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
  87. atomic_t load; /* Utilization of the crypto device */
  88. int request_count; /* # current requests. */
  89. };
  90. struct zcrypt_queue {
  91. struct list_head list; /* Device list. */
  92. struct kref refcount; /* device refcounting */
  93. struct zcrypt_card *zcard;
  94. struct zcrypt_ops *ops; /* Crypto operations. */
  95. struct ap_queue *queue; /* The "real" ap queue device. */
  96. int online; /* User online/offline */
  97. atomic_t load; /* Utilization of the crypto device */
  98. int request_count; /* # current requests. */
  99. struct ap_message reply; /* Per-device reply structure. */
  100. };
  101. /* transport layer rescanning */
  102. extern atomic_t zcrypt_rescan_req;
  103. extern spinlock_t zcrypt_list_lock;
  104. extern int zcrypt_device_count;
  105. extern struct list_head zcrypt_card_list;
  106. #define for_each_zcrypt_card(_zc) \
  107. list_for_each_entry(_zc, &zcrypt_card_list, list)
  108. #define for_each_zcrypt_queue(_zq, _zc) \
  109. list_for_each_entry(_zq, &(_zc)->zqueues, list)
  110. struct zcrypt_card *zcrypt_card_alloc(void);
  111. void zcrypt_card_free(struct zcrypt_card *);
  112. void zcrypt_card_get(struct zcrypt_card *);
  113. int zcrypt_card_put(struct zcrypt_card *);
  114. int zcrypt_card_register(struct zcrypt_card *);
  115. void zcrypt_card_unregister(struct zcrypt_card *);
  116. struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
  117. unsigned int, unsigned int);
  118. void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
  119. struct zcrypt_queue *zcrypt_queue_alloc(size_t);
  120. void zcrypt_queue_free(struct zcrypt_queue *);
  121. void zcrypt_queue_get(struct zcrypt_queue *);
  122. int zcrypt_queue_put(struct zcrypt_queue *);
  123. int zcrypt_queue_register(struct zcrypt_queue *);
  124. void zcrypt_queue_unregister(struct zcrypt_queue *);
  125. void zcrypt_queue_force_online(struct zcrypt_queue *, int);
  126. struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
  127. void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
  128. int zcrypt_rng_device_add(void);
  129. void zcrypt_rng_device_remove(void);
  130. void zcrypt_msgtype_register(struct zcrypt_ops *);
  131. void zcrypt_msgtype_unregister(struct zcrypt_ops *);
  132. struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
  133. int zcrypt_api_init(void);
  134. void zcrypt_api_exit(void);
  135. long zcrypt_send_cprb(struct ica_xcRB *xcRB);
  136. void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
  137. #endif /* _ZCRYPT_API_H_ */