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 65 #ifdef INET6 66 char *addr6_str; 67 char *gateway6_str; 68 uint8_t prefix_len; 69 #endif 70 71 int nb_lcores; 72 int nb_slaves; 73 uint16_t lcore_list[DPDK_MAX_LCORE]; 74 uint16_t *slave_portid_list; 75 }; 76 77 struct ff_vdev_cfg { 78 char *name; 79 char *iface; 80 char *path; 81 char *mac; 82 uint8_t vdev_id; 83 uint8_t nb_queues; 84 uint8_t nb_cq; 85 uint16_t queue_size; 86 }; 87 88 struct ff_bond_cfg { 89 char *name; 90 char *slave; 91 char *primary; 92 char *bond_mac; 93 char *xmit_policy; 94 uint8_t bond_id; 95 uint8_t mode; 96 uint8_t socket_id; 97 uint8_t lsc_poll_period_ms; 98 uint16_t up_delay; 99 uint16_t down_delay; 100 }; 101 102 struct ff_freebsd_cfg { 103 char *name; 104 char *str; 105 void *value; 106 size_t vlen; 107 struct ff_freebsd_cfg *next; 108 }; 109 110 struct ff_config { 111 char *filename; 112 struct { 113 char *proc_type; 114 /* mask of enabled lcores */ 115 char *lcore_mask; 116 /* mask of current proc on all lcores */ 117 char *proc_mask; 118 119 /* specify base virtual address to map. */ 120 char *base_virtaddr; 121 122 /* allow processes that do not want to co-operate to have different memory regions */ 123 char *file_prefix; 124 125 /* load an external driver */ 126 char *pci_whitelist; 127 128 int nb_channel; 129 int memory; 130 int no_huge; 131 int nb_procs; 132 int proc_id; 133 int promiscuous; 134 int nb_vdev; 135 int nb_bond; 136 int numa_on; 137 int tso; 138 int tx_csum_offoad_skip; 139 int vlan_strip; 140 int symmetric_rss; 141 142 /* sleep x microseconds when no pkts incomming */ 143 unsigned idle_sleep; 144 145 /* TX burst queue drain nodelay dalay time */ 146 unsigned pkt_tx_delay; 147 148 /* list of proc-lcore */ 149 uint16_t *proc_lcore; 150 151 int nb_ports; 152 uint16_t max_portid; 153 uint16_t *portid_list; 154 // MAP(portid => struct ff_port_cfg*) 155 struct ff_port_cfg *port_cfgs; 156 struct ff_vdev_cfg *vdev_cfgs; 157 struct ff_bond_cfg *bond_cfgs; 158 } dpdk; 159 160 struct { 161 int enable; 162 char *kni_action; 163 char *method; 164 char *tcp_port; 165 char *udp_port; 166 } kni; 167 168 struct { 169 int level; 170 const char *dir; 171 } log; 172 173 struct { 174 struct ff_freebsd_cfg *boot; 175 struct ff_freebsd_cfg *sysctl; 176 long physmem; 177 int hz; 178 int fd_reserve; 179 int mem_size; 180 } freebsd; 181 182 struct { 183 uint16_t enable; 184 uint16_t snap_len; 185 uint32_t save_len; 186 char* save_path; 187 } pcap; 188 }; 189 190 extern struct ff_config ff_global_cfg; 191 192 int ff_load_config(int argc, char * const argv[]); 193 194 #ifdef __cplusplus 195 } 196 #endif 197 198 #endif /* ifndef __FSTACK_CONFIG_H */ 199