linux/drivers/crypto/caam/desc_constr.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * caam descriptor construction helper functions
 *
 * Copyright 2008-2012 Freescale Semiconductor, Inc.
 * Copyright 2019 NXP
 */

#ifndef DESC_CONSTR_H
#define DESC_CONSTR_H

#include "desc.h"
#include "regs.h"

#define IMMEDIATE
#define CAAM_CMD_SZ
#define CAAM_PTR_SZ
#define CAAM_PTR_SZ_MAX
#define CAAM_PTR_SZ_MIN
#define CAAM_DESC_BYTES_MAX
#define __DESC_JOB_IO_LEN(n)
#define DESC_JOB_IO_LEN
#define DESC_JOB_IO_LEN_MAX
#define DESC_JOB_IO_LEN_MIN

/*
 * The CAAM QI hardware constructs a job descriptor which points
 * to shared descriptor (as pointed by context_a of FQ to CAAM).
 * When the job descriptor is executed by deco, the whole job
 * descriptor together with shared descriptor gets loaded in
 * deco buffer which is 64 words long (each 32-bit).
 *
 * The job descriptor constructed by QI hardware has layout:
 *
 *	HEADER		(1 word)
 *	Shdesc ptr	(1 or 2 words)
 *	SEQ_OUT_PTR	(1 word)
 *	Out ptr		(1 or 2 words)
 *	Out length	(1 word)
 *	SEQ_IN_PTR	(1 word)
 *	In ptr		(1 or 2 words)
 *	In length	(1 word)
 *
 * The shdesc ptr is used to fetch shared descriptor contents
 * into deco buffer.
 *
 * Apart from shdesc contents, the total number of words that
 * get loaded in deco buffer are '8' or '11'. The remaining words
 * in deco buffer can be used for storing shared descriptor.
 */
#define MAX_SDLEN

#ifdef DEBUG
#define PRINT_POS
#else
#define PRINT_POS
#endif

#define SET_OK_NO_PROP_ERRORS
#define DISABLE_AUTO_INFO_FIFO
#define ENABLE_AUTO_INFO_FIFO

extern bool caam_little_end;
extern size_t caam_ptr_sz;

/*
 * HW fetches 4 S/G table entries at a time, irrespective of how many entries
 * are in the table. It's SW's responsibility to make sure these accesses
 * do not have side effects.
 */
static inline int pad_sg_nents(int sg_nents)
{}

static inline int desc_len(u32 * const desc)
{}

static inline int desc_bytes(void * const desc)
{}

static inline u32 *desc_end(u32 * const desc)
{}

static inline void *sh_desc_pdb(u32 * const desc)
{}

static inline void init_desc(u32 * const desc, u32 options)
{}

static inline void init_sh_desc(u32 * const desc, u32 options)
{}

static inline void init_sh_desc_pdb(u32 * const desc, u32 options,
				    size_t pdb_bytes)
{}

static inline void init_job_desc(u32 * const desc, u32 options)
{}

static inline void init_job_desc_pdb(u32 * const desc, u32 options,
				     size_t pdb_bytes)
{}

static inline void append_ptr(u32 * const desc, dma_addr_t ptr)
{}

static inline void init_job_desc_shared(u32 * const desc, dma_addr_t ptr,
					int len, u32 options)
{}

static inline void append_data(u32 * const desc, const void *data, int len)
{}

static inline void append_cmd(u32 * const desc, u32 command)
{}

#define append_u32

static inline void append_u64(u32 * const desc, u64 data)
{}

/* Write command without affecting header, and return pointer to next word */
static inline u32 *write_cmd(u32 * const desc, u32 command)
{}

static inline void append_cmd_ptr(u32 * const desc, dma_addr_t ptr, int len,
				  u32 command)
{}

/* Write length after pointer, rather than inside command */
static inline void append_cmd_ptr_extlen(u32 * const desc, dma_addr_t ptr,
					 unsigned int len, u32 command)
{}

static inline void append_cmd_data(u32 * const desc, const void *data, int len,
				   u32 command)
{}

#define APPEND_CMD_RET(cmd, op)
APPEND_CMD_RET()
APPEND_CMD_RET()
APPEND_CMD_RET()

static inline void set_jump_tgt_here(u32 * const desc, u32 *jump_cmd)
{}

static inline void set_move_tgt_here(u32 * const desc, u32 *move_cmd)
{}

#define APPEND_CMD(cmd, op)
APPEND_CMD()

#define APPEND_CMD_LEN(cmd, op)

APPEND_CMD_LEN()
APPEND_CMD_LEN()
APPEND_CMD_LEN()
APPEND_CMD_LEN()

#define APPEND_CMD_PTR(cmd, op)
APPEND_CMD_PTR()
APPEND_CMD_PTR()
APPEND_CMD_PTR()
APPEND_CMD_PTR()

static inline void append_store(u32 * const desc, dma_addr_t ptr,
				unsigned int len, u32 options)
{}

#define APPEND_SEQ_PTR_INTLEN(cmd, op)
APPEND_SEQ_PTR_INTLEN()
APPEND_SEQ_PTR_INTLEN()

#define APPEND_CMD_PTR_TO_IMM(cmd, op)
APPEND_CMD_PTR_TO_IMM(load, LOAD);
APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);

#define APPEND_CMD_PTR_EXTLEN(cmd, op)
APPEND_CMD_PTR_EXTLEN()
APPEND_CMD_PTR_EXTLEN()

/*
 * Determine whether to store length internally or externally depending on
 * the size of its type
 */
#define APPEND_CMD_PTR_LEN(cmd, op, type)
APPEND_CMD_PTR_LEN()
APPEND_CMD_PTR_LEN()

/*
 * 2nd variant for commands whose specified immediate length differs
 * from length of immediate data provided, e.g., split keys
 */
#define APPEND_CMD_PTR_TO_IMM2(cmd, op)
APPEND_CMD_PTR_TO_IMM2(key, KEY);

#define APPEND_CMD_RAW_IMM(cmd, op, type)
APPEND_CMD_RAW_IMM(load, LOAD, u32);

/*
 * ee - endianness
 * size - size of immediate type in bytes
 */
#define APPEND_CMD_RAW_IMM2(cmd, op, ee, size)

APPEND_CMD_RAW_IMM2(load, LOAD, be, 32);

/*
 * Append math command. Only the last part of destination and source need to
 * be specified
 */
#define APPEND_MATH(op, desc, dest, src_0, src_1, len)

#define append_math_add(desc, dest, src0, src1, len)
#define append_math_sub(desc, dest, src0, src1, len)
#define append_math_add_c(desc, dest, src0, src1, len)
#define append_math_sub_b(desc, dest, src0, src1, len)
#define append_math_and(desc, dest, src0, src1, len)
#define append_math_or(desc, dest, src0, src1, len)
#define append_math_xor(desc, dest, src0, src1, len)
#define append_math_lshift(desc, dest, src0, src1, len)
#define append_math_rshift(desc, dest, src0, src1, len)
#define append_math_ldshift(desc, dest, src0, src1, len)

/* Exactly one source is IMM. Data is passed in as u32 value */
#define APPEND_MATH_IMM_u32(op, desc, dest, src_0, src_1, data)

#define append_math_add_imm_u32(desc, dest, src0, src1, data)
#define append_math_sub_imm_u32(desc, dest, src0, src1, data)
#define append_math_add_c_imm_u32(desc, dest, src0, src1, data)
#define append_math_sub_b_imm_u32(desc, dest, src0, src1, data)
#define append_math_and_imm_u32(desc, dest, src0, src1, data)
#define append_math_or_imm_u32(desc, dest, src0, src1, data)
#define append_math_xor_imm_u32(desc, dest, src0, src1, data)
#define append_math_lshift_imm_u32(desc, dest, src0, src1, data)
#define append_math_rshift_imm_u32(desc, dest, src0, src1, data)

/* Exactly one source is IMM. Data is passed in as u64 value */
#define APPEND_MATH_IMM_u64(op, desc, dest, src_0, src_1, data)

#define append_math_add_imm_u64(desc, dest, src0, src1, data)
#define append_math_sub_imm_u64(desc, dest, src0, src1, data)
#define append_math_add_c_imm_u64(desc, dest, src0, src1, data)
#define append_math_sub_b_imm_u64(desc, dest, src0, src1, data)
#define append_math_and_imm_u64(desc, dest, src0, src1, data)
#define append_math_or_imm_u64(desc, dest, src0, src1, data)
#define append_math_xor_imm_u64(desc, dest, src0, src1, data)
#define append_math_lshift_imm_u64(desc, dest, src0, src1, data)
#define append_math_rshift_imm_u64(desc, dest, src0, src1, data)

/**
 * struct alginfo - Container for algorithm details
 * @algtype: algorithm selector; for valid values, see documentation of the
 *           functions where it is used.
 * @keylen: length of the provided algorithm key, in bytes
 * @keylen_pad: padded length of the provided algorithm key, in bytes
 * @key_dma: dma (bus) address where algorithm key resides
 * @key_virt: virtual address where algorithm key resides
 * @key_inline: true - key can be inlined in the descriptor; false - key is
 *              referenced by the descriptor
 */
struct alginfo {};

/**
 * desc_inline_query() - Provide indications on which data items can be inlined
 *                       and which shall be referenced in a shared descriptor.
 * @sd_base_len: Shared descriptor base length - bytes consumed by the commands,
 *               excluding the data items to be inlined (or corresponding
 *               pointer if an item is not inlined). Each cnstr_* function that
 *               generates descriptors should have a define mentioning
 *               corresponding length.
 * @jd_len: Maximum length of the job descriptor(s) that will be used
 *          together with the shared descriptor.
 * @data_len: Array of lengths of the data items trying to be inlined
 * @inl_mask: 32bit mask with bit x = 1 if data item x can be inlined, 0
 *            otherwise.
 * @count: Number of data items (size of @data_len array); must be <= 32
 *
 * Return: 0 if data can be inlined / referenced, negative value if not. If 0,
 *         check @inl_mask for details.
 */
static inline int desc_inline_query(unsigned int sd_base_len,
				    unsigned int jd_len, unsigned int *data_len,
				    u32 *inl_mask, unsigned int count)
{}

/**
 * append_proto_dkp - Derived Key Protocol (DKP): key -> split key
 * @desc: pointer to buffer used for descriptor construction
 * @adata: pointer to authentication transform definitions.
 *         keylen should be the length of initial key, while keylen_pad
 *         the length of the derived (split) key.
 *         Valid algorithm values - one of OP_ALG_ALGSEL_{MD5, SHA1, SHA224,
 *         SHA256, SHA384, SHA512}.
 */
static inline void append_proto_dkp(u32 * const desc, struct alginfo *adata)
{}

#endif /* DESC_CONSTR_H */