1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
8 #include <rte_eventdev.h>
9 #include <rte_eventdev_pmd_vdev.h>
10 #include <rte_atomic.h>
11 #include "opdl_ring.h"
13 #define OPDL_QID_NUM_FIDS 1024
14 #define OPDL_IQS_MAX 1
15 #define OPDL_Q_PRIORITY_MAX 1
16 #define OPDL_PORTS_MAX 64
17 #define MAX_OPDL_CONS_Q_DEPTH 128
19 #define OPDL_INFLIGHT_EVENTS_TOTAL 4096
20 /* allow for lots of over-provisioning */
21 #define OPDL_FRAGMENTS_MAX 1
23 /* report dequeue burst sizes in buckets */
24 #define OPDL_DEQ_STAT_BUCKET_SHIFT 2
25 /* how many packets pulled from port by sched */
26 #define SCHED_DEQUEUE_BURST_SIZE 32
28 /* size of our history list */
29 #define OPDL_PORT_HIST_LIST (MAX_OPDL_PROD_Q_DEPTH)
31 /* how many data points use for average stats */
32 #define NUM_SAMPLES 64
34 #define EVENTDEV_NAME_OPDL_PMD event_opdl
35 #define OPDL_PMD_NAME RTE_STR(event_opdl)
36 #define OPDL_PMD_NAME_MAX 64
38 #define OPDL_INVALID_QID 255
40 #define OPDL_SCHED_TYPE_DIRECT (RTE_SCHED_TYPE_PARALLEL + 1)
42 #define OPDL_NUM_POLL_BUCKETS \
43 (MAX_OPDL_CONS_Q_DEPTH >> OPDL_DEQ_STAT_BUCKET_SHIFT)
46 QE_FLAG_VALID_SHIFT = 0,
47 QE_FLAG_COMPLETE_SHIFT,
48 QE_FLAG_NOT_EOP_SHIFT,
53 OPDL_INVALID_PORT = 0,
54 OPDL_REGULAR_PORT = 1,
61 OPDL_Q_TYPE_INVALID = 0,
62 OPDL_Q_TYPE_SINGLE_LINK = 1,
73 #define QE_FLAG_VALID (1 << QE_FLAG_VALID_SHIFT) /* for NEW FWD, FRAG */
74 #define QE_FLAG_COMPLETE (1 << QE_FLAG_COMPLETE_SHIFT) /* set for FWD, DROP */
75 #define QE_FLAG_NOT_EOP (1 << QE_FLAG_NOT_EOP_SHIFT) /* set for FRAG only */
77 static const uint8_t opdl_qe_flag_map[] = {
78 QE_FLAG_VALID /* NEW Event */,
79 QE_FLAG_VALID | QE_FLAG_COMPLETE /* FWD Event */,
80 QE_FLAG_COMPLETE /* RELEASE Event */,
82 /* Values which can be used for future support for partial
83 * events, i.e. where one event comes back to the scheduler
84 * as multiple which need to be tracked together
86 QE_FLAG_VALID | QE_FLAG_COMPLETE | QE_FLAG_NOT_EOP,
90 enum port_xstat_name {
91 claim_pkts_requested = 0,
99 #define OPDL_MAX_PORT_XSTAT_NUM (OPDL_PORTS_MAX * max_num_port_xstat)
103 typedef uint16_t (*opdl_enq_operation)(struct opdl_port *port,
104 const struct rte_event ev[],
107 typedef uint16_t (*opdl_deq_operation)(struct opdl_port *port,
108 struct rte_event ev[],
113 struct opdl_stage_meta_data {
114 uint32_t num_claimed; /* number of entries claimed by this stage */
115 uint32_t burst_sz; /* Port claim burst size */
121 struct opdl_evdev *opdl;
123 /* enq handler & stage instance */
124 opdl_enq_operation enq;
125 struct opdl_stage *enq_stage_inst;
127 /* deq handler & stage instance */
128 opdl_deq_operation deq;
129 struct opdl_stage *deq_stage_inst;
131 /* port id has correctly been set */
134 /* set when the port is initialized */
137 /* A numeric ID for the port */
140 /* Space for claimed entries */
141 struct rte_event *entries[MAX_OPDL_CONS_Q_DEPTH];
143 /* RX/REGULAR/TX/ASYNC - determined on position in queue */
144 enum port_type p_type;
146 /* if the claim is static atomic type */
149 /* Queue linked to this port - internal queue id*/
152 /* Queue linked to this port - external queue id*/
153 uint8_t external_qid;
155 /* Next queue linked to this port - external queue id*/
156 uint8_t next_external_qid;
158 /* number of instances of this stage */
159 uint32_t num_instance;
161 /* instance ID of this stage*/
162 uint32_t instance_id;
164 /* track packets in and out of this port */
165 uint64_t port_stat[max_num_port_xstat];
166 uint64_t start_cycles;
169 struct opdl_queue_meta_data {
171 enum queue_type type;
175 struct opdl_xstats_entry {
176 struct rte_event_dev_xstats_name stat;
183 /* Opdl ring this queue is associated with */
186 /* type and position have correctly been set */
189 /* port number and associated ports have been associated */
192 /* type of this queue (Atomic, Ordered, Parallel, Direct)*/
193 enum queue_type q_type;
195 /* position of queue (START, MIDDLE, END) */
196 enum queue_pos q_pos;
198 /* external queue id. It is mapped to the queue position */
199 uint8_t external_qid;
201 struct opdl_port *ports[OPDL_PORTS_MAX];
204 /* priority, reserved for future */
209 #define OPDL_TUR_PER_DEV 12
211 /* PMD needs an extra queue per Opdl */
212 #define OPDL_MAX_QUEUES (RTE_EVENT_MAX_QUEUES_PER_DEV - OPDL_TUR_PER_DEV)
216 struct rte_eventdev_data *data;
220 /* Max number of ports and queues*/
221 uint32_t max_port_nb;
222 uint32_t max_queue_nb;
224 /* slots in the opdl ring */
225 uint32_t nb_events_limit;
228 * Array holding all opdl for this device
230 struct opdl_ring *opdl[OPDL_TUR_PER_DEV];
233 struct opdl_queue_meta_data q_md[OPDL_MAX_QUEUES];
236 /* Internal queues - one per logical queue */
238 queue[RTE_EVENT_MAX_QUEUES_PER_DEV] __rte_cache_aligned;
242 struct opdl_stage_meta_data s_md[OPDL_PORTS_MAX];
244 /* Contains all ports - load balanced and directed */
245 struct opdl_port ports[OPDL_PORTS_MAX] __rte_cache_aligned;
248 uint8_t q_map_ex_to_in[OPDL_INVALID_QID];
251 struct opdl_xstats_entry port_xstat[OPDL_MAX_PORT_XSTAT_NUM];
253 char service_name[OPDL_PMD_NAME_MAX];
260 static inline struct opdl_evdev *
261 opdl_pmd_priv(const struct rte_eventdev *eventdev)
263 return eventdev->data->dev_private;
266 static inline uint8_t
267 opdl_pmd_dev_id(const struct opdl_evdev *opdl)
269 return opdl->data->dev_id;
272 static inline const struct opdl_evdev *
273 opdl_pmd_priv_const(const struct rte_eventdev *eventdev)
275 return eventdev->data->dev_private;
278 uint16_t opdl_event_enqueue(void *port, const struct rte_event *ev);
279 uint16_t opdl_event_enqueue_burst(void *port, const struct rte_event ev[],
282 uint16_t opdl_event_dequeue(void *port, struct rte_event *ev, uint64_t wait);
283 uint16_t opdl_event_dequeue_burst(void *port, struct rte_event *ev,
284 uint16_t num, uint64_t wait);
285 void opdl_event_schedule(struct rte_eventdev *dev);
287 void opdl_xstats_init(struct rte_eventdev *dev);
288 int opdl_xstats_uninit(struct rte_eventdev *dev);
289 int opdl_xstats_get_names(const struct rte_eventdev *dev,
290 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
291 struct rte_event_dev_xstats_name *xstats_names,
292 unsigned int *ids, unsigned int size);
293 int opdl_xstats_get(const struct rte_eventdev *dev,
294 enum rte_event_dev_xstats_mode mode, uint8_t queue_port_id,
295 const unsigned int ids[], uint64_t values[], unsigned int n);
296 uint64_t opdl_xstats_get_by_name(const struct rte_eventdev *dev,
297 const char *name, unsigned int *id);
298 int opdl_xstats_reset(struct rte_eventdev *dev,
299 enum rte_event_dev_xstats_mode mode,
300 int16_t queue_port_id,
301 const uint32_t ids[],
304 int opdl_add_event_handlers(struct rte_eventdev *dev);
305 int build_all_dependencies(struct rte_eventdev *dev);
306 int check_queues_linked(struct rte_eventdev *dev);
307 int create_queues_and_rings(struct rte_eventdev *dev);
308 int initialise_all_other_ports(struct rte_eventdev *dev);
309 int initialise_queue_zero_ports(struct rte_eventdev *dev);
310 int assign_internal_queue_ids(struct rte_eventdev *dev);
311 void destroy_queues_and_rings(struct rte_eventdev *dev);
312 int opdl_selftest(void);
314 #endif /* _OPDL_EVDEV_H_ */