Increase default mbuf size and code simplification/cleanup
[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
31 #define TEN_GIGABIT     1250000000
32 #define QUEUE_SIZES     128
33 #define NB_PIPES        32768
34 #define NB_MBUF         4096
35 #define RING_RX_SIZE    256
36 #define NB_RX_RING_DESC 256
37 #define NB_TX_RING_DESC 256
38
39 /* 1500000 milliseconds */
40 #define DEFAULT_CPE_TIMEOUT_MS    1500000
41
42 /**/
43 #if DEFAULT_CPE_TIMEOUT_MS < (DRAIN_TIMEOUT/3000000)
44 #error DEFAULT_CPE_TIMEOUT_MS too small (needs to be at least 2 ms)
45 #endif
46
47 static const struct rte_eth_conf default_port_conf = {
48         .rxmode = {
49                 .split_hdr_size = 0,
50                 .header_split   = 0, /* Header Split disabled */
51                 .hw_ip_checksum = 0, /* IP checksum offload disabled */
52                 .hw_vlan_filter = 0, /* VLAN filtering disabled */
53                 .hw_vlan_strip = 0, /* VLAN filtering disabled */
54                 .jumbo_frame    = 0, /* Jumbo frame support disabled */
55                 .hw_strip_crc   = 1, /* CRC stripped by hardware --- always set to 1 in VF */
56                 .hw_vlan_extend = 0,
57                 .mq_mode        = 0,
58                 .max_rx_pkt_len = PROX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN
59         },
60         .rx_adv_conf = {
61                 .rss_conf = {
62                         .rss_key = NULL,
63                 },
64         },
65         .intr_conf = {
66                 .lsc = 1, /* lsc interrupt feature enabled */
67         },
68 };
69
70 static const struct rte_eth_rxconf default_rx_conf = {
71         .rx_free_thresh = 32,
72 };
73
74 static struct rte_eth_txconf default_tx_conf = {
75         .tx_thresh = {
76                 .pthresh = 32,
77                 .hthresh = 8,
78                 .wthresh = 0,
79         },
80         .tx_free_thresh = 32, /* Use PMD default values */
81         .tx_rs_thresh = 32, /* Use PMD default values */
82 };
83
84 static struct rte_sched_port_params port_params_default = {
85         .name = "port_0",
86         .socket = 0,
87         .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
88         .rate = 0,
89         .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
90         .n_subports_per_port = 1,
91         .n_pipes_per_subport = NB_PIPES,
92         .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
93         .pipe_profiles = NULL,
94         .n_pipe_profiles = 1 /* only one profile */
95 };
96
97 static struct rte_sched_pipe_params pipe_params_default = {
98         .tb_rate = TEN_GIGABIT / NB_PIPES,
99         .tb_size = 4000000,
100
101         .tc_rate = {TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES},
102         .tc_period = 40,
103
104         .wrr_weights = {1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1},
105 };
106
107 static struct rte_sched_subport_params subport_params_default = {
108         .tb_rate = TEN_GIGABIT,
109         .tb_size = 4000000,
110         .tc_rate = {TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT},
111         .tc_period = 40, /* default was 10 */
112 };
113
114 void set_global_defaults(__attribute__((unused)) struct prox_cfg *prox_cfg)
115 {
116 }
117
118 void set_task_defaults(struct prox_cfg* prox_cfg, struct lcore_cfg* lcore_cfg_init)
119 {
120         prox_cfg->master = RTE_MAX_LCORE;
121         handle_ctrl_plane = NULL;
122
123         for (uint32_t i = 0; i < RTE_DIM(prox_cfg->cpe_table_ports); ++i) {
124                 prox_cfg->cpe_table_ports[i] = -1;
125         }
126
127         for (uint8_t lcore_id = 0; lcore_id < RTE_MAX_LCORE; ++lcore_id) {
128                 struct lcore_cfg *cur_lcore_cfg_init = &lcore_cfg_init[lcore_id];
129                 cur_lcore_cfg_init->id = lcore_id;
130                 for (uint8_t task_id = 0; task_id < MAX_TASKS_PER_CORE; ++task_id) {
131                         struct task_args *targ = &cur_lcore_cfg_init->targs[task_id];
132                         for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
133                                 targ->rx_port_queue[port_id].port = OUT_DISCARD;
134                         }
135                         targ->flags |= TASK_ARG_DROP;
136                         targ->flags |= TASK_ARG_QINQ_ACL;
137                         targ->cpe_table_timeout_ms = DEFAULT_CPE_TIMEOUT_MS;
138                         targ->n_flows = NB_PIPES;
139                         /* configure default values for QoS (can be overwritten by config) */
140                         targ->qos_conf.port_params = port_params_default;
141                         targ->qos_conf.pipe_params[0] = pipe_params_default;
142                         targ->qos_conf.subport_params[0] = subport_params_default;
143                         targ->qos_conf.port_params.pipe_profiles = targ->qos_conf.pipe_params;
144                         targ->qos_conf.port_params.rate = TEN_GIGABIT;
145                         targ->qinq_tag = ETYPE_8021ad;
146                         targ->n_concur_conn = 8192*2;
147
148                         for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
149                                 targ->tx_port_queue[port_id].port = OUT_DISCARD;
150                         }
151
152                         for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i) {
153                                 targ->mapping[i] = i; // identity
154                         }
155
156                         targ->cbs = ETHER_MAX_LEN;
157                         targ->ebs = ETHER_MAX_LEN;
158                         targ->pbs = ETHER_MAX_LEN;
159
160                         targ->n_max_rules = 1024;
161                         targ->ring_size = RING_RX_SIZE;
162                         targ->nb_cache_mbuf = MAX_PKT_BURST * 4;
163                         targ->overhead = ETHER_CRC_LEN + 20;
164
165                         targ->tunnel_hop_limit = 3;
166                         targ->ctrl_freq = 1000;
167                         targ->lb_friend_core = 0xFF;
168                         targ->n_pkts = 1024*64;
169                         targ->runtime_flags |= TASK_TX_CRC;
170                         targ->accuracy_limit_nsec = 5000;
171                 }
172         }
173 }
174
175 void set_port_defaults(void)
176 {
177         for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i ) {
178                 prox_port_cfg[i].promiscuous = 1;
179                 prox_port_cfg[i].n_rxd = NB_RX_RING_DESC;
180                 prox_port_cfg[i].n_txd = NB_TX_RING_DESC;
181                 prox_port_cfg[i].port_conf = default_port_conf;
182                 prox_port_cfg[i].tx_conf = default_tx_conf;
183                 prox_port_cfg[i].rx_conf = default_rx_conf;
184                 prox_port_cfg[i].rx_ring[0] = '\0';
185                 prox_port_cfg[i].tx_ring[0] = '\0';
186                 prox_port_cfg[i].mtu = PROX_MTU;
187         }
188 }