drivers/crypto/gemini/sl3516-ce-cipher.c

Source file repositories/reference/linux-study-clean/drivers/crypto/gemini/sl3516-ce-cipher.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/gemini/sl3516-ce-cipher.c
Extension
.c
Size
10581 bytes
Lines
390
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

if ((sg->length % 16) != 0) {
			ce->fallback_mod16++;
			return true;
		}
		if ((sg_dma_len(sg) % 16) != 0) {
			ce->fallback_mod16++;
			return true;
		}
		if (!IS_ALIGNED(sg->offset, 16)) {
			ce->fallback_align16++;
			return true;
		}
		sg = sg_next(sg);
	}
	sg = areq->dst;
	while (sg) {
		if ((sg->length % 16) != 0) {
			ce->fallback_mod16++;
			return true;
		}
		if ((sg_dma_len(sg) % 16) != 0) {
			ce->fallback_mod16++;
			return true;
		}
		if (!IS_ALIGNED(sg->offset, 16)) {
			ce->fallback_align16++;
			return true;
		}
		sg = sg_next(sg);
	}

	/* need same numbers of SG (with same length) for source and destination */
	in_sg = areq->src;
	out_sg = areq->dst;
	while (in_sg && out_sg) {
		if (in_sg->length != out_sg->length) {
			ce->fallback_not_same_len++;
			return true;
		}
		in_sg = sg_next(in_sg);
		out_sg = sg_next(out_sg);
	}
	if (in_sg || out_sg)
		return true;

	return false;
}

static int sl3516_ce_cipher_fallback(struct skcipher_request *areq)
{
	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
	struct sl3516_ce_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm);
	struct sl3516_ce_cipher_req_ctx *rctx = skcipher_request_ctx(areq);
	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
	struct sl3516_ce_alg_template *algt;
	int err;

	algt = container_of(alg, struct sl3516_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);
	skcipher_request_set_crypt(&rctx->fallback_req, areq->src, areq->dst,
				   areq->cryptlen, areq->iv);
	if (rctx->op_dir == CE_DECRYPTION)
		err = crypto_skcipher_decrypt(&rctx->fallback_req);
	else
		err = crypto_skcipher_encrypt(&rctx->fallback_req);
	return err;
}

static int sl3516_ce_cipher(struct skcipher_request *areq)
{
	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
	struct sl3516_ce_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm);
	struct sl3516_ce_dev *ce = op->ce;
	struct sl3516_ce_cipher_req_ctx *rctx = skcipher_request_ctx(areq);
	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
	struct sl3516_ce_alg_template *algt;
	struct scatterlist *sg;
	unsigned int todo, len;
	struct pkt_control_ecb *ecb;
	int nr_sgs = 0;
	int nr_sgd = 0;
	int err = 0;
	int i;

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

Annotation

Implementation Notes