2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #ifndef __INCLUDE_PIPELINE_COMMON_BE_H__
18 #define __INCLUDE_PIPELINE_COMMON_BE_H__
20 #include <rte_common.h>
22 #include <rte_pipeline.h>
24 #include "pipeline_be.h"
28 enum pipeline_msg_req_type {
29 PIPELINE_MSG_REQ_PING = 0,
30 PIPELINE_MSG_REQ_STATS_PORT_IN,
31 PIPELINE_MSG_REQ_STATS_PORT_OUT,
32 PIPELINE_MSG_REQ_STATS_TABLE,
33 PIPELINE_MSG_REQ_PORT_IN_ENABLE,
34 PIPELINE_MSG_REQ_PORT_IN_DISABLE,
35 PIPELINE_MSG_REQ_CUSTOM,
39 typedef void *(*pipeline_msg_req_handler)(struct pipeline *p, void *msg);
42 struct rte_pipeline *p;
43 uint32_t port_in_id[PIPELINE_MAX_PORT_IN];
44 uint32_t port_out_id[PIPELINE_MAX_PORT_OUT];
45 uint32_t table_id[PIPELINE_MAX_TABLES];
46 struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
47 struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
54 pipeline_msg_req_handler handlers[PIPELINE_MSG_REQS];
55 char name[PIPELINE_NAME_SIZE];
59 enum pipeline_log_level {
60 PIPELINE_LOG_LEVEL_HIGH = 1,
61 PIPELINE_LOG_LEVEL_LOW,
65 #define PLOG(p, level, fmt, ...) \
67 if (p->log_level >= PIPELINE_LOG_LEVEL_ ## level) \
68 fprintf(stdout, "[%s] " fmt "\n", p->name, ## __VA_ARGS__);\
72 pipeline_msg_recv(struct pipeline *p,
75 struct rte_ring *r = p->msgq_in[msgq_id];
77 int status = rte_ring_sc_dequeue(r, &msg);
86 pipeline_msg_send(struct pipeline *p,
90 struct rte_ring *r = p->msgq_out[msgq_id];
94 status = rte_ring_sp_enqueue(r, msg);
95 } while (status == -ENOBUFS);
98 struct pipeline_msg_req {
99 enum pipeline_msg_req_type type;
102 struct pipeline_stats_msg_req {
103 enum pipeline_msg_req_type type;
107 struct pipeline_port_in_msg_req {
108 enum pipeline_msg_req_type type;
112 struct pipeline_custom_msg_req {
113 enum pipeline_msg_req_type type;
117 struct pipeline_msg_rsp {
121 struct pipeline_stats_port_in_msg_rsp {
123 struct rte_pipeline_port_in_stats stats;
126 struct pipeline_stats_port_out_msg_rsp {
128 struct rte_pipeline_port_out_stats stats;
131 struct pipeline_stats_table_msg_rsp {
133 struct rte_pipeline_table_stats stats;
136 void *pipeline_msg_req_ping_handler(struct pipeline *p, void *msg);
137 void *pipeline_msg_req_stats_port_in_handler(struct pipeline *p, void *msg);
138 void *pipeline_msg_req_stats_port_out_handler(struct pipeline *p, void *msg);
139 void *pipeline_msg_req_stats_table_handler(struct pipeline *p, void *msg);
140 void *pipeline_msg_req_port_in_enable_handler(struct pipeline *p, void *msg);
141 void *pipeline_msg_req_port_in_disable_handler(struct pipeline *p, void *msg);
142 void *pipeline_msg_req_invalid_handler(struct pipeline *p, void *msg);
144 int pipeline_msg_req_handle(struct pipeline *p);