Skip to content

Commit

Permalink
nfp: add support for simultaneous driver and hw XDP
Browse files Browse the repository at this point in the history
Split handling of offloaded and driver programs completely.  Since
offloaded programs always come with XDP_FLAGS_HW_MODE set in reality
there could be no sharing, anyway, programs would only be installed
in driver or in hardware.  Splitting the handling allows us to install
programs in HW and in driver at the same time.

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>
  • Loading branch information
Jakub Kicinski authored and Daniel Borkmann committed Jul 13, 2018
1 parent 99dadb6 commit 5f42840
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
11 changes: 2 additions & 9 deletions drivers/net/ethernet/netronome/nfp/bpf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,19 @@ nfp_bpf_xdp_offload(struct nfp_app *app, struct nfp_net *nn,
struct bpf_prog *prog, struct netlink_ext_ack *extack)
{
bool running, xdp_running;
int ret;

if (!nfp_net_ebpf_capable(nn))
return -EINVAL;

running = nn->dp.ctrl & NFP_NET_CFG_CTRL_BPF;
xdp_running = running && nn->dp.bpf_offload_xdp;
xdp_running = running && nn->xdp_hw.prog;

if (!prog && !xdp_running)
return 0;
if (prog && running && !xdp_running)
return -EBUSY;

ret = nfp_net_bpf_offload(nn, prog, running, extack);
/* Stop offload if replace not possible */
if (ret)
return ret;

nn->dp.bpf_offload_xdp = !!prog;
return ret;
return nfp_net_bpf_offload(nn, prog, running, extack);
}

static const char *nfp_bpf_extra_cap(struct nfp_app *app, struct nfp_net *nn)
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/ethernet/netronome/nfp/nfp_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ struct nfp_stat_pair {
* @dev: Backpointer to struct device
* @netdev: Backpointer to net_device structure
* @is_vf: Is the driver attached to a VF?
* @bpf_offload_xdp: Offloaded BPF program is XDP
* @chained_metadata_format: Firemware will use new metadata format
* @rx_dma_dir: Mapping direction for RX buffers
* @rx_dma_off: Offset at which DMA packets (for XDP headroom)
Expand All @@ -510,7 +509,6 @@ struct nfp_net_dp {
struct net_device *netdev;

u8 is_vf:1;
u8 bpf_offload_xdp:1;
u8 chained_metadata_format:1;

u8 rx_dma_dir;
Expand Down Expand Up @@ -553,7 +551,8 @@ struct nfp_net_dp {
* @rss_cfg: RSS configuration
* @rss_key: RSS secret key
* @rss_itbl: RSS indirection table
* @xdp: Information about the attached XDP program
* @xdp: Information about the driver XDP program
* @xdp_hw: Information about the HW XDP program
* @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
Expand Down Expand Up @@ -610,6 +609,7 @@ struct nfp_net {
u8 rss_itbl[NFP_NET_CFG_RSS_ITBL_SZ];

struct xdp_attachment_info xdp;
struct xdp_attachment_info xdp_hw;

unsigned int max_tx_rings;
unsigned int max_rx_rings;
Expand Down
49 changes: 21 additions & 28 deletions drivers/net/ethernet/netronome/nfp/nfp_net_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1710,8 +1710,7 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)
}
}

if (xdp_prog && !(rxd->rxd.flags & PCIE_DESC_RX_BPF &&
dp->bpf_offload_xdp) && !meta.portid) {
if (xdp_prog && !meta.portid) {
void *orig_data = rxbuf->frag + pkt_off;
unsigned int dma_off;
int act;
Expand Down Expand Up @@ -3393,14 +3392,18 @@ 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_drv(struct nfp_net *nn, struct bpf_prog *prog,
struct netlink_ext_ack *extack)
static int nfp_net_xdp_setup_drv(struct nfp_net *nn, struct netdev_bpf *bpf)
{
struct bpf_prog *prog = bpf->prog;
struct nfp_net_dp *dp;
int err;

if (!xdp_attachment_flags_ok(&nn->xdp, bpf))
return -EBUSY;

if (!prog == !nn->dp.xdp_prog) {
WRITE_ONCE(nn->dp.xdp_prog, prog);
xdp_attachment_setup(&nn->xdp, bpf);
return 0;
}

Expand All @@ -3414,33 +3417,26 @@ nfp_net_xdp_setup_drv(struct nfp_net *nn, struct bpf_prog *prog,
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) */
return nfp_net_ring_reconfig(nn, dp, extack);
err = nfp_net_ring_reconfig(nn, dp, bpf->extack);
if (err)
return err;

xdp_attachment_setup(&nn->xdp, bpf);
return 0;
}

static int nfp_net_xdp_setup(struct nfp_net *nn, struct netdev_bpf *bpf)
static int nfp_net_xdp_setup_hw(struct nfp_net *nn, struct netdev_bpf *bpf)
{
struct bpf_prog *drv_prog, *offload_prog;
int err;

if (!xdp_attachment_flags_ok(&nn->xdp, bpf))
if (!xdp_attachment_flags_ok(&nn->xdp_hw, bpf))
return -EBUSY;

/* Load both when no flags set to allow easy activation of driver path
* when program is replaced by one which can't be offloaded.
*/
drv_prog = bpf->flags & XDP_FLAGS_HW_MODE ? NULL : bpf->prog;
offload_prog = bpf->flags & XDP_FLAGS_DRV_MODE ? NULL : bpf->prog;

err = nfp_net_xdp_setup_drv(nn, drv_prog, bpf->extack);
err = nfp_app_xdp_offload(nn->app, nn, bpf->prog, bpf->extack);
if (err)
return err;

err = nfp_app_xdp_offload(nn->app, nn, offload_prog, bpf->extack);
if (err && bpf->flags & XDP_FLAGS_HW_MODE)
return err;

xdp_attachment_setup(&nn->xdp, bpf);

xdp_attachment_setup(&nn->xdp_hw, bpf);
return 0;
}

Expand All @@ -3450,16 +3446,13 @@ static int nfp_net_xdp(struct net_device *netdev, struct netdev_bpf *xdp)

switch (xdp->command) {
case XDP_SETUP_PROG:
return nfp_net_xdp_setup_drv(nn, xdp);
case XDP_SETUP_PROG_HW:
return nfp_net_xdp_setup(nn, xdp);
return nfp_net_xdp_setup_hw(nn, xdp);
case XDP_QUERY_PROG:
if (nn->dp.bpf_offload_xdp)
return 0;
return xdp_attachment_query(&nn->xdp, xdp);
case XDP_QUERY_PROG_HW:
if (!nn->dp.bpf_offload_xdp)
return 0;
return xdp_attachment_query(&nn->xdp, xdp);
return xdp_attachment_query(&nn->xdp_hw, xdp);
default:
return nfp_app_bpf(nn->app, nn, xdp);
}
Expand Down

0 comments on commit 5f42840

Please sign in to comment.