/* * Cryptographic API. * * Driver for EIP97 SHA1/SHA2(HMAC) acceleration. * * Copyright (c) 2016 Ryder Lee <ryder.lee@mediatek.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Some ideas are from atmel-sha.c and omap-sham.c drivers. */#include<crypto/sha.h>#include"mtk-platform.h"#define SHA_ALIGN_MSK (sizeof(u32) - 1)#define SHA_QUEUE_SIZE 512#define SHA_TMP_BUF_SIZE 512#define SHA_BUF_SIZE ((u32)PAGE_SIZE)#define SHA_OP_UPDATE 1#define SHA_OP_FINAL 2#define SHA_DATA_LEN_MSK cpu_to_le32(GENMASK(16, 0))/* SHA command token */#define SHA_CT_SIZE 5#define SHA_CT_CTRL_HDR cpu_to_le32(0x02220000)#define SHA_CMD0 cpu_to_le32(0x03020000)#define SHA_CMD1 cpu_to_le32(0x21060000)#define SHA_CMD2 cpu_to_le32(0xe0e63802)/* SHA transform information */#define SHA_TFM_HASH cpu_to_le32(0x2 << 0)#define SHA_TFM_INNER_DIG cpu_to_le32(0x1 << 21)#define SHA_TFM_SIZE(x) cpu_to_le32((x) << 8)#define SHA_TFM_START cpu_to_le32(0x1 << 4)#define SHA_TFM_CONTINUE cpu_to_le32(0x1 << 5)#define SHA_TFM_HASH_STORE cpu_to_le32(0x1 << 19)#define SHA_TFM_SHA1 cpu_to_le32(0x2 << 23)#define SHA_TFM_SHA256 cpu_to_le32(0x3 << 23)#define SHA_TFM_SHA224 cpu_to_le32(0x4 << 23)#define SHA_TFM_SHA512 cpu_to_le32(0x5 << 23)#define SHA_TFM_SHA384 cpu_to_le32(0x6 << 23)#define SHA_TFM_DIGEST(x) cpu_to_le32(((x) & GENMASK(3, 0)) << 24)/* SHA flags */#define SHA_FLAGS_BUSY BIT(0)#define SHA_FLAGS_FINAL BIT(1)#define SHA_FLAGS_FINUP BIT(2)#define SHA_FLAGS_SG BIT(3)#define SHA_FLAGS_ALGO_MSK GENMASK(8, 4)#define SHA_FLAGS_SHA1 BIT(4)#define SHA_FLAGS_SHA224 BIT(5)#define SHA_FLAGS_SHA256 BIT(6)#define SHA_FLAGS_SHA384 BIT(7)#define SHA_FLAGS_SHA512 BIT(8)#define SHA_FLAGS_HMAC BIT(9)#define SHA_FLAGS_PAD BIT(10)/** * mtk_sha_ct is a set of hardware instructions(command token) * that are used to control engine's processing flow of SHA, * and it contains the first two words of transform state. */structmtk_sha_ct{__le32ctrl[2];__le32cmd[3];};/** * mtk_sha_tfm is used to define SHA transform state * and store result digest that produced by engine. */structmtk_sha_tfm{__le32ctrl[2];__le32digest[SIZE_IN_WORDS(SHA512_DIGEST_SIZE)];};/** * mtk_sha_info consists of command token and transform state * of SHA, its role is similar to mtk_aes_info. */structmtk_sha_info{structmtk_sha_ctct;structmtk_sha_tfmtfm;};structmtk_sha_reqctx{structmtk_sha_infoinfo;unsignedlongflags;unsignedlongop;u64digcnt;boolstart;size_tbufcnt;dma_addr_tdma_addr;__le32ct_hdr;u32ct_size;dma_addr_tct_dma;dma_addr_ttfm_dma;/* Walk state */structscatterlist*sg;u32offset;/* Offset in current sg */u32total;/* Total request */