aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-01-10 07:26:04 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-01-10 07:49:36 -0500
commitaf93d15ac6c40d097b08c18a65a0414f94110401 (patch)
tree6f5a407b11ecf323222c6b808717eeb5ef9fb488
parente84797fe159c8f849edd96ab72cc21eb890656fe (diff)
nfp: hand over to BPF offload app at coarser granularity
Instead of having an app callback per message type hand off all offload-related handling to apps with one "rest of ndo_bpf" callback. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/main.c5
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/main.h8
-rw-r--r--drivers/net/ethernet/netronome/nfp/bpf/offload.c25
-rw-r--r--drivers/net/ethernet/netronome/nfp/nfp_app.h47
-rw-r--r--drivers/net/ethernet/netronome/nfp/nfp_net_common.c10
5 files changed, 34 insertions, 61 deletions
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.c b/drivers/net/ethernet/netronome/nfp/bpf/main.c
index 9ed76ccdd3c1..e8cfe300c8c4 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.c
@@ -345,9 +345,6 @@ const struct nfp_app_type app_bpf = {
345 345
346 .setup_tc = nfp_bpf_setup_tc, 346 .setup_tc = nfp_bpf_setup_tc,
347 .tc_busy = nfp_bpf_tc_busy, 347 .tc_busy = nfp_bpf_tc_busy,
348 .bpf = nfp_ndo_bpf,
348 .xdp_offload = nfp_bpf_xdp_offload, 349 .xdp_offload = nfp_bpf_xdp_offload,
349
350 .bpf_verifier_prep = nfp_bpf_verifier_prep,
351 .bpf_translate = nfp_bpf_translate,
352 .bpf_destroy = nfp_bpf_destroy,
353}; 350};
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/main.h b/drivers/net/ethernet/netronome/nfp/bpf/main.h
index 8d02c39b9b10..66381afee2a9 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/main.h
+++ b/drivers/net/ethernet/netronome/nfp/bpf/main.h
@@ -256,15 +256,11 @@ struct netdev_bpf;
256struct nfp_app; 256struct nfp_app;
257struct nfp_net; 257struct nfp_net;
258 258
259int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn,
260 struct netdev_bpf *bpf);
259int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog, 261int nfp_net_bpf_offload(struct nfp_net *nn, struct bpf_prog *prog,
260 bool old_prog); 262 bool old_prog);
261 263
262int nfp_bpf_verifier_prep(struct nfp_app *app, struct nfp_net *nn,
263 struct netdev_bpf *bpf);
264int nfp_bpf_translate(struct nfp_app *app, struct nfp_net *nn,
265 struct bpf_prog *prog);
266int nfp_bpf_destroy(struct nfp_app *app, struct nfp_net *nn,
267 struct bpf_prog *prog);
268struct nfp_insn_meta * 264struct nfp_insn_meta *
269nfp_bpf_goto_meta(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta, 265nfp_bpf_goto_meta(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta,
270 unsigned int insn_idx, unsigned int n_insns); 266 unsigned int insn_idx, unsigned int n_insns);
diff --git a/drivers/net/ethernet/netronome/nfp/bpf/offload.c b/drivers/net/ethernet/netronome/nfp/bpf/offload.c
index f63560550753..320b2250d29a 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/offload.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/offload.c
@@ -87,8 +87,9 @@ static void nfp_prog_free(struct nfp_prog *nfp_prog)
87 kfree(nfp_prog); 87 kfree(nfp_prog);
88} 88}
89 89
90int nfp_bpf_verifier_prep(struct nfp_app *app, struct nfp_net *nn, 90static int
91 struct netdev_bpf *bpf) 91nfp_bpf_verifier_prep(struct nfp_app *app, struct nfp_net *nn,
92 struct netdev_bpf *bpf)
92{ 93{
93 struct bpf_prog *prog = bpf->verifier.prog; 94 struct bpf_prog *prog = bpf->verifier.prog;
94 struct nfp_prog *nfp_prog; 95 struct nfp_prog *nfp_prog;
@@ -118,8 +119,7 @@ err_free:
118 return ret; 119 return ret;
119} 120}
120 121
121int nfp_bpf_translate(struct nfp_app *app, struct nfp_net *nn, 122static int nfp_bpf_translate(struct nfp_net *nn, struct bpf_prog *prog)
122 struct bpf_prog *prog)
123{ 123{
124 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; 124 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
125 unsigned int stack_size; 125 unsigned int stack_size;
@@ -143,8 +143,7 @@ int nfp_bpf_translate(struct nfp_app *app, struct nfp_net *nn,
143 return nfp_bpf_jit(nfp_prog); 143 return nfp_bpf_jit(nfp_prog);
144} 144}
145 145
146int nfp_bpf_destroy(struct nfp_app *app, struct nfp_net *nn, 146static int nfp_bpf_destroy(struct nfp_net *nn, struct bpf_prog *prog)
147 struct bpf_prog *prog)
148{ 147{
149 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; 148 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
150 149
@@ -154,6 +153,20 @@ int nfp_bpf_destroy(struct nfp_app *app, struct nfp_net *nn,
154 return 0; 153 return 0;
155} 154}
156 155
156int nfp_ndo_bpf(struct nfp_app *app, struct nfp_net *nn, struct netdev_bpf *bpf)
157{
158 switch (bpf->command) {
159 case BPF_OFFLOAD_VERIFIER_PREP:
160 return nfp_bpf_verifier_prep(app, nn, bpf);
161 case BPF_OFFLOAD_TRANSLATE:
162 return nfp_bpf_translate(nn, bpf->offload.prog);
163 case BPF_OFFLOAD_DESTROY:
164 return nfp_bpf_destroy(nn, bpf->offload.prog);
165 default:
166 return -EINVAL;
167 }
168}
169
157static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog) 170static int nfp_net_bpf_load(struct nfp_net *nn, struct bpf_prog *prog)
158{ 171{
159 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv; 172 struct nfp_prog *nfp_prog = prog->aux->offload->dev_priv;
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_app.h b/drivers/net/ethernet/netronome/nfp/nfp_app.h
index e6b59c28c4ca..32ff46a00f70 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_app.h
+++ b/drivers/net/ethernet/netronome/nfp/nfp_app.h
@@ -89,10 +89,8 @@ extern const struct nfp_app_type app_flower;
89 * @ctrl_msg_rx: control message handler 89 * @ctrl_msg_rx: control message handler
90 * @setup_tc: setup TC ndo 90 * @setup_tc: setup TC ndo
91 * @tc_busy: TC HW offload busy (rules loaded) 91 * @tc_busy: TC HW offload busy (rules loaded)
92 * @bpf: BPF ndo offload-related calls
92 * @xdp_offload: offload an XDP program 93 * @xdp_offload: offload an XDP program
93 * @bpf_verifier_prep: verifier prep for dev-specific BPF programs
94 * @bpf_translate: translate call for dev-specific BPF programs
95 * @bpf_destroy: destroy for dev-specific BPF programs
96 * @eswitch_mode_get: get SR-IOV eswitch mode 94 * @eswitch_mode_get: get SR-IOV eswitch mode
97 * @sriov_enable: app-specific sriov initialisation 95 * @sriov_enable: app-specific sriov initialisation
98 * @sriov_disable: app-specific sriov clean-up 96 * @sriov_disable: app-specific sriov clean-up
@@ -133,14 +131,10 @@ struct nfp_app_type {
133 int (*setup_tc)(struct nfp_app *app, struct net_device *netdev, 131 int (*setup_tc)(struct nfp_app *app, struct net_device *netdev,
134 enum tc_setup_type type, void *type_data); 132 enum tc_setup_type type, void *type_data);
135 bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn); 133 bool (*tc_busy)(struct nfp_app *app, struct nfp_net *nn);
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, 136 int (*xdp_offload)(struct nfp_app *app, struct nfp_net *nn,
137 struct bpf_prog *prog); 137 struct bpf_prog *prog);
138 int (*bpf_verifier_prep)(struct nfp_app *app, struct nfp_net *nn,
139 struct netdev_bpf *bpf);
140 int (*bpf_translate)(struct nfp_app *app, struct nfp_net *nn,
141 struct bpf_prog *prog);
142 int (*bpf_destroy)(struct nfp_app *app, struct nfp_net *nn,
143 struct bpf_prog *prog);
144 138
145 int (*sriov_enable)(struct nfp_app *app, int num_vfs); 139 int (*sriov_enable)(struct nfp_app *app, int num_vfs);
146 void (*sriov_disable)(struct nfp_app *app); 140 void (*sriov_disable)(struct nfp_app *app);
@@ -316,6 +310,14 @@ static inline int nfp_app_setup_tc(struct nfp_app *app,
316 return app->type->setup_tc(app, netdev, type, type_data); 310 return app->type->setup_tc(app, netdev, type, type_data);
317} 311}
318 312
313static inline int nfp_app_bpf(struct nfp_app *app, struct nfp_net *nn,
314 struct netdev_bpf *bpf)
315{
316 if (!app || !app->type->bpf)
317 return -EINVAL;
318 return app->type->bpf(app, nn, bpf);
319}
320
319static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn, 321static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
320 struct bpf_prog *prog) 322 struct bpf_prog *prog)
321{ 323{
@@ -324,33 +326,6 @@ static inline int nfp_app_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
324 return app->type->xdp_offload(app, nn, prog); 326 return app->type->xdp_offload(app, nn, prog);
325} 327}
326 328
327static inline int
328nfp_app_bpf_verifier_prep(struct nfp_app *app, struct nfp_net *nn,
329 struct netdev_bpf *bpf)
330{
331 if (!app || !app->type->bpf_verifier_prep)
332 return -EOPNOTSUPP;
333 return app->type->bpf_verifier_prep(app, nn, bpf);
334}
335
336static inline int
337nfp_app_bpf_translate(struct nfp_app *app, struct nfp_net *nn,
338 struct bpf_prog *prog)
339{
340 if (!app || !app->type->bpf_translate)
341 return -EOPNOTSUPP;
342 return app->type->bpf_translate(app, nn, prog);
343}
344
345static inline int
346nfp_app_bpf_destroy(struct nfp_app *app, struct nfp_net *nn,
347 struct bpf_prog *prog)
348{
349 if (!app || !app->type->bpf_destroy)
350 return -EOPNOTSUPP;
351 return app->type->bpf_destroy(app, nn, prog);
352}
353
354static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb) 329static inline bool nfp_app_ctrl_tx(struct nfp_app *app, struct sk_buff *skb)
355{ 330{
356 trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0, 331 trace_devlink_hwmsg(priv_to_devlink(app->pf), false, 0,
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 33cbb9b35e68..caee147fce04 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -3414,16 +3414,8 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_bpf *xdp)
3414 xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0; 3414 xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0;
3415 xdp->prog_flags = nn->xdp_prog ? nn->xdp_flags : 0; 3415 xdp->prog_flags = nn->xdp_prog ? nn->xdp_flags : 0;
3416 return 0; 3416 return 0;
3417 case BPF_OFFLOAD_VERIFIER_PREP:
3418 return nfp_app_bpf_verifier_prep(nn->app, nn, xdp);
3419 case BPF_OFFLOAD_TRANSLATE:
3420 return nfp_app_bpf_translate(nn->app, nn,
3421 xdp->offload.prog);
3422 case BPF_OFFLOAD_DESTROY:
3423 return nfp_app_bpf_destroy(nn->app, nn,
3424 xdp->offload.prog);
3425 default: 3417 default:
3426 return -EINVAL; 3418 return nfp_app_bpf(nn->app, nn, xdp);
3427 } 3419 }
3428} 3420}
3429 3421