net/softnic: update meter profile
[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  * Input port action
283  */
284 struct softnic_port_in_action_profile_params {
285         uint64_t action_mask;
286         struct rte_port_in_action_fltr_config fltr;
287         struct rte_port_in_action_lb_config lb;
288 };
289
290 struct softnic_port_in_action_profile {
291         TAILQ_ENTRY(softnic_port_in_action_profile) node;
292         char name[NAME_SIZE];
293         struct softnic_port_in_action_profile_params params;
294         struct rte_port_in_action_profile *ap;
295 };
296
297 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
298
299 /**
300  * Table action
301  */
302 struct softnic_table_action_profile_params {
303         uint64_t action_mask;
304         struct rte_table_action_common_config common;
305         struct rte_table_action_lb_config lb;
306         struct rte_table_action_mtr_config mtr;
307         struct rte_table_action_tm_config tm;
308         struct rte_table_action_encap_config encap;
309         struct rte_table_action_nat_config nat;
310         struct rte_table_action_ttl_config ttl;
311         struct rte_table_action_stats_config stats;
312 };
313
314 struct softnic_table_action_profile {
315         TAILQ_ENTRY(softnic_table_action_profile) node;
316         char name[NAME_SIZE];
317         struct softnic_table_action_profile_params params;
318         struct rte_table_action_profile *ap;
319 };
320
321 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
322
323 struct softnic_table_meter_profile {
324         TAILQ_ENTRY(softnic_table_meter_profile) node;
325         uint32_t meter_profile_id;
326         struct rte_table_action_meter_profile profile;
327 };
328
329 TAILQ_HEAD(softnic_table_meter_profile_list,
330         softnic_table_meter_profile);
331
332 /**
333  * Pipeline
334  */
335 struct pipeline_params {
336         uint32_t timer_period_ms;
337         uint32_t offset_port_id;
338 };
339
340 enum softnic_port_in_type {
341         PORT_IN_RXQ,
342         PORT_IN_SWQ,
343         PORT_IN_TMGR,
344         PORT_IN_TAP,
345         PORT_IN_SOURCE,
346 };
347
348 struct softnic_port_in_params {
349         /* Read */
350         enum softnic_port_in_type type;
351         char dev_name[NAME_SIZE];
352         union {
353                 struct {
354                         uint16_t queue_id;
355                 } rxq;
356
357                 struct {
358                         const char *mempool_name;
359                         uint32_t mtu;
360                 } tap;
361
362                 struct {
363                         const char *mempool_name;
364                         const char *file_name;
365                         uint32_t n_bytes_per_pkt;
366                 } source;
367         };
368         uint32_t burst_size;
369
370         /* Action */
371         char action_profile_name[NAME_SIZE];
372 };
373
374 enum softnic_port_out_type {
375         PORT_OUT_TXQ,
376         PORT_OUT_SWQ,
377         PORT_OUT_TMGR,
378         PORT_OUT_TAP,
379         PORT_OUT_SINK,
380 };
381
382 struct softnic_port_out_params {
383         enum softnic_port_out_type type;
384         char dev_name[NAME_SIZE];
385         union {
386                 struct {
387                         uint16_t queue_id;
388                 } txq;
389
390                 struct {
391                         const char *file_name;
392                         uint32_t max_n_pkts;
393                 } sink;
394         };
395         uint32_t burst_size;
396         int retry;
397         uint32_t n_retries;
398 };
399
400 enum softnic_table_type {
401         TABLE_ACL,
402         TABLE_ARRAY,
403         TABLE_HASH,
404         TABLE_LPM,
405         TABLE_STUB,
406 };
407
408 struct softnic_table_acl_params {
409         uint32_t n_rules;
410         uint32_t ip_header_offset;
411         int ip_version;
412 };
413
414 struct softnic_table_array_params {
415         uint32_t n_keys;
416         uint32_t key_offset;
417 };
418
419 #ifndef TABLE_RULE_MATCH_SIZE_MAX
420 #define TABLE_RULE_MATCH_SIZE_MAX                          256
421 #endif
422
423 struct softnic_table_hash_params {
424         uint32_t n_keys;
425         uint32_t key_offset;
426         uint32_t key_size;
427         uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
428         uint32_t n_buckets;
429         int extendable_bucket;
430 };
431
432 struct softnic_table_lpm_params {
433         uint32_t n_rules;
434         uint32_t key_offset;
435         uint32_t key_size;
436 };
437
438 struct softnic_table_params {
439         /* Match */
440         enum softnic_table_type match_type;
441         union {
442                 struct softnic_table_acl_params acl;
443                 struct softnic_table_array_params array;
444                 struct softnic_table_hash_params hash;
445                 struct softnic_table_lpm_params lpm;
446         } match;
447
448         /* Action */
449         char action_profile_name[NAME_SIZE];
450 };
451
452 struct softnic_port_in {
453         struct softnic_port_in_params params;
454         struct softnic_port_in_action_profile *ap;
455         struct rte_port_in_action *a;
456 };
457
458 struct softnic_port_out {
459         struct softnic_port_out_params params;
460 };
461
462 struct softnic_table {
463         struct softnic_table_params params;
464         struct softnic_table_action_profile *ap;
465         struct rte_table_action *a;
466         struct flow_list flows;
467         struct softnic_table_meter_profile_list meter_profiles;
468 };
469
470 struct pipeline {
471         TAILQ_ENTRY(pipeline) node;
472         char name[NAME_SIZE];
473
474         struct rte_pipeline *p;
475         struct pipeline_params params;
476         struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
477         struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
478         struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
479         uint32_t n_ports_in;
480         uint32_t n_ports_out;
481         uint32_t n_tables;
482
483         struct rte_ring *msgq_req;
484         struct rte_ring *msgq_rsp;
485         uint32_t timer_period_ms;
486
487         int enabled;
488         uint32_t thread_id;
489         uint32_t cpu_id;
490 };
491
492 TAILQ_HEAD(pipeline_list, pipeline);
493
494 /**
495  * Thread
496  */
497 #ifndef THREAD_PIPELINES_MAX
498 #define THREAD_PIPELINES_MAX                               256
499 #endif
500
501 #ifndef THREAD_MSGQ_SIZE
502 #define THREAD_MSGQ_SIZE                                   64
503 #endif
504
505 #ifndef THREAD_TIMER_PERIOD_MS
506 #define THREAD_TIMER_PERIOD_MS                             100
507 #endif
508
509 /**
510  * Master thead: data plane thread context
511  */
512 struct softnic_thread {
513         struct rte_ring *msgq_req;
514         struct rte_ring *msgq_rsp;
515
516         uint32_t enabled;
517 };
518
519 /**
520  * Data plane threads: context
521  */
522 #ifndef TABLE_RULE_ACTION_SIZE_MAX
523 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
524 #endif
525
526 struct softnic_table_data {
527         struct rte_table_action *a;
528 };
529
530 struct pipeline_data {
531         struct rte_pipeline *p;
532         struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
533         uint32_t n_tables;
534
535         struct rte_ring *msgq_req;
536         struct rte_ring *msgq_rsp;
537         uint64_t timer_period; /* Measured in CPU cycles. */
538         uint64_t time_next;
539
540         uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
541 };
542
543 struct softnic_thread_data {
544         struct rte_pipeline *p[THREAD_PIPELINES_MAX];
545         uint32_t n_pipelines;
546
547         struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
548         struct rte_ring *msgq_req;
549         struct rte_ring *msgq_rsp;
550         uint64_t timer_period; /* Measured in CPU cycles. */
551         uint64_t time_next;
552         uint64_t time_next_min;
553         uint64_t iter;
554 } __rte_cache_aligned;
555
556 /**
557  * PMD Internals
558  */
559 struct pmd_internals {
560         /** Params */
561         struct pmd_params params;
562
563         struct {
564                 struct tm_internals tm; /**< Traffic Management */
565         } soft;
566
567         struct flow_internals flow;
568         struct mtr_internals mtr;
569
570         struct softnic_conn *conn;
571         struct softnic_mempool_list mempool_list;
572         struct softnic_swq_list swq_list;
573         struct softnic_link_list link_list;
574         struct softnic_tmgr_port_list tmgr_port_list;
575         struct softnic_tap_list tap_list;
576         struct softnic_port_in_action_profile_list port_in_action_profile_list;
577         struct softnic_table_action_profile_list table_action_profile_list;
578         struct pipeline_list pipeline_list;
579         struct softnic_thread thread[RTE_MAX_LCORE];
580         struct softnic_thread_data thread_data[RTE_MAX_LCORE];
581 };
582
583 static inline struct rte_eth_dev *
584 ETHDEV(struct pmd_internals *softnic)
585 {
586         uint16_t port_id;
587         int status;
588
589         if (softnic == NULL)
590                 return NULL;
591
592         status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
593         if (status)
594                 return NULL;
595
596         return &rte_eth_devices[port_id];
597 }
598
599 /**
600  * Ethdev Flow API
601  */
602 int
603 flow_attr_map_set(struct pmd_internals *softnic,
604                 uint32_t group_id,
605                 int ingress,
606                 const char *pipeline_name,
607                 uint32_t table_id);
608
609 struct flow_attr_map *
610 flow_attr_map_get(struct pmd_internals *softnic,
611                 uint32_t group_id,
612                 int ingress);
613
614 extern const struct rte_flow_ops pmd_flow_ops;
615
616 /**
617  * Meter
618  */
619 int
620 softnic_mtr_init(struct pmd_internals *p);
621
622 void
623 softnic_mtr_free(struct pmd_internals *p);
624
625 struct softnic_mtr *
626 softnic_mtr_find(struct pmd_internals *p,
627         uint32_t mtr_id);
628
629 struct softnic_mtr_meter_profile *
630 softnic_mtr_meter_profile_find(struct pmd_internals *p,
631         uint32_t meter_profile_id);
632
633 extern const struct rte_mtr_ops pmd_mtr_ops;
634
635 /**
636  * MEMPOOL
637  */
638 int
639 softnic_mempool_init(struct pmd_internals *p);
640
641 void
642 softnic_mempool_free(struct pmd_internals *p);
643
644 struct softnic_mempool *
645 softnic_mempool_find(struct pmd_internals *p,
646         const char *name);
647
648 struct softnic_mempool *
649 softnic_mempool_create(struct pmd_internals *p,
650         const char *name,
651         struct softnic_mempool_params *params);
652
653 /**
654  * SWQ
655  */
656 int
657 softnic_swq_init(struct pmd_internals *p);
658
659 void
660 softnic_swq_free(struct pmd_internals *p);
661
662 void
663 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
664
665 struct softnic_swq *
666 softnic_swq_find(struct pmd_internals *p,
667         const char *name);
668
669 struct softnic_swq *
670 softnic_swq_create(struct pmd_internals *p,
671         const char *name,
672         struct softnic_swq_params *params);
673
674 /**
675  * LINK
676  */
677 int
678 softnic_link_init(struct pmd_internals *p);
679
680 void
681 softnic_link_free(struct pmd_internals *p);
682
683 struct softnic_link *
684 softnic_link_find(struct pmd_internals *p,
685         const char *name);
686
687 struct softnic_link *
688 softnic_link_create(struct pmd_internals *p,
689         const char *name,
690         struct softnic_link_params *params);
691
692 /**
693  * TMGR
694  */
695 int
696 softnic_tmgr_init(struct pmd_internals *p);
697
698 void
699 softnic_tmgr_free(struct pmd_internals *p);
700
701 struct softnic_tmgr_port *
702 softnic_tmgr_port_find(struct pmd_internals *p,
703         const char *name);
704
705 struct softnic_tmgr_port *
706 softnic_tmgr_port_create(struct pmd_internals *p,
707         const char *name);
708
709 void
710 tm_hierarchy_init(struct pmd_internals *p);
711
712 void
713 tm_hierarchy_free(struct pmd_internals *p);
714
715 static inline int
716 tm_used(struct rte_eth_dev *dev)
717 {
718         struct pmd_internals *p = dev->data->dev_private;
719
720         return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
721 }
722
723 extern const struct rte_tm_ops pmd_tm_ops;
724
725 /**
726  * TAP
727  */
728 int
729 softnic_tap_init(struct pmd_internals *p);
730
731 void
732 softnic_tap_free(struct pmd_internals *p);
733
734 struct softnic_tap *
735 softnic_tap_find(struct pmd_internals *p,
736         const char *name);
737
738 struct softnic_tap *
739 softnic_tap_create(struct pmd_internals *p,
740         const char *name);
741
742 /**
743  * Input port action
744  */
745 int
746 softnic_port_in_action_profile_init(struct pmd_internals *p);
747
748 void
749 softnic_port_in_action_profile_free(struct pmd_internals *p);
750
751 struct softnic_port_in_action_profile *
752 softnic_port_in_action_profile_find(struct pmd_internals *p,
753         const char *name);
754
755 struct softnic_port_in_action_profile *
756 softnic_port_in_action_profile_create(struct pmd_internals *p,
757         const char *name,
758         struct softnic_port_in_action_profile_params *params);
759
760 /**
761  * Table action
762  */
763 int
764 softnic_table_action_profile_init(struct pmd_internals *p);
765
766 void
767 softnic_table_action_profile_free(struct pmd_internals *p);
768
769 struct softnic_table_action_profile *
770 softnic_table_action_profile_find(struct pmd_internals *p,
771         const char *name);
772
773 struct softnic_table_action_profile *
774 softnic_table_action_profile_create(struct pmd_internals *p,
775         const char *name,
776         struct softnic_table_action_profile_params *params);
777
778 /**
779  * Pipeline
780  */
781 int
782 softnic_pipeline_init(struct pmd_internals *p);
783
784 void
785 softnic_pipeline_free(struct pmd_internals *p);
786
787 void
788 softnic_pipeline_disable_all(struct pmd_internals *p);
789
790 struct pipeline *
791 softnic_pipeline_find(struct pmd_internals *p, const char *name);
792
793 struct pipeline *
794 softnic_pipeline_create(struct pmd_internals *p,
795         const char *name,
796         struct pipeline_params *params);
797
798 int
799 softnic_pipeline_port_in_create(struct pmd_internals *p,
800         const char *pipeline_name,
801         struct softnic_port_in_params *params,
802         int enabled);
803
804 int
805 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
806         const char *pipeline_name,
807         uint32_t port_id,
808         uint32_t table_id);
809
810 int
811 softnic_pipeline_port_out_create(struct pmd_internals *p,
812         const char *pipeline_name,
813         struct softnic_port_out_params *params);
814
815 int
816 softnic_pipeline_port_out_find(struct pmd_internals *softnic,
817                 const char *pipeline_name,
818                 const char *name,
819                 uint32_t *port_id);
820
821 int
822 softnic_pipeline_table_create(struct pmd_internals *p,
823         const char *pipeline_name,
824         struct softnic_table_params *params);
825
826 struct softnic_table_meter_profile *
827 softnic_pipeline_table_meter_profile_find(struct softnic_table *table,
828         uint32_t meter_profile_id);
829
830 struct softnic_table_rule_match_acl {
831         int ip_version;
832
833         RTE_STD_C11
834         union {
835                 struct {
836                         uint32_t sa;
837                         uint32_t da;
838                 } ipv4;
839
840                 struct {
841                         uint8_t sa[16];
842                         uint8_t da[16];
843                 } ipv6;
844         };
845
846         uint32_t sa_depth;
847         uint32_t da_depth;
848         uint16_t sp0;
849         uint16_t sp1;
850         uint16_t dp0;
851         uint16_t dp1;
852         uint8_t proto;
853         uint8_t proto_mask;
854         uint32_t priority;
855 };
856
857 struct softnic_table_rule_match_array {
858         uint32_t pos;
859 };
860
861 struct softnic_table_rule_match_hash {
862         uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
863 };
864
865 struct softnic_table_rule_match_lpm {
866         int ip_version;
867
868         RTE_STD_C11
869         union {
870                 uint32_t ipv4;
871                 uint8_t ipv6[16];
872         };
873
874         uint8_t depth;
875 };
876
877 struct softnic_table_rule_match {
878         enum softnic_table_type match_type;
879
880         union {
881                 struct softnic_table_rule_match_acl acl;
882                 struct softnic_table_rule_match_array array;
883                 struct softnic_table_rule_match_hash hash;
884                 struct softnic_table_rule_match_lpm lpm;
885         } match;
886 };
887
888 struct softnic_table_rule_action {
889         uint64_t action_mask;
890         struct rte_table_action_fwd_params fwd;
891         struct rte_table_action_lb_params lb;
892         struct rte_table_action_mtr_params mtr;
893         struct rte_table_action_tm_params tm;
894         struct rte_table_action_encap_params encap;
895         struct rte_table_action_nat_params nat;
896         struct rte_table_action_ttl_params ttl;
897         struct rte_table_action_stats_params stats;
898         struct rte_table_action_time_params time;
899 };
900
901 struct rte_flow {
902         TAILQ_ENTRY(rte_flow) node;
903         struct softnic_table_rule_match match;
904         struct softnic_table_rule_action action;
905         void *data;
906         struct pipeline *pipeline;
907         uint32_t table_id;
908 };
909
910 int
911 softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
912         const char *pipeline_name,
913         uint32_t port_id,
914         struct rte_pipeline_port_in_stats *stats,
915         int clear);
916
917 int
918 softnic_pipeline_port_in_enable(struct pmd_internals *p,
919         const char *pipeline_name,
920         uint32_t port_id);
921
922 int
923 softnic_pipeline_port_in_disable(struct pmd_internals *p,
924         const char *pipeline_name,
925         uint32_t port_id);
926
927 int
928 softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
929         const char *pipeline_name,
930         uint32_t port_id,
931         struct rte_pipeline_port_out_stats *stats,
932         int clear);
933
934 int
935 softnic_pipeline_table_stats_read(struct pmd_internals *p,
936         const char *pipeline_name,
937         uint32_t table_id,
938         struct rte_pipeline_table_stats *stats,
939         int clear);
940
941 int
942 softnic_pipeline_table_rule_add(struct pmd_internals *p,
943         const char *pipeline_name,
944         uint32_t table_id,
945         struct softnic_table_rule_match *match,
946         struct softnic_table_rule_action *action,
947         void **data);
948
949 int
950 softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
951         const char *pipeline_name,
952         uint32_t table_id,
953         struct softnic_table_rule_match *match,
954         struct softnic_table_rule_action *action,
955         void **data,
956         uint32_t *n_rules);
957
958 int
959 softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
960         const char *pipeline_name,
961         uint32_t table_id,
962         struct softnic_table_rule_action *action,
963         void **data);
964
965 int
966 softnic_pipeline_table_rule_delete(struct pmd_internals *p,
967         const char *pipeline_name,
968         uint32_t table_id,
969         struct softnic_table_rule_match *match);
970
971 int
972 softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
973         const char *pipeline_name,
974         uint32_t table_id);
975
976 int
977 softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
978         const char *pipeline_name,
979         uint32_t table_id,
980         void *data,
981         struct rte_table_action_stats_counters *stats,
982         int clear);
983
984 int
985 softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
986         const char *pipeline_name,
987         uint32_t table_id,
988         uint32_t meter_profile_id,
989         struct rte_table_action_meter_profile *profile);
990
991 int
992 softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
993         const char *pipeline_name,
994         uint32_t table_id,
995         uint32_t meter_profile_id);
996
997 int
998 softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
999         const char *pipeline_name,
1000         uint32_t table_id,
1001         void *data,
1002         uint32_t tc_mask,
1003         struct rte_table_action_mtr_counters *stats,
1004         int clear);
1005
1006 int
1007 softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
1008         const char *pipeline_name,
1009         uint32_t table_id,
1010         uint64_t dscp_mask,
1011         struct rte_table_action_dscp_table *dscp_table);
1012
1013 int
1014 softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
1015         const char *pipeline_name,
1016         uint32_t table_id,
1017         void *data,
1018         struct rte_table_action_ttl_counters *stats,
1019         int clear);
1020
1021 /**
1022  * Thread
1023  */
1024 int
1025 softnic_thread_init(struct pmd_internals *p);
1026
1027 void
1028 softnic_thread_free(struct pmd_internals *p);
1029
1030 int
1031 softnic_thread_pipeline_enable(struct pmd_internals *p,
1032         uint32_t thread_id,
1033         const char *pipeline_name);
1034
1035 int
1036 softnic_thread_pipeline_disable(struct pmd_internals *p,
1037         uint32_t thread_id,
1038         const char *pipeline_name);
1039
1040 /**
1041  * CLI
1042  */
1043 void
1044 softnic_cli_process(char *in,
1045         char *out,
1046         size_t out_size,
1047         void *arg);
1048
1049 int
1050 softnic_cli_script_process(struct pmd_internals *softnic,
1051         const char *file_name,
1052         size_t msg_in_len_max,
1053         size_t msg_out_len_max);
1054
1055 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */