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