3f35a00e74efbb9385cbd7485e5c3ce066b45adb
[deb_dpdk.git] / drivers / crypto / qat / qat_crypto.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _QAT_CRYPTO_H_
35 #define _QAT_CRYPTO_H_
36
37 #include <rte_cryptodev_pmd.h>
38 #include <rte_memzone.h>
39
40 #include "qat_crypto_capabilities.h"
41
42 #define CRYPTODEV_NAME_QAT_SYM_PMD      crypto_qat
43 /**< Intel QAT Symmetric Crypto PMD device name */
44
45 /*
46  * This macro rounds up a number to a be a multiple of
47  * the alignment when the alignment is a power of 2
48  */
49 #define ALIGN_POW2_ROUNDUP(num, align) \
50         (((num) + (align) - 1) & ~((align) - 1))
51 #define QAT_64_BTYE_ALIGN_MASK (~0x3f)
52
53 struct qat_session;
54
55 enum qat_device_gen {
56         QAT_GEN1 = 1,
57         QAT_GEN2,
58 };
59
60 /**
61  * Structure associated with each queue.
62  */
63 struct qat_queue {
64         char            memz_name[RTE_MEMZONE_NAMESIZE];
65         void            *base_addr;             /* Base address */
66         phys_addr_t     base_phys_addr;         /* Queue physical address */
67         uint32_t        head;                   /* Shadow copy of the head */
68         uint32_t        tail;                   /* Shadow copy of the tail */
69         uint32_t        modulo;
70         uint32_t        msg_size;
71         uint16_t        max_inflights;
72         uint32_t        queue_size;
73         uint8_t         hw_bundle_number;
74         uint8_t         hw_queue_number;
75         /* HW queue aka ring offset on bundle */
76 };
77
78 struct qat_qp {
79         void                    *mmap_bar_addr;
80         rte_atomic16_t          inflights16;
81         struct  qat_queue       tx_q;
82         struct  qat_queue       rx_q;
83         struct  rte_cryptodev_stats stats;
84         struct rte_mempool *op_cookie_pool;
85         void **op_cookies;
86         uint32_t nb_descriptors;
87         enum qat_device_gen qat_dev_gen;
88 } __rte_cache_aligned;
89
90 /** private data structure for each QAT device */
91 struct qat_pmd_private {
92         unsigned max_nb_queue_pairs;
93         /**< Max number of queue pairs supported by device */
94         unsigned max_nb_sessions;
95         /**< Max number of sessions supported by device */
96         enum qat_device_gen qat_dev_gen;
97         /**< QAT device generation */
98         const struct rte_cryptodev_capabilities *qat_dev_capabilities;
99 };
100
101 extern uint8_t cryptodev_qat_driver_id;
102
103 int qat_dev_config(struct rte_cryptodev *dev,
104                 struct rte_cryptodev_config *config);
105 int qat_dev_start(struct rte_cryptodev *dev);
106 void qat_dev_stop(struct rte_cryptodev *dev);
107 int qat_dev_close(struct rte_cryptodev *dev);
108 void qat_dev_info_get(struct rte_cryptodev *dev,
109         struct rte_cryptodev_info *info);
110
111 void qat_crypto_sym_stats_get(struct rte_cryptodev *dev,
112         struct rte_cryptodev_stats *stats);
113 void qat_crypto_sym_stats_reset(struct rte_cryptodev *dev);
114
115 int qat_crypto_sym_qp_setup(struct rte_cryptodev *dev, uint16_t queue_pair_id,
116         const struct rte_cryptodev_qp_conf *rx_conf, int socket_id,
117         struct rte_mempool *session_pool);
118 int qat_crypto_sym_qp_release(struct rte_cryptodev *dev,
119         uint16_t queue_pair_id);
120
121 int
122 qat_pmd_session_mempool_create(struct rte_cryptodev *dev,
123         unsigned nb_objs, unsigned obj_cache_size, int socket_id);
124
125 extern unsigned
126 qat_crypto_sym_get_session_private_size(struct rte_cryptodev *dev);
127
128 extern int
129 qat_crypto_sym_configure_session(struct rte_cryptodev *dev,
130                 struct rte_crypto_sym_xform *xform,
131                 struct rte_cryptodev_sym_session *sess,
132                 struct rte_mempool *mempool);
133
134
135 int
136 qat_crypto_set_session_parameters(struct rte_cryptodev *dev,
137                 struct rte_crypto_sym_xform *xform, void *session_private);
138
139 int
140 qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
141                                 struct qat_session *session);
142
143 int
144 qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
145                                 struct rte_crypto_sym_xform *xform,
146                                 struct qat_session *session);
147
148 int
149 qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
150                 struct rte_crypto_sym_xform *xform,
151                 struct qat_session *session);
152
153
154 extern void
155 qat_crypto_sym_clear_session(struct rte_cryptodev *dev,
156                 struct rte_cryptodev_sym_session *session);
157
158 extern uint16_t
159 qat_pmd_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
160                 uint16_t nb_ops);
161
162 extern uint16_t
163 qat_pmd_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
164                 uint16_t nb_ops);
165
166 #endif /* _QAT_CRYPTO_H_ */