1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#ifndef _NFP_APP_H
35#define _NFP_APP_H 1
36
37#include <net/devlink.h>
38
39#include <trace/events/devlink.h>
40
41#include "nfp_net_repr.h"
42
43struct bpf_prog;
44struct net_device;
45struct netdev_bpf;
46struct pci_dev;
47struct sk_buff;
48struct sk_buff;
49struct nfp_app;
50struct nfp_cpp;
51struct nfp_pf;
52struct nfp_repr;
53struct nfp_net;
54
55enum nfp_app_id {
56 NFP_APP_CORE_NIC = 0x1,
57 NFP_APP_BPF_NIC = 0x2,
58 NFP_APP_FLOWER_NIC = 0x3,
59};
60
61extern const struct nfp_app_type app_nic;
62extern const struct nfp_app_type app_bpf;
63extern const struct nfp_app_type app_flower;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97struct nfp_app_type {
98 enum nfp_app_id id;
99 const char *name;
100
101 bool ctrl_has_meta;
102
103 int (*init)(struct nfp_app *app);
104 void (*clean)(struct nfp_app *app);
105
106 const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
107
108 int (*vnic_alloc)(struct nfp_app *app, struct nfp_net *nn,
109 unsigned int id);
110 void (*vnic_free)(struct nfp_app *app, struct nfp_net *nn);
111 int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn);
112 void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
113
114 int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
115 void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
116
117 int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
118 int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr);
119
120 int (*start)(struct nfp_app *app);
121 void (*stop)(struct nfp_app *app);
122
123 void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
124
125 int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
126 enum tc_setup_type type, void *type_data);
127 bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn);
128 int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
129 struct bpf_prog *prog);
130 int (*bpf_verifier_prep)(struct nfp_app *app, struct nfp_net *nn,
131 struct netdev_bpf *bpf);
132 int (*bpf_translate)(struct nfp_app *app, struct nfp_net *nn,
133 struct bpf_prog *prog);
134 int (*bpf_destroy)(struct nfp_app *app, struct nfp_net *nn,
135 struct bpf_prog *prog);
136
137 int (*sriov_enable)(struct nfp_app *app, int num_vfs);
138 void (*sriov_disable)(struct nfp_app *app);
139
140 enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
141 struct net_device *(*repr_get)(struct nfp_app *app, u32 id);
142};
143
144
145
146
147
148
149
150
151
152
153
154struct nfp_app {
155 struct pci_dev *pdev;
156 struct nfp_pf *pf;
157 struct nfp_cpp *cpp;
158
159 struct nfp_net *ctrl;
160 struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
161
162 const struct nfp_app_type *type;
163 void *priv;
164};
165
166bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
167
168static inline int nfp_app_init(struct nfp_app *app)
169{
170 if (!app->type->init)
171 return 0;
172 return app->type->init(app);
173}
174
175static inline void nfp_app_clean(struct nfp_app *app)
176{
177 if (app->type->clean)
178 app->type->clean(app);
179}
180
181static inline int nfp_app_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
182 unsigned int id)
183{
184 return app->type->vnic_alloc(app, nn, id);
185}
186
187static inline void nfp_app_vnic_free(struct nfp_app *app, struct nfp_net *nn)
188{
189 if (app->type->vnic_free)
190 app->type->vnic_free(app, nn);
191}
192
193static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn)
194{
195 if (!app->type->vnic_init)
196 return 0;
197 return app->type->vnic_init(app, nn);
198}
199
200static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
201{
202 if (app->type->vnic_clean)
203 app->type->vnic_clean(app, nn);
204}
205
206static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr)
207{
208 if (!app->type->repr_open)
209 return -EINVAL;
210 return app->type->repr_open(app, repr);
211}
212
213static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr)
214{
215 if (!app->type->repr_stop)
216 return -EINVAL;
217 return app->type->repr_stop(app, repr);
218}
219
220static inline int
221nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
222{
223 if (!app->type->repr_init)
224 return 0;
225 return app->type->repr_init(app, netdev);
226}
227
228static inline void
229nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
230{
231 if (app->type->repr_clean)
232 app->type->repr_clean(app, netdev);
233}
234
235static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
236{
237 app->ctrl = ctrl;
238 if (!app->type->start)
239 return 0;
240 return app->type->start(app);
241}
242
243static inline void nfp_app_stop(struct nfp_app *app)
244{
245 if (!app->type->stop)
246 return;
247 app->type->stop(app);
248}
249
250static inline const char *nfp_app_name(struct nfp_app *app)
251{
252 if (!app)
253 return "";
254 return app->type->name;
255}
256
257static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
258{
259 return app && app->type->ctrl_msg_rx;
260}
261
262static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
263{
264 return app->type->ctrl_has_meta;
265}
266
267static inline const char *nfp_app_extra_cap(struct nfp_app *app,
268 struct nfp_net *nn)
269{
270 if (!app || !app->type->extra_cap)
271 return "";
272 return app->type->extra_cap(app, nn);
273}
274
275static inline bool nfp_app_has_tc(struct nfp_app *app)
276{
277 return app && app->type->setup_tc;
278}
279
280static inline bool nfp_app_tc_busy(struct nfp_app *app, struct nfp_net *nn)
281{
282 if (!app || !app->type->tc_busy)
283 return false;
284 return app->type->tc_busy(app, nn);
285}
286
287static inline int nfp_app_setup_tc(struct nfp_app *app,
288 struct net_device *netdev,
289 enum tc_setup_type type, void *type_data)
290{
291 if (!app || !app->type->setup_tc)
292 return -EOPNOTSUPP;
293 return app->type->setup_tc(app, netdev, type, type_data);
294}
295
296static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
297 struct bpf_prog *prog)
298{
299 if (!app || !app->type->xdp_offload)
300 return -EOPNOTSUPP;
301 return app->type->xdp_offload(app, nn, prog);
302}
303
304static inline int
305nfp_app_bpf_verifier_prep(struct nfp_app *app, struct nfp_net *nn,
306 struct netdev_bpf *bpf)
307{
308 if (!app || !app->type->bpf_verifier_prep)
309 return -EOPNOTSUPP;
310 return app->type->bpf_verifier_prep(app, nn, bpf);
311}
312
313static inline int
314nfp_app_bpf_translate(struct nfp_app *app, struct nfp_net *nn,
315 struct bpf_prog *prog)
316{
317 if (!app || !app->type->bpf_translate)
318 return -EOPNOTSUPP;
319 return app->type->bpf_translate(app, nn, prog);
320}
321
322static inline int
323nfp_app_bpf_destroy(struct nfp_app *app, struct nfp_net *nn,
324 struct bpf_prog *prog)
325{
326 if (!app || !app->type->bpf_destroy)
327 return -EOPNOTSUPP;
328 return app->type->bpf_destroy(app, nn, prog);
329}
330
331static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
332{
333 trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
334 skb->data, skb->len);
335
336 return nfp_ctrl_tx(app->ctrl, skb);
337}
338
339static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
340{
341 trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0,
342 skb->data, skb->len);
343
344 app->type->ctrl_msg_rx(app, skb);
345}
346
347static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
348{
349 if (!app->type->eswitch_mode_get)
350 return -EOPNOTSUPP;
351
352 *mode = app->type->eswitch_mode_get(app);
353
354 return 0;
355}
356
357static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
358{
359 if (!app || !app->type->sriov_enable)
360 return -EOPNOTSUPP;
361 return app->type->sriov_enable(app, num_vfs);
362}
363
364static inline void nfp_app_sriov_disable(struct nfp_app *app)
365{
366 if (app && app->type->sriov_disable)
367 app->type->sriov_disable(app);
368}
369
370static inline struct net_device *nfp_app_repr_get(struct nfp_app *app, u32 id)
371{
372 if (unlikely(!app || !app->type->repr_get))
373 return NULL;
374
375 return app->type->repr_get(app, id);
376}
377
378struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
379
380struct nfp_reprs *
381nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
382 struct nfp_reprs *reprs);
383
384const char *nfp_app_mip_name(struct nfp_app *app);
385struct sk_buff *
386nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
387
388struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
389void nfp_app_free(struct nfp_app *app);
390
391
392
393int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
394 unsigned int id);
395
396#endif
397