Skip to contentSkip to conversation

mtd: nand_base: Removed unnecessary command masking

PATCH In review Alexander Shiyan 3 participants 9 messages Feb 28, 2013 – Mar 11, 2013

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

PATCH 1/3 mtd: nand_base: Removed unnecessary command masking

NAND command, passed to cmd_ctrl(), is masked with 0xff. This patch removes this since masking is not necessary and masking is not performed in other places for same call.

---
 drivers/mtd/nand/nand_base.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_base.c +1 -2
index 4321415..13c89c9 100644
@@ -631,8 +631,7 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command,
 	}
 
 	/* Command latch cycle */
-	chip->cmd_ctrl(mtd, command & 0xff,
-		       NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
+	chip->cmd_ctrl(mtd, command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE);
 
 	if (column != -1 || page_addr != -1) {
 		int ctrl = NAND_CTRL_CHANGE | NAND_NCE | NAND_ALE;
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH 2/3 mtd: nand_base: Removed unnecessary cleaning "onfi_version" variable

Variable "onfi_version" is already set to zero before nand_flash_detect_onfi() call, so additional cleaning is not necessary.

---
 drivers/mtd/nand/nand_base.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_base.c +0 -2
index 13c89c9..382b857 100644
@@ -2888,8 +2888,6 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip,
 		chip->onfi_version = 20;
 	else if (val & (1 << 1))
 		chip->onfi_version = 10;
-	else
-		chip->onfi_version = 0;
 
 	if (!chip->onfi_version) {
 		pr_info("%s: unsupported ONFI version: %d\n", __func__, val);
Signature · 1 line
1.7.3.4
#3 lore raw

PATCH 3/3 mtd: nand_base: Use readsb/readsw/writesb/writesw if possible

In reply to Alexander Shiyan

This patch provide using readsb/readsw/writesb/writesw functions if it possible for particular platform.

---
 drivers/mtd/nand/nand_base.c |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_base.c +24 -5
index 382b857..4efde01 100644
@@ -214,11 +214,16 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr)
  */
 static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-	int i;
 	struct nand_chip *chip = mtd->priv;
 
+#ifndef writesb
+	int i;
+
 	for (i = 0; i < len; i++)
 		writeb(buf[i], chip->IO_ADDR_W);
+#else
+	writesb(chip->IO_ADDR_W, buf, len);
+#endif
 }
 
 /**
@@ -231,11 +236,16 @@ static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  */
 static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-	int i;
 	struct nand_chip *chip = mtd->priv;
 
+#ifndef readsb
+	int i;
+
 	for (i = 0; i < len; i++)
 		buf[i] = readb(chip->IO_ADDR_R);
+#else
+	readsb(chip->IO_ADDR_R, buf, len);
+#endif
 }
 
 /**
@@ -248,14 +258,18 @@ static void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
  */
 static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
 {
-	int i;
 	struct nand_chip *chip = mtd->priv;
 	u16 *p = (u16 *) buf;
 	len >>= 1;
 
+#ifndef writesw
+	int i;
+
 	for (i = 0; i < len; i++)
 		writew(p[i], chip->IO_ADDR_W);
-
+#else
+	writesw(chip->IO_ADDR_W, p, len);
+#endif
 }
 
 /**
@@ -268,13 +282,18 @@ static void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len)
  */
 static void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len)
 {
-	int i;
 	struct nand_chip *chip = mtd->priv;
 	u16 *p = (u16 *) buf;
 	len >>= 1;
 
+#ifndef readsw
+	int i;
+
 	for (i = 0; i < len; i++)
 		p[i] = readw(chip->IO_ADDR_R);
+#else
+	readsw(chip->IO_ADDR_R, p, len);
+#endif
 }
 
 /**
Signature · 1 line
1.7.3.4
#4 lore raw

Re: [PATCH 3/3] mtd: nand_base: Use readsb/readsw/writesb/writesw if possible

Hi Alexander,

I'm not an expert on IO accessors, but since you asked...

Quoted 2 lines · Alexander Shiyan

This patch provide using readsb/readsw/writesb/writesw functions if it possible for particular platform.

The commit description does not give enough motivation. Should this improve performance? Or is this just a "cleanup"? (If the latter, then it fails, as the resulting code is much less clean.)

Quoted 10 lines
---
  drivers/mtd/nand/nand_base.c |   29 ++++++++++++++++++++++++-----
  1 files changed, 24 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 382b857..4efde01 100644

drivers/mtd/nand/nand_base.c static void nand_select_chip(struct mtd_info *mtd, int chipnr) · line 219

Quoted 7 lines
drivers/mtd/nand/nand_base.c +1 -1
@@ -214,11 +214,16 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr)
   */
  static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  {
-	int i;
  	struct nand_chip *chip = mtd->priv;
 
+#ifndef writesb

No one guarantees that 'writesb' will be a macro and not a static inline function, do they?

drivers/mtd/nand/nand_base.c static void nand_select_chip(struct mtd_info *mtd, int chipnr) · line 227

Quoted 8 lines
drivers/mtd/nand/nand_base.c +5 -0
+	int i;
+
  	for (i = 0; i < len; i++)
  		writeb(buf[i], chip->IO_ADDR_W);
+#else
+	writesb(chip->IO_ADDR_W, buf, len);
+#endif
  }

These #ifndef's are very ugly and are likely the wrong way(TM). The first question I ask when I see this is: why isn't this interface available on all platforms? In fact, it seems like it has been dropped from the asm-generic headers and specifically recommended against. See:

commit b2656a138ab7bc4e7abd3b1cbd6d1f105c7a7186

Author: Will Deacon <[email protected]>
Date:   Wed Oct 17 16:45:01 2012 +0100

asm-generic: io: remove {read,write} string functions

Quote: "We should encourage driver writers to use the io{read,write}{8,16,32}_rep functions instead."

So, an alternative patch might use iowrite8_rep() here unconditionally.

drivers/mtd/nand/nand_base.c static void nand_select_chip(struct mtd_info *mtd, int chipnr) · line 228

Quoted 1 line
drivers/mtd/nand/nand_base.c +0 -0
  /**

<snipped the rest; same comments apply>

Brian

#5 lore raw

Re[2]: [PATCH 3/3] mtd: nand_base: Use readsb/readsw/writesb/writesw if possible

Quoted 11 lines

Hi Alexander,

I'm not an expert on IO accessors, but since you asked...

Quoted 2 lines · Alexander Shiyan

This patch provide using readsb/readsw/writesb/writesw functions if it possible for particular platform.

The commit description does not give enough motivation. Should this improve performance? Or is this just a "cleanup"? (If the latter, then it fails, as the resulting code is much less clean.)

Basic idea is a performance, because architecture may have a improved functions for multiple read/write.

Quoted 40 lines
Quoted 11 lines
---
  drivers/mtd/nand/nand_base.c |   29 ++++++++++++++++++++++++-----
  1 files changed, 24 insertions(+), 5 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 382b857..4efde01 100644

drivers/mtd/nand/nand_base.c static void nand_select_chip(struct mtd_info *mtd, int chipnr) · line 219

Quoted 7 lines
drivers/mtd/nand/nand_base.c +1 -1
@@ -214,11 +214,16 @@ static void nand_select_chip(struct mtd_info *mtd, int chipnr)
   */
  static void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
  {
-	int i;
  	struct nand_chip *chip = mtd->priv;
 
+#ifndef writesb

No one guarantees that 'writesb' will be a macro and not a static inline function, do they?

drivers/mtd/nand/nand_base.c static void nand_select_chip(struct mtd_info *mtd, int chipnr) · line 227

Quoted 8 lines
drivers/mtd/nand/nand_base.c +5 -0
+	int i;
+
  	for (i = 0; i < len; i++)
  		writeb(buf[i], chip->IO_ADDR_W);
+#else
+	writesb(chip->IO_ADDR_W, buf, len);
+#endif
  }

These #ifndef's are very ugly and are likely the wrong way(TM). The first question I ask when I see this is: why isn't this interface available on all platforms? In fact, it seems like it has been dropped from the asm-generic headers and specifically recommended against. See:

commit b2656a138ab7bc4e7abd3b1cbd6d1f105c7a7186

Author: Will Deacon <[email protected]>
Date:   Wed Oct 17 16:45:01 2012 +0100
Quoted 6 lines

asm-generic: io: remove {read,write} string functions

Quote: "We should encourage driver writers to use the io{read,write}{8,16,32}_rep functions instead."

So, an alternative patch might use iowrite8_rep() here unconditionally.

Indeed. So I can remade patch to use ioread/iowrite and remove unnecessary #ifdefs if you have not additional comments.

---

#6 lore raw
In reply to Alexander Shiyan
Quoted 3 lines · Alexander Shiyan

NAND command, passed to cmd_ctrl(), is masked with 0xff. This patch removes this since masking is not necessary and masking is not performed in other places for same call.

As I commented on the other thread, this is not a sufficient explanation. AG-AND (soon to be removed) may use a fake 9-bit command which could expect this masking, even though masking is not done everywhere. Please document why the command does not need to be masked.

Thanks,
Brian

#7 lore raw
Quoted 10 lines · Alexander Shiyan
Quoted 3 lines

NAND command, passed to cmd_ctrl(), is masked with 0xff. This patch removes this since masking is not necessary and masking is not performed in other places for same call.

As I commented on the other thread, this is not a sufficient explanation. AG-AND (soon to be removed) may use a fake 9-bit command which could expect this masking, even though masking is not done everywhere. Please document why the command does not need to be masked.

I think the best if Artem take this part into his patch. And what about [3/3] part?

---

#8 lore raw
In reply to Alexander Shiyan
Quoted 5 lines · Alexander Shiyan

NAND command, passed to cmd_ctrl(), is masked with 0xff. This patch removes this since masking is not necessary and masking is not performed in other places for same call.

Pushed patches 1 and 2 to l2-mtd.git. Did not take patch 3. Thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy