New upstream version 18.02
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_be.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4
5 #include <rte_common.h>
6 #include <rte_malloc.h>
7
8 #include "pipeline_common_be.h"
9
10 void *
11 pipeline_msg_req_ping_handler(__rte_unused struct pipeline *p,
12         void *msg)
13 {
14         struct pipeline_msg_rsp *rsp = msg;
15
16         rsp->status = 0; /* OK */
17
18         return rsp;
19 }
20
21 void *
22 pipeline_msg_req_stats_port_in_handler(struct pipeline *p,
23         void *msg)
24 {
25         struct pipeline_stats_msg_req *req = msg;
26         struct pipeline_stats_port_in_msg_rsp *rsp = msg;
27         uint32_t port_id;
28
29         /* Check request */
30         if (req->id >= p->n_ports_in) {
31                 rsp->status = -1;
32                 return rsp;
33         }
34         port_id = p->port_in_id[req->id];
35
36         /* Process request */
37         rsp->status = rte_pipeline_port_in_stats_read(p->p,
38                 port_id,
39                 &rsp->stats,
40                 1);
41
42         return rsp;
43 }
44
45 void *
46 pipeline_msg_req_stats_port_out_handler(struct pipeline *p,
47         void *msg)
48 {
49         struct pipeline_stats_msg_req *req = msg;
50         struct pipeline_stats_port_out_msg_rsp *rsp = msg;
51         uint32_t port_id;
52
53         /* Check request */
54         if (req->id >= p->n_ports_out) {
55                 rsp->status = -1;
56                 return rsp;
57         }
58         port_id = p->port_out_id[req->id];
59
60         /* Process request */
61         rsp->status = rte_pipeline_port_out_stats_read(p->p,
62                 port_id,
63                 &rsp->stats,
64                 1);
65
66         return rsp;
67 }
68
69 void *
70 pipeline_msg_req_stats_table_handler(struct pipeline *p,
71         void *msg)
72 {
73         struct pipeline_stats_msg_req *req = msg;
74         struct pipeline_stats_table_msg_rsp *rsp = msg;
75         uint32_t table_id;
76
77         /* Check request */
78         if (req->id >= p->n_tables) {
79                 rsp->status = -1;
80                 return rsp;
81         }
82         table_id = p->table_id[req->id];
83
84         /* Process request */
85         rsp->status = rte_pipeline_table_stats_read(p->p,
86                 table_id,
87                 &rsp->stats,
88                 1);
89
90         return rsp;
91 }
92
93 void *
94 pipeline_msg_req_port_in_enable_handler(struct pipeline *p,
95         void *msg)
96 {
97         struct pipeline_port_in_msg_req *req = msg;
98         struct pipeline_msg_rsp *rsp = msg;
99         uint32_t port_id;
100
101         /* Check request */
102         if (req->port_id >= p->n_ports_in) {
103                 rsp->status = -1;
104                 return rsp;
105         }
106         port_id = p->port_in_id[req->port_id];
107
108         /* Process request */
109         rsp->status = rte_pipeline_port_in_enable(p->p,
110                 port_id);
111
112         return rsp;
113 }
114
115 void *
116 pipeline_msg_req_port_in_disable_handler(struct pipeline *p,
117         void *msg)
118 {
119         struct pipeline_port_in_msg_req *req = msg;
120         struct pipeline_msg_rsp *rsp = msg;
121         uint32_t port_id;
122
123         /* Check request */
124         if (req->port_id >= p->n_ports_in) {
125                 rsp->status = -1;
126                 return rsp;
127         }
128         port_id = p->port_in_id[req->port_id];
129
130         /* Process request */
131         rsp->status = rte_pipeline_port_in_disable(p->p,
132                 port_id);
133
134         return rsp;
135 }
136
137 void *
138 pipeline_msg_req_invalid_handler(__rte_unused struct pipeline *p,
139         void *msg)
140 {
141         struct pipeline_msg_rsp *rsp = msg;
142
143         rsp->status = -1; /* Error */
144
145         return rsp;
146 }
147
148 int
149 pipeline_msg_req_handle(struct pipeline *p)
150 {
151         uint32_t msgq_id;
152
153         for (msgq_id = 0; msgq_id < p->n_msgq; msgq_id++) {
154                 for ( ; ; ) {
155                         struct pipeline_msg_req *req;
156                         pipeline_msg_req_handler f_handle;
157
158                         req = pipeline_msg_recv(p, msgq_id);
159                         if (req == NULL)
160                                 break;
161
162                         f_handle = (req->type < PIPELINE_MSG_REQS) ?
163                                 p->handlers[req->type] :
164                                 pipeline_msg_req_invalid_handler;
165
166                         if (f_handle == NULL)
167                                 f_handle = pipeline_msg_req_invalid_handler;
168
169                         pipeline_msg_send(p,
170                                 msgq_id,
171                                 f_handle(p, (void *) req));
172                 }
173         }
174
175         return 0;
176 }