zcrypt_api.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. struct zcrypt_device;
  81. struct zcrypt_ops {
  82. long (*rsa_modexpo)(struct zcrypt_device *, struct ica_rsa_modexpo *);
  83. long (*rsa_modexpo_crt)(struct zcrypt_device *,
  84. struct ica_rsa_modexpo_crt *);
  85. long (*send_cprb)(struct zcrypt_device *, struct ica_xcRB *);
  86. long (*send_ep11_cprb)(struct zcrypt_device *, struct ep11_urb *);
  87. long (*rng)(struct zcrypt_device *, char *);
  88. struct list_head list; /* zcrypt ops list. */
  89. struct module *owner;
  90. int variant;
  91. char name[128];
  92. };
  93. struct zcrypt_device {
  94. struct list_head list; /* Device list. */
  95. spinlock_t lock; /* Per device lock. */
  96. struct kref refcount; /* device refcounting */
  97. struct ap_device *ap_dev; /* The "real" ap device. */
  98. struct zcrypt_ops *ops; /* Crypto operations. */
  99. int online; /* User online/offline */
  100. int user_space_type; /* User space device id. */
  101. char *type_string; /* User space device name. */
  102. int min_mod_size; /* Min number of bits. */
  103. int max_mod_size; /* Max number of bits. */
  104. int short_crt; /* Card has crt length restriction. */
  105. int speed_rating; /* Speed of the crypto device. */
  106. int request_count; /* # current requests. */
  107. struct ap_message reply; /* Per-device reply structure. */
  108. int max_exp_bit_length;
  109. debug_info_t *dbf_area; /* debugging */
  110. };
  111. /* transport layer rescanning */
  112. extern atomic_t zcrypt_rescan_req;
  113. struct zcrypt_device *zcrypt_device_alloc(size_t);
  114. void zcrypt_device_free(struct zcrypt_device *);
  115. void zcrypt_device_get(struct zcrypt_device *);
  116. int zcrypt_device_put(struct zcrypt_device *);
  117. int zcrypt_device_register(struct zcrypt_device *);
  118. void zcrypt_device_unregister(struct zcrypt_device *);
  119. void zcrypt_msgtype_register(struct zcrypt_ops *);
  120. void zcrypt_msgtype_unregister(struct zcrypt_ops *);
  121. struct zcrypt_ops *zcrypt_msgtype_request(unsigned char *, int);
  122. void zcrypt_msgtype_release(struct zcrypt_ops *);
  123. int zcrypt_api_init(void);
  124. void zcrypt_api_exit(void);
  125. #endif /* _ZCRYPT_API_H_ */