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>
24 #include "rte_eth_softnic.h"
39 /** Traffic Management (TM) */
41 uint32_t n_queues; /**< Number of queues */
42 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
49 struct softnic_mempool_params {
55 struct softnic_mempool {
56 TAILQ_ENTRY(softnic_mempool) node;
58 struct rte_mempool *m;
62 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
67 struct softnic_swq_params {
72 TAILQ_ENTRY(softnic_swq) node;
77 TAILQ_HEAD(softnic_swq_list, softnic_swq);
82 struct softnic_link_params {
84 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
88 TAILQ_ENTRY(softnic_link) node;
95 TAILQ_HEAD(softnic_link_list, softnic_link);
101 #ifndef TM_MAX_SUBPORTS
102 #define TM_MAX_SUBPORTS 8
105 #ifndef TM_MAX_PIPES_PER_SUBPORT
106 #define TM_MAX_PIPES_PER_SUBPORT 4096
110 struct rte_sched_port_params port_params;
112 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
114 struct rte_sched_pipe_params
115 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
116 uint32_t n_pipe_profiles;
117 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
122 TM_NODE_LEVEL_PORT = 0,
123 TM_NODE_LEVEL_SUBPORT,
130 /* TM Shaper Profile */
131 struct tm_shaper_profile {
132 TAILQ_ENTRY(tm_shaper_profile) node;
133 uint32_t shaper_profile_id;
135 struct rte_tm_shaper_params params;
138 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
140 /* TM Shared Shaper */
141 struct tm_shared_shaper {
142 TAILQ_ENTRY(tm_shared_shaper) node;
143 uint32_t shared_shaper_id;
145 uint32_t shaper_profile_id;
148 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
150 /* TM WRED Profile */
151 struct tm_wred_profile {
152 TAILQ_ENTRY(tm_wred_profile) node;
153 uint32_t wred_profile_id;
155 struct rte_tm_wred_params params;
158 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
162 TAILQ_ENTRY(tm_node) node;
164 uint32_t parent_node_id;
168 struct tm_node *parent_node;
169 struct tm_shaper_profile *shaper_profile;
170 struct tm_wred_profile *wred_profile;
171 struct rte_tm_node_params params;
172 struct rte_tm_node_stats stats;
176 TAILQ_HEAD(tm_node_list, tm_node);
178 /* TM Hierarchy Specification */
179 struct tm_hierarchy {
180 struct tm_shaper_profile_list shaper_profiles;
181 struct tm_shared_shaper_list shared_shapers;
182 struct tm_wred_profile_list wred_profiles;
183 struct tm_node_list nodes;
185 uint32_t n_shaper_profiles;
186 uint32_t n_shared_shapers;
187 uint32_t n_wred_profiles;
190 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
193 struct tm_internals {
194 /** Hierarchy specification
196 * -Hierarchy is unfrozen at init and when port is stopped.
197 * -Hierarchy is frozen on successful hierarchy commit.
198 * -Run-time hierarchy changes are not allowed, therefore it makes
199 * sense to keep the hierarchy frozen after the port is started.
201 struct tm_hierarchy h;
202 int hierarchy_frozen;
205 struct tm_params params;
208 struct softnic_tmgr_port {
209 TAILQ_ENTRY(softnic_tmgr_port) node;
210 char name[NAME_SIZE];
211 struct rte_sched_port *s;
214 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
220 TAILQ_ENTRY(softnic_tap) node;
221 char name[NAME_SIZE];
225 TAILQ_HEAD(softnic_tap_list, softnic_tap);
230 struct softnic_port_in_action_profile_params {
231 uint64_t action_mask;
232 struct rte_port_in_action_fltr_config fltr;
233 struct rte_port_in_action_lb_config lb;
236 struct softnic_port_in_action_profile {
237 TAILQ_ENTRY(softnic_port_in_action_profile) node;
238 char name[NAME_SIZE];
239 struct softnic_port_in_action_profile_params params;
240 struct rte_port_in_action_profile *ap;
243 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
248 struct softnic_table_action_profile_params {
249 uint64_t action_mask;
250 struct rte_table_action_common_config common;
251 struct rte_table_action_lb_config lb;
252 struct rte_table_action_mtr_config mtr;
253 struct rte_table_action_tm_config tm;
254 struct rte_table_action_encap_config encap;
255 struct rte_table_action_nat_config nat;
256 struct rte_table_action_ttl_config ttl;
257 struct rte_table_action_stats_config stats;
260 struct softnic_table_action_profile {
261 TAILQ_ENTRY(softnic_table_action_profile) node;
262 char name[NAME_SIZE];
263 struct softnic_table_action_profile_params params;
264 struct rte_table_action_profile *ap;
267 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
272 struct pipeline_params {
273 uint32_t timer_period_ms;
274 uint32_t offset_port_id;
277 enum softnic_port_in_type {
285 struct softnic_port_in_params {
287 enum softnic_port_in_type type;
288 const char *dev_name;
295 const char *mempool_name;
300 const char *mempool_name;
301 const char *file_name;
302 uint32_t n_bytes_per_pkt;
308 const char *action_profile_name;
311 enum softnic_port_out_type {
319 struct softnic_port_out_params {
320 enum softnic_port_out_type type;
321 const char *dev_name;
328 const char *file_name;
337 enum softnic_table_type {
345 struct softnic_table_acl_params {
347 uint32_t ip_header_offset;
351 struct softnic_table_array_params {
356 struct softnic_table_hash_params {
362 int extendable_bucket;
365 struct softnic_table_lpm_params {
371 struct softnic_table_params {
373 enum softnic_table_type match_type;
375 struct softnic_table_acl_params acl;
376 struct softnic_table_array_params array;
377 struct softnic_table_hash_params hash;
378 struct softnic_table_lpm_params lpm;
382 const char *action_profile_name;
385 struct softnic_port_in {
386 struct softnic_port_in_params params;
387 struct softnic_port_in_action_profile *ap;
388 struct rte_port_in_action *a;
391 struct softnic_table {
392 struct softnic_table_params params;
393 struct softnic_table_action_profile *ap;
394 struct rte_table_action *a;
398 TAILQ_ENTRY(pipeline) node;
399 char name[NAME_SIZE];
401 struct rte_pipeline *p;
402 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
403 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
405 uint32_t n_ports_out;
408 struct rte_ring *msgq_req;
409 struct rte_ring *msgq_rsp;
410 uint32_t timer_period_ms;
417 TAILQ_HEAD(pipeline_list, pipeline);
422 #ifndef THREAD_PIPELINES_MAX
423 #define THREAD_PIPELINES_MAX 256
426 #ifndef THREAD_MSGQ_SIZE
427 #define THREAD_MSGQ_SIZE 64
430 #ifndef THREAD_TIMER_PERIOD_MS
431 #define THREAD_TIMER_PERIOD_MS 100
435 * Master thead: data plane thread context
437 struct softnic_thread {
438 struct rte_ring *msgq_req;
439 struct rte_ring *msgq_rsp;
445 * Data plane threads: context
447 #ifndef TABLE_RULE_ACTION_SIZE_MAX
448 #define TABLE_RULE_ACTION_SIZE_MAX 2048
451 struct softnic_table_data {
452 struct rte_table_action *a;
455 struct pipeline_data {
456 struct rte_pipeline *p;
457 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
460 struct rte_ring *msgq_req;
461 struct rte_ring *msgq_rsp;
462 uint64_t timer_period; /* Measured in CPU cycles. */
465 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
468 struct softnic_thread_data {
469 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
470 uint32_t n_pipelines;
472 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
473 struct rte_ring *msgq_req;
474 struct rte_ring *msgq_rsp;
475 uint64_t timer_period; /* Measured in CPU cycles. */
477 uint64_t time_next_min;
479 } __rte_cache_aligned;
484 struct pmd_internals {
486 struct pmd_params params;
489 struct tm_internals tm; /**< Traffic Management */
492 struct softnic_conn *conn;
493 struct softnic_mempool_list mempool_list;
494 struct softnic_swq_list swq_list;
495 struct softnic_link_list link_list;
496 struct softnic_tmgr_port_list tmgr_port_list;
497 struct softnic_tap_list tap_list;
498 struct softnic_port_in_action_profile_list port_in_action_profile_list;
499 struct softnic_table_action_profile_list table_action_profile_list;
500 struct pipeline_list pipeline_list;
501 struct softnic_thread thread[RTE_MAX_LCORE];
502 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
509 softnic_mempool_init(struct pmd_internals *p);
512 softnic_mempool_free(struct pmd_internals *p);
514 struct softnic_mempool *
515 softnic_mempool_find(struct pmd_internals *p,
518 struct softnic_mempool *
519 softnic_mempool_create(struct pmd_internals *p,
521 struct softnic_mempool_params *params);
527 softnic_swq_init(struct pmd_internals *p);
530 softnic_swq_free(struct pmd_internals *p);
533 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
536 softnic_swq_find(struct pmd_internals *p,
540 softnic_swq_create(struct pmd_internals *p,
542 struct softnic_swq_params *params);
548 softnic_link_init(struct pmd_internals *p);
551 softnic_link_free(struct pmd_internals *p);
553 struct softnic_link *
554 softnic_link_find(struct pmd_internals *p,
557 struct softnic_link *
558 softnic_link_create(struct pmd_internals *p,
560 struct softnic_link_params *params);
566 softnic_tmgr_init(struct pmd_internals *p);
569 softnic_tmgr_free(struct pmd_internals *p);
571 struct softnic_tmgr_port *
572 softnic_tmgr_port_find(struct pmd_internals *p,
575 struct softnic_tmgr_port *
576 softnic_tmgr_port_create(struct pmd_internals *p,
580 tm_hierarchy_init(struct pmd_internals *p);
583 tm_hierarchy_free(struct pmd_internals *p);
586 tm_used(struct rte_eth_dev *dev)
588 struct pmd_internals *p = dev->data->dev_private;
590 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
593 extern const struct rte_tm_ops pmd_tm_ops;
599 softnic_tap_init(struct pmd_internals *p);
602 softnic_tap_free(struct pmd_internals *p);
605 softnic_tap_find(struct pmd_internals *p,
609 softnic_tap_create(struct pmd_internals *p,
616 softnic_port_in_action_profile_init(struct pmd_internals *p);
619 softnic_port_in_action_profile_free(struct pmd_internals *p);
621 struct softnic_port_in_action_profile *
622 softnic_port_in_action_profile_find(struct pmd_internals *p,
625 struct softnic_port_in_action_profile *
626 softnic_port_in_action_profile_create(struct pmd_internals *p,
628 struct softnic_port_in_action_profile_params *params);
634 softnic_table_action_profile_init(struct pmd_internals *p);
637 softnic_table_action_profile_free(struct pmd_internals *p);
639 struct softnic_table_action_profile *
640 softnic_table_action_profile_find(struct pmd_internals *p,
643 struct softnic_table_action_profile *
644 softnic_table_action_profile_create(struct pmd_internals *p,
646 struct softnic_table_action_profile_params *params);
652 softnic_pipeline_init(struct pmd_internals *p);
655 softnic_pipeline_free(struct pmd_internals *p);
658 softnic_pipeline_disable_all(struct pmd_internals *p);
661 softnic_pipeline_find(struct pmd_internals *p, const char *name);
664 softnic_pipeline_create(struct pmd_internals *p,
666 struct pipeline_params *params);
669 softnic_pipeline_port_in_create(struct pmd_internals *p,
670 const char *pipeline_name,
671 struct softnic_port_in_params *params,
675 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
676 const char *pipeline_name,
681 softnic_pipeline_port_out_create(struct pmd_internals *p,
682 const char *pipeline_name,
683 struct softnic_port_out_params *params);
686 softnic_pipeline_table_create(struct pmd_internals *p,
687 const char *pipeline_name,
688 struct softnic_table_params *params);
690 struct softnic_table_rule_match_acl {
717 struct softnic_table_rule_match_array {
721 #ifndef TABLE_RULE_MATCH_SIZE_MAX
722 #define TABLE_RULE_MATCH_SIZE_MAX 256
725 struct softnic_table_rule_match_hash {
726 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
729 struct softnic_table_rule_match_lpm {
741 struct softnic_table_rule_match {
742 enum softnic_table_type match_type;
745 struct softnic_table_rule_match_acl acl;
746 struct softnic_table_rule_match_array array;
747 struct softnic_table_rule_match_hash hash;
748 struct softnic_table_rule_match_lpm lpm;
752 struct softnic_table_rule_action {
753 uint64_t action_mask;
754 struct rte_table_action_fwd_params fwd;
755 struct rte_table_action_lb_params lb;
756 struct rte_table_action_mtr_params mtr;
757 struct rte_table_action_tm_params tm;
758 struct rte_table_action_encap_params encap;
759 struct rte_table_action_nat_params nat;
760 struct rte_table_action_ttl_params ttl;
761 struct rte_table_action_stats_params stats;
762 struct rte_table_action_time_params time;
766 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
767 const char *pipeline_name,
769 struct rte_pipeline_port_in_stats *stats,
773 softnic_pipeline_port_in_enable(struct pmd_internals *p,
774 const char *pipeline_name,
778 softnic_pipeline_port_in_disable(struct pmd_internals *p,
779 const char *pipeline_name,
783 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
784 const char *pipeline_name,
786 struct rte_pipeline_port_out_stats *stats,
790 softnic_pipeline_table_stats_read(struct pmd_internals *p,
791 const char *pipeline_name,
793 struct rte_pipeline_table_stats *stats,
797 softnic_pipeline_table_rule_add(struct pmd_internals *p,
798 const char *pipeline_name,
800 struct softnic_table_rule_match *match,
801 struct softnic_table_rule_action *action,
805 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
806 const char *pipeline_name,
808 struct softnic_table_rule_match *match,
809 struct softnic_table_rule_action *action,
814 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
815 const char *pipeline_name,
817 struct softnic_table_rule_action *action,
821 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
822 const char *pipeline_name,
824 struct softnic_table_rule_match *match);
827 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
828 const char *pipeline_name,
832 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
833 const char *pipeline_name,
836 struct rte_table_action_stats_counters *stats,
840 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
841 const char *pipeline_name,
843 uint32_t meter_profile_id,
844 struct rte_table_action_meter_profile *profile);
847 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
848 const char *pipeline_name,
850 uint32_t meter_profile_id);
853 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
854 const char *pipeline_name,
858 struct rte_table_action_mtr_counters *stats,
862 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
863 const char *pipeline_name,
866 struct rte_table_action_dscp_table *dscp_table);
869 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
870 const char *pipeline_name,
873 struct rte_table_action_ttl_counters *stats,
880 softnic_thread_init(struct pmd_internals *p);
883 softnic_thread_free(struct pmd_internals *p);
886 softnic_thread_pipeline_enable(struct pmd_internals *p,
888 const char *pipeline_name);
891 softnic_thread_pipeline_disable(struct pmd_internals *p,
893 const char *pipeline_name);
899 softnic_cli_process(char *in,
905 softnic_cli_script_process(struct pmd_internals *softnic,
906 const char *file_name,
907 size_t msg_in_len_max,
908 size_t msg_out_len_max);
910 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */