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

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

#include <crypto/engine.h>
#include <crypto/hmac.h>
#include <crypto/internal/hash.h>
#include <crypto/scatterwalk.h>
#include <crypto/sha2.h>
#include <crypto/sm3.h>
#include <linux/completion.h>
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/string.h>

#include "ocs-hcu.h"

#define DRV_NAME

/* Flag marking a final request. */
#define REQ_FINAL
/* Flag marking a HMAC request. */
#define REQ_FLAGS_HMAC
/* Flag set when HW HMAC is being used. */
#define REQ_FLAGS_HMAC_HW
/* Flag set when SW HMAC is being used. */
#define REQ_FLAGS_HMAC_SW

/**
 * struct ocs_hcu_ctx: OCS HCU Transform context.
 * @hcu_dev:	 The OCS HCU device used by the transformation.
 * @key:	 The key (used only for HMAC transformations).
 * @key_len:	 The length of the key.
 * @is_sm3_tfm:  Whether or not this is an SM3 transformation.
 * @is_hmac_tfm: Whether or not this is a HMAC transformation.
 */
struct ocs_hcu_ctx {};

/**
 * struct ocs_hcu_rctx - Context for the request.
 * @hcu_dev:	    OCS HCU device to be used to service the request.
 * @flags:	    Flags tracking request status.
 * @algo:	    Algorithm to use for the request.
 * @blk_sz:	    Block size of the transformation / request.
 * @dig_sz:	    Digest size of the transformation / request.
 * @dma_list:	    OCS DMA linked list.
 * @hash_ctx:	    OCS HCU hashing context.
 * @buffer:	    Buffer to store: partial block of data and SW HMAC
 *		    artifacts (ipad, opad, etc.).
 * @buf_cnt:	    Number of bytes currently stored in the buffer.
 * @buf_dma_addr:   The DMA address of @buffer (when mapped).
 * @buf_dma_count:  The number of bytes in @buffer currently DMA-mapped.
 * @sg:		    Head of the scatterlist entries containing data.
 * @sg_data_total:  Total data in the SG list at any time.
 * @sg_data_offset: Offset into the data of the current individual SG node.
 * @sg_dma_nents:   Number of sg entries mapped in dma_list.
 */
struct ocs_hcu_rctx {};

/**
 * struct ocs_hcu_drv - Driver data
 * @dev_list:	The list of HCU devices.
 * @lock:	The lock protecting dev_list.
 */
struct ocs_hcu_drv {};

static struct ocs_hcu_drv ocs_hcu =;

/*
 * Return the total amount of data in the request; that is: the data in the
 * request buffer + the data in the sg list.
 */
static inline unsigned int kmb_get_total_data(struct ocs_hcu_rctx *rctx)
{}

/* Move remaining content of scatter-gather list to context buffer. */
static int flush_sg_to_ocs_buffer(struct ocs_hcu_rctx *rctx)
{}

static struct ocs_hcu_dev *kmb_ocs_hcu_find_dev(struct ahash_request *req)
{}

/* Free OCS DMA linked list and DMA-able context buffer. */
static void kmb_ocs_hcu_dma_cleanup(struct ahash_request *req,
				    struct ocs_hcu_rctx *rctx)
{}

/*
 * Prepare for DMA operation:
 * - DMA-map request context buffer (if needed)
 * - DMA-map SG list (only the entries to be processed, see note below)
 * - Allocate OCS HCU DMA linked list (number of elements =  SG entries to
 *   process + context buffer (if not empty)).
 * - Add DMA-mapped request context buffer to OCS HCU DMA list.
 * - Add SG entries to DMA list.
 *
 * Note: if this is a final request, we process all the data in the SG list,
 * otherwise we can only process up to the maximum amount of block-aligned data
 * (the remainder will be put into the context buffer and processed in the next
 * request).
 */
static int kmb_ocs_dma_prepare(struct ahash_request *req)
{}

static void kmb_ocs_hcu_secure_cleanup(struct ahash_request *req)
{}

static int kmb_ocs_hcu_handle_queue(struct ahash_request *req)
{}

static int prepare_ipad(struct ahash_request *req)
{}

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

static int kmb_ocs_hcu_init(struct ahash_request *req)
{}

static int kmb_ocs_hcu_update(struct ahash_request *req)
{}

/* Common logic for kmb_ocs_hcu_final() and kmb_ocs_hcu_finup(). */
static int kmb_ocs_hcu_fin_common(struct ahash_request *req)
{}

static int kmb_ocs_hcu_final(struct ahash_request *req)
{}

static int kmb_ocs_hcu_finup(struct ahash_request *req)
{}

static int kmb_ocs_hcu_digest(struct ahash_request *req)
{}

static int kmb_ocs_hcu_export(struct ahash_request *req, void *out)
{}

static int kmb_ocs_hcu_import(struct ahash_request *req, const void *in)
{}

static int kmb_ocs_hcu_setkey(struct crypto_ahash *tfm, const u8 *key,
			      unsigned int keylen)
{}

/* Set request size and initialize tfm context. */
static void __cra_init(struct crypto_tfm *tfm, struct ocs_hcu_ctx *ctx)
{}

static int kmb_ocs_hcu_sha_cra_init(struct crypto_tfm *tfm)
{}

static int kmb_ocs_hcu_sm3_cra_init(struct crypto_tfm *tfm)
{}

static int kmb_ocs_hcu_hmac_sm3_cra_init(struct crypto_tfm *tfm)
{}

static int kmb_ocs_hcu_hmac_cra_init(struct crypto_tfm *tfm)
{}

/* Function called when 'tfm' is de-initialized. */
static void kmb_ocs_hcu_hmac_cra_exit(struct crypto_tfm *tfm)
{}

static struct ahash_engine_alg ocs_hcu_algs[] =;

/* Device tree driver match. */
static const struct of_device_id kmb_ocs_hcu_of_match[] =;
MODULE_DEVICE_TABLE(of, kmb_ocs_hcu_of_match);

static void kmb_ocs_hcu_remove(struct platform_device *pdev)
{}

static int kmb_ocs_hcu_probe(struct platform_device *pdev)
{}

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

module_platform_driver();

MODULE_LICENSE();