1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef _RTE_CRYPTO_SCHEDULER_H
6 #define _RTE_CRYPTO_SCHEDULER_H
9 * @file rte_cryptodev_scheduler.h
11 * RTE Cryptodev Scheduler Device
13 * The RTE Cryptodev Scheduler Device allows the aggregation of multiple worker
14 * Cryptodevs into a single logical crypto device, and the scheduling the
15 * crypto operations to the workers 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.
21 #include "rte_cryptodev_scheduler_operations.h"
27 /** Maximum number of bonded devices per device */
28 #ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS
29 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS (8)
32 /** Maximum number of multi-core worker cores */
33 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKER_CORES (RTE_MAX_LCORE - 1)
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
45 * Crypto scheduler PMD operation modes
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,
56 CDEV_SCHED_MODE_FAILOVER,
57 /** multi-core mode */
58 CDEV_SCHED_MODE_MULTICORE,
60 CDEV_SCHED_MODE_COUNT /**< number of modes */
63 #define RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN (64)
64 #define RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN (256)
67 * Crypto scheduler option types
69 enum rte_cryptodev_schedule_option_type {
70 CDEV_SCHED_OPTION_NOT_SET = 0,
71 CDEV_SCHED_OPTION_THRESHOLD,
73 CDEV_SCHED_OPTION_COUNT
77 * Threshold option structure
79 #define RTE_CRYPTODEV_SCHEDULER_PARAM_THRES "threshold"
80 struct rte_cryptodev_scheduler_threshold_option {
81 uint32_t threshold; /**< Threshold for packet-size mode */
84 struct rte_cryptodev_scheduler;
87 * Load a user defined scheduler
90 * The target scheduler device ID
92 * Pointer to the user defined scheduler
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.
101 rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
102 struct rte_cryptodev_scheduler *scheduler);
105 * Attach a crypto device to the scheduler
107 * @param scheduler_id
108 * The target scheduler device ID
110 * Crypto device ID to be attached
113 * - 0 if the worker is attached.
114 * - -ENOTSUP if the operation is not supported.
115 * - -EBUSY if device is started.
116 * - -ENOMEM if the scheduler's worker list is full.
119 rte_cryptodev_scheduler_worker_attach(uint8_t scheduler_id, uint8_t worker_id);
122 * Detach a crypto device from the scheduler
124 * @param scheduler_id
125 * The target scheduler device ID
127 * Crypto device ID to be detached
130 * - 0 if the worker is detached.
131 * - -ENOTSUP if the operation is not supported.
132 * - -EBUSY if device is started.
135 rte_cryptodev_scheduler_worker_detach(uint8_t scheduler_id, uint8_t worker_id);
138 * Set the scheduling mode
140 * @param scheduler_id
141 * The target scheduler device ID
143 * The scheduling mode
146 * - 0 if the mode is set.
147 * - -ENOTSUP if the operation is not supported.
148 * - -EBUSY if device is started.
151 rte_cryptodev_scheduler_mode_set(uint8_t scheduler_id,
152 enum rte_cryptodev_scheduler_mode mode);
155 * Get the current scheduling mode
157 * @param scheduler_id
158 * The target scheduler device ID
161 * - non-negative enumerate value: the scheduling mode
162 * - -ENOTSUP if the operation is not supported.
164 enum rte_cryptodev_scheduler_mode
165 rte_cryptodev_scheduler_mode_get(uint8_t scheduler_id);
168 * Set the crypto ops reordering feature on/off
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
178 * - 0 if the ordering is set.
179 * - -ENOTSUP if the operation is not supported.
180 * - -EBUSY if device is started.
183 rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id,
184 uint32_t enable_reorder);
187 * Get the current crypto ops reordering feature
189 * @param scheduler_id
190 * The target scheduler device ID
193 * - 0 if reordering is disabled
194 * - 1 if reordering is enabled
195 * - -ENOTSUP if the operation is not supported.
198 rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
201 * Get the attached workers' count and/or ID
203 * @param scheduler_id
204 * The target scheduler device ID
206 * If successful, the function will write back all workers' device IDs to it.
207 * This parameter will either be an uint8_t array of
208 * RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS elements or NULL.
211 * - non-negative number: the number of workers attached
212 * - -ENOTSUP if the operation is not supported.
215 rte_cryptodev_scheduler_workers_get(uint8_t scheduler_id, uint8_t *workers);
218 * Set the mode specific option
220 * @param scheduler_id
221 * The target scheduler device ID
223 * The option type enumerate
225 * The specific mode's option structure
229 * - negative integer if otherwise.
232 rte_cryptodev_scheduler_option_set(uint8_t scheduler_id,
233 enum rte_cryptodev_schedule_option_type option_type,
237 * Set the mode specific option
239 * @param scheduler_id
240 * The target scheduler device ID
242 * The option type enumerate
244 * If successful, the function will write back the current
248 * - negative integer if otherwise.
251 rte_cryptodev_scheduler_option_get(uint8_t scheduler_id,
252 enum rte_cryptodev_schedule_option_type option_type,
255 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
256 struct rte_crypto_op **ops, uint16_t nb_ops);
258 typedef uint16_t (*rte_cryptodev_scheduler_burst_dequeue_t)(void *qp_ctx,
259 struct rte_crypto_op **ops, uint16_t nb_ops);
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 */
267 /** Pointer to scheduler operation structure */
268 struct rte_cryptodev_scheduler_ops *ops;
271 /** Round-robin mode scheduler */
272 extern struct rte_cryptodev_scheduler *crypto_scheduler_roundrobin;
273 /** Packet-size based distribution mode scheduler */
274 extern struct rte_cryptodev_scheduler *crypto_scheduler_pkt_size_based_distr;
275 /** Fail-over mode scheduler */
276 extern struct rte_cryptodev_scheduler *crypto_scheduler_failover;
277 /** multi-core mode scheduler */
278 extern struct rte_cryptodev_scheduler *crypto_scheduler_multicore;
283 #endif /* _RTE_CRYPTO_SCHEDULER_H */