xref: /dpdk/drivers/net/softnic/rte_eth_softnic_internals.h (revision 27595cd83053b2d39634a159d6709b3ce3cdf3b0)
15566a3e3SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
25566a3e3SBruce Richardson  * Copyright(c) 2017 Intel Corporation
3cc6d4215SJasvinder Singh  */
4cc6d4215SJasvinder Singh 
5cc6d4215SJasvinder Singh #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
6cc6d4215SJasvinder Singh #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
7cc6d4215SJasvinder Singh 
87e68bc20SJasvinder Singh #include <stddef.h>
9cc6d4215SJasvinder Singh #include <stdint.h>
10161b5515SJasvinder Singh #include <sys/queue.h>
11cc6d4215SJasvinder Singh 
120efefe11SJasvinder Singh #include <rte_mempool.h>
13cc6d4215SJasvinder Singh #include <rte_mbuf.h>
14161b5515SJasvinder Singh #include <rte_ring.h>
157e68bc20SJasvinder Singh #include <rte_ethdev.h>
16fa0a52a7SCristian Dumitrescu #include <rte_swx_pipeline.h>
17fa0a52a7SCristian Dumitrescu #include <rte_swx_ctl.h>
18dc3bce36SJasvinder Singh 
19e12b1770SReshma Pattan #include <rte_ethdev_core.h>
20df96fd0dSBruce Richardson #include <ethdev_driver.h>
21cc6d4215SJasvinder Singh 
22cc6d4215SJasvinder Singh #include "rte_eth_softnic.h"
237709a63bSJasvinder Singh #include "conn.h"
24cc6d4215SJasvinder Singh 
25161b5515SJasvinder Singh #define NAME_SIZE                                            64
26d8f852f5SDapeng Yu #define SOFTNIC_PATH_MAX                                     4096
27161b5515SJasvinder Singh 
288316b981SJasvinder Singh /**
298316b981SJasvinder Singh  * PMD Parameters
308316b981SJasvinder Singh  */
318316b981SJasvinder Singh 
32cc6d4215SJasvinder Singh struct pmd_params {
33d8f852f5SDapeng Yu 	char name[NAME_SIZE];
34d8f852f5SDapeng Yu 	char firmware[SOFTNIC_PATH_MAX];
357709a63bSJasvinder Singh 	uint16_t conn_port;
367e68bc20SJasvinder Singh 	uint32_t cpu_id;
37a958a5c0SCristian Dumitrescu 	int sc; /**< Service cores. */
38cc6d4215SJasvinder Singh };
39cc6d4215SJasvinder Singh 
40cc6d4215SJasvinder Singh /**
410efefe11SJasvinder Singh  * MEMPOOL
420efefe11SJasvinder Singh  */
430efefe11SJasvinder Singh struct softnic_mempool_params {
440efefe11SJasvinder Singh 	uint32_t buffer_size;
450efefe11SJasvinder Singh 	uint32_t pool_size;
460efefe11SJasvinder Singh 	uint32_t cache_size;
470efefe11SJasvinder Singh };
480efefe11SJasvinder Singh 
490efefe11SJasvinder Singh struct softnic_mempool {
500efefe11SJasvinder Singh 	TAILQ_ENTRY(softnic_mempool) node;
510efefe11SJasvinder Singh 	char name[NAME_SIZE];
520efefe11SJasvinder Singh 	struct rte_mempool *m;
530efefe11SJasvinder Singh 	uint32_t buffer_size;
540efefe11SJasvinder Singh };
550efefe11SJasvinder Singh 
560efefe11SJasvinder Singh TAILQ_HEAD(softnic_mempool_list, softnic_mempool);
570efefe11SJasvinder Singh 
580efefe11SJasvinder Singh /**
59161b5515SJasvinder Singh  * SWQ
60161b5515SJasvinder Singh  */
61161b5515SJasvinder Singh struct softnic_swq_params {
62161b5515SJasvinder Singh 	uint32_t size;
63161b5515SJasvinder Singh };
64161b5515SJasvinder Singh 
65161b5515SJasvinder Singh struct softnic_swq {
66161b5515SJasvinder Singh 	TAILQ_ENTRY(softnic_swq) node;
67161b5515SJasvinder Singh 	char name[NAME_SIZE];
68161b5515SJasvinder Singh 	struct rte_ring *r;
69161b5515SJasvinder Singh };
70161b5515SJasvinder Singh 
71161b5515SJasvinder Singh TAILQ_HEAD(softnic_swq_list, softnic_swq);
72161b5515SJasvinder Singh 
73161b5515SJasvinder Singh /**
74dc3bce36SJasvinder Singh  * Pipeline
75dc3bce36SJasvinder Singh  */
76dc3bce36SJasvinder Singh struct pipeline {
77dc3bce36SJasvinder Singh 	TAILQ_ENTRY(pipeline) node;
78dc3bce36SJasvinder Singh 	char name[NAME_SIZE];
79dc3bce36SJasvinder Singh 
80fa0a52a7SCristian Dumitrescu 	struct rte_swx_pipeline *p;
81fa0a52a7SCristian Dumitrescu 	struct rte_swx_ctl_pipeline *ctl;
82dc3bce36SJasvinder Singh 
83dc3bce36SJasvinder Singh 	int enabled;
84dc3bce36SJasvinder Singh 	uint32_t thread_id;
85dc3bce36SJasvinder Singh };
86dc3bce36SJasvinder Singh 
87dc3bce36SJasvinder Singh TAILQ_HEAD(pipeline_list, pipeline);
88dc3bce36SJasvinder Singh 
89bd2fbb62SJasvinder Singh /**
90bd2fbb62SJasvinder Singh  * Thread
91bd2fbb62SJasvinder Singh  */
92bd2fbb62SJasvinder Singh #ifndef THREAD_PIPELINES_MAX
93bd2fbb62SJasvinder Singh #define THREAD_PIPELINES_MAX                               256
94bd2fbb62SJasvinder Singh #endif
95bd2fbb62SJasvinder Singh 
96bd2fbb62SJasvinder Singh #ifndef THREAD_MSGQ_SIZE
97bd2fbb62SJasvinder Singh #define THREAD_MSGQ_SIZE                                   64
98bd2fbb62SJasvinder Singh #endif
99bd2fbb62SJasvinder Singh 
100bd2fbb62SJasvinder Singh #ifndef THREAD_TIMER_PERIOD_MS
101bd2fbb62SJasvinder Singh #define THREAD_TIMER_PERIOD_MS                             100
102bd2fbb62SJasvinder Singh #endif
103bd2fbb62SJasvinder Singh 
104fa0a52a7SCristian Dumitrescu /* Pipeline instruction quanta: Needs to be big enough to do some meaningful
105fa0a52a7SCristian Dumitrescu  * work, but not too big to avoid starving any other pipelines mapped to the
106fa0a52a7SCristian Dumitrescu  * same thread. For a pipeline that executes 10 instructions per packet, a
107fa0a52a7SCristian Dumitrescu  * quanta of 1000 instructions equates to processing 100 packets.
108fa0a52a7SCristian Dumitrescu  */
109fa0a52a7SCristian Dumitrescu #ifndef PIPELINE_INSTR_QUANTA
110fa0a52a7SCristian Dumitrescu #define PIPELINE_INSTR_QUANTA                              1000
111fa0a52a7SCristian Dumitrescu #endif
112fa0a52a7SCristian Dumitrescu 
113bd2fbb62SJasvinder Singh /**
114cb056611SStephen Hemminger  * Main thread: data plane thread context
115bd2fbb62SJasvinder Singh  */
116bd2fbb62SJasvinder Singh struct softnic_thread {
117bd2fbb62SJasvinder Singh 	struct rte_ring *msgq_req;
118bd2fbb62SJasvinder Singh 	struct rte_ring *msgq_rsp;
119bd2fbb62SJasvinder Singh 
120a958a5c0SCristian Dumitrescu 	uint32_t service_id;
121bd2fbb62SJasvinder Singh };
122bd2fbb62SJasvinder Singh 
123bd2fbb62SJasvinder Singh /**
124bd2fbb62SJasvinder Singh  * Data plane threads: context
125bd2fbb62SJasvinder Singh  */
126*27595cd8STyler Retzlaff struct __rte_cache_aligned softnic_thread_data {
127fa0a52a7SCristian Dumitrescu 	struct rte_swx_pipeline *p[THREAD_PIPELINES_MAX];
128bd2fbb62SJasvinder Singh 	uint32_t n_pipelines;
129bd2fbb62SJasvinder Singh 
130bd2fbb62SJasvinder Singh 	struct rte_ring *msgq_req;
131bd2fbb62SJasvinder Singh 	struct rte_ring *msgq_rsp;
132bd2fbb62SJasvinder Singh 	uint64_t timer_period; /* Measured in CPU cycles. */
133bd2fbb62SJasvinder Singh 	uint64_t time_next;
134bd2fbb62SJasvinder Singh 	uint64_t iter;
135*27595cd8STyler Retzlaff };
136bd2fbb62SJasvinder Singh 
137dc3bce36SJasvinder Singh /**
138cc6d4215SJasvinder Singh  * PMD Internals
139cc6d4215SJasvinder Singh  */
140cc6d4215SJasvinder Singh struct pmd_internals {
141cc6d4215SJasvinder Singh 	/** Params */
142cc6d4215SJasvinder Singh 	struct pmd_params params;
143cc6d4215SJasvinder Singh 
1447709a63bSJasvinder Singh 	struct softnic_conn *conn;
1450efefe11SJasvinder Singh 	struct softnic_mempool_list mempool_list;
146161b5515SJasvinder Singh 	struct softnic_swq_list swq_list;
147dc3bce36SJasvinder Singh 	struct pipeline_list pipeline_list;
148bd2fbb62SJasvinder Singh 	struct softnic_thread thread[RTE_MAX_LCORE];
149bd2fbb62SJasvinder Singh 	struct softnic_thread_data thread_data[RTE_MAX_LCORE];
150cc6d4215SJasvinder Singh };
151cc6d4215SJasvinder Singh 
152e12b1770SReshma Pattan static inline struct rte_eth_dev *
ETHDEV(struct pmd_internals * softnic)153e12b1770SReshma Pattan ETHDEV(struct pmd_internals *softnic)
154e12b1770SReshma Pattan {
155e12b1770SReshma Pattan 	uint16_t port_id;
156e12b1770SReshma Pattan 	int status;
157e12b1770SReshma Pattan 
158e12b1770SReshma Pattan 	if (softnic == NULL)
159e12b1770SReshma Pattan 		return NULL;
160e12b1770SReshma Pattan 
161e12b1770SReshma Pattan 	status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
162e12b1770SReshma Pattan 	if (status)
163e12b1770SReshma Pattan 		return NULL;
164e12b1770SReshma Pattan 
165e12b1770SReshma Pattan 	return &rte_eth_devices[port_id];
166e12b1770SReshma Pattan }
167e12b1770SReshma Pattan 
168299a89deSJasvinder Singh /**
1690efefe11SJasvinder Singh  * MEMPOOL
1700efefe11SJasvinder Singh  */
1710efefe11SJasvinder Singh int
1720efefe11SJasvinder Singh softnic_mempool_init(struct pmd_internals *p);
1730efefe11SJasvinder Singh 
1740efefe11SJasvinder Singh void
1750efefe11SJasvinder Singh softnic_mempool_free(struct pmd_internals *p);
1760efefe11SJasvinder Singh 
1770efefe11SJasvinder Singh struct softnic_mempool *
1780efefe11SJasvinder Singh softnic_mempool_find(struct pmd_internals *p,
1790efefe11SJasvinder Singh 	const char *name);
1800efefe11SJasvinder Singh 
1810efefe11SJasvinder Singh struct softnic_mempool *
1820efefe11SJasvinder Singh softnic_mempool_create(struct pmd_internals *p,
1830efefe11SJasvinder Singh 	const char *name,
1840efefe11SJasvinder Singh 	struct softnic_mempool_params *params);
1850efefe11SJasvinder Singh 
1860efefe11SJasvinder Singh /**
187161b5515SJasvinder Singh  * SWQ
188161b5515SJasvinder Singh  */
189161b5515SJasvinder Singh int
190161b5515SJasvinder Singh softnic_swq_init(struct pmd_internals *p);
191161b5515SJasvinder Singh 
192161b5515SJasvinder Singh void
193161b5515SJasvinder Singh softnic_swq_free(struct pmd_internals *p);
194161b5515SJasvinder Singh 
195bef50bcbSJasvinder Singh void
196bef50bcbSJasvinder Singh softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
197bef50bcbSJasvinder Singh 
198161b5515SJasvinder Singh struct softnic_swq *
199161b5515SJasvinder Singh softnic_swq_find(struct pmd_internals *p,
200161b5515SJasvinder Singh 	const char *name);
201161b5515SJasvinder Singh 
202161b5515SJasvinder Singh struct softnic_swq *
203161b5515SJasvinder Singh softnic_swq_create(struct pmd_internals *p,
204161b5515SJasvinder Singh 	const char *name,
205161b5515SJasvinder Singh 	struct softnic_swq_params *params);
206161b5515SJasvinder Singh 
207161b5515SJasvinder Singh /**
208dc3bce36SJasvinder Singh  * Pipeline
209dc3bce36SJasvinder Singh  */
210dc3bce36SJasvinder Singh int
211dc3bce36SJasvinder Singh softnic_pipeline_init(struct pmd_internals *p);
212dc3bce36SJasvinder Singh 
213dc3bce36SJasvinder Singh void
214dc3bce36SJasvinder Singh softnic_pipeline_free(struct pmd_internals *p);
215dc3bce36SJasvinder Singh 
216bef50bcbSJasvinder Singh void
217bef50bcbSJasvinder Singh softnic_pipeline_disable_all(struct pmd_internals *p);
218bef50bcbSJasvinder Singh 
219a958a5c0SCristian Dumitrescu uint32_t
220a958a5c0SCristian Dumitrescu softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
221a958a5c0SCristian Dumitrescu 
222dc3bce36SJasvinder Singh struct pipeline *
223dc3bce36SJasvinder Singh softnic_pipeline_find(struct pmd_internals *p, const char *name);
224dc3bce36SJasvinder Singh 
225dc3bce36SJasvinder Singh struct pipeline *
226dc3bce36SJasvinder Singh softnic_pipeline_create(struct pmd_internals *p,
227dc3bce36SJasvinder Singh 	const char *name,
228fa0a52a7SCristian Dumitrescu 	const char *lib_file_name,
229fa0a52a7SCristian Dumitrescu 	const char *iospec_file_name,
230fa0a52a7SCristian Dumitrescu 	int numa_node);
2312505030aSJasvinder Singh 
232bd2fbb62SJasvinder Singh /**
233bd2fbb62SJasvinder Singh  * Thread
234bd2fbb62SJasvinder Singh  */
235bd2fbb62SJasvinder Singh int
236bd2fbb62SJasvinder Singh softnic_thread_init(struct pmd_internals *p);
237bd2fbb62SJasvinder Singh 
238bd2fbb62SJasvinder Singh void
239bd2fbb62SJasvinder Singh softnic_thread_free(struct pmd_internals *p);
240bd2fbb62SJasvinder Singh 
24170709c78SJasvinder Singh int
24270709c78SJasvinder Singh softnic_thread_pipeline_enable(struct pmd_internals *p,
24370709c78SJasvinder Singh 	uint32_t thread_id,
244fa0a52a7SCristian Dumitrescu 	struct pipeline *pipeline);
24570709c78SJasvinder Singh 
24670709c78SJasvinder Singh int
24770709c78SJasvinder Singh softnic_thread_pipeline_disable(struct pmd_internals *p,
24870709c78SJasvinder Singh 	uint32_t thread_id,
249fa0a52a7SCristian Dumitrescu 	struct pipeline *pipeline);
250fa0a52a7SCristian Dumitrescu 
251fa0a52a7SCristian Dumitrescu void
252fa0a52a7SCristian Dumitrescu softnic_thread_pipeline_disable_all(struct pmd_internals *p);
25370709c78SJasvinder Singh 
25431ce8d88SJasvinder Singh /**
25531ce8d88SJasvinder Singh  * CLI
25631ce8d88SJasvinder Singh  */
25731ce8d88SJasvinder Singh void
25831ce8d88SJasvinder Singh softnic_cli_process(char *in,
25931ce8d88SJasvinder Singh 	char *out,
26031ce8d88SJasvinder Singh 	size_t out_size,
26131ce8d88SJasvinder Singh 	void *arg);
26231ce8d88SJasvinder Singh 
26331ce8d88SJasvinder Singh int
26431ce8d88SJasvinder Singh softnic_cli_script_process(struct pmd_internals *softnic,
26531ce8d88SJasvinder Singh 	const char *file_name,
26631ce8d88SJasvinder Singh 	size_t msg_in_len_max,
26731ce8d88SJasvinder Singh 	size_t msg_out_len_max);
26831ce8d88SJasvinder Singh 
269cc6d4215SJasvinder Singh #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */
270