crypto/aesni_gcm: migrate to Multi-buffer library
[dpdk.git] / drivers / crypto / aesni_gcm / aesni_gcm_pmd_private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
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
15  *       distribution.
16  *     * Neither the name of Intel Corporation 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.
19  *
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.
31  */
32
33 #ifndef _RTE_AESNI_GCM_PMD_PRIVATE_H_
34 #define _RTE_AESNI_GCM_PMD_PRIVATE_H_
35
36 #include "aesni_gcm_ops.h"
37
38 #define GCM_LOG_ERR(fmt, args...) \
39         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
40                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), \
41                         __func__, __LINE__, ## args)
42
43 #ifdef RTE_LIBRTE_AESNI_MB_DEBUG
44 #define GCM_LOG_INFO(fmt, args...) \
45         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
46                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), \
47                         __func__, __LINE__, ## args)
48
49 #define GCM_LOG_DBG(fmt, args...) \
50         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
51                         RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), \
52                         __func__, __LINE__, ## args)
53 #else
54 #define GCM_LOG_INFO(fmt, args...)
55 #define GCM_LOG_DBG(fmt, args...)
56 #endif
57
58
59 /** private data structure for each virtual AESNI GCM device */
60 struct aesni_gcm_private {
61         enum aesni_gcm_vector_mode vector_mode;
62         /**< Vector mode */
63         unsigned max_nb_queue_pairs;
64         /**< Max number of queue pairs supported by device */
65         unsigned max_nb_sessions;
66         /**< Max number of sessions supported by device */
67 };
68
69 struct aesni_gcm_qp {
70         const struct aesni_gcm_ops *ops;
71         /**< Architecture dependent function pointer table of the gcm APIs */
72         struct rte_ring *processed_pkts;
73         /**< Ring for placing process packets */
74         struct gcm_context_data gdata_ctx; /* (16 * 5) + 8 = 88 B */
75         /**< GCM parameters */
76         struct rte_cryptodev_stats qp_stats; /* 8 * 4 = 32 B */
77         /**< Queue pair statistics */
78         struct rte_mempool *sess_mp;
79         /**< Session Mempool */
80         uint16_t id;
81         /**< Queue Pair Identifier */
82         char name[RTE_CRYPTODEV_NAME_LEN];
83         /**< Unique Queue Pair Name */
84 } __rte_cache_aligned;
85
86
87 enum aesni_gcm_operation {
88         AESNI_GCM_OP_AUTHENTICATED_ENCRYPTION,
89         AESNI_GCM_OP_AUTHENTICATED_DECRYPTION,
90         AESNI_GMAC_OP_GENERATE,
91         AESNI_GMAC_OP_VERIFY
92 };
93
94 /** AESNI GCM private session structure */
95 struct aesni_gcm_session {
96         struct {
97                 uint16_t length;
98                 uint16_t offset;
99         } iv;
100         /**< IV parameters */
101         uint16_t aad_length;
102         /**< AAD length */
103         uint16_t digest_length;
104         /**< Digest length */
105         enum aesni_gcm_operation op;
106         /**< GCM operation type */
107         enum aesni_gcm_key key;
108         /**< GCM key type */
109         struct gcm_key_data gdata_key;
110         /**< GCM parameters */
111 };
112
113
114 /**
115  * Setup GCM session parameters
116  * @param       sess    aesni gcm session structure
117  * @param       xform   crypto transform chain
118  *
119  * @return
120  * - On success returns 0
121  * - On failure returns error code < 0
122  */
123 extern int
124 aesni_gcm_set_session_parameters(const struct aesni_gcm_ops *ops,
125                 struct aesni_gcm_session *sess,
126                 const struct rte_crypto_sym_xform *xform);
127
128
129 /**
130  * Device specific operations function pointer structure */
131 extern struct rte_cryptodev_ops *rte_aesni_gcm_pmd_ops;
132
133
134 #endif /* _RTE_AESNI_GCM_PMD_PRIVATE_H_ */