2 * Copyright (c) 2016 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
23 #include <arpa/inet.h>
27 #include <rte_config.h>
28 #include <rte_common.h>
30 #include <rte_lcore.h>
31 #include <rte_ethdev.h>
32 #include <rte_kvargs.h>
33 #include <rte_errno.h>
34 #include <rte_malloc.h>
35 #include <rte_cycles.h>
40 #include <rte_ip_frag.h>
42 #include <tle_udp_impl.h>
43 #include <tle_event.h>
45 #define MAX_PKT_BURST 0x20
48 * BE related structures.
59 struct ether_addr mac;
72 struct ether_addr mac;
75 struct netbe_dest_prm {
77 struct netbe_dest *dest;
82 struct rte_mbuf *pkt[2 * MAX_PKT_BURST];
88 struct netbe_port port;
89 struct tle_udp_dev *dev;
100 struct pkt_buf tx_buf;
103 /* 8 bit LPM user data. */
104 #define LCORE_MAX_DST (UINT8_MAX + 1)
108 struct rte_lpm *lpm4;
109 struct rte_lpm6 *lpm6;
110 struct rte_ip_frag_tbl *ftbl;
111 struct tle_udp_ctx *ctx;
115 struct netbe_dev prt[RTE_MAX_ETHPORTS];
116 struct tle_udp_dest dst4[LCORE_MAX_DST];
117 struct tle_udp_dest dst6[LCORE_MAX_DST];
118 struct rte_ip_frag_death_row death_row;
125 struct netbe_port prt[RTE_MAX_ETHPORTS];
126 struct netbe_lcore cpu[RTE_MAX_LCORE];
130 * FE related structures.
141 uint32_t bidx; /* BE index to use. */
142 struct tle_udp_stream_param prm;
145 struct netfe_stream_prm {
149 uint16_t txlen; /* valid/used only for TXONLY op. */
150 struct netfe_sprm sprm;
151 struct netfe_sprm fprm; /* valid/used only for FWD op. */
154 struct netfe_lcore_prm {
155 uint32_t max_streams;
157 struct netfe_stream_prm *stream;
160 struct netfe_stream {
161 struct tle_udp_stream *s;
162 struct tle_event *rxev;
163 struct tle_event *txev;
172 uint64_t rxev[TLE_SEV_NUM];
173 uint64_t txev[TLE_SEV_NUM];
176 struct sockaddr_storage raddr;
177 struct netfe_sprm fwdprm;
181 uint32_t snum; /* max number of streams */
182 uint32_t sidx; /* last open stream index */
183 struct tle_evq *rxeq;
184 struct tle_evq *txeq;
185 struct rte_hash *fw4h;
186 struct rte_hash *fw6h;
187 struct netfe_stream *fs;
191 * debug/trace macros.
194 #define DUMMY_MACRO do {} while (0)
197 #define NETFE_TRACE(fmt, arg...) printf(fmt, ##arg)
198 #define NETFE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
200 #define NETFE_TRACE(fmt, arg...) DUMMY_MACRO
201 #define NETFE_PKT_DUMP(p) DUMMY_MACRO
205 #define NETBE_TRACE(fmt, arg...) printf(fmt, ##arg)
206 #define NETBE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
208 #define NETBE_TRACE(fmt, arg...) DUMMY_MACRO
209 #define NETBE_PKT_DUMP(p) DUMMY_MACRO
212 #define FUNC_STAT(v, c) do { \
213 static uint64_t nb_call, nb_data; \
216 if ((nb_call & ((c) - 1)) == 0) { \
217 printf("%s#%d@%u: nb_call=%lu, avg(" #v ")=%#Lf\n", \
218 __func__, __LINE__, rte_lcore_id(), nb_call, \
219 (long double)nb_data / nb_call); \
225 #define FUNC_TM_STAT(v, c) do { \
226 static uint64_t nb_call, nb_data; \
227 static uint64_t cts, pts, sts; \
234 if ((nb_call & ((c) - 1)) == 0) { \
235 printf("%s#%d@%u: nb_call=%lu, " \
236 "avg(" #v ")=%#Lf, " \
237 "avg(cycles)=%#Lf, " \
238 "avg(cycles/" #v ")=%#Lf\n", \
239 __func__, __LINE__, rte_lcore_id(), nb_call, \
240 (long double)nb_data / nb_call, \
241 (long double)sts / nb_call, \
242 (long double)sts / nb_data); \
249 int setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc);
251 #endif /* __NETBE_H__ */