18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CAAM/SEC 4.x driver backend 48c2ecf20Sopenharmony_ci * Private/internal definitions between modules 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright 2008-2011 Freescale Semiconductor, Inc. 78c2ecf20Sopenharmony_ci * Copyright 2019 NXP 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef INTERN_H 118c2ecf20Sopenharmony_ci#define INTERN_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "ctrl.h" 148c2ecf20Sopenharmony_ci#include <crypto/engine.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci/* Currently comes from Kconfig param as a ^2 (driver-required) */ 178c2ecf20Sopenharmony_ci#define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* Kconfig params for interrupt coalescing if selected (else zero) */ 208c2ecf20Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_INTC 218c2ecf20Sopenharmony_ci#define JOBR_INTC JRCFG_ICEN 228c2ecf20Sopenharmony_ci#define JOBR_INTC_TIME_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD 238c2ecf20Sopenharmony_ci#define JOBR_INTC_COUNT_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_COUNT_THLD 248c2ecf20Sopenharmony_ci#else 258c2ecf20Sopenharmony_ci#define JOBR_INTC 0 268c2ecf20Sopenharmony_ci#define JOBR_INTC_TIME_THLD 0 278c2ecf20Sopenharmony_ci#define JOBR_INTC_COUNT_THLD 0 288c2ecf20Sopenharmony_ci#endif 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* 318c2ecf20Sopenharmony_ci * Storage for tracking each in-process entry moving across a ring 328c2ecf20Sopenharmony_ci * Each entry on an output ring needs one of these 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cistruct caam_jrentry_info { 358c2ecf20Sopenharmony_ci void (*callbk)(struct device *dev, u32 *desc, u32 status, void *arg); 368c2ecf20Sopenharmony_ci void *cbkarg; /* Argument per ring entry */ 378c2ecf20Sopenharmony_ci u32 *desc_addr_virt; /* Stored virt addr for postprocessing */ 388c2ecf20Sopenharmony_ci dma_addr_t desc_addr_dma; /* Stored bus addr for done matching */ 398c2ecf20Sopenharmony_ci u32 desc_size; /* Stored size for postprocessing, header derived */ 408c2ecf20Sopenharmony_ci}; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* Private sub-storage for a single JobR */ 438c2ecf20Sopenharmony_cistruct caam_drv_private_jr { 448c2ecf20Sopenharmony_ci struct list_head list_node; /* Job Ring device list */ 458c2ecf20Sopenharmony_ci struct device *dev; 468c2ecf20Sopenharmony_ci int ridx; 478c2ecf20Sopenharmony_ci struct caam_job_ring __iomem *rregs; /* JobR's register space */ 488c2ecf20Sopenharmony_ci struct tasklet_struct irqtask; 498c2ecf20Sopenharmony_ci int irq; /* One per queue */ 508c2ecf20Sopenharmony_ci bool hwrng; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci /* Number of scatterlist crypt transforms active on the JobR */ 538c2ecf20Sopenharmony_ci atomic_t tfm_count ____cacheline_aligned; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci /* Job ring info */ 568c2ecf20Sopenharmony_ci struct caam_jrentry_info *entinfo; /* Alloc'ed 1 per ring entry */ 578c2ecf20Sopenharmony_ci spinlock_t inplock ____cacheline_aligned; /* Input ring index lock */ 588c2ecf20Sopenharmony_ci u32 inpring_avail; /* Number of free entries in input ring */ 598c2ecf20Sopenharmony_ci int head; /* entinfo (s/w ring) head index */ 608c2ecf20Sopenharmony_ci void *inpring; /* Base of input ring, alloc 618c2ecf20Sopenharmony_ci * DMA-safe */ 628c2ecf20Sopenharmony_ci int out_ring_read_index; /* Output index "tail" */ 638c2ecf20Sopenharmony_ci int tail; /* entinfo (s/w ring) tail index */ 648c2ecf20Sopenharmony_ci void *outring; /* Base of output ring, DMA-safe */ 658c2ecf20Sopenharmony_ci struct crypto_engine *engine; 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci * Driver-private storage for a single CAAM block instance 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_cistruct caam_drv_private { 728c2ecf20Sopenharmony_ci /* Physical-presence section */ 738c2ecf20Sopenharmony_ci struct caam_ctrl __iomem *ctrl; /* controller region */ 748c2ecf20Sopenharmony_ci struct caam_deco __iomem *deco; /* DECO/CCB views */ 758c2ecf20Sopenharmony_ci struct caam_assurance __iomem *assure; 768c2ecf20Sopenharmony_ci struct caam_queue_if __iomem *qi; /* QI control region */ 778c2ecf20Sopenharmony_ci struct caam_job_ring __iomem *jr[4]; /* JobR's register space */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci struct iommu_domain *domain; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci /* 828c2ecf20Sopenharmony_ci * Detected geometry block. Filled in from device tree if powerpc, 838c2ecf20Sopenharmony_ci * or from register-based version detection code 848c2ecf20Sopenharmony_ci */ 858c2ecf20Sopenharmony_ci u8 total_jobrs; /* Total Job Rings in device */ 868c2ecf20Sopenharmony_ci u8 qi_present; /* Nonzero if QI present in device */ 878c2ecf20Sopenharmony_ci u8 mc_en; /* Nonzero if MC f/w is active */ 888c2ecf20Sopenharmony_ci int secvio_irq; /* Security violation interrupt number */ 898c2ecf20Sopenharmony_ci int virt_en; /* Virtualization enabled in CAAM */ 908c2ecf20Sopenharmony_ci int era; /* CAAM Era (internal HW revision) */ 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci#define RNG4_MAX_HANDLES 2 938c2ecf20Sopenharmony_ci /* RNG4 block */ 948c2ecf20Sopenharmony_ci u32 rng4_sh_init; /* This bitmap shows which of the State 958c2ecf20Sopenharmony_ci Handles of the RNG4 block are initialized 968c2ecf20Sopenharmony_ci by this driver */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci struct clk_bulk_data *clks; 998c2ecf20Sopenharmony_ci int num_clks; 1008c2ecf20Sopenharmony_ci /* 1018c2ecf20Sopenharmony_ci * debugfs entries for developer view into driver/device 1028c2ecf20Sopenharmony_ci * variables at runtime. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 1058c2ecf20Sopenharmony_ci struct dentry *ctl; /* controller dir */ 1068c2ecf20Sopenharmony_ci struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap; 1078c2ecf20Sopenharmony_ci#endif 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciint caam_algapi_init(struct device *dev); 1138c2ecf20Sopenharmony_civoid caam_algapi_exit(void); 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci#else 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_cistatic inline int caam_algapi_init(struct device *dev) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci return 0; 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic inline void caam_algapi_exit(void) 1238c2ecf20Sopenharmony_ci{ 1248c2ecf20Sopenharmony_ci} 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API */ 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciint caam_algapi_hash_init(struct device *dev); 1318c2ecf20Sopenharmony_civoid caam_algapi_hash_exit(void); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#else 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic inline int caam_algapi_hash_init(struct device *dev) 1368c2ecf20Sopenharmony_ci{ 1378c2ecf20Sopenharmony_ci return 0; 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_cistatic inline void caam_algapi_hash_exit(void) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci} 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */ 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ciint caam_pkc_init(struct device *dev); 1498c2ecf20Sopenharmony_civoid caam_pkc_exit(void); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#else 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic inline int caam_pkc_init(struct device *dev) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci return 0; 1568c2ecf20Sopenharmony_ci} 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic inline void caam_pkc_exit(void) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci} 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */ 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci#ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ciint caam_rng_init(struct device *dev); 1678c2ecf20Sopenharmony_civoid caam_rng_exit(struct device *dev); 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci#else 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_cistatic inline int caam_rng_init(struct device *dev) 1728c2ecf20Sopenharmony_ci{ 1738c2ecf20Sopenharmony_ci return 0; 1748c2ecf20Sopenharmony_ci} 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_cistatic inline void caam_rng_exit(struct device *dev) {} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci#endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API */ 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#ifdef CONFIG_CAAM_QI 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ciint caam_qi_algapi_init(struct device *dev); 1838c2ecf20Sopenharmony_civoid caam_qi_algapi_exit(void); 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#else 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistatic inline int caam_qi_algapi_init(struct device *dev) 1888c2ecf20Sopenharmony_ci{ 1898c2ecf20Sopenharmony_ci return 0; 1908c2ecf20Sopenharmony_ci} 1918c2ecf20Sopenharmony_ci 1928c2ecf20Sopenharmony_cistatic inline void caam_qi_algapi_exit(void) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci} 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci#endif /* CONFIG_CAAM_QI */ 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_cistatic inline u64 caam_get_dma_mask(struct device *dev) 1998c2ecf20Sopenharmony_ci{ 2008c2ecf20Sopenharmony_ci struct device_node *nprop = dev->of_node; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci if (caam_ptr_sz != sizeof(u64)) 2038c2ecf20Sopenharmony_ci return DMA_BIT_MASK(32); 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci if (caam_dpaa2) 2068c2ecf20Sopenharmony_ci return DMA_BIT_MASK(49); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ci if (of_device_is_compatible(nprop, "fsl,sec-v5.0-job-ring") || 2098c2ecf20Sopenharmony_ci of_device_is_compatible(nprop, "fsl,sec-v5.0")) 2108c2ecf20Sopenharmony_ci return DMA_BIT_MASK(40); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci return DMA_BIT_MASK(36); 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci#endif /* INTERN_H */ 217