All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Ioana Ciornei <ioana.ciornei@nxp.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"davem@davemloft.net" <davem@davemloft.net>,
	Ioana Ciocoi Radulescu <ruxandra.radulescu@nxp.com>,
	"ilias.apalodimas@linaro.org" <ilias.apalodimas@linaro.org>,
	"toke@redhat.com" <toke@redhat.com>,
	brouer@redhat.com
Subject: Re: [PATCH v2 2/2] dpaa2-eth: add XDP_REDIRECT support
Date: Mon, 4 Mar 2019 13:29:37 +0100	[thread overview]
Message-ID: <20190304132937.65efdfed@carbon> (raw)
In-Reply-To: <1551462396-5115-3-git-send-email-ioana.ciornei@nxp.com>

On Fri, 1 Mar 2019 17:47:24 +0000
Ioana Ciornei <ioana.ciornei@nxp.com> wrote:

> +static int dpaa2_eth_xdp_xmit_frame(struct net_device *net_dev,
> +				    struct xdp_frame *xdpf)
> +{
> +	struct dpaa2_eth_priv *priv = netdev_priv(net_dev);
> +	struct device *dev = net_dev->dev.parent;
> +	struct rtnl_link_stats64 *percpu_stats;
> +	struct dpaa2_eth_drv_stats *percpu_extras;
> +	unsigned int needed_headroom;
> +	struct dpaa2_eth_swa *swa;
> +	struct dpaa2_eth_fq *fq;
> +	struct dpaa2_fd fd;
> +	void *buffer_start, *aligned_start;
> +	dma_addr_t addr;
> +	int err, i;
> +
> +	/* We require a minimum headroom to be able to transmit the frame.
> +	 * Otherwise return an error and let the original net_device handle it
> +	 */
> +	needed_headroom = dpaa2_eth_needed_headroom(priv, NULL);
> +	if (xdpf->headroom < needed_headroom)
> +		return -EINVAL;
> +
> +	percpu_stats = this_cpu_ptr(priv->percpu_stats);
> +	percpu_extras = this_cpu_ptr(priv->percpu_extras);
> +
> +	/* Setup the FD fields */
> +	memset(&fd, 0, sizeof(fd));
> +
> +	/* Align FD address, if possible */
> +	buffer_start = xdpf->data - needed_headroom;
> +	aligned_start = PTR_ALIGN(buffer_start - DPAA2_ETH_TX_BUF_ALIGN,
> +				  DPAA2_ETH_TX_BUF_ALIGN);
> +	if (aligned_start >= xdpf->data - xdpf->headroom)
> +		buffer_start = aligned_start;
> +
> +	swa = (struct dpaa2_eth_swa *)buffer_start;
> +	/* fill in necessary fields here */
> +	swa->type = DPAA2_ETH_SWA_XDP;
> +	swa->xdp.dma_size = xdpf->data + xdpf->len - buffer_start;
> +	swa->xdp.xdpf = xdpf;
> +
> +	addr = dma_map_single(dev, buffer_start,
> +			      swa->xdp.dma_size,
> +			      DMA_BIDIRECTIONAL);
> +	if (unlikely(dma_mapping_error(dev, addr))) {
> +		percpu_stats->tx_dropped++;
> +		return -ENOMEM;
> +	}
> +
> +	dpaa2_fd_set_addr(&fd, addr);
> +	dpaa2_fd_set_offset(&fd, xdpf->data - buffer_start);
> +	dpaa2_fd_set_len(&fd, xdpf->len);
> +	dpaa2_fd_set_format(&fd, dpaa2_fd_single);
> +	dpaa2_fd_set_ctrl(&fd, FD_CTRL_PTA);
> +
> +	fq = &priv->fq[smp_processor_id()];

It is guaranteed that you have one FQ per CPU in the system?

> +	for (i = 0; i < DPAA2_ETH_ENQUEUE_RETRIES; i++) {
> +		err = priv->enqueue(priv, fq, &fd, 0);
> +		if (err != -EBUSY)
> +			break;


-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

  reply	other threads:[~2019-03-04 12:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01 17:47 [PATCH v2 0/2] dpaa2-eth: add XDP_REDIRECT support Ioana Ciornei
2019-03-01 17:47 ` [PATCH v2 1/2] dpaa2-eth: Add software annotation types Ioana Ciornei
2019-03-01 17:47 ` [PATCH v2 2/2] dpaa2-eth: add XDP_REDIRECT support Ioana Ciornei
2019-03-04 12:29   ` Jesper Dangaard Brouer [this message]
2019-03-04 12:56     ` Ioana Ciocoi Radulescu
2019-03-04  4:41 ` [PATCH v2 0/2] " David Miller

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=20190304132937.65efdfed@carbon \
    --to=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ilias.apalodimas@linaro.org \
    --cc=ioana.ciornei@nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=ruxandra.radulescu@nxp.com \
    --cc=toke@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.