Branch data Line data Source code
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 <rte_string_fns.h>
9 : : #include <rte_tailq.h>
10 : :
11 : : #include "rte_eth_softnic_internals.h"
12 : :
13 : : int
14 : 0 : softnic_swq_init(struct pmd_internals *p)
15 : : {
16 : 0 : TAILQ_INIT(&p->swq_list);
17 : :
18 : 0 : return 0;
19 : : }
20 : :
21 : : void
22 : 0 : softnic_swq_free(struct pmd_internals *p)
23 : : {
24 : 0 : for ( ; ; ) {
25 : : struct softnic_swq *swq;
26 : :
27 : 0 : swq = TAILQ_FIRST(&p->swq_list);
28 [ # # ]: 0 : if (swq == NULL)
29 : : break;
30 : :
31 [ # # ]: 0 : TAILQ_REMOVE(&p->swq_list, swq, node);
32 : 0 : rte_ring_free(swq->r);
33 : 0 : free(swq);
34 : : }
35 : 0 : }
36 : :
37 : : void
38 : 0 : softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p)
39 : : {
40 : : struct softnic_swq *swq, *tswq;
41 : :
42 [ # # ]: 0 : RTE_TAILQ_FOREACH_SAFE(swq, &p->swq_list, node, tswq) {
43 [ # # ]: 0 : if ((strncmp(swq->name, "RXQ", strlen("RXQ")) == 0) ||
44 [ # # ]: 0 : (strncmp(swq->name, "TXQ", strlen("TXQ")) == 0))
45 : 0 : continue;
46 : :
47 [ # # ]: 0 : TAILQ_REMOVE(&p->swq_list, swq, node);
48 : 0 : rte_ring_free(swq->r);
49 : 0 : free(swq);
50 : : }
51 : 0 : }
52 : :
53 : : struct softnic_swq *
54 : 0 : softnic_swq_find(struct pmd_internals *p,
55 : : const char *name)
56 : : {
57 : : struct softnic_swq *swq;
58 : :
59 [ # # ]: 0 : if (name == NULL)
60 : : return NULL;
61 : :
62 [ # # ]: 0 : TAILQ_FOREACH(swq, &p->swq_list, node)
63 [ # # ]: 0 : if (strcmp(swq->name, name) == 0)
64 : 0 : return swq;
65 : :
66 : : return NULL;
67 : : }
68 : :
69 : : struct softnic_swq *
70 : 0 : softnic_swq_create(struct pmd_internals *p,
71 : : const char *name,
72 : : struct softnic_swq_params *params)
73 : : {
74 : : char ring_name[NAME_SIZE];
75 : : struct softnic_swq *swq;
76 : : struct rte_ring *r;
77 : : unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
78 : :
79 : : /* Check input params */
80 [ # # # # ]: 0 : if (name == NULL ||
81 [ # # ]: 0 : softnic_swq_find(p, name) ||
82 : 0 : params == NULL ||
83 [ # # ]: 0 : params->size == 0)
84 : 0 : return NULL;
85 : :
86 : : /* Resource create */
87 : : snprintf(ring_name, sizeof(ring_name), "%s_%s",
88 : 0 : p->params.name,
89 : : name);
90 : :
91 : 0 : r = rte_ring_create(ring_name,
92 : : params->size,
93 : 0 : p->params.cpu_id,
94 : : flags);
95 : :
96 [ # # ]: 0 : if (r == NULL)
97 : : return NULL;
98 : :
99 : : /* Node allocation */
100 : 0 : swq = calloc(1, sizeof(struct softnic_swq));
101 [ # # ]: 0 : if (swq == NULL) {
102 : 0 : rte_ring_free(r);
103 : 0 : return NULL;
104 : : }
105 : :
106 : : /* Node fill in */
107 : 0 : strlcpy(swq->name, name, sizeof(swq->name));
108 : 0 : swq->r = r;
109 : :
110 : : /* Node add to list */
111 : 0 : TAILQ_INSERT_TAIL(&p->swq_list, swq, node);
112 : :
113 : 0 : return swq;
114 : : }
|