drivers/crypto/intel/qat/qat_common/qat_comp_algs.c

Source file repositories/reference/linux-study-clean/drivers/crypto/intel/qat/qat_common/qat_comp_algs.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c
Extension
.c
Size
19317 bytes
Lines
760
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

struct qat_zstd_scratch {
	size_t		cctx_buffer_size;
	void		*lz4s;
	void		*literals;
	void		*out_seqs;
	void		*workspace;
	ZSTD_CCtx	*ctx;
};

static void *qat_zstd_alloc_scratch(void)
{
	struct qat_zstd_scratch *scratch;
	ZSTD_parameters params;
	size_t cctx_size;
	ZSTD_CCtx *ctx;
	size_t zret;
	int ret;

	ret = -ENOMEM;
	scratch = kzalloc_obj(*scratch);
	if (!scratch)
		return ERR_PTR(ret);

	scratch->lz4s = kvmalloc(QAT_ZSTD_SCRATCH_SIZE, GFP_KERNEL);
	if (!scratch->lz4s)
		goto error;

	scratch->literals = kvmalloc(QAT_ZSTD_SCRATCH_SIZE, GFP_KERNEL);
	if (!scratch->literals)
		goto error;

	scratch->out_seqs = kvcalloc(QAT_MAX_SEQUENCES, sizeof(ZSTD_Sequence),
				     GFP_KERNEL);
	if (!scratch->out_seqs)
		goto error;

	params = zstd_get_params(zstd_max_clevel(), QAT_ZSTD_SCRATCH_SIZE);
	cctx_size = zstd_cctx_workspace_bound(&params.cParams);

	scratch->workspace = kvmalloc(cctx_size, GFP_KERNEL | __GFP_ZERO);
	if (!scratch->workspace)
		goto error;

	ret = -EINVAL;
	ctx = zstd_init_cctx(scratch->workspace, cctx_size);
	if (!ctx)
		goto error;

	scratch->ctx = ctx;
	scratch->cctx_buffer_size = cctx_size;

	zret = zstd_cctx_set_param(ctx, ZSTD_c_blockDelimiters, ZSTD_sf_explicitBlockDelimiters);
	if (zstd_is_error(zret))
		goto error;

	return scratch;

error:
	kvfree(scratch->lz4s);
	kvfree(scratch->literals);
	kvfree(scratch->out_seqs);
	kvfree(scratch->workspace);
	kfree(scratch);
	return ERR_PTR(ret);
}

static void qat_zstd_free_scratch(void *ctx)
{
	struct qat_zstd_scratch *scratch = ctx;

	if (!scratch)
		return;

	kvfree(scratch->lz4s);
	kvfree(scratch->literals);
	kvfree(scratch->out_seqs);
	kvfree(scratch->workspace);
	kfree(scratch);
}

static struct crypto_acomp_streams qat_zstd_streams = {
	.alloc_ctx = qat_zstd_alloc_scratch,
	.free_ctx = qat_zstd_free_scratch,
};

enum direction {
	DECOMPRESSION = 0,
	COMPRESSION = 1,
};

Annotation

Implementation Notes