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 TLE_DEFAULT_MSS 536
49 #define MAX_PKT_BURST 0x20
51 /* Used to allocate the memory for hash key. */
52 #define RSS_HASH_KEY_LENGTH 64
66 * BE related structures.
78 struct ether_addr mac;
79 uint32_t hash_key_size;
80 uint8_t hash_key[RSS_HASH_KEY_LENGTH];
93 struct ether_addr mac;
96 struct netbe_dest_prm {
98 struct netbe_dest *dest;
103 struct rte_mbuf *pkt[2 * MAX_PKT_BURST];
109 struct netbe_port port;
121 struct pkt_buf tx_buf;
122 struct pkt_buf arp_buf;
125 /* 8 bit LPM user data. */
126 #define LCORE_MAX_DST (UINT8_MAX + 1)
130 uint32_t proto; /**< L4 proto to handle. */
131 struct rte_lpm *lpm4;
132 struct rte_lpm6 *lpm6;
133 struct rte_ip_frag_tbl *ftbl;
138 struct netbe_dev *prtq;
139 struct tle_dest dst4[LCORE_MAX_DST];
140 struct tle_dest dst6[LCORE_MAX_DST];
141 struct rte_ip_frag_death_row death_row;
143 uint64_t flags[UINT8_MAX + 1];
154 struct netbe_port *prt;
155 struct netbe_lcore *cpu;
159 * FE related structures.
171 uint32_t bidx; /* BE index to use. */
172 struct sockaddr_storage local_addr; /**< stream local address. */
173 struct sockaddr_storage remote_addr; /**< stream remote address. */
176 struct netfe_stream_prm {
181 uint32_t txlen; /* valid/used only for TXONLY op. */
182 uint32_t rxlen; /* Used by RXTX */
183 struct netfe_sprm sprm;
184 struct netfe_sprm fprm; /* valid/used only for FWD op. */
187 struct netfe_lcore_prm {
188 uint32_t max_streams;
190 struct netfe_stream_prm *stream;
193 struct netfe_stream {
194 struct tle_stream *s;
195 struct tle_event *erev;
196 struct tle_event *rxev;
197 struct tle_event *txev;
203 uint16_t reply_count;
205 uint16_t posterr; /* # of time error event handling was postponed */
213 uint64_t rxev[TLE_SEV_NUM];
214 uint64_t txev[TLE_SEV_NUM];
215 uint64_t erev[TLE_SEV_NUM];
218 struct sockaddr_storage laddr;
219 struct sockaddr_storage raddr;
220 struct netfe_sprm fwdprm;
221 struct netfe_stream *fwds;
222 LIST_ENTRY(netfe_stream) link;
225 struct netfe_stream_list {
227 LIST_HEAD(, netfe_stream) head;
231 uint32_t snum; /* max number of streams */
232 struct tle_evq *syneq;
233 struct tle_evq *ereq;
234 struct tle_evq *rxeq;
235 struct tle_evq *txeq;
236 struct rte_hash *fw4h;
237 struct rte_hash *fw6h;
243 struct netfe_stream_list free;
244 struct netfe_stream_list use;
249 struct netbe_lcore *lc;
251 struct netfe_lcore_prm fe;
259 extern struct tx_content tx_content;
262 * debug/trace macros.
265 #define DUMMY_MACRO do {} while (0)
268 #define NETFE_TRACE(fmt, arg...) printf(fmt, ##arg)
269 #define NETFE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
271 #define NETFE_TRACE(fmt, arg...) DUMMY_MACRO
272 #define NETFE_PKT_DUMP(p) DUMMY_MACRO
276 #define NETBE_TRACE(fmt, arg...) printf(fmt, ##arg)
277 #define NETBE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
279 #define NETBE_TRACE(fmt, arg...) DUMMY_MACRO
280 #define NETBE_PKT_DUMP(p) DUMMY_MACRO
283 #define FUNC_STAT(v, c) do { \
284 static uint64_t nb_call, nb_data; \
287 if ((nb_call & ((c) - 1)) == 0) { \
288 printf("%s#%d@%u: nb_call=%lu, avg(" #v ")=%#Lf\n", \
289 __func__, __LINE__, rte_lcore_id(), nb_call, \
290 (long double)nb_data / nb_call); \
296 #define FUNC_TM_STAT(v, c) do { \
297 static uint64_t nb_call, nb_data; \
298 static uint64_t cts, pts, sts; \
305 if ((nb_call & ((c) - 1)) == 0) { \
306 printf("%s#%d@%u: nb_call=%lu, " \
307 "avg(" #v ")=%#Lf, " \
308 "avg(cycles)=%#Lf, " \
309 "avg(cycles/" #v ")=%#Lf\n", \
310 __func__, __LINE__, rte_lcore_id(), nb_call, \
311 (long double)nb_data / nb_call, \
312 (long double)sts / nb_call, \
313 (long double)sts / nb_data); \
320 int setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc,
321 uint16_t qid, uint32_t arp);
324 * application function pointers
327 typedef int (*LCORE_MAIN_FUNCTYPE)(void *arg);
330 * tle_l4p lib function pointers
333 typedef uint16_t (*TLE_RX_BULK_FUNCTYPE)
334 (struct tle_dev *dev, struct rte_mbuf *pkt[],
335 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
337 typedef uint16_t (*TLE_TX_BULK_FUNCTYPE)
338 (struct tle_dev *dev, struct rte_mbuf *pkt[], uint16_t num);
340 typedef uint16_t (*TLE_STREAM_RECV_FUNCTYPE)
341 (struct tle_stream *ts, struct rte_mbuf *pkt[], uint16_t num);
343 typedef int (*TLE_STREAM_CLOSE_FUNCTYPE)(struct tle_stream *s);
345 #endif /* __NETBE_H__ */