* @dp: NFP Net data path struct
* @rx_ring: RX ring structure of the skb
* @dma_addr: Pointer to storage for DMA address (output param)
- * @xdp: Whether XDP is enabled
*
* This function will allcate a new page frag, map it for DMA.
*
* Return: allocated page frag or NULL on failure.
*/
static void *
-nfp_net_rx_alloc_one(struct nfp_net_dp *dp,
- struct nfp_net_rx_ring *rx_ring, dma_addr_t *dma_addr,
- bool xdp)
+nfp_net_rx_alloc_one(struct nfp_net_dp *dp, struct nfp_net_rx_ring *rx_ring,
+ dma_addr_t *dma_addr)
{
int direction;
void *frag;
- if (!xdp)
+ if (!dp->xdp_prog)
frag = netdev_alloc_frag(dp->fl_bufsz);
else
frag = page_address(alloc_page(GFP_KERNEL | __GFP_COLD));
return NULL;
}
- direction = xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
+ direction = dp->xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
*dma_addr = nfp_net_dma_map_rx(dp, frag, direction);
if (dma_mapping_error(dp->dev, *dma_addr)) {
- nfp_net_free_frag(frag, xdp);
+ nfp_net_free_frag(frag, dp->xdp_prog);
nn_dp_warn(dp, "Failed to map DMA RX buffer\n");
return NULL;
}
* nfp_net_rx_ring_bufs_free() - Free any buffers currently on the RX ring
* @dp: NFP Net data path struct
* @rx_ring: RX ring to remove buffers from
- * @xdp: Whether XDP is enabled
*
* Assumes that the device is stopped and buffers are in [0, ring->cnt - 1)
* entries. After device is disabled nfp_net_rx_ring_reset() must be called
*/
static void
nfp_net_rx_ring_bufs_free(struct nfp_net_dp *dp,
- struct nfp_net_rx_ring *rx_ring, bool xdp)
+ struct nfp_net_rx_ring *rx_ring)
{
- int direction = xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
+ int direction = dp->xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;
unsigned int i;
for (i = 0; i < rx_ring->cnt - 1; i++) {
nfp_net_dma_unmap_rx(dp, rx_ring->rxbufs[i].dma_addr,
direction);
- nfp_net_free_frag(rx_ring->rxbufs[i].frag, xdp);
+ nfp_net_free_frag(rx_ring->rxbufs[i].frag, dp->xdp_prog);
rx_ring->rxbufs[i].dma_addr = 0;
rx_ring->rxbufs[i].frag = NULL;
}
* nfp_net_rx_ring_bufs_alloc() - Fill RX ring with buffers (don't give to FW)
* @dp: NFP Net data path struct
* @rx_ring: RX ring to remove buffers from
- * @xdp: Whether XDP is enabled
*/
static int
nfp_net_rx_ring_bufs_alloc(struct nfp_net_dp *dp,
- struct nfp_net_rx_ring *rx_ring, bool xdp)
+ struct nfp_net_rx_ring *rx_ring)
{
struct nfp_net_rx_buf *rxbufs;
unsigned int i;
for (i = 0; i < rx_ring->cnt - 1; i++) {
rxbufs[i].frag =
- nfp_net_rx_alloc_one(dp, rx_ring, &rxbufs[i].dma_addr,
- xdp);
+ nfp_net_rx_alloc_one(dp, rx_ring, &rxbufs[i].dma_addr);
if (!rxbufs[i].frag) {
- nfp_net_rx_ring_bufs_free(dp, rx_ring, xdp);
+ nfp_net_rx_ring_bufs_free(dp, rx_ring);
return -ENOMEM;
}
}
static struct nfp_net_rx_ring *
nfp_net_rx_ring_set_prepare(struct nfp_net *nn, struct nfp_net_dp *dp,
- struct nfp_net_ring_set *s, bool xdp)
+ struct nfp_net_ring_set *s)
{
struct nfp_net_rx_ring *rings;
unsigned int r;
if (nfp_net_rx_ring_alloc(dp, &rings[r], s->dcnt))
goto err_free_prev;
- if (nfp_net_rx_ring_bufs_alloc(dp, &rings[r], xdp))
+ if (nfp_net_rx_ring_bufs_alloc(dp, &rings[r]))
goto err_free_ring;
}
err_free_prev:
while (r--) {
- nfp_net_rx_ring_bufs_free(dp, &rings[r], xdp);
+ nfp_net_rx_ring_bufs_free(dp, &rings[r]);
err_free_ring:
nfp_net_rx_ring_free(&rings[r]);
}
}
static void
-nfp_net_rx_ring_set_free(struct nfp_net_dp *dp, struct nfp_net_ring_set *s,
- bool xdp)
+nfp_net_rx_ring_set_free(struct nfp_net_dp *dp, struct nfp_net_ring_set *s)
{
struct nfp_net_rx_ring *rings = s->rings;
unsigned int r;
for (r = 0; r < s->n_rings; r++) {
- nfp_net_rx_ring_bufs_free(dp, &rings[r], xdp);
+ nfp_net_rx_ring_bufs_free(dp, &rings[r]);
nfp_net_rx_ring_free(&rings[r]);
}
goto err_cleanup_vec_p;
}
- nn->dp.rx_rings = nfp_net_rx_ring_set_prepare(nn, &nn->dp, &rx,
- nn->dp.xdp_prog);
+ nn->dp.rx_rings = nfp_net_rx_ring_set_prepare(nn, &nn->dp, &rx);
if (!nn->dp.rx_rings) {
err = -ENOMEM;
goto err_cleanup_vec;
err_free_rings:
nfp_net_tx_ring_set_free(&tx);
err_free_rx_rings:
- nfp_net_rx_ring_set_free(&nn->dp, &rx, nn->dp.xdp_prog);
+ nfp_net_rx_ring_set_free(&nn->dp, &rx);
err_cleanup_vec:
r = nn->dp.num_r_vecs;
err_cleanup_vec_p:
unsigned int r;
for (r = 0; r < nn->dp.num_rx_rings; r++) {
- nfp_net_rx_ring_bufs_free(&nn->dp, &nn->dp.rx_rings[r],
- nn->dp.xdp_prog);
+ nfp_net_rx_ring_bufs_free(&nn->dp, &nn->dp.rx_rings[r]);
nfp_net_rx_ring_free(&nn->dp.rx_rings[r]);
}
for (r = 0; r < nn->dp.num_tx_rings; r++)
static int
nfp_net_ring_swap_enable(struct nfp_net *nn, struct nfp_net_dp *dp,
- struct bpf_prog **xdp_prog,
struct nfp_net_ring_set *rx,
struct nfp_net_ring_set *tx)
{
swap(dp->num_r_vecs, nn->dp.num_r_vecs);
swap(dp->num_stack_tx_rings, nn->dp.num_stack_tx_rings);
- *xdp_prog = xchg(&nn->dp.xdp_prog, *xdp_prog);
+ dp->xdp_prog = xchg(&nn->dp.xdp_prog, dp->xdp_prog);
for (r = 0; r < nn->max_r_vecs; r++)
nfp_net_vector_assign_rings(&nn->dp, &nn->r_vecs[r], r);
static int
nfp_net_check_config(struct nfp_net *nn, struct nfp_net_dp *dp,
- struct bpf_prog *xdp_prog,
struct nfp_net_ring_set *rx, struct nfp_net_ring_set *tx)
{
/* XDP-enabled tests */
- if (!xdp_prog)
+ if (!dp->xdp_prog)
return 0;
if (dp->fl_bufsz > PAGE_SIZE) {
nn_warn(nn, "MTU too large w/ XDP enabled\n");
static void
nfp_net_ring_reconfig_down(struct nfp_net *nn, struct nfp_net_dp *dp,
- struct bpf_prog **xdp_prog,
struct nfp_net_ring_set *rx,
struct nfp_net_ring_set *tx)
{
nn->dp.txd_cnt = tx ? tx->dcnt : nn->dp.txd_cnt;
nn->dp.num_rx_rings = rx ? rx->n_rings : nn->dp.num_rx_rings;
nn->dp.num_tx_rings = tx ? tx->n_rings : nn->dp.num_tx_rings;
- *xdp_prog = xchg(&nn->dp.xdp_prog, *xdp_prog);
if (!netif_is_rxfh_configured(nn->dp.netdev))
nfp_net_rss_init_itbl(nn);
int
nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *dp,
- struct bpf_prog **xdp_prog,
struct nfp_net_ring_set *rx, struct nfp_net_ring_set *tx)
{
int r, err;
dp->fl_bufsz = nfp_net_calc_fl_bufsz(dp);
dp->num_stack_tx_rings = tx ? tx->n_rings : dp->num_tx_rings;
- if (*xdp_prog)
+ if (dp->xdp_prog)
dp->num_stack_tx_rings -= rx ? rx->n_rings : dp->num_rx_rings;
dp->num_r_vecs = max(rx ? rx->n_rings : dp->num_rx_rings,
dp->num_stack_tx_rings);
- err = nfp_net_check_config(nn, dp, *xdp_prog, rx, tx);
+ err = nfp_net_check_config(nn, dp, rx, tx);
if (err)
goto exit_free_dp;
if (!netif_running(dp->netdev)) {
- nfp_net_ring_reconfig_down(nn, dp, xdp_prog, rx, tx);
+ nfp_net_ring_reconfig_down(nn, dp, rx, tx);
err = 0;
goto exit_free_dp;
}
}
if (rx) {
- if (!nfp_net_rx_ring_set_prepare(nn, dp, rx, *xdp_prog)) {
+ if (!nfp_net_rx_ring_set_prepare(nn, dp, rx)) {
err = -ENOMEM;
goto err_cleanup_vecs;
}
nfp_net_close_stack(nn);
nfp_net_clear_config_and_disable(nn);
- err = nfp_net_ring_swap_enable(nn, dp, xdp_prog, rx, tx);
+ err = nfp_net_ring_swap_enable(nn, dp, rx, tx);
if (err) {
int err2;
nfp_net_clear_config_and_disable(nn);
/* Try with old configuration and old rings */
- err2 = nfp_net_ring_swap_enable(nn, dp, xdp_prog, rx, tx);
+ err2 = nfp_net_ring_swap_enable(nn, dp, rx, tx);
if (err2)
nn_err(nn, "Can't restore ring config - FW communication failed (%d,%d)\n",
err, err2);
nfp_net_cleanup_vector(nn, &nn->r_vecs[r]);
if (rx)
- nfp_net_rx_ring_set_free(dp, rx, *xdp_prog);
+ nfp_net_rx_ring_set_free(dp, rx);
if (tx)
nfp_net_tx_ring_set_free(tx);
err_free_rx:
if (rx)
- nfp_net_rx_ring_set_free(dp, rx, *xdp_prog);
+ nfp_net_rx_ring_set_free(dp, rx);
err_cleanup_vecs:
for (r = dp->num_r_vecs - 1; r >= nn->dp.num_r_vecs; r--)
nfp_net_cleanup_vector(nn, &nn->r_vecs[r]);
dp->mtu = new_mtu;
- return nfp_net_ring_reconfig(nn, dp, &nn->dp.xdp_prog, &rx, NULL);
+ return nfp_net_ring_reconfig(nn, dp, &rx, NULL);
}
static void nfp_net_stat64(struct net_device *netdev,
static int nfp_net_xdp_setup(struct nfp_net *nn, struct bpf_prog *prog)
{
+ struct bpf_prog *old_prog = nn->dp.xdp_prog;
struct nfp_net_ring_set rx = {
.n_rings = nn->dp.num_rx_rings,
.dcnt = nn->dp.rxd_cnt,
if (!dp)
return -ENOMEM;
+ dp->xdp_prog = prog;
tx.n_rings += prog ? nn->dp.num_rx_rings : -nn->dp.num_rx_rings;
/* We need RX reconfig to remap the buffers (BIDIR vs FROM_DEV) */
- err = nfp_net_ring_reconfig(nn, dp, &prog, &rx, &tx);
+ err = nfp_net_ring_reconfig(nn, dp, &rx, &tx);
if (err)
return err;
- /* @prog got swapped and is now the old one */
- if (prog)
- bpf_prog_put(prog);
+ if (old_prog)
+ bpf_prog_put(old_prog);
nfp_net_xdp_offload(nn, nn->dp.xdp_prog);