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