summaryrefslogtreecommitdiff
path: root/drivers/net/softnic/rte_eth_softnic_internals.h
blob: d45957129e72646d598b799cab95f52580ac100b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2017 Intel Corporation
 */

#ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
#define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__

#include <stddef.h>
#include <stdint.h>
#include <sys/queue.h>

#include <rte_mempool.h>
#include <rte_mbuf.h>
#include <rte_ring.h>
#include <rte_ethdev.h>
#include <rte_sched.h>
#include <rte_port_in_action.h>
#include <rte_table_action.h>
#include <rte_pipeline.h>

#include <rte_ethdev_driver.h>
#include <rte_tm_driver.h>

#include "rte_eth_softnic.h"

#define NAME_SIZE                                            64

/**
 * PMD Parameters
 */

struct pmd_params {
	const char *name;
	const char *firmware;
	uint32_t cpu_id;

	/** Traffic Management (TM) */
	struct {
		uint32_t n_queues; /**< Number of queues */
		uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
	} tm;
};

/**
 * MEMPOOL
 */
struct softnic_mempool_params {
	uint32_t buffer_size;
	uint32_t pool_size;
	uint32_t cache_size;
};

struct softnic_mempool {
	TAILQ_ENTRY(softnic_mempool) node;
	char name[NAME_SIZE];
	struct rte_mempool *m;
	uint32_t buffer_size;
};

TAILQ_HEAD(softnic_mempool_list, softnic_mempool);

/**
 * SWQ
 */
struct softnic_swq_params {
	uint32_t size;
};

struct softnic_swq {
	TAILQ_ENTRY(softnic_swq) node;
	char name[NAME_SIZE];
	struct rte_ring *r;
};

TAILQ_HEAD(softnic_swq_list, softnic_swq);

/**
 * LINK
 */
struct softnic_link_params {
	const char *dev_name;
	uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
};

struct softnic_link {
	TAILQ_ENTRY(softnic_link) node;
	char name[NAME_SIZE];
	uint16_t port_id;
	uint32_t n_rxq;
	uint32_t n_txq;
};

TAILQ_HEAD(softnic_link_list, softnic_link);

/**
 * TMGR
 */

#ifndef TM_MAX_SUBPORTS
#define TM_MAX_SUBPORTS					8
#endif

#ifndef TM_MAX_PIPES_PER_SUBPORT
#define TM_MAX_PIPES_PER_SUBPORT			4096
#endif

struct tm_params {
	struct rte_sched_port_params port_params;

	struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];

	struct rte_sched_pipe_params
		pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
	uint32_t n_pipe_profiles;
	uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
};

/* TM Levels */
enum tm_node_level {
	TM_NODE_LEVEL_PORT = 0,
	TM_NODE_LEVEL_SUBPORT,
	TM_NODE_LEVEL_PIPE,
	TM_NODE_LEVEL_TC,
	TM_NODE_LEVEL_QUEUE,
	TM_NODE_LEVEL_MAX,
};

/* TM Shaper Profile */
struct tm_shaper_profile {
	TAILQ_ENTRY(tm_shaper_profile) node;
	uint32_t shaper_profile_id;
	uint32_t n_users;
	struct rte_tm_shaper_params params;
};

TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);

/* TM Shared Shaper */
struct tm_shared_shaper {
	TAILQ_ENTRY(tm_shared_shaper) node;
	uint32_t shared_shaper_id;
	uint32_t n_users;
	uint32_t shaper_profile_id;
};

TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);

/* TM WRED Profile */
struct tm_wred_profile {
	TAILQ_ENTRY(tm_wred_profile) node;
	uint32_t wred_profile_id;
	uint32_t n_users;
	struct rte_tm_wred_params params;
};

TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);

/* TM Node */
struct tm_node {
	TAILQ_ENTRY(tm_node) node;
	uint32_t node_id;
	uint32_t parent_node_id;
	uint32_t priority;
	uint32_t weight;
	uint32_t level;
	struct tm_node *parent_node;
	struct tm_shaper_profile *shaper_profile;
	struct tm_wred_profile *wred_profile;
	struct rte_tm_node_params params;
	struct rte_tm_node_stats stats;
	uint32_t n_children;
};

TAILQ_HEAD(tm_node_list, tm_node);

/* TM Hierarchy Specification */
struct tm_hierarchy {
	struct tm_shaper_profile_list shaper_profiles;
	struct tm_shared_shaper_list shared_shapers;
	struct tm_wred_profile_list wred_profiles;
	struct tm_node_list nodes;

	uint32_t n_shaper_profiles;
	uint32_t n_shared_shapers;
	uint32_t n_wred_profiles;
	uint32_t n_nodes;

	uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
};

struct tm_internals {
	/** Hierarchy specification
	 *
	 *     -Hierarchy is unfrozen at init and when port is stopped.
	 *     -Hierarchy is frozen on successful hierarchy commit.
	 *     -Run-time hierarchy changes are not allowed, therefore it makes
	 *      sense to keep the hierarchy frozen after the port is started.
	 */
	struct tm_hierarchy h;
	int hierarchy_frozen;

	/** Blueprints */
	struct tm_params params;
	struct rte_sched_port *sched;
};

struct softnic_tmgr_port {
	TAILQ_ENTRY(softnic_tmgr_port) node;
	char name[NAME_SIZE];
	struct rte_sched_port *s;
};

TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);

/**
 * TAP
 */
struct softnic_tap {
	TAILQ_ENTRY(softnic_tap) node;
	char name[NAME_SIZE];
	int fd;
};

TAILQ_HEAD(softnic_tap_list, softnic_tap);

/**
 * Input port action
 */
struct softnic_port_in_action_profile_params {
	uint64_t action_mask;
	struct rte_port_in_action_fltr_config fltr;
	struct rte_port_in_action_lb_config lb;
};

struct softnic_port_in_action_profile {
	TAILQ_ENTRY(softnic_port_in_action_profile) node;
	char name[NAME_SIZE];
	struct softnic_port_in_action_profile_params params;
	struct rte_port_in_action_profile *ap;
};

TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);

/**
 * Table action
 */
struct softnic_table_action_profile_params {
	uint64_t action_mask;
	struct rte_table_action_common_config common;
	struct rte_table_action_lb_config lb;
	struct rte_table_action_mtr_config mtr;
	struct rte_table_action_tm_config tm;
	struct rte_table_action_encap_config encap;
	struct rte_table_action_nat_config nat;
	struct rte_table_action_ttl_config ttl;
	struct rte_table_action_stats_config stats;
};

struct softnic_table_action_profile {
	TAILQ_ENTRY(softnic_table_action_profile) node;
	char name[NAME_SIZE];
	struct softnic_table_action_profile_params params;
	struct rte_table_action_profile *ap;
};

TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);

/**
 * Pipeline
 */
struct pipeline_params {
	uint32_t timer_period_ms;
	uint32_t offset_port_id;
};

enum softnic_port_in_type {
	PORT_IN_RXQ,
	PORT_IN_SWQ,
	PORT_IN_TMGR,
	PORT_IN_TAP,
	PORT_IN_SOURCE,
};

struct softnic_port_in_params {
	/* Read */
	enum softnic_port_in_type type;
	const char *dev_name;
	union {
		struct {
			uint16_t queue_id;
		} rxq;

		struct {
			const char *mempool_name;
			uint32_t mtu;
		} tap;

		struct {
			const char *mempool_name;
			const char *file_name;
			uint32_t n_bytes_per_pkt;
		} source;
	};
	uint32_t burst_size;

	/* Action */
	const char *action_profile_name;
};

enum softnic_port_out_type {
	PORT_OUT_TXQ,
	PORT_OUT_SWQ,
	PORT_OUT_TMGR,
	PORT_OUT_TAP,
	PORT_OUT_SINK,
};

struct softnic_port_out_params {
	enum softnic_port_out_type type;
	const char *dev_name;
	union {
		struct {
			uint16_t queue_id;
		} txq;

		struct {
			const char *file_name;
			uint32_t max_n_pkts;
		} sink;
	};
	uint32_t burst_size;
	int retry;
	uint32_t n_retries;
};

enum softnic_table_type {
	TABLE_ACL,
	TABLE_ARRAY,
	TABLE_HASH,
	TABLE_LPM,
	TABLE_STUB,
};

struct softnic_table_acl_params {
	uint32_t n_rules;
	uint32_t ip_header_offset;
	int ip_version;
};

struct softnic_table_array_params {
	uint32_t n_keys;
	uint32_t key_offset;
};

struct softnic_table_hash_params {
	uint32_t n_keys;
	uint32_t key_offset;
	uint32_t key_size;
	uint8_t *key_mask;
	uint32_t n_buckets;
	int extendable_bucket;
};

struct softnic_table_lpm_params {
	uint32_t n_rules;
	uint32_t key_offset;
	uint32_t key_size;
};

struct softnic_table_params {
	/* Match */
	enum softnic_table_type match_type;
	union {
		struct softnic_table_acl_params acl;
		struct softnic_table_array_params array;
		struct softnic_table_hash_params hash;
		struct softnic_table_lpm_params lpm;
	} match;

	/* Action */
	const char *action_profile_name;
};

struct softnic_port_in {
	struct softnic_port_in_params params;
	struct softnic_port_in_action_profile *ap;
	struct rte_port_in_action *a;
};

struct softnic_table {
	struct softnic_table_params params;
	struct softnic_table_action_profile *ap;
	struct rte_table_action *a;
};

struct pipeline {
	TAILQ_ENTRY(pipeline) node;
	char name[NAME_SIZE];

	struct rte_pipeline *p;
	struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
	struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
	uint32_t n_ports_in;
	uint32_t n_ports_out;
	uint32_t n_tables;

	struct rte_ring *msgq_req;
	struct rte_ring *msgq_rsp;
	uint32_t timer_period_ms;

	int enabled;
	uint32_t thread_id;
	uint32_t cpu_id;
};

TAILQ_HEAD(pipeline_list, pipeline);

/**
 * Thread
 */
#ifndef THREAD_PIPELINES_MAX
#define THREAD_PIPELINES_MAX                               256
#endif

#ifndef THREAD_MSGQ_SIZE
#define THREAD_MSGQ_SIZE                                   64
#endif

#ifndef THREAD_TIMER_PERIOD_MS
#define THREAD_TIMER_PERIOD_MS                             100
#endif

/**
 * Master thead: data plane thread context
 */
struct softnic_thread {
	struct rte_ring *msgq_req;
	struct rte_ring *msgq_rsp;

	uint32_t enabled;
};

/**
 * Data plane threads: context
 */
#ifndef TABLE_RULE_ACTION_SIZE_MAX
#define TABLE_RULE_ACTION_SIZE_MAX                         2048
#endif

struct softnic_table_data {
	struct rte_table_action *a;
};

struct pipeline_data {
	struct rte_pipeline *p;
	struct softnic_table_data table_data[RTE_PIPELINE_TABLE_MAX];
	uint32_t n_tables;

	struct rte_ring *msgq_req;
	struct rte_ring *msgq_rsp;
	uint64_t timer_period; /* Measured in CPU cycles. */
	uint64_t time_next;

	uint8_t buffer[TABLE_RULE_ACTION_SIZE_MAX];
};

struct softnic_thread_data {
	struct rte_pipeline *p[THREAD_PIPELINES_MAX];
	uint32_t n_pipelines;

	struct pipeline_data pipeline_data[THREAD_PIPELINES_MAX];
	struct rte_ring *msgq_req;
	struct rte_ring *msgq_rsp;
	uint64_t timer_period; /* Measured in CPU cycles. */
	uint64_t time_next;
	uint64_t time_next_min;
	uint64_t iter;
} __rte_cache_aligned;

/**
 * PMD Internals
 */
struct pmd_internals {
	/** Params */
	struct pmd_params params;

	struct {
		struct tm_internals tm; /**< Traffic Management */
	} soft;

	struct softnic_mempool_list mempool_list;
	struct softnic_swq_list swq_list;
	struct softnic_link_list link_list;
	struct softnic_tmgr_port_list tmgr_port_list;
	struct softnic_tap_list tap_list;
	struct softnic_port_in_action_profile_list port_in_action_profile_list;
	struct softnic_table_action_profile_list table_action_profile_list;
	struct pipeline_list pipeline_list;
	struct softnic_thread thread[RTE_MAX_LCORE];
	struct softnic_thread_data thread_data[RTE_MAX_LCORE];
};

/**
 * MEMPOOL
 */
int
softnic_mempool_init(struct pmd_internals *p);

void
softnic_mempool_free(struct pmd_internals *p);

struct softnic_mempool *
softnic_mempool_find(struct pmd_internals *p,
	const char *name);

struct softnic_mempool *
softnic_mempool_create(struct pmd_internals *p,
	const char *name,
	struct softnic_mempool_params *params);

/**
 * SWQ
 */
int
softnic_swq_init(struct pmd_internals *p);

void
softnic_swq_free(struct pmd_internals *p);

struct softnic_swq *
softnic_swq_find(struct pmd_internals *p,
	const char *name);

struct softnic_swq *
softnic_swq_create(struct pmd_internals *p,
	const char *name,
	struct softnic_swq_params *params);

/**
 * LINK
 */
int
softnic_link_init(struct pmd_internals *p);

void
softnic_link_free(struct pmd_internals *p);

struct softnic_link *
softnic_link_find(struct pmd_internals *p,
	const char *name);

struct softnic_link *
softnic_link_create(struct pmd_internals *p,
	const char *name,
	struct softnic_link_params *params);

/**
 * TMGR
 */
int
softnic_tmgr_init(struct pmd_internals *p);

void
softnic_tmgr_free(struct pmd_internals *p);

struct softnic_tmgr_port *
softnic_tmgr_port_find(struct pmd_internals *p,
	const char *name);

struct softnic_tmgr_port *
softnic_tmgr_port_create(struct pmd_internals *p,
	const char *name,
	struct rte_sched_port *sched);

int
tm_init(struct pmd_internals *p);

void
tm_free(struct pmd_internals *p);

int
tm_start(struct pmd_internals *p);

void
tm_stop(struct pmd_internals *p);

static inline int
tm_used(struct rte_eth_dev *dev)
{
	struct pmd_internals *p = dev->data->dev_private;

	return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
}

extern const struct rte_tm_ops pmd_tm_ops;

/**
 * TAP
 */
int
softnic_tap_init(struct pmd_internals *p);

void
softnic_tap_free(struct pmd_internals *p);

struct softnic_tap *
softnic_tap_find(struct pmd_internals *p,
	const char *name);

struct softnic_tap *
softnic_tap_create(struct pmd_internals *p,
	const char *name);

/**
 * Input port action
 */
int
softnic_port_in_action_profile_init(struct pmd_internals *p);

void
softnic_port_in_action_profile_free(struct pmd_internals *p);

struct softnic_port_in_action_profile *
softnic_port_in_action_profile_find(struct pmd_internals *p,
	const char *name);

struct softnic_port_in_action_profile *
softnic_port_in_action_profile_create(struct pmd_internals *p,
	const char *name,
	struct softnic_port_in_action_profile_params *params);

/**
 * Table action
 */
int
softnic_table_action_profile_init(struct pmd_internals *p);

void
softnic_table_action_profile_free(struct pmd_internals *p);

struct softnic_table_action_profile *
softnic_table_action_profile_find(struct pmd_internals *p,
	const char *name);

struct softnic_table_action_profile *
softnic_table_action_profile_create(struct pmd_internals *p,
	const char *name,
	struct softnic_table_action_profile_params *params);

/**
 * Pipeline
 */
int
softnic_pipeline_init(struct pmd_internals *p);

void
softnic_pipeline_free(struct pmd_internals *p);

struct pipeline *
softnic_pipeline_find(struct pmd_internals *p, const char *name);

struct pipeline *
softnic_pipeline_create(struct pmd_internals *p,
	const char *name,
	struct pipeline_params *params);

int
softnic_pipeline_port_in_create(struct pmd_internals *p,
	const char *pipeline_name,
	struct softnic_port_in_params *params,
	int enabled);

int
softnic_pipeline_port_in_connect_to_table(struct pmd_internals *p,
	const char *pipeline_name,
	uint32_t port_id,
	uint32_t table_id);

int
softnic_pipeline_port_out_create(struct pmd_internals *p,
	const char *pipeline_name,
	struct softnic_port_out_params *params);

int
softnic_pipeline_table_create(struct pmd_internals *p,
	const char *pipeline_name,
	struct softnic_table_params *params);

/**
 * Thread
 */
int
softnic_thread_init(struct pmd_internals *p);

void
softnic_thread_free(struct pmd_internals *p);

/**
 * CLI
 */
void
softnic_cli_process(char *in,
	char *out,
	size_t out_size,
	void *arg);

int
softnic_cli_script_process(struct pmd_internals *softnic,
	const char *file_name,
	size_t msg_in_len_max,
	size_t msg_out_len_max);

#endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */