bbf299eb40aa002256a0cdea9c7c54c108241193
[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_port_in_action.h>
18 #include <rte_ethdev_driver.h>
19 #include <rte_tm_driver.h>
20
21 #include "rte_eth_softnic.h"
22
23 #define NAME_SIZE                                            64
24
25 /**
26  * PMD Parameters
27  */
28
29 struct pmd_params {
30         const char *name;
31         const char *firmware;
32         uint32_t cpu_id;
33
34         /** Traffic Management (TM) */
35         struct {
36                 uint32_t n_queues; /**< Number of queues */
37                 uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
38         } tm;
39 };
40
41 /**
42  * MEMPOOL
43  */
44 struct softnic_mempool_params {
45         uint32_t buffer_size;
46         uint32_t pool_size;
47         uint32_t cache_size;
48 };
49
50 struct softnic_mempool {
51         TAILQ_ENTRY(softnic_mempool) node;
52         char name[NAME_SIZE];
53         struct rte_mempool *m;
54         uint32_t buffer_size;
55 };
56
57 TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
58
59 /**
60  * SWQ
61  */
62 struct softnic_swq_params {
63         uint32_t size;
64 };
65
66 struct softnic_swq {
67         TAILQ_ENTRY(softnic_swq) node;
68         char name[NAME_SIZE];
69         struct rte_ring *r;
70 };
71
72 TAILQ_HEAD(softnic_swq_list, softnic_swq);
73
74 /**
75  * LINK
76  */
77 struct softnic_link_params {
78         const char *dev_name;
79         uint16_t port_id; /**< Valid only when *dev_name* is NULL. */
80 };
81
82 struct softnic_link {
83         TAILQ_ENTRY(softnic_link) node;
84         char name[NAME_SIZE];
85         uint16_t port_id;
86         uint32_t n_rxq;
87         uint32_t n_txq;
88 };
89
90 TAILQ_HEAD(softnic_link_list, softnic_link);
91
92 /**
93  * TMGR
94  */
95
96 #ifndef TM_MAX_SUBPORTS
97 #define TM_MAX_SUBPORTS                                 8
98 #endif
99
100 #ifndef TM_MAX_PIPES_PER_SUBPORT
101 #define TM_MAX_PIPES_PER_SUBPORT                        4096
102 #endif
103
104 struct tm_params {
105         struct rte_sched_port_params port_params;
106
107         struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
108
109         struct rte_sched_pipe_params
110                 pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
111         uint32_t n_pipe_profiles;
112         uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
113 };
114
115 /* TM Levels */
116 enum tm_node_level {
117         TM_NODE_LEVEL_PORT = 0,
118         TM_NODE_LEVEL_SUBPORT,
119         TM_NODE_LEVEL_PIPE,
120         TM_NODE_LEVEL_TC,
121         TM_NODE_LEVEL_QUEUE,
122         TM_NODE_LEVEL_MAX,
123 };
124
125 /* TM Shaper Profile */
126 struct tm_shaper_profile {
127         TAILQ_ENTRY(tm_shaper_profile) node;
128         uint32_t shaper_profile_id;
129         uint32_t n_users;
130         struct rte_tm_shaper_params params;
131 };
132
133 TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
134
135 /* TM Shared Shaper */
136 struct tm_shared_shaper {
137         TAILQ_ENTRY(tm_shared_shaper) node;
138         uint32_t shared_shaper_id;
139         uint32_t n_users;
140         uint32_t shaper_profile_id;
141 };
142
143 TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
144
145 /* TM WRED Profile */
146 struct tm_wred_profile {
147         TAILQ_ENTRY(tm_wred_profile) node;
148         uint32_t wred_profile_id;
149         uint32_t n_users;
150         struct rte_tm_wred_params params;
151 };
152
153 TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
154
155 /* TM Node */
156 struct tm_node {
157         TAILQ_ENTRY(tm_node) node;
158         uint32_t node_id;
159         uint32_t parent_node_id;
160         uint32_t priority;
161         uint32_t weight;
162         uint32_t level;
163         struct tm_node *parent_node;
164         struct tm_shaper_profile *shaper_profile;
165         struct tm_wred_profile *wred_profile;
166         struct rte_tm_node_params params;
167         struct rte_tm_node_stats stats;
168         uint32_t n_children;
169 };
170
171 TAILQ_HEAD(tm_node_list, tm_node);
172
173 /* TM Hierarchy Specification */
174 struct tm_hierarchy {
175         struct tm_shaper_profile_list shaper_profiles;
176         struct tm_shared_shaper_list shared_shapers;
177         struct tm_wred_profile_list wred_profiles;
178         struct tm_node_list nodes;
179
180         uint32_t n_shaper_profiles;
181         uint32_t n_shared_shapers;
182         uint32_t n_wred_profiles;
183         uint32_t n_nodes;
184
185         uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
186 };
187
188 struct tm_internals {
189         /** Hierarchy specification
190          *
191          *     -Hierarchy is unfrozen at init and when port is stopped.
192          *     -Hierarchy is frozen on successful hierarchy commit.
193          *     -Run-time hierarchy changes are not allowed, therefore it makes
194          *      sense to keep the hierarchy frozen after the port is started.
195          */
196         struct tm_hierarchy h;
197         int hierarchy_frozen;
198
199         /** Blueprints */
200         struct tm_params params;
201         struct rte_sched_port *sched;
202 };
203
204 struct softnic_tmgr_port {
205         TAILQ_ENTRY(softnic_tmgr_port) node;
206         char name[NAME_SIZE];
207         struct rte_sched_port *s;
208 };
209
210 TAILQ_HEAD(softnic_tmgr_port_list, softnic_tmgr_port);
211
212 /**
213  * TAP
214  */
215 struct softnic_tap {
216         TAILQ_ENTRY(softnic_tap) node;
217         char name[NAME_SIZE];
218         int fd;
219 };
220
221 TAILQ_HEAD(softnic_tap_list, softnic_tap);
222
223 /**
224  * Input port action
225  */
226 struct softnic_port_in_action_profile_params {
227         uint64_t action_mask;
228         struct rte_port_in_action_fltr_config fltr;
229         struct rte_port_in_action_lb_config lb;
230 };
231
232 struct softnic_port_in_action_profile {
233         TAILQ_ENTRY(softnic_port_in_action_profile) node;
234         char name[NAME_SIZE];
235         struct softnic_port_in_action_profile_params params;
236         struct rte_port_in_action_profile *ap;
237 };
238
239 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
240
241 /**
242  * PMD Internals
243  */
244 struct pmd_internals {
245         /** Params */
246         struct pmd_params params;
247
248         struct {
249                 struct tm_internals tm; /**< Traffic Management */
250         } soft;
251
252         struct softnic_mempool_list mempool_list;
253         struct softnic_swq_list swq_list;
254         struct softnic_link_list link_list;
255         struct softnic_tmgr_port_list tmgr_port_list;
256         struct softnic_tap_list tap_list;
257         struct softnic_port_in_action_profile_list port_in_action_profile_list;
258 };
259
260 /**
261  * MEMPOOL
262  */
263 int
264 softnic_mempool_init(struct pmd_internals *p);
265
266 void
267 softnic_mempool_free(struct pmd_internals *p);
268
269 struct softnic_mempool *
270 softnic_mempool_find(struct pmd_internals *p,
271         const char *name);
272
273 struct softnic_mempool *
274 softnic_mempool_create(struct pmd_internals *p,
275         const char *name,
276         struct softnic_mempool_params *params);
277
278 /**
279  * SWQ
280  */
281 int
282 softnic_swq_init(struct pmd_internals *p);
283
284 void
285 softnic_swq_free(struct pmd_internals *p);
286
287 struct softnic_swq *
288 softnic_swq_find(struct pmd_internals *p,
289         const char *name);
290
291 struct softnic_swq *
292 softnic_swq_create(struct pmd_internals *p,
293         const char *name,
294         struct softnic_swq_params *params);
295
296 /**
297  * LINK
298  */
299 int
300 softnic_link_init(struct pmd_internals *p);
301
302 void
303 softnic_link_free(struct pmd_internals *p);
304
305 struct softnic_link *
306 softnic_link_find(struct pmd_internals *p,
307         const char *name);
308
309 struct softnic_link *
310 softnic_link_create(struct pmd_internals *p,
311         const char *name,
312         struct softnic_link_params *params);
313
314 /**
315  * TMGR
316  */
317 int
318 softnic_tmgr_init(struct pmd_internals *p);
319
320 void
321 softnic_tmgr_free(struct pmd_internals *p);
322
323 struct softnic_tmgr_port *
324 softnic_tmgr_port_find(struct pmd_internals *p,
325         const char *name);
326
327 struct softnic_tmgr_port *
328 softnic_tmgr_port_create(struct pmd_internals *p,
329         const char *name,
330         struct rte_sched_port *sched);
331
332 int
333 tm_init(struct pmd_internals *p);
334
335 void
336 tm_free(struct pmd_internals *p);
337
338 int
339 tm_start(struct pmd_internals *p);
340
341 void
342 tm_stop(struct pmd_internals *p);
343
344 static inline int
345 tm_used(struct rte_eth_dev *dev)
346 {
347         struct pmd_internals *p = dev->data->dev_private;
348
349         return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
350 }
351
352 extern const struct rte_tm_ops pmd_tm_ops;
353
354 /**
355  * TAP
356  */
357 int
358 softnic_tap_init(struct pmd_internals *p);
359
360 void
361 softnic_tap_free(struct pmd_internals *p);
362
363 struct softnic_tap *
364 softnic_tap_find(struct pmd_internals *p,
365         const char *name);
366
367 struct softnic_tap *
368 softnic_tap_create(struct pmd_internals *p,
369         const char *name);
370
371 /**
372  * Input port action
373  */
374 int
375 softnic_port_in_action_profile_init(struct pmd_internals *p);
376
377 void
378 softnic_port_in_action_profile_free(struct pmd_internals *p);
379
380 struct softnic_port_in_action_profile *
381 softnic_port_in_action_profile_find(struct pmd_internals *p,
382         const char *name);
383
384 struct softnic_port_in_action_profile *
385 softnic_port_in_action_profile_create(struct pmd_internals *p,
386         const char *name,
387         struct softnic_port_in_action_profile_params *params);
388
389 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */