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
164 #ifndef TM_MAX_PIPE_PROFILE
165 #define TM_MAX_PIPE_PROFILE 256
168 #ifndef TM_MAX_SUBPORT_PROFILE
169 #define TM_MAX_SUBPORT_PROFILE 256
173 struct rte_sched_port_params port_params;
174 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
175 struct rte_sched_subport_profile_params
176 subport_profile[TM_MAX_SUBPORT_PROFILE];
177 uint32_t n_subport_profiles;
178 uint32_t subport_to_profile[TM_MAX_SUBPORT_PROFILE];
179 struct rte_sched_pipe_params pipe_profiles[TM_MAX_PIPE_PROFILE];
180 uint32_t n_pipe_profiles;
181 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
186 TM_NODE_LEVEL_PORT = 0,
187 TM_NODE_LEVEL_SUBPORT,
194 /* TM Shaper Profile */
195 struct tm_shaper_profile {
196 TAILQ_ENTRY(tm_shaper_profile) node;
197 uint32_t shaper_profile_id;
199 struct rte_tm_shaper_params params;
202 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
204 /* TM Shared Shaper */
205 struct tm_shared_shaper {
206 TAILQ_ENTRY(tm_shared_shaper) node;
207 uint32_t shared_shaper_id;
209 uint32_t shaper_profile_id;
212 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
214 /* TM WRED Profile */
215 struct tm_wred_profile {
216 TAILQ_ENTRY(tm_wred_profile) node;
217 uint32_t wred_profile_id;
219 struct rte_tm_wred_params params;
222 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
226 TAILQ_ENTRY(tm_node) node;
228 uint32_t parent_node_id;
232 struct tm_node *parent_node;
233 struct tm_shaper_profile *shaper_profile;
234 struct tm_wred_profile *wred_profile;
235 struct rte_tm_node_params params;
236 struct rte_tm_node_stats stats;
240 TAILQ_HEAD(tm_node_list, tm_node);
242 /* TM Hierarchy Specification */
243 struct tm_hierarchy {
244 struct tm_shaper_profile_list shaper_profiles;
245 struct tm_shared_shaper_list shared_shapers;
246 struct tm_wred_profile_list wred_profiles;
247 struct tm_node_list nodes;
249 uint32_t n_shaper_profiles;
250 uint32_t n_shared_shapers;
251 uint32_t n_wred_profiles;
254 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
257 struct tm_internals {
258 /** Hierarchy specification
260 * -Hierarchy is unfrozen at init and when port is stopped.
261 * -Hierarchy is frozen on successful hierarchy commit.
262 * -Run-time hierarchy changes are not allowed, therefore it makes
263 * sense to keep the hierarchy frozen after the port is started.
265 struct tm_hierarchy h;
266 int hierarchy_frozen;
269 struct tm_params params;
272 struct softnic_tmgr_port {
273 TAILQ_ENTRY(softnic_tmgr_port) node;
274 char name[NAME_SIZE];
275 struct rte_sched_port *s;
278 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
284 TAILQ_ENTRY(softnic_tap) node;
285 char name[NAME_SIZE];
289 TAILQ_HEAD(softnic_tap_list, softnic_tap);
294 struct softnic_cryptodev_params {
295 const char *dev_name;
296 uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
299 uint32_t session_pool_size;
302 struct softnic_cryptodev {
303 TAILQ_ENTRY(softnic_cryptodev) node;
304 char name[NAME_SIZE];
307 struct rte_mempool *mp_create;
308 struct rte_mempool *mp_init;
311 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
316 struct softnic_port_in_action_profile_params {
317 uint64_t action_mask;
318 struct rte_port_in_action_fltr_config fltr;
319 struct rte_port_in_action_lb_config lb;
322 struct softnic_port_in_action_profile {
323 TAILQ_ENTRY(softnic_port_in_action_profile) node;
324 char name[NAME_SIZE];
325 struct softnic_port_in_action_profile_params params;
326 struct rte_port_in_action_profile *ap;
329 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
334 struct softnic_table_action_profile_params {
335 uint64_t action_mask;
336 struct rte_table_action_common_config common;
337 struct rte_table_action_lb_config lb;
338 struct rte_table_action_mtr_config mtr;
339 struct rte_table_action_tm_config tm;
340 struct rte_table_action_encap_config encap;
341 struct rte_table_action_nat_config nat;
342 struct rte_table_action_ttl_config ttl;
343 struct rte_table_action_stats_config stats;
344 struct rte_table_action_sym_crypto_config sym_crypto;
347 struct softnic_table_action_profile {
348 TAILQ_ENTRY(softnic_table_action_profile) node;
349 char name[NAME_SIZE];
350 struct softnic_table_action_profile_params params;
351 struct rte_table_action_profile *ap;
354 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
356 struct softnic_table_meter_profile {
357 TAILQ_ENTRY(softnic_table_meter_profile) node;
358 uint32_t meter_profile_id;
359 struct rte_table_action_meter_profile profile;
362 TAILQ_HEAD(softnic_table_meter_profile_list,
363 softnic_table_meter_profile);
368 struct pipeline_params {
369 uint32_t timer_period_ms;
370 uint32_t offset_port_id;
373 enum softnic_port_in_type {
382 struct softnic_port_in_params {
384 enum softnic_port_in_type type;
385 char dev_name[NAME_SIZE];
392 const char *mempool_name;
397 const char *mempool_name;
398 const char *file_name;
399 uint32_t n_bytes_per_pkt;
411 char action_profile_name[NAME_SIZE];
414 enum softnic_port_out_type {
423 struct softnic_port_out_params {
424 enum softnic_port_out_type type;
425 char dev_name[NAME_SIZE];
432 const char *file_name;
446 enum softnic_table_type {
454 struct softnic_table_acl_params {
456 uint32_t ip_header_offset;
460 struct softnic_table_array_params {
465 #ifndef TABLE_RULE_MATCH_SIZE_MAX
466 #define TABLE_RULE_MATCH_SIZE_MAX 256
469 struct softnic_table_hash_params {
473 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
475 int extendable_bucket;
478 struct softnic_table_lpm_params {
484 struct softnic_table_params {
486 enum softnic_table_type match_type;
488 struct softnic_table_acl_params acl;
489 struct softnic_table_array_params array;
490 struct softnic_table_hash_params hash;
491 struct softnic_table_lpm_params lpm;
495 char action_profile_name[NAME_SIZE];
498 struct softnic_port_in {
499 struct softnic_port_in_params params;
500 struct softnic_port_in_action_profile *ap;
501 struct rte_port_in_action *a;
504 struct softnic_port_out {
505 struct softnic_port_out_params params;
508 struct softnic_table {
509 struct softnic_table_params params;
510 struct softnic_table_action_profile *ap;
511 struct rte_table_action *a;
512 struct flow_list flows;
513 struct rte_table_action_dscp_table dscp_table;
514 struct softnic_table_meter_profile_list meter_profiles;
518 TAILQ_ENTRY(pipeline) node;
519 char name[NAME_SIZE];
521 struct rte_pipeline *p;
522 struct pipeline_params params;
523 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
524 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
525 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
527 uint32_t n_ports_out;
530 struct rte_ring *msgq_req;
531 struct rte_ring *msgq_rsp;
532 uint32_t timer_period_ms;
539 TAILQ_HEAD(pipeline_list, pipeline);
544 #ifndef THREAD_PIPELINES_MAX
545 #define THREAD_PIPELINES_MAX 256
548 #ifndef THREAD_MSGQ_SIZE
549 #define THREAD_MSGQ_SIZE 64
552 #ifndef THREAD_TIMER_PERIOD_MS
553 #define THREAD_TIMER_PERIOD_MS 100
557 * Master thead: data plane thread context
559 struct softnic_thread {
560 struct rte_ring *msgq_req;
561 struct rte_ring *msgq_rsp;
567 * Data plane threads: context
569 #ifndef TABLE_RULE_ACTION_SIZE_MAX
570 #define TABLE_RULE_ACTION_SIZE_MAX 2048
573 struct softnic_table_data {
574 struct rte_table_action *a;
577 struct pipeline_data {
578 struct rte_pipeline *p;
579 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
582 struct rte_ring *msgq_req;
583 struct rte_ring *msgq_rsp;
584 uint64_t timer_period; /* Measured in CPU cycles. */
587 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
590 struct softnic_thread_data {
591 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
592 uint32_t n_pipelines;
594 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
595 struct rte_ring *msgq_req;
596 struct rte_ring *msgq_rsp;
597 uint64_t timer_period; /* Measured in CPU cycles. */
599 uint64_t time_next_min;
601 } __rte_cache_aligned;
606 struct pmd_internals {
608 struct pmd_params params;
611 struct tm_internals tm; /**< Traffic Management */
614 struct flow_internals flow;
615 struct mtr_internals mtr;
617 struct softnic_conn *conn;
618 struct softnic_mempool_list mempool_list;
619 struct softnic_swq_list swq_list;
620 struct softnic_link_list link_list;
621 struct softnic_tmgr_port_list tmgr_port_list;
622 struct softnic_tap_list tap_list;
623 struct softnic_cryptodev_list cryptodev_list;
624 struct softnic_port_in_action_profile_list port_in_action_profile_list;
625 struct softnic_table_action_profile_list table_action_profile_list;
626 struct pipeline_list pipeline_list;
627 struct softnic_thread thread[RTE_MAX_LCORE];
628 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
631 static inline struct rte_eth_dev *
632 ETHDEV(struct pmd_internals *softnic)
640 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
644 return &rte_eth_devices[port_id];
651 flow_attr_map_set(struct pmd_internals *softnic,
654 const char *pipeline_name,
657 struct flow_attr_map *
658 flow_attr_map_get(struct pmd_internals *softnic,
662 extern const struct rte_flow_ops pmd_flow_ops;
668 softnic_mtr_init(struct pmd_internals *p);
671 softnic_mtr_free(struct pmd_internals *p);
674 softnic_mtr_find(struct pmd_internals *p,
677 struct softnic_mtr_meter_profile *
678 softnic_mtr_meter_profile_find(struct pmd_internals *p,
679 uint32_t meter_profile_id);
681 extern const struct rte_mtr_ops pmd_mtr_ops;
687 softnic_mempool_init(struct pmd_internals *p);
690 softnic_mempool_free(struct pmd_internals *p);
692 struct softnic_mempool *
693 softnic_mempool_find(struct pmd_internals *p,
696 struct softnic_mempool *
697 softnic_mempool_create(struct pmd_internals *p,
699 struct softnic_mempool_params *params);
705 softnic_swq_init(struct pmd_internals *p);
708 softnic_swq_free(struct pmd_internals *p);
711 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
714 softnic_swq_find(struct pmd_internals *p,
718 softnic_swq_create(struct pmd_internals *p,
720 struct softnic_swq_params *params);
726 softnic_link_init(struct pmd_internals *p);
729 softnic_link_free(struct pmd_internals *p);
731 struct softnic_link *
732 softnic_link_find(struct pmd_internals *p,
735 struct softnic_link *
736 softnic_link_create(struct pmd_internals *p,
738 struct softnic_link_params *params);
744 softnic_tmgr_init(struct pmd_internals *p);
747 softnic_tmgr_free(struct pmd_internals *p);
749 struct softnic_tmgr_port *
750 softnic_tmgr_port_find(struct pmd_internals *p,
753 struct softnic_tmgr_port *
754 softnic_tmgr_port_create(struct pmd_internals *p,
758 tm_hierarchy_init(struct pmd_internals *p);
761 tm_hierarchy_free(struct pmd_internals *p);
764 tm_used(struct rte_eth_dev *dev)
766 struct pmd_internals *p = dev->data->dev_private;
768 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
771 extern const struct rte_tm_ops pmd_tm_ops;
777 softnic_tap_init(struct pmd_internals *p);
780 softnic_tap_free(struct pmd_internals *p);
783 softnic_tap_find(struct pmd_internals *p,
787 softnic_tap_create(struct pmd_internals *p,
794 softnic_cryptodev_init(struct pmd_internals *p);
797 softnic_cryptodev_free(struct pmd_internals *p);
799 struct softnic_cryptodev *
800 softnic_cryptodev_find(struct pmd_internals *p,
803 struct softnic_cryptodev *
804 softnic_cryptodev_create(struct pmd_internals *p,
806 struct softnic_cryptodev_params *params);
812 softnic_port_in_action_profile_init(struct pmd_internals *p);
815 softnic_port_in_action_profile_free(struct pmd_internals *p);
817 struct softnic_port_in_action_profile *
818 softnic_port_in_action_profile_find(struct pmd_internals *p,
821 struct softnic_port_in_action_profile *
822 softnic_port_in_action_profile_create(struct pmd_internals *p,
824 struct softnic_port_in_action_profile_params *params);
830 softnic_table_action_profile_init(struct pmd_internals *p);
833 softnic_table_action_profile_free(struct pmd_internals *p);
835 struct softnic_table_action_profile *
836 softnic_table_action_profile_find(struct pmd_internals *p,
839 struct softnic_table_action_profile *
840 softnic_table_action_profile_create(struct pmd_internals *p,
842 struct softnic_table_action_profile_params *params);
844 enum rte_table_action_policer
845 softnic_table_action_policer(enum rte_mtr_policer_action action);
851 softnic_pipeline_init(struct pmd_internals *p);
854 softnic_pipeline_free(struct pmd_internals *p);
857 softnic_pipeline_disable_all(struct pmd_internals *p);
860 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
863 softnic_pipeline_find(struct pmd_internals *p, const char *name);
866 softnic_pipeline_create(struct pmd_internals *p,
868 struct pipeline_params *params);
871 softnic_pipeline_port_in_create(struct pmd_internals *p,
872 const char *pipeline_name,
873 struct softnic_port_in_params *params,
877 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
878 const char *pipeline_name,
883 softnic_pipeline_port_out_create(struct pmd_internals *p,
884 const char *pipeline_name,
885 struct softnic_port_out_params *params);
888 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
889 const char *pipeline_name,
894 softnic_pipeline_table_create(struct pmd_internals *p,
895 const char *pipeline_name,
896 struct softnic_table_params *params);
898 struct softnic_table_meter_profile *
899 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
900 uint32_t meter_profile_id);
902 struct softnic_table_rule_match_acl {
929 struct softnic_table_rule_match_array {
933 struct softnic_table_rule_match_hash {
934 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
937 struct softnic_table_rule_match_lpm {
949 struct softnic_table_rule_match {
950 enum softnic_table_type match_type;
953 struct softnic_table_rule_match_acl acl;
954 struct softnic_table_rule_match_array array;
955 struct softnic_table_rule_match_hash hash;
956 struct softnic_table_rule_match_lpm lpm;
960 #ifndef SYM_CRYPTO_MAX_KEY_SIZE
961 #define SYM_CRYPTO_MAX_KEY_SIZE (256)
963 struct softnic_table_rule_action {
964 uint64_t action_mask;
965 struct rte_table_action_fwd_params fwd;
966 struct rte_table_action_lb_params lb;
967 struct rte_table_action_mtr_params mtr;
968 struct rte_table_action_tm_params tm;
969 struct rte_table_action_encap_params encap;
970 struct rte_table_action_nat_params nat;
971 struct rte_table_action_ttl_params ttl;
972 struct rte_table_action_stats_params stats;
973 struct rte_table_action_time_params time;
974 struct rte_table_action_tag_params tag;
975 struct rte_table_action_decap_params decap;
976 struct rte_table_action_sym_crypto_params sym_crypto;
977 uint8_t sym_crypto_key[SYM_CRYPTO_MAX_KEY_SIZE];
981 TAILQ_ENTRY(rte_flow) node;
982 struct softnic_table_rule_match match;
983 struct softnic_table_rule_action action;
985 struct pipeline *pipeline;
990 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
991 const char *pipeline_name,
993 struct rte_pipeline_port_in_stats *stats,
997 softnic_pipeline_port_in_enable(struct pmd_internals *p,
998 const char *pipeline_name,
1002 softnic_pipeline_port_in_disable(struct pmd_internals *p,
1003 const char *pipeline_name,
1007 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
1008 const char *pipeline_name,
1010 struct rte_pipeline_port_out_stats *stats,
1014 softnic_pipeline_table_stats_read(struct pmd_internals *p,
1015 const char *pipeline_name,
1017 struct rte_pipeline_table_stats *stats,
1021 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1022 const char *pipeline_name,
1024 struct softnic_table_rule_match *match,
1025 struct softnic_table_rule_action *action,
1029 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1030 const char *pipeline_name,
1032 struct softnic_table_rule_match *match,
1033 struct softnic_table_rule_action *action,
1038 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1039 const char *pipeline_name,
1041 struct softnic_table_rule_action *action,
1045 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1046 const char *pipeline_name,
1048 struct softnic_table_rule_match *match);
1051 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1052 const char *pipeline_name,
1056 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1057 const char *pipeline_name,
1060 struct rte_table_action_stats_counters *stats,
1064 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1065 const char *pipeline_name,
1067 uint32_t meter_profile_id,
1068 struct rte_table_action_meter_profile *profile);
1071 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1072 const char *pipeline_name,
1074 uint32_t meter_profile_id);
1077 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1078 const char *pipeline_name,
1082 struct rte_table_action_mtr_counters *stats,
1086 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1087 const char *pipeline_name,
1090 struct rte_table_action_dscp_table *dscp_table);
1093 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1094 const char *pipeline_name,
1097 struct rte_table_action_ttl_counters *stats,
1104 softnic_thread_init(struct pmd_internals *p);
1107 softnic_thread_free(struct pmd_internals *p);
1110 softnic_thread_pipeline_enable(struct pmd_internals *p,
1112 const char *pipeline_name);
1115 softnic_thread_pipeline_disable(struct pmd_internals *p,
1117 const char *pipeline_name);
1123 softnic_cli_process(char *in,
1129 softnic_cli_script_process(struct pmd_internals *softnic,
1130 const char *file_name,
1131 size_t msg_in_len_max,
1132 size_t msg_out_len_max);
1134 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */