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,
576 softnic_mempool_init(struct pmd_internals *p);
579 softnic_mempool_free(struct pmd_internals *p);
581 struct softnic_mempool *
582 softnic_mempool_find(struct pmd_internals *p,
585 struct softnic_mempool *
586 softnic_mempool_create(struct pmd_internals *p,
588 struct softnic_mempool_params *params);
594 softnic_swq_init(struct pmd_internals *p);
597 softnic_swq_free(struct pmd_internals *p);
600 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
603 softnic_swq_find(struct pmd_internals *p,
607 softnic_swq_create(struct pmd_internals *p,
609 struct softnic_swq_params *params);
615 softnic_link_init(struct pmd_internals *p);
618 softnic_link_free(struct pmd_internals *p);
620 struct softnic_link *
621 softnic_link_find(struct pmd_internals *p,
624 struct softnic_link *
625 softnic_link_create(struct pmd_internals *p,
627 struct softnic_link_params *params);
633 softnic_tmgr_init(struct pmd_internals *p);
636 softnic_tmgr_free(struct pmd_internals *p);
638 struct softnic_tmgr_port *
639 softnic_tmgr_port_find(struct pmd_internals *p,
642 struct softnic_tmgr_port *
643 softnic_tmgr_port_create(struct pmd_internals *p,
647 tm_hierarchy_init(struct pmd_internals *p);
650 tm_hierarchy_free(struct pmd_internals *p);
653 tm_used(struct rte_eth_dev *dev)
655 struct pmd_internals *p = dev->data->dev_private;
657 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
660 extern const struct rte_tm_ops pmd_tm_ops;
666 softnic_tap_init(struct pmd_internals *p);
669 softnic_tap_free(struct pmd_internals *p);
672 softnic_tap_find(struct pmd_internals *p,
676 softnic_tap_create(struct pmd_internals *p,
683 softnic_port_in_action_profile_init(struct pmd_internals *p);
686 softnic_port_in_action_profile_free(struct pmd_internals *p);
688 struct softnic_port_in_action_profile *
689 softnic_port_in_action_profile_find(struct pmd_internals *p,
692 struct softnic_port_in_action_profile *
693 softnic_port_in_action_profile_create(struct pmd_internals *p,
695 struct softnic_port_in_action_profile_params *params);
701 softnic_table_action_profile_init(struct pmd_internals *p);
704 softnic_table_action_profile_free(struct pmd_internals *p);
706 struct softnic_table_action_profile *
707 softnic_table_action_profile_find(struct pmd_internals *p,
710 struct softnic_table_action_profile *
711 softnic_table_action_profile_create(struct pmd_internals *p,
713 struct softnic_table_action_profile_params *params);
719 softnic_pipeline_init(struct pmd_internals *p);
722 softnic_pipeline_free(struct pmd_internals *p);
725 softnic_pipeline_disable_all(struct pmd_internals *p);
728 softnic_pipeline_find(struct pmd_internals *p, const char *name);
731 softnic_pipeline_create(struct pmd_internals *p,
733 struct pipeline_params *params);
736 softnic_pipeline_port_in_create(struct pmd_internals *p,
737 const char *pipeline_name,
738 struct softnic_port_in_params *params,
742 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
743 const char *pipeline_name,
748 softnic_pipeline_port_out_create(struct pmd_internals *p,
749 const char *pipeline_name,
750 struct softnic_port_out_params *params);
753 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
754 const char *pipeline_name,
759 softnic_pipeline_table_create(struct pmd_internals *p,
760 const char *pipeline_name,
761 struct softnic_table_params *params);
763 struct softnic_table_rule_match_acl {
790 struct softnic_table_rule_match_array {
794 struct softnic_table_rule_match_hash {
795 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
798 struct softnic_table_rule_match_lpm {
810 struct softnic_table_rule_match {
811 enum softnic_table_type match_type;
814 struct softnic_table_rule_match_acl acl;
815 struct softnic_table_rule_match_array array;
816 struct softnic_table_rule_match_hash hash;
817 struct softnic_table_rule_match_lpm lpm;
821 struct softnic_table_rule_action {
822 uint64_t action_mask;
823 struct rte_table_action_fwd_params fwd;
824 struct rte_table_action_lb_params lb;
825 struct rte_table_action_mtr_params mtr;
826 struct rte_table_action_tm_params tm;
827 struct rte_table_action_encap_params encap;
828 struct rte_table_action_nat_params nat;
829 struct rte_table_action_ttl_params ttl;
830 struct rte_table_action_stats_params stats;
831 struct rte_table_action_time_params time;
835 TAILQ_ENTRY(rte_flow) node;
836 struct softnic_table_rule_match match;
837 struct softnic_table_rule_action action;
839 struct pipeline *pipeline;
844 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
845 const char *pipeline_name,
847 struct rte_pipeline_port_in_stats *stats,
851 softnic_pipeline_port_in_enable(struct pmd_internals *p,
852 const char *pipeline_name,
856 softnic_pipeline_port_in_disable(struct pmd_internals *p,
857 const char *pipeline_name,
861 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
862 const char *pipeline_name,
864 struct rte_pipeline_port_out_stats *stats,
868 softnic_pipeline_table_stats_read(struct pmd_internals *p,
869 const char *pipeline_name,
871 struct rte_pipeline_table_stats *stats,
875 softnic_pipeline_table_rule_add(struct pmd_internals *p,
876 const char *pipeline_name,
878 struct softnic_table_rule_match *match,
879 struct softnic_table_rule_action *action,
883 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
884 const char *pipeline_name,
886 struct softnic_table_rule_match *match,
887 struct softnic_table_rule_action *action,
892 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
893 const char *pipeline_name,
895 struct softnic_table_rule_action *action,
899 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
900 const char *pipeline_name,
902 struct softnic_table_rule_match *match);
905 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
906 const char *pipeline_name,
910 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
911 const char *pipeline_name,
914 struct rte_table_action_stats_counters *stats,
918 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
919 const char *pipeline_name,
921 uint32_t meter_profile_id,
922 struct rte_table_action_meter_profile *profile);
925 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
926 const char *pipeline_name,
928 uint32_t meter_profile_id);
931 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
932 const char *pipeline_name,
936 struct rte_table_action_mtr_counters *stats,
940 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
941 const char *pipeline_name,
944 struct rte_table_action_dscp_table *dscp_table);
947 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
948 const char *pipeline_name,
951 struct rte_table_action_ttl_counters *stats,
958 softnic_thread_init(struct pmd_internals *p);
961 softnic_thread_free(struct pmd_internals *p);
964 softnic_thread_pipeline_enable(struct pmd_internals *p,
966 const char *pipeline_name);
969 softnic_thread_pipeline_disable(struct pmd_internals *p,
971 const char *pipeline_name);
977 softnic_cli_process(char *in,
983 softnic_cli_script_process(struct pmd_internals *softnic,
984 const char *file_name,
985 size_t msg_in_len_max,
986 size_t msg_out_len_max);
988 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */