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>
26 #include "rte_eth_softnic.h"
41 /** Traffic Management (TM) */
43 uint32_t n_queues; /**< Number of queues */
44 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
53 TAILQ_HEAD(flow_list, rte_flow);
55 struct flow_attr_map {
56 char pipeline_name[NAME_SIZE];
61 #ifndef SOFTNIC_FLOW_MAX_GROUPS
62 #define SOFTNIC_FLOW_MAX_GROUPS 64
65 struct flow_internals {
66 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
67 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
73 struct softnic_mempool_params {
79 struct softnic_mempool {
80 TAILQ_ENTRY(softnic_mempool) node;
82 struct rte_mempool *m;
86 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
91 struct softnic_swq_params {
96 TAILQ_ENTRY(softnic_swq) node;
101 TAILQ_HEAD(softnic_swq_list, softnic_swq);
106 struct softnic_link_params {
107 const char *dev_name;
108 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
111 struct softnic_link {
112 TAILQ_ENTRY(softnic_link) node;
113 char name[NAME_SIZE];
119 TAILQ_HEAD(softnic_link_list, softnic_link);
125 #ifndef TM_MAX_SUBPORTS
126 #define TM_MAX_SUBPORTS 8
129 #ifndef TM_MAX_PIPES_PER_SUBPORT
130 #define TM_MAX_PIPES_PER_SUBPORT 4096
134 struct rte_sched_port_params port_params;
136 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
138 struct rte_sched_pipe_params
139 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
140 uint32_t n_pipe_profiles;
141 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
146 TM_NODE_LEVEL_PORT = 0,
147 TM_NODE_LEVEL_SUBPORT,
154 /* TM Shaper Profile */
155 struct tm_shaper_profile {
156 TAILQ_ENTRY(tm_shaper_profile) node;
157 uint32_t shaper_profile_id;
159 struct rte_tm_shaper_params params;
162 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
164 /* TM Shared Shaper */
165 struct tm_shared_shaper {
166 TAILQ_ENTRY(tm_shared_shaper) node;
167 uint32_t shared_shaper_id;
169 uint32_t shaper_profile_id;
172 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
174 /* TM WRED Profile */
175 struct tm_wred_profile {
176 TAILQ_ENTRY(tm_wred_profile) node;
177 uint32_t wred_profile_id;
179 struct rte_tm_wred_params params;
182 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
186 TAILQ_ENTRY(tm_node) node;
188 uint32_t parent_node_id;
192 struct tm_node *parent_node;
193 struct tm_shaper_profile *shaper_profile;
194 struct tm_wred_profile *wred_profile;
195 struct rte_tm_node_params params;
196 struct rte_tm_node_stats stats;
200 TAILQ_HEAD(tm_node_list, tm_node);
202 /* TM Hierarchy Specification */
203 struct tm_hierarchy {
204 struct tm_shaper_profile_list shaper_profiles;
205 struct tm_shared_shaper_list shared_shapers;
206 struct tm_wred_profile_list wred_profiles;
207 struct tm_node_list nodes;
209 uint32_t n_shaper_profiles;
210 uint32_t n_shared_shapers;
211 uint32_t n_wred_profiles;
214 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
217 struct tm_internals {
218 /** Hierarchy specification
220 * -Hierarchy is unfrozen at init and when port is stopped.
221 * -Hierarchy is frozen on successful hierarchy commit.
222 * -Run-time hierarchy changes are not allowed, therefore it makes
223 * sense to keep the hierarchy frozen after the port is started.
225 struct tm_hierarchy h;
226 int hierarchy_frozen;
229 struct tm_params params;
232 struct softnic_tmgr_port {
233 TAILQ_ENTRY(softnic_tmgr_port) node;
234 char name[NAME_SIZE];
235 struct rte_sched_port *s;
238 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
244 TAILQ_ENTRY(softnic_tap) node;
245 char name[NAME_SIZE];
249 TAILQ_HEAD(softnic_tap_list, softnic_tap);
254 struct softnic_port_in_action_profile_params {
255 uint64_t action_mask;
256 struct rte_port_in_action_fltr_config fltr;
257 struct rte_port_in_action_lb_config lb;
260 struct softnic_port_in_action_profile {
261 TAILQ_ENTRY(softnic_port_in_action_profile) node;
262 char name[NAME_SIZE];
263 struct softnic_port_in_action_profile_params params;
264 struct rte_port_in_action_profile *ap;
267 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
272 struct softnic_table_action_profile_params {
273 uint64_t action_mask;
274 struct rte_table_action_common_config common;
275 struct rte_table_action_lb_config lb;
276 struct rte_table_action_mtr_config mtr;
277 struct rte_table_action_tm_config tm;
278 struct rte_table_action_encap_config encap;
279 struct rte_table_action_nat_config nat;
280 struct rte_table_action_ttl_config ttl;
281 struct rte_table_action_stats_config stats;
284 struct softnic_table_action_profile {
285 TAILQ_ENTRY(softnic_table_action_profile) node;
286 char name[NAME_SIZE];
287 struct softnic_table_action_profile_params params;
288 struct rte_table_action_profile *ap;
291 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
296 struct pipeline_params {
297 uint32_t timer_period_ms;
298 uint32_t offset_port_id;
301 enum softnic_port_in_type {
309 struct softnic_port_in_params {
311 enum softnic_port_in_type type;
312 char dev_name[NAME_SIZE];
319 const char *mempool_name;
324 const char *mempool_name;
325 const char *file_name;
326 uint32_t n_bytes_per_pkt;
332 char action_profile_name[NAME_SIZE];
335 enum softnic_port_out_type {
343 struct softnic_port_out_params {
344 enum softnic_port_out_type type;
345 char dev_name[NAME_SIZE];
352 const char *file_name;
361 enum softnic_table_type {
369 struct softnic_table_acl_params {
371 uint32_t ip_header_offset;
375 struct softnic_table_array_params {
380 #ifndef TABLE_RULE_MATCH_SIZE_MAX
381 #define TABLE_RULE_MATCH_SIZE_MAX 256
384 struct softnic_table_hash_params {
388 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
390 int extendable_bucket;
393 struct softnic_table_lpm_params {
399 struct softnic_table_params {
401 enum softnic_table_type match_type;
403 struct softnic_table_acl_params acl;
404 struct softnic_table_array_params array;
405 struct softnic_table_hash_params hash;
406 struct softnic_table_lpm_params lpm;
410 char action_profile_name[NAME_SIZE];
413 struct softnic_port_in {
414 struct softnic_port_in_params params;
415 struct softnic_port_in_action_profile *ap;
416 struct rte_port_in_action *a;
419 struct softnic_port_out {
420 struct softnic_port_out_params params;
423 struct softnic_table {
424 struct softnic_table_params params;
425 struct softnic_table_action_profile *ap;
426 struct rte_table_action *a;
427 struct flow_list flows;
431 TAILQ_ENTRY(pipeline) node;
432 char name[NAME_SIZE];
434 struct rte_pipeline *p;
435 struct pipeline_params params;
436 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
437 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
438 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
440 uint32_t n_ports_out;
443 struct rte_ring *msgq_req;
444 struct rte_ring *msgq_rsp;
445 uint32_t timer_period_ms;
452 TAILQ_HEAD(pipeline_list, pipeline);
457 #ifndef THREAD_PIPELINES_MAX
458 #define THREAD_PIPELINES_MAX 256
461 #ifndef THREAD_MSGQ_SIZE
462 #define THREAD_MSGQ_SIZE 64
465 #ifndef THREAD_TIMER_PERIOD_MS
466 #define THREAD_TIMER_PERIOD_MS 100
470 * Master thead: data plane thread context
472 struct softnic_thread {
473 struct rte_ring *msgq_req;
474 struct rte_ring *msgq_rsp;
480 * Data plane threads: context
482 #ifndef TABLE_RULE_ACTION_SIZE_MAX
483 #define TABLE_RULE_ACTION_SIZE_MAX 2048
486 struct softnic_table_data {
487 struct rte_table_action *a;
490 struct pipeline_data {
491 struct rte_pipeline *p;
492 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
495 struct rte_ring *msgq_req;
496 struct rte_ring *msgq_rsp;
497 uint64_t timer_period; /* Measured in CPU cycles. */
500 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
503 struct softnic_thread_data {
504 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
505 uint32_t n_pipelines;
507 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
508 struct rte_ring *msgq_req;
509 struct rte_ring *msgq_rsp;
510 uint64_t timer_period; /* Measured in CPU cycles. */
512 uint64_t time_next_min;
514 } __rte_cache_aligned;
519 struct pmd_internals {
521 struct pmd_params params;
524 struct tm_internals tm; /**< Traffic Management */
527 struct flow_internals flow;
528 struct softnic_conn *conn;
529 struct softnic_mempool_list mempool_list;
530 struct softnic_swq_list swq_list;
531 struct softnic_link_list link_list;
532 struct softnic_tmgr_port_list tmgr_port_list;
533 struct softnic_tap_list tap_list;
534 struct softnic_port_in_action_profile_list port_in_action_profile_list;
535 struct softnic_table_action_profile_list table_action_profile_list;
536 struct pipeline_list pipeline_list;
537 struct softnic_thread thread[RTE_MAX_LCORE];
538 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
541 static inline struct rte_eth_dev *
542 ETHDEV(struct pmd_internals *softnic)
550 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
554 return &rte_eth_devices[port_id];
561 flow_attr_map_set(struct pmd_internals *softnic,
564 const char *pipeline_name,
567 struct flow_attr_map *
568 flow_attr_map_get(struct pmd_internals *softnic,
572 extern const struct rte_flow_ops pmd_flow_ops;
578 softnic_mempool_init(struct pmd_internals *p);
581 softnic_mempool_free(struct pmd_internals *p);
583 struct softnic_mempool *
584 softnic_mempool_find(struct pmd_internals *p,
587 struct softnic_mempool *
588 softnic_mempool_create(struct pmd_internals *p,
590 struct softnic_mempool_params *params);
596 softnic_swq_init(struct pmd_internals *p);
599 softnic_swq_free(struct pmd_internals *p);
602 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
605 softnic_swq_find(struct pmd_internals *p,
609 softnic_swq_create(struct pmd_internals *p,
611 struct softnic_swq_params *params);
617 softnic_link_init(struct pmd_internals *p);
620 softnic_link_free(struct pmd_internals *p);
622 struct softnic_link *
623 softnic_link_find(struct pmd_internals *p,
626 struct softnic_link *
627 softnic_link_create(struct pmd_internals *p,
629 struct softnic_link_params *params);
635 softnic_tmgr_init(struct pmd_internals *p);
638 softnic_tmgr_free(struct pmd_internals *p);
640 struct softnic_tmgr_port *
641 softnic_tmgr_port_find(struct pmd_internals *p,
644 struct softnic_tmgr_port *
645 softnic_tmgr_port_create(struct pmd_internals *p,
649 tm_hierarchy_init(struct pmd_internals *p);
652 tm_hierarchy_free(struct pmd_internals *p);
655 tm_used(struct rte_eth_dev *dev)
657 struct pmd_internals *p = dev->data->dev_private;
659 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
662 extern const struct rte_tm_ops pmd_tm_ops;
668 softnic_tap_init(struct pmd_internals *p);
671 softnic_tap_free(struct pmd_internals *p);
674 softnic_tap_find(struct pmd_internals *p,
678 softnic_tap_create(struct pmd_internals *p,
685 softnic_port_in_action_profile_init(struct pmd_internals *p);
688 softnic_port_in_action_profile_free(struct pmd_internals *p);
690 struct softnic_port_in_action_profile *
691 softnic_port_in_action_profile_find(struct pmd_internals *p,
694 struct softnic_port_in_action_profile *
695 softnic_port_in_action_profile_create(struct pmd_internals *p,
697 struct softnic_port_in_action_profile_params *params);
703 softnic_table_action_profile_init(struct pmd_internals *p);
706 softnic_table_action_profile_free(struct pmd_internals *p);
708 struct softnic_table_action_profile *
709 softnic_table_action_profile_find(struct pmd_internals *p,
712 struct softnic_table_action_profile *
713 softnic_table_action_profile_create(struct pmd_internals *p,
715 struct softnic_table_action_profile_params *params);
721 softnic_pipeline_init(struct pmd_internals *p);
724 softnic_pipeline_free(struct pmd_internals *p);
727 softnic_pipeline_disable_all(struct pmd_internals *p);
730 softnic_pipeline_find(struct pmd_internals *p, const char *name);
733 softnic_pipeline_create(struct pmd_internals *p,
735 struct pipeline_params *params);
738 softnic_pipeline_port_in_create(struct pmd_internals *p,
739 const char *pipeline_name,
740 struct softnic_port_in_params *params,
744 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
745 const char *pipeline_name,
750 softnic_pipeline_port_out_create(struct pmd_internals *p,
751 const char *pipeline_name,
752 struct softnic_port_out_params *params);
755 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
756 const char *pipeline_name,
761 softnic_pipeline_table_create(struct pmd_internals *p,
762 const char *pipeline_name,
763 struct softnic_table_params *params);
765 struct softnic_table_rule_match_acl {
792 struct softnic_table_rule_match_array {
796 struct softnic_table_rule_match_hash {
797 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
800 struct softnic_table_rule_match_lpm {
812 struct softnic_table_rule_match {
813 enum softnic_table_type match_type;
816 struct softnic_table_rule_match_acl acl;
817 struct softnic_table_rule_match_array array;
818 struct softnic_table_rule_match_hash hash;
819 struct softnic_table_rule_match_lpm lpm;
823 struct softnic_table_rule_action {
824 uint64_t action_mask;
825 struct rte_table_action_fwd_params fwd;
826 struct rte_table_action_lb_params lb;
827 struct rte_table_action_mtr_params mtr;
828 struct rte_table_action_tm_params tm;
829 struct rte_table_action_encap_params encap;
830 struct rte_table_action_nat_params nat;
831 struct rte_table_action_ttl_params ttl;
832 struct rte_table_action_stats_params stats;
833 struct rte_table_action_time_params time;
837 TAILQ_ENTRY(rte_flow) node;
838 struct softnic_table_rule_match match;
839 struct softnic_table_rule_action action;
841 struct pipeline *pipeline;
846 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
847 const char *pipeline_name,
849 struct rte_pipeline_port_in_stats *stats,
853 softnic_pipeline_port_in_enable(struct pmd_internals *p,
854 const char *pipeline_name,
858 softnic_pipeline_port_in_disable(struct pmd_internals *p,
859 const char *pipeline_name,
863 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
864 const char *pipeline_name,
866 struct rte_pipeline_port_out_stats *stats,
870 softnic_pipeline_table_stats_read(struct pmd_internals *p,
871 const char *pipeline_name,
873 struct rte_pipeline_table_stats *stats,
877 softnic_pipeline_table_rule_add(struct pmd_internals *p,
878 const char *pipeline_name,
880 struct softnic_table_rule_match *match,
881 struct softnic_table_rule_action *action,
885 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
886 const char *pipeline_name,
888 struct softnic_table_rule_match *match,
889 struct softnic_table_rule_action *action,
894 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
895 const char *pipeline_name,
897 struct softnic_table_rule_action *action,
901 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
902 const char *pipeline_name,
904 struct softnic_table_rule_match *match);
907 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
908 const char *pipeline_name,
912 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
913 const char *pipeline_name,
916 struct rte_table_action_stats_counters *stats,
920 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
921 const char *pipeline_name,
923 uint32_t meter_profile_id,
924 struct rte_table_action_meter_profile *profile);
927 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
928 const char *pipeline_name,
930 uint32_t meter_profile_id);
933 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
934 const char *pipeline_name,
938 struct rte_table_action_mtr_counters *stats,
942 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
943 const char *pipeline_name,
946 struct rte_table_action_dscp_table *dscp_table);
949 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
950 const char *pipeline_name,
953 struct rte_table_action_ttl_counters *stats,
960 softnic_thread_init(struct pmd_internals *p);
963 softnic_thread_free(struct pmd_internals *p);
966 softnic_thread_pipeline_enable(struct pmd_internals *p,
968 const char *pipeline_name);
971 softnic_thread_pipeline_disable(struct pmd_internals *p,
973 const char *pipeline_name);
979 softnic_cli_process(char *in,
985 softnic_cli_script_process(struct pmd_internals *softnic,
986 const char *file_name,
987 size_t msg_in_len_max,
988 size_t msg_out_len_max);
990 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */