ngx_tldk.h revision e18a033b
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	uint32_t rx_offload;
58	uint32_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	uint32_t nb_rbuf;
90	uint32_t nb_sbuf;
91	uint32_t nb_dev;
92	uint32_t nb_dest;
93	uint32_t be_in_worker;
94	uint32_t tcp_timewait; /* TCP TIME_WAIT value in milliseconds */
95	struct tldk_dev_conf dev[RTE_MAX_ETHPORTS];
96	struct tldk_dest_conf dest[TLDK_MAX_DEST];
97};
98
99typedef struct tldk_conf tldk_conf_t;
100
101struct tldk_conf {
102	uint32_t eal_argc;
103	char *eal_argv[NGX_CONF_MAX_ARGS];
104	char eal_cmd[PATH_MAX];
105	uint32_t nb_port;
106	struct tldk_port_conf port[RTE_MAX_ETHPORTS];
107	uint32_t nb_ctx;
108	struct tldk_ctx_conf ctx[RTE_MAX_LCORE];
109};
110
111extern char *tldk_block_parse(ngx_conf_t *, ngx_command_t *, void *);
112extern char *tldk_ctx_parse(ngx_conf_t *, ngx_command_t *, void *);
113
114struct pkt_buf {
115	uint32_t num;
116	struct rte_mbuf *pkt[2 * MAX_PKT_BURST];
117};
118
119struct tldk_dev {
120	struct tle_dev *dev;
121	struct tldk_dev_conf cf;
122	struct {
123		uint64_t in;
124		uint64_t up;
125		uint64_t drop;
126	} rx_stat;
127	struct {
128		uint64_t down;
129		uint64_t out;
130		uint64_t drop;
131	} tx_stat;
132	struct pkt_buf tx_buf;
133};
134
135#define LCORE_MAX_DST (UINT8_MAX + 1)
136
137struct tldk_ctx {
138	const struct tldk_ctx_conf *cf;
139	struct rte_lpm *lpm4;
140	struct rte_lpm6 *lpm6;
141	struct tle_ctx *ctx;
142	struct rte_mempool *mpool;
143	struct rte_mempool *frag_mpool;
144	uint32_t nb_dev;
145	struct tldk_dev dev[RTE_MAX_ETHPORTS];
146	uint32_t dst4_num;
147	uint32_t dst6_num;
148	struct tle_dest dst4[LCORE_MAX_DST];
149	struct tle_dest dst6[LCORE_MAX_DST];
150	struct {
151		uint64_t flags[UINT8_MAX + 1];
152	} tcp_stat;
153} __rte_cache_aligned;
154
155extern struct tldk_ctx wrk2ctx[RTE_MAX_LCORE];
156
157struct lcore_ctxs_list {
158	uint32_t nb_ctxs;
159	struct tldk_ctx *ctxs[MAX_CTX_PER_LOCRE];
160};
161
162/* helper macros */
163#define	DUMMY_MACRO	do {} while (0)
164
165#ifdef BE_DEBUG
166#define	BE_TRACE(fmt, arg...)	printf(fmt, ##arg)
167#define	BE_PKT_DUMP(p)		rte_pktmbuf_dump(stdout, (p), 74)
168#else
169#define	BE_TRACE(fmt, arg...)	DUMMY_MACRO
170#define	BE_PKT_DUMP(p)		DUMMY_MACRO
171#endif
172
173#ifdef FE_DEBUG
174#define	FE_TRACE(fmt, arg...)	printf(fmt, ##arg)
175#define	FE_PKT_DUMP(p)		rte_pktmbuf_dump(stdout, (p), 74)
176#else
177#define	FE_TRACE(fmt, arg...)	DUMMY_MACRO
178#define	FE_PKT_DUMP(p)		DUMMY_MACRO
179#endif
180
181
182#endif /* __NGX_TLDK_H__ */
183