On Mon, 4 May 2020 10:24:11 +0200 Miquel Raynal <miquel.raynal@xxxxxxxxxxx> wrote: > We already know that there are controllers not able to read the three > copies of the parameter page in one go. The workaround was to first > request the controller to assert command and address cycles on the > NAND bus to trigger a parameter page read, and then do a read > operation for each page. > > But there are also controllers which are not able to split the > parameter page read between the command/address cycles and the actual > data operation. > > Let's use a regular PARAMETER PAGE READ operation for the first > iteration and use eithe a CHANGE READ COLUMN or a simple DATA READ > operation for the following copies, depending on what the controller > supports. The default for non-exec-op compliant drivers remains > unchanged: use a SIMPLE READ. > > Signed-off-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx> > --- > drivers/mtd/nand/raw/nand_jedec.c | 34 ++++++++++++++++++++----------- > 1 file changed, 22 insertions(+), 12 deletions(-) > > diff --git a/drivers/mtd/nand/raw/nand_jedec.c b/drivers/mtd/nand/raw/nand_jedec.c > index 63069f1948a8..be270b36317e 100644 > --- a/drivers/mtd/nand/raw/nand_jedec.c > +++ b/drivers/mtd/nand/raw/nand_jedec.c > @@ -25,8 +25,9 @@ int nand_jedec_detect(struct nand_chip *chip) > { > struct mtd_info *mtd = nand_to_mtd(chip); > struct nand_memory_organization *memorg; > - struct nand_jedec_params *p; > + struct nand_jedec_params *p = NULL, *pbuf; > struct jedec_ecc_info *ecc; > + bool use_datain = false; > int jedec_version = 0; > char id[5]; > int i, val, ret; > @@ -40,25 +41,32 @@ int nand_jedec_detect(struct nand_chip *chip) > return 0; > > /* JEDEC chip: allocate a buffer to hold its parameter page */ > - p = kzalloc(sizeof(*p), GFP_KERNEL); > - if (!p) > + pbuf = kzalloc(sizeof(*pbuf) * JEDEC_PARAM_PAGES, GFP_KERNEL); > + if (!pbuf) > return -ENOMEM; > > - ret = nand_read_param_page_op(chip, 0x40, NULL, 0); > - if (ret) { > - ret = 0; > - goto free_jedec_param_page; > - } > + if (!nand_has_exec_op(chip) || > + (nand_read_data_op(chip, &pbuf[0], sizeof(*pbuf), true, true) == 0)) > + use_datain = true; > > for (i = 0; i < JEDEC_PARAM_PAGES; i++) { > - ret = nand_read_data_op(chip, p, sizeof(*p), true, false); > + if (!i) > + ret = nand_read_param_page_op(chip, 0x40, &pbuf[i], > + sizeof(*pbuf)); > + else if (use_datain) > + ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf), > + true, false); > + else > + ret = nand_change_read_column_op(chip, sizeof(*pbuf) * i, > + &pbuf[i], sizeof(*pbuf), > + true); Now that you only ever read a page at a time, and given you don't do the majority_bit() thing when all pages are corrupted, I'd suggest sticking to one sizeof(*p) allocation and getting rid of the pbuf var. But it's not a big deal, so feel free to add Reviewed-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx> if you don't want to send a new version. > if (ret) { > ret = 0; > goto free_jedec_param_page; > } > > - crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)p, 510); > - if (crc == le16_to_cpu(p->crc)) > + crc = onfi_crc16(ONFI_CRC_BASE, (u8 *)&pbuf[i], 510); > + if (crc == le16_to_cpu(pbuf[i].crc)) > break; > } > > @@ -67,6 +75,8 @@ int nand_jedec_detect(struct nand_chip *chip) > goto free_jedec_param_page; > } > > + p = &pbuf[i]; > + > /* Check version */ > val = le16_to_cpu(p->revision); > if (val & (1 << 2)) > @@ -122,6 +132,6 @@ int nand_jedec_detect(struct nand_chip *chip) > ret = 1; > > free_jedec_param_page: > - kfree(p); > + kfree(pbuf); > return ret; > } ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/