From: Jakub Kicinski <kubakici@wp.pl>
To: Michael Chan <michael.chan@broadcom.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 09/10] bnxt_en: Add basic XDP support.
Date: Mon, 30 Jan 2017 21:04:14 -0800 [thread overview]
Message-ID: <20170130210345.5a00e190@cakuba> (raw)
In-Reply-To: <1485827375-20421-10-git-send-email-michael.chan@broadcom.com>
On Mon, 30 Jan 2017 20:49:34 -0500, Michael Chan wrote:
> +#ifdef CONFIG_BNXT_XDP
> +/* returns the following:
> + * true - packet consumed by XDP and new buffer is allocated.
> + * false - packet should be passed to the stack.
> + */
> +bool bnxt_rx_xdp(struct bnxt_rx_ring_info *rxr, u16 cons, void *data,
> + u8 *data_ptr, unsigned int len, dma_addr_t dma_addr,
> + u8 *event)
> +{
> + struct bpf_prog *xdp_prog = READ_ONCE(rxr->xdp_prog);
> + struct xdp_buff xdp;
> + u32 act;
> +
> + if (!xdp_prog)
> + return false;
> +
> + xdp.data = data_ptr;
> + xdp.data_end = xdp.data + len;
> + rcu_read_lock();
> + act = bpf_prog_run_xdp(xdp_prog, &xdp);
> + rcu_read_unlock();
> +
> + switch (act) {
> + case XDP_PASS:
> + return false;
> +
> + default:
> + bpf_warn_invalid_xdp_action(act);
> + /* Fall thru */
> + case XDP_DROP:
> + case XDP_ABORTED:
> + bnxt_reuse_rx_data(rxr, cons, data);
> + break;
> + }
> + return true;
> +}
It would be cool if you could populate the appropriate paths with
tracepoints Daniel added in a67edbf4fb6d ("bpf: add initial bpf
tracepoints").
> + if (netif_running(dev))
> + bnxt_close_nic(bp, true, false);
> +
> + old = xchg(&bp->xdp_prog, prog);
> + if (old)
> + bpf_prog_put(old);
> +
> + if (prog) {
> + bnxt_set_rx_skb_mode(bp, true);
> + } else {
> + bool sh = (bp->flags & BNXT_FLAG_SHARED_RINGS) ? true : false;
> + int rx, tx;
> +
> + bnxt_set_rx_skb_mode(bp, false);
> + bnxt_get_max_rings(bp, &rx, &tx, sh);
> + if (rx > 1) {
> + bp->flags &= ~BNXT_FLAG_NO_AGG_RINGS;
> + bp->dev->hw_features |= NETIF_F_LRO;
> + }
> + }
> + bp->tx_nr_rings_xdp = tx_xdp;
> + bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc + tx_xdp;
> + bp->cp_nr_rings = max_t(int, bp->tx_nr_rings, bp->rx_nr_rings);
> + bp->num_stat_ctxs = bp->cp_nr_rings;
> + bnxt_set_tpa_flags(bp);
> + bnxt_set_ring_params(bp);
> +
> + if (netif_running(dev))
> + return bnxt_open_nic(bp, true, false);
Mm.. I thought doing open/close like this and risking you won't be
able to come back up was frowned upon [1]. I must be misunderstanding
things...
[1] https://www.spinics.net/lists/netdev/msg365229.html
> +int bnxt_xdp(struct net_device *dev, struct netdev_xdp *xdp)
> +{
> + struct bnxt *bp = netdev_priv(dev);
> + int rc;
> +
> + switch (xdp->command) {
> + case XDP_SETUP_PROG:
> + rc = bnxt_xdp_set(bp, xdp->prog);
> + break;
> + case XDP_QUERY_PROG:
> + xdp->prog_attached = !!bp->xdp_prog;
> + rc = 0;
> + break;
> + default:
> + rc = -EINVAL;
> + break;
> + }
> + return rc;
> +}
Nit: why not simply return?
next prev parent reply other threads:[~2017-01-31 5:04 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 1:49 [PATCH net-next 00/10] bnxt_en: Add XDP support Michael Chan
2017-01-31 1:49 ` [PATCH net-next 01/10] bnxt_en: Refactor rx SKB function Michael Chan
2017-01-31 4:26 ` Jakub Kicinski
2017-01-31 18:27 ` David Miller
2017-01-31 1:49 ` [PATCH net-next 02/10] bnxt_en: Add bp->rx_dir field for rx buffer DMA direction Michael Chan
2017-01-31 1:49 ` [PATCH net-next 03/10] bnxt_en: Add RX page mode support Michael Chan
2017-01-31 1:49 ` [PATCH net-next 04/10] bnxt_en: Use event bit map in RX path Michael Chan
2017-01-31 1:49 ` [PATCH net-next 05/10] bnxt_en: Centralize logic to reserve rings Michael Chan
2017-01-31 1:49 ` [PATCH net-next 06/10] bnxt_en: Add tx ring mapping logic Michael Chan
2017-01-31 1:49 ` [PATCH net-next 07/10] bnxt_en: Add a set of TX rings to support XDP Michael Chan
2017-01-31 1:49 ` [PATCH net-next 08/10] bnxt_en: Refactor tx completion path Michael Chan
2017-01-31 1:49 ` [PATCH net-next 09/10] bnxt_en: Add basic XDP support Michael Chan
2017-01-31 5:04 ` Jakub Kicinski [this message]
2017-01-31 7:33 ` Michael Chan
2017-01-31 1:49 ` [PATCH net-next 10/10] bnxt_en: Add support for XDP_TX action Michael Chan
2017-01-31 5:27 ` Jakub Kicinski
2017-01-31 7:19 ` Michael Chan
2017-01-31 4:47 ` [PATCH net-next 00/10] bnxt_en: Add XDP support Alexei Starovoitov
2017-01-31 5:13 ` Jakub Kicinski
2017-01-31 7:38 ` Michael Chan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170130210345.5a00e190@cakuba \
--to=kubakici@wp.pl \
--cc=davem@davemloft.net \
--cc=michael.chan@broadcom.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).