13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 23998e2a0SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 3cc8f4d02SIntel */ 4cc8f4d02SIntel 5cc8f4d02SIntel #include <stdio.h> 6cc8f4d02SIntel #include <stdlib.h> 7cc8f4d02SIntel #include <stdint.h> 8cc8f4d02SIntel #include <inttypes.h> 9cc8f4d02SIntel #include <sys/types.h> 10cc8f4d02SIntel #include <string.h> 11cc8f4d02SIntel #include <sys/queue.h> 12cc8f4d02SIntel #include <stdarg.h> 13cc8f4d02SIntel #include <errno.h> 14cc8f4d02SIntel #include <getopt.h> 15cc8f4d02SIntel #include <signal.h> 16b84fb4cbSAnatoly Burakov #include <sys/param.h> 17cc8f4d02SIntel 18cc8f4d02SIntel #include <rte_common.h> 19cc8f4d02SIntel #include <rte_byteorder.h> 20cc8f4d02SIntel #include <rte_log.h> 21cc8f4d02SIntel #include <rte_memory.h> 22cc8f4d02SIntel #include <rte_memcpy.h> 23cc8f4d02SIntel #include <rte_eal.h> 24cc8f4d02SIntel #include <rte_launch.h> 25cc8f4d02SIntel #include <rte_cycles.h> 26cc8f4d02SIntel #include <rte_prefetch.h> 27cc8f4d02SIntel #include <rte_lcore.h> 28cc8f4d02SIntel #include <rte_per_lcore.h> 29cc8f4d02SIntel #include <rte_branch_prediction.h> 30cc8f4d02SIntel #include <rte_interrupts.h> 31cc8f4d02SIntel #include <rte_random.h> 32cc8f4d02SIntel #include <rte_debug.h> 33cc8f4d02SIntel #include <rte_ether.h> 34cc8f4d02SIntel #include <rte_ethdev.h> 35cc8f4d02SIntel #include <rte_mempool.h> 36cc8f4d02SIntel #include <rte_mbuf.h> 37cc8f4d02SIntel #include <rte_malloc.h> 38cc8f4d02SIntel #include <rte_ip.h> 39cc8f4d02SIntel #include <rte_tcp.h> 40cc8f4d02SIntel #include <rte_udp.h> 41cc8f4d02SIntel #include <rte_string_fns.h> 42cc8f4d02SIntel #include <rte_lpm.h> 43cc8f4d02SIntel #include <rte_lpm6.h> 44b84fb4cbSAnatoly Burakov 45b84fb4cbSAnatoly Burakov #include <rte_ip_frag.h> 46b84fb4cbSAnatoly Burakov 47595ea7dcSIntel #define MAX_PKT_BURST 32 48595ea7dcSIntel 49595ea7dcSIntel 50b84fb4cbSAnatoly Burakov #define RTE_LOGTYPE_IP_RSMBL RTE_LOGTYPE_USER1 51cc8f4d02SIntel 52cc8f4d02SIntel #define MAX_JUMBO_PKT_LEN 9600 53cc8f4d02SIntel 54824cb29cSKonstantin Ananyev #define BUF_SIZE RTE_MBUF_DEFAULT_DATAROOM 55b325a66aSAshish Jain #define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE 56cc8f4d02SIntel 57b84fb4cbSAnatoly Burakov #define NB_MBUF 8192 58b325a66aSAshish Jain #define MEMPOOL_CACHE_SIZE 256 59b84fb4cbSAnatoly Burakov 60b84fb4cbSAnatoly Burakov /* allow max jumbo frame 9.5 KB */ 61b84fb4cbSAnatoly Burakov #define JUMBO_FRAME_MAX_SIZE 0x2600 62b84fb4cbSAnatoly Burakov 63cc8f4d02SIntel #define MAX_FLOW_NUM UINT16_MAX 64cc8f4d02SIntel #define MIN_FLOW_NUM 1 65cc8f4d02SIntel #define DEF_FLOW_NUM 0x1000 66cc8f4d02SIntel 67cc8f4d02SIntel /* TTL numbers are in ms. */ 68cc8f4d02SIntel #define MAX_FLOW_TTL (3600 * MS_PER_S) 69cc8f4d02SIntel #define MIN_FLOW_TTL 1 70cc8f4d02SIntel #define DEF_FLOW_TTL MS_PER_S 71cc8f4d02SIntel 72b84fb4cbSAnatoly Burakov #define MAX_FRAG_NUM RTE_LIBRTE_IP_FRAG_MAX_FRAG 73cc8f4d02SIntel 74cc8f4d02SIntel /* Should be power of two. */ 75b84fb4cbSAnatoly Burakov #define IP_FRAG_TBL_BUCKET_ENTRIES 16 76cc8f4d02SIntel 77cc8f4d02SIntel static uint32_t max_flow_num = DEF_FLOW_NUM; 78cc8f4d02SIntel static uint32_t max_flow_ttl = DEF_FLOW_TTL; 79cc8f4d02SIntel 80cc8f4d02SIntel #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 81cc8f4d02SIntel 82cc8f4d02SIntel #define NB_SOCKETS 8 83cc8f4d02SIntel 84cc8f4d02SIntel /* Configure how many packets ahead to prefetch, when reading packets */ 85cc8f4d02SIntel #define PREFETCH_OFFSET 3 86cc8f4d02SIntel 87cc8f4d02SIntel /* 88cc8f4d02SIntel * Configurable number of RX/TX ring descriptors 89cc8f4d02SIntel */ 90867a6c66SKevin Laatz #define RTE_TEST_RX_DESC_DEFAULT 1024 91867a6c66SKevin Laatz #define RTE_TEST_TX_DESC_DEFAULT 1024 92595ea7dcSIntel 93cc8f4d02SIntel static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 94cc8f4d02SIntel static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; 95cc8f4d02SIntel 96cc8f4d02SIntel /* ethernet addresses of ports */ 976d13ea8eSOlivier Matz static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; 98b84fb4cbSAnatoly Burakov 99b84fb4cbSAnatoly Burakov #ifndef IPv4_BYTES 100b84fb4cbSAnatoly Burakov #define IPv4_BYTES_FMT "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 101b84fb4cbSAnatoly Burakov #define IPv4_BYTES(addr) \ 102b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 24) & 0xFF),\ 103b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 16) & 0xFF),\ 104b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 8) & 0xFF),\ 105b84fb4cbSAnatoly Burakov (uint8_t) ((addr) & 0xFF) 106b84fb4cbSAnatoly Burakov #endif 107b84fb4cbSAnatoly Burakov 108b84fb4cbSAnatoly Burakov #ifndef IPv6_BYTES 109b84fb4cbSAnatoly Burakov #define IPv6_BYTES_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"\ 110b84fb4cbSAnatoly Burakov "%02x%02x:%02x%02x:%02x%02x:%02x%02x" 111b84fb4cbSAnatoly Burakov #define IPv6_BYTES(addr) \ 112b84fb4cbSAnatoly Burakov addr[0], addr[1], addr[2], addr[3], \ 113b84fb4cbSAnatoly Burakov addr[4], addr[5], addr[6], addr[7], \ 114b84fb4cbSAnatoly Burakov addr[8], addr[9], addr[10], addr[11],\ 115b84fb4cbSAnatoly Burakov addr[12], addr[13],addr[14], addr[15] 116b84fb4cbSAnatoly Burakov #endif 117b84fb4cbSAnatoly Burakov 118b84fb4cbSAnatoly Burakov #define IPV6_ADDR_LEN 16 119cc8f4d02SIntel 120cc8f4d02SIntel /* mask of enabled ports */ 121cc8f4d02SIntel static uint32_t enabled_port_mask = 0; 122b84fb4cbSAnatoly Burakov 123b84fb4cbSAnatoly Burakov static int rx_queue_per_lcore = 1; 124cc8f4d02SIntel 125cc8f4d02SIntel struct mbuf_table { 126595ea7dcSIntel uint32_t len; 127595ea7dcSIntel uint32_t head; 128595ea7dcSIntel uint32_t tail; 129595ea7dcSIntel struct rte_mbuf *m_table[0]; 130cc8f4d02SIntel }; 131cc8f4d02SIntel 132b84fb4cbSAnatoly Burakov struct rx_queue { 133b84fb4cbSAnatoly Burakov struct rte_ip_frag_tbl *frag_tbl; 134b84fb4cbSAnatoly Burakov struct rte_mempool *pool; 135b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 136b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 137f8244c63SZhiyong Yang uint16_t portid; 138cc8f4d02SIntel }; 139cc8f4d02SIntel 140b84fb4cbSAnatoly Burakov struct tx_lcore_stat { 141b84fb4cbSAnatoly Burakov uint64_t call; 142b84fb4cbSAnatoly Burakov uint64_t drop; 143b84fb4cbSAnatoly Burakov uint64_t queue; 144b84fb4cbSAnatoly Burakov uint64_t send; 145b84fb4cbSAnatoly Burakov }; 146b84fb4cbSAnatoly Burakov 147b84fb4cbSAnatoly Burakov #define MAX_RX_QUEUE_PER_LCORE 16 148b84fb4cbSAnatoly Burakov #define MAX_TX_QUEUE_PER_PORT 16 149b84fb4cbSAnatoly Burakov #define MAX_RX_QUEUE_PER_PORT 128 150b84fb4cbSAnatoly Burakov 151b84fb4cbSAnatoly Burakov struct lcore_queue_conf { 152b84fb4cbSAnatoly Burakov uint16_t n_rx_queue; 153b84fb4cbSAnatoly Burakov struct rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE]; 154b84fb4cbSAnatoly Burakov uint16_t tx_queue_id[RTE_MAX_ETHPORTS]; 155b84fb4cbSAnatoly Burakov struct rte_ip_frag_death_row death_row; 156b84fb4cbSAnatoly Burakov struct mbuf_table *tx_mbufs[RTE_MAX_ETHPORTS]; 157b84fb4cbSAnatoly Burakov struct tx_lcore_stat tx_stat; 158b84fb4cbSAnatoly Burakov } __rte_cache_aligned; 159b84fb4cbSAnatoly Burakov static struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE]; 160cc8f4d02SIntel 161cc8f4d02SIntel static struct rte_eth_conf port_conf = { 162cc8f4d02SIntel .rxmode = { 163295968d1SFerruh Yigit .mq_mode = RTE_ETH_MQ_RX_RSS, 1641bb4a528SFerruh Yigit .mtu = JUMBO_FRAME_MAX_SIZE - RTE_ETHER_HDR_LEN - 1651bb4a528SFerruh Yigit RTE_ETHER_CRC_LEN, 166cc8f4d02SIntel .split_hdr_size = 0, 167295968d1SFerruh Yigit .offloads = RTE_ETH_RX_OFFLOAD_CHECKSUM, 168cc8f4d02SIntel }, 169cc8f4d02SIntel .rx_adv_conf = { 170cc8f4d02SIntel .rss_conf = { 171cc8f4d02SIntel .rss_key = NULL, 172295968d1SFerruh Yigit .rss_hf = RTE_ETH_RSS_IP, 173cc8f4d02SIntel }, 174cc8f4d02SIntel }, 175cc8f4d02SIntel .txmode = { 176295968d1SFerruh Yigit .mq_mode = RTE_ETH_MQ_TX_NONE, 177295968d1SFerruh Yigit .offloads = (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | 178295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_MULTI_SEGS), 179cc8f4d02SIntel }, 180cc8f4d02SIntel }; 181cc8f4d02SIntel 182b84fb4cbSAnatoly Burakov /* 183b84fb4cbSAnatoly Burakov * IPv4 forwarding table 184b84fb4cbSAnatoly Burakov */ 185b84fb4cbSAnatoly Burakov struct l3fwd_ipv4_route { 186cc8f4d02SIntel uint32_t ip; 187cc8f4d02SIntel uint8_t depth; 188cc8f4d02SIntel uint8_t if_out; 189cc8f4d02SIntel }; 190cc8f4d02SIntel 1919a212dc0SConor Fogarty /* Default l3fwd_ipv4_route_array table. 8< */ 192b84fb4cbSAnatoly Burakov struct l3fwd_ipv4_route l3fwd_ipv4_route_array[] = { 1930c9da755SDavid Marchand {RTE_IPV4(100,10,0,0), 16, 0}, 1940c9da755SDavid Marchand {RTE_IPV4(100,20,0,0), 16, 1}, 1950c9da755SDavid Marchand {RTE_IPV4(100,30,0,0), 16, 2}, 1960c9da755SDavid Marchand {RTE_IPV4(100,40,0,0), 16, 3}, 1970c9da755SDavid Marchand {RTE_IPV4(100,50,0,0), 16, 4}, 1980c9da755SDavid Marchand {RTE_IPV4(100,60,0,0), 16, 5}, 1990c9da755SDavid Marchand {RTE_IPV4(100,70,0,0), 16, 6}, 2000c9da755SDavid Marchand {RTE_IPV4(100,80,0,0), 16, 7}, 201b84fb4cbSAnatoly Burakov }; 2029a212dc0SConor Fogarty /* >8 End of default l3fwd_ipv4_route_array table. */ 203b84fb4cbSAnatoly Burakov 204b84fb4cbSAnatoly Burakov /* 205b84fb4cbSAnatoly Burakov * IPv6 forwarding table 206b84fb4cbSAnatoly Burakov */ 207b84fb4cbSAnatoly Burakov 208b84fb4cbSAnatoly Burakov struct l3fwd_ipv6_route { 209b84fb4cbSAnatoly Burakov uint8_t ip[IPV6_ADDR_LEN]; 210cc8f4d02SIntel uint8_t depth; 211cc8f4d02SIntel uint8_t if_out; 212cc8f4d02SIntel }; 213cc8f4d02SIntel 2149a212dc0SConor Fogarty /* Default l3fwd_ipv6_route_array table. 8< */ 215b84fb4cbSAnatoly Burakov static struct l3fwd_ipv6_route l3fwd_ipv6_route_array[] = { 216cc8f4d02SIntel {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 0}, 217cc8f4d02SIntel {{2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 1}, 218cc8f4d02SIntel {{3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 2}, 219cc8f4d02SIntel {{4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 3}, 220cc8f4d02SIntel {{5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 4}, 221cc8f4d02SIntel {{6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 5}, 222cc8f4d02SIntel {{7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 6}, 223cc8f4d02SIntel {{8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 7}, 224cc8f4d02SIntel }; 2259a212dc0SConor Fogarty /* >8 End of default l3fwd_ipv6_route_array table. */ 226cc8f4d02SIntel 227b84fb4cbSAnatoly Burakov #define LPM_MAX_RULES 1024 228b84fb4cbSAnatoly Burakov #define LPM6_MAX_RULES 1024 229b84fb4cbSAnatoly Burakov #define LPM6_NUMBER_TBL8S (1 << 16) 230cc8f4d02SIntel 231b84fb4cbSAnatoly Burakov struct rte_lpm6_config lpm6_config = { 232b84fb4cbSAnatoly Burakov .max_rules = LPM6_MAX_RULES, 233b84fb4cbSAnatoly Burakov .number_tbl8s = LPM6_NUMBER_TBL8S, 234b84fb4cbSAnatoly Burakov .flags = 0 235595ea7dcSIntel }; 236595ea7dcSIntel 237b84fb4cbSAnatoly Burakov static struct rte_lpm *socket_lpm[RTE_MAX_NUMA_NODES]; 238b84fb4cbSAnatoly Burakov static struct rte_lpm6 *socket_lpm6[RTE_MAX_NUMA_NODES]; 239b84fb4cbSAnatoly Burakov 240240952a9SAnatoly Burakov #ifdef RTE_LIBRTE_IP_FRAG_TBL_STAT 241595ea7dcSIntel #define TX_LCORE_STAT_UPDATE(s, f, v) ((s)->f += (v)) 242595ea7dcSIntel #else 243595ea7dcSIntel #define TX_LCORE_STAT_UPDATE(s, f, v) do {} while (0) 244240952a9SAnatoly Burakov #endif /* RTE_LIBRTE_IP_FRAG_TBL_STAT */ 245cc8f4d02SIntel 246595ea7dcSIntel /* 247595ea7dcSIntel * If number of queued packets reached given threahold, then 248595ea7dcSIntel * send burst of packets on an output interface. 249595ea7dcSIntel */ 250595ea7dcSIntel static inline uint32_t 251f8244c63SZhiyong Yang send_burst(struct lcore_queue_conf *qconf, uint32_t thresh, uint16_t port) 252cc8f4d02SIntel { 253595ea7dcSIntel uint32_t fill, len, k, n; 254595ea7dcSIntel struct mbuf_table *txmb; 255cc8f4d02SIntel 256595ea7dcSIntel txmb = qconf->tx_mbufs[port]; 257595ea7dcSIntel len = txmb->len; 258cc8f4d02SIntel 259595ea7dcSIntel if ((int32_t)(fill = txmb->head - txmb->tail) < 0) 260595ea7dcSIntel fill += len; 261595ea7dcSIntel 262595ea7dcSIntel if (fill >= thresh) { 263595ea7dcSIntel n = RTE_MIN(len - txmb->tail, fill); 264595ea7dcSIntel 265595ea7dcSIntel k = rte_eth_tx_burst(port, qconf->tx_queue_id[port], 266595ea7dcSIntel txmb->m_table + txmb->tail, (uint16_t)n); 267595ea7dcSIntel 268595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, call, 1); 269595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, send, k); 270595ea7dcSIntel 271595ea7dcSIntel fill -= k; 272595ea7dcSIntel if ((txmb->tail += k) == len) 273595ea7dcSIntel txmb->tail = 0; 274cc8f4d02SIntel } 275cc8f4d02SIntel 276693f715dSHuawei Xie return fill; 277cc8f4d02SIntel } 278cc8f4d02SIntel 279cc8f4d02SIntel /* Enqueue a single packet, and send burst if queue is filled */ 280cc8f4d02SIntel static inline int 281f8244c63SZhiyong Yang send_single_packet(struct rte_mbuf *m, uint16_t port) 282cc8f4d02SIntel { 283595ea7dcSIntel uint32_t fill, lcore_id, len; 284b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 285595ea7dcSIntel struct mbuf_table *txmb; 286cc8f4d02SIntel 287cc8f4d02SIntel lcore_id = rte_lcore_id(); 288b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 289cc8f4d02SIntel 290595ea7dcSIntel txmb = qconf->tx_mbufs[port]; 291595ea7dcSIntel len = txmb->len; 292595ea7dcSIntel 293595ea7dcSIntel fill = send_burst(qconf, MAX_PKT_BURST, port); 294595ea7dcSIntel 295595ea7dcSIntel if (fill == len - 1) { 296595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, drop, 1); 297595ea7dcSIntel rte_pktmbuf_free(txmb->m_table[txmb->tail]); 298595ea7dcSIntel if (++txmb->tail == len) 299595ea7dcSIntel txmb->tail = 0; 300cc8f4d02SIntel } 301cc8f4d02SIntel 302595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, queue, 1); 303595ea7dcSIntel txmb->m_table[txmb->head] = m; 304595ea7dcSIntel if(++txmb->head == len) 305595ea7dcSIntel txmb->head = 0; 306595ea7dcSIntel 307693f715dSHuawei Xie return 0; 308cc8f4d02SIntel } 309cc8f4d02SIntel 310cc8f4d02SIntel static inline void 311f8244c63SZhiyong Yang reassemble(struct rte_mbuf *m, uint16_t portid, uint32_t queue, 312b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf, uint64_t tms) 313cc8f4d02SIntel { 3146d13ea8eSOlivier Matz struct rte_ether_hdr *eth_hdr; 315b84fb4cbSAnatoly Burakov struct rte_ip_frag_tbl *tbl; 316b84fb4cbSAnatoly Burakov struct rte_ip_frag_death_row *dr; 317b84fb4cbSAnatoly Burakov struct rx_queue *rxq; 318cc8f4d02SIntel void *d_addr_bytes; 319d89a5bceSVladyslav Buslov uint32_t next_hop; 320f8244c63SZhiyong Yang uint16_t dst_port; 321b84fb4cbSAnatoly Burakov 322b84fb4cbSAnatoly Burakov rxq = &qconf->rx_queue_list[queue]; 323cc8f4d02SIntel 3246d13ea8eSOlivier Matz eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); 325cc8f4d02SIntel 326b84fb4cbSAnatoly Burakov dst_port = portid; 327cc8f4d02SIntel 328b84fb4cbSAnatoly Burakov /* if packet is IPv4 */ 3293c0184ccSHelin Zhang if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) { 330a7c528e5SOlivier Matz struct rte_ipv4_hdr *ip_hdr; 331b84fb4cbSAnatoly Burakov uint32_t ip_dst; 332cc8f4d02SIntel 333a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1); 334cc8f4d02SIntel 335cc8f4d02SIntel /* if it is a fragmented packet, then try to reassemble. */ 336b84fb4cbSAnatoly Burakov if (rte_ipv4_frag_pkt_is_fragmented(ip_hdr)) { 337cc8f4d02SIntel struct rte_mbuf *mo; 338cc8f4d02SIntel 339b84fb4cbSAnatoly Burakov tbl = rxq->frag_tbl; 340595ea7dcSIntel dr = &qconf->death_row; 341cc8f4d02SIntel 342cc8f4d02SIntel /* prepare mbuf: setup l2_len/l3_len. */ 3437869536fSBruce Richardson m->l2_len = sizeof(*eth_hdr); 3447869536fSBruce Richardson m->l3_len = sizeof(*ip_hdr); 345cc8f4d02SIntel 346cc8f4d02SIntel /* process this fragment. */ 347b84fb4cbSAnatoly Burakov mo = rte_ipv4_frag_reassemble_packet(tbl, dr, m, tms, ip_hdr); 348b84fb4cbSAnatoly Burakov if (mo == NULL) 349cc8f4d02SIntel /* no packet to send out. */ 350cc8f4d02SIntel return; 351cc8f4d02SIntel 352cc8f4d02SIntel /* we have our packet reassembled. */ 353cc8f4d02SIntel if (mo != m) { 354cc8f4d02SIntel m = mo; 355cc8f4d02SIntel eth_hdr = rte_pktmbuf_mtod(m, 3566d13ea8eSOlivier Matz struct rte_ether_hdr *); 357a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1); 358b84fb4cbSAnatoly Burakov } 35931c78767SSunil Kumar Kori 36031c78767SSunil Kumar Kori /* update offloading flags */ 361*daa02b5cSOlivier Matz m->ol_flags |= (RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_IP_CKSUM); 362b84fb4cbSAnatoly Burakov } 363b84fb4cbSAnatoly Burakov ip_dst = rte_be_to_cpu_32(ip_hdr->dst_addr); 364b84fb4cbSAnatoly Burakov 365b84fb4cbSAnatoly Burakov /* Find destination port */ 366d89a5bceSVladyslav Buslov if (rte_lpm_lookup(rxq->lpm, ip_dst, &next_hop) == 0 && 367d89a5bceSVladyslav Buslov (enabled_port_mask & 1 << next_hop) != 0) { 368d89a5bceSVladyslav Buslov dst_port = next_hop; 369b84fb4cbSAnatoly Burakov } 370b84fb4cbSAnatoly Burakov 3710c9da755SDavid Marchand eth_hdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPV4); 3723c0184ccSHelin Zhang } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) { 3733c0184ccSHelin Zhang /* if packet is IPv6 */ 374b84fb4cbSAnatoly Burakov struct ipv6_extension_fragment *frag_hdr; 375a7c528e5SOlivier Matz struct rte_ipv6_hdr *ip_hdr; 376b84fb4cbSAnatoly Burakov 377a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1); 378b84fb4cbSAnatoly Burakov 379b84fb4cbSAnatoly Burakov frag_hdr = rte_ipv6_frag_get_ipv6_fragment_header(ip_hdr); 380b84fb4cbSAnatoly Burakov 381b84fb4cbSAnatoly Burakov if (frag_hdr != NULL) { 382b84fb4cbSAnatoly Burakov struct rte_mbuf *mo; 383b84fb4cbSAnatoly Burakov 384b84fb4cbSAnatoly Burakov tbl = rxq->frag_tbl; 385b84fb4cbSAnatoly Burakov dr = &qconf->death_row; 386b84fb4cbSAnatoly Burakov 387b84fb4cbSAnatoly Burakov /* prepare mbuf: setup l2_len/l3_len. */ 3887869536fSBruce Richardson m->l2_len = sizeof(*eth_hdr); 3897869536fSBruce Richardson m->l3_len = sizeof(*ip_hdr) + sizeof(*frag_hdr); 390b84fb4cbSAnatoly Burakov 391b84fb4cbSAnatoly Burakov mo = rte_ipv6_frag_reassemble_packet(tbl, dr, m, tms, ip_hdr, frag_hdr); 392b84fb4cbSAnatoly Burakov if (mo == NULL) 393b84fb4cbSAnatoly Burakov return; 394b84fb4cbSAnatoly Burakov 395b84fb4cbSAnatoly Burakov if (mo != m) { 396b84fb4cbSAnatoly Burakov m = mo; 3976d13ea8eSOlivier Matz eth_hdr = rte_pktmbuf_mtod(m, 3986d13ea8eSOlivier Matz struct rte_ether_hdr *); 399a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1); 400cc8f4d02SIntel } 401cc8f4d02SIntel } 402cc8f4d02SIntel 403b84fb4cbSAnatoly Burakov /* Find destination port */ 404d89a5bceSVladyslav Buslov if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr, 405d89a5bceSVladyslav Buslov &next_hop) == 0 && 406d89a5bceSVladyslav Buslov (enabled_port_mask & 1 << next_hop) != 0) { 407d89a5bceSVladyslav Buslov dst_port = next_hop; 408b84fb4cbSAnatoly Burakov } 409b84fb4cbSAnatoly Burakov 4100c9da755SDavid Marchand eth_hdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPV6); 411b84fb4cbSAnatoly Burakov } 412b84fb4cbSAnatoly Burakov /* if packet wasn't IPv4 or IPv6, it's forwarded to the port it came from */ 413cc8f4d02SIntel 414cc8f4d02SIntel /* 02:00:00:00:00:xx */ 41504d43857SDmitry Kozlyuk d_addr_bytes = ð_hdr->dst_addr.addr_bytes[0]; 416cc8f4d02SIntel *((uint64_t *)d_addr_bytes) = 0x000000000002 + ((uint64_t)dst_port << 40); 417cc8f4d02SIntel 418cc8f4d02SIntel /* src addr */ 41904d43857SDmitry Kozlyuk rte_ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->src_addr); 420cc8f4d02SIntel 421cc8f4d02SIntel send_single_packet(m, dst_port); 422cc8f4d02SIntel } 423cc8f4d02SIntel 424cc8f4d02SIntel /* main processing loop */ 425cc8f4d02SIntel static int 426f2fc83b4SThomas Monjalon main_loop(__rte_unused void *dummy) 427cc8f4d02SIntel { 428cc8f4d02SIntel struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; 429cc8f4d02SIntel unsigned lcore_id; 430cc8f4d02SIntel uint64_t diff_tsc, cur_tsc, prev_tsc; 431cc8f4d02SIntel int i, j, nb_rx; 432f8244c63SZhiyong Yang uint16_t portid; 433b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 434cc8f4d02SIntel const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; 435cc8f4d02SIntel 436cc8f4d02SIntel prev_tsc = 0; 437cc8f4d02SIntel 438cc8f4d02SIntel lcore_id = rte_lcore_id(); 439b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 440cc8f4d02SIntel 441cc8f4d02SIntel if (qconf->n_rx_queue == 0) { 442b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "lcore %u has nothing to do\n", lcore_id); 443cc8f4d02SIntel return 0; 444cc8f4d02SIntel } 445cc8f4d02SIntel 446b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "entering main loop on lcore %u\n", lcore_id); 447cc8f4d02SIntel 448cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; i++) { 449cc8f4d02SIntel 450b84fb4cbSAnatoly Burakov portid = qconf->rx_queue_list[i].portid; 451f8244c63SZhiyong Yang RTE_LOG(INFO, IP_RSMBL, " -- lcoreid=%u portid=%u\n", lcore_id, 452b84fb4cbSAnatoly Burakov portid); 453cc8f4d02SIntel } 454cc8f4d02SIntel 455cc8f4d02SIntel while (1) { 456cc8f4d02SIntel 457cc8f4d02SIntel cur_tsc = rte_rdtsc(); 458cc8f4d02SIntel 459cc8f4d02SIntel /* 460cc8f4d02SIntel * TX burst queue drain 461cc8f4d02SIntel */ 462cc8f4d02SIntel diff_tsc = cur_tsc - prev_tsc; 463cc8f4d02SIntel if (unlikely(diff_tsc > drain_tsc)) { 464cc8f4d02SIntel 465cc8f4d02SIntel /* 466cc8f4d02SIntel * This could be optimized (use queueid instead of 467cc8f4d02SIntel * portid), but it is not called so often 468cc8f4d02SIntel */ 469b84fb4cbSAnatoly Burakov for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 470595ea7dcSIntel if ((enabled_port_mask & (1 << portid)) != 0) 471595ea7dcSIntel send_burst(qconf, 1, portid); 472cc8f4d02SIntel } 473cc8f4d02SIntel 474cc8f4d02SIntel prev_tsc = cur_tsc; 475cc8f4d02SIntel } 476cc8f4d02SIntel 477cc8f4d02SIntel /* 478cc8f4d02SIntel * Read packet from RX queues 479cc8f4d02SIntel */ 480cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; ++i) { 481cc8f4d02SIntel 482b84fb4cbSAnatoly Burakov portid = qconf->rx_queue_list[i].portid; 483cc8f4d02SIntel 484b84fb4cbSAnatoly Burakov nb_rx = rte_eth_rx_burst(portid, 0, pkts_burst, 485cc8f4d02SIntel MAX_PKT_BURST); 486cc8f4d02SIntel 487cc8f4d02SIntel /* Prefetch first packets */ 488cc8f4d02SIntel for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) { 489cc8f4d02SIntel rte_prefetch0(rte_pktmbuf_mtod( 490cc8f4d02SIntel pkts_burst[j], void *)); 491cc8f4d02SIntel } 492cc8f4d02SIntel 493cc8f4d02SIntel /* Prefetch and forward already prefetched packets */ 494cc8f4d02SIntel for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) { 495cc8f4d02SIntel rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[ 496cc8f4d02SIntel j + PREFETCH_OFFSET], void *)); 497b84fb4cbSAnatoly Burakov reassemble(pkts_burst[j], portid, 498cc8f4d02SIntel i, qconf, cur_tsc); 499cc8f4d02SIntel } 500cc8f4d02SIntel 501cc8f4d02SIntel /* Forward remaining prefetched packets */ 502cc8f4d02SIntel for (; j < nb_rx; j++) { 503b84fb4cbSAnatoly Burakov reassemble(pkts_burst[j], portid, 504cc8f4d02SIntel i, qconf, cur_tsc); 505cc8f4d02SIntel } 506595ea7dcSIntel 50763ec0b58SAnatoly Burakov rte_ip_frag_free_death_row(&qconf->death_row, 508595ea7dcSIntel PREFETCH_OFFSET); 509cc8f4d02SIntel } 510cc8f4d02SIntel } 511cc8f4d02SIntel } 512cc8f4d02SIntel 513cc8f4d02SIntel /* display usage */ 514cc8f4d02SIntel static void 515cc8f4d02SIntel print_usage(const char *prgname) 516cc8f4d02SIntel { 517b84fb4cbSAnatoly Burakov printf("%s [EAL options] -- -p PORTMASK [-q NQ]" 518cc8f4d02SIntel " [--maxflows=<flows>] [--flowttl=<ttl>[(s|ms)]]\n" 519cc8f4d02SIntel " -p PORTMASK: hexadecimal bitmask of ports to configure\n" 520b84fb4cbSAnatoly Burakov " -q NQ: number of RX queues per lcore\n" 521cc8f4d02SIntel " --maxflows=<flows>: optional, maximum number of flows " 522cc8f4d02SIntel "supported\n" 523cc8f4d02SIntel " --flowttl=<ttl>[(s|ms)]: optional, maximum TTL for each " 524cc8f4d02SIntel "flow\n", 525cc8f4d02SIntel prgname); 526cc8f4d02SIntel } 527cc8f4d02SIntel 528cc8f4d02SIntel static uint32_t 529cc8f4d02SIntel parse_flow_num(const char *str, uint32_t min, uint32_t max, uint32_t *val) 530cc8f4d02SIntel { 531cc8f4d02SIntel char *end; 532cc8f4d02SIntel uint64_t v; 533cc8f4d02SIntel 534cc8f4d02SIntel /* parse decimal string */ 535cc8f4d02SIntel errno = 0; 536cc8f4d02SIntel v = strtoul(str, &end, 10); 537cc8f4d02SIntel if (errno != 0 || *end != '\0') 538693f715dSHuawei Xie return -EINVAL; 539cc8f4d02SIntel 540cc8f4d02SIntel if (v < min || v > max) 541693f715dSHuawei Xie return -EINVAL; 542cc8f4d02SIntel 543cc8f4d02SIntel *val = (uint32_t)v; 544693f715dSHuawei Xie return 0; 545cc8f4d02SIntel } 546cc8f4d02SIntel 547cc8f4d02SIntel static int 548cc8f4d02SIntel parse_flow_ttl(const char *str, uint32_t min, uint32_t max, uint32_t *val) 549cc8f4d02SIntel { 550cc8f4d02SIntel char *end; 551cc8f4d02SIntel uint64_t v; 552cc8f4d02SIntel 553cc8f4d02SIntel static const char frmt_sec[] = "s"; 554cc8f4d02SIntel static const char frmt_msec[] = "ms"; 555cc8f4d02SIntel 556cc8f4d02SIntel /* parse decimal string */ 557cc8f4d02SIntel errno = 0; 558cc8f4d02SIntel v = strtoul(str, &end, 10); 559cc8f4d02SIntel if (errno != 0) 560693f715dSHuawei Xie return -EINVAL; 561cc8f4d02SIntel 562cc8f4d02SIntel if (*end != '\0') { 563cc8f4d02SIntel if (strncmp(frmt_sec, end, sizeof(frmt_sec)) == 0) 564cc8f4d02SIntel v *= MS_PER_S; 565cc8f4d02SIntel else if (strncmp(frmt_msec, end, sizeof (frmt_msec)) != 0) 566693f715dSHuawei Xie return -EINVAL; 567cc8f4d02SIntel } 568cc8f4d02SIntel 569cc8f4d02SIntel if (v < min || v > max) 570693f715dSHuawei Xie return -EINVAL; 571cc8f4d02SIntel 572cc8f4d02SIntel *val = (uint32_t)v; 573693f715dSHuawei Xie return 0; 574cc8f4d02SIntel } 575cc8f4d02SIntel 576cc8f4d02SIntel static int 577cc8f4d02SIntel parse_portmask(const char *portmask) 578cc8f4d02SIntel { 579cc8f4d02SIntel char *end = NULL; 580cc8f4d02SIntel unsigned long pm; 581cc8f4d02SIntel 582cc8f4d02SIntel /* parse hexadecimal string */ 583cc8f4d02SIntel pm = strtoul(portmask, &end, 16); 584cc8f4d02SIntel if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) 585ce6b8c31SSarosh Arif return 0; 586cc8f4d02SIntel 587cc8f4d02SIntel return pm; 588cc8f4d02SIntel } 589cc8f4d02SIntel 590cc8f4d02SIntel static int 591b84fb4cbSAnatoly Burakov parse_nqueue(const char *q_arg) 592cc8f4d02SIntel { 593b84fb4cbSAnatoly Burakov char *end = NULL; 594b84fb4cbSAnatoly Burakov unsigned long n; 595cc8f4d02SIntel 596b84fb4cbSAnatoly Burakov printf("%p\n", q_arg); 597cc8f4d02SIntel 598b84fb4cbSAnatoly Burakov /* parse hexadecimal string */ 599b84fb4cbSAnatoly Burakov n = strtoul(q_arg, &end, 10); 600b84fb4cbSAnatoly Burakov if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 601b84fb4cbSAnatoly Burakov return -1; 602b84fb4cbSAnatoly Burakov if (n == 0) 603b84fb4cbSAnatoly Burakov return -1; 604b84fb4cbSAnatoly Burakov if (n >= MAX_RX_QUEUE_PER_LCORE) 605cc8f4d02SIntel return -1; 606cc8f4d02SIntel 607b84fb4cbSAnatoly Burakov return n; 608cc8f4d02SIntel } 609cc8f4d02SIntel 610cc8f4d02SIntel /* Parse the argument given in the command line of the application */ 611cc8f4d02SIntel static int 612cc8f4d02SIntel parse_args(int argc, char **argv) 613cc8f4d02SIntel { 614cc8f4d02SIntel int opt, ret; 615cc8f4d02SIntel char **argvopt; 616cc8f4d02SIntel int option_index; 617cc8f4d02SIntel char *prgname = argv[0]; 618cc8f4d02SIntel static struct option lgopts[] = { 619cc8f4d02SIntel {"maxflows", 1, 0, 0}, 620cc8f4d02SIntel {"flowttl", 1, 0, 0}, 621cc8f4d02SIntel {NULL, 0, 0, 0} 622cc8f4d02SIntel }; 623cc8f4d02SIntel 624cc8f4d02SIntel argvopt = argv; 625cc8f4d02SIntel 626b84fb4cbSAnatoly Burakov while ((opt = getopt_long(argc, argvopt, "p:q:", 627cc8f4d02SIntel lgopts, &option_index)) != EOF) { 628cc8f4d02SIntel 629cc8f4d02SIntel switch (opt) { 630cc8f4d02SIntel /* portmask */ 631cc8f4d02SIntel case 'p': 632cc8f4d02SIntel enabled_port_mask = parse_portmask(optarg); 633cc8f4d02SIntel if (enabled_port_mask == 0) { 634cc8f4d02SIntel printf("invalid portmask\n"); 635cc8f4d02SIntel print_usage(prgname); 636cc8f4d02SIntel return -1; 637cc8f4d02SIntel } 638cc8f4d02SIntel break; 639b84fb4cbSAnatoly Burakov 640b84fb4cbSAnatoly Burakov /* nqueue */ 641b84fb4cbSAnatoly Burakov case 'q': 642b84fb4cbSAnatoly Burakov rx_queue_per_lcore = parse_nqueue(optarg); 643b84fb4cbSAnatoly Burakov if (rx_queue_per_lcore < 0) { 644b84fb4cbSAnatoly Burakov printf("invalid queue number\n"); 645b84fb4cbSAnatoly Burakov print_usage(prgname); 646b84fb4cbSAnatoly Burakov return -1; 647b84fb4cbSAnatoly Burakov } 648cc8f4d02SIntel break; 649cc8f4d02SIntel 650cc8f4d02SIntel /* long options */ 651cc8f4d02SIntel case 0: 652cc8f4d02SIntel if (!strncmp(lgopts[option_index].name, 653cc8f4d02SIntel "maxflows", 8)) { 654cc8f4d02SIntel if ((ret = parse_flow_num(optarg, MIN_FLOW_NUM, 655cc8f4d02SIntel MAX_FLOW_NUM, 656cc8f4d02SIntel &max_flow_num)) != 0) { 657cc8f4d02SIntel printf("invalid value: \"%s\" for " 658cc8f4d02SIntel "parameter %s\n", 659cc8f4d02SIntel optarg, 660cc8f4d02SIntel lgopts[option_index].name); 661cc8f4d02SIntel print_usage(prgname); 662693f715dSHuawei Xie return ret; 663cc8f4d02SIntel } 664cc8f4d02SIntel } 665cc8f4d02SIntel 666cc8f4d02SIntel if (!strncmp(lgopts[option_index].name, "flowttl", 7)) { 667cc8f4d02SIntel if ((ret = parse_flow_ttl(optarg, MIN_FLOW_TTL, 668cc8f4d02SIntel MAX_FLOW_TTL, 669cc8f4d02SIntel &max_flow_ttl)) != 0) { 670cc8f4d02SIntel printf("invalid value: \"%s\" for " 671cc8f4d02SIntel "parameter %s\n", 672cc8f4d02SIntel optarg, 673cc8f4d02SIntel lgopts[option_index].name); 674cc8f4d02SIntel print_usage(prgname); 675693f715dSHuawei Xie return ret; 676cc8f4d02SIntel } 677cc8f4d02SIntel } 678cc8f4d02SIntel 679cc8f4d02SIntel break; 680cc8f4d02SIntel 681cc8f4d02SIntel default: 682cc8f4d02SIntel print_usage(prgname); 683cc8f4d02SIntel return -1; 684cc8f4d02SIntel } 685cc8f4d02SIntel } 686cc8f4d02SIntel 687cc8f4d02SIntel if (optind >= 0) 688cc8f4d02SIntel argv[optind-1] = prgname; 689cc8f4d02SIntel 690cc8f4d02SIntel ret = optind-1; 6919d5ca532SKeith Wiles optind = 1; /* reset getopt lib */ 692cc8f4d02SIntel return ret; 693cc8f4d02SIntel } 694cc8f4d02SIntel 695cc8f4d02SIntel static void 6966d13ea8eSOlivier Matz print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 697cc8f4d02SIntel { 69835b2d13fSOlivier Matz char buf[RTE_ETHER_ADDR_FMT_SIZE]; 69935b2d13fSOlivier Matz rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 700ec3d82dbSCunming Liang printf("%s%s", name, buf); 701cc8f4d02SIntel } 702cc8f4d02SIntel 703cc8f4d02SIntel /* Check the link status of all ports in up to 9s, and print them finally */ 704cc8f4d02SIntel static void 7058728ccf3SThomas Monjalon check_all_ports_link_status(uint32_t port_mask) 706cc8f4d02SIntel { 707cc8f4d02SIntel #define CHECK_INTERVAL 100 /* 100ms */ 708cc8f4d02SIntel #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ 709f8244c63SZhiyong Yang uint16_t portid; 710f8244c63SZhiyong Yang uint8_t count, all_ports_up, print_flag = 0; 711cc8f4d02SIntel struct rte_eth_link link; 71222e5c73bSIgor Romanov int ret; 713db4e8135SIvan Dyukov char link_status_text[RTE_ETH_LINK_MAX_STR_LEN]; 714cc8f4d02SIntel 715cc8f4d02SIntel printf("\nChecking link status"); 716cc8f4d02SIntel fflush(stdout); 717cc8f4d02SIntel for (count = 0; count <= MAX_CHECK_TIME; count++) { 718cc8f4d02SIntel all_ports_up = 1; 7198728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 720cc8f4d02SIntel if ((port_mask & (1 << portid)) == 0) 721cc8f4d02SIntel continue; 722cc8f4d02SIntel memset(&link, 0, sizeof(link)); 72322e5c73bSIgor Romanov ret = rte_eth_link_get_nowait(portid, &link); 72422e5c73bSIgor Romanov if (ret < 0) { 72522e5c73bSIgor Romanov all_ports_up = 0; 72622e5c73bSIgor Romanov if (print_flag == 1) 72722e5c73bSIgor Romanov printf("Port %u link get failed: %s\n", 72822e5c73bSIgor Romanov portid, rte_strerror(-ret)); 72922e5c73bSIgor Romanov continue; 73022e5c73bSIgor Romanov } 731cc8f4d02SIntel /* print link status if flag set */ 732cc8f4d02SIntel if (print_flag == 1) { 733db4e8135SIvan Dyukov rte_eth_link_to_str(link_status_text, 734db4e8135SIvan Dyukov sizeof(link_status_text), &link); 735db4e8135SIvan Dyukov printf("Port %d %s\n", portid, 736db4e8135SIvan Dyukov link_status_text); 737cc8f4d02SIntel continue; 738cc8f4d02SIntel } 739cc8f4d02SIntel /* clear all_ports_up flag if any link down */ 740295968d1SFerruh Yigit if (link.link_status == RTE_ETH_LINK_DOWN) { 741cc8f4d02SIntel all_ports_up = 0; 742cc8f4d02SIntel break; 743cc8f4d02SIntel } 744cc8f4d02SIntel } 745cc8f4d02SIntel /* after finally printing all link status, get out */ 746cc8f4d02SIntel if (print_flag == 1) 747cc8f4d02SIntel break; 748cc8f4d02SIntel 749cc8f4d02SIntel if (all_ports_up == 0) { 750cc8f4d02SIntel printf("."); 751cc8f4d02SIntel fflush(stdout); 752cc8f4d02SIntel rte_delay_ms(CHECK_INTERVAL); 753cc8f4d02SIntel } 754cc8f4d02SIntel 755cc8f4d02SIntel /* set the print_flag if all ports up or timeout */ 756cc8f4d02SIntel if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { 757cc8f4d02SIntel print_flag = 1; 758b84fb4cbSAnatoly Burakov printf("\ndone\n"); 759cc8f4d02SIntel } 760cc8f4d02SIntel } 761cc8f4d02SIntel } 762b84fb4cbSAnatoly Burakov 763b84fb4cbSAnatoly Burakov static int 764b84fb4cbSAnatoly Burakov init_routing_table(void) 765b84fb4cbSAnatoly Burakov { 766b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 767b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 768b84fb4cbSAnatoly Burakov int socket, ret; 769b84fb4cbSAnatoly Burakov unsigned i; 770b84fb4cbSAnatoly Burakov 771b84fb4cbSAnatoly Burakov for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) { 772b84fb4cbSAnatoly Burakov if (socket_lpm[socket]) { 773b84fb4cbSAnatoly Burakov lpm = socket_lpm[socket]; 774b84fb4cbSAnatoly Burakov /* populate the LPM table */ 775b84fb4cbSAnatoly Burakov for (i = 0; i < RTE_DIM(l3fwd_ipv4_route_array); i++) { 776b84fb4cbSAnatoly Burakov ret = rte_lpm_add(lpm, 777b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].ip, 778b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].depth, 779b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].if_out); 780b84fb4cbSAnatoly Burakov 781b84fb4cbSAnatoly Burakov if (ret < 0) { 782b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Unable to add entry %i to the l3fwd " 783b84fb4cbSAnatoly Burakov "LPM table\n", i); 784b84fb4cbSAnatoly Burakov return -1; 785b84fb4cbSAnatoly Burakov } 786b84fb4cbSAnatoly Burakov 787b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Socket %i: adding route " IPv4_BYTES_FMT 788b84fb4cbSAnatoly Burakov "/%d (port %d)\n", 789b84fb4cbSAnatoly Burakov socket, 790b84fb4cbSAnatoly Burakov IPv4_BYTES(l3fwd_ipv4_route_array[i].ip), 791b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].depth, 792b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].if_out); 793b84fb4cbSAnatoly Burakov } 794b84fb4cbSAnatoly Burakov } 795b84fb4cbSAnatoly Burakov 796b84fb4cbSAnatoly Burakov if (socket_lpm6[socket]) { 797b84fb4cbSAnatoly Burakov lpm6 = socket_lpm6[socket]; 798b84fb4cbSAnatoly Burakov /* populate the LPM6 table */ 799b84fb4cbSAnatoly Burakov for (i = 0; i < RTE_DIM(l3fwd_ipv6_route_array); i++) { 800b84fb4cbSAnatoly Burakov ret = rte_lpm6_add(lpm6, 801b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].ip, 802b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].depth, 803b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].if_out); 804b84fb4cbSAnatoly Burakov 805b84fb4cbSAnatoly Burakov if (ret < 0) { 806b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Unable to add entry %i to the l3fwd " 807b84fb4cbSAnatoly Burakov "LPM6 table\n", i); 808b84fb4cbSAnatoly Burakov return -1; 809b84fb4cbSAnatoly Burakov } 810b84fb4cbSAnatoly Burakov 811b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Socket %i: adding route " IPv6_BYTES_FMT 812b84fb4cbSAnatoly Burakov "/%d (port %d)\n", 813b84fb4cbSAnatoly Burakov socket, 814b84fb4cbSAnatoly Burakov IPv6_BYTES(l3fwd_ipv6_route_array[i].ip), 815b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].depth, 816b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].if_out); 817b84fb4cbSAnatoly Burakov } 818b84fb4cbSAnatoly Burakov } 819b84fb4cbSAnatoly Burakov } 820b84fb4cbSAnatoly Burakov return 0; 821b84fb4cbSAnatoly Burakov } 822b84fb4cbSAnatoly Burakov 823b84fb4cbSAnatoly Burakov static int 824b84fb4cbSAnatoly Burakov setup_port_tbl(struct lcore_queue_conf *qconf, uint32_t lcore, int socket, 825595ea7dcSIntel uint32_t port) 826595ea7dcSIntel { 827595ea7dcSIntel struct mbuf_table *mtb; 828595ea7dcSIntel uint32_t n; 829595ea7dcSIntel size_t sz; 830595ea7dcSIntel 831595ea7dcSIntel n = RTE_MAX(max_flow_num, 2UL * MAX_PKT_BURST); 832595ea7dcSIntel sz = sizeof (*mtb) + sizeof (mtb->m_table[0]) * n; 833595ea7dcSIntel 834fdf20fa7SSergio Gonzalez Monroy if ((mtb = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE, 835b84fb4cbSAnatoly Burakov socket)) == NULL) { 836b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "%s() for lcore: %u, port: %u " 837595ea7dcSIntel "failed to allocate %zu bytes\n", 838595ea7dcSIntel __func__, lcore, port, sz); 839b84fb4cbSAnatoly Burakov return -1; 840b84fb4cbSAnatoly Burakov } 841595ea7dcSIntel 842595ea7dcSIntel mtb->len = n; 843595ea7dcSIntel qconf->tx_mbufs[port] = mtb; 844b84fb4cbSAnatoly Burakov 845b84fb4cbSAnatoly Burakov return 0; 846595ea7dcSIntel } 847cc8f4d02SIntel 848b84fb4cbSAnatoly Burakov static int 849b84fb4cbSAnatoly Burakov setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) 850cc8f4d02SIntel { 851b84fb4cbSAnatoly Burakov int socket; 852cc8f4d02SIntel uint32_t nb_mbuf; 853cc8f4d02SIntel uint64_t frag_cycles; 854cc8f4d02SIntel char buf[RTE_MEMPOOL_NAMESIZE]; 855cc8f4d02SIntel 856b84fb4cbSAnatoly Burakov socket = rte_lcore_to_socket_id(lcore); 857b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 858b84fb4cbSAnatoly Burakov socket = 0; 859b84fb4cbSAnatoly Burakov 8609a212dc0SConor Fogarty /* Each table entry holds information about packet fragmentation. 8< */ 861cc8f4d02SIntel frag_cycles = (rte_get_tsc_hz() + MS_PER_S - 1) / MS_PER_S * 862cc8f4d02SIntel max_flow_ttl; 863cc8f4d02SIntel 864b84fb4cbSAnatoly Burakov if ((rxq->frag_tbl = rte_ip_frag_table_create(max_flow_num, 865b84fb4cbSAnatoly Burakov IP_FRAG_TBL_BUCKET_ENTRIES, max_flow_num, frag_cycles, 866b84fb4cbSAnatoly Burakov socket)) == NULL) { 867b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "ip_frag_tbl_create(%u) on " 868cc8f4d02SIntel "lcore: %u for queue: %u failed\n", 869cc8f4d02SIntel max_flow_num, lcore, queue); 870b84fb4cbSAnatoly Burakov return -1; 871b84fb4cbSAnatoly Burakov } 8729a212dc0SConor Fogarty /* >8 End of holding packet fragmentation. */ 873cc8f4d02SIntel 874595ea7dcSIntel /* 875d47bd10cSAnatoly Burakov * At any given moment up to <max_flow_num * (MAX_FRAG_NUM)> 876595ea7dcSIntel * mbufs could be stored int the fragment table. 877595ea7dcSIntel * Plus, each TX queue can hold up to <max_flow_num> packets. 878595ea7dcSIntel */ 879595ea7dcSIntel 8809a212dc0SConor Fogarty /* mbufs stored int the gragment table. 8< */ 881d47bd10cSAnatoly Burakov nb_mbuf = RTE_MAX(max_flow_num, 2UL * MAX_PKT_BURST) * MAX_FRAG_NUM; 8821bb4a528SFerruh Yigit nb_mbuf *= (port_conf.rxmode.mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN 8831bb4a528SFerruh Yigit + BUF_SIZE - 1) / BUF_SIZE; 884b84fb4cbSAnatoly Burakov nb_mbuf *= 2; /* ipv4 and ipv6 */ 88560efb44fSRoman Zhukov nb_mbuf += nb_rxd + nb_txd; 886595ea7dcSIntel 887b84fb4cbSAnatoly Burakov nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); 888cc8f4d02SIntel 8896f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); 890cc8f4d02SIntel 891b325a66aSAshish Jain rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, 892b325a66aSAshish Jain MBUF_DATA_SIZE, socket); 893b325a66aSAshish Jain if (rxq->pool == NULL) { 894b325a66aSAshish Jain RTE_LOG(ERR, IP_RSMBL, 895b325a66aSAshish Jain "rte_pktmbuf_pool_create(%s) failed", buf); 896b84fb4cbSAnatoly Burakov return -1; 897b84fb4cbSAnatoly Burakov } 8989a212dc0SConor Fogarty /* >8 End of mbufs stored int the fragmentation table. */ 899b84fb4cbSAnatoly Burakov 900b84fb4cbSAnatoly Burakov return 0; 901b84fb4cbSAnatoly Burakov } 902b84fb4cbSAnatoly Burakov 903b84fb4cbSAnatoly Burakov static int 904b84fb4cbSAnatoly Burakov init_mem(void) 905b84fb4cbSAnatoly Burakov { 906b84fb4cbSAnatoly Burakov char buf[PATH_MAX]; 907b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 908b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 909f1f72618SMichal Kobylinski struct rte_lpm_config lpm_config; 910b84fb4cbSAnatoly Burakov int socket; 911b84fb4cbSAnatoly Burakov unsigned lcore_id; 912b84fb4cbSAnatoly Burakov 913b84fb4cbSAnatoly Burakov /* traverse through lcores and initialize structures on each socket */ 914b84fb4cbSAnatoly Burakov 915b84fb4cbSAnatoly Burakov for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 916b84fb4cbSAnatoly Burakov 917b84fb4cbSAnatoly Burakov if (rte_lcore_is_enabled(lcore_id) == 0) 918b84fb4cbSAnatoly Burakov continue; 919b84fb4cbSAnatoly Burakov 920b84fb4cbSAnatoly Burakov socket = rte_lcore_to_socket_id(lcore_id); 921b84fb4cbSAnatoly Burakov 922b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 923b84fb4cbSAnatoly Burakov socket = 0; 924b84fb4cbSAnatoly Burakov 925b84fb4cbSAnatoly Burakov if (socket_lpm[socket] == NULL) { 926b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Creating LPM table on socket %i\n", socket); 9276f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "IP_RSMBL_LPM_%i", socket); 928b84fb4cbSAnatoly Burakov 929f1f72618SMichal Kobylinski lpm_config.max_rules = LPM_MAX_RULES; 930f1f72618SMichal Kobylinski lpm_config.number_tbl8s = 256; 931f1f72618SMichal Kobylinski lpm_config.flags = 0; 932f1f72618SMichal Kobylinski 933f1f72618SMichal Kobylinski lpm = rte_lpm_create(buf, socket, &lpm_config); 934b84fb4cbSAnatoly Burakov if (lpm == NULL) { 935b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Cannot create LPM table\n"); 936b84fb4cbSAnatoly Burakov return -1; 937b84fb4cbSAnatoly Burakov } 938b84fb4cbSAnatoly Burakov socket_lpm[socket] = lpm; 939b84fb4cbSAnatoly Burakov } 940b84fb4cbSAnatoly Burakov 941b84fb4cbSAnatoly Burakov if (socket_lpm6[socket] == NULL) { 942b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Creating LPM6 table on socket %i\n", socket); 9436f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "IP_RSMBL_LPM_%i", socket); 944b84fb4cbSAnatoly Burakov 945d1082cdeSOlivier Matz lpm6 = rte_lpm6_create(buf, socket, &lpm6_config); 946b84fb4cbSAnatoly Burakov if (lpm6 == NULL) { 947b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Cannot create LPM table\n"); 948b84fb4cbSAnatoly Burakov return -1; 949b84fb4cbSAnatoly Burakov } 950b84fb4cbSAnatoly Burakov socket_lpm6[socket] = lpm6; 951b84fb4cbSAnatoly Burakov } 952b84fb4cbSAnatoly Burakov } 953b84fb4cbSAnatoly Burakov 954b84fb4cbSAnatoly Burakov return 0; 955cc8f4d02SIntel } 956cc8f4d02SIntel 957cc8f4d02SIntel static void 958595ea7dcSIntel queue_dump_stat(void) 959cc8f4d02SIntel { 960cc8f4d02SIntel uint32_t i, lcore; 961b84fb4cbSAnatoly Burakov const struct lcore_queue_conf *qconf; 962cc8f4d02SIntel 963cc8f4d02SIntel for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { 964cc8f4d02SIntel if (rte_lcore_is_enabled(lcore) == 0) 965cc8f4d02SIntel continue; 966cc8f4d02SIntel 967b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore]; 968cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; i++) { 969cc8f4d02SIntel 970f8244c63SZhiyong Yang fprintf(stdout, " -- lcoreid=%u portid=%u " 971b84fb4cbSAnatoly Burakov "frag tbl stat:\n", 972b84fb4cbSAnatoly Burakov lcore, qconf->rx_queue_list[i].portid); 973b84fb4cbSAnatoly Burakov rte_ip_frag_table_statistics_dump(stdout, 974b84fb4cbSAnatoly Burakov qconf->rx_queue_list[i].frag_tbl); 975595ea7dcSIntel fprintf(stdout, "TX bursts:\t%" PRIu64 "\n" 976595ea7dcSIntel "TX packets _queued:\t%" PRIu64 "\n" 977595ea7dcSIntel "TX packets dropped:\t%" PRIu64 "\n" 978595ea7dcSIntel "TX packets send:\t%" PRIu64 "\n", 979595ea7dcSIntel qconf->tx_stat.call, 980595ea7dcSIntel qconf->tx_stat.queue, 981595ea7dcSIntel qconf->tx_stat.drop, 982595ea7dcSIntel qconf->tx_stat.send); 983cc8f4d02SIntel } 984cc8f4d02SIntel } 985cc8f4d02SIntel } 986cc8f4d02SIntel 987cc8f4d02SIntel static void 988cc8f4d02SIntel signal_handler(int signum) 989cc8f4d02SIntel { 990595ea7dcSIntel queue_dump_stat(); 991cc8f4d02SIntel if (signum != SIGUSR1) 992cc8f4d02SIntel rte_exit(0, "received signal: %d, exiting\n", signum); 993cc8f4d02SIntel } 994cc8f4d02SIntel 995cc8f4d02SIntel int 99698a16481SDavid Marchand main(int argc, char **argv) 997cc8f4d02SIntel { 998b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 99981f7ecd9SPablo de Lara struct rte_eth_dev_info dev_info; 100081f7ecd9SPablo de Lara struct rte_eth_txconf *txconf; 1001b84fb4cbSAnatoly Burakov struct rx_queue *rxq; 1002b84fb4cbSAnatoly Burakov int ret, socket; 1003cc8f4d02SIntel unsigned nb_ports; 1004cc8f4d02SIntel uint16_t queueid; 1005b84fb4cbSAnatoly Burakov unsigned lcore_id = 0, rx_lcore_id = 0; 1006cc8f4d02SIntel uint32_t n_tx_queue, nb_lcores; 1007f8244c63SZhiyong Yang uint16_t portid; 1008cc8f4d02SIntel 1009cc8f4d02SIntel /* init EAL */ 1010cc8f4d02SIntel ret = rte_eal_init(argc, argv); 1011cc8f4d02SIntel if (ret < 0) 1012cc8f4d02SIntel rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n"); 1013cc8f4d02SIntel argc -= ret; 1014cc8f4d02SIntel argv += ret; 1015cc8f4d02SIntel 1016cc8f4d02SIntel /* parse application arguments (after the EAL ones) */ 1017cc8f4d02SIntel ret = parse_args(argc, argv); 1018cc8f4d02SIntel if (ret < 0) 1019b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Invalid IP reassembly parameters\n"); 1020cc8f4d02SIntel 1021d9a42a69SThomas Monjalon nb_ports = rte_eth_dev_count_avail(); 1022b4e0f64fSMauricio Vasquez B if (nb_ports == 0) 1023b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "No ports found!\n"); 1024cc8f4d02SIntel 1025cc8f4d02SIntel nb_lcores = rte_lcore_count(); 1026cc8f4d02SIntel 1027b84fb4cbSAnatoly Burakov /* initialize structures (mempools, lpm etc.) */ 1028b84fb4cbSAnatoly Burakov if (init_mem() < 0) 1029b84fb4cbSAnatoly Burakov rte_panic("Cannot initialize memory structures!\n"); 1030b84fb4cbSAnatoly Burakov 1031eaa8d3bfSAnatoly Burakov /* check if portmask has non-existent ports */ 1032eaa8d3bfSAnatoly Burakov if (enabled_port_mask & ~(RTE_LEN2MASK(nb_ports, unsigned))) 1033eaa8d3bfSAnatoly Burakov rte_exit(EXIT_FAILURE, "Non-existent ports in portmask!\n"); 1034eaa8d3bfSAnatoly Burakov 1035cc8f4d02SIntel /* initialize all ports */ 10368728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 10379df56e69SShahaf Shuler struct rte_eth_rxconf rxq_conf; 10389df56e69SShahaf Shuler struct rte_eth_conf local_port_conf = port_conf; 10399df56e69SShahaf Shuler 1040cc8f4d02SIntel /* skip ports that are not enabled */ 1041cc8f4d02SIntel if ((enabled_port_mask & (1 << portid)) == 0) { 1042cc8f4d02SIntel printf("\nSkipping disabled port %d\n", portid); 1043cc8f4d02SIntel continue; 1044cc8f4d02SIntel } 1045cc8f4d02SIntel 1046b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[rx_lcore_id]; 1047b84fb4cbSAnatoly Burakov 10485e470a66SAndriy Berestovskyy /* limit the frame size to the maximum supported by NIC */ 1049089e5ed7SIvan Ilchenko ret = rte_eth_dev_info_get(portid, &dev_info); 1050089e5ed7SIvan Ilchenko if (ret != 0) 1051089e5ed7SIvan Ilchenko rte_exit(EXIT_FAILURE, 1052089e5ed7SIvan Ilchenko "Error during getting device (port %u) info: %s\n", 1053089e5ed7SIvan Ilchenko portid, strerror(-ret)); 1054089e5ed7SIvan Ilchenko 10551bb4a528SFerruh Yigit local_port_conf.rxmode.mtu = RTE_MIN( 10561bb4a528SFerruh Yigit dev_info.max_mtu, 10571bb4a528SFerruh Yigit local_port_conf.rxmode.mtu); 10585e470a66SAndriy Berestovskyy 1059b84fb4cbSAnatoly Burakov /* get the lcore_id for this port */ 1060b84fb4cbSAnatoly Burakov while (rte_lcore_is_enabled(rx_lcore_id) == 0 || 1061b84fb4cbSAnatoly Burakov qconf->n_rx_queue == (unsigned)rx_queue_per_lcore) { 1062b84fb4cbSAnatoly Burakov 1063b84fb4cbSAnatoly Burakov rx_lcore_id++; 1064b84fb4cbSAnatoly Burakov if (rx_lcore_id >= RTE_MAX_LCORE) 1065b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Not enough cores\n"); 1066b84fb4cbSAnatoly Burakov 1067b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[rx_lcore_id]; 1068b84fb4cbSAnatoly Burakov } 1069b84fb4cbSAnatoly Burakov 1070324bcf45SAnatoly Burakov socket = rte_lcore_to_socket_id(portid); 1071b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 1072b84fb4cbSAnatoly Burakov socket = 0; 1073b84fb4cbSAnatoly Burakov 1074b84fb4cbSAnatoly Burakov queueid = qconf->n_rx_queue; 1075b84fb4cbSAnatoly Burakov rxq = &qconf->rx_queue_list[queueid]; 1076b84fb4cbSAnatoly Burakov rxq->portid = portid; 1077b84fb4cbSAnatoly Burakov rxq->lpm = socket_lpm[socket]; 1078b84fb4cbSAnatoly Burakov rxq->lpm6 = socket_lpm6[socket]; 107960efb44fSRoman Zhukov 108060efb44fSRoman Zhukov ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, 108160efb44fSRoman Zhukov &nb_txd); 108260efb44fSRoman Zhukov if (ret < 0) 108360efb44fSRoman Zhukov rte_exit(EXIT_FAILURE, 108460efb44fSRoman Zhukov "Cannot adjust number of descriptors: err=%d, port=%d\n", 108560efb44fSRoman Zhukov ret, portid); 108660efb44fSRoman Zhukov 1087b84fb4cbSAnatoly Burakov if (setup_queue_tbl(rxq, rx_lcore_id, queueid) < 0) 1088b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Failed to set up queue table\n"); 1089b84fb4cbSAnatoly Burakov qconf->n_rx_queue++; 1090b84fb4cbSAnatoly Burakov 1091cc8f4d02SIntel /* init port */ 1092cc8f4d02SIntel printf("Initializing port %d ... ", portid ); 1093cc8f4d02SIntel fflush(stdout); 1094cc8f4d02SIntel 1095cc8f4d02SIntel n_tx_queue = nb_lcores; 1096cc8f4d02SIntel if (n_tx_queue > MAX_TX_QUEUE_PER_PORT) 1097cc8f4d02SIntel n_tx_queue = MAX_TX_QUEUE_PER_PORT; 1098295968d1SFerruh Yigit if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) 10999df56e69SShahaf Shuler local_port_conf.txmode.offloads |= 1100295968d1SFerruh Yigit RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE; 11014f5701f2SFerruh Yigit 11024f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 11034f5701f2SFerruh Yigit dev_info.flow_type_rss_offloads; 11044f5701f2SFerruh Yigit if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 11054f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf) { 11064f5701f2SFerruh Yigit printf("Port %u modified RSS hash function based on hardware support," 11074f5701f2SFerruh Yigit "requested:%#"PRIx64" configured:%#"PRIx64"\n", 11084f5701f2SFerruh Yigit portid, 11094f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf, 11104f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf); 11114f5701f2SFerruh Yigit } 11124f5701f2SFerruh Yigit 1113b84fb4cbSAnatoly Burakov ret = rte_eth_dev_configure(portid, 1, (uint16_t)n_tx_queue, 11149df56e69SShahaf Shuler &local_port_conf); 1115b84fb4cbSAnatoly Burakov if (ret < 0) { 1116b84fb4cbSAnatoly Burakov printf("\n"); 1117b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Cannot configure device: " 1118b84fb4cbSAnatoly Burakov "err=%d, port=%d\n", 1119cc8f4d02SIntel ret, portid); 1120b84fb4cbSAnatoly Burakov } 1121b84fb4cbSAnatoly Burakov 1122b84fb4cbSAnatoly Burakov /* init one RX queue */ 11239df56e69SShahaf Shuler rxq_conf = dev_info.default_rxconf; 11249df56e69SShahaf Shuler rxq_conf.offloads = local_port_conf.rxmode.offloads; 1125b84fb4cbSAnatoly Burakov ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, 11269df56e69SShahaf Shuler socket, &rxq_conf, 1127b84fb4cbSAnatoly Burakov rxq->pool); 1128b84fb4cbSAnatoly Burakov if (ret < 0) { 1129b84fb4cbSAnatoly Burakov printf("\n"); 1130b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: " 1131b84fb4cbSAnatoly Burakov "err=%d, port=%d\n", 1132b84fb4cbSAnatoly Burakov ret, portid); 1133b84fb4cbSAnatoly Burakov } 1134cc8f4d02SIntel 113570febdcfSIgor Romanov ret = rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); 113670febdcfSIgor Romanov if (ret < 0) { 113770febdcfSIgor Romanov printf("\n"); 113870febdcfSIgor Romanov rte_exit(EXIT_FAILURE, 113970febdcfSIgor Romanov "rte_eth_macaddr_get: err=%d, port=%d\n", 114070febdcfSIgor Romanov ret, portid); 114170febdcfSIgor Romanov } 114270febdcfSIgor Romanov 1143cc8f4d02SIntel print_ethaddr(" Address:", &ports_eth_addr[portid]); 1144b84fb4cbSAnatoly Burakov printf("\n"); 1145cc8f4d02SIntel 1146cc8f4d02SIntel /* init one TX queue per couple (lcore,port) */ 1147cc8f4d02SIntel queueid = 0; 1148cc8f4d02SIntel for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1149cc8f4d02SIntel if (rte_lcore_is_enabled(lcore_id) == 0) 1150cc8f4d02SIntel continue; 1151cc8f4d02SIntel 1152b84fb4cbSAnatoly Burakov socket = (int) rte_lcore_to_socket_id(lcore_id); 1153cc8f4d02SIntel 1154b84fb4cbSAnatoly Burakov printf("txq=%u,%d,%d ", lcore_id, queueid, socket); 1155cc8f4d02SIntel fflush(stdout); 115681f7ecd9SPablo de Lara 115781f7ecd9SPablo de Lara txconf = &dev_info.default_txconf; 11589df56e69SShahaf Shuler txconf->offloads = local_port_conf.txmode.offloads; 115981f7ecd9SPablo de Lara 1160cc8f4d02SIntel ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd, 116181f7ecd9SPablo de Lara socket, txconf); 1162cc8f4d02SIntel if (ret < 0) 1163cc8f4d02SIntel rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, " 1164cc8f4d02SIntel "port=%d\n", ret, portid); 1165cc8f4d02SIntel 1166b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 1167cc8f4d02SIntel qconf->tx_queue_id[portid] = queueid; 1168b84fb4cbSAnatoly Burakov setup_port_tbl(qconf, lcore_id, socket, portid); 1169cc8f4d02SIntel queueid++; 1170cc8f4d02SIntel } 1171cc8f4d02SIntel printf("\n"); 1172cc8f4d02SIntel } 1173cc8f4d02SIntel 1174cc8f4d02SIntel printf("\n"); 1175cc8f4d02SIntel 1176cc8f4d02SIntel /* start ports */ 11778728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 1178cc8f4d02SIntel if ((enabled_port_mask & (1 << portid)) == 0) { 1179cc8f4d02SIntel continue; 1180cc8f4d02SIntel } 1181cc8f4d02SIntel /* Start device */ 1182cc8f4d02SIntel ret = rte_eth_dev_start(portid); 1183cc8f4d02SIntel if (ret < 0) 1184cc8f4d02SIntel rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", 1185cc8f4d02SIntel ret, portid); 1186cc8f4d02SIntel 1187f430bbceSIvan Ilchenko ret = rte_eth_promiscuous_enable(portid); 1188f430bbceSIvan Ilchenko if (ret != 0) 1189f430bbceSIvan Ilchenko rte_exit(EXIT_FAILURE, 1190f430bbceSIvan Ilchenko "rte_eth_promiscuous_enable: err=%s, port=%d\n", 1191f430bbceSIvan Ilchenko rte_strerror(-ret), portid); 1192cc8f4d02SIntel } 1193cc8f4d02SIntel 1194b84fb4cbSAnatoly Burakov if (init_routing_table() < 0) 1195b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Cannot init routing table\n"); 1196b84fb4cbSAnatoly Burakov 11978728ccf3SThomas Monjalon check_all_ports_link_status(enabled_port_mask); 1198cc8f4d02SIntel 1199cc8f4d02SIntel signal(SIGUSR1, signal_handler); 1200cc8f4d02SIntel signal(SIGTERM, signal_handler); 1201cc8f4d02SIntel signal(SIGINT, signal_handler); 1202cc8f4d02SIntel 1203cc8f4d02SIntel /* launch per-lcore init on every lcore */ 1204cb056611SStephen Hemminger rte_eal_mp_remote_launch(main_loop, NULL, CALL_MAIN); 1205cb056611SStephen Hemminger RTE_LCORE_FOREACH_WORKER(lcore_id) { 1206cc8f4d02SIntel if (rte_eal_wait_lcore(lcore_id) < 0) 1207cc8f4d02SIntel return -1; 1208cc8f4d02SIntel } 1209cc8f4d02SIntel 121010aa3757SChengchang Tang /* clean up the EAL */ 121110aa3757SChengchang Tang rte_eal_cleanup(); 121210aa3757SChengchang Tang 1213cc8f4d02SIntel return 0; 1214cc8f4d02SIntel } 1215