Skip to content

Commit 2c4197a

Browse files
Jakub Kicinskidavem330
authored andcommitted
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: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f449657 commit 2c4197a

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

drivers/net/ethernet/netronome/nfp/nfp_app.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
#include "nfp_net_repr.h"
4444

4545
static const struct nfp_app_type *apps[] = {
46-
&app_nic,
47-
&app_bpf,
46+
[NFP_APP_CORE_NIC] = &app_nic,
47+
[NFP_APP_BPF_NIC] = &app_bpf,
4848
#ifdef CONFIG_NFP_APP_FLOWER
49-
&app_flower,
49+
[NFP_APP_FLOWER_NIC] = &app_flower,
5050
#endif
5151
};
5252

@@ -116,17 +116,13 @@ nfp_app_reprs_set(struct nfp_app *app, enum nfp_repr_type type,
116116
struct nfp_app *nfp_app_alloc(struct nfp_pf *pf, enum nfp_app_id id)
117117
{
118118
struct nfp_app *app;
119-
unsigned int i;
120119

121-
for (i = 0; i < ARRAY_SIZE(apps); i++)
122-
if (apps[i]->id == id)
123-
break;
124-
if (i == ARRAY_SIZE(apps)) {
120+
if (id >= ARRAY_SIZE(apps) || !apps[id]) {
125121
nfp_err(pf->cpp, "failed to find app with ID 0x%02hhx\n", id);
126122
return ERR_PTR(-EINVAL);
127123
}
128124

129-
if (WARN_ON(!apps[i]->name || !apps[i]->vnic_alloc))
125+
if (WARN_ON(!apps[id]->name || !apps[id]->vnic_alloc))
130126
return ERR_PTR(-EINVAL);
131127

132128
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)
136132
app->pf = pf;
137133
app->cpp = pf->cpp;
138134
app->pdev = pf->pdev;
139-
app->type = apps[i];
135+
app->type = apps[id];
140136

141137
return app;
142138
}

0 commit comments

Comments
 (0)