linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0
@ 2019-09-06 19:47 Kamal Dasu
  2019-09-06 19:47 ` [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected Kamal Dasu
  2019-10-04 16:04 ` [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Miquel Raynal
  0 siblings, 2 replies; 8+ messages in thread
From: Kamal Dasu @ 2019-09-06 19:47 UTC (permalink / raw)
  To: kdasu.kdev
  Cc: Brian Norris, Miquel Raynal, Richard Weinberger, David Woodhouse,
	Marek Vasut, Vignesh Raghavendra, Boris Brezillon,
	Frieder Schrempf, linux-mtd, bcm-kernel-feedback-list,
	linux-kernel

This change adds support for flash dma v0.0.

Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
 drivers/mtd/nand/raw/brcmnand/brcmnand.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/brcmnand/brcmnand.c b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
index 33310b8a6eb8..1eade9dc3b0d 100644
--- a/drivers/mtd/nand/raw/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/raw/brcmnand/brcmnand.c
@@ -117,6 +117,18 @@ enum flash_dma_reg {
 	FLASH_DMA_CURRENT_DESC_EXT,
 };
 
+/* flash_dma registers v0*/
+static const u16 flash_dma_regs_v0[] = {
+	[FLASH_DMA_REVISION]		= 0x00,
+	[FLASH_DMA_FIRST_DESC]		= 0x04,
+	[FLASH_DMA_CTRL]		= 0x08,
+	[FLASH_DMA_MODE]		= 0x0c,
+	[FLASH_DMA_STATUS]		= 0x10,
+	[FLASH_DMA_INTERRUPT_DESC]	= 0x14,
+	[FLASH_DMA_ERROR_STATUS]	= 0x18,
+	[FLASH_DMA_CURRENT_DESC]	= 0x1c,
+};
+
 /* flash_dma registers v1*/
 static const u16 flash_dma_regs_v1[] = {
 	[FLASH_DMA_REVISION]		= 0x00,
@@ -597,6 +609,8 @@ static void brcmnand_flash_dma_revision_init(struct brcmnand_controller *ctrl)
 	/* flash_dma register offsets */
 	if (ctrl->nand_version >= 0x0703)
 		ctrl->flash_dma_offsets = flash_dma_regs_v4;
+	else if (ctrl->nand_version == 0x0602)
+		ctrl->flash_dma_offsets = flash_dma_regs_v0;
 	else
 		ctrl->flash_dma_offsets = flash_dma_regs_v1;
 }
@@ -1673,8 +1687,11 @@ static void brcmnand_dma_run(struct brcmnand_host *host, dma_addr_t desc)
 
 	flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC, lower_32_bits(desc));
 	(void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC);
-	flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC_EXT, upper_32_bits(desc));
-	(void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC_EXT);
+	if (ctrl->nand_version > 0x0602) {
+		flash_dma_writel(ctrl, FLASH_DMA_FIRST_DESC_EXT,
+				 upper_32_bits(desc));
+		(void)flash_dma_readl(ctrl, FLASH_DMA_FIRST_DESC_EXT);
+	}
 
 	/* Start FLASH_DMA engine */
 	ctrl->dma_pending = true;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-06 19:47 [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Kamal Dasu
@ 2019-09-06 19:47 ` Kamal Dasu
  2019-09-30 16:01   ` Kamal Dasu
  2019-10-04 16:04 ` [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Miquel Raynal
  1 sibling, 1 reply; 8+ messages in thread
From: Kamal Dasu @ 2019-09-06 19:47 UTC (permalink / raw)
  To: kdasu.kdev
  Cc: Brian Norris, Miquel Raynal, Richard Weinberger, David Woodhouse,
	Marek Vasut, Vignesh Raghavendra, Boris Brezillon,
	Frieder Schrempf, linux-mtd, bcm-kernel-feedback-list,
	linux-kernel

For controller drivers that use DMA and set NAND_USE_BOUNCE_BUFFER
option use data buffers that are not vmalloced, aligned and have
valid virtual address to be able to do DMA transfers. This change
adds additional check and makes use of data buffer allocated
in nand_base driver when it is passed a vmalloced data buffer for
DMA transfers.

Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
---
 drivers/mtd/nand/raw/nand_base.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 91f046d4d452..46f6965a896a 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -45,6 +45,12 @@
 
 #include "internals.h"
 
+static int nand_need_bounce_buf(const void *buf, struct nand_chip *chip)
+{
+	return !virt_addr_valid(buf) || is_vmalloc_addr(buf) ||
+		!IS_ALIGNED((unsigned long)buf, chip->buf_align);
+}
+
 /* Define default oob placement schemes for large and small page devices */
 static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
 				 struct mtd_oob_region *oobregion)
@@ -3183,9 +3189,7 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
 		if (!aligned)
 			use_bufpoi = 1;
 		else if (chip->options & NAND_USE_BOUNCE_BUFFER)
-			use_bufpoi = !virt_addr_valid(buf) ||
-				     !IS_ALIGNED((unsigned long)buf,
-						 chip->buf_align);
+			use_bufpoi = nand_need_bounce_buf(buf, chip);
 		else
 			use_bufpoi = 0;
 
@@ -4009,9 +4013,7 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
 		if (part_pagewr)
 			use_bufpoi = 1;
 		else if (chip->options & NAND_USE_BOUNCE_BUFFER)
-			use_bufpoi = !virt_addr_valid(buf) ||
-				     !IS_ALIGNED((unsigned long)buf,
-						 chip->buf_align);
+			use_bufpoi = nand_need_bounce_buf(buf, chip);
 		else
 			use_bufpoi = 0;
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-06 19:47 ` [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected Kamal Dasu
@ 2019-09-30 16:01   ` Kamal Dasu
  2019-09-30 16:24     ` Boris Brezillon
  0 siblings, 1 reply; 8+ messages in thread
From: Kamal Dasu @ 2019-09-30 16:01 UTC (permalink / raw)
  To: Kamal Dasu
  Cc: Brian Norris, Miquel Raynal, Richard Weinberger, David Woodhouse,
	Marek Vasut, Vignesh Raghavendra, Boris Brezillon,
	Frieder Schrempf, MTD Maling List, bcm-kernel-feedback-list,
	Linux Kernel Mailing List

Does anyone have any comments on this patch ?.

Kamal

On Fri, Sep 6, 2019 at 3:49 PM Kamal Dasu <kdasu.kdev@gmail.com> wrote:
>
> For controller drivers that use DMA and set NAND_USE_BOUNCE_BUFFER
> option use data buffers that are not vmalloced, aligned and have
> valid virtual address to be able to do DMA transfers. This change
> adds additional check and makes use of data buffer allocated
> in nand_base driver when it is passed a vmalloced data buffer for
> DMA transfers.
>
> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> ---
>  drivers/mtd/nand/raw/nand_base.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 91f046d4d452..46f6965a896a 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -45,6 +45,12 @@
>
>  #include "internals.h"
>
> +static int nand_need_bounce_buf(const void *buf, struct nand_chip *chip)
> +{
> +       return !virt_addr_valid(buf) || is_vmalloc_addr(buf) ||
> +               !IS_ALIGNED((unsigned long)buf, chip->buf_align);
> +}
> +
>  /* Define default oob placement schemes for large and small page devices */
>  static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
>                                  struct mtd_oob_region *oobregion)
> @@ -3183,9 +3189,7 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
>                 if (!aligned)
>                         use_bufpoi = 1;
>                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> -                       use_bufpoi = !virt_addr_valid(buf) ||
> -                                    !IS_ALIGNED((unsigned long)buf,
> -                                                chip->buf_align);
> +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
>                 else
>                         use_bufpoi = 0;
>
> @@ -4009,9 +4013,7 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
>                 if (part_pagewr)
>                         use_bufpoi = 1;
>                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> -                       use_bufpoi = !virt_addr_valid(buf) ||
> -                                    !IS_ALIGNED((unsigned long)buf,
> -                                                chip->buf_align);
> +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
>                 else
>                         use_bufpoi = 0;
>
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-30 16:01   ` Kamal Dasu
@ 2019-09-30 16:24     ` Boris Brezillon
  2019-09-30 16:33       ` Kamal Dasu
  0 siblings, 1 reply; 8+ messages in thread
From: Boris Brezillon @ 2019-09-30 16:24 UTC (permalink / raw)
  To: Kamal Dasu
  Cc: Brian Norris, Miquel Raynal, Richard Weinberger, David Woodhouse,
	Marek Vasut, Vignesh Raghavendra, Boris Brezillon,
	Frieder Schrempf, MTD Maling List, bcm-kernel-feedback-list,
	Linux Kernel Mailing List

On Mon, 30 Sep 2019 12:01:28 -0400
Kamal Dasu <kdasu.kdev@gmail.com> wrote:

> Does anyone have any comments on this patch ?.
> 
> Kamal
> 
> On Fri, Sep 6, 2019 at 3:49 PM Kamal Dasu <kdasu.kdev@gmail.com> wrote:
> >
> > For controller drivers that use DMA and set NAND_USE_BOUNCE_BUFFER
> > option use data buffers that are not vmalloced, aligned and have
> > valid virtual address to be able to do DMA transfers. This change
> > adds additional check and makes use of data buffer allocated
> > in nand_base driver when it is passed a vmalloced data buffer for
> > DMA transfers.
> >
> > Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> > ---
> >  drivers/mtd/nand/raw/nand_base.c | 14 ++++++++------
> >  1 file changed, 8 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> > index 91f046d4d452..46f6965a896a 100644
> > --- a/drivers/mtd/nand/raw/nand_base.c
> > +++ b/drivers/mtd/nand/raw/nand_base.c
> > @@ -45,6 +45,12 @@
> >
> >  #include "internals.h"
> >
> > +static int nand_need_bounce_buf(const void *buf, struct nand_chip *chip)
> > +{
> > +       return !virt_addr_valid(buf) || is_vmalloc_addr(buf) ||

I thought virt_addr_valid() was implying !is_vmalloc_addr(), are you
sure you need that test, and can you tell me on which arch(es) this is
needed.

> > +               !IS_ALIGNED((unsigned long)buf, chip->buf_align);
> > +}
> > +
> >  /* Define default oob placement schemes for large and small page devices */
> >  static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
> >                                  struct mtd_oob_region *oobregion)
> > @@ -3183,9 +3189,7 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
> >                 if (!aligned)
> >                         use_bufpoi = 1;
> >                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> > -                       use_bufpoi = !virt_addr_valid(buf) ||
> > -                                    !IS_ALIGNED((unsigned long)buf,
> > -                                                chip->buf_align);
> > +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
> >                 else
> >                         use_bufpoi = 0;
> >
> > @@ -4009,9 +4013,7 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
> >                 if (part_pagewr)
> >                         use_bufpoi = 1;
> >                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> > -                       use_bufpoi = !virt_addr_valid(buf) ||
> > -                                    !IS_ALIGNED((unsigned long)buf,
> > -                                                chip->buf_align);
> > +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
> >                 else
> >                         use_bufpoi = 0;
> >
> > --
> > 2.17.1
> >  


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-30 16:24     ` Boris Brezillon
@ 2019-09-30 16:33       ` Kamal Dasu
  2019-09-30 19:39         ` Richard Weinberger
  0 siblings, 1 reply; 8+ messages in thread
From: Kamal Dasu @ 2019-09-30 16:33 UTC (permalink / raw)
  To: Boris Brezillon
  Cc: Kamal Dasu, Brian Norris, Miquel Raynal, Richard Weinberger,
	David Woodhouse, Marek Vasut, Vignesh Raghavendra,
	Boris Brezillon, Frieder Schrempf, MTD Maling List,
	bcm-kernel-feedback-list, Linux Kernel Mailing List

On Mon, Sep 30, 2019 at 12:25 PM Boris Brezillon
<boris.brezillon@collabora.com> wrote:
>
> On Mon, 30 Sep 2019 12:01:28 -0400
> Kamal Dasu <kdasu.kdev@gmail.com> wrote:
>
> > Does anyone have any comments on this patch ?.
> >
> > Kamal
> >
> > On Fri, Sep 6, 2019 at 3:49 PM Kamal Dasu <kdasu.kdev@gmail.com> wrote:
> > >
> > > For controller drivers that use DMA and set NAND_USE_BOUNCE_BUFFER
> > > option use data buffers that are not vmalloced, aligned and have
> > > valid virtual address to be able to do DMA transfers. This change
> > > adds additional check and makes use of data buffer allocated
> > > in nand_base driver when it is passed a vmalloced data buffer for
> > > DMA transfers.
> > >
> > > Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>
> > > ---
> > >  drivers/mtd/nand/raw/nand_base.c | 14 ++++++++------
> > >  1 file changed, 8 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> > > index 91f046d4d452..46f6965a896a 100644
> > > --- a/drivers/mtd/nand/raw/nand_base.c
> > > +++ b/drivers/mtd/nand/raw/nand_base.c
> > > @@ -45,6 +45,12 @@
> > >
> > >  #include "internals.h"
> > >
> > > +static int nand_need_bounce_buf(const void *buf, struct nand_chip *chip)
> > > +{
> > > +       return !virt_addr_valid(buf) || is_vmalloc_addr(buf) ||
>
> I thought virt_addr_valid() was implying !is_vmalloc_addr(), are you
> sure you need that test, and can you tell me on which arch(es) this is
> needed.
>

This has been observed on MIPS4K and MIPS5K architectures. There is a
check on the controller driver to use pio in such cases.

> > > +               !IS_ALIGNED((unsigned long)buf, chip->buf_align);
> > > +}
> > > +
> > >  /* Define default oob placement schemes for large and small page devices */
> > >  static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
> > >                                  struct mtd_oob_region *oobregion)
> > > @@ -3183,9 +3189,7 @@ static int nand_do_read_ops(struct nand_chip *chip, loff_t from,
> > >                 if (!aligned)
> > >                         use_bufpoi = 1;
> > >                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> > > -                       use_bufpoi = !virt_addr_valid(buf) ||
> > > -                                    !IS_ALIGNED((unsigned long)buf,
> > > -                                                chip->buf_align);
> > > +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
> > >                 else
> > >                         use_bufpoi = 0;
> > >
> > > @@ -4009,9 +4013,7 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
> > >                 if (part_pagewr)
> > >                         use_bufpoi = 1;
> > >                 else if (chip->options & NAND_USE_BOUNCE_BUFFER)
> > > -                       use_bufpoi = !virt_addr_valid(buf) ||
> > > -                                    !IS_ALIGNED((unsigned long)buf,
> > > -                                                chip->buf_align);
> > > +                       use_bufpoi = nand_need_bounce_buf(buf, chip);
> > >                 else
> > >                         use_bufpoi = 0;
> > >
> > > --
> > > 2.17.1
> > >
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-30 16:33       ` Kamal Dasu
@ 2019-09-30 19:39         ` Richard Weinberger
  2019-10-01 17:07           ` Kamal Dasu
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Weinberger @ 2019-09-30 19:39 UTC (permalink / raw)
  To: Kamal Dasu
  Cc: Boris Brezillon, Kamal Dasu, Brian Norris, Miquel Raynal,
	David Woodhouse, Marek Vasut, Vignesh Raghavendra,
	Boris Brezillon, Schrempf Frieder, linux-mtd,
	bcm-kernel-feedback-list, linux-kernel

----- Ursprüngliche Mail -----
> Von: "Kamal Dasu" <kamal.dasu@broadcom.com>
> This has been observed on MIPS4K and MIPS5K architectures. There is a
> check on the controller driver to use pio in such cases.

I fear your kernel misses commit:
074a1e1167af ("MIPS: Bounds check virt_addr_valid")

Thanks,
//richard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected
  2019-09-30 19:39         ` Richard Weinberger
@ 2019-10-01 17:07           ` Kamal Dasu
  0 siblings, 0 replies; 8+ messages in thread
From: Kamal Dasu @ 2019-10-01 17:07 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Kamal Dasu, Boris Brezillon, Brian Norris, Miquel Raynal,
	David Woodhouse, Marek Vasut, Vignesh Raghavendra,
	Boris Brezillon, Schrempf Frieder, linux-mtd,
	bcm-kernel-feedback-list, linux-kernel

I was testing with UBI/UBIFS where vmalloced  data buffers can be
passed to the nand_base and then o the controller driver. Probably
applies to older kernel 4.1.

Can the Patch1/2 be accepted or you want me to send it separately by
removing the nand_base changes ?.

Kamal

Kamal

On Mon, Sep 30, 2019 at 3:39 PM Richard Weinberger <richard@nod.at> wrote:
>
> ----- Ursprüngliche Mail -----
> > Von: "Kamal Dasu" <kamal.dasu@broadcom.com>
> > This has been observed on MIPS4K and MIPS5K architectures. There is a
> > check on the controller driver to use pio in such cases.
>
> I fear your kernel misses commit:
> 074a1e1167af ("MIPS: Bounds check virt_addr_valid")
>
> Thanks,
> //richard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0
  2019-09-06 19:47 [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Kamal Dasu
  2019-09-06 19:47 ` [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected Kamal Dasu
@ 2019-10-04 16:04 ` Miquel Raynal
  1 sibling, 0 replies; 8+ messages in thread
From: Miquel Raynal @ 2019-10-04 16:04 UTC (permalink / raw)
  To: Kamal Dasu
  Cc: Miquel Raynal, Vignesh Raghavendra, Boris Brezillon,
	Richard Weinberger, linux-kernel, Frieder Schrempf, Marek Vasut,
	linux-mtd, bcm-kernel-feedback-list, Brian Norris,
	David Woodhouse

On Fri, 2019-09-06 at 19:47:15 UTC, Kamal Dasu wrote:
> This change adds support for flash dma v0.0.
> 
> Signed-off-by: Kamal Dasu <kdasu.kdev@gmail.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-10-04 16:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06 19:47 [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Kamal Dasu
2019-09-06 19:47 ` [PATCH 2/2] mtd: rawnand: use bounce buffer when vmalloced data buf detected Kamal Dasu
2019-09-30 16:01   ` Kamal Dasu
2019-09-30 16:24     ` Boris Brezillon
2019-09-30 16:33       ` Kamal Dasu
2019-09-30 19:39         ` Richard Weinberger
2019-10-01 17:07           ` Kamal Dasu
2019-10-04 16:04 ` [PATCH 1/2] mtd: nand: brcmnand: Add support for flash-dma v0 Miquel Raynal

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).