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"
37 /** Traffic Management (TM) */
39 uint32_t n_queues; /**< Number of queues */
40 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
47 struct softnic_mempool_params {
53 struct softnic_mempool {
54 TAILQ_ENTRY(softnic_mempool) node;
56 struct rte_mempool *m;
60 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
65 struct softnic_swq_params {
70 TAILQ_ENTRY(softnic_swq) node;
75 TAILQ_HEAD(softnic_swq_list, softnic_swq);
80 struct softnic_link_params {
82 uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
86 TAILQ_ENTRY(softnic_link) node;
93 TAILQ_HEAD(softnic_link_list, softnic_link);
99 #ifndef TM_MAX_SUBPORTS
100 #define TM_MAX_SUBPORTS 8
103 #ifndef TM_MAX_PIPES_PER_SUBPORT
104 #define TM_MAX_PIPES_PER_SUBPORT 4096
108 struct rte_sched_port_params port_params;
110 struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
112 struct rte_sched_pipe_params
113 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
114 uint32_t n_pipe_profiles;
115 uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
120 TM_NODE_LEVEL_PORT = 0,
121 TM_NODE_LEVEL_SUBPORT,
128 /* TM Shaper Profile */
129 struct tm_shaper_profile {
130 TAILQ_ENTRY(tm_shaper_profile) node;
131 uint32_t shaper_profile_id;
133 struct rte_tm_shaper_params params;
136 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
138 /* TM Shared Shaper */
139 struct tm_shared_shaper {
140 TAILQ_ENTRY(tm_shared_shaper) node;
141 uint32_t shared_shaper_id;
143 uint32_t shaper_profile_id;
146 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
148 /* TM WRED Profile */
149 struct tm_wred_profile {
150 TAILQ_ENTRY(tm_wred_profile) node;
151 uint32_t wred_profile_id;
153 struct rte_tm_wred_params params;
156 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
160 TAILQ_ENTRY(tm_node) node;
162 uint32_t parent_node_id;
166 struct tm_node *parent_node;
167 struct tm_shaper_profile *shaper_profile;
168 struct tm_wred_profile *wred_profile;
169 struct rte_tm_node_params params;
170 struct rte_tm_node_stats stats;
174 TAILQ_HEAD(tm_node_list, tm_node);
176 /* TM Hierarchy Specification */
177 struct tm_hierarchy {
178 struct tm_shaper_profile_list shaper_profiles;
179 struct tm_shared_shaper_list shared_shapers;
180 struct tm_wred_profile_list wred_profiles;
181 struct tm_node_list nodes;
183 uint32_t n_shaper_profiles;
184 uint32_t n_shared_shapers;
185 uint32_t n_wred_profiles;
188 uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
191 struct tm_internals {
192 /** Hierarchy specification
194 * -Hierarchy is unfrozen at init and when port is stopped.
195 * -Hierarchy is frozen on successful hierarchy commit.
196 * -Run-time hierarchy changes are not allowed, therefore it makes
197 * sense to keep the hierarchy frozen after the port is started.
199 struct tm_hierarchy h;
200 int hierarchy_frozen;
203 struct tm_params params;
204 struct rte_sched_port *sched;
207 struct softnic_tmgr_port {
208 TAILQ_ENTRY(softnic_tmgr_port) node;
209 char name[NAME_SIZE];
210 struct rte_sched_port *s;
213 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
219 TAILQ_ENTRY(softnic_tap) node;
220 char name[NAME_SIZE];
224 TAILQ_HEAD(softnic_tap_list, softnic_tap);
229 struct softnic_port_in_action_profile_params {
230 uint64_t action_mask;
231 struct rte_port_in_action_fltr_config fltr;
232 struct rte_port_in_action_lb_config lb;
235 struct softnic_port_in_action_profile {
236 TAILQ_ENTRY(softnic_port_in_action_profile) node;
237 char name[NAME_SIZE];
238 struct softnic_port_in_action_profile_params params;
239 struct rte_port_in_action_profile *ap;
242 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
247 struct softnic_table_action_profile_params {
248 uint64_t action_mask;
249 struct rte_table_action_common_config common;
250 struct rte_table_action_lb_config lb;
251 struct rte_table_action_mtr_config mtr;
252 struct rte_table_action_tm_config tm;
253 struct rte_table_action_encap_config encap;
254 struct rte_table_action_nat_config nat;
255 struct rte_table_action_ttl_config ttl;
256 struct rte_table_action_stats_config stats;
259 struct softnic_table_action_profile {
260 TAILQ_ENTRY(softnic_table_action_profile) node;
261 char name[NAME_SIZE];
262 struct softnic_table_action_profile_params params;
263 struct rte_table_action_profile *ap;
266 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
271 struct pipeline_params {
272 uint32_t timer_period_ms;
273 uint32_t offset_port_id;
276 enum softnic_port_in_type {
284 struct softnic_port_in_params {
286 enum softnic_port_in_type type;
287 const char *dev_name;
294 const char *mempool_name;
299 const char *mempool_name;
300 const char *file_name;
301 uint32_t n_bytes_per_pkt;
307 const char *action_profile_name;
310 enum softnic_port_out_type {
318 struct softnic_port_out_params {
319 enum softnic_port_out_type type;
320 const char *dev_name;
327 const char *file_name;
336 enum softnic_table_type {
344 struct softnic_table_acl_params {
346 uint32_t ip_header_offset;
350 struct softnic_table_array_params {
355 struct softnic_table_hash_params {
361 int extendable_bucket;
364 struct softnic_table_lpm_params {
370 struct softnic_table_params {
372 enum softnic_table_type match_type;
374 struct softnic_table_acl_params acl;
375 struct softnic_table_array_params array;
376 struct softnic_table_hash_params hash;
377 struct softnic_table_lpm_params lpm;
381 const char *action_profile_name;
384 struct softnic_port_in {
385 struct softnic_port_in_params params;
386 struct softnic_port_in_action_profile *ap;
387 struct rte_port_in_action *a;
390 struct softnic_table {
391 struct softnic_table_params params;
392 struct softnic_table_action_profile *ap;
393 struct rte_table_action *a;
397 TAILQ_ENTRY(pipeline) node;
398 char name[NAME_SIZE];
400 struct rte_pipeline *p;
401 struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
402 struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
404 uint32_t n_ports_out;
407 struct rte_ring *msgq_req;
408 struct rte_ring *msgq_rsp;
409 uint32_t timer_period_ms;
416 TAILQ_HEAD(pipeline_list, pipeline);
421 #ifndef THREAD_PIPELINES_MAX
422 #define THREAD_PIPELINES_MAX 256
425 #ifndef THREAD_MSGQ_SIZE
426 #define THREAD_MSGQ_SIZE 64
429 #ifndef THREAD_TIMER_PERIOD_MS
430 #define THREAD_TIMER_PERIOD_MS 100
434 * Master thead: data plane thread context
436 struct softnic_thread {
437 struct rte_ring *msgq_req;
438 struct rte_ring *msgq_rsp;
444 * Data plane threads: context
446 #ifndef TABLE_RULE_ACTION_SIZE_MAX
447 #define TABLE_RULE_ACTION_SIZE_MAX 2048
450 struct softnic_table_data {
451 struct rte_table_action *a;
454 struct pipeline_data {
455 struct rte_pipeline *p;
456 struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
459 struct rte_ring *msgq_req;
460 struct rte_ring *msgq_rsp;
461 uint64_t timer_period; /* Measured in CPU cycles. */
464 uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
467 struct softnic_thread_data {
468 struct rte_pipeline *p[THREAD_PIPELINES_MAX];
469 uint32_t n_pipelines;
471 struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
472 struct rte_ring *msgq_req;
473 struct rte_ring *msgq_rsp;
474 uint64_t timer_period; /* Measured in CPU cycles. */
476 uint64_t time_next_min;
478 } __rte_cache_aligned;
483 struct pmd_internals {
485 struct pmd_params params;
488 struct tm_internals tm; /**< Traffic Management */
491 struct softnic_mempool_list mempool_list;
492 struct softnic_swq_list swq_list;
493 struct softnic_link_list link_list;
494 struct softnic_tmgr_port_list tmgr_port_list;
495 struct softnic_tap_list tap_list;
496 struct softnic_port_in_action_profile_list port_in_action_profile_list;
497 struct softnic_table_action_profile_list table_action_profile_list;
498 struct pipeline_list pipeline_list;
499 struct softnic_thread thread[RTE_MAX_LCORE];
500 struct softnic_thread_data thread_data[RTE_MAX_LCORE];
507 softnic_mempool_init(struct pmd_internals *p);
510 softnic_mempool_free(struct pmd_internals *p);
512 struct softnic_mempool *
513 softnic_mempool_find(struct pmd_internals *p,
516 struct softnic_mempool *
517 softnic_mempool_create(struct pmd_internals *p,
519 struct softnic_mempool_params *params);
525 softnic_swq_init(struct pmd_internals *p);
528 softnic_swq_free(struct pmd_internals *p);
531 softnic_swq_find(struct pmd_internals *p,
535 softnic_swq_create(struct pmd_internals *p,
537 struct softnic_swq_params *params);
543 softnic_link_init(struct pmd_internals *p);
546 softnic_link_free(struct pmd_internals *p);
548 struct softnic_link *
549 softnic_link_find(struct pmd_internals *p,
552 struct softnic_link *
553 softnic_link_create(struct pmd_internals *p,
555 struct softnic_link_params *params);
561 softnic_tmgr_init(struct pmd_internals *p);
564 softnic_tmgr_free(struct pmd_internals *p);
566 struct softnic_tmgr_port *
567 softnic_tmgr_port_find(struct pmd_internals *p,
570 struct softnic_tmgr_port *
571 softnic_tmgr_port_create(struct pmd_internals *p,
573 struct rte_sched_port *sched);
576 tm_init(struct pmd_internals *p);
579 tm_free(struct pmd_internals *p);
582 tm_start(struct pmd_internals *p);
585 tm_stop(struct pmd_internals *p);
588 tm_used(struct rte_eth_dev *dev)
590 struct pmd_internals *p = dev->data->dev_private;
592 return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
595 extern const struct rte_tm_ops pmd_tm_ops;
601 softnic_tap_init(struct pmd_internals *p);
604 softnic_tap_free(struct pmd_internals *p);
607 softnic_tap_find(struct pmd_internals *p,
611 softnic_tap_create(struct pmd_internals *p,
618 softnic_port_in_action_profile_init(struct pmd_internals *p);
621 softnic_port_in_action_profile_free(struct pmd_internals *p);
623 struct softnic_port_in_action_profile *
624 softnic_port_in_action_profile_find(struct pmd_internals *p,
627 struct softnic_port_in_action_profile *
628 softnic_port_in_action_profile_create(struct pmd_internals *p,
630 struct softnic_port_in_action_profile_params *params);
636 softnic_table_action_profile_init(struct pmd_internals *p);
639 softnic_table_action_profile_free(struct pmd_internals *p);
641 struct softnic_table_action_profile *
642 softnic_table_action_profile_find(struct pmd_internals *p,
645 struct softnic_table_action_profile *
646 softnic_table_action_profile_create(struct pmd_internals *p,
648 struct softnic_table_action_profile_params *params);
654 softnic_pipeline_init(struct pmd_internals *p);
657 softnic_pipeline_free(struct pmd_internals *p);
660 softnic_pipeline_find(struct pmd_internals *p, const char *name);
663 softnic_pipeline_create(struct pmd_internals *p,
665 struct pipeline_params *params);
668 softnic_pipeline_port_in_create(struct pmd_internals *p,
669 const char *pipeline_name,
670 struct softnic_port_in_params *params,
674 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
675 const char *pipeline_name,
680 softnic_pipeline_port_out_create(struct pmd_internals *p,
681 const char *pipeline_name,
682 struct softnic_port_out_params *params);
685 softnic_pipeline_table_create(struct pmd_internals *p,
686 const char *pipeline_name,
687 struct softnic_table_params *params);
693 softnic_thread_init(struct pmd_internals *p);
696 softnic_thread_free(struct pmd_internals *p);
698 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */