New upstream version 18.02
[deb_dpdk.git] / examples / ip_pipeline / pipeline / pipeline_common_be.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_PIPELINE_COMMON_BE_H__
6 #define __INCLUDE_PIPELINE_COMMON_BE_H__
7
8 #include <rte_common.h>
9 #include <rte_ring.h>
10 #include <rte_pipeline.h>
11
12 #include "pipeline_be.h"
13
14 struct pipeline;
15
16 enum pipeline_msg_req_type {
17         PIPELINE_MSG_REQ_PING = 0,
18         PIPELINE_MSG_REQ_STATS_PORT_IN,
19         PIPELINE_MSG_REQ_STATS_PORT_OUT,
20         PIPELINE_MSG_REQ_STATS_TABLE,
21         PIPELINE_MSG_REQ_PORT_IN_ENABLE,
22         PIPELINE_MSG_REQ_PORT_IN_DISABLE,
23         PIPELINE_MSG_REQ_CUSTOM,
24         PIPELINE_MSG_REQS
25 };
26
27 typedef void *(*pipeline_msg_req_handler)(struct pipeline *p, void *msg);
28
29 struct pipeline {
30         struct rte_pipeline *p;
31         uint32_t port_in_id[PIPELINE_MAX_PORT_IN];
32         uint32_t port_out_id[PIPELINE_MAX_PORT_OUT];
33         uint32_t table_id[PIPELINE_MAX_TABLES];
34         struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
35         struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
36
37         uint32_t n_ports_in;
38         uint32_t n_ports_out;
39         uint32_t n_tables;
40         uint32_t n_msgq;
41
42         pipeline_msg_req_handler handlers[PIPELINE_MSG_REQS];
43         char name[PIPELINE_NAME_SIZE];
44         uint32_t log_level;
45 };
46
47 enum pipeline_log_level {
48         PIPELINE_LOG_LEVEL_HIGH = 1,
49         PIPELINE_LOG_LEVEL_LOW,
50         PIPELINE_LOG_LEVELS
51 };
52
53 #define PLOG(p, level, fmt, ...)                                        \
54 do {                                                                    \
55         if (p->log_level >= PIPELINE_LOG_LEVEL_ ## level)               \
56                 fprintf(stdout, "[%s] " fmt "\n", p->name, ## __VA_ARGS__);\
57 } while (0)
58
59 static inline void *
60 pipeline_msg_recv(struct pipeline *p,
61         uint32_t msgq_id)
62 {
63         struct rte_ring *r = p->msgq_in[msgq_id];
64         void *msg;
65         int status = rte_ring_sc_dequeue(r, &msg);
66
67         if (status != 0)
68                 return NULL;
69
70         return msg;
71 }
72
73 static inline void
74 pipeline_msg_send(struct pipeline *p,
75         uint32_t msgq_id,
76         void *msg)
77 {
78         struct rte_ring *r = p->msgq_out[msgq_id];
79         int status;
80
81         do {
82                 status = rte_ring_sp_enqueue(r, msg);
83         } while (status == -ENOBUFS);
84 }
85
86 struct pipeline_msg_req {
87         enum pipeline_msg_req_type type;
88 };
89
90 struct pipeline_stats_msg_req {
91         enum pipeline_msg_req_type type;
92         uint32_t id;
93 };
94
95 struct pipeline_port_in_msg_req {
96         enum pipeline_msg_req_type type;
97         uint32_t port_id;
98 };
99
100 struct pipeline_custom_msg_req {
101         enum pipeline_msg_req_type type;
102         uint32_t subtype;
103 };
104
105 struct pipeline_msg_rsp {
106         int status;
107 };
108
109 struct pipeline_stats_port_in_msg_rsp {
110         int status;
111         struct rte_pipeline_port_in_stats stats;
112 };
113
114 struct pipeline_stats_port_out_msg_rsp {
115         int status;
116         struct rte_pipeline_port_out_stats stats;
117 };
118
119 struct pipeline_stats_table_msg_rsp {
120         int status;
121         struct rte_pipeline_table_stats stats;
122 };
123
124 void *pipeline_msg_req_ping_handler(struct pipeline *p, void *msg);
125 void *pipeline_msg_req_stats_port_in_handler(struct pipeline *p, void *msg);
126 void *pipeline_msg_req_stats_port_out_handler(struct pipeline *p, void *msg);
127 void *pipeline_msg_req_stats_table_handler(struct pipeline *p, void *msg);
128 void *pipeline_msg_req_port_in_enable_handler(struct pipeline *p, void *msg);
129 void *pipeline_msg_req_port_in_disable_handler(struct pipeline *p, void *msg);
130 void *pipeline_msg_req_invalid_handler(struct pipeline *p, void *msg);
131
132 int pipeline_msg_req_handle(struct pipeline *p);
133
134 #endif