Commit 2c4197a0 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: reorganize the app table

The app table is an unordered array right now.  We have to search
apps by ID.  It also makes it harder to fall back to core NIC if
advanced functions are not compiled into the kernel (e.g. eBPF).
Make the table keyed by app id.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarSimon Horman <simon.horman@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f449657f
...@@ -43,10 +43,10 @@ ...@@ -43,10 +43,10 @@
#include "nfp_net_repr.h" #include "nfp_net_repr.h"
static const struct nfp_app_type *apps[] = { static const struct nfp_app_type *apps[] = {
&app_nic, [NFP_APP_CORE_NIC] = &app_nic,
&app_bpf, [NFP_APP_BPF_NIC] = &app_bpf,
#ifdef CONFIG_NFP_APP_FLOWER #ifdef CONFIG_NFP_APP_FLOWER
&app_flower, [NFP_APP_FLOWER_NIC] = &app_flower,
#endif #endif
}; };
...@@ -116,17 +116,13 @@ nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type, ...@@ -116,17 +116,13 @@ nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id) struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
{ {
struct nfp_app *app; struct nfp_app *app;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(apps); i++) if (id >= ARRAY_SIZE(apps) || !apps[id]) {
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); nfp_err(pf->cpp, "failed to find app with ID 0x%02hhx\n", id);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
if (WARN_ON(!apps[i]->name || !apps[i]->vnic_alloc)) if (WARN_ON(!apps[id]->name || !apps[id]->vnic_alloc))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
app = kzalloc(sizeof(*app), GFP_KERNEL); app = kzalloc(sizeof(*app), GFP_KERNEL);
...@@ -136,7 +132,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id) ...@@ -136,7 +132,7 @@ struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
app->pf = pf; app->pf = pf;
app->cpp = pf->cpp; app->cpp = pf->cpp;
app->pdev = pf->pdev; app->pdev = pf->pdev;
app->type = apps[i]; app->type = apps[id];
return app; return app;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment