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_CONFIG_H 28 #define __FSTACK_CONFIG_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 // dpdk argc, argv, max argc: 16, member of dpdk_config 35 #define DPDK_CONFIG_NUM 16 36 #define DPDK_CONFIG_MAXLEN 256 37 #define DPDK_MAX_LCORE 128 38 #define PCAP_SNAP_MINLEN 94 39 #define PCAP_SAVE_MINLEN (2<<22) 40 41 extern int dpdk_argc; 42 extern char *dpdk_argv[DPDK_CONFIG_NUM + 1]; 43 44 #define MAX_PKT_BURST 32 45 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ 46 47 struct ff_hw_features { 48 uint8_t rx_csum; 49 uint8_t rx_lro; 50 uint8_t tx_csum_ip; 51 uint8_t tx_csum_l4; 52 uint8_t tx_tso; 53 }; 54 55 struct ff_port_cfg { 56 char *name; 57 uint8_t port_id; 58 uint8_t mac[6]; 59 struct ff_hw_features hw_features; 60 char *addr; 61 char *netmask; 62 char *broadcast; 63 char *gateway; 64 char *pcap; 65 uint16_t snaplen; 66 uint32_t savelen; 67 68 int nb_lcores; 69 int nb_slaves; 70 uint16_t lcore_list[DPDK_MAX_LCORE]; 71 uint16_t *slave_portid_list; 72 }; 73 74 struct ff_vdev_cfg { 75 char *name; 76 char *iface; 77 char *path; 78 char *mac; 79 uint8_t vdev_id; 80 uint8_t nb_queues; 81 uint8_t nb_cq; 82 uint16_t queue_size; 83 }; 84 85 struct ff_bond_cfg { 86 char *name; 87 char *slave; 88 char *primary; 89 char *bond_mac; 90 char *xmit_policy; 91 uint8_t bond_id; 92 uint8_t mode; 93 uint8_t socket_id; 94 uint8_t lsc_poll_period_ms; 95 uint16_t up_delay; 96 uint16_t down_delay; 97 }; 98 99 struct ff_freebsd_cfg { 100 char *name; 101 char *str; 102 void *value; 103 size_t vlen; 104 struct ff_freebsd_cfg *next; 105 }; 106 107 struct ff_config { 108 char *filename; 109 struct { 110 char *proc_type; 111 /* mask of enabled lcores */ 112 char *lcore_mask; 113 /* mask of current proc on all lcores */ 114 char *proc_mask; 115 116 /* specify base virtual address to map. */ 117 char *base_virtaddr; 118 119 /* allow processes that do not want to co-operate to have different memory regions */ 120 char *file_prefix; 121 122 /* load an external driver */ 123 char *pci_whitelist; 124 125 int nb_channel; 126 int memory; 127 int no_huge; 128 int nb_procs; 129 int proc_id; 130 int promiscuous; 131 int nb_vdev; 132 int nb_bond; 133 int numa_on; 134 int tso; 135 int tx_csum_offoad_skip; 136 int vlan_strip; 137 int symmetric_rss; 138 139 /* sleep x microseconds when no pkts incomming */ 140 unsigned idle_sleep; 141 142 /* TX burst queue drain nodelay dalay time */ 143 unsigned pkt_tx_delay; 144 145 /* list of proc-lcore */ 146 uint16_t *proc_lcore; 147 148 int nb_ports; 149 uint16_t max_portid; 150 uint16_t *portid_list; 151 // MAP(portid => struct ff_port_cfg*) 152 struct ff_port_cfg *port_cfgs; 153 struct ff_vdev_cfg *vdev_cfgs; 154 struct ff_bond_cfg *bond_cfgs; 155 } dpdk; 156 157 struct { 158 int enable; 159 char *kni_action; 160 char *method; 161 char *tcp_port; 162 char *udp_port; 163 } kni; 164 165 struct { 166 int level; 167 const char *dir; 168 } log; 169 170 struct { 171 struct ff_freebsd_cfg *boot; 172 struct ff_freebsd_cfg *sysctl; 173 long physmem; 174 int hz; 175 int fd_reserve; 176 int mem_size; 177 } freebsd; 178 179 struct { 180 uint16_t enable; 181 uint16_t snap_len; 182 uint32_t save_len; 183 char* save_path; 184 } pcap; 185 }; 186 187 extern struct ff_config ff_global_cfg; 188 189 int ff_load_config(int argc, char * const argv[]); 190 191 #ifdef __cplusplus 192 } 193 #endif 194 195 #endif /* ifndef __FSTACK_CONFIG_H */ 196