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"
41 int sc; /**< Service cores. */
43 /** Traffic Management (TM) */
45 uint32_t n_queues; /**< Number of queues */
46 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
55 TAILQ_HEAD(flow_list, rte_flow);
57 struct flow_attr_map {
58 char pipeline_name[NAME_SIZE];
63 #ifndef SOFTNIC_FLOW_MAX_GROUPS
64 #define SOFTNIC_FLOW_MAX_GROUPS 64
67 struct flow_internals {
68 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
69 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
76 /* MTR meter profile */
77 struct softnic_mtr_meter_profile {
78 TAILQ_ENTRY(softnic_mtr_meter_profile) node;
79 uint32_t meter_profile_id;
80 struct rte_mtr_meter_profile params;
84 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
86 /* MTR meter object */
88 TAILQ_ENTRY(softnic_mtr) node;
90 struct rte_mtr_params params;
91 struct rte_flow *flow;
94 TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
96 struct mtr_internals {
97 struct softnic_mtr_meter_profile_list meter_profiles;
98 struct softnic_mtr_list mtrs;
104 struct softnic_mempool_params {
105 uint32_t buffer_size;
110 struct softnic_mempool {
111 TAILQ_ENTRY(softnic_mempool) node;
112 char name[NAME_SIZE];
113 struct rte_mempool *m;
114 uint32_t buffer_size;
117 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
122 struct softnic_swq_params {
127 TAILQ_ENTRY(softnic_swq) node;
128 char name[NAME_SIZE];
132 TAILQ_HEAD(softnic_swq_list, softnic_swq);
137 struct softnic_link_params {
138 const char *dev_name;
139 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
142 struct softnic_link {
143 TAILQ_ENTRY(softnic_link) node;
144 char name[NAME_SIZE];
150 TAILQ_HEAD(softnic_link_list, softnic_link);
156 #ifndef TM_MAX_SUBPORTS
157 #define TM_MAX_SUBPORTS 8
160 #ifndef TM_MAX_PIPES_PER_SUBPORT
161 #define TM_MAX_PIPES_PER_SUBPORT 4096
165 struct rte_sched_port_params port_params;
167 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
169 struct rte_sched_pipe_params
170 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
171 uint32_t n_pipe_profiles;
172 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
177 TM_NODE_LEVEL_PORT = 0,
178 TM_NODE_LEVEL_SUBPORT,
185 /* TM Shaper Profile */
186 struct tm_shaper_profile {
187 TAILQ_ENTRY(tm_shaper_profile) node;
188 uint32_t shaper_profile_id;
190 struct rte_tm_shaper_params params;
193 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
195 /* TM Shared Shaper */
196 struct tm_shared_shaper {
197 TAILQ_ENTRY(tm_shared_shaper) node;
198 uint32_t shared_shaper_id;
200 uint32_t shaper_profile_id;
203 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
205 /* TM WRED Profile */
206 struct tm_wred_profile {
207 TAILQ_ENTRY(tm_wred_profile) node;
208 uint32_t wred_profile_id;
210 struct rte_tm_wred_params params;
213 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
217 TAILQ_ENTRY(tm_node) node;
219 uint32_t parent_node_id;
223 struct tm_node *parent_node;
224 struct tm_shaper_profile *shaper_profile;
225 struct tm_wred_profile *wred_profile;
226 struct rte_tm_node_params params;
227 struct rte_tm_node_stats stats;
231 TAILQ_HEAD(tm_node_list, tm_node);
233 /* TM Hierarchy Specification */
234 struct tm_hierarchy {
235 struct tm_shaper_profile_list shaper_profiles;
236 struct tm_shared_shaper_list shared_shapers;
237 struct tm_wred_profile_list wred_profiles;
238 struct tm_node_list nodes;
240 uint32_t n_shaper_profiles;
241 uint32_t n_shared_shapers;
242 uint32_t n_wred_profiles;
245 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
248 struct tm_internals {
249 /** Hierarchy specification
251 * -Hierarchy is unfrozen at init and when port is stopped.
252 * -Hierarchy is frozen on successful hierarchy commit.
253 * -Run-time hierarchy changes are not allowed, therefore it makes
254 * sense to keep the hierarchy frozen after the port is started.
256 struct tm_hierarchy h;
257 int hierarchy_frozen;
260 struct tm_params params;
263 struct softnic_tmgr_port {
264 TAILQ_ENTRY(softnic_tmgr_port) node;
265 char name[NAME_SIZE];
266 struct rte_sched_port *s;
269 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
275 TAILQ_ENTRY(softnic_tap) node;
276 char name[NAME_SIZE];
280 TAILQ_HEAD(softnic_tap_list, softnic_tap);
285 struct softnic_cryptodev_params {
286 const char *dev_name;
287 uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
292 struct softnic_cryptodev {
293 TAILQ_ENTRY(softnic_cryptodev) node;
294 char name[NAME_SIZE];
299 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
304 struct softnic_port_in_action_profile_params {
305 uint64_t action_mask;
306 struct rte_port_in_action_fltr_config fltr;
307 struct rte_port_in_action_lb_config lb;
310 struct softnic_port_in_action_profile {
311 TAILQ_ENTRY(softnic_port_in_action_profile) node;
312 char name[NAME_SIZE];
313 struct softnic_port_in_action_profile_params params;
314 struct rte_port_in_action_profile *ap;
317 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
322 struct softnic_table_action_profile_params {
323 uint64_t action_mask;
324 struct rte_table_action_common_config common;
325 struct rte_table_action_lb_config lb;
326 struct rte_table_action_mtr_config mtr;
327 struct rte_table_action_tm_config tm;
328 struct rte_table_action_encap_config encap;
329 struct rte_table_action_nat_config nat;
330 struct rte_table_action_ttl_config ttl;
331 struct rte_table_action_stats_config stats;
332 struct rte_table_action_sym_crypto_config sym_crypto;
335 struct softnic_table_action_profile {
336 TAILQ_ENTRY(softnic_table_action_profile) node;
337 char name[NAME_SIZE];
338 struct softnic_table_action_profile_params params;
339 struct rte_table_action_profile *ap;
342 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
344 struct softnic_table_meter_profile {
345 TAILQ_ENTRY(softnic_table_meter_profile) node;
346 uint32_t meter_profile_id;
347 struct rte_table_action_meter_profile profile;
350 TAILQ_HEAD(softnic_table_meter_profile_list,
351 softnic_table_meter_profile);
356 struct pipeline_params {
357 uint32_t timer_period_ms;
358 uint32_t offset_port_id;
361 enum softnic_port_in_type {
370 struct softnic_port_in_params {
372 enum softnic_port_in_type type;
373 char dev_name[NAME_SIZE];
380 const char *mempool_name;
385 const char *mempool_name;
386 const char *file_name;
387 uint32_t n_bytes_per_pkt;
399 char action_profile_name[NAME_SIZE];
402 enum softnic_port_out_type {
411 struct softnic_port_out_params {
412 enum softnic_port_out_type type;
413 char dev_name[NAME_SIZE];
420 const char *file_name;
434 enum softnic_table_type {
442 struct softnic_table_acl_params {
444 uint32_t ip_header_offset;
448 struct softnic_table_array_params {
453 #ifndef TABLE_RULE_MATCH_SIZE_MAX
454 #define TABLE_RULE_MATCH_SIZE_MAX 256
457 struct softnic_table_hash_params {
461 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
463 int extendable_bucket;
466 struct softnic_table_lpm_params {
472 struct softnic_table_params {
474 enum softnic_table_type match_type;
476 struct softnic_table_acl_params acl;
477 struct softnic_table_array_params array;
478 struct softnic_table_hash_params hash;
479 struct softnic_table_lpm_params lpm;
483 char action_profile_name[NAME_SIZE];
486 struct softnic_port_in {
487 struct softnic_port_in_params params;
488 struct softnic_port_in_action_profile *ap;
489 struct rte_port_in_action *a;
492 struct softnic_port_out {
493 struct softnic_port_out_params params;
496 struct softnic_table {
497 struct softnic_table_params params;
498 struct softnic_table_action_profile *ap;
499 struct rte_table_action *a;
500 struct flow_list flows;
501 struct rte_table_action_dscp_table dscp_table;
502 struct softnic_table_meter_profile_list meter_profiles;
506 TAILQ_ENTRY(pipeline) node;
507 char name[NAME_SIZE];
509 struct rte_pipeline *p;
510 struct pipeline_params params;
511 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
512 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
513 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
515 uint32_t n_ports_out;
518 struct rte_ring *msgq_req;
519 struct rte_ring *msgq_rsp;
520 uint32_t timer_period_ms;
527 TAILQ_HEAD(pipeline_list, pipeline);
532 #ifndef THREAD_PIPELINES_MAX
533 #define THREAD_PIPELINES_MAX 256
536 #ifndef THREAD_MSGQ_SIZE
537 #define THREAD_MSGQ_SIZE 64
540 #ifndef THREAD_TIMER_PERIOD_MS
541 #define THREAD_TIMER_PERIOD_MS 100
545 * Master thead: data plane thread context
547 struct softnic_thread {
548 struct rte_ring *msgq_req;
549 struct rte_ring *msgq_rsp;
555 * Data plane threads: context
557 #ifndef TABLE_RULE_ACTION_SIZE_MAX
558 #define TABLE_RULE_ACTION_SIZE_MAX 2048
561 struct softnic_table_data {
562 struct rte_table_action *a;
565 struct pipeline_data {
566 struct rte_pipeline *p;
567 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
570 struct rte_ring *msgq_req;
571 struct rte_ring *msgq_rsp;
572 uint64_t timer_period; /* Measured in CPU cycles. */
575 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
578 struct softnic_thread_data {
579 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
580 uint32_t n_pipelines;
582 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
583 struct rte_ring *msgq_req;
584 struct rte_ring *msgq_rsp;
585 uint64_t timer_period; /* Measured in CPU cycles. */
587 uint64_t time_next_min;
589 } __rte_cache_aligned;
594 struct pmd_internals {
596 struct pmd_params params;
599 struct tm_internals tm; /**< Traffic Management */
602 struct flow_internals flow;
603 struct mtr_internals mtr;
605 struct softnic_conn *conn;
606 struct softnic_mempool_list mempool_list;
607 struct softnic_swq_list swq_list;
608 struct softnic_link_list link_list;
609 struct softnic_tmgr_port_list tmgr_port_list;
610 struct softnic_tap_list tap_list;
611 struct softnic_cryptodev_list cryptodev_list;
612 struct softnic_port_in_action_profile_list port_in_action_profile_list;
613 struct softnic_table_action_profile_list table_action_profile_list;
614 struct pipeline_list pipeline_list;
615 struct softnic_thread thread[RTE_MAX_LCORE];
616 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
619 static inline struct rte_eth_dev *
620 ETHDEV(struct pmd_internals *softnic)
628 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
632 return &rte_eth_devices[port_id];
639 flow_attr_map_set(struct pmd_internals *softnic,
642 const char *pipeline_name,
645 struct flow_attr_map *
646 flow_attr_map_get(struct pmd_internals *softnic,
650 extern const struct rte_flow_ops pmd_flow_ops;
656 softnic_mtr_init(struct pmd_internals *p);
659 softnic_mtr_free(struct pmd_internals *p);
662 softnic_mtr_find(struct pmd_internals *p,
665 struct softnic_mtr_meter_profile *
666 softnic_mtr_meter_profile_find(struct pmd_internals *p,
667 uint32_t meter_profile_id);
669 extern const struct rte_mtr_ops pmd_mtr_ops;
675 softnic_mempool_init(struct pmd_internals *p);
678 softnic_mempool_free(struct pmd_internals *p);
680 struct softnic_mempool *
681 softnic_mempool_find(struct pmd_internals *p,
684 struct softnic_mempool *
685 softnic_mempool_create(struct pmd_internals *p,
687 struct softnic_mempool_params *params);
693 softnic_swq_init(struct pmd_internals *p);
696 softnic_swq_free(struct pmd_internals *p);
699 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
702 softnic_swq_find(struct pmd_internals *p,
706 softnic_swq_create(struct pmd_internals *p,
708 struct softnic_swq_params *params);
714 softnic_link_init(struct pmd_internals *p);
717 softnic_link_free(struct pmd_internals *p);
719 struct softnic_link *
720 softnic_link_find(struct pmd_internals *p,
723 struct softnic_link *
724 softnic_link_create(struct pmd_internals *p,
726 struct softnic_link_params *params);
732 softnic_tmgr_init(struct pmd_internals *p);
735 softnic_tmgr_free(struct pmd_internals *p);
737 struct softnic_tmgr_port *
738 softnic_tmgr_port_find(struct pmd_internals *p,
741 struct softnic_tmgr_port *
742 softnic_tmgr_port_create(struct pmd_internals *p,
746 tm_hierarchy_init(struct pmd_internals *p);
749 tm_hierarchy_free(struct pmd_internals *p);
752 tm_used(struct rte_eth_dev *dev)
754 struct pmd_internals *p = dev->data->dev_private;
756 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
759 extern const struct rte_tm_ops pmd_tm_ops;
765 softnic_tap_init(struct pmd_internals *p);
768 softnic_tap_free(struct pmd_internals *p);
771 softnic_tap_find(struct pmd_internals *p,
775 softnic_tap_create(struct pmd_internals *p,
782 softnic_cryptodev_init(struct pmd_internals *p);
785 softnic_cryptodev_free(struct pmd_internals *p);
787 struct softnic_cryptodev *
788 softnic_cryptodev_find(struct pmd_internals *p,
791 struct softnic_cryptodev *
792 softnic_cryptodev_create(struct pmd_internals *p,
794 struct softnic_cryptodev_params *params);
800 softnic_port_in_action_profile_init(struct pmd_internals *p);
803 softnic_port_in_action_profile_free(struct pmd_internals *p);
805 struct softnic_port_in_action_profile *
806 softnic_port_in_action_profile_find(struct pmd_internals *p,
809 struct softnic_port_in_action_profile *
810 softnic_port_in_action_profile_create(struct pmd_internals *p,
812 struct softnic_port_in_action_profile_params *params);
818 softnic_table_action_profile_init(struct pmd_internals *p);
821 softnic_table_action_profile_free(struct pmd_internals *p);
823 struct softnic_table_action_profile *
824 softnic_table_action_profile_find(struct pmd_internals *p,
827 struct softnic_table_action_profile *
828 softnic_table_action_profile_create(struct pmd_internals *p,
830 struct softnic_table_action_profile_params *params);
832 enum rte_table_action_policer
833 softnic_table_action_policer(enum rte_mtr_policer_action action);
839 softnic_pipeline_init(struct pmd_internals *p);
842 softnic_pipeline_free(struct pmd_internals *p);
845 softnic_pipeline_disable_all(struct pmd_internals *p);
848 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
851 softnic_pipeline_find(struct pmd_internals *p, const char *name);
854 softnic_pipeline_create(struct pmd_internals *p,
856 struct pipeline_params *params);
859 softnic_pipeline_port_in_create(struct pmd_internals *p,
860 const char *pipeline_name,
861 struct softnic_port_in_params *params,
865 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
866 const char *pipeline_name,
871 softnic_pipeline_port_out_create(struct pmd_internals *p,
872 const char *pipeline_name,
873 struct softnic_port_out_params *params);
876 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
877 const char *pipeline_name,
882 softnic_pipeline_table_create(struct pmd_internals *p,
883 const char *pipeline_name,
884 struct softnic_table_params *params);
886 struct softnic_table_meter_profile *
887 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
888 uint32_t meter_profile_id);
890 struct softnic_table_rule_match_acl {
917 struct softnic_table_rule_match_array {
921 struct softnic_table_rule_match_hash {
922 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
925 struct softnic_table_rule_match_lpm {
937 struct softnic_table_rule_match {
938 enum softnic_table_type match_type;
941 struct softnic_table_rule_match_acl acl;
942 struct softnic_table_rule_match_array array;
943 struct softnic_table_rule_match_hash hash;
944 struct softnic_table_rule_match_lpm lpm;
948 struct softnic_table_rule_action {
949 uint64_t action_mask;
950 struct rte_table_action_fwd_params fwd;
951 struct rte_table_action_lb_params lb;
952 struct rte_table_action_mtr_params mtr;
953 struct rte_table_action_tm_params tm;
954 struct rte_table_action_encap_params encap;
955 struct rte_table_action_nat_params nat;
956 struct rte_table_action_ttl_params ttl;
957 struct rte_table_action_stats_params stats;
958 struct rte_table_action_time_params time;
959 struct rte_table_action_tag_params tag;
960 struct rte_table_action_decap_params decap;
961 struct rte_table_action_sym_crypto_params sym_crypto;
965 TAILQ_ENTRY(rte_flow) node;
966 struct softnic_table_rule_match match;
967 struct softnic_table_rule_action action;
969 struct pipeline *pipeline;
974 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
975 const char *pipeline_name,
977 struct rte_pipeline_port_in_stats *stats,
981 softnic_pipeline_port_in_enable(struct pmd_internals *p,
982 const char *pipeline_name,
986 softnic_pipeline_port_in_disable(struct pmd_internals *p,
987 const char *pipeline_name,
991 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
992 const char *pipeline_name,
994 struct rte_pipeline_port_out_stats *stats,
998 softnic_pipeline_table_stats_read(struct pmd_internals *p,
999 const char *pipeline_name,
1001 struct rte_pipeline_table_stats *stats,
1005 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1006 const char *pipeline_name,
1008 struct softnic_table_rule_match *match,
1009 struct softnic_table_rule_action *action,
1013 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1014 const char *pipeline_name,
1016 struct softnic_table_rule_match *match,
1017 struct softnic_table_rule_action *action,
1022 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1023 const char *pipeline_name,
1025 struct softnic_table_rule_action *action,
1029 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1030 const char *pipeline_name,
1032 struct softnic_table_rule_match *match);
1035 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1036 const char *pipeline_name,
1040 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1041 const char *pipeline_name,
1044 struct rte_table_action_stats_counters *stats,
1048 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1049 const char *pipeline_name,
1051 uint32_t meter_profile_id,
1052 struct rte_table_action_meter_profile *profile);
1055 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1056 const char *pipeline_name,
1058 uint32_t meter_profile_id);
1061 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1062 const char *pipeline_name,
1066 struct rte_table_action_mtr_counters *stats,
1070 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1071 const char *pipeline_name,
1074 struct rte_table_action_dscp_table *dscp_table);
1077 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1078 const char *pipeline_name,
1081 struct rte_table_action_ttl_counters *stats,
1088 softnic_thread_init(struct pmd_internals *p);
1091 softnic_thread_free(struct pmd_internals *p);
1094 softnic_thread_pipeline_enable(struct pmd_internals *p,
1096 const char *pipeline_name);
1099 softnic_thread_pipeline_disable(struct pmd_internals *p,
1101 const char *pipeline_name);
1107 softnic_cli_process(char *in,
1113 softnic_cli_script_process(struct pmd_internals *softnic,
1114 const char *file_name,
1115 size_t msg_in_len_max,
1116 size_t msg_out_len_max);
1118 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */