aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/softnic/rte_eth_softnic_link.c
blob: d669913a4d5a53173fd37d586d4675fae2472727 (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

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

#include <rte_ethdev.h>
#include <rte_string_fns.h>

#include "rte_eth_softnic_internals.h"

int
softnic_link_init(struct pmd_internals *p)
{
	TAILQ_INIT(&p->link_list);

	return 0;
}

void
softnic_link_free(struct pmd_internals *p)
{
	for ( ; ; ) {
		struct softnic_link *link;

		link = TAILQ_FIRST(&p->link_list);
		if (link == NULL)
			break;

		TAILQ_REMOVE(&p->link_list, link, node);
		free(link);
	}
}

struct softnic_link *
softnic_link_find(struct pmd_internals *p,
	const char *name)
{
	struct softnic_link *link;

	if (name == NULL)
		return NULL;

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

	return NULL;
}

struct softnic_link *
softnic_link_create(struct pmd_internals *p,
	const char *name,
	struct softnic_link_params *params)
{
	struct rte_eth_dev_info port_info;
	struct softnic_link *link;
	uint16_t port_id;

	/* Check input params */
	if (name == NULL ||
		softnic_link_find(p, name) ||
		params == NULL)
		return NULL;

	port_id = params->port_id;
	if (params->dev_name) {
		int status;

		status = rte_eth_dev_get_port_by_name(params->dev_name,
			&port_id);

		if (status)
			return NULL;
	} else {
		if (!rte_eth_dev_is_valid_port(port_id))
			return NULL;
	}

	rte_eth_dev_info_get(port_id, &port_info);

	/* Node allocation */
	link = calloc(1, sizeof(struct softnic_link));
	if (link == NULL)
		return NULL;

	/* Node fill in */
	strlcpy(link->name, name, sizeof(link->name));
	link->port_id = port_id;
	link->n_rxq = port_info.nb_rx_queues;
	link->n_txq = port_info.nb_tx_queues;

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

	return link;
}