* @rss_key: RSS secret key
* @rss_itbl: RSS indirection table
* @xdp_flags: Flags with which XDP prog was loaded
+ * @xdp_prog: XDP prog (for ctrl path, both DRV and HW modes)
* @max_r_vecs: Number of allocated interrupt vectors for RX/TX
* @max_tx_rings: Maximum number of TX rings supported by the Firmware
* @max_rx_rings: Maximum number of RX rings supported by the Firmware
u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];
u32 xdp_flags;
+ struct bpf_prog *xdp_prog;
unsigned int max_tx_rings;
unsigned int max_rx_rings;
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 nfp_net_dp *dp;
- int err;
- if (!prog && !nn->dp.xdp_prog)
- return 0;
- if (prog && nn->dp.xdp_prog) {
- prog = xchg(&nn->dp.xdp_prog, prog);
- bpf_prog_put(prog);
+ if (!prog == !nn->dp.xdp_prog) {
+ WRITE_ONCE(nn->dp.xdp_prog, prog);
return 0;
}
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, extack);
- if (err)
- return err;
-
- if (old_prog)
- bpf_prog_put(old_prog);
-
- return 0;
+ return nfp_net_ring_reconfig(nn, dp, extack);
}
static int
struct bpf_prog *offload_prog;
int err;
- if (nn->dp.xdp_prog && (flags ^ nn->xdp_flags) & XDP_FLAGS_MODES)
+ if (nn->xdp_prog && (flags ^ nn->xdp_flags) & XDP_FLAGS_MODES)
return -EBUSY;
offload_prog = flags & XDP_FLAGS_DRV_MODE ? NULL : prog;
return err;
nfp_app_xdp_offload(nn->app, nn, offload_prog);
+
+ if (nn->xdp_prog)
+ bpf_prog_put(nn->xdp_prog);
+ nn->xdp_prog = prog;
nn->xdp_flags = flags;
return 0;
return nfp_net_xdp_setup(nn, xdp->prog, xdp->flags,
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;
+ xdp->prog_attached = !!nn->xdp_prog;
+ xdp->prog_id = nn->xdp_prog ? nn->xdp_prog->aux->id : 0;
return 0;
default:
return -EINVAL;
*/
void nfp_net_free(struct nfp_net *nn)
{
+ if (nn->xdp_prog)
+ bpf_prog_put(nn->xdp_prog);
+
if (nn->dp.netdev)
free_netdev(nn->dp.netdev);
else
return;
unregister_netdev(nn->dp.netdev);
-
- if (nn->dp.xdp_prog)
- bpf_prog_put(nn->dp.xdp_prog);
}