4 * Copyright (C) Cavium networks Ltd. 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 networks 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 ARMV8_CRYPTO_LOG_ERR(fmt, args...) \
37 RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
38 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
39 __func__, __LINE__, ## args)
41 #ifdef RTE_LIBRTE_ARMV8_CRYPTO_DEBUG
42 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...) \
43 RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
44 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
45 __func__, __LINE__, ## args)
47 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...) \
48 RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
49 RTE_STR(CRYPTODEV_NAME_ARMV8_CRYPTO_PMD), \
50 __func__, __LINE__, ## args)
52 #define ARMV8_CRYPTO_ASSERT(con) \
56 con "condition failed, line %u", __func__); \
61 #define ARMV8_CRYPTO_LOG_INFO(fmt, args...)
62 #define ARMV8_CRYPTO_LOG_DBG(fmt, args...)
63 #define ARMV8_CRYPTO_ASSERT(con)
66 #define NBBY 8 /* Number of bits in a byte */
67 #define BYTE_LENGTH(x) ((x) / NBBY) /* Number of bytes in x (round down) */
69 /** ARMv8 operation order mode enumerator */
70 enum armv8_crypto_chain_order {
71 ARMV8_CRYPTO_CHAIN_CIPHER_AUTH,
72 ARMV8_CRYPTO_CHAIN_AUTH_CIPHER,
73 ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED,
74 ARMV8_CRYPTO_CHAIN_LIST_END = ARMV8_CRYPTO_CHAIN_NOT_SUPPORTED
77 /** ARMv8 cipher operation enumerator */
78 enum armv8_crypto_cipher_operation {
79 ARMV8_CRYPTO_CIPHER_OP_ENCRYPT = RTE_CRYPTO_CIPHER_OP_ENCRYPT,
80 ARMV8_CRYPTO_CIPHER_OP_DECRYPT = RTE_CRYPTO_CIPHER_OP_DECRYPT,
81 ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED,
82 ARMV8_CRYPTO_CIPHER_OP_LIST_END = ARMV8_CRYPTO_CIPHER_OP_NOT_SUPPORTED
85 enum armv8_crypto_cipher_keylen {
86 ARMV8_CRYPTO_CIPHER_KEYLEN_128,
87 ARMV8_CRYPTO_CIPHER_KEYLEN_192,
88 ARMV8_CRYPTO_CIPHER_KEYLEN_256,
89 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED,
90 ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END =
91 ARMV8_CRYPTO_CIPHER_KEYLEN_NOT_SUPPORTED
94 /** ARMv8 auth mode enumerator */
95 enum armv8_crypto_auth_mode {
96 ARMV8_CRYPTO_AUTH_AS_AUTH,
97 ARMV8_CRYPTO_AUTH_AS_HMAC,
98 ARMV8_CRYPTO_AUTH_AS_CIPHER,
99 ARMV8_CRYPTO_AUTH_NOT_SUPPORTED,
100 ARMV8_CRYPTO_AUTH_LIST_END = ARMV8_CRYPTO_AUTH_NOT_SUPPORTED
103 #define CRYPTO_ORDER_MAX ARMV8_CRYPTO_CHAIN_LIST_END
104 #define CRYPTO_CIPHER_OP_MAX ARMV8_CRYPTO_CIPHER_OP_LIST_END
105 #define CRYPTO_CIPHER_KEYLEN_MAX ARMV8_CRYPTO_CIPHER_KEYLEN_LIST_END
106 #define CRYPTO_CIPHER_MAX RTE_CRYPTO_CIPHER_LIST_END
107 #define CRYPTO_AUTH_MAX RTE_CRYPTO_AUTH_LIST_END
109 #define HMAC_IPAD_VALUE (0x36)
110 #define HMAC_OPAD_VALUE (0x5C)
112 #define SHA256_AUTH_KEY_LENGTH (BYTE_LENGTH(256))
113 #define SHA256_BLOCK_SIZE (BYTE_LENGTH(512))
115 #define SHA1_AUTH_KEY_LENGTH (BYTE_LENGTH(160))
116 #define SHA1_BLOCK_SIZE (BYTE_LENGTH(512))
118 #define SHA_AUTH_KEY_MAX SHA256_AUTH_KEY_LENGTH
119 #define SHA_BLOCK_MAX SHA256_BLOCK_SIZE
121 typedef int (*crypto_func_t)(uint8_t *, uint8_t *, uint64_t,
122 uint8_t *, uint8_t *, uint64_t,
125 typedef void (*crypto_key_sched_t)(uint8_t *, const uint8_t *);
127 /** private data structure for each ARMv8 crypto device */
128 struct armv8_crypto_private {
129 unsigned int max_nb_qpairs;
130 /**< Max number of queue pairs */
131 unsigned int max_nb_sessions;
132 /**< Max number of sessions */
135 /** ARMv8 crypto queue pair */
136 struct armv8_crypto_qp {
138 /**< Queue Pair Identifier */
139 struct rte_ring *processed_ops;
140 /**< Ring for placing process packets */
141 struct rte_mempool *sess_mp;
142 /**< Session Mempool */
143 struct rte_cryptodev_stats stats;
144 /**< Queue pair statistics */
145 char name[RTE_CRYPTODEV_NAME_LEN];
146 /**< Unique Queue Pair Name */
147 } __rte_cache_aligned;
149 /** ARMv8 crypto private session structure */
150 struct armv8_crypto_session {
151 enum armv8_crypto_chain_order chain_order;
152 /**< chain order mode */
153 crypto_func_t crypto_func;
154 /**< cryptographic function to use for this session */
156 /** Cipher Parameters */
158 enum rte_crypto_cipher_operation direction;
159 /**< cipher operation direction */
160 enum rte_crypto_cipher_algorithm algo;
161 /**< cipher algorithm */
169 /**< key length in bytes */
172 crypto_key_sched_t key_sched;
173 /**< Key schedule function */
176 /** Authentication Parameters */
178 enum rte_crypto_auth_operation operation;
179 /**< auth operation generate or verify */
180 enum armv8_crypto_auth_mode mode;
181 /**< auth operation mode */
185 /* Add data if needed */
189 uint8_t i_key_pad[SHA_BLOCK_MAX]
191 /**< inner pad (max supported block length) */
192 uint8_t o_key_pad[SHA_BLOCK_MAX]
194 /**< outer pad (max supported block length) */
195 uint8_t key[SHA_AUTH_KEY_MAX];
196 /**< HMAC key (max supported length)*/
201 } __rte_cache_aligned;
203 /** Set and validate ARMv8 crypto session parameters */
204 extern int armv8_crypto_set_session_parameters(
205 struct armv8_crypto_session *sess,
206 const struct rte_crypto_sym_xform *xform);
208 /** device specific operations function pointer structure */
209 extern struct rte_cryptodev_ops *rte_armv8_crypto_pmd_ops;
211 #endif /* _RTE_ARMV8_PMD_PRIVATE_H_ */