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