examples/ip_pipeline: reconfigure thread binding dynamically
[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         if (pipeline_data->enabled == 0)
72                 return NULL;
73
74         return pipeline_data->fe;
75 }
76
77 static inline struct rte_ring *
78 app_pipeline_msgq_in_get(struct app_params *app,
79         uint32_t pipeline_id)
80 {
81         struct app_msgq_params *p;
82
83         APP_PARAM_FIND_BY_ID(app->msgq_params,
84                 "MSGQ-REQ-PIPELINE",
85                 pipeline_id,
86                 p);
87         if (p == NULL)
88                 return NULL;
89
90         return app->msgq[p - app->msgq_params];
91 }
92
93 static inline struct rte_ring *
94 app_pipeline_msgq_out_get(struct app_params *app,
95         uint32_t pipeline_id)
96 {
97         struct app_msgq_params *p;
98
99         APP_PARAM_FIND_BY_ID(app->msgq_params,
100                 "MSGQ-RSP-PIPELINE",
101                 pipeline_id,
102                 p);
103         if (p == NULL)
104                 return NULL;
105
106         return app->msgq[p - app->msgq_params];
107 }
108
109 static inline void *
110 app_msg_alloc(__rte_unused struct app_params *app)
111 {
112         return rte_malloc(NULL, 2048, RTE_CACHE_LINE_SIZE);
113 }
114
115 static inline void
116 app_msg_free(__rte_unused struct app_params *app,
117         void *msg)
118 {
119         rte_free(msg);
120 }
121
122 static inline void
123 app_msg_send(struct app_params *app,
124         uint32_t pipeline_id,
125         void *msg)
126 {
127         struct rte_ring *r = app_pipeline_msgq_in_get(app, pipeline_id);
128         int status;
129
130         do {
131                 status = rte_ring_sp_enqueue(r, msg);
132         } while (status == -ENOBUFS);
133 }
134
135 static inline void *
136 app_msg_recv(struct app_params *app,
137         uint32_t pipeline_id)
138 {
139         struct rte_ring *r = app_pipeline_msgq_out_get(app, pipeline_id);
140         void *msg;
141         int status = rte_ring_sc_dequeue(r, &msg);
142
143         if (status != 0)
144                 return NULL;
145
146         return msg;
147 }
148
149 static inline void *
150 app_msg_send_recv(struct app_params *app,
151         uint32_t pipeline_id,
152         void *msg,
153         uint32_t timeout_ms)
154 {
155         struct rte_ring *r_req = app_pipeline_msgq_in_get(app, pipeline_id);
156         struct rte_ring *r_rsp = app_pipeline_msgq_out_get(app, pipeline_id);
157         uint64_t hz = rte_get_tsc_hz();
158         void *msg_recv;
159         uint64_t deadline;
160         int status;
161
162         /* send */
163         do {
164                 status = rte_ring_sp_enqueue(r_req, (void *) msg);
165         } while (status == -ENOBUFS);
166
167         /* recv */
168         deadline = (timeout_ms) ?
169                 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
170                 UINT64_MAX;
171
172         do {
173                 if (rte_rdtsc() > deadline)
174                         return NULL;
175
176                 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
177         } while (status != 0);
178
179         return msg_recv;
180 }
181
182 int
183 app_pipeline_ping(struct app_params *app,
184         uint32_t pipeline_id);
185
186 int
187 app_pipeline_stats_port_in(struct app_params *app,
188         uint32_t pipeline_id,
189         uint32_t port_id,
190         struct rte_pipeline_port_in_stats *stats);
191
192 int
193 app_pipeline_stats_port_out(struct app_params *app,
194         uint32_t pipeline_id,
195         uint32_t port_id,
196         struct rte_pipeline_port_out_stats *stats);
197
198 int
199 app_pipeline_stats_table(struct app_params *app,
200         uint32_t pipeline_id,
201         uint32_t table_id,
202         struct rte_pipeline_table_stats *stats);
203
204 int
205 app_pipeline_port_in_enable(struct app_params *app,
206         uint32_t pipeline_id,
207         uint32_t port_id);
208
209 int
210 app_pipeline_port_in_disable(struct app_params *app,
211         uint32_t pipeline_id,
212         uint32_t port_id);
213
214 int
215 app_link_config(struct app_params *app,
216         uint32_t link_id,
217         uint32_t ip,
218         uint32_t depth);
219
220 int
221 app_link_up(struct app_params *app,
222         uint32_t link_id);
223
224 int
225 app_link_down(struct app_params *app,
226         uint32_t link_id);
227
228 int
229 app_pipeline_common_cmd_push(struct app_params *app);
230
231 #endif