nfp: xdp: move driver XDP setup into a separate function

In preparation of XDP offload flags move the driver setup into
a function.  Otherwise the number of conditions in one function
would make it slightly hard to follow.  The offload handler may
now be called with NULL prog, even if no offload is currently
active, but that's fine, offload code can handle that.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Jakub Kicinski 2017-06-21 18:25:05 -07:00 committed by David S. Miller
parent ee5d032f7d
commit c443b5acce
1 changed files with 18 additions and 5 deletions

View File

@ -3274,10 +3274,11 @@ static void nfp_net_del_vxlan_port(struct net_device *netdev,
nfp_net_set_vxlan_port(nn, idx, 0);
}
static int nfp_net_xdp_setup(struct nfp_net *nn, struct netdev_xdp *xdp)
static int
nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog,
struct netlink_ext_ack *extack)
{
struct bpf_prog *old_prog = nn->dp.xdp_prog;
struct bpf_prog *prog = xdp->prog;
struct nfp_net_dp *dp;
int err;
@ -3286,7 +3287,6 @@ static int nfp_net_xdp_setup(struct nfp_net *nn, struct netdev_xdp *xdp)
if (prog && nn->dp.xdp_prog) {
prog = xchg(&nn->dp.xdp_prog, prog);
bpf_prog_put(prog);
nfp_app_xdp_offload(nn->app, nn, nn->dp.xdp_prog);
return 0;
}
@ -3300,13 +3300,26 @@ static int nfp_net_xdp_setup(struct nfp_net *nn, struct netdev_xdp *xdp)
dp->rx_dma_off = prog ? XDP_PACKET_HEADROOM - nn->dp.rx_offset : 0;
/* We need RX reconfig to remap the buffers (BIDIR vs FROM_DEV) */
err = nfp_net_ring_reconfig(nn, dp, xdp->extack);
err = nfp_net_ring_reconfig(nn, dp, extack);
if (err)
return err;
if (old_prog)
bpf_prog_put(old_prog);
return 0;
}
static int
nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog,
struct netlink_ext_ack *extack)
{
int err;
err = nfp_net_xdp_setup_drv(nn, prog, extack);
if (err)
return err;
nfp_app_xdp_offload(nn->app, nn, nn->dp.xdp_prog);
return 0;
@ -3318,7 +3331,7 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_xdp *xdp)
switch (xdp->command) {
case XDP_SETUP_PROG:
return nfp_net_xdp_setup(nn, xdp);
return nfp_net_xdp_setup(nn, xdp->prog, xdp->extack);
case XDP_QUERY_PROG:
xdp->prog_attached = !!nn->dp.xdp_prog;
xdp->prog_id = nn->dp.xdp_prog ? nn->dp.xdp_prog->aux->id : 0;