crypto/dpaa2_sec: add sample descriptors
[dpdk.git] / drivers / crypto / dpaa2_sec / hw / desc / common.h
1 /*
2  * Copyright 2008-2016 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause or GPL-2.0+
5  */
6
7 #ifndef __DESC_COMMON_H__
8 #define __DESC_COMMON_H__
9
10 #include "hw/rta.h"
11
12 /**
13  * DOC: Shared Descriptor Constructors - shared structures
14  *
15  * Data structures shared between algorithm, protocol implementations.
16  */
17
18 /**
19  * struct alginfo - Container for algorithm details
20  * @algtype: algorithm selector; for valid values, see documentation of the
21  *           functions where it is used.
22  * @keylen: length of the provided algorithm key, in bytes
23  * @key: address where algorithm key resides; virtual address if key_type is
24  *       RTA_DATA_IMM, physical (bus) address if key_type is RTA_DATA_PTR or
25  *       RTA_DATA_IMM_DMA.
26  * @key_enc_flags: key encryption flags; see encrypt_flags parameter of KEY
27  *                 command for valid values.
28  * @key_type: enum rta_data_type
29  * @algmode: algorithm mode selector; for valid values, see documentation of the
30  *           functions where it is used.
31  */
32 struct alginfo {
33         uint32_t algtype;
34         uint32_t keylen;
35         uint64_t key;
36         uint32_t key_enc_flags;
37         enum rta_data_type key_type;
38         uint16_t algmode;
39 };
40
41 #define INLINE_KEY(alginfo)     inline_flags(alginfo->key_type)
42
43 /**
44  * rta_inline_query() - Provide indications on which data items can be inlined
45  *                      and which shall be referenced in a shared descriptor.
46  * @sd_base_len: Shared descriptor base length - bytes consumed by the commands,
47  *               excluding the data items to be inlined (or corresponding
48  *               pointer if an item is not inlined). Each cnstr_* function that
49  *               generates descriptors should have a define mentioning
50  *               corresponding length.
51  * @jd_len: Maximum length of the job descriptor(s) that will be used
52  *          together with the shared descriptor.
53  * @data_len: Array of lengths of the data items trying to be inlined
54  * @inl_mask: 32bit mask with bit x = 1 if data item x can be inlined, 0
55  *            otherwise.
56  * @count: Number of data items (size of @data_len array); must be <= 32
57  *
58  * Return: 0 if data can be inlined / referenced, negative value if not. If 0,
59  *         check @inl_mask for details.
60  */
61 static inline int
62 rta_inline_query(unsigned int sd_base_len,
63                  unsigned int jd_len,
64                  unsigned int *data_len,
65                  uint32_t *inl_mask,
66                  unsigned int count)
67 {
68         int rem_bytes = (int)(CAAM_DESC_BYTES_MAX - sd_base_len - jd_len);
69         unsigned int i;
70
71         *inl_mask = 0;
72         for (i = 0; (i < count) && (rem_bytes > 0); i++) {
73                 if (rem_bytes - (int)(data_len[i] +
74                         (count - i - 1) * CAAM_PTR_SZ) >= 0) {
75                         rem_bytes -= data_len[i];
76                         *inl_mask |= (1 << i);
77                 } else {
78                         rem_bytes -= CAAM_PTR_SZ;
79                 }
80         }
81
82         return (rem_bytes >= 0) ? 0 : -1;
83 }
84
85 /**
86  * struct protcmd - Container for Protocol Operation Command fields
87  * @optype: command type
88  * @protid: protocol Identifier
89  * @protinfo: protocol Information
90  */
91 struct protcmd {
92         uint32_t optype;
93         uint32_t protid;
94         uint16_t protinfo;
95 };
96
97 #endif /* __DESC_COMMON_H__ */