aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/odp_classification_datamodel.h
blob: c042a530800ce0ade1ffd9441e5fe9373196b37f (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
/* 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_macros_internal.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
/* 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 fields */
	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
*/
typedef struct ODP_ALIGNED_CACHE cos_s {
	uint32_t valid;			/* validity Flag */
	odp_atomic_u32_t num_rule;	/* num of PMRs attached with this CoS */
	struct pmr_s *pmr[CLS_PMR_PER_COS_MAX];	/* Chained PMR */
	struct cos_s *linked_cos[CLS_PMR_PER_COS_MAX]; /* Chained CoS with PMR*/
	odp_bool_t stats_enable;
	odp_cos_action_t action;	/* Action */
	odp_queue_t queue;		/* Associated Queue */
	uint32_t num_queue;
	odp_pool_t pool;		/* Associated Buffer pool */
	uint8_t index;
	bool queue_group;
	odp_cls_hash_proto_t hash_proto;
	odp_pktin_vector_config_t vector;	/* Packet vector config */
	size_t headroom;		/* Headroom for this CoS */
	odp_spinlock_t lock;		/* cos lock */
	odp_queue_param_t queue_param;
	char name[ODP_COS_NAME_LEN];	/* name */
	struct {
		odp_atomic_u64_t discards;
		odp_atomic_u64_t packets;
	} stats, queue_stats[CLS_COS_QUEUE_MAX];
} cos_t;

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

typedef struct ODP_ALIGNED_CACHE {
	odp_queue_t queue[CLS_QUEUE_GROUP_MAX];
} _cls_queue_grp_tbl_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 */
	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;

/**
Classifier global data
**/
typedef struct cls_global_t {
	cos_tbl_t cos_tbl;
	pmr_tbl_t pmr_tbl;
	_cls_queue_grp_tbl_t queue_grp_tbl;
	odp_shm_t shm;

} cls_global_t;

#ifdef __cplusplus
}
#endif
#endif