mtd: rawnand: bcm47xx: Convert to exec_op() (and more)
Subsystems (3)
v2 cover mtd: rawnand: bcm47xx: Convert to exec_op() (and more)
Hello,
A bit of context to explain the motivation behind those conversions I've been sending for the last couple of weeks. The raw NAND subsystem carries a lot of history which makes any rework not only painful, but also subject to regressions which we only detect when someone dares to update its kernel on one of those ancient HW. While carrying drivers for old HW is not a problem per se, carrying ancient and unmaintained drivers that are not converted to new APIs is a maintenance burden, hence this massive conversion attempt I'm conducting here.
So here is a series converting the BCM47XX NAND controller driver to exec_op(), plus a bunch of minor improvements done along the way. I hope I'll find someone to test those changes, but if there's no one still having access to this HW or no interest in keeping it supported in recent kernel versions, we should definitely consider removing the driver instead.
No major changes in this v2, apart from fixes for things reported by Miquel. See the changelog on each patch for more details.
Regards,
Boris
Boris Brezillon (8):
mtd: rawnand: Add an is_last flag to nand_subop
mtd: rawnand: bcm47xx: Drop dependency on BCMA
mtd: rawnand: bcm47xx: Allow compiling the driver when COMPILE_TEST=y
mtd: rawnand: bcm47xx: Demistify a few more things
mtd: rawnand: bcm47xx: Implement the exec_op() interface
mtd: rawnand: bcm47xx: Get rid of the legacy implementation
mtd: rawnand: bcm47xx: Simplify the init() function
mtd: rawnand: bcm47xx: Merge all source files
drivers/mtd/nand/raw/Kconfig | 3 +- drivers/mtd/nand/raw/Makefile | 2 +- .../mtd/nand/raw/bcm47xx-nand-controller.c | 343 +++++++++++++ drivers/mtd/nand/raw/bcm47xxnflash/Makefile | 5 - .../nand/raw/bcm47xxnflash/bcm47xxnflash.h | 26 - drivers/mtd/nand/raw/bcm47xxnflash/main.c | 77 --- .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 450 ------------------ drivers/mtd/nand/raw/nand_base.c | 2 + include/linux/mtd/rawnand.h | 2 + 9 files changed, 349 insertions(+), 561 deletions(-) create mode 100644 drivers/mtd/nand/raw/bcm47xx-nand-controller.c delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/Makefile delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/main.c delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c
Signature · 1 line
2.25.4
PATCH v2 1/8 mtd: rawnand: Add an is_last flag to nand_subop
Some controllers need to know when they're passed the last subop so they can de-assert the CE pin.
---
Changes in v2:
* Add R-b
--- drivers/mtd/nand/raw/nand_base.c | 2 ++ include/linux/mtd/rawnand.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/mtd/nand/raw/nand_base.c +2 -0
@@ -2169,6 +2169,8 @@ nand_op_parser_match_pat(const struct nand_op_parser_pattern *pat,*/ ctx->subop.ninstrs = ninstrs; ctx->subop.last_instr_end_off = instr_offset; +if (ctx->subop.instrs + ninstrs == end && !instr_offset) + ctx->subop.is_last = true;return true; }
include/linux/mtd/rawnand.h +2 -0
@@ -715,6 +715,7 @@ struct nand_op_instr {* of the sub-operation * @last_instr_end_off: offset to end at (excluded) for the last instruction * of the sub-operation +* @is_last: this sub-operation is the last one * * Both @first_instr_start_off and @last_instr_end_off only apply to data or * address instructions.
@@ -728,6 +729,7 @@ struct nand_subop {unsigned int ninstrs;unsigned int first_instr_start_off;unsigned int last_instr_end_off; +bool is_last; }; unsigned int nand_subop_get_addr_start_off(const struct nand_subop *subop,
Signature · 1 line
2.25.4
PATCH v2 2/8 mtd: rawnand: bcm47xx: Drop dependency on BCMA
In reply to Boris BrezillonBCMA_NFLASH can only be selected if BCMA is enabled and we already depend on BCMA_NFLASH, making the dependency on BCMA useless.
---
Changes in v2:
* None
--- drivers/mtd/nand/raw/Kconfig | 1 - 1 file changed, 1 deletion(-)
drivers/mtd/nand/raw/Kconfig +0 -1
@@ -243,7 +243,6 @@ config MTD_NAND_BRCMNAND config MTD_NAND_BCM47XXNFLASH tristate "BCM4706 BCMA NAND controller" depends on BCMA_NFLASH - depends on BCMA help BCMA bus can have various flash memories attached, they are registered by bcma as platform devices. This enables driver for
Signature · 1 line
2.25.4
PATCH v2 3/8 mtd: rawnand: bcm47xx: Allow compiling the driver when COMPILE_TEST=y
In reply to Boris BrezillonMakes it easier to spot compile-time issues.
---
Changes in v2:
* None
--- drivers/mtd/nand/raw/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/Kconfig +1 -1
@@ -242,7 +242,7 @@ config MTD_NAND_BRCMNAND config MTD_NAND_BCM47XXNFLASH tristate "BCM4706 BCMA NAND controller" - depends on BCMA_NFLASH + depends on BCMA_NFLASH || COMPILE_TEST help BCMA bus can have various flash memories attached, they are registered by bcma as platform devices. This enables driver for
Signature · 1 line
2.25.4
PATCH v2 4/8 mtd: rawnand: bcm47xx: Demistify a few more things
In reply to Boris BrezillonThere were a few places where raw hex values were used instead of the register/field definitions. Let's replace them by proper definitions.
---
Changes in v2:
* Fix the commit message
* Fix a typo in a comment
* Add R-b
--- .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-)
drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c +27 -7
@@ -25,12 +25,29 @@#define NCTL_CMD1W 0x00080000#define NCTL_READ 0x00100000#define NCTL_WRITE 0x00200000 +/* When the SPECADDR is set CMD1 is interpreted as a single ADDR cycle */ #define NCTL_SPECADDR 0x01000000#define NCTL_READY 0x04000000#define NCTL_ERR 0x08000000 +/* +* Number of DATA cycles to issue when NCTL_{READ,WRITE} is set. The minimum +* value is 1 and the maximum value is 4. Those bytes are then stored in the +* BCMA_CC_NFLASH_DATA register. +*/ +#define NCTL_DATA_CYCLES (x) ((((x) - 1) & 0x3) << 28) +/* +* The CS pin seems to be asserted even if NCTL_CSA is not set. All this bit +* seems to encode is whether the CS line should stay asserted after the +* operation has been executed. In other words, you should only set it if you +* intend to do more operations on the NAND bus. +*/ #define NCTL_CSA 0x40000000#define NCTL_START 0x80000000 +#define CONF_MAGIC_BIT 0x00000002 +#define CONF_COL_BYTES (x) (((x) - 1) << 4) +#define CONF_ROW_BYTES (x) (((x) - 1) << 6) +/************************************************** * Various helpers **************************************************/
@@ -118,7 +135,7 @@ static void bcm47xxnflash_ops_bcm4706_read(struct mtd_info *mtd, uint8_t *buf,/* Eventually read some data :) */ for (i =0 ; i < toread; i +=4 , dest++) { - ctlcode =NCTL_CSA |0x30000000 |NCTL_READ ; + ctlcode =NCTL_CSA |NCTL_DATA_CYCLES (4 ) |NCTL_READ ;if (i == toread -4 )/* Last read goes without that */ ctlcode &= ~NCTL_CSA ; if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc,
@@ -150,7 +167,7 @@ static void bcm47xxnflash_ops_bcm4706_write(struct mtd_info *mtd,for (i =0 ; i < len; i +=4 , data++) {bcma_cc_write32 (cc,BCMA_CC_NFLASH_DATA , *data); - ctlcode =NCTL_CSA |0x30000000 |NCTL_WRITE ; + ctlcode =NCTL_CSA |NCTL_DATA_CYCLES (4 ) |NCTL_WRITE ;if (i == len -4 )/* Last read goes without that */ ctlcode &= ~NCTL_CSA ;if (bcm47xxnflash_ops_bcm4706_ctl_cmd (cc, ctlcode)) {
@@ -229,7 +246,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct nand_chip *nand_chip,nand_wait_ready (nand_chip);break ;case NAND_CMD_READID : - ctlcode =NCTL_CSA |0x01000000 |NCTL_CMD1W |NCTL_CMD0 ; + ctlcode =NCTL_CSA |NCTL_SPECADDR |NCTL_CMD1W |NCTL_CMD0 ; ctlcode |=NAND_CMD_READID ;if (bcm47xxnflash_ops_bcm4706_ctl_cmd (b47n->cc, ctlcode)) {pr_err ("READID error\n" );
@@ -242,7 +259,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct nand_chip *nand_chip,* to perform, so cache everything. */ for (i =0 ; i <ARRAY_SIZE (b47n->id_data); i++) { - ctlcode =NCTL_CSA |NCTL_READ ; + ctlcode =NCTL_CSA |NCTL_READ |NCTL_DATA_CYCLES (1 );if (i ==ARRAY_SIZE (b47n->id_data) -1 ) ctlcode &= ~NCTL_CSA ; if (bcm47xxnflash_ops_bcm4706_ctl_cmd(b47n->cc,
@@ -285,7 +302,7 @@ static void bcm47xxnflash_ops_bcm4706_cmdfunc(struct nand_chip *nand_chip, b47n->curr_page_addr);/* Prepare to write */ - ctlcode =0x40000000 |NCTL_ROW |NCTL_COL |NCTL_CMD0 ; + ctlcode =NCTL_CSA |NCTL_ROW |NCTL_COL |NCTL_CMD0 ; ctlcode |=NAND_CMD_SEQIN ;if (bcm47xxnflash_ops_bcm4706_ctl_cmd (cc, ctlcode))pr_err ("SEQIN failed\n" );
@@ -320,7 +337,9 @@ static u8 bcm47xxnflash_ops_bcm4706_read_byte(struct nand_chip *nand_chip) }return b47n->id_data[b47n->curr_column++];case NAND_CMD_STATUS : -if (bcm47xxnflash_ops_bcm4706_ctl_cmd (cc,NCTL_READ )) +if (bcm47xxnflash_ops_bcm4706_ctl_cmd (cc, +NCTL_READ | +NCTL_DATA_CYCLES (1 )))return 0 ;return bcma_cc_read32 (cc,BCMA_CC_NFLASH_DATA ) &0xff ;case NAND_CMD_READOOB :
@@ -439,7 +458,8 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) row_bits = tbits - col_bits +1 ; row_bsize = (row_bits +7 ) /8 ; - val = ((row_bsize -1 ) <<6 ) | ((col_size -1 ) <<4 ) |2 ; + val =CONF_ROW_BYTES (row_bsize) |CONF_COL_BYTES (col_size) | +CONF_MAGIC_BIT ;bcma_cc_write32 (b47n->cc,BCMA_CC_NFLASH_CONF , val); exit:
Signature · 1 line
2.25.4
PATCH v2 5/8 mtd: rawnand: bcm47xx: Implement the exec_op() interface
In reply to Boris BrezillonImplement the exec_op() interface so we can get rid of the convoluted cmdfunc() implementation.
---
This is based on my understanding of how this controller works, and I think it covers all the use cases covered by the custom cmdfunc() implementation. I might be wrong of course, so it'd be great to have someone test on real HW.
Changes in v2:
* s/i/j/ in exec_cmd_addr()
* Drop WARN_ON()s
--- .../nand/raw/bcm47xxnflash/bcm47xxnflash.h | 1 + .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 140 ++++++++++++++++++ 2 files changed, 141 insertions(+)
drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h +1 -0
@@ -10,6 +10,7 @@#include <linux/mtd/rawnand.h> struct bcm47xxnflash { +struct nand_controller base;struct bcma_drv_cc *cc;struct nand_chip nand_chip;
drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c +140 -0
152 lines not on this page · raw message
Signature · 1 line
2.25.4
PATCH v2 6/8 mtd: rawnand: bcm47xx: Get rid of the legacy implementation
In reply to Boris BrezillonNow that exec_op() is implemented we don't need to implement all those legacy hooks, which simplifies the code quite a bit.
---
Changes in v2:
* Add R-b
--- .../nand/raw/bcm47xxnflash/bcm47xxnflash.h | 6 - .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 315 ------------------ 2 files changed, 321 deletions(-)
drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h +0 -6
@@ -14,12 +14,6 @@ struct bcm47xxnflash {struct bcma_drv_cc *cc;struct nand_chip nand_chip; - -unsigned curr_command; -int curr_page_addr; -int curr_column; - -u8 id_data[8 ]; };int bcm47xxnflash_ops_bcm4706_init (struct bcm47xxnflash *b47n);
drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c +0 -315
337 lines not on this page · raw message
Signature · 1 line
2.25.4
PATCH v2 7/8 mtd: rawnand: bcm47xx: Simplify the init() function
In reply to Boris BrezillonThe row and column sizes are now set as part of the exec_op() procedure and adjusted to match the requested number of address cycles. No need to set them in the init() function since those values will be overwritten anyway. As for the other sanity check that was done on the chip size, I don't think it's really needed.
---
Changes in v2:
* Add R-b
--- .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 31 ++----------------- 1 file changed, 2 insertions(+), 29 deletions(-)
drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c +2 -29
@@ -227,10 +227,6 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n)u16 clock;u8 w0, w1, w2, w3, w4; -unsigned long chipsize;/* MiB */ -u8 tbits, col_bits, col_size, row_bits, row_bsize; -u32 val; -nand_controller_init (&b47n->base); b47n->base.ops = &bcm47xxnflash_ops; b47n->nand_chip.controller = &b47n->base;
@@ -264,32 +260,9 @@ int bcm47xxnflash_ops_bcm4706_init(struct bcm47xxnflash *b47n) err =nand_scan (&b47n->nand_chip,1 );if (err) {pr_err ("Could not scan NAND flash: %d\n" , err); - goto exit; - } - -/* Configure FLASH */ - chipsize =nanddev_target_size (&b47n->nand_chip.base) >>20 ; - tbits =ffs (chipsize);/* find first bit set */ -if (!tbits || tbits !=fls (chipsize)) { -pr_err ("Invalid flash size: 0x%lX\n" , chipsize); - err = -ENOTSUPP ; - goto exit; - } - tbits +=19 ;/* Broadcom increases *index* by 20, we increase *pos* */ - - col_bits = b47n->nand_chip.page_shift +1 ; - col_size = (col_bits +7 ) /8 ; - - row_bits = tbits - col_bits +1 ; - row_bsize = (row_bits +7 ) /8 ; - - val =CONF_ROW_BYTES (row_bsize) |CONF_COL_BYTES (col_size) | -CONF_MAGIC_BIT ; -bcma_cc_write32 (b47n->cc,BCMA_CC_NFLASH_CONF , val); - -exit: -if (err)bcma_cc_mask32 (b47n->cc,BCMA_CC_4706_FLASHSCFG , ~BCMA_CC_4706_FLASHSCFG_NF1 ); + } +return err; }
Signature · 1 line
2.25.4
PATCH v2 8/8 mtd: rawnand: bcm47xx: Merge all source files
In reply to Boris BrezillonGiven the number of lines it doesn't make sense to split the code. Let's merge everything and move the driver to drivers/mtd/nand/raw.
---
Changes in v2:
* Fix the Makefile entry
* Merge commits doing the source merge and the file move
* Rename the driver bcm47xx-nand-controller
---
drivers/mtd/nand/raw/Makefile | 2 +-
...ps_bcm4706.c => bcm47xx-nand-controller.c} | 81 ++++++++++++++++++-
drivers/mtd/nand/raw/bcm47xxnflash/Makefile | 5 --
.../nand/raw/bcm47xxnflash/bcm47xxnflash.h | 21 -----
drivers/mtd/nand/raw/bcm47xxnflash/main.c | 77 ------------------
5 files changed, 79 insertions(+), 107 deletions(-)
rename drivers/mtd/nand/raw/{bcm47xxnflash/ops_bcm4706.c => bcm47xx-nand-controller.c} (81%)
delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/Makefile
delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h
delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/main.cdrivers/mtd/nand/raw/Makefile +1 -1
@@ -47,7 +47,7 @@ obj-$(CONFIG_MTD_NAND_RICOH) += r852.o obj-y += ingenic/ obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/ obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o -obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/ +obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xx-nand-controller.o obj-$(CONFIG_MTD_NAND_SUNXI) += sunxi_nand.o obj-$(CONFIG_MTD_NAND_HISI504) += hisi504_nand.o obj-$(CONFIG_MTD_NAND_BRCMNAND) += brcmnand/
drivers/mtd/nand/raw/bcm47xx-nand-controller.c renamed from drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c +78 -3
100 lines not on this page · raw message
drivers/mtd/nand/raw/bcm47xxnflash/Makefile deleted +0 -5
@@ -1,5 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -bcm47xxnflash-y += main.o -bcm47xxnflash-y += ops_bcm4706.o - -obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash.o
drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __BCM47XXNFLASH_H -#define __BCM47XXNFLASH_H - -#ifndef pr_fmt -#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#endif - -#include <linux/mtd/mtd.h> -#include <linux/mtd/rawnand.h> - -struct bcm47xxnflash { -struct nand_controller base; -struct bcma_drv_cc *cc; - -struct nand_chip nand_chip; -}; - -int bcm47xxnflash_ops_bcm4706_init (struct bcm47xxnflash *b47n); - -#endif /* BCM47XXNFLASH */
drivers/mtd/nand/raw/bcm47xxnflash/main.c deleted +0 -77
77 lines not on this page · raw message
Signature · 1 line
2.25.4
Miquel Raynal
maintainerHello,
Boris Brezillon <[email protected]> wrote on Mon, 18 May 2020 18:28:29 +0200:
Quoted 35 lines
Hello,
A bit of context to explain the motivation behind those conversions I've been sending for the last couple of weeks. The raw NAND subsystem carries a lot of history which makes any rework not only painful, but also subject to regressions which we only detect when someone dares to update its kernel on one of those ancient HW. While carrying drivers for old HW is not a problem per se, carrying ancient and unmaintained drivers that are not converted to new APIs is a maintenance burden, hence this massive conversion attempt I'm conducting here.
So here is a series converting the BCM47XX NAND controller driver to
exec_op(), plus a bunch of minor improvements done along the way. I hope I'll find someone to test those changes, but if there's no one still having access to this HW or no interest in keeping it supported in recent kernel versions, we should definitely consider removing the driver instead.No major changes in this v2, apart from fixes for things reported by Miquel. See the changelog on each patch for more details.
Regards,
Boris
Boris Brezillon (8):
mtd: rawnand: Add anis_lastflag tonand_subop
mtd: rawnand: bcm47xx: Drop dependency on BCMA
mtd: rawnand: bcm47xx: Allow compiling the driver when COMPILE_TEST=y
mtd: rawnand: bcm47xx: Demistify a few more things
mtd: rawnand: bcm47xx: Implement theexec_op()interface
mtd: rawnand: bcm47xx: Get rid of the legacy implementation
mtd: rawnand: bcm47xx: Simplify theinit()function
mtd: rawnand: bcm47xx: Merge all source files
Quoted 16 lines
drivers/mtd/nand/raw/Kconfig | 3 +- drivers/mtd/nand/raw/Makefile | 2 +- .../mtd/nand/raw/bcm47xx-nand-controller.c | 343 +++++++++++++ drivers/mtd/nand/raw/bcm47xxnflash/Makefile | 5 - .../nand/raw/bcm47xxnflash/bcm47xxnflash.h | 26 - drivers/mtd/nand/raw/bcm47xxnflash/main.c | 77 --- .../mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c | 450 ------------------ drivers/mtd/nand/raw/nand_base.c | 2 + include/linux/mtd/rawnand.h | 2 + 9 files changed, 349 insertions(+), 561 deletions(-) create mode 100644 drivers/mtd/nand/raw/bcm47xx-nand-controller.c delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/Makefile delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/bcm47xxnflash.h delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/main.c delete mode 100644 drivers/mtd/nand/raw/bcm47xxnflash/ops_bcm4706.c
Anyone to test this series?
If not I will apply it as soon as v5.8-rc1 is released.
Thanks,
Miquèl