net/softnic: support traffic management
[dpdk.git] / drivers / net / softnic / rte_eth_softnic_internals.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
35 #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
36
37 #include <stdint.h>
38
39 #include <rte_mbuf.h>
40 #include <rte_sched.h>
41 #include <rte_ethdev.h>
42
43 #include "rte_eth_softnic.h"
44
45 /**
46  * PMD Parameters
47  */
48
49 enum pmd_feature {
50         PMD_FEATURE_TM = 1, /**< Traffic Management (TM) */
51 };
52
53 #ifndef INTRUSIVE
54 #define INTRUSIVE                                       0
55 #endif
56
57 struct pmd_params {
58         /** Parameters for the soft device (to be created) */
59         struct {
60                 const char *name; /**< Name */
61                 uint32_t flags; /**< Flags */
62
63                 /** 0 = Access hard device though API only (potentially slower,
64                  *      but safer);
65                  *  1 = Access hard device private data structures is allowed
66                  *      (potentially faster).
67                  */
68                 int intrusive;
69
70                 /** Traffic Management (TM) */
71                 struct {
72                         uint32_t rate; /**< Rate (bytes/second) */
73                         uint32_t nb_queues; /**< Number of queues */
74                         uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
75                         /**< Queue size per traffic class */
76                         uint32_t enq_bsz; /**< Enqueue burst size */
77                         uint32_t deq_bsz; /**< Dequeue burst size */
78                 } tm;
79         } soft;
80
81         /** Parameters for the hard device (existing) */
82         struct {
83                 char *name; /**< Name */
84                 uint16_t tx_queue_id; /**< TX queue ID */
85         } hard;
86 };
87
88 /**
89  * Default Internals
90  */
91
92 #ifndef DEFAULT_BURST_SIZE
93 #define DEFAULT_BURST_SIZE                              32
94 #endif
95
96 #ifndef FLUSH_COUNT_THRESHOLD
97 #define FLUSH_COUNT_THRESHOLD                   (1 << 17)
98 #endif
99
100 struct default_internals {
101         struct rte_mbuf **pkts;
102         uint32_t pkts_len;
103         uint32_t txq_pos;
104         uint32_t flush_count;
105 };
106
107 /**
108  * Traffic Management (TM) Internals
109  */
110
111 #ifndef TM_MAX_SUBPORTS
112 #define TM_MAX_SUBPORTS                                 8
113 #endif
114
115 #ifndef TM_MAX_PIPES_PER_SUBPORT
116 #define TM_MAX_PIPES_PER_SUBPORT                        4096
117 #endif
118
119 struct tm_params {
120         struct rte_sched_port_params port_params;
121
122         struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
123
124         struct rte_sched_pipe_params
125                 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
126         uint32_t n_pipe_profiles;
127         uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
128 };
129
130 /* TM Levels */
131 enum tm_node_level {
132         TM_NODE_LEVEL_PORT = 0,
133         TM_NODE_LEVEL_SUBPORT,
134         TM_NODE_LEVEL_PIPE,
135         TM_NODE_LEVEL_TC,
136         TM_NODE_LEVEL_QUEUE,
137         TM_NODE_LEVEL_MAX,
138 };
139
140 /* TM Hierarchy Specification */
141 struct tm_hierarchy {
142         uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
143 };
144
145 struct tm_internals {
146         /** Hierarchy specification
147          *
148          *     -Hierarchy is unfrozen at init and when port is stopped.
149          *     -Hierarchy is frozen on successful hierarchy commit.
150          *     -Run-time hierarchy changes are not allowed, therefore it makes
151          *      sense to keep the hierarchy frozen after the port is started.
152          */
153         struct tm_hierarchy h;
154
155         /** Blueprints */
156         struct tm_params params;
157
158         /** Run-time */
159         struct rte_sched_port *sched;
160         struct rte_mbuf **pkts_enq;
161         struct rte_mbuf **pkts_deq;
162         uint32_t pkts_enq_len;
163         uint32_t txq_pos;
164         uint32_t flush_count;
165 };
166
167 /**
168  * PMD Internals
169  */
170 struct pmd_internals {
171         /** Params */
172         struct pmd_params params;
173
174         /** Soft device */
175         struct {
176                 struct default_internals def; /**< Default */
177                 struct tm_internals tm; /**< Traffic Management */
178         } soft;
179
180         /** Hard device */
181         struct {
182                 uint16_t port_id;
183         } hard;
184 };
185
186 struct pmd_rx_queue {
187         /** Hard device */
188         struct {
189                 uint16_t port_id;
190                 uint16_t rx_queue_id;
191         } hard;
192 };
193
194 int
195 tm_params_check(struct pmd_params *params, uint32_t hard_rate);
196
197 int
198 tm_init(struct pmd_internals *p, struct pmd_params *params, int numa_node);
199
200 void
201 tm_free(struct pmd_internals *p);
202
203 int
204 tm_start(struct pmd_internals *p);
205
206 void
207 tm_stop(struct pmd_internals *p);
208
209 static inline int
210 tm_used(struct rte_eth_dev *dev)
211 {
212         struct pmd_internals *p = dev->data->dev_private;
213
214         return (p->params.soft.flags & PMD_FEATURE_TM) &&
215                 p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
216 }
217
218 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */