52da1ae715a386cdf2827dd0577c441885a4e4f3
[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_driver.h>
22 #include <rte_tm_driver.h>
23
24 #include "rte_eth_softnic.h"
25
26 #define NAME_SIZE                                            64
27
28 /**
29  * PMD Parameters
30  */
31
32 struct pmd_params {
33         const char *name;
34         const char *firmware;
35         uint32_t cpu_id;
36
37         /** Traffic Management (TM) */
38         struct {
39                 uint32_t n_queues; /**< Number of queues */
40                 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
41         } tm;
42 };
43
44 /**
45  * MEMPOOL
46  */
47 struct softnic_mempool_params {
48         uint32_t buffer_size;
49         uint32_t pool_size;
50         uint32_t cache_size;
51 };
52
53 struct softnic_mempool {
54         TAILQ_ENTRY(softnic_mempool) node;
55         char name[NAME_SIZE];
56         struct rte_mempool *m;
57         uint32_t buffer_size;
58 };
59
60 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
61
62 /**
63  * SWQ
64  */
65 struct softnic_swq_params {
66         uint32_t size;
67 };
68
69 struct softnic_swq {
70         TAILQ_ENTRY(softnic_swq) node;
71         char name[NAME_SIZE];
72         struct rte_ring *r;
73 };
74
75 TAILQ_HEAD(softnic_swq_list, softnic_swq);
76
77 /**
78  * LINK
79  */
80 struct softnic_link_params {
81         const char *dev_name;
82         uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
83 };
84
85 struct softnic_link {
86         TAILQ_ENTRY(softnic_link) node;
87         char name[NAME_SIZE];
88         uint16_t port_id;
89         uint32_t n_rxq;
90         uint32_t n_txq;
91 };
92
93 TAILQ_HEAD(softnic_link_list, softnic_link);
94
95 /**
96  * TMGR
97  */
98
99 #ifndef TM_MAX_SUBPORTS
100 #define TM_MAX_SUBPORTS                                 8
101 #endif
102
103 #ifndef TM_MAX_PIPES_PER_SUBPORT
104 #define TM_MAX_PIPES_PER_SUBPORT                        4096
105 #endif
106
107 struct tm_params {
108         struct rte_sched_port_params port_params;
109
110         struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
111
112         struct rte_sched_pipe_params
113                 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
114         uint32_t n_pipe_profiles;
115         uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
116 };
117
118 /* TM Levels */
119 enum tm_node_level {
120         TM_NODE_LEVEL_PORT = 0,
121         TM_NODE_LEVEL_SUBPORT,
122         TM_NODE_LEVEL_PIPE,
123         TM_NODE_LEVEL_TC,
124         TM_NODE_LEVEL_QUEUE,
125         TM_NODE_LEVEL_MAX,
126 };
127
128 /* TM Shaper Profile */
129 struct tm_shaper_profile {
130         TAILQ_ENTRY(tm_shaper_profile) node;
131         uint32_t shaper_profile_id;
132         uint32_t n_users;
133         struct rte_tm_shaper_params params;
134 };
135
136 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
137
138 /* TM Shared Shaper */
139 struct tm_shared_shaper {
140         TAILQ_ENTRY(tm_shared_shaper) node;
141         uint32_t shared_shaper_id;
142         uint32_t n_users;
143         uint32_t shaper_profile_id;
144 };
145
146 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
147
148 /* TM WRED Profile */
149 struct tm_wred_profile {
150         TAILQ_ENTRY(tm_wred_profile) node;
151         uint32_t wred_profile_id;
152         uint32_t n_users;
153         struct rte_tm_wred_params params;
154 };
155
156 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
157
158 /* TM Node */
159 struct tm_node {
160         TAILQ_ENTRY(tm_node) node;
161         uint32_t node_id;
162         uint32_t parent_node_id;
163         uint32_t priority;
164         uint32_t weight;
165         uint32_t level;
166         struct tm_node *parent_node;
167         struct tm_shaper_profile *shaper_profile;
168         struct tm_wred_profile *wred_profile;
169         struct rte_tm_node_params params;
170         struct rte_tm_node_stats stats;
171         uint32_t n_children;
172 };
173
174 TAILQ_HEAD(tm_node_list, tm_node);
175
176 /* TM Hierarchy Specification */
177 struct tm_hierarchy {
178         struct tm_shaper_profile_list shaper_profiles;
179         struct tm_shared_shaper_list shared_shapers;
180         struct tm_wred_profile_list wred_profiles;
181         struct tm_node_list nodes;
182
183         uint32_t n_shaper_profiles;
184         uint32_t n_shared_shapers;
185         uint32_t n_wred_profiles;
186         uint32_t n_nodes;
187
188         uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
189 };
190
191 struct tm_internals {
192         /** Hierarchy specification
193          *
194          *     -Hierarchy is unfrozen at init and when port is stopped.
195          *     -Hierarchy is frozen on successful hierarchy commit.
196          *     -Run-time hierarchy changes are not allowed, therefore it makes
197          *      sense to keep the hierarchy frozen after the port is started.
198          */
199         struct tm_hierarchy h;
200         int hierarchy_frozen;
201
202         /** Blueprints */
203         struct tm_params params;
204         struct rte_sched_port *sched;
205 };
206
207 struct softnic_tmgr_port {
208         TAILQ_ENTRY(softnic_tmgr_port) node;
209         char name[NAME_SIZE];
210         struct rte_sched_port *s;
211 };
212
213 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
214
215 /**
216  * TAP
217  */
218 struct softnic_tap {
219         TAILQ_ENTRY(softnic_tap) node;
220         char name[NAME_SIZE];
221         int fd;
222 };
223
224 TAILQ_HEAD(softnic_tap_list, softnic_tap);
225
226 /**
227  * Input port action
228  */
229 struct softnic_port_in_action_profile_params {
230         uint64_t action_mask;
231         struct rte_port_in_action_fltr_config fltr;
232         struct rte_port_in_action_lb_config lb;
233 };
234
235 struct softnic_port_in_action_profile {
236         TAILQ_ENTRY(softnic_port_in_action_profile) node;
237         char name[NAME_SIZE];
238         struct softnic_port_in_action_profile_params params;
239         struct rte_port_in_action_profile *ap;
240 };
241
242 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
243
244 /**
245  * Table action
246  */
247 struct softnic_table_action_profile_params {
248         uint64_t action_mask;
249         struct rte_table_action_common_config common;
250         struct rte_table_action_lb_config lb;
251         struct rte_table_action_mtr_config mtr;
252         struct rte_table_action_tm_config tm;
253         struct rte_table_action_encap_config encap;
254         struct rte_table_action_nat_config nat;
255         struct rte_table_action_ttl_config ttl;
256         struct rte_table_action_stats_config stats;
257 };
258
259 struct softnic_table_action_profile {
260         TAILQ_ENTRY(softnic_table_action_profile) node;
261         char name[NAME_SIZE];
262         struct softnic_table_action_profile_params params;
263         struct rte_table_action_profile *ap;
264 };
265
266 TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
267
268 /**
269  * Pipeline
270  */
271 struct pipeline_params {
272         uint32_t timer_period_ms;
273         uint32_t offset_port_id;
274 };
275
276 enum softnic_port_in_type {
277         PORT_IN_RXQ,
278         PORT_IN_SWQ,
279         PORT_IN_TMGR,
280         PORT_IN_TAP,
281         PORT_IN_SOURCE,
282 };
283
284 struct softnic_port_in_params {
285         /* Read */
286         enum softnic_port_in_type type;
287         const char *dev_name;
288         union {
289                 struct {
290                         uint16_t queue_id;
291                 } rxq;
292
293                 struct {
294                         const char *mempool_name;
295                         uint32_t mtu;
296                 } tap;
297
298                 struct {
299                         const char *mempool_name;
300                         const char *file_name;
301                         uint32_t n_bytes_per_pkt;
302                 } source;
303         };
304         uint32_t burst_size;
305
306         /* Action */
307         const char *action_profile_name;
308 };
309
310 enum softnic_port_out_type {
311         PORT_OUT_TXQ,
312         PORT_OUT_SWQ,
313         PORT_OUT_TMGR,
314         PORT_OUT_TAP,
315         PORT_OUT_SINK,
316 };
317
318 struct softnic_port_out_params {
319         enum softnic_port_out_type type;
320         const char *dev_name;
321         union {
322                 struct {
323                         uint16_t queue_id;
324                 } txq;
325
326                 struct {
327                         const char *file_name;
328                         uint32_t max_n_pkts;
329                 } sink;
330         };
331         uint32_t burst_size;
332         int retry;
333         uint32_t n_retries;
334 };
335
336 enum softnic_table_type {
337         TABLE_ACL,
338         TABLE_ARRAY,
339         TABLE_HASH,
340         TABLE_LPM,
341         TABLE_STUB,
342 };
343
344 struct softnic_table_acl_params {
345         uint32_t n_rules;
346         uint32_t ip_header_offset;
347         int ip_version;
348 };
349
350 struct softnic_table_array_params {
351         uint32_t n_keys;
352         uint32_t key_offset;
353 };
354
355 struct softnic_table_hash_params {
356         uint32_t n_keys;
357         uint32_t key_offset;
358         uint32_t key_size;
359         uint8_t *key_mask;
360         uint32_t n_buckets;
361         int extendable_bucket;
362 };
363
364 struct softnic_table_lpm_params {
365         uint32_t n_rules;
366         uint32_t key_offset;
367         uint32_t key_size;
368 };
369
370 struct softnic_table_params {
371         /* Match */
372         enum softnic_table_type match_type;
373         union {
374                 struct softnic_table_acl_params acl;
375                 struct softnic_table_array_params array;
376                 struct softnic_table_hash_params hash;
377                 struct softnic_table_lpm_params lpm;
378         } match;
379
380         /* Action */
381         const char *action_profile_name;
382 };
383
384 struct softnic_port_in {
385         struct softnic_port_in_params params;
386         struct softnic_port_in_action_profile *ap;
387         struct rte_port_in_action *a;
388 };
389
390 struct softnic_table {
391         struct softnic_table_params params;
392         struct softnic_table_action_profile *ap;
393         struct rte_table_action *a;
394 };
395
396 struct pipeline {
397         TAILQ_ENTRY(pipeline) node;
398         char name[NAME_SIZE];
399
400         struct rte_pipeline *p;
401         struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
402         struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
403         uint32_t n_ports_in;
404         uint32_t n_ports_out;
405         uint32_t n_tables;
406
407         struct rte_ring *msgq_req;
408         struct rte_ring *msgq_rsp;
409         uint32_t timer_period_ms;
410
411         int enabled;
412         uint32_t thread_id;
413         uint32_t cpu_id;
414 };
415
416 TAILQ_HEAD(pipeline_list, pipeline);
417
418 #ifndef TABLE_RULE_ACTION_SIZE_MAX
419 #define TABLE_RULE_ACTION_SIZE_MAX                         2048
420 #endif
421
422 /**
423  * PMD Internals
424  */
425 struct pmd_internals {
426         /** Params */
427         struct pmd_params params;
428
429         struct {
430                 struct tm_internals tm; /**< Traffic Management */
431         } soft;
432
433         struct softnic_mempool_list mempool_list;
434         struct softnic_swq_list swq_list;
435         struct softnic_link_list link_list;
436         struct softnic_tmgr_port_list tmgr_port_list;
437         struct softnic_tap_list tap_list;
438         struct softnic_port_in_action_profile_list port_in_action_profile_list;
439         struct softnic_table_action_profile_list table_action_profile_list;
440         struct pipeline_list pipeline_list;
441 };
442
443 /**
444  * MEMPOOL
445  */
446 int
447 softnic_mempool_init(struct pmd_internals *p);
448
449 void
450 softnic_mempool_free(struct pmd_internals *p);
451
452 struct softnic_mempool *
453 softnic_mempool_find(struct pmd_internals *p,
454         const char *name);
455
456 struct softnic_mempool *
457 softnic_mempool_create(struct pmd_internals *p,
458         const char *name,
459         struct softnic_mempool_params *params);
460
461 /**
462  * SWQ
463  */
464 int
465 softnic_swq_init(struct pmd_internals *p);
466
467 void
468 softnic_swq_free(struct pmd_internals *p);
469
470 struct softnic_swq *
471 softnic_swq_find(struct pmd_internals *p,
472         const char *name);
473
474 struct softnic_swq *
475 softnic_swq_create(struct pmd_internals *p,
476         const char *name,
477         struct softnic_swq_params *params);
478
479 /**
480  * LINK
481  */
482 int
483 softnic_link_init(struct pmd_internals *p);
484
485 void
486 softnic_link_free(struct pmd_internals *p);
487
488 struct softnic_link *
489 softnic_link_find(struct pmd_internals *p,
490         const char *name);
491
492 struct softnic_link *
493 softnic_link_create(struct pmd_internals *p,
494         const char *name,
495         struct softnic_link_params *params);
496
497 /**
498  * TMGR
499  */
500 int
501 softnic_tmgr_init(struct pmd_internals *p);
502
503 void
504 softnic_tmgr_free(struct pmd_internals *p);
505
506 struct softnic_tmgr_port *
507 softnic_tmgr_port_find(struct pmd_internals *p,
508         const char *name);
509
510 struct softnic_tmgr_port *
511 softnic_tmgr_port_create(struct pmd_internals *p,
512         const char *name,
513         struct rte_sched_port *sched);
514
515 int
516 tm_init(struct pmd_internals *p);
517
518 void
519 tm_free(struct pmd_internals *p);
520
521 int
522 tm_start(struct pmd_internals *p);
523
524 void
525 tm_stop(struct pmd_internals *p);
526
527 static inline int
528 tm_used(struct rte_eth_dev *dev)
529 {
530         struct pmd_internals *p = dev->data->dev_private;
531
532         return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
533 }
534
535 extern const struct rte_tm_ops pmd_tm_ops;
536
537 /**
538  * TAP
539  */
540 int
541 softnic_tap_init(struct pmd_internals *p);
542
543 void
544 softnic_tap_free(struct pmd_internals *p);
545
546 struct softnic_tap *
547 softnic_tap_find(struct pmd_internals *p,
548         const char *name);
549
550 struct softnic_tap *
551 softnic_tap_create(struct pmd_internals *p,
552         const char *name);
553
554 /**
555  * Input port action
556  */
557 int
558 softnic_port_in_action_profile_init(struct pmd_internals *p);
559
560 void
561 softnic_port_in_action_profile_free(struct pmd_internals *p);
562
563 struct softnic_port_in_action_profile *
564 softnic_port_in_action_profile_find(struct pmd_internals *p,
565         const char *name);
566
567 struct softnic_port_in_action_profile *
568 softnic_port_in_action_profile_create(struct pmd_internals *p,
569         const char *name,
570         struct softnic_port_in_action_profile_params *params);
571
572 /**
573  * Table action
574  */
575 int
576 softnic_table_action_profile_init(struct pmd_internals *p);
577
578 void
579 softnic_table_action_profile_free(struct pmd_internals *p);
580
581 struct softnic_table_action_profile *
582 softnic_table_action_profile_find(struct pmd_internals *p,
583         const char *name);
584
585 struct softnic_table_action_profile *
586 softnic_table_action_profile_create(struct pmd_internals *p,
587         const char *name,
588         struct softnic_table_action_profile_params *params);
589
590 /**
591  * Pipeline
592  */
593 int
594 softnic_pipeline_init(struct pmd_internals *p);
595
596 void
597 softnic_pipeline_free(struct pmd_internals *p);
598
599 struct pipeline *
600 softnic_pipeline_find(struct pmd_internals *p, const char *name);
601
602 struct pipeline *
603 softnic_pipeline_create(struct pmd_internals *p,
604         const char *name,
605         struct pipeline_params *params);
606
607 int
608 softnic_pipeline_port_in_create(struct pmd_internals *p,
609         const char *pipeline_name,
610         struct softnic_port_in_params *params,
611         int enabled);
612
613 int
614 softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
615         const char *pipeline_name,
616         uint32_t port_id,
617         uint32_t table_id);
618
619 int
620 softnic_pipeline_port_out_create(struct pmd_internals *p,
621         const char *pipeline_name,
622         struct softnic_port_out_params *params);
623
624 int
625 softnic_pipeline_table_create(struct pmd_internals *p,
626         const char *pipeline_name,
627         struct softnic_table_params *params);
628
629 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */