qcedev.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2019, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _UAPI_QCEDEV__H
  7. #define _UAPI_QCEDEV__H
  8. #include <linux/types.h>
  9. #include <linux/ioctl.h>
  10. #define QCEDEV_MAX_SHA_BLOCK_SIZE 64
  11. #define QCEDEV_MAX_BEARER 31
  12. #define QCEDEV_MAX_KEY_SIZE 64
  13. #define QCEDEV_MAX_IV_SIZE 32
  14. #define QCEDEV_MAX_BUFFERS 16
  15. #define QCEDEV_MAX_SHA_DIGEST 32
  16. #define QCEDEV_USE_PMEM 1
  17. #define QCEDEV_NO_PMEM 0
  18. #define QCEDEV_AES_KEY_128 16
  19. #define QCEDEV_AES_KEY_192 24
  20. #define QCEDEV_AES_KEY_256 32
  21. /**
  22. *qcedev_oper_enum: Operation types
  23. * @QCEDEV_OPER_ENC: Encrypt
  24. * @QCEDEV_OPER_DEC: Decrypt
  25. * @QCEDEV_OPER_ENC_NO_KEY: Encrypt. Do not need key to be specified by
  26. * user. Key already set by an external processor.
  27. * @QCEDEV_OPER_DEC_NO_KEY: Decrypt. Do not need the key to be specified by
  28. * user. Key already set by an external processor.
  29. */
  30. enum qcedev_oper_enum {
  31. QCEDEV_OPER_DEC = 0,
  32. QCEDEV_OPER_ENC = 1,
  33. QCEDEV_OPER_DEC_NO_KEY = 2,
  34. QCEDEV_OPER_ENC_NO_KEY = 3,
  35. QCEDEV_OPER_LAST
  36. };
  37. /**
  38. *qcedev_offload_oper_enum: Offload operation types (uses pipe keys)
  39. * @QCEDEV_OFFLOAD_HLOS_HLOS: Non-secure to non-secure (eg. audio dec).
  40. * @QCEDEV_OFFLOAD_HLOS_CPB: Non-secure to secure (eg. video dec).
  41. * @QCEDEV_OFFLOAD_CPB_HLOS: Secure to non-secure (eg. hdcp video enc).
  42. */
  43. enum qcedev_offload_oper_enum {
  44. QCEDEV_OFFLOAD_HLOS_HLOS = 1,
  45. QCEDEV_OFFLOAD_HLOS_HLOS_1 = 2,
  46. QCEDEV_OFFLOAD_HLOS_CPB = 3,
  47. QCEDEV_OFFLOAD_HLOS_CPB_1 = 4,
  48. QCEDEV_OFFLOAD_CPB_HLOS = 5,
  49. QCEDEV_OFFLOAD_OPER_LAST
  50. };
  51. /**
  52. *qcedev_offload_err_enum: Offload error conditions
  53. * @QCEDEV_OFFLOAD_NO_ERROR: Successful crypto operation.
  54. * @QCEDEV_OFFLOAD_GENERIC_ERROR: Generic error in crypto status.
  55. * @QCEDEV_OFFLOAD_TIMER_EXPIRED_ERROR: Pipe key timer expired.
  56. * @QCEDEV_OFFLOAD_KEY_PAUSE_ERROR: Pipe key pause (means GPCE is paused).
  57. */
  58. enum qcedev_offload_err_enum {
  59. QCEDEV_OFFLOAD_NO_ERROR = 0,
  60. QCEDEV_OFFLOAD_GENERIC_ERROR = 1,
  61. QCEDEV_OFFLOAD_KEY_TIMER_EXPIRED_ERROR = 2,
  62. QCEDEV_OFFLOAD_KEY_PAUSE_ERROR = 3
  63. };
  64. /**
  65. *qcedev_oper_enum: Cipher algorithm types
  66. * @QCEDEV_ALG_DES: DES
  67. * @QCEDEV_ALG_3DES: 3DES
  68. * @QCEDEV_ALG_AES: AES
  69. */
  70. enum qcedev_cipher_alg_enum {
  71. QCEDEV_ALG_DES = 0,
  72. QCEDEV_ALG_3DES = 1,
  73. QCEDEV_ALG_AES = 2,
  74. QCEDEV_ALG_LAST
  75. };
  76. /**
  77. *qcedev_cipher_mode_enum : AES mode
  78. * @QCEDEV_AES_MODE_CBC: CBC
  79. * @QCEDEV_AES_MODE_ECB: ECB
  80. * @QCEDEV_AES_MODE_CTR: CTR
  81. * @QCEDEV_AES_MODE_XTS: XTS
  82. * @QCEDEV_AES_MODE_CCM: CCM
  83. * @QCEDEV_DES_MODE_CBC: CBC
  84. * @QCEDEV_DES_MODE_ECB: ECB
  85. */
  86. enum qcedev_cipher_mode_enum {
  87. QCEDEV_AES_MODE_CBC = 0,
  88. QCEDEV_AES_MODE_ECB = 1,
  89. QCEDEV_AES_MODE_CTR = 2,
  90. QCEDEV_AES_MODE_XTS = 3,
  91. QCEDEV_AES_MODE_CCM = 4,
  92. QCEDEV_DES_MODE_CBC = 5,
  93. QCEDEV_DES_MODE_ECB = 6,
  94. QCEDEV_AES_DES_MODE_LAST
  95. };
  96. /**
  97. *enum qcedev_sha_alg_enum : Secure Hashing Algorithm
  98. * @QCEDEV_ALG_SHA1: Digest returned: 20 bytes (160 bits)
  99. * @QCEDEV_ALG_SHA256: Digest returned: 32 bytes (256 bit)
  100. * @QCEDEV_ALG_SHA1_HMAC: HMAC returned 20 bytes (160 bits)
  101. * @QCEDEV_ALG_SHA256_HMAC: HMAC returned 32 bytes (256 bit)
  102. * @QCEDEV_ALG_AES_CMAC: Configurable MAC size
  103. */
  104. enum qcedev_sha_alg_enum {
  105. QCEDEV_ALG_SHA1 = 0,
  106. QCEDEV_ALG_SHA256 = 1,
  107. QCEDEV_ALG_SHA1_HMAC = 2,
  108. QCEDEV_ALG_SHA256_HMAC = 3,
  109. QCEDEV_ALG_AES_CMAC = 4,
  110. QCEDEV_ALG_SHA_ALG_LAST
  111. };
  112. /**
  113. * struct buf_info - Buffer information
  114. * @offset: Offset from the base address of the buffer
  115. * (Used when buffer is allocated using PMEM)
  116. * @vaddr: Virtual buffer address pointer
  117. * @len: Size of the buffer
  118. */
  119. struct buf_info {
  120. union {
  121. __u32 offset;
  122. __u8 *vaddr;
  123. };
  124. __u32 len;
  125. };
  126. /**
  127. * struct qcedev_vbuf_info - Source and destination Buffer information
  128. * @src: Array of buf_info for input/source
  129. * @dst: Array of buf_info for output/destination
  130. */
  131. struct qcedev_vbuf_info {
  132. struct buf_info src[QCEDEV_MAX_BUFFERS];
  133. struct buf_info dst[QCEDEV_MAX_BUFFERS];
  134. };
  135. /**
  136. * struct qcedev_pmem_info - Stores PMEM buffer information
  137. * @fd_src: Handle to /dev/adsp_pmem used to allocate
  138. * memory for input/src buffer
  139. * @src: Array of buf_info for input/source
  140. * @fd_dst: Handle to /dev/adsp_pmem used to allocate
  141. * memory for output/dst buffer
  142. * @dst: Array of buf_info for output/destination
  143. * @pmem_src_offset: The offset from input/src buffer
  144. * (allocated by PMEM)
  145. */
  146. struct qcedev_pmem_info {
  147. int fd_src;
  148. struct buf_info src[QCEDEV_MAX_BUFFERS];
  149. int fd_dst;
  150. struct buf_info dst[QCEDEV_MAX_BUFFERS];
  151. };
  152. /**
  153. * struct qcedev_cipher_op_req - Holds the ciphering request information
  154. * @use_pmem (IN): Flag to indicate if buffer source is PMEM
  155. * QCEDEV_USE_PMEM/QCEDEV_NO_PMEM
  156. * @pmem (IN): Stores PMEM buffer information.
  157. * Refer struct qcedev_pmem_info
  158. * @vbuf (IN/OUT): Stores Source and destination Buffer information
  159. * Refer to struct qcedev_vbuf_info
  160. * @data_len (IN): Total Length of input/src and output/dst in bytes
  161. * @in_place_op (IN): Indicates whether the operation is inplace where
  162. * source == destination
  163. * When using PMEM allocated memory, must set this to 1
  164. * @enckey (IN): 128 bits of confidentiality key
  165. * enckey[0] bit 127-120, enckey[1] bit 119-112,..
  166. * enckey[15] bit 7-0
  167. * @encklen (IN): Length of the encryption key(set to 128 bits/16
  168. * bytes in the driver)
  169. * @iv (IN/OUT): Initialisation vector data
  170. * This is updated by the driver, incremented by
  171. * number of blocks encrypted/decrypted.
  172. * @ivlen (IN): Length of the IV
  173. * @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
  174. * for AES-128 CTR mode only)
  175. * @alg (IN): Type of ciphering algorithm: AES/DES/3DES
  176. * @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR
  177. * Apllicabel when using AES algorithm only
  178. * @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or
  179. * QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY
  180. *
  181. *If use_pmem is set to 0, the driver assumes that memory was not allocated
  182. * via PMEM, and kernel will need to allocate memory and copy data from user
  183. * space buffer (data_src/dta_dst) and process accordingly and copy data back
  184. * to the user space buffer
  185. *
  186. * If use_pmem is set to 1, the driver assumes that memory was allocated via
  187. * PMEM.
  188. * The kernel driver will use the fd_src to determine the kernel virtual address
  189. * base that maps to the user space virtual address base for the buffer
  190. * allocated in user space.
  191. * The final input/src and output/dst buffer pointer will be determined
  192. * by adding the offsets to the kernel virtual addr.
  193. *
  194. * If use of hardware key is supported in the target, user can configure the
  195. * key parameters (encklen, enckey) to use the hardware key.
  196. * In order to use the hardware key, set encklen to 0 and set the enckey
  197. * data array to 0.
  198. */
  199. struct qcedev_cipher_op_req {
  200. __u8 use_pmem;
  201. union {
  202. struct qcedev_pmem_info pmem;
  203. struct qcedev_vbuf_info vbuf;
  204. };
  205. __u32 entries;
  206. __u32 data_len;
  207. __u8 in_place_op;
  208. __u8 enckey[QCEDEV_MAX_KEY_SIZE];
  209. __u32 encklen;
  210. __u8 iv[QCEDEV_MAX_IV_SIZE];
  211. __u32 ivlen;
  212. __u32 byteoffset;
  213. enum qcedev_cipher_alg_enum alg;
  214. enum qcedev_cipher_mode_enum mode;
  215. enum qcedev_oper_enum op;
  216. };
  217. /**
  218. * struct qcedev_sha_op_req - Holds the hashing request information
  219. * @data (IN): Array of pointers to the data to be hashed
  220. * @entries (IN): Number of buf_info entries in the data array
  221. * @data_len (IN): Length of data to be hashed
  222. * @digest (IN/OUT): Returns the hashed data information
  223. * @diglen (OUT): Size of the hashed/digest data
  224. * @authkey (IN): Pointer to authentication key for HMAC
  225. * @authklen (IN): Size of the authentication key
  226. * @alg (IN): Secure Hash algorithm
  227. */
  228. struct qcedev_sha_op_req {
  229. struct buf_info data[QCEDEV_MAX_BUFFERS];
  230. __u32 entries;
  231. __u32 data_len;
  232. __u8 digest[QCEDEV_MAX_SHA_DIGEST];
  233. __u32 diglen;
  234. __u8 *authkey;
  235. __u32 authklen;
  236. enum qcedev_sha_alg_enum alg;
  237. };
  238. /**
  239. * struct pattern_info - Holds pattern information for pattern-based
  240. * decryption/encryption for AES ECB, counter, and CBC modes.
  241. * @patt_sz (IN): Total number of blocks.
  242. * @proc_data_sz (IN): Number of blocks to be processed.
  243. * @patt_offset (IN): Start of the segment.
  244. */
  245. struct pattern_info {
  246. __u8 patt_sz;
  247. __u8 proc_data_sz;
  248. __u8 patt_offset;
  249. };
  250. /**
  251. * struct qcedev_offload_cipher_op_req - Holds the offload request information
  252. * @vbuf (IN/OUT): Stores Source and destination Buffer information.
  253. * Refer to struct qcedev_vbuf_info.
  254. * @entries (IN): Number of entries to be processed as part of request.
  255. * @data_len (IN): Total Length of input/src and output/dst in bytes
  256. * @in_place_op (IN): Indicates whether the operation is inplace where
  257. * source == destination.
  258. * @encklen (IN): Length of the encryption key(set to 128 bits/16
  259. * bytes in the driver).
  260. * @iv (IN/OUT): Initialisation vector data
  261. * This is updated by the driver, incremented by
  262. * number of blocks encrypted/decrypted.
  263. * @ivlen (IN): Length of the IV.
  264. * @iv_ctr_size (IN): IV counter increment mask size.
  265. * Driver sets the mask value based on this size.
  266. * @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
  267. * for AES-128 CTR mode only).
  268. * @block_offset (IN): Offset in the block that needs a skip of encrypt/
  269. * decrypt.
  270. * @pattern_valid (IN): Indicates the request contains a valid pattern.
  271. * @pattern_info (IN): The pattern to be used for the offload request.
  272. * @is_copy_op (IN): Offload operations sometimes requires a copy between
  273. * secure and non-secure buffers without any encrypt/
  274. * decrypt operations.
  275. * @alg (IN): Type of ciphering algorithm: AES/DES/3DES.
  276. * @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR.
  277. * Applicable when using AES algorithm only.
  278. * @op (IN): Type of operation.
  279. * Refer to qcedev_offload_oper_enum.
  280. * @err (OUT): Error in crypto status.
  281. * Refer to qcedev_offload_err_enum.
  282. */
  283. struct qcedev_offload_cipher_op_req {
  284. struct qcedev_vbuf_info vbuf;
  285. __u32 entries;
  286. __u32 data_len;
  287. __u32 in_place_op;
  288. __u32 encklen;
  289. __u8 iv[QCEDEV_MAX_IV_SIZE];
  290. __u32 ivlen;
  291. __u32 iv_ctr_size;
  292. __u32 byteoffset;
  293. __u8 block_offset;
  294. __u8 is_pattern_valid;
  295. __u8 is_copy_op;
  296. __u8 encrypt;
  297. struct pattern_info pattern_info;
  298. enum qcedev_cipher_alg_enum alg;
  299. enum qcedev_cipher_mode_enum mode;
  300. enum qcedev_offload_oper_enum op;
  301. enum qcedev_offload_err_enum err;
  302. };
  303. /**
  304. * struct qfips_verify_t - Holds data for FIPS Integrity test
  305. * @kernel_size (IN): Size of kernel Image
  306. * @kernel (IN): pointer to buffer containing the kernel Image
  307. */
  308. struct qfips_verify_t {
  309. unsigned int kernel_size;
  310. void *kernel;
  311. };
  312. /**
  313. * struct qcedev_map_buf_req - Holds the mapping request information
  314. * fd (IN): Array of fds.
  315. * num_fds (IN): Number of fds in fd[].
  316. * fd_size (IN): Array of sizes corresponding to each fd in fd[].
  317. * fd_offset (IN): Array of offset corresponding to each fd in fd[].
  318. * vaddr (OUT): Array of mapped virtual address corresponding to
  319. * each fd in fd[].
  320. */
  321. struct qcedev_map_buf_req {
  322. __s32 fd[QCEDEV_MAX_BUFFERS];
  323. __u32 num_fds;
  324. __u32 fd_size[QCEDEV_MAX_BUFFERS];
  325. __u32 fd_offset[QCEDEV_MAX_BUFFERS];
  326. __u64 buf_vaddr[QCEDEV_MAX_BUFFERS];
  327. };
  328. /**
  329. * struct qcedev_unmap_buf_req - Holds the hashing request information
  330. * fd (IN): Array of fds to unmap
  331. * num_fds (IN): Number of fds in fd[].
  332. */
  333. struct qcedev_unmap_buf_req {
  334. __s32 fd[QCEDEV_MAX_BUFFERS];
  335. __u32 num_fds;
  336. };
  337. struct file;
  338. long qcedev_ioctl(struct file *file,
  339. unsigned int cmd, unsigned long arg);
  340. #define QCEDEV_IOC_MAGIC 0x87
  341. #define QCEDEV_IOCTL_ENC_REQ \
  342. _IOWR(QCEDEV_IOC_MAGIC, 1, struct qcedev_cipher_op_req)
  343. #define QCEDEV_IOCTL_DEC_REQ \
  344. _IOWR(QCEDEV_IOC_MAGIC, 2, struct qcedev_cipher_op_req)
  345. #define QCEDEV_IOCTL_SHA_INIT_REQ \
  346. _IOWR(QCEDEV_IOC_MAGIC, 3, struct qcedev_sha_op_req)
  347. #define QCEDEV_IOCTL_SHA_UPDATE_REQ \
  348. _IOWR(QCEDEV_IOC_MAGIC, 4, struct qcedev_sha_op_req)
  349. #define QCEDEV_IOCTL_SHA_FINAL_REQ \
  350. _IOWR(QCEDEV_IOC_MAGIC, 5, struct qcedev_sha_op_req)
  351. #define QCEDEV_IOCTL_GET_SHA_REQ \
  352. _IOWR(QCEDEV_IOC_MAGIC, 6, struct qcedev_sha_op_req)
  353. #define QCEDEV_IOCTL_LOCK_CE \
  354. _IO(QCEDEV_IOC_MAGIC, 7)
  355. #define QCEDEV_IOCTL_UNLOCK_CE \
  356. _IO(QCEDEV_IOC_MAGIC, 8)
  357. #define QCEDEV_IOCTL_GET_CMAC_REQ \
  358. _IOWR(QCEDEV_IOC_MAGIC, 9, struct qcedev_sha_op_req)
  359. #define QCEDEV_IOCTL_MAP_BUF_REQ \
  360. _IOWR(QCEDEV_IOC_MAGIC, 10, struct qcedev_map_buf_req)
  361. #define QCEDEV_IOCTL_UNMAP_BUF_REQ \
  362. _IOWR(QCEDEV_IOC_MAGIC, 11, struct qcedev_unmap_buf_req)
  363. #define QCEDEV_IOCTL_OFFLOAD_OP_REQ \
  364. _IOWR(QCEDEV_IOC_MAGIC, 12, struct qcedev_offload_cipher_op_req)
  365. #endif /* _UAPI_QCEDEV__H */