1/*
2 * Copyright (c) 2017  Intel Corporation.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifndef __NGX_TLDK_H__
28#define __NGX_TLDK_H__
29
30#include <stdint.h>
31#include <stddef.h>
32#include <inttypes.h>
33
34#include <ngx_config.h>
35#include <ngx_core.h>
36
37#include <rte_config.h>
38#include <rte_eal.h>
39#include <rte_common.h>
40#include <rte_ether.h>
41
42#include <tle_ctx.h>
43#include <tle_event.h>
44
45#define MAX_PKT_BURST 0x20
46
47#define MAX_PORT_QUEUE		\
48	(sizeof(((struct tldk_port_conf *)NULL)->queue_map) * CHAR_BIT)
49
50#define MAX_CTX_PER_LOCRE 32
51
52struct tldk_port_conf {
53	uint32_t id;
54	uint32_t nb_queues;
55	uint32_t queue_map;
56	uint32_t mtu;
57	uint64_t rx_offload;
58	uint64_t tx_offload;
59	uint32_t ipv4;
60	struct in6_addr ipv6;
61	struct ether_addr mac;
62};
63
64struct tldk_dev_conf {
65	uint32_t id;
66	uint32_t port;
67	uint32_t queue;
68};
69
70struct tldk_dest_conf {
71	uint32_t dev;
72	uint32_t mtu;
73	uint32_t prfx;
74	uint16_t family;
75	union {
76		struct in_addr ipv4;
77		struct in6_addr ipv6;
78	};
79	struct ether_addr mac;
80};
81
82#define	TLDK_MAX_DEST	0x10
83
84struct tldk_ctx_conf {
85	ngx_uint_t worker;
86	uint32_t lcore;
87	uint32_t nb_mbuf;
88	uint32_t nb_stream;
89	struct {
90		uint32_t nb_min;
91		uint32_t nb_max;
92	} free_streams;
93	uint32_t nb_rbuf;
94	uint32_t nb_sbuf;
95	uint32_t nb_dev;
96	uint32_t nb_dest;
97	uint32_t be_in_worker;
98	uint32_t tcp_timewait; /* TCP TIME_WAIT value in milliseconds */
99	struct tldk_dev_conf dev[RTE_MAX_ETHPORTS];
100	struct tldk_dest_conf dest[TLDK_MAX_DEST];
101};
102
103typedef struct tldk_conf tldk_conf_t;
104
105struct tldk_conf {
106	uint32_t eal_argc;
107	char *eal_argv[NGX_CONF_MAX_ARGS];
108	char eal_cmd[PATH_MAX];
109	uint32_t nb_port;
110	struct tldk_port_conf port[RTE_MAX_ETHPORTS];
111	uint32_t nb_ctx;
112	struct tldk_ctx_conf ctx[RTE_MAX_LCORE];
113};
114
115extern char *tldk_block_parse(ngx_conf_t *, ngx_command_t *, void *);
116extern char *tldk_ctx_parse(ngx_conf_t *, ngx_command_t *, void *);
117
118struct pkt_buf {
119	uint32_t num;
120	struct rte_mbuf *pkt[2 * MAX_PKT_BURST];
121};
122
123struct tldk_dev {
124	struct tle_dev *dev;
125	struct tldk_dev_conf cf;
126	struct {
127		uint64_t in;
128		uint64_t up;
129		uint64_t drop;
130	} rx_stat;
131	struct {
132		uint64_t down;
133		uint64_t out;
134		uint64_t drop;
135	} tx_stat;
136	struct pkt_buf tx_buf;
137};
138
139#define LCORE_MAX_DST (UINT8_MAX + 1)
140
141struct tldk_ctx {
142	const struct tldk_ctx_conf *cf;
143	struct rte_lpm *lpm4;
144	struct rte_lpm6 *lpm6;
145	struct tle_ctx *ctx;
146	struct rte_mempool *mpool;
147	struct rte_mempool *frag_mpool;
148	uint32_t nb_dev;
149	struct tldk_dev dev[RTE_MAX_ETHPORTS];
150	uint32_t dst4_num;
151	uint32_t dst6_num;
152	struct tle_dest dst4[LCORE_MAX_DST];
153	struct tle_dest dst6[LCORE_MAX_DST];
154	struct {
155		uint64_t flags[UINT8_MAX + 1];
156	} tcp_stat;
157} __rte_cache_aligned;
158
159extern struct tldk_ctx wrk2ctx[RTE_MAX_LCORE];
160
161struct lcore_ctxs_list {
162	uint32_t nb_ctxs;
163	struct tldk_ctx *ctxs[MAX_CTX_PER_LOCRE];
164};
165
166/* helper macros */
167#define	DUMMY_MACRO	do {} while (0)
168
169#ifdef BE_DEBUG
170#define	BE_TRACE(fmt, arg...)	printf(fmt, ##arg)
171#define	BE_PKT_DUMP(p)		rte_pktmbuf_dump(stdout, (p), 74)
172#else
173#define	BE_TRACE(fmt, arg...)	DUMMY_MACRO
174#define	BE_PKT_DUMP(p)		DUMMY_MACRO
175#endif
176
177#ifdef FE_DEBUG
178#define	FE_TRACE(fmt, arg...)	printf(fmt, ##arg)
179#define	FE_PKT_DUMP(p)		rte_pktmbuf_dump(stdout, (p), 74)
180#else
181#define	FE_TRACE(fmt, arg...)	DUMMY_MACRO
182#define	FE_PKT_DUMP(p)		DUMMY_MACRO
183#endif
184
185
186#endif /* __NGX_TLDK_H__ */
187