zcrypt_api.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright IBM Corp. 2001, 2018
  4. * Author(s): Robert Burroughs
  5. * Eric Rossman (edrossma@us.ibm.com)
  6. * Cornelia Huck <cornelia.huck@de.ibm.com>
  7. *
  8. * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
  9. * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
  10. * Ralph Wuerthner <rwuerthn@de.ibm.com>
  11. * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
  12. */
  13. #ifndef _ZCRYPT_API_H_
  14. #define _ZCRYPT_API_H_
  15. #include <linux/atomic.h>
  16. #include <asm/debug.h>
  17. #include <asm/zcrypt.h>
  18. #include "ap_bus.h"
  19. /**
  20. * Supported device types
  21. */
  22. #define ZCRYPT_CEX2C 5
  23. #define ZCRYPT_CEX2A 6
  24. #define ZCRYPT_CEX3C 7
  25. #define ZCRYPT_CEX3A 8
  26. #define ZCRYPT_CEX4 10
  27. #define ZCRYPT_CEX5 11
  28. #define ZCRYPT_CEX6 12
  29. /**
  30. * Large random numbers are pulled in 4096 byte chunks from the crypto cards
  31. * and stored in a page. Be careful when increasing this buffer due to size
  32. * limitations for AP requests.
  33. */
  34. #define ZCRYPT_RNG_BUFFER_SIZE 4096
  35. /*
  36. * Identifier for Crypto Request Performance Index
  37. */
  38. enum crypto_ops {
  39. MEX_1K,
  40. MEX_2K,
  41. MEX_4K,
  42. CRT_1K,
  43. CRT_2K,
  44. CRT_4K,
  45. HWRNG,
  46. SECKEY,
  47. NUM_OPS
  48. };
  49. struct zcrypt_queue;
  50. struct zcrypt_ops {
  51. long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *);
  52. long (*rsa_modexpo_crt)(struct zcrypt_queue *,
  53. struct ica_rsa_modexpo_crt *);
  54. long (*send_cprb)(struct zcrypt_queue *, struct ica_xcRB *,
  55. struct ap_message *);
  56. long (*send_ep11_cprb)(struct zcrypt_queue *, struct ep11_urb *,
  57. struct ap_message *);
  58. long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
  59. struct list_head list; /* zcrypt ops list. */
  60. struct module *owner;
  61. int variant;
  62. char name[128];
  63. };
  64. struct zcrypt_card {
  65. struct list_head list; /* Device list. */
  66. struct list_head zqueues; /* List of zcrypt queues */
  67. struct kref refcount; /* device refcounting */
  68. struct ap_card *card; /* The "real" ap card device. */
  69. int online; /* User online/offline */
  70. int user_space_type; /* User space device id. */
  71. char *type_string; /* User space device name. */
  72. int min_mod_size; /* Min number of bits. */
  73. int max_mod_size; /* Max number of bits. */
  74. int max_exp_bit_length;
  75. int speed_rating[NUM_OPS]; /* Speed idx of crypto ops. */
  76. atomic_t load; /* Utilization of the crypto device */
  77. int request_count; /* # current requests. */
  78. };
  79. struct zcrypt_queue {
  80. struct list_head list; /* Device list. */
  81. struct kref refcount; /* device refcounting */
  82. struct zcrypt_card *zcard;
  83. struct zcrypt_ops *ops; /* Crypto operations. */
  84. struct ap_queue *queue; /* The "real" ap queue device. */
  85. int online; /* User online/offline */
  86. atomic_t load; /* Utilization of the crypto device */
  87. int request_count; /* # current requests. */
  88. struct ap_message reply; /* Per-device reply structure. */
  89. };
  90. /* transport layer rescanning */
  91. extern atomic_t zcrypt_rescan_req;
  92. extern spinlock_t zcrypt_list_lock;
  93. extern int zcrypt_device_count;
  94. extern struct list_head zcrypt_card_list;
  95. #define for_each_zcrypt_card(_zc) \
  96. list_for_each_entry(_zc, &zcrypt_card_list, list)
  97. #define for_each_zcrypt_queue(_zq, _zc) \
  98. list_for_each_entry(_zq, &(_zc)->zqueues, list)
  99. struct zcrypt_card *zcrypt_card_alloc(void);
  100. void zcrypt_card_free(struct zcrypt_card *);
  101. void zcrypt_card_get(struct zcrypt_card *);
  102. int zcrypt_card_put(struct zcrypt_card *);
  103. int zcrypt_card_register(struct zcrypt_card *);
  104. void zcrypt_card_unregister(struct zcrypt_card *);
  105. struct zcrypt_card *zcrypt_card_get_best(unsigned int *,
  106. unsigned int, unsigned int);
  107. void zcrypt_card_put_best(struct zcrypt_card *, unsigned int);
  108. struct zcrypt_queue *zcrypt_queue_alloc(size_t);
  109. void zcrypt_queue_free(struct zcrypt_queue *);
  110. void zcrypt_queue_get(struct zcrypt_queue *);
  111. int zcrypt_queue_put(struct zcrypt_queue *);
  112. int zcrypt_queue_register(struct zcrypt_queue *);
  113. void zcrypt_queue_unregister(struct zcrypt_queue *);
  114. void zcrypt_queue_force_online(struct zcrypt_queue *, int);
  115. struct zcrypt_queue *zcrypt_queue_get_best(unsigned int, unsigned int);
  116. void zcrypt_queue_put_best(struct zcrypt_queue *, unsigned int);
  117. int zcrypt_rng_device_add(void);
  118. void zcrypt_rng_device_remove(void);
  119. void zcrypt_msgtype_register(struct zcrypt_ops *);
  120. void zcrypt_msgtype_unregister(struct zcrypt_ops *);
  121. struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
  122. int zcrypt_api_init(void);
  123. void zcrypt_api_exit(void);
  124. long zcrypt_send_cprb(struct ica_xcRB *xcRB);
  125. void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
  126. #endif /* _ZCRYPT_API_H_ */