1c0b668e0SJasvinder Singh /* SPDX-License-Identifier: BSD-3-Clause
2c0b668e0SJasvinder Singh * Copyright(c) 2010-2018 Intel Corporation
3c0b668e0SJasvinder Singh */
4c0b668e0SJasvinder Singh
5c0b668e0SJasvinder Singh #include <stdlib.h>
6c0b668e0SJasvinder Singh
7c0b668e0SJasvinder Singh #include <rte_common.h>
8c0b668e0SJasvinder Singh #include <rte_cycles.h>
9c0b668e0SJasvinder Singh #include <rte_lcore.h>
10c0b668e0SJasvinder Singh #include <rte_ring.h>
11c0b668e0SJasvinder Singh
12c0b668e0SJasvinder Singh #include <rte_table_acl.h>
13c0b668e0SJasvinder Singh #include <rte_table_array.h>
14c0b668e0SJasvinder Singh #include <rte_table_hash.h>
15c0b668e0SJasvinder Singh #include <rte_table_lpm.h>
16c0b668e0SJasvinder Singh #include <rte_table_lpm_ipv6.h>
17c0b668e0SJasvinder Singh
18c0b668e0SJasvinder Singh #include "common.h"
19c0b668e0SJasvinder Singh #include "thread.h"
20c0b668e0SJasvinder Singh #include "pipeline.h"
21c0b668e0SJasvinder Singh
22c0b668e0SJasvinder Singh #ifndef THREAD_PIPELINES_MAX
23c0b668e0SJasvinder Singh #define THREAD_PIPELINES_MAX 256
24c0b668e0SJasvinder Singh #endif
25c0b668e0SJasvinder Singh
26c0b668e0SJasvinder Singh #ifndef THREAD_MSGQ_SIZE
27c0b668e0SJasvinder Singh #define THREAD_MSGQ_SIZE 64
28c0b668e0SJasvinder Singh #endif
29c0b668e0SJasvinder Singh
30c0b668e0SJasvinder Singh #ifndef THREAD_TIMER_PERIOD_MS
31c0b668e0SJasvinder Singh #define THREAD_TIMER_PERIOD_MS 100
32c0b668e0SJasvinder Singh #endif
33c0b668e0SJasvinder Singh
34c0b668e0SJasvinder Singh /**
35*cb056611SStephen Hemminger * Main thread: data plane thread context
36c0b668e0SJasvinder Singh */
37c0b668e0SJasvinder Singh struct thread {
38c0b668e0SJasvinder Singh struct rte_ring *msgq_req;
39c0b668e0SJasvinder Singh struct rte_ring *msgq_rsp;
40c0b668e0SJasvinder Singh
41c0b668e0SJasvinder Singh uint32_t enabled;
42c0b668e0SJasvinder Singh };
43c0b668e0SJasvinder Singh
44c0b668e0SJasvinder Singh static struct thread thread[RTE_MAX_LCORE];
45c0b668e0SJasvinder Singh
46c0b668e0SJasvinder Singh /**
47c0b668e0SJasvinder Singh * Data plane threads: context
48c0b668e0SJasvinder Singh */
49c0b668e0SJasvinder Singh struct table_data {
50c0b668e0SJasvinder Singh struct rte_table_action *a;
51c0b668e0SJasvinder Singh };
52c0b668e0SJasvinder Singh
53c0b668e0SJasvinder Singh struct pipeline_data {
54c0b668e0SJasvinder Singh struct rte_pipeline *p;
55c0b668e0SJasvinder Singh struct table_data table_data[RTE_PIPELINE_TABLE_MAX];
56c0b668e0SJasvinder Singh uint32_t n_tables;
57c0b668e0SJasvinder Singh
58c0b668e0SJasvinder Singh struct rte_ring *msgq_req;
59c0b668e0SJasvinder Singh struct rte_ring *msgq_rsp;
60c0b668e0SJasvinder Singh uint64_t timer_period; /* Measured in CPU cycles. */
61c0b668e0SJasvinder Singh uint64_t time_next;
62c0b668e0SJasvinder Singh
63c0b668e0SJasvinder Singh uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
64c0b668e0SJasvinder Singh };
65c0b668e0SJasvinder Singh
66c0b668e0SJasvinder Singh struct thread_data {
67c0b668e0SJasvinder Singh struct rte_pipeline *p[THREAD_PIPELINES_MAX];
68c0b668e0SJasvinder Singh uint32_t n_pipelines;
69c0b668e0SJasvinder Singh
70c0b668e0SJasvinder Singh struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
71c0b668e0SJasvinder Singh struct rte_ring *msgq_req;
72c0b668e0SJasvinder Singh struct rte_ring *msgq_rsp;
73c0b668e0SJasvinder Singh uint64_t timer_period; /* Measured in CPU cycles. */
74c0b668e0SJasvinder Singh uint64_t time_next;
75c0b668e0SJasvinder Singh uint64_t time_next_min;
76c0b668e0SJasvinder Singh } __rte_cache_aligned;
77c0b668e0SJasvinder Singh
78c0b668e0SJasvinder Singh static struct thread_data thread_data[RTE_MAX_LCORE];
79c0b668e0SJasvinder Singh
80c0b668e0SJasvinder Singh /**
81*cb056611SStephen Hemminger * Main thread: data plane thread init
82c0b668e0SJasvinder Singh */
83c0b668e0SJasvinder Singh static void
thread_free(void)84c0b668e0SJasvinder Singh thread_free(void)
85c0b668e0SJasvinder Singh {
86c0b668e0SJasvinder Singh uint32_t i;
87c0b668e0SJasvinder Singh
88c0b668e0SJasvinder Singh for (i = 0; i < RTE_MAX_LCORE; i++) {
89c0b668e0SJasvinder Singh struct thread *t = &thread[i];
90c0b668e0SJasvinder Singh
91c0b668e0SJasvinder Singh if (!rte_lcore_is_enabled(i))
92c0b668e0SJasvinder Singh continue;
93c0b668e0SJasvinder Singh
94c0b668e0SJasvinder Singh /* MSGQs */
95c0b668e0SJasvinder Singh rte_ring_free(t->msgq_req);
96c0b668e0SJasvinder Singh
97c0b668e0SJasvinder Singh rte_ring_free(t->msgq_rsp);
98c0b668e0SJasvinder Singh }
99c0b668e0SJasvinder Singh }
100c0b668e0SJasvinder Singh
101c0b668e0SJasvinder Singh int
thread_init(void)102c0b668e0SJasvinder Singh thread_init(void)
103c0b668e0SJasvinder Singh {
104c0b668e0SJasvinder Singh uint32_t i;
105c0b668e0SJasvinder Singh
106*cb056611SStephen Hemminger RTE_LCORE_FOREACH_WORKER(i) {
107c0b668e0SJasvinder Singh char name[NAME_MAX];
108c0b668e0SJasvinder Singh struct rte_ring *msgq_req, *msgq_rsp;
109c0b668e0SJasvinder Singh struct thread *t = &thread[i];
110c0b668e0SJasvinder Singh struct thread_data *t_data = &thread_data[i];
111c0b668e0SJasvinder Singh uint32_t cpu_id = rte_lcore_to_socket_id(i);
112c0b668e0SJasvinder Singh
113c0b668e0SJasvinder Singh /* MSGQs */
114c0b668e0SJasvinder Singh snprintf(name, sizeof(name), "THREAD-%04x-MSGQ-REQ", i);
115c0b668e0SJasvinder Singh
116c0b668e0SJasvinder Singh msgq_req = rte_ring_create(name,
117c0b668e0SJasvinder Singh THREAD_MSGQ_SIZE,
118c0b668e0SJasvinder Singh cpu_id,
119c0b668e0SJasvinder Singh RING_F_SP_ENQ | RING_F_SC_DEQ);
120c0b668e0SJasvinder Singh
121c0b668e0SJasvinder Singh if (msgq_req == NULL) {
122c0b668e0SJasvinder Singh thread_free();
123c0b668e0SJasvinder Singh return -1;
124c0b668e0SJasvinder Singh }
125c0b668e0SJasvinder Singh
126c0b668e0SJasvinder Singh snprintf(name, sizeof(name), "THREAD-%04x-MSGQ-RSP", i);
127c0b668e0SJasvinder Singh
128c0b668e0SJasvinder Singh msgq_rsp = rte_ring_create(name,
129c0b668e0SJasvinder Singh THREAD_MSGQ_SIZE,
130c0b668e0SJasvinder Singh cpu_id,
131c0b668e0SJasvinder Singh RING_F_SP_ENQ | RING_F_SC_DEQ);
132c0b668e0SJasvinder Singh
133c0b668e0SJasvinder Singh if (msgq_rsp == NULL) {
134c0b668e0SJasvinder Singh thread_free();
135c0b668e0SJasvinder Singh return -1;
136c0b668e0SJasvinder Singh }
137c0b668e0SJasvinder Singh
138*cb056611SStephen Hemminger /* Main thread records */
139c0b668e0SJasvinder Singh t->msgq_req = msgq_req;
140c0b668e0SJasvinder Singh t->msgq_rsp = msgq_rsp;
141c0b668e0SJasvinder Singh t->enabled = 1;
142c0b668e0SJasvinder Singh
143c0b668e0SJasvinder Singh /* Data plane thread records */
144c0b668e0SJasvinder Singh t_data->n_pipelines = 0;
145c0b668e0SJasvinder Singh t_data->msgq_req = msgq_req;
146c0b668e0SJasvinder Singh t_data->msgq_rsp = msgq_rsp;
147c0b668e0SJasvinder Singh t_data->timer_period =
148c0b668e0SJasvinder Singh (rte_get_tsc_hz() * THREAD_TIMER_PERIOD_MS) / 1000;
149c0b668e0SJasvinder Singh t_data->time_next = rte_get_tsc_cycles() + t_data->timer_period;
150c0b668e0SJasvinder Singh t_data->time_next_min = t_data->time_next;
151c0b668e0SJasvinder Singh }
152c0b668e0SJasvinder Singh
153c0b668e0SJasvinder Singh return 0;
154c0b668e0SJasvinder Singh }
155a8bd581dSJasvinder Singh
156f68a1d3fSJasvinder Singh static inline int
thread_is_running(uint32_t thread_id)157f68a1d3fSJasvinder Singh thread_is_running(uint32_t thread_id)
158f68a1d3fSJasvinder Singh {
159f68a1d3fSJasvinder Singh enum rte_lcore_state_t thread_state;
160f68a1d3fSJasvinder Singh
161f68a1d3fSJasvinder Singh thread_state = rte_eal_get_lcore_state(thread_id);
162f68a1d3fSJasvinder Singh return (thread_state == RUNNING) ? 1 : 0;
163f68a1d3fSJasvinder Singh }
164f68a1d3fSJasvinder Singh
165f68a1d3fSJasvinder Singh /**
166f68a1d3fSJasvinder Singh * Pipeline is running when:
167f68a1d3fSJasvinder Singh * (A) Pipeline is mapped to a data plane thread AND
168f68a1d3fSJasvinder Singh * (B) Its data plane thread is in RUNNING state.
169f68a1d3fSJasvinder Singh */
170f68a1d3fSJasvinder Singh static inline int
pipeline_is_running(struct pipeline * p)171f68a1d3fSJasvinder Singh pipeline_is_running(struct pipeline *p)
172f68a1d3fSJasvinder Singh {
173f68a1d3fSJasvinder Singh if (p->enabled == 0)
174f68a1d3fSJasvinder Singh return 0;
175f68a1d3fSJasvinder Singh
176f68a1d3fSJasvinder Singh return thread_is_running(p->thread_id);
177f68a1d3fSJasvinder Singh }
178f68a1d3fSJasvinder Singh
179a8bd581dSJasvinder Singh /**
180*cb056611SStephen Hemminger * Main thread & data plane threads: message passing
181a8bd581dSJasvinder Singh */
182a8bd581dSJasvinder Singh enum thread_req_type {
18332e5d9b1SJasvinder Singh THREAD_REQ_PIPELINE_ENABLE = 0,
18432e5d9b1SJasvinder Singh THREAD_REQ_PIPELINE_DISABLE,
185a8bd581dSJasvinder Singh THREAD_REQ_MAX
186a8bd581dSJasvinder Singh };
187a8bd581dSJasvinder Singh
188a8bd581dSJasvinder Singh struct thread_msg_req {
189a8bd581dSJasvinder Singh enum thread_req_type type;
19032e5d9b1SJasvinder Singh
19132e5d9b1SJasvinder Singh union {
19232e5d9b1SJasvinder Singh struct {
19332e5d9b1SJasvinder Singh struct rte_pipeline *p;
19432e5d9b1SJasvinder Singh struct {
19532e5d9b1SJasvinder Singh struct rte_table_action *a;
19632e5d9b1SJasvinder Singh } table[RTE_PIPELINE_TABLE_MAX];
19732e5d9b1SJasvinder Singh struct rte_ring *msgq_req;
19832e5d9b1SJasvinder Singh struct rte_ring *msgq_rsp;
19932e5d9b1SJasvinder Singh uint32_t timer_period_ms;
20032e5d9b1SJasvinder Singh uint32_t n_tables;
20132e5d9b1SJasvinder Singh } pipeline_enable;
20232e5d9b1SJasvinder Singh
20332e5d9b1SJasvinder Singh struct {
20432e5d9b1SJasvinder Singh struct rte_pipeline *p;
20532e5d9b1SJasvinder Singh } pipeline_disable;
20632e5d9b1SJasvinder Singh };
207a8bd581dSJasvinder Singh };
208a8bd581dSJasvinder Singh
209a8bd581dSJasvinder Singh struct thread_msg_rsp {
210a8bd581dSJasvinder Singh int status;
211a8bd581dSJasvinder Singh };
212a8bd581dSJasvinder Singh
213a8bd581dSJasvinder Singh /**
214*cb056611SStephen Hemminger * Main thread
21532e5d9b1SJasvinder Singh */
21632e5d9b1SJasvinder Singh static struct thread_msg_req *
thread_msg_alloc(void)21732e5d9b1SJasvinder Singh thread_msg_alloc(void)
21832e5d9b1SJasvinder Singh {
21932e5d9b1SJasvinder Singh size_t size = RTE_MAX(sizeof(struct thread_msg_req),
22032e5d9b1SJasvinder Singh sizeof(struct thread_msg_rsp));
22132e5d9b1SJasvinder Singh
22232e5d9b1SJasvinder Singh return calloc(1, size);
22332e5d9b1SJasvinder Singh }
22432e5d9b1SJasvinder Singh
22532e5d9b1SJasvinder Singh static void
thread_msg_free(struct thread_msg_rsp * rsp)22632e5d9b1SJasvinder Singh thread_msg_free(struct thread_msg_rsp *rsp)
22732e5d9b1SJasvinder Singh {
22832e5d9b1SJasvinder Singh free(rsp);
22932e5d9b1SJasvinder Singh }
23032e5d9b1SJasvinder Singh
23132e5d9b1SJasvinder Singh static struct thread_msg_rsp *
thread_msg_send_recv(uint32_t thread_id,struct thread_msg_req * req)23232e5d9b1SJasvinder Singh thread_msg_send_recv(uint32_t thread_id,
23332e5d9b1SJasvinder Singh struct thread_msg_req *req)
23432e5d9b1SJasvinder Singh {
23532e5d9b1SJasvinder Singh struct thread *t = &thread[thread_id];
23632e5d9b1SJasvinder Singh struct rte_ring *msgq_req = t->msgq_req;
23732e5d9b1SJasvinder Singh struct rte_ring *msgq_rsp = t->msgq_rsp;
23832e5d9b1SJasvinder Singh struct thread_msg_rsp *rsp;
23932e5d9b1SJasvinder Singh int status;
24032e5d9b1SJasvinder Singh
24132e5d9b1SJasvinder Singh /* send */
24232e5d9b1SJasvinder Singh do {
24332e5d9b1SJasvinder Singh status = rte_ring_sp_enqueue(msgq_req, req);
24432e5d9b1SJasvinder Singh } while (status == -ENOBUFS);
24532e5d9b1SJasvinder Singh
24632e5d9b1SJasvinder Singh /* recv */
24732e5d9b1SJasvinder Singh do {
24832e5d9b1SJasvinder Singh status = rte_ring_sc_dequeue(msgq_rsp, (void **) &rsp);
24932e5d9b1SJasvinder Singh } while (status != 0);
25032e5d9b1SJasvinder Singh
25132e5d9b1SJasvinder Singh return rsp;
25232e5d9b1SJasvinder Singh }
25332e5d9b1SJasvinder Singh
25432e5d9b1SJasvinder Singh int
thread_pipeline_enable(uint32_t thread_id,const char * pipeline_name)25532e5d9b1SJasvinder Singh thread_pipeline_enable(uint32_t thread_id,
25632e5d9b1SJasvinder Singh const char *pipeline_name)
25732e5d9b1SJasvinder Singh {
25832e5d9b1SJasvinder Singh struct pipeline *p = pipeline_find(pipeline_name);
25932e5d9b1SJasvinder Singh struct thread *t;
26032e5d9b1SJasvinder Singh struct thread_msg_req *req;
26132e5d9b1SJasvinder Singh struct thread_msg_rsp *rsp;
26232e5d9b1SJasvinder Singh uint32_t i;
26332e5d9b1SJasvinder Singh int status;
26432e5d9b1SJasvinder Singh
26532e5d9b1SJasvinder Singh /* Check input params */
26632e5d9b1SJasvinder Singh if ((thread_id >= RTE_MAX_LCORE) ||
26732e5d9b1SJasvinder Singh (p == NULL) ||
26832e5d9b1SJasvinder Singh (p->n_ports_in == 0) ||
26932e5d9b1SJasvinder Singh (p->n_ports_out == 0) ||
27032e5d9b1SJasvinder Singh (p->n_tables == 0))
27132e5d9b1SJasvinder Singh return -1;
27232e5d9b1SJasvinder Singh
27332e5d9b1SJasvinder Singh t = &thread[thread_id];
27432e5d9b1SJasvinder Singh if ((t->enabled == 0) ||
27532e5d9b1SJasvinder Singh p->enabled)
27632e5d9b1SJasvinder Singh return -1;
27732e5d9b1SJasvinder Singh
278f68a1d3fSJasvinder Singh if (!thread_is_running(thread_id)) {
279f68a1d3fSJasvinder Singh struct thread_data *td = &thread_data[thread_id];
280f68a1d3fSJasvinder Singh struct pipeline_data *tdp = &td->pipeline_data[td->n_pipelines];
281f68a1d3fSJasvinder Singh
282f68a1d3fSJasvinder Singh if (td->n_pipelines >= THREAD_PIPELINES_MAX)
283f68a1d3fSJasvinder Singh return -1;
284f68a1d3fSJasvinder Singh
285f68a1d3fSJasvinder Singh /* Data plane thread */
286f68a1d3fSJasvinder Singh td->p[td->n_pipelines] = p->p;
287f68a1d3fSJasvinder Singh
288f68a1d3fSJasvinder Singh tdp->p = p->p;
289f68a1d3fSJasvinder Singh for (i = 0; i < p->n_tables; i++)
290f68a1d3fSJasvinder Singh tdp->table_data[i].a = p->table[i].a;
291f68a1d3fSJasvinder Singh
292f68a1d3fSJasvinder Singh tdp->n_tables = p->n_tables;
293f68a1d3fSJasvinder Singh
294f68a1d3fSJasvinder Singh tdp->msgq_req = p->msgq_req;
295f68a1d3fSJasvinder Singh tdp->msgq_rsp = p->msgq_rsp;
296f68a1d3fSJasvinder Singh tdp->timer_period = (rte_get_tsc_hz() * p->timer_period_ms) / 1000;
297f68a1d3fSJasvinder Singh tdp->time_next = rte_get_tsc_cycles() + tdp->timer_period;
298f68a1d3fSJasvinder Singh
299f68a1d3fSJasvinder Singh td->n_pipelines++;
300f68a1d3fSJasvinder Singh
301f68a1d3fSJasvinder Singh /* Pipeline */
302f68a1d3fSJasvinder Singh p->thread_id = thread_id;
303f68a1d3fSJasvinder Singh p->enabled = 1;
304f68a1d3fSJasvinder Singh
305f68a1d3fSJasvinder Singh return 0;
306f68a1d3fSJasvinder Singh }
307f68a1d3fSJasvinder Singh
30832e5d9b1SJasvinder Singh /* Allocate request */
30932e5d9b1SJasvinder Singh req = thread_msg_alloc();
31032e5d9b1SJasvinder Singh if (req == NULL)
31132e5d9b1SJasvinder Singh return -1;
31232e5d9b1SJasvinder Singh
31332e5d9b1SJasvinder Singh /* Write request */
31432e5d9b1SJasvinder Singh req->type = THREAD_REQ_PIPELINE_ENABLE;
31532e5d9b1SJasvinder Singh req->pipeline_enable.p = p->p;
31632e5d9b1SJasvinder Singh for (i = 0; i < p->n_tables; i++)
31732e5d9b1SJasvinder Singh req->pipeline_enable.table[i].a =
31832e5d9b1SJasvinder Singh p->table[i].a;
31932e5d9b1SJasvinder Singh req->pipeline_enable.msgq_req = p->msgq_req;
32032e5d9b1SJasvinder Singh req->pipeline_enable.msgq_rsp = p->msgq_rsp;
32132e5d9b1SJasvinder Singh req->pipeline_enable.timer_period_ms = p->timer_period_ms;
32232e5d9b1SJasvinder Singh req->pipeline_enable.n_tables = p->n_tables;
32332e5d9b1SJasvinder Singh
32432e5d9b1SJasvinder Singh /* Send request and wait for response */
32532e5d9b1SJasvinder Singh rsp = thread_msg_send_recv(thread_id, req);
32632e5d9b1SJasvinder Singh
32732e5d9b1SJasvinder Singh /* Read response */
32832e5d9b1SJasvinder Singh status = rsp->status;
32932e5d9b1SJasvinder Singh
33032e5d9b1SJasvinder Singh /* Free response */
33132e5d9b1SJasvinder Singh thread_msg_free(rsp);
33232e5d9b1SJasvinder Singh
33332e5d9b1SJasvinder Singh /* Request completion */
33432e5d9b1SJasvinder Singh if (status)
33532e5d9b1SJasvinder Singh return status;
33632e5d9b1SJasvinder Singh
33732e5d9b1SJasvinder Singh p->thread_id = thread_id;
33832e5d9b1SJasvinder Singh p->enabled = 1;
33932e5d9b1SJasvinder Singh
34032e5d9b1SJasvinder Singh return 0;
34132e5d9b1SJasvinder Singh }
34232e5d9b1SJasvinder Singh
34332e5d9b1SJasvinder Singh int
thread_pipeline_disable(uint32_t thread_id,const char * pipeline_name)34432e5d9b1SJasvinder Singh thread_pipeline_disable(uint32_t thread_id,
34532e5d9b1SJasvinder Singh const char *pipeline_name)
34632e5d9b1SJasvinder Singh {
34732e5d9b1SJasvinder Singh struct pipeline *p = pipeline_find(pipeline_name);
34832e5d9b1SJasvinder Singh struct thread *t;
34932e5d9b1SJasvinder Singh struct thread_msg_req *req;
35032e5d9b1SJasvinder Singh struct thread_msg_rsp *rsp;
35132e5d9b1SJasvinder Singh int status;
35232e5d9b1SJasvinder Singh
35332e5d9b1SJasvinder Singh /* Check input params */
35432e5d9b1SJasvinder Singh if ((thread_id >= RTE_MAX_LCORE) ||
35532e5d9b1SJasvinder Singh (p == NULL))
35632e5d9b1SJasvinder Singh return -1;
35732e5d9b1SJasvinder Singh
35832e5d9b1SJasvinder Singh t = &thread[thread_id];
35932e5d9b1SJasvinder Singh if (t->enabled == 0)
36032e5d9b1SJasvinder Singh return -1;
36132e5d9b1SJasvinder Singh
36232e5d9b1SJasvinder Singh if (p->enabled == 0)
36332e5d9b1SJasvinder Singh return 0;
36432e5d9b1SJasvinder Singh
36532e5d9b1SJasvinder Singh if (p->thread_id != thread_id)
36632e5d9b1SJasvinder Singh return -1;
36732e5d9b1SJasvinder Singh
368f68a1d3fSJasvinder Singh if (!thread_is_running(thread_id)) {
369f68a1d3fSJasvinder Singh struct thread_data *td = &thread_data[thread_id];
370f68a1d3fSJasvinder Singh uint32_t i;
371f68a1d3fSJasvinder Singh
372f68a1d3fSJasvinder Singh for (i = 0; i < td->n_pipelines; i++) {
373f68a1d3fSJasvinder Singh struct pipeline_data *tdp = &td->pipeline_data[i];
374f68a1d3fSJasvinder Singh
375f68a1d3fSJasvinder Singh if (tdp->p != p->p)
376f68a1d3fSJasvinder Singh continue;
377f68a1d3fSJasvinder Singh
378f68a1d3fSJasvinder Singh /* Data plane thread */
379f68a1d3fSJasvinder Singh if (i < td->n_pipelines - 1) {
380f68a1d3fSJasvinder Singh struct rte_pipeline *pipeline_last =
381f68a1d3fSJasvinder Singh td->p[td->n_pipelines - 1];
382f68a1d3fSJasvinder Singh struct pipeline_data *tdp_last =
383f68a1d3fSJasvinder Singh &td->pipeline_data[td->n_pipelines - 1];
384f68a1d3fSJasvinder Singh
385f68a1d3fSJasvinder Singh td->p[i] = pipeline_last;
386f68a1d3fSJasvinder Singh memcpy(tdp, tdp_last, sizeof(*tdp));
387f68a1d3fSJasvinder Singh }
388f68a1d3fSJasvinder Singh
389f68a1d3fSJasvinder Singh td->n_pipelines--;
390f68a1d3fSJasvinder Singh
391f68a1d3fSJasvinder Singh /* Pipeline */
392f68a1d3fSJasvinder Singh p->enabled = 0;
393f68a1d3fSJasvinder Singh
394f68a1d3fSJasvinder Singh break;
395f68a1d3fSJasvinder Singh }
396f68a1d3fSJasvinder Singh
397f68a1d3fSJasvinder Singh return 0;
398f68a1d3fSJasvinder Singh }
399f68a1d3fSJasvinder Singh
40032e5d9b1SJasvinder Singh /* Allocate request */
40132e5d9b1SJasvinder Singh req = thread_msg_alloc();
40232e5d9b1SJasvinder Singh if (req == NULL)
40332e5d9b1SJasvinder Singh return -1;
40432e5d9b1SJasvinder Singh
40532e5d9b1SJasvinder Singh /* Write request */
40632e5d9b1SJasvinder Singh req->type = THREAD_REQ_PIPELINE_DISABLE;
40732e5d9b1SJasvinder Singh req->pipeline_disable.p = p->p;
40832e5d9b1SJasvinder Singh
40932e5d9b1SJasvinder Singh /* Send request and wait for response */
41032e5d9b1SJasvinder Singh rsp = thread_msg_send_recv(thread_id, req);
41132e5d9b1SJasvinder Singh
41232e5d9b1SJasvinder Singh /* Read response */
41332e5d9b1SJasvinder Singh status = rsp->status;
41432e5d9b1SJasvinder Singh
41532e5d9b1SJasvinder Singh /* Free response */
41632e5d9b1SJasvinder Singh thread_msg_free(rsp);
41732e5d9b1SJasvinder Singh
41832e5d9b1SJasvinder Singh /* Request completion */
41932e5d9b1SJasvinder Singh if (status)
42032e5d9b1SJasvinder Singh return status;
42132e5d9b1SJasvinder Singh
42232e5d9b1SJasvinder Singh p->enabled = 0;
42332e5d9b1SJasvinder Singh
42432e5d9b1SJasvinder Singh return 0;
42532e5d9b1SJasvinder Singh }
42632e5d9b1SJasvinder Singh
42732e5d9b1SJasvinder Singh /**
428a8bd581dSJasvinder Singh * Data plane threads: message handling
429a8bd581dSJasvinder Singh */
430a8bd581dSJasvinder Singh static inline struct thread_msg_req *
thread_msg_recv(struct rte_ring * msgq_req)431a8bd581dSJasvinder Singh thread_msg_recv(struct rte_ring *msgq_req)
432a8bd581dSJasvinder Singh {
433a8bd581dSJasvinder Singh struct thread_msg_req *req;
434a8bd581dSJasvinder Singh
435a8bd581dSJasvinder Singh int status = rte_ring_sc_dequeue(msgq_req, (void **) &req);
436a8bd581dSJasvinder Singh
437a8bd581dSJasvinder Singh if (status != 0)
438a8bd581dSJasvinder Singh return NULL;
439a8bd581dSJasvinder Singh
440a8bd581dSJasvinder Singh return req;
441a8bd581dSJasvinder Singh }
442a8bd581dSJasvinder Singh
443a8bd581dSJasvinder Singh static inline void
thread_msg_send(struct rte_ring * msgq_rsp,struct thread_msg_rsp * rsp)444a8bd581dSJasvinder Singh thread_msg_send(struct rte_ring *msgq_rsp,
445a8bd581dSJasvinder Singh struct thread_msg_rsp *rsp)
446a8bd581dSJasvinder Singh {
447a8bd581dSJasvinder Singh int status;
448a8bd581dSJasvinder Singh
449a8bd581dSJasvinder Singh do {
450a8bd581dSJasvinder Singh status = rte_ring_sp_enqueue(msgq_rsp, rsp);
451a8bd581dSJasvinder Singh } while (status == -ENOBUFS);
452a8bd581dSJasvinder Singh }
453a8bd581dSJasvinder Singh
45432e5d9b1SJasvinder Singh static struct thread_msg_rsp *
thread_msg_handle_pipeline_enable(struct thread_data * t,struct thread_msg_req * req)45532e5d9b1SJasvinder Singh thread_msg_handle_pipeline_enable(struct thread_data *t,
45632e5d9b1SJasvinder Singh struct thread_msg_req *req)
45732e5d9b1SJasvinder Singh {
45832e5d9b1SJasvinder Singh struct thread_msg_rsp *rsp = (struct thread_msg_rsp *) req;
45932e5d9b1SJasvinder Singh struct pipeline_data *p = &t->pipeline_data[t->n_pipelines];
46032e5d9b1SJasvinder Singh uint32_t i;
46132e5d9b1SJasvinder Singh
46232e5d9b1SJasvinder Singh /* Request */
46332e5d9b1SJasvinder Singh if (t->n_pipelines >= THREAD_PIPELINES_MAX) {
46432e5d9b1SJasvinder Singh rsp->status = -1;
46532e5d9b1SJasvinder Singh return rsp;
46632e5d9b1SJasvinder Singh }
46732e5d9b1SJasvinder Singh
46832e5d9b1SJasvinder Singh t->p[t->n_pipelines] = req->pipeline_enable.p;
46932e5d9b1SJasvinder Singh
47032e5d9b1SJasvinder Singh p->p = req->pipeline_enable.p;
47132e5d9b1SJasvinder Singh for (i = 0; i < req->pipeline_enable.n_tables; i++)
47232e5d9b1SJasvinder Singh p->table_data[i].a =
47332e5d9b1SJasvinder Singh req->pipeline_enable.table[i].a;
47432e5d9b1SJasvinder Singh
47532e5d9b1SJasvinder Singh p->n_tables = req->pipeline_enable.n_tables;
47632e5d9b1SJasvinder Singh
47732e5d9b1SJasvinder Singh p->msgq_req = req->pipeline_enable.msgq_req;
47832e5d9b1SJasvinder Singh p->msgq_rsp = req->pipeline_enable.msgq_rsp;
47932e5d9b1SJasvinder Singh p->timer_period =
48032e5d9b1SJasvinder Singh (rte_get_tsc_hz() * req->pipeline_enable.timer_period_ms) / 1000;
48132e5d9b1SJasvinder Singh p->time_next = rte_get_tsc_cycles() + p->timer_period;
48232e5d9b1SJasvinder Singh
48332e5d9b1SJasvinder Singh t->n_pipelines++;
48432e5d9b1SJasvinder Singh
48532e5d9b1SJasvinder Singh /* Response */
48632e5d9b1SJasvinder Singh rsp->status = 0;
48732e5d9b1SJasvinder Singh return rsp;
48832e5d9b1SJasvinder Singh }
48932e5d9b1SJasvinder Singh
49032e5d9b1SJasvinder Singh static struct thread_msg_rsp *
thread_msg_handle_pipeline_disable(struct thread_data * t,struct thread_msg_req * req)49132e5d9b1SJasvinder Singh thread_msg_handle_pipeline_disable(struct thread_data *t,
49232e5d9b1SJasvinder Singh struct thread_msg_req *req)
49332e5d9b1SJasvinder Singh {
49432e5d9b1SJasvinder Singh struct thread_msg_rsp *rsp = (struct thread_msg_rsp *) req;
49532e5d9b1SJasvinder Singh uint32_t n_pipelines = t->n_pipelines;
49632e5d9b1SJasvinder Singh struct rte_pipeline *pipeline = req->pipeline_disable.p;
49732e5d9b1SJasvinder Singh uint32_t i;
49832e5d9b1SJasvinder Singh
49932e5d9b1SJasvinder Singh /* find pipeline */
50032e5d9b1SJasvinder Singh for (i = 0; i < n_pipelines; i++) {
50132e5d9b1SJasvinder Singh struct pipeline_data *p = &t->pipeline_data[i];
50232e5d9b1SJasvinder Singh
50332e5d9b1SJasvinder Singh if (p->p != pipeline)
50432e5d9b1SJasvinder Singh continue;
50532e5d9b1SJasvinder Singh
50632e5d9b1SJasvinder Singh if (i < n_pipelines - 1) {
50732e5d9b1SJasvinder Singh struct rte_pipeline *pipeline_last =
50832e5d9b1SJasvinder Singh t->p[n_pipelines - 1];
50932e5d9b1SJasvinder Singh struct pipeline_data *p_last =
51032e5d9b1SJasvinder Singh &t->pipeline_data[n_pipelines - 1];
51132e5d9b1SJasvinder Singh
51232e5d9b1SJasvinder Singh t->p[i] = pipeline_last;
51332e5d9b1SJasvinder Singh memcpy(p, p_last, sizeof(*p));
51432e5d9b1SJasvinder Singh }
51532e5d9b1SJasvinder Singh
51632e5d9b1SJasvinder Singh t->n_pipelines--;
51732e5d9b1SJasvinder Singh
51832e5d9b1SJasvinder Singh rsp->status = 0;
51932e5d9b1SJasvinder Singh return rsp;
52032e5d9b1SJasvinder Singh }
52132e5d9b1SJasvinder Singh
52232e5d9b1SJasvinder Singh /* should not get here */
52332e5d9b1SJasvinder Singh rsp->status = 0;
52432e5d9b1SJasvinder Singh return rsp;
52532e5d9b1SJasvinder Singh }
52632e5d9b1SJasvinder Singh
527a8bd581dSJasvinder Singh static void
thread_msg_handle(struct thread_data * t)528a8bd581dSJasvinder Singh thread_msg_handle(struct thread_data *t)
529a8bd581dSJasvinder Singh {
530a8bd581dSJasvinder Singh for ( ; ; ) {
531a8bd581dSJasvinder Singh struct thread_msg_req *req;
532a8bd581dSJasvinder Singh struct thread_msg_rsp *rsp;
533a8bd581dSJasvinder Singh
534a8bd581dSJasvinder Singh req = thread_msg_recv(t->msgq_req);
535a8bd581dSJasvinder Singh if (req == NULL)
536a8bd581dSJasvinder Singh break;
537a8bd581dSJasvinder Singh
538a8bd581dSJasvinder Singh switch (req->type) {
53932e5d9b1SJasvinder Singh case THREAD_REQ_PIPELINE_ENABLE:
54032e5d9b1SJasvinder Singh rsp = thread_msg_handle_pipeline_enable(t, req);
54132e5d9b1SJasvinder Singh break;
54232e5d9b1SJasvinder Singh
54332e5d9b1SJasvinder Singh case THREAD_REQ_PIPELINE_DISABLE:
54432e5d9b1SJasvinder Singh rsp = thread_msg_handle_pipeline_disable(t, req);
54532e5d9b1SJasvinder Singh break;
54632e5d9b1SJasvinder Singh
547a8bd581dSJasvinder Singh default:
548a8bd581dSJasvinder Singh rsp = (struct thread_msg_rsp *) req;
549a8bd581dSJasvinder Singh rsp->status = -1;
550a8bd581dSJasvinder Singh }
551a8bd581dSJasvinder Singh
552a8bd581dSJasvinder Singh thread_msg_send(t->msgq_rsp, rsp);
553a8bd581dSJasvinder Singh }
554a8bd581dSJasvinder Singh }
555a8bd581dSJasvinder Singh
556a8bd581dSJasvinder Singh /**
557*cb056611SStephen Hemminger * Main thread & data plane threads: message passing
558a8bd581dSJasvinder Singh */
559a8bd581dSJasvinder Singh enum pipeline_req_type {
5606b1b3c3cSJasvinder Singh /* Port IN */
56150e73d05SJasvinder Singh PIPELINE_REQ_PORT_IN_STATS_READ,
5626b1b3c3cSJasvinder Singh PIPELINE_REQ_PORT_IN_ENABLE,
5636b1b3c3cSJasvinder Singh PIPELINE_REQ_PORT_IN_DISABLE,
5646b1b3c3cSJasvinder Singh
56550e73d05SJasvinder Singh /* Port OUT */
56650e73d05SJasvinder Singh PIPELINE_REQ_PORT_OUT_STATS_READ,
56750e73d05SJasvinder Singh
56850e73d05SJasvinder Singh /* Table */
56950e73d05SJasvinder Singh PIPELINE_REQ_TABLE_STATS_READ,
570a3a95b7dSJasvinder Singh PIPELINE_REQ_TABLE_RULE_ADD,
571a3a95b7dSJasvinder Singh PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT,
5723186282fSJasvinder Singh PIPELINE_REQ_TABLE_RULE_ADD_BULK,
573f634e4c5SJasvinder Singh PIPELINE_REQ_TABLE_RULE_DELETE,
574f634e4c5SJasvinder Singh PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT,
575c64b9121SJasvinder Singh PIPELINE_REQ_TABLE_RULE_STATS_READ,
5767e11393eSJasvinder Singh PIPELINE_REQ_TABLE_MTR_PROFILE_ADD,
5777e11393eSJasvinder Singh PIPELINE_REQ_TABLE_MTR_PROFILE_DELETE,
578e92058d6SJasvinder Singh PIPELINE_REQ_TABLE_RULE_MTR_READ,
5792b82ef48SJasvinder Singh PIPELINE_REQ_TABLE_DSCP_TABLE_UPDATE,
580d0d306c7SJasvinder Singh PIPELINE_REQ_TABLE_RULE_TTL_READ,
581a3169ee5SCristian Dumitrescu PIPELINE_REQ_TABLE_RULE_TIME_READ,
582a8bd581dSJasvinder Singh PIPELINE_REQ_MAX
583a8bd581dSJasvinder Singh };
584a8bd581dSJasvinder Singh
58550e73d05SJasvinder Singh struct pipeline_msg_req_port_in_stats_read {
58650e73d05SJasvinder Singh int clear;
58750e73d05SJasvinder Singh };
58850e73d05SJasvinder Singh
58950e73d05SJasvinder Singh struct pipeline_msg_req_port_out_stats_read {
59050e73d05SJasvinder Singh int clear;
59150e73d05SJasvinder Singh };
59250e73d05SJasvinder Singh
59350e73d05SJasvinder Singh struct pipeline_msg_req_table_stats_read {
59450e73d05SJasvinder Singh int clear;
59550e73d05SJasvinder Singh };
59650e73d05SJasvinder Singh
597a3a95b7dSJasvinder Singh struct pipeline_msg_req_table_rule_add {
598a3a95b7dSJasvinder Singh struct table_rule_match match;
599a3a95b7dSJasvinder Singh struct table_rule_action action;
600a3a95b7dSJasvinder Singh };
601a3a95b7dSJasvinder Singh
602a3a95b7dSJasvinder Singh struct pipeline_msg_req_table_rule_add_default {
603a3a95b7dSJasvinder Singh struct table_rule_action action;
604a3a95b7dSJasvinder Singh };
605a3a95b7dSJasvinder Singh
6063186282fSJasvinder Singh struct pipeline_msg_req_table_rule_add_bulk {
60727b333b2SCristian Dumitrescu struct table_rule_list *list;
6083186282fSJasvinder Singh int bulk;
6093186282fSJasvinder Singh };
6103186282fSJasvinder Singh
611f634e4c5SJasvinder Singh struct pipeline_msg_req_table_rule_delete {
612f634e4c5SJasvinder Singh struct table_rule_match match;
613f634e4c5SJasvinder Singh };
614f634e4c5SJasvinder Singh
615c64b9121SJasvinder Singh struct pipeline_msg_req_table_rule_stats_read {
616c64b9121SJasvinder Singh void *data;
617c64b9121SJasvinder Singh int clear;
618c64b9121SJasvinder Singh };
619c64b9121SJasvinder Singh
6207e11393eSJasvinder Singh struct pipeline_msg_req_table_mtr_profile_add {
6217e11393eSJasvinder Singh uint32_t meter_profile_id;
6227e11393eSJasvinder Singh struct rte_table_action_meter_profile profile;
6237e11393eSJasvinder Singh };
6247e11393eSJasvinder Singh
6257e11393eSJasvinder Singh struct pipeline_msg_req_table_mtr_profile_delete {
6267e11393eSJasvinder Singh uint32_t meter_profile_id;
6277e11393eSJasvinder Singh };
6287e11393eSJasvinder Singh
629e92058d6SJasvinder Singh struct pipeline_msg_req_table_rule_mtr_read {
630e92058d6SJasvinder Singh void *data;
631e92058d6SJasvinder Singh uint32_t tc_mask;
632e92058d6SJasvinder Singh int clear;
633e92058d6SJasvinder Singh };
6342b82ef48SJasvinder Singh
6352b82ef48SJasvinder Singh struct pipeline_msg_req_table_dscp_table_update {
6362b82ef48SJasvinder Singh uint64_t dscp_mask;
6372b82ef48SJasvinder Singh struct rte_table_action_dscp_table dscp_table;
6382b82ef48SJasvinder Singh };
6392b82ef48SJasvinder Singh
640d0d306c7SJasvinder Singh struct pipeline_msg_req_table_rule_ttl_read {
641d0d306c7SJasvinder Singh void *data;
642d0d306c7SJasvinder Singh int clear;
643d0d306c7SJasvinder Singh };
644d0d306c7SJasvinder Singh
645a3169ee5SCristian Dumitrescu struct pipeline_msg_req_table_rule_time_read {
646a3169ee5SCristian Dumitrescu void *data;
647a3169ee5SCristian Dumitrescu };
648a3169ee5SCristian Dumitrescu
649a8bd581dSJasvinder Singh struct pipeline_msg_req {
650a8bd581dSJasvinder Singh enum pipeline_req_type type;
6516b1b3c3cSJasvinder Singh uint32_t id; /* Port IN, port OUT or table ID */
65250e73d05SJasvinder Singh
65350e73d05SJasvinder Singh RTE_STD_C11
65450e73d05SJasvinder Singh union {
65550e73d05SJasvinder Singh struct pipeline_msg_req_port_in_stats_read port_in_stats_read;
65650e73d05SJasvinder Singh struct pipeline_msg_req_port_out_stats_read port_out_stats_read;
65750e73d05SJasvinder Singh struct pipeline_msg_req_table_stats_read table_stats_read;
658a3a95b7dSJasvinder Singh struct pipeline_msg_req_table_rule_add table_rule_add;
659a3a95b7dSJasvinder Singh struct pipeline_msg_req_table_rule_add_default table_rule_add_default;
6603186282fSJasvinder Singh struct pipeline_msg_req_table_rule_add_bulk table_rule_add_bulk;
661f634e4c5SJasvinder Singh struct pipeline_msg_req_table_rule_delete table_rule_delete;
662c64b9121SJasvinder Singh struct pipeline_msg_req_table_rule_stats_read table_rule_stats_read;
6637e11393eSJasvinder Singh struct pipeline_msg_req_table_mtr_profile_add table_mtr_profile_add;
6647e11393eSJasvinder Singh struct pipeline_msg_req_table_mtr_profile_delete table_mtr_profile_delete;
665e92058d6SJasvinder Singh struct pipeline_msg_req_table_rule_mtr_read table_rule_mtr_read;
6662b82ef48SJasvinder Singh struct pipeline_msg_req_table_dscp_table_update table_dscp_table_update;
667d0d306c7SJasvinder Singh struct pipeline_msg_req_table_rule_ttl_read table_rule_ttl_read;
668a3169ee5SCristian Dumitrescu struct pipeline_msg_req_table_rule_time_read table_rule_time_read;
66950e73d05SJasvinder Singh };
67050e73d05SJasvinder Singh };
67150e73d05SJasvinder Singh
67250e73d05SJasvinder Singh struct pipeline_msg_rsp_port_in_stats_read {
67350e73d05SJasvinder Singh struct rte_pipeline_port_in_stats stats;
67450e73d05SJasvinder Singh };
67550e73d05SJasvinder Singh
67650e73d05SJasvinder Singh struct pipeline_msg_rsp_port_out_stats_read {
67750e73d05SJasvinder Singh struct rte_pipeline_port_out_stats stats;
67850e73d05SJasvinder Singh };
67950e73d05SJasvinder Singh
68050e73d05SJasvinder Singh struct pipeline_msg_rsp_table_stats_read {
68150e73d05SJasvinder Singh struct rte_pipeline_table_stats stats;
682a8bd581dSJasvinder Singh };
683a8bd581dSJasvinder Singh
684a3a95b7dSJasvinder Singh struct pipeline_msg_rsp_table_rule_add {
685a3a95b7dSJasvinder Singh void *data;
686a3a95b7dSJasvinder Singh };
687a3a95b7dSJasvinder Singh
688a3a95b7dSJasvinder Singh struct pipeline_msg_rsp_table_rule_add_default {
689a3a95b7dSJasvinder Singh void *data;
690a3a95b7dSJasvinder Singh };
691a3a95b7dSJasvinder Singh
6923186282fSJasvinder Singh struct pipeline_msg_rsp_table_rule_add_bulk {
6933186282fSJasvinder Singh uint32_t n_rules;
6943186282fSJasvinder Singh };
6953186282fSJasvinder Singh
696c64b9121SJasvinder Singh struct pipeline_msg_rsp_table_rule_stats_read {
697c64b9121SJasvinder Singh struct rte_table_action_stats_counters stats;
698c64b9121SJasvinder Singh };
699c64b9121SJasvinder Singh
700e92058d6SJasvinder Singh struct pipeline_msg_rsp_table_rule_mtr_read {
701e92058d6SJasvinder Singh struct rte_table_action_mtr_counters stats;
702e92058d6SJasvinder Singh };
703e92058d6SJasvinder Singh
704d0d306c7SJasvinder Singh struct pipeline_msg_rsp_table_rule_ttl_read {
705d0d306c7SJasvinder Singh struct rte_table_action_ttl_counters stats;
706d0d306c7SJasvinder Singh };
707d0d306c7SJasvinder Singh
708a3169ee5SCristian Dumitrescu struct pipeline_msg_rsp_table_rule_time_read {
709a3169ee5SCristian Dumitrescu uint64_t timestamp;
710a3169ee5SCristian Dumitrescu };
711a3169ee5SCristian Dumitrescu
712a8bd581dSJasvinder Singh struct pipeline_msg_rsp {
713a8bd581dSJasvinder Singh int status;
71450e73d05SJasvinder Singh
71550e73d05SJasvinder Singh RTE_STD_C11
71650e73d05SJasvinder Singh union {
71750e73d05SJasvinder Singh struct pipeline_msg_rsp_port_in_stats_read port_in_stats_read;
71850e73d05SJasvinder Singh struct pipeline_msg_rsp_port_out_stats_read port_out_stats_read;
71950e73d05SJasvinder Singh struct pipeline_msg_rsp_table_stats_read table_stats_read;
720a3a95b7dSJasvinder Singh struct pipeline_msg_rsp_table_rule_add table_rule_add;
721a3a95b7dSJasvinder Singh struct pipeline_msg_rsp_table_rule_add_default table_rule_add_default;
7223186282fSJasvinder Singh struct pipeline_msg_rsp_table_rule_add_bulk table_rule_add_bulk;
723c64b9121SJasvinder Singh struct pipeline_msg_rsp_table_rule_stats_read table_rule_stats_read;
724e92058d6SJasvinder Singh struct pipeline_msg_rsp_table_rule_mtr_read table_rule_mtr_read;
725d0d306c7SJasvinder Singh struct pipeline_msg_rsp_table_rule_ttl_read table_rule_ttl_read;
726a3169ee5SCristian Dumitrescu struct pipeline_msg_rsp_table_rule_time_read table_rule_time_read;
72750e73d05SJasvinder Singh };
728a8bd581dSJasvinder Singh };
729a8bd581dSJasvinder Singh
730a8bd581dSJasvinder Singh /**
731*cb056611SStephen Hemminger * Main thread
7326b1b3c3cSJasvinder Singh */
7336b1b3c3cSJasvinder Singh static struct pipeline_msg_req *
pipeline_msg_alloc(void)7346b1b3c3cSJasvinder Singh pipeline_msg_alloc(void)
7356b1b3c3cSJasvinder Singh {
7366b1b3c3cSJasvinder Singh size_t size = RTE_MAX(sizeof(struct pipeline_msg_req),
7376b1b3c3cSJasvinder Singh sizeof(struct pipeline_msg_rsp));
7386b1b3c3cSJasvinder Singh
7396b1b3c3cSJasvinder Singh return calloc(1, size);
7406b1b3c3cSJasvinder Singh }
7416b1b3c3cSJasvinder Singh
7426b1b3c3cSJasvinder Singh static void
pipeline_msg_free(struct pipeline_msg_rsp * rsp)7436b1b3c3cSJasvinder Singh pipeline_msg_free(struct pipeline_msg_rsp *rsp)
7446b1b3c3cSJasvinder Singh {
7456b1b3c3cSJasvinder Singh free(rsp);
7466b1b3c3cSJasvinder Singh }
7476b1b3c3cSJasvinder Singh
7486b1b3c3cSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_send_recv(struct pipeline * p,struct pipeline_msg_req * req)7496b1b3c3cSJasvinder Singh pipeline_msg_send_recv(struct pipeline *p,
7506b1b3c3cSJasvinder Singh struct pipeline_msg_req *req)
7516b1b3c3cSJasvinder Singh {
7526b1b3c3cSJasvinder Singh struct rte_ring *msgq_req = p->msgq_req;
7536b1b3c3cSJasvinder Singh struct rte_ring *msgq_rsp = p->msgq_rsp;
7546b1b3c3cSJasvinder Singh struct pipeline_msg_rsp *rsp;
7556b1b3c3cSJasvinder Singh int status;
7566b1b3c3cSJasvinder Singh
7576b1b3c3cSJasvinder Singh /* send */
7586b1b3c3cSJasvinder Singh do {
7596b1b3c3cSJasvinder Singh status = rte_ring_sp_enqueue(msgq_req, req);
7606b1b3c3cSJasvinder Singh } while (status == -ENOBUFS);
7616b1b3c3cSJasvinder Singh
7626b1b3c3cSJasvinder Singh /* recv */
7636b1b3c3cSJasvinder Singh do {
7646b1b3c3cSJasvinder Singh status = rte_ring_sc_dequeue(msgq_rsp, (void **) &rsp);
7656b1b3c3cSJasvinder Singh } while (status != 0);
7666b1b3c3cSJasvinder Singh
7676b1b3c3cSJasvinder Singh return rsp;
7686b1b3c3cSJasvinder Singh }
7696b1b3c3cSJasvinder Singh
7706b1b3c3cSJasvinder Singh int
pipeline_port_in_stats_read(const char * pipeline_name,uint32_t port_id,struct rte_pipeline_port_in_stats * stats,int clear)77150e73d05SJasvinder Singh pipeline_port_in_stats_read(const char *pipeline_name,
77250e73d05SJasvinder Singh uint32_t port_id,
77350e73d05SJasvinder Singh struct rte_pipeline_port_in_stats *stats,
77450e73d05SJasvinder Singh int clear)
77550e73d05SJasvinder Singh {
77650e73d05SJasvinder Singh struct pipeline *p;
77750e73d05SJasvinder Singh struct pipeline_msg_req *req;
77850e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp;
77950e73d05SJasvinder Singh int status;
78050e73d05SJasvinder Singh
78150e73d05SJasvinder Singh /* Check input params */
78250e73d05SJasvinder Singh if ((pipeline_name == NULL) ||
78350e73d05SJasvinder Singh (stats == NULL))
78450e73d05SJasvinder Singh return -1;
78550e73d05SJasvinder Singh
78650e73d05SJasvinder Singh p = pipeline_find(pipeline_name);
78750e73d05SJasvinder Singh if ((p == NULL) ||
78850e73d05SJasvinder Singh (port_id >= p->n_ports_in))
78950e73d05SJasvinder Singh return -1;
79050e73d05SJasvinder Singh
791f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
792f68a1d3fSJasvinder Singh status = rte_pipeline_port_in_stats_read(p->p,
793f68a1d3fSJasvinder Singh port_id,
794f68a1d3fSJasvinder Singh stats,
795f68a1d3fSJasvinder Singh clear);
796f68a1d3fSJasvinder Singh
797f68a1d3fSJasvinder Singh return status;
798f68a1d3fSJasvinder Singh }
799f68a1d3fSJasvinder Singh
80050e73d05SJasvinder Singh /* Allocate request */
80150e73d05SJasvinder Singh req = pipeline_msg_alloc();
80250e73d05SJasvinder Singh if (req == NULL)
80350e73d05SJasvinder Singh return -1;
80450e73d05SJasvinder Singh
80550e73d05SJasvinder Singh /* Write request */
80650e73d05SJasvinder Singh req->type = PIPELINE_REQ_PORT_IN_STATS_READ;
80750e73d05SJasvinder Singh req->id = port_id;
80850e73d05SJasvinder Singh req->port_in_stats_read.clear = clear;
80950e73d05SJasvinder Singh
81050e73d05SJasvinder Singh /* Send request and wait for response */
81150e73d05SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
81250e73d05SJasvinder Singh
81350e73d05SJasvinder Singh /* Read response */
81450e73d05SJasvinder Singh status = rsp->status;
815c4160d30SCristian Dumitrescu if (status == 0)
81650e73d05SJasvinder Singh memcpy(stats, &rsp->port_in_stats_read.stats, sizeof(*stats));
81750e73d05SJasvinder Singh
81850e73d05SJasvinder Singh /* Free response */
81950e73d05SJasvinder Singh pipeline_msg_free(rsp);
82050e73d05SJasvinder Singh
82150e73d05SJasvinder Singh return status;
82250e73d05SJasvinder Singh }
82350e73d05SJasvinder Singh
82450e73d05SJasvinder Singh int
pipeline_port_in_enable(const char * pipeline_name,uint32_t port_id)8256b1b3c3cSJasvinder Singh pipeline_port_in_enable(const char *pipeline_name,
8266b1b3c3cSJasvinder Singh uint32_t port_id)
8276b1b3c3cSJasvinder Singh {
8286b1b3c3cSJasvinder Singh struct pipeline *p;
8296b1b3c3cSJasvinder Singh struct pipeline_msg_req *req;
8306b1b3c3cSJasvinder Singh struct pipeline_msg_rsp *rsp;
8316b1b3c3cSJasvinder Singh int status;
8326b1b3c3cSJasvinder Singh
8336b1b3c3cSJasvinder Singh /* Check input params */
8346b1b3c3cSJasvinder Singh if (pipeline_name == NULL)
8356b1b3c3cSJasvinder Singh return -1;
8366b1b3c3cSJasvinder Singh
8376b1b3c3cSJasvinder Singh p = pipeline_find(pipeline_name);
8386b1b3c3cSJasvinder Singh if ((p == NULL) ||
8396b1b3c3cSJasvinder Singh (port_id >= p->n_ports_in))
8406b1b3c3cSJasvinder Singh return -1;
8416b1b3c3cSJasvinder Singh
842f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
843f68a1d3fSJasvinder Singh status = rte_pipeline_port_in_enable(p->p, port_id);
844f68a1d3fSJasvinder Singh return status;
845f68a1d3fSJasvinder Singh }
846f68a1d3fSJasvinder Singh
8476b1b3c3cSJasvinder Singh /* Allocate request */
8486b1b3c3cSJasvinder Singh req = pipeline_msg_alloc();
8496b1b3c3cSJasvinder Singh if (req == NULL)
8506b1b3c3cSJasvinder Singh return -1;
8516b1b3c3cSJasvinder Singh
8526b1b3c3cSJasvinder Singh /* Write request */
8536b1b3c3cSJasvinder Singh req->type = PIPELINE_REQ_PORT_IN_ENABLE;
8546b1b3c3cSJasvinder Singh req->id = port_id;
8556b1b3c3cSJasvinder Singh
8566b1b3c3cSJasvinder Singh /* Send request and wait for response */
8576b1b3c3cSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
8586b1b3c3cSJasvinder Singh
8596b1b3c3cSJasvinder Singh /* Read response */
8606b1b3c3cSJasvinder Singh status = rsp->status;
8616b1b3c3cSJasvinder Singh
8626b1b3c3cSJasvinder Singh /* Free response */
8636b1b3c3cSJasvinder Singh pipeline_msg_free(rsp);
8646b1b3c3cSJasvinder Singh
8656b1b3c3cSJasvinder Singh return status;
8666b1b3c3cSJasvinder Singh }
8676b1b3c3cSJasvinder Singh
8686b1b3c3cSJasvinder Singh int
pipeline_port_in_disable(const char * pipeline_name,uint32_t port_id)8696b1b3c3cSJasvinder Singh pipeline_port_in_disable(const char *pipeline_name,
8706b1b3c3cSJasvinder Singh uint32_t port_id)
8716b1b3c3cSJasvinder Singh {
8726b1b3c3cSJasvinder Singh struct pipeline *p;
8736b1b3c3cSJasvinder Singh struct pipeline_msg_req *req;
8746b1b3c3cSJasvinder Singh struct pipeline_msg_rsp *rsp;
8756b1b3c3cSJasvinder Singh int status;
8766b1b3c3cSJasvinder Singh
8776b1b3c3cSJasvinder Singh /* Check input params */
8786b1b3c3cSJasvinder Singh if (pipeline_name == NULL)
8796b1b3c3cSJasvinder Singh return -1;
8806b1b3c3cSJasvinder Singh
8816b1b3c3cSJasvinder Singh p = pipeline_find(pipeline_name);
8826b1b3c3cSJasvinder Singh if ((p == NULL) ||
8836b1b3c3cSJasvinder Singh (port_id >= p->n_ports_in))
8846b1b3c3cSJasvinder Singh return -1;
8856b1b3c3cSJasvinder Singh
886f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
887f68a1d3fSJasvinder Singh status = rte_pipeline_port_in_disable(p->p, port_id);
888f68a1d3fSJasvinder Singh return status;
889f68a1d3fSJasvinder Singh }
890f68a1d3fSJasvinder Singh
8916b1b3c3cSJasvinder Singh /* Allocate request */
8926b1b3c3cSJasvinder Singh req = pipeline_msg_alloc();
8936b1b3c3cSJasvinder Singh if (req == NULL)
8946b1b3c3cSJasvinder Singh return -1;
8956b1b3c3cSJasvinder Singh
8966b1b3c3cSJasvinder Singh /* Write request */
8976b1b3c3cSJasvinder Singh req->type = PIPELINE_REQ_PORT_IN_DISABLE;
8986b1b3c3cSJasvinder Singh req->id = port_id;
8996b1b3c3cSJasvinder Singh
9006b1b3c3cSJasvinder Singh /* Send request and wait for response */
9016b1b3c3cSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
9026b1b3c3cSJasvinder Singh
9036b1b3c3cSJasvinder Singh /* Read response */
9046b1b3c3cSJasvinder Singh status = rsp->status;
9056b1b3c3cSJasvinder Singh
9066b1b3c3cSJasvinder Singh /* Free response */
9076b1b3c3cSJasvinder Singh pipeline_msg_free(rsp);
9086b1b3c3cSJasvinder Singh
9096b1b3c3cSJasvinder Singh return status;
9106b1b3c3cSJasvinder Singh }
9116b1b3c3cSJasvinder Singh
91250e73d05SJasvinder Singh int
pipeline_port_out_stats_read(const char * pipeline_name,uint32_t port_id,struct rte_pipeline_port_out_stats * stats,int clear)91350e73d05SJasvinder Singh pipeline_port_out_stats_read(const char *pipeline_name,
91450e73d05SJasvinder Singh uint32_t port_id,
91550e73d05SJasvinder Singh struct rte_pipeline_port_out_stats *stats,
91650e73d05SJasvinder Singh int clear)
91750e73d05SJasvinder Singh {
91850e73d05SJasvinder Singh struct pipeline *p;
91950e73d05SJasvinder Singh struct pipeline_msg_req *req;
92050e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp;
92150e73d05SJasvinder Singh int status;
92250e73d05SJasvinder Singh
92350e73d05SJasvinder Singh /* Check input params */
92450e73d05SJasvinder Singh if ((pipeline_name == NULL) ||
92550e73d05SJasvinder Singh (stats == NULL))
92650e73d05SJasvinder Singh return -1;
92750e73d05SJasvinder Singh
92850e73d05SJasvinder Singh p = pipeline_find(pipeline_name);
92950e73d05SJasvinder Singh if ((p == NULL) ||
93050e73d05SJasvinder Singh (port_id >= p->n_ports_out))
93150e73d05SJasvinder Singh return -1;
93250e73d05SJasvinder Singh
933f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
934f68a1d3fSJasvinder Singh status = rte_pipeline_port_out_stats_read(p->p,
935f68a1d3fSJasvinder Singh port_id,
936f68a1d3fSJasvinder Singh stats,
937f68a1d3fSJasvinder Singh clear);
938f68a1d3fSJasvinder Singh
939f68a1d3fSJasvinder Singh return status;
940f68a1d3fSJasvinder Singh }
941f68a1d3fSJasvinder Singh
94250e73d05SJasvinder Singh /* Allocate request */
94350e73d05SJasvinder Singh req = pipeline_msg_alloc();
94450e73d05SJasvinder Singh if (req == NULL)
94550e73d05SJasvinder Singh return -1;
94650e73d05SJasvinder Singh
94750e73d05SJasvinder Singh /* Write request */
94850e73d05SJasvinder Singh req->type = PIPELINE_REQ_PORT_OUT_STATS_READ;
94950e73d05SJasvinder Singh req->id = port_id;
95050e73d05SJasvinder Singh req->port_out_stats_read.clear = clear;
95150e73d05SJasvinder Singh
95250e73d05SJasvinder Singh /* Send request and wait for response */
95350e73d05SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
95450e73d05SJasvinder Singh
95550e73d05SJasvinder Singh /* Read response */
95650e73d05SJasvinder Singh status = rsp->status;
957c4160d30SCristian Dumitrescu if (status == 0)
95850e73d05SJasvinder Singh memcpy(stats, &rsp->port_out_stats_read.stats, sizeof(*stats));
95950e73d05SJasvinder Singh
96050e73d05SJasvinder Singh /* Free response */
96150e73d05SJasvinder Singh pipeline_msg_free(rsp);
96250e73d05SJasvinder Singh
96350e73d05SJasvinder Singh return status;
96450e73d05SJasvinder Singh }
96550e73d05SJasvinder Singh
96650e73d05SJasvinder Singh int
pipeline_table_stats_read(const char * pipeline_name,uint32_t table_id,struct rte_pipeline_table_stats * stats,int clear)96750e73d05SJasvinder Singh pipeline_table_stats_read(const char *pipeline_name,
96850e73d05SJasvinder Singh uint32_t table_id,
96950e73d05SJasvinder Singh struct rte_pipeline_table_stats *stats,
97050e73d05SJasvinder Singh int clear)
97150e73d05SJasvinder Singh {
97250e73d05SJasvinder Singh struct pipeline *p;
97350e73d05SJasvinder Singh struct pipeline_msg_req *req;
97450e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp;
97550e73d05SJasvinder Singh int status;
97650e73d05SJasvinder Singh
97750e73d05SJasvinder Singh /* Check input params */
97850e73d05SJasvinder Singh if ((pipeline_name == NULL) ||
97950e73d05SJasvinder Singh (stats == NULL))
98050e73d05SJasvinder Singh return -1;
98150e73d05SJasvinder Singh
98250e73d05SJasvinder Singh p = pipeline_find(pipeline_name);
98350e73d05SJasvinder Singh if ((p == NULL) ||
98450e73d05SJasvinder Singh (table_id >= p->n_tables))
98550e73d05SJasvinder Singh return -1;
98650e73d05SJasvinder Singh
987f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
988f68a1d3fSJasvinder Singh status = rte_pipeline_table_stats_read(p->p,
989f68a1d3fSJasvinder Singh table_id,
990f68a1d3fSJasvinder Singh stats,
991f68a1d3fSJasvinder Singh clear);
992f68a1d3fSJasvinder Singh
993f68a1d3fSJasvinder Singh return status;
994f68a1d3fSJasvinder Singh }
995f68a1d3fSJasvinder Singh
99650e73d05SJasvinder Singh /* Allocate request */
99750e73d05SJasvinder Singh req = pipeline_msg_alloc();
99850e73d05SJasvinder Singh if (req == NULL)
99950e73d05SJasvinder Singh return -1;
100050e73d05SJasvinder Singh
100150e73d05SJasvinder Singh /* Write request */
100250e73d05SJasvinder Singh req->type = PIPELINE_REQ_TABLE_STATS_READ;
100350e73d05SJasvinder Singh req->id = table_id;
100450e73d05SJasvinder Singh req->table_stats_read.clear = clear;
100550e73d05SJasvinder Singh
100650e73d05SJasvinder Singh /* Send request and wait for response */
100750e73d05SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
100850e73d05SJasvinder Singh
100950e73d05SJasvinder Singh /* Read response */
101050e73d05SJasvinder Singh status = rsp->status;
1011c4160d30SCristian Dumitrescu if (status == 0)
101250e73d05SJasvinder Singh memcpy(stats, &rsp->table_stats_read.stats, sizeof(*stats));
101350e73d05SJasvinder Singh
101450e73d05SJasvinder Singh /* Free response */
101550e73d05SJasvinder Singh pipeline_msg_free(rsp);
101650e73d05SJasvinder Singh
101750e73d05SJasvinder Singh return status;
101850e73d05SJasvinder Singh }
10196b1b3c3cSJasvinder Singh
1020a3a95b7dSJasvinder Singh static int
match_check(struct table_rule_match * match,struct pipeline * p,uint32_t table_id)1021a3a95b7dSJasvinder Singh match_check(struct table_rule_match *match,
1022a3a95b7dSJasvinder Singh struct pipeline *p,
1023a3a95b7dSJasvinder Singh uint32_t table_id)
1024a3a95b7dSJasvinder Singh {
1025a3a95b7dSJasvinder Singh struct table *table;
1026a3a95b7dSJasvinder Singh
1027a3a95b7dSJasvinder Singh if ((match == NULL) ||
1028a3a95b7dSJasvinder Singh (p == NULL) ||
1029a3a95b7dSJasvinder Singh (table_id >= p->n_tables))
1030a3a95b7dSJasvinder Singh return -1;
1031a3a95b7dSJasvinder Singh
1032a3a95b7dSJasvinder Singh table = &p->table[table_id];
1033a3a95b7dSJasvinder Singh if (match->match_type != table->params.match_type)
1034a3a95b7dSJasvinder Singh return -1;
1035a3a95b7dSJasvinder Singh
1036a3a95b7dSJasvinder Singh switch (match->match_type) {
1037a3a95b7dSJasvinder Singh case TABLE_ACL:
1038a3a95b7dSJasvinder Singh {
1039a3a95b7dSJasvinder Singh struct table_acl_params *t = &table->params.match.acl;
1040a3a95b7dSJasvinder Singh struct table_rule_match_acl *r = &match->match.acl;
1041a3a95b7dSJasvinder Singh
1042a3a95b7dSJasvinder Singh if ((r->ip_version && (t->ip_version == 0)) ||
1043a3a95b7dSJasvinder Singh ((r->ip_version == 0) && t->ip_version))
1044a3a95b7dSJasvinder Singh return -1;
1045a3a95b7dSJasvinder Singh
1046a3a95b7dSJasvinder Singh if (r->ip_version) {
1047a3a95b7dSJasvinder Singh if ((r->sa_depth > 32) ||
1048a3a95b7dSJasvinder Singh (r->da_depth > 32))
1049a3a95b7dSJasvinder Singh return -1;
1050a3a95b7dSJasvinder Singh } else {
1051a3a95b7dSJasvinder Singh if ((r->sa_depth > 128) ||
1052a3a95b7dSJasvinder Singh (r->da_depth > 128))
1053a3a95b7dSJasvinder Singh return -1;
1054a3a95b7dSJasvinder Singh }
1055a3a95b7dSJasvinder Singh return 0;
1056a3a95b7dSJasvinder Singh }
1057a3a95b7dSJasvinder Singh
1058a3a95b7dSJasvinder Singh case TABLE_ARRAY:
1059a3a95b7dSJasvinder Singh return 0;
1060a3a95b7dSJasvinder Singh
1061a3a95b7dSJasvinder Singh case TABLE_HASH:
1062a3a95b7dSJasvinder Singh return 0;
1063a3a95b7dSJasvinder Singh
1064a3a95b7dSJasvinder Singh case TABLE_LPM:
1065a3a95b7dSJasvinder Singh {
1066a3a95b7dSJasvinder Singh struct table_lpm_params *t = &table->params.match.lpm;
1067a3a95b7dSJasvinder Singh struct table_rule_match_lpm *r = &match->match.lpm;
1068a3a95b7dSJasvinder Singh
1069a3a95b7dSJasvinder Singh if ((r->ip_version && (t->key_size != 4)) ||
1070a3a95b7dSJasvinder Singh ((r->ip_version == 0) && (t->key_size != 16)))
1071a3a95b7dSJasvinder Singh return -1;
1072a3a95b7dSJasvinder Singh
1073a3a95b7dSJasvinder Singh if (r->ip_version) {
1074a3a95b7dSJasvinder Singh if (r->depth > 32)
1075a3a95b7dSJasvinder Singh return -1;
1076a3a95b7dSJasvinder Singh } else {
1077a3a95b7dSJasvinder Singh if (r->depth > 128)
1078a3a95b7dSJasvinder Singh return -1;
1079a3a95b7dSJasvinder Singh }
1080a3a95b7dSJasvinder Singh return 0;
1081a3a95b7dSJasvinder Singh }
1082a3a95b7dSJasvinder Singh
1083a3a95b7dSJasvinder Singh case TABLE_STUB:
1084a3a95b7dSJasvinder Singh return -1;
1085a3a95b7dSJasvinder Singh
1086a3a95b7dSJasvinder Singh default:
1087a3a95b7dSJasvinder Singh return -1;
1088a3a95b7dSJasvinder Singh }
1089a3a95b7dSJasvinder Singh }
1090a3a95b7dSJasvinder Singh
1091a3a95b7dSJasvinder Singh static int
action_check(struct table_rule_action * action,struct pipeline * p,uint32_t table_id)1092a3a95b7dSJasvinder Singh action_check(struct table_rule_action *action,
1093a3a95b7dSJasvinder Singh struct pipeline *p,
1094a3a95b7dSJasvinder Singh uint32_t table_id)
1095a3a95b7dSJasvinder Singh {
1096a3a95b7dSJasvinder Singh struct table_action_profile *ap;
1097a3a95b7dSJasvinder Singh
1098a3a95b7dSJasvinder Singh if ((action == NULL) ||
1099a3a95b7dSJasvinder Singh (p == NULL) ||
1100a3a95b7dSJasvinder Singh (table_id >= p->n_tables))
1101a3a95b7dSJasvinder Singh return -1;
1102a3a95b7dSJasvinder Singh
1103a3a95b7dSJasvinder Singh ap = p->table[table_id].ap;
1104a3a95b7dSJasvinder Singh if (action->action_mask != ap->params.action_mask)
1105a3a95b7dSJasvinder Singh return -1;
1106a3a95b7dSJasvinder Singh
1107a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
1108a3a95b7dSJasvinder Singh if ((action->fwd.action == RTE_PIPELINE_ACTION_PORT) &&
1109a3a95b7dSJasvinder Singh (action->fwd.id >= p->n_ports_out))
1110a3a95b7dSJasvinder Singh return -1;
1111a3a95b7dSJasvinder Singh
1112a3a95b7dSJasvinder Singh if ((action->fwd.action == RTE_PIPELINE_ACTION_TABLE) &&
1113a3a95b7dSJasvinder Singh (action->fwd.id >= p->n_tables))
1114a3a95b7dSJasvinder Singh return -1;
1115a3a95b7dSJasvinder Singh }
1116a3a95b7dSJasvinder Singh
1117a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
1118a3a95b7dSJasvinder Singh uint32_t tc_mask0 = (1 << ap->params.mtr.n_tc) - 1;
1119a3a95b7dSJasvinder Singh uint32_t tc_mask1 = action->mtr.tc_mask;
1120a3a95b7dSJasvinder Singh
1121a3a95b7dSJasvinder Singh if (tc_mask1 != tc_mask0)
1122a3a95b7dSJasvinder Singh return -1;
1123a3a95b7dSJasvinder Singh }
1124a3a95b7dSJasvinder Singh
1125a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
1126a3a95b7dSJasvinder Singh uint32_t n_subports_per_port =
1127a3a95b7dSJasvinder Singh ap->params.tm.n_subports_per_port;
1128a3a95b7dSJasvinder Singh uint32_t n_pipes_per_subport =
1129a3a95b7dSJasvinder Singh ap->params.tm.n_pipes_per_subport;
1130a3a95b7dSJasvinder Singh uint32_t subport_id = action->tm.subport_id;
1131a3a95b7dSJasvinder Singh uint32_t pipe_id = action->tm.pipe_id;
1132a3a95b7dSJasvinder Singh
1133a3a95b7dSJasvinder Singh if ((subport_id >= n_subports_per_port) ||
1134a3a95b7dSJasvinder Singh (pipe_id >= n_pipes_per_subport))
1135a3a95b7dSJasvinder Singh return -1;
1136a3a95b7dSJasvinder Singh }
1137a3a95b7dSJasvinder Singh
1138a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
1139a3a95b7dSJasvinder Singh uint64_t encap_mask = ap->params.encap.encap_mask;
1140a3a95b7dSJasvinder Singh enum rte_table_action_encap_type type = action->encap.type;
1141a3a95b7dSJasvinder Singh
1142a3a95b7dSJasvinder Singh if ((encap_mask & (1LLU << type)) == 0)
1143a3a95b7dSJasvinder Singh return -1;
1144a3a95b7dSJasvinder Singh }
1145a3a95b7dSJasvinder Singh
1146a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
1147a3a95b7dSJasvinder Singh int ip_version0 = ap->params.common.ip_version;
1148a3a95b7dSJasvinder Singh int ip_version1 = action->nat.ip_version;
1149a3a95b7dSJasvinder Singh
1150a3a95b7dSJasvinder Singh if ((ip_version1 && (ip_version0 == 0)) ||
1151a3a95b7dSJasvinder Singh ((ip_version1 == 0) && ip_version0))
1152a3a95b7dSJasvinder Singh return -1;
1153a3a95b7dSJasvinder Singh }
1154a3a95b7dSJasvinder Singh
1155a3a95b7dSJasvinder Singh return 0;
1156a3a95b7dSJasvinder Singh }
1157a3a95b7dSJasvinder Singh
1158a3a95b7dSJasvinder Singh static int
action_default_check(struct table_rule_action * action,struct pipeline * p,uint32_t table_id)1159a3a95b7dSJasvinder Singh action_default_check(struct table_rule_action *action,
1160a3a95b7dSJasvinder Singh struct pipeline *p,
1161a3a95b7dSJasvinder Singh uint32_t table_id)
1162a3a95b7dSJasvinder Singh {
1163a3a95b7dSJasvinder Singh if ((action == NULL) ||
1164a3a95b7dSJasvinder Singh (action->action_mask != (1LLU << RTE_TABLE_ACTION_FWD)) ||
1165a3a95b7dSJasvinder Singh (p == NULL) ||
1166a3a95b7dSJasvinder Singh (table_id >= p->n_tables))
1167a3a95b7dSJasvinder Singh return -1;
1168a3a95b7dSJasvinder Singh
1169a3a95b7dSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
1170a3a95b7dSJasvinder Singh if ((action->fwd.action == RTE_PIPELINE_ACTION_PORT) &&
1171a3a95b7dSJasvinder Singh (action->fwd.id >= p->n_ports_out))
1172a3a95b7dSJasvinder Singh return -1;
1173a3a95b7dSJasvinder Singh
1174a3a95b7dSJasvinder Singh if ((action->fwd.action == RTE_PIPELINE_ACTION_TABLE) &&
1175a3a95b7dSJasvinder Singh (action->fwd.id >= p->n_tables))
1176a3a95b7dSJasvinder Singh return -1;
1177a3a95b7dSJasvinder Singh }
1178a3a95b7dSJasvinder Singh
1179a3a95b7dSJasvinder Singh return 0;
1180a3a95b7dSJasvinder Singh }
1181a3a95b7dSJasvinder Singh
1182f68a1d3fSJasvinder Singh union table_rule_match_low_level {
1183f68a1d3fSJasvinder Singh struct rte_table_acl_rule_add_params acl_add;
1184f68a1d3fSJasvinder Singh struct rte_table_acl_rule_delete_params acl_delete;
1185f68a1d3fSJasvinder Singh struct rte_table_array_key array;
1186f68a1d3fSJasvinder Singh uint8_t hash[TABLE_RULE_MATCH_SIZE_MAX];
1187f68a1d3fSJasvinder Singh struct rte_table_lpm_key lpm_ipv4;
1188f68a1d3fSJasvinder Singh struct rte_table_lpm_ipv6_key lpm_ipv6;
1189f68a1d3fSJasvinder Singh };
1190f68a1d3fSJasvinder Singh
1191f68a1d3fSJasvinder Singh static int
1192f68a1d3fSJasvinder Singh match_convert(struct table_rule_match *mh,
1193f68a1d3fSJasvinder Singh union table_rule_match_low_level *ml,
1194f68a1d3fSJasvinder Singh int add);
1195f68a1d3fSJasvinder Singh
1196f68a1d3fSJasvinder Singh static int
1197f68a1d3fSJasvinder Singh action_convert(struct rte_table_action *a,
1198f68a1d3fSJasvinder Singh struct table_rule_action *action,
1199f68a1d3fSJasvinder Singh struct rte_pipeline_table_entry *data);
1200f68a1d3fSJasvinder Singh
120127b333b2SCristian Dumitrescu struct table_ll {
120227b333b2SCristian Dumitrescu struct rte_pipeline *p;
120327b333b2SCristian Dumitrescu int table_id;
120427b333b2SCristian Dumitrescu struct rte_table_action *a;
120527b333b2SCristian Dumitrescu int bulk_supported;
120627b333b2SCristian Dumitrescu };
120727b333b2SCristian Dumitrescu
120827b333b2SCristian Dumitrescu static int
table_rule_add_bulk_ll(struct table_ll * table,struct table_rule_list * list,uint32_t * n_rules)120927b333b2SCristian Dumitrescu table_rule_add_bulk_ll(struct table_ll *table,
121027b333b2SCristian Dumitrescu struct table_rule_list *list,
121127b333b2SCristian Dumitrescu uint32_t *n_rules)
121227b333b2SCristian Dumitrescu {
121327b333b2SCristian Dumitrescu union table_rule_match_low_level *match_ll = NULL;
121427b333b2SCristian Dumitrescu uint8_t *action_ll = NULL;
121527b333b2SCristian Dumitrescu void **match_ll_ptr = NULL;
121627b333b2SCristian Dumitrescu struct rte_pipeline_table_entry **action_ll_ptr = NULL;
121727b333b2SCristian Dumitrescu struct rte_pipeline_table_entry **entries_ptr = NULL;
121827b333b2SCristian Dumitrescu int *found = NULL;
121927b333b2SCristian Dumitrescu struct table_rule *rule;
122027b333b2SCristian Dumitrescu uint32_t n, i;
122127b333b2SCristian Dumitrescu int status = 0;
122227b333b2SCristian Dumitrescu
122327b333b2SCristian Dumitrescu n = 0;
122427b333b2SCristian Dumitrescu TAILQ_FOREACH(rule, list, node)
122527b333b2SCristian Dumitrescu n++;
122627b333b2SCristian Dumitrescu
122727b333b2SCristian Dumitrescu /* Memory allocation */
122827b333b2SCristian Dumitrescu match_ll = calloc(n, sizeof(union table_rule_match_low_level));
122927b333b2SCristian Dumitrescu action_ll = calloc(n, TABLE_RULE_ACTION_SIZE_MAX);
123027b333b2SCristian Dumitrescu
123127b333b2SCristian Dumitrescu match_ll_ptr = calloc(n, sizeof(void *));
123227b333b2SCristian Dumitrescu action_ll_ptr = calloc(n, sizeof(struct rte_pipeline_table_entry *));
123327b333b2SCristian Dumitrescu
123427b333b2SCristian Dumitrescu entries_ptr = calloc(n, sizeof(struct rte_pipeline_table_entry *));
123527b333b2SCristian Dumitrescu found = calloc(n, sizeof(int));
123627b333b2SCristian Dumitrescu
123727b333b2SCristian Dumitrescu if (match_ll == NULL ||
123827b333b2SCristian Dumitrescu action_ll == NULL ||
123927b333b2SCristian Dumitrescu match_ll_ptr == NULL ||
124027b333b2SCristian Dumitrescu action_ll_ptr == NULL ||
124127b333b2SCristian Dumitrescu entries_ptr == NULL ||
124227b333b2SCristian Dumitrescu found == NULL) {
124327b333b2SCristian Dumitrescu status = -ENOMEM;
124427b333b2SCristian Dumitrescu goto table_rule_add_bulk_ll_free;
124527b333b2SCristian Dumitrescu }
124627b333b2SCristian Dumitrescu
124727b333b2SCristian Dumitrescu /* Init */
124827b333b2SCristian Dumitrescu for (i = 0; i < n; i++) {
124927b333b2SCristian Dumitrescu match_ll_ptr[i] = (void *)&match_ll[i];
125027b333b2SCristian Dumitrescu action_ll_ptr[i] = (struct rte_pipeline_table_entry *)
125127b333b2SCristian Dumitrescu &action_ll[i * TABLE_RULE_ACTION_SIZE_MAX];
125227b333b2SCristian Dumitrescu }
125327b333b2SCristian Dumitrescu
125427b333b2SCristian Dumitrescu /* Rule (match, action) conversion */
125527b333b2SCristian Dumitrescu i = 0;
125627b333b2SCristian Dumitrescu TAILQ_FOREACH(rule, list, node) {
125727b333b2SCristian Dumitrescu status = match_convert(&rule->match, match_ll_ptr[i], 1);
125827b333b2SCristian Dumitrescu if (status)
125927b333b2SCristian Dumitrescu goto table_rule_add_bulk_ll_free;
126027b333b2SCristian Dumitrescu
126127b333b2SCristian Dumitrescu status = action_convert(table->a, &rule->action, action_ll_ptr[i]);
126227b333b2SCristian Dumitrescu if (status)
126327b333b2SCristian Dumitrescu goto table_rule_add_bulk_ll_free;
126427b333b2SCristian Dumitrescu
126527b333b2SCristian Dumitrescu i++;
126627b333b2SCristian Dumitrescu }
126727b333b2SCristian Dumitrescu
126827b333b2SCristian Dumitrescu /* Add rule (match, action) to table */
126927b333b2SCristian Dumitrescu if (table->bulk_supported) {
127027b333b2SCristian Dumitrescu status = rte_pipeline_table_entry_add_bulk(table->p,
127127b333b2SCristian Dumitrescu table->table_id,
127227b333b2SCristian Dumitrescu match_ll_ptr,
127327b333b2SCristian Dumitrescu action_ll_ptr,
127427b333b2SCristian Dumitrescu n,
127527b333b2SCristian Dumitrescu found,
127627b333b2SCristian Dumitrescu entries_ptr);
127727b333b2SCristian Dumitrescu if (status)
127827b333b2SCristian Dumitrescu goto table_rule_add_bulk_ll_free;
127927b333b2SCristian Dumitrescu } else
128027b333b2SCristian Dumitrescu for (i = 0; i < n; i++) {
128127b333b2SCristian Dumitrescu status = rte_pipeline_table_entry_add(table->p,
128227b333b2SCristian Dumitrescu table->table_id,
128327b333b2SCristian Dumitrescu match_ll_ptr[i],
128427b333b2SCristian Dumitrescu action_ll_ptr[i],
128527b333b2SCristian Dumitrescu &found[i],
128627b333b2SCristian Dumitrescu &entries_ptr[i]);
128727b333b2SCristian Dumitrescu if (status) {
128827b333b2SCristian Dumitrescu if (i == 0)
128927b333b2SCristian Dumitrescu goto table_rule_add_bulk_ll_free;
129027b333b2SCristian Dumitrescu
129127b333b2SCristian Dumitrescu /* No roll-back. */
129227b333b2SCristian Dumitrescu status = 0;
129327b333b2SCristian Dumitrescu n = i;
129427b333b2SCristian Dumitrescu break;
129527b333b2SCristian Dumitrescu }
129627b333b2SCristian Dumitrescu }
129727b333b2SCristian Dumitrescu
129827b333b2SCristian Dumitrescu /* Write back to the rule list. */
129927b333b2SCristian Dumitrescu i = 0;
130027b333b2SCristian Dumitrescu TAILQ_FOREACH(rule, list, node) {
130127b333b2SCristian Dumitrescu if (i >= n)
130227b333b2SCristian Dumitrescu break;
130327b333b2SCristian Dumitrescu
130427b333b2SCristian Dumitrescu rule->data = entries_ptr[i];
130527b333b2SCristian Dumitrescu
130627b333b2SCristian Dumitrescu i++;
130727b333b2SCristian Dumitrescu }
130827b333b2SCristian Dumitrescu
130927b333b2SCristian Dumitrescu *n_rules = n;
131027b333b2SCristian Dumitrescu
131127b333b2SCristian Dumitrescu /* Free */
131227b333b2SCristian Dumitrescu table_rule_add_bulk_ll_free:
131327b333b2SCristian Dumitrescu free(found);
131427b333b2SCristian Dumitrescu free(entries_ptr);
131527b333b2SCristian Dumitrescu free(action_ll_ptr);
131627b333b2SCristian Dumitrescu free(match_ll_ptr);
131727b333b2SCristian Dumitrescu free(action_ll);
131827b333b2SCristian Dumitrescu free(match_ll);
131927b333b2SCristian Dumitrescu
132027b333b2SCristian Dumitrescu return status;
132127b333b2SCristian Dumitrescu }
132227b333b2SCristian Dumitrescu
1323a3a95b7dSJasvinder Singh int
pipeline_table_rule_add(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match,struct table_rule_action * action)1324a3a95b7dSJasvinder Singh pipeline_table_rule_add(const char *pipeline_name,
1325a3a95b7dSJasvinder Singh uint32_t table_id,
1326a3a95b7dSJasvinder Singh struct table_rule_match *match,
13274c65163eSCristian Dumitrescu struct table_rule_action *action)
1328a3a95b7dSJasvinder Singh {
1329a3a95b7dSJasvinder Singh struct pipeline *p;
13304c65163eSCristian Dumitrescu struct table *table;
1331a3a95b7dSJasvinder Singh struct pipeline_msg_req *req;
1332a3a95b7dSJasvinder Singh struct pipeline_msg_rsp *rsp;
13334c65163eSCristian Dumitrescu struct table_rule *rule;
1334a3a95b7dSJasvinder Singh int status;
1335a3a95b7dSJasvinder Singh
1336a3a95b7dSJasvinder Singh /* Check input params */
1337a3a95b7dSJasvinder Singh if ((pipeline_name == NULL) ||
1338a3a95b7dSJasvinder Singh (match == NULL) ||
13394c65163eSCristian Dumitrescu (action == NULL))
1340a3a95b7dSJasvinder Singh return -1;
1341a3a95b7dSJasvinder Singh
1342a3a95b7dSJasvinder Singh p = pipeline_find(pipeline_name);
1343a3a95b7dSJasvinder Singh if ((p == NULL) ||
1344a3a95b7dSJasvinder Singh (table_id >= p->n_tables) ||
1345a3a95b7dSJasvinder Singh match_check(match, p, table_id) ||
1346a3a95b7dSJasvinder Singh action_check(action, p, table_id))
1347a3a95b7dSJasvinder Singh return -1;
1348a3a95b7dSJasvinder Singh
13494c65163eSCristian Dumitrescu table = &p->table[table_id];
13504c65163eSCristian Dumitrescu
13514c65163eSCristian Dumitrescu rule = calloc(1, sizeof(struct table_rule));
13524c65163eSCristian Dumitrescu if (rule == NULL)
13534c65163eSCristian Dumitrescu return -1;
13544c65163eSCristian Dumitrescu
13554c65163eSCristian Dumitrescu memcpy(&rule->match, match, sizeof(*match));
13564c65163eSCristian Dumitrescu memcpy(&rule->action, action, sizeof(*action));
13574c65163eSCristian Dumitrescu
1358f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1359f68a1d3fSJasvinder Singh union table_rule_match_low_level match_ll;
1360f68a1d3fSJasvinder Singh struct rte_pipeline_table_entry *data_in, *data_out;
1361f68a1d3fSJasvinder Singh int key_found;
1362f68a1d3fSJasvinder Singh uint8_t *buffer;
1363f68a1d3fSJasvinder Singh
1364f68a1d3fSJasvinder Singh buffer = calloc(TABLE_RULE_ACTION_SIZE_MAX, sizeof(uint8_t));
13654c65163eSCristian Dumitrescu if (buffer == NULL) {
13664c65163eSCristian Dumitrescu free(rule);
1367f68a1d3fSJasvinder Singh return -1;
13684c65163eSCristian Dumitrescu }
1369f68a1d3fSJasvinder Singh
1370f68a1d3fSJasvinder Singh /* Table match-action rule conversion */
1371f68a1d3fSJasvinder Singh data_in = (struct rte_pipeline_table_entry *)buffer;
1372f68a1d3fSJasvinder Singh
1373f68a1d3fSJasvinder Singh status = match_convert(match, &match_ll, 1);
1374f68a1d3fSJasvinder Singh if (status) {
1375f68a1d3fSJasvinder Singh free(buffer);
13764c65163eSCristian Dumitrescu free(rule);
1377f68a1d3fSJasvinder Singh return -1;
1378f68a1d3fSJasvinder Singh }
1379f68a1d3fSJasvinder Singh
13804c65163eSCristian Dumitrescu status = action_convert(table->a, action, data_in);
1381f68a1d3fSJasvinder Singh if (status) {
1382f68a1d3fSJasvinder Singh free(buffer);
13834c65163eSCristian Dumitrescu free(rule);
1384f68a1d3fSJasvinder Singh return -1;
1385f68a1d3fSJasvinder Singh }
1386f68a1d3fSJasvinder Singh
1387f68a1d3fSJasvinder Singh /* Add rule (match, action) to table */
1388f68a1d3fSJasvinder Singh status = rte_pipeline_table_entry_add(p->p,
1389f68a1d3fSJasvinder Singh table_id,
1390f68a1d3fSJasvinder Singh &match_ll,
1391f68a1d3fSJasvinder Singh data_in,
1392f68a1d3fSJasvinder Singh &key_found,
1393f68a1d3fSJasvinder Singh &data_out);
1394f68a1d3fSJasvinder Singh if (status) {
1395f68a1d3fSJasvinder Singh free(buffer);
13964c65163eSCristian Dumitrescu free(rule);
1397f68a1d3fSJasvinder Singh return -1;
1398f68a1d3fSJasvinder Singh }
1399f68a1d3fSJasvinder Singh
1400f68a1d3fSJasvinder Singh /* Write Response */
14014c65163eSCristian Dumitrescu rule->data = data_out;
14024c65163eSCristian Dumitrescu table_rule_add(table, rule);
1403f68a1d3fSJasvinder Singh
1404f68a1d3fSJasvinder Singh free(buffer);
1405f68a1d3fSJasvinder Singh return 0;
1406f68a1d3fSJasvinder Singh }
1407f68a1d3fSJasvinder Singh
1408a3a95b7dSJasvinder Singh /* Allocate request */
1409a3a95b7dSJasvinder Singh req = pipeline_msg_alloc();
14104c65163eSCristian Dumitrescu if (req == NULL) {
14114c65163eSCristian Dumitrescu free(rule);
1412a3a95b7dSJasvinder Singh return -1;
14134c65163eSCristian Dumitrescu }
1414a3a95b7dSJasvinder Singh
1415a3a95b7dSJasvinder Singh /* Write request */
1416a3a95b7dSJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_ADD;
1417a3a95b7dSJasvinder Singh req->id = table_id;
1418a3a95b7dSJasvinder Singh memcpy(&req->table_rule_add.match, match, sizeof(*match));
1419a3a95b7dSJasvinder Singh memcpy(&req->table_rule_add.action, action, sizeof(*action));
1420a3a95b7dSJasvinder Singh
1421a3a95b7dSJasvinder Singh /* Send request and wait for response */
1422a3a95b7dSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
1423a3a95b7dSJasvinder Singh
1424a3a95b7dSJasvinder Singh /* Read response */
1425a3a95b7dSJasvinder Singh status = rsp->status;
14264c65163eSCristian Dumitrescu if (status == 0) {
14274c65163eSCristian Dumitrescu rule->data = rsp->table_rule_add.data;
14284c65163eSCristian Dumitrescu table_rule_add(table, rule);
14294c65163eSCristian Dumitrescu } else
14304c65163eSCristian Dumitrescu free(rule);
1431a3a95b7dSJasvinder Singh
1432a3a95b7dSJasvinder Singh /* Free response */
1433a3a95b7dSJasvinder Singh pipeline_msg_free(rsp);
1434a3a95b7dSJasvinder Singh
1435a3a95b7dSJasvinder Singh return status;
1436a3a95b7dSJasvinder Singh }
1437a3a95b7dSJasvinder Singh
1438a3a95b7dSJasvinder Singh int
pipeline_table_rule_add_default(const char * pipeline_name,uint32_t table_id,struct table_rule_action * action)1439a3a95b7dSJasvinder Singh pipeline_table_rule_add_default(const char *pipeline_name,
1440a3a95b7dSJasvinder Singh uint32_t table_id,
1441c348ec05SCristian Dumitrescu struct table_rule_action *action)
1442a3a95b7dSJasvinder Singh {
1443a3a95b7dSJasvinder Singh struct pipeline *p;
1444c348ec05SCristian Dumitrescu struct table *table;
1445a3a95b7dSJasvinder Singh struct pipeline_msg_req *req;
1446a3a95b7dSJasvinder Singh struct pipeline_msg_rsp *rsp;
1447c348ec05SCristian Dumitrescu struct table_rule *rule;
1448a3a95b7dSJasvinder Singh int status;
1449a3a95b7dSJasvinder Singh
1450a3a95b7dSJasvinder Singh /* Check input params */
1451a3a95b7dSJasvinder Singh if ((pipeline_name == NULL) ||
1452c348ec05SCristian Dumitrescu (action == NULL))
1453a3a95b7dSJasvinder Singh return -1;
1454a3a95b7dSJasvinder Singh
1455a3a95b7dSJasvinder Singh p = pipeline_find(pipeline_name);
1456a3a95b7dSJasvinder Singh if ((p == NULL) ||
1457a3a95b7dSJasvinder Singh (table_id >= p->n_tables) ||
1458a3a95b7dSJasvinder Singh action_default_check(action, p, table_id))
1459a3a95b7dSJasvinder Singh return -1;
1460a3a95b7dSJasvinder Singh
1461c348ec05SCristian Dumitrescu table = &p->table[table_id];
1462c348ec05SCristian Dumitrescu
1463c348ec05SCristian Dumitrescu rule = calloc(1, sizeof(struct table_rule));
1464c348ec05SCristian Dumitrescu if (rule == NULL)
1465c348ec05SCristian Dumitrescu return -1;
1466c348ec05SCristian Dumitrescu
1467c348ec05SCristian Dumitrescu memcpy(&rule->action, action, sizeof(*action));
1468c348ec05SCristian Dumitrescu
1469f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1470f68a1d3fSJasvinder Singh struct rte_pipeline_table_entry *data_in, *data_out;
1471f68a1d3fSJasvinder Singh uint8_t *buffer;
1472f68a1d3fSJasvinder Singh
1473f68a1d3fSJasvinder Singh buffer = calloc(TABLE_RULE_ACTION_SIZE_MAX, sizeof(uint8_t));
1474c348ec05SCristian Dumitrescu if (buffer == NULL) {
1475c348ec05SCristian Dumitrescu free(rule);
1476f68a1d3fSJasvinder Singh return -1;
1477c348ec05SCristian Dumitrescu }
1478f68a1d3fSJasvinder Singh
1479f68a1d3fSJasvinder Singh /* Apply actions */
1480f68a1d3fSJasvinder Singh data_in = (struct rte_pipeline_table_entry *)buffer;
1481f68a1d3fSJasvinder Singh
1482f68a1d3fSJasvinder Singh data_in->action = action->fwd.action;
1483f68a1d3fSJasvinder Singh if (action->fwd.action == RTE_PIPELINE_ACTION_PORT)
1484f68a1d3fSJasvinder Singh data_in->port_id = action->fwd.id;
1485f68a1d3fSJasvinder Singh if (action->fwd.action == RTE_PIPELINE_ACTION_TABLE)
1486f68a1d3fSJasvinder Singh data_in->table_id = action->fwd.id;
1487f68a1d3fSJasvinder Singh
1488f68a1d3fSJasvinder Singh /* Add default rule to table */
1489f68a1d3fSJasvinder Singh status = rte_pipeline_table_default_entry_add(p->p,
1490f68a1d3fSJasvinder Singh table_id,
1491f68a1d3fSJasvinder Singh data_in,
1492f68a1d3fSJasvinder Singh &data_out);
1493f68a1d3fSJasvinder Singh if (status) {
1494f68a1d3fSJasvinder Singh free(buffer);
1495c348ec05SCristian Dumitrescu free(rule);
1496f68a1d3fSJasvinder Singh return -1;
1497f68a1d3fSJasvinder Singh }
1498f68a1d3fSJasvinder Singh
1499f68a1d3fSJasvinder Singh /* Write Response */
1500c348ec05SCristian Dumitrescu rule->data = data_out;
1501c348ec05SCristian Dumitrescu table_rule_default_add(table, rule);
1502f68a1d3fSJasvinder Singh
1503f68a1d3fSJasvinder Singh free(buffer);
1504f68a1d3fSJasvinder Singh return 0;
1505f68a1d3fSJasvinder Singh }
1506f68a1d3fSJasvinder Singh
1507a3a95b7dSJasvinder Singh /* Allocate request */
1508a3a95b7dSJasvinder Singh req = pipeline_msg_alloc();
1509c348ec05SCristian Dumitrescu if (req == NULL) {
1510c348ec05SCristian Dumitrescu free(rule);
1511a3a95b7dSJasvinder Singh return -1;
1512c348ec05SCristian Dumitrescu }
1513a3a95b7dSJasvinder Singh
1514a3a95b7dSJasvinder Singh /* Write request */
1515a3a95b7dSJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT;
1516a3a95b7dSJasvinder Singh req->id = table_id;
1517a3a95b7dSJasvinder Singh memcpy(&req->table_rule_add_default.action, action, sizeof(*action));
1518a3a95b7dSJasvinder Singh
1519a3a95b7dSJasvinder Singh /* Send request and wait for response */
1520a3a95b7dSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
1521a3a95b7dSJasvinder Singh
1522a3a95b7dSJasvinder Singh /* Read response */
1523a3a95b7dSJasvinder Singh status = rsp->status;
1524c348ec05SCristian Dumitrescu if (status == 0) {
1525c348ec05SCristian Dumitrescu rule->data = rsp->table_rule_add_default.data;
1526c348ec05SCristian Dumitrescu table_rule_default_add(table, rule);
1527c348ec05SCristian Dumitrescu } else
1528c348ec05SCristian Dumitrescu free(rule);
1529a3a95b7dSJasvinder Singh
1530a3a95b7dSJasvinder Singh /* Free response */
1531a3a95b7dSJasvinder Singh pipeline_msg_free(rsp);
1532a3a95b7dSJasvinder Singh
1533a3a95b7dSJasvinder Singh return status;
1534a3a95b7dSJasvinder Singh }
1535a3a95b7dSJasvinder Singh
153627b333b2SCristian Dumitrescu static uint32_t
table_rule_list_free(struct table_rule_list * list)153727b333b2SCristian Dumitrescu table_rule_list_free(struct table_rule_list *list)
153827b333b2SCristian Dumitrescu {
153927b333b2SCristian Dumitrescu uint32_t n = 0;
154027b333b2SCristian Dumitrescu
154127b333b2SCristian Dumitrescu if (!list)
154227b333b2SCristian Dumitrescu return 0;
154327b333b2SCristian Dumitrescu
154427b333b2SCristian Dumitrescu for ( ; ; ) {
154527b333b2SCristian Dumitrescu struct table_rule *rule;
154627b333b2SCristian Dumitrescu
154727b333b2SCristian Dumitrescu rule = TAILQ_FIRST(list);
154827b333b2SCristian Dumitrescu if (rule == NULL)
154927b333b2SCristian Dumitrescu break;
155027b333b2SCristian Dumitrescu
155127b333b2SCristian Dumitrescu TAILQ_REMOVE(list, rule, node);
155227b333b2SCristian Dumitrescu free(rule);
155327b333b2SCristian Dumitrescu n++;
155427b333b2SCristian Dumitrescu }
155527b333b2SCristian Dumitrescu
155627b333b2SCristian Dumitrescu free(list);
155727b333b2SCristian Dumitrescu return n;
155827b333b2SCristian Dumitrescu }
155927b333b2SCristian Dumitrescu
1560f634e4c5SJasvinder Singh int
pipeline_table_rule_add_bulk(const char * pipeline_name,uint32_t table_id,struct table_rule_list * list,uint32_t * n_rules_added,uint32_t * n_rules_not_added)15613186282fSJasvinder Singh pipeline_table_rule_add_bulk(const char *pipeline_name,
15623186282fSJasvinder Singh uint32_t table_id,
156327b333b2SCristian Dumitrescu struct table_rule_list *list,
156427b333b2SCristian Dumitrescu uint32_t *n_rules_added,
156527b333b2SCristian Dumitrescu uint32_t *n_rules_not_added)
15663186282fSJasvinder Singh {
15673186282fSJasvinder Singh struct pipeline *p;
156827b333b2SCristian Dumitrescu struct table *table;
15693186282fSJasvinder Singh struct pipeline_msg_req *req;
15703186282fSJasvinder Singh struct pipeline_msg_rsp *rsp;
157127b333b2SCristian Dumitrescu struct table_rule *rule;
157227b333b2SCristian Dumitrescu int status = 0;
15733186282fSJasvinder Singh
15743186282fSJasvinder Singh /* Check input params */
15753186282fSJasvinder Singh if ((pipeline_name == NULL) ||
157627b333b2SCristian Dumitrescu (list == NULL) ||
157727b333b2SCristian Dumitrescu TAILQ_EMPTY(list) ||
157827b333b2SCristian Dumitrescu (n_rules_added == NULL) ||
157927b333b2SCristian Dumitrescu (n_rules_not_added == NULL)) {
158027b333b2SCristian Dumitrescu table_rule_list_free(list);
158127b333b2SCristian Dumitrescu return -EINVAL;
158227b333b2SCristian Dumitrescu }
15833186282fSJasvinder Singh
15843186282fSJasvinder Singh p = pipeline_find(pipeline_name);
15853186282fSJasvinder Singh if ((p == NULL) ||
158627b333b2SCristian Dumitrescu (table_id >= p->n_tables)) {
158727b333b2SCristian Dumitrescu table_rule_list_free(list);
158827b333b2SCristian Dumitrescu return -EINVAL;
158927b333b2SCristian Dumitrescu }
15903186282fSJasvinder Singh
159127b333b2SCristian Dumitrescu table = &p->table[table_id];
159227b333b2SCristian Dumitrescu
159327b333b2SCristian Dumitrescu TAILQ_FOREACH(rule, list, node)
159427b333b2SCristian Dumitrescu if (match_check(&rule->match, p, table_id) ||
159527b333b2SCristian Dumitrescu action_check(&rule->action, p, table_id)) {
159627b333b2SCristian Dumitrescu table_rule_list_free(list);
159727b333b2SCristian Dumitrescu return -EINVAL;
159827b333b2SCristian Dumitrescu }
15993186282fSJasvinder Singh
1600f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
160127b333b2SCristian Dumitrescu struct table_ll table_ll = {
160227b333b2SCristian Dumitrescu .p = p->p,
160327b333b2SCristian Dumitrescu .table_id = table_id,
160427b333b2SCristian Dumitrescu .a = table->a,
160527b333b2SCristian Dumitrescu .bulk_supported = table->params.match_type == TABLE_ACL,
160627b333b2SCristian Dumitrescu };
1607f68a1d3fSJasvinder Singh
160827b333b2SCristian Dumitrescu status = table_rule_add_bulk_ll(&table_ll, list, n_rules_added);
1609f68a1d3fSJasvinder Singh if (status) {
161027b333b2SCristian Dumitrescu table_rule_list_free(list);
1611f68a1d3fSJasvinder Singh return status;
161227b333b2SCristian Dumitrescu }
1613f68a1d3fSJasvinder Singh
161427b333b2SCristian Dumitrescu table_rule_add_bulk(table, list, *n_rules_added);
161527b333b2SCristian Dumitrescu *n_rules_not_added = table_rule_list_free(list);
161627b333b2SCristian Dumitrescu return 0;
1617f68a1d3fSJasvinder Singh }
1618f68a1d3fSJasvinder Singh
16193186282fSJasvinder Singh /* Allocate request */
16203186282fSJasvinder Singh req = pipeline_msg_alloc();
162127b333b2SCristian Dumitrescu if (req == NULL) {
162227b333b2SCristian Dumitrescu table_rule_list_free(list);
162327b333b2SCristian Dumitrescu return -ENOMEM;
162427b333b2SCristian Dumitrescu }
16253186282fSJasvinder Singh
16263186282fSJasvinder Singh /* Write request */
16273186282fSJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_ADD_BULK;
16283186282fSJasvinder Singh req->id = table_id;
162927b333b2SCristian Dumitrescu req->table_rule_add_bulk.list = list;
163027b333b2SCristian Dumitrescu req->table_rule_add_bulk.bulk = table->params.match_type == TABLE_ACL;
16313186282fSJasvinder Singh
16323186282fSJasvinder Singh /* Send request and wait for response */
16333186282fSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
16343186282fSJasvinder Singh
16353186282fSJasvinder Singh /* Read response */
16363186282fSJasvinder Singh status = rsp->status;
163727b333b2SCristian Dumitrescu if (status == 0) {
163827b333b2SCristian Dumitrescu *n_rules_added = rsp->table_rule_add_bulk.n_rules;
163927b333b2SCristian Dumitrescu
164027b333b2SCristian Dumitrescu table_rule_add_bulk(table, list, *n_rules_added);
164127b333b2SCristian Dumitrescu *n_rules_not_added = table_rule_list_free(list);
164227b333b2SCristian Dumitrescu } else
164327b333b2SCristian Dumitrescu table_rule_list_free(list);
164427b333b2SCristian Dumitrescu
16453186282fSJasvinder Singh
16463186282fSJasvinder Singh /* Free response */
16473186282fSJasvinder Singh pipeline_msg_free(rsp);
16483186282fSJasvinder Singh
16493186282fSJasvinder Singh return status;
16503186282fSJasvinder Singh }
16513186282fSJasvinder Singh
16523186282fSJasvinder Singh int
pipeline_table_rule_delete(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match)1653f634e4c5SJasvinder Singh pipeline_table_rule_delete(const char *pipeline_name,
1654f634e4c5SJasvinder Singh uint32_t table_id,
1655f634e4c5SJasvinder Singh struct table_rule_match *match)
1656f634e4c5SJasvinder Singh {
1657f634e4c5SJasvinder Singh struct pipeline *p;
1658d2cb41c2SCristian Dumitrescu struct table *table;
1659f634e4c5SJasvinder Singh struct pipeline_msg_req *req;
1660f634e4c5SJasvinder Singh struct pipeline_msg_rsp *rsp;
1661f634e4c5SJasvinder Singh int status;
1662f634e4c5SJasvinder Singh
1663f634e4c5SJasvinder Singh /* Check input params */
1664f634e4c5SJasvinder Singh if ((pipeline_name == NULL) ||
1665f634e4c5SJasvinder Singh (match == NULL))
1666f634e4c5SJasvinder Singh return -1;
1667f634e4c5SJasvinder Singh
1668f634e4c5SJasvinder Singh p = pipeline_find(pipeline_name);
1669f634e4c5SJasvinder Singh if ((p == NULL) ||
1670f634e4c5SJasvinder Singh (table_id >= p->n_tables) ||
1671f634e4c5SJasvinder Singh match_check(match, p, table_id))
1672f634e4c5SJasvinder Singh return -1;
1673f634e4c5SJasvinder Singh
1674d2cb41c2SCristian Dumitrescu table = &p->table[table_id];
1675d2cb41c2SCristian Dumitrescu
1676f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1677f68a1d3fSJasvinder Singh union table_rule_match_low_level match_ll;
1678f68a1d3fSJasvinder Singh int key_found;
1679f68a1d3fSJasvinder Singh
1680f68a1d3fSJasvinder Singh status = match_convert(match, &match_ll, 0);
1681f68a1d3fSJasvinder Singh if (status)
1682f68a1d3fSJasvinder Singh return -1;
1683f68a1d3fSJasvinder Singh
1684f68a1d3fSJasvinder Singh status = rte_pipeline_table_entry_delete(p->p,
1685f68a1d3fSJasvinder Singh table_id,
1686f68a1d3fSJasvinder Singh &match_ll,
1687f68a1d3fSJasvinder Singh &key_found,
1688f68a1d3fSJasvinder Singh NULL);
1689f68a1d3fSJasvinder Singh
1690d2cb41c2SCristian Dumitrescu if (status == 0)
1691d2cb41c2SCristian Dumitrescu table_rule_delete(table, match);
1692d2cb41c2SCristian Dumitrescu
1693f68a1d3fSJasvinder Singh return status;
1694f68a1d3fSJasvinder Singh }
1695f68a1d3fSJasvinder Singh
1696f634e4c5SJasvinder Singh /* Allocate request */
1697f634e4c5SJasvinder Singh req = pipeline_msg_alloc();
1698f634e4c5SJasvinder Singh if (req == NULL)
1699f634e4c5SJasvinder Singh return -1;
1700f634e4c5SJasvinder Singh
1701f634e4c5SJasvinder Singh /* Write request */
1702f634e4c5SJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_DELETE;
1703f634e4c5SJasvinder Singh req->id = table_id;
1704f634e4c5SJasvinder Singh memcpy(&req->table_rule_delete.match, match, sizeof(*match));
1705f634e4c5SJasvinder Singh
1706f634e4c5SJasvinder Singh /* Send request and wait for response */
1707f634e4c5SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
1708f634e4c5SJasvinder Singh
1709f634e4c5SJasvinder Singh /* Read response */
1710f634e4c5SJasvinder Singh status = rsp->status;
1711d2cb41c2SCristian Dumitrescu if (status == 0)
1712d2cb41c2SCristian Dumitrescu table_rule_delete(table, match);
1713f634e4c5SJasvinder Singh
1714f634e4c5SJasvinder Singh /* Free response */
1715f634e4c5SJasvinder Singh pipeline_msg_free(rsp);
1716f634e4c5SJasvinder Singh
1717f634e4c5SJasvinder Singh return status;
1718f634e4c5SJasvinder Singh }
1719f634e4c5SJasvinder Singh
1720f634e4c5SJasvinder Singh int
pipeline_table_rule_delete_default(const char * pipeline_name,uint32_t table_id)1721f634e4c5SJasvinder Singh pipeline_table_rule_delete_default(const char *pipeline_name,
1722f634e4c5SJasvinder Singh uint32_t table_id)
1723f634e4c5SJasvinder Singh {
1724f634e4c5SJasvinder Singh struct pipeline *p;
1725f6df5f53SCristian Dumitrescu struct table *table;
1726f634e4c5SJasvinder Singh struct pipeline_msg_req *req;
1727f634e4c5SJasvinder Singh struct pipeline_msg_rsp *rsp;
1728f634e4c5SJasvinder Singh int status;
1729f634e4c5SJasvinder Singh
1730f634e4c5SJasvinder Singh /* Check input params */
1731f634e4c5SJasvinder Singh if (pipeline_name == NULL)
1732f634e4c5SJasvinder Singh return -1;
1733f634e4c5SJasvinder Singh
1734f634e4c5SJasvinder Singh p = pipeline_find(pipeline_name);
1735f634e4c5SJasvinder Singh if ((p == NULL) ||
1736f634e4c5SJasvinder Singh (table_id >= p->n_tables))
1737f634e4c5SJasvinder Singh return -1;
1738f634e4c5SJasvinder Singh
1739f6df5f53SCristian Dumitrescu table = &p->table[table_id];
1740f6df5f53SCristian Dumitrescu
1741f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1742f68a1d3fSJasvinder Singh status = rte_pipeline_table_default_entry_delete(p->p,
1743f68a1d3fSJasvinder Singh table_id,
1744f68a1d3fSJasvinder Singh NULL);
1745f68a1d3fSJasvinder Singh
1746f6df5f53SCristian Dumitrescu if (status == 0)
1747f6df5f53SCristian Dumitrescu table_rule_default_delete(table);
1748f6df5f53SCristian Dumitrescu
1749f68a1d3fSJasvinder Singh return status;
1750f68a1d3fSJasvinder Singh }
1751f68a1d3fSJasvinder Singh
1752f634e4c5SJasvinder Singh /* Allocate request */
1753f634e4c5SJasvinder Singh req = pipeline_msg_alloc();
1754f634e4c5SJasvinder Singh if (req == NULL)
1755f634e4c5SJasvinder Singh return -1;
1756f634e4c5SJasvinder Singh
1757f634e4c5SJasvinder Singh /* Write request */
1758f634e4c5SJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT;
1759f634e4c5SJasvinder Singh req->id = table_id;
1760f634e4c5SJasvinder Singh
1761f634e4c5SJasvinder Singh /* Send request and wait for response */
1762f634e4c5SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
1763f634e4c5SJasvinder Singh
1764f634e4c5SJasvinder Singh /* Read response */
1765f634e4c5SJasvinder Singh status = rsp->status;
1766f6df5f53SCristian Dumitrescu if (status == 0)
1767f6df5f53SCristian Dumitrescu table_rule_default_delete(table);
1768f634e4c5SJasvinder Singh
1769f634e4c5SJasvinder Singh /* Free response */
1770f634e4c5SJasvinder Singh pipeline_msg_free(rsp);
1771f634e4c5SJasvinder Singh
1772f634e4c5SJasvinder Singh return status;
1773f634e4c5SJasvinder Singh }
1774f634e4c5SJasvinder Singh
1775c64b9121SJasvinder Singh int
pipeline_table_rule_stats_read(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match,struct rte_table_action_stats_counters * stats,int clear)1776c64b9121SJasvinder Singh pipeline_table_rule_stats_read(const char *pipeline_name,
1777c64b9121SJasvinder Singh uint32_t table_id,
177887b36dcdSCristian Dumitrescu struct table_rule_match *match,
1779c64b9121SJasvinder Singh struct rte_table_action_stats_counters *stats,
1780c64b9121SJasvinder Singh int clear)
1781c64b9121SJasvinder Singh {
1782c64b9121SJasvinder Singh struct pipeline *p;
178387b36dcdSCristian Dumitrescu struct table *table;
1784c64b9121SJasvinder Singh struct pipeline_msg_req *req;
1785c64b9121SJasvinder Singh struct pipeline_msg_rsp *rsp;
178687b36dcdSCristian Dumitrescu struct table_rule *rule;
1787c64b9121SJasvinder Singh int status;
1788c64b9121SJasvinder Singh
1789c64b9121SJasvinder Singh /* Check input params */
1790c64b9121SJasvinder Singh if ((pipeline_name == NULL) ||
179187b36dcdSCristian Dumitrescu (match == NULL) ||
1792c64b9121SJasvinder Singh (stats == NULL))
1793c64b9121SJasvinder Singh return -1;
1794c64b9121SJasvinder Singh
1795c64b9121SJasvinder Singh p = pipeline_find(pipeline_name);
1796c64b9121SJasvinder Singh if ((p == NULL) ||
179787b36dcdSCristian Dumitrescu (table_id >= p->n_tables) ||
179887b36dcdSCristian Dumitrescu match_check(match, p, table_id))
179987b36dcdSCristian Dumitrescu return -1;
180087b36dcdSCristian Dumitrescu
180187b36dcdSCristian Dumitrescu table = &p->table[table_id];
180287b36dcdSCristian Dumitrescu rule = table_rule_find(table, match);
180387b36dcdSCristian Dumitrescu if (rule == NULL)
1804c64b9121SJasvinder Singh return -1;
1805c64b9121SJasvinder Singh
1806f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
180787b36dcdSCristian Dumitrescu status = rte_table_action_stats_read(table->a,
180887b36dcdSCristian Dumitrescu rule->data,
1809f68a1d3fSJasvinder Singh stats,
1810f68a1d3fSJasvinder Singh clear);
1811f68a1d3fSJasvinder Singh
1812f68a1d3fSJasvinder Singh return status;
1813f68a1d3fSJasvinder Singh }
1814f68a1d3fSJasvinder Singh
1815c64b9121SJasvinder Singh /* Allocate request */
1816c64b9121SJasvinder Singh req = pipeline_msg_alloc();
1817c64b9121SJasvinder Singh if (req == NULL)
1818c64b9121SJasvinder Singh return -1;
1819c64b9121SJasvinder Singh
1820c64b9121SJasvinder Singh /* Write request */
1821c64b9121SJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_STATS_READ;
1822c64b9121SJasvinder Singh req->id = table_id;
182387b36dcdSCristian Dumitrescu req->table_rule_stats_read.data = rule->data;
1824c64b9121SJasvinder Singh req->table_rule_stats_read.clear = clear;
1825c64b9121SJasvinder Singh
1826c64b9121SJasvinder Singh /* Send request and wait for response */
1827c64b9121SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
1828c64b9121SJasvinder Singh
1829c64b9121SJasvinder Singh /* Read response */
1830c64b9121SJasvinder Singh status = rsp->status;
183187b36dcdSCristian Dumitrescu if (status == 0)
1832c64b9121SJasvinder Singh memcpy(stats, &rsp->table_rule_stats_read.stats, sizeof(*stats));
1833c64b9121SJasvinder Singh
1834c64b9121SJasvinder Singh /* Free response */
1835c64b9121SJasvinder Singh pipeline_msg_free(rsp);
1836c64b9121SJasvinder Singh
1837c64b9121SJasvinder Singh return status;
1838c64b9121SJasvinder Singh }
1839c64b9121SJasvinder Singh
18407e11393eSJasvinder Singh int
pipeline_table_mtr_profile_add(const char * pipeline_name,uint32_t table_id,uint32_t meter_profile_id,struct rte_table_action_meter_profile * profile)18417e11393eSJasvinder Singh pipeline_table_mtr_profile_add(const char *pipeline_name,
18427e11393eSJasvinder Singh uint32_t table_id,
18437e11393eSJasvinder Singh uint32_t meter_profile_id,
18447e11393eSJasvinder Singh struct rte_table_action_meter_profile *profile)
18457e11393eSJasvinder Singh {
18467e11393eSJasvinder Singh struct pipeline *p;
18477e11393eSJasvinder Singh struct pipeline_msg_req *req;
18487e11393eSJasvinder Singh struct pipeline_msg_rsp *rsp;
18497e11393eSJasvinder Singh int status;
18507e11393eSJasvinder Singh
18517e11393eSJasvinder Singh /* Check input params */
18527e11393eSJasvinder Singh if ((pipeline_name == NULL) ||
18537e11393eSJasvinder Singh (profile == NULL))
18547e11393eSJasvinder Singh return -1;
18557e11393eSJasvinder Singh
18567e11393eSJasvinder Singh p = pipeline_find(pipeline_name);
18577e11393eSJasvinder Singh if ((p == NULL) ||
18587e11393eSJasvinder Singh (table_id >= p->n_tables))
18597e11393eSJasvinder Singh return -1;
18607e11393eSJasvinder Singh
1861f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1862f68a1d3fSJasvinder Singh struct rte_table_action *a = p->table[table_id].a;
1863f68a1d3fSJasvinder Singh
1864f68a1d3fSJasvinder Singh status = rte_table_action_meter_profile_add(a,
1865f68a1d3fSJasvinder Singh meter_profile_id,
1866f68a1d3fSJasvinder Singh profile);
1867f68a1d3fSJasvinder Singh
1868f68a1d3fSJasvinder Singh return status;
1869f68a1d3fSJasvinder Singh }
1870f68a1d3fSJasvinder Singh
18717e11393eSJasvinder Singh /* Allocate request */
18727e11393eSJasvinder Singh req = pipeline_msg_alloc();
18737e11393eSJasvinder Singh if (req == NULL)
18747e11393eSJasvinder Singh return -1;
18757e11393eSJasvinder Singh
18767e11393eSJasvinder Singh /* Write request */
18777e11393eSJasvinder Singh req->type = PIPELINE_REQ_TABLE_MTR_PROFILE_ADD;
18787e11393eSJasvinder Singh req->id = table_id;
18797e11393eSJasvinder Singh req->table_mtr_profile_add.meter_profile_id = meter_profile_id;
18807e11393eSJasvinder Singh memcpy(&req->table_mtr_profile_add.profile, profile, sizeof(*profile));
18817e11393eSJasvinder Singh
18827e11393eSJasvinder Singh /* Send request and wait for response */
18837e11393eSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
18847e11393eSJasvinder Singh
18857e11393eSJasvinder Singh /* Read response */
18867e11393eSJasvinder Singh status = rsp->status;
18877e11393eSJasvinder Singh
18887e11393eSJasvinder Singh /* Free response */
18897e11393eSJasvinder Singh pipeline_msg_free(rsp);
18907e11393eSJasvinder Singh
18917e11393eSJasvinder Singh return status;
18927e11393eSJasvinder Singh }
18937e11393eSJasvinder Singh
18947e11393eSJasvinder Singh int
pipeline_table_mtr_profile_delete(const char * pipeline_name,uint32_t table_id,uint32_t meter_profile_id)18957e11393eSJasvinder Singh pipeline_table_mtr_profile_delete(const char *pipeline_name,
18967e11393eSJasvinder Singh uint32_t table_id,
18977e11393eSJasvinder Singh uint32_t meter_profile_id)
18987e11393eSJasvinder Singh {
18997e11393eSJasvinder Singh struct pipeline *p;
19007e11393eSJasvinder Singh struct pipeline_msg_req *req;
19017e11393eSJasvinder Singh struct pipeline_msg_rsp *rsp;
19027e11393eSJasvinder Singh int status;
19037e11393eSJasvinder Singh
19047e11393eSJasvinder Singh /* Check input params */
19057e11393eSJasvinder Singh if (pipeline_name == NULL)
19067e11393eSJasvinder Singh return -1;
19077e11393eSJasvinder Singh
19087e11393eSJasvinder Singh p = pipeline_find(pipeline_name);
19097e11393eSJasvinder Singh if ((p == NULL) ||
19107e11393eSJasvinder Singh (table_id >= p->n_tables))
19117e11393eSJasvinder Singh return -1;
19127e11393eSJasvinder Singh
1913f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
1914f68a1d3fSJasvinder Singh struct rte_table_action *a = p->table[table_id].a;
1915f68a1d3fSJasvinder Singh
1916f68a1d3fSJasvinder Singh status = rte_table_action_meter_profile_delete(a,
1917f68a1d3fSJasvinder Singh meter_profile_id);
1918f68a1d3fSJasvinder Singh
1919f68a1d3fSJasvinder Singh return status;
1920f68a1d3fSJasvinder Singh }
1921f68a1d3fSJasvinder Singh
19227e11393eSJasvinder Singh /* Allocate request */
19237e11393eSJasvinder Singh req = pipeline_msg_alloc();
19247e11393eSJasvinder Singh if (req == NULL)
19257e11393eSJasvinder Singh return -1;
19267e11393eSJasvinder Singh
19277e11393eSJasvinder Singh /* Write request */
19287e11393eSJasvinder Singh req->type = PIPELINE_REQ_TABLE_MTR_PROFILE_DELETE;
19297e11393eSJasvinder Singh req->id = table_id;
19307e11393eSJasvinder Singh req->table_mtr_profile_delete.meter_profile_id = meter_profile_id;
19317e11393eSJasvinder Singh
19327e11393eSJasvinder Singh /* Send request and wait for response */
19337e11393eSJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
19347e11393eSJasvinder Singh
19357e11393eSJasvinder Singh /* Read response */
19367e11393eSJasvinder Singh status = rsp->status;
19377e11393eSJasvinder Singh
19387e11393eSJasvinder Singh /* Free response */
19397e11393eSJasvinder Singh pipeline_msg_free(rsp);
19407e11393eSJasvinder Singh
19417e11393eSJasvinder Singh return status;
19427e11393eSJasvinder Singh }
19437e11393eSJasvinder Singh
1944e92058d6SJasvinder Singh int
pipeline_table_rule_mtr_read(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match,struct rte_table_action_mtr_counters * stats,int clear)1945e92058d6SJasvinder Singh pipeline_table_rule_mtr_read(const char *pipeline_name,
1946e92058d6SJasvinder Singh uint32_t table_id,
19478c6dc647SCristian Dumitrescu struct table_rule_match *match,
1948e92058d6SJasvinder Singh struct rte_table_action_mtr_counters *stats,
1949e92058d6SJasvinder Singh int clear)
1950e92058d6SJasvinder Singh {
1951e92058d6SJasvinder Singh struct pipeline *p;
19528c6dc647SCristian Dumitrescu struct table *table;
1953e92058d6SJasvinder Singh struct pipeline_msg_req *req;
1954e92058d6SJasvinder Singh struct pipeline_msg_rsp *rsp;
19558c6dc647SCristian Dumitrescu struct table_rule *rule;
19568c6dc647SCristian Dumitrescu uint32_t tc_mask;
1957e92058d6SJasvinder Singh int status;
1958e92058d6SJasvinder Singh
1959e92058d6SJasvinder Singh /* Check input params */
1960e92058d6SJasvinder Singh if ((pipeline_name == NULL) ||
19618c6dc647SCristian Dumitrescu (match == NULL) ||
1962e92058d6SJasvinder Singh (stats == NULL))
1963e92058d6SJasvinder Singh return -1;
1964e92058d6SJasvinder Singh
1965e92058d6SJasvinder Singh p = pipeline_find(pipeline_name);
1966e92058d6SJasvinder Singh if ((p == NULL) ||
19678c6dc647SCristian Dumitrescu (table_id >= p->n_tables) ||
19688c6dc647SCristian Dumitrescu match_check(match, p, table_id))
19698c6dc647SCristian Dumitrescu return -1;
19708c6dc647SCristian Dumitrescu
19718c6dc647SCristian Dumitrescu table = &p->table[table_id];
19728c6dc647SCristian Dumitrescu tc_mask = (1 << table->ap->params.mtr.n_tc) - 1;
19738c6dc647SCristian Dumitrescu
19748c6dc647SCristian Dumitrescu rule = table_rule_find(table, match);
19758c6dc647SCristian Dumitrescu if (rule == NULL)
1976e92058d6SJasvinder Singh return -1;
1977e92058d6SJasvinder Singh
1978f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
19798c6dc647SCristian Dumitrescu status = rte_table_action_meter_read(table->a,
19808c6dc647SCristian Dumitrescu rule->data,
1981f68a1d3fSJasvinder Singh tc_mask,
1982f68a1d3fSJasvinder Singh stats,
1983f68a1d3fSJasvinder Singh clear);
1984f68a1d3fSJasvinder Singh
1985f68a1d3fSJasvinder Singh return status;
1986f68a1d3fSJasvinder Singh }
1987f68a1d3fSJasvinder Singh
1988e92058d6SJasvinder Singh /* Allocate request */
1989e92058d6SJasvinder Singh req = pipeline_msg_alloc();
1990e92058d6SJasvinder Singh if (req == NULL)
1991e92058d6SJasvinder Singh return -1;
1992e92058d6SJasvinder Singh
1993e92058d6SJasvinder Singh /* Write request */
1994e92058d6SJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_MTR_READ;
1995e92058d6SJasvinder Singh req->id = table_id;
19968c6dc647SCristian Dumitrescu req->table_rule_mtr_read.data = rule->data;
1997e92058d6SJasvinder Singh req->table_rule_mtr_read.tc_mask = tc_mask;
1998e92058d6SJasvinder Singh req->table_rule_mtr_read.clear = clear;
1999e92058d6SJasvinder Singh
2000e92058d6SJasvinder Singh /* Send request and wait for response */
2001e92058d6SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
2002e92058d6SJasvinder Singh
2003e92058d6SJasvinder Singh /* Read response */
2004e92058d6SJasvinder Singh status = rsp->status;
20058c6dc647SCristian Dumitrescu if (status == 0)
2006e92058d6SJasvinder Singh memcpy(stats, &rsp->table_rule_mtr_read.stats, sizeof(*stats));
2007e92058d6SJasvinder Singh
2008e92058d6SJasvinder Singh /* Free response */
2009e92058d6SJasvinder Singh pipeline_msg_free(rsp);
2010e92058d6SJasvinder Singh
2011e92058d6SJasvinder Singh return status;
2012e92058d6SJasvinder Singh }
2013e92058d6SJasvinder Singh
20142b82ef48SJasvinder Singh int
pipeline_table_dscp_table_update(const char * pipeline_name,uint32_t table_id,uint64_t dscp_mask,struct rte_table_action_dscp_table * dscp_table)20152b82ef48SJasvinder Singh pipeline_table_dscp_table_update(const char *pipeline_name,
20162b82ef48SJasvinder Singh uint32_t table_id,
20172b82ef48SJasvinder Singh uint64_t dscp_mask,
20182b82ef48SJasvinder Singh struct rte_table_action_dscp_table *dscp_table)
20192b82ef48SJasvinder Singh {
20202b82ef48SJasvinder Singh struct pipeline *p;
20212b82ef48SJasvinder Singh struct pipeline_msg_req *req;
20222b82ef48SJasvinder Singh struct pipeline_msg_rsp *rsp;
20232b82ef48SJasvinder Singh int status;
20242b82ef48SJasvinder Singh
20252b82ef48SJasvinder Singh /* Check input params */
20262b82ef48SJasvinder Singh if ((pipeline_name == NULL) ||
20272b82ef48SJasvinder Singh (dscp_table == NULL))
20282b82ef48SJasvinder Singh return -1;
20292b82ef48SJasvinder Singh
20302b82ef48SJasvinder Singh p = pipeline_find(pipeline_name);
20312b82ef48SJasvinder Singh if ((p == NULL) ||
20322b82ef48SJasvinder Singh (table_id >= p->n_tables))
20332b82ef48SJasvinder Singh return -1;
20342b82ef48SJasvinder Singh
2035f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
2036f68a1d3fSJasvinder Singh struct rte_table_action *a = p->table[table_id].a;
2037f68a1d3fSJasvinder Singh
2038f68a1d3fSJasvinder Singh status = rte_table_action_dscp_table_update(a,
2039f68a1d3fSJasvinder Singh dscp_mask,
2040f68a1d3fSJasvinder Singh dscp_table);
2041f68a1d3fSJasvinder Singh
2042f68a1d3fSJasvinder Singh return status;
2043f68a1d3fSJasvinder Singh }
2044f68a1d3fSJasvinder Singh
20452b82ef48SJasvinder Singh /* Allocate request */
20462b82ef48SJasvinder Singh req = pipeline_msg_alloc();
20472b82ef48SJasvinder Singh if (req == NULL)
20482b82ef48SJasvinder Singh return -1;
20492b82ef48SJasvinder Singh
20502b82ef48SJasvinder Singh /* Write request */
20512b82ef48SJasvinder Singh req->type = PIPELINE_REQ_TABLE_DSCP_TABLE_UPDATE;
20522b82ef48SJasvinder Singh req->id = table_id;
20532b82ef48SJasvinder Singh req->table_dscp_table_update.dscp_mask = dscp_mask;
20542b82ef48SJasvinder Singh memcpy(&req->table_dscp_table_update.dscp_table,
20552b82ef48SJasvinder Singh dscp_table, sizeof(*dscp_table));
20562b82ef48SJasvinder Singh
20572b82ef48SJasvinder Singh /* Send request and wait for response */
20582b82ef48SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
20592b82ef48SJasvinder Singh
20602b82ef48SJasvinder Singh /* Read response */
20612b82ef48SJasvinder Singh status = rsp->status;
20622b82ef48SJasvinder Singh
20632b82ef48SJasvinder Singh /* Free response */
20642b82ef48SJasvinder Singh pipeline_msg_free(rsp);
20652b82ef48SJasvinder Singh
20662b82ef48SJasvinder Singh return status;
20672b82ef48SJasvinder Singh }
20682b82ef48SJasvinder Singh
2069d0d306c7SJasvinder Singh int
pipeline_table_rule_ttl_read(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match,struct rte_table_action_ttl_counters * stats,int clear)2070d0d306c7SJasvinder Singh pipeline_table_rule_ttl_read(const char *pipeline_name,
2071d0d306c7SJasvinder Singh uint32_t table_id,
20728bfe22acSCristian Dumitrescu struct table_rule_match *match,
2073d0d306c7SJasvinder Singh struct rte_table_action_ttl_counters *stats,
2074d0d306c7SJasvinder Singh int clear)
2075d0d306c7SJasvinder Singh {
2076d0d306c7SJasvinder Singh struct pipeline *p;
20778bfe22acSCristian Dumitrescu struct table *table;
2078d0d306c7SJasvinder Singh struct pipeline_msg_req *req;
2079d0d306c7SJasvinder Singh struct pipeline_msg_rsp *rsp;
20808bfe22acSCristian Dumitrescu struct table_rule *rule;
2081d0d306c7SJasvinder Singh int status;
2082d0d306c7SJasvinder Singh
2083d0d306c7SJasvinder Singh /* Check input params */
2084d0d306c7SJasvinder Singh if ((pipeline_name == NULL) ||
20858bfe22acSCristian Dumitrescu (match == NULL) ||
2086d0d306c7SJasvinder Singh (stats == NULL))
2087d0d306c7SJasvinder Singh return -1;
2088d0d306c7SJasvinder Singh
2089d0d306c7SJasvinder Singh p = pipeline_find(pipeline_name);
2090d0d306c7SJasvinder Singh if ((p == NULL) ||
20918bfe22acSCristian Dumitrescu (table_id >= p->n_tables) ||
20928bfe22acSCristian Dumitrescu match_check(match, p, table_id))
20938bfe22acSCristian Dumitrescu return -1;
20948bfe22acSCristian Dumitrescu
20958bfe22acSCristian Dumitrescu table = &p->table[table_id];
20968bfe22acSCristian Dumitrescu if (!table->ap->params.ttl.n_packets_enabled)
20978bfe22acSCristian Dumitrescu return -1;
20988bfe22acSCristian Dumitrescu
20998bfe22acSCristian Dumitrescu rule = table_rule_find(table, match);
21008bfe22acSCristian Dumitrescu if (rule == NULL)
2101d0d306c7SJasvinder Singh return -1;
2102d0d306c7SJasvinder Singh
2103f68a1d3fSJasvinder Singh if (!pipeline_is_running(p)) {
21048bfe22acSCristian Dumitrescu status = rte_table_action_ttl_read(table->a,
21058bfe22acSCristian Dumitrescu rule->data,
2106f68a1d3fSJasvinder Singh stats,
2107f68a1d3fSJasvinder Singh clear);
2108f68a1d3fSJasvinder Singh
2109f68a1d3fSJasvinder Singh return status;
2110f68a1d3fSJasvinder Singh }
2111f68a1d3fSJasvinder Singh
2112d0d306c7SJasvinder Singh /* Allocate request */
2113d0d306c7SJasvinder Singh req = pipeline_msg_alloc();
2114d0d306c7SJasvinder Singh if (req == NULL)
2115d0d306c7SJasvinder Singh return -1;
2116d0d306c7SJasvinder Singh
2117d0d306c7SJasvinder Singh /* Write request */
2118d0d306c7SJasvinder Singh req->type = PIPELINE_REQ_TABLE_RULE_TTL_READ;
2119d0d306c7SJasvinder Singh req->id = table_id;
21208bfe22acSCristian Dumitrescu req->table_rule_ttl_read.data = rule->data;
2121d0d306c7SJasvinder Singh req->table_rule_ttl_read.clear = clear;
2122d0d306c7SJasvinder Singh
2123d0d306c7SJasvinder Singh /* Send request and wait for response */
2124d0d306c7SJasvinder Singh rsp = pipeline_msg_send_recv(p, req);
2125d0d306c7SJasvinder Singh
2126d0d306c7SJasvinder Singh /* Read response */
2127d0d306c7SJasvinder Singh status = rsp->status;
21288bfe22acSCristian Dumitrescu if (status == 0)
2129d0d306c7SJasvinder Singh memcpy(stats, &rsp->table_rule_ttl_read.stats, sizeof(*stats));
2130d0d306c7SJasvinder Singh
2131d0d306c7SJasvinder Singh /* Free response */
2132d0d306c7SJasvinder Singh pipeline_msg_free(rsp);
2133d0d306c7SJasvinder Singh
2134d0d306c7SJasvinder Singh return status;
2135d0d306c7SJasvinder Singh }
2136d0d306c7SJasvinder Singh
2137a3169ee5SCristian Dumitrescu int
pipeline_table_rule_time_read(const char * pipeline_name,uint32_t table_id,struct table_rule_match * match,uint64_t * timestamp)2138a3169ee5SCristian Dumitrescu pipeline_table_rule_time_read(const char *pipeline_name,
2139a3169ee5SCristian Dumitrescu uint32_t table_id,
2140a3169ee5SCristian Dumitrescu struct table_rule_match *match,
2141a3169ee5SCristian Dumitrescu uint64_t *timestamp)
2142a3169ee5SCristian Dumitrescu {
2143a3169ee5SCristian Dumitrescu struct pipeline *p;
2144a3169ee5SCristian Dumitrescu struct table *table;
2145a3169ee5SCristian Dumitrescu struct pipeline_msg_req *req;
2146a3169ee5SCristian Dumitrescu struct pipeline_msg_rsp *rsp;
2147a3169ee5SCristian Dumitrescu struct table_rule *rule;
2148a3169ee5SCristian Dumitrescu int status;
2149a3169ee5SCristian Dumitrescu
2150a3169ee5SCristian Dumitrescu /* Check input params */
2151a3169ee5SCristian Dumitrescu if ((pipeline_name == NULL) ||
2152a3169ee5SCristian Dumitrescu (match == NULL) ||
2153a3169ee5SCristian Dumitrescu (timestamp == NULL))
2154a3169ee5SCristian Dumitrescu return -1;
2155a3169ee5SCristian Dumitrescu
2156a3169ee5SCristian Dumitrescu p = pipeline_find(pipeline_name);
2157a3169ee5SCristian Dumitrescu if ((p == NULL) ||
2158a3169ee5SCristian Dumitrescu (table_id >= p->n_tables) ||
2159a3169ee5SCristian Dumitrescu match_check(match, p, table_id))
2160a3169ee5SCristian Dumitrescu return -1;
2161a3169ee5SCristian Dumitrescu
2162a3169ee5SCristian Dumitrescu table = &p->table[table_id];
2163a3169ee5SCristian Dumitrescu
2164a3169ee5SCristian Dumitrescu rule = table_rule_find(table, match);
2165a3169ee5SCristian Dumitrescu if (rule == NULL)
2166a3169ee5SCristian Dumitrescu return -1;
2167a3169ee5SCristian Dumitrescu
2168a3169ee5SCristian Dumitrescu if (!pipeline_is_running(p)) {
2169a3169ee5SCristian Dumitrescu status = rte_table_action_time_read(table->a,
2170a3169ee5SCristian Dumitrescu rule->data,
2171a3169ee5SCristian Dumitrescu timestamp);
2172a3169ee5SCristian Dumitrescu
2173a3169ee5SCristian Dumitrescu return status;
2174a3169ee5SCristian Dumitrescu }
2175a3169ee5SCristian Dumitrescu
2176a3169ee5SCristian Dumitrescu /* Allocate request */
2177a3169ee5SCristian Dumitrescu req = pipeline_msg_alloc();
2178a3169ee5SCristian Dumitrescu if (req == NULL)
2179a3169ee5SCristian Dumitrescu return -1;
2180a3169ee5SCristian Dumitrescu
2181a3169ee5SCristian Dumitrescu /* Write request */
2182a3169ee5SCristian Dumitrescu req->type = PIPELINE_REQ_TABLE_RULE_TIME_READ;
2183a3169ee5SCristian Dumitrescu req->id = table_id;
2184a3169ee5SCristian Dumitrescu req->table_rule_time_read.data = rule->data;
2185a3169ee5SCristian Dumitrescu
2186a3169ee5SCristian Dumitrescu /* Send request and wait for response */
2187a3169ee5SCristian Dumitrescu rsp = pipeline_msg_send_recv(p, req);
2188a3169ee5SCristian Dumitrescu
2189a3169ee5SCristian Dumitrescu /* Read response */
2190a3169ee5SCristian Dumitrescu status = rsp->status;
2191a3169ee5SCristian Dumitrescu if (status == 0)
2192a3169ee5SCristian Dumitrescu *timestamp = rsp->table_rule_time_read.timestamp;
2193a3169ee5SCristian Dumitrescu
2194a3169ee5SCristian Dumitrescu /* Free response */
2195a3169ee5SCristian Dumitrescu pipeline_msg_free(rsp);
2196a3169ee5SCristian Dumitrescu
2197a3169ee5SCristian Dumitrescu return status;
2198a3169ee5SCristian Dumitrescu }
2199a3169ee5SCristian Dumitrescu
22006b1b3c3cSJasvinder Singh /**
2201a8bd581dSJasvinder Singh * Data plane threads: message handling
2202a8bd581dSJasvinder Singh */
2203a8bd581dSJasvinder Singh static inline struct pipeline_msg_req *
pipeline_msg_recv(struct rte_ring * msgq_req)2204a8bd581dSJasvinder Singh pipeline_msg_recv(struct rte_ring *msgq_req)
2205a8bd581dSJasvinder Singh {
2206a8bd581dSJasvinder Singh struct pipeline_msg_req *req;
2207a8bd581dSJasvinder Singh
2208a8bd581dSJasvinder Singh int status = rte_ring_sc_dequeue(msgq_req, (void **) &req);
2209a8bd581dSJasvinder Singh
2210a8bd581dSJasvinder Singh if (status != 0)
2211a8bd581dSJasvinder Singh return NULL;
2212a8bd581dSJasvinder Singh
2213a8bd581dSJasvinder Singh return req;
2214a8bd581dSJasvinder Singh }
2215a8bd581dSJasvinder Singh
2216a8bd581dSJasvinder Singh static inline void
pipeline_msg_send(struct rte_ring * msgq_rsp,struct pipeline_msg_rsp * rsp)2217a8bd581dSJasvinder Singh pipeline_msg_send(struct rte_ring *msgq_rsp,
2218a8bd581dSJasvinder Singh struct pipeline_msg_rsp *rsp)
2219a8bd581dSJasvinder Singh {
2220a8bd581dSJasvinder Singh int status;
2221a8bd581dSJasvinder Singh
2222a8bd581dSJasvinder Singh do {
2223a8bd581dSJasvinder Singh status = rte_ring_sp_enqueue(msgq_rsp, rsp);
2224a8bd581dSJasvinder Singh } while (status == -ENOBUFS);
2225a8bd581dSJasvinder Singh }
2226a8bd581dSJasvinder Singh
22276b1b3c3cSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_port_in_stats_read(struct pipeline_data * p,struct pipeline_msg_req * req)222850e73d05SJasvinder Singh pipeline_msg_handle_port_in_stats_read(struct pipeline_data *p,
222950e73d05SJasvinder Singh struct pipeline_msg_req *req)
223050e73d05SJasvinder Singh {
223150e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
223250e73d05SJasvinder Singh uint32_t port_id = req->id;
223350e73d05SJasvinder Singh int clear = req->port_in_stats_read.clear;
223450e73d05SJasvinder Singh
223550e73d05SJasvinder Singh rsp->status = rte_pipeline_port_in_stats_read(p->p,
223650e73d05SJasvinder Singh port_id,
223750e73d05SJasvinder Singh &rsp->port_in_stats_read.stats,
223850e73d05SJasvinder Singh clear);
223950e73d05SJasvinder Singh
224050e73d05SJasvinder Singh return rsp;
224150e73d05SJasvinder Singh }
224250e73d05SJasvinder Singh
224350e73d05SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_port_in_enable(struct pipeline_data * p,struct pipeline_msg_req * req)22446b1b3c3cSJasvinder Singh pipeline_msg_handle_port_in_enable(struct pipeline_data *p,
22456b1b3c3cSJasvinder Singh struct pipeline_msg_req *req)
22466b1b3c3cSJasvinder Singh {
22476b1b3c3cSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
22486b1b3c3cSJasvinder Singh uint32_t port_id = req->id;
22496b1b3c3cSJasvinder Singh
22506b1b3c3cSJasvinder Singh rsp->status = rte_pipeline_port_in_enable(p->p,
22516b1b3c3cSJasvinder Singh port_id);
22526b1b3c3cSJasvinder Singh
22536b1b3c3cSJasvinder Singh return rsp;
22546b1b3c3cSJasvinder Singh }
22556b1b3c3cSJasvinder Singh
22566b1b3c3cSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_port_in_disable(struct pipeline_data * p,struct pipeline_msg_req * req)22576b1b3c3cSJasvinder Singh pipeline_msg_handle_port_in_disable(struct pipeline_data *p,
22586b1b3c3cSJasvinder Singh struct pipeline_msg_req *req)
22596b1b3c3cSJasvinder Singh {
22606b1b3c3cSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
22616b1b3c3cSJasvinder Singh uint32_t port_id = req->id;
22626b1b3c3cSJasvinder Singh
22636b1b3c3cSJasvinder Singh rsp->status = rte_pipeline_port_in_disable(p->p,
22646b1b3c3cSJasvinder Singh port_id);
22656b1b3c3cSJasvinder Singh
22666b1b3c3cSJasvinder Singh return rsp;
22676b1b3c3cSJasvinder Singh }
22686b1b3c3cSJasvinder Singh
226950e73d05SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_port_out_stats_read(struct pipeline_data * p,struct pipeline_msg_req * req)227050e73d05SJasvinder Singh pipeline_msg_handle_port_out_stats_read(struct pipeline_data *p,
227150e73d05SJasvinder Singh struct pipeline_msg_req *req)
227250e73d05SJasvinder Singh {
227350e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
227450e73d05SJasvinder Singh uint32_t port_id = req->id;
227550e73d05SJasvinder Singh int clear = req->port_out_stats_read.clear;
227650e73d05SJasvinder Singh
227750e73d05SJasvinder Singh rsp->status = rte_pipeline_port_out_stats_read(p->p,
227850e73d05SJasvinder Singh port_id,
227950e73d05SJasvinder Singh &rsp->port_out_stats_read.stats,
228050e73d05SJasvinder Singh clear);
228150e73d05SJasvinder Singh
228250e73d05SJasvinder Singh return rsp;
228350e73d05SJasvinder Singh }
228450e73d05SJasvinder Singh
228550e73d05SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_stats_read(struct pipeline_data * p,struct pipeline_msg_req * req)228650e73d05SJasvinder Singh pipeline_msg_handle_table_stats_read(struct pipeline_data *p,
228750e73d05SJasvinder Singh struct pipeline_msg_req *req)
228850e73d05SJasvinder Singh {
228950e73d05SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
229050e73d05SJasvinder Singh uint32_t port_id = req->id;
229150e73d05SJasvinder Singh int clear = req->table_stats_read.clear;
229250e73d05SJasvinder Singh
229350e73d05SJasvinder Singh rsp->status = rte_pipeline_table_stats_read(p->p,
229450e73d05SJasvinder Singh port_id,
229550e73d05SJasvinder Singh &rsp->table_stats_read.stats,
229650e73d05SJasvinder Singh clear);
229750e73d05SJasvinder Singh
229850e73d05SJasvinder Singh return rsp;
229950e73d05SJasvinder Singh }
230050e73d05SJasvinder Singh
2301a3a95b7dSJasvinder Singh static int
match_convert_ipv6_depth(uint32_t depth,uint32_t * depth32)2302a3a95b7dSJasvinder Singh match_convert_ipv6_depth(uint32_t depth, uint32_t *depth32)
2303a3a95b7dSJasvinder Singh {
2304a3a95b7dSJasvinder Singh if (depth > 128)
2305a3a95b7dSJasvinder Singh return -1;
2306a3a95b7dSJasvinder Singh
2307a3a95b7dSJasvinder Singh switch (depth / 32) {
2308a3a95b7dSJasvinder Singh case 0:
2309a3a95b7dSJasvinder Singh depth32[0] = depth;
2310a3a95b7dSJasvinder Singh depth32[1] = 0;
2311a3a95b7dSJasvinder Singh depth32[2] = 0;
2312a3a95b7dSJasvinder Singh depth32[3] = 0;
2313a3a95b7dSJasvinder Singh return 0;
2314a3a95b7dSJasvinder Singh
2315a3a95b7dSJasvinder Singh case 1:
2316a3a95b7dSJasvinder Singh depth32[0] = 32;
2317a3a95b7dSJasvinder Singh depth32[1] = depth - 32;
2318a3a95b7dSJasvinder Singh depth32[2] = 0;
2319a3a95b7dSJasvinder Singh depth32[3] = 0;
2320a3a95b7dSJasvinder Singh return 0;
2321a3a95b7dSJasvinder Singh
2322a3a95b7dSJasvinder Singh case 2:
2323a3a95b7dSJasvinder Singh depth32[0] = 32;
2324a3a95b7dSJasvinder Singh depth32[1] = 32;
2325a3a95b7dSJasvinder Singh depth32[2] = depth - 64;
2326a3a95b7dSJasvinder Singh depth32[3] = 0;
2327a3a95b7dSJasvinder Singh return 0;
2328a3a95b7dSJasvinder Singh
2329a3a95b7dSJasvinder Singh case 3:
2330a3a95b7dSJasvinder Singh depth32[0] = 32;
2331a3a95b7dSJasvinder Singh depth32[1] = 32;
2332a3a95b7dSJasvinder Singh depth32[2] = 32;
2333a3a95b7dSJasvinder Singh depth32[3] = depth - 96;
2334a3a95b7dSJasvinder Singh return 0;
2335a3a95b7dSJasvinder Singh
2336a3a95b7dSJasvinder Singh case 4:
2337a3a95b7dSJasvinder Singh depth32[0] = 32;
2338a3a95b7dSJasvinder Singh depth32[1] = 32;
2339a3a95b7dSJasvinder Singh depth32[2] = 32;
2340a3a95b7dSJasvinder Singh depth32[3] = 32;
2341a3a95b7dSJasvinder Singh return 0;
2342a3a95b7dSJasvinder Singh
2343a3a95b7dSJasvinder Singh default:
2344a3a95b7dSJasvinder Singh return -1;
2345a3a95b7dSJasvinder Singh }
2346a3a95b7dSJasvinder Singh }
2347a3a95b7dSJasvinder Singh
2348a3a95b7dSJasvinder Singh static int
match_convert(struct table_rule_match * mh,union table_rule_match_low_level * ml,int add)2349a3a95b7dSJasvinder Singh match_convert(struct table_rule_match *mh,
2350a3a95b7dSJasvinder Singh union table_rule_match_low_level *ml,
2351a3a95b7dSJasvinder Singh int add)
2352a3a95b7dSJasvinder Singh {
2353a3a95b7dSJasvinder Singh memset(ml, 0, sizeof(*ml));
2354a3a95b7dSJasvinder Singh
2355a3a95b7dSJasvinder Singh switch (mh->match_type) {
2356a3a95b7dSJasvinder Singh case TABLE_ACL:
2357a3a95b7dSJasvinder Singh if (mh->match.acl.ip_version)
2358a3a95b7dSJasvinder Singh if (add) {
2359a3a95b7dSJasvinder Singh ml->acl_add.field_value[0].value.u8 =
2360a3a95b7dSJasvinder Singh mh->match.acl.proto;
2361a3a95b7dSJasvinder Singh ml->acl_add.field_value[0].mask_range.u8 =
2362a3a95b7dSJasvinder Singh mh->match.acl.proto_mask;
2363a3a95b7dSJasvinder Singh
2364a3a95b7dSJasvinder Singh ml->acl_add.field_value[1].value.u32 =
2365a3a95b7dSJasvinder Singh mh->match.acl.ipv4.sa;
2366a3a95b7dSJasvinder Singh ml->acl_add.field_value[1].mask_range.u32 =
2367a3a95b7dSJasvinder Singh mh->match.acl.sa_depth;
2368a3a95b7dSJasvinder Singh
2369a3a95b7dSJasvinder Singh ml->acl_add.field_value[2].value.u32 =
2370a3a95b7dSJasvinder Singh mh->match.acl.ipv4.da;
2371a3a95b7dSJasvinder Singh ml->acl_add.field_value[2].mask_range.u32 =
2372a3a95b7dSJasvinder Singh mh->match.acl.da_depth;
2373a3a95b7dSJasvinder Singh
2374a3a95b7dSJasvinder Singh ml->acl_add.field_value[3].value.u16 =
2375a3a95b7dSJasvinder Singh mh->match.acl.sp0;
2376a3a95b7dSJasvinder Singh ml->acl_add.field_value[3].mask_range.u16 =
2377a3a95b7dSJasvinder Singh mh->match.acl.sp1;
2378a3a95b7dSJasvinder Singh
2379a3a95b7dSJasvinder Singh ml->acl_add.field_value[4].value.u16 =
2380a3a95b7dSJasvinder Singh mh->match.acl.dp0;
2381a3a95b7dSJasvinder Singh ml->acl_add.field_value[4].mask_range.u16 =
2382a3a95b7dSJasvinder Singh mh->match.acl.dp1;
2383a3a95b7dSJasvinder Singh
2384a3a95b7dSJasvinder Singh ml->acl_add.priority =
2385a3a95b7dSJasvinder Singh (int32_t) mh->match.acl.priority;
2386a3a95b7dSJasvinder Singh } else {
2387a3a95b7dSJasvinder Singh ml->acl_delete.field_value[0].value.u8 =
2388a3a95b7dSJasvinder Singh mh->match.acl.proto;
2389a3a95b7dSJasvinder Singh ml->acl_delete.field_value[0].mask_range.u8 =
2390a3a95b7dSJasvinder Singh mh->match.acl.proto_mask;
2391a3a95b7dSJasvinder Singh
2392a3a95b7dSJasvinder Singh ml->acl_delete.field_value[1].value.u32 =
2393a3a95b7dSJasvinder Singh mh->match.acl.ipv4.sa;
2394a3a95b7dSJasvinder Singh ml->acl_delete.field_value[1].mask_range.u32 =
2395a3a95b7dSJasvinder Singh mh->match.acl.sa_depth;
2396a3a95b7dSJasvinder Singh
2397a3a95b7dSJasvinder Singh ml->acl_delete.field_value[2].value.u32 =
2398a3a95b7dSJasvinder Singh mh->match.acl.ipv4.da;
2399a3a95b7dSJasvinder Singh ml->acl_delete.field_value[2].mask_range.u32 =
2400a3a95b7dSJasvinder Singh mh->match.acl.da_depth;
2401a3a95b7dSJasvinder Singh
2402a3a95b7dSJasvinder Singh ml->acl_delete.field_value[3].value.u16 =
2403a3a95b7dSJasvinder Singh mh->match.acl.sp0;
2404a3a95b7dSJasvinder Singh ml->acl_delete.field_value[3].mask_range.u16 =
2405a3a95b7dSJasvinder Singh mh->match.acl.sp1;
2406a3a95b7dSJasvinder Singh
2407a3a95b7dSJasvinder Singh ml->acl_delete.field_value[4].value.u16 =
2408a3a95b7dSJasvinder Singh mh->match.acl.dp0;
2409a3a95b7dSJasvinder Singh ml->acl_delete.field_value[4].mask_range.u16 =
2410a3a95b7dSJasvinder Singh mh->match.acl.dp1;
2411a3a95b7dSJasvinder Singh }
2412a3a95b7dSJasvinder Singh else
2413a3a95b7dSJasvinder Singh if (add) {
2414a3a95b7dSJasvinder Singh uint32_t *sa32 =
2415a3a95b7dSJasvinder Singh (uint32_t *) mh->match.acl.ipv6.sa;
2416a3a95b7dSJasvinder Singh uint32_t *da32 =
2417a3a95b7dSJasvinder Singh (uint32_t *) mh->match.acl.ipv6.da;
2418a3a95b7dSJasvinder Singh uint32_t sa32_depth[4], da32_depth[4];
2419a3a95b7dSJasvinder Singh int status;
2420a3a95b7dSJasvinder Singh
2421a3a95b7dSJasvinder Singh status = match_convert_ipv6_depth(
2422a3a95b7dSJasvinder Singh mh->match.acl.sa_depth,
2423a3a95b7dSJasvinder Singh sa32_depth);
2424a3a95b7dSJasvinder Singh if (status)
2425a3a95b7dSJasvinder Singh return status;
2426a3a95b7dSJasvinder Singh
2427a3a95b7dSJasvinder Singh status = match_convert_ipv6_depth(
2428a3a95b7dSJasvinder Singh mh->match.acl.da_depth,
2429a3a95b7dSJasvinder Singh da32_depth);
2430a3a95b7dSJasvinder Singh if (status)
2431a3a95b7dSJasvinder Singh return status;
2432a3a95b7dSJasvinder Singh
2433a3a95b7dSJasvinder Singh ml->acl_add.field_value[0].value.u8 =
2434a3a95b7dSJasvinder Singh mh->match.acl.proto;
2435a3a95b7dSJasvinder Singh ml->acl_add.field_value[0].mask_range.u8 =
2436a3a95b7dSJasvinder Singh mh->match.acl.proto_mask;
2437a3a95b7dSJasvinder Singh
2438223be676SReshma Pattan ml->acl_add.field_value[1].value.u32 =
2439223be676SReshma Pattan rte_be_to_cpu_32(sa32[0]);
2440a3a95b7dSJasvinder Singh ml->acl_add.field_value[1].mask_range.u32 =
2441a3a95b7dSJasvinder Singh sa32_depth[0];
2442223be676SReshma Pattan ml->acl_add.field_value[2].value.u32 =
2443223be676SReshma Pattan rte_be_to_cpu_32(sa32[1]);
2444a3a95b7dSJasvinder Singh ml->acl_add.field_value[2].mask_range.u32 =
2445a3a95b7dSJasvinder Singh sa32_depth[1];
2446223be676SReshma Pattan ml->acl_add.field_value[3].value.u32 =
2447223be676SReshma Pattan rte_be_to_cpu_32(sa32[2]);
2448a3a95b7dSJasvinder Singh ml->acl_add.field_value[3].mask_range.u32 =
2449a3a95b7dSJasvinder Singh sa32_depth[2];
2450223be676SReshma Pattan ml->acl_add.field_value[4].value.u32 =
2451223be676SReshma Pattan rte_be_to_cpu_32(sa32[3]);
2452a3a95b7dSJasvinder Singh ml->acl_add.field_value[4].mask_range.u32 =
2453a3a95b7dSJasvinder Singh sa32_depth[3];
2454a3a95b7dSJasvinder Singh
2455223be676SReshma Pattan ml->acl_add.field_value[5].value.u32 =
2456223be676SReshma Pattan rte_be_to_cpu_32(da32[0]);
2457a3a95b7dSJasvinder Singh ml->acl_add.field_value[5].mask_range.u32 =
2458a3a95b7dSJasvinder Singh da32_depth[0];
2459223be676SReshma Pattan ml->acl_add.field_value[6].value.u32 =
2460223be676SReshma Pattan rte_be_to_cpu_32(da32[1]);
2461a3a95b7dSJasvinder Singh ml->acl_add.field_value[6].mask_range.u32 =
2462a3a95b7dSJasvinder Singh da32_depth[1];
2463223be676SReshma Pattan ml->acl_add.field_value[7].value.u32 =
2464223be676SReshma Pattan rte_be_to_cpu_32(da32[2]);
2465a3a95b7dSJasvinder Singh ml->acl_add.field_value[7].mask_range.u32 =
2466a3a95b7dSJasvinder Singh da32_depth[2];
2467223be676SReshma Pattan ml->acl_add.field_value[8].value.u32 =
2468223be676SReshma Pattan rte_be_to_cpu_32(da32[3]);
2469a3a95b7dSJasvinder Singh ml->acl_add.field_value[8].mask_range.u32 =
2470a3a95b7dSJasvinder Singh da32_depth[3];
2471a3a95b7dSJasvinder Singh
2472a3a95b7dSJasvinder Singh ml->acl_add.field_value[9].value.u16 =
2473a3a95b7dSJasvinder Singh mh->match.acl.sp0;
2474a3a95b7dSJasvinder Singh ml->acl_add.field_value[9].mask_range.u16 =
2475a3a95b7dSJasvinder Singh mh->match.acl.sp1;
2476a3a95b7dSJasvinder Singh
2477a3a95b7dSJasvinder Singh ml->acl_add.field_value[10].value.u16 =
2478a3a95b7dSJasvinder Singh mh->match.acl.dp0;
2479a3a95b7dSJasvinder Singh ml->acl_add.field_value[10].mask_range.u16 =
2480a3a95b7dSJasvinder Singh mh->match.acl.dp1;
2481a3a95b7dSJasvinder Singh
2482a3a95b7dSJasvinder Singh ml->acl_add.priority =
2483a3a95b7dSJasvinder Singh (int32_t) mh->match.acl.priority;
2484a3a95b7dSJasvinder Singh } else {
2485a3a95b7dSJasvinder Singh uint32_t *sa32 =
2486a3a95b7dSJasvinder Singh (uint32_t *) mh->match.acl.ipv6.sa;
2487a3a95b7dSJasvinder Singh uint32_t *da32 =
2488a3a95b7dSJasvinder Singh (uint32_t *) mh->match.acl.ipv6.da;
2489a3a95b7dSJasvinder Singh uint32_t sa32_depth[4], da32_depth[4];
2490a3a95b7dSJasvinder Singh int status;
2491a3a95b7dSJasvinder Singh
2492a3a95b7dSJasvinder Singh status = match_convert_ipv6_depth(
2493a3a95b7dSJasvinder Singh mh->match.acl.sa_depth,
2494a3a95b7dSJasvinder Singh sa32_depth);
2495a3a95b7dSJasvinder Singh if (status)
2496a3a95b7dSJasvinder Singh return status;
2497a3a95b7dSJasvinder Singh
2498a3a95b7dSJasvinder Singh status = match_convert_ipv6_depth(
2499a3a95b7dSJasvinder Singh mh->match.acl.da_depth,
2500a3a95b7dSJasvinder Singh da32_depth);
2501a3a95b7dSJasvinder Singh if (status)
2502a3a95b7dSJasvinder Singh return status;
2503a3a95b7dSJasvinder Singh
2504a3a95b7dSJasvinder Singh ml->acl_delete.field_value[0].value.u8 =
2505a3a95b7dSJasvinder Singh mh->match.acl.proto;
2506a3a95b7dSJasvinder Singh ml->acl_delete.field_value[0].mask_range.u8 =
2507a3a95b7dSJasvinder Singh mh->match.acl.proto_mask;
2508a3a95b7dSJasvinder Singh
2509a3a95b7dSJasvinder Singh ml->acl_delete.field_value[1].value.u32 =
2510223be676SReshma Pattan rte_be_to_cpu_32(sa32[0]);
2511a3a95b7dSJasvinder Singh ml->acl_delete.field_value[1].mask_range.u32 =
2512a3a95b7dSJasvinder Singh sa32_depth[0];
2513a3a95b7dSJasvinder Singh ml->acl_delete.field_value[2].value.u32 =
2514223be676SReshma Pattan rte_be_to_cpu_32(sa32[1]);
2515a3a95b7dSJasvinder Singh ml->acl_delete.field_value[2].mask_range.u32 =
2516a3a95b7dSJasvinder Singh sa32_depth[1];
2517a3a95b7dSJasvinder Singh ml->acl_delete.field_value[3].value.u32 =
2518223be676SReshma Pattan rte_be_to_cpu_32(sa32[2]);
2519a3a95b7dSJasvinder Singh ml->acl_delete.field_value[3].mask_range.u32 =
2520a3a95b7dSJasvinder Singh sa32_depth[2];
2521a3a95b7dSJasvinder Singh ml->acl_delete.field_value[4].value.u32 =
2522223be676SReshma Pattan rte_be_to_cpu_32(sa32[3]);
2523a3a95b7dSJasvinder Singh ml->acl_delete.field_value[4].mask_range.u32 =
2524a3a95b7dSJasvinder Singh sa32_depth[3];
2525a3a95b7dSJasvinder Singh
2526a3a95b7dSJasvinder Singh ml->acl_delete.field_value[5].value.u32 =
2527223be676SReshma Pattan rte_be_to_cpu_32(da32[0]);
2528a3a95b7dSJasvinder Singh ml->acl_delete.field_value[5].mask_range.u32 =
2529a3a95b7dSJasvinder Singh da32_depth[0];
2530a3a95b7dSJasvinder Singh ml->acl_delete.field_value[6].value.u32 =
2531223be676SReshma Pattan rte_be_to_cpu_32(da32[1]);
2532a3a95b7dSJasvinder Singh ml->acl_delete.field_value[6].mask_range.u32 =
2533a3a95b7dSJasvinder Singh da32_depth[1];
2534a3a95b7dSJasvinder Singh ml->acl_delete.field_value[7].value.u32 =
2535223be676SReshma Pattan rte_be_to_cpu_32(da32[2]);
2536a3a95b7dSJasvinder Singh ml->acl_delete.field_value[7].mask_range.u32 =
2537a3a95b7dSJasvinder Singh da32_depth[2];
2538a3a95b7dSJasvinder Singh ml->acl_delete.field_value[8].value.u32 =
2539223be676SReshma Pattan rte_be_to_cpu_32(da32[3]);
2540a3a95b7dSJasvinder Singh ml->acl_delete.field_value[8].mask_range.u32 =
2541a3a95b7dSJasvinder Singh da32_depth[3];
2542a3a95b7dSJasvinder Singh
2543a3a95b7dSJasvinder Singh ml->acl_delete.field_value[9].value.u16 =
2544a3a95b7dSJasvinder Singh mh->match.acl.sp0;
2545a3a95b7dSJasvinder Singh ml->acl_delete.field_value[9].mask_range.u16 =
2546a3a95b7dSJasvinder Singh mh->match.acl.sp1;
2547a3a95b7dSJasvinder Singh
2548a3a95b7dSJasvinder Singh ml->acl_delete.field_value[10].value.u16 =
2549a3a95b7dSJasvinder Singh mh->match.acl.dp0;
2550a3a95b7dSJasvinder Singh ml->acl_delete.field_value[10].mask_range.u16 =
2551a3a95b7dSJasvinder Singh mh->match.acl.dp1;
2552a3a95b7dSJasvinder Singh }
2553a3a95b7dSJasvinder Singh return 0;
2554a3a95b7dSJasvinder Singh
2555a3a95b7dSJasvinder Singh case TABLE_ARRAY:
2556a3a95b7dSJasvinder Singh ml->array.pos = mh->match.array.pos;
2557a3a95b7dSJasvinder Singh return 0;
2558a3a95b7dSJasvinder Singh
2559a3a95b7dSJasvinder Singh case TABLE_HASH:
2560a3a95b7dSJasvinder Singh memcpy(ml->hash, mh->match.hash.key, sizeof(ml->hash));
2561a3a95b7dSJasvinder Singh return 0;
2562a3a95b7dSJasvinder Singh
2563a3a95b7dSJasvinder Singh case TABLE_LPM:
2564a3a95b7dSJasvinder Singh if (mh->match.lpm.ip_version) {
2565a3a95b7dSJasvinder Singh ml->lpm_ipv4.ip = mh->match.lpm.ipv4;
2566a3a95b7dSJasvinder Singh ml->lpm_ipv4.depth = mh->match.lpm.depth;
2567a3a95b7dSJasvinder Singh } else {
2568a3a95b7dSJasvinder Singh memcpy(ml->lpm_ipv6.ip,
2569a3a95b7dSJasvinder Singh mh->match.lpm.ipv6, sizeof(ml->lpm_ipv6.ip));
2570a3a95b7dSJasvinder Singh ml->lpm_ipv6.depth = mh->match.lpm.depth;
2571a3a95b7dSJasvinder Singh }
2572a3a95b7dSJasvinder Singh
2573a3a95b7dSJasvinder Singh return 0;
2574a3a95b7dSJasvinder Singh
2575a3a95b7dSJasvinder Singh default:
2576a3a95b7dSJasvinder Singh return -1;
2577a3a95b7dSJasvinder Singh }
2578a3a95b7dSJasvinder Singh }
2579a3a95b7dSJasvinder Singh
2580f68a1d3fSJasvinder Singh static int
action_convert(struct rte_table_action * a,struct table_rule_action * action,struct rte_pipeline_table_entry * data)2581f68a1d3fSJasvinder Singh action_convert(struct rte_table_action *a,
2582f68a1d3fSJasvinder Singh struct table_rule_action *action,
2583f68a1d3fSJasvinder Singh struct rte_pipeline_table_entry *data)
2584f68a1d3fSJasvinder Singh {
2585f68a1d3fSJasvinder Singh int status;
2586f68a1d3fSJasvinder Singh
2587f68a1d3fSJasvinder Singh /* Apply actions */
2588f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
2589f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2590f68a1d3fSJasvinder Singh data,
2591f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_FWD,
2592f68a1d3fSJasvinder Singh &action->fwd);
2593f68a1d3fSJasvinder Singh
2594f68a1d3fSJasvinder Singh if (status)
2595f68a1d3fSJasvinder Singh return status;
2596f68a1d3fSJasvinder Singh }
2597f68a1d3fSJasvinder Singh
2598f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
2599f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2600f68a1d3fSJasvinder Singh data,
2601f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_LB,
2602f68a1d3fSJasvinder Singh &action->lb);
2603f68a1d3fSJasvinder Singh
2604f68a1d3fSJasvinder Singh if (status)
2605f68a1d3fSJasvinder Singh return status;
2606f68a1d3fSJasvinder Singh }
2607f68a1d3fSJasvinder Singh
2608f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
2609f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2610f68a1d3fSJasvinder Singh data,
2611f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_MTR,
2612f68a1d3fSJasvinder Singh &action->mtr);
2613f68a1d3fSJasvinder Singh
2614f68a1d3fSJasvinder Singh if (status)
2615f68a1d3fSJasvinder Singh return status;
2616f68a1d3fSJasvinder Singh }
2617f68a1d3fSJasvinder Singh
2618f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
2619f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2620f68a1d3fSJasvinder Singh data,
2621f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_TM,
2622f68a1d3fSJasvinder Singh &action->tm);
2623f68a1d3fSJasvinder Singh
2624f68a1d3fSJasvinder Singh if (status)
2625f68a1d3fSJasvinder Singh return status;
2626f68a1d3fSJasvinder Singh }
2627f68a1d3fSJasvinder Singh
2628f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
2629f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2630f68a1d3fSJasvinder Singh data,
2631f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_ENCAP,
2632f68a1d3fSJasvinder Singh &action->encap);
2633f68a1d3fSJasvinder Singh
2634f68a1d3fSJasvinder Singh if (status)
2635f68a1d3fSJasvinder Singh return status;
2636f68a1d3fSJasvinder Singh }
2637f68a1d3fSJasvinder Singh
2638f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
2639f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2640f68a1d3fSJasvinder Singh data,
2641f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_NAT,
2642f68a1d3fSJasvinder Singh &action->nat);
2643f68a1d3fSJasvinder Singh
2644f68a1d3fSJasvinder Singh if (status)
2645f68a1d3fSJasvinder Singh return status;
2646f68a1d3fSJasvinder Singh }
2647f68a1d3fSJasvinder Singh
2648f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
2649f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2650f68a1d3fSJasvinder Singh data,
2651f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_TTL,
2652f68a1d3fSJasvinder Singh &action->ttl);
2653f68a1d3fSJasvinder Singh
2654f68a1d3fSJasvinder Singh if (status)
2655f68a1d3fSJasvinder Singh return status;
2656f68a1d3fSJasvinder Singh }
2657f68a1d3fSJasvinder Singh
2658f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
2659f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2660f68a1d3fSJasvinder Singh data,
2661f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_STATS,
2662f68a1d3fSJasvinder Singh &action->stats);
2663f68a1d3fSJasvinder Singh
2664f68a1d3fSJasvinder Singh if (status)
2665f68a1d3fSJasvinder Singh return status;
2666f68a1d3fSJasvinder Singh }
2667f68a1d3fSJasvinder Singh
2668f68a1d3fSJasvinder Singh if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
2669f68a1d3fSJasvinder Singh status = rte_table_action_apply(a,
2670f68a1d3fSJasvinder Singh data,
2671f68a1d3fSJasvinder Singh RTE_TABLE_ACTION_TIME,
2672f68a1d3fSJasvinder Singh &action->time);
2673f68a1d3fSJasvinder Singh
2674f68a1d3fSJasvinder Singh if (status)
2675f68a1d3fSJasvinder Singh return status;
2676f68a1d3fSJasvinder Singh }
2677f68a1d3fSJasvinder Singh
2678d46fe944SFan Zhang if (action->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
2679d46fe944SFan Zhang status = rte_table_action_apply(a,
2680d46fe944SFan Zhang data,
2681d46fe944SFan Zhang RTE_TABLE_ACTION_SYM_CRYPTO,
2682d46fe944SFan Zhang &action->sym_crypto);
2683d46fe944SFan Zhang
2684d46fe944SFan Zhang if (status)
2685d46fe944SFan Zhang return status;
2686d46fe944SFan Zhang }
2687d46fe944SFan Zhang
26881bdf2632SCristian Dumitrescu if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
26891bdf2632SCristian Dumitrescu status = rte_table_action_apply(a,
26901bdf2632SCristian Dumitrescu data,
26911bdf2632SCristian Dumitrescu RTE_TABLE_ACTION_TAG,
26921bdf2632SCristian Dumitrescu &action->tag);
26931bdf2632SCristian Dumitrescu
26941bdf2632SCristian Dumitrescu if (status)
26951bdf2632SCristian Dumitrescu return status;
26961bdf2632SCristian Dumitrescu }
26971bdf2632SCristian Dumitrescu
2698d5ed626fSCristian Dumitrescu if (action->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
2699d5ed626fSCristian Dumitrescu status = rte_table_action_apply(a,
2700d5ed626fSCristian Dumitrescu data,
2701d5ed626fSCristian Dumitrescu RTE_TABLE_ACTION_DECAP,
2702d5ed626fSCristian Dumitrescu &action->decap);
2703d5ed626fSCristian Dumitrescu
2704d5ed626fSCristian Dumitrescu if (status)
2705d5ed626fSCristian Dumitrescu return status;
2706d5ed626fSCristian Dumitrescu }
2707d5ed626fSCristian Dumitrescu
2708f68a1d3fSJasvinder Singh return 0;
2709f68a1d3fSJasvinder Singh }
2710f68a1d3fSJasvinder Singh
2711a3a95b7dSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_add(struct pipeline_data * p,struct pipeline_msg_req * req)2712a3a95b7dSJasvinder Singh pipeline_msg_handle_table_rule_add(struct pipeline_data *p,
2713a3a95b7dSJasvinder Singh struct pipeline_msg_req *req)
2714a3a95b7dSJasvinder Singh {
2715a3a95b7dSJasvinder Singh union table_rule_match_low_level match_ll;
2716a3a95b7dSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2717a3a95b7dSJasvinder Singh struct table_rule_match *match = &req->table_rule_add.match;
2718a3a95b7dSJasvinder Singh struct table_rule_action *action = &req->table_rule_add.action;
2719a3a95b7dSJasvinder Singh struct rte_pipeline_table_entry *data_in, *data_out;
2720a3a95b7dSJasvinder Singh uint32_t table_id = req->id;
2721a3a95b7dSJasvinder Singh int key_found, status;
2722a3a95b7dSJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
2723a3a95b7dSJasvinder Singh
2724a3a95b7dSJasvinder Singh /* Apply actions */
2725a3a95b7dSJasvinder Singh memset(p->buffer, 0, sizeof(p->buffer));
2726a3a95b7dSJasvinder Singh data_in = (struct rte_pipeline_table_entry *) p->buffer;
2727a3a95b7dSJasvinder Singh
2728a3a95b7dSJasvinder Singh status = match_convert(match, &match_ll, 1);
2729a3a95b7dSJasvinder Singh if (status) {
2730a3a95b7dSJasvinder Singh rsp->status = -1;
2731a3a95b7dSJasvinder Singh return rsp;
2732a3a95b7dSJasvinder Singh }
2733a3a95b7dSJasvinder Singh
2734f68a1d3fSJasvinder Singh status = action_convert(a, action, data_in);
2735f68a1d3fSJasvinder Singh if (status) {
2736f68a1d3fSJasvinder Singh rsp->status = -1;
2737f68a1d3fSJasvinder Singh return rsp;
2738f68a1d3fSJasvinder Singh }
2739f68a1d3fSJasvinder Singh
2740a3a95b7dSJasvinder Singh status = rte_pipeline_table_entry_add(p->p,
2741a3a95b7dSJasvinder Singh table_id,
2742a3a95b7dSJasvinder Singh &match_ll,
2743a3a95b7dSJasvinder Singh data_in,
2744a3a95b7dSJasvinder Singh &key_found,
2745a3a95b7dSJasvinder Singh &data_out);
2746a3a95b7dSJasvinder Singh if (status) {
2747a3a95b7dSJasvinder Singh rsp->status = -1;
2748a3a95b7dSJasvinder Singh return rsp;
2749a3a95b7dSJasvinder Singh }
2750a3a95b7dSJasvinder Singh
2751a3a95b7dSJasvinder Singh /* Write response */
2752a3a95b7dSJasvinder Singh rsp->status = 0;
2753a3a95b7dSJasvinder Singh rsp->table_rule_add.data = data_out;
2754a3a95b7dSJasvinder Singh
2755a3a95b7dSJasvinder Singh return rsp;
2756a3a95b7dSJasvinder Singh }
2757a3a95b7dSJasvinder Singh
2758a3a95b7dSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_add_default(struct pipeline_data * p,struct pipeline_msg_req * req)2759a3a95b7dSJasvinder Singh pipeline_msg_handle_table_rule_add_default(struct pipeline_data *p,
2760a3a95b7dSJasvinder Singh struct pipeline_msg_req *req)
2761a3a95b7dSJasvinder Singh {
2762a3a95b7dSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2763a3a95b7dSJasvinder Singh struct table_rule_action *action = &req->table_rule_add_default.action;
2764a3a95b7dSJasvinder Singh struct rte_pipeline_table_entry *data_in, *data_out;
2765a3a95b7dSJasvinder Singh uint32_t table_id = req->id;
2766a3a95b7dSJasvinder Singh int status;
2767a3a95b7dSJasvinder Singh
2768a3a95b7dSJasvinder Singh /* Apply actions */
2769a3a95b7dSJasvinder Singh memset(p->buffer, 0, sizeof(p->buffer));
2770a3a95b7dSJasvinder Singh data_in = (struct rte_pipeline_table_entry *) p->buffer;
2771a3a95b7dSJasvinder Singh
2772a3a95b7dSJasvinder Singh data_in->action = action->fwd.action;
2773a3a95b7dSJasvinder Singh if (action->fwd.action == RTE_PIPELINE_ACTION_PORT)
2774a3a95b7dSJasvinder Singh data_in->port_id = action->fwd.id;
2775a3a95b7dSJasvinder Singh if (action->fwd.action == RTE_PIPELINE_ACTION_TABLE)
2776a3a95b7dSJasvinder Singh data_in->table_id = action->fwd.id;
2777a3a95b7dSJasvinder Singh
2778a3a95b7dSJasvinder Singh /* Add default rule to table */
2779a3a95b7dSJasvinder Singh status = rte_pipeline_table_default_entry_add(p->p,
2780a3a95b7dSJasvinder Singh table_id,
2781a3a95b7dSJasvinder Singh data_in,
2782a3a95b7dSJasvinder Singh &data_out);
2783a3a95b7dSJasvinder Singh if (status) {
2784a3a95b7dSJasvinder Singh rsp->status = -1;
2785a3a95b7dSJasvinder Singh return rsp;
2786a3a95b7dSJasvinder Singh }
2787a3a95b7dSJasvinder Singh
2788a3a95b7dSJasvinder Singh /* Write response */
2789a3a95b7dSJasvinder Singh rsp->status = 0;
2790a3a95b7dSJasvinder Singh rsp->table_rule_add_default.data = data_out;
2791a3a95b7dSJasvinder Singh
2792a3a95b7dSJasvinder Singh return rsp;
2793a3a95b7dSJasvinder Singh }
2794a3a95b7dSJasvinder Singh
2795f634e4c5SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_add_bulk(struct pipeline_data * p,struct pipeline_msg_req * req)27963186282fSJasvinder Singh pipeline_msg_handle_table_rule_add_bulk(struct pipeline_data *p,
27973186282fSJasvinder Singh struct pipeline_msg_req *req)
27983186282fSJasvinder Singh {
27993186282fSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
28003186282fSJasvinder Singh
28013186282fSJasvinder Singh uint32_t table_id = req->id;
280227b333b2SCristian Dumitrescu struct table_rule_list *list = req->table_rule_add_bulk.list;
28033186282fSJasvinder Singh uint32_t bulk = req->table_rule_add_bulk.bulk;
28043186282fSJasvinder Singh
280527b333b2SCristian Dumitrescu uint32_t n_rules_added;
280627b333b2SCristian Dumitrescu int status;
28073186282fSJasvinder Singh
280827b333b2SCristian Dumitrescu struct table_ll table_ll = {
280927b333b2SCristian Dumitrescu .p = p->p,
281027b333b2SCristian Dumitrescu .table_id = table_id,
281127b333b2SCristian Dumitrescu .a = p->table_data[table_id].a,
281227b333b2SCristian Dumitrescu .bulk_supported = bulk,
281327b333b2SCristian Dumitrescu };
28143186282fSJasvinder Singh
281527b333b2SCristian Dumitrescu status = table_rule_add_bulk_ll(&table_ll, list, &n_rules_added);
28163186282fSJasvinder Singh if (status) {
281727b333b2SCristian Dumitrescu rsp->status = -1;
281827b333b2SCristian Dumitrescu rsp->table_rule_add_bulk.n_rules = 0;
281927b333b2SCristian Dumitrescu return rsp;
28203186282fSJasvinder Singh }
28213186282fSJasvinder Singh
28223186282fSJasvinder Singh /* Write response */
28233186282fSJasvinder Singh rsp->status = 0;
282427b333b2SCristian Dumitrescu rsp->table_rule_add_bulk.n_rules = n_rules_added;
28253186282fSJasvinder Singh return rsp;
28263186282fSJasvinder Singh }
28273186282fSJasvinder Singh
28283186282fSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_delete(struct pipeline_data * p,struct pipeline_msg_req * req)2829f634e4c5SJasvinder Singh pipeline_msg_handle_table_rule_delete(struct pipeline_data *p,
2830f634e4c5SJasvinder Singh struct pipeline_msg_req *req)
2831f634e4c5SJasvinder Singh {
2832f634e4c5SJasvinder Singh union table_rule_match_low_level match_ll;
2833f634e4c5SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2834f634e4c5SJasvinder Singh struct table_rule_match *match = &req->table_rule_delete.match;
2835f634e4c5SJasvinder Singh uint32_t table_id = req->id;
2836f634e4c5SJasvinder Singh int key_found, status;
2837f634e4c5SJasvinder Singh
2838f634e4c5SJasvinder Singh status = match_convert(match, &match_ll, 0);
2839f634e4c5SJasvinder Singh if (status) {
2840f634e4c5SJasvinder Singh rsp->status = -1;
2841f634e4c5SJasvinder Singh return rsp;
2842f634e4c5SJasvinder Singh }
2843f634e4c5SJasvinder Singh
2844f634e4c5SJasvinder Singh rsp->status = rte_pipeline_table_entry_delete(p->p,
2845f634e4c5SJasvinder Singh table_id,
2846f634e4c5SJasvinder Singh &match_ll,
2847f634e4c5SJasvinder Singh &key_found,
2848f634e4c5SJasvinder Singh NULL);
2849f634e4c5SJasvinder Singh
2850f634e4c5SJasvinder Singh return rsp;
2851f634e4c5SJasvinder Singh }
2852f634e4c5SJasvinder Singh
2853f634e4c5SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_delete_default(struct pipeline_data * p,struct pipeline_msg_req * req)2854f634e4c5SJasvinder Singh pipeline_msg_handle_table_rule_delete_default(struct pipeline_data *p,
2855f634e4c5SJasvinder Singh struct pipeline_msg_req *req)
2856f634e4c5SJasvinder Singh {
2857f634e4c5SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2858f634e4c5SJasvinder Singh uint32_t table_id = req->id;
2859f634e4c5SJasvinder Singh
2860f634e4c5SJasvinder Singh rsp->status = rte_pipeline_table_default_entry_delete(p->p,
2861f634e4c5SJasvinder Singh table_id,
2862f634e4c5SJasvinder Singh NULL);
2863f634e4c5SJasvinder Singh
2864f634e4c5SJasvinder Singh return rsp;
2865f634e4c5SJasvinder Singh }
2866f634e4c5SJasvinder Singh
2867c64b9121SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_stats_read(struct pipeline_data * p,struct pipeline_msg_req * req)2868c64b9121SJasvinder Singh pipeline_msg_handle_table_rule_stats_read(struct pipeline_data *p,
2869c64b9121SJasvinder Singh struct pipeline_msg_req *req)
2870c64b9121SJasvinder Singh {
2871c64b9121SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2872c64b9121SJasvinder Singh uint32_t table_id = req->id;
2873c64b9121SJasvinder Singh void *data = req->table_rule_stats_read.data;
2874c64b9121SJasvinder Singh int clear = req->table_rule_stats_read.clear;
2875c64b9121SJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
2876c64b9121SJasvinder Singh
2877c64b9121SJasvinder Singh rsp->status = rte_table_action_stats_read(a,
2878c64b9121SJasvinder Singh data,
2879c64b9121SJasvinder Singh &rsp->table_rule_stats_read.stats,
2880c64b9121SJasvinder Singh clear);
2881c64b9121SJasvinder Singh
2882c64b9121SJasvinder Singh return rsp;
2883c64b9121SJasvinder Singh }
2884c64b9121SJasvinder Singh
28857e11393eSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_mtr_profile_add(struct pipeline_data * p,struct pipeline_msg_req * req)28867e11393eSJasvinder Singh pipeline_msg_handle_table_mtr_profile_add(struct pipeline_data *p,
28877e11393eSJasvinder Singh struct pipeline_msg_req *req)
28887e11393eSJasvinder Singh {
28897e11393eSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
28907e11393eSJasvinder Singh uint32_t table_id = req->id;
28917e11393eSJasvinder Singh uint32_t meter_profile_id = req->table_mtr_profile_add.meter_profile_id;
28927e11393eSJasvinder Singh struct rte_table_action_meter_profile *profile =
28937e11393eSJasvinder Singh &req->table_mtr_profile_add.profile;
28947e11393eSJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
28957e11393eSJasvinder Singh
28967e11393eSJasvinder Singh rsp->status = rte_table_action_meter_profile_add(a,
28977e11393eSJasvinder Singh meter_profile_id,
28987e11393eSJasvinder Singh profile);
28997e11393eSJasvinder Singh
29007e11393eSJasvinder Singh return rsp;
29017e11393eSJasvinder Singh }
29027e11393eSJasvinder Singh
29037e11393eSJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_mtr_profile_delete(struct pipeline_data * p,struct pipeline_msg_req * req)29047e11393eSJasvinder Singh pipeline_msg_handle_table_mtr_profile_delete(struct pipeline_data *p,
29057e11393eSJasvinder Singh struct pipeline_msg_req *req)
29067e11393eSJasvinder Singh {
29077e11393eSJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
29087e11393eSJasvinder Singh uint32_t table_id = req->id;
29097e11393eSJasvinder Singh uint32_t meter_profile_id =
29107e11393eSJasvinder Singh req->table_mtr_profile_delete.meter_profile_id;
29117e11393eSJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
29127e11393eSJasvinder Singh
29137e11393eSJasvinder Singh rsp->status = rte_table_action_meter_profile_delete(a,
29147e11393eSJasvinder Singh meter_profile_id);
29157e11393eSJasvinder Singh
29167e11393eSJasvinder Singh return rsp;
29177e11393eSJasvinder Singh }
29187e11393eSJasvinder Singh
2919e92058d6SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_mtr_read(struct pipeline_data * p,struct pipeline_msg_req * req)2920e92058d6SJasvinder Singh pipeline_msg_handle_table_rule_mtr_read(struct pipeline_data *p,
2921e92058d6SJasvinder Singh struct pipeline_msg_req *req)
2922e92058d6SJasvinder Singh {
2923e92058d6SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2924e92058d6SJasvinder Singh uint32_t table_id = req->id;
2925e92058d6SJasvinder Singh void *data = req->table_rule_mtr_read.data;
2926e92058d6SJasvinder Singh uint32_t tc_mask = req->table_rule_mtr_read.tc_mask;
2927e92058d6SJasvinder Singh int clear = req->table_rule_mtr_read.clear;
2928e92058d6SJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
2929e92058d6SJasvinder Singh
2930e92058d6SJasvinder Singh rsp->status = rte_table_action_meter_read(a,
2931e92058d6SJasvinder Singh data,
2932e92058d6SJasvinder Singh tc_mask,
2933e92058d6SJasvinder Singh &rsp->table_rule_mtr_read.stats,
2934e92058d6SJasvinder Singh clear);
2935e92058d6SJasvinder Singh
2936e92058d6SJasvinder Singh return rsp;
2937e92058d6SJasvinder Singh }
2938e92058d6SJasvinder Singh
29392b82ef48SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_dscp_table_update(struct pipeline_data * p,struct pipeline_msg_req * req)29402b82ef48SJasvinder Singh pipeline_msg_handle_table_dscp_table_update(struct pipeline_data *p,
29412b82ef48SJasvinder Singh struct pipeline_msg_req *req)
29422b82ef48SJasvinder Singh {
29432b82ef48SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
29442b82ef48SJasvinder Singh uint32_t table_id = req->id;
29452b82ef48SJasvinder Singh uint64_t dscp_mask = req->table_dscp_table_update.dscp_mask;
29462b82ef48SJasvinder Singh struct rte_table_action_dscp_table *dscp_table =
29472b82ef48SJasvinder Singh &req->table_dscp_table_update.dscp_table;
29482b82ef48SJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
29492b82ef48SJasvinder Singh
29502b82ef48SJasvinder Singh rsp->status = rte_table_action_dscp_table_update(a,
29512b82ef48SJasvinder Singh dscp_mask,
29522b82ef48SJasvinder Singh dscp_table);
29532b82ef48SJasvinder Singh
29542b82ef48SJasvinder Singh return rsp;
29552b82ef48SJasvinder Singh }
29562b82ef48SJasvinder Singh
2957d0d306c7SJasvinder Singh static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_ttl_read(struct pipeline_data * p,struct pipeline_msg_req * req)2958d0d306c7SJasvinder Singh pipeline_msg_handle_table_rule_ttl_read(struct pipeline_data *p,
2959d0d306c7SJasvinder Singh struct pipeline_msg_req *req)
2960d0d306c7SJasvinder Singh {
2961d0d306c7SJasvinder Singh struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2962d0d306c7SJasvinder Singh uint32_t table_id = req->id;
2963d0d306c7SJasvinder Singh void *data = req->table_rule_ttl_read.data;
2964d0d306c7SJasvinder Singh int clear = req->table_rule_ttl_read.clear;
2965d0d306c7SJasvinder Singh struct rte_table_action *a = p->table_data[table_id].a;
2966d0d306c7SJasvinder Singh
2967d0d306c7SJasvinder Singh rsp->status = rte_table_action_ttl_read(a,
2968d0d306c7SJasvinder Singh data,
2969d0d306c7SJasvinder Singh &rsp->table_rule_ttl_read.stats,
2970d0d306c7SJasvinder Singh clear);
2971d0d306c7SJasvinder Singh
2972d0d306c7SJasvinder Singh return rsp;
2973d0d306c7SJasvinder Singh }
2974d0d306c7SJasvinder Singh
2975a3169ee5SCristian Dumitrescu static struct pipeline_msg_rsp *
pipeline_msg_handle_table_rule_time_read(struct pipeline_data * p,struct pipeline_msg_req * req)2976a3169ee5SCristian Dumitrescu pipeline_msg_handle_table_rule_time_read(struct pipeline_data *p,
2977a3169ee5SCristian Dumitrescu struct pipeline_msg_req *req)
2978a3169ee5SCristian Dumitrescu {
2979a3169ee5SCristian Dumitrescu struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
2980a3169ee5SCristian Dumitrescu uint32_t table_id = req->id;
2981a3169ee5SCristian Dumitrescu void *data = req->table_rule_time_read.data;
2982a3169ee5SCristian Dumitrescu struct rte_table_action *a = p->table_data[table_id].a;
2983a3169ee5SCristian Dumitrescu
2984a3169ee5SCristian Dumitrescu rsp->status = rte_table_action_time_read(a,
2985a3169ee5SCristian Dumitrescu data,
2986a3169ee5SCristian Dumitrescu &rsp->table_rule_time_read.timestamp);
2987a3169ee5SCristian Dumitrescu
2988a3169ee5SCristian Dumitrescu return rsp;
2989a3169ee5SCristian Dumitrescu }
2990a3169ee5SCristian Dumitrescu
2991a8bd581dSJasvinder Singh static void
pipeline_msg_handle(struct pipeline_data * p)2992a8bd581dSJasvinder Singh pipeline_msg_handle(struct pipeline_data *p)
2993a8bd581dSJasvinder Singh {
2994a8bd581dSJasvinder Singh for ( ; ; ) {
2995a8bd581dSJasvinder Singh struct pipeline_msg_req *req;
2996a8bd581dSJasvinder Singh struct pipeline_msg_rsp *rsp;
2997a8bd581dSJasvinder Singh
2998a8bd581dSJasvinder Singh req = pipeline_msg_recv(p->msgq_req);
2999a8bd581dSJasvinder Singh if (req == NULL)
3000a8bd581dSJasvinder Singh break;
3001a8bd581dSJasvinder Singh
3002a8bd581dSJasvinder Singh switch (req->type) {
300350e73d05SJasvinder Singh case PIPELINE_REQ_PORT_IN_STATS_READ:
300450e73d05SJasvinder Singh rsp = pipeline_msg_handle_port_in_stats_read(p, req);
300550e73d05SJasvinder Singh break;
300650e73d05SJasvinder Singh
30076b1b3c3cSJasvinder Singh case PIPELINE_REQ_PORT_IN_ENABLE:
30086b1b3c3cSJasvinder Singh rsp = pipeline_msg_handle_port_in_enable(p, req);
30096b1b3c3cSJasvinder Singh break;
30106b1b3c3cSJasvinder Singh
30116b1b3c3cSJasvinder Singh case PIPELINE_REQ_PORT_IN_DISABLE:
30126b1b3c3cSJasvinder Singh rsp = pipeline_msg_handle_port_in_disable(p, req);
30136b1b3c3cSJasvinder Singh break;
30146b1b3c3cSJasvinder Singh
301550e73d05SJasvinder Singh case PIPELINE_REQ_PORT_OUT_STATS_READ:
301650e73d05SJasvinder Singh rsp = pipeline_msg_handle_port_out_stats_read(p, req);
301750e73d05SJasvinder Singh break;
301850e73d05SJasvinder Singh
301950e73d05SJasvinder Singh case PIPELINE_REQ_TABLE_STATS_READ:
302050e73d05SJasvinder Singh rsp = pipeline_msg_handle_table_stats_read(p, req);
302150e73d05SJasvinder Singh break;
302250e73d05SJasvinder Singh
3023a3a95b7dSJasvinder Singh case PIPELINE_REQ_TABLE_RULE_ADD:
3024a3a95b7dSJasvinder Singh rsp = pipeline_msg_handle_table_rule_add(p, req);
3025a3a95b7dSJasvinder Singh break;
3026a3a95b7dSJasvinder Singh
3027a3a95b7dSJasvinder Singh case PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT:
3028a3a95b7dSJasvinder Singh rsp = pipeline_msg_handle_table_rule_add_default(p, req);
3029a3a95b7dSJasvinder Singh break;
303050e73d05SJasvinder Singh
30313186282fSJasvinder Singh case PIPELINE_REQ_TABLE_RULE_ADD_BULK:
30323186282fSJasvinder Singh rsp = pipeline_msg_handle_table_rule_add_bulk(p, req);
30333186282fSJasvinder Singh break;
30343186282fSJasvinder Singh
3035f634e4c5SJasvinder Singh case PIPELINE_REQ_TABLE_RULE_DELETE:
3036f634e4c5SJasvinder Singh rsp = pipeline_msg_handle_table_rule_delete(p, req);
3037f634e4c5SJasvinder Singh break;
3038f634e4c5SJasvinder Singh
3039f634e4c5SJasvinder Singh case PIPELINE_REQ_TABLE_RULE_DELETE_DEFAULT:
3040f634e4c5SJasvinder Singh rsp = pipeline_msg_handle_table_rule_delete_default(p, req);
3041f634e4c5SJasvinder Singh break;
3042f634e4c5SJasvinder Singh
3043c64b9121SJasvinder Singh case PIPELINE_REQ_TABLE_RULE_STATS_READ:
3044c64b9121SJasvinder Singh rsp = pipeline_msg_handle_table_rule_stats_read(p, req);
3045c64b9121SJasvinder Singh break;
3046c64b9121SJasvinder Singh
30477e11393eSJasvinder Singh case PIPELINE_REQ_TABLE_MTR_PROFILE_ADD:
30487e11393eSJasvinder Singh rsp = pipeline_msg_handle_table_mtr_profile_add(p, req);
30497e11393eSJasvinder Singh break;
30507e11393eSJasvinder Singh
30517e11393eSJasvinder Singh case PIPELINE_REQ_TABLE_MTR_PROFILE_DELETE:
30527e11393eSJasvinder Singh rsp = pipeline_msg_handle_table_mtr_profile_delete(p, req);
30537e11393eSJasvinder Singh break;
30547e11393eSJasvinder Singh
3055e92058d6SJasvinder Singh case PIPELINE_REQ_TABLE_RULE_MTR_READ:
3056e92058d6SJasvinder Singh rsp = pipeline_msg_handle_table_rule_mtr_read(p, req);
3057e92058d6SJasvinder Singh break;
3058e92058d6SJasvinder Singh
30592b82ef48SJasvinder Singh case PIPELINE_REQ_TABLE_DSCP_TABLE_UPDATE:
30602b82ef48SJasvinder Singh rsp = pipeline_msg_handle_table_dscp_table_update(p, req);
30612b82ef48SJasvinder Singh break;
30622b82ef48SJasvinder Singh
3063d0d306c7SJasvinder Singh case PIPELINE_REQ_TABLE_RULE_TTL_READ:
3064d0d306c7SJasvinder Singh rsp = pipeline_msg_handle_table_rule_ttl_read(p, req);
3065d0d306c7SJasvinder Singh break;
3066d0d306c7SJasvinder Singh
3067a3169ee5SCristian Dumitrescu case PIPELINE_REQ_TABLE_RULE_TIME_READ:
3068a3169ee5SCristian Dumitrescu rsp = pipeline_msg_handle_table_rule_time_read(p, req);
3069a3169ee5SCristian Dumitrescu break;
3070a3169ee5SCristian Dumitrescu
3071a8bd581dSJasvinder Singh default:
3072a8bd581dSJasvinder Singh rsp = (struct pipeline_msg_rsp *) req;
3073a8bd581dSJasvinder Singh rsp->status = -1;
3074a8bd581dSJasvinder Singh }
3075a8bd581dSJasvinder Singh
3076a8bd581dSJasvinder Singh pipeline_msg_send(p->msgq_rsp, rsp);
3077a8bd581dSJasvinder Singh }
3078a8bd581dSJasvinder Singh }
3079a8bd581dSJasvinder Singh
3080a8bd581dSJasvinder Singh /**
3081a8bd581dSJasvinder Singh * Data plane threads: main
3082a8bd581dSJasvinder Singh */
3083a8bd581dSJasvinder Singh int
thread_main(void * arg __rte_unused)3084a8bd581dSJasvinder Singh thread_main(void *arg __rte_unused)
3085a8bd581dSJasvinder Singh {
3086a8bd581dSJasvinder Singh struct thread_data *t;
3087a8bd581dSJasvinder Singh uint32_t thread_id, i;
3088a8bd581dSJasvinder Singh
3089a8bd581dSJasvinder Singh thread_id = rte_lcore_id();
3090a8bd581dSJasvinder Singh t = &thread_data[thread_id];
3091a8bd581dSJasvinder Singh
3092a8bd581dSJasvinder Singh /* Dispatch loop */
3093a8bd581dSJasvinder Singh for (i = 0; ; i++) {
3094a8bd581dSJasvinder Singh uint32_t j;
3095a8bd581dSJasvinder Singh
3096a8bd581dSJasvinder Singh /* Data Plane */
3097a8bd581dSJasvinder Singh for (j = 0; j < t->n_pipelines; j++)
3098a8bd581dSJasvinder Singh rte_pipeline_run(t->p[j]);
3099a8bd581dSJasvinder Singh
3100a8bd581dSJasvinder Singh /* Control Plane */
3101a8bd581dSJasvinder Singh if ((i & 0xF) == 0) {
3102a8bd581dSJasvinder Singh uint64_t time = rte_get_tsc_cycles();
3103a8bd581dSJasvinder Singh uint64_t time_next_min = UINT64_MAX;
3104a8bd581dSJasvinder Singh
3105a8bd581dSJasvinder Singh if (time < t->time_next_min)
3106a8bd581dSJasvinder Singh continue;
3107a8bd581dSJasvinder Singh
3108a8bd581dSJasvinder Singh /* Pipeline message queues */
3109a8bd581dSJasvinder Singh for (j = 0; j < t->n_pipelines; j++) {
3110a8bd581dSJasvinder Singh struct pipeline_data *p =
3111a8bd581dSJasvinder Singh &t->pipeline_data[j];
3112a8bd581dSJasvinder Singh uint64_t time_next = p->time_next;
3113a8bd581dSJasvinder Singh
3114a8bd581dSJasvinder Singh if (time_next <= time) {
3115a8bd581dSJasvinder Singh pipeline_msg_handle(p);
3116a8bd581dSJasvinder Singh rte_pipeline_flush(p->p);
3117a8bd581dSJasvinder Singh time_next = time + p->timer_period;
3118a8bd581dSJasvinder Singh p->time_next = time_next;
3119a8bd581dSJasvinder Singh }
3120a8bd581dSJasvinder Singh
3121a8bd581dSJasvinder Singh if (time_next < time_next_min)
3122a8bd581dSJasvinder Singh time_next_min = time_next;
3123a8bd581dSJasvinder Singh }
3124a8bd581dSJasvinder Singh
3125a8bd581dSJasvinder Singh /* Thread message queues */
3126a8bd581dSJasvinder Singh {
3127a8bd581dSJasvinder Singh uint64_t time_next = t->time_next;
3128a8bd581dSJasvinder Singh
3129a8bd581dSJasvinder Singh if (time_next <= time) {
3130a8bd581dSJasvinder Singh thread_msg_handle(t);
3131a8bd581dSJasvinder Singh time_next = time + t->timer_period;
3132a8bd581dSJasvinder Singh t->time_next = time_next;
3133a8bd581dSJasvinder Singh }
3134a8bd581dSJasvinder Singh
3135a8bd581dSJasvinder Singh if (time_next < time_next_min)
3136a8bd581dSJasvinder Singh time_next_min = time_next;
3137a8bd581dSJasvinder Singh }
3138a8bd581dSJasvinder Singh
3139a8bd581dSJasvinder Singh t->time_next_min = time_next_min;
3140a8bd581dSJasvinder Singh }
3141a8bd581dSJasvinder Singh }
3142a8bd581dSJasvinder Singh
3143a8bd581dSJasvinder Singh return 0;
3144a8bd581dSJasvinder Singh }
3145