qcedev.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #ifndef __QCEDEV__H
  2. #define __QCEDEV__H
  3. #include <linux/types.h>
  4. #include <linux/ioctl.h>
  5. #include "fips_status.h"
  6. #define QCEDEV_MAX_SHA_BLOCK_SIZE 64
  7. #define QCEDEV_MAX_BEARER 31
  8. #define QCEDEV_MAX_KEY_SIZE 64
  9. #define QCEDEV_MAX_IV_SIZE 32
  10. #define QCEDEV_MAX_BUFFERS 16
  11. #define QCEDEV_MAX_SHA_DIGEST 32
  12. #define QCEDEV_USE_PMEM 1
  13. #define QCEDEV_NO_PMEM 0
  14. #define QCEDEV_AES_KEY_128 16
  15. #define QCEDEV_AES_KEY_192 24
  16. #define QCEDEV_AES_KEY_256 32
  17. /**
  18. *qcedev_oper_enum: Operation types
  19. * @QCEDEV_OPER_ENC: Encrypt
  20. * @QCEDEV_OPER_DEC: Decrypt
  21. * @QCEDEV_OPER_ENC_NO_KEY: Encrypt. Do not need key to be specified by
  22. * user. Key already set by an external processor.
  23. * @QCEDEV_OPER_DEC_NO_KEY: Decrypt. Do not need the key to be specified by
  24. * user. Key already set by an external processor.
  25. */
  26. enum qcedev_oper_enum {
  27. QCEDEV_OPER_DEC = 0,
  28. QCEDEV_OPER_ENC = 1,
  29. QCEDEV_OPER_DEC_NO_KEY = 2,
  30. QCEDEV_OPER_ENC_NO_KEY = 3,
  31. QCEDEV_OPER_LAST
  32. };
  33. /**
  34. *qcedev_oper_enum: Cipher algorithm types
  35. * @QCEDEV_ALG_DES: DES
  36. * @QCEDEV_ALG_3DES: 3DES
  37. * @QCEDEV_ALG_AES: AES
  38. */
  39. enum qcedev_cipher_alg_enum {
  40. QCEDEV_ALG_DES = 0,
  41. QCEDEV_ALG_3DES = 1,
  42. QCEDEV_ALG_AES = 2,
  43. QCEDEV_ALG_LAST
  44. };
  45. /**
  46. *qcedev_cipher_mode_enum : AES mode
  47. * @QCEDEV_AES_MODE_CBC: CBC
  48. * @QCEDEV_AES_MODE_ECB: ECB
  49. * @QCEDEV_AES_MODE_CTR: CTR
  50. * @QCEDEV_AES_MODE_XTS: XTS
  51. * @QCEDEV_AES_MODE_CCM: CCM
  52. * @QCEDEV_DES_MODE_CBC: CBC
  53. * @QCEDEV_DES_MODE_ECB: ECB
  54. */
  55. enum qcedev_cipher_mode_enum {
  56. QCEDEV_AES_MODE_CBC = 0,
  57. QCEDEV_AES_MODE_ECB = 1,
  58. QCEDEV_AES_MODE_CTR = 2,
  59. QCEDEV_AES_MODE_XTS = 3,
  60. QCEDEV_AES_MODE_CCM = 4,
  61. QCEDEV_DES_MODE_CBC = 5,
  62. QCEDEV_DES_MODE_ECB = 6,
  63. QCEDEV_AES_DES_MODE_LAST
  64. };
  65. /**
  66. *enum qcedev_sha_alg_enum : Secure Hashing Algorithm
  67. * @QCEDEV_ALG_SHA1: Digest returned: 20 bytes (160 bits)
  68. * @QCEDEV_ALG_SHA256: Digest returned: 32 bytes (256 bit)
  69. * @QCEDEV_ALG_SHA1_HMAC: HMAC returned 20 bytes (160 bits)
  70. * @QCEDEV_ALG_SHA256_HMAC: HMAC returned 32 bytes (256 bit)
  71. * @QCEDEV_ALG_AES_CMAC: Configurable MAC size
  72. */
  73. enum qcedev_sha_alg_enum {
  74. QCEDEV_ALG_SHA1 = 0,
  75. QCEDEV_ALG_SHA256 = 1,
  76. QCEDEV_ALG_SHA1_HMAC = 2,
  77. QCEDEV_ALG_SHA256_HMAC = 3,
  78. QCEDEV_ALG_AES_CMAC = 4,
  79. QCEDEV_ALG_SHA_ALG_LAST
  80. };
  81. /**
  82. * struct buf_info - Buffer information
  83. * @offset: Offset from the base address of the buffer
  84. * (Used when buffer is allocated using PMEM)
  85. * @vaddr: Virtual buffer address pointer
  86. * @len: Size of the buffer
  87. */
  88. struct buf_info {
  89. union {
  90. uint32_t offset;
  91. uint8_t *vaddr;
  92. };
  93. uint32_t len;
  94. };
  95. /**
  96. * struct qcedev_vbuf_info - Source and destination Buffer information
  97. * @src: Array of buf_info for input/source
  98. * @dst: Array of buf_info for output/destination
  99. */
  100. struct qcedev_vbuf_info {
  101. struct buf_info src[QCEDEV_MAX_BUFFERS];
  102. struct buf_info dst[QCEDEV_MAX_BUFFERS];
  103. };
  104. /**
  105. * struct qcedev_pmem_info - Stores PMEM buffer information
  106. * @fd_src: Handle to /dev/adsp_pmem used to allocate
  107. * memory for input/src buffer
  108. * @src: Array of buf_info for input/source
  109. * @fd_dst: Handle to /dev/adsp_pmem used to allocate
  110. * memory for output/dst buffer
  111. * @dst: Array of buf_info for output/destination
  112. * @pmem_src_offset: The offset from input/src buffer
  113. * (allocated by PMEM)
  114. */
  115. struct qcedev_pmem_info {
  116. int fd_src;
  117. struct buf_info src[QCEDEV_MAX_BUFFERS];
  118. int fd_dst;
  119. struct buf_info dst[QCEDEV_MAX_BUFFERS];
  120. };
  121. /**
  122. * struct qcedev_cipher_op_req - Holds the ciphering request information
  123. * @use_pmem (IN): Flag to indicate if buffer source is PMEM
  124. * QCEDEV_USE_PMEM/QCEDEV_NO_PMEM
  125. * @pmem (IN): Stores PMEM buffer information.
  126. * Refer struct qcedev_pmem_info
  127. * @vbuf (IN/OUT): Stores Source and destination Buffer information
  128. * Refer to struct qcedev_vbuf_info
  129. * @data_len (IN): Total Length of input/src and output/dst in bytes
  130. * @in_place_op (IN): Indicates whether the operation is inplace where
  131. * source == destination
  132. * When using PMEM allocated memory, must set this to 1
  133. * @enckey (IN): 128 bits of confidentiality key
  134. * enckey[0] bit 127-120, enckey[1] bit 119-112,..
  135. * enckey[15] bit 7-0
  136. * @encklen (IN): Length of the encryption key(set to 128 bits/16
  137. * bytes in the driver)
  138. * @iv (IN/OUT): Initialisation vector data
  139. * This is updated by the driver, incremented by
  140. * number of blocks encrypted/decrypted.
  141. * @ivlen (IN): Length of the IV
  142. * @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
  143. * for AES-128 CTR mode only)
  144. * @alg (IN): Type of ciphering algorithm: AES/DES/3DES
  145. * @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR
  146. * Apllicabel when using AES algorithm only
  147. * @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or
  148. * QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY
  149. *
  150. *If use_pmem is set to 0, the driver assumes that memory was not allocated
  151. * via PMEM, and kernel will need to allocate memory and copy data from user
  152. * space buffer (data_src/dta_dst) and process accordingly and copy data back
  153. * to the user space buffer
  154. *
  155. * If use_pmem is set to 1, the driver assumes that memory was allocated via
  156. * PMEM.
  157. * The kernel driver will use the fd_src to determine the kernel virtual address
  158. * base that maps to the user space virtual address base for the buffer
  159. * allocated in user space.
  160. * The final input/src and output/dst buffer pointer will be determined
  161. * by adding the offsets to the kernel virtual addr.
  162. *
  163. * If use of hardware key is supported in the target, user can configure the
  164. * key paramters (encklen, enckey) to use the hardware key.
  165. * In order to use the hardware key, set encklen to 0 and set the enckey
  166. * data array to 0.
  167. */
  168. struct qcedev_cipher_op_req {
  169. uint8_t use_pmem;
  170. union {
  171. struct qcedev_pmem_info pmem;
  172. struct qcedev_vbuf_info vbuf;
  173. };
  174. uint32_t entries;
  175. uint32_t data_len;
  176. uint8_t in_place_op;
  177. uint8_t enckey[QCEDEV_MAX_KEY_SIZE];
  178. uint32_t encklen;
  179. uint8_t iv[QCEDEV_MAX_IV_SIZE];
  180. uint32_t ivlen;
  181. uint32_t byteoffset;
  182. enum qcedev_cipher_alg_enum alg;
  183. enum qcedev_cipher_mode_enum mode;
  184. enum qcedev_oper_enum op;
  185. };
  186. /**
  187. * struct qcedev_sha_op_req - Holds the hashing request information
  188. * @data (IN): Array of pointers to the data to be hashed
  189. * @entries (IN): Number of buf_info entries in the data array
  190. * @data_len (IN): Length of data to be hashed
  191. * @digest (IN/OUT): Returns the hashed data information
  192. * @diglen (OUT): Size of the hashed/digest data
  193. * @authkey (IN): Pointer to authentication key for HMAC
  194. * @authklen (IN): Size of the authentication key
  195. * @alg (IN): Secure Hash algorithm
  196. */
  197. struct qcedev_sha_op_req {
  198. struct buf_info data[QCEDEV_MAX_BUFFERS];
  199. uint32_t entries;
  200. uint32_t data_len;
  201. uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
  202. uint32_t diglen;
  203. uint8_t *authkey;
  204. uint32_t authklen;
  205. enum qcedev_sha_alg_enum alg;
  206. };
  207. /**
  208. * struct qfips_verify_t - Holds data for FIPS Integrity test
  209. * @kernel_size (IN): Size of kernel Image
  210. * @kernel (IN): pointer to buffer containing the kernel Image
  211. */
  212. struct qfips_verify_t {
  213. unsigned kernel_size;
  214. void *kernel;
  215. };
  216. #define QCEDEV_IOC_MAGIC 0x87
  217. #define QCEDEV_IOCTL_ENC_REQ \
  218. _IOWR(QCEDEV_IOC_MAGIC, 1, struct qcedev_cipher_op_req)
  219. #define QCEDEV_IOCTL_DEC_REQ \
  220. _IOWR(QCEDEV_IOC_MAGIC, 2, struct qcedev_cipher_op_req)
  221. #define QCEDEV_IOCTL_SHA_INIT_REQ \
  222. _IOWR(QCEDEV_IOC_MAGIC, 3, struct qcedev_sha_op_req)
  223. #define QCEDEV_IOCTL_SHA_UPDATE_REQ \
  224. _IOWR(QCEDEV_IOC_MAGIC, 4, struct qcedev_sha_op_req)
  225. #define QCEDEV_IOCTL_SHA_FINAL_REQ \
  226. _IOWR(QCEDEV_IOC_MAGIC, 5, struct qcedev_sha_op_req)
  227. #define QCEDEV_IOCTL_GET_SHA_REQ \
  228. _IOWR(QCEDEV_IOC_MAGIC, 6, struct qcedev_sha_op_req)
  229. #define QCEDEV_IOCTL_LOCK_CE \
  230. _IO(QCEDEV_IOC_MAGIC, 7)
  231. #define QCEDEV_IOCTL_UNLOCK_CE \
  232. _IO(QCEDEV_IOC_MAGIC, 8)
  233. #define QCEDEV_IOCTL_GET_CMAC_REQ \
  234. _IOWR(QCEDEV_IOC_MAGIC, 9, struct qcedev_cipher_op_req)
  235. #define QCEDEV_IOCTL_UPDATE_FIPS_STATUS \
  236. _IOWR(QCEDEV_IOC_MAGIC, 10, enum fips_status)
  237. #define QCEDEV_IOCTL_QUERY_FIPS_STATUS \
  238. _IOR(QCEDEV_IOC_MAGIC, 11, enum fips_status)
  239. #endif /* _QCEDEV__H */