1 /* 2 * Copyright (C) 2017 THL A29 Limited, a Tencent company. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 */ 26 27 #ifndef __FSTACK_MEMORY_H 28 #define __FSTACK_MEMORY_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #define MEMPOOL_CACHE_SIZE 256 35 36 #define DISPATCH_RING_SIZE 2048 37 38 #define MSG_RING_SIZE 32 39 40 /* 41 * Configurable number of RX/TX ring descriptors 42 */ 43 #define RX_QUEUE_SIZE 512 44 #define TX_QUEUE_SIZE 512 45 46 #define MAX_PKT_BURST 32 47 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 48 49 /* 50 * Try to avoid TX buffering if we have at least MAX_TX_BURST packets to send. 51 */ 52 #define MAX_TX_BURST (MAX_PKT_BURST / 2) 53 54 #define NB_SOCKETS 8 55 56 /* Configure how many packets ahead to prefetch, when reading packets */ 57 #define PREFETCH_OFFSET 3 58 59 #define MAX_RX_QUEUE_PER_LCORE 16 60 #define MAX_TX_QUEUE_PER_PORT RTE_MAX_ETHPORTS 61 #define MAX_RX_QUEUE_PER_PORT 128 62 63 struct ff_dpdk_if_context { 64 void *sc; 65 void *ifp; 66 uint16_t port_id; 67 struct ff_hw_features hw_features; 68 } __rte_cache_aligned; 69 70 struct mbuf_table { 71 uint16_t len; 72 struct rte_mbuf *m_table[MAX_PKT_BURST]; 73 #ifdef FF_USE_PAGE_ARRAY 74 void* bsd_m_table[MAX_PKT_BURST]; // save bsd mbuf address which will be enquene into txring after NIC transmitted pkt. 75 #endif 76 }; 77 78 struct lcore_rx_queue { 79 uint16_t port_id; 80 uint16_t queue_id; 81 } __rte_cache_aligned; 82 83 struct lcore_conf { 84 uint16_t proc_id; 85 uint16_t socket_id; 86 uint16_t nb_queue_list[RTE_MAX_ETHPORTS]; 87 struct ff_port_cfg *port_cfgs; 88 89 uint16_t nb_rx_queue; 90 struct lcore_rx_queue rx_queue_list[MAX_RX_QUEUE_PER_LCORE]; 91 uint16_t nb_tx_port; 92 uint16_t tx_port_id[RTE_MAX_ETHPORTS]; 93 uint16_t tx_queue_id[RTE_MAX_ETHPORTS]; 94 struct mbuf_table tx_mbufs[RTE_MAX_ETHPORTS]; 95 char *pcap[RTE_MAX_ETHPORTS]; 96 } __rte_cache_aligned; 97 98 #ifdef FF_USE_PAGE_ARRAY 99 // mbuf_txring save mbuf which had bursted into NIC, m_tables has same length with NIC dev's sw_ring. 100 // Then when txring.m_table[x] is reused, the packet in txring.m_table[x] had been transmited by NIC. 101 // that means the mbuf can be freed safely. 102 struct mbuf_txring{ 103 void* m_table[TX_QUEUE_SIZE]; 104 uint16_t head; // next available element. 105 }; 106 107 void ff_init_ref_pool(int nb_mbuf, int socketid); 108 int ff_mmap_init(); 109 int ff_if_send_onepkt(struct ff_dpdk_if_context *ctx, void *m, int total); 110 int ff_enq_tx_bsdmbuf(uint8_t portid, void *p_mbuf, int nb_segs); 111 #endif 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif 118 119 120