c7177d46ec5fd831b1999bea3ffd3e5fbc842977
[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  * TAP
205  */
206 struct softnic_tap {
207         TAILQ_ENTRY(softnic_tap) node;
208         char name[NAME_SIZE];
209         int fd;
210 };
211
212 TAILQ_HEAD(softnic_tap_list, softnic_tap);
213
214 /**
215  * PMD Internals
216  */
217 struct pmd_internals {
218         /** Params */
219         struct pmd_params params;
220
221         /** Soft device */
222         struct {
223                 struct tm_internals tm; /**< Traffic Management */
224         } soft;
225
226         struct softnic_mempool_list mempool_list;
227         struct softnic_swq_list swq_list;
228         struct softnic_link_list link_list;
229         struct softnic_tap_list tap_list;
230 };
231
232 /**
233  * MEMPOOL
234  */
235 int
236 softnic_mempool_init(struct pmd_internals *p);
237
238 void
239 softnic_mempool_free(struct pmd_internals *p);
240
241 struct softnic_mempool *
242 softnic_mempool_find(struct pmd_internals *p,
243         const char *name);
244
245 struct softnic_mempool *
246 softnic_mempool_create(struct pmd_internals *p,
247         const char *name,
248         struct softnic_mempool_params *params);
249
250 /**
251  * SWQ
252  */
253 int
254 softnic_swq_init(struct pmd_internals *p);
255
256 void
257 softnic_swq_free(struct pmd_internals *p);
258
259 struct softnic_swq *
260 softnic_swq_find(struct pmd_internals *p,
261         const char *name);
262
263 struct softnic_swq *
264 softnic_swq_create(struct pmd_internals *p,
265         const char *name,
266         struct softnic_swq_params *params);
267
268 /**
269  * LINK
270  */
271 int
272 softnic_link_init(struct pmd_internals *p);
273
274 void
275 softnic_link_free(struct pmd_internals *p);
276
277 struct softnic_link *
278 softnic_link_find(struct pmd_internals *p,
279         const char *name);
280
281 struct softnic_link *
282 softnic_link_create(struct pmd_internals *p,
283         const char *name,
284         struct softnic_link_params *params);
285
286 /**
287  * Traffic Management (TM) Operation
288  */
289 extern const struct rte_tm_ops pmd_tm_ops;
290
291 int
292 tm_init(struct pmd_internals *p, struct pmd_params *params, int numa_node);
293
294 void
295 tm_free(struct pmd_internals *p);
296
297 int
298 tm_start(struct pmd_internals *p);
299
300 void
301 tm_stop(struct pmd_internals *p);
302
303 static inline int
304 tm_used(struct rte_eth_dev *dev __rte_unused)
305 {
306         return 0;
307 }
308
309 /**
310  * TAP
311  */
312 int
313 softnic_tap_init(struct pmd_internals *p);
314
315 void
316 softnic_tap_free(struct pmd_internals *p);
317
318 struct softnic_tap *
319 softnic_tap_find(struct pmd_internals *p,
320         const char *name);
321
322 struct softnic_tap *
323 softnic_tap_create(struct pmd_internals *p,
324         const char *name);
325
326 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */