drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c

Source file repositories/reference/linux-study-clean/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c
Extension
.c
Size
14239 bytes
Lines
513
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.

Dependency Surface

Detected Declarations

Annotated Snippet

sg_nents_for_len(areq->dst, areq->cryptlen) > MAX_SG) {
		if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
			algt->stat_fb_maxsg++;

		return true;
	}

	if (areq->cryptlen < crypto_skcipher_ivsize(tfm)) {
		if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
			algt->stat_fb_leniv++;

		return true;
	}

	if (areq->cryptlen == 0) {
		if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
			algt->stat_fb_len0++;

		return true;
	}

	if (areq->cryptlen % 16) {
		if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
			algt->stat_fb_mod16++;

		return true;
	}

	len = areq->cryptlen;
	sg = areq->src;
	while (sg) {
		if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
			if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
				algt->stat_fb_srcali++;

			return true;
		}
		todo = min(len, sg->length);
		if (todo % 4) {
			if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
				algt->stat_fb_srclen++;

			return true;
		}
		len -= todo;
		sg = sg_next(sg);
	}

	len = areq->cryptlen;
	sg = areq->dst;
	while (sg) {
		if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
			if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
				algt->stat_fb_dstali++;

			return true;
		}
		todo = min(len, sg->length);
		if (todo % 4) {
			if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
				algt->stat_fb_dstlen++;

			return true;
		}
		len -= todo;
		sg = sg_next(sg);
	}
	return false;
}

static int sun8i_ce_cipher_fallback(struct skcipher_request *areq)
{
	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
	struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm);
	struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq);
	int err;

	if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG)) {
		struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
		struct sun8i_ce_alg_template *algt;

		algt = container_of(alg, struct sun8i_ce_alg_template,
				    alg.skcipher.base);

		algt->stat_fb++;
	}

	skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
	skcipher_request_set_callback(&rctx->fallback_req, areq->base.flags,
				      areq->base.complete, areq->base.data);

Annotation

Implementation Notes