summaryrefslogtreecommitdiffstats
path: root/drivers/net/softnic/rte_eth_softnic_swq.c
blob: 2083d0a976a6ce822a4641d7c9c0e29d8cd694ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#include <stdlib.h>
#include <string.h>

#include <rte_string_fns.h>
#include <rte_tailq.h>

#include "rte_eth_softnic_internals.h"

int
softnic_swq_init(struct pmd_internals *p)
{
	TAILQ_INIT(&p->swq_list);

	return 0;
}

void
softnic_swq_free(struct pmd_internals *p)
{
	for ( ; ; ) {
		struct softnic_swq *swq;

		swq = TAILQ_FIRST(&p->swq_list);
		if (swq == NULL)
			break;

		TAILQ_REMOVE(&p->swq_list, swq, node);
		rte_ring_free(swq->r);
		free(swq);
	}
}

void
softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p)
{
	struct softnic_swq *swq, *tswq;

	TAILQ_FOREACH_SAFE(swq, &p->swq_list, node, tswq) {
		if ((strncmp(swq->name, "RXQ", strlen("RXQ")) == 0) ||
			(strncmp(swq->name, "TXQ", strlen("TXQ")) == 0))
			continue;

		TAILQ_REMOVE(&p->swq_list, swq, node);
		rte_ring_free(swq->r);
		free(swq);
	}
}

struct softnic_swq *
softnic_swq_find(struct pmd_internals *p,
	const char *name)
{
	struct softnic_swq *swq;

	if (name == NULL)
		return NULL;

	TAILQ_FOREACH(swq, &p->swq_list, node)
		if (strcmp(swq->name, name) == 0)
			return swq;

	return NULL;
}

struct softnic_swq *
softnic_swq_create(struct pmd_internals *p,
	const char *name,
	struct softnic_swq_params *params)
{
	char ring_name[NAME_SIZE];
	struct softnic_swq *swq;
	struct rte_ring *r;
	unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;

	/* Check input params */
	if (name == NULL ||
		softnic_swq_find(p, name) ||
		params == NULL ||
		params->size == 0)
		return NULL;

	/* Resource create */
	snprintf(ring_name, sizeof(ring_name), "%s_%s",
		p->params.name,
		name);

	r = rte_ring_create(ring_name,
		params->size,
		p->params.cpu_id,
		flags);

	if (r == NULL)
		return NULL;

	/* Node allocation */
	swq = calloc(1, sizeof(struct softnic_swq));
	if (swq == NULL) {
		rte_ring_free(r);
		return NULL;
	}

	/* Node fill in */
	strlcpy(swq->name, name, sizeof(swq->name));
	swq->r = r;

	/* Node add to list */
	TAILQ_INSERT_TAIL(&p->swq_list, swq, node);

	return swq;
}