2 * Copyright (C) 2017 Netronome Systems, Inc.
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 #include <net/devlink.h>
39 #include "nfp_net_repr.h"
53 NFP_APP_CORE_NIC = 0x1,
54 NFP_APP_BPF_NIC = 0x2,
57 extern const struct nfp_app_type app_nic;
58 extern const struct nfp_app_type app_bpf;
61 * struct nfp_app_type - application definition
63 * @name: application name
64 * @ctrl_has_meta: control messages have prepend of type:5/port:CTRL
67 * @init: perform basic app checks
68 * @extra_cap: extra capabilities string
69 * @vnic_init: init vNICs (assign port types, etc.)
70 * @vnic_clean: clean up app's vNIC state
71 * @start: start application logic
72 * @stop: stop application logic
73 * @ctrl_msg_rx: control message handler
74 * @setup_tc: setup TC ndo
75 * @tc_busy: TC HW offload busy (rules loaded)
76 * @xdp_offload: offload an XDP program
77 * @eswitch_mode_get: get SR-IOV eswitch mode
78 * @sriov_enable: app-specific sriov initialisation
79 * @sriov_disable: app-specific sriov clean-up
80 * @repr_get: get representor netdev
88 int (*init)(struct nfp_app *app);
90 const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
92 int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn,
94 void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
96 int (*start)(struct nfp_app *app);
97 void (*stop)(struct nfp_app *app);
99 void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
101 int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
102 u32 handle, __be16 proto, struct tc_to_netdev *tc);
103 bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn);
104 int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
105 struct bpf_prog *prog);
107 int (*sriov_enable)(struct nfp_app *app, int num_vfs);
108 void (*sriov_disable)(struct nfp_app *app);
110 enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
111 struct net_device *(*repr_get)(struct nfp_app *app, u32 id);
115 * struct nfp_app - NFP application container
116 * @pdev: backpointer to PCI device
117 * @pf: backpointer to NFP PF structure
118 * @cpp: pointer to the CPP handle
119 * @ctrl: pointer to ctrl vNIC struct
120 * @reprs: array of pointers to representors
121 * @type: pointer to const application ops and info
124 struct pci_dev *pdev;
128 struct nfp_net *ctrl;
129 struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
131 const struct nfp_app_type *type;
134 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
136 static inline int nfp_app_init(struct nfp_app *app)
138 if (!app->type->init)
140 return app->type->init(app);
143 static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn,
146 return app->type->vnic_init(app, nn, id);
149 static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
151 if (app->type->vnic_clean)
152 app->type->vnic_clean(app, nn);
155 static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
158 if (!app->type->start)
160 return app->type->start(app);
163 static inline void nfp_app_stop(struct nfp_app *app)
165 if (!app->type->stop)
167 app->type->stop(app);
170 static inline const char *nfp_app_name(struct nfp_app *app)
174 return app->type->name;
177 static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
179 return app && app->type->ctrl_msg_rx;
182 static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
184 return app->type->ctrl_has_meta;
187 static inline const char *nfp_app_extra_cap(struct nfp_app *app,
190 if (!app || !app->type->extra_cap)
192 return app->type->extra_cap(app, nn);
195 static inline bool nfp_app_has_tc(struct nfp_app *app)
197 return app && app->type->setup_tc;
200 static inline bool nfp_app_tc_busy(struct nfp_app *app, struct nfp_net *nn)
202 if (!app || !app->type->tc_busy)
204 return app->type->tc_busy(app, nn);
207 static inline int nfp_app_setup_tc(struct nfp_app *app,
208 struct net_device *netdev,
209 u32 handle, __be16 proto,
210 struct tc_to_netdev *tc)
212 if (!app || !app->type->setup_tc)
214 return app->type->setup_tc(app, netdev, handle, proto, tc);
217 static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
218 struct bpf_prog *prog)
220 if (!app || !app->type->xdp_offload)
222 return app->type->xdp_offload(app, nn, prog);
225 static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
227 return nfp_ctrl_tx(app->ctrl, skb);
230 static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
232 app->type->ctrl_msg_rx(app, skb);
235 static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
237 if (!app->type->eswitch_mode_get)
240 *mode = app->type->eswitch_mode_get(app);
245 static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
247 if (!app || !app->type->sriov_enable)
249 return app->type->sriov_enable(app, num_vfs);
252 static inline void nfp_app_sriov_disable(struct nfp_app *app)
254 if (app && app->type->sriov_disable)
255 app->type->sriov_disable(app);
258 static inline struct net_device *nfp_app_repr_get(struct nfp_app *app, u32 id)
260 if (unlikely(!app || !app->type->repr_get))
263 return app->type->repr_get(app, id);
267 nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
268 struct nfp_reprs *reprs);
270 const char *nfp_app_mip_name(struct nfp_app *app);
271 struct sk_buff *nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size);
273 struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
274 void nfp_app_free(struct nfp_app *app);
276 /* Callbacks shared between apps */
278 int nfp_app_nic_vnic_init(struct nfp_app *app, struct nfp_net *nn,