netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: Jakub Kicinski <jakub.kicinski@netronome.com>,
	netdev@vger.kernel.org, lorenzo.bianconi@redhat.com,
	davem@davemloft.net, thomas.petazzoni@bootlin.com,
	brouer@redhat.com, matteo.croce@redhat.com, mw@semihalf.com
Subject: Re: [PATCH v3 net-next 8/8] net: mvneta: add XDP_TX support
Date: Wed, 16 Oct 2019 13:55:06 +0300	[thread overview]
Message-ID: <20191016105506.GA19689@apalos.home> (raw)
In-Reply-To: <20191016100900.GE2638@localhost.localdomain>

On Wed, Oct 16, 2019 at 12:09:00PM +0200, Lorenzo Bianconi wrote:
> > On Mon, 14 Oct 2019 12:49:55 +0200, Lorenzo Bianconi wrote:
> > > Implement XDP_TX verdict and ndo_xdp_xmit net_device_ops function
> > > pointer
> > > 
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > 
> > > @@ -1972,6 +1975,109 @@ int mvneta_rx_refill_queue(struct mvneta_port *pp, struct mvneta_rx_queue *rxq)
> > >  	return i;
> > >  }
> > >  
> > > +static int
> > > +mvneta_xdp_submit_frame(struct mvneta_port *pp, struct mvneta_tx_queue *txq,
> > > +			struct xdp_frame *xdpf, bool dma_map)
> > > +{
> > > +	struct mvneta_tx_desc *tx_desc;
> > > +	struct mvneta_tx_buf *buf;
> > > +	dma_addr_t dma_addr;
> > > +
> > > +	if (txq->count >= txq->tx_stop_threshold)
> > > +		return MVNETA_XDP_CONSUMED;
> > > +
> > > +	tx_desc = mvneta_txq_next_desc_get(txq);
> > > +
> > > +	buf = &txq->buf[txq->txq_put_index];
> > > +	if (dma_map) {
> > > +		/* ndo_xdp_xmit */
> > > +		dma_addr = dma_map_single(pp->dev->dev.parent, xdpf->data,
> > > +					  xdpf->len, DMA_TO_DEVICE);
> > > +		if (dma_mapping_error(pp->dev->dev.parent, dma_addr)) {
> > > +			mvneta_txq_desc_put(txq);
> > > +			return MVNETA_XDP_CONSUMED;
> > > +		}
> > > +		buf->type = MVNETA_TYPE_XDP_NDO;
> > > +	} else {
> > > +		struct page *page = virt_to_page(xdpf->data);
> > > +
> > > +		dma_addr = page_pool_get_dma_addr(page) +
> > > +			   pp->rx_offset_correction + MVNETA_MH_SIZE;
> > > +		dma_sync_single_for_device(pp->dev->dev.parent, dma_addr,
> > > +					   xdpf->len, DMA_BIDIRECTIONAL);
> > 
> > This looks a little suspicious, XDP could have moved the start of frame
> > with adjust_head, right? You should also use xdpf->data to find where
> > the frame starts, no?
> 
> uhm, right..we need to update the dma_addr doing something like:
> 
> dma_addr = page_pool_get_dma_addr(page) + xdpf->data - xdpf;

Can we do  page_pool_get_dma_addr(page) + xdpf->headroom as well right?

> 
> and then use xdpf->len for dma-sync
> 
> > 
> > > +		buf->type = MVNETA_TYPE_XDP_TX;
> > > +	}
> > > +	buf->xdpf = xdpf;
> > > +
> > > +	tx_desc->command = MVNETA_TXD_FLZ_DESC;
> > > +	tx_desc->buf_phys_addr = dma_addr;
> > > +	tx_desc->data_size = xdpf->len;
> > > +
> > > +	mvneta_update_stats(pp, 1, xdpf->len, true);
> > > +	mvneta_txq_inc_put(txq);
> > > +	txq->pending++;
> > > +	txq->count++;
> > > +
> > > +	return MVNETA_XDP_TX;
> > > +}
> > > +
> > > +static int
> > > +mvneta_xdp_xmit_back(struct mvneta_port *pp, struct xdp_buff *xdp)
> > > +{
> > > +	struct xdp_frame *xdpf = convert_to_xdp_frame(xdp);
> > > +	int cpu = smp_processor_id();
> > > +	struct mvneta_tx_queue *txq;
> > > +	struct netdev_queue *nq;
> > > +	u32 ret;
> > > +
> > > +	if (unlikely(!xdpf))
> > > +		return MVNETA_XDP_CONSUMED;
> > 
> > Personally I'd prefer you haven't called a function which return code
> > has to be error checked in local variable init.
> 
> do you mean moving cpu = smp_processor_id(); after the if condition?
> 
> Regards,
> Lorenzo
> 
> > 
> > > +
> > > +	txq = &pp->txqs[cpu % txq_number];
> > > +	nq = netdev_get_tx_queue(pp->dev, txq->id);
> > > +
> > > +	__netif_tx_lock(nq, cpu);
> > > +	ret = mvneta_xdp_submit_frame(pp, txq, xdpf, false);
> > > +	if (ret == MVNETA_XDP_TX)
> > > +		mvneta_txq_pend_desc_add(pp, txq, 0);
> > > +	__netif_tx_unlock(nq);
> > > +
> > > +	return ret;
> > > +}

Thanks
/Ilias

  reply	other threads:[~2019-10-16 10:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 10:49 [PATCH v3 net-next 0/8] add XDP support to mvneta driver Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 1/8] net: mvneta: introduce mvneta_update_stats routine Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 2/8] net: mvneta: introduce page pool API for sw buffer manager Lorenzo Bianconi
2019-10-15 22:41   ` Jakub Kicinski
2019-10-16  8:32     ` Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 3/8] net: mvneta: rely on build_skb in mvneta_rx_swbm poll routine Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 4/8] net: mvneta: sync dma buffers before refilling hw queues Lorenzo Bianconi
2019-10-15 23:01   ` Jakub Kicinski
2019-10-16  9:09     ` Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 5/8] net: mvneta: add basic XDP support Lorenzo Bianconi
2019-10-14 12:48   ` Jesper Dangaard Brouer
2019-10-14 13:27     ` Lorenzo Bianconi
2019-10-15 23:20   ` Jakub Kicinski
2019-10-16  8:39     ` Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 6/8] net: mvneta: move header prefetch in mvneta_swbm_rx_frame Lorenzo Bianconi
2019-10-14 10:49 ` [PATCH v3 net-next 7/8] net: mvneta: make tx buffer array agnostic Lorenzo Bianconi
2019-10-16  0:03   ` Jakub Kicinski
2019-10-16  8:18     ` Ilias Apalodimas
2019-10-14 10:49 ` [PATCH v3 net-next 8/8] net: mvneta: add XDP_TX support Lorenzo Bianconi
2019-10-16  0:11   ` Jakub Kicinski
2019-10-16 10:09     ` Lorenzo Bianconi
2019-10-16 10:55       ` Ilias Apalodimas [this message]
2019-10-16 11:16         ` Jesper Dangaard Brouer
2019-10-16 12:00           ` Lorenzo Bianconi
2019-10-16 16:27       ` Jakub Kicinski

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=20191016105506.GA19689@apalos.home \
    --to=ilias.apalodimas@linaro.org \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=lorenzo.bianconi@redhat.com \
    --cc=lorenzo@kernel.org \
    --cc=matteo.croce@redhat.com \
    --cc=mw@semihalf.com \
    --cc=netdev@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.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 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).