mtd: gpmi: add NAND write verify support
Subsystems (2)
PATCH 1/1 mtd: gpmi: add NAND write verify support
Add NAND write verify support in gpmi-nand driver.
--- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +17 -0
@@ -1488,6 +1488,22 @@ static int gpmi_set_geometry(struct gpmi_nand_data *this)return gpmi_alloc_dma_buffer (this); } +#define MAX_PAGESIZE 8192 +static uint8_t verify_buf[MAX_PAGESIZE ]; + +static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +struct nand_chip *nand = mtd->priv; +int ret; + + ret =gpmi_ecc_read_page (mtd, nand, verify_buf,0 ,0 ); +if (ret) +return -EFAULT ; +if (memcmp (buf, verify_buf, len)) +return -EFAULT ; +return 0 ; +} +static int gpmi_pre_bbt_scan (struct gpmi_nand_data *this) {int ret;
@@ -1556,6 +1572,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this) chip->read_byte = gpmi_read_byte; chip->read_buf = gpmi_read_buf; chip->write_buf = gpmi_write_buf; + chip->verify_buf = gpmi_verify_buf; chip->ecc.read_page = gpmi_ecc_read_page; chip->ecc.write_page = gpmi_ecc_write_page; chip->ecc.read_oob = gpmi_ecc_read_oob;
Signature · 1 line
1.7.0.4
PATCH 1/1 mtd: gpmi: add NAND write verify support
Quoted 3 lines · Huang Shijie
Add NAND write verify support in gpmi-nand driver.
Signed-off-by Huang Shijie <[email protected]>
Tested by: Fabio Estevam <[email protected]>
PATCH 1/1 mtd: gpmi: add NAND write verify support
In reply to Huang ShijieDear Huang Shijie,
Quoted 12 lines
Add NAND write verify support in gpmi-nand driver.
Signed-off-by Huang Shijie <[email protected]>--- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/mtd/nand/gpmi-nand/gpmi-nand.cindex 8c0d2f0..6394483 100644
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data · line 1491
Quoted 4 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0@@ -1488,6 +1488,22 @@ static int gpmi_set_geometry(struct gpmi_nand_data *this) return gpmi_alloc_dma_buffer(this); } +#define MAX_PAGESIZE 8192
Use NAND_MAX_PAGESIZE, see include/linux/mtd/nand.h .
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1492
Quoted 1 line
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0+static uint8_t verify_buf[MAX_PAGESIZE ];
What will happen when you have two NANDs attached to GPMI controller and they hit this place both at once? Race condition, causing this function to fail for both?
Possibly devm_kmalloc() such buffer per-controller?
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1499
Quoted 6 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +5
-0+static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +struct nand_chip *nand = mtd->priv; +int ret; + + ret =gpmi_ecc_read_page (mtd, nand, verify_buf,0 ,0 );
mtd->chip.ecc.read_page() ?
Quoted 11 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +7
-0+if (ret) +return -EFAULT ; +if (memcmp (buf, verify_buf, len)) +return -EFAULT ; +return 0 ; +} +static int gpmi_pre_bbt_scan (struct gpmi_nand_data *this) {int ret;
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int __devinit gpmi_nfc_init(struct · line 1578
Quoted 7 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0@@ -1556,6 +1572,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data *this) chip->read_byte = gpmi_read_byte; chip->read_buf = gpmi_read_buf; chip->write_buf = gpmi_write_buf; + chip->verify_buf = gpmi_verify_buf; chip->ecc.read_page = gpmi_ecc_read_page; chip->ecc.write_page = gpmi_ecc_write_page; chip->ecc.read_oob = gpmi_ecc_read_oob;
Best regards,
Marek Vasut
PATCH 1/1 mtd: gpmi: add NAND write verify support
Quoted 17 lines · Marek Vasut
Dear Huang Shijie,
Quoted 15 lines
Add NAND write verify support in gpmi-nand driver.
Signed-off-by Huang Shijie <[email protected]>--- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/mtd/nand/gpmi-nand/gpmi-nand.cindex 8c0d2f0..6394483 100644drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0
-0@@ -1488,6 +1488,22 @@ static int gpmi_set_geometry(struct gpmi_nand_data *this) return gpmi_alloc_dma_buffer(this); }
Quoted 5 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1491
Quoted 1 line
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0+#define MAX_PAGESIZE 8192Use
NAND_MAX_PAGESIZE, seeinclude/linux/mtd/nand.h.Quoted 1 line
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0+static uint8_t verify_buf[MAX_PAGESIZE ];
ok, thanks.
Quoted 5 lines
What will happen when you have two NANDs attached to GPMI controller and they hit this place both at once? Race condition, causing this function to fail for both?
Even there are two nand chips, there is only one gpmi controller. And the current gpmi-nand does not support two nands now. does the race occur with only one nand chip?
Quoted 10 lines
Possibly
devm_kmalloc()such buffer per-controller?drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1499
Quoted 6 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +5
-0+static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +struct nand_chip *nand = mtd->priv; +int ret; + + ret =gpmi_ecc_read_page (mtd, nand, verify_buf,0 ,0 );
mtd->chip.ecc.read_page()?
In actually, they are the same.
Best Regards
Huang Shijie
PATCH 1/1 mtd: gpmi: add NAND write verify support
Dear Huang Shijie,
Quoted 26 lines · Marek Vasut
Quoted 17 lines
Dear Huang Shijie,
Quoted 15 lines
Add NAND write verify support in gpmi-nand driver.
Signed-off-by Huang Shijie <[email protected]>---
drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)(quoted diff) +0
-0
b/drivers/mtd/nand/gpmi-nand/gpmi-nand.cindex 8c0d2f0..6394483 100644drivers/mtd/nand/gpmi-nand/gpmi-nand.c +0
-0@@ -1488,6 +1488,22 @@ static int gpmi_set_geometry(struct gpmi_nand_data *this) return gpmi_alloc_dma_buffer(this);Quoted 7 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1491
Quoted 3 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0} +#define MAX_PAGESIZE 8192Use
NAND_MAX_PAGESIZE, seeinclude/linux/mtd/nand.h.Quoted 1 line
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +1
-0+static uint8_t verify_buf[MAX_PAGESIZE ];
Quoted 7 lines
ok, thanks.
Quoted 3 lines
What will happen when you have two NANDs attached to GPMI controller and they hit this place both at once? Race condition, causing this function to fail for both?
Even there are two nand chips, there is only one gpmi controller.
For now ... yes.
Quoted 2 lines
And the current gpmi-nand does not support two nands now. does the race occur with only one nand chip?
With one chip and one GPMI controller, no ... but that's no reason to introduce crappy and error prone code!
Quoted 11 lines
Quoted 10 lines
Possibly
devm_kmalloc()such buffer per-controller?drivers/mtd/nand/gpmi-nand/gpmi-nand.c static int gpmi_set_geometry(struct gpmi_nand_data *this) · line 1499
Quoted 6 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +5
-0+static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf, int len) +{ +struct nand_chip *nand = mtd->priv; +int ret; + + ret =gpmi_ecc_read_page (mtd, nand, verify_buf,0 ,0 );
mtd->chip.ecc.read_page()?
Quoted 1 line
In actually, they are the same.
They are, but if you rename the function, this is one less place to care for.
Quoted 3 lines
Best Regards
Huang Shijie
Best regards,
Marek Vasut
PATCH 1/1 mtd: gpmi: add NAND write verify support
Hi Marek,
Quoted 3 lines · Marek Vasut
Quoted 1 line
Even there are two nand chips, there is only one gpmi controller.
For now ... yes.
Does this look better?
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +16 -0
@@ -1533,6 +1533,21 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)gpmi_free_dma_buffer (this); } +static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +struct nand_chip *nand = mtd->priv; + struct gpmi_nand_data *data = container_of(mtd, struct gpmi_nand_data, + mtd); +int ret; + + ret =gpmi_ecc_read_page (mtd, nand, data->verify_buf,0 ,0 ); +if (ret) +return -EFAULT ; +if (memcmp (buf, data->verify_buf, len)) +return -EFAULT ; +return 0 ; +} +static int __devinit gpmi_nfc_init (struct gpmi_nand_data *this) {struct mtd_info *mtd = &this->mtd;
@@ -1555,6 +1570,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data * chip->dev_ready = gpmi_dev_ready; chip->read_byte = gpmi_read_byte; chip->read_buf = gpmi_read_buf; + chip->verify_buf = gpmi_verify_buf; chip->write_buf = gpmi_write_buf; chip->ecc.read_page = gpmi_ecc_read_page; chip->ecc.write_page = gpmi_ecc_write_page;
drivers/mtd/nand/gpmi-nand/gpmi-nand.h +1 -0
@@ -148,6 +148,7 @@ struct gpmi_nand_data {/* General-use Variables */ int current_chip;unsigned int command_length; +uint8_t verify_buf[NAND_MAX_PAGESIZE ];/* passed from upper layer */ uint8_t *upper_buf;
and then I can also send this separate change to allow multi-instances:
@@ -1630,7 +1646,7 @@ static int __devinit gpmi_nand_probe(struct platform_devic
return -ENOMEM;
}- this = kzalloc(sizeof(*this), GFP_KERNEL);
+ this = devm_kzalloc(&pdev->dev, sizeof(*this), GFP_KERNEL);
if (!this) {
pr_err("Failed to allocate per-device memory\n");
return -ENOMEM;PATCH 1/1 mtd: gpmi: add NAND write verify support
Dear Fabio Estevam,
Quoted 23 lines
Hi Marek,
Quoted 3 lines · Marek Vasut
Quoted 1 line
Even there are two nand chips, there is only one gpmi controller.
For now ... yes.
Does this look better?
(quoted diff) +0
-0b/drivers/mtd/nand/gpmi-nand index 8c0d2f0..5262ef3 100644
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +3
-0@@ -1533,6 +1533,21 @@ void gpmi_nfc_exit(struct gpmi_nand_data *this)gpmi_free_dma_buffer (this); } +static int gpmi_verify_buf (struct mtd_info *mtd,const uint8_t *buf,int len) +{ +struct nand_chip *nand = mtd->priv; + struct gpmi_nand_data *data = container_of(mtd, struct
gpmi_nand_data, +mtd); + int ret;
drivers/mtd/nand/gpmi-nand/gpmi-nand.c void gpmi_nfc_exit(struct gpmi_nand_data *this) · line 1543
Quoted 2 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +2
-0+ + ret =gpmi_ecc_read_page (mtd, nand, data->verify_buf,0 ,0 );
You ignored my comment on this one.
Quoted 23 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.c +8
-0+if (ret) +return -EFAULT ; +if (memcmp (buf, data->verify_buf, len)) +return -EFAULT ; +return 0 ; +} +static int __devinit gpmi_nfc_init (struct gpmi_nand_data *this) {struct mtd_info *mtd = &this->mtd;@@ -1555,6 +1570,7 @@ static int __devinit gpmi_nfc_init(struct gpmi_nand_data * chip->dev_ready = gpmi_dev_ready; chip->read_byte = gpmi_read_byte; chip->read_buf = gpmi_read_buf; + chip->verify_buf = gpmi_verify_buf; chip->write_buf = gpmi_write_buf; chip->ecc.read_page = gpmi_ecc_read_page; chip->ecc.write_page = gpmi_ecc_write_page;(quoted diff) +0
-0b/drivers/mtd/nand/gpmi-nand index 1547a60..cd9bdf7 100644
drivers/mtd/nand/gpmi-nand/gpmi-nand.h struct gpmi_nand_data { · line 151
Quoted 4 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.h +1
-0@@ -148,6 +148,7 @@ struct gpmi_nand_data {/* General-use Variables */ int current_chip;unsigned int command_length; +uint8_t verify_buf[NAND_MAX_PAGESIZE ];
Yes, this is definitelly better.
drivers/mtd/nand/gpmi-nand/gpmi-nand.h static int __devinit gpmi_nand_probe(struct · line 1649
Quoted 11 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.h +0
-0/* passed from upper layer */ uint8_t *upper_buf;and then I can also send this separate change to allow multi-instances:
drivers/mtd/nand/gpmi-nand/gpmi-nand.h +1
-1@@ -1630,7 +1646,7 @@ static int __devinit gpmi_nand_probe(struct platform_devic return -ENOMEM; } - this =kzalloc (sizeof (*this),GFP_KERNEL ); + this =devm_kzalloc (&pdev->dev,sizeof (*this),GFP_KERNEL );
devm_clk_* functions could be used too from a quick glance ... devm_request_irq is in place iirc, but check that too.
drivers/mtd/nand/gpmi-nand/gpmi-nand.h static int __devinit gpmi_nand_probe(struct · line 1652
Quoted 3 lines
drivers/mtd/nand/gpmi-nand/gpmi-nand.h +0
-0if (!this) {pr_err ("Failed to allocate per-device memory\n" );return -ENOMEM ;
Best regards,
Marek Vasut