1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
10 #include <rte_debug.h>
11 #include <rte_ethdev.h>
12 #include <rte_mempool.h>
13 #include <rte_sched.h>
14 #include <rte_cycles.h>
15 #include <rte_string_fns.h>
16 #include <rte_cfgfile.h>
21 uint32_t app_numa_mask = 0;
22 static uint32_t app_inited_port_mask = 0;
24 int app_pipe_to_profile[MAX_SCHED_SUBPORTS][MAX_SCHED_PIPES];
26 #define MAX_NAME_LEN 32
28 struct ring_conf ring_conf = {
29 .rx_size = APP_RX_DESC_DEFAULT,
30 .ring_size = APP_RING_SIZE,
31 .tx_size = APP_TX_DESC_DEFAULT,
34 struct burst_conf burst_conf = {
35 .rx_burst = MAX_PKT_RX_BURST,
36 .ring_burst = PKT_ENQUEUE,
37 .qos_dequeue = PKT_DEQUEUE,
38 .tx_burst = MAX_PKT_TX_BURST,
41 struct ring_thresh rx_thresh = {
42 .pthresh = RX_PTHRESH,
43 .hthresh = RX_HTHRESH,
44 .wthresh = RX_WTHRESH,
47 struct ring_thresh tx_thresh = {
48 .pthresh = TX_PTHRESH,
49 .hthresh = TX_HTHRESH,
50 .wthresh = TX_WTHRESH,
54 const char *cfg_profile = NULL;
55 int mp_size = NB_MBUF;
56 struct flow_conf qos_conf[MAX_DATA_STREAMS];
58 static const struct rte_eth_conf port_conf = {
60 .max_rx_pkt_len = ETHER_MAX_LEN,
62 .header_split = 0, /**< Header Split disabled */
63 .hw_ip_checksum = 0, /**< IP checksum offload disabled */
64 .hw_vlan_filter = 0, /**< VLAN filtering disabled */
65 .jumbo_frame = 0, /**< Jumbo Frame Support disabled */
66 .hw_strip_crc = 1, /**< CRC stripped by hardware */
69 .mq_mode = ETH_DCB_NONE,
74 app_init_port(uint16_t portid, struct rte_mempool *mp)
77 struct rte_eth_link link;
78 struct rte_eth_rxconf rx_conf;
79 struct rte_eth_txconf tx_conf;
83 /* check if port already initialized (multistream configuration) */
84 if (app_inited_port_mask & (1u << portid))
87 rx_conf.rx_thresh.pthresh = rx_thresh.pthresh;
88 rx_conf.rx_thresh.hthresh = rx_thresh.hthresh;
89 rx_conf.rx_thresh.wthresh = rx_thresh.wthresh;
90 rx_conf.rx_free_thresh = 32;
91 rx_conf.rx_drop_en = 0;
92 rx_conf.rx_deferred_start = 0;
94 tx_conf.tx_thresh.pthresh = tx_thresh.pthresh;
95 tx_conf.tx_thresh.hthresh = tx_thresh.hthresh;
96 tx_conf.tx_thresh.wthresh = tx_thresh.wthresh;
97 tx_conf.tx_free_thresh = 0;
98 tx_conf.tx_rs_thresh = 0;
99 tx_conf.txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS;
100 tx_conf.tx_deferred_start = 0;
103 RTE_LOG(INFO, APP, "Initializing port %"PRIu16"... ", portid);
105 ret = rte_eth_dev_configure(portid, 1, 1, &port_conf);
107 rte_exit(EXIT_FAILURE,
108 "Cannot configure device: err=%d, port=%u\n",
111 rx_size = ring_conf.rx_size;
112 tx_size = ring_conf.tx_size;
113 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &rx_size, &tx_size);
115 rte_exit(EXIT_FAILURE,
116 "rte_eth_dev_adjust_nb_rx_tx_desc: err=%d,port=%u\n",
118 ring_conf.rx_size = rx_size;
119 ring_conf.tx_size = tx_size;
121 /* init one RX queue */
123 ret = rte_eth_rx_queue_setup(portid, 0, (uint16_t)ring_conf.rx_size,
124 rte_eth_dev_socket_id(portid), &rx_conf, mp);
126 rte_exit(EXIT_FAILURE,
127 "rte_eth_tx_queue_setup: err=%d, port=%u\n",
130 /* init one TX queue */
132 ret = rte_eth_tx_queue_setup(portid, 0,
133 (uint16_t)ring_conf.tx_size, rte_eth_dev_socket_id(portid), &tx_conf);
135 rte_exit(EXIT_FAILURE,
136 "rte_eth_tx_queue_setup: err=%d, port=%u queue=%d\n",
140 ret = rte_eth_dev_start(portid);
142 rte_exit(EXIT_FAILURE,
143 "rte_pmd_port_start: err=%d, port=%u\n",
148 /* get link status */
149 rte_eth_link_get(portid, &link);
150 if (link.link_status) {
151 printf(" Link Up - speed %u Mbps - %s\n",
152 (uint32_t) link.link_speed,
153 (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
154 ("full-duplex") : ("half-duplex\n"));
156 printf(" Link Down\n");
158 rte_eth_promiscuous_enable(portid);
160 /* mark port as initialized */
161 app_inited_port_mask |= 1u << portid;
166 static struct rte_sched_subport_params subport_params[MAX_SCHED_SUBPORTS] = {
168 .tb_rate = 1250000000,
171 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000},
176 static struct rte_sched_pipe_params pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT] = {
181 .tc_rate = {305175, 305175, 305175, 305175},
183 #ifdef RTE_SCHED_SUBPORT_TC_OV
187 .wrr_weights = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
191 struct rte_sched_port_params port_params = {
192 .name = "port_scheduler_0",
193 .socket = 0, /* computed */
194 .rate = 0, /* computed */
195 .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
196 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
197 .n_subports_per_port = 1,
198 .n_pipes_per_subport = 4096,
199 .qsize = {64, 64, 64, 64},
200 .pipe_profiles = pipe_profiles,
201 .n_pipe_profiles = sizeof(pipe_profiles) / sizeof(struct rte_sched_pipe_params),
205 /* Traffic Class 0 Colors Green / Yellow / Red */
206 [0][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
207 [0][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
208 [0][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
210 /* Traffic Class 1 - Colors Green / Yellow / Red */
211 [1][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
212 [1][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
213 [1][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
215 /* Traffic Class 2 - Colors Green / Yellow / Red */
216 [2][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
217 [2][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
218 [2][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
220 /* Traffic Class 3 - Colors Green / Yellow / Red */
221 [3][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
222 [3][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
223 [3][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9}
225 #endif /* RTE_SCHED_RED */
228 static struct rte_sched_port *
229 app_init_sched_port(uint32_t portid, uint32_t socketid)
231 static char port_name[32]; /* static as referenced from global port_params*/
232 struct rte_eth_link link;
233 struct rte_sched_port *port = NULL;
234 uint32_t pipe, subport;
237 rte_eth_link_get(portid, &link);
239 port_params.socket = socketid;
240 port_params.rate = (uint64_t) link.link_speed * 1000 * 1000 / 8;
241 snprintf(port_name, sizeof(port_name), "port_%d", portid);
242 port_params.name = port_name;
244 port = rte_sched_port_config(&port_params);
246 rte_exit(EXIT_FAILURE, "Unable to config sched port\n");
249 for (subport = 0; subport < port_params.n_subports_per_port; subport ++) {
250 err = rte_sched_subport_config(port, subport, &subport_params[subport]);
252 rte_exit(EXIT_FAILURE, "Unable to config sched subport %u, err=%d\n",
256 for (pipe = 0; pipe < port_params.n_pipes_per_subport; pipe ++) {
257 if (app_pipe_to_profile[subport][pipe] != -1) {
258 err = rte_sched_pipe_config(port, subport, pipe,
259 app_pipe_to_profile[subport][pipe]);
261 rte_exit(EXIT_FAILURE, "Unable to config sched pipe %u "
262 "for profile %d, err=%d\n", pipe,
263 app_pipe_to_profile[subport][pipe], err);
273 app_load_cfg_profile(const char *profile)
277 struct rte_cfgfile *file = rte_cfgfile_load(profile, 0);
279 rte_exit(EXIT_FAILURE, "Cannot load configuration profile %s\n", profile);
281 cfg_load_port(file, &port_params);
282 cfg_load_subport(file, subport_params);
283 cfg_load_pipe(file, pipe_profiles);
285 rte_cfgfile_close(file);
293 char ring_name[MAX_NAME_LEN];
294 char pool_name[MAX_NAME_LEN];
296 if (rte_eth_dev_count() == 0)
297 rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n");
299 /* load configuration profile */
300 if (app_load_cfg_profile(cfg_profile) != 0)
301 rte_exit(EXIT_FAILURE, "Invalid configuration profile\n");
303 /* Initialize each active flow */
304 for(i = 0; i < nb_pfc; i++) {
305 uint32_t socket = rte_lcore_to_socket_id(qos_conf[i].rx_core);
306 struct rte_ring *ring;
308 snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].rx_core);
309 ring = rte_ring_lookup(ring_name);
311 qos_conf[i].rx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
312 socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
314 qos_conf[i].rx_ring = ring;
316 snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].tx_core);
317 ring = rte_ring_lookup(ring_name);
319 qos_conf[i].tx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
320 socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
322 qos_conf[i].tx_ring = ring;
325 /* create the mbuf pools for each RX Port */
326 snprintf(pool_name, MAX_NAME_LEN, "mbuf_pool%u", i);
327 qos_conf[i].mbuf_pool = rte_pktmbuf_pool_create(pool_name,
328 mp_size, burst_conf.rx_burst * 4, 0,
329 RTE_MBUF_DEFAULT_BUF_SIZE,
330 rte_eth_dev_socket_id(qos_conf[i].rx_port));
331 if (qos_conf[i].mbuf_pool == NULL)
332 rte_exit(EXIT_FAILURE, "Cannot init mbuf pool for socket %u\n", i);
334 app_init_port(qos_conf[i].rx_port, qos_conf[i].mbuf_pool);
335 app_init_port(qos_conf[i].tx_port, qos_conf[i].mbuf_pool);
337 qos_conf[i].sched_port = app_init_sched_port(qos_conf[i].tx_port, socket);
340 RTE_LOG(INFO, APP, "time stamp clock running at %" PRIu64 " Hz\n",
343 RTE_LOG(INFO, APP, "Ring sizes: NIC RX = %u, Mempool = %d SW queue = %u,"
344 "NIC TX = %u\n", ring_conf.rx_size, mp_size, ring_conf.ring_size,
347 RTE_LOG(INFO, APP, "Burst sizes: RX read = %hu, RX write = %hu,\n"
348 " Worker read/QoS enqueue = %hu,\n"
349 " QoS dequeue = %hu, Worker write = %hu\n",
350 burst_conf.rx_burst, burst_conf.ring_burst, burst_conf.ring_burst,
351 burst_conf.qos_dequeue, burst_conf.tx_burst);
353 RTE_LOG(INFO, APP, "NIC thresholds RX (p = %hhu, h = %hhu, w = %hhu),"
354 "TX (p = %hhu, h = %hhu, w = %hhu)\n",
355 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh,
356 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);