3b816d3e2e41d7c92810277fdca43dd78ead4b81
[dpdk.git] / drivers / crypto / scheduler / rte_cryptodev_scheduler.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 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 _RTE_CRYPTO_SCHEDULER_H
35 #define _RTE_CRYPTO_SCHEDULER_H
36
37 #include "rte_cryptodev_scheduler_operations.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**< Maximum number of bonded devices per device */
44 #ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
45 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES   (8)
46 #endif
47
48 /* round-robin scheduling mode */
49 #define SCHEDULER_MODE_NAME_ROUND_ROBIN         round-robin
50 /* packet-size based distribution scheduling mode */
51 #define SCHEDULER_MODE_NAME_PKT_SIZE_DISTR      packet-size-distr
52 /* fail-over mode */
53 #define SCHEDULER_MODE_NAME_FAIL_OVER           fail-over
54 /**
55
56  * Crypto scheduler PMD operation modes
57  */
58 enum rte_cryptodev_scheduler_mode {
59         CDEV_SCHED_MODE_NOT_SET = 0,
60         CDEV_SCHED_MODE_USERDEFINED,
61         CDEV_SCHED_MODE_ROUNDROBIN,
62         /** packet-size based distribution mode */
63         CDEV_SCHED_MODE_PKT_SIZE_DISTR,
64         /** fail-over mode */
65         CDEV_SCHED_MODE_FAILOVER,
66
67         CDEV_SCHED_MODE_COUNT /* number of modes */
68 };
69
70 #define RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN    (64)
71 #define RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN    (256)
72
73 struct rte_cryptodev_scheduler;
74
75 /**
76  * Load a user defined scheduler
77  *
78  * @param       scheduler_id    The target scheduler device ID
79  *              scheduler       Pointer to the user defined scheduler
80  *
81  * @return
82  *      0 if loading successful, negative integer if otherwise.
83  */
84 int
85 rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
86                 struct rte_cryptodev_scheduler *scheduler);
87
88 /**
89  * Attach a pre-configured crypto device to the scheduler
90  *
91  * @param       scheduler_id    The target scheduler device ID
92  *              slave_id        crypto device ID to be attached
93  *
94  * @return
95  *      0 if attaching successful, negative int if otherwise.
96  */
97 int
98 rte_cryptodev_scheduler_slave_attach(uint8_t scheduler_id, uint8_t slave_id);
99
100 /**
101  * Detach a attached crypto device to the scheduler
102  *
103  * @param       scheduler_id    The target scheduler device ID
104  *              slave_id        crypto device ID to be detached
105  *
106  * @return
107  *      0 if detaching successful, negative int if otherwise.
108  */
109 int
110 rte_cryptodev_scheduler_slave_detach(uint8_t scheduler_id, uint8_t slave_id);
111
112
113 /**
114  * Set the scheduling mode
115  *
116  * @param       scheduler_id    The target scheduler device ID
117  *              mode            The scheduling mode
118  *
119  * @return
120  *      0 if attaching successful, negative integer if otherwise.
121  */
122 int
123 rte_cryptodev_scheduler_mode_set(uint8_t scheduler_id,
124                 enum rte_cryptodev_scheduler_mode mode);
125
126 /**
127  * Get the current scheduling mode
128  *
129  * @param       scheduler_id    The target scheduler device ID
130  *              mode            Pointer to write the scheduling mode
131  */
132 enum rte_cryptodev_scheduler_mode
133 rte_cryptodev_scheduler_mode_get(uint8_t scheduler_id);
134
135 /**
136  * @deprecated
137  * Set the scheduling mode
138  *
139  * @param       scheduler_id    The target scheduler device ID
140  *              mode            The scheduling mode
141  *
142  * @return
143  *      0 if attaching successful, negative integer if otherwise.
144  */
145 __rte_deprecated
146 int
147 rte_crpytodev_scheduler_mode_set(uint8_t scheduler_id,
148                 enum rte_cryptodev_scheduler_mode mode);
149
150 /**
151  * @deprecated
152  * Get the current scheduling mode
153  *
154  * @param       scheduler_id    The target scheduler device ID
155  *              mode            Pointer to write the scheduling mode
156  */
157 __rte_deprecated
158 enum rte_cryptodev_scheduler_mode
159 rte_crpytodev_scheduler_mode_get(uint8_t scheduler_id);
160
161 /**
162  * Set the crypto ops reordering feature on/off
163  *
164  * @param       dev_id          The target scheduler device ID
165  *              enable_reorder  set the crypto op reordering feature
166  *                              0: disable reordering
167  *                              1: enable reordering
168  *
169  * @return
170  *      0 if setting successful, negative integer if otherwise.
171  */
172 int
173 rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id,
174                 uint32_t enable_reorder);
175
176 /**
177  * Get the current crypto ops reordering feature
178  *
179  * @param       dev_id          The target scheduler device ID
180  *
181  * @return
182  *      0 if reordering is disabled
183  *      1 if reordering is enabled
184  *      negative integer if otherwise.
185  */
186 int
187 rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
188
189 /**
190  * Get the the attached slaves' count and/or ID
191  *
192  * @param scheduler_id
193  *   The target scheduler device ID
194  * @param slaves
195  *  If successful, the function will write back
196  *  all slaves' device IDs to it. This
197  *  parameter SHALL either be an uint8_t array
198  *  of RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
199  *  elements or NULL.
200  *
201  * @return
202  *   - non-negative number: the number of slaves attached
203  *   - negative integer if error occurs.
204  */
205 int
206 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
207
208 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
209                 struct rte_crypto_op **ops, uint16_t nb_ops);
210
211 typedef uint16_t (*rte_cryptodev_scheduler_burst_dequeue_t)(void *qp_ctx,
212                 struct rte_crypto_op **ops, uint16_t nb_ops);
213
214 struct rte_cryptodev_scheduler {
215         const char *name;
216         const char *description;
217         enum rte_cryptodev_scheduler_mode mode;
218
219         struct rte_cryptodev_scheduler_ops *ops;
220 };
221
222 extern struct rte_cryptodev_scheduler *roundrobin_scheduler;
223 extern struct rte_cryptodev_scheduler *pkt_size_based_distr_scheduler;
224 extern struct rte_cryptodev_scheduler *failover_scheduler;
225
226 #ifdef __cplusplus
227 }
228 #endif
229 #endif /* _RTE_CRYPTO_SCHEDULER_H */