Skip to content

Commit b451f5b

Browse files
committed
mtd: rawnand: Give the possibility to verify a read operation is supported
This can be used to discriminate between two path in the parameter page detection: use data_in cycles (like before) if supported, use the CHANGE READ COLUMN command otherwise. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Link: https://lore.kernel.org/linux-mtd/20200507105241.14299-9-miquel.raynal@bootlin.com
1 parent 9303702 commit b451f5b

8 files changed

Lines changed: 44 additions & 31 deletions

File tree

‎drivers/mtd/nand/raw/fsmc_nand.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static int fsmc_read_page_hwecc(struct nand_chip *chip, u8 *buf,
694694
for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
695695
nand_read_page_op(chip, page, s * eccsize, NULL, 0);
696696
chip->ecc.hwctl(chip, NAND_ECC_READ);
697-
ret = nand_read_data_op(chip, p, eccsize, false);
697+
ret = nand_read_data_op(chip, p, eccsize, false, false);
698698
if (ret)
699699
return ret;
700700

‎drivers/mtd/nand/raw/marvell_nand.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,12 +1224,12 @@ static int marvell_nfc_hw_ecc_bch_read_page_raw(struct nand_chip *chip, u8 *buf,
12241224

12251225
/* Read spare bytes */
12261226
nand_read_data_op(chip, oob + (lt->spare_bytes * chunk),
1227-
spare_len, false);
1227+
spare_len, false, false);
12281228

12291229
/* Read ECC bytes */
12301230
nand_read_data_op(chip, oob + ecc_offset +
12311231
(ALIGN(lt->ecc_bytes, 32) * chunk),
1232-
ecc_len, false);
1232+
ecc_len, false, false);
12331233
}
12341234

12351235
return 0;

‎drivers/mtd/nand/raw/nand_base.c‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms)
740740
*/
741741
timeout_ms = jiffies + msecs_to_jiffies(timeout_ms) + 1;
742742
do {
743-
ret = nand_read_data_op(chip, &status, sizeof(status), true);
743+
ret = nand_read_data_op(chip, &status, sizeof(status), true,
744+
false);
744745
if (ret)
745746
break;
746747

@@ -820,7 +821,7 @@ void panic_nand_wait(struct nand_chip *chip, unsigned long timeo)
820821
u8 status;
821822

822823
ret = nand_read_data_op(chip, &status, sizeof(status),
823-
true);
824+
true, false);
824825
if (ret)
825826
return;
826827

@@ -1918,6 +1919,8 @@ EXPORT_SYMBOL_GPL(nand_reset_op);
19181919
* @buf: buffer used to store the data
19191920
* @len: length of the buffer
19201921
* @force_8bit: force 8-bit bus access
1922+
* @check_only: do not actually run the command, only checks if the
1923+
* controller driver supports it
19211924
*
19221925
* This function does a raw data read on the bus. Usually used after launching
19231926
* another NAND operation like nand_read_page_op().
@@ -1926,7 +1929,7 @@ EXPORT_SYMBOL_GPL(nand_reset_op);
19261929
* Returns 0 on success, a negative error code otherwise.
19271930
*/
19281931
int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
1929-
bool force_8bit)
1932+
bool force_8bit, bool check_only)
19301933
{
19311934
if (!len || !buf)
19321935
return -EINVAL;
@@ -1939,9 +1942,15 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
19391942

19401943
instrs[0].ctx.data.force_8bit = force_8bit;
19411944

1945+
if (check_only)
1946+
return nand_check_op(chip, &op);
1947+
19421948
return nand_exec_op(chip, &op);
19431949
}
19441950

1951+
if (check_only)
1952+
return 0;
1953+
19451954
if (force_8bit) {
19461955
u8 *p = buf;
19471956
unsigned int i;
@@ -2670,7 +2679,7 @@ int nand_read_page_raw(struct nand_chip *chip, uint8_t *buf, int oob_required,
26702679

26712680
if (oob_required) {
26722681
ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize,
2673-
false);
2682+
false, false);
26742683
if (ret)
26752684
return ret;
26762685
}
@@ -2702,30 +2711,30 @@ static int nand_read_page_raw_syndrome(struct nand_chip *chip, uint8_t *buf,
27022711
return ret;
27032712

27042713
for (steps = chip->ecc.steps; steps > 0; steps--) {
2705-
ret = nand_read_data_op(chip, buf, eccsize, false);
2714+
ret = nand_read_data_op(chip, buf, eccsize, false, false);
27062715
if (ret)
27072716
return ret;
27082717

27092718
buf += eccsize;
27102719

27112720
if (chip->ecc.prepad) {
27122721
ret = nand_read_data_op(chip, oob, chip->ecc.prepad,
2713-
false);
2722+
false, false);
27142723
if (ret)
27152724
return ret;
27162725

27172726
oob += chip->ecc.prepad;
27182727
}
27192728

2720-
ret = nand_read_data_op(chip, oob, eccbytes, false);
2729+
ret = nand_read_data_op(chip, oob, eccbytes, false, false);
27212730
if (ret)
27222731
return ret;
27232732

27242733
oob += eccbytes;
27252734

27262735
if (chip->ecc.postpad) {
27272736
ret = nand_read_data_op(chip, oob, chip->ecc.postpad,
2728-
false);
2737+
false, false);
27292738
if (ret)
27302739
return ret;
27312740

@@ -2735,7 +2744,7 @@ static int nand_read_page_raw_syndrome(struct nand_chip *chip, uint8_t *buf,
27352744

27362745
size = mtd->oobsize - (oob - chip->oob_poi);
27372746
if (size) {
2738-
ret = nand_read_data_op(chip, oob, size, false);
2747+
ret = nand_read_data_op(chip, oob, size, false, false);
27392748
if (ret)
27402749
return ret;
27412750
}
@@ -2928,14 +2937,15 @@ static int nand_read_page_hwecc(struct nand_chip *chip, uint8_t *buf,
29282937
for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize) {
29292938
chip->ecc.hwctl(chip, NAND_ECC_READ);
29302939

2931-
ret = nand_read_data_op(chip, p, eccsize, false);
2940+
ret = nand_read_data_op(chip, p, eccsize, false, false);
29322941
if (ret)
29332942
return ret;
29342943

29352944
chip->ecc.calculate(chip, p, &ecc_calc[i]);
29362945
}
29372946

2938-
ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, false);
2947+
ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, false,
2948+
false);
29392949
if (ret)
29402950
return ret;
29412951

@@ -3014,7 +3024,7 @@ static int nand_read_page_hwecc_oob_first(struct nand_chip *chip, uint8_t *buf,
30143024

30153025
chip->ecc.hwctl(chip, NAND_ECC_READ);
30163026

3017-
ret = nand_read_data_op(chip, p, eccsize, false);
3027+
ret = nand_read_data_op(chip, p, eccsize, false, false);
30183028
if (ret)
30193029
return ret;
30203030

@@ -3071,13 +3081,13 @@ static int nand_read_page_syndrome(struct nand_chip *chip, uint8_t *buf,
30713081

30723082
chip->ecc.hwctl(chip, NAND_ECC_READ);
30733083

3074-
ret = nand_read_data_op(chip, p, eccsize, false);
3084+
ret = nand_read_data_op(chip, p, eccsize, false, false);
30753085
if (ret)
30763086
return ret;
30773087

30783088
if (chip->ecc.prepad) {
30793089
ret = nand_read_data_op(chip, oob, chip->ecc.prepad,
3080-
false);
3090+
false, false);
30813091
if (ret)
30823092
return ret;
30833093

@@ -3086,7 +3096,7 @@ static int nand_read_page_syndrome(struct nand_chip *chip, uint8_t *buf,
30863096

30873097
chip->ecc.hwctl(chip, NAND_ECC_READSYN);
30883098

3089-
ret = nand_read_data_op(chip, oob, eccbytes, false);
3099+
ret = nand_read_data_op(chip, oob, eccbytes, false, false);
30903100
if (ret)
30913101
return ret;
30923102

@@ -3096,7 +3106,7 @@ static int nand_read_page_syndrome(struct nand_chip *chip, uint8_t *buf,
30963106

30973107
if (chip->ecc.postpad) {
30983108
ret = nand_read_data_op(chip, oob, chip->ecc.postpad,
3099-
false);
3109+
false, false);
31003110
if (ret)
31013111
return ret;
31023112

@@ -3124,7 +3134,7 @@ static int nand_read_page_syndrome(struct nand_chip *chip, uint8_t *buf,
31243134
/* Calculate remaining oob bytes */
31253135
i = mtd->oobsize - (oob - chip->oob_poi);
31263136
if (i) {
3127-
ret = nand_read_data_op(chip, oob, i, false);
3137+
ret = nand_read_data_op(chip, oob, i, false, false);
31283138
if (ret)
31293139
return ret;
31303140
}
@@ -3426,15 +3436,15 @@ static int nand_read_oob_syndrome(struct nand_chip *chip, int page)
34263436
sndrnd = 1;
34273437
toread = min_t(int, length, chunk);
34283438

3429-
ret = nand_read_data_op(chip, bufpoi, toread, false);
3439+
ret = nand_read_data_op(chip, bufpoi, toread, false, false);
34303440
if (ret)
34313441
return ret;
34323442

34333443
bufpoi += toread;
34343444
length -= toread;
34353445
}
34363446
if (length > 0) {
3437-
ret = nand_read_data_op(chip, bufpoi, length, false);
3447+
ret = nand_read_data_op(chip, bufpoi, length, false, false);
34383448
if (ret)
34393449
return ret;
34403450
}

‎drivers/mtd/nand/raw/nand_jedec.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int nand_jedec_detect(struct nand_chip *chip)
5151
}
5252

5353
for (i = 0; i < JEDEC_PARAM_PAGES; i++) {
54-
ret = nand_read_data_op(chip, p, sizeof(*p), true);
54+
ret = nand_read_data_op(chip, p, sizeof(*p), true, false);
5555
if (ret) {
5656
ret = 0;
5757
goto free_jedec_param_page;

‎drivers/mtd/nand/raw/nand_legacy.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ static void nand_wait_status_ready(struct nand_chip *chip, unsigned long timeo)
225225
do {
226226
u8 status;
227227

228-
ret = nand_read_data_op(chip, &status, sizeof(status), true);
228+
ret = nand_read_data_op(chip, &status, sizeof(status), true,
229+
false);
229230
if (ret)
230231
return;
231232

@@ -552,7 +553,8 @@ static int nand_wait(struct nand_chip *chip)
552553
break;
553554
} else {
554555
ret = nand_read_data_op(chip, &status,
555-
sizeof(status), true);
556+
sizeof(status), true,
557+
false);
556558
if (ret)
557559
return ret;
558560

@@ -563,7 +565,7 @@ static int nand_wait(struct nand_chip *chip)
563565
} while (time_before(jiffies, timeo));
564566
}
565567

566-
ret = nand_read_data_op(chip, &status, sizeof(status), true);
568+
ret = nand_read_data_op(chip, &status, sizeof(status), true, false);
567569
if (ret)
568570
return ret;
569571

‎drivers/mtd/nand/raw/nand_micron.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int micron_nand_on_die_ecc_status_4(struct nand_chip *chip, u8 status,
212212
*/
213213
if (!oob_required) {
214214
ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize,
215-
false);
215+
false, false);
216216
if (ret)
217217
return ret;
218218
}
@@ -304,10 +304,10 @@ micron_nand_read_page_on_die_ecc(struct nand_chip *chip, uint8_t *buf,
304304
if (ret)
305305
goto out;
306306

307-
ret = nand_read_data_op(chip, buf, mtd->writesize, false);
307+
ret = nand_read_data_op(chip, buf, mtd->writesize, false, false);
308308
if (!ret && oob_required)
309309
ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize,
310-
false);
310+
false, false);
311311

312312
if (chip->ecc.strength == 4)
313313
max_bitflips = micron_nand_on_die_ecc_status_4(chip, status,

‎drivers/mtd/nand/raw/nand_onfi.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ int nand_onfi_detect(struct nand_chip *chip)
167167
}
168168

169169
for (i = 0; i < ONFI_PARAM_PAGES; i++) {
170-
ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf), true);
170+
ret = nand_read_data_op(chip, &pbuf[i], sizeof(*pbuf), true,
171+
false);
171172
if (ret) {
172173
ret = 0;
173174
goto free_onfi_param_page;

‎include/linux/mtd/rawnand.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ int nand_change_write_column_op(struct nand_chip *chip,
13631363
unsigned int offset_in_page, const void *buf,
13641364
unsigned int len, bool force_8bit);
13651365
int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
1366-
bool force_8bit);
1366+
bool force_8bit, bool check_only);
13671367
int nand_write_data_op(struct nand_chip *chip, const void *buf,
13681368
unsigned int len, bool force_8bit);
13691369

0 commit comments

Comments
 (0)