drivers/crypto/caam/caamalg_qi.c
Source file repositories/reference/linux-study-clean/drivers/crypto/caam/caamalg_qi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/caam/caamalg_qi.c- Extension
.c- Size
- 73003 bytes
- Lines
- 2744
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
compat.hctrl.hregs.hintern.hdesc_constr.herror.hsg_sw_qm.hkey_gen.hqi.hjr.hcaamalg_desc.hcrypto/xts.hlinux/unaligned.hlinux/device.hlinux/err.hlinux/dma-mapping.hlinux/kernel.hlinux/string.h
Detected Declarations
struct caam_alg_entrystruct caam_aead_algstruct caam_skcipher_algstruct caam_ctxstruct caam_skcipher_req_ctxstruct aead_edescstruct skcipher_edescfunction aead_set_sh_descfunction aead_setauthsizefunction aead_setkeyfunction des3_aead_setkeyfunction gcm_set_sh_descfunction gcm_setauthsizefunction gcm_setkeyfunction rfc4106_set_sh_descfunction rfc4106_setauthsizefunction rfc4106_setkeyfunction rfc4543_set_sh_descfunction rfc4543_setauthsizefunction rfc4543_setkeyfunction skcipher_setkeyfunction aes_skcipher_setkeyfunction rfc3686_skcipher_setkeyfunction ctr_skcipher_setkeyfunction des3_skcipher_setkeyfunction des_skcipher_setkeyfunction xts_skcipher_setkeyfunction caam_unmapfunction aead_unmapfunction skcipher_unmapfunction aead_donefunction aead_cryptfunction aead_encryptfunction aead_decryptfunction ipsec_gcm_encryptfunction ipsec_gcm_decryptfunction skcipher_donefunction xts_skcipher_ivsizefunction skcipher_cryptfunction skcipher_encryptfunction skcipher_decryptfunction caam_init_commonfunction caam_cra_initfunction caam_aead_initfunction caam_exit_commonfunction caam_cra_exitfunction caam_aead_exitfunction caam_qi_algapi_exit
Annotated Snippet
struct caam_alg_entry {
int class1_alg_type;
int class2_alg_type;
bool rfc3686;
bool geniv;
bool nodkp;
};
struct caam_aead_alg {
struct aead_alg aead;
struct caam_alg_entry caam;
bool registered;
};
struct caam_skcipher_alg {
struct skcipher_alg skcipher;
struct caam_alg_entry caam;
bool registered;
};
/*
* per-session context
*/
struct caam_ctx {
struct device *jrdev;
u32 sh_desc_enc[DESC_MAX_USED_LEN];
u32 sh_desc_dec[DESC_MAX_USED_LEN];
u8 key[CAAM_MAX_KEY_SIZE];
dma_addr_t key_dma;
enum dma_data_direction dir;
struct alginfo adata;
struct alginfo cdata;
unsigned int authsize;
struct device *qidev;
spinlock_t lock; /* Protects multiple init of driver context */
struct caam_drv_ctx *drv_ctx[NUM_OP];
bool xts_key_fallback;
struct crypto_skcipher *fallback;
};
struct caam_skcipher_req_ctx {
struct skcipher_request fallback_req;
};
static int aead_set_sh_desc(struct crypto_aead *aead)
{
struct caam_aead_alg *alg = container_of(crypto_aead_alg(aead),
typeof(*alg), aead);
struct caam_ctx *ctx = crypto_aead_ctx_dma(aead);
unsigned int ivsize = crypto_aead_ivsize(aead);
u32 ctx1_iv_off = 0;
u32 *nonce = NULL;
unsigned int data_len[2];
u32 inl_mask;
const bool ctr_mode = ((ctx->cdata.algtype & OP_ALG_AAI_MASK) ==
OP_ALG_AAI_CTR_MOD128);
const bool is_rfc3686 = alg->caam.rfc3686;
struct caam_drv_private *ctrlpriv = dev_get_drvdata(ctx->jrdev->parent);
if (!ctx->cdata.keylen || !ctx->authsize)
return 0;
/*
* AES-CTR needs to load IV in CONTEXT1 reg
* at an offset of 128bits (16bytes)
* CONTEXT1[255:128] = IV
*/
if (ctr_mode)
ctx1_iv_off = 16;
/*
* RFC3686 specific:
* CONTEXT1[255:128] = {NONCE, IV, COUNTER}
*/
if (is_rfc3686) {
ctx1_iv_off = 16 + CTR_RFC3686_NONCE_SIZE;
nonce = (u32 *)((void *)ctx->key + ctx->adata.keylen_pad +
ctx->cdata.keylen - CTR_RFC3686_NONCE_SIZE);
}
/*
* In case |user key| > |derived key|, using DKP<imm,imm> would result
* in invalid opcodes (last bytes of user key) in the resulting
* descriptor. Use DKP<ptr,imm> instead => both virtual and dma key
* addresses are needed.
*/
ctx->adata.key_virt = ctx->key;
ctx->adata.key_dma = ctx->key_dma;
ctx->cdata.key_virt = ctx->key + ctx->adata.keylen_pad;
Annotation
- Immediate include surface: `compat.h`, `ctrl.h`, `regs.h`, `intern.h`, `desc_constr.h`, `error.h`, `sg_sw_qm.h`, `key_gen.h`.
- Detected declarations: `struct caam_alg_entry`, `struct caam_aead_alg`, `struct caam_skcipher_alg`, `struct caam_ctx`, `struct caam_skcipher_req_ctx`, `struct aead_edesc`, `struct skcipher_edesc`, `function aead_set_sh_desc`, `function aead_setauthsize`, `function aead_setkey`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.