a78e9a6feba0a66900f3521a428fcb786c4f64c5
[dpdk.git] / drivers / crypto / scheduler / scheduler_pmd_private.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 _SCHEDULER_PMD_PRIVATE_H
35 #define _SCHEDULER_PMD_PRIVATE_H
36
37 #include "rte_cryptodev_scheduler.h"
38
39 #define CRYPTODEV_NAME_SCHEDULER_PMD    crypto_scheduler
40 /**< Scheduler Crypto PMD device name */
41
42 #define PER_SLAVE_BUFF_SIZE                     (256)
43
44 #define CS_LOG_ERR(fmt, args...)                                        \
45         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",         \
46                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),                  \
47                 __func__, __LINE__, ## args)
48
49 #ifdef RTE_LIBRTE_CRYPTO_SCHEDULER_DEBUG
50 #define CS_LOG_INFO(fmt, args...)                                       \
51         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",        \
52                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),                  \
53                 __func__, __LINE__, ## args)
54
55 #define CS_LOG_DBG(fmt, args...)                                        \
56         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",       \
57                 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),                  \
58                 __func__, __LINE__, ## args)
59 #else
60 #define CS_LOG_INFO(fmt, args...)
61 #define CS_LOG_DBG(fmt, args...)
62 #endif
63
64 struct scheduler_slave {
65         uint8_t dev_id;
66         uint16_t qp_id;
67         uint32_t nb_inflight_cops;
68
69         uint8_t driver_id;
70 };
71
72 struct scheduler_ctx {
73         void *private_ctx;
74         /**< private scheduler context pointer */
75
76         struct rte_cryptodev_capabilities *capabilities;
77         uint32_t nb_capabilities;
78
79         uint32_t max_nb_queue_pairs;
80
81         struct scheduler_slave slaves[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES];
82         uint32_t nb_slaves;
83
84         enum rte_cryptodev_scheduler_mode mode;
85
86         struct rte_cryptodev_scheduler_ops ops;
87
88         uint8_t reordering_enabled;
89
90         char name[RTE_CRYPTODEV_SCHEDULER_NAME_MAX_LEN];
91         char description[RTE_CRYPTODEV_SCHEDULER_DESC_MAX_LEN];
92
93         char *init_slave_names[RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES];
94         int nb_init_slaves;
95 } __rte_cache_aligned;
96
97 struct scheduler_qp_ctx {
98         void *private_qp_ctx;
99
100         uint32_t max_nb_objs;
101
102         struct rte_ring *order_ring;
103         uint32_t seqn;
104 } __rte_cache_aligned;
105
106 struct scheduler_session {
107         struct rte_cryptodev_sym_session *sessions[
108                         RTE_CRYPTODEV_SCHEDULER_MAX_NB_SLAVES];
109 };
110
111 extern uint8_t cryptodev_driver_id;
112
113 static __rte_always_inline uint16_t
114 get_max_enqueue_order_count(struct rte_ring *order_ring, uint16_t nb_ops)
115 {
116         uint32_t count = rte_ring_free_count(order_ring);
117
118         return count > nb_ops ? nb_ops : count;
119 }
120
121 static __rte_always_inline void
122 scheduler_order_insert(struct rte_ring *order_ring,
123                 struct rte_crypto_op **ops, uint16_t nb_ops)
124 {
125         rte_ring_sp_enqueue_burst(order_ring, (void **)ops, nb_ops, NULL);
126 }
127
128 #define SCHEDULER_GET_RING_OBJ(order_ring, pos, op) do {            \
129         struct rte_crypto_op **ring = (void *)&order_ring[1];     \
130         op = ring[(order_ring->cons.head + pos) & order_ring->mask]; \
131 } while (0)
132
133 static __rte_always_inline uint16_t
134 scheduler_order_drain(struct rte_ring *order_ring,
135                 struct rte_crypto_op **ops, uint16_t nb_ops)
136 {
137         struct rte_crypto_op *op;
138         uint32_t nb_objs = rte_ring_count(order_ring);
139         uint32_t nb_ops_to_deq = 0;
140         uint32_t nb_ops_deqd = 0;
141
142         if (nb_objs > nb_ops)
143                 nb_objs = nb_ops;
144
145         while (nb_ops_to_deq < nb_objs) {
146                 SCHEDULER_GET_RING_OBJ(order_ring, nb_ops_to_deq, op);
147                 if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
148                         break;
149                 nb_ops_to_deq++;
150         }
151
152         if (nb_ops_to_deq)
153                 nb_ops_deqd = rte_ring_sc_dequeue_bulk(order_ring,
154                                 (void **)ops, nb_ops_to_deq, NULL);
155
156         return nb_ops_deqd;
157 }
158 /** device specific operations function pointer structure */
159 extern struct rte_cryptodev_ops *rte_crypto_scheduler_pmd_ops;
160
161 #endif /* _SCHEDULER_PMD_PRIVATE_H */