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 struct rte_eth_conf port_conf = {
60 .max_rx_pkt_len = RTE_ETHER_MAX_LEN,
64 .mq_mode = ETH_DCB_NONE,
69 app_init_port(uint16_t portid, struct rte_mempool *mp)
72 struct rte_eth_link link;
73 struct rte_eth_dev_info dev_info;
74 struct rte_eth_rxconf rx_conf;
75 struct rte_eth_txconf tx_conf;
78 struct rte_eth_conf local_port_conf = port_conf;
79 char link_status_text[RTE_ETH_LINK_MAX_STR_LEN];
81 /* check if port already initialized (multistream configuration) */
82 if (app_inited_port_mask & (1u << portid))
85 rx_conf.rx_thresh.pthresh = rx_thresh.pthresh;
86 rx_conf.rx_thresh.hthresh = rx_thresh.hthresh;
87 rx_conf.rx_thresh.wthresh = rx_thresh.wthresh;
88 rx_conf.rx_free_thresh = 32;
89 rx_conf.rx_drop_en = 0;
90 rx_conf.rx_deferred_start = 0;
92 tx_conf.tx_thresh.pthresh = tx_thresh.pthresh;
93 tx_conf.tx_thresh.hthresh = tx_thresh.hthresh;
94 tx_conf.tx_thresh.wthresh = tx_thresh.wthresh;
95 tx_conf.tx_free_thresh = 0;
96 tx_conf.tx_rs_thresh = 0;
97 tx_conf.tx_deferred_start = 0;
100 RTE_LOG(INFO, APP, "Initializing port %"PRIu16"... ", portid);
103 ret = rte_eth_dev_info_get(portid, &dev_info);
105 rte_exit(EXIT_FAILURE,
106 "Error during getting device (port %u) info: %s\n",
107 portid, strerror(-ret));
109 if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
110 local_port_conf.txmode.offloads |=
111 DEV_TX_OFFLOAD_MBUF_FAST_FREE;
112 ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
114 rte_exit(EXIT_FAILURE,
115 "Cannot configure device: err=%d, port=%u\n",
118 rx_size = ring_conf.rx_size;
119 tx_size = ring_conf.tx_size;
120 ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &rx_size, &tx_size);
122 rte_exit(EXIT_FAILURE,
123 "rte_eth_dev_adjust_nb_rx_tx_desc: err=%d,port=%u\n",
125 ring_conf.rx_size = rx_size;
126 ring_conf.tx_size = tx_size;
128 /* init one RX queue */
130 rx_conf.offloads = local_port_conf.rxmode.offloads;
131 ret = rte_eth_rx_queue_setup(portid, 0, (uint16_t)ring_conf.rx_size,
132 rte_eth_dev_socket_id(portid), &rx_conf, mp);
134 rte_exit(EXIT_FAILURE,
135 "rte_eth_tx_queue_setup: err=%d, port=%u\n",
138 /* init one TX queue */
140 tx_conf.offloads = local_port_conf.txmode.offloads;
141 ret = rte_eth_tx_queue_setup(portid, 0,
142 (uint16_t)ring_conf.tx_size, rte_eth_dev_socket_id(portid), &tx_conf);
144 rte_exit(EXIT_FAILURE,
145 "rte_eth_tx_queue_setup: err=%d, port=%u queue=%d\n",
149 ret = rte_eth_dev_start(portid);
151 rte_exit(EXIT_FAILURE,
152 "rte_pmd_port_start: err=%d, port=%u\n",
157 /* get link status */
158 ret = rte_eth_link_get(portid, &link);
160 rte_exit(EXIT_FAILURE,
161 "rte_eth_link_get: err=%d, port=%u: %s\n",
162 ret, portid, rte_strerror(-ret));
164 rte_eth_link_to_str(link_status_text, sizeof(link_status_text), &link);
165 printf("%s\n", link_status_text);
167 ret = rte_eth_promiscuous_enable(portid);
169 rte_exit(EXIT_FAILURE,
170 "rte_eth_promiscuous_enable: err=%s, port=%u\n",
171 rte_strerror(-ret), portid);
173 /* mark port as initialized */
174 app_inited_port_mask |= 1u << portid;
179 static struct rte_sched_pipe_params pipe_profiles[MAX_SCHED_PIPE_PROFILES] = {
184 .tc_rate = {305175, 305175, 305175, 305175, 305175, 305175,
185 305175, 305175, 305175, 305175, 305175, 305175, 305175},
187 #ifdef RTE_SCHED_SUBPORT_TC_OV
191 .wrr_weights = {1, 1, 1, 1},
195 struct rte_sched_subport_params subport_params[MAX_SCHED_SUBPORTS] = {
197 .tb_rate = 1250000000,
200 .tc_rate = {1250000000, 1250000000, 1250000000, 1250000000,
201 1250000000, 1250000000, 1250000000, 1250000000, 1250000000,
202 1250000000, 1250000000, 1250000000, 1250000000},
204 .n_pipes_per_subport_enabled = 4096,
205 .qsize = {64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
206 .pipe_profiles = pipe_profiles,
207 .n_pipe_profiles = sizeof(pipe_profiles) /
208 sizeof(struct rte_sched_pipe_params),
209 .n_max_pipe_profiles = MAX_SCHED_PIPE_PROFILES,
212 /* Traffic Class 0 Colors Green / Yellow / Red */
213 [0][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
214 [0][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
215 [0][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
217 /* Traffic Class 1 - Colors Green / Yellow / Red */
218 [1][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
219 [1][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
220 [1][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
222 /* Traffic Class 2 - Colors Green / Yellow / Red */
223 [2][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
224 [2][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
225 [2][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
227 /* Traffic Class 3 - Colors Green / Yellow / Red */
228 [3][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
229 [3][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
230 [3][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
232 /* Traffic Class 4 - Colors Green / Yellow / Red */
233 [4][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
234 [4][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
235 [4][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
237 /* Traffic Class 5 - Colors Green / Yellow / Red */
238 [5][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
239 [5][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
240 [5][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
242 /* Traffic Class 6 - Colors Green / Yellow / Red */
243 [6][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
244 [6][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
245 [6][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
247 /* Traffic Class 7 - Colors Green / Yellow / Red */
248 [7][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
249 [7][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
250 [7][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
252 /* Traffic Class 8 - Colors Green / Yellow / Red */
253 [8][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
254 [8][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
255 [8][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
257 /* Traffic Class 9 - Colors Green / Yellow / Red */
258 [9][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
259 [9][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
260 [9][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
262 /* Traffic Class 10 - Colors Green / Yellow / Red */
263 [10][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
264 [10][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
265 [10][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
267 /* Traffic Class 11 - Colors Green / Yellow / Red */
268 [11][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
269 [11][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
270 [11][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
272 /* Traffic Class 12 - Colors Green / Yellow / Red */
273 [12][0] = {.min_th = 48, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
274 [12][1] = {.min_th = 40, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
275 [12][2] = {.min_th = 32, .max_th = 64, .maxp_inv = 10, .wq_log2 = 9},
277 #endif /* RTE_SCHED_RED */
281 struct rte_sched_port_params port_params = {
282 .name = "port_scheduler_0",
283 .socket = 0, /* computed */
284 .rate = 0, /* computed */
285 .mtu = 6 + 6 + 4 + 4 + 2 + 1500,
286 .frame_overhead = RTE_SCHED_FRAME_OVERHEAD_DEFAULT,
287 .n_subports_per_port = 1,
288 .n_pipes_per_subport = MAX_SCHED_PIPES,
291 static struct rte_sched_port *
292 app_init_sched_port(uint32_t portid, uint32_t socketid)
294 static char port_name[32]; /* static as referenced from global port_params*/
295 struct rte_eth_link link;
296 struct rte_sched_port *port = NULL;
297 uint32_t pipe, subport;
300 err = rte_eth_link_get(portid, &link);
302 rte_exit(EXIT_FAILURE,
303 "rte_eth_link_get: err=%d, port=%u: %s\n",
304 err, portid, rte_strerror(-err));
306 port_params.socket = socketid;
307 port_params.rate = (uint64_t) link.link_speed * 1000 * 1000 / 8;
308 snprintf(port_name, sizeof(port_name), "port_%d", portid);
309 port_params.name = port_name;
311 port = rte_sched_port_config(&port_params);
313 rte_exit(EXIT_FAILURE, "Unable to config sched port\n");
316 for (subport = 0; subport < port_params.n_subports_per_port; subport ++) {
317 err = rte_sched_subport_config(port, subport, &subport_params[subport]);
319 rte_exit(EXIT_FAILURE, "Unable to config sched subport %u, err=%d\n",
323 uint32_t n_pipes_per_subport =
324 subport_params[subport].n_pipes_per_subport_enabled;
326 for (pipe = 0; pipe < n_pipes_per_subport; pipe++) {
327 if (app_pipe_to_profile[subport][pipe] != -1) {
328 err = rte_sched_pipe_config(port, subport, pipe,
329 app_pipe_to_profile[subport][pipe]);
331 rte_exit(EXIT_FAILURE, "Unable to config sched pipe %u "
332 "for profile %d, err=%d\n", pipe,
333 app_pipe_to_profile[subport][pipe], err);
343 app_load_cfg_profile(const char *profile)
347 struct rte_cfgfile *file = rte_cfgfile_load(profile, 0);
349 rte_exit(EXIT_FAILURE, "Cannot load configuration profile %s\n", profile);
351 cfg_load_port(file, &port_params);
352 cfg_load_subport(file, subport_params);
353 cfg_load_pipe(file, pipe_profiles);
355 rte_cfgfile_close(file);
363 char ring_name[MAX_NAME_LEN];
364 char pool_name[MAX_NAME_LEN];
366 if (rte_eth_dev_count_avail() == 0)
367 rte_exit(EXIT_FAILURE, "No Ethernet port - bye\n");
369 /* load configuration profile */
370 if (app_load_cfg_profile(cfg_profile) != 0)
371 rte_exit(EXIT_FAILURE, "Invalid configuration profile\n");
373 /* Initialize each active flow */
374 for(i = 0; i < nb_pfc; i++) {
375 uint32_t socket = rte_lcore_to_socket_id(qos_conf[i].rx_core);
376 struct rte_ring *ring;
378 snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].rx_core);
379 ring = rte_ring_lookup(ring_name);
381 qos_conf[i].rx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
382 socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
384 qos_conf[i].rx_ring = ring;
386 snprintf(ring_name, MAX_NAME_LEN, "ring-%u-%u", i, qos_conf[i].tx_core);
387 ring = rte_ring_lookup(ring_name);
389 qos_conf[i].tx_ring = rte_ring_create(ring_name, ring_conf.ring_size,
390 socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
392 qos_conf[i].tx_ring = ring;
395 /* create the mbuf pools for each RX Port */
396 snprintf(pool_name, MAX_NAME_LEN, "mbuf_pool%u", i);
397 qos_conf[i].mbuf_pool = rte_pktmbuf_pool_create(pool_name,
398 mp_size, burst_conf.rx_burst * 4, 0,
399 RTE_MBUF_DEFAULT_BUF_SIZE,
400 rte_eth_dev_socket_id(qos_conf[i].rx_port));
401 if (qos_conf[i].mbuf_pool == NULL)
402 rte_exit(EXIT_FAILURE, "Cannot init mbuf pool for socket %u\n", i);
404 app_init_port(qos_conf[i].rx_port, qos_conf[i].mbuf_pool);
405 app_init_port(qos_conf[i].tx_port, qos_conf[i].mbuf_pool);
407 qos_conf[i].sched_port = app_init_sched_port(qos_conf[i].tx_port, socket);
410 RTE_LOG(INFO, APP, "time stamp clock running at %" PRIu64 " Hz\n",
413 RTE_LOG(INFO, APP, "Ring sizes: NIC RX = %u, Mempool = %d SW queue = %u,"
414 "NIC TX = %u\n", ring_conf.rx_size, mp_size, ring_conf.ring_size,
417 RTE_LOG(INFO, APP, "Burst sizes: RX read = %hu, RX write = %hu,\n"
418 " Worker read/QoS enqueue = %hu,\n"
419 " QoS dequeue = %hu, Worker write = %hu\n",
420 burst_conf.rx_burst, burst_conf.ring_burst, burst_conf.ring_burst,
421 burst_conf.qos_dequeue, burst_conf.tx_burst);
423 RTE_LOG(INFO, APP, "NIC thresholds RX (p = %hhu, h = %hhu, w = %hhu),"
424 "TX (p = %hhu, h = %hhu, w = %hhu)\n",
425 rx_thresh.pthresh, rx_thresh.hthresh, rx_thresh.wthresh,
426 tx_thresh.pthresh, tx_thresh.hthresh, tx_thresh.wthresh);