examples/ip_pipeline: add master pipeline
[dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_fe.h
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 #ifndef __INCLUDE_PIPELINE_COMMON_FE_H__
35 #define __INCLUDE_PIPELINE_COMMON_FE_H__
36
37 #include <rte_common.h>
38 #include <rte_cycles.h>
39 #include <rte_malloc.h>
40 #include <cmdline_parse.h>
41
42 #include "pipeline_common_be.h"
43 #include "pipeline.h"
44 #include "app.h"
45
46 #ifndef MSG_TIMEOUT_DEFAULT
47 #define MSG_TIMEOUT_DEFAULT                      1000
48 #endif
49
50 static inline struct app_pipeline_data *
51 app_pipeline_data(struct app_params *app, uint32_t id)
52 {
53         struct app_pipeline_params *params;
54
55         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", id, params);
56         if (params == NULL)
57                 return NULL;
58
59         return &app->pipeline_data[params - app->pipeline_params];
60 }
61
62 static inline void *
63 app_pipeline_data_fe(struct app_params *app, uint32_t id)
64 {
65         struct app_pipeline_data *pipeline_data;
66
67         pipeline_data = app_pipeline_data(app, id);
68         if (pipeline_data == NULL)
69                 return NULL;
70
71         return pipeline_data->fe;
72 }
73
74 static inline struct rte_ring *
75 app_pipeline_msgq_in_get(struct app_params *app,
76         uint32_t pipeline_id)
77 {
78         struct app_msgq_params *p;
79
80         APP_PARAM_FIND_BY_ID(app->msgq_params,
81                 "MSGQ-REQ-PIPELINE",
82                 pipeline_id,
83                 p);
84         if (p == NULL)
85                 return NULL;
86
87         return app->msgq[p - app->msgq_params];
88 }
89
90 static inline struct rte_ring *
91 app_pipeline_msgq_out_get(struct app_params *app,
92         uint32_t pipeline_id)
93 {
94         struct app_msgq_params *p;
95
96         APP_PARAM_FIND_BY_ID(app->msgq_params,
97                 "MSGQ-RSP-PIPELINE",
98                 pipeline_id,
99                 p);
100         if (p == NULL)
101                 return NULL;
102
103         return app->msgq[p - app->msgq_params];
104 }
105
106 static inline void *
107 app_msg_alloc(__rte_unused struct app_params *app)
108 {
109         return rte_malloc(NULL, 2048, RTE_CACHE_LINE_SIZE);
110 }
111
112 static inline void
113 app_msg_free(__rte_unused struct app_params *app,
114         void *msg)
115 {
116         rte_free(msg);
117 }
118
119 static inline void
120 app_msg_send(struct app_params *app,
121         uint32_t pipeline_id,
122         void *msg)
123 {
124         struct rte_ring *r = app_pipeline_msgq_in_get(app, pipeline_id);
125         int status;
126
127         do {
128                 status = rte_ring_sp_enqueue(r, msg);
129         } while (status == -ENOBUFS);
130 }
131
132 static inline void *
133 app_msg_recv(struct app_params *app,
134         uint32_t pipeline_id)
135 {
136         struct rte_ring *r = app_pipeline_msgq_out_get(app, pipeline_id);
137         void *msg;
138         int status = rte_ring_sc_dequeue(r, &msg);
139
140         if (status != 0)
141                 return NULL;
142
143         return msg;
144 }
145
146 static inline void *
147 app_msg_send_recv(struct app_params *app,
148         uint32_t pipeline_id,
149         void *msg,
150         uint32_t timeout_ms)
151 {
152         struct rte_ring *r_req = app_pipeline_msgq_in_get(app, pipeline_id);
153         struct rte_ring *r_rsp = app_pipeline_msgq_out_get(app, pipeline_id);
154         uint64_t hz = rte_get_tsc_hz();
155         void *msg_recv;
156         uint64_t deadline;
157         int status;
158
159         /* send */
160         do {
161                 status = rte_ring_sp_enqueue(r_req, (void *) msg);
162         } while (status == -ENOBUFS);
163
164         /* recv */
165         deadline = (timeout_ms) ?
166                 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
167                 UINT64_MAX;
168
169         do {
170                 if (rte_rdtsc() > deadline)
171                         return NULL;
172
173                 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
174         } while (status != 0);
175
176         return msg_recv;
177 }
178
179 int
180 app_pipeline_ping(struct app_params *app,
181         uint32_t pipeline_id);
182
183 int
184 app_pipeline_stats_port_in(struct app_params *app,
185         uint32_t pipeline_id,
186         uint32_t port_id,
187         struct rte_pipeline_port_in_stats *stats);
188
189 int
190 app_pipeline_stats_port_out(struct app_params *app,
191         uint32_t pipeline_id,
192         uint32_t port_id,
193         struct rte_pipeline_port_out_stats *stats);
194
195 int
196 app_pipeline_stats_table(struct app_params *app,
197         uint32_t pipeline_id,
198         uint32_t table_id,
199         struct rte_pipeline_table_stats *stats);
200
201 int
202 app_pipeline_port_in_enable(struct app_params *app,
203         uint32_t pipeline_id,
204         uint32_t port_id);
205
206 int
207 app_pipeline_port_in_disable(struct app_params *app,
208         uint32_t pipeline_id,
209         uint32_t port_id);
210
211 int
212 app_link_config(struct app_params *app,
213         uint32_t link_id,
214         uint32_t ip,
215         uint32_t depth);
216
217 int
218 app_link_up(struct app_params *app,
219         uint32_t link_id);
220
221 int
222 app_link_down(struct app_params *app,
223         uint32_t link_id);
224
225 int
226 app_pipeline_common_cmd_push(struct app_params *app);
227
228 #endif