ddf0cd213885b12121e4d12072d32cf1c41b7cec
[dpdk.git] / drivers / event / sw / sw_evdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _SW_EVDEV_H_
34 #define _SW_EVDEV_H_
35
36 #include <rte_eventdev.h>
37 #include <rte_eventdev_pmd.h>
38 #include <rte_atomic.h>
39
40 #define SW_DEFAULT_CREDIT_QUANTA 32
41 #define SW_DEFAULT_SCHED_QUANTA 128
42 #define SW_QID_NUM_FIDS 16384
43 #define SW_IQS_MAX 4
44 #define SW_Q_PRIORITY_MAX 255
45 #define SW_PORTS_MAX 64
46 #define MAX_SW_CONS_Q_DEPTH 128
47 #define SW_INFLIGHT_EVENTS_TOTAL 4096
48 /* allow for lots of over-provisioning */
49 #define MAX_SW_PROD_Q_DEPTH 4096
50 #define SW_FRAGMENTS_MAX 16
51
52 #define EVENTDEV_NAME_SW_PMD event_sw
53 #define SW_PMD_NAME RTE_STR(event_sw)
54
55 #define SW_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
56
57 #ifdef RTE_LIBRTE_PMD_EVDEV_SW_DEBUG
58 #define SW_LOG_INFO(fmt, args...) \
59         RTE_LOG(INFO, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
60                         SW_PMD_NAME, \
61                         __func__, __LINE__, ## args)
62
63 #define SW_LOG_DBG(fmt, args...) \
64         RTE_LOG(DEBUG, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
65                         SW_PMD_NAME, \
66                         __func__, __LINE__, ## args)
67 #else
68 #define SW_LOG_INFO(fmt, args...)
69 #define SW_LOG_DBG(fmt, args...)
70 #endif
71
72 #define SW_LOG_ERR(fmt, args...) \
73         RTE_LOG(ERR, EVENTDEV, "[%s] %s() line %u: " fmt "\n", \
74                         SW_PMD_NAME, \
75                         __func__, __LINE__, ## args)
76
77 /* Records basic event stats at a given point. Used in port and qid structs */
78 struct sw_point_stats {
79         uint64_t rx_pkts;
80         uint64_t rx_dropped;
81         uint64_t tx_pkts;
82 };
83
84 /* structure used to track what port a flow (FID) is pinned to */
85 struct sw_fid_t {
86         /* which CQ this FID is currently pinned to */
87         int32_t cq;
88         /* number of packets gone to the CQ with this FID */
89         uint32_t pcount;
90 };
91
92 struct reorder_buffer_entry {
93         uint16_t num_fragments;         /**< Number of packet fragments */
94         uint16_t fragment_index;        /**< Points to the oldest valid frag */
95         uint8_t ready;                  /**< Entry is ready to be reordered */
96         struct rte_event fragments[SW_FRAGMENTS_MAX];
97 };
98
99 struct sw_qid {
100         /* set when the QID has been initialized */
101         uint8_t initialized;
102         /* The type of this QID */
103         int8_t type;
104         /* Integer ID representing the queue. This is used in history lists,
105          * to identify the stage of processing.
106          */
107         uint32_t id;
108         struct sw_point_stats stats;
109
110         /* Internal priority rings for packets */
111         struct iq_ring *iq[SW_IQS_MAX];
112         uint32_t iq_pkt_mask; /* A mask to indicate packets in an IQ */
113         uint64_t iq_pkt_count[SW_IQS_MAX];
114
115         /* Information on what CQs are polling this IQ */
116         uint32_t cq_num_mapped_cqs;
117         uint32_t cq_next_tx; /* cq to write next (non-atomic) packet */
118         uint32_t cq_map[SW_PORTS_MAX];
119
120         /* Track flow ids for atomic load balancing */
121         struct sw_fid_t fids[SW_QID_NUM_FIDS];
122
123         /* Track packet order for reordering when needed */
124         struct reorder_buffer_entry *reorder_buffer; /*< pkts await reorder */
125         struct rte_ring *reorder_buffer_freelist; /* available reorder slots */
126         uint32_t reorder_buffer_index; /* oldest valid reorder buffer entry */
127         uint32_t window_size;          /* Used to wrap reorder_buffer_index */
128
129         uint8_t priority;
130 };
131
132 struct sw_evdev {
133         struct rte_eventdev_data *data;
134
135         uint32_t port_count;
136         uint32_t qid_count;
137
138         /*
139          * max events in this instance. Cached here for performance.
140          * (also available in data->conf.nb_events_limit)
141          */
142         uint32_t nb_events_limit;
143
144         /* Internal queues - one per logical queue */
145         struct sw_qid qids[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
146
147         int32_t sched_quanta;
148
149         uint32_t credit_update_quanta;
150 };
151
152 static inline struct sw_evdev *
153 sw_pmd_priv(const struct rte_eventdev *eventdev)
154 {
155         return eventdev->data->dev_private;
156 }
157
158 static inline const struct sw_evdev *
159 sw_pmd_priv_const(const struct rte_eventdev *eventdev)
160 {
161         return eventdev->data->dev_private;
162 }
163
164 #endif /* _SW_EVDEV_H_ */