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"
41 int sc; /**< Service cores. */
43 /** Traffic Management (TM) */
45 uint32_t n_queues; /**< Number of queues */
46 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
55 TAILQ_HEAD(flow_list, rte_flow);
57 struct flow_attr_map {
58 char pipeline_name[NAME_SIZE];
63 #ifndef SOFTNIC_FLOW_MAX_GROUPS
64 #define SOFTNIC_FLOW_MAX_GROUPS 64
67 struct flow_internals {
68 struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
69 struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
76 /* MTR meter profile */
77 struct softnic_mtr_meter_profile {
78 TAILQ_ENTRY(softnic_mtr_meter_profile) node;
79 uint32_t meter_profile_id;
80 struct rte_mtr_meter_profile params;
84 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
86 /* MTR meter object */
88 TAILQ_ENTRY(softnic_mtr) node;
90 struct rte_mtr_params params;
91 struct rte_flow *flow;
94 TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
96 struct mtr_internals {
97 struct softnic_mtr_meter_profile_list meter_profiles;
98 struct softnic_mtr_list mtrs;
104 struct softnic_mempool_params {
105 uint32_t buffer_size;
110 struct softnic_mempool {
111 TAILQ_ENTRY(softnic_mempool) node;
112 char name[NAME_SIZE];
113 struct rte_mempool *m;
114 uint32_t buffer_size;
117 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
122 struct softnic_swq_params {
127 TAILQ_ENTRY(softnic_swq) node;
128 char name[NAME_SIZE];
132 TAILQ_HEAD(softnic_swq_list, softnic_swq);
137 struct softnic_link_params {
138 const char *dev_name;
139 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
142 struct softnic_link {
143 TAILQ_ENTRY(softnic_link) node;
144 char name[NAME_SIZE];
150 TAILQ_HEAD(softnic_link_list, softnic_link);
156 #ifndef TM_MAX_SUBPORTS
157 #define TM_MAX_SUBPORTS 8
160 #ifndef TM_MAX_PIPES_PER_SUBPORT
161 #define TM_MAX_PIPES_PER_SUBPORT 4096
165 struct rte_sched_port_params port_params;
167 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
169 struct rte_sched_pipe_params
170 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
171 uint32_t n_pipe_profiles;
172 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
177 TM_NODE_LEVEL_PORT = 0,
178 TM_NODE_LEVEL_SUBPORT,
185 /* TM Shaper Profile */
186 struct tm_shaper_profile {
187 TAILQ_ENTRY(tm_shaper_profile) node;
188 uint32_t shaper_profile_id;
190 struct rte_tm_shaper_params params;
193 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
195 /* TM Shared Shaper */
196 struct tm_shared_shaper {
197 TAILQ_ENTRY(tm_shared_shaper) node;
198 uint32_t shared_shaper_id;
200 uint32_t shaper_profile_id;
203 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
205 /* TM WRED Profile */
206 struct tm_wred_profile {
207 TAILQ_ENTRY(tm_wred_profile) node;
208 uint32_t wred_profile_id;
210 struct rte_tm_wred_params params;
213 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
217 TAILQ_ENTRY(tm_node) node;
219 uint32_t parent_node_id;
223 struct tm_node *parent_node;
224 struct tm_shaper_profile *shaper_profile;
225 struct tm_wred_profile *wred_profile;
226 struct rte_tm_node_params params;
227 struct rte_tm_node_stats stats;
231 TAILQ_HEAD(tm_node_list, tm_node);
233 /* TM Hierarchy Specification */
234 struct tm_hierarchy {
235 struct tm_shaper_profile_list shaper_profiles;
236 struct tm_shared_shaper_list shared_shapers;
237 struct tm_wred_profile_list wred_profiles;
238 struct tm_node_list nodes;
240 uint32_t n_shaper_profiles;
241 uint32_t n_shared_shapers;
242 uint32_t n_wred_profiles;
245 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
248 struct tm_internals {
249 /** Hierarchy specification
251 * -Hierarchy is unfrozen at init and when port is stopped.
252 * -Hierarchy is frozen on successful hierarchy commit.
253 * -Run-time hierarchy changes are not allowed, therefore it makes
254 * sense to keep the hierarchy frozen after the port is started.
256 struct tm_hierarchy h;
257 int hierarchy_frozen;
260 struct tm_params params;
263 struct softnic_tmgr_port {
264 TAILQ_ENTRY(softnic_tmgr_port) node;
265 char name[NAME_SIZE];
266 struct rte_sched_port *s;
269 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
275 TAILQ_ENTRY(softnic_tap) node;
276 char name[NAME_SIZE];
280 TAILQ_HEAD(softnic_tap_list, softnic_tap);
285 struct softnic_cryptodev_params {
286 const char *dev_name;
287 uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
290 uint32_t session_pool_size;
293 struct softnic_cryptodev {
294 TAILQ_ENTRY(softnic_cryptodev) node;
295 char name[NAME_SIZE];
298 struct rte_mempool *mp_create;
299 struct rte_mempool *mp_init;
302 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
307 struct softnic_port_in_action_profile_params {
308 uint64_t action_mask;
309 struct rte_port_in_action_fltr_config fltr;
310 struct rte_port_in_action_lb_config lb;
313 struct softnic_port_in_action_profile {
314 TAILQ_ENTRY(softnic_port_in_action_profile) node;
315 char name[NAME_SIZE];
316 struct softnic_port_in_action_profile_params params;
317 struct rte_port_in_action_profile *ap;
320 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
325 struct softnic_table_action_profile_params {
326 uint64_t action_mask;
327 struct rte_table_action_common_config common;
328 struct rte_table_action_lb_config lb;
329 struct rte_table_action_mtr_config mtr;
330 struct rte_table_action_tm_config tm;
331 struct rte_table_action_encap_config encap;
332 struct rte_table_action_nat_config nat;
333 struct rte_table_action_ttl_config ttl;
334 struct rte_table_action_stats_config stats;
335 struct rte_table_action_sym_crypto_config sym_crypto;
338 struct softnic_table_action_profile {
339 TAILQ_ENTRY(softnic_table_action_profile) node;
340 char name[NAME_SIZE];
341 struct softnic_table_action_profile_params params;
342 struct rte_table_action_profile *ap;
345 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
347 struct softnic_table_meter_profile {
348 TAILQ_ENTRY(softnic_table_meter_profile) node;
349 uint32_t meter_profile_id;
350 struct rte_table_action_meter_profile profile;
353 TAILQ_HEAD(softnic_table_meter_profile_list,
354 softnic_table_meter_profile);
359 struct pipeline_params {
360 uint32_t timer_period_ms;
361 uint32_t offset_port_id;
364 enum softnic_port_in_type {
373 struct softnic_port_in_params {
375 enum softnic_port_in_type type;
376 char dev_name[NAME_SIZE];
383 const char *mempool_name;
388 const char *mempool_name;
389 const char *file_name;
390 uint32_t n_bytes_per_pkt;
402 char action_profile_name[NAME_SIZE];
405 enum softnic_port_out_type {
414 struct softnic_port_out_params {
415 enum softnic_port_out_type type;
416 char dev_name[NAME_SIZE];
423 const char *file_name;
437 enum softnic_table_type {
445 struct softnic_table_acl_params {
447 uint32_t ip_header_offset;
451 struct softnic_table_array_params {
456 #ifndef TABLE_RULE_MATCH_SIZE_MAX
457 #define TABLE_RULE_MATCH_SIZE_MAX 256
460 struct softnic_table_hash_params {
464 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
466 int extendable_bucket;
469 struct softnic_table_lpm_params {
475 struct softnic_table_params {
477 enum softnic_table_type match_type;
479 struct softnic_table_acl_params acl;
480 struct softnic_table_array_params array;
481 struct softnic_table_hash_params hash;
482 struct softnic_table_lpm_params lpm;
486 char action_profile_name[NAME_SIZE];
489 struct softnic_port_in {
490 struct softnic_port_in_params params;
491 struct softnic_port_in_action_profile *ap;
492 struct rte_port_in_action *a;
495 struct softnic_port_out {
496 struct softnic_port_out_params params;
499 struct softnic_table {
500 struct softnic_table_params params;
501 struct softnic_table_action_profile *ap;
502 struct rte_table_action *a;
503 struct flow_list flows;
504 struct rte_table_action_dscp_table dscp_table;
505 struct softnic_table_meter_profile_list meter_profiles;
509 TAILQ_ENTRY(pipeline) node;
510 char name[NAME_SIZE];
512 struct rte_pipeline *p;
513 struct pipeline_params params;
514 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
515 struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
516 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
518 uint32_t n_ports_out;
521 struct rte_ring *msgq_req;
522 struct rte_ring *msgq_rsp;
523 uint32_t timer_period_ms;
530 TAILQ_HEAD(pipeline_list, pipeline);
535 #ifndef THREAD_PIPELINES_MAX
536 #define THREAD_PIPELINES_MAX 256
539 #ifndef THREAD_MSGQ_SIZE
540 #define THREAD_MSGQ_SIZE 64
543 #ifndef THREAD_TIMER_PERIOD_MS
544 #define THREAD_TIMER_PERIOD_MS 100
548 * Master thead: data plane thread context
550 struct softnic_thread {
551 struct rte_ring *msgq_req;
552 struct rte_ring *msgq_rsp;
558 * Data plane threads: context
560 #ifndef TABLE_RULE_ACTION_SIZE_MAX
561 #define TABLE_RULE_ACTION_SIZE_MAX 2048
564 struct softnic_table_data {
565 struct rte_table_action *a;
568 struct pipeline_data {
569 struct rte_pipeline *p;
570 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
573 struct rte_ring *msgq_req;
574 struct rte_ring *msgq_rsp;
575 uint64_t timer_period; /* Measured in CPU cycles. */
578 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
581 struct softnic_thread_data {
582 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
583 uint32_t n_pipelines;
585 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
586 struct rte_ring *msgq_req;
587 struct rte_ring *msgq_rsp;
588 uint64_t timer_period; /* Measured in CPU cycles. */
590 uint64_t time_next_min;
592 } __rte_cache_aligned;
597 struct pmd_internals {
599 struct pmd_params params;
602 struct tm_internals tm; /**< Traffic Management */
605 struct flow_internals flow;
606 struct mtr_internals mtr;
608 struct softnic_conn *conn;
609 struct softnic_mempool_list mempool_list;
610 struct softnic_swq_list swq_list;
611 struct softnic_link_list link_list;
612 struct softnic_tmgr_port_list tmgr_port_list;
613 struct softnic_tap_list tap_list;
614 struct softnic_cryptodev_list cryptodev_list;
615 struct softnic_port_in_action_profile_list port_in_action_profile_list;
616 struct softnic_table_action_profile_list table_action_profile_list;
617 struct pipeline_list pipeline_list;
618 struct softnic_thread thread[RTE_MAX_LCORE];
619 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
622 static inline struct rte_eth_dev *
623 ETHDEV(struct pmd_internals *softnic)
631 status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
635 return &rte_eth_devices[port_id];
642 flow_attr_map_set(struct pmd_internals *softnic,
645 const char *pipeline_name,
648 struct flow_attr_map *
649 flow_attr_map_get(struct pmd_internals *softnic,
653 extern const struct rte_flow_ops pmd_flow_ops;
659 softnic_mtr_init(struct pmd_internals *p);
662 softnic_mtr_free(struct pmd_internals *p);
665 softnic_mtr_find(struct pmd_internals *p,
668 struct softnic_mtr_meter_profile *
669 softnic_mtr_meter_profile_find(struct pmd_internals *p,
670 uint32_t meter_profile_id);
672 extern const struct rte_mtr_ops pmd_mtr_ops;
678 softnic_mempool_init(struct pmd_internals *p);
681 softnic_mempool_free(struct pmd_internals *p);
683 struct softnic_mempool *
684 softnic_mempool_find(struct pmd_internals *p,
687 struct softnic_mempool *
688 softnic_mempool_create(struct pmd_internals *p,
690 struct softnic_mempool_params *params);
696 softnic_swq_init(struct pmd_internals *p);
699 softnic_swq_free(struct pmd_internals *p);
702 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
705 softnic_swq_find(struct pmd_internals *p,
709 softnic_swq_create(struct pmd_internals *p,
711 struct softnic_swq_params *params);
717 softnic_link_init(struct pmd_internals *p);
720 softnic_link_free(struct pmd_internals *p);
722 struct softnic_link *
723 softnic_link_find(struct pmd_internals *p,
726 struct softnic_link *
727 softnic_link_create(struct pmd_internals *p,
729 struct softnic_link_params *params);
735 softnic_tmgr_init(struct pmd_internals *p);
738 softnic_tmgr_free(struct pmd_internals *p);
740 struct softnic_tmgr_port *
741 softnic_tmgr_port_find(struct pmd_internals *p,
744 struct softnic_tmgr_port *
745 softnic_tmgr_port_create(struct pmd_internals *p,
749 tm_hierarchy_init(struct pmd_internals *p);
752 tm_hierarchy_free(struct pmd_internals *p);
755 tm_used(struct rte_eth_dev *dev)
757 struct pmd_internals *p = dev->data->dev_private;
759 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
762 extern const struct rte_tm_ops pmd_tm_ops;
768 softnic_tap_init(struct pmd_internals *p);
771 softnic_tap_free(struct pmd_internals *p);
774 softnic_tap_find(struct pmd_internals *p,
778 softnic_tap_create(struct pmd_internals *p,
785 softnic_cryptodev_init(struct pmd_internals *p);
788 softnic_cryptodev_free(struct pmd_internals *p);
790 struct softnic_cryptodev *
791 softnic_cryptodev_find(struct pmd_internals *p,
794 struct softnic_cryptodev *
795 softnic_cryptodev_create(struct pmd_internals *p,
797 struct softnic_cryptodev_params *params);
803 softnic_port_in_action_profile_init(struct pmd_internals *p);
806 softnic_port_in_action_profile_free(struct pmd_internals *p);
808 struct softnic_port_in_action_profile *
809 softnic_port_in_action_profile_find(struct pmd_internals *p,
812 struct softnic_port_in_action_profile *
813 softnic_port_in_action_profile_create(struct pmd_internals *p,
815 struct softnic_port_in_action_profile_params *params);
821 softnic_table_action_profile_init(struct pmd_internals *p);
824 softnic_table_action_profile_free(struct pmd_internals *p);
826 struct softnic_table_action_profile *
827 softnic_table_action_profile_find(struct pmd_internals *p,
830 struct softnic_table_action_profile *
831 softnic_table_action_profile_create(struct pmd_internals *p,
833 struct softnic_table_action_profile_params *params);
835 enum rte_table_action_policer
836 softnic_table_action_policer(enum rte_mtr_policer_action action);
842 softnic_pipeline_init(struct pmd_internals *p);
845 softnic_pipeline_free(struct pmd_internals *p);
848 softnic_pipeline_disable_all(struct pmd_internals *p);
851 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
854 softnic_pipeline_find(struct pmd_internals *p, const char *name);
857 softnic_pipeline_create(struct pmd_internals *p,
859 struct pipeline_params *params);
862 softnic_pipeline_port_in_create(struct pmd_internals *p,
863 const char *pipeline_name,
864 struct softnic_port_in_params *params,
868 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
869 const char *pipeline_name,
874 softnic_pipeline_port_out_create(struct pmd_internals *p,
875 const char *pipeline_name,
876 struct softnic_port_out_params *params);
879 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
880 const char *pipeline_name,
885 softnic_pipeline_table_create(struct pmd_internals *p,
886 const char *pipeline_name,
887 struct softnic_table_params *params);
889 struct softnic_table_meter_profile *
890 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
891 uint32_t meter_profile_id);
893 struct softnic_table_rule_match_acl {
920 struct softnic_table_rule_match_array {
924 struct softnic_table_rule_match_hash {
925 uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
928 struct softnic_table_rule_match_lpm {
940 struct softnic_table_rule_match {
941 enum softnic_table_type match_type;
944 struct softnic_table_rule_match_acl acl;
945 struct softnic_table_rule_match_array array;
946 struct softnic_table_rule_match_hash hash;
947 struct softnic_table_rule_match_lpm lpm;
951 struct softnic_table_rule_action {
952 uint64_t action_mask;
953 struct rte_table_action_fwd_params fwd;
954 struct rte_table_action_lb_params lb;
955 struct rte_table_action_mtr_params mtr;
956 struct rte_table_action_tm_params tm;
957 struct rte_table_action_encap_params encap;
958 struct rte_table_action_nat_params nat;
959 struct rte_table_action_ttl_params ttl;
960 struct rte_table_action_stats_params stats;
961 struct rte_table_action_time_params time;
962 struct rte_table_action_tag_params tag;
963 struct rte_table_action_decap_params decap;
964 struct rte_table_action_sym_crypto_params sym_crypto;
968 TAILQ_ENTRY(rte_flow) node;
969 struct softnic_table_rule_match match;
970 struct softnic_table_rule_action action;
972 struct pipeline *pipeline;
977 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
978 const char *pipeline_name,
980 struct rte_pipeline_port_in_stats *stats,
984 softnic_pipeline_port_in_enable(struct pmd_internals *p,
985 const char *pipeline_name,
989 softnic_pipeline_port_in_disable(struct pmd_internals *p,
990 const char *pipeline_name,
994 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
995 const char *pipeline_name,
997 struct rte_pipeline_port_out_stats *stats,
1001 softnic_pipeline_table_stats_read(struct pmd_internals *p,
1002 const char *pipeline_name,
1004 struct rte_pipeline_table_stats *stats,
1008 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1009 const char *pipeline_name,
1011 struct softnic_table_rule_match *match,
1012 struct softnic_table_rule_action *action,
1016 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1017 const char *pipeline_name,
1019 struct softnic_table_rule_match *match,
1020 struct softnic_table_rule_action *action,
1025 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1026 const char *pipeline_name,
1028 struct softnic_table_rule_action *action,
1032 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1033 const char *pipeline_name,
1035 struct softnic_table_rule_match *match);
1038 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1039 const char *pipeline_name,
1043 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1044 const char *pipeline_name,
1047 struct rte_table_action_stats_counters *stats,
1051 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1052 const char *pipeline_name,
1054 uint32_t meter_profile_id,
1055 struct rte_table_action_meter_profile *profile);
1058 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1059 const char *pipeline_name,
1061 uint32_t meter_profile_id);
1064 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1065 const char *pipeline_name,
1069 struct rte_table_action_mtr_counters *stats,
1073 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1074 const char *pipeline_name,
1077 struct rte_table_action_dscp_table *dscp_table);
1080 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1081 const char *pipeline_name,
1084 struct rte_table_action_ttl_counters *stats,
1091 softnic_thread_init(struct pmd_internals *p);
1094 softnic_thread_free(struct pmd_internals *p);
1097 softnic_thread_pipeline_enable(struct pmd_internals *p,
1099 const char *pipeline_name);
1102 softnic_thread_pipeline_disable(struct pmd_internals *p,
1104 const char *pipeline_name);
1110 softnic_cli_process(char *in,
1116 softnic_cli_script_process(struct pmd_internals *softnic,
1117 const char *file_name,
1118 size_t msg_in_len_max,
1119 size_t msg_out_len_max);
1121 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */