Linux Audio

Check our new training course

Loading...
v4.17
  1/*
  2 * Copyright (C) 2017 Netronome Systems, Inc.
  3 *
  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.
  8 *
  9 * The BSD 2-Clause License:
 10 *
 11 *     Redistribution and use in source and binary forms, with or
 12 *     without modification, are permitted provided that the following
 13 *     conditions are met:
 14 *
 15 *      1. Redistributions of source code must retain the above
 16 *         copyright notice, this list of conditions and the following
 17 *         disclaimer.
 18 *
 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.
 23 *
 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
 31 * SOFTWARE.
 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 netlink_ext_ack;
 47struct pci_dev;
 48struct sk_buff;
 49struct sk_buff;
 50struct nfp_app;
 51struct nfp_cpp;
 52struct nfp_pf;
 53struct nfp_repr;
 54struct nfp_net;
 55
 56enum nfp_app_id {
 57	NFP_APP_CORE_NIC	= 0x1,
 58	NFP_APP_BPF_NIC		= 0x2,
 59	NFP_APP_FLOWER_NIC	= 0x3,
 
 60};
 61
 62extern const struct nfp_app_type app_nic;
 63extern const struct nfp_app_type app_bpf;
 64extern const struct nfp_app_type app_flower;
 
 65
 66/**
 67 * struct nfp_app_type - application definition
 68 * @id:		application ID
 69 * @name:	application name
 70 * @ctrl_cap_mask:  ctrl vNIC capability mask, allows disabling features like
 71 *		    IRQMOD which are on by default but counter-productive for
 72 *		    control messages which are often latency-sensitive
 73 * @ctrl_has_meta:  control messages have prepend of type:5/port:CTRL
 74 *
 75 * Callbacks
 76 * @init:	perform basic app checks and init
 77 * @clean:	clean app state
 78 * @extra_cap:	extra capabilities string
 
 
 79 * @vnic_alloc:	allocate vNICs (assign port types, etc.)
 80 * @vnic_free:	free up app's vNIC state
 81 * @vnic_init:	vNIC netdev was registered
 82 * @vnic_clean:	vNIC netdev about to be unregistered
 83 * @repr_init:	representor about to be registered
 84 * @repr_preclean:	representor about to unregistered, executed before app
 85 *			reference to the it is removed
 86 * @repr_clean:	representor about to be unregistered
 87 * @repr_open:	representor netdev open callback
 88 * @repr_stop:	representor netdev stop callback
 89 * @check_mtu:	MTU change request on a netdev (verify it is valid)
 90 * @repr_change_mtu:	MTU change request on repr (make and verify change)
 
 
 
 91 * @start:	start application logic
 92 * @stop:	stop application logic
 
 93 * @ctrl_msg_rx:    control message handler
 
 94 * @setup_tc:	setup TC ndo
 95 * @bpf:	BPF ndo offload-related calls
 96 * @xdp_offload:    offload an XDP program
 97 * @eswitch_mode_get:    get SR-IOV eswitch mode
 
 98 * @sriov_enable: app-specific sriov initialisation
 99 * @sriov_disable: app-specific sriov clean-up
100 * @repr_get:	get representor netdev
101 */
102struct nfp_app_type {
103	enum nfp_app_id id;
104	const char *name;
105
106	u32 ctrl_cap_mask;
107	bool ctrl_has_meta;
108
109	int (*init)(struct nfp_app *app);
110	void (*clean)(struct nfp_app *app);
111
112	const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
113
 
 
 
114	int (*vnic_alloc)(struct nfp_app *app, struct nfp_net *nn,
115			  unsigned int id);
116	void (*vnic_free)(struct nfp_app *app, struct nfp_net *nn);
117	int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn);
118	void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
119
120	int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
121	void (*repr_preclean)(struct nfp_app *app, struct net_device *netdev);
122	void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
123
124	int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
125	int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr);
126
127	int (*check_mtu)(struct nfp_app *app, struct net_device *netdev,
128			 int new_mtu);
129	int (*repr_change_mtu)(struct nfp_app *app, struct net_device *netdev,
130			       int new_mtu);
131
 
 
 
 
 
 
132	int (*start)(struct nfp_app *app);
133	void (*stop)(struct nfp_app *app);
134
 
 
 
135	void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
 
 
136
137	int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
138			enum tc_setup_type type, void *type_data);
139	int (*bpf)(struct nfp_app *app, struct nfp_net *nn,
140		   struct netdev_bpf *xdp);
141	int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
142			   struct bpf_prog *prog,
143			   struct netlink_ext_ack *extack);
144
145	int (*sriov_enable)(struct nfp_app *app, int num_vfs);
146	void (*sriov_disable)(struct nfp_app *app);
147
148	enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
149	struct net_device *(*repr_get)(struct nfp_app *app, u32 id);
 
 
150};
151
152/**
153 * struct nfp_app - NFP application container
154 * @pdev:	backpointer to PCI device
155 * @pf:		backpointer to NFP PF structure
156 * @cpp:	pointer to the CPP handle
157 * @ctrl:	pointer to ctrl vNIC struct
158 * @reprs:	array of pointers to representors
159 * @type:	pointer to const application ops and info
 
 
160 * @priv:	app-specific priv data
161 */
162struct nfp_app {
163	struct pci_dev *pdev;
164	struct nfp_pf *pf;
165	struct nfp_cpp *cpp;
166
167	struct nfp_net *ctrl;
168	struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
169
170	const struct nfp_app_type *type;
 
 
 
 
171	void *priv;
172};
173
 
 
 
 
 
 
 
 
 
 
 
174bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
175bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
176
177static inline int nfp_app_init(struct nfp_app *app)
178{
179	if (!app->type->init)
180		return 0;
181	return app->type->init(app);
182}
183
184static inline void nfp_app_clean(struct nfp_app *app)
185{
186	if (app->type->clean)
187		app->type->clean(app);
188}
189
 
 
 
190static inline int nfp_app_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
191				     unsigned int id)
192{
193	return app->type->vnic_alloc(app, nn, id);
194}
195
196static inline void nfp_app_vnic_free(struct nfp_app *app, struct nfp_net *nn)
197{
198	if (app->type->vnic_free)
199		app->type->vnic_free(app, nn);
200}
201
202static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn)
203{
204	if (!app->type->vnic_init)
205		return 0;
206	return app->type->vnic_init(app, nn);
207}
208
209static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
210{
211	if (app->type->vnic_clean)
212		app->type->vnic_clean(app, nn);
213}
214
215static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr)
216{
217	if (!app->type->repr_open)
218		return -EINVAL;
219	return app->type->repr_open(app, repr);
220}
221
222static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr)
223{
224	if (!app->type->repr_stop)
225		return -EINVAL;
226	return app->type->repr_stop(app, repr);
227}
228
229static inline int
230nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
231{
232	if (!app->type->repr_init)
233		return 0;
234	return app->type->repr_init(app, netdev);
235}
236
237static inline void
238nfp_app_repr_preclean(struct nfp_app *app, struct net_device *netdev)
239{
240	if (app->type->repr_preclean)
241		app->type->repr_preclean(app, netdev);
242}
243
244static inline void
245nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
246{
247	if (app->type->repr_clean)
248		app->type->repr_clean(app, netdev);
249}
250
251static inline int
252nfp_app_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
253{
254	if (!app || !app->type->check_mtu)
255		return 0;
256	return app->type->check_mtu(app, netdev, new_mtu);
257}
258
259static inline int
260nfp_app_repr_change_mtu(struct nfp_app *app, struct net_device *netdev,
261			int new_mtu)
262{
263	if (!app || !app->type->repr_change_mtu)
264		return 0;
265	return app->type->repr_change_mtu(app, netdev, new_mtu);
266}
267
268static inline int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl)
269{
270	app->ctrl = ctrl;
271	if (!app->type->start)
272		return 0;
273	return app->type->start(app);
274}
275
276static inline void nfp_app_stop(struct nfp_app *app)
277{
278	if (!app->type->stop)
279		return;
280	app->type->stop(app);
281}
282
283static inline const char *nfp_app_name(struct nfp_app *app)
284{
285	if (!app)
286		return "";
287	return app->type->name;
288}
289
290static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
291{
292	return app && app->type->ctrl_msg_rx;
293}
294
295static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
296{
297	return app->type->ctrl_has_meta;
298}
299
 
 
 
 
 
300static inline const char *nfp_app_extra_cap(struct nfp_app *app,
301					    struct nfp_net *nn)
302{
303	if (!app || !app->type->extra_cap)
304		return "";
305	return app->type->extra_cap(app, nn);
306}
307
308static inline bool nfp_app_has_tc(struct nfp_app *app)
309{
310	return app && app->type->setup_tc;
311}
312
313static inline int nfp_app_setup_tc(struct nfp_app *app,
314				   struct net_device *netdev,
315				   enum tc_setup_type type, void *type_data)
316{
317	if (!app || !app->type->setup_tc)
318		return -EOPNOTSUPP;
319	return app->type->setup_tc(app, netdev, type, type_data);
320}
321
322static inline int nfp_app_bpf(struct nfp_app *app, struct nfp_net *nn,
323			      struct netdev_bpf *bpf)
324{
325	if (!app || !app->type->bpf)
326		return -EINVAL;
327	return app->type->bpf(app, nn, bpf);
328}
329
330static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
331				      struct bpf_prog *prog,
332				      struct netlink_ext_ack *extack)
333{
334	if (!app || !app->type->xdp_offload)
335		return -EOPNOTSUPP;
336	return app->type->xdp_offload(app, nn, prog, extack);
337}
338
339static inline bool __nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
340{
341	trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
342			    skb->data, skb->len);
343
344	return __nfp_ctrl_tx(app->ctrl, skb);
345}
346
347static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
348{
349	trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
350			    skb->data, skb->len);
351
352	return nfp_ctrl_tx(app->ctrl, skb);
353}
354
355static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
356{
357	trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0,
358			    skb->data, skb->len);
359
360	app->type->ctrl_msg_rx(app, skb);
361}
362
 
 
 
 
 
 
 
 
 
 
363static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
364{
365	if (!app->type->eswitch_mode_get)
366		return -EOPNOTSUPP;
367
368	*mode = app->type->eswitch_mode_get(app);
369
370	return 0;
371}
372
 
 
 
 
 
 
 
373static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
374{
375	if (!app || !app->type->sriov_enable)
376		return -EOPNOTSUPP;
377	return app->type->sriov_enable(app, num_vfs);
378}
379
380static inline void nfp_app_sriov_disable(struct nfp_app *app)
381{
382	if (app && app->type->sriov_disable)
383		app->type->sriov_disable(app);
384}
385
386static inline struct net_device *nfp_app_repr_get(struct nfp_app *app, u32 id)
 
 
387{
388	if (unlikely(!app || !app->type->repr_get))
389		return NULL;
390
391	return app->type->repr_get(app, id);
392}
393
394struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
395
 
 
 
 
396struct nfp_reprs *
397nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type);
398struct nfp_reprs *
399nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
400		  struct nfp_reprs *reprs);
401
402const char *nfp_app_mip_name(struct nfp_app *app);
403struct sk_buff *
404nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
405
406struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
407void nfp_app_free(struct nfp_app *app);
 
 
408
409/* Callbacks shared between apps */
410
411int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
412			   unsigned int id);
 
 
413
414#endif
v6.13.7
  1/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
  2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  3
  4#ifndef _NFP_APP_H
  5#define _NFP_APP_H 1
  6
  7#include <net/devlink.h>
  8
  9#include <trace/events/devlink.h>
 10
 11#include "nfp_net_repr.h"
 12
 13#define NFP_APP_CTRL_MTU_MAX	U32_MAX
 14
 15struct bpf_prog;
 16struct net_device;
 17struct netdev_bpf;
 18struct netlink_ext_ack;
 19struct pci_dev;
 20struct sk_buff;
 
 21struct nfp_app;
 22struct nfp_cpp;
 23struct nfp_pf;
 24struct nfp_repr;
 25struct nfp_net;
 26
 27enum nfp_app_id {
 28	NFP_APP_CORE_NIC	= 0x1,
 29	NFP_APP_BPF_NIC		= 0x2,
 30	NFP_APP_FLOWER_NIC	= 0x3,
 31	NFP_APP_ACTIVE_BUFFER_MGMT_NIC = 0x4,
 32};
 33
 34extern const struct nfp_app_type app_nic;
 35extern const struct nfp_app_type app_bpf;
 36extern const struct nfp_app_type app_flower;
 37extern const struct nfp_app_type app_abm;
 38
 39/**
 40 * struct nfp_app_type - application definition
 41 * @id:		application ID
 42 * @name:	application name
 43 * @ctrl_cap_mask:  ctrl vNIC capability mask, allows disabling features like
 44 *		    IRQMOD which are on by default but counter-productive for
 45 *		    control messages which are often latency-sensitive
 46 * @ctrl_has_meta:  control messages have prepend of type:5/port:CTRL
 47 *
 48 * Callbacks
 49 * @init:	perform basic app checks and init
 50 * @clean:	clean app state
 51 * @extra_cap:	extra capabilities string
 52 * @ndo_init:	vNIC and repr netdev .ndo_init
 53 * @ndo_uninit:	vNIC and repr netdev .ndo_unint
 54 * @vnic_alloc:	allocate vNICs (assign port types, etc.)
 55 * @vnic_free:	free up app's vNIC state
 56 * @vnic_init:	vNIC netdev was registered
 57 * @vnic_clean:	vNIC netdev about to be unregistered
 58 * @repr_init:	representor about to be registered
 59 * @repr_preclean:	representor about to unregistered, executed before app
 60 *			reference to the it is removed
 61 * @repr_clean:	representor about to be unregistered
 62 * @repr_open:	representor netdev open callback
 63 * @repr_stop:	representor netdev stop callback
 64 * @check_mtu:	MTU change request on a netdev (verify it is valid)
 65 * @repr_change_mtu:	MTU change request on repr (make and verify change)
 66 * @port_get_stats:		get extra ethtool statistics for a port
 67 * @port_get_stats_count:	get count of extra statistics for a port
 68 * @port_get_stats_strings:	get strings for extra statistics
 69 * @start:	start application logic
 70 * @stop:	stop application logic
 71 * @netdev_event:	Netdevice notifier event
 72 * @ctrl_msg_rx:    control message handler
 73 * @ctrl_msg_rx_raw:	handler for control messages from data queues
 74 * @setup_tc:	setup TC ndo
 75 * @bpf:	BPF ndo offload-related calls
 76 * @xdp_offload:    offload an XDP program
 77 * @eswitch_mode_get:    get SR-IOV eswitch mode
 78 * @eswitch_mode_set:    set SR-IOV eswitch mode
 79 * @sriov_enable: app-specific sriov initialisation
 80 * @sriov_disable: app-specific sriov clean-up
 81 * @dev_get:	get representor or internal port representing netdev
 82 */
 83struct nfp_app_type {
 84	enum nfp_app_id id;
 85	const char *name;
 86
 87	u32 ctrl_cap_mask;
 88	bool ctrl_has_meta;
 89
 90	int (*init)(struct nfp_app *app);
 91	void (*clean)(struct nfp_app *app);
 92
 93	const char *(*extra_cap)(struct nfp_app *app, struct nfp_net *nn);
 94
 95	int (*ndo_init)(struct nfp_app *app, struct net_device *netdev);
 96	void (*ndo_uninit)(struct nfp_app *app, struct net_device *netdev);
 97
 98	int (*vnic_alloc)(struct nfp_app *app, struct nfp_net *nn,
 99			  unsigned int id);
100	void (*vnic_free)(struct nfp_app *app, struct nfp_net *nn);
101	int (*vnic_init)(struct nfp_app *app, struct nfp_net *nn);
102	void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
103
104	int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
105	void (*repr_preclean)(struct nfp_app *app, struct net_device *netdev);
106	void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
107
108	int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
109	int (*repr_stop)(struct nfp_app *app, struct nfp_repr *repr);
110
111	int (*check_mtu)(struct nfp_app *app, struct net_device *netdev,
112			 int new_mtu);
113	int (*repr_change_mtu)(struct nfp_app *app, struct net_device *netdev,
114			       int new_mtu);
115
116	u64 *(*port_get_stats)(struct nfp_app *app,
117			       struct nfp_port *port, u64 *data);
118	int (*port_get_stats_count)(struct nfp_app *app, struct nfp_port *port);
119	u8 *(*port_get_stats_strings)(struct nfp_app *app,
120				      struct nfp_port *port, u8 *data);
121
122	int (*start)(struct nfp_app *app);
123	void (*stop)(struct nfp_app *app);
124
125	int (*netdev_event)(struct nfp_app *app, struct net_device *netdev,
126			    unsigned long event, void *ptr);
127
128	void (*ctrl_msg_rx)(struct nfp_app *app, struct sk_buff *skb);
129	void (*ctrl_msg_rx_raw)(struct nfp_app *app, const void *data,
130				unsigned int len);
131
132	int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
133			enum tc_setup_type type, void *type_data);
134	int (*bpf)(struct nfp_app *app, struct nfp_net *nn,
135		   struct netdev_bpf *xdp);
136	int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
137			   struct bpf_prog *prog,
138			   struct netlink_ext_ack *extack);
139
140	int (*sriov_enable)(struct nfp_app *app, int num_vfs);
141	void (*sriov_disable)(struct nfp_app *app);
142
143	enum devlink_eswitch_mode (*eswitch_mode_get)(struct nfp_app *app);
144	int (*eswitch_mode_set)(struct nfp_app *app, u16 mode);
145	struct net_device *(*dev_get)(struct nfp_app *app, u32 id,
146				      bool *redir_egress);
147};
148
149/**
150 * struct nfp_app - NFP application container
151 * @pdev:	backpointer to PCI device
152 * @pf:		backpointer to NFP PF structure
153 * @cpp:	pointer to the CPP handle
154 * @ctrl:	pointer to ctrl vNIC struct
155 * @reprs:	array of pointers to representors
156 * @type:	pointer to const application ops and info
157 * @ctrl_mtu:	MTU to set on the control vNIC (set in .init())
158 * @netdev_nb:	Netdevice notifier block
159 * @priv:	app-specific priv data
160 */
161struct nfp_app {
162	struct pci_dev *pdev;
163	struct nfp_pf *pf;
164	struct nfp_cpp *cpp;
165
166	struct nfp_net *ctrl;
167	struct nfp_reprs __rcu *reprs[NFP_REPR_TYPE_MAX + 1];
168
169	const struct nfp_app_type *type;
170	unsigned int ctrl_mtu;
171
172	struct notifier_block netdev_nb;
173
174	void *priv;
175};
176
177static inline void assert_nfp_app_locked(struct nfp_app *app)
178{
179	devl_assert_locked(priv_to_devlink(app->pf));
180}
181
182static inline bool nfp_app_is_locked(struct nfp_app *app)
183{
184	return devl_lock_is_held(priv_to_devlink(app->pf));
185}
186
187void nfp_check_rhashtable_empty(void *ptr, void *arg);
188bool __nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
189bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb);
190
191static inline int nfp_app_init(struct nfp_app *app)
192{
193	if (!app->type->init)
194		return 0;
195	return app->type->init(app);
196}
197
198static inline void nfp_app_clean(struct nfp_app *app)
199{
200	if (app->type->clean)
201		app->type->clean(app);
202}
203
204int nfp_app_ndo_init(struct net_device *netdev);
205void nfp_app_ndo_uninit(struct net_device *netdev);
206
207static inline int nfp_app_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
208				     unsigned int id)
209{
210	return app->type->vnic_alloc(app, nn, id);
211}
212
213static inline void nfp_app_vnic_free(struct nfp_app *app, struct nfp_net *nn)
214{
215	if (app->type->vnic_free)
216		app->type->vnic_free(app, nn);
217}
218
219static inline int nfp_app_vnic_init(struct nfp_app *app, struct nfp_net *nn)
220{
221	if (!app->type->vnic_init)
222		return 0;
223	return app->type->vnic_init(app, nn);
224}
225
226static inline void nfp_app_vnic_clean(struct nfp_app *app, struct nfp_net *nn)
227{
228	if (app->type->vnic_clean)
229		app->type->vnic_clean(app, nn);
230}
231
232static inline int nfp_app_repr_open(struct nfp_app *app, struct nfp_repr *repr)
233{
234	if (!app->type->repr_open)
235		return -EINVAL;
236	return app->type->repr_open(app, repr);
237}
238
239static inline int nfp_app_repr_stop(struct nfp_app *app, struct nfp_repr *repr)
240{
241	if (!app->type->repr_stop)
242		return -EINVAL;
243	return app->type->repr_stop(app, repr);
244}
245
246static inline int
247nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
248{
249	if (!app->type->repr_init)
250		return 0;
251	return app->type->repr_init(app, netdev);
252}
253
254static inline void
255nfp_app_repr_preclean(struct nfp_app *app, struct net_device *netdev)
256{
257	if (app->type->repr_preclean)
258		app->type->repr_preclean(app, netdev);
259}
260
261static inline void
262nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
263{
264	if (app->type->repr_clean)
265		app->type->repr_clean(app, netdev);
266}
267
268static inline int
269nfp_app_check_mtu(struct nfp_app *app, struct net_device *netdev, int new_mtu)
270{
271	if (!app || !app->type->check_mtu)
272		return 0;
273	return app->type->check_mtu(app, netdev, new_mtu);
274}
275
276static inline int
277nfp_app_repr_change_mtu(struct nfp_app *app, struct net_device *netdev,
278			int new_mtu)
279{
280	if (!app || !app->type->repr_change_mtu)
281		return 0;
282	return app->type->repr_change_mtu(app, netdev, new_mtu);
283}
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285static inline const char *nfp_app_name(struct nfp_app *app)
286{
287	if (!app)
288		return "";
289	return app->type->name;
290}
291
292static inline bool nfp_app_needs_ctrl_vnic(struct nfp_app *app)
293{
294	return app && app->type->ctrl_msg_rx;
295}
296
297static inline bool nfp_app_ctrl_has_meta(struct nfp_app *app)
298{
299	return app->type->ctrl_has_meta;
300}
301
302static inline bool nfp_app_ctrl_uses_data_vnics(struct nfp_app *app)
303{
304	return app && app->type->ctrl_msg_rx_raw;
305}
306
307static inline const char *nfp_app_extra_cap(struct nfp_app *app,
308					    struct nfp_net *nn)
309{
310	if (!app || !app->type->extra_cap)
311		return "";
312	return app->type->extra_cap(app, nn);
313}
314
315static inline bool nfp_app_has_tc(struct nfp_app *app)
316{
317	return app && app->type->setup_tc;
318}
319
320static inline int nfp_app_setup_tc(struct nfp_app *app,
321				   struct net_device *netdev,
322				   enum tc_setup_type type, void *type_data)
323{
324	if (!app || !app->type->setup_tc)
325		return -EOPNOTSUPP;
326	return app->type->setup_tc(app, netdev, type, type_data);
327}
328
329static inline int nfp_app_bpf(struct nfp_app *app, struct nfp_net *nn,
330			      struct netdev_bpf *bpf)
331{
332	if (!app || !app->type->bpf)
333		return -EINVAL;
334	return app->type->bpf(app, nn, bpf);
335}
336
337static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
338				      struct bpf_prog *prog,
339				      struct netlink_ext_ack *extack)
340{
341	if (!app || !app->type->xdp_offload)
342		return -EOPNOTSUPP;
343	return app->type->xdp_offload(app, nn, prog, extack);
344}
345
346static inline bool __nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
347{
348	trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
349			    skb->data, skb->len);
350
351	return __nfp_ctrl_tx(app->ctrl, skb);
352}
353
354static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
355{
356	trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
357			    skb->data, skb->len);
358
359	return nfp_ctrl_tx(app->ctrl, skb);
360}
361
362static inline void nfp_app_ctrl_rx(struct nfp_app *app, struct sk_buff *skb)
363{
364	trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0,
365			    skb->data, skb->len);
366
367	app->type->ctrl_msg_rx(app, skb);
368}
369
370static inline void
371nfp_app_ctrl_rx_raw(struct nfp_app *app, const void *data, unsigned int len)
372{
373	if (!app || !app->type->ctrl_msg_rx_raw)
374		return;
375
376	trace_devlink_hwmsg(priv_to_devlink(app->pf), true, 0, data, len);
377	app->type->ctrl_msg_rx_raw(app, data, len);
378}
379
380static inline int nfp_app_eswitch_mode_get(struct nfp_app *app, u16 *mode)
381{
382	if (!app->type->eswitch_mode_get)
383		return -EOPNOTSUPP;
384
385	*mode = app->type->eswitch_mode_get(app);
386
387	return 0;
388}
389
390static inline int nfp_app_eswitch_mode_set(struct nfp_app *app, u16 mode)
391{
392	if (!app->type->eswitch_mode_set)
393		return -EOPNOTSUPP;
394	return app->type->eswitch_mode_set(app, mode);
395}
396
397static inline int nfp_app_sriov_enable(struct nfp_app *app, int num_vfs)
398{
399	if (!app || !app->type->sriov_enable)
400		return -EOPNOTSUPP;
401	return app->type->sriov_enable(app, num_vfs);
402}
403
404static inline void nfp_app_sriov_disable(struct nfp_app *app)
405{
406	if (app && app->type->sriov_disable)
407		app->type->sriov_disable(app);
408}
409
410static inline
411struct net_device *nfp_app_dev_get(struct nfp_app *app, u32 id,
412				   bool *redir_egress)
413{
414	if (unlikely(!app || !app->type->dev_get))
415		return NULL;
416
417	return app->type->dev_get(app, id, redir_egress);
418}
419
420struct nfp_app *nfp_app_from_netdev(struct net_device *netdev);
421
422u64 *nfp_app_port_get_stats(struct nfp_port *port, u64 *data);
423int nfp_app_port_get_stats_count(struct nfp_port *port);
424u8 *nfp_app_port_get_stats_strings(struct nfp_port *port, u8 *data);
425
426struct nfp_reprs *
427nfp_reprs_get_locked(struct nfp_app *app, enum nfp_repr_type type);
428struct nfp_reprs *
429nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
430		  struct nfp_reprs *reprs);
431
432const char *nfp_app_mip_name(struct nfp_app *app);
433struct sk_buff *
434nfp_app_ctrl_msg_alloc(struct nfp_app *app, unsigned int size, gfp_t priority);
435
436struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id);
437void nfp_app_free(struct nfp_app *app);
438int nfp_app_start(struct nfp_app *app, struct nfp_net *ctrl);
439void nfp_app_stop(struct nfp_app *app);
440
441/* Callbacks shared between apps */
442
443int nfp_app_nic_vnic_alloc(struct nfp_app *app, struct nfp_net *nn,
444			   unsigned int id);
445int nfp_app_nic_vnic_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
446				   struct nfp_net *nn, unsigned int id);
447
448#endif