1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_cycles.h>
12 #include <rte_table_acl.h>
13 #include <rte_table_array.h>
14 #include <rte_table_hash.h>
15 #include <rte_table_lpm.h>
16 #include <rte_table_lpm_ipv6.h>
22 #ifndef THREAD_PIPELINES_MAX
23 #define THREAD_PIPELINES_MAX 256
26 #ifndef THREAD_MSGQ_SIZE
27 #define THREAD_MSGQ_SIZE 64
30 #ifndef THREAD_TIMER_PERIOD_MS
31 #define THREAD_TIMER_PERIOD_MS 100
35 * Master thead: data plane thread context
38 struct rte_ring *msgq_req;
39 struct rte_ring *msgq_rsp;
44 static struct thread thread[RTE_MAX_LCORE];
47 * Data plane threads: context
50 struct rte_table_action *a;
53 struct pipeline_data {
54 struct rte_pipeline *p;
55 struct table_data table_data[RTE_PIPELINE_TABLE_MAX];
58 struct rte_ring *msgq_req;
59 struct rte_ring *msgq_rsp;
60 uint64_t timer_period; /* Measured in CPU cycles. */
63 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
67 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
70 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
71 struct rte_ring *msgq_req;
72 struct rte_ring *msgq_rsp;
73 uint64_t timer_period; /* Measured in CPU cycles. */
75 uint64_t time_next_min;
76 } __rte_cache_aligned;
78 static struct thread_data thread_data[RTE_MAX_LCORE];
81 * Master thread: data plane thread init
88 for (i = 0; i < RTE_MAX_LCORE; i++) {
89 struct thread *t = &thread[i];
91 if (!rte_lcore_is_enabled(i))
96 rte_ring_free(t->msgq_req);
99 rte_ring_free(t->msgq_rsp);
108 RTE_LCORE_FOREACH_SLAVE(i) {
110 struct rte_ring *msgq_req, *msgq_rsp;
111 struct thread *t = &thread[i];
112 struct thread_data *t_data = &thread_data[i];
113 uint32_t cpu_id = rte_lcore_to_socket_id(i);
116 snprintf(name, sizeof(name), "THREAD-%04x-MSGQ-REQ", i);
118 msgq_req = rte_ring_create(name,
121 RING_F_SP_ENQ | RING_F_SC_DEQ);
123 if (msgq_req == NULL) {
128 snprintf(name, sizeof(name), "THREAD-%04x-MSGQ-RSP", i);
130 msgq_rsp = rte_ring_create(name,
133 RING_F_SP_ENQ | RING_F_SC_DEQ);
135 if (msgq_rsp == NULL) {
140 /* Master thread records */
141 t->msgq_req = msgq_req;
142 t->msgq_rsp = msgq_rsp;
145 /* Data plane thread records */
146 t_data->n_pipelines = 0;
147 t_data->msgq_req = msgq_req;
148 t_data->msgq_rsp = msgq_rsp;
149 t_data->timer_period =
150 (rte_get_tsc_hz() * THREAD_TIMER_PERIOD_MS) / 1000;
151 t_data->time_next = rte_get_tsc_cycles() + t_data->timer_period;
152 t_data->time_next_min = t_data->time_next;
159 * Master thread & data plane threads: message passing
161 enum thread_req_type {
162 THREAD_REQ_PIPELINE_ENABLE = 0,
163 THREAD_REQ_PIPELINE_DISABLE,
167 struct thread_msg_req {
168 enum thread_req_type type;
172 struct rte_pipeline *p;
174 struct rte_table_action *a;
175 } table[RTE_PIPELINE_TABLE_MAX];
176 struct rte_ring *msgq_req;
177 struct rte_ring *msgq_rsp;
178 uint32_t timer_period_ms;
183 struct rte_pipeline *p;
188 struct thread_msg_rsp {
195 static struct thread_msg_req *
196 thread_msg_alloc(void)
198 size_t size = RTE_MAX(sizeof(struct thread_msg_req),
199 sizeof(struct thread_msg_rsp));
201 return calloc(1, size);
205 thread_msg_free(struct thread_msg_rsp *rsp)
210 static struct thread_msg_rsp *
211 thread_msg_send_recv(uint32_t thread_id,
212 struct thread_msg_req *req)
214 struct thread *t = &thread[thread_id];
215 struct rte_ring *msgq_req = t->msgq_req;
216 struct rte_ring *msgq_rsp = t->msgq_rsp;
217 struct thread_msg_rsp *rsp;
222 status = rte_ring_sp_enqueue(msgq_req, req);
223 } while (status == -ENOBUFS);
227 status = rte_ring_sc_dequeue(msgq_rsp, (void **) &rsp);
228 } while (status != 0);
234 thread_pipeline_enable(uint32_t thread_id,
235 const char *pipeline_name)
237 struct pipeline *p = pipeline_find(pipeline_name);
239 struct thread_msg_req *req;
240 struct thread_msg_rsp *rsp;
244 /* Check input params */
245 if ((thread_id >= RTE_MAX_LCORE) ||
247 (p->n_ports_in == 0) ||
248 (p->n_ports_out == 0) ||
252 t = &thread[thread_id];
253 if ((t->enabled == 0) ||
257 /* Allocate request */
258 req = thread_msg_alloc();
263 req->type = THREAD_REQ_PIPELINE_ENABLE;
264 req->pipeline_enable.p = p->p;
265 for (i = 0; i < p->n_tables; i++)
266 req->pipeline_enable.table[i].a =
268 req->pipeline_enable.msgq_req = p->msgq_req;
269 req->pipeline_enable.msgq_rsp = p->msgq_rsp;
270 req->pipeline_enable.timer_period_ms = p->timer_period_ms;
271 req->pipeline_enable.n_tables = p->n_tables;
273 /* Send request and wait for response */
274 rsp = thread_msg_send_recv(thread_id, req);
279 status = rsp->status;
282 thread_msg_free(rsp);
284 /* Request completion */
288 p->thread_id = thread_id;
295 thread_pipeline_disable(uint32_t thread_id,
296 const char *pipeline_name)
298 struct pipeline *p = pipeline_find(pipeline_name);
300 struct thread_msg_req *req;
301 struct thread_msg_rsp *rsp;
304 /* Check input params */
305 if ((thread_id >= RTE_MAX_LCORE) ||
309 t = &thread[thread_id];
316 if (p->thread_id != thread_id)
319 /* Allocate request */
320 req = thread_msg_alloc();
325 req->type = THREAD_REQ_PIPELINE_DISABLE;
326 req->pipeline_disable.p = p->p;
328 /* Send request and wait for response */
329 rsp = thread_msg_send_recv(thread_id, req);
334 status = rsp->status;
337 thread_msg_free(rsp);
339 /* Request completion */
349 * Data plane threads: message handling
351 static inline struct thread_msg_req *
352 thread_msg_recv(struct rte_ring *msgq_req)
354 struct thread_msg_req *req;
356 int status = rte_ring_sc_dequeue(msgq_req, (void **) &req);
365 thread_msg_send(struct rte_ring *msgq_rsp,
366 struct thread_msg_rsp *rsp)
371 status = rte_ring_sp_enqueue(msgq_rsp, rsp);
372 } while (status == -ENOBUFS);
375 static struct thread_msg_rsp *
376 thread_msg_handle_pipeline_enable(struct thread_data *t,
377 struct thread_msg_req *req)
379 struct thread_msg_rsp *rsp = (struct thread_msg_rsp *) req;
380 struct pipeline_data *p = &t->pipeline_data[t->n_pipelines];
384 if (t->n_pipelines >= THREAD_PIPELINES_MAX) {
389 t->p[t->n_pipelines] = req->pipeline_enable.p;
391 p->p = req->pipeline_enable.p;
392 for (i = 0; i < req->pipeline_enable.n_tables; i++)
394 req->pipeline_enable.table[i].a;
396 p->n_tables = req->pipeline_enable.n_tables;
398 p->msgq_req = req->pipeline_enable.msgq_req;
399 p->msgq_rsp = req->pipeline_enable.msgq_rsp;
401 (rte_get_tsc_hz() * req->pipeline_enable.timer_period_ms) / 1000;
402 p->time_next = rte_get_tsc_cycles() + p->timer_period;
411 static struct thread_msg_rsp *
412 thread_msg_handle_pipeline_disable(struct thread_data *t,
413 struct thread_msg_req *req)
415 struct thread_msg_rsp *rsp = (struct thread_msg_rsp *) req;
416 uint32_t n_pipelines = t->n_pipelines;
417 struct rte_pipeline *pipeline = req->pipeline_disable.p;
421 for (i = 0; i < n_pipelines; i++) {
422 struct pipeline_data *p = &t->pipeline_data[i];
424 if (p->p != pipeline)
427 if (i < n_pipelines - 1) {
428 struct rte_pipeline *pipeline_last =
429 t->p[n_pipelines - 1];
430 struct pipeline_data *p_last =
431 &t->pipeline_data[n_pipelines - 1];
433 t->p[i] = pipeline_last;
434 memcpy(p, p_last, sizeof(*p));
443 /* should not get here */
449 thread_msg_handle(struct thread_data *t)
452 struct thread_msg_req *req;
453 struct thread_msg_rsp *rsp;
455 req = thread_msg_recv(t->msgq_req);
460 case THREAD_REQ_PIPELINE_ENABLE:
461 rsp = thread_msg_handle_pipeline_enable(t, req);
464 case THREAD_REQ_PIPELINE_DISABLE:
465 rsp = thread_msg_handle_pipeline_disable(t, req);
469 rsp = (struct thread_msg_rsp *) req;
473 thread_msg_send(t->msgq_rsp, rsp);
478 * Master thread & data plane threads: message passing
480 enum pipeline_req_type {
482 PIPELINE_REQ_PORT_IN_STATS_READ,
483 PIPELINE_REQ_PORT_IN_ENABLE,
484 PIPELINE_REQ_PORT_IN_DISABLE,
487 PIPELINE_REQ_PORT_OUT_STATS_READ,
490 PIPELINE_REQ_TABLE_STATS_READ,
491 PIPELINE_REQ_TABLE_RULE_ADD,
492 PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT,
497 struct pipeline_msg_req_port_in_stats_read {
501 struct pipeline_msg_req_port_out_stats_read {
505 struct pipeline_msg_req_table_stats_read {
509 struct pipeline_msg_req_table_rule_add {
510 struct table_rule_match match;
511 struct table_rule_action action;
514 struct pipeline_msg_req_table_rule_add_default {
515 struct table_rule_action action;
518 struct pipeline_msg_req {
519 enum pipeline_req_type type;
520 uint32_t id; /* Port IN, port OUT or table ID */
524 struct pipeline_msg_req_port_in_stats_read port_in_stats_read;
525 struct pipeline_msg_req_port_out_stats_read port_out_stats_read;
526 struct pipeline_msg_req_table_stats_read table_stats_read;
527 struct pipeline_msg_req_table_rule_add table_rule_add;
528 struct pipeline_msg_req_table_rule_add_default table_rule_add_default;
532 struct pipeline_msg_rsp_port_in_stats_read {
533 struct rte_pipeline_port_in_stats stats;
536 struct pipeline_msg_rsp_port_out_stats_read {
537 struct rte_pipeline_port_out_stats stats;
540 struct pipeline_msg_rsp_table_stats_read {
541 struct rte_pipeline_table_stats stats;
544 struct pipeline_msg_rsp_table_rule_add {
548 struct pipeline_msg_rsp_table_rule_add_default {
552 struct pipeline_msg_rsp {
557 struct pipeline_msg_rsp_port_in_stats_read port_in_stats_read;
558 struct pipeline_msg_rsp_port_out_stats_read port_out_stats_read;
559 struct pipeline_msg_rsp_table_stats_read table_stats_read;
560 struct pipeline_msg_rsp_table_rule_add table_rule_add;
561 struct pipeline_msg_rsp_table_rule_add_default table_rule_add_default;
568 static struct pipeline_msg_req *
569 pipeline_msg_alloc(void)
571 size_t size = RTE_MAX(sizeof(struct pipeline_msg_req),
572 sizeof(struct pipeline_msg_rsp));
574 return calloc(1, size);
578 pipeline_msg_free(struct pipeline_msg_rsp *rsp)
583 static struct pipeline_msg_rsp *
584 pipeline_msg_send_recv(struct pipeline *p,
585 struct pipeline_msg_req *req)
587 struct rte_ring *msgq_req = p->msgq_req;
588 struct rte_ring *msgq_rsp = p->msgq_rsp;
589 struct pipeline_msg_rsp *rsp;
594 status = rte_ring_sp_enqueue(msgq_req, req);
595 } while (status == -ENOBUFS);
599 status = rte_ring_sc_dequeue(msgq_rsp, (void **) &rsp);
600 } while (status != 0);
606 pipeline_port_in_stats_read(const char *pipeline_name,
608 struct rte_pipeline_port_in_stats *stats,
612 struct pipeline_msg_req *req;
613 struct pipeline_msg_rsp *rsp;
616 /* Check input params */
617 if ((pipeline_name == NULL) ||
621 p = pipeline_find(pipeline_name);
624 (port_id >= p->n_ports_in))
627 /* Allocate request */
628 req = pipeline_msg_alloc();
633 req->type = PIPELINE_REQ_PORT_IN_STATS_READ;
635 req->port_in_stats_read.clear = clear;
637 /* Send request and wait for response */
638 rsp = pipeline_msg_send_recv(p, req);
643 status = rsp->status;
645 memcpy(stats, &rsp->port_in_stats_read.stats, sizeof(*stats));
648 pipeline_msg_free(rsp);
654 pipeline_port_in_enable(const char *pipeline_name,
658 struct pipeline_msg_req *req;
659 struct pipeline_msg_rsp *rsp;
662 /* Check input params */
663 if (pipeline_name == NULL)
666 p = pipeline_find(pipeline_name);
669 (port_id >= p->n_ports_in))
672 /* Allocate request */
673 req = pipeline_msg_alloc();
678 req->type = PIPELINE_REQ_PORT_IN_ENABLE;
681 /* Send request and wait for response */
682 rsp = pipeline_msg_send_recv(p, req);
687 status = rsp->status;
690 pipeline_msg_free(rsp);
696 pipeline_port_in_disable(const char *pipeline_name,
700 struct pipeline_msg_req *req;
701 struct pipeline_msg_rsp *rsp;
704 /* Check input params */
705 if (pipeline_name == NULL)
708 p = pipeline_find(pipeline_name);
711 (port_id >= p->n_ports_in))
714 /* Allocate request */
715 req = pipeline_msg_alloc();
720 req->type = PIPELINE_REQ_PORT_IN_DISABLE;
723 /* Send request and wait for response */
724 rsp = pipeline_msg_send_recv(p, req);
729 status = rsp->status;
732 pipeline_msg_free(rsp);
738 pipeline_port_out_stats_read(const char *pipeline_name,
740 struct rte_pipeline_port_out_stats *stats,
744 struct pipeline_msg_req *req;
745 struct pipeline_msg_rsp *rsp;
748 /* Check input params */
749 if ((pipeline_name == NULL) ||
753 p = pipeline_find(pipeline_name);
756 (port_id >= p->n_ports_out))
759 /* Allocate request */
760 req = pipeline_msg_alloc();
765 req->type = PIPELINE_REQ_PORT_OUT_STATS_READ;
767 req->port_out_stats_read.clear = clear;
769 /* Send request and wait for response */
770 rsp = pipeline_msg_send_recv(p, req);
775 status = rsp->status;
777 memcpy(stats, &rsp->port_out_stats_read.stats, sizeof(*stats));
780 pipeline_msg_free(rsp);
786 pipeline_table_stats_read(const char *pipeline_name,
788 struct rte_pipeline_table_stats *stats,
792 struct pipeline_msg_req *req;
793 struct pipeline_msg_rsp *rsp;
796 /* Check input params */
797 if ((pipeline_name == NULL) ||
801 p = pipeline_find(pipeline_name);
804 (table_id >= p->n_tables))
807 /* Allocate request */
808 req = pipeline_msg_alloc();
813 req->type = PIPELINE_REQ_TABLE_STATS_READ;
815 req->table_stats_read.clear = clear;
817 /* Send request and wait for response */
818 rsp = pipeline_msg_send_recv(p, req);
823 status = rsp->status;
825 memcpy(stats, &rsp->table_stats_read.stats, sizeof(*stats));
828 pipeline_msg_free(rsp);
834 match_check(struct table_rule_match *match,
840 if ((match == NULL) ||
842 (table_id >= p->n_tables))
845 table = &p->table[table_id];
846 if (match->match_type != table->params.match_type)
849 switch (match->match_type) {
852 struct table_acl_params *t = &table->params.match.acl;
853 struct table_rule_match_acl *r = &match->match.acl;
855 if ((r->ip_version && (t->ip_version == 0)) ||
856 ((r->ip_version == 0) && t->ip_version))
860 if ((r->sa_depth > 32) ||
864 if ((r->sa_depth > 128) ||
879 struct table_lpm_params *t = &table->params.match.lpm;
880 struct table_rule_match_lpm *r = &match->match.lpm;
882 if ((r->ip_version && (t->key_size != 4)) ||
883 ((r->ip_version == 0) && (t->key_size != 16)))
905 action_check(struct table_rule_action *action,
909 struct table_action_profile *ap;
911 if ((action == NULL) ||
913 (table_id >= p->n_tables))
916 ap = p->table[table_id].ap;
917 if (action->action_mask != ap->params.action_mask)
920 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
921 if ((action->fwd.action == RTE_PIPELINE_ACTION_PORT) &&
922 (action->fwd.id >= p->n_ports_out))
925 if ((action->fwd.action == RTE_PIPELINE_ACTION_TABLE) &&
926 (action->fwd.id >= p->n_tables))
930 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
931 uint32_t tc_mask0 = (1 << ap->params.mtr.n_tc) - 1;
932 uint32_t tc_mask1 = action->mtr.tc_mask;
934 if (tc_mask1 != tc_mask0)
938 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
939 uint32_t n_subports_per_port =
940 ap->params.tm.n_subports_per_port;
941 uint32_t n_pipes_per_subport =
942 ap->params.tm.n_pipes_per_subport;
943 uint32_t subport_id = action->tm.subport_id;
944 uint32_t pipe_id = action->tm.pipe_id;
946 if ((subport_id >= n_subports_per_port) ||
947 (pipe_id >= n_pipes_per_subport))
951 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
952 uint64_t encap_mask = ap->params.encap.encap_mask;
953 enum rte_table_action_encap_type type = action->encap.type;
955 if ((encap_mask & (1LLU << type)) == 0)
959 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
960 int ip_version0 = ap->params.common.ip_version;
961 int ip_version1 = action->nat.ip_version;
963 if ((ip_version1 && (ip_version0 == 0)) ||
964 ((ip_version1 == 0) && ip_version0))
972 action_default_check(struct table_rule_action *action,
976 if ((action == NULL) ||
977 (action->action_mask != (1LLU << RTE_TABLE_ACTION_FWD)) ||
979 (table_id >= p->n_tables))
982 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
983 if ((action->fwd.action == RTE_PIPELINE_ACTION_PORT) &&
984 (action->fwd.id >= p->n_ports_out))
987 if ((action->fwd.action == RTE_PIPELINE_ACTION_TABLE) &&
988 (action->fwd.id >= p->n_tables))
996 pipeline_table_rule_add(const char *pipeline_name,
998 struct table_rule_match *match,
999 struct table_rule_action *action,
1003 struct pipeline_msg_req *req;
1004 struct pipeline_msg_rsp *rsp;
1007 /* Check input params */
1008 if ((pipeline_name == NULL) ||
1014 p = pipeline_find(pipeline_name);
1016 (p->enabled == 0) ||
1017 (table_id >= p->n_tables) ||
1018 match_check(match, p, table_id) ||
1019 action_check(action, p, table_id))
1022 /* Allocate request */
1023 req = pipeline_msg_alloc();
1028 req->type = PIPELINE_REQ_TABLE_RULE_ADD;
1030 memcpy(&req->table_rule_add.match, match, sizeof(*match));
1031 memcpy(&req->table_rule_add.action, action, sizeof(*action));
1033 /* Send request and wait for response */
1034 rsp = pipeline_msg_send_recv(p, req);
1039 status = rsp->status;
1041 *data = rsp->table_rule_add.data;
1044 pipeline_msg_free(rsp);
1050 pipeline_table_rule_add_default(const char *pipeline_name,
1052 struct table_rule_action *action,
1056 struct pipeline_msg_req *req;
1057 struct pipeline_msg_rsp *rsp;
1060 /* Check input params */
1061 if ((pipeline_name == NULL) ||
1066 p = pipeline_find(pipeline_name);
1068 (p->enabled == 0) ||
1069 (table_id >= p->n_tables) ||
1070 action_default_check(action, p, table_id))
1073 /* Allocate request */
1074 req = pipeline_msg_alloc();
1079 req->type = PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT;
1081 memcpy(&req->table_rule_add_default.action, action, sizeof(*action));
1083 /* Send request and wait for response */
1084 rsp = pipeline_msg_send_recv(p, req);
1089 status = rsp->status;
1091 *data = rsp->table_rule_add_default.data;
1094 pipeline_msg_free(rsp);
1100 * Data plane threads: message handling
1102 static inline struct pipeline_msg_req *
1103 pipeline_msg_recv(struct rte_ring *msgq_req)
1105 struct pipeline_msg_req *req;
1107 int status = rte_ring_sc_dequeue(msgq_req, (void **) &req);
1116 pipeline_msg_send(struct rte_ring *msgq_rsp,
1117 struct pipeline_msg_rsp *rsp)
1122 status = rte_ring_sp_enqueue(msgq_rsp, rsp);
1123 } while (status == -ENOBUFS);
1126 static struct pipeline_msg_rsp *
1127 pipeline_msg_handle_port_in_stats_read(struct pipeline_data *p,
1128 struct pipeline_msg_req *req)
1130 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1131 uint32_t port_id = req->id;
1132 int clear = req->port_in_stats_read.clear;
1134 rsp->status = rte_pipeline_port_in_stats_read(p->p,
1136 &rsp->port_in_stats_read.stats,
1142 static struct pipeline_msg_rsp *
1143 pipeline_msg_handle_port_in_enable(struct pipeline_data *p,
1144 struct pipeline_msg_req *req)
1146 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1147 uint32_t port_id = req->id;
1149 rsp->status = rte_pipeline_port_in_enable(p->p,
1155 static struct pipeline_msg_rsp *
1156 pipeline_msg_handle_port_in_disable(struct pipeline_data *p,
1157 struct pipeline_msg_req *req)
1159 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1160 uint32_t port_id = req->id;
1162 rsp->status = rte_pipeline_port_in_disable(p->p,
1168 static struct pipeline_msg_rsp *
1169 pipeline_msg_handle_port_out_stats_read(struct pipeline_data *p,
1170 struct pipeline_msg_req *req)
1172 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1173 uint32_t port_id = req->id;
1174 int clear = req->port_out_stats_read.clear;
1176 rsp->status = rte_pipeline_port_out_stats_read(p->p,
1178 &rsp->port_out_stats_read.stats,
1184 static struct pipeline_msg_rsp *
1185 pipeline_msg_handle_table_stats_read(struct pipeline_data *p,
1186 struct pipeline_msg_req *req)
1188 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1189 uint32_t port_id = req->id;
1190 int clear = req->table_stats_read.clear;
1192 rsp->status = rte_pipeline_table_stats_read(p->p,
1194 &rsp->table_stats_read.stats,
1200 union table_rule_match_low_level {
1201 struct rte_table_acl_rule_add_params acl_add;
1202 struct rte_table_acl_rule_delete_params acl_delete;
1203 struct rte_table_array_key array;
1204 uint8_t hash[TABLE_RULE_MATCH_SIZE_MAX];
1205 struct rte_table_lpm_key lpm_ipv4;
1206 struct rte_table_lpm_ipv6_key lpm_ipv6;
1210 match_convert_ipv6_depth(uint32_t depth, uint32_t *depth32)
1215 switch (depth / 32) {
1225 depth32[1] = depth - 32;
1233 depth32[2] = depth - 64;
1241 depth32[3] = depth - 96;
1257 match_convert(struct table_rule_match *mh,
1258 union table_rule_match_low_level *ml,
1261 memset(ml, 0, sizeof(*ml));
1263 switch (mh->match_type) {
1265 if (mh->match.acl.ip_version)
1267 ml->acl_add.field_value[0].value.u8 =
1268 mh->match.acl.proto;
1269 ml->acl_add.field_value[0].mask_range.u8 =
1270 mh->match.acl.proto_mask;
1272 ml->acl_add.field_value[1].value.u32 =
1273 mh->match.acl.ipv4.sa;
1274 ml->acl_add.field_value[1].mask_range.u32 =
1275 mh->match.acl.sa_depth;
1277 ml->acl_add.field_value[2].value.u32 =
1278 mh->match.acl.ipv4.da;
1279 ml->acl_add.field_value[2].mask_range.u32 =
1280 mh->match.acl.da_depth;
1282 ml->acl_add.field_value[3].value.u16 =
1284 ml->acl_add.field_value[3].mask_range.u16 =
1287 ml->acl_add.field_value[4].value.u16 =
1289 ml->acl_add.field_value[4].mask_range.u16 =
1292 ml->acl_add.priority =
1293 (int32_t) mh->match.acl.priority;
1295 ml->acl_delete.field_value[0].value.u8 =
1296 mh->match.acl.proto;
1297 ml->acl_delete.field_value[0].mask_range.u8 =
1298 mh->match.acl.proto_mask;
1300 ml->acl_delete.field_value[1].value.u32 =
1301 mh->match.acl.ipv4.sa;
1302 ml->acl_delete.field_value[1].mask_range.u32 =
1303 mh->match.acl.sa_depth;
1305 ml->acl_delete.field_value[2].value.u32 =
1306 mh->match.acl.ipv4.da;
1307 ml->acl_delete.field_value[2].mask_range.u32 =
1308 mh->match.acl.da_depth;
1310 ml->acl_delete.field_value[3].value.u16 =
1312 ml->acl_delete.field_value[3].mask_range.u16 =
1315 ml->acl_delete.field_value[4].value.u16 =
1317 ml->acl_delete.field_value[4].mask_range.u16 =
1323 (uint32_t *) mh->match.acl.ipv6.sa;
1325 (uint32_t *) mh->match.acl.ipv6.da;
1326 uint32_t sa32_depth[4], da32_depth[4];
1329 status = match_convert_ipv6_depth(
1330 mh->match.acl.sa_depth,
1335 status = match_convert_ipv6_depth(
1336 mh->match.acl.da_depth,
1341 ml->acl_add.field_value[0].value.u8 =
1342 mh->match.acl.proto;
1343 ml->acl_add.field_value[0].mask_range.u8 =
1344 mh->match.acl.proto_mask;
1346 ml->acl_add.field_value[1].value.u32 = sa32[0];
1347 ml->acl_add.field_value[1].mask_range.u32 =
1349 ml->acl_add.field_value[2].value.u32 = sa32[1];
1350 ml->acl_add.field_value[2].mask_range.u32 =
1352 ml->acl_add.field_value[3].value.u32 = sa32[2];
1353 ml->acl_add.field_value[3].mask_range.u32 =
1355 ml->acl_add.field_value[4].value.u32 = sa32[3];
1356 ml->acl_add.field_value[4].mask_range.u32 =
1359 ml->acl_add.field_value[5].value.u32 = da32[0];
1360 ml->acl_add.field_value[5].mask_range.u32 =
1362 ml->acl_add.field_value[6].value.u32 = da32[1];
1363 ml->acl_add.field_value[6].mask_range.u32 =
1365 ml->acl_add.field_value[7].value.u32 = da32[2];
1366 ml->acl_add.field_value[7].mask_range.u32 =
1368 ml->acl_add.field_value[8].value.u32 = da32[3];
1369 ml->acl_add.field_value[8].mask_range.u32 =
1372 ml->acl_add.field_value[9].value.u16 =
1374 ml->acl_add.field_value[9].mask_range.u16 =
1377 ml->acl_add.field_value[10].value.u16 =
1379 ml->acl_add.field_value[10].mask_range.u16 =
1382 ml->acl_add.priority =
1383 (int32_t) mh->match.acl.priority;
1386 (uint32_t *) mh->match.acl.ipv6.sa;
1388 (uint32_t *) mh->match.acl.ipv6.da;
1389 uint32_t sa32_depth[4], da32_depth[4];
1392 status = match_convert_ipv6_depth(
1393 mh->match.acl.sa_depth,
1398 status = match_convert_ipv6_depth(
1399 mh->match.acl.da_depth,
1404 ml->acl_delete.field_value[0].value.u8 =
1405 mh->match.acl.proto;
1406 ml->acl_delete.field_value[0].mask_range.u8 =
1407 mh->match.acl.proto_mask;
1409 ml->acl_delete.field_value[1].value.u32 =
1411 ml->acl_delete.field_value[1].mask_range.u32 =
1413 ml->acl_delete.field_value[2].value.u32 =
1415 ml->acl_delete.field_value[2].mask_range.u32 =
1417 ml->acl_delete.field_value[3].value.u32 =
1419 ml->acl_delete.field_value[3].mask_range.u32 =
1421 ml->acl_delete.field_value[4].value.u32 =
1423 ml->acl_delete.field_value[4].mask_range.u32 =
1426 ml->acl_delete.field_value[5].value.u32 =
1428 ml->acl_delete.field_value[5].mask_range.u32 =
1430 ml->acl_delete.field_value[6].value.u32 =
1432 ml->acl_delete.field_value[6].mask_range.u32 =
1434 ml->acl_delete.field_value[7].value.u32 =
1436 ml->acl_delete.field_value[7].mask_range.u32 =
1438 ml->acl_delete.field_value[8].value.u32 =
1440 ml->acl_delete.field_value[8].mask_range.u32 =
1443 ml->acl_delete.field_value[9].value.u16 =
1445 ml->acl_delete.field_value[9].mask_range.u16 =
1448 ml->acl_delete.field_value[10].value.u16 =
1450 ml->acl_delete.field_value[10].mask_range.u16 =
1456 ml->array.pos = mh->match.array.pos;
1460 memcpy(ml->hash, mh->match.hash.key, sizeof(ml->hash));
1464 if (mh->match.lpm.ip_version) {
1465 ml->lpm_ipv4.ip = mh->match.lpm.ipv4;
1466 ml->lpm_ipv4.depth = mh->match.lpm.depth;
1468 memcpy(ml->lpm_ipv6.ip,
1469 mh->match.lpm.ipv6, sizeof(ml->lpm_ipv6.ip));
1470 ml->lpm_ipv6.depth = mh->match.lpm.depth;
1480 static struct pipeline_msg_rsp *
1481 pipeline_msg_handle_table_rule_add(struct pipeline_data *p,
1482 struct pipeline_msg_req *req)
1484 union table_rule_match_low_level match_ll;
1485 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1486 struct table_rule_match *match = &req->table_rule_add.match;
1487 struct table_rule_action *action = &req->table_rule_add.action;
1488 struct rte_pipeline_table_entry *data_in, *data_out;
1489 uint32_t table_id = req->id;
1490 int key_found, status;
1491 struct rte_table_action *a = p->table_data[table_id].a;
1494 memset(p->buffer, 0, sizeof(p->buffer));
1495 data_in = (struct rte_pipeline_table_entry *) p->buffer;
1497 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
1498 status = rte_table_action_apply(a,
1500 RTE_TABLE_ACTION_FWD,
1509 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
1510 status = rte_table_action_apply(a,
1512 RTE_TABLE_ACTION_MTR,
1521 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
1522 status = rte_table_action_apply(a,
1524 RTE_TABLE_ACTION_TM,
1533 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
1534 status = rte_table_action_apply(a,
1536 RTE_TABLE_ACTION_ENCAP,
1545 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
1546 status = rte_table_action_apply(a,
1548 RTE_TABLE_ACTION_NAT,
1557 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
1558 status = rte_table_action_apply(a,
1560 RTE_TABLE_ACTION_TTL,
1569 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
1570 status = rte_table_action_apply(a,
1572 RTE_TABLE_ACTION_STATS,
1581 if (action->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
1582 status = rte_table_action_apply(a,
1584 RTE_TABLE_ACTION_TIME,
1593 /* Add rule (match, action) to table */
1594 status = match_convert(match, &match_ll, 1);
1600 status = rte_pipeline_table_entry_add(p->p,
1611 /* Write response */
1613 rsp->table_rule_add.data = data_out;
1618 static struct pipeline_msg_rsp *
1619 pipeline_msg_handle_table_rule_add_default(struct pipeline_data *p,
1620 struct pipeline_msg_req *req)
1622 struct pipeline_msg_rsp *rsp = (struct pipeline_msg_rsp *) req;
1623 struct table_rule_action *action = &req->table_rule_add_default.action;
1624 struct rte_pipeline_table_entry *data_in, *data_out;
1625 uint32_t table_id = req->id;
1629 memset(p->buffer, 0, sizeof(p->buffer));
1630 data_in = (struct rte_pipeline_table_entry *) p->buffer;
1632 data_in->action = action->fwd.action;
1633 if (action->fwd.action == RTE_PIPELINE_ACTION_PORT)
1634 data_in->port_id = action->fwd.id;
1635 if (action->fwd.action == RTE_PIPELINE_ACTION_TABLE)
1636 data_in->table_id = action->fwd.id;
1638 /* Add default rule to table */
1639 status = rte_pipeline_table_default_entry_add(p->p,
1648 /* Write response */
1650 rsp->table_rule_add_default.data = data_out;
1656 pipeline_msg_handle(struct pipeline_data *p)
1659 struct pipeline_msg_req *req;
1660 struct pipeline_msg_rsp *rsp;
1662 req = pipeline_msg_recv(p->msgq_req);
1666 switch (req->type) {
1667 case PIPELINE_REQ_PORT_IN_STATS_READ:
1668 rsp = pipeline_msg_handle_port_in_stats_read(p, req);
1671 case PIPELINE_REQ_PORT_IN_ENABLE:
1672 rsp = pipeline_msg_handle_port_in_enable(p, req);
1675 case PIPELINE_REQ_PORT_IN_DISABLE:
1676 rsp = pipeline_msg_handle_port_in_disable(p, req);
1679 case PIPELINE_REQ_PORT_OUT_STATS_READ:
1680 rsp = pipeline_msg_handle_port_out_stats_read(p, req);
1683 case PIPELINE_REQ_TABLE_STATS_READ:
1684 rsp = pipeline_msg_handle_table_stats_read(p, req);
1687 case PIPELINE_REQ_TABLE_RULE_ADD:
1688 rsp = pipeline_msg_handle_table_rule_add(p, req);
1691 case PIPELINE_REQ_TABLE_RULE_ADD_DEFAULT:
1692 rsp = pipeline_msg_handle_table_rule_add_default(p, req);
1696 rsp = (struct pipeline_msg_rsp *) req;
1700 pipeline_msg_send(p->msgq_rsp, rsp);
1705 * Data plane threads: main
1708 thread_main(void *arg __rte_unused)
1710 struct thread_data *t;
1711 uint32_t thread_id, i;
1713 thread_id = rte_lcore_id();
1714 t = &thread_data[thread_id];
1717 for (i = 0; ; i++) {
1721 for (j = 0; j < t->n_pipelines; j++)
1722 rte_pipeline_run(t->p[j]);
1725 if ((i & 0xF) == 0) {
1726 uint64_t time = rte_get_tsc_cycles();
1727 uint64_t time_next_min = UINT64_MAX;
1729 if (time < t->time_next_min)
1732 /* Pipeline message queues */
1733 for (j = 0; j < t->n_pipelines; j++) {
1734 struct pipeline_data *p =
1735 &t->pipeline_data[j];
1736 uint64_t time_next = p->time_next;
1738 if (time_next <= time) {
1739 pipeline_msg_handle(p);
1740 rte_pipeline_flush(p->p);
1741 time_next = time + p->timer_period;
1742 p->time_next = time_next;
1745 if (time_next < time_next_min)
1746 time_next_min = time_next;
1749 /* Thread message queues */
1751 uint64_t time_next = t->time_next;
1753 if (time_next <= time) {
1754 thread_msg_handle(t);
1755 time_next = time + t->timer_period;
1756 t->time_next = time_next;
1759 if (time_next < time_next_min)
1760 time_next_min = time_next;
1763 t->time_next_min = time_next_min;