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>
45 #include <tle_event.h>
47 #define MAX_PKT_BURST 0x20
49 /* Used to allocate the memory for hash key. */
50 #define RSS_HASH_KEY_LENGTH 64
64 * BE related structures.
76 struct ether_addr mac;
77 uint32_t hash_key_size;
78 uint8_t hash_key[RSS_HASH_KEY_LENGTH];
91 struct ether_addr mac;
94 struct netbe_dest_prm {
96 struct netbe_dest *dest;
101 struct rte_mbuf *pkt[2 * MAX_PKT_BURST];
107 struct netbe_port port;
119 struct pkt_buf tx_buf;
120 struct pkt_buf arp_buf;
123 /* 8 bit LPM user data. */
124 #define LCORE_MAX_DST (UINT8_MAX + 1)
128 uint32_t proto; /**< L4 proto to handle. */
129 struct rte_lpm *lpm4;
130 struct rte_lpm6 *lpm6;
131 struct rte_ip_frag_tbl *ftbl;
136 struct netbe_dev *prtq;
137 struct tle_dest dst4[LCORE_MAX_DST];
138 struct tle_dest dst6[LCORE_MAX_DST];
139 struct rte_ip_frag_death_row death_row;
141 uint64_t flags[UINT8_MAX + 1];
152 struct netbe_port *prt;
153 struct netbe_lcore *cpu;
157 * FE related structures.
168 uint32_t bidx; /* BE index to use. */
169 struct sockaddr_storage local_addr; /**< stream local address. */
170 struct sockaddr_storage remote_addr; /**< stream remote address. */
173 struct netfe_stream_prm {
178 uint16_t txlen; /* valid/used only for TXONLY op. */
179 struct netfe_sprm sprm;
180 struct netfe_sprm fprm; /* valid/used only for FWD op. */
183 struct netfe_lcore_prm {
184 uint32_t max_streams;
186 struct netfe_stream_prm *stream;
189 struct netfe_stream {
190 struct tle_stream *s;
191 struct tle_event *erev;
192 struct tle_event *rxev;
193 struct tle_event *txev;
198 uint16_t posterr; /* # of time error event handling was postponed */
206 uint64_t rxev[TLE_SEV_NUM];
207 uint64_t txev[TLE_SEV_NUM];
208 uint64_t erev[TLE_SEV_NUM];
211 struct sockaddr_storage laddr;
212 struct sockaddr_storage raddr;
213 struct netfe_sprm fwdprm;
214 struct netfe_stream *fwds;
215 LIST_ENTRY(netfe_stream) link;
218 struct netfe_stream_list {
220 LIST_HEAD(, netfe_stream) head;
224 uint32_t snum; /* max number of streams */
225 struct tle_evq *syneq;
226 struct tle_evq *ereq;
227 struct tle_evq *rxeq;
228 struct tle_evq *txeq;
229 struct rte_hash *fw4h;
230 struct rte_hash *fw6h;
236 struct netfe_stream_list free;
237 struct netfe_stream_list use;
242 struct netbe_lcore *lc;
244 struct netfe_lcore_prm fe;
248 * debug/trace macros.
251 #define DUMMY_MACRO do {} while (0)
254 #define NETFE_TRACE(fmt, arg...) printf(fmt, ##arg)
255 #define NETFE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
257 #define NETFE_TRACE(fmt, arg...) DUMMY_MACRO
258 #define NETFE_PKT_DUMP(p) DUMMY_MACRO
262 #define NETBE_TRACE(fmt, arg...) printf(fmt, ##arg)
263 #define NETBE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
265 #define NETBE_TRACE(fmt, arg...) DUMMY_MACRO
266 #define NETBE_PKT_DUMP(p) DUMMY_MACRO
269 #define FUNC_STAT(v, c) do { \
270 static uint64_t nb_call, nb_data; \
273 if ((nb_call & ((c) - 1)) == 0) { \
274 printf("%s#%d@%u: nb_call=%lu, avg(" #v ")=%#Lf\n", \
275 __func__, __LINE__, rte_lcore_id(), nb_call, \
276 (long double)nb_data / nb_call); \
282 #define FUNC_TM_STAT(v, c) do { \
283 static uint64_t nb_call, nb_data; \
284 static uint64_t cts, pts, sts; \
291 if ((nb_call & ((c) - 1)) == 0) { \
292 printf("%s#%d@%u: nb_call=%lu, " \
293 "avg(" #v ")=%#Lf, " \
294 "avg(cycles)=%#Lf, " \
295 "avg(cycles/" #v ")=%#Lf\n", \
296 __func__, __LINE__, rte_lcore_id(), nb_call, \
297 (long double)nb_data / nb_call, \
298 (long double)sts / nb_call, \
299 (long double)sts / nb_data); \
306 int setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc,
307 uint16_t qid, uint32_t arp);
310 * application function pointers
313 typedef int (*LCORE_MAIN_FUNCTYPE)(void *arg);
316 * tle_l4p lib function pointers
319 typedef uint16_t (*TLE_RX_BULK_FUNCTYPE)
320 (struct tle_dev *dev, struct rte_mbuf *pkt[],
321 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
323 typedef uint16_t (*TLE_TX_BULK_FUNCTYPE)
324 (struct tle_dev *dev, struct rte_mbuf *pkt[], uint16_t num);
326 typedef uint16_t (*TLE_STREAM_RECV_FUNCTYPE)
327 (struct tle_stream *ts, struct rte_mbuf *pkt[], uint16_t num);
329 typedef int (*TLE_STREAM_CLOSE_FUNCTYPE)(struct tle_stream *s);
331 #endif /* __NETBE_H__ */