[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190705131354.15a9313c@carbon>
Date: Fri, 5 Jul 2019 13:13:54 +0200
From: Jesper Dangaard Brouer <brouer@...hat.com>
To: Ivan Khoronzhuk <ivan.khoronzhuk@...aro.org>
Cc: grygorii.strashko@...com, davem@...emloft.net, ast@...nel.org,
linux-kernel@...r.kernel.org, linux-omap@...r.kernel.org,
ilias.apalodimas@...aro.org, netdev@...r.kernel.org,
daniel@...earbox.net, jakub.kicinski@...ronome.com,
john.fastabend@...il.com, brouer@...hat.com
Subject: Re: [PATCH v7 net-next 5/5] net: ethernet: ti: cpsw: add XDP
support
On Fri, 5 Jul 2019 02:14:06 +0300
Ivan Khoronzhuk <ivan.khoronzhuk@...aro.org> wrote:
> +static int cpsw_xdp_tx_frame(struct cpsw_priv *priv, struct xdp_frame *xdpf,
> + struct page *page)
> +{
> + struct cpsw_common *cpsw = priv->cpsw;
> + struct cpsw_meta_xdp *xmeta;
> + struct cpdma_chan *txch;
> + dma_addr_t dma;
> + int ret, port;
> +
> + xmeta = (void *)xdpf + CPSW_XMETA_OFFSET;
> + xmeta->ndev = priv->ndev;
> + xmeta->ch = 0;
> + txch = cpsw->txv[0].ch;
> +
> + port = priv->emac_port + cpsw->data.dual_emac;
> + if (page) {
> + dma = page_pool_get_dma_addr(page);
> + dma += xdpf->data - (void *)xdpf;
This code is only okay because this only happens for XDP_TX, where you
know this head-room calculation will be true. The "correct"
calculation of the head-room would be:
dma += xdpf->headroom + sizeof(struct xdp_frame);
The reason behind not using xdpf pointer itself as "data_hard_start",
is to allow struct xdp_frame to be located in another memory area.
This will be useful for e.g. AF_XDP transmit, or other zero-copy
transmit to go through ndo_xdp_xmit() (as we don't want userspace to
be-able to e.g. "race" change xdpf->len during transmit/DMA-completion).
> + ret = cpdma_chan_submit_mapped(txch, cpsw_xdpf_to_handle(xdpf),
> + dma, xdpf->len, port);
> + } else {
> + if (sizeof(*xmeta) > xdpf->headroom) {
> + xdp_return_frame_rx_napi(xdpf);
> + return -EINVAL;
> + }
> +
> + ret = cpdma_chan_submit(txch, cpsw_xdpf_to_handle(xdpf),
> + xdpf->data, xdpf->len, port);
> + }
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
Powered by blists - more mailing lists