All of lore.kernel.org
 help / color / mirror / Atom feed
From: Darek Marcinkiewicz <reksio@newterm.pl>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/1] Driver for Beckhoff CX5020 EtherCAT master module.
Date: Wed, 30 Apr 2014 07:54:18 +0200	[thread overview]
Message-ID: <20140430055418.GC20080@newterm.pl> (raw)
In-Reply-To: <20140429.154508.1310732534931361787.davem@davemloft.net>

On Tue, Apr 29, 2014 at 03:45:08PM -0400, David Miller wrote:
> From: Darek Marcinkiewicz <reksio@newterm.pl>
> Date: Mon, 28 Apr 2014 07:36:58 +0200
> 
> > +void *ec_bh_alloc_dma_mem(struct bh_priv *priv,
> > +			     int channel,
> > +			     u8 **buf,
> > +			     dma_addr_t *phys,
> > +			     dma_addr_t *phys_buf,
> > +			     size_t *len) {
> > +	u32 mask;
> > +	int offset = channel * DMA_CHAN_SIZE + DMA_CHAN_OFFSET;
> > +
> > +	iowrite32(0xffffffff, priv->dma_io + offset);
> > +
> > +	mask = ioread32(priv->dma_io + offset);
> > +	mask &= 0xfffffffc;
> > +	dev_info(PRIV_TO_DEV(priv),
> > +		 "Read mask %x for channel %d\n",
> > +		 mask, channel);
> > +	*len = ~mask + 1;
> > +
> > +	dev_info(PRIV_TO_DEV(priv),
> > +		 "Allocating %d bytes for channel %d",
> > +		 (int)*len, channel);
> > +	*buf = pci_alloc_consistent(priv->dev,
> > +				    *len * 2,
> > +				    phys_buf);
> 
> This is really confusing, the log message says that it allocates
> "*len" bytes, but actually you are allocating "*len * 2" bytes as
> per the arguments you are passing into pci_alloc_consistent.
> 
> Either one or the other is wrong, and if "*len * 2" is the correct
> size then it should be explained why you're doubling this value
> but providing just plain "*len" to the caller.
> 
> All of these *len values seem to be doubled over and over again,
> in the memset() calls, in the pci_free_consistent() calls during
> resource release on probe error and driver shutdown.
> 
> Why not just assign X * 2 to *len and get rid of this doubling all
> over the place?
> 
This device imposes some limitations on location and size of the buffers
that it dma data from/to. It has a "mask" parameter saying two things:
1. RX/TX buffers have to be aligned to "mask" bits.
2. Their max size is 2^mask.
In order to have a buffer meeting above criteria driver allocates
chunk of size 2 * max buffer size, and half of this chunk gets
used later on. So, len here is the size of that aligned buffer, whereas
2 * len is how much memory was actually allocated. 

So, yes, this is a little bit confusing. I'll try to clean this up
a little bit and send updated patch.

Thank you!

-- 
DM


  reply	other threads:[~2014-04-30  5:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-28  5:36 [PATCH v2 1/1] Driver for Beckhoff CX5020 EtherCAT master module Darek Marcinkiewicz
2014-04-29 19:45 ` David Miller
2014-04-30  5:54   ` Darek Marcinkiewicz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-04-24 20:46 [PATCH " Darek Marcinkiewicz
2014-04-26 16:24 ` David Miller
2014-04-27 21:10   ` [PATCH v2 " Darek Marcinkiewicz
2014-04-27 22:21     ` David Miller
2014-04-29 17:03       ` Darek Marcinkiewicz

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=20140430055418.GC20080@newterm.pl \
    --to=reksio@newterm.pl \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.