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