linux/drivers/crypto/intel/keembay/keembay-ocs-aes-core.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Intel Keem Bay OCS AES Crypto Driver.
 *
 * Copyright (C) 2018-2020 Intel Corporation
 */

#include <crypto/aes.h>
#include <crypto/engine.h>
#include <crypto/gcm.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>
#include <crypto/scatterwalk.h>
#include <linux/clk.h>
#include <linux/completion.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/string.h>

#include "ocs-aes.h"

#define KMB_OCS_PRIORITY
#define DRV_NAME

#define OCS_AES_MIN_KEY_SIZE
#define OCS_AES_MAX_KEY_SIZE
#define OCS_AES_KEYSIZE_128
#define OCS_AES_KEYSIZE_192
#define OCS_AES_KEYSIZE_256
#define OCS_SM4_KEY_SIZE

/**
 * struct ocs_aes_tctx - OCS AES Transform context
 * @aes_dev:		The OCS AES device.
 * @key:		AES/SM4 key.
 * @key_len:		The length (in bytes) of @key.
 * @cipher:		OCS cipher to use (either AES or SM4).
 * @sw_cipher:		The cipher to use as fallback.
 * @use_fallback:	Whether or not fallback cipher should be used.
 */
struct ocs_aes_tctx {};

/**
 * struct ocs_aes_rctx - OCS AES Request context.
 * @instruction:	Instruction to be executed (encrypt / decrypt).
 * @mode:		Mode to use (ECB, CBC, CTR, CCm, GCM, CTS)
 * @src_nents:		Number of source SG entries.
 * @dst_nents:		Number of destination SG entries.
 * @src_dma_count:	The number of DMA-mapped entries of the source SG.
 * @dst_dma_count:	The number of DMA-mapped entries of the destination SG.
 * @in_place:		Whether or not this is an in place request, i.e.,
 *			src_sg == dst_sg.
 * @src_dll:		OCS DMA linked list for input data.
 * @dst_dll:		OCS DMA linked list for output data.
 * @last_ct_blk:	Buffer to hold last cipher text block (only used in CBC
 *			mode).
 * @cts_swap:		Whether or not CTS swap must be performed.
 * @aad_src_dll:	OCS DMA linked list for input AAD data.
 * @aad_dst_dll:	OCS DMA linked list for output AAD data.
 * @in_tag:		Buffer to hold input encrypted tag (only used for
 *			CCM/GCM decrypt).
 * @out_tag:		Buffer to hold output encrypted / decrypted tag (only
 *			used for GCM encrypt / decrypt).
 */
struct ocs_aes_rctx {};

/* Driver data. */
struct ocs_aes_drv {};

static struct ocs_aes_drv ocs_aes =;

static struct ocs_aes_dev *kmb_ocs_aes_find_dev(struct ocs_aes_tctx *tctx)
{}

/*
 * Ensure key is 128-bit or 256-bit for AES or 128-bit for SM4 and an actual
 * key is being passed in.
 *
 * Return: 0 if key is valid, -EINVAL otherwise.
 */
static int check_key(const u8 *in_key, size_t key_len, enum ocs_cipher cipher)
{}

/* Save key into transformation context. */
static int save_key(struct ocs_aes_tctx *tctx, const u8 *in_key, size_t key_len,
		    enum ocs_cipher cipher)
{}

/* Set key for symmetric cypher. */
static int kmb_ocs_sk_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
			      size_t key_len, enum ocs_cipher cipher)
{}

/* Set key for AEAD cipher. */
static int kmb_ocs_aead_set_key(struct crypto_aead *tfm, const u8 *in_key,
				size_t key_len, enum ocs_cipher cipher)
{}

/* Swap two AES blocks in SG lists. */
static void sg_swap_blocks(struct scatterlist *sgl, unsigned int nents,
			   off_t blk1_offset, off_t blk2_offset)
{}

/* Initialize request context to default values. */
static void ocs_aes_init_rctx(struct ocs_aes_rctx *rctx)
{}

static int kmb_ocs_sk_validate_input(struct skcipher_request *req,
				     enum ocs_mode mode)
{}

/*
 * Called by encrypt() / decrypt() skcipher functions.
 *
 * Use fallback if needed, otherwise initialize context and enqueue request
 * into engine.
 */
static int kmb_ocs_sk_common(struct skcipher_request *req,
			     enum ocs_cipher cipher,
			     enum ocs_instruction instruction,
			     enum ocs_mode mode)
{}

static void cleanup_ocs_dma_linked_list(struct device *dev,
					struct ocs_dll_desc *dll)
{}

static void kmb_ocs_sk_dma_cleanup(struct skcipher_request *req)
{}

static int kmb_ocs_sk_prepare_inplace(struct skcipher_request *req)
{}

static int kmb_ocs_sk_prepare_notinplace(struct skcipher_request *req)
{}

static int kmb_ocs_sk_run(struct skcipher_request *req)
{}

static int kmb_ocs_aead_validate_input(struct aead_request *req,
				       enum ocs_instruction instruction,
				       enum ocs_mode mode)
{}

/*
 * Called by encrypt() / decrypt() aead functions.
 *
 * Use fallback if needed, otherwise initialize context and enqueue request
 * into engine.
 */
static int kmb_ocs_aead_common(struct aead_request *req,
			       enum ocs_cipher cipher,
			       enum ocs_instruction instruction,
			       enum ocs_mode mode)
{}

static void kmb_ocs_aead_dma_cleanup(struct aead_request *req)
{}

/**
 * kmb_ocs_aead_dma_prepare() - Do DMA mapping for AEAD processing.
 * @req:		The AEAD request being processed.
 * @src_dll_size:	Where to store the length of the data mapped into the
 *			src_dll OCS DMA list.
 *
 * Do the following:
 * - DMA map req->src and req->dst
 * - Initialize the following OCS DMA linked lists: rctx->src_dll,
 *   rctx->dst_dll, rctx->aad_src_dll and rxtc->aad_dst_dll.
 *
 * Return: 0 on success, negative error code otherwise.
 */
static int kmb_ocs_aead_dma_prepare(struct aead_request *req, u32 *src_dll_size)
{}

static int kmb_ocs_aead_run(struct aead_request *req)
{}

static int kmb_ocs_aes_sk_do_one_request(struct crypto_engine *engine,
					 void *areq)
{}

static int kmb_ocs_aes_aead_do_one_request(struct crypto_engine *engine,
					   void *areq)
{}

static int kmb_ocs_aes_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
			       unsigned int key_len)
{}

static int kmb_ocs_aes_aead_set_key(struct crypto_aead *tfm, const u8 *in_key,
				    unsigned int key_len)
{}

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB
static int kmb_ocs_aes_ecb_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_aes_ecb_decrypt(struct skcipher_request *req)
{}
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */

static int kmb_ocs_aes_cbc_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_aes_cbc_decrypt(struct skcipher_request *req)
{}

static int kmb_ocs_aes_ctr_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_aes_ctr_decrypt(struct skcipher_request *req)
{}

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS
static int kmb_ocs_aes_cts_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_aes_cts_decrypt(struct skcipher_request *req)
{}
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */

static int kmb_ocs_aes_gcm_encrypt(struct aead_request *req)
{}

static int kmb_ocs_aes_gcm_decrypt(struct aead_request *req)
{}

static int kmb_ocs_aes_ccm_encrypt(struct aead_request *req)
{}

static int kmb_ocs_aes_ccm_decrypt(struct aead_request *req)
{}

static int kmb_ocs_sm4_set_key(struct crypto_skcipher *tfm, const u8 *in_key,
			       unsigned int key_len)
{}

static int kmb_ocs_sm4_aead_set_key(struct crypto_aead *tfm, const u8 *in_key,
				    unsigned int key_len)
{}

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB
static int kmb_ocs_sm4_ecb_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_sm4_ecb_decrypt(struct skcipher_request *req)
{}
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */

static int kmb_ocs_sm4_cbc_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_sm4_cbc_decrypt(struct skcipher_request *req)
{}

static int kmb_ocs_sm4_ctr_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_sm4_ctr_decrypt(struct skcipher_request *req)
{}

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS
static int kmb_ocs_sm4_cts_encrypt(struct skcipher_request *req)
{}

static int kmb_ocs_sm4_cts_decrypt(struct skcipher_request *req)
{}
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */

static int kmb_ocs_sm4_gcm_encrypt(struct aead_request *req)
{}

static int kmb_ocs_sm4_gcm_decrypt(struct aead_request *req)
{}

static int kmb_ocs_sm4_ccm_encrypt(struct aead_request *req)
{}

static int kmb_ocs_sm4_ccm_decrypt(struct aead_request *req)
{}

static int ocs_aes_init_tfm(struct crypto_skcipher *tfm)
{}

static int ocs_sm4_init_tfm(struct crypto_skcipher *tfm)
{}

static inline void clear_key(struct ocs_aes_tctx *tctx)
{}

static void ocs_exit_tfm(struct crypto_skcipher *tfm)
{}

static int ocs_aes_aead_cra_init(struct crypto_aead *tfm)
{}

static int kmb_ocs_aead_ccm_setauthsize(struct crypto_aead *tfm,
					unsigned int authsize)
{}

static int kmb_ocs_aead_gcm_setauthsize(struct crypto_aead *tfm,
					unsigned int authsize)
{}

static int ocs_sm4_aead_cra_init(struct crypto_aead *tfm)
{}

static void ocs_aead_cra_exit(struct crypto_aead *tfm)
{}

static struct skcipher_engine_alg algs[] =;

static struct aead_engine_alg algs_aead[] =;

static void unregister_aes_algs(struct ocs_aes_dev *aes_dev)
{}

static int register_aes_algs(struct ocs_aes_dev *aes_dev)
{}

/* Device tree driver match. */
static const struct of_device_id kmb_ocs_aes_of_match[] =;

static void kmb_ocs_aes_remove(struct platform_device *pdev)
{}

static int kmb_ocs_aes_probe(struct platform_device *pdev)
{}

/* The OCS driver is a platform device. */
static struct platform_driver kmb_ocs_aes_driver =;

module_platform_driver();

MODULE_DESCRIPTION();
MODULE_LICENSE();

MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();

MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_ECB */

#ifdef CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS
MODULE_ALIAS_CRYPTO();
MODULE_ALIAS_CRYPTO();
#endif /* CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS */