All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: linux-mtd@lists.infradead.org, devicetree@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Marek Vasut <marek.vasut@gmail.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Richard Weinberger <richard@nod.at>,
	David Woodhouse <dwmw2@infradead.org>,
	Cyrille Pitchen <cyrille.pitchen@atmel.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH 00/39] mtd: nand: denali: 2nd round of Denali NAND IP patch bomb
Date: Mon, 13 Mar 2017 12:33:22 +0100	[thread overview]
Message-ID: <20170313123322.06475e5c@bbrezillon> (raw)
In-Reply-To: <CAK7LNAQxTSJT3szu46pQfBXGmenAexMWo8GyjmHsnXVmht4mOA@mail.gmail.com>

Hi Masahiro,

On Fri, 10 Mar 2017 20:00:03 +0900
Masahiro Yamada <yamada.masahiro@socionext.com> wrote:

> Hi Boris,
> 
> I am almost getting v2 done,
> and now I am testing it.
> 
> I am having one problem.  Please teach me.
> 
> 
> 2016-11-30 17:17 GMT+09:00 Boris Brezillon <boris.brezillon@free-electrons.com>:
> >> [2]
> >> Remove driver-internal bounce buffer.
> >> The current Denali driver allocate DMA_BIDIRECTIONAL buffer
> >> to use it as a driver-internal bounce buffer.
> >>
> >> The hardware transfer page data into the bounce buffer,
> >> then CPU copies from the bounce buffer to a given buf (and oob_poi).
> >> This is not efficient.
> >>
> >> So, I want to set NAND_USE_BOUNCE_BUFFER flag
> >> and do dma_map_single directly for a given buffer.  
> >
> > Sounds good. Be careful though, when you use the generic bounce buffer
> > interface you might have to clear the page cache info (->pagebuf = -1).  
> 
> 
> Instead of memcpy() of the whole page,
> I am trying to use dma_map_single()  in ecc->read_page() / ecc->write_page().
> This will allow direct transfer between the buffer and the device by DMA.
> 
> But, this does not work for Denali if use_bufpoi is set in nand_do_read_ops().
> 
> 
> In the following code in nand_scan_tail(),
> 
>         if (!(chip->options & NAND_OWN_BUFFERS)) {
>                 nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
>                                 + mtd->oobsize * 3, GFP_KERNEL);
>                 if (!nbuf)
>                         return -ENOMEM;
>                 nbuf->ecccalc = (uint8_t *)(nbuf + 1);
>                 nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
>                 nbuf->databuf = nbuf->ecccode + mtd->oobsize;
> 
>                 chip->buffers = nbuf;
> 
> 
> chip->buffers->databuf has no guarantee for DMA'able alignment.
> (actually it has unwanted offset 0xc because sizeof(*nbuf) == 0xc on
> 32bit systems)

Well, I think the DMA alignment requirement is a platform/controller
specific (some controllers are fine with this 32bits alignment), but I
get your point.

> 
> If we could change the code as follows,
> 
>                 nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>                 nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>                 nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize,
> GFP_KERNEL);
> 
> chip->buffers->databuf would have DMA'able alignment in most cases
> without NAND_OWN_BUFFERS.  (but, I am not sure if this is a good idea)

I'm fine with this change. I don't know what are the guarantees in term
of alignment when you use kmalloc, but I guess the size you're
allocating (writesize + oobsize) kind of guarantees that the alignment
is rather big (because the SLAB caches are organized by power-of-2
chunk sizes, and for allocations >PAGE_SIZE the page allocator will be
used).

> 
> 
> So, the idea of NAND_OWN_BUFFERS is that
> drivers should allocate own buffers if they need to perform DMA-mapping
> in read_page(), write_page(), right?

Right.

> 
> 
> However, "git grep NAND_OWN_BUFFERS" shows
> cafe_nand.c is the only driver that does so.
> 
> On the other hand, "git grep dma_map_single" has more hits,
> i.e. some drivers perform dma_map_single() for read/write without
> NAND_OWN_BUFFERS.
> 
> I have no idea how they are working.

Probably because the controllers and/or DMA engines have no alignment
constraints.

Anyway, the change you're proposing is rather simple, so go ahead.

Regards,

Boris

WARNING: multiple messages have this Message-ID (diff)
From: Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
To: Masahiro Yamada
	<yamada.masahiro-uWyLwvC0a2jby3iVrkZq2A@public.gmane.org>
Cc: linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Kernel Mailing List
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Marek Vasut <marek.vasut-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Brian Norris
	<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Richard Weinberger <richard-/L3Ra7n9ekc@public.gmane.org>,
	David Woodhouse <dwmw2-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>,
	Cyrille Pitchen
	<cyrille.pitchen-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Andy Shevchenko
	<andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Subject: Re: [PATCH 00/39] mtd: nand: denali: 2nd round of Denali NAND IP patch bomb
Date: Mon, 13 Mar 2017 12:33:22 +0100	[thread overview]
Message-ID: <20170313123322.06475e5c@bbrezillon> (raw)
In-Reply-To: <CAK7LNAQxTSJT3szu46pQfBXGmenAexMWo8GyjmHsnXVmht4mOA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi Masahiro,

On Fri, 10 Mar 2017 20:00:03 +0900
Masahiro Yamada <yamada.masahiro-uWyLwvC0a2jby3iVrkZq2A@public.gmane.org> wrote:

> Hi Boris,
> 
> I am almost getting v2 done,
> and now I am testing it.
> 
> I am having one problem.  Please teach me.
> 
> 
> 2016-11-30 17:17 GMT+09:00 Boris Brezillon <boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>:
> >> [2]
> >> Remove driver-internal bounce buffer.
> >> The current Denali driver allocate DMA_BIDIRECTIONAL buffer
> >> to use it as a driver-internal bounce buffer.
> >>
> >> The hardware transfer page data into the bounce buffer,
> >> then CPU copies from the bounce buffer to a given buf (and oob_poi).
> >> This is not efficient.
> >>
> >> So, I want to set NAND_USE_BOUNCE_BUFFER flag
> >> and do dma_map_single directly for a given buffer.  
> >
> > Sounds good. Be careful though, when you use the generic bounce buffer
> > interface you might have to clear the page cache info (->pagebuf = -1).  
> 
> 
> Instead of memcpy() of the whole page,
> I am trying to use dma_map_single()  in ecc->read_page() / ecc->write_page().
> This will allow direct transfer between the buffer and the device by DMA.
> 
> But, this does not work for Denali if use_bufpoi is set in nand_do_read_ops().
> 
> 
> In the following code in nand_scan_tail(),
> 
>         if (!(chip->options & NAND_OWN_BUFFERS)) {
>                 nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize
>                                 + mtd->oobsize * 3, GFP_KERNEL);
>                 if (!nbuf)
>                         return -ENOMEM;
>                 nbuf->ecccalc = (uint8_t *)(nbuf + 1);
>                 nbuf->ecccode = nbuf->ecccalc + mtd->oobsize;
>                 nbuf->databuf = nbuf->ecccode + mtd->oobsize;
> 
>                 chip->buffers = nbuf;
> 
> 
> chip->buffers->databuf has no guarantee for DMA'able alignment.
> (actually it has unwanted offset 0xc because sizeof(*nbuf) == 0xc on
> 32bit systems)

Well, I think the DMA alignment requirement is a platform/controller
specific (some controllers are fine with this 32bits alignment), but I
get your point.

> 
> If we could change the code as follows,
> 
>                 nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>                 nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>                 nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize,
> GFP_KERNEL);
> 
> chip->buffers->databuf would have DMA'able alignment in most cases
> without NAND_OWN_BUFFERS.  (but, I am not sure if this is a good idea)

I'm fine with this change. I don't know what are the guarantees in term
of alignment when you use kmalloc, but I guess the size you're
allocating (writesize + oobsize) kind of guarantees that the alignment
is rather big (because the SLAB caches are organized by power-of-2
chunk sizes, and for allocations >PAGE_SIZE the page allocator will be
used).

> 
> 
> So, the idea of NAND_OWN_BUFFERS is that
> drivers should allocate own buffers if they need to perform DMA-mapping
> in read_page(), write_page(), right?

Right.

> 
> 
> However, "git grep NAND_OWN_BUFFERS" shows
> cafe_nand.c is the only driver that does so.
> 
> On the other hand, "git grep dma_map_single" has more hits,
> i.e. some drivers perform dma_map_single() for read/write without
> NAND_OWN_BUFFERS.
> 
> I have no idea how they are working.

Probably because the controllers and/or DMA engines have no alignment
constraints.

Anyway, the change you're proposing is rather simple, so go ahead.

Regards,

Boris

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-03-13 11:33 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-26 18:05 [PATCH 00/39] mtd: nand: denali: 2nd round of Denali NAND IP patch bomb Masahiro Yamada
2016-11-26 18:05 ` [PATCH 01/39] mtd: nand: allow to set only one of ECC size and ECC strength from DT Masahiro Yamada
2016-11-27 13:58   ` Boris Brezillon
2016-11-26 18:05 ` [PATCH 02/39] mtd: nand: denali: remove unused CONFIG option and macros Masahiro Yamada
2016-11-26 18:05 ` [PATCH 03/39] mtd: nand: denali: remove redundant define of BANK(x) Masahiro Yamada
2016-11-26 18:05 ` [PATCH 04/39] mtd: nand: denali: remove more unused struct members Masahiro Yamada
2016-11-27 15:12   ` Boris Brezillon
2016-11-30  7:16     ` Masahiro Yamada
2016-11-30  7:47       ` Boris Brezillon
2016-11-26 18:05 ` [PATCH 05/39] mtd: nand: denali: fix comment of denali_nand_info::flash_mem Masahiro Yamada
2016-11-26 18:05 ` [PATCH 06/39] mtd: nand: denali: fix write_oob_data() function Masahiro Yamada
2016-11-26 18:05 ` [PATCH 07/39] mtd: nand: denali: transfer OOB only when oob_required is set Masahiro Yamada
2016-11-26 18:05 ` [PATCH 08/39] mtd: nand: denali: introduce capability flag Masahiro Yamada
2016-11-26 18:05 ` [PATCH 09/39] mtd: nand: denali: fix erased page check code Masahiro Yamada
2016-11-27 15:21   ` Boris Brezillon
2016-12-02  4:33     ` Masahiro Yamada
2016-12-02  7:57       ` Boris Brezillon
2016-11-26 18:05 ` [PATCH 10/39] mtd: nand: denali: remove redundant if conditional of erased_check Masahiro Yamada
2016-11-26 18:05 ` [PATCH 11/39] mtd: nand: denali: increment ecc_stats.failed by one per error Masahiro Yamada
2016-11-26 18:05 ` [PATCH 12/39] mtd: nand: denali: return 0 for uncorrectable ECC error Masahiro Yamada
2016-11-26 18:05 ` [PATCH 13/39] mtd: nand: denali: increment ecc_stats->corrected Masahiro Yamada
2016-11-27 15:31   ` Boris Brezillon
2016-12-02  4:28     ` Masahiro Yamada
2016-11-26 18:06 ` [PATCH 14/39] mtd: nand: denali: replace uint{8/16/32}_t with u{8/16/32} Masahiro Yamada
2016-11-26 18:06 ` [PATCH 15/39] mtd: nand: denali: improve readability of handle_ecc() Masahiro Yamada
2016-11-27 15:34   ` Boris Brezillon
2016-11-27 15:42   ` Boris Brezillon
2016-12-02  4:26     ` Masahiro Yamada
2016-12-02  7:55       ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 16/39] mtd: nand: denali: rename handle_ecc() to denali_sw_ecc_fixup() Masahiro Yamada
2016-11-26 18:06 ` [PATCH 17/39] mtd: nand: denali: support HW_ECC_FIXUP capability Masahiro Yamada
2016-11-27 16:09   ` Boris Brezillon
2016-11-30  6:20     ` Masahiro Yamada
2016-11-30  7:51       ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 18/39] mtd: nand: denali: move denali_read_page_raw() above denali_read_page() Masahiro Yamada
2016-11-27 16:10   ` Boris Brezillon
2016-11-30  6:13     ` Masahiro Yamada
2016-11-26 18:06 ` [PATCH 19/39] mtd: nand: denali: perform erased check against raw transferred page Masahiro Yamada
2016-11-27 16:12   ` Boris Brezillon
2016-11-30  5:36     ` Masahiro Yamada
2016-11-30  8:00       ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 20/39] mtd: nand: denali_dt: enable HW_ECC_FIXUP capability for DT platform Masahiro Yamada
2016-11-27 16:14   ` Boris Brezillon
2016-11-30  6:14     ` Masahiro Yamada
2016-11-26 18:06 ` [PATCH 21/39] mtd: nand: denali: support 64bit capable DMA engine Masahiro Yamada
2016-11-27 16:16   ` Boris Brezillon
2016-11-30  7:11     ` Masahiro Yamada
2016-11-30  7:17       ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 22/39] mtd: nand: denali_dt: remove dma-mask DT property Masahiro Yamada
2016-12-01 15:56   ` Rob Herring
2016-12-01 15:56     ` Rob Herring
2016-11-26 18:06 ` [PATCH 23/39] mtd: nand: denali_dt: use pdev instead of ofdev for platform_device Masahiro Yamada
2016-11-26 18:06 ` [PATCH 24/39] mtd: nand: denali: add NEW_N_BANKS_FORMAT capability Masahiro Yamada
2016-11-26 18:06 ` [PATCH 25/39] mtd: nand: denali: use nand_chip to hold frequently accessed data Masahiro Yamada
2016-11-26 18:06 ` [PATCH 26/39] mtd: nand: denali: call nand_set_flash_node() to set DT node Masahiro Yamada
2016-11-26 18:06 ` [PATCH 27/39] mtd: nand: denali: do not set mtd->name Masahiro Yamada
2016-11-26 18:06 ` [PATCH 28/39] mtd: nand: denali: move multi NAND fixup code to a helper function Masahiro Yamada
2016-11-27 16:24   ` Boris Brezillon
2016-11-30  6:09     ` Masahiro Yamada
2016-11-30  8:07       ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 29/39] mtd: nand: denali: refactor multi NAND fixup code in more generic way Masahiro Yamada
2016-11-26 18:06 ` [PATCH 30/39] mtd: nand: denali: set DEVICES_CONNECTED 1 if not set Masahiro Yamada
2016-11-26 18:06 ` [PATCH 31/39] mtd: nand: denali: remove meaningless writes to read-only registers Masahiro Yamada
2016-11-26 18:06 ` [PATCH 32/39] mtd: nand: denali: remove unnecessary writes to ECC_CORRECTION Masahiro Yamada
2016-11-26 18:06 ` [PATCH 33/39] mtd: nand: denali: support 1024 byte ECC step size Masahiro Yamada
2016-11-26 18:06   ` Masahiro Yamada
2016-12-01 15:58   ` Rob Herring
2016-12-01 15:58     ` Rob Herring
2016-11-26 18:06 ` [PATCH 34/39] mtd: nand: denali: fix the condition for 15 bit ECC strength Masahiro Yamada
2016-11-26 18:06 ` [PATCH 35/39] mtd: nand: denali: calculate ecc.strength and ecc.bytes generically Masahiro Yamada
2016-11-26 18:06 ` [PATCH 36/39] mtd: nand: denali: allow to use SoC-specific ECC strength Masahiro Yamada
2016-11-26 18:06 ` [PATCH 37/39] mtd: nand: denali: support "nand-ecc-strength" DT property Masahiro Yamada
2016-11-26 18:06   ` Masahiro Yamada
2016-12-01 15:59   ` Rob Herring
2016-12-01 15:59     ` Rob Herring
2016-11-26 18:06 ` [PATCH 38/39] mtd: nand: denali: remove Toshiba, Hynix specific fixup code Masahiro Yamada
2016-11-27 16:28   ` Boris Brezillon
2016-11-26 18:06 ` [PATCH 39/39] mtd: nand: denali_dt: add compatible strings for UniPhier SoC variants Masahiro Yamada
2016-11-26 18:06   ` Masahiro Yamada
2016-12-01 16:05   ` Rob Herring
2016-12-02  2:54     ` Masahiro Yamada
2016-12-02  2:54       ` Masahiro Yamada
2016-12-02 16:26       ` Rob Herring
2016-12-02 16:26         ` Rob Herring
2016-12-03  2:41         ` Masahiro Yamada
2016-12-03  2:41           ` Masahiro Yamada
2016-12-03  2:49           ` Marek Vasut
2016-12-03  2:49             ` Marek Vasut
2016-12-03 22:08             ` Dinh Nguyen
2016-12-05  3:30               ` Masahiro Yamada
2016-12-05  3:30                 ` Masahiro Yamada
2016-12-05  3:44                 ` Marek Vasut
2016-12-05  3:44                   ` Marek Vasut
2016-12-05  4:10                   ` Masahiro Yamada
2016-12-05  4:10                     ` Masahiro Yamada
2016-12-05  4:22                     ` Marek Vasut
2016-12-05 20:51                       ` Dinh Nguyen
2016-12-05 21:29                         ` Marek Vasut
2016-12-05 21:29                           ` Marek Vasut
2016-12-05 22:31                           ` Dinh Nguyen
2016-12-05 22:31                             ` Dinh Nguyen
2016-11-27 15:04 ` [PATCH 00/39] mtd: nand: denali: 2nd round of Denali NAND IP patch bomb Boris Brezillon
2016-11-27 15:04   ` Boris Brezillon
2016-11-30  8:02   ` Masahiro Yamada
2016-11-30  8:02     ` Masahiro Yamada
2016-11-30  8:17     ` Boris Brezillon
2016-11-30  8:17       ` Boris Brezillon
2016-12-01  9:15       ` Masahiro Yamada
2017-03-10 11:00       ` Masahiro Yamada
2017-03-10 11:00         ` Masahiro Yamada
2017-03-13 11:33         ` Boris Brezillon [this message]
2017-03-13 11:33           ` Boris Brezillon
2016-11-30  8:13   ` Masahiro Yamada
2016-11-27 16:31 ` Boris Brezillon
2016-11-27 16:31   ` Boris Brezillon

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=20170313123322.06475e5c@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=mark.rutland@arm.com \
    --cc=richard@nod.at \
    --cc=robh+dt@kernel.org \
    --cc=yamada.masahiro@socionext.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.