linux/drivers/crypto/allwinner/sun8i-ss/sun8i-ss.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * sun8i-ss.h - hardware cryptographic offloader for
 * Allwinner A80/A83T SoC
 *
 * Copyright (C) 2016-2019 Corentin LABBE <[email protected]>
 */
#include <crypto/aes.h>
#include <crypto/des.h>
#include <crypto/engine.h>
#include <crypto/rng.h>
#include <crypto/skcipher.h>
#include <linux/atomic.h>
#include <linux/debugfs.h>
#include <linux/crypto.h>
#include <crypto/internal/hash.h>
#include <crypto/md5.h>
#include <crypto/sha1.h>
#include <crypto/sha2.h>

#define SS_START

#define SS_ENCRYPTION
#define SS_DECRYPTION

#define SS_ALG_AES
#define SS_ALG_DES
#define SS_ALG_3DES
#define SS_ALG_MD5
#define SS_ALG_PRNG
#define SS_ALG_SHA1
#define SS_ALG_SHA224
#define SS_ALG_SHA256

#define SS_CTL_REG
#define SS_INT_CTL_REG
#define SS_INT_STA_REG
#define SS_KEY_ADR_REG
#define SS_IV_ADR_REG
#define SS_SRC_ADR_REG
#define SS_DST_ADR_REG
#define SS_LEN_ADR_REG

#define SS_ID_NOTSUPP

#define SS_ID_CIPHER_AES
#define SS_ID_CIPHER_DES
#define SS_ID_CIPHER_DES3
#define SS_ID_CIPHER_MAX

#define SS_ID_OP_ECB
#define SS_ID_OP_CBC
#define SS_ID_OP_MAX

#define SS_AES_128BITS
#define SS_AES_192BITS
#define SS_AES_256BITS

#define SS_OP_ECB
#define SS_OP_CBC

#define SS_ID_HASH_MD5
#define SS_ID_HASH_SHA1
#define SS_ID_HASH_SHA224
#define SS_ID_HASH_SHA256
#define SS_ID_HASH_MAX

#define SS_FLOW0
#define SS_FLOW1

#define SS_PRNG_CONTINUE

#define MAX_SG

#define MAXFLOW

#define SS_MAX_CLOCKS

#define SS_DIE_ID_SHIFT
#define SS_DIE_ID_MASK

#define PRNG_DATA_SIZE
#define PRNG_SEED_SIZE

#define MAX_PAD_SIZE

/*
 * struct ss_clock - Describe clocks used by sun8i-ss
 * @name:       Name of clock needed by this variant
 * @freq:       Frequency to set for each clock
 * @max_freq:   Maximum frequency for each clock
 */
struct ss_clock {};

/*
 * struct ss_variant - Describe SS capability for each variant hardware
 * @alg_cipher:	list of supported ciphers. for each SS_ID_ this will give the
 *              coresponding SS_ALG_XXX value
 * @alg_hash:	list of supported hashes. for each SS_ID_ this will give the
 *              corresponding SS_ALG_XXX value
 * @op_mode:	list of supported block modes
 * @ss_clks:	list of clock needed by this variant
 */
struct ss_variant {};

struct sginfo {};

/*
 * struct sun8i_ss_flow - Information used by each flow
 * @engine:	ptr to the crypto_engine for this flow
 * @complete:	completion for the current task on this flow
 * @status:	set to 1 by interrupt if task is done
 * @stat_req:	number of request done by this flow
 * @iv:		list of IV to use for each step
 * @biv:	buffer which contain the backuped IV
 * @pad:	padding buffer for hash operations
 * @result:	buffer for storing the result of hash operations
 */
struct sun8i_ss_flow {};

/*
 * struct sun8i_ss_dev - main container for all this driver information
 * @base:	base address of SS
 * @ssclks:	clocks used by SS
 * @reset:	pointer to reset controller
 * @dev:	the platform device
 * @mlock:	Control access to device registers
 * @flows:	array of all flow
 * @flow:	flow to use in next request
 * @variant:	pointer to variant specific data
 * @dbgfs_dir:	Debugfs dentry for statistic directory
 * @dbgfs_stats: Debugfs dentry for statistic counters
 */
struct sun8i_ss_dev {};

/*
 * struct sun8i_cipher_req_ctx - context for a skcipher request
 * @t_src:		list of mapped SGs with their size
 * @t_dst:		list of mapped SGs with their size
 * @p_key:		DMA address of the key
 * @p_iv:		DMA address of the IVs
 * @niv:		Number of IVs DMA mapped
 * @method:		current algorithm for this request
 * @op_mode:		op_mode for this request
 * @op_dir:		direction (encrypt vs decrypt) for this request
 * @flow:		the flow to use for this request
 * @ivlen:		size of IVs
 * @keylen:		keylen for this request
 * @fallback_req:	request struct for invoking the fallback skcipher TFM
 */
struct sun8i_cipher_req_ctx {};

/*
 * struct sun8i_cipher_tfm_ctx - context for a skcipher TFM
 * @key:		pointer to key data
 * @keylen:		len of the key
 * @ss:			pointer to the private data of driver handling this TFM
 * @fallback_tfm:	pointer to the fallback TFM
 */
struct sun8i_cipher_tfm_ctx {};

/*
 * struct sun8i_ss_prng_ctx - context for PRNG TFM
 * @seed:	The seed to use
 * @slen:	The size of the seed
 */
struct sun8i_ss_rng_tfm_ctx {};

/*
 * struct sun8i_ss_hash_tfm_ctx - context for an ahash TFM
 * @fallback_tfm:	pointer to the fallback TFM
 * @ss:			pointer to the private data of driver handling this TFM
 */
struct sun8i_ss_hash_tfm_ctx {};

/*
 * struct sun8i_ss_hash_reqctx - context for an ahash request
 * @t_src:	list of DMA address and size for source SGs
 * @t_dst:	list of DMA address and size for destination SGs
 * @fallback_req:	pre-allocated fallback request
 * @method:	the register value for the algorithm used by this request
 * @flow:	the flow to use for this request
 */
struct sun8i_ss_hash_reqctx {};

/*
 * struct sun8i_ss_alg_template - crypto_alg template
 * @type:		the CRYPTO_ALG_TYPE for this template
 * @ss_algo_id:		the SS_ID for this template
 * @ss_blockmode:	the type of block operation SS_ID
 * @ss:			pointer to the sun8i_ss_dev structure associated with
 *			this template
 * @alg:		one of sub struct must be used
 * @stat_req:		number of request done on this template
 * @stat_fb:		number of request which has fallbacked
 * @stat_bytes:		total data size done by this template
 */
struct sun8i_ss_alg_template {};

int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
			unsigned int keylen);
int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
			 unsigned int keylen);
int sun8i_ss_cipher_init(struct crypto_tfm *tfm);
void sun8i_ss_cipher_exit(struct crypto_tfm *tfm);
int sun8i_ss_handle_cipher_request(struct crypto_engine *engine, void *areq);
int sun8i_ss_skdecrypt(struct skcipher_request *areq);
int sun8i_ss_skencrypt(struct skcipher_request *areq);

int sun8i_ss_get_engine_number(struct sun8i_ss_dev *ss);

int sun8i_ss_run_task(struct sun8i_ss_dev *ss, struct sun8i_cipher_req_ctx *rctx, const char *name);
int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
			   unsigned int slen, u8 *dst, unsigned int dlen);
int sun8i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
int sun8i_ss_prng_init(struct crypto_tfm *tfm);
void sun8i_ss_prng_exit(struct crypto_tfm *tfm);

int sun8i_ss_hash_init_tfm(struct crypto_ahash *tfm);
void sun8i_ss_hash_exit_tfm(struct crypto_ahash *tfm);
int sun8i_ss_hash_init(struct ahash_request *areq);
int sun8i_ss_hash_export(struct ahash_request *areq, void *out);
int sun8i_ss_hash_import(struct ahash_request *areq, const void *in);
int sun8i_ss_hash_final(struct ahash_request *areq);
int sun8i_ss_hash_update(struct ahash_request *areq);
int sun8i_ss_hash_finup(struct ahash_request *areq);
int sun8i_ss_hash_digest(struct ahash_request *areq);
int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq);
int sun8i_ss_hmac_setkey(struct crypto_ahash *ahash, const u8 *key,
			 unsigned int keylen);