drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
Source file repositories/reference/linux-study-clean/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-cipher.c- Extension
.c- Size
- 18176 bytes
- Lines
- 645
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sun4i-ss.h
Detected Declarations
function Copyrightfunction sun4i_ss_cipher_poll_fallbackfunction sun4i_ss_cipher_pollfunction sun4i_ss_cbc_aes_encryptfunction sun4i_ss_cbc_aes_decryptfunction sun4i_ss_ecb_aes_encryptfunction sun4i_ss_ecb_aes_decryptfunction sun4i_ss_cbc_des_encryptfunction sun4i_ss_cbc_des_decryptfunction sun4i_ss_ecb_des_encryptfunction sun4i_ss_ecb_des_decryptfunction sun4i_ss_cbc_des3_encryptfunction sun4i_ss_cbc_des3_decryptfunction sun4i_ss_ecb_des3_encryptfunction sun4i_ss_ecb_des3_decryptfunction sun4i_ss_cipher_initfunction sun4i_ss_cipher_exitfunction sun4i_ss_aes_setkeyfunction sun4i_ss_des_setkeyfunction sun4i_ss_des3_setkey
Annotated Snippet
if (ileft) {
sg_miter_start(&mi, areq->src, sg_nents(areq->src),
SG_MITER_FROM_SG | SG_MITER_ATOMIC);
if (pi)
sg_miter_skip(&mi, pi);
miter_err = sg_miter_next(&mi);
if (!miter_err || !mi.addr) {
dev_err_ratelimited(ss->dev, "ERROR: sg_miter return null\n");
err = -EINVAL;
goto release_ss;
}
todo = min(rx_cnt, ileft);
todo = min_t(size_t, todo, (mi.length - oi) / 4);
if (todo) {
ileft -= todo;
writesl(ss->base + SS_RXFIFO, mi.addr + oi, todo);
oi += todo * 4;
}
if (oi == mi.length) {
pi += mi.length;
oi = 0;
}
sg_miter_stop(&mi);
}
spaces = readl(ss->base + SS_FCSR);
rx_cnt = SS_RXFIFO_SPACES(spaces);
tx_cnt = SS_TXFIFO_SPACES(spaces);
sg_miter_start(&mo, areq->dst, sg_nents(areq->dst),
SG_MITER_TO_SG | SG_MITER_ATOMIC);
if (po)
sg_miter_skip(&mo, po);
miter_err = sg_miter_next(&mo);
if (!miter_err || !mo.addr) {
dev_err_ratelimited(ss->dev, "ERROR: sg_miter return null\n");
err = -EINVAL;
goto release_ss;
}
todo = min(tx_cnt, oleft);
todo = min_t(size_t, todo, (mo.length - oo) / 4);
if (todo) {
oleft -= todo;
readsl(ss->base + SS_TXFIFO, mo.addr + oo, todo);
oo += todo * 4;
}
if (oo == mo.length) {
oo = 0;
po += mo.length;
}
sg_miter_stop(&mo);
} while (oleft);
if (areq->iv) {
if (mode & SS_DECRYPTION) {
memcpy(areq->iv, ctx->backup_iv, ivsize);
memzero_explicit(ctx->backup_iv, ivsize);
} else {
scatterwalk_map_and_copy(areq->iv, areq->dst, areq->cryptlen - ivsize,
ivsize, 0);
}
}
release_ss:
writel(0, ss->base + SS_CTL);
spin_unlock_irqrestore(&ss->slock, flags);
return err;
}
static int noinline_for_stack sun4i_ss_cipher_poll_fallback(struct skcipher_request *areq)
{
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
struct sun4i_tfm_ctx *op = crypto_skcipher_ctx(tfm);
struct sun4i_cipher_req_ctx *ctx = skcipher_request_ctx(areq);
int err;
struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct sun4i_ss_alg_template *algt;
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
algt = container_of(alg, struct sun4i_ss_alg_template, alg.crypto);
algt->stat_fb++;
}
skcipher_request_set_tfm(&ctx->fallback_req, op->fallback_tfm);
skcipher_request_set_callback(&ctx->fallback_req, areq->base.flags,
areq->base.complete, areq->base.data);
skcipher_request_set_crypt(&ctx->fallback_req, areq->src, areq->dst,
areq->cryptlen, areq->iv);
if (ctx->mode & SS_DECRYPTION)
err = crypto_skcipher_decrypt(&ctx->fallback_req);
Annotation
- Immediate include surface: `sun4i-ss.h`.
- Detected declarations: `function Copyright`, `function sun4i_ss_cipher_poll_fallback`, `function sun4i_ss_cipher_poll`, `function sun4i_ss_cbc_aes_encrypt`, `function sun4i_ss_cbc_aes_decrypt`, `function sun4i_ss_ecb_aes_encrypt`, `function sun4i_ss_ecb_aes_decrypt`, `function sun4i_ss_cbc_des_encrypt`, `function sun4i_ss_cbc_des_decrypt`, `function sun4i_ss_ecb_des_encrypt`.
- 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.
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.