xref: /dpdk/examples/ip_pipeline/tmgr.c (revision a61b319674a99f5f6ad45442a18a65b88df27690)
125961ff3SJasvinder Singh /* SPDX-License-Identifier: BSD-3-Clause
225961ff3SJasvinder Singh  * Copyright(c) 2010-2018 Intel Corporation
325961ff3SJasvinder Singh  */
425961ff3SJasvinder Singh 
525961ff3SJasvinder Singh #include <stdlib.h>
625961ff3SJasvinder Singh 
754a298e5SSavinay Dharmappa #include <rte_common.h>
87959831bSJasvinder Singh #include <rte_string_fns.h>
97959831bSJasvinder Singh 
1025961ff3SJasvinder Singh #include "tmgr.h"
1125961ff3SJasvinder Singh 
1254a298e5SSavinay Dharmappa static struct rte_sched_subport_profile_params
1325961ff3SJasvinder Singh 	subport_profile[TMGR_SUBPORT_PROFILE_MAX];
1425961ff3SJasvinder Singh 
1525961ff3SJasvinder Singh static uint32_t n_subport_profiles;
1625961ff3SJasvinder Singh 
1725961ff3SJasvinder Singh static struct rte_sched_pipe_params
1825961ff3SJasvinder Singh 	pipe_profile[TMGR_PIPE_PROFILE_MAX];
1925961ff3SJasvinder Singh 
205dbbc2abSWojciech Liguzinski static uint32_t n_pipe_profiles;
215dbbc2abSWojciech Liguzinski 
225dbbc2abSWojciech Liguzinski static const struct rte_sched_subport_params subport_params_default = {
235dbbc2abSWojciech Liguzinski 	.n_pipes_per_subport_enabled = 0, /* filled at runtime */
245dbbc2abSWojciech Liguzinski 	.qsize = {64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64},
255dbbc2abSWojciech Liguzinski 	.pipe_profiles = pipe_profile,
265dbbc2abSWojciech Liguzinski 	.n_pipe_profiles = 0, /* filled at run time */
275dbbc2abSWojciech Liguzinski 	.n_max_pipe_profiles = RTE_DIM(pipe_profile),
28*a61b3196SMarcin Danilewicz 	.cman_params = NULL,
2954a298e5SSavinay Dharmappa };
3054a298e5SSavinay Dharmappa 
3125961ff3SJasvinder Singh static struct tmgr_port_list tmgr_port_list;
3225961ff3SJasvinder Singh 
3325961ff3SJasvinder Singh int
tmgr_init(void)3425961ff3SJasvinder Singh tmgr_init(void)
3525961ff3SJasvinder Singh {
3625961ff3SJasvinder Singh 	TAILQ_INIT(&tmgr_port_list);
3725961ff3SJasvinder Singh 
3825961ff3SJasvinder Singh 	return 0;
3925961ff3SJasvinder Singh }
4025961ff3SJasvinder Singh 
4125961ff3SJasvinder Singh struct tmgr_port *
tmgr_port_find(const char * name)4225961ff3SJasvinder Singh tmgr_port_find(const char *name)
4325961ff3SJasvinder Singh {
4425961ff3SJasvinder Singh 	struct tmgr_port *tmgr_port;
4525961ff3SJasvinder Singh 
4625961ff3SJasvinder Singh 	if (name == NULL)
4725961ff3SJasvinder Singh 		return NULL;
4825961ff3SJasvinder Singh 
4925961ff3SJasvinder Singh 	TAILQ_FOREACH(tmgr_port, &tmgr_port_list, node)
5025961ff3SJasvinder Singh 		if (strcmp(tmgr_port->name, name) == 0)
5125961ff3SJasvinder Singh 			return tmgr_port;
5225961ff3SJasvinder Singh 
5325961ff3SJasvinder Singh 	return NULL;
5425961ff3SJasvinder Singh }
5525961ff3SJasvinder Singh 
5625961ff3SJasvinder Singh int
tmgr_subport_profile_add(struct rte_sched_subport_profile_params * params)5754a298e5SSavinay Dharmappa tmgr_subport_profile_add(struct rte_sched_subport_profile_params *params)
5825961ff3SJasvinder Singh {
5925961ff3SJasvinder Singh 	/* Check input params */
6054a298e5SSavinay Dharmappa 	if (params == NULL)
6125961ff3SJasvinder Singh 		return -1;
6225961ff3SJasvinder Singh 
6325961ff3SJasvinder Singh 	/* Save profile */
6425961ff3SJasvinder Singh 	memcpy(&subport_profile[n_subport_profiles],
6554a298e5SSavinay Dharmappa 		params,
6654a298e5SSavinay Dharmappa 		sizeof(*params));
6725961ff3SJasvinder Singh 
6825961ff3SJasvinder Singh 	n_subport_profiles++;
6925961ff3SJasvinder Singh 
7025961ff3SJasvinder Singh 	return 0;
7125961ff3SJasvinder Singh }
7225961ff3SJasvinder Singh 
7325961ff3SJasvinder Singh int
tmgr_pipe_profile_add(struct rte_sched_pipe_params * p)7425961ff3SJasvinder Singh tmgr_pipe_profile_add(struct rte_sched_pipe_params *p)
7525961ff3SJasvinder Singh {
7625961ff3SJasvinder Singh 	/* Check input params */
7725961ff3SJasvinder Singh 	if (p == NULL)
7825961ff3SJasvinder Singh 		return -1;
7925961ff3SJasvinder Singh 
8025961ff3SJasvinder Singh 	/* Save profile */
8125961ff3SJasvinder Singh 	memcpy(&pipe_profile[n_pipe_profiles],
8225961ff3SJasvinder Singh 		p,
8325961ff3SJasvinder Singh 		sizeof(*p));
8425961ff3SJasvinder Singh 
8525961ff3SJasvinder Singh 	n_pipe_profiles++;
8625961ff3SJasvinder Singh 
8725961ff3SJasvinder Singh 	return 0;
8825961ff3SJasvinder Singh }
8925961ff3SJasvinder Singh 
9025961ff3SJasvinder Singh struct tmgr_port *
tmgr_port_create(const char * name,struct tmgr_port_params * params)9125961ff3SJasvinder Singh tmgr_port_create(const char *name, struct tmgr_port_params *params)
9225961ff3SJasvinder Singh {
9354a298e5SSavinay Dharmappa 	struct rte_sched_subport_params subport_params;
9425961ff3SJasvinder Singh 	struct rte_sched_port_params p;
9525961ff3SJasvinder Singh 	struct tmgr_port *tmgr_port;
9625961ff3SJasvinder Singh 	struct rte_sched_port *s;
9725961ff3SJasvinder Singh 	uint32_t i, j;
9825961ff3SJasvinder Singh 
9925961ff3SJasvinder Singh 	/* Check input params */
10025961ff3SJasvinder Singh 	if ((name == NULL) ||
10125961ff3SJasvinder Singh 		tmgr_port_find(name) ||
10225961ff3SJasvinder Singh 		(params == NULL) ||
10325961ff3SJasvinder Singh 		(params->n_subports_per_port == 0) ||
10454a298e5SSavinay Dharmappa 		(params->n_pipes_per_subport == 0) ||
10525961ff3SJasvinder Singh 		(params->cpu_id >= RTE_MAX_NUMA_NODES) ||
10625961ff3SJasvinder Singh 		(n_subport_profiles == 0) ||
10725961ff3SJasvinder Singh 		(n_pipe_profiles == 0))
10825961ff3SJasvinder Singh 		return NULL;
10925961ff3SJasvinder Singh 
11025961ff3SJasvinder Singh 	/* Resource create */
11125961ff3SJasvinder Singh 	p.name = name;
11225961ff3SJasvinder Singh 	p.socket = (int) params->cpu_id;
11325961ff3SJasvinder Singh 	p.rate = params->rate;
11425961ff3SJasvinder Singh 	p.mtu = params->mtu;
11525961ff3SJasvinder Singh 	p.frame_overhead = params->frame_overhead;
11625961ff3SJasvinder Singh 	p.n_subports_per_port = params->n_subports_per_port;
11754a298e5SSavinay Dharmappa 	p.n_subport_profiles = n_subport_profiles;
11854a298e5SSavinay Dharmappa 	p.subport_profiles = subport_profile;
11954a298e5SSavinay Dharmappa 	p.n_max_subport_profiles = TMGR_SUBPORT_PROFILE_MAX;
12054a298e5SSavinay Dharmappa 	p.n_pipes_per_subport = params->n_pipes_per_subport;
12154a298e5SSavinay Dharmappa 
12225961ff3SJasvinder Singh 
12325961ff3SJasvinder Singh 	s = rte_sched_port_config(&p);
12425961ff3SJasvinder Singh 	if (s == NULL)
12525961ff3SJasvinder Singh 		return NULL;
12625961ff3SJasvinder Singh 
12754a298e5SSavinay Dharmappa 	memcpy(&subport_params, &subport_params_default,
12854a298e5SSavinay Dharmappa 		sizeof(subport_params_default));
12954a298e5SSavinay Dharmappa 
13054a298e5SSavinay Dharmappa 	subport_params.n_pipe_profiles = n_pipe_profiles;
13154a298e5SSavinay Dharmappa 	subport_params.n_pipes_per_subport_enabled =
13254a298e5SSavinay Dharmappa 						params->n_pipes_per_subport;
13329169a41SJasvinder Singh 
13425961ff3SJasvinder Singh 	for (i = 0; i < params->n_subports_per_port; i++) {
13525961ff3SJasvinder Singh 		int status;
13625961ff3SJasvinder Singh 
13725961ff3SJasvinder Singh 		status = rte_sched_subport_config(
13825961ff3SJasvinder Singh 			s,
13925961ff3SJasvinder Singh 			i,
14054a298e5SSavinay Dharmappa 			&subport_params,
141ac6fcb84SSavinay Dharmappa 			0);
14225961ff3SJasvinder Singh 
14325961ff3SJasvinder Singh 		if (status) {
14425961ff3SJasvinder Singh 			rte_sched_port_free(s);
14525961ff3SJasvinder Singh 			return NULL;
14625961ff3SJasvinder Singh 		}
14725961ff3SJasvinder Singh 
14854a298e5SSavinay Dharmappa 		for (j = 0; j < params->n_pipes_per_subport; j++) {
14954a298e5SSavinay Dharmappa 
15025961ff3SJasvinder Singh 			status = rte_sched_pipe_config(
15125961ff3SJasvinder Singh 				s,
15225961ff3SJasvinder Singh 				i,
15325961ff3SJasvinder Singh 				j,
15425961ff3SJasvinder Singh 				0);
15525961ff3SJasvinder Singh 
15625961ff3SJasvinder Singh 			if (status) {
15725961ff3SJasvinder Singh 				rte_sched_port_free(s);
15825961ff3SJasvinder Singh 				return NULL;
15925961ff3SJasvinder Singh 			}
16025961ff3SJasvinder Singh 		}
16125961ff3SJasvinder Singh 	}
16225961ff3SJasvinder Singh 
16325961ff3SJasvinder Singh 	/* Node allocation */
16425961ff3SJasvinder Singh 	tmgr_port = calloc(1, sizeof(struct tmgr_port));
16525961ff3SJasvinder Singh 	if (tmgr_port == NULL) {
16625961ff3SJasvinder Singh 		rte_sched_port_free(s);
16725961ff3SJasvinder Singh 		return NULL;
16825961ff3SJasvinder Singh 	}
16925961ff3SJasvinder Singh 
17025961ff3SJasvinder Singh 	/* Node fill in */
1717959831bSJasvinder Singh 	strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
17225961ff3SJasvinder Singh 	tmgr_port->s = s;
17325961ff3SJasvinder Singh 	tmgr_port->n_subports_per_port = params->n_subports_per_port;
17454a298e5SSavinay Dharmappa 	tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport;
17525961ff3SJasvinder Singh 
17625961ff3SJasvinder Singh 	/* Node add to list */
17725961ff3SJasvinder Singh 	TAILQ_INSERT_TAIL(&tmgr_port_list, tmgr_port, node);
17825961ff3SJasvinder Singh 
17925961ff3SJasvinder Singh 	return tmgr_port;
18025961ff3SJasvinder Singh }
18125961ff3SJasvinder Singh 
18225961ff3SJasvinder Singh int
tmgr_subport_config(const char * port_name,uint32_t subport_id,uint32_t subport_profile_id)18325961ff3SJasvinder Singh tmgr_subport_config(const char *port_name,
18425961ff3SJasvinder Singh 	uint32_t subport_id,
18525961ff3SJasvinder Singh 	uint32_t subport_profile_id)
18625961ff3SJasvinder Singh {
18725961ff3SJasvinder Singh 	struct tmgr_port *port;
18825961ff3SJasvinder Singh 	int status;
18925961ff3SJasvinder Singh 
19025961ff3SJasvinder Singh 	/* Check input params */
19125961ff3SJasvinder Singh 	if (port_name == NULL)
19225961ff3SJasvinder Singh 		return -1;
19325961ff3SJasvinder Singh 
19425961ff3SJasvinder Singh 	port = tmgr_port_find(port_name);
19525961ff3SJasvinder Singh 	if ((port == NULL) ||
19625961ff3SJasvinder Singh 		(subport_id >= port->n_subports_per_port) ||
19725961ff3SJasvinder Singh 		(subport_profile_id >= n_subport_profiles))
19825961ff3SJasvinder Singh 		return -1;
19925961ff3SJasvinder Singh 
20025961ff3SJasvinder Singh 	/* Resource config */
20125961ff3SJasvinder Singh 	status = rte_sched_subport_config(
20225961ff3SJasvinder Singh 		port->s,
20325961ff3SJasvinder Singh 		subport_id,
20454a298e5SSavinay Dharmappa 		NULL,
20554a298e5SSavinay Dharmappa 		subport_profile_id);
20625961ff3SJasvinder Singh 
20725961ff3SJasvinder Singh 	return status;
20825961ff3SJasvinder Singh }
20925961ff3SJasvinder Singh 
21025961ff3SJasvinder Singh int
tmgr_pipe_config(const char * port_name,uint32_t subport_id,uint32_t pipe_id_first,uint32_t pipe_id_last,uint32_t pipe_profile_id)21125961ff3SJasvinder Singh tmgr_pipe_config(const char *port_name,
21225961ff3SJasvinder Singh 	uint32_t subport_id,
21325961ff3SJasvinder Singh 	uint32_t pipe_id_first,
21425961ff3SJasvinder Singh 	uint32_t pipe_id_last,
21525961ff3SJasvinder Singh 	uint32_t pipe_profile_id)
21625961ff3SJasvinder Singh {
21725961ff3SJasvinder Singh 	struct tmgr_port *port;
21825961ff3SJasvinder Singh 	uint32_t i;
21925961ff3SJasvinder Singh 
22025961ff3SJasvinder Singh 	/* Check input params */
22125961ff3SJasvinder Singh 	if (port_name == NULL)
22225961ff3SJasvinder Singh 		return -1;
22325961ff3SJasvinder Singh 
22425961ff3SJasvinder Singh 	port = tmgr_port_find(port_name);
22525961ff3SJasvinder Singh 	if ((port == NULL) ||
22625961ff3SJasvinder Singh 		(subport_id >= port->n_subports_per_port) ||
22754a298e5SSavinay Dharmappa 		(pipe_id_first >= port->n_pipes_per_subport) ||
22854a298e5SSavinay Dharmappa 		(pipe_id_last >= port->n_pipes_per_subport) ||
22925961ff3SJasvinder Singh 		(pipe_id_first > pipe_id_last) ||
23025961ff3SJasvinder Singh 		(pipe_profile_id >= n_pipe_profiles))
23125961ff3SJasvinder Singh 		return -1;
23225961ff3SJasvinder Singh 
23325961ff3SJasvinder Singh 	/* Resource config */
23425961ff3SJasvinder Singh 	for (i = pipe_id_first; i <= pipe_id_last; i++) {
23525961ff3SJasvinder Singh 		int status;
23625961ff3SJasvinder Singh 
23725961ff3SJasvinder Singh 		status = rte_sched_pipe_config(
23825961ff3SJasvinder Singh 			port->s,
23925961ff3SJasvinder Singh 			subport_id,
24025961ff3SJasvinder Singh 			i,
24125961ff3SJasvinder Singh 			(int) pipe_profile_id);
24225961ff3SJasvinder Singh 
24325961ff3SJasvinder Singh 		if (status)
24425961ff3SJasvinder Singh 			return status;
24525961ff3SJasvinder Singh 	}
24625961ff3SJasvinder Singh 
24725961ff3SJasvinder Singh 	return 0;
24825961ff3SJasvinder Singh }
249