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