xref: /f-stack/lib/ff_config.h (revision a1d3d0a7)
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         int nb_channel;
120         int memory;
121         int no_huge;
122         int nb_procs;
123         int proc_id;
124         int promiscuous;
125         int nb_vdev;
126         int nb_bond;
127         int numa_on;
128         int tso;
129         int tx_csum_offoad_skip;
130         int vlan_strip;
131         int symmetric_rss;
132 
133         /* sleep x microseconds when no pkts incomming */
134         unsigned idle_sleep;
135 
136         /* TX burst queue drain nodelay dalay time */
137         unsigned pkt_tx_delay;
138 
139         /* list of proc-lcore */
140         uint16_t *proc_lcore;
141 
142         int nb_ports;
143         uint16_t max_portid;
144         uint16_t *portid_list;
145         // MAP(portid => struct ff_port_cfg*)
146         struct ff_port_cfg *port_cfgs;
147         struct ff_vdev_cfg *vdev_cfgs;
148         struct ff_bond_cfg *bond_cfgs;
149     } dpdk;
150 
151     struct {
152         int enable;
153         char *kni_action;
154         char *method;
155         char *tcp_port;
156         char *udp_port;
157     } kni;
158 
159     struct {
160         int level;
161         const char *dir;
162     } log;
163 
164     struct {
165         struct ff_freebsd_cfg *boot;
166         struct ff_freebsd_cfg *sysctl;
167         long physmem;
168         int hz;
169         int fd_reserve;
170         int mem_size;
171     } freebsd;
172 
173     struct {
174         uint16_t enable;
175         uint16_t snap_len;
176         uint32_t save_len;
177         char*	 save_path;
178     } pcap;
179 };
180 
181 extern struct ff_config ff_global_cfg;
182 
183 int ff_load_config(int argc, char * const argv[]);
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* ifndef __FSTACK_CONFIG_H */
190