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;
206 struct rte_sched_port *sched;
209 struct softnic_tmgr_port {
210 TAILQ_ENTRY(softnic_tmgr_port) node;
211 char name[NAME_SIZE];
212 struct rte_sched_port *s;
215 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
221 TAILQ_ENTRY(softnic_tap) node;
222 char name[NAME_SIZE];
226 TAILQ_HEAD(softnic_tap_list, softnic_tap);
231 struct softnic_port_in_action_profile_params {
232 uint64_t action_mask;
233 struct rte_port_in_action_fltr_config fltr;
234 struct rte_port_in_action_lb_config lb;
237 struct softnic_port_in_action_profile {
238 TAILQ_ENTRY(softnic_port_in_action_profile) node;
239 char name[NAME_SIZE];
240 struct softnic_port_in_action_profile_params params;
241 struct rte_port_in_action_profile *ap;
244 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
249 struct softnic_table_action_profile_params {
250 uint64_t action_mask;
251 struct rte_table_action_common_config common;
252 struct rte_table_action_lb_config lb;
253 struct rte_table_action_mtr_config mtr;
254 struct rte_table_action_tm_config tm;
255 struct rte_table_action_encap_config encap;
256 struct rte_table_action_nat_config nat;
257 struct rte_table_action_ttl_config ttl;
258 struct rte_table_action_stats_config stats;
261 struct softnic_table_action_profile {
262 TAILQ_ENTRY(softnic_table_action_profile) node;
263 char name[NAME_SIZE];
264 struct softnic_table_action_profile_params params;
265 struct rte_table_action_profile *ap;
268 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
273 struct pipeline_params {
274 uint32_t timer_period_ms;
275 uint32_t offset_port_id;
278 enum softnic_port_in_type {
286 struct softnic_port_in_params {
288 enum softnic_port_in_type type;
289 const char *dev_name;
296 const char *mempool_name;
301 const char *mempool_name;
302 const char *file_name;
303 uint32_t n_bytes_per_pkt;
309 const char *action_profile_name;
312 enum softnic_port_out_type {
320 struct softnic_port_out_params {
321 enum softnic_port_out_type type;
322 const char *dev_name;
329 const char *file_name;
338 enum softnic_table_type {
346 struct softnic_table_acl_params {
348 uint32_t ip_header_offset;
352 struct softnic_table_array_params {
357 struct softnic_table_hash_params {
363 int extendable_bucket;
366 struct softnic_table_lpm_params {
372 struct softnic_table_params {
374 enum softnic_table_type match_type;
376 struct softnic_table_acl_params acl;
377 struct softnic_table_array_params array;
378 struct softnic_table_hash_params hash;
379 struct softnic_table_lpm_params lpm;
383 const char *action_profile_name;
386 struct softnic_port_in {
387 struct softnic_port_in_params params;
388 struct softnic_port_in_action_profile *ap;
389 struct rte_port_in_action *a;
392 struct softnic_table {
393 struct softnic_table_params params;
394 struct softnic_table_action_profile *ap;
395 struct rte_table_action *a;
399 TAILQ_ENTRY(pipeline) node;
400 char name[NAME_SIZE];
402 struct rte_pipeline *p;
403 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
404 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
406 uint32_t n_ports_out;
409 struct rte_ring *msgq_req;
410 struct rte_ring *msgq_rsp;
411 uint32_t timer_period_ms;
418 TAILQ_HEAD(pipeline_list, pipeline);
423 #ifndef THREAD_PIPELINES_MAX
424 #define THREAD_PIPELINES_MAX 256
427 #ifndef THREAD_MSGQ_SIZE
428 #define THREAD_MSGQ_SIZE 64
431 #ifndef THREAD_TIMER_PERIOD_MS
432 #define THREAD_TIMER_PERIOD_MS 100
436 * Master thead: data plane thread context
438 struct softnic_thread {
439 struct rte_ring *msgq_req;
440 struct rte_ring *msgq_rsp;
446 * Data plane threads: context
448 #ifndef TABLE_RULE_ACTION_SIZE_MAX
449 #define TABLE_RULE_ACTION_SIZE_MAX 2048
452 struct softnic_table_data {
453 struct rte_table_action *a;
456 struct pipeline_data {
457 struct rte_pipeline *p;
458 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
461 struct rte_ring *msgq_req;
462 struct rte_ring *msgq_rsp;
463 uint64_t timer_period; /* Measured in CPU cycles. */
466 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
469 struct softnic_thread_data {
470 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
471 uint32_t n_pipelines;
473 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
474 struct rte_ring *msgq_req;
475 struct rte_ring *msgq_rsp;
476 uint64_t timer_period; /* Measured in CPU cycles. */
478 uint64_t time_next_min;
480 } __rte_cache_aligned;
485 struct pmd_internals {
487 struct pmd_params params;
490 struct tm_internals tm; /**< Traffic Management */
493 struct softnic_conn *conn;
494 struct softnic_mempool_list mempool_list;
495 struct softnic_swq_list swq_list;
496 struct softnic_link_list link_list;
497 struct softnic_tmgr_port_list tmgr_port_list;
498 struct softnic_tap_list tap_list;
499 struct softnic_port_in_action_profile_list port_in_action_profile_list;
500 struct softnic_table_action_profile_list table_action_profile_list;
501 struct pipeline_list pipeline_list;
502 struct softnic_thread thread[RTE_MAX_LCORE];
503 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
510 softnic_mempool_init(struct pmd_internals *p);
513 softnic_mempool_free(struct pmd_internals *p);
515 struct softnic_mempool *
516 softnic_mempool_find(struct pmd_internals *p,
519 struct softnic_mempool *
520 softnic_mempool_create(struct pmd_internals *p,
522 struct softnic_mempool_params *params);
528 softnic_swq_init(struct pmd_internals *p);
531 softnic_swq_free(struct pmd_internals *p);
534 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
537 softnic_swq_find(struct pmd_internals *p,
541 softnic_swq_create(struct pmd_internals *p,
543 struct softnic_swq_params *params);
549 softnic_link_init(struct pmd_internals *p);
552 softnic_link_free(struct pmd_internals *p);
554 struct softnic_link *
555 softnic_link_find(struct pmd_internals *p,
558 struct softnic_link *
559 softnic_link_create(struct pmd_internals *p,
561 struct softnic_link_params *params);
567 softnic_tmgr_init(struct pmd_internals *p);
570 softnic_tmgr_free(struct pmd_internals *p);
572 struct softnic_tmgr_port *
573 softnic_tmgr_port_find(struct pmd_internals *p,
576 struct softnic_tmgr_port *
577 softnic_tmgr_port_create(struct pmd_internals *p,
579 struct rte_sched_port *sched);
582 tm_init(struct pmd_internals *p);
585 tm_free(struct pmd_internals *p);
588 tm_start(struct pmd_internals *p);
591 tm_stop(struct pmd_internals *p);
594 tm_used(struct rte_eth_dev *dev)
596 struct pmd_internals *p = dev->data->dev_private;
598 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
601 extern const struct rte_tm_ops pmd_tm_ops;
607 softnic_tap_init(struct pmd_internals *p);
610 softnic_tap_free(struct pmd_internals *p);
613 softnic_tap_find(struct pmd_internals *p,
617 softnic_tap_create(struct pmd_internals *p,
624 softnic_port_in_action_profile_init(struct pmd_internals *p);
627 softnic_port_in_action_profile_free(struct pmd_internals *p);
629 struct softnic_port_in_action_profile *
630 softnic_port_in_action_profile_find(struct pmd_internals *p,
633 struct softnic_port_in_action_profile *
634 softnic_port_in_action_profile_create(struct pmd_internals *p,
636 struct softnic_port_in_action_profile_params *params);
642 softnic_table_action_profile_init(struct pmd_internals *p);
645 softnic_table_action_profile_free(struct pmd_internals *p);
647 struct softnic_table_action_profile *
648 softnic_table_action_profile_find(struct pmd_internals *p,
651 struct softnic_table_action_profile *
652 softnic_table_action_profile_create(struct pmd_internals *p,
654 struct softnic_table_action_profile_params *params);
660 softnic_pipeline_init(struct pmd_internals *p);
663 softnic_pipeline_free(struct pmd_internals *p);
666 softnic_pipeline_disable_all(struct pmd_internals *p);
669 softnic_pipeline_find(struct pmd_internals *p, const char *name);
672 softnic_pipeline_create(struct pmd_internals *p,
674 struct pipeline_params *params);
677 softnic_pipeline_port_in_create(struct pmd_internals *p,
678 const char *pipeline_name,
679 struct softnic_port_in_params *params,
683 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
684 const char *pipeline_name,
689 softnic_pipeline_port_out_create(struct pmd_internals *p,
690 const char *pipeline_name,
691 struct softnic_port_out_params *params);
694 softnic_pipeline_table_create(struct pmd_internals *p,
695 const char *pipeline_name,
696 struct softnic_table_params *params);
698 struct softnic_table_rule_match_acl {
725 struct softnic_table_rule_match_array {
729 #ifndef TABLE_RULE_MATCH_SIZE_MAX
730 #define TABLE_RULE_MATCH_SIZE_MAX 256
733 struct softnic_table_rule_match_hash {
734 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
737 struct softnic_table_rule_match_lpm {
749 struct softnic_table_rule_match {
750 enum softnic_table_type match_type;
753 struct softnic_table_rule_match_acl acl;
754 struct softnic_table_rule_match_array array;
755 struct softnic_table_rule_match_hash hash;
756 struct softnic_table_rule_match_lpm lpm;
760 struct softnic_table_rule_action {
761 uint64_t action_mask;
762 struct rte_table_action_fwd_params fwd;
763 struct rte_table_action_lb_params lb;
764 struct rte_table_action_mtr_params mtr;
765 struct rte_table_action_tm_params tm;
766 struct rte_table_action_encap_params encap;
767 struct rte_table_action_nat_params nat;
768 struct rte_table_action_ttl_params ttl;
769 struct rte_table_action_stats_params stats;
770 struct rte_table_action_time_params time;
774 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
775 const char *pipeline_name,
777 struct rte_pipeline_port_in_stats *stats,
781 softnic_pipeline_port_in_enable(struct pmd_internals *p,
782 const char *pipeline_name,
786 softnic_pipeline_port_in_disable(struct pmd_internals *p,
787 const char *pipeline_name,
791 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
792 const char *pipeline_name,
794 struct rte_pipeline_port_out_stats *stats,
798 softnic_pipeline_table_stats_read(struct pmd_internals *p,
799 const char *pipeline_name,
801 struct rte_pipeline_table_stats *stats,
805 softnic_pipeline_table_rule_add(struct pmd_internals *p,
806 const char *pipeline_name,
808 struct softnic_table_rule_match *match,
809 struct softnic_table_rule_action *action,
813 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
814 const char *pipeline_name,
816 struct softnic_table_rule_match *match,
817 struct softnic_table_rule_action *action,
822 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
823 const char *pipeline_name,
825 struct softnic_table_rule_action *action,
829 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
830 const char *pipeline_name,
832 struct softnic_table_rule_match *match);
835 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
836 const char *pipeline_name,
840 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
841 const char *pipeline_name,
844 struct rte_table_action_stats_counters *stats,
848 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
849 const char *pipeline_name,
851 uint32_t meter_profile_id,
852 struct rte_table_action_meter_profile *profile);
855 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
856 const char *pipeline_name,
858 uint32_t meter_profile_id);
861 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
862 const char *pipeline_name,
866 struct rte_table_action_mtr_counters *stats,
870 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
871 const char *pipeline_name,
874 struct rte_table_action_dscp_table *dscp_table);
877 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
878 const char *pipeline_name,
881 struct rte_table_action_ttl_counters *stats,
888 softnic_thread_init(struct pmd_internals *p);
891 softnic_thread_free(struct pmd_internals *p);
894 softnic_thread_pipeline_enable(struct pmd_internals *p,
896 const char *pipeline_name);
899 softnic_thread_pipeline_disable(struct pmd_internals *p,
901 const char *pipeline_name);
907 softnic_cli_process(char *in,
913 softnic_cli_script_process(struct pmd_internals *softnic,
914 const char *file_name,
915 size_t msg_in_len_max,
916 size_t msg_out_len_max);
918 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */