nfp: move port init to apps
Start fleshing out the apps by turning the vNIC init code to
a per-app callback. The two initial apps we have are NIC and
eBPF.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.c b/drivers/net/ethernet/netronome/nfp/nfp_app.c
index 59be638..30687d8 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_app.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_app.c
@@ -33,12 +33,30 @@
#include <linux/slab.h>
+#include "nfpcore/nfp_cpp.h"
#include "nfp_app.h"
#include "nfp_main.h"
-struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
+static const struct nfp_app_type *apps[] = {
+ &app_nic,
+ &app_bpf,
+};
+
+struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
{
struct nfp_app *app;
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(apps); i++)
+ if (apps[i]->id == id)
+ break;
+ if (i == ARRAY_SIZE(apps)) {
+ nfp_err(pf->cpp, "failed to find app with ID 0x%02hhx\n", id);
+ return ERR_PTR(-EINVAL);
+ }
+
+ if (WARN_ON(!apps[i]->vnic_init))
+ return ERR_PTR(-EINVAL);
app = kzalloc(sizeof(*app), GFP_KERNEL);
if (!app)
@@ -47,6 +65,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf)
app->pf = pf;
app->cpp = pf->cpp;
app->pdev = pf->pdev;
+ app->type = apps[i];
return app;
}