DPDK  23.07.0
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_swx_pipeline.h>
17 #include <rte_swx_ctl.h>
18 
19 #include <rte_ethdev_core.h>
20 #include <ethdev_driver.h>
21 
22 #include "rte_eth_softnic.h"
23 #include "conn.h"
24 
25 #define NAME_SIZE 64
26 #define SOFTNIC_PATH_MAX 4096
27 
32 struct pmd_params {
33  char name[NAME_SIZE];
34  char firmware[SOFTNIC_PATH_MAX];
35  uint16_t conn_port;
36  uint32_t cpu_id;
37  int sc;
38 };
39 
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 
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 
76 struct pipeline {
77  TAILQ_ENTRY(pipeline) node;
78  char name[NAME_SIZE];
79 
80  struct rte_swx_pipeline *p;
81  struct rte_swx_ctl_pipeline *ctl;
82 
83  int enabled;
84  uint32_t thread_id;
85 };
86 
87 TAILQ_HEAD(pipeline_list, pipeline);
88 
92 #ifndef THREAD_PIPELINES_MAX
93 #define THREAD_PIPELINES_MAX 256
94 #endif
95 
96 #ifndef THREAD_MSGQ_SIZE
97 #define THREAD_MSGQ_SIZE 64
98 #endif
99 
100 #ifndef THREAD_TIMER_PERIOD_MS
101 #define THREAD_TIMER_PERIOD_MS 100
102 #endif
103 
104 /* Pipeline instruction quanta: Needs to be big enough to do some meaningful
105  * work, but not too big to avoid starving any other pipelines mapped to the
106  * same thread. For a pipeline that executes 10 instructions per packet, a
107  * quanta of 1000 instructions equates to processing 100 packets.
108  */
109 #ifndef PIPELINE_INSTR_QUANTA
110 #define PIPELINE_INSTR_QUANTA 1000
111 #endif
112 
117  struct rte_ring *msgq_req;
118  struct rte_ring *msgq_rsp;
119 
120  uint32_t service_id;
121 };
122 
127  struct rte_swx_pipeline *p[THREAD_PIPELINES_MAX];
128  uint32_t n_pipelines;
129 
130  struct rte_ring *msgq_req;
131  struct rte_ring *msgq_rsp;
132  uint64_t timer_period; /* Measured in CPU cycles. */
133  uint64_t time_next;
134  uint64_t iter;
136 
142  struct pmd_params params;
143 
144  struct softnic_conn *conn;
145  struct softnic_mempool_list mempool_list;
146  struct softnic_swq_list swq_list;
147  struct pipeline_list pipeline_list;
148  struct softnic_thread thread[RTE_MAX_LCORE];
149  struct softnic_thread_data thread_data[RTE_MAX_LCORE];
150 };
151 
152 static inline struct rte_eth_dev *
153 ETHDEV(struct pmd_internals *softnic)
154 {
155  uint16_t port_id;
156  int status;
157 
158  if (softnic == NULL)
159  return NULL;
160 
161  status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
162  if (status)
163  return NULL;
164 
165  return &rte_eth_devices[port_id];
166 }
167 
171 int
172 softnic_mempool_init(struct pmd_internals *p);
173 
174 void
175 softnic_mempool_free(struct pmd_internals *p);
176 
177 struct softnic_mempool *
178 softnic_mempool_find(struct pmd_internals *p,
179  const char *name);
180 
181 struct softnic_mempool *
182 softnic_mempool_create(struct pmd_internals *p,
183  const char *name,
184  struct softnic_mempool_params *params);
185 
189 int
190 softnic_swq_init(struct pmd_internals *p);
191 
192 void
193 softnic_swq_free(struct pmd_internals *p);
194 
195 void
196 softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
197 
198 struct softnic_swq *
199 softnic_swq_find(struct pmd_internals *p,
200  const char *name);
201 
202 struct softnic_swq *
203 softnic_swq_create(struct pmd_internals *p,
204  const char *name,
205  struct softnic_swq_params *params);
206 
210 int
211 softnic_pipeline_init(struct pmd_internals *p);
212 
213 void
214 softnic_pipeline_free(struct pmd_internals *p);
215 
216 void
217 softnic_pipeline_disable_all(struct pmd_internals *p);
218 
219 uint32_t
220 softnic_pipeline_thread_count(struct pmd_internals *p, uint32_t thread_id);
221 
222 struct pipeline *
223 softnic_pipeline_find(struct pmd_internals *p, const char *name);
224 
225 struct pipeline *
226 softnic_pipeline_create(struct pmd_internals *p,
227  const char *name,
228  const char *lib_file_name,
229  const char *iospec_file_name,
230  int numa_node);
231 
235 int
236 softnic_thread_init(struct pmd_internals *p);
237 
238 void
239 softnic_thread_free(struct pmd_internals *p);
240 
241 int
242 softnic_thread_pipeline_enable(struct pmd_internals *p,
243  uint32_t thread_id,
244  struct pipeline *pipeline);
245 
246 int
247 softnic_thread_pipeline_disable(struct pmd_internals *p,
248  uint32_t thread_id,
249  struct pipeline *pipeline);
250 
251 void
252 softnic_thread_pipeline_disable_all(struct pmd_internals *p);
253 
257 void
258 softnic_cli_process(char *in,
259  char *out,
260  size_t out_size,
261  void *arg);
262 
263 int
264 softnic_cli_script_process(struct pmd_internals *softnic,
265  const char *file_name,
266  size_t msg_in_len_max,
267  size_t msg_out_len_max);
268 
269 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */
struct pmd_params params
int rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
#define __rte_cache_aligned
Definition: rte_common.h:440