Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Ericsson AB
3 : : */
4 : :
5 : : #include <stdbool.h>
6 : :
7 : : #include <rte_cycles.h>
8 : : #include <eventdev_pmd.h>
9 : : #include <eventdev_pmd_vdev.h>
10 : : #include <rte_random.h>
11 : : #include <rte_ring_elem.h>
12 : :
13 : : #include "dsw_evdev.h"
14 : :
15 : : #define EVENTDEV_NAME_DSW_PMD event_dsw
16 : :
17 : : static int
18 : 0 : dsw_port_setup(struct rte_eventdev *dev, uint8_t port_id,
19 : : const struct rte_event_port_conf *conf)
20 : : {
21 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
22 : : struct dsw_port *port;
23 : : struct rte_event_ring *in_ring;
24 : : struct rte_ring *ctl_in_ring;
25 : : char ring_name[RTE_RING_NAMESIZE];
26 : :
27 : 0 : port = &dsw->ports[port_id];
28 : :
29 : 0 : *port = (struct dsw_port) {
30 : : .id = port_id,
31 : : .dsw = dsw,
32 : 0 : .dequeue_depth = conf->dequeue_depth,
33 : 0 : .enqueue_depth = conf->enqueue_depth,
34 : 0 : .new_event_threshold = conf->new_event_threshold
35 : : };
36 : :
37 : 0 : snprintf(ring_name, sizeof(ring_name), "dsw%d_p%u", dev->data->dev_id,
38 : : port_id);
39 : :
40 : 0 : in_ring = rte_event_ring_create(ring_name, DSW_IN_RING_SIZE,
41 : 0 : dev->data->socket_id,
42 : : RING_F_SC_DEQ|RING_F_EXACT_SZ);
43 : :
44 [ # # ]: 0 : if (in_ring == NULL)
45 : : return -ENOMEM;
46 : :
47 : 0 : snprintf(ring_name, sizeof(ring_name), "dswctl%d_p%u",
48 : 0 : dev->data->dev_id, port_id);
49 : :
50 : 0 : ctl_in_ring = rte_ring_create_elem(ring_name,
51 : : sizeof(struct dsw_ctl_msg),
52 : : DSW_CTL_IN_RING_SIZE,
53 : 0 : dev->data->socket_id,
54 : : RING_F_SC_DEQ|RING_F_EXACT_SZ);
55 : :
56 [ # # ]: 0 : if (ctl_in_ring == NULL) {
57 : 0 : rte_event_ring_free(in_ring);
58 : 0 : return -ENOMEM;
59 : : }
60 : :
61 : 0 : port->in_ring = in_ring;
62 : 0 : port->ctl_in_ring = ctl_in_ring;
63 : :
64 : 0 : port->load_update_interval =
65 : 0 : (DSW_LOAD_UPDATE_INTERVAL * rte_get_timer_hz()) / US_PER_S;
66 : :
67 : 0 : port->migration_interval =
68 : 0 : (DSW_MIGRATION_INTERVAL * rte_get_timer_hz()) / US_PER_S;
69 : :
70 : 0 : dev->data->ports[port_id] = port;
71 : :
72 : 0 : return 0;
73 : : }
74 : :
75 : : static void
76 : 0 : dsw_port_def_conf(struct rte_eventdev *dev __rte_unused,
77 : : uint8_t port_id __rte_unused,
78 : : struct rte_event_port_conf *port_conf)
79 : : {
80 : 0 : *port_conf = (struct rte_event_port_conf) {
81 : : .new_event_threshold = 1024,
82 : : .dequeue_depth = DSW_MAX_PORT_DEQUEUE_DEPTH / 4,
83 : : .enqueue_depth = DSW_MAX_PORT_ENQUEUE_DEPTH / 4
84 : : };
85 : 0 : }
86 : :
87 : : static void
88 : 0 : dsw_port_release(void *p)
89 : : {
90 : : struct dsw_port *port = p;
91 : :
92 : 0 : rte_event_ring_free(port->in_ring);
93 : 0 : rte_ring_free(port->ctl_in_ring);
94 : 0 : }
95 : :
96 : : static int
97 [ # # ]: 0 : dsw_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
98 : : const struct rte_event_queue_conf *conf)
99 : : {
100 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
101 : 0 : struct dsw_queue *queue = &dsw->queues[queue_id];
102 : :
103 [ # # ]: 0 : if (RTE_EVENT_QUEUE_CFG_ALL_TYPES & conf->event_queue_cfg)
104 : : return -ENOTSUP;
105 : :
106 : : /* SINGLE_LINK is better off treated as TYPE_ATOMIC, since it
107 : : * avoid the "fake" TYPE_PARALLEL flow_id assignment. Since
108 : : * the queue will only have a single serving port, no
109 : : * migration will ever happen, so the extra TYPE_ATOMIC
110 : : * migration overhead is avoided.
111 : : */
112 [ # # ]: 0 : if (RTE_EVENT_QUEUE_CFG_SINGLE_LINK & conf->event_queue_cfg)
113 : 0 : queue->schedule_type = RTE_SCHED_TYPE_ATOMIC;
114 : : else {
115 [ # # ]: 0 : if (conf->schedule_type == RTE_SCHED_TYPE_ORDERED)
116 : : return -ENOTSUP;
117 : : /* atomic or parallel */
118 : 0 : queue->schedule_type = conf->schedule_type;
119 : : }
120 : :
121 : 0 : queue->num_serving_ports = 0;
122 : :
123 : 0 : return 0;
124 : : }
125 : :
126 : : static void
127 : 0 : dsw_queue_def_conf(struct rte_eventdev *dev __rte_unused,
128 : : uint8_t queue_id __rte_unused,
129 : : struct rte_event_queue_conf *queue_conf)
130 : : {
131 : 0 : *queue_conf = (struct rte_event_queue_conf) {
132 : : .nb_atomic_flows = 4096,
133 : : .schedule_type = RTE_SCHED_TYPE_ATOMIC,
134 : : .priority = RTE_EVENT_DEV_PRIORITY_NORMAL
135 : : };
136 : 0 : }
137 : :
138 : : static void
139 : 0 : dsw_queue_release(struct rte_eventdev *dev __rte_unused,
140 : : uint8_t queue_id __rte_unused)
141 : : {
142 : 0 : }
143 : :
144 : : static void
145 : : queue_add_port(struct dsw_queue *queue, uint16_t port_id)
146 : : {
147 : 0 : uint64_t port_mask = UINT64_C(1) << port_id;
148 : :
149 : 0 : queue->serving_ports |= port_mask;
150 : 0 : queue->num_serving_ports++;
151 : : }
152 : :
153 : : static bool
154 : : queue_remove_port(struct dsw_queue *queue, uint16_t port_id)
155 : : {
156 : 0 : uint64_t port_mask = UINT64_C(1) << port_id;
157 : :
158 : 0 : if (queue->serving_ports & port_mask) {
159 : 0 : queue->num_serving_ports--;
160 : 0 : queue->serving_ports ^= port_mask;
161 : : return true;
162 : : }
163 : :
164 : : return false;
165 : : }
166 : :
167 : : static int
168 : 0 : dsw_port_link_unlink(struct rte_eventdev *dev, void *port,
169 : : const uint8_t queues[], uint16_t num, bool link)
170 : : {
171 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
172 : : struct dsw_port *p = port;
173 : : uint16_t i;
174 : : uint16_t count = 0;
175 : :
176 [ # # ]: 0 : for (i = 0; i < num; i++) {
177 : 0 : uint8_t qid = queues[i];
178 : 0 : struct dsw_queue *q = &dsw->queues[qid];
179 [ # # ]: 0 : if (link) {
180 : 0 : queue_add_port(q, p->id);
181 : 0 : count++;
182 : : } else {
183 [ # # ]: 0 : bool removed = queue_remove_port(q, p->id);
184 : : if (removed)
185 : 0 : count++;
186 : : }
187 : : }
188 : :
189 : 0 : return count;
190 : : }
191 : :
192 : : static int
193 : 0 : dsw_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
194 : : const uint8_t priorities[] __rte_unused, uint16_t num)
195 : : {
196 : 0 : return dsw_port_link_unlink(dev, port, queues, num, true);
197 : : }
198 : :
199 : : static int
200 : 0 : dsw_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
201 : : uint16_t num)
202 : : {
203 : 0 : return dsw_port_link_unlink(dev, port, queues, num, false);
204 : : }
205 : :
206 : : static void
207 : 0 : dsw_info_get(struct rte_eventdev *dev __rte_unused,
208 : : struct rte_event_dev_info *info)
209 : : {
210 : 0 : *info = (struct rte_event_dev_info) {
211 : : .driver_name = DSW_PMD_NAME,
212 : : .max_event_queues = DSW_MAX_QUEUES,
213 : : .max_event_queue_flows = DSW_MAX_FLOWS,
214 : : .max_event_queue_priority_levels = 1,
215 : : .max_event_priority_levels = 1,
216 : : .max_event_ports = DSW_MAX_PORTS,
217 : : .max_event_port_dequeue_depth = DSW_MAX_PORT_DEQUEUE_DEPTH,
218 : : .max_event_port_enqueue_depth = DSW_MAX_PORT_ENQUEUE_DEPTH,
219 : : .max_num_events = DSW_MAX_EVENTS,
220 : : .max_profiles_per_port = 1,
221 : : .event_dev_cap = RTE_EVENT_DEV_CAP_BURST_MODE|
222 : : RTE_EVENT_DEV_CAP_ATOMIC |
223 : : RTE_EVENT_DEV_CAP_PARALLEL |
224 : : RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED|
225 : : RTE_EVENT_DEV_CAP_NONSEQ_MODE|
226 : : RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT|
227 : : RTE_EVENT_DEV_CAP_CARRY_FLOW_ID
228 : : };
229 : 0 : }
230 : :
231 : : static int
232 : 0 : dsw_configure(const struct rte_eventdev *dev)
233 : : {
234 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
235 : : const struct rte_event_dev_config *conf = &dev->data->dev_conf;
236 : : int32_t min_max_in_flight;
237 : :
238 : 0 : dsw->num_ports = conf->nb_event_ports;
239 : 0 : dsw->num_queues = conf->nb_event_queues;
240 : :
241 : : /* Avoid a situation where consumer ports are holding all the
242 : : * credits, without making use of them.
243 : : */
244 : 0 : min_max_in_flight = conf->nb_event_ports * DSW_PORT_MAX_CREDITS;
245 : :
246 : 0 : dsw->max_inflight = RTE_MAX(conf->nb_events_limit, min_max_in_flight);
247 : :
248 : 0 : return 0;
249 : : }
250 : :
251 : :
252 : : static void
253 : 0 : initial_flow_to_port_assignment(struct dsw_evdev *dsw)
254 : : {
255 : : uint8_t queue_id;
256 [ # # ]: 0 : for (queue_id = 0; queue_id < dsw->num_queues; queue_id++) {
257 : 0 : struct dsw_queue *queue = &dsw->queues[queue_id];
258 : : uint16_t flow_hash;
259 [ # # ]: 0 : for (flow_hash = 0; flow_hash < DSW_MAX_FLOWS; flow_hash++) {
260 : 0 : uint8_t skip =
261 : 0 : rte_rand_max(queue->num_serving_ports);
262 : : uint8_t port_id;
263 : :
264 : 0 : for (port_id = 0;; port_id++) {
265 : 0 : uint64_t port_mask = UINT64_C(1) << port_id;
266 : :
267 [ # # ]: 0 : if (queue->serving_ports & port_mask) {
268 [ # # ]: 0 : if (skip == 0)
269 : : break;
270 : 0 : skip--;
271 : : }
272 : : }
273 : :
274 : 0 : dsw->queues[queue_id].flow_to_port_map[flow_hash] =
275 : : port_id;
276 : : }
277 : : }
278 : 0 : }
279 : :
280 : : static int
281 : 0 : dsw_start(struct rte_eventdev *dev)
282 : : {
283 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
284 : : uint16_t i;
285 : : uint64_t now;
286 : :
287 : 0 : dsw->credits_on_loan = 0;
288 : :
289 : 0 : initial_flow_to_port_assignment(dsw);
290 : :
291 : : now = rte_get_timer_cycles();
292 [ # # ]: 0 : for (i = 0; i < dsw->num_ports; i++) {
293 : 0 : dsw->ports[i].measurement_start = now;
294 : 0 : dsw->ports[i].busy_start = now;
295 : : }
296 : :
297 : 0 : return 0;
298 : : }
299 : :
300 : : static void
301 : : dsw_port_drain_buf(uint8_t dev_id, struct rte_event *buf, uint16_t buf_len,
302 : : eventdev_stop_flush_t flush, void *flush_arg)
303 : : {
304 : : uint16_t i;
305 : :
306 [ # # # # ]: 0 : for (i = 0; i < buf_len; i++)
307 : 0 : flush(dev_id, buf[i], flush_arg);
308 : : }
309 : :
310 : : static void
311 : : dsw_port_drain_paused(uint8_t dev_id, struct dsw_port *port,
312 : : eventdev_stop_flush_t flush, void *flush_arg)
313 : : {
314 : 0 : dsw_port_drain_buf(dev_id, port->paused_events, port->paused_events_len,
315 : : flush, flush_arg);
316 : : }
317 : :
318 : : static void
319 : : dsw_port_drain_out(uint8_t dev_id, struct dsw_evdev *dsw, struct dsw_port *port,
320 : : eventdev_stop_flush_t flush, void *flush_arg)
321 : : {
322 : : uint16_t dport_id;
323 : :
324 [ # # ]: 0 : for (dport_id = 0; dport_id < dsw->num_ports; dport_id++)
325 [ # # ]: 0 : if (dport_id != port->id)
326 : 0 : dsw_port_drain_buf(dev_id, port->out_buffer[dport_id],
327 : 0 : port->out_buffer_len[dport_id],
328 : : flush, flush_arg);
329 : : }
330 : :
331 : : static void
332 : 0 : dsw_port_drain_in_ring(uint8_t dev_id, struct dsw_port *port,
333 : : eventdev_stop_flush_t flush, void *flush_arg)
334 : : {
335 : : struct rte_event ev;
336 : :
337 [ # # # # : 0 : while (rte_event_ring_dequeue_burst(port->in_ring, &ev, 1, NULL))
# # # ]
338 : 0 : flush(dev_id, ev, flush_arg);
339 : 0 : }
340 : :
341 : : static void
342 : 0 : dsw_drain(uint8_t dev_id, struct dsw_evdev *dsw,
343 : : eventdev_stop_flush_t flush, void *flush_arg)
344 : : {
345 : : uint16_t port_id;
346 : :
347 [ # # ]: 0 : if (flush == NULL)
348 : : return;
349 : :
350 [ # # ]: 0 : for (port_id = 0; port_id < dsw->num_ports; port_id++) {
351 : 0 : struct dsw_port *port = &dsw->ports[port_id];
352 : :
353 : 0 : dsw_port_drain_out(dev_id, dsw, port, flush, flush_arg);
354 : : dsw_port_drain_paused(dev_id, port, flush, flush_arg);
355 : 0 : dsw_port_drain_in_ring(dev_id, port, flush, flush_arg);
356 : : }
357 : : }
358 : :
359 : : static void
360 : 0 : dsw_stop(struct rte_eventdev *dev)
361 : : {
362 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
363 : : uint8_t dev_id;
364 : : eventdev_stop_flush_t flush;
365 : : void *flush_arg;
366 : :
367 : 0 : dev_id = dev->data->dev_id;
368 : 0 : flush = dev->dev_ops->dev_stop_flush;
369 : 0 : flush_arg = dev->data->dev_stop_flush_arg;
370 : :
371 : 0 : dsw_drain(dev_id, dsw, flush, flush_arg);
372 : 0 : }
373 : :
374 : : static int
375 : 0 : dsw_close(struct rte_eventdev *dev)
376 : : {
377 : : struct dsw_evdev *dsw = dsw_pmd_priv(dev);
378 : : uint16_t port_id;
379 : :
380 [ # # ]: 0 : for (port_id = 0; port_id < dsw->num_ports; port_id++)
381 : 0 : dsw_port_release(&dsw->ports[port_id]);
382 : :
383 : 0 : dsw->num_ports = 0;
384 : 0 : dsw->num_queues = 0;
385 : :
386 : 0 : return 0;
387 : : }
388 : :
389 : : static int
390 : 0 : dsw_eth_rx_adapter_caps_get(const struct rte_eventdev *dev __rte_unused,
391 : : const struct rte_eth_dev *eth_dev __rte_unused,
392 : : uint32_t *caps)
393 : : {
394 : 0 : *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
395 : 0 : return 0;
396 : : }
397 : :
398 : : static int
399 : 0 : dsw_timer_adapter_caps_get(const struct rte_eventdev *dev __rte_unused,
400 : : uint64_t flags __rte_unused, uint32_t *caps,
401 : : const struct event_timer_adapter_ops **ops)
402 : : {
403 : 0 : *caps = 0;
404 : 0 : *ops = NULL;
405 : 0 : return 0;
406 : : }
407 : :
408 : : static int
409 : 0 : dsw_crypto_adapter_caps_get(const struct rte_eventdev *dev __rte_unused,
410 : : const struct rte_cryptodev *cdev __rte_unused,
411 : : uint32_t *caps)
412 : : {
413 : 0 : *caps = RTE_EVENT_CRYPTO_ADAPTER_SW_CAP;
414 : 0 : return 0;
415 : : }
416 : :
417 : : static struct eventdev_ops dsw_evdev_ops = {
418 : : .port_setup = dsw_port_setup,
419 : : .port_def_conf = dsw_port_def_conf,
420 : : .port_release = dsw_port_release,
421 : : .queue_setup = dsw_queue_setup,
422 : : .queue_def_conf = dsw_queue_def_conf,
423 : : .queue_release = dsw_queue_release,
424 : : .port_link = dsw_port_link,
425 : : .port_unlink = dsw_port_unlink,
426 : : .dev_infos_get = dsw_info_get,
427 : : .dev_configure = dsw_configure,
428 : : .dev_start = dsw_start,
429 : : .dev_stop = dsw_stop,
430 : : .dev_close = dsw_close,
431 : : .eth_rx_adapter_caps_get = dsw_eth_rx_adapter_caps_get,
432 : : .timer_adapter_caps_get = dsw_timer_adapter_caps_get,
433 : : .crypto_adapter_caps_get = dsw_crypto_adapter_caps_get,
434 : : .xstats_get = dsw_xstats_get,
435 : : .xstats_get_names = dsw_xstats_get_names,
436 : : .xstats_get_by_name = dsw_xstats_get_by_name
437 : : };
438 : :
439 : : static int
440 [ # # ]: 0 : dsw_probe(struct rte_vdev_device *vdev)
441 : : {
442 : : const char *name;
443 : : struct rte_eventdev *dev;
444 : : struct dsw_evdev *dsw;
445 : :
446 : : name = rte_vdev_device_name(vdev);
447 : :
448 : 0 : dev = rte_event_pmd_vdev_init(name, sizeof(struct dsw_evdev),
449 : 0 : rte_socket_id(), vdev);
450 [ # # ]: 0 : if (dev == NULL)
451 : : return -EFAULT;
452 : :
453 : 0 : dev->dev_ops = &dsw_evdev_ops;
454 : 0 : dev->enqueue = dsw_event_enqueue;
455 : 0 : dev->enqueue_burst = dsw_event_enqueue_burst;
456 : 0 : dev->enqueue_new_burst = dsw_event_enqueue_new_burst;
457 : 0 : dev->enqueue_forward_burst = dsw_event_enqueue_forward_burst;
458 : 0 : dev->dequeue = dsw_event_dequeue;
459 : 0 : dev->dequeue_burst = dsw_event_dequeue_burst;
460 : 0 : dev->maintain = dsw_event_maintain;
461 : :
462 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
463 : : return 0;
464 : :
465 : 0 : dsw = dev->data->dev_private;
466 : 0 : dsw->data = dev->data;
467 : :
468 : 0 : event_dev_probing_finish(dev);
469 : 0 : return 0;
470 : : }
471 : :
472 : : static int
473 [ # # ]: 0 : dsw_remove(struct rte_vdev_device *vdev)
474 : : {
475 : : const char *name;
476 : :
477 : : name = rte_vdev_device_name(vdev);
478 : : if (name == NULL)
479 : : return -EINVAL;
480 : :
481 : 0 : return rte_event_pmd_vdev_uninit(name);
482 : : }
483 : :
484 : : static struct rte_vdev_driver evdev_dsw_pmd_drv = {
485 : : .probe = dsw_probe,
486 : : .remove = dsw_remove
487 : : };
488 : :
489 : 238 : RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_DSW_PMD, evdev_dsw_pmd_drv);
|