accel/amdxdna: Return error when setting clock failed for npu1
[drm/drm-misc.git] / include / soc / fsl / caam-blob.h
blob937cac52f36d84a06acaec22e287d9fa5d0d91d5
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2020 Pengutronix, Ahmad Fatoum <kernel@pengutronix.de>
4 */
6 #ifndef __CAAM_BLOB_GEN
7 #define __CAAM_BLOB_GEN
9 #include <linux/types.h>
10 #include <linux/errno.h>
12 #define CAAM_BLOB_KEYMOD_LENGTH 16
13 #define CAAM_BLOB_OVERHEAD (32 + 16)
14 #define CAAM_BLOB_MAX_LEN 4096
16 struct caam_blob_priv;
18 /**
19 * struct caam_blob_info - information for CAAM blobbing
20 * @input: pointer to input buffer (must be DMAable)
21 * @input_len: length of @input buffer in bytes.
22 * @output: pointer to output buffer (must be DMAable)
23 * @output_len: length of @output buffer in bytes.
24 * @key_mod: key modifier
25 * @key_mod_len: length of @key_mod in bytes.
26 * May not exceed %CAAM_BLOB_KEYMOD_LENGTH
28 struct caam_blob_info {
29 void *input;
30 size_t input_len;
32 void *output;
33 size_t output_len;
35 const void *key_mod;
36 size_t key_mod_len;
39 /**
40 * caam_blob_gen_init - initialize blob generation
41 * Return: pointer to new &struct caam_blob_priv instance on success
42 * and ``ERR_PTR(-ENODEV)`` if CAAM has no hardware blobbing support
43 * or no job ring could be allocated.
45 struct caam_blob_priv *caam_blob_gen_init(void);
47 /**
48 * caam_blob_gen_exit - free blob generation resources
49 * @priv: instance returned by caam_blob_gen_init()
51 void caam_blob_gen_exit(struct caam_blob_priv *priv);
53 /**
54 * caam_process_blob - encapsulate or decapsulate blob
55 * @priv: instance returned by caam_blob_gen_init()
56 * @info: pointer to blobbing info describing key, blob and
57 * key modifier buffers.
58 * @encap: true for encapsulation, false for decapsulation
60 * Return: %0 and sets ``info->output_len`` on success and a negative
61 * error code otherwise.
63 int caam_process_blob(struct caam_blob_priv *priv,
64 struct caam_blob_info *info, bool encap);
66 /**
67 * caam_encap_blob - encapsulate blob
68 * @priv: instance returned by caam_blob_gen_init()
69 * @info: pointer to blobbing info describing input key,
70 * output blob and key modifier buffers.
72 * Return: %0 and sets ``info->output_len`` on success and
73 * a negative error code otherwise.
75 static inline int caam_encap_blob(struct caam_blob_priv *priv,
76 struct caam_blob_info *info)
78 if (info->output_len < info->input_len + CAAM_BLOB_OVERHEAD)
79 return -EINVAL;
81 return caam_process_blob(priv, info, true);
84 /**
85 * caam_decap_blob - decapsulate blob
86 * @priv: instance returned by caam_blob_gen_init()
87 * @info: pointer to blobbing info describing output key,
88 * input blob and key modifier buffers.
90 * Return: %0 and sets ``info->output_len`` on success and
91 * a negative error code otherwise.
93 static inline int caam_decap_blob(struct caam_blob_priv *priv,
94 struct caam_blob_info *info)
96 if (info->input_len < CAAM_BLOB_OVERHEAD ||
97 info->output_len < info->input_len - CAAM_BLOB_OVERHEAD)
98 return -EINVAL;
100 return caam_process_blob(priv, info, false);
103 #endif