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>
25 #include <rte_mtr_driver.h>
27 #include "rte_eth_softnic.h"
42 /** Traffic Management (TM) */
44 uint32_t n_queues; /**< Number of queues */
45 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
54 TAILQ_HEAD(flow_list, rte_flow);
56 struct flow_attr_map {
57 char pipeline_name[NAME_SIZE];
62 #ifndef SOFTNIC_FLOW_MAX_GROUPS
63 #define SOFTNIC_FLOW_MAX_GROUPS 64
66 struct flow_internals {
67 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
68 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
75 /* MTR meter profile */
76 struct softnic_mtr_meter_profile {
77 TAILQ_ENTRY(softnic_mtr_meter_profile) node;
78 uint32_t meter_profile_id;
79 struct rte_mtr_meter_profile params;
83 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
85 /* MTR meter object */
87 TAILQ_ENTRY(softnic_mtr) node;
89 struct rte_mtr_params params;
90 struct rte_flow *flow;
93 TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
95 struct mtr_internals {
96 struct softnic_mtr_meter_profile_list meter_profiles;
97 struct softnic_mtr_list mtrs;
103 struct softnic_mempool_params {
104 uint32_t buffer_size;
109 struct softnic_mempool {
110 TAILQ_ENTRY(softnic_mempool) node;
111 char name[NAME_SIZE];
112 struct rte_mempool *m;
113 uint32_t buffer_size;
116 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
121 struct softnic_swq_params {
126 TAILQ_ENTRY(softnic_swq) node;
127 char name[NAME_SIZE];
131 TAILQ_HEAD(softnic_swq_list, softnic_swq);
136 struct softnic_link_params {
137 const char *dev_name;
138 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
141 struct softnic_link {
142 TAILQ_ENTRY(softnic_link) node;
143 char name[NAME_SIZE];
149 TAILQ_HEAD(softnic_link_list, softnic_link);
155 #ifndef TM_MAX_SUBPORTS
156 #define TM_MAX_SUBPORTS 8
159 #ifndef TM_MAX_PIPES_PER_SUBPORT
160 #define TM_MAX_PIPES_PER_SUBPORT 4096
164 struct rte_sched_port_params port_params;
166 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
168 struct rte_sched_pipe_params
169 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
170 uint32_t n_pipe_profiles;
171 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
176 TM_NODE_LEVEL_PORT = 0,
177 TM_NODE_LEVEL_SUBPORT,
184 /* TM Shaper Profile */
185 struct tm_shaper_profile {
186 TAILQ_ENTRY(tm_shaper_profile) node;
187 uint32_t shaper_profile_id;
189 struct rte_tm_shaper_params params;
192 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
194 /* TM Shared Shaper */
195 struct tm_shared_shaper {
196 TAILQ_ENTRY(tm_shared_shaper) node;
197 uint32_t shared_shaper_id;
199 uint32_t shaper_profile_id;
202 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
204 /* TM WRED Profile */
205 struct tm_wred_profile {
206 TAILQ_ENTRY(tm_wred_profile) node;
207 uint32_t wred_profile_id;
209 struct rte_tm_wred_params params;
212 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
216 TAILQ_ENTRY(tm_node) node;
218 uint32_t parent_node_id;
222 struct tm_node *parent_node;
223 struct tm_shaper_profile *shaper_profile;
224 struct tm_wred_profile *wred_profile;
225 struct rte_tm_node_params params;
226 struct rte_tm_node_stats stats;
230 TAILQ_HEAD(tm_node_list, tm_node);
232 /* TM Hierarchy Specification */
233 struct tm_hierarchy {
234 struct tm_shaper_profile_list shaper_profiles;
235 struct tm_shared_shaper_list shared_shapers;
236 struct tm_wred_profile_list wred_profiles;
237 struct tm_node_list nodes;
239 uint32_t n_shaper_profiles;
240 uint32_t n_shared_shapers;
241 uint32_t n_wred_profiles;
244 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
247 struct tm_internals {
248 /** Hierarchy specification
250 * -Hierarchy is unfrozen at init and when port is stopped.
251 * -Hierarchy is frozen on successful hierarchy commit.
252 * -Run-time hierarchy changes are not allowed, therefore it makes
253 * sense to keep the hierarchy frozen after the port is started.
255 struct tm_hierarchy h;
256 int hierarchy_frozen;
259 struct tm_params params;
262 struct softnic_tmgr_port {
263 TAILQ_ENTRY(softnic_tmgr_port) node;
264 char name[NAME_SIZE];
265 struct rte_sched_port *s;
268 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
274 TAILQ_ENTRY(softnic_tap) node;
275 char name[NAME_SIZE];
279 TAILQ_HEAD(softnic_tap_list, softnic_tap);
284 struct softnic_port_in_action_profile_params {
285 uint64_t action_mask;
286 struct rte_port_in_action_fltr_config fltr;
287 struct rte_port_in_action_lb_config lb;
290 struct softnic_port_in_action_profile {
291 TAILQ_ENTRY(softnic_port_in_action_profile) node;
292 char name[NAME_SIZE];
293 struct softnic_port_in_action_profile_params params;
294 struct rte_port_in_action_profile *ap;
297 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
302 struct softnic_table_action_profile_params {
303 uint64_t action_mask;
304 struct rte_table_action_common_config common;
305 struct rte_table_action_lb_config lb;
306 struct rte_table_action_mtr_config mtr;
307 struct rte_table_action_tm_config tm;
308 struct rte_table_action_encap_config encap;
309 struct rte_table_action_nat_config nat;
310 struct rte_table_action_ttl_config ttl;
311 struct rte_table_action_stats_config stats;
314 struct softnic_table_action_profile {
315 TAILQ_ENTRY(softnic_table_action_profile) node;
316 char name[NAME_SIZE];
317 struct softnic_table_action_profile_params params;
318 struct rte_table_action_profile *ap;
321 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
323 struct softnic_table_meter_profile {
324 TAILQ_ENTRY(softnic_table_meter_profile) node;
325 uint32_t meter_profile_id;
326 struct rte_table_action_meter_profile profile;
329 TAILQ_HEAD(softnic_table_meter_profile_list,
330 softnic_table_meter_profile);
335 struct pipeline_params {
336 uint32_t timer_period_ms;
337 uint32_t offset_port_id;
340 enum softnic_port_in_type {
348 struct softnic_port_in_params {
350 enum softnic_port_in_type type;
351 char dev_name[NAME_SIZE];
358 const char *mempool_name;
363 const char *mempool_name;
364 const char *file_name;
365 uint32_t n_bytes_per_pkt;
371 char action_profile_name[NAME_SIZE];
374 enum softnic_port_out_type {
382 struct softnic_port_out_params {
383 enum softnic_port_out_type type;
384 char dev_name[NAME_SIZE];
391 const char *file_name;
400 enum softnic_table_type {
408 struct softnic_table_acl_params {
410 uint32_t ip_header_offset;
414 struct softnic_table_array_params {
419 #ifndef TABLE_RULE_MATCH_SIZE_MAX
420 #define TABLE_RULE_MATCH_SIZE_MAX 256
423 struct softnic_table_hash_params {
427 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
429 int extendable_bucket;
432 struct softnic_table_lpm_params {
438 struct softnic_table_params {
440 enum softnic_table_type match_type;
442 struct softnic_table_acl_params acl;
443 struct softnic_table_array_params array;
444 struct softnic_table_hash_params hash;
445 struct softnic_table_lpm_params lpm;
449 char action_profile_name[NAME_SIZE];
452 struct softnic_port_in {
453 struct softnic_port_in_params params;
454 struct softnic_port_in_action_profile *ap;
455 struct rte_port_in_action *a;
458 struct softnic_port_out {
459 struct softnic_port_out_params params;
462 struct softnic_table {
463 struct softnic_table_params params;
464 struct softnic_table_action_profile *ap;
465 struct rte_table_action *a;
466 struct flow_list flows;
467 struct softnic_table_meter_profile_list meter_profiles;
471 TAILQ_ENTRY(pipeline) node;
472 char name[NAME_SIZE];
474 struct rte_pipeline *p;
475 struct pipeline_params params;
476 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
477 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
478 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
480 uint32_t n_ports_out;
483 struct rte_ring *msgq_req;
484 struct rte_ring *msgq_rsp;
485 uint32_t timer_period_ms;
492 TAILQ_HEAD(pipeline_list, pipeline);
497 #ifndef THREAD_PIPELINES_MAX
498 #define THREAD_PIPELINES_MAX 256
501 #ifndef THREAD_MSGQ_SIZE
502 #define THREAD_MSGQ_SIZE 64
505 #ifndef THREAD_TIMER_PERIOD_MS
506 #define THREAD_TIMER_PERIOD_MS 100
510 * Master thead: data plane thread context
512 struct softnic_thread {
513 struct rte_ring *msgq_req;
514 struct rte_ring *msgq_rsp;
520 * Data plane threads: context
522 #ifndef TABLE_RULE_ACTION_SIZE_MAX
523 #define TABLE_RULE_ACTION_SIZE_MAX 2048
526 struct softnic_table_data {
527 struct rte_table_action *a;
530 struct pipeline_data {
531 struct rte_pipeline *p;
532 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
535 struct rte_ring *msgq_req;
536 struct rte_ring *msgq_rsp;
537 uint64_t timer_period; /* Measured in CPU cycles. */
540 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
543 struct softnic_thread_data {
544 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
545 uint32_t n_pipelines;
547 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
548 struct rte_ring *msgq_req;
549 struct rte_ring *msgq_rsp;
550 uint64_t timer_period; /* Measured in CPU cycles. */
552 uint64_t time_next_min;
554 } __rte_cache_aligned;
559 struct pmd_internals {
561 struct pmd_params params;
564 struct tm_internals tm; /**< Traffic Management */
567 struct flow_internals flow;
568 struct mtr_internals mtr;
570 struct softnic_conn *conn;
571 struct softnic_mempool_list mempool_list;
572 struct softnic_swq_list swq_list;
573 struct softnic_link_list link_list;
574 struct softnic_tmgr_port_list tmgr_port_list;
575 struct softnic_tap_list tap_list;
576 struct softnic_port_in_action_profile_list port_in_action_profile_list;
577 struct softnic_table_action_profile_list table_action_profile_list;
578 struct pipeline_list pipeline_list;
579 struct softnic_thread thread[RTE_MAX_LCORE];
580 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
583 static inline struct rte_eth_dev *
584 ETHDEV(struct pmd_internals *softnic)
592 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
596 return &rte_eth_devices[port_id];
603 flow_attr_map_set(struct pmd_internals *softnic,
606 const char *pipeline_name,
609 struct flow_attr_map *
610 flow_attr_map_get(struct pmd_internals *softnic,
614 extern const struct rte_flow_ops pmd_flow_ops;
620 softnic_mtr_init(struct pmd_internals *p);
623 softnic_mtr_free(struct pmd_internals *p);
626 softnic_mtr_find(struct pmd_internals *p,
629 struct softnic_mtr_meter_profile *
630 softnic_mtr_meter_profile_find(struct pmd_internals *p,
631 uint32_t meter_profile_id);
633 extern const struct rte_mtr_ops pmd_mtr_ops;
639 softnic_mempool_init(struct pmd_internals *p);
642 softnic_mempool_free(struct pmd_internals *p);
644 struct softnic_mempool *
645 softnic_mempool_find(struct pmd_internals *p,
648 struct softnic_mempool *
649 softnic_mempool_create(struct pmd_internals *p,
651 struct softnic_mempool_params *params);
657 softnic_swq_init(struct pmd_internals *p);
660 softnic_swq_free(struct pmd_internals *p);
663 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
666 softnic_swq_find(struct pmd_internals *p,
670 softnic_swq_create(struct pmd_internals *p,
672 struct softnic_swq_params *params);
678 softnic_link_init(struct pmd_internals *p);
681 softnic_link_free(struct pmd_internals *p);
683 struct softnic_link *
684 softnic_link_find(struct pmd_internals *p,
687 struct softnic_link *
688 softnic_link_create(struct pmd_internals *p,
690 struct softnic_link_params *params);
696 softnic_tmgr_init(struct pmd_internals *p);
699 softnic_tmgr_free(struct pmd_internals *p);
701 struct softnic_tmgr_port *
702 softnic_tmgr_port_find(struct pmd_internals *p,
705 struct softnic_tmgr_port *
706 softnic_tmgr_port_create(struct pmd_internals *p,
710 tm_hierarchy_init(struct pmd_internals *p);
713 tm_hierarchy_free(struct pmd_internals *p);
716 tm_used(struct rte_eth_dev *dev)
718 struct pmd_internals *p = dev->data->dev_private;
720 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
723 extern const struct rte_tm_ops pmd_tm_ops;
729 softnic_tap_init(struct pmd_internals *p);
732 softnic_tap_free(struct pmd_internals *p);
735 softnic_tap_find(struct pmd_internals *p,
739 softnic_tap_create(struct pmd_internals *p,
746 softnic_port_in_action_profile_init(struct pmd_internals *p);
749 softnic_port_in_action_profile_free(struct pmd_internals *p);
751 struct softnic_port_in_action_profile *
752 softnic_port_in_action_profile_find(struct pmd_internals *p,
755 struct softnic_port_in_action_profile *
756 softnic_port_in_action_profile_create(struct pmd_internals *p,
758 struct softnic_port_in_action_profile_params *params);
764 softnic_table_action_profile_init(struct pmd_internals *p);
767 softnic_table_action_profile_free(struct pmd_internals *p);
769 struct softnic_table_action_profile *
770 softnic_table_action_profile_find(struct pmd_internals *p,
773 struct softnic_table_action_profile *
774 softnic_table_action_profile_create(struct pmd_internals *p,
776 struct softnic_table_action_profile_params *params);
782 softnic_pipeline_init(struct pmd_internals *p);
785 softnic_pipeline_free(struct pmd_internals *p);
788 softnic_pipeline_disable_all(struct pmd_internals *p);
791 softnic_pipeline_find(struct pmd_internals *p, const char *name);
794 softnic_pipeline_create(struct pmd_internals *p,
796 struct pipeline_params *params);
799 softnic_pipeline_port_in_create(struct pmd_internals *p,
800 const char *pipeline_name,
801 struct softnic_port_in_params *params,
805 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
806 const char *pipeline_name,
811 softnic_pipeline_port_out_create(struct pmd_internals *p,
812 const char *pipeline_name,
813 struct softnic_port_out_params *params);
816 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
817 const char *pipeline_name,
822 softnic_pipeline_table_create(struct pmd_internals *p,
823 const char *pipeline_name,
824 struct softnic_table_params *params);
826 struct softnic_table_meter_profile *
827 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
828 uint32_t meter_profile_id);
830 struct softnic_table_rule_match_acl {
857 struct softnic_table_rule_match_array {
861 struct softnic_table_rule_match_hash {
862 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
865 struct softnic_table_rule_match_lpm {
877 struct softnic_table_rule_match {
878 enum softnic_table_type match_type;
881 struct softnic_table_rule_match_acl acl;
882 struct softnic_table_rule_match_array array;
883 struct softnic_table_rule_match_hash hash;
884 struct softnic_table_rule_match_lpm lpm;
888 struct softnic_table_rule_action {
889 uint64_t action_mask;
890 struct rte_table_action_fwd_params fwd;
891 struct rte_table_action_lb_params lb;
892 struct rte_table_action_mtr_params mtr;
893 struct rte_table_action_tm_params tm;
894 struct rte_table_action_encap_params encap;
895 struct rte_table_action_nat_params nat;
896 struct rte_table_action_ttl_params ttl;
897 struct rte_table_action_stats_params stats;
898 struct rte_table_action_time_params time;
902 TAILQ_ENTRY(rte_flow) node;
903 struct softnic_table_rule_match match;
904 struct softnic_table_rule_action action;
906 struct pipeline *pipeline;
911 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
912 const char *pipeline_name,
914 struct rte_pipeline_port_in_stats *stats,
918 softnic_pipeline_port_in_enable(struct pmd_internals *p,
919 const char *pipeline_name,
923 softnic_pipeline_port_in_disable(struct pmd_internals *p,
924 const char *pipeline_name,
928 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
929 const char *pipeline_name,
931 struct rte_pipeline_port_out_stats *stats,
935 softnic_pipeline_table_stats_read(struct pmd_internals *p,
936 const char *pipeline_name,
938 struct rte_pipeline_table_stats *stats,
942 softnic_pipeline_table_rule_add(struct pmd_internals *p,
943 const char *pipeline_name,
945 struct softnic_table_rule_match *match,
946 struct softnic_table_rule_action *action,
950 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
951 const char *pipeline_name,
953 struct softnic_table_rule_match *match,
954 struct softnic_table_rule_action *action,
959 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
960 const char *pipeline_name,
962 struct softnic_table_rule_action *action,
966 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
967 const char *pipeline_name,
969 struct softnic_table_rule_match *match);
972 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
973 const char *pipeline_name,
977 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
978 const char *pipeline_name,
981 struct rte_table_action_stats_counters *stats,
985 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
986 const char *pipeline_name,
988 uint32_t meter_profile_id,
989 struct rte_table_action_meter_profile *profile);
992 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
993 const char *pipeline_name,
995 uint32_t meter_profile_id);
998 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
999 const char *pipeline_name,
1003 struct rte_table_action_mtr_counters *stats,
1007 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1008 const char *pipeline_name,
1011 struct rte_table_action_dscp_table *dscp_table);
1014 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1015 const char *pipeline_name,
1018 struct rte_table_action_ttl_counters *stats,
1025 softnic_thread_init(struct pmd_internals *p);
1028 softnic_thread_free(struct pmd_internals *p);
1031 softnic_thread_pipeline_enable(struct pmd_internals *p,
1033 const char *pipeline_name);
1036 softnic_thread_pipeline_disable(struct pmd_internals *p,
1038 const char *pipeline_name);
1044 softnic_cli_process(char *in,
1050 softnic_cli_script_process(struct pmd_internals *softnic,
1051 const char *file_name,
1052 size_t msg_in_len_max,
1053 size_t msg_out_len_max);
1055 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */