Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Masahiro Yamada
2017-12-05 19:28 GMT+09:00 Boris Brezillon :
> On Tue, 5 Dec 2017 19:02:26 +0900
> Masahiro Yamada  wrote:
>
>> Hi Boris,
>>
>> 2017-12-04 18:10 GMT+09:00 Boris Brezillon
>> :
>>
>> >>   }
>> >>
>> >>   if (!(chip->options & NAND_OWN_BUFFERS)) {
>> >> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
>> >> - if (!nbuf)
>> >> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> + if (!chip->ecccalc)
>> >>   return -ENOMEM;
>> >>
>> >> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> - if (!nbuf->ecccalc) {
>> >> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> + if (!chip->ecccode) {
>> >>   ret = -ENOMEM;
>> >>   goto err_free_nbuf;
>> >>   }
>> >
>> > Hm, again not directly related to this patch, but I wonder if we
>> > couldn't allocate those buffers only when they are really needed.
>> > For example, most NAND controllers do the ECC calculation/correct
>> > in HW and simply don't need those buffers.
>>
>>
>> The only idea I came up with is to add a new flag,
>> but I am not sure if you are happy with it
>> because we are removing NAND_OWN_BUFFERS.
>
> All drivers using ->calc/code_buf are providing a ->correct() and/or
> ->calculate() method, so I thought we could make the allocation
> dependent on the presence of one of these hooks [1].
>
> The only exception is the denali driver, but I think we can patch it
> to not use the ->code_buf buffer [2].

Cool!


> [1]http://code.bulix.org/2ks7yp-236649
> [2]http://code.bulix.org/sxqx7o-236650
>

Thanks!

I can issue Acked-by for [2].


-- 
Best Regards
Masahiro Yamada


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Masahiro Yamada
2017-12-05 19:28 GMT+09:00 Boris Brezillon :
> On Tue, 5 Dec 2017 19:02:26 +0900
> Masahiro Yamada  wrote:
>
>> Hi Boris,
>>
>> 2017-12-04 18:10 GMT+09:00 Boris Brezillon
>> :
>>
>> >>   }
>> >>
>> >>   if (!(chip->options & NAND_OWN_BUFFERS)) {
>> >> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
>> >> - if (!nbuf)
>> >> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> + if (!chip->ecccalc)
>> >>   return -ENOMEM;
>> >>
>> >> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> - if (!nbuf->ecccalc) {
>> >> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>> >> + if (!chip->ecccode) {
>> >>   ret = -ENOMEM;
>> >>   goto err_free_nbuf;
>> >>   }
>> >
>> > Hm, again not directly related to this patch, but I wonder if we
>> > couldn't allocate those buffers only when they are really needed.
>> > For example, most NAND controllers do the ECC calculation/correct
>> > in HW and simply don't need those buffers.
>>
>>
>> The only idea I came up with is to add a new flag,
>> but I am not sure if you are happy with it
>> because we are removing NAND_OWN_BUFFERS.
>
> All drivers using ->calc/code_buf are providing a ->correct() and/or
> ->calculate() method, so I thought we could make the allocation
> dependent on the presence of one of these hooks [1].
>
> The only exception is the denali driver, but I think we can patch it
> to not use the ->code_buf buffer [2].

Cool!


> [1]http://code.bulix.org/2ks7yp-236649
> [2]http://code.bulix.org/sxqx7o-236650
>

Thanks!

I can issue Acked-by for [2].


-- 
Best Regards
Masahiro Yamada


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Boris Brezillon
On Tue, 5 Dec 2017 19:02:26 +0900
Masahiro Yamada  wrote:

> Hi Boris,
> 
> 2017-12-04 18:10 GMT+09:00 Boris Brezillon
> :
> 
> >>   }
> >>
> >>   if (!(chip->options & NAND_OWN_BUFFERS)) {
> >> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
> >> - if (!nbuf)
> >> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> + if (!chip->ecccalc)
> >>   return -ENOMEM;
> >>
> >> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> - if (!nbuf->ecccalc) {
> >> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> + if (!chip->ecccode) {
> >>   ret = -ENOMEM;
> >>   goto err_free_nbuf;
> >>   }  
> >
> > Hm, again not directly related to this patch, but I wonder if we
> > couldn't allocate those buffers only when they are really needed.
> > For example, most NAND controllers do the ECC calculation/correct
> > in HW and simply don't need those buffers.  
> 
> 
> The only idea I came up with is to add a new flag,
> but I am not sure if you are happy with it
> because we are removing NAND_OWN_BUFFERS.

All drivers using ->calc/code_buf are providing a ->correct() and/or
->calculate() method, so I thought we could make the allocation
dependent on the presence of one of these hooks [1].

The only exception is the denali driver, but I think we can patch it
to not use the ->code_buf buffer [2].

[1]http://code.bulix.org/2ks7yp-236649
[2]http://code.bulix.org/sxqx7o-236650


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Boris Brezillon
On Tue, 5 Dec 2017 19:02:26 +0900
Masahiro Yamada  wrote:

> Hi Boris,
> 
> 2017-12-04 18:10 GMT+09:00 Boris Brezillon
> :
> 
> >>   }
> >>
> >>   if (!(chip->options & NAND_OWN_BUFFERS)) {
> >> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
> >> - if (!nbuf)
> >> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> + if (!chip->ecccalc)
> >>   return -ENOMEM;
> >>
> >> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> - if (!nbuf->ecccalc) {
> >> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
> >> + if (!chip->ecccode) {
> >>   ret = -ENOMEM;
> >>   goto err_free_nbuf;
> >>   }  
> >
> > Hm, again not directly related to this patch, but I wonder if we
> > couldn't allocate those buffers only when they are really needed.
> > For example, most NAND controllers do the ECC calculation/correct
> > in HW and simply don't need those buffers.  
> 
> 
> The only idea I came up with is to add a new flag,
> but I am not sure if you are happy with it
> because we are removing NAND_OWN_BUFFERS.

All drivers using ->calc/code_buf are providing a ->correct() and/or
->calculate() method, so I thought we could make the allocation
dependent on the presence of one of these hooks [1].

The only exception is the denali driver, but I think we can patch it
to not use the ->code_buf buffer [2].

[1]http://code.bulix.org/2ks7yp-236649
[2]http://code.bulix.org/sxqx7o-236650


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Masahiro Yamada
Hi Boris,

2017-12-04 18:10 GMT+09:00 Boris Brezillon :

>>   }
>>
>>   if (!(chip->options & NAND_OWN_BUFFERS)) {
>> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
>> - if (!nbuf)
>> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> + if (!chip->ecccalc)
>>   return -ENOMEM;
>>
>> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> - if (!nbuf->ecccalc) {
>> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>> + if (!chip->ecccode) {
>>   ret = -ENOMEM;
>>   goto err_free_nbuf;
>>   }
>
> Hm, again not directly related to this patch, but I wonder if we
> couldn't allocate those buffers only when they are really needed. For
> example, most NAND controllers do the ECC calculation/correct in HW and
> simply don't need those buffers.


The only idea I came up with is to add a new flag,
but I am not sure if you are happy with it
because we are removing NAND_OWN_BUFFERS.





-- 
Best Regards
Masahiro Yamada


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-05 Thread Masahiro Yamada
Hi Boris,

2017-12-04 18:10 GMT+09:00 Boris Brezillon :

>>   }
>>
>>   if (!(chip->options & NAND_OWN_BUFFERS)) {
>> - nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL);
>> - if (!nbuf)
>> + chip->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> + if (!chip->ecccalc)
>>   return -ENOMEM;
>>
>> - nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL);
>> - if (!nbuf->ecccalc) {
>> + chip->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL);
>> + if (!chip->ecccode) {
>>   ret = -ENOMEM;
>>   goto err_free_nbuf;
>>   }
>
> Hm, again not directly related to this patch, but I wonder if we
> couldn't allocate those buffers only when they are really needed. For
> example, most NAND controllers do the ECC calculation/correct in HW and
> simply don't need those buffers.


The only idea I came up with is to add a new flag,
but I am not sure if you are happy with it
because we are removing NAND_OWN_BUFFERS.





-- 
Best Regards
Masahiro Yamada


Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-04 Thread Boris Brezillon
On Mon,  4 Dec 2017 14:47:50 +0900
Masahiro Yamada  wrote:

> struct nand_buffers is malloc'ed in nand_scan_tail() just for
> containing three pointers.  Move the pointers into nand_chip
> and delete struct nand_buffers.
> 
> Signed-off-by: Masahiro Yamada 
> ---
> 
> Another possibility is to keep struct nand_buffers,
> but embed it in struct nand_chip.
> 
> struct nand_chip {
>  ...
> 
>  struct nand_buffers buffers;
> 
>  ...
> };
> 
> I will follow Boris's opinion, anyway.

Nope, I think it's fine to just drop the nand_buffers struct, but I'd
prefer to have ecc related buffers placed in nand_ecc_ctrl:

struct nand_ecc_ctrl {
...
u8 *code_buf;
u8 *calc_buf;
...
};

or

struct nand_ecc_ctrl {
...
struct {
u8 *code;
u8 *calc;
} bufs;
...
};

And ideally, databuf should be placed next to pagebuf in the
nand_chip struct, since those fields are tightly linked.

> 
> 
>  drivers/mtd/nand/brcmnand/brcmnand.c   |  2 +-
>  drivers/mtd/nand/cafe_nand.c   | 15 ++
>  drivers/mtd/nand/denali.c  |  2 +-
>  drivers/mtd/nand/fsmc_nand.c   |  4 +-
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c |  4 +-
>  drivers/mtd/nand/nand_base.c   | 91 
> +++---
>  drivers/mtd/nand/nand_bbt.c|  2 +-
>  drivers/mtd/nand/omap2.c   | 10 ++--
>  drivers/mtd/nand/sunxi_nand.c  |  6 +--
>  include/linux/mtd/rawnand.h| 23 +++--
>  10 files changed, 64 insertions(+), 95 deletions(-)
> 
> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
> b/drivers/mtd/nand/brcmnand/brcmnand.c
> index e0eb51d..6c9f7ec 100644
> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> @@ -1681,7 +1681,7 @@ static int brcmstb_nand_verify_erased_page(struct 
> mtd_info *mtd,
>   int ret;
>  
>   if (!buf) {
> - buf = chip->buffers->databuf;
> + buf = chip->databuf;
>   /* Invalidate page cache */
>   chip->pagebuf = -1;
>   }
> diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
> index bc558c4..1e54196 100644
> --- a/drivers/mtd/nand/cafe_nand.c
> +++ b/drivers/mtd/nand/cafe_nand.c
> @@ -613,7 +613,6 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   uint32_t ctrl;
>   int err = 0;
>   int old_dma;
> - struct nand_buffers *nbuf;
>  
>   /* Very old versions shared the same PCI ident for all three
>  functions on the chip. Verify the class too... */
> @@ -732,14 +731,12 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   goto out_irq;
>  
>   cafe->dmabuf = dma_alloc_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - mtd->writesize + mtd->oobsize,
> + 2112 + mtd->writesize + mtd->oobsize,
>   >dmaaddr, GFP_KERNEL);

Not directly related to this patch, but cafe_nand is the last user of
NAND_OWN_BUFFERS, and after looking at the code, I think it's actually
not needed, because the driver uses its own bounce buffer to do DMA
transfers. That'd be great if we could get rid of this flag completely
and let the core allocate the buffers for everyone. Could you have a
look?

>   if (!cafe->dmabuf) {
>   err = -ENOMEM;
>   goto out_irq;
>   }
> - cafe->nand.buffers = nbuf = (void *)cafe->dmabuf + 2112;
>  
>   /* Set up DMA address */
>   cafe_writel(cafe, cafe->dmaaddr & 0x, NAND_DMA_ADDR0);
> @@ -753,9 +750,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
>  
>   /* this driver does not need the @ecccalc and @ecccode */
> - nbuf->ecccalc = NULL;
> - nbuf->ecccode = NULL;
> - nbuf->databuf = (uint8_t *)(nbuf + 1);
> + cafe->nand.databuf = (void *)cafe->dmabuf + 2112;
>  
>   /* Restore the DMA flag */
>   usedma = old_dma;
> @@ -802,8 +797,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>  
>   out_free_dma:
>   dma_free_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - mtd->writesize + mtd->oobsize,
> + 2112 + mtd->writesize + mtd->oobsize,
>   cafe->dmabuf, cafe->dmaaddr);
>   out_irq:
>   /* Disable NAND IRQ in global IRQ mask register */
> @@ -830,8 +824,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
>   free_rs(cafe->rs);
>   pci_iounmap(pdev, cafe->mmio);
>   dma_free_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - 

Re: [PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-04 Thread Boris Brezillon
On Mon,  4 Dec 2017 14:47:50 +0900
Masahiro Yamada  wrote:

> struct nand_buffers is malloc'ed in nand_scan_tail() just for
> containing three pointers.  Move the pointers into nand_chip
> and delete struct nand_buffers.
> 
> Signed-off-by: Masahiro Yamada 
> ---
> 
> Another possibility is to keep struct nand_buffers,
> but embed it in struct nand_chip.
> 
> struct nand_chip {
>  ...
> 
>  struct nand_buffers buffers;
> 
>  ...
> };
> 
> I will follow Boris's opinion, anyway.

Nope, I think it's fine to just drop the nand_buffers struct, but I'd
prefer to have ecc related buffers placed in nand_ecc_ctrl:

struct nand_ecc_ctrl {
...
u8 *code_buf;
u8 *calc_buf;
...
};

or

struct nand_ecc_ctrl {
...
struct {
u8 *code;
u8 *calc;
} bufs;
...
};

And ideally, databuf should be placed next to pagebuf in the
nand_chip struct, since those fields are tightly linked.

> 
> 
>  drivers/mtd/nand/brcmnand/brcmnand.c   |  2 +-
>  drivers/mtd/nand/cafe_nand.c   | 15 ++
>  drivers/mtd/nand/denali.c  |  2 +-
>  drivers/mtd/nand/fsmc_nand.c   |  4 +-
>  drivers/mtd/nand/gpmi-nand/gpmi-nand.c |  4 +-
>  drivers/mtd/nand/nand_base.c   | 91 
> +++---
>  drivers/mtd/nand/nand_bbt.c|  2 +-
>  drivers/mtd/nand/omap2.c   | 10 ++--
>  drivers/mtd/nand/sunxi_nand.c  |  6 +--
>  include/linux/mtd/rawnand.h| 23 +++--
>  10 files changed, 64 insertions(+), 95 deletions(-)
> 
> diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
> b/drivers/mtd/nand/brcmnand/brcmnand.c
> index e0eb51d..6c9f7ec 100644
> --- a/drivers/mtd/nand/brcmnand/brcmnand.c
> +++ b/drivers/mtd/nand/brcmnand/brcmnand.c
> @@ -1681,7 +1681,7 @@ static int brcmstb_nand_verify_erased_page(struct 
> mtd_info *mtd,
>   int ret;
>  
>   if (!buf) {
> - buf = chip->buffers->databuf;
> + buf = chip->databuf;
>   /* Invalidate page cache */
>   chip->pagebuf = -1;
>   }
> diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
> index bc558c4..1e54196 100644
> --- a/drivers/mtd/nand/cafe_nand.c
> +++ b/drivers/mtd/nand/cafe_nand.c
> @@ -613,7 +613,6 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   uint32_t ctrl;
>   int err = 0;
>   int old_dma;
> - struct nand_buffers *nbuf;
>  
>   /* Very old versions shared the same PCI ident for all three
>  functions on the chip. Verify the class too... */
> @@ -732,14 +731,12 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   goto out_irq;
>  
>   cafe->dmabuf = dma_alloc_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - mtd->writesize + mtd->oobsize,
> + 2112 + mtd->writesize + mtd->oobsize,
>   >dmaaddr, GFP_KERNEL);

Not directly related to this patch, but cafe_nand is the last user of
NAND_OWN_BUFFERS, and after looking at the code, I think it's actually
not needed, because the driver uses its own bounce buffer to do DMA
transfers. That'd be great if we could get rid of this flag completely
and let the core allocate the buffers for everyone. Could you have a
look?

>   if (!cafe->dmabuf) {
>   err = -ENOMEM;
>   goto out_irq;
>   }
> - cafe->nand.buffers = nbuf = (void *)cafe->dmabuf + 2112;
>  
>   /* Set up DMA address */
>   cafe_writel(cafe, cafe->dmaaddr & 0x, NAND_DMA_ADDR0);
> @@ -753,9 +750,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>   cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
>  
>   /* this driver does not need the @ecccalc and @ecccode */
> - nbuf->ecccalc = NULL;
> - nbuf->ecccode = NULL;
> - nbuf->databuf = (uint8_t *)(nbuf + 1);
> + cafe->nand.databuf = (void *)cafe->dmabuf + 2112;
>  
>   /* Restore the DMA flag */
>   usedma = old_dma;
> @@ -802,8 +797,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
>  
>   out_free_dma:
>   dma_free_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - mtd->writesize + mtd->oobsize,
> + 2112 + mtd->writesize + mtd->oobsize,
>   cafe->dmabuf, cafe->dmaaddr);
>   out_irq:
>   /* Disable NAND IRQ in global IRQ mask register */
> @@ -830,8 +824,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
>   free_rs(cafe->rs);
>   pci_iounmap(pdev, cafe->mmio);
>   dma_free_coherent(>pdev->dev,
> - 2112 + sizeof(struct nand_buffers) +
> - mtd->writesize + mtd->oobsize,
> + 2112 + 

[PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-03 Thread Masahiro Yamada
struct nand_buffers is malloc'ed in nand_scan_tail() just for
containing three pointers.  Move the pointers into nand_chip
and delete struct nand_buffers.

Signed-off-by: Masahiro Yamada 
---

Another possibility is to keep struct nand_buffers,
but embed it in struct nand_chip.

struct nand_chip {
 ...

 struct nand_buffers buffers;

 ...
};

I will follow Boris's opinion, anyway.


 drivers/mtd/nand/brcmnand/brcmnand.c   |  2 +-
 drivers/mtd/nand/cafe_nand.c   | 15 ++
 drivers/mtd/nand/denali.c  |  2 +-
 drivers/mtd/nand/fsmc_nand.c   |  4 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |  4 +-
 drivers/mtd/nand/nand_base.c   | 91 +++---
 drivers/mtd/nand/nand_bbt.c|  2 +-
 drivers/mtd/nand/omap2.c   | 10 ++--
 drivers/mtd/nand/sunxi_nand.c  |  6 +--
 include/linux/mtd/rawnand.h| 23 +++--
 10 files changed, 64 insertions(+), 95 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
b/drivers/mtd/nand/brcmnand/brcmnand.c
index e0eb51d..6c9f7ec 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1681,7 +1681,7 @@ static int brcmstb_nand_verify_erased_page(struct 
mtd_info *mtd,
int ret;
 
if (!buf) {
-   buf = chip->buffers->databuf;
+   buf = chip->databuf;
/* Invalidate page cache */
chip->pagebuf = -1;
}
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index bc558c4..1e54196 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -613,7 +613,6 @@ static int cafe_nand_probe(struct pci_dev *pdev,
uint32_t ctrl;
int err = 0;
int old_dma;
-   struct nand_buffers *nbuf;
 
/* Very old versions shared the same PCI ident for all three
   functions on the chip. Verify the class too... */
@@ -732,14 +731,12 @@ static int cafe_nand_probe(struct pci_dev *pdev,
goto out_irq;
 
cafe->dmabuf = dma_alloc_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
>dmaaddr, GFP_KERNEL);
if (!cafe->dmabuf) {
err = -ENOMEM;
goto out_irq;
}
-   cafe->nand.buffers = nbuf = (void *)cafe->dmabuf + 2112;
 
/* Set up DMA address */
cafe_writel(cafe, cafe->dmaaddr & 0x, NAND_DMA_ADDR0);
@@ -753,9 +750,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
 
/* this driver does not need the @ecccalc and @ecccode */
-   nbuf->ecccalc = NULL;
-   nbuf->ecccode = NULL;
-   nbuf->databuf = (uint8_t *)(nbuf + 1);
+   cafe->nand.databuf = (void *)cafe->dmabuf + 2112;
 
/* Restore the DMA flag */
usedma = old_dma;
@@ -802,8 +797,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
 
  out_free_dma:
dma_free_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
cafe->dmabuf, cafe->dmaaddr);
  out_irq:
/* Disable NAND IRQ in global IRQ mask register */
@@ -830,8 +824,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
free_rs(cafe->rs);
pci_iounmap(pdev, cafe->mmio);
dma_free_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
cafe->dmabuf, cafe->dmaaddr);
kfree(cafe);
 }
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 2fc964b..e1f8c6f 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -328,7 +328,7 @@ static int denali_check_erased_page(struct mtd_info *mtd,
unsigned long uncor_ecc_flags,
unsigned int max_bitflips)
 {
-   uint8_t *ecc_code = chip->buffers->ecccode;
+   uint8_t *ecc_code = chip->ecccode;
int ecc_steps = chip->ecc.steps;
int ecc_size = chip->ecc.size;
int ecc_bytes = chip->ecc.bytes;
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index eac15d9..147ca3d 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -684,8 +684,8 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
int eccbytes = chip->ecc.bytes;
int eccsteps = chip->ecc.steps;
uint8_t *p = buf;
-   uint8_t *ecc_calc = 

[PATCH] mtd: nand: squash struct nand_buffers into struct nand_chip

2017-12-03 Thread Masahiro Yamada
struct nand_buffers is malloc'ed in nand_scan_tail() just for
containing three pointers.  Move the pointers into nand_chip
and delete struct nand_buffers.

Signed-off-by: Masahiro Yamada 
---

Another possibility is to keep struct nand_buffers,
but embed it in struct nand_chip.

struct nand_chip {
 ...

 struct nand_buffers buffers;

 ...
};

I will follow Boris's opinion, anyway.


 drivers/mtd/nand/brcmnand/brcmnand.c   |  2 +-
 drivers/mtd/nand/cafe_nand.c   | 15 ++
 drivers/mtd/nand/denali.c  |  2 +-
 drivers/mtd/nand/fsmc_nand.c   |  4 +-
 drivers/mtd/nand/gpmi-nand/gpmi-nand.c |  4 +-
 drivers/mtd/nand/nand_base.c   | 91 +++---
 drivers/mtd/nand/nand_bbt.c|  2 +-
 drivers/mtd/nand/omap2.c   | 10 ++--
 drivers/mtd/nand/sunxi_nand.c  |  6 +--
 include/linux/mtd/rawnand.h| 23 +++--
 10 files changed, 64 insertions(+), 95 deletions(-)

diff --git a/drivers/mtd/nand/brcmnand/brcmnand.c 
b/drivers/mtd/nand/brcmnand/brcmnand.c
index e0eb51d..6c9f7ec 100644
--- a/drivers/mtd/nand/brcmnand/brcmnand.c
+++ b/drivers/mtd/nand/brcmnand/brcmnand.c
@@ -1681,7 +1681,7 @@ static int brcmstb_nand_verify_erased_page(struct 
mtd_info *mtd,
int ret;
 
if (!buf) {
-   buf = chip->buffers->databuf;
+   buf = chip->databuf;
/* Invalidate page cache */
chip->pagebuf = -1;
}
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index bc558c4..1e54196 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -613,7 +613,6 @@ static int cafe_nand_probe(struct pci_dev *pdev,
uint32_t ctrl;
int err = 0;
int old_dma;
-   struct nand_buffers *nbuf;
 
/* Very old versions shared the same PCI ident for all three
   functions on the chip. Verify the class too... */
@@ -732,14 +731,12 @@ static int cafe_nand_probe(struct pci_dev *pdev,
goto out_irq;
 
cafe->dmabuf = dma_alloc_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
>dmaaddr, GFP_KERNEL);
if (!cafe->dmabuf) {
err = -ENOMEM;
goto out_irq;
}
-   cafe->nand.buffers = nbuf = (void *)cafe->dmabuf + 2112;
 
/* Set up DMA address */
cafe_writel(cafe, cafe->dmaaddr & 0x, NAND_DMA_ADDR0);
@@ -753,9 +750,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
 
/* this driver does not need the @ecccalc and @ecccode */
-   nbuf->ecccalc = NULL;
-   nbuf->ecccode = NULL;
-   nbuf->databuf = (uint8_t *)(nbuf + 1);
+   cafe->nand.databuf = (void *)cafe->dmabuf + 2112;
 
/* Restore the DMA flag */
usedma = old_dma;
@@ -802,8 +797,7 @@ static int cafe_nand_probe(struct pci_dev *pdev,
 
  out_free_dma:
dma_free_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
cafe->dmabuf, cafe->dmaaddr);
  out_irq:
/* Disable NAND IRQ in global IRQ mask register */
@@ -830,8 +824,7 @@ static void cafe_nand_remove(struct pci_dev *pdev)
free_rs(cafe->rs);
pci_iounmap(pdev, cafe->mmio);
dma_free_coherent(>pdev->dev,
-   2112 + sizeof(struct nand_buffers) +
-   mtd->writesize + mtd->oobsize,
+   2112 + mtd->writesize + mtd->oobsize,
cafe->dmabuf, cafe->dmaaddr);
kfree(cafe);
 }
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 2fc964b..e1f8c6f 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -328,7 +328,7 @@ static int denali_check_erased_page(struct mtd_info *mtd,
unsigned long uncor_ecc_flags,
unsigned int max_bitflips)
 {
-   uint8_t *ecc_code = chip->buffers->ecccode;
+   uint8_t *ecc_code = chip->ecccode;
int ecc_steps = chip->ecc.steps;
int ecc_size = chip->ecc.size;
int ecc_bytes = chip->ecc.bytes;
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index eac15d9..147ca3d 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -684,8 +684,8 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, 
struct nand_chip *chip,
int eccbytes = chip->ecc.bytes;
int eccsteps = chip->ecc.steps;
uint8_t *p = buf;
-   uint8_t *ecc_calc = chip->buffers->ecccalc;
-   uint8_t