aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/odp_classification_datamodel.h
blob: ebd0107f9433f195a474ec9dad4896c2c6c91db5 (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
/* Copyright (c) 2014-2018, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP Classification Datamodel
 * Describes the classification internal data model
 */

#ifndef ODP_CLASSIFICATION_DATAMODEL_H_
#define ODP_CLASSIFICATION_DATAMODEL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp/api/spinlock.h>
#include <odp/api/classification.h>
#include <odp/api/debug.h>
#include <odp_pool_internal.h>
#include <odp_packet_internal.h>
#include <odp_packet_io_internal.h>
#include <odp_queue_if.h>
#include <protocols/ip.h>

/* Maximum Class Of Service Entry */
#define CLS_COS_MAX_ENTRY		64
/* Invalid CoS index */
#define CLS_COS_IDX_NONE		CLS_COS_MAX_ENTRY
/* Maximum PMR Entry */
#define CLS_PMR_MAX_ENTRY		256
/* Maximum PMR Terms in a PMR Set */
#define CLS_PMRTERM_MAX			8
/* Maximum PMRs attached in PKTIO Level */
#define CLS_PMR_PER_COS_MAX		8
/* L2 Priority Bits */
#define CLS_COS_L2_QOS_BITS		3
/* Max L2 QoS value */
#define CLS_COS_MAX_L2_QOS		(1 << CLS_COS_L2_QOS_BITS)
/* L2 DSCP Bits */
#define CLS_COS_L3_QOS_BITS		6
/* Max L3 QoS Value */
#define CLS_COS_MAX_L3_QOS		(1 << CLS_COS_L3_QOS_BITS)
/* Max PMR Term size */
#define MAX_PMR_TERM_SIZE		16
/* Max queue per Class of service */
#define CLS_COS_QUEUE_MAX		32
/* Max number of implementation created queues */
#define CLS_QUEUE_GROUP_MAX		(CLS_COS_MAX_ENTRY * CLS_COS_QUEUE_MAX)

/* CoS index is stored in odp_packet_hdr_t */
ODP_STATIC_ASSERT(CLS_COS_MAX_ENTRY <= UINT16_MAX, "CoS_does_not_fit_16_bits");

typedef union {
	/* All proto fileds */
	uint32_t all;

	struct {
		uint32_t ipv4:1;
		uint32_t ipv6:1;
		uint32_t udp:1;
		uint32_t tcp:1;
	};
} odp_cls_hash_proto_t;

/*
 * Term and value mapping for a PMR
 */
typedef struct pmr_term_value {
	/* PMR Term */
	odp_cls_pmr_term_t term;

	/* True if range, false if match */
	odp_bool_t range_term;

	union {
		/* Match value and mask */
		struct {
			/* Value to be matched. Arrays are used with custom and
			 * IPv6 address terms. */
			union {
				uint64_t value;
				uint8_t  value_u8[MAX_PMR_TERM_SIZE];
				uint64_t value_u64[2];
			};

			/* Mask for the data to be matched */
			union {
				uint64_t mask;
				uint8_t  mask_u8[MAX_PMR_TERM_SIZE];
				uint64_t mask_u64[2];
			};

		} match;

		/* Range values */
		struct {
			/* Start value of the range */
			union {
				uint64_t start;
				uint8_t  start_u8[MAX_PMR_TERM_SIZE];
				uint64_t start_u64[2];
			};

			/* End value of the range */
			union {
				uint64_t end;
				uint8_t  end_u8[MAX_PMR_TERM_SIZE];
				uint64_t end_u64[2];
			};

		} range;

	};

	/* Offset used with custom PMR */
	uint32_t offset;

	/* Size of the value to be matched */
	uint32_t val_sz;

} pmr_term_value_t;

/*
Class Of Service
*/
struct cos_s {
	odp_queue_t queue;		/* Associated Queue */
	odp_pool_t pool;		/* Associated Buffer pool */
	odp_pktin_vector_config_t vector;	/* Packet vector config */
	union pmr_u *pmr[CLS_PMR_PER_COS_MAX];	/* Chained PMR */
	union cos_u *linked_cos[CLS_PMR_PER_COS_MAX]; /* Chained CoS with PMR*/
	uint32_t valid;			/* validity Flag */
	odp_cls_drop_t drop_policy;	/* Associated Drop Policy */
	size_t headroom;		/* Headroom for this CoS */
	odp_spinlock_t lock;		/* cos lock */
	odp_atomic_u32_t num_rule;	/* num of PMRs attached with this CoS */
	bool queue_group;
	odp_cls_hash_proto_t hash_proto;
	uint32_t num_queue;
	odp_queue_param_t queue_param;
	char name[ODP_COS_NAME_LEN];	/* name */
	uint8_t index;
};

typedef union cos_u {
	struct cos_s s;
	uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct cos_s))];
} cos_t;

/* Pattern Matching Rule */
struct pmr_s {
	uint32_t valid;			/* Validity Flag */
	odp_atomic_u32_t count;		/* num of packets matching this rule */
	uint32_t num_pmr;		/* num of PMR Term Values*/
	uint16_t mark;
	odp_spinlock_t lock;		/* pmr lock*/
	cos_t *src_cos;			/* source CoS where PMR is attached */
	pmr_term_value_t  pmr_term_value[CLS_PMRTERM_MAX];
			/* List of associated PMR Terms */
};

typedef union pmr_u {
	struct pmr_s s;
	uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(struct pmr_s))];
} pmr_t;

typedef struct _cls_queue_grp_tbl_s {
	odp_queue_t queue[CLS_QUEUE_GROUP_MAX];
} _cls_queue_grp_tbl_s;

typedef union _cls_queue_grp_tbl_t {
	_cls_queue_grp_tbl_s s;
	uint8_t pad[ROUNDUP_CACHE_LINE(sizeof(_cls_queue_grp_tbl_s))];
} _cls_queue_grp_tbl_t;

/**
L2 QoS and CoS Map

This structure holds the mapping between L2 QoS value and
corresponding cos_t object
**/
typedef struct pmr_l2_cos {
	odp_spinlock_t lock;	/* pmr_l2_cos lock */
	cos_t *cos[CLS_COS_MAX_L2_QOS];	/* Array of CoS objects */
} pmr_l2_cos_t;

/**
L3 QoS and CoS Map

This structure holds the mapping between L3 QoS value and
corresponding cos_t object
**/
typedef struct pmr_l3_cos {
	odp_spinlock_t lock;	/* pmr_l3_cos lock */
	cos_t *cos[CLS_COS_MAX_L3_QOS];	/* Array of CoS objects */
} pmr_l3_cos_t;

/**
Linux Generic Classifier

This structure is stored in pktio_entry and holds all
the classifier configuration value.
**/
typedef struct classifier {
	cos_t *error_cos;		/* Associated Error CoS */
	cos_t *default_cos;		/* Associated Default CoS */
	uint32_t l3_precedence;		/* L3 QoS precedence */
	pmr_l2_cos_t l2_cos_table;	/* L2 QoS-CoS table map */
	pmr_l3_cos_t l3_cos_table;	/* L3 Qos-CoS table map */
	size_t headroom;		/* Pktio Headroom */
	size_t skip;			/* Pktio Skip Offset */
} classifier_t;

/**
Class of Service Table
**/
typedef struct odp_cos_table {
	cos_t cos_entry[CLS_COS_MAX_ENTRY];
} cos_tbl_t;

/**
PMR table
**/
typedef struct pmr_tbl {
	pmr_t pmr[CLS_PMR_MAX_ENTRY];
} pmr_tbl_t;

#ifdef __cplusplus
}
#endif
#endif