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