e8d3c454bb4f999a044ad9fc3c28723471bd8437
[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 /**
38  * @file rte_cryptodev_scheduler.h
39  *
40  * RTE Cryptodev Scheduler Device
41  *
42  * The RTE Cryptodev Scheduler Device allows the aggregation of multiple (slave)
43  * Cryptodevs into a single logical crypto device, and the scheduling the
44  * crypto operations to the slaves based on the mode of the specified mode of
45  * operation specified and supported. This implementation supports 3 modes of
46  * operation: round robin, packet-size based, and fail-over.
47  */
48
49 #include <stdint.h>
50 #include "rte_cryptodev_scheduler_operations.h"
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 /** Maximum number of bonded devices per device */
57 #ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
58 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES   (8)
59 #endif
60
61 /** Maximum number of multi-core worker cores */
62 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKER_CORES     (64)
63
64 /** Round-robin scheduling mode string */
65 #define SCHEDULER_MODE_NAME_ROUND_ROBIN         round-robin
66 /** Packet-size based distribution scheduling mode string */
67 #define SCHEDULER_MODE_NAME_PKT_SIZE_DISTR      packet-size-distr
68 /** Fail-over scheduling mode string */
69 #define SCHEDULER_MODE_NAME_FAIL_OVER           fail-over
70 /** multi-core scheduling mode string */
71 #define SCHEDULER_MODE_NAME_MULTI_CORE          multi-core
72
73 /**
74  * Crypto scheduler PMD operation modes
75  */
76 enum rte_cryptodev_scheduler_mode {
77         CDEV_SCHED_MODE_NOT_SET = 0,
78         /** User defined mode */
79         CDEV_SCHED_MODE_USERDEFINED,
80         /** Round-robin mode */
81         CDEV_SCHED_MODE_ROUNDROBIN,
82         /** Packet-size based distribution mode */
83         CDEV_SCHED_MODE_PKT_SIZE_DISTR,
84         /** Fail-over mode */
85         CDEV_SCHED_MODE_FAILOVER,
86         /** multi-core mode */
87         CDEV_SCHED_MODE_MULTICORE,
88
89         CDEV_SCHED_MODE_COUNT /**< number of modes */
90 };
91
92 #define RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN    (64)
93 #define RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN    (256)
94
95 /**
96  * Crypto scheduler option types
97  */
98 enum rte_cryptodev_schedule_option_type {
99         CDEV_SCHED_OPTION_NOT_SET = 0,
100         CDEV_SCHED_OPTION_THRESHOLD,
101
102         CDEV_SCHED_OPTION_COUNT
103 };
104
105 /**
106  * Threshold option structure
107  */
108 struct rte_cryptodev_scheduler_threshold_option {
109         uint32_t threshold;     /**< Threshold for packet-size mode */
110 };
111
112 struct rte_cryptodev_scheduler;
113
114 /**
115  * Load a user defined scheduler
116  *
117  * @param scheduler_id
118  *   The target scheduler device ID
119  * @param scheduler
120  *   Pointer to the user defined scheduler
121  *
122  * @return
123  *   - 0 if the scheduler is successfully loaded
124  *   - -ENOTSUP if the operation is not supported.
125  *   - -EBUSY if device is started.
126  */
127 int
128 rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
129                 struct rte_cryptodev_scheduler *scheduler);
130
131 /**
132  * Attach a crypto device to the scheduler
133  *
134  * @param scheduler_id
135  *   The target scheduler device ID
136  * @param slave_id
137  *   Crypto device ID to be attached
138  *
139  * @return
140  *   - 0 if the slave is attached.
141  *   - -ENOTSUP if the operation is not supported.
142  *   - -EBUSY if device is started.
143  *   - -ENOMEM if the scheduler's slave list is full.
144  */
145 int
146 rte_cryptodev_scheduler_slave_attach(uint8_t scheduler_id, uint8_t slave_id);
147
148 /**
149  * Detach a crypto device from the scheduler
150  *
151  * @param scheduler_id
152  *   The target scheduler device ID
153  * @param slave_id
154  *   Crypto device ID to be detached
155  *
156  * @return
157  *   - 0 if the slave is detached.
158  *   - -ENOTSUP if the operation is not supported.
159  *   - -EBUSY if device is started.
160  */
161 int
162 rte_cryptodev_scheduler_slave_detach(uint8_t scheduler_id, uint8_t slave_id);
163
164
165 /**
166  * Set the scheduling mode
167  *
168  * @param scheduler_id
169  *   The target scheduler device ID
170  * @param mode
171  *   The scheduling mode
172  *
173  * @return
174  *   - 0 if the mode is set.
175  *   - -ENOTSUP if the operation is not supported.
176  *   - -EBUSY if device is started.
177  */
178 int
179 rte_cryptodev_scheduler_mode_set(uint8_t scheduler_id,
180                 enum rte_cryptodev_scheduler_mode mode);
181
182 /**
183  * Get the current scheduling mode
184  *
185  * @param scheduler_id
186  *   The target scheduler device ID
187  *
188  * @return mode
189  *   - non-negative enumerate value: the scheduling mode
190  *   - -ENOTSUP if the operation is not supported.
191  */
192 enum rte_cryptodev_scheduler_mode
193 rte_cryptodev_scheduler_mode_get(uint8_t scheduler_id);
194
195 /**
196  * Set the crypto ops reordering feature on/off
197  *
198  * @param scheduler_id
199  *   The target scheduler device ID
200  * @param enable_reorder
201  *   Set the crypto op reordering feature
202  *   - 0: disable reordering
203  *   - 1: enable reordering
204  *
205  * @return
206  *   - 0 if the ordering is set.
207  *   - -ENOTSUP if the operation is not supported.
208  *   - -EBUSY if device is started.
209  */
210 int
211 rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id,
212                 uint32_t enable_reorder);
213
214 /**
215  * Get the current crypto ops reordering feature
216  *
217  * @param scheduler_id
218  *   The target scheduler device ID
219  *
220  * @return
221  *   - 0 if reordering is disabled
222  *   - 1 if reordering is enabled
223  *   - -ENOTSUP if the operation is not supported.
224  */
225 int
226 rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
227
228 /**
229  * Get the the attached slaves' count and/or ID
230  *
231  * @param scheduler_id
232  *   The target scheduler device ID
233  * @param slaves
234  *   If successful, the function will write back all slaves' device IDs to it.
235  *   This parameter will either be an uint8_t array of
236  *   RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES elements or NULL.
237  *
238  * @return
239  *   - non-negative number: the number of slaves attached
240  *   - -ENOTSUP if the operation is not supported.
241  */
242 int
243 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
244
245 /**
246  * Set the mode specific option
247  *
248  * @param scheduler_id
249  *   The target scheduler device ID
250  * @param option_type
251  *   The option type enumerate
252  * @param option
253  *   The specific mode's option structure
254  *
255  * @return
256  *   - 0 if successful
257  *   - negative integer if otherwise.
258  */
259 int
260 rte_cryptodev_scheduler_option_set(uint8_t scheduler_id,
261                 enum rte_cryptodev_schedule_option_type option_type,
262                 void *option);
263
264 /**
265  * Set the mode specific option
266  *
267  * @param scheduler_id
268  *   The target scheduler device ID
269  * @param option_type
270  *   The option type enumerate
271  * @param option
272  *   If successful, the function will write back the current
273  *
274  * @return
275  *   - 0 if successful
276  *   - negative integer if otherwise.
277  */
278 int
279 rte_cryptodev_scheduler_option_get(uint8_t scheduler_id,
280                 enum rte_cryptodev_schedule_option_type option_type,
281                 void *option);
282
283 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
284                 struct rte_crypto_op **ops, uint16_t nb_ops);
285
286 typedef uint16_t (*rte_cryptodev_scheduler_burst_dequeue_t)(void *qp_ctx,
287                 struct rte_crypto_op **ops, uint16_t nb_ops);
288
289 /** The data structure associated with each mode of scheduler. */
290 struct rte_cryptodev_scheduler {
291         const char *name;                        /**< Scheduler name */
292         const char *description;                 /**< Scheduler description */
293         enum rte_cryptodev_scheduler_mode mode;  /**< Scheduling mode */
294
295         /** Pointer to scheduler operation structure */
296         struct rte_cryptodev_scheduler_ops *ops;
297 };
298
299 /** Round-robin mode scheduler */
300 extern struct rte_cryptodev_scheduler *roundrobin_scheduler;
301 /** Packet-size based distribution mode scheduler */
302 extern struct rte_cryptodev_scheduler *pkt_size_based_distr_scheduler;
303 /** Fail-over mode scheduler */
304 extern struct rte_cryptodev_scheduler *failover_scheduler;
305 /** multi-core mode scheduler */
306 extern struct rte_cryptodev_scheduler *multicore_scheduler;
307
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif /* _RTE_CRYPTO_SCHEDULER_H */