net/softnic: add mempool object
[dpdk.git] / drivers / net / softnic / rte_eth_softnic_internals.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
6 #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
7
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <sys/queue.h>
11
12 #include <rte_mempool.h>
13 #include <rte_mbuf.h>
14 #include <rte_ring.h>
15 #include <rte_ethdev.h>
16 #include <rte_sched.h>
17 #include <rte_ethdev_driver.h>
18 #include <rte_tm_driver.h>
19
20 #include "rte_eth_softnic.h"
21
22 #define NAME_SIZE                                            64
23
24 /**
25  * PMD Parameters
26  */
27
28 struct pmd_params {
29         const char *name;
30         const char *firmware;
31         uint32_t cpu_id;
32
33         /** Traffic Management (TM) */
34         struct {
35                 uint32_t n_queues; /**< Number of queues */
36                 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
37         } tm;
38 };
39
40 /**
41  * MEMPOOL
42  */
43 struct softnic_mempool_params {
44         uint32_t buffer_size;
45         uint32_t pool_size;
46         uint32_t cache_size;
47 };
48
49 struct softnic_mempool {
50         TAILQ_ENTRY(softnic_mempool) node;
51         char name[NAME_SIZE];
52         struct rte_mempool *m;
53         uint32_t buffer_size;
54 };
55
56 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
57
58 /**
59  * SWQ
60  */
61 struct softnic_swq_params {
62         uint32_t size;
63 };
64
65 struct softnic_swq {
66         TAILQ_ENTRY(softnic_swq) node;
67         char name[NAME_SIZE];
68         struct rte_ring *r;
69 };
70
71 TAILQ_HEAD(softnic_swq_list, softnic_swq);
72
73 /**
74  * LINK
75  */
76 struct softnic_link_params {
77         const char *dev_name;
78         uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
79 };
80
81 struct softnic_link {
82         TAILQ_ENTRY(softnic_link) node;
83         char name[NAME_SIZE];
84         uint16_t port_id;
85         uint32_t n_rxq;
86         uint32_t n_txq;
87 };
88
89 TAILQ_HEAD(softnic_link_list, softnic_link);
90
91 /**
92  * Traffic Management (TM) Internals
93  */
94
95 #ifndef TM_MAX_SUBPORTS
96 #define TM_MAX_SUBPORTS                                 8
97 #endif
98
99 #ifndef TM_MAX_PIPES_PER_SUBPORT
100 #define TM_MAX_PIPES_PER_SUBPORT                        4096
101 #endif
102
103 struct tm_params {
104         struct rte_sched_port_params port_params;
105
106         struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
107
108         struct rte_sched_pipe_params
109                 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
110         uint32_t n_pipe_profiles;
111         uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
112 };
113
114 /* TM Levels */
115 enum tm_node_level {
116         TM_NODE_LEVEL_PORT = 0,
117         TM_NODE_LEVEL_SUBPORT,
118         TM_NODE_LEVEL_PIPE,
119         TM_NODE_LEVEL_TC,
120         TM_NODE_LEVEL_QUEUE,
121         TM_NODE_LEVEL_MAX,
122 };
123
124 /* TM Shaper Profile */
125 struct tm_shaper_profile {
126         TAILQ_ENTRY(tm_shaper_profile) node;
127         uint32_t shaper_profile_id;
128         uint32_t n_users;
129         struct rte_tm_shaper_params params;
130 };
131
132 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
133
134 /* TM Shared Shaper */
135 struct tm_shared_shaper {
136         TAILQ_ENTRY(tm_shared_shaper) node;
137         uint32_t shared_shaper_id;
138         uint32_t n_users;
139         uint32_t shaper_profile_id;
140 };
141
142 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
143
144 /* TM WRED Profile */
145 struct tm_wred_profile {
146         TAILQ_ENTRY(tm_wred_profile) node;
147         uint32_t wred_profile_id;
148         uint32_t n_users;
149         struct rte_tm_wred_params params;
150 };
151
152 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
153
154 /* TM Node */
155 struct tm_node {
156         TAILQ_ENTRY(tm_node) node;
157         uint32_t node_id;
158         uint32_t parent_node_id;
159         uint32_t priority;
160         uint32_t weight;
161         uint32_t level;
162         struct tm_node *parent_node;
163         struct tm_shaper_profile *shaper_profile;
164         struct tm_wred_profile *wred_profile;
165         struct rte_tm_node_params params;
166         struct rte_tm_node_stats stats;
167         uint32_t n_children;
168 };
169
170 TAILQ_HEAD(tm_node_list, tm_node);
171
172 /* TM Hierarchy Specification */
173 struct tm_hierarchy {
174         struct tm_shaper_profile_list shaper_profiles;
175         struct tm_shared_shaper_list shared_shapers;
176         struct tm_wred_profile_list wred_profiles;
177         struct tm_node_list nodes;
178
179         uint32_t n_shaper_profiles;
180         uint32_t n_shared_shapers;
181         uint32_t n_wred_profiles;
182         uint32_t n_nodes;
183
184         uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
185 };
186
187 struct tm_internals {
188         /** Hierarchy specification
189          *
190          *     -Hierarchy is unfrozen at init and when port is stopped.
191          *     -Hierarchy is frozen on successful hierarchy commit.
192          *     -Run-time hierarchy changes are not allowed, therefore it makes
193          *      sense to keep the hierarchy frozen after the port is started.
194          */
195         struct tm_hierarchy h;
196         int hierarchy_frozen;
197
198         /** Blueprints */
199         struct tm_params params;
200         struct rte_sched_port *sched;
201 };
202
203 /**
204  * PMD Internals
205  */
206 struct pmd_internals {
207         /** Params */
208         struct pmd_params params;
209
210         /** Soft device */
211         struct {
212                 struct tm_internals tm; /**< Traffic Management */
213         } soft;
214
215         struct softnic_mempool_list mempool_list;
216         struct softnic_swq_list swq_list;
217         struct softnic_link_list link_list;
218 };
219
220 /**
221  * MEMPOOL
222  */
223 int
224 softnic_mempool_init(struct pmd_internals *p);
225
226 void
227 softnic_mempool_free(struct pmd_internals *p);
228
229 struct softnic_mempool *
230 softnic_mempool_find(struct pmd_internals *p,
231         const char *name);
232
233 struct softnic_mempool *
234 softnic_mempool_create(struct pmd_internals *p,
235         const char *name,
236         struct softnic_mempool_params *params);
237
238 /**
239  * SWQ
240  */
241 int
242 softnic_swq_init(struct pmd_internals *p);
243
244 void
245 softnic_swq_free(struct pmd_internals *p);
246
247 struct softnic_swq *
248 softnic_swq_find(struct pmd_internals *p,
249         const char *name);
250
251 struct softnic_swq *
252 softnic_swq_create(struct pmd_internals *p,
253         const char *name,
254         struct softnic_swq_params *params);
255
256 /**
257  * LINK
258  */
259 int
260 softnic_link_init(struct pmd_internals *p);
261
262 void
263 softnic_link_free(struct pmd_internals *p);
264
265 struct softnic_link *
266 softnic_link_find(struct pmd_internals *p,
267         const char *name);
268
269 struct softnic_link *
270 softnic_link_create(struct pmd_internals *p,
271         const char *name,
272         struct softnic_link_params *params);
273
274 /**
275  * Traffic Management (TM) Operation
276  */
277 extern const struct rte_tm_ops pmd_tm_ops;
278
279 int
280 tm_init(struct pmd_internals *p, struct pmd_params *params, int numa_node);
281
282 void
283 tm_free(struct pmd_internals *p);
284
285 int
286 tm_start(struct pmd_internals *p);
287
288 void
289 tm_stop(struct pmd_internals *p);
290
291 static inline int
292 tm_used(struct rte_eth_dev *dev __rte_unused)
293 {
294         return 0;
295 }
296
297 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */