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 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. 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 bonding devices per device */ 28 #ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS 29 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_WORKERS (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 worker_id 110 * Crypto device ID to be attached 111 * 112 * @return 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. 117 */ 118 int 119 rte_cryptodev_scheduler_worker_attach(uint8_t scheduler_id, uint8_t worker_id); 120 121 /** 122 * Detach a crypto device from the scheduler 123 * 124 * @param scheduler_id 125 * The target scheduler device ID 126 * @param worker_id 127 * Crypto device ID to be detached 128 * 129 * @return 130 * - 0 if the worker is detached. 131 * - -ENOTSUP if the operation is not supported. 132 * - -EBUSY if device is started. 133 */ 134 int 135 rte_cryptodev_scheduler_worker_detach(uint8_t scheduler_id, uint8_t worker_id); 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 workers' count and/or ID 202 * 203 * @param scheduler_id 204 * The target scheduler device ID 205 * @param workers 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. 209 * 210 * @return 211 * - non-negative number: the number of workers attached 212 * - -ENOTSUP if the operation is not supported. 213 */ 214 int 215 rte_cryptodev_scheduler_workers_get(uint8_t scheduler_id, uint8_t *workers); 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 *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; 279 280 #ifdef __cplusplus 281 } 282 #endif 283 #endif /* _RTE_CRYPTO_SCHEDULER_H */ 284