Added support for DPDK 19.11
[samplevnf.git] / VNFs / DPPD-PROX / defaults.c
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include <string.h>
18 #include <libgen.h>
19 #include <rte_sched.h>
20 #include <rte_version.h>
21
22 #include "lconf.h"
23 #include "defaults.h"
24 #include "defines.h"
25 #include "prox_cfg.h"
26 #include "prox_port_cfg.h"
27 #include "etypes.h"
28 #include "toeplitz.h"
29 #include "handle_master.h"
30 #include "prox_compat.h"
31
32 #define TEN_GIGABIT     1250000000
33 #define QUEUE_SIZES     128
34 #define NB_PIPES        32768
35 #define NB_MBUF         4096
36 #define RING_RX_SIZE    256
37 #define NB_RX_RING_DESC 2048
38 #define NB_TX_RING_DESC 2048
39
40 /* 1500000 milliseconds */
41 #define DEFAULT_CPE_TIMEOUT_MS    1500000
42
43 /**/
44 #if DEFAULT_CPE_TIMEOUT_MS < (DRAIN_TIMEOUT/3000000)
45 #error DEFAULT_CPE_TIMEOUT_MS too small (needs to be at least 2 ms)
46 #endif
47
48 static const struct rte_eth_conf default_port_conf = {
49         .rxmode = {
50                 .mq_mode        = 0,
51                 .max_rx_pkt_len = PROX_MTU + PROX_RTE_ETHER_HDR_LEN + PROX_RTE_ETHER_CRC_LEN
52         },
53         .rx_adv_conf = {
54                 .rss_conf = {
55                         .rss_key = NULL,
56                 },
57         },
58         .intr_conf = {
59                 .lsc = 1, /* lsc interrupt feature enabled */
60         },
61 };
62
63 static const struct rte_eth_rxconf default_rx_conf = {
64         .rx_free_thresh = 32,
65 };
66
67 static struct rte_eth_txconf default_tx_conf = {
68         .tx_thresh = {
69                 .pthresh = 32,
70                 .hthresh = 8,
71                 .wthresh = 0,
72         },
73         .tx_free_thresh = 32, /* Use PMD default values */
74         .tx_rs_thresh = 32, /* Use PMD default values */
75 };
76
77 static struct rte_sched_port_params port_params_default = {
78         .name = "port_0",
79         .socket = 0,
80         .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
81         .rate = 0,
82         .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
83         .n_subports_per_port = 1,
84         .n_pipes_per_subport = NB_PIPES,
85 #if RTE_VERSION < RTE_VERSION_NUM(19,11,0,0)
86         .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
87         .pipe_profiles = NULL,
88         .n_pipe_profiles = 1 /* only one profile */
89 #endif
90 };
91
92 static struct rte_sched_pipe_params pipe_params_default = {
93         .tb_rate = TEN_GIGABIT / NB_PIPES,
94         .tb_size = 4000000,
95
96         .tc_rate = {TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES},
97         .tc_period = 40,
98
99 #if RTE_VERSION >= RTE_VERSION_NUM(19,8,0,0)
100         .wrr_weights = {1, 1, 1, 1},
101 #else
102         .wrr_weights = {1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1},
103 #endif
104 };
105
106 static struct rte_sched_subport_params subport_params_default = {
107         .tb_rate = TEN_GIGABIT,
108         .tb_size = 4000000,
109         .tc_rate = {TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT},
110         .tc_period = 40, /* default was 10 */
111 #if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
112         .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
113         .pipe_profiles = NULL,
114         .n_pipe_profiles = 1 /* only one profile */
115 #endif
116 };
117
118 void set_global_defaults(__attribute__((unused)) struct prox_cfg *prox_cfg)
119 {
120 }
121
122 void set_task_defaults(struct prox_cfg* prox_cfg, struct lcore_cfg* lcore_cfg_init)
123 {
124         prox_cfg->master = RTE_MAX_LCORE;
125         handle_ctrl_plane = NULL;
126
127         for (uint32_t i = 0; i < RTE_DIM(prox_cfg->cpe_table_ports); ++i) {
128                 prox_cfg->cpe_table_ports[i] = -1;
129         }
130
131         for (uint8_t lcore_id = 0; lcore_id < RTE_MAX_LCORE; ++lcore_id) {
132                 struct lcore_cfg *cur_lcore_cfg_init = &lcore_cfg_init[lcore_id];
133                 cur_lcore_cfg_init->id = lcore_id;
134                 for (uint8_t task_id = 0; task_id < MAX_TASKS_PER_CORE; ++task_id) {
135                         struct task_args *targ = &cur_lcore_cfg_init->targs[task_id];
136                         for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
137                                 targ->rx_port_queue[port_id].port = OUT_DISCARD;
138                         }
139                         targ->flags |= TASK_ARG_DROP;
140                         targ->flags |= TASK_ARG_QINQ_ACL;
141                         targ->cpe_table_timeout_ms = DEFAULT_CPE_TIMEOUT_MS;
142                         targ->n_flows = NB_PIPES;
143                         /* configure default values for QoS (can be overwritten by config) */
144                         targ->qos_conf.port_params = port_params_default;
145                         targ->qos_conf.pipe_params[0] = pipe_params_default;
146                         targ->qos_conf.subport_params[0] = subport_params_default;
147 #if RTE_VERSION >= RTE_VERSION_NUM(19,11,0,0)
148                         targ->qos_conf.subport_params[0].pipe_profiles = targ->qos_conf.pipe_params;
149 #else
150                         targ->qos_conf.port_params.pipe_profiles = targ->qos_conf.pipe_params;
151 #endif
152                         targ->qos_conf.port_params.rate = TEN_GIGABIT;
153                         targ->qinq_tag = ETYPE_8021ad;
154                         targ->n_concur_conn = 8192*2;
155
156                         for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
157                                 targ->tx_port_queue[port_id].port = OUT_DISCARD;
158                         }
159
160                         for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i) {
161                                 targ->mapping[i] = i; // identity
162                         }
163
164                         targ->cbs = PROX_RTE_ETHER_MAX_LEN;
165                         targ->ebs = PROX_RTE_ETHER_MAX_LEN;
166                         targ->pbs = PROX_RTE_ETHER_MAX_LEN;
167
168                         targ->n_max_rules = 1024;
169                         targ->ring_size = RING_RX_SIZE;
170                         targ->nb_cache_mbuf = MAX_PKT_BURST * 4;
171                         targ->overhead = PROX_RTE_ETHER_CRC_LEN + 20;
172
173                         targ->tunnel_hop_limit = 3;
174                         targ->ctrl_freq = 1000;
175                         targ->lb_friend_core = 0xFF;
176                         targ->n_pkts = 0;
177
178                         targ->runtime_flags |= TASK_TX_CRC;
179                         targ->accuracy_limit_nsec = 5000;
180                 }
181         }
182 }
183
184 void set_port_defaults(void)
185 {
186         for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i ) {
187                 prox_port_cfg[i].promiscuous = 1;
188                 prox_port_cfg[i].nb_mc_addr = 0;
189                 prox_port_cfg[i].n_rxd = NB_RX_RING_DESC;
190                 prox_port_cfg[i].n_txd = NB_TX_RING_DESC;
191                 prox_port_cfg[i].port_conf = default_port_conf;
192                 prox_port_cfg[i].tx_conf = default_tx_conf;
193                 prox_port_cfg[i].rx_conf = default_rx_conf;
194                 prox_port_cfg[i].rx_ring[0] = '\0';
195                 prox_port_cfg[i].tx_ring[0] = '\0';
196                 prox_port_cfg[i].mtu = PROX_MTU;
197
198                 // CRC_STRIP becoming the default behavior in DPDK 18.08, and
199                 // DEV_RX_OFFLOAD_CRC_STRIP define has been deleted
200 #if defined (DEV_RX_OFFLOAD_CRC_STRIP)
201                 prox_port_cfg[i].requested_rx_offload = DEV_RX_OFFLOAD_CRC_STRIP;
202 #endif
203                 prox_port_cfg[i].requested_tx_offload = DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM;
204         }
205 }