6b254908484190300a469b99bd46cd82cd66a589
[deb_dpdk.git] / drivers / crypto / dpaa2_sec / hw / desc / common.h
1 /*-
2  * This file is provided under a dual BSD/GPLv2 license. When using or
3  * redistributing this file, you may do so under either license.
4  *
5  *   BSD LICENSE
6  *
7  * Copyright 2008-2016 Freescale Semiconductor Inc.
8  * Copyright (c) 2016 NXP.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the above-listed copyright holders nor the
18  * names of any contributors may be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  *   GPL LICENSE SUMMARY
22  *
23  * ALTERNATIVELY, this software may be distributed under the terms of the
24  * GNU General Public License ("GPL") as published by the Free Software
25  * Foundation, either version 2 of that License or (at your option) any
26  * later version.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 #ifndef __DESC_COMMON_H__
42 #define __DESC_COMMON_H__
43
44 #include "hw/rta.h"
45
46 /**
47  * DOC: Shared Descriptor Constructors - shared structures
48  *
49  * Data structures shared between algorithm, protocol implementations.
50  */
51
52 /**
53  * struct alginfo - Container for algorithm details
54  * @algtype: algorithm selector; for valid values, see documentation of the
55  *           functions where it is used.
56  * @keylen: length of the provided algorithm key, in bytes
57  * @key: address where algorithm key resides; virtual address if key_type is
58  *       RTA_DATA_IMM, physical (bus) address if key_type is RTA_DATA_PTR or
59  *       RTA_DATA_IMM_DMA.
60  * @key_enc_flags: key encryption flags; see encrypt_flags parameter of KEY
61  *                 command for valid values.
62  * @key_type: enum rta_data_type
63  * @algmode: algorithm mode selector; for valid values, see documentation of the
64  *           functions where it is used.
65  */
66 struct alginfo {
67         uint32_t algtype;
68         uint32_t keylen;
69         uint64_t key;
70         uint32_t key_enc_flags;
71         enum rta_data_type key_type;
72         uint16_t algmode;
73 };
74
75 #define INLINE_KEY(alginfo)     inline_flags(alginfo->key_type)
76
77 /**
78  * rta_inline_query() - Provide indications on which data items can be inlined
79  *                      and which shall be referenced in a shared descriptor.
80  * @sd_base_len: Shared descriptor base length - bytes consumed by the commands,
81  *               excluding the data items to be inlined (or corresponding
82  *               pointer if an item is not inlined). Each cnstr_* function that
83  *               generates descriptors should have a define mentioning
84  *               corresponding length.
85  * @jd_len: Maximum length of the job descriptor(s) that will be used
86  *          together with the shared descriptor.
87  * @data_len: Array of lengths of the data items trying to be inlined
88  * @inl_mask: 32bit mask with bit x = 1 if data item x can be inlined, 0
89  *            otherwise.
90  * @count: Number of data items (size of @data_len array); must be <= 32
91  *
92  * Return: 0 if data can be inlined / referenced, negative value if not. If 0,
93  *         check @inl_mask for details.
94  */
95 static inline int
96 rta_inline_query(unsigned int sd_base_len,
97                  unsigned int jd_len,
98                  unsigned int *data_len,
99                  uint32_t *inl_mask,
100                  unsigned int count)
101 {
102         int rem_bytes = (int)(CAAM_DESC_BYTES_MAX - sd_base_len - jd_len);
103         unsigned int i;
104
105         *inl_mask = 0;
106         for (i = 0; (i < count) && (rem_bytes > 0); i++) {
107                 if (rem_bytes - (int)(data_len[i] +
108                         (count - i - 1) * CAAM_PTR_SZ) >= 0) {
109                         rem_bytes -= data_len[i];
110                         *inl_mask |= (1 << i);
111                 } else {
112                         rem_bytes -= CAAM_PTR_SZ;
113                 }
114         }
115
116         return (rem_bytes >= 0) ? 0 : -1;
117 }
118
119 /**
120  * struct protcmd - Container for Protocol Operation Command fields
121  * @optype: command type
122  * @protid: protocol Identifier
123  * @protinfo: protocol Information
124  */
125 struct protcmd {
126         uint32_t optype;
127         uint32_t protid;
128         uint16_t protinfo;
129 };
130
131 #endif /* __DESC_COMMON_H__ */