1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
6 #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
10 #include <sys/queue.h>
12 #include <rte_mempool.h>
15 #include <rte_ethdev.h>
16 #include <rte_sched.h>
17 #include <rte_port_in_action.h>
18 #include <rte_table_action.h>
19 #include <rte_pipeline.h>
21 #include <rte_ethdev_core.h>
22 #include <rte_ethdev_driver.h>
23 #include <rte_tm_driver.h>
24 #include <rte_flow_driver.h>
25 #include <rte_mtr_driver.h>
27 #include "rte_eth_softnic.h"
42 /** Traffic Management (TM) */
44 uint32_t n_queues; /**< Number of queues */
45 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
54 TAILQ_HEAD(flow_list, rte_flow);
56 struct flow_attr_map {
57 char pipeline_name[NAME_SIZE];
62 #ifndef SOFTNIC_FLOW_MAX_GROUPS
63 #define SOFTNIC_FLOW_MAX_GROUPS 64
66 struct flow_internals {
67 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
68 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
75 /* MTR meter profile */
76 struct softnic_mtr_meter_profile {
77 TAILQ_ENTRY(softnic_mtr_meter_profile) node;
78 uint32_t meter_profile_id;
79 struct rte_mtr_meter_profile params;
83 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
85 /* MTR meter object */
87 TAILQ_ENTRY(softnic_mtr) node;
89 struct rte_mtr_params params;
90 struct rte_flow *flow;
93 TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
95 struct mtr_internals {
96 struct softnic_mtr_meter_profile_list meter_profiles;
97 struct softnic_mtr_list mtrs;
103 struct softnic_mempool_params {
104 uint32_t buffer_size;
109 struct softnic_mempool {
110 TAILQ_ENTRY(softnic_mempool) node;
111 char name[NAME_SIZE];
112 struct rte_mempool *m;
113 uint32_t buffer_size;
116 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
121 struct softnic_swq_params {
126 TAILQ_ENTRY(softnic_swq) node;
127 char name[NAME_SIZE];
131 TAILQ_HEAD(softnic_swq_list, softnic_swq);
136 struct softnic_link_params {
137 const char *dev_name;
138 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
141 struct softnic_link {
142 TAILQ_ENTRY(softnic_link) node;
143 char name[NAME_SIZE];
149 TAILQ_HEAD(softnic_link_list, softnic_link);
155 #ifndef TM_MAX_SUBPORTS
156 #define TM_MAX_SUBPORTS 8
159 #ifndef TM_MAX_PIPES_PER_SUBPORT
160 #define TM_MAX_PIPES_PER_SUBPORT 4096
164 struct rte_sched_port_params port_params;
166 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
168 struct rte_sched_pipe_params
169 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
170 uint32_t n_pipe_profiles;
171 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
176 TM_NODE_LEVEL_PORT = 0,
177 TM_NODE_LEVEL_SUBPORT,
184 /* TM Shaper Profile */
185 struct tm_shaper_profile {
186 TAILQ_ENTRY(tm_shaper_profile) node;
187 uint32_t shaper_profile_id;
189 struct rte_tm_shaper_params params;
192 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
194 /* TM Shared Shaper */
195 struct tm_shared_shaper {
196 TAILQ_ENTRY(tm_shared_shaper) node;
197 uint32_t shared_shaper_id;
199 uint32_t shaper_profile_id;
202 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
204 /* TM WRED Profile */
205 struct tm_wred_profile {
206 TAILQ_ENTRY(tm_wred_profile) node;
207 uint32_t wred_profile_id;
209 struct rte_tm_wred_params params;
212 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
216 TAILQ_ENTRY(tm_node) node;
218 uint32_t parent_node_id;
222 struct tm_node *parent_node;
223 struct tm_shaper_profile *shaper_profile;
224 struct tm_wred_profile *wred_profile;
225 struct rte_tm_node_params params;
226 struct rte_tm_node_stats stats;
230 TAILQ_HEAD(tm_node_list, tm_node);
232 /* TM Hierarchy Specification */
233 struct tm_hierarchy {
234 struct tm_shaper_profile_list shaper_profiles;
235 struct tm_shared_shaper_list shared_shapers;
236 struct tm_wred_profile_list wred_profiles;
237 struct tm_node_list nodes;
239 uint32_t n_shaper_profiles;
240 uint32_t n_shared_shapers;
241 uint32_t n_wred_profiles;
244 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
247 struct tm_internals {
248 /** Hierarchy specification
250 * -Hierarchy is unfrozen at init and when port is stopped.
251 * -Hierarchy is frozen on successful hierarchy commit.
252 * -Run-time hierarchy changes are not allowed, therefore it makes
253 * sense to keep the hierarchy frozen after the port is started.
255 struct tm_hierarchy h;
256 int hierarchy_frozen;
259 struct tm_params params;
262 struct softnic_tmgr_port {
263 TAILQ_ENTRY(softnic_tmgr_port) node;
264 char name[NAME_SIZE];
265 struct rte_sched_port *s;
268 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
274 TAILQ_ENTRY(softnic_tap) node;
275 char name[NAME_SIZE];
279 TAILQ_HEAD(softnic_tap_list, softnic_tap);
284 struct softnic_port_in_action_profile_params {
285 uint64_t action_mask;
286 struct rte_port_in_action_fltr_config fltr;
287 struct rte_port_in_action_lb_config lb;
290 struct softnic_port_in_action_profile {
291 TAILQ_ENTRY(softnic_port_in_action_profile) node;
292 char name[NAME_SIZE];
293 struct softnic_port_in_action_profile_params params;
294 struct rte_port_in_action_profile *ap;
297 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
302 struct softnic_table_action_profile_params {
303 uint64_t action_mask;
304 struct rte_table_action_common_config common;
305 struct rte_table_action_lb_config lb;
306 struct rte_table_action_mtr_config mtr;
307 struct rte_table_action_tm_config tm;
308 struct rte_table_action_encap_config encap;
309 struct rte_table_action_nat_config nat;
310 struct rte_table_action_ttl_config ttl;
311 struct rte_table_action_stats_config stats;
314 struct softnic_table_action_profile {
315 TAILQ_ENTRY(softnic_table_action_profile) node;
316 char name[NAME_SIZE];
317 struct softnic_table_action_profile_params params;
318 struct rte_table_action_profile *ap;
321 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
323 struct softnic_table_meter_profile {
324 TAILQ_ENTRY(softnic_table_meter_profile) node;
325 uint32_t meter_profile_id;
326 struct rte_table_action_meter_profile profile;
329 TAILQ_HEAD(softnic_table_meter_profile_list,
330 softnic_table_meter_profile);
335 struct pipeline_params {
336 uint32_t timer_period_ms;
337 uint32_t offset_port_id;
340 enum softnic_port_in_type {
348 struct softnic_port_in_params {
350 enum softnic_port_in_type type;
351 char dev_name[NAME_SIZE];
358 const char *mempool_name;
363 const char *mempool_name;
364 const char *file_name;
365 uint32_t n_bytes_per_pkt;
371 char action_profile_name[NAME_SIZE];
374 enum softnic_port_out_type {
382 struct softnic_port_out_params {
383 enum softnic_port_out_type type;
384 char dev_name[NAME_SIZE];
391 const char *file_name;
400 enum softnic_table_type {
408 struct softnic_table_acl_params {
410 uint32_t ip_header_offset;
414 struct softnic_table_array_params {
419 #ifndef TABLE_RULE_MATCH_SIZE_MAX
420 #define TABLE_RULE_MATCH_SIZE_MAX 256
423 struct softnic_table_hash_params {
427 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
429 int extendable_bucket;
432 struct softnic_table_lpm_params {
438 struct softnic_table_params {
440 enum softnic_table_type match_type;
442 struct softnic_table_acl_params acl;
443 struct softnic_table_array_params array;
444 struct softnic_table_hash_params hash;
445 struct softnic_table_lpm_params lpm;
449 char action_profile_name[NAME_SIZE];
452 struct softnic_port_in {
453 struct softnic_port_in_params params;
454 struct softnic_port_in_action_profile *ap;
455 struct rte_port_in_action *a;
458 struct softnic_port_out {
459 struct softnic_port_out_params params;
462 struct softnic_table {
463 struct softnic_table_params params;
464 struct softnic_table_action_profile *ap;
465 struct rte_table_action *a;
466 struct flow_list flows;
467 struct rte_table_action_dscp_table dscp_table;
468 struct softnic_table_meter_profile_list meter_profiles;
472 TAILQ_ENTRY(pipeline) node;
473 char name[NAME_SIZE];
475 struct rte_pipeline *p;
476 struct pipeline_params params;
477 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
478 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
479 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
481 uint32_t n_ports_out;
484 struct rte_ring *msgq_req;
485 struct rte_ring *msgq_rsp;
486 uint32_t timer_period_ms;
493 TAILQ_HEAD(pipeline_list, pipeline);
498 #ifndef THREAD_PIPELINES_MAX
499 #define THREAD_PIPELINES_MAX 256
502 #ifndef THREAD_MSGQ_SIZE
503 #define THREAD_MSGQ_SIZE 64
506 #ifndef THREAD_TIMER_PERIOD_MS
507 #define THREAD_TIMER_PERIOD_MS 100
511 * Master thead: data plane thread context
513 struct softnic_thread {
514 struct rte_ring *msgq_req;
515 struct rte_ring *msgq_rsp;
521 * Data plane threads: context
523 #ifndef TABLE_RULE_ACTION_SIZE_MAX
524 #define TABLE_RULE_ACTION_SIZE_MAX 2048
527 struct softnic_table_data {
528 struct rte_table_action *a;
531 struct pipeline_data {
532 struct rte_pipeline *p;
533 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
536 struct rte_ring *msgq_req;
537 struct rte_ring *msgq_rsp;
538 uint64_t timer_period; /* Measured in CPU cycles. */
541 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
544 struct softnic_thread_data {
545 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
546 uint32_t n_pipelines;
548 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
549 struct rte_ring *msgq_req;
550 struct rte_ring *msgq_rsp;
551 uint64_t timer_period; /* Measured in CPU cycles. */
553 uint64_t time_next_min;
555 } __rte_cache_aligned;
560 struct pmd_internals {
562 struct pmd_params params;
565 struct tm_internals tm; /**< Traffic Management */
568 struct flow_internals flow;
569 struct mtr_internals mtr;
571 struct softnic_conn *conn;
572 struct softnic_mempool_list mempool_list;
573 struct softnic_swq_list swq_list;
574 struct softnic_link_list link_list;
575 struct softnic_tmgr_port_list tmgr_port_list;
576 struct softnic_tap_list tap_list;
577 struct softnic_port_in_action_profile_list port_in_action_profile_list;
578 struct softnic_table_action_profile_list table_action_profile_list;
579 struct pipeline_list pipeline_list;
580 struct softnic_thread thread[RTE_MAX_LCORE];
581 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
584 static inline struct rte_eth_dev *
585 ETHDEV(struct pmd_internals *softnic)
593 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
597 return &rte_eth_devices[port_id];
604 flow_attr_map_set(struct pmd_internals *softnic,
607 const char *pipeline_name,
610 struct flow_attr_map *
611 flow_attr_map_get(struct pmd_internals *softnic,
615 extern const struct rte_flow_ops pmd_flow_ops;
621 softnic_mtr_init(struct pmd_internals *p);
624 softnic_mtr_free(struct pmd_internals *p);
627 softnic_mtr_find(struct pmd_internals *p,
630 struct softnic_mtr_meter_profile *
631 softnic_mtr_meter_profile_find(struct pmd_internals *p,
632 uint32_t meter_profile_id);
634 extern const struct rte_mtr_ops pmd_mtr_ops;
640 softnic_mempool_init(struct pmd_internals *p);
643 softnic_mempool_free(struct pmd_internals *p);
645 struct softnic_mempool *
646 softnic_mempool_find(struct pmd_internals *p,
649 struct softnic_mempool *
650 softnic_mempool_create(struct pmd_internals *p,
652 struct softnic_mempool_params *params);
658 softnic_swq_init(struct pmd_internals *p);
661 softnic_swq_free(struct pmd_internals *p);
664 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
667 softnic_swq_find(struct pmd_internals *p,
671 softnic_swq_create(struct pmd_internals *p,
673 struct softnic_swq_params *params);
679 softnic_link_init(struct pmd_internals *p);
682 softnic_link_free(struct pmd_internals *p);
684 struct softnic_link *
685 softnic_link_find(struct pmd_internals *p,
688 struct softnic_link *
689 softnic_link_create(struct pmd_internals *p,
691 struct softnic_link_params *params);
697 softnic_tmgr_init(struct pmd_internals *p);
700 softnic_tmgr_free(struct pmd_internals *p);
702 struct softnic_tmgr_port *
703 softnic_tmgr_port_find(struct pmd_internals *p,
706 struct softnic_tmgr_port *
707 softnic_tmgr_port_create(struct pmd_internals *p,
711 tm_hierarchy_init(struct pmd_internals *p);
714 tm_hierarchy_free(struct pmd_internals *p);
717 tm_used(struct rte_eth_dev *dev)
719 struct pmd_internals *p = dev->data->dev_private;
721 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
724 extern const struct rte_tm_ops pmd_tm_ops;
730 softnic_tap_init(struct pmd_internals *p);
733 softnic_tap_free(struct pmd_internals *p);
736 softnic_tap_find(struct pmd_internals *p,
740 softnic_tap_create(struct pmd_internals *p,
747 softnic_port_in_action_profile_init(struct pmd_internals *p);
750 softnic_port_in_action_profile_free(struct pmd_internals *p);
752 struct softnic_port_in_action_profile *
753 softnic_port_in_action_profile_find(struct pmd_internals *p,
756 struct softnic_port_in_action_profile *
757 softnic_port_in_action_profile_create(struct pmd_internals *p,
759 struct softnic_port_in_action_profile_params *params);
765 softnic_table_action_profile_init(struct pmd_internals *p);
768 softnic_table_action_profile_free(struct pmd_internals *p);
770 struct softnic_table_action_profile *
771 softnic_table_action_profile_find(struct pmd_internals *p,
774 struct softnic_table_action_profile *
775 softnic_table_action_profile_create(struct pmd_internals *p,
777 struct softnic_table_action_profile_params *params);
783 softnic_pipeline_init(struct pmd_internals *p);
786 softnic_pipeline_free(struct pmd_internals *p);
789 softnic_pipeline_disable_all(struct pmd_internals *p);
792 softnic_pipeline_find(struct pmd_internals *p, const char *name);
795 softnic_pipeline_create(struct pmd_internals *p,
797 struct pipeline_params *params);
800 softnic_pipeline_port_in_create(struct pmd_internals *p,
801 const char *pipeline_name,
802 struct softnic_port_in_params *params,
806 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
807 const char *pipeline_name,
812 softnic_pipeline_port_out_create(struct pmd_internals *p,
813 const char *pipeline_name,
814 struct softnic_port_out_params *params);
817 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
818 const char *pipeline_name,
823 softnic_pipeline_table_create(struct pmd_internals *p,
824 const char *pipeline_name,
825 struct softnic_table_params *params);
827 struct softnic_table_meter_profile *
828 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
829 uint32_t meter_profile_id);
831 struct softnic_table_rule_match_acl {
858 struct softnic_table_rule_match_array {
862 struct softnic_table_rule_match_hash {
863 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
866 struct softnic_table_rule_match_lpm {
878 struct softnic_table_rule_match {
879 enum softnic_table_type match_type;
882 struct softnic_table_rule_match_acl acl;
883 struct softnic_table_rule_match_array array;
884 struct softnic_table_rule_match_hash hash;
885 struct softnic_table_rule_match_lpm lpm;
889 struct softnic_table_rule_action {
890 uint64_t action_mask;
891 struct rte_table_action_fwd_params fwd;
892 struct rte_table_action_lb_params lb;
893 struct rte_table_action_mtr_params mtr;
894 struct rte_table_action_tm_params tm;
895 struct rte_table_action_encap_params encap;
896 struct rte_table_action_nat_params nat;
897 struct rte_table_action_ttl_params ttl;
898 struct rte_table_action_stats_params stats;
899 struct rte_table_action_time_params time;
903 TAILQ_ENTRY(rte_flow) node;
904 struct softnic_table_rule_match match;
905 struct softnic_table_rule_action action;
907 struct pipeline *pipeline;
912 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
913 const char *pipeline_name,
915 struct rte_pipeline_port_in_stats *stats,
919 softnic_pipeline_port_in_enable(struct pmd_internals *p,
920 const char *pipeline_name,
924 softnic_pipeline_port_in_disable(struct pmd_internals *p,
925 const char *pipeline_name,
929 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
930 const char *pipeline_name,
932 struct rte_pipeline_port_out_stats *stats,
936 softnic_pipeline_table_stats_read(struct pmd_internals *p,
937 const char *pipeline_name,
939 struct rte_pipeline_table_stats *stats,
943 softnic_pipeline_table_rule_add(struct pmd_internals *p,
944 const char *pipeline_name,
946 struct softnic_table_rule_match *match,
947 struct softnic_table_rule_action *action,
951 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
952 const char *pipeline_name,
954 struct softnic_table_rule_match *match,
955 struct softnic_table_rule_action *action,
960 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
961 const char *pipeline_name,
963 struct softnic_table_rule_action *action,
967 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
968 const char *pipeline_name,
970 struct softnic_table_rule_match *match);
973 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
974 const char *pipeline_name,
978 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
979 const char *pipeline_name,
982 struct rte_table_action_stats_counters *stats,
986 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
987 const char *pipeline_name,
989 uint32_t meter_profile_id,
990 struct rte_table_action_meter_profile *profile);
993 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
994 const char *pipeline_name,
996 uint32_t meter_profile_id);
999 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1000 const char *pipeline_name,
1004 struct rte_table_action_mtr_counters *stats,
1008 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1009 const char *pipeline_name,
1012 struct rte_table_action_dscp_table *dscp_table);
1015 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1016 const char *pipeline_name,
1019 struct rte_table_action_ttl_counters *stats,
1026 softnic_thread_init(struct pmd_internals *p);
1029 softnic_thread_free(struct pmd_internals *p);
1032 softnic_thread_pipeline_enable(struct pmd_internals *p,
1034 const char *pipeline_name);
1037 softnic_thread_pipeline_disable(struct pmd_internals *p,
1039 const char *pipeline_name);
1045 softnic_cli_process(char *in,
1051 softnic_cli_script_process(struct pmd_internals *softnic,
1052 const char *file_name,
1053 size_t msg_in_len_max,
1054 size_t msg_out_len_max);
1056 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */