crypto/scheduler: support mode specific option
[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 /**
74  * Crypto scheduler option types
75  */
76 enum rte_cryptodev_schedule_option_type {
77         CDEV_SCHED_OPTION_NOT_SET = 0,
78         CDEV_SCHED_OPTION_THRESHOLD,
79
80         CDEV_SCHED_OPTION_COUNT
81 };
82
83 /**
84  * Threshold option structure
85  */
86 struct rte_cryptodev_scheduler_threshold_option {
87         uint32_t threshold;
88 };
89
90 struct rte_cryptodev_scheduler;
91
92 /**
93  * Load a user defined scheduler
94  *
95  * @param       scheduler_id    The target scheduler device ID
96  *              scheduler       Pointer to the user defined scheduler
97  *
98  * @return
99  *      0 if loading successful, negative integer if otherwise.
100  */
101 int
102 rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
103                 struct rte_cryptodev_scheduler *scheduler);
104
105 /**
106  * Attach a pre-configured crypto device to the scheduler
107  *
108  * @param       scheduler_id    The target scheduler device ID
109  *              slave_id        crypto device ID to be attached
110  *
111  * @return
112  *      0 if attaching successful, negative int if otherwise.
113  */
114 int
115 rte_cryptodev_scheduler_slave_attach(uint8_t scheduler_id, uint8_t slave_id);
116
117 /**
118  * Detach a attached crypto device to the scheduler
119  *
120  * @param       scheduler_id    The target scheduler device ID
121  *              slave_id        crypto device ID to be detached
122  *
123  * @return
124  *      0 if detaching successful, negative int if otherwise.
125  */
126 int
127 rte_cryptodev_scheduler_slave_detach(uint8_t scheduler_id, uint8_t slave_id);
128
129
130 /**
131  * Set the scheduling mode
132  *
133  * @param       scheduler_id    The target scheduler device ID
134  *              mode            The scheduling mode
135  *
136  * @return
137  *      0 if attaching successful, negative integer if otherwise.
138  */
139 int
140 rte_cryptodev_scheduler_mode_set(uint8_t scheduler_id,
141                 enum rte_cryptodev_scheduler_mode mode);
142
143 /**
144  * Get the current scheduling mode
145  *
146  * @param       scheduler_id    The target scheduler device ID
147  *              mode            Pointer to write the scheduling mode
148  */
149 enum rte_cryptodev_scheduler_mode
150 rte_cryptodev_scheduler_mode_get(uint8_t scheduler_id);
151
152 /**
153  * @deprecated
154  * Set the scheduling mode
155  *
156  * @param       scheduler_id    The target scheduler device ID
157  *              mode            The scheduling mode
158  *
159  * @return
160  *      0 if attaching successful, negative integer if otherwise.
161  */
162 __rte_deprecated
163 int
164 rte_crpytodev_scheduler_mode_set(uint8_t scheduler_id,
165                 enum rte_cryptodev_scheduler_mode mode);
166
167 /**
168  * @deprecated
169  * Get the current scheduling mode
170  *
171  * @param       scheduler_id    The target scheduler device ID
172  *              mode            Pointer to write the scheduling mode
173  */
174 __rte_deprecated
175 enum rte_cryptodev_scheduler_mode
176 rte_crpytodev_scheduler_mode_get(uint8_t scheduler_id);
177
178 /**
179  * Set the crypto ops reordering feature on/off
180  *
181  * @param       dev_id          The target scheduler device ID
182  *              enable_reorder  set the crypto op reordering feature
183  *                              0: disable reordering
184  *                              1: enable reordering
185  *
186  * @return
187  *      0 if setting successful, negative integer if otherwise.
188  */
189 int
190 rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id,
191                 uint32_t enable_reorder);
192
193 /**
194  * Get the current crypto ops reordering feature
195  *
196  * @param       dev_id          The target scheduler device ID
197  *
198  * @return
199  *      0 if reordering is disabled
200  *      1 if reordering is enabled
201  *      negative integer if otherwise.
202  */
203 int
204 rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
205
206 /**
207  * Get the the attached slaves' count and/or ID
208  *
209  * @param scheduler_id
210  *   The target scheduler device ID
211  * @param slaves
212  *  If successful, the function will write back
213  *  all slaves' device IDs to it. This
214  *  parameter SHALL either be an uint8_t array
215  *  of RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
216  *  elements or NULL.
217  *
218  * @return
219  *   - non-negative number: the number of slaves attached
220  *   - negative integer if error occurs.
221  */
222 int
223 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
224
225 /**
226  * Set the mode specific option
227  *
228  * @param dev_id
229  *   The target scheduler device ID
230  * @param option_type
231  *   The option type enumerate
232  * @param option
233  *   The specific mode's option structure
234  *
235  * @return
236  *   - 0 if successful
237  *   - negative integer if otherwise.
238  */
239 int
240 rte_cryptodev_scheduler_option_set(uint8_t scheduler_id,
241                 enum rte_cryptodev_schedule_option_type option_type,
242                 void *option);
243
244 /**
245  * Set the mode specific option
246  *
247  * @param dev_id
248  *   The target scheduler device ID
249  * @param option_type
250  *   The option type enumerate
251  * @param option
252  *   If successful, the function will write back the current
253  *
254  * @return
255  *   - 0 if successful
256  *   - negative integer if otherwise.
257  */
258 int
259 rte_cryptodev_scheduler_option_get(uint8_t scheduler_id,
260                 enum rte_cryptodev_schedule_option_type option_type,
261                 void *option);
262
263 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
264                 struct rte_crypto_op **ops, uint16_t nb_ops);
265
266 typedef uint16_t (*rte_cryptodev_scheduler_burst_dequeue_t)(void *qp_ctx,
267                 struct rte_crypto_op **ops, uint16_t nb_ops);
268
269 struct rte_cryptodev_scheduler {
270         const char *name;
271         const char *description;
272         enum rte_cryptodev_scheduler_mode mode;
273
274         struct rte_cryptodev_scheduler_ops *ops;
275 };
276
277 extern struct rte_cryptodev_scheduler *roundrobin_scheduler;
278 extern struct rte_cryptodev_scheduler *pkt_size_based_distr_scheduler;
279 extern struct rte_cryptodev_scheduler *failover_scheduler;
280
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif /* _RTE_CRYPTO_SCHEDULER_H */