aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libtle_udp/udp_impl.h
blob: af35197a8c420d192f76b44579ea371616ab40d7 (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
/*
 * Copyright (c) 2016  Intel Corporation.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _UDP_IMPL_H_
#define _UDP_IMPL_H_

#include <rte_spinlock.h>
#include <rte_vect.h>
#include <tle_dring.h>
#include <tle_udp_impl.h>
#include <tle_event.h>

#include "port_bitmap.h"
#include "osdep.h"

#ifdef __cplusplus
extern "C" {
#endif

enum {
	TLE_UDP_V4,
	TLE_UDP_V6,
	TLE_UDP_VNUM
};

union udp_ports {
	uint32_t raw;
	struct {
		uint16_t src;
		uint16_t dst;
	};
};

union udph {
	uint64_t raw;
	struct {
		union udp_ports ports;
		uint16_t len;
		uint16_t cksum;
	};
};

union ipv4_addrs {
	uint64_t raw;
	struct {
		uint32_t src;
		uint32_t dst;
	};
};

union ipv6_addrs {
	_ymm_t raw;
	struct {
		rte_xmm_t src;
		rte_xmm_t dst;
	};
};

union ip_addrs {
	union ipv4_addrs v4;
	union ipv6_addrs v6;
};


struct tle_udp_stream {

	STAILQ_ENTRY(tle_udp_stream) link;
	struct tle_udp_ctx *ctx;

	uint8_t type;	       /* TLE_UDP_V4 or TLE_UDP_V6 */

	struct {
		struct rte_ring *q;
		struct tle_event *ev;
		struct tle_udp_stream_cb cb;
		rte_atomic32_t use;
	} rx;

	union udp_ports port;
	union udp_ports pmsk;

	union {
		struct {
			union ipv4_addrs addr;
			union ipv4_addrs mask;
		} ipv4;
		struct {
			union ipv6_addrs addr;
			union ipv6_addrs mask;
		} ipv6;
	};

	struct {
		rte_atomic32_t use;
		struct {
			uint32_t nb_elem;  /* number of obects per drb. */
			uint32_t nb_max;   /* number of drbs per stream. */
			struct rte_ring *r;
		} drb;
		struct tle_event *ev;
		struct tle_udp_stream_cb cb;
	} tx __rte_cache_aligned;

	struct tle_udp_stream_param prm;
} __rte_cache_aligned;

#define UDP_STREAM_TX_PENDING(s)	\
	((s)->tx.drb.nb_max != rte_ring_count((s)->tx.drb.r))

#define UDP_STREAM_TX_FINISHED(s)	\
	((s)->tx.drb.nb_max == rte_ring_count((s)->tx.drb.r))

struct tle_udp_dport {
	struct udp_pbm use; /* ports in use. */
	struct tle_udp_stream *streams[MAX_PORT_NUM]; /* port to stream. */
};

struct tle_udp_dev {
	struct tle_udp_ctx *ctx;
	struct {
		uint64_t ol_flags[TLE_UDP_VNUM];
	} rx;
	struct {
		/* used by FE. */
		uint64_t ol_flags[TLE_UDP_VNUM];
		rte_atomic32_t packet_id[TLE_UDP_VNUM];

		/* used by FE & BE. */
		struct tle_dring dr;
	} tx;
	struct tle_udp_dev_param prm; /* copy of device paramaters. */
	struct tle_udp_dport *dp[TLE_UDP_VNUM]; /* device udp ports */
};

struct tle_udp_ctx {
	struct tle_udp_ctx_param prm;
	struct {
		rte_spinlock_t lock;
		uint32_t nb_free; /* number of free streams. */
		STAILQ_HEAD(, tle_udp_stream) free;
		struct tle_udp_stream *buf; /* array of streams */
	} streams;

	rte_spinlock_t dev_lock;
	uint32_t nb_dev;
	struct udp_pbm use[TLE_UDP_VNUM];          /* all ports in use. */
	struct tle_udp_dev dev[RTE_MAX_ETHPORTS];
};

#ifdef __cplusplus
}
#endif

#endif /* _UDP_IMPL_H_ */