4 * Copyright (C) Cavium, Inc. 2017.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Cavium, Inc nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #ifndef _RTE_ARMV8_PMD_PRIVATE_H_
34 #define _RTE_ARMV8_PMD_PRIVATE_H_
36 #define CRYPTODEV_NAME_ARMV8_PMD crypto_armv8
37 /**< ARMv8 Crypto PMD device name */
39 #define ARMV8_CRYPTO_LOG_ERR(fmt, args...) \
40 RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
41 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
42 __func__, __LINE__, ## args)
44 #ifdef RTE_LIBRTE_ARMV8_CRYPTO_DEBUG
45 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \
46 RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
47 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
48 __func__, __LINE__, ## args)
50 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \
51 RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
52 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
53 __func__, __LINE__, ## args)
55 #define ARMV8_CRYPTO_ASSERT(con) \
59 con "condition failed, line %u", __func__); \
64 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...)
65 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...)
66 #define ARMV8_CRYPTO_ASSERT(con)
69 #define NBBY 8 /* Number of bits in a byte */
70 #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */
72 /** ARMv8 operation order mode enumerator */
73 enum armv8_crypto_chain_order {
74 ARMV8_CRYPTO_CHAIN_CIPHER_AUTH,
75 ARMV8_CRYPTO_CHAIN_AUTH_CIPHER,
76 ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED,
77 ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED
80 /** ARMv8 cipher operation enumerator */
81 enum armv8_crypto_cipher_operation {
82 ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT,
83 ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT,
84 ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED,
85 ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED
88 enum armv8_crypto_cipher_keylen {
89 ARMV8_CRYPTO_CIPHER_KEYLEN_128,
90 ARMV8_CRYPTO_CIPHER_KEYLEN_192,
91 ARMV8_CRYPTO_CIPHER_KEYLEN_256,
92 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED,
93 ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END =
94 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED
97 /** ARMv8 auth mode enumerator */
98 enum armv8_crypto_auth_mode {
99 ARMV8_CRYPTO_AUTH_AS_AUTH,
100 ARMV8_CRYPTO_AUTH_AS_HMAC,
101 ARMV8_CRYPTO_AUTH_AS_CIPHER,
102 ARMV8_CRYPTO_AUTH_NOT_SUPPORTED,
103 ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED
106 #define CRYPTO_ORDER_MAX ARMV8_CRYPTO_CHAIN_LIST_END
107 #define CRYPTO_CIPHER_OP_MAX ARMV8_CRYPTO_CIPHER_OP_LIST_END
108 #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END
109 #define CRYPTO_CIPHER_MAX RTE_CRYPTO_CIPHER_LIST_END
110 #define CRYPTO_AUTH_MAX RTE_CRYPTO_AUTH_LIST_END
112 #define HMAC_IPAD_VALUE (0x36)
113 #define HMAC_OPAD_VALUE (0x5C)
115 #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256))
116 #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512))
118 #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160))
119 #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512))
121 #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH
122 #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE
124 typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t,
125 uint8_t *, uint8_t *, uint64_t,
128 typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *);
130 /** private data structure for each ARMv8 crypto device */
131 struct armv8_crypto_private {
132 unsigned int max_nb_qpairs;
133 /**< Max number of queue pairs */
134 unsigned int max_nb_sessions;
135 /**< Max number of sessions */
138 /** ARMv8 crypto queue pair */
139 struct armv8_crypto_qp {
141 /**< Queue Pair Identifier */
142 struct rte_ring *processed_ops;
143 /**< Ring for placing process packets */
144 struct rte_mempool *sess_mp;
145 /**< Session Mempool */
146 struct rte_cryptodev_stats stats;
147 /**< Queue pair statistics */
148 char name[RTE_CRYPTODEV_NAME_LEN];
149 /**< Unique Queue Pair Name */
150 } __rte_cache_aligned;
152 /** ARMv8 crypto private session structure */
153 struct armv8_crypto_session {
154 enum armv8_crypto_chain_order chain_order;
155 /**< chain order mode */
156 crypto_func_t crypto_func;
157 /**< cryptographic function to use for this session */
159 /** Cipher Parameters */
161 enum rte_crypto_cipher_operation direction;
162 /**< cipher operation direction */
163 enum rte_crypto_cipher_algorithm algo;
164 /**< cipher algorithm */
169 /**< IV parameters */
175 /**< key length in bytes */
178 crypto_key_sched_t key_sched;
179 /**< Key schedule function */
182 /** Authentication Parameters */
184 enum rte_crypto_auth_operation operation;
185 /**< auth operation generate or verify */
186 enum armv8_crypto_auth_mode mode;
187 /**< auth operation mode */
191 /* Add data if needed */
195 uint8_t i_key_pad[SHA_BLOCK_MAX]
197 /**< inner pad (max supported block length) */
198 uint8_t o_key_pad[SHA_BLOCK_MAX]
200 /**< outer pad (max supported block length) */
201 uint8_t key[SHA_BLOCK_MAX];
202 /**< HMAC key (max supported block length)*/
205 uint16_t digest_length;
209 } __rte_cache_aligned;
211 /** Set and validate ARMv8 crypto session parameters */
212 extern int armv8_crypto_set_session_parameters(
213 struct armv8_crypto_session *sess,
214 const struct rte_crypto_sym_xform *xform);
216 /** device specific operations function pointer structure */
217 extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops;
219 #endif /* _RTE_ARMV8_PMD_PRIVATE_H_ */