1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2018 Intel Corporation 3 */ 4 5 #include <stdlib.h> 6 7 #include "tmgr.h" 8 9 static struct rte_sched_subport_params 10 subport_profile[TMGR_SUBPORT_PROFILE_MAX]; 11 12 static uint32_t n_subport_profiles; 13 14 static struct rte_sched_pipe_params 15 pipe_profile[TMGR_PIPE_PROFILE_MAX]; 16 17 static uint32_t n_pipe_profiles; 18 19 static struct tmgr_port_list tmgr_port_list; 20 21 int 22 tmgr_init(void) 23 { 24 TAILQ_INIT(&tmgr_port_list); 25 26 return 0; 27 } 28 29 struct tmgr_port * 30 tmgr_port_find(const char *name) 31 { 32 struct tmgr_port *tmgr_port; 33 34 if (name == NULL) 35 return NULL; 36 37 TAILQ_FOREACH(tmgr_port, &tmgr_port_list, node) 38 if (strcmp(tmgr_port->name, name) == 0) 39 return tmgr_port; 40 41 return NULL; 42 } 43 44 int 45 tmgr_subport_profile_add(struct rte_sched_subport_params *p) 46 { 47 /* Check input params */ 48 if (p == NULL) 49 return -1; 50 51 /* Save profile */ 52 memcpy(&subport_profile[n_subport_profiles], 53 p, 54 sizeof(*p)); 55 56 n_subport_profiles++; 57 58 return 0; 59 } 60 61 int 62 tmgr_pipe_profile_add(struct rte_sched_pipe_params *p) 63 { 64 /* Check input params */ 65 if (p == NULL) 66 return -1; 67 68 /* Save profile */ 69 memcpy(&pipe_profile[n_pipe_profiles], 70 p, 71 sizeof(*p)); 72 73 n_pipe_profiles++; 74 75 return 0; 76 } 77 78 struct tmgr_port * 79 tmgr_port_create(const char *name, struct tmgr_port_params *params) 80 { 81 struct rte_sched_port_params p; 82 struct tmgr_port *tmgr_port; 83 struct rte_sched_port *s; 84 uint32_t i, j; 85 86 /* Check input params */ 87 if ((name == NULL) || 88 tmgr_port_find(name) || 89 (params == NULL) || 90 (params->n_subports_per_port == 0) || 91 (params->n_pipes_per_subport == 0) || 92 (params->cpu_id >= RTE_MAX_NUMA_NODES) || 93 (n_subport_profiles == 0) || 94 (n_pipe_profiles == 0)) 95 return NULL; 96 97 /* Resource create */ 98 p.name = name; 99 p.socket = (int) params->cpu_id; 100 p.rate = params->rate; 101 p.mtu = params->mtu; 102 p.frame_overhead = params->frame_overhead; 103 p.n_subports_per_port = params->n_subports_per_port; 104 p.n_pipes_per_subport = params->n_pipes_per_subport; 105 106 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) 107 p.qsize[i] = params->qsize[i]; 108 109 p.pipe_profiles = pipe_profile; 110 p.n_pipe_profiles = n_pipe_profiles; 111 112 s = rte_sched_port_config(&p); 113 if (s == NULL) 114 return NULL; 115 116 for (i = 0; i < params->n_subports_per_port; i++) { 117 int status; 118 119 status = rte_sched_subport_config( 120 s, 121 i, 122 &subport_profile[0]); 123 124 if (status) { 125 rte_sched_port_free(s); 126 return NULL; 127 } 128 129 for (j = 0; j < params->n_pipes_per_subport; j++) { 130 status = rte_sched_pipe_config( 131 s, 132 i, 133 j, 134 0); 135 136 if (status) { 137 rte_sched_port_free(s); 138 return NULL; 139 } 140 } 141 } 142 143 /* Node allocation */ 144 tmgr_port = calloc(1, sizeof(struct tmgr_port)); 145 if (tmgr_port == NULL) { 146 rte_sched_port_free(s); 147 return NULL; 148 } 149 150 /* Node fill in */ 151 strncpy(tmgr_port->name, name, sizeof(tmgr_port->name)); 152 tmgr_port->s = s; 153 tmgr_port->n_subports_per_port = params->n_subports_per_port; 154 tmgr_port->n_pipes_per_subport = params->n_pipes_per_subport; 155 156 /* Node add to list */ 157 TAILQ_INSERT_TAIL(&tmgr_port_list, tmgr_port, node); 158 159 return tmgr_port; 160 } 161 162 int 163 tmgr_subport_config(const char *port_name, 164 uint32_t subport_id, 165 uint32_t subport_profile_id) 166 { 167 struct tmgr_port *port; 168 int status; 169 170 /* Check input params */ 171 if (port_name == NULL) 172 return -1; 173 174 port = tmgr_port_find(port_name); 175 if ((port == NULL) || 176 (subport_id >= port->n_subports_per_port) || 177 (subport_profile_id >= n_subport_profiles)) 178 return -1; 179 180 /* Resource config */ 181 status = rte_sched_subport_config( 182 port->s, 183 subport_id, 184 &subport_profile[subport_profile_id]); 185 186 return status; 187 } 188 189 int 190 tmgr_pipe_config(const char *port_name, 191 uint32_t subport_id, 192 uint32_t pipe_id_first, 193 uint32_t pipe_id_last, 194 uint32_t pipe_profile_id) 195 { 196 struct tmgr_port *port; 197 uint32_t i; 198 199 /* Check input params */ 200 if (port_name == NULL) 201 return -1; 202 203 port = tmgr_port_find(port_name); 204 if ((port == NULL) || 205 (subport_id >= port->n_subports_per_port) || 206 (pipe_id_first >= port->n_pipes_per_subport) || 207 (pipe_id_last >= port->n_pipes_per_subport) || 208 (pipe_id_first > pipe_id_last) || 209 (pipe_profile_id >= n_pipe_profiles)) 210 return -1; 211 212 /* Resource config */ 213 for (i = pipe_id_first; i <= pipe_id_last; i++) { 214 int status; 215 216 status = rte_sched_pipe_config( 217 port->s, 218 subport_id, 219 i, 220 (int) pipe_profile_id); 221 222 if (status) 223 return status; 224 } 225 226 return 0; 227 } 228