2 // Copyright (c) 2010-2020 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <rte_sched.h>
20 #include <rte_ether.h>
21 #include <rte_version.h>
27 #include "prox_port_cfg.h"
30 #include "handle_master.h"
31 #include "prox_compat.h"
32 #include "prox_ipv6.h"
34 #define TEN_GIGABIT 1250000000
35 #define QUEUE_SIZES 128
36 #define NB_PIPES 32768
38 #define RING_RX_SIZE 256
39 #define NB_RX_RING_DESC 2048
40 #define NB_TX_RING_DESC 2048
42 /* 1500000 milliseconds */
43 #define DEFAULT_CPE_TIMEOUT_MS 1500000
46 #if DEFAULT_CPE_TIMEOUT_MS < (DRAIN_TIMEOUT/3000000)
47 #error DEFAULT_CPE_TIMEOUT_MS too small (needs to be at least 2 ms)
50 static const struct rte_eth_conf default_port_conf = {
53 .max_rx_pkt_len = PROX_MTU + PROX_RTE_ETHER_HDR_LEN + PROX_RTE_ETHER_CRC_LEN
61 .lsc = 1, /* lsc interrupt feature enabled */
65 static const struct rte_eth_rxconf default_rx_conf = {
69 static struct rte_eth_txconf default_tx_conf = {
75 .tx_free_thresh = 32, /* Use PMD default values */
76 .tx_rs_thresh = 32, /* Use PMD default values */
79 #if RTE_VERSION >= RTE_VERSION_NUM(20,11,0,0)
80 static struct rte_sched_subport_profile_params subport_profile_params_default = {
81 .tb_rate = TEN_GIGABIT / NB_PIPES,
84 .tc_rate = {TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES},
89 static struct rte_sched_port_params port_params_default = {
92 .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
94 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
95 .n_subports_per_port = 1,
96 #if RTE_VERSION >= RTE_VERSION_NUM(20,11,0,0)
97 .subport_profiles = &subport_profile_params_default,
99 .n_pipes_per_subport = NB_PIPES,
100 #if RTE_VERSION < RTE_VERSION_NUM(19,11,0,0)
101 .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
102 .pipe_profiles = NULL,
103 .n_pipe_profiles = 1 /* only one profile */
107 static struct rte_sched_pipe_params pipe_params_default = {
108 .tb_rate = TEN_GIGABIT / NB_PIPES,
111 .tc_rate = {TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES},
114 #if RTE_VERSION >= RTE_VERSION_NUM(19,8,0,0)
115 .wrr_weights = {1, 1, 1, 1},
117 .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
121 static struct rte_sched_subport_params subport_params_default = {
122 #if RTE_VERSION < RTE_VERSION_NUM(20,11,0,0)
123 .tb_rate = TEN_GIGABIT,
125 .tc_rate = {TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT},
126 .tc_period = 40, /* default was 10 */
128 #if RTE_VERSION > RTE_VERSION_NUM(19,11,0,0)
129 .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
130 .pipe_profiles = NULL,
131 .n_pipe_profiles = 1 /* only one profile */
135 void set_global_defaults(struct prox_cfg *prox_cfg)
137 if (parse_ip6(&prox_cfg->all_routers_ipv6_mcast_addr, ALL_ROUTERS_IPV6_MCAST_ADDR) != 0)
138 plog_err("Failed to parse %s\n", ALL_ROUTERS_IPV6_MCAST_ADDR);
139 if (parse_ip6(&prox_cfg->all_nodes_ipv6_mcast_addr, ALL_NODES_IPV6_MCAST_ADDR) != 0)
140 plog_err("Failed to parse %s\n", ALL_NODES_IPV6_MCAST_ADDR);
141 if (parse_ip6(&prox_cfg->random_ip, RANDOM_IPV6) != 0)
142 plog_err("Failed to parse %s\n", RANDOM_IPV6);
143 set_mcast_mac_from_ipv6(&prox_cfg->all_routers_mac_addr, &prox_cfg->all_routers_ipv6_mcast_addr);
144 set_mcast_mac_from_ipv6(&prox_cfg->all_nodes_mac_addr, &prox_cfg->all_nodes_ipv6_mcast_addr);
147 void set_task_defaults(struct prox_cfg* prox_cfg, struct lcore_cfg* lcore_cfg_init)
149 prox_cfg->master = RTE_MAX_LCORE;
150 handle_ctrl_plane = NULL;
152 for (uint32_t i = 0; i < RTE_DIM(prox_cfg->cpe_table_ports); ++i) {
153 prox_cfg->cpe_table_ports[i] = -1;
156 for (uint8_t lcore_id = 0; lcore_id < RTE_MAX_LCORE; ++lcore_id) {
157 struct lcore_cfg *cur_lcore_cfg_init = &lcore_cfg_init[lcore_id];
158 cur_lcore_cfg_init->id = lcore_id;
159 for (uint8_t task_id = 0; task_id < MAX_TASKS_PER_CORE; ++task_id) {
160 struct task_args *targ = &cur_lcore_cfg_init->targs[task_id];
161 for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
162 targ->rx_port_queue[port_id].port = OUT_DISCARD;
164 targ->flags |= TASK_ARG_DROP;
165 targ->flags |= TASK_ARG_QINQ_ACL;
166 targ->cpe_table_timeout_ms = DEFAULT_CPE_TIMEOUT_MS;
167 targ->n_flows = NB_PIPES;
168 /* configure default values for QoS (can be overwritten by config) */
169 targ->qos_conf.port_params = port_params_default;
170 targ->qos_conf.pipe_params[0] = pipe_params_default;
171 targ->qos_conf.subport_params[0] = subport_params_default;
172 #if RTE_VERSION > RTE_VERSION_NUM(19,11,0,0)
173 targ->qos_conf.subport_params[0].pipe_profiles = targ->qos_conf.pipe_params;
175 targ->qos_conf.port_params.pipe_profiles = targ->qos_conf.pipe_params;
177 targ->qos_conf.port_params.rate = TEN_GIGABIT;
178 targ->qinq_tag = ETYPE_8021ad;
179 targ->n_concur_conn = 8192*2;
181 for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
182 targ->tx_port_queue[port_id].port = OUT_DISCARD;
185 for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i) {
186 targ->mapping[i] = i; // identity
189 targ->cbs = PROX_RTE_ETHER_MAX_LEN;
190 targ->ebs = PROX_RTE_ETHER_MAX_LEN;
191 targ->pbs = PROX_RTE_ETHER_MAX_LEN;
193 targ->n_max_rules = 1024;
194 targ->ring_size = RING_RX_SIZE;
195 targ->nb_cache_mbuf = MAX_PKT_BURST * 4;
196 targ->overhead = PROX_RTE_ETHER_CRC_LEN + 20;
198 targ->tunnel_hop_limit = 3;
199 targ->ctrl_freq = 1000;
200 targ->lb_friend_core = 0xFF;
203 targ->runtime_flags |= TASK_TX_CRC;
204 targ->accuracy_limit_nsec = 5000;
205 targ->probability_delay = 1000000;
206 targ->probability_no_drop = 1000000;
211 void set_port_defaults(void)
213 for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i ) {
214 prox_port_cfg[i].promiscuous = 1;
215 prox_port_cfg[i].nb_mc_addr = 0;
216 prox_port_cfg[i].n_rxd = NB_RX_RING_DESC;
217 prox_port_cfg[i].n_txd = NB_TX_RING_DESC;
218 prox_port_cfg[i].port_conf = default_port_conf;
219 prox_port_cfg[i].tx_conf = default_tx_conf;
220 prox_port_cfg[i].rx_conf = default_rx_conf;
221 prox_port_cfg[i].rx_ring[0] = '\0';
222 prox_port_cfg[i].tx_ring[0] = '\0';
223 prox_port_cfg[i].mtu = PROX_MTU;
224 prox_port_cfg[i].dpdk_mapping = NO_VDEV_PORT;
226 // CRC_STRIP becoming the default behavior in DPDK 18.08, and
227 // DEV_RX_OFFLOAD_CRC_STRIP define has been deleted
228 #if defined (DEV_RX_OFFLOAD_CRC_STRIP)
229 prox_port_cfg[i].requested_rx_offload = DEV_RX_OFFLOAD_CRC_STRIP;
231 prox_port_cfg[i].requested_tx_offload = DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM;