Path: blob/master/drivers/crypto/amcc/crypto4xx_core.h
15111 views
/**1* AMCC SoC PPC4xx Crypto Driver2*3* Copyright (c) 2008 Applied Micro Circuits Corporation.4* All rights reserved. James Hsiao <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* This is the header file for AMCC Crypto offload Linux device driver for17* use with Linux CryptoAPI.1819*/2021#ifndef __CRYPTO4XX_CORE_H__22#define __CRYPTO4XX_CORE_H__2324#include <crypto/internal/hash.h>2526#define PPC460SX_SDR0_SRST 0x20127#define PPC405EX_SDR0_SRST 0x20028#define PPC460EX_SDR0_SRST 0x20129#define PPC460EX_CE_RESET 0x0800000030#define PPC460SX_CE_RESET 0x2000000031#define PPC405EX_CE_RESET 0x000000083233#define CRYPTO4XX_CRYPTO_PRIORITY 30034#define PPC4XX_LAST_PD 6335#define PPC4XX_NUM_PD 6436#define PPC4XX_LAST_GD 102337#define PPC4XX_NUM_GD 102438#define PPC4XX_LAST_SD 6339#define PPC4XX_NUM_SD 6440#define PPC4XX_SD_BUFFER_SIZE 20484142#define PD_ENTRY_INUSE 143#define PD_ENTRY_FREE 044#define ERING_WAS_FULL 0xffffffff4546struct crypto4xx_device;4748struct pd_uinfo {49struct crypto4xx_device *dev;50u32 state;51u32 using_sd;52u32 first_gd; /* first gather discriptor53used by this packet */54u32 num_gd; /* number of gather discriptor55used by this packet */56u32 first_sd; /* first scatter discriptor57used by this packet */58u32 num_sd; /* number of scatter discriptors59used by this packet */60void *sa_va; /* shadow sa, when using cp from ctx->sa */61u32 sa_pa;62void *sr_va; /* state record for shadow sa */63u32 sr_pa;64struct scatterlist *dest_va;65struct crypto_async_request *async_req; /* base crypto request66for this packet */67};6869struct crypto4xx_device {70struct crypto4xx_core_device *core_dev;71char *name;72u64 ce_phy_address;73void __iomem *ce_base;7475void *pdr; /* base address of packet76descriptor ring */77dma_addr_t pdr_pa; /* physical address used to78program ce pdr_base_register */79void *gdr; /* gather descriptor ring */80dma_addr_t gdr_pa; /* physical address used to81program ce gdr_base_register */82void *sdr; /* scatter descriptor ring */83dma_addr_t sdr_pa; /* physical address used to84program ce sdr_base_register */85void *scatter_buffer_va;86dma_addr_t scatter_buffer_pa;87u32 scatter_buffer_size;8889void *shadow_sa_pool; /* pool of memory for sa in pd_uinfo */90dma_addr_t shadow_sa_pool_pa;91void *shadow_sr_pool; /* pool of memory for sr in pd_uinfo */92dma_addr_t shadow_sr_pool_pa;93u32 pdr_tail;94u32 pdr_head;95u32 gdr_tail;96u32 gdr_head;97u32 sdr_tail;98u32 sdr_head;99void *pdr_uinfo;100struct list_head alg_list; /* List of algorithm supported101by this device */102};103104struct crypto4xx_core_device {105struct device *device;106struct platform_device *ofdev;107struct crypto4xx_device *dev;108u32 int_status;109u32 irq;110struct tasklet_struct tasklet;111spinlock_t lock;112};113114struct crypto4xx_ctx {115struct crypto4xx_device *dev;116void *sa_in;117dma_addr_t sa_in_dma_addr;118void *sa_out;119dma_addr_t sa_out_dma_addr;120void *state_record;121dma_addr_t state_record_dma_addr;122u32 sa_len;123u32 offset_to_sr_ptr; /* offset to state ptr, in dynamic sa */124u32 direction;125u32 next_hdr;126u32 save_iv;127u32 pd_ctl_len;128u32 pd_ctl;129u32 bypass;130u32 is_hash;131u32 hash_final;132};133134struct crypto4xx_req_ctx {135struct crypto4xx_device *dev; /* Device in which136operation to send to */137void *sa;138u32 sa_dma_addr;139u16 sa_len;140};141142struct crypto4xx_alg_common {143u32 type;144union {145struct crypto_alg cipher;146struct ahash_alg hash;147} u;148};149150struct crypto4xx_alg {151struct list_head entry;152struct crypto4xx_alg_common alg;153struct crypto4xx_device *dev;154};155156static inline struct crypto4xx_alg *crypto_alg_to_crypto4xx_alg(157struct crypto_alg *x)158{159switch (x->cra_flags & CRYPTO_ALG_TYPE_MASK) {160case CRYPTO_ALG_TYPE_AHASH:161return container_of(__crypto_ahash_alg(x),162struct crypto4xx_alg, alg.u.hash);163}164165return container_of(x, struct crypto4xx_alg, alg.u.cipher);166}167168extern int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);169extern void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);170extern u32 crypto4xx_alloc_sa_rctx(struct crypto4xx_ctx *ctx,171struct crypto4xx_ctx *rctx);172extern void crypto4xx_free_sa_rctx(struct crypto4xx_ctx *rctx);173extern void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);174extern u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);175extern u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);176extern u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);177extern u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);178extern void crypto4xx_memcpy_le(unsigned int *dst,179const unsigned char *buf, int len);180extern u32 crypto4xx_build_pd(struct crypto_async_request *req,181struct crypto4xx_ctx *ctx,182struct scatterlist *src,183struct scatterlist *dst,184unsigned int datalen,185void *iv, u32 iv_len);186extern int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,187const u8 *key, unsigned int keylen);188extern int crypto4xx_encrypt(struct ablkcipher_request *req);189extern int crypto4xx_decrypt(struct ablkcipher_request *req);190extern int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);191extern int crypto4xx_hash_digest(struct ahash_request *req);192extern int crypto4xx_hash_final(struct ahash_request *req);193extern int crypto4xx_hash_update(struct ahash_request *req);194extern int crypto4xx_hash_init(struct ahash_request *req);195#endif196197198