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);
57 struct softnic_mempool_params {
63 struct softnic_mempool {
64 TAILQ_ENTRY(softnic_mempool) node;
66 struct rte_mempool *m;
70 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
75 struct softnic_swq_params {
80 TAILQ_ENTRY(softnic_swq) node;
85 TAILQ_HEAD(softnic_swq_list, softnic_swq);
90 struct softnic_link_params {
92 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
96 TAILQ_ENTRY(softnic_link) node;
103 TAILQ_HEAD(softnic_link_list, softnic_link);
109 #ifndef TM_MAX_SUBPORTS
110 #define TM_MAX_SUBPORTS 8
113 #ifndef TM_MAX_PIPES_PER_SUBPORT
114 #define TM_MAX_PIPES_PER_SUBPORT 4096
118 struct rte_sched_port_params port_params;
120 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
122 struct rte_sched_pipe_params
123 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
124 uint32_t n_pipe_profiles;
125 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
130 TM_NODE_LEVEL_PORT = 0,
131 TM_NODE_LEVEL_SUBPORT,
138 /* TM Shaper Profile */
139 struct tm_shaper_profile {
140 TAILQ_ENTRY(tm_shaper_profile) node;
141 uint32_t shaper_profile_id;
143 struct rte_tm_shaper_params params;
146 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
148 /* TM Shared Shaper */
149 struct tm_shared_shaper {
150 TAILQ_ENTRY(tm_shared_shaper) node;
151 uint32_t shared_shaper_id;
153 uint32_t shaper_profile_id;
156 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
158 /* TM WRED Profile */
159 struct tm_wred_profile {
160 TAILQ_ENTRY(tm_wred_profile) node;
161 uint32_t wred_profile_id;
163 struct rte_tm_wred_params params;
166 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
170 TAILQ_ENTRY(tm_node) node;
172 uint32_t parent_node_id;
176 struct tm_node *parent_node;
177 struct tm_shaper_profile *shaper_profile;
178 struct tm_wred_profile *wred_profile;
179 struct rte_tm_node_params params;
180 struct rte_tm_node_stats stats;
184 TAILQ_HEAD(tm_node_list, tm_node);
186 /* TM Hierarchy Specification */
187 struct tm_hierarchy {
188 struct tm_shaper_profile_list shaper_profiles;
189 struct tm_shared_shaper_list shared_shapers;
190 struct tm_wred_profile_list wred_profiles;
191 struct tm_node_list nodes;
193 uint32_t n_shaper_profiles;
194 uint32_t n_shared_shapers;
195 uint32_t n_wred_profiles;
198 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
201 struct tm_internals {
202 /** Hierarchy specification
204 * -Hierarchy is unfrozen at init and when port is stopped.
205 * -Hierarchy is frozen on successful hierarchy commit.
206 * -Run-time hierarchy changes are not allowed, therefore it makes
207 * sense to keep the hierarchy frozen after the port is started.
209 struct tm_hierarchy h;
210 int hierarchy_frozen;
213 struct tm_params params;
216 struct softnic_tmgr_port {
217 TAILQ_ENTRY(softnic_tmgr_port) node;
218 char name[NAME_SIZE];
219 struct rte_sched_port *s;
222 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
228 TAILQ_ENTRY(softnic_tap) node;
229 char name[NAME_SIZE];
233 TAILQ_HEAD(softnic_tap_list, softnic_tap);
238 struct softnic_port_in_action_profile_params {
239 uint64_t action_mask;
240 struct rte_port_in_action_fltr_config fltr;
241 struct rte_port_in_action_lb_config lb;
244 struct softnic_port_in_action_profile {
245 TAILQ_ENTRY(softnic_port_in_action_profile) node;
246 char name[NAME_SIZE];
247 struct softnic_port_in_action_profile_params params;
248 struct rte_port_in_action_profile *ap;
251 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
256 struct softnic_table_action_profile_params {
257 uint64_t action_mask;
258 struct rte_table_action_common_config common;
259 struct rte_table_action_lb_config lb;
260 struct rte_table_action_mtr_config mtr;
261 struct rte_table_action_tm_config tm;
262 struct rte_table_action_encap_config encap;
263 struct rte_table_action_nat_config nat;
264 struct rte_table_action_ttl_config ttl;
265 struct rte_table_action_stats_config stats;
268 struct softnic_table_action_profile {
269 TAILQ_ENTRY(softnic_table_action_profile) node;
270 char name[NAME_SIZE];
271 struct softnic_table_action_profile_params params;
272 struct rte_table_action_profile *ap;
275 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
280 struct pipeline_params {
281 uint32_t timer_period_ms;
282 uint32_t offset_port_id;
285 enum softnic_port_in_type {
293 struct softnic_port_in_params {
295 enum softnic_port_in_type type;
296 const char *dev_name;
303 const char *mempool_name;
308 const char *mempool_name;
309 const char *file_name;
310 uint32_t n_bytes_per_pkt;
316 const char *action_profile_name;
319 enum softnic_port_out_type {
327 struct softnic_port_out_params {
328 enum softnic_port_out_type type;
329 const char *dev_name;
336 const char *file_name;
345 enum softnic_table_type {
353 struct softnic_table_acl_params {
355 uint32_t ip_header_offset;
359 struct softnic_table_array_params {
364 struct softnic_table_hash_params {
370 int extendable_bucket;
373 struct softnic_table_lpm_params {
379 struct softnic_table_params {
381 enum softnic_table_type match_type;
383 struct softnic_table_acl_params acl;
384 struct softnic_table_array_params array;
385 struct softnic_table_hash_params hash;
386 struct softnic_table_lpm_params lpm;
390 const char *action_profile_name;
393 struct softnic_port_in {
394 struct softnic_port_in_params params;
395 struct softnic_port_in_action_profile *ap;
396 struct rte_port_in_action *a;
399 struct softnic_table {
400 struct softnic_table_params params;
401 struct softnic_table_action_profile *ap;
402 struct rte_table_action *a;
406 TAILQ_ENTRY(pipeline) node;
407 char name[NAME_SIZE];
409 struct rte_pipeline *p;
410 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
411 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
413 uint32_t n_ports_out;
416 struct rte_ring *msgq_req;
417 struct rte_ring *msgq_rsp;
418 uint32_t timer_period_ms;
425 TAILQ_HEAD(pipeline_list, pipeline);
430 #ifndef THREAD_PIPELINES_MAX
431 #define THREAD_PIPELINES_MAX 256
434 #ifndef THREAD_MSGQ_SIZE
435 #define THREAD_MSGQ_SIZE 64
438 #ifndef THREAD_TIMER_PERIOD_MS
439 #define THREAD_TIMER_PERIOD_MS 100
443 * Master thead: data plane thread context
445 struct softnic_thread {
446 struct rte_ring *msgq_req;
447 struct rte_ring *msgq_rsp;
453 * Data plane threads: context
455 #ifndef TABLE_RULE_ACTION_SIZE_MAX
456 #define TABLE_RULE_ACTION_SIZE_MAX 2048
459 struct softnic_table_data {
460 struct rte_table_action *a;
463 struct pipeline_data {
464 struct rte_pipeline *p;
465 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
468 struct rte_ring *msgq_req;
469 struct rte_ring *msgq_rsp;
470 uint64_t timer_period; /* Measured in CPU cycles. */
473 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
476 struct softnic_thread_data {
477 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
478 uint32_t n_pipelines;
480 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
481 struct rte_ring *msgq_req;
482 struct rte_ring *msgq_rsp;
483 uint64_t timer_period; /* Measured in CPU cycles. */
485 uint64_t time_next_min;
487 } __rte_cache_aligned;
492 struct pmd_internals {
494 struct pmd_params params;
497 struct tm_internals tm; /**< Traffic Management */
500 struct softnic_conn *conn;
501 struct softnic_mempool_list mempool_list;
502 struct softnic_swq_list swq_list;
503 struct softnic_link_list link_list;
504 struct softnic_tmgr_port_list tmgr_port_list;
505 struct softnic_tap_list tap_list;
506 struct softnic_port_in_action_profile_list port_in_action_profile_list;
507 struct softnic_table_action_profile_list table_action_profile_list;
508 struct pipeline_list pipeline_list;
509 struct softnic_thread thread[RTE_MAX_LCORE];
510 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
517 softnic_mempool_init(struct pmd_internals *p);
520 softnic_mempool_free(struct pmd_internals *p);
522 struct softnic_mempool *
523 softnic_mempool_find(struct pmd_internals *p,
526 struct softnic_mempool *
527 softnic_mempool_create(struct pmd_internals *p,
529 struct softnic_mempool_params *params);
535 softnic_swq_init(struct pmd_internals *p);
538 softnic_swq_free(struct pmd_internals *p);
541 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
544 softnic_swq_find(struct pmd_internals *p,
548 softnic_swq_create(struct pmd_internals *p,
550 struct softnic_swq_params *params);
556 softnic_link_init(struct pmd_internals *p);
559 softnic_link_free(struct pmd_internals *p);
561 struct softnic_link *
562 softnic_link_find(struct pmd_internals *p,
565 struct softnic_link *
566 softnic_link_create(struct pmd_internals *p,
568 struct softnic_link_params *params);
574 softnic_tmgr_init(struct pmd_internals *p);
577 softnic_tmgr_free(struct pmd_internals *p);
579 struct softnic_tmgr_port *
580 softnic_tmgr_port_find(struct pmd_internals *p,
583 struct softnic_tmgr_port *
584 softnic_tmgr_port_create(struct pmd_internals *p,
588 tm_hierarchy_init(struct pmd_internals *p);
591 tm_hierarchy_free(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 TAILQ_ENTRY(rte_flow) node;
775 struct softnic_table_rule_match match;
776 struct softnic_table_rule_action action;
778 struct pipeline *pipeline;
783 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
784 const char *pipeline_name,
786 struct rte_pipeline_port_in_stats *stats,
790 softnic_pipeline_port_in_enable(struct pmd_internals *p,
791 const char *pipeline_name,
795 softnic_pipeline_port_in_disable(struct pmd_internals *p,
796 const char *pipeline_name,
800 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
801 const char *pipeline_name,
803 struct rte_pipeline_port_out_stats *stats,
807 softnic_pipeline_table_stats_read(struct pmd_internals *p,
808 const char *pipeline_name,
810 struct rte_pipeline_table_stats *stats,
814 softnic_pipeline_table_rule_add(struct pmd_internals *p,
815 const char *pipeline_name,
817 struct softnic_table_rule_match *match,
818 struct softnic_table_rule_action *action,
822 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
823 const char *pipeline_name,
825 struct softnic_table_rule_match *match,
826 struct softnic_table_rule_action *action,
831 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
832 const char *pipeline_name,
834 struct softnic_table_rule_action *action,
838 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
839 const char *pipeline_name,
841 struct softnic_table_rule_match *match);
844 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
845 const char *pipeline_name,
849 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
850 const char *pipeline_name,
853 struct rte_table_action_stats_counters *stats,
857 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
858 const char *pipeline_name,
860 uint32_t meter_profile_id,
861 struct rte_table_action_meter_profile *profile);
864 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
865 const char *pipeline_name,
867 uint32_t meter_profile_id);
870 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
871 const char *pipeline_name,
875 struct rte_table_action_mtr_counters *stats,
879 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
880 const char *pipeline_name,
883 struct rte_table_action_dscp_table *dscp_table);
886 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
887 const char *pipeline_name,
890 struct rte_table_action_ttl_counters *stats,
897 softnic_thread_init(struct pmd_internals *p);
900 softnic_thread_free(struct pmd_internals *p);
903 softnic_thread_pipeline_enable(struct pmd_internals *p,
905 const char *pipeline_name);
908 softnic_thread_pipeline_disable(struct pmd_internals *p,
910 const char *pipeline_name);
916 softnic_cli_process(char *in,
922 softnic_cli_script_process(struct pmd_internals *softnic,
923 const char *file_name,
924 size_t msg_in_len_max,
925 size_t msg_out_len_max);
927 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */