New upstream version 18.02
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_fe.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_PIPELINE_COMMON_FE_H__
6 #define __INCLUDE_PIPELINE_COMMON_FE_H__
7
8 #include <rte_common.h>
9 #include <rte_cycles.h>
10 #include <rte_malloc.h>
11 #include <cmdline_parse.h>
12
13 #include "pipeline_common_be.h"
14 #include "pipeline.h"
15 #include "app.h"
16
17 #ifndef MSG_TIMEOUT_DEFAULT
18 #define MSG_TIMEOUT_DEFAULT                      1000
19 #endif
20
21 static inline struct app_pipeline_data *
22 app_pipeline_data(struct app_params *app, uint32_t id)
23 {
24         struct app_pipeline_params *params;
25
26         APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", id, params);
27         if (params == NULL)
28                 return NULL;
29
30         return &app->pipeline_data[params - app->pipeline_params];
31 }
32
33 static inline void *
34 app_pipeline_data_fe(struct app_params *app, uint32_t id, struct pipeline_type *ptype)
35 {
36         struct app_pipeline_data *pipeline_data;
37
38         pipeline_data = app_pipeline_data(app, id);
39         if (pipeline_data == NULL)
40                 return NULL;
41
42         if (strcmp(pipeline_data->ptype->name, ptype->name) != 0)
43                 return NULL;
44
45         if (pipeline_data->enabled == 0)
46                 return NULL;
47
48         return pipeline_data->fe;
49 }
50
51 static inline struct rte_ring *
52 app_pipeline_msgq_in_get(struct app_params *app,
53         uint32_t pipeline_id)
54 {
55         struct app_msgq_params *p;
56
57         APP_PARAM_FIND_BY_ID(app->msgq_params,
58                 "MSGQ-REQ-PIPELINE",
59                 pipeline_id,
60                 p);
61         if (p == NULL)
62                 return NULL;
63
64         return app->msgq[p - app->msgq_params];
65 }
66
67 static inline struct rte_ring *
68 app_pipeline_msgq_out_get(struct app_params *app,
69         uint32_t pipeline_id)
70 {
71         struct app_msgq_params *p;
72
73         APP_PARAM_FIND_BY_ID(app->msgq_params,
74                 "MSGQ-RSP-PIPELINE",
75                 pipeline_id,
76                 p);
77         if (p == NULL)
78                 return NULL;
79
80         return app->msgq[p - app->msgq_params];
81 }
82
83 static inline void *
84 app_msg_alloc(__rte_unused struct app_params *app)
85 {
86         return rte_malloc(NULL, 2048, RTE_CACHE_LINE_SIZE);
87 }
88
89 static inline void
90 app_msg_free(__rte_unused struct app_params *app,
91         void *msg)
92 {
93         rte_free(msg);
94 }
95
96 static inline void
97 app_msg_send(struct app_params *app,
98         uint32_t pipeline_id,
99         void *msg)
100 {
101         struct rte_ring *r = app_pipeline_msgq_in_get(app, pipeline_id);
102         int status;
103
104         do {
105                 status = rte_ring_sp_enqueue(r, msg);
106         } while (status == -ENOBUFS);
107 }
108
109 static inline void *
110 app_msg_recv(struct app_params *app,
111         uint32_t pipeline_id)
112 {
113         struct rte_ring *r = app_pipeline_msgq_out_get(app, pipeline_id);
114         void *msg;
115         int status = rte_ring_sc_dequeue(r, &msg);
116
117         if (status != 0)
118                 return NULL;
119
120         return msg;
121 }
122
123 static inline void *
124 app_msg_send_recv(struct app_params *app,
125         uint32_t pipeline_id,
126         void *msg,
127         uint32_t timeout_ms)
128 {
129         struct rte_ring *r_req = app_pipeline_msgq_in_get(app, pipeline_id);
130         struct rte_ring *r_rsp = app_pipeline_msgq_out_get(app, pipeline_id);
131         uint64_t hz = rte_get_tsc_hz();
132         void *msg_recv;
133         uint64_t deadline;
134         int status;
135
136         /* send */
137         do {
138                 status = rte_ring_sp_enqueue(r_req, (void *) msg);
139         } while (status == -ENOBUFS);
140
141         /* recv */
142         deadline = (timeout_ms) ?
143                 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
144                 UINT64_MAX;
145
146         do {
147                 if (rte_rdtsc() > deadline)
148                         return NULL;
149
150                 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
151         } while (status != 0);
152
153         return msg_recv;
154 }
155
156 struct app_link_params *
157 app_pipeline_track_pktq_out_to_link(struct app_params *app,
158         uint32_t pipeline_id,
159         uint32_t pktq_out_id);
160
161 int
162 app_pipeline_track_default(struct pipeline_params *params,
163         uint32_t port_in,
164         uint32_t *port_out);
165
166 int
167 app_pipeline_ping(struct app_params *app,
168         uint32_t pipeline_id);
169
170 int
171 app_pipeline_stats_port_in(struct app_params *app,
172         uint32_t pipeline_id,
173         uint32_t port_id,
174         struct rte_pipeline_port_in_stats *stats);
175
176 int
177 app_pipeline_stats_port_out(struct app_params *app,
178         uint32_t pipeline_id,
179         uint32_t port_id,
180         struct rte_pipeline_port_out_stats *stats);
181
182 int
183 app_pipeline_stats_table(struct app_params *app,
184         uint32_t pipeline_id,
185         uint32_t table_id,
186         struct rte_pipeline_table_stats *stats);
187
188 int
189 app_pipeline_port_in_enable(struct app_params *app,
190         uint32_t pipeline_id,
191         uint32_t port_id);
192
193 int
194 app_pipeline_port_in_disable(struct app_params *app,
195         uint32_t pipeline_id,
196         uint32_t port_id);
197
198 int
199 app_link_set_op(struct app_params *app,
200         uint32_t link_id,
201         uint32_t pipeline_id,
202         app_link_op op,
203         void *arg);
204
205 int
206 app_link_config(struct app_params *app,
207         uint32_t link_id,
208         uint32_t ip,
209         uint32_t depth);
210
211 int
212 app_link_up(struct app_params *app,
213         uint32_t link_id);
214
215 int
216 app_link_down(struct app_params *app,
217         uint32_t link_id);
218
219 int
220 app_pipeline_common_cmd_push(struct app_params *app);
221
222 #define CMD_MSG_OUT_OF_MEMORY   "Not enough memory\n"
223 #define CMD_MSG_NOT_ENOUGH_ARGS "Not enough arguments for command \"%s\"\n"
224 #define CMD_MSG_TOO_MANY_ARGS   "Too many arguments for command \"%s\"\n"
225 #define CMD_MSG_MISMATCH_ARGS   "Incorrect set of arguments for command \"%s\"\n"
226 #define CMD_MSG_INVALID_ARG     "Invalid value for argument \"%s\"\n"
227 #define CMD_MSG_ARG_NOT_FOUND   "Syntax error: \"%s\" not found\n"
228 #define CMD_MSG_FILE_ERR        "Error in file \"%s\" at line %u\n"
229 #define CMD_MSG_FAIL            "Command \"%s\" failed\n"
230
231 #endif