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_driver.h>
22 #include <rte_tm_driver.h>
23 #include <rte_flow_driver.h>
25 #include "rte_eth_softnic.h"
40 /** Traffic Management (TM) */
42 uint32_t n_queues; /**< Number of queues */
43 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
52 TAILQ_HEAD(flow_list, rte_flow);
54 struct flow_attr_map {
55 char pipeline_name[NAME_SIZE];
60 #ifndef SOFTNIC_FLOW_MAX_GROUPS
61 #define SOFTNIC_FLOW_MAX_GROUPS 64
64 struct flow_internals {
65 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
66 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
72 struct softnic_mempool_params {
78 struct softnic_mempool {
79 TAILQ_ENTRY(softnic_mempool) node;
81 struct rte_mempool *m;
85 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
90 struct softnic_swq_params {
95 TAILQ_ENTRY(softnic_swq) node;
100 TAILQ_HEAD(softnic_swq_list, softnic_swq);
105 struct softnic_link_params {
106 const char *dev_name;
107 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
110 struct softnic_link {
111 TAILQ_ENTRY(softnic_link) node;
112 char name[NAME_SIZE];
118 TAILQ_HEAD(softnic_link_list, softnic_link);
124 #ifndef TM_MAX_SUBPORTS
125 #define TM_MAX_SUBPORTS 8
128 #ifndef TM_MAX_PIPES_PER_SUBPORT
129 #define TM_MAX_PIPES_PER_SUBPORT 4096
133 struct rte_sched_port_params port_params;
135 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
137 struct rte_sched_pipe_params
138 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
139 uint32_t n_pipe_profiles;
140 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
145 TM_NODE_LEVEL_PORT = 0,
146 TM_NODE_LEVEL_SUBPORT,
153 /* TM Shaper Profile */
154 struct tm_shaper_profile {
155 TAILQ_ENTRY(tm_shaper_profile) node;
156 uint32_t shaper_profile_id;
158 struct rte_tm_shaper_params params;
161 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
163 /* TM Shared Shaper */
164 struct tm_shared_shaper {
165 TAILQ_ENTRY(tm_shared_shaper) node;
166 uint32_t shared_shaper_id;
168 uint32_t shaper_profile_id;
171 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
173 /* TM WRED Profile */
174 struct tm_wred_profile {
175 TAILQ_ENTRY(tm_wred_profile) node;
176 uint32_t wred_profile_id;
178 struct rte_tm_wred_params params;
181 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
185 TAILQ_ENTRY(tm_node) node;
187 uint32_t parent_node_id;
191 struct tm_node *parent_node;
192 struct tm_shaper_profile *shaper_profile;
193 struct tm_wred_profile *wred_profile;
194 struct rte_tm_node_params params;
195 struct rte_tm_node_stats stats;
199 TAILQ_HEAD(tm_node_list, tm_node);
201 /* TM Hierarchy Specification */
202 struct tm_hierarchy {
203 struct tm_shaper_profile_list shaper_profiles;
204 struct tm_shared_shaper_list shared_shapers;
205 struct tm_wred_profile_list wred_profiles;
206 struct tm_node_list nodes;
208 uint32_t n_shaper_profiles;
209 uint32_t n_shared_shapers;
210 uint32_t n_wred_profiles;
213 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
216 struct tm_internals {
217 /** Hierarchy specification
219 * -Hierarchy is unfrozen at init and when port is stopped.
220 * -Hierarchy is frozen on successful hierarchy commit.
221 * -Run-time hierarchy changes are not allowed, therefore it makes
222 * sense to keep the hierarchy frozen after the port is started.
224 struct tm_hierarchy h;
225 int hierarchy_frozen;
228 struct tm_params params;
231 struct softnic_tmgr_port {
232 TAILQ_ENTRY(softnic_tmgr_port) node;
233 char name[NAME_SIZE];
234 struct rte_sched_port *s;
237 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
243 TAILQ_ENTRY(softnic_tap) node;
244 char name[NAME_SIZE];
248 TAILQ_HEAD(softnic_tap_list, softnic_tap);
253 struct softnic_port_in_action_profile_params {
254 uint64_t action_mask;
255 struct rte_port_in_action_fltr_config fltr;
256 struct rte_port_in_action_lb_config lb;
259 struct softnic_port_in_action_profile {
260 TAILQ_ENTRY(softnic_port_in_action_profile) node;
261 char name[NAME_SIZE];
262 struct softnic_port_in_action_profile_params params;
263 struct rte_port_in_action_profile *ap;
266 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
271 struct softnic_table_action_profile_params {
272 uint64_t action_mask;
273 struct rte_table_action_common_config common;
274 struct rte_table_action_lb_config lb;
275 struct rte_table_action_mtr_config mtr;
276 struct rte_table_action_tm_config tm;
277 struct rte_table_action_encap_config encap;
278 struct rte_table_action_nat_config nat;
279 struct rte_table_action_ttl_config ttl;
280 struct rte_table_action_stats_config stats;
283 struct softnic_table_action_profile {
284 TAILQ_ENTRY(softnic_table_action_profile) node;
285 char name[NAME_SIZE];
286 struct softnic_table_action_profile_params params;
287 struct rte_table_action_profile *ap;
290 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
295 struct pipeline_params {
296 uint32_t timer_period_ms;
297 uint32_t offset_port_id;
300 enum softnic_port_in_type {
308 struct softnic_port_in_params {
310 enum softnic_port_in_type type;
311 char dev_name[NAME_SIZE];
318 const char *mempool_name;
323 const char *mempool_name;
324 const char *file_name;
325 uint32_t n_bytes_per_pkt;
331 char action_profile_name[NAME_SIZE];
334 enum softnic_port_out_type {
342 struct softnic_port_out_params {
343 enum softnic_port_out_type type;
344 char dev_name[NAME_SIZE];
351 const char *file_name;
360 enum softnic_table_type {
368 struct softnic_table_acl_params {
370 uint32_t ip_header_offset;
374 struct softnic_table_array_params {
379 #ifndef TABLE_RULE_MATCH_SIZE_MAX
380 #define TABLE_RULE_MATCH_SIZE_MAX 256
383 struct softnic_table_hash_params {
387 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
389 int extendable_bucket;
392 struct softnic_table_lpm_params {
398 struct softnic_table_params {
400 enum softnic_table_type match_type;
402 struct softnic_table_acl_params acl;
403 struct softnic_table_array_params array;
404 struct softnic_table_hash_params hash;
405 struct softnic_table_lpm_params lpm;
409 char action_profile_name[NAME_SIZE];
412 struct softnic_port_in {
413 struct softnic_port_in_params params;
414 struct softnic_port_in_action_profile *ap;
415 struct rte_port_in_action *a;
418 struct softnic_table {
419 struct softnic_table_params params;
420 struct softnic_table_action_profile *ap;
421 struct rte_table_action *a;
425 TAILQ_ENTRY(pipeline) node;
426 char name[NAME_SIZE];
428 struct rte_pipeline *p;
429 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
430 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
432 uint32_t n_ports_out;
435 struct rte_ring *msgq_req;
436 struct rte_ring *msgq_rsp;
437 uint32_t timer_period_ms;
444 TAILQ_HEAD(pipeline_list, pipeline);
449 #ifndef THREAD_PIPELINES_MAX
450 #define THREAD_PIPELINES_MAX 256
453 #ifndef THREAD_MSGQ_SIZE
454 #define THREAD_MSGQ_SIZE 64
457 #ifndef THREAD_TIMER_PERIOD_MS
458 #define THREAD_TIMER_PERIOD_MS 100
462 * Master thead: data plane thread context
464 struct softnic_thread {
465 struct rte_ring *msgq_req;
466 struct rte_ring *msgq_rsp;
472 * Data plane threads: context
474 #ifndef TABLE_RULE_ACTION_SIZE_MAX
475 #define TABLE_RULE_ACTION_SIZE_MAX 2048
478 struct softnic_table_data {
479 struct rte_table_action *a;
482 struct pipeline_data {
483 struct rte_pipeline *p;
484 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
487 struct rte_ring *msgq_req;
488 struct rte_ring *msgq_rsp;
489 uint64_t timer_period; /* Measured in CPU cycles. */
492 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
495 struct softnic_thread_data {
496 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
497 uint32_t n_pipelines;
499 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
500 struct rte_ring *msgq_req;
501 struct rte_ring *msgq_rsp;
502 uint64_t timer_period; /* Measured in CPU cycles. */
504 uint64_t time_next_min;
506 } __rte_cache_aligned;
511 struct pmd_internals {
513 struct pmd_params params;
516 struct tm_internals tm; /**< Traffic Management */
519 struct flow_internals flow;
520 struct softnic_conn *conn;
521 struct softnic_mempool_list mempool_list;
522 struct softnic_swq_list swq_list;
523 struct softnic_link_list link_list;
524 struct softnic_tmgr_port_list tmgr_port_list;
525 struct softnic_tap_list tap_list;
526 struct softnic_port_in_action_profile_list port_in_action_profile_list;
527 struct softnic_table_action_profile_list table_action_profile_list;
528 struct pipeline_list pipeline_list;
529 struct softnic_thread thread[RTE_MAX_LCORE];
530 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
537 flow_attr_map_set(struct pmd_internals *softnic,
540 const char *pipeline_name,
543 struct flow_attr_map *
544 flow_attr_map_get(struct pmd_internals *softnic,
552 softnic_mempool_init(struct pmd_internals *p);
555 softnic_mempool_free(struct pmd_internals *p);
557 struct softnic_mempool *
558 softnic_mempool_find(struct pmd_internals *p,
561 struct softnic_mempool *
562 softnic_mempool_create(struct pmd_internals *p,
564 struct softnic_mempool_params *params);
570 softnic_swq_init(struct pmd_internals *p);
573 softnic_swq_free(struct pmd_internals *p);
576 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
579 softnic_swq_find(struct pmd_internals *p,
583 softnic_swq_create(struct pmd_internals *p,
585 struct softnic_swq_params *params);
591 softnic_link_init(struct pmd_internals *p);
594 softnic_link_free(struct pmd_internals *p);
596 struct softnic_link *
597 softnic_link_find(struct pmd_internals *p,
600 struct softnic_link *
601 softnic_link_create(struct pmd_internals *p,
603 struct softnic_link_params *params);
609 softnic_tmgr_init(struct pmd_internals *p);
612 softnic_tmgr_free(struct pmd_internals *p);
614 struct softnic_tmgr_port *
615 softnic_tmgr_port_find(struct pmd_internals *p,
618 struct softnic_tmgr_port *
619 softnic_tmgr_port_create(struct pmd_internals *p,
623 tm_hierarchy_init(struct pmd_internals *p);
626 tm_hierarchy_free(struct pmd_internals *p);
629 tm_used(struct rte_eth_dev *dev)
631 struct pmd_internals *p = dev->data->dev_private;
633 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
636 extern const struct rte_tm_ops pmd_tm_ops;
642 softnic_tap_init(struct pmd_internals *p);
645 softnic_tap_free(struct pmd_internals *p);
648 softnic_tap_find(struct pmd_internals *p,
652 softnic_tap_create(struct pmd_internals *p,
659 softnic_port_in_action_profile_init(struct pmd_internals *p);
662 softnic_port_in_action_profile_free(struct pmd_internals *p);
664 struct softnic_port_in_action_profile *
665 softnic_port_in_action_profile_find(struct pmd_internals *p,
668 struct softnic_port_in_action_profile *
669 softnic_port_in_action_profile_create(struct pmd_internals *p,
671 struct softnic_port_in_action_profile_params *params);
677 softnic_table_action_profile_init(struct pmd_internals *p);
680 softnic_table_action_profile_free(struct pmd_internals *p);
682 struct softnic_table_action_profile *
683 softnic_table_action_profile_find(struct pmd_internals *p,
686 struct softnic_table_action_profile *
687 softnic_table_action_profile_create(struct pmd_internals *p,
689 struct softnic_table_action_profile_params *params);
695 softnic_pipeline_init(struct pmd_internals *p);
698 softnic_pipeline_free(struct pmd_internals *p);
701 softnic_pipeline_disable_all(struct pmd_internals *p);
704 softnic_pipeline_find(struct pmd_internals *p, const char *name);
707 softnic_pipeline_create(struct pmd_internals *p,
709 struct pipeline_params *params);
712 softnic_pipeline_port_in_create(struct pmd_internals *p,
713 const char *pipeline_name,
714 struct softnic_port_in_params *params,
718 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
719 const char *pipeline_name,
724 softnic_pipeline_port_out_create(struct pmd_internals *p,
725 const char *pipeline_name,
726 struct softnic_port_out_params *params);
729 softnic_pipeline_table_create(struct pmd_internals *p,
730 const char *pipeline_name,
731 struct softnic_table_params *params);
733 struct softnic_table_rule_match_acl {
760 struct softnic_table_rule_match_array {
764 struct softnic_table_rule_match_hash {
765 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
768 struct softnic_table_rule_match_lpm {
780 struct softnic_table_rule_match {
781 enum softnic_table_type match_type;
784 struct softnic_table_rule_match_acl acl;
785 struct softnic_table_rule_match_array array;
786 struct softnic_table_rule_match_hash hash;
787 struct softnic_table_rule_match_lpm lpm;
791 struct softnic_table_rule_action {
792 uint64_t action_mask;
793 struct rte_table_action_fwd_params fwd;
794 struct rte_table_action_lb_params lb;
795 struct rte_table_action_mtr_params mtr;
796 struct rte_table_action_tm_params tm;
797 struct rte_table_action_encap_params encap;
798 struct rte_table_action_nat_params nat;
799 struct rte_table_action_ttl_params ttl;
800 struct rte_table_action_stats_params stats;
801 struct rte_table_action_time_params time;
805 TAILQ_ENTRY(rte_flow) node;
806 struct softnic_table_rule_match match;
807 struct softnic_table_rule_action action;
809 struct pipeline *pipeline;
814 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
815 const char *pipeline_name,
817 struct rte_pipeline_port_in_stats *stats,
821 softnic_pipeline_port_in_enable(struct pmd_internals *p,
822 const char *pipeline_name,
826 softnic_pipeline_port_in_disable(struct pmd_internals *p,
827 const char *pipeline_name,
831 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
832 const char *pipeline_name,
834 struct rte_pipeline_port_out_stats *stats,
838 softnic_pipeline_table_stats_read(struct pmd_internals *p,
839 const char *pipeline_name,
841 struct rte_pipeline_table_stats *stats,
845 softnic_pipeline_table_rule_add(struct pmd_internals *p,
846 const char *pipeline_name,
848 struct softnic_table_rule_match *match,
849 struct softnic_table_rule_action *action,
853 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
854 const char *pipeline_name,
856 struct softnic_table_rule_match *match,
857 struct softnic_table_rule_action *action,
862 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
863 const char *pipeline_name,
865 struct softnic_table_rule_action *action,
869 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
870 const char *pipeline_name,
872 struct softnic_table_rule_match *match);
875 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
876 const char *pipeline_name,
880 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
881 const char *pipeline_name,
884 struct rte_table_action_stats_counters *stats,
888 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
889 const char *pipeline_name,
891 uint32_t meter_profile_id,
892 struct rte_table_action_meter_profile *profile);
895 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
896 const char *pipeline_name,
898 uint32_t meter_profile_id);
901 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
902 const char *pipeline_name,
906 struct rte_table_action_mtr_counters *stats,
910 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
911 const char *pipeline_name,
914 struct rte_table_action_dscp_table *dscp_table);
917 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
918 const char *pipeline_name,
921 struct rte_table_action_ttl_counters *stats,
928 softnic_thread_init(struct pmd_internals *p);
931 softnic_thread_free(struct pmd_internals *p);
934 softnic_thread_pipeline_enable(struct pmd_internals *p,
936 const char *pipeline_name);
939 softnic_thread_pipeline_disable(struct pmd_internals *p,
941 const char *pipeline_name);
947 softnic_cli_process(char *in,
953 softnic_cli_script_process(struct pmd_internals *softnic,
954 const char *file_name,
955 size_t msg_in_len_max,
956 size_t msg_out_len_max);
958 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */