Skip to contentSkip to conversation

mtd: rawnand: meson: handle OOB buffer according OOB layout

PATCH Applied Arseniy Krasnov 3 participants 7 messages Nov 9, 2023 – Nov 30, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: rawnand: meson: handle OOB buffer according OOB layout

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
 drivers/mtd/nand/raw/meson_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +2 -2
index 561d46d860b7..0d4d358152d7 100644
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		*info |= oob_buf[count];
 		*info |= oob_buf[count + 1] << 8;
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		oob_buf[count] = *info;
 		oob_buf[count + 1] = *info >> 8;
Signature · 6 lines
2.35.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

Hi!

Quoted 13 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
 drivers/mtd/nand/raw/meson_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 561d46d860b7..0d4d358152d7 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 516

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		*info |= oob_buf[count];
 		*info |= oob_buf[count + 1] << 8;

Seems something wrong with your logic here. I think this code should most likely look like this:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    *info |= oob_buf[count];
    if (nand->ecc.bytes > 1)
      *info |= oob_buf[count + 1] << 8;
}

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 529

Quoted 9 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		oob_buf[count] = *info;
 		oob_buf[count + 1] = *info >> 8;

And there:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    oob_buf[count] = *info;
    if (nand->ecc.bytes > 1)
        oob_buf[count + 1] = *info >> 8;
}

This is more similar to the behavior of similar functions in the proprietary U-Boot.

--
Viacheslav Bocharov

#2 lore raw

Hello, thanks for review!

Quoted 27 lines · Viacheslav Bocharov

Hi!

Quoted 13 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
 drivers/mtd/nand/raw/meson_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 561d46d860b7..0d4d358152d7 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 516

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		*info |= oob_buf[count];
 		*info |= oob_buf[count + 1] << 8;

Seems something wrong with your logic here. I think this code should most likely look like this:

Quoted 6 lines
for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    *info |= oob_buf[count];
    if (nand->ecc.bytes > 1)
      *info |= oob_buf[count + 1] << 8;
}

For 64 bytes OOB and 512 bytes ECC this driver reports free areas as:

AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB

where AA is free byte(user byte), BB - ECC codes. So to access user bytes we need bytes 0,1,16,17,32,33,48,49. nand->ecc.bytes == 14, so 'count' is increased at 16 every iteration, so i guess this is correct.

WDYT?

Thanks, Arseniy

Quoted 26 lines

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 529

Quoted 11 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		oob_buf[count] = *info;
 		oob_buf[count + 1] = *info >> 8;

And there:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    oob_buf[count] = *info;
    if (nand->ecc.bytes > 1)
        oob_buf[count + 1] = *info >> 8;
}

This is more similar to the behavior of similar functions in the proprietary U-Boot.

--
Viacheslav Bocharov

#3 lore raw

Hello all, 2 weeks from 9.11, please ping

Thanks, Arseniy

Quoted 44 lines · Arseniy Krasnov

Hello, thanks for review!

Quoted 27 lines · Viacheslav Bocharov

Hi!

Quoted 13 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
 drivers/mtd/nand/raw/meson_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 561d46d860b7..0d4d358152d7 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 516

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		*info |= oob_buf[count];
 		*info |= oob_buf[count + 1] << 8;

Seems something wrong with your logic here. I think this code should most likely look like this:

Quoted 6 lines
for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    *info |= oob_buf[count];
    if (nand->ecc.bytes > 1)
      *info |= oob_buf[count + 1] << 8;
}

For 64 bytes OOB and 512 bytes ECC this driver reports free areas as:

AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB

Quoted 34 lines

where AA is free byte(user byte), BB - ECC codes. So to access user bytes we need bytes 0,1,16,17,32,33,48,49. nand->ecc.bytes == 14, so 'count' is increased at 16 every iteration, so i guess this is correct.

WDYT?

Thanks, Arseniy

Quoted 26 lines

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 529

Quoted 11 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		oob_buf[count] = *info;
 		oob_buf[count + 1] = *info >> 8;

And there:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    oob_buf[count] = *info;
    if (nand->ecc.bytes > 1)
        oob_buf[count + 1] = *info >> 8;
}

This is more similar to the behavior of similar functions in the proprietary U-Boot.

--
Viacheslav Bocharov

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

maintainer
#4 lore raw

Hi Arseniy,

[email protected] wrote on Fri, 24 Nov 2023 10:50:54 +0300:

Quoted 1 line

Hello all, 2 weeks from 9.11, please ping

I'm waiting for Viacheslav.

Quoted 83 lines

Thanks, Arseniy

Quoted 78 lines · Arseniy Krasnov

Hello, thanks for review!

Quoted 27 lines · Viacheslav Bocharov

Hi!

Quoted 13 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
 drivers/mtd/nand/raw/meson_nand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 561d46d860b7..0d4d358152d7 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 516

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		*info |= oob_buf[count];
 		*info |= oob_buf[count + 1] << 8;  

Seems something wrong with your logic here. I think this code should most likely look like this:

Quoted 6 lines
for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    *info |= oob_buf[count];
    if (nand->ecc.bytes > 1)
      *info |= oob_buf[count + 1] << 8;
}  

For 64 bytes OOB and 512 bytes ECC this driver reports free areas as:

AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB

where AA is free byte(user byte), BB - ECC codes. So to access user bytes we need bytes 0,1,16,17,32,33,48,49. nand->ecc.bytes == 14, so 'count' is increased at 16 every iteration, so i guess this is correct.

WDYT?

Thanks, Arseniy

Quoted 26 lines

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 529

Quoted 11 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
 	__le64 *info;
 	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
 		info = &meson_chip->info_buf[i];
 		oob_buf[count] = *info;
 		oob_buf[count + 1] = *info >> 8;  

And there:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
    info = &meson_chip->info_buf[i];
    oob_buf[count] = *info;
    if (nand->ecc.bytes > 1)
        oob_buf[count + 1] = *info >> 8;
}

This is more similar to the behavior of similar functions in the proprietary U-Boot.

--
Viacheslav Bocharov

Thanks,
Miquèl

#5 lore raw

Hi, Miquel!

Quoted 7 lines · Miquel Raynal

Hi Arseniy,

[email protected] wrote on Fri, 24 Nov 2023 10:50:54 +0300:

Quoted 1 line

Hello all, 2 weeks from 9.11, please ping

I'm waiting for Viacheslav.

We discussed this update with Arseniy. My suggestion was based on the difference in patch from the algorithms used in amlogic u-boot. Arseniy claims that everything works for them.

Unfortunately, I don't have the devices available to test this.

Quoted 81 lines
Quoted 81 lines

Thanks, Arseniy

Quoted 75 lines · Arseniy Krasnov

Hello, thanks for review!

Quoted 27 lines · Viacheslav Bocharov

Hi!

Quoted 13 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

---
  drivers/mtd/nand/raw/meson_nand.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/meson_nand.c +0 -0
index 561d46d860b7..0d4d358152d7 100644

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 516

Quoted 8 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -510,7 +510,7 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf)
  	__le64 *info;
  	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
  		info = &meson_chip->info_buf[i];
  		*info |= oob_buf[count];
  		*info |= oob_buf[count + 1] << 8;

Seems something wrong with your logic here. I think this code should most likely look like this:

Quoted 6 lines
for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
     info = &meson_chip->info_buf[i];
     *info |= oob_buf[count];
     if (nand->ecc.bytes > 1)
       *info |= oob_buf[count + 1] << 8;
}

For 64 bytes OOB and 512 bytes ECC this driver reports free areas as:

AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB
AA AA BB BB BB BB BB BB BB BB BB BB BB BB BB BB

where AA is free byte(user byte), BB - ECC codes. So to access user bytes we need bytes 0,1,16,17,32,33,48,49. nand->ecc.bytes == 14, so 'count' is increased at 16 every iteration, so i guess this is correct.

WDYT?

Thanks, Arseniy

Quoted 23 lines

drivers/mtd/nand/raw/meson_nand.c static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) · line 529

Quoted 11 lines
drivers/mtd/nand/raw/meson_nand.c +1 -1
@@ -523,7 +523,7 @@ static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf)
  	__le64 *info;
  	int i, count;
 
-	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) {
+	for (i = 0, count = 0; i < nand->ecc.steps; i++, count += (2 + nand->ecc.bytes)) {
  		info = &meson_chip->info_buf[i];
  		oob_buf[count] = *info;
  		oob_buf[count + 1] = *info >> 8;

And there:

for (i = 0, count = 0; i < nand->ecc.steps; i++, count += nand->ecc.bytes) {
     info = &meson_chip->info_buf[i];
     oob_buf[count] = *info;
     if (nand->ecc.bytes > 1)
         oob_buf[count + 1] = *info >> 8;
}

This is more similar to the behavior of similar functions in the proprietary U-Boot.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

--
Viacheslav Bocharov

Thanks,
Miquèl

--
Viacheslav Bocharov

maintainer Applied
#6 lore raw
In reply to Arseniy Krasnov
Quoted 4 lines · Arseniy Krasnov

In case of MTD_OPS_AUTO_OOB mode, MTD/NAND layer fills/reads OOB buffer according current OOB layout so we need to follow it in the driver.

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

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/