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 static struct rte_sched_port_params port_params_default = {
82 .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
84 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
85 .n_subports_per_port = 1,
86 .n_pipes_per_subport = NB_PIPES,
87 #if RTE_VERSION < RTE_VERSION_NUM(19,11,0,0)
88 .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
89 .pipe_profiles = NULL,
90 .n_pipe_profiles = 1 /* only one profile */
94 static struct rte_sched_pipe_params pipe_params_default = {
95 .tb_rate = TEN_GIGABIT / NB_PIPES,
98 .tc_rate = {TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES, TEN_GIGABIT / NB_PIPES},
101 #if RTE_VERSION >= RTE_VERSION_NUM(19,8,0,0)
102 .wrr_weights = {1, 1, 1, 1},
104 .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
108 static struct rte_sched_subport_params subport_params_default = {
109 .tb_rate = TEN_GIGABIT,
111 .tc_rate = {TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT, TEN_GIGABIT},
112 .tc_period = 40, /* default was 10 */
113 #if RTE_VERSION > RTE_VERSION_NUM(19,11,0,0)
114 .qsize = {QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES, QUEUE_SIZES},
115 .pipe_profiles = NULL,
116 .n_pipe_profiles = 1 /* only one profile */
120 void set_global_defaults(struct prox_cfg *prox_cfg)
122 if (parse_ip6(&prox_cfg->all_routers_ipv6_mcast_addr, ALL_ROUTERS_IPV6_MCAST_ADDR) != 0)
123 plog_err("Failed to parse %s\n", ALL_ROUTERS_IPV6_MCAST_ADDR);
124 if (parse_ip6(&prox_cfg->all_nodes_ipv6_mcast_addr, ALL_NODES_IPV6_MCAST_ADDR) != 0)
125 plog_err("Failed to parse %s\n", ALL_NODES_IPV6_MCAST_ADDR);
126 if (parse_ip6(&prox_cfg->random_ip, RANDOM_IPV6) != 0)
127 plog_err("Failed to parse %s\n", RANDOM_IPV6);
128 set_mcast_mac_from_ipv6(&prox_cfg->all_routers_mac_addr, &prox_cfg->all_routers_ipv6_mcast_addr);
129 set_mcast_mac_from_ipv6(&prox_cfg->all_nodes_mac_addr, &prox_cfg->all_nodes_ipv6_mcast_addr);
132 void set_task_defaults(struct prox_cfg* prox_cfg, struct lcore_cfg* lcore_cfg_init)
134 prox_cfg->master = RTE_MAX_LCORE;
135 handle_ctrl_plane = NULL;
137 for (uint32_t i = 0; i < RTE_DIM(prox_cfg->cpe_table_ports); ++i) {
138 prox_cfg->cpe_table_ports[i] = -1;
141 for (uint8_t lcore_id = 0; lcore_id < RTE_MAX_LCORE; ++lcore_id) {
142 struct lcore_cfg *cur_lcore_cfg_init = &lcore_cfg_init[lcore_id];
143 cur_lcore_cfg_init->id = lcore_id;
144 for (uint8_t task_id = 0; task_id < MAX_TASKS_PER_CORE; ++task_id) {
145 struct task_args *targ = &cur_lcore_cfg_init->targs[task_id];
146 for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
147 targ->rx_port_queue[port_id].port = OUT_DISCARD;
149 targ->flags |= TASK_ARG_DROP;
150 targ->flags |= TASK_ARG_QINQ_ACL;
151 targ->cpe_table_timeout_ms = DEFAULT_CPE_TIMEOUT_MS;
152 targ->n_flows = NB_PIPES;
153 /* configure default values for QoS (can be overwritten by config) */
154 targ->qos_conf.port_params = port_params_default;
155 targ->qos_conf.pipe_params[0] = pipe_params_default;
156 targ->qos_conf.subport_params[0] = subport_params_default;
157 #if RTE_VERSION > RTE_VERSION_NUM(19,11,0,0)
158 targ->qos_conf.subport_params[0].pipe_profiles = targ->qos_conf.pipe_params;
160 targ->qos_conf.port_params.pipe_profiles = targ->qos_conf.pipe_params;
162 targ->qos_conf.port_params.rate = TEN_GIGABIT;
163 targ->qinq_tag = ETYPE_8021ad;
164 targ->n_concur_conn = 8192*2;
166 for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
167 targ->tx_port_queue[port_id].port = OUT_DISCARD;
170 for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i) {
171 targ->mapping[i] = i; // identity
174 targ->cbs = PROX_RTE_ETHER_MAX_LEN;
175 targ->ebs = PROX_RTE_ETHER_MAX_LEN;
176 targ->pbs = PROX_RTE_ETHER_MAX_LEN;
178 targ->n_max_rules = 1024;
179 targ->ring_size = RING_RX_SIZE;
180 targ->nb_cache_mbuf = MAX_PKT_BURST * 4;
181 targ->overhead = PROX_RTE_ETHER_CRC_LEN + 20;
183 targ->tunnel_hop_limit = 3;
184 targ->ctrl_freq = 1000;
185 targ->lb_friend_core = 0xFF;
188 targ->runtime_flags |= TASK_TX_CRC;
189 targ->accuracy_limit_nsec = 5000;
190 targ->probability_delay = 1000000;
191 targ->probability_no_drop = 1000000;
196 void set_port_defaults(void)
198 for (uint8_t i = 0; i < PROX_MAX_PORTS; ++i ) {
199 prox_port_cfg[i].promiscuous = 1;
200 prox_port_cfg[i].nb_mc_addr = 0;
201 prox_port_cfg[i].n_rxd = NB_RX_RING_DESC;
202 prox_port_cfg[i].n_txd = NB_TX_RING_DESC;
203 prox_port_cfg[i].port_conf = default_port_conf;
204 prox_port_cfg[i].tx_conf = default_tx_conf;
205 prox_port_cfg[i].rx_conf = default_rx_conf;
206 prox_port_cfg[i].rx_ring[0] = '\0';
207 prox_port_cfg[i].tx_ring[0] = '\0';
208 prox_port_cfg[i].mtu = PROX_MTU;
209 prox_port_cfg[i].dpdk_mapping = NO_VDEV_PORT;
211 // CRC_STRIP becoming the default behavior in DPDK 18.08, and
212 // DEV_RX_OFFLOAD_CRC_STRIP define has been deleted
213 #if defined (DEV_RX_OFFLOAD_CRC_STRIP)
214 prox_port_cfg[i].requested_rx_offload = DEV_RX_OFFLOAD_CRC_STRIP;
216 prox_port_cfg[i].requested_tx_offload = DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM;