forked from Minki/linux
d075c0c1be
API: - Test in-place en/decryption with two sglists in testmgr. - Fix process vs. softirq race in cryptd. Algorithms: - Add arm64 acceleration for sm4. - Add s390 acceleration for chacha20. Drivers: - Add polarfire soc hwrng support in mpsf. - Add support for TI SoC AM62x in sa2ul. - Add support for ATSHA204 cryptochip in atmel-sha204a. - Add support for PRNG in caam. - Restore support for storage encryption in qat. - Restore support for storage encryption in hisilicon/sec. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEn51F/lCuNhUwmDeSxycdCkmxi6cFAmKQs9cACgkQxycdCkmx i6deOA//bwX9JvxI+SiwEK/1u5GX9VHtCpAa1rMOqhfl8UrBfo0516M/CeUDjW0J t1yoq0JUoIfYrEbSJqxXTnfG6+fJ1WsQtT3jd1/64nrwVk+w6OdMBTt48B9GF0R5 ZjWG7zmjKZcspZqSwib/gxbehJ+IX7dYdUsrlUQq3q64qpQEqxTgqsfyiY3LP24N lng6weLudrFA5Xa8pVCmrCnOH3J7kPGA4iGqTGNV8Qx3ud9CUWSc8BT4VdqU8t2f opaYL3s9oKc+xtS4yrOnfV+Wa/A8K6AuBYeODFtLe41FSpGYgaPslcGqEGwAHNpL 0HjqQdC+4auimGJxyVcef7QVMCpGqIfKqYu7sYXuNROylPjqMNa/DRL64csaDxDn WiheV9RSc1zfchxHC4IjnfwE7nNDVYnYrZ1awyvQ9xvAoh7bldiEe6k/UlWi3L0F nejJRFPXOSZ2GfJjrVNsv5lSWZCNWRBzOehN4D6EMJjEfM/G3/30Q0qwif39QWVj r1gYQWmZuCa9mL7enga1XavebQ6cLXggR4sTxEmV7Sta6AJ+RqNqOnrPecEF5Avr eSYQLxor+jvhaepcKhyDOF4dKGGJIWaEi00GC83yZ8hApVbfWoVh8Nfxmp8TUEzH UUJFvrFLNTBOwRoz3fIT57vaFxksQREZwlcQ77xVAeg8S+BOB4o= =oVRe -----END PGP SIGNATURE----- Merge tag 'v5.19-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6 Pull crypto updates from Herbert Xu: "API: - Test in-place en/decryption with two sglists in testmgr - Fix process vs softirq race in cryptd Algorithms: - Add arm64 acceleration for sm4 - Add s390 acceleration for chacha20 Drivers: - Add polarfire soc hwrng support in mpsf - Add support for TI SoC AM62x in sa2ul - Add support for ATSHA204 cryptochip in atmel-sha204a - Add support for PRNG in caam - Restore support for storage encryption in qat - Restore support for storage encryption in hisilicon/sec" * tag 'v5.19-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (116 commits) hwrng: omap3-rom - fix using wrong clk_disable() in omap_rom_rng_runtime_resume() crypto: hisilicon/sec - delete the flag CRYPTO_ALG_ALLOCATES_MEMORY crypto: qat - add support for 401xx devices crypto: qat - re-enable registration of algorithms crypto: qat - honor CRYPTO_TFM_REQ_MAY_SLEEP flag crypto: qat - add param check for DH crypto: qat - add param check for RSA crypto: qat - remove dma_free_coherent() for DH crypto: qat - remove dma_free_coherent() for RSA crypto: qat - fix memory leak in RSA crypto: qat - add backlog mechanism crypto: qat - refactor submission logic crypto: qat - use pre-allocated buffers in datapath crypto: qat - set to zero DH parameters before free crypto: s390 - add crypto library interface for ChaCha20 crypto: talitos - Uniform coding style with defined variable crypto: octeontx2 - simplify the return expression of otx2_cpt_aead_cbc_aes_sha_setkey() crypto: cryptd - Protect per-CPU resource by disabling BH. crypto: sun8i-ce - do not fallback if cryptlen is less than sg length crypto: sun8i-ce - rework debugging ...
241 lines
5.9 KiB
C
241 lines
5.9 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* CAAM/SEC 4.x driver backend
|
|
* Private/internal definitions between modules
|
|
*
|
|
* Copyright 2008-2011 Freescale Semiconductor, Inc.
|
|
* Copyright 2019 NXP
|
|
*/
|
|
|
|
#ifndef INTERN_H
|
|
#define INTERN_H
|
|
|
|
#include "ctrl.h"
|
|
#include <crypto/engine.h>
|
|
|
|
/* Currently comes from Kconfig param as a ^2 (driver-required) */
|
|
#define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE)
|
|
|
|
/*
|
|
* Maximum size for crypto-engine software queue based on Job Ring
|
|
* size (JOBR_DEPTH) and a THRESHOLD (reserved for the non-crypto-API
|
|
* requests that are not passed through crypto-engine)
|
|
*/
|
|
#define THRESHOLD 15
|
|
#define CRYPTO_ENGINE_MAX_QLEN (JOBR_DEPTH - THRESHOLD)
|
|
|
|
/* Kconfig params for interrupt coalescing if selected (else zero) */
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_INTC
|
|
#define JOBR_INTC JRCFG_ICEN
|
|
#define JOBR_INTC_TIME_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD
|
|
#define JOBR_INTC_COUNT_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_COUNT_THLD
|
|
#else
|
|
#define JOBR_INTC 0
|
|
#define JOBR_INTC_TIME_THLD 0
|
|
#define JOBR_INTC_COUNT_THLD 0
|
|
#endif
|
|
|
|
/*
|
|
* Storage for tracking each in-process entry moving across a ring
|
|
* Each entry on an output ring needs one of these
|
|
*/
|
|
struct caam_jrentry_info {
|
|
void (*callbk)(struct device *dev, u32 *desc, u32 status, void *arg);
|
|
void *cbkarg; /* Argument per ring entry */
|
|
u32 *desc_addr_virt; /* Stored virt addr for postprocessing */
|
|
dma_addr_t desc_addr_dma; /* Stored bus addr for done matching */
|
|
u32 desc_size; /* Stored size for postprocessing, header derived */
|
|
};
|
|
|
|
/* Private sub-storage for a single JobR */
|
|
struct caam_drv_private_jr {
|
|
struct list_head list_node; /* Job Ring device list */
|
|
struct device *dev;
|
|
int ridx;
|
|
struct caam_job_ring __iomem *rregs; /* JobR's register space */
|
|
struct tasklet_struct irqtask;
|
|
int irq; /* One per queue */
|
|
bool hwrng;
|
|
|
|
/* Number of scatterlist crypt transforms active on the JobR */
|
|
atomic_t tfm_count ____cacheline_aligned;
|
|
|
|
/* Job ring info */
|
|
struct caam_jrentry_info *entinfo; /* Alloc'ed 1 per ring entry */
|
|
spinlock_t inplock ____cacheline_aligned; /* Input ring index lock */
|
|
u32 inpring_avail; /* Number of free entries in input ring */
|
|
int head; /* entinfo (s/w ring) head index */
|
|
void *inpring; /* Base of input ring, alloc
|
|
* DMA-safe */
|
|
int out_ring_read_index; /* Output index "tail" */
|
|
int tail; /* entinfo (s/w ring) tail index */
|
|
void *outring; /* Base of output ring, DMA-safe */
|
|
struct crypto_engine *engine;
|
|
};
|
|
|
|
/*
|
|
* Driver-private storage for a single CAAM block instance
|
|
*/
|
|
struct caam_drv_private {
|
|
/* Physical-presence section */
|
|
struct caam_ctrl __iomem *ctrl; /* controller region */
|
|
struct caam_deco __iomem *deco; /* DECO/CCB views */
|
|
struct caam_assurance __iomem *assure;
|
|
struct caam_queue_if __iomem *qi; /* QI control region */
|
|
struct caam_job_ring __iomem *jr[4]; /* JobR's register space */
|
|
|
|
struct iommu_domain *domain;
|
|
|
|
/*
|
|
* Detected geometry block. Filled in from device tree if powerpc,
|
|
* or from register-based version detection code
|
|
*/
|
|
u8 total_jobrs; /* Total Job Rings in device */
|
|
u8 qi_present; /* Nonzero if QI present in device */
|
|
u8 blob_present; /* Nonzero if BLOB support present in device */
|
|
u8 mc_en; /* Nonzero if MC f/w is active */
|
|
int secvio_irq; /* Security violation interrupt number */
|
|
int virt_en; /* Virtualization enabled in CAAM */
|
|
int era; /* CAAM Era (internal HW revision) */
|
|
|
|
#define RNG4_MAX_HANDLES 2
|
|
/* RNG4 block */
|
|
u32 rng4_sh_init; /* This bitmap shows which of the State
|
|
Handles of the RNG4 block are initialized
|
|
by this driver */
|
|
|
|
struct clk_bulk_data *clks;
|
|
int num_clks;
|
|
/*
|
|
* debugfs entries for developer view into driver/device
|
|
* variables at runtime.
|
|
*/
|
|
#ifdef CONFIG_DEBUG_FS
|
|
struct dentry *ctl; /* controller dir */
|
|
struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;
|
|
#endif
|
|
};
|
|
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API
|
|
|
|
int caam_algapi_init(struct device *dev);
|
|
void caam_algapi_exit(void);
|
|
|
|
#else
|
|
|
|
static inline int caam_algapi_init(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_algapi_exit(void)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API */
|
|
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API
|
|
|
|
int caam_algapi_hash_init(struct device *dev);
|
|
void caam_algapi_hash_exit(void);
|
|
|
|
#else
|
|
|
|
static inline int caam_algapi_hash_init(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_algapi_hash_exit(void)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */
|
|
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API
|
|
|
|
int caam_pkc_init(struct device *dev);
|
|
void caam_pkc_exit(void);
|
|
|
|
#else
|
|
|
|
static inline int caam_pkc_init(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_pkc_exit(void)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */
|
|
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API
|
|
|
|
int caam_rng_init(struct device *dev);
|
|
void caam_rng_exit(struct device *dev);
|
|
|
|
#else
|
|
|
|
static inline int caam_rng_init(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_rng_exit(struct device *dev) {}
|
|
|
|
#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API */
|
|
|
|
#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PRNG_API
|
|
|
|
int caam_prng_register(struct device *dev);
|
|
void caam_prng_unregister(void *data);
|
|
|
|
#else
|
|
|
|
static inline int caam_prng_register(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_prng_unregister(void *data) {}
|
|
#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PRNG_API */
|
|
|
|
#ifdef CONFIG_CAAM_QI
|
|
|
|
int caam_qi_algapi_init(struct device *dev);
|
|
void caam_qi_algapi_exit(void);
|
|
|
|
#else
|
|
|
|
static inline int caam_qi_algapi_init(struct device *dev)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void caam_qi_algapi_exit(void)
|
|
{
|
|
}
|
|
|
|
#endif /* CONFIG_CAAM_QI */
|
|
|
|
static inline u64 caam_get_dma_mask(struct device *dev)
|
|
{
|
|
struct device_node *nprop = dev->of_node;
|
|
|
|
if (caam_ptr_sz != sizeof(u64))
|
|
return DMA_BIT_MASK(32);
|
|
|
|
if (caam_dpaa2)
|
|
return DMA_BIT_MASK(49);
|
|
|
|
if (of_device_is_compatible(nprop, "fsl,sec-v5.0-job-ring") ||
|
|
of_device_is_compatible(nprop, "fsl,sec-v5.0"))
|
|
return DMA_BIT_MASK(40);
|
|
|
|
return DMA_BIT_MASK(36);
|
|
}
|
|
|
|
|
|
#endif /* INTERN_H */
|