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