4 * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
36 #include <rte_memzone.h>
37 #include <rte_kvargs.h>
43 #define EVENTDEV_NAME_SW_PMD event_sw
44 #define NUMA_NODE_ARG "numa_node"
45 #define SCHED_QUANTA_ARG "sched_quanta"
46 #define CREDIT_QUANTA_ARG "credit_quanta"
49 qid_init(struct sw_evdev *sw, unsigned int idx, int type,
50 const struct rte_event_queue_conf *queue_conf)
53 int dev_id = sw->data->dev_id;
54 int socket_id = sw->data->socket_id;
55 char buf[IQ_RING_NAMESIZE];
56 struct sw_qid *qid = &sw->qids[idx];
58 for (i = 0; i < SW_IQS_MAX; i++) {
59 snprintf(buf, sizeof(buf), "q_%u_iq_%d", idx, i);
60 qid->iq[i] = iq_ring_create(buf, socket_id);
62 SW_LOG_DBG("ring create failed");
67 /* Initialize the FID structures to no pinning (-1), and zero packets */
68 const struct sw_fid_t fid = {.cq = -1, .pcount = 0};
69 for (i = 0; i < RTE_DIM(qid->fids); i++)
74 qid->priority = queue_conf->priority;
76 if (qid->type == RTE_SCHED_TYPE_ORDERED) {
77 char ring_name[RTE_RING_NAMESIZE];
80 /* rte_ring and window_size_mask require require window_size to
83 window_size = rte_align32pow2(
84 queue_conf->nb_atomic_order_sequences);
86 qid->window_size = window_size - 1;
90 "invalid reorder_window_size for ordered queue\n"
95 snprintf(buf, sizeof(buf), "sw%d_iq_%d_rob", dev_id, i);
96 qid->reorder_buffer = rte_zmalloc_socket(buf,
97 window_size * sizeof(qid->reorder_buffer[0]),
99 if (!qid->reorder_buffer) {
100 SW_LOG_DBG("reorder_buffer malloc failed\n");
104 memset(&qid->reorder_buffer[0],
106 window_size * sizeof(qid->reorder_buffer[0]));
108 snprintf(ring_name, sizeof(ring_name), "sw%d_q%d_freelist",
111 /* lookup the ring, and if it already exists, free it */
112 struct rte_ring *cleanup = rte_ring_lookup(ring_name);
114 rte_ring_free(cleanup);
116 qid->reorder_buffer_freelist = rte_ring_create(ring_name,
119 RING_F_SP_ENQ | RING_F_SC_DEQ);
120 if (!qid->reorder_buffer_freelist) {
121 SW_LOG_DBG("freelist ring create failed");
125 /* Populate the freelist with reorder buffer entries. Enqueue
126 * 'window_size - 1' entries because the rte_ring holds only
129 for (i = 0; i < window_size - 1; i++) {
130 if (rte_ring_sp_enqueue(qid->reorder_buffer_freelist,
131 &qid->reorder_buffer[i]) < 0)
135 qid->reorder_buffer_index = 0;
139 qid->initialized = 1;
144 for (i = 0; i < SW_IQS_MAX; i++) {
146 iq_ring_destroy(qid->iq[i]);
149 if (qid->reorder_buffer) {
150 rte_free(qid->reorder_buffer);
151 qid->reorder_buffer = NULL;
154 if (qid->reorder_buffer_freelist) {
155 rte_ring_free(qid->reorder_buffer_freelist);
156 qid->reorder_buffer_freelist = NULL;
163 sw_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
164 const struct rte_event_queue_conf *conf)
168 /* SINGLE_LINK can be OR-ed with other types, so handle first */
169 if (RTE_EVENT_QUEUE_CFG_SINGLE_LINK & conf->event_queue_cfg) {
170 type = SW_SCHED_TYPE_DIRECT;
172 switch (conf->event_queue_cfg) {
173 case RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY:
174 type = RTE_SCHED_TYPE_ATOMIC;
176 case RTE_EVENT_QUEUE_CFG_ORDERED_ONLY:
177 type = RTE_SCHED_TYPE_ORDERED;
179 case RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY:
180 type = RTE_SCHED_TYPE_PARALLEL;
182 case RTE_EVENT_QUEUE_CFG_ALL_TYPES:
183 SW_LOG_ERR("QUEUE_CFG_ALL_TYPES not supported\n");
186 SW_LOG_ERR("Unknown queue type %d requested\n",
187 conf->event_queue_cfg);
192 struct sw_evdev *sw = sw_pmd_priv(dev);
193 return qid_init(sw, queue_id, type, conf);
197 sw_queue_release(struct rte_eventdev *dev, uint8_t id)
199 struct sw_evdev *sw = sw_pmd_priv(dev);
200 struct sw_qid *qid = &sw->qids[id];
203 for (i = 0; i < SW_IQS_MAX; i++)
204 iq_ring_destroy(qid->iq[i]);
206 if (qid->type == RTE_SCHED_TYPE_ORDERED) {
207 rte_free(qid->reorder_buffer);
208 rte_ring_free(qid->reorder_buffer_freelist);
210 memset(qid, 0, sizeof(*qid));
214 sw_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
215 struct rte_event_queue_conf *conf)
218 RTE_SET_USED(queue_id);
220 static const struct rte_event_queue_conf default_conf = {
221 .nb_atomic_flows = 4096,
222 .nb_atomic_order_sequences = 1,
223 .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY,
224 .priority = RTE_EVENT_DEV_PRIORITY_NORMAL,
227 *conf = default_conf;
231 sw_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
232 struct rte_event_port_conf *port_conf)
235 RTE_SET_USED(port_id);
237 port_conf->new_event_threshold = 1024;
238 port_conf->dequeue_depth = 16;
239 port_conf->enqueue_depth = 16;
243 sw_dev_configure(const struct rte_eventdev *dev)
245 struct sw_evdev *sw = sw_pmd_priv(dev);
246 const struct rte_eventdev_data *data = dev->data;
247 const struct rte_event_dev_config *conf = &data->dev_conf;
249 sw->qid_count = conf->nb_event_queues;
250 sw->port_count = conf->nb_event_ports;
251 sw->nb_events_limit = conf->nb_events_limit;
253 if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT)
260 sw_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *info)
264 static const struct rte_event_dev_info evdev_sw_info = {
265 .driver_name = SW_PMD_NAME,
266 .max_event_queues = RTE_EVENT_MAX_QUEUES_PER_DEV,
267 .max_event_queue_flows = SW_QID_NUM_FIDS,
268 .max_event_queue_priority_levels = SW_Q_PRIORITY_MAX,
269 .max_event_priority_levels = SW_IQS_MAX,
270 .max_event_ports = SW_PORTS_MAX,
271 .max_event_port_dequeue_depth = MAX_SW_CONS_Q_DEPTH,
272 .max_event_port_enqueue_depth = MAX_SW_PROD_Q_DEPTH,
273 .max_num_events = SW_INFLIGHT_EVENTS_TOTAL,
274 .event_dev_cap = (RTE_EVENT_DEV_CAP_QUEUE_QOS |
275 RTE_EVENT_DEV_CAP_EVENT_QOS),
278 *info = evdev_sw_info;
282 assign_numa_node(const char *key __rte_unused, const char *value, void *opaque)
284 int *socket_id = opaque;
285 *socket_id = atoi(value);
286 if (*socket_id >= RTE_MAX_NUMA_NODES)
292 set_sched_quanta(const char *key __rte_unused, const char *value, void *opaque)
294 int *quanta = opaque;
295 *quanta = atoi(value);
296 if (*quanta < 0 || *quanta >= 4096)
302 set_credit_quanta(const char *key __rte_unused, const char *value, void *opaque)
304 int *credit = opaque;
305 *credit = atoi(value);
306 if (*credit < 0 || *credit >= 128)
312 sw_probe(const char *name, const char *params)
314 static const struct rte_eventdev_ops evdev_sw_ops = {
315 .dev_configure = sw_dev_configure,
316 .dev_infos_get = sw_info_get,
318 .queue_def_conf = sw_queue_def_conf,
319 .queue_setup = sw_queue_setup,
320 .queue_release = sw_queue_release,
321 .port_def_conf = sw_port_def_conf,
324 static const char *const args[] = {
330 struct rte_eventdev *dev;
332 int socket_id = rte_socket_id();
333 int sched_quanta = SW_DEFAULT_SCHED_QUANTA;
334 int credit_quanta = SW_DEFAULT_CREDIT_QUANTA;
336 if (params != NULL && params[0] != '\0') {
337 struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
341 "Ignoring unsupported parameters when creating device '%s'\n",
344 int ret = rte_kvargs_process(kvlist, NUMA_NODE_ARG,
345 assign_numa_node, &socket_id);
348 "%s: Error parsing numa node parameter",
350 rte_kvargs_free(kvlist);
354 ret = rte_kvargs_process(kvlist, SCHED_QUANTA_ARG,
355 set_sched_quanta, &sched_quanta);
358 "%s: Error parsing sched quanta parameter",
360 rte_kvargs_free(kvlist);
364 ret = rte_kvargs_process(kvlist, CREDIT_QUANTA_ARG,
365 set_credit_quanta, &credit_quanta);
368 "%s: Error parsing credit quanta parameter",
370 rte_kvargs_free(kvlist);
374 rte_kvargs_free(kvlist);
379 "Creating eventdev sw device %s, numa_node=%d, sched_quanta=%d, credit_quanta=%d\n",
380 name, socket_id, sched_quanta, credit_quanta);
382 dev = rte_event_pmd_vdev_init(name,
383 sizeof(struct sw_evdev), socket_id);
385 SW_LOG_ERR("eventdev vdev init() failed");
388 dev->dev_ops = &evdev_sw_ops;
390 sw = dev->data->dev_private;
391 sw->data = dev->data;
393 /* copy values passed from vdev command line to instance */
394 sw->credit_update_quanta = credit_quanta;
395 sw->sched_quanta = sched_quanta;
401 sw_remove(const char *name)
406 SW_LOG_INFO("Closing eventdev sw device %s\n", name);
408 return rte_event_pmd_vdev_uninit(name);
411 static struct rte_vdev_driver evdev_sw_pmd_drv = {
416 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_SW_PMD, evdev_sw_pmd_drv);
417 RTE_PMD_REGISTER_PARAM_STRING(event_sw, NUMA_NODE_ARG "=<int> "
418 SCHED_QUANTA_ARG "=<int>" CREDIT_QUANTA_ARG "=<int>");