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 struct mtr_internals {
86 struct softnic_mtr_meter_profile_list meter_profiles;
92 struct softnic_mempool_params {
98 struct softnic_mempool {
99 TAILQ_ENTRY(softnic_mempool) node;
100 char name[NAME_SIZE];
101 struct rte_mempool *m;
102 uint32_t buffer_size;
105 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
110 struct softnic_swq_params {
115 TAILQ_ENTRY(softnic_swq) node;
116 char name[NAME_SIZE];
120 TAILQ_HEAD(softnic_swq_list, softnic_swq);
125 struct softnic_link_params {
126 const char *dev_name;
127 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
130 struct softnic_link {
131 TAILQ_ENTRY(softnic_link) node;
132 char name[NAME_SIZE];
138 TAILQ_HEAD(softnic_link_list, softnic_link);
144 #ifndef TM_MAX_SUBPORTS
145 #define TM_MAX_SUBPORTS 8
148 #ifndef TM_MAX_PIPES_PER_SUBPORT
149 #define TM_MAX_PIPES_PER_SUBPORT 4096
153 struct rte_sched_port_params port_params;
155 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
157 struct rte_sched_pipe_params
158 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
159 uint32_t n_pipe_profiles;
160 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
165 TM_NODE_LEVEL_PORT = 0,
166 TM_NODE_LEVEL_SUBPORT,
173 /* TM Shaper Profile */
174 struct tm_shaper_profile {
175 TAILQ_ENTRY(tm_shaper_profile) node;
176 uint32_t shaper_profile_id;
178 struct rte_tm_shaper_params params;
181 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
183 /* TM Shared Shaper */
184 struct tm_shared_shaper {
185 TAILQ_ENTRY(tm_shared_shaper) node;
186 uint32_t shared_shaper_id;
188 uint32_t shaper_profile_id;
191 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
193 /* TM WRED Profile */
194 struct tm_wred_profile {
195 TAILQ_ENTRY(tm_wred_profile) node;
196 uint32_t wred_profile_id;
198 struct rte_tm_wred_params params;
201 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
205 TAILQ_ENTRY(tm_node) node;
207 uint32_t parent_node_id;
211 struct tm_node *parent_node;
212 struct tm_shaper_profile *shaper_profile;
213 struct tm_wred_profile *wred_profile;
214 struct rte_tm_node_params params;
215 struct rte_tm_node_stats stats;
219 TAILQ_HEAD(tm_node_list, tm_node);
221 /* TM Hierarchy Specification */
222 struct tm_hierarchy {
223 struct tm_shaper_profile_list shaper_profiles;
224 struct tm_shared_shaper_list shared_shapers;
225 struct tm_wred_profile_list wred_profiles;
226 struct tm_node_list nodes;
228 uint32_t n_shaper_profiles;
229 uint32_t n_shared_shapers;
230 uint32_t n_wred_profiles;
233 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
236 struct tm_internals {
237 /** Hierarchy specification
239 * -Hierarchy is unfrozen at init and when port is stopped.
240 * -Hierarchy is frozen on successful hierarchy commit.
241 * -Run-time hierarchy changes are not allowed, therefore it makes
242 * sense to keep the hierarchy frozen after the port is started.
244 struct tm_hierarchy h;
245 int hierarchy_frozen;
248 struct tm_params params;
251 struct softnic_tmgr_port {
252 TAILQ_ENTRY(softnic_tmgr_port) node;
253 char name[NAME_SIZE];
254 struct rte_sched_port *s;
257 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
263 TAILQ_ENTRY(softnic_tap) node;
264 char name[NAME_SIZE];
268 TAILQ_HEAD(softnic_tap_list, softnic_tap);
273 struct softnic_port_in_action_profile_params {
274 uint64_t action_mask;
275 struct rte_port_in_action_fltr_config fltr;
276 struct rte_port_in_action_lb_config lb;
279 struct softnic_port_in_action_profile {
280 TAILQ_ENTRY(softnic_port_in_action_profile) node;
281 char name[NAME_SIZE];
282 struct softnic_port_in_action_profile_params params;
283 struct rte_port_in_action_profile *ap;
286 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
291 struct softnic_table_action_profile_params {
292 uint64_t action_mask;
293 struct rte_table_action_common_config common;
294 struct rte_table_action_lb_config lb;
295 struct rte_table_action_mtr_config mtr;
296 struct rte_table_action_tm_config tm;
297 struct rte_table_action_encap_config encap;
298 struct rte_table_action_nat_config nat;
299 struct rte_table_action_ttl_config ttl;
300 struct rte_table_action_stats_config stats;
303 struct softnic_table_action_profile {
304 TAILQ_ENTRY(softnic_table_action_profile) node;
305 char name[NAME_SIZE];
306 struct softnic_table_action_profile_params params;
307 struct rte_table_action_profile *ap;
310 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
315 struct pipeline_params {
316 uint32_t timer_period_ms;
317 uint32_t offset_port_id;
320 enum softnic_port_in_type {
328 struct softnic_port_in_params {
330 enum softnic_port_in_type type;
331 char dev_name[NAME_SIZE];
338 const char *mempool_name;
343 const char *mempool_name;
344 const char *file_name;
345 uint32_t n_bytes_per_pkt;
351 char action_profile_name[NAME_SIZE];
354 enum softnic_port_out_type {
362 struct softnic_port_out_params {
363 enum softnic_port_out_type type;
364 char dev_name[NAME_SIZE];
371 const char *file_name;
380 enum softnic_table_type {
388 struct softnic_table_acl_params {
390 uint32_t ip_header_offset;
394 struct softnic_table_array_params {
399 #ifndef TABLE_RULE_MATCH_SIZE_MAX
400 #define TABLE_RULE_MATCH_SIZE_MAX 256
403 struct softnic_table_hash_params {
407 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
409 int extendable_bucket;
412 struct softnic_table_lpm_params {
418 struct softnic_table_params {
420 enum softnic_table_type match_type;
422 struct softnic_table_acl_params acl;
423 struct softnic_table_array_params array;
424 struct softnic_table_hash_params hash;
425 struct softnic_table_lpm_params lpm;
429 char action_profile_name[NAME_SIZE];
432 struct softnic_port_in {
433 struct softnic_port_in_params params;
434 struct softnic_port_in_action_profile *ap;
435 struct rte_port_in_action *a;
438 struct softnic_port_out {
439 struct softnic_port_out_params params;
442 struct softnic_table {
443 struct softnic_table_params params;
444 struct softnic_table_action_profile *ap;
445 struct rte_table_action *a;
446 struct flow_list flows;
450 TAILQ_ENTRY(pipeline) node;
451 char name[NAME_SIZE];
453 struct rte_pipeline *p;
454 struct pipeline_params params;
455 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
456 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
457 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
459 uint32_t n_ports_out;
462 struct rte_ring *msgq_req;
463 struct rte_ring *msgq_rsp;
464 uint32_t timer_period_ms;
471 TAILQ_HEAD(pipeline_list, pipeline);
476 #ifndef THREAD_PIPELINES_MAX
477 #define THREAD_PIPELINES_MAX 256
480 #ifndef THREAD_MSGQ_SIZE
481 #define THREAD_MSGQ_SIZE 64
484 #ifndef THREAD_TIMER_PERIOD_MS
485 #define THREAD_TIMER_PERIOD_MS 100
489 * Master thead: data plane thread context
491 struct softnic_thread {
492 struct rte_ring *msgq_req;
493 struct rte_ring *msgq_rsp;
499 * Data plane threads: context
501 #ifndef TABLE_RULE_ACTION_SIZE_MAX
502 #define TABLE_RULE_ACTION_SIZE_MAX 2048
505 struct softnic_table_data {
506 struct rte_table_action *a;
509 struct pipeline_data {
510 struct rte_pipeline *p;
511 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
514 struct rte_ring *msgq_req;
515 struct rte_ring *msgq_rsp;
516 uint64_t timer_period; /* Measured in CPU cycles. */
519 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
522 struct softnic_thread_data {
523 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
524 uint32_t n_pipelines;
526 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
527 struct rte_ring *msgq_req;
528 struct rte_ring *msgq_rsp;
529 uint64_t timer_period; /* Measured in CPU cycles. */
531 uint64_t time_next_min;
533 } __rte_cache_aligned;
538 struct pmd_internals {
540 struct pmd_params params;
543 struct tm_internals tm; /**< Traffic Management */
546 struct flow_internals flow;
547 struct mtr_internals mtr;
549 struct softnic_conn *conn;
550 struct softnic_mempool_list mempool_list;
551 struct softnic_swq_list swq_list;
552 struct softnic_link_list link_list;
553 struct softnic_tmgr_port_list tmgr_port_list;
554 struct softnic_tap_list tap_list;
555 struct softnic_port_in_action_profile_list port_in_action_profile_list;
556 struct softnic_table_action_profile_list table_action_profile_list;
557 struct pipeline_list pipeline_list;
558 struct softnic_thread thread[RTE_MAX_LCORE];
559 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
562 static inline struct rte_eth_dev *
563 ETHDEV(struct pmd_internals *softnic)
571 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
575 return &rte_eth_devices[port_id];
582 flow_attr_map_set(struct pmd_internals *softnic,
585 const char *pipeline_name,
588 struct flow_attr_map *
589 flow_attr_map_get(struct pmd_internals *softnic,
593 extern const struct rte_flow_ops pmd_flow_ops;
599 softnic_mtr_init(struct pmd_internals *p);
602 softnic_mtr_free(struct pmd_internals *p);
604 struct softnic_mtr_meter_profile *
605 softnic_mtr_meter_profile_find(struct pmd_internals *p,
606 uint32_t meter_profile_id);
608 extern const struct rte_mtr_ops pmd_mtr_ops;
614 softnic_mempool_init(struct pmd_internals *p);
617 softnic_mempool_free(struct pmd_internals *p);
619 struct softnic_mempool *
620 softnic_mempool_find(struct pmd_internals *p,
623 struct softnic_mempool *
624 softnic_mempool_create(struct pmd_internals *p,
626 struct softnic_mempool_params *params);
632 softnic_swq_init(struct pmd_internals *p);
635 softnic_swq_free(struct pmd_internals *p);
638 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
641 softnic_swq_find(struct pmd_internals *p,
645 softnic_swq_create(struct pmd_internals *p,
647 struct softnic_swq_params *params);
653 softnic_link_init(struct pmd_internals *p);
656 softnic_link_free(struct pmd_internals *p);
658 struct softnic_link *
659 softnic_link_find(struct pmd_internals *p,
662 struct softnic_link *
663 softnic_link_create(struct pmd_internals *p,
665 struct softnic_link_params *params);
671 softnic_tmgr_init(struct pmd_internals *p);
674 softnic_tmgr_free(struct pmd_internals *p);
676 struct softnic_tmgr_port *
677 softnic_tmgr_port_find(struct pmd_internals *p,
680 struct softnic_tmgr_port *
681 softnic_tmgr_port_create(struct pmd_internals *p,
685 tm_hierarchy_init(struct pmd_internals *p);
688 tm_hierarchy_free(struct pmd_internals *p);
691 tm_used(struct rte_eth_dev *dev)
693 struct pmd_internals *p = dev->data->dev_private;
695 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
698 extern const struct rte_tm_ops pmd_tm_ops;
704 softnic_tap_init(struct pmd_internals *p);
707 softnic_tap_free(struct pmd_internals *p);
710 softnic_tap_find(struct pmd_internals *p,
714 softnic_tap_create(struct pmd_internals *p,
721 softnic_port_in_action_profile_init(struct pmd_internals *p);
724 softnic_port_in_action_profile_free(struct pmd_internals *p);
726 struct softnic_port_in_action_profile *
727 softnic_port_in_action_profile_find(struct pmd_internals *p,
730 struct softnic_port_in_action_profile *
731 softnic_port_in_action_profile_create(struct pmd_internals *p,
733 struct softnic_port_in_action_profile_params *params);
739 softnic_table_action_profile_init(struct pmd_internals *p);
742 softnic_table_action_profile_free(struct pmd_internals *p);
744 struct softnic_table_action_profile *
745 softnic_table_action_profile_find(struct pmd_internals *p,
748 struct softnic_table_action_profile *
749 softnic_table_action_profile_create(struct pmd_internals *p,
751 struct softnic_table_action_profile_params *params);
757 softnic_pipeline_init(struct pmd_internals *p);
760 softnic_pipeline_free(struct pmd_internals *p);
763 softnic_pipeline_disable_all(struct pmd_internals *p);
766 softnic_pipeline_find(struct pmd_internals *p, const char *name);
769 softnic_pipeline_create(struct pmd_internals *p,
771 struct pipeline_params *params);
774 softnic_pipeline_port_in_create(struct pmd_internals *p,
775 const char *pipeline_name,
776 struct softnic_port_in_params *params,
780 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
781 const char *pipeline_name,
786 softnic_pipeline_port_out_create(struct pmd_internals *p,
787 const char *pipeline_name,
788 struct softnic_port_out_params *params);
791 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
792 const char *pipeline_name,
797 softnic_pipeline_table_create(struct pmd_internals *p,
798 const char *pipeline_name,
799 struct softnic_table_params *params);
801 struct softnic_table_rule_match_acl {
828 struct softnic_table_rule_match_array {
832 struct softnic_table_rule_match_hash {
833 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
836 struct softnic_table_rule_match_lpm {
848 struct softnic_table_rule_match {
849 enum softnic_table_type match_type;
852 struct softnic_table_rule_match_acl acl;
853 struct softnic_table_rule_match_array array;
854 struct softnic_table_rule_match_hash hash;
855 struct softnic_table_rule_match_lpm lpm;
859 struct softnic_table_rule_action {
860 uint64_t action_mask;
861 struct rte_table_action_fwd_params fwd;
862 struct rte_table_action_lb_params lb;
863 struct rte_table_action_mtr_params mtr;
864 struct rte_table_action_tm_params tm;
865 struct rte_table_action_encap_params encap;
866 struct rte_table_action_nat_params nat;
867 struct rte_table_action_ttl_params ttl;
868 struct rte_table_action_stats_params stats;
869 struct rte_table_action_time_params time;
873 TAILQ_ENTRY(rte_flow) node;
874 struct softnic_table_rule_match match;
875 struct softnic_table_rule_action action;
877 struct pipeline *pipeline;
882 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
883 const char *pipeline_name,
885 struct rte_pipeline_port_in_stats *stats,
889 softnic_pipeline_port_in_enable(struct pmd_internals *p,
890 const char *pipeline_name,
894 softnic_pipeline_port_in_disable(struct pmd_internals *p,
895 const char *pipeline_name,
899 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
900 const char *pipeline_name,
902 struct rte_pipeline_port_out_stats *stats,
906 softnic_pipeline_table_stats_read(struct pmd_internals *p,
907 const char *pipeline_name,
909 struct rte_pipeline_table_stats *stats,
913 softnic_pipeline_table_rule_add(struct pmd_internals *p,
914 const char *pipeline_name,
916 struct softnic_table_rule_match *match,
917 struct softnic_table_rule_action *action,
921 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
922 const char *pipeline_name,
924 struct softnic_table_rule_match *match,
925 struct softnic_table_rule_action *action,
930 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
931 const char *pipeline_name,
933 struct softnic_table_rule_action *action,
937 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
938 const char *pipeline_name,
940 struct softnic_table_rule_match *match);
943 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
944 const char *pipeline_name,
948 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
949 const char *pipeline_name,
952 struct rte_table_action_stats_counters *stats,
956 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
957 const char *pipeline_name,
959 uint32_t meter_profile_id,
960 struct rte_table_action_meter_profile *profile);
963 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
964 const char *pipeline_name,
966 uint32_t meter_profile_id);
969 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
970 const char *pipeline_name,
974 struct rte_table_action_mtr_counters *stats,
978 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
979 const char *pipeline_name,
982 struct rte_table_action_dscp_table *dscp_table);
985 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
986 const char *pipeline_name,
989 struct rte_table_action_ttl_counters *stats,
996 softnic_thread_init(struct pmd_internals *p);
999 softnic_thread_free(struct pmd_internals *p);
1002 softnic_thread_pipeline_enable(struct pmd_internals *p,
1004 const char *pipeline_name);
1007 softnic_thread_pipeline_disable(struct pmd_internals *p,
1009 const char *pipeline_name);
1015 softnic_cli_process(char *in,
1021 softnic_cli_script_process(struct pmd_internals *softnic,
1022 const char *file_name,
1023 size_t msg_in_len_max,
1024 size_t msg_out_len_max);
1026 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */