xref: /openbmc/linux/drivers/crypto/ccp/ccp-dev.h (revision fba8855cb2403707b0639bdff0d34149699f14a2)
163b94509STom Lendacky /*
263b94509STom Lendacky  * AMD Cryptographic Coprocessor (CCP) driver
363b94509STom Lendacky  *
4553d2374SGary R Hook  * Copyright (C) 2013,2016 Advanced Micro Devices, Inc.
563b94509STom Lendacky  *
663b94509STom Lendacky  * Author: Tom Lendacky <thomas.lendacky@amd.com>
7*fba8855cSGary R Hook  * Author: Gary R Hook <gary.hook@amd.com>
863b94509STom Lendacky  *
963b94509STom Lendacky  * This program is free software; you can redistribute it and/or modify
1063b94509STom Lendacky  * it under the terms of the GNU General Public License version 2 as
1163b94509STom Lendacky  * published by the Free Software Foundation.
1263b94509STom Lendacky  */
1363b94509STom Lendacky 
1463b94509STom Lendacky #ifndef __CCP_DEV_H__
1563b94509STom Lendacky #define __CCP_DEV_H__
1663b94509STom Lendacky 
1763b94509STom Lendacky #include <linux/device.h>
1863b94509STom Lendacky #include <linux/pci.h>
1963b94509STom Lendacky #include <linux/spinlock.h>
2063b94509STom Lendacky #include <linux/mutex.h>
2163b94509STom Lendacky #include <linux/list.h>
2263b94509STom Lendacky #include <linux/wait.h>
2363b94509STom Lendacky #include <linux/dmapool.h>
2463b94509STom Lendacky #include <linux/hw_random.h>
258db88467STom Lendacky #include <linux/bitops.h>
2658ea8abfSGary R Hook #include <linux/interrupt.h>
2758ea8abfSGary R Hook #include <linux/irqreturn.h>
2858ea8abfSGary R Hook #include <linux/dmaengine.h>
2963b94509STom Lendacky 
30553d2374SGary R Hook #define MAX_CCP_NAME_LEN		16
3163b94509STom Lendacky #define MAX_DMAPOOL_NAME_LEN		32
3263b94509STom Lendacky 
3363b94509STom Lendacky #define MAX_HW_QUEUES			5
3463b94509STom Lendacky #define MAX_CMD_QLEN			100
3563b94509STom Lendacky 
3663b94509STom Lendacky #define TRNG_RETRIES			10
3763b94509STom Lendacky 
38126ae9adSTom Lendacky #define CACHE_NONE			0x00
39c4f4b325STom Lendacky #define CACHE_WB_NO_ALLOC		0xb7
40c4f4b325STom Lendacky 
4163b94509STom Lendacky /****** Register Mappings ******/
4263b94509STom Lendacky #define Q_MASK_REG			0x000
4363b94509STom Lendacky #define TRNG_OUT_REG			0x00c
4463b94509STom Lendacky #define IRQ_MASK_REG			0x040
4563b94509STom Lendacky #define IRQ_STATUS_REG			0x200
4663b94509STom Lendacky 
4763b94509STom Lendacky #define DEL_CMD_Q_JOB			0x124
4863b94509STom Lendacky #define DEL_Q_ACTIVE			0x00000200
4963b94509STom Lendacky #define DEL_Q_ID_SHIFT			6
5063b94509STom Lendacky 
5163b94509STom Lendacky #define CMD_REQ0			0x180
5263b94509STom Lendacky #define CMD_REQ_INCR			0x04
5363b94509STom Lendacky 
5463b94509STom Lendacky #define CMD_Q_STATUS_BASE		0x210
5563b94509STom Lendacky #define CMD_Q_INT_STATUS_BASE		0x214
5663b94509STom Lendacky #define CMD_Q_STATUS_INCR		0x20
5763b94509STom Lendacky 
58c4f4b325STom Lendacky #define CMD_Q_CACHE_BASE		0x228
5963b94509STom Lendacky #define CMD_Q_CACHE_INC			0x20
6063b94509STom Lendacky 
618db88467STom Lendacky #define CMD_Q_ERROR(__qs)		((__qs) & 0x0000003f)
628db88467STom Lendacky #define CMD_Q_DEPTH(__qs)		(((__qs) >> 12) & 0x0000000f)
6363b94509STom Lendacky 
6463b94509STom Lendacky /****** REQ0 Related Values ******/
6563b94509STom Lendacky #define REQ0_WAIT_FOR_WRITE		0x00000004
6663b94509STom Lendacky #define REQ0_INT_ON_COMPLETE		0x00000002
6763b94509STom Lendacky #define REQ0_STOP_ON_COMPLETE		0x00000001
6863b94509STom Lendacky 
6963b94509STom Lendacky #define REQ0_CMD_Q_SHIFT		9
7063b94509STom Lendacky #define REQ0_JOBID_SHIFT		3
7163b94509STom Lendacky 
7263b94509STom Lendacky /****** REQ1 Related Values ******/
7363b94509STom Lendacky #define REQ1_PROTECT_SHIFT		27
7463b94509STom Lendacky #define REQ1_ENGINE_SHIFT		23
7563b94509STom Lendacky #define REQ1_KEY_KSB_SHIFT		2
7663b94509STom Lendacky 
7763b94509STom Lendacky #define REQ1_EOM			0x00000002
7863b94509STom Lendacky #define REQ1_INIT			0x00000001
7963b94509STom Lendacky 
8063b94509STom Lendacky /* AES Related Values */
8163b94509STom Lendacky #define REQ1_AES_TYPE_SHIFT		21
8263b94509STom Lendacky #define REQ1_AES_MODE_SHIFT		18
8363b94509STom Lendacky #define REQ1_AES_ACTION_SHIFT		17
8463b94509STom Lendacky #define REQ1_AES_CFB_SIZE_SHIFT		10
8563b94509STom Lendacky 
8663b94509STom Lendacky /* XTS-AES Related Values */
8763b94509STom Lendacky #define REQ1_XTS_AES_SIZE_SHIFT		10
8863b94509STom Lendacky 
8963b94509STom Lendacky /* SHA Related Values */
9063b94509STom Lendacky #define REQ1_SHA_TYPE_SHIFT		21
9163b94509STom Lendacky 
9263b94509STom Lendacky /* RSA Related Values */
9363b94509STom Lendacky #define REQ1_RSA_MOD_SIZE_SHIFT		10
9463b94509STom Lendacky 
9563b94509STom Lendacky /* Pass-Through Related Values */
9663b94509STom Lendacky #define REQ1_PT_BW_SHIFT		12
9763b94509STom Lendacky #define REQ1_PT_BS_SHIFT		10
9863b94509STom Lendacky 
9963b94509STom Lendacky /* ECC Related Values */
10063b94509STom Lendacky #define REQ1_ECC_AFFINE_CONVERT		0x00200000
10163b94509STom Lendacky #define REQ1_ECC_FUNCTION_SHIFT		18
10263b94509STom Lendacky 
10363b94509STom Lendacky /****** REQ4 Related Values ******/
10463b94509STom Lendacky #define REQ4_KSB_SHIFT			18
10563b94509STom Lendacky #define REQ4_MEMTYPE_SHIFT		16
10663b94509STom Lendacky 
10763b94509STom Lendacky /****** REQ6 Related Values ******/
10863b94509STom Lendacky #define REQ6_MEMTYPE_SHIFT		16
10963b94509STom Lendacky 
11063b94509STom Lendacky /****** Key Storage Block ******/
11163b94509STom Lendacky #define KSB_START			77
11263b94509STom Lendacky #define KSB_END				127
11363b94509STom Lendacky #define KSB_COUNT			(KSB_END - KSB_START + 1)
11463b94509STom Lendacky #define CCP_KSB_BITS			256
11563b94509STom Lendacky #define CCP_KSB_BYTES			32
11663b94509STom Lendacky 
11763b94509STom Lendacky #define CCP_JOBID_MASK			0x0000003f
11863b94509STom Lendacky 
11963b94509STom Lendacky #define CCP_DMAPOOL_MAX_SIZE		64
1208db88467STom Lendacky #define CCP_DMAPOOL_ALIGN		BIT(5)
12163b94509STom Lendacky 
12263b94509STom Lendacky #define CCP_REVERSE_BUF_SIZE		64
12363b94509STom Lendacky 
12463b94509STom Lendacky #define CCP_AES_KEY_KSB_COUNT		1
12563b94509STom Lendacky #define CCP_AES_CTX_KSB_COUNT		1
12663b94509STom Lendacky 
12763b94509STom Lendacky #define CCP_XTS_AES_KEY_KSB_COUNT	1
12863b94509STom Lendacky #define CCP_XTS_AES_CTX_KSB_COUNT	1
12963b94509STom Lendacky 
13063b94509STom Lendacky #define CCP_SHA_KSB_COUNT		1
13163b94509STom Lendacky 
13263b94509STom Lendacky #define CCP_RSA_MAX_WIDTH		4096
13363b94509STom Lendacky 
13463b94509STom Lendacky #define CCP_PASSTHRU_BLOCKSIZE		256
13563b94509STom Lendacky #define CCP_PASSTHRU_MASKSIZE		32
13663b94509STom Lendacky #define CCP_PASSTHRU_KSB_COUNT		1
13763b94509STom Lendacky 
13863b94509STom Lendacky #define CCP_ECC_MODULUS_BYTES		48      /* 384-bits */
13963b94509STom Lendacky #define CCP_ECC_MAX_OPERANDS		6
14063b94509STom Lendacky #define CCP_ECC_MAX_OUTPUTS		3
14163b94509STom Lendacky #define CCP_ECC_SRC_BUF_SIZE		448
14263b94509STom Lendacky #define CCP_ECC_DST_BUF_SIZE		192
14363b94509STom Lendacky #define CCP_ECC_OPERAND_SIZE		64
14463b94509STom Lendacky #define CCP_ECC_OUTPUT_SIZE		64
14563b94509STom Lendacky #define CCP_ECC_RESULT_OFFSET		60
14663b94509STom Lendacky #define CCP_ECC_RESULT_SUCCESS		0x0001
14763b94509STom Lendacky 
148ea0375afSGary R Hook struct ccp_op;
149ea0375afSGary R Hook 
150ea0375afSGary R Hook /* Structure for computation functions that are device-specific */
151ea0375afSGary R Hook struct ccp_actions {
152ea0375afSGary R Hook 	int (*perform_aes)(struct ccp_op *);
153ea0375afSGary R Hook 	int (*perform_xts_aes)(struct ccp_op *);
154ea0375afSGary R Hook 	int (*perform_sha)(struct ccp_op *);
155ea0375afSGary R Hook 	int (*perform_rsa)(struct ccp_op *);
156ea0375afSGary R Hook 	int (*perform_passthru)(struct ccp_op *);
157ea0375afSGary R Hook 	int (*perform_ecc)(struct ccp_op *);
158ea0375afSGary R Hook 	int (*init)(struct ccp_device *);
159ea0375afSGary R Hook 	void (*destroy)(struct ccp_device *);
160ea0375afSGary R Hook 	irqreturn_t (*irqhandler)(int, void *);
161ea0375afSGary R Hook };
162ea0375afSGary R Hook 
163c7019c4dSGary R Hook /* Structure to hold CCP version-specific values */
164c7019c4dSGary R Hook struct ccp_vdata {
165c7019c4dSGary R Hook 	unsigned int version;
166bc197b2aSJulia Lawall 	const struct ccp_actions *perform;
167*fba8855cSGary R Hook 	const unsigned int bar;
168*fba8855cSGary R Hook 	const unsigned int offset;
169c7019c4dSGary R Hook };
170c7019c4dSGary R Hook 
171c7019c4dSGary R Hook extern struct ccp_vdata ccpv3;
172c7019c4dSGary R Hook 
17363b94509STom Lendacky struct ccp_device;
17463b94509STom Lendacky struct ccp_cmd;
17563b94509STom Lendacky 
17658ea8abfSGary R Hook struct ccp_dma_cmd {
17758ea8abfSGary R Hook 	struct list_head entry;
17858ea8abfSGary R Hook 
17958ea8abfSGary R Hook 	struct ccp_cmd ccp_cmd;
18058ea8abfSGary R Hook };
18158ea8abfSGary R Hook 
18258ea8abfSGary R Hook struct ccp_dma_desc {
18358ea8abfSGary R Hook 	struct list_head entry;
18458ea8abfSGary R Hook 
18558ea8abfSGary R Hook 	struct ccp_device *ccp;
18658ea8abfSGary R Hook 
18758ea8abfSGary R Hook 	struct list_head pending;
18858ea8abfSGary R Hook 	struct list_head active;
18958ea8abfSGary R Hook 
19058ea8abfSGary R Hook 	enum dma_status status;
19158ea8abfSGary R Hook 	struct dma_async_tx_descriptor tx_desc;
19258ea8abfSGary R Hook 	size_t len;
19358ea8abfSGary R Hook };
19458ea8abfSGary R Hook 
19558ea8abfSGary R Hook struct ccp_dma_chan {
19658ea8abfSGary R Hook 	struct ccp_device *ccp;
19758ea8abfSGary R Hook 
19858ea8abfSGary R Hook 	spinlock_t lock;
19958ea8abfSGary R Hook 	struct list_head pending;
20058ea8abfSGary R Hook 	struct list_head active;
20158ea8abfSGary R Hook 	struct list_head complete;
20258ea8abfSGary R Hook 
20358ea8abfSGary R Hook 	struct tasklet_struct cleanup_tasklet;
20458ea8abfSGary R Hook 
20558ea8abfSGary R Hook 	enum dma_status status;
20658ea8abfSGary R Hook 	struct dma_chan dma_chan;
20758ea8abfSGary R Hook };
20858ea8abfSGary R Hook 
20963b94509STom Lendacky struct ccp_cmd_queue {
21063b94509STom Lendacky 	struct ccp_device *ccp;
21163b94509STom Lendacky 
21263b94509STom Lendacky 	/* Queue identifier */
21363b94509STom Lendacky 	u32 id;
21463b94509STom Lendacky 
21563b94509STom Lendacky 	/* Queue dma pool */
21663b94509STom Lendacky 	struct dma_pool *dma_pool;
21763b94509STom Lendacky 
21863b94509STom Lendacky 	/* Queue reserved KSB regions */
21963b94509STom Lendacky 	u32 ksb_key;
22063b94509STom Lendacky 	u32 ksb_ctx;
22163b94509STom Lendacky 
22263b94509STom Lendacky 	/* Queue processing thread */
22363b94509STom Lendacky 	struct task_struct *kthread;
22463b94509STom Lendacky 	unsigned int active;
22563b94509STom Lendacky 	unsigned int suspended;
22663b94509STom Lendacky 
22763b94509STom Lendacky 	/* Number of free command slots available */
22863b94509STom Lendacky 	unsigned int free_slots;
22963b94509STom Lendacky 
23063b94509STom Lendacky 	/* Interrupt masks */
23163b94509STom Lendacky 	u32 int_ok;
23263b94509STom Lendacky 	u32 int_err;
23363b94509STom Lendacky 
23463b94509STom Lendacky 	/* Register addresses for queue */
23563b94509STom Lendacky 	void __iomem *reg_status;
23663b94509STom Lendacky 	void __iomem *reg_int_status;
23763b94509STom Lendacky 
23863b94509STom Lendacky 	/* Status values from job */
23963b94509STom Lendacky 	u32 int_status;
24063b94509STom Lendacky 	u32 q_status;
24163b94509STom Lendacky 	u32 q_int_status;
24263b94509STom Lendacky 	u32 cmd_error;
24363b94509STom Lendacky 
24463b94509STom Lendacky 	/* Interrupt wait queue */
24563b94509STom Lendacky 	wait_queue_head_t int_queue;
24663b94509STom Lendacky 	unsigned int int_rcvd;
24763b94509STom Lendacky } ____cacheline_aligned;
24863b94509STom Lendacky 
24963b94509STom Lendacky struct ccp_device {
250553d2374SGary R Hook 	struct list_head entry;
251553d2374SGary R Hook 
252c7019c4dSGary R Hook 	struct ccp_vdata *vdata;
253553d2374SGary R Hook 	unsigned int ord;
254553d2374SGary R Hook 	char name[MAX_CCP_NAME_LEN];
255553d2374SGary R Hook 	char rngname[MAX_CCP_NAME_LEN];
256553d2374SGary R Hook 
25763b94509STom Lendacky 	struct device *dev;
25863b94509STom Lendacky 
259fa242e80SGary R Hook 	/* Bus specific device information
26063b94509STom Lendacky 	 */
26163b94509STom Lendacky 	void *dev_specific;
26263b94509STom Lendacky 	int (*get_irq)(struct ccp_device *ccp);
26363b94509STom Lendacky 	void (*free_irq)(struct ccp_device *ccp);
2643d77565bSTom Lendacky 	unsigned int irq;
26563b94509STom Lendacky 
266fa242e80SGary R Hook 	/* I/O area used for device communication. The register mapping
26763b94509STom Lendacky 	 * starts at an offset into the mapped bar.
26863b94509STom Lendacky 	 *   The CMD_REQx registers and the Delete_Cmd_Queue_Job register
26963b94509STom Lendacky 	 *   need to be protected while a command queue thread is accessing
27063b94509STom Lendacky 	 *   them.
27163b94509STom Lendacky 	 */
27263b94509STom Lendacky 	struct mutex req_mutex ____cacheline_aligned;
27363b94509STom Lendacky 	void __iomem *io_map;
27463b94509STom Lendacky 	void __iomem *io_regs;
27563b94509STom Lendacky 
276fa242e80SGary R Hook 	/* Master lists that all cmds are queued on. Because there can be
27763b94509STom Lendacky 	 * more than one CCP command queue that can process a cmd a separate
27863b94509STom Lendacky 	 * backlog list is neeeded so that the backlog completion call
27963b94509STom Lendacky 	 * completes before the cmd is available for execution.
28063b94509STom Lendacky 	 */
28163b94509STom Lendacky 	spinlock_t cmd_lock ____cacheline_aligned;
28263b94509STom Lendacky 	unsigned int cmd_count;
28363b94509STom Lendacky 	struct list_head cmd;
28463b94509STom Lendacky 	struct list_head backlog;
28563b94509STom Lendacky 
286fa242e80SGary R Hook 	/* The command queues. These represent the queues available on the
28763b94509STom Lendacky 	 * CCP that are available for processing cmds
28863b94509STom Lendacky 	 */
28963b94509STom Lendacky 	struct ccp_cmd_queue cmd_q[MAX_HW_QUEUES];
29063b94509STom Lendacky 	unsigned int cmd_q_count;
29163b94509STom Lendacky 
292fa242e80SGary R Hook 	/* Support for the CCP True RNG
29363b94509STom Lendacky 	 */
29463b94509STom Lendacky 	struct hwrng hwrng;
29563b94509STom Lendacky 	unsigned int hwrng_retries;
29663b94509STom Lendacky 
297fa242e80SGary R Hook 	/* Support for the CCP DMA capabilities
29858ea8abfSGary R Hook 	 */
29958ea8abfSGary R Hook 	struct dma_device dma_dev;
30058ea8abfSGary R Hook 	struct ccp_dma_chan *ccp_dma_chan;
30158ea8abfSGary R Hook 	struct kmem_cache *dma_cmd_cache;
30258ea8abfSGary R Hook 	struct kmem_cache *dma_desc_cache;
30358ea8abfSGary R Hook 
304fa242e80SGary R Hook 	/* A counter used to generate job-ids for cmds submitted to the CCP
30563b94509STom Lendacky 	 */
30663b94509STom Lendacky 	atomic_t current_id ____cacheline_aligned;
30763b94509STom Lendacky 
308fa242e80SGary R Hook 	/* The CCP uses key storage blocks (KSB) to maintain context for certain
30963b94509STom Lendacky 	 * operations. To prevent multiple cmds from using the same KSB range
31063b94509STom Lendacky 	 * a command queue reserves a KSB range for the duration of the cmd.
31163b94509STom Lendacky 	 * Each queue, will however, reserve 2 KSB blocks for operations that
31263b94509STom Lendacky 	 * only require single KSB entries (eg. AES context/iv and key) in order
31363b94509STom Lendacky 	 * to avoid allocation contention.  This will reserve at most 10 KSB
31463b94509STom Lendacky 	 * entries, leaving 40 KSB entries available for dynamic allocation.
31563b94509STom Lendacky 	 */
31663b94509STom Lendacky 	struct mutex ksb_mutex ____cacheline_aligned;
31763b94509STom Lendacky 	DECLARE_BITMAP(ksb, KSB_COUNT);
31863b94509STom Lendacky 	wait_queue_head_t ksb_queue;
31963b94509STom Lendacky 	unsigned int ksb_avail;
32063b94509STom Lendacky 	unsigned int ksb_count;
32163b94509STom Lendacky 	u32 ksb_start;
32263b94509STom Lendacky 
32363b94509STom Lendacky 	/* Suspend support */
32463b94509STom Lendacky 	unsigned int suspending;
32563b94509STom Lendacky 	wait_queue_head_t suspend_queue;
326126ae9adSTom Lendacky 
327126ae9adSTom Lendacky 	/* DMA caching attribute support */
328126ae9adSTom Lendacky 	unsigned int axcache;
32963b94509STom Lendacky };
33063b94509STom Lendacky 
331ea0375afSGary R Hook enum ccp_memtype {
332ea0375afSGary R Hook 	CCP_MEMTYPE_SYSTEM = 0,
333ea0375afSGary R Hook 	CCP_MEMTYPE_KSB,
334ea0375afSGary R Hook 	CCP_MEMTYPE_LOCAL,
335ea0375afSGary R Hook 	CCP_MEMTYPE__LAST,
336ea0375afSGary R Hook };
337ea0375afSGary R Hook 
338ea0375afSGary R Hook struct ccp_dma_info {
339ea0375afSGary R Hook 	dma_addr_t address;
340ea0375afSGary R Hook 	unsigned int offset;
341ea0375afSGary R Hook 	unsigned int length;
342ea0375afSGary R Hook 	enum dma_data_direction dir;
343ea0375afSGary R Hook };
344ea0375afSGary R Hook 
345ea0375afSGary R Hook struct ccp_dm_workarea {
346ea0375afSGary R Hook 	struct device *dev;
347ea0375afSGary R Hook 	struct dma_pool *dma_pool;
348ea0375afSGary R Hook 	unsigned int length;
349ea0375afSGary R Hook 
350ea0375afSGary R Hook 	u8 *address;
351ea0375afSGary R Hook 	struct ccp_dma_info dma;
352ea0375afSGary R Hook };
353ea0375afSGary R Hook 
354ea0375afSGary R Hook struct ccp_sg_workarea {
355ea0375afSGary R Hook 	struct scatterlist *sg;
356ea0375afSGary R Hook 	int nents;
357ea0375afSGary R Hook 
358ea0375afSGary R Hook 	struct scatterlist *dma_sg;
359ea0375afSGary R Hook 	struct device *dma_dev;
360ea0375afSGary R Hook 	unsigned int dma_count;
361ea0375afSGary R Hook 	enum dma_data_direction dma_dir;
362ea0375afSGary R Hook 
363ea0375afSGary R Hook 	unsigned int sg_used;
364ea0375afSGary R Hook 
365ea0375afSGary R Hook 	u64 bytes_left;
366ea0375afSGary R Hook };
367ea0375afSGary R Hook 
368ea0375afSGary R Hook struct ccp_data {
369ea0375afSGary R Hook 	struct ccp_sg_workarea sg_wa;
370ea0375afSGary R Hook 	struct ccp_dm_workarea dm_wa;
371ea0375afSGary R Hook };
372ea0375afSGary R Hook 
373ea0375afSGary R Hook struct ccp_mem {
374ea0375afSGary R Hook 	enum ccp_memtype type;
375ea0375afSGary R Hook 	union {
376ea0375afSGary R Hook 		struct ccp_dma_info dma;
377ea0375afSGary R Hook 		u32 ksb;
378ea0375afSGary R Hook 	} u;
379ea0375afSGary R Hook };
380ea0375afSGary R Hook 
381ea0375afSGary R Hook struct ccp_aes_op {
382ea0375afSGary R Hook 	enum ccp_aes_type type;
383ea0375afSGary R Hook 	enum ccp_aes_mode mode;
384ea0375afSGary R Hook 	enum ccp_aes_action action;
385ea0375afSGary R Hook };
386ea0375afSGary R Hook 
387ea0375afSGary R Hook struct ccp_xts_aes_op {
388ea0375afSGary R Hook 	enum ccp_aes_action action;
389ea0375afSGary R Hook 	enum ccp_xts_aes_unit_size unit_size;
390ea0375afSGary R Hook };
391ea0375afSGary R Hook 
392ea0375afSGary R Hook struct ccp_sha_op {
393ea0375afSGary R Hook 	enum ccp_sha_type type;
394ea0375afSGary R Hook 	u64 msg_bits;
395ea0375afSGary R Hook };
396ea0375afSGary R Hook 
397ea0375afSGary R Hook struct ccp_rsa_op {
398ea0375afSGary R Hook 	u32 mod_size;
399ea0375afSGary R Hook 	u32 input_len;
400ea0375afSGary R Hook };
401ea0375afSGary R Hook 
402ea0375afSGary R Hook struct ccp_passthru_op {
403ea0375afSGary R Hook 	enum ccp_passthru_bitwise bit_mod;
404ea0375afSGary R Hook 	enum ccp_passthru_byteswap byte_swap;
405ea0375afSGary R Hook };
406ea0375afSGary R Hook 
407ea0375afSGary R Hook struct ccp_ecc_op {
408ea0375afSGary R Hook 	enum ccp_ecc_function function;
409ea0375afSGary R Hook };
410ea0375afSGary R Hook 
411ea0375afSGary R Hook struct ccp_op {
412ea0375afSGary R Hook 	struct ccp_cmd_queue *cmd_q;
413ea0375afSGary R Hook 
414ea0375afSGary R Hook 	u32 jobid;
415ea0375afSGary R Hook 	u32 ioc;
416ea0375afSGary R Hook 	u32 soc;
417ea0375afSGary R Hook 	u32 ksb_key;
418ea0375afSGary R Hook 	u32 ksb_ctx;
419ea0375afSGary R Hook 	u32 init;
420ea0375afSGary R Hook 	u32 eom;
421ea0375afSGary R Hook 
422ea0375afSGary R Hook 	struct ccp_mem src;
423ea0375afSGary R Hook 	struct ccp_mem dst;
424ea0375afSGary R Hook 
425ea0375afSGary R Hook 	union {
426ea0375afSGary R Hook 		struct ccp_aes_op aes;
427ea0375afSGary R Hook 		struct ccp_xts_aes_op xts;
428ea0375afSGary R Hook 		struct ccp_sha_op sha;
429ea0375afSGary R Hook 		struct ccp_rsa_op rsa;
430ea0375afSGary R Hook 		struct ccp_passthru_op passthru;
431ea0375afSGary R Hook 		struct ccp_ecc_op ecc;
432ea0375afSGary R Hook 	} u;
433ea0375afSGary R Hook };
434ea0375afSGary R Hook 
435ea0375afSGary R Hook static inline u32 ccp_addr_lo(struct ccp_dma_info *info)
436ea0375afSGary R Hook {
437ea0375afSGary R Hook 	return lower_32_bits(info->address + info->offset);
438ea0375afSGary R Hook }
439ea0375afSGary R Hook 
440ea0375afSGary R Hook static inline u32 ccp_addr_hi(struct ccp_dma_info *info)
441ea0375afSGary R Hook {
442ea0375afSGary R Hook 	return upper_32_bits(info->address + info->offset) & 0x0000ffff;
443ea0375afSGary R Hook }
444ea0375afSGary R Hook 
44563b94509STom Lendacky int ccp_pci_init(void);
44663b94509STom Lendacky void ccp_pci_exit(void);
44763b94509STom Lendacky 
448c4f4b325STom Lendacky int ccp_platform_init(void);
449c4f4b325STom Lendacky void ccp_platform_exit(void);
450c4f4b325STom Lendacky 
451ea0375afSGary R Hook void ccp_add_device(struct ccp_device *ccp);
452ea0375afSGary R Hook void ccp_del_device(struct ccp_device *ccp);
45363b94509STom Lendacky 
454ea0375afSGary R Hook struct ccp_device *ccp_alloc_struct(struct device *dev);
455ea0375afSGary R Hook bool ccp_queues_suspended(struct ccp_device *ccp);
456ea0375afSGary R Hook int ccp_cmd_queue_thread(void *data);
45763b94509STom Lendacky 
45863b94509STom Lendacky int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd);
45963b94509STom Lendacky 
46058ea8abfSGary R Hook int ccp_dmaengine_register(struct ccp_device *ccp);
46158ea8abfSGary R Hook void ccp_dmaengine_unregister(struct ccp_device *ccp);
46258ea8abfSGary R Hook 
46363b94509STom Lendacky #endif
464