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 struct rte_sched_port_params port_params;
170 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
172 struct rte_sched_pipe_params pipe_profiles[TM_MAX_PIPE_PROFILE];
173 uint32_t n_pipe_profiles;
174 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
179 TM_NODE_LEVEL_PORT = 0,
180 TM_NODE_LEVEL_SUBPORT,
187 /* TM Shaper Profile */
188 struct tm_shaper_profile {
189 TAILQ_ENTRY(tm_shaper_profile) node;
190 uint32_t shaper_profile_id;
192 struct rte_tm_shaper_params params;
195 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
197 /* TM Shared Shaper */
198 struct tm_shared_shaper {
199 TAILQ_ENTRY(tm_shared_shaper) node;
200 uint32_t shared_shaper_id;
202 uint32_t shaper_profile_id;
205 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
207 /* TM WRED Profile */
208 struct tm_wred_profile {
209 TAILQ_ENTRY(tm_wred_profile) node;
210 uint32_t wred_profile_id;
212 struct rte_tm_wred_params params;
215 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
219 TAILQ_ENTRY(tm_node) node;
221 uint32_t parent_node_id;
225 struct tm_node *parent_node;
226 struct tm_shaper_profile *shaper_profile;
227 struct tm_wred_profile *wred_profile;
228 struct rte_tm_node_params params;
229 struct rte_tm_node_stats stats;
233 TAILQ_HEAD(tm_node_list, tm_node);
235 /* TM Hierarchy Specification */
236 struct tm_hierarchy {
237 struct tm_shaper_profile_list shaper_profiles;
238 struct tm_shared_shaper_list shared_shapers;
239 struct tm_wred_profile_list wred_profiles;
240 struct tm_node_list nodes;
242 uint32_t n_shaper_profiles;
243 uint32_t n_shared_shapers;
244 uint32_t n_wred_profiles;
247 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
250 struct tm_internals {
251 /** Hierarchy specification
253 * -Hierarchy is unfrozen at init and when port is stopped.
254 * -Hierarchy is frozen on successful hierarchy commit.
255 * -Run-time hierarchy changes are not allowed, therefore it makes
256 * sense to keep the hierarchy frozen after the port is started.
258 struct tm_hierarchy h;
259 int hierarchy_frozen;
262 struct tm_params params;
265 struct softnic_tmgr_port {
266 TAILQ_ENTRY(softnic_tmgr_port) node;
267 char name[NAME_SIZE];
268 struct rte_sched_port *s;
271 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
277 TAILQ_ENTRY(softnic_tap) node;
278 char name[NAME_SIZE];
282 TAILQ_HEAD(softnic_tap_list, softnic_tap);
287 struct softnic_cryptodev_params {
288 const char *dev_name;
289 uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
292 uint32_t session_pool_size;
295 struct softnic_cryptodev {
296 TAILQ_ENTRY(softnic_cryptodev) node;
297 char name[NAME_SIZE];
300 struct rte_mempool *mp_create;
301 struct rte_mempool *mp_init;
304 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
309 struct softnic_port_in_action_profile_params {
310 uint64_t action_mask;
311 struct rte_port_in_action_fltr_config fltr;
312 struct rte_port_in_action_lb_config lb;
315 struct softnic_port_in_action_profile {
316 TAILQ_ENTRY(softnic_port_in_action_profile) node;
317 char name[NAME_SIZE];
318 struct softnic_port_in_action_profile_params params;
319 struct rte_port_in_action_profile *ap;
322 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
327 struct softnic_table_action_profile_params {
328 uint64_t action_mask;
329 struct rte_table_action_common_config common;
330 struct rte_table_action_lb_config lb;
331 struct rte_table_action_mtr_config mtr;
332 struct rte_table_action_tm_config tm;
333 struct rte_table_action_encap_config encap;
334 struct rte_table_action_nat_config nat;
335 struct rte_table_action_ttl_config ttl;
336 struct rte_table_action_stats_config stats;
337 struct rte_table_action_sym_crypto_config sym_crypto;
340 struct softnic_table_action_profile {
341 TAILQ_ENTRY(softnic_table_action_profile) node;
342 char name[NAME_SIZE];
343 struct softnic_table_action_profile_params params;
344 struct rte_table_action_profile *ap;
347 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
349 struct softnic_table_meter_profile {
350 TAILQ_ENTRY(softnic_table_meter_profile) node;
351 uint32_t meter_profile_id;
352 struct rte_table_action_meter_profile profile;
355 TAILQ_HEAD(softnic_table_meter_profile_list,
356 softnic_table_meter_profile);
361 struct pipeline_params {
362 uint32_t timer_period_ms;
363 uint32_t offset_port_id;
366 enum softnic_port_in_type {
375 struct softnic_port_in_params {
377 enum softnic_port_in_type type;
378 char dev_name[NAME_SIZE];
385 const char *mempool_name;
390 const char *mempool_name;
391 const char *file_name;
392 uint32_t n_bytes_per_pkt;
404 char action_profile_name[NAME_SIZE];
407 enum softnic_port_out_type {
416 struct softnic_port_out_params {
417 enum softnic_port_out_type type;
418 char dev_name[NAME_SIZE];
425 const char *file_name;
439 enum softnic_table_type {
447 struct softnic_table_acl_params {
449 uint32_t ip_header_offset;
453 struct softnic_table_array_params {
458 #ifndef TABLE_RULE_MATCH_SIZE_MAX
459 #define TABLE_RULE_MATCH_SIZE_MAX 256
462 struct softnic_table_hash_params {
466 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
468 int extendable_bucket;
471 struct softnic_table_lpm_params {
477 struct softnic_table_params {
479 enum softnic_table_type match_type;
481 struct softnic_table_acl_params acl;
482 struct softnic_table_array_params array;
483 struct softnic_table_hash_params hash;
484 struct softnic_table_lpm_params lpm;
488 char action_profile_name[NAME_SIZE];
491 struct softnic_port_in {
492 struct softnic_port_in_params params;
493 struct softnic_port_in_action_profile *ap;
494 struct rte_port_in_action *a;
497 struct softnic_port_out {
498 struct softnic_port_out_params params;
501 struct softnic_table {
502 struct softnic_table_params params;
503 struct softnic_table_action_profile *ap;
504 struct rte_table_action *a;
505 struct flow_list flows;
506 struct rte_table_action_dscp_table dscp_table;
507 struct softnic_table_meter_profile_list meter_profiles;
511 TAILQ_ENTRY(pipeline) node;
512 char name[NAME_SIZE];
514 struct rte_pipeline *p;
515 struct pipeline_params params;
516 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
517 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
518 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
520 uint32_t n_ports_out;
523 struct rte_ring *msgq_req;
524 struct rte_ring *msgq_rsp;
525 uint32_t timer_period_ms;
532 TAILQ_HEAD(pipeline_list, pipeline);
537 #ifndef THREAD_PIPELINES_MAX
538 #define THREAD_PIPELINES_MAX 256
541 #ifndef THREAD_MSGQ_SIZE
542 #define THREAD_MSGQ_SIZE 64
545 #ifndef THREAD_TIMER_PERIOD_MS
546 #define THREAD_TIMER_PERIOD_MS 100
550 * Master thead: data plane thread context
552 struct softnic_thread {
553 struct rte_ring *msgq_req;
554 struct rte_ring *msgq_rsp;
560 * Data plane threads: context
562 #ifndef TABLE_RULE_ACTION_SIZE_MAX
563 #define TABLE_RULE_ACTION_SIZE_MAX 2048
566 struct softnic_table_data {
567 struct rte_table_action *a;
570 struct pipeline_data {
571 struct rte_pipeline *p;
572 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
575 struct rte_ring *msgq_req;
576 struct rte_ring *msgq_rsp;
577 uint64_t timer_period; /* Measured in CPU cycles. */
580 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
583 struct softnic_thread_data {
584 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
585 uint32_t n_pipelines;
587 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
588 struct rte_ring *msgq_req;
589 struct rte_ring *msgq_rsp;
590 uint64_t timer_period; /* Measured in CPU cycles. */
592 uint64_t time_next_min;
594 } __rte_cache_aligned;
599 struct pmd_internals {
601 struct pmd_params params;
604 struct tm_internals tm; /**< Traffic Management */
607 struct flow_internals flow;
608 struct mtr_internals mtr;
610 struct softnic_conn *conn;
611 struct softnic_mempool_list mempool_list;
612 struct softnic_swq_list swq_list;
613 struct softnic_link_list link_list;
614 struct softnic_tmgr_port_list tmgr_port_list;
615 struct softnic_tap_list tap_list;
616 struct softnic_cryptodev_list cryptodev_list;
617 struct softnic_port_in_action_profile_list port_in_action_profile_list;
618 struct softnic_table_action_profile_list table_action_profile_list;
619 struct pipeline_list pipeline_list;
620 struct softnic_thread thread[RTE_MAX_LCORE];
621 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
624 static inline struct rte_eth_dev *
625 ETHDEV(struct pmd_internals *softnic)
633 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
637 return &rte_eth_devices[port_id];
644 flow_attr_map_set(struct pmd_internals *softnic,
647 const char *pipeline_name,
650 struct flow_attr_map *
651 flow_attr_map_get(struct pmd_internals *softnic,
655 extern const struct rte_flow_ops pmd_flow_ops;
661 softnic_mtr_init(struct pmd_internals *p);
664 softnic_mtr_free(struct pmd_internals *p);
667 softnic_mtr_find(struct pmd_internals *p,
670 struct softnic_mtr_meter_profile *
671 softnic_mtr_meter_profile_find(struct pmd_internals *p,
672 uint32_t meter_profile_id);
674 extern const struct rte_mtr_ops pmd_mtr_ops;
680 softnic_mempool_init(struct pmd_internals *p);
683 softnic_mempool_free(struct pmd_internals *p);
685 struct softnic_mempool *
686 softnic_mempool_find(struct pmd_internals *p,
689 struct softnic_mempool *
690 softnic_mempool_create(struct pmd_internals *p,
692 struct softnic_mempool_params *params);
698 softnic_swq_init(struct pmd_internals *p);
701 softnic_swq_free(struct pmd_internals *p);
704 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
707 softnic_swq_find(struct pmd_internals *p,
711 softnic_swq_create(struct pmd_internals *p,
713 struct softnic_swq_params *params);
719 softnic_link_init(struct pmd_internals *p);
722 softnic_link_free(struct pmd_internals *p);
724 struct softnic_link *
725 softnic_link_find(struct pmd_internals *p,
728 struct softnic_link *
729 softnic_link_create(struct pmd_internals *p,
731 struct softnic_link_params *params);
737 softnic_tmgr_init(struct pmd_internals *p);
740 softnic_tmgr_free(struct pmd_internals *p);
742 struct softnic_tmgr_port *
743 softnic_tmgr_port_find(struct pmd_internals *p,
746 struct softnic_tmgr_port *
747 softnic_tmgr_port_create(struct pmd_internals *p,
751 tm_hierarchy_init(struct pmd_internals *p);
754 tm_hierarchy_free(struct pmd_internals *p);
757 tm_used(struct rte_eth_dev *dev)
759 struct pmd_internals *p = dev->data->dev_private;
761 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
764 extern const struct rte_tm_ops pmd_tm_ops;
770 softnic_tap_init(struct pmd_internals *p);
773 softnic_tap_free(struct pmd_internals *p);
776 softnic_tap_find(struct pmd_internals *p,
780 softnic_tap_create(struct pmd_internals *p,
787 softnic_cryptodev_init(struct pmd_internals *p);
790 softnic_cryptodev_free(struct pmd_internals *p);
792 struct softnic_cryptodev *
793 softnic_cryptodev_find(struct pmd_internals *p,
796 struct softnic_cryptodev *
797 softnic_cryptodev_create(struct pmd_internals *p,
799 struct softnic_cryptodev_params *params);
805 softnic_port_in_action_profile_init(struct pmd_internals *p);
808 softnic_port_in_action_profile_free(struct pmd_internals *p);
810 struct softnic_port_in_action_profile *
811 softnic_port_in_action_profile_find(struct pmd_internals *p,
814 struct softnic_port_in_action_profile *
815 softnic_port_in_action_profile_create(struct pmd_internals *p,
817 struct softnic_port_in_action_profile_params *params);
823 softnic_table_action_profile_init(struct pmd_internals *p);
826 softnic_table_action_profile_free(struct pmd_internals *p);
828 struct softnic_table_action_profile *
829 softnic_table_action_profile_find(struct pmd_internals *p,
832 struct softnic_table_action_profile *
833 softnic_table_action_profile_create(struct pmd_internals *p,
835 struct softnic_table_action_profile_params *params);
837 enum rte_table_action_policer
838 softnic_table_action_policer(enum rte_mtr_policer_action action);
844 softnic_pipeline_init(struct pmd_internals *p);
847 softnic_pipeline_free(struct pmd_internals *p);
850 softnic_pipeline_disable_all(struct pmd_internals *p);
853 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
856 softnic_pipeline_find(struct pmd_internals *p, const char *name);
859 softnic_pipeline_create(struct pmd_internals *p,
861 struct pipeline_params *params);
864 softnic_pipeline_port_in_create(struct pmd_internals *p,
865 const char *pipeline_name,
866 struct softnic_port_in_params *params,
870 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
871 const char *pipeline_name,
876 softnic_pipeline_port_out_create(struct pmd_internals *p,
877 const char *pipeline_name,
878 struct softnic_port_out_params *params);
881 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
882 const char *pipeline_name,
887 softnic_pipeline_table_create(struct pmd_internals *p,
888 const char *pipeline_name,
889 struct softnic_table_params *params);
891 struct softnic_table_meter_profile *
892 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
893 uint32_t meter_profile_id);
895 struct softnic_table_rule_match_acl {
922 struct softnic_table_rule_match_array {
926 struct softnic_table_rule_match_hash {
927 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
930 struct softnic_table_rule_match_lpm {
942 struct softnic_table_rule_match {
943 enum softnic_table_type match_type;
946 struct softnic_table_rule_match_acl acl;
947 struct softnic_table_rule_match_array array;
948 struct softnic_table_rule_match_hash hash;
949 struct softnic_table_rule_match_lpm lpm;
953 #ifndef SYM_CRYPTO_MAX_KEY_SIZE
954 #define SYM_CRYPTO_MAX_KEY_SIZE (256)
956 struct softnic_table_rule_action {
957 uint64_t action_mask;
958 struct rte_table_action_fwd_params fwd;
959 struct rte_table_action_lb_params lb;
960 struct rte_table_action_mtr_params mtr;
961 struct rte_table_action_tm_params tm;
962 struct rte_table_action_encap_params encap;
963 struct rte_table_action_nat_params nat;
964 struct rte_table_action_ttl_params ttl;
965 struct rte_table_action_stats_params stats;
966 struct rte_table_action_time_params time;
967 struct rte_table_action_tag_params tag;
968 struct rte_table_action_decap_params decap;
969 struct rte_table_action_sym_crypto_params sym_crypto;
970 uint8_t sym_crypto_key[SYM_CRYPTO_MAX_KEY_SIZE];
974 TAILQ_ENTRY(rte_flow) node;
975 struct softnic_table_rule_match match;
976 struct softnic_table_rule_action action;
978 struct pipeline *pipeline;
983 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
984 const char *pipeline_name,
986 struct rte_pipeline_port_in_stats *stats,
990 softnic_pipeline_port_in_enable(struct pmd_internals *p,
991 const char *pipeline_name,
995 softnic_pipeline_port_in_disable(struct pmd_internals *p,
996 const char *pipeline_name,
1000 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
1001 const char *pipeline_name,
1003 struct rte_pipeline_port_out_stats *stats,
1007 softnic_pipeline_table_stats_read(struct pmd_internals *p,
1008 const char *pipeline_name,
1010 struct rte_pipeline_table_stats *stats,
1014 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1015 const char *pipeline_name,
1017 struct softnic_table_rule_match *match,
1018 struct softnic_table_rule_action *action,
1022 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1023 const char *pipeline_name,
1025 struct softnic_table_rule_match *match,
1026 struct softnic_table_rule_action *action,
1031 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1032 const char *pipeline_name,
1034 struct softnic_table_rule_action *action,
1038 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1039 const char *pipeline_name,
1041 struct softnic_table_rule_match *match);
1044 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1045 const char *pipeline_name,
1049 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1050 const char *pipeline_name,
1053 struct rte_table_action_stats_counters *stats,
1057 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1058 const char *pipeline_name,
1060 uint32_t meter_profile_id,
1061 struct rte_table_action_meter_profile *profile);
1064 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1065 const char *pipeline_name,
1067 uint32_t meter_profile_id);
1070 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1071 const char *pipeline_name,
1075 struct rte_table_action_mtr_counters *stats,
1079 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1080 const char *pipeline_name,
1083 struct rte_table_action_dscp_table *dscp_table);
1086 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1087 const char *pipeline_name,
1090 struct rte_table_action_ttl_counters *stats,
1097 softnic_thread_init(struct pmd_internals *p);
1100 softnic_thread_free(struct pmd_internals *p);
1103 softnic_thread_pipeline_enable(struct pmd_internals *p,
1105 const char *pipeline_name);
1108 softnic_thread_pipeline_disable(struct pmd_internals *p,
1110 const char *pipeline_name);
1116 softnic_cli_process(char *in,
1122 softnic_cli_script_process(struct pmd_internals *softnic,
1123 const char *file_name,
1124 size_t msg_in_len_max,
1125 size_t msg_out_len_max);
1127 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */