From: thomas.petazzoni@free-electrons.com (Thomas Petazzoni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4] Network driver for the Armada 370 and Armada XP ARM Marvell SoCs
Date: Tue, 13 Nov 2012 12:34:19 +0100 [thread overview]
Message-ID: <20121113123419.4516b4b8@skate> (raw)
In-Reply-To: <20121103115321.GA4539@electric-eye.fr.zoreil.com>
Fran?ois,
Thanks for your detailed review. I have a few comments/questions below
on specific topics.
On Sat, 3 Nov 2012 12:53:21 +0100, Francois Romieu wrote:
> > + if (rxq->descs == NULL) {
> > + netdev_err(pp->dev,
> > + "rxQ=%d: Can't allocate %d bytes for %d RX descr\n",
> > + rxq->id, rxq->size * MVNETA_DESC_ALIGNED_SIZE,
> > + rxq->size);
> > + return -ENOMEM;
> > + }
> > +
> > + BUG_ON(rxq->descs !=
> > + PTR_ALIGN(rxq->descs, MVNETA_CPU_D_CACHE_LINE_SIZE));
>
> There is no reason to crash.
Well, there is a reason: the hardware will not work properly if
rxq->descs is not aligned on a MVNETA_CPU_D_CACHE_LINE_SIZE boundary.
So one solution is to over-allocated to guarantee the alignment, but
since practically speaking MVNETA_CPU_D_CACHE_LINE_SIZE=32 and
dma_alloc_coherent() returns things that seem at least 32 bytes
aligned, it sounded overkill to include more code to fix a problem that
doesn't exist. This BUG_ON() is here solely for the purpose of noisily
letting the user know if this implicit assumption on the alignment of
dma_alloc_coherent() allocated buffer changes in the future. I can turn
this into an error if you prefer:
if (rxq->descs != PTR_ALIGN(rxq->descs, MVNETA_CPU_D_CACHE_LINE_SIZE)) {
netdev_err(pp->dev, "improper buffer alignement assumption, driver needs fixing\n");
dma_free_coherent(...);
return -EINVAL;
}
> (...]
> > +static int mvneta_txq_init(struct mvneta_port *pp,
> > + struct mvneta_tx_queue *txq)
> > +{
> > + txq->size = pp->tx_ring_size;
> > +
> > + /* Allocate memory for TX descriptors */
> > + txq->descs = dma_alloc_coherent(pp->dev->dev.parent,
> > + txq->size * MVNETA_DESC_ALIGNED_SIZE,
> > + &txq->descs_phys,
> > + DMA_BIDIRECTIONAL);
>
> &txq->descs_phys, DMA_BIDIRECTIONAL);
Aaah, thanks for pointing this one! It should have been GFP_KERNEL, not
DMA_BIDIRECTIONAL here.
> > + if (txq->descs == NULL) {
> > + netdev_err(pp->dev,
> > + "txQ=%d: Can't allocate %d bytes for %d TX descr\n",
> > + txq->id, txq->size * MVNETA_DESC_ALIGNED_SIZE,
> > + txq->size);
> > + return -ENOMEM;
> > + }
> > +
> > + /* Make sure descriptor address is cache line size aligned */
> > + BUG_ON(txq->descs !=
> > + PTR_ALIGN(txq->descs, MVNETA_CPU_D_CACHE_LINE_SIZE));
>
> There is no reason to crash.
Same as above :-)
> [...]
> > +static int mvneta_setup_rxqs(struct mvneta_port *pp)
> > +{
> > + int queue;
> > +
> > + for (queue = 0; queue < rxq_number; queue++) {
> > + int err = mvneta_rxq_init(pp, &pp->rxqs[queue]);
> > + if (err) {
> > + netdev_err(pp->dev,
> > + "%s: can't create RxQ rxq=%d\n",
>
> netdev_err(pp->dev, "%s: can't create RxQ rxq=%d\n",
>
> > + __func__, queue);
> > + mvneta_cleanup_rxqs(pp);
> > + return -ENODEV;
>
> mvneta_rxq_init should return a proper error code and it should be
> propagated (option: break instead of return and mvneta_setup_rxqs scoped
> err variable)
Besides turning the "return -ENODEV;" into "return err;", I don't see
what is the other problem here? mvneta_rxq_init() properly returns
-ENOMEM where there is a memory allocation failure, and
mvneta_cleanup_rxqs() properly cleans up *all* initialized rxqs. Is
there something I'm missing?
Thanks again for your review!
Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
prev parent reply other threads:[~2012-11-13 11:34 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-26 10:03 [PATCH v4] Network driver for the Armada 370 and Armada XP ARM Marvell SoCs Thomas Petazzoni
2012-10-26 10:03 ` [PATCH 1/4] net: mvneta: driver for Marvell Armada 370/XP network unit Thomas Petazzoni
2012-10-30 12:07 ` Nobuhiro Iwamatsu
2012-10-30 12:28 ` Thomas Petazzoni
2012-10-31 11:12 ` Florian Fainelli
2012-10-26 10:03 ` [PATCH 2/4] net: mvneta: update MAINTAINERS file for the mvneta maintainers Thomas Petazzoni
2012-10-26 10:03 ` [PATCH 3/4] arm: mvebu: add Ethernet controllers using mvneta driver for Armada 370/XP Thomas Petazzoni
2012-10-30 4:19 ` Nobuhiro Iwamatsu
2012-10-30 8:36 ` Thomas Petazzoni
2012-10-26 10:03 ` [PATCH 4/4] arm: mvebu: enable Ethernet controllers on Armada 370/XP eval boards Thomas Petazzoni
2012-11-04 2:03 ` [4/4] " Jason Gunthorpe
2012-11-04 9:12 ` Thomas Petazzoni
2012-11-12 17:30 ` Thomas Petazzoni
2012-10-30 9:51 ` [PATCH v4] Network driver for the Armada 370 and Armada XP ARM Marvell SoCs Thomas Petazzoni
2012-11-02 22:21 ` Thomas Petazzoni
2012-11-03 11:53 ` Francois Romieu
2012-11-12 17:58 ` Thomas Petazzoni
2012-11-13 11:34 ` Thomas Petazzoni [this message]
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=20121113123419.4516b4b8@skate \
--to=thomas.petazzoni@free-electrons.com \
--cc=linux-arm-kernel@lists.infradead.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 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.