aboutsummaryrefslogtreecommitdiffstats
path: root/examples/ip_pipeline/pipeline/pipeline_common_be.c
blob: 5d84989a14fdbb65cd29b0b0423a7c1fce294f75 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2015 Intel Corporation
 */

#include <rte_common.h>
#include <rte_malloc.h>

#include "pipeline_common_be.h"

void *
pipeline_msg_req_ping_handler(__rte_unused struct pipeline *p,
	void *msg)
{
	struct pipeline_msg_rsp *rsp = msg;

	rsp->status = 0; /* OK */

	return rsp;
}

void *
pipeline_msg_req_stats_port_in_handler(struct pipeline *p,
	void *msg)
{
	struct pipeline_stats_msg_req *req = msg;
	struct pipeline_stats_port_in_msg_rsp *rsp = msg;
	uint32_t port_id;

	/* Check request */
	if (req->id >= p->n_ports_in) {
		rsp->status = -1;
		return rsp;
	}
	port_id = p->port_in_id[req->id];

	/* Process request */
	rsp->status = rte_pipeline_port_in_stats_read(p->p,
		port_id,
		&rsp->stats,
		1);

	return rsp;
}

void *
pipeline_msg_req_stats_port_out_handler(struct pipeline *p,
	void *msg)
{
	struct pipeline_stats_msg_req *req = msg;
	struct pipeline_stats_port_out_msg_rsp *rsp = msg;
	uint32_t port_id;

	/* Check request */
	if (req->id >= p->n_ports_out) {
		rsp->status = -1;
		return rsp;
	}
	port_id = p->port_out_id[req->id];

	/* Process request */
	rsp->status = rte_pipeline_port_out_stats_read(p->p,
		port_id,
		&rsp->stats,
		1);

	return rsp;
}

void *
pipeline_msg_req_stats_table_handler(struct pipeline *p,
	void *msg)
{
	struct pipeline_stats_msg_req *req = msg;
	struct pipeline_stats_table_msg_rsp *rsp = msg;
	uint32_t table_id;

	/* Check request */
	if (req->id >= p->n_tables) {
		rsp->status = -1;
		return rsp;
	}
	table_id = p->table_id[req->id];

	/* Process request */
	rsp->status = rte_pipeline_table_stats_read(p->p,
		table_id,
		&rsp->stats,
		1);

	return rsp;
}

void *
pipeline_msg_req_port_in_enable_handler(struct pipeline *p,
	void *msg)
{
	struct pipeline_port_in_msg_req *req = msg;
	struct pipeline_msg_rsp *rsp = msg;
	uint32_t port_id;

	/* Check request */
	if (req->port_id >= p->n_ports_in) {
		rsp->status = -1;
		return rsp;
	}
	port_id = p->port_in_id[req->port_id];

	/* Process request */
	rsp->status = rte_pipeline_port_in_enable(p->p,
		port_id);

	return rsp;
}

void *
pipeline_msg_req_port_in_disable_handler(struct pipeline *p,
	void *msg)
{
	struct pipeline_port_in_msg_req *req = msg;
	struct pipeline_msg_rsp *rsp = msg;
	uint32_t port_id;

	/* Check request */
	if (req->port_id >= p->n_ports_in) {
		rsp->status = -1;
		return rsp;
	}
	port_id = p->port_in_id[req->port_id];

	/* Process request */
	rsp->status = rte_pipeline_port_in_disable(p->p,
		port_id);

	return rsp;
}

void *
pipeline_msg_req_invalid_handler(__rte_unused struct pipeline *p,
	void *msg)
{
	struct pipeline_msg_rsp *rsp = msg;

	rsp->status = -1; /* Error */

	return rsp;
}

int
pipeline_msg_req_handle(struct pipeline *p)
{
	uint32_t msgq_id;

	for (msgq_id = 0; msgq_id < p->n_msgq; msgq_id++) {
		for ( ; ; ) {
			struct pipeline_msg_req *req;
			pipeline_msg_req_handler f_handle;

			req = pipeline_msg_recv(p, msgq_id);
			if (req == NULL)
				break;

			f_handle = (req->type < PIPELINE_MSG_REQS) ?
				p->handlers[req->type] :
				pipeline_msg_req_invalid_handler;

			if (f_handle == NULL)
				f_handle = pipeline_msg_req_invalid_handler;

			pipeline_msg_send(p,
				msgq_id,
				f_handle(p, (void *) req));
		}
	}

	return 0;
}