xref: /dpdk/drivers/net/softnic/rte_eth_softnic_internals.h (revision d38febb08d57fec29fed27a2d12a507fc6fcdfa1)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
6 #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <sys/queue.h>
11 
12 #include <rte_mempool.h>
13 #include <rte_mbuf.h>
14 #include <rte_ring.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>
20 
21 #include <rte_ethdev_core.h>
22 #include <ethdev_driver.h>
23 #include <rte_tm_driver.h>
24 #include <rte_flow_driver.h>
25 #include <rte_mtr_driver.h>
26 
27 #include "rte_eth_softnic.h"
28 #include "conn.h"
29 
30 #define NAME_SIZE                                            64
31 #define SOFTNIC_PATH_MAX                                     4096
32 
33 /**
34  * PMD Parameters
35  */
36 
37 struct pmd_params {
38 	char name[NAME_SIZE];
39 	char firmware[SOFTNIC_PATH_MAX];
40 	uint16_t conn_port;
41 	uint32_t cpu_id;
42 	int sc; /**< Service cores. */
43 
44 	/** Traffic Management (TM) */
45 	struct {
46 		uint32_t n_queues; /**< Number of queues */
47 		uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
48 	} tm;
49 };
50 
51 /**
52  * Ethdev Flow API
53  */
54 struct rte_flow;
55 
56 TAILQ_HEAD(flow_list, rte_flow);
57 
58 struct flow_attr_map {
59 	char pipeline_name[NAME_SIZE];
60 	uint32_t table_id;
61 	int valid;
62 };
63 
64 #ifndef SOFTNIC_FLOW_MAX_GROUPS
65 #define SOFTNIC_FLOW_MAX_GROUPS                            64
66 #endif
67 
68 struct flow_internals {
69 	struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
70 	struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
71 };
72 
73 /**
74  * Meter
75  */
76 
77 /* MTR meter profile */
78 struct softnic_mtr_meter_profile {
79 	TAILQ_ENTRY(softnic_mtr_meter_profile) node;
80 	uint32_t meter_profile_id;
81 	struct rte_mtr_meter_profile params;
82 	uint32_t n_users;
83 };
84 
85 TAILQ_HEAD(softnic_mtr_meter_profile_list, softnic_mtr_meter_profile);
86 
87 /* MTR meter policy */
88 struct softnic_mtr_meter_policy {
89 	TAILQ_ENTRY(softnic_mtr_meter_policy) node;
90 	uint32_t meter_policy_id;
91 	enum rte_table_action_policer policer[RTE_COLORS];
92 	uint32_t n_users;
93 };
94 
95 TAILQ_HEAD(softnic_mtr_meter_policy_list, softnic_mtr_meter_policy);
96 
97 /* MTR meter object */
98 struct softnic_mtr {
99 	TAILQ_ENTRY(softnic_mtr) node;
100 	uint32_t mtr_id;
101 	struct rte_mtr_params params;
102 	struct rte_flow *flow;
103 };
104 
105 TAILQ_HEAD(softnic_mtr_list, softnic_mtr);
106 
107 struct mtr_internals {
108 	struct softnic_mtr_meter_profile_list meter_profiles;
109 	struct softnic_mtr_meter_policy_list meter_policies;
110 	struct softnic_mtr_list mtrs;
111 };
112 
113 /**
114  * MEMPOOL
115  */
116 struct softnic_mempool_params {
117 	uint32_t buffer_size;
118 	uint32_t pool_size;
119 	uint32_t cache_size;
120 };
121 
122 struct softnic_mempool {
123 	TAILQ_ENTRY(softnic_mempool) node;
124 	char name[NAME_SIZE];
125 	struct rte_mempool *m;
126 	uint32_t buffer_size;
127 };
128 
129 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
130 
131 /**
132  * SWQ
133  */
134 struct softnic_swq_params {
135 	uint32_t size;
136 };
137 
138 struct softnic_swq {
139 	TAILQ_ENTRY(softnic_swq) node;
140 	char name[NAME_SIZE];
141 	struct rte_ring *r;
142 };
143 
144 TAILQ_HEAD(softnic_swq_list, softnic_swq);
145 
146 /**
147  * LINK
148  */
149 struct softnic_link_params {
150 	const char *dev_name;
151 	uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
152 };
153 
154 struct softnic_link {
155 	TAILQ_ENTRY(softnic_link) node;
156 	char name[NAME_SIZE];
157 	uint16_t port_id;
158 	uint32_t n_rxq;
159 	uint32_t n_txq;
160 };
161 
162 TAILQ_HEAD(softnic_link_list, softnic_link);
163 
164 /**
165  * TMGR
166  */
167 
168 #ifndef TM_MAX_SUBPORTS
169 #define TM_MAX_SUBPORTS					8
170 #endif
171 
172 #ifndef TM_MAX_PIPES_PER_SUBPORT
173 #define TM_MAX_PIPES_PER_SUBPORT			4096
174 #endif
175 
176 #ifndef TM_MAX_PIPE_PROFILE
177 #define TM_MAX_PIPE_PROFILE				256
178 #endif
179 
180 #ifndef TM_MAX_SUBPORT_PROFILE
181 #define TM_MAX_SUBPORT_PROFILE				256
182 #endif
183 
184 struct tm_params {
185 	struct rte_sched_port_params port_params;
186 	struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
187 	struct rte_sched_subport_profile_params
188 		subport_profile[TM_MAX_SUBPORT_PROFILE];
189 	uint32_t n_subport_profiles;
190 	uint32_t subport_to_profile[TM_MAX_SUBPORT_PROFILE];
191 	struct rte_sched_pipe_params pipe_profiles[TM_MAX_PIPE_PROFILE];
192 	uint32_t n_pipe_profiles;
193 	uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
194 };
195 
196 /* TM Levels */
197 enum tm_node_level {
198 	TM_NODE_LEVEL_PORT = 0,
199 	TM_NODE_LEVEL_SUBPORT,
200 	TM_NODE_LEVEL_PIPE,
201 	TM_NODE_LEVEL_TC,
202 	TM_NODE_LEVEL_QUEUE,
203 	TM_NODE_LEVEL_MAX,
204 };
205 
206 /* TM Shaper Profile */
207 struct tm_shaper_profile {
208 	TAILQ_ENTRY(tm_shaper_profile) node;
209 	uint32_t shaper_profile_id;
210 	uint32_t n_users;
211 	struct rte_tm_shaper_params params;
212 };
213 
214 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
215 
216 /* TM Shared Shaper */
217 struct tm_shared_shaper {
218 	TAILQ_ENTRY(tm_shared_shaper) node;
219 	uint32_t shared_shaper_id;
220 	uint32_t n_users;
221 	uint32_t shaper_profile_id;
222 };
223 
224 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
225 
226 /* TM WRED Profile */
227 struct tm_wred_profile {
228 	TAILQ_ENTRY(tm_wred_profile) node;
229 	uint32_t wred_profile_id;
230 	uint32_t n_users;
231 	struct rte_tm_wred_params params;
232 };
233 
234 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
235 
236 /* TM Node */
237 struct tm_node {
238 	TAILQ_ENTRY(tm_node) node;
239 	uint32_t node_id;
240 	uint32_t parent_node_id;
241 	uint32_t priority;
242 	uint32_t weight;
243 	uint32_t level;
244 	struct tm_node *parent_node;
245 	struct tm_shaper_profile *shaper_profile;
246 	struct tm_wred_profile *wred_profile;
247 	struct rte_tm_node_params params;
248 	struct rte_tm_node_stats stats;
249 	uint32_t n_children;
250 };
251 
252 TAILQ_HEAD(tm_node_list, tm_node);
253 
254 /* TM Hierarchy Specification */
255 struct tm_hierarchy {
256 	struct tm_shaper_profile_list shaper_profiles;
257 	struct tm_shared_shaper_list shared_shapers;
258 	struct tm_wred_profile_list wred_profiles;
259 	struct tm_node_list nodes;
260 
261 	uint32_t n_shaper_profiles;
262 	uint32_t n_shared_shapers;
263 	uint32_t n_wred_profiles;
264 	uint32_t n_nodes;
265 
266 	uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
267 };
268 
269 struct tm_internals {
270 	/** Hierarchy specification
271 	 *
272 	 *     -Hierarchy is unfrozen at init and when port is stopped.
273 	 *     -Hierarchy is frozen on successful hierarchy commit.
274 	 *     -Run-time hierarchy changes are not allowed, therefore it makes
275 	 *      sense to keep the hierarchy frozen after the port is started.
276 	 */
277 	struct tm_hierarchy h;
278 	int hierarchy_frozen;
279 
280 	/** Blueprints */
281 	struct tm_params params;
282 };
283 
284 struct softnic_tmgr_port {
285 	TAILQ_ENTRY(softnic_tmgr_port) node;
286 	char name[NAME_SIZE];
287 	struct rte_sched_port *s;
288 };
289 
290 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
291 
292 /**
293  * TAP
294  */
295 struct softnic_tap {
296 	TAILQ_ENTRY(softnic_tap) node;
297 	char name[NAME_SIZE];
298 	int fd;
299 };
300 
301 TAILQ_HEAD(softnic_tap_list, softnic_tap);
302 
303 /**
304  * Cryptodev
305  */
306 struct softnic_cryptodev_params {
307 	const char *dev_name;
308 	uint32_t dev_id; /**< Valid only when *dev_name* is NULL. */
309 	uint32_t n_queues;
310 	uint32_t queue_size;
311 	uint32_t session_pool_size;
312 };
313 
314 struct softnic_cryptodev {
315 	TAILQ_ENTRY(softnic_cryptodev) node;
316 	char name[NAME_SIZE];
317 	uint16_t dev_id;
318 	uint32_t n_queues;
319 	struct rte_mempool *mp_create;
320 	struct rte_mempool *mp_init;
321 };
322 
323 TAILQ_HEAD(softnic_cryptodev_list, softnic_cryptodev);
324 
325 /**
326  * Input port action
327  */
328 struct softnic_port_in_action_profile_params {
329 	uint64_t action_mask;
330 	struct rte_port_in_action_fltr_config fltr;
331 	struct rte_port_in_action_lb_config lb;
332 };
333 
334 struct softnic_port_in_action_profile {
335 	TAILQ_ENTRY(softnic_port_in_action_profile) node;
336 	char name[NAME_SIZE];
337 	struct softnic_port_in_action_profile_params params;
338 	struct rte_port_in_action_profile *ap;
339 };
340 
341 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
342 
343 /**
344  * Table action
345  */
346 struct softnic_table_action_profile_params {
347 	uint64_t action_mask;
348 	struct rte_table_action_common_config common;
349 	struct rte_table_action_lb_config lb;
350 	struct rte_table_action_mtr_config mtr;
351 	struct rte_table_action_tm_config tm;
352 	struct rte_table_action_encap_config encap;
353 	struct rte_table_action_nat_config nat;
354 	struct rte_table_action_ttl_config ttl;
355 	struct rte_table_action_stats_config stats;
356 	struct rte_table_action_sym_crypto_config sym_crypto;
357 };
358 
359 struct softnic_table_action_profile {
360 	TAILQ_ENTRY(softnic_table_action_profile) node;
361 	char name[NAME_SIZE];
362 	struct softnic_table_action_profile_params params;
363 	struct rte_table_action_profile *ap;
364 };
365 
366 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
367 
368 struct softnic_table_meter_profile {
369 	TAILQ_ENTRY(softnic_table_meter_profile) node;
370 	uint32_t meter_profile_id;
371 	struct rte_table_action_meter_profile profile;
372 };
373 
374 TAILQ_HEAD(softnic_table_meter_profile_list,
375 	softnic_table_meter_profile);
376 
377 /**
378  * Pipeline
379  */
380 struct pipeline_params {
381 	uint32_t timer_period_ms;
382 	uint32_t offset_port_id;
383 };
384 
385 enum softnic_port_in_type {
386 	PORT_IN_RXQ,
387 	PORT_IN_SWQ,
388 	PORT_IN_TMGR,
389 	PORT_IN_TAP,
390 	PORT_IN_SOURCE,
391 	PORT_IN_CRYPTODEV,
392 };
393 
394 struct softnic_port_in_params {
395 	/* Read */
396 	enum softnic_port_in_type type;
397 	char dev_name[NAME_SIZE];
398 	union {
399 		struct {
400 			uint16_t queue_id;
401 		} rxq;
402 
403 		struct {
404 			const char *mempool_name;
405 			uint32_t mtu;
406 		} tap;
407 
408 		struct {
409 			const char *mempool_name;
410 			const char *file_name;
411 			uint32_t n_bytes_per_pkt;
412 		} source;
413 
414 		struct {
415 			uint16_t queue_id;
416 			void *f_callback;
417 			void *arg_callback;
418 		} cryptodev;
419 	};
420 	uint32_t burst_size;
421 
422 	/* Action */
423 	char action_profile_name[NAME_SIZE];
424 };
425 
426 enum softnic_port_out_type {
427 	PORT_OUT_TXQ,
428 	PORT_OUT_SWQ,
429 	PORT_OUT_TMGR,
430 	PORT_OUT_TAP,
431 	PORT_OUT_SINK,
432 	PORT_OUT_CRYPTODEV,
433 };
434 
435 struct softnic_port_out_params {
436 	enum softnic_port_out_type type;
437 	char dev_name[NAME_SIZE];
438 	union {
439 		struct {
440 			uint16_t queue_id;
441 		} txq;
442 
443 		struct {
444 			const char *file_name;
445 			uint32_t max_n_pkts;
446 		} sink;
447 
448 		struct {
449 			uint16_t queue_id;
450 			uint32_t op_offset;
451 		} cryptodev;
452 	};
453 	uint32_t burst_size;
454 	int retry;
455 	uint32_t n_retries;
456 };
457 
458 enum softnic_table_type {
459 	TABLE_ACL,
460 	TABLE_ARRAY,
461 	TABLE_HASH,
462 	TABLE_LPM,
463 	TABLE_STUB,
464 };
465 
466 struct softnic_table_acl_params {
467 	uint32_t n_rules;
468 	uint32_t ip_header_offset;
469 	int ip_version;
470 };
471 
472 struct softnic_table_array_params {
473 	uint32_t n_keys;
474 	uint32_t key_offset;
475 };
476 
477 #ifndef TABLE_RULE_MATCH_SIZE_MAX
478 #define TABLE_RULE_MATCH_SIZE_MAX                          256
479 #endif
480 
481 struct softnic_table_hash_params {
482 	uint32_t n_keys;
483 	uint32_t key_offset;
484 	uint32_t key_size;
485 	uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
486 	uint32_t n_buckets;
487 	int extendable_bucket;
488 };
489 
490 struct softnic_table_lpm_params {
491 	uint32_t n_rules;
492 	uint32_t key_offset;
493 	uint32_t key_size;
494 };
495 
496 struct softnic_table_params {
497 	/* Match */
498 	enum softnic_table_type match_type;
499 	union {
500 		struct softnic_table_acl_params acl;
501 		struct softnic_table_array_params array;
502 		struct softnic_table_hash_params hash;
503 		struct softnic_table_lpm_params lpm;
504 	} match;
505 
506 	/* Action */
507 	char action_profile_name[NAME_SIZE];
508 };
509 
510 struct softnic_port_in {
511 	struct softnic_port_in_params params;
512 	struct softnic_port_in_action_profile *ap;
513 	struct rte_port_in_action *a;
514 };
515 
516 struct softnic_port_out {
517 	struct softnic_port_out_params params;
518 };
519 
520 struct softnic_table {
521 	struct softnic_table_params params;
522 	struct softnic_table_action_profile *ap;
523 	struct rte_table_action *a;
524 	struct flow_list flows;
525 	struct rte_table_action_dscp_table dscp_table;
526 	struct softnic_table_meter_profile_list meter_profiles;
527 };
528 
529 struct pipeline {
530 	TAILQ_ENTRY(pipeline) node;
531 	char name[NAME_SIZE];
532 
533 	struct rte_pipeline *p;
534 	struct pipeline_params params;
535 	struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
536 	struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
537 	struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
538 	uint32_t n_ports_in;
539 	uint32_t n_ports_out;
540 	uint32_t n_tables;
541 
542 	struct rte_ring *msgq_req;
543 	struct rte_ring *msgq_rsp;
544 	uint32_t timer_period_ms;
545 
546 	int enabled;
547 	uint32_t thread_id;
548 	uint32_t cpu_id;
549 };
550 
551 TAILQ_HEAD(pipeline_list, pipeline);
552 
553 /**
554  * Thread
555  */
556 #ifndef THREAD_PIPELINES_MAX
557 #define THREAD_PIPELINES_MAX                               256
558 #endif
559 
560 #ifndef THREAD_MSGQ_SIZE
561 #define THREAD_MSGQ_SIZE                                   64
562 #endif
563 
564 #ifndef THREAD_TIMER_PERIOD_MS
565 #define THREAD_TIMER_PERIOD_MS                             100
566 #endif
567 
568 /**
569  * Main thread: data plane thread context
570  */
571 struct softnic_thread {
572 	struct rte_ring *msgq_req;
573 	struct rte_ring *msgq_rsp;
574 
575 	uint32_t service_id;
576 };
577 
578 /**
579  * Data plane threads: context
580  */
581 #ifndef TABLE_RULE_ACTION_SIZE_MAX
582 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
583 #endif
584 
585 struct softnic_table_data {
586 	struct rte_table_action *a;
587 };
588 
589 struct pipeline_data {
590 	struct rte_pipeline *p;
591 	struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
592 	uint32_t n_tables;
593 
594 	struct rte_ring *msgq_req;
595 	struct rte_ring *msgq_rsp;
596 	uint64_t timer_period; /* Measured in CPU cycles. */
597 	uint64_t time_next;
598 
599 	uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
600 };
601 
602 struct softnic_thread_data {
603 	struct rte_pipeline *p[THREAD_PIPELINES_MAX];
604 	uint32_t n_pipelines;
605 
606 	struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
607 	struct rte_ring *msgq_req;
608 	struct rte_ring *msgq_rsp;
609 	uint64_t timer_period; /* Measured in CPU cycles. */
610 	uint64_t time_next;
611 	uint64_t time_next_min;
612 	uint64_t iter;
613 } __rte_cache_aligned;
614 
615 /**
616  * PMD Internals
617  */
618 struct pmd_internals {
619 	/** Params */
620 	struct pmd_params params;
621 
622 	struct {
623 		struct tm_internals tm; /**< Traffic Management */
624 	} soft;
625 
626 	struct flow_internals flow;
627 	struct mtr_internals mtr;
628 
629 	struct softnic_conn *conn;
630 	struct softnic_mempool_list mempool_list;
631 	struct softnic_swq_list swq_list;
632 	struct softnic_link_list link_list;
633 	struct softnic_tmgr_port_list tmgr_port_list;
634 	struct softnic_tap_list tap_list;
635 	struct softnic_cryptodev_list cryptodev_list;
636 	struct softnic_port_in_action_profile_list port_in_action_profile_list;
637 	struct softnic_table_action_profile_list table_action_profile_list;
638 	struct pipeline_list pipeline_list;
639 	struct softnic_thread thread[RTE_MAX_LCORE];
640 	struct softnic_thread_data thread_data[RTE_MAX_LCORE];
641 };
642 
643 static inline struct rte_eth_dev *
644 ETHDEV(struct pmd_internals *softnic)
645 {
646 	uint16_t port_id;
647 	int status;
648 
649 	if (softnic == NULL)
650 		return NULL;
651 
652 	status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
653 	if (status)
654 		return NULL;
655 
656 	return &rte_eth_devices[port_id];
657 }
658 
659 /**
660  * Ethdev Flow API
661  */
662 int
663 flow_attr_map_set(struct pmd_internals *softnic,
664 		uint32_t group_id,
665 		int ingress,
666 		const char *pipeline_name,
667 		uint32_t table_id);
668 
669 struct flow_attr_map *
670 flow_attr_map_get(struct pmd_internals *softnic,
671 		uint32_t group_id,
672 		int ingress);
673 
674 extern const struct rte_flow_ops pmd_flow_ops;
675 
676 /**
677  * Meter
678  */
679 int
680 softnic_mtr_init(struct pmd_internals *p);
681 
682 void
683 softnic_mtr_free(struct pmd_internals *p);
684 
685 struct softnic_mtr *
686 softnic_mtr_find(struct pmd_internals *p,
687 	uint32_t mtr_id);
688 
689 struct softnic_mtr_meter_profile *
690 softnic_mtr_meter_profile_find(struct pmd_internals *p,
691 	uint32_t meter_profile_id);
692 
693 struct softnic_mtr_meter_policy *
694 softnic_mtr_meter_policy_find(struct pmd_internals *p,
695 	uint32_t meter_policy_id);
696 
697 extern const struct rte_mtr_ops pmd_mtr_ops;
698 
699 /**
700  * MEMPOOL
701  */
702 int
703 softnic_mempool_init(struct pmd_internals *p);
704 
705 void
706 softnic_mempool_free(struct pmd_internals *p);
707 
708 struct softnic_mempool *
709 softnic_mempool_find(struct pmd_internals *p,
710 	const char *name);
711 
712 struct softnic_mempool *
713 softnic_mempool_create(struct pmd_internals *p,
714 	const char *name,
715 	struct softnic_mempool_params *params);
716 
717 /**
718  * SWQ
719  */
720 int
721 softnic_swq_init(struct pmd_internals *p);
722 
723 void
724 softnic_swq_free(struct pmd_internals *p);
725 
726 void
727 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
728 
729 struct softnic_swq *
730 softnic_swq_find(struct pmd_internals *p,
731 	const char *name);
732 
733 struct softnic_swq *
734 softnic_swq_create(struct pmd_internals *p,
735 	const char *name,
736 	struct softnic_swq_params *params);
737 
738 /**
739  * LINK
740  */
741 int
742 softnic_link_init(struct pmd_internals *p);
743 
744 void
745 softnic_link_free(struct pmd_internals *p);
746 
747 struct softnic_link *
748 softnic_link_find(struct pmd_internals *p,
749 	const char *name);
750 
751 struct softnic_link *
752 softnic_link_create(struct pmd_internals *p,
753 	const char *name,
754 	struct softnic_link_params *params);
755 
756 /**
757  * TMGR
758  */
759 int
760 softnic_tmgr_init(struct pmd_internals *p);
761 
762 void
763 softnic_tmgr_free(struct pmd_internals *p);
764 
765 struct softnic_tmgr_port *
766 softnic_tmgr_port_find(struct pmd_internals *p,
767 	const char *name);
768 
769 struct softnic_tmgr_port *
770 softnic_tmgr_port_create(struct pmd_internals *p,
771 	const char *name);
772 
773 void
774 tm_hierarchy_init(struct pmd_internals *p);
775 
776 void
777 tm_hierarchy_free(struct pmd_internals *p);
778 
779 static inline int
780 tm_used(struct rte_eth_dev *dev)
781 {
782 	struct pmd_internals *p = dev->data->dev_private;
783 
784 	return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
785 }
786 
787 extern const struct rte_tm_ops pmd_tm_ops;
788 
789 /**
790  * TAP
791  */
792 int
793 softnic_tap_init(struct pmd_internals *p);
794 
795 void
796 softnic_tap_free(struct pmd_internals *p);
797 
798 struct softnic_tap *
799 softnic_tap_find(struct pmd_internals *p,
800 	const char *name);
801 
802 struct softnic_tap *
803 softnic_tap_create(struct pmd_internals *p,
804 	const char *name);
805 
806 /**
807  * Sym Crypto
808  */
809 int
810 softnic_cryptodev_init(struct pmd_internals *p);
811 
812 void
813 softnic_cryptodev_free(struct pmd_internals *p);
814 
815 struct softnic_cryptodev *
816 softnic_cryptodev_find(struct pmd_internals *p,
817 	const char *name);
818 
819 struct softnic_cryptodev *
820 softnic_cryptodev_create(struct pmd_internals *p,
821 	const char *name,
822 	struct softnic_cryptodev_params *params);
823 
824 /**
825  * Input port action
826  */
827 int
828 softnic_port_in_action_profile_init(struct pmd_internals *p);
829 
830 void
831 softnic_port_in_action_profile_free(struct pmd_internals *p);
832 
833 struct softnic_port_in_action_profile *
834 softnic_port_in_action_profile_find(struct pmd_internals *p,
835 	const char *name);
836 
837 struct softnic_port_in_action_profile *
838 softnic_port_in_action_profile_create(struct pmd_internals *p,
839 	const char *name,
840 	struct softnic_port_in_action_profile_params *params);
841 
842 /**
843  * Table action
844  */
845 int
846 softnic_table_action_profile_init(struct pmd_internals *p);
847 
848 void
849 softnic_table_action_profile_free(struct pmd_internals *p);
850 
851 struct softnic_table_action_profile *
852 softnic_table_action_profile_find(struct pmd_internals *p,
853 	const char *name);
854 
855 struct softnic_table_action_profile *
856 softnic_table_action_profile_create(struct pmd_internals *p,
857 	const char *name,
858 	struct softnic_table_action_profile_params *params);
859 
860 /**
861  * Pipeline
862  */
863 int
864 softnic_pipeline_init(struct pmd_internals *p);
865 
866 void
867 softnic_pipeline_free(struct pmd_internals *p);
868 
869 void
870 softnic_pipeline_disable_all(struct pmd_internals *p);
871 
872 uint32_t
873 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
874 
875 struct pipeline *
876 softnic_pipeline_find(struct pmd_internals *p, const char *name);
877 
878 struct pipeline *
879 softnic_pipeline_create(struct pmd_internals *p,
880 	const char *name,
881 	struct pipeline_params *params);
882 
883 int
884 softnic_pipeline_port_in_create(struct pmd_internals *p,
885 	const char *pipeline_name,
886 	struct softnic_port_in_params *params,
887 	int enabled);
888 
889 int
890 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
891 	const char *pipeline_name,
892 	uint32_t port_id,
893 	uint32_t table_id);
894 
895 int
896 softnic_pipeline_port_out_create(struct pmd_internals *p,
897 	const char *pipeline_name,
898 	struct softnic_port_out_params *params);
899 
900 int
901 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
902 		const char *pipeline_name,
903 		const char *name,
904 		uint32_t *port_id);
905 
906 int
907 softnic_pipeline_table_create(struct pmd_internals *p,
908 	const char *pipeline_name,
909 	struct softnic_table_params *params);
910 
911 struct softnic_table_meter_profile *
912 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
913 	uint32_t meter_profile_id);
914 
915 struct softnic_table_rule_match_acl {
916 	int ip_version;
917 
918 	RTE_STD_C11
919 	union {
920 		struct {
921 			uint32_t sa;
922 			uint32_t da;
923 		} ipv4;
924 
925 		struct {
926 			uint8_t sa[16];
927 			uint8_t da[16];
928 		} ipv6;
929 	};
930 
931 	uint32_t sa_depth;
932 	uint32_t da_depth;
933 	uint16_t sp0;
934 	uint16_t sp1;
935 	uint16_t dp0;
936 	uint16_t dp1;
937 	uint8_t proto;
938 	uint8_t proto_mask;
939 	uint32_t priority;
940 };
941 
942 struct softnic_table_rule_match_array {
943 	uint32_t pos;
944 };
945 
946 struct softnic_table_rule_match_hash {
947 	uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
948 };
949 
950 struct softnic_table_rule_match_lpm {
951 	int ip_version;
952 
953 	RTE_STD_C11
954 	union {
955 		uint32_t ipv4;
956 		uint8_t ipv6[16];
957 	};
958 
959 	uint8_t depth;
960 };
961 
962 struct softnic_table_rule_match {
963 	enum softnic_table_type match_type;
964 
965 	union {
966 		struct softnic_table_rule_match_acl acl;
967 		struct softnic_table_rule_match_array array;
968 		struct softnic_table_rule_match_hash hash;
969 		struct softnic_table_rule_match_lpm lpm;
970 	} match;
971 };
972 
973 #ifndef SYM_CRYPTO_MAX_KEY_SIZE
974 #define SYM_CRYPTO_MAX_KEY_SIZE		(256)
975 #endif
976 struct softnic_table_rule_action {
977 	uint64_t action_mask;
978 	struct rte_table_action_fwd_params fwd;
979 	struct rte_table_action_lb_params lb;
980 	struct rte_table_action_mtr_params mtr;
981 	struct rte_table_action_tm_params tm;
982 	struct rte_table_action_encap_params encap;
983 	struct rte_table_action_nat_params nat;
984 	struct rte_table_action_ttl_params ttl;
985 	struct rte_table_action_stats_params stats;
986 	struct rte_table_action_time_params time;
987 	struct rte_table_action_tag_params tag;
988 	struct rte_table_action_decap_params decap;
989 	struct rte_table_action_sym_crypto_params sym_crypto;
990 	uint8_t sym_crypto_key[SYM_CRYPTO_MAX_KEY_SIZE];
991 };
992 
993 struct rte_flow {
994 	TAILQ_ENTRY(rte_flow) node;
995 	struct softnic_table_rule_match match;
996 	struct softnic_table_rule_action action;
997 	void *data;
998 	struct pipeline *pipeline;
999 	uint32_t table_id;
1000 };
1001 
1002 int
1003 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
1004 	const char *pipeline_name,
1005 	uint32_t port_id,
1006 	struct rte_pipeline_port_in_stats *stats,
1007 	int clear);
1008 
1009 int
1010 softnic_pipeline_port_in_enable(struct pmd_internals *p,
1011 	const char *pipeline_name,
1012 	uint32_t port_id);
1013 
1014 int
1015 softnic_pipeline_port_in_disable(struct pmd_internals *p,
1016 	const char *pipeline_name,
1017 	uint32_t port_id);
1018 
1019 int
1020 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
1021 	const char *pipeline_name,
1022 	uint32_t port_id,
1023 	struct rte_pipeline_port_out_stats *stats,
1024 	int clear);
1025 
1026 int
1027 softnic_pipeline_table_stats_read(struct pmd_internals *p,
1028 	const char *pipeline_name,
1029 	uint32_t table_id,
1030 	struct rte_pipeline_table_stats *stats,
1031 	int clear);
1032 
1033 int
1034 softnic_pipeline_table_rule_add(struct pmd_internals *p,
1035 	const char *pipeline_name,
1036 	uint32_t table_id,
1037 	struct softnic_table_rule_match *match,
1038 	struct softnic_table_rule_action *action,
1039 	void **data);
1040 
1041 int
1042 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
1043 	const char *pipeline_name,
1044 	uint32_t table_id,
1045 	struct softnic_table_rule_match *match,
1046 	struct softnic_table_rule_action *action,
1047 	void **data,
1048 	uint32_t *n_rules);
1049 
1050 int
1051 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
1052 	const char *pipeline_name,
1053 	uint32_t table_id,
1054 	struct softnic_table_rule_action *action,
1055 	void **data);
1056 
1057 int
1058 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
1059 	const char *pipeline_name,
1060 	uint32_t table_id,
1061 	struct softnic_table_rule_match *match);
1062 
1063 int
1064 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
1065 	const char *pipeline_name,
1066 	uint32_t table_id);
1067 
1068 int
1069 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
1070 	const char *pipeline_name,
1071 	uint32_t table_id,
1072 	void *data,
1073 	struct rte_table_action_stats_counters *stats,
1074 	int clear);
1075 
1076 int
1077 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
1078 	const char *pipeline_name,
1079 	uint32_t table_id,
1080 	uint32_t meter_profile_id,
1081 	struct rte_table_action_meter_profile *profile);
1082 
1083 int
1084 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
1085 	const char *pipeline_name,
1086 	uint32_t table_id,
1087 	uint32_t meter_profile_id);
1088 
1089 int
1090 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
1091 	const char *pipeline_name,
1092 	uint32_t table_id,
1093 	void *data,
1094 	uint32_t tc_mask,
1095 	struct rte_table_action_mtr_counters *stats,
1096 	int clear);
1097 
1098 int
1099 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1100 	const char *pipeline_name,
1101 	uint32_t table_id,
1102 	uint64_t dscp_mask,
1103 	struct rte_table_action_dscp_table *dscp_table);
1104 
1105 int
1106 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1107 	const char *pipeline_name,
1108 	uint32_t table_id,
1109 	void *data,
1110 	struct rte_table_action_ttl_counters *stats,
1111 	int clear);
1112 
1113 /**
1114  * Thread
1115  */
1116 int
1117 softnic_thread_init(struct pmd_internals *p);
1118 
1119 void
1120 softnic_thread_free(struct pmd_internals *p);
1121 
1122 int
1123 softnic_thread_pipeline_enable(struct pmd_internals *p,
1124 	uint32_t thread_id,
1125 	const char *pipeline_name);
1126 
1127 int
1128 softnic_thread_pipeline_disable(struct pmd_internals *p,
1129 	uint32_t thread_id,
1130 	const char *pipeline_name);
1131 
1132 /**
1133  * CLI
1134  */
1135 void
1136 softnic_cli_process(char *in,
1137 	char *out,
1138 	size_t out_size,
1139 	void *arg);
1140 
1141 int
1142 softnic_cli_script_process(struct pmd_internals *softnic,
1143 	const char *file_name,
1144 	size_t msg_in_len_max,
1145 	size_t msg_out_len_max);
1146 
1147 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */
1148