15bf882b4S10077240 /* 2*2317ada5Sfengbojiang * Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. 35bf882b4S10077240 * All rights reserved. 45bf882b4S10077240 * 55bf882b4S10077240 * Redistribution and use in source and binary forms, with or without 65bf882b4S10077240 * modification, are permitted provided that the following conditions are met: 75bf882b4S10077240 * 85bf882b4S10077240 * 1. Redistributions of source code must retain the above copyright notice, this 95bf882b4S10077240 * list of conditions and the following disclaimer. 105bf882b4S10077240 * 2. Redistributions in binary form must reproduce the above copyright notice, 115bf882b4S10077240 * this list of conditions and the following disclaimer in the documentation 125bf882b4S10077240 * and/or other materials provided with the distribution. 135bf882b4S10077240 * 145bf882b4S10077240 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 155bf882b4S10077240 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 165bf882b4S10077240 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 175bf882b4S10077240 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 185bf882b4S10077240 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 195bf882b4S10077240 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 205bf882b4S10077240 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 215bf882b4S10077240 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225bf882b4S10077240 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 235bf882b4S10077240 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245bf882b4S10077240 * 255bf882b4S10077240 */ 265bf882b4S10077240 275bf882b4S10077240 #ifndef __FSTACK_MEMORY_H 285bf882b4S10077240 #define __FSTACK_MEMORY_H 295bf882b4S10077240 305bf882b4S10077240 #ifdef __cplusplus 315bf882b4S10077240 extern "C" { 325bf882b4S10077240 #endif 335bf882b4S10077240 345bf882b4S10077240 #define MEMPOOL_CACHE_SIZE 256 355bf882b4S10077240 365bf882b4S10077240 #define DISPATCH_RING_SIZE 2048 375bf882b4S10077240 385bf882b4S10077240 #define MSG_RING_SIZE 32 395bf882b4S10077240 405bf882b4S10077240 /* 415bf882b4S10077240 * Configurable number of RX/TX ring descriptors 425bf882b4S10077240 */ 435bf882b4S10077240 #define RX_QUEUE_SIZE 512 445bf882b4S10077240 #define TX_QUEUE_SIZE 512 455bf882b4S10077240 465bf882b4S10077240 /* 475bf882b4S10077240 * Try to avoid TX buffering if we have at least MAX_TX_BURST packets to send. 485bf882b4S10077240 */ 495bf882b4S10077240 #define MAX_TX_BURST (MAX_PKT_BURST / 2) 505bf882b4S10077240 515bf882b4S10077240 #define NB_SOCKETS 8 525bf882b4S10077240 535bf882b4S10077240 /* Configure how many packets ahead to prefetch, when reading packets */ 545bf882b4S10077240 #define PREFETCH_OFFSET 3 555bf882b4S10077240 565bf882b4S10077240 #define MAX_RX_QUEUE_PER_LCORE 16 575bf882b4S10077240 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS 585bf882b4S10077240 #define MAX_RX_QUEUE_PER_PORT 128 595bf882b4S10077240 605bf882b4S10077240 struct ff_dpdk_if_context { 615bf882b4S10077240 void *sc; 625bf882b4S10077240 void *ifp; 635bf882b4S10077240 uint16_t port_id; 645bf882b4S10077240 struct ff_hw_features hw_features; 655bf882b4S10077240 } __rte_cache_aligned; 665bf882b4S10077240 675bf882b4S10077240 struct mbuf_table { 685bf882b4S10077240 uint16_t len; 695bf882b4S10077240 struct rte_mbuf *m_table[MAX_PKT_BURST]; 705bf882b4S10077240 #ifdef FF_USE_PAGE_ARRAY 715bf882b4S10077240 void* bsd_m_table[MAX_PKT_BURST]; // save bsd mbuf address which will be enquene into txring after NIC transmitted pkt. 725bf882b4S10077240 #endif 735bf882b4S10077240 }; 745bf882b4S10077240 755bf882b4S10077240 struct lcore_rx_queue { 765bf882b4S10077240 uint16_t port_id; 775bf882b4S10077240 uint16_t queue_id; 785bf882b4S10077240 } __rte_cache_aligned; 795bf882b4S10077240 805bf882b4S10077240 struct lcore_conf { 815bf882b4S10077240 uint16_t proc_id; 825bf882b4S10077240 uint16_t socket_id; 835bf882b4S10077240 uint16_t nb_queue_list[RTE_MAX_ETHPORTS]; 845bf882b4S10077240 struct ff_port_cfg *port_cfgs; 855bf882b4S10077240 865bf882b4S10077240 uint16_t nb_rx_queue; 875bf882b4S10077240 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE]; 885bf882b4S10077240 uint16_t nb_tx_port; 895bf882b4S10077240 uint16_t tx_port_id[RTE_MAX_ETHPORTS]; 905bf882b4S10077240 uint16_t tx_queue_id[RTE_MAX_ETHPORTS]; 915bf882b4S10077240 struct mbuf_table tx_mbufs[RTE_MAX_ETHPORTS]; 92819aafb6Sjinhao2 //char *pcap[RTE_MAX_ETHPORTS]; 935bf882b4S10077240 } __rte_cache_aligned; 945bf882b4S10077240 955bf882b4S10077240 #ifdef FF_USE_PAGE_ARRAY 965bf882b4S10077240 // mbuf_txring save mbuf which had bursted into NIC, m_tables has same length with NIC dev's sw_ring. 975bf882b4S10077240 // Then when txring.m_table[x] is reused, the packet in txring.m_table[x] had been transmited by NIC. 985bf882b4S10077240 // that means the mbuf can be freed safely. 995bf882b4S10077240 struct mbuf_txring{ 1005bf882b4S10077240 void* m_table[TX_QUEUE_SIZE]; 1015bf882b4S10077240 uint16_t head; // next available element. 1025bf882b4S10077240 }; 1035bf882b4S10077240 1045bf882b4S10077240 void ff_init_ref_pool(int nb_mbuf, int socketid); 1055bf882b4S10077240 int ff_mmap_init(); 1065bf882b4S10077240 int ff_if_send_onepkt(struct ff_dpdk_if_context *ctx, void *m, int total); 1075bf882b4S10077240 int ff_enq_tx_bsdmbuf(uint8_t portid, void *p_mbuf, int nb_segs); 1085bf882b4S10077240 #endif 1095bf882b4S10077240 1105bf882b4S10077240 #ifdef __cplusplus 1115bf882b4S10077240 } 1125bf882b4S10077240 #endif 1135bf882b4S10077240 1145bf882b4S10077240 #endif 1155bf882b4S10077240 1165bf882b4S10077240 117