mtd: rawnand: Skip timing mode readback check for GigaDevice NAND
Subsystems (2)
PATCH 1/1 mtd: rawnand: Skip timing mode readback check for GigaDevice NAND
GigaDevice raw NAND chips (manufacturer ID 0xC8) support the timing modes advertised in their ONFI parameter page, so there is no need to verify or enforce the timing mode switch on them. The supported set depends on the supply voltage: 3.3V parts (e.g. GD9FU2G8F3A, DID DAh) report modes 0-5 (3Fh in byte 129-130 of the parameter page), while 1.8V parts (e.g. GD9FS2G8F3A, DID AAh) report modes 0-4 (1Fh). The highest supported mode is already picked automatically from the parameter page by nand_choose_best_sdr_timings(), so the only thing getting in the way is the readback check.
The GET_FEATURE timing mode readback on these chips does not reflect the mode selected through SET_FEATURE. The strict check in nand_setup_interface() therefore misdetects the chip as not acknowledging the requested timing mode, printing "timing mode N not acknowledged by the NAND chip" and falling back to a slower mode for no reason.
Skip the readback check for GigaDevice chips while keeping it for all other vendors, and go straight to updating the interface configuration.
--- drivers/mtd/nand/raw/nand_base.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mtd/nand/raw/nand_base.c +9 -0
@@ -890,6 +890,15 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr) goto err_reset_chip;if (request != tmode_param[0 ]) { +/* +* GigaDevice raw NAND chips (manufacturer ID 0xC8) support +* the timing modes advertised in their ONFI parameter page. +* Skip the strict ack check; keep it for other vendors. +*/ +if (chip->id.data[0 ] ==0xC8 ) { + goto update_interface_config; + } +pr_warn ("%s timing mode %d not acknowledged by the NAND chip\n" ,nand_interface_is_nvddr (chip->best_interface_config) ?"NV-DDR" :"SDR" , chip->best_interface_config->timings.mode);
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mtd: rawnand: hardcoded 0xC8 check in nand_setup_interface() hits ESMT chips It also noticed 1…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mtd: rawnand: hardcoded 0xC8 check in nand_setup_interface() hits ESMT chips
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] mtd: rawnand: stale current_interface_config in nand_setup_interface() [1]
--
commit dfc5fac94fb600d7bec8edf7fac78be636e97132
Author: Teng Wu <[email protected]>
mtd: rawnand: Skip timing mode readback check for GigaDevice NAND
This commit skips the ONFI timing mode GET_FEATURES readback check in nand_setup_interface() for NAND chips with manufacturer ID 0xC8.
Quoted 6 lines
drivers/mtd/nand/raw/nand_base.c +0
-0@@ -890,6 +890,15 @@ static int nand_setup_interface(struct nand_chip *chip, int chipnr) goto err_reset_chip;
drivers/mtd/nand/raw/nand_base.c static int nand_setup_interface(struct nand_chip *chip, int chipnr) · line 900
Quoted 10 lines
drivers/mtd/nand/raw/nand_base.c +8
-0if (request != tmode_param[0 ]) { +/* +* GigaDevice raw NAND chips (manufacturer ID 0xC8) support +* the timing modes advertised in their ONFI parameter page. +* Skip the strict ack check; keep it for other vendors. +*/ +if (chip->id.data[0 ] ==0xC8 ) { + goto update_interface_config; + }
[Severity: Medium]
Does checking chip->id.data[0] == 0xC8 here also skip timing mode readback verification for ESMT NAND chips?
Manufacturer ID 0xC8 (NAND_MFR_ESMT) is shared by both ESMT and GigaDevice. Suppressing the readback check for all 0xC8 chips prevents nand_setup_interface() from detecting a rejected timing mode and falling back to mode 0 on ESMT parts, while still issuing unnecessary SET_FEATURES and GET_FEATURES bus operations on affected GigaDevice parts before ignoring the result.
esmt_nand_fix_broken_get_timings() in drivers/mtd/nand/raw/nand_esmt.c already handles this for GD9FU2G8F3A by matching chip->parameters.model and clearing ONFI_FEATURE_ADDR_TIMING_MODE from get_feature_list and set_feature_list:
drivers/mtd/nand/raw/nand_esmt.c:esmt_nand_fix_broken_get_timings() {
static const char * const broken_get_timings[] = {
"GD9FU2G8F3A",
};
...
bitmap_clear(chip->parameters.get_feature_list,
ONFI_FEATURE_ADDR_TIMING_MODE, 1);
bitmap_clear(chip->parameters.set_feature_list,
ONFI_FEATURE_ADDR_TIMING_MODE, 1);
}Could other affected GigaDevice models such as GD9FS2G8F3A be added to broken_get_timings[] there instead?
[Severity: High]
This problem wasn't introduced by this patch, but nand_setup_interface() calls nand_get_features() [1] after switching both the NAND chip and the controller to chip->best_interface_config while chip->current_interface_config still holds the SDR mode 0 reset configuration until update_interface_config.
Because nand_get_features_op() queries nand_get_interface_config(chip), it passes stale SDR mode 0 timings to nand_exec_op(). When switching to an NV-DDR timing mode, nand_interface_is_nvddr(conf) evaluates to false, so nand_get_features_op() reads only 4 bytes instead of 8 and skips NV-DDR byte de-interleaving, corrupting tmode_param[1..3]:
drivers/mtd/nand/raw/nand_base.c:nand_get_features_op() {
...
if (nand_has_exec_op(chip)) {
const struct nand_interface_config *conf =
nand_get_interface_config(chip);
...
/* GET_FEATURE data bytes are received twice in NV-DDR mode */
if (nand_interface_is_nvddr(conf)) {
instrs[3].ctx.data.len *= 2;
instrs[3].ctx.data.buf.in = ddrbuf;
}
}[1] https://sashiko.dev/#/bug/linux-0615e8bb-0985-4ed5-8173-2580f1023f12
Signature · 5 lines
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Miquel Raynal
maintainerHi,
drivers/mtd/nand/raw/nand_base.c static int nand_setup_interface(struct nand_chip *chip, int chipnr) · line 901
Quoted 10 lines
drivers/mtd/nand/raw/nand_base.c +9
-0if (request != tmode_param[0 ]) { +/* +* GigaDevice raw NAND chips (manufacturer ID 0xC8) support +* the timing modes advertised in their ONFI parameter page. +* Skip the strict ack check; keep it for other vendors. +*/ +if (chip->id.data[0 ] ==0xC8 ) { + goto update_interface_config; + } +
There is a vendor driver, you shall use it rather than polluting the core with vendor specific fixups. Check what macronix_nand_fix_broken_get_timings() does for example.
Thanks,
Miquèl