Imported Upstream version 16.11
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_be.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <rte_common.h>
35 #include <rte_malloc.h>
36
37 #include "pipeline_common_be.h"
38
39 void *
40 pipeline_msg_req_ping_handler(__rte_unused struct pipeline *p,
41         void *msg)
42 {
43         struct pipeline_msg_rsp *rsp = msg;
44
45         rsp->status = 0; /* OK */
46
47         return rsp;
48 }
49
50 void *
51 pipeline_msg_req_stats_port_in_handler(struct pipeline *p,
52         void *msg)
53 {
54         struct pipeline_stats_msg_req *req = msg;
55         struct pipeline_stats_port_in_msg_rsp *rsp = msg;
56         uint32_t port_id;
57
58         /* Check request */
59         if (req->id >= p->n_ports_in) {
60                 rsp->status = -1;
61                 return rsp;
62         }
63         port_id = p->port_in_id[req->id];
64
65         /* Process request */
66         rsp->status = rte_pipeline_port_in_stats_read(p->p,
67                 port_id,
68                 &rsp->stats,
69                 1);
70
71         return rsp;
72 }
73
74 void *
75 pipeline_msg_req_stats_port_out_handler(struct pipeline *p,
76         void *msg)
77 {
78         struct pipeline_stats_msg_req *req = msg;
79         struct pipeline_stats_port_out_msg_rsp *rsp = msg;
80         uint32_t port_id;
81
82         /* Check request */
83         if (req->id >= p->n_ports_out) {
84                 rsp->status = -1;
85                 return rsp;
86         }
87         port_id = p->port_out_id[req->id];
88
89         /* Process request */
90         rsp->status = rte_pipeline_port_out_stats_read(p->p,
91                 port_id,
92                 &rsp->stats,
93                 1);
94
95         return rsp;
96 }
97
98 void *
99 pipeline_msg_req_stats_table_handler(struct pipeline *p,
100         void *msg)
101 {
102         struct pipeline_stats_msg_req *req = msg;
103         struct pipeline_stats_table_msg_rsp *rsp = msg;
104         uint32_t table_id;
105
106         /* Check request */
107         if (req->id >= p->n_tables) {
108                 rsp->status = -1;
109                 return rsp;
110         }
111         table_id = p->table_id[req->id];
112
113         /* Process request */
114         rsp->status = rte_pipeline_table_stats_read(p->p,
115                 table_id,
116                 &rsp->stats,
117                 1);
118
119         return rsp;
120 }
121
122 void *
123 pipeline_msg_req_port_in_enable_handler(struct pipeline *p,
124         void *msg)
125 {
126         struct pipeline_port_in_msg_req *req = msg;
127         struct pipeline_msg_rsp *rsp = msg;
128         uint32_t port_id;
129
130         /* Check request */
131         if (req->port_id >= p->n_ports_in) {
132                 rsp->status = -1;
133                 return rsp;
134         }
135         port_id = p->port_in_id[req->port_id];
136
137         /* Process request */
138         rsp->status = rte_pipeline_port_in_enable(p->p,
139                 port_id);
140
141         return rsp;
142 }
143
144 void *
145 pipeline_msg_req_port_in_disable_handler(struct pipeline *p,
146         void *msg)
147 {
148         struct pipeline_port_in_msg_req *req = msg;
149         struct pipeline_msg_rsp *rsp = msg;
150         uint32_t port_id;
151
152         /* Check request */
153         if (req->port_id >= p->n_ports_in) {
154                 rsp->status = -1;
155                 return rsp;
156         }
157         port_id = p->port_in_id[req->port_id];
158
159         /* Process request */
160         rsp->status = rte_pipeline_port_in_disable(p->p,
161                 port_id);
162
163         return rsp;
164 }
165
166 void *
167 pipeline_msg_req_invalid_handler(__rte_unused struct pipeline *p,
168         void *msg)
169 {
170         struct pipeline_msg_rsp *rsp = msg;
171
172         rsp->status = -1; /* Error */
173
174         return rsp;
175 }
176
177 int
178 pipeline_msg_req_handle(struct pipeline *p)
179 {
180         uint32_t msgq_id;
181
182         for (msgq_id = 0; msgq_id < p->n_msgq; msgq_id++) {
183                 for ( ; ; ) {
184                         struct pipeline_msg_req *req;
185                         pipeline_msg_req_handler f_handle;
186
187                         req = pipeline_msg_recv(p, msgq_id);
188                         if (req == NULL)
189                                 break;
190
191                         f_handle = (req->type < PIPELINE_MSG_REQS) ?
192                                 p->handlers[req->type] :
193                                 pipeline_msg_req_invalid_handler;
194
195                         if (f_handle == NULL)
196                                 f_handle = pipeline_msg_req_invalid_handler;
197
198                         pipeline_msg_send(p,
199                                 msgq_id,
200                                 f_handle(p, (void *) req));
201                 }
202         }
203
204         return 0;
205 }