File: flow_api_engine.h

package info (click to toggle)
dpdk 25.11-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 127,892 kB
  • sloc: ansic: 2,358,479; python: 16,426; sh: 4,474; makefile: 1,713; awk: 70
file content (432 lines) | stat: -rw-r--r-- 9,445 bytes parent folder | download
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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2023 Napatech A/S
 */

#ifndef _FLOW_API_ENGINE_H_
#define _FLOW_API_ENGINE_H_

#include <stdint.h>
#include <stdatomic.h>

#include "hw_mod_backend.h"
#include "stream_binary_flow_api.h"

/*
 * Resource management
 */
#define BIT_CONTAINER_8_ALIGN(x) (((x) + 7) / 8)

/*
 * Resource management
 * These are free resources in FPGA
 * Other FPGA memory lists are linked to one of these
 * and will implicitly follow them
 */
enum res_type_e {
	RES_QUEUE,
	RES_CAT_CFN,
	RES_CAT_COT,
	RES_CAT_EXO,
	RES_CAT_LEN,
	RES_KM_FLOW_TYPE,
	RES_KM_CATEGORY,
	RES_HSH_RCP,
	RES_PDB_RCP,
	RES_QSL_RCP,
	RES_QSL_QST,
	RES_SLC_LR_RCP,

	RES_FLM_FLOW_TYPE,
	RES_FLM_RCP,
	RES_TPE_RCP,
	RES_TPE_EXT,
	RES_TPE_RPL,
	RES_SCRUB_RCP,
	RES_COUNT,
	RES_INVALID,
	RES_END
};

/*
 * Flow NIC offload management
 */
#define MAX_OUTPUT_DEST (128)

#define MAX_WORD_NUM 24
#define MAX_BANKS 6

#define MAX_TCAM_START_OFFSETS 4

#define MAX_FLM_MTRS_SUPPORTED 4
#define MAX_CPY_WRITERS_SUPPORTED 8

#define MAX_MATCH_FIELDS 16

/*
 *          128      128     32     32    32
 * Have  |  QW0  ||  QW4  || SW8 || SW9 | SWX   in FPGA
 *
 * Each word may start at any offset, though
 * they are combined in chronological order, with all enabled to
 * build the extracted match data, thus that is how the match key
 * must be build
 */
enum extractor_e {
	KM_USE_EXTRACTOR_UNDEF,
	KM_USE_EXTRACTOR_QWORD,
	KM_USE_EXTRACTOR_SWORD,
};

struct match_elem_s {
	enum extractor_e extr;
	int masked_for_tcam;	/* if potentially selected for TCAM */
	uint32_t e_word[4];
	uint32_t e_mask[4];

	int extr_start_offs_id;
	int8_t rel_offs;
	uint32_t word_len;
};

enum cam_tech_use_e {
	KM_CAM,
	KM_TCAM,
	KM_SYNERGY
};

struct km_flow_def_s {
	struct flow_api_backend_s *be;

	/* For keeping track of identical entries */
	struct km_flow_def_s *reference;
	struct km_flow_def_s *root;

	/* For collect flow elements and sorting */
	struct match_elem_s match[MAX_MATCH_FIELDS];
	struct match_elem_s *match_map[MAX_MATCH_FIELDS];
	int num_ftype_elem;

	/* Finally formatted CAM/TCAM entry */
	enum cam_tech_use_e target;
	uint32_t entry_word[MAX_WORD_NUM];
	uint32_t entry_mask[MAX_WORD_NUM];
	int key_word_size;

	/* TCAM calculated possible bank start offsets */
	int start_offsets[MAX_TCAM_START_OFFSETS];
	int num_start_offsets;

	/* Flow information */
	/* HW input port ID needed for compare. In port must be identical on flow types */
	uint32_t port_id;
	uint32_t info;	/* used for color (actions) */
	int info_set;
	int flow_type;	/* 0 is illegal and used as unset */
	int flushed_to_target;	/* if this km entry has been finally programmed into NIC hw */

	/* CAM specific bank management */
	int cam_paired;
	int record_indexes[MAX_BANKS];
	int bank_used;
	uint32_t *cuckoo_moves;	/* for CAM statistics only */
	struct cam_distrib_s *cam_dist;
	struct hasher_s *hsh;

	/* TCAM specific bank management */
	struct tcam_distrib_s *tcam_dist;
	int tcam_start_bank;
	int tcam_record;
};

/*
 * RSS configuration, see struct rte_flow_action_rss
 */
struct hsh_def_s {
	enum rte_eth_hash_function func;	/* RSS hash function to apply */
	/* RSS hash types, see definition of RTE_ETH_RSS_* for hash calculation options */
	uint64_t types;
	uint32_t key_len;	/* Hash key length in bytes. */
	const uint8_t *key;	/* Hash key. */
};

/*
 * AGE configuration, see struct rte_flow_action_age
 */
struct age_def_s {
	uint32_t timeout;
	void *context;
};

/*
 * Tunnel encapsulation header definition
 */
#define MAX_TUN_HDR_SIZE 128

struct tunnel_header_s {
	union {
		uint8_t hdr8[MAX_TUN_HDR_SIZE];
		uint32_t hdr32[(MAX_TUN_HDR_SIZE + 3) / 4];
	} d;

	uint8_t len;

	uint8_t nb_vlans;

	uint8_t ip_version;	/* 4: v4, 6: v6 */

	uint8_t new_outer;
	uint8_t l2_len;
	uint8_t l3_len;
	uint8_t l4_len;
};

enum flow_port_type_e {
	PORT_NONE,	/* not defined or drop */
	PORT_INTERNAL,	/* no queues attached */
	PORT_PHY,	/* MAC phy output queue */
	PORT_VIRT,	/* Memory queues to Host */
};

struct output_s {
	uint32_t owning_port_id;/* the port who owns this output destination */
	enum flow_port_type_e type;
	int id;	/* depending on port type: queue ID or physical port id or not used */
	int active;	/* activated */
};

struct nic_flow_def {
	/*
	 * Frame Decoder match info collected
	 */
	int l2_prot;
	int l3_prot;
	int l4_prot;
	int tunnel_prot;
	int tunnel_l2_prot;
	int tunnel_l3_prot;
	int tunnel_l4_prot;
	int vlans;
	int tunnel_vlans;
	int fragmentation;
	int ip_prot;
	int tunnel_ip_prot;
	/*
	 * Additional meta data for various functions
	 */
	int in_port_override;
	int non_empty;	/* default value is -1; value 1 means flow actions update */
	struct output_s dst_id[MAX_OUTPUT_DEST];/* define the output to use */
	/* total number of available queues defined for all outputs - i.e. number of dst_id's */
	int dst_num_avail;

	/*
	 * Mark or Action info collection
	 */
	uint32_t mark;

	uint32_t jump_to_group;

	uint32_t mtr_ids[MAX_FLM_MTRS_SUPPORTED];

	int full_offload;

	/*
	 * Action push tunnel
	 */
	struct tunnel_header_s tun_hdr;

	/*
	 * If DPDK RTE tunnel helper API used
	 * this holds the tunnel if used in flow
	 */
	struct tunnel_s *tnl;

	/*
	 * Header Stripper
	 */
	int header_strip_end_dyn;
	int header_strip_end_ofs;

	/*
	 * Modify field
	 */
	struct {
		uint32_t select;
		uint32_t dyn;
		uint32_t ofs;
		uint32_t len;
		uint32_t level;
		union {
			uint8_t value8[16];
			uint16_t value16[8];
			uint32_t value32[4];
		};
	} modify_field[MAX_CPY_WRITERS_SUPPORTED];

	uint32_t modify_field_count;
	uint8_t ttl_sub_enable;
	uint8_t ttl_sub_ipv4;
	uint8_t ttl_sub_outer;

	/*
	 * Key Matcher flow definitions
	 */
	struct km_flow_def_s km;

	/*
	 * Hash module RSS definitions
	 */
	struct hsh_def_s hsh;

	/*
	 * AGE action timeout
	 */
	struct age_def_s age;

	/*
	 * TX fragmentation IFR/RPP_LR MTU recipe
	 */
	uint8_t flm_mtu_fragmentation_recipe;
};

enum flow_handle_type {
	FLOW_HANDLE_TYPE_FLOW,
	FLOW_HANDLE_TYPE_FLM,
};

struct flow_handle {
	enum flow_handle_type type;
	uint32_t flm_id;
	uint16_t caller_id;
	RTE_ATOMIC(uint16_t) learn_ignored;

	struct flow_eth_dev *dev;
	struct flow_handle *next;
	struct flow_handle *prev;

	/* Flow specific pointer to application data stored during action creation. */
	void *context;
	void *user_data;

	union {
		struct {
			/*
			 * 1st step conversion and validation of flow
			 * verified and converted flow match + actions structure
			 */
			struct nic_flow_def *fd;
			/*
			 * 2nd step NIC HW resource allocation and configuration
			 * NIC resource management structures
			 */
			struct {
				uint32_t db_idx_counter;
				uint32_t db_idxs[RES_COUNT];
			};
			uint32_t port_id;	/* MAC port ID or override of virtual in_port */
		};

		struct {
			uint32_t flm_db_idx_counter;
			uint32_t flm_db_idxs[RES_COUNT];

			uint32_t flm_mtr_ids[MAX_FLM_MTRS_SUPPORTED];

			uint32_t flm_data[10];
			uint8_t flm_prot;
			uint8_t flm_kid;
			uint8_t flm_prio;
			uint8_t flm_ft;

			uint16_t flm_rpl_ext_ptr;
			uint32_t flm_nat_ipv4;
			uint16_t flm_nat_port;
			uint8_t flm_dscp;
			uint32_t flm_teid;
			uint8_t flm_rqi;
			uint8_t flm_qfi;
			uint8_t flm_scrub_prof;

			uint8_t flm_mtu_fragmentation_recipe;

			/* Flow specific pointer to application template table cell stored during
			 * flow create.
			 */
			struct flow_template_table_cell *template_table_cell;
			bool flm_async;
		};
	};
};

struct flow_pattern_template {
	struct nic_flow_def *fd;
};

struct flow_actions_template {
	struct nic_flow_def *fd;

	uint32_t num_dest_port;
	uint32_t num_queues;
};

struct flow_template_table_cell {
	atomic_int status;
	atomic_int counter;

	uint32_t flm_db_idx_counter;
	uint32_t flm_db_idxs[RES_COUNT];

	uint32_t flm_key_id;
	uint32_t flm_ft;

	uint16_t flm_rpl_ext_ptr;
	uint8_t  flm_scrub_prof;
};

struct flow_template_table {
	struct flow_pattern_template **pattern_templates;
	uint8_t nb_pattern_templates;

	struct flow_actions_template **actions_templates;
	uint8_t nb_actions_templates;

	struct flow_template_table_cell *pattern_action_pairs;

	struct rte_flow_attr attr;
	uint16_t forced_vlan_vid;
	uint16_t caller_id;
};

void nthw_km_attach_ndev_resource_management(struct km_flow_def_s *km, void **handle);
void nthw_km_free_ndev_resource_management(void **handle);

int nthw_km_add_match_elem(struct km_flow_def_s *km, uint32_t e_word[4], uint32_t e_mask[4],
	uint32_t word_len, enum frame_offs_e start, int8_t offset);

int nthw_km_key_create(struct km_flow_def_s *km, uint32_t port_id);
/*
 * Compares 2 KM key definitions after first collect validate and optimization.
 * km is compared against an existing km1.
 * if identical, km1 flow_type is returned
 */
int nthw_km_key_compare(struct km_flow_def_s *km, struct km_flow_def_s *km1);

int nthw_km_rcp_set(struct km_flow_def_s *km, int index);

int nthw_km_write_data_match_entry(struct km_flow_def_s *km, uint32_t color);
int nthw_km_clear_data_match_entry(struct km_flow_def_s *km);

void nthw_kcc_free_ndev_resource_mgmnt(void **handle);

/*
 * Group management
 */
int nthw_flow_group_handle_create(void **handle, uint32_t group_count);
int nthw_flow_group_handle_destroy(void **handle);

int nthw_flow_group_translate_get(void *handle, uint8_t owner_id, uint8_t port_id,
	uint32_t group_in, uint32_t *group_out);
int nthw_flow_group_translate_get_orig_group(void *handle, uint32_t translated_group,
	uint32_t *group_orig);

#endif  /* _FLOW_API_ENGINE_H_ */