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_atomic.h> 26cc8f4d02SIntel #include <rte_cycles.h> 27cc8f4d02SIntel #include <rte_prefetch.h> 28cc8f4d02SIntel #include <rte_lcore.h> 29cc8f4d02SIntel #include <rte_per_lcore.h> 30cc8f4d02SIntel #include <rte_branch_prediction.h> 31cc8f4d02SIntel #include <rte_interrupts.h> 32cc8f4d02SIntel #include <rte_random.h> 33cc8f4d02SIntel #include <rte_debug.h> 34cc8f4d02SIntel #include <rte_ether.h> 35cc8f4d02SIntel #include <rte_ethdev.h> 36cc8f4d02SIntel #include <rte_mempool.h> 37cc8f4d02SIntel #include <rte_mbuf.h> 38cc8f4d02SIntel #include <rte_malloc.h> 39cc8f4d02SIntel #include <rte_ip.h> 40cc8f4d02SIntel #include <rte_tcp.h> 41cc8f4d02SIntel #include <rte_udp.h> 42cc8f4d02SIntel #include <rte_string_fns.h> 43cc8f4d02SIntel #include <rte_lpm.h> 44cc8f4d02SIntel #include <rte_lpm6.h> 45b84fb4cbSAnatoly Burakov 46b84fb4cbSAnatoly Burakov #include <rte_ip_frag.h> 47b84fb4cbSAnatoly Burakov 48595ea7dcSIntel #define MAX_PKT_BURST 32 49595ea7dcSIntel 50595ea7dcSIntel 51b84fb4cbSAnatoly Burakov #define RTE_LOGTYPE_IP_RSMBL RTE_LOGTYPE_USER1 52cc8f4d02SIntel 53cc8f4d02SIntel #define MAX_JUMBO_PKT_LEN 9600 54cc8f4d02SIntel 55824cb29cSKonstantin Ananyev #define BUF_SIZE RTE_MBUF_DEFAULT_DATAROOM 56b325a66aSAshish Jain #define MBUF_DATA_SIZE RTE_MBUF_DEFAULT_BUF_SIZE 57cc8f4d02SIntel 58b84fb4cbSAnatoly Burakov #define NB_MBUF 8192 59b325a66aSAshish Jain #define MEMPOOL_CACHE_SIZE 256 60b84fb4cbSAnatoly Burakov 61b84fb4cbSAnatoly Burakov /* allow max jumbo frame 9.5 KB */ 62b84fb4cbSAnatoly Burakov #define JUMBO_FRAME_MAX_SIZE 0x2600 63b84fb4cbSAnatoly Burakov 64cc8f4d02SIntel #define MAX_FLOW_NUM UINT16_MAX 65cc8f4d02SIntel #define MIN_FLOW_NUM 1 66cc8f4d02SIntel #define DEF_FLOW_NUM 0x1000 67cc8f4d02SIntel 68cc8f4d02SIntel /* TTL numbers are in ms. */ 69cc8f4d02SIntel #define MAX_FLOW_TTL (3600 * MS_PER_S) 70cc8f4d02SIntel #define MIN_FLOW_TTL 1 71cc8f4d02SIntel #define DEF_FLOW_TTL MS_PER_S 72cc8f4d02SIntel 73b84fb4cbSAnatoly Burakov #define MAX_FRAG_NUM RTE_LIBRTE_IP_FRAG_MAX_FRAG 74cc8f4d02SIntel 75cc8f4d02SIntel /* Should be power of two. */ 76b84fb4cbSAnatoly Burakov #define IP_FRAG_TBL_BUCKET_ENTRIES 16 77cc8f4d02SIntel 78cc8f4d02SIntel static uint32_t max_flow_num = DEF_FLOW_NUM; 79cc8f4d02SIntel static uint32_t max_flow_ttl = DEF_FLOW_TTL; 80cc8f4d02SIntel 81cc8f4d02SIntel #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 82cc8f4d02SIntel 83cc8f4d02SIntel #define NB_SOCKETS 8 84cc8f4d02SIntel 85cc8f4d02SIntel /* Configure how many packets ahead to prefetch, when reading packets */ 86cc8f4d02SIntel #define PREFETCH_OFFSET 3 87cc8f4d02SIntel 88cc8f4d02SIntel /* 89cc8f4d02SIntel * Configurable number of RX/TX ring descriptors 90cc8f4d02SIntel */ 91867a6c66SKevin Laatz #define RTE_TEST_RX_DESC_DEFAULT 1024 92867a6c66SKevin Laatz #define RTE_TEST_TX_DESC_DEFAULT 1024 93595ea7dcSIntel 94cc8f4d02SIntel static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; 95cc8f4d02SIntel static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; 96cc8f4d02SIntel 97cc8f4d02SIntel /* ethernet addresses of ports */ 986d13ea8eSOlivier Matz static struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; 99b84fb4cbSAnatoly Burakov 100b84fb4cbSAnatoly Burakov #ifndef IPv4_BYTES 101b84fb4cbSAnatoly Burakov #define IPv4_BYTES_FMT "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 102b84fb4cbSAnatoly Burakov #define IPv4_BYTES(addr) \ 103b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 24) & 0xFF),\ 104b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 16) & 0xFF),\ 105b84fb4cbSAnatoly Burakov (uint8_t) (((addr) >> 8) & 0xFF),\ 106b84fb4cbSAnatoly Burakov (uint8_t) ((addr) & 0xFF) 107b84fb4cbSAnatoly Burakov #endif 108b84fb4cbSAnatoly Burakov 109b84fb4cbSAnatoly Burakov #ifndef IPv6_BYTES 110b84fb4cbSAnatoly Burakov #define IPv6_BYTES_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"\ 111b84fb4cbSAnatoly Burakov "%02x%02x:%02x%02x:%02x%02x:%02x%02x" 112b84fb4cbSAnatoly Burakov #define IPv6_BYTES(addr) \ 113b84fb4cbSAnatoly Burakov addr[0], addr[1], addr[2], addr[3], \ 114b84fb4cbSAnatoly Burakov addr[4], addr[5], addr[6], addr[7], \ 115b84fb4cbSAnatoly Burakov addr[8], addr[9], addr[10], addr[11],\ 116b84fb4cbSAnatoly Burakov addr[12], addr[13],addr[14], addr[15] 117b84fb4cbSAnatoly Burakov #endif 118b84fb4cbSAnatoly Burakov 119b84fb4cbSAnatoly Burakov #define IPV6_ADDR_LEN 16 120cc8f4d02SIntel 121cc8f4d02SIntel /* mask of enabled ports */ 122cc8f4d02SIntel static uint32_t enabled_port_mask = 0; 123b84fb4cbSAnatoly Burakov 124b84fb4cbSAnatoly Burakov static int rx_queue_per_lcore = 1; 125cc8f4d02SIntel 126cc8f4d02SIntel struct mbuf_table { 127595ea7dcSIntel uint32_t len; 128595ea7dcSIntel uint32_t head; 129595ea7dcSIntel uint32_t tail; 130595ea7dcSIntel struct rte_mbuf *m_table[0]; 131cc8f4d02SIntel }; 132cc8f4d02SIntel 133b84fb4cbSAnatoly Burakov struct rx_queue { 134b84fb4cbSAnatoly Burakov struct rte_ip_frag_tbl *frag_tbl; 135b84fb4cbSAnatoly Burakov struct rte_mempool *pool; 136b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 137b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 138f8244c63SZhiyong Yang uint16_t portid; 139cc8f4d02SIntel }; 140cc8f4d02SIntel 141b84fb4cbSAnatoly Burakov struct tx_lcore_stat { 142b84fb4cbSAnatoly Burakov uint64_t call; 143b84fb4cbSAnatoly Burakov uint64_t drop; 144b84fb4cbSAnatoly Burakov uint64_t queue; 145b84fb4cbSAnatoly Burakov uint64_t send; 146b84fb4cbSAnatoly Burakov }; 147b84fb4cbSAnatoly Burakov 148b84fb4cbSAnatoly Burakov #define MAX_RX_QUEUE_PER_LCORE 16 149b84fb4cbSAnatoly Burakov #define MAX_TX_QUEUE_PER_PORT 16 150b84fb4cbSAnatoly Burakov #define MAX_RX_QUEUE_PER_PORT 128 151b84fb4cbSAnatoly Burakov 152b84fb4cbSAnatoly Burakov struct lcore_queue_conf { 153b84fb4cbSAnatoly Burakov uint16_t n_rx_queue; 154b84fb4cbSAnatoly Burakov struct rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE]; 155b84fb4cbSAnatoly Burakov uint16_t tx_queue_id[RTE_MAX_ETHPORTS]; 156b84fb4cbSAnatoly Burakov struct rte_ip_frag_death_row death_row; 157b84fb4cbSAnatoly Burakov struct mbuf_table *tx_mbufs[RTE_MAX_ETHPORTS]; 158b84fb4cbSAnatoly Burakov struct tx_lcore_stat tx_stat; 159b84fb4cbSAnatoly Burakov } __rte_cache_aligned; 160b84fb4cbSAnatoly Burakov static struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE]; 161cc8f4d02SIntel 162cc8f4d02SIntel static struct rte_eth_conf port_conf = { 163cc8f4d02SIntel .rxmode = { 16413c4ebd6SBruce Richardson .mq_mode = ETH_MQ_RX_RSS, 165b84fb4cbSAnatoly Burakov .max_rx_pkt_len = JUMBO_FRAME_MAX_SIZE, 166cc8f4d02SIntel .split_hdr_size = 0, 1679df56e69SShahaf Shuler .offloads = (DEV_RX_OFFLOAD_CHECKSUM | 168323e7b66SFerruh Yigit DEV_RX_OFFLOAD_JUMBO_FRAME), 169cc8f4d02SIntel }, 170cc8f4d02SIntel .rx_adv_conf = { 171cc8f4d02SIntel .rss_conf = { 172cc8f4d02SIntel .rss_key = NULL, 1738a387fa8SHelin Zhang .rss_hf = ETH_RSS_IP, 174cc8f4d02SIntel }, 175cc8f4d02SIntel }, 176cc8f4d02SIntel .txmode = { 177cc8f4d02SIntel .mq_mode = ETH_MQ_TX_NONE, 1789df56e69SShahaf Shuler .offloads = (DEV_TX_OFFLOAD_IPV4_CKSUM | 1799df56e69SShahaf Shuler DEV_TX_OFFLOAD_MULTI_SEGS), 180cc8f4d02SIntel }, 181cc8f4d02SIntel }; 182cc8f4d02SIntel 183b84fb4cbSAnatoly Burakov /* 184b84fb4cbSAnatoly Burakov * IPv4 forwarding table 185b84fb4cbSAnatoly Burakov */ 186b84fb4cbSAnatoly Burakov struct l3fwd_ipv4_route { 187cc8f4d02SIntel uint32_t ip; 188cc8f4d02SIntel uint8_t depth; 189cc8f4d02SIntel uint8_t if_out; 190cc8f4d02SIntel }; 191cc8f4d02SIntel 192b84fb4cbSAnatoly Burakov struct l3fwd_ipv4_route l3fwd_ipv4_route_array[] = { 193b84fb4cbSAnatoly Burakov {IPv4(100,10,0,0), 16, 0}, 194b84fb4cbSAnatoly Burakov {IPv4(100,20,0,0), 16, 1}, 195b84fb4cbSAnatoly Burakov {IPv4(100,30,0,0), 16, 2}, 196b84fb4cbSAnatoly Burakov {IPv4(100,40,0,0), 16, 3}, 197b84fb4cbSAnatoly Burakov {IPv4(100,50,0,0), 16, 4}, 198b84fb4cbSAnatoly Burakov {IPv4(100,60,0,0), 16, 5}, 199b84fb4cbSAnatoly Burakov {IPv4(100,70,0,0), 16, 6}, 200b84fb4cbSAnatoly Burakov {IPv4(100,80,0,0), 16, 7}, 201b84fb4cbSAnatoly Burakov }; 202b84fb4cbSAnatoly Burakov 203b84fb4cbSAnatoly Burakov /* 204b84fb4cbSAnatoly Burakov * IPv6 forwarding table 205b84fb4cbSAnatoly Burakov */ 206b84fb4cbSAnatoly Burakov 207b84fb4cbSAnatoly Burakov struct l3fwd_ipv6_route { 208b84fb4cbSAnatoly Burakov uint8_t ip[IPV6_ADDR_LEN]; 209cc8f4d02SIntel uint8_t depth; 210cc8f4d02SIntel uint8_t if_out; 211cc8f4d02SIntel }; 212cc8f4d02SIntel 213b84fb4cbSAnatoly Burakov static struct l3fwd_ipv6_route l3fwd_ipv6_route_array[] = { 214cc8f4d02SIntel {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 0}, 215cc8f4d02SIntel {{2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 1}, 216cc8f4d02SIntel {{3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 2}, 217cc8f4d02SIntel {{4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 3}, 218cc8f4d02SIntel {{5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 4}, 219cc8f4d02SIntel {{6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 5}, 220cc8f4d02SIntel {{7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 6}, 221cc8f4d02SIntel {{8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 48, 7}, 222cc8f4d02SIntel }; 223cc8f4d02SIntel 224b84fb4cbSAnatoly Burakov #define LPM_MAX_RULES 1024 225b84fb4cbSAnatoly Burakov #define LPM6_MAX_RULES 1024 226b84fb4cbSAnatoly Burakov #define LPM6_NUMBER_TBL8S (1 << 16) 227cc8f4d02SIntel 228b84fb4cbSAnatoly Burakov struct rte_lpm6_config lpm6_config = { 229b84fb4cbSAnatoly Burakov .max_rules = LPM6_MAX_RULES, 230b84fb4cbSAnatoly Burakov .number_tbl8s = LPM6_NUMBER_TBL8S, 231b84fb4cbSAnatoly Burakov .flags = 0 232595ea7dcSIntel }; 233595ea7dcSIntel 234b84fb4cbSAnatoly Burakov static struct rte_lpm *socket_lpm[RTE_MAX_NUMA_NODES]; 235b84fb4cbSAnatoly Burakov static struct rte_lpm6 *socket_lpm6[RTE_MAX_NUMA_NODES]; 236b84fb4cbSAnatoly Burakov 237240952a9SAnatoly Burakov #ifdef RTE_LIBRTE_IP_FRAG_TBL_STAT 238595ea7dcSIntel #define TX_LCORE_STAT_UPDATE(s, f, v) ((s)->f += (v)) 239595ea7dcSIntel #else 240595ea7dcSIntel #define TX_LCORE_STAT_UPDATE(s, f, v) do {} while (0) 241240952a9SAnatoly Burakov #endif /* RTE_LIBRTE_IP_FRAG_TBL_STAT */ 242cc8f4d02SIntel 243595ea7dcSIntel /* 244595ea7dcSIntel * If number of queued packets reached given threahold, then 245595ea7dcSIntel * send burst of packets on an output interface. 246595ea7dcSIntel */ 247595ea7dcSIntel static inline uint32_t 248f8244c63SZhiyong Yang send_burst(struct lcore_queue_conf *qconf, uint32_t thresh, uint16_t port) 249cc8f4d02SIntel { 250595ea7dcSIntel uint32_t fill, len, k, n; 251595ea7dcSIntel struct mbuf_table *txmb; 252cc8f4d02SIntel 253595ea7dcSIntel txmb = qconf->tx_mbufs[port]; 254595ea7dcSIntel len = txmb->len; 255cc8f4d02SIntel 256595ea7dcSIntel if ((int32_t)(fill = txmb->head - txmb->tail) < 0) 257595ea7dcSIntel fill += len; 258595ea7dcSIntel 259595ea7dcSIntel if (fill >= thresh) { 260595ea7dcSIntel n = RTE_MIN(len - txmb->tail, fill); 261595ea7dcSIntel 262595ea7dcSIntel k = rte_eth_tx_burst(port, qconf->tx_queue_id[port], 263595ea7dcSIntel txmb->m_table + txmb->tail, (uint16_t)n); 264595ea7dcSIntel 265595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, call, 1); 266595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, send, k); 267595ea7dcSIntel 268595ea7dcSIntel fill -= k; 269595ea7dcSIntel if ((txmb->tail += k) == len) 270595ea7dcSIntel txmb->tail = 0; 271cc8f4d02SIntel } 272cc8f4d02SIntel 273693f715dSHuawei Xie return fill; 274cc8f4d02SIntel } 275cc8f4d02SIntel 276cc8f4d02SIntel /* Enqueue a single packet, and send burst if queue is filled */ 277cc8f4d02SIntel static inline int 278f8244c63SZhiyong Yang send_single_packet(struct rte_mbuf *m, uint16_t port) 279cc8f4d02SIntel { 280595ea7dcSIntel uint32_t fill, lcore_id, len; 281b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 282595ea7dcSIntel struct mbuf_table *txmb; 283cc8f4d02SIntel 284cc8f4d02SIntel lcore_id = rte_lcore_id(); 285b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 286cc8f4d02SIntel 287595ea7dcSIntel txmb = qconf->tx_mbufs[port]; 288595ea7dcSIntel len = txmb->len; 289595ea7dcSIntel 290595ea7dcSIntel fill = send_burst(qconf, MAX_PKT_BURST, port); 291595ea7dcSIntel 292595ea7dcSIntel if (fill == len - 1) { 293595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, drop, 1); 294595ea7dcSIntel rte_pktmbuf_free(txmb->m_table[txmb->tail]); 295595ea7dcSIntel if (++txmb->tail == len) 296595ea7dcSIntel txmb->tail = 0; 297cc8f4d02SIntel } 298cc8f4d02SIntel 299595ea7dcSIntel TX_LCORE_STAT_UPDATE(&qconf->tx_stat, queue, 1); 300595ea7dcSIntel txmb->m_table[txmb->head] = m; 301595ea7dcSIntel if(++txmb->head == len) 302595ea7dcSIntel txmb->head = 0; 303595ea7dcSIntel 304693f715dSHuawei Xie return 0; 305cc8f4d02SIntel } 306cc8f4d02SIntel 307cc8f4d02SIntel static inline void 308f8244c63SZhiyong Yang reassemble(struct rte_mbuf *m, uint16_t portid, uint32_t queue, 309b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf, uint64_t tms) 310cc8f4d02SIntel { 3116d13ea8eSOlivier Matz struct rte_ether_hdr *eth_hdr; 312b84fb4cbSAnatoly Burakov struct rte_ip_frag_tbl *tbl; 313b84fb4cbSAnatoly Burakov struct rte_ip_frag_death_row *dr; 314b84fb4cbSAnatoly Burakov struct rx_queue *rxq; 315cc8f4d02SIntel void *d_addr_bytes; 316d89a5bceSVladyslav Buslov uint32_t next_hop; 317f8244c63SZhiyong Yang uint16_t dst_port; 318b84fb4cbSAnatoly Burakov 319b84fb4cbSAnatoly Burakov rxq = &qconf->rx_queue_list[queue]; 320cc8f4d02SIntel 3216d13ea8eSOlivier Matz eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); 322cc8f4d02SIntel 323b84fb4cbSAnatoly Burakov dst_port = portid; 324cc8f4d02SIntel 325b84fb4cbSAnatoly Burakov /* if packet is IPv4 */ 3263c0184ccSHelin Zhang if (RTE_ETH_IS_IPV4_HDR(m->packet_type)) { 327*a7c528e5SOlivier Matz struct rte_ipv4_hdr *ip_hdr; 328b84fb4cbSAnatoly Burakov uint32_t ip_dst; 329cc8f4d02SIntel 330*a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1); 331cc8f4d02SIntel 332cc8f4d02SIntel /* if it is a fragmented packet, then try to reassemble. */ 333b84fb4cbSAnatoly Burakov if (rte_ipv4_frag_pkt_is_fragmented(ip_hdr)) { 334cc8f4d02SIntel struct rte_mbuf *mo; 335cc8f4d02SIntel 336b84fb4cbSAnatoly Burakov tbl = rxq->frag_tbl; 337595ea7dcSIntel dr = &qconf->death_row; 338cc8f4d02SIntel 339cc8f4d02SIntel /* prepare mbuf: setup l2_len/l3_len. */ 3407869536fSBruce Richardson m->l2_len = sizeof(*eth_hdr); 3417869536fSBruce Richardson m->l3_len = sizeof(*ip_hdr); 342cc8f4d02SIntel 343cc8f4d02SIntel /* process this fragment. */ 344b84fb4cbSAnatoly Burakov mo = rte_ipv4_frag_reassemble_packet(tbl, dr, m, tms, ip_hdr); 345b84fb4cbSAnatoly Burakov if (mo == NULL) 346cc8f4d02SIntel /* no packet to send out. */ 347cc8f4d02SIntel return; 348cc8f4d02SIntel 349cc8f4d02SIntel /* we have our packet reassembled. */ 350cc8f4d02SIntel if (mo != m) { 351cc8f4d02SIntel m = mo; 352cc8f4d02SIntel eth_hdr = rte_pktmbuf_mtod(m, 3536d13ea8eSOlivier Matz struct rte_ether_hdr *); 354*a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv4_hdr *)(eth_hdr + 1); 355b84fb4cbSAnatoly Burakov } 356b84fb4cbSAnatoly Burakov } 357b84fb4cbSAnatoly Burakov ip_dst = rte_be_to_cpu_32(ip_hdr->dst_addr); 358b84fb4cbSAnatoly Burakov 359b84fb4cbSAnatoly Burakov /* Find destination port */ 360d89a5bceSVladyslav Buslov if (rte_lpm_lookup(rxq->lpm, ip_dst, &next_hop) == 0 && 361d89a5bceSVladyslav Buslov (enabled_port_mask & 1 << next_hop) != 0) { 362d89a5bceSVladyslav Buslov dst_port = next_hop; 363b84fb4cbSAnatoly Burakov } 364b84fb4cbSAnatoly Burakov 36535b2d13fSOlivier Matz eth_hdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPv4); 3663c0184ccSHelin Zhang } else if (RTE_ETH_IS_IPV6_HDR(m->packet_type)) { 3673c0184ccSHelin Zhang /* if packet is IPv6 */ 368b84fb4cbSAnatoly Burakov struct ipv6_extension_fragment *frag_hdr; 369*a7c528e5SOlivier Matz struct rte_ipv6_hdr *ip_hdr; 370b84fb4cbSAnatoly Burakov 371*a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1); 372b84fb4cbSAnatoly Burakov 373b84fb4cbSAnatoly Burakov frag_hdr = rte_ipv6_frag_get_ipv6_fragment_header(ip_hdr); 374b84fb4cbSAnatoly Burakov 375b84fb4cbSAnatoly Burakov if (frag_hdr != NULL) { 376b84fb4cbSAnatoly Burakov struct rte_mbuf *mo; 377b84fb4cbSAnatoly Burakov 378b84fb4cbSAnatoly Burakov tbl = rxq->frag_tbl; 379b84fb4cbSAnatoly Burakov dr = &qconf->death_row; 380b84fb4cbSAnatoly Burakov 381b84fb4cbSAnatoly Burakov /* prepare mbuf: setup l2_len/l3_len. */ 3827869536fSBruce Richardson m->l2_len = sizeof(*eth_hdr); 3837869536fSBruce Richardson m->l3_len = sizeof(*ip_hdr) + sizeof(*frag_hdr); 384b84fb4cbSAnatoly Burakov 385b84fb4cbSAnatoly Burakov mo = rte_ipv6_frag_reassemble_packet(tbl, dr, m, tms, ip_hdr, frag_hdr); 386b84fb4cbSAnatoly Burakov if (mo == NULL) 387b84fb4cbSAnatoly Burakov return; 388b84fb4cbSAnatoly Burakov 389b84fb4cbSAnatoly Burakov if (mo != m) { 390b84fb4cbSAnatoly Burakov m = mo; 3916d13ea8eSOlivier Matz eth_hdr = rte_pktmbuf_mtod(m, 3926d13ea8eSOlivier Matz struct rte_ether_hdr *); 393*a7c528e5SOlivier Matz ip_hdr = (struct rte_ipv6_hdr *)(eth_hdr + 1); 394cc8f4d02SIntel } 395cc8f4d02SIntel } 396cc8f4d02SIntel 397b84fb4cbSAnatoly Burakov /* Find destination port */ 398d89a5bceSVladyslav Buslov if (rte_lpm6_lookup(rxq->lpm6, ip_hdr->dst_addr, 399d89a5bceSVladyslav Buslov &next_hop) == 0 && 400d89a5bceSVladyslav Buslov (enabled_port_mask & 1 << next_hop) != 0) { 401d89a5bceSVladyslav Buslov dst_port = next_hop; 402b84fb4cbSAnatoly Burakov } 403b84fb4cbSAnatoly Burakov 40435b2d13fSOlivier Matz eth_hdr->ether_type = rte_be_to_cpu_16(RTE_ETHER_TYPE_IPv6); 405b84fb4cbSAnatoly Burakov } 406b84fb4cbSAnatoly Burakov /* if packet wasn't IPv4 or IPv6, it's forwarded to the port it came from */ 407cc8f4d02SIntel 408cc8f4d02SIntel /* 02:00:00:00:00:xx */ 409cc8f4d02SIntel d_addr_bytes = ð_hdr->d_addr.addr_bytes[0]; 410cc8f4d02SIntel *((uint64_t *)d_addr_bytes) = 0x000000000002 + ((uint64_t)dst_port << 40); 411cc8f4d02SIntel 412cc8f4d02SIntel /* src addr */ 413538da7a1SOlivier Matz rte_ether_addr_copy(&ports_eth_addr[dst_port], ð_hdr->s_addr); 414cc8f4d02SIntel 415cc8f4d02SIntel send_single_packet(m, dst_port); 416cc8f4d02SIntel } 417cc8f4d02SIntel 418cc8f4d02SIntel /* main processing loop */ 419cc8f4d02SIntel static int 420cc8f4d02SIntel main_loop(__attribute__((unused)) void *dummy) 421cc8f4d02SIntel { 422cc8f4d02SIntel struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; 423cc8f4d02SIntel unsigned lcore_id; 424cc8f4d02SIntel uint64_t diff_tsc, cur_tsc, prev_tsc; 425cc8f4d02SIntel int i, j, nb_rx; 426f8244c63SZhiyong Yang uint16_t portid; 427b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 428cc8f4d02SIntel const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S * BURST_TX_DRAIN_US; 429cc8f4d02SIntel 430cc8f4d02SIntel prev_tsc = 0; 431cc8f4d02SIntel 432cc8f4d02SIntel lcore_id = rte_lcore_id(); 433b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 434cc8f4d02SIntel 435cc8f4d02SIntel if (qconf->n_rx_queue == 0) { 436b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "lcore %u has nothing to do\n", lcore_id); 437cc8f4d02SIntel return 0; 438cc8f4d02SIntel } 439cc8f4d02SIntel 440b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "entering main loop on lcore %u\n", lcore_id); 441cc8f4d02SIntel 442cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; i++) { 443cc8f4d02SIntel 444b84fb4cbSAnatoly Burakov portid = qconf->rx_queue_list[i].portid; 445f8244c63SZhiyong Yang RTE_LOG(INFO, IP_RSMBL, " -- lcoreid=%u portid=%u\n", lcore_id, 446b84fb4cbSAnatoly Burakov portid); 447cc8f4d02SIntel } 448cc8f4d02SIntel 449cc8f4d02SIntel while (1) { 450cc8f4d02SIntel 451cc8f4d02SIntel cur_tsc = rte_rdtsc(); 452cc8f4d02SIntel 453cc8f4d02SIntel /* 454cc8f4d02SIntel * TX burst queue drain 455cc8f4d02SIntel */ 456cc8f4d02SIntel diff_tsc = cur_tsc - prev_tsc; 457cc8f4d02SIntel if (unlikely(diff_tsc > drain_tsc)) { 458cc8f4d02SIntel 459cc8f4d02SIntel /* 460cc8f4d02SIntel * This could be optimized (use queueid instead of 461cc8f4d02SIntel * portid), but it is not called so often 462cc8f4d02SIntel */ 463b84fb4cbSAnatoly Burakov for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) { 464595ea7dcSIntel if ((enabled_port_mask & (1 << portid)) != 0) 465595ea7dcSIntel send_burst(qconf, 1, portid); 466cc8f4d02SIntel } 467cc8f4d02SIntel 468cc8f4d02SIntel prev_tsc = cur_tsc; 469cc8f4d02SIntel } 470cc8f4d02SIntel 471cc8f4d02SIntel /* 472cc8f4d02SIntel * Read packet from RX queues 473cc8f4d02SIntel */ 474cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; ++i) { 475cc8f4d02SIntel 476b84fb4cbSAnatoly Burakov portid = qconf->rx_queue_list[i].portid; 477cc8f4d02SIntel 478b84fb4cbSAnatoly Burakov nb_rx = rte_eth_rx_burst(portid, 0, pkts_burst, 479cc8f4d02SIntel MAX_PKT_BURST); 480cc8f4d02SIntel 481cc8f4d02SIntel /* Prefetch first packets */ 482cc8f4d02SIntel for (j = 0; j < PREFETCH_OFFSET && j < nb_rx; j++) { 483cc8f4d02SIntel rte_prefetch0(rte_pktmbuf_mtod( 484cc8f4d02SIntel pkts_burst[j], void *)); 485cc8f4d02SIntel } 486cc8f4d02SIntel 487cc8f4d02SIntel /* Prefetch and forward already prefetched packets */ 488cc8f4d02SIntel for (j = 0; j < (nb_rx - PREFETCH_OFFSET); j++) { 489cc8f4d02SIntel rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[ 490cc8f4d02SIntel j + PREFETCH_OFFSET], void *)); 491b84fb4cbSAnatoly Burakov reassemble(pkts_burst[j], portid, 492cc8f4d02SIntel i, qconf, cur_tsc); 493cc8f4d02SIntel } 494cc8f4d02SIntel 495cc8f4d02SIntel /* Forward remaining prefetched packets */ 496cc8f4d02SIntel for (; j < nb_rx; j++) { 497b84fb4cbSAnatoly Burakov reassemble(pkts_burst[j], portid, 498cc8f4d02SIntel i, qconf, cur_tsc); 499cc8f4d02SIntel } 500595ea7dcSIntel 50163ec0b58SAnatoly Burakov rte_ip_frag_free_death_row(&qconf->death_row, 502595ea7dcSIntel PREFETCH_OFFSET); 503cc8f4d02SIntel } 504cc8f4d02SIntel } 505cc8f4d02SIntel } 506cc8f4d02SIntel 507cc8f4d02SIntel /* display usage */ 508cc8f4d02SIntel static void 509cc8f4d02SIntel print_usage(const char *prgname) 510cc8f4d02SIntel { 511b84fb4cbSAnatoly Burakov printf("%s [EAL options] -- -p PORTMASK [-q NQ]" 512b84fb4cbSAnatoly Burakov " [--max-pkt-len PKTLEN]" 513cc8f4d02SIntel " [--maxflows=<flows>] [--flowttl=<ttl>[(s|ms)]]\n" 514cc8f4d02SIntel " -p PORTMASK: hexadecimal bitmask of ports to configure\n" 515b84fb4cbSAnatoly Burakov " -q NQ: number of RX queues per lcore\n" 516cc8f4d02SIntel " --maxflows=<flows>: optional, maximum number of flows " 517cc8f4d02SIntel "supported\n" 518cc8f4d02SIntel " --flowttl=<ttl>[(s|ms)]: optional, maximum TTL for each " 519cc8f4d02SIntel "flow\n", 520cc8f4d02SIntel prgname); 521cc8f4d02SIntel } 522cc8f4d02SIntel 523cc8f4d02SIntel static uint32_t 524cc8f4d02SIntel parse_flow_num(const char *str, uint32_t min, uint32_t max, uint32_t *val) 525cc8f4d02SIntel { 526cc8f4d02SIntel char *end; 527cc8f4d02SIntel uint64_t v; 528cc8f4d02SIntel 529cc8f4d02SIntel /* parse decimal string */ 530cc8f4d02SIntel errno = 0; 531cc8f4d02SIntel v = strtoul(str, &end, 10); 532cc8f4d02SIntel if (errno != 0 || *end != '\0') 533693f715dSHuawei Xie return -EINVAL; 534cc8f4d02SIntel 535cc8f4d02SIntel if (v < min || v > max) 536693f715dSHuawei Xie return -EINVAL; 537cc8f4d02SIntel 538cc8f4d02SIntel *val = (uint32_t)v; 539693f715dSHuawei Xie return 0; 540cc8f4d02SIntel } 541cc8f4d02SIntel 542cc8f4d02SIntel static int 543cc8f4d02SIntel parse_flow_ttl(const char *str, uint32_t min, uint32_t max, uint32_t *val) 544cc8f4d02SIntel { 545cc8f4d02SIntel char *end; 546cc8f4d02SIntel uint64_t v; 547cc8f4d02SIntel 548cc8f4d02SIntel static const char frmt_sec[] = "s"; 549cc8f4d02SIntel static const char frmt_msec[] = "ms"; 550cc8f4d02SIntel 551cc8f4d02SIntel /* parse decimal string */ 552cc8f4d02SIntel errno = 0; 553cc8f4d02SIntel v = strtoul(str, &end, 10); 554cc8f4d02SIntel if (errno != 0) 555693f715dSHuawei Xie return -EINVAL; 556cc8f4d02SIntel 557cc8f4d02SIntel if (*end != '\0') { 558cc8f4d02SIntel if (strncmp(frmt_sec, end, sizeof(frmt_sec)) == 0) 559cc8f4d02SIntel v *= MS_PER_S; 560cc8f4d02SIntel else if (strncmp(frmt_msec, end, sizeof (frmt_msec)) != 0) 561693f715dSHuawei Xie return -EINVAL; 562cc8f4d02SIntel } 563cc8f4d02SIntel 564cc8f4d02SIntel if (v < min || v > max) 565693f715dSHuawei Xie return -EINVAL; 566cc8f4d02SIntel 567cc8f4d02SIntel *val = (uint32_t)v; 568693f715dSHuawei Xie return 0; 569cc8f4d02SIntel } 570cc8f4d02SIntel 571cc8f4d02SIntel static int 572cc8f4d02SIntel parse_portmask(const char *portmask) 573cc8f4d02SIntel { 574cc8f4d02SIntel char *end = NULL; 575cc8f4d02SIntel unsigned long pm; 576cc8f4d02SIntel 577cc8f4d02SIntel /* parse hexadecimal string */ 578cc8f4d02SIntel pm = strtoul(portmask, &end, 16); 579cc8f4d02SIntel if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) 580cc8f4d02SIntel return -1; 581cc8f4d02SIntel 582cc8f4d02SIntel if (pm == 0) 583cc8f4d02SIntel return -1; 584cc8f4d02SIntel 585cc8f4d02SIntel return pm; 586cc8f4d02SIntel } 587cc8f4d02SIntel 588cc8f4d02SIntel static int 589b84fb4cbSAnatoly Burakov parse_nqueue(const char *q_arg) 590cc8f4d02SIntel { 591b84fb4cbSAnatoly Burakov char *end = NULL; 592b84fb4cbSAnatoly Burakov unsigned long n; 593cc8f4d02SIntel 594b84fb4cbSAnatoly Burakov printf("%p\n", q_arg); 595cc8f4d02SIntel 596b84fb4cbSAnatoly Burakov /* parse hexadecimal string */ 597b84fb4cbSAnatoly Burakov n = strtoul(q_arg, &end, 10); 598b84fb4cbSAnatoly Burakov if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0')) 599b84fb4cbSAnatoly Burakov return -1; 600b84fb4cbSAnatoly Burakov if (n == 0) 601b84fb4cbSAnatoly Burakov return -1; 602b84fb4cbSAnatoly Burakov if (n >= MAX_RX_QUEUE_PER_LCORE) 603cc8f4d02SIntel return -1; 604cc8f4d02SIntel 605b84fb4cbSAnatoly Burakov return n; 606cc8f4d02SIntel } 607cc8f4d02SIntel 608cc8f4d02SIntel /* Parse the argument given in the command line of the application */ 609cc8f4d02SIntel static int 610cc8f4d02SIntel parse_args(int argc, char **argv) 611cc8f4d02SIntel { 612cc8f4d02SIntel int opt, ret; 613cc8f4d02SIntel char **argvopt; 614cc8f4d02SIntel int option_index; 615cc8f4d02SIntel char *prgname = argv[0]; 616cc8f4d02SIntel static struct option lgopts[] = { 617b84fb4cbSAnatoly Burakov {"max-pkt-len", 1, 0, 0}, 618cc8f4d02SIntel {"maxflows", 1, 0, 0}, 619cc8f4d02SIntel {"flowttl", 1, 0, 0}, 620cc8f4d02SIntel {NULL, 0, 0, 0} 621cc8f4d02SIntel }; 622cc8f4d02SIntel 623cc8f4d02SIntel argvopt = argv; 624cc8f4d02SIntel 625b84fb4cbSAnatoly Burakov while ((opt = getopt_long(argc, argvopt, "p:q:", 626cc8f4d02SIntel lgopts, &option_index)) != EOF) { 627cc8f4d02SIntel 628cc8f4d02SIntel switch (opt) { 629cc8f4d02SIntel /* portmask */ 630cc8f4d02SIntel case 'p': 631cc8f4d02SIntel enabled_port_mask = parse_portmask(optarg); 632cc8f4d02SIntel if (enabled_port_mask == 0) { 633cc8f4d02SIntel printf("invalid portmask\n"); 634cc8f4d02SIntel print_usage(prgname); 635cc8f4d02SIntel return -1; 636cc8f4d02SIntel } 637cc8f4d02SIntel break; 638b84fb4cbSAnatoly Burakov 639b84fb4cbSAnatoly Burakov /* nqueue */ 640b84fb4cbSAnatoly Burakov case 'q': 641b84fb4cbSAnatoly Burakov rx_queue_per_lcore = parse_nqueue(optarg); 642b84fb4cbSAnatoly Burakov if (rx_queue_per_lcore < 0) { 643b84fb4cbSAnatoly Burakov printf("invalid queue number\n"); 644b84fb4cbSAnatoly Burakov print_usage(prgname); 645b84fb4cbSAnatoly Burakov return -1; 646b84fb4cbSAnatoly Burakov } 647cc8f4d02SIntel break; 648cc8f4d02SIntel 649cc8f4d02SIntel /* long options */ 650cc8f4d02SIntel case 0: 651cc8f4d02SIntel if (!strncmp(lgopts[option_index].name, 652cc8f4d02SIntel "maxflows", 8)) { 653cc8f4d02SIntel if ((ret = parse_flow_num(optarg, MIN_FLOW_NUM, 654cc8f4d02SIntel MAX_FLOW_NUM, 655cc8f4d02SIntel &max_flow_num)) != 0) { 656cc8f4d02SIntel printf("invalid value: \"%s\" for " 657cc8f4d02SIntel "parameter %s\n", 658cc8f4d02SIntel optarg, 659cc8f4d02SIntel lgopts[option_index].name); 660cc8f4d02SIntel print_usage(prgname); 661693f715dSHuawei Xie return ret; 662cc8f4d02SIntel } 663cc8f4d02SIntel } 664cc8f4d02SIntel 665cc8f4d02SIntel if (!strncmp(lgopts[option_index].name, "flowttl", 7)) { 666cc8f4d02SIntel if ((ret = parse_flow_ttl(optarg, MIN_FLOW_TTL, 667cc8f4d02SIntel MAX_FLOW_TTL, 668cc8f4d02SIntel &max_flow_ttl)) != 0) { 669cc8f4d02SIntel printf("invalid value: \"%s\" for " 670cc8f4d02SIntel "parameter %s\n", 671cc8f4d02SIntel optarg, 672cc8f4d02SIntel lgopts[option_index].name); 673cc8f4d02SIntel print_usage(prgname); 674693f715dSHuawei Xie return ret; 675cc8f4d02SIntel } 676cc8f4d02SIntel } 677cc8f4d02SIntel 678cc8f4d02SIntel break; 679cc8f4d02SIntel 680cc8f4d02SIntel default: 681cc8f4d02SIntel print_usage(prgname); 682cc8f4d02SIntel return -1; 683cc8f4d02SIntel } 684cc8f4d02SIntel } 685cc8f4d02SIntel 686cc8f4d02SIntel if (optind >= 0) 687cc8f4d02SIntel argv[optind-1] = prgname; 688cc8f4d02SIntel 689cc8f4d02SIntel ret = optind-1; 6909d5ca532SKeith Wiles optind = 1; /* reset getopt lib */ 691cc8f4d02SIntel return ret; 692cc8f4d02SIntel } 693cc8f4d02SIntel 694cc8f4d02SIntel static void 6956d13ea8eSOlivier Matz print_ethaddr(const char *name, const struct rte_ether_addr *eth_addr) 696cc8f4d02SIntel { 69735b2d13fSOlivier Matz char buf[RTE_ETHER_ADDR_FMT_SIZE]; 69835b2d13fSOlivier Matz rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, eth_addr); 699ec3d82dbSCunming Liang printf("%s%s", name, buf); 700cc8f4d02SIntel } 701cc8f4d02SIntel 702cc8f4d02SIntel /* Check the link status of all ports in up to 9s, and print them finally */ 703cc8f4d02SIntel static void 7048728ccf3SThomas Monjalon check_all_ports_link_status(uint32_t port_mask) 705cc8f4d02SIntel { 706cc8f4d02SIntel #define CHECK_INTERVAL 100 /* 100ms */ 707cc8f4d02SIntel #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ 708f8244c63SZhiyong Yang uint16_t portid; 709f8244c63SZhiyong Yang uint8_t count, all_ports_up, print_flag = 0; 710cc8f4d02SIntel struct rte_eth_link link; 711cc8f4d02SIntel 712cc8f4d02SIntel printf("\nChecking link status"); 713cc8f4d02SIntel fflush(stdout); 714cc8f4d02SIntel for (count = 0; count <= MAX_CHECK_TIME; count++) { 715cc8f4d02SIntel all_ports_up = 1; 7168728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 717cc8f4d02SIntel if ((port_mask & (1 << portid)) == 0) 718cc8f4d02SIntel continue; 719cc8f4d02SIntel memset(&link, 0, sizeof(link)); 720cc8f4d02SIntel rte_eth_link_get_nowait(portid, &link); 721cc8f4d02SIntel /* print link status if flag set */ 722cc8f4d02SIntel if (print_flag == 1) { 723cc8f4d02SIntel if (link.link_status) 724f8244c63SZhiyong Yang printf( 725f8244c63SZhiyong Yang "Port%d Link Up. Speed %u Mbps - %s\n", 726f8244c63SZhiyong Yang portid, link.link_speed, 727cc8f4d02SIntel (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 728cc8f4d02SIntel ("full-duplex") : ("half-duplex\n")); 729cc8f4d02SIntel else 730f8244c63SZhiyong Yang printf("Port %d Link Down\n", portid); 731cc8f4d02SIntel continue; 732cc8f4d02SIntel } 733cc8f4d02SIntel /* clear all_ports_up flag if any link down */ 73409419f23SThomas Monjalon if (link.link_status == ETH_LINK_DOWN) { 735cc8f4d02SIntel all_ports_up = 0; 736cc8f4d02SIntel break; 737cc8f4d02SIntel } 738cc8f4d02SIntel } 739cc8f4d02SIntel /* after finally printing all link status, get out */ 740cc8f4d02SIntel if (print_flag == 1) 741cc8f4d02SIntel break; 742cc8f4d02SIntel 743cc8f4d02SIntel if (all_ports_up == 0) { 744cc8f4d02SIntel printf("."); 745cc8f4d02SIntel fflush(stdout); 746cc8f4d02SIntel rte_delay_ms(CHECK_INTERVAL); 747cc8f4d02SIntel } 748cc8f4d02SIntel 749cc8f4d02SIntel /* set the print_flag if all ports up or timeout */ 750cc8f4d02SIntel if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) { 751cc8f4d02SIntel print_flag = 1; 752b84fb4cbSAnatoly Burakov printf("\ndone\n"); 753cc8f4d02SIntel } 754cc8f4d02SIntel } 755cc8f4d02SIntel } 756b84fb4cbSAnatoly Burakov 757b84fb4cbSAnatoly Burakov static int 758b84fb4cbSAnatoly Burakov init_routing_table(void) 759b84fb4cbSAnatoly Burakov { 760b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 761b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 762b84fb4cbSAnatoly Burakov int socket, ret; 763b84fb4cbSAnatoly Burakov unsigned i; 764b84fb4cbSAnatoly Burakov 765b84fb4cbSAnatoly Burakov for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) { 766b84fb4cbSAnatoly Burakov if (socket_lpm[socket]) { 767b84fb4cbSAnatoly Burakov lpm = socket_lpm[socket]; 768b84fb4cbSAnatoly Burakov /* populate the LPM table */ 769b84fb4cbSAnatoly Burakov for (i = 0; i < RTE_DIM(l3fwd_ipv4_route_array); i++) { 770b84fb4cbSAnatoly Burakov ret = rte_lpm_add(lpm, 771b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].ip, 772b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].depth, 773b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].if_out); 774b84fb4cbSAnatoly Burakov 775b84fb4cbSAnatoly Burakov if (ret < 0) { 776b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Unable to add entry %i to the l3fwd " 777b84fb4cbSAnatoly Burakov "LPM table\n", i); 778b84fb4cbSAnatoly Burakov return -1; 779b84fb4cbSAnatoly Burakov } 780b84fb4cbSAnatoly Burakov 781b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Socket %i: adding route " IPv4_BYTES_FMT 782b84fb4cbSAnatoly Burakov "/%d (port %d)\n", 783b84fb4cbSAnatoly Burakov socket, 784b84fb4cbSAnatoly Burakov IPv4_BYTES(l3fwd_ipv4_route_array[i].ip), 785b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].depth, 786b84fb4cbSAnatoly Burakov l3fwd_ipv4_route_array[i].if_out); 787b84fb4cbSAnatoly Burakov } 788b84fb4cbSAnatoly Burakov } 789b84fb4cbSAnatoly Burakov 790b84fb4cbSAnatoly Burakov if (socket_lpm6[socket]) { 791b84fb4cbSAnatoly Burakov lpm6 = socket_lpm6[socket]; 792b84fb4cbSAnatoly Burakov /* populate the LPM6 table */ 793b84fb4cbSAnatoly Burakov for (i = 0; i < RTE_DIM(l3fwd_ipv6_route_array); i++) { 794b84fb4cbSAnatoly Burakov ret = rte_lpm6_add(lpm6, 795b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].ip, 796b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].depth, 797b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].if_out); 798b84fb4cbSAnatoly Burakov 799b84fb4cbSAnatoly Burakov if (ret < 0) { 800b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Unable to add entry %i to the l3fwd " 801b84fb4cbSAnatoly Burakov "LPM6 table\n", i); 802b84fb4cbSAnatoly Burakov return -1; 803b84fb4cbSAnatoly Burakov } 804b84fb4cbSAnatoly Burakov 805b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Socket %i: adding route " IPv6_BYTES_FMT 806b84fb4cbSAnatoly Burakov "/%d (port %d)\n", 807b84fb4cbSAnatoly Burakov socket, 808b84fb4cbSAnatoly Burakov IPv6_BYTES(l3fwd_ipv6_route_array[i].ip), 809b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].depth, 810b84fb4cbSAnatoly Burakov l3fwd_ipv6_route_array[i].if_out); 811b84fb4cbSAnatoly Burakov } 812b84fb4cbSAnatoly Burakov } 813b84fb4cbSAnatoly Burakov } 814b84fb4cbSAnatoly Burakov return 0; 815b84fb4cbSAnatoly Burakov } 816b84fb4cbSAnatoly Burakov 817b84fb4cbSAnatoly Burakov static int 818b84fb4cbSAnatoly Burakov setup_port_tbl(struct lcore_queue_conf *qconf, uint32_t lcore, int socket, 819595ea7dcSIntel uint32_t port) 820595ea7dcSIntel { 821595ea7dcSIntel struct mbuf_table *mtb; 822595ea7dcSIntel uint32_t n; 823595ea7dcSIntel size_t sz; 824595ea7dcSIntel 825595ea7dcSIntel n = RTE_MAX(max_flow_num, 2UL * MAX_PKT_BURST); 826595ea7dcSIntel sz = sizeof (*mtb) + sizeof (mtb->m_table[0]) * n; 827595ea7dcSIntel 828fdf20fa7SSergio Gonzalez Monroy if ((mtb = rte_zmalloc_socket(__func__, sz, RTE_CACHE_LINE_SIZE, 829b84fb4cbSAnatoly Burakov socket)) == NULL) { 830b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "%s() for lcore: %u, port: %u " 831595ea7dcSIntel "failed to allocate %zu bytes\n", 832595ea7dcSIntel __func__, lcore, port, sz); 833b84fb4cbSAnatoly Burakov return -1; 834b84fb4cbSAnatoly Burakov } 835595ea7dcSIntel 836595ea7dcSIntel mtb->len = n; 837595ea7dcSIntel qconf->tx_mbufs[port] = mtb; 838b84fb4cbSAnatoly Burakov 839b84fb4cbSAnatoly Burakov return 0; 840595ea7dcSIntel } 841cc8f4d02SIntel 842b84fb4cbSAnatoly Burakov static int 843b84fb4cbSAnatoly Burakov setup_queue_tbl(struct rx_queue *rxq, uint32_t lcore, uint32_t queue) 844cc8f4d02SIntel { 845b84fb4cbSAnatoly Burakov int socket; 846cc8f4d02SIntel uint32_t nb_mbuf; 847cc8f4d02SIntel uint64_t frag_cycles; 848cc8f4d02SIntel char buf[RTE_MEMPOOL_NAMESIZE]; 849cc8f4d02SIntel 850b84fb4cbSAnatoly Burakov socket = rte_lcore_to_socket_id(lcore); 851b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 852b84fb4cbSAnatoly Burakov socket = 0; 853b84fb4cbSAnatoly Burakov 854cc8f4d02SIntel frag_cycles = (rte_get_tsc_hz() + MS_PER_S - 1) / MS_PER_S * 855cc8f4d02SIntel max_flow_ttl; 856cc8f4d02SIntel 857b84fb4cbSAnatoly Burakov if ((rxq->frag_tbl = rte_ip_frag_table_create(max_flow_num, 858b84fb4cbSAnatoly Burakov IP_FRAG_TBL_BUCKET_ENTRIES, max_flow_num, frag_cycles, 859b84fb4cbSAnatoly Burakov socket)) == NULL) { 860b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "ip_frag_tbl_create(%u) on " 861cc8f4d02SIntel "lcore: %u for queue: %u failed\n", 862cc8f4d02SIntel max_flow_num, lcore, queue); 863b84fb4cbSAnatoly Burakov return -1; 864b84fb4cbSAnatoly Burakov } 865cc8f4d02SIntel 866595ea7dcSIntel /* 867d47bd10cSAnatoly Burakov * At any given moment up to <max_flow_num * (MAX_FRAG_NUM)> 868595ea7dcSIntel * mbufs could be stored int the fragment table. 869595ea7dcSIntel * Plus, each TX queue can hold up to <max_flow_num> packets. 870595ea7dcSIntel */ 871595ea7dcSIntel 872d47bd10cSAnatoly Burakov nb_mbuf = RTE_MAX(max_flow_num, 2UL * MAX_PKT_BURST) * MAX_FRAG_NUM; 873cc8f4d02SIntel nb_mbuf *= (port_conf.rxmode.max_rx_pkt_len + BUF_SIZE - 1) / BUF_SIZE; 874b84fb4cbSAnatoly Burakov nb_mbuf *= 2; /* ipv4 and ipv6 */ 87560efb44fSRoman Zhukov nb_mbuf += nb_rxd + nb_txd; 876595ea7dcSIntel 877b84fb4cbSAnatoly Burakov nb_mbuf = RTE_MAX(nb_mbuf, (uint32_t)NB_MBUF); 878cc8f4d02SIntel 8796f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "mbuf_pool_%u_%u", lcore, queue); 880cc8f4d02SIntel 881b325a66aSAshish Jain rxq->pool = rte_pktmbuf_pool_create(buf, nb_mbuf, MEMPOOL_CACHE_SIZE, 0, 882b325a66aSAshish Jain MBUF_DATA_SIZE, socket); 883b325a66aSAshish Jain if (rxq->pool == NULL) { 884b325a66aSAshish Jain RTE_LOG(ERR, IP_RSMBL, 885b325a66aSAshish Jain "rte_pktmbuf_pool_create(%s) failed", buf); 886b84fb4cbSAnatoly Burakov return -1; 887b84fb4cbSAnatoly Burakov } 888b84fb4cbSAnatoly Burakov 889b84fb4cbSAnatoly Burakov return 0; 890b84fb4cbSAnatoly Burakov } 891b84fb4cbSAnatoly Burakov 892b84fb4cbSAnatoly Burakov static int 893b84fb4cbSAnatoly Burakov init_mem(void) 894b84fb4cbSAnatoly Burakov { 895b84fb4cbSAnatoly Burakov char buf[PATH_MAX]; 896b84fb4cbSAnatoly Burakov struct rte_lpm *lpm; 897b84fb4cbSAnatoly Burakov struct rte_lpm6 *lpm6; 898f1f72618SMichal Kobylinski struct rte_lpm_config lpm_config; 899b84fb4cbSAnatoly Burakov int socket; 900b84fb4cbSAnatoly Burakov unsigned lcore_id; 901b84fb4cbSAnatoly Burakov 902b84fb4cbSAnatoly Burakov /* traverse through lcores and initialize structures on each socket */ 903b84fb4cbSAnatoly Burakov 904b84fb4cbSAnatoly Burakov for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 905b84fb4cbSAnatoly Burakov 906b84fb4cbSAnatoly Burakov if (rte_lcore_is_enabled(lcore_id) == 0) 907b84fb4cbSAnatoly Burakov continue; 908b84fb4cbSAnatoly Burakov 909b84fb4cbSAnatoly Burakov socket = rte_lcore_to_socket_id(lcore_id); 910b84fb4cbSAnatoly Burakov 911b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 912b84fb4cbSAnatoly Burakov socket = 0; 913b84fb4cbSAnatoly Burakov 914b84fb4cbSAnatoly Burakov if (socket_lpm[socket] == NULL) { 915b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Creating LPM table on socket %i\n", socket); 9166f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "IP_RSMBL_LPM_%i", socket); 917b84fb4cbSAnatoly Burakov 918f1f72618SMichal Kobylinski lpm_config.max_rules = LPM_MAX_RULES; 919f1f72618SMichal Kobylinski lpm_config.number_tbl8s = 256; 920f1f72618SMichal Kobylinski lpm_config.flags = 0; 921f1f72618SMichal Kobylinski 922f1f72618SMichal Kobylinski lpm = rte_lpm_create(buf, socket, &lpm_config); 923b84fb4cbSAnatoly Burakov if (lpm == NULL) { 924b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Cannot create LPM table\n"); 925b84fb4cbSAnatoly Burakov return -1; 926b84fb4cbSAnatoly Burakov } 927b84fb4cbSAnatoly Burakov socket_lpm[socket] = lpm; 928b84fb4cbSAnatoly Burakov } 929b84fb4cbSAnatoly Burakov 930b84fb4cbSAnatoly Burakov if (socket_lpm6[socket] == NULL) { 931b84fb4cbSAnatoly Burakov RTE_LOG(INFO, IP_RSMBL, "Creating LPM6 table on socket %i\n", socket); 9326f41fe75SStephen Hemminger snprintf(buf, sizeof(buf), "IP_RSMBL_LPM_%i", socket); 933b84fb4cbSAnatoly Burakov 934d1082cdeSOlivier Matz lpm6 = rte_lpm6_create(buf, socket, &lpm6_config); 935b84fb4cbSAnatoly Burakov if (lpm6 == NULL) { 936b84fb4cbSAnatoly Burakov RTE_LOG(ERR, IP_RSMBL, "Cannot create LPM table\n"); 937b84fb4cbSAnatoly Burakov return -1; 938b84fb4cbSAnatoly Burakov } 939b84fb4cbSAnatoly Burakov socket_lpm6[socket] = lpm6; 940b84fb4cbSAnatoly Burakov } 941b84fb4cbSAnatoly Burakov } 942b84fb4cbSAnatoly Burakov 943b84fb4cbSAnatoly Burakov return 0; 944cc8f4d02SIntel } 945cc8f4d02SIntel 946cc8f4d02SIntel static void 947595ea7dcSIntel queue_dump_stat(void) 948cc8f4d02SIntel { 949cc8f4d02SIntel uint32_t i, lcore; 950b84fb4cbSAnatoly Burakov const struct lcore_queue_conf *qconf; 951cc8f4d02SIntel 952cc8f4d02SIntel for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { 953cc8f4d02SIntel if (rte_lcore_is_enabled(lcore) == 0) 954cc8f4d02SIntel continue; 955cc8f4d02SIntel 956b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore]; 957cc8f4d02SIntel for (i = 0; i < qconf->n_rx_queue; i++) { 958cc8f4d02SIntel 959f8244c63SZhiyong Yang fprintf(stdout, " -- lcoreid=%u portid=%u " 960b84fb4cbSAnatoly Burakov "frag tbl stat:\n", 961b84fb4cbSAnatoly Burakov lcore, qconf->rx_queue_list[i].portid); 962b84fb4cbSAnatoly Burakov rte_ip_frag_table_statistics_dump(stdout, 963b84fb4cbSAnatoly Burakov qconf->rx_queue_list[i].frag_tbl); 964595ea7dcSIntel fprintf(stdout, "TX bursts:\t%" PRIu64 "\n" 965595ea7dcSIntel "TX packets _queued:\t%" PRIu64 "\n" 966595ea7dcSIntel "TX packets dropped:\t%" PRIu64 "\n" 967595ea7dcSIntel "TX packets send:\t%" PRIu64 "\n", 968595ea7dcSIntel qconf->tx_stat.call, 969595ea7dcSIntel qconf->tx_stat.queue, 970595ea7dcSIntel qconf->tx_stat.drop, 971595ea7dcSIntel qconf->tx_stat.send); 972cc8f4d02SIntel } 973cc8f4d02SIntel } 974cc8f4d02SIntel } 975cc8f4d02SIntel 976cc8f4d02SIntel static void 977cc8f4d02SIntel signal_handler(int signum) 978cc8f4d02SIntel { 979595ea7dcSIntel queue_dump_stat(); 980cc8f4d02SIntel if (signum != SIGUSR1) 981cc8f4d02SIntel rte_exit(0, "received signal: %d, exiting\n", signum); 982cc8f4d02SIntel } 983cc8f4d02SIntel 984cc8f4d02SIntel int 98598a16481SDavid Marchand main(int argc, char **argv) 986cc8f4d02SIntel { 987b84fb4cbSAnatoly Burakov struct lcore_queue_conf *qconf; 98881f7ecd9SPablo de Lara struct rte_eth_dev_info dev_info; 98981f7ecd9SPablo de Lara struct rte_eth_txconf *txconf; 990b84fb4cbSAnatoly Burakov struct rx_queue *rxq; 991b84fb4cbSAnatoly Burakov int ret, socket; 992cc8f4d02SIntel unsigned nb_ports; 993cc8f4d02SIntel uint16_t queueid; 994b84fb4cbSAnatoly Burakov unsigned lcore_id = 0, rx_lcore_id = 0; 995cc8f4d02SIntel uint32_t n_tx_queue, nb_lcores; 996f8244c63SZhiyong Yang uint16_t portid; 997cc8f4d02SIntel 998cc8f4d02SIntel /* init EAL */ 999cc8f4d02SIntel ret = rte_eal_init(argc, argv); 1000cc8f4d02SIntel if (ret < 0) 1001cc8f4d02SIntel rte_exit(EXIT_FAILURE, "Invalid EAL parameters\n"); 1002cc8f4d02SIntel argc -= ret; 1003cc8f4d02SIntel argv += ret; 1004cc8f4d02SIntel 1005cc8f4d02SIntel /* parse application arguments (after the EAL ones) */ 1006cc8f4d02SIntel ret = parse_args(argc, argv); 1007cc8f4d02SIntel if (ret < 0) 1008b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Invalid IP reassembly parameters\n"); 1009cc8f4d02SIntel 1010d9a42a69SThomas Monjalon nb_ports = rte_eth_dev_count_avail(); 1011b4e0f64fSMauricio Vasquez B if (nb_ports == 0) 1012b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "No ports found!\n"); 1013cc8f4d02SIntel 1014cc8f4d02SIntel nb_lcores = rte_lcore_count(); 1015cc8f4d02SIntel 1016b84fb4cbSAnatoly Burakov /* initialize structures (mempools, lpm etc.) */ 1017b84fb4cbSAnatoly Burakov if (init_mem() < 0) 1018b84fb4cbSAnatoly Burakov rte_panic("Cannot initialize memory structures!\n"); 1019b84fb4cbSAnatoly Burakov 1020eaa8d3bfSAnatoly Burakov /* check if portmask has non-existent ports */ 1021eaa8d3bfSAnatoly Burakov if (enabled_port_mask & ~(RTE_LEN2MASK(nb_ports, unsigned))) 1022eaa8d3bfSAnatoly Burakov rte_exit(EXIT_FAILURE, "Non-existent ports in portmask!\n"); 1023eaa8d3bfSAnatoly Burakov 1024cc8f4d02SIntel /* initialize all ports */ 10258728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 10269df56e69SShahaf Shuler struct rte_eth_rxconf rxq_conf; 10279df56e69SShahaf Shuler struct rte_eth_conf local_port_conf = port_conf; 10289df56e69SShahaf Shuler 1029cc8f4d02SIntel /* skip ports that are not enabled */ 1030cc8f4d02SIntel if ((enabled_port_mask & (1 << portid)) == 0) { 1031cc8f4d02SIntel printf("\nSkipping disabled port %d\n", portid); 1032cc8f4d02SIntel continue; 1033cc8f4d02SIntel } 1034cc8f4d02SIntel 1035b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[rx_lcore_id]; 1036b84fb4cbSAnatoly Burakov 10375e470a66SAndriy Berestovskyy /* limit the frame size to the maximum supported by NIC */ 10385e470a66SAndriy Berestovskyy rte_eth_dev_info_get(portid, &dev_info); 10399df56e69SShahaf Shuler local_port_conf.rxmode.max_rx_pkt_len = RTE_MIN( 10409df56e69SShahaf Shuler dev_info.max_rx_pktlen, 10419df56e69SShahaf Shuler local_port_conf.rxmode.max_rx_pkt_len); 10425e470a66SAndriy Berestovskyy 1043b84fb4cbSAnatoly Burakov /* get the lcore_id for this port */ 1044b84fb4cbSAnatoly Burakov while (rte_lcore_is_enabled(rx_lcore_id) == 0 || 1045b84fb4cbSAnatoly Burakov qconf->n_rx_queue == (unsigned)rx_queue_per_lcore) { 1046b84fb4cbSAnatoly Burakov 1047b84fb4cbSAnatoly Burakov rx_lcore_id++; 1048b84fb4cbSAnatoly Burakov if (rx_lcore_id >= RTE_MAX_LCORE) 1049b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Not enough cores\n"); 1050b84fb4cbSAnatoly Burakov 1051b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[rx_lcore_id]; 1052b84fb4cbSAnatoly Burakov } 1053b84fb4cbSAnatoly Burakov 1054324bcf45SAnatoly Burakov socket = rte_lcore_to_socket_id(portid); 1055b84fb4cbSAnatoly Burakov if (socket == SOCKET_ID_ANY) 1056b84fb4cbSAnatoly Burakov socket = 0; 1057b84fb4cbSAnatoly Burakov 1058b84fb4cbSAnatoly Burakov queueid = qconf->n_rx_queue; 1059b84fb4cbSAnatoly Burakov rxq = &qconf->rx_queue_list[queueid]; 1060b84fb4cbSAnatoly Burakov rxq->portid = portid; 1061b84fb4cbSAnatoly Burakov rxq->lpm = socket_lpm[socket]; 1062b84fb4cbSAnatoly Burakov rxq->lpm6 = socket_lpm6[socket]; 106360efb44fSRoman Zhukov 106460efb44fSRoman Zhukov ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd, 106560efb44fSRoman Zhukov &nb_txd); 106660efb44fSRoman Zhukov if (ret < 0) 106760efb44fSRoman Zhukov rte_exit(EXIT_FAILURE, 106860efb44fSRoman Zhukov "Cannot adjust number of descriptors: err=%d, port=%d\n", 106960efb44fSRoman Zhukov ret, portid); 107060efb44fSRoman Zhukov 1071b84fb4cbSAnatoly Burakov if (setup_queue_tbl(rxq, rx_lcore_id, queueid) < 0) 1072b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Failed to set up queue table\n"); 1073b84fb4cbSAnatoly Burakov qconf->n_rx_queue++; 1074b84fb4cbSAnatoly Burakov 1075cc8f4d02SIntel /* init port */ 1076cc8f4d02SIntel printf("Initializing port %d ... ", portid ); 1077cc8f4d02SIntel fflush(stdout); 1078cc8f4d02SIntel 1079cc8f4d02SIntel n_tx_queue = nb_lcores; 1080cc8f4d02SIntel if (n_tx_queue > MAX_TX_QUEUE_PER_PORT) 1081cc8f4d02SIntel n_tx_queue = MAX_TX_QUEUE_PER_PORT; 10829df56e69SShahaf Shuler if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE) 10839df56e69SShahaf Shuler local_port_conf.txmode.offloads |= 10849df56e69SShahaf Shuler DEV_TX_OFFLOAD_MBUF_FAST_FREE; 10854f5701f2SFerruh Yigit 10864f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf &= 10874f5701f2SFerruh Yigit dev_info.flow_type_rss_offloads; 10884f5701f2SFerruh Yigit if (local_port_conf.rx_adv_conf.rss_conf.rss_hf != 10894f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf) { 10904f5701f2SFerruh Yigit printf("Port %u modified RSS hash function based on hardware support," 10914f5701f2SFerruh Yigit "requested:%#"PRIx64" configured:%#"PRIx64"\n", 10924f5701f2SFerruh Yigit portid, 10934f5701f2SFerruh Yigit port_conf.rx_adv_conf.rss_conf.rss_hf, 10944f5701f2SFerruh Yigit local_port_conf.rx_adv_conf.rss_conf.rss_hf); 10954f5701f2SFerruh Yigit } 10964f5701f2SFerruh Yigit 1097b84fb4cbSAnatoly Burakov ret = rte_eth_dev_configure(portid, 1, (uint16_t)n_tx_queue, 10989df56e69SShahaf Shuler &local_port_conf); 1099b84fb4cbSAnatoly Burakov if (ret < 0) { 1100b84fb4cbSAnatoly Burakov printf("\n"); 1101b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Cannot configure device: " 1102b84fb4cbSAnatoly Burakov "err=%d, port=%d\n", 1103cc8f4d02SIntel ret, portid); 1104b84fb4cbSAnatoly Burakov } 1105b84fb4cbSAnatoly Burakov 1106b84fb4cbSAnatoly Burakov /* init one RX queue */ 11079df56e69SShahaf Shuler rxq_conf = dev_info.default_rxconf; 11089df56e69SShahaf Shuler rxq_conf.offloads = local_port_conf.rxmode.offloads; 1109b84fb4cbSAnatoly Burakov ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd, 11109df56e69SShahaf Shuler socket, &rxq_conf, 1111b84fb4cbSAnatoly Burakov rxq->pool); 1112b84fb4cbSAnatoly Burakov if (ret < 0) { 1113b84fb4cbSAnatoly Burakov printf("\n"); 1114b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup: " 1115b84fb4cbSAnatoly Burakov "err=%d, port=%d\n", 1116b84fb4cbSAnatoly Burakov ret, portid); 1117b84fb4cbSAnatoly Burakov } 1118cc8f4d02SIntel 1119cc8f4d02SIntel rte_eth_macaddr_get(portid, &ports_eth_addr[portid]); 1120cc8f4d02SIntel print_ethaddr(" Address:", &ports_eth_addr[portid]); 1121b84fb4cbSAnatoly Burakov printf("\n"); 1122cc8f4d02SIntel 1123cc8f4d02SIntel /* init one TX queue per couple (lcore,port) */ 1124cc8f4d02SIntel queueid = 0; 1125cc8f4d02SIntel for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1126cc8f4d02SIntel if (rte_lcore_is_enabled(lcore_id) == 0) 1127cc8f4d02SIntel continue; 1128cc8f4d02SIntel 1129b84fb4cbSAnatoly Burakov socket = (int) rte_lcore_to_socket_id(lcore_id); 1130cc8f4d02SIntel 1131b84fb4cbSAnatoly Burakov printf("txq=%u,%d,%d ", lcore_id, queueid, socket); 1132cc8f4d02SIntel fflush(stdout); 113381f7ecd9SPablo de Lara 113481f7ecd9SPablo de Lara txconf = &dev_info.default_txconf; 11359df56e69SShahaf Shuler txconf->offloads = local_port_conf.txmode.offloads; 113681f7ecd9SPablo de Lara 1137cc8f4d02SIntel ret = rte_eth_tx_queue_setup(portid, queueid, nb_txd, 113881f7ecd9SPablo de Lara socket, txconf); 1139cc8f4d02SIntel if (ret < 0) 1140cc8f4d02SIntel rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup: err=%d, " 1141cc8f4d02SIntel "port=%d\n", ret, portid); 1142cc8f4d02SIntel 1143b84fb4cbSAnatoly Burakov qconf = &lcore_queue_conf[lcore_id]; 1144cc8f4d02SIntel qconf->tx_queue_id[portid] = queueid; 1145b84fb4cbSAnatoly Burakov setup_port_tbl(qconf, lcore_id, socket, portid); 1146cc8f4d02SIntel queueid++; 1147cc8f4d02SIntel } 1148cc8f4d02SIntel printf("\n"); 1149cc8f4d02SIntel } 1150cc8f4d02SIntel 1151cc8f4d02SIntel printf("\n"); 1152cc8f4d02SIntel 1153cc8f4d02SIntel /* start ports */ 11548728ccf3SThomas Monjalon RTE_ETH_FOREACH_DEV(portid) { 1155cc8f4d02SIntel if ((enabled_port_mask & (1 << portid)) == 0) { 1156cc8f4d02SIntel continue; 1157cc8f4d02SIntel } 1158cc8f4d02SIntel /* Start device */ 1159cc8f4d02SIntel ret = rte_eth_dev_start(portid); 1160cc8f4d02SIntel if (ret < 0) 1161cc8f4d02SIntel rte_exit(EXIT_FAILURE, "rte_eth_dev_start: err=%d, port=%d\n", 1162cc8f4d02SIntel ret, portid); 1163cc8f4d02SIntel 1164cc8f4d02SIntel rte_eth_promiscuous_enable(portid); 1165cc8f4d02SIntel } 1166cc8f4d02SIntel 1167b84fb4cbSAnatoly Burakov if (init_routing_table() < 0) 1168b84fb4cbSAnatoly Burakov rte_exit(EXIT_FAILURE, "Cannot init routing table\n"); 1169b84fb4cbSAnatoly Burakov 11708728ccf3SThomas Monjalon check_all_ports_link_status(enabled_port_mask); 1171cc8f4d02SIntel 1172cc8f4d02SIntel signal(SIGUSR1, signal_handler); 1173cc8f4d02SIntel signal(SIGTERM, signal_handler); 1174cc8f4d02SIntel signal(SIGINT, signal_handler); 1175cc8f4d02SIntel 1176cc8f4d02SIntel /* launch per-lcore init on every lcore */ 1177cc8f4d02SIntel rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); 1178cc8f4d02SIntel RTE_LCORE_FOREACH_SLAVE(lcore_id) { 1179cc8f4d02SIntel if (rte_eal_wait_lcore(lcore_id) < 0) 1180cc8f4d02SIntel return -1; 1181cc8f4d02SIntel } 1182cc8f4d02SIntel 1183cc8f4d02SIntel return 0; 1184cc8f4d02SIntel } 1185