4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_malloc.h>
40 #include "rte_eth_softnic_internals.h"
41 #include "rte_eth_softnic.h"
43 #define BYTES_IN_MBPS (1000 * 1000 / 8)
46 tm_params_check(struct pmd_params *params, uint32_t hard_rate)
48 uint64_t hard_rate_bytes_per_sec = hard_rate * BYTES_IN_MBPS;
52 if (params->soft.tm.rate) {
53 if (params->soft.tm.rate > hard_rate_bytes_per_sec)
56 params->soft.tm.rate =
57 (hard_rate_bytes_per_sec > UINT32_MAX) ?
58 UINT32_MAX : hard_rate_bytes_per_sec;
62 if (params->soft.tm.nb_queues == 0)
65 if (params->soft.tm.nb_queues < RTE_SCHED_QUEUES_PER_PIPE)
66 params->soft.tm.nb_queues = RTE_SCHED_QUEUES_PER_PIPE;
68 params->soft.tm.nb_queues =
69 rte_align32pow2(params->soft.tm.nb_queues);
72 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++) {
73 if (params->soft.tm.qsize[i] == 0)
76 params->soft.tm.qsize[i] =
77 rte_align32pow2(params->soft.tm.qsize[i]);
80 /* enq_bsz, deq_bsz */
81 if (params->soft.tm.enq_bsz == 0 ||
82 params->soft.tm.deq_bsz == 0 ||
83 params->soft.tm.deq_bsz >= params->soft.tm.enq_bsz)
90 tm_init(struct pmd_internals *p,
91 struct pmd_params *params,
94 uint32_t enq_bsz = params->soft.tm.enq_bsz;
95 uint32_t deq_bsz = params->soft.tm.deq_bsz;
97 p->soft.tm.pkts_enq = rte_zmalloc_socket(params->soft.name,
98 2 * enq_bsz * sizeof(struct rte_mbuf *),
102 if (p->soft.tm.pkts_enq == NULL)
105 p->soft.tm.pkts_deq = rte_zmalloc_socket(params->soft.name,
106 deq_bsz * sizeof(struct rte_mbuf *),
110 if (p->soft.tm.pkts_deq == NULL) {
111 rte_free(p->soft.tm.pkts_enq);
119 tm_free(struct pmd_internals *p)
121 rte_free(p->soft.tm.pkts_enq);
122 rte_free(p->soft.tm.pkts_deq);
126 tm_start(struct pmd_internals *p)
128 struct tm_params *t = &p->soft.tm.params;
129 uint32_t n_subports, subport_id;
133 p->soft.tm.sched = rte_sched_port_config(&t->port_params);
134 if (p->soft.tm.sched == NULL)
138 n_subports = t->port_params.n_subports_per_port;
139 for (subport_id = 0; subport_id < n_subports; subport_id++) {
140 uint32_t n_pipes_per_subport =
141 t->port_params.n_pipes_per_subport;
144 status = rte_sched_subport_config(p->soft.tm.sched,
146 &t->subport_params[subport_id]);
148 rte_sched_port_free(p->soft.tm.sched);
153 n_pipes_per_subport = t->port_params.n_pipes_per_subport;
154 for (pipe_id = 0; pipe_id < n_pipes_per_subport; pipe_id++) {
155 int pos = subport_id * TM_MAX_PIPES_PER_SUBPORT +
157 int profile_id = t->pipe_to_profile[pos];
162 status = rte_sched_pipe_config(p->soft.tm.sched,
167 rte_sched_port_free(p->soft.tm.sched);
177 tm_stop(struct pmd_internals *p)
179 if (p->soft.tm.sched)
180 rte_sched_port_free(p->soft.tm.sched);