examples/ip_pipeline: add TAP port example
[dpdk.git] / examples / ip_pipeline / swq.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "swq.h"
9
10 static struct swq_list swq_list;
11
12 int
13 swq_init(void)
14 {
15         TAILQ_INIT(&swq_list);
16
17         return 0;
18 }
19
20 struct swq *
21 swq_find(const char *name)
22 {
23         struct swq *swq;
24
25         if (name == NULL)
26                 return NULL;
27
28         TAILQ_FOREACH(swq, &swq_list, node)
29                 if (strcmp(swq->name, name) == 0)
30                         return swq;
31
32         return NULL;
33 }
34
35 struct swq *
36 swq_create(const char *name, struct swq_params *params)
37 {
38         struct swq *swq;
39         struct rte_ring *r;
40         unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
41
42         /* Check input params */
43         if ((name == NULL) ||
44                 swq_find(name) ||
45                 (params == NULL) ||
46                 (params->size == 0))
47                 return NULL;
48
49         /* Resource create */
50         r = rte_ring_create(
51                 name,
52                 params->size,
53                 params->cpu_id,
54                 flags);
55
56         if (r == NULL)
57                 return NULL;
58
59         /* Node allocation */
60         swq = calloc(1, sizeof(struct swq));
61         if (swq == NULL) {
62                 rte_ring_free(r);
63                 return NULL;
64         }
65
66         /* Node fill in */
67         strncpy(swq->name, name, sizeof(swq->name));
68         swq->r = r;
69
70         /* Node add to list */
71         TAILQ_INSERT_TAIL(&swq_list, swq, node);
72
73         return swq;
74 }