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_cryptodev_params {
285 const char *dev_name;
286 uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
291 struct softnic_cryptodev {
292 TAILQ_ENTRY(softnic_cryptodev) node;
293 char name[NAME_SIZE];
298 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
303 struct softnic_port_in_action_profile_params {
304 uint64_t action_mask;
305 struct rte_port_in_action_fltr_config fltr;
306 struct rte_port_in_action_lb_config lb;
309 struct softnic_port_in_action_profile {
310 TAILQ_ENTRY(softnic_port_in_action_profile) node;
311 char name[NAME_SIZE];
312 struct softnic_port_in_action_profile_params params;
313 struct rte_port_in_action_profile *ap;
316 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
321 struct softnic_table_action_profile_params {
322 uint64_t action_mask;
323 struct rte_table_action_common_config common;
324 struct rte_table_action_lb_config lb;
325 struct rte_table_action_mtr_config mtr;
326 struct rte_table_action_tm_config tm;
327 struct rte_table_action_encap_config encap;
328 struct rte_table_action_nat_config nat;
329 struct rte_table_action_ttl_config ttl;
330 struct rte_table_action_stats_config stats;
331 struct rte_table_action_sym_crypto_config sym_crypto;
334 struct softnic_table_action_profile {
335 TAILQ_ENTRY(softnic_table_action_profile) node;
336 char name[NAME_SIZE];
337 struct softnic_table_action_profile_params params;
338 struct rte_table_action_profile *ap;
341 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
343 struct softnic_table_meter_profile {
344 TAILQ_ENTRY(softnic_table_meter_profile) node;
345 uint32_t meter_profile_id;
346 struct rte_table_action_meter_profile profile;
349 TAILQ_HEAD(softnic_table_meter_profile_list,
350 softnic_table_meter_profile);
355 struct pipeline_params {
356 uint32_t timer_period_ms;
357 uint32_t offset_port_id;
360 enum softnic_port_in_type {
369 struct softnic_port_in_params {
371 enum softnic_port_in_type type;
372 char dev_name[NAME_SIZE];
379 const char *mempool_name;
384 const char *mempool_name;
385 const char *file_name;
386 uint32_t n_bytes_per_pkt;
398 char action_profile_name[NAME_SIZE];
401 enum softnic_port_out_type {
410 struct softnic_port_out_params {
411 enum softnic_port_out_type type;
412 char dev_name[NAME_SIZE];
419 const char *file_name;
433 enum softnic_table_type {
441 struct softnic_table_acl_params {
443 uint32_t ip_header_offset;
447 struct softnic_table_array_params {
452 #ifndef TABLE_RULE_MATCH_SIZE_MAX
453 #define TABLE_RULE_MATCH_SIZE_MAX 256
456 struct softnic_table_hash_params {
460 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
462 int extendable_bucket;
465 struct softnic_table_lpm_params {
471 struct softnic_table_params {
473 enum softnic_table_type match_type;
475 struct softnic_table_acl_params acl;
476 struct softnic_table_array_params array;
477 struct softnic_table_hash_params hash;
478 struct softnic_table_lpm_params lpm;
482 char action_profile_name[NAME_SIZE];
485 struct softnic_port_in {
486 struct softnic_port_in_params params;
487 struct softnic_port_in_action_profile *ap;
488 struct rte_port_in_action *a;
491 struct softnic_port_out {
492 struct softnic_port_out_params params;
495 struct softnic_table {
496 struct softnic_table_params params;
497 struct softnic_table_action_profile *ap;
498 struct rte_table_action *a;
499 struct flow_list flows;
500 struct rte_table_action_dscp_table dscp_table;
501 struct softnic_table_meter_profile_list meter_profiles;
505 TAILQ_ENTRY(pipeline) node;
506 char name[NAME_SIZE];
508 struct rte_pipeline *p;
509 struct pipeline_params params;
510 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
511 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
512 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
514 uint32_t n_ports_out;
517 struct rte_ring *msgq_req;
518 struct rte_ring *msgq_rsp;
519 uint32_t timer_period_ms;
526 TAILQ_HEAD(pipeline_list, pipeline);
531 #ifndef THREAD_PIPELINES_MAX
532 #define THREAD_PIPELINES_MAX 256
535 #ifndef THREAD_MSGQ_SIZE
536 #define THREAD_MSGQ_SIZE 64
539 #ifndef THREAD_TIMER_PERIOD_MS
540 #define THREAD_TIMER_PERIOD_MS 100
544 * Master thead: data plane thread context
546 struct softnic_thread {
547 struct rte_ring *msgq_req;
548 struct rte_ring *msgq_rsp;
554 * Data plane threads: context
556 #ifndef TABLE_RULE_ACTION_SIZE_MAX
557 #define TABLE_RULE_ACTION_SIZE_MAX 2048
560 struct softnic_table_data {
561 struct rte_table_action *a;
564 struct pipeline_data {
565 struct rte_pipeline *p;
566 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
569 struct rte_ring *msgq_req;
570 struct rte_ring *msgq_rsp;
571 uint64_t timer_period; /* Measured in CPU cycles. */
574 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
577 struct softnic_thread_data {
578 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
579 uint32_t n_pipelines;
581 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
582 struct rte_ring *msgq_req;
583 struct rte_ring *msgq_rsp;
584 uint64_t timer_period; /* Measured in CPU cycles. */
586 uint64_t time_next_min;
588 } __rte_cache_aligned;
593 struct pmd_internals {
595 struct pmd_params params;
598 struct tm_internals tm; /**< Traffic Management */
601 struct flow_internals flow;
602 struct mtr_internals mtr;
604 struct softnic_conn *conn;
605 struct softnic_mempool_list mempool_list;
606 struct softnic_swq_list swq_list;
607 struct softnic_link_list link_list;
608 struct softnic_tmgr_port_list tmgr_port_list;
609 struct softnic_tap_list tap_list;
610 struct softnic_cryptodev_list cryptodev_list;
611 struct softnic_port_in_action_profile_list port_in_action_profile_list;
612 struct softnic_table_action_profile_list table_action_profile_list;
613 struct pipeline_list pipeline_list;
614 struct softnic_thread thread[RTE_MAX_LCORE];
615 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
618 static inline struct rte_eth_dev *
619 ETHDEV(struct pmd_internals *softnic)
627 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
631 return &rte_eth_devices[port_id];
638 flow_attr_map_set(struct pmd_internals *softnic,
641 const char *pipeline_name,
644 struct flow_attr_map *
645 flow_attr_map_get(struct pmd_internals *softnic,
649 extern const struct rte_flow_ops pmd_flow_ops;
655 softnic_mtr_init(struct pmd_internals *p);
658 softnic_mtr_free(struct pmd_internals *p);
661 softnic_mtr_find(struct pmd_internals *p,
664 struct softnic_mtr_meter_profile *
665 softnic_mtr_meter_profile_find(struct pmd_internals *p,
666 uint32_t meter_profile_id);
668 extern const struct rte_mtr_ops pmd_mtr_ops;
674 softnic_mempool_init(struct pmd_internals *p);
677 softnic_mempool_free(struct pmd_internals *p);
679 struct softnic_mempool *
680 softnic_mempool_find(struct pmd_internals *p,
683 struct softnic_mempool *
684 softnic_mempool_create(struct pmd_internals *p,
686 struct softnic_mempool_params *params);
692 softnic_swq_init(struct pmd_internals *p);
695 softnic_swq_free(struct pmd_internals *p);
698 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
701 softnic_swq_find(struct pmd_internals *p,
705 softnic_swq_create(struct pmd_internals *p,
707 struct softnic_swq_params *params);
713 softnic_link_init(struct pmd_internals *p);
716 softnic_link_free(struct pmd_internals *p);
718 struct softnic_link *
719 softnic_link_find(struct pmd_internals *p,
722 struct softnic_link *
723 softnic_link_create(struct pmd_internals *p,
725 struct softnic_link_params *params);
731 softnic_tmgr_init(struct pmd_internals *p);
734 softnic_tmgr_free(struct pmd_internals *p);
736 struct softnic_tmgr_port *
737 softnic_tmgr_port_find(struct pmd_internals *p,
740 struct softnic_tmgr_port *
741 softnic_tmgr_port_create(struct pmd_internals *p,
745 tm_hierarchy_init(struct pmd_internals *p);
748 tm_hierarchy_free(struct pmd_internals *p);
751 tm_used(struct rte_eth_dev *dev)
753 struct pmd_internals *p = dev->data->dev_private;
755 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
758 extern const struct rte_tm_ops pmd_tm_ops;
764 softnic_tap_init(struct pmd_internals *p);
767 softnic_tap_free(struct pmd_internals *p);
770 softnic_tap_find(struct pmd_internals *p,
774 softnic_tap_create(struct pmd_internals *p,
781 softnic_cryptodev_init(struct pmd_internals *p);
784 softnic_cryptodev_free(struct pmd_internals *p);
786 struct softnic_cryptodev *
787 softnic_cryptodev_find(struct pmd_internals *p,
790 struct softnic_cryptodev *
791 softnic_cryptodev_create(struct pmd_internals *p,
793 struct softnic_cryptodev_params *params);
799 softnic_port_in_action_profile_init(struct pmd_internals *p);
802 softnic_port_in_action_profile_free(struct pmd_internals *p);
804 struct softnic_port_in_action_profile *
805 softnic_port_in_action_profile_find(struct pmd_internals *p,
808 struct softnic_port_in_action_profile *
809 softnic_port_in_action_profile_create(struct pmd_internals *p,
811 struct softnic_port_in_action_profile_params *params);
817 softnic_table_action_profile_init(struct pmd_internals *p);
820 softnic_table_action_profile_free(struct pmd_internals *p);
822 struct softnic_table_action_profile *
823 softnic_table_action_profile_find(struct pmd_internals *p,
826 struct softnic_table_action_profile *
827 softnic_table_action_profile_create(struct pmd_internals *p,
829 struct softnic_table_action_profile_params *params);
831 enum rte_table_action_policer
832 softnic_table_action_policer(enum rte_mtr_policer_action action);
838 softnic_pipeline_init(struct pmd_internals *p);
841 softnic_pipeline_free(struct pmd_internals *p);
844 softnic_pipeline_disable_all(struct pmd_internals *p);
847 softnic_pipeline_find(struct pmd_internals *p, const char *name);
850 softnic_pipeline_create(struct pmd_internals *p,
852 struct pipeline_params *params);
855 softnic_pipeline_port_in_create(struct pmd_internals *p,
856 const char *pipeline_name,
857 struct softnic_port_in_params *params,
861 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
862 const char *pipeline_name,
867 softnic_pipeline_port_out_create(struct pmd_internals *p,
868 const char *pipeline_name,
869 struct softnic_port_out_params *params);
872 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
873 const char *pipeline_name,
878 softnic_pipeline_table_create(struct pmd_internals *p,
879 const char *pipeline_name,
880 struct softnic_table_params *params);
882 struct softnic_table_meter_profile *
883 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
884 uint32_t meter_profile_id);
886 struct softnic_table_rule_match_acl {
913 struct softnic_table_rule_match_array {
917 struct softnic_table_rule_match_hash {
918 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
921 struct softnic_table_rule_match_lpm {
933 struct softnic_table_rule_match {
934 enum softnic_table_type match_type;
937 struct softnic_table_rule_match_acl acl;
938 struct softnic_table_rule_match_array array;
939 struct softnic_table_rule_match_hash hash;
940 struct softnic_table_rule_match_lpm lpm;
944 struct softnic_table_rule_action {
945 uint64_t action_mask;
946 struct rte_table_action_fwd_params fwd;
947 struct rte_table_action_lb_params lb;
948 struct rte_table_action_mtr_params mtr;
949 struct rte_table_action_tm_params tm;
950 struct rte_table_action_encap_params encap;
951 struct rte_table_action_nat_params nat;
952 struct rte_table_action_ttl_params ttl;
953 struct rte_table_action_stats_params stats;
954 struct rte_table_action_time_params time;
955 struct rte_table_action_tag_params tag;
956 struct rte_table_action_decap_params decap;
957 struct rte_table_action_sym_crypto_params sym_crypto;
961 TAILQ_ENTRY(rte_flow) node;
962 struct softnic_table_rule_match match;
963 struct softnic_table_rule_action action;
965 struct pipeline *pipeline;
970 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
971 const char *pipeline_name,
973 struct rte_pipeline_port_in_stats *stats,
977 softnic_pipeline_port_in_enable(struct pmd_internals *p,
978 const char *pipeline_name,
982 softnic_pipeline_port_in_disable(struct pmd_internals *p,
983 const char *pipeline_name,
987 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
988 const char *pipeline_name,
990 struct rte_pipeline_port_out_stats *stats,
994 softnic_pipeline_table_stats_read(struct pmd_internals *p,
995 const char *pipeline_name,
997 struct rte_pipeline_table_stats *stats,
1001 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1002 const char *pipeline_name,
1004 struct softnic_table_rule_match *match,
1005 struct softnic_table_rule_action *action,
1009 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1010 const char *pipeline_name,
1012 struct softnic_table_rule_match *match,
1013 struct softnic_table_rule_action *action,
1018 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1019 const char *pipeline_name,
1021 struct softnic_table_rule_action *action,
1025 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1026 const char *pipeline_name,
1028 struct softnic_table_rule_match *match);
1031 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1032 const char *pipeline_name,
1036 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1037 const char *pipeline_name,
1040 struct rte_table_action_stats_counters *stats,
1044 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1045 const char *pipeline_name,
1047 uint32_t meter_profile_id,
1048 struct rte_table_action_meter_profile *profile);
1051 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1052 const char *pipeline_name,
1054 uint32_t meter_profile_id);
1057 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1058 const char *pipeline_name,
1062 struct rte_table_action_mtr_counters *stats,
1066 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1067 const char *pipeline_name,
1070 struct rte_table_action_dscp_table *dscp_table);
1073 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1074 const char *pipeline_name,
1077 struct rte_table_action_ttl_counters *stats,
1084 softnic_thread_init(struct pmd_internals *p);
1087 softnic_thread_free(struct pmd_internals *p);
1090 softnic_thread_pipeline_enable(struct pmd_internals *p,
1092 const char *pipeline_name);
1095 softnic_thread_pipeline_disable(struct pmd_internals *p,
1097 const char *pipeline_name);
1103 softnic_cli_process(char *in,
1109 softnic_cli_script_process(struct pmd_internals *softnic,
1110 const char *file_name,
1111 size_t msg_in_len_max,
1112 size_t msg_out_len_max);
1114 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */