ccp-dev.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * AMD Cryptographic Coprocessor (CCP) driver
  3. *
  4. * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
  5. *
  6. * Author: Tom Lendacky <thomas.lendacky@amd.com>
  7. * Author: Gary R Hook <gary.hook@amd.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #ifndef __CCP_DEV_H__
  14. #define __CCP_DEV_H__
  15. #include <linux/device.h>
  16. #include <linux/pci.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/mutex.h>
  19. #include <linux/list.h>
  20. #include <linux/wait.h>
  21. #include <linux/dmapool.h>
  22. #include <linux/hw_random.h>
  23. #include <linux/bitops.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irqreturn.h>
  26. #include <linux/dmaengine.h>
  27. #include "sp-dev.h"
  28. #define MAX_CCP_NAME_LEN 16
  29. #define MAX_DMAPOOL_NAME_LEN 32
  30. #define MAX_HW_QUEUES 5
  31. #define MAX_CMD_QLEN 100
  32. #define TRNG_RETRIES 10
  33. #define CACHE_NONE 0x00
  34. #define CACHE_WB_NO_ALLOC 0xb7
  35. /****** Register Mappings ******/
  36. #define Q_MASK_REG 0x000
  37. #define TRNG_OUT_REG 0x00c
  38. #define IRQ_MASK_REG 0x040
  39. #define IRQ_STATUS_REG 0x200
  40. #define DEL_CMD_Q_JOB 0x124
  41. #define DEL_Q_ACTIVE 0x00000200
  42. #define DEL_Q_ID_SHIFT 6
  43. #define CMD_REQ0 0x180
  44. #define CMD_REQ_INCR 0x04
  45. #define CMD_Q_STATUS_BASE 0x210
  46. #define CMD_Q_INT_STATUS_BASE 0x214
  47. #define CMD_Q_STATUS_INCR 0x20
  48. #define CMD_Q_CACHE_BASE 0x228
  49. #define CMD_Q_CACHE_INC 0x20
  50. #define CMD_Q_ERROR(__qs) ((__qs) & 0x0000003f)
  51. #define CMD_Q_DEPTH(__qs) (((__qs) >> 12) & 0x0000000f)
  52. /* ------------------------ CCP Version 5 Specifics ------------------------ */
  53. #define CMD5_QUEUE_MASK_OFFSET 0x00
  54. #define CMD5_QUEUE_PRIO_OFFSET 0x04
  55. #define CMD5_REQID_CONFIG_OFFSET 0x08
  56. #define CMD5_CMD_TIMEOUT_OFFSET 0x10
  57. #define LSB_PUBLIC_MASK_LO_OFFSET 0x18
  58. #define LSB_PUBLIC_MASK_HI_OFFSET 0x1C
  59. #define LSB_PRIVATE_MASK_LO_OFFSET 0x20
  60. #define LSB_PRIVATE_MASK_HI_OFFSET 0x24
  61. #define CMD5_PSP_CCP_VERSION 0x100
  62. #define CMD5_Q_CONTROL_BASE 0x0000
  63. #define CMD5_Q_TAIL_LO_BASE 0x0004
  64. #define CMD5_Q_HEAD_LO_BASE 0x0008
  65. #define CMD5_Q_INT_ENABLE_BASE 0x000C
  66. #define CMD5_Q_INTERRUPT_STATUS_BASE 0x0010
  67. #define CMD5_Q_STATUS_BASE 0x0100
  68. #define CMD5_Q_INT_STATUS_BASE 0x0104
  69. #define CMD5_Q_DMA_STATUS_BASE 0x0108
  70. #define CMD5_Q_DMA_READ_STATUS_BASE 0x010C
  71. #define CMD5_Q_DMA_WRITE_STATUS_BASE 0x0110
  72. #define CMD5_Q_ABORT_BASE 0x0114
  73. #define CMD5_Q_AX_CACHE_BASE 0x0118
  74. #define CMD5_CONFIG_0_OFFSET 0x6000
  75. #define CMD5_TRNG_CTL_OFFSET 0x6008
  76. #define CMD5_AES_MASK_OFFSET 0x6010
  77. #define CMD5_CLK_GATE_CTL_OFFSET 0x603C
  78. /* Address offset between two virtual queue registers */
  79. #define CMD5_Q_STATUS_INCR 0x1000
  80. /* Bit masks */
  81. #define CMD5_Q_RUN 0x1
  82. #define CMD5_Q_HALT 0x2
  83. #define CMD5_Q_MEM_LOCATION 0x4
  84. #define CMD5_Q_SIZE 0x1F
  85. #define CMD5_Q_SHIFT 3
  86. #define COMMANDS_PER_QUEUE 16
  87. #define QUEUE_SIZE_VAL ((ffs(COMMANDS_PER_QUEUE) - 2) & \
  88. CMD5_Q_SIZE)
  89. #define Q_PTR_MASK (2 << (QUEUE_SIZE_VAL + 5) - 1)
  90. #define Q_DESC_SIZE sizeof(struct ccp5_desc)
  91. #define Q_SIZE(n) (COMMANDS_PER_QUEUE*(n))
  92. #define INT_COMPLETION 0x1
  93. #define INT_ERROR 0x2
  94. #define INT_QUEUE_STOPPED 0x4
  95. #define INT_EMPTY_QUEUE 0x8
  96. #define SUPPORTED_INTERRUPTS (INT_COMPLETION | INT_ERROR)
  97. #define LSB_REGION_WIDTH 5
  98. #define MAX_LSB_CNT 8
  99. #define LSB_SIZE 16
  100. #define LSB_ITEM_SIZE 32
  101. #define PLSB_MAP_SIZE (LSB_SIZE)
  102. #define SLSB_MAP_SIZE (MAX_LSB_CNT * LSB_SIZE)
  103. #define LSB_ENTRY_NUMBER(LSB_ADDR) (LSB_ADDR / LSB_ITEM_SIZE)
  104. /* ------------------------ CCP Version 3 Specifics ------------------------ */
  105. #define REQ0_WAIT_FOR_WRITE 0x00000004
  106. #define REQ0_INT_ON_COMPLETE 0x00000002
  107. #define REQ0_STOP_ON_COMPLETE 0x00000001
  108. #define REQ0_CMD_Q_SHIFT 9
  109. #define REQ0_JOBID_SHIFT 3
  110. /****** REQ1 Related Values ******/
  111. #define REQ1_PROTECT_SHIFT 27
  112. #define REQ1_ENGINE_SHIFT 23
  113. #define REQ1_KEY_KSB_SHIFT 2
  114. #define REQ1_EOM 0x00000002
  115. #define REQ1_INIT 0x00000001
  116. /* AES Related Values */
  117. #define REQ1_AES_TYPE_SHIFT 21
  118. #define REQ1_AES_MODE_SHIFT 18
  119. #define REQ1_AES_ACTION_SHIFT 17
  120. #define REQ1_AES_CFB_SIZE_SHIFT 10
  121. /* XTS-AES Related Values */
  122. #define REQ1_XTS_AES_SIZE_SHIFT 10
  123. /* SHA Related Values */
  124. #define REQ1_SHA_TYPE_SHIFT 21
  125. /* RSA Related Values */
  126. #define REQ1_RSA_MOD_SIZE_SHIFT 10
  127. /* Pass-Through Related Values */
  128. #define REQ1_PT_BW_SHIFT 12
  129. #define REQ1_PT_BS_SHIFT 10
  130. /* ECC Related Values */
  131. #define REQ1_ECC_AFFINE_CONVERT 0x00200000
  132. #define REQ1_ECC_FUNCTION_SHIFT 18
  133. /****** REQ4 Related Values ******/
  134. #define REQ4_KSB_SHIFT 18
  135. #define REQ4_MEMTYPE_SHIFT 16
  136. /****** REQ6 Related Values ******/
  137. #define REQ6_MEMTYPE_SHIFT 16
  138. /****** Key Storage Block ******/
  139. #define KSB_START 77
  140. #define KSB_END 127
  141. #define KSB_COUNT (KSB_END - KSB_START + 1)
  142. #define CCP_SB_BITS 256
  143. #define CCP_JOBID_MASK 0x0000003f
  144. /* ------------------------ General CCP Defines ------------------------ */
  145. #define CCP_DMA_DFLT 0x0
  146. #define CCP_DMA_PRIV 0x1
  147. #define CCP_DMA_PUB 0x2
  148. #define CCP_DMAPOOL_MAX_SIZE 64
  149. #define CCP_DMAPOOL_ALIGN BIT(5)
  150. #define CCP_REVERSE_BUF_SIZE 64
  151. #define CCP_AES_KEY_SB_COUNT 1
  152. #define CCP_AES_CTX_SB_COUNT 1
  153. #define CCP_XTS_AES_KEY_SB_COUNT 1
  154. #define CCP5_XTS_AES_KEY_SB_COUNT 2
  155. #define CCP_XTS_AES_CTX_SB_COUNT 1
  156. #define CCP_DES3_KEY_SB_COUNT 1
  157. #define CCP_DES3_CTX_SB_COUNT 1
  158. #define CCP_SHA_SB_COUNT 1
  159. #define CCP_RSA_MAX_WIDTH 4096
  160. #define CCP5_RSA_MAX_WIDTH 16384
  161. #define CCP_PASSTHRU_BLOCKSIZE 256
  162. #define CCP_PASSTHRU_MASKSIZE 32
  163. #define CCP_PASSTHRU_SB_COUNT 1
  164. #define CCP_ECC_MODULUS_BYTES 48 /* 384-bits */
  165. #define CCP_ECC_MAX_OPERANDS 6
  166. #define CCP_ECC_MAX_OUTPUTS 3
  167. #define CCP_ECC_SRC_BUF_SIZE 448
  168. #define CCP_ECC_DST_BUF_SIZE 192
  169. #define CCP_ECC_OPERAND_SIZE 64
  170. #define CCP_ECC_OUTPUT_SIZE 64
  171. #define CCP_ECC_RESULT_OFFSET 60
  172. #define CCP_ECC_RESULT_SUCCESS 0x0001
  173. #define CCP_SB_BYTES 32
  174. struct ccp_op;
  175. struct ccp_device;
  176. struct ccp_cmd;
  177. struct ccp_fns;
  178. struct ccp_dma_cmd {
  179. struct list_head entry;
  180. struct ccp_cmd ccp_cmd;
  181. };
  182. struct ccp_dma_desc {
  183. struct list_head entry;
  184. struct ccp_device *ccp;
  185. struct list_head pending;
  186. struct list_head active;
  187. enum dma_status status;
  188. struct dma_async_tx_descriptor tx_desc;
  189. size_t len;
  190. };
  191. struct ccp_dma_chan {
  192. struct ccp_device *ccp;
  193. spinlock_t lock;
  194. struct list_head created;
  195. struct list_head pending;
  196. struct list_head active;
  197. struct list_head complete;
  198. struct tasklet_struct cleanup_tasklet;
  199. enum dma_status status;
  200. struct dma_chan dma_chan;
  201. };
  202. struct ccp_cmd_queue {
  203. struct ccp_device *ccp;
  204. /* Queue identifier */
  205. u32 id;
  206. /* Queue dma pool */
  207. struct dma_pool *dma_pool;
  208. /* Queue base address (not neccessarily aligned)*/
  209. struct ccp5_desc *qbase;
  210. /* Aligned queue start address (per requirement) */
  211. struct mutex q_mutex ____cacheline_aligned;
  212. unsigned int qidx;
  213. /* Version 5 has different requirements for queue memory */
  214. unsigned int qsize;
  215. dma_addr_t qbase_dma;
  216. dma_addr_t qdma_tail;
  217. /* Per-queue reserved storage block(s) */
  218. u32 sb_key;
  219. u32 sb_ctx;
  220. /* Bitmap of LSBs that can be accessed by this queue */
  221. DECLARE_BITMAP(lsbmask, MAX_LSB_CNT);
  222. /* Private LSB that is assigned to this queue, or -1 if none.
  223. * Bitmap for my private LSB, unused otherwise
  224. */
  225. int lsb;
  226. DECLARE_BITMAP(lsbmap, PLSB_MAP_SIZE);
  227. /* Queue processing thread */
  228. struct task_struct *kthread;
  229. unsigned int active;
  230. unsigned int suspended;
  231. /* Number of free command slots available */
  232. unsigned int free_slots;
  233. /* Interrupt masks */
  234. u32 int_ok;
  235. u32 int_err;
  236. /* Register addresses for queue */
  237. void __iomem *reg_control;
  238. void __iomem *reg_tail_lo;
  239. void __iomem *reg_head_lo;
  240. void __iomem *reg_int_enable;
  241. void __iomem *reg_interrupt_status;
  242. void __iomem *reg_status;
  243. void __iomem *reg_int_status;
  244. void __iomem *reg_dma_status;
  245. void __iomem *reg_dma_read_status;
  246. void __iomem *reg_dma_write_status;
  247. u32 qcontrol; /* Cached control register */
  248. /* Status values from job */
  249. u32 int_status;
  250. u32 q_status;
  251. u32 q_int_status;
  252. u32 cmd_error;
  253. /* Interrupt wait queue */
  254. wait_queue_head_t int_queue;
  255. unsigned int int_rcvd;
  256. /* Per-queue Statistics */
  257. unsigned long total_ops;
  258. unsigned long total_aes_ops;
  259. unsigned long total_xts_aes_ops;
  260. unsigned long total_3des_ops;
  261. unsigned long total_sha_ops;
  262. unsigned long total_rsa_ops;
  263. unsigned long total_pt_ops;
  264. unsigned long total_ecc_ops;
  265. } ____cacheline_aligned;
  266. struct ccp_device {
  267. struct list_head entry;
  268. struct ccp_vdata *vdata;
  269. unsigned int ord;
  270. char name[MAX_CCP_NAME_LEN];
  271. char rngname[MAX_CCP_NAME_LEN];
  272. struct device *dev;
  273. struct sp_device *sp;
  274. /* Bus specific device information
  275. */
  276. void *dev_specific;
  277. unsigned int qim;
  278. unsigned int irq;
  279. bool use_tasklet;
  280. struct tasklet_struct irq_tasklet;
  281. /* I/O area used for device communication. The register mapping
  282. * starts at an offset into the mapped bar.
  283. * The CMD_REQx registers and the Delete_Cmd_Queue_Job register
  284. * need to be protected while a command queue thread is accessing
  285. * them.
  286. */
  287. struct mutex req_mutex ____cacheline_aligned;
  288. void __iomem *io_regs;
  289. /* Master lists that all cmds are queued on. Because there can be
  290. * more than one CCP command queue that can process a cmd a separate
  291. * backlog list is neeeded so that the backlog completion call
  292. * completes before the cmd is available for execution.
  293. */
  294. spinlock_t cmd_lock ____cacheline_aligned;
  295. unsigned int cmd_count;
  296. struct list_head cmd;
  297. struct list_head backlog;
  298. /* The command queues. These represent the queues available on the
  299. * CCP that are available for processing cmds
  300. */
  301. struct ccp_cmd_queue cmd_q[MAX_HW_QUEUES];
  302. unsigned int cmd_q_count;
  303. /* Support for the CCP True RNG
  304. */
  305. struct hwrng hwrng;
  306. unsigned int hwrng_retries;
  307. /* Support for the CCP DMA capabilities
  308. */
  309. struct dma_device dma_dev;
  310. struct ccp_dma_chan *ccp_dma_chan;
  311. struct kmem_cache *dma_cmd_cache;
  312. struct kmem_cache *dma_desc_cache;
  313. /* A counter used to generate job-ids for cmds submitted to the CCP
  314. */
  315. atomic_t current_id ____cacheline_aligned;
  316. /* The v3 CCP uses key storage blocks (SB) to maintain context for
  317. * certain operations. To prevent multiple cmds from using the same
  318. * SB range a command queue reserves an SB range for the duration of
  319. * the cmd. Each queue, will however, reserve 2 SB blocks for
  320. * operations that only require single SB entries (eg. AES context/iv
  321. * and key) in order to avoid allocation contention. This will reserve
  322. * at most 10 SB entries, leaving 40 SB entries available for dynamic
  323. * allocation.
  324. *
  325. * The v5 CCP Local Storage Block (LSB) is broken up into 8
  326. * memrory ranges, each of which can be enabled for access by one
  327. * or more queues. Device initialization takes this into account,
  328. * and attempts to assign one region for exclusive use by each
  329. * available queue; the rest are then aggregated as "public" use.
  330. * If there are fewer regions than queues, all regions are shared
  331. * amongst all queues.
  332. */
  333. struct mutex sb_mutex ____cacheline_aligned;
  334. DECLARE_BITMAP(sb, KSB_COUNT);
  335. wait_queue_head_t sb_queue;
  336. unsigned int sb_avail;
  337. unsigned int sb_count;
  338. u32 sb_start;
  339. /* Bitmap of shared LSBs, if any */
  340. DECLARE_BITMAP(lsbmap, SLSB_MAP_SIZE);
  341. /* Suspend support */
  342. unsigned int suspending;
  343. wait_queue_head_t suspend_queue;
  344. /* DMA caching attribute support */
  345. unsigned int axcache;
  346. /* Device Statistics */
  347. unsigned long total_interrupts;
  348. /* DebugFS info */
  349. struct dentry *debugfs_instance;
  350. };
  351. enum ccp_memtype {
  352. CCP_MEMTYPE_SYSTEM = 0,
  353. CCP_MEMTYPE_SB,
  354. CCP_MEMTYPE_LOCAL,
  355. CCP_MEMTYPE__LAST,
  356. };
  357. #define CCP_MEMTYPE_LSB CCP_MEMTYPE_KSB
  358. struct ccp_dma_info {
  359. dma_addr_t address;
  360. unsigned int offset;
  361. unsigned int length;
  362. enum dma_data_direction dir;
  363. } __packed __aligned(4);
  364. struct ccp_dm_workarea {
  365. struct device *dev;
  366. struct dma_pool *dma_pool;
  367. u8 *address;
  368. struct ccp_dma_info dma;
  369. unsigned int length;
  370. };
  371. struct ccp_sg_workarea {
  372. struct scatterlist *sg;
  373. int nents;
  374. unsigned int sg_used;
  375. struct scatterlist *dma_sg;
  376. struct device *dma_dev;
  377. unsigned int dma_count;
  378. enum dma_data_direction dma_dir;
  379. u64 bytes_left;
  380. };
  381. struct ccp_data {
  382. struct ccp_sg_workarea sg_wa;
  383. struct ccp_dm_workarea dm_wa;
  384. };
  385. struct ccp_mem {
  386. enum ccp_memtype type;
  387. union {
  388. struct ccp_dma_info dma;
  389. u32 sb;
  390. } u;
  391. };
  392. struct ccp_aes_op {
  393. enum ccp_aes_type type;
  394. enum ccp_aes_mode mode;
  395. enum ccp_aes_action action;
  396. unsigned int size;
  397. };
  398. struct ccp_xts_aes_op {
  399. enum ccp_aes_type type;
  400. enum ccp_aes_action action;
  401. enum ccp_xts_aes_unit_size unit_size;
  402. };
  403. struct ccp_des3_op {
  404. enum ccp_des3_type type;
  405. enum ccp_des3_mode mode;
  406. enum ccp_des3_action action;
  407. };
  408. struct ccp_sha_op {
  409. enum ccp_sha_type type;
  410. u64 msg_bits;
  411. };
  412. struct ccp_rsa_op {
  413. u32 mod_size;
  414. u32 input_len;
  415. };
  416. struct ccp_passthru_op {
  417. enum ccp_passthru_bitwise bit_mod;
  418. enum ccp_passthru_byteswap byte_swap;
  419. };
  420. struct ccp_ecc_op {
  421. enum ccp_ecc_function function;
  422. };
  423. struct ccp_op {
  424. struct ccp_cmd_queue *cmd_q;
  425. u32 jobid;
  426. u32 ioc;
  427. u32 soc;
  428. u32 sb_key;
  429. u32 sb_ctx;
  430. u32 init;
  431. u32 eom;
  432. struct ccp_mem src;
  433. struct ccp_mem dst;
  434. struct ccp_mem exp;
  435. union {
  436. struct ccp_aes_op aes;
  437. struct ccp_xts_aes_op xts;
  438. struct ccp_des3_op des3;
  439. struct ccp_sha_op sha;
  440. struct ccp_rsa_op rsa;
  441. struct ccp_passthru_op passthru;
  442. struct ccp_ecc_op ecc;
  443. } u;
  444. };
  445. static inline u32 ccp_addr_lo(struct ccp_dma_info *info)
  446. {
  447. return lower_32_bits(info->address + info->offset);
  448. }
  449. static inline u32 ccp_addr_hi(struct ccp_dma_info *info)
  450. {
  451. return upper_32_bits(info->address + info->offset) & 0x0000ffff;
  452. }
  453. /**
  454. * descriptor for version 5 CPP commands
  455. * 8 32-bit words:
  456. * word 0: function; engine; control bits
  457. * word 1: length of source data
  458. * word 2: low 32 bits of source pointer
  459. * word 3: upper 16 bits of source pointer; source memory type
  460. * word 4: low 32 bits of destination pointer
  461. * word 5: upper 16 bits of destination pointer; destination memory type
  462. * word 6: low 32 bits of key pointer
  463. * word 7: upper 16 bits of key pointer; key memory type
  464. */
  465. struct dword0 {
  466. unsigned int soc:1;
  467. unsigned int ioc:1;
  468. unsigned int rsvd1:1;
  469. unsigned int init:1;
  470. unsigned int eom:1; /* AES/SHA only */
  471. unsigned int function:15;
  472. unsigned int engine:4;
  473. unsigned int prot:1;
  474. unsigned int rsvd2:7;
  475. };
  476. struct dword3 {
  477. unsigned int src_hi:16;
  478. unsigned int src_mem:2;
  479. unsigned int lsb_cxt_id:8;
  480. unsigned int rsvd1:5;
  481. unsigned int fixed:1;
  482. };
  483. union dword4 {
  484. __le32 dst_lo; /* NON-SHA */
  485. __le32 sha_len_lo; /* SHA */
  486. };
  487. union dword5 {
  488. struct {
  489. unsigned int dst_hi:16;
  490. unsigned int dst_mem:2;
  491. unsigned int rsvd1:13;
  492. unsigned int fixed:1;
  493. } fields;
  494. __le32 sha_len_hi;
  495. };
  496. struct dword7 {
  497. unsigned int key_hi:16;
  498. unsigned int key_mem:2;
  499. unsigned int rsvd1:14;
  500. };
  501. struct ccp5_desc {
  502. struct dword0 dw0;
  503. __le32 length;
  504. __le32 src_lo;
  505. struct dword3 dw3;
  506. union dword4 dw4;
  507. union dword5 dw5;
  508. __le32 key_lo;
  509. struct dword7 dw7;
  510. };
  511. void ccp_add_device(struct ccp_device *ccp);
  512. void ccp_del_device(struct ccp_device *ccp);
  513. extern void ccp_log_error(struct ccp_device *, unsigned int);
  514. struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
  515. bool ccp_queues_suspended(struct ccp_device *ccp);
  516. int ccp_cmd_queue_thread(void *data);
  517. int ccp_trng_read(struct hwrng *rng, void *data, size_t max, bool wait);
  518. int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd);
  519. int ccp_register_rng(struct ccp_device *ccp);
  520. void ccp_unregister_rng(struct ccp_device *ccp);
  521. int ccp_dmaengine_register(struct ccp_device *ccp);
  522. void ccp_dmaengine_unregister(struct ccp_device *ccp);
  523. void ccp5_debugfs_setup(struct ccp_device *ccp);
  524. void ccp5_debugfs_destroy(void);
  525. /* Structure for computation functions that are device-specific */
  526. struct ccp_actions {
  527. int (*aes)(struct ccp_op *);
  528. int (*xts_aes)(struct ccp_op *);
  529. int (*des3)(struct ccp_op *);
  530. int (*sha)(struct ccp_op *);
  531. int (*rsa)(struct ccp_op *);
  532. int (*passthru)(struct ccp_op *);
  533. int (*ecc)(struct ccp_op *);
  534. u32 (*sballoc)(struct ccp_cmd_queue *, unsigned int);
  535. void (*sbfree)(struct ccp_cmd_queue *, unsigned int, unsigned int);
  536. unsigned int (*get_free_slots)(struct ccp_cmd_queue *);
  537. int (*init)(struct ccp_device *);
  538. void (*destroy)(struct ccp_device *);
  539. irqreturn_t (*irqhandler)(int, void *);
  540. };
  541. extern const struct ccp_vdata ccpv3_platform;
  542. extern const struct ccp_vdata ccpv3;
  543. extern const struct ccp_vdata ccpv5a;
  544. extern const struct ccp_vdata ccpv5b;
  545. #endif