drivers/crypto/caam/blob_gen.c

Source file repositories/reference/linux-study-clean/drivers/crypto/caam/blob_gen.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/caam/blob_gen.c
Extension
.c
Size
6880 bytes
Lines
247
Domain
Driver Families
Bucket
drivers/crypto
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

struct caam_blob_priv {
	struct device jrdev;
};

struct caam_blob_job_result {
	int err;
	struct completion completion;
};

static void caam_blob_job_done(struct device *dev, u32 *desc, u32 err, void *context)
{
	struct caam_blob_job_result *res = context;
	int ecode = 0;

	dev_dbg(dev, "%s %d: err 0x%x\n", __func__, __LINE__, err);

	if (err)
		ecode = caam_jr_strstatus(dev, err);

	res->err = ecode;

	/*
	 * Upon completion, desc points to a buffer containing a CAAM job
	 * descriptor which encapsulates data into an externally-storable
	 * blob.
	 */
	complete(&res->completion);
}

static u32 check_caam_state(struct device *jrdev)
{
	const struct caam_drv_private *ctrlpriv;

	ctrlpriv = dev_get_drvdata(jrdev->parent);
	return FIELD_GET(CSTA_MOO, rd_reg32(&ctrlpriv->jr[0]->perfmon.status));
}

int caam_process_blob(struct caam_blob_priv *priv,
		      struct caam_blob_info *info, bool encap)
{
	struct caam_blob_job_result testres;
	struct device *jrdev = &priv->jrdev;
	dma_addr_t dma_in, dma_out;
	int op = OP_PCLID_BLOB;
	int hwbk_caam_ovhd = 0;
	size_t output_len;
	u32 *desc;
	u32 moo;
	int ret;
	int len;

	if (info->key_mod_len > CAAM_BLOB_KEYMOD_LENGTH)
		return -EINVAL;

	if (encap) {
		op |= OP_TYPE_ENCAP_PROTOCOL;
		output_len = info->input_len + CAAM_BLOB_OVERHEAD;
	} else {
		op |= OP_TYPE_DECAP_PROTOCOL;
		output_len = info->input_len - CAAM_BLOB_OVERHEAD;
		info->output_len = output_len;
	}

	if (encap && info->pkey_info.is_pkey) {
		op |= OP_PCL_BLOB_BLACK;
		if (info->pkey_info.key_enc_algo == CAAM_ENC_ALGO_CCM) {
			op |= OP_PCL_BLOB_EKT;
			hwbk_caam_ovhd = CAAM_CCM_OVERHEAD;
		}
		if ((info->input_len + hwbk_caam_ovhd) > MAX_KEY_SIZE)
			return -EINVAL;

		len = info->input_len + hwbk_caam_ovhd;
	} else {
		len = info->input_len;
	}

	desc = kzalloc(CAAM_BLOB_DESC_BYTES_MAX, GFP_KERNEL);
	if (!desc)
		return -ENOMEM;

	dma_in = dma_map_single(jrdev, info->input, len,
				encap ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
	if (dma_mapping_error(jrdev, dma_in)) {
		dev_err(jrdev, "unable to map input DMA buffer\n");
		ret = -ENOMEM;
		goto out_free;
	}

	dma_out = dma_map_single(jrdev, info->output, output_len,

Annotation

Implementation Notes