Merge "Temp Fix for vFW perf issue"
[samplevnf.git] / common / VIL / pipeline_common / pipeline_common_be.c
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <rte_common.h>
18 #include <rte_ring.h>
19 #include <rte_malloc.h>
20
21 #include "pipeline_common_be.h"
22
23 void *
24 pipeline_msg_req_ping_handler(__rte_unused struct pipeline *p,
25         void *msg)
26 {
27         struct pipeline_msg_rsp *rsp = msg;
28
29         rsp->status = 0; /* OK */
30
31         return rsp;
32 }
33
34 void *
35 pipeline_msg_req_stats_port_in_handler(struct pipeline *p,
36         void *msg)
37 {
38         struct pipeline_stats_msg_req *req = msg;
39         struct pipeline_stats_port_in_msg_rsp *rsp = msg;
40         uint32_t port_id;
41
42         /* Check request */
43         if (req->id >= p->n_ports_in) {
44                 rsp->status = -1;
45                 return rsp;
46         }
47         port_id = p->port_in_id[req->id];
48
49         /* Process request */
50         rsp->status = rte_pipeline_port_in_stats_read(p->p,
51                 port_id,
52                 &rsp->stats,
53                 1);
54
55         return rsp;
56 }
57
58 void *
59 pipeline_msg_req_stats_port_out_handler(struct pipeline *p,
60         void *msg)
61 {
62         struct pipeline_stats_msg_req *req = msg;
63         struct pipeline_stats_port_out_msg_rsp *rsp = msg;
64         uint32_t port_id;
65
66         /* Check request */
67         if (req->id >= p->n_ports_out) {
68                 rsp->status = -1;
69                 return rsp;
70         }
71         port_id = p->port_out_id[req->id];
72
73         /* Process request */
74         rsp->status = rte_pipeline_port_out_stats_read(p->p,
75                 port_id,
76                 &rsp->stats,
77                 1);
78
79         return rsp;
80 }
81
82 void *
83 pipeline_msg_req_stats_table_handler(struct pipeline *p,
84         void *msg)
85 {
86         struct pipeline_stats_msg_req *req = msg;
87         struct pipeline_stats_table_msg_rsp *rsp = msg;
88         uint32_t table_id;
89
90         /* Check request */
91         if (req->id >= p->n_tables) {
92                 rsp->status = -1;
93                 return rsp;
94         }
95         table_id = p->table_id[req->id];
96
97         /* Process request */
98         rsp->status = rte_pipeline_table_stats_read(p->p,
99                 table_id,
100                 &rsp->stats,
101                 1);
102
103         return rsp;
104 }
105
106 void *
107 pipeline_msg_req_port_in_enable_handler(struct pipeline *p,
108         void *msg)
109 {
110         struct pipeline_port_in_msg_req *req = msg;
111         struct pipeline_msg_rsp *rsp = msg;
112         uint32_t port_id;
113
114         /* Check request */
115         if (req->port_id >= p->n_ports_in) {
116                 rsp->status = -1;
117                 return rsp;
118         }
119         port_id = p->port_in_id[req->port_id];
120
121         /* Process request */
122         rsp->status = rte_pipeline_port_in_enable(p->p,
123                 port_id);
124
125         return rsp;
126 }
127
128 void *
129 pipeline_msg_req_port_in_disable_handler(struct pipeline *p,
130         void *msg)
131 {
132         struct pipeline_port_in_msg_req *req = msg;
133         struct pipeline_msg_rsp *rsp = msg;
134         uint32_t port_id;
135
136         /* Check request */
137         if (req->port_id >= p->n_ports_in) {
138                 rsp->status = -1;
139                 return rsp;
140         }
141         port_id = p->port_in_id[req->port_id];
142
143         /* Process request */
144         rsp->status = rte_pipeline_port_in_disable(p->p,
145                 port_id);
146
147         return rsp;
148 }
149
150 void *
151 pipeline_msg_req_invalid_handler(__rte_unused struct pipeline *p,
152         void *msg)
153 {
154         struct pipeline_msg_rsp *rsp = msg;
155
156         rsp->status = -1; /* Error */
157
158         return rsp;
159 }
160
161 int
162 pipeline_msg_req_handle(struct pipeline *p)
163 {
164         uint32_t msgq_id;
165
166         for (msgq_id = 0; msgq_id < p->n_msgq; msgq_id++) {
167                 for ( ; ; ) {
168                         struct pipeline_msg_req *req;
169                         pipeline_msg_req_handler f_handle;
170
171                         req = pipeline_msg_recv(p, msgq_id);
172                         if (req == NULL)
173                                 break;
174
175                         f_handle = (req->type < PIPELINE_MSG_REQS) ?
176                                 p->handlers[req->type] :
177                                 pipeline_msg_req_invalid_handler;
178
179                         if (f_handle == NULL)
180                                 f_handle = pipeline_msg_req_invalid_handler;
181
182                         pipeline_msg_send(p,
183                                 msgq_id,
184                                 f_handle(p, (void *) req));
185                 }
186         }
187
188         return 0;
189 }