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;
205 uint64_t rxev[TLE_SEV_NUM];
206 uint64_t txev[TLE_SEV_NUM];
207 uint64_t erev[TLE_SEV_NUM];
210 struct sockaddr_storage laddr;
211 struct sockaddr_storage raddr;
212 struct netfe_sprm fwdprm;
213 struct netfe_stream *fwds;
214 LIST_ENTRY(netfe_stream) link;
217 struct netfe_stream_list {
219 LIST_HEAD(, netfe_stream) head;
223 uint32_t snum; /* max number of streams */
224 struct tle_evq *syneq;
225 struct tle_evq *ereq;
226 struct tle_evq *rxeq;
227 struct tle_evq *txeq;
228 struct rte_hash *fw4h;
229 struct rte_hash *fw6h;
235 struct netfe_stream_list free;
236 struct netfe_stream_list use;
241 struct netbe_lcore *lc;
243 struct netfe_lcore_prm fe;
247 * debug/trace macros.
250 #define DUMMY_MACRO do {} while (0)
253 #define NETFE_TRACE(fmt, arg...) printf(fmt, ##arg)
254 #define NETFE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
256 #define NETFE_TRACE(fmt, arg...) DUMMY_MACRO
257 #define NETFE_PKT_DUMP(p) DUMMY_MACRO
261 #define NETBE_TRACE(fmt, arg...) printf(fmt, ##arg)
262 #define NETBE_PKT_DUMP(p) rte_pktmbuf_dump(stdout, (p), 64)
264 #define NETBE_TRACE(fmt, arg...) DUMMY_MACRO
265 #define NETBE_PKT_DUMP(p) DUMMY_MACRO
268 #define FUNC_STAT(v, c) do { \
269 static uint64_t nb_call, nb_data; \
272 if ((nb_call & ((c) - 1)) == 0) { \
273 printf("%s#%d@%u: nb_call=%lu, avg(" #v ")=%#Lf\n", \
274 __func__, __LINE__, rte_lcore_id(), nb_call, \
275 (long double)nb_data / nb_call); \
281 #define FUNC_TM_STAT(v, c) do { \
282 static uint64_t nb_call, nb_data; \
283 static uint64_t cts, pts, sts; \
290 if ((nb_call & ((c) - 1)) == 0) { \
291 printf("%s#%d@%u: nb_call=%lu, " \
292 "avg(" #v ")=%#Lf, " \
293 "avg(cycles)=%#Lf, " \
294 "avg(cycles/" #v ")=%#Lf\n", \
295 __func__, __LINE__, rte_lcore_id(), nb_call, \
296 (long double)nb_data / nb_call, \
297 (long double)sts / nb_call, \
298 (long double)sts / nb_data); \
305 int setup_rx_cb(const struct netbe_port *uprt, struct netbe_lcore *lc,
306 uint16_t qid, uint32_t arp);
309 * application function pointers
312 typedef int (*LCORE_MAIN_FUNCTYPE)(void *arg);
315 * tle_l4p lib function pointers
318 typedef uint16_t (*TLE_RX_BULK_FUNCTYPE)
319 (struct tle_dev *dev, struct rte_mbuf *pkt[],
320 struct rte_mbuf *rp[], int32_t rc[], uint16_t num);
322 typedef uint16_t (*TLE_TX_BULK_FUNCTYPE)
323 (struct tle_dev *dev, struct rte_mbuf *pkt[], uint16_t num);
325 typedef uint16_t (*TLE_STREAM_RECV_FUNCTYPE)
326 (struct tle_stream *ts, struct rte_mbuf *pkt[], uint16_t num);
328 typedef int (*TLE_STREAM_CLOSE_FUNCTYPE)(struct tle_stream *s);
330 #endif /* __NETBE_H__ */