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