crypto/scheduler: add API to get attached slaves
[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 #include "rte_cryptodev_scheduler_operations.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**< Maximum number of bonded devices per device */
44 #ifndef RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
45 #define RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES   (8)
46 #endif
47
48 /**
49  * Crypto scheduler PMD operation modes
50  */
51 enum rte_cryptodev_scheduler_mode {
52         CDEV_SCHED_MODE_NOT_SET = 0,
53         CDEV_SCHED_MODE_USERDEFINED,
54         CDEV_SCHED_MODE_ROUNDROBIN,
55         /** packet-size based distribution mode */
56         CDEV_SCHED_MODE_PKT_SIZE_DISTR,
57         /** fail-over mode */
58         CDEV_SCHED_MODE_FAILOVER,
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 struct rte_cryptodev_scheduler;
67
68 /**
69  * Load a user defined scheduler
70  *
71  * @param       scheduler_id    The target scheduler device ID
72  *              scheduler       Pointer to the user defined scheduler
73  *
74  * @return
75  *      0 if loading successful, negative integer if otherwise.
76  */
77 int
78 rte_cryptodev_scheduler_load_user_scheduler(uint8_t scheduler_id,
79                 struct rte_cryptodev_scheduler *scheduler);
80
81 /**
82  * Attach a pre-configured crypto device to the scheduler
83  *
84  * @param       scheduler_id    The target scheduler device ID
85  *              slave_id        crypto device ID to be attached
86  *
87  * @return
88  *      0 if attaching successful, negative int if otherwise.
89  */
90 int
91 rte_cryptodev_scheduler_slave_attach(uint8_t scheduler_id, uint8_t slave_id);
92
93 /**
94  * Detach a attached crypto device to the scheduler
95  *
96  * @param       scheduler_id    The target scheduler device ID
97  *              slave_id        crypto device ID to be detached
98  *
99  * @return
100  *      0 if detaching successful, negative int if otherwise.
101  */
102 int
103 rte_cryptodev_scheduler_slave_detach(uint8_t scheduler_id, uint8_t slave_id);
104
105 /**
106  * Set the scheduling mode
107  *
108  * @param       scheduler_id    The target scheduler device ID
109  *              mode            The scheduling mode
110  *
111  * @return
112  *      0 if attaching successful, negative integer if otherwise.
113  */
114 int
115 rte_crpytodev_scheduler_mode_set(uint8_t scheduler_id,
116                 enum rte_cryptodev_scheduler_mode mode);
117
118 /**
119  * Get the current scheduling mode
120  *
121  * @param       scheduler_id    The target scheduler device ID
122  *              mode            Pointer to write the scheduling mode
123  */
124 enum rte_cryptodev_scheduler_mode
125 rte_crpytodev_scheduler_mode_get(uint8_t scheduler_id);
126
127 /**
128  * Set the crypto ops reordering feature on/off
129  *
130  * @param       dev_id          The target scheduler device ID
131  *              enable_reorder  set the crypto op reordering feature
132  *                              0: disable reordering
133  *                              1: enable reordering
134  *
135  * @return
136  *      0 if setting successful, negative integer if otherwise.
137  */
138 int
139 rte_cryptodev_scheduler_ordering_set(uint8_t scheduler_id,
140                 uint32_t enable_reorder);
141
142 /**
143  * Get the current crypto ops reordering feature
144  *
145  * @param       dev_id          The target scheduler device ID
146  *
147  * @return
148  *      0 if reordering is disabled
149  *      1 if reordering is enabled
150  *      negative integer if otherwise.
151  */
152 int
153 rte_cryptodev_scheduler_ordering_get(uint8_t scheduler_id);
154
155 /**
156  * Get the the attached slaves' count and/or ID
157  *
158  * @param scheduler_id
159  *   The target scheduler device ID
160  * @param slaves
161  *  If successful, the function will write back
162  *  all slaves' device IDs to it. This
163  *  parameter SHALL either be an uint8_t array
164  *  of RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES
165  *  elements or NULL.
166  *
167  * @return
168  *   - non-negative number: the number of slaves attached
169  *   - negative integer if error occurs.
170  */
171 int
172 rte_cryptodev_scheduler_slaves_get(uint8_t scheduler_id, uint8_t *slaves);
173
174 typedef uint16_t (*rte_cryptodev_scheduler_burst_enqueue_t)(void *qp_ctx,
175                 struct rte_crypto_op **ops, uint16_t nb_ops);
176
177 typedef uint16_t (*rte_cryptodev_scheduler_burst_dequeue_t)(void *qp_ctx,
178                 struct rte_crypto_op **ops, uint16_t nb_ops);
179
180 struct rte_cryptodev_scheduler {
181         const char *name;
182         const char *description;
183         enum rte_cryptodev_scheduler_mode mode;
184
185         struct rte_cryptodev_scheduler_ops *ops;
186 };
187
188 extern struct rte_cryptodev_scheduler *roundrobin_scheduler;
189 extern struct rte_cryptodev_scheduler *pkt_size_based_distr_scheduler;
190 extern struct rte_cryptodev_scheduler *failover_scheduler;
191
192 #ifdef __cplusplus
193 }
194 #endif
195 #endif /* _RTE_CRYPTO_SCHEDULER_H */